@xopcai/xopc 0.0.462 → 0.0.463

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 (80) hide show
  1. package/dist/browser-ext/_locales/en/messages.json +1 -0
  2. package/dist/browser-ext/_locales/zh_CN/messages.json +1 -0
  3. package/dist/browser-ext/dist/assets/{auth-CQmxIyWw.js → auth-YPMDpWOW.js} +32 -1
  4. package/dist/browser-ext/dist/background.js +24 -19
  5. package/dist/browser-ext/dist/sidepanel.html +1 -1
  6. package/dist/browser-ext/dist/sidepanel.js +7 -7
  7. package/dist/browser-ext/manifest.json +1 -1
  8. package/dist/extensions/telegram/xopc.extension.json +1 -1
  9. package/dist/gateway/static/root/assets/agent-plugin-dialog-C_rlXuEe.js +1 -0
  10. package/dist/gateway/static/root/assets/{apps-page-QLOYw2QR.js → apps-page-D1qzENN_.js} +1 -1
  11. package/dist/gateway/static/root/assets/{automations-page-DpKnqajR.js → automations-page-HYFnPiNG.js} +1 -1
  12. package/dist/gateway/static/root/assets/{automations-workspace-BXT_EDON.js → automations-workspace-JCQ1IXFk.js} +2 -2
  13. package/dist/gateway/static/root/assets/{capabilities-page-CnU0htlO.js → capabilities-page-kPv2dOzf.js} +2 -2
  14. package/dist/gateway/static/root/assets/{chat-page-U2a7d6wP.js → chat-page-CalELOKj.js} +6 -6
  15. package/dist/gateway/static/root/assets/{connectors-page-Bs29RvXz.js → connectors-page-B9mpz_Rt.js} +1 -1
  16. package/dist/gateway/static/root/assets/{index-CEBDMkde.js → index-DUo6H0PC.js} +4 -4
  17. package/dist/gateway/static/root/assets/mcp-conversation-setup-page-DCIEL5bA.js +1 -0
  18. package/dist/gateway/static/root/assets/{note-detail-panel-D_l5jkV9.js → note-detail-panel-DsXb1qjW.js} +2 -2
  19. package/dist/gateway/static/root/assets/{notes-page-R4uJroeD.js → notes-page-BTpiOw67.js} +1 -1
  20. package/dist/gateway/static/root/assets/{personal-page-BsONyPfQ.js → personal-page-I3IGVSJh.js} +1 -1
  21. package/dist/gateway/static/root/assets/{plugin-details-dialog-nSDw8sfo.js → plugin-details-dialog-F08k_k2u.js} +1 -1
  22. package/dist/gateway/static/root/assets/{project-detail-page-xNSy6SAv.js → project-detail-page-Dy46uSEt.js} +1 -1
  23. package/dist/gateway/static/root/assets/{route-preload-Dwb_N8L-.js → route-preload-ChTaYgpA.js} +2 -2
  24. package/dist/gateway/static/root/assets/{service-recommendation-list-DDlMyPvC.js → service-recommendation-list-BmRtbJz2.js} +1 -1
  25. package/dist/gateway/static/root/assets/{settings-page-8MiJzbbl.js → settings-page-C39lKVRv.js} +1 -1
  26. package/dist/gateway/static/root/assets/{task-detail-page-DxKXoBbE.js → task-detail-page-D1dNWTnP.js} +1 -1
  27. package/dist/gateway/static/root/assets/{work-discovery-overlay-UvWbDUXi.js → work-discovery-overlay-BJ15p4rH.js} +1 -1
  28. package/dist/gateway/static/root/assets/{work-discovery-page-BM1HsYz6.js → work-discovery-page-8XciWNs5.js} +1 -1
  29. package/dist/gateway/static/root/index.html +6 -6
  30. package/dist/package.js +1 -1
  31. package/dist/src/agent/embedded/session-runner.js +2 -2
  32. package/dist/src/agent/external-tools/gateway-tools.js +8 -1
  33. package/dist/src/agent/mcp/connection-setup.js +46 -42
  34. package/dist/src/agent/mcp/conversation-setup.js +13 -8
  35. package/dist/src/agent/mcp/discovery.d.ts +22 -1
  36. package/dist/src/agent/mcp/discovery.js +19 -3
  37. package/dist/src/agent/mcp/managed-discovery.d.ts +8 -0
  38. package/dist/src/agent/mcp/managed-discovery.js +77 -0
  39. package/dist/src/agent/mcp/tool-catalog.js +1 -1
  40. package/dist/src/agent/prompt/conversational-configuration-guide.js +1 -1
  41. package/dist/src/agent/skills/marketplace/adapters/store/store-api-client.d.ts +6 -2
  42. package/dist/src/agent/skills/marketplace/adapters/store/store-api-client.js +10 -7
  43. package/dist/src/agent/tool-manuals/xopc-configuration.d.ts +1 -1
  44. package/dist/src/agent/tool-manuals/xopc-configuration.js +12 -4
  45. package/dist/src/cli/commands/extension-agent-plugin.js +1 -1
  46. package/dist/src/cli/commands/gateway/lifecycle.js +2 -2
  47. package/dist/src/cli/commands/update.js +1 -1
  48. package/dist/src/connectors/connection-recovery-service.js +38 -5
  49. package/dist/src/connectors/excluded-connectors.d.ts +1 -0
  50. package/dist/src/connectors/excluded-connectors.js +5 -1
  51. package/dist/src/connectors/plugin-connection.d.ts +10 -0
  52. package/dist/src/connectors/plugin-connection.js +105 -0
  53. package/dist/src/extensions/agent-plugins/setup.js +1 -1
  54. package/dist/src/extensions/agent-plugins/skill-catalog.js +1 -1
  55. package/dist/src/gateway/hono/middleware/auth.js +1 -1
  56. package/dist/src/gateway/hono/routes/agent-plugins.js +2 -2
  57. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
  58. package/dist/src/gateway/hono/routes/connectors.js +1 -1
  59. package/dist/src/gateway/hono/routes/desktop-host.js +1 -1
  60. package/dist/src/gateway/hono/routes/home.js +1 -1
  61. package/dist/src/gateway/hono/routes/imports.js +1 -1
  62. package/dist/src/gateway/hono/routes/personal-agent.js +3 -3
  63. package/dist/src/gateway/hono/routes/update.js +2 -2
  64. package/dist/src/gateway/index.js +1 -1
  65. package/dist/src/gateway/run-loop.js +2 -2
  66. package/dist/src/gateway/security/gateway-scopes.js +1 -0
  67. package/dist/src/gateway/service/agent-runner.js +1 -1
  68. package/dist/src/gateway/service/run-gateway-agent.js +1 -1
  69. package/dist/src/gateway/service.js +11 -11
  70. package/dist/src/home-intelligence/host.js +5 -5
  71. package/dist/src/infra/gateway-processes.js +1 -1
  72. package/dist/src/infra/update-restart.js +2 -2
  73. package/dist/src/infra/update-runner.js +2 -2
  74. package/dist/src/infra/update-startup.js +1 -1
  75. package/dist/src/notifications/service.js +2 -2
  76. package/dist/src/phone/stream-gateway.js +1 -1
  77. package/dist/src/tui/tui-management.js +2 -2
  78. package/package.json +1 -1
  79. package/dist/gateway/static/root/assets/agent-plugin-dialog-CikzCYAG.js +0 -1
  80. package/dist/gateway/static/root/assets/mcp-conversation-setup-page-CsTSmjmX.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mcp-conversation-setup-page-CsTSmjmX.js","assets/rolldown-runtime-aKtaBQYM.js","assets/vendor-react-BOUWij0V.js","assets/chunk-KS7C4IRE-CiwuuyV8.js","assets/preload-helper-Czpn1I53.js","assets/locale-store-Dy1EByeG.js","assets/messages-BAnhwALN.js","assets/dist-CY7CS_D3.js","assets/es2015-DBLcMg5B.js","assets/dist-CxGUk8J-.js","assets/check-DUBLcKHA.js","assets/createLucideIcon-DPHK1VkS.js","assets/secret-input-DsjfQmDn.js","assets/circle-check-C23XjkUj.js","assets/copy-Dv6d4Dvw.js","assets/eye-CABVeTq0.js","assets/loader-circle-CifKLtgG.js","assets/cn-0WouolD0.js","assets/bundle-mjs-rHxsej31.js","assets/copy-to-clipboard-HOJ79TWv.js","assets/interaction-BdhHBbYa.js","assets/form-field-width-DJw_jULe.js","assets/is-masked-secret-DOkL5b_X.js","assets/key-round-DWbpyU2U.js","assets/link-2-D_ZKYUW7.js","assets/lock-keyhole-DEK5kH0u.js","assets/x-B_N4OPjy.js","assets/skeleton-DzdOeGYz.js","assets/vendor-swr-CdRzEUwF.js","assets/button-Cc4hUNTt.js","assets/chat-terminal-dock-eneTvxV3.js","assets/plus-Q2yW6OE7.js","assets/square-terminal-K87bylpZ.js","assets/session-api-BFiIYodK.js","assets/schemas-CCWMleym.js","assets/gateway-startup-retry-D6WPS0RW.js","assets/session-manager-63NaXb1s.js","assets/diagnostics-Bo0Z42P_.js","assets/constants-Bg1wM2nv.js","assets/local-session-drafts-BIBHRkpM.js","assets/tool-activity-BtJkgjFf.js","assets/attachment-utils-core-BIOUBrpT.js","assets/gateway-realtime-DIs1pjkQ.js","assets/gateway-realtime-store-sx7B8kdC.js","assets/registry-api-DuDIthjL.js","assets/agents-admin-api-D0N09mqJ.js","assets/gateway-config-swr-1Rk0LeEM.js","assets/sliding-tab-list-CmcrqRzN.js","assets/sliding-indicator-hwz0sx3h.js","assets/terminal-panel-store-Du53Upr2.js","assets/chat-terminal-dock-uQUnjRtf.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mcp-conversation-setup-page-DCIEL5bA.js","assets/rolldown-runtime-aKtaBQYM.js","assets/vendor-react-BOUWij0V.js","assets/chunk-KS7C4IRE-CiwuuyV8.js","assets/preload-helper-Czpn1I53.js","assets/locale-store-Dy1EByeG.js","assets/messages-BAnhwALN.js","assets/dist-CY7CS_D3.js","assets/es2015-DBLcMg5B.js","assets/dist-CxGUk8J-.js","assets/check-DUBLcKHA.js","assets/createLucideIcon-DPHK1VkS.js","assets/secret-input-DsjfQmDn.js","assets/circle-check-C23XjkUj.js","assets/copy-Dv6d4Dvw.js","assets/eye-CABVeTq0.js","assets/loader-circle-CifKLtgG.js","assets/cn-0WouolD0.js","assets/bundle-mjs-rHxsej31.js","assets/copy-to-clipboard-HOJ79TWv.js","assets/interaction-BdhHBbYa.js","assets/form-field-width-DJw_jULe.js","assets/is-masked-secret-DOkL5b_X.js","assets/key-round-DWbpyU2U.js","assets/link-2-D_ZKYUW7.js","assets/lock-keyhole-DEK5kH0u.js","assets/x-B_N4OPjy.js","assets/skeleton-DzdOeGYz.js","assets/vendor-swr-CdRzEUwF.js","assets/button-Cc4hUNTt.js","assets/agent-plugin-dialog-C_rlXuEe.js","assets/arrow-left-D880xG-P.js","assets/chevron-down-ccbiQQz_.js","assets/working-directory-picker-modal-BGZduAXV.js","assets/file-archive-DanfQJNe.js","assets/settings-form-draft-Dy10ldo8.js","assets/circle-alert-BEjgurr2.js","assets/circle-BoO4YvTx.js","assets/folder-open-CyzJ19I9.js","assets/package-wATCyihJ.js","assets/shield-check-BU58siTV.js","assets/upload-rrb46c3c.js","assets/capability-links-MZdYfPKx.js","assets/connection-usage-BhdQRWgQ.js","assets/browser-BLJWD7WI.js","assets/capability-icon-CmvCZOJX.js","assets/chat-terminal-dock-eneTvxV3.js","assets/plus-Q2yW6OE7.js","assets/square-terminal-K87bylpZ.js","assets/session-api-BFiIYodK.js","assets/schemas-CCWMleym.js","assets/gateway-startup-retry-D6WPS0RW.js","assets/session-manager-63NaXb1s.js","assets/diagnostics-Bo0Z42P_.js","assets/constants-Bg1wM2nv.js","assets/local-session-drafts-BIBHRkpM.js","assets/tool-activity-BtJkgjFf.js","assets/attachment-utils-core-BIOUBrpT.js","assets/gateway-realtime-DIs1pjkQ.js","assets/gateway-realtime-store-sx7B8kdC.js","assets/registry-api-DuDIthjL.js","assets/agents-admin-api-D0N09mqJ.js","assets/gateway-config-swr-1Rk0LeEM.js","assets/sliding-tab-list-CmcrqRzN.js","assets/sliding-indicator-hwz0sx3h.js","assets/terminal-panel-store-Du53Upr2.js","assets/chat-terminal-dock-uQUnjRtf.css"])))=>i.map(i=>d[i]);
2
2
  import{i as e,n as t}from"./rolldown-runtime-aKtaBQYM.js";import{n,r,t as i}from"./diagnostics-Bo0Z42P_.js";import{a,i as o,n as s,t as c}from"./vendor-react-BOUWij0V.js";import{t as l}from"./preload-helper-Czpn1I53.js";import{f as u,l as d,m as f,t as p,u as m}from"./chunk-KS7C4IRE-CiwuuyV8.js";import{a as h,i as g,l as _,n as v,o as y,p as b,u as x}from"./locale-store-Dy1EByeG.js";import{t as S}from"./messages-BAnhwALN.js";import{a as C,c as w,i as T,n as E,o as D,r as O,s as k,t as A}from"./dist-CY7CS_D3.js";import{t as j}from"./createLucideIcon-DPHK1VkS.js";import{t as M}from"./app-window-DXFNqt_0.js";import{t as N}from"./archive-Dz0hferG.js";import{t as P}from"./arrow-left-D880xG-P.js";import{t as F}from"./arrow-up-right-T72JbQ1Q.js";import{t as I}from"./arrow-up-D5ZtR1QT.js";import{a as L,c as R,d as z,f as B,l as ee,s as V,t as H,u as U}from"./product-automation-feedback-CGso8wGv.js";import{n as W,t as te}from"./earth-C9Z4bTTG.js";import{t as ne}from"./bot-DjLkhyZL.js";import{t as re}from"./check-DUBLcKHA.js";import{t as ie}from"./chevron-down-ccbiQQz_.js";import{t as ae}from"./chevron-right-BweFrslA.js";import{i as oe,r as se,t as ce}from"./working-directory-picker-modal-BGZduAXV.js";import{a as le,d as ue,n as de,o as G,r as K,t as fe}from"./popover-select-CLsphyzA.js";import{t as q}from"./circle-alert-BEjgurr2.js";import{i as pe,r as me,t as J}from"./new-chat-navigation-B6NPQ4h4.js";import{t as he}from"./circle-x-DFsCKeya.js";import{t as ge}from"./circle-BoO4YvTx.js";import{i as _e,n as ve,r as ye,t as be}from"./file-tree-utils-DJs1faGv.js";import{t as xe}from"./copy-Dv6d4Dvw.js";import{t as Se}from"./database-CjjeZfRG.js";import{t as Ce}from"./ellipsis-0k4rZLoy.js";import{t as we}from"./external-link-DjqjBmc3.js";import{n as Te,t as Ee}from"./file-BqMS_3DT.js";import{t as De}from"./file-image-CDUPkZvG.js";import{t as Oe}from"./file-text-D12HbeVy.js";import{t as ke}from"./folder-kanban-CpLlFI1o.js";import{t as Ae}from"./folder-open-CyzJ19I9.js";import{t as je}from"./folder-CN-pC3XL.js";import{i as Me,r as Ne,u as Pe}from"./use-file-preview-expanded-D0IBFhM9.js";import{t as Fe}from"./git-branch-Dh9uxTot.js";import{t as Ie}from"./globe-DSSGFWFn.js";import{t as Le}from"./history-DXH_9jsE.js";import{F as Re,L as ze,P as Be,c as Ve,g as He,o as Ue,t as We,v as Ge}from"./notes-api-BOIM9Q_D.js";import{t as Ke}from"./key-round-DWbpyU2U.js";import{t as qe}from"./laptop-CI3hBVrl.js";import{t as Je}from"./link-2-D_ZKYUW7.js";import{t as Ye}from"./list-checks-BbsExAoq.js";import{t as Xe}from"./list-todo-CTVRto8O.js";import{t as Ze}from"./loader-circle-CifKLtgG.js";import{C as Qe,E as $e,F as et,I as tt,O as nt,T as rt,V as it,_ as at,b as ot,c as st,d as ct,f as lt,g as ut,h as dt,j as ft,l as pt,m as mt,n as ht,p as gt,r as _t,u as vt,v as yt,w as bt,x as xt,y as St,z as Ct}from"./markdown-view-CNJaAdNN.js";import{t as wt}from"./messages-square-BckAJrEW.js";import{t as Tt}from"./mic-CuUb7zc-.js";import{t as Et}from"./monitor-Af5eAvF7.js";import{s as Dt,t as Ot}from"./install-connector-dialog-DxSv1wS2.js";import{t as kt}from"./paperclip-f1HujQY1.js";import{t as At}from"./pause-DuPxgSxk.js";import{t as jt}from"./pencil-DmIY3Oa-.js";import{t as Mt}from"./play-kxZvpBg8.js";import{t as Nt}from"./plus-Q2yW6OE7.js";import{t as Pt}from"./refresh-cw-BRlGaq2w.js";import{t as Ft}from"./rotate-ccw-JM1TBLpp.js";import{t as It}from"./save-DRDABU--.js";import{t as Lt}from"./search-DA7gz22f.js";import{t as Rt}from"./settings-2-D-csvaET.js";import{t as zt}from"./settings-uiTATseT.js";import{t as Bt}from"./shield-check-BU58siTV.js";import{t as Vt}from"./smartphone-DSSsQFqA.js";import{t as Ht}from"./sparkles-DHlfQFAF.js";import{t as Ut}from"./square-DMK_fB-3.js";import{t as Wt}from"./trash-2-DusmjVPV.js";import{t as Gt}from"./triangle-alert-2JXFNNKU.js";import{a as Kt,r as qt,t as Jt}from"./share-link-dialog-C1t_HB6f.js";import{t as Yt}from"./wrench-DFb4r8bH.js";import{t as Xt}from"./x-B_N4OPjy.js";import{t as Zt}from"./zap-dximCGjy.js";import{t as Y}from"./cn-0WouolD0.js";import{t as Qt}from"./skeleton-DzdOeGYz.js";import{a as $t,d as en,m as tn,n as nn,u as rn}from"./schemas-CCWMleym.js";import{t as an}from"./tasks-BTLabOMp.js";import{i as on,n as sn,o as cn,s as ln,t as un}from"./product-delivery-BFfqdKLe.js";import{o as dn}from"./local-apps-DeqzkJiF.js";import{a as fn,c as pn,d as mn}from"./api-B4FJ51EC.js";import{a as hn,s as gn}from"./session-api-BFiIYodK.js";import{$ as _n,A as vn,B as yn,C as bn,Ct as xn,D as Sn,E as Cn,F as wn,G as Tn,H as En,I as Dn,J as On,K as kn,L as An,M as jn,N as Mn,O as Nn,P as Pn,Q as Fn,R as In,S as Ln,St as Rn,T as zn,Tt as Bn,U as Vn,V as Hn,W as Un,X as Wn,Y as Gn,Z as Kn,_ as qn,_t as Jn,b as Yn,bt as Xn,c as Zn,ct as Qn,d as $n,dt as er,et as tr,f as nr,ft as rr,g as ir,gt as ar,it as or,j as sr,k as cr,l as lr,lt as ur,mt as dr,nt as fr,o as pr,ot as mr,p as hr,r as gr,rt as _r,st as vr,t as yr,tt as br,u as xr,v as Sr,vt as Cr,w as wr,wt as Tr,x as Er,xt as Dr,y as Or,yt as kr,z as Ar}from"./session-manager-63NaXb1s.js";import{a as jr,d as Mr,m as Nr,n as Pr,o as Fr,p as Ir,s as Lr,t as Rr,u as zr}from"./local-session-drafts-BIBHRkpM.js";import{t as Br}from"./tool-activity-BtJkgjFf.js";import{a as Vr,c as Hr,i as Ur,l as Wr,n as Gr,o as Kr,r as qr,s as Jr,t as Yr}from"./new-session-preferences-gb411vZP.js";import{n as Xr,t as Zr}from"./composer-model-config-control-DAagrRx_.js";import{i as Qr}from"./vendor-swr-CdRzEUwF.js";import{g as $r,i as ei,n as ti,o as ni,p as ri,r as ii,t as ai}from"./workspace-preview-store-imhtuEIP.js";import{a as oi}from"./gateway-config-swr-1Rk0LeEM.js";import{t as si}from"./chat-agents-api-CjlzCSmC.js";import{a as ci,c as li,i as ui,r as di,s as fi}from"./attachment-utils-core-BIOUBrpT.js";import{n as pi}from"./gateway-realtime-DIs1pjkQ.js";import{n as mi}from"./gateway-realtime-store-sx7B8kdC.js";import{n as hi,t as gi}from"./registry-api-DuDIthjL.js";import{a as _i}from"./agents-admin-api-D0N09mqJ.js";import{t as vi}from"./button-Cc4hUNTt.js";import{n as yi}from"./right-workspace-store-HPw7Gw0n.js";import{a as bi,i as xi,o as Si,r as Ci,s as wi}from"./dist-GJ8-1PAx.js";import{t as Ti}from"./middleware-Pd0e8Igk.js";import{i as Ei,r as Di}from"./app-link-DImAfVs5.js";import{t as Oi}from"./copy-to-clipboard-HOJ79TWv.js";import{a as ki,i as Ai,n as ji,o as Mi,r as Ni,s as Pi}from"./composer-payload-handoff-Dc43dgSg.js";import{C as Fi,D as Ii,E as Li,T as Ri,_ as zi,b as Bi,c as Vi,d as Hi,f as Ui,g as Wi,h as Gi,m as Ki,n as qi,o as Ji,p as Yi,r as Xi,s as Zi,u as Qi,v as $i,w as ea,x as ta,y as na}from"./chunk-D32TOXHM-DQIy-Baq.js";import{i as ra,n as ia,r as aa,t as oa}from"./chat-chart-block-ClCZyIi0.js";import{t as sa}from"./linkify-it-BkqEorO0.js";import{n as ca}from"./interaction-BdhHBbYa.js";import{a as la,i as ua,n as da,o as fa,r as pa,s as ma,t as ha}from"./tool-friendly-title-CP35P4VA.js";import{s as ga}from"./connectors-api-CTuVWwBf.js";import{t as _a}from"./use-realtime-voice-B5IsKrRW.js";import{t as va}from"./activity-store-CQHh48Zf.js";import{t as ya}from"./composer-notifications-CqV6Xj-H.js";import{n as ba}from"./voice-call-context-BM2A4bLz.js";import{r as xa}from"./app-chrome-BeB4KgOf.js";import{i as Sa,n as Ca,r as wa}from"./form-field-width-DJw_jULe.js";import{n as Ta}from"./electron-env-DHOGevH3.js";import{t as Ea}from"./page-header-store-Bm8oxpFR.js";import{t as Da}from"./use-async-resource-BHFGZCY2.js";import{t as Oa}from"./loopi-CNtmi9FU.js";import{a as ka}from"./extension-provider-D-LolObs.js";import{t as Aa}from"./agent-avatar-display-loBdGw_i.js";import{a as ja,n as Ma,r as Na,t as Pa}from"./skill-wire-pattern-BPpeIcCi.js";import{c as Fa,i as Ia,n as La,o as Ra,r as za,s as Ba,t as Va}from"./use-composer-attachments-Xn6eUus2.js";import{n as Ha,t as Ua}from"./use-directory-picker-C4p7AgWY.js";import{t as Wa}from"./confirm-dialog-DrA5mTQp.js";import{a as Ga,c as Ka,f as qa,l as Ja,s as Ya,u as Xa}from"./workspace-api-Dd_UDfeo.js";import{n as Za}from"./index.module-Cd9ENXfk.js";import{a as Qa,i as $a,o as eo,r as to,s as no}from"./copy-text-row-CpiRzq4G.js";import{_ as ro,b as io,d as ao,f as oo,h as so,i as co,n as lo,p as uo,s as fo,u as po,y as mo}from"./shares-api-Dm07CnXw.js";import{t as ho}from"./workspace-editor-agent-store-DVPJcbuE.js";import{l as go,m as _o,o as vo,r as yo,t as bo,u as xo}from"./dist-ZrL34Ps4.js";import{a as So,c as Co,d as wo,f as To,h as Eo,i as Do,l as Oo,m as ko,p as Ao,s as jo,t as Mo,u as No}from"./command-palette-api-CP0F6sIm.js";import{n as Po,o as Fo,r as Io,s as Lo}from"./voice-input-shortcut-events-CEeFBhp3.js";import{_ as Ro,g as zo,h as Bo,i as Vo,t as Ho,v as Uo}from"./automation-task-card-CJbIHRxN.js";import{t as Wo}from"./dev-view-store-B8fGILny.js";import{t as Go}from"./extension-iframe-host-Vs6USa0c.js";import{i as Ko,r as qo,t as Jo}from"./runtime-health-zDkHcOZO.js";import{c as Yo,i as Xo,r as Zo}from"./api-B1J5ajiP.js";import{r as Qo}from"./terminal-panel-store-Du53Upr2.js";import{n as $o}from"./agents-app-path-ciChvpCS.js";import{n as es,t as ts}from"./agent-display-names-Bje7vfSn.js";import{t as ns}from"./oauth-provider-connect-D63M8Iv7.js";import{t as rs}from"./use-media-query-ady-FgjK.js";import{n as is,r as as,t as os}from"./oauth-authorization-window-o6URRos4.js";import{n as ss,t as cs}from"./page-context-draft-Cr5GqS2D.js";import{i as ls,r as us}from"./management-api-B5w5DdXH.js";import{t as ds}from"./side-chat-shortcut-BIw-1TTD.js";var fs=j(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),ps=j(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),ms=j(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),hs=j(`corner-down-right`,[[`path`,{d:`m15 10 5 5-5 5`,key:`qqa56n`}],[`path`,{d:`M4 4v7a4 4 0 0 0 4 4h12`,key:`z08zvw`}]]),gs=j(`file-headphone`,[[`path`,{d:`M4 6.835V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-.343`,key:`1vfytu`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M2 19a2 2 0 0 1 4 0v1a2 2 0 0 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 0 1-4 0v-1a2 2 0 0 1 4 0`,key:`1etmh7`}]]),_s=j(`file-pen-line`,[[`path`,{d:`M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z`,key:`ukzhwg`}],[`path`,{d:`M14.487 7.858A1 1 0 0 1 14 7V2`,key:`1klhew`}],[`path`,{d:`M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516`,key:`rxaxab`}],[`path`,{d:`M8 18h1`,key:`13wk12`}]]),vs=j(`file-plus-corner`,[[`path`,{d:`M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35`,key:`17jvcc`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M14 19h6`,key:`bvotb8`}],[`path`,{d:`M17 16v6`,key:`18yu1i`}]]),ys=j(`files`,[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]),bs=j(`git-commit-horizontal`,[[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`line`,{x1:`3`,x2:`9`,y1:`12`,y2:`12`,key:`1dyftd`}],[`line`,{x1:`15`,x2:`21`,y1:`12`,y2:`12`,key:`oup4p8`}]]),xs=j(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),Ss=j(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),Cs=j(`layout-template`,[[`rect`,{width:`18`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`f1a2em`}],[`rect`,{width:`9`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`jqznyg`}],[`rect`,{width:`5`,height:`7`,x:`16`,y:`14`,rx:`1`,key:`q5h2i8`}]]),ws=j(`message-circle-more`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}]]),Ts=j(`message-circle-plus`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),Es=j(`message-square-share`,[[`path`,{d:`M12 3H4a2 2 0 0 0-2 2v16.286a.71.71 0 0 0 1.212.502l2.202-2.202A2 2 0 0 1 6.828 19H20a2 2 0 0 0 2-2v-4`,key:`11da1y`}],[`path`,{d:`M16 3h6v6`,key:`1bx56c`}],[`path`,{d:`m16 9 6-6`,key:`m4dnic`}]]),Ds=j(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),Os=j(`notebook-pen`,[[`path`,{d:`M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4`,key:`re6nr2`}],[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`path`,{d:`M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z`,key:`pqwjuv`}]]),ks=j(`shuffle`,[[`path`,{d:`m18 14 4 4-4 4`,key:`10pe0f`}],[`path`,{d:`m18 2 4 4-4 4`,key:`pucp1d`}],[`path`,{d:`M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22`,key:`1ailkh`}],[`path`,{d:`M2 6h1.972a4 4 0 0 1 3.6 2.2`,key:`km57vx`}],[`path`,{d:`M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45`,key:`os18l9`}]]),As=j(`square-plus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),js=j(`target`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`6`,key:`1vlfrh`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Ms=j(`wallet`,[[`path`,{d:`M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1`,key:`18etb6`}],[`path`,{d:`M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4`,key:`xoc0q4`}]]);function Ns(e,t){return e.replace(/\{\{(\w+)}}/g,(e,n)=>t[n]?.trim()??``).replace(/[ \t]{2,}/g,` `).trim()}function Ps(e,t,n){return{id:e,title:Ns(t.title,n),prompt:Ns(t.prompt,n),reason:Ns(t.reason,n)}}function Fs(e,t){let n={projectName:e.projectName,blockedReason:e.blockedReason,recentFailure:e.recentFailure,nextAction:e.recommendedAction};if(e.blockedReason?.trim())return Ps(`project-blocked`,t.recommendations.projectBlocked,n);if(e.recentFailure?.trim())return Ps(`project-failure`,t.recommendations.projectFailure,n);if(e.recommendedAction?.trim())return Ps(`project-next-action`,t.recommendations.projectNextAction,n)}function Is(e,t){let n={taskTitle:e.taskTitle,attentionSummary:e.attentionSummary,recentFailure:e.recentFailure,nextAction:e.nextAction};if(e.attentionSummary?.trim())return Ps(`task-attention`,t.recommendations.taskAttention,n);if(e.recentFailure?.trim())return Ps(`task-failure`,t.recommendations.taskFailure,n);if(e.phase===`review`||e.operationalState===`verifying`)return Ps(`task-review`,t.recommendations.taskReview,n);if(e.phase===`closed`)return Ps(`task-closed`,t.recommendations.taskClosed,n);if(e.nextAction?.trim())return Ps(`task-next-action`,t.recommendations.taskNextAction,n)}function Ls(e,t){switch(e.kind){case`project`:return Fs(e,t);case`task`:return Is(e,t);default:return}}function Rs(e,t,n={}){let r=n.contextStatus??`ready`;return{headline:e.kind===`project`&&t.projectHeadline?Ns(t.projectHeadline,{projectName:e.projectName}):t.headline,contextKind:e.kind,contextStatus:r,recommendation:r===`ready`?Ls(e,t):void 0}}var zs=en({id:tn().uuid(),conversationId:tn(),transcriptId:tn(),sourceRunId:tn(),inputRevision:rn().int().nonnegative(),transcriptCursor:rn().int().nonnegative(),agentId:tn(),locale:nn([`zh`,`en`]),prompt:tn().min(1).max(160),expiresAt:rn()}),Bs=en({status:nn([`ready`,`pending`,`none`]),suggestion:zs.optional()});en({suggestionId:tn().uuid(),impressionId:tn().uuid(),event:nn([`shown`,`accepted`,`dismissed`,`submitted`]),edited:$t().optional()}).strict();function Vs(e,t=`body`){return`result:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Hs(e){return`${e.taskRunId}:${e.assignmentEpoch}:${e.outcome.outcomeId}`}var Us=e(o(),1),X=s(),Z=c(),Q=e(a(),1);function Ws(e,t){return e?[`task-detail`,e,t??``]:null}function Gs(e,t){return t.source!==`user`||e===void 0||t.version>e}function Ks(e){let t=_(e=>e.conversationId),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(``),l=(0,Q.useRef)(void 0),u=Qr(Ws(e,t),()=>$r(e),{keepPreviousData:!1,revalidateOnFocus:!0,revalidateOnReconnect:!0,refreshInterval:e=>e&&[`allocating`,`queued`,`running`,`waiting`,`verifying`].includes(e.operationalState)?5e3:0});return l.current=u.data?.task.version,(0,Q.useEffect)(()=>{r(null),a(!1),s(null),c.current=``},[e]),(0,Q.useEffect)(()=>{let t=u.data;if(!t||t.conversation.activeConversationId||t.allocation&&t.allocation.status!==`assigned`)return;let n=`${e}:${t.task.version}`;c.current!==n&&(c.current=n,a(!0),s(null),ri(e).then(()=>c.current===n?u.mutate():void 0).catch(e=>{c.current===n&&s(e)}).finally(()=>{c.current===n&&a(!1)}))},[u.data,u.mutate,e]),(0,Q.useEffect)(()=>{let t,n=()=>{window.clearTimeout(t),t=window.setTimeout(()=>void u.mutate(),120)},i=t=>{let i=an.safeParse(t.detail);!i.success||i.data.taskId!==e||Gs(l.current,i.data)&&(r(i.data),n())},a=()=>n();return window.addEventListener(`task-changed-v2`,i),window.addEventListener(`gateway-realtime-connected`,a),window.addEventListener(`realtime-gap`,a),()=>{window.clearTimeout(t),window.removeEventListener(`task-changed-v2`,i),window.removeEventListener(`gateway-realtime-connected`,a),window.removeEventListener(`realtime-gap`,a)}},[u.mutate,e]),{...u,lastChange:n,conversationLoading:i,conversationError:o}}var qs=new Map,Js=new Set;function Ys(e,t){qs.set(e,t);for(let e of Js)e();return()=>{qs.get(e)===t&&qs.delete(e)}}async function Xs(e,t,n){await(qs.get(e)??await new Promise((t,n)=>{let r=()=>{let n=qs.get(e);n&&(clearTimeout(i),Js.delete(r),t(n))},i=setTimeout(()=>{Js.delete(r),n(Error(`Chat input is not ready. Please retry.`))},15e3);Js.add(r),r()}))(t,n)}var Zs=crypto.randomUUID(),Qs=e=>e===`closed`;function $s(e,t){let n=e,r=n?.code??n?.body?.error?.code,i={PHONE_HDC_VIDEO_DEPENDENCY:`鸿蒙投屏库或 JDK 不兼容,请在添加手机的投屏工具路径中检查 HOScrcpy JAR 和 JDK。`,PHONE_HDC_VIDEO_TIMEOUT:`鸿蒙投屏启动超时,已回退截图。请检查 USB 连接和投屏工具。`,PHONE_HDC_VIDEO_FAILED:`鸿蒙投屏暂不可用,已回退截图。请检查 USB 连接和投屏库兼容性。`,PHONE_VIDEO_BUSY:`手机已有原生调试或投屏连接,请关闭该连接后重试视频。`,PHONE_CONTROL_BUSY:`另一设备正在操作手机,请等待其结束控制。`,PHONE_DEVICE_BUSY:`手机正被其他聊天或人工操作占用,本次操作尚未开始。请查看当前任务,等待或明确停止后再试。`,PHONE_OBSERVE_ONLY:`此入口仅支持查看手机画面,请在来源聊天中操作或接管手机。`,PHONE_CONTROL_CHANGED:`手机控制权已变化,本次操作未继续。请查看最新状态后重新接管。`,PHONE_CONTROL_REQUIRED:`当前窗口没有手机操作权,请先接管手机。`,PHONE_CONTROL_STALE:`手机控制状态已更新,请等待状态刷新后再操作。`,PHONE_DISPATCH_UNKNOWN:`上一条手机输入的结果尚未确认,请先检查手机,避免重复执行。`,PHONE_FRAME_STALE:`手机画面已变化,请等待新画面后再操作。`,PHONE_APP_DENIED:`当前页面不在授权应用范围内,请返回授权应用。`,PHONE_SESSION_NOT_FOUND:`手机连接或来源聊天已变化,请刷新手机面板。`,PHONE_PAUSED:`手机任务已暂停,请检查手机状态并明确交回控制权后继续。`,PHONE_DEVICE_OFFLINE:`手机暂未连接,任务进度已保留。请连接手机后重试。`,PHONE_BINDING_CHANGED:`手机或 Agent 设置已变化,任务进度已保留。请检查设备和模型设置后重试。`,PHONE_ASSISTANCE_CHANGED:`待接管任务已更新,请刷新状态后操作。`};return t&&r&&i[r]?i[r]:n?.message??(t?`无法完成手机操作,请检查连接状态。`:`Phone operation failed. Check the connection.`)}var ec=e=>`/api/phone/conversations/${encodeURIComponent(e)}`,tc=new Map,nc=()=>{let e=_.getState();return`${e.baseUrl}:${e.conversationId}`};function rc(e,t,n=nc()){let r=`${n}:${e}`,i=tc.get(r);return t&&i&&t.report.sessionId===i.report.sessionId&&(t.report.revision??0)<(i.report.revision??0)?i:(t?(tc.set(r,t),tc.size>100&&tc.delete(tc.keys().next().value)):tc.delete(r),t)}async function ic(e,t=nc()){let n=await h(g(e)),r=decodeURIComponent(e.split(`/conversations/`)[1]?.split(`?`)[0]??``);if(n.status===404)return rc(r,null,t);if((n.status===401||n.status===403)&&rc(r,null,t),!n.ok)throw Object.assign(Error(`Phone view unavailable (HTTP ${n.status})`),{status:n.status});return rc(r,(await n.json()).payload,t)}function ac(e,t){let n=(0,X.c)(5),r=t===void 0||t,i=_(cc),a;n[0]!==e||n[1]!==r||n[2]!==i?(a=r&&/^(?:device:)?[\da-f]{8}-[\da-f-]{27}$/i.test(e)?[`${ec(e)}?clientId=${Zs}`,i]:null,n[0]=e,n[1]=r,n[2]=i,n[3]=a):a=n[3];let o;return n[4]===Symbol.for(`react.memo_cache_sentinel`)?(o={refreshInterval:1200,revalidateOnFocus:!0,shouldRetryOnError:oc,errorRetryCount:6,errorRetryInterval:2e3,refreshWhenHidden:!1},n[4]=o):o=n[4],Qr(a,sc,o)}function oc(e){return e.status!==401&&e.status!==403}function sc(e){let[t,n]=e;return ic(t,n)}function cc(e){return`${e.baseUrl}:${e.conversationId}`}async function lc(e,t,n,r={},i=!1){let a=nc();return rc(e,(await y(g(`${ec(e)}/${t.report.sessionId}/control`),{method:`POST`,keepalive:i,body:JSON.stringify({expectedTranscriptId:t.report.transcriptId,clientId:Zs,assistanceId:t.report.assistanceId,assistanceVersion:t.report.assistanceVersion,operationId:crypto.randomUUID(),epoch:t.report.controlEpoch,op:n,...r})})).payload,a)}async function uc(e,t,n){let r=await h(g(`${ec(e)}/${t}/frame`),{signal:n});if(!r.ok){let e=await r.json().catch(()=>({}));throw Object.assign(Error(e.error?.message??`HTTP ${r.status}`),{status:r.status,code:e.error?.code})}return{blob:await r.blob(),seq:Number(r.headers.get(`X-Phone-Frame-Seq`)),capturedAt:Number(r.headers.get(`X-Phone-Captured-At`)),width:Number(r.headers.get(`X-Phone-Width`)),height:Number(r.headers.get(`X-Phone-Height`))}}function dc(e,t,n,r,i){let a=Math.min(e.width/t,e.height/n),o=t*a,s=n*a,c=r-e.left-(e.width-o)/2,l=i-e.top-(e.height-s)/2;return!a||c<0||l<0||c>o||l>s?null:[Math.round(c/o*1e3),Math.round(l/s*1e3)]}async function fc(e,t,n,r=!1){return(await y(g(`${ec(e)}/${t.report.sessionId}/execution-mode`),{method:`POST`,body:JSON.stringify({executionMode:n,applyCurrent:r,epoch:t.report.controlEpoch,clientId:Zs})})).payload}function pc(e,t){if(!t.assistanceId||![`needs_user`,`paused`].includes(t.status))return null;let n=_.getState();return JSON.stringify([n.baseUrl,n.conversationId,e,t.transcriptId,t.assistanceId,t.assistanceVersion??1])}var mc=b(Ti(e=>({seen:[],markSeen:t=>e(e=>e.seen.includes(t)?e:{seen:[...e.seen.slice(-99),t]})}),{name:`xopc-phone-attention-v1`}));function hc(e){let t=(0,X.c)(15),{detail:n,language:r}=e,i;t[0]===n?i=t[1]:(i=ni(n),t[0]=n,t[1]=i);let a=i,o=r===`zh`,s=a.receipt?.status===`failed`?o?`最近一轮执行失败`:`Latest run failed`:a.receipt?.status===`cancelled`?o?`最近一轮执行已取消`:`Latest run canceled`:a.receipt?o?`最近一轮执行已结束`:`Latest run ended`:o?`尚无本版任务的执行结果`:`No run result for this task version`,c=o?`执行、验收与交付`:`Execution, acceptance and delivery`,l=n.task.phase===`closed`?``:o?`;任务仍未关闭`:`; task remains open`,u;t[2]!==s||t[3]!==l?(u=(0,Z.jsxs)(`p`,{children:[s,l]}),t[2]=s,t[3]=l,t[4]=u):u=t[4];let d=o?`验收:${a.verified}/${a.criteria} 项通过`:`Acceptance: ${a.verified}/${a.criteria} criteria passed`,f=a.criteria===0?o?`,尚未定义验收标准`:`; criteria not defined`:``,p;t[5]!==d||t[6]!==f?(p=(0,Z.jsxs)(`p`,{children:[d,f]}),t[5]=d,t[6]=f,t[7]=p):p=t[7];let m=a.deliverables>0?o?`已关联交付物:${a.deliverables} 项`:`Linked deliverables: ${a.deliverables}`:o?`尚无正式交付物`:`No formal deliverables linked`,h;t[8]===m?h=t[9]:(h=(0,Z.jsx)(`p`,{children:m}),t[8]=m,t[9]=h);let g;return t[10]!==c||t[11]!==u||t[12]!==p||t[13]!==h?(g=(0,Z.jsxs)(`div`,{className:`mt-3 space-y-1 border-t border-edge-subtle pt-3 text-xs leading-5 text-fg-muted`,"aria-label":c,children:[u,p,h]}),t[10]=c,t[11]=u,t[12]=p,t[13]=h,t[14]=g):g=t[14],g}var gc=(0,Q.memo)(function(e){let t=(0,X.c)(58),{taskId:n}=e,r=d(),i=v(_c),a;t[0]===i?a=t[1]:(a=Pi(i),t[0]=i,t[1]=a);let o=a,{data:s}=Ks(n);if(!s)return null;let{task:c,operationalState:l}=s,u,f,m,h;if(t[2]!==o.noDecisionNeeded||t[3]!==s||t[4]!==l||t[5]!==c.phase){let e=ti(s);m=s.attention.length>0;let n;t[10]!==l||t[11]!==c.phase?(n=c.phase!==`closed`&&[`queued`,`running`,`verifying`].includes(l),t[10]=l,t[11]=c.phase,t[12]=n):n=t[12],f=n,u=m?s.attention[0]?.summary??e?.nextAction??e?.summary:c.phase===`closed`?e?.summary:e?.nextAction??e?.summary??o.noDecisionNeeded,h=e?.evidence.filter(vc).length??0,t[2]=o.noDecisionNeeded,t[3]=s,t[4]=l,t[5]=c.phase,t[6]=u,t[7]=f,t[8]=m,t[9]=h}else u=t[6],f=t[7],m=t[8],h=t[9];let g=h,_=o.taskProgress.title,y;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Z.jsx)(js,{className:`size-4`,"aria-hidden":!0}),t[13]=y):y=t[13];let b;t[14]===f?b=t[15]:(b=f?(0,Z.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-surface-panel bg-accent motion-safe:animate-pulse`}):null,t[14]=f,t[15]=b);let x;t[16]===b?x=t[17]:(x=(0,Z.jsxs)(`span`,{className:`relative mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-full bg-accent-soft text-accent-fg`,children:[y,b]}),t[16]=b,t[17]=x);let S;t[18]===o.taskProgress.title?S=t[19]:(S=(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:o.taskProgress.title}),t[18]=o.taskProgress.title,t[19]=S);let C;t[20]===s?C=t[21]:(C=Y(`rounded-full border px-1.5 py-0.5 text-[10px] font-medium`,ei(ii(s))),t[20]=s,t[21]=C);let w=o.detailStatuses[ii(s)],T;t[22]!==C||t[23]!==w?(T=(0,Z.jsx)(`span`,{className:C,children:w}),t[22]=C,t[23]=w,t[24]=T):T=t[24];let E;t[25]!==o.taskProgress.evidence||t[26]!==g?(E=g>0?(0,Z.jsxs)(`span`,{className:`text-[11px] text-fg-muted`,children:[g,` `,o.taskProgress.evidence]}):null,t[25]=o.taskProgress.evidence,t[26]=g,t[27]=E):E=t[27];let D;t[28]!==T||t[29]!==E||t[30]!==S?(D=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[S,T,E]}),t[28]=T,t[29]=E,t[30]=S,t[31]=D):D=t[31];let O;t[32]===c.title?O=t[33]:(O=(0,Z.jsx)(`p`,{className:`mt-1 text-sm font-medium leading-5 text-fg`,children:c.title}),t[32]=c.title,t[33]=O);let k;t[34]===u?k=t[35]:(k=u?(0,Z.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs leading-5 text-fg-muted`,children:u}):null,t[34]=u,t[35]=k);let A;t[36]!==D||t[37]!==O||t[38]!==k?(A=(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[D,O,k]}),t[36]=D,t[37]=O,t[38]=k,t[39]=A):A=t[39];let j=`${r.pathname}${r.search}`,M;t[40]!==j||t[41]!==c.id?(M=tt(j,c.id),t[40]=j,t[41]=c.id,t[42]=M):M=t[42];let N=m?o.taskProgress.decide:o.taskProgress.open,P;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,Z.jsx)(we,{className:`size-3.5`,"aria-hidden":!0}),t[43]=P):P=t[43];let F;t[44]!==M||t[45]!==N?(F=(0,Z.jsxs)(p,{to:M,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-xs font-medium text-accent hover:bg-accent-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[N,P]}),t[44]=M,t[45]=N,t[46]=F):F=t[46];let I;t[47]!==A||t[48]!==F||t[49]!==x?(I=(0,Z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[x,A,F]}),t[47]=A,t[48]=F,t[49]=x,t[50]=I):I=t[50];let L;t[51]!==s||t[52]!==i?(L=(0,Z.jsx)(hc,{detail:s,language:i}),t[51]=s,t[52]=i,t[53]=L):L=t[53];let R;return t[54]!==o.taskProgress.title||t[55]!==I||t[56]!==L?(R=(0,Z.jsxs)(`section`,{className:`mb-6 rounded-xl border border-edge bg-surface-panel px-3 py-3 sm:px-4`,"aria-label":_,"aria-live":`polite`,children:[I,L]}),t[54]=o.taskProgress.title,t[55]=I,t[56]=L,t[57]=R):R=t[57],R});function _c(e){return e.language}function vc(e){return e.strength===`verified`}function yc(e){return e===-5||e===-4||e===-3?`
3
3
  `:e<0?` `:String.fromCharCode(e)}var bc={partial:!0,tokenize(e,t,n){let r=this;return i=>i===null?t(i):(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),e=>r.parser.lazy[r.now().line]?n(e):t(e))}};function xc(e){return function(t,n,r){let i=this,a=``,o=!1,s=!1,c=!1,l=e?`xopcMathFlow`:`xopcMathInline`;return u;function u(e){return t.enter(l),f(e)}function d(i){return(e?Qe(a):bt(a))?(c&&t.exit(`xopcMathValue`),t.exit(l),n(i)):r(i)}function f(n){if(n===null)return d(n);let l=yc(n);if(l===`
4
4
  `)return e&&i.interrupt||!e||o?d(n):(c&&t.exit(`xopcMathValue`),c=!1,t.attempt(bc,e=>(a+=`
@@ -57,15 +57,15 @@ Open in xopc:`)[0]))}catch{return i}if(typeof e.result==`string`)try{return I_(J
57
57
  <script>${xv(e.script,`script`)}<\/script>
58
58
  </body></html>`}function wv(e,t,n){let r=r=>{if(r.source!==e.contentWindow)return;let i=Sv(r.data);!i||i.channel!==t||n(i)};return window.addEventListener(`message`,r),()=>window.removeEventListener(`message`,r)}function Tv({leaseId:e,reference:t,sourceHash:n,preferredHeight:r,language:i}){let a=m(),o=d(),s=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(0),[u,f]=(0,Q.useState)(`booting`),[p,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),b=ra(e),x=Math.min(720,Math.max(240,r)),S=(0,Q.useMemo)(()=>crypto.randomUUID(),[c,n]),C=Qr(b.active?[`chat-preview-revision`,t.id,n]:null,()=>vv(t.id,n),{revalidateOnFocus:!1,shouldRetryOnError:!1}),w=C.data?Cv(C.data,S):void 0;(0,Q.useEffect)(()=>{let e=s.current;if(!e||!w)return;f(`booting`),h([]);let t=window.setTimeout(()=>{f(e=>e===`booting`?`timeout`:e)},7e3),n=wv(e,S,t=>{t.type===`ready`&&f(`healthy`),t.type===`resize`&&(e.style.height=`${Math.min(720,Math.max(240,t.height))}px`),t.type===`error`&&(f(`failed`),h(e=>[...e,t.diagnostic].slice(-20)))});return()=>{window.clearTimeout(t),n()}},[S,w]);let T=()=>{y(null),l(e=>e+1)},E=async()=>{if(p.length){_(`fix`),y(null);try{rm((await yv(t.id,{sourceHash:n,diagnostics:p,locale:i})).prompt)}catch(e){y(e instanceof Error?e.message:String(e))}finally{_(null)}}},D=async()=>{_(`promote`),y(null);try{let e=await bv(t.id,n);a(nt(`${o.pathname}${o.search}`,`/local-apps/${encodeURIComponent(e.id)}`))}catch(e){y(e instanceof Error?e.message:String(e))}finally{_(null)}},O=`content-block-action-scope mt-3 overflow-hidden rounded-2xl border border-edge bg-surface-panel`;if(!b.active)return(0,Z.jsxs)(`section`,{ref:b.containerRef,className:O,"data-inline-chat-preview":t.id,children:[(0,Z.jsxs)(`header`,{className:`border-b border-edge-subtle px-4 py-3`,children:[(0,Z.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:t.title}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:b.state===`queued`?i===`zh`?`正在等待预览资源`:`Waiting for a preview slot`:i===`zh`?`预览尚未加载`:`Preview not loaded`})]}),(0,Z.jsx)(`div`,{className:`grid place-items-center bg-surface-base`,style:{height:x},children:(0,Z.jsx)(vi,{variant:`secondary`,className:`min-h-11`,onClick:b.activate,children:i===`zh`?`加载交互预览`:`Load interactive preview`})})]});if(C.isLoading)return(0,Z.jsxs)(`section`,{ref:b.containerRef,className:O,"aria-busy":`true`,"aria-label":i===`zh`?`正在加载预览`:`Loading preview`,children:[(0,Z.jsx)(`div`,{className:`border-b border-edge-subtle px-4 py-3`,children:(0,Z.jsx)(Qt,{className:`h-5 w-40`})}),(0,Z.jsx)(Qt,{className:`m-3 w-[calc(100%-1.5rem)]`,style:{height:x}})]});if(!C.data||!w){let e=C.error instanceof Error?C.error.message:i===`zh`?`无法加载预览`:`Unable to load preview`;return(0,Z.jsx)(`section`,{ref:b.containerRef,className:`mt-3 rounded-2xl border border-danger/30 bg-danger-soft p-4 text-sm text-danger`,role:`alert`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Gt,{className:`size-4`}),e]})})}let k=u===`failed`||u===`timeout`,A=u===`healthy`?i===`zh`?`运行正常`:`Running`:u===`booting`?i===`zh`?`正在启动`:`Starting`:u===`timeout`?i===`zh`?`启动超时`:`Start timed out`:i===`zh`?`运行错误`:`Runtime error`;return(0,Z.jsxs)(`section`,{ref:b.containerRef,className:O,"data-inline-chat-preview":t.id,children:[(0,Z.jsxs)(`header`,{className:`flex min-w-0 flex-wrap items-center gap-2 border-b border-edge-subtle px-4 py-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:t.title}),(0,Z.jsx)(`p`,{className:Y(`mt-0.5 text-xs`,k?`text-danger`:`text-fg-muted`),"aria-live":`polite`,children:A})]}),(0,Z.jsx)(vi,{variant:`ghost`,className:`content-block-action`,onClick:T,"data-action-visible":k,title:i===`zh`?`重新加载预览`:`Reload preview`,"aria-label":i===`zh`?`重新加载预览`:`Reload preview`,children:(0,Z.jsx)(Pt,{className:`size-4`,"aria-hidden":!0})}),(0,Z.jsx)(vi,{variant:`ghost`,className:`content-block-action`,disabled:g!==null,onClick:()=>void D(),"aria-busy":g===`promote`,title:g===`promote`?i===`zh`?`保存中…`:`Saving…`:i===`zh`?`保存为应用`:`Save as app`,"aria-label":g===`promote`?i===`zh`?`保存中…`:`Saving…`:i===`zh`?`保存为应用`:`Save as app`,children:(0,Z.jsx)(It,{className:Y(`size-4`,g===`promote`&&`motion-safe:animate-pulse`),"aria-hidden":!0})})]}),(0,Z.jsxs)(`div`,{className:`relative bg-surface-base`,style:{minHeight:x},children:[(0,Z.jsx)(`iframe`,{ref:s,title:i===`zh`?`${t.title} 交互预览`:`${t.title} interactive preview`,srcDoc:w,sandbox:`allow-scripts allow-forms`,className:`block w-full border-0 bg-white`,style:{height:x}},c),u===`booting`?(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-0 grid place-items-center bg-surface-base/75`,children:(0,Z.jsx)(Qt,{className:`h-10 w-40`})}):null]}),k?(0,Z.jsx)(`footer`,{className:`border-t border-danger/20 bg-danger-soft/60 px-4 py-3`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`p`,{className:`min-w-0 flex-1 text-xs text-danger`,role:`alert`,children:p.at(-1)?.message??(i===`zh`?`预览未能正常启动`:`The preview did not start correctly`)}),(0,Z.jsxs)(vi,{variant:`secondary`,className:`min-h-11 px-3 text-xs`,disabled:!p.length||g!==null,onClick:()=>void E(),children:[(0,Z.jsx)(Yt,{className:`size-4`}),g===`fix`?i===`zh`?`生成中…`:`Preparing…`:i===`zh`?`让 AI 修复`:`Ask AI to fix`]})]})}):null,v?(0,Z.jsx)(`p`,{className:`border-t border-danger/20 px-4 py-2 text-xs text-danger`,role:`alert`,children:v}):null]})}function Ev(e){let t=(0,X.c)(8),{children:n,label:r,className:i}=e,a;t[0]===i?a=t[1]:(a=Y(`mt-2 w-full min-w-0 max-w-full self-start`,i),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=(0,Z.jsx)(`div`,{className:`min-w-0`,children:n}),t[2]=n,t[3]=o);let s;return t[4]!==r||t[5]!==a||t[6]!==o?(s=(0,Z.jsx)(`section`,{className:a,"aria-label":r,"data-turn-tail":!0,children:o}),t[4]=r,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function Dv(e){return{id:e.artifactId,name:e.title,type:e.kind,mimeType:e.mimeType,size:e.sizeBytes,uri:e.uri,workspaceRelativePath:e.workspaceRelativePath}}function Ov(e){let t=e.mimeType?.toLowerCase()??``,n=e.type?.toLowerCase()??``;return t.startsWith(`image/`)||n===`image`?De:t.startsWith(`audio/`)||n===`audio`||n===`voice`?gs:t.startsWith(`video/`)||n===`video`?ye:t.includes(`spreadsheet`)||[`spreadsheet`,`csv`,`xlsx`,`xls`].includes(n)?ve:t.includes(`zip`)||[`archive`,`zip`].includes(n)?N:n===`site`?te:Oe}function kv(e,t,n){return!!(e.uri||ui(e)||e.workspaceRelativePath?.trim()&&(t?.trim()||n?.trim()))}function Av(e){let t=(0,X.c)(43),{item:n,authToken:r,conversationId:i,projectId:a,onOpen:o}=e,s=v(jv),c;t[0]===s?c=t[1]:(c=S(s),t[0]=s,t[1]=c);let l=c.chat.productDelivery.kinds.file,u;t[2]!==r||t[3]!==i?(u={authToken:r,conversationId:i},t[2]=r,t[3]=i,t[4]=u):u=t[4];let d=Cm(n.attachment,u),f;t[5]===n.attachment?f=t[6]:(f=Ov(n.attachment),t[5]=n.attachment,t[6]=f);let p=f,m;t[7]!==i||t[8]!==n.attachment||t[9]!==a?(m=kv(n.attachment,i,a),t[7]=i,t[8]=n.attachment,t[9]=a,t[10]=m):m=t[10];let h=m,g=h||!!n.href,_;t[11]!==p||t[12]!==d.src||t[13]!==n.failed?(_=d.src?(0,Z.jsx)(`img`,{src:d.src,alt:``,className:`size-[18px] rounded object-cover`,decoding:`async`,loading:`lazy`}):(0,Z.jsx)(p,{strokeWidth:1.75,className:n.failed?`text-danger`:void 0}),t[11]=p,t[12]=d.src,t[13]=n.failed,t[14]=_):_=t[14];let y=n.attachment.name??l,b;t[15]===g?b=t[16]:(b=g?(0,Z.jsx)(ae,{className:`size-3.5 shrink-0 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}):null,t[15]=g,t[16]=b);let x;t[17]!==n.meta||t[18]!==_||t[19]!==y||t[20]!==b?(x=(0,Z.jsx)(Bo,{icon:_,title:y,meta:n.meta,trailing:b}),t[17]=n.meta,t[18]=_,t[19]=y,t[20]=b,t[21]=x):x=t[21];let C=x,w=g?`cursor-pointer`:`cursor-default`,T;t[22]===w?T=t[23]:(T=Y(zo,w),t[22]=w,t[23]=T);let E=T,D=n.attachment.name??l,O;t[24]!==n.meta||t[25]!==D?(O=[D,n.meta],t[24]=n.meta,t[25]=D,t[26]=O):O=t[26];let k=O.join(` · `);if(!h&&n.href){let e;return t[27]!==E||t[28]!==C||t[29]!==n.href||t[30]!==k?(e=(0,Z.jsx)(`li`,{className:`min-w-0 max-w-full`,"data-result-attachment":!0,children:(0,Z.jsx)(`a`,{title:k,href:n.href,target:`_blank`,rel:`noreferrer`,className:E,children:C})}),t[27]=E,t[28]=C,t[29]=n.href,t[30]=k,t[31]=e):e=t[31],e}if(!h){let e;return t[32]!==E||t[33]!==C?(e=(0,Z.jsx)(`li`,{className:E,"data-result-attachment":!0,children:C}),t[32]=E,t[33]=C,t[34]=e):e=t[34],e}let A;t[35]!==n.attachment||t[36]!==o?(A=()=>o(n.attachment),t[35]=n.attachment,t[36]=o,t[37]=A):A=t[37];let j;return t[38]!==E||t[39]!==C||t[40]!==A||t[41]!==k?(j=(0,Z.jsx)(`li`,{className:`min-w-0 max-w-full`,"data-result-attachment":!0,children:(0,Z.jsx)(`button`,{type:`button`,className:E,title:k,onClick:A,children:C})}),t[38]=E,t[39]=C,t[40]=A,t[41]=k,t[42]=j):j=t[42],j}function jv(e){return e.language}function Mv(e){let t=(0,X.c)(25),{attachments:n,authToken:r,conversationId:i,projectId:a,onOpen:o,language:s}=e,c;t[0]!==n.length||t[1]!==s?(c=S(s).chat.turnOutcome.fileCount.replace(`{{count}}`,String(n.length)),t[0]=n.length,t[1]=s,t[2]=c):c=t[2];let l=c,u;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(u=Y(zo,`cursor-pointer list-none`),t[3]=u):u=t[3];let d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(ys,{strokeWidth:1.75}),t[4]=d):d=t[4];let f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(ae,{className:`size-3.5 shrink-0 text-fg-subtle transition-transform duration-150 group-open:rotate-90 motion-reduce:transition-none`,"aria-hidden":!0}),t[5]=f):f=t[5];let p;t[6]===l?p=t[7]:(p=(0,Z.jsx)(`summary`,{className:u,children:(0,Z.jsx)(Bo,{icon:d,title:l,trailing:f})}),t[6]=l,t[7]=p);let m;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(m=Y(Uo,Ro),t[8]=m):m=t[8];let h;if(t[9]!==n||t[10]!==r||t[11]!==i||t[12]!==o||t[13]!==a){let e;t[15]!==r||t[16]!==i||t[17]!==o||t[18]!==a?(e=e=>(0,Z.jsx)(Av,{item:e,authToken:r,conversationId:i,projectId:a,onOpen:o},e.key),t[15]=r,t[16]=i,t[17]=o,t[18]=a,t[19]=e):e=t[19],h=n.map(e),t[9]=n,t[10]=r,t[11]=i,t[12]=o,t[13]=a,t[14]=h}else h=t[14];let g;t[20]===h?g=t[21]:(g=(0,Z.jsx)(`ul`,{className:m,children:h}),t[20]=h,t[21]=g);let _;return t[22]!==p||t[23]!==g?(_=(0,Z.jsx)(`li`,{className:`min-w-0 max-w-full`,"data-result-attachment-group":!0,children:(0,Z.jsxs)(`details`,{className:`group`,children:[p,g]})}),t[22]=p,t[23]=g,t[24]=_):_=t[24],_}function Nv(e,t){if(!e)return[];let n=S(t).chat.turnOutcome;return e.deliverables.map(e=>{let t=Dv(e);return{key:`outcome:${e.artifactId}`,attachment:t,href:e.shareUrl,failed:e.availability===`failed`||e.availability===`missing`,meta:[n.availability[e.availability],e.sizeBytes===void 0?null:di(e.sizeBytes)].filter(Boolean).join(` · `)}})}function Pv(e,t){let n=S(t).chat.turnOutcome;return(e??[]).map((e,t)=>({key:`attachment:${e.id??e.uri??e.name??t}`,attachment:e,meta:[n.generatedFile,typeof e.size==`number`?di(e.size):null].filter(Boolean).join(` · `)}))}function Fv(e){let t=new Set;for(let n of e?.deliverables??[])for(let e of[n.artifactId,n.sourceFileId,n.workspaceRelativePath]){let n=e?.trim();n&&t.add(`file:${n}`)}return t}function Iv(e){let t=(0,X.c)(46),{view:n,authToken:r,conversationId:i,projectId:a}=e,o=v(Vv)===`zh`?`zh`:`en`,s;t[0]!==i||t[1]!==a?(s={layout:`assistant`,conversationId:i,projectId:a},t[0]=i,t[1]=a,t[2]=s):s=t[2];let c=Em(s),l=n.deliveries.filter(Bv),u=H_(l),d=W_(l),f=G_(l),p=U_(l),m=(0,Q.useContext)($_),h=new Set(Fv(n.outcome));if(m)for(let{delivery:e,reference:t}of K_(l))t.kind===`automation`&&!t.runId&&e.operation!==`failed`&&h.add(`automation:${t.id}`);let g=K_(l,h).length,_,y,b,x;if(t[3]!==o||t[4]!==c||t[5]!==n.attachments||t[6]!==n.outcome||t[7]!==n.resultRevision){_=[...Nv(n.outcome,o),...Pv(n.attachments,o)];let e;t[12]!==n.outcome?.deliverables||t[13]!==n.resultRevision?(e=e=>!!(n.resultRevision&&n.outcome?.deliverables.some(t=>t.artifactId===e.id)),t[12]=n.outcome?.deliverables,t[13]=n.resultRevision,t[14]=e):e=t[14],y=e;let r;t[15]!==y||t[16]!==c||t[17]!==n.resultRevision?(r=e=>{c.openAttachment(e,y(e)?n.resultRevision:void 0)},t[15]=y,t[16]=c,t[17]=n.resultRevision,t[18]=r):r=t[18],b=r,x=_.filter(zv),t[3]=o,t[4]=c,t[5]=n.attachments,t[6]=n.outcome,t[7]=n.resultRevision,t[8]=_,t[9]=y,t[10]=b,t[11]=x}else _=t[8],y=t[9],b=t[10],x=t[11];let C=x,w;t[19]!==_||t[20]!==C?(w=_.filter(e=>!C.includes(e)),t[19]=_,t[20]=C,t[21]=w):w=t[21];let T=w,E=g>0||T.length>0;if(u.length===0&&d.length===0&&f.length===0&&!E&&!C.length)return null;let D;t[22]!==r||t[23]!==i||t[24]!==C?(D=C.length>0?(0,Z.jsx)(Fm,{attachments:C.map(Rv),authToken:r,conversationId:i,workspaceConversationId:i,layout:`assistant`}):null,t[22]=r,t[23]=i,t[24]=C,t[25]=D):D=t[25];let O=u.map(Lv),k;t[26]===o?k=t[27]:(k=e=>{let{key:t,presentation:n}=e;return(0,Z.jsx)(_v,{previewId:`${t}:${n.reference.id}:${n.snapshot.sourceHash}`,reference:n.reference,sourceHash:n.snapshot.sourceHash,preferredHeight:n.preferredHeight,language:o},t)},t[26]=o,t[27]=k);let A=d.map(k),j;t[28]===o?j=t[29]:(j=e=>{let{key:t,presentation:n}=e;return(0,Z.jsx)(Tv,{leaseId:`${t}:${n.reference.id}:${n.sourceHash}`,reference:n.reference,sourceHash:n.sourceHash,preferredHeight:n.preferredHeight,language:o},t)},t[28]=o,t[29]=j);let M=f.map(j),N=E?(0,Z.jsxs)(Ev,{label:S(o).chat.productDelivery.heading,children:[(0,Z.jsxs)(`ul`,{className:Uo,children:[(0,Z.jsx)(uv,{deliveries:l,language:o,excludedReferenceKeys:h,conversationId:i,projectId:a}),T.length>1?(0,Z.jsx)(Mv,{attachments:T,authToken:r,conversationId:i,projectId:a,onOpen:b,language:o}):T.map(e=>(0,Z.jsx)(Av,{item:e,authToken:r,conversationId:i,projectId:a,onOpen:b},e.key))]}),p.truncated?(0,Z.jsx)(`p`,{role:`status`,className:`mt-2 text-xs text-fg-muted`,children:S(o).chat.productDelivery.partialResults}):null]}):null,P;t[30]!==T.length||t[31]!==r||t[32]!==i||t[33]!==y||t[34]!==c.active||t[35]!==c.closePreview||t[36]!==c.open||t[37]!==n.resultRevision?(P=T.length>0?(0,Z.jsx)(za,{open:c.open,attachment:c.active,resultRevision:c.active&&y(c.active)?n.resultRevision:void 0,authToken:r,conversationId:i,onClose:c.closePreview}):null,t[30]=T.length,t[31]=r,t[32]=i,t[33]=y,t[34]=c.active,t[35]=c.closePreview,t[36]=c.open,t[37]=n.resultRevision,t[38]=P):P=t[38];let F;return t[39]!==N||t[40]!==P||t[41]!==D||t[42]!==O||t[43]!==A||t[44]!==M?(F=(0,Z.jsxs)(Z.Fragment,{children:[D,O,A,M,N,P]}),t[39]=N,t[40]=P,t[41]=D,t[42]=O,t[43]=A,t[44]=M,t[45]=F):F=t[45],F}function Lv(e){let{key:t,presentation:n}=e;return(0,Z.jsx)(hv,{presentation:n},t)}function Rv(e){return e.attachment}function zv(e){return!e.failed&&e.attachment.mimeType?.startsWith(`image/`)}function Bv(e){let{delivery:t}=e;return V_(t)}function Vv(e){return e.language}var Hv=(0,Q.createContext)({});function Uv(e){let t=(0,X.c)(16),{outcome:n}=e,r=S(v(Kv)).chat.turnOutcome,i=(0,Q.useContext)(Hv),a=!!(i.turnId&&i.turnId===n.turnId),o=n.status===`failed`&&!(a&&i.running)?(0,Z.jsx)(yh,{errorText:a&&i.error||n.summary||r.statusFailed,onRetry:a?i.onRetry:void 0}):null,s=!!n.changeSet,c=n.evidence.length>0;if(!s&&!c)return o;let l=n.evidence.filter(Gv).length,u=n.evidence.filter(Wv).length,d=n.status===`succeeded`?r.statusSucceeded:n.status===`failed`?r.statusFailed:r.statusPartial,f=n.status===`succeeded`?re:n.status===`failed`?he:q,p=[n.changeSet?r.changedFileCount.replace(`{{count}}`,String(n.changeSet.files.length)):null,l>0?r.passedCount.replace(`{{count}}`,String(l)):null,u>0?r.failedCount.replace(`{{count}}`,String(u)):null,c&&l===0&&u===0?r.evidenceCount.replace(`{{count}}`,String(n.evidence.length)):null].filter(Boolean).join(` · `),m=n.status===`succeeded`?`text-success`:n.status===`failed`?`text-danger`:`text-warning`,h;t[0]!==f||t[1]!==m?(h=(0,Z.jsx)(f,{className:m,"aria-hidden":!0}),t[0]=f,t[1]=m,t[2]=h):h=t[2];let g;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(ae,{className:`size-3.5 shrink-0 text-fg-subtle transition-transform group-open:rotate-90 motion-reduce:transition-none`,strokeWidth:1.75,"aria-hidden":!0}),t[3]=g):g=t[3];let _=Ro,y=n.changeSet?(0,Z.jsxs)(`section`,{"aria-label":r.changes,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:r.changeSetTitle}),(0,Z.jsx)(`span`,{className:`shrink-0 text-fg-subtle`,children:r.changeStats.replace(`{{files}}`,String(n.changeSet.files.length)).replace(`{{added}}`,String(n.changeSet.added)).replace(`{{removed}}`,String(n.changeSet.removed))})]}),(0,Z.jsxs)(`div`,{className:`mt-2 border-t border-edge-subtle/70 pt-2`,children:[n.changeSet.files.slice(0,8).map(e=>(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 py-1 text-xs`,children:[(0,Z.jsx)(`span`,{className:`w-14 shrink-0 text-fg-subtle`,children:r.fileStatus[e.status??`modified`]}),(0,Z.jsx)(`code`,{className:`min-w-0 truncate text-fg-muted`,children:e.path})]},e.path)),n.changeSet.files.length>8?(0,Z.jsx)(`div`,{className:`pt-1 text-xs text-fg-subtle`,children:r.moreFiles.replace(`{{count}}`,String(n.changeSet.files.length-8))}):null]}),n.changeSet.diff?(0,Z.jsxs)(`details`,{className:`mt-2`,children:[(0,Z.jsx)(`summary`,{className:`w-fit cursor-pointer rounded-md px-1.5 py-1 text-xs font-medium text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:r.viewDiff}),n.changeSet.diffTruncated?(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-warning`,children:r.diffTruncated}):null,(0,Z.jsx)(`pre`,{className:`mt-2 max-h-72 overflow-auto rounded-lg bg-surface-inset p-3 text-xs leading-5 text-fg-muted`,children:(0,Z.jsx)(`code`,{children:n.changeSet.diff})})]}):null]}):null,b;t[4]!==s||t[5]!==c?(b=s&&c?(0,Z.jsx)(`div`,{className:`my-2 border-t border-edge-subtle`}):null,t[4]=s,t[5]=c,t[6]=b):b=t[6];let x;t[7]!==c||t[8]!==n.evidence||t[9]!==r?(x=c?(0,Z.jsxs)(`section`,{"aria-label":r.evidence,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-fg`,children:r.evidence}),n.evidence.map(e=>(0,Z.jsxs)(`div`,{className:`flex min-h-10 items-center gap-2.5 border-b border-edge-subtle/60 py-1.5 last:border-b-0`,children:[(0,Z.jsx)(Ye,{className:e.status===`passed`?`size-4 shrink-0 text-success`:e.status===`failed`?`size-4 shrink-0 text-danger`:`size-4 shrink-0 text-warning`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-fg-muted`,children:e.label}),(0,Z.jsx)(`span`,{className:e.status===`passed`?`text-xs font-medium text-success`:e.status===`failed`?`text-xs font-medium text-danger`:`text-xs font-medium text-warning`,children:e.status===`passed`?r.passed:e.status===`failed`?r.failed:r.warning})]},e.evidenceId))]}):null,t[7]=c,t[8]=n.evidence,t[9]=r,t[10]=x):x=t[10];let C;return t[11]!==_||t[12]!==y||t[13]!==b||t[14]!==x?(C=(0,Z.jsxs)(`div`,{className:_,children:[y,b,x]}),t[11]=_,t[12]=y,t[13]=b,t[14]=x,t[15]=C):C=t[15],(0,Z.jsxs)(Z.Fragment,{children:[o,(0,Z.jsxs)(`details`,{className:`group mt-2 min-w-0 max-w-full text-sm`,children:[(0,Z.jsx)(`summary`,{className:`${zo} cursor-pointer list-none`,title:`${d} · ${p}`,children:(0,Z.jsx)(Bo,{icon:h,title:d,meta:p,trailing:g})}),C]})]})}function Wv(e){return e.status===`failed`}function Gv(e){return e.status===`passed`}function Kv(e){return e.language}function qv(e){let t=(0,X.c)(14),{view:n,authToken:r,conversationId:i,projectId:a,sourcesLabel:o}=e,s;t[0]!==r||t[1]!==i||t[2]!==a||t[3]!==n?(s=(0,Z.jsx)(Iv,{view:n,authToken:r,conversationId:i,projectId:a}),t[0]=r,t[1]=i,t[2]=a,t[3]=n,t[4]=s):s=t[4];let c;t[5]===n.outcome?c=t[6]:(c=n.outcome?(0,Z.jsx)(Uv,{outcome:n.outcome}):null,t[5]=n.outcome,t[6]=c);let l;t[7]!==o||t[8]!==n.sources?(l=n.sources.length>0?(0,Z.jsxs)(`details`,{className:`group min-w-0 max-w-full`,"aria-label":o,children:[(0,Z.jsx)(`summary`,{className:`${zo} cursor-pointer list-none`,children:(0,Z.jsx)(Bo,{icon:(0,Z.jsx)(Ie,{}),title:o,trailing:(0,Z.jsx)(ae,{className:`size-3.5 shrink-0 text-fg-subtle transition-transform group-open:rotate-90 motion-reduce:transition-none`,"aria-hidden":!0})})}),(0,Z.jsx)(`div`,{className:Ro,children:(0,Z.jsx)(Y_,{sources:n.sources,className:``})})]}):null,t[7]=o,t[8]=n.sources,t[9]=l):l=t[9];let u;return t[10]!==s||t[11]!==c||t[12]!==l?(u=(0,Z.jsxs)(Z.Fragment,{children:[s,c,l]}),t[10]=s,t[11]=c,t[12]=l,t[13]=u):u=t[13],u}var Jv=`NO_REPLY`;function Yv(e,t){if(e.role!==`assistant`||!e.content?.length)return e;if(t?.hideSilentReply){let n=e.content.filter(e=>e.type!==`text`||e.text.trim()!==Jv);if(n.length!==e.content.length)return Yv({...e,content:n},t)}let n=e.content.findIndex(e=>e.type===`text`);if(n<0)return e;let r=e.content[n];if(r.type!==`text`)return e;let i=r.text.trimStart();if(t?.hideSilentReply&&(i===Jv||t.streaming&&i.length>0&&Jv.startsWith(i)))return{...e,content:e.content.filter((e,t)=>t!==n)};if(!i.startsWith(Jv))return e;if(i.length===8)return e.content.slice(n+1).some(e=>e.type===`text`&&e.text.trim().length>0)?{...e,content:e.content.filter((e,t)=>t!==n)}:e;let a=i.slice(8).trimStart();if(!a)return e;let o=[...e.content];return o[n]={...r,text:a},{...e,content:o}}function Xv(e,t){return t||e.workLog.items.some(e=>e.type===`tool_use`&&(e.status===`error`||e.activity?.status===`failed`))}function Zv(e,t){if(e.role!==`assistant`||t.isStreaming||t.followUpTrigger)return!0;let n=J_({message:Yv(e,{hideSilentReply:!0}),...t});return!!(n.answerContent.some(e=>e.type===`review`||e.type===`text`&&e.text.trim())||n.attachments?.length||n.deliveries.length||n.sources.length||n.outcome&&(n.outcome.status===`failed`||n.outcome.changeSet||n.outcome.evidence.length||n.outcome.deliverables.length)||e.taskResultDelivery||e.personalProvenance||Xv(n,t.showAssistantWorkLog)&&n.workLog.items.some(e=>t.personal||!n.workLog.compact&&t.showAssistantWorkLog||e.type===`tool_use`&&(e.status===`error`||e.activity?.status===`failed`)))}function Qv(e,t){let n=fr(e.content).some(e=>e.type===`review`&&(!e.status||e.status===`complete`)||e.type===`text`&&!!e.text.trim()),r=e.fromHistory&&n,i=e.outcome??e.taskResultDelivery?.outcome,a=!t&&e.runStatus!==`suspended`&&!!(e.runStatus||i||r),o=e.runStatus===`error`||e.runStatus===`cancelled`||i?.status===`failed`;return{settled:a,defaultCollapsed:a&&n&&!o,outcome:i}}function $v(e){let t=(0,X.c)(17),{message:n,isStreaming:r,enabled:i,items:a,durationMs:o}=e,s=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),f=v(ey),p=S(f).chat,m;t[0]!==r||t[1]!==n?(m=Qv(n,r),t[0]=r,t[1]=n,t[2]=m):m=t[2];let h=m,g=i&&h.settled&&a.length>0,_,y;t[3]===r?(_=t[4],y=t[5]):(_=()=>{r&&d(null)},y=[r],t[3]=r,t[4]=_,t[5]=y),(0,Q.useEffect)(_,y);let b,x;t[6]!==i||t[7]!==a.length?(b=()=>{if(!i||a.length===0)return;let e=()=>{let e=window.getSelection();l(!!(s.current&&[...s.current.querySelectorAll(`[data-assistant-process-item]`)].some(t=>e&&!e.isCollapsed&&e.containsNode(t,!0)||t.contains(document.activeElement))))};return e(),document.addEventListener(`selectionchange`,e),document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,e),()=>{document.removeEventListener(`selectionchange`,e),document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,e)}},x=[i,a.length],t[6]=i,t[7]=a.length,t[8]=b,t[9]=x):(b=t[8],x=t[9]),(0,Q.useEffect)(b,x);let C=u??(!h.defaultCollapsed||c),w=o==null?null:Gg(o,f),T=n.runStatus===`cancelled`?p.processStopped:n.runStatus===`error`||h.outcome?.status===`failed`?p.processFailed:h.outcome?.status===`partial`?p.processPartial:null,E=T?`${T}${w?` · ${w}`:``}`:w?p.processWorkedFor.replace(`{{duration}}`,w):p.processView,D=g&&!C,O;t[10]!==C||t[11]!==E||t[12]!==g?(O=g?(0,Z.jsxs)(`button`,{type:`button`,"data-assistant-process-toggle":!0,"aria-expanded":C,onClick:()=>d(!C),className:`flex min-h-11 w-full items-center gap-1.5 border-b border-edge-subtle py-2 text-left text-sm text-fg-muted hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,children:[(0,Z.jsx)(`span`,{children:E}),(0,Z.jsx)(ae,{"aria-hidden":!0,className:`size-4 shrink-0 transition-transform motion-reduce:transition-none ${C?`rotate-90`:``}`})]}):null,t[10]=C,t[11]=E,t[12]=g,t[13]=O):O=t[13];let k;return t[14]!==D||t[15]!==O?(k={contentRef:s,collapsed:D,summary:O},t[14]=D,t[15]=O,t[16]=k):k=t[16],k}function ey(e){return e.language}function ty(e,t=!1){return t||e.textSurface===`conversation`}function ny(e){let t=e.trim().split(/[,,;;。\n]/,1)[0]?.trim()||e.trim(),n=Array.from(t);return n.length>32?`${n.slice(0,32).join(``)}…`:t}function ry(e){let t=(0,X.c)(23),{trigger:n}=e,r=d(),i=v(iy),a;t[0]===i?a=t[1]:(a=S(i),t[0]=i,t[1]=a);let o=a.chat.taskTrigger,s=n.entryId,c;t[2]===o.about?c=t[3]:(c=(0,Z.jsx)(`span`,{className:`shrink-0`,children:o.about}),t[2]=o.about,t[3]=c);let l=`${r.pathname}${r.search}`,u;t[4]!==l||t[5]!==n.taskId?(u=et(l,n.taskId),t[4]=l,t[5]=n.taskId,t[6]=u):u=t[6];let f=n.taskTitle,m=`${o.openTask}:${n.taskTitle}`,h;t[7]===n.taskTitle?h=t[8]:(h=ny(n.taskTitle),t[7]=n.taskTitle,t[8]=h);let g;t[9]===h?g=t[10]:(g=(0,Z.jsxs)(`span`,{className:`truncate`,children:[`「`,h,`」`]}),t[9]=h,t[10]=g);let _;t[11]!==u||t[12]!==m||t[13]!==g||t[14]!==n.taskTitle?(_=(0,Z.jsx)(p,{className:`inline-flex min-w-0 max-w-[min(48vw,30rem)] font-medium text-fg hover:text-accent hover:underline`,to:u,title:f,"aria-label":m,children:g}),t[11]=u,t[12]=m,t[13]=g,t[14]=n.taskTitle,t[15]=_):_=t[15];let y=o[n.kind],b;t[16]===y?b=t[17]:(b=(0,Z.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap`,children:[`· `,y]}),t[16]=y,t[17]=b);let x;return t[18]!==_||t[19]!==b||t[20]!==c||t[21]!==n.entryId?(x=(0,Z.jsxs)(`div`,{className:`mb-4 flex min-w-0 max-w-full items-center gap-1.5 border-t border-edge-subtle pt-5 text-sm text-fg-muted`,"data-task-trigger":s,children:[c,_,b]}),t[18]=_,t[19]=b,t[20]=c,t[21]=n.entryId,t[22]=x):x=t[22],x}function iy(e){return e.language}var ay=3;function oy(e){let t=(0,X.c)(36),{refs:n,groupLabel:r,noteLabel:i,fileLabel:a,folderLabel:o,sessionLabel:s,browserTabLabel:c,mcpResourceLabel:l,truncatedLabel:u,showMoreLabel:d,showLessLabel:f,onOpen:p}=e,[m,h]=(0,Q.useState)(!1);if(n.length===0)return null;let g=n.length>ay,_;t[0]!==m||t[1]!==n?(_=m?n:n.slice(0,ay),t[0]=m,t[1]=n,t[2]=_):_=t[2];let v=_,y=n.length-ay,b;if(t[3]!==c||t[4]!==a||t[5]!==o||t[6]!==r||t[7]!==l||t[8]!==i||t[9]!==p||t[10]!==s||t[11]!==u||t[12]!==v){let e;t[14]!==c||t[15]!==a||t[16]!==o||t[17]!==r||t[18]!==l||t[19]!==i||t[20]!==p||t[21]!==s||t[22]!==u?(e=e=>{let t=e.kind===`note`,n=t?`button`:`div`,d=e.kind===`result`?a:e.kind===`file`?e.fileKind===`directory`?o:a:e.kind===`session`?s:e.kind===`browser_tab`?c:e.kind===`mcp_resource`?l:i;return(0,Z.jsxs)(n,{...t?{type:`button`,onClick:()=>p(e)}:{},className:Y(`group inline-flex min-h-9 min-w-0 max-w-full items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel/80 px-2 py-1.5 text-left`,t&&`transition-colors hover:border-accent/40 hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),...t?{"aria-label":`${r}: ${e.title}`}:{},title:e.truncated?u:e.title,children:[(0,Z.jsx)(`span`,{className:`inline-flex size-7 shrink-0 items-center justify-center rounded-md bg-accent-soft text-accent-fg`,children:e.kind===`file`&&e.fileKind===`directory`?(0,Z.jsx)(je,{className:`size-3.5`,"aria-hidden":!0}):e.kind===`file`||e.kind===`result`?(0,Z.jsx)(Oe,{className:`size-3.5`,"aria-hidden":!0}):e.kind===`session`?(0,Z.jsx)(wt,{className:`size-3.5`,"aria-hidden":!0}):e.kind===`browser_tab`?(0,Z.jsx)(M,{className:`size-3.5`,"aria-hidden":!0}):e.kind===`mcp_resource`?(0,Z.jsx)(Se,{className:`size-3.5`,"aria-hidden":!0}):(0,Z.jsx)(Os,{className:`size-3.5`,"aria-hidden":!0})}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-fg-muted`,children:d}),(0,Z.jsx)(`span`,{className:`max-w-56 truncate text-xs font-medium text-fg sm:max-w-72`,children:e.title})]}),t?(0,Z.jsx)(ae,{className:`size-3.5 shrink-0 text-fg-disabled transition-transform group-hover:translate-x-0.5 group-hover:text-fg-muted`,"aria-hidden":!0}):null]},`${e.kind}:${e.sourceId}`)},t[14]=c,t[15]=a,t[16]=o,t[17]=r,t[18]=l,t[19]=i,t[20]=p,t[21]=s,t[22]=u,t[23]=e):e=t[23],b=v.map(e),t[3]=c,t[4]=a,t[5]=o,t[6]=r,t[7]=l,t[8]=i,t[9]=p,t[10]=s,t[11]=u,t[12]=v,t[13]=b}else b=t[13];let x;t[24]===b?x=t[25]:(x=(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-wrap gap-1.5`,children:b}),t[24]=b,t[25]=x);let S;t[26]!==g||t[27]!==m||t[28]!==y||t[29]!==f||t[30]!==d?(S=g?(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex min-h-8 w-fit items-center gap-1 rounded-md px-2 text-xs text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-expanded":m,onClick:()=>h(sy),children:[m?(0,Z.jsx)(oe,{className:`size-3.5`,"aria-hidden":!0}):(0,Z.jsx)(ie,{className:`size-3.5`,"aria-hidden":!0}),m?f:d.replace(`{{count}}`,String(y))]}):null,t[26]=g,t[27]=m,t[28]=y,t[29]=f,t[30]=d,t[31]=S):S=t[31];let C;return t[32]!==r||t[33]!==x||t[34]!==S?(C=(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,role:`group`,"aria-label":r,children:[x,S]}),t[32]=r,t[33]=x,t[34]=S,t[35]=C):C=t[35],C}function sy(e){return!e}function cy(e,t){let n=new Map;for(let r of e){let e=r.sourceName.trim(),i=r.statement.trim().replace(/\s+/g,` `),a=r.origin===`connected_source`?`${r.origin}:${e}`:r.origin,o=r.origin===`connected_source`?t.connected_source.replace(`{{source}}`,e):t[r.origin],s=n.get(a);s?s.items.some(e=>e.statement.trim().replace(/\s+/g,` `)===i)||s.items.push(r):n.set(a,{id:a,label:o,items:[r]})}return Array.from(n.values())}function ly(e){let t=(0,X.c)(67),{open:n,onOpenChange:r,items:i,labels:a}=e,o;t[0]!==i||t[1]!==a.origins?(o=cy(i,a.origins),t[0]=i,t[1]=a.origins,t[2]=o):o=t[2];let s=o,c=s.reduce(py,0),l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=new Set,t[3]=l):l=t[3];let[u,d]=(0,Q.useState)(l),f,p;t[4]!==c||t[5]!==s||t[6]!==n?(f=()=>{!n||s.length===0||d(new Set(c<=6?s.map(fy):[s[0].id]))},p=[c,s,n],t[4]=c,t[5]=s,t[6]=n,t[7]=f,t[8]=p):(f=t[7],p=t[8]),(0,Q.useEffect)(f,p);let m;t[9]!==u||t[10]!==s?(m=s.length>0&&s.every(e=>u.has(e.id)),t[9]=u,t[10]=s,t[11]=m):m=t[11];let h=m,g;t[12]!==h||t[13]!==s?(g=()=>{d(h?new Set:new Set(s.map(dy)))},t[12]=h,t[13]=s,t[14]=g):g=t[14];let _=g,v;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(v=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},t[15]=v):v=t[15];let y=v,b;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[80] bg-scrim/60 backdrop-blur-[1px]`}),t[16]=b):b=t[16];let x;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(x=Y(`xopc-dialog-content fixed left-1/2 top-1/2 z-[90] flex h-[min(36rem,calc(100dvh-2rem))]`,`w-[min(42rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-overlay shadow-popover outline-none`),t[17]=x):x=t[17];let S;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Z.jsx)(`span`,{className:`mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg bg-accent-soft text-accent-fg`,children:(0,Z.jsx)(ms,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})}),t[18]=S):S=t[18];let w;t[19]===a.title?w=t[20]:(w=(0,Z.jsx)(k,{className:`text-base font-semibold text-fg`,children:a.title}),t[19]=a.title,t[20]=w);let j;t[21]===a.hint?j=t[22]:(j=(0,Z.jsx)(T,{className:`mt-1 text-sm leading-5 text-fg-muted`,children:a.hint}),t[21]=a.hint,t[22]=j);let M;t[23]!==c||t[24]!==a.itemsSummary?(M=a.itemsSummary.replace(`{{count}}`,String(c)),t[23]=c,t[24]=a.itemsSummary,t[25]=M):M=t[25];let N;t[26]===M?N=t[27]:(N=(0,Z.jsx)(`p`,{className:`mt-2 text-xs font-medium text-fg-subtle`,children:M}),t[26]=M,t[27]=N);let P;t[28]!==w||t[29]!==j||t[30]!==N?(P=(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[w,j,N]}),t[28]=w,t[29]=j,t[30]=N,t[31]=P):P=t[31];let F;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,Z.jsx)(Xt,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[32]=F):F=t[32];let I;t[33]===a.close?I=t[34]:(I=(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-colors duration-150 hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":a.close,title:a.close,children:F})}),t[33]=a.close,t[34]=I);let L;t[35]!==P||t[36]!==I?(L=(0,Z.jsxs)(`header`,{className:`flex shrink-0 items-start gap-3 border-b border-edge-subtle px-4 py-4 sm:px-5`,children:[S,P,I]}),t[35]=P,t[36]=I,t[37]=L):L=t[37];let R;t[38]!==s.length||t[39]!==a.groupSummary?(R=a.groupSummary.replace(`{{count}}`,String(s.length)),t[38]=s.length,t[39]=a.groupSummary,t[40]=R):R=t[40];let z;t[41]===R?z=t[42]:(z=(0,Z.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:R}),t[41]=R,t[42]=z);let B;t[43]!==h||t[44]!==s.length||t[45]!==a.collapseAll||t[46]!==a.expandAll||t[47]!==_?(B=s.length>1?(0,Z.jsx)(`button`,{type:`button`,className:`rounded-md px-2 py-1 text-xs font-medium text-accent-fg transition-colors duration-150 hover:bg-accent-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:_,children:h?a.collapseAll:a.expandAll}):null,t[43]=h,t[44]=s.length,t[45]=a.collapseAll,t[46]=a.expandAll,t[47]=_,t[48]=B):B=t[48];let ee;t[49]!==z||t[50]!==B?(ee=(0,Z.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between gap-3 border-b border-edge-subtle px-4 sm:px-5`,children:[z,B]}),t[49]=z,t[50]=B,t[51]=ee):ee=t[51];let V;if(t[52]!==u||t[53]!==s){let e;t[55]===u?e=t[56]:(e=e=>{let t=u.has(e.id);return(0,Z.jsxs)(`section`,{className:`overflow-hidden rounded-xl border border-edge-subtle bg-surface-panel`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`flex min-h-12 w-full items-center gap-3 px-3.5 py-2.5 text-left transition-colors duration-150 hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,"aria-expanded":t,onClick:()=>y(e.id),children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-fg`,children:e.label}),(0,Z.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-hover px-2 py-0.5 text-[11px] tabular-nums text-fg-muted`,children:e.items.length}),(0,Z.jsx)(ie,{className:Y(`size-4 shrink-0 text-fg-subtle transition-transform duration-200`,t&&`rotate-180`),strokeWidth:1.75,"aria-hidden":!0})]}),t?(0,Z.jsx)(`div`,{className:`border-t border-edge-subtle px-3.5`,children:e.items.map(uy)}):null]},e.id)},t[55]=u,t[56]=e),V=s.map(e),t[52]=u,t[53]=s,t[54]=V}else V=t[54];let H;t[57]===V?H=t[58]:(H=(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-3 sm:px-4`,"data-testid":`response-context-scroll-region`,children:(0,Z.jsx)(`div`,{className:`space-y-2`,children:V})}),t[57]=V,t[58]=H);let U;t[59]!==L||t[60]!==ee||t[61]!==H?(U=(0,Z.jsxs)(D,{children:[b,(0,Z.jsxs)(O,{className:x,children:[L,ee,H]})]}),t[59]=L,t[60]=ee,t[61]=H,t[62]=U):U=t[62];let W;return t[63]!==r||t[64]!==n||t[65]!==U?(W=(0,Z.jsx)(A,{open:n,onOpenChange:r,children:U}),t[63]=r,t[64]=n,t[65]=U,t[66]=W):W=t[66],W}function uy(e){return(0,Z.jsx)(`p`,{className:`border-b border-edge-subtle py-3 text-sm leading-6 text-fg last:border-b-0`,children:e.statement},e.id)}function dy(e){return e.id}function fy(e){return e.id}function py(e,t){return e+t.items.length}var my=Y(`inline-flex size-11 shrink-0 items-center justify-center rounded-lg sm:size-9`,`text-fg-muted transition-colors transition-transform duration-150 ease-out`,`hover:bg-surface-hover hover:text-fg active:scale-95`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,ca.disabled),hy=[`misunderstood_intent`,`incorrect`,`did_not_act`,`tone_mismatch`,`too_verbose`,`other`],gy=Y(`inline-flex h-8 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-xs text-fg-muted transition-colors`,`hover:bg-surface-hover hover:text-fg active:scale-[0.98]`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,ca.disabled),_y=700,vy=120,yy=(0,Q.memo)(function({message:e,personal:t=!1,followUpTrigger:n,authToken:r,conversationId:i,workspaceConversationId:a,projectId:o,isStreaming:s,progress:c,reasoningLevel:l=`on`,messageIndex:u,onDeleteRound:f,onRetryUserMessageRound:p,userMessageCanRetry:h=!1,deleteRoundDisabled:_=!1,onSaveAssistantAsNote:b,onSaveAssistantToSourceNote:x,onExtractAssistantTask:C,onForkAssistantTurn:w,readonly:T=!1,density:E=`normal`,suppressAssistantActions:D=!1,onEditUserMessage:O,userMessageCanEdit:k=!0,responseFeedbackEnabled:A=!0,showAssistantWorkLog:j=!0}){let M=(0,Q.useMemo)(()=>Yv(e,{hideSilentReply:ty(e,t),streaming:s}),[e,t,s]),N=v(e=>e.language),P=S(N),F=m(),I=d(),z=M.role===`user`,B=M.role===`assistant`,H=(0,Q.useRef)(z&&M.deliveryStatus===`sending`).current,W=z&&M.deliveryStatus===`sending`,te=z&&M.deliveryStatus===`failed`,[ne,ae]=(0,Q.useState)(!1),[se,ce]=(0,Q.useState)(!1),[le,ue]=(0,Q.useState)(()=>typeof navigator<`u`&&navigator.onLine===!1),de=z?P.chat.you:B?P.chat.assistant:P.chat.tool;(0,Q.useEffect)(()=>{if(!W||typeof window>`u`)return;let e=()=>ue(window.navigator.onLine===!1);return window.addEventListener(`online`,e),window.addEventListener(`offline`,e),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,e)}},[W]),(0,Q.useEffect)(()=>{if(W){if(ne)return;let e=window.setTimeout(()=>ae(!0),le?0:_y);return()=>window.clearTimeout(e)}if(!ne)return;let e=0,t=window.requestAnimationFrame(()=>{ce(!0),e=window.setTimeout(()=>{ae(!1),ce(!1)},vy)});return()=>{window.cancelAnimationFrame(t),window.clearTimeout(e)}},[W,le,ne]);let G=te||ne,K=te?`failed`:`sending`,fe=(0,Q.useCallback)(e=>{let t=`${I.pathname}${I.search}`;F(Ct(t,e))},[I.pathname,I.search,F]),pe=(0,Q.useMemo)(()=>({input:P.chat.toolInput,output:P.chat.toolOutput,noOutput:P.chat.noOutput}),[P.chat.toolInput,P.chat.toolOutput,P.chat.noOutput]),me=(0,Q.useMemo)(()=>({thoughts:P.chat.thoughts,thoughtsStreaming:P.chat.thoughtsStreaming,workLogTitle:P.chat.workLogTitle,workLogRunning:P.chat.workLogRunning,workLogComplete:P.chat.workLogComplete,workLogPartial:P.chat.workLogPartial,workLogFailed:P.chat.workLogFailed,searchedWeb:P.chat.stepSearchedWeb,searchedMemory:P.chat.stepSearchedMemory,searchedCode:P.chat.stepSearchedCode,searched:P.chat.stepSearched,readFile:P.chat.stepReadFile,stepDetails:P.chat.stepDetails,runCommand:P.chat.stepRunCommand,listDirectory:P.chat.stepListDirectory,writeFile:P.chat.stepWriteFile,editFile:P.chat.stepEditFile,openUrl:P.chat.stepOpenUrl,fetchUrl:P.chat.stepFetchUrl,unknownTool:P.chat.stepUnknownTool,rawThinking:P.chat.rawThinking,toolError:P.chat.toolError,toolActivity:P.chat.toolActivity,memoryActivity:P.chat.memoryActivity}),[P.chat.thoughts,P.chat.thoughtsStreaming,P.chat.workLogTitle,P.chat.workLogRunning,P.chat.workLogComplete,P.chat.workLogPartial,P.chat.workLogFailed,P.chat.stepSearchedWeb,P.chat.stepSearchedMemory,P.chat.stepSearchedCode,P.chat.stepSearched,P.chat.stepReadFile,P.chat.stepDetails,P.chat.stepRunCommand,P.chat.stepListDirectory,P.chat.stepWriteFile,P.chat.stepEditFile,P.chat.stepOpenUrl,P.chat.stepFetchUrl,P.chat.stepUnknownTool,P.chat.rawThinking,P.chat.toolError,P.chat.toolActivity,P.chat.memoryActivity]),J=(0,Q.useMemo)(()=>({ing:P.chat.stepsClusterIng}),[P.chat.stepsClusterIng]),he=(0,Q.useMemo)(()=>P.chat.toolCard,[P.chat.toolCard]),ge=l===`off`,_e=(0,Q.useMemo)(()=>B?J_({message:M,isStreaming:s,reasoningLevel:l,personal:t}):null,[B,s,M,l,t]),ve=(0,Q.useMemo)(()=>{if(!_e)return(M.content??[]).filter(e=>e.type!==`image`);if(t)return _e.answerContent;if(!ge&&j)return(M.content??[]).filter(e=>e.type!==`image`);let e=new Set(_e.answerContent);return(M.content??[]).filter(t=>e.has(t)||t.type===`tool_use`&&(t.status===`error`||t.activity?.status===`failed`))},[_e,M.content,t,ge,j]),ye=(0,Q.useMemo)(()=>_e?_e.attachments:M.attachments,[_e,M.attachments]),be=B&&!t&&!ge&&j,Se=$v({message:M,isStreaming:s,enabled:be,items:_e?.workLog.items??[],durationMs:M.completedAt==null?void 0:_e?.workLog.durationMs}),we=(0,Q.useMemo)(()=>be?new Set(_e?.workLog.items):void 0,[be,_e]),Ee=(0,Q.useMemo)(()=>{let e=new Set(M.userTurnDocument?.parts.flatMap(e=>e.type===`context_ref`?[e.refId]:[])??[]);return M.contextRefs?.filter(t=>!t.refId||!e.has(t.refId))},[M.contextRefs,M.userTurnDocument]),De=!!(_e?.workLog.active||_e?.workLog.items.length),ke=!!_e?.answer.started,Ae=ge||B&&(De||ke)?null:c,je=!ge&&!!M.content?.some(e=>e.type===`thinking`&&e.streaming),Me=B?!!_e?.answer.showStreamingCursor:s,Ne=t&&B&&s&&!_e?.answer.started&&!ye?.length,Pe=s&&!je&&(!B||!De&&!ke),Fe=!!Ae?.message||Pe,Ie=B&&!T&&!s&&!D,Le=B&&s&&!T&&!D&&ke,Re=(0,Q.useMemo)(()=>Ie?Bm(M.content??[]):``,[Ie,M]),ze=(0,Q.useMemo)(()=>Ie&&Re?Hm(M.content??[]):``,[Ie,Re,M]),Be=(0,Q.useMemo)(()=>Ie&&Re?V(Re):``,[Ie,Re]),Ve=(0,Q.useMemo)(()=>({source:{type:`chat-message`,id:`${i??`chat`}:${M.timestamp??u??Re.length}`,title:Be.split(`
59
59
  `)[0]?.slice(0,48)||P.chat.messageReadAloudTitle,href:i?`#/chat/${encodeURIComponent(i)}`:void 0,targetId:u==null?void 0:`chat-message-${u}`},text:Be,language:R(Be,N)}),[Re.length,N,P.chat.messageReadAloudTitle,M.timestamp,u,i,Be]),He=(0,Q.useMemo)(()=>{if(!z)return``;if(M.userTurnDocument){let e=new Map(M.contextRefs?.flatMap(e=>e.refId?[[e.refId,e.title]]:[])??[]);return xn(M.userTurnDocument,t=>e.get(t))}return Wn(M.content)},[z,M.content,M.contextRefs,M.userTurnDocument]),[Ue,We]=(0,Q.useState)(null),[Ge,Ke]=(0,Q.useState)(!1),[qe,Je]=(0,Q.useState)(null),[Ye,Ze]=(0,Q.useState)(null),[Qe,$e]=(0,Q.useState)(!1),[et,tt]=(0,Q.useState)(null),[nt,rt]=(0,Q.useState)(!1),[it,at]=(0,Q.useState)(!1),[ot,st]=(0,Q.useState)(!1),[ct,lt]=(0,Q.useState)(!1),[ut,dt]=(0,Q.useState)(null),[ft,pt]=(0,Q.useState)([]),[mt,ht]=(0,Q.useState)(!1),[gt,_t]=(0,Q.useState)(!1),[vt,yt]=(0,Q.useState)(null),[bt,xt]=(0,Q.useState)(!1),[St,wt]=(0,Q.useState)(!1),Tt=(0,Q.useRef)(null),Et=(0,Q.useCallback)((e,t)=>{let n=Rm(e,t);n&&yt(n)},[]),Dt=(0,Q.useCallback)(()=>{!i||!M.renderKey||Sn.getState().completeProgressiveRender(i,M.renderKey)},[M.renderKey,i]),Ot=(0,Q.useCallback)(()=>{ze&&Oi(ze).then(e=>{e&&(We(`plain`),window.setTimeout(()=>We(e=>e===`plain`?null:e),2e3))})},[ze]),kt=(0,Q.useCallback)(()=>{Re&&Oi(Re).then(e=>{e&&(We(`markdown`),window.setTimeout(()=>We(e=>e===`markdown`?null:e),2e3))})},[Re]),At=(0,Q.useCallback)(()=>{!Re||!b||Ye||(Ze(`create-note`),Promise.resolve(b(Re)).then(()=>{Je(`create-note`),window.setTimeout(()=>Je(e=>e===`create-note`?null:e),2e3)}).catch(()=>void 0).finally(()=>Ze(null)))},[Ye,Re,b]),Mt=(0,Q.useCallback)(()=>{!Re||!x||Ye||(Ze(`save-source-note`),Promise.resolve(x(Re)).then(()=>{Je(`save-source-note`),window.setTimeout(()=>Je(e=>e===`save-source-note`?null:e),2e3)}).catch(()=>void 0).finally(()=>Ze(null)))},[Ye,Re,x]),Nt=(0,Q.useCallback)(()=>{!ze&&!Re||!C||Ye||(Ze(`extract-task`),Promise.resolve(C(ze||Re)).then(()=>{Je(`extract-task`),window.setTimeout(()=>Je(e=>e===`extract-task`?null:e),2e3)}).catch(()=>void 0).finally(()=>Ze(null)))},[Ye,Re,ze,C]),Ft=(0,Q.useCallback)(()=>{He&&Oi(He).then(e=>{e&&(We(`user`),window.setTimeout(()=>We(e=>e===`user`?null:e),2e3))})},[He]),It=(0,Q.useCallback)(()=>{!M.turnId||!w||Qe||($e(!0),Promise.resolve(w(M.turnId)).catch(()=>void 0).finally(()=>$e(!1)))},[Qe,M.turnId,w]),Lt=(0,Q.useCallback)((e,t)=>{!M.turnId||it||(at(!0),rt(!0),st(!1),y(g(`/api/turns/${encodeURIComponent(M.turnId)}/execution-context/feedback`),{method:`POST`,body:JSON.stringify({rating:e===`helpful`?`helpful`:`irrelevant`,reason:t})}).then(()=>{tt(e),dt(t??null),lt(!1)}).catch(()=>st(!0)).finally(()=>at(!1)))},[M.turnId,it]),Rt=(0,Q.useCallback)(()=>{ut&&rm(P.chat.messageFeedbackRepairPrompts[ut])},[P.chat.messageFeedbackRepairPrompts,ut]),zt=(0,Q.useCallback)(()=>{!M.turnId||nt||it||(at(!0),y(g(`/api/turns/${encodeURIComponent(M.turnId)}/execution-context`)).then(e=>{pt(e.resolvedItems.filter(e=>e.included).map(e=>({id:`${e.objectType}:${e.objectId}`,statement:e.content,origin:e.origin,sourceName:e.sourceLabel})))}).catch(()=>void 0).finally(()=>{rt(!0),at(!1)}))},[M.turnId,it,nt]),Bt=(0,Q.useCallback)(()=>{u==null||!f||_t(!0)},[u,f]),Vt=(0,Q.useCallback)(()=>{u==null||!f||(f(u),_t(!1))},[u,f]),Ht=(0,Q.useCallback)(()=>{_t(!1)},[]);(0,Q.useLayoutEffect)(()=>{if(!z)return;let e=Tt.current;if(!e)return;let t=()=>{let t=window.getComputedStyle(e),n=Number.parseFloat(t.lineHeight),r=Number.parseFloat(t.fontSize)||14,i=Number.isFinite(n)?n:r*1.625;wt(e.scrollHeight>i*10+1)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[z,ve,He]),(0,Q.useLayoutEffect)(()=>{xt(!1)},[z,He]);let Ut=_||!h,Gt=_e&&Xv(_e,j)&&(_e.workLog.active||_e.workLog.items.length>0)?(0,Z.jsx)(t_,{workLog:_e.workLog,pendingStatus:M.pendingResponseStatus,toolLabels:pe,stepLabels:me,clusterLabels:J,cardLabels:he,conversationId:i,simplified:!t,personal:t,surfacesOnly:!t,answerStarted:_e.answer.started}):null;return(0,Z.jsx)(bd.Provider,{value:xd(_e?.deliveries??[]),children:(0,Z.jsxs)(`article`,{className:Y(`group/msg flex w-full min-w-0`,z?`justify-end`:`justify-start`,H&&`xopc-chat-user-message-enter`),children:[(0,Z.jsxs)(`div`,{className:Y(`min-w-0`,z?`flex w-full max-w-[min(78%,var(--max-width-chat-user))] flex-col items-end`:`w-full max-w-[var(--max-width-chat-reading)]`,T&&`max-w-full`),children:[(0,Z.jsx)(`span`,{className:`sr-only`,children:de}),n?(0,Z.jsx)(ry,{trigger:n}):null,z&&Fe?(0,Z.jsxs)(`div`,{className:`mb-2 flex w-full min-w-0 flex-wrap items-center justify-end gap-x-2 gap-y-0.5 text-xs`,children:[Ae?.message&&!De?(0,Z.jsx)(`span`,{className:`text-fg-subtle`,title:Ae.detail??``,children:Ae.message}):null,Pe&&!Ae?.message?(0,Z.jsx)(`span`,{className:`text-fg-subtle`,children:P.chat.thinkingLabel}):null]}):null,!z&&Fe&&!Ne?(0,Z.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-xs text-fg-disabled`,children:[Ae?.message&&!De?(0,Z.jsx)(`span`,{className:`text-fg-subtle`,title:Ae.detail??``,children:Ae.message}):null,Pe&&!Ae?.message?(0,Z.jsx)(`span`,{className:`text-fg-subtle`,children:P.chat.thinkingLabel}):null]}):null,(0,Z.jsx)(`div`,{dir:z?`auto`:void 0,className:Y(`min-w-0 text-fg`,z&&`chat-user-message`,E===`compact`?`text-sm leading-relaxed`:z?`text-[0.9375rem] leading-[1.6667]`:`text-base leading-[1.6875]`,z&&`w-fit max-w-full rounded-2xl bg-surface-hover/80 px-4 py-3 text-left dark:bg-surface-hover/50`,Ne&&`bg-transparent p-0`),children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[Ne?(0,Z.jsx)(`div`,{className:`xopc-personal-thinking`,role:`status`,"aria-label":P.chat.thinkingLabel,children:(0,Z.jsxs)(`span`,{className:`xopc-personal-thinking-dots`,"aria-hidden":`true`,children:[(0,Z.jsx)(`i`,{}),(0,Z.jsx)(`i`,{}),(0,Z.jsx)(`i`,{})]})}):null,t?Gt:null,(ve?.length??0)>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{ref:z?Tt:Se.contentRef,"data-chat-find-text":!0,className:Y(`relative min-w-0`,`flex flex-col gap-3`,z&&!bt&&`overflow-hidden`),style:z&&!bt?{maxHeight:`calc(10lh)`}:void 0,children:[Se.summary,(0,Z.jsx)(Hh,{taskRunId:M.taskResultDelivery?.taskRunId,content:ve,isUser:z,isAssistantMessageStreaming:B&&s,imagePreviewLabel:P.chat.attachmentPreviewImage,onImagePreview:Et,conversationId:i,workspaceConversationId:a,projectId:o,progressiveRender:!!M.progressiveRender,onProgressiveRenderComplete:Dt,userTurnDocument:M.userTurnDocument,contextRefs:M.contextRefs,responseRunId:B?M.turnId:void 0,immediateFirstCommit:!0,processItems:we,processCollapsed:Se.collapsed,renderActivity:!t&&_e?(e,t)=>{let n=s&&(t||e.some(e=>e.type===`tool_use`&&e.status===`running`)),r=j_(e);return(0,Z.jsx)(t_,{workLog:{items:e,active:n,status:n?`running`:e.some(e=>e.type===`tool_use`&&(e.status===`error`||e.activity?.status===`failed`))?`failed`:`completed`,compact:!1,expandedByDefault:l===`stream`&&n,startedAt:r.startedAt,durationMs:r.durationMs},toolLabels:pe,stepLabels:me,clusterLabels:J,cardLabels:he,conversationId:i,simplified:!1,showThinking:!0,renderSurfaces:!1})}:void 0}),Me?(0,Z.jsx)(`span`,{"aria-hidden":!0,"data-chat-streaming-cursor":!0,className:`pointer-events-none absolute start-0 top-full mt-1 h-3 w-0.5 bg-accent opacity-60`}):null]}),z&&St?(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex w-fit items-center gap-1 rounded-md px-1.5 py-1 text-xs font-medium text-accent transition-colors hover:bg-accent/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,onClick:()=>xt(e=>!e),"aria-expanded":bt,children:[bt?(0,Z.jsx)(oe,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(ie,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:bt?P.chat.userMessageCollapse:P.chat.userMessageExpand})]}):null]}):null,t?null:Gt,!t&&_e&&!_e.answer.started&&s&&!ve.some(e=>e.type===`thinking`||e.type===`tool_use`)?(0,Z.jsx)(t_,{workLog:{items:[],active:!0,status:`running`,compact:!0,expandedByDefault:!1},pendingStatus:M.pendingResponseStatus,toolLabels:pe,stepLabels:me,clusterLabels:J,cardLabels:he,conversationId:i}):null,!t&&!z&&M.taskResultDelivery&&i?(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,"data-result-follow-up":!0,children:[M.taskResultDelivery.resultRevision?(0,Z.jsxs)(`span`,{className:`text-xs text-fg-muted`,"data-result-revision":!0,children:[N===`zh`?`成果版本`:`Result version`,` `,M.taskResultDelivery.resultRevision]}):null,[{sourceId:`body`,title:M.taskResultDelivery.taskTitle},...M.taskResultDelivery.outcome.deliverables.filter(e=>e.availability===`available`).map(e=>({sourceId:e.artifactId,title:e.title}))].map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`max-w-64 truncate rounded-md border border-edge-subtle px-2 py-1 text-xs text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:()=>{let t=M.taskResultDelivery;window.dispatchEvent(new CustomEvent(`chat-result-reference`,{detail:{conversationId:i,reference:{kind:`result`,sourceId:Vs(t.deliveryId.replace(/^reply:/,``),e.sourceId),expectedVersion:Hs(t),title:e.title}}}))},children:[N===`zh`?`询问:`:`Ask about: `,e.title]},e.sourceId))]}):null,_e?(0,Z.jsx)(qv,{view:_e,authToken:r,conversationId:a??i,projectId:o,sourcesLabel:P.chat.searchSourcesHeading.replace(`{{count}}`,String(_e.sources.length))}):null,z&&M.sourceDevice?(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:[N===`zh`?`来自 `:`From `,M.sourceDevice.name]}):null,z&&Ee?.length?(0,Z.jsx)(oy,{refs:Ee,groupLabel:P.chat.commandPalette.contextLabel,noteLabel:P.chat.commandPalette.notesSection,fileLabel:P.chat.atMention.files,folderLabel:P.chat.atMention.folders,sessionLabel:P.chat.atMention.chats,browserTabLabel:P.chat.atMention.browserTabs,mcpResourceLabel:P.chat.atMention.mcpResources,truncatedLabel:P.chat.commandPalette.contextTruncated,showMoreLabel:P.chat.contextReferencesMore,showLessLabel:P.chat.contextReferencesLess,onOpen:e=>fe(e.sourceId)}):null,z&&ye?.length?(0,Z.jsx)(Fm,{attachments:ye,authToken:r,conversationId:i,workspaceConversationId:a,layout:`user`,centerUserVoiceRow:He.length===0}):null]})}),G?(0,Z.jsxs)(`div`,{"data-delivery-status":K,role:te?`alert`:`status`,"aria-live":`polite`,"aria-hidden":se&&!te?!0:void 0,className:Y(`mt-1 flex min-h-5 items-center justify-end gap-1.5 pe-1 text-xs transition-opacity duration-[120ms] ease-out motion-reduce:transition-none`,te?`text-danger`:`text-fg-subtle`,se&&!te&&`opacity-0`),children:[te?(0,Z.jsx)(q,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}):null,(0,Z.jsx)(`span`,{children:te?P.chat.userMessageSendFailed:le&&W?P.chat.userMessageWaitingForNetwork:P.chat.userMessageSending}),te&&p&&u!=null?(0,Z.jsx)(`button`,{type:`button`,className:`rounded-md px-1.5 py-0.5 font-medium text-danger underline-offset-2 hover:bg-danger/10 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-danger/40`,onClick:()=>p(u),children:P.chat.userMessageRetry}):null]}):null,!z&&M.personalProvenance&&!s&&(0,Z.jsx)(xm,{provenance:M.personalProvenance}),z&&!s&&!T?(0,Z.jsxs)(`div`,{"data-user-message-actions":!0,className:Y(`mt-1 flex h-8 w-full min-w-0 shrink-0 items-center justify-end gap-0.5 sm:gap-2`,`pointer-events-none opacity-0 transition-opacity duration-150 ease-out`,`group-hover/msg:pointer-events-auto group-hover/msg:opacity-100`,`group-focus-within/msg:pointer-events-auto group-focus-within/msg:opacity-100`,`[@media(hover:none)_and_(pointer:coarse)]:pointer-events-auto [@media(hover:none)_and_(pointer:coarse)]:opacity-100`),children:[p&&u!=null&&M.deliveryStatus!==`failed`?(0,Z.jsxs)(`button`,{type:`button`,className:Y(gy,Ut&&`opacity-40`),onClick:()=>p(u),disabled:Ut,title:_?P.chat.userMessageActionsWait:h?P.chat.userMessageRetry:P.chat.userMessageRetryDisabledHint,"aria-label":P.chat.userMessageRetry,children:[(0,Z.jsx)(Pt,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`max-w-[4.5rem] truncate sm:max-w-none`,children:P.chat.userMessageRetry})]}):null,(0,Z.jsx)(`button`,{type:`button`,className:Y(gy,`size-8 px-0`),onClick:()=>{if(O&&u!=null){O(M,u);return}rm(He,Kn(M.attachments))},disabled:!He&&!M.attachments?.length&&!M.contextRefs?.length||!k,title:k?_?P.chat.userMessageStopAndEdit:P.chat.userMessageEdit:P.chat.userMessageEditDisabledHint,"aria-label":P.chat.userMessageEdit,children:(0,Z.jsx)(jt,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})}),(0,Z.jsx)(`button`,{type:`button`,className:Y(gy,`size-8 px-0`),onClick:Ft,disabled:!He,title:Ue===`user`?P.chat.messageCopied:P.chat.userMessageCopy,"aria-label":Ue===`user`?P.chat.messageCopied:P.chat.userMessageCopy,children:Ue===`user`?(0,Z.jsx)(re,{className:`size-3.5 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(xe,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})}),f&&u!=null&&!_?(0,Z.jsx)(`button`,{type:`button`,className:Y(gy,`size-8 px-0 hover:text-red-500 dark:hover:text-red-400`),onClick:Bt,title:P.chat.userMessageDelete,"aria-label":P.chat.userMessageDelete,children:(0,Z.jsx)(Wt,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})}):null]}):null,Le?(0,Z.jsx)(`div`,{"data-assistant-actions-placeholder":!0,className:`mt-1 min-h-9 shrink-0`,"aria-hidden":`true`}):null,Ie&&Re?(0,Z.jsx)(k_,{children:(0,Z.jsxs)(`div`,{"data-assistant-message-actions":!0,className:Y(`mt-1 flex min-h-9 shrink-0 items-center gap-1 overflow-visible transition-opacity duration-150 ease-out motion-reduce:transition-none`,`pointer-events-none opacity-0 group-hover/msg:pointer-events-auto group-hover/msg:opacity-100`,`group-focus-within/msg:pointer-events-auto group-focus-within/msg:opacity-100`,`[@media(hover:none)_and_(pointer:coarse)]:pointer-events-auto [@media(hover:none)_and_(pointer:coarse)]:opacity-100`,(Ge||ct||ot)&&`pointer-events-auto opacity-100`),children:[(0,Z.jsx)(A_,{label:Ue===`plain`?P.chat.messageCopied:P.chat.messageCopyPlainText,children:(0,Z.jsx)(`button`,{type:`button`,className:my,onClick:Ot,disabled:!ze,"aria-label":Ue===`plain`?P.chat.messageCopied:P.chat.messageCopyPlainText,children:Ue===`plain`?(0,Z.jsx)(re,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(xe,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})})}),(0,Z.jsx)(A_,{label:P.chat.messageReadAloud,children:(0,Z.jsx)(L,{input:Ve,labels:{read:P.chat.messageReadAloud,preparing:P.chat.messageReadAloudPreparing,pause:P.chat.messageReadAloudPause,resume:P.chat.messageReadAloudResume,retry:P.chat.messageReadAloudRetry},hideNativeTitle:!0})}),(0,Z.jsxs)(Si,{open:Ge,onOpenChange:e=>{Ke(e),e&&zt()},children:[(0,Z.jsx)(A_,{label:P.chat.messageMoreActions,children:(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:my,"aria-label":P.chat.messageMoreActions,children:(0,Z.jsx)(Ce,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})})})}),(0,Z.jsx)(bi,{children:(0,Z.jsxs)(xi,{side:`bottom`,align:`start`,sideOffset:6,className:`z-[70] w-56 rounded-xl border border-edge bg-surface-overlay p-1.5 shadow-popover outline-none`,children:[(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:kt,children:[Ue===`markdown`?(0,Z.jsx)(re,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(Te,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),Ue===`markdown`?P.chat.messageCopied:P.chat.messageCopyMarkdown]})}),w&&M.turnId?(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:It,disabled:Qe,children:[(0,Z.jsx)(xs,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),Qe?P.chat.messageForkCreating:P.chat.messageForkFromHere]})}):null,b?(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:At,disabled:Ye!==null,children:[qe===`create-note`?(0,Z.jsx)(re,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(vs,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),qe===`create-note`?P.chat.messageSavedToNote:P.chat.messageSaveToNote]})}):null,A&&i&&M.timestamp?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`my-1 border-t border-edge-subtle`,role:`separator`}),(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:()=>Lt(`helpful`),disabled:it,"aria-pressed":et===`helpful`,children:[(0,Z.jsx)(ee,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),P.chat.messageHelpful]})}),(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:()=>lt(e=>!e),disabled:it,"aria-pressed":et===`not_helpful`,children:[(0,Z.jsx)(U,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),P.chat.messageNotHelpful]})})]}):null,ot?(0,Z.jsx)(`p`,{className:`px-2.5 py-1 text-xs text-danger`,role:`status`,children:P.chat.messageFeedbackUnavailable}):null,ft.length>0?(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:()=>ht(e=>!e),children:[(0,Z.jsx)(ms,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),P.chat.messageWhyThisAnswer]})}):null,x?(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg disabled:opacity-40`,onClick:Mt,disabled:!Re||Ye!==null,children:[qe===`save-source-note`?(0,Z.jsx)(re,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(Oe,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),qe===`save-source-note`?P.chat.messageSavedToSourceNote:P.chat.messageSaveToSourceNote]})}):null,C?(0,Z.jsx)(Ci,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-xs text-fg-muted hover:bg-surface-hover hover:text-fg disabled:opacity-40`,onClick:Nt,disabled:!ze&&!Re||Ye!==null,children:[qe===`extract-task`?(0,Z.jsx)(re,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(Xe,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),qe===`extract-task`?P.chat.messageTaskExtracted:P.chat.messageExtractTask]})}):null]})})]})]})}):null,Ie&&ft.length>0?(0,Z.jsx)(ly,{open:mt,onOpenChange:ht,items:ft,labels:{title:P.chat.messageWhyThisAnswer,hint:P.chat.messageWhyThisAnswerHint,close:P.chat.messageContextClose,itemsSummary:P.chat.messageContextItemsSummary,expandAll:P.chat.messageContextExpandAll,collapseAll:P.chat.messageContextCollapseAll,groupSummary:P.chat.messageContextGroupSummary,origins:P.chat.messageContextOrigins}}):null,Ie&&ct?(0,Z.jsxs)(`div`,{className:`mt-2 w-full max-w-xl rounded-xl border border-edge-subtle bg-surface-panel p-3`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:P.chat.messageFeedbackReasonTitle}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:P.chat.messageFeedbackReasonHint}),(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:hy.map(e=>(0,Z.jsx)(`button`,{type:`button`,className:`rounded-lg border border-edge bg-surface-panel px-2.5 py-1.5 text-xs font-medium text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg`,disabled:it,onClick:()=>Lt(`not_helpful`,e),children:P.chat.messageFeedbackReasons[e]},e))})]}):null,Ie&&et===`not_helpful`&&ut?(0,Z.jsxs)(`button`,{type:`button`,className:`mt-2 inline-flex w-fit items-center gap-1.5 rounded-lg bg-accent-soft px-3 py-1.5 text-xs font-medium text-accent-fg hover:bg-accent-soft/80`,onClick:Rt,children:[(0,Z.jsx)(Pt,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),P.chat.messageFeedbackRepair]}):null]}),z&&f&&u!=null&&!T?(0,Z.jsx)(Wa,{open:gt,title:P.chat.userMessageDeleteConfirmTitle,description:P.chat.userMessageDeleteConfirm,confirmLabel:P.chat.userMessageDeleteOk,cancelLabel:P.chat.userMessageDeleteCancel,destructive:!0,onConfirm:Vt,onCancel:Ht}):null,(0,Z.jsx)(za,{open:vt!==null,attachment:vt,images:(M.content??[]).flatMap((e,t)=>{if(e.type!==`image`)return[];let n=Rm(e,t);return n?[n]:[]}),onAttachmentChange:yt,authToken:r,conversationId:i,onClose:()=>yt(null)})]})})}),by=(0,Q.memo)(function(e){let t=(0,X.c)(3),n=eh(e.conversationId,e.message.renderKey)??e.message,r;return t[0]!==n||t[1]!==e?(r=(0,Z.jsx)(yy,{...e,message:n}),t[0]=n,t[1]=e,t[2]=r):r=t[2],r});function xy(e,t){return e.renderKey??`${e.timestamp??`n`}-${t}`}var Sy=new Map;function Cy(e,t=`time`){let n=`${e??`default`}:${t}`,r=Sy.get(n);return r||(r=new Intl.DateTimeFormat(e===`zh`?`zh-CN`:e,t===`time`?{hour:`2-digit`,minute:`2-digit`}:{month:`short`,day:`numeric`,year:t===`year`?`numeric`:void 0}),Sy.set(n,r)),r}function wy(e){return e?Cy().format(e):``}var Ty=1800*1e3;function Ey(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function Dy(e,t){return e?!t||!Ey(new Date(e),new Date(t))||e-t>=Ty:!1}function Oy(e,t,n){let r=new Date(e),i=new Date(t),a=new Date(i);return a.setDate(i.getDate()-1),`${Ey(r,i)?n===`zh`?`今天`:`Today`:Ey(r,a)?n===`zh`?`昨天`:`Yesterday`:Cy(n,r.getFullYear()===i.getFullYear()?`date`:`year`).format(r)} ${Cy(n).format(r)}`}var ky=0,Ay=1,jy=2,My=4;function Ny(e){return()=>e}function Py(e){e()}function Fy(e,t){return n=>e(t(n))}function Iy(e,t){return()=>e(t)}function Ly(e,t){return n=>e(t,n)}function Ry(e){return e!==void 0}function zy(...e){return()=>{e.map(Py)}}function By(){}function Vy(e,t){return t(e),e}function Hy(e,t){return t(e)}function Uy(...e){return e}function Wy(e,t){return e(Ay,t)}function Gy(e,t){e(ky,t)}function Ky(e){e(jy)}function qy(e){return e(My)}function Jy(e,t){return Wy(e,Ly(t,ky))}function Yy(e,t){let n=e(Ay,e=>{n(),t(e)});return n}function Xy(e){let t,n;return r=>i=>{t=i,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Zy(e,t){return e===t}function Qy(e=Zy){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function $y(e){return t=>n=>{e(n)&&t(n)}}function eb(e){return t=>Fy(t,e)}function tb(e){return t=>()=>{t(e)}}function $(e,...t){let n=ob(...t);return((t,r)=>{switch(t){case jy:Ky(e);return;case Ay:return Wy(e,n(r))}})}function nb(e,t){return n=>r=>{n(t=e(t,r))}}function rb(e){return t=>n=>{e>0?e--:t(n)}}function ib(e){let t=null,n;return r=>i=>{t=i,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function ab(...e){let t=Array.from({length:e.length}),n=0,r=null,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;Wy(e,e=>{let s=n;n|=o,t[a]=e,s!==i&&n===i&&r&&(r(),r=null)})}),e=>a=>{let o=()=>{e([a].concat(t))};n===i?o():r=o}}function ob(...e){return t=>e.reduceRight(Hy,t)}function sb(e){let t,n,r=()=>t?.();return function(i,a){switch(i){case Ay:return a?n===a?void 0:(r(),n=a,t=Wy(e,a),t):(r(),By);case jy:r(),n=null;return}}}function cb(e){let t=e,n=ub();return((e,r)=>{switch(e){case ky:t=r;break;case Ay:r(t);break;case My:return t}return n(e,r)})}function lb(e,t){return Vy(cb(t),t=>Jy(e,t))}function ub(){let e=[];return((t,n)=>{switch(t){case ky:e.slice().forEach(e=>{e(n)});return;case jy:e.splice(0);return;case Ay:return e.push(n),()=>{let t=e.indexOf(n);t>-1&&e.splice(t,1)}}})}function db(e){return Vy(ub(),t=>Jy(e,t))}var fb={singleton:!0};function pb(e,t=[],n=fb){let{singleton:r}=n;return{constructor:e,dependencies:t,id:mb(),singleton:r}}var mb=()=>Symbol(`id`);function hb(e){let t=new Map,n=({constructor:e,dependencies:r,id:i,singleton:a})=>{if(a&&t.has(i))return t.get(i);let o=e(r.map(e=>n(e)));return a&&t.set(i,o),o};return n(e)}function gb(...e){let t=ub(),n=Array.from({length:e.length}),r=0,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;Wy(e,e=>{n[a]=e,r|=o,r===i&&Gy(t,n)})}),function(e,a){switch(e){case jy:Ky(t);return;case Ay:return r===i&&a(n),Wy(t,a)}}}function _b(e,t=Zy){return $(e,Qy(t))}function vb(...e){return function(t,n){switch(t){case jy:return;case Ay:return zy(...e.map(e=>Wy(e,n)))}}}var yb={DEBUG:0,INFO:1,WARN:2,ERROR:3},bb={[yb.DEBUG]:`debug`,[yb.ERROR]:`error`,[yb.INFO]:`log`,[yb.WARN]:`warn`},xb=()=>typeof globalThis>`u`?window:globalThis,Sb=pb(()=>{let e=cb(yb.ERROR);return{log:cb((t,n,r=yb.INFO)=>{r>=(xb().VIRTUOSO_LOG_LEVEL??qy(e))&&console[bb[r]](`%creact-virtuoso: %c%s %o`,`color: #0253b3; font-weight: bold`,`color: initial`,t,n)}),logLevel:e}},[],{singleton:!0});function Cb(e){return`self`in e?e.document.documentElement:e}function wb(e){let t=Cb(e);return t.ownerDocument.defaultView.getComputedStyle(t).direction===`rtl`}function Tb(e,t){return wb(e)?-t:t}function Eb(e,t){return wb(e)?-t:t}function Db(e,t,n){return Ob(e,t,n).callbackRef}function Ob(e,t,n){let r=Q.useRef(null),i=e=>{},a=Q.useMemo(()=>typeof ResizeObserver<`u`?new ResizeObserver(t=>{let r=()=>{let n=t[0].target;n.offsetParent!==null&&e(n)};n?r():requestAnimationFrame(r)}):null,[e,n]);return i=e=>{e&&t?(a?.observe(e),r.current=e):(r.current&&a?.unobserve(r.current),r.current=null)},{callbackRef:i,ref:r}}function kb(e,t,n,r,i,a,o,s,c){return Ob(Q.useCallback(n=>{let c=Ab(n.children,t,s?`offsetWidth`:`offsetHeight`,i),l=n.parentElement;for(;l.dataset.virtuosoScroller===void 0;)l=l.parentElement;let u=l.lastElementChild?.dataset.viewportType===`window`,d;u&&(d=l.ownerDocument.defaultView);let f=o?s?o.scrollWidth:o.scrollHeight:u?s?d.document.documentElement.scrollWidth:d.document.documentElement.scrollHeight:s?l.scrollWidth:l.scrollHeight,p=o?s?o.offsetWidth:o.offsetHeight:u?s?d.innerWidth:d.innerHeight:s?l.offsetWidth:l.offsetHeight,m=o?s?Tb(o,o.scrollLeft):o.scrollTop:u?s?Tb(d,d.scrollX||d.document.documentElement.scrollLeft):d.scrollY||d.document.documentElement.scrollTop:s?Tb(l,l.scrollLeft):l.scrollTop;r({scrollHeight:f,scrollTop:Math.max(m,0),viewportHeight:p}),a?.(s?jb(`column-gap`,getComputedStyle(n).columnGap,i):jb(`row-gap`,getComputedStyle(n).rowGap,i)),c!==null&&e(c)},[e,t,i,a,o,r,s]),n,c)}function Ab(e,t,n,r){let i=e.length;if(i===0)return null;let a=[];for(let o=0;o<i;o++){let i=e.item(o);if(i.dataset.index===void 0)continue;let s=parseInt(i.dataset.index,10),c=parseFloat(i.dataset.knownSize),l=t(i,n);if(l===0&&r(`Zero-sized element, this should not happen`,{child:i},yb.ERROR),l===c)continue;let u=a[a.length-1];a.length===0||u.size!==l||u.endIndex!==s-1?a.push({endIndex:s,size:l,startIndex:s}):a[a.length-1].endIndex++}return a}function jb(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,yb.WARN),t===`normal`?0:parseInt(t??`0`,10)}var Mb=typeof document>`u`?Q.useEffect:Q.useLayoutEffect;function Nb(e,t,n){let r=Q.useRef(null),i=Q.useCallback(n=>{if(!n?.offsetParent)return;let i=n.getBoundingClientRect(),a=i.width,s,c;if(t){let e=t.getBoundingClientRect(),n=i.top-e.top;c=e.height-Math.max(0,n),s=n+t.scrollTop}else{let e=o.current.ownerDocument.defaultView;c=e.innerHeight-Math.max(0,i.top),s=i.top+e.scrollY}r.current={listHeight:i.height,offsetTop:s,visibleHeight:c,visibleWidth:a},e(r.current)},[e,t]),{callbackRef:a,ref:o}=Ob(i,!0,n),s=Q.useCallback(()=>{i(o.current)},[i,o]);return Q.useEffect(()=>{if(t){t.addEventListener(`scroll`,s);let e=new ResizeObserver(()=>{requestAnimationFrame(s)});return e.observe(t),()=>{t.removeEventListener(`scroll`,s),e.unobserve(t)}}let e=o.current?.ownerDocument.defaultView;return e?.addEventListener(`scroll`,s),e?.addEventListener(`resize`,s),()=>{e?.removeEventListener(`scroll`,s),e?.removeEventListener(`resize`,s)}},[s,t,o]),a}var Pb=pb(()=>{let e=ub(),t=ub(),n=cb(0),r=ub(),i=ub(),a=cb(0),o=ub(),s=ub(),c=cb(0),l=cb(0),u=cb(0),d=cb(0),f=ub(),p=ub(),m=cb(!1),h=cb(!1),g=cb(!1);return Jy($(e,eb(({scrollTop:e})=>e)),t),Jy($(e,eb(({scrollHeight:e})=>e)),s),Jy(t,a),{deviation:n,deviationCommitted:r,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:c,horizontalDirection:h,scrollBy:p,scrollContainerState:e,scrollHeight:s,scrollingInProgress:m,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:i,statefulScrollTop:a,viewportHeight:o}},[],{singleton:!0}),Fb={lvl:0};function Ib(e,t){let n=e.length;if(n===0)return[];let{index:r,value:i}=t(e[0]),a=[];for(let o=1;o<n;o++){let{index:n,value:s}=t(e[o]);a.push({end:n-1,start:r,value:i}),r=n,i=s}return a.push({end:1/0,start:r,value:i}),a}function Lb(e){return e===Fb}function Rb(e,t){if(!Lb(e))return t===e.k?e.v:t<e.k?Rb(e.l,t):Rb(e.r,t)}function zb(e,t,n=`k`){if(Lb(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){let r=zb(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return zb(e.l,t,n)}function Bb(e,t,n){return Lb(e)?Zb(t,n,1):t===e.k?qb(e,{k:t,v:n}):t<e.k?Qb(qb(e,{l:Bb(e.l,t,n)})):Qb(qb(e,{r:Bb(e.r,t,n)}))}function Vb(){return Fb}function Hb(e,t,n){if(Lb(e))return[];let r=zb(e,t)[0];return tx(Gb(e,r,n))}function Ub(e,t){if(Lb(e))return Fb;let{k:n,l:r,r:i}=e;if(t===n){if(Lb(r))return i;if(Lb(i))return r;let[t,n]=Xb(r);return Kb(qb(e,{k:t,l:Jb(r),v:n}))}return Kb(t<n?qb(e,{l:Ub(r,t)}):qb(e,{r:Ub(i,t)}))}function Wb(e){return Lb(e)?[]:[...Wb(e.l),{k:e.k,v:e.v},...Wb(e.r)]}function Gb(e,t,n){if(Lb(e))return[];let{k:r,l:i,r:a,v:o}=e,s=[];return r>t&&(s=s.concat(Gb(i,t,n))),r>=t&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(Gb(a,t,n))),s}function Kb(e){let{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Yb(t))return $b(qb(e,{lvl:n-1}));if(!Lb(t)&&!Lb(t.r))return qb(t.r,{l:qb(t,{r:t.r.l}),lvl:n,r:qb(e,{l:t.r.r,lvl:n-1})});throw Error(`Unexpected empty nodes`)}if(Yb(e))return ex(qb(e,{lvl:n-1}));if(!Lb(r)&&!Lb(r.l)){let t=r.l,i=Yb(t)?r.lvl-1:r.lvl;return qb(t,{l:qb(e,{lvl:n-1,r:t.l}),lvl:t.lvl+1,r:ex(qb(r,{l:t.r,lvl:i}))})}throw Error(`Unexpected empty nodes`)}function qb(e,t){return Zb(t.k===void 0?e.k:t.k,t.v===void 0?e.v:t.v,t.lvl===void 0?e.lvl:t.lvl,t.l===void 0?e.l:t.l,t.r===void 0?e.r:t.r)}function Jb(e){return Lb(e.r)?e.l:Kb(qb(e,{r:Jb(e.r)}))}function Yb(e){return Lb(e)||e.lvl>e.r.lvl}function Xb(e){return Lb(e.r)?[e.k,e.v]:Xb(e.r)}function Zb(e,t,n,r=Fb,i=Fb){return{k:e,l:r,lvl:n,r:i,v:t}}function Qb(e){return ex($b(e))}function $b(e){let{l:t}=e;return!Lb(t)&&t.lvl===e.lvl?qb(t,{r:qb(e,{l:t.r})}):e}function ex(e){let{lvl:t,r:n}=e;return!Lb(n)&&!Lb(n.r)&&n.lvl===t&&n.r.lvl===t?qb(n,{l:qb(e,{r:n.l}),lvl:t+1}):e}function tx(e){return Ib(e,({k:e,v:t})=>({index:e,value:t}))}function nx(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function rx(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}var ix=pb(()=>({recalcInProgress:cb(!1)}),[],{singleton:!0});function ax(e,t,n){return e[ox(e,t,n)]}function ox(e,t,n,r=0){let i=e.length-1;for(;r<=i;){let a=Math.floor((r+i)/2),o=e[a],s=n(o,t);if(s===0)return a;if(s===-1){if(i-r<2)return a-1;i=a-1}else{if(i===r)return a;r=a+1}}throw Error(`Failed binary finding record in array - ${e.join(`,`)}, searched for ${t}`)}function sx(e,t,n,r){let i=ox(e,t,r),a=ox(e,n,r,i);return e.slice(i,a+1)}function cx(e,t){return Math.round(e.getBoundingClientRect()[t])}function lx(e){return!Lb(e.groupOffsetTree)}function ux({index:e},t){return t===e?0:t<e?-1:1}function dx(){return{groupIndices:[],groupOffsetTree:Vb(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Vb()}}function fx(e,t){let n=Lb(e)?0:1/0;for(let r of t){let{endIndex:t,size:i,startIndex:a}=r;if(n=Math.min(n,a),Lb(e)){e=Bb(e,0,i);continue}let o=Hb(e,a-1,t+1);if(o.some(wx(r)))continue;let s=!1,c=!1;for(let{end:n,start:r,value:a}of o)s?(t>=r||i===a)&&(e=Ub(e,r)):(c=a!==i,s=!0),n>t&&t>=r&&a!==i&&(e=Bb(e,t+1,a));c&&(e=Bb(e,a,i))}return[e,n]}function px(e){return e.groupIndex!==void 0}function mx({offset:e},t){return t===e?0:t<e?-1:1}function hx(e,t,n){if(t.length===0)return 0;let{index:r,offset:i,size:a}=ax(t,e,ux),o=e-r,s=a*o+(o-1)*n+i;return s>0?s+n:s}function gx(e,t){if(!lx(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function _x(e,t,n){if(px(e))return t.groupIndices[e.groupIndex]+1;let r=gx(e.index===`LAST`?n:e.index,t);return r=Math.max(0,Math.min(n,r)),r}function vx(e,t,n,r=0){return r>0&&(t=Math.max(t,ax(e,r,ux).offset)),Ib(sx(e,t,n,mx),Cx)}function yx(e,[t,n,r,i]){t.length>0&&r(`received item sizes`,t,yb.DEBUG);let a=e.sizeTree,o=a,s=0;if(n.length>0&&Lb(a)&&t.length===2){let e=t[0].size,r=t[1].size;o=n.reduce((t,n)=>Bb(Bb(t,n,e),n+1,r),o)}else[o,s]=fx(o,t);if(o===a)return e;let{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d}=Sx(e.offsetTree,s,o,i);return{groupIndices:n,groupOffsetTree:n.reduce((e,t)=>Bb(e,t,hx(t,d,i)),Vb()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d,sizeTree:o}}function bx(e){return Wb(e).map(({k:e,v:t},n,r)=>{let i=r[n+1];return{endIndex:i===void 0?1/0:i.k-1,size:t,startIndex:e}})}function xx(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function Sx(e,t,n,r){let i=e,a=0,o=0,s=0,c=0;if(t===0)i=[];else{c=ox(i,t-1,ux),s=i[c].offset;let e=zb(n,t-1);a=e[0],o=e[1],i.length&&i[c].size===zb(n,t)[1]&&--c,i=i.slice(0,c+1)}for(let{start:e,value:c}of Hb(n,t,1/0)){let t=e-a,n=t*o+s+t*r;i.push({index:e,offset:n,size:c}),a=e,s=n,o=c}return{lastIndex:a,lastOffset:s,lastSize:o,offsetTree:i}}function Cx(e){return{index:e.index,value:e}}function wx(e){let{endIndex:t,size:n,startIndex:r}=e;return e=>e.start===r&&(e.end===t||e.end===1/0)&&e.value===n}var Tx={offsetHeight:`height`,offsetWidth:`width`},Ex=pb(([{log:e},{recalcInProgress:t}])=>{let n=ub(),r=ub(),i=lb(r,0),a=ub(),o=ub(),s=cb(0),c=cb([]),l=cb(void 0),u=cb(void 0),d=cb(void 0),f=cb(void 0),p=cb((e,t)=>cx(e,Tx[t])),m=cb(void 0),h=cb(0),g=dx(),_=lb($(n,ab(c,e,h),nb(yx,g),Qy()),g),v=lb($(c,Qy(),nb((e,t)=>({current:t,prev:e.current}),{current:[],prev:[]}),eb(({prev:e})=>e)),[]);Jy($(c,$y(e=>e.length>0),ab(_,h),eb(([e,t,n])=>{let r=e.reduce((e,r,i)=>Bb(e,r,hx(r,t.offsetTree,n)||i),Vb());return{...t,groupIndices:e,groupOffsetTree:r}})),_),Jy($(r,ab(_),$y(([e,{lastIndex:t}])=>e<t),eb(([e,{lastIndex:t,lastSize:n}])=>[{endIndex:t,size:n,startIndex:e}])),n),Jy(l,u);let y=lb($(l,eb(e=>e===void 0)),!0);Jy($(u,$y(e=>e!==void 0&&Lb(qy(_).sizeTree)),eb(e=>{let t=qy(d),n=qy(c).length>0;return t!==void 0&&t!==0?n?[{endIndex:0,size:t,startIndex:0},{endIndex:1,size:e,startIndex:1}]:[]:[{endIndex:0,size:e,startIndex:0}]})),n),Jy($(f,$y(e=>e!==void 0&&e.length>0&&Lb(qy(_).sizeTree)),eb(e=>{let t=[],n=e[0],r=0;for(let i=1;i<e.length;i++){let a=e[i];a!==n&&(t.push({endIndex:i-1,size:n,startIndex:r}),n=a,r=i)}return t.push({endIndex:e.length-1,size:n,startIndex:r}),t})),n),Jy($(c,ab(d,u),$y(([,e,t])=>e!==void 0&&t!==void 0),eb(([e,t,n])=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=e[i+1];r.push({startIndex:a,endIndex:a,size:t}),o!==void 0&&r.push({startIndex:a+1,endIndex:o-1,size:n})}return r})),n);let b=db($(n,ab(_),nb(({sizes:e},[t,n])=>({changed:n!==e,sizes:n}),{changed:!1,sizes:g}),eb(e=>e.changed)));Wy($(s,nb((e,t)=>({diff:e.prev-t,prev:t}),{diff:0,prev:0}),eb(e=>e.diff)),e=>{let{groupIndices:n}=qy(_);if(e>0)Gy(t,!0),Gy(a,e+xx(e,n));else if(e<0){let t=qy(v);t.length>0&&(e-=xx(-e,t)),Gy(o,e)}}),Wy($(s,ab(e)),([e,t])=>{e<0&&t("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:s},yb.ERROR)});let x=db(a);Jy($(a,ab(_),eb(([e,t])=>{let n=t.groupIndices.length>0,r=[],i=t.lastSize;if(n){let n=Rb(t.sizeTree,0),a=0,o=0;for(;a<e;){let e=t.groupIndices[o],s=t.groupIndices.length===o+1?1/0:t.groupIndices[o+1]-e-1;r.push({endIndex:e,size:n,startIndex:e}),r.push({endIndex:e+1+s-1,size:i,startIndex:e+1}),o++,a+=s+1}let s=Wb(t.sizeTree);return a!==e&&s.shift(),s.reduce((t,{k:n,v:r})=>{let i=t.ranges;return t.prevSize!==0&&(i=[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]),{prevIndex:n+e,prevSize:r,ranges:i}},{prevIndex:e,prevSize:0,ranges:r}).ranges}return Wb(t.sizeTree).reduce((t,{k:n,v:r})=>({prevIndex:n+e,prevSize:r,ranges:[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]}),{prevIndex:0,prevSize:i,ranges:[]}).ranges})),n);let S=db($(o,ab(_,h),eb(([e,{offsetTree:t},n])=>hx(-e,t,n))));return Jy($(o,ab(_,h),eb(([e,t,n])=>{if(t.groupIndices.length>0){if(Lb(t.sizeTree))return t;let r=Vb(),i=qy(v),a=0,o=0,s=0;for(;a<-e;){s=i[o];let e=i[o+1]-s-1;o++,a+=e+1}if(r=Wb(t.sizeTree).reduce((t,{k:n,v:r})=>Bb(t,Math.max(0,n+e),r),r),a!==-e){let n=Rb(t.sizeTree,s);r=Bb(r,0,n);let i=zb(t.sizeTree,-e+1)[1];r=Bb(r,1,i)}return{...t,sizeTree:r,...Sx(t.offsetTree,0,r,n)}}let r=Wb(t.sizeTree).reduce((t,{k:n,v:r})=>Bb(t,Math.max(0,n+e),r),Vb());return{...t,sizeTree:r,...Sx(t.offsetTree,0,r,n)}})),_),{beforeUnshiftWith:x,data:m,defaultItemSize:u,firstItemIndex:s,fixedItemSize:l,fixedGroupSize:d,gap:h,groupIndices:c,heightEstimates:f,itemSize:p,listRefresh:b,shiftWith:o,shiftWithOffset:S,sizeRanges:n,sizes:_,statefulTotalCount:i,totalCount:r,trackItemSizes:y,unshiftWith:a}},Uy(Sb,ix),{singleton:!0});function Dx(e){return e.reduce((e,t)=>(e.groupIndices.push(e.totalCount),e.totalCount+=t+1,e),{groupIndices:[],totalCount:0})}var Ox=pb(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:i}])=>{let a=ub(),o=ub(),s=db($(a,eb(Dx)));return Jy($(s,eb(e=>e.totalCount)),n),Jy($(s,eb(e=>e.groupIndices)),e),Jy($(gb(i,t,r),$y(([e,t])=>lx(t)),eb(([e,t,n])=>zb(t.groupOffsetTree,Math.max(e-n,0),`v`)[0]),Qy(),eb(e=>[e])),o),{groupCounts:a,topItemsIndexes:o}},Uy(Ex,Pb)),kx=pb(([{log:e}])=>{let t=cb(!1),n=db($(t,$y(e=>e),Qy()));return Wy(t,t=>{t&&qy(e)(`props updated`,{},yb.DEBUG)}),{didMount:n,propsReady:t}},Uy(Sb),{singleton:!0}),Ax=typeof document<`u`&&`scrollBehavior`in document.documentElement.style;function jx(e){let t=typeof e==`number`?{index:e}:{...e};return t.align||=`start`,(!t.behavior||!Ax)&&(t.behavior=`auto`),t.offset===void 0&&(t.offset=0),t}var Mx=pb(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:i,fixedHeaderHeight:a,footerHeight:o,headerHeight:s,scrollingInProgress:c,scrollTo:l,smoothScrollTargetReached:u,viewportHeight:d},{log:f}])=>{let p=ub(),m=ub(),h=cb(0),g=null,_=null,v=null;function y(){g!==null&&(g(),g=null),v!==null&&(v(),v=null),_&&=(clearTimeout(_),null),Gy(c,!1)}return Jy($(p,ab(n,d,r,h,s,o,f),ab(e,a,i),eb(([[e,n,r,i,a,o,s,l],d,f,h])=>{let b=jx(e),{align:x,behavior:S,offset:C}=b,w=i-1,T=_x(b,n,w),E=hx(T,n.offsetTree,d)+o;x===`end`?(E+=f+zb(n.sizeTree,T)[1]-r+h,T===w&&(E+=s)):x===`center`?E+=(f+zb(n.sizeTree,T)[1]-r+h)/2:E-=a,C!==void 0&&C!==0&&(E+=C);let D=t=>{y(),t?(l(`retrying to scroll to`,{location:e},yb.DEBUG),Gy(p,e)):(Gy(m,!0),l(`list did not change, scroll successful`,{},yb.DEBUG))};if(y(),S===`smooth`){let e=!1;v=Wy(t,t=>{e||=t}),g=Yy(u,()=>{D(e)})}else g=Yy($(t,Nx(150)),D);return _=setTimeout(()=>{y()},1200),Gy(c,!0),l(`scrolling from index to`,{behavior:S,index:T,top:E},yb.DEBUG),{behavior:S,top:E}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:h}},Uy(Ex,Pb,Sb),{singleton:!0});function Nx(e){return t=>{let n=setTimeout(()=>{t(!1)},e);return e=>{e&&(t(!0),clearTimeout(n))}}}function Px(e,t){e===0?t():requestAnimationFrame(()=>{Px(e-1,t)})}function Fx(e,t){if(e===void 0)return 0;let n=t-1,r=typeof e==`number`?e:e.index===`LAST`?n:e.index;return Math.max(0,Math.min(r,n))}function Ix(e){return e===void 0?!0:typeof e==`number`?e===0:e.index===0&&(e.align===void 0||e.align===`start`)&&(e.offset===void 0||e.offset===0)}var Lx=pb(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:i,scrollToIndex:a},{didMount:o}])=>{let s=cb(!0),c=cb(0),l=cb(!0);return Jy($(o,ab(c),$y(([e,t])=>!Ix(t)),tb(!1)),s),Jy($(o,ab(c),$y(([e,t])=>!Ix(t)),tb(!1)),l),Wy($(gb(t,o),ab(s,n,e,l),$y(([[,e],t,{sizeTree:n},r,i])=>e&&(!Lb(n)||Ry(r))&&!t&&!i),ab(c)),([,e])=>{if(e===void 0){Gy(s,!0),Gy(l,!0);return}Yy(i,()=>{Gy(l,!0)}),Px(4,()=>{Yy(r,()=>{Gy(s,!0)}),Gy(a,e)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:s}},Uy(Ex,Pb,Mx,kx),{singleton:!0});function Rx(e,t){return Math.abs(e-t)<1.01}var zx=`up`,Bx=`down`,Vx=`none`,Hx={atBottom:!1,notAtBottomBecause:`NOT_SHOWING_LAST_ITEM`,state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ux=0,Wx=pb(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:i,viewportHeight:a}])=>{let o=cb(!1),s=cb(!0),c=ub(),l=ub(),u=cb(4),d=cb(Ux),f=lb($(vb($(_b(i),rb(1),tb(!0)),$(_b(i),rb(1),tb(!1),Xy(100))),Qy()),!1),p=lb($(vb($(n,tb(!0)),$(n,tb(!1),Xy(200))),Qy()),!1);Jy($(gb(_b(i),_b(d)),eb(([e,t])=>e<=t),Qy()),s),Jy($(s,ib(50)),l);let m=db($(gb(r,_b(a),_b(t),_b(e),_b(u)),nb((e,[{scrollHeight:t,scrollTop:n},r,i,a,o])=>{let s=n+r-t>-o,c={scrollHeight:t,scrollTop:n,viewportHeight:r};if(s){let t,r;return n>e.state.scrollTop?(t=`SCROLLED_DOWN`,r=e.state.scrollTop-n):(t=`SIZE_DECREASED`,r=e.state.scrollTop-n||e.scrollTopDelta),{atBottom:!0,atBottomBecause:t,scrollTopDelta:r,state:c}}let l;return l=c.scrollHeight>e.state.scrollHeight?`SIZE_INCREASED`:r<e.state.viewportHeight?`VIEWPORT_HEIGHT_DECREASING`:n<e.state.scrollTop?`SCROLLING_UPWARDS`:`NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM`,{atBottom:!1,notAtBottomBecause:l,state:c}},Hx),Qy((e,t)=>e!==void 0&&e.atBottom===t.atBottom))),h=lb($(r,nb((e,{scrollHeight:t,scrollTop:n,viewportHeight:r})=>{if(!Rx(e.scrollHeight,t)){let i=t-(n+r)<1;return e.scrollTop!==n&&i?{changed:!0,jump:e.scrollTop-n,scrollHeight:t,scrollTop:n}:{changed:!0,jump:0,scrollHeight:t,scrollTop:n}}return{changed:!1,jump:0,scrollHeight:t,scrollTop:n}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),$y(e=>e.changed),eb(e=>e.jump)),0);Jy($(m,eb(e=>e.atBottom)),o),Jy($(o,ib(50)),c);let g=cb(Bx);Jy($(r,eb(({scrollTop:e})=>e),Qy(),nb((e,t)=>qy(p)?{direction:e.direction,prevScrollTop:t}:{direction:t<e.prevScrollTop?zx:Bx,prevScrollTop:t},{direction:Bx,prevScrollTop:0}),eb(e=>e.direction)),g),Jy($(r,ib(50),tb(Vx)),g);let _=cb(0);return Jy($(f,$y(e=>!e),tb(0)),_),Jy($(i,ib(100),ab(f),$y(([e,t])=>t),nb(([e,t],[n])=>[t,n],[0,0]),eb(([e,t])=>t-e)),_),{atBottomState:m,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:l,atTopThreshold:d,isAtBottom:o,isAtTop:s,isScrolling:f,lastJumpDueToItemResize:h,scrollDirection:g,scrollVelocity:_}},Uy(Pb)),Gx=`top`,Kx=`bottom`,qx=`none`;function Jx(e,t,n){return typeof e==`number`?n===zx&&t===Gx||n===Bx&&t===Kx?e:0:n===zx?t===Gx?e.main:e.reverse:t===Kx?e.main:e.reverse}function Yx(e,t){return typeof e==`number`?e:e[t]??0}var Xx=pb(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:i}])=>{let a=ub(),o=cb(0),s=cb(0),c=cb(0);return{increaseViewportBy:s,listBoundary:a,overscan:c,topListHeight:o,visibleRange:lb($(gb(_b(r),_b(i),_b(n),_b(a,rx),_b(c),_b(o),_b(t),_b(e),_b(s)),eb(([e,t,n,[r,i],a,o,s,c,l])=>{let u=e-c,d=o+s,f=Math.max(n-u,0),p=qx,m=Yx(l,Gx),h=Yx(l,Kx);return r-=c,r+=n+s,i+=n+s,i-=c,r>e+d-m&&(p=zx),i<e-f+t+h&&(p=Bx),p===qx?null:[Math.max(u-n-Jx(a,Gx,p)-m,0),u-f-s+t+Jx(a,Kx,p)+h]}),$y(e=>e!==null),Qy(rx)),[0,0])}},Uy(Pb),{singleton:!0});function Zx(e,t,n){if(lx(t)){let r=gx(e,t);return[{index:zb(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n?.[0],index:r,offset:0,size:0}]}return[{data:n?.[0],index:e,offset:0,size:0}]}var Qx={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function $x(e,t,n,r,i,a){let{lastIndex:o,lastOffset:s,lastSize:c}=i,l=0,u=0;if(e.length>0){l=e[0].offset;let t=e[e.length-1];u=t.offset+t.size}let d=n-o,f=s+d*c+(d-1)*r,p=l,m=f-u;return{bottom:u,firstItemIndex:a,items:tS(e,i,a),offsetBottom:m,offsetTop:l,top:p,topItems:tS(t,i,a),topListHeight:t.reduce((e,t)=>t.size+e,0),totalCount:n}}function eS(e,t,n,r,i,a){let o=0;if(n.groupIndices.length>0)for(let t of n.groupIndices){if(t-o>=e)break;o++}let s=e+o,c=a!==void 0,l=a?.length??0,u=Fx(t,c?l:s),d=c?Math.max(0,Math.min(s,l-u)):s;return $x(Array.from({length:d}).map((e,t)=>({data:a?.[t+u],index:t+u,offset:0,size:0})),[],d,i,n,r)}function tS(e,t,n){if(e.length===0)return[];if(!lx(t))return e.map(e=>({...e,index:e.index+n,originalIndex:e.index}));let r=e[0].index,i=e[e.length-1].index,a=[],o=Hb(t.groupOffsetTree,r,i),s,c=0;for(let r of e){(!s||s.end<r.index)&&(s=o.shift(),c=t.groupIndices.indexOf(s.start));let e;e=r.index===s.start?{index:c,type:`group`}:{groupIndex:c,index:r.index-(c+1)+n},a.push({...e,data:r.data,offset:r.offset,originalIndex:r.index,size:r.size})}return a}function nS(e,t){return e===void 0?0:typeof e==`number`?e:e[t]??0}var rS=pb(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:i},a,{listBoundary:o,topListHeight:s,visibleRange:c},{initialTopMostItemIndex:l,scrolledToInitialItem:u},{topListHeight:d},f,{didMount:p},{recalcInProgress:m}])=>{let h=cb([]),g=cb(0),_=ub(),v=cb(0);Jy(a.topItemsIndexes,h);let y=lb($(gb(p,m,_b(c,rx),_b(i),_b(r),_b(l),u,_b(h),_b(t),_b(n),_b(v),e,_b(g)),$y(([e,t,,n,,,,,,,,r])=>{let i=r!==void 0&&r.length!==n;return e&&!t&&!i}),eb(([,,[e,t],n,r,i,a,o,s,c,l,u,d])=>{let f=r,{offsetTree:p,sizeTree:m}=f;if(n===0)return{...Qx,totalCount:n};if(e===0&&t===0)return d===0?{...Qx,totalCount:n}:eS(d,i,r,s,c,u);if(Lb(m))return d>0?null:$x(Zx(Fx(i,n),f,u),[],n,c,f,s);let h=[];if(o.length>0){let e=o[0],t=o[o.length-1],n=0;for(let r of Hb(m,e,t)){let i=r.value,a=Math.max(r.start,e),o=Math.min(r.end,t);for(let e=a;e<=o;e++)h.push({data:u?.[e],index:e,offset:n,size:i}),n+=i}}if(!a)return $x([],h,n,c,f,s);let g=o.length>0?o[o.length-1]+1:0,_=vx(p,e,t,g);if(_.length===0)return null;let v=n-1,y=Vy([],n=>{for(let r of _){let i=r.value,a=i.offset,o=r.start,s=i.size;if(i.offset<e){o+=Math.floor((e-i.offset+c)/(s+c));let t=o-r.start;a+=t*s+t*c}o<g&&(a+=(g-o)*s,o=g);let l=Math.min(r.end,v);for(let e=o;e<=l&&!(a>=t);e++)n.push({data:u?.[e],index:e,offset:a,size:s}),a+=s+c}}),b=nS(l,Gx),x=nS(l,Kx);if(y.length>0&&(b>0||x>0)){let e=y[0],t=y[y.length-1];if(b>0&&e.index>g){let t=Math.min(b,e.index-g),n=[],r=e.offset;for(let i=e.index-1;i>=e.index-t;i--){let t=Hb(m,i,i)[0]?.value??e.size;r-=t+c,n.unshift({data:u?.[i],index:i,offset:r,size:t})}y.unshift(...n)}if(x>0&&t.index<v){let e=Math.min(x,v-t.index),n=t.offset+t.size+c;for(let r=t.index+1;r<=t.index+e;r++){let e=Hb(m,r,r)[0]?.value??t.size;y.push({data:u?.[r],index:r,offset:n,size:e}),n+=e+c}}}return $x(y,h,n,c,f,s)}),$y(e=>e!==null),Qy()),Qx);Jy($(e,$y(Ry),eb(e=>e?.length)),i),Jy($(y,eb(e=>e.topListHeight)),d),Jy(d,s),Jy($(y,eb(e=>[e.top,e.bottom])),o),Jy($(y,eb(e=>e.items)),_);let b=db($(y,$y(({items:e})=>e.length>0),ab(i,e),$y(([{items:e},t])=>e[e.length-1].originalIndex===t-1),eb(([,e,t])=>[e-1,t]),Qy(rx),eb(([e])=>e))),x=db($(y,ib(200),$y(({items:e,topItems:t})=>e.length>0&&e[0].originalIndex===t.length),eb(({items:e})=>e[0].index),Qy()));return{endReached:b,initialItemCount:g,itemsRendered:_,listState:y,minOverscanItemCount:v,rangeChanged:db($(y,$y(({items:e})=>e.length>0),eb(({items:e})=>{let t=0,n=e.length-1;for(;e[t].type===`group`&&t<n;)t++;for(;e[n].type===`group`&&n>t;)n--;return{endIndex:e[n].index,startIndex:e[t].index}}),Qy(nx))),startReached:x,topItemsIndexes:h,...f}},Uy(Ex,Ox,Xx,Lx,Mx,Wx,kx,ix),{singleton:!0}),iS=pb(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:i}])=>{let a=ub(),o=lb($(gb(n,e,r,t,i),eb(([e,t,n,r,i])=>e+t+n+r+i.offsetBottom+i.bottom)),0);return Jy(_b(o),a),{totalListHeight:o,totalListHeightChanged:a}},Uy(Pb,rS),{singleton:!0}),aS=pb(([{viewportHeight:e},{totalListHeight:t}])=>{let n=cb(!1);return{alignToBottom:n,paddingTopAddition:lb($(gb(n,e,t),$y(([e])=>e),eb(([,e,t])=>Math.max(0,e-t)),ib(0),Qy()),0)}},Uy(Pb,iS),{singleton:!0}),oS=pb(()=>({context:cb(null)})),sS=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...i},viewportBottom:a,viewportTop:o})=>t<o?{...i,align:n??`start`,...r===void 0?{}:{behavior:r}}:e>a?{...i,align:n??`end`,...r===void 0?{}:{behavior:r}}:null,cS=pb(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:i,headerHeight:a,scrollingInProgress:o,scrollTop:s,viewportHeight:c},{scrollToIndex:l}])=>{let u=ub();return Jy($(u,ab(t,c,n,a,i,r,s),ab(e),eb(([[e,t,n,r,i,a,s,c],l])=>{let{calculateViewLocation:u=sS,done:d,...f}=e,p=_x(e,t,r-1),m=hx(p,t.offsetTree,l)+i+a,h=m+zb(t.sizeTree,p)[1],g=c+a,_=u({itemBottom:h,itemTop:m,locationParams:f,viewportBottom:c+n-s,viewportTop:g});return _===null?d?.():d&&Yy($(o,$y(e=>!e),rb(qy(o)?1:2)),d),_}),$y(e=>e!==null)),l),{scrollIntoView:u}},Uy(Ex,Pb,Mx,rS,Sb),{singleton:!0});function lS(e){return e===!1?!1:e===`smooth`?`smooth`:`auto`}var uS=(e,t)=>typeof e==`function`?lS(e(t)):t&&lS(e),dS=pb(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:i,isAtBottom:a},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:c,propsReady:l},{log:u},{scrollingInProgress:d},{context:f},{scrollIntoView:p}])=>{let m=cb(!1),h=ub(),g=null;function _(e){Gy(o,{align:`end`,behavior:e,index:`LAST`})}Wy($(gb($(_b(t),rb(1)),c),ab(_b(m),a,s,d),eb(([[e,t],n,r,i,a])=>{let o=t&&i,s=`auto`;return o&&(s=uS(n,r||a),o&&=s!==!1),{followOutputBehavior:s,shouldFollow:o,totalCount:e}}),$y(({shouldFollow:e})=>e)),({followOutputBehavior:t,totalCount:r})=>{g!==null&&(g(),g=null),qy(n)===void 0?g=Yy(e,()=>{qy(u)(`following output to `,{totalCount:r},yb.DEBUG),_(t),g=null}):requestAnimationFrame(()=>{qy(u)(`following output to `,{totalCount:r},yb.DEBUG),_(t)})});function v(e){let t=Yy(i,t=>{e&&!t.atBottom&&t.notAtBottomBecause===`SIZE_INCREASED`&&g===null&&(qy(u)(`scrolling to bottom due to increased size`,{},yb.DEBUG),_(`auto`))});setTimeout(t,100)}Wy($(gb(_b(m),t,l),$y(([e,,t])=>e!==!1&&t),nb(({value:e},[,t])=>({refreshed:e===t,value:t}),{refreshed:!1,value:0}),$y(({refreshed:e})=>e),ab(m,t)),([,e])=>{qy(s)&&v(e!==!1)}),Wy(h,()=>{v(qy(m)!==!1)}),Wy(gb(_b(m),i),([e,t])=>{e!==!1&&!t.atBottom&&t.notAtBottomBecause===`VIEWPORT_HEIGHT_DECREASING`&&_(`auto`)});let y=cb(null),b=ub();return Jy(vb($(_b(r),eb(e=>e?.length??0)),$(_b(t))),b),Wy($(gb($(b,rb(1)),c),ab(_b(y),s,d,f),eb(([[e,t],n,r,i,a])=>t&&r&&n?.({context:a,totalCount:e,scrollingInProgress:i})),$y(e=>!!e),ib(0)),t=>{g!==null&&(g(),g=null),qy(n)===void 0?g=Yy(e,()=>{qy(u)(`scrolling into view`,{}),Gy(p,t),g=null}):requestAnimationFrame(()=>{qy(u)(`scrolling into view`,{}),Gy(p,t)})}),{autoscrollToBottom:h,followOutput:m,scrollIntoViewOnChange:y}},Uy(Ex,Wx,Mx,Lx,kx,Sb,Pb,oS,cS)),fS=pb(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:i},{initialItemCount:a,listState:o},{didMount:s}])=>(Jy($(s,ab(a),$y(([,e])=>e!==0),ab(i,r,t,n,e),eb(([[,e],t,n,r,i,a])=>eS(e,t,n,r,i,a))),o),{}),Uy(Ex,Lx,rS,kx),{singleton:!0}),pS=pb(([{didMount:e},{scrollTo:t},{listState:n}])=>{let r=cb(0);return Wy($(e,ab(r),$y(([,e])=>e!==0),eb(([,e])=>({top:e}))),e=>{Yy($(n,rb(1),$y(e=>e.items.length>1)),()=>{requestAnimationFrame(()=>{Gy(t,e)})})}),{initialScrollTop:r}},Uy(kx,Pb,rS),{singleton:!0}),mS=pb(([{scrollVelocity:e}])=>{let t=cb(!1),n=ub(),r=cb(!1);return Jy($(e,ab(r,t,n),$y(([e,t])=>t!==!1&&t!==void 0),eb(([e,t,n,r])=>{let{enter:i,exit:a}=t;if(n){if(a(e,r))return!1}else if(i(e,r))return!0;return n}),Qy()),t),Wy($(gb(t,e,n),ab(r)),([[e,t,n],r])=>{e&&r!==!1&&r!==void 0&&r.change&&r.change(t,n)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Uy(Wx),{singleton:!0}),hS=pb(([{scrollContainerState:e,scrollTo:t}])=>{let n=ub(),r=ub(),i=ub(),a=cb(!1),o=cb(void 0);return Jy($(gb(n,r),eb(([{scrollTop:e,viewportHeight:t},{offsetTop:n,listHeight:r}])=>({scrollHeight:r,scrollTop:Math.max(0,e-n),viewportHeight:t}))),e),Jy($(t,ab(r),eb(([e,{offsetTop:t}])=>({...e,top:e.top+t}))),i),{customScrollParent:o,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:i,windowViewportRect:r}},Uy(Pb)),gS=pb(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:i},{didMount:a},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:c}])=>{let l=ub(),u=cb(void 0),d=cb(null),f=cb(null);return Jy(s,d),Jy(c,f),Wy($(l,ab(t,r,o,d,f,n)),([e,t,n,r,i,a,o])=>{let s=bx(t.sizeTree);r&&i!==null&&a!==null&&(n=i.scrollTop-a.offsetTop),n-=o,e({ranges:s,scrollTop:n})}),Jy($(u,$y(Ry),eb(_S)),i),Jy($(a,ab(u),$y(([,e])=>e!==void 0),Qy(),eb(([,e])=>e.ranges)),e),{getState:l,restoreStateFrom:u}},Uy(Ex,Pb,Lx,kx,hS));function _S(e){return{align:`start`,index:0,offset:e.scrollTop}}var vS=pb(([{topItemsIndexes:e}])=>{let t=cb(0);return Jy($(t,$y(e=>e>=0),eb(e=>Array.from({length:e}).map((e,t)=>t))),e),{topItemCount:t}},Uy(rS));function yS(e){let t=!1,n;return(()=>(t||(t=!0,n=e()),n))}var bS=yS(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),xS=pb(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,fixedGroupSize:i,gap:a,groupIndices:o,heightEstimates:s,itemSize:c,sizeRanges:l,sizes:u,statefulTotalCount:d,totalCount:f,trackItemSizes:p},{initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g},_,v,y,b,{scrollToIndex:x},S,{topItemCount:C},{groupCounts:w},T])=>{let{listState:E,minOverscanItemCount:D,topItemsIndexes:O,rangeChanged:k,...A}=b;return Jy(k,T.scrollSeekRangeChanged),Jy($(gb(T.windowViewportRect,_.headerHeight,_.fixedHeaderHeight),eb(([e,t,n])=>Math.max(t+n+1,e.visibleHeight))),_.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,fixedGroupHeight:i,gap:a,groupCounts:w,heightEstimates:s,initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g,sizeRanges:l,topItemCount:C,topItemsIndexes:O,totalCount:f,...y,groupIndices:o,itemSize:c,listState:E,minOverscanItemCount:D,scrollToIndex:x,statefulTotalCount:d,trackItemSizes:p,rangeChanged:k,...A,...T,..._,sizes:u,...v}},Uy(Ex,Lx,Pb,gS,dS,rS,Mx,pb(([{deviation:e,deviationCommitted:t,scrollBy:n,scrollingInProgress:r,scrollTop:i},{isAtBottom:a,isScrolling:o,lastJumpDueToItemResize:s,scrollDirection:c},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:p},{log:m},{recalcInProgress:h}])=>{let g=db($(l,ab(s),nb(([,e,t,n],[{bottom:r,items:i,offsetBottom:a,totalCount:o},s])=>{let c=r+a,l=0;return t===o&&e.length>0&&i.length>0&&(i[0].originalIndex===0&&e[0].originalIndex===0||(l=c-n,l!==0&&(l+=s))),[l,i,o,c]},[0,[],0,0]),$y(([e])=>e!==0),ab(i,c,r,a,m,h),$y(([,e,t,n,,,r])=>!r&&!n&&e!==0&&t===zx),eb(([[e],,,,,t])=>(t(`Upward scrolling compensation`,{amount:e},yb.DEBUG),e))));function _(t){t>0?(Gy(n,{behavior:`auto`,top:-t}),Gy(e,0)):(Gy(e,0),Gy(n,{behavior:`auto`,top:-t}))}Wy($(g,ab(e,o)),([t,n,r])=>{r&&bS()?Gy(e,n-t):_(-t)}),Wy($(gb(lb(o,!1),e,h),$y(([e,t,n])=>!e&&!n&&t!==0),eb(([e,t])=>t),ib(1)),_),Jy($(f,eb(e=>({top:-e}))),n);let v=null;function y(){if(v===null)return;let{offset:t}=v;v=null,Gy(n,{top:t}),requestAnimationFrame(()=>{Gy(e,0),Gy(h,!1)})}return Wy(t,e=>{v===null||!v.acknowledgeable||e===v.offset&&y()}),Wy($(u,ab(p,d),eb(([e,{groupIndices:t,lastSize:n,sizeTree:r},i])=>{function a(e){return e*(n+i)}if(t.length===0)return a(e);let o=0,s=Rb(r,0),c=0,l=0;for(;c<e;){c++,o+=s;let n=t.length===l+1?1/0:t[l+1]-t[l]-1;c+n>e&&(o-=s,n=e-c+1),c+=n,o+=a(n),l++}return o})),t=>{v={acknowledgeable:qy(e)!==t,offset:t},Gy(e,t),requestAnimationFrame(y)}),{deviation:e}},Uy(Pb,Wx,rS,Ex,Sb,ix)),vS,Ox,pb(([e,t,n,r,i,a,o,s,c,l,u])=>({...e,...t,...n,...r,...i,...a,...o,...s,...c,...l,...u}),Uy(Xx,fS,kx,mS,iS,pS,aS,hS,cS,Sb,oS))));function SS(e,t){let n={},r={},i=0,a=e.length;for(;i<a;)r[e[i]]=1,i+=1;for(let e in t)Object.hasOwn(r,e)||(n[e]=t[e]);return n}var CS=typeof document>`u`?Q.useEffect:Q.useLayoutEffect;function wS(e,t,n){let r=Object.keys(t.required||{}),i=Object.keys(t.optional||{}),a=Object.keys(t.methods||{}),o=Object.keys(t.events||{}),s=Q.createContext({});function c(e,n){e.propsReady!==void 0&&Gy(e.propsReady,!1);for(let i of r){let r=e[t.required[i]];Gy(r,n[i])}for(let r of i)if(r in n){let i=e[t.optional[r]];Gy(i,n[r])}e.propsReady!==void 0&&Gy(e.propsReady,!0)}function l(e){return a.reduce((n,r)=>(n[r]=n=>{let i=e[t.methods[r]];Gy(i,n)},n),{})}function u(e){return o.reduce((n,r)=>(n[r]=sb(e[t.events[r]]),n),{})}return{Component:Q.forwardRef(function(t,a){let{children:d,...f}=t,[p]=Q.useState(()=>Vy(hb(e),e=>{c(e,f)})),[m]=Q.useState(Iy(u,p));CS(()=>{for(let e of o)e in f&&Wy(m[e],f[e]);return()=>{Object.values(m).map(Ky)}},[f,m,p]),CS(()=>{c(p,f)}),Q.useImperativeHandle(a,Ny(l(p)));let h=n;return(0,Z.jsx)(s.Provider,{value:p,children:n===void 0?d:(0,Z.jsx)(h,{...SS([...r,...i,...o],f),children:d})})}),useEmitter:(e,t)=>{let n=Q.useContext(s)[e];CS(()=>Wy(n,t),[t,n])},useEmitterValue:e=>{let t=Q.useContext(s)[e],n=Q.useCallback(e=>Wy(t,e),[t]);return Q.useSyncExternalStore(n,()=>qy(t),()=>qy(t))},usePublisher:e=>{let t=Q.useContext(s);return Q.useCallback(n=>{Gy(t[e],n)},[t,e])}}}var TS=Q.createContext(void 0),ES=Q.createContext(void 0),DS=`-webkit-sticky`,OS=`sticky`,kS=yS(()=>{if(typeof document>`u`)return OS;let e=document.createElement(`div`);return e.style.position=DS,e.style.position===DS?DS:OS});function AS(e){return`self`in e}function jS(e){return`body`in e}function MS(e,t,n,r=By,i,a){let o=Q.useRef(null),s=Q.useRef(null),c=Q.useRef(null),l=Q.useCallback(n=>{let r,i,o,l=n.target;if(jS(l)||AS(l)){let e=AS(l)?l:l.defaultView;o=a===!0?Tb(e,e.scrollX):e.scrollY,r=a===!0?e.document.documentElement.scrollWidth:e.document.documentElement.scrollHeight,i=a===!0?e.innerWidth:e.innerHeight}else o=a===!0?Tb(l,l.scrollLeft):l.scrollTop,r=a===!0?l.scrollWidth:l.scrollHeight,i=a===!0?l.offsetWidth:l.offsetHeight;let u=()=>{e({scrollHeight:r,scrollTop:Math.max(o,0),viewportHeight:i})};n.suppressFlushSync===!0?u():Us.flushSync(u),s.current!==null&&(o===s.current||o<=0||o===r-i)&&(s.current=null,t(!0),c.current&&=(clearTimeout(c.current),null))},[e,t,a]);Q.useEffect(()=>{let e=i??o.current;return r(i??o.current),l({suppressFlushSync:!0,target:e}),e.addEventListener(`scroll`,l,{passive:!0}),()=>{r(null),e.removeEventListener(`scroll`,l)}},[o,l,n,r,i]);function u(n){let r=o.current;if(!r||(a===!0?`offsetWidth`in r&&r.offsetWidth===0:`offsetHeight`in r&&r.offsetHeight===0))return;let i=n.behavior===`smooth`,l,u,d;AS(r)?(u=Math.max(cx(r.document.documentElement,a===!0?`width`:`height`),a===!0?r.document.documentElement.scrollWidth:r.document.documentElement.scrollHeight),l=a===!0?r.innerWidth:r.innerHeight,d=a===!0?Tb(r,r.scrollX):r.scrollY):(u=r[a===!0?`scrollWidth`:`scrollHeight`],l=cx(r,a===!0?`width`:`height`),d=a===!0?Tb(r,r.scrollLeft):r.scrollTop);let f=u-l;if(n.top===void 0){r.scrollTo(n);return}let p=Math.ceil(Math.max(Math.min(f,n.top),0));if(n.top=p,Rx(l,u)||p===d){e({scrollHeight:u,scrollTop:d,viewportHeight:l}),i&&t(!0);return}i?(s.current=p,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,s.current=null,t(!0)},1e3)):s.current=null,a===!0&&(n={...n.behavior===void 0?{}:{behavior:n.behavior},left:Eb(r,p)}),r.scrollTo(n)}return{scrollByCallback:Q.useCallback(e=>{a===!0&&(e={...e.behavior===void 0?{}:{behavior:e.behavior},...e.top===void 0?{}:{left:Eb(o.current,e.top)}}),o.current.scrollBy(e)},[a]),scrollerRef:o,scrollToCallback:u}}function NS(e){return e}var PS=pb(([e,t])=>({...e,...t}),Uy(xS,pb(()=>{let e=cb(e=>`Item ${e}`),t=cb(e=>`Group ${e}`),n=cb({}),r=cb(NS),i=cb(`div`),a=cb(By),o=(e,t=null)=>lb($(n,eb(t=>t[e]),Qy()),t);return{components:n,computeItemKey:r,EmptyPlaceholder:o(`EmptyPlaceholder`),FooterComponent:o(`Footer`),GroupComponent:o(`Group`,`div`),groupContent:t,HeaderComponent:o(`Header`),HeaderFooterTag:i,ItemComponent:o(`Item`,`div`),itemContent:e,ListComponent:o(`List`,`div`),ScrollerComponent:o(`Scroller`,`div`),scrollerRef:a,ScrollSeekPlaceholder:o(`ScrollSeekPlaceholder`),TopItemListComponent:o(`TopItemList`)}}))),FS=({height:e})=>(0,Z.jsx)(`div`,{style:{height:e}}),IS={overflowAnchor:`none`,position:kS(),zIndex:1},LS={overflowAnchor:`none`},RS={...LS,display:`inline-block`,height:`100%`},zS=Q.memo(function({showTopList:e=!1}){let t=nC(`listState`),n=rC(`sizeRanges`),r=nC(`useWindowScroll`),i=nC(`customScrollParent`),a=rC(`windowScrollContainerState`),o=rC(`scrollContainerState`),s=i||r?a:o,c=nC(`itemContent`),l=nC(`context`),u=nC(`groupContent`),d=nC(`trackItemSizes`),f=nC(`itemSize`),p=nC(`log`),m=rC(`gap`),h=nC(`horizontalDirection`),{callbackRef:g}=kb(n,f,d,e?By:s,p,m,i,h,nC(`skipAnimationFrameInResizeObserver`)),[_,v]=Q.useState(0);tC(`deviation`,e=>{_!==e&&v(e)});let y=rC(`deviationCommitted`);Mb(()=>{y(_)},[_,y]);let b=nC(`EmptyPlaceholder`),x=nC(`ScrollSeekPlaceholder`)??FS,S=nC(`ListComponent`),C=nC(`ItemComponent`),w=nC(`GroupComponent`),T=nC(`computeItemKey`),E=nC(`isSeeking`),D=nC(`groupIndices`).length>0,O=nC(`alignToBottom`),k=nC(`initialItemFinalLocationReached`),A=e?{}:{boxSizing:`border-box`,...h?{display:`inline-block`,height:`100%`,marginInlineStart:_===0?O?`auto`:0:_,paddingInlineEnd:t.offsetBottom,paddingInlineStart:t.offsetTop,whiteSpace:`nowrap`}:{marginTop:_===0?O?`auto`:0:_,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...k?{}:{visibility:`hidden`}};return!e&&t.totalCount===0&&b!=null?(0,Z.jsx)(b,{...GS(b,l)}):(0,Z.jsx)(S,{...GS(S,l),"data-testid":e?`virtuoso-top-item-list`:`virtuoso-item-list`,ref:g,style:A,children:(e?t.topItems:t.items).map(e=>{let n=e.originalIndex,r=T(n+t.firstItemIndex,e.data,l);return E?(0,Q.createElement)(x,{...GS(x,l),height:e.size,index:e.index,key:r,type:e.type||`item`,...e.type===`group`?{}:{groupIndex:e.groupIndex}}):e.type===`group`?(0,Q.createElement)(w,{...GS(w,l),"data-index":n,"data-item-index":e.index,"data-known-size":e.size,key:r,style:IS},u(e.index,l)):(0,Q.createElement)(C,{...GS(C,l),...KS(C,e.data),"data-index":n,"data-item-group-index":e.groupIndex,"data-item-index":e.index,"data-known-size":e.size,key:r,style:h?RS:LS},D?c(e.index,e.groupIndex,e.data,l):c(e.index,e.data,l))})})}),BS={height:`100%`,outline:`none`,overflowY:`auto`,position:`relative`,WebkitOverflowScrolling:`touch`},VS={outline:`none`,overflowX:`auto`,position:`relative`},HS=e=>({height:`100%`,position:`absolute`,top:0,width:`100%`,...e?{display:`flex`,flexDirection:`column`}:void 0}),US=(e,t,n=0)=>({...HS(e),position:t?`relative`:`absolute`,top:t?-n:0}),WS={position:kS(),top:0,width:`100%`,zIndex:1};function GS(e,t){if(typeof e!=`string`)return{context:t}}function KS(e,t){return{item:typeof e==`string`?void 0:t}}var qS=Q.memo(function(){let e=nC(`HeaderComponent`),t=rC(`headerHeight`),n=nC(`HeaderFooterTag`),r=Db(Q.useMemo(()=>e=>{t(cx(e,`height`))},[t]),!0,nC(`skipAnimationFrameInResizeObserver`)),i=nC(`context`);return e==null?null:(0,Z.jsx)(n,{ref:r,children:(0,Z.jsx)(e,{...GS(e,i)})})}),JS=Q.memo(function(){let e=nC(`FooterComponent`),t=rC(`footerHeight`),n=nC(`HeaderFooterTag`),r=Db(Q.useMemo(()=>e=>{t(cx(e,`height`))},[t]),!0,nC(`skipAnimationFrameInResizeObserver`)),i=nC(`context`);return e==null?null:(0,Z.jsx)(n,{ref:r,children:(0,Z.jsx)(e,{...GS(e,i)})})});function YS({useEmitter:e,useEmitterValue:t,usePublisher:n}){return Q.memo(function({children:r,style:i,context:a,...o}){let s=n(`scrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`scrollerRef`),d=t(`horizontalDirection`)||!1,{scrollByCallback:f,scrollerRef:p,scrollToCallback:m}=MS(s,l,c,u,void 0,d);return e(`scrollTo`,m),e(`scrollBy`,f),(0,Z.jsx)(c,{"data-testid":`virtuoso-scroller`,"data-virtuoso-scroller":!0,ref:p,style:{...d?VS:BS,...i},tabIndex:0,...o,...GS(c,a),children:r})})}function XS({useEmitter:e,useEmitterValue:t,usePublisher:n}){return Q.memo(function({children:r,style:i,context:a,...o}){let s=n(`windowScrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`totalListHeight`),d=t(`deviation`),f=t(`customScrollParent`),p=Q.useRef(null),{scrollByCallback:m,scrollerRef:h,scrollToCallback:g}=MS(s,l,c,t(`scrollerRef`),f);return Mb(()=>(h.current=f??p.current?.ownerDocument.defaultView,()=>{h.current=null}),[h,f]),e(`windowScrollTo`,g),e(`scrollBy`,m),(0,Z.jsx)(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:`relative`,...i,...u===0?void 0:{height:u+d}},...o,...GS(c,a),children:r})})}var ZS=({children:e})=>{let t=Q.useContext(TS),n=rC(`viewportHeight`),r=rC(`fixedItemHeight`),i=nC(`alignToBottom`),a=nC(`horizontalDirection`),o=Db(Q.useMemo(()=>Fy(n,e=>cx(e,a?`width`:`height`)),[n,a]),!0,nC(`skipAnimationFrameInResizeObserver`));return Q.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,Z.jsx)(`div`,{"data-viewport-type":`element`,ref:o,style:HS(i),children:e})},QS=({children:e})=>{let t=Q.useContext(TS),n=rC(`windowViewportRect`),r=rC(`fixedItemHeight`),i=nC(`customScrollParent`),a=nC(`useWindowScroll`),o=nC(`topListHeight`),s=Nb(n,i,nC(`skipAnimationFrameInResizeObserver`)),c=nC(`alignToBottom`);return Q.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,Z.jsx)(`div`,{"data-viewport-type":`window`,ref:s,style:US(c,a,o),children:e})},$S=({children:e})=>{let t=nC(`TopItemListComponent`)??`div`,n=nC(`headerHeight`);return(0,Z.jsx)(t,{style:{...WS,marginTop:`${n}px`},...GS(t,nC(`context`)),children:e})},{Component:eC,useEmitter:tC,useEmitterValue:nC,usePublisher:rC}=wS(PS,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,scrollIntoViewOnChange:`scrollIntoViewOnChange`,itemContent:`itemContent`,groupContent:`groupContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,groupCounts:`groupCounts`,topItemCount:`topItemCount`,firstItemIndex:`firstItemIndex`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,heightEstimates:`heightEstimates`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`HeaderFooterTag`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,horizontalDirection:`horizontalDirection`,skipAnimationFrameInResizeObserver:`skipAnimationFrameInResizeObserver`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,autoscrollToBottom:`autoscrollToBottom`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},Q.memo(function(e){let t=nC(`useWindowScroll`),n=nC(`topItemsIndexes`).length>0,r=nC(`customScrollParent`),i=nC(`context`);return(0,Z.jsxs)(r||t?aC:iC,{...e,context:i,children:[n&&(0,Z.jsx)($S,{children:(0,Z.jsx)(zS,{showTopList:!0})}),(0,Z.jsxs)(r||t?QS:ZS,{children:[(0,Z.jsx)(qS,{}),(0,Z.jsx)(zS,{}),(0,Z.jsx)(JS,{})]})]})})),iC=YS({useEmitter:tC,useEmitterValue:nC,usePublisher:rC}),aC=XS({useEmitter:tC,useEmitterValue:nC,usePublisher:rC}),oC=eC,sC=pb(([e,t])=>({...e,...t}),Uy(xS,pb(()=>{let e=cb(e=>(0,Z.jsxs)(`td`,{children:[`Item $`,e]})),t=cb(null),n=cb(e=>(0,Z.jsxs)(`td`,{colSpan:1e3,children:[`Group `,e]})),r=cb(null),i=cb(null),a=cb({}),o=cb(NS),s=cb(By),c=(e,t=null)=>lb($(a,eb(t=>t[e]),Qy()),t);return{components:a,computeItemKey:o,context:t,EmptyPlaceholder:c(`EmptyPlaceholder`),FillerRow:c(`FillerRow`),fixedFooterContent:i,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`),TableBodyComponent:c(`TableBody`,`tbody`),TableComponent:c(`Table`,`table`),TableFooterComponent:c(`TableFoot`,`tfoot`),TableHeadComponent:c(`TableHead`,`thead`),TableRowComponent:c(`TableRow`,`tr`),GroupComponent:c(`Group`,`tr`)}}))),cC=({height:e})=>(0,Z.jsx)(`tr`,{children:(0,Z.jsx)(`td`,{style:{height:e}})}),lC=({height:e})=>(0,Z.jsx)(`tr`,{children:(0,Z.jsx)(`td`,{style:{border:0,height:e,padding:0}})}),uC={overflowAnchor:`none`},dC={position:kS(),zIndex:2,overflowAnchor:`none`},fC=Q.memo(function({showTopList:e=!1}){let t=vC(`listState`),n=vC(`computeItemKey`),r=vC(`firstItemIndex`),i=vC(`context`),a=vC(`isSeeking`),o=vC(`fixedHeaderHeight`),s=vC(`groupIndices`).length>0,c=vC(`itemContent`),l=vC(`groupContent`),u=vC(`ScrollSeekPlaceholder`)??cC,d=vC(`GroupComponent`),f=vC(`TableRowComponent`),p=(e?t.topItems:[]).reduce((e,t,n)=>(n===0?e.push(t.size):e.push(e[n-1]+t.size),e),[]);return(e?t.topItems:t.items).map(t=>{let m=t.originalIndex,h=n(m+r,t.data,i),g=e?m===0?0:p[m-1]:0;return a?(0,Q.createElement)(u,{...GS(u,i),height:t.size,index:t.index,key:h,type:t.type||`item`}):t.type===`group`?(0,Q.createElement)(d,{...GS(d,i),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,key:h,style:{...dC,top:o}},l(t.index,i)):(0,Q.createElement)(f,{...GS(f,i),...KS(f,t.data),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,"data-item-group-index":t.groupIndex,key:h,style:e?{...dC,top:o+g}:uC},s?c(t.index,t.groupIndex,t.data,i):c(t.index,t.data,i))})}),pC=Q.memo(function(){let e=vC(`listState`),t=vC(`topItemsIndexes`).length>0,n=yC(`sizeRanges`),r=vC(`useWindowScroll`),i=vC(`customScrollParent`),a=yC(`windowScrollContainerState`),o=yC(`scrollContainerState`),s=i||r?a:o,c=vC(`trackItemSizes`),{callbackRef:l,ref:u}=kb(n,vC(`itemSize`),c,s,vC(`log`),void 0,i,!1,vC(`skipAnimationFrameInResizeObserver`)),[d,f]=Q.useState(0);_C(`deviation`,e=>{d!==e&&(u.current.style.marginTop=`${e}px`,f(e))});let p=yC(`deviationCommitted`);Mb(()=>{p(d)},[d,p]);let m=vC(`EmptyPlaceholder`),h=vC(`FillerRow`)??lC,g=vC(`TableBodyComponent`),_=vC(`paddingTopAddition`),v=vC(`statefulTotalCount`),y=vC(`context`);if(v===0&&m!=null)return(0,Z.jsx)(m,{...GS(m,y)});let b=(t?e.topItems:[]).reduce((e,t)=>e+t.size,0),x=e.offsetTop+_+d-b,S=e.offsetBottom,C=x>0?(0,Z.jsx)(h,{context:y,height:x},`padding-top`):null,w=S>0?(0,Z.jsx)(h,{context:y,height:S},`padding-bottom`):null;return(0,Z.jsxs)(g,{"data-testid":`virtuoso-item-list`,ref:l,...GS(g,y),children:[C,t&&(0,Z.jsx)(fC,{showTopList:!0}),(0,Z.jsx)(fC,{}),w]})}),mC=({children:e})=>{let t=Q.useContext(TS),n=yC(`viewportHeight`),r=yC(`fixedItemHeight`),i=Db(Q.useMemo(()=>Fy(n,e=>cx(e,`height`)),[n]),!0,vC(`skipAnimationFrameInResizeObserver`));return Q.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,Z.jsx)(`div`,{"data-viewport-type":`element`,ref:i,style:HS(!1),children:e})},hC=({children:e})=>{let t=Q.useContext(TS),n=yC(`windowViewportRect`),r=yC(`fixedItemHeight`),i=vC(`customScrollParent`),a=vC(`useWindowScroll`),o=Nb(n,i,vC(`skipAnimationFrameInResizeObserver`));return Q.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,Z.jsx)(`div`,{"data-viewport-type":`window`,ref:o,style:US(!1,a),children:e})},{Component:gC,useEmitter:_C,useEmitterValue:vC,usePublisher:yC}=wS(sC,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,firstItemIndex:`firstItemIndex`,itemContent:`itemContent`,groupContent:`groupContent`,fixedHeaderContent:`fixedHeaderContent`,fixedFooterContent:`fixedFooterContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,topItemCount:`topItemCount`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,groupCounts:`groupCounts`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,skipAnimationFrameInResizeObserver:`skipAnimationFrameInResizeObserver`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},Q.memo(function(e){let t=vC(`useWindowScroll`),n=vC(`customScrollParent`),r=yC(`fixedHeaderHeight`),i=yC(`fixedFooterHeight`),a=vC(`fixedHeaderContent`),o=vC(`fixedFooterContent`),s=vC(`context`),c=Db(Q.useMemo(()=>Fy(r,e=>cx(e,`height`)),[r]),!0,vC(`skipAnimationFrameInResizeObserver`)),l=Db(Q.useMemo(()=>Fy(i,e=>cx(e,`height`)),[i]),!0,vC(`skipAnimationFrameInResizeObserver`)),u=n||t?xC:bC,d=n||t?hC:mC,f=vC(`TableComponent`),p=vC(`TableHeadComponent`),m=vC(`TableFooterComponent`),h=a?(0,Z.jsx)(p,{ref:c,style:{position:`sticky`,top:0,zIndex:2},...GS(p,s),children:a()},`TableHead`):null,g=o?(0,Z.jsx)(m,{ref:l,style:{bottom:0,position:`sticky`,zIndex:1},...GS(m,s),children:o()},`TableFoot`):null;return(0,Z.jsx)(u,{...e,...GS(u,s),children:(0,Z.jsx)(d,{children:(0,Z.jsxs)(f,{style:{borderSpacing:0,overflowAnchor:`none`},...GS(f,s),children:[h,(0,Z.jsx)(pC,{},`TableBody`),g]})})})})),bC=YS({useEmitter:_C,useEmitterValue:vC,usePublisher:yC}),xC=XS({useEmitter:_C,useEmitterValue:vC,usePublisher:yC}),SC={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},CC={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:wC,floor:TC,max:EC,min:DC,round:OC}=Math;function kC(e,t,n){return Array.from({length:t-e+1}).map((t,r)=>({data:n===null?null:n[r+e],index:r+e}))}function AC(e){return{...CC,items:e}}function jC(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function MC(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}var NC=pb(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:i,headerHeight:a,scrollBy:o,scrollContainerState:s,scrollTo:c,scrollTop:l,smoothScrollTargetReached:u,viewportHeight:d},f,p,{didMount:m,propsReady:h},{customScrollParent:g,useWindowScroll:_,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b},x])=>{let S=cb(0),C=cb(0),w=cb(SC),T=cb({height:0,width:0}),E=cb({height:0,width:0}),D=ub(),O=ub(),k=cb(0),A=cb(null),j=cb({column:0,row:0}),M=ub(),N=ub(),P=cb(!1),F=cb(0),I=cb(!0),L=cb(!1),R=cb(!1);Wy($(m,ab(F),$y(([e,t])=>!Ix(t))),()=>{Gy(I,!1)}),Wy($(gb(m,I,E,T,F,L),$y(([e,t,n,r,,i])=>e&&!t&&n.height!==0&&r.height!==0&&!i)),([,,,,e])=>{if(e===void 0){Gy(I,!0);return}Gy(L,!0),Px(1,()=>{Gy(D,e)}),Yy($(l),()=>{Gy(t,[0,0]),Gy(I,!0)})}),Jy($(N,$y(e=>e!=null&&e.scrollTop>0),tb(0)),C),Wy($(m,ab(N),$y(([,e])=>e!=null)),([,e])=>{e&&(Gy(T,e.viewport),Gy(E,e.item),Gy(j,e.gap),e.scrollTop>0&&(Gy(P,!0),Yy($(l,rb(1)),e=>{Gy(P,!1)}),Gy(c,{top:e.scrollTop})))}),Jy($(T,eb(({height:e})=>e)),d),Jy($(gb(_b(T,jC),_b(E,jC),_b(j,(e,t)=>e!==void 0&&e.column===t.column&&e.row===t.row),_b(l)),eb(([e,t,n,r])=>({gap:n,item:t,scrollTop:r,viewport:e}))),M),Jy($(gb(_b(S),r,_b(j,MC),_b(E,jC),_b(T,jC),_b(A),_b(C),_b(P),_b(I),_b(F)),$y(([,,,,,,,e])=>!e),eb(([e,[t,n],r,i,a,o,s,,c,l])=>{let{column:u,row:d}=r,{height:f,width:p}=i,{width:m}=a;if(s===0&&(e===0||m===0))return SC;if(p===0){let t=Fx(l,e);return AC(kC(t,t+Math.max(s-1,0),o))}let h=PC(m,p,u),g,_;c?t===0&&n===0&&s>0?(g=0,_=s-1):(g=h*TC((t+d)/(f+d)),_=h*wC((n+d)/(f+d))-1,_=DC(e-1,EC(_,h-1)),g=DC(_,EC(0,g))):(g=0,_=-1);let v=kC(g,_,o),{bottom:y,top:b}=FC(a,r,i,v),x=wC(e/h);return{bottom:y,itemHeight:f,items:v,itemWidth:p,offsetBottom:x*f+(x-1)*d-y,offsetTop:b,top:b}})),w),Jy($(A,$y(e=>e!==null),eb(e=>e.length)),S),Jy($(gb(T,E,w,j),$y(([e,t,{items:n}])=>n.length>0&&t.height!==0&&e.height!==0),eb(([e,t,{items:n},r])=>{let{bottom:i,top:a}=FC(e,r,t,n);return[a,i]}),Qy(rx)),t);let z=cb(!1);Jy($(l,ab(z),eb(([e,t])=>t||e!==0)),z);let B=db($(gb(w,S),$y(([{items:e}])=>e.length>0),ab(z),$y(([[e,t],n])=>{let r=e.items[e.items.length-1].index===t-1;return(n||e.bottom>0&&e.itemHeight>0&&e.offsetBottom===0&&e.items.length===t)&&r}),eb(([[,e]])=>e-1),Qy())),ee=db($(_b(w),$y(({items:e})=>e.length>0&&e[0].index===0),tb(0),Qy())),V=db($(_b(w),ab(P),$y(([{items:e},t])=>e.length>0&&!t),eb(([{items:e}])=>({endIndex:e[e.length-1].index,startIndex:e[0].index})),Qy(nx),ib(0)));Jy(V,p.scrollSeekRangeChanged),Jy($(D,ab(T,E,S,j),eb(([e,t,n,r,i])=>{let a=jx(e),{align:o,behavior:s,offset:c}=a,l=a.index;l===`LAST`&&(l=r-1),l=EC(0,l,DC(r-1,l));let u=IC(t,i,n,l);return o===`end`?u=OC(u-t.height+n.height):o===`center`&&(u=OC(u-t.height/2+n.height/2)),c!==void 0&&c!==0&&(u+=c),{behavior:s,top:u}})),c);let H=lb($(w,eb(e=>e.offsetBottom+e.bottom)),0);return Jy($(b,eb(e=>({height:e.visibleHeight,width:e.visibleWidth}))),T),{customScrollParent:g,data:A,deviation:k,footerHeight:i,gap:j,headerHeight:a,increaseViewportBy:e,initialItemCount:C,itemDimensions:E,overscan:n,restoreStateFrom:N,scrollBy:o,scrollContainerState:s,scrollHeight:O,scrollTo:c,scrollToIndex:D,scrollTop:l,smoothScrollTargetReached:u,totalCount:S,useWindowScroll:_,viewportDimensions:T,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b,...p,gridState:w,horizontalDirection:R,initialTopMostItemIndex:F,totalListHeight:H,...f,endReached:B,propsReady:h,rangeChanged:V,startReached:ee,stateChanged:M,stateRestoreInProgress:P,...x}},Uy(Xx,Pb,Wx,mS,kx,hS,Sb));function PC(e,t,n){return EC(1,TC((e+n)/(TC(t)+n)))}function FC(e,t,n,r){let{height:i}=n;if(i===void 0||r.length===0)return{bottom:0,top:0};let a=IC(e,t,n,r[0].index);return{bottom:IC(e,t,n,r[r.length-1].index)+i,top:a}}function IC(e,t,n,r){let i=TC(r/PC(e.width,n.width,t.column)),a=i*n.height+EC(0,i-1)*t.row;return a>0?a+t.row:a}var LC=pb(([e,t])=>({...e,...t}),Uy(NC,pb(()=>{let e=cb(e=>`Item ${e}`),t=cb({}),n=cb(null),r=cb(`virtuoso-grid-item`),i=cb(`virtuoso-grid-list`),a=cb(NS),o=cb(`div`),s=cb(By),c=(e,n=null)=>lb($(t,eb(t=>t[e]),Qy()),n),l=cb(!1),u=cb(!1);return Jy(_b(u),l),{components:t,computeItemKey:a,context:n,FooterComponent:c(`Footer`),HeaderComponent:c(`Header`),headerFooterTag:o,itemClassName:r,ItemComponent:c(`Item`,`div`),itemContent:e,listClassName:i,ListComponent:c(`List`,`div`),readyStateChanged:l,reportReadyState:u,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`,`div`)}}))),RC=Q.memo(function(){let e=GC(`gridState`),t=GC(`listClassName`),n=GC(`itemClassName`),r=GC(`itemContent`),i=GC(`computeItemKey`),a=GC(`isSeeking`),o=KC(`scrollHeight`),s=GC(`ItemComponent`),c=GC(`ListComponent`),l=GC(`ScrollSeekPlaceholder`),u=GC(`context`),d=KC(`itemDimensions`),f=KC(`gap`),p=GC(`log`),m=GC(`stateRestoreInProgress`),h=KC(`reportReadyState`),g=Db(Q.useMemo(()=>e=>{let t=e.parentElement.parentElement.scrollHeight;o(t);let n=e.firstChild;if(n!==null){let{height:e,width:t}=n.getBoundingClientRect();d({height:e,width:t})}f({column:YC(`column-gap`,getComputedStyle(e).columnGap,p),row:YC(`row-gap`,getComputedStyle(e).rowGap,p)})},[o,d,f,p]),!0,!1);return Mb(()=>{e.itemHeight>0&&e.itemWidth>0&&h(!0)},[e]),m?null:(0,Z.jsx)(c,{className:t,ref:g,...GS(c,u),"data-testid":`virtuoso-item-list`,style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(t=>{let o=i(t.index,t.data,u);return a?(0,Z.jsx)(l,{...GS(l,u),height:e.itemHeight,index:t.index,width:e.itemWidth},o):(0,Q.createElement)(s,{...GS(s,u),className:n,"data-index":t.index,key:o},r(t.index,t.data,u))})})}),zC=Q.memo(function(){let e=GC(`HeaderComponent`),t=KC(`headerHeight`),n=GC(`headerFooterTag`),r=Db(Q.useMemo(()=>e=>{t(cx(e,`height`))},[t]),!0,!1),i=GC(`context`);return e==null?null:(0,Z.jsx)(n,{ref:r,children:(0,Z.jsx)(e,{...GS(e,i)})})}),BC=Q.memo(function(){let e=GC(`FooterComponent`),t=KC(`footerHeight`),n=GC(`headerFooterTag`),r=Db(Q.useMemo(()=>e=>{t(cx(e,`height`))},[t]),!0,!1),i=GC(`context`);return e==null?null:(0,Z.jsx)(n,{ref:r,children:(0,Z.jsx)(e,{...GS(e,i)})})}),VC=({children:e})=>{let t=Q.useContext(ES),n=KC(`itemDimensions`),r=KC(`viewportDimensions`),i=Db(Q.useMemo(()=>e=>{r(e.getBoundingClientRect())},[r]),!0,!1);return Q.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),(0,Z.jsx)(`div`,{ref:i,style:HS(!1),children:e})},HC=({children:e})=>{let t=Q.useContext(ES),n=KC(`windowViewportRect`),r=KC(`itemDimensions`),i=GC(`customScrollParent`),a=GC(`useWindowScroll`),o=Nb(n,i,!1);return Q.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),(0,Z.jsx)(`div`,{ref:o,style:US(!1,a),children:e})},{Component:UC,useEmitter:WC,useEmitterValue:GC,usePublisher:KC}=wS(LC,{optional:{context:`context`,totalCount:`totalCount`,overscan:`overscan`,itemContent:`itemContent`,components:`components`,computeItemKey:`computeItemKey`,data:`data`,initialItemCount:`initialItemCount`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`headerFooterTag`,listClassName:`listClassName`,itemClassName:`itemClassName`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,restoreStateFrom:`restoreStateFrom`,initialTopMostItemIndex:`initialTopMostItemIndex`,increaseViewportBy:`increaseViewportBy`},methods:{scrollTo:`scrollTo`,scrollBy:`scrollBy`,scrollToIndex:`scrollToIndex`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,stateChanged:`stateChanged`,readyStateChanged:`readyStateChanged`}},Q.memo(function({...e}){let t=GC(`useWindowScroll`),n=GC(`customScrollParent`),r=n||t?JC:qC,i=n||t?HC:VC,a=GC(`context`);return(0,Z.jsx)(r,{...e,...GS(r,a),children:(0,Z.jsxs)(i,{children:[(0,Z.jsx)(zC,{}),(0,Z.jsx)(RC,{}),(0,Z.jsx)(BC,{})]})})})),qC=YS({useEmitter:WC,useEmitterValue:GC,usePublisher:KC}),JC=XS({useEmitter:WC,useEmitterValue:GC,usePublisher:KC});function YC(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,yb.WARN),t===`normal`?0:parseInt(t??`0`,10)}function XC(e){return e.scrollHeight-e.scrollTop-e.clientHeight}function ZC(e,t=96){return XC(e)<=t}function QC(e){Math.abs(XC(e))>.5&&(e.scrollTop=e.scrollHeight)}function $C(e){let t=e.querySelectorAll(`[data-chat-message-index]`);if(!t.length)return 0;let n=e.getBoundingClientRect(),r=n.top+Math.min(180,n.height*.35),i=0,a=t.length-1;for(;i<a;){let e=Math.ceil((i+a)/2);t[e].getBoundingClientRect().top<=r?i=e:a=e-1}let o=Number.parseInt(t[i].dataset.chatMessageIndex??``,10);return Number.isFinite(o)?o:0}function ew(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`}var tw=new WeakMap;function nw(e,t){return tw.set(e,t),()=>{tw.get(e)===t&&tw.delete(e)}}function rw(e){return tw.get(e)}function iw(e){e.dispatchEvent(new Event(`chat-scroll-reading`))}function aw({context:e}){return e?.footer}var ow={Footer:aw},sw={top:800,bottom:800};function cw({rows:e,scrollRef:t,renderRow:n,footer:r}){let i=(0,Q.useRef)(null),[a,o]=(0,Q.useState)(),[s,c]=(0,Q.useState)(sw),[l,u]=(0,Q.useState)({rows:e,first:1e9});if(l.rows!==e){let t=l.rows[0]?.key,n=t?e.findIndex(e=>e.key===t):0;u({rows:e,first:l.first-Math.max(0,n)})}return(0,Q.useEffect)(()=>{o(t.current??void 0)},[t]),(0,Q.useLayoutEffect)(()=>{if(a)return nw(a,{reveal:t=>{let n=e.findIndex(e=>e.index===t||e.aliases.includes(t));return n<0?!1:(iw(a),i.current?.scrollToIndex({index:n,align:`start`,offset:-16,behavior:`auto`}),!0)},end:e=>i.current?.scrollToIndex({index:`LAST`,align:`end`,offset:(parseFloat(getComputedStyle(a).paddingBottom)||0)+(parseFloat(getComputedStyle(a.querySelector(`[data-chat-virtualized]`)??a).paddingBottom)||0),behavior:e&&ew()===`smooth`?`smooth`:`auto`})})},[a,e,l.first]),(0,Q.useLayoutEffect)(()=>{if(!a)return;let e=null,t=()=>{let t=window.getSelection();t&&!t.isCollapsed&&a.contains(t.anchorNode)?(e??={start:a.scrollTop,end:a.scrollTop},e.start=Math.min(e.start,a.scrollTop),e.end=Math.max(e.end,a.scrollTop)):e=null;let n=sw.top+(e?a.scrollTop-e.start:0),r=sw.bottom+(e?e.end-a.scrollTop:0);c(e=>e.top===n&&e.bottom===r?e:{top:n,bottom:r})},n=()=>{e!==null&&t()};return document.addEventListener(`selectionchange`,t),a.addEventListener(`scroll`,n,{passive:!0}),()=>{document.removeEventListener(`selectionchange`,t),a.removeEventListener(`scroll`,n)}},[a]),a?(0,Z.jsx)(oC,{ref:i,customScrollParent:a,data:e,skipAnimationFrameInResizeObserver:!0,components:ow,context:{footer:r},firstItemIndex:l.first,initialTopMostItemIndex:{index:e.length-1,align:`end`},defaultItemHeight:160,increaseViewportBy:s,computeItemKey:(e,t)=>t.key,itemContent:(t,r)=>(0,Z.jsx)(`div`,{className:r===e[0]?void 0:`pt-8`,children:n(r.index)})}):null}function lw(e){let t=(0,X.c)(6),{progress:n}=e,r=v(uw),i;if(t[0]!==r||t[1]!==n.completed||t[2]!==n.stage||t[3]!==n.total){let e=S(r).chat.runRecovery,a;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Pt,{className:`size-3.5 shrink-0 motion-safe:animate-spin`,"aria-hidden":!0}),t[5]=a):a=t[5],i=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex flex-wrap items-center gap-2 py-2 text-xs text-fg-muted`,"data-run-recovery":!0,children:[a,(0,Z.jsx)(`span`,{children:n.stage===`model_fallback`?e.fallback:e.retrying}),n.completed!=null&&n.total!=null?(0,Z.jsx)(`span`,{className:`tabular-nums`,children:e.attempt.replace(`{{attempt}}`,String(n.completed)).replace(`{{total}}`,String(n.total))}):null]}),t[0]=r,t[1]=n.completed,t[2]=n.stage,t[3]=n.total,t[4]=i}else i=t[4];return i}function uw(e){return e.language}var dw=e=>{},fw=(0,Q.memo)(function(e){let t=(0,X.c)(72),{messages:n,timelineEntries:r,personal:i,authToken:a,conversationId:o,workspaceConversationId:s,projectId:c,streaming:l,sending:u,progress:d,runError:f,reasoningLevel:p,registerListContentRef:m,onPickWelcomePrompt:h,welcomeSpotlight:g,welcomeOverlay:_,compactWelcome:y,onDeleteRound:b,onRetryUserMessageRound:x,deleteRoundDisabled:C,onSaveAssistantAsNote:w,onSaveAssistantToSourceNote:T,onExtractAssistantTask:E,onForkAssistantTurn:D,onEditUserMessage:O,editLatestUserOnly:k,editRequiresTurnId:A,responseFeedbackEnabled:j,showAssistantWorkLog:M,hideAssistantActions:N,trailingContent:P,replySpaceRef:F,scrollRef:I}=e,L=r===void 0?[]:r,R=i!==void 0&&i,z=u!==void 0&&u,B=y!==void 0&&y,ee=k!==void 0&&k,V=A!==void 0&&A,H=M===void 0||M,U=N!==void 0&&N,W=v(pw),te;t[0]===W?te=t[1]:(te=S(W),t[0]=W,t[1]=te);let ne=te,[re]=(0,Q.useState)(!!(I&&n.length>=300));if(n.length===0&&L.length===0&&!l&&!z&&!f){if(_){let e;return t[2]===_?e=t[3]:(e=(0,Z.jsx)(`div`,{className:`pb-1.5`,children:_}),t[2]=_,t[3]=e),e}let e;t[4]!==ne||t[5]!==g?(e=g??{headline:ne.chat.welcomeSpotlight.headline,contextKind:`empty`,contextStatus:`ready`},t[4]=ne,t[5]=g,t[6]=e):e=t[6];let n=h??dw,r;return t[7]!==B||t[8]!==e||t[9]!==n?(r=(0,Z.jsx)(`div`,{className:`pb-1.5`,children:(0,Z.jsx)(ym,{spotlight:e,onPickPrompt:n,compact:B})}),t[7]=B,t[8]=e,t[9]=n,t[10]=r):r=t[10],r}let ie=Date.now(),ae=n.findLastIndex(mw),oe,se,ce;if(t[11]!==ae||t[12]!==n||t[13]!==x||t[14]!==z||t[15]!==l){let e=n.slice(ae+1);oe=e.findLast(hw)?.outcome,se=l||z,ce=!se&&x&&ae>=0&&(n[ae].turnId||n[ae].deliveryStatus===`failed`&&n[ae].clientSubmissionId)&&!e.some(_w)?()=>x(ae):void 0,t[11]=ae,t[12]=n,t[13]=x,t[14]=z,t[15]=l,t[16]=oe,t[17]=se,t[18]=ce}else oe=t[16],se=t[17],ce=t[18];let le=ce,ue=oe?.turnId,de;t[19]!==le||t[20]!==f||t[21]!==se||t[22]!==ue?(de={turnId:ue,running:se,error:f,onRetry:le},t[19]=le,t[20]=f,t[21]=se,t[22]=ue,t[23]=de):de=t[23];let G=de,K=se&&(d?.stage===`model_retry`||d?.stage===`model_fallback`),fe;t[24]!==n.length||t[25]!==z||t[26]!==l?(fe=(e,t)=>!!((l||z||e.pendingResponseStatus)&&t===n.length-1&&e.role===`assistant`),t[24]=n.length,t[25]=z,t[26]=l,t[27]=fe):fe=t[27];let q=fe,pe;t[28]===n?pe=t[29]:(pe=(e,t)=>e.role===`assistant`&&e.turnId&&n[t-1]?.role===`task`&&n[t-1]?.turnId===e.turnId?n[t-1].taskTrigger:void 0,t[28]=n,t[29]=pe);let me=pe,J;t[30]!==me||t[31]!==q||t[32]!==n||t[33]!==R||t[34]!==p||t[35]!==H?(J=(e,t)=>!Zv(e,{personal:R,isStreaming:q(e,t),reasoningLevel:p,showAssistantWorkLog:H,followUpTrigger:me(e,t)})||e.role===`task`&&e.taskTrigger&&e.turnId&&n[t+1]?.role===`assistant`&&n[t+1]?.turnId===e.turnId?[]:[{key:xy(e,t),index:t,aliases:e.role===`assistant`&&n[t-1]?.role===`task`&&e.turnId===n[t-1]?.turnId?[t-1]:[]}],t[30]=me,t[31]=q,t[32]=n,t[33]=R,t[34]=p,t[35]=H,t[36]=J):J=t[36];let he=n.flatMap(J),ge;t[37]===n.length?ge=t[38]:(ge=(e,t)=>({key:e.id,index:n.length+t,aliases:[]}),t[37]=n.length,t[38]=ge),he.push(...L.map(ge));let _e=0,ve=n.map(e=>(_e=Math.max(e.timestamp??_e,_e),_e));L.length&&he.sort((e,t)=>{let r=e=>e<n.length?ve[e]:L[e-n.length].timestamp;return r(e.index)-r(t.index)||e.index-t.index});let ye=new Map(he.map((e,t)=>[e.index,he[t-1]?.index])),be=e=>{if(e>=n.length){let t=L[e-n.length];return(0,Z.jsx)(`div`,{"data-chat-timeline-entry":t.id,children:t.content},t.id)}let t=n[e],r=q(t,e),i=e===ae,l=n[e-1],u=me(t,e),f=ye.get(e),m=f===void 0?void 0:n[f],h=m&&f!==void 0?me(m,f)?n[f-1]?.timestamp??m.timestamp:m.timestamp:void 0,g=xy(t,e),_=u?l?.timestamp??t.timestamp:t.timestamp,v=Dy(_,h);return(0,Z.jsxs)(`div`,{id:`chat-message-${e}`,className:Y(`scroll-mt-4`,m&&(m.role===`user`||m.role===`task`)&&!u&&!v&&`-mt-5`),"data-chat-message-index":e,"data-chat-message-row":!0,"data-client-submission-id":t.clientSubmissionId,"data-message-render-key":t.renderKey,children:[u?(0,Z.jsx)(`span`,{id:`chat-message-${e-1}`,className:`block h-0 scroll-mt-4`,"aria-hidden":!0}):null,v&&_?(0,Z.jsx)(`div`,{className:`mb-8 flex justify-center`,"data-chat-time-separator":!0,children:(0,Z.jsx)(`time`,{suppressHydrationWarning:!0,className:`rounded-md px-2 py-1 text-xs tabular-nums text-fg-disabled`,dateTime:new Date(_).toISOString(),children:Oy(_,ie,W)})}):null,t.role===`task`&&t.taskTrigger?(0,Z.jsx)(ry,{trigger:t.taskTrigger}):(0,Z.jsx)(by,{message:t,personal:R,followUpTrigger:u,authToken:a,conversationId:o,workspaceConversationId:s,projectId:c,isStreaming:r,progress:r&&!K?d:null,reasoningLevel:p,messageIndex:e,onDeleteRound:b,onRetryUserMessageRound:x,userMessageCanRetry:!!x&&i,deleteRoundDisabled:!!(C&&i),onSaveAssistantAsNote:w,onSaveAssistantToSourceNote:T,onExtractAssistantTask:E,onForkAssistantTurn:D,suppressAssistantActions:U,onEditUserMessage:O,userMessageCanEdit:(!ee||i)&&(!V||!!t.turnId)&&t.deliveryStatus!==`sending`,responseFeedbackEnabled:j,showAssistantWorkLog:H})]},g)},xe=re?`pt-8`:`contents`,Se;t[39]===xe?Se=t[40]:(Se=Y(xe),t[39]=xe,t[40]=Se);let Ce;t[41]!==d||t[42]!==K?(Ce=K?(0,Z.jsx)(lw,{progress:d}):null,t[41]=d,t[42]=K,t[43]=Ce):Ce=t[43];let we;t[44]!==oe?.status||t[45]!==le||t[46]!==f||t[47]!==se?(we=!se&&f&&oe?.status!==`failed`?(0,Z.jsx)(yh,{errorText:f,onRetry:le}):null,t[44]=oe?.status,t[45]=le,t[46]=f,t[47]=se,t[48]=we):we=t[48];let Te;t[49]!==F||t[50]!==re?(Te=F&&(0,Z.jsx)(`div`,{ref:F,className:Y(!re&&`-mt-8`,`shrink-0 transition-none`),"aria-hidden":!0,"data-chat-reply-space":!0}),t[49]=F,t[50]=re,t[51]=Te):Te=t[51];let Ee;t[52]!==Se||t[53]!==Ce||t[54]!==we||t[55]!==Te||t[56]!==P?(Ee=(0,Z.jsxs)(`div`,{className:Se,children:[Ce,we,P,Te]}),t[52]=Se,t[53]=Ce,t[54]=we,t[55]=Te,t[56]=P,t[57]=Ee):Ee=t[57];let De=Ee,Oe=Hv,ke=aa,Ae=!re&&`flex flex-col gap-8`,je;t[58]===Ae?je=t[59]:(je=Y(`w-full min-w-0 pb-8`,Ae),t[58]=Ae,t[59]=je);let Me=re||void 0,Ne=re&&I?(0,Z.jsx)(cw,{rows:he,scrollRef:I,renderRow:be,footer:De}):(0,Z.jsxs)(Z.Fragment,{children:[he.map(e=>be(e.index)),De]}),Pe;t[60]!==m||t[61]!==je||t[62]!==Me||t[63]!==Ne?(Pe=(0,Z.jsx)(`div`,{ref:m,className:je,"data-chat-virtualized":Me,children:Ne}),t[60]=m,t[61]=je,t[62]=Me,t[63]=Ne,t[64]=Pe):Pe=t[64];let Fe;t[65]!==ke||t[66]!==Pe?(Fe=(0,Z.jsx)(ke,{children:Pe}),t[65]=ke,t[66]=Pe,t[67]=Fe):Fe=t[67];let Ie;return t[68]!==Oe||t[69]!==G||t[70]!==Fe?(Ie=(0,Z.jsx)(Oe,{value:G,children:Fe}),t[68]=Oe,t[69]=G,t[70]=Fe,t[71]=Ie):Ie=t[71],Ie});function pw(e){return e.language}function mw(e){return e.role===`user`}function hw(e){return e.outcome}function gw(e){return e.type===`tool_use`}function _w(e){return e.content.some(gw)}function vw(e){let t=(0,X.c)(8),{alt:n,className:r,"aria-hidden":i}=e,a=n?.trim()?n:void 0,o=i??(!a||void 0),s;t[0]===r?s=t[1]:(s=Y(`xopc-loop-logo relative inline-block shrink-0`,r),t[0]=r,t[1]=s);let c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsxs)(`linearGradient`,{id:`xopc-onboarding-ai-glass`,x1:`198`,y1:`180`,x2:`826`,y2:`844`,gradientUnits:`userSpaceOnUse`,children:[(0,Z.jsx)(`stop`,{stopColor:`var(--xopc-loop-ai-highlight)`}),(0,Z.jsx)(`stop`,{offset:`0.46`,stopColor:`var(--xopc-loop-ai)`}),(0,Z.jsx)(`stop`,{offset:`1`,stopColor:`var(--xopc-loop-ai-shadow)`})]}),t[2]=c):c=t[2];let l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Z.jsxs)(`svg`,{className:`size-full overflow-visible`,viewBox:`0 0 1024 1024`,fill:`none`,"aria-hidden":`true`,children:[(0,Z.jsxs)(`defs`,{children:[c,(0,Z.jsxs)(`linearGradient`,{id:`xopc-onboarding-human-glass`,x1:`340`,y1:`224`,x2:`700`,y2:`816`,gradientUnits:`userSpaceOnUse`,children:[(0,Z.jsx)(`stop`,{stopColor:`var(--xopc-loop-human-highlight)`}),(0,Z.jsx)(`stop`,{offset:`0.52`,stopColor:`var(--xopc-loop-human)`}),(0,Z.jsx)(`stop`,{offset:`1`,stopColor:`var(--xopc-loop-human-shadow)`})]})]}),(0,Z.jsx)(`circle`,{className:`xopc-loop-logo__ambient`,cx:`512`,cy:`512`,r:`330`}),(0,Z.jsx)(`circle`,{className:`xopc-loop-logo__origin`,cx:`512`,cy:`512`,r:`330`}),(0,Z.jsx)(`circle`,{className:`xopc-loop-logo__ai-glow`,cx:`512`,cy:`512`,r:`330`,strokeDasharray:`1419.162121 654.289030`,transform:`rotate(11.8 512 512)`}),(0,Z.jsx)(`circle`,{className:`xopc-loop-logo__ai`,cx:`512`,cy:`512`,r:`330`,stroke:`url(#xopc-onboarding-ai-glass)`,strokeDasharray:`1419.162121 654.289030`,transform:`rotate(11.8 512 512)`}),(0,Z.jsx)(`circle`,{className:`xopc-loop-logo__human`,cx:`512`,cy:`512`,r:`330`,stroke:`url(#xopc-onboarding-human-glass)`,strokeDasharray:`354.790530 1718.660621`,transform:`rotate(284.2 512 512)`}),(0,Z.jsx)(`circle`,{className:`xopc-loop-logo__liquid-front`,cx:`512`,cy:`512`,r:`330`,strokeDasharray:`58 2015.451151`,transform:`rotate(11.8 512 512)`})]}),t[3]=l):l=t[3];let u;return t[4]!==o||t[5]!==a||t[6]!==s?(u=(0,Z.jsx)(`span`,{className:s,role:`img`,"aria-hidden":o,"aria-label":a,children:l}),t[4]=o,t[5]=a,t[6]=s,t[7]=u):u=t[7],u}var yw=(0,Q.memo)(function(e){let t=(0,X.c)(19),{visible:n,onClick:r,edge:i,running:a}=e,o=i===void 0?`top`:i,s=a!==void 0&&a,c=v(bw),l;t[0]===c?l=t[1]:(l=S(c),t[0]=c,t[1]=l);let u=l,d=!n,f=o===`top`?`-top-2 -translate-y-full`:`bottom-2`,p=n?`opacity-100`:`opacity-0`,m;t[2]!==f||t[3]!==p?(m=Y(`pointer-events-none absolute inset-x-0 z-20 flex items-center justify-center transition-opacity duration-150 ease-out motion-reduce:transition-none`,f,p),t[2]=f,t[3]=p,t[4]=m):m=t[4];let h=n?`scale-100 opacity-100`:`pointer-events-none translate-y-1 scale-95 opacity-0`,g;t[5]===h?g=t[6]:(g=Y(`group relative pointer-events-auto flex size-11 sm:size-8 shrink-0 items-center justify-center rounded-full border border-edge-subtle bg-surface-overlay text-fg-muted shadow-surface`,`hover:border-edge-strong hover:text-fg`,ca.transition,ca.press,ca.focusRingPanel,h,`motion-reduce:translate-y-0 motion-reduce:scale-100`),t[5]=h,t[6]=g);let _=n?void 0:-1,y;t[7]===s?y=t[8]:(y=s?(0,Z.jsx)(`span`,{"data-scroll-to-bottom-running-logo":!0,className:`flex size-5 items-center justify-center`,"aria-hidden":!0,children:(0,Z.jsx)(vw,{className:`xopc-loop-logo--stream size-5`})}):(0,Z.jsx)(fs,{"data-scroll-to-bottom-arrow":!0,className:`size-4 transition-transform duration-150 ease-out group-hover:translate-y-0.5 motion-reduce:transition-none`,strokeWidth:1.8,"aria-hidden":!0}),t[7]=s,t[8]=y);let b;t[9]!==u.chat.scrollToBottom||t[10]!==r||t[11]!==_||t[12]!==y||t[13]!==g?(b=(0,Z.jsx)(`button`,{type:`button`,className:g,tabIndex:_,onClick:r,title:u.chat.scrollToBottom,"aria-label":u.chat.scrollToBottom,children:y}),t[9]=u.chat.scrollToBottom,t[10]=r,t[11]=_,t[12]=y,t[13]=g,t[14]=b):b=t[14];let x;return t[15]!==b||t[16]!==d||t[17]!==m?(x=(0,Z.jsx)(`div`,{"data-scroll-to-bottom-dock":!0,"aria-hidden":d,className:m,children:b}),t[15]=b,t[16]=d,t[17]=m,t[18]=x):x=t[18],x});function bw(e){return e.language}function xw(e){let t=e.getBoundingClientRect();for(let n of e.querySelectorAll(`[data-chat-message-row]`)){let e=n.getBoundingClientRect(),r=n.dataset.messageRenderKey??n.dataset.clientSubmissionId;if(r&&e.bottom>t.top&&e.top<t.bottom)return{rowId:r,offset:e.top-t.top}}return null}function Sw(e,t){if(!t)return!1;let n=Array.from(e.querySelectorAll(`[data-chat-message-row]`)).find(e=>e.dataset.messageRenderKey===t.rowId||e.dataset.clientSubmissionId===t.rowId);if(!n)return!1;let r=n.getBoundingClientRect().top-e.getBoundingClientRect().top-t.offset;return Math.abs(r)>.5&&(e.scrollTop+=r),!0}function Cw(e){return e.webkitDirectionInvertedFromDevice===!0?e.deltaY>0:e.deltaY<0}function ww(e,t){return!e||!t||e.role!==t.role?!1:e===t?!0:e.renderKey&&t.renderKey?e.renderKey===t.renderKey:e.clientSubmissionId&&t.clientSubmissionId?e.clientSubmissionId===t.clientSubmissionId:e.timestamp!=null&&e.timestamp===t.timestamp&&e.turnId===t.turnId}function Tw(e){let t=(0,X.c)(48),{hasToken:n,showSessionLoading:r,conversationId:i,chatMessages:a,streaming:o,hasMore:s,loadingMore:c,loadMoreMessages:l}=e,u=(0,Q.useRef)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useRef)(!0),m=(0,Q.useRef)(null),h=(0,Q.useRef)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(0),y=(0,Q.useRef)(0),b=(0,Q.useRef)(null),x=(0,Q.useRef)(null),S=(0,Q.useRef)(null),C=(0,Q.useRef)(null),w=(0,Q.useRef)(0),T=(0,Q.useRef)(0),[E,D]=(0,Q.useState)(!0),O=(0,Q.useRef)(!0),k=(0,Q.useRef)(0),A=(0,Q.useRef)(o),j;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(j={first:void 0,len:0,scrollHeight:0},t[0]=j):j=t[0];let M=(0,Q.useRef)(j),N;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(N=e=>{p.current=e,e&&(S.current=null)},t[1]=N):N=t[1];let P=N,F;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(F=e=>{let t=u.current;if(!t)return;let n=ZC(t);P(n),D(n),_.current=n?e:null,n||(S.current=xw(t))},t[2]=F):F=t[2];let I=F,L;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(L=()=>{let e=u.current,t=m.current;if(!e||!t||!p.current||!_.current&&!h.current)return!1;let n=_.current??h.current;if(!n)return!1;let r=!_.current&&g.current?.isConnected?g.current:Array.from(e.querySelectorAll(`[data-chat-message-row]`)).find(e=>e.dataset.messageRenderKey===n||e.dataset.clientSubmissionId===n);if(!r)return!1;_.current&&(h.current=n,g.current=r,_.current=null,v.current=Math.min(64,Math.max(0,e.clientHeight)*.1),y.current=v.current);let i=parseFloat(getComputedStyle(t.parentElement).paddingTop)||0,a=Math.max(i,t.getBoundingClientRect().top-r.getBoundingClientRect().bottom),o=Math.max(y.current,a),s=Math.min(v.current,Math.min(64,Math.max(0,e.clientHeight)*.1)),c=Math.max(0,Math.min(s,o-a));return y.current=a+c,t.style.height===`${c}px`?!1:(t.style.height=`${c}px`,!0)},t[3]=L):L=t[3];let R=L,z;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(z=e=>{let t=u.current;if(!t||!e?.force&&!p.current)return;e?.force&&P(!0);let n=rw(t);if(n){n.end(!!e?.smooth),w.current=t.scrollHeight,T.current=t.clientHeight;return}if(e?.smooth){t.scrollTo({top:t.scrollHeight,behavior:ew()});return}QC(t),w.current=t.scrollHeight,T.current=t.clientHeight,D(ZC(t))},t[4]=z):z=t[4];let B=z,ee;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(ee=()=>{let e=u.current;!e||e.scrollHeight<=e.clientHeight||(P(!1),D(ZC(e)))},t[5]=ee):ee=t[5];let V=ee,H;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(H=()=>{let e=u.current;if(!e)return;!p.current&&!rw(e)&&Sw(e,S.current);let t=R(),n=e.scrollHeight>w.current,r=e.clientHeight<T.current;w.current=e.scrollHeight,T.current=e.clientHeight,(n||r||t)&&B(),D(ZC(e))},t[6]=H):H=t[6];let U=H,W;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(W=()=>{let e=u.current;e&&p.current&&(rw(e)?QC(e):e.scrollHeight>w.current&&B()),C.current===null&&(C.current=requestAnimationFrame(()=>{C.current=null,U()}))},t[7]=W):W=t[7];let te=W,ne;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>{if(f.current===e||(x.current?.disconnect(),b.current?.disconnect(),b.current=null,x.current=null,f.current=e,!e))return;let t=new ResizeObserver(te);t.observe(e),x.current=t;let n=new MutationObserver(e=>{let t=u.current;!t||!p.current||!rw(t)||(R()||e.some(Ew))&&QC(t)});n.observe(e,{subtree:!0,childList:!0,characterData:!0,attributes:!0,attributeFilter:[`style`]}),b.current=n},t[8]=ne):ne=t[8];let re=ne,ie,ae;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(ie=()=>()=>{x.current?.disconnect(),b.current?.disconnect(),C.current!==null&&(cancelAnimationFrame(C.current),C.current=null)},ae=[],t[9]=ie,t[10]=ae):(ie=t[9],ae=t[10]),(0,Q.useEffect)(ie,ae);let oe;t[11]!==s||t[12]!==l||t[13]!==c?(oe=()=>{let e=u.current;if(!e)return;let t=ZC(e),n=T.current>0&&(e.scrollHeight!==w.current||e.clientHeight!==T.current);if(!t&&p.current&&n){D(!1),te();return}P(t),t||(S.current=xw(e)),D(t),t&&R(),e.scrollTop<100&&!t&&s&&!c&&l()},t[11]=s,t[12]=l,t[13]=c,t[14]=oe):oe=t[14];let se=oe,ce;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(ce=e=>{B({force:!0,smooth:e===void 0||e})},t[15]=ce):ce=t[15];let le=ce,ue,de;t[16]!==n||t[17]!==r?(ue=()=>{if(n){if(r){O.current=!0;return}O.current===!0&&(O.current=!1,P(!0),B({force:!0}))}},de=[r,n,P,B],t[16]=n,t[17]=r,t[18]=ue,t[19]=de):(ue=t[18],de=t[19]),(0,Q.useLayoutEffect)(ue,de);let G;t[20]!==n||t[21]!==r?(G=()=>{!n||r||(M.current={first:void 0,len:0,scrollHeight:0},k.current=0,w.current=0,T.current=0,h.current=null,g.current=null,y.current=0,Array.from(u.current?.querySelectorAll(`[data-chat-message-row]`)??[]).some(e=>e.dataset.messageRenderKey===_.current||e.dataset.clientSubmissionId===_.current)||(_.current=null),m.current&&(m.current.style.height=`0px`),P(!0),B({force:!0}))},t[20]=n,t[21]=r,t[22]=G):G=t[22];let K;t[23]!==i||t[24]!==n||t[25]!==r?(K=[i,n,r,P,B],t[23]=i,t[24]=n,t[25]=r,t[26]=K):K=t[26],(0,Q.useLayoutEffect)(G,K);let fe,q;t[27]!==a||t[28]!==r||t[29]!==o?(fe=()=>{if(r)return;let e=A.current&&!o;A.current=o;let t=R(),n=a.length,i=k.current;k.current=n;let s=(u.current?.scrollHeight??0)>w.current;p.current&&(n>i||s||t||e)&&B()},q=[a,o,r,B,R],t[27]=a,t[28]=r,t[29]=o,t[30]=fe,t[31]=q):(fe=t[30],q=t[31]),(0,Q.useLayoutEffect)(fe,q);let pe,me;t[32]!==a||t[33]!==r?(pe=()=>{let e=u.current;if(!e||r)return;let t=M.current,n=a[0],i=a.length,o=e.scrollHeight,s=i-t.len;s>0&&t.len>0&&!ww(n,t.first)&&ww(a[s],t.first)&&!rw(e)&&t.scrollHeight>0&&!Sw(e,S.current)&&(e.scrollTop+=o-t.scrollHeight),M.current={first:n,len:i,scrollHeight:o}},me=[a,r],t[32]=a,t[33]=r,t[34]=pe,t[35]=me):(pe=t[34],me=t[35]),(0,Q.useLayoutEffect)(pe,me);let J,he;t[36]!==n||t[37]!==r?(J=()=>{if(!n||r)return;let e=u.current;if(!e)return;let t=new ResizeObserver(te);t.observe(e);let i=e=>{Math.abs(e.deltaY)<Math.abs(e.deltaX)||Math.abs(e.deltaY)<.25||Cw(e)&&V()},a=0,o=e=>{e.touches.length===1&&(a=e.touches[0].clientY)},s=e=>{if(e.touches.length!==1)return;let t=e.touches[0].clientY,n=t-a;a=t,n>2&&V()},c=t=>{if(t.button!==0)return;let n=e.offsetWidth-e.clientWidth;if(n<=0)return;let r=e.getBoundingClientRect();t.clientX>=r.right-n&&V()},l=()=>{let t=window.getSelection();!t||t.isCollapsed||!e.contains(t.anchorNode)||(V(),S.current=xw(e))},d=t=>{(t.target instanceof Element?t.target:null)?.closest(`button[aria-expanded="false"]:not([aria-haspopup]), summary`)&&(V(),S.current=xw(e))};return e.addEventListener(`chat-scroll-reading`,V),e.addEventListener(`wheel`,i,{passive:!0}),e.addEventListener(`pointerdown`,c),e.addEventListener(`touchstart`,o,{passive:!0}),e.addEventListener(`touchmove`,s,{passive:!0}),e.addEventListener(`click`,d,!0),document.addEventListener(`selectionchange`,l),()=>{t.disconnect(),e.removeEventListener(`chat-scroll-reading`,V),e.removeEventListener(`wheel`,i),e.removeEventListener(`pointerdown`,c),e.removeEventListener(`touchstart`,o),e.removeEventListener(`touchmove`,s),e.removeEventListener(`click`,d,!0),document.removeEventListener(`selectionchange`,l)}},he=[n,r,V,te],t[36]=n,t[37]=r,t[38]=J,t[39]=he):(J=t[38],he=t[39]),(0,Q.useLayoutEffect)(J,he);let ge;t[40]===n?ge=t[41]:(ge=()=>{if(!n)return;let e=u.current,t=d.current;if(!e||!t)return;let r=()=>{let n=`${t.getBoundingClientRect().height+16}px`;e.style.paddingBottom=n,e.style.scrollPaddingBottom=n,te()};r();let i=new ResizeObserver(r);return i.observe(t),()=>{i.disconnect(),e.style.removeProperty(`padding-bottom`),e.style.removeProperty(`scroll-padding-bottom`)}},t[40]=n,t[41]=ge);let _e;t[42]!==n||t[43]!==r?(_e=[n,r,te],t[42]=n,t[43]=r,t[44]=_e):_e=t[44],(0,Q.useLayoutEffect)(ge,_e);let ve;return t[45]!==E||t[46]!==se?(ve={scrollRef:u,composerDockRef:d,atBottom:E,registerListContentRef:re,scrollToBottom:le,onScroll:se,replySpaceRef:m,reserveReplySpace:I},t[45]=E,t[46]=se,t[47]=ve):ve=t[47],ve}function Ew(e){return e.target instanceof HTMLElement&&e.target.hasAttribute(`data-virtuoso-scroller`)}var Dw=256*1024,Ow=new TextEncoder;function kw(e){return Ow.encode(e).byteLength}function Aw(e){return kw(e)<=262144?e:new TextDecoder().decode(Ow.encode(e).subarray(0,Dw),{stream:!0})}function jw(e){let t=512*1024,n=e.length>20,r=[];for(let i of e.slice(-20).reverse()){let e=i.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
60
- `);if((i.content.some(e=>e.type!==`text`)||i.attachments?.length)&&(n=!0),!e)continue;if(t<=256){n=!0;continue}let a=Ow.encode(e),o=a.byteLength+256>t?new TextDecoder().decode(a.subarray(0,t-256),{stream:!0}):e;o!==e&&(n=!0);let s=kw(o)+256;t-=s,r.unshift({role:i.role,content:[{type:`text`,text:o}],timestamp:i.timestamp,renderKey:i.renderKey?.slice(0,128)})}return{messages:r,truncated:n,bytes:512*1024-t}}var Mw=`xopc:side-chat-panes:v3`,Nw={text:``,attachments:[]};function Pw(e){return Math.min(760,Math.max(360,Math.round(e)))}function Fw(){return{panes:{},tabs:[],widthPx:520}}function Iw(){try{let e=JSON.parse(sessionStorage.getItem(Mw)||`{}`),t=e.identity;if(t&&t!==_.getState().conversationId)return Fw();let n=Array.isArray(e.tabs)?e.tabs.filter(e=>!!(e?.id&&e.parentConversationId)):[],r=e.panes&&typeof e.panes==`object`?e.panes:{},i=Object.fromEntries(Object.entries(r).map(([e,t])=>{let r=n.filter(t=>t.parentConversationId===e),i=typeof t?.activeId==`string`&&r.some(e=>e.id===t.activeId)?t.activeId:r.at(-1)?.id??null;return[e,{open:t?.open===!0&&r.length>0,activeId:i}]}));for(let e of n)i[e.parentConversationId]??={open:!1,activeId:e.id};return{panes:i,tabs:n,widthPx:Pw(typeof e.widthPx==`number`?e.widthPx:520)}}catch{return Fw()}}function Lw(e){try{sessionStorage.setItem(Mw,JSON.stringify({...e,identity:_.getState().conversationId}))}catch{}}var Rw=Iw(),zw=b((e,t)=>{let n=n=>{e(n),queueMicrotask(()=>{let e=t();Lw({panes:e.panes,tabs:e.tabs,widthPx:e.widthPx})})},r=(e,r)=>{let i=t().panes[e]??{open:!1,activeId:null};n({panes:{...t().panes,[e]:{...i,...r}}})};return{...Rw,drafts:{},readings:{},setDraftText:(n,r)=>e({drafts:{...t().drafts,[n]:{...t().drafts[n]??Nw,text:r}}}),setDraftAttachments:(n,r)=>e({drafts:{...t().drafts,[n]:{...t().drafts[n]??Nw,attachments:r}}}),rememberMessages:(n,r)=>{let i={...t().readings};delete i[n],i[n]=jw(r),i[n].truncated||=t().readings[n]?.truncated??!1;let a=Object.values(i).reduce((e,t)=>e+t.bytes,0);for(;Object.keys(i).length>5||a>2097152;){let e=Object.keys(i)[0];a-=i[e].bytes,delete i[e]}e({readings:i})},markEnded:(e,r)=>n({tabs:t().tabs.map(t=>t.id===e?{...t,ended:r,runId:void 0}:t)}),markPromoted:(e,r)=>n({tabs:t().tabs.map(t=>t.id===e?{...t,ended:`promoted`,promotedConversationId:r,runId:void 0}:t)}),replaceTab:(r,i)=>{yi.getState().replaceSideChat(r,i.id,i.parentConversationId);let a=t();if(!a.tabs.some(e=>e.id===r))return;let o={...a.drafts,[i.id]:a.drafts[r]??Nw},s={...a.readings};delete o[r],delete s[r],e({drafts:o,readings:s}),n({tabs:a.tabs.map(e=>e.id===r?{...i,fresh:!0}:e),panes:{...a.panes,[i.parentConversationId]:{open:a.panes[i.parentConversationId]?.open??!1,activeId:a.panes[i.parentConversationId]?.activeId===r?i.id:a.panes[i.parentConversationId]?.activeId??i.id}}})},reset:()=>{yi.getState().reset(),e({drafts:{},readings:{},pendingCreate:null,creatingRequests:{}}),n({panes:{},tabs:[]})},pendingCreate:null,creatingRequests:{},requestCreate:(n,i=[])=>{yi.getState().setOpen(!0,n),!(t().creatingRequests[n]||t().pendingCreate?.parentConversationId===n)&&(e({pendingCreate:{requestId:crypto.randomUUID(),parentConversationId:n,selections:i}}),r(n,{open:!0}))},claimPendingCreate:(n,r)=>{let i=t().pendingCreate;return!i||i.parentConversationId!==n||i.requestId!==r?null:(e({pendingCreate:null,creatingRequests:{...t().creatingRequests,[n]:r}}),i)},finishCreate:(n,r)=>{if(t().creatingRequests[n]!==r)return;let i={...t().creatingRequests};delete i[n],e({creatingRequests:i})},addTab:(e,r=!0)=>{yi.getState().addSideChat(e.id,e.title,e.parentConversationId,r);let i=[...t().tabs.filter(t=>t.id!==e.id),{...e,lastSelectedAt:Date.now()}],a=t().panes[e.parentConversationId]??{open:!1,activeId:null};n({tabs:i,panes:{...t().panes,[e.parentConversationId]:{...a,activeId:e.id,open:!0}}})},removeTab:r=>{let i=t().tabs.find(e=>e.id===r);if(!i)return;yi.getState().remove(`side:${r}`,i.parentConversationId);let a={...t().drafts},o={...t().readings};delete a[r],delete o[r],e({drafts:a,readings:o});let s=t().tabs.filter(e=>e.id!==r),c=s.filter(e=>e.parentConversationId===i.parentConversationId),l=t().panes[i.parentConversationId]??{open:!1,activeId:null},u=l.activeId===r?c.at(-1)?.id??null:l.activeId;n({tabs:s,panes:{...t().panes,[i.parentConversationId]:{open:c.length>0&&l.open,activeId:u}}})},setActive:e=>{let i=t().tabs.find(t=>t.id===e);i&&(yi.getState().activate(`side:${e}`,i.parentConversationId),n({tabs:t().tabs.map(t=>t.id===e?{...t,lastSelectedAt:Date.now()}:t)}),r(i.parentConversationId,{activeId:e,open:!0}))},setTabStatus:(n,r)=>{let i=t().tabs.find(e=>e.id===n);i&&(i.waiting!==r.waiting||i.disconnected!==r.disconnected||i.unread!==r.unread)&&e({tabs:t().tabs.map(e=>e.id===n?{...e,...r}:e)})},setTabRunId:(e,r)=>n({tabs:t().tabs.map(t=>t.id===e?{...t,runId:r}:t)}),setOpen:(e,n)=>{if(yi.getState().setOpen(n,e),!n){r(e,{open:n});return}let i=t(),a=i.tabs.filter(t=>t.parentConversationId===e&&!t.ended&&!t.promotedConversationId),o=a.find(t=>t.id===i.panes[e]?.activeId)??a.reduce((e,t)=>!e||(t.lastSelectedAt??0)>=(e.lastSelectedAt??0)?t:e,void 0);r(e,{open:n,activeId:o?.id??null}),o&&yi.getState().activate(`side:${o.id}`,e),o||i.requestCreate(e)},setWidthPx:e=>n({widthPx:Pw(e)})}});_.subscribe((e,t)=>{if(e.conversationId&&!t.conversationId&&e.baseUrl===t.baseUrl){let e=Iw();zw.setState(e)}if(e.baseUrl!==t.baseUrl||t.conversationId!==void 0&&e.conversationId!==t.conversationId){zw.getState().reset();try{sessionStorage.removeItem(`xopc:side-chat-client-id`)}catch{}}});function Bw(e){return e.acceptsArgs?`/${e.name} `:`/${e.name}`}var Vw=3e4,Hw=null;function Uw(e,t){return e.map(e=>({id:`file:${e.id}`,kind:`file`,name:e.name,description:e.path,relativePath:e.path,isDirectory:e.isDirectory,...t.has(e.path)?{isRecent:!0}:{},fileRef:{sourceId:e.id,expectedVersion:e.revision}}))}async function Ww(e,t){let n=t.conversationId?.trim(),r=t.agentId?.trim(),i=t.limit??15,a=e.trim(),o=t.recentPaths??new Set;if(n&&a.length===0){let e=Date.now();if(Hw&&Hw.key===n&&e-Hw.at<Vw)return Hw.items.map(e=>({...e,...o.has(e.relativePath)?{isRecent:!0}:{isRecent:void 0}}))}let s={conversationId:n,agentId:r},c=Uw(a.length===0?await Ya(``,s):await qa(a,s,i),o);return n&&a.length===0&&(Hw={key:n,at:Date.now(),items:c}),c}async function Gw(e,t){return Ya(e,{conversationId:t.conversationId,agentId:t.agentId})}function Kw(e,...t){let n=e.trim().toLocaleLowerCase();return!n||t.some(e=>e?.toLocaleLowerCase().includes(n))}async function qw(e){let t=await h(g(e)),n=await t.json().catch(()=>({}));if(!t.ok||!n.payload)throw Error(typeof n.error==`string`?n.error:`HTTP ${t.status}`);return n.payload}var Jw=[{kind:`file`,search:(e,t)=>Ww(e,{conversationId:t.conversationId,agentId:t.currentAgentId,limit:10,recentPaths:t.recentPaths})},{kind:`note`,async search(e,t){return(await He({...e.trim()?{search:e.trim()}:{},limit:5,sortBy:`updatedAt`,sortOrder:`desc`})).items.filter(e=>e.status!==`trashed`&&!t.selectedContextKeys.has(`note:${e.id}`)).map(e=>({id:`note:${e.id}`,kind:`note`,name:e.title?.trim()||e.snippet?.trim()||S(t.language).chat.commandPalette.untitledNote,description:e.snippet?.trim()||``,noteRef:{sourceId:e.id,expectedVersion:String(e.updatedAt)}}))}},{kind:`session`,async search(e,t){return(await gn({...e.trim()?{search:e.trim()}:{},limit:5,sortBy:`updatedAt`,sortOrder:`desc`})).items.filter(e=>e.key!==t.conversationId&&!t.selectedContextKeys.has(`session:${e.key}`)).map(e=>({id:`session:${e.key}`,kind:`session`,name:e.name?.trim()||e.key,description:`${e.messageCount} messages`,sessionRef:{sourceId:e.key,expectedVersion:e.updatedAt}}))}},{kind:`skill`,async search(e,t){return(await So(t.currentAgentId,t.conversationId)).skills.flatMap(n=>{if(!n.availableForCurrentAgent)return[];let r=Oo(n,t.language);return Kw(e,n.name,r.displayName,r.description,...r.searchTerms)?[{id:`skill:${n.name}`,kind:`skill`,name:r.displayName,description:r.description,canonicalName:n.name}]:[]}).slice(0,5)}},{kind:`agent`,async search(e,t){let n=await si(),r=S(t.language).agentsSettings;return n.items.flatMap(t=>{let n=es(t,r),i=ts(t,r);return Kw(e,t.id,n,i)?[{id:`agent:${t.id}`,kind:`agent`,name:n,description:i,agentId:t.id,...t.avatar?{avatar:t.avatar}:{}}]:[]}).slice(0,5)}},{kind:`browser_tab`,async search(e,t){return(await qw(`/api/browser/tabs?${new URLSearchParams({conversationId:t.conversationId})}`)).tabs.flatMap(n=>!Kw(e,n.title,n.url)||t.selectedContextKeys.has(`browser_tab:${n.id}`)?[]:[{id:`browser-tab:${n.id}`,kind:`browser_tab`,name:n.title||n.url,description:n.url,url:n.url,tabRef:{sourceId:n.id,expectedVersion:n.documentId}}])}}],Yw=(0,Q.createContext)({target:null,register:()=>()=>{}});function Xw(e){let t=(0,X.c)(9),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0];let[i,a]=(0,Q.useState)(r),o;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(o=e=>(a(t=>[...t,e]),()=>a(t=>t.filter(t=>t!==e))),t[1]=o):o=t[1];let s=o,c;t[2]===i?c=t[3]:(c=i.at(-1)??null,t[2]=i,t[3]=c);let l;t[4]===c?l=t[5]:(l={target:c,register:s},t[4]=c,t[5]=l);let u=l,d;return t[6]!==n||t[7]!==u?(d=(0,Z.jsx)(Yw,{value:u,children:n}),t[6]=n,t[7]=u,t[8]=d):d=t[8],d}function Zw(){let e=(0,X.c)(2),{register:t}=(0,Q.useContext)(Yw),n;return e[0]===t?n=e[1]:(n=(0,Z.jsx)(`div`,{ref:t,className:`min-w-0 shrink-0`}),e[0]=t,e[1]=n),n}function Qw(){return(0,Q.useContext)(Yw).target}function $w({conversationId:e,turnId:t,messages:n,ready:r,hasMore:i,loadingMore:a,loadMore:o,reveal:s,onLocated:c}){let l=(0,Q.useRef)({key:``,finished:!1,requestedLength:-1});(0,Q.useEffect)(()=>{let u=`${e??``}:${t??``}`;if(l.current.key!==u&&(l.current={key:u,finished:!1,requestedLength:-1}),!t||!r||l.current.finished)return;let d=l.current,f=n.findIndex(e=>e.turnId===t);if(f>=0){let e=0,t=!1,n=0,r=()=>{t||l.current===d&&(s(f)?(d.finished=!0,c?.(!0)):++n<3?e=requestAnimationFrame(r):(d.finished=!0,c?.(!1)))};return e=requestAnimationFrame(r),()=>{t=!0,cancelAnimationFrame(e)}}if(!a){if(!i||l.current.requestedLength===n.length){l.current.finished=!0,c?.(!1);return}l.current.requestedLength=n.length,o().catch(()=>{l.current===d&&(d.finished=!0,c?.(!1))})}},[e,t,n,r,i,a,o,s,c])}function eT({interaction:e,path:t,complete:n}){let r=v(e=>e.language)===`zh`,[i,a]=(0,Q.useState)(`{}`),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),u=async r=>{s(!0),l(!1);try{let a=r===`accept`?JSON.parse(i):void 0;if(r===`accept`&&(!a||typeof a!=`object`||Array.isArray(a)))throw Error(`Expected an object`);await y(t,{method:`POST`,body:JSON.stringify({requestId:e.requestId,action:r,content:a})}),n()}catch{l(!0)}finally{s(!1)}},d=Object.entries(e.inputSchema.properties??{});return(0,Z.jsxs)(`form`,{className:`space-y-2 rounded-xl border border-edge bg-surface p-3 text-sm`,onSubmit:e=>{e.preventDefault(),u(`accept`)},children:[(0,Z.jsx)(`p`,{className:`font-medium text-fg`,children:r?`设备需要补充信息`:`Device needs input`}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-fg-muted`,children:e.message}),d.length?(0,Z.jsx)(`ul`,{className:`max-h-24 overflow-y-auto text-xs text-fg-muted`,children:d.map(([t,n])=>(0,Z.jsxs)(`li`,{children:[t,n.type?` (${n.type})`:``,e.inputSchema.required?.includes(t)?` *`:``,Array.isArray(n.enum)?` · ${JSON.stringify(n.enum).slice(0,180)}`:``]},t))}):null,(0,Z.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),maxLength:7e3,"aria-label":r?`设备请求参数(JSON)`:`Device response (JSON)`,className:`h-16 w-full resize-none rounded-md border border-edge bg-surface p-2 font-mono text-xs`}),c?(0,Z.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:r?`输入不符合要求,或设备请求已结束。`:`The input is invalid or the device request has ended.`}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(vi,{type:`button`,variant:`secondary`,disabled:o,onClick:()=>void u(`decline`),children:r?`拒绝`:`Decline`}),(0,Z.jsx)(vi,{type:`submit`,disabled:o,children:r?`提交给设备`:`Send to device`})]})]})}function tT(e){let t=(0,X.c)(8),{conversationId:n,active:r}=e,i;t[0]===n?i=t[1]:(i=n?g(`/api/endpoint-tools/interactions/${encodeURIComponent(n)}`):null,t[0]=n,t[1]=i);let a=i,o=r?1500:5e3,s;t[2]===o?s=t[3]:(s={refreshInterval:o,shouldRetryOnError:!1},t[2]=o,t[3]=s);let{data:c,mutate:l}=Qr(a,nT,s),u=c?.payload?.[0],d;return t[4]!==u||t[5]!==l||t[6]!==a?(d=a&&u?(0,Z.jsx)(eT,{interaction:u,path:a,complete:()=>{l()}},u.requestId):null,t[4]=u,t[5]=l,t[6]=a,t[7]=d):d=t[7],d}function nT(e){return y(e)}function rT(e){let t=(0,X.c)(24),{sk:n,onPick:r,disabled:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Ht,{className:`size-4`,"aria-hidden":!0}),t[0]=a):a=t[0];let o;t[1]===n.findCapability?o=t[2]:(o=(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-accent-fg`,children:[a,n.findCapability]}),t[1]=n.findCapability,t[2]=o);let s;t[3]===n.findWelcome?s=t[4]:(s=(0,Z.jsx)(`h1`,{className:`text-xl font-semibold text-fg`,children:n.findWelcome}),t[3]=n.findWelcome,t[4]=s);let c;t[5]===n.findDescription?c=t[6]:(c=(0,Z.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n.findDescription}),t[5]=n.findDescription,t[6]=c);let l;if(t[7]!==i||t[8]!==r||t[9]!==n.findExamples){let e;t[11]!==i||t[12]!==r?(e=e=>(0,Z.jsx)(vi,{disabled:i,onClick:()=>r(e),children:e},e),t[11]=i,t[12]=r,t[13]=e):e=t[13],l=n.findExamples.map(e),t[7]=i,t[8]=r,t[9]=n.findExamples,t[10]=l}else l=t[10];let u;t[14]===l?u=t[15]:(u=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:l}),t[14]=l,t[15]=u);let d;t[16]===n.findBack?d=t[17]:(d=(0,Z.jsx)(p,{to:`/capabilities/skills`,className:`text-sm text-accent-fg hover:underline`,children:n.findBack}),t[16]=n.findBack,t[17]=d);let f;return t[18]!==o||t[19]!==s||t[20]!==c||t[21]!==u||t[22]!==d?(f=(0,Z.jsxs)(`section`,{className:`mx-auto flex max-w-xl flex-col items-start gap-4 py-8 sm:py-12`,children:[o,s,c,u,d]}),t[18]=o,t[19]=s,t[20]=c,t[21]=u,t[22]=d,t[23]=f):f=t[23],f}function iT(e){let t=`/api/sessions/${encodeURIComponent(e)}/connection-wait`,n=Sn(t=>t.sessions[e]?.localDraft),{data:r,mutate:i,isLoading:a}=Qr(n?null:[t,n===!1?`persisted`:`unknown`],async()=>await jr(e)?null:(await y(g(t))).payload,{refreshInterval:e=>e?.wait?5e3:0,revalidateOnFocus:!0}),o=(0,Q.useRef)(r);o.current=r;let s=(0,Q.useRef)(!1),c=(0,Q.useRef)(!1),l=(0,Q.useRef)(0),u=(0,Q.useRef)(null),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(),[h,_]=(0,Q.useState)(),b=(0,Q.useCallback)(async(e,n,r,a,d)=>{let p=o.current,h=p?.wait;if(!h||(e===`cancel`?c.current:s.current||c.current))return!1;e===`cancel`?c.current=!0:s.current=!0,l.current+=1,f(!0),m(void 0),e===`cancel`&&_(void 0);let b=e===`connect`?as():null,x=JSON.stringify([h.id,h.objectiveRevision,e,n,r,a,d]);u.current?.signature!==x&&(u.current={signature:x,key:crypto.randomUUID()});let S=u.current.key,C=i=>y(g(`${t}/actions`),{method:`POST`,body:JSON.stringify({action:e,needKey:n,accountId:r,candidateRef:a,instanceId:d,waitId:h.id,expectedTranscriptId:i.transcriptId,expectedVersion:i.wait.version,...e===`cancel`?{expectedObjectiveRevision:h.objectiveRevision}:{},idempotencyKey:S})});try{let n;try{n=await C(p)}catch(r){if(e!==`cancel`||r.status!==409)throw r;let a=(await y(g(t))).payload;if(await i(e=>!e||e.transcriptId!==a.transcriptId||a.revision>=e.revision?a:e,!1),a.transcriptId!==p.transcriptId||a.wait?.id!==h.id||a.wait.objectiveRevision!==h.objectiveRevision)throw r;n=await C(a)}let r=n.payload.snapshot;if(await i(e=>!e||e.transcriptId!==r.transcriptId||r.revision>=e.revision?r:e,!1),n.payload.authorizationUrl){if(!await is(n.payload.authorizationUrl,b))throw Error(`Unable to open the authorization window. Allow pop-ups, then retry.`)}else os(b);return u.current?.signature===x&&(u.current=null),!0}catch(t){if(os(b),t.status===409&&e===`cancel`){let e=v.getState().language===`zh`?`目标状态已变化,未能取消。请检查当前任务状态后再试。`:`The objective state changed and cancellation was not confirmed. Check its current status and try again.`;m(e),_(e)}else if(t.status!==409){let n=t instanceof Error?t.message:String(t);m(n),e===`cancel`&&_(n)}return await i(),!1}finally{e===`cancel`?c.current=!1:s.current=!1,--l.current,f(l.current>0)}},[t,i]);return(0,Q.useEffect)(()=>{let t=t=>{let n=t.detail;n?.conversationId===e&&(n.revision??1/0)>(o.current?.revision??0)&&i()};window.addEventListener(`session-connection-wait-changed`,t);let n=()=>{i()};return window.addEventListener(`gateway-realtime-connected`,n),()=>{window.removeEventListener(`session-connection-wait-changed`,t),window.removeEventListener(`gateway-realtime-connected`,n)}},[e,i]),{wait:r?.wait,isLoading:a,busy:d,error:p,cancellationError:h,act:b,dismissError:()=>{m(void 0),_(void 0)}}}function aT(e){let t=(0,X.c)(39),{need:n,language:r,disabled:i,onSelect:a,onConnect:o}=e,s=(0,Q.useId)(),[c,l]=(0,Q.useState)(),u=r===`zh`,d;if(t[0]!==n.accounts||t[1]!==c){let e;t[3]===c?e=t[4]:(e=e=>e.id===c,t[3]=c,t[4]=e),d=n.accounts.some(e),t[0]=n.accounts,t[1]=c,t[2]=d}else d=t[2];let f=d,p=u?`这次使用哪个 ${n.label} 账号或工作区?`:`Which ${n.label} account or workspace should this request use?`,m;t[5]===p?m=t[6]:(m=(0,Z.jsx)(`legend`,{className:`float-left mb-3 w-full text-sm font-medium text-fg`,children:p}),t[5]=p,t[6]=m);let h;if(t[7]!==s||t[8]!==n.accounts||t[9]!==c){let e;t[11]!==s||t[12]!==c?(e=e=>(0,Z.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-center gap-3 rounded-lg border px-3 py-2 text-sm text-fg hover:bg-surface-hover ${c===e.id?`border-accent bg-surface-hover`:`border-edge`}`,children:[(0,Z.jsx)(`input`,{type:`radio`,name:s,value:e.id,checked:c===e.id,onChange:()=>l(e.id),className:`shrink-0 accent-accent focus-visible:outline-2 focus-visible:outline-accent`}),(0,Z.jsx)(`span`,{className:`min-w-0 break-words`,children:e.label})]},e.id),t[11]=s,t[12]=c,t[13]=e):e=t[13],h=n.accounts.map(e),t[7]=s,t[8]=n.accounts,t[9]=c,t[10]=h}else h=t[10];let g;t[14]===h?g=t[15]:(g=(0,Z.jsx)(`div`,{className:`clear-both grid max-h-48 gap-2 overflow-y-auto sm:grid-cols-2`,children:h}),t[14]=h,t[15]=g);let _=u?`选择仅用于本次目标,选定后会自动继续。`:`This choice applies to this objective only. It will continue after selection.`,v;t[16]===_?v=t[17]:(v=(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:_}),t[16]=_,t[17]=v);let y=i||!f,b;t[18]!==a||t[19]!==c||t[20]!==f?(b=()=>{f&&c&&a(c)},t[18]=a,t[19]=c,t[20]=f,t[21]=b):b=t[21];let x=u?`使用所选账号并继续`:`Use selected account and continue`,S;t[22]!==x||t[23]!==y||t[24]!==b?(S=(0,Z.jsx)(`button`,{type:`button`,disabled:y,onClick:b,className:`min-h-11 rounded-lg bg-accent px-3 py-2 text-sm text-on-accent disabled:opacity-50`,children:x}),t[22]=x,t[23]=y,t[24]=b,t[25]=S):S=t[25];let C=u?`连接其他账号`:`Connect another account`,w;t[26]!==i||t[27]!==o||t[28]!==C?(w=(0,Z.jsx)(`button`,{type:`button`,disabled:i,onClick:o,className:`min-h-11 rounded-lg px-3 py-2 text-sm text-accent hover:bg-surface-hover disabled:opacity-50`,children:C}),t[26]=i,t[27]=o,t[28]=C,t[29]=w):w=t[29];let T;t[30]!==S||t[31]!==w?(T=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[S,w]}),t[30]=S,t[31]=w,t[32]=T):T=t[32];let E;return t[33]!==i||t[34]!==T||t[35]!==m||t[36]!==g||t[37]!==v?(E=(0,Z.jsxs)(`fieldset`,{disabled:i,className:`mt-3 min-w-0 space-y-3 border-t border-edge-subtle pt-3`,children:[m,g,v,T]}),t[33]=i,t[34]=T,t[35]=m,t[36]=g,t[37]=v,t[38]=E):E=t[38],E}var oT=(0,Q.lazy)(()=>l(()=>import(`./mcp-conversation-setup-page-CsTSmjmX.js`).then(e=>({default:e.McpConversationSetupDialog})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29])));function sT(e){let t=(0,X.c)(35),{conversationId:n}=e,r=v(uT),[i,a]=f(),o;t[0]===i?o=t[1]:(o=i.get(`mcpSetup`),t[0]=i,t[1]=o);let s=o,c;t[2]!==i||t[3]!==a?(c=e=>{let t=new URLSearchParams(i);e?t.set(`mcpSetup`,e):t.delete(`mcpSetup`),a(t,{replace:!e})},t[2]=i,t[3]=a,t[4]=c):c=t[4];let l=c,u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={refreshInterval:cT,shouldRetryOnError:!1},t[5]=u):u=t[5];let{data:d,mutate:m}=Qr(`/api/mcp/setup/conversations/${encodeURIComponent(n)}`,lT,u),h;t[6]!==n||t[7]!==d?.permitted||t[8]!==m?(h=()=>{if(d?.permitted===!1)return;let e=e=>{let t=e.detail;(t?.conversationId??t?.key)===n&&m()},t=()=>{m()};return window.addEventListener(`session-mcp-setup-changed`,e),window.addEventListener(`session-transcript-updated`,e),window.addEventListener(`gateway-realtime-connected`,t),()=>{window.removeEventListener(`session-mcp-setup-changed`,e),window.removeEventListener(`session-transcript-updated`,e),window.removeEventListener(`gateway-realtime-connected`,t)}},t[6]=n,t[7]=d?.permitted,t[8]=m,t[9]=h):h=t[9];let g=d?.permitted,_;t[10]!==n||t[11]!==m||t[12]!==g?(_=[n,m,g],t[10]=n,t[11]=m,t[12]=g,t[13]=_):_=t[13],(0,Q.useEffect)(h,_);let y;t[14]!==m||t[15]!==s||t[16]!==l?(y=s?(0,Z.jsx)(Q.Suspense,{fallback:null,children:(0,Z.jsx)(oT,{setupId:s,onClose:()=>{l(null),m()}})}):null,t[14]=m,t[15]=s,t[16]=l,t[17]=y):y=t[17];let b=y;if(!d?.setup)return b;let x=d.setup,S=r===`zh`?`服务连接`:`Service connection`,C=x.expired?r===`zh`?`连接请求已过期`:`Connection request expired`:r===`zh`?`连接`:`Connect`,w=x.displayName||x.serverId,T;t[18]!==w||t[19]!==C?(T=(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 break-all text-sm text-fg`,role:`status`,children:[C,` `,w]}),t[18]=w,t[19]=C,t[20]=T):T=t[20];let E=`/mcp-setup/${encodeURIComponent(x.setupId)}`,D;t[21]!==l||t[22]!==x.setupId?(D=e=>{e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),l(x.setupId))},t[21]=l,t[22]=x.setupId,t[23]=D):D=t[23];let O=r===`zh`?`完成连接`:`Complete connection`,k;t[24]!==E||t[25]!==D||t[26]!==O?(k=(0,Z.jsx)(p,{className:`inline-flex min-h-11 items-center rounded-lg px-3 text-sm text-accent-fg hover:bg-surface-hover`,to:E,onClick:D,children:O}),t[24]=E,t[25]=D,t[26]=O,t[27]=k):k=t[27];let A;t[28]!==T||t[29]!==k||t[30]!==S?(A=(0,Z.jsxs)(`section`,{className:`mb-2 flex flex-wrap items-center gap-3 rounded-xl border border-edge bg-surface-panel px-3 py-2`,"aria-label":S,children:[T,k]}),t[28]=T,t[29]=k,t[30]=S,t[31]=A):A=t[31];let j;return t[32]!==b||t[33]!==A?(j=(0,Z.jsxs)(Z.Fragment,{children:[A,b]}),t[32]=b,t[33]=A,t[34]=j):j=t[34],j}function cT(e){return e?.setup?5e3:0}async function lT(e){try{return{permitted:!0,...(await y(g(e))).payload}}catch(e){let t=e;if([403,404].includes(t.status??0))return{permitted:!1,setup:null};throw t}}function uT(e){return e.language}var dT={zh:{waiting:`等待连接`,install:`安装`,installing:`正在准备安装`,connect:`连接`,reconnect:`重新连接`,details:`查看详情`,skip:`跳过连接`,cancel:`取消这个目标`,ready:`已连接`,check:`我已完成授权`,authorizing:`等待完成授权`,queued:`已连接,等待继续`,queuedSkipped:`等待使用现有信息继续`,checkingConnection:`正在检查连接`,checkingTools:`已连接,正在验证工具`,queueHint:`目标已保存,正在等待当前执行结束。`,interruptedInputHint:`有条补充消息在重启时中断。请重新发送要求,或移除上方中断的消息后继续。`,checkFailed:`连接检查暂时失败,目标已保存`,interrupted:`恢复检查曾中断,目标已保存`,lastChecked:`最近检查`,scope:`确认后继续`,scopeHint:`这个目标已等待了一段时间。请确认仍要按下方原始要求继续;如需修改时间范围,请先在聊天中说明。未读等条件将以实际执行时为准。`,account:`选择账号`,all:`查看全部连接`,close:`关闭`,intro:`完成连接后,将自动恢复当前目标。你也可以继续发送消息。`,callbackHint:`远程 Gateway 无法接收本地回调时,粘贴浏览器地址栏中的完整回调 URL。`,callbackPlaceholder:`完整回调 URL`,callbackSubmit:`完成连接`,replace:`更换应用`,confirmReplace:`确认改用`,apps:`个应用需要连接`,preserved:`目标已保留`,retry:`重试检查`,toolsUnavailable:`应用工具暂不可用`,toolsHint:`账号已连接,当前无法使用任务所需工具。可以重试检查,无需重新授权。`},en:{waiting:`Waiting for connection`,install:`Install`,installing:`Preparing installation`,connect:`Connect`,reconnect:`Reconnect`,details:`Details`,skip:`Skip connection`,cancel:`Cancel this objective`,ready:`Connected`,check:`Check authorization`,authorizing:`Waiting for authorization`,queued:`Connected, waiting to continue`,queuedSkipped:`Waiting to continue with available information`,checkingConnection:`Checking connection`,checkingTools:`Connected, checking tools`,queueHint:`Your objective is saved. Waiting for the current execution to finish.`,interruptedInputHint:`A message was interrupted during restart. Resend the requirement or remove the interrupted message above before continuing.`,checkFailed:`Connection check failed; objective saved`,interrupted:`Recovery check interrupted; objective saved`,lastChecked:`Last checked`,scope:`Confirm and continue`,scopeHint:`This objective has been waiting for a while. Confirm the original request below, or send a message to change the time range first. Conditions such as unread status are evaluated at execution time.`,account:`Choose an account`,all:`View all connections`,close:`Close`,intro:`The current objective resumes automatically after connecting. You can keep sending messages.`,callbackHint:`If a remote Gateway cannot receive the local callback, paste the complete callback URL from the browser address bar.`,callbackPlaceholder:`Complete callback URL`,callbackSubmit:`Complete connection`,replace:`Change app`,confirmReplace:`Confirm switch to`,apps:`apps need connecting`,preserved:`Objective preserved`,retry:`Retry check`,toolsUnavailable:`App tools unavailable`,toolsHint:`The account is connected, but the tools needed for this task are unavailable. Retry the check without reconnecting.`}},fT=`rounded-lg border border-edge px-3 py-1.5 text-sm text-fg hover:bg-surface-hover disabled:opacity-50`,pT=`rounded-lg bg-accent px-3 py-1.5 text-sm text-on-accent disabled:opacity-50`;function mT({conversationId:e}){let{wait:t,busy:n,error:r,cancellationError:i,act:a,dismissError:o}=iT(e),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(),[d,f]=(0,Q.useState)(),[p,m]=(0,Q.useState)(),[h,g]=(0,Q.useState)(!1),[_,y]=(0,Q.useState)(),b=v(e=>e.language),x=dT[b];if(!t)return i?(0,Z.jsxs)(`div`,{role:`alert`,className:`mb-2 flex items-center gap-2 rounded-xl border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,children:[(0,Z.jsx)(`p`,{className:`min-w-0 flex-1`,children:i}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:fT,children:x.close})]}):(0,Z.jsx)(sT,{conversationId:e});let w=t.needs[0],j=t.needs.length===1,M=t.phase===`queued`,N=t.recoveryStage===`checking_connection`||t.recoveryStage===`checking_tools`,P=t.needs.find(e=>e.phase===`choose_account`),F=t.needs.some(e=>e.capabilityError);if(t.phase===`ready`&&!N&&!t.recoveryError)return(0,Z.jsx)(sT,{conversationId:e});let I=t.recoveryStage===`checking_connection`?x.checkingConnection:t.recoveryStage===`checking_tools`?x.checkingTools:M?t.resolution===`skipped`?x.queuedSkipped:x.queued:t.recoveryError===`check_failed`?x.checkFailed:t.recoveryError?x.interrupted:F?x.toolsUnavailable:P?x.account:j&&w.phase===`authorizing`?x.authorizing:x.waiting,L=M||N?x.details:t.recoveryError?x.retry:t.phase===`review_scope`?x.scope:j&&w.phase===`install`?h?x.installing:`${x.install} ${w.label}`:j&&w.phase===`connect`?b===`zh`?`连接 ${w.label}`:`Connect ${w.label}`:j&&w.phase===`reconnect`?x.reconnect:j&&w.phase===`authorizing`?x.check:x.details;async function R(e=w){if(e.target.type===`store-connector`){g(!0),y(void 0);try{let t=await ga(e.target.packageName,e.target.version);if(t.reviewHash!==e.target.reviewHash||t.definition.id!==e.target.connectorId||t.definition.provenance?.sha256!==e.target.sha256)throw Error(b===`zh`?`Connector 包在审查后发生了变化,请重新发起推荐。`:`The Connector package changed after review. Request a new recommendation.`);f(Dt(t.definition,{packageName:t.packageName,version:t.version,reviewHash:t.reviewHash,permissions:t.permissions})),m(e.key)}catch(e){y(e instanceof Error?e.message:String(e))}finally{g(!1)}}}function z(){M||N?c(!0):t?.recoveryError?a(`check`):t?.phase===`review_scope`?c(!0):j&&w.phase===`install`?R():j&&[`connect`,`reconnect`].includes(w.phase)?a(`connect`,w.key):j&&w.phase===`authorizing`?a(`check`):c(!0)}return(0,Z.jsxs)(`section`,{className:`mb-2 rounded-xl border border-edge bg-surface-panel px-3 py-2`,"aria-label":I,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(Je,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),(0,Z.jsxs)(`button`,{type:`button`,className:`min-w-0 flex-1 text-left text-sm text-fg`,onClick:()=>c(!0),children:[(0,Z.jsx)(`span`,{role:`status`,children:j?`${I} · ${w.label}`:`${I} · ${t.needs.length} ${x.apps}`}),(0,Z.jsx)(ae,{className:`ml-1 inline size-3`,"aria-hidden":!0})]}),(0,Z.jsxs)(`button`,{type:`button`,className:P||M||N?fT:pT,disabled:n&&!N||h,onClick:z,children:[n&&(0,Z.jsx)(Ze,{className:`mr-1 inline size-3 animate-spin`,"aria-hidden":!0}),L]}),!M&&!N&&(0,Z.jsx)(`button`,{type:`button`,className:`text-xs text-fg-muted hover:text-fg`,disabled:n,onClick:()=>void a(`skip`),children:x.skip}),(0,Z.jsx)(`button`,{type:`button`,className:`min-h-11 px-2 text-xs text-fg-muted hover:text-fg`,onClick:()=>void a(`cancel`),children:x.cancel})]}),t.queueBlocked&&(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.blockedInputId?x.interruptedInputHint:x.queueHint}),t.lastCheckedAt&&(0,Z.jsxs)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:[x.lastChecked,`: `,new Date(t.lastCheckedAt).toLocaleTimeString(b===`zh`?`zh-CN`:`en-US`)]}),P&&!M&&(0,Z.jsx)(`p`,{className:`mt-2 line-clamp-2 break-words text-sm text-fg-muted`,children:t.summary}),P&&!M&&(0,Z.jsx)(aT,{need:P,language:b,disabled:n||N,onSelect:e=>void a(`select_account`,P.key,e),onConnect:()=>void a(`connect`,P.key)},`${t.id}:${t.objectiveRevision}:${P.key}`),(r||_)&&(0,Z.jsxs)(`p`,{role:`alert`,className:`mt-2 text-xs text-fg-muted`,children:[r??_,` `,(0,Z.jsx)(`button`,{type:`button`,className:`text-accent`,onClick:()=>void a(`check`),children:x.retry})]}),(0,Z.jsx)(A,{open:s,onOpenChange:c,children:(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[2px]`}),(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(90dvh,34rem)] w-[min(94vw,34rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-edge px-5 py-4`,children:[(0,Z.jsx)(k,{className:`font-medium text-fg`,children:x.preserved}),(0,Z.jsx)(E,{"aria-label":x.close,children:(0,Z.jsx)(Xt,{className:`size-4`})})]}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto p-5`,children:[(0,Z.jsx)(T,{className:`text-sm text-fg-muted`,children:F?x.toolsHint:t.phase===`review_scope`?x.scopeHint:x.intro}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap rounded-lg border border-edge p-3 text-sm text-fg`,children:t.summary}),(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:new Date(t.objectiveUpdatedAt).toLocaleString(b===`zh`?`zh-CN`:`en-US`)}),t.timeRange&&(0,Z.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[new Date(t.timeRange.from).toLocaleString(b,{timeZone:t.timeRange.timezone}),` – `,new Date(t.timeRange.to).toLocaleString(b,{timeZone:t.timeRange.timezone}),` (`,t.timeRange.timezone,`)`]}),t.needs.map(e=>(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-edge p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[e.label,e.accountSelector?` · ${e.accountSelector}`:``]}),e.capabilityError?(0,Z.jsx)(`button`,{type:`button`,disabled:n||M,className:fT,onClick:()=>void a(`check`),children:x.retry}):e.phase===`ready`?(0,Z.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[(0,Z.jsx)(re,{className:`mr-1 inline size-3`}),x.ready]}):e.phase===`authorizing`?(0,Z.jsx)(`button`,{type:`button`,disabled:n,className:fT,onClick:()=>void a(`check`),children:x.check}):e.phase===`install`?(0,Z.jsx)(`button`,{type:`button`,disabled:n||M||h,className:pT,onClick:()=>void R(e),children:x.install}):e.phase!==`blocked`&&e.phase!==`choose_account`?(0,Z.jsx)(`button`,{type:`button`,disabled:n||M,className:pT,onClick:()=>void a(`connect`,e.key),children:e.phase===`reconnect`?x.reconnect:x.connect}):null]}),e.accountId&&(0,Z.jsx)(`p`,{className:`break-words text-xs text-fg-muted`,children:e.accounts.find(t=>t.id===e.accountId)?.label??e.accountId}),e.alternatives?.length?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(fe,{value:l?.needKey===e.key?l.candidateRef:``,options:e.alternatives.map(e=>({value:e.candidateRef,label:e.label})),placeholder:x.replace,ariaLabel:`${e.label}: ${x.replace}`,disabled:n||M,allowEmpty:!1,onChange:t=>u({needKey:e.key,candidateRef:t,label:e.alternatives.find(e=>e.candidateRef===t).label})}),l?.needKey===e.key&&(0,Z.jsxs)(`button`,{type:`button`,className:fT,disabled:n,onClick:()=>{a(`replace_source`,e.key,void 0,l.candidateRef),u(void 0)},children:[x.confirmReplace,` `,l.label]})]}):null,e.reason&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.reason}),e.phase===`authorizing`&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:x.authorizing}),(0,Z.jsx)(`button`,{type:`button`,disabled:n,className:`text-accent`,onClick:()=>void a(`connect`,e.key),children:x.reconnect})]})]},e.key)),(0,Z.jsx)(`a`,{href:`#/capabilities/connectors`,className:`text-sm text-accent`,onClick:()=>c(!1),children:x.all})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-t border-edge p-4`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`min-h-11 text-sm text-fg-muted`,onClick:()=>void a(`cancel`),children:x.cancel}),t.phase===`review_scope`?(0,Z.jsx)(`button`,{type:`button`,disabled:n||M,className:pT,onClick:()=>void a(`confirm_scope`),children:x.scope}):null]})]})]})}),d?(0,Z.jsx)(Ot,{draft:d,onChange:f,onClose:()=>{f(void 0),m(void 0)},onInstalled:async e=>{p&&await a(`install_complete`,p,void 0,void 0,e.instanceId)&&(f(void 0),m(void 0))},t:S(b).connectorsSettings}):null]})}var hT=new Set([`button`,`checkbox`,`color`,`file`,`hidden`,`image`,`radio`,`range`,`reset`,`submit`]);function gT(e){if(!(e instanceof Element))return!1;if(e.closest(`textarea, select, [role="textbox"]`)||e instanceof HTMLElement&&e.isContentEditable)return!0;let t=e.closest(`input`);return t instanceof HTMLInputElement&&!hT.has(t.type)}function _T(){return!!document.querySelector(`dialog[open], [aria-modal="true"], [role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`)}function vT(e,t){return t.disabled||t.editorHidden||e.defaultPrevented||gT(e.target)||gT(document.activeElement)?!1:!_T()}function yT(e){for(let t=e.parentElement;t;t=t.parentElement)if(/(auto|scroll)/.test(getComputedStyle(t).overflowY))return t;return null}function bT({items:e,disabled:t,onReorder:n}){let r=(0,Q.useRef)(null),i=(0,Q.useRef)(null),a=(0,Q.useRef)(0),o=(0,Q.useRef)(null),s=(0,Q.useRef)({items:e,onReorder:n});s.current={items:e,onReorder:n};let[c,l]=(0,Q.useState)(null),u=e.map(e=>`${e.id}:${e.version}:${e.status}`).join(`|`);function d(){let e=i.current;e&&(cancelAnimationFrame(e.frame),e.overlay?.remove(),e.row.hasPointerCapture?.(e.pointerId)&&e.row.releasePointerCapture(e.pointerId),e.overlay&&(a.current=Date.now()+250,document.body.style.cursor=e.cursor,document.body.style.userSelect=e.userSelect),i.current=null,o.current&&clearTimeout(o.current),o.current=null)}(0,Q.useEffect)(()=>(l(null),d),[u,t]);function f(e){let t=(e.scroller?.scrollTop??0)-e.initialScroll,n=e.y-e.offsetY+e.slots[e.from].height/2,r=e.slots.filter((r,i)=>i!==e.from&&n>r.top-t+r.height/2).length;e.to=r;let i=[...e.slots];i.splice(r,0,i.splice(e.from,1)[0]);let a={},o=0,s=e.allSlots[0].top;e.allSlots.forEach((t,n)=>{let r=t.sortable?i[o++]:t;a[r.id]=s-r.top,r.id===e.id&&(e.landingTop=s);let c=e.allSlots[n+1];s+=r.height+(c?c.top-t.top-t.height:0)}),l(t=>t?.id===e.id&&t.targetId===e.slots[r].id?t:{id:e.id,targetId:e.slots[r].id,shifts:a})}function p(e){if(i.current!==e||!e.overlay)return;let t=e.scroller;if(t){let n=t.getBoundingClientRect(),r=Math.min(32,n.height/4),i=e.y<n.top+r?-Math.min(8,(n.top+r-e.y)/4):e.y>n.bottom-r?Math.min(8,(e.y-n.bottom+r)/4):0;i&&(t.scrollTop+=i,f(e))}e.frame=requestAnimationFrame(()=>p(e))}function m(e,n){if(t||n.status!==`queued`||e.button!==0||i.current)return;let a=e.target;if(a.closest(`button, a, input`)&&!a.closest(`[data-follow-up-drag-surface]`)||e.pointerType===`touch`&&!a.closest(`[data-follow-up-drag-handle]`))return;let o=e.currentTarget,s=o.getBoundingClientRect(),c=Array.from(r.current?.querySelectorAll(`[data-follow-up-id]`)??[]).map(e=>{let t=e.getBoundingClientRect();return{id:e.dataset.followUpId,top:t.top,height:t.height,sortable:e.dataset.followUpSortable===`true`}}),l=c.filter(e=>e.sortable);if(l.length<2)return;let u=l.findIndex(e=>e.id===n.id);if(u<0)return;let d=yT(o);i.current={pointerId:e.pointerId,id:n.id,row:o,startX:e.clientX,startY:e.clientY,x:e.clientX,y:e.clientY,left:s.left,top:s.top,offsetY:e.clientY-s.top,slots:l,allSlots:c,landingTop:s.top,from:u,to:u,scroller:d,initialScroll:d?.scrollTop??0,overlay:null,frame:0,cursor:document.body.style.cursor,userSelect:document.body.style.userSelect}}function h(e){let t=i.current;if(!(!t||t.pointerId!==e.pointerId||o.current)&&(t.x=e.clientX,t.y=e.clientY,!(!t.overlay&&Math.hypot(t.x-t.startX,t.y-t.startY)<5))){if(e.preventDefault(),!t.overlay){t.row.setPointerCapture?.(t.pointerId);let e=t.row.cloneNode(!0);e.removeAttribute(`data-follow-up-id`),e.removeAttribute(`data-follow-up-sortable`),e.setAttribute(`data-follow-up-drag-overlay`,``),e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`inert`,``),e.querySelectorAll(`[id]`).forEach(e=>e.removeAttribute(`id`)),Object.assign(e.style,{position:`fixed`,left:`${t.left}px`,top:`${t.top}px`,width:`${t.row.getBoundingClientRect().width}px`,height:`${t.slots[t.from].height}px`,zIndex:`60`,pointerEvents:`none`,margin:`0`,opacity:`1`,background:`var(--color-surface-overlay)`,border:`1px solid var(--color-edge-strong)`,boxShadow:`var(--shadow-popover)`,willChange:`transform`,transition:`none`}),document.body.append(e),t.overlay=e,document.body.style.cursor=`grabbing`,document.body.style.userSelect=`none`,t.frame=requestAnimationFrame(()=>p(t))}t.overlay.style.transform=`translate3d(${t.x-t.startX}px, ${t.y-t.startY}px, 0) scale(1.015)`,f(t)}}function g(e){let t=i.current;if(!t||o.current)return;if(!t.overlay){d();return}a.current=Date.now()+250,cancelAnimationFrame(t.frame);let n=e?t.landingTop:t.top,r=(t.scroller?.scrollTop??0)-t.initialScroll,c=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches;if(t.overlay.style.transition=c?`none`:`transform 160ms ease-out, opacity 160ms ease-out`,t.overlay.style.transform=`translate3d(0, ${n-r-t.top}px, 0) scale(1)`,o.current=setTimeout(()=>{d(),l(null)},c?0:170),e&&t.to!==t.from){let e=s.current.items.findIndex(e=>e.id===t.id),n=s.current.items.findIndex(e=>e.id===t.slots[t.to].id);e>=0&&n>=0&&s.current.onReorder(e,n)}}return(0,Q.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i.current&&(e.preventDefault(),d(),l(null))},t=()=>{d(),l(null)},n=e=>h(e),r=e=>{e.pointerId===i.current?.pointerId&&g(!0)},a=e=>{e.pointerId===i.current?.pointerId&&g(!1)};return window.addEventListener(`pointermove`,n,{passive:!1}),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,a),window.addEventListener(`keydown`,e),window.addEventListener(`blur`,t),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,a),window.removeEventListener(`keydown`,e),window.removeEventListener(`blur`,t),window.removeEventListener(`resize`,t)}},[]),{listRef:r,view:c,onPointerDown:m,onClickCapture:e=>{Date.now()<a.current&&(e.preventDefault(),e.stopPropagation())}}}function xT(e){return e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;if(typeof t.id!=`string`||typeof t.clientMessageId!=`string`||typeof t.content!=`string`||typeof t.version!=`number`||t.effectiveDelivery!==`next`&&t.effectiveDelivery!==`steer`||t.status!==`queued`&&t.status!==`interrupted`)return[];let n=Array.isArray(t.contextRefs)?t.contextRefs.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return t.kind!==`note`&&t.kind!==`file`&&t.kind!==`session`&&t.kind!==`browser_tab`||typeof t.sourceId!=`string`||typeof t.version!=`string`||typeof t.title!=`string`?[]:[{...typeof t.refId==`string`?{refId:t.refId}:{},kind:t.kind,sourceId:t.sourceId,expectedVersion:t.version,title:t.title,...t.kind===`file`&&(t.fileKind===`file`||t.fileKind===`directory`)?{fileKind:t.fileKind}:{}}]}):void 0;return[{id:t.id,clientMessageId:t.clientMessageId,text:t.content,attachments:Array.isArray(t.attachments)?t.attachments:void 0,thinkingLevel:typeof t.thinking==`string`?t.thinking:void 0,contextRefs:n?.length?n:void 0,version:t.version,delivery:t.effectiveDelivery,status:t.status}]})}function ST(e){let t=xT(e.inputs);if(!e.control?.paused&&!e.activeRunId&&e.preparation?.state!==`preparation_failed`){let e=t.findIndex(e=>e.status===`queued`);e>=0&&t.splice(e,1)}return t}var CT=(0,Q.memo)(function({items:e,disabled:t,editingFollowUpId:n,onEditInComposer:r,onRemove:i,onMove:a,onReorder:o,onSteer:s,onSendSingle:c,queuePaused:l=!1,queueIdle:u=!1,steeringBusyId:d,onOpenSideChat:f}){let p=S(v(e=>e.language)),m=(0,Q.useRef)(!1),h=e.filter(e=>e.status===`queued`),g=!!(t||d),_=bT({items:e,disabled:g,onReorder:o}),y=Y(`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-lg px-2 text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg disabled:pointer-events-none disabled:opacity-35`,ca.focusRingPanel),b=`flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm text-fg outline-none focus:bg-surface-hover data-[disabled]:pointer-events-none data-[disabled]:opacity-35`;return e.length===0?null:(0,Z.jsxs)(`div`,{ref:_.listRef,className:`space-y-1 px-2 py-2`,onClickCapture:_.onClickCapture,role:`list`,"aria-label":p.chat.followUpQueueAria,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 pb-1`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:p.chat.followUpQueueHeading}),(0,Z.jsxs)(`span`,{className:`tabular-nums text-[0.65rem] text-fg-muted`,children:[e.length,`/`,10]})]}),e.map(e=>{let t=e.status===`queued`,o=t||e.status===`interrupted`,v=h.findIndex(t=>t.id===e.id),x=u&&(l||e.status===`interrupted`),S=o&&!!(e.text.trim()||e.attachments?.length||e.contextRefs?.length),C=o&&!e.attachments?.length&&!e.contextRefs?.length&&e.text.trim().length>0,w=d===e.id,T=e.status===`interrupted`?p.chat.followUpStatusInterrupted:null,E=Rn(e.text),D=new Map(e.contextRefs?.flatMap(e=>e.refId?[[e.refId,e.title]]:[])??[]),O=new Set(E?Bn(E):[]),k=e.contextRefs?.filter(e=>!e.refId||!O.has(e.refId)),A=dr(E?xn(E,e=>D.get(e)):e.text).trim();return!A&&e.attachments?.length&&(A=e.attachments[0]?.name?.trim()||p.chat.followUpQueueAttachmentOnly),A||=p.chat.followUpQueueEmptyPreview,(0,Z.jsxs)(`div`,{role:`listitem`,"data-follow-up-id":e.id,"data-follow-up-sortable":!g&&t,onPointerDown:t=>_.onPointerDown(t,e),onDragStart:e=>e.preventDefault(),style:{transform:_.view?.shifts[e.id]?`translateY(${_.view.shifts[e.id]}px)`:void 0},className:Y(`relative flex min-h-10 items-center gap-1 rounded-lg px-1.5 py-1 motion-safe:transition-transform motion-safe:duration-150`,!g&&t&&`cursor-grab`,_.view?.id===e.id&&`bg-surface-inset ring-1 ring-inset ring-edge-strong [&>*]:invisible`,n===e.id?`bg-accent-soft ring-1 ring-inset ring-accent/30`:`hover:bg-surface-hover/50`),children:[(0,Z.jsx)(`div`,{"data-follow-up-drag-handle":!0,className:Y(`flex shrink-0 touch-none cursor-grab items-center active:cursor-grabbing`,(g||!t)&&`cursor-not-allowed opacity-40`),title:p.chat.followUpQueueDrag,children:(0,Z.jsx)(Ss,{className:`size-3.5 text-fg-muted`,"aria-hidden":!0})}),(0,Z.jsx)(`button`,{type:`button`,"data-follow-up-drag-surface":!0,disabled:g||!t,title:p.chat.followUpQueueClickToEdit,"aria-label":p.chat.followUpQueueClickToEdit,className:Y(`min-h-8 min-w-0 flex-1 cursor-grab rounded-md px-1.5 text-left text-sm text-fg`,ca.focusRingPanel,`disabled:pointer-events-none disabled:opacity-50`),onClick:()=>r(e.id),children:e.attachments?.length?(0,Z.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1`,children:[(0,Z.jsx)(Ee,{className:`size-3 shrink-0 text-fg-muted`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:A})]}):(0,Z.jsx)(`span`,{className:`line-clamp-2 break-words [overflow-wrap:anywhere]`,children:A})}),k?.length?(0,Z.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5 rounded bg-accent-soft px-1.5 py-0.5 text-[0.625rem] text-accent-fg`,title:k.map(e=>e.title).join(`, `),children:[(0,Z.jsx)(Os,{className:`size-3`,"aria-hidden":!0}),k.length]}):null,T?(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-surface-panel px-1.5 py-0.5 text-[0.625rem] text-fg-muted`,children:T}):null,(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:y,disabled:g||(x?!o:!S),title:x?p.chat.sendThisMessage:p.chat.followUpQueueSteerHint,"aria-label":x?p.chat.sendThisMessage:p.chat.followUpQueueSteerNow,"aria-busy":w,onClick:()=>x?c?.(e.id):s(e.id),children:[(0,Z.jsx)(hs,{className:Y(`size-4`,w&&`motion-safe:animate-pulse`),"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`hidden text-xs sm:inline`,children:x?p.chat.sendThisMessage:p.chat.followUpQueueSteerNow})]}),(0,Z.jsx)(`button`,{type:`button`,className:Y(y,`px-1.5 hover:text-danger`),disabled:g||!o,title:p.chat.followUpQueueRemove,"aria-label":p.chat.followUpQueueRemove,onClick:()=>i(e.id),children:(0,Z.jsx)(Wt,{className:`size-4`,"aria-hidden":!0})}),(0,Z.jsxs)(go,{modal:!1,children:[(0,Z.jsx)(_o,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:Y(y,`px-1.5`),disabled:g,title:p.chat.followUpQueueMore,"aria-label":p.chat.followUpQueueMore,children:(0,Z.jsx)(Ce,{className:`size-4`,"aria-hidden":!0})})}),(0,Z.jsx)(vo,{children:(0,Z.jsxs)(bo,{side:`top`,align:`end`,sideOffset:6,onCloseAutoFocus:e=>{m.current&&e.preventDefault(),m.current=!1},className:`z-50 min-w-52 max-w-[calc(100vw-2rem)] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover`,children:[(0,Z.jsxs)(yo,{className:b,disabled:!t,onSelect:()=>{m.current=!0,r(e.id)},children:[(0,Z.jsx)(jt,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueClickToEdit]}),f?(0,Z.jsxs)(yo,{className:b,disabled:!C,onSelect:()=>f(e,A),children:[(0,Z.jsx)(Ts,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueOpenSideChat]}):null,h.length>1?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(xo,{className:`my-1 h-px bg-edge-subtle`}),(0,Z.jsxs)(yo,{className:b,disabled:!t||v===0,onSelect:()=>a(e.id,`up`),children:[(0,Z.jsx)(oe,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueMoveUp]}),(0,Z.jsxs)(yo,{className:b,disabled:!t||v>=h.length-1,onSelect:()=>a(e.id,`down`),children:[(0,Z.jsx)(ie,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueMoveDown]})]}):null]})})]})]})]},e.id)})]})});function wT({conversationId:e}){let t=_(e=>e.conversationId),n=v(e=>e.language).startsWith(`zh`),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),s=Qr(e?[`session-preparation`,t,e]:null,async()=>{let t=await jr(e);if(t&&!t.materialization)return null;let n=await y(g(`/api/sessions/${encodeURIComponent(e)}/input-state`));return n.payload.preparation?Nr.parse(n.payload.preparation):null},{refreshInterval:e=>e?.state===`preparing`?5e3:0,shouldRetryOnError:!1}),{mutate:c}=s;(0,Q.useEffect)(()=>{let t=t=>{t.detail?.conversationId===e&&c()};return window.addEventListener(`session-input-state`,t),()=>window.removeEventListener(`session-input-state`,t)},[e,c]);let l=s.data;if(!l||l.state===`ready`)return null;let u=async()=>{i(!0),o(``);try{let t=await h(g(`/api/sessions/${encodeURIComponent(e)}/preparation/retry`),{method:`POST`,body:JSON.stringify({operationId:l.operationId,expectedRevision:l.revision,idempotencyKey:`${l.operationId}:${l.revision}`})});if(!t.ok)throw Error(`HTTP ${t.status}`);await c()}catch(e){o(e instanceof Error?e.message:String(e))}finally{i(!1)}};return(0,Z.jsxs)(`div`,{className:`border-b border-edge-subtle px-3 py-2 text-sm text-fg-muted`,role:`status`,children:[(0,Z.jsx)(`span`,{children:l.state===`preparing`?n?`正在准备会话环境…`:`Preparing conversation environment…`:l.lastError??(n?`会话环境准备失败`:`Conversation environment preparation failed`)}),l.state===`preparation_failed`?(0,Z.jsx)(`button`,{type:`button`,className:`ml-2 text-accent-fg`,disabled:r,onClick:()=>void u(),children:n?`重试准备`:`Retry preparation`}):null,a?(0,Z.jsx)(`span`,{role:`alert`,className:`ml-2`,children:a}):null]})}function TT(e){let t=(0,X.c)(10),{refs:n,label:r,onRemove:i}=e;if(n.length===0)return null;let a;if(t[0]!==r||t[1]!==i||t[2]!==n){let e;t[4]!==r||t[5]!==i?(e=e=>(0,Z.jsxs)(`span`,{className:`inline-flex h-7 min-w-0 max-w-56 items-center gap-1.5 rounded-md border border-edge-subtle bg-accent-soft/50 px-2 text-xs text-fg`,children:[e.kind===`file`&&e.fileKind===`directory`?(0,Z.jsx)(je,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):e.kind===`file`||e.kind===`result`?(0,Z.jsx)(Oe,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):e.kind===`session`?(0,Z.jsx)(wt,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):e.kind===`browser_tab`?(0,Z.jsx)(M,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):(0,Z.jsx)(Os,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.title}),(0,Z.jsx)(`button`,{type:`button`,className:`-mr-1 inline-flex size-5 shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-hover hover:text-fg`,"aria-label":`${r}: ${e.title}`,onClick:()=>i(e.sourceId),children:(0,Z.jsx)(Xt,{className:`size-3`,"aria-hidden":!0})})]},e.sourceId),t[4]=r,t[5]=i,t[6]=e):e=t[6],a=n.map(e),t[0]=r,t[1]=i,t[2]=n,t[3]=a}else a=t[3];let o;return t[7]!==r||t[8]!==a?(o=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-4 pt-2`,"aria-label":r,children:a}),t[7]=r,t[8]=a,t[9]=o):o=t[9],o}var ET=`inline-flex h-8 min-w-0 shrink-0 items-center justify-center gap-1.5 rounded-full px-2.5 text-sm text-fg transition-[background-color,transform] hover:bg-surface-hover active:scale-95 disabled:pointer-events-none disabled:opacity-45 motion-reduce:transition-none motion-reduce:transform-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`;function DT(e){let t=(0,X.c)(96),{conversationId:n,project:r,workspacePath:i,canChangeWorkspace:a,disabled:o,environmentPicker:s,onProjectChange:c,onWorkspaceChange:l}=e,u=v(jT),d;t[0]===u?d=t[1]:(d=S(u),t[0]=u,t[1]=d);let f=d,p=f.chat.composerContext,m=_(AT),h=_(kT),[g,y]=(0,Q.useState)(``),[b]=Za(g,200),x;t[2]!==h||t[3]!==b||t[4]!==m?(x=[`composer-projects`,h,m,b],t[2]=h,t[3]=b,t[4]=m,t[5]=x):x=t[5];let C;t[6]===b?C=t[7]:(C=()=>mn({status:`active`,search:b,sortBy:`updatedAt`,sortOrder:`desc`,limit:50}),t[6]=b,t[7]=C);let w;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(w={keepPreviousData:!1,shouldRetryOnError:!1},t[8]=w):w=t[8];let T=Qr(x,C,w),E=Df(n,!1),D=E.error?void 0:E.data?.environment,O;t[9]!==D?.rootPath||t[10]!==i?(O=i?.trim()||D?.rootPath||``,t[9]=D?.rootPath,t[10]=i,t[11]=O):O=t[11];let k=O,[A,j]=(0,Q.useState)(null),M;t[12]!==E||t[13]!==l?(M=async e=>{j(null);try{await l(e),await E.mutate()}catch(e){let t=e;j(t instanceof Error?t.message:String(t))}},t[12]=E,t[13]=l,t[14]=M):M=t[14];let N;t[15]!==k||t[16]!==M?(N={initialPath:k,onPicked:M},t[15]=k,t[16]=M,t[17]=N):N=t[17];let P=Ua(N),F=a?`${p.chooseFolder}${k?`: ${k}`:``}`:r?p.projectFolder:p.lockedFolder,I;t[18]===D?I=t[19]:(I=D?.branch||(D?.detached?D.headSha?.slice(0,8):void 0),t[18]=D,t[19]=I);let L=I,R=p.label,z=r&&`bg-surface-hover`,B;t[20]===z?B=t[21]:(B=Y(`flex min-w-0 max-w-full items-center rounded-full`,z),t[20]=z,t[21]=B);let ee;t[22]!==o||t[23]!==f.chat.scopeRemoveProject||t[24]!==c||t[25]!==r?(ee=r?(0,Z.jsx)(`button`,{type:`button`,disabled:o,title:f.chat.scopeRemoveProject,"aria-label":f.chat.scopeRemoveProject,className:Y(ET,`size-7 shrink-0 px-0 ml-0.5 text-fg-muted`),onClick:()=>c(null),children:(0,Z.jsx)(Xt,{className:`size-3.5`,"aria-hidden":!0})}):null,t[22]=o,t[23]=f.chat.scopeRemoveProject,t[24]=c,t[25]=r,t[26]=ee):ee=t[26];let V=r?.id??``,H=r?.name,U;t[27]!==T.data?.items||t[28]!==T.error?(U=T.error?[]:T.data?.items??[],t[27]=T.data?.items,t[28]=T.error,t[29]=U):U=t[29];let W;t[30]===U?W=t[31]:(W=U.map(OT),t[30]=U,t[31]=W);let te=p.chooseProject,ne=p.changeProject,re=p.changeProject,ie=p.noProject,ae=p.searchProjects,oe=T.isLoading,se=T.error?p.projectsFailed:T.data?.items.length===0?p.noProjects:void 0,le=r&&`pl-1`,ue;t[32]===le?ue=t[33]:(ue=Y(ET,`h-8 w-auto max-w-44 gap-1 border-0 bg-transparent pr-2.5 text-sm [&>svg]:hidden [&>span]:text-fg`,le),t[32]=le,t[33]=ue);let de;t[34]!==c||t[35]!==r?.id?(de=e=>{e!==(r?.id??``)&&c(e||null)},t[34]=c,t[35]=r?.id,t[36]=de):de=t[36];let G;t[37]!==p.changeProject||t[38]!==p.chooseProject||t[39]!==p.noProject||t[40]!==p.searchProjects||t[41]!==o||t[42]!==T.isLoading||t[43]!==g||t[44]!==V||t[45]!==H||t[46]!==W||t[47]!==se||t[48]!==ue||t[49]!==de?(G=(0,Z.jsx)(fe,{value:V,selectedLabel:H,options:W,placeholder:te,ariaLabel:ne,title:re,emptyLabel:ie,disabled:o,side:`top`,align:`start`,searchPlaceholder:ae,searchValue:g,onSearchChange:y,loading:oe,statusMessage:se,triggerClassName:ue,contentClassName:`xopc-composer-config-popover w-max min-w-[min(12rem,calc(100vw-1.5rem))] max-w-[min(20rem,calc(100vw-1.5rem))] [&>input]:w-0 [&>input]:min-w-full`,onChange:de}),t[37]=p.changeProject,t[38]=p.chooseProject,t[39]=p.noProject,t[40]=p.searchProjects,t[41]=o,t[42]=T.isLoading,t[43]=g,t[44]=V,t[45]=H,t[46]=W,t[47]=se,t[48]=ue,t[49]=de,t[50]=G):G=t[50];let K;t[51]!==B||t[52]!==ee||t[53]!==G?(K=(0,Z.jsxs)(`div`,{className:B,children:[ee,G]}),t[51]=B,t[52]=ee,t[53]=G,t[54]=K):K=t[54];let q=r?s:null,pe;t[55]!==D||t[56]!==s||t[57]!==r?(pe=!s&&r&&D&&(D.headSha||D.branch)?(0,Z.jsxs)(`span`,{className:`inline-flex h-8 min-w-0 items-center gap-1.5 rounded-full bg-surface-hover px-2.5 text-sm text-fg`,title:D.rootPath,children:[D.kind===`managed_worktree`?(0,Z.jsx)(ks,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(qe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),D.kind===`managed_worktree`?`Worktree`:`Local`]}):null,t[55]=D,t[56]=s,t[57]=r,t[58]=pe):pe=t[58];let me;t[59]!==p.retryProjects||t[60]!==T?(me=T.error?(0,Z.jsx)(`button`,{type:`button`,className:Y(ET,`size-7 px-0`),"aria-label":p.retryProjects,onClick:()=>void T.mutate(),children:(0,Z.jsx)(Pt,{className:`size-3.5`,"aria-hidden":!0})}):null,t[59]=p.retryProjects,t[60]=T,t[61]=me):me=t[61];let J;t[62]!==a||t[63]!==E.isLoading||t[64]!==p.chooseFolder||t[65]!==o||t[66]!==P.pick||t[67]!==P.picking||t[68]!==r||t[69]!==k||t[70]!==F?(J=r?null:(0,Z.jsxs)(`button`,{type:`button`,className:Y(ET,`max-w-52`),disabled:o||!a||P.picking,title:F,"aria-label":p.chooseFolder,onClick:P.pick,children:[(0,Z.jsx)(Ae,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),k?(0,Z.jsx)(`span`,{className:`truncate`,children:Ha(k)}):E.isLoading?(0,Z.jsx)(Qt,{className:`h-4 w-16`}):(0,Z.jsx)(`span`,{children:p.chooseFolder})]}),t[62]=a,t[63]=E.isLoading,t[64]=p.chooseFolder,t[65]=o,t[66]=P.pick,t[67]=P.picking,t[68]=r,t[69]=k,t[70]=F,t[71]=J):J=t[71];let he;t[72]!==L||t[73]!==D?(he=L?(0,Z.jsxs)(`span`,{className:`inline-flex h-8 min-w-0 max-w-44 items-center gap-1.5 px-2 text-sm text-fg`,title:`${L}${D?.headSha?` · ${D.headSha.slice(0,8)}`:``}`,children:[(0,Z.jsx)(Fe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:L})]}):null,t[72]=L,t[73]=D,t[74]=he):he=t[74];let ge;t[75]===A?ge=t[76]:(ge=A?(0,Z.jsx)(`p`,{role:`alert`,className:`w-full px-2 py-1 text-xs text-danger`,children:A}):null,t[75]=A,t[76]=ge);let _e;t[77]!==p.label||t[78]!==K||t[79]!==q||t[80]!==pe||t[81]!==me||t[82]!==J||t[83]!==he||t[84]!==ge?(_e=(0,Z.jsxs)(`div`,{className:`mx-3 -mb-3 flex min-w-0 shrink-0 flex-wrap items-center gap-x-1 gap-y-1 rounded-t-2xl bg-surface-base px-2 pb-4 pt-1.5 sm:mx-4`,"aria-label":R,children:[K,q,pe,me,J,he,ge]}),t[77]=p.label,t[78]=K,t[79]=q,t[80]=pe,t[81]=me,t[82]=J,t[83]=he,t[84]=ge,t[85]=_e):_e=t[85];let ve;t[86]!==f.chat.workingDirectory||t[87]!==P.confirmPick||t[88]!==P.hasNativePicker||t[89]!==P.modalOpen||t[90]!==P.setModalOpen||t[91]!==k?(ve=P.hasNativePicker?null:(0,Z.jsx)(ce,{open:P.modalOpen,onOpenChange:P.setModalOpen,initialAbsolutePath:k||void 0,onConfirm:P.confirmPick,wd:f.chat.workingDirectory}),t[86]=f.chat.workingDirectory,t[87]=P.confirmPick,t[88]=P.hasNativePicker,t[89]=P.modalOpen,t[90]=P.setModalOpen,t[91]=k,t[92]=ve):ve=t[92];let ye;return t[93]!==_e||t[94]!==ve?(ye=(0,Z.jsxs)(Z.Fragment,{children:[_e,ve]}),t[93]=_e,t[94]=ve,t[95]=ye):ye=t[95],ye}function OT(e){return{value:e.id,label:e.name}}function kT(e){return e.baseUrl}function AT(e){return e.conversationId}function jT(e){return e.language}var MT=`flex size-11 shrink-0 items-center justify-center rounded-full text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent sm:size-10`;function NT(e){let t=(0,X.c)(10),{disabled:n,attachmentCount:r,maxAttachments:i,chat:a,onPickFiles:o}=e,s=r>=i,c;t[0]!==a.attachFile||t[1]!==a.maxAttachmentsReached||t[2]!==s||t[3]!==i?(c=s?mm(a.maxAttachmentsReached,{max:i}):a.attachFile,t[0]=a.attachFile,t[1]=a.maxAttachmentsReached,t[2]=s,t[3]=i,t[4]=c):c=t[4];let l=c,u=n||s,d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(Nt,{className:`size-5`,"aria-hidden":!0}),t[5]=d):d=t[5];let f;return t[6]!==l||t[7]!==o||t[8]!==u?(f=(0,Z.jsx)(`button`,{type:`button`,className:MT,disabled:u,"aria-label":l,title:l,onClick:o,children:d}),t[6]=l,t[7]=o,t[8]=u,t[9]=f):f=t[9],f}function PT(e){let t=(0,X.c)(16),{disabled:n,voiceActive:r,runBusy:i,hasDraft:a,chat:o,onStartVoiceInput:s,onSend:c,onAbort:l}=e;if(r)return null;let u=i&&!a,d=u?o.abort:o.sendMessage,f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(Tt,{className:`size-[1.125rem]`,"aria-hidden":!0}),t[0]=f):f=t[0];let p;t[1]!==o.voiceInput||t[2]!==n||t[3]!==s?(p=(0,Z.jsx)(`button`,{type:`button`,className:MT,disabled:n,title:o.voiceInput,"aria-label":o.voiceInput,onClick:s,children:f}),t[1]=o.voiceInput,t[2]=n,t[3]=s,t[4]=p):p=t[4];let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=Y(MT,`bg-accent text-on-accent hover:bg-accent-hover hover:text-on-accent disabled:bg-surface-hover disabled:text-fg-disabled`),t[5]=m):m=t[5];let h=!u&&(n||!a),g=u?l:c,_;t[6]===u?_=t[7]:(_=u?(0,Z.jsx)(Ut,{className:`size-4 fill-current`,"aria-hidden":!0}):(0,Z.jsx)(I,{className:`size-5`,"aria-hidden":!0}),t[6]=u,t[7]=_);let v;t[8]!==d||t[9]!==h||t[10]!==g||t[11]!==_?(v=(0,Z.jsx)(`button`,{type:`button`,className:m,disabled:h,"aria-label":d,title:d,onClick:g,children:_}),t[8]=d,t[9]=h,t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;return t[13]!==p||t[14]!==v?(y=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[p,v]}),t[13]=p,t[14]=v,t[15]=y):y=t[15],y}function FT(e){return e.map(e=>({type:e.type===`voice`?`voice`:(e.mimeType??``).startsWith(`image/`)?`image`:`document`,mimeType:e.mimeType??`application/octet-stream`,content:e.data??``,name:e.name??`file`,size:e.size??0,uri:e.uri,...typeof e.durationSeconds==`number`&&Number.isFinite(e.durationSeconds)&&e.durationSeconds>0?{durationSeconds:e.durationSeconds}:{}}))}var IT=100,LT=400,RT=900;function zT(e,t){switch(t.type){case`reset`:return{box:null,hoverPreview:null};case`set-box`:return{...e,box:t.box};case`set-hover`:return{...e,hoverPreview:t.hoverPreview}}}function BT(e,t){let n=t.trim().toLowerCase();if(!n)return[];let r=e.toLowerCase(),i=[],a=0;for(let e=0;e<r.length&&a<n.length;e++)r[e]===n[a]&&(i.push([e,e+1]),a++);return i}function VT(e){let t=(0,X.c)(8),{name:n,query:r}=e,i;t[0]!==n||t[1]!==r?(i=BT(n,r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i;if(a.length===0){let e;return t[3]===n?e=t[4]:(e=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:n}),t[3]=n,t[4]=e),e}let o;if(t[5]!==n||t[6]!==a){let e=[],r=0;a.forEach(t=>{let[i,a]=t;i>r&&e.push((0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:n.slice(r,i)},`pre-${i}`)),e.push((0,Z.jsx)(`span`,{className:`font-semibold text-accent-fg`,children:n.slice(i,a)},`hl-${i}-${a}`)),r=a}),r<n.length&&e.push((0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:n.slice(r)},`tail`)),o=(0,Z.jsx)(Z.Fragment,{children:e}),t[5]=n,t[6]=a,t[7]=o}else o=t[7];return o}var HT=(0,Q.memo)(function(e){let t=(0,X.c)(42),{open:n,anchorRef:r,items:i,selectedIndex:a,loading:o,query:s,noResults:c,conversationId:l,recentLabel:u,sectionLabels:d,ariaLabel:f,onSelectItem:p}=e,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m={box:null,hoverPreview:null},t[0]=m):m=t[0];let[h,g]=(0,Q.useReducer)(zT,m),_=h.box,v=h.hoverPreview,y=(0,Q.useRef)(null),b=(0,Q.useRef)(0),x=(0,Q.useRef)(null),S;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>{y.current&&=(clearTimeout(y.current),null)},t[1]=S):S=t[1];let C=S,w;t[2]===l?w=t[3]:(w=(e,t,n)=>{C(),b.current+=1;let r=b.current;if(e.kind!==`file`){g({type:`set-hover`,hoverPreview:null});return}let i=e.relativePath;if(!l?.trim()||e.isDirectory||e.isBrowseUp||!i){g({type:`set-hover`,hoverPreview:null});return}y.current=setTimeout(()=>{y.current=null,r===b.current&&Ka(i,{conversationId:l}).then(e=>{let{content:i}=e,a=i.length>RT?`${i.slice(0,RT)}…`:i;r===b.current&&g({type:`set-hover`,hoverPreview:{text:a,x:t,y:n}})}).catch(()=>{r===b.current&&g({type:`set-hover`,hoverPreview:null})})},420)},t[2]=l,t[3]=w);let T=w,E,D;t[4]!==r||t[5]!==n?(E=()=>{if(!n){g({type:`reset`}),C(),b.current+=1;return}let e=()=>{let e=r.current;if(!e)return;let t=e.getBoundingClientRect();g({type:`set-box`,box:{left:t.left,top:t.top,width:t.width}})};e();let t=r.current,i=t&&typeof ResizeObserver<`u`?new ResizeObserver(()=>{e()}):null;return t&&i&&i.observe(t),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{t&&i&&i.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},D=[n,r],t[4]=r,t[5]=n,t[6]=E,t[7]=D):(E=t[6],D=t[7]),(0,Q.useLayoutEffect)(E,D);let O,k;if(t[8]!==i.length||t[9]!==n||t[10]!==a?(O=()=>{!n||a<0||a>=i.length||(x.current?.querySelector(`#at-mention-${a}`))?.scrollIntoView({block:`nearest`})},k=[n,a,i.length],t[8]=i.length,t[9]=n,t[10]=a,t[11]=O,t[12]=k):(O=t[11],k=t[12]),(0,Q.useLayoutEffect)(O,k),!n||typeof document>`u`||_===null)return null;let A=i.length,j=Math.min(_.width,LT),N;t[13]!==_.left||t[14]!==_.top||t[15]!==j?(N={position:`fixed`,left:_.left,top:_.top,width:j,transform:`translateY(calc(-100% - 8px))`,zIndex:IT},t[13]=_.left,t[14]=_.top,t[15]=j,t[16]=N):N=t[16];let P=a>=0&&a<A?`at-mention-${a}`:void 0,F;t[17]!==o||t[18]!==A?(F=o&&A===0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5 text-sm text-fg-muted`,children:[(0,Z.jsx)(Ze,{className:`size-4 shrink-0 animate-spin`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:`…`})]}):null,t[17]=o,t[18]=A,t[19]=F):F=t[19];let I;t[20]!==i||t[21]!==o||t[22]!==c||t[23]!==p||t[24]!==s||t[25]!==u||t[26]!==T||t[27]!==d||t[28]!==a||t[29]!==A?(I=!o&&A===0?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-sm text-fg-muted`,children:c}):(0,Z.jsxs)(Z.Fragment,{children:[i.map((e,t)=>{let n=i[t-1]?.kind,r=d[e.kind],o=e.kind===`file`&&e.isRecent;return(0,Z.jsxs)(Q.Fragment,{children:[n===e.kind?null:(0,Z.jsx)(`div`,{className:`border-t border-edge-subtle px-3 pb-1 pt-2 text-[0.65rem] font-medium uppercase tracking-wide text-fg-muted first:border-t-0`,children:r}),(0,Z.jsxs)(`div`,{id:`at-mention-${t}`,role:`option`,"aria-selected":a===t,tabIndex:-1,className:Y(`flex cursor-pointer items-start gap-2 px-3 py-2 text-left text-sm`,a===t?`bg-surface-hover text-fg`:`text-fg-subtle hover:bg-surface-hover/80`,o&&`border-l-2 border-l-accent/60`),onPointerDown:t=>{t.pointerType===`mouse`&&t.button!==0||(t.preventDefault(),p(e))},onPointerEnter:t=>T(e,t.clientX,t.clientY),onPointerLeave:()=>{C(),b.current+=1,g({type:`set-hover`,hoverPreview:null})},children:[(0,Z.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:e.kind===`note`?(0,Z.jsx)(Os,{className:`size-3.5 text-accent-fg`,"aria-hidden":!0}):e.kind===`session`?(0,Z.jsx)(wt,{className:`size-3.5 text-violet-600 dark:text-violet-400`,"aria-hidden":!0}):e.kind===`skill`?(0,Z.jsx)(Ht,{className:`size-3.5 text-cyan-600 dark:text-cyan-400`,"aria-hidden":!0}):e.kind===`agent`?(0,Z.jsx)(ne,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):e.kind===`browser_tab`?(0,Z.jsx)(M,{className:`size-3.5 text-blue-600 dark:text-blue-400`,"aria-hidden":!0}):e.isBrowseUp?(0,Z.jsx)(je,{className:`size-3.5 text-fg-muted`,"aria-hidden":!0}):e.isDirectory?(0,Z.jsx)(je,{className:`size-3.5 text-amber-600 dark:text-amber-400`,"aria-hidden":!0}):(0,Z.jsx)(Oe,{className:Y(`size-3.5`,be(e.name)),"aria-hidden":!0})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:(0,Z.jsx)(VT,{name:e.name,query:s})}),o?(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-accent-soft px-1 py-0 text-[0.65rem] text-accent-fg`,children:u}):null]}),(0,Z.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:e.description||r})]})]})]},e.id)}),o&&A>0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-edge-subtle px-3 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(Ze,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:`…`})]}):null]}),t[20]=i,t[21]=o,t[22]=c,t[23]=p,t[24]=s,t[25]=u,t[26]=T,t[27]=d,t[28]=a,t[29]=A,t[30]=I):I=t[30];let L;t[31]!==f||t[32]!==F||t[33]!==I||t[34]!==P?(L=(0,Z.jsxs)(`div`,{ref:x,className:`max-h-[min(26rem,54vh)] overflow-y-auto`,role:`listbox`,"aria-label":f,"aria-activedescendant":P,children:[F,I]}),t[31]=f,t[32]=F,t[33]=I,t[34]=P,t[35]=L):L=t[35];let R;t[36]===v?R=t[37]:(R=v?(0,Z.jsx)(`div`,{className:`pointer-events-none fixed z-[200] max-h-48 max-w-sm overflow-auto rounded-md border border-edge bg-surface-overlay p-2 font-mono text-[0.7rem] text-fg shadow-lg`,style:{left:Math.min(v.x+12,window.innerWidth-320),top:Math.min(v.y+12,window.innerHeight-200)},children:v.text}):null,t[36]=v,t[37]=R);let z;return t[38]!==L||t[39]!==R||t[40]!==N?(z=(0,Us.createPortal)((0,Z.jsxs)(`div`,{"data-composer-picker-panel":!0,className:`pointer-events-auto max-h-[min(28rem,60vh)] min-h-[2.5rem] overflow-hidden rounded-lg border border-edge bg-surface-overlay shadow-lg`,style:N,role:`presentation`,children:[L,R]}),document.body),t[38]=L,t[39]=R,t[40]=N,t[41]=z):z=t[41],z});function UT(e,t){let n=e=>{e!==!1&&(e&&typeof e==`object`?t(e.conversationId):t())};e instanceof Promise?e.then(n).catch(e=>{ya(`error`,e instanceof Error?e.message:String(e))}):n(e)}var WT=new Set([`abort`,`stop`,`cancel`]);function GT(e){if(e.kind!==`command`)return!1;if(WT.has(e.name.toLowerCase()))return!0;for(let t of e.aliases??[])if(WT.has(t.toLowerCase()))return!0;return!1}function KT(e,t,n,r){return e.slice(0,t)+r+e.slice(n)}var qT=(e,t)=>{let n=t.slashRange;if(!n)return;if(e.availability.status!==`available`){t.callbacks.onUnavailableSkill?.(e);return}let r=`/skill:${e.canonicalName} `,i=KT(t.editor.valueRef.current,n.start,n.end,r),a=n.start+r.length;t.editor.resetEditor({nextText:i,caretOffset:a,focus:!0})},JT=(e,t)=>{let n=t.slashRange;if(!n||n.start!==0)return;if(e.name.toLowerCase()===`review`&&t.callbacks.onReviewLauncher&&!t.runBusy&&t.pendingFollowUpsCount===0){let e=t.editor.valueRef.current,r=e.slice(0,n.start)+e.slice(n.end);t.editor.resetEditor({nextText:r,caretOffset:n.start,focus:!0}),t.callbacks.onReviewLauncher();return}if(e.acceptsArgs===!0){let r=`/${e.name} `,i=KT(t.editor.valueRef.current,n.start,n.end,r),a=n.start+r.length;t.editor.resetEditor({nextText:i,caretOffset:a,focus:!0});return}let r=`/${e.name}`;if(t.runBusy||t.pendingFollowUpsCount>0){if(GT(e)){if(!t.callbacks.onAbort)return;t.callbacks.onAbort();let e=t.editor.valueRef.current,r=e.slice(0,n.start)+e.slice(n.end);t.editor.resetEditor({nextText:r,caretOffset:n.start});return}if(!t.callbacks.onAddPendingFollowUp||t.pendingFollowUpsCount>=t.maxPendingFollowUps)return;t.contextRefs.current.length?t.callbacks.onAddPendingFollowUp(r,void 0,t.contextRefs.current):t.callbacks.onAddPendingFollowUp(r,void 0),t.callbacks.onUserTextCommitted?.(r),t.attachments.clearAttachments(),t.contextRefs.clear(),t.editor.resetEditor();return}UT(t.contextRefs.current.length?t.callbacks.onSend(r,void 0,t.thinkingLevel,t.contextRefs.current):t.callbacks.onSend(r,void 0,t.thinkingLevel),e=>{e===void 0?t.callbacks.onUserTextCommitted?.(r):t.callbacks.onUserTextCommitted?.(r,e),t.attachments.clearAttachments(),t.contextRefs.clear(),t.editor.resetEditor()})},YT=(e,t)=>{let n=t.slashRange;if(!n||n.start!==0||!t.callbacks.onChatAgentChange)return;let r=t.editor.valueRef.current,i=r.slice(n.end),a=r.slice(0,n.start)+(i.startsWith(` `)?i.slice(1):i);t.editor.resetEditor({nextText:a,caretOffset:n.start}),t.callbacks.onChatAgentChange(e.agentId)};function XT(e,t){switch(e.kind){case`skill`:qT(e,t);return;case`command`:JT(e,t);return;case`agent`:YT(e,t)}}var ZT={new:10,help:11,list:12,clear:13,switch:14,models:15,usage:16,skills:17,settings:18,start:19,think:20,reasoning:21,verbose:22,status:23,tts:24},QT=new Set([`abort`,`archive`]);function $T(e){if(e.kind===`command`){let t=e.name.toLowerCase();if(ZT[t]!==void 0)return 0;if(QT.has(t))return 2}return 1}function eE(e,t){let n=$T(e),r=$T(t);if(n!==r)return n-r;if(n===0){let n=ZT[e.name.toLowerCase()]??999,r=ZT[t.name.toLowerCase()]??999;if(n!==r)return n-r}let i=e.name.localeCompare(t.name);return i===0?e.id.localeCompare(t.id):i}function tE(e){if(e.kind!==`command`)return!1;if(WT.has(e.name.toLowerCase()))return!0;for(let t of e.aliases??[])if(WT.has(t.toLowerCase()))return!0;return!1}function nE(e,t){return e.kind!==`command`||e.acceptsArgs===!0||tE(e)||!(t.runBusy||t.pendingFollowUpsCount>0)?!1:t.pendingFollowUpsCount>=t.maxPendingFollowUps}function rE(e,t){return e.kind!==`command`||e.acceptsArgs===!0||tE(e)||!(t.runBusy||t.pendingFollowUpsCount>0)?!1:t.pendingFollowUpsCount<t.maxPendingFollowUps}function iE(e){return e.includes(`/`)||/^[A-Za-z]:/u.test(e)?!0:/^(Users|home|var|tmp|etc|opt|private|Volumes|System|Applications|Library|usr|dev|bin|sbin|proc|sys)(\/|$)/iu.test(e)}function aE(e,t){if(t===0)return!1;let n=e[t-1];if(n===void 0||n===`.`||n===`:`||n===`/`)return!0;let r=e.slice(0,t);return/[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+$/u.test(r)}function oE(e,t){let n=e.length,r=Math.min(Math.max(t,0),n);if(r<1&&e===`/`&&(r=1),r<1)return null;let i=e.slice(0,r).match(/\/[^\s]*$/);if(!i||i.index===void 0)return null;let a=i.index;if(aE(e,a))return null;let o=i[0],s=o.slice(1);return iE(s)||o.startsWith(`/skill:`)?null:{start:i.index,end:r,query:s}}function sE(e,t){let n=t.trim().toLowerCase();if(!n)return 0;let r=e.name.toLowerCase();if(r===n)return 0;for(let t of e.aliases??[])if(t.toLowerCase()===n)return 1;if(r.startsWith(n))return 2;for(let t of e.aliases??[])if(t.toLowerCase().startsWith(n))return 3;if(r.includes(n))return 4;for(let t of e.aliases??[])if(t.toLowerCase().includes(n))return 5;if(e.description.toLowerCase().includes(n))return 100;if(e.category.toLowerCase().includes(n))return 101;if(e.kind===`skill`&&(e.source??``).toLowerCase().includes(n))return 102;if(e.kind===`skill`){for(let t of e.searchTerms??[])if(t.toLowerCase().includes(n))return 103}return null}function cE(e,t){return t===0?0:Math.min(e,t-1)}function lE(e,t){let{query:n,value:r,commandsAllowed:i,agentsAllowed:a}=t,o=n.trim()===``,s=Mp(r),c=[];for(let r of e){if(r.kind===`command`&&!i||r.kind===`agent`&&!a||r.kind===`skill`&&t.skillsAllowed===!1||r.kind===`skill`&&s.has(r.canonicalName)||r.kind===`skill`&&o&&r.availability.status!==`available`)continue;let e=sE(r,n);e!==null&&c.push({item:r,rank:e})}c.sort((e,t)=>{let n=e.item.kind===`skill`&&e.item.availability.status!==`available`;return n===(t.item.kind===`skill`&&t.item.availability.status!==`available`)?e.rank===t.rank?eE(e.item,t.item):e.rank-t.rank:n?1:-1});let l=c.map(e=>e.item),u=[],d=l.filter(e=>e.kind===`skill`),f=l.filter(e=>e.kind===`command`),p=l.filter(e=>e.kind===`agent`);d.length>0&&u.push({kind:`skill`,items:d}),f.length>0&&u.push({kind:`command`,items:f}),p.length>0&&u.push({kind:`agent`,items:p});let m=[];for(let e of u)m.push(...e.items);return{sections:u,flatItems:m}}function uE(e,t,n){let r=(0,X.c)(49),[i,a]=(0,Q.useState)(0),[o,s]=(0,Q.useState)(0),c=v(pE),l=n?.capabilities??pp,u=l.commands||l.skills||l.agentSwitch;n?.isComposing;let d;r[0]!==t||r[1]!==u||r[2]!==n?.isComposing||r[3]!==e?(d=!u||n?.isComposing?null:oE(e,t),r[0]=t,r[1]=u,r[2]=n?.isComposing,r[3]=e,r[4]=d):d=r[4];let f=d,p=!!(f&&!n?.suppress),m,h;r[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=e=>{let t=e.detail;t&&typeof t==`object`&&`section`in t&&(t.section===`skills`||t.section===`agents`)&&s(fE)};return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},h=[],r[5]=m,r[6]=h):(m=r[5],h=r[6]),(0,Q.useEffect)(m,h);let g;r[7]!==c||r[8]!==n?.conversationId||r[9]!==n?.currentAgentId?(g=async()=>{let[e,t,r]=await Promise.allSettled([Do(),So(n?.currentAgentId,n?.conversationId),si()]),i=[];t.status===`rejected`&&i.push(`skill`),e.status===`rejected`&&i.push(`command`),r.status===`rejected`&&i.push(`agent`);let a=(e.status===`fulfilled`?e.value:[]).map(dE),o=(t.status===`fulfilled`?t.value.skills:[]).map(e=>{let t=Oo(e,c);return{kind:`skill`,id:`skill:${e.name}`,name:t.displayName,canonicalName:e.name,description:t.description,aliases:t.aliases,searchTerms:t.searchTerms,category:`skill`,source:e.source,availability:{status:e.availableForCurrentAgent?`available`:e.unavailableReason??`agent-denied`,reason:e.unavailableReason??void 0}}}),s=S(c).agentsSettings,l=r.status===`fulfilled`?r.value:null,u=l&&l.items.length>1?l.items.map(e=>({kind:`agent`,id:`agent:${e.id}`,agentId:e.id,name:es(e,s),description:ts(e,s),category:`agent`,...e.avatar?{avatar:e.avatar}:{},aliases:[e.id,...e.name?[e.name]:[]]})):[];return{items:[...o,...a,...u],failedKinds:i}},r[7]=c,r[8]=n?.conversationId,r[9]=n?.currentAgentId,r[10]=g):g=r[10];let _=n?.currentAgentId,y=n?.conversationId,b;r[11]!==c||r[12]!==o||r[13]!==_||r[14]!==y?(b=[c,_,y,o],r[11]=c,r[12]=o,r[13]=_,r[14]=y,r[15]=b):b=r[15];let x;r[16]===Symbol.for(`react.memo_cache_sentinel`)?(x=[],r[16]=x):x=r[16];let C;r[17]===Symbol.for(`react.memo_cache_sentinel`)?(C=[],r[17]=C):C=r[17];let w,T;r[18]===Symbol.for(`react.memo_cache_sentinel`)?(T={items:x,failedKinds:C},w=[],r[18]=w,r[19]=T):(w=r[18],T=r[19]);let E;r[20]===Symbol.for(`react.memo_cache_sentinel`)?(E=[],r[20]=E):E=r[20];let D;r[21]===Symbol.for(`react.memo_cache_sentinel`)?(D={items:w,failedKinds:E},r[21]=D):D=r[21];let O;r[22]===p?O=r[23]:(O={enabled:p,initial:T,errorData:D},r[22]=p,r[23]=O);let k=Da(g,b,O),A=k.data.items,j=k.error==null?null:k.error instanceof Error?k.error.message:String(k.error),M=f?.query??``,N=l.commands&&f!==null&&f.start===0,P=l.agentSwitch&&f!==null&&f.start===0,F;r[24]!==P||r[25]!==A||r[26]!==l.skills||r[27]!==N||r[28]!==M||r[29]!==e?(F=lE(A,{query:M,value:e,commandsAllowed:N,agentsAllowed:P,skillsAllowed:l.skills}),r[24]=P,r[25]=A,r[26]=l.skills,r[27]=N,r[28]=M,r[29]=e,r[30]=F):F=r[30];let{sections:I,flatItems:L}=F,R=f?M:``,z=(0,Q.useRef)(R);z.current!==R&&(z.current=R,i!==0&&a(0));let B;r[31]!==L.length||r[32]!==i?(B=cE(i,L.length),r[31]=L.length,r[32]=i,r[33]=B):B=r[33];let ee=B,V;r[34]===L.length?V=r[35]:(V=e=>{L.length!==0&&a(t=>e===`down`?(t+1)%L.length:(t-1+L.length)%L.length)},r[34]=L.length,r[35]=V);let H=V,U;return r[36]!==P||r[37]!==N||r[38]!==L||r[39]!==k.data.failedKinds||r[40]!==k.loading||r[41]!==j||r[42]!==H||r[43]!==p||r[44]!==M||r[45]!==ee||r[46]!==I||r[47]!==f?(U={open:p,slashRange:f,commandsAllowed:N,agentsAllowed:P,sections:I,flatItems:L,selectedIndex:ee,query:M,loading:k.loading,failedKinds:k.data.failedKinds,loadError:j,onNavigate:H,setSelectedIndex:a},r[36]=P,r[37]=N,r[38]=L,r[39]=k.data.failedKinds,r[40]=k.loading,r[41]=j,r[42]=H,r[43]=p,r[44]=M,r[45]=ee,r[46]=I,r[47]=f,r[48]=U):U=r[48],U}function dE(e){return{kind:`command`,id:`cmd:${e.id}`,name:e.name,description:e.description,category:e.category,aliases:e.aliases,acceptsArgs:e.acceptsArgs,acceptsContext:e.acceptsContext,examples:e.examples}}function fE(e){return e+1}function pE(e){return e.language}var mE=100,hE=560;function gE(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase().indexOf(n);if(r>=0)return(0,Z.jsxs)(Z.Fragment,{children:[e.slice(0,r),(0,Z.jsx)(`span`,{className:`text-accent-fg`,children:e.slice(r,r+n.length)}),e.slice(r+n.length)]});let i=[],a=0,o=0;for(let t of e){let e=n[a],r=`${String(o)}-${t}`;e!==void 0&&t.toLowerCase()===e?(i.push((0,Z.jsx)(`span`,{className:`text-accent-fg`,children:t},r)),a+=1):i.push((0,Z.jsx)(Q.Fragment,{children:t},r)),o+=1}return(0,Z.jsx)(Z.Fragment,{children:i})}function _E(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase().indexOf(n);return r<0?e:(0,Z.jsxs)(Z.Fragment,{children:[e.slice(0,r),(0,Z.jsx)(`span`,{className:`text-accent-fg`,children:e.slice(r,r+n.length)}),e.slice(r+n.length)]})}var vE=(0,Q.memo)(function(e){let t=(0,X.c)(46),{item:n,index:r,selectedIndex:i,showHighlight:a,filterQuery:o,currentAgentId:s,currentBadgeLabel:c,runBusy:l,pendingFollowUpsCount:u,maxPendingFollowUps:d,queueBadgeLabel:f,queueFullBadgeLabel:p,queueFullTooltip:m,skillUnavailableLabel:h,skillAgentDeniedLabel:g,skillSourceLabels:_,onSelectItem:v}=e,y=n.kind===`skill`,b=n.kind===`agent`,x;t[0]!==b||t[1]!==y||t[2]!==n.agentId||t[3]!==n.avatar?(x=b?(0,Z.jsx)(Aa,{agentId:n.agentId,avatar:n.avatar,size:18,className:`size-[18px] shrink-0`}):y?(0,Z.jsx)(Ht,{className:`size-4 shrink-0 text-accent-fg`,"aria-hidden":!0}):(0,Z.jsx)(Zt,{className:`size-4 shrink-0 text-amber-600 dark:text-amber-400`,"aria-hidden":!0}),t[0]=b,t[1]=y,t[2]=n.agentId,t[3]=n.avatar,t[4]=x):x=t[4];let S=x,C;t[5]!==o||t[6]!==b||t[7]!==n.name||t[8]!==a?(C=b?a?(0,Z.jsx)(Z.Fragment,{children:gE(n.name,o)}):(0,Z.jsx)(`span`,{className:`text-fg`,children:n.name}):a?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-fg`,children:`/`}),gE(n.name,o)]}):(0,Z.jsxs)(`span`,{className:`text-fg`,children:[`/`,n.name]}),t[5]=o,t[6]=b,t[7]=n.name,t[8]=a,t[9]=C):C=t[9];let w=C,T=b&&s!=null&&s.length>0&&n.agentId===s,E=y&&n.availability.status!==`available`,D,O;if(t[10]!==n||t[11]!==d||t[12]!==u||t[13]!==l){let e={runBusy:l,pendingFollowUpsCount:u,maxPendingFollowUps:d};O=rE(n,e),D=nE(n,e),t[10]=n,t[11]=d,t[12]=u,t[13]=l,t[14]=D,t[15]=O}else D=t[14],O=t[15];let k=D,A=null;if(T){let e;t[16]===c?e=t[17]:(e=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-accent-soft px-1 py-px text-[0.6rem] font-medium leading-none text-accent-fg`,"aria-label":c,children:c}),t[16]=c,t[17]=e),A=e}else if(E){let e=n.availability.reason??`unavailable`,r=n.availability.status===`agent-denied`?g:h,i;t[18]!==e||t[19]!==r?(i=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-surface-hover px-1 py-px text-[0.6rem] font-medium leading-none text-fg-muted`,"aria-label":e,children:r}),t[18]=e,t[19]=r,t[20]=i):i=t[20],A=i}else if(y&&n.source){let e=_[n.source]??n.source,r;t[21]===e?r=t[22]:(r=(0,Z.jsx)(`span`,{className:`ml-2 shrink-0 text-[11px] font-normal text-fg-muted`,children:e}),t[21]=e,t[22]=r),A=r}else if(k){let e;t[23]===p?e=t[24]:(e=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-red-100 px-1 py-px text-[0.6rem] font-medium leading-none text-red-700 dark:bg-red-900/40 dark:text-red-300`,"aria-label":p,children:p}),t[23]=p,t[24]=e),A=e}else if(O){let e;t[25]===f?e=t[26]:(e=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-surface-hover px-1 py-px text-[0.6rem] font-medium leading-none text-fg-muted`,"aria-label":f,children:f}),t[25]=f,t[26]=e),A=e}let j=i===r,M=`palette-${r}`,N;t[27]!==o||t[28]!==n.description||t[29]!==a?(N=n.description?a?_E(n.description,o):n.description:null,t[27]=o,t[28]=n.description,t[29]=a,t[30]=N):N=t[30];let P=k?m:void 0,F;t[31]!==n||t[32]!==v?(F=()=>v(n),t[31]=n,t[32]=v,t[33]=F):F=t[33];let I;return t[34]!==S||t[35]!==k||t[36]!==n||t[37]!==w||t[38]!==a||t[39]!==j||t[40]!==M||t[41]!==N||t[42]!==P||t[43]!==F||t[44]!==A?(I=(0,Z.jsx)(bE,{item:n,icon:S,selected:j,id:M,nameLine:w,descriptionLine:N,dimCategoryBadge:a,trailingBadge:A,disabled:k,disabledTooltip:P,onSelect:F}),t[34]=S,t[35]=k,t[36]=n,t[37]=w,t[38]=a,t[39]=j,t[40]=M,t[41]=N,t[42]=P,t[43]=F,t[44]=A,t[45]=I):I=t[45],I}),yE=(0,Q.memo)(function(e){let t=(0,X.c)(53),{open:n,anchorRef:r,sections:i,flatItems:a,loading:o,failedKinds:s,selectedIndex:c,noResults:l,sectionLoadFailedLabel:u,query:d,skillsLabel:f,commandsLabel:p,agentsLabel:m,currentAgentId:h,currentBadgeLabel:g,runBusy:_,pendingFollowUpsCount:v,maxPendingFollowUps:y,queueBadgeLabel:b,queueFullBadgeLabel:x,queueFullTooltip:S,skillUnavailableLabel:C,skillAgentDeniedLabel:w,skillSourceLabels:T,onSelectItem:E,panelRef:D}=e,[O,k]=(0,Q.useState)(null),A,j;t[0]!==r||t[1]!==n?(A=()=>{if(!n){k(null);return}let e=()=>{let e=r.current;if(!e)return;let t=e.getBoundingClientRect();k({left:t.left,top:t.top,width:t.width})};e();let t=r.current,i=t&&typeof ResizeObserver<`u`?new ResizeObserver(()=>{e()}):null;return t&&i&&i.observe(t),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{t&&i&&i.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},j=[n,r],t[0]=r,t[1]=n,t[2]=A,t[3]=j):(A=t[2],j=t[3]),(0,Q.useLayoutEffect)(A,j);let M,N;if(t[4]!==a.length||t[5]!==n||t[6]!==c?(M=()=>{!n||a.length===0||document.getElementById(`palette-${c}`)?.scrollIntoView?.({block:`nearest`})},N=[a.length,n,c],t[4]=a.length,t[5]=n,t[6]=c,t[7]=M,t[8]=N):(M=t[7],N=t[8]),(0,Q.useEffect)(M,N),!n||typeof document>`u`||O===null)return null;let P=a.length,F=a[c],I=Math.min(O.width,hE),L;t[9]===d?L=t[10]:(L=d.trim(),t[9]=d,t[10]=L);let R=L,z=R.length>0,B;t[11]!==m||t[12]!==p||t[13]!==f?(B={skill:f,command:p,agent:m},t[11]=m,t[12]=p,t[13]=f,t[14]=B):B=t[14];let ee=B,V;t[15]!==h||t[16]!==g||t[17]!==R||t[18]!==y||t[19]!==E||t[20]!==v||t[21]!==b||t[22]!==x||t[23]!==S||t[24]!==_||t[25]!==c||t[26]!==z||t[27]!==w||t[28]!==T||t[29]!==C?(V={selectedIndex:c,showHighlight:z,filterQuery:R,currentAgentId:h,currentBadgeLabel:g,runBusy:_,pendingFollowUpsCount:v,maxPendingFollowUps:y,queueBadgeLabel:b,queueFullBadgeLabel:x,queueFullTooltip:S,skillUnavailableLabel:C,skillAgentDeniedLabel:w,skillSourceLabels:T,onSelectItem:E},t[15]=h,t[16]=g,t[17]=R,t[18]=y,t[19]=E,t[20]=v,t[21]=b,t[22]=x,t[23]=S,t[24]=_,t[25]=c,t[26]=z,t[27]=w,t[28]=T,t[29]=C,t[30]=V):V=t[30];let H=V,U;if(t[31]!==s||t[32]!==o||t[33]!==l||t[34]!==H||t[35]!==ee||t[36]!==u||t[37]!==i||t[38]!==P){let e=new Map(i.map(xE)),n=[`skill`,`command`,`agent`].filter(t=>e.has(t)||s.includes(t)),r=0;U=o&&P===0?(0,Z.jsx)(`div`,{className:`space-y-2 p-2.5`,"aria-busy":`true`,children:Array.from({length:6},SE)}):P===0&&s.length===0?(0,Z.jsx)(`div`,{className:`p-2.5 text-xs leading-normal text-fg-muted`,children:l}):n.map((t,n)=>{let i=e.get(t)?.items??[],a=r;r+=i.length;let o=`palette-section-${t}`;return(0,Z.jsxs)(`div`,{role:`group`,"aria-labelledby":o,className:Y(n>0&&`border-t border-edge-subtle`),children:[(0,Z.jsxs)(`div`,{id:o,className:`sticky top-0 z-10 flex items-center justify-between bg-surface-overlay px-2.5 py-2 text-[0.65rem] font-medium uppercase leading-none tracking-wide text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:ee[t]}),(0,Z.jsx)(`span`,{className:`tabular-nums`,"aria-hidden":!0,children:i.length})]}),s.includes(t)?(0,Z.jsx)(`div`,{className:`px-2.5 pb-2 text-[11px] leading-relaxed text-fg-muted`,children:u}):i.map((e,t)=>(0,Z.jsx)(vE,{item:e,index:a+t,...H},e.id))]},t)}),t[31]=s,t[32]=o,t[33]=l,t[34]=H,t[35]=ee,t[36]=u,t[37]=i,t[38]=P,t[39]=U}else U=t[39];let W=U,te;t[40]!==O.left||t[41]!==O.top||t[42]!==I?(te={position:`fixed`,left:O.left,top:O.top,width:I,transform:`translateY(calc(-100% - 8px))`,zIndex:mE},t[40]=O.left,t[41]=O.top,t[42]=I,t[43]=te):te=t[43];let ne=`${f}, ${p}, ${m}`,re=F?`${ee[F.kind]}: ${F.name}`:``,ie;t[44]===re?ie=t[45]:(ie=(0,Z.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:re}),t[44]=re,t[45]=ie);let ae;return t[46]!==W||t[47]!==o||t[48]!==D||t[49]!==ne||t[50]!==ie||t[51]!==te?(ae=(0,Us.createPortal)((0,Z.jsx)(Qa,{delayDuration:0,skipDelayDuration:0,disableHoverableContent:!1,children:(0,Z.jsxs)(`div`,{ref:D,className:`pointer-events-auto max-h-[min(32rem,60vh)] min-h-8 overflow-y-auto rounded-md border border-edge bg-surface-overlay text-xs leading-4 shadow-lg`,style:te,role:`listbox`,"aria-label":ne,"aria-busy":o,children:[ie,W]})}),document.body),t[46]=W,t[47]=o,t[48]=D,t[49]=ne,t[50]=ie,t[51]=te,t[52]=ae):ae=t[52],ae}),bE=(0,Q.memo)(function(e){let t=(0,X.c)(39),{item:n,icon:r,selected:i,id:a,nameLine:o,descriptionLine:s,dimCategoryBadge:c,trailingBadge:l,disabled:u,disabledTooltip:d,onSelect:f}=e,p;t[0]===n.description?p=t[1]:(p=n.description.trim(),t[0]=n.description,t[1]=p);let m=p,h=m.length>0&&s!=null,g=m.length>0,_=n.description,v=n.category&&n.kind!==`skill`&&!c&&!(n.kind===`agent`&&l),y;t[2]===o?y=t[3]:(y=(0,Z.jsx)(`span`,{className:`min-w-0 max-w-[min(12rem,46%)] shrink-0 truncate font-semibold text-fg`,children:o}),t[2]=o,t[3]=y);let b;t[4]!==n.category||t[5]!==v?(b=v?(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 py-px text-[0.6rem] font-normal leading-none text-fg-muted`,children:n.category}):null,t[4]=n.category,t[5]=v,t[6]=b):b=t[6];let x;t[7]!==s||t[8]!==h?(x=h?(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-normal leading-tight text-fg-muted`,children:s}):null,t[7]=s,t[8]=h,t[9]=x):x=t[9];let S;t[10]!==y||t[11]!==b||t[12]!==x?(S=(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-baseline gap-1`,children:[y,b,x]}),t[10]=y,t[11]=b,t[12]=x,t[13]=S):S=t[13];let C=S,w=u?`cursor-not-allowed opacity-50 text-fg-muted`:i?`cursor-pointer bg-surface-hover text-fg`:`cursor-pointer text-fg-subtle hover:bg-surface-hover/80`,T;t[14]===w?T=t[15]:(T=Y(`flex min-h-11 w-full min-w-0 items-center gap-2 px-2.5 py-1.5 text-left text-sm leading-5 sm:min-h-9`,w),t[14]=w,t[15]=T);let E=T,D;t[16]!==u||t[17]!==f?(D=e=>{u||e.pointerType===`mouse`&&e.button!==0||(e.preventDefault(),f())},t[16]=u,t[17]=f,t[18]=D):D=t[18];let O=D,k;t[19]===r?k=t[20]:(k=(0,Z.jsx)(`span`,{className:`shrink-0 [&_svg]:align-middle`,children:r}),t[19]=r,t[20]=k);let A;t[21]!==k||t[22]!==C||t[23]!==l?(A=(0,Z.jsxs)(Z.Fragment,{children:[k,C,l]}),t[21]=k,t[22]=C,t[23]=l,t[24]=A):A=t[24];let j=A,M=u&&d?d:g?_:null,N=u||void 0,P;t[25]!==a||t[26]!==O||t[27]!==E||t[28]!==j||t[29]!==i||t[30]!==N?(P=(0,Z.jsx)(`div`,{id:a,role:`option`,"aria-selected":i,"aria-disabled":N,tabIndex:-1,className:E,onPointerDown:O,children:j}),t[25]=a,t[26]=O,t[27]=E,t[28]=j,t[29]=i,t[30]=N,t[31]=P):P=t[31];let F=P;if(M!==null){let e;t[32]===F?e=t[33]:(e=(0,Z.jsx)(no,{asChild:!0,children:F}),t[32]=F,t[33]=e);let n;t[34]===M?n=t[35]:(n=(0,Z.jsx)($a,{children:(0,Z.jsx)(to,{side:`right`,align:`start`,sideOffset:8,collisionPadding:12,className:`!z-[10000] max-h-[min(12rem,40vh)] max-w-sm overflow-y-auto rounded-md border border-edge bg-surface-overlay px-2 py-1.5 text-left text-[11px] leading-snug text-fg shadow-lg select-text [max-width:min(20rem,90vw)]`,"data-slash-palette-tooltip":``,children:(0,Z.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:M})})}),t[34]=M,t[35]=n);let r;return t[36]!==e||t[37]!==n?(r=(0,Z.jsxs)(eo,{delayDuration:0,children:[e,n]}),t[36]=e,t[37]=n,t[38]=r):r=t[38],r}return F});function xE(e){return[e.kind,e]}function SE(e,t){return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,Z.jsx)(Qt,{className:`size-4 shrink-0`}),(0,Z.jsx)(Qt,{className:`h-3 w-28`}),(0,Z.jsx)(Qt,{className:`h-3 flex-1`})]},t)}var CE=new Map;function wE(e){let t=CE.get(e);return t||(t={items:[],loadPromise:null,loaded:!1,writeQueue:Promise.resolve(),mutationVersion:0,clearVersion:0},CE.set(e,t)),t}function TE(e,t){if(e.items[0]?.text===t.text){t.id>0&&(e.items[0]=t);return}e.items=[t,...e.items].slice(0,100)}function EE(e,t){if(e.items.some(e=>e.id===t.id))return;let n=e.items.findIndex(e=>e.id===0&&e.text===t.text);if(n>=0){e.items[n]=t;return}TE(e,t)}function DE(e){return wE(e).items.map(e=>e.text)}function OE(e,t=!1){let n=wE(e);if(n.loaded&&!t)return Promise.resolve();if(n.loadPromise)return n.loadPromise;let r=n.mutationVersion,i=!1;return n.loadPromise=n.writeQueue.then(()=>y(`/api/composer-history?conversationId=${encodeURIComponent(e)}`)).then(t=>{n.mutationVersion===r?(n.items=t.items.filter(t=>t.conversationId===e).slice(0,100),n.loaded=!0):i=!0}).catch(()=>{}).finally(()=>{n.loadPromise=null,i&&n.writeQueue.then(()=>OE(e,!0))}),n.loadPromise}function kE(e,t){let n=t.trim();if(!n)return;let r=wE(e),i=r.clearVersion;r.mutationVersion+=1,TE(r,{conversationId:e,id:0,text:n,createdAt:Date.now()}),r.writeQueue=r.writeQueue.then(async()=>{let t=await y(`/api/composer-history`,{method:`POST`,body:JSON.stringify({conversationId:e,text:n})});r.clearVersion===i&&t.item.conversationId===e&&EE(r,t.item)}).catch(()=>{})}function AE(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.conversationId!=`string`||!t.conversationId||typeof t.id!=`number`||typeof t.text!=`string`||typeof t.createdAt!=`number`)return null;let n=wE(t.conversationId);return n.mutationVersion+=1,EE(n,t),t.conversationId}function jE(e){if(!e||typeof e!=`object`||!(`conversationId`in e)||typeof e.conversationId!=`string`)return null;let t=wE(e.conversationId);return t.mutationVersion+=1,t.clearVersion+=1,t.items=[],e.conversationId}function ME(e){let{conversationId:t,editorRef:n,valueRef:r,resetEditor:i,onWireInput:a}=e,o=(0,Q.useRef)(t);o.current=t;let s=(0,Q.useRef)(null),c=(0,Q.useCallback)(()=>{s.current=null},[]);return(0,Q.useEffect)(()=>{c()},[t,c]),(0,Q.useEffect)(()=>{t&&OE(t,!0);let e=e=>{AE(e.detail)===t&&c()},n=e=>{jE(e.detail)===t&&c()},r=()=>{t&&OE(t,!0)};return window.addEventListener(`composer-history-appended`,e),window.addEventListener(`composer-history-cleared`,n),window.addEventListener(`gateway-realtime-connected`,r),()=>{window.removeEventListener(`composer-history-appended`,e),window.removeEventListener(`composer-history-cleared`,n),window.removeEventListener(`gateway-realtime-connected`,r)}},[t,c]),{onUserTextCommitted:(0,Q.useCallback)((e,n=t)=>{n&&!Rn(e)&&kE(n,e),n===o.current&&c()},[t,c]),onWireInputClearWalk:(0,Q.useCallback)((e,t)=>{s.current=null,a(e,t)},[a]),tryInputHistoryArrow:(0,Q.useCallback)(e=>{if(!t)return!1;let a=DE(t);if(a.length===0)return!1;let o=s.current,c=n.current,l=c?Np(c):0,u=r.current;if(e===`up`){if(o==null){if(l!==0)return!1;s.current={index:0,stash:u};let e=a[0];return e?(i({nextText:e,caretOffset:e.length,focus:!0}),!0):!1}if(o.index>=a.length-1)return!0;o.index+=1;let e=a[o.index];return e?(i({nextText:e,caretOffset:e.length,focus:!0}),!0):!1}if(o==null)return!1;if(--o.index,o.index<0){let e=o.stash;return s.current=null,i({nextText:e,caretOffset:e.length,focus:!0}),!0}let d=a[o.index];return d?(i({nextText:d,caretOffset:d.length,focus:!0}),!0):!1},[t,n,r,i])}}function NE(e){return e.blocked||(e.editingUserTurnId||e.editingFollowUpId)&&e.queuePaused===!1?`blocked`:e.editingFollowUpId?`saveFollowUp`:e.editingUserTurnId?e.runBusy?`blocked`:`replaceTurn`:e.runBusy?`queue`:`send`}function PE(e){if(e.voiceActive)return e.cancelVoiceInput(),null;let t=e.getTextValue(),n=e.getContextRefs();if(!t.trim()&&e.getAttachmentCount()===0&&n.length===0)return null;let r=e.wireAttachmentsPayload();return structuredClone({text:t,attachments:r,contextRefs:n})}function FE(e){let t=(0,Q.useRef)(e);t.current=e;let{chat:n,runBusy:r,voiceActive:i,cancelVoiceInput:a,editingFollowUpId:o,getTextValue:s,getAttachmentCount:c,wireAttachmentsPayload:l,getContextRefs:u,getThinkingLevel:d,onSend:f,onDispatched:p,onAddPendingFollowUp:m,onSteeringInterrupt:h,onCommitEditFollowUp:g,onPendingFollowUpRemove:_,pendingFollowUpsCount:v,resetEditor:y,clearAttachments:b,clearContextRefs:x,clearEditFollowUpRef:S,onUserTextCommitted:C}=e,w={getTextValue:s,getAttachmentCount:c,wireAttachmentsPayload:l,getContextRefs:u},T=(0,Q.useRef)(!1),E=(0,Q.useRef)(!1),D=(0,Q.useRef)(()=>{}),O=(0,Q.useRef)(!1),k=(0,Q.useCallback)(()=>{let n=performance.now(),r=NE(t.current);if(r===`blocked`)return;if(r===`queue`){D.current();return}let s=PE({voiceActive:i,cancelVoiceInput:a,...w});if(!s)return;if(r===`saveFollowUp`){if(O.current||!o)return;O.current=!0,Promise.resolve().then(()=>g(o,s.text,s.attachments,d(),s.contextRefs)).then(n=>{if(n===!1)return;C?.(s.text);let r=t.current;r.draftScope!==e.draftScope||r.editingFollowUpId!==o||r.getTextValue()!==s.text||JSON.stringify(r.wireAttachmentsPayload())!==JSON.stringify(s.attachments)||JSON.stringify(r.getContextRefs())!==JSON.stringify(s.contextRefs)||(r.onFinishFollowUpEdit?.(),S())}).catch(e=>ya(`error`,e instanceof Error?e.message:String(e))).finally(()=>{O.current=!1});return}let c=[s.text,s.attachments.length>0?s.attachments:void 0,d(),s.contextRefs.length>0?s.contextRefs:void 0,{submittedAt:n,onDispatched:e=>p?.(e,s)}];UT(f(...c),n=>{C?.(s.text,n);let i=t.current,a=e.draftScope,o=i.draftScope;if(!(!(r===`send`&&a?.conversationId===null&&n!==void 0&&o?.conversationId===n&&o.gatewayIdentity===a.gatewayIdentity)&&o!==a||i.getTextValue()!==s.text||JSON.stringify(i.wireAttachmentsPayload())!==JSON.stringify(s.attachments)||JSON.stringify(i.getContextRefs())!==JSON.stringify(s.contextRefs))){if(r===`replaceTurn`){i.editingUserTurnId===e.editingUserTurnId&&i.onFinishUserEdit?.();return}y(),b(),x()}})},[r,o,g,S,i,a,f,p,e.editingUserTurnId,e.draftScope,d,C,y,b,x,s,c,l,u]),A=(0,Q.useCallback)(async(o=!e.personal&&void 0,s=e.personal?`steer`:void 0)=>{if(t.current.editingFollowUpId||t.current.editingUserTurnId){k();return}if(!r&&v===0)return;let c=PE({voiceActive:i,cancelVoiceInput:a,...w});if(c&&!t.current.blocked&&m&&!T.current){if(v>=10){ya(`warning`,n.followUpQueueMaxReached,{max:10});return}T.current=!0;try{let n=[c.text,c.attachments.length>0?c.attachments:void 0,c.contextRefs.length>0?c.contextRefs:void 0];(o!==void 0||s!==void 0)&&n.push(o),s!==void 0&&n.push(s),await m(...n),C?.(c.text);let r=t.current;if(r.draftScope!==e.draftScope||r.editingFollowUpId||r.editingUserTurnId||r.getTextValue()!==c.text||JSON.stringify(r.wireAttachmentsPayload())!==JSON.stringify(c.attachments)||JSON.stringify(r.getContextRefs())!==JSON.stringify(c.contextRefs))return;y(),b(),x()}catch(e){ya(`error`,n.followUpQueueSubmitFailed,{message:e instanceof Error?e.message:String(e)})}finally{T.current=!1}}},[k,r,i,a,o,v,m,g,d,e.personal,e.draftScope,n.followUpQueueMaxReached,n.followUpQueueSubmitFailed,S,C,y,b,x,s,c,l,u]);return D.current=()=>{A()},{send:k,flushSteeringDraft:A,interruptDraft:(0,Q.useCallback)(()=>{if(t.current.blocked||t.current.editingFollowUpId||t.current.editingUserTurnId||!r||!h||E.current)return;let n=PE({voiceActive:i,cancelVoiceInput:a,...w});n&&(E.current=!0,(async()=>{if(await h(n.text,n.attachments.length>0?n.attachments:void 0,n.contextRefs.length>0?n.contextRefs:void 0)===!1)return;C?.(n.text);let r=t.current;r.draftScope!==e.draftScope||r.editingFollowUpId||r.editingUserTurnId||r.getTextValue()!==n.text||JSON.stringify(r.wireAttachmentsPayload())!==JSON.stringify(n.attachments)||JSON.stringify(r.getContextRefs())!==JSON.stringify(n.contextRefs)||(y(),b(),x())})().catch(e=>ya(`error`,e instanceof Error?e.message:String(e))).finally(()=>{E.current=!1}))},[r,i,a,o,_,h,e.draftScope,C,S,y,b,x,s,c,l,u]),steerCurrentReply:(0,Q.useCallback)(()=>{let e=t.current;if(!(!e.runBusy||e.blocked||e.voiceActive||e.steeringPending||e.editingFollowUpId||e.editingUserTurnId)){if(!e.personal&&e.pendingFollowUpsCount>0){e.firstPendingFollowUpId&&e.onSteerPendingFollowUp?.(e.firstPendingFollowUpId);return}A(!1,`steer`)}},[A])}}var IE=e=>e?.kind===`editTurn`?`turn:${e.turnId}`:e?.kind===`editFollowUp`?`input:${e.inputId}:${e.version}`:`compose`,LE=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),RE=new Map;function zE(e,t){let n=(RE.get(e)??Promise.resolve()).catch(()=>{}).then(t);RE.set(e,n);let r=()=>{RE.get(e)===n&&RE.delete(e)};return n.then(r,r),n}function BE(e,t,n,r,i,a,o,s){let c=IE(a?.snapshot().mode),l=_(e=>e.conversationId),u=l&&e?JSON.stringify([l,e]):``,d=(0,Q.useRef)({editor:t,attachments:n,refs:r,setRefs:i,editSession:a});d.current={editor:t,attachments:n,refs:r,setRefs:i,editSession:a};let f=(0,Q.useRef)(void 0),p=(0,Q.useRef)(void 0),[m,h]=(0,Q.useState)(0);(0,Q.useLayoutEffect)(()=>{let t=p.current;p.current={identity:l,id:e,unboundDraftKey:o};let n=t?.identity===l&&t?.id===null&&!!e&&e===s?.(),r=t&&(t.identity!==l||t.id!==e||t.unboundDraftKey!==o)&&!n;if(r&&(d.current.editor.resetEditor(),d.current.attachments.clearAttachments(),d.current.setRefs([])),!u||!e){f.current=void 0;return}let i={receipts:[],scope:u,ready:!1,dirty:!1,observe:!1,snapshot:{text:d.current.editor.valueRef.current,attachments:d.current.attachments.attachmentsRef.current,refs:r?[]:d.current.refs,editSession:d.current.editSession?.snapshot()},storage:Pr(e)};f.current=i;let a=!1,c=RE.get(u);return(c?c.catch(()=>{}).then(()=>i.storage.read()):i.storage.read()).then(e=>{if(a=!0,f.current!==i)return;i.receipts=e?.intakeReceipts??[];let t=d.current;e&&!i.dirty&&!t.editor.valueRef.current&&!t.attachments.attachmentsRef.current.length&&!t.refs.length&&(t.editor.resetEditor({nextText:e.text}),t.attachments.setAttachments(e.attachments),t.setRefs(e.refs),e.editSession&&t.editSession?.restore(e.editSession))}).catch(e=>{console.warn(`Composer draft restoration failed`,e)}).finally(()=>{f.current===i&&(i.ready=a,a&&d.current.editSession?.ready?.(),h(e=>e+1))}),()=>{f.current===i&&(f.current=void 0)}},[u,e,l,o,s]),(0,Q.useLayoutEffect)(()=>{let e=f.current;if(!e||e.scope!==u)return;if(!e.observe){e.observe=!0;return}let i={text:t.value,attachments:n.attachments,refs:r,editSession:d.current.editSession?.snapshot()};(i.text!==e.snapshot.text||!LE(i.attachments,e.snapshot.attachments)||!LE(i.refs,e.snapshot.refs)||IE(i.editSession?.mode)!==IE(e.snapshot.editSession?.mode))&&(e.dirty=!0),e.snapshot=i},[u,t.value,n.attachments,r,c]),(0,Q.useEffect)(()=>{let e=f.current;if(!e||e.scope!==u||!e.ready&&!e.dirty)return;let i={text:t.value,attachments:n.attachments,refs:r,editSession:d.current.editSession?.snapshot()},a=i.text||i.attachments.length||r.length||i.editSession?.mode.kind!==void 0&&i.editSession.mode.kind!==`compose`?i:void 0;zE(u,()=>e.storage.write(a?{...a,intakeReceipts:e.receipts}:e.receipts.length?{text:``,attachments:[],refs:[],intakeReceipts:e.receipts}:void 0)).catch(e=>{console.warn(`Composer draft persistence failed`,e)})},[u,m,t.value,n.attachments,r,c]),(0,Q.useEffect)(()=>{let e=f.current;if(!(!e?.ready||!u))return Ys(u,async(t,n)=>{if(await RE.get(u)?.catch(()=>{}),f.current!==e)throw Error(`Conversation changed. Please retry.`);if(e.receipts.includes(t))return;let r=d.current,i=r.attachments.attachmentsRef.current,a=n.filter(e=>!i.some(t=>t.id===e.id));if(i.length+a.length>10)throw Error(`A message supports at most 10 attachments. Remove attachments or choose another conversation.`);r.attachments.setAttachments([...i,...a]),e.receipts.push(t);try{let t={text:r.editor.valueRef.current,attachments:r.attachments.attachmentsRef.current,refs:r.refs,intakeReceipts:e.receipts.slice(),editSession:r.editSession?.snapshot()};await zE(u,()=>e.storage.write(t))}catch(n){throw e.receipts=e.receipts.filter(e=>e!==t),n}})},[u,m])}function VE(e){let{conversationId:t,agentId:n,modelKey:r,locale:i,enabled:a,draftText:o,canShow:s}=e,c=_(e=>e.conversationId),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(null),m=(0,Q.useRef)(o),v=(0,Q.useRef)(-1),y=(0,Q.useCallback)((e,t,n)=>{h(g(`/api/sessions/${encodeURIComponent(e.suggestion.conversationId)}/next-turn-suggestion-feedback`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({suggestionId:e.suggestion.id,impressionId:e.impressionId,event:t,...n===void 0?{}:{edited:n}})}).catch(()=>{})},[]);(0,Q.useEffect)(()=>{m.current.length>0&&o.length===0&&(p.current=null),m.current=o},[o]),(0,Q.useEffect)(()=>{p.current=null,v.current=-1,u(null),f(null)},[t,n,r,i,c]),(0,Q.useEffect)(()=>{if(u(null),!a||!t)return;let e=!1,r=0,o,s=0,c=new AbortController,l=async()=>{let a=++r;try{if(await jr(t))return;let d=await h(g(`/api/sessions/${encodeURIComponent(t)}/next-turn-suggestion?locale=${i}`),{signal:c.signal});if(!d.ok)return;let f=Bs.safeParse(await d.json());if(e||a!==r||!f.success)return;let p=f.data.suggestion;if(f.data.status===`ready`&&p&&p.conversationId===t&&p.locale===i&&(!n||p.agentId===n)&&p.inputRevision>=v.current&&p.expiresAt>Date.now()&&p.transcriptId===await Lr(t)){if(e||a!==r)return;u(e=>e?.suggestion.id===p.id?e:{suggestion:p,impressionId:crypto.randomUUID()}),o=setTimeout(()=>{u(null)},Math.max(0,p.expiresAt-Date.now()))}else u(null),f.data.status===`pending`&&s++<7&&(o=setTimeout(()=>{l()},600))}catch{}},d=e=>{let n=e.detail;if(!(n?.conversationId!==t&&n?.key!==t)){if(typeof n.revision==`number`){if(n.revision<v.current)return;v.current=n.revision}r++,s=0,o&&clearTimeout(o),u(null),e.type===`session-transcript-updated`?o=setTimeout(()=>{l()},150):l()}},f=()=>{r++,s=0,o&&clearTimeout(o),u(null),l()},p=e=>{e.detail?.topic===`sessions`&&f()};l();let m=[`session-next-turn-suggestion-changed`,`session-input-state`,`session-updated`,`session-transcript-updated`];return m.forEach(e=>window.addEventListener(e,d)),window.addEventListener(`gateway-realtime-connected`,f),window.addEventListener(`config-reload`,f),window.addEventListener(`realtime-gap`,p),()=>{e=!0,r++,c.abort(),o&&clearTimeout(o),m.forEach(e=>window.removeEventListener(e,d)),window.removeEventListener(`gateway-realtime-connected`,f),window.removeEventListener(`config-reload`,f),window.removeEventListener(`realtime-gap`,p)}},[t,n,r,i,c,a]);let b=a&&s&&o.length===0&&l?.suggestion.id!==d&&l?.suggestion.conversationId===t&&l.suggestion.expiresAt>Date.now()?l:null,x=(0,Q.useCallback)(()=>{b&&y(b,`shown`)},[b,y]),S=(0,Q.useCallback)(()=>b?(p.current=b,y(b,`accepted`),b.suggestion.prompt):null,[b,y]),C=(0,Q.useCallback)(()=>{b&&(f(b.suggestion.id),y(b,`dismissed`))},[b,y]),w=(0,Q.useCallback)(e=>{let n=p.current;!n||n.suggestion.conversationId!==t||(f(n.suggestion.id),y(n,`submitted`,e.trim()!==n.suggestion.prompt),p.current=null)},[t,y]);return{suggestion:b?.suggestion??null,shown:x,accept:S,dismiss:C,submitted:w}}function HE(e){let t=(0,X.c)(6),{active:n,anchors:r,ignoreSelector:i,onDismiss:a}=e,o,s;t[0]!==n||t[1]!==r||t[2]!==i||t[3]!==a?(o=()=>{if(!n)return;let e=e=>{let t=e.target;if(t instanceof Node){for(let e of r){let n=e.current;if(n&&n.contains(t))return}i&&t instanceof Element&&t.closest(i)||a()}};return window.addEventListener(`pointerdown`,e,!0),()=>window.removeEventListener(`pointerdown`,e,!0)},s=[n,r,i,a],t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s):(o=t[4],s=t[5]),(0,Q.useEffect)(o,s)}var UE=20,WE=`xopc.atMention.recent:`;function GE(e){return`${WE}${e.trim()}`}function KE(e){let t=e?.trim();if(!t||typeof localStorage>`u`)return[];try{let e=localStorage.getItem(GE(t));if(!e)return[];let n=JSON.parse(e);return Array.isArray(n)?n.filter(e=>typeof e==`string`&&e.length>0).slice(0,UE):[]}catch{return[]}}function qE(e,t){let n=e?.trim(),r=t.trim();if(!(!n||!r||typeof localStorage>`u`))try{let e=[r,...KE(n).filter(e=>e!==r)].slice(0,UE);localStorage.setItem(GE(n),JSON.stringify(e))}catch{}}var JE=150,YE=[`file`,`note`,`session`,`browser_tab`,`skill`,`agent`];function XE(e){let t={items:[],loading:e,error:null};return{file:{...t},note:{...t},session:{...t},skill:{...t},agent:{...t},browser_tab:{...t}}}function ZE(e,t){let n=Math.min(Math.max(t,0),e.length);if(n<1)return null;let r=e.slice(0,n).match(/@((?:\\.|[^\s])*)$/);if(!r||r.index===void 0)return null;let i=r.index;return i>0&&/[a-zA-Z0-9_]/.test(e[i-1])?null:{start:i,end:n,query:(r[1]??``).replace(/\\([\\\s])/gu,`$1`)}}function QE(e){return e.replace(/[\\\s]/gu,e=>`\\${e}`)}function $E(e){let t=e.trim();return t.length>0&&t.endsWith(`/`)&&!/^https?:\/\//i.test(t)}function eD(e){return e.replace(/\/+$/,``).trim()}function tD(e){let t=e.replace(/\/+$/,``);if(!t)return``;let n=t.lastIndexOf(`/`);return n<=0?``:t.slice(0,n)}function nD(e,t){return t===0?0:Math.min(e,t-1)}function rD(e){return{id:`file:${e.id}`,kind:`file`,name:e.name,description:e.path,relativePath:e.path,isDirectory:e.isDirectory,fileRef:{sourceId:e.id,expectedVersion:e.revision}}}function iD(e,t,n){let r=(0,X.c)(55),i=n.capabilities??pp,[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(lD),l=(0,Q.useRef)(0),u=v(cD),d;bb0:{if(n.isComposing||n.slashPaletteOpen){d=null;break bb0}if(n.precomputedAtRange!==void 0){d=n.precomputedAtRange;break bb0}let i;r[0]!==t||r[1]!==e?(i=ZE(e,t),r[0]=t,r[1]=e,r[2]=i):i=r[2],d=i}let f=d,p=f!==null,[m]=Za(p?f.query:``,JE),h=p?m:``,g;r[3]===n.conversationId?g=r[4]:(g=n.conversationId?.trim()??``,r[3]=n.conversationId,r[4]=g);let _=g,y;r[5]===n.selectedContextKeys?y=r[6]:(y=[...n.selectedContextKeys??new Set].sort().join(`\0`),r[5]=n.selectedContextKeys,r[6]=y);let b=y,x;r[7]!==i.agentSwitch||r[8]!==i.skills||r[9]!==_||r[10]!==h||r[11]!==u||r[12]!==n||r[13]!==p||r[14]!==b?(x=()=>{let e=l.current+=1;if(!p){c(XE(!1));return}if(!_){c(XE(!!n.prepareSession)),n.prepareSession&&n.prepareSession().catch(()=>{l.current===e&&c(XE(!1))});return}let t={conversationId:_,currentAgentId:n.currentAgentId,language:u,selectedContextKeys:new Set(b?b.split(`\0`):[]),recentPaths:new Set(KE(_))};if($E(h)){let t=XE(!1);t.file={items:[],loading:!0,error:null},c(t);let r=eD(h);Gw(r,{conversationId:_,agentId:n.currentAgentId}).then(t=>{if(l.current!==e)return;let n={id:`browse-up:${r}`,kind:`file`,name:`..`,description:tD(r)||`/`,relativePath:``,isDirectory:!0,isBrowseUp:!0};c(e=>({...e,file:{items:[n,...t.map(rD)],loading:!1,error:null}}))}).catch(t=>{l.current===e&&c(e=>({...e,file:{items:[],loading:!1,error:t instanceof Error?t.message:String(t)}}))});return}c(XE(!0));for(let n of Jw.filter(e=>(e.kind!==`skill`||i.skills)&&(e.kind!==`agent`||i.agentSwitch)))n.search(h,t).then(t=>{l.current===e&&c(e=>({...e,[n.kind]:{items:t,loading:!1,error:null}}))}).catch(t=>{l.current===e&&c(e=>({...e,[n.kind]:{items:[],loading:!1,error:t instanceof Error?t.message:String(t)}}))})},r[7]=i.agentSwitch,r[8]=i.skills,r[9]=_,r[10]=h,r[11]=u,r[12]=n,r[13]=p,r[14]=b,r[15]=x):x=r[15];let S;r[16]!==i.agentSwitch||r[17]!==i.skills||r[18]!==_||r[19]!==h||r[20]!==u||r[21]!==n.currentAgentId||r[22]!==n.prepareSession||r[23]!==p||r[24]!==b?(S=[p,_,h,u,n.currentAgentId,n.prepareSession,b,i.skills,i.agentSwitch],r[16]=i.agentSwitch,r[17]=i.skills,r[18]=_,r[19]=h,r[20]=u,r[21]=n.currentAgentId,r[22]=n.prepareSession,r[23]=p,r[24]=b,r[25]=S):S=r[25],(0,Q.useEffect)(x,S);let C;if(r[26]!==i.agentSwitch||r[27]!==i.skills||r[28]!==s){let e;r[30]!==i.agentSwitch||r[31]!==i.skills?(e=e=>(e!==`skill`||i.skills)&&(e!==`agent`||i.agentSwitch),r[30]=i.agentSwitch,r[31]=i.skills,r[32]=e):e=r[32];let t;r[33]===s?t=r[34]:(t=e=>({kind:e,...s[e]}),r[33]=s,r[34]=t),C=YE.filter(e).map(t),r[26]=i.agentSwitch,r[27]=i.skills,r[28]=s,r[29]=C}else C=r[29];let w=C,T=p?w.flatMap(sD):[],E;r[35]!==p||r[36]!==w?(E=p&&w.some(oD),r[35]=p,r[36]=w,r[37]=E):E=r[37];let D=E,O;r[38]===w?O=r[39]:(O=w.flatMap(aD),r[38]=w,r[39]=O);let k=O,A=!D&&T.length===0?k[0]??null:null,j=`${f?.start??``}:${f?.end??``}:${h}`,M;r[40]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>o(0),r[40]=M):M=r[40];let N;r[41]===j?N=r[42]:(N=[j],r[41]=j,r[42]=N),(0,Q.useEffect)(M,N);let P=nD(a,T.length),F;r[43]===T.length?F=r[44]:(F=e=>{T.length!==0&&o(t=>e===`down`?(t+1)%T.length:(t-1+T.length)%T.length)},r[43]=T.length,r[44]=F);let I=F,L=f?.query??``,R;return r[45]!==f||r[46]!==A||r[47]!==T||r[48]!==D||r[49]!==I||r[50]!==p||r[51]!==P||r[52]!==w||r[53]!==L?(R={open:p,atRange:f,sections:w,items:T,selectedIndex:P,query:L,loading:D,error:A,onNavigate:I,setSelectedIndex:o},r[45]=f,r[46]=A,r[47]=T,r[48]=D,r[49]=I,r[50]=p,r[51]=P,r[52]=w,r[53]=L,r[54]=R):R=r[54],R}function aD(e){return e.error?[e.error]:[]}function oD(e){return e.loading}function sD(e){return e.items}function cD(e){return e.language}function lD(){return XE(!1)}function uD(e){return e.kind===`note`?{refId:crypto.randomUUID(),kind:`note`,sourceId:e.noteRef.sourceId,expectedVersion:e.noteRef.expectedVersion,title:e.name}:e.kind===`file`&&!e.isBrowseUp&&e.fileRef?{refId:crypto.randomUUID(),kind:`file`,sourceId:e.fileRef.sourceId,expectedVersion:e.fileRef.expectedVersion,title:e.name,fileKind:e.isDirectory?`directory`:`file`}:e.kind===`session`?{refId:crypto.randomUUID(),kind:`session`,sourceId:e.sessionRef.sourceId,expectedVersion:e.sessionRef.expectedVersion,title:e.name}:e.kind===`browser_tab`?{refId:crypto.randomUUID(),kind:`browser_tab`,sourceId:e.tabRef.sourceId,expectedVersion:e.tabRef.expectedVersion,title:e.name}:null}function dD(e){let{conversationId:t,editorValue:n,editorCursor:r,isComposing:i,runBusy:a,thinkingLevel:o,editorRef:s,valueRef:c,resetEditor:l,clearAttachments:u,onSend:d,onUserTextCommitted:f,onChatAgentChange:p,currentAgentId:m,prepareSession:h,contextRefs:g,onAddContextRef:_,onUnavailableSkill:v,onReviewLauncher:y,onAddPendingFollowUp:b,onAbort:x,pendingFollowUpsCount:S,maxPendingFollowUps:C,clearContextRefs:w,commandPalettePanelRef:T}=e,E=e.capabilities??pp,D=(0,Q.useMemo)(()=>ZE(n,r),[n,r]),O=uE(n,r,{suppress:D!=null,capabilities:E,isComposing:i,currentAgentId:m,conversationId:t}),k=iD(n,r,{conversationId:t,currentAgentId:m,slashPaletteOpen:O.open,capabilities:E,isComposing:i,precomputedAtRange:D,selectedContextKeys:new Set(g.map(e=>`${e.kind}:${e.sourceId}`)),prepareSession:h}),A=O.open||k.open||D!=null,j=(0,Q.useCallback)(()=>({slashRange:O.slashRange,runBusy:a,pendingFollowUpsCount:S,maxPendingFollowUps:C,thinkingLevel:o,editor:{valueRef:c,resetEditor:l},attachments:{clearAttachments:u},contextRefs:{current:g,clear:w},callbacks:{onSend:d,onUserTextCommitted:f,onChatAgentChange:p,onAddPendingFollowUp:b,onAbort:x,onUnavailableSkill:v,onReviewLauncher:y}}),[O.slashRange,a,S,C,o,c,l,u,g,w,d,f,p,b,x,v,y]),M=(0,Q.useCallback)(e=>{!E.commands&&e.kind===`command`||!E.skills&&e.kind===`skill`||!E.agentSwitch&&e.kind===`agent`||XT(e,j())},[j,E]),N=(0,Q.useCallback)(e=>{let n=k.atRange;if(!n)return;let r=uD(e);if(r){let i=_(r);if(!i?.refId)return;let a=`${Xn(i.refId)} `,o=KT(c.current,n.start,n.end,a);l({nextText:o,caretOffset:n.start+a.length,focus:!0}),t&&e.kind===`file`&&qE(t,e.relativePath);return}if(e.kind===`skill`){if(!E.skills)return;let t=`/skill:${e.canonicalName} `,r=KT(c.current,n.start,n.end,t);l({nextText:r,caretOffset:n.start+t.length,focus:!0});return}if(e.kind===`agent`){if(!E.agentSwitch)return;let t=KT(c.current,n.start,n.end,``);l({nextText:t,caretOffset:n.start,focus:!0}),p?.(e.agentId);return}if(e.kind!==`file`||!e.isDirectory)return;let i=`@${QE(e.isBrowseUp?(()=>{let e=tD(eD(n.query));return e?`${e}/`:``})():`${e.relativePath.replace(/\/+$/,``)}/`)}`,a=KT(c.current,n.start,n.end,i),o=n.start+i.length;l({nextText:a,caretOffset:o,focus:!0})},[k.atRange,E,_,t,p,c,l]),P=(0,Q.useRef)(null);P.current=k.open?k.atRange:O.open?O.slashRange:null;let F=c,I=(0,Q.useCallback)(()=>{let e=P.current;if(!e)return;let t=F.current,n=t.slice(0,e.start)+t.slice(e.end);l({nextText:n,caretOffset:e.start})},[l,F]),L=(0,Q.useMemo)(()=>[s,T],[s,T]);HE({active:O.open||k.open,anchors:L,ignoreSelector:`[data-composer-picker-panel], [data-slash-palette-tooltip]`,onDismiss:I});let R=(0,Q.useRef)(k);R.current=k;let z=(0,Q.useRef)(O);z.current=O;let B=(0,Q.useRef)(i);B.current=i;let ee=(0,Q.useRef)(M);ee.current=M;let V=(0,Q.useRef)(N);V.current=N;let H=(0,Q.useRef)({runBusy:a,pendingFollowUpsCount:S,maxPendingFollowUps:C});H.current={runBusy:a,pendingFollowUpsCount:S,maxPendingFollowUps:C};let U=(0,Q.useMemo)(()=>({name:`at-mention`,isActive:()=>{let e=R.current;return e.open&&e.atRange!=null&&!B.current},handleKey:e=>{let t=R.current;if(!t.atRange)return!1;if(e.key===`Escape`){e.preventDefault();let n=t.atRange,r=F.current,i=KT(r,n.start,n.end,``);return l({nextText:i,caretOffset:n.start,focus:!0}),!0}if(t.items.length===0)return!1;if(e.key===`ArrowDown`)return e.preventDefault(),t.onNavigate(`down`),!0;if(e.key===`ArrowUp`)return e.preventDefault(),t.onNavigate(`up`),!0;if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let n=t.items[t.selectedIndex];return n&&V.current(n),!0}return!1}}),[l,F]),W=(0,Q.useMemo)(()=>({name:`slash-palette`,isActive:()=>z.current.open&&!B.current,handleKey:e=>{let t=z.current;if(t.flatItems.length>0){if(e.key===`ArrowDown`)return e.preventDefault(),t.onNavigate(`down`),!0;if(e.key===`ArrowUp`)return e.preventDefault(),t.onNavigate(`up`),!0;if((e.key===`Enter`||e.key===`Tab`)&&!e.shiftKey){e.preventDefault();let n=t.flatItems[t.selectedIndex];return!n||nE(n,H.current)||ee.current(n),!0}}if(e.key===`Escape`){e.preventDefault();let n=t.slashRange;if(n){let e=F.current,t=KT(e,n.start,n.end,``);l({nextText:t,caretOffset:n.start,focus:!0})}return!0}return!1}}),[l,F]);return{palette:O,atPicker:k,shouldSyncSelection:A,adapters:(0,Q.useMemo)(()=>[U,W],[U,W]),applyPalette:M,applyAtMention:N}}function fD(e){return/^[A-Za-z0-9._/@:-]+$/.test(e)?e:JSON.stringify(e)}function pD(e,t){let n=t?.trim();return n?`${e} --instructions ${fD(n)}`:e}function mD(e){if(e.preset===`base`){if(!e.baseBranch?.trim())throw Error(`Missing base branch.`);return pD(`/review --base ${fD(e.baseBranch.trim())}`,e.instructions)}if(e.preset===`commit`){if(!e.commitSha?.trim())throw Error(`Missing commit SHA.`);return pD(`/review --commit ${fD(e.commitSha.trim())}`,e.instructions)}return e.preset,pD(`/review --uncommitted`,e.instructions)}async function hD(e){let t=await h(g(`/api/review/context?${new URLSearchParams({conversationId:e}).toString()}`)),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(x(t.status,t.statusText,n.error?.message));return n.payload}function gD(e,t){let n=e?.status;if(!n)return``;if(n.isClean)return t.statusClean;let r=[];return n.changedFiles>0&&r.push(t.statusChanged.replace(`{{count}}`,String(n.changedFiles))),n.untrackedFiles>0&&r.push(t.statusUntracked.replace(`{{count}}`,String(n.untrackedFiles))),r.join(`, `)}function _D(e,t){let n=t.trim().toLowerCase(),r=[...(e?.branches??[]).filter(e=>!e.current)].sort((t,n)=>t.name===e?.defaultBaseBranch&&n.name!==e.defaultBaseBranch?-1:n.name===e?.defaultBaseBranch&&t.name!==e.defaultBaseBranch?1:t.name.localeCompare(n.name));return n?r.filter(e=>e.name.toLowerCase().includes(n)):r}function vD(e,t){let n=t.trim().toLowerCase(),r=e?.commits??[];return n?r.filter(e=>`${e.sha} ${e.shortSha} ${e.subject}`.toLowerCase().includes(n)):r}function yD(e){let t=(0,X.c)(15),{icon:n,title:r,description:i,disabled:a,onClick:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=Y(`flex min-h-16 w-full items-center gap-3 rounded-lg border border-edge bg-surface-panel px-3 py-2.5 text-left`,`hover:border-accent/45 hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,`disabled:cursor-not-allowed disabled:opacity-50`,ca.transition),t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=(0,Z.jsx)(`span`,{className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg bg-surface-hover text-fg-muted`,children:n}),t[1]=n,t[2]=c);let l;t[3]===r?l=t[4]:(l=(0,Z.jsx)(`span`,{className:`block truncate text-sm font-medium text-fg`,children:r}),t[3]=r,t[4]=l);let u;t[5]===i?u=t[6]:(u=(0,Z.jsx)(`span`,{className:`mt-0.5 block truncate text-xs text-fg-muted`,children:i}),t[5]=i,t[6]=u);let d;t[7]!==l||t[8]!==u?(d=(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[l,u]}),t[7]=l,t[8]=u,t[9]=d):d=t[9];let f;return t[10]!==a||t[11]!==o||t[12]!==c||t[13]!==d?(f=(0,Z.jsxs)(`button`,{type:`button`,disabled:a,className:s,onClick:o,children:[c,d]}),t[10]=a,t[11]=o,t[12]=c,t[13]=d,t[14]=f):f=t[14],f}function bD(e){let t=(0,X.c)(89),{open:n,conversationId:r,disabled:i,chat:a,onClose:o,onSendCommand:s}=e,c=a.reviewLauncher,[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(`presets`),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(``),x;t[0]!==r||t[1]!==c.noSession?(x=()=>{if(!r){u(null),m(c.noSession);return}f(!0),m(null),hD(r).then(e=>u(e)).catch(e=>{u(null),m(e instanceof Error?e.message:String(e))}).finally(()=>f(!1))},t[0]=r,t[1]=c.noSession,t[2]=x):x=t[2];let S=x,w,E;t[3]!==S||t[4]!==n?(w=()=>{n&&(g(`presets`),v(``),b(``),S())},E=[S,n],t[3]=S,t[4]=n,t[5]=w,t[6]=E):(w=t[5],E=t[6]),(0,Q.useEffect)(w,E);let j;t[7]!==l||t[8]!==_?(j=_D(l,_),t[7]=l,t[8]=_,t[9]=j):j=t[9];let M=j,N;t[10]!==l||t[11]!==_?(N=vD(l,_),t[10]=l,t[11]=_,t[12]=N):N=t[12];let F=N,I;t[13]!==l||t[14]!==c?(I=gD(l,c),t[13]=l,t[14]=c,t[15]=I):I=t[15];let L=I,R;t[16]!==y||t[17]!==o||t[18]!==s?(R=(e,t)=>{let n=mD({preset:e,baseBranch:t?.branch,commitSha:t?.commit,instructions:y});s(n),o()},t[16]=y,t[17]=o,t[18]=s,t[19]=R):R=t[19];let z=R,B=h===`base`?c.baseTitle:h===`commit`?c.commitTitle:h===`custom`?c.customTitle:c.title,ee;t[20]===o?ee=t[21]:(ee=e=>!e&&o(),t[20]=o,t[21]=ee);let V;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[120] bg-scrim backdrop-blur-[1px]`}),t[22]=V):V=t[22];let H;t[23]!==c.back||t[24]!==h?(H=h===`presets`?null:(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex size-8 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":c.back,onClick:()=>{g(`presets`),v(``)},children:(0,Z.jsx)(P,{className:`size-4`})}),t[23]=c.back,t[24]=h,t[25]=H):H=t[25];let U;t[26]===B?U=t[27]:(U=(0,Z.jsx)(k,{className:`truncate text-sm font-semibold text-fg`,children:B}),t[26]=B,t[27]=U);let W=l?.cwd??c.description,te;t[28]===W?te=t[29]:(te=(0,Z.jsx)(T,{className:`truncate text-xs text-fg-muted`,children:W}),t[28]=W,t[29]=te);let ne;t[30]!==U||t[31]!==te?(ne=(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[U,te]}),t[30]=U,t[31]=te,t[32]=ne):ne=t[32];let re;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Z.jsx)(Xt,{className:`size-4`}),t[33]=re):re=t[33];let ie;t[34]!==c.close||t[35]!==o?(ie=(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex size-8 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":c.close,onClick:o,children:re}),t[34]=c.close,t[35]=o,t[36]=ie):ie=t[36];let ae;t[37]!==H||t[38]!==ne||t[39]!==ie?(ae=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-edge px-4 py-3`,children:[H,ne,ie]}),t[37]=H,t[38]=ne,t[39]=ie,t[40]=ae):ae=t[40];let oe;t[41]!==M||t[42]!==F||t[43]!==l||t[44]!==i||t[45]!==p||t[46]!==y||t[47]!==S||t[48]!==d||t[49]!==c.customDescription||t[50]!==c.customPlaceholder||t[51]!==c.defaultBadge||t[52]!==c.errorTitle||t[53]!==c.loading||t[54]!==c.localBadge||t[55]!==c.noBranches||t[56]!==c.noCommits||t[57]!==c.presetBase||t[58]!==c.presetBaseDescription||t[59]!==c.presetBaseDescriptionNoDefault||t[60]!==c.presetCommit||t[61]!==c.presetCommitDescription||t[62]!==c.presetCustom||t[63]!==c.presetCustomDescription||t[64]!==c.presetUncommitted||t[65]!==c.remoteBadge||t[66]!==c.retry||t[67]!==c.searchBranches||t[68]!==c.searchCommits||t[69]!==_||t[70]!==z||t[71]!==L||t[72]!==h?(oe=(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:d?(0,Z.jsxs)(`div`,{className:`flex h-full min-h-56 items-center justify-center text-sm text-fg-muted`,children:[(0,Z.jsx)(Pt,{className:`mr-2 size-4 animate-spin`}),c.loading]}):p?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 p-4`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:c.errorTitle}),(0,Z.jsx)(`div`,{className:`mt-1 text-sm text-fg-muted`,children:p}),(0,Z.jsxs)(vi,{type:`button`,className:`mt-4 h-9 rounded-lg`,variant:`secondary`,onClick:S,children:[(0,Z.jsx)(Pt,{className:`size-4`}),c.retry]})]}):h===`presets`?(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(yD,{icon:(0,Z.jsx)(Fe,{className:`size-4`}),title:c.presetBase,description:l?.defaultBaseBranch?c.presetBaseDescription.replace(`{{branch}}`,l.defaultBaseBranch):c.presetBaseDescriptionNoDefault,disabled:i,onClick:()=>g(`base`)}),(0,Z.jsx)(yD,{icon:(0,Z.jsx)(Ye,{className:`size-4`}),title:c.presetUncommitted,description:L,disabled:i,onClick:()=>z(`uncommitted`)}),(0,Z.jsx)(yD,{icon:(0,Z.jsx)(bs,{className:`size-4`}),title:c.presetCommit,description:c.presetCommitDescription.replace(`{{count}}`,String(l?.commits.length??0)),disabled:i,onClick:()=>g(`commit`)}),(0,Z.jsx)(yD,{icon:(0,Z.jsx)(Ye,{className:`size-4`}),title:c.presetCustom,description:c.presetCustomDescription,disabled:i,onClick:()=>g(`custom`)})]}):h===`base`?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(xD,{value:_,placeholder:c.searchBranches,onChange:v}),(0,Z.jsx)(`div`,{className:`grid gap-1`,children:M.length===0?(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge-subtle px-3 py-6 text-center text-sm text-fg-muted`,children:c.noBranches}):M.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`flex items-center justify-between gap-3 rounded-lg px-3 py-2 text-left hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,disabled:i,onClick:()=>z(`base`,{branch:e.name}),children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-fg`,children:e.name}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:e.name===l?.defaultBaseBranch?c.defaultBadge:e.remote?c.remoteBadge:c.localBadge})]},e.name))})]}):h===`commit`?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(xD,{value:_,placeholder:c.searchCommits,onChange:v}),(0,Z.jsx)(`div`,{className:`grid gap-1`,children:F.length===0?(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge-subtle px-3 py-6 text-center text-sm text-fg-muted`,children:c.noCommits}):F.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,disabled:i,onClick:()=>z(`commit`,{commit:e.sha}),children:[(0,Z.jsx)(`span`,{className:`font-mono text-xs text-fg-muted`,children:e.shortSha}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-fg`,children:e.subject}),e.date?(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:e.date.slice(0,10)}):null]},e.sha))})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(`textarea`,{className:`h-40 resize-none rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg outline-none placeholder:text-fg-disabled focus:border-accent focus:ring-2 focus:ring-accent/25`,value:y,placeholder:c.customPlaceholder,onChange:e=>b(e.target.value)}),(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:c.customDescription})]})}),t[41]=M,t[42]=F,t[43]=l,t[44]=i,t[45]=p,t[46]=y,t[47]=S,t[48]=d,t[49]=c.customDescription,t[50]=c.customPlaceholder,t[51]=c.defaultBadge,t[52]=c.errorTitle,t[53]=c.loading,t[54]=c.localBadge,t[55]=c.noBranches,t[56]=c.noCommits,t[57]=c.presetBase,t[58]=c.presetBaseDescription,t[59]=c.presetBaseDescriptionNoDefault,t[60]=c.presetCommit,t[61]=c.presetCommitDescription,t[62]=c.presetCustom,t[63]=c.presetCustomDescription,t[64]=c.presetUncommitted,t[65]=c.remoteBadge,t[66]=c.retry,t[67]=c.searchBranches,t[68]=c.searchCommits,t[69]=_,t[70]=z,t[71]=L,t[72]=h,t[73]=oe):oe=t[73];let se;t[74]!==i||t[75]!==c.cancel||t[76]!==c.runReview||t[77]!==o||t[78]!==z||t[79]!==h?(se=h===`custom`?(0,Z.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge px-4 py-3`,children:[(0,Z.jsx)(vi,{type:`button`,variant:`secondary`,className:`h-9 rounded-lg`,onClick:o,children:c.cancel}),(0,Z.jsx)(vi,{type:`button`,variant:`primary`,className:`h-9 rounded-lg`,disabled:i,onClick:()=>z(`custom`),children:c.runReview})]}):null,t[74]=i,t[75]=c.cancel,t[76]=c.runReview,t[77]=o,t[78]=z,t[79]=h,t[80]=se):se=t[80];let ce;t[81]!==ae||t[82]!==oe||t[83]!==se?(ce=(0,Z.jsxs)(D,{children:[V,(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[121] flex h-[min(86vh,34rem)] w-[min(100vw-2rem,40rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[ae,oe,se]})]}),t[81]=ae,t[82]=oe,t[83]=se,t[84]=ce):ce=t[84];let le;return t[85]!==n||t[86]!==ce||t[87]!==ee?(le=(0,Z.jsx)(A,{open:n,onOpenChange:ee,children:ce}),t[85]=n,t[86]=ce,t[87]=ee,t[88]=le):le=t[88],le}function xD(e){let t=(0,X.c)(7),{value:n,placeholder:r,onChange:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Lt,{className:`size-4 shrink-0 text-fg-muted`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=e=>i(e.target.value),t[1]=i,t[2]=o);let s;return t[3]!==r||t[4]!==o||t[5]!==n?(s=(0,Z.jsxs)(`label`,{className:`flex h-9 items-center gap-2 rounded-lg border border-edge bg-surface-base px-3 text-sm text-fg focus-within:border-accent focus-within:ring-2 focus-within:ring-accent/25`,children:[a,(0,Z.jsx)(`input`,{className:`min-w-0 flex-1 bg-transparent outline-none placeholder:text-fg-disabled`,value:n,placeholder:r,onChange:o})]}),t[3]=r,t[4]=o,t[5]=n,t[6]=s):s=t[6],s}function SD(e){let t=e.mimeType||`application/octet-stream`,n=e.type===`voice`||t.startsWith(`audio/`)?`voice`:e.type===`pasted_text`?`pasted_text`:t.startsWith(`image/`)?`image`:`document`;return{id:e.id,type:n,name:e.name||`file`,mimeType:t,size:e.size??0,content:e.data??``,data:e.data,uri:e.uri,durationSeconds:e.durationSeconds}}var CD=(0,Q.memo)(function({personal:e=!1,placeholder:t,nextTurnSuggestionsEnabled:n=!1,disabled:r,sendDisabled:i=!1,sending:a,streaming:o,conversationId:s,composerContext:c,pageContextPreview:l,contextRefs:u,setContextRefs:d,onDraftAttachmentsChange:p,thinkingLevel:m,modelSupportsThinking:h,onThinkingChange:g,onSend:y,onPersonalSendDispatched:b,onAbort:x,onAddPendingFollowUp:C,onSteeringInterrupt:w,pendingFollowUps:T,editingFollowUpId:E,onBeginEditFollowUp:D,onCancelEditFollowUp:O,onCommitEditFollowUp:k,onPendingFollowUpRemove:A,onPendingFollowUpMove:j,onPendingFollowUpReorder:M,onPendingFollowUpSteer:N,onPendingFollowUpSend:P,steeringFollowUpId:F,welcomeDraftSeed:I,welcomeSuggestion:L,onAcceptWelcomeSuggestion:R,sessionModel:z,showModelSelector:B,onModelChange:ee,modelDisabled:V,onChatAgentChange:H,currentAgentId:U,voiceAgentName:W,voiceTaskId:te,voiceMode:ne,prepareVoiceSession:re,prepareContextSession:ie,unboundDraftKey:ae,getDraftHandoffTarget:oe,editingUserTurnId:se,composerMode:ce,inputControl:le,onResumeQueue:ue,onRestoreEditor:de,onReacquireEdit:G,onComposerHydrated:K,onCancelUserMessageEdit:fe}){let q=ba(),pe=(0,Q.useRef)(!1);r||=q.conversationId===s&&q.active;let me=v(e=>e.language),J=S(me),[he,ge]=f();(0,Q.useEffect)(()=>{Do()},[]);let _e=(...e)=>{if(i)return!1;let t=y(...e);return t instanceof Promise?t.then(t=>(t!==!1&&ot.submitted(e[0]),t)):(t!==!1&&ot.submitted(e[0]),t)},ve=(0,Q.useRef)(!1),ye=(0,Q.useRef)(null),be=(0,Q.useRef)(null),xe=(0,Q.useRef)(null),Se=(0,Q.useRef)(!1),[Ce,we]=(0,Q.useState)(!1),[Te,Ee]=(0,Q.useState)(null),[De,Oe]=(0,Q.useState)(null),[ke,Ae]=(0,Q.useState)(!1),je=(0,Q.useRef)(_e),Ne=(0,Q.useRef)(m);je.current=_e,Ne.current=m,(0,Q.useEffect)(()=>{if(!s||De===s){Ee(null);return}let e=!1;return jr(s).then(e=>e?null:jo(s)).then(t=>{e||Ee(t&&t.required&&!t.trusted&&t.decision===null?t:null)}).catch(()=>{e||Ee(null)}),()=>{e=!0}},[s,De]);let Pe=(0,Q.useCallback)(()=>{!s||ke||(Ae(!0),Co(s,!0).then(()=>{Ee(null)}).catch(e=>{ya(`error`,J.chat.commandPalette.workspaceTrustFailed,{error:e instanceof Error?e.message:String(e)})}).finally(()=>Ae(!1)))},[J.chat.commandPalette,s,ke]),Fe=Va({conversationId:s??`new`,chat:J.chat,onAttachmentsChange:e=>p?.(e.map((e,t)=>({id:e.uri||e.id||`draft:${t}:${e.name}`,title:e.name})))}),Ie=(0,Q.useRef)(u);Ie.current=u;let Le=(0,Q.useCallback)(e=>{let t=u.find(t=>t.refId===e);return t?{title:t.title,kind:t.kind,fileKind:t.fileKind}:void 0},[u]),Re=(0,Q.useCallback)(e=>{let t=e?.contextRefs??[];if(Ie.current=t,d(t),e?.attachments){Fe.setAttachments(e.attachments.map(SD));return}Fe.clearAttachments()},[Fe.clearAttachments,Fe.setAttachments,d]),ze=(0,Q.useCallback)(e=>{let t=Ie.current,n=t.find(t=>t.kind===e.kind&&t.sourceId===e.sourceId);if(n){if(n.refId)return n;let r={...n,refId:e.refId},i=t.map(e=>e===n?r:e);return Ie.current=i,d(i),r}if(t.length>=5)return ya(`warning`,J.chat.commandPalette.contextLimitReached,{max:5}),null;let r=[...t,e];return Ie.current=r,d(r),e},[J.chat.commandPalette.contextLimitReached,d]);(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail;t?.conversationId!==s||t.reference.kind!==`result`||ze(t.reference)};return window.addEventListener(`chat-result-reference`,e),()=>window.removeEventListener(`chat-result-reference`,e)},[s,ze]);let Be=(0,Q.useCallback)(e=>{let t=e.availability.status===`agent-denied`?J.chat.commandPalette.skillAgentDeniedReason:J.chat.commandPalette.skillDisabledReason,n=mm(J.chat.commandPalette.skillUnavailableMessage,{name:e.name,agent:U||`main`,reason:t});if(e.availability.status===`agent-denied`&&window.confirm(`${n}\n\n${J.chat.commandPalette.skillAddToAllowlistConfirm}`)){Mo(U,e.canonicalName,s).catch(e=>{window.alert(e instanceof Error?e.message:String(e))});return}window.alert(n)},[U,J.chat.commandPalette,s]),Ve=lm({capabilities:e?mp:pp,disabled:r,agentId:U,conversationId:s,autoFocusKey:s,welcomeDraftSeed:I,onExternalTextReplace:Re,shouldSyncSelectionRef:ve,resolveContextRef:Le}),He=he.get(`attachmentHandoff`);(0,Q.useEffect)(()=>{if(!He)return;let e=Me(He);ge(e=>{let t=new URLSearchParams(e);return t.delete(`attachmentHandoff`),t},{replace:!0}),e&&Fe.processFiles([e]).then(()=>Ve.editorRef.current?.focus({preventScroll:!0}))},[He,Fe.processFiles,Ve.editorRef,s,ge]);let{onUserTextCommitted:Ue,onWireInputClearWalk:We,tryInputHistoryArrow:Ge}=ME({conversationId:s,editorRef:Ve.editorRef,valueRef:Ve.valueRef,resetEditor:Ve.resetEditor,onWireInput:Ve.onWireInput}),Ke=(0,Q.useCallback)((e,t)=>{We(e,t);let n=Rn(e),r=new Set(n?Bn(n):[]),i=Ie.current,a=i.filter(e=>!e.refId||r.has(e.refId));a.length!==i.length&&(Ie.current=a,d(a))},[We,d]),qe=qf(s??``),Je=a||o||qe||le?.phase===`running`||le?.phase===`stopping`;Se.current=Je;let Ye=(0,Q.useCallback)(()=>{Se.current||we(!0)},[]),Xe=(0,Q.useCallback)(e=>{UT(je.current(e,void 0,Ne.current,u),t=>{Ue?.(e,t),d([])})},[u,Ue,d]),Ze=dD({capabilities:e?mp:pp,conversationId:s,editorValue:Ve.value,editorCursor:Ve.cursor,isComposing:Ve.isComposing,runBusy:Je,thinkingLevel:m,editorRef:Ve.editorRef,valueRef:Ve.valueRef,resetEditor:Ve.resetEditor,clearAttachments:Fe.clearAttachments,onSend:_e,onUserTextCommitted:Ue,onChatAgentChange:H,currentAgentId:U,prepareSession:ie,contextRefs:u,onAddContextRef:ze,onUnavailableSkill:Be,onReviewLauncher:Ye,onAddPendingFollowUp:C,onAbort:x,pendingFollowUpsCount:T.length,maxPendingFollowUps:10,clearContextRefs:()=>d([]),commandPalettePanelRef:ye});ve.current=Ze.shouldSyncSelection;let Qe=_a({disabled:r||q.active,chat:J.chat,onTranscript:e=>{let t=Ve.valueRef.current,n=Ai(t,e);Ve.resetEditor({nextText:n,caretOffset:n.length,focus:!0})}}),{phase:$e,voiceActive:et,startVoiceInput:tt,cancelVoiceInput:nt,confirmVoiceInput:rt}=Qe;(0,Q.useEffect)(()=>{let e=e=>{if(!vT(e,{disabled:r,editorHidden:et&&$e!==`error`}))return;let t=em(e.clipboardData);t&&(e.preventDefault(),Ve.focusForExternalPaste(),tm(t,{processFiles:Fe.processFiles,processPastedText:Fe.processPastedText,insertText:e=>document.execCommand(`insertText`,!1,e),onUnsupportedFiles:()=>ya(`warning`,J.chat.clipboardFileTypeUnsupported)}))};return window.addEventListener(`paste`,e),()=>window.removeEventListener(`paste`,e)},[Fe.processFiles,Fe.processPastedText,r,Ve.focusForExternalPaste,J.chat.clipboardFileTypeUnsupported,et,$e]),(0,Q.useEffect)(()=>{let e=e=>{let t=e?.detail?.target;if(!(t&&t!==`chat`)&&(e?.preventDefault(),!r)){if($e===`recording`){rt();return}($e===`idle`||$e===`error`)&&(Ve.editorRef.current?.focus({preventScroll:!0}),tt())}},t=e=>{let t=e.detail?.target;t&&t!==`chat`||!et||(e.preventDefault(),nt(),Ve.editorRef.current?.focus({preventScroll:!0}))};window.addEventListener(Io,e),window.addEventListener(Po,t);let n=window.setTimeout(()=>{if(Lo()){if(r){Fo();return}e()}},0);return()=>{window.clearTimeout(n),window.removeEventListener(Io,e),window.removeEventListener(Po,t)}},[nt,rt,r,Ve.editorRef,tt,et,$e]);let it=(0,Q.useCallback)(()=>{xe.current=null},[]),at=n&&!r&&!i&&!Je&&!E&&!se&&!Qe.voiceActive&&!Ve.isComposing&&Ve.value.length===0&&Fe.attachments.length===0&&u.length===0&&T.length===0,ot=VE({conversationId:s,agentId:U,modelKey:z,locale:me,enabled:n,draftText:Ve.value,canShow:at}),st=()=>{if(!at||Ve.valueRef.current.length>0||Ie.current.length>0)return!1;let e=ot.accept();return e?(Ve.resetEditor({nextText:e,focus:!0}),!0):!1};(0,Q.useEffect)(()=>{at&&ot.suggestion&&!Ze.palette.open&&ot.shown()},[at,ot.suggestion,ot.shown,Ze.palette.open]);let ct=_(e=>e.conversationId),lt=(0,Q.useMemo)(()=>({gatewayIdentity:ct,conversationId:s,unboundDraftKey:ae}),[ct,s,ae]),ut=(0,Q.useRef)(new Map),dt=(0,Q.useRef)(`compose`),ft=ce??(E?{kind:`editFollowUp`,inputId:E,version:0}:{kind:`compose`}),pt=ft.kind===`editTurn`?`turn:${ft.turnId}`:ft.kind===`editFollowUp`?`input:${ft.inputId}`:`compose`;(0,Q.useLayoutEffect)(()=>{ut.current.clear(),dt.current=`compose`},[lt]),BE(s,Ve,Fe,u,d,{ready:K,snapshot:()=>({mode:ft,drafts:Object.fromEntries(ut.current)}),restore:e=>{ut.current=new Map(Object.entries(e.drafts)),dt.current=e.mode.kind===`editTurn`?`turn:${e.mode.turnId}`:e.mode.kind===`editFollowUp`?`input:${e.mode.inputId}`:`compose`,de?.(e.mode)}},ae,oe);let mt=ft.kind!==`compose`&&!!(le&&!le.paused),ht=FE({personal:e,chat:J.chat,runBusy:Je,draftScope:lt,queuePaused:le?.paused,editingUserTurnId:se,blocked:r||i||mt||le?.phase===`stopping`,onFinishUserEdit:fe,onFinishFollowUpEdit:O,voiceActive:Qe.voiceActive,cancelVoiceInput:Qe.cancelVoiceInput,editingFollowUpId:E,getTextValue:()=>Ve.valueRef.current,getAttachmentCount:()=>Fe.attachmentsRef.current.length,wireAttachmentsPayload:Fe.wireAttachmentsPayload,getContextRefs:()=>u,getThinkingLevel:()=>Ne.current,onSend:_e,onDispatched:e&&b?(e,t)=>{let n=Ve.editorRef.current?.getBoundingClientRect();n&&b(e,n,t)}:void 0,onAddPendingFollowUp:C,onSteeringInterrupt:w,onCommitEditFollowUp:k,onPendingFollowUpRemove:A,pendingFollowUpsCount:T.length,firstPendingFollowUpId:T[0]?.id,onSteerPendingFollowUp:N,steeringPending:!!F,resetEditor:()=>{Ve.resetEditor()},clearAttachments:Fe.clearAttachments,clearContextRefs:()=>d([]),clearEditFollowUpRef:it,onUserTextCommitted:Ue}),gt=(0,Q.useCallback)((e=!1)=>ht.flushSteeringDraft(e),[ht.flushSteeringDraft]),_t=(0,Q.useCallback)((e,t)=>{!s||s===`new`||zw.getState().requestCreate(s,[{id:e.id,type:`text`,text:t,label:J.chat.followUpQueueHeading}])},[s,J.chat.followUpQueueHeading]);(0,Q.useLayoutEffect)(()=>{if(dt.current===pt)return;ut.current.set(dt.current,{text:Ve.valueRef.current,attachments:Fe.wireAttachmentsPayload(),contextRefs:Ie.current,thinkingLevel:Ne.current}),dt.current=pt;let e=ft.kind===`editFollowUp`?T.find(e=>e.id===ft.inputId):void 0;e?.thinkingLevel&&h&&g(e.thinkingLevel);let t=(ft.kind===`compose`?ft.draft:void 0)??ut.current.get(pt)??(ft.kind===`editTurn`?ft.draft:e?{text:e.text,attachments:e.attachments??[],contextRefs:e.contextRefs??[]}:void 0);t?.thinkingLevel&&h&&g(t.thinkingLevel),Fe.setAttachments(FT(t?.attachments??[])),d(t?.contextRefs??[]),Ve.resetEditor({nextText:t?.text??``,focus:!0})},[pt,ft,T,Fe,Ve,d]);let vt=(0,Q.useCallback)(e=>{D(e)},[D]),yt=(0,Q.useRef)({});yt.current={adapters:Ze.adapters,send:ht.send,runBusy:Je,pendingFollowUpsCount:T.length,flushSteeringDraft:gt,steerDraft:()=>ht.flushSteeringDraft(!1,`steer`),steerCurrentReply:ht.steerCurrentReply,interruptDraft:ht.interruptDraft,editingFollowUpId:E,editingUserTurnId:se,onCancelUserMessageEdit:fe,onCancelEditFollowUp:O,attachmentsLen:Fe.attachments.length,contextRefsLen:u.length,isComposing:Ve.isComposing,valueRef:Ve.valueRef,adjustHeight:Ve.adjustHeight,editorRef:Ve.editorRef,tryInputHistoryArrow:Ge,acceptEmptySuggestion:ot.suggestion&&at?st:!Je&&!r&&!i&&!se&&!Qe.voiceActive&&L&&R?()=>(R(L),!0):void 0,dismissEmptySuggestion:ot.suggestion?ot.dismiss:void 0};let bt=Je&&!E&&!se,xt={...J.chat,sendMessage:E?J.chat.followUpSaveEdit:se?J.chat.userMessageReplaceSend:le?.paused?J.chat.sendThisMessage:J.chat.sendMessage},St=!!Ve.value.trim()||Fe.attachments.length>0||u.length>0,Ct=St&&!!w,wt=rs(`(hover: hover) and (pointer: fine)`),Tt=!bt&&!E&&L?`${L.prompt}${wt?` · ${J.chat.welcomeSpotlight.acceptSuggestionHint}`:``}`:null;return(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 w-full flex-col`,children:[s?(0,Z.jsx)(mT,{conversationId:s},s):null,c?(0,Z.jsx)(DT,{...c,conversationId:s,disabled:(c.disabled??r)||a||o}):null,(0,Z.jsxs)(pm,{className:e?`rounded-[1.65rem]`:void 0,dragging:Fe.isDragging,onDragOver:e=>{(e.dataTransfer?.types.includes(`Files`)||rp(e.dataTransfer))&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`,Fe.setIsDragging(!0))},onDragLeave:e=>{e.relatedTarget===null&&Fe.setIsDragging(!1)},onDrop:async e=>{e.preventDefault(),Fe.setIsDragging(!1);let t=e.dataTransfer?.files;if(t?.length){await Fe.processFiles(Array.from(t));return}let n=ip(e.dataTransfer);if(n)try{let e=await Ga(n.path,{conversationId:n.conversationId,agentId:n.agentId,projectId:n.projectId}),t=ci(n.name),r=e.type&&e.type!==`application/octet-stream`?e.type:t;await Fe.processFiles([new File([e],n.name,{type:r})])}catch{ya(`error`,J.chat.attachmentLoadFailed,{name:n.name})}},children:[Fe.isDragging?(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-accent-soft/80 text-sm font-medium text-accent-fg backdrop-blur-[1px]`,children:J.chat.dropFiles}):null,se?(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-b border-edge-subtle bg-accent-soft/40 px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:J.chat.userMessageEditing}),(0,Z.jsx)(`button`,{type:`button`,className:`font-medium text-accent-fg hover:underline`,onClick:fe,children:J.chat.userMessageEditCancel})]}):null,mt&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:J.chat.editQueueResumed}),(0,Z.jsx)(`button`,{type:`button`,disabled:r||i,className:`text-accent-fg disabled:opacity-40`,onClick:()=>G?.({text:Ve.valueRef.current,attachments:Fe.wireAttachmentsPayload(),contextRefs:Ie.current}),children:J.chat.editPauseAgain})]}),le?.paused&&(T.length>0||le.phase===`stopping`||ft.kind!==`compose`)&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:le.phase===`stopping`?J.chat.inputStopping:le.reviewRequired?J.chat.queueReviewRequired:T.length>0?J.chat.queuePausedCount.replace(`{count}`,String(T.length)):J.chat.queuePaused}),(0,Z.jsx)(`button`,{type:`button`,disabled:r||i||!!(E||se)||le.phase!==`idle`,className:`text-accent-fg disabled:opacity-40`,onClick:ue,children:J.chat.queueResume})]}),(0,Z.jsx)(wT,{conversationId:s}),T.length>0?(0,Z.jsx)(`div`,{className:`max-h-[min(30vh,11rem)] shrink-0 overflow-y-auto overflow-x-hidden border-b border-edge-subtle/80 [scrollbar-gutter:stable] dark:border-edge-subtle/70`,children:(0,Z.jsx)(CT,{items:T,disabled:r||i||!!(se||E),editingFollowUpId:E,onEditInComposer:vt,onRemove:A,onMove:j,onReorder:M,onSteer:N,onSendSingle:P,queuePaused:le?.paused,queueIdle:le?.phase===`idle`,steeringBusyId:F,onOpenSideChat:s&&s!==`new`?_t:void 0})}):null,(E||se)&&(0,Z.jsx)(`div`,{className:`flex items-center justify-end px-4 py-1 text-xs`,children:(0,Z.jsx)(`button`,{type:`button`,disabled:i,className:`text-accent-fg disabled:opacity-40`,onClick:()=>de?.({kind:`compose`,draft:{text:Ve.valueRef.current,attachments:Fe.wireAttachmentsPayload(),contextRefs:Ie.current}}),children:J.chat.editAsNewMessage})}),ft.kind===`editFollowUp`&&T.some(e=>e.id===ft.inputId&&e.version!==ft.version)&&(0,Z.jsxs)(`div`,{className:`border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`p`,{children:J.chat.followUpEditConflict}),(0,Z.jsx)(`p`,{className:`my-1 max-h-20 overflow-auto whitespace-pre-wrap`,children:T.find(e=>e.id===ft.inputId)?.text}),(0,Z.jsx)(`button`,{type:`button`,disabled:i,className:`text-accent-fg`,onClick:()=>D(ft.inputId),children:J.chat.followUpKeepMyEdit})]}),E?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:J.chat.inputPlaceholderSteeringEdit}),(0,Z.jsx)(`button`,{type:`button`,onClick:O,className:`shrink-0 rounded px-1 text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:J.chat.userMessageEditCancel})]}):null,(0,Z.jsx)(La,{attachments:Fe.attachments,conversationId:s,topPadded:T.length>0,onRemove:Fe.removeAttachment}),(0,Z.jsx)(TT,{refs:u.filter(e=>!e.refId),label:J.chat.commandPalette.contextLabel,onRemove:e=>d(t=>t.filter(t=>t.sourceId!==e))}),l,(0,Z.jsxs)(`div`,{className:e?`flex min-h-0 shrink-0 items-end gap-1 px-1.5 py-1.5 sm:px-2`:`flex min-h-0 shrink-0 flex-col`,children:[(0,Z.jsx)(`input`,{ref:be,type:`file`,multiple:!0,className:`hidden`,onChange:async e=>{let t=e.target.files;t&&await Fe.processFiles(Array.from(t)),e.target.value=``}}),e&&!Qe.voiceActive&&(0,Z.jsx)(NT,{disabled:r||i,attachmentCount:Fe.attachments.length,maxAttachments:10,chat:J.chat,onPickFiles:()=>be.current?.click()}),(0,Z.jsxs)(`div`,{className:e?`relative min-w-0 flex-1 px-1`:Y(`relative px-3 pb-0 pt-1 sm:px-4`,Fe.attachments.length>0&&`pt-2`),children:[(0,Z.jsx)(HT,{open:Ze.atPicker.open,anchorRef:Ve.editorRef,items:Ze.atPicker.items,selectedIndex:Ze.atPicker.selectedIndex,loading:Ze.atPicker.loading,query:Ze.atPicker.query,noResults:Ze.atPicker.error??J.chat.atMention.noResults,conversationId:s,recentLabel:J.chat.atMention.recentBadge,sectionLabels:{file:J.chat.atMention.files,note:J.chat.atMention.notes,session:J.chat.atMention.chats,skill:J.chat.atMention.skills,agent:J.chat.atMention.agents,browser_tab:J.chat.atMention.browserTabs},ariaLabel:J.chat.atMention.placeholder,onSelectItem:Ze.applyAtMention}),(0,Z.jsx)(yE,{open:Ze.palette.open,anchorRef:Ve.editorRef,panelRef:ye,sections:Ze.palette.loadError?[]:Ze.palette.sections,flatItems:Ze.palette.loadError?[]:Ze.palette.flatItems,loading:Ze.palette.loading,failedKinds:Ze.palette.failedKinds,selectedIndex:Ze.palette.selectedIndex,noResults:Ze.palette.loadError??J.chat.commandPalette.noResults,sectionLoadFailedLabel:J.chat.commandPalette.sectionLoadFailed,query:Ze.palette.query,skillsLabel:J.chat.commandPalette.skillsSection,commandsLabel:J.chat.commandPalette.commandsSection,agentsLabel:J.chat.commandPalette.agentsSection,currentAgentId:U,currentBadgeLabel:J.chat.commandPalette.currentBadge,runBusy:Je,pendingFollowUpsCount:T.length,maxPendingFollowUps:10,queueBadgeLabel:J.chat.commandPalette.queueBadge,queueFullBadgeLabel:J.chat.commandPalette.queueFullBadge,queueFullTooltip:J.chat.commandPalette.queueFullTooltip,skillUnavailableLabel:J.chat.commandPalette.skillUnavailableBadge,skillAgentDeniedLabel:J.chat.commandPalette.skillAgentDeniedBadge,skillSourceLabels:{builtin:J.chat.commandPalette.sourceBuiltin,workspace:J.chat.commandPalette.sourceWorkspace,global:J.chat.commandPalette.sourceGlobal,extra:J.chat.commandPalette.sourceExtra},onSelectItem:Ze.applyPalette}),Qe.voiceActive?(0,Z.jsx)(Ni,{phase:Qe.phase,elapsedLabel:Qe.elapsedLabel,recordedDictation:Qe.recordedDictation,audioLevel:Qe.audioLevel,partialTranscript:Qe.partialTranscript,finalTranscript:Qe.finalTranscript,error:Qe.error,settingsRequired:Qe.settingsRequired,disabled:r,chat:J.chat,onCancel:Qe.cancelVoiceInput,onConfirm:Qe.confirmVoiceInput,onRetry:Qe.retryVoiceInput}):null,(0,Z.jsx)(um,{editorRef:Ve.editorRef,disabled:r,hidden:Qe.voiceActive&&Qe.phase!==`error`,compact:e,ariaLabel:t??J.chat.inputPlaceholder,placeholder:(at&&ot.suggestion?`${ot.suggestion.prompt}${wt?` · ${J.chat.welcomeSpotlight.acceptSuggestionHint}`:``}`:null)??t??Tt??(bt?E?J.chat.inputPlaceholderSteeringEdit:e?J.chat.inputPlaceholderPersonal:J.chat.inputPlaceholderSteering:J.chat.inputPlaceholder),onWireInput:Ke,adjustHeight:Ve.adjustHeight,processFiles:Fe.processFiles,processPastedText:Fe.processPastedText,setIsComposing:Ve.setIsComposing,kbdRef:yt,chatMessages:J.chat})]}),e?(0,Z.jsx)(PT,{disabled:r||i||mt,voiceActive:Qe.voiceActive,runBusy:bt,hasDraft:St,chat:xt,onStartVoiceInput:Qe.startVoiceInput,onSend:ht.send,onAbort:x}):(0,Z.jsx)(vm,{disabled:r,sendDisabled:i||mt,sending:a,streaming:o,runBusy:bt,chat:xt,hasDraft:St,showSteeringInterrupt:Ct,attachmentCount:Fe.attachments.length,maxAttachments:10,onPickFiles:()=>be.current?.click(),thinkingLevel:m,onThinkingChange:g,voiceActive:Qe.voiceActive,onStartVoiceInput:Qe.startVoiceInput,voiceConversationEnabled:!!(s||re),onStartVoiceConversation:()=>{if(!pe.current){if(s){q.open({conversationId:s,name:W||U||`xopc`,taskId:te,mode:ne});return}re&&(pe.current=!0,re().then(e=>{if(e)return q.open({conversationId:e,name:W||U||`xopc`,taskId:te,mode:ne})}).catch(e=>ya(`error`,e instanceof Error?e.message:J.chat.callFailed)).finally(()=>{pe.current=!1}))}},onSend:ht.send,onAbort:x,onInterrupt:ht.interruptDraft,sessionModel:z,showModelSelector:B,onModelChange:ee,modelDisabled:V})]}),(0,Z.jsx)(bD,{open:Ce,conversationId:s,disabled:r||bt,chat:J.chat,onClose:()=>we(!1),onSendCommand:Xe}),(0,Z.jsx)(Wa,{open:Te!==null,title:J.chat.commandPalette.workspaceTrustTitle,description:mm(J.chat.commandPalette.workspaceTrustDescription,{path:Te?.workspacePath??``}),confirmLabel:ke?J.chat.commandPalette.workspaceTrustSaving:J.chat.commandPalette.workspaceTrustConfirm,cancelLabel:J.chat.commandPalette.workspaceTrustCancel,onConfirm:Pe,onCancel:()=>{Ee(null),Oe(s)}})]})]})});function wD(e){let t=(0,X.c)(42),{draft:n,onRemove:r,disabled:i,waiting:a}=e,o=i!==void 0&&i,s=a!==void 0&&a,c=v(ED),l;t[0]===c?l=t[1]:(l=S(c),t[0]=c,t[1]=l);let u=l.chat.pageContext,d=u.label,f;t[2]!==n.title||t[3]!==u.preview?(f=(0,Z.jsxs)(`summary`,{className:`cursor-pointer break-words rounded text-sm text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[u.preview,`: `,n.title]}),t[2]=n.title,t[3]=u.preview,t[4]=f):f=t[4];let p;t[5]===u.frozen?p=t[6]:(p=(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:u.frozen}),t[5]=u.frozen,t[6]=p);let m;t[7]===n.envelope.resourceRefs?m=t[8]:(m=n.envelope.resourceRefs.map(TD).join(`, `),t[7]=n.envelope.resourceRefs,t[8]=m);let h;t[9]===m?h=t[10]:(h=(0,Z.jsx)(`p`,{className:`mt-1 break-all text-xs text-fg-muted`,children:m}),t[9]=m,t[10]=h);let g;t[11]===n.preview?g=t[12]:(g=(0,Z.jsx)(`pre`,{className:`mt-2 max-h-48 overflow-y-auto whitespace-pre-wrap break-words font-sans text-sm text-fg`,children:n.preview}),t[11]=n.preview,t[12]=g);let _;t[13]!==n.truncated||t[14]!==u.truncated?(_=n.truncated?(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:u.truncated}):null,t[13]=n.truncated,t[14]=u.truncated,t[15]=_):_=t[15];let y;t[16]!==n.envelope.selection||t[17]!==u.draft||t[18]!==u.selection?(y=n.envelope.selection?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`mt-2 text-xs font-medium text-fg`,children:n.envelope.selection.draft?u.draft:u.selection}),(0,Z.jsx)(`pre`,{className:`mt-1 max-h-36 overflow-y-auto whitespace-pre-wrap break-words font-sans text-sm text-fg`,children:n.envelope.selection.text})]}):null,t[16]=n.envelope.selection,t[17]=u.draft,t[18]=u.selection,t[19]=y):y=t[19];let b;t[20]!==_||t[21]!==y||t[22]!==f||t[23]!==p||t[24]!==h||t[25]!==g?(b=(0,Z.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[f,p,h,g,_,y]}),t[20]=_,t[21]=y,t[22]=f,t[23]=p,t[24]=h,t[25]=g,t[26]=b):b=t[26];let x=`${u.remove}: ${n.title}`,C;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Z.jsx)(Xt,{className:`size-4`,"aria-hidden":!0}),t[27]=C):C=t[27];let w;t[28]!==o||t[29]!==r||t[30]!==x?(w=(0,Z.jsx)(`button`,{type:`button`,onClick:r,disabled:o,"aria-label":x,className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50`,children:C}),t[28]=o,t[29]=r,t[30]=x,t[31]=w):w=t[31];let T;t[32]!==b||t[33]!==w?(T=(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[b,w]}),t[32]=b,t[33]=w,t[34]=T):T=t[34];let E;t[35]!==u.pending||t[36]!==s?(E=s?(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,role:`status`,children:u.pending}):null,t[35]=u.pending,t[36]=s,t[37]=E):E=t[37];let D;return t[38]!==u.label||t[39]!==T||t[40]!==E?(D=(0,Z.jsxs)(`section`,{className:`mx-4 mt-2 min-w-0 rounded-lg border border-edge bg-surface-hover p-3`,"aria-label":d,children:[T,E]}),t[38]=u.label,t[39]=T,t[40]=E,t[41]=D):D=t[41],D}function TD(e){return`${e.kind} · ${e.id} · v${e.revision}`}function ED(e){return e.language}function DD(e){let t=(0,X.c)(30),{selection:n}=e,r=v(OD)===`zh`,{mode:i,options:a,checking:o,checkFailed:s,failure:c,busy:l,changeMode:u,retry:d}=n,f=s?r?`无法检查运行环境,请重试。`:`Could not check the environment. Retry.`:a?.worktreeUnavailableReason===`workspace_unavailable`?r?`项目目录不可用,请在项目设置中检查路径。`:`Project directory unavailable. Check its path in project settings.`:null;if(!s&&a?.worktreeUnavailableReason===`git_commit_required`){let e;return t[0]===c?e=t[1]:(e=c?(0,Z.jsx)(`p`,{role:`alert`,className:`w-full px-2 py-1 text-xs text-danger`,children:c}):null,t[0]=c,t[1]=e),e}let p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Z.jsx)(qe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),t[2]=p):p=t[2];let m=p,h;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsx)(ks,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),t[3]=h):h=t[3];let g=h,_=r?`运行位置`:`Work in`,y;t[4]!==l||t[5]!==u||t[6]!==s||t[7]!==_||t[8]!==i||t[9]!==a||t[10]!==r?(y=!a&&!s?(0,Z.jsx)(Qt,{className:`h-8 w-36 rounded-full`}):(0,Z.jsx)(fe,{ariaLabel:r?`新会话运行位置`:`New session environment`,placeholder:_,title:r?`Local 指 xopc Gateway 所在机器;首次发送时创建所选环境。`:`Local means the machine running xopc Gateway. The selected environment is created on first send.`,triggerIcon:l?(0,Z.jsx)(Ze,{className:`size-4 shrink-0 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}):i===`managed_worktree`?g:m,triggerClassName:`h-8 w-auto max-w-full justify-start gap-1.5 rounded-full border-0 bg-surface-hover px-2.5 hover:bg-surface-active [&>svg:last-child]:hidden`,contentClassName:`xopc-composer-config-popover w-max min-w-0 max-w-[calc(100vw-1.5rem)]`,side:`top`,allowEmpty:!1,value:i,disabled:l||s,options:[{value:`local_checkout`,label:`Local`,icon:m,group:_,disabled:!a?.localAvailable},{value:`managed_worktree`,label:`New local worktree`,icon:g,group:_,disabled:!a||!!a.worktreeUnavailableReason}],onChange:e=>u(e)}),t[4]=l,t[5]=u,t[6]=s,t[7]=_,t[8]=i,t[9]=a,t[10]=r,t[11]=y):y=t[11];let b;t[12]!==l||t[13]!==o||t[14]!==c||t[15]!==i||t[16]!==a?.worktreeUnavailableReason||t[17]!==f||t[18]!==d||t[19]!==r?(b=f||c||i===`managed_worktree`&&a?.worktreeUnavailableReason?(0,Z.jsx)(vi,{variant:`ghost`,className:`size-8 rounded-full p-0`,disabled:l||o,onClick:d,"aria-label":r?`重新检查环境`:`Recheck environment`,children:(0,Z.jsx)(Pt,{className:`size-3.5 `+(o?`animate-spin motion-reduce:animate-none`:``),"aria-hidden":!0})}):null,t[12]=l,t[13]=o,t[14]=c,t[15]=i,t[16]=a?.worktreeUnavailableReason,t[17]=f,t[18]=d,t[19]=r,t[20]=b):b=t[20];let x;t[21]===f?x=t[22]:(x=f?(0,Z.jsx)(`p`,{role:`status`,className:`w-full px-2 py-1 text-xs leading-5 text-fg-muted`,children:f}):null,t[21]=f,t[22]=x);let S;t[23]===c?S=t[24]:(S=c?(0,Z.jsx)(`p`,{role:`alert`,className:`max-h-20 w-full overflow-y-auto break-words px-2 py-1 text-xs leading-5 text-danger`,children:c}):null,t[23]=c,t[24]=S);let C;return t[25]!==y||t[26]!==b||t[27]!==x||t[28]!==S?(C=(0,Z.jsxs)(Z.Fragment,{children:[y,b,x,S]}),t[25]=y,t[26]=b,t[27]=x,t[28]=S,t[29]=C):C=t[29],C}function OD(e){return e.language}function kD({preparation:e,conversationId:t,ready:n,onSend:r}){let i=_(e=>e.conversationId),a=_(e=>e.baseUrl),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),f=(0,Q.useRef)(null),p=(0,Q.useRef)(!1),m=(0,Q.useRef)(r);m.current=r;let h=(0,Q.useRef)(t);h.current=t;let{data:v,error:b,isValidating:x,mutate:S}=Qr(e?[`project-environment-options`,a,i,e.project.id]:null,async()=>(await y(g(`/api/projects/${encodeURIComponent(e.project.id)}/environment-options`))).options,{keepPreviousData:!1,revalidateOnFocus:!1,shouldRetryOnError:!1}),C=v?.localAvailable&&v.worktreeUnavailableReason!==`git_commit_required`&&v.worktreeUnavailableReason!==`workspace_unavailable`?o?.preparation===e?o.mode:e?Kr(Yr(),e.project.id)??`local_checkout`:`local_checkout`:`local_checkout`,w=!!(!b&&v?.localAvailable&&(C===`local_checkout`||!v.worktreeUnavailableReason)),T=(0,Q.useCallback)(e=>{let t=f.current;f.current=null,d(null),t?.resolve(e?t.conversationId:null)},[]),E=(0,Q.useCallback)(()=>{let e=f.current,t=_.getState();return e?.token===t.conversationId&&e?.baseUrl===t.baseUrl?e?.openedConversationId:void 0},[]);(0,Q.useEffect)(()=>{if(u){if(u.baseUrl!==a||u.token!==i){T(!1);return}if(!u.conversationId){e!==u.preparation&&u.openedConversationId!==t&&T(!1);return}t===u.conversationId?n&&T(!0):e!==u.preparation&&T(!1)}},[u,t,n,e,T,a,i]),(0,Q.useEffect)(()=>()=>{f.current?.resolve(null),f.current=null},[]);let D=(0,Q.useCallback)(async()=>{if(!e)return t;let n=f.current;if(n)return n.preparation===e?n.completion:null;if(!w||x)return null;l(null);let r,o=new Promise(e=>{r=e}),s={preparation:e,baseUrl:a,token:i,conversationId:null,completion:o,resolve:r};return f.current=s,d(s),Promise.resolve().then(()=>e.create(C,void 0,e=>{f.current===s&&(s.openedConversationId=e)})).then(t=>{if(f.current!==s)return;Ur(e.project.id,C);let n={...s,conversationId:t};f.current=n,d(n)}).catch(t=>{f.current===s&&(l({preparation:e,message:t instanceof Error?t.message:String(t)}),S(),T(!1))}),o},[w,a,T,x,C,S,e,t,i]);return{mode:C,options:v,checking:x,checkFailed:!!b,allowed:w,busy:!!(u&&(u.preparation===e||u.conversationId&&u.conversationId===t)),failure:c?.preparation===e?c.message:null,changeMode:t=>{!e||f.current||(s({preparation:e,mode:t}),l(null))},retry:()=>void S(),getDraftHandoffTarget:E,prepareSession:D,send:async(...n)=>{let r=t;if(e){if(p.current)return!1;p.current=!0;try{let e=await D();if(!e)return!1;r=e,n[2]=void 0}finally{p.current=!1}}return!r||h.current!==r?!1:await m.current(...n)!==!1&&{conversationId:r}}}}function AD(e,t){let n=(0,X.c)(12),r=_(MD),i=_(jD),a;n[0]===e?a=n[1]:(a=t=>e?t.sessions[e]?.localDraft:void 0,n[0]=e,n[1]=a);let o=Sn(a),s;n[2]!==i||n[3]!==e||n[4]!==t||n[5]!==o||n[6]!==r?(s=e||t?[`chat-project-scope`,i,r,e,t,o===!0?`draft`:o===!1?`persisted`:`unknown`]:null,n[2]=i,n[3]=e,n[4]=t,n[5]=o,n[6]=r,n[7]=s):s=n[7];let c;n[8]!==e||n[9]!==t?(c=async()=>{let n=e?await jr(e):void 0,r=n?n.creation.projectId:e?(await hn(e)).projectId:t;return r?fn(r):null},n[8]=e,n[9]=t,n[10]=c):c=n[10];let l;n[11]===Symbol.for(`react.memo_cache_sentinel`)?(l={keepPreviousData:!1,shouldRetryOnError:!1},n[11]=l):l=n[11];let{data:u,error:d}=Qr(s,c,l);return d?null:u??null}function jD(e){return e.baseUrl}function MD(e){return e.conversationId}function ND(e,t){let n=es(e,t),r=ts(e,t);return`${e.id} ${n} ${r}`.toLowerCase()}function PD(e,t,n){let r=t.trim().toLowerCase();if(!r)return e;let i=r.split(/\s+/).filter(Boolean);return e.filter(e=>{let t=ND(e,n);return i.every(e=>t.includes(e))})}function FD(e){let t=(0,X.c)(57),{items:n,value:r,disabled:i,placeholder:a,searchPlaceholder:o,noMatches:s,compact:c,contentSide:l,contentAlign:u,className:d,onChange:f}=e,p=l===void 0?`bottom`:l,m=u===void 0?`end`:u,h=v(LD),g;t[0]===h?g=t[1]:(g=S(h),t[0]=h,t[1]=g);let _=g.agentsSettings,[y,b]=(0,Q.useState)(!1),[x,C]=(0,Q.useState)(``),w;t[2]!==_||t[3]!==n||t[4]!==x?(w=PD(n,x,_),t[2]=_,t[3]=n,t[4]=x,t[5]=w):w=t[5];let T=w,E,D,O;if(t[6]!==_||t[7]!==n||t[8]!==a||t[9]!==r){let e;t[13]===r?e=t[14]:(e=e=>e.id===r,t[13]=r,t[14]=e),D=n.find(e),E=D?es(D,_):r||a,O=D?[es(D,_),ts(D,_)].filter(Boolean).join(` — `):void 0,t[6]=_,t[7]=n,t[8]=a,t[9]=r,t[10]=E,t[11]=D,t[12]=O}else E=t[10],D=t[11],O=t[12];let k=O??a,A=c&&`min-w-0 max-w-[min(calc(15ch+3rem),calc(100vw-8rem))] py-1.5 text-[13px]`,j;t[15]!==d||t[16]!==A?(j=Y(Ca,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-2 text-left text-sm font-normal text-fg`,ca.transition,`hover:border-edge hover:bg-surface-hover/45`,wa,Sa,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,A,d),t[15]=d,t[16]=A,t[17]=j):j=t[17];let M;t[18]!==D?.avatar||t[19]!==r?(M=r?(0,Z.jsx)(Aa,{agentId:r,avatar:D?.avatar,size:28,className:`shrink-0`}):null,t[18]=D?.avatar,t[19]=r,t[20]=M):M=t[20];let N=c?`max-w-[15ch] shrink`:`flex-1`,P;t[21]===N?P=t[22]:(P=Y(`min-w-0 truncate text-left`,N),t[21]=N,t[22]=P);let F;t[23]!==E||t[24]!==P?(F=(0,Z.jsx)(`span`,{className:P,children:E}),t[23]=E,t[24]=P,t[25]=F):F=t[25];let I;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,Z.jsx)(ue,{className:`size-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0}),t[26]=I):I=t[26];let L;t[27]!==i||t[28]!==F||t[29]!==k||t[30]!==j||t[31]!==M?(L=(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:i,title:k,className:j,children:[M,F,I]})}),t[27]=i,t[28]=F,t[29]=k,t[30]=j,t[31]=M,t[32]=L):L=t[32];let R;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(R=Y(le,`z-50 w-[var(--radix-popover-trigger-width)] min-w-[12rem] rounded-lg border border-edge bg-surface-overlay shadow-md`,ca),t[33]=R):R=t[33];let z;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(z=e=>C(e.target.value),t[34]=z):z=t[34];let B;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(B=Y(`w-full rounded-md border border-edge bg-surface-panel px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-muted`,wa),t[35]=B):B=t[35];let ee;t[36]!==x||t[37]!==o?(ee=(0,Z.jsx)(`div`,{className:`shrink-0 border-b border-edge p-2`,children:(0,Z.jsx)(`input`,{type:`search`,value:x,onChange:z,placeholder:o,className:B,"aria-label":o})}),t[36]=x,t[37]=o,t[38]=ee):ee=t[38];let V;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(V=Y(G,`max-h-64 p-1`),t[39]=V):V=t[39];let H;t[40]!==_||t[41]!==T||t[42]!==s||t[43]!==f||t[44]!==r?(H=T.length===0?(0,Z.jsx)(`li`,{className:`p-2 text-sm text-fg-muted`,children:s}):T.map(e=>{let t=e.id===r,n=es(e,_),i=ts(e,_),a=i.length>0?i:void 0;return(0,Z.jsx)(`li`,{role:`option`,"aria-selected":t,children:(0,Z.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg`,t?`bg-surface-hover`:`hover:bg-surface-hover`),onClick:()=>{f(e.id),b(!1),C(``)},children:[(0,Z.jsx)(Aa,{agentId:e.id,avatar:e.avatar,size:32,className:`shrink-0`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate font-medium leading-tight`,title:n,children:n}),i?(0,Z.jsx)(`span`,{className:`mt-0.5 block truncate text-xs leading-tight text-fg-muted`,title:a,children:i}):null]}),(0,Z.jsx)(re,{className:Y(`size-4 shrink-0`,t?`opacity-100`:`opacity-0`),"aria-hidden":!0})]})},e.id)}),t[40]=_,t[41]=T,t[42]=s,t[43]=f,t[44]=r,t[45]=H):H=t[45];let U;t[46]===H?U=t[47]:(U=(0,Z.jsx)(`ul`,{"data-select-scroll-region":!0,className:V,role:`listbox`,children:H}),t[46]=H,t[47]=U);let W;t[48]!==m||t[49]!==p||t[50]!==ee||t[51]!==U?(W=(0,Z.jsx)(bi,{children:(0,Z.jsxs)(xi,{side:p,align:m,sideOffset:4,collisionPadding:8,className:R,onOpenAutoFocus:ID,children:[ee,U]})}),t[48]=m,t[49]=p,t[50]=ee,t[51]=U,t[52]=W):W=t[52];let te;return t[53]!==y||t[54]!==L||t[55]!==W?(te=(0,Z.jsxs)(Si,{open:y,onOpenChange:b,children:[L,W]}),t[53]=y,t[54]=L,t[55]=W,t[56]=te):te=t[56],te}function ID(e){return e.preventDefault()}function LD(e){return e.language}function RD(e,t,n=[],r){let i=new Map;for(let t of e)i.set(`${t.kind}:${t.id}`,{...t,pending:!1});let a=(e,t,n,r)=>{let a=`${e}:${t}`,o=i.get(a);if(o){o.pending=!0;return}i.set(a,{kind:e,id:t,title:n,...r?{fileKind:r}:{},origins:[],pending:!0})};for(let e of t)a(e.kind,e.sourceId,e.title,e.fileKind);for(let e of n)a(`attachment`,e.id,e.title);return r&&a(`app_context`,r.id,r.title),[...i.values()]}function zD(e){return e===`zh`?{title:`会话信息`,work:`当前工作`,sources:`关联来源`,environment:`运行位置`,independent:`独立会话`,delegatedTasks:`派出任务`,expand:`显示更多`,collapse:`收起`,session:`会话关联`,task:`任务关联`,recent:`最近引用`,draft:`待发送`,untitled:`未命名 Note`,untitledSource:`未命名来源`,unavailable:`暂无法查看`,partialUnavailable:`部分信息暂无法查看`,refresh:`重试`,more:`仅显示前 20 项`,local:`本地目录`,worktree:`Worktree`,detached:`游离 HEAD`,unavailableEnvironment:`运行目录不可用`,newEnvironment:`在另一环境新建会话`,copyEnvironmentPath:`复制环境路径`,copied:`已复制`}:{title:`Session info`,work:`Current work`,sources:`Related sources`,environment:`Run location`,independent:`Independent chat`,delegatedTasks:`Delegated tasks`,expand:`Show more`,collapse:`Show less`,session:`Linked to chat`,task:`Linked to task`,recent:`Recently used`,draft:`Pending send`,untitled:`Untitled Note`,untitledSource:`Untitled source`,unavailable:`Temporarily unavailable`,partialUnavailable:`Some details are unavailable`,refresh:`Retry`,more:`Showing the first 20 items`,local:`Local directory`,worktree:`Worktree`,detached:`Detached HEAD`,unavailableEnvironment:`Run directory unavailable`,newEnvironment:`New chat in another environment`,copyEnvironmentPath:`Copy environment path`,copied:`Copied`}}var BD=`flex min-w-0 items-center gap-3 rounded-lg px-2 py-2 text-sm text-fg transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,VD=`rounded-md px-2 py-1 text-xs text-fg-muted hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`;function HD({conversationId:e,draftRefs:t=[],draftAttachments:n=[],draftPage:r,project:i,...a}){let[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,f]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),g=zD(v(e=>e.language)),_=d(),y=`${_.pathname}${_.search}`,{data:b,error:x,isLoading:S,isValidating:C,mutate:w}=Df(e,o),T=x?void 0:b,E=T?.work.project??(!e&&i?{id:i.id,title:i.name}:void 0),D=T?.work.task,O=T?.work.delegatedTasks??[],k=RD(T?.sources??[],t,n,r),A=T?.environment,j=!!(E||D||O.length),N=!!T?.unavailableSections.includes(`work`),P=!!T?.unavailableSections.includes(`sources`),F=!!T?.unavailableSections.includes(`environment`),I=[E?.title,D?.title,k.length?`${g.sources} ${k.length}${T?.sourcesHasMore?`+`:``}`:null,A?.kind===`managed_worktree`?`Worktree`:null].filter(Boolean).join(` · `)||g.title,L=()=>s(!1),R=k.some(e=>e.kind===`note`&&!e.unavailable&&e.origins.some(e=>e.kind===`session`)),z=()=>{A?.rootPath&&Oi(A.rootPath).then(e=>{e&&(h(!0),window.setTimeout(()=>h(!1),1200))})},B=()=>(0,Z.jsx)(`button`,{type:`button`,className:VD,"aria-label":g.refresh,disabled:C,onClick:()=>void w(),children:(0,Z.jsx)(Pt,{className:`size-3.5 ${C?`animate-spin motion-reduce:animate-none`:``}`,"aria-hidden":!0})});return(0,Z.jsxs)(Si,{open:o,onOpenChange:s,children:[(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":g.title,title:I,className:`group inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-[background-color,color,transform] duration-150 hover:bg-surface-hover hover:text-fg active:scale-95 data-[state=open]:bg-surface-hover data-[state=open]:text-fg motion-reduce:transition-none motion-reduce:transform-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:(0,Z.jsx)(Xe,{className:`size-4 transition-transform duration-200 group-data-[state=open]:scale-110 motion-reduce:transform-none motion-reduce:transition-none`,strokeWidth:1.75,"aria-hidden":!0})})}),(0,Z.jsx)(bi,{children:(0,Z.jsx)(xi,{align:`end`,sideOffset:8,collisionPadding:12,"aria-label":g.title,onCloseAutoFocus:e=>{document.activeElement?.closest(`[data-primary-chat-composer]`)&&e.preventDefault()},className:`xopc-session-context-popover z-50 w-[min(23rem,calc(100vw-1.5rem))] rounded-xl border border-edge bg-surface-overlay shadow-popover`,children:(0,Z.jsxs)(`div`,{className:`max-h-[min(30rem,var(--radix-popover-content-available-height))] overflow-y-auto rounded-xl p-3`,children:[(0,Z.jsx)(`h2`,{className:`mb-2 px-2 text-sm font-medium text-fg`,children:g.title}),S?(0,Z.jsx)(`div`,{className:`space-y-2 px-2`,"aria-busy":`true`,children:[0,1,2].map(e=>(0,Z.jsx)(Qt,{className:`h-8 w-full`},e))}):x?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 text-sm text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:g.unavailable}),B()]}):(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`section`,{"aria-label":g.work,children:[E?(0,Z.jsxs)(p,{className:BD,to:nt(y,`/projects/${encodeURIComponent(E.id)}`),onClick:L,children:[(0,Z.jsx)(ke,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:E.title,children:E.title})]}):null,D?(0,Z.jsxs)(p,{className:BD,to:tt(y,D.id),onClick:L,children:[(0,Z.jsx)(js,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:D.title,children:D.title}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:D.phase})]}):null,O.length?(0,Z.jsxs)(Z.Fragment,{children:[O.length>2?(0,Z.jsxs)(`button`,{type:`button`,className:`${BD} w-full text-left`,onClick:()=>l(!c),"aria-expanded":c,children:[(0,Z.jsx)(js,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsxs)(`span`,{className:`flex-1`,children:[g.delegatedTasks,` · `,T?.work.delegatedTaskCount??O.length]}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:c?g.collapse:g.expand})]}):(0,Z.jsxs)(`p`,{className:`px-2 pt-2 text-xs text-fg-subtle`,children:[g.delegatedTasks,` · `,T?.work.delegatedTaskCount??O.length]}),(c?O:O.slice(0,2)).map(e=>(0,Z.jsxs)(p,{className:`${BD} pl-9`,to:tt(y,e.id),onClick:L,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title,children:e.title}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:e.runStatus??e.phase})]},e.id))]}):null,j?null:(0,Z.jsx)(`p`,{className:`px-2 py-2 text-sm text-fg-muted`,children:N?g.unavailable:g.independent}),N?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2 text-xs text-fg-muted`,children:[j?g.partialUnavailable:null,B()]}):null,E&&a.onLeaveProject?(0,Z.jsx)(`button`,{type:`button`,className:VD,onClick:()=>{L(),a.onLeaveProject?.()},children:a.leaveProjectLabel}):null]}),k.length||P?(0,Z.jsxs)(`section`,{className:`border-t border-edge-subtle pt-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between px-2`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm text-fg-subtle`,children:[g.sources,` `,k.length?`${k.length}${T?.sourcesHasMore?`+`:``}`:``]}),P?B():null]}),(u?k:k.slice(0,3)).map(e=>{let t=e.origins.some(e=>e.kind===`session`)?g.session:e.origins.some(e=>e.kind===`task`)?g.task:e.origins.some(e=>e.kind===`recent`)?g.recent:g.draft,n=e.pending&&e.origins.length?`${t} · ${g.draft}`:e.pending?g.draft:t,r=e.kind===`file`&&e.fileKind===`directory`?je:e.kind===`file`?Oe:e.kind===`session`?wt:e.kind===`browser_tab`||e.kind===`browser_page`||e.kind===`app_context`?M:e.kind===`mcp_resource`?Se:e.kind===`attachment`?kt:Oe,i=e.unavailable?g.unavailable:e.title||(e.kind===`note`?g.untitled:g.untitledSource),a=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(r,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.unavailable?void 0:e.title,children:i}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:n})]}),o=e.kind===`note`?Ct(y,e.id):e.kind===`session`?`/chat/${encodeURIComponent(e.id)}`:null,s=`${e.kind}:${e.id}`;return!e.unavailable&&o?(0,Z.jsx)(p,{className:BD,to:o,onClick:L,children:a},s):(0,Z.jsx)(`div`,{className:`flex min-w-0 items-center gap-3 px-2 py-2 text-sm text-fg-muted`,children:a},s)}),k.length?null:(0,Z.jsx)(`p`,{className:`px-2 py-2 text-xs text-fg-muted`,children:g.unavailable}),k.length>0&&P?(0,Z.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:g.partialUnavailable}):null,k.length>3?(0,Z.jsx)(`button`,{type:`button`,className:VD,onClick:()=>f(!u),"aria-expanded":u,children:u?g.collapse:g.expand}):null,T?.sourcesHasMore?(0,Z.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:g.more}):null,R&&a.onDraftSourceNote?(0,Z.jsx)(`button`,{type:`button`,className:VD,onClick:()=>{L(),a.onDraftSourceNote?.()},children:a.draftSourceNoteLabel}):null]}):null,e&&(A||F)||a.environmentAction?(0,Z.jsxs)(`section`,{className:`border-t border-edge-subtle pt-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between px-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm text-fg-subtle`,children:g.environment}),F?B():null]}),A?null:a.environmentAction,A?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 px-2 py-2 text-sm text-fg`,children:[(0,Z.jsx)(Et,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:A.kind===`managed_worktree`?g.worktree:g.local}),A.branch||A.headSha?(0,Z.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-40 items-center gap-1 text-xs text-fg-muted`,children:[(0,Z.jsx)(Fe,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:A.branch||(A.detached?`${g.detached} · ${A.headSha?.slice(0,8)}`:A.headSha?.slice(0,8))})]}):null]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 pl-9 pr-1`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-fg-muted`,title:A.rootPath,children:A.rootPath}),(0,Z.jsx)(`button`,{type:`button`,className:VD,"aria-label":m?g.copied:g.copyEnvironmentPath,title:m?g.copied:g.copyEnvironmentPath,onClick:z,children:m?(0,Z.jsx)(re,{className:`size-3.5`,"aria-hidden":!0}):(0,Z.jsx)(xe,{className:`size-3.5`,"aria-hidden":!0})})]}),a.environmentAction,A.available?null:(0,Z.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:g.unavailableEnvironment}),E&&i?.workspaceRoot?(0,Z.jsx)(J,{className:VD,to:Ra(E.id),state:{forceNewChat:!0,agentId:a.agentId,temporary:a.temporary},onClick:L,children:g.newEnvironment}):null]}):(0,Z.jsx)(`p`,{className:`px-2 py-2 text-xs text-fg-muted`,children:g.unavailable})]}):null]}),a.executionDeviceAction]})})})]})}var UD=`min(36dvh, 320px)`;function WD(e){return e&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0?e.width/e.height:void 0}function GD(e){let t=WD(e);return t?`min(calc(100vw - 2rem), ${36*t}dvh, ${Math.min(480,320*t)}px)`:`min(320px, calc(100vw - 2rem))`}function KD(e,t){if(e)return e.phase===`observing`?e.action?t?`正在查看操作结果`:`Checking the result`:t?`正在查看画面`:`Observing the window`:e.action?{activate:[`正在点击`,`Clicking`,`已点击`,`Clicked`],activateSequence:[`正在连续点击`,`Clicking controls`,`已连续点击`,`Controls clicked`],batch:[`正在执行操作`,`Performing actions`,`操作已执行`,`Actions completed`],showMenu:[`正在打开菜单`,`Opening a menu`,`菜单已打开`,`Menu opened`],click:[`正在点击`,`Clicking`,`已点击`,`Clicked`],drag:[`正在拖动`,`Dragging`,`已拖动`,`Dragged`],setValue:[`正在填写`,`Filling a field`,`已填写`,`Field filled`],typeText:[`正在输入`,`Typing`,`已输入`,`Typed`],pressKeys:[`正在按键`,`Pressing keys`,`已按键`,`Keys pressed`],scroll:[`正在滚动`,`Scrolling`,`已滚动`,`Scrolled`],wait:[`正在等待`,`Waiting`,`等待结束`,`Wait completed`]}[e.action]?.[(e.phase===`acting`?0:2)+ +!t]:t?`正在查看画面`:`Observing the window`}function qD(e,t=!0){let[n,r]=(0,Q.useState)(),[i,a]=(0,Q.useState)(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(),[u,d]=(0,Q.useState)(),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(0),[g,_]=(0,Q.useState)(!0),v=(0,Q.useRef)(new Set),y=(0,Q.useRef)(0),b=window.electronAPI?.computer?.preview,x=(0,Q.useCallback)(e=>{for(let e of v.current)e.isConnected||v.current.delete(e);e&&v.current.add(e)},[]);(0,Q.useEffect)(()=>{if(r(void 0),s(!1),a(void 0),!e||!b)return;let t=!1,n=!1,i=b.onState(i=>{!t&&i.conversationId===e&&(n=!0,r(i))});return b.current(e).then(i=>{!t&&!n&&r(i?.conversationId===e?i:void 0)}).catch(()=>{}),()=>{t=!0,i()}},[b,e]);let S=n?.previewId,C=n?.targetEpoch,w=n?.runId,T=n?.status===`preparing`&&!i,E=n?.status===`ended`;return(0,Q.useEffect)(()=>{if(s(!1),l(void 0),p(!1),y.current=0,!t||!b||!e||!S||C===void 0||E||T&&m===0)return;let n=!1,i,o=0,c=0;return b.subscribe({conversationId:e,runId:w,preset:`compact`},async e=>{if(n||e.previewId!==S||e.targetEpoch!==C)return;if(!(`sequence`in e)){r(e);return}if(e.streamEpoch<o||e.streamEpoch===o&&e.sequence<=c)return;o=e.streamEpoch,c=e.sequence;let t=new Uint8Array(e.bytes),i;try{if(i=await createImageBitmap(new Blob([t],{type:`image/jpeg`})),n||o!==e.streamEpoch||c!==e.sequence)return;for(let e of v.current){if(!e.isConnected){v.current.delete(e);continue}e.width=i.width,e.height=i.height,e.getContext(`2d`)?.drawImage(i,0,0)}let r=i.width,a=i.height;l(e=>e?.width===r&&e.height===a?e:{width:r,height:a}),y.current=performance.now(),d(S),s(!0),p(!1)}finally{i?.close()}}).then(e=>{i=e.subscriptionId,n?b.unsubscribe(i).catch(()=>{}):a(i)}).catch(()=>{n||r(e=>e?.previewId===S?{...e,status:`unavailable`,errorCode:`COMPUTER_PREVIEW_UNAVAILABLE`}:e)}),()=>{n=!0,a(void 0),i&&b.unsubscribe(i).catch(()=>{})}},[b,e,S,C,w,m,E,t]),(0,Q.useEffect)(()=>{let e=()=>_(document.visibilityState!==`hidden`);e(),document.addEventListener(`visibilitychange`,e);let t=setInterval(()=>{y.current&&p(performance.now()-y.current>1500)},500);return()=>{clearInterval(t),document.removeEventListener(`visibilitychange`,e)}},[]),{state:n,subscriptionId:i,frameSize:c,hasFrame:o&&u===n?.previewId,stale:f,visible:g,registerCanvas:x,retry:()=>h(e=>e+1),api:b}}function JD({conversationId:e,onFrameSizeChange:t}){let n=qD(e),[r,i]=(0,Q.useState)(!0),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(null),u=v(e=>e.language===`zh`),d=n.state?.previewId;if((0,Q.useEffect)(()=>{n.frameSize&&t?.(n.frameSize)},[n.frameSize,t]),(0,Q.useEffect)(()=>{c(!1)},[d]),(0,Q.useEffect)(()=>{if(!l.current||typeof IntersectionObserver>`u`)return;let e=new IntersectionObserver(e=>i(e.some(e=>e.isIntersecting)),{rootMargin:`160px`});return e.observe(l.current),()=>e.disconnect()},[d]),(0,Q.useEffect)(()=>{!n.subscriptionId||!n.api||n.api.setPreset(n.subscriptionId,n.visible&&r?`compact`:`paused`).catch(()=>{})},[n.api,n.subscriptionId,n.visible,r]),!n.state||n.state.conversationId!==e||n.state.status===`ended`)return null;let f=n.state.status===`unavailable`,p=s?u?`重试切换`:`Retry switch`:n.stale?u?`等待新画面`:`Waiting for a new frame`:KD(n.state.activity,u),m=async()=>{let t=window.electronAPI?.computer;if(!(!t?.focusTarget||!e||!d||a)){o(!0),c(!1);try{await t.focusTarget(e,d)}catch{c(!0)}finally{o(!1)}}};return(0,Z.jsxs)(`section`,{ref:l,"aria-label":u?`电脑操作预览`:`Computer activity`,className:`relative w-full overflow-hidden rounded-xl bg-transparent`,style:{aspectRatio:WD(n.frameSize)??16/10,maxHeight:UD},children:[!n.hasFrame&&!f&&(0,Z.jsx)(Qt,{className:`absolute inset-0`}),(0,Z.jsx)(`canvas`,{ref:n.registerCanvas,role:`img`,"aria-label":u?`${n.state.appName}窗口预览`:`${n.state.appName} window preview`,className:`absolute inset-0 h-full w-full object-contain ${n.hasFrame&&!f?``:`invisible`}`}),!f&&(0,Z.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`absolute left-2 top-2 z-10 max-w-[calc(100%-1rem)]`,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:a||!window.electronAPI?.computer?.focusTarget,"aria-label":u?`切换到正在操作的应用`:`Switch to the active app`,title:s?u?`暂时无法切换应用,请重试`:`Could not switch to the app. Try again.`:u?`切换到应用`:`Switch to app`,className:`inline-flex min-h-11 min-w-11 max-w-full sm:min-h-9 sm:min-w-9 items-center justify-center gap-1.5 rounded-md bg-surface-overlay/80 px-2 text-xs text-fg backdrop-blur-sm hover:bg-surface-overlay focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>{m()},children:[(0,Z.jsx)(Et,{size:14,className:`shrink-0`,"aria-hidden":!0}),p&&(0,Z.jsx)(`span`,{className:`truncate`,children:p})]})}),f&&(0,Z.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-surface-panel/90`,children:(0,Z.jsx)(`button`,{className:`min-h-11 rounded-md px-3 text-sm text-fg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:n.retry,children:u?`预览暂时不可用,点击重试`:`Preview unavailable. Retry preview`})})]})}function YD(e){let t=(0,X.c)(26),{conversationId:n}=e,{state:r}=qD(n,!1),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(),c=v(ZD),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{a(!1),s(void 0)},t[0]=l):l=t[0];let u=r?.previewId,d;if(t[1]!==n||t[2]!==u?(d=[n,u],t[1]=n,t[2]=u,t[3]=d):d=t[3],(0,Q.useEffect)(l,d),!r||r.conversationId!==n||r.status===`ended`)return null;let f=c?`查看电脑预览`:`View computer preview`,p=c?`查看电脑预览`:`View computer preview`,m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Z.jsx)(Et,{className:`size-4 shrink-0`,"aria-hidden":!0}),t[4]=m):m=t[4];let h=c?`电脑`:`Computer`,g;t[5]===h?g=t[6]:(g=(0,Z.jsx)(`span`,{className:`hidden whitespace-nowrap text-xs xl:inline`,children:h}),t[5]=h,t[6]=g);let _;t[7]!==f||t[8]!==p||t[9]!==g?(_=(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsxs)(vi,{variant:`ghost`,className:`size-8 shrink-0 gap-1.5 rounded-lg p-0 xl:w-auto xl:px-2`,title:f,"aria-label":p,children:[m,g]})}),t[7]=f,t[8]=p,t[9]=g,t[10]=_):_=t[10];let y=c?`电脑预览`:`Computer preview`,b;t[11]===o?b=t[12]:(b=GD(o),t[11]=o,t[12]=b);let x;t[13]===b?x=t[14]:(x={"--computer-preview-width":b},t[13]=b,t[14]=x);let S=x,C;t[15]!==n||t[16]!==r.previewId?(C=(0,Z.jsx)(JD,{conversationId:n,onFrameSizeChange:s},r.previewId),t[15]=n,t[16]=r.previewId,t[17]=C):C=t[17];let w;t[18]!==y||t[19]!==S||t[20]!==C?(w=(0,Z.jsx)(bi,{children:(0,Z.jsx)(xi,{align:`end`,sideOffset:8,collisionPadding:16,"aria-label":y,onOpenAutoFocus:XD,style:S,className:`z-40 w-[var(--computer-preview-width)] max-h-[calc(100dvh-5rem)] overflow-hidden rounded-xl bg-transparent p-0 outline-none`,children:C})}),t[18]=y,t[19]=S,t[20]=C,t[21]=w):w=t[21];let T;return t[22]!==i||t[23]!==w||t[24]!==_?(T=(0,Z.jsxs)(Si,{open:i,onOpenChange:a,children:[_,w]}),t[22]=i,t[23]=w,t[24]=_,t[25]=T):T=t[25],T}function XD(e){return e.preventDefault()}function ZD(e){return e.language===`zh`}function QD({conversationId:e,deviceName:t,zh:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,_]=(0,Q.useState)(!1),v=g(`/api/endpoint-tools/artifact-transfers`),{data:b,isLoading:x}=Qr(r?`${v}?conversationId=${encodeURIComponent(e)}`:null,e=>y(e),{shouldRetryOnError:!1}),S=b?.payload.files??[],j=b?.payload.tools??[],M=j.find(e=>e.toolName===s);return(0,Z.jsxs)(A,{open:r,onOpenChange:e=>{i(e),e&&(o(``),c(``),u(``),m(!1),_(!1))},children:[(0,Z.jsx)(w,{asChild:!0,children:(0,Z.jsx)(vi,{variant:`ghost`,className:`h-8 px-2 text-sm`,children:n?`传递文件`:`Transfer file`})}),(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`fixed inset-0 z-[120] bg-black/50`}),(0,Z.jsxs)(O,{className:`fixed left-1/2 top-1/2 z-[121] flex h-[min(23rem,90dvh)] w-[min(28rem,92vw)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay p-4 shadow-popover`,children:[(0,Z.jsx)(k,{className:`text-base font-semibold`,children:n?`向执行设备传递文件`:`Transfer file to execution device`}),(0,Z.jsx)(T,{className:`mt-1 text-sm text-fg-muted`,children:t}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto py-3`,children:[x?(0,Z.jsx)(Qt,{className:`h-20 w-full`}):S.length&&j.length?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(fe,{value:a,onChange:o,placeholder:n?`选择源文件`:`Select source file`,options:S.map(e=>({value:e.fileId,label:`${e.name} · ${e.sourceName} · ${Math.ceil(e.size/1024)} KB`}))}),(0,Z.jsx)(fe,{value:s,onChange:c,placeholder:n?`选择接收能力`:`Select receiving capability`,options:j.map(e=>({value:e.toolName,label:e.title}))})]}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n?`当前没有可传递的文件或接收能力。`:`No eligible file or receiving capability is available.`}),l?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n?`在两分钟内将这段请求发到当前对话。`:`Send this request in this chat within two minutes.`}),(0,Z.jsx)(`textarea`,{readOnly:!0,className:`h-20 w-full resize-none rounded-md border border-edge bg-surface-inset p-2 text-xs`,value:l,"aria-label":n?`对话请求`:`Chat request`,onFocus:e=>e.currentTarget.select()})]}):null,h?(0,Z.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:n?`文件授权失败,请重新选择设备或文件。`:`Unable to authorize transfer. Reselect the device or file.`}):null]}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(vi,{variant:`secondary`,children:n?`关闭`:`Close`})}),l?(0,Z.jsx)(vi,{onClick:async()=>{try{await navigator.clipboard.writeText(l),m(!0)}catch{m(!1)}},children:p?n?`已复制`:`Copied`:n?`复制请求`:`Copy request`}):(0,Z.jsx)(vi,{disabled:d||!M||!S.some(e=>e.fileId===a),onClick:async()=>{if(M){f(!0),_(!1);try{let t=await y(v,{method:`POST`,body:JSON.stringify({conversationId:e,fileId:a,toolName:s})}),r=JSON.stringify({[M.input]:t.payload.transferId});u(n?`请在当前执行设备调用 ${s} 处理已授权的文件,使用参数 ${r}。`:`Use ${s} on the selected execution device to process the authorized file with argument ${r}.`)}catch{_(!0)}finally{f(!1)}}},children:d?n?`授权中…`:`Authorizing…`:n?`生成一次性授权`:`Authorize one transfer`})]})]})]})]})}function $D({conversationId:e,disabled:t}){let n=v(e=>e.language)===`zh`,r=e&&/^[0-9a-f-]{36}$/i.test(e)?g(`/api/endpoint-tools/targets/${encodeURIComponent(e)}`):null,i=Qr(r,async e=>{let t=await h(e);if(t.status===404||t.status===403)return null;if(!t.ok)throw Error(`Device target unavailable`);return(await t.json()).payload},{refreshInterval:5e3,shouldRetryOnError:!1}),a=Qr(r?ls():null,us,{refreshInterval:3e4,shouldRetryOnError:!1}),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1);if(!r)return null;let u=(a.data??[]).filter(e=>!e.principal?.revokedAt&&!e.access?.revokedAt).flatMap(e=>e.endpoints.map(t=>({value:t.endpointId,label:`${e.displayName} · ${e.platform}`}))),d=i.data,f=(a.data??[]).find(e=>e.id===d?.principalId),p=f?.endpoints.some(e=>e.endpointId===d?.endpointId&&e.connectionId===d?.connectionId),m=d&&(!p||d.expiresAt<=Date.now()),_=d?`${f?.displayName??(n?`所选设备`:`Selected device`)}${m?n?` · 需要重新选择`:` · Reselect required`:``}`:void 0;return d&&!u.some(e=>e.value===d.endpointId)&&u.push({value:d.endpointId,label:_,disabled:!0}),(0,Z.jsxs)(`section`,{className:`mt-3 space-y-2 border-t border-edge-subtle px-2 pt-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm text-fg-subtle`,children:n?`执行设备`:`Execution device`}),i.isLoading||a.isLoading?(0,Z.jsx)(Qt,{className:`h-10 w-full rounded-lg`}):(0,Z.jsx)(fe,{value:d?.endpointId??``,options:u,allowEmpty:!0,emptyLabel:n?`由对话选择`:`Choose in conversation`,placeholder:n?`由对话选择`:`Choose in conversation`,title:_,selectedLabel:_,ariaLabel:n?`选择执行设备`:`Select execution device`,triggerIcon:(0,Z.jsx)(Et,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),triggerClassName:`justify-start [&>span]:flex-1`,side:`bottom`,disabled:t||o||!!(a.error||i.error),onChange:async e=>{if(!o){s(!0),l(!1);try{await y(r,{method:e?`PUT`:`DELETE`,...e?{body:JSON.stringify({endpointId:e})}:{}}),await i.mutate()}catch{l(!0),await i.mutate()}finally{s(!1)}}}}),e&&d&&!m&&!t?(0,Z.jsx)(QD,{conversationId:e,deviceName:f?.displayName??d.endpointId,zh:n},d.connectionId):null,c?(0,Z.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:n?`无法更改设备,请先结束正在进行的操作并重试。`:`Unable to change device. Finish active operations and retry.`}):null]})}function eO(e){let t=(0,X.c)(23),{conversationId:n}=e,{data:r}=ac(n),i=v(nO)===`zh`,a=mc(tO),o,s;if(t[0]!==n||t[1]!==r||t[2]!==a){let e=r?pc(n,r.report):null;o=Boolean,s=e&&!a.includes(e),t[0]=n,t[1]=r,t[2]=a,t[3]=o,t[4]=s}else o=t[3],s=t[4];let c=o(s);if(!r||Qs(r.report.status))return null;let l=c?i?`手机需要你操作`:`Your help is needed on the phone`:i?`查看手机`:`View phone`,u=c?i?`手机需要你操作`:`Your help is needed on the phone`:i?`查看手机`:`View phone`,d;t[5]!==n||t[6]!==r.report.deviceId||t[7]!==r.report.deviceName||t[8]!==r.report.sessionId?(d=()=>yi.getState().openPhone(r.report.deviceId??r.report.sessionId,r.report.deviceName,n,!0),t[5]=n,t[6]=r.report.deviceId,t[7]=r.report.deviceName,t[8]=r.report.sessionId,t[9]=d):d=t[9];let f;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(Vt,{className:`size-4`,"aria-hidden":!0}),t[10]=f):f=t[10];let p;t[11]===c?p=t[12]:(p=c&&(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`absolute -right-1 -top-1 size-1.5 rounded-full bg-accent`}),t[11]=c,t[12]=p);let m;t[13]===p?m=t[14]:(m=(0,Z.jsxs)(`span`,{className:`relative`,children:[f,p]}),t[13]=p,t[14]=m);let h=i?`手机`:`Phone`,g;t[15]===h?g=t[16]:(g=(0,Z.jsx)(`span`,{className:`text-xs`,children:h}),t[15]=h,t[16]=g);let _;return t[17]!==g||t[18]!==l||t[19]!==u||t[20]!==d||t[21]!==m?(_=(0,Z.jsxs)(vi,{variant:`ghost`,className:`min-h-10 gap-1.5 px-2`,title:l,"aria-label":u,onClick:d,children:[m,g]}),t[17]=g,t[18]=l,t[19]=u,t[20]=d,t[21]=m,t[22]=_):_=t[22],_}function tO(e){return e.seen}function nO(e){return e.language}function rO(e){let t=(0,X.c)(57),{conversationId:n,directoryOnly:r,workspacePath:i,canChangeWorkspace:a,disabled:o,available:s,onWorkspaceChange:c}=e,l=r!==void 0&&r,u=s===void 0||s,d=v(sO),f;t[0]===d?f=t[1]:(f=S(d),t[0]=d,t[1]=f);let p=f,m=fp(oO),h;t[2]===n?h=t[3]:(h=e=>e.panes[n??`new`]?.open===!0,t[2]=n,t[3]=h);let g=yi(h),[_,y]=(0,Q.useState)(null),b,x;t[4]!==p.chat.workingDirectory.notSet||t[5]!==i?(b=i?.trim()??``,x=b?Ha(b):p.chat.workingDirectory.notSet,t[4]=p.chat.workingDirectory.notSet,t[5]=i,t[6]=b,t[7]=x):(b=t[6],x=t[7]);let w=x,E;t[8]===c?E=t[9]:(E=async e=>{try{await c(e)}catch(e){let t=e;y(t instanceof Error?t.message:String(t))}},t[8]=c,t[9]=E);let j=E,M;t[10]!==j||t[11]!==b?(M={initialPath:b,onPicked:j},t[10]=j,t[11]=b,t[12]=M):M=t[12];let N=Ua(M),P=o||!u||N.picking,F;t[13]!==n||t[14]!==m?(F=()=>{let e=yi.getState(),t=n??`new`;e.setScope(t);let r=e.panes[t]?.tabs.find(aO);r?e.activate(r.id,t):e.openTools(t),m(n??``)},t[13]=n,t[14]=m,t[15]=F):F=t[15];let I=F,L;t[16]!==l||t[17]!==d||t[18]!==I||t[19]!==g?(L=l?null:(0,Z.jsx)(`button`,{type:`button`,className:Y(`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-colors`,`hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,g&&`bg-surface-hover text-fg`),title:d===`zh`?`打开工具`:`Open workspace tools`,"aria-label":d===`zh`?`打开工具`:`Open workspace tools`,"aria-pressed":g,"aria-controls":`app-workspace-panel`,"data-workspace-trigger":!0,onClick:I,children:(0,Z.jsx)(As,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0})}),t[16]=l,t[17]=d,t[18]=I,t[19]=g,t[20]=L):L=t[20];let R;t[21]!==a||t[22]!==l||t[23]!==N||t[24]!==p.chat.workingDirectory.chooseFolder||t[25]!==b||t[26]!==P||t[27]!==w?(R=l&&a?(0,Z.jsxs)(`button`,{type:`button`,disabled:P,className:Y(`inline-flex h-8 max-w-full shrink-0 px-2 items-center justify-center rounded-lg text-fg-muted transition-colors`,`hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,P&&`cursor-not-allowed opacity-50`),title:`${p.chat.workingDirectory.chooseFolder}: ${b||w}`,"aria-label":p.chat.workingDirectory.chooseFolder,onClick:N.pick,children:[(0,Z.jsx)(se,{className:`mr-2 size-4`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate text-xs`,children:p.chat.workingDirectory.chooseFolder})]}):null,t[21]=a,t[22]=l,t[23]=N,t[24]=p.chat.workingDirectory.chooseFolder,t[25]=b,t[26]=P,t[27]=w,t[28]=R):R=t[28];let z;t[29]!==R||t[30]!==L?(z=(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5`,children:[L,R]}),t[29]=R,t[30]=L,t[31]=z):z=t[31];let B;t[32]!==l||t[33]!==N||t[34]!==p.chat.workingDirectory||t[35]!==b?(B=l&&!N.hasNativePicker?(0,Z.jsx)(ce,{open:N.modalOpen,onOpenChange:N.setModalOpen,initialAbsolutePath:b||void 0,onConfirm:N.confirmPick,wd:p.chat.workingDirectory}):null,t[32]=l,t[33]=N,t[34]=p.chat.workingDirectory,t[35]=b,t[36]=B):B=t[36];let ee=_!==null,V;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(V=e=>{e||y(null)},t[37]=V):V=t[37];let H;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[80] bg-scrim backdrop-blur-[2px]`}),t[38]=H):H=t[38];let U;t[39]===p.chat.workingDirectory.applyErrorTitle?U=t[40]:(U=(0,Z.jsx)(k,{className:`text-base font-semibold text-fg`,children:p.chat.workingDirectory.applyErrorTitle}),t[39]=p.chat.workingDirectory.applyErrorTitle,t[40]=U);let W;t[41]===_?W=t[42]:(W=_?(0,Z.jsx)(T,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-fg-muted`,children:_}):null,t[41]=_,t[42]=W);let te;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(te=()=>y(null),t[43]=te):te=t[43];let ne;t[44]===p.chat.workingDirectory.applyErrorClose?ne=t[45]:(ne=(0,Z.jsx)(`div`,{className:`mt-4 flex justify-end border-t border-edge-subtle pt-3`,children:(0,Z.jsx)(vi,{type:`button`,onClick:te,children:p.chat.workingDirectory.applyErrorClose})}),t[44]=p.chat.workingDirectory.applyErrorClose,t[45]=ne);let re;t[46]!==U||t[47]!==W||t[48]!==ne?(re=(0,Z.jsxs)(D,{children:[H,(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[81] w-[min(100%-2rem,26rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-edge bg-surface-overlay p-4 shadow-popover`,onOpenAutoFocus:iO,children:[U,W,ne]})]}),t[46]=U,t[47]=W,t[48]=ne,t[49]=re):re=t[49];let ie;t[50]!==ee||t[51]!==re?(ie=(0,Z.jsx)(A,{open:ee,onOpenChange:V,children:re}),t[50]=ee,t[51]=re,t[52]=ie):ie=t[52];let ae;return t[53]!==z||t[54]!==B||t[55]!==ie?(ae=(0,Z.jsxs)(Z.Fragment,{children:[z,B,ie]}),t[53]=z,t[54]=B,t[55]=ie,t[56]=ae):ae=t[56],ae}function iO(e){return e.preventDefault()}function aO(e){return e.kind===`home`}function oO(e){return e.openForSession}function sO(e){return e.language}function cO(e,t){return e.repeat||e.altKey||e.shiftKey||e.key.toLowerCase()!==`j`?!1:t===`darwin`?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function lO({conversationId:e,dialogOpen:t,onDialogOpenChange:n,hideTrigger:r=!1}){let i=v(e=>e.language),a=i===`zh`?dO:fO,[o,s]=(0,Q.useState)(!1),c=t??o,l=e=>{s(e),n?.(e)},[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(864e5),[x,S]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(``),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)([]),[L,R]=(0,Q.useState)(`hosted`),[z,B]=(0,Q.useState)(!1),[ee,V]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!c||u||f)return;let t=!1;return h(!0),_(null),Promise.all([oo(e),uo(e),ao()]).then(async([n,r,i])=>{if(t)return;d(n),B(i);let a=i?await fo().catch(()=>null):null;if(t)return;V(a?.publishing.allowed===!0);let o=i?await po(e).catch(()=>[]):[];if(t)return;let s=[...o,...r].find(e=>!e.revoked&&!e.expired);s&&p(s)}).catch(e=>{t||_(e instanceof Error?e.message:String(e))}).finally(()=>{t||h(!1)}),()=>{t=!0}},[c,u,f,e]);let H=()=>{d(null),p(null),_(null),h(!1),M(``),P(!1),I([]),V(!1)},U=async()=>{if(!(!u||m)){h(!0),_(null);try{p(await(L===`hosted`?lo:co)(e,{expectedTranscriptId:u.transcriptId,expectedCutoffSeq:u.cutoffSeq,expectedMetadataUpdatedAt:u.metadataUpdatedAt,ttlMs:y,maxViews:x,description:j.trim()||void 0,includeToolActivities:N,attachmentIds:F}))}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},W=async()=>{if(!(!f||m)){h(!0),_(null);try{let t=await oo(e);d(t);let n=f.delivery===`hosted`?so:ro;p(await n(e,f.id,{expectedTranscriptId:t.transcriptId,expectedCutoffSeq:t.cutoffSeq,expectedMetadataUpdatedAt:t.metadataUpdatedAt}))}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},te=async()=>{if(!(!f||m)){h(!0),_(null);try{f.delivery===`hosted`?await mo(e,f.id):await io(f.id),l(!1),H()}catch(e){_(e instanceof Error?e.message:String(e)),h(!1)}}};return(0,Z.jsxs)(A,{open:c,onOpenChange:e=>{l(e),e||H()},children:[r?null:(0,Z.jsx)(w,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`rounded-md p-2 text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg`,title:a.share,"aria-label":a.share,children:(0,Z.jsx)(Es,{className:`size-4`})})}),(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[70] bg-scrim backdrop-blur-[2px]`}),(0,Z.jsxs)(O,{onCloseAutoFocus:e=>{r&&(e.preventDefault(),document.querySelector(`[data-chat-menu-trigger]`)?.focus())},className:Y(`xopc-dialog-content fixed left-1/2 top-1/2 z-[71] flex h-[min(35rem,calc(100dvh-2rem))] w-[min(34rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,`overflow-hidden rounded-xl border border-edge bg-surface-overlay outline-none`),children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(k,{className:`text-base font-semibold text-fg`,children:f?a.created:a.title}),(0,Z.jsx)(T,{className:`mt-0.5 text-xs text-fg-muted`,children:f?a.createdHint:a.hint})]}),(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`touch-target flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,"aria-label":a.close,children:(0,Z.jsx)(Xt,{className:`size-4`})})})]}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:[m&&!u&&!f?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Z.jsx)(Ze,{className:`size-4 animate-spin`}),a.loading]}):f?(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:f.fileName}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.snapshotMessages.replace(`{{count}}`,String(f.messageCount))}),(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:[f.delivery===`hosted`?a.hosted:a.local,` · `,a.revision.replace(`{{revision}}`,String(f.snapshotRevision)),` · `,a.sharedAttachments.replace(`{{count}}`,String(f.attachmentCount))]})]}),(0,Z.jsx)(qt,{shareUrl:f.shareUrl,lanUrl:f.lanUrl,reachability:f.reachability}),(0,Z.jsx)(Jt,{reachability:f.reachability,reachabilityHint:f.reachabilityHint}),(0,Z.jsxs)(`a`,{href:f.shareUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-sm font-medium text-accent hover:underline`,children:[a.open,(0,Z.jsx)(we,{className:`size-3.5`})]})]}):u?(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-inset p-3`,children:[(0,Z.jsx)(`p`,{className:`truncate text-sm font-medium text-fg`,children:u.title}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.snapshotMessages.replace(`{{count}}`,String(u.messageCount))}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:new Date(u.snapshotAt).toLocaleString(i===`zh`?`zh-CN`:`en-US`)})]}),(0,Z.jsxs)(`details`,{className:`rounded-lg border border-edge`,children:[(0,Z.jsx)(`summary`,{className:`touch-target cursor-pointer px-3 py-2.5 text-xs font-medium text-fg transition-colors hover:bg-surface-hover`,children:a.reviewContent}),(0,Z.jsx)(`div`,{className:`max-h-64 space-y-3 overflow-y-auto border-t border-edge p-3`,children:u.messages.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-inset px-3 py-2`,children:[(0,Z.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:e.role===`user`?a.you:a.assistant}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm leading-6 text-fg`,children:e.markdown})]},e.id))})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 rounded-lg border border-accent/20 bg-accent-soft px-3 py-2.5 text-xs leading-5 text-fg-muted`,children:[(0,Z.jsx)(Bt,{className:`mt-0.5 size-4 shrink-0 text-accent-fg`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:a.scope})]}),(0,Z.jsxs)(`label`,{className:`block space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.delivery}),(0,Z.jsxs)(de,{value:L,disabled:m,onChange:e=>R(e.target.value),children:[(0,Z.jsx)(K,{value:`hosted`,children:a.hosted}),(0,Z.jsx)(K,{value:`local`,children:a.local})]})]}),L===`hosted`&&!z?(0,Z.jsx)(ns,{providerId:`xopc-share`,displayName:a.hosted,connected:!1,onConnected:()=>{B(!0),fo().then(e=>V(e.publishing.allowed)).catch(()=>V(!1))}}):null,L===`hosted`&&z&&!ee?(0,Z.jsx)(`p`,{className:`rounded-lg border border-warning/30 bg-warning-soft px-3 py-2 text-xs text-warning`,children:a.hostedDisabled}):null,u.toolActivities.length?(0,Z.jsxs)(`label`,{className:`flex items-start gap-2 rounded-lg border border-edge bg-surface-inset px-3 py-2.5 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:N,disabled:m,onChange:e=>P(e.target.checked),className:`mt-0.5 size-4 rounded border-edge`}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:a.includeTools.replace(`{{count}}`,String(u.toolActivities.length))}),(0,Z.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-muted`,children:a.toolDisclosure})]})]}):null,u.attachmentCandidates.length?(0,Z.jsxs)(`fieldset`,{className:`rounded-lg border border-edge bg-surface-inset px-3 py-2.5`,children:[(0,Z.jsx)(`legend`,{className:`px-1 text-xs font-medium text-fg`,children:a.attachments}),(0,Z.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:a.attachmentDisclosure}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:u.attachmentCandidates.map(e=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(e.id),disabled:m,onChange:t=>I(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id)),className:`size-4 rounded border-edge`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.fileName}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-subtle`,children:uO(e.size)})]},e.id))})]}):null,(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`label`,{className:`space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.ttl}),(0,Z.jsxs)(de,{value:y,disabled:m,onChange:e=>b(Number(e.target.value)),children:[(0,Z.jsx)(K,{value:36e5,children:a.oneHour}),(0,Z.jsx)(K,{value:864e5,children:a.oneDay}),(0,Z.jsx)(K,{value:6048e5,children:a.sevenDays}),(0,Z.jsx)(K,{value:2592e6,children:a.thirtyDays})]})]}),(0,Z.jsxs)(`label`,{className:`space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.maxViews}),(0,Z.jsxs)(de,{value:x??`unlimited`,disabled:m,onChange:e=>S(e.target.value===`unlimited`?null:Number(e.target.value)),children:[(0,Z.jsx)(K,{value:`unlimited`,children:a.unlimited}),(0,Z.jsx)(K,{value:1,children:`1`}),(0,Z.jsx)(K,{value:10,children:`10`}),(0,Z.jsx)(K,{value:50,children:`50`})]})]})]}),(0,Z.jsxs)(`label`,{className:`block space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.description}),(0,Z.jsx)(`input`,{value:j,disabled:m,onChange:e=>M(e.target.value),className:`h-10 w-full rounded-lg border border-edge bg-surface-inset px-3 text-sm font-normal text-fg outline-none focus-visible:border-accent/50 focus-visible:ring-2 focus-visible:ring-accent/20`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:a.publicWarning})]}):null,g?(0,Z.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:g}):null]}),(0,Z.jsx)(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-edge bg-surface-overlay px-4 py-3`,children:f?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,disabled:m,onClick:()=>p(null),children:a.newShare}),(0,Z.jsxs)(vi,{type:`button`,variant:`ghost`,disabled:m,onClick:()=>void te(),children:[(0,Z.jsx)(Wt,{className:`size-4`}),a.revoke]}),(0,Z.jsxs)(vi,{type:`button`,disabled:m||f.delivery===`hosted`&&!ee,onClick:()=>void W(),children:[m?(0,Z.jsx)(Ze,{className:`size-4 animate-spin`}):(0,Z.jsx)(Pt,{className:`size-4`}),a.refresh]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,children:a.cancel})}),(0,Z.jsxs)(vi,{type:`button`,disabled:!u||m||u.messageCount===0||L===`hosted`&&(!z||!ee),onClick:()=>void U(),children:[m?(0,Z.jsx)(Ze,{className:`size-4 animate-spin`}):null,a.create]})]})})]})]})]})}function uO(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}var dO={share:`分享会话`,title:`分享会话`,hint:`创建当前会话的只读快照`,created:`分享已创建`,createdHint:`复制链接后即可发送给其他人`,close:`关闭`,loading:`正在准备预览…`,snapshotMessages:`当前快照包含 {{count}} 条公开消息`,scope:`默认仅包含用户与助手的可见文本;系统提示、推理、工具参数、命令文本、输出和路径始终不会公开。`,ttl:`有效期`,maxViews:`最大访问次数`,includeTools:`包含 {{count}} 条工具活动`,toolDisclosure:`只公开工具名称和成功/失败状态,不公开参数与结果。`,attachments:`附件`,attachmentDisclosure:`附件默认不公开,请逐个选择。`,oneHour:`1 小时`,oneDay:`24 小时`,sevenDays:`7 天`,thirtyDays:`30 天`,unlimited:`不限`,description:`说明(可选)`,publicWarning:`任何获得链接的人都可以查看这份快照。后续会话消息不会自动加入。`,cancel:`取消`,create:`创建分享`,revoke:`撤销分享`,refresh:`更新到当前会话`,open:`打开分享页面`,revision:`快照版本 {{revision}}`,sharedAttachments:`{{count}} 个附件`,newShare:`新建分享`,delivery:`分享方式`,hosted:`XOPC 托管分享`,local:`本机 Gateway 分享`,hostedDisabled:`管理员已暂停你的公网分享能力。已有托管链接当前不可访问,但仍可撤销。`,reviewContent:`检查将要公开的内容`,you:`你`,assistant:`助手`},fO={share:`Share conversation`,title:`Share conversation`,hint:`Create a read-only snapshot of this conversation`,created:`Share created`,createdHint:`Copy the link and send it to anyone`,close:`Close`,loading:`Preparing preview…`,snapshotMessages:`This snapshot contains {{count}} public messages`,scope:`Only visible user and assistant text is included by default. System prompts, reasoning, tool arguments, command text, output, and paths always stay private.`,ttl:`Expires after`,maxViews:`Maximum views`,includeTools:`Include {{count}} tool activities`,toolDisclosure:`Only tool names and success/failure states are shared; arguments and results stay private.`,attachments:`Attachments`,attachmentDisclosure:`Attachments stay private unless selected individually.`,oneHour:`1 hour`,oneDay:`24 hours`,sevenDays:`7 days`,thirtyDays:`30 days`,unlimited:`Unlimited`,description:`Description (optional)`,publicWarning:`Anyone with the link can view this snapshot. Later conversation messages are not added automatically.`,cancel:`Cancel`,create:`Create share`,revoke:`Revoke share`,refresh:`Update to current conversation`,open:`Open shared page`,revision:`Snapshot revision {{revision}}`,sharedAttachments:`{{count}} attachments`,newShare:`New share`,delivery:`Delivery`,hosted:`XOPC Hosted Share`,local:`Local Gateway Share`,hostedDisabled:`An administrator has paused public sharing for your account. Existing hosted links are unavailable, but can still be revoked.`,reviewContent:`Review the content to publish`,you:`You`,assistant:`Assistant`},pO=`(max-width: 767px)`,mO=(0,Q.memo)(function(e){let t=(0,X.c)(141),{inline:n,chatHeadline:r,chatAgents:i,showChatAgentSelector:a,chatAgentId:o,onChatAgentChange:s,chatAgentDisabled:c,conversationId:l,hasMessages:d,workspacePath:f,userContextMode:p,canChangeWorkspace:m,workspaceDisabled:h,onWorkspaceChange:g,prepareTerminalSession:_,terminalDisabled:y,showContextControls:b,onFindOpen:x,projectId:C,context:w}=e,T=n!==void 0&&n,E=d!==void 0&&d,D=p===void 0?`enabled`:p,O=m!==void 0&&m,k=h!==void 0&&h,A=y!==void 0&&y,j=b===void 0||b,M=v(hO),{conversationId:N}=u(),P=N&&N!==`new`?decodeURIComponent(N):null,F;t[0]!==l||t[1]!==P?(F=l?.trim()||P,t[0]=l,t[1]=P,t[2]=F):F=t[2];let I=F,{data:L,error:R,mutate:B}=Df(I??null,!1),ee=!R&&(!L||!!L.environment?.available),V;t[3]===I?V=t[4]:(V=e=>e.panes[I??`new`]?.open===!0,t[3]=I,t[4]=V);let H=yi(V),U;t[5]===M?U=t[6]:(U=S(M),t[5]=M,t[6]=U);let W=U,te=zf(gO),ne=zw(_O),re=Qo(vO),ie=Qo(yO),[ae,oe]=(0,Q.useState)(!1),se=(0,Q.useRef)(!1),[ce,le]=(0,Q.useState)(!1),ue=Bf(bO),de=Ea(xO),G=Ea(SO),K=window.electronAPI?.platform,fe=!!(j&&window.electronAPI?.terminal&&(I||_)),q;t[7]!==I||t[8]!==ie||t[9]!==_||t[10]!==fe||t[11]!==A||t[12]!==ce||t[13]!==re?(q=()=>{if(!(!fe||A||ce)){if(I){re(I);return}_&&(le(!0),_().then(e=>{e&&ie(e)}).finally(()=>le(!1)))}},t[7]=I,t[8]=ie,t[9]=_,t[10]=fe,t[11]=A,t[12]=ce,t[13]=re,t[14]=q):q=t[14];let pe=q,me;t[15]!==I||t[16]!==E||t[17]!==ne?(me=()=>{if(!I||!E)return;let e=yi.getState().panes[I],t=zw.getState().pendingCreate?.parentConversationId===I||!!zw.getState().creatingRequests[I],n=e?.open===!0&&(e.activeId?.startsWith(`side:`)===!0||t);ne(I,!n)},t[15]=I,t[16]=E,t[17]=ne,t[18]=me):me=t[18];let he=me,ge=rs(pO),_e;t[19]!==ue||t[20]!==te?(_e=jf({runtime:Af(),sidebarCollapsed:te,mobileNavOpen:ue}),t[19]=ue,t[20]=te,t[21]=_e):_e=t[21];let ve=ge?!ue:_e.collapsedNewChatVisible,ye,be;t[22]!==G||t[23]!==T?(ye=()=>{if(!T)return()=>G()},be=[G,T],t[22]=G,t[23]=T,t[24]=ye,t[25]=be):(ye=t[24],be=t[25]),(0,Q.useLayoutEffect)(ye,be);let xe,Se;t[26]!==pe||t[27]!==fe?(xe=()=>{if(!fe)return;let e=e=>{cO(e,K)&&(e.preventDefault(),pe())};return window.addEventListener(`keydown`,e),window.addEventListener(`workspace-open-terminal`,pe),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`workspace-open-terminal`,pe)}},Se=[pe,fe,K],t[26]=pe,t[27]=fe,t[28]=xe,t[29]=Se):(xe=t[28],Se=t[29]),(0,Q.useEffect)(xe,Se);let we,Te;t[30]!==I||t[31]!==he||t[32]!==E?(we=()=>{if(!I||!E)return;let e=e=>{ds(e,K)&&(e.preventDefault(),he())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},Te=[I,he,E,K],t[30]=I,t[31]=he,t[32]=E,t[33]=we,t[34]=Te):(we=t[33],Te=t[34]),(0,Q.useEffect)(we,Te);let Ee;t[35]!==o||t[36]!==W.sidebar.newTask||t[37]!==C||t[38]!==ve||t[39]!==D?(Ee=ve?(0,Z.jsx)(J,{to:Ra(C),state:{forceNewChat:!0,agentId:o,temporary:D===`temporary`},className:Y(`inline-flex size-8 shrink-0 items-center justify-center rounded-lg bg-surface-panel text-sm font-medium leading-none text-fg transition-colors hover:bg-surface-hover`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,xa),title:W.sidebar.newTask,children:(0,Z.jsx)(Nt,{className:`size-4 shrink-0 text-accent-fg`,strokeWidth:2,"aria-hidden":!0})}):null,t[35]=o,t[36]=W.sidebar.newTask,t[37]=C,t[38]=ve,t[39]=D,t[40]=Ee):Ee=t[40];let De=ve?`text-left md:text-center`:`text-left`,Oe;t[41]===De?Oe=t[42]:(Oe=Y(`min-w-0 flex-1 truncate text-[0.9375rem] font-semibold leading-5 tracking-tight text-fg`,De),t[41]=De,t[42]=Oe);let ke;t[43]!==r||t[44]!==Oe?(ke=(0,Z.jsx)(`div`,{className:`flex w-full min-w-0 max-w-(--max-width-chat-frame) items-center gap-3 px-3 sm:px-5 xl:px-6`,children:(0,Z.jsx)(`h1`,{className:Oe,title:r,children:r})}),t[43]=r,t[44]=Oe,t[45]=ke):ke=t[45];let Ae;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(Ae=Y(`flex min-w-0 max-w-[min(32rem,calc(100vw-8rem))] shrink-0 items-center justify-end gap-2`,xa),t[46]=Ae):Ae=t[46];let je;t[47]!==c||t[48]!==o||t[49]!==i||t[50]!==W.chat.agentNoMatches||t[51]!==W.chat.agentPlaceholder||t[52]!==W.chat.agentSearchPlaceholder||t[53]!==s||t[54]!==a?(je=a?(0,Z.jsx)(FD,{items:i,value:o,disabled:c,placeholder:W.chat.agentPlaceholder,searchPlaceholder:W.chat.agentSearchPlaceholder,noMatches:W.chat.agentNoMatches,compact:!0,contentSide:`bottom`,contentAlign:`end`,onChange:s}):null,t[47]=c,t[48]=o,t[49]=i,t[50]=W.chat.agentNoMatches,t[51]=W.chat.agentPlaceholder,t[52]=W.chat.agentSearchPlaceholder,t[53]=s,t[54]=a,t[55]=je):je=t[55];let Me=M===`zh`?`聊天菜单`:`Chat menu`,Ne=M===`zh`?`聊天菜单`:`Chat menu`,Pe;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=(0,Z.jsx)(Ce,{className:`size-4`,"aria-hidden":!0}),t[56]=Pe):Pe=t[56];let Fe;t[57]!==Me||t[58]!==Ne?(Fe=(0,Z.jsx)(_o,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"data-chat-menu-trigger":!0,"aria-label":Me,title:Ne,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-colors hover:bg-surface-hover data-[state=open]:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:Pe})}),t[57]=Me,t[58]=Ne,t[59]=Fe):Fe=t[59];let Ie;t[60]===x?Ie=t[61]:(Ie=e=>{se.current&&(e.preventDefault(),se.current=!1,document.querySelector(`[data-chat-menu-trigger]`)?.focus(),x?.())},t[60]=x,t[61]=Ie);let Le=!E||!x,Re;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(Re=()=>{se.current=!0},t[62]=Re):Re=t[62];let ze;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(ze=(0,Z.jsx)(Lt,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),t[63]=ze):ze=t[63];let Be;t[64]===W.chat.find.input?Be=t[65]:(Be=(0,Z.jsx)(`span`,{className:`flex-1`,children:W.chat.find.input}),t[64]=W.chat.find.input,t[65]=Be);let Ve;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(Ve=(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:K===`darwin`?`⌘F`:`Ctrl+F`}),t[66]=Ve):Ve=t[66];let He;t[67]!==Le||t[68]!==Be?(He=(0,Z.jsxs)(yo,{disabled:Le,onSelect:Re,className:`flex cursor-default items-center gap-3 rounded-lg px-3 py-2 text-fg outline-none data-[highlighted]:bg-surface-hover data-[disabled]:opacity-40`,children:[ze,Be,Ve]}),t[67]=Le,t[68]=Be,t[69]=He):He=t[69];let Ue=!I||!E,We;t[70]===Symbol.for(`react.memo_cache_sentinel`)?(We=()=>oe(!0),t[70]=We):We=t[70];let Ge;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=(0,Z.jsx)(z,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),t[71]=Ge):Ge=t[71];let Ke=M===`zh`?`分享对话`:`Share conversation`,qe;t[72]===Ke?qe=t[73]:(qe=(0,Z.jsx)(`span`,{children:Ke}),t[72]=Ke,t[73]=qe);let Je;t[74]!==Ue||t[75]!==qe?(Je=(0,Z.jsxs)(yo,{disabled:Ue,onSelect:We,className:`flex cursor-default items-center gap-3 rounded-lg px-3 py-2 text-fg outline-none data-[highlighted]:bg-surface-hover data-[disabled]:opacity-40`,children:[Ge,qe]}),t[74]=Ue,t[75]=qe,t[76]=Je):Je=t[76];let Ye;t[77]!==Ie||t[78]!==He||t[79]!==Je?(Ye=(0,Z.jsx)(vo,{children:(0,Z.jsxs)(bo,{onCloseAutoFocus:Ie,align:`end`,sideOffset:8,className:`workspace-menu z-[125] min-w-60 rounded-xl border border-edge bg-surface-overlay p-1.5 text-sm shadow-popover outline-none`,children:[He,Je]})}),t[77]=Ie,t[78]=He,t[79]=Je,t[80]=Ye):Ye=t[80];let Xe;t[81]!==Fe||t[82]!==Ye?(Xe=(0,Z.jsxs)(go,{modal:!1,children:[Fe,Ye]}),t[81]=Fe,t[82]=Ye,t[83]=Xe):Xe=t[83];let Ze;t[84]!==I||t[85]!==E||t[86]!==ae?(Ze=I&&E?(0,Z.jsx)(lO,{conversationId:I,hideTrigger:!0,dialogOpen:ae,onDialogOpenChange:oe},`share:${I}`):null,t[84]=I,t[85]=E,t[86]=ae,t[87]=Ze):Ze=t[87];let Qe;t[88]!==I||t[89]!==O||t[90]!==c||t[91]!==o||t[92]!==w||t[93]!==g||t[94]!==B||t[95]!==j||t[96]!==D||t[97]!==ee||t[98]!==k||t[99]!==f?(Qe=j?(0,Z.jsx)(HD,{...w,agentId:o,executionDeviceAction:I?(0,Z.jsx)($D,{conversationId:I,disabled:c}):null,environmentAction:O&&g?(0,Z.jsx)(rO,{directoryOnly:!0,conversationId:I,workspacePath:I?f:w?.project?.workspaceRoot,available:ee,canChangeWorkspace:!0,disabled:k,onWorkspaceChange:async e=>{await g(e),await B()}}):null,temporary:D===`temporary`,conversationId:I??null},`context:${I??w?.project?.id??`new`}`):null,t[88]=I,t[89]=O,t[90]=c,t[91]=o,t[92]=w,t[93]=g,t[94]=B,t[95]=j,t[96]=D,t[97]=ee,t[98]=k,t[99]=f,t[100]=Qe):Qe=t[100];let $e;t[101]!==j||t[102]!==H?($e=j&&!H?(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`mx-0.5 h-6 w-px shrink-0 bg-edge-subtle`}):null,t[101]=j,t[102]=H,t[103]=$e):$e=t[103];let et;t[104]===I?et=t[105]:(et=I?(0,Z.jsx)(YD,{conversationId:I},I):null,t[104]=I,t[105]=et);let tt;t[106]===I?tt=t[107]:(tt=I?(0,Z.jsx)(eO,{conversationId:I}):null,t[106]=I,t[107]=tt);let nt;t[108]!==I||t[109]!==w?.project?.workspaceRoot||t[110]!==g||t[111]!==C||t[112]!==B||t[113]!==j||t[114]!==ee||t[115]!==k||t[116]!==H||t[117]!==f?(nt=j&&!H?(0,Z.jsx)(rO,{conversationId:I,workspacePath:I?f:w?.project?.workspaceRoot,available:ee,canChangeWorkspace:!1,disabled:k,onWorkspaceChange:async e=>{await g?.(e),await B()}},`workspace:${I??C}`):null,t[108]=I,t[109]=w?.project?.workspaceRoot,t[110]=g,t[111]=C,t[112]=B,t[113]=j,t[114]=ee,t[115]=k,t[116]=H,t[117]=f,t[118]=nt):nt=t[118];let rt;t[119]!==je||t[120]!==Xe||t[121]!==Ze||t[122]!==Qe||t[123]!==$e||t[124]!==et||t[125]!==tt||t[126]!==nt?(rt=(0,Z.jsxs)(`div`,{className:Ae,children:[je,Xe,Ze,Qe,$e,et,tt,nt]}),t[119]=je,t[120]=Xe,t[121]=Ze,t[122]=Qe,t[123]=$e,t[124]=et,t[125]=tt,t[126]=nt,t[127]=rt):rt=t[127];let it;t[128]!==Ee||t[129]!==ke||t[130]!==rt?(it={className:`bg-surface-panel`,startExtra:Ee,main:ke,end:rt},t[128]=Ee,t[129]=ke,t[130]=rt,t[131]=it):it=t[131];let at=it,ot,st;t[132]!==at||t[133]!==T||t[134]!==de?(ot=()=>{T||de(at)},st=[at,T,de],t[132]=at,t[133]=T,t[134]=de,t[135]=ot,t[136]=st):(ot=t[135],st=t[136]),(0,Q.useLayoutEffect)(ot,st);let ct;return t[137]!==at||t[138]!==T||t[139]!==M?(ct=T?(0,Z.jsxs)(`header`,{"aria-label":M===`zh`?`聊天工具栏`:`Chat toolbar`,className:`flex min-h-14 shrink-0 items-center justify-between gap-2 border-b border-edge-subtle px-3 py-2`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:at.main}),at.end]}):null,t[137]=at,t[138]=T,t[139]=M,t[140]=ct):ct=t[140],ct});function hO(e){return e.language}function gO(e){return e.collapsed}function _O(e){return e.setOpen}function vO(e){return e.toggle}function yO(e){return e.open}function bO(e){return e.mobileNavOpen}function xO(e){return e.setPageHeader}function SO(e){return e.clearPageHeader}var CO=(0,Q.memo)(function(){let e=(0,X.c)(19),t=v(wO),n;e[0]===t?n=e[1]:(n=S(t),e[0]=t,e[1]=n);let r=n.chat.runRecovery,i=mi(TO),a=mi(EO),[o,s]=(0,Q.useState)(!1),c=i===`connecting`||i===`reconnecting`,l,u;if(e[2]===c?(l=e[3],u=e[4]):(l=()=>{if(!c)return;let e=window.setTimeout(()=>s(!0),1500);return()=>{window.clearTimeout(e),s(!1)}},u=[c],e[2]=c,e[3]=l,e[4]=u),(0,Q.useEffect)(l,u),i!==`error`&&!(c&&o))return null;let d=i===`error`,f=d?Kt:Pt,p=`size-3.5 shrink-0 ${c?`motion-safe:animate-spin`:``}`,m;e[5]!==f||e[6]!==p?(m=(0,Z.jsx)(f,{className:p,"aria-hidden":!0}),e[5]=f,e[6]=p,e[7]=m):m=e[7];let h=d?r.connectionFailed:i===`connecting`?r.connecting:r.reconnecting,g;e[8]===h?g=e[9]:(g=(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:h}),e[8]=h,e[9]=g);let _;e[10]!==a||e[11]!==d||e[12]!==r.details||e[13]!==r.reconnect?(_=d?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,className:`min-h-9 rounded-md border border-edge px-3 text-xs text-fg hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:DO,children:r.reconnect}),a?(0,Z.jsxs)(`details`,{className:`w-full min-w-0`,children:[(0,Z.jsx)(`summary`,{className:`w-fit cursor-pointer rounded-md py-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:r.details}),(0,Z.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words rounded-md bg-surface-inset p-2`,children:Yn(a)})]}):null]}):null,e[10]=a,e[11]=d,e[12]=r.details,e[13]=r.reconnect,e[14]=_):_=e[14];let y;return e[15]!==m||e[16]!==g||e[17]!==_?(y=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex flex-wrap items-center gap-2 border-b border-edge-subtle bg-surface-panel px-4 py-2 text-xs text-fg-muted`,children:[m,g,_]}),e[15]=m,e[16]=g,e[17]=_,e[18]=y):y=e[18],y});function wO(e){return e.language}function TO(e){return e.connectionState}function EO(e){return e.error}function DO(){return pi()}function OO(e,t){return Object.entries(t).reduce((e,[t,n])=>e.replaceAll(`{{${t}}}`,String(n)),e)}function kO(e){let t=(0,X.c)(4),{status:n}=e;if(n===`completed`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(`span`,{className:`mt-0.5 inline-flex size-4 shrink-0 items-center justify-center rounded-full bg-fg-muted text-surface-panel`,children:(0,Z.jsx)(re,{className:`size-3`,strokeWidth:2.5,"aria-hidden":!0})}),t[0]=e):e=t[0],e}if(n===`in_progress`){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(pe,{className:`mt-0.5 size-4 shrink-0 text-accent`,strokeWidth:2,"aria-hidden":!0}),t[1]=e):e=t[1],e}if(n===`cancelled`){let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(ps,{className:`mt-0.5 size-4 shrink-0 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),t[2]=e):e=t[2],e}let r;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Z.jsx)(ge,{className:`mt-0.5 size-4 shrink-0 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[3]=r):r=t[3],r}function AO(e,t){return e?`${OO(e.files.length===1?t.filesChangedOne:t.filesChangedOther,{count:e.files.length})} · +${e.added} -${e.removed}`:null}function jO(e){let t=(0,X.c)(61),{plan:n,changeSummary:r,isStreaming:i,labels:a}=e,o=n.currentIndex==null?void 0:n.items[n.currentIndex-1],s;t[0]===n.items?s=t[1]:(s=n.items.every(PO),t[0]=n.items,t[1]=s);let c=s,l=n.items.every(NO),u;t[2]!==a.completedProgress||t[3]!==n.completedCount||t[4]!==n.totalCount?(u=OO(a.completedProgress,{completed:n.completedCount,total:n.totalCount}),t[2]=a.completedProgress,t[3]=n.completedCount,t[4]=n.totalCount,t[5]=u):u=t[5];let d=u,f=a.ended;if(c)f=a.finished;else if(o){let e=n.currentIndex??1,r;t[6]!==a.stepProgress||t[7]!==n.totalCount||t[8]!==e?(r=OO(a.stepProgress,{current:e,total:n.totalCount}),t[6]=a.stepProgress,t[7]=n.totalCount,t[8]=e,t[9]=r):r=t[9],f=r}else!l&&i&&(f=a.planned);let p;t[10]!==r||t[11]!==a?(p=AO(r,a),t[10]=r,t[11]=a,t[12]=p):p=t[12];let m=p,h=o?.title,g;t[13]!==m||t[14]!==f||t[15]!==h?(g=[f,h,m].filter(Boolean),t[13]=m,t[14]=f,t[15]=h,t[16]=g):g=t[16];let _=g.join(` · `),v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(v=Y(`inline-flex min-h-9 min-w-0 max-w-full items-center gap-2 rounded-pill border border-edge-subtle bg-surface-overlay px-3 py-1.5 text-sm text-fg shadow-surface`,ca.transition,`hover:border-edge hover:text-accent-fg`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`),t[17]=v):v=t[17];let y=`${a.heading}: ${_}`,b;t[18]!==o||t[19]!==c?(b=c?(0,Z.jsx)(re,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:2,"aria-hidden":!0}):o?(0,Z.jsx)(pe,{className:`size-4 shrink-0 text-accent`,strokeWidth:2,"aria-hidden":!0}):(0,Z.jsx)(Ye,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[18]=o,t[19]=c,t[20]=b):b=t[20];let x;t[21]===f?x=t[22]:(x=(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:f}),t[21]=f,t[22]=x);let S;t[23]===o?S=t[24]:(S=o?(0,Z.jsxs)(`span`,{className:`min-w-0 truncate text-fg-muted`,children:[`· `,o.title]}):null,t[23]=o,t[24]=S);let C;t[25]===m?C=t[26]:(C=m?(0,Z.jsxs)(`span`,{className:`hidden shrink-0 tabular-nums text-fg-subtle sm:inline`,children:[`· `,m]}):null,t[25]=m,t[26]=C);let w;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Z.jsx)(ie,{className:`size-3.5 shrink-0 text-fg-subtle`,"aria-hidden":!0}),t[27]=w):w=t[27];let T;t[28]!==S||t[29]!==C||t[30]!==y||t[31]!==b||t[32]!==x?(T=(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:v,"aria-label":y,children:[b,x,S,C,w]})}),t[28]=S,t[29]=C,t[30]=y,t[31]=b,t[32]=x,t[33]=T):T=t[33];let E;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,Z.jsx)(Ye,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[34]=E):E=t[34];let D;t[35]===a.heading?D=t[36]:(D=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[E,(0,Z.jsx)(`span`,{children:a.heading})]}),t[35]=a.heading,t[36]=D);let O;t[37]===n.explanation?O=t[38]:(O=n.explanation?(0,Z.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:n.explanation}):null,t[37]=n.explanation,t[38]=O);let k;t[39]!==D||t[40]!==O?(k=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[D,O]}),t[39]=D,t[40]=O,t[41]=k):k=t[41];let A;t[42]===d?A=t[43]:(A=(0,Z.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-fg-subtle`,children:d}),t[42]=d,t[43]=A);let j;t[44]!==k||t[45]!==A?(j=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge-subtle px-4 py-3`,children:[k,A]}),t[44]=k,t[45]=A,t[46]=j):j=t[46];let M=a.heading,N;t[47]===n.items?N=t[48]:(N=n.items.map(MO),t[47]=n.items,t[48]=N);let P;t[49]!==a.heading||t[50]!==N?(P=(0,Z.jsx)(`ol`,{className:`max-h-[min(22rem,55vh)] overflow-y-auto px-4 py-3`,"aria-label":M,children:N}),t[49]=a.heading,t[50]=N,t[51]=P):P=t[51];let F;t[52]===m?F=t[53]:(F=m?(0,Z.jsx)(`div`,{className:`border-t border-edge-subtle px-4 py-2 text-right text-xs tabular-nums text-fg-subtle`,children:m}):null,t[52]=m,t[53]=F);let I;t[54]!==j||t[55]!==P||t[56]!==F?(I=(0,Z.jsx)(bi,{children:(0,Z.jsxs)(xi,{side:`top`,align:`center`,sideOffset:8,collisionPadding:16,className:`z-[120] w-[min(28rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[j,P,F]})}),t[54]=j,t[55]=P,t[56]=F,t[57]=I):I=t[57];let L;return t[58]!==T||t[59]!==I?(L=(0,Z.jsx)(`div`,{className:`mx-auto flex w-full max-w-80 justify-center pb-2 pt-1`,children:(0,Z.jsxs)(Si,{children:[T,I]})}),t[58]=T,t[59]=I,t[60]=L):L=t[60],L}function MO(e){return(0,Z.jsxs)(`li`,{className:Y(`flex gap-3 py-2 text-sm leading-relaxed text-fg-muted`,e.status===`in_progress`&&`font-medium text-fg`,e.status===`cancelled`&&`text-fg-disabled`),children:[(0,Z.jsx)(kO,{status:e.status}),(0,Z.jsx)(`span`,{className:`min-w-0 [overflow-wrap:anywhere]`,children:e.title})]},e.id)}function NO(e){return e.status===`completed`||e.status===`cancelled`}function PO(e){return e.status===`completed`}function FO(e){let t=VO(e.source,e.explanation,e.items.map(e=>({...e})));return t&&t.items.some(e=>e.status===`pending`||e.status===`in_progress`)?t:null}var IO=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function LO(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function RO(e){return e.trim().toLowerCase().replace(/-/g,`_`).split(`__`).at(-1)??``}function zO(e){let t=LO(e.details);return t&&Object.keys(t).length>0?t:ma(e.result).details}function BO(e){let t=typeof e==`string`?e.trim():``;return IO.has(t)?t:null}function VO(e,t,n){if(n.length===0)return null;let r=n.findIndex(e=>e.status===`in_progress`);return{source:e,explanation:t,items:n,currentIndex:r>=0?r+1:void 0,completedCount:n.filter(e=>e.status===`completed`).length,totalCount:n.length}}function HO(e){if(!Array.isArray(e.plan))return null;let t=e.plan.flatMap((e,t)=>{let n=LO(e),r=typeof n?.id==`string`&&n.id.trim()?n.id.trim():`update-plan-${t}`,i=typeof n?.step==`string`?n.step.trim():``,a=BO(n?.status);return i&&a?[{id:r,title:i,status:a}]:[]});return VO(`update_plan`,typeof e.explanation==`string`&&e.explanation.trim()?e.explanation.trim():void 0,t)}function UO(e){return Array.isArray(e.items)?VO(`todo`,void 0,e.items.flatMap((e,t)=>{let n=LO(e),r=typeof n?.id==`string`&&n.id.trim()?n.id.trim():`todo-${t}`,i=typeof n?.content==`string`?n.content.trim():``,a=BO(n?.status);return i&&a?[{id:r,title:i,status:a}]:[]})):null}function WO(e){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.type!==`tool_use`||n.status===`error`)continue;let r=RO(n.name),i=zO(n);if(i){if(r===`update_plan`)return{found:!0,plan:HO(i)};if(r===`todo`)return{found:!0,plan:UO(i)}}}return{found:!1,plan:null}}function GO(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:0}function KO(e){let t=new Set,n=0,r=0;for(let i of e){if(i.type!==`tool_use`||i.status===`error`||RO(i.name)!==`apply_patch`)continue;let e=zO(i);if(e){if(Array.isArray(e.files))for(let n of e.files)typeof n==`string`&&n.trim()&&t.add(n.trim());if(t.size===0&&Array.isArray(e.changes))for(let n of e.changes){let e=LO(n),r=typeof e?.moveTo==`string`?e.moveTo:typeof e?.path==`string`?e.path:``;r.trim()&&t.add(r.trim())}n+=GO(e.added),r+=GO(e.removed)}}return t.size>0||n>0||r>0?{files:[...t],added:n,removed:r}:null}function qO(e){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`assistant`)continue;let r=WO(n.content??[]);if(!r.found)continue;if(!r.plan||!r.plan.items.some(e=>e.status===`pending`||e.status===`in_progress`))return null;let i=e.slice(t).flatMap(e=>e.role===`assistant`?e.content??[]:[]);return{plan:r.plan,changeSummary:KO(i)}}return null}function JO(e,t){if(!t)return null;let n=-1;for(let t=e.length-1;t>=0;--t)if(e[t]?.role===`user`){n=t;break}return qO(e.slice(n+1))}function YO(e,t){return e.bottom>t.top&&e.top<t.bottom&&e.right>t.left&&e.left<t.right}function XO(e,t,n){let r=n.getBoundingClientRect(),i=t.getBoundingClientRect();if(!YO(e,{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight})||!YO(i,r)||typeof t.animate!=`function`)return()=>{};let a=t.closest(`article`);a&&(a.style.animation=`none`);let o=t.getBoundingClientRect(),s=e.left-o.left,c=e.top-o.top,l;try{l=t.animate([{transform:`translate3d(${s}px, ${c}px, 0)`},{transform:`translate3d(0, 0, 0)`}],{duration:360,easing:`cubic-bezier(0.25, 0.1, 0.25, 1)`})}catch{return()=>{}}let u=!1,d,f=()=>{u||(u=!0,d!==void 0&&window.clearTimeout(d),n.removeEventListener(`scroll`,p),n.removeEventListener(`wheel`,f),n.removeEventListener(`touchstart`,f),window.removeEventListener(`resize`,f),l.cancel())},p=()=>{let e=t.closest(`[data-chat-message-row]`);(!t.isConnected||e&&!YO(e.getBoundingClientRect(),n.getBoundingClientRect()))&&f()};return n.addEventListener(`scroll`,p,{passive:!0}),n.addEventListener(`wheel`,f,{passive:!0}),n.addEventListener(`touchstart`,f,{passive:!0}),window.addEventListener(`resize`,f),d=window.setTimeout(f,510),l.finished.then(f,f),f}function ZO(e){let t=(0,X.c)(13),{enabled:n,conversationId:r,messages:i,viewportRef:a}=e,o=(0,Q.useRef)(null),s=(0,Q.useRef)(null),c=(0,Q.useRef)(r),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{o.current&&window.clearTimeout(o.current.timeout),o.current=null,s.current?.(),s.current=null},t[0]=l):l=t[0];let u=l,d;t[1]===n?d=t[2]:(d=(e,t,r)=>{if(u(),!n||r.attachments.length>0||r.contextRefs.length>0||!r.text.trim()||document.visibilityState===`hidden`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let i={id:e.clientSubmissionId,source:{left:t.left,top:t.top,right:t.right,bottom:t.bottom},timeout:window.setTimeout(()=>{o.current===i&&(o.current=null)},500)};o.current=i},t[1]=n,t[2]=d);let f=d,p,m;t[3]===r?(p=t[4],m=t[5]):(p=()=>{let e=c.current;c.current=r,e!==null&&e!==r&&u()},m=[u,r],t[3]=r,t[4]=p,t[5]=m),(0,Q.useLayoutEffect)(p,m);let h,g;t[6]!==i||t[7]!==a?(h=()=>{let e=o.current,t=a.current;if(!e||!t||!i.some(t=>t.clientSubmissionId===e.id))return;window.clearTimeout(e.timeout),o.current=null;let n=t.querySelector(`[data-client-submission-id="${e.id}"]`)?.querySelector(`.chat-user-message`);n&&(s.current=XO(e.source,n,t))},g=[i,a],t[6]=i,t[7]=a,t[8]=h,t[9]=g):(h=t[8],g=t[9]),(0,Q.useLayoutEffect)(h,g);let _;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>u,t[10]=_):_=t[10];let v;return t[11]===n?v=t[12]:(v=[u,n],t[11]=n,t[12]=v),(0,Q.useEffect)(_,v),f}function QO(e){let t=(0,X.c)(61),{open:n,query:r,activeIndex:i,resultCount:a,searching:o,truncated:s,limitedToLoaded:c,inputRef:l,labels:u,onQueryChange:d,onPrevious:f,onNext:p,onClose:m}=e,h=o!==void 0&&o,g=s!==void 0&&s,_=c!==void 0&&c;if(!n)return null;let v;t[0]===r?v=t[1]:(v=r.trim(),t[0]=r,t[1]=v);let y=!!v,b;t[2]!==i||t[3]!==y||t[4]!==u.noResults||t[5]!==u.resultCount||t[6]!==u.searching||t[7]!==a||t[8]!==h||t[9]!==g?(b=h?u.searching:y&&a===0?u.noResults:y?u.resultCount.replace(`{{current}}`,String(i+1)).replace(`{{total}}`,`${a}${g?`+`:``}`):``,t[2]=i,t[3]=y,t[4]=u.noResults,t[5]=u.resultCount,t[6]=u.searching,t[7]=a,t[8]=h,t[9]=g,t[10]=b):b=t[10];let x=b,S;t[11]!==x||t[12]!==y||t[13]!==u.loadedOnly||t[14]!==_?(S=_&&y?[x,u.loadedOnly].filter(Boolean).join(` · `):x,t[11]=x,t[12]=y,t[13]=u.loadedOnly,t[14]=_,t[15]=S):S=t[15];let C=S,w=h||a===0,T=u.input,E;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,Z.jsx)(Lt,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[16]=E):E=t[16];let D;t[17]===d?D=t[18]:(D=e=>d(e.target.value),t[17]=d,t[18]=D);let O;t[19]!==p||t[20]!==f?(O=e=>{e.nativeEvent.isComposing||e.key===`Enter`&&(e.preventDefault(),e.shiftKey?f():p())},t[19]=p,t[20]=f,t[21]=O):O=t[21];let k;t[22]!==l||t[23]!==u.input||t[24]!==r||t[25]!==O||t[26]!==D?(k=(0,Z.jsx)(`input`,{ref:l,value:r,type:`search`,autoComplete:`off`,spellCheck:!1,"aria-label":u.input,className:`h-12 min-w-0 flex-1 bg-transparent text-base text-fg outline-none placeholder:text-fg-subtle`,placeholder:u.input,onChange:D,onKeyDown:O}),t[22]=l,t[23]=u.input,t[24]=r,t[25]=O,t[26]=D,t[27]=k):k=t[27];let A;t[28]===h?A=t[29]:(A=h?(0,Z.jsx)(Ze,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null,t[28]=h,t[29]=A);let j;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(j=Y(`inline-flex size-11 shrink-0 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,ca.focusRingPanel,ca.press),t[30]=j):j=t[30];let M;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Z.jsx)(Xt,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[31]=M):M=t[31];let N;t[32]!==u.close||t[33]!==m?(N=(0,Z.jsx)(`button`,{type:`button`,onClick:m,className:j,"aria-label":u.close,children:M}),t[32]=u.close,t[33]=m,t[34]=N):N=t[34];let P;t[35]!==k||t[36]!==A||t[37]!==N?(P=(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 px-3`,children:[E,k,A,N]}),t[35]=k,t[36]=A,t[37]=N,t[38]=P):P=t[38];let F;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(F=Y(`inline-flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,ca.focusRingPanel,ca.press,ca.disabled),t[39]=F):F=t[39];let I;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,Z.jsx)(oe,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[40]=I):I=t[40];let L;t[41]!==u.previous||t[42]!==w||t[43]!==f?(L=(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:f,className:F,"aria-label":u.previous,children:I}),t[41]=u.previous,t[42]=w,t[43]=f,t[44]=L):L=t[44];let R;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(R=Y(`inline-flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,ca.focusRingPanel,ca.press,ca.disabled),t[45]=R):R=t[45];let z;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,Z.jsx)(ie,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[46]=z):z=t[46];let B;t[47]!==u.next||t[48]!==w||t[49]!==p?(B=(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:p,className:R,"aria-label":u.next,children:z}),t[47]=u.next,t[48]=w,t[49]=p,t[50]=B):B=t[50];let ee;t[51]===C?ee=t[52]:(ee=(0,Z.jsx)(`span`,{className:`ml-auto px-2 text-sm tabular-nums text-fg-muted`,"aria-live":`polite`,"aria-atomic":`true`,children:C}),t[51]=C,t[52]=ee);let V;t[53]!==L||t[54]!==B||t[55]!==ee?(V=(0,Z.jsxs)(`div`,{className:`flex h-11 items-center border-t border-edge-subtle px-1.5`,children:[L,B,ee]}),t[53]=L,t[54]=B,t[55]=ee,t[56]=V):V=t[56];let H;return t[57]!==u.input||t[58]!==P||t[59]!==V?(H=(0,Z.jsxs)(`section`,{"data-chat-find-bar":!0,role:`search`,"aria-label":T,className:`absolute right-3 top-3 z-30 w-[min(25rem,calc(100%-1.5rem))] overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover`,children:[P,V]}),t[57]=u.input,t[58]=P,t[59]=V,t[60]=H):H=t[60],H}async function $O(e,t,n={}){let r=await h(g(`${n.taskId?`/api/tasks/${encodeURIComponent(n.taskId)}/conversation/find`:`/api/sessions/${encodeURIComponent(e)}/find`}?${new URLSearchParams({q:t,limit:`1000`})}`),{signal:n.signal});if(!r.ok)throw Error(`HTTP ${r.status}: ${r.statusText}`);let i=await r.json();if(i.ok!==!0||!Array.isArray(i.matches)||typeof i.total!=`number`)throw Error(`Invalid chat find response`);return{query:typeof i.query==`string`?i.query:t,total:i.total,truncated:i.truncated===!0,matches:i.matches.filter(e=>Number.isInteger(e?.displayIndex)&&e.displayIndex>=0&&Number.isInteger(e?.occurrence)&&e.occurrence>=0)}}var ek=`chat-find-match`,tk=`chat-find-active`,nk=`chat-find-highlight-styles`;function rk(){let e=globalThis.CSS,t=globalThis.Highlight;return!e?.highlights||!t?null:{registry:e.highlights,Highlight:t}}function ik(){if(document.getElementById(nk))return;let e=document.createElement(`style`);e.id=nk,e.textContent=`
61
- ::highlight(${ek}) {
60
+ `);if((i.content.some(e=>e.type!==`text`)||i.attachments?.length)&&(n=!0),!e)continue;if(t<=256){n=!0;continue}let a=Ow.encode(e),o=a.byteLength+256>t?new TextDecoder().decode(a.subarray(0,t-256),{stream:!0}):e;o!==e&&(n=!0);let s=kw(o)+256;t-=s,r.unshift({role:i.role,content:[{type:`text`,text:o}],timestamp:i.timestamp,renderKey:i.renderKey?.slice(0,128)})}return{messages:r,truncated:n,bytes:512*1024-t}}var Mw=`xopc:side-chat-panes:v3`,Nw={text:``,attachments:[]};function Pw(e){return Math.min(760,Math.max(360,Math.round(e)))}function Fw(){return{panes:{},tabs:[],widthPx:520}}function Iw(){try{let e=JSON.parse(sessionStorage.getItem(Mw)||`{}`),t=e.identity;if(t&&t!==_.getState().conversationId)return Fw();let n=Array.isArray(e.tabs)?e.tabs.filter(e=>!!(e?.id&&e.parentConversationId)):[],r=e.panes&&typeof e.panes==`object`?e.panes:{},i=Object.fromEntries(Object.entries(r).map(([e,t])=>{let r=n.filter(t=>t.parentConversationId===e),i=typeof t?.activeId==`string`&&r.some(e=>e.id===t.activeId)?t.activeId:r.at(-1)?.id??null;return[e,{open:t?.open===!0&&r.length>0,activeId:i}]}));for(let e of n)i[e.parentConversationId]??={open:!1,activeId:e.id};return{panes:i,tabs:n,widthPx:Pw(typeof e.widthPx==`number`?e.widthPx:520)}}catch{return Fw()}}function Lw(e){try{sessionStorage.setItem(Mw,JSON.stringify({...e,identity:_.getState().conversationId}))}catch{}}var Rw=Iw(),zw=b((e,t)=>{let n=n=>{e(n),queueMicrotask(()=>{let e=t();Lw({panes:e.panes,tabs:e.tabs,widthPx:e.widthPx})})},r=(e,r)=>{let i=t().panes[e]??{open:!1,activeId:null};n({panes:{...t().panes,[e]:{...i,...r}}})};return{...Rw,drafts:{},readings:{},setDraftText:(n,r)=>e({drafts:{...t().drafts,[n]:{...t().drafts[n]??Nw,text:r}}}),setDraftAttachments:(n,r)=>e({drafts:{...t().drafts,[n]:{...t().drafts[n]??Nw,attachments:r}}}),rememberMessages:(n,r)=>{let i={...t().readings};delete i[n],i[n]=jw(r),i[n].truncated||=t().readings[n]?.truncated??!1;let a=Object.values(i).reduce((e,t)=>e+t.bytes,0);for(;Object.keys(i).length>5||a>2097152;){let e=Object.keys(i)[0];a-=i[e].bytes,delete i[e]}e({readings:i})},markEnded:(e,r)=>n({tabs:t().tabs.map(t=>t.id===e?{...t,ended:r,runId:void 0}:t)}),markPromoted:(e,r)=>n({tabs:t().tabs.map(t=>t.id===e?{...t,ended:`promoted`,promotedConversationId:r,runId:void 0}:t)}),replaceTab:(r,i)=>{yi.getState().replaceSideChat(r,i.id,i.parentConversationId);let a=t();if(!a.tabs.some(e=>e.id===r))return;let o={...a.drafts,[i.id]:a.drafts[r]??Nw},s={...a.readings};delete o[r],delete s[r],e({drafts:o,readings:s}),n({tabs:a.tabs.map(e=>e.id===r?{...i,fresh:!0}:e),panes:{...a.panes,[i.parentConversationId]:{open:a.panes[i.parentConversationId]?.open??!1,activeId:a.panes[i.parentConversationId]?.activeId===r?i.id:a.panes[i.parentConversationId]?.activeId??i.id}}})},reset:()=>{yi.getState().reset(),e({drafts:{},readings:{},pendingCreate:null,creatingRequests:{}}),n({panes:{},tabs:[]})},pendingCreate:null,creatingRequests:{},requestCreate:(n,i=[])=>{yi.getState().setOpen(!0,n),!(t().creatingRequests[n]||t().pendingCreate?.parentConversationId===n)&&(e({pendingCreate:{requestId:crypto.randomUUID(),parentConversationId:n,selections:i}}),r(n,{open:!0}))},claimPendingCreate:(n,r)=>{let i=t().pendingCreate;return!i||i.parentConversationId!==n||i.requestId!==r?null:(e({pendingCreate:null,creatingRequests:{...t().creatingRequests,[n]:r}}),i)},finishCreate:(n,r)=>{if(t().creatingRequests[n]!==r)return;let i={...t().creatingRequests};delete i[n],e({creatingRequests:i})},addTab:(e,r=!0)=>{yi.getState().addSideChat(e.id,e.title,e.parentConversationId,r);let i=[...t().tabs.filter(t=>t.id!==e.id),{...e,lastSelectedAt:Date.now()}],a=t().panes[e.parentConversationId]??{open:!1,activeId:null};n({tabs:i,panes:{...t().panes,[e.parentConversationId]:{...a,activeId:e.id,open:!0}}})},removeTab:r=>{let i=t().tabs.find(e=>e.id===r);if(!i)return;yi.getState().remove(`side:${r}`,i.parentConversationId);let a={...t().drafts},o={...t().readings};delete a[r],delete o[r],e({drafts:a,readings:o});let s=t().tabs.filter(e=>e.id!==r),c=s.filter(e=>e.parentConversationId===i.parentConversationId),l=t().panes[i.parentConversationId]??{open:!1,activeId:null},u=l.activeId===r?c.at(-1)?.id??null:l.activeId;n({tabs:s,panes:{...t().panes,[i.parentConversationId]:{open:c.length>0&&l.open,activeId:u}}})},setActive:e=>{let i=t().tabs.find(t=>t.id===e);i&&(yi.getState().activate(`side:${e}`,i.parentConversationId),n({tabs:t().tabs.map(t=>t.id===e?{...t,lastSelectedAt:Date.now()}:t)}),r(i.parentConversationId,{activeId:e,open:!0}))},setTabStatus:(n,r)=>{let i=t().tabs.find(e=>e.id===n);i&&(i.waiting!==r.waiting||i.disconnected!==r.disconnected||i.unread!==r.unread)&&e({tabs:t().tabs.map(e=>e.id===n?{...e,...r}:e)})},setTabRunId:(e,r)=>n({tabs:t().tabs.map(t=>t.id===e?{...t,runId:r}:t)}),setOpen:(e,n)=>{if(yi.getState().setOpen(n,e),!n){r(e,{open:n});return}let i=t(),a=i.tabs.filter(t=>t.parentConversationId===e&&!t.ended&&!t.promotedConversationId),o=a.find(t=>t.id===i.panes[e]?.activeId)??a.reduce((e,t)=>!e||(t.lastSelectedAt??0)>=(e.lastSelectedAt??0)?t:e,void 0);r(e,{open:n,activeId:o?.id??null}),o&&yi.getState().activate(`side:${o.id}`,e),o||i.requestCreate(e)},setWidthPx:e=>n({widthPx:Pw(e)})}});_.subscribe((e,t)=>{if(e.conversationId&&!t.conversationId&&e.baseUrl===t.baseUrl){let e=Iw();zw.setState(e)}if(e.baseUrl!==t.baseUrl||t.conversationId!==void 0&&e.conversationId!==t.conversationId){zw.getState().reset();try{sessionStorage.removeItem(`xopc:side-chat-client-id`)}catch{}}});function Bw(e){return e.acceptsArgs?`/${e.name} `:`/${e.name}`}var Vw=3e4,Hw=null;function Uw(e,t){return e.map(e=>({id:`file:${e.id}`,kind:`file`,name:e.name,description:e.path,relativePath:e.path,isDirectory:e.isDirectory,...t.has(e.path)?{isRecent:!0}:{},fileRef:{sourceId:e.id,expectedVersion:e.revision}}))}async function Ww(e,t){let n=t.conversationId?.trim(),r=t.agentId?.trim(),i=t.limit??15,a=e.trim(),o=t.recentPaths??new Set;if(n&&a.length===0){let e=Date.now();if(Hw&&Hw.key===n&&e-Hw.at<Vw)return Hw.items.map(e=>({...e,...o.has(e.relativePath)?{isRecent:!0}:{isRecent:void 0}}))}let s={conversationId:n,agentId:r},c=Uw(a.length===0?await Ya(``,s):await qa(a,s,i),o);return n&&a.length===0&&(Hw={key:n,at:Date.now(),items:c}),c}async function Gw(e,t){return Ya(e,{conversationId:t.conversationId,agentId:t.agentId})}function Kw(e,...t){let n=e.trim().toLocaleLowerCase();return!n||t.some(e=>e?.toLocaleLowerCase().includes(n))}async function qw(e){let t=await h(g(e)),n=await t.json().catch(()=>({}));if(!t.ok||!n.payload)throw Error(typeof n.error==`string`?n.error:`HTTP ${t.status}`);return n.payload}var Jw=[{kind:`file`,search:(e,t)=>Ww(e,{conversationId:t.conversationId,agentId:t.currentAgentId,limit:10,recentPaths:t.recentPaths})},{kind:`note`,async search(e,t){return(await He({...e.trim()?{search:e.trim()}:{},limit:5,sortBy:`updatedAt`,sortOrder:`desc`})).items.filter(e=>e.status!==`trashed`&&!t.selectedContextKeys.has(`note:${e.id}`)).map(e=>({id:`note:${e.id}`,kind:`note`,name:e.title?.trim()||e.snippet?.trim()||S(t.language).chat.commandPalette.untitledNote,description:e.snippet?.trim()||``,noteRef:{sourceId:e.id,expectedVersion:String(e.updatedAt)}}))}},{kind:`session`,async search(e,t){return(await gn({...e.trim()?{search:e.trim()}:{},limit:5,sortBy:`updatedAt`,sortOrder:`desc`})).items.filter(e=>e.key!==t.conversationId&&!t.selectedContextKeys.has(`session:${e.key}`)).map(e=>({id:`session:${e.key}`,kind:`session`,name:e.name?.trim()||e.key,description:`${e.messageCount} messages`,sessionRef:{sourceId:e.key,expectedVersion:e.updatedAt}}))}},{kind:`skill`,async search(e,t){return(await So(t.currentAgentId,t.conversationId)).skills.flatMap(n=>{if(!n.availableForCurrentAgent)return[];let r=Oo(n,t.language);return Kw(e,n.name,r.displayName,r.description,...r.searchTerms)?[{id:`skill:${n.name}`,kind:`skill`,name:r.displayName,description:r.description,canonicalName:n.name}]:[]}).slice(0,5)}},{kind:`agent`,async search(e,t){let n=await si(),r=S(t.language).agentsSettings;return n.items.flatMap(t=>{let n=es(t,r),i=ts(t,r);return Kw(e,t.id,n,i)?[{id:`agent:${t.id}`,kind:`agent`,name:n,description:i,agentId:t.id,...t.avatar?{avatar:t.avatar}:{}}]:[]}).slice(0,5)}},{kind:`browser_tab`,async search(e,t){return(await qw(`/api/browser/tabs?${new URLSearchParams({conversationId:t.conversationId})}`)).tabs.flatMap(n=>!Kw(e,n.title,n.url)||t.selectedContextKeys.has(`browser_tab:${n.id}`)?[]:[{id:`browser-tab:${n.id}`,kind:`browser_tab`,name:n.title||n.url,description:n.url,url:n.url,tabRef:{sourceId:n.id,expectedVersion:n.documentId}}])}}],Yw=(0,Q.createContext)({target:null,register:()=>()=>{}});function Xw(e){let t=(0,X.c)(9),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0];let[i,a]=(0,Q.useState)(r),o;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(o=e=>(a(t=>[...t,e]),()=>a(t=>t.filter(t=>t!==e))),t[1]=o):o=t[1];let s=o,c;t[2]===i?c=t[3]:(c=i.at(-1)??null,t[2]=i,t[3]=c);let l;t[4]===c?l=t[5]:(l={target:c,register:s},t[4]=c,t[5]=l);let u=l,d;return t[6]!==n||t[7]!==u?(d=(0,Z.jsx)(Yw,{value:u,children:n}),t[6]=n,t[7]=u,t[8]=d):d=t[8],d}function Zw(){let e=(0,X.c)(2),{register:t}=(0,Q.useContext)(Yw),n;return e[0]===t?n=e[1]:(n=(0,Z.jsx)(`div`,{ref:t,className:`min-w-0 shrink-0`}),e[0]=t,e[1]=n),n}function Qw(){return(0,Q.useContext)(Yw).target}function $w({conversationId:e,turnId:t,messages:n,ready:r,hasMore:i,loadingMore:a,loadMore:o,reveal:s,onLocated:c}){let l=(0,Q.useRef)({key:``,finished:!1,requestedLength:-1});(0,Q.useEffect)(()=>{let u=`${e??``}:${t??``}`;if(l.current.key!==u&&(l.current={key:u,finished:!1,requestedLength:-1}),!t||!r||l.current.finished)return;let d=l.current,f=n.findIndex(e=>e.turnId===t);if(f>=0){let e=0,t=!1,n=0,r=()=>{t||l.current===d&&(s(f)?(d.finished=!0,c?.(!0)):++n<3?e=requestAnimationFrame(r):(d.finished=!0,c?.(!1)))};return e=requestAnimationFrame(r),()=>{t=!0,cancelAnimationFrame(e)}}if(!a){if(!i||l.current.requestedLength===n.length){l.current.finished=!0,c?.(!1);return}l.current.requestedLength=n.length,o().catch(()=>{l.current===d&&(d.finished=!0,c?.(!1))})}},[e,t,n,r,i,a,o,s,c])}function eT({interaction:e,path:t,complete:n}){let r=v(e=>e.language)===`zh`,[i,a]=(0,Q.useState)(`{}`),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),u=async r=>{s(!0),l(!1);try{let a=r===`accept`?JSON.parse(i):void 0;if(r===`accept`&&(!a||typeof a!=`object`||Array.isArray(a)))throw Error(`Expected an object`);await y(t,{method:`POST`,body:JSON.stringify({requestId:e.requestId,action:r,content:a})}),n()}catch{l(!0)}finally{s(!1)}},d=Object.entries(e.inputSchema.properties??{});return(0,Z.jsxs)(`form`,{className:`space-y-2 rounded-xl border border-edge bg-surface p-3 text-sm`,onSubmit:e=>{e.preventDefault(),u(`accept`)},children:[(0,Z.jsx)(`p`,{className:`font-medium text-fg`,children:r?`设备需要补充信息`:`Device needs input`}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-fg-muted`,children:e.message}),d.length?(0,Z.jsx)(`ul`,{className:`max-h-24 overflow-y-auto text-xs text-fg-muted`,children:d.map(([t,n])=>(0,Z.jsxs)(`li`,{children:[t,n.type?` (${n.type})`:``,e.inputSchema.required?.includes(t)?` *`:``,Array.isArray(n.enum)?` · ${JSON.stringify(n.enum).slice(0,180)}`:``]},t))}):null,(0,Z.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),maxLength:7e3,"aria-label":r?`设备请求参数(JSON)`:`Device response (JSON)`,className:`h-16 w-full resize-none rounded-md border border-edge bg-surface p-2 font-mono text-xs`}),c?(0,Z.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:r?`输入不符合要求,或设备请求已结束。`:`The input is invalid or the device request has ended.`}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(vi,{type:`button`,variant:`secondary`,disabled:o,onClick:()=>void u(`decline`),children:r?`拒绝`:`Decline`}),(0,Z.jsx)(vi,{type:`submit`,disabled:o,children:r?`提交给设备`:`Send to device`})]})]})}function tT(e){let t=(0,X.c)(8),{conversationId:n,active:r}=e,i;t[0]===n?i=t[1]:(i=n?g(`/api/endpoint-tools/interactions/${encodeURIComponent(n)}`):null,t[0]=n,t[1]=i);let a=i,o=r?1500:5e3,s;t[2]===o?s=t[3]:(s={refreshInterval:o,shouldRetryOnError:!1},t[2]=o,t[3]=s);let{data:c,mutate:l}=Qr(a,nT,s),u=c?.payload?.[0],d;return t[4]!==u||t[5]!==l||t[6]!==a?(d=a&&u?(0,Z.jsx)(eT,{interaction:u,path:a,complete:()=>{l()}},u.requestId):null,t[4]=u,t[5]=l,t[6]=a,t[7]=d):d=t[7],d}function nT(e){return y(e)}function rT(e){let t=(0,X.c)(24),{sk:n,onPick:r,disabled:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Ht,{className:`size-4`,"aria-hidden":!0}),t[0]=a):a=t[0];let o;t[1]===n.findCapability?o=t[2]:(o=(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-accent-fg`,children:[a,n.findCapability]}),t[1]=n.findCapability,t[2]=o);let s;t[3]===n.findWelcome?s=t[4]:(s=(0,Z.jsx)(`h1`,{className:`text-xl font-semibold text-fg`,children:n.findWelcome}),t[3]=n.findWelcome,t[4]=s);let c;t[5]===n.findDescription?c=t[6]:(c=(0,Z.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n.findDescription}),t[5]=n.findDescription,t[6]=c);let l;if(t[7]!==i||t[8]!==r||t[9]!==n.findExamples){let e;t[11]!==i||t[12]!==r?(e=e=>(0,Z.jsx)(vi,{disabled:i,onClick:()=>r(e),children:e},e),t[11]=i,t[12]=r,t[13]=e):e=t[13],l=n.findExamples.map(e),t[7]=i,t[8]=r,t[9]=n.findExamples,t[10]=l}else l=t[10];let u;t[14]===l?u=t[15]:(u=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:l}),t[14]=l,t[15]=u);let d;t[16]===n.findBack?d=t[17]:(d=(0,Z.jsx)(p,{to:`/capabilities/skills`,className:`text-sm text-accent-fg hover:underline`,children:n.findBack}),t[16]=n.findBack,t[17]=d);let f;return t[18]!==o||t[19]!==s||t[20]!==c||t[21]!==u||t[22]!==d?(f=(0,Z.jsxs)(`section`,{className:`mx-auto flex max-w-xl flex-col items-start gap-4 py-8 sm:py-12`,children:[o,s,c,u,d]}),t[18]=o,t[19]=s,t[20]=c,t[21]=u,t[22]=d,t[23]=f):f=t[23],f}function iT(e){let t=`/api/sessions/${encodeURIComponent(e)}/connection-wait`,n=Sn(t=>t.sessions[e]?.localDraft),{data:r,mutate:i,isLoading:a}=Qr(n?null:[t,n===!1?`persisted`:`unknown`],async()=>await jr(e)?null:(await y(g(t))).payload,{refreshInterval:e=>e?.wait?5e3:0,revalidateOnFocus:!0}),o=(0,Q.useRef)(r);o.current=r;let s=(0,Q.useRef)(!1),c=(0,Q.useRef)(!1),l=(0,Q.useRef)(0),u=(0,Q.useRef)(null),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(),[h,_]=(0,Q.useState)(),b=(0,Q.useCallback)(async(e,n,r,a,d)=>{let p=o.current,h=p?.wait;if(!h||(e===`cancel`?c.current:s.current||c.current))return!1;e===`cancel`?c.current=!0:s.current=!0,l.current+=1,f(!0),m(void 0),e===`cancel`&&_(void 0);let b=h.needs.find(e=>e.key===n),x=e===`connect`&&b?.target.type!==`plugin`?as():null,S=JSON.stringify([h.id,h.objectiveRevision,e,n,r,a,d]);u.current?.signature!==S&&(u.current={signature:S,key:crypto.randomUUID()});let C=u.current.key,w=i=>y(g(`${t}/actions`),{method:`POST`,body:JSON.stringify({action:e,needKey:n,accountId:r,candidateRef:a,instanceId:d,waitId:h.id,expectedTranscriptId:i.transcriptId,expectedVersion:i.wait.version,...e===`cancel`?{expectedObjectiveRevision:h.objectiveRevision}:{},idempotencyKey:C})});try{let n;try{n=await w(p)}catch(r){if(e!==`cancel`||r.status!==409)throw r;let a=(await y(g(t))).payload;if(await i(e=>!e||e.transcriptId!==a.transcriptId||a.revision>=e.revision?a:e,!1),a.transcriptId!==p.transcriptId||a.wait?.id!==h.id||a.wait.objectiveRevision!==h.objectiveRevision)throw r;n=await w(a)}let r=n.payload.snapshot;if(await i(e=>!e||e.transcriptId!==r.transcriptId||r.revision>=e.revision?r:e,!1),n.payload.authorizationUrl){if(!await is(n.payload.authorizationUrl,x))throw Error(`Unable to open the authorization window. Allow pop-ups, then retry.`)}else os(x);return u.current?.signature===S&&(u.current=null),!0}catch(t){if(os(x),t.status===409&&e===`cancel`){let e=v.getState().language===`zh`?`目标状态已变化,未能取消。请检查当前任务状态后再试。`:`The objective state changed and cancellation was not confirmed. Check its current status and try again.`;m(e),_(e)}else if(t.status!==409){let n=t instanceof Error?t.message:String(t);m(n),e===`cancel`&&_(n)}return await i(),!1}finally{e===`cancel`?c.current=!1:s.current=!1,--l.current,f(l.current>0)}},[t,i]);return(0,Q.useEffect)(()=>{let t=t=>{let n=t.detail;n?.conversationId===e&&(n.revision??1/0)>(o.current?.revision??0)&&i()};window.addEventListener(`session-connection-wait-changed`,t);let n=()=>{i()};return window.addEventListener(`gateway-realtime-connected`,n),()=>{window.removeEventListener(`session-connection-wait-changed`,t),window.removeEventListener(`gateway-realtime-connected`,n)}},[e,i]),{wait:r?.wait,isLoading:a,busy:d,error:p,cancellationError:h,act:b,dismissError:()=>{m(void 0),_(void 0)}}}function aT(e){let t=(0,X.c)(39),{need:n,language:r,disabled:i,onSelect:a,onConnect:o}=e,s=(0,Q.useId)(),[c,l]=(0,Q.useState)(),u=r===`zh`,d;if(t[0]!==n.accounts||t[1]!==c){let e;t[3]===c?e=t[4]:(e=e=>e.id===c,t[3]=c,t[4]=e),d=n.accounts.some(e),t[0]=n.accounts,t[1]=c,t[2]=d}else d=t[2];let f=d,p=u?`这次使用哪个 ${n.label} 账号或工作区?`:`Which ${n.label} account or workspace should this request use?`,m;t[5]===p?m=t[6]:(m=(0,Z.jsx)(`legend`,{className:`float-left mb-3 w-full text-sm font-medium text-fg`,children:p}),t[5]=p,t[6]=m);let h;if(t[7]!==s||t[8]!==n.accounts||t[9]!==c){let e;t[11]!==s||t[12]!==c?(e=e=>(0,Z.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-center gap-3 rounded-lg border px-3 py-2 text-sm text-fg hover:bg-surface-hover ${c===e.id?`border-accent bg-surface-hover`:`border-edge`}`,children:[(0,Z.jsx)(`input`,{type:`radio`,name:s,value:e.id,checked:c===e.id,onChange:()=>l(e.id),className:`shrink-0 accent-accent focus-visible:outline-2 focus-visible:outline-accent`}),(0,Z.jsx)(`span`,{className:`min-w-0 break-words`,children:e.label})]},e.id),t[11]=s,t[12]=c,t[13]=e):e=t[13],h=n.accounts.map(e),t[7]=s,t[8]=n.accounts,t[9]=c,t[10]=h}else h=t[10];let g;t[14]===h?g=t[15]:(g=(0,Z.jsx)(`div`,{className:`clear-both grid max-h-48 gap-2 overflow-y-auto sm:grid-cols-2`,children:h}),t[14]=h,t[15]=g);let _=u?`选择仅用于本次目标,选定后会自动继续。`:`This choice applies to this objective only. It will continue after selection.`,v;t[16]===_?v=t[17]:(v=(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:_}),t[16]=_,t[17]=v);let y=i||!f,b;t[18]!==a||t[19]!==c||t[20]!==f?(b=()=>{f&&c&&a(c)},t[18]=a,t[19]=c,t[20]=f,t[21]=b):b=t[21];let x=u?`使用所选账号并继续`:`Use selected account and continue`,S;t[22]!==x||t[23]!==y||t[24]!==b?(S=(0,Z.jsx)(`button`,{type:`button`,disabled:y,onClick:b,className:`min-h-11 rounded-lg bg-accent px-3 py-2 text-sm text-on-accent disabled:opacity-50`,children:x}),t[22]=x,t[23]=y,t[24]=b,t[25]=S):S=t[25];let C=u?`连接其他账号`:`Connect another account`,w;t[26]!==i||t[27]!==o||t[28]!==C?(w=(0,Z.jsx)(`button`,{type:`button`,disabled:i,onClick:o,className:`min-h-11 rounded-lg px-3 py-2 text-sm text-accent hover:bg-surface-hover disabled:opacity-50`,children:C}),t[26]=i,t[27]=o,t[28]=C,t[29]=w):w=t[29];let T;t[30]!==S||t[31]!==w?(T=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[S,w]}),t[30]=S,t[31]=w,t[32]=T):T=t[32];let E;return t[33]!==i||t[34]!==T||t[35]!==m||t[36]!==g||t[37]!==v?(E=(0,Z.jsxs)(`fieldset`,{disabled:i,className:`mt-3 min-w-0 space-y-3 border-t border-edge-subtle pt-3`,children:[m,g,v,T]}),t[33]=i,t[34]=T,t[35]=m,t[36]=g,t[37]=v,t[38]=E):E=t[38],E}var oT=(0,Q.lazy)(()=>l(()=>import(`./mcp-conversation-setup-page-DCIEL5bA.js`).then(e=>({default:e.McpConversationSetupDialog})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]))),sT={zh:{connection:`服务连接`,cancel:`取消连接请求`,close:`关闭`,finish:`完成连接`,review:`查看连接`,reconnect:`更新密钥`,expired:`连接请求已过期`,rejected:`服务未接受当前密钥`,token:`需要访问密钥`,oauth:`需要登录授权`,unknown:`无法确认认证方式`,failed:`连接检查未通过`,planned:`正在检查连接`,approval:`请确认服务和资料来源`,reload:`配置已保存,重启 Gateway 后生效`,help:`获取访问密钥`,connected:`连接已完成`,continuing:`连接已完成,原任务将自动继续`,cancelFailed:`暂时无法取消连接,请重试。`},en:{connection:`Service connection`,cancel:`Cancel connection request`,close:`Close`,finish:`Complete connection`,review:`View connection`,reconnect:`Update key`,expired:`Connection request expired`,rejected:`The service rejected the current key`,token:`Access key required`,oauth:`Sign-in required`,unknown:`Could not verify the authentication method`,failed:`Connection check failed`,planned:`Checking the connection`,approval:`Review the service and its sources`,reload:`Settings saved. Restart the Gateway to apply them.`,help:`Get an access key`,connected:`Connection complete`,continuing:`Connection complete. Your task will resume automatically.`,cancelFailed:`Could not cancel the connection. Try again.`}};function cT({conversationId:e}){let t=v(e=>e.language),[n,r]=f(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(),[c,l]=(0,Q.useState)(),u=sT[t];(0,Q.useEffect)(()=>{if(!c)return;let e=window.setTimeout(()=>l(void 0),8e3);return()=>window.clearTimeout(e)},[c]);let d=n.get(`mcpSetup`),m=e=>{let t=new URLSearchParams(n);e?t.set(`mcpSetup`,e):t.delete(`mcpSetup`),r(t,{replace:!e})},{data:h,mutate:_}=Qr(`/api/mcp/setup/conversations/${encodeURIComponent(e)}`,async e=>{try{return{permitted:!0,...(await y(g(e))).payload}}catch(e){if([403,404].includes(e.status??0))return{permitted:!1,setup:null};throw e}},{refreshInterval:e=>e?.setup?5e3:0,shouldRetryOnError:!1});(0,Q.useEffect)(()=>{if(h?.permitted===!1)return;let t=t=>{let n=t.detail;(n?.conversationId??n?.key)===e&&_()},n=()=>{_()};return window.addEventListener(`session-mcp-setup-changed`,t),window.addEventListener(`session-transcript-updated`,t),window.addEventListener(`gateway-realtime-connected`,n),()=>{window.removeEventListener(`session-mcp-setup-changed`,t),window.removeEventListener(`session-transcript-updated`,t),window.removeEventListener(`gateway-realtime-connected`,n)}},[e,_,h?.permitted]);let b=d?(0,Z.jsx)(Q.Suspense,{fallback:null,children:(0,Z.jsx)(oT,{setupId:d,onClose:t=>{t?.phase===`ready`&&!t.reloadRequired&&t.conversationId===e&&l({conversationId:e,label:t.displayName||t.serverId,continuing:t.continuationQueued===!0&&t.objective!==`connect_only`}),m(null),_()}})}):null;if(!h?.setup)return(0,Z.jsxs)(Z.Fragment,{children:[c?.conversationId===e?(0,Z.jsxs)(`section`,{className:`mb-2 flex items-center gap-3 rounded-xl border border-edge bg-success-soft px-3 py-2 text-sm text-fg`,children:[(0,Z.jsx)(re,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsxs)(`p`,{role:`status`,className:`min-w-0 flex-1 break-words`,children:[c.label,` · `,c.continuing?u.continuing:u.connected]}),(0,Z.jsx)(vi,{variant:`ghost`,className:`size-11 shrink-0 p-0`,"aria-label":u.close,onClick:()=>l(void 0),children:(0,Z.jsx)(Xt,{className:`size-4`,"aria-hidden":!0})})]}):null,b]});let x=h.setup,S=async()=>{a(!0),s(void 0);try{await y(g(`/api/mcp/setup/${encodeURIComponent(x.setupId)}`),{method:`POST`,body:JSON.stringify({action:`cancel`,expectedVersion:x.version})}),d===x.setupId&&m(null),await _(e=>e?.setup?.setupId===x.setupId?{...e,setup:null}:e)}catch{s(x.setupId),_()}finally{a(!1)}},C=x.errorCode===`credential_rejected`,w=x.expired?u.expired:x.reloadRequired?u.reload:C?u.rejected:x.phase===`token_required`?u.token:[`oauth_required`,`authorizing`].includes(x.phase)?u.oauth:x.phase===`auth_unknown`?u.unknown:x.phase===`blocked`?u.failed:x.phase===`approval_required`?u.approval:x.phase===`ready`?u.connected:u.planned,T=C&&!x.expired?u.reconnect:x.expired||x.reloadRequired||[`blocked`,`auth_unknown`].includes(x.phase)?u.review:u.finish;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`section`,{className:`mb-2 flex flex-wrap items-center gap-2 rounded-xl border border-edge bg-surface-panel px-3 py-2`,"aria-label":u.connection,children:[(0,Z.jsx)(Je,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 break-words text-sm`,role:`status`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-fg`,children:x.displayName||x.serverId}),(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:w})]}),(0,Z.jsx)(p,{className:`inline-flex min-h-11 items-center rounded-lg px-3 text-sm text-accent-fg hover:bg-surface-hover`,to:`/mcp-setup/${encodeURIComponent(x.setupId)}`,onClick:e=>{e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),m(x.setupId))},children:T}),(0,Z.jsx)(vi,{variant:`ghost`,className:`size-11 shrink-0 p-0`,"aria-label":u.cancel,title:u.cancel,disabled:i,onClick:()=>void S(),children:(0,Z.jsx)(Xt,{className:`size-4`,"aria-hidden":!0})}),!x.expired&&x.phase===`token_required`&&x.helpUrl?(0,Z.jsx)(`div`,{className:`basis-full pl-6`,children:(0,Z.jsxs)(`a`,{href:x.helpUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex min-h-8 items-center text-sm text-accent-fg hover:underline`,children:[u.help,` ↗`]})}):null,o===x.setupId?(0,Z.jsx)(`span`,{role:`alert`,className:`basis-full text-sm text-fg-muted`,children:u.cancelFailed}):null]}),b]})}var lT=(0,Q.lazy)(()=>l(()=>import(`./agent-plugin-dialog-C_rlXuEe.js`).then(e=>e.n).then(e=>({default:e.AgentPluginDialog})),__vite__mapDeps([30,1,2,3,4,5,6,7,8,9,31,11,32,33,34,16,17,18,29,20,21,35,36,13,37,38,39,40,41,27,28,42,43,44,45]))),uT={zh:{waiting:`等待连接`,reconnectRequired:`需要重新授权`,install:`安装`,installing:`正在准备安装`,connect:`连接`,reconnect:`重新连接`,details:`查看详情`,skip:`跳过连接`,cancel:`取消这个目标`,ready:`已连接`,check:`我已完成授权`,authorizing:`等待完成授权`,queued:`已连接,等待继续`,queuedSkipped:`等待使用现有信息继续`,checkingConnection:`正在检查连接`,checkingTools:`已连接,正在验证工具`,queueHint:`目标已保存,正在等待当前执行结束。`,interruptedInputHint:`有条补充消息在重启时中断。请重新发送要求,或移除上方中断的消息后继续。`,checkFailed:`连接检查暂时失败,目标已保存`,interrupted:`恢复检查曾中断,目标已保存`,lastChecked:`最近检查`,scope:`确认后继续`,scopeHint:`这个目标已等待了一段时间。请确认仍要按下方原始要求继续;如需修改时间范围,请先在聊天中说明。未读等条件将以实际执行时为准。`,account:`选择账号`,all:`查看全部连接`,close:`关闭`,intro:`完成连接后,将自动恢复当前目标。你也可以继续发送消息。`,callbackHint:`远程 Gateway 无法接收本地回调时,粘贴浏览器地址栏中的完整回调 URL。`,callbackPlaceholder:`完整回调 URL`,callbackSubmit:`完成连接`,replace:`更换应用`,confirmReplace:`确认改用`,apps:`个应用需要连接`,preserved:`目标已保留`,retry:`重试检查`,toolsUnavailable:`应用工具暂不可用`,toolsHint:`账号已连接,当前无法使用任务所需工具。可以重试检查,无需重新授权。`},en:{waiting:`Waiting for connection`,reconnectRequired:`Reauthorization required`,install:`Install`,installing:`Preparing installation`,connect:`Connect`,reconnect:`Reconnect`,details:`Details`,skip:`Skip connection`,cancel:`Cancel this objective`,ready:`Connected`,check:`Check authorization`,authorizing:`Waiting for authorization`,queued:`Connected, waiting to continue`,queuedSkipped:`Waiting to continue with available information`,checkingConnection:`Checking connection`,checkingTools:`Connected, checking tools`,queueHint:`Your objective is saved. Waiting for the current execution to finish.`,interruptedInputHint:`A message was interrupted during restart. Resend the requirement or remove the interrupted message above before continuing.`,checkFailed:`Connection check failed; objective saved`,interrupted:`Recovery check interrupted; objective saved`,lastChecked:`Last checked`,scope:`Confirm and continue`,scopeHint:`This objective has been waiting for a while. Confirm the original request below, or send a message to change the time range first. Conditions such as unread status are evaluated at execution time.`,account:`Choose an account`,all:`View all connections`,close:`Close`,intro:`The current objective resumes automatically after connecting. You can keep sending messages.`,callbackHint:`If a remote Gateway cannot receive the local callback, paste the complete callback URL from the browser address bar.`,callbackPlaceholder:`Complete callback URL`,callbackSubmit:`Complete connection`,replace:`Change app`,confirmReplace:`Confirm switch to`,apps:`apps need connecting`,preserved:`Objective preserved`,retry:`Retry check`,toolsUnavailable:`App tools unavailable`,toolsHint:`The account is connected, but the tools needed for this task are unavailable. Retry the check without reconnecting.`}},dT=`rounded-lg border border-edge px-3 py-1.5 text-sm text-fg hover:bg-surface-hover disabled:opacity-50`,fT=`rounded-lg bg-accent px-3 py-1.5 text-sm text-on-accent disabled:opacity-50`;function pT({conversationId:e}){let{wait:t,busy:n,error:r,cancellationError:i,act:a,dismissError:o}=iT(e),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(),[d,f]=(0,Q.useState)(),[p,m]=(0,Q.useState)(),[h,_]=(0,Q.useState)(),[b,x]=(0,Q.useState)(!1),[w,j]=(0,Q.useState)(),M=v(e=>e.language),N=uT[M];if(!t)return i?(0,Z.jsxs)(`div`,{role:`alert`,className:`mb-2 flex items-center gap-2 rounded-xl border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,children:[(0,Z.jsx)(`p`,{className:`min-w-0 flex-1`,children:i}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:dT,children:N.close})]}):(0,Z.jsx)(cT,{conversationId:e});let P=t.needs[0],F=t.needs.length===1,I=F&&P.phase===`reconnect`,L=t.phase===`queued`,R=t.recoveryStage===`checking_connection`||t.recoveryStage===`checking_tools`,z=t.needs.find(e=>e.phase===`choose_account`),B=t.needs.some(e=>e.capabilityError);if(t.phase===`ready`&&!R&&!t.recoveryError&&!t.needs.some(e=>e.target.type===`plugin`))return(0,Z.jsx)(cT,{conversationId:e});let ee=t.recoveryStage===`checking_connection`?N.checkingConnection:t.recoveryStage===`checking_tools`?N.checkingTools:L?t.resolution===`skipped`?N.queuedSkipped:N.queued:t.recoveryError===`check_failed`?N.checkFailed:t.recoveryError?N.interrupted:t.phase===`ready`?N.ready:B?N.toolsUnavailable:z?N.account:F&&P.phase===`authorizing`?N.authorizing:I?N.reconnectRequired:N.waiting,V=L||R?N.details:t.recoveryError?N.retry:t.phase===`review_scope`?N.scope:F&&P.phase===`install`?b?N.installing:`${N.install} ${P.label}`:F&&P.phase===`connect`?M===`zh`?`连接 ${P.label}`:`Connect ${P.label}`:F&&P.phase===`reconnect`?N.reconnect:F&&P.phase===`authorizing`&&P.target.type!==`plugin`?N.check:N.details;async function H(e=P){if(e.target.type===`store-connector`){x(!0),j(void 0);try{let t=await ga(e.target.packageName,e.target.version);if(t.reviewHash!==e.target.reviewHash||t.definition.id!==e.target.connectorId||t.definition.provenance?.sha256!==e.target.sha256)throw Error(M===`zh`?`Connector 包在审查后发生了变化,请重新发起推荐。`:`The Connector package changed after review. Request a new recommendation.`);f(Dt(t.definition,{packageName:t.packageName,version:t.version,reviewHash:t.reviewHash,permissions:t.permissions})),m(e.key)}catch(e){j(e instanceof Error?e.message:String(e))}finally{x(!1)}}}async function U(e){if(!(e.target.type!==`plugin`||!t)){x(!0),j(void 0);try{let{target:n,pluginId:r}=e,i=r?(await y(g(`/api/extensions/agent-plugins/${encodeURIComponent(r)}`))).payload:void 0,o=`packageName`in n&&!i?`store:${n.packageName}@${n.version}`:void 0;if(!i&&!o||!await a(`connect`,e.key))return;c(!1),_({waitId:t.id,extension:i,source:o})}catch(e){j(e instanceof Error?e.message:String(e))}finally{x(!1)}}}function W(){L||R?c(!0):t?.recoveryError?a(`check`):t?.phase===`review_scope`?c(!0):F&&P.target.type===`plugin`&&[`install`,`connect`,`reconnect`,`authorizing`].includes(P.phase)?U(P):F&&P.phase===`install`?H():F&&[`connect`,`reconnect`].includes(P.phase)?a(`connect`,P.key):F&&P.phase===`authorizing`?a(`check`):c(!0)}return(0,Z.jsxs)(`section`,{className:`mb-2 rounded-xl border border-edge bg-surface-panel px-3 py-2`,"aria-label":ee,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(Je,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),(0,Z.jsxs)(`button`,{type:`button`,className:`min-w-0 flex-1 text-left text-sm text-fg`,onClick:()=>c(!0),children:[(0,Z.jsx)(`span`,{role:`status`,children:F?`${ee} · ${P.label}`:`${ee} · ${t.needs.length} ${N.apps}`}),(0,Z.jsx)(ae,{className:`ml-1 inline size-3`,"aria-hidden":!0})]}),(0,Z.jsxs)(`button`,{type:`button`,className:z||L||R?dT:fT,disabled:n&&!R||b,onClick:W,children:[n&&(0,Z.jsx)(Ze,{className:`mr-1 inline size-3 animate-spin`,"aria-hidden":!0}),V]}),!L&&!R&&(0,Z.jsx)(`button`,{type:`button`,className:`text-xs text-fg-muted hover:text-fg`,disabled:n,onClick:()=>void a(`skip`),children:N.skip}),(0,Z.jsx)(`button`,{type:`button`,className:`min-h-11 px-2 text-xs text-fg-muted hover:text-fg`,onClick:()=>void a(`cancel`),children:N.cancel})]}),I&&!R&&!L?(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:N.intro}):null,t.queueBlocked&&(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.blockedInputId?N.interruptedInputHint:N.queueHint}),t.lastCheckedAt&&(0,Z.jsxs)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:[N.lastChecked,`: `,new Date(t.lastCheckedAt).toLocaleTimeString(M===`zh`?`zh-CN`:`en-US`)]}),z&&!L&&(0,Z.jsx)(`p`,{className:`mt-2 line-clamp-2 break-words text-sm text-fg-muted`,children:t.summary}),z&&!L&&(0,Z.jsx)(aT,{need:z,language:M,disabled:n||R,onSelect:e=>void a(`select_account`,z.key,e),onConnect:()=>void a(`connect`,z.key)},`${t.id}:${t.objectiveRevision}:${z.key}`),(r||w)&&(0,Z.jsxs)(`p`,{role:`alert`,className:`mt-2 text-xs text-fg-muted`,children:[r??w,` `,(0,Z.jsx)(`button`,{type:`button`,className:`text-accent`,onClick:()=>void a(`check`),children:N.retry})]}),(0,Z.jsx)(A,{open:s,onOpenChange:c,children:(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[2px]`}),(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(90dvh,34rem)] w-[min(94vw,34rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-edge px-5 py-4`,children:[(0,Z.jsx)(k,{className:`font-medium text-fg`,children:N.preserved}),(0,Z.jsx)(E,{"aria-label":N.close,children:(0,Z.jsx)(Xt,{className:`size-4`})})]}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto p-5`,children:[(0,Z.jsx)(T,{className:`text-sm text-fg-muted`,children:B?N.toolsHint:t.phase===`review_scope`?N.scopeHint:N.intro}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap rounded-lg border border-edge p-3 text-sm text-fg`,children:t.summary}),(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:new Date(t.objectiveUpdatedAt).toLocaleString(M===`zh`?`zh-CN`:`en-US`)}),t.timeRange&&(0,Z.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[new Date(t.timeRange.from).toLocaleString(M,{timeZone:t.timeRange.timezone}),` – `,new Date(t.timeRange.to).toLocaleString(M,{timeZone:t.timeRange.timezone}),` (`,t.timeRange.timezone,`)`]}),t.needs.map(e=>(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-edge p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[e.label,e.accountSelector?` · ${e.accountSelector}`:``]}),e.capabilityError?(0,Z.jsx)(`button`,{type:`button`,disabled:n||L,className:dT,onClick:()=>void a(`check`),children:N.retry}):e.phase===`ready`?(0,Z.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[(0,Z.jsx)(re,{className:`mr-1 inline size-3`}),N.ready]}):e.target.type===`plugin`&&e.phase!==`blocked`?(0,Z.jsx)(`button`,{type:`button`,disabled:n||L||b,className:fT,onClick:()=>void U(e),children:e.phase===`install`?N.install:e.phase===`reconnect`?N.reconnect:N.connect}):e.phase===`authorizing`?(0,Z.jsx)(`button`,{type:`button`,disabled:n,className:dT,onClick:()=>void a(`check`),children:N.check}):e.phase===`install`?(0,Z.jsx)(`button`,{type:`button`,disabled:n||L||b,className:fT,onClick:()=>void H(e),children:N.install}):e.phase!==`blocked`&&e.phase!==`choose_account`?(0,Z.jsx)(`button`,{type:`button`,disabled:n||L,className:fT,onClick:()=>void a(`connect`,e.key),children:e.phase===`reconnect`?N.reconnect:N.connect}):null]}),e.accountId&&(0,Z.jsx)(`p`,{className:`break-words text-xs text-fg-muted`,children:e.accounts.find(t=>t.id===e.accountId)?.label??e.accountId}),e.alternatives?.length?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(fe,{value:l?.needKey===e.key?l.candidateRef:``,options:e.alternatives.map(e=>({value:e.candidateRef,label:e.label})),placeholder:N.replace,ariaLabel:`${e.label}: ${N.replace}`,disabled:n||L,allowEmpty:!1,onChange:t=>u({needKey:e.key,candidateRef:t,label:e.alternatives.find(e=>e.candidateRef===t).label})}),l?.needKey===e.key&&(0,Z.jsxs)(`button`,{type:`button`,className:dT,disabled:n,onClick:()=>{a(`replace_source`,e.key,void 0,l.candidateRef),u(void 0)},children:[N.confirmReplace,` `,l.label]})]}):null,e.reason&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.reason}),e.phase===`authorizing`&&e.target.type!==`plugin`&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:N.authorizing}),(0,Z.jsx)(`button`,{type:`button`,disabled:n,className:`text-accent`,onClick:()=>void a(`connect`,e.key),children:N.reconnect})]})]},e.key)),(0,Z.jsx)(`a`,{href:`#/capabilities/connectors`,className:`text-sm text-accent`,onClick:()=>c(!1),children:N.all})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-t border-edge p-4`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`min-h-11 text-sm text-fg-muted`,onClick:()=>void a(`cancel`),children:N.cancel}),t.phase===`review_scope`?(0,Z.jsx)(`button`,{type:`button`,disabled:n||L,className:fT,onClick:()=>void a(`confirm_scope`),children:N.scope}):null]})]})]})}),h?.waitId===t.id?(0,Z.jsx)(Q.Suspense,{fallback:(0,Z.jsx)(Qt,{className:`mt-2 h-10 w-full`}),children:(0,Z.jsx)(lT,{extension:h.extension,initialSource:h.source,connectionFlow:!0,onClose:()=>_(void 0)})}):null,d?(0,Z.jsx)(Ot,{draft:d,onChange:f,onClose:()=>{f(void 0),m(void 0)},onInstalled:async e=>{p&&await a(`install_complete`,p,void 0,void 0,e.instanceId)&&(f(void 0),m(void 0))},t:S(M).connectorsSettings}):null]})}var mT=new Set([`button`,`checkbox`,`color`,`file`,`hidden`,`image`,`radio`,`range`,`reset`,`submit`]);function hT(e){if(!(e instanceof Element))return!1;if(e.closest(`textarea, select, [role="textbox"]`)||e instanceof HTMLElement&&e.isContentEditable)return!0;let t=e.closest(`input`);return t instanceof HTMLInputElement&&!mT.has(t.type)}function gT(){return!!document.querySelector(`dialog[open], [aria-modal="true"], [role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`)}function _T(e,t){return t.disabled||t.editorHidden||e.defaultPrevented||hT(e.target)||hT(document.activeElement)?!1:!gT()}function vT(e){for(let t=e.parentElement;t;t=t.parentElement)if(/(auto|scroll)/.test(getComputedStyle(t).overflowY))return t;return null}function yT({items:e,disabled:t,onReorder:n}){let r=(0,Q.useRef)(null),i=(0,Q.useRef)(null),a=(0,Q.useRef)(0),o=(0,Q.useRef)(null),s=(0,Q.useRef)({items:e,onReorder:n});s.current={items:e,onReorder:n};let[c,l]=(0,Q.useState)(null),u=e.map(e=>`${e.id}:${e.version}:${e.status}`).join(`|`);function d(){let e=i.current;e&&(cancelAnimationFrame(e.frame),e.overlay?.remove(),e.row.hasPointerCapture?.(e.pointerId)&&e.row.releasePointerCapture(e.pointerId),e.overlay&&(a.current=Date.now()+250,document.body.style.cursor=e.cursor,document.body.style.userSelect=e.userSelect),i.current=null,o.current&&clearTimeout(o.current),o.current=null)}(0,Q.useEffect)(()=>(l(null),d),[u,t]);function f(e){let t=(e.scroller?.scrollTop??0)-e.initialScroll,n=e.y-e.offsetY+e.slots[e.from].height/2,r=e.slots.filter((r,i)=>i!==e.from&&n>r.top-t+r.height/2).length;e.to=r;let i=[...e.slots];i.splice(r,0,i.splice(e.from,1)[0]);let a={},o=0,s=e.allSlots[0].top;e.allSlots.forEach((t,n)=>{let r=t.sortable?i[o++]:t;a[r.id]=s-r.top,r.id===e.id&&(e.landingTop=s);let c=e.allSlots[n+1];s+=r.height+(c?c.top-t.top-t.height:0)}),l(t=>t?.id===e.id&&t.targetId===e.slots[r].id?t:{id:e.id,targetId:e.slots[r].id,shifts:a})}function p(e){if(i.current!==e||!e.overlay)return;let t=e.scroller;if(t){let n=t.getBoundingClientRect(),r=Math.min(32,n.height/4),i=e.y<n.top+r?-Math.min(8,(n.top+r-e.y)/4):e.y>n.bottom-r?Math.min(8,(e.y-n.bottom+r)/4):0;i&&(t.scrollTop+=i,f(e))}e.frame=requestAnimationFrame(()=>p(e))}function m(e,n){if(t||n.status!==`queued`||e.button!==0||i.current)return;let a=e.target;if(a.closest(`button, a, input`)&&!a.closest(`[data-follow-up-drag-surface]`)||e.pointerType===`touch`&&!a.closest(`[data-follow-up-drag-handle]`))return;let o=e.currentTarget,s=o.getBoundingClientRect(),c=Array.from(r.current?.querySelectorAll(`[data-follow-up-id]`)??[]).map(e=>{let t=e.getBoundingClientRect();return{id:e.dataset.followUpId,top:t.top,height:t.height,sortable:e.dataset.followUpSortable===`true`}}),l=c.filter(e=>e.sortable);if(l.length<2)return;let u=l.findIndex(e=>e.id===n.id);if(u<0)return;let d=vT(o);i.current={pointerId:e.pointerId,id:n.id,row:o,startX:e.clientX,startY:e.clientY,x:e.clientX,y:e.clientY,left:s.left,top:s.top,offsetY:e.clientY-s.top,slots:l,allSlots:c,landingTop:s.top,from:u,to:u,scroller:d,initialScroll:d?.scrollTop??0,overlay:null,frame:0,cursor:document.body.style.cursor,userSelect:document.body.style.userSelect}}function h(e){let t=i.current;if(!(!t||t.pointerId!==e.pointerId||o.current)&&(t.x=e.clientX,t.y=e.clientY,!(!t.overlay&&Math.hypot(t.x-t.startX,t.y-t.startY)<5))){if(e.preventDefault(),!t.overlay){t.row.setPointerCapture?.(t.pointerId);let e=t.row.cloneNode(!0);e.removeAttribute(`data-follow-up-id`),e.removeAttribute(`data-follow-up-sortable`),e.setAttribute(`data-follow-up-drag-overlay`,``),e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`inert`,``),e.querySelectorAll(`[id]`).forEach(e=>e.removeAttribute(`id`)),Object.assign(e.style,{position:`fixed`,left:`${t.left}px`,top:`${t.top}px`,width:`${t.row.getBoundingClientRect().width}px`,height:`${t.slots[t.from].height}px`,zIndex:`60`,pointerEvents:`none`,margin:`0`,opacity:`1`,background:`var(--color-surface-overlay)`,border:`1px solid var(--color-edge-strong)`,boxShadow:`var(--shadow-popover)`,willChange:`transform`,transition:`none`}),document.body.append(e),t.overlay=e,document.body.style.cursor=`grabbing`,document.body.style.userSelect=`none`,t.frame=requestAnimationFrame(()=>p(t))}t.overlay.style.transform=`translate3d(${t.x-t.startX}px, ${t.y-t.startY}px, 0) scale(1.015)`,f(t)}}function g(e){let t=i.current;if(!t||o.current)return;if(!t.overlay){d();return}a.current=Date.now()+250,cancelAnimationFrame(t.frame);let n=e?t.landingTop:t.top,r=(t.scroller?.scrollTop??0)-t.initialScroll,c=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches;if(t.overlay.style.transition=c?`none`:`transform 160ms ease-out, opacity 160ms ease-out`,t.overlay.style.transform=`translate3d(0, ${n-r-t.top}px, 0) scale(1)`,o.current=setTimeout(()=>{d(),l(null)},c?0:170),e&&t.to!==t.from){let e=s.current.items.findIndex(e=>e.id===t.id),n=s.current.items.findIndex(e=>e.id===t.slots[t.to].id);e>=0&&n>=0&&s.current.onReorder(e,n)}}return(0,Q.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i.current&&(e.preventDefault(),d(),l(null))},t=()=>{d(),l(null)},n=e=>h(e),r=e=>{e.pointerId===i.current?.pointerId&&g(!0)},a=e=>{e.pointerId===i.current?.pointerId&&g(!1)};return window.addEventListener(`pointermove`,n,{passive:!1}),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,a),window.addEventListener(`keydown`,e),window.addEventListener(`blur`,t),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,a),window.removeEventListener(`keydown`,e),window.removeEventListener(`blur`,t),window.removeEventListener(`resize`,t)}},[]),{listRef:r,view:c,onPointerDown:m,onClickCapture:e=>{Date.now()<a.current&&(e.preventDefault(),e.stopPropagation())}}}function bT(e){return e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;if(typeof t.id!=`string`||typeof t.clientMessageId!=`string`||typeof t.content!=`string`||typeof t.version!=`number`||t.effectiveDelivery!==`next`&&t.effectiveDelivery!==`steer`||t.status!==`queued`&&t.status!==`interrupted`)return[];let n=Array.isArray(t.contextRefs)?t.contextRefs.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return t.kind!==`note`&&t.kind!==`file`&&t.kind!==`session`&&t.kind!==`browser_tab`||typeof t.sourceId!=`string`||typeof t.version!=`string`||typeof t.title!=`string`?[]:[{...typeof t.refId==`string`?{refId:t.refId}:{},kind:t.kind,sourceId:t.sourceId,expectedVersion:t.version,title:t.title,...t.kind===`file`&&(t.fileKind===`file`||t.fileKind===`directory`)?{fileKind:t.fileKind}:{}}]}):void 0;return[{id:t.id,clientMessageId:t.clientMessageId,text:t.content,attachments:Array.isArray(t.attachments)?t.attachments:void 0,thinkingLevel:typeof t.thinking==`string`?t.thinking:void 0,contextRefs:n?.length?n:void 0,version:t.version,delivery:t.effectiveDelivery,status:t.status}]})}function xT(e){let t=bT(e.inputs);if(!e.control?.paused&&!e.activeRunId&&e.preparation?.state!==`preparation_failed`){let e=t.findIndex(e=>e.status===`queued`);e>=0&&t.splice(e,1)}return t}var ST=(0,Q.memo)(function({items:e,disabled:t,editingFollowUpId:n,onEditInComposer:r,onRemove:i,onMove:a,onReorder:o,onSteer:s,onSendSingle:c,queuePaused:l=!1,queueIdle:u=!1,steeringBusyId:d,onOpenSideChat:f}){let p=S(v(e=>e.language)),m=(0,Q.useRef)(!1),h=e.filter(e=>e.status===`queued`),g=!!(t||d),_=yT({items:e,disabled:g,onReorder:o}),y=Y(`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-lg px-2 text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg disabled:pointer-events-none disabled:opacity-35`,ca.focusRingPanel),b=`flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm text-fg outline-none focus:bg-surface-hover data-[disabled]:pointer-events-none data-[disabled]:opacity-35`;return e.length===0?null:(0,Z.jsxs)(`div`,{ref:_.listRef,className:`space-y-1 px-2 py-2`,onClickCapture:_.onClickCapture,role:`list`,"aria-label":p.chat.followUpQueueAria,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 pb-1`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:p.chat.followUpQueueHeading}),(0,Z.jsxs)(`span`,{className:`tabular-nums text-[0.65rem] text-fg-muted`,children:[e.length,`/`,10]})]}),e.map(e=>{let t=e.status===`queued`,o=t||e.status===`interrupted`,v=h.findIndex(t=>t.id===e.id),x=u&&(l||e.status===`interrupted`),S=o&&!!(e.text.trim()||e.attachments?.length||e.contextRefs?.length),C=o&&!e.attachments?.length&&!e.contextRefs?.length&&e.text.trim().length>0,w=d===e.id,T=e.status===`interrupted`?p.chat.followUpStatusInterrupted:null,E=Rn(e.text),D=new Map(e.contextRefs?.flatMap(e=>e.refId?[[e.refId,e.title]]:[])??[]),O=new Set(E?Bn(E):[]),k=e.contextRefs?.filter(e=>!e.refId||!O.has(e.refId)),A=dr(E?xn(E,e=>D.get(e)):e.text).trim();return!A&&e.attachments?.length&&(A=e.attachments[0]?.name?.trim()||p.chat.followUpQueueAttachmentOnly),A||=p.chat.followUpQueueEmptyPreview,(0,Z.jsxs)(`div`,{role:`listitem`,"data-follow-up-id":e.id,"data-follow-up-sortable":!g&&t,onPointerDown:t=>_.onPointerDown(t,e),onDragStart:e=>e.preventDefault(),style:{transform:_.view?.shifts[e.id]?`translateY(${_.view.shifts[e.id]}px)`:void 0},className:Y(`relative flex min-h-10 items-center gap-1 rounded-lg px-1.5 py-1 motion-safe:transition-transform motion-safe:duration-150`,!g&&t&&`cursor-grab`,_.view?.id===e.id&&`bg-surface-inset ring-1 ring-inset ring-edge-strong [&>*]:invisible`,n===e.id?`bg-accent-soft ring-1 ring-inset ring-accent/30`:`hover:bg-surface-hover/50`),children:[(0,Z.jsx)(`div`,{"data-follow-up-drag-handle":!0,className:Y(`flex shrink-0 touch-none cursor-grab items-center active:cursor-grabbing`,(g||!t)&&`cursor-not-allowed opacity-40`),title:p.chat.followUpQueueDrag,children:(0,Z.jsx)(Ss,{className:`size-3.5 text-fg-muted`,"aria-hidden":!0})}),(0,Z.jsx)(`button`,{type:`button`,"data-follow-up-drag-surface":!0,disabled:g||!t,title:p.chat.followUpQueueClickToEdit,"aria-label":p.chat.followUpQueueClickToEdit,className:Y(`min-h-8 min-w-0 flex-1 cursor-grab rounded-md px-1.5 text-left text-sm text-fg`,ca.focusRingPanel,`disabled:pointer-events-none disabled:opacity-50`),onClick:()=>r(e.id),children:e.attachments?.length?(0,Z.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1`,children:[(0,Z.jsx)(Ee,{className:`size-3 shrink-0 text-fg-muted`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:A})]}):(0,Z.jsx)(`span`,{className:`line-clamp-2 break-words [overflow-wrap:anywhere]`,children:A})}),k?.length?(0,Z.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5 rounded bg-accent-soft px-1.5 py-0.5 text-[0.625rem] text-accent-fg`,title:k.map(e=>e.title).join(`, `),children:[(0,Z.jsx)(Os,{className:`size-3`,"aria-hidden":!0}),k.length]}):null,T?(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-surface-panel px-1.5 py-0.5 text-[0.625rem] text-fg-muted`,children:T}):null,(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:y,disabled:g||(x?!o:!S),title:x?p.chat.sendThisMessage:p.chat.followUpQueueSteerHint,"aria-label":x?p.chat.sendThisMessage:p.chat.followUpQueueSteerNow,"aria-busy":w,onClick:()=>x?c?.(e.id):s(e.id),children:[(0,Z.jsx)(hs,{className:Y(`size-4`,w&&`motion-safe:animate-pulse`),"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`hidden text-xs sm:inline`,children:x?p.chat.sendThisMessage:p.chat.followUpQueueSteerNow})]}),(0,Z.jsx)(`button`,{type:`button`,className:Y(y,`px-1.5 hover:text-danger`),disabled:g||!o,title:p.chat.followUpQueueRemove,"aria-label":p.chat.followUpQueueRemove,onClick:()=>i(e.id),children:(0,Z.jsx)(Wt,{className:`size-4`,"aria-hidden":!0})}),(0,Z.jsxs)(go,{modal:!1,children:[(0,Z.jsx)(_o,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:Y(y,`px-1.5`),disabled:g,title:p.chat.followUpQueueMore,"aria-label":p.chat.followUpQueueMore,children:(0,Z.jsx)(Ce,{className:`size-4`,"aria-hidden":!0})})}),(0,Z.jsx)(vo,{children:(0,Z.jsxs)(bo,{side:`top`,align:`end`,sideOffset:6,onCloseAutoFocus:e=>{m.current&&e.preventDefault(),m.current=!1},className:`z-50 min-w-52 max-w-[calc(100vw-2rem)] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover`,children:[(0,Z.jsxs)(yo,{className:b,disabled:!t,onSelect:()=>{m.current=!0,r(e.id)},children:[(0,Z.jsx)(jt,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueClickToEdit]}),f?(0,Z.jsxs)(yo,{className:b,disabled:!C,onSelect:()=>f(e,A),children:[(0,Z.jsx)(Ts,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueOpenSideChat]}):null,h.length>1?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(xo,{className:`my-1 h-px bg-edge-subtle`}),(0,Z.jsxs)(yo,{className:b,disabled:!t||v===0,onSelect:()=>a(e.id,`up`),children:[(0,Z.jsx)(oe,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueMoveUp]}),(0,Z.jsxs)(yo,{className:b,disabled:!t||v>=h.length-1,onSelect:()=>a(e.id,`down`),children:[(0,Z.jsx)(ie,{className:`size-4`,"aria-hidden":!0}),p.chat.followUpQueueMoveDown]})]}):null]})})]})]})]},e.id)})]})});function CT({conversationId:e}){let t=_(e=>e.conversationId),n=v(e=>e.language).startsWith(`zh`),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),s=Qr(e?[`session-preparation`,t,e]:null,async()=>{let t=await jr(e);if(t&&!t.materialization)return null;let n=await y(g(`/api/sessions/${encodeURIComponent(e)}/input-state`));return n.payload.preparation?Nr.parse(n.payload.preparation):null},{refreshInterval:e=>e?.state===`preparing`?5e3:0,shouldRetryOnError:!1}),{mutate:c}=s;(0,Q.useEffect)(()=>{let t=t=>{t.detail?.conversationId===e&&c()};return window.addEventListener(`session-input-state`,t),()=>window.removeEventListener(`session-input-state`,t)},[e,c]);let l=s.data;if(!l||l.state===`ready`)return null;let u=async()=>{i(!0),o(``);try{let t=await h(g(`/api/sessions/${encodeURIComponent(e)}/preparation/retry`),{method:`POST`,body:JSON.stringify({operationId:l.operationId,expectedRevision:l.revision,idempotencyKey:`${l.operationId}:${l.revision}`})});if(!t.ok)throw Error(`HTTP ${t.status}`);await c()}catch(e){o(e instanceof Error?e.message:String(e))}finally{i(!1)}};return(0,Z.jsxs)(`div`,{className:`border-b border-edge-subtle px-3 py-2 text-sm text-fg-muted`,role:`status`,children:[(0,Z.jsx)(`span`,{children:l.state===`preparing`?n?`正在准备会话环境…`:`Preparing conversation environment…`:l.lastError??(n?`会话环境准备失败`:`Conversation environment preparation failed`)}),l.state===`preparation_failed`?(0,Z.jsx)(`button`,{type:`button`,className:`ml-2 text-accent-fg`,disabled:r,onClick:()=>void u(),children:n?`重试准备`:`Retry preparation`}):null,a?(0,Z.jsx)(`span`,{role:`alert`,className:`ml-2`,children:a}):null]})}function wT(e){let t=(0,X.c)(10),{refs:n,label:r,onRemove:i}=e;if(n.length===0)return null;let a;if(t[0]!==r||t[1]!==i||t[2]!==n){let e;t[4]!==r||t[5]!==i?(e=e=>(0,Z.jsxs)(`span`,{className:`inline-flex h-7 min-w-0 max-w-56 items-center gap-1.5 rounded-md border border-edge-subtle bg-accent-soft/50 px-2 text-xs text-fg`,children:[e.kind===`file`&&e.fileKind===`directory`?(0,Z.jsx)(je,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):e.kind===`file`||e.kind===`result`?(0,Z.jsx)(Oe,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):e.kind===`session`?(0,Z.jsx)(wt,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):e.kind===`browser_tab`?(0,Z.jsx)(M,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}):(0,Z.jsx)(Os,{className:`size-3.5 shrink-0 text-accent-fg`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.title}),(0,Z.jsx)(`button`,{type:`button`,className:`-mr-1 inline-flex size-5 shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-hover hover:text-fg`,"aria-label":`${r}: ${e.title}`,onClick:()=>i(e.sourceId),children:(0,Z.jsx)(Xt,{className:`size-3`,"aria-hidden":!0})})]},e.sourceId),t[4]=r,t[5]=i,t[6]=e):e=t[6],a=n.map(e),t[0]=r,t[1]=i,t[2]=n,t[3]=a}else a=t[3];let o;return t[7]!==r||t[8]!==a?(o=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-4 pt-2`,"aria-label":r,children:a}),t[7]=r,t[8]=a,t[9]=o):o=t[9],o}var TT=`inline-flex h-8 min-w-0 shrink-0 items-center justify-center gap-1.5 rounded-full px-2.5 text-sm text-fg transition-[background-color,transform] hover:bg-surface-hover active:scale-95 disabled:pointer-events-none disabled:opacity-45 motion-reduce:transition-none motion-reduce:transform-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`;function ET(e){let t=(0,X.c)(96),{conversationId:n,project:r,workspacePath:i,canChangeWorkspace:a,disabled:o,environmentPicker:s,onProjectChange:c,onWorkspaceChange:l}=e,u=v(AT),d;t[0]===u?d=t[1]:(d=S(u),t[0]=u,t[1]=d);let f=d,p=f.chat.composerContext,m=_(kT),h=_(OT),[g,y]=(0,Q.useState)(``),[b]=Za(g,200),x;t[2]!==h||t[3]!==b||t[4]!==m?(x=[`composer-projects`,h,m,b],t[2]=h,t[3]=b,t[4]=m,t[5]=x):x=t[5];let C;t[6]===b?C=t[7]:(C=()=>mn({status:`active`,search:b,sortBy:`updatedAt`,sortOrder:`desc`,limit:50}),t[6]=b,t[7]=C);let w;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(w={keepPreviousData:!1,shouldRetryOnError:!1},t[8]=w):w=t[8];let T=Qr(x,C,w),E=Df(n,!1),D=E.error?void 0:E.data?.environment,O;t[9]!==D?.rootPath||t[10]!==i?(O=i?.trim()||D?.rootPath||``,t[9]=D?.rootPath,t[10]=i,t[11]=O):O=t[11];let k=O,[A,j]=(0,Q.useState)(null),M;t[12]!==E||t[13]!==l?(M=async e=>{j(null);try{await l(e),await E.mutate()}catch(e){let t=e;j(t instanceof Error?t.message:String(t))}},t[12]=E,t[13]=l,t[14]=M):M=t[14];let N;t[15]!==k||t[16]!==M?(N={initialPath:k,onPicked:M},t[15]=k,t[16]=M,t[17]=N):N=t[17];let P=Ua(N),F=a?`${p.chooseFolder}${k?`: ${k}`:``}`:r?p.projectFolder:p.lockedFolder,I;t[18]===D?I=t[19]:(I=D?.branch||(D?.detached?D.headSha?.slice(0,8):void 0),t[18]=D,t[19]=I);let L=I,R=p.label,z=r&&`bg-surface-hover`,B;t[20]===z?B=t[21]:(B=Y(`flex min-w-0 max-w-full items-center rounded-full`,z),t[20]=z,t[21]=B);let ee;t[22]!==o||t[23]!==f.chat.scopeRemoveProject||t[24]!==c||t[25]!==r?(ee=r?(0,Z.jsx)(`button`,{type:`button`,disabled:o,title:f.chat.scopeRemoveProject,"aria-label":f.chat.scopeRemoveProject,className:Y(TT,`size-7 shrink-0 px-0 ml-0.5 text-fg-muted`),onClick:()=>c(null),children:(0,Z.jsx)(Xt,{className:`size-3.5`,"aria-hidden":!0})}):null,t[22]=o,t[23]=f.chat.scopeRemoveProject,t[24]=c,t[25]=r,t[26]=ee):ee=t[26];let V=r?.id??``,H=r?.name,U;t[27]!==T.data?.items||t[28]!==T.error?(U=T.error?[]:T.data?.items??[],t[27]=T.data?.items,t[28]=T.error,t[29]=U):U=t[29];let W;t[30]===U?W=t[31]:(W=U.map(DT),t[30]=U,t[31]=W);let te=p.chooseProject,ne=p.changeProject,re=p.changeProject,ie=p.noProject,ae=p.searchProjects,oe=T.isLoading,se=T.error?p.projectsFailed:T.data?.items.length===0?p.noProjects:void 0,le=r&&`pl-1`,ue;t[32]===le?ue=t[33]:(ue=Y(TT,`h-8 w-auto max-w-44 gap-1 border-0 bg-transparent pr-2.5 text-sm [&>svg]:hidden [&>span]:text-fg`,le),t[32]=le,t[33]=ue);let de;t[34]!==c||t[35]!==r?.id?(de=e=>{e!==(r?.id??``)&&c(e||null)},t[34]=c,t[35]=r?.id,t[36]=de):de=t[36];let G;t[37]!==p.changeProject||t[38]!==p.chooseProject||t[39]!==p.noProject||t[40]!==p.searchProjects||t[41]!==o||t[42]!==T.isLoading||t[43]!==g||t[44]!==V||t[45]!==H||t[46]!==W||t[47]!==se||t[48]!==ue||t[49]!==de?(G=(0,Z.jsx)(fe,{value:V,selectedLabel:H,options:W,placeholder:te,ariaLabel:ne,title:re,emptyLabel:ie,disabled:o,side:`top`,align:`start`,searchPlaceholder:ae,searchValue:g,onSearchChange:y,loading:oe,statusMessage:se,triggerClassName:ue,contentClassName:`xopc-composer-config-popover w-max min-w-[min(12rem,calc(100vw-1.5rem))] max-w-[min(20rem,calc(100vw-1.5rem))] [&>input]:w-0 [&>input]:min-w-full`,onChange:de}),t[37]=p.changeProject,t[38]=p.chooseProject,t[39]=p.noProject,t[40]=p.searchProjects,t[41]=o,t[42]=T.isLoading,t[43]=g,t[44]=V,t[45]=H,t[46]=W,t[47]=se,t[48]=ue,t[49]=de,t[50]=G):G=t[50];let K;t[51]!==B||t[52]!==ee||t[53]!==G?(K=(0,Z.jsxs)(`div`,{className:B,children:[ee,G]}),t[51]=B,t[52]=ee,t[53]=G,t[54]=K):K=t[54];let q=r?s:null,pe;t[55]!==D||t[56]!==s||t[57]!==r?(pe=!s&&r&&D&&(D.headSha||D.branch)?(0,Z.jsxs)(`span`,{className:`inline-flex h-8 min-w-0 items-center gap-1.5 rounded-full bg-surface-hover px-2.5 text-sm text-fg`,title:D.rootPath,children:[D.kind===`managed_worktree`?(0,Z.jsx)(ks,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}):(0,Z.jsx)(qe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),D.kind===`managed_worktree`?`Worktree`:`Local`]}):null,t[55]=D,t[56]=s,t[57]=r,t[58]=pe):pe=t[58];let me;t[59]!==p.retryProjects||t[60]!==T?(me=T.error?(0,Z.jsx)(`button`,{type:`button`,className:Y(TT,`size-7 px-0`),"aria-label":p.retryProjects,onClick:()=>void T.mutate(),children:(0,Z.jsx)(Pt,{className:`size-3.5`,"aria-hidden":!0})}):null,t[59]=p.retryProjects,t[60]=T,t[61]=me):me=t[61];let J;t[62]!==a||t[63]!==E.isLoading||t[64]!==p.chooseFolder||t[65]!==o||t[66]!==P.pick||t[67]!==P.picking||t[68]!==r||t[69]!==k||t[70]!==F?(J=r?null:(0,Z.jsxs)(`button`,{type:`button`,className:Y(TT,`max-w-52`),disabled:o||!a||P.picking,title:F,"aria-label":p.chooseFolder,onClick:P.pick,children:[(0,Z.jsx)(Ae,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),k?(0,Z.jsx)(`span`,{className:`truncate`,children:Ha(k)}):E.isLoading?(0,Z.jsx)(Qt,{className:`h-4 w-16`}):(0,Z.jsx)(`span`,{children:p.chooseFolder})]}),t[62]=a,t[63]=E.isLoading,t[64]=p.chooseFolder,t[65]=o,t[66]=P.pick,t[67]=P.picking,t[68]=r,t[69]=k,t[70]=F,t[71]=J):J=t[71];let he;t[72]!==L||t[73]!==D?(he=L?(0,Z.jsxs)(`span`,{className:`inline-flex h-8 min-w-0 max-w-44 items-center gap-1.5 px-2 text-sm text-fg`,title:`${L}${D?.headSha?` · ${D.headSha.slice(0,8)}`:``}`,children:[(0,Z.jsx)(Fe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:L})]}):null,t[72]=L,t[73]=D,t[74]=he):he=t[74];let ge;t[75]===A?ge=t[76]:(ge=A?(0,Z.jsx)(`p`,{role:`alert`,className:`w-full px-2 py-1 text-xs text-danger`,children:A}):null,t[75]=A,t[76]=ge);let _e;t[77]!==p.label||t[78]!==K||t[79]!==q||t[80]!==pe||t[81]!==me||t[82]!==J||t[83]!==he||t[84]!==ge?(_e=(0,Z.jsxs)(`div`,{className:`mx-3 -mb-3 flex min-w-0 shrink-0 flex-wrap items-center gap-x-1 gap-y-1 rounded-t-2xl bg-surface-base px-2 pb-4 pt-1.5 sm:mx-4`,"aria-label":R,children:[K,q,pe,me,J,he,ge]}),t[77]=p.label,t[78]=K,t[79]=q,t[80]=pe,t[81]=me,t[82]=J,t[83]=he,t[84]=ge,t[85]=_e):_e=t[85];let ve;t[86]!==f.chat.workingDirectory||t[87]!==P.confirmPick||t[88]!==P.hasNativePicker||t[89]!==P.modalOpen||t[90]!==P.setModalOpen||t[91]!==k?(ve=P.hasNativePicker?null:(0,Z.jsx)(ce,{open:P.modalOpen,onOpenChange:P.setModalOpen,initialAbsolutePath:k||void 0,onConfirm:P.confirmPick,wd:f.chat.workingDirectory}),t[86]=f.chat.workingDirectory,t[87]=P.confirmPick,t[88]=P.hasNativePicker,t[89]=P.modalOpen,t[90]=P.setModalOpen,t[91]=k,t[92]=ve):ve=t[92];let ye;return t[93]!==_e||t[94]!==ve?(ye=(0,Z.jsxs)(Z.Fragment,{children:[_e,ve]}),t[93]=_e,t[94]=ve,t[95]=ye):ye=t[95],ye}function DT(e){return{value:e.id,label:e.name}}function OT(e){return e.baseUrl}function kT(e){return e.conversationId}function AT(e){return e.language}var jT=`flex size-11 shrink-0 items-center justify-center rounded-full text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent sm:size-10`;function MT(e){let t=(0,X.c)(10),{disabled:n,attachmentCount:r,maxAttachments:i,chat:a,onPickFiles:o}=e,s=r>=i,c;t[0]!==a.attachFile||t[1]!==a.maxAttachmentsReached||t[2]!==s||t[3]!==i?(c=s?mm(a.maxAttachmentsReached,{max:i}):a.attachFile,t[0]=a.attachFile,t[1]=a.maxAttachmentsReached,t[2]=s,t[3]=i,t[4]=c):c=t[4];let l=c,u=n||s,d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(Nt,{className:`size-5`,"aria-hidden":!0}),t[5]=d):d=t[5];let f;return t[6]!==l||t[7]!==o||t[8]!==u?(f=(0,Z.jsx)(`button`,{type:`button`,className:jT,disabled:u,"aria-label":l,title:l,onClick:o,children:d}),t[6]=l,t[7]=o,t[8]=u,t[9]=f):f=t[9],f}function NT(e){let t=(0,X.c)(16),{disabled:n,voiceActive:r,runBusy:i,hasDraft:a,chat:o,onStartVoiceInput:s,onSend:c,onAbort:l}=e;if(r)return null;let u=i&&!a,d=u?o.abort:o.sendMessage,f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(Tt,{className:`size-[1.125rem]`,"aria-hidden":!0}),t[0]=f):f=t[0];let p;t[1]!==o.voiceInput||t[2]!==n||t[3]!==s?(p=(0,Z.jsx)(`button`,{type:`button`,className:jT,disabled:n,title:o.voiceInput,"aria-label":o.voiceInput,onClick:s,children:f}),t[1]=o.voiceInput,t[2]=n,t[3]=s,t[4]=p):p=t[4];let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=Y(jT,`bg-accent text-on-accent hover:bg-accent-hover hover:text-on-accent disabled:bg-surface-hover disabled:text-fg-disabled`),t[5]=m):m=t[5];let h=!u&&(n||!a),g=u?l:c,_;t[6]===u?_=t[7]:(_=u?(0,Z.jsx)(Ut,{className:`size-4 fill-current`,"aria-hidden":!0}):(0,Z.jsx)(I,{className:`size-5`,"aria-hidden":!0}),t[6]=u,t[7]=_);let v;t[8]!==d||t[9]!==h||t[10]!==g||t[11]!==_?(v=(0,Z.jsx)(`button`,{type:`button`,className:m,disabled:h,"aria-label":d,title:d,onClick:g,children:_}),t[8]=d,t[9]=h,t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;return t[13]!==p||t[14]!==v?(y=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[p,v]}),t[13]=p,t[14]=v,t[15]=y):y=t[15],y}function PT(e){return e.map(e=>({type:e.type===`voice`?`voice`:(e.mimeType??``).startsWith(`image/`)?`image`:`document`,mimeType:e.mimeType??`application/octet-stream`,content:e.data??``,name:e.name??`file`,size:e.size??0,uri:e.uri,...typeof e.durationSeconds==`number`&&Number.isFinite(e.durationSeconds)&&e.durationSeconds>0?{durationSeconds:e.durationSeconds}:{}}))}var FT=100,IT=400,LT=900;function RT(e,t){switch(t.type){case`reset`:return{box:null,hoverPreview:null};case`set-box`:return{...e,box:t.box};case`set-hover`:return{...e,hoverPreview:t.hoverPreview}}}function zT(e,t){let n=t.trim().toLowerCase();if(!n)return[];let r=e.toLowerCase(),i=[],a=0;for(let e=0;e<r.length&&a<n.length;e++)r[e]===n[a]&&(i.push([e,e+1]),a++);return i}function BT(e){let t=(0,X.c)(8),{name:n,query:r}=e,i;t[0]!==n||t[1]!==r?(i=zT(n,r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i;if(a.length===0){let e;return t[3]===n?e=t[4]:(e=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:n}),t[3]=n,t[4]=e),e}let o;if(t[5]!==n||t[6]!==a){let e=[],r=0;a.forEach(t=>{let[i,a]=t;i>r&&e.push((0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:n.slice(r,i)},`pre-${i}`)),e.push((0,Z.jsx)(`span`,{className:`font-semibold text-accent-fg`,children:n.slice(i,a)},`hl-${i}-${a}`)),r=a}),r<n.length&&e.push((0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:n.slice(r)},`tail`)),o=(0,Z.jsx)(Z.Fragment,{children:e}),t[5]=n,t[6]=a,t[7]=o}else o=t[7];return o}var VT=(0,Q.memo)(function(e){let t=(0,X.c)(42),{open:n,anchorRef:r,items:i,selectedIndex:a,loading:o,query:s,noResults:c,conversationId:l,recentLabel:u,sectionLabels:d,ariaLabel:f,onSelectItem:p}=e,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m={box:null,hoverPreview:null},t[0]=m):m=t[0];let[h,g]=(0,Q.useReducer)(RT,m),_=h.box,v=h.hoverPreview,y=(0,Q.useRef)(null),b=(0,Q.useRef)(0),x=(0,Q.useRef)(null),S;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>{y.current&&=(clearTimeout(y.current),null)},t[1]=S):S=t[1];let C=S,w;t[2]===l?w=t[3]:(w=(e,t,n)=>{C(),b.current+=1;let r=b.current;if(e.kind!==`file`){g({type:`set-hover`,hoverPreview:null});return}let i=e.relativePath;if(!l?.trim()||e.isDirectory||e.isBrowseUp||!i){g({type:`set-hover`,hoverPreview:null});return}y.current=setTimeout(()=>{y.current=null,r===b.current&&Ka(i,{conversationId:l}).then(e=>{let{content:i}=e,a=i.length>LT?`${i.slice(0,LT)}…`:i;r===b.current&&g({type:`set-hover`,hoverPreview:{text:a,x:t,y:n}})}).catch(()=>{r===b.current&&g({type:`set-hover`,hoverPreview:null})})},420)},t[2]=l,t[3]=w);let T=w,E,D;t[4]!==r||t[5]!==n?(E=()=>{if(!n){g({type:`reset`}),C(),b.current+=1;return}let e=()=>{let e=r.current;if(!e)return;let t=e.getBoundingClientRect();g({type:`set-box`,box:{left:t.left,top:t.top,width:t.width}})};e();let t=r.current,i=t&&typeof ResizeObserver<`u`?new ResizeObserver(()=>{e()}):null;return t&&i&&i.observe(t),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{t&&i&&i.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},D=[n,r],t[4]=r,t[5]=n,t[6]=E,t[7]=D):(E=t[6],D=t[7]),(0,Q.useLayoutEffect)(E,D);let O,k;if(t[8]!==i.length||t[9]!==n||t[10]!==a?(O=()=>{!n||a<0||a>=i.length||(x.current?.querySelector(`#at-mention-${a}`))?.scrollIntoView({block:`nearest`})},k=[n,a,i.length],t[8]=i.length,t[9]=n,t[10]=a,t[11]=O,t[12]=k):(O=t[11],k=t[12]),(0,Q.useLayoutEffect)(O,k),!n||typeof document>`u`||_===null)return null;let A=i.length,j=Math.min(_.width,IT),N;t[13]!==_.left||t[14]!==_.top||t[15]!==j?(N={position:`fixed`,left:_.left,top:_.top,width:j,transform:`translateY(calc(-100% - 8px))`,zIndex:FT},t[13]=_.left,t[14]=_.top,t[15]=j,t[16]=N):N=t[16];let P=a>=0&&a<A?`at-mention-${a}`:void 0,F;t[17]!==o||t[18]!==A?(F=o&&A===0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5 text-sm text-fg-muted`,children:[(0,Z.jsx)(Ze,{className:`size-4 shrink-0 animate-spin`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:`…`})]}):null,t[17]=o,t[18]=A,t[19]=F):F=t[19];let I;t[20]!==i||t[21]!==o||t[22]!==c||t[23]!==p||t[24]!==s||t[25]!==u||t[26]!==T||t[27]!==d||t[28]!==a||t[29]!==A?(I=!o&&A===0?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-sm text-fg-muted`,children:c}):(0,Z.jsxs)(Z.Fragment,{children:[i.map((e,t)=>{let n=i[t-1]?.kind,r=d[e.kind],o=e.kind===`file`&&e.isRecent;return(0,Z.jsxs)(Q.Fragment,{children:[n===e.kind?null:(0,Z.jsx)(`div`,{className:`border-t border-edge-subtle px-3 pb-1 pt-2 text-[0.65rem] font-medium uppercase tracking-wide text-fg-muted first:border-t-0`,children:r}),(0,Z.jsxs)(`div`,{id:`at-mention-${t}`,role:`option`,"aria-selected":a===t,tabIndex:-1,className:Y(`flex cursor-pointer items-start gap-2 px-3 py-2 text-left text-sm`,a===t?`bg-surface-hover text-fg`:`text-fg-subtle hover:bg-surface-hover/80`,o&&`border-l-2 border-l-accent/60`),onPointerDown:t=>{t.pointerType===`mouse`&&t.button!==0||(t.preventDefault(),p(e))},onPointerEnter:t=>T(e,t.clientX,t.clientY),onPointerLeave:()=>{C(),b.current+=1,g({type:`set-hover`,hoverPreview:null})},children:[(0,Z.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:e.kind===`note`?(0,Z.jsx)(Os,{className:`size-3.5 text-accent-fg`,"aria-hidden":!0}):e.kind===`session`?(0,Z.jsx)(wt,{className:`size-3.5 text-violet-600 dark:text-violet-400`,"aria-hidden":!0}):e.kind===`skill`?(0,Z.jsx)(Ht,{className:`size-3.5 text-cyan-600 dark:text-cyan-400`,"aria-hidden":!0}):e.kind===`agent`?(0,Z.jsx)(ne,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):e.kind===`browser_tab`?(0,Z.jsx)(M,{className:`size-3.5 text-blue-600 dark:text-blue-400`,"aria-hidden":!0}):e.isBrowseUp?(0,Z.jsx)(je,{className:`size-3.5 text-fg-muted`,"aria-hidden":!0}):e.isDirectory?(0,Z.jsx)(je,{className:`size-3.5 text-amber-600 dark:text-amber-400`,"aria-hidden":!0}):(0,Z.jsx)(Oe,{className:Y(`size-3.5`,be(e.name)),"aria-hidden":!0})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:(0,Z.jsx)(BT,{name:e.name,query:s})}),o?(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-accent-soft px-1 py-0 text-[0.65rem] text-accent-fg`,children:u}):null]}),(0,Z.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:e.description||r})]})]})]},e.id)}),o&&A>0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-edge-subtle px-3 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(Ze,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:`…`})]}):null]}),t[20]=i,t[21]=o,t[22]=c,t[23]=p,t[24]=s,t[25]=u,t[26]=T,t[27]=d,t[28]=a,t[29]=A,t[30]=I):I=t[30];let L;t[31]!==f||t[32]!==F||t[33]!==I||t[34]!==P?(L=(0,Z.jsxs)(`div`,{ref:x,className:`max-h-[min(26rem,54vh)] overflow-y-auto`,role:`listbox`,"aria-label":f,"aria-activedescendant":P,children:[F,I]}),t[31]=f,t[32]=F,t[33]=I,t[34]=P,t[35]=L):L=t[35];let R;t[36]===v?R=t[37]:(R=v?(0,Z.jsx)(`div`,{className:`pointer-events-none fixed z-[200] max-h-48 max-w-sm overflow-auto rounded-md border border-edge bg-surface-overlay p-2 font-mono text-[0.7rem] text-fg shadow-lg`,style:{left:Math.min(v.x+12,window.innerWidth-320),top:Math.min(v.y+12,window.innerHeight-200)},children:v.text}):null,t[36]=v,t[37]=R);let z;return t[38]!==L||t[39]!==R||t[40]!==N?(z=(0,Us.createPortal)((0,Z.jsxs)(`div`,{"data-composer-picker-panel":!0,className:`pointer-events-auto max-h-[min(28rem,60vh)] min-h-[2.5rem] overflow-hidden rounded-lg border border-edge bg-surface-overlay shadow-lg`,style:N,role:`presentation`,children:[L,R]}),document.body),t[38]=L,t[39]=R,t[40]=N,t[41]=z):z=t[41],z});function HT(e,t){let n=e=>{e!==!1&&(e&&typeof e==`object`?t(e.conversationId):t())};e instanceof Promise?e.then(n).catch(e=>{ya(`error`,e instanceof Error?e.message:String(e))}):n(e)}var UT=new Set([`abort`,`stop`,`cancel`]);function WT(e){if(e.kind!==`command`)return!1;if(UT.has(e.name.toLowerCase()))return!0;for(let t of e.aliases??[])if(UT.has(t.toLowerCase()))return!0;return!1}function GT(e,t,n,r){return e.slice(0,t)+r+e.slice(n)}var KT=(e,t)=>{let n=t.slashRange;if(!n)return;if(e.availability.status!==`available`){t.callbacks.onUnavailableSkill?.(e);return}let r=`/skill:${e.canonicalName} `,i=GT(t.editor.valueRef.current,n.start,n.end,r),a=n.start+r.length;t.editor.resetEditor({nextText:i,caretOffset:a,focus:!0})},qT=(e,t)=>{let n=t.slashRange;if(!n||n.start!==0)return;if(e.name.toLowerCase()===`review`&&t.callbacks.onReviewLauncher&&!t.runBusy&&t.pendingFollowUpsCount===0){let e=t.editor.valueRef.current,r=e.slice(0,n.start)+e.slice(n.end);t.editor.resetEditor({nextText:r,caretOffset:n.start,focus:!0}),t.callbacks.onReviewLauncher();return}if(e.acceptsArgs===!0){let r=`/${e.name} `,i=GT(t.editor.valueRef.current,n.start,n.end,r),a=n.start+r.length;t.editor.resetEditor({nextText:i,caretOffset:a,focus:!0});return}let r=`/${e.name}`;if(t.runBusy||t.pendingFollowUpsCount>0){if(WT(e)){if(!t.callbacks.onAbort)return;t.callbacks.onAbort();let e=t.editor.valueRef.current,r=e.slice(0,n.start)+e.slice(n.end);t.editor.resetEditor({nextText:r,caretOffset:n.start});return}if(!t.callbacks.onAddPendingFollowUp||t.pendingFollowUpsCount>=t.maxPendingFollowUps)return;t.contextRefs.current.length?t.callbacks.onAddPendingFollowUp(r,void 0,t.contextRefs.current):t.callbacks.onAddPendingFollowUp(r,void 0),t.callbacks.onUserTextCommitted?.(r),t.attachments.clearAttachments(),t.contextRefs.clear(),t.editor.resetEditor();return}HT(t.contextRefs.current.length?t.callbacks.onSend(r,void 0,t.thinkingLevel,t.contextRefs.current):t.callbacks.onSend(r,void 0,t.thinkingLevel),e=>{e===void 0?t.callbacks.onUserTextCommitted?.(r):t.callbacks.onUserTextCommitted?.(r,e),t.attachments.clearAttachments(),t.contextRefs.clear(),t.editor.resetEditor()})},JT=(e,t)=>{let n=t.slashRange;if(!n||n.start!==0||!t.callbacks.onChatAgentChange)return;let r=t.editor.valueRef.current,i=r.slice(n.end),a=r.slice(0,n.start)+(i.startsWith(` `)?i.slice(1):i);t.editor.resetEditor({nextText:a,caretOffset:n.start}),t.callbacks.onChatAgentChange(e.agentId)};function YT(e,t){switch(e.kind){case`skill`:KT(e,t);return;case`command`:qT(e,t);return;case`agent`:JT(e,t)}}var XT={new:10,help:11,list:12,clear:13,switch:14,models:15,usage:16,skills:17,settings:18,start:19,think:20,reasoning:21,verbose:22,status:23,tts:24},ZT=new Set([`abort`,`archive`]);function QT(e){if(e.kind===`command`){let t=e.name.toLowerCase();if(XT[t]!==void 0)return 0;if(ZT.has(t))return 2}return 1}function $T(e,t){let n=QT(e),r=QT(t);if(n!==r)return n-r;if(n===0){let n=XT[e.name.toLowerCase()]??999,r=XT[t.name.toLowerCase()]??999;if(n!==r)return n-r}let i=e.name.localeCompare(t.name);return i===0?e.id.localeCompare(t.id):i}function eE(e){if(e.kind!==`command`)return!1;if(UT.has(e.name.toLowerCase()))return!0;for(let t of e.aliases??[])if(UT.has(t.toLowerCase()))return!0;return!1}function tE(e,t){return e.kind!==`command`||e.acceptsArgs===!0||eE(e)||!(t.runBusy||t.pendingFollowUpsCount>0)?!1:t.pendingFollowUpsCount>=t.maxPendingFollowUps}function nE(e,t){return e.kind!==`command`||e.acceptsArgs===!0||eE(e)||!(t.runBusy||t.pendingFollowUpsCount>0)?!1:t.pendingFollowUpsCount<t.maxPendingFollowUps}function rE(e){return e.includes(`/`)||/^[A-Za-z]:/u.test(e)?!0:/^(Users|home|var|tmp|etc|opt|private|Volumes|System|Applications|Library|usr|dev|bin|sbin|proc|sys)(\/|$)/iu.test(e)}function iE(e,t){if(t===0)return!1;let n=e[t-1];if(n===void 0||n===`.`||n===`:`||n===`/`)return!0;let r=e.slice(0,t);return/[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+$/u.test(r)}function aE(e,t){let n=e.length,r=Math.min(Math.max(t,0),n);if(r<1&&e===`/`&&(r=1),r<1)return null;let i=e.slice(0,r).match(/\/[^\s]*$/);if(!i||i.index===void 0)return null;let a=i.index;if(iE(e,a))return null;let o=i[0],s=o.slice(1);return rE(s)||o.startsWith(`/skill:`)?null:{start:i.index,end:r,query:s}}function oE(e,t){let n=t.trim().toLowerCase();if(!n)return 0;let r=e.name.toLowerCase();if(r===n)return 0;for(let t of e.aliases??[])if(t.toLowerCase()===n)return 1;if(r.startsWith(n))return 2;for(let t of e.aliases??[])if(t.toLowerCase().startsWith(n))return 3;if(r.includes(n))return 4;for(let t of e.aliases??[])if(t.toLowerCase().includes(n))return 5;if(e.description.toLowerCase().includes(n))return 100;if(e.category.toLowerCase().includes(n))return 101;if(e.kind===`skill`&&(e.source??``).toLowerCase().includes(n))return 102;if(e.kind===`skill`){for(let t of e.searchTerms??[])if(t.toLowerCase().includes(n))return 103}return null}function sE(e,t){return t===0?0:Math.min(e,t-1)}function cE(e,t){let{query:n,value:r,commandsAllowed:i,agentsAllowed:a}=t,o=n.trim()===``,s=Mp(r),c=[];for(let r of e){if(r.kind===`command`&&!i||r.kind===`agent`&&!a||r.kind===`skill`&&t.skillsAllowed===!1||r.kind===`skill`&&s.has(r.canonicalName)||r.kind===`skill`&&o&&r.availability.status!==`available`)continue;let e=oE(r,n);e!==null&&c.push({item:r,rank:e})}c.sort((e,t)=>{let n=e.item.kind===`skill`&&e.item.availability.status!==`available`;return n===(t.item.kind===`skill`&&t.item.availability.status!==`available`)?e.rank===t.rank?$T(e.item,t.item):e.rank-t.rank:n?1:-1});let l=c.map(e=>e.item),u=[],d=l.filter(e=>e.kind===`skill`),f=l.filter(e=>e.kind===`command`),p=l.filter(e=>e.kind===`agent`);d.length>0&&u.push({kind:`skill`,items:d}),f.length>0&&u.push({kind:`command`,items:f}),p.length>0&&u.push({kind:`agent`,items:p});let m=[];for(let e of u)m.push(...e.items);return{sections:u,flatItems:m}}function lE(e,t,n){let r=(0,X.c)(49),[i,a]=(0,Q.useState)(0),[o,s]=(0,Q.useState)(0),c=v(fE),l=n?.capabilities??pp,u=l.commands||l.skills||l.agentSwitch;n?.isComposing;let d;r[0]!==t||r[1]!==u||r[2]!==n?.isComposing||r[3]!==e?(d=!u||n?.isComposing?null:aE(e,t),r[0]=t,r[1]=u,r[2]=n?.isComposing,r[3]=e,r[4]=d):d=r[4];let f=d,p=!!(f&&!n?.suppress),m,h;r[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=e=>{let t=e.detail;t&&typeof t==`object`&&`section`in t&&(t.section===`skills`||t.section===`agents`)&&s(dE)};return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},h=[],r[5]=m,r[6]=h):(m=r[5],h=r[6]),(0,Q.useEffect)(m,h);let g;r[7]!==c||r[8]!==n?.conversationId||r[9]!==n?.currentAgentId?(g=async()=>{let[e,t,r]=await Promise.allSettled([Do(),So(n?.currentAgentId,n?.conversationId),si()]),i=[];t.status===`rejected`&&i.push(`skill`),e.status===`rejected`&&i.push(`command`),r.status===`rejected`&&i.push(`agent`);let a=(e.status===`fulfilled`?e.value:[]).map(uE),o=(t.status===`fulfilled`?t.value.skills:[]).map(e=>{let t=Oo(e,c);return{kind:`skill`,id:`skill:${e.name}`,name:t.displayName,canonicalName:e.name,description:t.description,aliases:t.aliases,searchTerms:t.searchTerms,category:`skill`,source:e.source,availability:{status:e.availableForCurrentAgent?`available`:e.unavailableReason??`agent-denied`,reason:e.unavailableReason??void 0}}}),s=S(c).agentsSettings,l=r.status===`fulfilled`?r.value:null,u=l&&l.items.length>1?l.items.map(e=>({kind:`agent`,id:`agent:${e.id}`,agentId:e.id,name:es(e,s),description:ts(e,s),category:`agent`,...e.avatar?{avatar:e.avatar}:{},aliases:[e.id,...e.name?[e.name]:[]]})):[];return{items:[...o,...a,...u],failedKinds:i}},r[7]=c,r[8]=n?.conversationId,r[9]=n?.currentAgentId,r[10]=g):g=r[10];let _=n?.currentAgentId,y=n?.conversationId,b;r[11]!==c||r[12]!==o||r[13]!==_||r[14]!==y?(b=[c,_,y,o],r[11]=c,r[12]=o,r[13]=_,r[14]=y,r[15]=b):b=r[15];let x;r[16]===Symbol.for(`react.memo_cache_sentinel`)?(x=[],r[16]=x):x=r[16];let C;r[17]===Symbol.for(`react.memo_cache_sentinel`)?(C=[],r[17]=C):C=r[17];let w,T;r[18]===Symbol.for(`react.memo_cache_sentinel`)?(T={items:x,failedKinds:C},w=[],r[18]=w,r[19]=T):(w=r[18],T=r[19]);let E;r[20]===Symbol.for(`react.memo_cache_sentinel`)?(E=[],r[20]=E):E=r[20];let D;r[21]===Symbol.for(`react.memo_cache_sentinel`)?(D={items:w,failedKinds:E},r[21]=D):D=r[21];let O;r[22]===p?O=r[23]:(O={enabled:p,initial:T,errorData:D},r[22]=p,r[23]=O);let k=Da(g,b,O),A=k.data.items,j=k.error==null?null:k.error instanceof Error?k.error.message:String(k.error),M=f?.query??``,N=l.commands&&f!==null&&f.start===0,P=l.agentSwitch&&f!==null&&f.start===0,F;r[24]!==P||r[25]!==A||r[26]!==l.skills||r[27]!==N||r[28]!==M||r[29]!==e?(F=cE(A,{query:M,value:e,commandsAllowed:N,agentsAllowed:P,skillsAllowed:l.skills}),r[24]=P,r[25]=A,r[26]=l.skills,r[27]=N,r[28]=M,r[29]=e,r[30]=F):F=r[30];let{sections:I,flatItems:L}=F,R=f?M:``,z=(0,Q.useRef)(R);z.current!==R&&(z.current=R,i!==0&&a(0));let B;r[31]!==L.length||r[32]!==i?(B=sE(i,L.length),r[31]=L.length,r[32]=i,r[33]=B):B=r[33];let ee=B,V;r[34]===L.length?V=r[35]:(V=e=>{L.length!==0&&a(t=>e===`down`?(t+1)%L.length:(t-1+L.length)%L.length)},r[34]=L.length,r[35]=V);let H=V,U;return r[36]!==P||r[37]!==N||r[38]!==L||r[39]!==k.data.failedKinds||r[40]!==k.loading||r[41]!==j||r[42]!==H||r[43]!==p||r[44]!==M||r[45]!==ee||r[46]!==I||r[47]!==f?(U={open:p,slashRange:f,commandsAllowed:N,agentsAllowed:P,sections:I,flatItems:L,selectedIndex:ee,query:M,loading:k.loading,failedKinds:k.data.failedKinds,loadError:j,onNavigate:H,setSelectedIndex:a},r[36]=P,r[37]=N,r[38]=L,r[39]=k.data.failedKinds,r[40]=k.loading,r[41]=j,r[42]=H,r[43]=p,r[44]=M,r[45]=ee,r[46]=I,r[47]=f,r[48]=U):U=r[48],U}function uE(e){return{kind:`command`,id:`cmd:${e.id}`,name:e.name,description:e.description,category:e.category,aliases:e.aliases,acceptsArgs:e.acceptsArgs,acceptsContext:e.acceptsContext,examples:e.examples}}function dE(e){return e+1}function fE(e){return e.language}var pE=100,mE=560;function hE(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase().indexOf(n);if(r>=0)return(0,Z.jsxs)(Z.Fragment,{children:[e.slice(0,r),(0,Z.jsx)(`span`,{className:`text-accent-fg`,children:e.slice(r,r+n.length)}),e.slice(r+n.length)]});let i=[],a=0,o=0;for(let t of e){let e=n[a],r=`${String(o)}-${t}`;e!==void 0&&t.toLowerCase()===e?(i.push((0,Z.jsx)(`span`,{className:`text-accent-fg`,children:t},r)),a+=1):i.push((0,Z.jsx)(Q.Fragment,{children:t},r)),o+=1}return(0,Z.jsx)(Z.Fragment,{children:i})}function gE(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase().indexOf(n);return r<0?e:(0,Z.jsxs)(Z.Fragment,{children:[e.slice(0,r),(0,Z.jsx)(`span`,{className:`text-accent-fg`,children:e.slice(r,r+n.length)}),e.slice(r+n.length)]})}var _E=(0,Q.memo)(function(e){let t=(0,X.c)(46),{item:n,index:r,selectedIndex:i,showHighlight:a,filterQuery:o,currentAgentId:s,currentBadgeLabel:c,runBusy:l,pendingFollowUpsCount:u,maxPendingFollowUps:d,queueBadgeLabel:f,queueFullBadgeLabel:p,queueFullTooltip:m,skillUnavailableLabel:h,skillAgentDeniedLabel:g,skillSourceLabels:_,onSelectItem:v}=e,y=n.kind===`skill`,b=n.kind===`agent`,x;t[0]!==b||t[1]!==y||t[2]!==n.agentId||t[3]!==n.avatar?(x=b?(0,Z.jsx)(Aa,{agentId:n.agentId,avatar:n.avatar,size:18,className:`size-[18px] shrink-0`}):y?(0,Z.jsx)(Ht,{className:`size-4 shrink-0 text-accent-fg`,"aria-hidden":!0}):(0,Z.jsx)(Zt,{className:`size-4 shrink-0 text-amber-600 dark:text-amber-400`,"aria-hidden":!0}),t[0]=b,t[1]=y,t[2]=n.agentId,t[3]=n.avatar,t[4]=x):x=t[4];let S=x,C;t[5]!==o||t[6]!==b||t[7]!==n.name||t[8]!==a?(C=b?a?(0,Z.jsx)(Z.Fragment,{children:hE(n.name,o)}):(0,Z.jsx)(`span`,{className:`text-fg`,children:n.name}):a?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-fg`,children:`/`}),hE(n.name,o)]}):(0,Z.jsxs)(`span`,{className:`text-fg`,children:[`/`,n.name]}),t[5]=o,t[6]=b,t[7]=n.name,t[8]=a,t[9]=C):C=t[9];let w=C,T=b&&s!=null&&s.length>0&&n.agentId===s,E=y&&n.availability.status!==`available`,D,O;if(t[10]!==n||t[11]!==d||t[12]!==u||t[13]!==l){let e={runBusy:l,pendingFollowUpsCount:u,maxPendingFollowUps:d};O=nE(n,e),D=tE(n,e),t[10]=n,t[11]=d,t[12]=u,t[13]=l,t[14]=D,t[15]=O}else D=t[14],O=t[15];let k=D,A=null;if(T){let e;t[16]===c?e=t[17]:(e=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-accent-soft px-1 py-px text-[0.6rem] font-medium leading-none text-accent-fg`,"aria-label":c,children:c}),t[16]=c,t[17]=e),A=e}else if(E){let e=n.availability.reason??`unavailable`,r=n.availability.status===`agent-denied`?g:h,i;t[18]!==e||t[19]!==r?(i=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-surface-hover px-1 py-px text-[0.6rem] font-medium leading-none text-fg-muted`,"aria-label":e,children:r}),t[18]=e,t[19]=r,t[20]=i):i=t[20],A=i}else if(y&&n.source){let e=_[n.source]??n.source,r;t[21]===e?r=t[22]:(r=(0,Z.jsx)(`span`,{className:`ml-2 shrink-0 text-[11px] font-normal text-fg-muted`,children:e}),t[21]=e,t[22]=r),A=r}else if(k){let e;t[23]===p?e=t[24]:(e=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-red-100 px-1 py-px text-[0.6rem] font-medium leading-none text-red-700 dark:bg-red-900/40 dark:text-red-300`,"aria-label":p,children:p}),t[23]=p,t[24]=e),A=e}else if(O){let e;t[25]===f?e=t[26]:(e=(0,Z.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-surface-hover px-1 py-px text-[0.6rem] font-medium leading-none text-fg-muted`,"aria-label":f,children:f}),t[25]=f,t[26]=e),A=e}let j=i===r,M=`palette-${r}`,N;t[27]!==o||t[28]!==n.description||t[29]!==a?(N=n.description?a?gE(n.description,o):n.description:null,t[27]=o,t[28]=n.description,t[29]=a,t[30]=N):N=t[30];let P=k?m:void 0,F;t[31]!==n||t[32]!==v?(F=()=>v(n),t[31]=n,t[32]=v,t[33]=F):F=t[33];let I;return t[34]!==S||t[35]!==k||t[36]!==n||t[37]!==w||t[38]!==a||t[39]!==j||t[40]!==M||t[41]!==N||t[42]!==P||t[43]!==F||t[44]!==A?(I=(0,Z.jsx)(yE,{item:n,icon:S,selected:j,id:M,nameLine:w,descriptionLine:N,dimCategoryBadge:a,trailingBadge:A,disabled:k,disabledTooltip:P,onSelect:F}),t[34]=S,t[35]=k,t[36]=n,t[37]=w,t[38]=a,t[39]=j,t[40]=M,t[41]=N,t[42]=P,t[43]=F,t[44]=A,t[45]=I):I=t[45],I}),vE=(0,Q.memo)(function(e){let t=(0,X.c)(53),{open:n,anchorRef:r,sections:i,flatItems:a,loading:o,failedKinds:s,selectedIndex:c,noResults:l,sectionLoadFailedLabel:u,query:d,skillsLabel:f,commandsLabel:p,agentsLabel:m,currentAgentId:h,currentBadgeLabel:g,runBusy:_,pendingFollowUpsCount:v,maxPendingFollowUps:y,queueBadgeLabel:b,queueFullBadgeLabel:x,queueFullTooltip:S,skillUnavailableLabel:C,skillAgentDeniedLabel:w,skillSourceLabels:T,onSelectItem:E,panelRef:D}=e,[O,k]=(0,Q.useState)(null),A,j;t[0]!==r||t[1]!==n?(A=()=>{if(!n){k(null);return}let e=()=>{let e=r.current;if(!e)return;let t=e.getBoundingClientRect();k({left:t.left,top:t.top,width:t.width})};e();let t=r.current,i=t&&typeof ResizeObserver<`u`?new ResizeObserver(()=>{e()}):null;return t&&i&&i.observe(t),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{t&&i&&i.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},j=[n,r],t[0]=r,t[1]=n,t[2]=A,t[3]=j):(A=t[2],j=t[3]),(0,Q.useLayoutEffect)(A,j);let M,N;if(t[4]!==a.length||t[5]!==n||t[6]!==c?(M=()=>{!n||a.length===0||document.getElementById(`palette-${c}`)?.scrollIntoView?.({block:`nearest`})},N=[a.length,n,c],t[4]=a.length,t[5]=n,t[6]=c,t[7]=M,t[8]=N):(M=t[7],N=t[8]),(0,Q.useEffect)(M,N),!n||typeof document>`u`||O===null)return null;let P=a.length,F=a[c],I=Math.min(O.width,mE),L;t[9]===d?L=t[10]:(L=d.trim(),t[9]=d,t[10]=L);let R=L,z=R.length>0,B;t[11]!==m||t[12]!==p||t[13]!==f?(B={skill:f,command:p,agent:m},t[11]=m,t[12]=p,t[13]=f,t[14]=B):B=t[14];let ee=B,V;t[15]!==h||t[16]!==g||t[17]!==R||t[18]!==y||t[19]!==E||t[20]!==v||t[21]!==b||t[22]!==x||t[23]!==S||t[24]!==_||t[25]!==c||t[26]!==z||t[27]!==w||t[28]!==T||t[29]!==C?(V={selectedIndex:c,showHighlight:z,filterQuery:R,currentAgentId:h,currentBadgeLabel:g,runBusy:_,pendingFollowUpsCount:v,maxPendingFollowUps:y,queueBadgeLabel:b,queueFullBadgeLabel:x,queueFullTooltip:S,skillUnavailableLabel:C,skillAgentDeniedLabel:w,skillSourceLabels:T,onSelectItem:E},t[15]=h,t[16]=g,t[17]=R,t[18]=y,t[19]=E,t[20]=v,t[21]=b,t[22]=x,t[23]=S,t[24]=_,t[25]=c,t[26]=z,t[27]=w,t[28]=T,t[29]=C,t[30]=V):V=t[30];let H=V,U;if(t[31]!==s||t[32]!==o||t[33]!==l||t[34]!==H||t[35]!==ee||t[36]!==u||t[37]!==i||t[38]!==P){let e=new Map(i.map(bE)),n=[`skill`,`command`,`agent`].filter(t=>e.has(t)||s.includes(t)),r=0;U=o&&P===0?(0,Z.jsx)(`div`,{className:`space-y-2 p-2.5`,"aria-busy":`true`,children:Array.from({length:6},xE)}):P===0&&s.length===0?(0,Z.jsx)(`div`,{className:`p-2.5 text-xs leading-normal text-fg-muted`,children:l}):n.map((t,n)=>{let i=e.get(t)?.items??[],a=r;r+=i.length;let o=`palette-section-${t}`;return(0,Z.jsxs)(`div`,{role:`group`,"aria-labelledby":o,className:Y(n>0&&`border-t border-edge-subtle`),children:[(0,Z.jsxs)(`div`,{id:o,className:`sticky top-0 z-10 flex items-center justify-between bg-surface-overlay px-2.5 py-2 text-[0.65rem] font-medium uppercase leading-none tracking-wide text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:ee[t]}),(0,Z.jsx)(`span`,{className:`tabular-nums`,"aria-hidden":!0,children:i.length})]}),s.includes(t)?(0,Z.jsx)(`div`,{className:`px-2.5 pb-2 text-[11px] leading-relaxed text-fg-muted`,children:u}):i.map((e,t)=>(0,Z.jsx)(_E,{item:e,index:a+t,...H},e.id))]},t)}),t[31]=s,t[32]=o,t[33]=l,t[34]=H,t[35]=ee,t[36]=u,t[37]=i,t[38]=P,t[39]=U}else U=t[39];let W=U,te;t[40]!==O.left||t[41]!==O.top||t[42]!==I?(te={position:`fixed`,left:O.left,top:O.top,width:I,transform:`translateY(calc(-100% - 8px))`,zIndex:pE},t[40]=O.left,t[41]=O.top,t[42]=I,t[43]=te):te=t[43];let ne=`${f}, ${p}, ${m}`,re=F?`${ee[F.kind]}: ${F.name}`:``,ie;t[44]===re?ie=t[45]:(ie=(0,Z.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:re}),t[44]=re,t[45]=ie);let ae;return t[46]!==W||t[47]!==o||t[48]!==D||t[49]!==ne||t[50]!==ie||t[51]!==te?(ae=(0,Us.createPortal)((0,Z.jsx)(Qa,{delayDuration:0,skipDelayDuration:0,disableHoverableContent:!1,children:(0,Z.jsxs)(`div`,{ref:D,className:`pointer-events-auto max-h-[min(32rem,60vh)] min-h-8 overflow-y-auto rounded-md border border-edge bg-surface-overlay text-xs leading-4 shadow-lg`,style:te,role:`listbox`,"aria-label":ne,"aria-busy":o,children:[ie,W]})}),document.body),t[46]=W,t[47]=o,t[48]=D,t[49]=ne,t[50]=ie,t[51]=te,t[52]=ae):ae=t[52],ae}),yE=(0,Q.memo)(function(e){let t=(0,X.c)(39),{item:n,icon:r,selected:i,id:a,nameLine:o,descriptionLine:s,dimCategoryBadge:c,trailingBadge:l,disabled:u,disabledTooltip:d,onSelect:f}=e,p;t[0]===n.description?p=t[1]:(p=n.description.trim(),t[0]=n.description,t[1]=p);let m=p,h=m.length>0&&s!=null,g=m.length>0,_=n.description,v=n.category&&n.kind!==`skill`&&!c&&!(n.kind===`agent`&&l),y;t[2]===o?y=t[3]:(y=(0,Z.jsx)(`span`,{className:`min-w-0 max-w-[min(12rem,46%)] shrink-0 truncate font-semibold text-fg`,children:o}),t[2]=o,t[3]=y);let b;t[4]!==n.category||t[5]!==v?(b=v?(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 py-px text-[0.6rem] font-normal leading-none text-fg-muted`,children:n.category}):null,t[4]=n.category,t[5]=v,t[6]=b):b=t[6];let x;t[7]!==s||t[8]!==h?(x=h?(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-normal leading-tight text-fg-muted`,children:s}):null,t[7]=s,t[8]=h,t[9]=x):x=t[9];let S;t[10]!==y||t[11]!==b||t[12]!==x?(S=(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-baseline gap-1`,children:[y,b,x]}),t[10]=y,t[11]=b,t[12]=x,t[13]=S):S=t[13];let C=S,w=u?`cursor-not-allowed opacity-50 text-fg-muted`:i?`cursor-pointer bg-surface-hover text-fg`:`cursor-pointer text-fg-subtle hover:bg-surface-hover/80`,T;t[14]===w?T=t[15]:(T=Y(`flex min-h-11 w-full min-w-0 items-center gap-2 px-2.5 py-1.5 text-left text-sm leading-5 sm:min-h-9`,w),t[14]=w,t[15]=T);let E=T,D;t[16]!==u||t[17]!==f?(D=e=>{u||e.pointerType===`mouse`&&e.button!==0||(e.preventDefault(),f())},t[16]=u,t[17]=f,t[18]=D):D=t[18];let O=D,k;t[19]===r?k=t[20]:(k=(0,Z.jsx)(`span`,{className:`shrink-0 [&_svg]:align-middle`,children:r}),t[19]=r,t[20]=k);let A;t[21]!==k||t[22]!==C||t[23]!==l?(A=(0,Z.jsxs)(Z.Fragment,{children:[k,C,l]}),t[21]=k,t[22]=C,t[23]=l,t[24]=A):A=t[24];let j=A,M=u&&d?d:g?_:null,N=u||void 0,P;t[25]!==a||t[26]!==O||t[27]!==E||t[28]!==j||t[29]!==i||t[30]!==N?(P=(0,Z.jsx)(`div`,{id:a,role:`option`,"aria-selected":i,"aria-disabled":N,tabIndex:-1,className:E,onPointerDown:O,children:j}),t[25]=a,t[26]=O,t[27]=E,t[28]=j,t[29]=i,t[30]=N,t[31]=P):P=t[31];let F=P;if(M!==null){let e;t[32]===F?e=t[33]:(e=(0,Z.jsx)(no,{asChild:!0,children:F}),t[32]=F,t[33]=e);let n;t[34]===M?n=t[35]:(n=(0,Z.jsx)($a,{children:(0,Z.jsx)(to,{side:`right`,align:`start`,sideOffset:8,collisionPadding:12,className:`!z-[10000] max-h-[min(12rem,40vh)] max-w-sm overflow-y-auto rounded-md border border-edge bg-surface-overlay px-2 py-1.5 text-left text-[11px] leading-snug text-fg shadow-lg select-text [max-width:min(20rem,90vw)]`,"data-slash-palette-tooltip":``,children:(0,Z.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:M})})}),t[34]=M,t[35]=n);let r;return t[36]!==e||t[37]!==n?(r=(0,Z.jsxs)(eo,{delayDuration:0,children:[e,n]}),t[36]=e,t[37]=n,t[38]=r):r=t[38],r}return F});function bE(e){return[e.kind,e]}function xE(e,t){return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,Z.jsx)(Qt,{className:`size-4 shrink-0`}),(0,Z.jsx)(Qt,{className:`h-3 w-28`}),(0,Z.jsx)(Qt,{className:`h-3 flex-1`})]},t)}var SE=new Map;function CE(e){let t=SE.get(e);return t||(t={items:[],loadPromise:null,loaded:!1,writeQueue:Promise.resolve(),mutationVersion:0,clearVersion:0},SE.set(e,t)),t}function wE(e,t){if(e.items[0]?.text===t.text){t.id>0&&(e.items[0]=t);return}e.items=[t,...e.items].slice(0,100)}function TE(e,t){if(e.items.some(e=>e.id===t.id))return;let n=e.items.findIndex(e=>e.id===0&&e.text===t.text);if(n>=0){e.items[n]=t;return}wE(e,t)}function EE(e){return CE(e).items.map(e=>e.text)}function DE(e,t=!1){let n=CE(e);if(n.loaded&&!t)return Promise.resolve();if(n.loadPromise)return n.loadPromise;let r=n.mutationVersion,i=!1;return n.loadPromise=n.writeQueue.then(()=>y(`/api/composer-history?conversationId=${encodeURIComponent(e)}`)).then(t=>{n.mutationVersion===r?(n.items=t.items.filter(t=>t.conversationId===e).slice(0,100),n.loaded=!0):i=!0}).catch(()=>{}).finally(()=>{n.loadPromise=null,i&&n.writeQueue.then(()=>DE(e,!0))}),n.loadPromise}function OE(e,t){let n=t.trim();if(!n)return;let r=CE(e),i=r.clearVersion;r.mutationVersion+=1,wE(r,{conversationId:e,id:0,text:n,createdAt:Date.now()}),r.writeQueue=r.writeQueue.then(async()=>{let t=await y(`/api/composer-history`,{method:`POST`,body:JSON.stringify({conversationId:e,text:n})});r.clearVersion===i&&t.item.conversationId===e&&TE(r,t.item)}).catch(()=>{})}function kE(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.conversationId!=`string`||!t.conversationId||typeof t.id!=`number`||typeof t.text!=`string`||typeof t.createdAt!=`number`)return null;let n=CE(t.conversationId);return n.mutationVersion+=1,TE(n,t),t.conversationId}function AE(e){if(!e||typeof e!=`object`||!(`conversationId`in e)||typeof e.conversationId!=`string`)return null;let t=CE(e.conversationId);return t.mutationVersion+=1,t.clearVersion+=1,t.items=[],e.conversationId}function jE(e){let{conversationId:t,editorRef:n,valueRef:r,resetEditor:i,onWireInput:a}=e,o=(0,Q.useRef)(t);o.current=t;let s=(0,Q.useRef)(null),c=(0,Q.useCallback)(()=>{s.current=null},[]);return(0,Q.useEffect)(()=>{c()},[t,c]),(0,Q.useEffect)(()=>{t&&DE(t,!0);let e=e=>{kE(e.detail)===t&&c()},n=e=>{AE(e.detail)===t&&c()},r=()=>{t&&DE(t,!0)};return window.addEventListener(`composer-history-appended`,e),window.addEventListener(`composer-history-cleared`,n),window.addEventListener(`gateway-realtime-connected`,r),()=>{window.removeEventListener(`composer-history-appended`,e),window.removeEventListener(`composer-history-cleared`,n),window.removeEventListener(`gateway-realtime-connected`,r)}},[t,c]),{onUserTextCommitted:(0,Q.useCallback)((e,n=t)=>{n&&!Rn(e)&&OE(n,e),n===o.current&&c()},[t,c]),onWireInputClearWalk:(0,Q.useCallback)((e,t)=>{s.current=null,a(e,t)},[a]),tryInputHistoryArrow:(0,Q.useCallback)(e=>{if(!t)return!1;let a=EE(t);if(a.length===0)return!1;let o=s.current,c=n.current,l=c?Np(c):0,u=r.current;if(e===`up`){if(o==null){if(l!==0)return!1;s.current={index:0,stash:u};let e=a[0];return e?(i({nextText:e,caretOffset:e.length,focus:!0}),!0):!1}if(o.index>=a.length-1)return!0;o.index+=1;let e=a[o.index];return e?(i({nextText:e,caretOffset:e.length,focus:!0}),!0):!1}if(o==null)return!1;if(--o.index,o.index<0){let e=o.stash;return s.current=null,i({nextText:e,caretOffset:e.length,focus:!0}),!0}let d=a[o.index];return d?(i({nextText:d,caretOffset:d.length,focus:!0}),!0):!1},[t,n,r,i])}}function ME(e){return e.blocked||(e.editingUserTurnId||e.editingFollowUpId)&&e.queuePaused===!1?`blocked`:e.editingFollowUpId?`saveFollowUp`:e.editingUserTurnId?e.runBusy?`blocked`:`replaceTurn`:e.runBusy?`queue`:`send`}function NE(e){if(e.voiceActive)return e.cancelVoiceInput(),null;let t=e.getTextValue(),n=e.getContextRefs();if(!t.trim()&&e.getAttachmentCount()===0&&n.length===0)return null;let r=e.wireAttachmentsPayload();return structuredClone({text:t,attachments:r,contextRefs:n})}function PE(e){let t=(0,Q.useRef)(e);t.current=e;let{chat:n,runBusy:r,voiceActive:i,cancelVoiceInput:a,editingFollowUpId:o,getTextValue:s,getAttachmentCount:c,wireAttachmentsPayload:l,getContextRefs:u,getThinkingLevel:d,onSend:f,onDispatched:p,onAddPendingFollowUp:m,onSteeringInterrupt:h,onCommitEditFollowUp:g,onPendingFollowUpRemove:_,pendingFollowUpsCount:v,resetEditor:y,clearAttachments:b,clearContextRefs:x,clearEditFollowUpRef:S,onUserTextCommitted:C}=e,w={getTextValue:s,getAttachmentCount:c,wireAttachmentsPayload:l,getContextRefs:u},T=(0,Q.useRef)(!1),E=(0,Q.useRef)(!1),D=(0,Q.useRef)(()=>{}),O=(0,Q.useRef)(!1),k=(0,Q.useCallback)(()=>{let n=performance.now(),r=ME(t.current);if(r===`blocked`)return;if(r===`queue`){D.current();return}let s=NE({voiceActive:i,cancelVoiceInput:a,...w});if(!s)return;if(r===`saveFollowUp`){if(O.current||!o)return;O.current=!0,Promise.resolve().then(()=>g(o,s.text,s.attachments,d(),s.contextRefs)).then(n=>{if(n===!1)return;C?.(s.text);let r=t.current;r.draftScope!==e.draftScope||r.editingFollowUpId!==o||r.getTextValue()!==s.text||JSON.stringify(r.wireAttachmentsPayload())!==JSON.stringify(s.attachments)||JSON.stringify(r.getContextRefs())!==JSON.stringify(s.contextRefs)||(r.onFinishFollowUpEdit?.(),S())}).catch(e=>ya(`error`,e instanceof Error?e.message:String(e))).finally(()=>{O.current=!1});return}let c=[s.text,s.attachments.length>0?s.attachments:void 0,d(),s.contextRefs.length>0?s.contextRefs:void 0,{submittedAt:n,onDispatched:e=>p?.(e,s)}];HT(f(...c),n=>{C?.(s.text,n);let i=t.current,a=e.draftScope,o=i.draftScope;if(!(!(r===`send`&&a?.conversationId===null&&n!==void 0&&o?.conversationId===n&&o.gatewayIdentity===a.gatewayIdentity)&&o!==a||i.getTextValue()!==s.text||JSON.stringify(i.wireAttachmentsPayload())!==JSON.stringify(s.attachments)||JSON.stringify(i.getContextRefs())!==JSON.stringify(s.contextRefs))){if(r===`replaceTurn`){i.editingUserTurnId===e.editingUserTurnId&&i.onFinishUserEdit?.();return}y(),b(),x()}})},[r,o,g,S,i,a,f,p,e.editingUserTurnId,e.draftScope,d,C,y,b,x,s,c,l,u]),A=(0,Q.useCallback)(async(o=!e.personal&&void 0,s=e.personal?`steer`:void 0)=>{if(t.current.editingFollowUpId||t.current.editingUserTurnId){k();return}if(!r&&v===0)return;let c=NE({voiceActive:i,cancelVoiceInput:a,...w});if(c&&!t.current.blocked&&m&&!T.current){if(v>=10){ya(`warning`,n.followUpQueueMaxReached,{max:10});return}T.current=!0;try{let n=[c.text,c.attachments.length>0?c.attachments:void 0,c.contextRefs.length>0?c.contextRefs:void 0];(o!==void 0||s!==void 0)&&n.push(o),s!==void 0&&n.push(s),await m(...n),C?.(c.text);let r=t.current;if(r.draftScope!==e.draftScope||r.editingFollowUpId||r.editingUserTurnId||r.getTextValue()!==c.text||JSON.stringify(r.wireAttachmentsPayload())!==JSON.stringify(c.attachments)||JSON.stringify(r.getContextRefs())!==JSON.stringify(c.contextRefs))return;y(),b(),x()}catch(e){ya(`error`,n.followUpQueueSubmitFailed,{message:e instanceof Error?e.message:String(e)})}finally{T.current=!1}}},[k,r,i,a,o,v,m,g,d,e.personal,e.draftScope,n.followUpQueueMaxReached,n.followUpQueueSubmitFailed,S,C,y,b,x,s,c,l,u]);return D.current=()=>{A()},{send:k,flushSteeringDraft:A,interruptDraft:(0,Q.useCallback)(()=>{if(t.current.blocked||t.current.editingFollowUpId||t.current.editingUserTurnId||!r||!h||E.current)return;let n=NE({voiceActive:i,cancelVoiceInput:a,...w});n&&(E.current=!0,(async()=>{if(await h(n.text,n.attachments.length>0?n.attachments:void 0,n.contextRefs.length>0?n.contextRefs:void 0)===!1)return;C?.(n.text);let r=t.current;r.draftScope!==e.draftScope||r.editingFollowUpId||r.editingUserTurnId||r.getTextValue()!==n.text||JSON.stringify(r.wireAttachmentsPayload())!==JSON.stringify(n.attachments)||JSON.stringify(r.getContextRefs())!==JSON.stringify(n.contextRefs)||(y(),b(),x())})().catch(e=>ya(`error`,e instanceof Error?e.message:String(e))).finally(()=>{E.current=!1}))},[r,i,a,o,_,h,e.draftScope,C,S,y,b,x,s,c,l,u]),steerCurrentReply:(0,Q.useCallback)(()=>{let e=t.current;if(!(!e.runBusy||e.blocked||e.voiceActive||e.steeringPending||e.editingFollowUpId||e.editingUserTurnId)){if(!e.personal&&e.pendingFollowUpsCount>0){e.firstPendingFollowUpId&&e.onSteerPendingFollowUp?.(e.firstPendingFollowUpId);return}A(!1,`steer`)}},[A])}}var FE=e=>e?.kind===`editTurn`?`turn:${e.turnId}`:e?.kind===`editFollowUp`?`input:${e.inputId}:${e.version}`:`compose`,IE=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),LE=new Map;function RE(e,t){let n=(LE.get(e)??Promise.resolve()).catch(()=>{}).then(t);LE.set(e,n);let r=()=>{LE.get(e)===n&&LE.delete(e)};return n.then(r,r),n}function zE(e,t,n,r,i,a,o,s){let c=FE(a?.snapshot().mode),l=_(e=>e.conversationId),u=l&&e?JSON.stringify([l,e]):``,d=(0,Q.useRef)({editor:t,attachments:n,refs:r,setRefs:i,editSession:a});d.current={editor:t,attachments:n,refs:r,setRefs:i,editSession:a};let f=(0,Q.useRef)(void 0),p=(0,Q.useRef)(void 0),[m,h]=(0,Q.useState)(0);(0,Q.useLayoutEffect)(()=>{let t=p.current;p.current={identity:l,id:e,unboundDraftKey:o};let n=t?.identity===l&&t?.id===null&&!!e&&e===s?.(),r=t&&(t.identity!==l||t.id!==e||t.unboundDraftKey!==o)&&!n;if(r&&(d.current.editor.resetEditor(),d.current.attachments.clearAttachments(),d.current.setRefs([])),!u||!e){f.current=void 0;return}let i={receipts:[],scope:u,ready:!1,dirty:!1,observe:!1,snapshot:{text:d.current.editor.valueRef.current,attachments:d.current.attachments.attachmentsRef.current,refs:r?[]:d.current.refs,editSession:d.current.editSession?.snapshot()},storage:Pr(e)};f.current=i;let a=!1,c=LE.get(u);return(c?c.catch(()=>{}).then(()=>i.storage.read()):i.storage.read()).then(e=>{if(a=!0,f.current!==i)return;i.receipts=e?.intakeReceipts??[];let t=d.current;e&&!i.dirty&&!t.editor.valueRef.current&&!t.attachments.attachmentsRef.current.length&&!t.refs.length&&(t.editor.resetEditor({nextText:e.text}),t.attachments.setAttachments(e.attachments),t.setRefs(e.refs),e.editSession&&t.editSession?.restore(e.editSession))}).catch(e=>{console.warn(`Composer draft restoration failed`,e)}).finally(()=>{f.current===i&&(i.ready=a,a&&d.current.editSession?.ready?.(),h(e=>e+1))}),()=>{f.current===i&&(f.current=void 0)}},[u,e,l,o,s]),(0,Q.useLayoutEffect)(()=>{let e=f.current;if(!e||e.scope!==u)return;if(!e.observe){e.observe=!0;return}let i={text:t.value,attachments:n.attachments,refs:r,editSession:d.current.editSession?.snapshot()};(i.text!==e.snapshot.text||!IE(i.attachments,e.snapshot.attachments)||!IE(i.refs,e.snapshot.refs)||FE(i.editSession?.mode)!==FE(e.snapshot.editSession?.mode))&&(e.dirty=!0),e.snapshot=i},[u,t.value,n.attachments,r,c]),(0,Q.useEffect)(()=>{let e=f.current;if(!e||e.scope!==u||!e.ready&&!e.dirty)return;let i={text:t.value,attachments:n.attachments,refs:r,editSession:d.current.editSession?.snapshot()},a=i.text||i.attachments.length||r.length||i.editSession?.mode.kind!==void 0&&i.editSession.mode.kind!==`compose`?i:void 0;RE(u,()=>e.storage.write(a?{...a,intakeReceipts:e.receipts}:e.receipts.length?{text:``,attachments:[],refs:[],intakeReceipts:e.receipts}:void 0)).catch(e=>{console.warn(`Composer draft persistence failed`,e)})},[u,m,t.value,n.attachments,r,c]),(0,Q.useEffect)(()=>{let e=f.current;if(!(!e?.ready||!u))return Ys(u,async(t,n)=>{if(await LE.get(u)?.catch(()=>{}),f.current!==e)throw Error(`Conversation changed. Please retry.`);if(e.receipts.includes(t))return;let r=d.current,i=r.attachments.attachmentsRef.current,a=n.filter(e=>!i.some(t=>t.id===e.id));if(i.length+a.length>10)throw Error(`A message supports at most 10 attachments. Remove attachments or choose another conversation.`);r.attachments.setAttachments([...i,...a]),e.receipts.push(t);try{let t={text:r.editor.valueRef.current,attachments:r.attachments.attachmentsRef.current,refs:r.refs,intakeReceipts:e.receipts.slice(),editSession:r.editSession?.snapshot()};await RE(u,()=>e.storage.write(t))}catch(n){throw e.receipts=e.receipts.filter(e=>e!==t),n}})},[u,m])}function BE(e){let{conversationId:t,agentId:n,modelKey:r,locale:i,enabled:a,draftText:o,canShow:s}=e,c=_(e=>e.conversationId),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(null),m=(0,Q.useRef)(o),v=(0,Q.useRef)(-1),y=(0,Q.useCallback)((e,t,n)=>{h(g(`/api/sessions/${encodeURIComponent(e.suggestion.conversationId)}/next-turn-suggestion-feedback`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({suggestionId:e.suggestion.id,impressionId:e.impressionId,event:t,...n===void 0?{}:{edited:n}})}).catch(()=>{})},[]);(0,Q.useEffect)(()=>{m.current.length>0&&o.length===0&&(p.current=null),m.current=o},[o]),(0,Q.useEffect)(()=>{p.current=null,v.current=-1,u(null),f(null)},[t,n,r,i,c]),(0,Q.useEffect)(()=>{if(u(null),!a||!t)return;let e=!1,r=0,o,s=0,c=new AbortController,l=async()=>{let a=++r;try{if(await jr(t))return;let d=await h(g(`/api/sessions/${encodeURIComponent(t)}/next-turn-suggestion?locale=${i}`),{signal:c.signal});if(!d.ok)return;let f=Bs.safeParse(await d.json());if(e||a!==r||!f.success)return;let p=f.data.suggestion;if(f.data.status===`ready`&&p&&p.conversationId===t&&p.locale===i&&(!n||p.agentId===n)&&p.inputRevision>=v.current&&p.expiresAt>Date.now()&&p.transcriptId===await Lr(t)){if(e||a!==r)return;u(e=>e?.suggestion.id===p.id?e:{suggestion:p,impressionId:crypto.randomUUID()}),o=setTimeout(()=>{u(null)},Math.max(0,p.expiresAt-Date.now()))}else u(null),f.data.status===`pending`&&s++<7&&(o=setTimeout(()=>{l()},600))}catch{}},d=e=>{let n=e.detail;if(!(n?.conversationId!==t&&n?.key!==t)){if(typeof n.revision==`number`){if(n.revision<v.current)return;v.current=n.revision}r++,s=0,o&&clearTimeout(o),u(null),e.type===`session-transcript-updated`?o=setTimeout(()=>{l()},150):l()}},f=()=>{r++,s=0,o&&clearTimeout(o),u(null),l()},p=e=>{e.detail?.topic===`sessions`&&f()};l();let m=[`session-next-turn-suggestion-changed`,`session-input-state`,`session-updated`,`session-transcript-updated`];return m.forEach(e=>window.addEventListener(e,d)),window.addEventListener(`gateway-realtime-connected`,f),window.addEventListener(`config-reload`,f),window.addEventListener(`realtime-gap`,p),()=>{e=!0,r++,c.abort(),o&&clearTimeout(o),m.forEach(e=>window.removeEventListener(e,d)),window.removeEventListener(`gateway-realtime-connected`,f),window.removeEventListener(`config-reload`,f),window.removeEventListener(`realtime-gap`,p)}},[t,n,r,i,c,a]);let b=a&&s&&o.length===0&&l?.suggestion.id!==d&&l?.suggestion.conversationId===t&&l.suggestion.expiresAt>Date.now()?l:null,x=(0,Q.useCallback)(()=>{b&&y(b,`shown`)},[b,y]),S=(0,Q.useCallback)(()=>b?(p.current=b,y(b,`accepted`),b.suggestion.prompt):null,[b,y]),C=(0,Q.useCallback)(()=>{b&&(f(b.suggestion.id),y(b,`dismissed`))},[b,y]),w=(0,Q.useCallback)(e=>{let n=p.current;!n||n.suggestion.conversationId!==t||(f(n.suggestion.id),y(n,`submitted`,e.trim()!==n.suggestion.prompt),p.current=null)},[t,y]);return{suggestion:b?.suggestion??null,shown:x,accept:S,dismiss:C,submitted:w}}function VE(e){let t=(0,X.c)(6),{active:n,anchors:r,ignoreSelector:i,onDismiss:a}=e,o,s;t[0]!==n||t[1]!==r||t[2]!==i||t[3]!==a?(o=()=>{if(!n)return;let e=e=>{let t=e.target;if(t instanceof Node){for(let e of r){let n=e.current;if(n&&n.contains(t))return}i&&t instanceof Element&&t.closest(i)||a()}};return window.addEventListener(`pointerdown`,e,!0),()=>window.removeEventListener(`pointerdown`,e,!0)},s=[n,r,i,a],t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s):(o=t[4],s=t[5]),(0,Q.useEffect)(o,s)}var HE=20,UE=`xopc.atMention.recent:`;function WE(e){return`${UE}${e.trim()}`}function GE(e){let t=e?.trim();if(!t||typeof localStorage>`u`)return[];try{let e=localStorage.getItem(WE(t));if(!e)return[];let n=JSON.parse(e);return Array.isArray(n)?n.filter(e=>typeof e==`string`&&e.length>0).slice(0,HE):[]}catch{return[]}}function KE(e,t){let n=e?.trim(),r=t.trim();if(!(!n||!r||typeof localStorage>`u`))try{let e=[r,...GE(n).filter(e=>e!==r)].slice(0,HE);localStorage.setItem(WE(n),JSON.stringify(e))}catch{}}var qE=150,JE=[`file`,`note`,`session`,`browser_tab`,`skill`,`agent`];function YE(e){let t={items:[],loading:e,error:null};return{file:{...t},note:{...t},session:{...t},skill:{...t},agent:{...t},browser_tab:{...t}}}function XE(e,t){let n=Math.min(Math.max(t,0),e.length);if(n<1)return null;let r=e.slice(0,n).match(/@((?:\\.|[^\s])*)$/);if(!r||r.index===void 0)return null;let i=r.index;return i>0&&/[a-zA-Z0-9_]/.test(e[i-1])?null:{start:i,end:n,query:(r[1]??``).replace(/\\([\\\s])/gu,`$1`)}}function ZE(e){return e.replace(/[\\\s]/gu,e=>`\\${e}`)}function QE(e){let t=e.trim();return t.length>0&&t.endsWith(`/`)&&!/^https?:\/\//i.test(t)}function $E(e){return e.replace(/\/+$/,``).trim()}function eD(e){let t=e.replace(/\/+$/,``);if(!t)return``;let n=t.lastIndexOf(`/`);return n<=0?``:t.slice(0,n)}function tD(e,t){return t===0?0:Math.min(e,t-1)}function nD(e){return{id:`file:${e.id}`,kind:`file`,name:e.name,description:e.path,relativePath:e.path,isDirectory:e.isDirectory,fileRef:{sourceId:e.id,expectedVersion:e.revision}}}function rD(e,t,n){let r=(0,X.c)(55),i=n.capabilities??pp,[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(cD),l=(0,Q.useRef)(0),u=v(sD),d;bb0:{if(n.isComposing||n.slashPaletteOpen){d=null;break bb0}if(n.precomputedAtRange!==void 0){d=n.precomputedAtRange;break bb0}let i;r[0]!==t||r[1]!==e?(i=XE(e,t),r[0]=t,r[1]=e,r[2]=i):i=r[2],d=i}let f=d,p=f!==null,[m]=Za(p?f.query:``,qE),h=p?m:``,g;r[3]===n.conversationId?g=r[4]:(g=n.conversationId?.trim()??``,r[3]=n.conversationId,r[4]=g);let _=g,y;r[5]===n.selectedContextKeys?y=r[6]:(y=[...n.selectedContextKeys??new Set].sort().join(`\0`),r[5]=n.selectedContextKeys,r[6]=y);let b=y,x;r[7]!==i.agentSwitch||r[8]!==i.skills||r[9]!==_||r[10]!==h||r[11]!==u||r[12]!==n||r[13]!==p||r[14]!==b?(x=()=>{let e=l.current+=1;if(!p){c(YE(!1));return}if(!_){c(YE(!!n.prepareSession)),n.prepareSession&&n.prepareSession().catch(()=>{l.current===e&&c(YE(!1))});return}let t={conversationId:_,currentAgentId:n.currentAgentId,language:u,selectedContextKeys:new Set(b?b.split(`\0`):[]),recentPaths:new Set(GE(_))};if(QE(h)){let t=YE(!1);t.file={items:[],loading:!0,error:null},c(t);let r=$E(h);Gw(r,{conversationId:_,agentId:n.currentAgentId}).then(t=>{if(l.current!==e)return;let n={id:`browse-up:${r}`,kind:`file`,name:`..`,description:eD(r)||`/`,relativePath:``,isDirectory:!0,isBrowseUp:!0};c(e=>({...e,file:{items:[n,...t.map(nD)],loading:!1,error:null}}))}).catch(t=>{l.current===e&&c(e=>({...e,file:{items:[],loading:!1,error:t instanceof Error?t.message:String(t)}}))});return}c(YE(!0));for(let n of Jw.filter(e=>(e.kind!==`skill`||i.skills)&&(e.kind!==`agent`||i.agentSwitch)))n.search(h,t).then(t=>{l.current===e&&c(e=>({...e,[n.kind]:{items:t,loading:!1,error:null}}))}).catch(t=>{l.current===e&&c(e=>({...e,[n.kind]:{items:[],loading:!1,error:t instanceof Error?t.message:String(t)}}))})},r[7]=i.agentSwitch,r[8]=i.skills,r[9]=_,r[10]=h,r[11]=u,r[12]=n,r[13]=p,r[14]=b,r[15]=x):x=r[15];let S;r[16]!==i.agentSwitch||r[17]!==i.skills||r[18]!==_||r[19]!==h||r[20]!==u||r[21]!==n.currentAgentId||r[22]!==n.prepareSession||r[23]!==p||r[24]!==b?(S=[p,_,h,u,n.currentAgentId,n.prepareSession,b,i.skills,i.agentSwitch],r[16]=i.agentSwitch,r[17]=i.skills,r[18]=_,r[19]=h,r[20]=u,r[21]=n.currentAgentId,r[22]=n.prepareSession,r[23]=p,r[24]=b,r[25]=S):S=r[25],(0,Q.useEffect)(x,S);let C;if(r[26]!==i.agentSwitch||r[27]!==i.skills||r[28]!==s){let e;r[30]!==i.agentSwitch||r[31]!==i.skills?(e=e=>(e!==`skill`||i.skills)&&(e!==`agent`||i.agentSwitch),r[30]=i.agentSwitch,r[31]=i.skills,r[32]=e):e=r[32];let t;r[33]===s?t=r[34]:(t=e=>({kind:e,...s[e]}),r[33]=s,r[34]=t),C=JE.filter(e).map(t),r[26]=i.agentSwitch,r[27]=i.skills,r[28]=s,r[29]=C}else C=r[29];let w=C,T=p?w.flatMap(oD):[],E;r[35]!==p||r[36]!==w?(E=p&&w.some(aD),r[35]=p,r[36]=w,r[37]=E):E=r[37];let D=E,O;r[38]===w?O=r[39]:(O=w.flatMap(iD),r[38]=w,r[39]=O);let k=O,A=!D&&T.length===0?k[0]??null:null,j=`${f?.start??``}:${f?.end??``}:${h}`,M;r[40]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>o(0),r[40]=M):M=r[40];let N;r[41]===j?N=r[42]:(N=[j],r[41]=j,r[42]=N),(0,Q.useEffect)(M,N);let P=tD(a,T.length),F;r[43]===T.length?F=r[44]:(F=e=>{T.length!==0&&o(t=>e===`down`?(t+1)%T.length:(t-1+T.length)%T.length)},r[43]=T.length,r[44]=F);let I=F,L=f?.query??``,R;return r[45]!==f||r[46]!==A||r[47]!==T||r[48]!==D||r[49]!==I||r[50]!==p||r[51]!==P||r[52]!==w||r[53]!==L?(R={open:p,atRange:f,sections:w,items:T,selectedIndex:P,query:L,loading:D,error:A,onNavigate:I,setSelectedIndex:o},r[45]=f,r[46]=A,r[47]=T,r[48]=D,r[49]=I,r[50]=p,r[51]=P,r[52]=w,r[53]=L,r[54]=R):R=r[54],R}function iD(e){return e.error?[e.error]:[]}function aD(e){return e.loading}function oD(e){return e.items}function sD(e){return e.language}function cD(){return YE(!1)}function lD(e){return e.kind===`note`?{refId:crypto.randomUUID(),kind:`note`,sourceId:e.noteRef.sourceId,expectedVersion:e.noteRef.expectedVersion,title:e.name}:e.kind===`file`&&!e.isBrowseUp&&e.fileRef?{refId:crypto.randomUUID(),kind:`file`,sourceId:e.fileRef.sourceId,expectedVersion:e.fileRef.expectedVersion,title:e.name,fileKind:e.isDirectory?`directory`:`file`}:e.kind===`session`?{refId:crypto.randomUUID(),kind:`session`,sourceId:e.sessionRef.sourceId,expectedVersion:e.sessionRef.expectedVersion,title:e.name}:e.kind===`browser_tab`?{refId:crypto.randomUUID(),kind:`browser_tab`,sourceId:e.tabRef.sourceId,expectedVersion:e.tabRef.expectedVersion,title:e.name}:null}function uD(e){let{conversationId:t,editorValue:n,editorCursor:r,isComposing:i,runBusy:a,thinkingLevel:o,editorRef:s,valueRef:c,resetEditor:l,clearAttachments:u,onSend:d,onUserTextCommitted:f,onChatAgentChange:p,currentAgentId:m,prepareSession:h,contextRefs:g,onAddContextRef:_,onUnavailableSkill:v,onReviewLauncher:y,onAddPendingFollowUp:b,onAbort:x,pendingFollowUpsCount:S,maxPendingFollowUps:C,clearContextRefs:w,commandPalettePanelRef:T}=e,E=e.capabilities??pp,D=(0,Q.useMemo)(()=>XE(n,r),[n,r]),O=lE(n,r,{suppress:D!=null,capabilities:E,isComposing:i,currentAgentId:m,conversationId:t}),k=rD(n,r,{conversationId:t,currentAgentId:m,slashPaletteOpen:O.open,capabilities:E,isComposing:i,precomputedAtRange:D,selectedContextKeys:new Set(g.map(e=>`${e.kind}:${e.sourceId}`)),prepareSession:h}),A=O.open||k.open||D!=null,j=(0,Q.useCallback)(()=>({slashRange:O.slashRange,runBusy:a,pendingFollowUpsCount:S,maxPendingFollowUps:C,thinkingLevel:o,editor:{valueRef:c,resetEditor:l},attachments:{clearAttachments:u},contextRefs:{current:g,clear:w},callbacks:{onSend:d,onUserTextCommitted:f,onChatAgentChange:p,onAddPendingFollowUp:b,onAbort:x,onUnavailableSkill:v,onReviewLauncher:y}}),[O.slashRange,a,S,C,o,c,l,u,g,w,d,f,p,b,x,v,y]),M=(0,Q.useCallback)(e=>{!E.commands&&e.kind===`command`||!E.skills&&e.kind===`skill`||!E.agentSwitch&&e.kind===`agent`||YT(e,j())},[j,E]),N=(0,Q.useCallback)(e=>{let n=k.atRange;if(!n)return;let r=lD(e);if(r){let i=_(r);if(!i?.refId)return;let a=`${Xn(i.refId)} `,o=GT(c.current,n.start,n.end,a);l({nextText:o,caretOffset:n.start+a.length,focus:!0}),t&&e.kind===`file`&&KE(t,e.relativePath);return}if(e.kind===`skill`){if(!E.skills)return;let t=`/skill:${e.canonicalName} `,r=GT(c.current,n.start,n.end,t);l({nextText:r,caretOffset:n.start+t.length,focus:!0});return}if(e.kind===`agent`){if(!E.agentSwitch)return;let t=GT(c.current,n.start,n.end,``);l({nextText:t,caretOffset:n.start,focus:!0}),p?.(e.agentId);return}if(e.kind!==`file`||!e.isDirectory)return;let i=`@${ZE(e.isBrowseUp?(()=>{let e=eD($E(n.query));return e?`${e}/`:``})():`${e.relativePath.replace(/\/+$/,``)}/`)}`,a=GT(c.current,n.start,n.end,i),o=n.start+i.length;l({nextText:a,caretOffset:o,focus:!0})},[k.atRange,E,_,t,p,c,l]),P=(0,Q.useRef)(null);P.current=k.open?k.atRange:O.open?O.slashRange:null;let F=c,I=(0,Q.useCallback)(()=>{let e=P.current;if(!e)return;let t=F.current,n=t.slice(0,e.start)+t.slice(e.end);l({nextText:n,caretOffset:e.start})},[l,F]),L=(0,Q.useMemo)(()=>[s,T],[s,T]);VE({active:O.open||k.open,anchors:L,ignoreSelector:`[data-composer-picker-panel], [data-slash-palette-tooltip]`,onDismiss:I});let R=(0,Q.useRef)(k);R.current=k;let z=(0,Q.useRef)(O);z.current=O;let B=(0,Q.useRef)(i);B.current=i;let ee=(0,Q.useRef)(M);ee.current=M;let V=(0,Q.useRef)(N);V.current=N;let H=(0,Q.useRef)({runBusy:a,pendingFollowUpsCount:S,maxPendingFollowUps:C});H.current={runBusy:a,pendingFollowUpsCount:S,maxPendingFollowUps:C};let U=(0,Q.useMemo)(()=>({name:`at-mention`,isActive:()=>{let e=R.current;return e.open&&e.atRange!=null&&!B.current},handleKey:e=>{let t=R.current;if(!t.atRange)return!1;if(e.key===`Escape`){e.preventDefault();let n=t.atRange,r=F.current,i=GT(r,n.start,n.end,``);return l({nextText:i,caretOffset:n.start,focus:!0}),!0}if(t.items.length===0)return!1;if(e.key===`ArrowDown`)return e.preventDefault(),t.onNavigate(`down`),!0;if(e.key===`ArrowUp`)return e.preventDefault(),t.onNavigate(`up`),!0;if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let n=t.items[t.selectedIndex];return n&&V.current(n),!0}return!1}}),[l,F]),W=(0,Q.useMemo)(()=>({name:`slash-palette`,isActive:()=>z.current.open&&!B.current,handleKey:e=>{let t=z.current;if(t.flatItems.length>0){if(e.key===`ArrowDown`)return e.preventDefault(),t.onNavigate(`down`),!0;if(e.key===`ArrowUp`)return e.preventDefault(),t.onNavigate(`up`),!0;if((e.key===`Enter`||e.key===`Tab`)&&!e.shiftKey){e.preventDefault();let n=t.flatItems[t.selectedIndex];return!n||tE(n,H.current)||ee.current(n),!0}}if(e.key===`Escape`){e.preventDefault();let n=t.slashRange;if(n){let e=F.current,t=GT(e,n.start,n.end,``);l({nextText:t,caretOffset:n.start,focus:!0})}return!0}return!1}}),[l,F]);return{palette:O,atPicker:k,shouldSyncSelection:A,adapters:(0,Q.useMemo)(()=>[U,W],[U,W]),applyPalette:M,applyAtMention:N}}function dD(e){return/^[A-Za-z0-9._/@:-]+$/.test(e)?e:JSON.stringify(e)}function fD(e,t){let n=t?.trim();return n?`${e} --instructions ${dD(n)}`:e}function pD(e){if(e.preset===`base`){if(!e.baseBranch?.trim())throw Error(`Missing base branch.`);return fD(`/review --base ${dD(e.baseBranch.trim())}`,e.instructions)}if(e.preset===`commit`){if(!e.commitSha?.trim())throw Error(`Missing commit SHA.`);return fD(`/review --commit ${dD(e.commitSha.trim())}`,e.instructions)}return e.preset,fD(`/review --uncommitted`,e.instructions)}async function mD(e){let t=await h(g(`/api/review/context?${new URLSearchParams({conversationId:e}).toString()}`)),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(x(t.status,t.statusText,n.error?.message));return n.payload}function hD(e,t){let n=e?.status;if(!n)return``;if(n.isClean)return t.statusClean;let r=[];return n.changedFiles>0&&r.push(t.statusChanged.replace(`{{count}}`,String(n.changedFiles))),n.untrackedFiles>0&&r.push(t.statusUntracked.replace(`{{count}}`,String(n.untrackedFiles))),r.join(`, `)}function gD(e,t){let n=t.trim().toLowerCase(),r=[...(e?.branches??[]).filter(e=>!e.current)].sort((t,n)=>t.name===e?.defaultBaseBranch&&n.name!==e.defaultBaseBranch?-1:n.name===e?.defaultBaseBranch&&t.name!==e.defaultBaseBranch?1:t.name.localeCompare(n.name));return n?r.filter(e=>e.name.toLowerCase().includes(n)):r}function _D(e,t){let n=t.trim().toLowerCase(),r=e?.commits??[];return n?r.filter(e=>`${e.sha} ${e.shortSha} ${e.subject}`.toLowerCase().includes(n)):r}function vD(e){let t=(0,X.c)(15),{icon:n,title:r,description:i,disabled:a,onClick:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=Y(`flex min-h-16 w-full items-center gap-3 rounded-lg border border-edge bg-surface-panel px-3 py-2.5 text-left`,`hover:border-accent/45 hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,`disabled:cursor-not-allowed disabled:opacity-50`,ca.transition),t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=(0,Z.jsx)(`span`,{className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg bg-surface-hover text-fg-muted`,children:n}),t[1]=n,t[2]=c);let l;t[3]===r?l=t[4]:(l=(0,Z.jsx)(`span`,{className:`block truncate text-sm font-medium text-fg`,children:r}),t[3]=r,t[4]=l);let u;t[5]===i?u=t[6]:(u=(0,Z.jsx)(`span`,{className:`mt-0.5 block truncate text-xs text-fg-muted`,children:i}),t[5]=i,t[6]=u);let d;t[7]!==l||t[8]!==u?(d=(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[l,u]}),t[7]=l,t[8]=u,t[9]=d):d=t[9];let f;return t[10]!==a||t[11]!==o||t[12]!==c||t[13]!==d?(f=(0,Z.jsxs)(`button`,{type:`button`,disabled:a,className:s,onClick:o,children:[c,d]}),t[10]=a,t[11]=o,t[12]=c,t[13]=d,t[14]=f):f=t[14],f}function yD(e){let t=(0,X.c)(89),{open:n,conversationId:r,disabled:i,chat:a,onClose:o,onSendCommand:s}=e,c=a.reviewLauncher,[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(`presets`),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(``),x;t[0]!==r||t[1]!==c.noSession?(x=()=>{if(!r){u(null),m(c.noSession);return}f(!0),m(null),mD(r).then(e=>u(e)).catch(e=>{u(null),m(e instanceof Error?e.message:String(e))}).finally(()=>f(!1))},t[0]=r,t[1]=c.noSession,t[2]=x):x=t[2];let S=x,w,E;t[3]!==S||t[4]!==n?(w=()=>{n&&(g(`presets`),v(``),b(``),S())},E=[S,n],t[3]=S,t[4]=n,t[5]=w,t[6]=E):(w=t[5],E=t[6]),(0,Q.useEffect)(w,E);let j;t[7]!==l||t[8]!==_?(j=gD(l,_),t[7]=l,t[8]=_,t[9]=j):j=t[9];let M=j,N;t[10]!==l||t[11]!==_?(N=_D(l,_),t[10]=l,t[11]=_,t[12]=N):N=t[12];let F=N,I;t[13]!==l||t[14]!==c?(I=hD(l,c),t[13]=l,t[14]=c,t[15]=I):I=t[15];let L=I,R;t[16]!==y||t[17]!==o||t[18]!==s?(R=(e,t)=>{let n=pD({preset:e,baseBranch:t?.branch,commitSha:t?.commit,instructions:y});s(n),o()},t[16]=y,t[17]=o,t[18]=s,t[19]=R):R=t[19];let z=R,B=h===`base`?c.baseTitle:h===`commit`?c.commitTitle:h===`custom`?c.customTitle:c.title,ee;t[20]===o?ee=t[21]:(ee=e=>!e&&o(),t[20]=o,t[21]=ee);let V;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[120] bg-scrim backdrop-blur-[1px]`}),t[22]=V):V=t[22];let H;t[23]!==c.back||t[24]!==h?(H=h===`presets`?null:(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex size-8 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":c.back,onClick:()=>{g(`presets`),v(``)},children:(0,Z.jsx)(P,{className:`size-4`})}),t[23]=c.back,t[24]=h,t[25]=H):H=t[25];let U;t[26]===B?U=t[27]:(U=(0,Z.jsx)(k,{className:`truncate text-sm font-semibold text-fg`,children:B}),t[26]=B,t[27]=U);let W=l?.cwd??c.description,te;t[28]===W?te=t[29]:(te=(0,Z.jsx)(T,{className:`truncate text-xs text-fg-muted`,children:W}),t[28]=W,t[29]=te);let ne;t[30]!==U||t[31]!==te?(ne=(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[U,te]}),t[30]=U,t[31]=te,t[32]=ne):ne=t[32];let re;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Z.jsx)(Xt,{className:`size-4`}),t[33]=re):re=t[33];let ie;t[34]!==c.close||t[35]!==o?(ie=(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex size-8 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":c.close,onClick:o,children:re}),t[34]=c.close,t[35]=o,t[36]=ie):ie=t[36];let ae;t[37]!==H||t[38]!==ne||t[39]!==ie?(ae=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-edge px-4 py-3`,children:[H,ne,ie]}),t[37]=H,t[38]=ne,t[39]=ie,t[40]=ae):ae=t[40];let oe;t[41]!==M||t[42]!==F||t[43]!==l||t[44]!==i||t[45]!==p||t[46]!==y||t[47]!==S||t[48]!==d||t[49]!==c.customDescription||t[50]!==c.customPlaceholder||t[51]!==c.defaultBadge||t[52]!==c.errorTitle||t[53]!==c.loading||t[54]!==c.localBadge||t[55]!==c.noBranches||t[56]!==c.noCommits||t[57]!==c.presetBase||t[58]!==c.presetBaseDescription||t[59]!==c.presetBaseDescriptionNoDefault||t[60]!==c.presetCommit||t[61]!==c.presetCommitDescription||t[62]!==c.presetCustom||t[63]!==c.presetCustomDescription||t[64]!==c.presetUncommitted||t[65]!==c.remoteBadge||t[66]!==c.retry||t[67]!==c.searchBranches||t[68]!==c.searchCommits||t[69]!==_||t[70]!==z||t[71]!==L||t[72]!==h?(oe=(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:d?(0,Z.jsxs)(`div`,{className:`flex h-full min-h-56 items-center justify-center text-sm text-fg-muted`,children:[(0,Z.jsx)(Pt,{className:`mr-2 size-4 animate-spin`}),c.loading]}):p?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 p-4`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:c.errorTitle}),(0,Z.jsx)(`div`,{className:`mt-1 text-sm text-fg-muted`,children:p}),(0,Z.jsxs)(vi,{type:`button`,className:`mt-4 h-9 rounded-lg`,variant:`secondary`,onClick:S,children:[(0,Z.jsx)(Pt,{className:`size-4`}),c.retry]})]}):h===`presets`?(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(vD,{icon:(0,Z.jsx)(Fe,{className:`size-4`}),title:c.presetBase,description:l?.defaultBaseBranch?c.presetBaseDescription.replace(`{{branch}}`,l.defaultBaseBranch):c.presetBaseDescriptionNoDefault,disabled:i,onClick:()=>g(`base`)}),(0,Z.jsx)(vD,{icon:(0,Z.jsx)(Ye,{className:`size-4`}),title:c.presetUncommitted,description:L,disabled:i,onClick:()=>z(`uncommitted`)}),(0,Z.jsx)(vD,{icon:(0,Z.jsx)(bs,{className:`size-4`}),title:c.presetCommit,description:c.presetCommitDescription.replace(`{{count}}`,String(l?.commits.length??0)),disabled:i,onClick:()=>g(`commit`)}),(0,Z.jsx)(vD,{icon:(0,Z.jsx)(Ye,{className:`size-4`}),title:c.presetCustom,description:c.presetCustomDescription,disabled:i,onClick:()=>g(`custom`)})]}):h===`base`?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(bD,{value:_,placeholder:c.searchBranches,onChange:v}),(0,Z.jsx)(`div`,{className:`grid gap-1`,children:M.length===0?(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge-subtle px-3 py-6 text-center text-sm text-fg-muted`,children:c.noBranches}):M.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`flex items-center justify-between gap-3 rounded-lg px-3 py-2 text-left hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,disabled:i,onClick:()=>z(`base`,{branch:e.name}),children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-fg`,children:e.name}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:e.name===l?.defaultBaseBranch?c.defaultBadge:e.remote?c.remoteBadge:c.localBadge})]},e.name))})]}):h===`commit`?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(bD,{value:_,placeholder:c.searchCommits,onChange:v}),(0,Z.jsx)(`div`,{className:`grid gap-1`,children:F.length===0?(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge-subtle px-3 py-6 text-center text-sm text-fg-muted`,children:c.noCommits}):F.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,disabled:i,onClick:()=>z(`commit`,{commit:e.sha}),children:[(0,Z.jsx)(`span`,{className:`font-mono text-xs text-fg-muted`,children:e.shortSha}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-fg`,children:e.subject}),e.date?(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:e.date.slice(0,10)}):null]},e.sha))})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(`textarea`,{className:`h-40 resize-none rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg outline-none placeholder:text-fg-disabled focus:border-accent focus:ring-2 focus:ring-accent/25`,value:y,placeholder:c.customPlaceholder,onChange:e=>b(e.target.value)}),(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:c.customDescription})]})}),t[41]=M,t[42]=F,t[43]=l,t[44]=i,t[45]=p,t[46]=y,t[47]=S,t[48]=d,t[49]=c.customDescription,t[50]=c.customPlaceholder,t[51]=c.defaultBadge,t[52]=c.errorTitle,t[53]=c.loading,t[54]=c.localBadge,t[55]=c.noBranches,t[56]=c.noCommits,t[57]=c.presetBase,t[58]=c.presetBaseDescription,t[59]=c.presetBaseDescriptionNoDefault,t[60]=c.presetCommit,t[61]=c.presetCommitDescription,t[62]=c.presetCustom,t[63]=c.presetCustomDescription,t[64]=c.presetUncommitted,t[65]=c.remoteBadge,t[66]=c.retry,t[67]=c.searchBranches,t[68]=c.searchCommits,t[69]=_,t[70]=z,t[71]=L,t[72]=h,t[73]=oe):oe=t[73];let se;t[74]!==i||t[75]!==c.cancel||t[76]!==c.runReview||t[77]!==o||t[78]!==z||t[79]!==h?(se=h===`custom`?(0,Z.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge px-4 py-3`,children:[(0,Z.jsx)(vi,{type:`button`,variant:`secondary`,className:`h-9 rounded-lg`,onClick:o,children:c.cancel}),(0,Z.jsx)(vi,{type:`button`,variant:`primary`,className:`h-9 rounded-lg`,disabled:i,onClick:()=>z(`custom`),children:c.runReview})]}):null,t[74]=i,t[75]=c.cancel,t[76]=c.runReview,t[77]=o,t[78]=z,t[79]=h,t[80]=se):se=t[80];let ce;t[81]!==ae||t[82]!==oe||t[83]!==se?(ce=(0,Z.jsxs)(D,{children:[V,(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[121] flex h-[min(86vh,34rem)] w-[min(100vw-2rem,40rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[ae,oe,se]})]}),t[81]=ae,t[82]=oe,t[83]=se,t[84]=ce):ce=t[84];let le;return t[85]!==n||t[86]!==ce||t[87]!==ee?(le=(0,Z.jsx)(A,{open:n,onOpenChange:ee,children:ce}),t[85]=n,t[86]=ce,t[87]=ee,t[88]=le):le=t[88],le}function bD(e){let t=(0,X.c)(7),{value:n,placeholder:r,onChange:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Lt,{className:`size-4 shrink-0 text-fg-muted`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=e=>i(e.target.value),t[1]=i,t[2]=o);let s;return t[3]!==r||t[4]!==o||t[5]!==n?(s=(0,Z.jsxs)(`label`,{className:`flex h-9 items-center gap-2 rounded-lg border border-edge bg-surface-base px-3 text-sm text-fg focus-within:border-accent focus-within:ring-2 focus-within:ring-accent/25`,children:[a,(0,Z.jsx)(`input`,{className:`min-w-0 flex-1 bg-transparent outline-none placeholder:text-fg-disabled`,value:n,placeholder:r,onChange:o})]}),t[3]=r,t[4]=o,t[5]=n,t[6]=s):s=t[6],s}function xD(e){let t=e.mimeType||`application/octet-stream`,n=e.type===`voice`||t.startsWith(`audio/`)?`voice`:e.type===`pasted_text`?`pasted_text`:t.startsWith(`image/`)?`image`:`document`;return{id:e.id,type:n,name:e.name||`file`,mimeType:t,size:e.size??0,content:e.data??``,data:e.data,uri:e.uri,durationSeconds:e.durationSeconds}}var SD=(0,Q.memo)(function({personal:e=!1,placeholder:t,nextTurnSuggestionsEnabled:n=!1,disabled:r,sendDisabled:i=!1,sending:a,streaming:o,conversationId:s,composerContext:c,pageContextPreview:l,contextRefs:u,setContextRefs:d,onDraftAttachmentsChange:p,thinkingLevel:m,modelSupportsThinking:h,onThinkingChange:g,onSend:y,onPersonalSendDispatched:b,onAbort:x,onAddPendingFollowUp:C,onSteeringInterrupt:w,pendingFollowUps:T,editingFollowUpId:E,onBeginEditFollowUp:D,onCancelEditFollowUp:O,onCommitEditFollowUp:k,onPendingFollowUpRemove:A,onPendingFollowUpMove:j,onPendingFollowUpReorder:M,onPendingFollowUpSteer:N,onPendingFollowUpSend:P,steeringFollowUpId:F,welcomeDraftSeed:I,welcomeSuggestion:L,onAcceptWelcomeSuggestion:R,sessionModel:z,showModelSelector:B,onModelChange:ee,modelDisabled:V,onChatAgentChange:H,currentAgentId:U,voiceAgentName:W,voiceTaskId:te,voiceMode:ne,prepareVoiceSession:re,prepareContextSession:ie,unboundDraftKey:ae,getDraftHandoffTarget:oe,editingUserTurnId:se,composerMode:ce,inputControl:le,onResumeQueue:ue,onRestoreEditor:de,onReacquireEdit:G,onComposerHydrated:K,onCancelUserMessageEdit:fe}){let q=ba(),pe=(0,Q.useRef)(!1);r||=q.conversationId===s&&q.active;let me=v(e=>e.language),J=S(me),[he,ge]=f();(0,Q.useEffect)(()=>{Do()},[]);let _e=(...e)=>{if(i)return!1;let t=y(...e);return t instanceof Promise?t.then(t=>(t!==!1&&ot.submitted(e[0]),t)):(t!==!1&&ot.submitted(e[0]),t)},ve=(0,Q.useRef)(!1),ye=(0,Q.useRef)(null),be=(0,Q.useRef)(null),xe=(0,Q.useRef)(null),Se=(0,Q.useRef)(!1),[Ce,we]=(0,Q.useState)(!1),[Te,Ee]=(0,Q.useState)(null),[De,Oe]=(0,Q.useState)(null),[ke,Ae]=(0,Q.useState)(!1),je=(0,Q.useRef)(_e),Ne=(0,Q.useRef)(m);je.current=_e,Ne.current=m,(0,Q.useEffect)(()=>{if(!s||De===s){Ee(null);return}let e=!1;return jr(s).then(e=>e?null:jo(s)).then(t=>{e||Ee(t&&t.required&&!t.trusted&&t.decision===null?t:null)}).catch(()=>{e||Ee(null)}),()=>{e=!0}},[s,De]);let Pe=(0,Q.useCallback)(()=>{!s||ke||(Ae(!0),Co(s,!0).then(()=>{Ee(null)}).catch(e=>{ya(`error`,J.chat.commandPalette.workspaceTrustFailed,{error:e instanceof Error?e.message:String(e)})}).finally(()=>Ae(!1)))},[J.chat.commandPalette,s,ke]),Fe=Va({conversationId:s??`new`,chat:J.chat,onAttachmentsChange:e=>p?.(e.map((e,t)=>({id:e.uri||e.id||`draft:${t}:${e.name}`,title:e.name})))}),Ie=(0,Q.useRef)(u);Ie.current=u;let Le=(0,Q.useCallback)(e=>{let t=u.find(t=>t.refId===e);return t?{title:t.title,kind:t.kind,fileKind:t.fileKind}:void 0},[u]),Re=(0,Q.useCallback)(e=>{let t=e?.contextRefs??[];if(Ie.current=t,d(t),e?.attachments){Fe.setAttachments(e.attachments.map(xD));return}Fe.clearAttachments()},[Fe.clearAttachments,Fe.setAttachments,d]),ze=(0,Q.useCallback)(e=>{let t=Ie.current,n=t.find(t=>t.kind===e.kind&&t.sourceId===e.sourceId);if(n){if(n.refId)return n;let r={...n,refId:e.refId},i=t.map(e=>e===n?r:e);return Ie.current=i,d(i),r}if(t.length>=5)return ya(`warning`,J.chat.commandPalette.contextLimitReached,{max:5}),null;let r=[...t,e];return Ie.current=r,d(r),e},[J.chat.commandPalette.contextLimitReached,d]);(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail;t?.conversationId!==s||t.reference.kind!==`result`||ze(t.reference)};return window.addEventListener(`chat-result-reference`,e),()=>window.removeEventListener(`chat-result-reference`,e)},[s,ze]);let Be=(0,Q.useCallback)(e=>{let t=e.availability.status===`agent-denied`?J.chat.commandPalette.skillAgentDeniedReason:J.chat.commandPalette.skillDisabledReason,n=mm(J.chat.commandPalette.skillUnavailableMessage,{name:e.name,agent:U||`main`,reason:t});if(e.availability.status===`agent-denied`&&window.confirm(`${n}\n\n${J.chat.commandPalette.skillAddToAllowlistConfirm}`)){Mo(U,e.canonicalName,s).catch(e=>{window.alert(e instanceof Error?e.message:String(e))});return}window.alert(n)},[U,J.chat.commandPalette,s]),Ve=lm({capabilities:e?mp:pp,disabled:r,agentId:U,conversationId:s,autoFocusKey:s,welcomeDraftSeed:I,onExternalTextReplace:Re,shouldSyncSelectionRef:ve,resolveContextRef:Le}),He=he.get(`attachmentHandoff`);(0,Q.useEffect)(()=>{if(!He)return;let e=Me(He);ge(e=>{let t=new URLSearchParams(e);return t.delete(`attachmentHandoff`),t},{replace:!0}),e&&Fe.processFiles([e]).then(()=>Ve.editorRef.current?.focus({preventScroll:!0}))},[He,Fe.processFiles,Ve.editorRef,s,ge]);let{onUserTextCommitted:Ue,onWireInputClearWalk:We,tryInputHistoryArrow:Ge}=jE({conversationId:s,editorRef:Ve.editorRef,valueRef:Ve.valueRef,resetEditor:Ve.resetEditor,onWireInput:Ve.onWireInput}),Ke=(0,Q.useCallback)((e,t)=>{We(e,t);let n=Rn(e),r=new Set(n?Bn(n):[]),i=Ie.current,a=i.filter(e=>!e.refId||r.has(e.refId));a.length!==i.length&&(Ie.current=a,d(a))},[We,d]),qe=qf(s??``),Je=a||o||qe||le?.phase===`running`||le?.phase===`stopping`;Se.current=Je;let Ye=(0,Q.useCallback)(()=>{Se.current||we(!0)},[]),Xe=(0,Q.useCallback)(e=>{HT(je.current(e,void 0,Ne.current,u),t=>{Ue?.(e,t),d([])})},[u,Ue,d]),Ze=uD({capabilities:e?mp:pp,conversationId:s,editorValue:Ve.value,editorCursor:Ve.cursor,isComposing:Ve.isComposing,runBusy:Je,thinkingLevel:m,editorRef:Ve.editorRef,valueRef:Ve.valueRef,resetEditor:Ve.resetEditor,clearAttachments:Fe.clearAttachments,onSend:_e,onUserTextCommitted:Ue,onChatAgentChange:H,currentAgentId:U,prepareSession:ie,contextRefs:u,onAddContextRef:ze,onUnavailableSkill:Be,onReviewLauncher:Ye,onAddPendingFollowUp:C,onAbort:x,pendingFollowUpsCount:T.length,maxPendingFollowUps:10,clearContextRefs:()=>d([]),commandPalettePanelRef:ye});ve.current=Ze.shouldSyncSelection;let Qe=_a({disabled:r||q.active,chat:J.chat,onTranscript:e=>{let t=Ve.valueRef.current,n=Ai(t,e);Ve.resetEditor({nextText:n,caretOffset:n.length,focus:!0})}}),{phase:$e,voiceActive:et,startVoiceInput:tt,cancelVoiceInput:nt,confirmVoiceInput:rt}=Qe;(0,Q.useEffect)(()=>{let e=e=>{if(!_T(e,{disabled:r,editorHidden:et&&$e!==`error`}))return;let t=em(e.clipboardData);t&&(e.preventDefault(),Ve.focusForExternalPaste(),tm(t,{processFiles:Fe.processFiles,processPastedText:Fe.processPastedText,insertText:e=>document.execCommand(`insertText`,!1,e),onUnsupportedFiles:()=>ya(`warning`,J.chat.clipboardFileTypeUnsupported)}))};return window.addEventListener(`paste`,e),()=>window.removeEventListener(`paste`,e)},[Fe.processFiles,Fe.processPastedText,r,Ve.focusForExternalPaste,J.chat.clipboardFileTypeUnsupported,et,$e]),(0,Q.useEffect)(()=>{let e=e=>{let t=e?.detail?.target;if(!(t&&t!==`chat`)&&(e?.preventDefault(),!r)){if($e===`recording`){rt();return}($e===`idle`||$e===`error`)&&(Ve.editorRef.current?.focus({preventScroll:!0}),tt())}},t=e=>{let t=e.detail?.target;t&&t!==`chat`||!et||(e.preventDefault(),nt(),Ve.editorRef.current?.focus({preventScroll:!0}))};window.addEventListener(Io,e),window.addEventListener(Po,t);let n=window.setTimeout(()=>{if(Lo()){if(r){Fo();return}e()}},0);return()=>{window.clearTimeout(n),window.removeEventListener(Io,e),window.removeEventListener(Po,t)}},[nt,rt,r,Ve.editorRef,tt,et,$e]);let it=(0,Q.useCallback)(()=>{xe.current=null},[]),at=n&&!r&&!i&&!Je&&!E&&!se&&!Qe.voiceActive&&!Ve.isComposing&&Ve.value.length===0&&Fe.attachments.length===0&&u.length===0&&T.length===0,ot=BE({conversationId:s,agentId:U,modelKey:z,locale:me,enabled:n,draftText:Ve.value,canShow:at}),st=()=>{if(!at||Ve.valueRef.current.length>0||Ie.current.length>0)return!1;let e=ot.accept();return e?(Ve.resetEditor({nextText:e,focus:!0}),!0):!1};(0,Q.useEffect)(()=>{at&&ot.suggestion&&!Ze.palette.open&&ot.shown()},[at,ot.suggestion,ot.shown,Ze.palette.open]);let ct=_(e=>e.conversationId),lt=(0,Q.useMemo)(()=>({gatewayIdentity:ct,conversationId:s,unboundDraftKey:ae}),[ct,s,ae]),ut=(0,Q.useRef)(new Map),dt=(0,Q.useRef)(`compose`),ft=ce??(E?{kind:`editFollowUp`,inputId:E,version:0}:{kind:`compose`}),pt=ft.kind===`editTurn`?`turn:${ft.turnId}`:ft.kind===`editFollowUp`?`input:${ft.inputId}`:`compose`;(0,Q.useLayoutEffect)(()=>{ut.current.clear(),dt.current=`compose`},[lt]),zE(s,Ve,Fe,u,d,{ready:K,snapshot:()=>({mode:ft,drafts:Object.fromEntries(ut.current)}),restore:e=>{ut.current=new Map(Object.entries(e.drafts)),dt.current=e.mode.kind===`editTurn`?`turn:${e.mode.turnId}`:e.mode.kind===`editFollowUp`?`input:${e.mode.inputId}`:`compose`,de?.(e.mode)}},ae,oe);let mt=ft.kind!==`compose`&&!!(le&&!le.paused),ht=PE({personal:e,chat:J.chat,runBusy:Je,draftScope:lt,queuePaused:le?.paused,editingUserTurnId:se,blocked:r||i||mt||le?.phase===`stopping`,onFinishUserEdit:fe,onFinishFollowUpEdit:O,voiceActive:Qe.voiceActive,cancelVoiceInput:Qe.cancelVoiceInput,editingFollowUpId:E,getTextValue:()=>Ve.valueRef.current,getAttachmentCount:()=>Fe.attachmentsRef.current.length,wireAttachmentsPayload:Fe.wireAttachmentsPayload,getContextRefs:()=>u,getThinkingLevel:()=>Ne.current,onSend:_e,onDispatched:e&&b?(e,t)=>{let n=Ve.editorRef.current?.getBoundingClientRect();n&&b(e,n,t)}:void 0,onAddPendingFollowUp:C,onSteeringInterrupt:w,onCommitEditFollowUp:k,onPendingFollowUpRemove:A,pendingFollowUpsCount:T.length,firstPendingFollowUpId:T[0]?.id,onSteerPendingFollowUp:N,steeringPending:!!F,resetEditor:()=>{Ve.resetEditor()},clearAttachments:Fe.clearAttachments,clearContextRefs:()=>d([]),clearEditFollowUpRef:it,onUserTextCommitted:Ue}),gt=(0,Q.useCallback)((e=!1)=>ht.flushSteeringDraft(e),[ht.flushSteeringDraft]),_t=(0,Q.useCallback)((e,t)=>{!s||s===`new`||zw.getState().requestCreate(s,[{id:e.id,type:`text`,text:t,label:J.chat.followUpQueueHeading}])},[s,J.chat.followUpQueueHeading]);(0,Q.useLayoutEffect)(()=>{if(dt.current===pt)return;ut.current.set(dt.current,{text:Ve.valueRef.current,attachments:Fe.wireAttachmentsPayload(),contextRefs:Ie.current,thinkingLevel:Ne.current}),dt.current=pt;let e=ft.kind===`editFollowUp`?T.find(e=>e.id===ft.inputId):void 0;e?.thinkingLevel&&h&&g(e.thinkingLevel);let t=(ft.kind===`compose`?ft.draft:void 0)??ut.current.get(pt)??(ft.kind===`editTurn`?ft.draft:e?{text:e.text,attachments:e.attachments??[],contextRefs:e.contextRefs??[]}:void 0);t?.thinkingLevel&&h&&g(t.thinkingLevel),Fe.setAttachments(PT(t?.attachments??[])),d(t?.contextRefs??[]),Ve.resetEditor({nextText:t?.text??``,focus:!0})},[pt,ft,T,Fe,Ve,d]);let vt=(0,Q.useCallback)(e=>{D(e)},[D]),yt=(0,Q.useRef)({});yt.current={adapters:Ze.adapters,send:ht.send,runBusy:Je,pendingFollowUpsCount:T.length,flushSteeringDraft:gt,steerDraft:()=>ht.flushSteeringDraft(!1,`steer`),steerCurrentReply:ht.steerCurrentReply,interruptDraft:ht.interruptDraft,editingFollowUpId:E,editingUserTurnId:se,onCancelUserMessageEdit:fe,onCancelEditFollowUp:O,attachmentsLen:Fe.attachments.length,contextRefsLen:u.length,isComposing:Ve.isComposing,valueRef:Ve.valueRef,adjustHeight:Ve.adjustHeight,editorRef:Ve.editorRef,tryInputHistoryArrow:Ge,acceptEmptySuggestion:ot.suggestion&&at?st:!Je&&!r&&!i&&!se&&!Qe.voiceActive&&L&&R?()=>(R(L),!0):void 0,dismissEmptySuggestion:ot.suggestion?ot.dismiss:void 0};let bt=Je&&!E&&!se,xt={...J.chat,sendMessage:E?J.chat.followUpSaveEdit:se?J.chat.userMessageReplaceSend:le?.paused?J.chat.sendThisMessage:J.chat.sendMessage},St=!!Ve.value.trim()||Fe.attachments.length>0||u.length>0,Ct=St&&!!w,wt=rs(`(hover: hover) and (pointer: fine)`),Tt=!bt&&!E&&L?`${L.prompt}${wt?` · ${J.chat.welcomeSpotlight.acceptSuggestionHint}`:``}`:null;return(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 w-full flex-col`,children:[s?(0,Z.jsx)(pT,{conversationId:s},s):null,c?(0,Z.jsx)(ET,{...c,conversationId:s,disabled:(c.disabled??r)||a||o}):null,(0,Z.jsxs)(pm,{className:e?`rounded-[1.65rem]`:void 0,dragging:Fe.isDragging,onDragOver:e=>{(e.dataTransfer?.types.includes(`Files`)||rp(e.dataTransfer))&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`,Fe.setIsDragging(!0))},onDragLeave:e=>{e.relatedTarget===null&&Fe.setIsDragging(!1)},onDrop:async e=>{e.preventDefault(),Fe.setIsDragging(!1);let t=e.dataTransfer?.files;if(t?.length){await Fe.processFiles(Array.from(t));return}let n=ip(e.dataTransfer);if(n)try{let e=await Ga(n.path,{conversationId:n.conversationId,agentId:n.agentId,projectId:n.projectId}),t=ci(n.name),r=e.type&&e.type!==`application/octet-stream`?e.type:t;await Fe.processFiles([new File([e],n.name,{type:r})])}catch{ya(`error`,J.chat.attachmentLoadFailed,{name:n.name})}},children:[Fe.isDragging?(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-accent-soft/80 text-sm font-medium text-accent-fg backdrop-blur-[1px]`,children:J.chat.dropFiles}):null,se?(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-b border-edge-subtle bg-accent-soft/40 px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:J.chat.userMessageEditing}),(0,Z.jsx)(`button`,{type:`button`,className:`font-medium text-accent-fg hover:underline`,onClick:fe,children:J.chat.userMessageEditCancel})]}):null,mt&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:J.chat.editQueueResumed}),(0,Z.jsx)(`button`,{type:`button`,disabled:r||i,className:`text-accent-fg disabled:opacity-40`,onClick:()=>G?.({text:Ve.valueRef.current,attachments:Fe.wireAttachmentsPayload(),contextRefs:Ie.current}),children:J.chat.editPauseAgain})]}),le?.paused&&(T.length>0||le.phase===`stopping`||ft.kind!==`compose`)&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:le.phase===`stopping`?J.chat.inputStopping:le.reviewRequired?J.chat.queueReviewRequired:T.length>0?J.chat.queuePausedCount.replace(`{count}`,String(T.length)):J.chat.queuePaused}),(0,Z.jsx)(`button`,{type:`button`,disabled:r||i||!!(E||se)||le.phase!==`idle`,className:`text-accent-fg disabled:opacity-40`,onClick:ue,children:J.chat.queueResume})]}),(0,Z.jsx)(CT,{conversationId:s}),T.length>0?(0,Z.jsx)(`div`,{className:`max-h-[min(30vh,11rem)] shrink-0 overflow-y-auto overflow-x-hidden border-b border-edge-subtle/80 [scrollbar-gutter:stable] dark:border-edge-subtle/70`,children:(0,Z.jsx)(ST,{items:T,disabled:r||i||!!(se||E),editingFollowUpId:E,onEditInComposer:vt,onRemove:A,onMove:j,onReorder:M,onSteer:N,onSendSingle:P,queuePaused:le?.paused,queueIdle:le?.phase===`idle`,steeringBusyId:F,onOpenSideChat:s&&s!==`new`?_t:void 0})}):null,(E||se)&&(0,Z.jsx)(`div`,{className:`flex items-center justify-end px-4 py-1 text-xs`,children:(0,Z.jsx)(`button`,{type:`button`,disabled:i,className:`text-accent-fg disabled:opacity-40`,onClick:()=>de?.({kind:`compose`,draft:{text:Ve.valueRef.current,attachments:Fe.wireAttachmentsPayload(),contextRefs:Ie.current}}),children:J.chat.editAsNewMessage})}),ft.kind===`editFollowUp`&&T.some(e=>e.id===ft.inputId&&e.version!==ft.version)&&(0,Z.jsxs)(`div`,{className:`border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`p`,{children:J.chat.followUpEditConflict}),(0,Z.jsx)(`p`,{className:`my-1 max-h-20 overflow-auto whitespace-pre-wrap`,children:T.find(e=>e.id===ft.inputId)?.text}),(0,Z.jsx)(`button`,{type:`button`,disabled:i,className:`text-accent-fg`,onClick:()=>D(ft.inputId),children:J.chat.followUpKeepMyEdit})]}),E?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:J.chat.inputPlaceholderSteeringEdit}),(0,Z.jsx)(`button`,{type:`button`,onClick:O,className:`shrink-0 rounded px-1 text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:J.chat.userMessageEditCancel})]}):null,(0,Z.jsx)(La,{attachments:Fe.attachments,conversationId:s,topPadded:T.length>0,onRemove:Fe.removeAttachment}),(0,Z.jsx)(wT,{refs:u.filter(e=>!e.refId),label:J.chat.commandPalette.contextLabel,onRemove:e=>d(t=>t.filter(t=>t.sourceId!==e))}),l,(0,Z.jsxs)(`div`,{className:e?`flex min-h-0 shrink-0 items-end gap-1 px-1.5 py-1.5 sm:px-2`:`flex min-h-0 shrink-0 flex-col`,children:[(0,Z.jsx)(`input`,{ref:be,type:`file`,multiple:!0,className:`hidden`,onChange:async e=>{let t=e.target.files;t&&await Fe.processFiles(Array.from(t)),e.target.value=``}}),e&&!Qe.voiceActive&&(0,Z.jsx)(MT,{disabled:r||i,attachmentCount:Fe.attachments.length,maxAttachments:10,chat:J.chat,onPickFiles:()=>be.current?.click()}),(0,Z.jsxs)(`div`,{className:e?`relative min-w-0 flex-1 px-1`:Y(`relative px-3 pb-0 pt-1 sm:px-4`,Fe.attachments.length>0&&`pt-2`),children:[(0,Z.jsx)(VT,{open:Ze.atPicker.open,anchorRef:Ve.editorRef,items:Ze.atPicker.items,selectedIndex:Ze.atPicker.selectedIndex,loading:Ze.atPicker.loading,query:Ze.atPicker.query,noResults:Ze.atPicker.error??J.chat.atMention.noResults,conversationId:s,recentLabel:J.chat.atMention.recentBadge,sectionLabels:{file:J.chat.atMention.files,note:J.chat.atMention.notes,session:J.chat.atMention.chats,skill:J.chat.atMention.skills,agent:J.chat.atMention.agents,browser_tab:J.chat.atMention.browserTabs},ariaLabel:J.chat.atMention.placeholder,onSelectItem:Ze.applyAtMention}),(0,Z.jsx)(vE,{open:Ze.palette.open,anchorRef:Ve.editorRef,panelRef:ye,sections:Ze.palette.loadError?[]:Ze.palette.sections,flatItems:Ze.palette.loadError?[]:Ze.palette.flatItems,loading:Ze.palette.loading,failedKinds:Ze.palette.failedKinds,selectedIndex:Ze.palette.selectedIndex,noResults:Ze.palette.loadError??J.chat.commandPalette.noResults,sectionLoadFailedLabel:J.chat.commandPalette.sectionLoadFailed,query:Ze.palette.query,skillsLabel:J.chat.commandPalette.skillsSection,commandsLabel:J.chat.commandPalette.commandsSection,agentsLabel:J.chat.commandPalette.agentsSection,currentAgentId:U,currentBadgeLabel:J.chat.commandPalette.currentBadge,runBusy:Je,pendingFollowUpsCount:T.length,maxPendingFollowUps:10,queueBadgeLabel:J.chat.commandPalette.queueBadge,queueFullBadgeLabel:J.chat.commandPalette.queueFullBadge,queueFullTooltip:J.chat.commandPalette.queueFullTooltip,skillUnavailableLabel:J.chat.commandPalette.skillUnavailableBadge,skillAgentDeniedLabel:J.chat.commandPalette.skillAgentDeniedBadge,skillSourceLabels:{builtin:J.chat.commandPalette.sourceBuiltin,workspace:J.chat.commandPalette.sourceWorkspace,global:J.chat.commandPalette.sourceGlobal,extra:J.chat.commandPalette.sourceExtra},onSelectItem:Ze.applyPalette}),Qe.voiceActive?(0,Z.jsx)(Ni,{phase:Qe.phase,elapsedLabel:Qe.elapsedLabel,recordedDictation:Qe.recordedDictation,audioLevel:Qe.audioLevel,partialTranscript:Qe.partialTranscript,finalTranscript:Qe.finalTranscript,error:Qe.error,settingsRequired:Qe.settingsRequired,disabled:r,chat:J.chat,onCancel:Qe.cancelVoiceInput,onConfirm:Qe.confirmVoiceInput,onRetry:Qe.retryVoiceInput}):null,(0,Z.jsx)(um,{editorRef:Ve.editorRef,disabled:r,hidden:Qe.voiceActive&&Qe.phase!==`error`,compact:e,ariaLabel:t??J.chat.inputPlaceholder,placeholder:(at&&ot.suggestion?`${ot.suggestion.prompt}${wt?` · ${J.chat.welcomeSpotlight.acceptSuggestionHint}`:``}`:null)??t??Tt??(bt?E?J.chat.inputPlaceholderSteeringEdit:e?J.chat.inputPlaceholderPersonal:J.chat.inputPlaceholderSteering:J.chat.inputPlaceholder),onWireInput:Ke,adjustHeight:Ve.adjustHeight,processFiles:Fe.processFiles,processPastedText:Fe.processPastedText,setIsComposing:Ve.setIsComposing,kbdRef:yt,chatMessages:J.chat})]}),e?(0,Z.jsx)(NT,{disabled:r||i||mt,voiceActive:Qe.voiceActive,runBusy:bt,hasDraft:St,chat:xt,onStartVoiceInput:Qe.startVoiceInput,onSend:ht.send,onAbort:x}):(0,Z.jsx)(vm,{disabled:r,sendDisabled:i||mt,sending:a,streaming:o,runBusy:bt,chat:xt,hasDraft:St,showSteeringInterrupt:Ct,attachmentCount:Fe.attachments.length,maxAttachments:10,onPickFiles:()=>be.current?.click(),thinkingLevel:m,onThinkingChange:g,voiceActive:Qe.voiceActive,onStartVoiceInput:Qe.startVoiceInput,voiceConversationEnabled:!!(s||re),onStartVoiceConversation:()=>{if(!pe.current){if(s){q.open({conversationId:s,name:W||U||`xopc`,taskId:te,mode:ne});return}re&&(pe.current=!0,re().then(e=>{if(e)return q.open({conversationId:e,name:W||U||`xopc`,taskId:te,mode:ne})}).catch(e=>ya(`error`,e instanceof Error?e.message:J.chat.callFailed)).finally(()=>{pe.current=!1}))}},onSend:ht.send,onAbort:x,onInterrupt:ht.interruptDraft,sessionModel:z,showModelSelector:B,onModelChange:ee,modelDisabled:V})]}),(0,Z.jsx)(yD,{open:Ce,conversationId:s,disabled:r||bt,chat:J.chat,onClose:()=>we(!1),onSendCommand:Xe}),(0,Z.jsx)(Wa,{open:Te!==null,title:J.chat.commandPalette.workspaceTrustTitle,description:mm(J.chat.commandPalette.workspaceTrustDescription,{path:Te?.workspacePath??``}),confirmLabel:ke?J.chat.commandPalette.workspaceTrustSaving:J.chat.commandPalette.workspaceTrustConfirm,cancelLabel:J.chat.commandPalette.workspaceTrustCancel,onConfirm:Pe,onCancel:()=>{Ee(null),Oe(s)}})]})]})});function CD(e){let t=(0,X.c)(42),{draft:n,onRemove:r,disabled:i,waiting:a}=e,o=i!==void 0&&i,s=a!==void 0&&a,c=v(TD),l;t[0]===c?l=t[1]:(l=S(c),t[0]=c,t[1]=l);let u=l.chat.pageContext,d=u.label,f;t[2]!==n.title||t[3]!==u.preview?(f=(0,Z.jsxs)(`summary`,{className:`cursor-pointer break-words rounded text-sm text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[u.preview,`: `,n.title]}),t[2]=n.title,t[3]=u.preview,t[4]=f):f=t[4];let p;t[5]===u.frozen?p=t[6]:(p=(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:u.frozen}),t[5]=u.frozen,t[6]=p);let m;t[7]===n.envelope.resourceRefs?m=t[8]:(m=n.envelope.resourceRefs.map(wD).join(`, `),t[7]=n.envelope.resourceRefs,t[8]=m);let h;t[9]===m?h=t[10]:(h=(0,Z.jsx)(`p`,{className:`mt-1 break-all text-xs text-fg-muted`,children:m}),t[9]=m,t[10]=h);let g;t[11]===n.preview?g=t[12]:(g=(0,Z.jsx)(`pre`,{className:`mt-2 max-h-48 overflow-y-auto whitespace-pre-wrap break-words font-sans text-sm text-fg`,children:n.preview}),t[11]=n.preview,t[12]=g);let _;t[13]!==n.truncated||t[14]!==u.truncated?(_=n.truncated?(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:u.truncated}):null,t[13]=n.truncated,t[14]=u.truncated,t[15]=_):_=t[15];let y;t[16]!==n.envelope.selection||t[17]!==u.draft||t[18]!==u.selection?(y=n.envelope.selection?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`mt-2 text-xs font-medium text-fg`,children:n.envelope.selection.draft?u.draft:u.selection}),(0,Z.jsx)(`pre`,{className:`mt-1 max-h-36 overflow-y-auto whitespace-pre-wrap break-words font-sans text-sm text-fg`,children:n.envelope.selection.text})]}):null,t[16]=n.envelope.selection,t[17]=u.draft,t[18]=u.selection,t[19]=y):y=t[19];let b;t[20]!==_||t[21]!==y||t[22]!==f||t[23]!==p||t[24]!==h||t[25]!==g?(b=(0,Z.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[f,p,h,g,_,y]}),t[20]=_,t[21]=y,t[22]=f,t[23]=p,t[24]=h,t[25]=g,t[26]=b):b=t[26];let x=`${u.remove}: ${n.title}`,C;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Z.jsx)(Xt,{className:`size-4`,"aria-hidden":!0}),t[27]=C):C=t[27];let w;t[28]!==o||t[29]!==r||t[30]!==x?(w=(0,Z.jsx)(`button`,{type:`button`,onClick:r,disabled:o,"aria-label":x,className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50`,children:C}),t[28]=o,t[29]=r,t[30]=x,t[31]=w):w=t[31];let T;t[32]!==b||t[33]!==w?(T=(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[b,w]}),t[32]=b,t[33]=w,t[34]=T):T=t[34];let E;t[35]!==u.pending||t[36]!==s?(E=s?(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,role:`status`,children:u.pending}):null,t[35]=u.pending,t[36]=s,t[37]=E):E=t[37];let D;return t[38]!==u.label||t[39]!==T||t[40]!==E?(D=(0,Z.jsxs)(`section`,{className:`mx-4 mt-2 min-w-0 rounded-lg border border-edge bg-surface-hover p-3`,"aria-label":d,children:[T,E]}),t[38]=u.label,t[39]=T,t[40]=E,t[41]=D):D=t[41],D}function wD(e){return`${e.kind} · ${e.id} · v${e.revision}`}function TD(e){return e.language}function ED(e){let t=(0,X.c)(30),{selection:n}=e,r=v(DD)===`zh`,{mode:i,options:a,checking:o,checkFailed:s,failure:c,busy:l,changeMode:u,retry:d}=n,f=s?r?`无法检查运行环境,请重试。`:`Could not check the environment. Retry.`:a?.worktreeUnavailableReason===`workspace_unavailable`?r?`项目目录不可用,请在项目设置中检查路径。`:`Project directory unavailable. Check its path in project settings.`:null;if(!s&&a?.worktreeUnavailableReason===`git_commit_required`){let e;return t[0]===c?e=t[1]:(e=c?(0,Z.jsx)(`p`,{role:`alert`,className:`w-full px-2 py-1 text-xs text-danger`,children:c}):null,t[0]=c,t[1]=e),e}let p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Z.jsx)(qe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),t[2]=p):p=t[2];let m=p,h;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsx)(ks,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),t[3]=h):h=t[3];let g=h,_=r?`运行位置`:`Work in`,y;t[4]!==l||t[5]!==u||t[6]!==s||t[7]!==_||t[8]!==i||t[9]!==a||t[10]!==r?(y=!a&&!s?(0,Z.jsx)(Qt,{className:`h-8 w-36 rounded-full`}):(0,Z.jsx)(fe,{ariaLabel:r?`新会话运行位置`:`New session environment`,placeholder:_,title:r?`Local 指 xopc Gateway 所在机器;首次发送时创建所选环境。`:`Local means the machine running xopc Gateway. The selected environment is created on first send.`,triggerIcon:l?(0,Z.jsx)(Ze,{className:`size-4 shrink-0 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}):i===`managed_worktree`?g:m,triggerClassName:`h-8 w-auto max-w-full justify-start gap-1.5 rounded-full border-0 bg-surface-hover px-2.5 hover:bg-surface-active [&>svg:last-child]:hidden`,contentClassName:`xopc-composer-config-popover w-max min-w-0 max-w-[calc(100vw-1.5rem)]`,side:`top`,allowEmpty:!1,value:i,disabled:l||s,options:[{value:`local_checkout`,label:`Local`,icon:m,group:_,disabled:!a?.localAvailable},{value:`managed_worktree`,label:`New local worktree`,icon:g,group:_,disabled:!a||!!a.worktreeUnavailableReason}],onChange:e=>u(e)}),t[4]=l,t[5]=u,t[6]=s,t[7]=_,t[8]=i,t[9]=a,t[10]=r,t[11]=y):y=t[11];let b;t[12]!==l||t[13]!==o||t[14]!==c||t[15]!==i||t[16]!==a?.worktreeUnavailableReason||t[17]!==f||t[18]!==d||t[19]!==r?(b=f||c||i===`managed_worktree`&&a?.worktreeUnavailableReason?(0,Z.jsx)(vi,{variant:`ghost`,className:`size-8 rounded-full p-0`,disabled:l||o,onClick:d,"aria-label":r?`重新检查环境`:`Recheck environment`,children:(0,Z.jsx)(Pt,{className:`size-3.5 `+(o?`animate-spin motion-reduce:animate-none`:``),"aria-hidden":!0})}):null,t[12]=l,t[13]=o,t[14]=c,t[15]=i,t[16]=a?.worktreeUnavailableReason,t[17]=f,t[18]=d,t[19]=r,t[20]=b):b=t[20];let x;t[21]===f?x=t[22]:(x=f?(0,Z.jsx)(`p`,{role:`status`,className:`w-full px-2 py-1 text-xs leading-5 text-fg-muted`,children:f}):null,t[21]=f,t[22]=x);let S;t[23]===c?S=t[24]:(S=c?(0,Z.jsx)(`p`,{role:`alert`,className:`max-h-20 w-full overflow-y-auto break-words px-2 py-1 text-xs leading-5 text-danger`,children:c}):null,t[23]=c,t[24]=S);let C;return t[25]!==y||t[26]!==b||t[27]!==x||t[28]!==S?(C=(0,Z.jsxs)(Z.Fragment,{children:[y,b,x,S]}),t[25]=y,t[26]=b,t[27]=x,t[28]=S,t[29]=C):C=t[29],C}function DD(e){return e.language}function OD({preparation:e,conversationId:t,ready:n,onSend:r}){let i=_(e=>e.conversationId),a=_(e=>e.baseUrl),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),f=(0,Q.useRef)(null),p=(0,Q.useRef)(!1),m=(0,Q.useRef)(r);m.current=r;let h=(0,Q.useRef)(t);h.current=t;let{data:v,error:b,isValidating:x,mutate:S}=Qr(e?[`project-environment-options`,a,i,e.project.id]:null,async()=>(await y(g(`/api/projects/${encodeURIComponent(e.project.id)}/environment-options`))).options,{keepPreviousData:!1,revalidateOnFocus:!1,shouldRetryOnError:!1}),C=v?.localAvailable&&v.worktreeUnavailableReason!==`git_commit_required`&&v.worktreeUnavailableReason!==`workspace_unavailable`?o?.preparation===e?o.mode:e?Kr(Yr(),e.project.id)??`local_checkout`:`local_checkout`:`local_checkout`,w=!!(!b&&v?.localAvailable&&(C===`local_checkout`||!v.worktreeUnavailableReason)),T=(0,Q.useCallback)(e=>{let t=f.current;f.current=null,d(null),t?.resolve(e?t.conversationId:null)},[]),E=(0,Q.useCallback)(()=>{let e=f.current,t=_.getState();return e?.token===t.conversationId&&e?.baseUrl===t.baseUrl?e?.openedConversationId:void 0},[]);(0,Q.useEffect)(()=>{if(u){if(u.baseUrl!==a||u.token!==i){T(!1);return}if(!u.conversationId){e!==u.preparation&&u.openedConversationId!==t&&T(!1);return}t===u.conversationId?n&&T(!0):e!==u.preparation&&T(!1)}},[u,t,n,e,T,a,i]),(0,Q.useEffect)(()=>()=>{f.current?.resolve(null),f.current=null},[]);let D=(0,Q.useCallback)(async()=>{if(!e)return t;let n=f.current;if(n)return n.preparation===e?n.completion:null;if(!w||x)return null;l(null);let r,o=new Promise(e=>{r=e}),s={preparation:e,baseUrl:a,token:i,conversationId:null,completion:o,resolve:r};return f.current=s,d(s),Promise.resolve().then(()=>e.create(C,void 0,e=>{f.current===s&&(s.openedConversationId=e)})).then(t=>{if(f.current!==s)return;Ur(e.project.id,C);let n={...s,conversationId:t};f.current=n,d(n)}).catch(t=>{f.current===s&&(l({preparation:e,message:t instanceof Error?t.message:String(t)}),S(),T(!1))}),o},[w,a,T,x,C,S,e,t,i]);return{mode:C,options:v,checking:x,checkFailed:!!b,allowed:w,busy:!!(u&&(u.preparation===e||u.conversationId&&u.conversationId===t)),failure:c?.preparation===e?c.message:null,changeMode:t=>{!e||f.current||(s({preparation:e,mode:t}),l(null))},retry:()=>void S(),getDraftHandoffTarget:E,prepareSession:D,send:async(...n)=>{let r=t;if(e){if(p.current)return!1;p.current=!0;try{let e=await D();if(!e)return!1;r=e,n[2]=void 0}finally{p.current=!1}}return!r||h.current!==r?!1:await m.current(...n)!==!1&&{conversationId:r}}}}function kD(e,t){let n=(0,X.c)(12),r=_(jD),i=_(AD),a;n[0]===e?a=n[1]:(a=t=>e?t.sessions[e]?.localDraft:void 0,n[0]=e,n[1]=a);let o=Sn(a),s;n[2]!==i||n[3]!==e||n[4]!==t||n[5]!==o||n[6]!==r?(s=e||t?[`chat-project-scope`,i,r,e,t,o===!0?`draft`:o===!1?`persisted`:`unknown`]:null,n[2]=i,n[3]=e,n[4]=t,n[5]=o,n[6]=r,n[7]=s):s=n[7];let c;n[8]!==e||n[9]!==t?(c=async()=>{let n=e?await jr(e):void 0,r=n?n.creation.projectId:e?(await hn(e)).projectId:t;return r?fn(r):null},n[8]=e,n[9]=t,n[10]=c):c=n[10];let l;n[11]===Symbol.for(`react.memo_cache_sentinel`)?(l={keepPreviousData:!1,shouldRetryOnError:!1},n[11]=l):l=n[11];let{data:u,error:d}=Qr(s,c,l);return d?null:u??null}function AD(e){return e.baseUrl}function jD(e){return e.conversationId}function MD(e,t){let n=es(e,t),r=ts(e,t);return`${e.id} ${n} ${r}`.toLowerCase()}function ND(e,t,n){let r=t.trim().toLowerCase();if(!r)return e;let i=r.split(/\s+/).filter(Boolean);return e.filter(e=>{let t=MD(e,n);return i.every(e=>t.includes(e))})}function PD(e){let t=(0,X.c)(57),{items:n,value:r,disabled:i,placeholder:a,searchPlaceholder:o,noMatches:s,compact:c,contentSide:l,contentAlign:u,className:d,onChange:f}=e,p=l===void 0?`bottom`:l,m=u===void 0?`end`:u,h=v(ID),g;t[0]===h?g=t[1]:(g=S(h),t[0]=h,t[1]=g);let _=g.agentsSettings,[y,b]=(0,Q.useState)(!1),[x,C]=(0,Q.useState)(``),w;t[2]!==_||t[3]!==n||t[4]!==x?(w=ND(n,x,_),t[2]=_,t[3]=n,t[4]=x,t[5]=w):w=t[5];let T=w,E,D,O;if(t[6]!==_||t[7]!==n||t[8]!==a||t[9]!==r){let e;t[13]===r?e=t[14]:(e=e=>e.id===r,t[13]=r,t[14]=e),D=n.find(e),E=D?es(D,_):r||a,O=D?[es(D,_),ts(D,_)].filter(Boolean).join(` — `):void 0,t[6]=_,t[7]=n,t[8]=a,t[9]=r,t[10]=E,t[11]=D,t[12]=O}else E=t[10],D=t[11],O=t[12];let k=O??a,A=c&&`min-w-0 max-w-[min(calc(15ch+3rem),calc(100vw-8rem))] py-1.5 text-[13px]`,j;t[15]!==d||t[16]!==A?(j=Y(Ca,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-2 text-left text-sm font-normal text-fg`,ca.transition,`hover:border-edge hover:bg-surface-hover/45`,wa,Sa,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,A,d),t[15]=d,t[16]=A,t[17]=j):j=t[17];let M;t[18]!==D?.avatar||t[19]!==r?(M=r?(0,Z.jsx)(Aa,{agentId:r,avatar:D?.avatar,size:28,className:`shrink-0`}):null,t[18]=D?.avatar,t[19]=r,t[20]=M):M=t[20];let N=c?`max-w-[15ch] shrink`:`flex-1`,P;t[21]===N?P=t[22]:(P=Y(`min-w-0 truncate text-left`,N),t[21]=N,t[22]=P);let F;t[23]!==E||t[24]!==P?(F=(0,Z.jsx)(`span`,{className:P,children:E}),t[23]=E,t[24]=P,t[25]=F):F=t[25];let I;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,Z.jsx)(ue,{className:`size-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0}),t[26]=I):I=t[26];let L;t[27]!==i||t[28]!==F||t[29]!==k||t[30]!==j||t[31]!==M?(L=(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:i,title:k,className:j,children:[M,F,I]})}),t[27]=i,t[28]=F,t[29]=k,t[30]=j,t[31]=M,t[32]=L):L=t[32];let R;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(R=Y(le,`z-50 w-[var(--radix-popover-trigger-width)] min-w-[12rem] rounded-lg border border-edge bg-surface-overlay shadow-md`,ca),t[33]=R):R=t[33];let z;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(z=e=>C(e.target.value),t[34]=z):z=t[34];let B;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(B=Y(`w-full rounded-md border border-edge bg-surface-panel px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-muted`,wa),t[35]=B):B=t[35];let ee;t[36]!==x||t[37]!==o?(ee=(0,Z.jsx)(`div`,{className:`shrink-0 border-b border-edge p-2`,children:(0,Z.jsx)(`input`,{type:`search`,value:x,onChange:z,placeholder:o,className:B,"aria-label":o})}),t[36]=x,t[37]=o,t[38]=ee):ee=t[38];let V;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(V=Y(G,`max-h-64 p-1`),t[39]=V):V=t[39];let H;t[40]!==_||t[41]!==T||t[42]!==s||t[43]!==f||t[44]!==r?(H=T.length===0?(0,Z.jsx)(`li`,{className:`p-2 text-sm text-fg-muted`,children:s}):T.map(e=>{let t=e.id===r,n=es(e,_),i=ts(e,_),a=i.length>0?i:void 0;return(0,Z.jsx)(`li`,{role:`option`,"aria-selected":t,children:(0,Z.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg`,t?`bg-surface-hover`:`hover:bg-surface-hover`),onClick:()=>{f(e.id),b(!1),C(``)},children:[(0,Z.jsx)(Aa,{agentId:e.id,avatar:e.avatar,size:32,className:`shrink-0`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate font-medium leading-tight`,title:n,children:n}),i?(0,Z.jsx)(`span`,{className:`mt-0.5 block truncate text-xs leading-tight text-fg-muted`,title:a,children:i}):null]}),(0,Z.jsx)(re,{className:Y(`size-4 shrink-0`,t?`opacity-100`:`opacity-0`),"aria-hidden":!0})]})},e.id)}),t[40]=_,t[41]=T,t[42]=s,t[43]=f,t[44]=r,t[45]=H):H=t[45];let U;t[46]===H?U=t[47]:(U=(0,Z.jsx)(`ul`,{"data-select-scroll-region":!0,className:V,role:`listbox`,children:H}),t[46]=H,t[47]=U);let W;t[48]!==m||t[49]!==p||t[50]!==ee||t[51]!==U?(W=(0,Z.jsx)(bi,{children:(0,Z.jsxs)(xi,{side:p,align:m,sideOffset:4,collisionPadding:8,className:R,onOpenAutoFocus:FD,children:[ee,U]})}),t[48]=m,t[49]=p,t[50]=ee,t[51]=U,t[52]=W):W=t[52];let te;return t[53]!==y||t[54]!==L||t[55]!==W?(te=(0,Z.jsxs)(Si,{open:y,onOpenChange:b,children:[L,W]}),t[53]=y,t[54]=L,t[55]=W,t[56]=te):te=t[56],te}function FD(e){return e.preventDefault()}function ID(e){return e.language}function LD(e,t,n=[],r){let i=new Map;for(let t of e)i.set(`${t.kind}:${t.id}`,{...t,pending:!1});let a=(e,t,n,r)=>{let a=`${e}:${t}`,o=i.get(a);if(o){o.pending=!0;return}i.set(a,{kind:e,id:t,title:n,...r?{fileKind:r}:{},origins:[],pending:!0})};for(let e of t)a(e.kind,e.sourceId,e.title,e.fileKind);for(let e of n)a(`attachment`,e.id,e.title);return r&&a(`app_context`,r.id,r.title),[...i.values()]}function RD(e){return e===`zh`?{title:`会话信息`,work:`当前工作`,sources:`关联来源`,environment:`运行位置`,independent:`独立会话`,delegatedTasks:`派出任务`,expand:`显示更多`,collapse:`收起`,session:`会话关联`,task:`任务关联`,recent:`最近引用`,draft:`待发送`,untitled:`未命名 Note`,untitledSource:`未命名来源`,unavailable:`暂无法查看`,partialUnavailable:`部分信息暂无法查看`,refresh:`重试`,more:`仅显示前 20 项`,local:`本地目录`,worktree:`Worktree`,detached:`游离 HEAD`,unavailableEnvironment:`运行目录不可用`,newEnvironment:`在另一环境新建会话`,copyEnvironmentPath:`复制环境路径`,copied:`已复制`}:{title:`Session info`,work:`Current work`,sources:`Related sources`,environment:`Run location`,independent:`Independent chat`,delegatedTasks:`Delegated tasks`,expand:`Show more`,collapse:`Show less`,session:`Linked to chat`,task:`Linked to task`,recent:`Recently used`,draft:`Pending send`,untitled:`Untitled Note`,untitledSource:`Untitled source`,unavailable:`Temporarily unavailable`,partialUnavailable:`Some details are unavailable`,refresh:`Retry`,more:`Showing the first 20 items`,local:`Local directory`,worktree:`Worktree`,detached:`Detached HEAD`,unavailableEnvironment:`Run directory unavailable`,newEnvironment:`New chat in another environment`,copyEnvironmentPath:`Copy environment path`,copied:`Copied`}}var zD=`flex min-w-0 items-center gap-3 rounded-lg px-2 py-2 text-sm text-fg transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,BD=`rounded-md px-2 py-1 text-xs text-fg-muted hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`;function VD({conversationId:e,draftRefs:t=[],draftAttachments:n=[],draftPage:r,project:i,...a}){let[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,f]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),g=RD(v(e=>e.language)),_=d(),y=`${_.pathname}${_.search}`,{data:b,error:x,isLoading:S,isValidating:C,mutate:w}=Df(e,o),T=x?void 0:b,E=T?.work.project??(!e&&i?{id:i.id,title:i.name}:void 0),D=T?.work.task,O=T?.work.delegatedTasks??[],k=LD(T?.sources??[],t,n,r),A=T?.environment,j=!!(E||D||O.length),N=!!T?.unavailableSections.includes(`work`),P=!!T?.unavailableSections.includes(`sources`),F=!!T?.unavailableSections.includes(`environment`),I=[E?.title,D?.title,k.length?`${g.sources} ${k.length}${T?.sourcesHasMore?`+`:``}`:null,A?.kind===`managed_worktree`?`Worktree`:null].filter(Boolean).join(` · `)||g.title,L=()=>s(!1),R=k.some(e=>e.kind===`note`&&!e.unavailable&&e.origins.some(e=>e.kind===`session`)),z=()=>{A?.rootPath&&Oi(A.rootPath).then(e=>{e&&(h(!0),window.setTimeout(()=>h(!1),1200))})},B=()=>(0,Z.jsx)(`button`,{type:`button`,className:BD,"aria-label":g.refresh,disabled:C,onClick:()=>void w(),children:(0,Z.jsx)(Pt,{className:`size-3.5 ${C?`animate-spin motion-reduce:animate-none`:``}`,"aria-hidden":!0})});return(0,Z.jsxs)(Si,{open:o,onOpenChange:s,children:[(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":g.title,title:I,className:`group inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-[background-color,color,transform] duration-150 hover:bg-surface-hover hover:text-fg active:scale-95 data-[state=open]:bg-surface-hover data-[state=open]:text-fg motion-reduce:transition-none motion-reduce:transform-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:(0,Z.jsx)(Xe,{className:`size-4 transition-transform duration-200 group-data-[state=open]:scale-110 motion-reduce:transform-none motion-reduce:transition-none`,strokeWidth:1.75,"aria-hidden":!0})})}),(0,Z.jsx)(bi,{children:(0,Z.jsx)(xi,{align:`end`,sideOffset:8,collisionPadding:12,"aria-label":g.title,onCloseAutoFocus:e=>{document.activeElement?.closest(`[data-primary-chat-composer]`)&&e.preventDefault()},className:`xopc-session-context-popover z-50 w-[min(23rem,calc(100vw-1.5rem))] rounded-xl border border-edge bg-surface-overlay shadow-popover`,children:(0,Z.jsxs)(`div`,{className:`max-h-[min(30rem,var(--radix-popover-content-available-height))] overflow-y-auto rounded-xl p-3`,children:[(0,Z.jsx)(`h2`,{className:`mb-2 px-2 text-sm font-medium text-fg`,children:g.title}),S?(0,Z.jsx)(`div`,{className:`space-y-2 px-2`,"aria-busy":`true`,children:[0,1,2].map(e=>(0,Z.jsx)(Qt,{className:`h-8 w-full`},e))}):x?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 text-sm text-fg-muted`,children:[(0,Z.jsx)(`span`,{children:g.unavailable}),B()]}):(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`section`,{"aria-label":g.work,children:[E?(0,Z.jsxs)(p,{className:zD,to:nt(y,`/projects/${encodeURIComponent(E.id)}`),onClick:L,children:[(0,Z.jsx)(ke,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:E.title,children:E.title})]}):null,D?(0,Z.jsxs)(p,{className:zD,to:tt(y,D.id),onClick:L,children:[(0,Z.jsx)(js,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:D.title,children:D.title}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:D.phase})]}):null,O.length?(0,Z.jsxs)(Z.Fragment,{children:[O.length>2?(0,Z.jsxs)(`button`,{type:`button`,className:`${zD} w-full text-left`,onClick:()=>l(!c),"aria-expanded":c,children:[(0,Z.jsx)(js,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsxs)(`span`,{className:`flex-1`,children:[g.delegatedTasks,` · `,T?.work.delegatedTaskCount??O.length]}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:c?g.collapse:g.expand})]}):(0,Z.jsxs)(`p`,{className:`px-2 pt-2 text-xs text-fg-subtle`,children:[g.delegatedTasks,` · `,T?.work.delegatedTaskCount??O.length]}),(c?O:O.slice(0,2)).map(e=>(0,Z.jsxs)(p,{className:`${zD} pl-9`,to:tt(y,e.id),onClick:L,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title,children:e.title}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:e.runStatus??e.phase})]},e.id))]}):null,j?null:(0,Z.jsx)(`p`,{className:`px-2 py-2 text-sm text-fg-muted`,children:N?g.unavailable:g.independent}),N?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2 text-xs text-fg-muted`,children:[j?g.partialUnavailable:null,B()]}):null,E&&a.onLeaveProject?(0,Z.jsx)(`button`,{type:`button`,className:BD,onClick:()=>{L(),a.onLeaveProject?.()},children:a.leaveProjectLabel}):null]}),k.length||P?(0,Z.jsxs)(`section`,{className:`border-t border-edge-subtle pt-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between px-2`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm text-fg-subtle`,children:[g.sources,` `,k.length?`${k.length}${T?.sourcesHasMore?`+`:``}`:``]}),P?B():null]}),(u?k:k.slice(0,3)).map(e=>{let t=e.origins.some(e=>e.kind===`session`)?g.session:e.origins.some(e=>e.kind===`task`)?g.task:e.origins.some(e=>e.kind===`recent`)?g.recent:g.draft,n=e.pending&&e.origins.length?`${t} · ${g.draft}`:e.pending?g.draft:t,r=e.kind===`file`&&e.fileKind===`directory`?je:e.kind===`file`?Oe:e.kind===`session`?wt:e.kind===`browser_tab`||e.kind===`browser_page`||e.kind===`app_context`?M:e.kind===`mcp_resource`?Se:e.kind===`attachment`?kt:Oe,i=e.unavailable?g.unavailable:e.title||(e.kind===`note`?g.untitled:g.untitledSource),a=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(r,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.unavailable?void 0:e.title,children:i}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-muted`,children:n})]}),o=e.kind===`note`?Ct(y,e.id):e.kind===`session`?`/chat/${encodeURIComponent(e.id)}`:null,s=`${e.kind}:${e.id}`;return!e.unavailable&&o?(0,Z.jsx)(p,{className:zD,to:o,onClick:L,children:a},s):(0,Z.jsx)(`div`,{className:`flex min-w-0 items-center gap-3 px-2 py-2 text-sm text-fg-muted`,children:a},s)}),k.length?null:(0,Z.jsx)(`p`,{className:`px-2 py-2 text-xs text-fg-muted`,children:g.unavailable}),k.length>0&&P?(0,Z.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:g.partialUnavailable}):null,k.length>3?(0,Z.jsx)(`button`,{type:`button`,className:BD,onClick:()=>f(!u),"aria-expanded":u,children:u?g.collapse:g.expand}):null,T?.sourcesHasMore?(0,Z.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:g.more}):null,R&&a.onDraftSourceNote?(0,Z.jsx)(`button`,{type:`button`,className:BD,onClick:()=>{L(),a.onDraftSourceNote?.()},children:a.draftSourceNoteLabel}):null]}):null,e&&(A||F)||a.environmentAction?(0,Z.jsxs)(`section`,{className:`border-t border-edge-subtle pt-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between px-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm text-fg-subtle`,children:g.environment}),F?B():null]}),A?null:a.environmentAction,A?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 px-2 py-2 text-sm text-fg`,children:[(0,Z.jsx)(Et,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:A.kind===`managed_worktree`?g.worktree:g.local}),A.branch||A.headSha?(0,Z.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-40 items-center gap-1 text-xs text-fg-muted`,children:[(0,Z.jsx)(Fe,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:A.branch||(A.detached?`${g.detached} · ${A.headSha?.slice(0,8)}`:A.headSha?.slice(0,8))})]}):null]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 pl-9 pr-1`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-fg-muted`,title:A.rootPath,children:A.rootPath}),(0,Z.jsx)(`button`,{type:`button`,className:BD,"aria-label":m?g.copied:g.copyEnvironmentPath,title:m?g.copied:g.copyEnvironmentPath,onClick:z,children:m?(0,Z.jsx)(re,{className:`size-3.5`,"aria-hidden":!0}):(0,Z.jsx)(xe,{className:`size-3.5`,"aria-hidden":!0})})]}),a.environmentAction,A.available?null:(0,Z.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:g.unavailableEnvironment}),E&&i?.workspaceRoot?(0,Z.jsx)(J,{className:BD,to:Ra(E.id),state:{forceNewChat:!0,agentId:a.agentId,temporary:a.temporary},onClick:L,children:g.newEnvironment}):null]}):(0,Z.jsx)(`p`,{className:`px-2 py-2 text-xs text-fg-muted`,children:g.unavailable})]}):null]}),a.executionDeviceAction]})})})]})}var HD=`min(36dvh, 320px)`;function UD(e){return e&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0?e.width/e.height:void 0}function WD(e){let t=UD(e);return t?`min(calc(100vw - 2rem), ${36*t}dvh, ${Math.min(480,320*t)}px)`:`min(320px, calc(100vw - 2rem))`}function GD(e,t){if(e)return e.phase===`observing`?e.action?t?`正在查看操作结果`:`Checking the result`:t?`正在查看画面`:`Observing the window`:e.action?{activate:[`正在点击`,`Clicking`,`已点击`,`Clicked`],activateSequence:[`正在连续点击`,`Clicking controls`,`已连续点击`,`Controls clicked`],batch:[`正在执行操作`,`Performing actions`,`操作已执行`,`Actions completed`],showMenu:[`正在打开菜单`,`Opening a menu`,`菜单已打开`,`Menu opened`],click:[`正在点击`,`Clicking`,`已点击`,`Clicked`],drag:[`正在拖动`,`Dragging`,`已拖动`,`Dragged`],setValue:[`正在填写`,`Filling a field`,`已填写`,`Field filled`],typeText:[`正在输入`,`Typing`,`已输入`,`Typed`],pressKeys:[`正在按键`,`Pressing keys`,`已按键`,`Keys pressed`],scroll:[`正在滚动`,`Scrolling`,`已滚动`,`Scrolled`],wait:[`正在等待`,`Waiting`,`等待结束`,`Wait completed`]}[e.action]?.[(e.phase===`acting`?0:2)+ +!t]:t?`正在查看画面`:`Observing the window`}function KD(e,t=!0){let[n,r]=(0,Q.useState)(),[i,a]=(0,Q.useState)(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(),[u,d]=(0,Q.useState)(),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(0),[g,_]=(0,Q.useState)(!0),v=(0,Q.useRef)(new Set),y=(0,Q.useRef)(0),b=window.electronAPI?.computer?.preview,x=(0,Q.useCallback)(e=>{for(let e of v.current)e.isConnected||v.current.delete(e);e&&v.current.add(e)},[]);(0,Q.useEffect)(()=>{if(r(void 0),s(!1),a(void 0),!e||!b)return;let t=!1,n=!1,i=b.onState(i=>{!t&&i.conversationId===e&&(n=!0,r(i))});return b.current(e).then(i=>{!t&&!n&&r(i?.conversationId===e?i:void 0)}).catch(()=>{}),()=>{t=!0,i()}},[b,e]);let S=n?.previewId,C=n?.targetEpoch,w=n?.runId,T=n?.status===`preparing`&&!i,E=n?.status===`ended`;return(0,Q.useEffect)(()=>{if(s(!1),l(void 0),p(!1),y.current=0,!t||!b||!e||!S||C===void 0||E||T&&m===0)return;let n=!1,i,o=0,c=0;return b.subscribe({conversationId:e,runId:w,preset:`compact`},async e=>{if(n||e.previewId!==S||e.targetEpoch!==C)return;if(!(`sequence`in e)){r(e);return}if(e.streamEpoch<o||e.streamEpoch===o&&e.sequence<=c)return;o=e.streamEpoch,c=e.sequence;let t=new Uint8Array(e.bytes),i;try{if(i=await createImageBitmap(new Blob([t],{type:`image/jpeg`})),n||o!==e.streamEpoch||c!==e.sequence)return;for(let e of v.current){if(!e.isConnected){v.current.delete(e);continue}e.width=i.width,e.height=i.height,e.getContext(`2d`)?.drawImage(i,0,0)}let r=i.width,a=i.height;l(e=>e?.width===r&&e.height===a?e:{width:r,height:a}),y.current=performance.now(),d(S),s(!0),p(!1)}finally{i?.close()}}).then(e=>{i=e.subscriptionId,n?b.unsubscribe(i).catch(()=>{}):a(i)}).catch(()=>{n||r(e=>e?.previewId===S?{...e,status:`unavailable`,errorCode:`COMPUTER_PREVIEW_UNAVAILABLE`}:e)}),()=>{n=!0,a(void 0),i&&b.unsubscribe(i).catch(()=>{})}},[b,e,S,C,w,m,E,t]),(0,Q.useEffect)(()=>{let e=()=>_(document.visibilityState!==`hidden`);e(),document.addEventListener(`visibilitychange`,e);let t=setInterval(()=>{y.current&&p(performance.now()-y.current>1500)},500);return()=>{clearInterval(t),document.removeEventListener(`visibilitychange`,e)}},[]),{state:n,subscriptionId:i,frameSize:c,hasFrame:o&&u===n?.previewId,stale:f,visible:g,registerCanvas:x,retry:()=>h(e=>e+1),api:b}}function qD({conversationId:e,onFrameSizeChange:t}){let n=KD(e),[r,i]=(0,Q.useState)(!0),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(null),u=v(e=>e.language===`zh`),d=n.state?.previewId;if((0,Q.useEffect)(()=>{n.frameSize&&t?.(n.frameSize)},[n.frameSize,t]),(0,Q.useEffect)(()=>{c(!1)},[d]),(0,Q.useEffect)(()=>{if(!l.current||typeof IntersectionObserver>`u`)return;let e=new IntersectionObserver(e=>i(e.some(e=>e.isIntersecting)),{rootMargin:`160px`});return e.observe(l.current),()=>e.disconnect()},[d]),(0,Q.useEffect)(()=>{!n.subscriptionId||!n.api||n.api.setPreset(n.subscriptionId,n.visible&&r?`compact`:`paused`).catch(()=>{})},[n.api,n.subscriptionId,n.visible,r]),!n.state||n.state.conversationId!==e||n.state.status===`ended`)return null;let f=n.state.status===`unavailable`,p=s?u?`重试切换`:`Retry switch`:n.stale?u?`等待新画面`:`Waiting for a new frame`:GD(n.state.activity,u),m=async()=>{let t=window.electronAPI?.computer;if(!(!t?.focusTarget||!e||!d||a)){o(!0),c(!1);try{await t.focusTarget(e,d)}catch{c(!0)}finally{o(!1)}}};return(0,Z.jsxs)(`section`,{ref:l,"aria-label":u?`电脑操作预览`:`Computer activity`,className:`relative w-full overflow-hidden rounded-xl bg-transparent`,style:{aspectRatio:UD(n.frameSize)??16/10,maxHeight:HD},children:[!n.hasFrame&&!f&&(0,Z.jsx)(Qt,{className:`absolute inset-0`}),(0,Z.jsx)(`canvas`,{ref:n.registerCanvas,role:`img`,"aria-label":u?`${n.state.appName}窗口预览`:`${n.state.appName} window preview`,className:`absolute inset-0 h-full w-full object-contain ${n.hasFrame&&!f?``:`invisible`}`}),!f&&(0,Z.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`absolute left-2 top-2 z-10 max-w-[calc(100%-1rem)]`,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:a||!window.electronAPI?.computer?.focusTarget,"aria-label":u?`切换到正在操作的应用`:`Switch to the active app`,title:s?u?`暂时无法切换应用,请重试`:`Could not switch to the app. Try again.`:u?`切换到应用`:`Switch to app`,className:`inline-flex min-h-11 min-w-11 max-w-full sm:min-h-9 sm:min-w-9 items-center justify-center gap-1.5 rounded-md bg-surface-overlay/80 px-2 text-xs text-fg backdrop-blur-sm hover:bg-surface-overlay focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>{m()},children:[(0,Z.jsx)(Et,{size:14,className:`shrink-0`,"aria-hidden":!0}),p&&(0,Z.jsx)(`span`,{className:`truncate`,children:p})]})}),f&&(0,Z.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-surface-panel/90`,children:(0,Z.jsx)(`button`,{className:`min-h-11 rounded-md px-3 text-sm text-fg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:n.retry,children:u?`预览暂时不可用,点击重试`:`Preview unavailable. Retry preview`})})]})}function JD(e){let t=(0,X.c)(26),{conversationId:n}=e,{state:r}=KD(n,!1),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(),c=v(XD),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{a(!1),s(void 0)},t[0]=l):l=t[0];let u=r?.previewId,d;if(t[1]!==n||t[2]!==u?(d=[n,u],t[1]=n,t[2]=u,t[3]=d):d=t[3],(0,Q.useEffect)(l,d),!r||r.conversationId!==n||r.status===`ended`)return null;let f=c?`查看电脑预览`:`View computer preview`,p=c?`查看电脑预览`:`View computer preview`,m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Z.jsx)(Et,{className:`size-4 shrink-0`,"aria-hidden":!0}),t[4]=m):m=t[4];let h=c?`电脑`:`Computer`,g;t[5]===h?g=t[6]:(g=(0,Z.jsx)(`span`,{className:`hidden whitespace-nowrap text-xs xl:inline`,children:h}),t[5]=h,t[6]=g);let _;t[7]!==f||t[8]!==p||t[9]!==g?(_=(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsxs)(vi,{variant:`ghost`,className:`size-8 shrink-0 gap-1.5 rounded-lg p-0 xl:w-auto xl:px-2`,title:f,"aria-label":p,children:[m,g]})}),t[7]=f,t[8]=p,t[9]=g,t[10]=_):_=t[10];let y=c?`电脑预览`:`Computer preview`,b;t[11]===o?b=t[12]:(b=WD(o),t[11]=o,t[12]=b);let x;t[13]===b?x=t[14]:(x={"--computer-preview-width":b},t[13]=b,t[14]=x);let S=x,C;t[15]!==n||t[16]!==r.previewId?(C=(0,Z.jsx)(qD,{conversationId:n,onFrameSizeChange:s},r.previewId),t[15]=n,t[16]=r.previewId,t[17]=C):C=t[17];let w;t[18]!==y||t[19]!==S||t[20]!==C?(w=(0,Z.jsx)(bi,{children:(0,Z.jsx)(xi,{align:`end`,sideOffset:8,collisionPadding:16,"aria-label":y,onOpenAutoFocus:YD,style:S,className:`z-40 w-[var(--computer-preview-width)] max-h-[calc(100dvh-5rem)] overflow-hidden rounded-xl bg-transparent p-0 outline-none`,children:C})}),t[18]=y,t[19]=S,t[20]=C,t[21]=w):w=t[21];let T;return t[22]!==i||t[23]!==w||t[24]!==_?(T=(0,Z.jsxs)(Si,{open:i,onOpenChange:a,children:[_,w]}),t[22]=i,t[23]=w,t[24]=_,t[25]=T):T=t[25],T}function YD(e){return e.preventDefault()}function XD(e){return e.language===`zh`}function ZD({conversationId:e,deviceName:t,zh:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,_]=(0,Q.useState)(!1),v=g(`/api/endpoint-tools/artifact-transfers`),{data:b,isLoading:x}=Qr(r?`${v}?conversationId=${encodeURIComponent(e)}`:null,e=>y(e),{shouldRetryOnError:!1}),S=b?.payload.files??[],j=b?.payload.tools??[],M=j.find(e=>e.toolName===s);return(0,Z.jsxs)(A,{open:r,onOpenChange:e=>{i(e),e&&(o(``),c(``),u(``),m(!1),_(!1))},children:[(0,Z.jsx)(w,{asChild:!0,children:(0,Z.jsx)(vi,{variant:`ghost`,className:`h-8 px-2 text-sm`,children:n?`传递文件`:`Transfer file`})}),(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`fixed inset-0 z-[120] bg-black/50`}),(0,Z.jsxs)(O,{className:`fixed left-1/2 top-1/2 z-[121] flex h-[min(23rem,90dvh)] w-[min(28rem,92vw)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay p-4 shadow-popover`,children:[(0,Z.jsx)(k,{className:`text-base font-semibold`,children:n?`向执行设备传递文件`:`Transfer file to execution device`}),(0,Z.jsx)(T,{className:`mt-1 text-sm text-fg-muted`,children:t}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto py-3`,children:[x?(0,Z.jsx)(Qt,{className:`h-20 w-full`}):S.length&&j.length?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(fe,{value:a,onChange:o,placeholder:n?`选择源文件`:`Select source file`,options:S.map(e=>({value:e.fileId,label:`${e.name} · ${e.sourceName} · ${Math.ceil(e.size/1024)} KB`}))}),(0,Z.jsx)(fe,{value:s,onChange:c,placeholder:n?`选择接收能力`:`Select receiving capability`,options:j.map(e=>({value:e.toolName,label:e.title}))})]}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n?`当前没有可传递的文件或接收能力。`:`No eligible file or receiving capability is available.`}),l?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n?`在两分钟内将这段请求发到当前对话。`:`Send this request in this chat within two minutes.`}),(0,Z.jsx)(`textarea`,{readOnly:!0,className:`h-20 w-full resize-none rounded-md border border-edge bg-surface-inset p-2 text-xs`,value:l,"aria-label":n?`对话请求`:`Chat request`,onFocus:e=>e.currentTarget.select()})]}):null,h?(0,Z.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:n?`文件授权失败,请重新选择设备或文件。`:`Unable to authorize transfer. Reselect the device or file.`}):null]}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(vi,{variant:`secondary`,children:n?`关闭`:`Close`})}),l?(0,Z.jsx)(vi,{onClick:async()=>{try{await navigator.clipboard.writeText(l),m(!0)}catch{m(!1)}},children:p?n?`已复制`:`Copied`:n?`复制请求`:`Copy request`}):(0,Z.jsx)(vi,{disabled:d||!M||!S.some(e=>e.fileId===a),onClick:async()=>{if(M){f(!0),_(!1);try{let t=await y(v,{method:`POST`,body:JSON.stringify({conversationId:e,fileId:a,toolName:s})}),r=JSON.stringify({[M.input]:t.payload.transferId});u(n?`请在当前执行设备调用 ${s} 处理已授权的文件,使用参数 ${r}。`:`Use ${s} on the selected execution device to process the authorized file with argument ${r}.`)}catch{_(!0)}finally{f(!1)}}},children:d?n?`授权中…`:`Authorizing…`:n?`生成一次性授权`:`Authorize one transfer`})]})]})]})]})}function QD({conversationId:e,disabled:t}){let n=v(e=>e.language)===`zh`,r=e&&/^[0-9a-f-]{36}$/i.test(e)?g(`/api/endpoint-tools/targets/${encodeURIComponent(e)}`):null,i=Qr(r,async e=>{let t=await h(e);if(t.status===404||t.status===403)return null;if(!t.ok)throw Error(`Device target unavailable`);return(await t.json()).payload},{refreshInterval:5e3,shouldRetryOnError:!1}),a=Qr(r?ls():null,us,{refreshInterval:3e4,shouldRetryOnError:!1}),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1);if(!r)return null;let u=(a.data??[]).filter(e=>!e.principal?.revokedAt&&!e.access?.revokedAt).flatMap(e=>e.endpoints.map(t=>({value:t.endpointId,label:`${e.displayName} · ${e.platform}`}))),d=i.data,f=(a.data??[]).find(e=>e.id===d?.principalId),p=f?.endpoints.some(e=>e.endpointId===d?.endpointId&&e.connectionId===d?.connectionId),m=d&&(!p||d.expiresAt<=Date.now()),_=d?`${f?.displayName??(n?`所选设备`:`Selected device`)}${m?n?` · 需要重新选择`:` · Reselect required`:``}`:void 0;return d&&!u.some(e=>e.value===d.endpointId)&&u.push({value:d.endpointId,label:_,disabled:!0}),(0,Z.jsxs)(`section`,{className:`mt-3 space-y-2 border-t border-edge-subtle px-2 pt-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm text-fg-subtle`,children:n?`执行设备`:`Execution device`}),i.isLoading||a.isLoading?(0,Z.jsx)(Qt,{className:`h-10 w-full rounded-lg`}):(0,Z.jsx)(fe,{value:d?.endpointId??``,options:u,allowEmpty:!0,emptyLabel:n?`由对话选择`:`Choose in conversation`,placeholder:n?`由对话选择`:`Choose in conversation`,title:_,selectedLabel:_,ariaLabel:n?`选择执行设备`:`Select execution device`,triggerIcon:(0,Z.jsx)(Et,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),triggerClassName:`justify-start [&>span]:flex-1`,side:`bottom`,disabled:t||o||!!(a.error||i.error),onChange:async e=>{if(!o){s(!0),l(!1);try{await y(r,{method:e?`PUT`:`DELETE`,...e?{body:JSON.stringify({endpointId:e})}:{}}),await i.mutate()}catch{l(!0),await i.mutate()}finally{s(!1)}}}}),e&&d&&!m&&!t?(0,Z.jsx)(ZD,{conversationId:e,deviceName:f?.displayName??d.endpointId,zh:n},d.connectionId):null,c?(0,Z.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:n?`无法更改设备,请先结束正在进行的操作并重试。`:`Unable to change device. Finish active operations and retry.`}):null]})}function $D(e){let t=(0,X.c)(23),{conversationId:n}=e,{data:r}=ac(n),i=v(tO)===`zh`,a=mc(eO),o,s;if(t[0]!==n||t[1]!==r||t[2]!==a){let e=r?pc(n,r.report):null;o=Boolean,s=e&&!a.includes(e),t[0]=n,t[1]=r,t[2]=a,t[3]=o,t[4]=s}else o=t[3],s=t[4];let c=o(s);if(!r||Qs(r.report.status))return null;let l=c?i?`手机需要你操作`:`Your help is needed on the phone`:i?`查看手机`:`View phone`,u=c?i?`手机需要你操作`:`Your help is needed on the phone`:i?`查看手机`:`View phone`,d;t[5]!==n||t[6]!==r.report.deviceId||t[7]!==r.report.deviceName||t[8]!==r.report.sessionId?(d=()=>yi.getState().openPhone(r.report.deviceId??r.report.sessionId,r.report.deviceName,n,!0),t[5]=n,t[6]=r.report.deviceId,t[7]=r.report.deviceName,t[8]=r.report.sessionId,t[9]=d):d=t[9];let f;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(Vt,{className:`size-4`,"aria-hidden":!0}),t[10]=f):f=t[10];let p;t[11]===c?p=t[12]:(p=c&&(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`absolute -right-1 -top-1 size-1.5 rounded-full bg-accent`}),t[11]=c,t[12]=p);let m;t[13]===p?m=t[14]:(m=(0,Z.jsxs)(`span`,{className:`relative`,children:[f,p]}),t[13]=p,t[14]=m);let h=i?`手机`:`Phone`,g;t[15]===h?g=t[16]:(g=(0,Z.jsx)(`span`,{className:`text-xs`,children:h}),t[15]=h,t[16]=g);let _;return t[17]!==g||t[18]!==l||t[19]!==u||t[20]!==d||t[21]!==m?(_=(0,Z.jsxs)(vi,{variant:`ghost`,className:`min-h-10 gap-1.5 px-2`,title:l,"aria-label":u,onClick:d,children:[m,g]}),t[17]=g,t[18]=l,t[19]=u,t[20]=d,t[21]=m,t[22]=_):_=t[22],_}function eO(e){return e.seen}function tO(e){return e.language}function nO(e){let t=(0,X.c)(57),{conversationId:n,directoryOnly:r,workspacePath:i,canChangeWorkspace:a,disabled:o,available:s,onWorkspaceChange:c}=e,l=r!==void 0&&r,u=s===void 0||s,d=v(oO),f;t[0]===d?f=t[1]:(f=S(d),t[0]=d,t[1]=f);let p=f,m=fp(aO),h;t[2]===n?h=t[3]:(h=e=>e.panes[n??`new`]?.open===!0,t[2]=n,t[3]=h);let g=yi(h),[_,y]=(0,Q.useState)(null),b,x;t[4]!==p.chat.workingDirectory.notSet||t[5]!==i?(b=i?.trim()??``,x=b?Ha(b):p.chat.workingDirectory.notSet,t[4]=p.chat.workingDirectory.notSet,t[5]=i,t[6]=b,t[7]=x):(b=t[6],x=t[7]);let w=x,E;t[8]===c?E=t[9]:(E=async e=>{try{await c(e)}catch(e){let t=e;y(t instanceof Error?t.message:String(t))}},t[8]=c,t[9]=E);let j=E,M;t[10]!==j||t[11]!==b?(M={initialPath:b,onPicked:j},t[10]=j,t[11]=b,t[12]=M):M=t[12];let N=Ua(M),P=o||!u||N.picking,F;t[13]!==n||t[14]!==m?(F=()=>{let e=yi.getState(),t=n??`new`;e.setScope(t);let r=e.panes[t]?.tabs.find(iO);r?e.activate(r.id,t):e.openTools(t),m(n??``)},t[13]=n,t[14]=m,t[15]=F):F=t[15];let I=F,L;t[16]!==l||t[17]!==d||t[18]!==I||t[19]!==g?(L=l?null:(0,Z.jsx)(`button`,{type:`button`,className:Y(`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-colors`,`hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,g&&`bg-surface-hover text-fg`),title:d===`zh`?`打开工具`:`Open workspace tools`,"aria-label":d===`zh`?`打开工具`:`Open workspace tools`,"aria-pressed":g,"aria-controls":`app-workspace-panel`,"data-workspace-trigger":!0,onClick:I,children:(0,Z.jsx)(As,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0})}),t[16]=l,t[17]=d,t[18]=I,t[19]=g,t[20]=L):L=t[20];let R;t[21]!==a||t[22]!==l||t[23]!==N||t[24]!==p.chat.workingDirectory.chooseFolder||t[25]!==b||t[26]!==P||t[27]!==w?(R=l&&a?(0,Z.jsxs)(`button`,{type:`button`,disabled:P,className:Y(`inline-flex h-8 max-w-full shrink-0 px-2 items-center justify-center rounded-lg text-fg-muted transition-colors`,`hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,P&&`cursor-not-allowed opacity-50`),title:`${p.chat.workingDirectory.chooseFolder}: ${b||w}`,"aria-label":p.chat.workingDirectory.chooseFolder,onClick:N.pick,children:[(0,Z.jsx)(se,{className:`mr-2 size-4`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate text-xs`,children:p.chat.workingDirectory.chooseFolder})]}):null,t[21]=a,t[22]=l,t[23]=N,t[24]=p.chat.workingDirectory.chooseFolder,t[25]=b,t[26]=P,t[27]=w,t[28]=R):R=t[28];let z;t[29]!==R||t[30]!==L?(z=(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5`,children:[L,R]}),t[29]=R,t[30]=L,t[31]=z):z=t[31];let B;t[32]!==l||t[33]!==N||t[34]!==p.chat.workingDirectory||t[35]!==b?(B=l&&!N.hasNativePicker?(0,Z.jsx)(ce,{open:N.modalOpen,onOpenChange:N.setModalOpen,initialAbsolutePath:b||void 0,onConfirm:N.confirmPick,wd:p.chat.workingDirectory}):null,t[32]=l,t[33]=N,t[34]=p.chat.workingDirectory,t[35]=b,t[36]=B):B=t[36];let ee=_!==null,V;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(V=e=>{e||y(null)},t[37]=V):V=t[37];let H;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[80] bg-scrim backdrop-blur-[2px]`}),t[38]=H):H=t[38];let U;t[39]===p.chat.workingDirectory.applyErrorTitle?U=t[40]:(U=(0,Z.jsx)(k,{className:`text-base font-semibold text-fg`,children:p.chat.workingDirectory.applyErrorTitle}),t[39]=p.chat.workingDirectory.applyErrorTitle,t[40]=U);let W;t[41]===_?W=t[42]:(W=_?(0,Z.jsx)(T,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-fg-muted`,children:_}):null,t[41]=_,t[42]=W);let te;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(te=()=>y(null),t[43]=te):te=t[43];let ne;t[44]===p.chat.workingDirectory.applyErrorClose?ne=t[45]:(ne=(0,Z.jsx)(`div`,{className:`mt-4 flex justify-end border-t border-edge-subtle pt-3`,children:(0,Z.jsx)(vi,{type:`button`,onClick:te,children:p.chat.workingDirectory.applyErrorClose})}),t[44]=p.chat.workingDirectory.applyErrorClose,t[45]=ne);let re;t[46]!==U||t[47]!==W||t[48]!==ne?(re=(0,Z.jsxs)(D,{children:[H,(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[81] w-[min(100%-2rem,26rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-edge bg-surface-overlay p-4 shadow-popover`,onOpenAutoFocus:rO,children:[U,W,ne]})]}),t[46]=U,t[47]=W,t[48]=ne,t[49]=re):re=t[49];let ie;t[50]!==ee||t[51]!==re?(ie=(0,Z.jsx)(A,{open:ee,onOpenChange:V,children:re}),t[50]=ee,t[51]=re,t[52]=ie):ie=t[52];let ae;return t[53]!==z||t[54]!==B||t[55]!==ie?(ae=(0,Z.jsxs)(Z.Fragment,{children:[z,B,ie]}),t[53]=z,t[54]=B,t[55]=ie,t[56]=ae):ae=t[56],ae}function rO(e){return e.preventDefault()}function iO(e){return e.kind===`home`}function aO(e){return e.openForSession}function oO(e){return e.language}function sO(e,t){return e.repeat||e.altKey||e.shiftKey||e.key.toLowerCase()!==`j`?!1:t===`darwin`?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function cO({conversationId:e,dialogOpen:t,onDialogOpenChange:n,hideTrigger:r=!1}){let i=v(e=>e.language),a=i===`zh`?uO:dO,[o,s]=(0,Q.useState)(!1),c=t??o,l=e=>{s(e),n?.(e)},[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(864e5),[x,S]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(``),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)([]),[L,R]=(0,Q.useState)(`hosted`),[z,B]=(0,Q.useState)(!1),[ee,V]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!c||u||f)return;let t=!1;return h(!0),_(null),Promise.all([oo(e),uo(e),ao()]).then(async([n,r,i])=>{if(t)return;d(n),B(i);let a=i?await fo().catch(()=>null):null;if(t)return;V(a?.publishing.allowed===!0);let o=i?await po(e).catch(()=>[]):[];if(t)return;let s=[...o,...r].find(e=>!e.revoked&&!e.expired);s&&p(s)}).catch(e=>{t||_(e instanceof Error?e.message:String(e))}).finally(()=>{t||h(!1)}),()=>{t=!0}},[c,u,f,e]);let H=()=>{d(null),p(null),_(null),h(!1),M(``),P(!1),I([]),V(!1)},U=async()=>{if(!(!u||m)){h(!0),_(null);try{p(await(L===`hosted`?lo:co)(e,{expectedTranscriptId:u.transcriptId,expectedCutoffSeq:u.cutoffSeq,expectedMetadataUpdatedAt:u.metadataUpdatedAt,ttlMs:y,maxViews:x,description:j.trim()||void 0,includeToolActivities:N,attachmentIds:F}))}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},W=async()=>{if(!(!f||m)){h(!0),_(null);try{let t=await oo(e);d(t);let n=f.delivery===`hosted`?so:ro;p(await n(e,f.id,{expectedTranscriptId:t.transcriptId,expectedCutoffSeq:t.cutoffSeq,expectedMetadataUpdatedAt:t.metadataUpdatedAt}))}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},te=async()=>{if(!(!f||m)){h(!0),_(null);try{f.delivery===`hosted`?await mo(e,f.id):await io(f.id),l(!1),H()}catch(e){_(e instanceof Error?e.message:String(e)),h(!1)}}};return(0,Z.jsxs)(A,{open:c,onOpenChange:e=>{l(e),e||H()},children:[r?null:(0,Z.jsx)(w,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`rounded-md p-2 text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg`,title:a.share,"aria-label":a.share,children:(0,Z.jsx)(Es,{className:`size-4`})})}),(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[70] bg-scrim backdrop-blur-[2px]`}),(0,Z.jsxs)(O,{onCloseAutoFocus:e=>{r&&(e.preventDefault(),document.querySelector(`[data-chat-menu-trigger]`)?.focus())},className:Y(`xopc-dialog-content fixed left-1/2 top-1/2 z-[71] flex h-[min(35rem,calc(100dvh-2rem))] w-[min(34rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,`overflow-hidden rounded-xl border border-edge bg-surface-overlay outline-none`),children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(k,{className:`text-base font-semibold text-fg`,children:f?a.created:a.title}),(0,Z.jsx)(T,{className:`mt-0.5 text-xs text-fg-muted`,children:f?a.createdHint:a.hint})]}),(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`touch-target flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,"aria-label":a.close,children:(0,Z.jsx)(Xt,{className:`size-4`})})})]}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:[m&&!u&&!f?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Z.jsx)(Ze,{className:`size-4 animate-spin`}),a.loading]}):f?(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:f.fileName}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.snapshotMessages.replace(`{{count}}`,String(f.messageCount))}),(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:[f.delivery===`hosted`?a.hosted:a.local,` · `,a.revision.replace(`{{revision}}`,String(f.snapshotRevision)),` · `,a.sharedAttachments.replace(`{{count}}`,String(f.attachmentCount))]})]}),(0,Z.jsx)(qt,{shareUrl:f.shareUrl,lanUrl:f.lanUrl,reachability:f.reachability}),(0,Z.jsx)(Jt,{reachability:f.reachability,reachabilityHint:f.reachabilityHint}),(0,Z.jsxs)(`a`,{href:f.shareUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-sm font-medium text-accent hover:underline`,children:[a.open,(0,Z.jsx)(we,{className:`size-3.5`})]})]}):u?(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-inset p-3`,children:[(0,Z.jsx)(`p`,{className:`truncate text-sm font-medium text-fg`,children:u.title}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.snapshotMessages.replace(`{{count}}`,String(u.messageCount))}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:new Date(u.snapshotAt).toLocaleString(i===`zh`?`zh-CN`:`en-US`)})]}),(0,Z.jsxs)(`details`,{className:`rounded-lg border border-edge`,children:[(0,Z.jsx)(`summary`,{className:`touch-target cursor-pointer px-3 py-2.5 text-xs font-medium text-fg transition-colors hover:bg-surface-hover`,children:a.reviewContent}),(0,Z.jsx)(`div`,{className:`max-h-64 space-y-3 overflow-y-auto border-t border-edge p-3`,children:u.messages.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-inset px-3 py-2`,children:[(0,Z.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:e.role===`user`?a.you:a.assistant}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm leading-6 text-fg`,children:e.markdown})]},e.id))})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 rounded-lg border border-accent/20 bg-accent-soft px-3 py-2.5 text-xs leading-5 text-fg-muted`,children:[(0,Z.jsx)(Bt,{className:`mt-0.5 size-4 shrink-0 text-accent-fg`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:a.scope})]}),(0,Z.jsxs)(`label`,{className:`block space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.delivery}),(0,Z.jsxs)(de,{value:L,disabled:m,onChange:e=>R(e.target.value),children:[(0,Z.jsx)(K,{value:`hosted`,children:a.hosted}),(0,Z.jsx)(K,{value:`local`,children:a.local})]})]}),L===`hosted`&&!z?(0,Z.jsx)(ns,{providerId:`xopc-share`,displayName:a.hosted,connected:!1,onConnected:()=>{B(!0),fo().then(e=>V(e.publishing.allowed)).catch(()=>V(!1))}}):null,L===`hosted`&&z&&!ee?(0,Z.jsx)(`p`,{className:`rounded-lg border border-warning/30 bg-warning-soft px-3 py-2 text-xs text-warning`,children:a.hostedDisabled}):null,u.toolActivities.length?(0,Z.jsxs)(`label`,{className:`flex items-start gap-2 rounded-lg border border-edge bg-surface-inset px-3 py-2.5 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:N,disabled:m,onChange:e=>P(e.target.checked),className:`mt-0.5 size-4 rounded border-edge`}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:a.includeTools.replace(`{{count}}`,String(u.toolActivities.length))}),(0,Z.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-muted`,children:a.toolDisclosure})]})]}):null,u.attachmentCandidates.length?(0,Z.jsxs)(`fieldset`,{className:`rounded-lg border border-edge bg-surface-inset px-3 py-2.5`,children:[(0,Z.jsx)(`legend`,{className:`px-1 text-xs font-medium text-fg`,children:a.attachments}),(0,Z.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:a.attachmentDisclosure}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:u.attachmentCandidates.map(e=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(e.id),disabled:m,onChange:t=>I(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id)),className:`size-4 rounded border-edge`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.fileName}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-fg-subtle`,children:lO(e.size)})]},e.id))})]}):null,(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`label`,{className:`space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.ttl}),(0,Z.jsxs)(de,{value:y,disabled:m,onChange:e=>b(Number(e.target.value)),children:[(0,Z.jsx)(K,{value:36e5,children:a.oneHour}),(0,Z.jsx)(K,{value:864e5,children:a.oneDay}),(0,Z.jsx)(K,{value:6048e5,children:a.sevenDays}),(0,Z.jsx)(K,{value:2592e6,children:a.thirtyDays})]})]}),(0,Z.jsxs)(`label`,{className:`space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.maxViews}),(0,Z.jsxs)(de,{value:x??`unlimited`,disabled:m,onChange:e=>S(e.target.value===`unlimited`?null:Number(e.target.value)),children:[(0,Z.jsx)(K,{value:`unlimited`,children:a.unlimited}),(0,Z.jsx)(K,{value:1,children:`1`}),(0,Z.jsx)(K,{value:10,children:`10`}),(0,Z.jsx)(K,{value:50,children:`50`})]})]})]}),(0,Z.jsxs)(`label`,{className:`block space-y-1.5 text-xs font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:a.description}),(0,Z.jsx)(`input`,{value:j,disabled:m,onChange:e=>M(e.target.value),className:`h-10 w-full rounded-lg border border-edge bg-surface-inset px-3 text-sm font-normal text-fg outline-none focus-visible:border-accent/50 focus-visible:ring-2 focus-visible:ring-accent/20`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:a.publicWarning})]}):null,g?(0,Z.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:g}):null]}),(0,Z.jsx)(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-edge bg-surface-overlay px-4 py-3`,children:f?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,disabled:m,onClick:()=>p(null),children:a.newShare}),(0,Z.jsxs)(vi,{type:`button`,variant:`ghost`,disabled:m,onClick:()=>void te(),children:[(0,Z.jsx)(Wt,{className:`size-4`}),a.revoke]}),(0,Z.jsxs)(vi,{type:`button`,disabled:m||f.delivery===`hosted`&&!ee,onClick:()=>void W(),children:[m?(0,Z.jsx)(Ze,{className:`size-4 animate-spin`}):(0,Z.jsx)(Pt,{className:`size-4`}),a.refresh]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,children:a.cancel})}),(0,Z.jsxs)(vi,{type:`button`,disabled:!u||m||u.messageCount===0||L===`hosted`&&(!z||!ee),onClick:()=>void U(),children:[m?(0,Z.jsx)(Ze,{className:`size-4 animate-spin`}):null,a.create]})]})})]})]})]})}function lO(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}var uO={share:`分享会话`,title:`分享会话`,hint:`创建当前会话的只读快照`,created:`分享已创建`,createdHint:`复制链接后即可发送给其他人`,close:`关闭`,loading:`正在准备预览…`,snapshotMessages:`当前快照包含 {{count}} 条公开消息`,scope:`默认仅包含用户与助手的可见文本;系统提示、推理、工具参数、命令文本、输出和路径始终不会公开。`,ttl:`有效期`,maxViews:`最大访问次数`,includeTools:`包含 {{count}} 条工具活动`,toolDisclosure:`只公开工具名称和成功/失败状态,不公开参数与结果。`,attachments:`附件`,attachmentDisclosure:`附件默认不公开,请逐个选择。`,oneHour:`1 小时`,oneDay:`24 小时`,sevenDays:`7 天`,thirtyDays:`30 天`,unlimited:`不限`,description:`说明(可选)`,publicWarning:`任何获得链接的人都可以查看这份快照。后续会话消息不会自动加入。`,cancel:`取消`,create:`创建分享`,revoke:`撤销分享`,refresh:`更新到当前会话`,open:`打开分享页面`,revision:`快照版本 {{revision}}`,sharedAttachments:`{{count}} 个附件`,newShare:`新建分享`,delivery:`分享方式`,hosted:`XOPC 托管分享`,local:`本机 Gateway 分享`,hostedDisabled:`管理员已暂停你的公网分享能力。已有托管链接当前不可访问,但仍可撤销。`,reviewContent:`检查将要公开的内容`,you:`你`,assistant:`助手`},dO={share:`Share conversation`,title:`Share conversation`,hint:`Create a read-only snapshot of this conversation`,created:`Share created`,createdHint:`Copy the link and send it to anyone`,close:`Close`,loading:`Preparing preview…`,snapshotMessages:`This snapshot contains {{count}} public messages`,scope:`Only visible user and assistant text is included by default. System prompts, reasoning, tool arguments, command text, output, and paths always stay private.`,ttl:`Expires after`,maxViews:`Maximum views`,includeTools:`Include {{count}} tool activities`,toolDisclosure:`Only tool names and success/failure states are shared; arguments and results stay private.`,attachments:`Attachments`,attachmentDisclosure:`Attachments stay private unless selected individually.`,oneHour:`1 hour`,oneDay:`24 hours`,sevenDays:`7 days`,thirtyDays:`30 days`,unlimited:`Unlimited`,description:`Description (optional)`,publicWarning:`Anyone with the link can view this snapshot. Later conversation messages are not added automatically.`,cancel:`Cancel`,create:`Create share`,revoke:`Revoke share`,refresh:`Update to current conversation`,open:`Open shared page`,revision:`Snapshot revision {{revision}}`,sharedAttachments:`{{count}} attachments`,newShare:`New share`,delivery:`Delivery`,hosted:`XOPC Hosted Share`,local:`Local Gateway Share`,hostedDisabled:`An administrator has paused public sharing for your account. Existing hosted links are unavailable, but can still be revoked.`,reviewContent:`Review the content to publish`,you:`You`,assistant:`Assistant`},fO=`(max-width: 767px)`,pO=(0,Q.memo)(function(e){let t=(0,X.c)(141),{inline:n,chatHeadline:r,chatAgents:i,showChatAgentSelector:a,chatAgentId:o,onChatAgentChange:s,chatAgentDisabled:c,conversationId:l,hasMessages:d,workspacePath:f,userContextMode:p,canChangeWorkspace:m,workspaceDisabled:h,onWorkspaceChange:g,prepareTerminalSession:_,terminalDisabled:y,showContextControls:b,onFindOpen:x,projectId:C,context:w}=e,T=n!==void 0&&n,E=d!==void 0&&d,D=p===void 0?`enabled`:p,O=m!==void 0&&m,k=h!==void 0&&h,A=y!==void 0&&y,j=b===void 0||b,M=v(mO),{conversationId:N}=u(),P=N&&N!==`new`?decodeURIComponent(N):null,F;t[0]!==l||t[1]!==P?(F=l?.trim()||P,t[0]=l,t[1]=P,t[2]=F):F=t[2];let I=F,{data:L,error:R,mutate:B}=Df(I??null,!1),ee=!R&&(!L||!!L.environment?.available),V;t[3]===I?V=t[4]:(V=e=>e.panes[I??`new`]?.open===!0,t[3]=I,t[4]=V);let H=yi(V),U;t[5]===M?U=t[6]:(U=S(M),t[5]=M,t[6]=U);let W=U,te=zf(hO),ne=zw(gO),re=Qo(_O),ie=Qo(vO),[ae,oe]=(0,Q.useState)(!1),se=(0,Q.useRef)(!1),[ce,le]=(0,Q.useState)(!1),ue=Bf(yO),de=Ea(bO),G=Ea(xO),K=window.electronAPI?.platform,fe=!!(j&&window.electronAPI?.terminal&&(I||_)),q;t[7]!==I||t[8]!==ie||t[9]!==_||t[10]!==fe||t[11]!==A||t[12]!==ce||t[13]!==re?(q=()=>{if(!(!fe||A||ce)){if(I){re(I);return}_&&(le(!0),_().then(e=>{e&&ie(e)}).finally(()=>le(!1)))}},t[7]=I,t[8]=ie,t[9]=_,t[10]=fe,t[11]=A,t[12]=ce,t[13]=re,t[14]=q):q=t[14];let pe=q,me;t[15]!==I||t[16]!==E||t[17]!==ne?(me=()=>{if(!I||!E)return;let e=yi.getState().panes[I],t=zw.getState().pendingCreate?.parentConversationId===I||!!zw.getState().creatingRequests[I],n=e?.open===!0&&(e.activeId?.startsWith(`side:`)===!0||t);ne(I,!n)},t[15]=I,t[16]=E,t[17]=ne,t[18]=me):me=t[18];let he=me,ge=rs(fO),_e;t[19]!==ue||t[20]!==te?(_e=jf({runtime:Af(),sidebarCollapsed:te,mobileNavOpen:ue}),t[19]=ue,t[20]=te,t[21]=_e):_e=t[21];let ve=ge?!ue:_e.collapsedNewChatVisible,ye,be;t[22]!==G||t[23]!==T?(ye=()=>{if(!T)return()=>G()},be=[G,T],t[22]=G,t[23]=T,t[24]=ye,t[25]=be):(ye=t[24],be=t[25]),(0,Q.useLayoutEffect)(ye,be);let xe,Se;t[26]!==pe||t[27]!==fe?(xe=()=>{if(!fe)return;let e=e=>{sO(e,K)&&(e.preventDefault(),pe())};return window.addEventListener(`keydown`,e),window.addEventListener(`workspace-open-terminal`,pe),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`workspace-open-terminal`,pe)}},Se=[pe,fe,K],t[26]=pe,t[27]=fe,t[28]=xe,t[29]=Se):(xe=t[28],Se=t[29]),(0,Q.useEffect)(xe,Se);let we,Te;t[30]!==I||t[31]!==he||t[32]!==E?(we=()=>{if(!I||!E)return;let e=e=>{ds(e,K)&&(e.preventDefault(),he())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},Te=[I,he,E,K],t[30]=I,t[31]=he,t[32]=E,t[33]=we,t[34]=Te):(we=t[33],Te=t[34]),(0,Q.useEffect)(we,Te);let Ee;t[35]!==o||t[36]!==W.sidebar.newTask||t[37]!==C||t[38]!==ve||t[39]!==D?(Ee=ve?(0,Z.jsx)(J,{to:Ra(C),state:{forceNewChat:!0,agentId:o,temporary:D===`temporary`},className:Y(`inline-flex size-8 shrink-0 items-center justify-center rounded-lg bg-surface-panel text-sm font-medium leading-none text-fg transition-colors hover:bg-surface-hover`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,xa),title:W.sidebar.newTask,children:(0,Z.jsx)(Nt,{className:`size-4 shrink-0 text-accent-fg`,strokeWidth:2,"aria-hidden":!0})}):null,t[35]=o,t[36]=W.sidebar.newTask,t[37]=C,t[38]=ve,t[39]=D,t[40]=Ee):Ee=t[40];let De=ve?`text-left md:text-center`:`text-left`,Oe;t[41]===De?Oe=t[42]:(Oe=Y(`min-w-0 flex-1 truncate text-[0.9375rem] font-semibold leading-5 tracking-tight text-fg`,De),t[41]=De,t[42]=Oe);let ke;t[43]!==r||t[44]!==Oe?(ke=(0,Z.jsx)(`div`,{className:`flex w-full min-w-0 max-w-(--max-width-chat-frame) items-center gap-3 px-3 sm:px-5 xl:px-6`,children:(0,Z.jsx)(`h1`,{className:Oe,title:r,children:r})}),t[43]=r,t[44]=Oe,t[45]=ke):ke=t[45];let Ae;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(Ae=Y(`flex min-w-0 max-w-[min(32rem,calc(100vw-8rem))] shrink-0 items-center justify-end gap-2`,xa),t[46]=Ae):Ae=t[46];let je;t[47]!==c||t[48]!==o||t[49]!==i||t[50]!==W.chat.agentNoMatches||t[51]!==W.chat.agentPlaceholder||t[52]!==W.chat.agentSearchPlaceholder||t[53]!==s||t[54]!==a?(je=a?(0,Z.jsx)(PD,{items:i,value:o,disabled:c,placeholder:W.chat.agentPlaceholder,searchPlaceholder:W.chat.agentSearchPlaceholder,noMatches:W.chat.agentNoMatches,compact:!0,contentSide:`bottom`,contentAlign:`end`,onChange:s}):null,t[47]=c,t[48]=o,t[49]=i,t[50]=W.chat.agentNoMatches,t[51]=W.chat.agentPlaceholder,t[52]=W.chat.agentSearchPlaceholder,t[53]=s,t[54]=a,t[55]=je):je=t[55];let Me=M===`zh`?`聊天菜单`:`Chat menu`,Ne=M===`zh`?`聊天菜单`:`Chat menu`,Pe;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=(0,Z.jsx)(Ce,{className:`size-4`,"aria-hidden":!0}),t[56]=Pe):Pe=t[56];let Fe;t[57]!==Me||t[58]!==Ne?(Fe=(0,Z.jsx)(_o,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"data-chat-menu-trigger":!0,"aria-label":Me,title:Ne,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-colors hover:bg-surface-hover data-[state=open]:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:Pe})}),t[57]=Me,t[58]=Ne,t[59]=Fe):Fe=t[59];let Ie;t[60]===x?Ie=t[61]:(Ie=e=>{se.current&&(e.preventDefault(),se.current=!1,document.querySelector(`[data-chat-menu-trigger]`)?.focus(),x?.())},t[60]=x,t[61]=Ie);let Le=!E||!x,Re;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(Re=()=>{se.current=!0},t[62]=Re):Re=t[62];let ze;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(ze=(0,Z.jsx)(Lt,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),t[63]=ze):ze=t[63];let Be;t[64]===W.chat.find.input?Be=t[65]:(Be=(0,Z.jsx)(`span`,{className:`flex-1`,children:W.chat.find.input}),t[64]=W.chat.find.input,t[65]=Be);let Ve;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(Ve=(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:K===`darwin`?`⌘F`:`Ctrl+F`}),t[66]=Ve):Ve=t[66];let He;t[67]!==Le||t[68]!==Be?(He=(0,Z.jsxs)(yo,{disabled:Le,onSelect:Re,className:`flex cursor-default items-center gap-3 rounded-lg px-3 py-2 text-fg outline-none data-[highlighted]:bg-surface-hover data-[disabled]:opacity-40`,children:[ze,Be,Ve]}),t[67]=Le,t[68]=Be,t[69]=He):He=t[69];let Ue=!I||!E,We;t[70]===Symbol.for(`react.memo_cache_sentinel`)?(We=()=>oe(!0),t[70]=We):We=t[70];let Ge;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=(0,Z.jsx)(z,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),t[71]=Ge):Ge=t[71];let Ke=M===`zh`?`分享对话`:`Share conversation`,qe;t[72]===Ke?qe=t[73]:(qe=(0,Z.jsx)(`span`,{children:Ke}),t[72]=Ke,t[73]=qe);let Je;t[74]!==Ue||t[75]!==qe?(Je=(0,Z.jsxs)(yo,{disabled:Ue,onSelect:We,className:`flex cursor-default items-center gap-3 rounded-lg px-3 py-2 text-fg outline-none data-[highlighted]:bg-surface-hover data-[disabled]:opacity-40`,children:[Ge,qe]}),t[74]=Ue,t[75]=qe,t[76]=Je):Je=t[76];let Ye;t[77]!==Ie||t[78]!==He||t[79]!==Je?(Ye=(0,Z.jsx)(vo,{children:(0,Z.jsxs)(bo,{onCloseAutoFocus:Ie,align:`end`,sideOffset:8,className:`workspace-menu z-[125] min-w-60 rounded-xl border border-edge bg-surface-overlay p-1.5 text-sm shadow-popover outline-none`,children:[He,Je]})}),t[77]=Ie,t[78]=He,t[79]=Je,t[80]=Ye):Ye=t[80];let Xe;t[81]!==Fe||t[82]!==Ye?(Xe=(0,Z.jsxs)(go,{modal:!1,children:[Fe,Ye]}),t[81]=Fe,t[82]=Ye,t[83]=Xe):Xe=t[83];let Ze;t[84]!==I||t[85]!==E||t[86]!==ae?(Ze=I&&E?(0,Z.jsx)(cO,{conversationId:I,hideTrigger:!0,dialogOpen:ae,onDialogOpenChange:oe},`share:${I}`):null,t[84]=I,t[85]=E,t[86]=ae,t[87]=Ze):Ze=t[87];let Qe;t[88]!==I||t[89]!==O||t[90]!==c||t[91]!==o||t[92]!==w||t[93]!==g||t[94]!==B||t[95]!==j||t[96]!==D||t[97]!==ee||t[98]!==k||t[99]!==f?(Qe=j?(0,Z.jsx)(VD,{...w,agentId:o,executionDeviceAction:I?(0,Z.jsx)(QD,{conversationId:I,disabled:c}):null,environmentAction:O&&g?(0,Z.jsx)(nO,{directoryOnly:!0,conversationId:I,workspacePath:I?f:w?.project?.workspaceRoot,available:ee,canChangeWorkspace:!0,disabled:k,onWorkspaceChange:async e=>{await g(e),await B()}}):null,temporary:D===`temporary`,conversationId:I??null},`context:${I??w?.project?.id??`new`}`):null,t[88]=I,t[89]=O,t[90]=c,t[91]=o,t[92]=w,t[93]=g,t[94]=B,t[95]=j,t[96]=D,t[97]=ee,t[98]=k,t[99]=f,t[100]=Qe):Qe=t[100];let $e;t[101]!==j||t[102]!==H?($e=j&&!H?(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`mx-0.5 h-6 w-px shrink-0 bg-edge-subtle`}):null,t[101]=j,t[102]=H,t[103]=$e):$e=t[103];let et;t[104]===I?et=t[105]:(et=I?(0,Z.jsx)(JD,{conversationId:I},I):null,t[104]=I,t[105]=et);let tt;t[106]===I?tt=t[107]:(tt=I?(0,Z.jsx)($D,{conversationId:I}):null,t[106]=I,t[107]=tt);let nt;t[108]!==I||t[109]!==w?.project?.workspaceRoot||t[110]!==g||t[111]!==C||t[112]!==B||t[113]!==j||t[114]!==ee||t[115]!==k||t[116]!==H||t[117]!==f?(nt=j&&!H?(0,Z.jsx)(nO,{conversationId:I,workspacePath:I?f:w?.project?.workspaceRoot,available:ee,canChangeWorkspace:!1,disabled:k,onWorkspaceChange:async e=>{await g?.(e),await B()}},`workspace:${I??C}`):null,t[108]=I,t[109]=w?.project?.workspaceRoot,t[110]=g,t[111]=C,t[112]=B,t[113]=j,t[114]=ee,t[115]=k,t[116]=H,t[117]=f,t[118]=nt):nt=t[118];let rt;t[119]!==je||t[120]!==Xe||t[121]!==Ze||t[122]!==Qe||t[123]!==$e||t[124]!==et||t[125]!==tt||t[126]!==nt?(rt=(0,Z.jsxs)(`div`,{className:Ae,children:[je,Xe,Ze,Qe,$e,et,tt,nt]}),t[119]=je,t[120]=Xe,t[121]=Ze,t[122]=Qe,t[123]=$e,t[124]=et,t[125]=tt,t[126]=nt,t[127]=rt):rt=t[127];let it;t[128]!==Ee||t[129]!==ke||t[130]!==rt?(it={className:`bg-surface-panel`,startExtra:Ee,main:ke,end:rt},t[128]=Ee,t[129]=ke,t[130]=rt,t[131]=it):it=t[131];let at=it,ot,st;t[132]!==at||t[133]!==T||t[134]!==de?(ot=()=>{T||de(at)},st=[at,T,de],t[132]=at,t[133]=T,t[134]=de,t[135]=ot,t[136]=st):(ot=t[135],st=t[136]),(0,Q.useLayoutEffect)(ot,st);let ct;return t[137]!==at||t[138]!==T||t[139]!==M?(ct=T?(0,Z.jsxs)(`header`,{"aria-label":M===`zh`?`聊天工具栏`:`Chat toolbar`,className:`flex min-h-14 shrink-0 items-center justify-between gap-2 border-b border-edge-subtle px-3 py-2`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:at.main}),at.end]}):null,t[137]=at,t[138]=T,t[139]=M,t[140]=ct):ct=t[140],ct});function mO(e){return e.language}function hO(e){return e.collapsed}function gO(e){return e.setOpen}function _O(e){return e.toggle}function vO(e){return e.open}function yO(e){return e.mobileNavOpen}function bO(e){return e.setPageHeader}function xO(e){return e.clearPageHeader}var SO=(0,Q.memo)(function(){let e=(0,X.c)(19),t=v(CO),n;e[0]===t?n=e[1]:(n=S(t),e[0]=t,e[1]=n);let r=n.chat.runRecovery,i=mi(wO),a=mi(TO),[o,s]=(0,Q.useState)(!1),c=i===`connecting`||i===`reconnecting`,l,u;if(e[2]===c?(l=e[3],u=e[4]):(l=()=>{if(!c)return;let e=window.setTimeout(()=>s(!0),1500);return()=>{window.clearTimeout(e),s(!1)}},u=[c],e[2]=c,e[3]=l,e[4]=u),(0,Q.useEffect)(l,u),i!==`error`&&!(c&&o))return null;let d=i===`error`,f=d?Kt:Pt,p=`size-3.5 shrink-0 ${c?`motion-safe:animate-spin`:``}`,m;e[5]!==f||e[6]!==p?(m=(0,Z.jsx)(f,{className:p,"aria-hidden":!0}),e[5]=f,e[6]=p,e[7]=m):m=e[7];let h=d?r.connectionFailed:i===`connecting`?r.connecting:r.reconnecting,g;e[8]===h?g=e[9]:(g=(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:h}),e[8]=h,e[9]=g);let _;e[10]!==a||e[11]!==d||e[12]!==r.details||e[13]!==r.reconnect?(_=d?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,className:`min-h-9 rounded-md border border-edge px-3 text-xs text-fg hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:EO,children:r.reconnect}),a?(0,Z.jsxs)(`details`,{className:`w-full min-w-0`,children:[(0,Z.jsx)(`summary`,{className:`w-fit cursor-pointer rounded-md py-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:r.details}),(0,Z.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words rounded-md bg-surface-inset p-2`,children:Yn(a)})]}):null]}):null,e[10]=a,e[11]=d,e[12]=r.details,e[13]=r.reconnect,e[14]=_):_=e[14];let y;return e[15]!==m||e[16]!==g||e[17]!==_?(y=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex flex-wrap items-center gap-2 border-b border-edge-subtle bg-surface-panel px-4 py-2 text-xs text-fg-muted`,children:[m,g,_]}),e[15]=m,e[16]=g,e[17]=_,e[18]=y):y=e[18],y});function CO(e){return e.language}function wO(e){return e.connectionState}function TO(e){return e.error}function EO(){return pi()}function DO(e,t){return Object.entries(t).reduce((e,[t,n])=>e.replaceAll(`{{${t}}}`,String(n)),e)}function OO(e){let t=(0,X.c)(4),{status:n}=e;if(n===`completed`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(`span`,{className:`mt-0.5 inline-flex size-4 shrink-0 items-center justify-center rounded-full bg-fg-muted text-surface-panel`,children:(0,Z.jsx)(re,{className:`size-3`,strokeWidth:2.5,"aria-hidden":!0})}),t[0]=e):e=t[0],e}if(n===`in_progress`){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(pe,{className:`mt-0.5 size-4 shrink-0 text-accent`,strokeWidth:2,"aria-hidden":!0}),t[1]=e):e=t[1],e}if(n===`cancelled`){let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(ps,{className:`mt-0.5 size-4 shrink-0 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),t[2]=e):e=t[2],e}let r;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Z.jsx)(ge,{className:`mt-0.5 size-4 shrink-0 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[3]=r):r=t[3],r}function kO(e,t){return e?`${DO(e.files.length===1?t.filesChangedOne:t.filesChangedOther,{count:e.files.length})} · +${e.added} -${e.removed}`:null}function AO(e){let t=(0,X.c)(61),{plan:n,changeSummary:r,isStreaming:i,labels:a}=e,o=n.currentIndex==null?void 0:n.items[n.currentIndex-1],s;t[0]===n.items?s=t[1]:(s=n.items.every(NO),t[0]=n.items,t[1]=s);let c=s,l=n.items.every(MO),u;t[2]!==a.completedProgress||t[3]!==n.completedCount||t[4]!==n.totalCount?(u=DO(a.completedProgress,{completed:n.completedCount,total:n.totalCount}),t[2]=a.completedProgress,t[3]=n.completedCount,t[4]=n.totalCount,t[5]=u):u=t[5];let d=u,f=a.ended;if(c)f=a.finished;else if(o){let e=n.currentIndex??1,r;t[6]!==a.stepProgress||t[7]!==n.totalCount||t[8]!==e?(r=DO(a.stepProgress,{current:e,total:n.totalCount}),t[6]=a.stepProgress,t[7]=n.totalCount,t[8]=e,t[9]=r):r=t[9],f=r}else!l&&i&&(f=a.planned);let p;t[10]!==r||t[11]!==a?(p=kO(r,a),t[10]=r,t[11]=a,t[12]=p):p=t[12];let m=p,h=o?.title,g;t[13]!==m||t[14]!==f||t[15]!==h?(g=[f,h,m].filter(Boolean),t[13]=m,t[14]=f,t[15]=h,t[16]=g):g=t[16];let _=g.join(` · `),v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(v=Y(`inline-flex min-h-9 min-w-0 max-w-full items-center gap-2 rounded-pill border border-edge-subtle bg-surface-overlay px-3 py-1.5 text-sm text-fg shadow-surface`,ca.transition,`hover:border-edge hover:text-accent-fg`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`),t[17]=v):v=t[17];let y=`${a.heading}: ${_}`,b;t[18]!==o||t[19]!==c?(b=c?(0,Z.jsx)(re,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:2,"aria-hidden":!0}):o?(0,Z.jsx)(pe,{className:`size-4 shrink-0 text-accent`,strokeWidth:2,"aria-hidden":!0}):(0,Z.jsx)(Ye,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[18]=o,t[19]=c,t[20]=b):b=t[20];let x;t[21]===f?x=t[22]:(x=(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:f}),t[21]=f,t[22]=x);let S;t[23]===o?S=t[24]:(S=o?(0,Z.jsxs)(`span`,{className:`min-w-0 truncate text-fg-muted`,children:[`· `,o.title]}):null,t[23]=o,t[24]=S);let C;t[25]===m?C=t[26]:(C=m?(0,Z.jsxs)(`span`,{className:`hidden shrink-0 tabular-nums text-fg-subtle sm:inline`,children:[`· `,m]}):null,t[25]=m,t[26]=C);let w;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Z.jsx)(ie,{className:`size-3.5 shrink-0 text-fg-subtle`,"aria-hidden":!0}),t[27]=w):w=t[27];let T;t[28]!==S||t[29]!==C||t[30]!==y||t[31]!==b||t[32]!==x?(T=(0,Z.jsx)(wi,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:v,"aria-label":y,children:[b,x,S,C,w]})}),t[28]=S,t[29]=C,t[30]=y,t[31]=b,t[32]=x,t[33]=T):T=t[33];let E;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,Z.jsx)(Ye,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[34]=E):E=t[34];let D;t[35]===a.heading?D=t[36]:(D=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[E,(0,Z.jsx)(`span`,{children:a.heading})]}),t[35]=a.heading,t[36]=D);let O;t[37]===n.explanation?O=t[38]:(O=n.explanation?(0,Z.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:n.explanation}):null,t[37]=n.explanation,t[38]=O);let k;t[39]!==D||t[40]!==O?(k=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[D,O]}),t[39]=D,t[40]=O,t[41]=k):k=t[41];let A;t[42]===d?A=t[43]:(A=(0,Z.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-fg-subtle`,children:d}),t[42]=d,t[43]=A);let j;t[44]!==k||t[45]!==A?(j=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge-subtle px-4 py-3`,children:[k,A]}),t[44]=k,t[45]=A,t[46]=j):j=t[46];let M=a.heading,N;t[47]===n.items?N=t[48]:(N=n.items.map(jO),t[47]=n.items,t[48]=N);let P;t[49]!==a.heading||t[50]!==N?(P=(0,Z.jsx)(`ol`,{className:`max-h-[min(22rem,55vh)] overflow-y-auto px-4 py-3`,"aria-label":M,children:N}),t[49]=a.heading,t[50]=N,t[51]=P):P=t[51];let F;t[52]===m?F=t[53]:(F=m?(0,Z.jsx)(`div`,{className:`border-t border-edge-subtle px-4 py-2 text-right text-xs tabular-nums text-fg-subtle`,children:m}):null,t[52]=m,t[53]=F);let I;t[54]!==j||t[55]!==P||t[56]!==F?(I=(0,Z.jsx)(bi,{children:(0,Z.jsxs)(xi,{side:`top`,align:`center`,sideOffset:8,collisionPadding:16,className:`z-[120] w-[min(28rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[j,P,F]})}),t[54]=j,t[55]=P,t[56]=F,t[57]=I):I=t[57];let L;return t[58]!==T||t[59]!==I?(L=(0,Z.jsx)(`div`,{className:`mx-auto flex w-full max-w-80 justify-center pb-2 pt-1`,children:(0,Z.jsxs)(Si,{children:[T,I]})}),t[58]=T,t[59]=I,t[60]=L):L=t[60],L}function jO(e){return(0,Z.jsxs)(`li`,{className:Y(`flex gap-3 py-2 text-sm leading-relaxed text-fg-muted`,e.status===`in_progress`&&`font-medium text-fg`,e.status===`cancelled`&&`text-fg-disabled`),children:[(0,Z.jsx)(OO,{status:e.status}),(0,Z.jsx)(`span`,{className:`min-w-0 [overflow-wrap:anywhere]`,children:e.title})]},e.id)}function MO(e){return e.status===`completed`||e.status===`cancelled`}function NO(e){return e.status===`completed`}function PO(e){let t=BO(e.source,e.explanation,e.items.map(e=>({...e})));return t&&t.items.some(e=>e.status===`pending`||e.status===`in_progress`)?t:null}var FO=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function IO(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function LO(e){return e.trim().toLowerCase().replace(/-/g,`_`).split(`__`).at(-1)??``}function RO(e){let t=IO(e.details);return t&&Object.keys(t).length>0?t:ma(e.result).details}function zO(e){let t=typeof e==`string`?e.trim():``;return FO.has(t)?t:null}function BO(e,t,n){if(n.length===0)return null;let r=n.findIndex(e=>e.status===`in_progress`);return{source:e,explanation:t,items:n,currentIndex:r>=0?r+1:void 0,completedCount:n.filter(e=>e.status===`completed`).length,totalCount:n.length}}function VO(e){if(!Array.isArray(e.plan))return null;let t=e.plan.flatMap((e,t)=>{let n=IO(e),r=typeof n?.id==`string`&&n.id.trim()?n.id.trim():`update-plan-${t}`,i=typeof n?.step==`string`?n.step.trim():``,a=zO(n?.status);return i&&a?[{id:r,title:i,status:a}]:[]});return BO(`update_plan`,typeof e.explanation==`string`&&e.explanation.trim()?e.explanation.trim():void 0,t)}function HO(e){return Array.isArray(e.items)?BO(`todo`,void 0,e.items.flatMap((e,t)=>{let n=IO(e),r=typeof n?.id==`string`&&n.id.trim()?n.id.trim():`todo-${t}`,i=typeof n?.content==`string`?n.content.trim():``,a=zO(n?.status);return i&&a?[{id:r,title:i,status:a}]:[]})):null}function UO(e){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.type!==`tool_use`||n.status===`error`)continue;let r=LO(n.name),i=RO(n);if(i){if(r===`update_plan`)return{found:!0,plan:VO(i)};if(r===`todo`)return{found:!0,plan:HO(i)}}}return{found:!1,plan:null}}function WO(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:0}function GO(e){let t=new Set,n=0,r=0;for(let i of e){if(i.type!==`tool_use`||i.status===`error`||LO(i.name)!==`apply_patch`)continue;let e=RO(i);if(e){if(Array.isArray(e.files))for(let n of e.files)typeof n==`string`&&n.trim()&&t.add(n.trim());if(t.size===0&&Array.isArray(e.changes))for(let n of e.changes){let e=IO(n),r=typeof e?.moveTo==`string`?e.moveTo:typeof e?.path==`string`?e.path:``;r.trim()&&t.add(r.trim())}n+=WO(e.added),r+=WO(e.removed)}}return t.size>0||n>0||r>0?{files:[...t],added:n,removed:r}:null}function KO(e){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`assistant`)continue;let r=UO(n.content??[]);if(!r.found)continue;if(!r.plan||!r.plan.items.some(e=>e.status===`pending`||e.status===`in_progress`))return null;let i=e.slice(t).flatMap(e=>e.role===`assistant`?e.content??[]:[]);return{plan:r.plan,changeSummary:GO(i)}}return null}function qO(e,t){if(!t)return null;let n=-1;for(let t=e.length-1;t>=0;--t)if(e[t]?.role===`user`){n=t;break}return KO(e.slice(n+1))}function JO(e,t){return e.bottom>t.top&&e.top<t.bottom&&e.right>t.left&&e.left<t.right}function YO(e,t,n){let r=n.getBoundingClientRect(),i=t.getBoundingClientRect();if(!JO(e,{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight})||!JO(i,r)||typeof t.animate!=`function`)return()=>{};let a=t.closest(`article`);a&&(a.style.animation=`none`);let o=t.getBoundingClientRect(),s=e.left-o.left,c=e.top-o.top,l;try{l=t.animate([{transform:`translate3d(${s}px, ${c}px, 0)`},{transform:`translate3d(0, 0, 0)`}],{duration:360,easing:`cubic-bezier(0.25, 0.1, 0.25, 1)`})}catch{return()=>{}}let u=!1,d,f=()=>{u||(u=!0,d!==void 0&&window.clearTimeout(d),n.removeEventListener(`scroll`,p),n.removeEventListener(`wheel`,f),n.removeEventListener(`touchstart`,f),window.removeEventListener(`resize`,f),l.cancel())},p=()=>{let e=t.closest(`[data-chat-message-row]`);(!t.isConnected||e&&!JO(e.getBoundingClientRect(),n.getBoundingClientRect()))&&f()};return n.addEventListener(`scroll`,p,{passive:!0}),n.addEventListener(`wheel`,f,{passive:!0}),n.addEventListener(`touchstart`,f,{passive:!0}),window.addEventListener(`resize`,f),d=window.setTimeout(f,510),l.finished.then(f,f),f}function XO(e){let t=(0,X.c)(13),{enabled:n,conversationId:r,messages:i,viewportRef:a}=e,o=(0,Q.useRef)(null),s=(0,Q.useRef)(null),c=(0,Q.useRef)(r),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{o.current&&window.clearTimeout(o.current.timeout),o.current=null,s.current?.(),s.current=null},t[0]=l):l=t[0];let u=l,d;t[1]===n?d=t[2]:(d=(e,t,r)=>{if(u(),!n||r.attachments.length>0||r.contextRefs.length>0||!r.text.trim()||document.visibilityState===`hidden`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let i={id:e.clientSubmissionId,source:{left:t.left,top:t.top,right:t.right,bottom:t.bottom},timeout:window.setTimeout(()=>{o.current===i&&(o.current=null)},500)};o.current=i},t[1]=n,t[2]=d);let f=d,p,m;t[3]===r?(p=t[4],m=t[5]):(p=()=>{let e=c.current;c.current=r,e!==null&&e!==r&&u()},m=[u,r],t[3]=r,t[4]=p,t[5]=m),(0,Q.useLayoutEffect)(p,m);let h,g;t[6]!==i||t[7]!==a?(h=()=>{let e=o.current,t=a.current;if(!e||!t||!i.some(t=>t.clientSubmissionId===e.id))return;window.clearTimeout(e.timeout),o.current=null;let n=t.querySelector(`[data-client-submission-id="${e.id}"]`)?.querySelector(`.chat-user-message`);n&&(s.current=YO(e.source,n,t))},g=[i,a],t[6]=i,t[7]=a,t[8]=h,t[9]=g):(h=t[8],g=t[9]),(0,Q.useLayoutEffect)(h,g);let _;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>u,t[10]=_):_=t[10];let v;return t[11]===n?v=t[12]:(v=[u,n],t[11]=n,t[12]=v),(0,Q.useEffect)(_,v),f}function ZO(e){let t=(0,X.c)(61),{open:n,query:r,activeIndex:i,resultCount:a,searching:o,truncated:s,limitedToLoaded:c,inputRef:l,labels:u,onQueryChange:d,onPrevious:f,onNext:p,onClose:m}=e,h=o!==void 0&&o,g=s!==void 0&&s,_=c!==void 0&&c;if(!n)return null;let v;t[0]===r?v=t[1]:(v=r.trim(),t[0]=r,t[1]=v);let y=!!v,b;t[2]!==i||t[3]!==y||t[4]!==u.noResults||t[5]!==u.resultCount||t[6]!==u.searching||t[7]!==a||t[8]!==h||t[9]!==g?(b=h?u.searching:y&&a===0?u.noResults:y?u.resultCount.replace(`{{current}}`,String(i+1)).replace(`{{total}}`,`${a}${g?`+`:``}`):``,t[2]=i,t[3]=y,t[4]=u.noResults,t[5]=u.resultCount,t[6]=u.searching,t[7]=a,t[8]=h,t[9]=g,t[10]=b):b=t[10];let x=b,S;t[11]!==x||t[12]!==y||t[13]!==u.loadedOnly||t[14]!==_?(S=_&&y?[x,u.loadedOnly].filter(Boolean).join(` · `):x,t[11]=x,t[12]=y,t[13]=u.loadedOnly,t[14]=_,t[15]=S):S=t[15];let C=S,w=h||a===0,T=u.input,E;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,Z.jsx)(Lt,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[16]=E):E=t[16];let D;t[17]===d?D=t[18]:(D=e=>d(e.target.value),t[17]=d,t[18]=D);let O;t[19]!==p||t[20]!==f?(O=e=>{e.nativeEvent.isComposing||e.key===`Enter`&&(e.preventDefault(),e.shiftKey?f():p())},t[19]=p,t[20]=f,t[21]=O):O=t[21];let k;t[22]!==l||t[23]!==u.input||t[24]!==r||t[25]!==O||t[26]!==D?(k=(0,Z.jsx)(`input`,{ref:l,value:r,type:`search`,autoComplete:`off`,spellCheck:!1,"aria-label":u.input,className:`h-12 min-w-0 flex-1 bg-transparent text-base text-fg outline-none placeholder:text-fg-subtle`,placeholder:u.input,onChange:D,onKeyDown:O}),t[22]=l,t[23]=u.input,t[24]=r,t[25]=O,t[26]=D,t[27]=k):k=t[27];let A;t[28]===h?A=t[29]:(A=h?(0,Z.jsx)(Ze,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null,t[28]=h,t[29]=A);let j;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(j=Y(`inline-flex size-11 shrink-0 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,ca.focusRingPanel,ca.press),t[30]=j):j=t[30];let M;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Z.jsx)(Xt,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[31]=M):M=t[31];let N;t[32]!==u.close||t[33]!==m?(N=(0,Z.jsx)(`button`,{type:`button`,onClick:m,className:j,"aria-label":u.close,children:M}),t[32]=u.close,t[33]=m,t[34]=N):N=t[34];let P;t[35]!==k||t[36]!==A||t[37]!==N?(P=(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 px-3`,children:[E,k,A,N]}),t[35]=k,t[36]=A,t[37]=N,t[38]=P):P=t[38];let F;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(F=Y(`inline-flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,ca.focusRingPanel,ca.press,ca.disabled),t[39]=F):F=t[39];let I;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,Z.jsx)(oe,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[40]=I):I=t[40];let L;t[41]!==u.previous||t[42]!==w||t[43]!==f?(L=(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:f,className:F,"aria-label":u.previous,children:I}),t[41]=u.previous,t[42]=w,t[43]=f,t[44]=L):L=t[44];let R;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(R=Y(`inline-flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover hover:text-fg`,ca.focusRingPanel,ca.press,ca.disabled),t[45]=R):R=t[45];let z;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,Z.jsx)(ie,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[46]=z):z=t[46];let B;t[47]!==u.next||t[48]!==w||t[49]!==p?(B=(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:p,className:R,"aria-label":u.next,children:z}),t[47]=u.next,t[48]=w,t[49]=p,t[50]=B):B=t[50];let ee;t[51]===C?ee=t[52]:(ee=(0,Z.jsx)(`span`,{className:`ml-auto px-2 text-sm tabular-nums text-fg-muted`,"aria-live":`polite`,"aria-atomic":`true`,children:C}),t[51]=C,t[52]=ee);let V;t[53]!==L||t[54]!==B||t[55]!==ee?(V=(0,Z.jsxs)(`div`,{className:`flex h-11 items-center border-t border-edge-subtle px-1.5`,children:[L,B,ee]}),t[53]=L,t[54]=B,t[55]=ee,t[56]=V):V=t[56];let H;return t[57]!==u.input||t[58]!==P||t[59]!==V?(H=(0,Z.jsxs)(`section`,{"data-chat-find-bar":!0,role:`search`,"aria-label":T,className:`absolute right-3 top-3 z-30 w-[min(25rem,calc(100%-1.5rem))] overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover`,children:[P,V]}),t[57]=u.input,t[58]=P,t[59]=V,t[60]=H):H=t[60],H}async function QO(e,t,n={}){let r=await h(g(`${n.taskId?`/api/tasks/${encodeURIComponent(n.taskId)}/conversation/find`:`/api/sessions/${encodeURIComponent(e)}/find`}?${new URLSearchParams({q:t,limit:`1000`})}`),{signal:n.signal});if(!r.ok)throw Error(`HTTP ${r.status}: ${r.statusText}`);let i=await r.json();if(i.ok!==!0||!Array.isArray(i.matches)||typeof i.total!=`number`)throw Error(`Invalid chat find response`);return{query:typeof i.query==`string`?i.query:t,total:i.total,truncated:i.truncated===!0,matches:i.matches.filter(e=>Number.isInteger(e?.displayIndex)&&e.displayIndex>=0&&Number.isInteger(e?.occurrence)&&e.occurrence>=0)}}var $O=`chat-find-match`,ek=`chat-find-active`,tk=`chat-find-highlight-styles`;function nk(){let e=globalThis.CSS,t=globalThis.Highlight;return!e?.highlights||!t?null:{registry:e.highlights,Highlight:t}}function rk(){if(document.getElementById(tk))return;let e=document.createElement(`style`);e.id=tk,e.textContent=`
61
+ ::highlight(${$O}) {
62
62
  color: inherit;
63
63
  background-color: color-mix(in srgb, var(--color-warning) 38%, transparent);
64
64
  }
65
- ::highlight(${tk}) {
65
+ ::highlight(${ek}) {
66
66
  color: inherit;
67
67
  background-color: color-mix(in srgb, var(--color-warning) 78%, transparent);
68
68
  text-decoration: underline 2px var(--color-fg);
69
69
  }
70
- `,document.head.appendChild(e)}function ak(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return!e.textContent||!t||t.closest(`button, [hidden], [aria-hidden="true"], .sr-only, script, style`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=n.nextNode();for(;r;)t.push(r),r=n.nextNode();return t}function ok(e,t,n){let r=e.find(e=>e.end>t),i=[...e].reverse().find(e=>e.start<n);if(!r||!i)return null;let a=document.createRange();return a.setStart(r.node,t-r.start),a.setEnd(i.node,n-i.start),a}function sk(e,t){let n=t.toLowerCase(),r=e.toLowerCase();if(!n)return[];let i=[],a=0;for(;a<=r.length-n.length;){let e=r.indexOf(n,a);if(e<0)break;i.push({start:e,end:e+n.length}),a=e+Math.max(n.length,1)}return i}function ck(e,t){let n=t.trim();if(!n)return[];let r=[],i=e.querySelectorAll(`[data-chat-message-index]`);for(let e of i){let t=e.dataset.chatMessageIndex,i=t?Number.parseInt(t,10):NaN;if(!Number.isFinite(i))continue;let a=0;for(let t of e.querySelectorAll(`[data-chat-find-text]`)){let e=ak(t),o=[],s=``;for(let t of e){let e=t.textContent??``,n=s.length;s+=e,o.push({node:t,start:n,end:s.length})}for(let e of sk(s,n)){let t=ok(o,e.start,e.end);t&&(r.push({messageIndex:i,occurrence:a,range:t}),a+=1)}}}return r}function lk(e,t){let n=rk();if(!n||(ik(),n.registry.delete(ek),n.registry.delete(tk),e.length===0))return;n.registry.set(ek,new n.Highlight(...e.map(e=>e.range)));let r=e[t];r&&n.registry.set(tk,new n.Highlight(r.range))}function uk(){let e=rk();e?.registry.delete(ek),e?.registry.delete(tk)}function dk(e,t,n=96){let r=t.range.getBoundingClientRect(),i=e.getBoundingClientRect(),a=i.top+n,o=i.bottom-24;r.top>=a&&r.bottom<=o||(iw(e),e.scrollTo({top:Math.max(0,e.scrollTop+r.top-a),behavior:window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`}))}function fk(e,t){return t===0?0:(e+t)%t}function pk(e){return`${e.displayIndex}:${e.occurrence}`}function mk(e,t){return e.length===t.length&&e.every((e,n)=>{let r=t[n];return r?.messageIndex===e.messageIndex&&r.occurrence===e.occurrence&&r.range.startContainer===e.range.startContainer&&r.range.startOffset===e.range.startOffset&&r.range.endContainer===e.range.endContainer&&r.range.endOffset===e.range.endOffset})}function hk(e){let t=(0,X.c)(66),{conversationId:n,taskId:r,messages:i,displayOffset:a,viewportRef:o,onRevealDisplayIndex:s}=e,[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=[],t[0]=f):f=t[0];let[p,m]=(0,Q.useState)(f),h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=[],t[1]=h):h=t[1];let[g,_]=(0,Q.useState)(h),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(0),E=(0,Q.useRef)(null),D=(0,Q.useRef)(null),O=(0,Q.useRef)(n),k=(0,Q.useDeferredValue)(u),A;if(t[2]!==a||t[3]!==p||t[4]!==g){let e=new Map(g.map(bk));for(let t of p){let n={displayIndex:a+t.messageIndex,occurrence:t.occurrence};e.set(pk(n),n)}A=[...e.values()].sort(yk),t[2]=a,t[3]=p,t[4]=g,t[5]=A}else A=t[5];let j=A,M;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>{requestAnimationFrame(()=>{E.current?.focus(),E.current?.select()})},t[6]=M):M=t[6];let N=M,P;t[7]===c?P=t[8]:(P=()=>{if(!c){D.current=document.activeElement instanceof HTMLElement?document.activeElement:null,l(!0);return}N()},t[7]=c,t[8]=P);let F=P,I,L;t[9]===c?(I=t[10],L=t[11]):(I=()=>{c&&N()},L=[N,c],t[9]=c,t[10]=I,t[11]=L),(0,Q.useLayoutEffect)(I,L);let R;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>{l(!1),d(``),m([]),_([]),y(!1),x(!1),C(!1),T(0),uk(),D.current?.focus(),D.current=null},t[12]=R):R=t[12];let z=R,B;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(B=e=>{d(e),T(0)},t[13]=B):B=t[13];let ee=B,V;t[14]===j.length?V=t[15]:(V=e=>{T(t=>fk(t+e,j.length))},t[14]=j.length,t[15]=V);let H=V,U,W;t[16]!==H||t[17]!==c||t[18]!==F?(U=()=>{let e=e=>{let t=e.metaKey||e.ctrlKey;if(t&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`f`){if(document.querySelector(`[role="dialog"][data-state="open"]`))return;e.preventDefault(),F();return}if(c){if(t&&!e.altKey&&e.key.toLowerCase()===`g`){e.preventDefault(),H(e.shiftKey?-1:1);return}e.key===`Escape`&&(e.preventDefault(),z())}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},W=[z,H,c,F],t[16]=H,t[17]=c,t[18]=F,t[19]=U,t[20]=W):(U=t[19],W=t[20]),(0,Q.useEffect)(U,W);let te;t[21]!==k||t[22]!==c||t[23]!==o?(te=()=>{let e=o.current;if(!c||!e||!k.trim()){m(vk),uk();return}let t=()=>{let t=ck(e,k);m(e=>mk(e,t)?e:t)};t();let n=null,r=new MutationObserver(()=>{n===null&&(n=requestAnimationFrame(()=>{n=null,t()}))});return r.observe(e,{childList:!0,subtree:!0,characterData:!0}),()=>{r.disconnect(),n!==null&&cancelAnimationFrame(n)}},t[21]=k,t[22]=c,t[23]=o,t[24]=te):te=t[24];let ne;t[25]!==k||t[26]!==i||t[27]!==c||t[28]!==o?(ne=[k,i,c,o],t[25]=k,t[26]=i,t[27]=c,t[28]=o,t[29]=ne):ne=t[29],(0,Q.useLayoutEffect)(te,ne);let re,ie;t[30]!==n||t[31]!==k||t[32]!==c||t[33]!==r?(re=()=>{let e=k.trim();if(!c||!n||!e){_([]),y(!1),x(!1),C(!1);return}let t=new AbortController;_([]),y(!1),x(!1),C(!0);let i=window.setTimeout(()=>{$O(n,e,{taskId:r,signal:t.signal}).then(e=>{_(e.matches),y(e.truncated)}).catch(e=>{e?.name!==`AbortError`&&(_([]),y(!1),x(!0))}).finally(()=>{t.signal.aborted||C(!1)})},150);return()=>{window.clearTimeout(i),t.abort()}},ie=[n,k,c,r],t[30]=n,t[31]=k,t[32]=c,t[33]=r,t[34]=re,t[35]=ie):(re=t[34],ie=t[35]),(0,Q.useEffect)(re,ie);let ae,oe;t[36]===j.length?(ae=t[37],oe=t[38]):(ae=()=>{T(e=>Math.min(e,Math.max(0,j.length-1)))},oe=[j.length],t[36]=j.length,t[37]=ae,t[38]=oe),(0,Q.useEffect)(ae,oe);let se,ce;t[39]!==w||t[40]!==j||t[41]!==a||t[42]!==p||t[43]!==s||t[44]!==o?(se=()=>{let e=j[w],t=o.current;if(!t||!e){lk(p,-1);return}let n=e.displayIndex-a,r=p.findIndex(t=>t.messageIndex===n&&t.occurrence===e.occurrence);lk(p,r),r>=0?dk(t,p[r]):s(e.displayIndex)},ce=[w,j,a,p,s,o],t[39]=w,t[40]=j,t[41]=a,t[42]=p,t[43]=s,t[44]=o,t[45]=se,t[46]=ce):(se=t[45],ce=t[46]),(0,Q.useLayoutEffect)(se,ce);let le;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(le=[],t[47]=le):le=t[47],(0,Q.useEffect)(gk,le);let ue,de;t[48]!==n||t[49]!==c?(ue=()=>{O.current!==n&&(O.current=n,c&&z())},de=[z,n,c],t[48]=n,t[49]=c,t[50]=ue,t[51]=de):(ue=t[50],de=t[51]),(0,Q.useEffect)(ue,de);let G,K;t[52]===H?(G=t[53],K=t[54]):(G=()=>H(-1),K=()=>H(1),t[52]=H,t[53]=G,t[54]=K);let fe;return t[55]!==w||t[56]!==j.length||t[57]!==b||t[58]!==c||t[59]!==u||t[60]!==v||t[61]!==S||t[62]!==F||t[63]!==G||t[64]!==K?(fe={open:c,query:u,inputRef:E,activeIndex:w,resultCount:j.length,truncated:v,limitedToLoaded:b,searching:S,setQuery:ee,show:F,close:z,previous:G,next:K},t[55]=w,t[56]=j.length,t[57]=b,t[58]=c,t[59]=u,t[60]=v,t[61]=S,t[62]=F,t[63]=G,t[64]=K,t[65]=fe):fe=t[65],fe}function gk(){return _k}function _k(){return uk()}function vk(e){return e.length===0?e:[]}function yk(e,t){return e.displayIndex-t.displayIndex||e.occurrence-t.occurrence}function bk(e){return[pk(e),e]}function xk(e){let t=String(e??``).trim();return!t||t===`new`?null:t}function Sk(e){let t=String(e.streamConversationId??``).trim(),n=xk(e.routeConversationId);return!t||!n?!1:t===n}function Ck(e){let t=xk(e.routeConversationId);return t?e.cacheConversationId===t:!1}function wk(e){let t=String(e.chatId??``).trim();if(!t)return!1;let n=xk(e.routeConversationId);return n?n===t:!1}function Tk(e,t){return e?`new`:t??null}function Ek(e,t){if(!(e||!t))return decodeURIComponent(t)}function Dk(e){if(!e.viewConversationId||e.conversationId!==e.viewConversationId)return[];if(!e.streamingMsg)return e.messages;let t=e.messages[e.messages.length-1];if(t?.role===`assistant`&&e.streamingMsg.role===`assistant`){let n=ur([t,e.streamingMsg]);return[...e.messages.slice(0,-1),...n]}return[...e.messages,e.streamingMsg]}function Ok(e,t){let n=e[e.length-1];return n?.role!==`assistant`||n.turnId!==t?null:{messagesWithoutTail:e.slice(0,-1),tail:n}}function kk(e){e()}function Ak(e,t){return!!(e&&(e.localDraft||e.configVersion!==void 0)&&t?.some(t=>t.id===e.model))}function jk(e){e.sendingRef.current=!1,e.streamingRef.current=!1}function Mk(e){return e.isNewRoute?`creating-session`:e.sessionRoutePending||e.showSessionLoading||e.sessionContentLoading?`loading-history`:e.messageCount===0?`ready-empty`:`ready-conversation`}var Nk=new Map;async function Pk(e,t,n,r,i){let a=_.getState(),o=Mr([a.baseUrl,a.conversationId,e,t]),s=Mr({action:n,submission:r}),c=Nk.get(o);if(c){if(c.signature!==s)throw Error(`An answer is already being submitted`);return(await c.promise).clone()}let l=Fk(e,t,n,r,i).then(e=>{for(e.ok||Nk.delete(o);Nk.size>64;)Nk.delete(Nk.keys().next().value);return e},e=>{throw Nk.delete(o),e});return Nk.set(o,{signature:s,promise:l}),(await l).clone()}async function Fk(e,t,n,r,i){let a=_.getState().conversationId,o=Cf(e,t,`submission`,i),s={schemaVersion:2,action:n,...r,expectedVersion:t},c=Mr(s),l=await o.read();if(l&&l.signature!==c)throw Error(`The previous answer is awaiting confirmation. Retry the original answer before changing it.`);let u=l??{signature:c,body:{...s,idempotencyKey:crypto.randomUUID()}};if(await o.write(u),window.dispatchEvent(new CustomEvent(`clarification-submission-state`,{detail:{requestId:e,pending:!0}})),_.getState().conversationId!==a)throw Error(`Active Gateway changed`);let d=await h(g(`/api/clarifications/${encodeURIComponent(e)}/responses`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(u.body)});return(d.ok||d.status>=400&&d.status<500)&&(await o.write(void 0),window.dispatchEvent(new CustomEvent(`clarification-submission-state`,{detail:{requestId:e,pending:!1}})),d.ok&&await Cf(e,t,`draft`,i).write(void 0)),d}async function Ik(e,t,n){let r=()=>{if(!n())throw new DOMException(`Conversation changed`,`AbortError`)},i=await Fr(e);if(r(),i&&(i.kind!==`append`||i.execution||i.delivery!==t.delivery||Mr(i.input)!==Mr(t.input)||!!i.interrupt!=!!t.interrupt))throw Error(`The previous input is awaiting confirmation`);let a=Ir.parse({...i??t,origin:t.origin}),o=t=>{let n=t?.receipt;if(!n||n.conversationId!==e||n.clientMessageId!==a.clientMessageId||n.transcriptId!==a.expectedTranscriptId||t?.session?.transcriptId!==n.transcriptId)throw Error(`Invalid input receipt or conversation was reset; reload before sending`);if(!t?.inputState)throw Error(`Gateway returned an invalid input state`);return t.inputState},s=async t=>{let n=await h(g(`/api/sessions/${encodeURIComponent(e)}/input-receipts/${encodeURIComponent(a.clientMessageId)}`),{signal:t}),i=await n.json();if(r(),n.ok)return o(i.payload);if(n.status!==404||i.error?.code!==`NOT_RECEIVED`)throw Error(i.error?.message??`Input receipt lookup failed`)},c=async t=>(r(),await Rr(e,a.clientMessageId),r(),t);if(i){let e=await s();if(e!==void 0)return c(e)}let{origin:l,...u}=a;await zr(e,u),r();let d,f;try{d=await h(g(`/api/sessions/${encodeURIComponent(e)}/inputs`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(a)});let t=await d.json();if(r(),!d.ok)throw Error(typeof t.error==`string`?t.error:t.error?.message??`Message was not accepted`);f=o(t.payload)}catch(t){if(r(),d&&d.status>=400&&d.status<500&&d.status!==408)throw await Rr(e,a.clientMessageId),t;if(f=await s(AbortSignal.timeout(3e3)).catch(()=>void 0),r(),f===void 0)throw t}return c(f)}function Lk(e,t){if(!e||typeof e!=`object`)return null;let n=e,r=n.clarification&&typeof n.clarification==`object`?n.clarification:n;if(r.status!==void 0&&r.status!==`open`||t&&typeof r.conversationId==`string`&&r.conversationId!==t)return null;let i=typeof r.id==`string`?r.id:r.requestId,a=r.question,o=r.kind===`approval`?`approval`:`input`;return typeof i!=`string`||!i.trim()||typeof a!=`string`||!a.trim()?null:{...kr(r),requestId:i.trim(),conversationId:t,kind:o,question:a.trim(),version:typeof r.version==`number`?r.version:1,createdAt:typeof r.createdAt==`number`?r.createdAt:Date.now(),expiresAt:typeof r.expiresAt==`number`?r.expiresAt:void 0,serverTime:typeof n.serverTime==`number`?n.serverTime:void 0}}function Rk(e){let{conversationId:t,decodedKey:n,conversationIdRef:r,sendingRef:i,streamingRef:a,modelSupportsThinking:o,thinkingLevel:s,shouldApplyStreamUpdate:c}=e,l=_(e=>e.conversationId),u=(0,Q.useRef)({gateway:l,conversationId:t});(u.current.gateway!==l||u.current.conversationId!==t)&&(u.current={gateway:l,conversationId:t});let d=(0,Q.useCallback)(()=>{let e=u.current;return()=>u.current===e&&r.current===e.conversationId&&_.getState().conversationId===e.gateway},[r]),[f,p]=(0,Q.useState)(null),[m,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),x=(0,Q.useRef)(null),S=(0,Q.useRef)(0),C=(0,Q.useRef)(null),[w,T]=(0,Q.useState)([]),E=(0,Q.useRef)([]),[D,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(()=>({scope:u.current,mode:{kind:`compose`}})),j=k.scope===u.current?k.mode:{kind:`compose`},M=(0,Q.useCallback)(e=>A({scope:u.current,mode:e}),[]),N=(0,Q.useRef)(j);N.current=j;let P=j.kind===`editFollowUp`?j.inputId:null,F=e=>M(e?{kind:`editFollowUp`,inputId:e,version:E.current.find(t=>t.id===e)?.version??0}:{kind:`compose`}),[I,L]=(0,Q.useState)(()=>mr(t??``)),[R,z]=(0,Q.useState)(!1),B=(0,Q.useRef)(!1),ee=(0,Q.useRef)(null),V=(0,Q.useRef)(-1),[H,U]=(0,Q.useState)(!1),W=(0,Q.useRef)(null),[te,ne]=(0,Q.useState)(null),re=(0,Q.useCallback)(()=>ne(u.current),[]);x.current=f,E.current=w,ee.current=P;let ie=(0,Q.useCallback)(e=>{if(!e||typeof e!=`object`)return;let t=e;if(t.conversationId!==r.current||typeof t.revision!=`number`||!Array.isArray(t.inputs)||t.revision<V.current)return;if(t.control){if(!vr(t.conversationId,t.control,t.revision))return;L(t.control)}let n=ST({control:t.control,inputs:t.inputs,activeRunId:t.activeRunId,preparation:t.preparation});V.current=t.revision,U(!t.activeRunId&&t.inputs.length===0),E.current=n,T(n)},[r]),ae=(0,Q.useCallback)(async e=>{if(e!==r.current)return;let t=d();if(await jr(e)||!t())return;let n=await h(g(`/api/sessions/${encodeURIComponent(e)}/input-state`)).catch(()=>null);if(!n?.ok||r.current!==e)return;let i=await n.json().catch(()=>null);t()&&ie(i?.payload)},[ie,d,r]),oe=(0,Q.useCallback)(async e=>{if(e!==r.current)return;let t=d(),n=++S.current;if(await jr(e)||!t())return;let i=await h(g(`/api/sessions/${encodeURIComponent(e)}/clarification`)).catch(()=>null);if(!i?.ok||r.current!==e)return;let a=await i.json().catch(()=>null);!t()||n!==S.current||r.current!==e||(b(null),p(Lk(a?.payload,e)),C.current=null)},[d,r]);(0,Q.useLayoutEffect)(()=>{V.current=-1,U(!1),W.current=null,B.current=!1,z(!1),O(null),S.current++,L(mr(t??``)),M({kind:`compose`}),E.current=[],T([]),F(null),p(null)},[t,l]),(0,Q.useEffect)(()=>{!t||t!==n||(ae(t),oe(t))},[n,oe,ae,t,l]),(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail;ie(t);let n=r.current;n&&t&&typeof t==`object`&&t.conversationId===n&&oe(n)},t=e=>{let t=r.current;if(!t)return;let n=e.detail;if(n&&typeof n==`object`){let e=n.conversationId;if(typeof e==`string`&&e!==t)return}b(null),S.current++,p(Lk(n,t)),C.current=null},n=()=>{let e=r.current;e&&(ae(e),oe(e))};return window.addEventListener(`session-input-state`,e),window.addEventListener(`clarification-updated`,t),window.addEventListener(`gateway-realtime-connected`,n),()=>{window.removeEventListener(`session-input-state`,e),window.removeEventListener(`clarification-updated`,t),window.removeEventListener(`gateway-realtime-connected`,n)}},[ie,oe,ae,r]),(0,Q.useEffect)(()=>{if(!f?.expiresAt)return;let e=Math.max(0,f.expiresAt-Date.now())+250,t=window.setTimeout(()=>{let e=r.current;e&&oe(e)},e);return()=>window.clearTimeout(t)},[f?.expiresAt,oe,r]);let se=(0,Q.useCallback)(()=>{b(null),p(null)},[]),ce=(0,Q.useCallback)(e=>{let t=String(e??``).trim();t&&r.current===t&&(b(null),p(null))},[r]),le=(0,Q.useCallback)(()=>{b(null),p(null)},[]),ue=(0,Q.useCallback)(()=>{F(null)},[]),de=(0,Q.useCallback)(()=>{b(null),p(null),F(null)},[]),G=(0,Q.useCallback)(e=>t=>{c(e)&&(i.current=!1,a.current=!1,Sn.getState().setSessionFlags(e,{sending:!1,streaming:!1}),Sn.getState().setSessionProgress(e,null),b(null),S.current++,p({...t,conversationId:e}),C.current=null)},[c,i,a]),K=(0,Q.useCallback)(async(e,t,n,i,a,o)=>{let s=e.trim();if(!s&&!t?.length&&!n?.length)return;let c=r.current;if(!c)throw Error(`No active session`);let l=d(),u=mr(c),f=await Lr(c);if(!l())throw new DOMException(`Conversation changed`,`AbortError`);let p=await ir();if(!l())throw new DOMException(`Conversation changed`,`AbortError`);if(!f)throw Error(`Reload the conversation before sending`);let m=Sn.getState().sessions[c]?.configVersion;if(m===void 0)throw Error(`Reload the conversation before sending`);let h=await Ik(c,{kind:`append`,expectedTranscriptId:f,configVersion:m,clientMessageId:crypto.randomUUID(),delivery:o??`next`,interrupt:a,controlVersion:u.version,input:{content:s||e,attachments:t?.length?t:void 0,contextRefs:n?.map(({refId:e,kind:t,sourceId:n,expectedVersion:r})=>({refId:e,kind:t,sourceId:n,expectedVersion:r})),appContext:i},origin:p},l);l()&&ie(h)},[ie,d,r]),fe=(0,Q.useCallback)(async(e,t)=>{let n=r.current;if(!n||B.current)throw Error(`Wait for the current operation`);let i=d(),a=()=>{if(!i())throw new DOMException(`Conversation changed`,`AbortError`)};B.current=!0,z(!0);try{let r=await Lr(n);a();let i=Date.now()+15e3;for(;!r&&e===`stop`&&Date.now()<i;)await new Promise(e=>setTimeout(e,100)),r=await Lr(n),a();if(!r)throw Error(`Input acceptance is awaiting confirmation`);if(t?.onlyIfEmpty&&N.current.kind!==`compose`)return;let o={action:e,operationId:crypto.randomUUID(),expectedTranscriptId:r,expectedVersion:mr(n).version,...t},s=await Qn(n,o);if(a(),ie(s),e===`steer`){let e=s.inputs?.find(e=>e.id===t?.inputId);if(e?.status===`interrupted`)throw Error(e.error??`Current reply ended before steering`)}if(e===`stop`){let e=Date.now()+15e3;for(;mr(n).phase===`stopping`;){if(a(),Date.now()>=e)throw Error(`Stop is awaiting confirmation`);await new Promise(e=>setTimeout(e,100)),await ae(n)}}if(a(),e===`stop`||e===`pause`){let t=mr(n);if(!t.paused||t.version!==o.expectedVersion+1)throw Error(`Queue control changed on another device`);if(e===`stop`&&t.phase!==`idle`)throw Error(`Another input has started`)}}catch(e){throw!i()||(await ae(n),!i())||t?.onlyIfEmpty||ya(`error`,e instanceof Error?e.message:String(e)),e}finally{i()&&(B.current=!1,z(!1))}},[ie,d,r,ae]);(0,Q.useEffect)(()=>{if(!t||!H||!I.paused||I.phase!==`idle`||R||j.kind!==`compose`||te!==u.current)return;let e=`${l}:${t}:${I.version}:${V.current}`;if(W.current===e)return;let n=window.setTimeout(()=>{B.current||N.current.kind!==`compose`||(W.current=e,fe(`resume`,{onlyIfEmpty:!0}).catch(()=>{}))},0);return()=>window.clearTimeout(n)},[fe,j.kind,I.paused,I.phase,I.version,R,t,l,te,H]);let q=(0,Q.useCallback)(()=>fe(`stop`),[fe]),pe=(0,Q.useCallback)(()=>fe(`resume`),[fe]),me=(0,Q.useCallback)(async(e,t)=>{let n=d();try{return await fe(`stop`,{turnId:e}),n()?(M({kind:`editTurn`,turnId:e,draft:t}),!0):!1}catch{return!1}},[d,fe]),J=(0,Q.useCallback)(async e=>{let t=E.current.find(t=>t.id===e);if(!t)return!1;let n=d();try{return await fe(`pause`,{inputId:e,inputVersion:t.version}),n()?(M({kind:`editFollowUp`,inputId:e,version:t.version}),!0):!1}catch{return!1}},[d,fe]),he=(0,Q.useCallback)(()=>M({kind:`compose`}),[]),ge=(0,Q.useCallback)(async(e,t,n,i,a)=>{let c=r.current;if(!c||j.kind!==`editFollowUp`||j.inputId!==e||!t.trim()&&!n?.length&&!a?.length)return!1;let l=d(),u=await h(g(`/api/sessions/${encodeURIComponent(c)}/inputs/${encodeURIComponent(e)}`),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({version:j.version,content:t,attachments:n??[],thinking:o?i??s:`off`,contextRefs:(a??[]).map(({refId:e,kind:t,sourceId:n,expectedVersion:r})=>({refId:e,kind:t,sourceId:n,expectedVersion:r}))})}),f=await u.json();if(!l())return!1;if(ie(f.payload),!u.ok)throw Error(f.error?.message??`This input changed; your draft has been preserved`);if(N.current===j){let t=f.payload?.inputs?.find(t=>t.id===e);t&&M({...j,version:t.version})}return!0},[ie,d,j,r,o,s]),_e=(0,Q.useCallback)(e=>{ee.current===e&&F(null);let t=r.current,n=E.current.find(t=>t.id===e);if(!t||!n)return;let i=d();h(g(`/api/sessions/${encodeURIComponent(t)}/inputs/${encodeURIComponent(e)}?version=${n.version}`),{method:`DELETE`}).then(async e=>{let t=await e.json().catch(()=>null);i()&&ie(t?.payload)}).catch(()=>{ae(t)})},[ie,d,ae,r]),ve=(0,Q.useCallback)((e,t)=>{let n=E.current.filter(e=>e.status===`queued`),i=n.findIndex(t=>t.id===e);if(i<0)return;let a=t===`up`?i-1:i+1,o=r.current,s=n[i];if(!o||!s||a<0||a>=n.length)return;let c=d();h(g(`/api/sessions/${encodeURIComponent(o)}/inputs/${encodeURIComponent(s.id)}`),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({version:s.version,position:a})}).then(async e=>{let t=await e.json().catch(()=>null);c()&&ie(t?.payload)}).catch(()=>{ae(o)})},[ie,d,ae,r]),ye=(0,Q.useCallback)((e,t)=>{let n=r.current,i=E.current[e],a=E.current[t],o=E.current.filter(e=>e.status===`queued`),s=a?o.findIndex(e=>e.id===a.id):-1;if(!n||i?.status!==`queued`||a?.status!==`queued`||s<0)return;let c=d();h(g(`/api/sessions/${encodeURIComponent(n)}/inputs/${encodeURIComponent(i.id)}`),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({version:i.version,position:s})}).then(async e=>{let t=await e.json().catch(()=>null);c()&&ie(t?.payload)}).catch(()=>{ae(n)})},[ie,d,ae,r]),be=(0,Q.useCallback)(async(e,t)=>{let n=E.current.find(t=>t.id===e);if(!n)return;let r=d();O(e);try{await fe(t,{inputId:e,inputVersion:n.version})}finally{r()&&O(null)}},[d,fe]),xe=(0,Q.useCallback)(e=>be(e,`steer`),[be]),Se=(0,Q.useCallback)(e=>be(e,`send`),[be]),Ce=(0,Q.useCallback)(async(e,t)=>{let n=x.current;if(!n)return;let i=JSON.stringify([n.requestId,n.version,e,t]);C.current?.signature!==i&&(C.current={signature:i,idempotencyKey:crypto.randomUUID()});let a=C.current.idempotencyKey;v(!0),b(null);try{let i=n.schemaVersion===2?await Pk(n.requestId,n.version,e,t,r.current??void 0):await h(g(`/api/clarifications/${encodeURIComponent(n.requestId)}/responses`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:e,...t,expectedVersion:n.version,idempotencyKey:a})});if(x.current?.requestId!==n.requestId)return;if(!i.ok){let e=await i.json().catch(()=>({}));b(e.error?.message??i.statusText??`Clarify failed`);let t=r.current;t&&(i.status===409||i.status===410)&&oe(t);return}C.current=null,p(null),b(null)}catch(e){x.current?.requestId===n.requestId&&b(e instanceof Error?e.message:String(e))}finally{v(!1)}},[oe,r]);return{clarifyPrompt:f,clarifySubmitting:m,clarifySubmitError:y,clarifyPromptRef:x,pendingFollowUps:w,pendingFollowUpsRef:E,steeringFollowUpId:D,composerMode:j,control:I,controlPending:R,stopSession:q,resumeQueue:pe,sendQueuedInput:Se,beginEditTurn:me,cancelEditor:he,restoreEditor:M,markComposerHydrated:re,editingFollowUpId:P,addPendingFollowUp:K,beginEditFollowUp:J,cancelEditFollowUp:he,commitEditFollowUp:ge,removePendingFollowUp:_e,movePendingFollowUp:ve,reorderPendingFollowUp:ye,steerPendingFollowUp:xe,submitClarifyAnswer:(0,Q.useCallback)(e=>Ce(`answer`,e),[Ce]),letAgentDecideClarification:(0,Q.useCallback)(()=>Ce(`agent_decide`),[Ce]),cancelClarification:(0,Q.useCallback)(()=>Ce(`cancel`),[Ce]),clearVisibleClarify:se,dismissClarify:le,dismissClarifyForSession:ce,clearPendingFollowUps:ue,dismissClarifyAndClearPending:de,makeOnClarifyRequest:G}}async function zk(e){let t=await jr(e);if(t)return{agentId:t.creation.agentId.trim().toLowerCase(),projectId:t.creation.projectId?.trim()||null};let n=await hn(e);return{agentId:(n.routing?.agentId??n.agentId).trim().toLowerCase(),projectId:n.projectId?.trim()||null}}function Bk(e){let t=(0,X.c)(59),{navigate:n,conversationIdRef:r,conversationId:i,isNewRoute:a,locationState:o,locationSearch:s,personal:c}=e,l=c!==void 0&&c,u=_(Wk),d;t[0]===i?d=t[1]:(d=i?.trim()??``,t[0]=i,t[1]=d);let f=d,p;t[2]===u?p=t[3]:(p=u?[`gateway-chat-agents`,u]:null,t[2]=u,t[3]=p);let m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m={revalidateOnFocus:!1},t[4]=m):m=t[4];let{data:h,mutate:g}=Qr(p,si,m),v;t[5]!==f||t[6]!==u?(v=u&&f?[`gateway-chat-session-agent`,u,f]:null,t[5]=f,t[6]=u,t[7]=v):v=t[7];let y;t[8]===f?y=t[9]:(y=()=>zk(f),t[8]=f,t[9]=y);let b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b={revalidateOnFocus:!1},t[10]=b):b=t[10];let{data:x}=Qr(v,y,b),S=x?.agentId??``,C,w;t[11]===g?(C=t[12],w=t[13]):(C=()=>{let e=e=>{oi(e.detail)||g()};return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},w=[g],t[11]=g,t[12]=C,t[13]=w),(0,Q.useEffect)(C,w);let[T,E]=(0,Q.useState)(Uk),D=(0,Q.useRef)(h??null),O;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(O=Yr().selectedAgentId??null,t[14]=O):O=t[14];let k=(0,Q.useRef)(O),A,j;t[15]===h?(A=t[16],j=t[17]):(A=()=>{D.current=h??null},j=[h],t[15]=h,t[16]=A,t[17]=j),(0,Q.useEffect)(A,j);let M,N;t[18]===T?(M=t[19],N=t[20]):(M=()=>{k.current=T},N=[T],t[18]=T,t[19]=M,t[20]=N),(0,Q.useEffect)(M,N);let P,F;t[21]===h?(P=t[22],F=t[23]):(P=()=>{if(!h)return;let e=new Set(h.items.map(Hk));E(t=>t==null||t===``||!e.has(t)?h.defaultId:t)},F=[h],t[21]=h,t[22]=P,t[23]=F),(0,Q.useEffect)(P,F);let I;t[24]!==r||t[25]!==S?(I=()=>{if(r.current&&S)return S;let e=D.current,t=(k.current??``).trim().toLowerCase();if(!e)return t||void 0;let n=new Set(e.items.map(Vk));return t&&n.has(t)?t:e.defaultId},t[24]=r,t[25]=S,t[26]=I):I=t[26];let L=I,R;t[27]!==r||t[28]!==S||t[29]!==x?.projectId||t[30]!==a||t[31]!==s||t[32]!==o||t[33]!==n?(R=e=>{let t=e.trim().toLowerCase(),i=r.current?S||k.current:null;k.current=t,E(t),Vr(t),i!==t&&n(a?`/chat/new${s}`:Ra(x?.projectId),{replace:!1,state:{...a&&o&&typeof o==`object`?o:{},agentId:t,forceNewChat:!0}})},t[27]=r,t[28]=S,t[29]=x?.projectId,t[30]=a,t[31]=s,t[32]=o,t[33]=n,t[34]=R):R=t[34],x?.projectId;let z=R,B,ee;t[35]===z?(B=t[36],ee=t[37]):(B=()=>{let e=e=>{let t=e.detail?.agentId;typeof t!=`string`||!t.trim()||z(t)};return window.addEventListener(`xopc-set-chat-agent`,e),()=>window.removeEventListener(`xopc-set-chat-agent`,e)},ee=[z],t[35]=z,t[36]=B,t[37]=ee),(0,Q.useEffect)(B,ee);let V,H;t[38]!==i||t[39]!==S||t[40]!==l?(V=()=>{if(!i||l)return;let e=S;!e||k.current===e||(k.current=e,E(e),Vr(e))},H=[S,i,l],t[38]=i,t[39]=S,t[40]=l,t[41]=V,t[42]=H):(V=t[41],H=t[42]),(0,Q.useLayoutEffect)(V,H);let U,W;t[43]!==i||t[44]!==x?(U=()=>{!i||!x||qr(x.projectId)},W=[x,i],t[43]=i,t[44]=x,t[45]=U,t[46]=W):(U=t[45],W=t[46]),(0,Q.useLayoutEffect)(U,W);let te,ne;t[47]!==a||t[48]!==o?(te=()=>{if(!a)return;let e=o,t=typeof e?.agentId==`string`?e.agentId.trim().toLowerCase():``;t&&(k.current=t,E(t),Vr(t))},ne=[a,o],t[47]=a,t[48]=o,t[49]=te,t[50]=ne):(te=t[49],ne=t[50]),(0,Q.useLayoutEffect)(te,ne);let re=S||T||h?.defaultId||`main`,ie=(h?.items.length??0)>1,ae=x?.projectId??null,oe;return t[51]!==h||t[52]!==re||t[53]!==z||t[54]!==L||t[55]!==ie||t[56]!==ae||t[57]!==u?(oe={token:u,chatAgentsData:h,resolveAgentIdForPost:L,onChatAgentChange:z,displayAgentId:re,showChatAgentSelector:ie,currentSessionProjectId:ae},t[51]=h,t[52]=re,t[53]=z,t[54]=L,t[55]=ie,t[56]=ae,t[57]=u,t[58]=oe):oe=t[58],oe}function Vk(e){return e.id}function Hk(e){return e.id}function Uk(){return Yr().selectedAgentId??null}function Wk(e){return e.conversationId}async function Gk(e){let t=await e.sessionMgr.createSession(e);return{kind:`create`,conversationId:t.key,session:t}}var Kk=new Map,qk=0;function Jk(e){let t=_.getState(),n=Hr(t.baseUrl,{agentId:e.agentId?.trim()||`main`,projectId:e.projectId??null}),r=JSON.stringify([n,t.conversationId,e.forceNew===!0,e.temporary===!0,e.executionMode,e.search]),i=Kk.get(r);if(i)return i.target.opts=e,i.target.generation=++qk,i.promise;let a={opts:e,generation:++qk},o=e=>{if(a.generation!==qk)return;let t=a.opts;!t.routeConversationId&&yi.getState().scope===`new`&&yi.getState().migrateScope(`new`,e),t.onOpened(e),(t.routeConversationId?.trim()||null)!==e&&t.navigateToSession(e,t.replaceNavigate??!1,t.search)},s=(async()=>{let t=e.agentId??void 0,{conversationId:n}=await Gk({sessionMgr:e.sessionMgr,agentId:t?.trim()||`main`,projectId:e.projectId,currentConversationId:e.currentConversationId,forceNew:e.forceNew,temporary:e.temporary,initialAgentConfig:e.initialAgentConfig,executionMode:e.executionMode});return o(n),n})().finally(()=>{Kk.delete(r)});return Kk.set(r,{promise:s,target:a}),s}var Yk={current:null},Xk={current:null};function Zk(e){return!!(e&&typeof e==`object`&&e.forceNewChat===!0)}function Qk(e){let t=d(),{conversationId:n}=u(),r=!e&&t.pathname.endsWith(`/new`),i=r&&Zk(t.state),a=e??Ek(r,n),o=Tk(r,a),s=xk(o),c=r?null:a??null,l=(0,Q.useRef)(o);return l.current=o,Yk.current=c,!r&&a&&(Xk.current=a),(0,Q.useLayoutEffect)(()=>{Sn.getState().focusedConversationId!==c&&Sn.getState().setFocusedConversationId(c)},[c]),{isNewRoute:r,forceNewChat:i,decodedKey:a,routedConversationId:o,viewConversationId:s,routedFocusedConversationId:c,routeConversationIdRef:l,locationKey:t.key,locationSearch:t.search,locationState:t.state}}var $k={get current(){return Xk.current}},eA={get current(){return Yk.current},set current(e){Yk.current=e,Sn.getState().setFocusedConversationId(e)}};function tA(e){let{token:t,isNewRoute:n,forceNewChat:r,temporary:i=!1,requestedAgentId:a,decodedKey:o,locationKey:s,locationSearch:c,sessionMgrRef:l,resolveAgentIdForPost:u,navigateToSession:d,loadSessionById:f,tryResumeAgentRun:p,restoreLiveCacheIfNeeded:m,adoptEmptySession:h,applyAgentConfig:g,patchInitUi:v}=e,y=(0,Q.useRef)(0),b=_(e=>e.baseUrl),[x,S]=(0,Q.useState)(null),C=n?c:``,w=n?`new:${s}`:o?`session:${o}`:`fallback:${s}`,T=(0,Q.useRef)({isNewRoute:n,forceNewChat:r,temporary:i,requestedAgentId:a,decodedKey:o,newRouteLocationSearch:C});T.current={isNewRoute:n,forceNewChat:r,temporary:i,requestedAgentId:a,decodedKey:o,newRouteLocationSearch:C};let E=(0,Q.useRef)({sessionMgrRef:l,resolveAgentIdForPost:u,navigateToSession:d,loadSessionById:f,tryResumeAgentRun:p,restoreLiveCacheIfNeeded:m,adoptEmptySession:h,applyAgentConfig:g,patchInitUi:v});return E.current={sessionMgrRef:l,resolveAgentIdForPost:u,navigateToSession:d,loadSessionById:f,tryResumeAgentRun:p,restoreLiveCacheIfNeeded:m,adoptEmptySession:h,applyAgentConfig:g,patchInitUi:v},(0,Q.useEffect)(()=>{let e=T.current,n=E.current;if(!t){n.patchInitUi({loading:!1});return}let r=++y.current,i=!1,a=()=>!i&&r===y.current,o=e=>{a()&&n.sessionMgrRef.current.loadSessionAgentConfig(e).then(t=>{a()&&n.applyAgentConfig(e,t)}).catch(()=>{})},s=async()=>{if(!a())return Promise.resolve();let r=Yr(),i=n.resolveAgentIdForPost(),s=Wr({origin:`web-route`,project:Ba(e.newRouteLocationSearch),agentId:e.requestedAgentId??i,forceNew:e.forceNewChat,temporary:e.temporary},{defaultAgentId:i??`main`,selectedAgentId:r.selectedAgentId,lastChatScope:r.lastChatScope}),c=s.projectId?await fn(s.projectId):null;if(!a())return;!e.requestedAgentId&&c?.defaultAgentId&&(s.agentId=c.defaultAgentId);let l=Jr(r,s.agentId),u=(t,r,i)=>Jk({sessionMgr:n.sessionMgrRef.current,agentId:s.agentId,currentConversationId:$k.current,routeConversationId:null,forceNew:s.forceNew,temporary:s.temporary,projectId:s.projectId,executionMode:t,initialAgentConfig:r??(l?{model:l.modelRef,...l.thinkingLevel?{thinkingLevel:l.thinkingLevel}:{}}:void 0),navigateToSession:(...e)=>{a()&&n.navigateToSession(...e)},replaceNavigate:!0,search:Fa(e.newRouteLocationSearch),onOpened:e=>{a()&&(i?.(e),n.adoptEmptySession(e,null),o(e))}});if(c?.workspaceRoot?.trim()){S({requestKey:w,token:t,baseUrl:b,project:c,agentId:s.agentId,temporary:s.temporary,create:(e,t,n)=>a()?u(e,t,n):Promise.reject(Error(`New chat request changed`))});return}await u()},c=(e,t)=>{if(!a())return Promise.resolve();n.restoreLiveCacheIfNeeded(e);let r=Ln(e)?.messages??t??bn(e);return n.tryResumeAgentRun(e,r)},l=e=>a()?Ln(e)?.historyStatus===`ready`?(o(e),c(e,bn(e))):n.loadSessionById(e,0).then(t=>{if(a())return c(e,t??bn(e))}):Promise.resolve(),u=()=>a()?n.sessionMgrRef.current.loadSessions().then(e=>{if(!a())return;let t=e.filter(e=>(e.messageCount??0)>0)[0]??e[0];if(t)return a()?n.loadSessionById(t.key,0).then(e=>{if(!a())return;n.restoreLiveCacheIfNeeded(t.key);let r=Ln(t.key)?.messages??e??bn(t.key);return n.sessionMgrRef.current.parseSessionFromHash()||n.navigateToSession(t.key,!0),n.tryResumeAgentRun(t.key,r)}):void 0;if(!a())return;let r=n.resolveAgentIdForPost();return Jk({sessionMgr:n.sessionMgrRef.current,agentId:r,currentConversationId:null,routeConversationId:null,navigateToSession:n.navigateToSession,onOpened:e=>{n.adoptEmptySession(e,null),o(e)}}).then(()=>void 0)}):Promise.resolve();return(()=>{let t=e.decodedKey===void 0&&!e.isNewRoute;n.patchInitUi({loading:t,error:null}),(e.isNewRoute?s():e.decodedKey?l(e.decodedKey):u()).then(()=>{a()&&n.patchInitUi({loading:!1})}).catch(e=>{i?a()&&n.patchInitUi({loading:!1}):n.patchInitUi({error:e instanceof Error?e.message:`Chat init failed`,loading:!1})})})(),()=>{i=!0}},[t,b,w]),n&&x?.requestKey===w&&x.token===t&&x.baseUrl===b?x:null}function nA(e){let t=_(e=>e.conversationId),n=_(e=>e.baseUrl),[r,i]=(0,Q.useState)(null),{data:a,error:o}=Qr(e?[`prepared-session-model`,n,t,e.create]:null,async()=>{let t=Jr(Yr(),e.agentId),[n,r]=await Promise.all([hi(),t?.modelRef??_i(e.agentId).then(e=>e.config.models.chat.primary)]),i=n.filter(e=>e.id===r||e.id.endsWith(`/${r}`)),a=n.find(e=>e.id===r)??(i.length===1?i[0]:void 0);return{models:n,selection:{model:a?.id??r,thinkingLevel:a?.thinking?Xr(a.thinking,t?.thinkingLevel,t?.thinkingByModel?.[a.id]):t?.thinkingLevel??`medium`}}},{revalidateOnFocus:!1}),s=r?.preparation===e?r?.selection:a?.selection,c=a?.models.find(e=>e.id===s?.model),l=!!(s?.model&&c),u=r?.preparation===e,d=(0,Q.useRef)({preparation:e,selection:s,ready:l,explicitlySelected:u});d.current={preparation:e,selection:s,ready:l,explicitlySelected:u};let f=(0,Q.useMemo)(()=>e&&{...e,create:async(t,n,r)=>{let i=d.current;if(i.preparation!==e||!i.ready||!i.selection)throw Error(`Model configuration is not ready`);let a=i.selection,o=await e.create(t,a,r);return i.explicitlySelected&&Gr(e.agentId,{modelRef:a.model,thinkingLevel:a.thinkingLevel}),o}},[e]),p=async(t,n)=>{if(!e||!a)throw Error(`Model configuration is not ready`);let r=a.models.find(e=>e.id===t);if(!r)throw Error(`Model is unavailable`);let o=Jr(Yr(),e.agentId)?.thinkingByModel?.[t],c=r.thinking?Xr(r.thinking,n??s?.thinkingLevel,n===void 0?o:void 0):n??s?.thinkingLevel??`medium`;i({preparation:e,selection:{model:t,thinkingLevel:c}})};return{preparation:f,model:s?.model??``,thinkingLevel:s?.thinkingLevel??`medium`,modelSupportsThinking:!!c?.reasoning,ready:l,error:o,onModelChange:e=>p(e),onThinkingChange:e=>p(s?.model??``,e)}}var rA=class{tails=new Map;run(e,t){let n=this.tails.get(e),r=n?n.then(t,t):Promise.resolve().then(t),i=r.finally(()=>{this.tails.get(e)===i&&this.tails.delete(e)});return this.tails.set(e,i),i.catch(()=>{}),r}};async function iA(e){let t=e.trim();if(!t)return!1;try{return!!(await hi()).find(e=>e.id===t)?.reasoning}catch{return!1}}function aA(e){let{sessionMgrRef:t,routeConversationIdRef:n,sendingRef:r,streamingRef:a,loadingSessionRef:o,messagesLenRef:s,thinkingSupportGenRef:c,navigateToSession:l,resolveAgentIdForPost:u,detachForNewConversation:d,conversationId:f,sessionAgentId:p,currentProjectId:m,taskId:h,hasMore:g}=e,_=()=>Sn.getState(),v=(0,Q.useRef)(new rA),y=(0,Q.useRef)(0),b=(0,Q.useRef)(null),x=(0,Q.useRef)(0),S=(0,Q.useCallback)(e=>{let t=_().focusedConversationId;if(!e.trim())return++c.current===c.current&&t&&_().patchSessionMeta(t,{modelSupportsThinking:!1}),Promise.resolve();let n=++c.current;return iA(e).then(t=>{if(n!==c.current)return;let r=_().focusedConversationId;r&&_().sessions[r]?.model===e&&_().patchSessionMeta(r,{modelSupportsThinking:t})})},[c]),C=(0,Q.useCallback)(async e=>{try{let n=await t.current.loadSessionAgentConfig(e);hr(e,n),S(n.model)}catch{}},[t,S]),w=(0,Q.useCallback)(()=>{let e=_().focusedConversationId;if(!e||(_().sessions[e]?.name)?.trim())return;let n=++x.current,r=[700,900,900,1e3,1e3],i=a=>{a>=5||n===x.current&&_().focusedConversationId===e&&(_().sessions[e]?.name?.trim()||window.setTimeout(()=>{n===x.current&&_().focusedConversationId===e&&(_().sessions[e]?.name?.trim()||t.current.fetchSessionName(e).then(t=>{if(n===x.current){if(t){_().patchSessionMeta(e,{name:t});return}i(a+1)}}).catch(()=>{i(a+1)}))},r[a]??900))};i(0)},[t]),T=(0,Q.useCallback)(e=>wk({chatId:e,routeConversationId:n.current}),[n]),E=(0,Q.useCallback)((e,t,n)=>{let r=_().sessions[e];if(n&&r?.messages!==n.messages&&!zn(r))return!1;let i=t.hasMore&&Er(r?.messages??[],t.messages)>0;return _().mergeCommittedFromServer(e,t.messages,t.hasMore,n?.completedRunId),t.name!==void 0&&_().patchSessionMeta(e,{name:t.name||null}),T(e)&&(i||(b.current=t.nextBeforeCursor??null)),!0},[T]),D=(0,Q.useCallback)(async(e,r=0,a)=>{let s=i(`session_load`),c=async(e,r,i)=>{let a=r===0&&!i;y.current++,o.current=!0,s(`request_started`);let d=a&&Cn(_().sessions[e]?.historyStatus);d&&_().setSessionHistoryStatus(e,`loading`);let f=a?Promise.resolve().then(()=>t.current.loadSessionAgentConfig(e)).then(e=>(s(`config_received`),{config:e}),e=>({error:e})):void 0;try{let n={messages:_().sessions[e]?.messages},{messages:o,hasMore:c,name:l,nextBeforeCursor:u}=await t.current.loadSession(e,r,i,h,n.messages);if(s(`history_received`),a){if(!E(e,{messages:o,hasMore:c,name:l,nextBeforeCursor:u},n))return _().sessions[e]?.messages;if(!T(e))return o;s(`history_committed`);let t=await f;if(`error`in t)throw t.error;let r=t.config;return T(e)?(hr(e,r),S(r.model),o):o}if(!T(e))return;b.current=u??null,_().prependHistoryMessages(e,o,c);return}catch(a){if(s(`failed`),n.current&&!T(e))return;if(r===0&&!i){b.current=null;let r=a instanceof Error?a.message:`Failed to load session`;_().setShellError(/^HTTP 404\b/.test(r)?JSON.stringify(Sr(r)):`Failed to load session`);let i=xk(n.current);if(i&&i===e)return;let o=await t.current.loadSessions().catch(()=>[]),s=o.filter(e=>(e.messageCount??0)>0)[0]??o[0];if(s)return l(s.key,!0),await c(s.key,0,null);{b.current=null;let e=u();Jk({sessionMgr:t.current,agentId:e,currentConversationId:null,routeConversationId:null,navigateToSession:l,replaceNavigate:!0,onOpened:e=>{_().setCommittedSnapshot(e,{messages:[],hasMore:!1,name:null}),C(e)}})}}return}finally{y.current--,o.current=y.current>0,s(`settled`),d&&_().sessions[e]?.historyStatus===`loading`&&_().setSessionHistoryStatus(e,`ready`)}};return v.current.run(e,()=>c(e,r,a))},[n,T,r,a,o,l,S,u,t,h,E]),O=(0,Q.useCallback)(async()=>{let e=_().focusedConversationId;if(!(!e||_().loadingMore||!g)){_().setLoadingMore(!0);try{await D(e,s.current,b.current)}finally{_().setLoadingMore(!1)}}},[g,D,s]),k=(0,Q.useCallback)(async(e,n)=>{if(!f)throw Error(`No active session`);let r=_().sessions[f];if(r?.modelConfigSaving)throw Error(`Model configuration is being saved`);if(!(r?.model===e&&n!==void 0&&r.thinkingLevel===n)){_().patchSessionMeta(f,{modelConfigSaving:!0});try{if(_().setShellError(null),n===void 0){let t=(await hi()).find(t=>t.id===e);if(t?.thinking){let i=Jr(Yr(),p)?.thinkingByModel?.[e];n=Xr(t.thinking,r?.thinkingLevel,i)}}let i=h?await t.current.patchTaskConversationModel(h,e,n,r?.configVersion):await t.current.patchSessionAgentConfig(f,{model:e,thinkingLevel:n,configVersion:r?.configVersion});hr(f,i),Gr(p,{modelRef:i.model,thinkingLevel:i.thinkingLevel}),i.model!==r?.model&&S(i.model)}catch(e){let n=e instanceof Error?e.message:`Failed to update model configuration`;_().setShellError(n);let r=await t.current.loadSessionAgentConfig(f).catch(()=>null);throw r&&hr(f,r),e}finally{_().patchSessionMeta(f,{modelConfigSaving:!1})}}},[f,p,h,t,S]);return{refreshModelThinkingSupport:S,pollSessionNameAfterTurn:w,applyLoadedSessionSnapshot:E,loadSessionById:D,loadMoreMessages:O,onSessionModelChange:k,onSessionThinkingLevelChange:(0,Q.useCallback)(async e=>{let t=f?_().sessions[f]?.model:void 0;t&&await k(t,e)},[f,k]),onSessionWorkingDirectoryChange:(0,Q.useCallback)(async e=>{let n=e.trim();if(!(!f||!n))try{_().setShellError(null),await t.current.patchSessionAgentConfig(f,{workingDirectory:n}),await C(f)}catch(e){throw _().setShellError(e instanceof Error?e.message:`Failed to update working directory`),e}},[C,f,t]),createNewSession:(0,Q.useCallback)(async e=>{_().setShellError(null);let n=u(),r=Jr(Yr(),n??`main`);await Jk({sessionMgr:t.current,agentId:n,currentConversationId:f,routeConversationId:f,forceNew:e?.forceNew,temporary:e?.temporary,executionMode:e?.executionMode,projectId:e?.projectId===void 0?m:e.projectId,initialAgentConfig:r?{model:r.modelRef,...r.thinkingLevel?{thinkingLevel:r.thinkingLevel}:{}}:void 0,navigateToSession:l,onOpened:e=>{d(),b.current=null,_().setCommittedSnapshot(e,{messages:[],hasMore:!1,name:null}),C(e)}})},[d,l,u,m,f,t,C]),resetCurrentSession:(0,Q.useCallback)(async()=>{if(f){_().setShellError(null);try{await t.current.resetSession(f),d(),b.current=null,_().setCommittedSnapshot(f,{messages:[],hasMore:!1,name:null}),C(f)}catch(e){_().setShellError(e instanceof Error?e.message:`Failed to reset session`)}}},[C,f,d,t])}}function oA(e){return new Promise(t=>{Promise.resolve().then(()=>e(()=>t(!0))).then(()=>t(!1),()=>t(!1))})}function sA(e,t,n){return e.map(e=>{if(e.clientSubmissionId!==t||!e.deliveryStatus)return e;if(n===`failed`)return{...e,deliveryStatus:`failed`};let r={...e,deliveryStatus:`accepted`};return delete r.pendingAppContext,r})}function cA(e){return e!==`suspended`}function lA(e){let{chatId:t,shouldApplyStreamUpdate:n,beforeAssistantDelta:r,reconcileHydratedAssistantText:i,setStreamingOnStreamStart:a,clearResumeRunIdOnBackgroundTerminal:o,clearResumeRunIdOnVisibleError:s,setError:c,sessionMgrRef:l,applyLoadedSessionSnapshot:u,finalizeMessage:d,fq:f}=e,p=e.isCurrentRun??(()=>!0),m=()=>Sn.getState(),h=()=>{m().sessions[t]?.progress?.stage.startsWith(`model_`)&&m().setSessionProgress(t,null)},g=e=>{let n=e?.runId,r={messages:m().sessions[t]?.messages,completedRunId:e?.terminal?n:void 0};return l.current.loadSession(t,0,void 0,void 0,r.messages).then(i=>{!p()||e?.signal.aborted||u(t,i,r)===!1||n&&m().sessions[t]?.messages.some(e=>e.role===`assistant`&&e.turnId===n&&e.content.some(e=>e.type===`text`&&e.text.trim()&&e.text.trim()!==`NO_REPLY`))&&xr(n,`history`)}).catch(()=>{})},_=new Map,y,b=()=>{if(y!==void 0&&(window.clearTimeout(y),y=void 0),!p()){_.clear();return}if(_.size===0)return;let e=Array.from(_.entries());_.clear(),r(),m().mutateSessionStreaming(t,t=>{for(let[n,r]of e)cr(t.content,n,r)})},x=(e,t)=>{_.set(e,`${_.get(e)??``}${t}`),y===void 0&&(y=window.setTimeout(b,120))},C=e=>{m().clearStreamingState(t),o&&kn.setResumeRunId(t,null),m().setSessionFlags(t,{sending:!1,streaming:!1}),m().setSessionProgress(t,null),cA(e)&&f.dismissClarifyForSession(t),g()},w={onTextSurface:e=>{r(),m().mutateSessionStreaming(t,t=>{t.textSurface=e})},onReplayGap:g,onUserMessage:e=>{n(t)&&m().appendUserMessageIfMissing(t,e)},onStreamStart:(e,n,i)=>{Xf(t),r(),i&&m().updateSessionMessages(t,t=>er([...t,{role:`task`,content:[],taskTrigger:i,turnId:e,timestamp:Date.now()}])),m().updateSessionMessages(t,t=>Gn(t,e)),m().mutateSessionStreaming(t,t=>{t.turnId=e,n&&(t.startsNewBubble=!0)}),m().setSessionFlags(t,{streaming:!0})},onToken:(e,a,o)=>{h(),r(),m().mutateSessionStreaming(t,t=>{vn(t.content,e,a,{offset:o,reconcileHydratedSegment:i})}),n(t)&&m().setSessionFlags(t,{streaming:!0})},onAssistantMessageEnd:(e,n,i)=>{r(),m().mutateSessionStreaming(t,t=>{Hn(t.content,e,n),i&&(t.usage=i)})},onThinking:(e,n,i)=>{h(),r(),m().mutateSessionStreaming(t,t=>{!n&&e===``?Un(t.content):sr(t.content,e,n,i)})},onThinkingEnd:e=>{r(),m().mutateSessionStreaming(t,t=>{Ar(t.content,e)})},onToolStart:(e,n,i,a,o,s)=>{h(),r(),m().mutateSessionStreaming(t,t=>{jn(t.content,e,n,i,a,o,s)}),m().setSessionFlags(t,{streaming:!0})},onToolEnd:(e,n,i,a,o,s,c)=>{r(),m().mutateSessionStreaming(t,t=>{Pn(t.content,e,n,i,a,o,s,c)})},onToolUpdate:(e,n,i)=>{r(),m().mutateSessionStreaming(t,t=>{Tn(t.content,e,n,i)})},onTaskPlanUpdated:e=>{m().setSessionTaskPlan(t,e)},onTurnOutcome:e=>{r(),m().mutateSessionStreaming(t,t=>{t.outcome=e})},onReview:({review:e})=>{r(),m().mutateSessionStreaming(t,t=>{Nn(t.content,e)}),n(t)&&m().setSessionFlags(t,{streaming:!0})},onReviewStart:e=>{r(),m().mutateSessionStreaming(t,t=>{Vn(t.content,e)}),n(t)&&m().setSessionFlags(t,{streaming:!0})},onReviewDelta:({reviewId:e,delta:t})=>{x(e,t)},onReviewEnd:({reviewId:e,status:n,message:i})=>{b(),r(),m().mutateSessionStreaming(t,t=>{yn(t.content,e,n,i)})},onProgress:e=>{m().setSessionProgress(t,e)},onTtsAudio:e=>{n(t)&&m().appendAttachmentToCurrentAssistant(t,{name:e.name,mimeType:e.mimeType,type:`voice`,uri:e.uri,size:0},{attachTo:e.attachTo,messageId:e.messageId})},onCompaction:e=>{if(!n(t))return;let r=S(v.getState().language).chat;if(e.status===`started`)m().setSessionProgress(t,{stage:`compaction`,message:r.compactingContext,timestamp:Date.now()});else if(e.status===`completed`){let n=e.tokensBefore&&e.tokensAfter?` (${r.contextTokensFreed.replace(`{{count}}`,String(Math.round((e.tokensBefore-e.tokensAfter)/1e3)))})`:``;m().setSessionProgress(t,{stage:`compaction`,message:`${r.contextCompacted}${n}`,timestamp:Date.now()})}else m().setSessionProgress(t,null)},onClarifyRequest:f.makeOnClarifyRequest(t),onSessionConfigUpdated:()=>{m().patchSessionMeta(t,{modelConfigSaving:!0}),l.current.loadSessionAgentConfig(t).then(e=>hr(t,e)).catch(()=>{}).finally(()=>m().patchSessionMeta(t,{modelConfigSaving:!1}))},onResult:({status:e})=>{b();let r=n(t);if(kn.takeUserAborted(t)||e===`cancelled`){$f(t),r?d(t,e):C(e);return}if(e===`error`){if(Qf(t,!r),!r){C(e);return}d(t,e),g();return}if(e===`suspended`?ep(t):Zf(t,!r),!r){C(e);return}d(t,e)},onError:e=>{b();let r=n(t);if(Qf(t,!r),!r){C(`error`);return}d(t,`error`),s&&kn.setResumeRunId(t,null),m().setSessionFlags(t,{sending:!1,streaming:!1}),m().setSessionProgress(t,null),c(e),f.dismissClarifyForSession(t)}};return Object.fromEntries(Object.entries(w).map(([e,t])=>[e,(...e)=>{if(p())return Reflect.apply(t,void 0,e)}]))}function uA(e){return Ln(e)?.streamingMsg??null}var dA=80;function fA(e){let t=e.trim();(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))&&(t=t.slice(1,-1).trim());let n=t.indexOf(`
71
- `);return n!==-1&&(t=t.slice(0,n).trim()),t.length>dA&&(t=t.slice(0,dA-1).trimEnd()+`…`),t}function pA(e){let t=e.trimStart();if(!/^##\s+Skill:\s*\S+/i.test(t))return e;let n=/(?:^|\r?\n)\*\*Arguments\*\*:\s*/gi,r=-1;for(;n.exec(t)!==null;)r=n.lastIndex;if(r!==-1){let e=t.slice(r).trim();if(e)return e}return(t.split(/\r?\n/)[0]?.trim()??``).replace(/^##\s+Skill:\s*/i,``).trim()}function mA(e){let t=e.trimStart().match(/^\/skill:([^\s]+)(?:\s+([\s\S]*))?$/i);return t&&(t[2]?.trim()||t[1]?.trim())||e}function hA(e){let t=mA(pA(Wn([{type:`text`,text:e}]))).split(/\n/)[0]?.trim();if(!t)return null;let n=fA(t);return n.length>0?n:null}function gA(e,t){let n=e.trim(),r=t.trim();!n||!r||window.dispatchEvent(new CustomEvent(`session-updated`,{detail:{key:n,name:r},bubbles:!0}))}var _A=new Set([`new`,`reset`,`restart`]),vA=new Set([..._A,`clear`,`archive`]);function yA(e){let t=e.trim(),n=/^\/([^\s@]+)(?:@[^\s]+)?(?:\s+([\s\S]*))?$/.exec(t);return n?{name:n[1].toLowerCase(),args:n[2]?.trim()??``}:null}function bA(e){let t=yA(e);return!!(t&&_A.has(t.name)&&!t.args)}function xA(e){let t=yA(e);return!!(t&&vA.has(t.name))}function SA(e){let{conversationId:t,taskId:n,thinkingLevel:r,modelSupportsThinking:i,conversationIdRef:a,sendingRef:o,streamingRef:s,sessionMgrRef:c,sendMessageRef:l,shouldApplyStreamUpdate:u,fq:d,applyLoadedSessionSnapshot:f,loadSessionById:p,resetCurrentSession:m,pollSessionNameAfterTurn:h}=e,g=()=>Sn.getState(),v=e=>g().setShellError(e),y=()=>g().setShellError(null),b=(0,Q.useCallback)((e,t)=>{let n=e??a.current;if(n&&!u(n))return;let r=n?uA(n):null,i=null;if(r){let e=wn(r,Date.now());e.runStatus=t,Dn(e.content,t===`success`),Ar(e.content),t!==`suspended`&&In(e.content,t===`success`),An(e.content),e.completedAt=t&&t!==`suspended`?Date.now():void 0,i=Mn(e)}i&&En(i)&&n?g().finalizeStreamingTurn(n,i):n&&g().clearStreamingState(n),o.current=!1,s.current=!1,n&&kn.resetRunTracking(n),(!t||cA(t))&&d.dismissClarify(),h();let c=a.current;c&&window.setTimeout(()=>{a.current===c&&(o.current||s.current||p(c,0))},400)},[o,s,a,d.dismissClarify,d.pendingFollowUpsRef,h,p,u]),x=(0,Q.useCallback)(async(e,t)=>{if(!u(e)||kn.isSubmittingFor(e))return;let r=_.getState().conversationId,i=()=>_.getState().conversationId===r,a=kn.getGeneration(e),l=g().sessions[e]?.streamingMsg,m=g().sessions[e]?.messages.findLast(e=>e.role===`user`)?.clientSubmissionId,h=await gr(e);if(!i()||kn.getGeneration(e)!==a||kn.isSubmittingFor(e))return;if(!h){let t=g().sessions[e]?.streamingMsg;if(t?.pendingResponseStatus||t&&t!==l||kn.isStreamingFor(e))return;let n=kn.getResumeRunId(e);n&&kn.reconcileInactive(e,n),g().clearStreamingState(e,{preservePendingResponse:!0}),$f(e);return}let y=()=>{let t=g().sessions[e]?.streamingMsg,n=g().sessions[e]?.messages.findLast(e=>e.role===`user`)?.clientSubmissionId;return!i()||kn.getGeneration(e)!==a||kn.isSubmittingFor(e)||!!(n&&n!==m)||!!(Zn(e)&&Zn(e)!==h)||!!(t?.turnId&&t.turnId!==h&&t.turnId!==l?.turnId)||!!(t?.pendingResponseStatus&&t!==l)};if(y()||kn.isTrackingRun(e,h))return;let x=()=>{let t=g().sessions[e]?.streamingMsg;!t?.turnId||t.turnId===h||t.turnId!==l?.turnId||(En(t)?g().finalizeStreamingTurn(e,Mn(t)):g().clearStreamingState(e))},S=t??bn(e),C=Ln(e)?.hasMore??!1;try{let t=await c.current.loadSession(e,0,void 0,n,g().sessions[e]?.messages);if(y()||kn.isTrackingRun(e,h))return;x(),g().mergeCommittedFromServer(e,t.messages,t.hasMore),S=t.messages,C=t.hasMore}catch{}if(y()||kn.isTrackingRun(e,h))return;x(),a=kn.advanceGeneration(e),kn.setUserAborted(e,!1),kn.setResumeRunId(e,h),o.current=!0,s.current=!0,g().seedSessionIfEmpty(e,S,!0,!0,C),g().setSessionFlags(e,{sending:!0,streaming:!0}),g().setSessionProgress(e,null),Xf(e);let w=!1,T=()=>{if(w||!u(e))return;w=!0;let t=Ok(bn(e),h);t&&g().applyHydratedTail(e,t.messagesWithoutTail,Mn(t.tail))},E=()=>{g().clearStreamingState(e),kn.getResumeRunId(e)===h&&kn.setResumeRunId(e,null),u(e)&&(o.current=!1,s.current=!1)};try{let t=lA({chatId:e,shouldApplyStreamUpdate:u,isCurrentRun:()=>i()&&kn.getGeneration(e)===a,beforeAssistantDelta:T,reconcileHydratedAssistantText:!0,setStreamingOnStreamStart:!1,clearResumeRunIdOnBackgroundTerminal:!0,clearResumeRunIdOnVisibleError:!0,setError:v,sessionMgrRef:c,applyLoadedSessionSnapshot:f,finalizeMessage:b,fq:d}),n=await kn.senderFor(e).resume(h,e,t,{replayFromStart:l?.turnId!==h||!En(l)});if(!i()||kn.getGeneration(e)!==a)return;n||($f(e),E(),await p(e,0).catch(()=>void 0))}catch(t){if(!i()||kn.getGeneration(e)!==a)return;t.name!==`AbortError`&&console.error(`[chat] resume failed:`,t),$f(e),E()}finally{kn.releaseIdleSender(e)}},[o,s,u,c,f,b,p,n]),S=(0,Q.useCallback)(async(e,t,r,i)=>{if(!e.trim()&&!t?.length&&!i?.length)return!1;let c=a.current;if(!c||!o.current&&!s.current&&!kn.isStreamingFor(c))return!1;let l=e.trim();if(n&&xA(l))return v(`A task has one continuous conversation.`),!1;if(bA(l)&&!t?.length){await m();return}return await d.addPendingFollowUp(e,t,i,void 0,!0),!0},[o,s,a,d.addPendingFollowUp,m,n]),C=(0,Q.useCallback)(async(e,a,l,h,x,S,C,w,T)=>{if(!t||!u(t)||!e.trim()&&!a?.length&&!h?.length||o.current||s.current||kn.isStreamingFor(t))return!1;let E=e.trim();if(n&&xA(E))return v(`A task has one continuous conversation.`),!1;if(bA(E)&&!a?.length){await m();return}let D=i?l??r:`off`,O=t,k=kn.advanceGeneration(O),A=_.getState().conversationId,j=()=>_.getState().conversationId===A&&kn.getGeneration(O)===k,M=crypto.randomUUID(),N=`assistant-stream:${O}:${M}`,P=bn(O),F=w?P.filter(e=>e.clientSubmissionId!==w):P,I=x?F.findIndex(e=>e.role===`user`&&e.turnId===x):-1;if(x&&I<0)return!1;kn.setUserAborted(O,!1),o.current=!0,s.current=!1,y(),d.dismissClarify();let L=I>=0?F.slice(0,I):F,R=Rn(e)??void 0,z=new Map(h?.flatMap(e=>e.refId?[[e.refId,e.title]]:[])??[]),B=R?xn(R,e=>z.get(e)):e,ee=[...L,{role:`user`,content:B?[{type:`text`,text:B}]:[],userTurnDocument:R,deliveryStatus:`sending`,clientSubmissionId:M,pendingAppContext:S===void 0?void 0:structuredClone(S),attachments:a,contextRefs:h?.map(e=>({refId:e.refId,kind:e.kind,sourceId:e.sourceId,version:e.expectedVersion,title:e.title,fileKind:e.fileKind})),timestamp:Date.now()}];C?.(M);let V=Ln(O);if(g().initSessionSnapshot(O,{...V??{...On(),historyStatus:`ready`,hasMore:!1,streamingMsg:null,progress:null,taskPlan:null,sending:!1,streaming:!1},messages:ee,hasMore:V?.hasMore??!1,streamingMsg:{role:`assistant`,content:[],timestamp:Date.now(),renderKey:N,pendingResponseStatus:`sending`},progress:null,sending:!0,streaming:!1}),Xf(O),!V?.name?.trim()&&B.trim()){let e=hA(B.trim());e&&(g().patchSessionMeta(O,{name:e}),gA(O,e))}let H=e=>{g().updateSessionMessages(O,t=>sA(t,M,e))};return oA(async t=>{let r=!1;try{let i=lA({chatId:O,shouldApplyStreamUpdate:u,isCurrentRun:j,beforeAssistantDelta:()=>{},reconcileHydratedAssistantText:!1,setStreamingOnStreamStart:!0,clearResumeRunIdOnBackgroundTerminal:!1,clearResumeRunIdOnVisibleError:!1,setError:v,sessionMgrRef:c,applyLoadedSessionSnapshot:f,finalizeMessage:b,fq:d});i.onInputAccepted=()=>{r=!0,H(`accepted`),j()&&g().setPendingResponseStatus(O,`waiting`),t()},await kn.senderFor(O).send(e,O,a,D,i,n,x,h,S,T)}catch(e){if(!j())return;if(e.name!==`AbortError`)g().clearStreamingState(O),$f(O),u(O)&&v(e instanceof Error?e.message:String(e)),x&&p(O,0);else{$f(O);let e=Ln(O)?.streamingMsg;e?.renderKey===N&&e.pendingResponseStatus&&g().clearStreamingState(O)}}finally{j()&&(r||H(`failed`),u(O)&&(o.current=!1,s.current=!1),g().setSessionFlags(O,{sending:!1}),kn.releaseIdleSender(O))}})},[t,r,i,o,s,u,c,f,b,d.dismissClarify,m,n,p]),w=(0,Q.useCallback)((e,t,n,r,i,a)=>C(t,n,r,i,e,void 0,void 0,void 0,a),[C]),T=(0,Q.useCallback)((e,t)=>{let n=a.current;if(!n||mr(n).phase!==`idle`||kn.getGeneration(n)!==e)return;let r=kn.getResumeRunId(n),i=g().sessions[n]?.streamingMsg?.turnId;r&&r!==t||i&&i!==t||(d.dismissClarify(),kn.abort(n,!1),$f(n),o.current=!1,s.current=!1,b(n,`cancelled`),p(n,0))},[d.dismissClarify,o,s,b,a,p]);return{finalizeMessage:b,tryResumeAgentRun:x,sendMessage:C,replaceLatestUserTurn:w,interruptAndSend:S,abort:(0,Q.useCallback)(async()=>{let e=a.current;if(!e)return;let t=kn.getGeneration(e),n=kn.getResumeRunId(e)??g().sessions[e]?.streamingMsg?.turnId??null;await d.stopSession(),a.current===e&&T(t,n)},[d.stopSession,a,T]),settleStoppedRun:T,deleteMessageRound:(0,Q.useCallback)(e=>{let t=a.current;if(!t||o.current||s.current)return;let n=bn(t),r=n[e];if(!r||!_n(r.role))return;if(r.deliveryStatus===`failed`){let r=[...n];r.splice(e,1),g().updateSessionMessages(t,()=>r);return}let i=br(n,e);if(i===null)return;let l=tr(n,e),u=[...n];u.splice(e,l),g().updateSessionMessages(t,()=>u),c.current.deleteMessages(t,{userRoundIndex:i}).catch(()=>{p(t,0)})},[a,o,s,c,p]),retryUserMessageRound:(0,Q.useCallback)(e=>{let t=a.current;if(!t||o.current||s.current)return;let n=bn(t),r=n[e];if(!r||!_n(r.role))return;for(let t=e+1;t<n.length;t++){let e=n[t];if(e&&_n(e.role))return}let i=r.userTurnDocument?Tr(r.userTurnDocument):Wn(r.content),c=Kn(r.attachments);if(!i.trim()&&!c?.length&&!r.contextRefs?.length)return;let u=r.contextRefs?.flatMap(e=>e.kind===`mcp_resource`?[]:[{refId:e.refId,kind:e.kind,sourceId:e.sourceId,expectedVersion:e.version,title:e.title,fileKind:e.fileKind}]),d=r.deliveryStatus===`failed`?r.clientSubmissionId:void 0;!d&&!r.turnId||l.current(i,c,void 0,u,r.turnId,r.pendingAppContext,void 0,d).catch(()=>{p(t,0)})},[a,o,s,p,l])}}function CA(e){let t=(0,X.c)(11),{conversationId:n,conversationIdRef:r,sessionMgrRef:i,loadSessionById:a,loadTimelineById:o,applyAgentConfig:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=[],t[0]=c):c=t[0],(0,Q.useEffect)(TA,c);let l,u;t[1]!==n||t[2]!==a||t[3]!==o?(l=()=>{let e=e=>{let t=e.detail;!t?.key||t.key!==n||(a(n,0),o(n))};return window.addEventListener(`session-transcript-updated`,e),()=>window.removeEventListener(`session-transcript-updated`,e)},u=[n,a,o],t[1]=n,t[2]=a,t[3]=o,t[4]=l,t[5]=u):(l=t[4],u=t[5]),(0,Q.useEffect)(l,u);let d,f;t[6]!==s||t[7]!==r||t[8]!==i?(d=()=>{let e=e=>{if(oi(e.detail))return;let t=r.current;t&&i.current.loadSessionAgentConfig(t).then(e=>{s(t,e)}).catch(wA)};return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},f=[r,i,s],t[6]=s,t[7]=r,t[8]=i,t[9]=d,t[10]=f):(d=t[9],f=t[10]),(0,Q.useEffect)(d,f)}function wA(){}function TA(){let e=EA;return window.addEventListener(`session-updated`,e),()=>window.removeEventListener(`session-updated`,e)}function EA(e){let t=e.detail;!t?.key||t.name===void 0||Sn.getState().patchSessionMeta(t.key,{name:t.name||null})}function DA(e){let t=m(),{isNewRoute:n,forceNewChat:r,decodedKey:i,viewConversationId:a,routedFocusedConversationId:o,routeConversationIdRef:s,locationKey:c,locationSearch:l,locationState:u}=Qk(e?.fixedConversationId),d=(0,Q.useRef)(new yr),f=(0,Q.useRef)(!1),p=(0,Q.useRef)(!1),h=(0,Q.useRef)(!1),g=(0,Q.useRef)(0),_=(0,Q.useRef)(!1),[v,y]=(0,Q.useState)([]),b=(0,Q.useRef)(async()=>{}),x=(0,Q.useRef)(0),S=o,C=Sn(e=>e.initLoading),w=Sn(e=>e.loadingMore),T=Sn(e=>e.shellError),E=a,D=Qm(E),O=E?zn(D):!1,k=O?D?.streaming??!1:!1,A=O?D?.sending??!1:!1,j=O?D?.progress??null:null,M=O?D?.taskPlan??null:null,N=D?.hasMore??!1,P=D?.name??null,F=D?.model??``,I=Ak(D,Qr(gi,hi,{revalidateOnFocus:!1}).data),L=D?.modelConfigSaving??!1,R=D?.thinkingLevel??`medium`,z=D?.reasoningLevel??`on`,B=D?.modelSupportsThinking??!1,ee=D?.effectiveWorkspacePath??``,V=D?.workspaceSource??`agent_default_root`,H=D?.userContextMode??`enabled`;(0,Q.useEffect)(()=>{!E||A||k||d.current.loadSessionAgentConfig(E).then(e=>hr(E,e)).catch(()=>void 0)},[E,A,k]),(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail.conversationId;d.current.loadSessionAgentConfig(t).then(e=>hr(t,e)).catch(()=>void 0)};return window.addEventListener(`session-model-config-stale`,e),()=>window.removeEventListener(`session-model-config-stale`,e)},[]),(0,Q.useEffect)(()=>{x.current=D?.messages.length??0},[D?.messages.length]),(0,Q.useEffect)(()=>{p.current=A,h.current=k},[A,k]);let{token:U,chatAgentsData:W,resolveAgentIdForPost:te,onChatAgentChange:ne,displayAgentId:re,showChatAgentSelector:ie,currentSessionProjectId:ae}=Bk({navigate:t,personal:e?.personal,conversationIdRef:eA,conversationId:S,isNewRoute:n,locationState:u,locationSearch:l}),oe=i!==void 0&&S!==i,se=!!(i&&D?.historyStatus===`loading`&&!oe),ce=(0,Q.useMemo)(()=>C&&(S==null||i===void 0),[C,S,i]),le=Mk({isNewRoute:n,sessionRoutePending:oe,showSessionLoading:ce,sessionContentLoading:se,messageCount:D?.messages.length??0}),ue=(0,Q.useCallback)((e,n=!1,r)=>{let i=r??``;t({pathname:`/chat/${encodeURIComponent(e)}`,search:i},{replace:n})},[t]),de=(0,Q.useCallback)(e=>Sk({streamConversationId:e,routeConversationId:s.current}),[s]),G=(0,Q.useCallback)(()=>{jk({sendingRef:p,streamingRef:h})},[]),K=Rk({conversationId:S,decodedKey:i,conversationIdRef:eA,sendingRef:p,streamingRef:h,modelSupportsThinking:B,thinkingLevel:R,shouldApplyStreamUpdate:de}),fe=(0,Q.useCallback)(()=>{K.clearVisibleClarify();let e=eA.current;e&&kn.resetRunTracking(e),kk(G)},[K.clearVisibleClarify,eA,G]),{refreshModelThinkingSupport:q,pollSessionNameAfterTurn:pe,applyLoadedSessionSnapshot:me,loadSessionById:J,loadMoreMessages:he,onSessionModelChange:ge,onSessionThinkingLevelChange:_e,onSessionWorkingDirectoryChange:ve,createNewSession:ye,resetCurrentSession:be}=aA({sessionMgrRef:d,routeConversationIdRef:s,sendingRef:p,streamingRef:h,loadingSessionRef:f,messagesLenRef:x,thinkingSupportGenRef:g,navigateToSession:ue,resolveAgentIdForPost:te,detachForNewConversation:fe,conversationId:S,sessionAgentId:re,currentProjectId:ae,hasMore:N,taskId:e?.taskId}),xe=(0,Q.useCallback)(e=>{if(!Ck({cacheConversationId:e,routeConversationId:s.current}))return!1;let t=Ln(e);return!t||!zn(t)&&!pr(e)&&!kn.isStreamingFor(e)?!1:(p.current=t.sending,h.current=t.streaming,!0)},[s]),{tryResumeAgentRun:Se,sendMessage:Ce,replaceLatestUserTurn:we,interruptAndSend:Te,abort:Ee,settleStoppedRun:De,deleteMessageRound:Oe,retryUserMessageRound:ke}=SA({conversationId:S,taskId:e?.taskId,thinkingLevel:R,modelSupportsThinking:B,conversationIdRef:eA,sendingRef:p,streamingRef:h,sessionMgrRef:d,sendMessageRef:b,shouldApplyStreamUpdate:de,fq:K,applyLoadedSessionSnapshot:me,loadSessionById:J,resetCurrentSession:be,pollSessionNameAfterTurn:pe});(0,Q.useEffect)(()=>{n&&fe()},[n,fe]);let Ae=(0,Q.useMemo)(()=>Dk({viewConversationId:a,conversationId:E,messages:D?.messages??[],streamingMsg:O?D?.streamingMsg??null:null}),[a,E,D?.messages,D?.streamingMsg,O]),je=(0,Q.useCallback)((e,t)=>{Sn.getState().setCommittedSnapshot(e,{messages:[],hasMore:!1,name:t}),G()},[G]),Me=(0,Q.useCallback)((e,t)=>{hr(e,t),q(t.model)},[q]),Ne=(0,Q.useCallback)(e=>{let t=Sn.getState();e.loading!==void 0&&t.setInitLoading(e.loading),e.error!==void 0&&t.setShellError(e.error)},[]),Pe=(0,Q.useCallback)(async t=>{try{let n=await d.current.loadTimeline(t,e?.taskId);if(s.current!==t)return;y(n)}catch{s.current===t&&y([])}},[s,e?.taskId]);(0,Q.useEffect)(()=>{if(n||!S){y([]);return}Pe(S)},[S,n,Pe]),CA({conversationId:S,conversationIdRef:eA,sendingRef:p,streamingRef:h,sessionMgrRef:d,loadSessionById:J,loadTimelineById:Pe,applyAgentConfig:Me});let Fe=tA({token:U,isNewRoute:n,forceNewChat:r,temporary:u?.temporary===!0,requestedAgentId:typeof u?.agentId==`string`?u.agentId:void 0,decodedKey:i,locationKey:c,locationSearch:l,sessionMgrRef:d,resolveAgentIdForPost:te,navigateToSession:ue,loadSessionById:J,tryResumeAgentRun:Se,restoreLiveCacheIfNeeded:xe,adoptEmptySession:je,applyAgentConfig:Me,patchInitUi:Ne}),Ie=nA(Fe);return(0,Q.useEffect)(()=>{Fe&&Ie.error&&Sn.getState().setShellError(Ie.error instanceof Error?Ie.error.message:`Failed to load model configuration`)},[Fe,Ie.error]),(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail,n=t?.conversationId,r=t?.runId;!n||!r?.trim()||(lr(n,r),kn.setResumeRunId(n,r),de(n)&&(kn.isTrackingRun(n,r)||queueMicrotask(()=>{de(n)&&(kn.isTrackingRun(n,r)||Se(n,bn(n)))})))};return window.addEventListener(`run-started`,e),()=>window.removeEventListener(`run-started`,e)},[Se,de]),(0,Q.useEffect)(()=>{let e=k||A,t=_.current;if(_.current=e,!t||e)return;let n=eA.current;n&&queueMicrotask(()=>{!n||!de(n)||kn.isStreamingFor(n)||pr(n)&&Se(n,bn(n))})},[k,A,Se,de]),b.current=Ce,{auth:{hasToken:!!U},session:{projectPreparation:Ie.preparation,conversationId:S,sessionName:P,decodedKey:i,sessionRoutePending:oe,sessionContentLoading:se,showSessionLoading:ce,conversationPhase:le,loading:C,sessionModel:Fe?Ie.model:F,modelConfigReady:Fe?Ie.ready:I,modelConfigSaving:L,thinkingLevel:Fe?Ie.thinkingLevel:R,onSessionThinkingLevelChange:Fe?Ie.onThinkingChange:_e,onSessionWorkingDirectoryChange:ve,reasoningLevel:z,modelSupportsThinking:Fe?Ie.modelSupportsThinking:B,effectiveWorkspacePath:ee,workspaceSource:V,userContextMode:Fe?.temporary?`temporary`:H,hasMore:N,loadingMore:w,loadMoreMessages:he,onSessionModelChange:Fe?Ie.onModelChange:ge,createNewSession:ye,sessionManager:d.current},messages:{items:Ae},timeline:{items:v,refresh:Pe},stream:{error:T,streaming:k,sending:A,progress:j,taskPlan:M,sendMessage:Ce,replaceLatestUserTurn:we,abort:Ee,settleStoppedRun:De,interruptAndSend:Te,deleteMessageRound:Oe,retryUserMessageRound:ke},followUp:{composerMode:K.composerMode,control:K.control,controlPending:K.controlPending,beginEditTurn:K.beginEditTurn,cancelEditor:K.cancelEditor,restoreEditor:K.restoreEditor,markComposerHydrated:K.markComposerHydrated,resumeQueue:K.resumeQueue,sendQueuedInput:K.sendQueuedInput,addPendingFollowUp:K.addPendingFollowUp,pendingFollowUps:K.pendingFollowUps,editingFollowUpId:K.editingFollowUpId,beginEditFollowUp:K.beginEditFollowUp,cancelEditFollowUp:K.cancelEditFollowUp,commitEditFollowUp:K.commitEditFollowUp,removePendingFollowUp:K.removePendingFollowUp,movePendingFollowUp:K.movePendingFollowUp,reorderPendingFollowUp:K.reorderPendingFollowUp,steerPendingFollowUp:K.steerPendingFollowUp,steeringFollowUpId:K.steeringFollowUpId},clarify:{clarifyPrompt:K.clarifyPrompt,clarifySubmitting:K.clarifySubmitting,clarifySubmitError:K.clarifySubmitError,submitClarifyAnswer:K.submitClarifyAnswer,letAgentDecideClarification:K.letAgentDecideClarification,cancelClarification:K.cancelClarification},agents:{chatAgents:W,displayAgentId:Fe?.agentId??re,showChatAgentSelector:ie,onChatAgentChange:ne}}}function OA(e){let t=(0,X.c)(11),n=_(kA),r;t[0]===e?r=t[1]:(r=e?.trim()||null,t[0]=e,t[1]=r);let i=r,a;t[2]===i?a=t[3]:(a=e=>i?e.sessions[i]?.localDraft:void 0,t[2]=i,t[3]=a);let o=Sn(a),s;t[4]!==o||t[5]!==n||t[6]!==i?(s=n&&i&&!o?[`chat-session-meta`,i,n,o===!1?`persisted`:`unknown`]:null,t[4]=o,t[5]=n,t[6]=i,t[7]=s):s=t[7];let c;t[8]===i?c=t[9]:(c=async()=>{if(await jr(i))return;let e=await hn(i),t=typeof e.sessionType==`string`&&e.sessionType.trim()?e.sessionType.trim():null,n=typeof e.routing?.agentId==`string`&&e.routing.agentId.trim()?e.routing.agentId.trim():null,r=e.customData?.sourceBinding,a=r&&typeof r==`object`?r:null,o=a?.kind===`note`&&typeof a.sourceId==`string`&&a.sourceId.trim()?a.sourceId.trim():null,s=typeof e.parentConversationId==`string`&&e.parentConversationId.trim()?e.parentConversationId.trim():null,c=e.customData?.forkedFromSessionName;return{identity:{sourceChannel:e.sourceChannel,sessionType:e.sessionType,customData:e.customData},ownerAgentId:n,sessionType:t,sourceNoteId:o,sourceNoteTitle:null,parentConversationId:s,forkedFromSessionName:typeof c==`string`&&c.trim()?c.trim():null}},t[8]=i,t[9]=c);let l;return t[10]===Symbol.for(`react.memo_cache_sentinel`)?(l={revalidateOnFocus:!1},t[10]=l):l=t[10],Qr(s,c,l)}function kA(e){return e.conversationId}function AA(e,t){if(!e)return``;let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,Math.max(0,t-3)).trimEnd()}...`}function jA(e,t){return AA(Fn(e??``),t)}function MA(e,t){return da(e,t)}function NA(e){return e===`context`||e===`branch`||e===`compaction`?e:null}function PA(e){return AA(e.preview||e.title,72)||e.kind}function FA(e,t){let n=[],r=null,i=0;for(let a of e){if(a.displayIndex!==void 0&&(i=a.displayIndex),a.kind===`turn`&&a.role===`user`){let e=a.turn||n.length+1;r={id:a.id,messageIndex:a.displayIndex??i,ordinal:e,title:t.turn.replace(`{{count}}`,String(e)),preview:jA(a.preview||a.title,88)||t.messageFallback,...a.timestamp===void 0?{}:{timestamp:a.timestamp},tools:[],events:[]},n.push(r);continue}if(!r)continue;if(a.kind===`tool`||a.kind===`file`||a.kind===`command`){let e=a.meta?.toolName||a.title||a.kind,n=a.kind===`file`||a.kind===`command`?a.title:MA(e,t),i=`${a.id}:${e}`;r.tools.some(e=>e.key===i)||r.tools.push({key:i,label:n,running:a.status===`running`});continue}let e=NA(a.kind);if(!e)continue;let o=`${a.id}:${a.kind}`;r.events.some(e=>e.key===o)||r.events.push({key:o,label:PA(a),tone:e})}return n}function IA(e,t){return(e===1?t.toolCount_one:t.toolCount_other).replace(`{{count}}`,String(e))}function LA(e,t){let n=e[0]?.id;for(let r of e)r.messageIndex<=t&&(n=r.id);return n}function RA(e){let t=(0,X.c)(53),{turn:n,active:r,labels:i,currentLabel:a,onSelect:o}=e,s,c,l,u,d,f,p,m;if(t[0]!==r||t[1]!==a||t[2]!==i||t[3]!==o||t[4]!==n.events||t[5]!==n.preview||t[6]!==n.timestamp||t[7]!==n.title||t[8]!==n.tools){let e=n.tools.slice(0,2),h=n.events.slice(0,Math.max(0,3-e.length)),g=Math.max(0,n.tools.length-e.length)+Math.max(0,n.events.length-h.length);d=`button`;let _=r&&`bg-accent-soft/70`;t[17]===_?f=t[18]:(f=Y(`flex w-full min-w-0 items-start gap-3 border-b border-edge-subtle px-4 py-3 text-left transition-colors`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,_),t[17]=_,t[18]=f),p=o;let v=r&&`border-accent bg-accent`,y;t[19]===v?y=t[20]:(y=Y(`mt-1 size-2.5 shrink-0 rounded-full border border-edge-strong bg-surface-panel`,v),t[19]=v,t[20]=y),t[21]===y?m=t[22]:(m=(0,Z.jsx)(`span`,{className:y,"aria-hidden":!0}),t[21]=y,t[22]=m),s=`min-w-0 flex-1`;let b;t[23]===n.preview?b=t[24]:(b=(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium text-fg`,children:n.preview}),t[23]=n.preview,t[24]=b);let x;t[25]!==r||t[26]!==a?(x=r?(0,Z.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-1.5 py-0.5 text-[10px] font-medium text-on-accent`,children:a}):null,t[25]=r,t[26]=a,t[27]=x):x=t[27],t[28]!==b||t[29]!==x?(c=(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[b,x]}),t[28]=b,t[29]=x,t[30]=c):c=t[30];let S;t[31]===n.title?S=t[32]:(S=(0,Z.jsx)(`span`,{children:n.title}),t[31]=n.title,t[32]=S);let C;t[33]===n.timestamp?C=t[34]:(C=n.timestamp?(0,Z.jsx)(`time`,{suppressHydrationWarning:!0,dateTime:new Date(n.timestamp).toISOString(),children:wy(n.timestamp)}):null,t[33]=n.timestamp,t[34]=C);let w;t[35]!==i||t[36]!==n.tools.length?(w=n.tools.length>0?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(Yt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),IA(n.tools.length,i)]}):null,t[35]=i,t[36]=n.tools.length,t[37]=w):w=t[37],t[38]!==S||t[39]!==C||t[40]!==w?(l=(0,Z.jsxs)(`span`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[S,C,w]}),t[38]=S,t[39]=C,t[40]=w,t[41]=l):l=t[41],u=e.length>0||n.events.length>0?(0,Z.jsxs)(`span`,{className:`mt-2 flex min-w-0 flex-wrap gap-1.5`,children:[e.map(BA),h.map(zA),g>0?(0,Z.jsxs)(`span`,{className:`rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,children:[`+`,g]}):null]}):null,t[0]=r,t[1]=a,t[2]=i,t[3]=o,t[4]=n.events,t[5]=n.preview,t[6]=n.timestamp,t[7]=n.title,t[8]=n.tools,t[9]=s,t[10]=c,t[11]=l,t[12]=u,t[13]=d,t[14]=f,t[15]=p,t[16]=m}else s=t[9],c=t[10],l=t[11],u=t[12],d=t[13],f=t[14],p=t[15],m=t[16];let h;t[42]!==s||t[43]!==c||t[44]!==l||t[45]!==u?(h=(0,Z.jsxs)(`span`,{className:s,children:[c,l,u]}),t[42]=s,t[43]=c,t[44]=l,t[45]=u,t[46]=h):h=t[46];let g;return t[47]!==d||t[48]!==f||t[49]!==p||t[50]!==m||t[51]!==h?(g=(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:d,className:f,onClick:p,children:[m,h]})}),t[47]=d,t[48]=f,t[49]=p,t[50]=m,t[51]=h,t[52]=g):g=t[52],g}function zA(e){return(0,Z.jsxs)(`span`,{className:`inline-flex max-w-[10rem] items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,children:[(0,Z.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-current opacity-70`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function BA(e){return(0,Z.jsxs)(`span`,{className:Y(`inline-flex max-w-[9rem] items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,e.running&&`text-accent-fg`),children:[(0,Z.jsx)(Yt,{className:`size-3 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function VA(e){let t=(0,X.c)(39),{items:n,activeMessageIndex:r,labels:i,openLabel:a,closeLabel:o,currentLabel:s,onSelectMessage:c}=e,l;t[0]!==n||t[1]!==i?(l=FA(n,i),t[0]=n,t[1]=i,t[2]=l):l=t[2];let u=l,[d,f]=(0,Q.useState)(!1);if(u.length<4)return null;let p;t[3]!==r||t[4]!==u?(p=LA(u,r),t[3]=r,t[4]=u,t[5]=p):p=t[5];let m=p,h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsx)(Le,{className:`size-[1.125rem]`,strokeWidth:1.8,"aria-hidden":!0}),t[6]=h):h=t[6];let g;t[7]===a?g=t[8]:(g=(0,Z.jsx)(w,{asChild:!0,children:(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,className:`size-10 shrink-0 rounded-full p-0 sm:size-9 xl:hidden`,"aria-label":a,title:a,children:h})}),t[7]=a,t[8]=g);let _;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[80] bg-scrim/60 backdrop-blur-[1px] xl:hidden`}),t[9]=_):_=t[9];let v;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(v=Y(`xopc-dialog-content-pane fixed inset-x-2 bottom-[max(.5rem,env(safe-area-inset-bottom))] z-[90] flex h-[min(72dvh,34rem)] flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-overlay shadow-popover outline-none`,`sm:left-auto sm:right-3 sm:w-[min(24rem,calc(100vw-1.5rem))]`,`md:bottom-[max(1rem,env(safe-area-inset-bottom))] md:right-4 md:h-[min(calc(100dvh-6rem),40rem)]`,`xl:hidden`),t[10]=v):v=t[10];let y;t[11]===i.title?y=t[12]:(y=(0,Z.jsx)(k,{className:`min-w-0 truncate text-base font-semibold text-fg`,children:i.title}),t[11]=i.title,t[12]=y);let b;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Z.jsx)(Xt,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[13]=b):b=t[13];let x;t[14]===o?x=t[15]:(x=(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 p-0`,"aria-label":o,children:b})}),t[14]=o,t[15]=x);let S;t[16]!==y||t[17]!==x?(S=(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-between gap-3 border-b border-edge-subtle px-3.5 py-3`,children:[y,x]}),t[16]=y,t[17]=x,t[18]=S):S=t[18];let T;if(t[19]!==m||t[20]!==s||t[21]!==i||t[22]!==c||t[23]!==u){let e;t[25]!==m||t[26]!==s||t[27]!==i||t[28]!==c?(e=e=>(0,Z.jsx)(RA,{turn:e,active:e.id===m,labels:i,currentLabel:s,onSelect:()=>{c(e.messageIndex),f(!1)}},e.id),t[25]=m,t[26]=s,t[27]=i,t[28]=c,t[29]=e):e=t[29],T=u.map(e),t[19]=m,t[20]=s,t[21]=i,t[22]=c,t[23]=u,t[24]=T}else T=t[24];let j;t[30]===T?j=t[31]:(j=(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Z.jsx)(`ol`,{className:`min-w-0`,children:T})}),t[30]=T,t[31]=j);let M;t[32]!==S||t[33]!==j?(M=(0,Z.jsxs)(D,{children:[_,(0,Z.jsxs)(O,{className:v,"aria-describedby":void 0,children:[S,j]})]}),t[32]=S,t[33]=j,t[34]=M):M=t[34];let N;return t[35]!==d||t[36]!==M||t[37]!==g?(N=(0,Z.jsxs)(A,{open:d,onOpenChange:f,children:[g,M]}),t[35]=d,t[36]=M,t[37]=g,t[38]=N):N=t[38],N}function HA(e){let{active:t,scrubbing:n,distance:r}=e;return n?r===0?`w-7 bg-fg`:r===1?`w-5 bg-fg-muted`:r===2?`w-4 bg-edge-strong/70`:t?`w-3.5 bg-accent`:`w-2.5 bg-edge-strong/45`:t?`w-3.5 bg-accent`:`w-2.5 bg-edge-strong/45`}function UA(e){let t=(0,X.c)(40),{turn:n,labels:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n.events||t[2]!==n.preview||t[3]!==n.timestamp||t[4]!==n.title||t[5]!==n.tools){let e=n.tools.slice(0,3),p=Math.max(0,n.tools.length-e.length),m=n.events.slice(0,Math.max(0,3-e.length));i=p+Math.max(0,n.events.length-m.length);let h=n.tools.length>0||n.events.length>0?[...e.map(qA),...m.map(KA),...i>0?[`+${i}`]:[]].join(` · `):n.title;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(l=Y(`pointer-events-auto absolute right-12 top-1/2 z-[100] w-[min(25rem,calc(100vw-8rem))] -translate-y-1/2`,`rounded-2xl border border-edge bg-surface-overlay p-3 text-left shadow-popover backdrop-blur`),t[15]=l):l=t[15],t[16]===n.timestamp?u=t[17]:(u=n.timestamp?(0,Z.jsx)(`div`,{className:`mb-1 flex min-w-0 justify-end text-xs`,children:(0,Z.jsx)(`time`,{suppressHydrationWarning:!0,className:`shrink-0 tabular-nums text-fg-disabled`,dateTime:new Date(n.timestamp).toISOString(),children:wy(n.timestamp)})}):null,t[16]=n.timestamp,t[17]=u),t[18]===n.preview?d=t[19]:(d=(0,Z.jsx)(`div`,{className:`min-w-0 text-sm font-semibold leading-5 text-fg`,children:(0,Z.jsx)(`span`,{className:`line-clamp-1`,children:n.preview})}),t[18]=n.preview,t[19]=d),t[20]===h?f=t[21]:(f=(0,Z.jsx)(`div`,{className:`mt-1 line-clamp-3 text-sm leading-6 text-fg-muted`,children:h}),t[20]=h,t[21]=f),a=`mt-3 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 text-sm text-fg-subtle`,t[22]!==r||t[23]!==n.title||t[24]!==n.tools.length?(o=n.tools.length>0?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Z.jsx)(Yt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:IA(n.tools.length,r)})]}):(0,Z.jsx)(`span`,{children:n.title}),t[22]=r,t[23]=n.title,t[24]=n.tools.length,t[25]=o):o=t[25],s=e.map(GA),c=m.map(WA),t[0]=r,t[1]=n.events,t[2]=n.preview,t[3]=n.timestamp,t[4]=n.title,t[5]=n.tools,t[6]=i,t[7]=a,t[8]=o,t[9]=s,t[10]=c,t[11]=l,t[12]=u,t[13]=d,t[14]=f}else i=t[6],a=t[7],o=t[8],s=t[9],c=t[10],l=t[11],u=t[12],d=t[13],f=t[14];let p;t[26]===i?p=t[27]:(p=i>0?(0,Z.jsxs)(`span`,{children:[`+`,i]}):null,t[26]=i,t[27]=p);let m;t[28]!==a||t[29]!==o||t[30]!==s||t[31]!==c||t[32]!==p?(m=(0,Z.jsxs)(`div`,{className:a,children:[o,s,c,p]}),t[28]=a,t[29]=o,t[30]=s,t[31]=c,t[32]=p,t[33]=m):m=t[33];let h;return t[34]!==m||t[35]!==l||t[36]!==u||t[37]!==d||t[38]!==f?(h=(0,Z.jsxs)(`div`,{className:l,children:[u,d,f,m]}),t[34]=m,t[35]=l,t[36]=u,t[37]=d,t[38]=f,t[39]=h):h=t[39],h}function WA(e){return(0,Z.jsxs)(`span`,{className:Y(`inline-flex min-w-0 max-w-[10rem] items-center gap-1.5`,e.tone===`branch`&&`text-accent`,e.tone===`compaction`&&`text-fg-muted`),children:[(0,Z.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-current opacity-70`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function GA(e){return(0,Z.jsxs)(`span`,{className:Y(`inline-flex min-w-0 max-w-[9rem] items-center gap-1.5`,e.running&&`text-accent`),children:[(0,Z.jsx)(Yt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function KA(e){return e.label}function qA(e){return e.label}function JA(e){let t=(0,X.c)(44),{items:n,activeMessageIndex:r,labels:i,onSelectMessage:a}=e,o;t[0]!==n||t[1]!==i?(o=FA(n,i),t[0]=n,t[1]=i,t[2]=o):o=t[2];let s=o,[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d,f;if(t[3]===c?(d=t[4],f=t[5]):(d=()=>{if(!c)return;let e=()=>{l(null)},t=t=>{let n=t.target;n instanceof Node&&(u.current?.contains(n)||e())},n=t=>{t.key===`Escape`&&e()};return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n)}},f=[c],t[3]=c,t[4]=d,t[5]=f),(0,Q.useEffect)(d,f),s.length<4)return null;let p;if(t[6]!==r||t[7]!==s){p=s[0]?.id;for(let e of s)e.messageIndex<=r&&(p=e.id);t[6]=r,t[7]=s,t[8]=p}else p=t[8];let m=c??p,h;t[9]!==c||t[10]!==s?(h=c?s.find(e=>e.id===c):null,t[9]=c,t[10]=s,t[11]=h):h=t[11];let g=h,_=c!==null,v;if(t[12]!==m||t[13]!==s){let e;t[15]===m?e=t[16]:(e=e=>e.id===m,t[15]=m,t[16]=e),v=s.findIndex(e),t[12]=m,t[13]=s,t[14]=v}else v=t[14];let y=Math.max(0,v),b=i.title,x,S;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>{l(null)},S=e=>{let t=e.relatedTarget;(!(t instanceof Node)||!e.currentTarget.contains(t))&&l(null)},t[17]=x,t[18]=S):(x=t[17],S=t[18]);let C;t[19]===p?C=t[20]:(C=()=>l(e=>e??p??null),t[19]=p,t[20]=C);let w;if(t[21]!==a||t[22]!==_||t[23]!==m||t[24]!==y||t[25]!==s){let e;t[27]!==a||t[28]!==_||t[29]!==m||t[30]!==y?(e=(e,t)=>{let n=e.id===m,r=Math.abs(t-y);return(0,Z.jsx)(`li`,{className:`group relative flex h-3.5 w-full shrink-0 items-center justify-end`,onMouseEnter:()=>l(e.id),onFocus:()=>l(e.id),children:(0,Z.jsx)(`button`,{type:`button`,className:Y(`flex h-3.5 w-full items-center justify-end rounded-sm pr-1.5`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),onClick:()=>a(e.messageIndex),"aria-label":`${e.title}: ${e.preview}`,children:(0,Z.jsx)(`span`,{className:Y(`block h-0.5 rounded-full transition-[width,background-color] duration-150 ease-out`,HA({active:n,scrubbing:_,distance:r}),`group-hover:bg-fg`),"aria-hidden":!0})})},e.id)},t[27]=a,t[28]=_,t[29]=m,t[30]=y,t[31]=e):e=t[31],w=s.map(e),t[21]=a,t[22]=_,t[23]=m,t[24]=y,t[25]=s,t[26]=w}else w=t[26];let T;t[32]!==w||t[33]!==C?(T=(0,Z.jsx)(`div`,{className:`chat-timeline-scroll flex min-h-0 w-full flex-col`,children:(0,Z.jsx)(`ol`,{className:`my-auto flex w-full shrink-0 flex-col items-end py-1`,onMouseEnter:C,children:w})}),t[32]=w,t[33]=C,t[34]=T):T=t[34];let E;t[35]!==i||t[36]!==g?(E=g?(0,Z.jsx)(UA,{turn:g,labels:i}):null,t[35]=i,t[36]=g,t[37]=E):E=t[37];let D;t[38]!==T||t[39]!==E?(D=(0,Z.jsxs)(`div`,{className:`relative z-[90] flex h-full min-h-0 w-full flex-col justify-center overflow-visible`,children:[T,E]}),t[38]=T,t[39]=E,t[40]=D):D=t[40];let O;return t[41]!==i.title||t[42]!==D?(O=(0,Z.jsx)(`aside`,{ref:u,className:`hidden h-full min-h-0 max-h-full w-12 shrink-0 items-center overflow-visible py-4 xl:flex`,"aria-label":b,onMouseLeave:x,onBlur:S,children:D}),t[41]=i.title,t[42]=D,t[43]=O):O=t[43],O}function YA(e){return e.enabled?e.sourceContextPending?`pending:${e.conversationId??``}`:e.task?`task:${e.task.task.id}:${e.task.task.version}`:e.suppressProjectContext?`suppressed:${e.conversationId??``}`:e.project?`project:${e.project.id}:${e.project.name}`:e.conversationId?`session:${e.conversationId}:failed:${e.sourceContextFailed?`1`:`0`}`:`empty`:`disabled`}function XA(e){let t=YA(e);if(!e.enabled)return{key:t,context:{kind:`empty`},status:`ready`};if(e.sourceContextPending)return{key:t,context:{kind:`empty`},status:`loading`};if(e.task){let n=e.task.receipts[0];return{key:t,context:{kind:`task`,taskId:e.task.task.id,taskTitle:e.task.task.title,phase:e.task.task.phase,operationalState:e.task.operationalState,attentionSummary:e.task.attention[0]?.summary,nextAction:n?.nextAction,recentFailure:n?.failure?.recoveryAction},status:`ready`}}return e.suppressProjectContext?{key:t,context:{kind:`empty`},status:e.sourceContextFailed?`degraded`:`ready`}:e.project?{key:t,context:{kind:`project`,projectId:e.project.id,projectName:e.project.name},status:`ready`}:{key:t,context:{kind:`empty`},status:e.conversationId?`loading`:`ready`}}function ZA(e){let{enabled:t,conversationId:n,sourceContextPending:r,sourceContextFailed:i,suppressProjectContext:a,project:o,task:s}=e,c=YA(e),[l,u]=(0,Q.useState)(()=>XA(e));(0,Q.useEffect)(()=>{let e=!1,l=XA({enabled:t,conversationId:n,sourceContextPending:r,sourceContextFailed:i,suppressProjectContext:a,project:o,task:s});if(u(l),!(!t||!n||r||s||a))return(async()=>{let t=!!i,r=o?.id??null;if(!r)try{let e=await jr(n);r=e?e.creation.projectId?.trim()||null:(await hn(n)).projectId?.trim()||null}catch{t=!0}if(!r){e||u({key:c,context:{kind:`empty`},status:t?`degraded`:`ready`});return}try{let[n,i]=await Promise.allSettled([o?Promise.resolve(o):fn(r),pn(r)]);if(n.status===`rejected`)throw n.reason;let a=i.status===`fulfilled`?i.value:null;a||(t=!0);let s=a?.blockers[0],l=a?.digest.health===`attention`?a.recentResults.find(({receipt:e})=>e.status===`failed`||e.verification.status===`failed`):void 0;e||u({key:c,context:{kind:`project`,projectId:r,projectName:n.value.name,recommendedAction:a?.digest.recommendedAction,blockedReason:s?.detail??s?.title,recentFailure:l?.receipt.failure?.recoveryAction??l?.receipt.summary},status:t?`degraded`:`ready`})}catch{e||u({key:c,context:{kind:`empty`},status:`degraded`})}})(),()=>{e=!0}},[n,c,t,i,r,a,o,s]);let d=l.key===c?l:XA(e);return{context:d.context,status:d.status}}var QA=[Ht,Rt,ws];function $A(e){let t=(0,X.c)(20),{agentName:n,messages:r,disabled:i,onPick:a}=e,o;t[0]!==r.setupPromptComplete||t[1]!==r.setupPromptIdentity||t[2]!==r.setupPromptProject?(o=[r.setupPromptIdentity,r.setupPromptProject,r.setupPromptComplete],t[0]=r.setupPromptComplete,t[1]=r.setupPromptIdentity,t[2]=r.setupPromptProject,t[3]=o):o=t[3];let s=o,c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(`div`,{className:`flex size-12 items-center justify-center rounded-2xl bg-accent-soft text-accent`,children:(0,Z.jsx)(Ht,{className:`size-6`,strokeWidth:1.75,"aria-hidden":!0})}),t[4]=c):c=t[4];let l;t[5]===r.setupTitle?l=t[6]:(l=(0,Z.jsx)(`h1`,{id:`agent-setup-title`,className:`mt-4 text-balance text-xl font-semibold tracking-tight text-fg`,children:r.setupTitle}),t[5]=r.setupTitle,t[6]=l);let u;t[7]!==n||t[8]!==r.setupDescription?(u=r.setupDescription.replace(`{{name}}`,n),t[7]=n,t[8]=r.setupDescription,t[9]=u):u=t[9];let d;t[10]===u?d=t[11]:(d=(0,Z.jsx)(`p`,{className:`mt-2 max-w-xl text-pretty text-sm leading-relaxed text-fg-muted`,children:u}),t[10]=u,t[11]=d);let f;t[12]!==i||t[13]!==a||t[14]!==s?(f=(0,Z.jsx)(`div`,{className:`mt-7 grid w-full gap-3 md:grid-cols-3`,children:s.map((e,t)=>{let n=QA[t]??Ht;return(0,Z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>a(e),className:Y(`flex min-h-24 items-center gap-3 rounded-xl border border-edge bg-surface-panel px-4 py-4 text-left text-sm font-medium leading-relaxed text-fg`,`hover:border-accent/30 hover:bg-surface-hover`,ca.transition,ca.pressCard,ca.focusRingPanel,ca.disabled),children:[(0,Z.jsx)(n,{className:`size-4 shrink-0 text-accent`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:e})]},e)})}),t[12]=i,t[13]=a,t[14]=s,t[15]=f):f=t[15];let p;return t[16]!==l||t[17]!==d||t[18]!==f?(p=(0,Z.jsxs)(`section`,{className:`mx-auto flex w-full max-w-4xl flex-col items-center px-2 pb-4 pt-12 text-center sm:pt-16`,"aria-labelledby":`agent-setup-title`,children:[c,l,d,f]}),t[16]=l,t[17]=d,t[18]=f,t[19]=p):p=t[19],p}var ej=t({ChatPage:()=>nj}),tj=(0,Q.lazy)(async()=>({default:(await l(()=>import(`./chat-terminal-dock-eneTvxV3.js`),__vite__mapDeps([30,1,2,5,6,31,11,32,26,27,17,18,33,34,35,36,37,38,39,40,41,42,43,44,4,45,46,28,29,9,47,48,49,50]))).ChatTerminalDock}));function nj({beforeSend:e,draftSeed:t,sourceNoteInView:n=!1,embedded:r=!1,conversationId:i,taskId:a,personal:o=!1,personalWelcome:s,automationWorkspace:c=!1,automationTimelineEntries:l,readOnly:u=!1,onHistoryReady:h,automationExecution:g=!1,initialTurnId:y,onInitialTurnLocated:b}={}){let x=v(e=>e.language),w=S(x),E=_(e=>e.conversationId),j=m(),M=d(),{pathname:N}=M,[P,F]=f(),I=(0,Q.useRef)(null),L=(0,Q.useRef)(0),R=(0,Q.useRef)(null),[z,B]=(0,Q.useState)(null),[ee,V]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{V(t??null)},[t]);let[U,W]=(0,Q.useState)(()=>!!(i&&window.localStorage.getItem(`personal-calibration:${i}`))),[te,ne]=(0,Q.useState)(null),[re,ie]=(0,Q.useState)(null),[ae,oe]=(0,Q.useState)(!1),[se,ce]=(0,Q.useState)(null),le=a?.trim()||null,{data:ue}=Ks(le??``),{auth:de,session:G,messages:K,timeline:fe,stream:q,followUp:pe,clarify:me,agents:J}=DA({fixedConversationId:i,taskId:le??void 0,personal:o}),he=pe.composerMode.kind===`editTurn`?pe.composerMode:null,ge=Sn(e=>!!(G.conversationId&&!e.shellError&&e.sessions[G.conversationId]?.historyStatus===`ready`));(0,Q.useEffect)(()=>{ge&&K.items.length>0&&h?.()},[ge,K.items.length,h]),(0,Q.useLayoutEffect)(()=>{if(!c&&!g||!G.conversationId)return;let e=G.conversationId;return fp.setState({conversationIdOverride:e}),()=>{fp.getState().conversationIdOverride===e&&fp.setState({conversationIdOverride:null})}},[c,g,G.conversationId]);let _e=!o&&!r&&!le&&P.get(`scene`)===`find-skills`,ve=c||P.get(`setup`)===`automation`,ye=!r&&!le&&P.get(`agentSetup`)===`1`,be=o?``:P.get(`skill`)?.trim()??``,xe=o?``:P.get(`slash`)?.trim()??``;(0,Q.useEffect)(()=>{if(!o||!P.has(`skill`)&&!P.has(`slash`))return;let e=new URLSearchParams(P);e.delete(`skill`),e.delete(`slash`),F(e,{replace:!0})},[o,P,F]);let Se=P.get(c?`chatDraft`:`draft`)??``,Ce=P.get(`autoSend`)===`1`,we=P.get(`attachmentHandoff`),Te=P.get(`attachmentsHandoff`),Ee=G.decodedKey??G.conversationId,[De,ke]=(0,Q.useState)(null),Ae=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(we){let e=Ne(we);e&&ke(e),Ae.current=Ee;return}Ae.current!==Ee&&(Ae.current=Ee,ke(null))},[we,Ee]);let je=Yf(e=>e.markViewed),Me=Yf(e=>Ee?e.runs[Ee]?.unread:!1);(0,Q.useEffect)(()=>{Ee&&Me&&je(Ee)},[Ee,Me,je]);let{data:Pe}=OA(Ee),Fe=ve||!!Pe?.identity?.customData?.automationSetup,Ie=!!Pe?.identity?.customData?.automationSetup?.automationId,Le=(0,Q.useCallback)(async e=>{if(Ee)try{let t=await G.sessionManager.forkSessionAtTurn(Ee,e);window.dispatchEvent(new CustomEvent(`session-created`,{detail:{key:t.conversationId,conversationId:t.conversationId}})),ya(`success`,w.chat.messageForkCreated),j(`/chat/${encodeURIComponent(t.conversationId)}`)}catch(e){throw ya(`error`,e instanceof Error?e.message:w.chat.messageForkFailed),e}},[Ee,w.chat.messageForkCreated,w.chat.messageForkFailed,j,G.sessionManager]),Re=K.items.at(-1),ze=o&&!U&&!q.streaming&&!q.sending&&Re?.role===`assistant`&&K.items.filter(e=>e.role===`user`).length===1&&K.items.filter(e=>e.role===`assistant`).length===1&&!K.items.some(e=>e.role===`task`),Be=e=>{W(!0),i&&window.localStorage.setItem(`personal-calibration:${i}`,`1`),e&&(L.current+=1,B({id:L.current,text:e}))};(0,Q.useEffect)(()=>{I.current=null},[G.conversationId]),(0,Q.useEffect)(()=>{if(!de.hasToken||!be&&!xe&&!Se&&!(G.projectPreparation&&Te)||Ce&&!G.projectPreparation||G.showSessionLoading||G.sessionRoutePending||!G.conversationId&&!G.projectPreparation)return;let e=G.projectPreparation&&Te?ji(Te)??void 0:void 0,t=()=>{let e=new URLSearchParams(P);e.delete(`skill`),e.delete(`slash`),e.delete(c?`chatDraft`:`draft`),G.projectPreparation&&(e.delete(`autoSend`),e.delete(`attachmentsHandoff`));let t=e.toString();j({pathname:N,search:t?`?${t}`:``},{replace:!0})},n=(n,r)=>{I.current!==r&&(I.current=r,queueMicrotask(()=>{e?.length?rm(n,e):(L.current+=1,B({id:L.current,text:n})),t()}))},r=Ia(be,Se);if(r||e?.length){let e=`${G.conversationId}:draft:${r}`;n(r??``,e);return}if(be){t();return}if(!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(xe)){t();return}let i=`${G.conversationId}:slash:${xe}`;I.current!==i&&queueMicrotask(()=>{(async()=>{try{let e=await Do(),t=xe.toLowerCase(),n=e.find(e=>e.name.toLowerCase()===t||Array.isArray(e.aliases)&&e.aliases.some(e=>e.toLowerCase()===t));if(n){if(I.current===i)return;I.current=i,L.current+=1,B({id:L.current,text:Bw(n)})}}finally{t()}})()})},[de.hasToken,c,be,xe,Se,Ce,Te,G.projectPreparation,P,G.showSessionLoading,G.sessionRoutePending,G.conversationId,j,N]);let{scrollRef:He,composerDockRef:Ke,atBottom:qe,registerListContentRef:Je,scrollToBottom:Ye,replySpaceRef:Xe,reserveReplySpace:Ze,onScroll:Qe}=Tw({hasToken:de.hasToken,showSessionLoading:G.showSessionLoading,conversationId:G.conversationId,chatMessages:K.items,streaming:q.streaming,hasMore:G.hasMore,loadingMore:G.loadingMore,loadMoreMessages:G.loadMoreMessages});(0,Q.useEffect)(()=>{if(!c||!qe||!l?.length)return;let e=requestAnimationFrame(()=>Ye(!1));return()=>cancelAnimationFrame(e)},[c,l,qe,Ye]);let $e=ZO({enabled:o,conversationId:G.conversationId,messages:K.items,viewportRef:He}),[et,tt]=(0,Q.useState)(0),nt=(0,Q.useRef)(null),rt=(0,Q.useRef)(null),it=(0,Q.useMemo)(()=>{let e=-1;for(let t of fe.items)typeof t.displayIndex==`number`&&Number.isFinite(t.displayIndex)&&(e=Math.max(e,t.displayIndex));return e<0?0:Math.max(0,e+1-K.items.length)},[K.items.length,fe.items]),at=(0,Q.useCallback)(e=>{let t=He.current;if(!t)return!1;let n=t.querySelector(`[data-chat-message-index="${e}"]`);if(!n){let n=rw(t)?.reveal(e)??!1;return n&&tt(e),n}iw(t),tt(e);let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=t.scrollTop+i.top-r.top-16;return t.scrollTo({top:Math.max(0,a),behavior:ew()}),!0},[He]),ot=(0,Q.useCallback)(()=>{let e=He.current;if(!e)return;let t=$C(e);tt(e=>e===t?e:t)},[He]),st=(0,Q.useCallback)(()=>{nt.current??=requestAnimationFrame(()=>{nt.current=null,ot()})},[ot]),ct=(0,Q.useCallback)(()=>{Qe(),st()},[Qe,st]),lt=(0,Q.useCallback)(e=>{let t=e-it;if(t<0||t>=K.items.length){t<0&&G.hasMore&&!G.loadingMore&&(rt.current=e,G.loadMoreMessages());return}rt.current=null,at(t)},[K.items.length,at,G.hasMore,G.loadMoreMessages,G.loadingMore,it]);$w({conversationId:G.conversationId,turnId:y,messages:K.items,ready:ge,hasMore:G.hasMore,loadingMore:G.loadingMore,loadMore:G.loadMoreMessages,reveal:at,onLocated:b});let ut=hk({conversationId:G.conversationId,taskId:le,messages:K.items,displayOffset:it,viewportRef:He,onRevealDisplayIndex:lt});(0,Q.useEffect)(()=>{let e=rt.current;if(e==null)return;let t=e-it;if(t>=0&&t<K.items.length){rt.current=null,requestAnimationFrame(()=>at(t));return}if(t<0&&G.hasMore&&!G.loadingMore){G.loadMoreMessages();return}(t>=K.items.length||!G.hasMore)&&(rt.current=null)},[K.items.length,at,G.hasMore,G.loadMoreMessages,G.loadingMore,it]),(0,Q.useEffect)(()=>{st()},[K.items.length,st,G.conversationId,it]),(0,Q.useEffect)(()=>()=>{nt.current!=null&&cancelAnimationFrame(nt.current)},[]),(0,Q.useEffect)(()=>{B(null)},[G.conversationId]);let dt=(0,Q.useCallback)(e=>{L.current+=1,B({id:L.current,text:e.prompt})},[]),ft=!!(G.conversationId&&!G.showSessionLoading&&!G.sessionRoutePending&&G.workspaceSource!==`project`&&G.workspaceSource!==`execution_environment`&&K.items.length===0),pt=ho(e=>e.setAgentId);(0,Q.useEffect)(()=>{if(de.hasToken)return pt(J.displayAgentId),()=>pt(``)},[de.hasToken,J.displayAgentId,pt]);let mt=G.conversationPhase===`creating-session`,ht=G.conversationPhase===`loading-history`;Hf(o&&!ht?Ee:null,o);let gt=mt||ht,_t=ht,vt=!_t&&K.items.length===0&&!l?.length&&!q.streaming,yt=(0,Q.useMemo)(()=>{if(q.taskPlan){let e=FO(q.taskPlan);return e?{plan:e,changeSummary:JO(K.items,q.streaming)?.changeSummary??null}:null}return JO(K.items,q.streaming)},[K.items,q.streaming,q.taskPlan]),bt=(0,Q.useMemo)(()=>(G.sessionRoutePending&&G.decodedKey?G.decodedKey:G.conversationId)?G.sessionName?.trim()||w.chat.newSession:w.nav.chat,[G.conversationId,G.sessionName,G.sessionRoutePending,G.decodedKey,w.nav.chat,w.chat.newSession]),xt=Pe?.sourceNoteId??null,St=AD(Ee,P.get(`projectId`)),wt=G.projectPreparation?.project??St,[Tt,Et]=(0,Q.useState)([]),[Dt,Ot]=(0,Q.useState)([]),kt=_(e=>e.baseUrl),At=Ee?cs(kt,E,Ee):null,jt=ss.store(e=>At?e.drafts[At]:void 0),Mt=(0,Q.useRef)(void 0),[Nt,Pt]=(0,Q.useState)(!1);(0,Q.useLayoutEffect)(()=>{Ee&&Ee!==Mt.current&&(Mt.current=void 0)},[Ee]),(0,Q.useEffect)(()=>{let e=!1;if(ne(null),xt)return Ve(xt).then(t=>{e||ne(t?.title?.trim()||null)}).catch(()=>{e||ne(null)}),()=>{e=!0}},[xt]);let Ft=te||Pe?.sourceNoteTitle||w.chat.sourceNoteFallbackTitle,It=ZA({enabled:de.hasToken&&!!(Ee||wt)&&!ye&&K.items.length===0&&!G.showSessionLoading&&!G.sessionRoutePending,conversationId:Ee,suppressProjectContext:!!(xt||De||G.workspaceSource===`execution_environment`||G.workspaceSource===`session_override`||G.workspaceSource===`agent_workspace`),project:wt,task:ue}),Lt=(0,Q.useMemo)(()=>J.chatAgents?.items.find(e=>e.id===J.displayAgentId)??{id:J.displayAgentId},[J.chatAgents?.items,J.displayAgentId]),Rt=(0,Q.useMemo)(()=>Rs(It.context,w.chat.welcomeSpotlight,{contextStatus:It.status}),[w.chat.welcomeSpotlight,It.context,It.status]),zt=(0,Q.useMemo)(()=>Rt.recommendation?{suggestionId:Rt.recommendation.id,contextKind:Rt.contextKind,prompt:Rt.recommendation.prompt}:null,[Rt]),Bt=(0,Q.useRef)(0);(0,Q.useEffect)(()=>(Bt.current++,()=>{Bt.current++}),[i,E]);let Vt=(0,Q.useCallback)((...t)=>{let n=()=>{let[e,n,r,i,a]=t;if(jt&&(he||e.trim().startsWith(`/`)))return Sn.getState().setShellError(w.chat.pageContext.pending),!1;if(he)return q.replaceLatestUserTurn(he.turnId,e,n,r,i,a?.submittedAt);let o=!1,s=q.sendMessage(e,n,r,i,void 0,jt?.envelope,(e,t)=>{o=!0,Ze(t??e),a?.onDispatched?.({clientSubmissionId:e,messageRenderKey:t})},void 0,a?.submittedAt);return o?(At&&jt&&ss.remove(At,jt),!0):s};if(!e)return n();let r=Bt.current;return e().then(e=>e&&r===Bt.current?n():!1)},[e,he,q.replaceLatestUserTurn,q.sendMessage,jt,At,w.chat.pageContext.pending,Ze]),Ht=kD({preparation:G.projectPreparation,conversationId:Ee,ready:G.modelConfigReady&&!gt,onSend:Vt}),Ut=(0,Q.useCallback)(e=>{if(!e.turnId||!G.conversationId)return;let t=kn.getGeneration(G.conversationId),n=kn.getResumeRunId(G.conversationId);pe.beginEditTurn(e.turnId,{text:e.userTurnDocument?Tr(e.userTurnDocument):Wn(e.content),attachments:Kn(e.attachments)??[],contextRefs:e.contextRefs?.flatMap(e=>e.kind===`mcp_resource`?[]:[{refId:e.refId,kind:e.kind,sourceId:e.sourceId,expectedVersion:e.version,title:e.title,fileKind:e.fileKind}])??[]}).then(e=>{e&&q.settleStoppedRun(t,n)})},[pe.beginEditTurn,q.settleStoppedRun,G.conversationId]),Wt=(0,Q.useCallback)(e=>{if(pe.composerMode.kind===`editFollowUp`)pe.beginEditFollowUp(pe.composerMode.inputId);else if(pe.composerMode.kind===`editTurn`&&G.conversationId){let t=kn.getGeneration(G.conversationId),n=kn.getResumeRunId(G.conversationId);pe.beginEditTurn(pe.composerMode.turnId,e).then(e=>{e&&q.settleStoppedRun(t,n)})}},[pe.composerMode,pe.beginEditFollowUp,pe.beginEditTurn,G.conversationId,q.settleStoppedRun]),Gt=pe.cancelEditor;(0,Q.useEffect)(()=>{if(!Ce||!Se.trim()&&!Te||!de.hasToken||G.showSessionLoading||G.sessionRoutePending||!G.conversationId||q.sending||q.streaming)return;let e=Ia(be,Se),t=Te?ji(Te):void 0;if(!e&&!t?.length)return;let n=`${G.conversationId}:auto-send:${e??``}:${Te??``}`;if(I.current===n)return;I.current=n;let r=new URLSearchParams(P);r.delete(`skill`),r.delete(`slash`),r.delete(`draft`),r.delete(`autoSend`),r.delete(`attachmentsHandoff`);let i=r.toString();j({pathname:N,search:i?`?${i}`:``},{replace:!0}),Vt(e??``,t??void 0)},[de.hasToken,Ce,Te,Se,Vt,j,N,P,G.conversationId,G.sessionRoutePending,G.showSessionLoading,be,q.sending,q.streaming]);let Kt=(0,Q.useCallback)(()=>{R.current?.reject(),R.current=null,ie(null),oe(!1)},[]);(0,Q.useEffect)(()=>{Kt()},[Kt,xt]);let qt=(0,Q.useMemo)(()=>({title:w.chat.timelineTitle,turn:w.chat.timelineTurn,messageFallback:w.chat.timelineMessageFallback,toolCount_one:w.chat.timelineToolCount_one,toolCount_other:w.chat.timelineToolCount_other,searchedWeb:w.chat.stepSearchedWeb,searchedMemory:w.chat.stepSearchedMemory,searchedCode:w.chat.stepSearchedCode,searched:w.chat.stepSearched,readFile:w.chat.stepReadFile,runCommand:w.chat.stepRunCommand,listDirectory:w.chat.stepListDirectory,writeFile:w.chat.stepWriteFile,editFile:w.chat.stepEditFile,openUrl:w.chat.stepOpenUrl,fetchUrl:w.chat.stepFetchUrl,unknownTool:w.chat.stepUnknownTool}),[w.chat.timelineTitle,w.chat.timelineTurn,w.chat.timelineMessageFallback,w.chat.timelineToolCount_one,w.chat.timelineToolCount_other,w.chat.stepSearchedWeb,w.chat.stepSearchedMemory,w.chat.stepSearchedCode,w.chat.stepSearched,w.chat.stepReadFile,w.chat.stepRunCommand,w.chat.stepListDirectory,w.chat.stepWriteFile,w.chat.stepEditFile,w.chat.stepOpenUrl,w.chat.stepFetchUrl,w.chat.stepUnknownTool]),Jt=(0,Q.useCallback)(async e=>{if(!xt)return;R.current?.reject(),oe(!1);let t=w.chat.sourceNoteAppendSourceLine.replace(`{{time}}`,new Date().toLocaleString(x));return ie({heading:w.chat.sourceNoteAppendHeading,content:`${t}\n\n${e.trim()}`}),new Promise((e,t)=>{R.current={sourceNoteId:xt,resolve:e,reject:t}})},[x,w.chat.sourceNoteAppendHeading,w.chat.sourceNoteAppendSourceLine,xt]),Yt=`${M.pathname}${M.search}`,Xt=(0,Q.useCallback)(async e=>{try{let t=await Ge(e.trim(),`web`);ya(`success`,w.chat.messageSavedToNote,void 0,{href:Ct(Yt,t.id)})}catch(e){throw ya(`error`,e instanceof Error?e.message:w.notes.quickCaptureFailed),e}},[Yt,w.chat.messageSavedToNote,w.notes.quickCaptureFailed]),Zt=(0,Q.useCallback)(async()=>{let e=R.current;if(!e||!re)return;let t=re.heading.trim()||w.chat.sourceNoteAppendHeading,n=re.content.trim();if(n){oe(!0),ce(null);try{await We(e.sourceNoteId,n,t),window.dispatchEvent(new CustomEvent(`note-updated`,{detail:{noteId:e.sourceNoteId,source:`chat`,conversationId:Ee}})),e.resolve(),R.current=null,ie(null)}catch(e){ce(e instanceof Error?e.message:w.chat.sourceNoteSaveFailed)}finally{oe(!1)}}},[Ee,w.chat.sourceNoteAppendHeading,w.chat.sourceNoteSaveFailed,w.chat.sourceNoteSaveSuccess,re]),$t=(0,Q.useCallback)(async e=>{if(!xt)return;let t=e.trim().split(/\n+/)[0]?.replace(/^[-#*>\s]+/,``).trim()||w.chat.sourceNoteTaskFallbackTitle;try{await Ue(t.slice(0,120),{sourceNoteId:xt,sourceConversationId:Ee})}catch(e){throw ya(`error`,e instanceof Error?e.message:w.chat.sourceNoteTaskFailed),e}},[Ee,w.chat.sourceNoteTaskFailed,w.chat.sourceNoteTaskFallbackTitle,w.chat.sourceNoteTaskSuccess,xt]),en=(0,Q.useCallback)(async()=>{if(!xt)return;let t=Bt.current;if(e&&(!await e()||t!==Bt.current))return;let n=w.chat.sourceNoteDigestPrompt.replace(`{{title}}`,Ft);if(q.streaming||q.sending){pe.addPendingFollowUp(n),va({tone:`info`,status:`done`,title:w.chat.sourceNoteDigestQueued,source:x===`zh`?`笔记整理`:`Note digest`,dedupeKey:xt?`note-digest:${xt}`:void 0});return}q.sendMessage(n)},[e,pe,x,w.chat.sourceNoteDigestPrompt,w.chat.sourceNoteDigestQueued,xt,Ft,q]),tn=(0,Q.useCallback)(async e=>{if(!(Nt||Ht.busy)){if(G.projectPreparation){j(Ra(e),{state:{forceNewChat:!0,agentId:J.displayAgentId,temporary:G.userContextMode===`temporary`}});return}if(!(Mt.current!==void 0||q.sending||q.streaming||gt)){Mt.current=Ee,Pt(!0);try{e?j(Ra(e),{state:{forceNewChat:!0,agentId:J.displayAgentId,temporary:G.userContextMode===`temporary`}}):await G.createNewSession({forceNew:!0,projectId:e,temporary:G.userContextMode===`temporary`})}catch(e){Mt.current=void 0,ya(`error`,w.chat.composerContext.changeFailed,{error:e instanceof Error?e.message:String(e)})}finally{Pt(!1)}}}},[Ee,gt,w.chat.composerContext.changeFailed,Nt,Ht.busy,G.createNewSession,G.projectPreparation,G.userContextMode,q.sending,q.streaming,j,J.displayAgentId]),nn=(0,Q.useCallback)(()=>tn(null),[tn]),rn=(0,Q.useCallback)(async e=>{if(!(Nt||gt||q.sending||q.streaming||!ft)){Pt(!0);try{await G.onSessionWorkingDirectoryChange(e)}finally{Pt(!1)}}},[Nt,gt,q.sending,q.streaming,ft,G.onSessionWorkingDirectoryChange]),an=(0,Q.useMemo)(()=>({project:wt,draftRefs:Tt,draftAttachments:Dt,draftPage:jt?{id:`${jt.envelope.tabId}:${jt.envelope.sequence}`,title:jt.title||(x===`zh`?`当前页面`:`Current page`)}:void 0,onLeaveProject:Nt||Ht.busy?void 0:nn,leaveProjectLabel:w.chat.scopeRemoveProject,onDraftSourceNote:xt?en:void 0,draftSourceNoteLabel:w.chat.sourceNoteDigestAction}),[Nt,Ht.busy,wt,Tt,Dt,jt,x,nn,w.chat.scopeRemoveProject,xt,en,w.chat.sourceNoteDigestAction]);return de.hasToken?(q.error?Or(q.error):null)?.code===`session_not_found`?(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col overflow-hidden bg-surface-panel`,children:[(0,Z.jsx)(CO,{}),(0,Z.jsx)(mO,{chatHeadline:w.chat.sessionNotFoundTitle,chatAgents:J.chatAgents?.items??[],showChatAgentSelector:!1,chatAgentId:J.displayAgentId,onChatAgentChange:J.onChatAgentChange,chatAgentDisabled:!0}),(0,Z.jsx)(`main`,{className:`mx-auto flex w-full max-w-xl flex-1 items-center px-4 py-12 sm:px-6`,children:(0,Z.jsx)(`div`,{className:`w-full`,children:(0,Z.jsx)(yh,{errorText:q.error})})})]}):(0,Z.jsx)($_,{value:Fe,children:(0,Z.jsxs)(`div`,{className:Y(`flex h-full min-h-0 flex-1 flex-col bg-surface-panel`,c?`overflow-clip`:`overflow-hidden`),children:[(0,Z.jsx)(CO,{}),!r||c?(0,Z.jsx)(mO,{inline:c,chatHeadline:_e&&K.items.length===0?w.skills.findTitle:bt,chatAgents:J.chatAgents?.items??[],showChatAgentSelector:!c&&!ye&&J.showChatAgentSelector,chatAgentId:J.displayAgentId,onChatAgentChange:J.onChatAgentChange,chatAgentDisabled:Ht.busy||Nt||gt&&!G.projectPreparation,conversationId:G.conversationId,hasMessages:!gt&&K.items.length>0,workspacePath:G.effectiveWorkspacePath,userContextMode:G.userContextMode,projectId:wt?.id,context:an,canChangeWorkspace:!1,workspaceDisabled:gt||q.sending||q.streaming,onWorkspaceChange:G.onSessionWorkingDirectoryChange,prepareTerminalSession:G.projectPreparation?Ht.prepareSession:void 0,terminalDisabled:!!(G.projectPreparation&&(Ht.busy||!Ht.allowed||Ht.checking)),showContextControls:!ye,onFindOpen:ut.show}):null,(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 w-full flex-1 flex-col`,children:[!r&&Pe?.parentConversationId?(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-edge-subtle bg-surface-panel/80 px-3 py-2 text-xs text-fg-muted sm:px-5 xl:px-6`,children:[(0,Z.jsx)(p,{to:`/chat/${encodeURIComponent(Pe.parentConversationId)}`,className:`font-medium text-accent transition-colors hover:text-accent-fg`,children:w.chat.forkedFromConversation.replace(`{{name}}`,Pe.forkedFromSessionName||w.chat.forkedFromConversationFallback)}),(0,Z.jsx)(`span`,{className:`ms-2`,children:w.chat.forkSharedWorkspaceNotice})]}):null,M.state?.fromAgentEditor&&J.displayAgentId?(0,Z.jsx)(`div`,{className:`shrink-0 border-b border-edge-subtle bg-surface-panel/80 px-3 py-1.5 sm:px-5 xl:px-6`,children:(0,Z.jsxs)(p,{to:$o(J.displayAgentId),className:`inline-flex items-center gap-1 text-xs font-medium text-accent transition-colors hover:text-accent-fg`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`←`}),w.agentsSettings.backToEditor]})}):null,r&&xt&&!n?(0,Z.jsx)(`div`,{className:`shrink-0 border-b border-edge-subtle bg-surface-panel/80 px-3 py-1.5 sm:px-5 xl:px-6`,children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:w.chat.sourceNoteBanner.replace(`{{title}}`,Ft)}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex h-7 items-center gap-1.5 rounded-md border border-edge-subtle px-2 font-medium text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,onClick:en,children:[(0,Z.jsx)(Oe,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:w.chat.sourceNoteDigestAction})]}),(0,Z.jsx)(p,{to:Ct(`${M.pathname}${M.search}`,xt),className:`font-medium text-accent transition-colors hover:text-accent-fg`,children:w.chat.sourceNoteOpen})]})]})}):null,(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(QO,{open:ut.open,query:ut.query,activeIndex:ut.activeIndex,resultCount:ut.resultCount,searching:ut.searching,truncated:ut.truncated,limitedToLoaded:ut.limitedToLoaded,inputRef:ut.inputRef,labels:w.chat.find,onQueryChange:ut.setQuery,onPrevious:ut.previous,onNext:ut.next,onClose:ut.close}),!r||c?(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-y-0 left-1/2 z-20 hidden w-full max-w-[calc(var(--max-width-chat-frame)+8rem)] -translate-x-1/2 xl:block`,children:(0,Z.jsx)(`div`,{className:`pointer-events-auto absolute inset-y-0 right-0`,children:(0,Z.jsx)(JA,{items:fe.items,activeMessageIndex:et+it,labels:qt,onSelectMessage:lt})})}):null,(0,Z.jsx)(`div`,{ref:He,"data-chat-scroll-viewport":!0,className:Y(`chat-messages chat-messages--wide-viewport relative min-h-0 flex-1 overflow-y-auto overflow-x-hidden [overflow-anchor:none] [scrollbar-gutter:stable_both-edges]`,vt?`chat-messages--compact-welcome pt-5 pb-2`:`py-4`),onScroll:ct,"data-chat-find-open":ut.open?``:void 0,children:(0,Z.jsx)(`div`,{className:r&&!o?`px-3`:`px-3 sm:px-5 xl:px-6`,children:(0,Z.jsx)(`div`,{"data-chat-message-frame":!0,className:Y(`mx-auto w-full min-w-0`,(!r||o||c)&&`max-w-[var(--max-width-chat-frame)]`),children:ht?(0,Z.jsxs)(`div`,{className:`flex min-h-[min(40vh,20rem)] w-full flex-col gap-10 py-8`,"aria-busy":`true`,children:[(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(Qt,{className:`h-11 w-[min(70%,22rem)] rounded-2xl`})}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(Qt,{className:`h-4 w-24`}),(0,Z.jsx)(Qt,{className:`h-4 w-[min(82%,36rem)]`}),(0,Z.jsx)(Qt,{className:`h-4 w-[min(74%,32rem)]`}),(0,Z.jsx)(Qt,{className:`h-4 w-[min(48%,22rem)]`})]}),(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(Qt,{className:`h-11 w-[min(62%,18rem)] rounded-2xl`})})]}):(0,Z.jsxs)(Z.Fragment,{children:[G.loadingMore?(0,Z.jsx)(`div`,{className:`mb-3 text-center text-xs text-fg-muted`,children:w.chat.loadOlder}):null,Fe&&!c&&Ee?(0,Z.jsx)(Ho,{conversationId:Ee,language:x,running:q.streaming||q.sending}):null,Fe&&!c&&K.items.length>0?(0,Z.jsx)(p,{className:`mb-4 inline-block rounded-md px-2 py-1 text-xs text-fg-muted hover:bg-surface-hover`,to:`/automations`,children:x===`zh`?`← 定时任务`:`← Scheduled tasks`}):null,!r&&le?(0,Z.jsx)(`div`,{className:`hidden md:block`,children:(0,Z.jsx)(gc,{taskId:le})}):null,null,null,!r&&Ee?(0,Z.jsx)(H,{eventType:`session.transcript.updated`,source:`sessions`,payloadKey:`conversationId`,payloadValue:Ee,className:`mb-6`}):null,(0,Z.jsx)(fw,{scrollRef:He,messages:K.items,timelineEntries:l,personal:o,authToken:E??void 0,conversationId:G.decodedKey??G.conversationId,projectId:wt?.id,streaming:q.streaming,sending:q.sending,progress:q.progress,runError:q.error,reasoningLevel:G.reasoningLevel,showAssistantWorkLog:!0,registerListContentRef:Je,replySpaceRef:Xe,onPickWelcomePrompt:dt,welcomeSpotlight:Rt,welcomeOverlay:o&&s?(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full max-w-2xl flex-col items-start gap-3 px-4 py-8 text-fg`,children:[(0,Z.jsx)(`div`,{className:`flex size-16 items-center justify-center rounded-3xl bg-accent/10 text-3xl text-accent`,"aria-hidden":!0,children:s.avatar??`✦`}),(0,Z.jsx)(`h2`,{className:`text-2xl font-semibold`,children:x===`zh`?`你好${s.addressAs?`,${s.addressAs}`:``}。我们从哪里开始?`:`Hello${s.addressAs?`, ${s.addressAs}`:``}. Where should we start?`}),(0,Z.jsx)(`p`,{className:`max-w-xl text-sm leading-relaxed text-fg-muted`,children:s.opening??(x===`zh`?`想讨论问题、整理思路或推进工作,都可以直接说。`:`Bring a question, an idea, or work to move forward.`)})]}):Fe?(0,Z.jsxs)(`div`,{className:`mx-auto max-w-xl px-4 py-10 text-center`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-fg`,children:Ie?x===`zh`?`想怎么调整这个任务?`:`What would you like to change?`:x===`zh`?`你想安排什么任务?`:`What would you like to schedule?`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-fg-muted`,children:Ie?x===`zh`?`直接说要改的内容、时间,或告诉我暂停、恢复。`:`Change what it does or when it runs, or ask to pause or resume.`:x===`zh`?`说说要做的事,时间和细节我们一起确定。`:`Tell us what to do. We’ll work out the timing and details together.`}),c?null:(0,Z.jsx)(p,{className:`mt-4 inline-block text-xs text-fg-muted hover:text-fg`,to:`/automations`,children:x===`zh`?`← 返回定时任务`:`← Back to scheduled tasks`})]}):ye?(0,Z.jsx)($A,{agentName:Lt.name?.trim()||J.displayAgentId,messages:w.agentsSettings,disabled:G.sessionRoutePending||G.showSessionLoading,onPick:e=>{L.current+=1,B({id:L.current,text:e})}}):_e?(0,Z.jsx)(rT,{sk:w.skills,disabled:G.sessionRoutePending||G.showSessionLoading,onPick:e=>{L.current+=1,B({id:L.current,text:Ia(`find-skills`,e)})}}):void 0,compactWelcome:r,onDeleteRound:le?void 0:q.deleteMessageRound,onRetryUserMessageRound:le?void 0:q.retryUserMessageRound,deleteRoundDisabled:q.streaming||q.sending,onEditUserMessage:le?void 0:Ut,editLatestUserOnly:!0,editRequiresTurnId:!0,onSaveAssistantAsNote:Xt,onSaveAssistantToSourceNote:xt?Jt:void 0,onExtractAssistantTask:xt?$t:void 0,onForkAssistantTurn:!le&&Pe?.sessionType===`chat`?Le:void 0,trailingContent:ze?(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-2xl rounded-2xl border border-edge-subtle bg-surface-panel px-4 py-3 text-sm`,children:[(0,Z.jsx)(`p`,{className:`text-fg-muted`,children:x===`zh`?`这个回答合适吗?点选后可以在输入框修改,再发给我。`:`Did that response work for you? Pick an adjustment, edit it, then send.`}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[[[x===`zh`?`再短一点`:`Make it shorter`,x===`zh`?`这次回答再短一点。`:`Please make this answer shorter.`],[x===`zh`?`更温和一点`:`A little gentler`,x===`zh`?`这次回答的语气更温和一点。`:`Please make this answer a little gentler.`]].map(([e,t])=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Be(t),className:`rounded-full border border-edge px-3 py-1.5 text-xs text-fg transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:e},e)),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Be(),className:`rounded-full px-3 py-1.5 text-xs text-fg-muted transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:x===`zh`?`这样就好`:`Looks good`})]})]}):null},Ee)]})})})}),(0,Z.jsx)(`div`,{ref:Ke,className:Y(`chat-composer-dock pointer-events-none absolute inset-x-0 bottom-0 z-10`,o?`[--chat-composer-bottom-radius:1.65rem]`:`[--chat-composer-bottom-radius:1rem]`,vt?`[--chat-composer-bottom-space:max(0.625rem,env(safe-area-inset-bottom))]`:`[--chat-composer-bottom-space:max(0.5rem,env(safe-area-inset-bottom))] sm:[--chat-composer-bottom-space:max(1rem,env(safe-area-inset-bottom))]`),children:(0,Z.jsx)(`div`,{className:r&&!o?`px-3`:`px-3 sm:px-5 xl:px-6`,children:(0,Z.jsxs)(`div`,{"data-chat-composer-frame":!0,"data-primary-chat-composer":!r||void 0,className:Y(`pointer-events-auto relative mx-auto w-full min-w-0 pb-[var(--chat-composer-bottom-space)]`,(!r||o||c)&&`max-w-[calc(var(--max-width-chat-frame)+14px)]`,vt?`pt-2.5`:`pt-2 sm:pt-4`),children:[(0,Z.jsx)(yw,{visible:!G.showSessionLoading&&!qe,onClick:()=>Ye(!0),running:q.streaming||q.sending}),(0,Z.jsx)(`div`,{className:`absolute bottom-full right-0 z-20 mb-2 flex items-center rounded-full border border-edge-subtle bg-surface-overlay p-1 shadow-elevated backdrop-blur-sm empty:hidden xl:hidden`,children:!r||c?(0,Z.jsx)(VA,{items:fe.items,activeMessageIndex:et+it,labels:qt,openLabel:w.chat.timelineOpen,closeLabel:w.chat.timelineClose,currentLabel:w.chat.timelineCurrent,onSelectMessage:lt}):null}),(0,Z.jsx)(Tf,{prompt:me.clarifyPrompt,submitting:me.clarifySubmitting,submitError:me.clarifySubmitError,labels:w.chat,onSubmit:me.submitClarifyAnswer,onAgentDecide:me.letAgentDecideClarification,onCancel:me.cancelClarification}),yt?(0,Z.jsx)(jO,{plan:yt.plan,changeSummary:yt.changeSummary,isStreaming:q.streaming,labels:{heading:w.chat.planHeading,stepProgress:w.chat.planStepProgress,completedProgress:w.chat.planCompletedProgress,finished:w.chat.planFinished,ended:w.chat.planEnded,planned:w.chat.planPlanned,filesChangedOne:w.chat.planFilesChanged_one,filesChangedOther:w.chat.planFilesChanged_other}}):null,_e&&K.items.length>0?(0,Z.jsx)(`div`,{className:`mb-2 text-right`,children:(0,Z.jsx)(p,{to:`/capabilities/skills`,className:`text-xs text-accent-fg hover:underline`,children:w.skills.findBack})}):null,(0,Z.jsx)(Zw,{}),(0,Z.jsx)(tT,{conversationId:G.conversationId,active:q.streaming||q.sending}),(0,Z.jsx)(CD,{personal:o,nextTurnSuggestionsEnabled:!q.streaming,onPersonalSendDispatched:o?$e:void 0,placeholder:o?q.streaming||q.sending?x===`zh`?`继续聊,或补充要求…`:`Keep talking or add a detail…`:x===`zh`?`发消息给「${s?.name||`Personal AI`}」…`:`Message ${s?.name||`Personal AI`}…`:ye?w.agentsSettings.setupComposerPlaceholder:_e?w.skills.findPlaceholder:void 0,composerContext:!ye&&!r&&!le&&!he&&!_t&&K.items.length===0?{project:wt,disabled:Nt||Ht.busy||gt&&!G.projectPreparation,environmentPicker:G.projectPreparation?(0,Z.jsx)(DD,{selection:Ht}):void 0,workspacePath:G.effectiveWorkspacePath,canChangeWorkspace:ft,onProjectChange:tn,onWorkspaceChange:rn}:void 0,contextRefs:Tt,pageContextPreview:jt&&At?(0,Z.jsx)(wD,{draft:jt,disabled:q.sending,waiting:q.streaming,onRemove:()=>ss.remove(At,jt)}):void 0,setContextRefs:Et,onDraftAttachmentsChange:Ot,disabled:u||ht||Ht.busy||Nt,sendDisabled:pe.controlPending||pe.control.phase===`stopping`||u||!G.modelConfigReady||!G.projectPreparation&&gt||!!(G.projectPreparation&&!Ht.allowed)||G.modelConfigSaving||Ht.busy||Nt,sending:q.sending,streaming:q.streaming,conversationId:G.conversationId,unboundDraftKey:G.conversationId?void 0:JSON.stringify([N,P.get(`projectId`)]),getDraftHandoffTarget:Ht.getDraftHandoffTarget,prepareContextSession:G.projectPreparation?Ht.prepareSession:void 0,welcomeDraftSeed:ee??z,welcomeSuggestion:!_e&&vt?zt:null,onAcceptWelcomeSuggestion:dt,thinkingLevel:G.thinkingLevel,modelSupportsThinking:G.modelSupportsThinking,onThinkingChange:G.onSessionThinkingLevelChange,onSend:Ht.send,composerMode:pe.composerMode,onRestoreEditor:pe.restoreEditor,onComposerHydrated:pe.markComposerHydrated,onReacquireEdit:Wt,inputControl:pe.control,onResumeQueue:()=>void pe.resumeQueue().catch(()=>{}),editingUserTurnId:he?.turnId,onCancelUserMessageEdit:Gt,onAbort:()=>void q.abort().catch(()=>{}),onAddPendingFollowUp:async(t,n,r,i,a)=>{let o=Bt.current;if(e&&(!await e()||o!==Bt.current))throw Error(x===`zh`?`请先保存笔记,再发送消息。`:`Save the note before sending.`);await pe.addPendingFollowUp(t,n,r,jt?.envelope,i,a),At&&jt&&ss.remove(At,jt)},onSteeringInterrupt:jt?void 0:async(t,n,r)=>{let i=Bt.current;return e&&(!await e()||i!==Bt.current)?!1:q.interruptAndSend(t,n,void 0,r)},pendingFollowUps:pe.pendingFollowUps,editingFollowUpId:pe.editingFollowUpId,onBeginEditFollowUp:pe.beginEditFollowUp,onCancelEditFollowUp:pe.cancelEditFollowUp,onCommitEditFollowUp:(e,t,n,r,i)=>pe.commitEditFollowUp(e,t,n,r,i),onPendingFollowUpRemove:pe.removePendingFollowUp,onPendingFollowUpMove:pe.movePendingFollowUp,onPendingFollowUpReorder:pe.reorderPendingFollowUp,onPendingFollowUpSteer:e=>void pe.steerPendingFollowUp(e).catch(()=>{}),onPendingFollowUpSend:e=>void pe.sendQueuedInput(e).catch(()=>{}),steeringFollowUpId:pe.steeringFollowUpId,sessionModel:G.sessionModel,showModelSelector:!o,onModelChange:G.onSessionModelChange,modelDisabled:gt&&!G.projectPreparation||Ht.busy||G.modelConfigSaving,onChatAgentChange:!o&&!ye&&!le&&J.showChatAgentSelector?J.onChatAgentChange:void 0,currentAgentId:J.displayAgentId,voiceAgentName:o&&s?s.name:Lt.name,voiceTaskId:le??void 0,prepareVoiceSession:G.projectPreparation?Ht.prepareSession:void 0})]})})})]})]}),(!r||c)&&Ee&&window.electronAPI?.terminal?(0,Z.jsx)(Q.Suspense,{fallback:null,children:(0,Z.jsx)(tj,{conversationId:Ee},Ee)}):null,(0,Z.jsx)(A,{open:re!==null,onOpenChange:e=>{!e&&!ae&&Kt()},children:(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[80] bg-scrim backdrop-blur-[1px]`}),(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[90] flex h-[min(82vh,42rem)] w-[min(100%-2rem,44rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-edge-subtle px-5 py-4`,children:[(0,Z.jsx)(k,{className:`text-base font-semibold text-fg`,children:w.chat.sourceNoteSaveDialogTitle}),(0,Z.jsx)(T,{className:`mt-1 text-sm text-fg-muted`,children:w.chat.sourceNoteSaveDialogDescription.replace(`{{title}}`,Ft)})]}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-5 py-4`,children:[se?(0,Z.jsxs)(`p`,{className:`rounded-lg border border-danger/25 bg-danger-soft px-3 py-2 text-sm text-danger`,role:`alert`,children:[w.chat.sourceNoteSaveFailed,`: `,se]}):null,(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:w.chat.sourceNoteSaveDialogHeadingLabel}),(0,Z.jsx)(`input`,{value:re?.heading??``,onChange:e=>ie(t=>t&&{...t,heading:e.target.value}),className:`h-10 rounded-lg border border-edge bg-surface-base px-3 text-sm font-normal text-fg outline-none transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20`,disabled:ae})]}),(0,Z.jsxs)(`label`,{className:`flex min-h-0 flex-1 flex-col gap-1.5 text-sm font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:w.chat.sourceNoteSaveDialogContentLabel}),(0,Z.jsx)(`textarea`,{value:re?.content??``,onChange:e=>ie(t=>t&&{...t,content:e.target.value}),className:`min-h-[18rem] flex-1 resize-none rounded-lg border border-edge bg-surface-base px-3 py-2 font-mono text-xs leading-relaxed text-fg outline-none transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20`,disabled:ae})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-5 py-4`,children:[(0,Z.jsx)(vi,{type:`button`,variant:`secondary`,onClick:Kt,disabled:ae,children:w.chat.sourceNoteSaveDialogCancel}),(0,Z.jsx)(vi,{type:`button`,variant:`primary`,onClick:()=>void Zt(),disabled:ae||!re?.content.trim(),children:ae?w.chat.sourceNoteSaveDialogSaving:w.chat.sourceNoteSaveDialogConfirm})]})]})]})})]})}):(0,Z.jsx)(`div`,{className:`mx-auto w-full max-w-[var(--max-width-chat-frame)] px-3 py-16 text-center text-sm leading-relaxed text-fg-muted sm:px-5`,children:w.chat.needToken})}export{ac as $,Yf as A,Tf as B,fp as C,fs as Ct,Qf as D,Zf as E,If as F,mc as G,gc as H,zf as I,Qs as J,lc as K,Af as L,Vf as M,Hf as N,Xf as O,Bf as P,fc as Q,jf as R,lp as S,ps as St,$f as T,hc as U,yf as V,pc as W,uc as X,$s as Y,dc as Z,_m as _,vs as _t,Ww as a,As as at,lm as b,hs as bt,Dw as c,Ds as ct,kw as d,ws as dt,Xs as et,Tw as f,Cs as ft,gm as g,ys as gt,hm as h,bs as ht,Qw as i,js as it,qf as j,ep as k,jw as l,Es as lt,fw as m,xs as mt,ej as n,Ks as nt,Bw as o,ks as ot,yw as p,Ss as pt,Zs as q,Xw as r,Ms as rt,zw as s,Os as st,nj as t,Ws as tt,Aw as u,Ts as ut,pm as v,_s as vt,np as w,rm as x,ms as xt,um as y,gs as yt,Df as z};
70
+ `,document.head.appendChild(e)}function ik(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return!e.textContent||!t||t.closest(`button, [hidden], [aria-hidden="true"], .sr-only, script, style`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=n.nextNode();for(;r;)t.push(r),r=n.nextNode();return t}function ak(e,t,n){let r=e.find(e=>e.end>t),i=[...e].reverse().find(e=>e.start<n);if(!r||!i)return null;let a=document.createRange();return a.setStart(r.node,t-r.start),a.setEnd(i.node,n-i.start),a}function ok(e,t){let n=t.toLowerCase(),r=e.toLowerCase();if(!n)return[];let i=[],a=0;for(;a<=r.length-n.length;){let e=r.indexOf(n,a);if(e<0)break;i.push({start:e,end:e+n.length}),a=e+Math.max(n.length,1)}return i}function sk(e,t){let n=t.trim();if(!n)return[];let r=[],i=e.querySelectorAll(`[data-chat-message-index]`);for(let e of i){let t=e.dataset.chatMessageIndex,i=t?Number.parseInt(t,10):NaN;if(!Number.isFinite(i))continue;let a=0;for(let t of e.querySelectorAll(`[data-chat-find-text]`)){let e=ik(t),o=[],s=``;for(let t of e){let e=t.textContent??``,n=s.length;s+=e,o.push({node:t,start:n,end:s.length})}for(let e of ok(s,n)){let t=ak(o,e.start,e.end);t&&(r.push({messageIndex:i,occurrence:a,range:t}),a+=1)}}}return r}function ck(e,t){let n=nk();if(!n||(rk(),n.registry.delete($O),n.registry.delete(ek),e.length===0))return;n.registry.set($O,new n.Highlight(...e.map(e=>e.range)));let r=e[t];r&&n.registry.set(ek,new n.Highlight(r.range))}function lk(){let e=nk();e?.registry.delete($O),e?.registry.delete(ek)}function uk(e,t,n=96){let r=t.range.getBoundingClientRect(),i=e.getBoundingClientRect(),a=i.top+n,o=i.bottom-24;r.top>=a&&r.bottom<=o||(iw(e),e.scrollTo({top:Math.max(0,e.scrollTop+r.top-a),behavior:window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`}))}function dk(e,t){return t===0?0:(e+t)%t}function fk(e){return`${e.displayIndex}:${e.occurrence}`}function pk(e,t){return e.length===t.length&&e.every((e,n)=>{let r=t[n];return r?.messageIndex===e.messageIndex&&r.occurrence===e.occurrence&&r.range.startContainer===e.range.startContainer&&r.range.startOffset===e.range.startOffset&&r.range.endContainer===e.range.endContainer&&r.range.endOffset===e.range.endOffset})}function mk(e){let t=(0,X.c)(66),{conversationId:n,taskId:r,messages:i,displayOffset:a,viewportRef:o,onRevealDisplayIndex:s}=e,[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=[],t[0]=f):f=t[0];let[p,m]=(0,Q.useState)(f),h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=[],t[1]=h):h=t[1];let[g,_]=(0,Q.useState)(h),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(0),E=(0,Q.useRef)(null),D=(0,Q.useRef)(null),O=(0,Q.useRef)(n),k=(0,Q.useDeferredValue)(u),A;if(t[2]!==a||t[3]!==p||t[4]!==g){let e=new Map(g.map(yk));for(let t of p){let n={displayIndex:a+t.messageIndex,occurrence:t.occurrence};e.set(fk(n),n)}A=[...e.values()].sort(vk),t[2]=a,t[3]=p,t[4]=g,t[5]=A}else A=t[5];let j=A,M;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>{requestAnimationFrame(()=>{E.current?.focus(),E.current?.select()})},t[6]=M):M=t[6];let N=M,P;t[7]===c?P=t[8]:(P=()=>{if(!c){D.current=document.activeElement instanceof HTMLElement?document.activeElement:null,l(!0);return}N()},t[7]=c,t[8]=P);let F=P,I,L;t[9]===c?(I=t[10],L=t[11]):(I=()=>{c&&N()},L=[N,c],t[9]=c,t[10]=I,t[11]=L),(0,Q.useLayoutEffect)(I,L);let R;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>{l(!1),d(``),m([]),_([]),y(!1),x(!1),C(!1),T(0),lk(),D.current?.focus(),D.current=null},t[12]=R):R=t[12];let z=R,B;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(B=e=>{d(e),T(0)},t[13]=B):B=t[13];let ee=B,V;t[14]===j.length?V=t[15]:(V=e=>{T(t=>dk(t+e,j.length))},t[14]=j.length,t[15]=V);let H=V,U,W;t[16]!==H||t[17]!==c||t[18]!==F?(U=()=>{let e=e=>{let t=e.metaKey||e.ctrlKey;if(t&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`f`){if(document.querySelector(`[role="dialog"][data-state="open"]`))return;e.preventDefault(),F();return}if(c){if(t&&!e.altKey&&e.key.toLowerCase()===`g`){e.preventDefault(),H(e.shiftKey?-1:1);return}e.key===`Escape`&&(e.preventDefault(),z())}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},W=[z,H,c,F],t[16]=H,t[17]=c,t[18]=F,t[19]=U,t[20]=W):(U=t[19],W=t[20]),(0,Q.useEffect)(U,W);let te;t[21]!==k||t[22]!==c||t[23]!==o?(te=()=>{let e=o.current;if(!c||!e||!k.trim()){m(_k),lk();return}let t=()=>{let t=sk(e,k);m(e=>pk(e,t)?e:t)};t();let n=null,r=new MutationObserver(()=>{n===null&&(n=requestAnimationFrame(()=>{n=null,t()}))});return r.observe(e,{childList:!0,subtree:!0,characterData:!0}),()=>{r.disconnect(),n!==null&&cancelAnimationFrame(n)}},t[21]=k,t[22]=c,t[23]=o,t[24]=te):te=t[24];let ne;t[25]!==k||t[26]!==i||t[27]!==c||t[28]!==o?(ne=[k,i,c,o],t[25]=k,t[26]=i,t[27]=c,t[28]=o,t[29]=ne):ne=t[29],(0,Q.useLayoutEffect)(te,ne);let re,ie;t[30]!==n||t[31]!==k||t[32]!==c||t[33]!==r?(re=()=>{let e=k.trim();if(!c||!n||!e){_([]),y(!1),x(!1),C(!1);return}let t=new AbortController;_([]),y(!1),x(!1),C(!0);let i=window.setTimeout(()=>{QO(n,e,{taskId:r,signal:t.signal}).then(e=>{_(e.matches),y(e.truncated)}).catch(e=>{e?.name!==`AbortError`&&(_([]),y(!1),x(!0))}).finally(()=>{t.signal.aborted||C(!1)})},150);return()=>{window.clearTimeout(i),t.abort()}},ie=[n,k,c,r],t[30]=n,t[31]=k,t[32]=c,t[33]=r,t[34]=re,t[35]=ie):(re=t[34],ie=t[35]),(0,Q.useEffect)(re,ie);let ae,oe;t[36]===j.length?(ae=t[37],oe=t[38]):(ae=()=>{T(e=>Math.min(e,Math.max(0,j.length-1)))},oe=[j.length],t[36]=j.length,t[37]=ae,t[38]=oe),(0,Q.useEffect)(ae,oe);let se,ce;t[39]!==w||t[40]!==j||t[41]!==a||t[42]!==p||t[43]!==s||t[44]!==o?(se=()=>{let e=j[w],t=o.current;if(!t||!e){ck(p,-1);return}let n=e.displayIndex-a,r=p.findIndex(t=>t.messageIndex===n&&t.occurrence===e.occurrence);ck(p,r),r>=0?uk(t,p[r]):s(e.displayIndex)},ce=[w,j,a,p,s,o],t[39]=w,t[40]=j,t[41]=a,t[42]=p,t[43]=s,t[44]=o,t[45]=se,t[46]=ce):(se=t[45],ce=t[46]),(0,Q.useLayoutEffect)(se,ce);let le;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(le=[],t[47]=le):le=t[47],(0,Q.useEffect)(hk,le);let ue,de;t[48]!==n||t[49]!==c?(ue=()=>{O.current!==n&&(O.current=n,c&&z())},de=[z,n,c],t[48]=n,t[49]=c,t[50]=ue,t[51]=de):(ue=t[50],de=t[51]),(0,Q.useEffect)(ue,de);let G,K;t[52]===H?(G=t[53],K=t[54]):(G=()=>H(-1),K=()=>H(1),t[52]=H,t[53]=G,t[54]=K);let fe;return t[55]!==w||t[56]!==j.length||t[57]!==b||t[58]!==c||t[59]!==u||t[60]!==v||t[61]!==S||t[62]!==F||t[63]!==G||t[64]!==K?(fe={open:c,query:u,inputRef:E,activeIndex:w,resultCount:j.length,truncated:v,limitedToLoaded:b,searching:S,setQuery:ee,show:F,close:z,previous:G,next:K},t[55]=w,t[56]=j.length,t[57]=b,t[58]=c,t[59]=u,t[60]=v,t[61]=S,t[62]=F,t[63]=G,t[64]=K,t[65]=fe):fe=t[65],fe}function hk(){return gk}function gk(){return lk()}function _k(e){return e.length===0?e:[]}function vk(e,t){return e.displayIndex-t.displayIndex||e.occurrence-t.occurrence}function yk(e){return[fk(e),e]}function bk(e){let t=String(e??``).trim();return!t||t===`new`?null:t}function xk(e){let t=String(e.streamConversationId??``).trim(),n=bk(e.routeConversationId);return!t||!n?!1:t===n}function Sk(e){let t=bk(e.routeConversationId);return t?e.cacheConversationId===t:!1}function Ck(e){let t=String(e.chatId??``).trim();if(!t)return!1;let n=bk(e.routeConversationId);return n?n===t:!1}function wk(e,t){return e?`new`:t??null}function Tk(e,t){if(!(e||!t))return decodeURIComponent(t)}function Ek(e){if(!e.viewConversationId||e.conversationId!==e.viewConversationId)return[];if(!e.streamingMsg)return e.messages;let t=e.messages[e.messages.length-1];if(t?.role===`assistant`&&e.streamingMsg.role===`assistant`){let n=ur([t,e.streamingMsg]);return[...e.messages.slice(0,-1),...n]}return[...e.messages,e.streamingMsg]}function Dk(e,t){let n=e[e.length-1];return n?.role!==`assistant`||n.turnId!==t?null:{messagesWithoutTail:e.slice(0,-1),tail:n}}function Ok(e){e()}function kk(e,t){return!!(e&&(e.localDraft||e.configVersion!==void 0)&&t?.some(t=>t.id===e.model))}function Ak(e){e.sendingRef.current=!1,e.streamingRef.current=!1}function jk(e){return e.isNewRoute?`creating-session`:e.sessionRoutePending||e.showSessionLoading||e.sessionContentLoading?`loading-history`:e.messageCount===0?`ready-empty`:`ready-conversation`}var Mk=new Map;async function Nk(e,t,n,r,i){let a=_.getState(),o=Mr([a.baseUrl,a.conversationId,e,t]),s=Mr({action:n,submission:r}),c=Mk.get(o);if(c){if(c.signature!==s)throw Error(`An answer is already being submitted`);return(await c.promise).clone()}let l=Pk(e,t,n,r,i).then(e=>{for(e.ok||Mk.delete(o);Mk.size>64;)Mk.delete(Mk.keys().next().value);return e},e=>{throw Mk.delete(o),e});return Mk.set(o,{signature:s,promise:l}),(await l).clone()}async function Pk(e,t,n,r,i){let a=_.getState().conversationId,o=Cf(e,t,`submission`,i),s={schemaVersion:2,action:n,...r,expectedVersion:t},c=Mr(s),l=await o.read();if(l&&l.signature!==c)throw Error(`The previous answer is awaiting confirmation. Retry the original answer before changing it.`);let u=l??{signature:c,body:{...s,idempotencyKey:crypto.randomUUID()}};if(await o.write(u),window.dispatchEvent(new CustomEvent(`clarification-submission-state`,{detail:{requestId:e,pending:!0}})),_.getState().conversationId!==a)throw Error(`Active Gateway changed`);let d=await h(g(`/api/clarifications/${encodeURIComponent(e)}/responses`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(u.body)});return(d.ok||d.status>=400&&d.status<500)&&(await o.write(void 0),window.dispatchEvent(new CustomEvent(`clarification-submission-state`,{detail:{requestId:e,pending:!1}})),d.ok&&await Cf(e,t,`draft`,i).write(void 0)),d}async function Fk(e,t,n){let r=()=>{if(!n())throw new DOMException(`Conversation changed`,`AbortError`)},i=await Fr(e);if(r(),i&&(i.kind!==`append`||i.execution||i.delivery!==t.delivery||Mr(i.input)!==Mr(t.input)||!!i.interrupt!=!!t.interrupt))throw Error(`The previous input is awaiting confirmation`);let a=Ir.parse({...i??t,origin:t.origin}),o=t=>{let n=t?.receipt;if(!n||n.conversationId!==e||n.clientMessageId!==a.clientMessageId||n.transcriptId!==a.expectedTranscriptId||t?.session?.transcriptId!==n.transcriptId)throw Error(`Invalid input receipt or conversation was reset; reload before sending`);if(!t?.inputState)throw Error(`Gateway returned an invalid input state`);return t.inputState},s=async t=>{let n=await h(g(`/api/sessions/${encodeURIComponent(e)}/input-receipts/${encodeURIComponent(a.clientMessageId)}`),{signal:t}),i=await n.json();if(r(),n.ok)return o(i.payload);if(n.status!==404||i.error?.code!==`NOT_RECEIVED`)throw Error(i.error?.message??`Input receipt lookup failed`)},c=async t=>(r(),await Rr(e,a.clientMessageId),r(),t);if(i){let e=await s();if(e!==void 0)return c(e)}let{origin:l,...u}=a;await zr(e,u),r();let d,f;try{d=await h(g(`/api/sessions/${encodeURIComponent(e)}/inputs`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(a)});let t=await d.json();if(r(),!d.ok)throw Error(typeof t.error==`string`?t.error:t.error?.message??`Message was not accepted`);f=o(t.payload)}catch(t){if(r(),d&&d.status>=400&&d.status<500&&d.status!==408)throw await Rr(e,a.clientMessageId),t;if(f=await s(AbortSignal.timeout(3e3)).catch(()=>void 0),r(),f===void 0)throw t}return c(f)}function Ik(e,t){if(!e||typeof e!=`object`)return null;let n=e,r=n.clarification&&typeof n.clarification==`object`?n.clarification:n;if(r.status!==void 0&&r.status!==`open`||t&&typeof r.conversationId==`string`&&r.conversationId!==t)return null;let i=typeof r.id==`string`?r.id:r.requestId,a=r.question,o=r.kind===`approval`?`approval`:`input`;return typeof i!=`string`||!i.trim()||typeof a!=`string`||!a.trim()?null:{...kr(r),requestId:i.trim(),conversationId:t,kind:o,question:a.trim(),version:typeof r.version==`number`?r.version:1,createdAt:typeof r.createdAt==`number`?r.createdAt:Date.now(),expiresAt:typeof r.expiresAt==`number`?r.expiresAt:void 0,serverTime:typeof n.serverTime==`number`?n.serverTime:void 0}}function Lk(e){let{conversationId:t,decodedKey:n,conversationIdRef:r,sendingRef:i,streamingRef:a,modelSupportsThinking:o,thinkingLevel:s,shouldApplyStreamUpdate:c}=e,l=_(e=>e.conversationId),u=(0,Q.useRef)({gateway:l,conversationId:t});(u.current.gateway!==l||u.current.conversationId!==t)&&(u.current={gateway:l,conversationId:t});let d=(0,Q.useCallback)(()=>{let e=u.current;return()=>u.current===e&&r.current===e.conversationId&&_.getState().conversationId===e.gateway},[r]),[f,p]=(0,Q.useState)(null),[m,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),x=(0,Q.useRef)(null),S=(0,Q.useRef)(0),C=(0,Q.useRef)(null),[w,T]=(0,Q.useState)([]),E=(0,Q.useRef)([]),[D,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(()=>({scope:u.current,mode:{kind:`compose`}})),j=k.scope===u.current?k.mode:{kind:`compose`},M=(0,Q.useCallback)(e=>A({scope:u.current,mode:e}),[]),N=(0,Q.useRef)(j);N.current=j;let P=j.kind===`editFollowUp`?j.inputId:null,F=e=>M(e?{kind:`editFollowUp`,inputId:e,version:E.current.find(t=>t.id===e)?.version??0}:{kind:`compose`}),[I,L]=(0,Q.useState)(()=>mr(t??``)),[R,z]=(0,Q.useState)(!1),B=(0,Q.useRef)(!1),ee=(0,Q.useRef)(null),V=(0,Q.useRef)(-1),[H,U]=(0,Q.useState)(!1),W=(0,Q.useRef)(null),[te,ne]=(0,Q.useState)(null),re=(0,Q.useCallback)(()=>ne(u.current),[]);x.current=f,E.current=w,ee.current=P;let ie=(0,Q.useCallback)(e=>{if(!e||typeof e!=`object`)return;let t=e;if(t.conversationId!==r.current||typeof t.revision!=`number`||!Array.isArray(t.inputs)||t.revision<V.current)return;if(t.control){if(!vr(t.conversationId,t.control,t.revision))return;L(t.control)}let n=xT({control:t.control,inputs:t.inputs,activeRunId:t.activeRunId,preparation:t.preparation});V.current=t.revision,U(!t.activeRunId&&t.inputs.length===0),E.current=n,T(n)},[r]),ae=(0,Q.useCallback)(async e=>{if(e!==r.current)return;let t=d();if(await jr(e)||!t())return;let n=await h(g(`/api/sessions/${encodeURIComponent(e)}/input-state`)).catch(()=>null);if(!n?.ok||r.current!==e)return;let i=await n.json().catch(()=>null);t()&&ie(i?.payload)},[ie,d,r]),oe=(0,Q.useCallback)(async e=>{if(e!==r.current)return;let t=d(),n=++S.current;if(await jr(e)||!t())return;let i=await h(g(`/api/sessions/${encodeURIComponent(e)}/clarification`)).catch(()=>null);if(!i?.ok||r.current!==e)return;let a=await i.json().catch(()=>null);!t()||n!==S.current||r.current!==e||(b(null),p(Ik(a?.payload,e)),C.current=null)},[d,r]);(0,Q.useLayoutEffect)(()=>{V.current=-1,U(!1),W.current=null,B.current=!1,z(!1),O(null),S.current++,L(mr(t??``)),M({kind:`compose`}),E.current=[],T([]),F(null),p(null)},[t,l]),(0,Q.useEffect)(()=>{!t||t!==n||(ae(t),oe(t))},[n,oe,ae,t,l]),(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail;ie(t);let n=r.current;n&&t&&typeof t==`object`&&t.conversationId===n&&oe(n)},t=e=>{let t=r.current;if(!t)return;let n=e.detail;if(n&&typeof n==`object`){let e=n.conversationId;if(typeof e==`string`&&e!==t)return}b(null),S.current++,p(Ik(n,t)),C.current=null},n=()=>{let e=r.current;e&&(ae(e),oe(e))};return window.addEventListener(`session-input-state`,e),window.addEventListener(`clarification-updated`,t),window.addEventListener(`gateway-realtime-connected`,n),()=>{window.removeEventListener(`session-input-state`,e),window.removeEventListener(`clarification-updated`,t),window.removeEventListener(`gateway-realtime-connected`,n)}},[ie,oe,ae,r]),(0,Q.useEffect)(()=>{if(!f?.expiresAt)return;let e=Math.max(0,f.expiresAt-Date.now())+250,t=window.setTimeout(()=>{let e=r.current;e&&oe(e)},e);return()=>window.clearTimeout(t)},[f?.expiresAt,oe,r]);let se=(0,Q.useCallback)(()=>{b(null),p(null)},[]),ce=(0,Q.useCallback)(e=>{let t=String(e??``).trim();t&&r.current===t&&(b(null),p(null))},[r]),le=(0,Q.useCallback)(()=>{b(null),p(null)},[]),ue=(0,Q.useCallback)(()=>{F(null)},[]),de=(0,Q.useCallback)(()=>{b(null),p(null),F(null)},[]),G=(0,Q.useCallback)(e=>t=>{c(e)&&(i.current=!1,a.current=!1,Sn.getState().setSessionFlags(e,{sending:!1,streaming:!1}),Sn.getState().setSessionProgress(e,null),b(null),S.current++,p({...t,conversationId:e}),C.current=null)},[c,i,a]),K=(0,Q.useCallback)(async(e,t,n,i,a,o)=>{let s=e.trim();if(!s&&!t?.length&&!n?.length)return;let c=r.current;if(!c)throw Error(`No active session`);let l=d(),u=mr(c),f=await Lr(c);if(!l())throw new DOMException(`Conversation changed`,`AbortError`);let p=await ir();if(!l())throw new DOMException(`Conversation changed`,`AbortError`);if(!f)throw Error(`Reload the conversation before sending`);let m=Sn.getState().sessions[c]?.configVersion;if(m===void 0)throw Error(`Reload the conversation before sending`);let h=await Fk(c,{kind:`append`,expectedTranscriptId:f,configVersion:m,clientMessageId:crypto.randomUUID(),delivery:o??`next`,interrupt:a,controlVersion:u.version,input:{content:s||e,attachments:t?.length?t:void 0,contextRefs:n?.map(({refId:e,kind:t,sourceId:n,expectedVersion:r})=>({refId:e,kind:t,sourceId:n,expectedVersion:r})),appContext:i},origin:p},l);l()&&ie(h)},[ie,d,r]),fe=(0,Q.useCallback)(async(e,t)=>{let n=r.current;if(!n||B.current)throw Error(`Wait for the current operation`);let i=d(),a=()=>{if(!i())throw new DOMException(`Conversation changed`,`AbortError`)};B.current=!0,z(!0);try{let r=await Lr(n);a();let i=Date.now()+15e3;for(;!r&&e===`stop`&&Date.now()<i;)await new Promise(e=>setTimeout(e,100)),r=await Lr(n),a();if(!r)throw Error(`Input acceptance is awaiting confirmation`);if(t?.onlyIfEmpty&&N.current.kind!==`compose`)return;let o={action:e,operationId:crypto.randomUUID(),expectedTranscriptId:r,expectedVersion:mr(n).version,...t},s=await Qn(n,o);if(a(),ie(s),e===`steer`){let e=s.inputs?.find(e=>e.id===t?.inputId);if(e?.status===`interrupted`)throw Error(e.error??`Current reply ended before steering`)}if(e===`stop`){let e=Date.now()+15e3;for(;mr(n).phase===`stopping`;){if(a(),Date.now()>=e)throw Error(`Stop is awaiting confirmation`);await new Promise(e=>setTimeout(e,100)),await ae(n)}}if(a(),e===`stop`||e===`pause`){let t=mr(n);if(!t.paused||t.version!==o.expectedVersion+1)throw Error(`Queue control changed on another device`);if(e===`stop`&&t.phase!==`idle`)throw Error(`Another input has started`)}}catch(e){throw!i()||(await ae(n),!i())||t?.onlyIfEmpty||ya(`error`,e instanceof Error?e.message:String(e)),e}finally{i()&&(B.current=!1,z(!1))}},[ie,d,r,ae]);(0,Q.useEffect)(()=>{if(!t||!H||!I.paused||I.phase!==`idle`||R||j.kind!==`compose`||te!==u.current)return;let e=`${l}:${t}:${I.version}:${V.current}`;if(W.current===e)return;let n=window.setTimeout(()=>{B.current||N.current.kind!==`compose`||(W.current=e,fe(`resume`,{onlyIfEmpty:!0}).catch(()=>{}))},0);return()=>window.clearTimeout(n)},[fe,j.kind,I.paused,I.phase,I.version,R,t,l,te,H]);let q=(0,Q.useCallback)(()=>fe(`stop`),[fe]),pe=(0,Q.useCallback)(()=>fe(`resume`),[fe]),me=(0,Q.useCallback)(async(e,t)=>{let n=d();try{return await fe(`stop`,{turnId:e}),n()?(M({kind:`editTurn`,turnId:e,draft:t}),!0):!1}catch{return!1}},[d,fe]),J=(0,Q.useCallback)(async e=>{let t=E.current.find(t=>t.id===e);if(!t)return!1;let n=d();try{return await fe(`pause`,{inputId:e,inputVersion:t.version}),n()?(M({kind:`editFollowUp`,inputId:e,version:t.version}),!0):!1}catch{return!1}},[d,fe]),he=(0,Q.useCallback)(()=>M({kind:`compose`}),[]),ge=(0,Q.useCallback)(async(e,t,n,i,a)=>{let c=r.current;if(!c||j.kind!==`editFollowUp`||j.inputId!==e||!t.trim()&&!n?.length&&!a?.length)return!1;let l=d(),u=await h(g(`/api/sessions/${encodeURIComponent(c)}/inputs/${encodeURIComponent(e)}`),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({version:j.version,content:t,attachments:n??[],thinking:o?i??s:`off`,contextRefs:(a??[]).map(({refId:e,kind:t,sourceId:n,expectedVersion:r})=>({refId:e,kind:t,sourceId:n,expectedVersion:r}))})}),f=await u.json();if(!l())return!1;if(ie(f.payload),!u.ok)throw Error(f.error?.message??`This input changed; your draft has been preserved`);if(N.current===j){let t=f.payload?.inputs?.find(t=>t.id===e);t&&M({...j,version:t.version})}return!0},[ie,d,j,r,o,s]),_e=(0,Q.useCallback)(e=>{ee.current===e&&F(null);let t=r.current,n=E.current.find(t=>t.id===e);if(!t||!n)return;let i=d();h(g(`/api/sessions/${encodeURIComponent(t)}/inputs/${encodeURIComponent(e)}?version=${n.version}`),{method:`DELETE`}).then(async e=>{let t=await e.json().catch(()=>null);i()&&ie(t?.payload)}).catch(()=>{ae(t)})},[ie,d,ae,r]),ve=(0,Q.useCallback)((e,t)=>{let n=E.current.filter(e=>e.status===`queued`),i=n.findIndex(t=>t.id===e);if(i<0)return;let a=t===`up`?i-1:i+1,o=r.current,s=n[i];if(!o||!s||a<0||a>=n.length)return;let c=d();h(g(`/api/sessions/${encodeURIComponent(o)}/inputs/${encodeURIComponent(s.id)}`),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({version:s.version,position:a})}).then(async e=>{let t=await e.json().catch(()=>null);c()&&ie(t?.payload)}).catch(()=>{ae(o)})},[ie,d,ae,r]),ye=(0,Q.useCallback)((e,t)=>{let n=r.current,i=E.current[e],a=E.current[t],o=E.current.filter(e=>e.status===`queued`),s=a?o.findIndex(e=>e.id===a.id):-1;if(!n||i?.status!==`queued`||a?.status!==`queued`||s<0)return;let c=d();h(g(`/api/sessions/${encodeURIComponent(n)}/inputs/${encodeURIComponent(i.id)}`),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({version:i.version,position:s})}).then(async e=>{let t=await e.json().catch(()=>null);c()&&ie(t?.payload)}).catch(()=>{ae(n)})},[ie,d,ae,r]),be=(0,Q.useCallback)(async(e,t)=>{let n=E.current.find(t=>t.id===e);if(!n)return;let r=d();O(e);try{await fe(t,{inputId:e,inputVersion:n.version})}finally{r()&&O(null)}},[d,fe]),xe=(0,Q.useCallback)(e=>be(e,`steer`),[be]),Se=(0,Q.useCallback)(e=>be(e,`send`),[be]),Ce=(0,Q.useCallback)(async(e,t)=>{let n=x.current;if(!n)return;let i=JSON.stringify([n.requestId,n.version,e,t]);C.current?.signature!==i&&(C.current={signature:i,idempotencyKey:crypto.randomUUID()});let a=C.current.idempotencyKey;v(!0),b(null);try{let i=n.schemaVersion===2?await Nk(n.requestId,n.version,e,t,r.current??void 0):await h(g(`/api/clarifications/${encodeURIComponent(n.requestId)}/responses`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:e,...t,expectedVersion:n.version,idempotencyKey:a})});if(x.current?.requestId!==n.requestId)return;if(!i.ok){let e=await i.json().catch(()=>({}));b(e.error?.message??i.statusText??`Clarify failed`);let t=r.current;t&&(i.status===409||i.status===410)&&oe(t);return}C.current=null,p(null),b(null)}catch(e){x.current?.requestId===n.requestId&&b(e instanceof Error?e.message:String(e))}finally{v(!1)}},[oe,r]);return{clarifyPrompt:f,clarifySubmitting:m,clarifySubmitError:y,clarifyPromptRef:x,pendingFollowUps:w,pendingFollowUpsRef:E,steeringFollowUpId:D,composerMode:j,control:I,controlPending:R,stopSession:q,resumeQueue:pe,sendQueuedInput:Se,beginEditTurn:me,cancelEditor:he,restoreEditor:M,markComposerHydrated:re,editingFollowUpId:P,addPendingFollowUp:K,beginEditFollowUp:J,cancelEditFollowUp:he,commitEditFollowUp:ge,removePendingFollowUp:_e,movePendingFollowUp:ve,reorderPendingFollowUp:ye,steerPendingFollowUp:xe,submitClarifyAnswer:(0,Q.useCallback)(e=>Ce(`answer`,e),[Ce]),letAgentDecideClarification:(0,Q.useCallback)(()=>Ce(`agent_decide`),[Ce]),cancelClarification:(0,Q.useCallback)(()=>Ce(`cancel`),[Ce]),clearVisibleClarify:se,dismissClarify:le,dismissClarifyForSession:ce,clearPendingFollowUps:ue,dismissClarifyAndClearPending:de,makeOnClarifyRequest:G}}async function Rk(e){let t=await jr(e);if(t)return{agentId:t.creation.agentId.trim().toLowerCase(),projectId:t.creation.projectId?.trim()||null};let n=await hn(e);return{agentId:(n.routing?.agentId??n.agentId).trim().toLowerCase(),projectId:n.projectId?.trim()||null}}function zk(e){let t=(0,X.c)(59),{navigate:n,conversationIdRef:r,conversationId:i,isNewRoute:a,locationState:o,locationSearch:s,personal:c}=e,l=c!==void 0&&c,u=_(Uk),d;t[0]===i?d=t[1]:(d=i?.trim()??``,t[0]=i,t[1]=d);let f=d,p;t[2]===u?p=t[3]:(p=u?[`gateway-chat-agents`,u]:null,t[2]=u,t[3]=p);let m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m={revalidateOnFocus:!1},t[4]=m):m=t[4];let{data:h,mutate:g}=Qr(p,si,m),v;t[5]!==f||t[6]!==u?(v=u&&f?[`gateway-chat-session-agent`,u,f]:null,t[5]=f,t[6]=u,t[7]=v):v=t[7];let y;t[8]===f?y=t[9]:(y=()=>Rk(f),t[8]=f,t[9]=y);let b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b={revalidateOnFocus:!1},t[10]=b):b=t[10];let{data:x}=Qr(v,y,b),S=x?.agentId??``,C,w;t[11]===g?(C=t[12],w=t[13]):(C=()=>{let e=e=>{oi(e.detail)||g()};return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},w=[g],t[11]=g,t[12]=C,t[13]=w),(0,Q.useEffect)(C,w);let[T,E]=(0,Q.useState)(Hk),D=(0,Q.useRef)(h??null),O;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(O=Yr().selectedAgentId??null,t[14]=O):O=t[14];let k=(0,Q.useRef)(O),A,j;t[15]===h?(A=t[16],j=t[17]):(A=()=>{D.current=h??null},j=[h],t[15]=h,t[16]=A,t[17]=j),(0,Q.useEffect)(A,j);let M,N;t[18]===T?(M=t[19],N=t[20]):(M=()=>{k.current=T},N=[T],t[18]=T,t[19]=M,t[20]=N),(0,Q.useEffect)(M,N);let P,F;t[21]===h?(P=t[22],F=t[23]):(P=()=>{if(!h)return;let e=new Set(h.items.map(Vk));E(t=>t==null||t===``||!e.has(t)?h.defaultId:t)},F=[h],t[21]=h,t[22]=P,t[23]=F),(0,Q.useEffect)(P,F);let I;t[24]!==r||t[25]!==S?(I=()=>{if(r.current&&S)return S;let e=D.current,t=(k.current??``).trim().toLowerCase();if(!e)return t||void 0;let n=new Set(e.items.map(Bk));return t&&n.has(t)?t:e.defaultId},t[24]=r,t[25]=S,t[26]=I):I=t[26];let L=I,R;t[27]!==r||t[28]!==S||t[29]!==x?.projectId||t[30]!==a||t[31]!==s||t[32]!==o||t[33]!==n?(R=e=>{let t=e.trim().toLowerCase(),i=r.current?S||k.current:null;k.current=t,E(t),Vr(t),i!==t&&n(a?`/chat/new${s}`:Ra(x?.projectId),{replace:!1,state:{...a&&o&&typeof o==`object`?o:{},agentId:t,forceNewChat:!0}})},t[27]=r,t[28]=S,t[29]=x?.projectId,t[30]=a,t[31]=s,t[32]=o,t[33]=n,t[34]=R):R=t[34],x?.projectId;let z=R,B,ee;t[35]===z?(B=t[36],ee=t[37]):(B=()=>{let e=e=>{let t=e.detail?.agentId;typeof t!=`string`||!t.trim()||z(t)};return window.addEventListener(`xopc-set-chat-agent`,e),()=>window.removeEventListener(`xopc-set-chat-agent`,e)},ee=[z],t[35]=z,t[36]=B,t[37]=ee),(0,Q.useEffect)(B,ee);let V,H;t[38]!==i||t[39]!==S||t[40]!==l?(V=()=>{if(!i||l)return;let e=S;!e||k.current===e||(k.current=e,E(e),Vr(e))},H=[S,i,l],t[38]=i,t[39]=S,t[40]=l,t[41]=V,t[42]=H):(V=t[41],H=t[42]),(0,Q.useLayoutEffect)(V,H);let U,W;t[43]!==i||t[44]!==x?(U=()=>{!i||!x||qr(x.projectId)},W=[x,i],t[43]=i,t[44]=x,t[45]=U,t[46]=W):(U=t[45],W=t[46]),(0,Q.useLayoutEffect)(U,W);let te,ne;t[47]!==a||t[48]!==o?(te=()=>{if(!a)return;let e=o,t=typeof e?.agentId==`string`?e.agentId.trim().toLowerCase():``;t&&(k.current=t,E(t),Vr(t))},ne=[a,o],t[47]=a,t[48]=o,t[49]=te,t[50]=ne):(te=t[49],ne=t[50]),(0,Q.useLayoutEffect)(te,ne);let re=S||T||h?.defaultId||`main`,ie=(h?.items.length??0)>1,ae=x?.projectId??null,oe;return t[51]!==h||t[52]!==re||t[53]!==z||t[54]!==L||t[55]!==ie||t[56]!==ae||t[57]!==u?(oe={token:u,chatAgentsData:h,resolveAgentIdForPost:L,onChatAgentChange:z,displayAgentId:re,showChatAgentSelector:ie,currentSessionProjectId:ae},t[51]=h,t[52]=re,t[53]=z,t[54]=L,t[55]=ie,t[56]=ae,t[57]=u,t[58]=oe):oe=t[58],oe}function Bk(e){return e.id}function Vk(e){return e.id}function Hk(){return Yr().selectedAgentId??null}function Uk(e){return e.conversationId}async function Wk(e){let t=await e.sessionMgr.createSession(e);return{kind:`create`,conversationId:t.key,session:t}}var Gk=new Map,Kk=0;function qk(e){let t=_.getState(),n=Hr(t.baseUrl,{agentId:e.agentId?.trim()||`main`,projectId:e.projectId??null}),r=JSON.stringify([n,t.conversationId,e.forceNew===!0,e.temporary===!0,e.executionMode,e.search]),i=Gk.get(r);if(i)return i.target.opts=e,i.target.generation=++Kk,i.promise;let a={opts:e,generation:++Kk},o=e=>{if(a.generation!==Kk)return;let t=a.opts;!t.routeConversationId&&yi.getState().scope===`new`&&yi.getState().migrateScope(`new`,e),t.onOpened(e),(t.routeConversationId?.trim()||null)!==e&&t.navigateToSession(e,t.replaceNavigate??!1,t.search)},s=(async()=>{let t=e.agentId??void 0,{conversationId:n}=await Wk({sessionMgr:e.sessionMgr,agentId:t?.trim()||`main`,projectId:e.projectId,currentConversationId:e.currentConversationId,forceNew:e.forceNew,temporary:e.temporary,initialAgentConfig:e.initialAgentConfig,executionMode:e.executionMode});return o(n),n})().finally(()=>{Gk.delete(r)});return Gk.set(r,{promise:s,target:a}),s}var Jk={current:null},Yk={current:null};function Xk(e){return!!(e&&typeof e==`object`&&e.forceNewChat===!0)}function Zk(e){let t=d(),{conversationId:n}=u(),r=!e&&t.pathname.endsWith(`/new`),i=r&&Xk(t.state),a=e??Tk(r,n),o=wk(r,a),s=bk(o),c=r?null:a??null,l=(0,Q.useRef)(o);return l.current=o,Jk.current=c,!r&&a&&(Yk.current=a),(0,Q.useLayoutEffect)(()=>{Sn.getState().focusedConversationId!==c&&Sn.getState().setFocusedConversationId(c)},[c]),{isNewRoute:r,forceNewChat:i,decodedKey:a,routedConversationId:o,viewConversationId:s,routedFocusedConversationId:c,routeConversationIdRef:l,locationKey:t.key,locationSearch:t.search,locationState:t.state}}var Qk={get current(){return Yk.current}},$k={get current(){return Jk.current},set current(e){Jk.current=e,Sn.getState().setFocusedConversationId(e)}};function eA(e){let{token:t,isNewRoute:n,forceNewChat:r,temporary:i=!1,requestedAgentId:a,decodedKey:o,locationKey:s,locationSearch:c,sessionMgrRef:l,resolveAgentIdForPost:u,navigateToSession:d,loadSessionById:f,tryResumeAgentRun:p,restoreLiveCacheIfNeeded:m,adoptEmptySession:h,applyAgentConfig:g,patchInitUi:v}=e,y=(0,Q.useRef)(0),b=_(e=>e.baseUrl),[x,S]=(0,Q.useState)(null),C=n?c:``,w=n?`new:${s}`:o?`session:${o}`:`fallback:${s}`,T=(0,Q.useRef)({isNewRoute:n,forceNewChat:r,temporary:i,requestedAgentId:a,decodedKey:o,newRouteLocationSearch:C});T.current={isNewRoute:n,forceNewChat:r,temporary:i,requestedAgentId:a,decodedKey:o,newRouteLocationSearch:C};let E=(0,Q.useRef)({sessionMgrRef:l,resolveAgentIdForPost:u,navigateToSession:d,loadSessionById:f,tryResumeAgentRun:p,restoreLiveCacheIfNeeded:m,adoptEmptySession:h,applyAgentConfig:g,patchInitUi:v});return E.current={sessionMgrRef:l,resolveAgentIdForPost:u,navigateToSession:d,loadSessionById:f,tryResumeAgentRun:p,restoreLiveCacheIfNeeded:m,adoptEmptySession:h,applyAgentConfig:g,patchInitUi:v},(0,Q.useEffect)(()=>{let e=T.current,n=E.current;if(!t){n.patchInitUi({loading:!1});return}let r=++y.current,i=!1,a=()=>!i&&r===y.current,o=e=>{a()&&n.sessionMgrRef.current.loadSessionAgentConfig(e).then(t=>{a()&&n.applyAgentConfig(e,t)}).catch(()=>{})},s=async()=>{if(!a())return Promise.resolve();let r=Yr(),i=n.resolveAgentIdForPost(),s=Wr({origin:`web-route`,project:Ba(e.newRouteLocationSearch),agentId:e.requestedAgentId??i,forceNew:e.forceNewChat,temporary:e.temporary},{defaultAgentId:i??`main`,selectedAgentId:r.selectedAgentId,lastChatScope:r.lastChatScope}),c=s.projectId?await fn(s.projectId):null;if(!a())return;!e.requestedAgentId&&c?.defaultAgentId&&(s.agentId=c.defaultAgentId);let l=Jr(r,s.agentId),u=(t,r,i)=>qk({sessionMgr:n.sessionMgrRef.current,agentId:s.agentId,currentConversationId:Qk.current,routeConversationId:null,forceNew:s.forceNew,temporary:s.temporary,projectId:s.projectId,executionMode:t,initialAgentConfig:r??(l?{model:l.modelRef,...l.thinkingLevel?{thinkingLevel:l.thinkingLevel}:{}}:void 0),navigateToSession:(...e)=>{a()&&n.navigateToSession(...e)},replaceNavigate:!0,search:Fa(e.newRouteLocationSearch),onOpened:e=>{a()&&(i?.(e),n.adoptEmptySession(e,null),o(e))}});if(c?.workspaceRoot?.trim()){S({requestKey:w,token:t,baseUrl:b,project:c,agentId:s.agentId,temporary:s.temporary,create:(e,t,n)=>a()?u(e,t,n):Promise.reject(Error(`New chat request changed`))});return}await u()},c=(e,t)=>{if(!a())return Promise.resolve();n.restoreLiveCacheIfNeeded(e);let r=Ln(e)?.messages??t??bn(e);return n.tryResumeAgentRun(e,r)},l=e=>a()?Ln(e)?.historyStatus===`ready`?(o(e),c(e,bn(e))):n.loadSessionById(e,0).then(t=>{if(a())return c(e,t??bn(e))}):Promise.resolve(),u=()=>a()?n.sessionMgrRef.current.loadSessions().then(e=>{if(!a())return;let t=e.filter(e=>(e.messageCount??0)>0)[0]??e[0];if(t)return a()?n.loadSessionById(t.key,0).then(e=>{if(!a())return;n.restoreLiveCacheIfNeeded(t.key);let r=Ln(t.key)?.messages??e??bn(t.key);return n.sessionMgrRef.current.parseSessionFromHash()||n.navigateToSession(t.key,!0),n.tryResumeAgentRun(t.key,r)}):void 0;if(!a())return;let r=n.resolveAgentIdForPost();return qk({sessionMgr:n.sessionMgrRef.current,agentId:r,currentConversationId:null,routeConversationId:null,navigateToSession:n.navigateToSession,onOpened:e=>{n.adoptEmptySession(e,null),o(e)}}).then(()=>void 0)}):Promise.resolve();return(()=>{let t=e.decodedKey===void 0&&!e.isNewRoute;n.patchInitUi({loading:t,error:null}),(e.isNewRoute?s():e.decodedKey?l(e.decodedKey):u()).then(()=>{a()&&n.patchInitUi({loading:!1})}).catch(e=>{i?a()&&n.patchInitUi({loading:!1}):n.patchInitUi({error:e instanceof Error?e.message:`Chat init failed`,loading:!1})})})(),()=>{i=!0}},[t,b,w]),n&&x?.requestKey===w&&x.token===t&&x.baseUrl===b?x:null}function tA(e){let t=_(e=>e.conversationId),n=_(e=>e.baseUrl),[r,i]=(0,Q.useState)(null),{data:a,error:o}=Qr(e?[`prepared-session-model`,n,t,e.create]:null,async()=>{let t=Jr(Yr(),e.agentId),[n,r]=await Promise.all([hi(),t?.modelRef??_i(e.agentId).then(e=>e.config.models.chat.primary)]),i=n.filter(e=>e.id===r||e.id.endsWith(`/${r}`)),a=n.find(e=>e.id===r)??(i.length===1?i[0]:void 0);return{models:n,selection:{model:a?.id??r,thinkingLevel:a?.thinking?Xr(a.thinking,t?.thinkingLevel,t?.thinkingByModel?.[a.id]):t?.thinkingLevel??`medium`}}},{revalidateOnFocus:!1}),s=r?.preparation===e?r?.selection:a?.selection,c=a?.models.find(e=>e.id===s?.model),l=!!(s?.model&&c),u=r?.preparation===e,d=(0,Q.useRef)({preparation:e,selection:s,ready:l,explicitlySelected:u});d.current={preparation:e,selection:s,ready:l,explicitlySelected:u};let f=(0,Q.useMemo)(()=>e&&{...e,create:async(t,n,r)=>{let i=d.current;if(i.preparation!==e||!i.ready||!i.selection)throw Error(`Model configuration is not ready`);let a=i.selection,o=await e.create(t,a,r);return i.explicitlySelected&&Gr(e.agentId,{modelRef:a.model,thinkingLevel:a.thinkingLevel}),o}},[e]),p=async(t,n)=>{if(!e||!a)throw Error(`Model configuration is not ready`);let r=a.models.find(e=>e.id===t);if(!r)throw Error(`Model is unavailable`);let o=Jr(Yr(),e.agentId)?.thinkingByModel?.[t],c=r.thinking?Xr(r.thinking,n??s?.thinkingLevel,n===void 0?o:void 0):n??s?.thinkingLevel??`medium`;i({preparation:e,selection:{model:t,thinkingLevel:c}})};return{preparation:f,model:s?.model??``,thinkingLevel:s?.thinkingLevel??`medium`,modelSupportsThinking:!!c?.reasoning,ready:l,error:o,onModelChange:e=>p(e),onThinkingChange:e=>p(s?.model??``,e)}}var nA=class{tails=new Map;run(e,t){let n=this.tails.get(e),r=n?n.then(t,t):Promise.resolve().then(t),i=r.finally(()=>{this.tails.get(e)===i&&this.tails.delete(e)});return this.tails.set(e,i),i.catch(()=>{}),r}};async function rA(e){let t=e.trim();if(!t)return!1;try{return!!(await hi()).find(e=>e.id===t)?.reasoning}catch{return!1}}function iA(e){let{sessionMgrRef:t,routeConversationIdRef:n,sendingRef:r,streamingRef:a,loadingSessionRef:o,messagesLenRef:s,thinkingSupportGenRef:c,navigateToSession:l,resolveAgentIdForPost:u,detachForNewConversation:d,conversationId:f,sessionAgentId:p,currentProjectId:m,taskId:h,hasMore:g}=e,_=()=>Sn.getState(),v=(0,Q.useRef)(new nA),y=(0,Q.useRef)(0),b=(0,Q.useRef)(null),x=(0,Q.useRef)(0),S=(0,Q.useCallback)(e=>{let t=_().focusedConversationId;if(!e.trim())return++c.current===c.current&&t&&_().patchSessionMeta(t,{modelSupportsThinking:!1}),Promise.resolve();let n=++c.current;return rA(e).then(t=>{if(n!==c.current)return;let r=_().focusedConversationId;r&&_().sessions[r]?.model===e&&_().patchSessionMeta(r,{modelSupportsThinking:t})})},[c]),C=(0,Q.useCallback)(async e=>{try{let n=await t.current.loadSessionAgentConfig(e);hr(e,n),S(n.model)}catch{}},[t,S]),w=(0,Q.useCallback)(()=>{let e=_().focusedConversationId;if(!e||(_().sessions[e]?.name)?.trim())return;let n=++x.current,r=[700,900,900,1e3,1e3],i=a=>{a>=5||n===x.current&&_().focusedConversationId===e&&(_().sessions[e]?.name?.trim()||window.setTimeout(()=>{n===x.current&&_().focusedConversationId===e&&(_().sessions[e]?.name?.trim()||t.current.fetchSessionName(e).then(t=>{if(n===x.current){if(t){_().patchSessionMeta(e,{name:t});return}i(a+1)}}).catch(()=>{i(a+1)}))},r[a]??900))};i(0)},[t]),T=(0,Q.useCallback)(e=>Ck({chatId:e,routeConversationId:n.current}),[n]),E=(0,Q.useCallback)((e,t,n)=>{let r=_().sessions[e];if(n&&r?.messages!==n.messages&&!zn(r))return!1;let i=t.hasMore&&Er(r?.messages??[],t.messages)>0;return _().mergeCommittedFromServer(e,t.messages,t.hasMore,n?.completedRunId),t.name!==void 0&&_().patchSessionMeta(e,{name:t.name||null}),T(e)&&(i||(b.current=t.nextBeforeCursor??null)),!0},[T]),D=(0,Q.useCallback)(async(e,r=0,a)=>{let s=i(`session_load`),c=async(e,r,i)=>{let a=r===0&&!i;y.current++,o.current=!0,s(`request_started`);let d=a&&Cn(_().sessions[e]?.historyStatus);d&&_().setSessionHistoryStatus(e,`loading`);let f=a?Promise.resolve().then(()=>t.current.loadSessionAgentConfig(e)).then(e=>(s(`config_received`),{config:e}),e=>({error:e})):void 0;try{let n={messages:_().sessions[e]?.messages},{messages:o,hasMore:c,name:l,nextBeforeCursor:u}=await t.current.loadSession(e,r,i,h,n.messages);if(s(`history_received`),a){if(!E(e,{messages:o,hasMore:c,name:l,nextBeforeCursor:u},n))return _().sessions[e]?.messages;if(!T(e))return o;s(`history_committed`);let t=await f;if(`error`in t)throw t.error;let r=t.config;return T(e)?(hr(e,r),S(r.model),o):o}if(!T(e))return;b.current=u??null,_().prependHistoryMessages(e,o,c);return}catch(a){if(s(`failed`),n.current&&!T(e))return;if(r===0&&!i){b.current=null;let r=a instanceof Error?a.message:`Failed to load session`;_().setShellError(/^HTTP 404\b/.test(r)?JSON.stringify(Sr(r)):`Failed to load session`);let i=bk(n.current);if(i&&i===e)return;let o=await t.current.loadSessions().catch(()=>[]),s=o.filter(e=>(e.messageCount??0)>0)[0]??o[0];if(s)return l(s.key,!0),await c(s.key,0,null);{b.current=null;let e=u();qk({sessionMgr:t.current,agentId:e,currentConversationId:null,routeConversationId:null,navigateToSession:l,replaceNavigate:!0,onOpened:e=>{_().setCommittedSnapshot(e,{messages:[],hasMore:!1,name:null}),C(e)}})}}return}finally{y.current--,o.current=y.current>0,s(`settled`),d&&_().sessions[e]?.historyStatus===`loading`&&_().setSessionHistoryStatus(e,`ready`)}};return v.current.run(e,()=>c(e,r,a))},[n,T,r,a,o,l,S,u,t,h,E]),O=(0,Q.useCallback)(async()=>{let e=_().focusedConversationId;if(!(!e||_().loadingMore||!g)){_().setLoadingMore(!0);try{await D(e,s.current,b.current)}finally{_().setLoadingMore(!1)}}},[g,D,s]),k=(0,Q.useCallback)(async(e,n)=>{if(!f)throw Error(`No active session`);let r=_().sessions[f];if(r?.modelConfigSaving)throw Error(`Model configuration is being saved`);if(!(r?.model===e&&n!==void 0&&r.thinkingLevel===n)){_().patchSessionMeta(f,{modelConfigSaving:!0});try{if(_().setShellError(null),n===void 0){let t=(await hi()).find(t=>t.id===e);if(t?.thinking){let i=Jr(Yr(),p)?.thinkingByModel?.[e];n=Xr(t.thinking,r?.thinkingLevel,i)}}let i=h?await t.current.patchTaskConversationModel(h,e,n,r?.configVersion):await t.current.patchSessionAgentConfig(f,{model:e,thinkingLevel:n,configVersion:r?.configVersion});hr(f,i),Gr(p,{modelRef:i.model,thinkingLevel:i.thinkingLevel}),i.model!==r?.model&&S(i.model)}catch(e){let n=e instanceof Error?e.message:`Failed to update model configuration`;_().setShellError(n);let r=await t.current.loadSessionAgentConfig(f).catch(()=>null);throw r&&hr(f,r),e}finally{_().patchSessionMeta(f,{modelConfigSaving:!1})}}},[f,p,h,t,S]);return{refreshModelThinkingSupport:S,pollSessionNameAfterTurn:w,applyLoadedSessionSnapshot:E,loadSessionById:D,loadMoreMessages:O,onSessionModelChange:k,onSessionThinkingLevelChange:(0,Q.useCallback)(async e=>{let t=f?_().sessions[f]?.model:void 0;t&&await k(t,e)},[f,k]),onSessionWorkingDirectoryChange:(0,Q.useCallback)(async e=>{let n=e.trim();if(!(!f||!n))try{_().setShellError(null),await t.current.patchSessionAgentConfig(f,{workingDirectory:n}),await C(f)}catch(e){throw _().setShellError(e instanceof Error?e.message:`Failed to update working directory`),e}},[C,f,t]),createNewSession:(0,Q.useCallback)(async e=>{_().setShellError(null);let n=u(),r=Jr(Yr(),n??`main`);await qk({sessionMgr:t.current,agentId:n,currentConversationId:f,routeConversationId:f,forceNew:e?.forceNew,temporary:e?.temporary,executionMode:e?.executionMode,projectId:e?.projectId===void 0?m:e.projectId,initialAgentConfig:r?{model:r.modelRef,...r.thinkingLevel?{thinkingLevel:r.thinkingLevel}:{}}:void 0,navigateToSession:l,onOpened:e=>{d(),b.current=null,_().setCommittedSnapshot(e,{messages:[],hasMore:!1,name:null}),C(e)}})},[d,l,u,m,f,t,C]),resetCurrentSession:(0,Q.useCallback)(async()=>{if(f){_().setShellError(null);try{await t.current.resetSession(f),d(),b.current=null,_().setCommittedSnapshot(f,{messages:[],hasMore:!1,name:null}),C(f)}catch(e){_().setShellError(e instanceof Error?e.message:`Failed to reset session`)}}},[C,f,d,t])}}function aA(e){return new Promise(t=>{Promise.resolve().then(()=>e(()=>t(!0))).then(()=>t(!1),()=>t(!1))})}function oA(e,t,n){return e.map(e=>{if(e.clientSubmissionId!==t||!e.deliveryStatus)return e;if(n===`failed`)return{...e,deliveryStatus:`failed`};let r={...e,deliveryStatus:`accepted`};return delete r.pendingAppContext,r})}function sA(e){return e!==`suspended`}function cA(e){let{chatId:t,shouldApplyStreamUpdate:n,beforeAssistantDelta:r,reconcileHydratedAssistantText:i,setStreamingOnStreamStart:a,clearResumeRunIdOnBackgroundTerminal:o,clearResumeRunIdOnVisibleError:s,setError:c,sessionMgrRef:l,applyLoadedSessionSnapshot:u,finalizeMessage:d,fq:f}=e,p=e.isCurrentRun??(()=>!0),m=()=>Sn.getState(),h=()=>{m().sessions[t]?.progress?.stage.startsWith(`model_`)&&m().setSessionProgress(t,null)},g=e=>{let n=e?.runId,r={messages:m().sessions[t]?.messages,completedRunId:e?.terminal?n:void 0};return l.current.loadSession(t,0,void 0,void 0,r.messages).then(i=>{!p()||e?.signal.aborted||u(t,i,r)===!1||n&&m().sessions[t]?.messages.some(e=>e.role===`assistant`&&e.turnId===n&&e.content.some(e=>e.type===`text`&&e.text.trim()&&e.text.trim()!==`NO_REPLY`))&&xr(n,`history`)}).catch(()=>{})},_=new Map,y,b=()=>{if(y!==void 0&&(window.clearTimeout(y),y=void 0),!p()){_.clear();return}if(_.size===0)return;let e=Array.from(_.entries());_.clear(),r(),m().mutateSessionStreaming(t,t=>{for(let[n,r]of e)cr(t.content,n,r)})},x=(e,t)=>{_.set(e,`${_.get(e)??``}${t}`),y===void 0&&(y=window.setTimeout(b,120))},C=e=>{m().clearStreamingState(t),o&&kn.setResumeRunId(t,null),m().setSessionFlags(t,{sending:!1,streaming:!1}),m().setSessionProgress(t,null),sA(e)&&f.dismissClarifyForSession(t),g()},w={onTextSurface:e=>{r(),m().mutateSessionStreaming(t,t=>{t.textSurface=e})},onReplayGap:g,onUserMessage:e=>{n(t)&&m().appendUserMessageIfMissing(t,e)},onStreamStart:(e,n,i)=>{Xf(t),r(),i&&m().updateSessionMessages(t,t=>er([...t,{role:`task`,content:[],taskTrigger:i,turnId:e,timestamp:Date.now()}])),m().updateSessionMessages(t,t=>Gn(t,e)),m().mutateSessionStreaming(t,t=>{t.turnId=e,n&&(t.startsNewBubble=!0)}),m().setSessionFlags(t,{streaming:!0})},onToken:(e,a,o)=>{h(),r(),m().mutateSessionStreaming(t,t=>{vn(t.content,e,a,{offset:o,reconcileHydratedSegment:i})}),n(t)&&m().setSessionFlags(t,{streaming:!0})},onAssistantMessageEnd:(e,n,i)=>{r(),m().mutateSessionStreaming(t,t=>{Hn(t.content,e,n),i&&(t.usage=i)})},onThinking:(e,n,i)=>{h(),r(),m().mutateSessionStreaming(t,t=>{!n&&e===``?Un(t.content):sr(t.content,e,n,i)})},onThinkingEnd:e=>{r(),m().mutateSessionStreaming(t,t=>{Ar(t.content,e)})},onToolStart:(e,n,i,a,o,s)=>{h(),r(),m().mutateSessionStreaming(t,t=>{jn(t.content,e,n,i,a,o,s)}),m().setSessionFlags(t,{streaming:!0})},onToolEnd:(e,n,i,a,o,s,c)=>{r(),m().mutateSessionStreaming(t,t=>{Pn(t.content,e,n,i,a,o,s,c)})},onToolUpdate:(e,n,i)=>{r(),m().mutateSessionStreaming(t,t=>{Tn(t.content,e,n,i)})},onTaskPlanUpdated:e=>{m().setSessionTaskPlan(t,e)},onTurnOutcome:e=>{r(),m().mutateSessionStreaming(t,t=>{t.outcome=e})},onReview:({review:e})=>{r(),m().mutateSessionStreaming(t,t=>{Nn(t.content,e)}),n(t)&&m().setSessionFlags(t,{streaming:!0})},onReviewStart:e=>{r(),m().mutateSessionStreaming(t,t=>{Vn(t.content,e)}),n(t)&&m().setSessionFlags(t,{streaming:!0})},onReviewDelta:({reviewId:e,delta:t})=>{x(e,t)},onReviewEnd:({reviewId:e,status:n,message:i})=>{b(),r(),m().mutateSessionStreaming(t,t=>{yn(t.content,e,n,i)})},onProgress:e=>{m().setSessionProgress(t,e)},onTtsAudio:e=>{n(t)&&m().appendAttachmentToCurrentAssistant(t,{name:e.name,mimeType:e.mimeType,type:`voice`,uri:e.uri,size:0},{attachTo:e.attachTo,messageId:e.messageId})},onCompaction:e=>{if(!n(t))return;let r=S(v.getState().language).chat;if(e.status===`started`)m().setSessionProgress(t,{stage:`compaction`,message:r.compactingContext,timestamp:Date.now()});else if(e.status===`completed`){let n=e.tokensBefore&&e.tokensAfter?` (${r.contextTokensFreed.replace(`{{count}}`,String(Math.round((e.tokensBefore-e.tokensAfter)/1e3)))})`:``;m().setSessionProgress(t,{stage:`compaction`,message:`${r.contextCompacted}${n}`,timestamp:Date.now()})}else m().setSessionProgress(t,null)},onClarifyRequest:f.makeOnClarifyRequest(t),onSessionConfigUpdated:()=>{m().patchSessionMeta(t,{modelConfigSaving:!0}),l.current.loadSessionAgentConfig(t).then(e=>hr(t,e)).catch(()=>{}).finally(()=>m().patchSessionMeta(t,{modelConfigSaving:!1}))},onResult:({status:e})=>{b();let r=n(t);if(kn.takeUserAborted(t)||e===`cancelled`){$f(t),r?d(t,e):C(e);return}if(e===`error`){if(Qf(t,!r),!r){C(e);return}d(t,e),g();return}if(e===`suspended`?ep(t):Zf(t,!r),!r){C(e);return}d(t,e)},onError:e=>{b();let r=n(t);if(Qf(t,!r),!r){C(`error`);return}d(t,`error`),s&&kn.setResumeRunId(t,null),m().setSessionFlags(t,{sending:!1,streaming:!1}),m().setSessionProgress(t,null),c(e),f.dismissClarifyForSession(t)}};return Object.fromEntries(Object.entries(w).map(([e,t])=>[e,(...e)=>{if(p())return Reflect.apply(t,void 0,e)}]))}function lA(e){return Ln(e)?.streamingMsg??null}var uA=80;function dA(e){let t=e.trim();(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))&&(t=t.slice(1,-1).trim());let n=t.indexOf(`
71
+ `);return n!==-1&&(t=t.slice(0,n).trim()),t.length>uA&&(t=t.slice(0,uA-1).trimEnd()+`…`),t}function fA(e){let t=e.trimStart();if(!/^##\s+Skill:\s*\S+/i.test(t))return e;let n=/(?:^|\r?\n)\*\*Arguments\*\*:\s*/gi,r=-1;for(;n.exec(t)!==null;)r=n.lastIndex;if(r!==-1){let e=t.slice(r).trim();if(e)return e}return(t.split(/\r?\n/)[0]?.trim()??``).replace(/^##\s+Skill:\s*/i,``).trim()}function pA(e){let t=e.trimStart().match(/^\/skill:([^\s]+)(?:\s+([\s\S]*))?$/i);return t&&(t[2]?.trim()||t[1]?.trim())||e}function mA(e){let t=pA(fA(Wn([{type:`text`,text:e}]))).split(/\n/)[0]?.trim();if(!t)return null;let n=dA(t);return n.length>0?n:null}function hA(e,t){let n=e.trim(),r=t.trim();!n||!r||window.dispatchEvent(new CustomEvent(`session-updated`,{detail:{key:n,name:r},bubbles:!0}))}var gA=new Set([`new`,`reset`,`restart`]),_A=new Set([...gA,`clear`,`archive`]);function vA(e){let t=e.trim(),n=/^\/([^\s@]+)(?:@[^\s]+)?(?:\s+([\s\S]*))?$/.exec(t);return n?{name:n[1].toLowerCase(),args:n[2]?.trim()??``}:null}function yA(e){let t=vA(e);return!!(t&&gA.has(t.name)&&!t.args)}function bA(e){let t=vA(e);return!!(t&&_A.has(t.name))}function xA(e){let{conversationId:t,taskId:n,thinkingLevel:r,modelSupportsThinking:i,conversationIdRef:a,sendingRef:o,streamingRef:s,sessionMgrRef:c,sendMessageRef:l,shouldApplyStreamUpdate:u,fq:d,applyLoadedSessionSnapshot:f,loadSessionById:p,resetCurrentSession:m,pollSessionNameAfterTurn:h}=e,g=()=>Sn.getState(),v=e=>g().setShellError(e),y=()=>g().setShellError(null),b=(0,Q.useCallback)((e,t)=>{let n=e??a.current;if(n&&!u(n))return;let r=n?lA(n):null,i=null;if(r){let e=wn(r,Date.now());e.runStatus=t,Dn(e.content,t===`success`),Ar(e.content),t!==`suspended`&&In(e.content,t===`success`),An(e.content),e.completedAt=t&&t!==`suspended`?Date.now():void 0,i=Mn(e)}i&&En(i)&&n?g().finalizeStreamingTurn(n,i):n&&g().clearStreamingState(n),o.current=!1,s.current=!1,n&&kn.resetRunTracking(n),(!t||sA(t))&&d.dismissClarify(),h();let c=a.current;c&&window.setTimeout(()=>{a.current===c&&(o.current||s.current||p(c,0))},400)},[o,s,a,d.dismissClarify,d.pendingFollowUpsRef,h,p,u]),x=(0,Q.useCallback)(async(e,t)=>{if(!u(e)||kn.isSubmittingFor(e))return;let r=_.getState().conversationId,i=()=>_.getState().conversationId===r,a=kn.getGeneration(e),l=g().sessions[e]?.streamingMsg,m=g().sessions[e]?.messages.findLast(e=>e.role===`user`)?.clientSubmissionId,h=await gr(e);if(!i()||kn.getGeneration(e)!==a||kn.isSubmittingFor(e))return;if(!h){let t=g().sessions[e]?.streamingMsg;if(t?.pendingResponseStatus||t&&t!==l||kn.isStreamingFor(e))return;let n=kn.getResumeRunId(e);n&&kn.reconcileInactive(e,n),g().clearStreamingState(e,{preservePendingResponse:!0}),$f(e);return}let y=()=>{let t=g().sessions[e]?.streamingMsg,n=g().sessions[e]?.messages.findLast(e=>e.role===`user`)?.clientSubmissionId;return!i()||kn.getGeneration(e)!==a||kn.isSubmittingFor(e)||!!(n&&n!==m)||!!(Zn(e)&&Zn(e)!==h)||!!(t?.turnId&&t.turnId!==h&&t.turnId!==l?.turnId)||!!(t?.pendingResponseStatus&&t!==l)};if(y()||kn.isTrackingRun(e,h))return;let x=()=>{let t=g().sessions[e]?.streamingMsg;!t?.turnId||t.turnId===h||t.turnId!==l?.turnId||(En(t)?g().finalizeStreamingTurn(e,Mn(t)):g().clearStreamingState(e))},S=t??bn(e),C=Ln(e)?.hasMore??!1;try{let t=await c.current.loadSession(e,0,void 0,n,g().sessions[e]?.messages);if(y()||kn.isTrackingRun(e,h))return;x(),g().mergeCommittedFromServer(e,t.messages,t.hasMore),S=t.messages,C=t.hasMore}catch{}if(y()||kn.isTrackingRun(e,h))return;x(),a=kn.advanceGeneration(e),kn.setUserAborted(e,!1),kn.setResumeRunId(e,h),o.current=!0,s.current=!0,g().seedSessionIfEmpty(e,S,!0,!0,C),g().setSessionFlags(e,{sending:!0,streaming:!0}),g().setSessionProgress(e,null),Xf(e);let w=!1,T=()=>{if(w||!u(e))return;w=!0;let t=Dk(bn(e),h);t&&g().applyHydratedTail(e,t.messagesWithoutTail,Mn(t.tail))},E=()=>{g().clearStreamingState(e),kn.getResumeRunId(e)===h&&kn.setResumeRunId(e,null),u(e)&&(o.current=!1,s.current=!1)};try{let t=cA({chatId:e,shouldApplyStreamUpdate:u,isCurrentRun:()=>i()&&kn.getGeneration(e)===a,beforeAssistantDelta:T,reconcileHydratedAssistantText:!0,setStreamingOnStreamStart:!1,clearResumeRunIdOnBackgroundTerminal:!0,clearResumeRunIdOnVisibleError:!0,setError:v,sessionMgrRef:c,applyLoadedSessionSnapshot:f,finalizeMessage:b,fq:d}),n=await kn.senderFor(e).resume(h,e,t,{replayFromStart:l?.turnId!==h||!En(l)});if(!i()||kn.getGeneration(e)!==a)return;n||($f(e),E(),await p(e,0).catch(()=>void 0))}catch(t){if(!i()||kn.getGeneration(e)!==a)return;t.name!==`AbortError`&&console.error(`[chat] resume failed:`,t),$f(e),E()}finally{kn.releaseIdleSender(e)}},[o,s,u,c,f,b,p,n]),S=(0,Q.useCallback)(async(e,t,r,i)=>{if(!e.trim()&&!t?.length&&!i?.length)return!1;let c=a.current;if(!c||!o.current&&!s.current&&!kn.isStreamingFor(c))return!1;let l=e.trim();if(n&&bA(l))return v(`A task has one continuous conversation.`),!1;if(yA(l)&&!t?.length){await m();return}return await d.addPendingFollowUp(e,t,i,void 0,!0),!0},[o,s,a,d.addPendingFollowUp,m,n]),C=(0,Q.useCallback)(async(e,a,l,h,x,S,C,w,T)=>{if(!t||!u(t)||!e.trim()&&!a?.length&&!h?.length||o.current||s.current||kn.isStreamingFor(t))return!1;let E=e.trim();if(n&&bA(E))return v(`A task has one continuous conversation.`),!1;if(yA(E)&&!a?.length){await m();return}let D=i?l??r:`off`,O=t,k=kn.advanceGeneration(O),A=_.getState().conversationId,j=()=>_.getState().conversationId===A&&kn.getGeneration(O)===k,M=crypto.randomUUID(),N=`assistant-stream:${O}:${M}`,P=bn(O),F=w?P.filter(e=>e.clientSubmissionId!==w):P,I=x?F.findIndex(e=>e.role===`user`&&e.turnId===x):-1;if(x&&I<0)return!1;kn.setUserAborted(O,!1),o.current=!0,s.current=!1,y(),d.dismissClarify();let L=I>=0?F.slice(0,I):F,R=Rn(e)??void 0,z=new Map(h?.flatMap(e=>e.refId?[[e.refId,e.title]]:[])??[]),B=R?xn(R,e=>z.get(e)):e,ee=[...L,{role:`user`,content:B?[{type:`text`,text:B}]:[],userTurnDocument:R,deliveryStatus:`sending`,clientSubmissionId:M,pendingAppContext:S===void 0?void 0:structuredClone(S),attachments:a,contextRefs:h?.map(e=>({refId:e.refId,kind:e.kind,sourceId:e.sourceId,version:e.expectedVersion,title:e.title,fileKind:e.fileKind})),timestamp:Date.now()}];C?.(M);let V=Ln(O);if(g().initSessionSnapshot(O,{...V??{...On(),historyStatus:`ready`,hasMore:!1,streamingMsg:null,progress:null,taskPlan:null,sending:!1,streaming:!1},messages:ee,hasMore:V?.hasMore??!1,streamingMsg:{role:`assistant`,content:[],timestamp:Date.now(),renderKey:N,pendingResponseStatus:`sending`},progress:null,sending:!0,streaming:!1}),Xf(O),!V?.name?.trim()&&B.trim()){let e=mA(B.trim());e&&(g().patchSessionMeta(O,{name:e}),hA(O,e))}let H=e=>{g().updateSessionMessages(O,t=>oA(t,M,e))};return aA(async t=>{let r=!1;try{let i=cA({chatId:O,shouldApplyStreamUpdate:u,isCurrentRun:j,beforeAssistantDelta:()=>{},reconcileHydratedAssistantText:!1,setStreamingOnStreamStart:!0,clearResumeRunIdOnBackgroundTerminal:!1,clearResumeRunIdOnVisibleError:!1,setError:v,sessionMgrRef:c,applyLoadedSessionSnapshot:f,finalizeMessage:b,fq:d});i.onInputAccepted=()=>{r=!0,H(`accepted`),j()&&g().setPendingResponseStatus(O,`waiting`),t()},await kn.senderFor(O).send(e,O,a,D,i,n,x,h,S,T)}catch(e){if(!j())return;if(e.name!==`AbortError`)g().clearStreamingState(O),$f(O),u(O)&&v(e instanceof Error?e.message:String(e)),x&&p(O,0);else{$f(O);let e=Ln(O)?.streamingMsg;e?.renderKey===N&&e.pendingResponseStatus&&g().clearStreamingState(O)}}finally{j()&&(r||H(`failed`),u(O)&&(o.current=!1,s.current=!1),g().setSessionFlags(O,{sending:!1}),kn.releaseIdleSender(O))}})},[t,r,i,o,s,u,c,f,b,d.dismissClarify,m,n,p]),w=(0,Q.useCallback)((e,t,n,r,i,a)=>C(t,n,r,i,e,void 0,void 0,void 0,a),[C]),T=(0,Q.useCallback)((e,t)=>{let n=a.current;if(!n||mr(n).phase!==`idle`||kn.getGeneration(n)!==e)return;let r=kn.getResumeRunId(n),i=g().sessions[n]?.streamingMsg?.turnId;r&&r!==t||i&&i!==t||(d.dismissClarify(),kn.abort(n,!1),$f(n),o.current=!1,s.current=!1,b(n,`cancelled`),p(n,0))},[d.dismissClarify,o,s,b,a,p]);return{finalizeMessage:b,tryResumeAgentRun:x,sendMessage:C,replaceLatestUserTurn:w,interruptAndSend:S,abort:(0,Q.useCallback)(async()=>{let e=a.current;if(!e)return;let t=kn.getGeneration(e),n=kn.getResumeRunId(e)??g().sessions[e]?.streamingMsg?.turnId??null;await d.stopSession(),a.current===e&&T(t,n)},[d.stopSession,a,T]),settleStoppedRun:T,deleteMessageRound:(0,Q.useCallback)(e=>{let t=a.current;if(!t||o.current||s.current)return;let n=bn(t),r=n[e];if(!r||!_n(r.role))return;if(r.deliveryStatus===`failed`){let r=[...n];r.splice(e,1),g().updateSessionMessages(t,()=>r);return}let i=br(n,e);if(i===null)return;let l=tr(n,e),u=[...n];u.splice(e,l),g().updateSessionMessages(t,()=>u),c.current.deleteMessages(t,{userRoundIndex:i}).catch(()=>{p(t,0)})},[a,o,s,c,p]),retryUserMessageRound:(0,Q.useCallback)(e=>{let t=a.current;if(!t||o.current||s.current)return;let n=bn(t),r=n[e];if(!r||!_n(r.role))return;for(let t=e+1;t<n.length;t++){let e=n[t];if(e&&_n(e.role))return}let i=r.userTurnDocument?Tr(r.userTurnDocument):Wn(r.content),c=Kn(r.attachments);if(!i.trim()&&!c?.length&&!r.contextRefs?.length)return;let u=r.contextRefs?.flatMap(e=>e.kind===`mcp_resource`?[]:[{refId:e.refId,kind:e.kind,sourceId:e.sourceId,expectedVersion:e.version,title:e.title,fileKind:e.fileKind}]),d=r.deliveryStatus===`failed`?r.clientSubmissionId:void 0;!d&&!r.turnId||l.current(i,c,void 0,u,r.turnId,r.pendingAppContext,void 0,d).catch(()=>{p(t,0)})},[a,o,s,p,l])}}function SA(e){let t=(0,X.c)(11),{conversationId:n,conversationIdRef:r,sessionMgrRef:i,loadSessionById:a,loadTimelineById:o,applyAgentConfig:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=[],t[0]=c):c=t[0],(0,Q.useEffect)(wA,c);let l,u;t[1]!==n||t[2]!==a||t[3]!==o?(l=()=>{let e=e=>{let t=e.detail;!t?.key||t.key!==n||(a(n,0),o(n))};return window.addEventListener(`session-transcript-updated`,e),()=>window.removeEventListener(`session-transcript-updated`,e)},u=[n,a,o],t[1]=n,t[2]=a,t[3]=o,t[4]=l,t[5]=u):(l=t[4],u=t[5]),(0,Q.useEffect)(l,u);let d,f;t[6]!==s||t[7]!==r||t[8]!==i?(d=()=>{let e=e=>{if(oi(e.detail))return;let t=r.current;t&&i.current.loadSessionAgentConfig(t).then(e=>{s(t,e)}).catch(CA)};return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},f=[r,i,s],t[6]=s,t[7]=r,t[8]=i,t[9]=d,t[10]=f):(d=t[9],f=t[10]),(0,Q.useEffect)(d,f)}function CA(){}function wA(){let e=TA;return window.addEventListener(`session-updated`,e),()=>window.removeEventListener(`session-updated`,e)}function TA(e){let t=e.detail;!t?.key||t.name===void 0||Sn.getState().patchSessionMeta(t.key,{name:t.name||null})}function EA(e){let t=m(),{isNewRoute:n,forceNewChat:r,decodedKey:i,viewConversationId:a,routedFocusedConversationId:o,routeConversationIdRef:s,locationKey:c,locationSearch:l,locationState:u}=Zk(e?.fixedConversationId),d=(0,Q.useRef)(new yr),f=(0,Q.useRef)(!1),p=(0,Q.useRef)(!1),h=(0,Q.useRef)(!1),g=(0,Q.useRef)(0),_=(0,Q.useRef)(!1),[v,y]=(0,Q.useState)([]),b=(0,Q.useRef)(async()=>{}),x=(0,Q.useRef)(0),S=o,C=Sn(e=>e.initLoading),w=Sn(e=>e.loadingMore),T=Sn(e=>e.shellError),E=a,D=Qm(E),O=E?zn(D):!1,k=O?D?.streaming??!1:!1,A=O?D?.sending??!1:!1,j=O?D?.progress??null:null,M=O?D?.taskPlan??null:null,N=D?.hasMore??!1,P=D?.name??null,F=D?.model??``,I=kk(D,Qr(gi,hi,{revalidateOnFocus:!1}).data),L=D?.modelConfigSaving??!1,R=D?.thinkingLevel??`medium`,z=D?.reasoningLevel??`on`,B=D?.modelSupportsThinking??!1,ee=D?.effectiveWorkspacePath??``,V=D?.workspaceSource??`agent_default_root`,H=D?.userContextMode??`enabled`;(0,Q.useEffect)(()=>{!E||A||k||d.current.loadSessionAgentConfig(E).then(e=>hr(E,e)).catch(()=>void 0)},[E,A,k]),(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail.conversationId;d.current.loadSessionAgentConfig(t).then(e=>hr(t,e)).catch(()=>void 0)};return window.addEventListener(`session-model-config-stale`,e),()=>window.removeEventListener(`session-model-config-stale`,e)},[]),(0,Q.useEffect)(()=>{x.current=D?.messages.length??0},[D?.messages.length]),(0,Q.useEffect)(()=>{p.current=A,h.current=k},[A,k]);let{token:U,chatAgentsData:W,resolveAgentIdForPost:te,onChatAgentChange:ne,displayAgentId:re,showChatAgentSelector:ie,currentSessionProjectId:ae}=zk({navigate:t,personal:e?.personal,conversationIdRef:$k,conversationId:S,isNewRoute:n,locationState:u,locationSearch:l}),oe=i!==void 0&&S!==i,se=!!(i&&D?.historyStatus===`loading`&&!oe),ce=(0,Q.useMemo)(()=>C&&(S==null||i===void 0),[C,S,i]),le=jk({isNewRoute:n,sessionRoutePending:oe,showSessionLoading:ce,sessionContentLoading:se,messageCount:D?.messages.length??0}),ue=(0,Q.useCallback)((e,n=!1,r)=>{let i=r??``;t({pathname:`/chat/${encodeURIComponent(e)}`,search:i},{replace:n})},[t]),de=(0,Q.useCallback)(e=>xk({streamConversationId:e,routeConversationId:s.current}),[s]),G=(0,Q.useCallback)(()=>{Ak({sendingRef:p,streamingRef:h})},[]),K=Lk({conversationId:S,decodedKey:i,conversationIdRef:$k,sendingRef:p,streamingRef:h,modelSupportsThinking:B,thinkingLevel:R,shouldApplyStreamUpdate:de}),fe=(0,Q.useCallback)(()=>{K.clearVisibleClarify();let e=$k.current;e&&kn.resetRunTracking(e),Ok(G)},[K.clearVisibleClarify,$k,G]),{refreshModelThinkingSupport:q,pollSessionNameAfterTurn:pe,applyLoadedSessionSnapshot:me,loadSessionById:J,loadMoreMessages:he,onSessionModelChange:ge,onSessionThinkingLevelChange:_e,onSessionWorkingDirectoryChange:ve,createNewSession:ye,resetCurrentSession:be}=iA({sessionMgrRef:d,routeConversationIdRef:s,sendingRef:p,streamingRef:h,loadingSessionRef:f,messagesLenRef:x,thinkingSupportGenRef:g,navigateToSession:ue,resolveAgentIdForPost:te,detachForNewConversation:fe,conversationId:S,sessionAgentId:re,currentProjectId:ae,hasMore:N,taskId:e?.taskId}),xe=(0,Q.useCallback)(e=>{if(!Sk({cacheConversationId:e,routeConversationId:s.current}))return!1;let t=Ln(e);return!t||!zn(t)&&!pr(e)&&!kn.isStreamingFor(e)?!1:(p.current=t.sending,h.current=t.streaming,!0)},[s]),{tryResumeAgentRun:Se,sendMessage:Ce,replaceLatestUserTurn:we,interruptAndSend:Te,abort:Ee,settleStoppedRun:De,deleteMessageRound:Oe,retryUserMessageRound:ke}=xA({conversationId:S,taskId:e?.taskId,thinkingLevel:R,modelSupportsThinking:B,conversationIdRef:$k,sendingRef:p,streamingRef:h,sessionMgrRef:d,sendMessageRef:b,shouldApplyStreamUpdate:de,fq:K,applyLoadedSessionSnapshot:me,loadSessionById:J,resetCurrentSession:be,pollSessionNameAfterTurn:pe});(0,Q.useEffect)(()=>{n&&fe()},[n,fe]);let Ae=(0,Q.useMemo)(()=>Ek({viewConversationId:a,conversationId:E,messages:D?.messages??[],streamingMsg:O?D?.streamingMsg??null:null}),[a,E,D?.messages,D?.streamingMsg,O]),je=(0,Q.useCallback)((e,t)=>{Sn.getState().setCommittedSnapshot(e,{messages:[],hasMore:!1,name:t}),G()},[G]),Me=(0,Q.useCallback)((e,t)=>{hr(e,t),q(t.model)},[q]),Ne=(0,Q.useCallback)(e=>{let t=Sn.getState();e.loading!==void 0&&t.setInitLoading(e.loading),e.error!==void 0&&t.setShellError(e.error)},[]),Pe=(0,Q.useCallback)(async t=>{try{let n=await d.current.loadTimeline(t,e?.taskId);if(s.current!==t)return;y(n)}catch{s.current===t&&y([])}},[s,e?.taskId]);(0,Q.useEffect)(()=>{if(n||!S){y([]);return}Pe(S)},[S,n,Pe]),SA({conversationId:S,conversationIdRef:$k,sendingRef:p,streamingRef:h,sessionMgrRef:d,loadSessionById:J,loadTimelineById:Pe,applyAgentConfig:Me});let Fe=eA({token:U,isNewRoute:n,forceNewChat:r,temporary:u?.temporary===!0,requestedAgentId:typeof u?.agentId==`string`?u.agentId:void 0,decodedKey:i,locationKey:c,locationSearch:l,sessionMgrRef:d,resolveAgentIdForPost:te,navigateToSession:ue,loadSessionById:J,tryResumeAgentRun:Se,restoreLiveCacheIfNeeded:xe,adoptEmptySession:je,applyAgentConfig:Me,patchInitUi:Ne}),Ie=tA(Fe);return(0,Q.useEffect)(()=>{Fe&&Ie.error&&Sn.getState().setShellError(Ie.error instanceof Error?Ie.error.message:`Failed to load model configuration`)},[Fe,Ie.error]),(0,Q.useEffect)(()=>{let e=e=>{let t=e.detail,n=t?.conversationId,r=t?.runId;!n||!r?.trim()||(lr(n,r),kn.setResumeRunId(n,r),de(n)&&(kn.isTrackingRun(n,r)||queueMicrotask(()=>{de(n)&&(kn.isTrackingRun(n,r)||Se(n,bn(n)))})))};return window.addEventListener(`run-started`,e),()=>window.removeEventListener(`run-started`,e)},[Se,de]),(0,Q.useEffect)(()=>{let e=k||A,t=_.current;if(_.current=e,!t||e)return;let n=$k.current;n&&queueMicrotask(()=>{!n||!de(n)||kn.isStreamingFor(n)||pr(n)&&Se(n,bn(n))})},[k,A,Se,de]),b.current=Ce,{auth:{hasToken:!!U},session:{projectPreparation:Ie.preparation,conversationId:S,sessionName:P,decodedKey:i,sessionRoutePending:oe,sessionContentLoading:se,showSessionLoading:ce,conversationPhase:le,loading:C,sessionModel:Fe?Ie.model:F,modelConfigReady:Fe?Ie.ready:I,modelConfigSaving:L,thinkingLevel:Fe?Ie.thinkingLevel:R,onSessionThinkingLevelChange:Fe?Ie.onThinkingChange:_e,onSessionWorkingDirectoryChange:ve,reasoningLevel:z,modelSupportsThinking:Fe?Ie.modelSupportsThinking:B,effectiveWorkspacePath:ee,workspaceSource:V,userContextMode:Fe?.temporary?`temporary`:H,hasMore:N,loadingMore:w,loadMoreMessages:he,onSessionModelChange:Fe?Ie.onModelChange:ge,createNewSession:ye,sessionManager:d.current},messages:{items:Ae},timeline:{items:v,refresh:Pe},stream:{error:T,streaming:k,sending:A,progress:j,taskPlan:M,sendMessage:Ce,replaceLatestUserTurn:we,abort:Ee,settleStoppedRun:De,interruptAndSend:Te,deleteMessageRound:Oe,retryUserMessageRound:ke},followUp:{composerMode:K.composerMode,control:K.control,controlPending:K.controlPending,beginEditTurn:K.beginEditTurn,cancelEditor:K.cancelEditor,restoreEditor:K.restoreEditor,markComposerHydrated:K.markComposerHydrated,resumeQueue:K.resumeQueue,sendQueuedInput:K.sendQueuedInput,addPendingFollowUp:K.addPendingFollowUp,pendingFollowUps:K.pendingFollowUps,editingFollowUpId:K.editingFollowUpId,beginEditFollowUp:K.beginEditFollowUp,cancelEditFollowUp:K.cancelEditFollowUp,commitEditFollowUp:K.commitEditFollowUp,removePendingFollowUp:K.removePendingFollowUp,movePendingFollowUp:K.movePendingFollowUp,reorderPendingFollowUp:K.reorderPendingFollowUp,steerPendingFollowUp:K.steerPendingFollowUp,steeringFollowUpId:K.steeringFollowUpId},clarify:{clarifyPrompt:K.clarifyPrompt,clarifySubmitting:K.clarifySubmitting,clarifySubmitError:K.clarifySubmitError,submitClarifyAnswer:K.submitClarifyAnswer,letAgentDecideClarification:K.letAgentDecideClarification,cancelClarification:K.cancelClarification},agents:{chatAgents:W,displayAgentId:Fe?.agentId??re,showChatAgentSelector:ie,onChatAgentChange:ne}}}function DA(e){let t=(0,X.c)(11),n=_(OA),r;t[0]===e?r=t[1]:(r=e?.trim()||null,t[0]=e,t[1]=r);let i=r,a;t[2]===i?a=t[3]:(a=e=>i?e.sessions[i]?.localDraft:void 0,t[2]=i,t[3]=a);let o=Sn(a),s;t[4]!==o||t[5]!==n||t[6]!==i?(s=n&&i&&!o?[`chat-session-meta`,i,n,o===!1?`persisted`:`unknown`]:null,t[4]=o,t[5]=n,t[6]=i,t[7]=s):s=t[7];let c;t[8]===i?c=t[9]:(c=async()=>{if(await jr(i))return;let e=await hn(i),t=typeof e.sessionType==`string`&&e.sessionType.trim()?e.sessionType.trim():null,n=typeof e.routing?.agentId==`string`&&e.routing.agentId.trim()?e.routing.agentId.trim():null,r=e.customData?.sourceBinding,a=r&&typeof r==`object`?r:null,o=a?.kind===`note`&&typeof a.sourceId==`string`&&a.sourceId.trim()?a.sourceId.trim():null,s=typeof e.parentConversationId==`string`&&e.parentConversationId.trim()?e.parentConversationId.trim():null,c=e.customData?.forkedFromSessionName;return{identity:{sourceChannel:e.sourceChannel,sessionType:e.sessionType,customData:e.customData},ownerAgentId:n,sessionType:t,sourceNoteId:o,sourceNoteTitle:null,parentConversationId:s,forkedFromSessionName:typeof c==`string`&&c.trim()?c.trim():null}},t[8]=i,t[9]=c);let l;return t[10]===Symbol.for(`react.memo_cache_sentinel`)?(l={revalidateOnFocus:!1},t[10]=l):l=t[10],Qr(s,c,l)}function OA(e){return e.conversationId}function kA(e,t){if(!e)return``;let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,Math.max(0,t-3)).trimEnd()}...`}function AA(e,t){return kA(Fn(e??``),t)}function jA(e,t){return da(e,t)}function MA(e){return e===`context`||e===`branch`||e===`compaction`?e:null}function NA(e){return kA(e.preview||e.title,72)||e.kind}function PA(e,t){let n=[],r=null,i=0;for(let a of e){if(a.displayIndex!==void 0&&(i=a.displayIndex),a.kind===`turn`&&a.role===`user`){let e=a.turn||n.length+1;r={id:a.id,messageIndex:a.displayIndex??i,ordinal:e,title:t.turn.replace(`{{count}}`,String(e)),preview:AA(a.preview||a.title,88)||t.messageFallback,...a.timestamp===void 0?{}:{timestamp:a.timestamp},tools:[],events:[]},n.push(r);continue}if(!r)continue;if(a.kind===`tool`||a.kind===`file`||a.kind===`command`){let e=a.meta?.toolName||a.title||a.kind,n=a.kind===`file`||a.kind===`command`?a.title:jA(e,t),i=`${a.id}:${e}`;r.tools.some(e=>e.key===i)||r.tools.push({key:i,label:n,running:a.status===`running`});continue}let e=MA(a.kind);if(!e)continue;let o=`${a.id}:${a.kind}`;r.events.some(e=>e.key===o)||r.events.push({key:o,label:NA(a),tone:e})}return n}function FA(e,t){return(e===1?t.toolCount_one:t.toolCount_other).replace(`{{count}}`,String(e))}function IA(e,t){let n=e[0]?.id;for(let r of e)r.messageIndex<=t&&(n=r.id);return n}function LA(e){let t=(0,X.c)(53),{turn:n,active:r,labels:i,currentLabel:a,onSelect:o}=e,s,c,l,u,d,f,p,m;if(t[0]!==r||t[1]!==a||t[2]!==i||t[3]!==o||t[4]!==n.events||t[5]!==n.preview||t[6]!==n.timestamp||t[7]!==n.title||t[8]!==n.tools){let e=n.tools.slice(0,2),h=n.events.slice(0,Math.max(0,3-e.length)),g=Math.max(0,n.tools.length-e.length)+Math.max(0,n.events.length-h.length);d=`button`;let _=r&&`bg-accent-soft/70`;t[17]===_?f=t[18]:(f=Y(`flex w-full min-w-0 items-start gap-3 border-b border-edge-subtle px-4 py-3 text-left transition-colors`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,_),t[17]=_,t[18]=f),p=o;let v=r&&`border-accent bg-accent`,y;t[19]===v?y=t[20]:(y=Y(`mt-1 size-2.5 shrink-0 rounded-full border border-edge-strong bg-surface-panel`,v),t[19]=v,t[20]=y),t[21]===y?m=t[22]:(m=(0,Z.jsx)(`span`,{className:y,"aria-hidden":!0}),t[21]=y,t[22]=m),s=`min-w-0 flex-1`;let b;t[23]===n.preview?b=t[24]:(b=(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium text-fg`,children:n.preview}),t[23]=n.preview,t[24]=b);let x;t[25]!==r||t[26]!==a?(x=r?(0,Z.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-1.5 py-0.5 text-[10px] font-medium text-on-accent`,children:a}):null,t[25]=r,t[26]=a,t[27]=x):x=t[27],t[28]!==b||t[29]!==x?(c=(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[b,x]}),t[28]=b,t[29]=x,t[30]=c):c=t[30];let S;t[31]===n.title?S=t[32]:(S=(0,Z.jsx)(`span`,{children:n.title}),t[31]=n.title,t[32]=S);let C;t[33]===n.timestamp?C=t[34]:(C=n.timestamp?(0,Z.jsx)(`time`,{suppressHydrationWarning:!0,dateTime:new Date(n.timestamp).toISOString(),children:wy(n.timestamp)}):null,t[33]=n.timestamp,t[34]=C);let w;t[35]!==i||t[36]!==n.tools.length?(w=n.tools.length>0?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(Yt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),FA(n.tools.length,i)]}):null,t[35]=i,t[36]=n.tools.length,t[37]=w):w=t[37],t[38]!==S||t[39]!==C||t[40]!==w?(l=(0,Z.jsxs)(`span`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[S,C,w]}),t[38]=S,t[39]=C,t[40]=w,t[41]=l):l=t[41],u=e.length>0||n.events.length>0?(0,Z.jsxs)(`span`,{className:`mt-2 flex min-w-0 flex-wrap gap-1.5`,children:[e.map(zA),h.map(RA),g>0?(0,Z.jsxs)(`span`,{className:`rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,children:[`+`,g]}):null]}):null,t[0]=r,t[1]=a,t[2]=i,t[3]=o,t[4]=n.events,t[5]=n.preview,t[6]=n.timestamp,t[7]=n.title,t[8]=n.tools,t[9]=s,t[10]=c,t[11]=l,t[12]=u,t[13]=d,t[14]=f,t[15]=p,t[16]=m}else s=t[9],c=t[10],l=t[11],u=t[12],d=t[13],f=t[14],p=t[15],m=t[16];let h;t[42]!==s||t[43]!==c||t[44]!==l||t[45]!==u?(h=(0,Z.jsxs)(`span`,{className:s,children:[c,l,u]}),t[42]=s,t[43]=c,t[44]=l,t[45]=u,t[46]=h):h=t[46];let g;return t[47]!==d||t[48]!==f||t[49]!==p||t[50]!==m||t[51]!==h?(g=(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:d,className:f,onClick:p,children:[m,h]})}),t[47]=d,t[48]=f,t[49]=p,t[50]=m,t[51]=h,t[52]=g):g=t[52],g}function RA(e){return(0,Z.jsxs)(`span`,{className:`inline-flex max-w-[10rem] items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,children:[(0,Z.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-current opacity-70`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function zA(e){return(0,Z.jsxs)(`span`,{className:Y(`inline-flex max-w-[9rem] items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,e.running&&`text-accent-fg`),children:[(0,Z.jsx)(Yt,{className:`size-3 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function BA(e){let t=(0,X.c)(39),{items:n,activeMessageIndex:r,labels:i,openLabel:a,closeLabel:o,currentLabel:s,onSelectMessage:c}=e,l;t[0]!==n||t[1]!==i?(l=PA(n,i),t[0]=n,t[1]=i,t[2]=l):l=t[2];let u=l,[d,f]=(0,Q.useState)(!1);if(u.length<4)return null;let p;t[3]!==r||t[4]!==u?(p=IA(u,r),t[3]=r,t[4]=u,t[5]=p):p=t[5];let m=p,h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsx)(Le,{className:`size-[1.125rem]`,strokeWidth:1.8,"aria-hidden":!0}),t[6]=h):h=t[6];let g;t[7]===a?g=t[8]:(g=(0,Z.jsx)(w,{asChild:!0,children:(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,className:`size-10 shrink-0 rounded-full p-0 sm:size-9 xl:hidden`,"aria-label":a,title:a,children:h})}),t[7]=a,t[8]=g);let _;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[80] bg-scrim/60 backdrop-blur-[1px] xl:hidden`}),t[9]=_):_=t[9];let v;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(v=Y(`xopc-dialog-content-pane fixed inset-x-2 bottom-[max(.5rem,env(safe-area-inset-bottom))] z-[90] flex h-[min(72dvh,34rem)] flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-overlay shadow-popover outline-none`,`sm:left-auto sm:right-3 sm:w-[min(24rem,calc(100vw-1.5rem))]`,`md:bottom-[max(1rem,env(safe-area-inset-bottom))] md:right-4 md:h-[min(calc(100dvh-6rem),40rem)]`,`xl:hidden`),t[10]=v):v=t[10];let y;t[11]===i.title?y=t[12]:(y=(0,Z.jsx)(k,{className:`min-w-0 truncate text-base font-semibold text-fg`,children:i.title}),t[11]=i.title,t[12]=y);let b;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Z.jsx)(Xt,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[13]=b):b=t[13];let x;t[14]===o?x=t[15]:(x=(0,Z.jsx)(E,{asChild:!0,children:(0,Z.jsx)(vi,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 p-0`,"aria-label":o,children:b})}),t[14]=o,t[15]=x);let S;t[16]!==y||t[17]!==x?(S=(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-between gap-3 border-b border-edge-subtle px-3.5 py-3`,children:[y,x]}),t[16]=y,t[17]=x,t[18]=S):S=t[18];let T;if(t[19]!==m||t[20]!==s||t[21]!==i||t[22]!==c||t[23]!==u){let e;t[25]!==m||t[26]!==s||t[27]!==i||t[28]!==c?(e=e=>(0,Z.jsx)(LA,{turn:e,active:e.id===m,labels:i,currentLabel:s,onSelect:()=>{c(e.messageIndex),f(!1)}},e.id),t[25]=m,t[26]=s,t[27]=i,t[28]=c,t[29]=e):e=t[29],T=u.map(e),t[19]=m,t[20]=s,t[21]=i,t[22]=c,t[23]=u,t[24]=T}else T=t[24];let j;t[30]===T?j=t[31]:(j=(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Z.jsx)(`ol`,{className:`min-w-0`,children:T})}),t[30]=T,t[31]=j);let M;t[32]!==S||t[33]!==j?(M=(0,Z.jsxs)(D,{children:[_,(0,Z.jsxs)(O,{className:v,"aria-describedby":void 0,children:[S,j]})]}),t[32]=S,t[33]=j,t[34]=M):M=t[34];let N;return t[35]!==d||t[36]!==M||t[37]!==g?(N=(0,Z.jsxs)(A,{open:d,onOpenChange:f,children:[g,M]}),t[35]=d,t[36]=M,t[37]=g,t[38]=N):N=t[38],N}function VA(e){let{active:t,scrubbing:n,distance:r}=e;return n?r===0?`w-7 bg-fg`:r===1?`w-5 bg-fg-muted`:r===2?`w-4 bg-edge-strong/70`:t?`w-3.5 bg-accent`:`w-2.5 bg-edge-strong/45`:t?`w-3.5 bg-accent`:`w-2.5 bg-edge-strong/45`}function HA(e){let t=(0,X.c)(40),{turn:n,labels:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n.events||t[2]!==n.preview||t[3]!==n.timestamp||t[4]!==n.title||t[5]!==n.tools){let e=n.tools.slice(0,3),p=Math.max(0,n.tools.length-e.length),m=n.events.slice(0,Math.max(0,3-e.length));i=p+Math.max(0,n.events.length-m.length);let h=n.tools.length>0||n.events.length>0?[...e.map(KA),...m.map(GA),...i>0?[`+${i}`]:[]].join(` · `):n.title;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(l=Y(`pointer-events-auto absolute right-12 top-1/2 z-[100] w-[min(25rem,calc(100vw-8rem))] -translate-y-1/2`,`rounded-2xl border border-edge bg-surface-overlay p-3 text-left shadow-popover backdrop-blur`),t[15]=l):l=t[15],t[16]===n.timestamp?u=t[17]:(u=n.timestamp?(0,Z.jsx)(`div`,{className:`mb-1 flex min-w-0 justify-end text-xs`,children:(0,Z.jsx)(`time`,{suppressHydrationWarning:!0,className:`shrink-0 tabular-nums text-fg-disabled`,dateTime:new Date(n.timestamp).toISOString(),children:wy(n.timestamp)})}):null,t[16]=n.timestamp,t[17]=u),t[18]===n.preview?d=t[19]:(d=(0,Z.jsx)(`div`,{className:`min-w-0 text-sm font-semibold leading-5 text-fg`,children:(0,Z.jsx)(`span`,{className:`line-clamp-1`,children:n.preview})}),t[18]=n.preview,t[19]=d),t[20]===h?f=t[21]:(f=(0,Z.jsx)(`div`,{className:`mt-1 line-clamp-3 text-sm leading-6 text-fg-muted`,children:h}),t[20]=h,t[21]=f),a=`mt-3 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 text-sm text-fg-subtle`,t[22]!==r||t[23]!==n.title||t[24]!==n.tools.length?(o=n.tools.length>0?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Z.jsx)(Yt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:FA(n.tools.length,r)})]}):(0,Z.jsx)(`span`,{children:n.title}),t[22]=r,t[23]=n.title,t[24]=n.tools.length,t[25]=o):o=t[25],s=e.map(WA),c=m.map(UA),t[0]=r,t[1]=n.events,t[2]=n.preview,t[3]=n.timestamp,t[4]=n.title,t[5]=n.tools,t[6]=i,t[7]=a,t[8]=o,t[9]=s,t[10]=c,t[11]=l,t[12]=u,t[13]=d,t[14]=f}else i=t[6],a=t[7],o=t[8],s=t[9],c=t[10],l=t[11],u=t[12],d=t[13],f=t[14];let p;t[26]===i?p=t[27]:(p=i>0?(0,Z.jsxs)(`span`,{children:[`+`,i]}):null,t[26]=i,t[27]=p);let m;t[28]!==a||t[29]!==o||t[30]!==s||t[31]!==c||t[32]!==p?(m=(0,Z.jsxs)(`div`,{className:a,children:[o,s,c,p]}),t[28]=a,t[29]=o,t[30]=s,t[31]=c,t[32]=p,t[33]=m):m=t[33];let h;return t[34]!==m||t[35]!==l||t[36]!==u||t[37]!==d||t[38]!==f?(h=(0,Z.jsxs)(`div`,{className:l,children:[u,d,f,m]}),t[34]=m,t[35]=l,t[36]=u,t[37]=d,t[38]=f,t[39]=h):h=t[39],h}function UA(e){return(0,Z.jsxs)(`span`,{className:Y(`inline-flex min-w-0 max-w-[10rem] items-center gap-1.5`,e.tone===`branch`&&`text-accent`,e.tone===`compaction`&&`text-fg-muted`),children:[(0,Z.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-current opacity-70`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function WA(e){return(0,Z.jsxs)(`span`,{className:Y(`inline-flex min-w-0 max-w-[9rem] items-center gap-1.5`,e.running&&`text-accent`),children:[(0,Z.jsx)(Yt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},e.key)}function GA(e){return e.label}function KA(e){return e.label}function qA(e){let t=(0,X.c)(44),{items:n,activeMessageIndex:r,labels:i,onSelectMessage:a}=e,o;t[0]!==n||t[1]!==i?(o=PA(n,i),t[0]=n,t[1]=i,t[2]=o):o=t[2];let s=o,[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d,f;if(t[3]===c?(d=t[4],f=t[5]):(d=()=>{if(!c)return;let e=()=>{l(null)},t=t=>{let n=t.target;n instanceof Node&&(u.current?.contains(n)||e())},n=t=>{t.key===`Escape`&&e()};return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n)}},f=[c],t[3]=c,t[4]=d,t[5]=f),(0,Q.useEffect)(d,f),s.length<4)return null;let p;if(t[6]!==r||t[7]!==s){p=s[0]?.id;for(let e of s)e.messageIndex<=r&&(p=e.id);t[6]=r,t[7]=s,t[8]=p}else p=t[8];let m=c??p,h;t[9]!==c||t[10]!==s?(h=c?s.find(e=>e.id===c):null,t[9]=c,t[10]=s,t[11]=h):h=t[11];let g=h,_=c!==null,v;if(t[12]!==m||t[13]!==s){let e;t[15]===m?e=t[16]:(e=e=>e.id===m,t[15]=m,t[16]=e),v=s.findIndex(e),t[12]=m,t[13]=s,t[14]=v}else v=t[14];let y=Math.max(0,v),b=i.title,x,S;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>{l(null)},S=e=>{let t=e.relatedTarget;(!(t instanceof Node)||!e.currentTarget.contains(t))&&l(null)},t[17]=x,t[18]=S):(x=t[17],S=t[18]);let C;t[19]===p?C=t[20]:(C=()=>l(e=>e??p??null),t[19]=p,t[20]=C);let w;if(t[21]!==a||t[22]!==_||t[23]!==m||t[24]!==y||t[25]!==s){let e;t[27]!==a||t[28]!==_||t[29]!==m||t[30]!==y?(e=(e,t)=>{let n=e.id===m,r=Math.abs(t-y);return(0,Z.jsx)(`li`,{className:`group relative flex h-3.5 w-full shrink-0 items-center justify-end`,onMouseEnter:()=>l(e.id),onFocus:()=>l(e.id),children:(0,Z.jsx)(`button`,{type:`button`,className:Y(`flex h-3.5 w-full items-center justify-end rounded-sm pr-1.5`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),onClick:()=>a(e.messageIndex),"aria-label":`${e.title}: ${e.preview}`,children:(0,Z.jsx)(`span`,{className:Y(`block h-0.5 rounded-full transition-[width,background-color] duration-150 ease-out`,VA({active:n,scrubbing:_,distance:r}),`group-hover:bg-fg`),"aria-hidden":!0})})},e.id)},t[27]=a,t[28]=_,t[29]=m,t[30]=y,t[31]=e):e=t[31],w=s.map(e),t[21]=a,t[22]=_,t[23]=m,t[24]=y,t[25]=s,t[26]=w}else w=t[26];let T;t[32]!==w||t[33]!==C?(T=(0,Z.jsx)(`div`,{className:`chat-timeline-scroll flex min-h-0 w-full flex-col`,children:(0,Z.jsx)(`ol`,{className:`my-auto flex w-full shrink-0 flex-col items-end py-1`,onMouseEnter:C,children:w})}),t[32]=w,t[33]=C,t[34]=T):T=t[34];let E;t[35]!==i||t[36]!==g?(E=g?(0,Z.jsx)(HA,{turn:g,labels:i}):null,t[35]=i,t[36]=g,t[37]=E):E=t[37];let D;t[38]!==T||t[39]!==E?(D=(0,Z.jsxs)(`div`,{className:`relative z-[90] flex h-full min-h-0 w-full flex-col justify-center overflow-visible`,children:[T,E]}),t[38]=T,t[39]=E,t[40]=D):D=t[40];let O;return t[41]!==i.title||t[42]!==D?(O=(0,Z.jsx)(`aside`,{ref:u,className:`hidden h-full min-h-0 max-h-full w-12 shrink-0 items-center overflow-visible py-4 xl:flex`,"aria-label":b,onMouseLeave:x,onBlur:S,children:D}),t[41]=i.title,t[42]=D,t[43]=O):O=t[43],O}function JA(e){return e.enabled?e.sourceContextPending?`pending:${e.conversationId??``}`:e.task?`task:${e.task.task.id}:${e.task.task.version}`:e.suppressProjectContext?`suppressed:${e.conversationId??``}`:e.project?`project:${e.project.id}:${e.project.name}`:e.conversationId?`session:${e.conversationId}:failed:${e.sourceContextFailed?`1`:`0`}`:`empty`:`disabled`}function YA(e){let t=JA(e);if(!e.enabled)return{key:t,context:{kind:`empty`},status:`ready`};if(e.sourceContextPending)return{key:t,context:{kind:`empty`},status:`loading`};if(e.task){let n=e.task.receipts[0];return{key:t,context:{kind:`task`,taskId:e.task.task.id,taskTitle:e.task.task.title,phase:e.task.task.phase,operationalState:e.task.operationalState,attentionSummary:e.task.attention[0]?.summary,nextAction:n?.nextAction,recentFailure:n?.failure?.recoveryAction},status:`ready`}}return e.suppressProjectContext?{key:t,context:{kind:`empty`},status:e.sourceContextFailed?`degraded`:`ready`}:e.project?{key:t,context:{kind:`project`,projectId:e.project.id,projectName:e.project.name},status:`ready`}:{key:t,context:{kind:`empty`},status:e.conversationId?`loading`:`ready`}}function XA(e){let{enabled:t,conversationId:n,sourceContextPending:r,sourceContextFailed:i,suppressProjectContext:a,project:o,task:s}=e,c=JA(e),[l,u]=(0,Q.useState)(()=>YA(e));(0,Q.useEffect)(()=>{let e=!1,l=YA({enabled:t,conversationId:n,sourceContextPending:r,sourceContextFailed:i,suppressProjectContext:a,project:o,task:s});if(u(l),!(!t||!n||r||s||a))return(async()=>{let t=!!i,r=o?.id??null;if(!r)try{let e=await jr(n);r=e?e.creation.projectId?.trim()||null:(await hn(n)).projectId?.trim()||null}catch{t=!0}if(!r){e||u({key:c,context:{kind:`empty`},status:t?`degraded`:`ready`});return}try{let[n,i]=await Promise.allSettled([o?Promise.resolve(o):fn(r),pn(r)]);if(n.status===`rejected`)throw n.reason;let a=i.status===`fulfilled`?i.value:null;a||(t=!0);let s=a?.blockers[0],l=a?.digest.health===`attention`?a.recentResults.find(({receipt:e})=>e.status===`failed`||e.verification.status===`failed`):void 0;e||u({key:c,context:{kind:`project`,projectId:r,projectName:n.value.name,recommendedAction:a?.digest.recommendedAction,blockedReason:s?.detail??s?.title,recentFailure:l?.receipt.failure?.recoveryAction??l?.receipt.summary},status:t?`degraded`:`ready`})}catch{e||u({key:c,context:{kind:`empty`},status:`degraded`})}})(),()=>{e=!0}},[n,c,t,i,r,a,o,s]);let d=l.key===c?l:YA(e);return{context:d.context,status:d.status}}var ZA=[Ht,Rt,ws];function QA(e){let t=(0,X.c)(20),{agentName:n,messages:r,disabled:i,onPick:a}=e,o;t[0]!==r.setupPromptComplete||t[1]!==r.setupPromptIdentity||t[2]!==r.setupPromptProject?(o=[r.setupPromptIdentity,r.setupPromptProject,r.setupPromptComplete],t[0]=r.setupPromptComplete,t[1]=r.setupPromptIdentity,t[2]=r.setupPromptProject,t[3]=o):o=t[3];let s=o,c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(`div`,{className:`flex size-12 items-center justify-center rounded-2xl bg-accent-soft text-accent`,children:(0,Z.jsx)(Ht,{className:`size-6`,strokeWidth:1.75,"aria-hidden":!0})}),t[4]=c):c=t[4];let l;t[5]===r.setupTitle?l=t[6]:(l=(0,Z.jsx)(`h1`,{id:`agent-setup-title`,className:`mt-4 text-balance text-xl font-semibold tracking-tight text-fg`,children:r.setupTitle}),t[5]=r.setupTitle,t[6]=l);let u;t[7]!==n||t[8]!==r.setupDescription?(u=r.setupDescription.replace(`{{name}}`,n),t[7]=n,t[8]=r.setupDescription,t[9]=u):u=t[9];let d;t[10]===u?d=t[11]:(d=(0,Z.jsx)(`p`,{className:`mt-2 max-w-xl text-pretty text-sm leading-relaxed text-fg-muted`,children:u}),t[10]=u,t[11]=d);let f;t[12]!==i||t[13]!==a||t[14]!==s?(f=(0,Z.jsx)(`div`,{className:`mt-7 grid w-full gap-3 md:grid-cols-3`,children:s.map((e,t)=>{let n=ZA[t]??Ht;return(0,Z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>a(e),className:Y(`flex min-h-24 items-center gap-3 rounded-xl border border-edge bg-surface-panel px-4 py-4 text-left text-sm font-medium leading-relaxed text-fg`,`hover:border-accent/30 hover:bg-surface-hover`,ca.transition,ca.pressCard,ca.focusRingPanel,ca.disabled),children:[(0,Z.jsx)(n,{className:`size-4 shrink-0 text-accent`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:e})]},e)})}),t[12]=i,t[13]=a,t[14]=s,t[15]=f):f=t[15];let p;return t[16]!==l||t[17]!==d||t[18]!==f?(p=(0,Z.jsxs)(`section`,{className:`mx-auto flex w-full max-w-4xl flex-col items-center px-2 pb-4 pt-12 text-center sm:pt-16`,"aria-labelledby":`agent-setup-title`,children:[c,l,d,f]}),t[16]=l,t[17]=d,t[18]=f,t[19]=p):p=t[19],p}var $A=t({ChatPage:()=>tj}),ej=(0,Q.lazy)(async()=>({default:(await l(()=>import(`./chat-terminal-dock-eneTvxV3.js`),__vite__mapDeps([46,1,2,5,6,47,11,48,26,27,17,18,49,50,51,52,53,54,55,56,57,58,59,60,4,61,62,28,29,9,63,64,65,66]))).ChatTerminalDock}));function tj({beforeSend:e,draftSeed:t,sourceNoteInView:n=!1,embedded:r=!1,conversationId:i,taskId:a,personal:o=!1,personalWelcome:s,automationWorkspace:c=!1,automationTimelineEntries:l,readOnly:u=!1,onHistoryReady:h,automationExecution:g=!1,initialTurnId:y,onInitialTurnLocated:b}={}){let x=v(e=>e.language),w=S(x),E=_(e=>e.conversationId),j=m(),M=d(),{pathname:N}=M,[P,F]=f(),I=(0,Q.useRef)(null),L=(0,Q.useRef)(0),R=(0,Q.useRef)(null),[z,B]=(0,Q.useState)(null),[ee,V]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{V(t??null)},[t]);let[U,W]=(0,Q.useState)(()=>!!(i&&window.localStorage.getItem(`personal-calibration:${i}`))),[te,ne]=(0,Q.useState)(null),[re,ie]=(0,Q.useState)(null),[ae,oe]=(0,Q.useState)(!1),[se,ce]=(0,Q.useState)(null),le=a?.trim()||null,{data:ue}=Ks(le??``),{auth:de,session:G,messages:K,timeline:fe,stream:q,followUp:pe,clarify:me,agents:J}=EA({fixedConversationId:i,taskId:le??void 0,personal:o}),he=pe.composerMode.kind===`editTurn`?pe.composerMode:null,ge=Sn(e=>!!(G.conversationId&&!e.shellError&&e.sessions[G.conversationId]?.historyStatus===`ready`));(0,Q.useEffect)(()=>{ge&&K.items.length>0&&h?.()},[ge,K.items.length,h]),(0,Q.useLayoutEffect)(()=>{if(!c&&!g||!G.conversationId)return;let e=G.conversationId;return fp.setState({conversationIdOverride:e}),()=>{fp.getState().conversationIdOverride===e&&fp.setState({conversationIdOverride:null})}},[c,g,G.conversationId]);let _e=!o&&!r&&!le&&P.get(`scene`)===`find-skills`,ve=c||P.get(`setup`)===`automation`,ye=!r&&!le&&P.get(`agentSetup`)===`1`,be=o?``:P.get(`skill`)?.trim()??``,xe=o?``:P.get(`slash`)?.trim()??``;(0,Q.useEffect)(()=>{if(!o||!P.has(`skill`)&&!P.has(`slash`))return;let e=new URLSearchParams(P);e.delete(`skill`),e.delete(`slash`),F(e,{replace:!0})},[o,P,F]);let Se=P.get(c?`chatDraft`:`draft`)??``,Ce=P.get(`autoSend`)===`1`,we=P.get(`attachmentHandoff`),Te=P.get(`attachmentsHandoff`),Ee=G.decodedKey??G.conversationId,[De,ke]=(0,Q.useState)(null),Ae=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(we){let e=Ne(we);e&&ke(e),Ae.current=Ee;return}Ae.current!==Ee&&(Ae.current=Ee,ke(null))},[we,Ee]);let je=Yf(e=>e.markViewed),Me=Yf(e=>Ee?e.runs[Ee]?.unread:!1);(0,Q.useEffect)(()=>{Ee&&Me&&je(Ee)},[Ee,Me,je]);let{data:Pe}=DA(Ee),Fe=ve||!!Pe?.identity?.customData?.automationSetup,Ie=!!Pe?.identity?.customData?.automationSetup?.automationId,Le=(0,Q.useCallback)(async e=>{if(Ee)try{let t=await G.sessionManager.forkSessionAtTurn(Ee,e);window.dispatchEvent(new CustomEvent(`session-created`,{detail:{key:t.conversationId,conversationId:t.conversationId}})),ya(`success`,w.chat.messageForkCreated),j(`/chat/${encodeURIComponent(t.conversationId)}`)}catch(e){throw ya(`error`,e instanceof Error?e.message:w.chat.messageForkFailed),e}},[Ee,w.chat.messageForkCreated,w.chat.messageForkFailed,j,G.sessionManager]),Re=K.items.at(-1),ze=o&&!U&&!q.streaming&&!q.sending&&Re?.role===`assistant`&&K.items.filter(e=>e.role===`user`).length===1&&K.items.filter(e=>e.role===`assistant`).length===1&&!K.items.some(e=>e.role===`task`),Be=e=>{W(!0),i&&window.localStorage.setItem(`personal-calibration:${i}`,`1`),e&&(L.current+=1,B({id:L.current,text:e}))};(0,Q.useEffect)(()=>{I.current=null},[G.conversationId]),(0,Q.useEffect)(()=>{if(!de.hasToken||!be&&!xe&&!Se&&!(G.projectPreparation&&Te)||Ce&&!G.projectPreparation||G.showSessionLoading||G.sessionRoutePending||!G.conversationId&&!G.projectPreparation)return;let e=G.projectPreparation&&Te?ji(Te)??void 0:void 0,t=()=>{let e=new URLSearchParams(P);e.delete(`skill`),e.delete(`slash`),e.delete(c?`chatDraft`:`draft`),G.projectPreparation&&(e.delete(`autoSend`),e.delete(`attachmentsHandoff`));let t=e.toString();j({pathname:N,search:t?`?${t}`:``},{replace:!0})},n=(n,r)=>{I.current!==r&&(I.current=r,queueMicrotask(()=>{e?.length?rm(n,e):(L.current+=1,B({id:L.current,text:n})),t()}))},r=Ia(be,Se);if(r||e?.length){let e=`${G.conversationId}:draft:${r}`;n(r??``,e);return}if(be){t();return}if(!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(xe)){t();return}let i=`${G.conversationId}:slash:${xe}`;I.current!==i&&queueMicrotask(()=>{(async()=>{try{let e=await Do(),t=xe.toLowerCase(),n=e.find(e=>e.name.toLowerCase()===t||Array.isArray(e.aliases)&&e.aliases.some(e=>e.toLowerCase()===t));if(n){if(I.current===i)return;I.current=i,L.current+=1,B({id:L.current,text:Bw(n)})}}finally{t()}})()})},[de.hasToken,c,be,xe,Se,Ce,Te,G.projectPreparation,P,G.showSessionLoading,G.sessionRoutePending,G.conversationId,j,N]);let{scrollRef:He,composerDockRef:Ke,atBottom:qe,registerListContentRef:Je,scrollToBottom:Ye,replySpaceRef:Xe,reserveReplySpace:Ze,onScroll:Qe}=Tw({hasToken:de.hasToken,showSessionLoading:G.showSessionLoading,conversationId:G.conversationId,chatMessages:K.items,streaming:q.streaming,hasMore:G.hasMore,loadingMore:G.loadingMore,loadMoreMessages:G.loadMoreMessages});(0,Q.useEffect)(()=>{if(!c||!qe||!l?.length)return;let e=requestAnimationFrame(()=>Ye(!1));return()=>cancelAnimationFrame(e)},[c,l,qe,Ye]);let $e=XO({enabled:o,conversationId:G.conversationId,messages:K.items,viewportRef:He}),[et,tt]=(0,Q.useState)(0),nt=(0,Q.useRef)(null),rt=(0,Q.useRef)(null),it=(0,Q.useMemo)(()=>{let e=-1;for(let t of fe.items)typeof t.displayIndex==`number`&&Number.isFinite(t.displayIndex)&&(e=Math.max(e,t.displayIndex));return e<0?0:Math.max(0,e+1-K.items.length)},[K.items.length,fe.items]),at=(0,Q.useCallback)(e=>{let t=He.current;if(!t)return!1;let n=t.querySelector(`[data-chat-message-index="${e}"]`);if(!n){let n=rw(t)?.reveal(e)??!1;return n&&tt(e),n}iw(t),tt(e);let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=t.scrollTop+i.top-r.top-16;return t.scrollTo({top:Math.max(0,a),behavior:ew()}),!0},[He]),ot=(0,Q.useCallback)(()=>{let e=He.current;if(!e)return;let t=$C(e);tt(e=>e===t?e:t)},[He]),st=(0,Q.useCallback)(()=>{nt.current??=requestAnimationFrame(()=>{nt.current=null,ot()})},[ot]),ct=(0,Q.useCallback)(()=>{Qe(),st()},[Qe,st]),lt=(0,Q.useCallback)(e=>{let t=e-it;if(t<0||t>=K.items.length){t<0&&G.hasMore&&!G.loadingMore&&(rt.current=e,G.loadMoreMessages());return}rt.current=null,at(t)},[K.items.length,at,G.hasMore,G.loadMoreMessages,G.loadingMore,it]);$w({conversationId:G.conversationId,turnId:y,messages:K.items,ready:ge,hasMore:G.hasMore,loadingMore:G.loadingMore,loadMore:G.loadMoreMessages,reveal:at,onLocated:b});let ut=mk({conversationId:G.conversationId,taskId:le,messages:K.items,displayOffset:it,viewportRef:He,onRevealDisplayIndex:lt});(0,Q.useEffect)(()=>{let e=rt.current;if(e==null)return;let t=e-it;if(t>=0&&t<K.items.length){rt.current=null,requestAnimationFrame(()=>at(t));return}if(t<0&&G.hasMore&&!G.loadingMore){G.loadMoreMessages();return}(t>=K.items.length||!G.hasMore)&&(rt.current=null)},[K.items.length,at,G.hasMore,G.loadMoreMessages,G.loadingMore,it]),(0,Q.useEffect)(()=>{st()},[K.items.length,st,G.conversationId,it]),(0,Q.useEffect)(()=>()=>{nt.current!=null&&cancelAnimationFrame(nt.current)},[]),(0,Q.useEffect)(()=>{B(null)},[G.conversationId]);let dt=(0,Q.useCallback)(e=>{L.current+=1,B({id:L.current,text:e.prompt})},[]),ft=!!(G.conversationId&&!G.showSessionLoading&&!G.sessionRoutePending&&G.workspaceSource!==`project`&&G.workspaceSource!==`execution_environment`&&K.items.length===0),pt=ho(e=>e.setAgentId);(0,Q.useEffect)(()=>{if(de.hasToken)return pt(J.displayAgentId),()=>pt(``)},[de.hasToken,J.displayAgentId,pt]);let mt=G.conversationPhase===`creating-session`,ht=G.conversationPhase===`loading-history`;Hf(o&&!ht?Ee:null,o);let gt=mt||ht,_t=ht,vt=!_t&&K.items.length===0&&!l?.length&&!q.streaming,yt=(0,Q.useMemo)(()=>{if(q.taskPlan){let e=PO(q.taskPlan);return e?{plan:e,changeSummary:qO(K.items,q.streaming)?.changeSummary??null}:null}return qO(K.items,q.streaming)},[K.items,q.streaming,q.taskPlan]),bt=(0,Q.useMemo)(()=>(G.sessionRoutePending&&G.decodedKey?G.decodedKey:G.conversationId)?G.sessionName?.trim()||w.chat.newSession:w.nav.chat,[G.conversationId,G.sessionName,G.sessionRoutePending,G.decodedKey,w.nav.chat,w.chat.newSession]),xt=Pe?.sourceNoteId??null,St=kD(Ee,P.get(`projectId`)),wt=G.projectPreparation?.project??St,[Tt,Et]=(0,Q.useState)([]),[Dt,Ot]=(0,Q.useState)([]),kt=_(e=>e.baseUrl),At=Ee?cs(kt,E,Ee):null,jt=ss.store(e=>At?e.drafts[At]:void 0),Mt=(0,Q.useRef)(void 0),[Nt,Pt]=(0,Q.useState)(!1);(0,Q.useLayoutEffect)(()=>{Ee&&Ee!==Mt.current&&(Mt.current=void 0)},[Ee]),(0,Q.useEffect)(()=>{let e=!1;if(ne(null),xt)return Ve(xt).then(t=>{e||ne(t?.title?.trim()||null)}).catch(()=>{e||ne(null)}),()=>{e=!0}},[xt]);let Ft=te||Pe?.sourceNoteTitle||w.chat.sourceNoteFallbackTitle,It=XA({enabled:de.hasToken&&!!(Ee||wt)&&!ye&&K.items.length===0&&!G.showSessionLoading&&!G.sessionRoutePending,conversationId:Ee,suppressProjectContext:!!(xt||De||G.workspaceSource===`execution_environment`||G.workspaceSource===`session_override`||G.workspaceSource===`agent_workspace`),project:wt,task:ue}),Lt=(0,Q.useMemo)(()=>J.chatAgents?.items.find(e=>e.id===J.displayAgentId)??{id:J.displayAgentId},[J.chatAgents?.items,J.displayAgentId]),Rt=(0,Q.useMemo)(()=>Rs(It.context,w.chat.welcomeSpotlight,{contextStatus:It.status}),[w.chat.welcomeSpotlight,It.context,It.status]),zt=(0,Q.useMemo)(()=>Rt.recommendation?{suggestionId:Rt.recommendation.id,contextKind:Rt.contextKind,prompt:Rt.recommendation.prompt}:null,[Rt]),Bt=(0,Q.useRef)(0);(0,Q.useEffect)(()=>(Bt.current++,()=>{Bt.current++}),[i,E]);let Vt=(0,Q.useCallback)((...t)=>{let n=()=>{let[e,n,r,i,a]=t;if(jt&&(he||e.trim().startsWith(`/`)))return Sn.getState().setShellError(w.chat.pageContext.pending),!1;if(he)return q.replaceLatestUserTurn(he.turnId,e,n,r,i,a?.submittedAt);let o=!1,s=q.sendMessage(e,n,r,i,void 0,jt?.envelope,(e,t)=>{o=!0,Ze(t??e),a?.onDispatched?.({clientSubmissionId:e,messageRenderKey:t})},void 0,a?.submittedAt);return o?(At&&jt&&ss.remove(At,jt),!0):s};if(!e)return n();let r=Bt.current;return e().then(e=>e&&r===Bt.current?n():!1)},[e,he,q.replaceLatestUserTurn,q.sendMessage,jt,At,w.chat.pageContext.pending,Ze]),Ht=OD({preparation:G.projectPreparation,conversationId:Ee,ready:G.modelConfigReady&&!gt,onSend:Vt}),Ut=(0,Q.useCallback)(e=>{if(!e.turnId||!G.conversationId)return;let t=kn.getGeneration(G.conversationId),n=kn.getResumeRunId(G.conversationId);pe.beginEditTurn(e.turnId,{text:e.userTurnDocument?Tr(e.userTurnDocument):Wn(e.content),attachments:Kn(e.attachments)??[],contextRefs:e.contextRefs?.flatMap(e=>e.kind===`mcp_resource`?[]:[{refId:e.refId,kind:e.kind,sourceId:e.sourceId,expectedVersion:e.version,title:e.title,fileKind:e.fileKind}])??[]}).then(e=>{e&&q.settleStoppedRun(t,n)})},[pe.beginEditTurn,q.settleStoppedRun,G.conversationId]),Wt=(0,Q.useCallback)(e=>{if(pe.composerMode.kind===`editFollowUp`)pe.beginEditFollowUp(pe.composerMode.inputId);else if(pe.composerMode.kind===`editTurn`&&G.conversationId){let t=kn.getGeneration(G.conversationId),n=kn.getResumeRunId(G.conversationId);pe.beginEditTurn(pe.composerMode.turnId,e).then(e=>{e&&q.settleStoppedRun(t,n)})}},[pe.composerMode,pe.beginEditFollowUp,pe.beginEditTurn,G.conversationId,q.settleStoppedRun]),Gt=pe.cancelEditor;(0,Q.useEffect)(()=>{if(!Ce||!Se.trim()&&!Te||!de.hasToken||G.showSessionLoading||G.sessionRoutePending||!G.conversationId||q.sending||q.streaming)return;let e=Ia(be,Se),t=Te?ji(Te):void 0;if(!e&&!t?.length)return;let n=`${G.conversationId}:auto-send:${e??``}:${Te??``}`;if(I.current===n)return;I.current=n;let r=new URLSearchParams(P);r.delete(`skill`),r.delete(`slash`),r.delete(`draft`),r.delete(`autoSend`),r.delete(`attachmentsHandoff`);let i=r.toString();j({pathname:N,search:i?`?${i}`:``},{replace:!0}),Vt(e??``,t??void 0)},[de.hasToken,Ce,Te,Se,Vt,j,N,P,G.conversationId,G.sessionRoutePending,G.showSessionLoading,be,q.sending,q.streaming]);let Kt=(0,Q.useCallback)(()=>{R.current?.reject(),R.current=null,ie(null),oe(!1)},[]);(0,Q.useEffect)(()=>{Kt()},[Kt,xt]);let qt=(0,Q.useMemo)(()=>({title:w.chat.timelineTitle,turn:w.chat.timelineTurn,messageFallback:w.chat.timelineMessageFallback,toolCount_one:w.chat.timelineToolCount_one,toolCount_other:w.chat.timelineToolCount_other,searchedWeb:w.chat.stepSearchedWeb,searchedMemory:w.chat.stepSearchedMemory,searchedCode:w.chat.stepSearchedCode,searched:w.chat.stepSearched,readFile:w.chat.stepReadFile,runCommand:w.chat.stepRunCommand,listDirectory:w.chat.stepListDirectory,writeFile:w.chat.stepWriteFile,editFile:w.chat.stepEditFile,openUrl:w.chat.stepOpenUrl,fetchUrl:w.chat.stepFetchUrl,unknownTool:w.chat.stepUnknownTool}),[w.chat.timelineTitle,w.chat.timelineTurn,w.chat.timelineMessageFallback,w.chat.timelineToolCount_one,w.chat.timelineToolCount_other,w.chat.stepSearchedWeb,w.chat.stepSearchedMemory,w.chat.stepSearchedCode,w.chat.stepSearched,w.chat.stepReadFile,w.chat.stepRunCommand,w.chat.stepListDirectory,w.chat.stepWriteFile,w.chat.stepEditFile,w.chat.stepOpenUrl,w.chat.stepFetchUrl,w.chat.stepUnknownTool]),Jt=(0,Q.useCallback)(async e=>{if(!xt)return;R.current?.reject(),oe(!1);let t=w.chat.sourceNoteAppendSourceLine.replace(`{{time}}`,new Date().toLocaleString(x));return ie({heading:w.chat.sourceNoteAppendHeading,content:`${t}\n\n${e.trim()}`}),new Promise((e,t)=>{R.current={sourceNoteId:xt,resolve:e,reject:t}})},[x,w.chat.sourceNoteAppendHeading,w.chat.sourceNoteAppendSourceLine,xt]),Yt=`${M.pathname}${M.search}`,Xt=(0,Q.useCallback)(async e=>{try{let t=await Ge(e.trim(),`web`);ya(`success`,w.chat.messageSavedToNote,void 0,{href:Ct(Yt,t.id)})}catch(e){throw ya(`error`,e instanceof Error?e.message:w.notes.quickCaptureFailed),e}},[Yt,w.chat.messageSavedToNote,w.notes.quickCaptureFailed]),Zt=(0,Q.useCallback)(async()=>{let e=R.current;if(!e||!re)return;let t=re.heading.trim()||w.chat.sourceNoteAppendHeading,n=re.content.trim();if(n){oe(!0),ce(null);try{await We(e.sourceNoteId,n,t),window.dispatchEvent(new CustomEvent(`note-updated`,{detail:{noteId:e.sourceNoteId,source:`chat`,conversationId:Ee}})),e.resolve(),R.current=null,ie(null)}catch(e){ce(e instanceof Error?e.message:w.chat.sourceNoteSaveFailed)}finally{oe(!1)}}},[Ee,w.chat.sourceNoteAppendHeading,w.chat.sourceNoteSaveFailed,w.chat.sourceNoteSaveSuccess,re]),$t=(0,Q.useCallback)(async e=>{if(!xt)return;let t=e.trim().split(/\n+/)[0]?.replace(/^[-#*>\s]+/,``).trim()||w.chat.sourceNoteTaskFallbackTitle;try{await Ue(t.slice(0,120),{sourceNoteId:xt,sourceConversationId:Ee})}catch(e){throw ya(`error`,e instanceof Error?e.message:w.chat.sourceNoteTaskFailed),e}},[Ee,w.chat.sourceNoteTaskFailed,w.chat.sourceNoteTaskFallbackTitle,w.chat.sourceNoteTaskSuccess,xt]),en=(0,Q.useCallback)(async()=>{if(!xt)return;let t=Bt.current;if(e&&(!await e()||t!==Bt.current))return;let n=w.chat.sourceNoteDigestPrompt.replace(`{{title}}`,Ft);if(q.streaming||q.sending){pe.addPendingFollowUp(n),va({tone:`info`,status:`done`,title:w.chat.sourceNoteDigestQueued,source:x===`zh`?`笔记整理`:`Note digest`,dedupeKey:xt?`note-digest:${xt}`:void 0});return}q.sendMessage(n)},[e,pe,x,w.chat.sourceNoteDigestPrompt,w.chat.sourceNoteDigestQueued,xt,Ft,q]),tn=(0,Q.useCallback)(async e=>{if(!(Nt||Ht.busy)){if(G.projectPreparation){j(Ra(e),{state:{forceNewChat:!0,agentId:J.displayAgentId,temporary:G.userContextMode===`temporary`}});return}if(!(Mt.current!==void 0||q.sending||q.streaming||gt)){Mt.current=Ee,Pt(!0);try{e?j(Ra(e),{state:{forceNewChat:!0,agentId:J.displayAgentId,temporary:G.userContextMode===`temporary`}}):await G.createNewSession({forceNew:!0,projectId:e,temporary:G.userContextMode===`temporary`})}catch(e){Mt.current=void 0,ya(`error`,w.chat.composerContext.changeFailed,{error:e instanceof Error?e.message:String(e)})}finally{Pt(!1)}}}},[Ee,gt,w.chat.composerContext.changeFailed,Nt,Ht.busy,G.createNewSession,G.projectPreparation,G.userContextMode,q.sending,q.streaming,j,J.displayAgentId]),nn=(0,Q.useCallback)(()=>tn(null),[tn]),rn=(0,Q.useCallback)(async e=>{if(!(Nt||gt||q.sending||q.streaming||!ft)){Pt(!0);try{await G.onSessionWorkingDirectoryChange(e)}finally{Pt(!1)}}},[Nt,gt,q.sending,q.streaming,ft,G.onSessionWorkingDirectoryChange]),an=(0,Q.useMemo)(()=>({project:wt,draftRefs:Tt,draftAttachments:Dt,draftPage:jt?{id:`${jt.envelope.tabId}:${jt.envelope.sequence}`,title:jt.title||(x===`zh`?`当前页面`:`Current page`)}:void 0,onLeaveProject:Nt||Ht.busy?void 0:nn,leaveProjectLabel:w.chat.scopeRemoveProject,onDraftSourceNote:xt?en:void 0,draftSourceNoteLabel:w.chat.sourceNoteDigestAction}),[Nt,Ht.busy,wt,Tt,Dt,jt,x,nn,w.chat.scopeRemoveProject,xt,en,w.chat.sourceNoteDigestAction]);return de.hasToken?(q.error?Or(q.error):null)?.code===`session_not_found`?(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col overflow-hidden bg-surface-panel`,children:[(0,Z.jsx)(SO,{}),(0,Z.jsx)(pO,{chatHeadline:w.chat.sessionNotFoundTitle,chatAgents:J.chatAgents?.items??[],showChatAgentSelector:!1,chatAgentId:J.displayAgentId,onChatAgentChange:J.onChatAgentChange,chatAgentDisabled:!0}),(0,Z.jsx)(`main`,{className:`mx-auto flex w-full max-w-xl flex-1 items-center px-4 py-12 sm:px-6`,children:(0,Z.jsx)(`div`,{className:`w-full`,children:(0,Z.jsx)(yh,{errorText:q.error})})})]}):(0,Z.jsx)($_,{value:Fe,children:(0,Z.jsxs)(`div`,{className:Y(`flex h-full min-h-0 flex-1 flex-col bg-surface-panel`,c?`overflow-clip`:`overflow-hidden`),children:[(0,Z.jsx)(SO,{}),!r||c?(0,Z.jsx)(pO,{inline:c,chatHeadline:_e&&K.items.length===0?w.skills.findTitle:bt,chatAgents:J.chatAgents?.items??[],showChatAgentSelector:!c&&!ye&&J.showChatAgentSelector,chatAgentId:J.displayAgentId,onChatAgentChange:J.onChatAgentChange,chatAgentDisabled:Ht.busy||Nt||gt&&!G.projectPreparation,conversationId:G.conversationId,hasMessages:!gt&&K.items.length>0,workspacePath:G.effectiveWorkspacePath,userContextMode:G.userContextMode,projectId:wt?.id,context:an,canChangeWorkspace:!1,workspaceDisabled:gt||q.sending||q.streaming,onWorkspaceChange:G.onSessionWorkingDirectoryChange,prepareTerminalSession:G.projectPreparation?Ht.prepareSession:void 0,terminalDisabled:!!(G.projectPreparation&&(Ht.busy||!Ht.allowed||Ht.checking)),showContextControls:!ye,onFindOpen:ut.show}):null,(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 w-full flex-1 flex-col`,children:[!r&&Pe?.parentConversationId?(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-edge-subtle bg-surface-panel/80 px-3 py-2 text-xs text-fg-muted sm:px-5 xl:px-6`,children:[(0,Z.jsx)(p,{to:`/chat/${encodeURIComponent(Pe.parentConversationId)}`,className:`font-medium text-accent transition-colors hover:text-accent-fg`,children:w.chat.forkedFromConversation.replace(`{{name}}`,Pe.forkedFromSessionName||w.chat.forkedFromConversationFallback)}),(0,Z.jsx)(`span`,{className:`ms-2`,children:w.chat.forkSharedWorkspaceNotice})]}):null,M.state?.fromAgentEditor&&J.displayAgentId?(0,Z.jsx)(`div`,{className:`shrink-0 border-b border-edge-subtle bg-surface-panel/80 px-3 py-1.5 sm:px-5 xl:px-6`,children:(0,Z.jsxs)(p,{to:$o(J.displayAgentId),className:`inline-flex items-center gap-1 text-xs font-medium text-accent transition-colors hover:text-accent-fg`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`←`}),w.agentsSettings.backToEditor]})}):null,r&&xt&&!n?(0,Z.jsx)(`div`,{className:`shrink-0 border-b border-edge-subtle bg-surface-panel/80 px-3 py-1.5 sm:px-5 xl:px-6`,children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:w.chat.sourceNoteBanner.replace(`{{title}}`,Ft)}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex h-7 items-center gap-1.5 rounded-md border border-edge-subtle px-2 font-medium text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,onClick:en,children:[(0,Z.jsx)(Oe,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:w.chat.sourceNoteDigestAction})]}),(0,Z.jsx)(p,{to:Ct(`${M.pathname}${M.search}`,xt),className:`font-medium text-accent transition-colors hover:text-accent-fg`,children:w.chat.sourceNoteOpen})]})]})}):null,(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(ZO,{open:ut.open,query:ut.query,activeIndex:ut.activeIndex,resultCount:ut.resultCount,searching:ut.searching,truncated:ut.truncated,limitedToLoaded:ut.limitedToLoaded,inputRef:ut.inputRef,labels:w.chat.find,onQueryChange:ut.setQuery,onPrevious:ut.previous,onNext:ut.next,onClose:ut.close}),!r||c?(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-y-0 left-1/2 z-20 hidden w-full max-w-[calc(var(--max-width-chat-frame)+8rem)] -translate-x-1/2 xl:block`,children:(0,Z.jsx)(`div`,{className:`pointer-events-auto absolute inset-y-0 right-0`,children:(0,Z.jsx)(qA,{items:fe.items,activeMessageIndex:et+it,labels:qt,onSelectMessage:lt})})}):null,(0,Z.jsx)(`div`,{ref:He,"data-chat-scroll-viewport":!0,className:Y(`chat-messages chat-messages--wide-viewport relative min-h-0 flex-1 overflow-y-auto overflow-x-hidden [overflow-anchor:none] [scrollbar-gutter:stable_both-edges]`,vt?`chat-messages--compact-welcome pt-5 pb-2`:`py-4`),onScroll:ct,"data-chat-find-open":ut.open?``:void 0,children:(0,Z.jsx)(`div`,{className:r&&!o?`px-3`:`px-3 sm:px-5 xl:px-6`,children:(0,Z.jsx)(`div`,{"data-chat-message-frame":!0,className:Y(`mx-auto w-full min-w-0`,(!r||o||c)&&`max-w-[var(--max-width-chat-frame)]`),children:ht?(0,Z.jsxs)(`div`,{className:`flex min-h-[min(40vh,20rem)] w-full flex-col gap-10 py-8`,"aria-busy":`true`,children:[(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(Qt,{className:`h-11 w-[min(70%,22rem)] rounded-2xl`})}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(Qt,{className:`h-4 w-24`}),(0,Z.jsx)(Qt,{className:`h-4 w-[min(82%,36rem)]`}),(0,Z.jsx)(Qt,{className:`h-4 w-[min(74%,32rem)]`}),(0,Z.jsx)(Qt,{className:`h-4 w-[min(48%,22rem)]`})]}),(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(Qt,{className:`h-11 w-[min(62%,18rem)] rounded-2xl`})})]}):(0,Z.jsxs)(Z.Fragment,{children:[G.loadingMore?(0,Z.jsx)(`div`,{className:`mb-3 text-center text-xs text-fg-muted`,children:w.chat.loadOlder}):null,Fe&&!c&&Ee?(0,Z.jsx)(Ho,{conversationId:Ee,language:x,running:q.streaming||q.sending}):null,Fe&&!c&&K.items.length>0?(0,Z.jsx)(p,{className:`mb-4 inline-block rounded-md px-2 py-1 text-xs text-fg-muted hover:bg-surface-hover`,to:`/automations`,children:x===`zh`?`← 定时任务`:`← Scheduled tasks`}):null,!r&&le?(0,Z.jsx)(`div`,{className:`hidden md:block`,children:(0,Z.jsx)(gc,{taskId:le})}):null,null,null,!r&&Ee?(0,Z.jsx)(H,{eventType:`session.transcript.updated`,source:`sessions`,payloadKey:`conversationId`,payloadValue:Ee,className:`mb-6`}):null,(0,Z.jsx)(fw,{scrollRef:He,messages:K.items,timelineEntries:l,personal:o,authToken:E??void 0,conversationId:G.decodedKey??G.conversationId,projectId:wt?.id,streaming:q.streaming,sending:q.sending,progress:q.progress,runError:q.error,reasoningLevel:G.reasoningLevel,showAssistantWorkLog:!0,registerListContentRef:Je,replySpaceRef:Xe,onPickWelcomePrompt:dt,welcomeSpotlight:Rt,welcomeOverlay:o&&s?(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full max-w-2xl flex-col items-start gap-3 px-4 py-8 text-fg`,children:[(0,Z.jsx)(`div`,{className:`flex size-16 items-center justify-center rounded-3xl bg-accent/10 text-3xl text-accent`,"aria-hidden":!0,children:s.avatar??`✦`}),(0,Z.jsx)(`h2`,{className:`text-2xl font-semibold`,children:x===`zh`?`你好${s.addressAs?`,${s.addressAs}`:``}。我们从哪里开始?`:`Hello${s.addressAs?`, ${s.addressAs}`:``}. Where should we start?`}),(0,Z.jsx)(`p`,{className:`max-w-xl text-sm leading-relaxed text-fg-muted`,children:s.opening??(x===`zh`?`想讨论问题、整理思路或推进工作,都可以直接说。`:`Bring a question, an idea, or work to move forward.`)})]}):Fe?(0,Z.jsxs)(`div`,{className:`mx-auto max-w-xl px-4 py-10 text-center`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-fg`,children:Ie?x===`zh`?`想怎么调整这个任务?`:`What would you like to change?`:x===`zh`?`你想安排什么任务?`:`What would you like to schedule?`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-fg-muted`,children:Ie?x===`zh`?`直接说要改的内容、时间,或告诉我暂停、恢复。`:`Change what it does or when it runs, or ask to pause or resume.`:x===`zh`?`说说要做的事,时间和细节我们一起确定。`:`Tell us what to do. We’ll work out the timing and details together.`}),c?null:(0,Z.jsx)(p,{className:`mt-4 inline-block text-xs text-fg-muted hover:text-fg`,to:`/automations`,children:x===`zh`?`← 返回定时任务`:`← Back to scheduled tasks`})]}):ye?(0,Z.jsx)(QA,{agentName:Lt.name?.trim()||J.displayAgentId,messages:w.agentsSettings,disabled:G.sessionRoutePending||G.showSessionLoading,onPick:e=>{L.current+=1,B({id:L.current,text:e})}}):_e?(0,Z.jsx)(rT,{sk:w.skills,disabled:G.sessionRoutePending||G.showSessionLoading,onPick:e=>{L.current+=1,B({id:L.current,text:Ia(`find-skills`,e)})}}):void 0,compactWelcome:r,onDeleteRound:le?void 0:q.deleteMessageRound,onRetryUserMessageRound:le?void 0:q.retryUserMessageRound,deleteRoundDisabled:q.streaming||q.sending,onEditUserMessage:le?void 0:Ut,editLatestUserOnly:!0,editRequiresTurnId:!0,onSaveAssistantAsNote:Xt,onSaveAssistantToSourceNote:xt?Jt:void 0,onExtractAssistantTask:xt?$t:void 0,onForkAssistantTurn:!le&&Pe?.sessionType===`chat`?Le:void 0,trailingContent:ze?(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-2xl rounded-2xl border border-edge-subtle bg-surface-panel px-4 py-3 text-sm`,children:[(0,Z.jsx)(`p`,{className:`text-fg-muted`,children:x===`zh`?`这个回答合适吗?点选后可以在输入框修改,再发给我。`:`Did that response work for you? Pick an adjustment, edit it, then send.`}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[[[x===`zh`?`再短一点`:`Make it shorter`,x===`zh`?`这次回答再短一点。`:`Please make this answer shorter.`],[x===`zh`?`更温和一点`:`A little gentler`,x===`zh`?`这次回答的语气更温和一点。`:`Please make this answer a little gentler.`]].map(([e,t])=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Be(t),className:`rounded-full border border-edge px-3 py-1.5 text-xs text-fg transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:e},e)),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Be(),className:`rounded-full px-3 py-1.5 text-xs text-fg-muted transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:x===`zh`?`这样就好`:`Looks good`})]})]}):null},Ee)]})})})}),(0,Z.jsx)(`div`,{ref:Ke,className:Y(`chat-composer-dock pointer-events-none absolute inset-x-0 bottom-0 z-10`,o?`[--chat-composer-bottom-radius:1.65rem]`:`[--chat-composer-bottom-radius:1rem]`,vt?`[--chat-composer-bottom-space:max(0.625rem,env(safe-area-inset-bottom))]`:`[--chat-composer-bottom-space:max(0.5rem,env(safe-area-inset-bottom))] sm:[--chat-composer-bottom-space:max(1rem,env(safe-area-inset-bottom))]`),children:(0,Z.jsx)(`div`,{className:r&&!o?`px-3`:`px-3 sm:px-5 xl:px-6`,children:(0,Z.jsxs)(`div`,{"data-chat-composer-frame":!0,"data-primary-chat-composer":!r||void 0,className:Y(`pointer-events-auto relative mx-auto w-full min-w-0 pb-[var(--chat-composer-bottom-space)]`,(!r||o||c)&&`max-w-[calc(var(--max-width-chat-frame)+14px)]`,vt?`pt-2.5`:`pt-2 sm:pt-4`),children:[(0,Z.jsx)(yw,{visible:!G.showSessionLoading&&!qe,onClick:()=>Ye(!0),running:q.streaming||q.sending}),(0,Z.jsx)(`div`,{className:`absolute bottom-full right-0 z-20 mb-2 flex items-center rounded-full border border-edge-subtle bg-surface-overlay p-1 shadow-elevated backdrop-blur-sm empty:hidden xl:hidden`,children:!r||c?(0,Z.jsx)(BA,{items:fe.items,activeMessageIndex:et+it,labels:qt,openLabel:w.chat.timelineOpen,closeLabel:w.chat.timelineClose,currentLabel:w.chat.timelineCurrent,onSelectMessage:lt}):null}),(0,Z.jsx)(Tf,{prompt:me.clarifyPrompt,submitting:me.clarifySubmitting,submitError:me.clarifySubmitError,labels:w.chat,onSubmit:me.submitClarifyAnswer,onAgentDecide:me.letAgentDecideClarification,onCancel:me.cancelClarification}),yt?(0,Z.jsx)(AO,{plan:yt.plan,changeSummary:yt.changeSummary,isStreaming:q.streaming,labels:{heading:w.chat.planHeading,stepProgress:w.chat.planStepProgress,completedProgress:w.chat.planCompletedProgress,finished:w.chat.planFinished,ended:w.chat.planEnded,planned:w.chat.planPlanned,filesChangedOne:w.chat.planFilesChanged_one,filesChangedOther:w.chat.planFilesChanged_other}}):null,_e&&K.items.length>0?(0,Z.jsx)(`div`,{className:`mb-2 text-right`,children:(0,Z.jsx)(p,{to:`/capabilities/skills`,className:`text-xs text-accent-fg hover:underline`,children:w.skills.findBack})}):null,(0,Z.jsx)(Zw,{}),(0,Z.jsx)(tT,{conversationId:G.conversationId,active:q.streaming||q.sending}),(0,Z.jsx)(SD,{personal:o,nextTurnSuggestionsEnabled:!q.streaming,onPersonalSendDispatched:o?$e:void 0,placeholder:o?q.streaming||q.sending?x===`zh`?`继续聊,或补充要求…`:`Keep talking or add a detail…`:x===`zh`?`发消息给「${s?.name||`Personal AI`}」…`:`Message ${s?.name||`Personal AI`}…`:ye?w.agentsSettings.setupComposerPlaceholder:_e?w.skills.findPlaceholder:void 0,composerContext:!ye&&!r&&!le&&!he&&!_t&&K.items.length===0?{project:wt,disabled:Nt||Ht.busy||gt&&!G.projectPreparation,environmentPicker:G.projectPreparation?(0,Z.jsx)(ED,{selection:Ht}):void 0,workspacePath:G.effectiveWorkspacePath,canChangeWorkspace:ft,onProjectChange:tn,onWorkspaceChange:rn}:void 0,contextRefs:Tt,pageContextPreview:jt&&At?(0,Z.jsx)(CD,{draft:jt,disabled:q.sending,waiting:q.streaming,onRemove:()=>ss.remove(At,jt)}):void 0,setContextRefs:Et,onDraftAttachmentsChange:Ot,disabled:u||ht||Ht.busy||Nt,sendDisabled:pe.controlPending||pe.control.phase===`stopping`||u||!G.modelConfigReady||!G.projectPreparation&&gt||!!(G.projectPreparation&&!Ht.allowed)||G.modelConfigSaving||Ht.busy||Nt,sending:q.sending,streaming:q.streaming,conversationId:G.conversationId,unboundDraftKey:G.conversationId?void 0:JSON.stringify([N,P.get(`projectId`)]),getDraftHandoffTarget:Ht.getDraftHandoffTarget,prepareContextSession:G.projectPreparation?Ht.prepareSession:void 0,welcomeDraftSeed:ee??z,welcomeSuggestion:!_e&&vt?zt:null,onAcceptWelcomeSuggestion:dt,thinkingLevel:G.thinkingLevel,modelSupportsThinking:G.modelSupportsThinking,onThinkingChange:G.onSessionThinkingLevelChange,onSend:Ht.send,composerMode:pe.composerMode,onRestoreEditor:pe.restoreEditor,onComposerHydrated:pe.markComposerHydrated,onReacquireEdit:Wt,inputControl:pe.control,onResumeQueue:()=>void pe.resumeQueue().catch(()=>{}),editingUserTurnId:he?.turnId,onCancelUserMessageEdit:Gt,onAbort:()=>void q.abort().catch(()=>{}),onAddPendingFollowUp:async(t,n,r,i,a)=>{let o=Bt.current;if(e&&(!await e()||o!==Bt.current))throw Error(x===`zh`?`请先保存笔记,再发送消息。`:`Save the note before sending.`);await pe.addPendingFollowUp(t,n,r,jt?.envelope,i,a),At&&jt&&ss.remove(At,jt)},onSteeringInterrupt:jt?void 0:async(t,n,r)=>{let i=Bt.current;return e&&(!await e()||i!==Bt.current)?!1:q.interruptAndSend(t,n,void 0,r)},pendingFollowUps:pe.pendingFollowUps,editingFollowUpId:pe.editingFollowUpId,onBeginEditFollowUp:pe.beginEditFollowUp,onCancelEditFollowUp:pe.cancelEditFollowUp,onCommitEditFollowUp:(e,t,n,r,i)=>pe.commitEditFollowUp(e,t,n,r,i),onPendingFollowUpRemove:pe.removePendingFollowUp,onPendingFollowUpMove:pe.movePendingFollowUp,onPendingFollowUpReorder:pe.reorderPendingFollowUp,onPendingFollowUpSteer:e=>void pe.steerPendingFollowUp(e).catch(()=>{}),onPendingFollowUpSend:e=>void pe.sendQueuedInput(e).catch(()=>{}),steeringFollowUpId:pe.steeringFollowUpId,sessionModel:G.sessionModel,showModelSelector:!o,onModelChange:G.onSessionModelChange,modelDisabled:gt&&!G.projectPreparation||Ht.busy||G.modelConfigSaving,onChatAgentChange:!o&&!ye&&!le&&J.showChatAgentSelector?J.onChatAgentChange:void 0,currentAgentId:J.displayAgentId,voiceAgentName:o&&s?s.name:Lt.name,voiceTaskId:le??void 0,prepareVoiceSession:G.projectPreparation?Ht.prepareSession:void 0})]})})})]})]}),(!r||c)&&Ee&&window.electronAPI?.terminal?(0,Z.jsx)(Q.Suspense,{fallback:null,children:(0,Z.jsx)(ej,{conversationId:Ee},Ee)}):null,(0,Z.jsx)(A,{open:re!==null,onOpenChange:e=>{!e&&!ae&&Kt()},children:(0,Z.jsxs)(D,{children:[(0,Z.jsx)(C,{className:`xopc-dialog-overlay fixed inset-0 z-[80] bg-scrim backdrop-blur-[1px]`}),(0,Z.jsxs)(O,{className:`xopc-dialog-content fixed left-1/2 top-1/2 z-[90] flex h-[min(82vh,42rem)] w-[min(100%-2rem,44rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-edge-subtle px-5 py-4`,children:[(0,Z.jsx)(k,{className:`text-base font-semibold text-fg`,children:w.chat.sourceNoteSaveDialogTitle}),(0,Z.jsx)(T,{className:`mt-1 text-sm text-fg-muted`,children:w.chat.sourceNoteSaveDialogDescription.replace(`{{title}}`,Ft)})]}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-5 py-4`,children:[se?(0,Z.jsxs)(`p`,{className:`rounded-lg border border-danger/25 bg-danger-soft px-3 py-2 text-sm text-danger`,role:`alert`,children:[w.chat.sourceNoteSaveFailed,`: `,se]}):null,(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:w.chat.sourceNoteSaveDialogHeadingLabel}),(0,Z.jsx)(`input`,{value:re?.heading??``,onChange:e=>ie(t=>t&&{...t,heading:e.target.value}),className:`h-10 rounded-lg border border-edge bg-surface-base px-3 text-sm font-normal text-fg outline-none transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20`,disabled:ae})]}),(0,Z.jsxs)(`label`,{className:`flex min-h-0 flex-1 flex-col gap-1.5 text-sm font-medium text-fg`,children:[(0,Z.jsx)(`span`,{children:w.chat.sourceNoteSaveDialogContentLabel}),(0,Z.jsx)(`textarea`,{value:re?.content??``,onChange:e=>ie(t=>t&&{...t,content:e.target.value}),className:`min-h-[18rem] flex-1 resize-none rounded-lg border border-edge bg-surface-base px-3 py-2 font-mono text-xs leading-relaxed text-fg outline-none transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20`,disabled:ae})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-5 py-4`,children:[(0,Z.jsx)(vi,{type:`button`,variant:`secondary`,onClick:Kt,disabled:ae,children:w.chat.sourceNoteSaveDialogCancel}),(0,Z.jsx)(vi,{type:`button`,variant:`primary`,onClick:()=>void Zt(),disabled:ae||!re?.content.trim(),children:ae?w.chat.sourceNoteSaveDialogSaving:w.chat.sourceNoteSaveDialogConfirm})]})]})]})})]})}):(0,Z.jsx)(`div`,{className:`mx-auto w-full max-w-[var(--max-width-chat-frame)] px-3 py-16 text-center text-sm leading-relaxed text-fg-muted sm:px-5`,children:w.chat.needToken})}export{ac as $,Yf as A,Tf as B,fp as C,fs as Ct,Qf as D,Zf as E,If as F,mc as G,gc as H,zf as I,Qs as J,lc as K,Af as L,Vf as M,Hf as N,Xf as O,Bf as P,fc as Q,jf as R,lp as S,ps as St,$f as T,hc as U,yf as V,pc as W,uc as X,$s as Y,dc as Z,_m as _,vs as _t,Ww as a,As as at,lm as b,hs as bt,Dw as c,Ds as ct,kw as d,ws as dt,Xs as et,Tw as f,Cs as ft,gm as g,ys as gt,hm as h,bs as ht,Qw as i,js as it,qf as j,ep as k,jw as l,Es as lt,fw as m,xs as mt,$A as n,Ks as nt,Bw as o,ks as ot,yw as p,Ss as pt,Zs as q,Xw as r,Ms as rt,zw as s,Os as st,tj as t,Ws as tt,Aw as u,Ts as ut,pm as v,_s as vt,np as w,rm as x,ms as xt,um as y,gs as yt,Df as z};