@yuriai/web 0.2.27-beta.2 → 0.2.27-beta.3

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 (94) hide show
  1. package/dist/assets/{AgentAvatar-BW4Zg8bo.js → AgentAvatar-kIN4sZMz.js} +1 -1
  2. package/dist/assets/{AssistantView-Cl0ZeXwr.js → AssistantView-C2KQZ6a4.js} +3 -3
  3. package/dist/assets/{DiagramView-D6wdXRzu.js → DiagramView-DK0iXm9b.js} +1 -1
  4. package/dist/assets/{FadeInOnReveal-gOsILpSk.js → FadeInOnReveal-BJA9Za3T.js} +1 -1
  5. package/dist/assets/{GuiPluginSurface-DOZAQKX0.js → GuiPluginSurface-Dz2CdSUA.js} +1 -1
  6. package/dist/assets/{GuiPluginWindow-tGvc4_0g.js → GuiPluginWindow-l4FYY6S-.js} +1 -1
  7. package/dist/assets/{Icon-DvUDsV1z.js → Icon-BP1sfnHn.js} +1 -1
  8. package/dist/assets/{ImageLoadingPlaceholder-9xYbKqtf.js → ImageLoadingPlaceholder-DCWssLJG.js} +1 -1
  9. package/dist/assets/{LoadingImage-CiOcKPfb.js → LoadingImage-C_Hryaqe.js} +1 -1
  10. package/dist/assets/{MarkdownRenderer-DZkP4UNr.js → MarkdownRenderer-Y6uQXIFH.js} +2 -2
  11. package/dist/assets/{MarkdownRendererImpl-BXzPUEEo.js → MarkdownRendererImpl-qKp1tQrP.js} +1 -1
  12. package/dist/assets/{MarkstreamRendererImpl-B-NWd069.js → MarkstreamRendererImpl-B_JTod0h.js} +1 -1
  13. package/dist/assets/{MobileDetailNavigation-5U28hfYf.js → MobileDetailNavigation-B3rUx5Ve.js} +1 -1
  14. package/dist/assets/{MobileResizableSheet-ZL-zPa3W.js → MobileResizableSheet-F1zSUD1S.js} +1 -1
  15. package/dist/assets/{MobileShareBridge-JSH_Y8Ps.js → MobileShareBridge-F70fkIfS.js} +1 -1
  16. package/dist/assets/{MobileTabPageHeader-Bj9MIS38.js → MobileTabPageHeader-0esgB2TO.js} +1 -1
  17. package/dist/assets/{MultiRunWindow-ZPz62Aqg.js → MultiRunWindow-D8m6R_4x.js} +1 -1
  18. package/dist/assets/{OnboardingScreen-BQNoy9o1.js → OnboardingScreen-BAsPVV_W.js} +1 -1
  19. package/dist/assets/{OverlayScrollbar-BwCFalSw.js → OverlayScrollbar-wiRM4AGj.js} +1 -1
  20. package/dist/assets/{SettingsView-B17qt8dh.js → SettingsView-izzjIckv.js} +15 -15
  21. package/dist/assets/{SettingsWindow-CIFNHb-F.js → SettingsWindow-CSuHDq_c.js} +1 -1
  22. package/dist/assets/{TerminalView-BZZ8LW4d.js → TerminalView-BtM5-BVx.js} +1 -1
  23. package/dist/assets/{ToolOutputDialog-BKuVpgEu.js → ToolOutputDialog-DJs9w1_J.js} +1 -1
  24. package/dist/assets/{YuriLogo-C1Ty-RTB.js → YuriLogo-aBS6wlYU.js} +1 -1
  25. package/dist/assets/{appThemeRegistry-DqGuzMaH.js → appThemeRegistry-BY5rY9-W.js} +1 -1
  26. package/dist/assets/{button-DuHjvKJJ.js → button-Dt6Ygbc7.js} +1 -1
  27. package/dist/assets/{capgoAdapter-B-tddboe.js → capgoAdapter-MQ1qpf60.js} +1 -1
  28. package/dist/assets/{collapsible-B8eL5nLo.js → collapsible-Dm7OHk7m.js} +1 -1
  29. package/dist/assets/{diagram-ChoQDKzy.js → diagram-DWZaG3_v.js} +1 -1
  30. package/dist/assets/{dialog-CVhqZux0.js → dialog-CjQeHVOc.js} +1 -1
  31. package/dist/assets/{dropdown-menu.styles-DGvlOX_5.js → dropdown-menu.styles-PdxueXzN.js} +1 -1
  32. package/dist/assets/{es-B8sAsuo5.js → es-BjI1GHJ5.js} +1 -1
  33. package/dist/assets/{fileMentionTouchSelection-Dd-iSIe2.js → fileMentionTouchSelection-D7QtVxjI.js} +1 -1
  34. package/dist/assets/{fr-BPpW8T-l.js → fr-Bs7ndHkb.js} +1 -1
  35. package/dist/assets/{gitApi-D43bAQh1.js → gitApi-BxQmH8Wg.js} +1 -1
  36. package/dist/assets/{input-E_oYiXZT.js → input-Dq4usRDa.js} +1 -1
  37. package/dist/assets/{insertionBoundaries-BQjiZAmZ.js → insertionBoundaries-CKQL85zy.js} +1 -1
  38. package/dist/assets/{ja-DEoFDi7P.js → ja-DkdV26EW.js} +1 -1
  39. package/dist/assets/{ko-B45xHN6I.js → ko-B0qoC5da.js} +1 -1
  40. package/dist/assets/{main-C6MDfyZy.js → main-CNwFqQQd.js} +2 -2
  41. package/dist/assets/{main-u5iQScJs.js → main-DPhcXanT.js} +4 -4
  42. package/dist/assets/{markdownHeightCache-heNXHdzb.js → markdownHeightCache-C1u0bWDL.js} +1 -1
  43. package/dist/assets/{mcpQueries-BqKVe4Su.js → mcpQueries-D2IxTr4k.js} +1 -1
  44. package/dist/assets/{miniChat-Dhfn71Re.js → miniChat-CF2vb25D.js} +2 -2
  45. package/dist/assets/{mobile-DSVdPfcG.js → mobile-C24qSj44.js} +2 -2
  46. package/dist/assets/{mobileBackNavigation-DHxFQ7SY.js → mobileBackNavigation-vpCg1S7j.js} +1 -1
  47. package/dist/assets/{multirun-CPOzaEQj.js → multirun-DT-dFXud.js} +1 -1
  48. package/dist/assets/{native-config-oauL2ekt.js → native-config-ncdoz9Wl.js} +1 -1
  49. package/dist/assets/{pl-Bm3Je_AX.js → pl-D27Y_GBs.js} +1 -1
  50. package/dist/assets/{projectMeta-YDMdD3AP.js → projectMeta-CG8NLahh.js} +1 -1
  51. package/dist/assets/{pt-BR-BiQwFHhL.js → pt-BR-DbocEu4b.js} +1 -1
  52. package/dist/assets/{readiness-BveVUOIb.js → readiness-DSJs_3v4.js} +1 -1
  53. package/dist/assets/{renderElectronMiniChatApp-NC8iRPyy.js → renderElectronMiniChatApp-ChZCxxH6.js} +2 -2
  54. package/dist/assets/{renderMobileApp-D5ai1i6y.js → renderMobileApp-CRv3Il6P.js} +4 -4
  55. package/dist/assets/{runtimeConfig-BpcgdIV9.js → runtimeConfig-CZrflo-r.js} +1 -1
  56. package/dist/assets/{runtimeEndpointReset-ByKa_0nu.js → runtimeEndpointReset-Cx3RE97b.js} +3 -3
  57. package/dist/assets/{scheduledTaskNavigation-CZfAnPD-.js → scheduledTaskNavigation-rhgnZaaj.js} +1 -1
  58. package/dist/assets/{sessionChangeSummary-D6NlE_5k.js → sessionChangeSummary-CVUA1AFw.js} +1 -1
  59. package/dist/assets/{sessionLookup-C70EoX-V.js → sessionLookup-C3_vQwLe.js} +1 -1
  60. package/dist/assets/{sortable-tabs-strip-aKussO2c.js → sortable-tabs-strip-C1QmKFdb.js} +1 -1
  61. package/dist/assets/{speechSettingsQueries-B6qf-mCh.js → speechSettingsQueries-BSQ-2JTv.js} +1 -1
  62. package/dist/assets/{store-BeD2keas.js → store-DvN2L3vf.js} +2 -2
  63. package/dist/assets/{textarea-DmKaqHSb.js → textarea-vtIQM2iP.js} +1 -1
  64. package/dist/assets/{tooltip-DUKu4nC6.js → tooltip-BpG2mxrT.js} +1 -1
  65. package/dist/assets/{types-DRTMRW4R.js → types-CNTgeeM1.js} +1 -1
  66. package/dist/assets/{uk-CYZXWdd7.js → uk-B_JwElWz.js} +1 -1
  67. package/dist/assets/{useAppFontEffects-BiQf6tgZ.js → useAppFontEffects-BguV1Hfa.js} +5 -5
  68. package/dist/assets/{useDesktopWindowControlsLayout-DJxNmCWb.js → useDesktopWindowControlsLayout-CwgkVw9f.js} +1 -1
  69. package/dist/assets/{useEffectiveDirectory-B8q00InF.js → useEffectiveDirectory-Ci6Z13kj.js} +1 -1
  70. package/dist/assets/{useMobileNavigationStore-Bn4SaalY.js → useMobileNavigationStore-TCj7ZnhV.js} +6 -6
  71. package/dist/assets/{useWorkerHighlightedLines-B6lWNk01.js → useWorkerHighlightedLines-HKhuYGSj.js} +1 -1
  72. package/dist/assets/{zh-CN-CMLBHipA.js → zh-CN-DhFFdHQu.js} +1 -1
  73. package/dist/assets/{zh-TW-CJlmnnhK.js → zh-TW-BvehppXO.js} +1 -1
  74. package/dist/index.html +5 -5
  75. package/dist/mini-chat.html +5 -5
  76. package/dist/mobile.html +5 -5
  77. package/package.json +1 -1
  78. package/server/lib/assistants/DOCUMENTATION.md +10 -0
  79. package/server/lib/assistants/contact-store.js +16 -0
  80. package/server/lib/assistants/contact-store.test.js +19 -0
  81. package/server/lib/assistants/routes.js +25 -3
  82. package/server/lib/assistants/service.js +7 -1
  83. package/server/lib/assistants/weixin/DOCUMENTATION.md +142 -0
  84. package/server/lib/assistants/weixin/api.js +113 -0
  85. package/server/lib/assistants/weixin/api.test.js +80 -0
  86. package/server/lib/assistants/weixin/routes.js +23 -0
  87. package/server/lib/assistants/weixin/routes.test.js +41 -0
  88. package/server/lib/assistants/weixin/runtime.js +357 -0
  89. package/server/lib/assistants/weixin/runtime.test.js +286 -0
  90. package/server/lib/assistants/weixin/store.js +103 -0
  91. package/server/lib/assistants/weixin/typing.js +88 -0
  92. package/server/lib/assistants/weixin/typing.test.js +185 -0
  93. package/server/lib/opencode/shutdown-runtime.js +1 -1
  94. package/server/lib/opencode/shutdown-runtime.test.js +12 -0
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-BKuVpgEu.js","assets/rolldown-runtime-hePW80VL.js","assets/runtime-auth-DBn9yahL.js","assets/runtime-switch-DEZ1K7qW.js","assets/runtime-fetch-D4ja813o.js","assets/desktop-JwYqThiw.js","assets/runtimeAPIRegistry-C2VogTny.js","assets/vendor-base-ui-BQjbsJ43.js","assets/useUIStore-DI7va1HH.js","assets/vendor-zustand-B43HCgwC.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/vendor-react-D5d-V1vN.js","assets/vendor-tanstack-react-query-C4SG3JZB.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/runtime-file-resource-6np6lzoV.js","assets/queryRuntime-Dkpnq3Z1.js","assets/fileQueries-5a1jkme2.js","assets/runtime-file-store-BVRgEtI-.js","assets/path-utils-jGozTg9d.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/runtime-file-download-CcNIVp7u.js","assets/platform-DFJEtBlo.js","assets/vendor-pierre-diffs-Bj9Nqn6w.js","assets/vendor-hast-util-to-html-Bw_SgZ1t.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-BMOrLc9L.js","assets/vendor-reactuses-core-BcebBLwF.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-DuHjvKJJ.js","assets/store-BeD2keas.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/useThemeSystem-CGF5jnIh.js","assets/vendor-framer-motion-C1twy-GF.js","assets/Icon-DvUDsV1z.js","assets/dialog-CVhqZux0.js","assets/dialog-CTYD3Sbr.css","assets/tap-LkQum5bB.js","assets/image-loading-Dq1g_wpm.js","assets/image-loading-D9Z_BASK.css","assets/MobileWindowStack-DGLdgoGr.js","assets/appThemeRegistry-DqGuzMaH.js","assets/useMobileNavigationStore-Bn4SaalY.js","assets/gitApiHttp-DHrRqnYh.js","assets/vendor-opencode-client-UL_TecvQ.js","assets/vendor-effect-DV9F8PTZ.js","assets/persistence-JyLTFv27.js","assets/pathNormalization-ewtPqJWn.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-sonner-r2EJnfoo.js","assets/useAssistantUIStore-C9FPlYQz.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/vendor-fuzzysort-ukaRp9PC.js","assets/agentColors-DWSbQXy2.js","assets/rasterizePng-056Poix7.js","assets/MarkdownRenderer-DZkP4UNr.js","assets/useEffectiveDirectory-B8q00InF.js","assets/markdownHeightCache-heNXHdzb.js","assets/dualLimitLru-D8Sphgua.js","assets/toolHelpers-iEHVHQ9p.js","assets/ImageLoadingPlaceholder-9xYbKqtf.js","assets/useWorkerHighlightedLines-B6lWNk01.js","assets/markdownTheme-hpURsgju.js","assets/markdown-worker-oBGEB9Eg.js","assets/vendor-tanstack-react-virtual-BeZn51tF.js","assets/mobileBackNavigation-DHxFQ7SY.js","assets/touch-gestures-K2_ZOkKW.js","assets/ToolOutputDialog-CbGuK5bP.css","assets/vendor-capacitor-app-B5H_XtmE.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}from"./runtime-auth-DBn9yahL.js";import{c as i,f as a,i as o,l as s,n as c,o as l,r as u,t as d}from"./runtime-switch-DEZ1K7qW.js";import{n as f}from"./runtime-fetch-D4ja813o.js";import{N as p,S as m,T as h,b as g,h as _,t as v,v as y,w as b,x}from"./desktop-JwYqThiw.js";import{t as S}from"./runtimeAPIRegistry-C2VogTny.js";import{c as C,f as w,g as T,h as E,i as D,m as O,n as k,o as A,p as j,r as M,s as N,u as P,v as F}from"./desktopHosts-CB0CTcMg.js";import{r as I}from"./desktopRelayRestore-CoLLVJw8.js";import{a as L,i as R,o as z,r as B,s as V,t as H}from"./vendor-zustand-B43HCgwC.js";import{at as U,d as W,f as ee,it as te,m as ne,p as re,rt as G,u as ie}from"./vendor-base-ui-BQjbsJ43.js";import{$t as ae,Ar as oe,At as se,Cn as ce,Cr as le,Dt as ue,En as de,Et as fe,Fi as pe,Ii as me,Kt as he,Nn as ge,Nt as _e,On as ve,Or as ye,Ot as be,Pi as xe,Pn as Se,Pt as Ce,Qt as we,Rn as Te,Si as Ee,Sn as De,Ti as Oe,Tn as ke,Tr as Ae,Tt as je,Un as Me,Vn as Ne,Wt as Pe,Yt as Fe,Zt as Ie,_r as Le,an as Re,bi as ze,bn as Be,br as Ve,bt as He,dn as Ue,en as We,er as Ge,fn as Ke,gn as qe,hn as Je,hr as Ye,in as Xe,ki as Ze,kn as Qe,ln as $e,mi as et,nn as tt,qt as nt,rn as rt,un as it,vi as at,vn as ot,vr as st,wi as ct,wn as lt,wr as ut,yn as dt,yr as ft,zn as pt}from"./gitApiHttp-DHrRqnYh.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{_ as mt,b as ht,c as gt,f as _t,g as vt,h as yt,n as K,y as bt}from"./useUIStore-DI7va1HH.js";import{$ as xt,A as St,B as Ct,C as wt,Ct as Tt,F as Et,G as Dt,J as Ot,K as kt,L as At,M as jt,Ot as Mt,Pt as Nt,Q as Pt,R as Ft,S as It,T as Lt,Tt as Rt,V as zt,W as Bt,X as Vt,Y as Ht,_ as Ut,at as Wt,b as Gt,f as Kt,ft as qt,g as Jt,i as Yt,it as Xt,j as Zt,lt as Qt,m as $t,ot as en,pt as tn,q as nn,r as rn,rt as an,st as on,t as sn,tt as cn,v as ln,vt as un,wt as dn,x as fn,y as pn,yt as mn}from"./persistence-JyLTFv27.js";import{n as hn}from"./vendor-react-D5d-V1vN.js";import{i as gn}from"./vendor-tanstack-query-core-BWz0ose6.js";import{c as _n,i as vn,n as q,o as yn,t as bn}from"./vendor-tanstack-react-query-C4SG3JZB.js";import{a as xn,n as Sn,o as Cn}from"./queryRuntime-Dkpnq3Z1.js";import{d as wn,l as Tn,u as En}from"./fileQueries-5a1jkme2.js";import{a as Dn,i as On,n as kn,o as An,t as jn}from"./path-utils-jGozTg9d.js";import{o as Mn}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as Nn,t as Pn}from"./pathNormalization-ewtPqJWn.js";import{n as Fn,t as In}from"./platform-DFJEtBlo.js";import{i as Ln,u as Rn}from"./vendor-pierre-diffs-Bj9Nqn6w.js";import{r as zn,t as Bn}from"./vendor-sonner-r2EJnfoo.js";import{a as Vn,d as Hn,h as Un,i as Wn,m as Gn,o as Kn,p as qn,r as J,s as Jn}from"./vendor-reactuses-core-BcebBLwF.js";import{d as Yn,f as Xn,i as Zn,l as Qn,p as $n,r as Y,t as er,v as tr,y as nr}from"./button-DuHjvKJJ.js";import{i as rr,t as ir}from"./store-BeD2keas.js";import{$ as ar,$a as or,$i as sr,$r as cr,$t as lr,A as ur,Ai as dr,An as fr,At as pr,B as mr,Ba as hr,Bi as gr,Bn as _r,Cn as vr,Ct as yr,D as br,Di as xr,Dn as Sr,Do as Cr,Dr as wr,Dt as Tr,E as Er,Ei as Dr,Er as Or,Et as kr,F as Ar,Fi as jr,G as Mr,Ga as Nr,Gn as Pr,Gt as Fr,H as Ir,Ha as Lr,Hi as Rr,Hn as zr,Hr as Br,I as Vr,Ii as Hr,In as Ur,J as Wr,Jt as Gr,K as Kr,Ka as qr,Kn as Jr,Kr as Yr,Kt as Xr,L as Zr,Li as Qr,Ln as $r,Lt as ei,M as ti,Ma as ni,Mn as ri,Mo as ii,Mt as ai,N as oi,Nt as si,O as ci,Oa as li,Oi as ui,On as di,Oo as fi,Ot as pi,P as mi,Pa as hi,Pi as gi,Pn as _i,Pt as vi,Q as yi,Qi as bi,Qr as xi,Qt as Si,R as Ci,Ra as wi,Rn as Ti,Rt as Ei,Si as Di,Sn as Oi,St as ki,Ti as Ai,Tr as ji,Tt as Mi,U as Ni,Ua as Pi,Ui as Fi,Un as Ii,V as Li,Va as Ri,Vi as zi,Vn as Bi,Vr as Vi,Vt as Hi,W as Ui,Wa as Wi,Wi as Gi,Wn as Ki,X as qi,Xn as Ji,Xt as Yi,Y as Xi,Yn as Zi,Yt as Qi,Z as $i,Za as ea,Zn as ta,_ as na,_a as ra,_n as ia,_t as aa,a as oa,aa as sa,ai as ca,at as la,ba as ua,bi as da,bn as fa,bo as pa,bt as ma,c as ha,ca as ga,ci as _a,cn as va,da as ya,dn as ba,dr as xa,ea as Sa,ei as Ca,en as wa,eo as Ta,et as Ea,f as Da,fa as Oa,fi as ka,fn as Aa,ft as ja,ga as Ma,gi as Na,gn as Pa,h as Fa,ha as Ia,hi as La,hn as Ra,ho as za,i as Ba,ia as Va,ii as Ha,it as Ua,j as Wa,ja as Ga,jn as Ka,jo as qa,jt as Ja,k as Ya,ka as Xa,kn as Za,kt as Qa,l as $a,la as eo,ln as to,lr as no,ma as ro,mi as io,mn as ao,mt as oo,n as so,na as co,nn as lo,nr as uo,nt as fo,oa as po,oi as mo,on as ho,or as go,ot as _o,pa as vo,pi as yo,pr as bo,pt as xo,q as So,qa as Co,qn as wo,qt as To,r as Eo,ra as Do,ro as Oo,rt as ko,sa as Ao,sn as jo,sr as Mo,st as No,ta as Po,ti as Fo,tn as Io,tr as Lo,tt as Ro,ua as zo,ui as Bo,un as Vo,ur as Ho,va as Uo,vi as Wo,vn as Go,w as Ko,wa as qo,wi as Jo,wn as Yo,wr as Xo,wt as Zo,xn as Qo,xt as $o,y as es,ya as ts,yi as ns,yn as rs,yo as is,yt as as,z as os,za as ss,zi as cs,zn as ls,zt as us}from"./useMobileNavigationStore-Bn4SaalY.js";import{t as ds}from"./agentColors-DWSbQXy2.js";import{t as fs}from"./dualLimitLru-D8Sphgua.js";import{a as ps,i as ms,r as hs,t as gs}from"./AgentAvatar-BW4Zg8bo.js";import{n as _s,r as vs,t as ys}from"./useThemeSystem-CGF5jnIh.js";import{o as bs}from"./vendor-framer-motion-C1twy-GF.js";import{n as X}from"./Icon-DvUDsV1z.js";import{a as xs,i as Ss,n as Cs,o as ws,r as Ts,s as Es,t as Ds}from"./dialog-CVhqZux0.js";import{E as Os,n as ks}from"./gitApi-D43bAQh1.js";import{a as As}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{A as js,C as Ms,D as Ns,O as Ps,S as Fs,_ as Is,a as Ls,b as Rs,f as zs,h as Bs,i as Vs,k as Hs,l as Us,m as Ws,n as Gs,o as Ks,s as qs,u as Js,w as Ys,x as Xs,y as Zs}from"./projectMeta-YDMdD3AP.js";import{t as Qs}from"./input-E_oYiXZT.js";import{i as $s,n as ec,t as tc}from"./tooltip-DUKu4nC6.js";import{$ as nc,At as rc,B as ic,Bt as ac,Ct as oc,Ft as sc,Gt as cc,H as lc,Ht as uc,J as dc,Jt as fc,K as pc,Kt as mc,L as hc,Ot as gc,Pt as _c,Q as vc,Qt as yc,R as bc,Rt as xc,St as Sc,Vt as Cc,X as wc,Y as Tc,Z as Ec,_t as Dc,an as Oc,at as kc,d as Ac,et as jc,ft as Mc,gt as Nc,i as Pc,in as Fc,it as Ic,jt as Lc,kt as Rc,lt as zc,mt as Bc,n as Vc,nt as Hc,o as Uc,on as Wc,pt as Gc,q as Kc,rt as qc,tt as Jc,ut as Yc,z as Xc,zt as Zc}from"./speechSettingsQueries-B6qf-mCh.js";import{t as Qc}from"./YuriLogo-C1Ty-RTB.js";import{r as $c}from"./device-BjRYYXNT.js";import{c as el,d as tl,f as nl,l as rl,n as il,o as al,p as ol,r as sl,u as cl}from"./image-loading-Dq1g_wpm.js";import{S as ll,a as ul,c as dl,g as fl,l as pl,o as ml,x as hl,y as gl}from"./dropdown-menu.styles-DGvlOX_5.js";import{S as _l,b as vl,t as yl,x as bl}from"./MobileResizableSheet-ZL-zPa3W.js";import{A as xl,C as Sl,D as Cl,E as wl,O as Tl,T as El,_ as Dl,a as Ol,b as kl,c as Al,d as jl,f as Ml,g as Nl,h as Pl,i as Fl,k as Il,l as Ll,m as Rl,o as zl,p as Bl,s as Vl,u as Hl,v as Ul,w as Wl,x as Gl,y as Kl}from"./sessionChangeSummary-D6NlE_5k.js";import{a as ql,i as Jl,o as Yl,s as Xl,u as Zl}from"./fileMentionTouchSelection-Dd-iSIe2.js";import{C as Ql,E as $l,O as eu,S as tu,T as nu,a as ru,b as iu,c as au,d as ou,f as su,i as cu,l as lu,n as uu,o as du,p as fu,r as pu,s as mu,t as hu,u as gu,w as _u,x as vu,y as yu}from"./insertionBoundaries-BQjiZAmZ.js";import{C as bu,D as xu,E as Su,O as Cu,S as wu,T as Tu,_ as Eu,a as Du,b as Ou,c as ku,d as Au,f as ju,g as Mu,h as Nu,j as Pu,l as Fu,m as Iu,o as Lu,p as Ru,r as zu,s as Bu,t as Vu,u as Hu,v as Uu,w as Wu,x as Gu,y as Ku}from"./appThemeRegistry-DqGuzMaH.js";import{a as qu,n as Ju,o as Yu,r as Xu,t as Zu}from"./MarkdownRenderer-DZkP4UNr.js";import{t as Qu}from"./OverlayScrollbar-BwCFalSw.js";import{n as $u,r as ed}from"./textarea-DmKaqHSb.js";import{_ as td,a as nd,c as rd,g as id,l as ad,o as od,t as sd,v as cd,y as ld}from"./vendor-dnd-kit-core-B3g3zWQd.js";import{i as ud,n as dd,o as fd,s as pd,t as md}from"./vendor-dnd-kit-sortable-BKewx0Py.js";import{a as hd,n as gd,t as _d}from"./url-MRa-FtQa.js";import{a as vd,o as yd,t as bd,u as xd}from"./toolHelpers-iEHVHQ9p.js";import{t as Sd}from"./react-CURmDhtB.js";import{n as Cd,t as wd}from"./useEffectiveDirectory-B8q00InF.js";import{t as Td}from"./ImageLoadingPlaceholder-9xYbKqtf.js";import{t as Ed}from"./LoadingImage-CiOcKPfb.js";import{a as Dd,i as Od,l as kd,n as Ad,o as jd,r as Md,s as Nd,t as Pd}from"./FadeInOnReveal-gOsILpSk.js";import{_ as Fd,a as Id,f as Ld,g as Rd,h as zd,i as Bd,m as Vd,o as Hd,r as Ud,s as Wd,t as Gd,v as Kd,y as qd}from"./useWorkerHighlightedLines-B6lWNk01.js";import{n as Jd,r as Yd,t as Xd}from"./vendor-tanstack-react-virtual-BeZn51tF.js";import{t as Zd}from"./vendor-cmdk-C3oBVL9X.js";import{t as Qd}from"./sortable-tabs-strip-aKussO2c.js";import{a as $d}from"./markdownHeightCache-heNXHdzb.js";import{n as ef}from"./markdownTheme-hpURsgju.js";import{t as tf}from"./vendor-motion-BmLx2V78.js";import{n as nf,t as rf}from"./useFontPreferences-DMiP_Yy-.js";var af=e=>{if(typeof e!=`string`)return;let t=e.trim();if(t)return{location:{directory:t}}};typeof window<`u`&&(window.__opencodeDebug={getLastAssistantMessage(){let e=Da.getState().currentSessionId;if(!e)return null;let t=Te(e);if(!t||t.length===0)return null;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`assistant`){let e=(pt(n.id)||[]).map(e=>{let t={id:e.id,type:e.type};return e.type===`text`?(t.text=e.text,t.textLength=e.text?.length||0):e.type===`tool`?(t.tool=e.tool,t.state=e.state?.status):(e.type===`step-start`||e.type===`step-finish`)&&(t.isStepMarker=!0),t}),t=e.some(e=>e.type===`text`&&e.text&&e.text.trim().length>0),r=e.some(e=>e.type===`tool`),i=e.some(e=>e.type===`step-start`||e.type===`step-finish`),a=e.length===0,o=!t&&!r&&(!a||i),s={messageId:n.id,role:n.role,timestamp:n.time?.created||0,partsCount:e.length,parts:e,isEmpty:a,isEmptyResponse:o,raw:n};return s.messageId,s.partsCount,s.isEmpty,s.isEmptyResponse,s.isEmpty&&console.warn(`[WARNING] Message has NO parts!`),s.isEmptyResponse&&(console.warn(`[WARNING] Message has parts but NO meaningful content (empty text, no tools)!`),i&&!t&&!r&&console.warn(`[CRITICAL] CLAUDE EMPTY RESPONSE BUG: Only step-start/step-finish markers, no actual content!`)),s}}return null},truncateString(e,t=80){return!e||typeof e!=`string`||e.length<=t?e:e.substring(0,t)+`…`},truncateMessages(e){return e.map(e=>({...e,parts:(pt(e.id)||[]).map(e=>{let t={...e};return`text`in e&&(t.text=this.truncateString(e.text)),`textPreview`in e&&(t.textPreview=this.truncateString(e.textPreview)),e.state&&(t.state={...e.state},`output`in e.state&&(t.state.output=this.truncateString(e.state.output)),`error`in e.state&&(t.state.error=this.truncateString(e.state.error)),e.state.metadata&&`preview`in e.state.metadata&&(t.state.metadata={...e.state.metadata,preview:this.truncateString(e.state.metadata.preview)})),t})}))},getAllMessages(e=!1){let t=Da.getState().currentSessionId;if(!t)return[];let n=Te(t);return`${n.length}`,n.forEach((e,t)=>{let n=pt(e.id)||[];`${t}${e.role}${e.id}${n.length}`}),e?this.truncateMessages(n):n},async getAppStatus(){let e=He.getState(),t=Da.getState(),n=pa.getState(),r=e.currentDirectory||null,i=se.getDirectory()??null,a=Ne(),o=new Set,s={};a.forEach(e=>{let t=e.directory;typeof t==`string`&&t.trim().length>0?(o.add(t),s[t]=(s[t]??0)+1):s[`(none)`]=(s[`(none)`]??0)+1});let c=(()=>{if(typeof window>`u`)return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem(`lastDirectory`),homeDirectory:window.localStorage.getItem(`homeDirectory`)}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}})(),l=S(),u=typeof window<`u`&&!!window.__YURI_ELECTRON__,d=async e=>{try{return await e.json()}catch{return null}},p=async e=>{try{return await e.text()}catch{return null}},m=async e=>{try{let t=await f(e);return t.ok?await d(t):{status:t.status}}catch(e){return{error:e instanceof Error?e.message:String(e)}}},h=null,g=null,_=null,v=null;try{let e=await se.getSdkClient().location.get(af(r));h=Ce(e)}catch(e){h={error:e instanceof Error?e.message:String(e)}}try{g=(await se.getSdkClient().location.get(af(r)))?.project??null}catch(e){g={error:e instanceof Error?e.message:String(e)}}_=await m(`/api/config/settings`);try{let e=await f(`/api/health`),t=e.headers.get(`content-type`)||``,n=await p(e),r=t.toLowerCase().includes(`application/json`),i=null;if(r&&n)try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)&&(i=e)}catch{i=null}v={status:e.status,ok:e.ok,contentType:t,type:r?`json`:`html`,openCodePort:i?.openCodePort??null,openCodeRunning:i?.openCodeRunning??null,openCodeSecureConnection:i?.openCodeSecureConnection??null,openCodeAuthSource:i?.openCodeAuthSource??null,isOpenCodeReady:i?.isOpenCodeReady??null,lastOpenCodeError:i?.lastOpenCodeError??null,preview:n?n.slice(0,120):null}}catch(e){v={error:e instanceof Error?e.message:String(e)}}let y={isGitRepo:null};if(r)try{y.isGitRepo=await ks(r)}catch(e){y={isGitRepo:null,error:e instanceof Error?e.message:String(e)}}let b=n.projects.map(e=>({id:e.id,path:e.path,label:e.label}));return{runtime:{platform:l?.runtime?.platform??null,isDesktop:u,isVSCode:!!l?.runtime?.isVSCode,hasRuntimeApis:!!l,desktopServerOrigin:null},location:typeof window<`u`?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:r,opencodeDirectory:h?.directory||h?.worktree||i,homeDirectory:e.homeDirectory||null,isHomeReady:e.isHomeReady,hasPersistedDirectory:e.hasPersistedDirectory,isSwitchingDirectory:e.isSwitchingDirectory},projects:{total:n.projects.length,activeProjectId:n.activeProjectId,samples:b},sessions:{total:a.length,currentSessionId:t.currentSessionId,lastLoadedDirectory:t.lastLoadedDirectory,uniqueDirectories:o.size,directorySamples:Array.from(o).slice(0,5),directoryCounts:s},worktrees:{available:t.availableWorktrees.length,metadataEntries:t.worktreeMetadata.size},git:y,localStorage:c,opencode:{pathInfo:h,projectInfo:g,health:v},yuri:{settingsInfo:_}}},async buildDiagnosticsReport(){let e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return Yn(e)},async copyDiagnosticsReport(){let e=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(e),report:e}},checkLastMessage(){let e=this.getLastAssistantMessage();if(!e)return!1;let t=e.isEmpty||e.isEmptyResponse;return t&&(console.error(`[ALERT] PROBLEMATIC MESSAGE DETECTED!`),e.messageId,e.isEmpty,e.isEmptyResponse,e.partsCount,e.parts.length>0&&e.parts),t},getStreamingState(){let e=Da.getState(),t=_i.getState(),n=e.currentSessionId?t.streamingMessageIds.get(e.currentSessionId)??null:null;return Array.from(t.streamingMessageIds.entries()),Array.from(t.messageStreamStates.entries()),{streamingMessageId:n,streamingMessageIds:t.streamingMessageIds,streamStates:t.messageStreamStates}},findEmptyMessages(){let e=Da.getState().currentSessionId;if(!e)return[];let t=Te(e).filter(e=>e.role===`assistant`).filter(e=>{let t=pt(e.id)||[],n=t.some(e=>e.type===`text`&&e.text&&e.text.trim().length>0),r=t.some(e=>e.type===`tool`);return t.length===0||!n&&!r});return`${t.length}`,t.forEach((e,t)=>{let n=pt(e.id)||[];`${t}`,e.id,n.length,e.providerID,e.modelID,e.time?.created}),t},showRetryHelp(){},analyzeMessageCompletionConsistency(e={}){let{includeNonAssistant:t=!1,verbose:n=!0,maxTableRows:r=25}=e,i=Da.getState().currentSessionId;if(!i)return{summary:null,rows:[]};let a=Te(i),o=t?a:a.filter(e=>e.role===`assistant`),s={totalMessages:a.length,analyzedMessages:o.length,completedMissing:0,completedBeforeTool:0,completedBeforeReasoning:0,runningToolsWhenCompleted:0,reasoningOpenWhenCompleted:0,withTools:0,withReasoning:0},c=e=>typeof e==`number`&&Number.isFinite(e)?e:null,l=e=>{let t=e.filter(e=>typeof e==`number`);return t.length>0?Math.max(...t):null},u=o.map((e,t)=>{let n=e,r=pt(e.id)||[],i=n.time??{},a=c(i.completed),o=a!==null,u=r.filter(e=>e.type===`tool`),d=r.filter(e=>e.type===`reasoning`),f=l(u.map(e=>c(e.state?.time?.end??e.state?.time?.start))),p=l(d.map(e=>c(e.time?.end??e.time?.start))),m=l([f,p].filter(e=>e!==null)),h=u.some(e=>[`pending`,`running`,`started`].includes(e.state?.status)),g=d.some(e=>typeof e.time?.end!=`number`);u.length>0&&(s.withTools+=1),d.length>0&&(s.withReasoning+=1),o||(s.completedMissing+=1);let _=!!(o&&typeof f==`number`&&a<f);_&&(s.completedBeforeTool+=1);let v=!!(o&&typeof p==`number`&&a<p);return v&&(s.completedBeforeReasoning+=1),o&&h&&(s.runningToolsWhenCompleted+=1),o&&g&&(s.reasoningOpenWhenCompleted+=1),{index:t,messageId:n.id,role:n.role,completedAt:a,latestToolTimestamp:f,latestReasoningTimestamp:p,latestPartTimestamp:m,completed_missing:!o,completed_before_tool:_,completed_before_reasoning:v,running_tools_when_completed:!!(o&&h),reasoning_open_when_completed:!!(o&&g),has_tools:u.length>0,has_reasoning:d.length>0}});return n&&(console.table(u.slice(0,r)),u.length>r&&`${r}${u.length}`),{summary:s,rows:u}},checkCompletionStatus(){let e=Da.getState().currentSessionId;if(!e)return null;let t=Te(e).filter(e=>e.role===`assistant`);if(t.length===0)return null;let n=t[t.length-1],r=(pt(n.id)||[]).filter(e=>e.type===`step-finish`),i=n.finish===`stop`,a=n.time?.completed,o=n.status,s=typeof a==`number`&&a>0||o===`completed`,c=!!(s&&i),l=_i.getState();n.sessionID&&l.streamingMessageIds.get(n.sessionID);let u=l.messageStreamStates.get(n.id);return n.id,n.id,u?.phase,{messageId:n.id,completed:a,status:o,hasCompletedFlag:s,hasStopReason:i,messageIsComplete:c,stepFinishParts:r,raw:n}}},je(),window.addEventListener(`error`,e=>{try{let t=e.message||``,n=e.filename||``;typeof t==`string`&&t.includes(`this._renderer.value.dimensions`)&&/xterm/i.test(String(n))&&e.preventDefault()}catch{}}));var Z=e(U(),1),Q=hn(),of=async()=>{if(typeof window>`u`)return;let e=null;try{e=Nt(`lastDirectory`)}catch(e){console.warn(`Failed to read saved directory preferences:`,e)}e&&!b()&&He.getState().setDirectory(e,{showOverlay:!1})},sf=new Map,cf=e=>sf.get(e)??null,lf=({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:i},a={})=>{let o=sf.get(e);if(o&&!a.force)return o;let s=(async()=>{o&&await o;try{await t()}catch(e){return i(`appearance`,e),!1}try{await Promise.all([n(),r()])}catch(e){i(`secondary`,e)}return!0})();return sf.set(e,s),s},uf=async({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,startWatchers:i,onError:a})=>{await lf({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:a})&&i()},df=(e,t=50)=>{let n=null,r;return{schedule:i=>{r=i,n&&clearTimeout(n),n=setTimeout(()=>{n=null;let t=r;r=void 0,t!==void 0&&e(t)},t)},cancel:()=>{n&&clearTimeout(n),n=null,r=void 0}}};function ff(e){return!e||e===`idle`?null:e===`ready`?`ok`:e===`error`?`unreachable`:`auth`}function pf(e,t){let n=e.via===`relay`;return t?n:!n}function mf(e){let{isActive:t,isSsh:n,runtimeIsConnected:r,runtimeConnectionPhase:i,currentTransportIsRelay:a,probe:o,sshPhase:s}=e,c;c=t?r&&i===`connected`?`ok`:`checking`:n?ff(s):o?.status??`checking`;let l=t?a:o?.via===`relay`,u=null;return!n&&c===`ok`&&o?.status===`ok`&&typeof o.latencyMs==`number`&&(!t||pf(o,a))&&(u=Math.max(0,Math.round(o.latencyMs))),{statusKind:c,showViaRelay:l,latencyMs:u}}var $=te(),hf=`local`,gf=9e4,_f=`SSH connection cancelled`,vf=e=>I(e),yf={},bf=e=>{let t=O(e);if(!t)return e.trim();try{let e=new URL(t);return e.pathname.endsWith(`/`)||(e.pathname=`${e.pathname}/`),e.toString()}catch{return t}},xf=()=>typeof window>`u`?``:window.__YURI_LOCAL_ORIGIN__||window.location.origin,Sf=async()=>m()?A().catch(()=>``):``,Cf=e=>e===`ok`?`bg-status-success`:e===`auth`||e===`update-recommended`?`bg-status-warning`:e===`incompatible`||e===`wrong-service`||e===`unreachable`?`bg-status-error`:e===`checking`?`bg-status-info`:`bg-muted-foreground/40`,wf=e=>e===`ok`?`text-[var(--status-success)]`:e===`auth`||e===`update-recommended`?`text-[var(--status-warning)]`:e===`incompatible`||e===`wrong-service`||e===`unreachable`?`text-[var(--status-error)]`:`text-muted-foreground`,Tf=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Ef=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Df=e=>e===`ok`?`desktopHostSwitcher.status.connected`:e===`auth`?`desktopHostSwitcher.status.authRequired`:e===`checking`?`desktopHostSwitcher.status.checking`:e===`update-recommended`?`desktopHostSwitcher.status.updateRecommended`:e===`incompatible`?`desktopHostSwitcher.status.incompatible`:e===`wrong-service`?`desktopHostSwitcher.status.wrongService`:e===`unreachable`?`desktopHostSwitcher.status.unreachable`:`desktopHostSwitcher.status.unknown`,Of=e=>new Promise(t=>window.setTimeout(t,e)),kf=e=>{switch(e){case`ready`:return`desktopHostSwitcher.sshPhase.ready`;case`error`:return`desktopHostSwitcher.sshPhase.error`;case`degraded`:return`desktopHostSwitcher.sshPhase.reconnecting`;case`config_resolved`:return`desktopHostSwitcher.sshPhase.resolvingConfig`;case`auth_check`:return`desktopHostSwitcher.sshPhase.checkingAuth`;case`master_connecting`:return`desktopHostSwitcher.sshPhase.connectingSsh`;case`remote_probe`:return`desktopHostSwitcher.sshPhase.probingRemote`;case`installing`:return`desktopHostSwitcher.sshPhase.installing`;case`updating`:return`desktopHostSwitcher.sshPhase.updating`;case`server_detecting`:return`desktopHostSwitcher.sshPhase.detectingServer`;case`server_starting`:return`desktopHostSwitcher.sshPhase.startingServer`;case`forwarding`:return`desktopHostSwitcher.sshPhase.forwardingPorts`;default:return`desktopHostSwitcher.sshPhase.idle`}},Af=async()=>{let e=await yc().catch(()=>[]),t={};for(let n of e)t[n.id]=n;return t},jf=async(e,t,n,r)=>{let i=Date.now()+t;for(;Date.now()<i;){if(r?.())throw Error(_f);let t=(await yc(e).catch(()=>[])).find(t=>t.id===e);if(t){if(n(t),t.phase===`ready`)return t;if(t.phase===`error`)throw Error(t.detail||`SSH connection failed`)}await Of(700)}throw r?.()?Error(_f):Error(`Timed out waiting for SSH connection`)},Mf=e=>({id:hf,label:`Local`,url:e||xf()}),Nf=e=>{let t=typeof window>`u`?``:window.location.href,n=e.find(e=>e.id===hf)?.url||xf(),r=d(),i=O(n)||n,a=O(t)||t,o=u(),s=e.find(e=>e.relay&&vf(e)===o);if(s)return{id:s.id,label:s.label,url:s.url};if(r&&j(r,n))return{id:hf,label:`Local`,url:i};let c=e.find(e=>r?j(r,P(e)):!1);if(c)return{id:c.id,label:c.label,url:O(P(c))||P(c)};if(t&&j(t,n))return{id:hf,label:`Local`,url:i};let l=e.find(e=>t?j(t,e.url):!1);return l?{id:l.id,label:l.label,url:O(l.url)||l.url}:t.startsWith(`yuri-ui://`)?{id:hf,label:`Local`,url:i}:{id:`custom`,label:T(a||`Instance`),url:a}};function Pf({open:e,onOpenChange:t,embedded:n=!1,onHostSwitched:r,onBusyChange:a}){let{t:s}=Xn(),c=K(e=>e.setSettingsDialogOpen),l=K(e=>e.setSettingsPage),u=ni(e=>e.isConnected),d=ni(e=>e.connectionPhase),[f,p]=Z.useState([]),[h,g]=Z.useState(null),[_,v]=Z.useState(()=>({...yf}));Z.useEffect(()=>{Object.assign(yf,_)},[_]);let[y,b]=Z.useState(!1),[S,A]=Z.useState(!1),[j,I]=Z.useState(!1),L=Oc(),R=Wc(),[z,B]=Z.useState(null),V=z||R,H=Z.useRef(!1),U=J(e=>{H.current=e!==null,B(e),a?.(e!==null)}),[W,ee]=Z.useState({}),[te,ne]=Z.useState({}),[re,G]=Z.useState({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),[ie,ae]=Z.useState(``),[oe,se]=Z.useState(()=>xf()),[ce,le]=Z.useState(null),[ue,de]=Z.useState(``),[fe,pe]=Z.useState(``),[me,he]=Z.useState(0),ge=Z.useRef(0),_e=Z.useMemo(()=>[Mf(oe),...f.map(e=>({...e,url:O(e.url)||e.url}))],[f,oe]),ve=Z.useMemo(()=>new Set(Object.keys(W)),[W]),ye=Z.useMemo(()=>_e.filter(e=>e.id===hf||w(e,ve)),[_e,ve]);Z.useEffect(()=>i(()=>he(e=>e+1)),[]);let be=Z.useMemo(()=>Nf(_e),[_e,me]),xe=Z.useMemo(()=>o().startsWith(`relay:`),[me]),Se=Z.useMemo(()=>{let e=h||hf;return _e.find(t=>t.id===e)?.label||s(`desktopHostSwitcher.instance.local`)},[_e,h,s]),Ce=Z.useCallback(async(e,t)=>{if(x()){I(!0),ae(``);try{let n=e.filter(e=>e.id!==hf);await D({hosts:n,defaultHostId:t}),p(n),g(t)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToSave`))}finally{I(!1)}}},[s]),we=Z.useCallback(()=>{l(`remote-instances`),c(!0),t(!1)},[t,c,l]),Te=Z.useCallback(async()=>{if(x()){b(!0),ae(``);try{let[e,t,n]=await Promise.all([M(),fc().catch(()=>({instances:[]})),Af()]);e.localOrigin&&se(e.localOrigin);let r={};for(let e of t.instances)r[e.id]=!0;p(e.hosts||[]),g(e.defaultHostId??null),ee(r),ne(n)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToLoad`)),p([]),g(null),ee({}),ne({})}finally{b(!1)}}},[s]),Ee=Z.useCallback(async e=>{if(x()){A(!0);try{let t=await Sf(),n=await Promise.all(e.map(async e=>{let n=async()=>{let t=await E(e.relay,{clientToken:e.clientToken||null}).catch(()=>({status:`unreachable`,latencyMs:0}));return{status:t.status,latencyMs:t.latencyMs,...t.status===`ok`?{via:`relay`}:{}}};if(e.relay&&!e.apiUrl)return[e.id,await n()];let r=O(m()?P(e):e.url);if(!r)return[e.id,{status:`unreachable`,latencyMs:0}];let i=e.id===hf?t:e.clientToken||``,a=await k(r,{clientToken:i||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(Tf(a.status)&&e.relay){let t=await n();if(t.status===`ok`)return[e.id,t]}return[e.id,{status:a.status,latencyMs:a.latencyMs}]})),r={};for(let[e,t]of n)r[e]=t;v(r)}finally{A(!1)}}},[]);Z.useEffect(()=>{if(!e){le(null),de(``),pe(``),B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),ae(``);return}Te()},[e,Te]),Z.useEffect(()=>{e&&Ee(ye)},[e,ye,Ee]),Z.useEffect(()=>{if(!e||!x())return;let t=!1,n=async()=>{let e=await Af();t||ne(e)};n();let r=window.setInterval(()=>{typeof document<`u`&&document.visibilityState!==`visible`||n()},1500);return()=>{t=!0,window.clearInterval(r)}},[e]);let De=J(async e=>{if(H.current||L)return;let t=e.id===hf?oe:O(e.url)||``,n=e.id===hf?oe:O(P(e))||``,i=!!e.relay&&!e.apiUrl&&e.id!==hf;if(!t&&!i)return;if(m()){if(!n&&!e.relay||L)return;U(e.id);try{let t=e.id===hf?await Sf():null,i=await Fc({host:e,inlineProgress:!0,cachedProbe:_[e.id]||null,...e.id===hf?{localApiOrigin:n,localClientToken:t}:{}});v(t=>({...t,[e.id]:i.status})),i.ok&&r?.()}finally{U(null)}return}let a=!!W[e.id];if(e.id!==hf&&a&&x()){let n=te[e.id],i=await yc(e.id).then(t=>t.find(t=>t.id===e.id)||null).catch(()=>null);i&&(n=i,ne(t=>({...t,[e.id]:i})));let a=O(n?.localUrl||e.url||``);if(n?.phase===`ready`&&a){let e=bf(a);r?.(),window.location.assign(e);return}B(e.id);let o=ge.current+1;ge.current=o,G({open:!0,hostId:e.id,hostLabel:T(e.label),phase:`master_connecting`,detail:null,error:null,errorCode:null});try{if(await cc(e.id),o!==ge.current)return;let n=await jf(e.id,gf,e=>{ne(t=>({...t,[e.id]:e})),G(t=>({...t,phase:e.phase,detail:e.detail||null,errorCode:e.errorCode||null}))},()=>o!==ge.current);if(o!==ge.current)return;let i=bf(O(n.localUrl||``)||t);r?.(),window.location.assign(i);return}catch(t){if(o!==ge.current)return;let n=t instanceof Error?t.message:String(t);if(n===_f)return;let r=ac(re.errorCode,n);G(e=>({...e,error:n,errorCode:r})),Yr.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Zc(s(Cc(r)),r,n)});return}finally{o===ge.current&&B(null)}}if(e.id!==hf&&x()){B(e.id);let n=await k(t,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(v(t=>({...t,[e.id]:{status:n.status,latencyMs:n.latencyMs}})),Tf(n.status)){Yr.error(s(`desktopHostSwitcher.toast.instanceUnreachable`,{host:T(e.label)})),B(null);return}}let o=bf(t);r?.();try{window.location.assign(o)}catch{window.location.href=o}}),Oe=Z.useCallback(()=>{le(null),de(``),pe(``)},[]),ke=Z.useCallback(e=>{e.stopPropagation()},[]),Ae=Z.useCallback(async()=>{if(!ce)return;if(ce===hf){Oe();return}let e=F(fe);if(!e){ae(s(`desktopHostSwitcher.error.invalidUrl`));return}let t=e.persistedUrl,n=(ue||T(t)).trim(),r=f.map(e=>e.id===ce?{...e,label:n,url:t,apiUrl:t}:e);await Ce(r,h),Oe(),e.redeemUrl&&window.location.assign(e.redeemUrl)},[Oe,f,h,ue,fe,ce,Ce,s]),je=Z.useCallback(async e=>{await Ce(f,e===hf?hf:e)},[f,Ce]),Me=J(async e=>{if(H.current||L)return;U(e.id);let t=e=>{Yr.error(s(`desktopHostSwitcher.error.failedToOpenNewWindow`),{description:e instanceof Error?e.message:String(e)})};try{if(e.relay&&e.id!==hf)await C(e.id);else{let t=e.id===hf?oe:P(e);if(!t)return;let n=bf(t);await N(n,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null})}r?.()}catch(e){t(e)}finally{U(null)}}),Ne=J(async()=>{ge.current+=1,B(null),G(e=>({...e,open:!1,hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}));let e=bf(oe);if(m()){if(L)return;let e=await Sf();(await Fc({host:Mf(oe),localApiOrigin:oe,localClientToken:e})).ok&&r?.();return}r?.(),window.location.assign(e)}),Pe=Z.useCallback(async()=>{let e=re.hostId||V;ge.current+=1,B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),!(!e||e===hf||!x())&&await mc(e).catch(()=>{})},[re.hostId,V]),Fe=Z.useCallback(()=>{let e=re.hostId;if(!e)return;let t=_e.find(t=>t.id===e);t&&De(t)},[_e,De,re.hostId]),Ie=J(async e=>{if(!(!x()||H.current||L)){U(e.id);try{await cc(e.id),(await jf(e.id,gf,e=>{ne(t=>({...t,[e.id]:e}))})).phase===`ready`&&Yr.success(s(`desktopHostSwitcher.toast.sshConnected`,{host:T(e.label)}))}catch(t){let n=t instanceof Error?t.message:String(t);if(n!==_f){let t=ac(null,n);Yr.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Zc(s(Cc(t)),t,n)})}}finally{U(null)}}});if(!x())return null;let Le=x(),Re=(0,$.jsxs)($.Fragment,{children:[n?(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-[var(--interactive-border)] px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex items-baseline gap-1.5 typography-ui-label`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.current`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`•`}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.default`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(Se)})]}),(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors`,`hover:text-foreground hover:bg-interactive-hover`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),onClick:()=>void Ee(ye),disabled:!Le||y||S,"aria-label":s(`desktopHostSwitcher.actions.refreshInstancesAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)})})]})}):(0,$.jsxs)(xs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ws,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`server`,className:`h-5 w-5`}),s(`desktopHostSwitcher.title`)]}),(0,$.jsx)(Ts,{children:s(`desktopHostSwitcher.description`)})]}),!n&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentDefaultColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(Se)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsxs)(er,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Ee(ye),disabled:!Le||y||S,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)}),s(`desktopHostSwitcher.actions.refresh`)]})})]}),!Le&&(0,$.jsx)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.state.limitedOnPage`)})}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:Y(`space-y-1`,n&&`space-y-1.5 px-3 py-1`),children:y?(0,$.jsx)(`div`,{className:`px-2 py-2 text-muted-foreground text-sm`,children:s(`desktopHostSwitcher.state.loading`)}):ye.map(e=>{let t=e.id===hf,r=!!W[e.id],i=e.id===be.id,a=(h||hf)===e.id,o=_[e.id]||null,c=te[e.id]||null,l=mf({isActive:i,isSsh:r,runtimeIsConnected:u,runtimeConnectionPhase:d,currentTransportIsRelay:xe,probe:o,sshPhase:c?.phase}),f=l.statusKind,p=l.showViaRelay,m=ce===e.id,g=t?oe:O(e.url)||e.url,v=e.id===hf?s(`desktopHostSwitcher.instance.local`):T(e.label),y=e.relay&&!e.apiUrl?s(`mobile.connect.relay.badge`):T(g);return(0,$.jsxs)(`div`,{className:Y(`app-region-no-drag group flex items-center gap-2 px-2.5 py-2 rounded-md overflow-hidden`,n&&`rounded-xl bg-[var(--surface-muted)] px-3 py-2.5`,n&&i&&`bg-[var(--interactive-selection)]/25`,m?`bg-interactive-hover/20`:`hover:bg-interactive-hover/30`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-2 flex-1 min-w-0 text-left`,m&&`pointer-events-none opacity-70`),onClick:()=>void De(e),disabled:!!V,"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.switchToAria`,{instance:v}),children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,$.jsx)(`span`,{className:Y(`h-2 w-2 rounded-full flex-shrink-0`,Cf(f))}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium truncate text-foreground`,children:v}),i&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 text-muted-foreground bg-muted px-1 rounded leading-none pb-px border border-border/50`,children:s(`desktopHostSwitcher.header.current`)}),r&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 px-1 rounded leading-none pb-px text-[var(--status-info)] bg-[var(--status-info)]/10`,children:`SSH`})]}),(0,$.jsxs)(`div`,{className:Y(`typography-micro truncate`,wf(f)),children:[r&&(!i||V===e.id)?s(kf(c?.phase)):s(Df(f)),l.latencyMs==null?``:s(`desktopHostSwitcher.status.ping`,{ms:l.latencyMs}),p?` · ${s(`settings.remoteInstances.clientAuth.state.viaRelay`)}`:``]}),(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70 truncate font-mono`,children:y})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[r&&!t&&(c?.phase===`idle`||!c?.phase?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 px-2.5`,disabled:!!V,onClick:t=>{t.stopPropagation(),Ie(e)},children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(X,{name:`plug-2`,className:`h-3.5 w-3.5`}),s(`desktopHostSwitcher.actions.connect`)]}):(0,$.jsx)(`div`,{className:`h-8 w-8 opacity-0 pointer-events-none`,"aria-hidden":`true`})),(0,$.jsxs)(tc,{delayDuration:600,children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`app-region-no-drag h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors`,a?`text-primary hover:text-primary/80`:`text-muted-foreground/60 hover:text-primary/80`),onClick:()=>void je(e.id),"aria-label":s(a?`desktopHostSwitcher.actions.defaultInstanceAria`:`desktopHostSwitcher.actions.setAsDefaultAria`),disabled:j||!a&&Ef(f),children:a?(0,$.jsx)(X,{name:`star-fill`,className:`h-4 w-4`}):(0,$.jsx)(X,{name:`star`,className:`h-4 w-4`})})}),(0,$.jsx)(ec,{sideOffset:6,children:s(a?`desktopHostSwitcher.header.default`:`desktopHostSwitcher.actions.setAsDefault`)})]}),(0,$.jsxs)(tc,{delayDuration:600,children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`app-region-no-drag h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors`,Ef(f)?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground/60 hover:text-foreground`),onClick:t=>{t.stopPropagation(),Me(e)},disabled:!!V||Ef(f),"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.openInNewWindowAria`),children:(0,$.jsx)(X,{name:V===e.id?`loader-4`:`window`,className:Y(`h-4 w-4`,V===e.id&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:Ef(f)?s(`desktopHostSwitcher.state.instanceUnreachable`):s(`desktopHostSwitcher.actions.openInNewWindow`)})]})]})]},e.id)})})}),Le&&ce&&ce!==hf&&(0,$.jsxs)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground`,children:s(`desktopHostSwitcher.edit.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(er,{type:`button`,variant:`outline`,size:`sm`,onClick:Oe,disabled:j,children:s(`desktopHostSwitcher.actions.cancel`)}),(0,$.jsxs)(er,{type:`button`,size:`sm`,onClick:()=>void Ae(),disabled:j,children:[j?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):null,s(`desktopHostSwitcher.actions.save`)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,$.jsx)(Qs,{value:ue,onChange:e=>de(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.labelPlaceholder`),disabled:j}),(0,$.jsx)(Qs,{value:fe,onChange:e=>pe(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.urlPlaceholder`),disabled:j})]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 border-t border-[var(--interactive-border)]`,children:(0,$.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-2 py-2 text-left text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,onClick:we,disabled:!!V,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:s(`desktopHostSwitcher.actions.addInstance`)})]})}),ie&&(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-status-error`,children:ie})]}),ze=(0,$.jsx)(Ds,{open:re.open,onOpenChange:e=>{if(!e&&V){Pe();return}G(t=>({...t,open:e,...e?{}:{hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}}))},children:(0,$.jsxs)(Cs,{className:`w-[min(28rem,calc(100vw-2rem))] max-w-none`,children:[(0,$.jsxs)(xs,{children:[(0,$.jsxs)(ws,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(`h-4 w-4`,!re.error&&`animate-spin`)}),s(`desktopHostSwitcher.ssh.connectingTo`,{host:re.hostLabel||s(`desktopHostSwitcher.ssh.instanceFallback`)})]}),re.error?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ts,{className:`sr-only`,children:s(uc(ac(re.errorCode,re.error)))}),(0,$.jsx)(xc,{errorCode:re.errorCode,detail:re.error})]}):(0,$.jsx)(Ts,{children:re.detail||s(kf(re.phase))})]}),re.error?(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{we(),Pe()},children:s(`desktopHostSwitcher.sshError.openRemoteSettings`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void Ne(),children:s(`desktopHostSwitcher.actions.switchToLocal`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,onClick:Fe,disabled:!re.hostId,children:s(`desktopHostSwitcher.actions.retry`)})]}):null]})});return n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-full max-h-[70vh] flex flex-col overflow-hidden gap-2`,children:Re}),ze]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ds,{open:e,onOpenChange:e=>{!e&&H.current||t(e)},children:(0,$.jsx)(Cs,{className:`w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3`,children:Re})}),ze]})}function Ff(){let e=(0,Q.c)(11),[t,n]=Z.useState(!1),{t:r}=Xn();if(!x())return null;let i,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>n(!0),a=(0,$.jsx)(X,{name:`server`,className:`h-4 w-4`}),e[0]=i,e[1]=a):(i=e[0],a=e[1]);let o;e[2]===r?o=e[3]:(o=r(`desktopHostSwitcher.actions.switchInstance`),e[2]=r,e[3]=o);let s;e[4]===o?s=e[5]:(s=(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,"data-yuri-host-switcher":!0,className:`w-full justify-center`,onClick:i,children:[a,o]}),e[4]=o,e[5]=s);let c;e[6]===t?c=e[7]:(c=(0,$.jsx)(Pf,{open:t,onOpenChange:n}),e[6]=t,e[7]=c);let l;return e[8]!==s||e[9]!==c?(l=(0,$.jsxs)($.Fragment,{children:[s,c]}),e[8]=s,e[9]=c,e[10]=l):l=e[10],l}var If=e=>e.shouldUseDesktopShellPasswordLogin?`locked`:`error`,Lf=`/auth/session`,Rf=4,zf=1500,Bf=`yuri.uiAuth.trustDevice`,Vf=`desktop-local`,Hf=`desktop-local`,Uf=()=>{if(typeof window>`u`)return``;let e=window.__YURI_LOCAL_ORIGIN__;return typeof e==`string`?e.trim():``},Wf=(e,t)=>{let n=O(e),r=O(t);if(!n||!r)return!1;try{return new URL(n).origin===new URL(r).origin}catch{return!1}},Gf=()=>x(),Kf=e=>{let t=e.replace(/^\[|\]$/g,``);return t===`localhost`||t===`127.0.0.1`||t===`::1`},qf=()=>{if(!x())return!1;let e=Uf();if(!e)return!1;let t=d()||(typeof window<`u`?window.location.origin:``);if(Wf(e,t))return!0;try{let e=O(t);return!!(e&&Kf(new URL(e).hostname))}catch{return!1}},Jf=()=>qf()?{clientKind:Vf,dedupeKey:Hf}:{},Yf=async()=>await f(Lf,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}}),Xf=()=>typeof window>`u`?!1:window.localStorage.getItem(Bf)===`true`,Zf=async(e,t)=>{let n=Gf();return await f(Lf,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({password:e,trustDevice:t,issueClientToken:n,clientLabel:`Yuri Desktop`,...Jf()})})},Qf=async()=>{if(!x())return``;let e=await f(`/api/client-auth/clients`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:`Yuri Desktop`,...Jf()})}).catch(()=>null);if(!e?.ok)return``;let t=await e.json().catch(()=>null);return typeof t?.token==`string`?t.token.trim():``},$f=()=>x()&&!qf(),ep=async(e,t)=>{if(!x()||typeof window>`u`)return null;let r=await y(`desktop_remote_password_login`,{url:d(),password:e,trustDevice:t,requestHeaders:n()}).catch(()=>null);if(!r||typeof r!=`object`)return null;let i=r.token,a=r.status;return{token:typeof i==`string`?i.trim():``,...typeof a==`number`?{status:a}:{}}},tp=async(e,t)=>{if(!x()||!t)return;let n=await M().catch(()=>null);if(!n)return;if(n.localOrigin&&Wf(n.localOrigin,e)){await D({hosts:n.hosts,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted,localClientToken:t}).catch(()=>void 0);return}let r=!1,i=n.hosts.map(n=>!Wf(P(n),e)||n.clientToken===t?n:(r=!0,{...n,clientToken:t}));r&&await D({hosts:i,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted}).catch(()=>void 0)},np=async e=>{if(!e)return;let r=d(),i=n();await tp(r,e),s({apiBaseUrl:r,clientToken:e,requestHeaders:Object.keys(i).length>0?i:null,relay:t()})},rp=e=>{let t=(0,Q.c)(7),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={height:`var(--yuri-wco-titlebar-height, 0px)`,right:`var(--yuri-wco-right-inset, 0px)`},t[0]=r):r=t[0];let i=r,a,o;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a={fontFamily:`"Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif`},o=(0,$.jsx)(`div`,{className:`app-region-drag fixed left-0 top-0 z-20`,style:i,"aria-hidden":!0}),t[1]=a,t[2]=o):(a=t[1],o=t[2]);let s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-55`,style:{background:`radial-gradient(120% 140% at 50% -20%, var(--surface-overlay) 0%, transparent 68%)`}}),t[3]=s):s=t[3];let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,style:{backgroundColor:`var(--surface-subtle)`,opacity:.22}}),t[4]=c):c=t[4];let l;return t[5]===n?l=t[6]:(l=(0,$.jsxs)(`div`,{className:`relative flex min-h-screen items-center justify-center overflow-hidden bg-background text-foreground`,style:a,children:[o,s,c,(0,$.jsx)(`div`,{className:`app-region-no-drag relative z-10 flex w-full justify-center px-4 py-12 sm:px-6`,children:n})]}),t[5]=n,t[6]=l),l},ip=()=>{let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background text-foreground`,children:(0,$.jsx)(Qc,{width:120,height:120})}),e[0]=t):t=e[0],t},ap=e=>{let t=(0,Q.c)(23),{onRetry:n,errorType:r,retryAfter:i,children:a}=e,o=r===void 0?`network`:r,{t:s}=Xn(),c=o===`rate-limit`,l=i?Math.ceil(i/60):1,u;t[0]!==c||t[1]!==s?(u=s(c?`sessionAuth.error.rateLimitTitle`:`sessionAuth.error.networkTitle`),t[0]=c,t[1]=s,t[2]=u):u=t[2];let d;t[3]===u?d=t[4]:(d=(0,$.jsx)(`h1`,{className:`typography-ui-header font-semibold text-destructive`,children:u}),t[3]=u,t[4]=d);let f;t[5]!==c||t[6]!==l||t[7]!==s?(f=c?s(l>1?`sessionAuth.error.rateLimitDescriptionPlural`:`sessionAuth.error.rateLimitDescriptionSingle`,{minutes:l}):s(`sessionAuth.error.networkDescription`),t[5]=c,t[6]=l,t[7]=s,t[8]=f):f=t[8];let p;t[9]===f?p=t[10]:(p=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground max-w-xs`,children:f}),t[9]=f,t[10]=p);let m;t[11]!==d||t[12]!==p?(m=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[d,p]}),t[11]=d,t[12]=p,t[13]=m):m=t[13];let h;t[14]===s?h=t[15]:(h=s(`sessionAuth.error.retry`),t[14]=s,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(er,{type:`button`,onClick:n,className:`w-full max-w-xs`,children:h}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;return t[19]!==a||t[20]!==m||t[21]!==g?(_=(0,$.jsx)(rp,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[m,g,a]})}),t[19]=a,t[20]=m,t[21]=g,t[22]=_):_=t[22],_},op=({children:e})=>{let{t}=Xn(),n=Z.useMemo(()=>b(),[]),r=n,a=Z.useMemo(()=>x()&&!n,[n]),[o,s]=Z.useState(()=>r?`authenticated`:`pending`),[c,d]=Z.useState(``),[f,p]=Z.useState(!1),[m,h]=Z.useState(``),[g,_]=Z.useState(void 0),[v,y]=Z.useState(!1),[S,C]=Z.useState(rc),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(()=>Xf()),[A,j]=Z.useState(null),[M,N]=Z.useState(r),P=Z.useRef(null),F=Z.useRef(r);Z.useEffect(()=>{typeof window>`u`||window.localStorage.setItem(Bf,O?`true`:`false`)},[O]);let I=Z.useCallback(async()=>{if(r)return rc;try{let e=await Lc();return C(e),e}catch{return C(rc),rc}},[r]);Z.useEffect(()=>{let e=!1;if(!r)return(async()=>{try{if(!window.isSecureContext||!As()){e||T(!1);return}e||T(!0)}catch{e||T(!1)}})(),()=>{e=!0}},[r]);let L=Z.useRef(0),R=Z.useRef(null),z=Z.useRef(null),B=Z.useCallback(()=>{R.current!==null&&(window.clearTimeout(R.current),R.current=null)},[]),V=Z.useCallback(()=>{L.current=0,B()},[B]),H=Z.useCallback(()=>L.current>=Rf?!1:(L.current+=1,B(),R.current=window.setTimeout(()=>{R.current=null,z.current?.()},zf*L.current),!0),[B]);Z.useEffect(()=>B,[B]);let U=Z.useCallback(async()=>{if(r){s(`authenticated`);return}s(e=>e===`authenticated`?e:`pending`);try{let[e,t]=await Promise.all([Yf(),I()]),n=await e.text();if(e.ok){V(),s(`authenticated`),y(!1),h(``),_(void 0);return}if(e.status===401){let e={};try{e=JSON.parse(n)}catch{e={}}V(),y(e.tunnelLocked===!0),C(t),s(`locked`),_(void 0);return}if(e.status===429){let e={};try{e=JSON.parse(n)}catch{e={}}V(),_(e.retryAfter),y(!1),s(`rate-limited`);return}if(H())return;s(`error`),y(!1)}catch(e){if(console.warn(`Failed to check session status:`,e),If({shouldUseDesktopShellPasswordLogin:$f()})===`locked`){s(`locked`),_(void 0),y(!1);return}if(H())return;s(`error`),y(!1)}},[I,V,H,r]);Z.useEffect(()=>{z.current=U},[U]),Z.useEffect(()=>{r||U()},[U,r]),Z.useEffect(()=>{if(o===`pending`||o===`authenticated`||typeof document>`u`)return;let e=document.getElementById(`initial-loading`);if(!e)return;e.classList.add(`fade-out`);let t=window.setTimeout(()=>{e.remove()},300);return()=>{window.clearTimeout(t)}},[o]),Z.useEffect(()=>{if(r)return;let e=df(e=>{l(e)&&(d(``),h(``),_(void 0),y(!1),V(),N(!1),F.current=!1,s(`pending`),U())}),t=i(t=>e.schedule(t));return()=>{t(),e.cancel()}},[U,V,r]),Z.useEffect(()=>{!r&&o===`locked`&&(F.current=!1,N(!1))},[r,o]),Z.useEffect(()=>{o===`locked`&&P.current&&(P.current.focus(),P.current.select())},[o]),Z.useEffect(()=>{if(!r&&o===`authenticated`&&!F.current){F.current=!0;let e=!1;return lf({runtimeKey:u(),initializeAppearance:sn,syncSettings:rn,applyDirectory:of,onError:(e,t)=>{console.error(`[SessionAuthGate] ${e} settings hydration failed:`,t)}},{force:!0}).then(()=>{e||N(!0)}),()=>{e=!0}}},[r,o]);let W=async e=>{e.preventDefault(),await ne(!1)},ee=Z.useCallback(async()=>{j(`register`),D(!0);try{await sc()}finally{j(null),D(!1)}await I()},[I]),te=Z.useCallback(()=>{Rc(),j(null),D(!1)},[]),ne=Z.useCallback(async e=>{if(!v&&!(!c||f)){E&&te(),p(!0),h(``);try{if($f()){let e=await ep(c,O);if(e?.token){d(``),y(!1),await np(e.token),s(`authenticated`);return}if(e?.status===401){h(t(`sessionAuth.error.incorrectPassword`)),y(!1),s(`locked`);return}if(e?.status===429){_(void 0),y(!1),s(`rate-limited`);return}}let n=await Zf(c,O);if(n.ok){let r=await n.json().catch(()=>null),i=Gf(),a=``;if(i&&(a=typeof r?.clientToken==`string`&&r.clientToken.trim()?r.clientToken.trim():``,a||=(await ep(c,O))?.token||await Qf()),d(``),y(!1),a&&await np(a),e&&w)try{await ee(),Yr.success(t(`sessionAuth.toast.passkeyAdded`)),s(`authenticated`);return}catch(e){if(_c(e))Yr.message(t(`sessionAuth.toast.passkeySetupCanceled`));else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);Yr.error(n)}s(`authenticated`);return}s(`authenticated`);return}if(n.status===401){h(t(`sessionAuth.error.incorrectPassword`)),y(!1),s(`locked`);return}if(n.status===429){let e=await n.json().catch(()=>({}));_(e.retryAfter),y(!1),s(`rate-limited`);return}h(t(`sessionAuth.error.unexpectedResponse`)),y(!1),s(`error`)}catch(e){console.warn(`Failed to submit UI password:`,e);let n=$f()?await ep(c,O):null;if(n?.token){d(``),y(!1),await np(n.token),s(`authenticated`);return}if(n?.status===401){h(t(`sessionAuth.error.incorrectPassword`)),y(!1),s(`locked`);return}if(n?.status===429){_(void 0),y(!1),s(`rate-limited`);return}h(t(`sessionAuth.error.networkRetry`)),y(!1),s(`error`)}finally{p(!1)}}},[te,E,f,v,c,ee,w,t,O]),re=Z.useCallback(async()=>{if(!(f||!w)){if(E){te();return}D(!0),j(`auth`),h(``);try{let e=await gc(O,{issueClientToken:Gf(),clientLabel:`Yuri Desktop`,...Jf()}),t=Gf()&&typeof e?.clientToken==`string`&&e.clientToken.trim()?e.clientToken.trim():``;t&&await np(t),d(``),s(`authenticated`)}catch(e){if(_c(e))h(``);else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySignInCanceled`);h(n)}}finally{j(null),D(!1)}}},[te,E,f,w,t,O]),G=Z.useCallback(async()=>{if(!(f||v||!w)){if(E){te();return}if(o!==`authenticated`){if(!c){h(t(`sessionAuth.error.enterPasswordForPasskey`));return}await ne(!0);return}h(``);try{await ee(),Yr.success(t(`sessionAuth.toast.passkeyAdded`))}catch(e){if(_c(e)){Yr.message(t(`sessionAuth.toast.passkeySetupCanceled`));return}let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);Yr.error(n)}}},[te,ne,E,f,v,c,ee,o,w,t]),ie=w&&S.enabled,ae=ie&&S.hasPasskeys;return o===`pending`||o===`authenticated`&&!M?(0,$.jsx)(ip,{}):o===`error`?(0,$.jsx)(ap,{onRetry:()=>{V(),U()},errorType:`network`,children:a&&(0,$.jsxs)(`div`,{className:`w-full max-w-xs`,children:[(0,$.jsx)(Ff,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})}):o===`rate-limited`?(0,$.jsx)(ap,{onRetry:()=>void U(),errorType:`rate-limit`,retryAfter:g}):o===`locked`?(0,$.jsx)(rp,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 w-full max-w-xs`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-1 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:t(v?`sessionAuth.locked.tunnelTitle`:`sessionAuth.locked.unlockTitle`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(v?`sessionAuth.locked.tunnelDescription`:`sessionAuth.locked.passwordDescription`)})]}),!v&&(0,$.jsxs)(`form`,{onSubmit:W,className:`w-full space-y-2`,children:[ae&&(0,$.jsxs)(er,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>void re(),disabled:f||E&&A!==`auth`,children:[E?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:t(E&&A===`auth`?`sessionAuth.actions.cancelPasskey`:`sessionAuth.actions.usePasskey`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(X,{name:`lock`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60`}),(0,$.jsx)(Qs,{id:`yuri-ui-password`,ref:P,type:`password`,autoComplete:`current-password`,placeholder:t(`sessionAuth.password.placeholder`),value:c,onChange:e=>{d(e.target.value),m&&h(``)},className:`pl-10`,"aria-invalid":!!m||void 0,"aria-describedby":m?`yuri-ui-auth-error`:void 0,disabled:f})]}),(0,$.jsx)(er,{type:`submit`,size:`icon`,disabled:!c||f,"aria-label":t(f?`sessionAuth.actions.unlockingAria`:`sessionAuth.actions.unlockAria`),children:f?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`})})]}),ie?(0,$.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(js,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void G(),disabled:f,children:t(E&&A===`register`?`sessionAuth.actions.cancelPasskeySetup`:`sessionAuth.actions.addPasskey`)})]}):(0,$.jsxs)(`label`,{className:`flex items-center justify-center gap-2 pt-1 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(js,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),m&&(0,$.jsx)(`p`,{id:`yuri-ui-auth-error`,className:`typography-meta text-destructive`,children:m})]}),a&&(0,$.jsxs)(`div`,{className:`w-full`,children:[(0,$.jsx)(Ff,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})]})}):(0,$.jsx)($.Fragment,{children:e})},sp=e=>!!e&&typeof e==`object`&&!Array.isArray(e),cp=e=>typeof e==`string`&&e.trim()?e.trim():null,lp=e=>{if(!sp(e))throw Error(`Could not check OpenCode compatibility`);let t=e.state,n=e.installation;if(t!==`compatible`&&t!==`incompatible`&&t!==`unavailable`||n!==`managed`&&n!==`external`&&n!==`bundled`)throw Error(`Could not check OpenCode compatibility`);let r=cp(e.minimumVersion),i=cp(e.targetVersion);if(!r||!i||typeof e.canInstall!=`boolean`)throw Error(`Could not check OpenCode compatibility`);return{state:t,version:cp(e.version),installation:n,minimumVersion:r,targetVersion:i,canInstall:e.canInstall,guidance:cp(e.guidance)}},up=async()=>{let e=await f(`/api/opencode/compatibility`,{signal:AbortSignal.timeout(2e4)});if(!e.ok)throw Error(`Could not check OpenCode compatibility`);return lp(await e.json())},dp=async()=>{let e=await f(`/api/opencode/install-required`,{method:`POST`}),t=await e.json().catch(()=>null),n=sp(t)?t:null,r=cp(n?.error);if(!e.ok||n?.success!==!0||n?.upgraded!==!0)throw Error(r||`OpenCode installation failed`);let i=cp(n.version);if(!i)throw Error(r||`OpenCode installation did not report a verified version`);return{version:i}},fp=(e,t)=>e instanceof Error&&e.message.trim()?e.message.trim():t,pp=({children:e})=>{let{t}=Xn(),[n,r]=Z.useState(null),[a,o]=Z.useState(!1),[s,c]=Z.useState(null),[l,u]=Z.useState(null),d=Z.useId(),f=Z.useRef(null),p=Z.useRef(0);Z.useEffect(()=>{let e=!0,t=async()=>{let t=++p.current;try{let n=await up();if(!e||t!==p.current)return;r(n),n.state!==`incompatible`&&u(null)}catch{}finally{e&&t===p.current&&o(!0)}};t();let n=i(()=>{e&&(r(null),o(!1),c(null),u(null),t())});return()=>{e=!1,p.current+=1,n()}},[]);let m=n?.state===`incompatible`;Z.useEffect(()=>{m&&(document.getElementById(`initial-loading`)?.remove(),f.current?.focus())},[m]);let h=J(async e=>{if(s)return;let n=++p.current;c(e),u(null);try{if(e===`install`){let e=await dp();if(n!==p.current)return;if(!e.version)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload();return}let i=await up();if(n!==p.current)return;if(i.state===`incompatible`){r(i);return}if(i.state!==`compatible`)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload()}catch(e){if(n!==p.current)return;u(fp(e,t(`opencodeUpgrade.screen.failedGeneric`)))}finally{n===p.current&&c(null)}}),g=(0,$.jsx)(`main`,{"data-startup-logo":!0,className:`flex min-h-dvh items-center justify-center bg-background text-foreground`,children:(0,$.jsx)(Qc,{width:120,height:120,isAnimated:!0})});if(!a)return g;if(!m||!n)return(0,$.jsx)(oc,{children:(0,$.jsx)(Z.Suspense,{fallback:g,children:e})});let _=!!n.version?.startsWith(`2.`),v=n.installation===`bundled`?`opencodeUpgrade.screen.bundled`:n.installation===`external`?_?`opencodeUpgrade.screen.outdatedExternal`:`opencodeUpgrade.screen.external`:_?`opencodeUpgrade.screen.outdatedLocal`:`opencodeUpgrade.screen.local`,y=n.minimumVersion,b=s!==null;return(0,$.jsx)(`section`,{className:`app-region-drag flex h-full min-h-dvh min-h-0 items-center justify-center overflow-y-auto bg-background px-4 py-10 text-foreground select-none sm:px-6`,"aria-labelledby":d,"aria-busy":b,"data-opencode-upgrade-screen":`true`,children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col items-center text-center`,children:[(0,$.jsx)(Qc,{width:48,height:48}),(0,$.jsx)(`h1`,{id:d,ref:f,tabIndex:-1,className:`mt-6 text-xl font-semibold tracking-tight text-balance outline-none`,children:t(_?`opencodeUpgrade.screen.outdatedTitle`:`opencodeUpgrade.screen.title`)}),(0,$.jsxs)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground text-balance`,children:[t(v,{version:n.version??``,minimum:y}),n.canInstall?(0,$.jsxs)($.Fragment,{children:[` `,t(`opencodeUpgrade.screen.installDescription`,{minimum:y})]}):null]}),n.canInstall?null:(0,$.jsx)(`p`,{className:`mt-3 text-sm leading-relaxed text-muted-foreground text-balance`,children:t(`opencodeUpgrade.screen.manualGuidance`)}),n.version?(0,$.jsxs)(`div`,{className:`mt-5 inline-flex max-w-full items-center gap-2 rounded-md border border-border px-2.5 py-1 font-mono text-xs`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`truncate text-muted-foreground`,children:n.version}),(0,$.jsx)(X,{name:`arrow-right`,className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`text-foreground`,children:[y,`+`]})]}):null,l?(0,$.jsxs)(`p`,{role:`alert`,className:`mt-5 w-full break-words rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] px-3 py-2 text-left text-sm text-[var(--status-error-text)]`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t(`opencodeUpgrade.screen.failedTitle`)}),` `,l]}):null,(0,$.jsxs)(`div`,{className:`app-region-no-drag mt-7 flex w-full flex-wrap items-center justify-center gap-2`,children:[n.canInstall?(0,$.jsxs)(er,{type:`button`,disabled:b,onClick:()=>void h(`install`),children:[(0,$.jsx)(X,{name:s===`install`?`refresh`:`download`,className:s===`install`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`install`?`status`:void 0,children:s===`install`?t(_?`opencodeUpgrade.screen.updating`:`opencodeUpgrade.screen.installing`):t(_?`opencodeUpgrade.screen.update`:`opencodeUpgrade.screen.install`,{minimum:y})})]}):null,(0,$.jsxs)(er,{type:`button`,variant:n.canInstall?`ghost`:`default`,disabled:b,onClick:()=>void h(`reconnect`),children:[(0,$.jsx)(X,{name:`refresh`,className:s===`reconnect`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`reconnect`?`status`:void 0,children:t(s===`reconnect`?`opencodeUpgrade.screen.reconnecting`:`opencodeUpgrade.screen.reconnect`)})]})]}),(0,$.jsxs)(`a`,{className:`app-region-no-drag mt-6 inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,href:`https://opencode.ai/download`,target:`_blank`,rel:`noopener noreferrer`,children:[t(`opencodeUpgrade.screen.guide`),(0,$.jsx)(X,{name:`external-link`,className:`size-3`})]}),(0,$.jsx)(`div`,{className:`app-region-no-drag mt-3 w-full`,children:(0,$.jsx)(Ff,{})})]})})},mp=e=>{let t=(0,Q.c)(14),{children:n}=e,r=K(hp),i=K(gp),a=K(_p),o=K(vp),s=K(yp),{deviceType:c,hasTouchInput:l}=$c(),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=typeof document<`u`&&bt(),t[0]=u):u=t[0];let d=u,f;t[1]!==s||t[2]!==a?(f=()=>{a(),s()},t[1]=s,t[2]=a,t[3]=f):f=t[3];let p;t[4]!==s||t[5]!==a||t[6]!==i||t[7]!==c||t[8]!==r||t[9]!==l||t[10]!==o?(p=[r,i,a,o,s,c,l,d],t[4]=s,t[5]=a,t[6]=i,t[7]=c,t[8]=r,t[9]=l,t[10]=o,t[11]=p):p=t[11],Z.useLayoutEffect(f,p);let m;return t[12]===n?m=t[13]:(m=(0,$.jsx)($.Fragment,{children:n}),t[12]=n,t[13]=m),m};function hp(e){return e.fontSize}function gp(e){return e.codeFontSize}function _p(e){return e.applyTypography}function vp(e){return e.padding}function yp(e){return e.applyPadding}var bp=e(G(),1),xp=e=>{if(!e||typeof e!=`string`)return null;let t=e.trim();if(!t.startsWith(`#`))return null;let n=t.slice(1);if((n.length===3||n.length===4)&&(n=n.split(``).map(e=>e+e).join(``)),n.length===8&&(n=n.slice(0,6)),n.length!==6)return null;let r=Number.parseInt(n,16);return Number.isNaN(r)?null:`${r>>16&255} ${r>>8&255} ${r&255}`},Sp=class{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){let t=[];return t.push(...this.generateTailwindVariables(e)),t.push(...this.generatePrimaryColors(e.colors.primary)),t.push(...this.generateSurfaceColors(e.colors.surface)),t.push(...this.generateInteractiveColors(e.colors.interactive)),t.push(...this.generateStatusColors(e.colors.status)),t.push(...this.generatePullRequestColors(e)),t.push(...this.generateSyntaxColors(e.colors.syntax)),t.push(...this.generateComponentColors(e.colors,e)),t.push(...this.generateTypographyVariables()),e.config&&t.push(...this.generateConfigVariables(e.config)),t.join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-DJs9w1_J.js","assets/rolldown-runtime-hePW80VL.js","assets/runtime-auth-DBn9yahL.js","assets/runtime-switch-DEZ1K7qW.js","assets/runtime-fetch-D4ja813o.js","assets/desktop-JwYqThiw.js","assets/runtimeAPIRegistry-C2VogTny.js","assets/vendor-base-ui-BQjbsJ43.js","assets/useUIStore-DI7va1HH.js","assets/vendor-zustand-B43HCgwC.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/vendor-react-D5d-V1vN.js","assets/vendor-tanstack-react-query-C4SG3JZB.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/runtime-file-resource-6np6lzoV.js","assets/queryRuntime-Dkpnq3Z1.js","assets/fileQueries-5a1jkme2.js","assets/runtime-file-store-BVRgEtI-.js","assets/path-utils-jGozTg9d.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/runtime-file-download-CcNIVp7u.js","assets/platform-DFJEtBlo.js","assets/vendor-pierre-diffs-Bj9Nqn6w.js","assets/vendor-hast-util-to-html-Bw_SgZ1t.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-BMOrLc9L.js","assets/vendor-reactuses-core-BcebBLwF.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-Dt6Ygbc7.js","assets/store-DvN2L3vf.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/useThemeSystem-CGF5jnIh.js","assets/vendor-framer-motion-C1twy-GF.js","assets/Icon-BP1sfnHn.js","assets/dialog-CjQeHVOc.js","assets/dialog-CTYD3Sbr.css","assets/tap-LkQum5bB.js","assets/image-loading-Dq1g_wpm.js","assets/image-loading-D9Z_BASK.css","assets/MobileWindowStack-DGLdgoGr.js","assets/appThemeRegistry-BY5rY9-W.js","assets/useMobileNavigationStore-TCj7ZnhV.js","assets/gitApiHttp-DHrRqnYh.js","assets/vendor-opencode-client-UL_TecvQ.js","assets/vendor-effect-DV9F8PTZ.js","assets/persistence-JyLTFv27.js","assets/pathNormalization-ewtPqJWn.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-sonner-r2EJnfoo.js","assets/useAssistantUIStore-C9FPlYQz.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/vendor-fuzzysort-ukaRp9PC.js","assets/agentColors-DWSbQXy2.js","assets/rasterizePng-056Poix7.js","assets/MarkdownRenderer-Y6uQXIFH.js","assets/useEffectiveDirectory-Ci6Z13kj.js","assets/markdownHeightCache-C1u0bWDL.js","assets/dualLimitLru-D8Sphgua.js","assets/toolHelpers-iEHVHQ9p.js","assets/ImageLoadingPlaceholder-DCWssLJG.js","assets/useWorkerHighlightedLines-HKhuYGSj.js","assets/markdownTheme-hpURsgju.js","assets/markdown-worker-oBGEB9Eg.js","assets/vendor-tanstack-react-virtual-BeZn51tF.js","assets/mobileBackNavigation-vpCg1S7j.js","assets/touch-gestures-K2_ZOkKW.js","assets/ToolOutputDialog-CbGuK5bP.css","assets/vendor-capacitor-app-B5H_XtmE.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}from"./runtime-auth-DBn9yahL.js";import{c as i,f as a,i as o,l as s,n as c,o as l,r as u,t as d}from"./runtime-switch-DEZ1K7qW.js";import{n as f}from"./runtime-fetch-D4ja813o.js";import{N as p,S as m,T as h,b as g,h as _,t as v,v as y,w as b,x}from"./desktop-JwYqThiw.js";import{t as S}from"./runtimeAPIRegistry-C2VogTny.js";import{c as C,f as w,g as T,h as E,i as D,m as O,n as k,o as A,p as j,r as M,s as N,u as P,v as F}from"./desktopHosts-CB0CTcMg.js";import{r as I}from"./desktopRelayRestore-CoLLVJw8.js";import{a as L,i as R,o as z,r as B,s as V,t as H}from"./vendor-zustand-B43HCgwC.js";import{at as U,d as W,f as ee,it as te,m as ne,p as re,rt as G,u as ie}from"./vendor-base-ui-BQjbsJ43.js";import{$t as ae,Ar as oe,At as se,Cn as ce,Cr as le,Dt as ue,En as de,Et as fe,Fi as pe,Ii as me,Kt as he,Nn as ge,Nt as _e,On as ve,Or as ye,Ot as be,Pi as xe,Pn as Se,Pt as Ce,Qt as we,Rn as Te,Si as Ee,Sn as De,Ti as Oe,Tn as ke,Tr as Ae,Tt as je,Un as Me,Vn as Ne,Wt as Pe,Yt as Fe,Zt as Ie,_r as Le,an as Re,bi as ze,bn as Be,br as Ve,bt as He,dn as Ue,en as We,er as Ge,fn as Ke,gn as qe,hn as Je,hr as Ye,in as Xe,ki as Ze,kn as Qe,ln as $e,mi as et,nn as tt,qt as nt,rn as rt,un as it,vi as at,vn as ot,vr as st,wi as ct,wn as lt,wr as ut,yn as dt,yr as ft,zn as pt}from"./gitApiHttp-DHrRqnYh.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{_ as mt,b as ht,c as gt,f as _t,g as vt,h as yt,n as K,y as bt}from"./useUIStore-DI7va1HH.js";import{$ as xt,A as St,B as Ct,C as wt,Ct as Tt,F as Et,G as Dt,J as Ot,K as kt,L as At,M as jt,Ot as Mt,Pt as Nt,Q as Pt,R as Ft,S as It,T as Lt,Tt as Rt,V as zt,W as Bt,X as Vt,Y as Ht,_ as Ut,at as Wt,b as Gt,f as Kt,ft as qt,g as Jt,i as Yt,it as Xt,j as Zt,lt as Qt,m as $t,ot as en,pt as tn,q as nn,r as rn,rt as an,st as on,t as sn,tt as cn,v as ln,vt as un,wt as dn,x as fn,y as pn,yt as mn}from"./persistence-JyLTFv27.js";import{n as hn}from"./vendor-react-D5d-V1vN.js";import{i as gn}from"./vendor-tanstack-query-core-BWz0ose6.js";import{c as _n,i as vn,n as q,o as yn,t as bn}from"./vendor-tanstack-react-query-C4SG3JZB.js";import{a as xn,n as Sn,o as Cn}from"./queryRuntime-Dkpnq3Z1.js";import{d as wn,l as Tn,u as En}from"./fileQueries-5a1jkme2.js";import{a as Dn,i as On,n as kn,o as An,t as jn}from"./path-utils-jGozTg9d.js";import{o as Mn}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as Nn,t as Pn}from"./pathNormalization-ewtPqJWn.js";import{n as Fn,t as In}from"./platform-DFJEtBlo.js";import{i as Ln,u as Rn}from"./vendor-pierre-diffs-Bj9Nqn6w.js";import{r as zn,t as Bn}from"./vendor-sonner-r2EJnfoo.js";import{a as Vn,d as Hn,h as Un,i as Wn,m as Gn,o as Kn,p as qn,r as J,s as Jn}from"./vendor-reactuses-core-BcebBLwF.js";import{d as Yn,f as Xn,i as Zn,l as Qn,p as $n,r as Y,t as er,v as tr,y as nr}from"./button-Dt6Ygbc7.js";import{i as rr,t as ir}from"./store-DvN2L3vf.js";import{$ as ar,$a as or,$i as sr,$r as cr,$t as lr,A as ur,Ai as dr,An as fr,At as pr,B as mr,Ba as hr,Bi as gr,Bn as _r,Cn as vr,Ct as yr,D as br,Di as xr,Dn as Sr,Do as Cr,Dr as wr,Dt as Tr,E as Er,Ei as Dr,Er as Or,Et as kr,F as Ar,Fi as jr,G as Mr,Ga as Nr,Gn as Pr,Gt as Fr,H as Ir,Ha as Lr,Hi as Rr,Hn as zr,Hr as Br,I as Vr,Ii as Hr,In as Ur,J as Wr,Jt as Gr,K as Kr,Ka as qr,Kn as Jr,Kr as Yr,Kt as Xr,L as Zr,Li as Qr,Ln as $r,Lt as ei,M as ti,Ma as ni,Mn as ri,Mo as ii,Mt as ai,N as oi,Nt as si,O as ci,Oa as li,Oi as ui,On as di,Oo as fi,Ot as pi,P as mi,Pa as hi,Pi as gi,Pn as _i,Pt as vi,Q as yi,Qi as bi,Qr as xi,Qt as Si,R as Ci,Ra as wi,Rn as Ti,Rt as Ei,Si as Di,Sn as Oi,St as ki,Ti as Ai,Tr as ji,Tt as Mi,U as Ni,Ua as Pi,Ui as Fi,Un as Ii,V as Li,Va as Ri,Vi as zi,Vn as Bi,Vr as Vi,Vt as Hi,W as Ui,Wa as Wi,Wi as Gi,Wn as Ki,X as qi,Xn as Ji,Xt as Yi,Y as Xi,Yn as Zi,Yt as Qi,Z as $i,Za as ea,Zn as ta,_ as na,_a as ra,_n as ia,_t as aa,a as oa,aa as sa,ai as ca,at as la,ba as ua,bi as da,bn as fa,bo as pa,bt as ma,c as ha,ca as ga,ci as _a,cn as va,da as ya,dn as ba,dr as xa,ea as Sa,ei as Ca,en as wa,eo as Ta,et as Ea,f as Da,fa as Oa,fi as ka,fn as Aa,ft as ja,ga as Ma,gi as Na,gn as Pa,h as Fa,ha as Ia,hi as La,hn as Ra,ho as za,i as Ba,ia as Va,ii as Ha,it as Ua,j as Wa,ja as Ga,jn as Ka,jo as qa,jt as Ja,k as Ya,ka as Xa,kn as Za,kt as Qa,l as $a,la as eo,ln as to,lr as no,ma as ro,mi as io,mn as ao,mt as oo,n as so,na as co,nn as lo,nr as uo,nt as fo,oa as po,oi as mo,on as ho,or as go,ot as _o,pa as vo,pi as yo,pr as bo,pt as xo,q as So,qa as Co,qn as wo,qt as To,r as Eo,ra as Do,ro as Oo,rt as ko,sa as Ao,sn as jo,sr as Mo,st as No,ta as Po,ti as Fo,tn as Io,tr as Lo,tt as Ro,ua as zo,ui as Bo,un as Vo,ur as Ho,va as Uo,vi as Wo,vn as Go,w as Ko,wa as qo,wi as Jo,wn as Yo,wr as Xo,wt as Zo,xn as Qo,xt as $o,y as es,ya as ts,yi as ns,yn as rs,yo as is,yt as as,z as os,za as ss,zi as cs,zn as ls,zt as us}from"./useMobileNavigationStore-TCj7ZnhV.js";import{t as ds}from"./agentColors-DWSbQXy2.js";import{t as fs}from"./dualLimitLru-D8Sphgua.js";import{a as ps,i as ms,r as hs,t as gs}from"./AgentAvatar-kIN4sZMz.js";import{n as _s,r as vs,t as ys}from"./useThemeSystem-CGF5jnIh.js";import{o as bs}from"./vendor-framer-motion-C1twy-GF.js";import{n as X}from"./Icon-BP1sfnHn.js";import{a as xs,i as Ss,n as Cs,o as ws,r as Ts,s as Es,t as Ds}from"./dialog-CjQeHVOc.js";import{E as Os,n as ks}from"./gitApi-BxQmH8Wg.js";import{a as As}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{A as js,C as Ms,D as Ns,O as Ps,S as Fs,_ as Is,a as Ls,b as Rs,f as zs,h as Bs,i as Vs,k as Hs,l as Us,m as Ws,n as Gs,o as Ks,s as qs,u as Js,w as Ys,x as Xs,y as Zs}from"./projectMeta-CG8NLahh.js";import{t as Qs}from"./input-Dq4usRDa.js";import{i as $s,n as ec,t as tc}from"./tooltip-BpG2mxrT.js";import{$ as nc,At as rc,B as ic,Bt as ac,Ct as oc,Ft as sc,Gt as cc,H as lc,Ht as uc,J as dc,Jt as fc,K as pc,Kt as mc,L as hc,Ot as gc,Pt as _c,Q as vc,Qt as yc,R as bc,Rt as xc,St as Sc,Vt as Cc,X as wc,Y as Tc,Z as Ec,_t as Dc,an as Oc,at as kc,d as Ac,et as jc,ft as Mc,gt as Nc,i as Pc,in as Fc,it as Ic,jt as Lc,kt as Rc,lt as zc,mt as Bc,n as Vc,nt as Hc,o as Uc,on as Wc,pt as Gc,q as Kc,rt as qc,tt as Jc,ut as Yc,z as Xc,zt as Zc}from"./speechSettingsQueries-BSQ-2JTv.js";import{t as Qc}from"./YuriLogo-aBS6wlYU.js";import{r as $c}from"./device-BjRYYXNT.js";import{c as el,d as tl,f as nl,l as rl,n as il,o as al,p as ol,r as sl,u as cl}from"./image-loading-Dq1g_wpm.js";import{S as ll,a as ul,c as dl,g as fl,l as pl,o as ml,x as hl,y as gl}from"./dropdown-menu.styles-PdxueXzN.js";import{S as _l,b as vl,t as yl,x as bl}from"./MobileResizableSheet-F1zSUD1S.js";import{A as xl,C as Sl,D as Cl,E as wl,O as Tl,T as El,_ as Dl,a as Ol,b as kl,c as Al,d as jl,f as Ml,g as Nl,h as Pl,i as Fl,k as Il,l as Ll,m as Rl,o as zl,p as Bl,s as Vl,u as Hl,v as Ul,w as Wl,x as Gl,y as Kl}from"./sessionChangeSummary-CVUA1AFw.js";import{a as ql,i as Jl,o as Yl,s as Xl,u as Zl}from"./fileMentionTouchSelection-D7QtVxjI.js";import{C as Ql,E as $l,O as eu,S as tu,T as nu,a as ru,b as iu,c as au,d as ou,f as su,i as cu,l as lu,n as uu,o as du,p as fu,r as pu,s as mu,t as hu,u as gu,w as _u,x as vu,y as yu}from"./insertionBoundaries-CKQL85zy.js";import{C as bu,D as xu,E as Su,O as Cu,S as wu,T as Tu,_ as Eu,a as Du,b as Ou,c as ku,d as Au,f as ju,g as Mu,h as Nu,j as Pu,l as Fu,m as Iu,o as Lu,p as Ru,r as zu,s as Bu,t as Vu,u as Hu,v as Uu,w as Wu,x as Gu,y as Ku}from"./appThemeRegistry-BY5rY9-W.js";import{a as qu,n as Ju,o as Yu,r as Xu,t as Zu}from"./MarkdownRenderer-Y6uQXIFH.js";import{t as Qu}from"./OverlayScrollbar-wiRM4AGj.js";import{n as $u,r as ed}from"./textarea-vtIQM2iP.js";import{_ as td,a as nd,c as rd,g as id,l as ad,o as od,t as sd,v as cd,y as ld}from"./vendor-dnd-kit-core-B3g3zWQd.js";import{i as ud,n as dd,o as fd,s as pd,t as md}from"./vendor-dnd-kit-sortable-BKewx0Py.js";import{a as hd,n as gd,t as _d}from"./url-MRa-FtQa.js";import{a as vd,o as yd,t as bd,u as xd}from"./toolHelpers-iEHVHQ9p.js";import{t as Sd}from"./react-CURmDhtB.js";import{n as Cd,t as wd}from"./useEffectiveDirectory-Ci6Z13kj.js";import{t as Td}from"./ImageLoadingPlaceholder-DCWssLJG.js";import{t as Ed}from"./LoadingImage-C_Hryaqe.js";import{a as Dd,i as Od,l as kd,n as Ad,o as jd,r as Md,s as Nd,t as Pd}from"./FadeInOnReveal-BJA9Za3T.js";import{_ as Fd,a as Id,f as Ld,g as Rd,h as zd,i as Bd,m as Vd,o as Hd,r as Ud,s as Wd,t as Gd,v as Kd,y as qd}from"./useWorkerHighlightedLines-HKhuYGSj.js";import{n as Jd,r as Yd,t as Xd}from"./vendor-tanstack-react-virtual-BeZn51tF.js";import{t as Zd}from"./vendor-cmdk-C3oBVL9X.js";import{t as Qd}from"./sortable-tabs-strip-C1QmKFdb.js";import{a as $d}from"./markdownHeightCache-C1u0bWDL.js";import{n as ef}from"./markdownTheme-hpURsgju.js";import{t as tf}from"./vendor-motion-BmLx2V78.js";import{n as nf,t as rf}from"./useFontPreferences-DMiP_Yy-.js";var af=e=>{if(typeof e!=`string`)return;let t=e.trim();if(t)return{location:{directory:t}}};typeof window<`u`&&(window.__opencodeDebug={getLastAssistantMessage(){let e=Da.getState().currentSessionId;if(!e)return null;let t=Te(e);if(!t||t.length===0)return null;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`assistant`){let e=(pt(n.id)||[]).map(e=>{let t={id:e.id,type:e.type};return e.type===`text`?(t.text=e.text,t.textLength=e.text?.length||0):e.type===`tool`?(t.tool=e.tool,t.state=e.state?.status):(e.type===`step-start`||e.type===`step-finish`)&&(t.isStepMarker=!0),t}),t=e.some(e=>e.type===`text`&&e.text&&e.text.trim().length>0),r=e.some(e=>e.type===`tool`),i=e.some(e=>e.type===`step-start`||e.type===`step-finish`),a=e.length===0,o=!t&&!r&&(!a||i),s={messageId:n.id,role:n.role,timestamp:n.time?.created||0,partsCount:e.length,parts:e,isEmpty:a,isEmptyResponse:o,raw:n};return s.messageId,s.partsCount,s.isEmpty,s.isEmptyResponse,s.isEmpty&&console.warn(`[WARNING] Message has NO parts!`),s.isEmptyResponse&&(console.warn(`[WARNING] Message has parts but NO meaningful content (empty text, no tools)!`),i&&!t&&!r&&console.warn(`[CRITICAL] CLAUDE EMPTY RESPONSE BUG: Only step-start/step-finish markers, no actual content!`)),s}}return null},truncateString(e,t=80){return!e||typeof e!=`string`||e.length<=t?e:e.substring(0,t)+`…`},truncateMessages(e){return e.map(e=>({...e,parts:(pt(e.id)||[]).map(e=>{let t={...e};return`text`in e&&(t.text=this.truncateString(e.text)),`textPreview`in e&&(t.textPreview=this.truncateString(e.textPreview)),e.state&&(t.state={...e.state},`output`in e.state&&(t.state.output=this.truncateString(e.state.output)),`error`in e.state&&(t.state.error=this.truncateString(e.state.error)),e.state.metadata&&`preview`in e.state.metadata&&(t.state.metadata={...e.state.metadata,preview:this.truncateString(e.state.metadata.preview)})),t})}))},getAllMessages(e=!1){let t=Da.getState().currentSessionId;if(!t)return[];let n=Te(t);return`${n.length}`,n.forEach((e,t)=>{let n=pt(e.id)||[];`${t}${e.role}${e.id}${n.length}`}),e?this.truncateMessages(n):n},async getAppStatus(){let e=He.getState(),t=Da.getState(),n=pa.getState(),r=e.currentDirectory||null,i=se.getDirectory()??null,a=Ne(),o=new Set,s={};a.forEach(e=>{let t=e.directory;typeof t==`string`&&t.trim().length>0?(o.add(t),s[t]=(s[t]??0)+1):s[`(none)`]=(s[`(none)`]??0)+1});let c=(()=>{if(typeof window>`u`)return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem(`lastDirectory`),homeDirectory:window.localStorage.getItem(`homeDirectory`)}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}})(),l=S(),u=typeof window<`u`&&!!window.__YURI_ELECTRON__,d=async e=>{try{return await e.json()}catch{return null}},p=async e=>{try{return await e.text()}catch{return null}},m=async e=>{try{let t=await f(e);return t.ok?await d(t):{status:t.status}}catch(e){return{error:e instanceof Error?e.message:String(e)}}},h=null,g=null,_=null,v=null;try{let e=await se.getSdkClient().location.get(af(r));h=Ce(e)}catch(e){h={error:e instanceof Error?e.message:String(e)}}try{g=(await se.getSdkClient().location.get(af(r)))?.project??null}catch(e){g={error:e instanceof Error?e.message:String(e)}}_=await m(`/api/config/settings`);try{let e=await f(`/api/health`),t=e.headers.get(`content-type`)||``,n=await p(e),r=t.toLowerCase().includes(`application/json`),i=null;if(r&&n)try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)&&(i=e)}catch{i=null}v={status:e.status,ok:e.ok,contentType:t,type:r?`json`:`html`,openCodePort:i?.openCodePort??null,openCodeRunning:i?.openCodeRunning??null,openCodeSecureConnection:i?.openCodeSecureConnection??null,openCodeAuthSource:i?.openCodeAuthSource??null,isOpenCodeReady:i?.isOpenCodeReady??null,lastOpenCodeError:i?.lastOpenCodeError??null,preview:n?n.slice(0,120):null}}catch(e){v={error:e instanceof Error?e.message:String(e)}}let y={isGitRepo:null};if(r)try{y.isGitRepo=await ks(r)}catch(e){y={isGitRepo:null,error:e instanceof Error?e.message:String(e)}}let b=n.projects.map(e=>({id:e.id,path:e.path,label:e.label}));return{runtime:{platform:l?.runtime?.platform??null,isDesktop:u,isVSCode:!!l?.runtime?.isVSCode,hasRuntimeApis:!!l,desktopServerOrigin:null},location:typeof window<`u`?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:r,opencodeDirectory:h?.directory||h?.worktree||i,homeDirectory:e.homeDirectory||null,isHomeReady:e.isHomeReady,hasPersistedDirectory:e.hasPersistedDirectory,isSwitchingDirectory:e.isSwitchingDirectory},projects:{total:n.projects.length,activeProjectId:n.activeProjectId,samples:b},sessions:{total:a.length,currentSessionId:t.currentSessionId,lastLoadedDirectory:t.lastLoadedDirectory,uniqueDirectories:o.size,directorySamples:Array.from(o).slice(0,5),directoryCounts:s},worktrees:{available:t.availableWorktrees.length,metadataEntries:t.worktreeMetadata.size},git:y,localStorage:c,opencode:{pathInfo:h,projectInfo:g,health:v},yuri:{settingsInfo:_}}},async buildDiagnosticsReport(){let e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return Yn(e)},async copyDiagnosticsReport(){let e=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(e),report:e}},checkLastMessage(){let e=this.getLastAssistantMessage();if(!e)return!1;let t=e.isEmpty||e.isEmptyResponse;return t&&(console.error(`[ALERT] PROBLEMATIC MESSAGE DETECTED!`),e.messageId,e.isEmpty,e.isEmptyResponse,e.partsCount,e.parts.length>0&&e.parts),t},getStreamingState(){let e=Da.getState(),t=_i.getState(),n=e.currentSessionId?t.streamingMessageIds.get(e.currentSessionId)??null:null;return Array.from(t.streamingMessageIds.entries()),Array.from(t.messageStreamStates.entries()),{streamingMessageId:n,streamingMessageIds:t.streamingMessageIds,streamStates:t.messageStreamStates}},findEmptyMessages(){let e=Da.getState().currentSessionId;if(!e)return[];let t=Te(e).filter(e=>e.role===`assistant`).filter(e=>{let t=pt(e.id)||[],n=t.some(e=>e.type===`text`&&e.text&&e.text.trim().length>0),r=t.some(e=>e.type===`tool`);return t.length===0||!n&&!r});return`${t.length}`,t.forEach((e,t)=>{let n=pt(e.id)||[];`${t}`,e.id,n.length,e.providerID,e.modelID,e.time?.created}),t},showRetryHelp(){},analyzeMessageCompletionConsistency(e={}){let{includeNonAssistant:t=!1,verbose:n=!0,maxTableRows:r=25}=e,i=Da.getState().currentSessionId;if(!i)return{summary:null,rows:[]};let a=Te(i),o=t?a:a.filter(e=>e.role===`assistant`),s={totalMessages:a.length,analyzedMessages:o.length,completedMissing:0,completedBeforeTool:0,completedBeforeReasoning:0,runningToolsWhenCompleted:0,reasoningOpenWhenCompleted:0,withTools:0,withReasoning:0},c=e=>typeof e==`number`&&Number.isFinite(e)?e:null,l=e=>{let t=e.filter(e=>typeof e==`number`);return t.length>0?Math.max(...t):null},u=o.map((e,t)=>{let n=e,r=pt(e.id)||[],i=n.time??{},a=c(i.completed),o=a!==null,u=r.filter(e=>e.type===`tool`),d=r.filter(e=>e.type===`reasoning`),f=l(u.map(e=>c(e.state?.time?.end??e.state?.time?.start))),p=l(d.map(e=>c(e.time?.end??e.time?.start))),m=l([f,p].filter(e=>e!==null)),h=u.some(e=>[`pending`,`running`,`started`].includes(e.state?.status)),g=d.some(e=>typeof e.time?.end!=`number`);u.length>0&&(s.withTools+=1),d.length>0&&(s.withReasoning+=1),o||(s.completedMissing+=1);let _=!!(o&&typeof f==`number`&&a<f);_&&(s.completedBeforeTool+=1);let v=!!(o&&typeof p==`number`&&a<p);return v&&(s.completedBeforeReasoning+=1),o&&h&&(s.runningToolsWhenCompleted+=1),o&&g&&(s.reasoningOpenWhenCompleted+=1),{index:t,messageId:n.id,role:n.role,completedAt:a,latestToolTimestamp:f,latestReasoningTimestamp:p,latestPartTimestamp:m,completed_missing:!o,completed_before_tool:_,completed_before_reasoning:v,running_tools_when_completed:!!(o&&h),reasoning_open_when_completed:!!(o&&g),has_tools:u.length>0,has_reasoning:d.length>0}});return n&&(console.table(u.slice(0,r)),u.length>r&&`${r}${u.length}`),{summary:s,rows:u}},checkCompletionStatus(){let e=Da.getState().currentSessionId;if(!e)return null;let t=Te(e).filter(e=>e.role===`assistant`);if(t.length===0)return null;let n=t[t.length-1],r=(pt(n.id)||[]).filter(e=>e.type===`step-finish`),i=n.finish===`stop`,a=n.time?.completed,o=n.status,s=typeof a==`number`&&a>0||o===`completed`,c=!!(s&&i),l=_i.getState();n.sessionID&&l.streamingMessageIds.get(n.sessionID);let u=l.messageStreamStates.get(n.id);return n.id,n.id,u?.phase,{messageId:n.id,completed:a,status:o,hasCompletedFlag:s,hasStopReason:i,messageIsComplete:c,stepFinishParts:r,raw:n}}},je(),window.addEventListener(`error`,e=>{try{let t=e.message||``,n=e.filename||``;typeof t==`string`&&t.includes(`this._renderer.value.dimensions`)&&/xterm/i.test(String(n))&&e.preventDefault()}catch{}}));var Z=e(U(),1),Q=hn(),of=async()=>{if(typeof window>`u`)return;let e=null;try{e=Nt(`lastDirectory`)}catch(e){console.warn(`Failed to read saved directory preferences:`,e)}e&&!b()&&He.getState().setDirectory(e,{showOverlay:!1})},sf=new Map,cf=e=>sf.get(e)??null,lf=({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:i},a={})=>{let o=sf.get(e);if(o&&!a.force)return o;let s=(async()=>{o&&await o;try{await t()}catch(e){return i(`appearance`,e),!1}try{await Promise.all([n(),r()])}catch(e){i(`secondary`,e)}return!0})();return sf.set(e,s),s},uf=async({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,startWatchers:i,onError:a})=>{await lf({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:a})&&i()},df=(e,t=50)=>{let n=null,r;return{schedule:i=>{r=i,n&&clearTimeout(n),n=setTimeout(()=>{n=null;let t=r;r=void 0,t!==void 0&&e(t)},t)},cancel:()=>{n&&clearTimeout(n),n=null,r=void 0}}};function ff(e){return!e||e===`idle`?null:e===`ready`?`ok`:e===`error`?`unreachable`:`auth`}function pf(e,t){let n=e.via===`relay`;return t?n:!n}function mf(e){let{isActive:t,isSsh:n,runtimeIsConnected:r,runtimeConnectionPhase:i,currentTransportIsRelay:a,probe:o,sshPhase:s}=e,c;c=t?r&&i===`connected`?`ok`:`checking`:n?ff(s):o?.status??`checking`;let l=t?a:o?.via===`relay`,u=null;return!n&&c===`ok`&&o?.status===`ok`&&typeof o.latencyMs==`number`&&(!t||pf(o,a))&&(u=Math.max(0,Math.round(o.latencyMs))),{statusKind:c,showViaRelay:l,latencyMs:u}}var $=te(),hf=`local`,gf=9e4,_f=`SSH connection cancelled`,vf=e=>I(e),yf={},bf=e=>{let t=O(e);if(!t)return e.trim();try{let e=new URL(t);return e.pathname.endsWith(`/`)||(e.pathname=`${e.pathname}/`),e.toString()}catch{return t}},xf=()=>typeof window>`u`?``:window.__YURI_LOCAL_ORIGIN__||window.location.origin,Sf=async()=>m()?A().catch(()=>``):``,Cf=e=>e===`ok`?`bg-status-success`:e===`auth`||e===`update-recommended`?`bg-status-warning`:e===`incompatible`||e===`wrong-service`||e===`unreachable`?`bg-status-error`:e===`checking`?`bg-status-info`:`bg-muted-foreground/40`,wf=e=>e===`ok`?`text-[var(--status-success)]`:e===`auth`||e===`update-recommended`?`text-[var(--status-warning)]`:e===`incompatible`||e===`wrong-service`||e===`unreachable`?`text-[var(--status-error)]`:`text-muted-foreground`,Tf=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Ef=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Df=e=>e===`ok`?`desktopHostSwitcher.status.connected`:e===`auth`?`desktopHostSwitcher.status.authRequired`:e===`checking`?`desktopHostSwitcher.status.checking`:e===`update-recommended`?`desktopHostSwitcher.status.updateRecommended`:e===`incompatible`?`desktopHostSwitcher.status.incompatible`:e===`wrong-service`?`desktopHostSwitcher.status.wrongService`:e===`unreachable`?`desktopHostSwitcher.status.unreachable`:`desktopHostSwitcher.status.unknown`,Of=e=>new Promise(t=>window.setTimeout(t,e)),kf=e=>{switch(e){case`ready`:return`desktopHostSwitcher.sshPhase.ready`;case`error`:return`desktopHostSwitcher.sshPhase.error`;case`degraded`:return`desktopHostSwitcher.sshPhase.reconnecting`;case`config_resolved`:return`desktopHostSwitcher.sshPhase.resolvingConfig`;case`auth_check`:return`desktopHostSwitcher.sshPhase.checkingAuth`;case`master_connecting`:return`desktopHostSwitcher.sshPhase.connectingSsh`;case`remote_probe`:return`desktopHostSwitcher.sshPhase.probingRemote`;case`installing`:return`desktopHostSwitcher.sshPhase.installing`;case`updating`:return`desktopHostSwitcher.sshPhase.updating`;case`server_detecting`:return`desktopHostSwitcher.sshPhase.detectingServer`;case`server_starting`:return`desktopHostSwitcher.sshPhase.startingServer`;case`forwarding`:return`desktopHostSwitcher.sshPhase.forwardingPorts`;default:return`desktopHostSwitcher.sshPhase.idle`}},Af=async()=>{let e=await yc().catch(()=>[]),t={};for(let n of e)t[n.id]=n;return t},jf=async(e,t,n,r)=>{let i=Date.now()+t;for(;Date.now()<i;){if(r?.())throw Error(_f);let t=(await yc(e).catch(()=>[])).find(t=>t.id===e);if(t){if(n(t),t.phase===`ready`)return t;if(t.phase===`error`)throw Error(t.detail||`SSH connection failed`)}await Of(700)}throw r?.()?Error(_f):Error(`Timed out waiting for SSH connection`)},Mf=e=>({id:hf,label:`Local`,url:e||xf()}),Nf=e=>{let t=typeof window>`u`?``:window.location.href,n=e.find(e=>e.id===hf)?.url||xf(),r=d(),i=O(n)||n,a=O(t)||t,o=u(),s=e.find(e=>e.relay&&vf(e)===o);if(s)return{id:s.id,label:s.label,url:s.url};if(r&&j(r,n))return{id:hf,label:`Local`,url:i};let c=e.find(e=>r?j(r,P(e)):!1);if(c)return{id:c.id,label:c.label,url:O(P(c))||P(c)};if(t&&j(t,n))return{id:hf,label:`Local`,url:i};let l=e.find(e=>t?j(t,e.url):!1);return l?{id:l.id,label:l.label,url:O(l.url)||l.url}:t.startsWith(`yuri-ui://`)?{id:hf,label:`Local`,url:i}:{id:`custom`,label:T(a||`Instance`),url:a}};function Pf({open:e,onOpenChange:t,embedded:n=!1,onHostSwitched:r,onBusyChange:a}){let{t:s}=Xn(),c=K(e=>e.setSettingsDialogOpen),l=K(e=>e.setSettingsPage),u=ni(e=>e.isConnected),d=ni(e=>e.connectionPhase),[f,p]=Z.useState([]),[h,g]=Z.useState(null),[_,v]=Z.useState(()=>({...yf}));Z.useEffect(()=>{Object.assign(yf,_)},[_]);let[y,b]=Z.useState(!1),[S,A]=Z.useState(!1),[j,I]=Z.useState(!1),L=Oc(),R=Wc(),[z,B]=Z.useState(null),V=z||R,H=Z.useRef(!1),U=J(e=>{H.current=e!==null,B(e),a?.(e!==null)}),[W,ee]=Z.useState({}),[te,ne]=Z.useState({}),[re,G]=Z.useState({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),[ie,ae]=Z.useState(``),[oe,se]=Z.useState(()=>xf()),[ce,le]=Z.useState(null),[ue,de]=Z.useState(``),[fe,pe]=Z.useState(``),[me,he]=Z.useState(0),ge=Z.useRef(0),_e=Z.useMemo(()=>[Mf(oe),...f.map(e=>({...e,url:O(e.url)||e.url}))],[f,oe]),ve=Z.useMemo(()=>new Set(Object.keys(W)),[W]),ye=Z.useMemo(()=>_e.filter(e=>e.id===hf||w(e,ve)),[_e,ve]);Z.useEffect(()=>i(()=>he(e=>e+1)),[]);let be=Z.useMemo(()=>Nf(_e),[_e,me]),xe=Z.useMemo(()=>o().startsWith(`relay:`),[me]),Se=Z.useMemo(()=>{let e=h||hf;return _e.find(t=>t.id===e)?.label||s(`desktopHostSwitcher.instance.local`)},[_e,h,s]),Ce=Z.useCallback(async(e,t)=>{if(x()){I(!0),ae(``);try{let n=e.filter(e=>e.id!==hf);await D({hosts:n,defaultHostId:t}),p(n),g(t)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToSave`))}finally{I(!1)}}},[s]),we=Z.useCallback(()=>{l(`remote-instances`),c(!0),t(!1)},[t,c,l]),Te=Z.useCallback(async()=>{if(x()){b(!0),ae(``);try{let[e,t,n]=await Promise.all([M(),fc().catch(()=>({instances:[]})),Af()]);e.localOrigin&&se(e.localOrigin);let r={};for(let e of t.instances)r[e.id]=!0;p(e.hosts||[]),g(e.defaultHostId??null),ee(r),ne(n)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToLoad`)),p([]),g(null),ee({}),ne({})}finally{b(!1)}}},[s]),Ee=Z.useCallback(async e=>{if(x()){A(!0);try{let t=await Sf(),n=await Promise.all(e.map(async e=>{let n=async()=>{let t=await E(e.relay,{clientToken:e.clientToken||null}).catch(()=>({status:`unreachable`,latencyMs:0}));return{status:t.status,latencyMs:t.latencyMs,...t.status===`ok`?{via:`relay`}:{}}};if(e.relay&&!e.apiUrl)return[e.id,await n()];let r=O(m()?P(e):e.url);if(!r)return[e.id,{status:`unreachable`,latencyMs:0}];let i=e.id===hf?t:e.clientToken||``,a=await k(r,{clientToken:i||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(Tf(a.status)&&e.relay){let t=await n();if(t.status===`ok`)return[e.id,t]}return[e.id,{status:a.status,latencyMs:a.latencyMs}]})),r={};for(let[e,t]of n)r[e]=t;v(r)}finally{A(!1)}}},[]);Z.useEffect(()=>{if(!e){le(null),de(``),pe(``),B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),ae(``);return}Te()},[e,Te]),Z.useEffect(()=>{e&&Ee(ye)},[e,ye,Ee]),Z.useEffect(()=>{if(!e||!x())return;let t=!1,n=async()=>{let e=await Af();t||ne(e)};n();let r=window.setInterval(()=>{typeof document<`u`&&document.visibilityState!==`visible`||n()},1500);return()=>{t=!0,window.clearInterval(r)}},[e]);let De=J(async e=>{if(H.current||L)return;let t=e.id===hf?oe:O(e.url)||``,n=e.id===hf?oe:O(P(e))||``,i=!!e.relay&&!e.apiUrl&&e.id!==hf;if(!t&&!i)return;if(m()){if(!n&&!e.relay||L)return;U(e.id);try{let t=e.id===hf?await Sf():null,i=await Fc({host:e,inlineProgress:!0,cachedProbe:_[e.id]||null,...e.id===hf?{localApiOrigin:n,localClientToken:t}:{}});v(t=>({...t,[e.id]:i.status})),i.ok&&r?.()}finally{U(null)}return}let a=!!W[e.id];if(e.id!==hf&&a&&x()){let n=te[e.id],i=await yc(e.id).then(t=>t.find(t=>t.id===e.id)||null).catch(()=>null);i&&(n=i,ne(t=>({...t,[e.id]:i})));let a=O(n?.localUrl||e.url||``);if(n?.phase===`ready`&&a){let e=bf(a);r?.(),window.location.assign(e);return}B(e.id);let o=ge.current+1;ge.current=o,G({open:!0,hostId:e.id,hostLabel:T(e.label),phase:`master_connecting`,detail:null,error:null,errorCode:null});try{if(await cc(e.id),o!==ge.current)return;let n=await jf(e.id,gf,e=>{ne(t=>({...t,[e.id]:e})),G(t=>({...t,phase:e.phase,detail:e.detail||null,errorCode:e.errorCode||null}))},()=>o!==ge.current);if(o!==ge.current)return;let i=bf(O(n.localUrl||``)||t);r?.(),window.location.assign(i);return}catch(t){if(o!==ge.current)return;let n=t instanceof Error?t.message:String(t);if(n===_f)return;let r=ac(re.errorCode,n);G(e=>({...e,error:n,errorCode:r})),Yr.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Zc(s(Cc(r)),r,n)});return}finally{o===ge.current&&B(null)}}if(e.id!==hf&&x()){B(e.id);let n=await k(t,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(v(t=>({...t,[e.id]:{status:n.status,latencyMs:n.latencyMs}})),Tf(n.status)){Yr.error(s(`desktopHostSwitcher.toast.instanceUnreachable`,{host:T(e.label)})),B(null);return}}let o=bf(t);r?.();try{window.location.assign(o)}catch{window.location.href=o}}),Oe=Z.useCallback(()=>{le(null),de(``),pe(``)},[]),ke=Z.useCallback(e=>{e.stopPropagation()},[]),Ae=Z.useCallback(async()=>{if(!ce)return;if(ce===hf){Oe();return}let e=F(fe);if(!e){ae(s(`desktopHostSwitcher.error.invalidUrl`));return}let t=e.persistedUrl,n=(ue||T(t)).trim(),r=f.map(e=>e.id===ce?{...e,label:n,url:t,apiUrl:t}:e);await Ce(r,h),Oe(),e.redeemUrl&&window.location.assign(e.redeemUrl)},[Oe,f,h,ue,fe,ce,Ce,s]),je=Z.useCallback(async e=>{await Ce(f,e===hf?hf:e)},[f,Ce]),Me=J(async e=>{if(H.current||L)return;U(e.id);let t=e=>{Yr.error(s(`desktopHostSwitcher.error.failedToOpenNewWindow`),{description:e instanceof Error?e.message:String(e)})};try{if(e.relay&&e.id!==hf)await C(e.id);else{let t=e.id===hf?oe:P(e);if(!t)return;let n=bf(t);await N(n,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null})}r?.()}catch(e){t(e)}finally{U(null)}}),Ne=J(async()=>{ge.current+=1,B(null),G(e=>({...e,open:!1,hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}));let e=bf(oe);if(m()){if(L)return;let e=await Sf();(await Fc({host:Mf(oe),localApiOrigin:oe,localClientToken:e})).ok&&r?.();return}r?.(),window.location.assign(e)}),Pe=Z.useCallback(async()=>{let e=re.hostId||V;ge.current+=1,B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),!(!e||e===hf||!x())&&await mc(e).catch(()=>{})},[re.hostId,V]),Fe=Z.useCallback(()=>{let e=re.hostId;if(!e)return;let t=_e.find(t=>t.id===e);t&&De(t)},[_e,De,re.hostId]),Ie=J(async e=>{if(!(!x()||H.current||L)){U(e.id);try{await cc(e.id),(await jf(e.id,gf,e=>{ne(t=>({...t,[e.id]:e}))})).phase===`ready`&&Yr.success(s(`desktopHostSwitcher.toast.sshConnected`,{host:T(e.label)}))}catch(t){let n=t instanceof Error?t.message:String(t);if(n!==_f){let t=ac(null,n);Yr.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Zc(s(Cc(t)),t,n)})}}finally{U(null)}}});if(!x())return null;let Le=x(),Re=(0,$.jsxs)($.Fragment,{children:[n?(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-[var(--interactive-border)] px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex items-baseline gap-1.5 typography-ui-label`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.current`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`•`}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.default`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(Se)})]}),(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors`,`hover:text-foreground hover:bg-interactive-hover`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),onClick:()=>void Ee(ye),disabled:!Le||y||S,"aria-label":s(`desktopHostSwitcher.actions.refreshInstancesAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)})})]})}):(0,$.jsxs)(xs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ws,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`server`,className:`h-5 w-5`}),s(`desktopHostSwitcher.title`)]}),(0,$.jsx)(Ts,{children:s(`desktopHostSwitcher.description`)})]}),!n&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentDefaultColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(Se)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsxs)(er,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Ee(ye),disabled:!Le||y||S,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)}),s(`desktopHostSwitcher.actions.refresh`)]})})]}),!Le&&(0,$.jsx)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.state.limitedOnPage`)})}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:Y(`space-y-1`,n&&`space-y-1.5 px-3 py-1`),children:y?(0,$.jsx)(`div`,{className:`px-2 py-2 text-muted-foreground text-sm`,children:s(`desktopHostSwitcher.state.loading`)}):ye.map(e=>{let t=e.id===hf,r=!!W[e.id],i=e.id===be.id,a=(h||hf)===e.id,o=_[e.id]||null,c=te[e.id]||null,l=mf({isActive:i,isSsh:r,runtimeIsConnected:u,runtimeConnectionPhase:d,currentTransportIsRelay:xe,probe:o,sshPhase:c?.phase}),f=l.statusKind,p=l.showViaRelay,m=ce===e.id,g=t?oe:O(e.url)||e.url,v=e.id===hf?s(`desktopHostSwitcher.instance.local`):T(e.label),y=e.relay&&!e.apiUrl?s(`mobile.connect.relay.badge`):T(g);return(0,$.jsxs)(`div`,{className:Y(`app-region-no-drag group flex items-center gap-2 px-2.5 py-2 rounded-md overflow-hidden`,n&&`rounded-xl bg-[var(--surface-muted)] px-3 py-2.5`,n&&i&&`bg-[var(--interactive-selection)]/25`,m?`bg-interactive-hover/20`:`hover:bg-interactive-hover/30`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-2 flex-1 min-w-0 text-left`,m&&`pointer-events-none opacity-70`),onClick:()=>void De(e),disabled:!!V,"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.switchToAria`,{instance:v}),children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,$.jsx)(`span`,{className:Y(`h-2 w-2 rounded-full flex-shrink-0`,Cf(f))}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium truncate text-foreground`,children:v}),i&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 text-muted-foreground bg-muted px-1 rounded leading-none pb-px border border-border/50`,children:s(`desktopHostSwitcher.header.current`)}),r&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 px-1 rounded leading-none pb-px text-[var(--status-info)] bg-[var(--status-info)]/10`,children:`SSH`})]}),(0,$.jsxs)(`div`,{className:Y(`typography-micro truncate`,wf(f)),children:[r&&(!i||V===e.id)?s(kf(c?.phase)):s(Df(f)),l.latencyMs==null?``:s(`desktopHostSwitcher.status.ping`,{ms:l.latencyMs}),p?` · ${s(`settings.remoteInstances.clientAuth.state.viaRelay`)}`:``]}),(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70 truncate font-mono`,children:y})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[r&&!t&&(c?.phase===`idle`||!c?.phase?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 px-2.5`,disabled:!!V,onClick:t=>{t.stopPropagation(),Ie(e)},children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(X,{name:`plug-2`,className:`h-3.5 w-3.5`}),s(`desktopHostSwitcher.actions.connect`)]}):(0,$.jsx)(`div`,{className:`h-8 w-8 opacity-0 pointer-events-none`,"aria-hidden":`true`})),(0,$.jsxs)(tc,{delayDuration:600,children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`app-region-no-drag h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors`,a?`text-primary hover:text-primary/80`:`text-muted-foreground/60 hover:text-primary/80`),onClick:()=>void je(e.id),"aria-label":s(a?`desktopHostSwitcher.actions.defaultInstanceAria`:`desktopHostSwitcher.actions.setAsDefaultAria`),disabled:j||!a&&Ef(f),children:a?(0,$.jsx)(X,{name:`star-fill`,className:`h-4 w-4`}):(0,$.jsx)(X,{name:`star`,className:`h-4 w-4`})})}),(0,$.jsx)(ec,{sideOffset:6,children:s(a?`desktopHostSwitcher.header.default`:`desktopHostSwitcher.actions.setAsDefault`)})]}),(0,$.jsxs)(tc,{delayDuration:600,children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`app-region-no-drag h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors`,Ef(f)?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground/60 hover:text-foreground`),onClick:t=>{t.stopPropagation(),Me(e)},disabled:!!V||Ef(f),"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.openInNewWindowAria`),children:(0,$.jsx)(X,{name:V===e.id?`loader-4`:`window`,className:Y(`h-4 w-4`,V===e.id&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:Ef(f)?s(`desktopHostSwitcher.state.instanceUnreachable`):s(`desktopHostSwitcher.actions.openInNewWindow`)})]})]})]},e.id)})})}),Le&&ce&&ce!==hf&&(0,$.jsxs)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground`,children:s(`desktopHostSwitcher.edit.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(er,{type:`button`,variant:`outline`,size:`sm`,onClick:Oe,disabled:j,children:s(`desktopHostSwitcher.actions.cancel`)}),(0,$.jsxs)(er,{type:`button`,size:`sm`,onClick:()=>void Ae(),disabled:j,children:[j?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):null,s(`desktopHostSwitcher.actions.save`)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,$.jsx)(Qs,{value:ue,onChange:e=>de(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.labelPlaceholder`),disabled:j}),(0,$.jsx)(Qs,{value:fe,onChange:e=>pe(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.urlPlaceholder`),disabled:j})]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 border-t border-[var(--interactive-border)]`,children:(0,$.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-2 py-2 text-left text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,onClick:we,disabled:!!V,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:s(`desktopHostSwitcher.actions.addInstance`)})]})}),ie&&(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-status-error`,children:ie})]}),ze=(0,$.jsx)(Ds,{open:re.open,onOpenChange:e=>{if(!e&&V){Pe();return}G(t=>({...t,open:e,...e?{}:{hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}}))},children:(0,$.jsxs)(Cs,{className:`w-[min(28rem,calc(100vw-2rem))] max-w-none`,children:[(0,$.jsxs)(xs,{children:[(0,$.jsxs)(ws,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(`h-4 w-4`,!re.error&&`animate-spin`)}),s(`desktopHostSwitcher.ssh.connectingTo`,{host:re.hostLabel||s(`desktopHostSwitcher.ssh.instanceFallback`)})]}),re.error?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ts,{className:`sr-only`,children:s(uc(ac(re.errorCode,re.error)))}),(0,$.jsx)(xc,{errorCode:re.errorCode,detail:re.error})]}):(0,$.jsx)(Ts,{children:re.detail||s(kf(re.phase))})]}),re.error?(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{we(),Pe()},children:s(`desktopHostSwitcher.sshError.openRemoteSettings`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void Ne(),children:s(`desktopHostSwitcher.actions.switchToLocal`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,onClick:Fe,disabled:!re.hostId,children:s(`desktopHostSwitcher.actions.retry`)})]}):null]})});return n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-full max-h-[70vh] flex flex-col overflow-hidden gap-2`,children:Re}),ze]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ds,{open:e,onOpenChange:e=>{!e&&H.current||t(e)},children:(0,$.jsx)(Cs,{className:`w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3`,children:Re})}),ze]})}function Ff(){let e=(0,Q.c)(11),[t,n]=Z.useState(!1),{t:r}=Xn();if(!x())return null;let i,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>n(!0),a=(0,$.jsx)(X,{name:`server`,className:`h-4 w-4`}),e[0]=i,e[1]=a):(i=e[0],a=e[1]);let o;e[2]===r?o=e[3]:(o=r(`desktopHostSwitcher.actions.switchInstance`),e[2]=r,e[3]=o);let s;e[4]===o?s=e[5]:(s=(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,"data-yuri-host-switcher":!0,className:`w-full justify-center`,onClick:i,children:[a,o]}),e[4]=o,e[5]=s);let c;e[6]===t?c=e[7]:(c=(0,$.jsx)(Pf,{open:t,onOpenChange:n}),e[6]=t,e[7]=c);let l;return e[8]!==s||e[9]!==c?(l=(0,$.jsxs)($.Fragment,{children:[s,c]}),e[8]=s,e[9]=c,e[10]=l):l=e[10],l}var If=e=>e.shouldUseDesktopShellPasswordLogin?`locked`:`error`,Lf=`/auth/session`,Rf=4,zf=1500,Bf=`yuri.uiAuth.trustDevice`,Vf=`desktop-local`,Hf=`desktop-local`,Uf=()=>{if(typeof window>`u`)return``;let e=window.__YURI_LOCAL_ORIGIN__;return typeof e==`string`?e.trim():``},Wf=(e,t)=>{let n=O(e),r=O(t);if(!n||!r)return!1;try{return new URL(n).origin===new URL(r).origin}catch{return!1}},Gf=()=>x(),Kf=e=>{let t=e.replace(/^\[|\]$/g,``);return t===`localhost`||t===`127.0.0.1`||t===`::1`},qf=()=>{if(!x())return!1;let e=Uf();if(!e)return!1;let t=d()||(typeof window<`u`?window.location.origin:``);if(Wf(e,t))return!0;try{let e=O(t);return!!(e&&Kf(new URL(e).hostname))}catch{return!1}},Jf=()=>qf()?{clientKind:Vf,dedupeKey:Hf}:{},Yf=async()=>await f(Lf,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}}),Xf=()=>typeof window>`u`?!1:window.localStorage.getItem(Bf)===`true`,Zf=async(e,t)=>{let n=Gf();return await f(Lf,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({password:e,trustDevice:t,issueClientToken:n,clientLabel:`Yuri Desktop`,...Jf()})})},Qf=async()=>{if(!x())return``;let e=await f(`/api/client-auth/clients`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:`Yuri Desktop`,...Jf()})}).catch(()=>null);if(!e?.ok)return``;let t=await e.json().catch(()=>null);return typeof t?.token==`string`?t.token.trim():``},$f=()=>x()&&!qf(),ep=async(e,t)=>{if(!x()||typeof window>`u`)return null;let r=await y(`desktop_remote_password_login`,{url:d(),password:e,trustDevice:t,requestHeaders:n()}).catch(()=>null);if(!r||typeof r!=`object`)return null;let i=r.token,a=r.status;return{token:typeof i==`string`?i.trim():``,...typeof a==`number`?{status:a}:{}}},tp=async(e,t)=>{if(!x()||!t)return;let n=await M().catch(()=>null);if(!n)return;if(n.localOrigin&&Wf(n.localOrigin,e)){await D({hosts:n.hosts,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted,localClientToken:t}).catch(()=>void 0);return}let r=!1,i=n.hosts.map(n=>!Wf(P(n),e)||n.clientToken===t?n:(r=!0,{...n,clientToken:t}));r&&await D({hosts:i,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted}).catch(()=>void 0)},np=async e=>{if(!e)return;let r=d(),i=n();await tp(r,e),s({apiBaseUrl:r,clientToken:e,requestHeaders:Object.keys(i).length>0?i:null,relay:t()})},rp=e=>{let t=(0,Q.c)(7),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={height:`var(--yuri-wco-titlebar-height, 0px)`,right:`var(--yuri-wco-right-inset, 0px)`},t[0]=r):r=t[0];let i=r,a,o;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a={fontFamily:`"Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif`},o=(0,$.jsx)(`div`,{className:`app-region-drag fixed left-0 top-0 z-20`,style:i,"aria-hidden":!0}),t[1]=a,t[2]=o):(a=t[1],o=t[2]);let s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-55`,style:{background:`radial-gradient(120% 140% at 50% -20%, var(--surface-overlay) 0%, transparent 68%)`}}),t[3]=s):s=t[3];let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,style:{backgroundColor:`var(--surface-subtle)`,opacity:.22}}),t[4]=c):c=t[4];let l;return t[5]===n?l=t[6]:(l=(0,$.jsxs)(`div`,{className:`relative flex min-h-screen items-center justify-center overflow-hidden bg-background text-foreground`,style:a,children:[o,s,c,(0,$.jsx)(`div`,{className:`app-region-no-drag relative z-10 flex w-full justify-center px-4 py-12 sm:px-6`,children:n})]}),t[5]=n,t[6]=l),l},ip=()=>{let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background text-foreground`,children:(0,$.jsx)(Qc,{width:120,height:120})}),e[0]=t):t=e[0],t},ap=e=>{let t=(0,Q.c)(23),{onRetry:n,errorType:r,retryAfter:i,children:a}=e,o=r===void 0?`network`:r,{t:s}=Xn(),c=o===`rate-limit`,l=i?Math.ceil(i/60):1,u;t[0]!==c||t[1]!==s?(u=s(c?`sessionAuth.error.rateLimitTitle`:`sessionAuth.error.networkTitle`),t[0]=c,t[1]=s,t[2]=u):u=t[2];let d;t[3]===u?d=t[4]:(d=(0,$.jsx)(`h1`,{className:`typography-ui-header font-semibold text-destructive`,children:u}),t[3]=u,t[4]=d);let f;t[5]!==c||t[6]!==l||t[7]!==s?(f=c?s(l>1?`sessionAuth.error.rateLimitDescriptionPlural`:`sessionAuth.error.rateLimitDescriptionSingle`,{minutes:l}):s(`sessionAuth.error.networkDescription`),t[5]=c,t[6]=l,t[7]=s,t[8]=f):f=t[8];let p;t[9]===f?p=t[10]:(p=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground max-w-xs`,children:f}),t[9]=f,t[10]=p);let m;t[11]!==d||t[12]!==p?(m=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[d,p]}),t[11]=d,t[12]=p,t[13]=m):m=t[13];let h;t[14]===s?h=t[15]:(h=s(`sessionAuth.error.retry`),t[14]=s,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(er,{type:`button`,onClick:n,className:`w-full max-w-xs`,children:h}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;return t[19]!==a||t[20]!==m||t[21]!==g?(_=(0,$.jsx)(rp,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[m,g,a]})}),t[19]=a,t[20]=m,t[21]=g,t[22]=_):_=t[22],_},op=({children:e})=>{let{t}=Xn(),n=Z.useMemo(()=>b(),[]),r=n,a=Z.useMemo(()=>x()&&!n,[n]),[o,s]=Z.useState(()=>r?`authenticated`:`pending`),[c,d]=Z.useState(``),[f,p]=Z.useState(!1),[m,h]=Z.useState(``),[g,_]=Z.useState(void 0),[v,y]=Z.useState(!1),[S,C]=Z.useState(rc),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(()=>Xf()),[A,j]=Z.useState(null),[M,N]=Z.useState(r),P=Z.useRef(null),F=Z.useRef(r);Z.useEffect(()=>{typeof window>`u`||window.localStorage.setItem(Bf,O?`true`:`false`)},[O]);let I=Z.useCallback(async()=>{if(r)return rc;try{let e=await Lc();return C(e),e}catch{return C(rc),rc}},[r]);Z.useEffect(()=>{let e=!1;if(!r)return(async()=>{try{if(!window.isSecureContext||!As()){e||T(!1);return}e||T(!0)}catch{e||T(!1)}})(),()=>{e=!0}},[r]);let L=Z.useRef(0),R=Z.useRef(null),z=Z.useRef(null),B=Z.useCallback(()=>{R.current!==null&&(window.clearTimeout(R.current),R.current=null)},[]),V=Z.useCallback(()=>{L.current=0,B()},[B]),H=Z.useCallback(()=>L.current>=Rf?!1:(L.current+=1,B(),R.current=window.setTimeout(()=>{R.current=null,z.current?.()},zf*L.current),!0),[B]);Z.useEffect(()=>B,[B]);let U=Z.useCallback(async()=>{if(r){s(`authenticated`);return}s(e=>e===`authenticated`?e:`pending`);try{let[e,t]=await Promise.all([Yf(),I()]),n=await e.text();if(e.ok){V(),s(`authenticated`),y(!1),h(``),_(void 0);return}if(e.status===401){let e={};try{e=JSON.parse(n)}catch{e={}}V(),y(e.tunnelLocked===!0),C(t),s(`locked`),_(void 0);return}if(e.status===429){let e={};try{e=JSON.parse(n)}catch{e={}}V(),_(e.retryAfter),y(!1),s(`rate-limited`);return}if(H())return;s(`error`),y(!1)}catch(e){if(console.warn(`Failed to check session status:`,e),If({shouldUseDesktopShellPasswordLogin:$f()})===`locked`){s(`locked`),_(void 0),y(!1);return}if(H())return;s(`error`),y(!1)}},[I,V,H,r]);Z.useEffect(()=>{z.current=U},[U]),Z.useEffect(()=>{r||U()},[U,r]),Z.useEffect(()=>{if(o===`pending`||o===`authenticated`||typeof document>`u`)return;let e=document.getElementById(`initial-loading`);if(!e)return;e.classList.add(`fade-out`);let t=window.setTimeout(()=>{e.remove()},300);return()=>{window.clearTimeout(t)}},[o]),Z.useEffect(()=>{if(r)return;let e=df(e=>{l(e)&&(d(``),h(``),_(void 0),y(!1),V(),N(!1),F.current=!1,s(`pending`),U())}),t=i(t=>e.schedule(t));return()=>{t(),e.cancel()}},[U,V,r]),Z.useEffect(()=>{!r&&o===`locked`&&(F.current=!1,N(!1))},[r,o]),Z.useEffect(()=>{o===`locked`&&P.current&&(P.current.focus(),P.current.select())},[o]),Z.useEffect(()=>{if(!r&&o===`authenticated`&&!F.current){F.current=!0;let e=!1;return lf({runtimeKey:u(),initializeAppearance:sn,syncSettings:rn,applyDirectory:of,onError:(e,t)=>{console.error(`[SessionAuthGate] ${e} settings hydration failed:`,t)}},{force:!0}).then(()=>{e||N(!0)}),()=>{e=!0}}},[r,o]);let W=async e=>{e.preventDefault(),await ne(!1)},ee=Z.useCallback(async()=>{j(`register`),D(!0);try{await sc()}finally{j(null),D(!1)}await I()},[I]),te=Z.useCallback(()=>{Rc(),j(null),D(!1)},[]),ne=Z.useCallback(async e=>{if(!v&&!(!c||f)){E&&te(),p(!0),h(``);try{if($f()){let e=await ep(c,O);if(e?.token){d(``),y(!1),await np(e.token),s(`authenticated`);return}if(e?.status===401){h(t(`sessionAuth.error.incorrectPassword`)),y(!1),s(`locked`);return}if(e?.status===429){_(void 0),y(!1),s(`rate-limited`);return}}let n=await Zf(c,O);if(n.ok){let r=await n.json().catch(()=>null),i=Gf(),a=``;if(i&&(a=typeof r?.clientToken==`string`&&r.clientToken.trim()?r.clientToken.trim():``,a||=(await ep(c,O))?.token||await Qf()),d(``),y(!1),a&&await np(a),e&&w)try{await ee(),Yr.success(t(`sessionAuth.toast.passkeyAdded`)),s(`authenticated`);return}catch(e){if(_c(e))Yr.message(t(`sessionAuth.toast.passkeySetupCanceled`));else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);Yr.error(n)}s(`authenticated`);return}s(`authenticated`);return}if(n.status===401){h(t(`sessionAuth.error.incorrectPassword`)),y(!1),s(`locked`);return}if(n.status===429){let e=await n.json().catch(()=>({}));_(e.retryAfter),y(!1),s(`rate-limited`);return}h(t(`sessionAuth.error.unexpectedResponse`)),y(!1),s(`error`)}catch(e){console.warn(`Failed to submit UI password:`,e);let n=$f()?await ep(c,O):null;if(n?.token){d(``),y(!1),await np(n.token),s(`authenticated`);return}if(n?.status===401){h(t(`sessionAuth.error.incorrectPassword`)),y(!1),s(`locked`);return}if(n?.status===429){_(void 0),y(!1),s(`rate-limited`);return}h(t(`sessionAuth.error.networkRetry`)),y(!1),s(`error`)}finally{p(!1)}}},[te,E,f,v,c,ee,w,t,O]),re=Z.useCallback(async()=>{if(!(f||!w)){if(E){te();return}D(!0),j(`auth`),h(``);try{let e=await gc(O,{issueClientToken:Gf(),clientLabel:`Yuri Desktop`,...Jf()}),t=Gf()&&typeof e?.clientToken==`string`&&e.clientToken.trim()?e.clientToken.trim():``;t&&await np(t),d(``),s(`authenticated`)}catch(e){if(_c(e))h(``);else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySignInCanceled`);h(n)}}finally{j(null),D(!1)}}},[te,E,f,w,t,O]),G=Z.useCallback(async()=>{if(!(f||v||!w)){if(E){te();return}if(o!==`authenticated`){if(!c){h(t(`sessionAuth.error.enterPasswordForPasskey`));return}await ne(!0);return}h(``);try{await ee(),Yr.success(t(`sessionAuth.toast.passkeyAdded`))}catch(e){if(_c(e)){Yr.message(t(`sessionAuth.toast.passkeySetupCanceled`));return}let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);Yr.error(n)}}},[te,ne,E,f,v,c,ee,o,w,t]),ie=w&&S.enabled,ae=ie&&S.hasPasskeys;return o===`pending`||o===`authenticated`&&!M?(0,$.jsx)(ip,{}):o===`error`?(0,$.jsx)(ap,{onRetry:()=>{V(),U()},errorType:`network`,children:a&&(0,$.jsxs)(`div`,{className:`w-full max-w-xs`,children:[(0,$.jsx)(Ff,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})}):o===`rate-limited`?(0,$.jsx)(ap,{onRetry:()=>void U(),errorType:`rate-limit`,retryAfter:g}):o===`locked`?(0,$.jsx)(rp,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 w-full max-w-xs`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-1 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:t(v?`sessionAuth.locked.tunnelTitle`:`sessionAuth.locked.unlockTitle`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(v?`sessionAuth.locked.tunnelDescription`:`sessionAuth.locked.passwordDescription`)})]}),!v&&(0,$.jsxs)(`form`,{onSubmit:W,className:`w-full space-y-2`,children:[ae&&(0,$.jsxs)(er,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>void re(),disabled:f||E&&A!==`auth`,children:[E?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:t(E&&A===`auth`?`sessionAuth.actions.cancelPasskey`:`sessionAuth.actions.usePasskey`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(X,{name:`lock`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60`}),(0,$.jsx)(Qs,{id:`yuri-ui-password`,ref:P,type:`password`,autoComplete:`current-password`,placeholder:t(`sessionAuth.password.placeholder`),value:c,onChange:e=>{d(e.target.value),m&&h(``)},className:`pl-10`,"aria-invalid":!!m||void 0,"aria-describedby":m?`yuri-ui-auth-error`:void 0,disabled:f})]}),(0,$.jsx)(er,{type:`submit`,size:`icon`,disabled:!c||f,"aria-label":t(f?`sessionAuth.actions.unlockingAria`:`sessionAuth.actions.unlockAria`),children:f?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`})})]}),ie?(0,$.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(js,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void G(),disabled:f,children:t(E&&A===`register`?`sessionAuth.actions.cancelPasskeySetup`:`sessionAuth.actions.addPasskey`)})]}):(0,$.jsxs)(`label`,{className:`flex items-center justify-center gap-2 pt-1 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(js,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),m&&(0,$.jsx)(`p`,{id:`yuri-ui-auth-error`,className:`typography-meta text-destructive`,children:m})]}),a&&(0,$.jsxs)(`div`,{className:`w-full`,children:[(0,$.jsx)(Ff,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})]})}):(0,$.jsx)($.Fragment,{children:e})},sp=e=>!!e&&typeof e==`object`&&!Array.isArray(e),cp=e=>typeof e==`string`&&e.trim()?e.trim():null,lp=e=>{if(!sp(e))throw Error(`Could not check OpenCode compatibility`);let t=e.state,n=e.installation;if(t!==`compatible`&&t!==`incompatible`&&t!==`unavailable`||n!==`managed`&&n!==`external`&&n!==`bundled`)throw Error(`Could not check OpenCode compatibility`);let r=cp(e.minimumVersion),i=cp(e.targetVersion);if(!r||!i||typeof e.canInstall!=`boolean`)throw Error(`Could not check OpenCode compatibility`);return{state:t,version:cp(e.version),installation:n,minimumVersion:r,targetVersion:i,canInstall:e.canInstall,guidance:cp(e.guidance)}},up=async()=>{let e=await f(`/api/opencode/compatibility`,{signal:AbortSignal.timeout(2e4)});if(!e.ok)throw Error(`Could not check OpenCode compatibility`);return lp(await e.json())},dp=async()=>{let e=await f(`/api/opencode/install-required`,{method:`POST`}),t=await e.json().catch(()=>null),n=sp(t)?t:null,r=cp(n?.error);if(!e.ok||n?.success!==!0||n?.upgraded!==!0)throw Error(r||`OpenCode installation failed`);let i=cp(n.version);if(!i)throw Error(r||`OpenCode installation did not report a verified version`);return{version:i}},fp=(e,t)=>e instanceof Error&&e.message.trim()?e.message.trim():t,pp=({children:e})=>{let{t}=Xn(),[n,r]=Z.useState(null),[a,o]=Z.useState(!1),[s,c]=Z.useState(null),[l,u]=Z.useState(null),d=Z.useId(),f=Z.useRef(null),p=Z.useRef(0);Z.useEffect(()=>{let e=!0,t=async()=>{let t=++p.current;try{let n=await up();if(!e||t!==p.current)return;r(n),n.state!==`incompatible`&&u(null)}catch{}finally{e&&t===p.current&&o(!0)}};t();let n=i(()=>{e&&(r(null),o(!1),c(null),u(null),t())});return()=>{e=!1,p.current+=1,n()}},[]);let m=n?.state===`incompatible`;Z.useEffect(()=>{m&&(document.getElementById(`initial-loading`)?.remove(),f.current?.focus())},[m]);let h=J(async e=>{if(s)return;let n=++p.current;c(e),u(null);try{if(e===`install`){let e=await dp();if(n!==p.current)return;if(!e.version)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload();return}let i=await up();if(n!==p.current)return;if(i.state===`incompatible`){r(i);return}if(i.state!==`compatible`)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload()}catch(e){if(n!==p.current)return;u(fp(e,t(`opencodeUpgrade.screen.failedGeneric`)))}finally{n===p.current&&c(null)}}),g=(0,$.jsx)(`main`,{"data-startup-logo":!0,className:`flex min-h-dvh items-center justify-center bg-background text-foreground`,children:(0,$.jsx)(Qc,{width:120,height:120,isAnimated:!0})});if(!a)return g;if(!m||!n)return(0,$.jsx)(oc,{children:(0,$.jsx)(Z.Suspense,{fallback:g,children:e})});let _=!!n.version?.startsWith(`2.`),v=n.installation===`bundled`?`opencodeUpgrade.screen.bundled`:n.installation===`external`?_?`opencodeUpgrade.screen.outdatedExternal`:`opencodeUpgrade.screen.external`:_?`opencodeUpgrade.screen.outdatedLocal`:`opencodeUpgrade.screen.local`,y=n.minimumVersion,b=s!==null;return(0,$.jsx)(`section`,{className:`app-region-drag flex h-full min-h-dvh min-h-0 items-center justify-center overflow-y-auto bg-background px-4 py-10 text-foreground select-none sm:px-6`,"aria-labelledby":d,"aria-busy":b,"data-opencode-upgrade-screen":`true`,children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col items-center text-center`,children:[(0,$.jsx)(Qc,{width:48,height:48}),(0,$.jsx)(`h1`,{id:d,ref:f,tabIndex:-1,className:`mt-6 text-xl font-semibold tracking-tight text-balance outline-none`,children:t(_?`opencodeUpgrade.screen.outdatedTitle`:`opencodeUpgrade.screen.title`)}),(0,$.jsxs)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground text-balance`,children:[t(v,{version:n.version??``,minimum:y}),n.canInstall?(0,$.jsxs)($.Fragment,{children:[` `,t(`opencodeUpgrade.screen.installDescription`,{minimum:y})]}):null]}),n.canInstall?null:(0,$.jsx)(`p`,{className:`mt-3 text-sm leading-relaxed text-muted-foreground text-balance`,children:t(`opencodeUpgrade.screen.manualGuidance`)}),n.version?(0,$.jsxs)(`div`,{className:`mt-5 inline-flex max-w-full items-center gap-2 rounded-md border border-border px-2.5 py-1 font-mono text-xs`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`truncate text-muted-foreground`,children:n.version}),(0,$.jsx)(X,{name:`arrow-right`,className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`text-foreground`,children:[y,`+`]})]}):null,l?(0,$.jsxs)(`p`,{role:`alert`,className:`mt-5 w-full break-words rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] px-3 py-2 text-left text-sm text-[var(--status-error-text)]`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t(`opencodeUpgrade.screen.failedTitle`)}),` `,l]}):null,(0,$.jsxs)(`div`,{className:`app-region-no-drag mt-7 flex w-full flex-wrap items-center justify-center gap-2`,children:[n.canInstall?(0,$.jsxs)(er,{type:`button`,disabled:b,onClick:()=>void h(`install`),children:[(0,$.jsx)(X,{name:s===`install`?`refresh`:`download`,className:s===`install`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`install`?`status`:void 0,children:s===`install`?t(_?`opencodeUpgrade.screen.updating`:`opencodeUpgrade.screen.installing`):t(_?`opencodeUpgrade.screen.update`:`opencodeUpgrade.screen.install`,{minimum:y})})]}):null,(0,$.jsxs)(er,{type:`button`,variant:n.canInstall?`ghost`:`default`,disabled:b,onClick:()=>void h(`reconnect`),children:[(0,$.jsx)(X,{name:`refresh`,className:s===`reconnect`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`reconnect`?`status`:void 0,children:t(s===`reconnect`?`opencodeUpgrade.screen.reconnecting`:`opencodeUpgrade.screen.reconnect`)})]})]}),(0,$.jsxs)(`a`,{className:`app-region-no-drag mt-6 inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,href:`https://opencode.ai/download`,target:`_blank`,rel:`noopener noreferrer`,children:[t(`opencodeUpgrade.screen.guide`),(0,$.jsx)(X,{name:`external-link`,className:`size-3`})]}),(0,$.jsx)(`div`,{className:`app-region-no-drag mt-3 w-full`,children:(0,$.jsx)(Ff,{})})]})})},mp=e=>{let t=(0,Q.c)(14),{children:n}=e,r=K(hp),i=K(gp),a=K(_p),o=K(vp),s=K(yp),{deviceType:c,hasTouchInput:l}=$c(),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=typeof document<`u`&&bt(),t[0]=u):u=t[0];let d=u,f;t[1]!==s||t[2]!==a?(f=()=>{a(),s()},t[1]=s,t[2]=a,t[3]=f):f=t[3];let p;t[4]!==s||t[5]!==a||t[6]!==i||t[7]!==c||t[8]!==r||t[9]!==l||t[10]!==o?(p=[r,i,a,o,s,c,l,d],t[4]=s,t[5]=a,t[6]=i,t[7]=c,t[8]=r,t[9]=l,t[10]=o,t[11]=p):p=t[11],Z.useLayoutEffect(f,p);let m;return t[12]===n?m=t[13]:(m=(0,$.jsx)($.Fragment,{children:n}),t[12]=n,t[13]=m),m};function hp(e){return e.fontSize}function gp(e){return e.codeFontSize}function _p(e){return e.applyTypography}function vp(e){return e.padding}function yp(e){return e.applyPadding}var bp=e(G(),1),xp=e=>{if(!e||typeof e!=`string`)return null;let t=e.trim();if(!t.startsWith(`#`))return null;let n=t.slice(1);if((n.length===3||n.length===4)&&(n=n.split(``).map(e=>e+e).join(``)),n.length===8&&(n=n.slice(0,6)),n.length!==6)return null;let r=Number.parseInt(n,16);return Number.isNaN(r)?null:`${r>>16&255} ${r>>8&255} ${r&255}`},Sp=class{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){let t=[];return t.push(...this.generateTailwindVariables(e)),t.push(...this.generatePrimaryColors(e.colors.primary)),t.push(...this.generateSurfaceColors(e.colors.surface)),t.push(...this.generateInteractiveColors(e.colors.interactive)),t.push(...this.generateStatusColors(e.colors.status)),t.push(...this.generatePullRequestColors(e)),t.push(...this.generateSyntaxColors(e.colors.syntax)),t.push(...this.generateComponentColors(e.colors,e)),t.push(...this.generateTypographyVariables()),e.config&&t.push(...this.generateConfigVariables(e.config)),t.join(`
3
3
  `)}generateTailwindVariables(e){let t=[];t.push(` --background: ${e.colors.surface.background} !important;`),t.push(` --foreground: ${e.colors.surface.foreground} !important;`),t.push(` --muted: ${e.colors.surface.muted} !important;`),t.push(` --muted-foreground: ${e.colors.surface.mutedForeground} !important;`),t.push(` --card: ${e.colors.surface.elevated} !important;`),t.push(` --card-foreground: ${e.colors.surface.elevatedForeground} !important;`),t.push(` --popover: ${e.colors.surface.elevated} !important;`),t.push(` --popover-foreground: ${e.colors.surface.elevatedForeground} !important;`),t.push(` --border: ${e.colors.interactive.border} !important;`),t.push(` --input: ${e.colors.interactive.border} !important;`),t.push(` --primary: ${e.colors.primary.base} !important;`),t.push(` --primary-foreground: ${e.colors.primary.foreground} !important;`),t.push(` --secondary: ${e.colors.surface.muted} !important;`),t.push(` --secondary-foreground: ${e.colors.surface.mutedForeground} !important;`),t.push(` --accent: ${e.colors.surface.subtle} !important;`),t.push(` --accent-foreground: ${e.colors.surface.foreground} !important;`),t.push(` --destructive: ${e.colors.status.error} !important;`),t.push(` --destructive-foreground: ${e.colors.status.errorForeground} !important;`),t.push(` --ring: ${e.colors.interactive.focusRing} !important;`);let n=xp(e.colors.surface.muted),r=xp(e.colors.surface.subtle),i=xp(e.colors.interactive.border);t.push(` --sidebar-base: ${e.colors.surface.muted} !important;`),n&&t.push(` --sidebar-base-rgb: ${n} !important;`),t.push(` --sidebar: var(--sidebar-base) !important;`),t.push(` --sidebar-foreground: ${e.colors.surface.mutedForeground} !important;`),t.push(` --sidebar-primary: ${e.colors.primary.base} !important;`),t.push(` --sidebar-primary-foreground: ${e.colors.primary.foreground} !important;`),t.push(` --sidebar-accent-base: ${e.colors.surface.subtle} !important;`),r&&t.push(` --sidebar-accent-base-rgb: ${r} !important;`),t.push(` --sidebar-accent: var(--sidebar-accent-base) !important;`),t.push(` --sidebar-accent-foreground: ${e.colors.surface.foreground} !important;`),t.push(` --sidebar-border: ${e.colors.interactive.border} !important;`),i&&t.push(` --sidebar-border-rgb: ${i} !important;`),t.push(` --sidebar-ring: ${e.colors.interactive.focusRing} !important;`);let a=e.metadata.variant===`dark`,o=a?.15:.5,s=a?.1:.3,c=a?.42:.52;if(n)t.push(` --sidebar-overlay-strong: rgb(${n} / ${o}) !important;`),t.push(` --sidebar-overlay-soft: rgb(${n} / ${s}) !important;`),t.push(` --sidebar-vibrancy-overlay: rgb(${n} / ${c}) !important;`);else{let n=e.colors.surface.muted;t.push(` --sidebar-overlay-strong: ${this.opacity(n,o)} !important;`),t.push(` --sidebar-overlay-soft: ${this.opacity(n,s)} !important;`),t.push(` --sidebar-vibrancy-overlay: ${this.opacity(n,c)} !important;`)}return e.colors.charts?.series&&Array.isArray(e.colors.charts.series)&&e.colors.charts.series.forEach((e,n)=>{t.push(` --chart-${n+1}: ${e};`)}),e.colors.loading?(t.push(` --loading-spinner: ${e.colors.loading.spinner||e.colors.primary.base};`),t.push(` --loading-spinner-track: ${e.colors.loading.spinnerTrack||e.colors.surface.muted};`)):(t.push(` --loading-spinner: ${e.colors.primary.base};`),t.push(` --loading-spinner-track: ${e.colors.surface.muted};`)),t}apply(e){let t=this.generate(e),n=document.createElement(`style`);n.id=`opencode-theme-variables`;let r=``;e.metadata.variant===`dark`?(r=`:root {\n${t}\n}\n\n.dark {\n${t}\n}`,document.documentElement.classList.add(`dark`),document.documentElement.classList.remove(`light`)):(r=`:root {\n${t}\n}\n\n:root:not(.dark) {\n${t}\n}`,document.documentElement.classList.remove(`dark`),document.documentElement.classList.add(`light`)),n.textContent=r;let i=document.getElementById(`opencode-theme-variables`);i&&i.remove(),document.head.appendChild(n),document.documentElement.setAttribute(`data-theme`,e.metadata.variant);let a=typeof window<`u`&&window.__YURI_ELECTRON__?.runtime===`electron`&&window.__YURI_ELECTRON__?.macVibrancy===!0;document.documentElement.toggleAttribute(`data-yuri-vibrancy`,a),a&&document.documentElement.toggleAttribute(`data-yuri-vibrancy-ready`,!0)}generatePrimaryColors(e){let t=[];return t.push(` --primary-base: ${e.base};`),t.push(` --primary-hover: ${e.hover||this.darken(e.base,10)};`),t.push(` --primary-active: ${e.active||this.darken(e.base,20)};`),t.push(` --primary-foreground: ${e.foreground||`#ffffff`};`),t.push(` --primary-muted: ${e.muted||this.opacity(e.base,.5)};`),t.push(` --primary-emphasis: ${e.emphasis||this.lighten(e.base,10)};`),t}generateSurfaceColors(e){let t=[];return t.push(` --surface-background: ${e.background};`),t.push(` --surface-foreground: ${e.foreground};`),t.push(` --surface-muted: ${e.muted};`),t.push(` --surface-muted-foreground: ${e.mutedForeground};`),t.push(` --surface-elevated: ${e.elevated};`),t.push(` --surface-elevated-foreground: ${e.elevatedForeground};`),t.push(` --surface-overlay: ${e.overlay};`),t.push(` --surface-subtle: ${e.subtle};`),t}generateInteractiveColors(e){let t=[];return t.push(` --interactive-border: ${e.border};`),t.push(` --interactive-border-hover: ${e.borderHover};`),t.push(` --interactive-border-focus: ${e.borderFocus};`),t.push(` --interactive-selection: ${e.selection};`),t.push(` --interactive-selection-foreground: ${e.selectionForeground};`),t.push(` --interactive-focus: ${e.focus};`),t.push(` --interactive-focus-ring: ${e.focusRing};`),t.push(` --interactive-cursor: ${e.cursor};`),t.push(` --interactive-hover: ${e.hover};`),t.push(` --interactive-active: ${e.active};`),t}generateStatusColors(e){let t=[];return t.push(` --status-error: ${e.error};`),t.push(` --status-error-foreground: ${e.errorForeground};`),t.push(` --status-error-background: ${e.errorBackground};`),t.push(` --status-error-border: ${e.errorBorder};`),t.push(` --status-warning: ${e.warning};`),t.push(` --status-warning-foreground: ${e.warningForeground};`),t.push(` --status-warning-background: ${e.warningBackground};`),t.push(` --status-warning-border: ${e.warningBorder};`),t.push(` --status-success: ${e.success};`),t.push(` --status-success-foreground: ${e.successForeground};`),t.push(` --status-success-background: ${e.successBackground};`),t.push(` --status-success-border: ${e.successBorder};`),t.push(` --status-info: ${e.info};`),t.push(` --status-info-foreground: ${e.infoForeground};`),t.push(` --status-info-background: ${e.infoBackground};`),t.push(` --status-info-border: ${e.infoBorder};`),t}generatePullRequestColors(e){let t=[],n=e.colors.pr;return t.push(` --pr-open: ${n?.open||e.colors.status.success};`),t.push(` --pr-draft: ${n?.draft||e.colors.surface.mutedForeground};`),t.push(` --pr-blocked: ${n?.blocked||e.colors.status.warning};`),t.push(` --pr-merged: ${n?.merged||(e.metadata.variant===`dark`?`#8957e5`:`#8250df`)};`),t.push(` --pr-closed: ${n?.closed||e.colors.status.error};`),t}generateSyntaxColors(e){let t=[];t.push(` --syntax-background: ${e.base.background};`),t.push(` --syntax-foreground: ${e.base.foreground};`),t.push(` --syntax-comment: ${e.base.comment};`),t.push(` --syntax-keyword: ${e.base.keyword};`),t.push(` --syntax-string: ${e.base.string};`),t.push(` --syntax-number: ${e.base.number};`),t.push(` --syntax-function: ${e.base.function};`),t.push(` --syntax-variable: ${e.base.variable};`),t.push(` --syntax-type: ${e.base.type};`),t.push(` --syntax-operator: ${e.base.operator};`);let n=this.generateSyntaxTokens(e);for(let[e,r]of Object.entries(n))t.push(` --syntax-${this.kebabCase(e)}: ${r};`);return t}generateSyntaxTokens(e){let t=e.base,n=e.tokens||{};return{commentDoc:n.commentDoc||this.lighten(t.comment,10),stringEscape:n.stringEscape||this.darken(t.string,20),stringInterpolation:n.stringInterpolation||t.variable,stringRegex:n.stringRegex||this.adjustHue(t.string,15),keywordControl:n.keywordControl||t.keyword,keywordOperator:n.keywordOperator||t.operator,keywordImport:n.keywordImport||this.lighten(t.keyword,10),keywordReturn:n.keywordReturn||this.emphasize(t.keyword),functionCall:n.functionCall||this.lighten(t.function,5),functionBuiltin:n.functionBuiltin||this.darken(t.function,10),method:n.method||t.function,methodCall:n.methodCall||this.lighten(t.function,5),variableBuiltin:n.variableBuiltin||this.emphasize(t.variable),variableProperty:n.variableProperty||this.lighten(t.variable,10),variableReadonly:n.variableReadonly||t.number,parameter:n.parameter||t.variable,typePrimitive:n.typePrimitive||this.darken(t.type,10),typeInterface:n.typeInterface||t.type,className:n.className||this.emphasize(t.type),enum:n.enum||t.type,boolean:n.boolean||t.number,null:n.null||this.opacity(t.number,.7),constant:n.constant||t.number,punctuation:n.punctuation||this.opacity(t.foreground,.7),delimiter:n.delimiter||this.opacity(t.foreground,.8),bracket:n.bracket||t.foreground,tag:n.tag||t.keyword,tagAttribute:n.tagAttribute||t.variable,tagAttributeValue:n.tagAttributeValue||t.string,tagBracket:n.tagBracket||this.opacity(t.foreground,.8),decorator:n.decorator||t.function,annotation:n.annotation||t.function,namespace:n.namespace||this.opacity(t.type,.8),module:n.module||this.opacity(t.type,.8),...n}}generateComponentColors(e,t){let n=[];return e.markdown?n.push(...this.generateMarkdownColors(e.markdown,t)):n.push(...this.generateDefaultMarkdownColors(t)),e.chat?n.push(...this.generateChatColors(e.chat,t)):n.push(...this.generateDefaultChatColors(t)),e.tools?n.push(...this.generateToolColors(e.tools,t)):n.push(...this.generateDefaultToolColors(t)),n}generateMarkdownColors(e,t){let n=[],r=t.colors.primary.base,i=t.colors.chat?.background||t.colors.surface.background;return n.push(` --markdown-heading1: ${e.heading1||r};`),n.push(` --markdown-heading2: ${e.heading2||this.opacity(r,.9)};`),n.push(` --markdown-heading3: ${e.heading3||this.opacity(r,.8)};`),n.push(` --markdown-heading4: ${e.heading4||t.colors.surface.foreground};`),n.push(` --markdown-link: ${e.link||r};`),n.push(` --markdown-link-hover: ${e.linkHover||t.colors.primary.hover||this.darken(r,10)};`),n.push(` --markdown-inline-code: ${e.inlineCode||t.colors.syntax.base.string};`),n.push(` --markdown-inline-code-bg: ${e.inlineCodeBackground||i};`),n.push(` --markdown-blockquote: ${e.blockquote||t.colors.surface.mutedForeground};`),n.push(` --markdown-blockquote-border: ${e.blockquoteBorder||t.colors.interactive.border};`),n.push(` --markdown-list-marker: ${r};`),n.push(` --markdown-bold: ${e.bold||t.colors.surface.foreground};`),n.push(` --markdown-italic: ${e.italic||this.opacity(t.colors.surface.foreground,.9)};`),n.push(` --markdown-strikethrough: ${e.strikethrough||t.colors.surface.mutedForeground};`),n.push(` --markdown-hr: ${e.hr||t.colors.interactive.border};`),n}generateDefaultMarkdownColors(e){let t=[],n=e.colors.primary.base,r=e.colors.chat?.background||e.colors.surface.background;return t.push(` --markdown-heading1: ${n};`),t.push(` --markdown-heading2: ${this.opacity(n,.9)};`),t.push(` --markdown-heading3: ${this.opacity(n,.8)};`),t.push(` --markdown-heading4: ${e.colors.surface.foreground};`),t.push(` --markdown-link: ${n};`),t.push(` --markdown-link-hover: ${e.colors.primary.hover||this.darken(n,10)};`),t.push(` --markdown-inline-code: ${e.colors.syntax.base.string};`),t.push(` --markdown-inline-code-bg: ${r};`),t.push(` --markdown-blockquote: ${e.colors.surface.mutedForeground};`),t.push(` --markdown-blockquote-border: ${e.colors.interactive.border};`),t.push(` --markdown-list-marker: ${n};`),t.push(` --markdown-bold: ${e.colors.surface.foreground};`),t.push(` --markdown-italic: ${this.opacity(e.colors.surface.foreground,.9)};`),t.push(` --markdown-strikethrough: ${e.colors.surface.mutedForeground};`),t.push(` --markdown-hr: ${e.colors.interactive.border};`),t}generateChatColors(e,t){let n=[],r=e.background||t.colors.surface.background,i=e.composerSkill||this.getDefaultComposerSkillColor(t);return n.push(` --chat-background: ${r};`),n.push(` --chat-user-message: ${e.userMessage||t.colors.surface.foreground};`),n.push(` --chat-user-message-bg: ${e.userMessageBackground||t.colors.surface.elevated};`),n.push(` --chat-assistant-message: ${e.assistantMessage||t.colors.surface.foreground};`),n.push(` --chat-assistant-message-bg: ${e.assistantMessageBackground||t.colors.surface.muted};`),n.push(` --chat-timestamp: ${e.timestamp||t.colors.surface.mutedForeground};`),n.push(` --chat-divider: ${e.divider||t.colors.interactive.border};`),n.push(` --chat-typing: ${e.typing||t.colors.surface.mutedForeground};`),n.push(` --chat-composer-skill: ${i};`),n}generateDefaultChatColors(e){let t=[];return t.push(` --chat-background: ${e.colors.surface.background};`),t.push(` --chat-user-message: ${e.colors.surface.foreground};`),t.push(` --chat-user-message-bg: ${e.colors.surface.elevated};`),t.push(` --chat-assistant-message: ${e.colors.surface.foreground};`),t.push(` --chat-assistant-message-bg: ${e.colors.surface.muted};`),t.push(` --chat-timestamp: ${e.colors.surface.mutedForeground};`),t.push(` --chat-divider: ${e.colors.interactive.border};`),t.push(` --chat-typing: ${e.colors.surface.mutedForeground};`),t.push(` --chat-composer-skill: ${this.getDefaultComposerSkillColor(e)};`),t}getDefaultComposerSkillColor(e){return e.metadata.variant===`dark`?this.lighten(e.colors.status.warning,25):e.colors.status.warning}generateToolColors(e,t){let n=[];return n.push(` --tools-background: ${e?.background||this.opacity(t.colors.surface.muted,.2)};`),n.push(` --tools-border: ${e?.border||this.opacity(t.colors.interactive.border,.3)};`),n.push(` --tools-header-hover: ${e?.headerHover||this.opacity(t.colors.surface.muted,.3)};`),n.push(` --tools-icon: ${e?.icon||t.colors.surface.mutedForeground};`),n.push(` --tools-title: color-mix(in srgb, ${e?.title||t.colors.surface.foreground} 50%, ${t.colors.surface.mutedForeground});`),n.push(` --tools-description: ${e?.description||this.opacity(t.colors.surface.mutedForeground,.6)};`),e?.edit?(n.push(` --tools-edit-added: ${e.edit.added||t.colors.status.success};`),n.push(` --tools-edit-added-bg: ${e.edit.addedBackground||t.colors.status.successBackground};`),n.push(` --tools-edit-removed: ${e.edit.removed||t.colors.status.error};`),n.push(` --tools-edit-removed-bg: ${e.edit.removedBackground||t.colors.status.errorBackground};`),n.push(` --tools-edit-modified: ${e.edit.modified||t.colors.status.info};`),n.push(` --tools-edit-modified-bg: ${e.edit.modifiedBackground||t.colors.status.infoBackground};`),n.push(` --tools-edit-line-number: ${e.edit.lineNumber||this.opacity(t.colors.surface.mutedForeground,.6)};`)):(n.push(` --tools-edit-added: ${t.colors.status.success};`),n.push(` --tools-edit-added-bg: ${t.colors.status.successBackground};`),n.push(` --tools-edit-removed: ${t.colors.status.error};`),n.push(` --tools-edit-removed-bg: ${t.colors.status.errorBackground};`),n.push(` --tools-edit-modified: ${t.colors.status.info};`),n.push(` --tools-edit-modified-bg: ${t.colors.status.infoBackground};`),n.push(` --tools-edit-line-number: ${this.opacity(t.colors.surface.mutedForeground,.6)};`)),n}generateDefaultToolColors(e){let t=[];return t.push(` --tools-background: ${this.opacity(e.colors.surface.muted,.2)};`),t.push(` --tools-border: ${this.opacity(e.colors.interactive.border,.3)};`),t.push(` --tools-header-hover: ${this.opacity(e.colors.surface.muted,.3)};`),t.push(` --tools-icon: ${e.colors.surface.mutedForeground};`),t.push(` --tools-title: color-mix(in srgb, ${e.colors.surface.foreground} 50%, ${e.colors.surface.mutedForeground});`),t.push(` --tools-description: ${this.opacity(e.colors.surface.mutedForeground,.6)};`),t.push(` --tools-edit-added: ${e.colors.status.success};`),t.push(` --tools-edit-added-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.successBackground),.15)};`),t.push(` --tools-edit-removed: ${e.colors.status.error};`),t.push(` --tools-edit-removed-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.errorBackground),.15)};`),t.push(` --tools-edit-modified: ${e.colors.status.info};`),t.push(` --tools-edit-modified-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.infoBackground),.15)};`),t.push(` --tools-edit-line-number: ${this.opacity(e.colors.surface.mutedForeground,.6)};`),t}generateConfigVariables(e){let t=[];return e?(e.fonts&&(e.fonts.sans&&(t.push(` --font-sans: ${e.fonts.sans};`),t.push(` --font-family-sans: ${e.fonts.sans};`)),e.fonts.mono&&(t.push(` --font-mono: ${e.fonts.mono};`),t.push(` --font-family-mono: ${e.fonts.mono};`)),e.fonts.heading&&t.push(` --font-heading: ${e.fonts.heading};`)),e.transitions&&(e.transitions.fast&&t.push(` --transition-fast: ${e.transitions.fast};`),e.transitions.normal&&t.push(` --transition-normal: ${e.transitions.normal};`),e.transitions.slow&&t.push(` --transition-slow: ${e.transitions.slow};`)),t):t}generateTypographyVariables(){let e=[],t=b()?vt:yt;return e.push(` /* Semantic Typography Variables */`),e.push(` --ui-regular-font-weight: 400;`),e.push(` /* Markdown content - all markdown elements use same size */`),e.push(` --text-markdown: ${t.markdown};`),e.push(` /* Code content - all code elements use same size */`),e.push(` --text-code: ${t.code};`),e.push(` /* UI headers - dialog titles, panel headers */`),e.push(` --text-ui-header: ${t.uiHeader};`),e.push(` /* UI labels - buttons, menus, navigation */`),e.push(` --text-ui-label: ${t.uiLabel};`),e.push(` /* Metadata - timestamps, status, helper text */`),e.push(` --text-meta: ${t.meta};`),e.push(` /* Micro text - badges, shortcuts, indicators */`),e.push(` --text-micro: ${t.micro};`),e.push(` /* Heading line height and letter spacing */`),e.push(` --h1-line-height: 1.25rem;`),e.push(` --h2-line-height: 1.25rem;`),e.push(` --h3-line-height: 1.5rem;`),e.push(` --h4-line-height: 1.5rem;`),e.push(` --h5-line-height: 1.5rem;`),e.push(` --h6-line-height: 1.5rem;`),e.push(` --h1-letter-spacing: -0.025em;`),e.push(` --h2-letter-spacing: -0.02em;`),e.push(` --h3-letter-spacing: -0.015em;`),e.push(` --h4-letter-spacing: -0.01em;`),e.push(` --h5-letter-spacing: 0;`),e.push(` --h6-letter-spacing: 0.01em;`),e.push(` /* UI element line height and letter spacing */`),e.push(` --ui-button-line-height: 1.375rem;`),e.push(` --ui-button-letter-spacing: 0.02em;`),e.push(` --ui-button-font-weight: 500;`),e.push(` --ui-label-line-height: 1rem;`),e.push(` --ui-label-letter-spacing: 0.03em;`),e.push(` --ui-label-font-weight: 500;`),e.push(` --ui-caption-line-height: 1rem;`),e.push(` --ui-caption-letter-spacing: 0.025em;`),e.push(` --ui-caption-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` /* Markdown line height and letter spacing */`),e.push(` --markdown-body-line-height: 1.625;`),e.push(` --markdown-body-letter-spacing: 0;`),e.push(` --markdown-body-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` --markdown-h1-line-height: 1.25rem;`),e.push(` --markdown-h1-letter-spacing: -0.025em;`),e.push(` --markdown-h2-line-height: 1.25rem;`),e.push(` --markdown-h2-letter-spacing: -0.02em;`),e.push(` --markdown-h3-line-height: 1.5rem;`),e.push(` --markdown-h3-letter-spacing: -0.015em;`),e.push(` --markdown-h4-line-height: 1.5rem;`),e.push(` --markdown-h4-letter-spacing: -0.01em;`),e.push(` --markdown-h5-line-height: 1.5rem;`),e.push(` --markdown-h5-letter-spacing: 0;`),e.push(` --markdown-h6-line-height: 1.5rem;`),e.push(` --markdown-h6-letter-spacing: 0.01em;`),e.push(` --markdown-list-line-height: 1.625;`),e.push(` --markdown-code-block-line-height: 1rem;`),e.push(` --ui-button-small-line-height: 1.25rem;`),e.push(` --ui-button-small-letter-spacing: 0.02em;`),e.push(` --ui-button-small-font-weight: 500;`),e.push(` --markdown-body-small-line-height: 1.5;`),e.push(` --markdown-body-small-letter-spacing: 0;`),e.push(` --markdown-body-small-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` --ui-button-large-line-height: 1.5rem;`),e.push(` --ui-button-large-letter-spacing: 0.02em;`),e.push(` --ui-button-large-font-weight: 500;`),e.push(` --markdown-body-large-line-height: 1.625;`),e.push(` --markdown-body-large-letter-spacing: 0;`),e.push(` --markdown-body-large-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` /* Code line height and letter spacing */`),e.push(` --code-inline-line-height: 1rem;`),e.push(` --code-inline-letter-spacing: 0;`),e.push(` --code-inline-font-weight: 400;`),e.push(` --code-block-line-height: 1.4rem;`),e.push(` --code-block-letter-spacing: 0;`),e.push(` --code-block-font-weight: 400;`),e.push(` --code-line-numbers-line-height: 1.25rem;`),e.push(` --code-line-numbers-letter-spacing: 0;`),e.push(` --code-line-numbers-font-weight: 400;`),e.push(` /* Additional UI element line height and letter spacing */`),e.push(` --ui-badge-line-height: 1rem;`),e.push(` --ui-badge-letter-spacing: 0.025em;`),e.push(` --ui-badge-font-weight: 500;`),e.push(` --ui-tooltip-line-height: 1rem;`),e.push(` --ui-tooltip-letter-spacing: 0.025em;`),e.push(` --ui-tooltip-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` --ui-input-line-height: 1.375rem;`),e.push(` --ui-input-letter-spacing: 0.02em;`),e.push(` --ui-input-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` --ui-helper-text-line-height: 1rem;`),e.push(` --ui-helper-text-letter-spacing: 0.025em;`),e.push(` --ui-helper-text-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` /* Additional markdown line height and letter spacing */`),e.push(` --markdown-blockquote-line-height: 1.625;`),e.push(` --markdown-blockquote-letter-spacing: 0;`),e.push(` --markdown-blockquote-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` --markdown-list-letter-spacing: 0;`),e.push(` --markdown-list-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` --markdown-link-line-height: 1.625;`),e.push(` --markdown-link-letter-spacing: 0;`),e.push(` --markdown-link-font-weight: var(--ui-regular-font-weight, 400);`),e.push(` --markdown-code-line-height: 1.35;`),e.push(` --markdown-code-letter-spacing: 0;`),e.push(` --markdown-code-font-weight: 400;`),e.push(` --markdown-code-block-letter-spacing: 0;`),e.push(` --markdown-code-block-font-weight: 400;`),e}initializeInheritanceMap(){this.inheritanceMap.set(`header.background`,`surface.background`),this.inheritanceMap.set(`header.foreground`,`surface.foreground`),this.inheritanceMap.set(`header.logoTint`,`primary.base`),this.inheritanceMap.set(`header.divider`,`interactive.border`),this.inheritanceMap.set(`sidebar.background`,`surface.muted`),this.inheritanceMap.set(`sidebar.foreground`,`surface.mutedForeground`),this.inheritanceMap.set(`sidebar.hover`,`interactive.hover`),this.inheritanceMap.set(`sidebar.active`,`primary.base`),this.inheritanceMap.set(`sidebar.activeForeground`,`primary.foreground`)}opacity(e,t){return e.startsWith(`#`)?`${e}${Math.round(t*255).toString(16).padStart(2,`0`)}`:e.startsWith(`rgb`)?e.replace(`rgb`,`rgba`).replace(`)`,`, ${t})`):e}removeTransparency(e){return e.startsWith(`#`)?e.length===9?e.slice(0,7):e.length===5?e.slice(0,4):e:e.startsWith(`rgba`)?e.replace(`rgba`,`rgb`).replace(/,\s*[\d.]+\)$/,`)`):e}addTransparency(e,t){if(e.startsWith(`#`)){let n=e.slice(1);if(n.length===3)return`rgba(${parseInt(n[0]+n[0],16)}, ${parseInt(n[1]+n[1],16)}, ${parseInt(n[2]+n[2],16)}, ${t})`;if(n.length===6)return`rgba(${parseInt(n.slice(0,2),16)}, ${parseInt(n.slice(2,4),16)}, ${parseInt(n.slice(4,6),16)}, ${t})`}return e.startsWith(`rgb`)?e.replace(`rgb`,`rgba`).replace(`)`,`, ${t})`):e}darken(e,t){if(e.startsWith(`#`)){let n=parseInt(e.slice(1),16),r=Math.round(2.55*t),i=(n>>16)-r,a=(n>>8&255)-r,o=(n&255)-r;return`#`+(16777216+(i<255?i<0?0:i:255)*65536+(a<255?a<0?0:a:255)*256+(o<255?o<0?0:o:255)).toString(16).slice(1)}return e}lighten(e,t){if(e.startsWith(`#`)){let n=parseInt(e.slice(1),16),r=Math.round(2.55*t),i=(n>>16)+r,a=(n>>8&255)+r,o=(n&255)+r;return`#`+(16777216+(i<255?i<0?0:i:255)*65536+(a<255?a<0?0:a:255)*256+(o<255?o<0?0:o:255)).toString(16).slice(1)}return e}adjustHue(e,t){return this.lighten(e,t/10)}emphasize(e){return this.lighten(e,15)}kebabCase(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).toLowerCase()}},Cp=()=>hl()?new URLSearchParams(window.location.search):null,wp=()=>typeof window>`u`||window.matchMedia(`(prefers-color-scheme: dark)`).matches,Tp=()=>{let e=Cp()?.get(`themeVariant`);return e===`dark`||e===`light`?e===`dark`:wp()},Ep=(e,t)=>t.reduce((e,t)=>e&&typeof e==`object`?e[t]:void 0,e),Dp=e=>typeof e==`string`&&e.trim().length>0,Op=e=>{if(!e||typeof e!=`object`)return!1;for(let t of[[`metadata`,`id`],[`metadata`,`name`],[`metadata`,`variant`],[`colors`,`primary`,`base`],[`colors`,`primary`,`foreground`],[`colors`,`surface`,`background`],[`colors`,`surface`,`foreground`],[`colors`,`surface`,`muted`],[`colors`,`surface`,`mutedForeground`],[`colors`,`surface`,`elevated`],[`colors`,`surface`,`elevatedForeground`],[`colors`,`surface`,`subtle`],[`colors`,`interactive`,`border`],[`colors`,`interactive`,`selection`],[`colors`,`interactive`,`selectionForeground`],[`colors`,`interactive`,`focusRing`],[`colors`,`interactive`,`hover`],[`colors`,`status`,`error`],[`colors`,`status`,`errorForeground`],[`colors`,`status`,`errorBackground`],[`colors`,`status`,`errorBorder`],[`colors`,`status`,`warning`],[`colors`,`status`,`warningForeground`],[`colors`,`status`,`warningBackground`],[`colors`,`status`,`warningBorder`],[`colors`,`status`,`success`],[`colors`,`status`,`successForeground`],[`colors`,`status`,`successBackground`],[`colors`,`status`,`successBorder`],[`colors`,`status`,`info`],[`colors`,`status`,`infoForeground`],[`colors`,`status`,`infoBackground`],[`colors`,`status`,`infoBorder`],[`colors`,`syntax`,`base`,`background`],[`colors`,`syntax`,`base`,`foreground`],[`colors`,`syntax`,`base`,`keyword`],[`colors`,`syntax`,`base`,`string`],[`colors`,`syntax`,`base`,`number`],[`colors`,`syntax`,`base`,`function`],[`colors`,`syntax`,`base`,`variable`],[`colors`,`syntax`,`base`,`type`],[`colors`,`syntax`,`base`,`comment`],[`colors`,`syntax`,`base`,`operator`],[`colors`,`syntax`,`highlights`,`diffAdded`],[`colors`,`syntax`,`highlights`,`diffRemoved`],[`colors`,`syntax`,`highlights`,`lineNumber`]])if(!Dp(Ep(e,t)))return!1;let t=Ep(e,[`metadata`,`variant`]);return t===`light`||t===`dark`},kp=e=>Op(e.currentTheme)?e.currentTheme:null,Ap=e=>kp(e)?.metadata.variant??null,jp=cl,Mp=rl,Np=()=>{let e=Cp()?.get(`currentTheme`);if(!e)return null;try{let t=JSON.parse(e);return Op(t)?t:null}catch{return null}},Pp=e=>tl(e===`dark`),Fp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,Ip=()=>{if(typeof document>`u`)return;let e=document.documentElement;e.classList.add(`yuri-theme-switching`);let t=window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>{e.classList.remove(`yuri-theme-switching`)})});return()=>{window.cancelAnimationFrame(t),e.classList.remove(`yuri-theme-switching`)}},Lp=e=>{let t=jp,n=Mp,r=`system`;if(typeof window<`u`){let e=Cp(),i=e?.get(`themeMode`),a=e?.get(`lightThemeId`),o=e?.get(`darkThemeId`),s=$t(`themeMode`),c=$t(`lightThemeId`),l=$t(`darkThemeId`),u=$t(`useSystemTheme`),d=$t(`selectedThemeId`),f=$t(`selectedThemeVariant`);if(i===`light`||i===`dark`||i===`system`)r=i;else if(s===`light`||s===`dark`||s===`system`)r=s;else if(u!==null){if(u===`true`)r=`system`;else if(d){let e=nl(d);e&&(r=e.metadata.variant===`dark`?`dark`:`light`,e.metadata.variant===`dark`?n=e.metadata.id:t=e.metadata.id)}}else(f===`light`||f===`dark`)&&(r=f);typeof a==`string`&&a.trim().length>0?t=a.trim():typeof c==`string`&&c.trim().length>0&&(t=c.trim()),typeof o==`string`&&o.trim().length>0?n=o.trim():typeof l==`string`&&l.trim().length>0&&(n=l.trim())}if(e){let r=nl(e);r&&(r.metadata.variant===`light`?t=r.metadata.id:n=r.metadata.id)}return{themeMode:r,lightThemeId:t,darkThemeId:n}};function Rp({children:e,defaultThemeId:t}){let n=(0,Z.useMemo)(()=>new Sp,[]),[r,a]=(0,Z.useState)(()=>Lp(t)),[o,s]=(0,Z.useState)(!1),[c,u]=(0,Z.useState)(()=>Tp()),[d,p]=(0,Z.useState)([]),[m]=(0,Z.useState)(()=>Np()),[h,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(()=>typeof window>`u`||!b()?null:window.__YURI_VSCODE_THEME__||null),w=(0,Z.useMemo)(()=>b(),[]),T=(0,Z.useMemo)(()=>g(),[]),E=(0,Z.useMemo)(()=>x(),[]),D=(0,Z.useMemo)(()=>typeof window>`u`?!1:Cp()!==null,[]),O=(0,Z.useMemo)(()=>{let e=[],t=new Set,n=n=>{let r=n.metadata.id;t.has(r)||(t.add(r),e.push(n))};return w&&S&&n(S),h&&n(h),m&&n(m),d.forEach(n),ol.forEach(n),e},[d,m,h,w,S]),k=(0,Z.useMemo)(()=>e=>O.find(t=>t.metadata.id===e),[O]),A=(0,Z.useMemo)(()=>(e,t)=>{let n=k(e);return n&&n.metadata.variant===t?n:O.find(e=>e.metadata.variant===t)??Pp(t)},[O,k]),j=(0,Z.useMemo)(()=>w&&S?S:r.themeMode===`light`?A(r.lightThemeId,`light`):r.themeMode===`dark`||c?A(r.darkThemeId,`dark`):A(r.lightThemeId,`light`),[A,w,r,c,S]),M=J(async()=>{if(!(typeof window>`u`||w)){y(!0);try{let e=await f(`/api/config/themes`,{method:`GET`,credentials:T?`omit`:`include`,headers:{Accept:`application/json`}});if(e.status===401||!e.ok)return;let t=await e.json(),n=(Array.isArray(t?.themes)?t.themes:[]).filter(Op);p(n)}catch{}finally{y(!1)}}});(0,Z.useEffect)(()=>{M()},[M]),(0,Z.useEffect)(()=>{if(!w)return;let e=e=>{C(e)},t=t=>{let n=t.detail;n?.theme&&e(n.theme)},n=window.__YURI_VSCODE_THEME__;return n&&e(n),window.addEventListener(`yuri:vscode-theme`,t),()=>window.removeEventListener(`yuri:vscode-theme`,t)},[w]);let N=J(e=>{if(typeof document>`u`)return;let t=document.documentElement.hasAttribute(`data-yuri-vibrancy`)||window.__YURI_ELECTRON__?.macVibrancy===!0?`transparent`:e.colors.surface.background;document.body.style.backgroundColor=t;let n=document.querySelector(`meta[name="theme-color"]`);n||(n=document.createElement(`meta`),n.setAttribute(`name`,`theme-color`),document.head.appendChild(n)),n.setAttribute(`content`,t);let r=e.metadata.variant===`dark`?`(prefers-color-scheme: dark)`:`(prefers-color-scheme: light)`,i=document.querySelector(`meta[name="theme-color"][media="${r}"]`);i||(i=document.createElement(`meta`),i.setAttribute(`name`,`theme-color`),i.setAttribute(`media`,r),document.head.appendChild(i)),i.setAttribute(`content`,t)}),P=J(e=>{typeof document>`u`||document.documentElement.classList.toggle(`vscode-runtime`,e)});Fp(()=>{if(typeof window>`u`)return;let e=Ip();n.apply(j),P(w),N(j);let t=document.documentElement;return t.classList.remove(`light`,`dark`),t.classList.add(j.metadata.variant),e},[P,n,j,w,N]),(0,Z.useEffect)(()=>{if(r.themeMode!==`system`||typeof window>`u`||D)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>{u(e.matches)};return u(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[r.themeMode,D]),(0,Z.useEffect)(()=>{if(D||typeof window>`u`)return;Jt(`themeMode`,r.themeMode),Jt(`lightThemeId`,r.lightThemeId),Jt(`darkThemeId`,r.darkThemeId),Jt(`useSystemTheme`,String(r.themeMode===`system`)),Jt(`selectedThemeId`,j.metadata.id),Jt(`selectedThemeVariant`,j.metadata.variant===`light`?`light`:`dark`);let e=A(r.lightThemeId,`light`),t=A(r.darkThemeId,`dark`);Jt(`splashBgLight`,e.colors.surface.background),Jt(`splashFgLight`,e.colors.surface.foreground),Jt(`splashBgDark`,t.colors.surface.background),Jt(`splashFgDark`,t.colors.surface.foreground),T&&(localStorage.setItem(`themeMode`,r.themeMode),localStorage.setItem(`useSystemTheme`,String(r.themeMode===`system`)),localStorage.setItem(`splashBgLight`,e.colors.surface.background),localStorage.setItem(`splashFgLight`,e.colors.surface.foreground),localStorage.setItem(`splashBgDark`,t.colors.surface.background),localStorage.setItem(`splashFgDark`,t.colors.surface.foreground))},[r,j,A,T,D]),(0,Z.useEffect)(()=>{if(typeof window>`u`||D)return;let e=e=>{e.storageArea===window.localStorage&&(Kt(e.key,`themeMode`)||Kt(e.key,`lightThemeId`)||Kt(e.key,`darkThemeId`))&&a(e=>{let t=$t(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=$t(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=$t(`darkThemeId`),o=typeof a==`string`&&a.trim().length>0?a.trim():e.darkThemeId;return n===e.themeMode&&i===e.lightThemeId&&o===e.darkThemeId?e:{themeMode:n,lightThemeId:i,darkThemeId:o}})};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[D]);let F=J(e=>{let t=e.themeMode,n=e.lightThemeId,r=e.darkThemeId,i=Ap(e),o=kp(e);if(t!==`light`&&t!==`dark`&&t!==`system`||typeof n!=`string`||typeof r!=`string`)return;let s=n.trim(),c=r.trim();!s||!c||(Ip(),(0,bp.flushSync)(()=>{D&&o&&_(o),t===`system`&&i&&u(i===`dark`),a(e=>e.themeMode===t&&e.lightThemeId===s&&e.darkThemeId===c?e:{themeMode:t,lightThemeId:s,darkThemeId:c})}))});(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=window;return e.__yuriApplyThemeSync=F,()=>{e.__yuriApplyThemeSync===F&&delete e.__yuriApplyThemeSync}},[F]),(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin)return;let t=e.data;t?.type!==`yuri:theme-sync`||!t.payload||F(t.payload)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[F]),(0,Z.useEffect)(()=>{if(D||!o)return;let e=A(r.lightThemeId,`light`),t=A(r.darkThemeId,`dark`);Yt({themeId:j.metadata.id,themeVariant:j.metadata.variant===`light`?`light`:`dark`,useSystemTheme:r.themeMode===`system`,lightThemeId:r.lightThemeId,darkThemeId:r.darkThemeId,splashBgLight:e.colors.surface.background,splashFgLight:e.colors.surface.foreground,splashBgDark:t.colors.surface.background,splashFgDark:t.colors.surface.foreground})},[j.metadata.id,j.metadata.variant,A,r.themeMode,r.lightThemeId,r.darkThemeId,D,o]),(0,Z.useEffect)(()=>{D||!E||(async()=>{await tr(r.themeMode,j.metadata.variant)})()},[j.metadata.variant,E,r.themeMode,D]),(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t&&(a(e=>{let n=e.themeMode;t.useSystemTheme===!0?n=`system`:t.useSystemTheme===!1&&(t.themeVariant===`dark`||t.themeVariant===`light`)&&(n=t.themeVariant);let r=e.lightThemeId;typeof t.lightThemeId==`string`&&t.lightThemeId.length>0&&(r=t.lightThemeId.trim());let i=e.darkThemeId;return typeof t.darkThemeId==`string`&&t.darkThemeId.length>0&&(i=t.darkThemeId.trim()),n===e.themeMode&&r===e.lightThemeId&&i===e.darkThemeId?e:{themeMode:n,lightThemeId:r,darkThemeId:i}}),s(!0))};return window.addEventListener(`yuri:settings-synced`,e),()=>window.removeEventListener(`yuri:settings-synced`,e)},[]),(0,Z.useEffect)(()=>{if(!(D||typeof window>`u`))return i(e=>{l(e)&&(a(e=>{let t=$t(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=$t(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=$t(`darkThemeId`),o=typeof a==`string`&&a.trim().length>0?a.trim():e.darkThemeId;return n===e.themeMode&&i===e.lightThemeId&&o===e.darkThemeId?e:{themeMode:n,lightThemeId:i,darkThemeId:o}}),s(!1))})},[D]);let I=J(e=>{let t=O.find(t=>t.metadata.id===e);t&&a(e=>t.metadata.variant===`dark`?e.darkThemeId===t.metadata.id&&e.themeMode===`dark`?e:{...e,darkThemeId:t.metadata.id,themeMode:`dark`}:e.lightThemeId===t.metadata.id&&e.themeMode===`light`?e:{...e,lightThemeId:t.metadata.id,themeMode:`light`})}),L=J(e=>{a(t=>t.themeMode===e?t:{...t,themeMode:e})}),R=J(e=>{if(e){a(e=>e.themeMode===`system`?e:{...e,themeMode:`system`});return}let t=j.metadata.variant===`dark`?`dark`:`light`;a(e=>e.themeMode===t?e:{...e,themeMode:t})}),z=J(e=>{let t=O.find(t=>t.metadata.id===e&&t.metadata.variant===`light`);t&&a(e=>e.lightThemeId===t.metadata.id?e:{...e,lightThemeId:t.metadata.id})}),B=J(e=>{let t=O.find(t=>t.metadata.id===e&&t.metadata.variant===`dark`);t&&a(e=>e.darkThemeId===t.metadata.id?e:{...e,darkThemeId:t.metadata.id})}),V=(0,Z.useMemo)(()=>({currentTheme:j,availableThemes:O,setTheme:I,customThemesLoading:v,reloadCustomThemes:M,isSystemPreference:r.themeMode===`system`,setSystemPreference:R,themeMode:r.themeMode,setThemeMode:L,lightThemeId:r.lightThemeId,darkThemeId:r.darkThemeId,setLightThemePreference:z,setDarkThemePreference:B}),[O,j,v,r.darkThemeId,r.lightThemeId,r.themeMode,M,B,z,R,I,L]);return(0,$.jsx)(vs.Provider,{value:V,children:e})}var zp=!1,Bp=()=>{if(zp||typeof window>`u`)return;zp=!0;let e={showReasoningTraces:K.getState().showReasoningTraces,sessionTitleRefreshEnabled:K.getState().sessionTitleRefreshEnabled,sessionGoalEnabled:K.getState().sessionGoalEnabled,sessionGoalDefaultBudgetEnabled:K.getState().sessionGoalDefaultBudgetEnabled,sessionGoalDefaultBudget:K.getState().sessionGoalDefaultBudget,collapsibleThinkingBlocks:K.getState().collapsibleThinkingBlocks,showDeletionDialog:K.getState().showDeletionDialog,nativeNotificationsEnabled:K.getState().nativeNotificationsEnabled,notificationMode:K.getState().notificationMode,notifyOnSubtasks:K.getState().notifyOnSubtasks,notifyOnCompletion:K.getState().notifyOnCompletion,notifyOnError:K.getState().notifyOnError,notifyOnQuestion:K.getState().notifyOnQuestion,notifyOnPermission:K.getState().notifyOnPermission,notifyOnScheduledTasks:K.getState().notifyOnScheduledTasks,notifyOnAssistants:K.getState().notifyOnAssistants,notifyOnGoals:K.getState().notifyOnGoals,notificationTemplates:K.getState().notificationTemplates,summarizeLastMessage:K.getState().summarizeLastMessage,summaryThreshold:K.getState().summaryThreshold,summaryLength:K.getState().summaryLength,maxLastMessageLength:K.getState().maxLastMessageLength,autoDeleteEnabled:K.getState().autoDeleteEnabled,autoDeleteAfterDays:K.getState().autoDeleteAfterDays,sessionRetentionAction:K.getState().sessionRetentionAction,fontSize:K.getState().fontSize,terminalFontSize:K.getState().terminalFontSize,editorFontSize:K.getState().editorFontSize,uiFont:K.getState().uiFont,monoFont:K.getState().monoFont,padding:K.getState().padding,cornerRadius:K.getState().cornerRadius,inputBarOffset:K.getState().inputBarOffset,mobileKeyboardMode:K.getState().mobileKeyboardMode,diffLayoutPreference:K.getState().diffLayoutPreference,gitChangesViewMode:K.getState().gitChangesViewMode},t=null,n=null,r=()=>{let e=t;t=null,n=null,e&&Object.keys(e).length>0&&Yt(e)},i=e=>{t={...t??{},...e},!n&&(n=setTimeout(r,150))};K.subscribe(t=>{let n={showReasoningTraces:t.showReasoningTraces,sessionTitleRefreshEnabled:t.sessionTitleRefreshEnabled,sessionGoalEnabled:t.sessionGoalEnabled,sessionGoalDefaultBudgetEnabled:t.sessionGoalDefaultBudgetEnabled,sessionGoalDefaultBudget:t.sessionGoalDefaultBudget,collapsibleThinkingBlocks:t.collapsibleThinkingBlocks,showDeletionDialog:t.showDeletionDialog,nativeNotificationsEnabled:t.nativeNotificationsEnabled,notificationMode:t.notificationMode,notifyOnSubtasks:t.notifyOnSubtasks,notifyOnCompletion:t.notifyOnCompletion,notifyOnError:t.notifyOnError,notifyOnQuestion:t.notifyOnQuestion,notifyOnPermission:t.notifyOnPermission,notifyOnScheduledTasks:t.notifyOnScheduledTasks,notifyOnAssistants:t.notifyOnAssistants,notifyOnGoals:t.notifyOnGoals,notificationTemplates:t.notificationTemplates,summarizeLastMessage:t.summarizeLastMessage,summaryThreshold:t.summaryThreshold,summaryLength:t.summaryLength,maxLastMessageLength:t.maxLastMessageLength,autoDeleteEnabled:t.autoDeleteEnabled,autoDeleteAfterDays:t.autoDeleteAfterDays,sessionRetentionAction:t.sessionRetentionAction,fontSize:t.fontSize,terminalFontSize:t.terminalFontSize,editorFontSize:t.editorFontSize,uiFont:t.uiFont,monoFont:t.monoFont,padding:t.padding,cornerRadius:t.cornerRadius,inputBarOffset:t.inputBarOffset,mobileKeyboardMode:t.mobileKeyboardMode,diffLayoutPreference:t.diffLayoutPreference,gitChangesViewMode:t.gitChangesViewMode},r={};n.showReasoningTraces!==e.showReasoningTraces&&(r.showReasoningTraces=n.showReasoningTraces),n.sessionTitleRefreshEnabled!==e.sessionTitleRefreshEnabled&&(r.sessionTitleRefreshEnabled=n.sessionTitleRefreshEnabled),n.sessionGoalEnabled!==e.sessionGoalEnabled&&(r.sessionGoalEnabled=n.sessionGoalEnabled),n.sessionGoalDefaultBudgetEnabled!==e.sessionGoalDefaultBudgetEnabled&&(r.sessionGoalDefaultBudgetEnabled=n.sessionGoalDefaultBudgetEnabled),n.sessionGoalDefaultBudget!==e.sessionGoalDefaultBudget&&(r.sessionGoalDefaultBudget=n.sessionGoalDefaultBudget),n.collapsibleThinkingBlocks!==e.collapsibleThinkingBlocks&&(r.collapsibleThinkingBlocks=n.collapsibleThinkingBlocks),n.showDeletionDialog!==e.showDeletionDialog&&(r.showDeletionDialog=n.showDeletionDialog),n.nativeNotificationsEnabled!==e.nativeNotificationsEnabled&&(r.nativeNotificationsEnabled=n.nativeNotificationsEnabled),n.notificationMode!==e.notificationMode&&(r.notificationMode=n.notificationMode),n.notifyOnSubtasks!==e.notifyOnSubtasks&&(r.notifyOnSubtasks=n.notifyOnSubtasks),n.notifyOnCompletion!==e.notifyOnCompletion&&(r.notifyOnCompletion=n.notifyOnCompletion),n.notifyOnError!==e.notifyOnError&&(r.notifyOnError=n.notifyOnError),n.notifyOnQuestion!==e.notifyOnQuestion&&(r.notifyOnQuestion=n.notifyOnQuestion),n.notifyOnPermission!==e.notifyOnPermission&&(r.notifyOnPermission=n.notifyOnPermission),n.notifyOnScheduledTasks!==e.notifyOnScheduledTasks&&(r.notifyOnScheduledTasks=n.notifyOnScheduledTasks),n.notifyOnAssistants!==e.notifyOnAssistants&&(r.notifyOnAssistants=n.notifyOnAssistants),n.notifyOnGoals!==e.notifyOnGoals&&(r.notifyOnGoals=n.notifyOnGoals),JSON.stringify(n.notificationTemplates)!==JSON.stringify(e.notificationTemplates)&&(r.notificationTemplates=n.notificationTemplates),n.summarizeLastMessage!==e.summarizeLastMessage&&(r.summarizeLastMessage=n.summarizeLastMessage),n.summaryThreshold!==e.summaryThreshold&&(r.summaryThreshold=n.summaryThreshold),n.summaryLength!==e.summaryLength&&(r.summaryLength=n.summaryLength),n.maxLastMessageLength!==e.maxLastMessageLength&&(r.maxLastMessageLength=n.maxLastMessageLength),n.autoDeleteEnabled!==e.autoDeleteEnabled&&(r.autoDeleteEnabled=n.autoDeleteEnabled),n.autoDeleteAfterDays!==e.autoDeleteAfterDays&&(r.autoDeleteAfterDays=n.autoDeleteAfterDays),n.sessionRetentionAction!==e.sessionRetentionAction&&(r.sessionRetentionAction=n.sessionRetentionAction),n.fontSize!==e.fontSize&&(r.fontSize=n.fontSize),n.terminalFontSize!==e.terminalFontSize&&(r.terminalFontSize=n.terminalFontSize),n.editorFontSize!==e.editorFontSize&&(r.editorFontSize=n.editorFontSize),n.uiFont!==e.uiFont&&(r.uiFont=n.uiFont),n.monoFont!==e.monoFont&&(r.monoFont=n.monoFont),n.padding!==e.padding&&(r.padding=n.padding),n.cornerRadius!==e.cornerRadius&&(r.cornerRadius=n.cornerRadius),n.inputBarOffset!==e.inputBarOffset&&(r.inputBarOffset=n.inputBarOffset),n.mobileKeyboardMode!==e.mobileKeyboardMode&&(r.mobileKeyboardMode=n.mobileKeyboardMode),n.diffLayoutPreference!==e.diffLayoutPreference&&(r.diffLayoutPreference=n.diffLayoutPreference),n.gitChangesViewMode!==e.gitChangesViewMode&&(r.gitChangesViewMode=n.gitChangesViewMode),e=n,Object.keys(r).length>0&&i(r)})},Vp=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]?.providerID!==t[n]?.providerID||e[n]?.modelID!==t[n]?.modelID||e[n]?.variant!==t[n]?.variant)return!1;return!0},Hp=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]?.providerID!==t[n]?.providerID||e[n]?.modelID!==t[n]?.modelID)return!1;return!0},Up=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0},Wp=(e,t)=>{if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Array.isArray(t[n])&&Up(e[n],t[n]))},Gp=()=>{let e=K.getState();return{favoriteModels:e.favoriteModels,hiddenModels:e.hiddenModels,collapsedModelProviders:e.collapsedModelProviders,recentModels:e.recentModels,recentAgents:e.recentAgents,recentEfforts:e.recentEfforts}},Kp=(e,t)=>Vp(e.favoriteModels,t.favoriteModels)&&Hp(e.hiddenModels,t.hiddenModels)&&Up(e.collapsedModelProviders,t.collapsedModelProviders)&&Vp(e.recentModels,t.recentModels)&&Up(e.recentAgents,t.recentAgents)&&Wp(e.recentEfforts,t.recentEfforts),qp=e=>({favoriteModels:e.favoriteModels.slice(),hiddenModels:e.hiddenModels.slice(),collapsedModelProviders:e.collapsedModelProviders.slice(),recentModels:e.recentModels.slice(),recentAgents:e.recentAgents.slice(),recentEfforts:Object.fromEntries(Object.entries(e.recentEfforts).map(([e,t])=>[e,t.slice()]))}),Jp=()=>{if(typeof window>`u`)return()=>{};let e=null,t=null,n=!1,r=()=>{e=null;let n=Gp();t&&Kp(t,n)||(t=qp(n),Yt(n).catch(()=>{}))},i=()=>{if(!n){n=!0;return}e!==null&&window.clearTimeout(e),e=window.setTimeout(r,1200)},a=K.subscribe((e,t)=>{Kp({favoriteModels:e.favoriteModels,hiddenModels:e.hiddenModels,collapsedModelProviders:e.collapsedModelProviders,recentModels:e.recentModels,recentAgents:e.recentAgents,recentEfforts:e.recentEfforts},{favoriteModels:t.favoriteModels,hiddenModels:t.hiddenModels,collapsedModelProviders:t.collapsedModelProviders,recentModels:t.recentModels,recentAgents:t.recentAgents,recentEfforts:t.recentEfforts})||i()});return()=>{a(),e!==null&&window.clearTimeout(e)}},Yp=!1,Xp=`yuri-typography-base`,Zp=()=>{if(typeof document>`u`)return;let e=`:root {\n${Object.entries(yt).map(([e,t])=>` --text-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}: ${t};`).join(`
4
4
  `)}\n}\n`,t=document.getElementById(Xp);if(t){t.textContent=e;return}let n=document.createElement(`style`);n.id=Xp,n.textContent=e,document.head.appendChild(n)},Qp=()=>{Yp||typeof window>`u`||(Yp=!0,Zp())};function $p(e){let t=(0,Q.c)(3),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0],(0,Z.useEffect)(em,r);let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(_n,{client:xn,children:n}),t[1]=n,t[2]=i),i}function em(){return Sn(xn)}var tm=15,nm=2e3,rm=40,im=2e4,am=e=>{let t=ni(e=>e.isConnected),n=ni(e=>e.providers.length),r=ni(e=>e.agents.length),i=ni(e=>e.activeDirectoryKey),a=ni(e=>e.refreshMissingCatalogs),o=e.enabled&&t&&(n===0||r===0),s=Z.useRef(0),c=Z.useRef(!1),[l,u]=Z.useState(`fast`),d=e.source,f=J(async()=>{if(!o||c.current||l===`done`)return;let e=l===`fast`?tm:rm;if(s.current>=e){if(l===`fast`){s.current=0,u(`slow`);return}u(`done`);return}let t=ni.getState();if(!(t.providers.length>0&&t.agents.length>0)){c.current=!0,s.current+=1;try{await a({source:d})}catch{}finally{c.current=!1}}});Z.useEffect(()=>{s.current=0,c.current=!1,u(`fast`),o&&f()},[o,i]),Kn(f,!o||l===`done`?null:l===`slow`?im:nm)},om=40,sm=20971520,cm=new Map,lm=0;function um(e){return e.length*2}function dm(e,t){let n=cm.get(e);n!==void 0&&(lm-=n),cm.delete(e),cm.set(e,t),lm+=t}function fm(e,t){let n=cm.get(e);(n!==void 0||t!==void 0)&&dm(e,t??n??0)}function pm(e){let t=cm.get(e);t!==void 0&&(cm.delete(e),lm-=t)}function mm(e,t){let n=e??new Set;for(;cm.size>om||lm>sm;){let e=cm.keys().next().value;if(!e)return;if(n.has(e)){if(fm(e),cm.size<=n.size)return;continue}pm(e),t(e)}}function hm(e,t){dm(e,t)}function gm(e){pm(e)}function _m(e,t){fm(e,t)}function vm(e){let t=new Map,n=e=>{t.delete(e),gm(e)},r=e=>{let r=e.endsWith(`/`)?e:`${e}/`;for(let i of t.keys())(i===e||i.startsWith(r))&&n(i)},i=(e,t)=>t.isFile?e.mtimeMs!==void 0&&t.mtimeMs!==void 0?e.mtimeMs===t.mtimeMs&&e.size===t.size:e.size===t.size:!1,a=(e,r,i)=>{if(r.exists===!1)return n(e),r;let a=um(r.content);return t.set(e,{...r,size:i?.isFile?i.size:void 0,mtimeMs:i?.isFile?i.mtimeMs:void 0}),hm(e,a),mm(new Set,e=>{t.delete(e)}),r},o=async(t,n)=>{let r=await e.statFile?.(t,n).catch(()=>null),i=await e.readFile(t,n),o=await e.statFile?.(t,n).catch(()=>null);if(r&&o&&r.isFile&&o.isFile){if(r.size===o.size&&r.mtimeMs===o.mtimeMs)return a(t,i,o);let s=await e.statFile?.(t,n).catch(()=>null),c=await e.readFile(t,n),l=await e.statFile?.(t,n).catch(()=>null);return s&&l&&s.isFile&&l.isFile&&s.size===l.size&&(s.mtimeMs,l.mtimeMs),a(t,c,l)}return a(t,i,o??r)},s=e.readFile?async(r,a)=>{if(a?.allowOutsideWorkspace)return o(r,a);let s=t.get(r);if(s){if(a?.optional&&(s.exists===void 0||!e.statFile))return o(r,a);if(e.statFile){let t=await e.statFile(r,a).catch(()=>(n(r),null));if(!t||!i(s,t))return n(r),o(r,a)}return _m(r),{content:s.content,path:s.path,exists:s.exists}}return o(r,a)}:void 0,c=e.writeFile?async(t,r)=>(n(t),e.writeFile(t,r)):void 0,l=e.delete?async t=>(r(t),e.delete(t)):void 0,u=e.rename?async(t,n)=>(r(t),r(n),e.rename(t,n)):void 0;return{...e,readFile:s,writeFile:c,delete:l,rename:u}}function ym(e){let t=(0,Q.c)(8),{apis:n,children:r}=e,i;t[0]===n.files?i=t[1]:(i=vm(n.files),t[0]=n.files,t[1]=i);let a;t[2]!==n||t[3]!==i?(a={...n,files:i},t[2]=n,t[3]=i,t[4]=a):a=t[4];let o=a,s;return t[5]!==o||t[6]!==r?(s=(0,$.jsx)(wn.Provider,{value:o,children:r}),t[5]=o,t[6]=r,t[7]=s):s=t[7],s}var bm=`var(--yuri-toast-shadow, inset 0 1px 0 0 rgba(255,255,255,0.12), inset 0 0 0 1px rgba(255,255,255,0.08), 0 0 0 1px rgba(0,0,0,0.36), 0 1px 1px -0.5px rgba(0,0,0,0.22), 0 3px 3px -1.5px rgba(0,0,0,0.20), 0 6px 6px -3px rgba(0,0,0,0.16))`,xm=`var(--yuri-toast-shadow, inset 0 1px 0 0 rgba(255,255,255,0.8), inset 0 0 0 1px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.10), 0 1px 2px -0.5px rgba(0,0,0,0.08), 0 4px 8px -2px rgba(0,0,0,0.08), 0 12px 20px -4px rgba(0,0,0,0.08))`,Sm={success:(0,$.jsx)(X,{name:`checkbox-circle`,weight:`medium`,className:`yuri-toast-status-icon size-5`}),info:(0,$.jsx)(X,{name:`information`,weight:`medium`,className:`yuri-toast-status-icon size-5`}),warning:(0,$.jsx)(X,{name:`error-warning`,weight:`medium`,className:`yuri-toast-status-icon size-5`}),error:(0,$.jsx)(X,{name:`close-circle`,weight:`medium`,className:`yuri-toast-status-icon size-5`}),loading:(0,$.jsx)(X,{name:`loader-4`,weight:`medium`,className:`yuri-toast-status-icon size-5 animate-spin motion-reduce:animate-none`})};function Cm(){let e=(0,Q.c)(2),t=wm,[n,r]=Z.useState(t),i,a;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>{let e=()=>r(t()),n=new MutationObserver(e);return n.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),e(),()=>n.disconnect()},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),Z.useEffect(i,a),n}function wm(){return typeof document<`u`&&document.documentElement.classList.contains(`dark`)}function Tm(e,t){let n=(0,Q.c)(4),r,i;n[0]!==t||n[1]!==e?(r=()=>{let n=t.current;if(!n)return;let r=document.createElement(`div`).style;r.setProperty(`box-shadow`,e,`important`),r.setProperty(`outline`,`none`,`important`);let i=t=>{(t.style.getPropertyValue(`box-shadow`)!==r.getPropertyValue(`box-shadow`)||t.style.getPropertyPriority(`box-shadow`)!==`important`)&&t.style.setProperty(`box-shadow`,e,`important`),(t.style.getPropertyValue(`outline`)!==r.getPropertyValue(`outline`)||t.style.getPropertyPriority(`outline`)!==`important`)&&t.style.setProperty(`outline`,`none`,`important`),t.getAttribute(`tabindex`)===`0`&&t.setAttribute(`tabindex`,`-1`)};n.querySelectorAll(`[data-sonner-toast]`).forEach(i);let a=new MutationObserver(e=>{for(let t of e)t.type===`attributes`&&t.target instanceof HTMLElement&&t.target.matches(`[data-sonner-toast]`)&&i(t.target),t.addedNodes.forEach(e=>{e instanceof HTMLElement&&(e.matches?.(`[data-sonner-toast]`)&&i(e),e.querySelectorAll?.(`[data-sonner-toast]`).forEach(i))})});return a.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`,`tabindex`,`data-expanded`,`data-swiping`]}),()=>a.disconnect()},i=[e,t],n[0]=t,n[1]=e,n[2]=r,n[3]=i):(r=n[2],i=n[3]),Z.useEffect(r,i)}var Em=e=>{let t=(0,Q.c)(8),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r=Cm(),i=r?bm:xm,a=Z.useRef(null);Tm(i,a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o={display:`contents`},t[2]=o):o=t[2];let s=r?`dark`:`light`,c,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c={classNames:{toast:`group/toast toast !flex !min-w-[min(var(--width),calc(100vw-2rem))] !max-w-[calc(100vw-2rem)] !items-center !rounded-[var(--yuri-toast-radius,var(--radius-xl))] !border-0 !px-[var(--yuri-toast-padding-x,0.875rem)] !py-[var(--yuri-toast-padding-y,0.75rem)] !gap-[var(--yuri-toast-gap,0.625rem)] !text-foreground`,content:`!min-w-0 !flex-1 !text-left`,title:`typography-ui-label !font-medium !text-foreground`,description:`typography-meta !text-muted-foreground !mt-0`,actionButton:`!ms-0 !me-0 !shrink-0 !rounded-[var(--radius-md)] !bg-[var(--yuri-toast-action-background,var(--surface-muted))] !text-[var(--yuri-toast-action-foreground,var(--foreground))] hover:!opacity-85 !px-2 !py-1 typography-meta !font-medium transition-opacity`,cancelButton:`!ms-0 !me-0 !shrink-0 !rounded-[var(--radius-md)] !bg-[var(--yuri-toast-cancel-background,var(--interactive-hover))] !text-[var(--yuri-toast-cancel-foreground,var(--foreground))] hover:!bg-[var(--interactive-active)] !px-2 !py-1 typography-meta !font-medium transition-colors`,closeButton:`!rounded-[var(--radius-md)] !bg-[var(--interactive-hover)] !text-foreground hover:!bg-[var(--interactive-active)]`,icon:`!shrink-0 !text-[var(--yuri-toast-status-color,var(--muted-foreground))]`,success:`[&_[data-icon]]:!text-[var(--status-success)]`,error:`[&_[data-icon]]:!text-[var(--status-error)]`,warning:`[&_[data-icon]]:!text-[var(--status-warning)]`,info:`[&_[data-icon]]:!text-[var(--status-info)]`},style:{borderRadius:`var(--radius-xl)`,backgroundColor:`var(--yuri-toast-background, var(--surface-elevated))`}},l={"--normal-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--normal-text":`var(--foreground)`,"--normal-border":`transparent`,"--error-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--error-text":`var(--foreground)`,"--error-border":`transparent`,"--success-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--success-text":`var(--foreground)`,"--success-border":`transparent`,"--warning-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--warning-text":`var(--foreground)`,"--warning-border":`transparent`,"--info-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--info-text":`var(--foreground)`,"--info-border":`transparent`},t[3]=c,t[4]=l):(c=t[3],l=t[4]);let u;return t[5]!==n||t[6]!==s?(u=(0,$.jsx)(`div`,{ref:a,style:o,children:(0,$.jsx)(Bn,{theme:s,className:`toaster group`,position:`bottom-right`,closeButton:!1,duration:3500,icons:Sm,toastOptions:c,style:l,...n})}),t[5]=n,t[6]=s,t[7]=u):u=t[7],u},Dm=new fs({maxEntries:128,maxBytes:1048576}),Om=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}\0${e.agentName??``}`).join(`|`)}`,km=async e=>{let t=Tu(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=e.agentName===void 0?void 0:ps(ds(e.agentName).var,Tu),r=JSON.stringify([e.iconName,t,e.agentName,n?.background]),i=Dm.get(r);return i===void 0&&(i=await(e.agentName===void 0?Zl(e.iconName,t):bu(ms(`agent`,e.agentName,!1,n)))??``,i&&Dm.set(r,i,(r.length+i.length)*2)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:i}}))},Am=[],jm=e=>void 0,Mm=()=>void 0;function Nm(e){let t=Pu()&&e.enabled&&ju(e.isMobile),n=(0,Z.useRef)(null),r=(0,Z.useRef)(e.text),i=(0,Z.useRef)(!1),a=(0,Z.useRef)(-1),o=(0,Z.useRef)(null),s=(0,Z.useRef)(``),c=(0,Z.useRef)(``),l=hs(e.agentName),u=ys()?.currentTheme,d=(0,Z.useRef)([]),f=(0,Z.useRef)(Ru()),p=J(e.onText),m=J(e.onSend),h=J(e.onAbort),g=J(e.onAttach),_=J(e.onFiles),v=J(e.onRemoveAttachment),y=J(e.onOpenModel),b=J(e.onCycleAgent),x=J(e.onOpenAgent),S=J(e.onScrollToBottom),C=J(e.onAutocompleteAccept??jm),w=J(e.onAutocompleteDismiss??Mm),T=J(e=>{typeof document>`u`||ku(document.documentElement,e)});Du.bind({onText:(e,t,n)=>{Cu({incoming:e,replacedText:o.current})||(o.current=null,r.current=e,i.current=!0,p(e,t,n))},onSend:e=>{r.current=e,m(e)},onAbort:h,onAttach:g,onFiles:_,onRemoveAttachment:v,onOpenModel:y,onCycleAgent:b,onOpenAgent:x,onHeight:T,onScrollToBottom:S,onAutocompleteAccept:e=>{i.current=!1,C(e)},onAutocompleteDismiss:w});let E=()=>({text:e.text,placeholder:e.placeholder,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel,modelIcon:s.current,canSend:e.canSend,canAbort:e.canAbort,attachmentCount:e.attachmentCount,attachmentPreviews:d.current,citationRanges:ve(e.text,e.attachments.map(e=>e.filename)),chipRanges:Hu(Eu(e.text,e.chipHighlights),Tu(`--primary`)),appearance:typeof document>`u`?`dark`:Ou(document.documentElement),attachAria:e.attachAria,attachTitle:e.attachTitle,attachPhotosLabel:e.attachPhotosLabel,attachFilesLabel:e.attachFilesLabel,attachCancelLabel:e.attachCancelLabel,sendAria:e.sendAria,queueAria:e.queueAria,stopAria:e.stopAria,modelAria:e.modelAria,agentAria:e.agentAria,agentLabel:e.agentLabel,agentColor:Ku(e.agentName||void 0),agentIdenticon:Gu(e.agentName||void 0),agentIcon:c.current,suppressed:e.suppressed,showScrollToBottom:e.showScrollToBottom,scrollAria:e.scrollAria,autocomplete:f.current});(0,Z.useLayoutEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement;return xu(e,!0),()=>{xu(e,!1)}},[t]),(0,Z.useEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement,i=E();n.current=i,r.current=i.text,Du.rememberText(i.text),Du.retain(e,i);let a=zu();return()=>{n.current=null,a(),Du.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e=>{c.current=e,n.current&&={...n.current,agentIcon:e},Iu().update({agentIcon:e})};return i(``),bu(ms(`agent`,e.agentName||void 0,!1,l)).then(e=>{r||i(e??``)}),()=>{r=!0}},[t,e.agentName,l]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=Hs(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Iu().update(a),i)return bu(i).then(t=>{if(r)return;let i=t??``;s.current=i;let a={modelIcon:i,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};n.current&&={...n.current,...a},Iu().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let D=Fu(e.attachments);(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e.attachments;if(i.length===0){d.current=[],n.current&&(n.current={...n.current,attachmentPreviews:[]},Du.rememberState(n.current)),Iu().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await wu(t.dataUrl):``;return{id:t.id,filename:t.filename,mime:t.mimeType,thumbnailBase64:n??``,removeAria:e.removeAttachmentNamedAria(t.filename)}})).then(e=>{r||(d.current=e,n.current&&(n.current={...n.current,attachmentPreviews:e},Du.rememberState(n.current)),Iu().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,D]);let O=e.autocompleteRows??Am,k=e.autocompleteOpen===!0,A=e.autocompleteHighlightedIndex??0,j=e.autocompleteQuery??``,M=`${Om(O,k,A)}\0${j}`;(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(k&&O.length>0)){let e=Ru();Mu(f.current,e)||(f.current=e,n.current&&(n.current={...n.current,autocomplete:e},Du.rememberState(n.current)),Iu().update({autocomplete:e}));return}return km(O).then(t=>{if(e)return;let r={open:t.length>0,highlightedIndex:Math.max(0,Math.min(A,Math.max(t.length-1,0))),query:j,highlightColor:Tu(`--primary-base`)||Tu(`--primary`),rows:t};Mu(f.current,r)||(f.current=r,n.current&&(n.current={...n.current,autocomplete:r},Du.rememberState(n.current)),Iu().update({autocomplete:r}))}),()=>{e=!0}},[t,M,u]);let N=t?Eu(e.text,e.chipHighlights).map(e=>`${e.start}:${e.end}:${e.triggerLength}`).join(`|`):``;return(0,Z.useEffect)(()=>{if(!t)return;let s=E(),c=n.current;if(c&&Uu(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,Du.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=Su({nextText:s.text,nativeOwnedText:r.current,echoingNative:i.current,preset:l});i.current=!1,!u.omitText&&u.forceText&&(o.current=r.current),u.omitText||(r.current=s.text);let d=Au(c,s,u,{caret:e.caret});d&&Iu().update(d)},[t,e.text,e.textPresetEpoch,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,D,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,N]),t}var Pm=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},Fm=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=_s(),i=Math.min(1,Math.max(0,n)),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=[.45,.7,1,.7,.45],t[0]=a):a=t[0];let o=a,s;return t[1]!==r||t[2]!==i?(s=(0,$.jsx)(`div`,{className:`flex h-6 w-10 flex-shrink-0 items-center justify-center gap-1`,"aria-hidden":`true`,children:o.map((e,t)=>(0,$.jsx)(`span`,{className:`h-full w-1 rounded-full transition-transform duration-75 ease-out motion-reduce:transition-none`,style:{backgroundColor:r.colors.primary.base,transform:`scaleY(${.25+i*e*.75})`}},t))}),t[1]=r,t[2]=i,t[3]=s):s=t[3],s},Im=e=>{let t=ni(e=>e.sttLocalModel),[n,r]=Z.useState(null);return Z.useEffect(()=>{if(!e){r(null);return}let n=!1,i=async()=>{try{let e=await f(`/api/dictation/status`,{query:{provider:`local`,localModel:t}});if(!e.ok||n)return;let i=await e.json(),a=Array.isArray(i?.models)?i.models.find(e=>e.id===t):null;n||r(typeof a?.downloadProgress==`number`?a.downloadProgress:null)}catch{}};i();let a=setInterval(()=>{i()},2e3);return()=>{n=!0,clearInterval(a)}},[e,t]),e?n:null},Lm=e=>{let t=(0,Q.c)(89),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:c,onInsert:l,onInsertAndSend:u,onActiveChange:d,onContentHeightChange:f,renderTrigger:p,topAccessory:m}=e,h=p===void 0||p,{t:g}=Xn(),{currentTheme:_}=_s(),v=ni(Rm),y=K(zm),b;t[0]===y?b=t[1]:(b=Bc(Nc(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(Bm),C=Z.useRef(null),w=Z.useRef(l),T=Z.useRef(u),E,D;t[2]!==l||t[3]!==u?(E=()=>{w.current=l,T.current=u},D=[l,u],t[2]=l,t[3]=u,t[4]=E,t[5]=D):(E=t[4],D=t[5]),Z.useEffect(E,D);let O;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(O={onTranscript:e=>{let t=C.current;C.current=null,t===`send`?T.current(e):w.current(e)}},t[6]=O):O=t[6];let{status:k,partialTranscript:A,volume:j,duration:M,error:N,errorReason:P,startDictation:F,confirmDictation:I,cancelDictation:L,retryFailedDictation:R,acceptPartialTranscript:z,discardFailedDictation:B}=ul(O),V=k===`recording`&&P===`model_download_in_progress`,H=Im(V),U=Z.useRef(k),W,ee;t[7]===k?(W=t[8],ee=t[9]):(W=()=>{U.current=k},ee=[k],t[7]=k,t[8]=W,t[9]=ee),Z.useEffect(W,ee);let te,ne;t[10]!==d||t[11]!==k?(te=()=>(d?.(k!==`idle`),()=>d?.(!1)),ne=[k,d],t[10]=d,t[11]=k,t[12]=te,t[13]=ne):(te=t[12],ne=t[13]),Z.useLayoutEffect(te,ne);let re,G;t[14]!==I||t[15]!==v||t[16]!==c||t[17]!==F||t[18]!==S?(re=()=>{if(!S||!v||c)return;let e=()=>{U.current===`idle`?F():U.current===`recording`&&(C.current=`insert`,I())};return window.addEventListener(`yuri:dictation-toggle`,e),()=>window.removeEventListener(`yuri:dictation-toggle`,e)},G=[S,v,c,F,I],t[14]=I,t[15]=v,t[16]=c,t[17]=F,t[18]=S,t[19]=re,t[20]=G):(re=t[19],G=t[20]),Z.useEffect(re,G);let ie,ae;t[21]!==L||t[22]!==I||t[23]!==k?(ie=()=>{if(k!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),C.current=`insert`,I();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),L())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ae=[k,I,L],t[21]=L,t[22]=I,t[23]=k,t[24]=ie,t[25]=ae):(ie=t[24],ae=t[25]),Z.useEffect(ie,ae);let oe=Z.useRef(null),se=Z.useRef(null),ce=Z.useRef(null),[le,ue]=Z.useState(null),de=k!==`idle`,fe=Z.useRef(f),pe,me;t[26]===f?(pe=t[27],me=t[28]):(pe=()=>{fe.current=f},me=[f],t[26]=f,t[27]=pe,t[28]=me),Z.useEffect(pe,me);let he=Z.useRef(!1),ge;t[29]===de?ge=t[30]:(ge=()=>{if(!de){he.current&&(he.current=!1,fe.current?.(null));return}let e=se.current,t=ce.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);he.current=!0,fe.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[29]=de,t[30]=ge);let _e;t[31]!==N||t[32]!==de||t[33]!==A||t[34]!==k?(_e=[de,A,k,N],t[31]=N,t[32]=de,t[33]=A,t[34]=k,t[35]=_e):_e=t[35],Z.useLayoutEffect(ge,_e);let ve,ye;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(ve=()=>()=>{he.current&&(he.current=!1,fe.current?.(null))},ye=[],t[36]=ve,t[37]=ye):(ve=t[36],ye=t[37]),Z.useEffect(ve,ye);let be,xe;if(t[38]===de?(be=t[39],xe=t[40]):(be=()=>{if(!de)return;let e=oe.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&ue(e.offsetHeight)},xe=[de],t[38]=de,t[39]=be,t[40]=xe),Z.useLayoutEffect(be,xe),!S||!v)return null;let Se=k!==`idle`,Ce;t[41]===I?Ce=t[42]:(Ce=e=>{C.current=e,I()},t[41]=I,t[42]=Ce);let we=Ce,Te;t[43]===R?Te=t[44]:(Te=()=>{C.current=`insert`,R()},t[43]=R,t[44]=Te);let Ee=Te,De;bb0:{if(k===`failed`){De=``;break bb0}if(k===`uploading`){let e;t[45]===g?e=t[46]:(e=g(`chat.dictation.processing`),t[45]=g,t[46]=e),De=e;break bb0}if(V){let e;t[47]!==H||t[48]!==g?(e=H===null?g(`chat.dictation.downloadingModel`):g(`chat.dictation.downloadingModelProgress`,{percent:String(H)}),t[47]=H,t[48]=g,t[49]=e):e=t[49],De=e;break bb0}let e;t[50]===g?e=t[51]:(e=g(`chat.dictation.listening`),t[50]=g,t[51]=e),De=e}let Oe=De,ke;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(ke={onMouseDown:Vm,onPointerDownCapture:Hm},t[52]=ke):ke=t[52];let Ae=ke,je;t[53]!==x||t[54]!==c||t[55]!==i||t[56]!==o||t[57]!==Se||t[58]!==h||t[59]!==F||t[60]!==g?(je=h?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{F()},disabled:c||Se,title:x?`${g(`chat.dictation.start`)} (${x})`:g(`chat.dictation.start`),"aria-label":g(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[53]=x,t[54]=c,t[55]=i,t[56]=o,t[57]=Se,t[58]=h,t[59]=F,t[60]=g,t[61]=je):je=t[61];let Me;t[62]!==z||t[63]!==L||t[64]!==we||t[65]!==_||t[66]!==B||t[67]!==M||t[68]!==N||t[69]!==le||t[70]!==i||t[71]!==a||t[72]!==o||t[73]!==Se||t[74]!==r||t[75]!==V||t[76]!==A||t[77]!==Oe||t[78]!==n||t[79]!==Ee||t[80]!==s||t[81]!==k||t[82]!==g||t[83]!==m||t[84]!==j?(Me=Se?(0,$.jsxs)(`div`,{ref:oe,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`yuri-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:_.colors.surface.subtle},role:`dialog`,"aria-label":g(`chat.dictation.overlayAria`),children:[m,(0,$.jsx)(`div`,{ref:se,className:Y(`scrollbar-none flex-1 min-h-0 overflow-y-auto px-3`,r?`pt-3.5 pb-2.5`:`pt-5 pb-2`),children:(0,$.jsxs)(`div`,{ref:ce,className:Y(!A&&`translate-y-1.5`),children:[A?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:_.colors.surface.foreground},children:A}):k===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:_.colors.surface.mutedForeground},children:[(0,$.jsx)(Fm,{volume:j}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:Oe})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:_.colors.surface.mutedForeground},children:Oe}),k===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.error},children:N||g(`chat.dictation.failed`)}):null,k===`recording`&&N&&!V?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.warning},children:N}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:le?{height:le}:void 0,children:[k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:_.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:_.colors.status.error}})]}),(0,$.jsx)(Fm,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:Pm(M)})]}):k===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:_.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>we(`insert`),title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-primary hover:text-primary`),onClick:()=>we(`send`),title:g(`chat.dictation.insertAndSend`),"aria-label":g(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:s})})]}):k===`uploading`?(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:B,title:g(`chat.dictation.discard`),"aria-label":g(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:Ee,title:g(`chat.dictation.retry`),"aria-label":g(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),A.trim()?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{C.current=`insert`,z()},title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[62]=z,t[63]=L,t[64]=we,t[65]=_,t[66]=B,t[67]=M,t[68]=N,t[69]=le,t[70]=i,t[71]=a,t[72]=o,t[73]=Se,t[74]=r,t[75]=V,t[76]=A,t[77]=Oe,t[78]=n,t[79]=Ee,t[80]=s,t[81]=k,t[82]=g,t[83]=m,t[84]=j,t[85]=Me):Me=t[85];let Ne;return t[86]!==je||t[87]!==Me?(Ne=(0,$.jsxs)($.Fragment,{children:[je,Me]}),t[86]=je,t[87]=Me,t[88]=Ne):Ne=t[88],Ne};function Rm(e){return e.dictationEnabled}function zm(e){return e.shortcutOverrides}function Bm(){return!b()&&ml()}function Vm(e){return e.preventDefault()}function Hm(e){e.pointerType===`touch`&&e.preventDefault()}function Um(e){let t=(0,Q.c)(11),{kind:n,active:r,className:i}=e,a;t[0]===i?a=t[1]:(a=Y(`relative inline-flex shrink-0 items-center justify-center`,i),t[0]=i,t[1]=a);let o;t[2]===r?o=t[3]:(o=r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`pointer-events-none absolute -inset-1.5 rounded-full bg-[var(--voice-active-fill)]/15 motion-safe:animate-pulse motion-safe:[animation-duration:2.4s]`}),(0,$.jsx)(`span`,{className:`pointer-events-none absolute -inset-1 rounded-full bg-[var(--voice-active-fill)]/25 motion-safe:animate-pulse motion-safe:[animation-delay:300ms] motion-safe:[animation-duration:2.4s]`}),(0,$.jsx)(`span`,{className:`pointer-events-none absolute -inset-0.5 rounded-full bg-[var(--voice-active-fill)]`})]}),t[2]=r,t[3]=o);let s;t[4]!==r||t[5]!==n?(s=n===`mic`?r?(0,$.jsx)(X,{name:`mic-fill`,className:`relative size-full p-0.5 text-[var(--primary-foreground)]`}):(0,$.jsx)(X,{name:`mic`,className:`relative size-full`}):r?(0,$.jsx)(X,{name:`volume-up-fill`,className:`relative size-full p-0.5 text-[var(--primary-foreground)]`}):(0,$.jsx)(X,{name:`volume-up`,weight:`medium`,className:`relative size-full`}),t[4]=r,t[5]=n,t[6]=s):s=t[6];let c;return t[7]!==a||t[8]!==o||t[9]!==s?(c=(0,$.jsxs)(`span`,{"aria-hidden":`true`,className:a,children:[o,s]}),t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function Wm({onInsert:e,onPartial:t,onStart:n,onCancel:r,className:i,iconClassName:a,inputRef:o,onRecordingChange:s,onActiveChange:c,interactionMode:l=`desktop`,disabled:u=!1}){let{t:d}=Xn(),f=K(e=>e.shortcutOverrides),p=Bc(Nc(`toggle_dictation`,f)),m=ul({onTranscript:e,onPartialTranscript:t}),h=(0,Z.useRef)(!1),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),b=g||m.isStarting,x=m.status===`recording`,S=m.status===`uploading`,C=l===`mobile`,w=b||v||S,T=x||w,E=J(e=>c?.(e));(0,Z.useEffect)(()=>(E(T),()=>E(!1)),[T,E]);let D=(0,Z.useRef)(null),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),j=(0,Z.useRef)({x:0,y:0}),M=J(e=>s?.(e));(0,Z.useEffect)(()=>(M(x&&(C||!w)),()=>M(!1)),[x,w,C,M]);let N=(0,Z.useRef)(0);(0,Z.useEffect)(()=>()=>{N.current+=1},[]);let P=J(async(e=!1)=>{if(v)return;let t=o?.current,n=N.current;h.current=!1,y(!0);try{await m.confirmDictation()}finally{y(!1),e&&!C&&n===N.current&&t?.isConnected&&o?.current===t&&!t.disabled&&!t.readOnly&&!document.hidden&&document.hasFocus()&&(document.activeElement===document.body||document.activeElement===t||k.current?.contains(document.activeElement))&&(t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}}),F=J(()=>{D.current=null,x&&(h.current=!1,P())}),I=J(async()=>{if(!(v||S)){if(x){F();return}if(!(S||b||u)){m.status===`failed`&&(r(),m.discardFailedDictation()),h.current=!1,n(),_(!0);try{await m.startDictation(),h.current=!0}finally{_(!1)}}}}),[,L,R]=Gn(()=>{let e=O.current;O.current=null;let t=o?.current;!e||!t||t.disabled||t.readOnly||u||T||t.selectionStart!==t.selectionEnd||(D.current=e.id,k.current?.setPointerCapture?.(e.id),t.blur(),t.setSelectionRange(t.value.length,t.value.length),I())},500,{immediate:!1}),z=J(()=>{O.current&&(O.current=null,R())});Wn(`pointerdown`,e=>{if(C)return;let t=o?.current;!t||e.target!==t||t.disabled||t.readOnly||e.pointerType!==`mouse`||e.button!==0||e.detail>1||u||T||D.current!==null||(O.current={id:e.pointerId,x:e.clientX,y:e.clientY},j.current={x:e.clientX,y:e.clientY},L())},window,{capture:!0}),Wn(`pointermove`,e=>{let t=O.current;t?.id===e.pointerId&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>6&&z(),D.current===e.pointerId&&(e.preventDefault(),j.current={x:e.clientX,y:e.clientY},A.current&&(A.current.style.transform=`translate(${e.clientX}px, ${e.clientY}px)`))},window,{capture:!0}),Wn(`selectstart`,e=>{D.current!==null&&e.preventDefault()},document,{capture:!0}),Wn(`mousemove`,e=>{D.current!==null&&e.preventDefault()},window,{capture:!0}),Wn(`selectionchange`,()=>{if(D.current===null)return;let e=o?.current;e&&e.selectionStart!==e.selectionEnd&&e.setSelectionRange(e.selectionEnd,e.selectionEnd);let t=document.getSelection();t&&!t.isCollapsed&&t.removeAllRanges()},document),Wn(`pointerup`,e=>{O.current?.id===e.pointerId&&z(),D.current===e.pointerId&&e.button===0&&(D.current=null,h.current=!1,P(!0))},window,{capture:!0}),Wn(`pointercancel`,e=>{O.current?.id===e.pointerId&&z(),D.current===e.pointerId&&(D.current=null,h.current=!1,r(),m.cancelDictation())},window,{capture:!0});let B=J(()=>{D.current!==null&&(D.current=null,h.current=!1,P())});Wn(`blur`,()=>{C||(z(),D.current===null?h.current&&F():B())},window),Wn(`visibilitychange`,()=>{C||document.hidden&&(z(),D.current===null?h.current&&F():B())},document),Wn(C?`yuri:mobile-dictation-toggle`:`yuri:dictation-toggle`,()=>{I()},window),Wn(`keydown`,e=>{if(!C&&(z(),!(e.isComposing||e.keyCode===229))){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&(x||S)){e.preventDefault(),e.stopPropagation(),e.repeat||F();return}e.key!==`Escape`||!x&&!S&&m.status!==`failed`||(e.preventDefault(),e.stopPropagation(),h.current=!1,D.current=null,r(),m.status===`failed`?m.discardFailedDictation():m.cancelDictation())}},window,{capture:!0});let V=d(x?`settings.voice.volcengine.finishRecording`:S?`chat.dictation.processing`:`chat.dictation.start`);return(0,$.jsxs)(`div`,{ref:k,"data-dictation-control":!0,className:`relative flex shrink-0 items-center gap-1.5`,children:[!C&&(x||b)&&D.current!==null&&(0,bp.createPortal)((0,$.jsxs)(`span`,{ref:A,"data-listening-cursor":!0,"aria-hidden":`true`,className:`pointer-events-none fixed left-0 top-0 z-[100]`,style:{transform:`translate(${j.current.x}px, ${j.current.y}px)`},children:[(0,$.jsx)(`style`,{children:`html, html * { cursor: none !important; user-select: none !important; -webkit-user-select: none !important; } @keyframes yuri-listening-cursor { from { transform: scaleY(0.35); } to { transform: scaleY(1); } }`}),(0,$.jsx)(`span`,{className:`absolute -left-5 -top-5 flex size-10 items-center justify-center gap-1`,children:b?(0,$.jsx)(wl,{decorative:!0}):[0,1,2].map(e=>(0,$.jsx)(`span`,{className:`h-6 w-[3px] rounded-full bg-[var(--voice-active-fill)] motion-safe:animate-[yuri-listening-cursor_450ms_ease-in-out_infinite_alternate]`,style:{animationDelay:`${e*-150}ms`}},e))})]}),document.body),(0,$.jsxs)(tc,{delayDuration:0,children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{variant:`ghost`,size:`icon`,className:Y(`shadow-none`,i),"aria-label":V,"aria-pressed":x,"aria-busy":w,disabled:S||v||u&&!x,onClick:()=>{I()},onBlur:C?void 0:F,children:w?(0,$.jsx)(wl,{decorative:!0}):(0,$.jsx)(Um,{kind:`mic`,active:x&&!m.error,className:Y(a??`size-5`,m.error&&`text-[var(--status-error)]`)})})}),(0,$.jsx)(ec,{side:`top`,sideOffset:8,className:`yuri-composer-tooltip max-w-64 break-words`,children:m.error||(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(`span`,{children:V}),!C&&p&&(0,$.jsx)(`kbd`,{className:`font-sans text-[10px] opacity-70`,children:p})]})})]}),!C&&x&&!w&&(0,$.jsx)(`span`,{className:`pointer-events-none select-none whitespace-nowrap text-[10px] leading-none text-muted-foreground`,children:d(D.current===null?`chat.dictation.keyboardHint`:`chat.dictation.releaseConfirm`)})]})}var Gm=2e3,Km=L((e,t)=>({pending:!1,expiresAt:null,arm:(t=Gm)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),qm=new class{inFlightByScope=new WeakMap;generationByScope=new WeakMap;run(e){let t=this.inFlightByScope.get(e.scope);t||(t=new Map,this.inFlightByScope.set(e.scope,t));let n=t.get(e.key);if(n)return n;let r=this.generationByScope.get(e.scope);r||(r=new Map,this.generationByScope.set(e.scope,r));let i=(r.get(e.key)??0)+1;r.set(e.key,i);let a=e.request(()=>r?.get(e.key)!==i);return t.set(e.key,a),a.finally(()=>{t?.get(e.key)===a&&t.delete(e.key)}).catch(()=>{}),a}},Jm=e=>yn({queryKey:[e.transport,`sessionChildren`,e.generation,Pn(e.directory),e.sessionID],queryFn:({signal:t})=>e.request(t),staleTime:0,gcTime:6e4,retry:!1}),Ym=e=>xn.fetchQuery(Jm(e)),Xm=(e,t)=>e.id<t.id?-1:+(e.id>t.id),Zm=(e,t,n)=>{let r=new Set(e.map(e=>e.id)),i=t.filter(e=>!e?.id||r.has(e.id)||e.parentID!==n?!1:(r.add(e.id),!0));return i.length===0?e:[...e,...i].sort(Xm)},Qm=30,$m=new Map;function eh(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function th(e,t){let n=Ve();if(!n)return!1;let r=n.getTranscript(oe(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>Sa()}function nh(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function rh(e,t,n){let r=[...e.getState().session],i=Uo.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function ih(){let e=vr(),t=To(),n=Fr(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=Ve();if(!r||!t)return eh({kind:`unknown`,loadedTurns:0},!1);let i=oe(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return eh(a.boundary,o?.status===`loading`)},[e]),a=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let r=n.getChild(e);if(!r)return;let i=r.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_error_at:{...i.session_error_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};$r(a,t),ei(r,t),r.setState(a);for(let n of t)ut(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=$m.get(t);if(n)return $m.delete(t),$m.set(t,n),n;let r=new Set;for($m.set(t,r);$m.size>Qm;){let e=$m.keys().next().value;if(!e)break;let t=[...$m.get(e)??[]];$m.delete(e),a(e,t)}return r},[e,a]),l=(0,Z.useCallback)((r,i=e)=>{let o=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=Ti(o.getState()),u=bi(),d=ls({seen:c,keep:r,limit:u,preserve:l});if(a(i,d),sr()){let e=new Set([r,...c,...l]),t=(Ve()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),n=(t.length>0?t:Array.from(c)).filter(t=>t===r||e.has(t)?!1:th(i,t));if(n.length>0){for(let e of n)c.delete(e);a(i,n)}}},[n,e,s,a,t]),u=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await st(a,r):await Ae(a,r,{background:!0})}catch{return}if(i?.isStale?.())return;let u=Ve()?.getTranscript(oe(a,r));Dr({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await Gi({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),d=(0,Z.useCallback)(async(t,i)=>{await qa();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),c=se.getScopedSdkClient(o);l(t,o);let d=r(t,o);return qm.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Ve(),i=oe(o,t),l=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Uo.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&l&&d.kind!==`unknown`&&p?.status!==`error`&&f&&co(o,t)){Dr({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!l||f),h=nh({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Xa(async()=>c.session.get({sessionID:t}));if(n&&!e()){let r=li(xe(n));e()||rh(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?u(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,l,u,e]),f=J(async(t,r)=>{let i=r||e;if(!t||!i)return;let a=n.ensureChild(i,{bootstrap:!1}),s=se.getScopedSdkClient(i),l=c(),u=o(),d=()=>l!==c()||u!==o()||n.getChild(i)!==a,f=await Ym({transport:u,generation:l,directory:i,sessionID:t,request:async e=>{let n=[],r=new Set,a;do{if(e.throwIfAborted(),l!==c()||u!==o())throw new DOMException(`Session children runtime changed`,`AbortError`);let d=await s.session.list(a?{cursor:a,limit:50}:{directory:i,parentID:t,limit:50},{signal:e});if(!Array.isArray(d?.data))throw Error(`session.list children returned no data`);if(n.push(...d.data.map(xe)),d.data.length<50)break;if(a=d.cursor?.next??void 0,!a||r.has(a))throw Error(`session.list children pagination did not advance`);r.add(a)}while(a);return n}}).catch(e=>{if(d())return null;throw e});!f||d()||a.setState(e=>{let n=Zm(e.session,f,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})}),p=(0,Z.useCallback)((t,n)=>{let r=i(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,i]),m=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).loading,[e,i]),h=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).complete,[e,i]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;Ye(oe(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;Ye(oe(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(t=>{let n=t.directory||e;Ye(oe(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),y=J(async(t,r)=>{if(!t)return;await qa();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),s=c(),l=o(),u=()=>s!==c()||l!==o()||n.ensureChild(i,{bootstrap:!1})!==a,d=a.getState();try{if(await Ae(i,t),u())return;Dr({directory:i,sessionID:t,store:a}),await Gi({directory:i,sessionID:t,store:a,statusBeforePull:d.session_status?.[t],statusObservedAtBeforePull:d.session_status_observed_at?.[t],hasMessages:(Ve()?.getTranscript(oe(i,t)).messageOrder.length??0)>0,isStale:u})}catch{throw Error(`refresh transcript failed`)}});return(0,Z.useMemo)(()=>({ensureSessionRenderable:d,syncSession:d,loadChildren:f,hasMore:p,isLoading:m,isComplete:h,refreshSessionTranscript:y,optimistic:{add:g,remove:_,confirm:v}}),[d,f,p,m,h,y,g,_,v])}var ah=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,oh=e=>e===`original`||e===`modified`,sh=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},ch=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!ah(t.source))return null;let n=sh(t.startLine),r=sh(t.endLine);return!n||!r?null:{id:typeof t.id==`string`&&t.id.trim().length>0?t.id:`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,sessionKey:t.sessionKey,source:t.source,fileLabel:typeof t.fileLabel==`string`?t.fileLabel:`unknown`,startLine:n,endLine:r,side:oh(t.side)?t.side:void 0,code:typeof t.code==`string`?t.code:``,language:typeof t.language==`string`?t.language:`text`,text:typeof t.text==`string`?t.text:``,createdAt:Number.isFinite(t.createdAt)?Number(t.createdAt):Date.now()}},lh=e=>{if(!e||typeof e!=`object`)return{};let t=Object.entries(e),n={};for(let[e,r]of t){if(!Array.isArray(r))continue;let t=r.map(ch).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},uh=L()(B(R((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`yuri-inline-comment-drafts`,storage:ht(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:lh(e.drafts)}}),{name:`inline-comment-draft-store`}));function dh(e){let{fileLabel:t,startLine:n,endLine:r,side:i,language:a,code:o,text:s}=e;return e.source===`diff`&&i?`Comment on \`${t}\` lines ${n}-${r} (${i}):\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`:e.source===`preview-console`?`Attached preview context from \`${t}\`:\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`:e.source===`preview-annotation`?s?`${o}\n\n${s}`:o:`Comment on \`${t}\` lines ${n}-${r}:\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`}function fh(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(dh).join(`
5
5
 
@@ -6539,7 +6539,7 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}f
6539
6539
 
6540
6540
  `),`Follow-up question:`,lw(t)].join(`
6541
6541
 
6542
- `)},dw=(e,t,n,r,i)=>{if(ew(e,n)&&XC===r.epoch){if(o()!==r.transport||c()!==r.generation){sw(e,t,{pending:!1});return}sw(e,t,i)}},fw=e=>{let t=typeof e.sessionId==`string`?e.sessionId.trim():``;return t?{sessionId:t,directory:typeof e.directory==`string`&&e.directory.trim()?e.directory:e.directory??null}:null},pw=e=>{let t=JC.get(e);t&&(rw(e),sw(e,t.turnId,{pending:!1}))},mw=e=>{let t=fw(e);if(!t)return null;let n=qC(t),r=ww.getState().sendSelection[n];if(r?.providerID&&r?.modelID)return r;let i=wi.getState().getSessionModelSelection(t.sessionId);if(i)return{providerID:i.providerId,modelID:i.modelId,agent:wi.getState().getSessionAgentSelection(t.sessionId)??void 0};let a=ni.getState();return a.currentProviderId&&a.currentModelId?{providerID:a.currentProviderId,modelID:a.currentModelId,agent:a.currentAgentName??void 0,variant:a.currentVariant??null}:null},hw=async e=>{let t=mw({sessionId:e.sessionId,directory:e.directory});if(!t)return;let n=typeof t.variant==`string`&&t.variant.trim()?t.variant.trim():void 0;await se.applySendSelection(e.sessionId,{model:{providerID:t.providerID,id:t.modelID,...n?{variant:n}:{}},...t.agent?{agent:t.agent}:{}},e.directory)},gw=(e,t)=>{let n=fw(e);if(!n)return;let r=qC(n);ww.setState(e=>({sendSelection:{...e.sendSelection,[r]:t}})),wi.getState().saveSessionModelSelection(n.sessionId,t.providerID,t.modelID),t.agent&&wi.getState().saveSessionAgentSelection(n.sessionId,t.agent)},_w=async(e,t,n,r)=>{let i=n.id,a={epoch:XC,transport:o(),generation:c()},s=new AbortController;JC.set(t,{controller:s,turnId:i});try{if(await hw(e),!ew(t,s))return;let o=await se.generateSessionAside({sessionId:e.sessionId,directory:e.directory,prompt:uw(r,n),signal:s.signal}),c=typeof o?.text==`string`?o.text.trim():``;dw(t,i,s,a,c?{answer:c,error:null,pending:!1}:{answer:``,error:`empty response`,pending:!1})}catch(e){dw(t,i,s,a,$C(e,s.signal)?{pending:!1}:{error:QC(e),pending:!1})}finally{ew(t,s)&&JC.delete(t)}},vw=async(e,t)=>{let n=typeof t==`string`?t.trim():``,r=fw(e);if(!n||!r)return;let i=qC(r);pw(i);let a=ww.getState().entries[i]??KC;ZC+=1;let o={id:`btw_${ZC}`,quotes:a.quotes,question:n,answer:``,error:null,pending:!0};aw(i,e=>({turns:[...e.turns,o].slice(-50),quotes:KC.quotes})),await _w(r,i,o,a.turns)},yw=async e=>{let t=fw(e);if(!t)return;let n=qC(t),r=ww.getState().entries[n]?.turns??[],i=r[r.length-1];i&&(pw(n),sw(n,i.id,{answer:``,error:null,pending:!0}),await _w(t,n,i,r.slice(0,-1)))},bw=(e,t)=>{let n=typeof t==`string`?t.trim():``;!n||!fw(e)||aw(qC(e),e=>e.quotes.includes(n)?null:{...e,quotes:[...e.quotes,n].slice(-10)})},xw=(e,t)=>{let n=qC(e);ww.getState().entries[n]&&aw(n,e=>t<0||t>=e.quotes.length?null:{...e,quotes:e.quotes.filter((e,n)=>n!==t)})},Sw=e=>{pw(qC(e))},Cw=e=>{let t=qC(e);rw(t),YC=YC.filter(e=>e!==t),ww.setState(e=>{let n=t in e.entries,r=t in e.sendSelection;if(!n&&!r)return e;let i=n?{...e.entries}:e.entries,a=r?{...e.sendSelection}:e.sendSelection;return n&&delete i[t],r&&delete a[t],{entries:i,sendSelection:a}})},ww=L(()=>({entries:{},sendSelection:{},setSendSelection:gw,ask:vw,retry:yw,cancel:Sw,addQuote:bw,removeQuote:xw,clear:Cw})),Tw=()=>{XC+=1;for(let{controller:e}of JC.values())e.abort();JC.clear(),YC=[],ww.setState({entries:{},sendSelection:{}})},Ew=(e=>{let t=new Map,n=()=>{let e=0;for(let n of t.values())e+=n;return e};return{hold(r){let i=(t.get(r)??0)+1;t.set(r,i),n()===1&&e.conceal();let a=!1;return()=>{if(a)return;a=!0;let i=(t.get(r)??1)-1;i<=0?t.delete(r):t.set(r,i),n()===0&&e.reveal()}}}})(Du),Dw=new Map,Ow=e=>Ew.hold(e),kw=e=>{Dw.has(e)||Dw.set(e,Ew.hold(e))},Aw=e=>{let t=Dw.get(e);t&&(Dw.delete(e),t())},jw=`btw-page`,Mw=`btw-sheet`,Nw=`text-selection`,Pw=`1.5rem`,Fw=`box-border w-full whitespace-pre-wrap break-words px-3 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit] md:typography-ui-label pt-4 pb-2`,Iw=`box-border w-full whitespace-pre-wrap break-words px-3 py-2.5 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit]`;function Lw(e){let t=(0,Q.c)(40),{turn:n,isLast:r,scope:i}=e,{t:a}=Xn(),o;t[0]!==a||t[1]!==n.error?(o=n.error===`empty response`||n.error===`session.btw failed`?a(`chat.btw.failed`):n.error,t[0]=a,t[1]=n.error,t[2]=o):o=t[2];let s=o,c=!n.pending&&!n.error&&!n.answer,l;t[3]!==a||t[4]!==n.answer?(l=async()=>{(await Yn(n.answer)).ok?Yr.success(a(`contextSidebar.actions.copied`)):Yr.error(a(`filesView.toast.copyFailed`))},t[3]=a,t[4]=n.answer,t[5]=l):l=t[5];let u=J(l),d=n.id,f;t[6]===n.quotes?f=t[7]:(f=n.quotes.map(Rw),t[6]=n.quotes,t[7]=f);let p;t[8]===n.question?p=t[9]:(p=(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words typography-markdown text-foreground`,children:n.question}),t[8]=n.question,t[9]=p);let m;t[10]!==f||t[11]!==p?(m=(0,$.jsxs)(`div`,{className:`ml-8 flex flex-col gap-1.5 self-end rounded-xl bg-[var(--surface-elevated)] px-3 py-2`,children:[f,p]}),t[10]=f,t[11]=p,t[12]=m):m=t[12];let h;t[13]!==a||t[14]!==n.pending?(h=n.pending?(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),a(`chat.btw.pending`)]}):null,t[13]=a,t[14]=n.pending,t[15]=h):h=t[15];let g;t[16]===s?g=t[17]:(g=s?(0,$.jsxs)(`p`,{role:`alert`,className:`whitespace-pre-wrap break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`mr-1.5 inline size-3.5 align-[-2px] text-[var(--status-error)]/85`,"aria-hidden":`true`}),s]}):null,t[16]=s,t[17]=g);let _;t[18]!==c||t[19]!==a?(_=c?(0,$.jsx)(`p`,{role:`status`,className:`typography-meta text-muted-foreground`,children:a(`chat.btw.cancelled`)}):null,t[18]=c,t[19]=a,t[20]=_):_=t[20];let v;t[21]===n.answer?v=t[22]:(v=n.answer?(0,$.jsx)(`div`,{className:`min-w-0 text-foreground`,children:(0,$.jsx)(Ju,{content:n.answer,enableFileReferences:!1})}):null,t[21]=n.answer,t[22]=v);let y;t[23]!==c||t[24]!==u||t[25]!==s||t[26]!==r||t[27]!==i||t[28]!==a||t[29]!==n.answer||t[30]!==n.pending?(y=!n.pending&&(n.answer||r&&(s||c))?(0,$.jsxs)(`div`,{className:`-ml-2 flex items-center gap-0.5`,children:[n.answer?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:u,"aria-label":a(`contextSidebar.actions.copy`),children:(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`})}):null,r?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:()=>void ww.getState().retry(i),"aria-label":a(`contextPanel.preview.actions.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`})}):null]}):null,t[23]=c,t[24]=u,t[25]=s,t[26]=r,t[27]=i,t[28]=a,t[29]=n.answer,t[30]=n.pending,t[31]=y):y=t[31];let b;return t[32]!==v||t[33]!==y||t[34]!==m||t[35]!==h||t[36]!==g||t[37]!==_||t[38]!==n.id?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-btw-turn":d,children:[m,h,g,_,v,y]}),t[32]=v,t[33]=y,t[34]=m,t[35]=h,t[36]=g,t[37]=_,t[38]=n.id,t[39]=b):b=t[39],b}function Rw(e,t){return(0,$.jsx)(`p`,{"data-btw-quote":!0,"data-conversation-quote":!0,className:`m-0 whitespace-pre-wrap break-words border-l-2 border-border pl-1.5 typography-meta text-muted-foreground`,children:e},t)}function zw(e){let t=(0,Q.c)(64),{scope:n,pending:r,quotes:i,foot:a}=e,{t:o}=Xn(),s;t[0]===n?s=t[1]:(s=e=>e.sendSelection[qC(n)],t[0]=n,t[1]=s);let c=ww(s),l;t[2]!==n||t[3]!==c?(l=c??mw(n),t[2]=n,t[3]=c,t[4]=l):l=t[4];let u=l,d=ni(Bw),f;bb0:{if(!u?.providerID||!u?.modelID){f=null;break bb0}let e;if(t[5]!==d||t[6]!==u.modelID||t[7]!==u.providerID){let n;t[9]===u.providerID?n=t[10]:(n=e=>e.id===u.providerID,t[9]=u.providerID,t[10]=n);let r=d.find(n);e=qr(r,u.modelID)||u.modelID,t[5]=d,t[6]=u.modelID,t[7]=u.providerID,t[8]=e}else e=t[8];f=e}let p=f,[m,h]=Z.useState(``),g=Z.useRef(null),_,v;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{let e=window.requestAnimationFrame(()=>{g.current?.focus({preventScroll:!0})});return()=>window.cancelAnimationFrame(e)},v=[],t[11]=_,t[12]=v):(_=t[11],v=t[12]),Z.useEffect(_,v);let y;t[13]!==m||t[14]!==r||t[15]!==n?(y=()=>{let e=m.trim();!e||r||(h(``),ww.getState().ask(n,e))},t[13]=m,t[14]=r,t[15]=n,t[16]=y):y=t[16];let b=J(y),x;t[17]!==p||t[18]!==u?(x=u&&p?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5 rounded-lg px-2.5 py-1`,"aria-label":p,children:[(0,$.jsx)(Ps,{modelId:u.modelID,providerId:u.providerID,className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-meta font-medium text-foreground`,children:p})]}):null,t[17]=p,t[18]=u,t[19]=x):x=t[19];let S=x,C=a!==`panel`,w=C?`yuri-mobile-composer`:`pb-3`,T=a===`page`?`bottom-safe-area`:``,E;t[20]!==w||t[21]!==T?(E=[`shrink-0 px-3 pt-1`,w,T].filter(Boolean),t[20]=w,t[21]=T,t[22]=E):E=t[22];let D=E.join(` `),O;t[23]===b?O=t[24]:(O=e=>{e.preventDefault(),b()},t[23]=b,t[24]=O);let k;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(k=e=>h(e),t[25]=k):k=t[25];let A;t[26]===n?A=t[27]:(A=()=>ww.getState().cancel(n),t[26]=n,t[27]=A);let j;t[28]===o?j=t[29]:(j=o(`chat.btw.placeholder`),t[28]=o,t[29]=j);let M;t[30]===o?M=t[31]:(M=o(`chat.chatInput.actions.sendMessageAria`),t[30]=o,t[31]=M);let N;t[32]===o?N=t[33]:(N=o(`chat.statusRow.actions.stopGeneratingAria`),t[32]=o,t[33]=N);let P;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(P={autoFocus:!0},t[34]=P):P=t[34];let F=C?`relative z-10 yuri-mobile-composer-surface`:`relative z-10`,I;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(I={borderRadius:Pw},t[35]=I):I=t[35];let L=C?Iw:Fw,R;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(R={borderTopLeftRadius:Pw,borderTopRightRadius:Pw},t[36]=R):R=t[36];let z;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(z={borderBottomLeftRadius:Pw,borderBottomRightRadius:Pw},t[37]=z):z=t[37];let B;t[38]===o?B=t[39]:(B=o(`chat.btw.removeQuoteAria`),t[38]=o,t[39]=B);let V;t[40]===n?V=t[41]:(V=e=>ww.getState().removeQuote(n,e),t[40]=n,t[41]=V);let H;t[42]!==i||t[43]!==B||t[44]!==V?(H=(0,$.jsx)(Lh,{quotes:i,removeLabel:B,onRemove:V}),t[42]=i,t[43]=B,t[44]=V,t[45]=H):H=t[45];let U;t[46]!==m||t[47]!==C||t[48]!==S||t[49]!==r||t[50]!==b||t[51]!==A||t[52]!==j||t[53]!==M||t[54]!==N||t[55]!==F||t[56]!==L||t[57]!==H?(U=(0,$.jsx)(Ul,{value:m,onChange:k,onSubmit:b,onStop:A,pending:r,disableInputWhilePending:!1,isMobile:C,placeholder:j,sendLabel:M,stopLabel:N,inputRef:g,textareaProps:P,leftControls:S,className:F,style:I,textLayoutClassName:L,inputStyle:R,footerClassName:`z-30 bg-transparent flex-shrink-0 px-2.5 py-1.5`,footerStyle:z,inputHeader:H}),t[46]=m,t[47]=C,t[48]=S,t[49]=r,t[50]=b,t[51]=A,t[52]=j,t[53]=M,t[54]=N,t[55]=F,t[56]=L,t[57]=H,t[58]=U):U=t[58];let W;return t[59]!==a||t[60]!==D||t[61]!==O||t[62]!==U?(W=(0,$.jsx)(`form`,{"data-btw-composer":!0,"data-btw-composer-foot":a,className:D,onSubmit:O,children:U}),t[59]=a,t[60]=D,t[61]=O,t[62]=U,t[63]=W):W=t[63],W}function Bw(e){return e.providers}function Vw(e){let t=(0,Q.c)(29),{scope:n,foot:r}=e,i=r===void 0?`panel`:r,{t:a}=Xn(),o;t[0]===n?o=t[1]:(o=qC(n),t[0]=n,t[1]=o);let s=o,c;t[2]===s?c=t[3]:(c=e=>(e.entries[s]??KC).turns,t[2]=s,t[3]=c);let l=ww(c),u;t[4]===s?u=t[5]:(u=e=>(e.entries[s]??KC).quotes,t[4]=s,t[5]=u);let d=ww(u),f;t[6]===l?f=t[7]:(f=l.some(Hw),t[6]=l,t[7]=f);let p=f,m=Z.useRef(null),h=l[l.length-1],g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},t[8]=g):g=t[8];let _=h?.answer,v=h?.pending,y;t[9]!==_||t[10]!==v||t[11]!==l.length?(y=[l.length,_,v],t[9]=_,t[10]=v,t[11]=l.length,t[12]=y):y=t[12],Z.useLayoutEffect(g,y);let b;t[13]===a?b=t[14]:(b=a(`chat.btw.title`),t[13]=a,t[14]=b);let x;t[15]!==n||t[16]!==a||t[17]!==l?(x=(0,$.jsx)(`div`,{ref:m,className:`overlay-scrollbar-container min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-3`,children:l.length===0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:a(`chat.btw.description`)}):(0,$.jsx)(`div`,{className:`flex flex-col gap-5`,children:l.map((e,t)=>(0,$.jsx)(Lw,{turn:e,isLast:t===l.length-1,scope:n},e.id))})}),t[15]=n,t[16]=a,t[17]=l,t[18]=x):x=t[18];let S;t[19]!==i||t[20]!==s||t[21]!==p||t[22]!==d||t[23]!==n?(S=(0,$.jsx)(zw,{scope:n,pending:p,quotes:d,foot:i},s),t[19]=i,t[20]=s,t[21]=p,t[22]=d,t[23]=n,t[24]=S):S=t[24];let C;return t[25]!==b||t[26]!==x||t[27]!==S?(C=(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-col text-foreground`,"aria-label":b,children:[x,S]}),t[25]=b,t[26]=x,t[27]=S,t[28]=C):C=t[28],C}function Hw(e){return e.pending}function Uw(e){let t=(0,Q.c)(53),{scope:n,active:r,mobile:i}=e,{t:a}=Xn(),{sessionId:o,directory:s}=n,c;t[0]===n?c=t[1]:(c=qC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===s?u=t[3]:(u=Pn(s),t[2]=s,t[3]=u);let d=u,f;t[4]===d?f=t[5]:(f=e=>e.contextPanelByDirectory[d],t[4]=d,t[5]=f);let p=K(f),m;t[6]!==r||t[7]!==p?(m=r&&!!(p?.isOpen&&p.tabs.find(e=>e.id===p.activeTabId)?.mode===`btw`),t[6]=r,t[7]=p,t[8]=m):m=t[8];let h=m,g;t[9]===p?g=t[10]:(g=p?.isOpen&&p.tabs.some(Gw),t[9]=p,t[10]=g);let _=!!g,v;t[11]!==l||t[12]!==_?(v={key:l,retained:_},t[11]=l,t[12]=_,t[13]=v):v=t[13];let y=Z.useRef(v),b,x;t[14]!==l||t[15]!==_||t[16]!==s||t[17]!==o?(b=()=>{let e={sessionId:o,directory:s},t=y.current;y.current={key:l,retained:_},t.key===l&&t.retained&&!_&&ww.getState().clear(e)},x=[l,_,o,s],t[14]=l,t[15]=_,t[16]=s,t[17]=o,t[18]=b,t[19]=x):(b=t[18],x=t[19]),Z.useEffect(b,x);let S=Z.useRef(null),C,w;t[20]!==r||t[21]!==l||t[22]!==s||t[23]!==o?(w=()=>{let e={sessionId:o,directory:s},t={key:l,active:r};S.current=t;let n=()=>so({sessionId:o,directory:s??null});return!r&&!n()&&ww.getState().cancel(e),()=>{let r=ww.getState().entries[l];queueMicrotask(()=>{let i=S.current;i!==t&&i?.key===l&&i.active||n()||qC(e)===l&&ww.getState().entries[l]===r&&ww.getState().cancel(e)})}},C=[l,r,o,s],t[20]=r,t[21]=l,t[22]=s,t[23]=o,t[24]=C,t[25]=w):(C=t[24],w=t[25]),Z.useEffect(w,C);let T;t[26]!==d||t[27]!==n?(T=()=>{ww.getState().clear(n),K.getState().closeContextPanel(d)},t[26]=d,t[27]=n,t[28]=T):T=t[28];let E=J(T),D,O;if(t[29]!==i||t[30]!==h?(D=()=>{if(!i||!h){Aw(Mw);return}return kw(Mw),Ww},O=[i,h],t[29]=i,t[30]=h,t[31]=D,t[32]=O):(D=t[31],O=t[32]),Z.useEffect(D,O),!i)return null;let k;t[33]===E?k=t[34]:(k=e=>{e||E()},t[33]=E,t[34]=k);let A;t[35]===a?A=t[36]:(A=a(`chat.btw.title`),t[35]=a,t[36]=A);let j;t[37]===a?j=t[38]:(j=a(`chat.btw.title`),t[37]=a,t[38]=j);let M;t[39]===a?M=t[40]:(M=a(`gitView.common.close`),t[39]=a,t[40]=M);let N;t[41]===a?N=t[42]:(N=a(`chat.btw.resize`),t[41]=a,t[42]=N);let P;t[43]===n?P=t[44]:(P=(0,$.jsx)(Vw,{scope:n,foot:`sheet`}),t[43]=n,t[44]=P);let F;return t[45]!==h||t[46]!==k||t[47]!==A||t[48]!==j||t[49]!==M||t[50]!==N||t[51]!==P?(F=(0,$.jsx)(yl,{id:`session-btw`,open:h,onOpenChange:k,title:A,ariaLabel:j,closeAriaLabel:M,resizeAriaLabel:N,children:P}),t[45]=h,t[46]=k,t[47]=A,t[48]=j,t[49]=M,t[50]=N,t[51]=P,t[52]=F):F=t[52],F}function Ww(){return Aw(Mw)}function Gw(e){return e.mode===`btw`}var Kw=()=>{typeof window>`u`||window.requestAnimationFrame(()=>{document.querySelector(`[data-btw-composer] textarea`)?.focus()})},qw=e=>{let t=e.directory??null;Ba({sessionId:e.sessionId,directory:t})?kw(jw):K.getState().openContextPanelTab(t??``,{mode:`btw`}),Kw()},Jw=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Yw=async({command:e,consumeCommandText:t,forkSession:n,waitForConnection:r,getDirectoryForSession:i,summarizeSession:a,onCompactError:o,onForkError:s})=>{if(t(),e===`fork`){try{await n()}catch(e){s(e)}return}try{await r();let e=i();if(!e){o();return}await a(e)}catch{o()}},Xw=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,Zw=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&e.delivery!==`queue`&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,Qw=e=>e.surfaceKind!==`primary`||!e.stagedSessionId||!e.stagedMessageId||e.stagedMessageId!==e.blurredMessageId||e.submitInFlight||e.focusHeld||e.overlayOpen||e.focusInsideComposer?{action:`keep`}:{action:`disarm`,sessionId:e.stagedSessionId},$w=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),eT=(e,t)=>{let n=At.getState();return n.bindLegacyQueue(jt(e.sessionID),e),n.stageAdmission(e,{requestID:t.requestID,queueItemID:t.queueItemID,operationID:t.operationID,messageID:t.messageID,content:t.content,createdAt:t.createdAt,attachmentCount:t.attachments.length,...t.composerDocument?{composerDocument:t.composerDocument}:{},...t.composerMentions?{composerMentions:t.composerMentions}:{}}),n.confirmAdmission(e,{requestID:t.requestID,sendConfig:t.sendConfig,attachments:t.attachments}).ok},tT=async e=>{let t=vi.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=$w(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}eT(n,a)?r+=1:i+=1}catch{try{eT(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},nT=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),rT=e=>{let t=e.ctrlEnter&&e.canQueue&&e.primary&&e.sessionIsRunning&&!e.autoReviewRunning;return e.followUpBehavior===`queue`?t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:e.primary?{kind:`submit`,delivery:`queue`}:e.queueUsable?{kind:`queue`}:{kind:`submit`,delivery:`steer`}:t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:{kind:`submit`,delivery:`steer`}},iT=e=>Object.prototype.hasOwnProperty.call(e,`permissions`)?e.permissions:e.permission,aT=e=>{let t=lc(e);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n){if(n.action===`*`&&n.resource===`*`)return n.effect===`ask`;if(n.effect===`ask`)return!0}}return!0},oT=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>aT(iT(e)));let r=e.find(e=>e?.name===n);return!r||aT(iT(r))},sT=e=>{let{permissionScopeSessionId:t,newSessionDraftOpen:n,draftPermissionAutoAcceptEnabled:r,permissionAutoAcceptEnabled:i,setDraftPermissionAutoAcceptEnabled:a,setSessionAutoAccept:o,onOpenSessionFirst:s,onToggleFailed:c}=e;if(!t){if(!n){s();return}a(!r);return}o(t,!i).catch(c)},cT=null,lT=new Set,uT=()=>{for(let e of lT)e()},dT=e=>e===`chat`||e===`assistant`,fT=()=>cT,pT=e=>{cT!==e&&(cT=e,uT())},mT=e=>{cT&&(e&&cT.surfaceID!==e||(cT=null,uT()))},hT=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},gT=e=>{let t=e.options?.delivery===`steer`?`steer`:e.options?.delivery===`queue`?`queue`:void 0,n={...t?{delivery:t}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},r=e.options?.sessionId??e.sessionID??void 0;if(!r)return n;let i=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...n,sessionId:r,directoryHint:i}},_T=(e,t,n={})=>({operation:t,surfaceID:e.surfaceID,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration,sessionID:e.sessionID,directory:e.directory??``,draftKey:e.draftKey,deliveryTarget:e.deliveryTarget,...n}),vT=e=>{if(!e.active||!e.draftKey||!e.directory)return null;let t=e.activity?.phase??`idle`,n=e.activity?.canAbort??(t===`busy`||t===`retry`);return{send:async t=>{let n=_T(e,`send`,t);return await e.selection.flush(),e.kind===`secondary`&&await e.shortcuts.submit(),e.backend.send(n)},sendQueued:async(t,n={})=>{let{manual:r,...i}=n,a=_T(e,`send`,i),o=Iy(e);if(await e.selection.flush(),!o)throw Error(`chat-input-queue-scope-incomplete`);return e.backend.sendQueued({...a,queueItemID:t,manual:r,queueScope:o})},create:async()=>{let t=_T(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=_T(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=_T(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Iy(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>ky(e,{name:t,source:`yuri`}),shortcut:async(t,n=1)=>{if(e.kind===`secondary`){t===`cycle`?await e.shortcuts.cycle(n):t===`new`?await e.shortcuts.new():t===`abort`?await e.shortcuts.abort():await e.shortcuts.submit();return}if(t===`abort`){let t=_T(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=_T(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},yT=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let i=r??t.currentAgentName;i&&e.providerID&&e.modelID&&t.saveAgentModelSelection(i,e.providerID,e.modelID,e.variant);let a=n?.sessionId,o=n?.memory;!a||!o||!e.providerID||!e.modelID||(o.saveSessionModelSelection(a,e.providerID,e.modelID),i&&o.saveSessionAgentSelection&&o.saveSessionAgentSelection(a,i),i&&(o.saveAgentModelForSession(a,i,e.providerID,e.modelID),o.saveAgentModelVariantForSession(a,i,e.providerID,e.modelID,e.variant)))},bT=(e,t,n)=>{let r=e.providers.find(e=>e.id===t);return r?(Array.isArray(r.models)?r.models:[]).some(e=>e.id===n):!1},xT=(e,t)=>e.agents.some(e=>e.name===t),ST=(e,t,n,r)=>{if(!r)return!0;let i=e.providers.find(e=>e.id===t)?.models?.find(e=>e.id===n)?.variants;return i?Array.isArray(i)?i.includes(r):typeof i==`object`&&Object.prototype.hasOwnProperty.call(i,r):!1},CT=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return ST(t,n,r,i)?i:void 0;if(a&&ST(t,n,r,a))return a},wT=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!bT(r,n.providerID,n.modelID))return null;let s=n.agent&&xT(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&xT(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&xT(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=CT({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:c});return{agent:s,providerID:n.providerID,modelID:n.modelID,variant:l,source:o,messageId:n.id}},TT=e=>{let{sessionId:t,latestUserChoice:n,latestExecution:r,catalog:i,memory:a,sessionEntity:o,fallbackAgentName:s,transcriptReady:c=!0}=e;if(c&&r){let e=wT({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=wT({sessionId:t,choice:n,catalog:i,memory:a,fallbackAgentName:s,source:`history`});if(e)return e}if(c&&a){let e=a.getSessionAgentSelection?.(t)??null,n=e&&xT(i,e)?e:s&&xT(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&bT(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&ST(i,e.providerId,e.modelId,r)?r:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let r=a.getSessionModelSelection?.(t);if(r&&bT(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&ST(i,r.providerId,r.modelId,e)?e:void 0;return{agent:n,providerID:r.providerId,modelID:r.modelId,variant:o,source:`session-memory`}}}let l=o?.model;if(l&&bT(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&xT(i,o.agent)?o.agent:void 0)??(e&&xT(i,e)?e:s&&xT(i,s)?s:void 0),r=l.variant,c=r&&ST(i,l.providerID,l.id,r)?r:void 0;return{agent:n,providerID:l.providerID,modelID:l.id,variant:c,source:`session-entity`}}return null},ET=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let{sessionId:i,memory:a}=n;a.saveSessionModelSelection(i,e.providerID,e.modelID);let o=r??t.currentAgentName;o&&a.saveSessionAgentSelection&&a.saveSessionAgentSelection(i,o),o&&(a.saveAgentModelForSession(i,o,e.providerID,e.modelID),a.saveAgentModelVariantForSession(i,o,e.providerID,e.modelID,e.variant))},DT=(e,t)=>{if((t?.expectedConfigKey===void 0||t.activeDirectoryKey===t.expectedConfigKey)&&!(!e.currentProviderId||!e.currentModelId))return{providerID:e.currentProviderId,modelID:e.currentModelId,agent:e.currentAgentName,variant:e.currentVariant}},OT=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,kT=e=>{if(e.captured?.providerID&&e.captured?.modelID)return e.captured;let t=e.surfaceSelection;if(!(!t?.providerID||!t?.modelID))return{providerID:t.providerID,modelID:t.modelID,...t.agent?{agent:t.agent}:{},...t.variant?{variant:t.variant}:{}}},AT=e=>typeof e==`string`&&e.trim().length>0?e:void 0,jT=e=>AT(e.agent)??AT(e.mode),MT=e=>AT(typeof e.model==`object`?e.model?.variant:void 0)??AT(e.variant),NT=e=>{let t=typeof e.model==`object`?e.model:void 0,n=AT(e.providerID)??AT(t?.providerID),r=AT(e.modelID)??AT(t?.modelID)??AT(t?.id);return!n||!r?null:{providerID:n,modelID:r}},PT=e=>NT(e),FT=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`||n.nativeType===`synthetic`||n.type===`synthetic`)continue;let r=NT(n);return{id:typeof n.id==`string`?n.id:void 0,agent:jT(n),providerID:r?.providerID,modelID:r?.modelID,variant:MT(n)}}return null},IT=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.nativeType===`synthetic`||n.type===`synthetic`)continue;if(n.role===`user`){if(NT(n))return null;continue}if(n.role!==`assistant`)continue;let r=PT(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:jT(n),providerID:r.providerID,modelID:r.modelID,variant:MT(n)}}return null},LT=500,RT=e=>Array.from(e).length,zT=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},BT=e=>RT(e)>=LT,VT=e=>{let t=Ht(e.text,e.references).document.references,n=t.reduce((e,t)=>{let n=t.kind===`paste`?t.index:0;return typeof n==`number`&&Number.isSafeInteger(n)&&n>=1?Math.max(e,n):e},0);if(n<2**53-1)return n+1;let r=new Set(t.flatMap(e=>e.kind===`paste`&&typeof e.index==`number`&&Number.isSafeInteger(e.index)&&e.index>=1?[e.index]:[]));for(let e=1;e<=t.length+1;e+=1)if(!r.has(e))return e;return 1},HT=(e,t)=>{let n=t??e;return typeof n!=`string`||!BT(n)?!1:Ft(typeof e==`string`?{text:``,references:[]}:e,n)},UT=(e,t,n,r,i=1)=>{let a=RT(e),o=new Set(n.map(e=>e.token));for(let n=i;n<2**53-1;n+=1){let i=`[${r({index:n,count:a})}]`;if(!(t.includes(i)||o.has(i)))return{id:`pasted-text-${n}-${zT(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},WT=e=>({text:e?.text??``,references:e?.composerReferences??[]}),GT=e=>({text:e.text,references:e.references.map(e=>({...e}))}),KT=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),qT=e=>JSON.stringify([e.text,e.references]),JT=(e,t)=>e!==null&&t!==null&&mn(e)===t,YT=(e,t,n)=>{let r=e?KT(e):null,i=r?n(r):void 0;return{document:zt(WT(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?mn(r):null}},XT=(e,t,n,r)=>{if(!t||mn(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=qT(WT(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===qT(e)?`same-document-metadata`:`external-document`},ZT=(e,t,n)=>{let r=n.newEnd-n.oldEnd;return e.flatMap(e=>{if(e.range.start<n.oldEnd&&e.range.end>n.oldStart)return[];let i=e.range.start>=n.oldEnd?{start:e.range.start+r,end:e.range.end+r}:e.range;return t.text.slice(i.start,i.end)===`@${e.value}`?[{...e,range:i}]:[]})},QT=e=>e.map((e,t)=>({mention:e,index:t})).sort((e,t)=>e.mention.range.start-t.mention.range.start||e.mention.range.end-t.mention.range.end||e.index-t.index).map(({mention:e})=>e),$T=(e,t,n,r,i=r)=>{let a=kt(e,n,r,i);return{document:a.document,mentions:ZT(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},eE=(e,t,n)=>({preview:{real:GT(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),tE=e=>({document:e.real,mentions:e.realMentions}),nE=(e,t,n,r)=>{let i=[...e,...t.map(e=>({...e,range:{start:e.range.start+r,end:e.range.end+r}}))],a=new Set;return i.filter(e=>{let t=`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return a.has(t)||n.text.slice(e.range.start,e.range.end)!==`@${e.value}`?!1:(a.add(t),!0)})},rE=(e,t)=>{let n=WT(t),r=Bt(e.document,n),i=e.document.text===n.text&&JSON.stringify(e.document.references)===JSON.stringify(n.references)?0:e.document.text.length+2;return{document:r,mentions:nE(e.mentions,t?.mentions??[],r,i)}},iE=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=fi})=>{let a=e?mn(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>YT(e,t,i.getState().getDraft).document),[d,f]=(0,Z.useState)(()=>YT(e,t,i.getState().getDraft).mentions),[p,m]=(0,Z.useState)(`compose`),[h,g]=(0,Z.useState)(0),_=(0,Z.useRef)(l),v=(0,Z.useRef)(d),y=(0,Z.useRef)(t),b=(0,Z.useRef)(r),x=(0,Z.useRef)(e),S=(0,Z.useRef)(e?KT(e):null),C=(0,Z.useRef)(a),w=(0,Z.useRef)(a),T=(0,Z.useRef)(0),E=(0,Z.useRef)(o?.revision??0),D=(0,Z.useRef)(void 0),O=(0,Z.useRef)(void 0),k=(0,Z.useRef)(Al());_.current=l,v.current=d,y.current=t,b.current=r,x.current=e,C.current=a;let A=(0,Z.useCallback)((e,t)=>{_.current=e,v.current=t,u(e),f(t)},[]),j=(0,Z.useCallback)((e,t)=>{let n=Pt(e,t);b.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{T.current+=1;let e=T.current;w.current=a;let t=YT(x.current,y.current,i.getState().getDraft),n=t.key;if(S.current=t.key,D.current=void 0,O.current=void 0,k.current=Al(),m(`compose`),E.current=t.revision,A(t.document,t.mentions),g(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!JT(S.current,a)||w.current!==a||C.current!==a||T.current!==e||E.current!==r||o?.revision!==t.revision||(E.current=t.revision,A(zt(WT(t),y.current),t.mentions))})}},[a,A,i]),(0,Z.useEffect)(()=>{if(!a||w.current!==a||O.current)return;let e=XT(_.current,o,D.current,{keyID:a,epoch:T.current,appliedRevision:E.current});if(e!==`ignore`){if(o&&(E.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&f(o.mentions);return}e===`external-document`&&o&&(D.current=void 0,A(zt(WT(o),y.current),o.mentions),m(`compose`),g(e=>e+1))}},[a,A,o]);let M=(0,Z.useCallback)((e,t)=>{let n=S.current;if(!JT(n,C.current)||O.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:QT(t)});if(!a)return;let o=WT(a);return D.current={keyID:mn(n),revision:a.revision,fingerprint:qT(o)},E.current=a.revision,A(o,a.mentions),j(r,o),a},[i,A,j]),N=(0,Z.useCallback)((e,t,n,r,i,a)=>{k.current=Ll(k.current,{before:Vl(e,t,n),after:Vl(r,i,a)})},[]),P=(0,Z.useCallback)(()=>O.current?(O.current=void 0,m(`compose`),!0):!1,[]),F=(0,Z.useCallback)(e=>(P(),M({text:e,references:[]},[])),[M,P]),I=(0,Z.useCallback)((e,t=[])=>{P();let n=Rt(e.text,e.references);return n?M(zt(n,y.current),t):void 0},[M,P]),L=(0,Z.useCallback)((e,t,n=t,r)=>{let i=P(),a=GT(_.current),o=i?[]:v.current,s=$T(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return M(s.document,c),s.removedReferences.length>0&&N(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[M,P,N]),R=(0,Z.useCallback)((e,t)=>{let n=_.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=P(),o=kt(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=ZT(a?[]:v.current,o.document,o.edit);return M(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[M,P]),z=(0,Z.useCallback)((e,t)=>{let n=_.current;return R({start:0,end:n.text.length,text:e},t)},[R]),B=(0,Z.useCallback)((e,t,n,r)=>{let i=P(),a=Ct(_.current,e,t,n,r);return M(a.document,ZT(i?[]:v.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[M,P]),V=(0,Z.useCallback)(e=>{let t=GT(_.current),n=nn(t,e);if(!n)return null;let r=P()?[]:v.current,i=ZT(r,n.document,n.edit),a=Dt(n.document.text,n.caret),o=kt(n.document,a.text,a.caret),s=ZT(i,o.document,o.edit);return M(o.document,s),N(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[M,P,N]),H=(0,Z.useCallback)(e=>{if(O.current)return null;let t=e===`undo`?jl(k.current,_.current):Hl(k.current,_.current);return!t||!M(t.snapshot.document,t.snapshot.mentions)?null:(k.current=t.history,t.snapshot.selection)},[M]),U=(0,Z.useCallback)(e=>M(_.current,e),[M]),W=(0,Z.useCallback)(e=>{let t=O.current?{document:{text:e.text,references:[]},mentions:[]}:eE(_.current,v.current,e);`preview`in t&&(O.current=t.preview),m(`history-preview`),A(t.document,t.mentions),g(e=>e+1)},[A]),ee=(0,Z.useCallback)(()=>{let e=O.current;if(!e)return;O.current=void 0,m(`compose`);let t=tE(e);A(t.document,t.mentions),g(e=>e+1)},[A]),te=(0,Z.useCallback)(()=>{let e=S.current;if(!JT(e,C.current))return null;let t=i.getState().getDraft(e);return{key:KT(e),keyID:mn(e),revision:t?.revision??0,document:GT(_.current),mentions:v.current.map(e=>({...e,range:{...e.range}})),epoch:T.current,runtime:i.getState().captureDraftRuntime()}},[i]),ne=(0,Z.useCallback)(e=>{let t=rE(e,i.getState().getDraft(e.key)),n=WT(i.getState().getDraft(e.key)),r=Ht(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:QT(t.mentions)});if(a){let e=WT(a);j(r,e)}return a},[j,i]),re=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:p,hydration:s,persistence:c,textPresetEpoch:h,getDocument:re,replacePlainDocument:F,replaceMaterializedDocument:I,applyBrowserEdit:L,applyProgrammaticEdit:R,replaceProgrammaticText:z,insertReference:B,deleteReference:V,restoreReferenceHistory:H,commitMentions:U,enterHistoryPreview:W,exitHistoryPreview:ee,captureSubmission:te,recoverSubmission:ne}),[L,R,te,U,V,l,W,ee,re,s,p,B,d,c,ne,I,F,z,H,h])};function aE(e){let t=e.maxLines??8,n=e.lineHeight*t+e.paddingTotal,r=Math.max(e.scrollHeight,e.dictationHeight);return{height:Math.min(r,n),maxHeight:n,overflowY:r>n?`auto`:`hidden`}}function oE(e){let t=(0,Q.c)(22),{inputRef:n,message:r,expanded:i,isMobile:a,dictationHeight:o,manualHeight:s}=e,c=s!==void 0&&s,[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f;t[0]!==o||t[1]!==i||t[2]!==n||t[3]!==c?(f=e=>{let t=n.current;if(!t||c)return;let r=t.scrollTop;if(i){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,u(null),t.scrollTop!==r&&(t.scrollTop=r);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let a=t.ownerDocument?.defaultView,s=a?a.getComputedStyle(t):null,l=s?parseFloat(s.lineHeight):NaN,d=s?parseFloat(s.paddingTop):NaN,f=s?parseFloat(s.paddingBottom):NaN,p=Number.isNaN(d)||Number.isNaN(f)?16:d+f,m=aE({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:o??0,lineHeight:Number.isNaN(l)?22:l,paddingTotal:p});t.style.height=`${m.height}px`,t.style.maxHeight=`${m.maxHeight}px`,t.style.overflowY=m.overflowY,t.scrollTop!==r&&(t.scrollTop=r),u(e=>e?.height===m.height&&e.maxHeight===m.maxHeight?e:{height:m.height,maxHeight:m.maxHeight})},t[0]=o,t[1]=i,t[2]=n,t[3]=c,t[4]=f):f=t[4];let p=J(f),m=c?null:r,h;t[5]!==m?.length||t[6]!==o||t[7]!==i||t[8]!==c||t[9]!==p?(h=()=>{let e=d.current,t=m?.length??0,n=!e||e.manualHeight||t<e.length||i!==e.expanded||e.dictationHeight!==null&&o===null;d.current={length:t,expanded:i,dictationHeight:o,manualHeight:c},p({allowShrink:n})},t[5]=m?.length,t[6]=o,t[7]=i,t[8]=c,t[9]=p,t[10]=h):h=t[10];let g;t[11]!==m||t[12]!==o||t[13]!==i||t[14]!==n||t[15]!==a||t[16]!==c||t[17]!==p?(g=[m,i,a,o,c,n,p],t[11]=m,t[12]=o,t[13]=i,t[14]=n,t[15]=a,t[16]=c,t[17]=p,t[18]=g):g=t[18],(0,Z.useLayoutEffect)(h,g);let _;return t[19]!==p||t[20]!==l?(_={size:l,resize:p},t[19]=p,t[20]=l,t[21]=_):_=t[21],_}function sE(e){let t=(0,Q.c)(26),{enabled:n,hasContent:r,draftID:i,inputRef:a}=e,o=n&&r,s;t[0]===a?s=t[1]:(s=()=>{let e=a.current;if(!e)return[];let t=e.closest(`[data-mobile-composer-surface]`)??e,n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=getComputedStyle(e),o=parseFloat(i.lineHeight)||22,s=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0),c=Math.max(parseFloat(i.minHeight)||0,o+s),l=window.visualViewport,u=l?.offsetTop??0;for(let e=t.parentElement;e;e=e.parentElement){let t=e.querySelector(`.yuri-mobile-detail-navigation, [data-mobile-chat-header]`);if(t){u=Math.max(u,t.getBoundingClientRect().bottom);break}}let d=Math.min(r.bottom,(l?.offsetTop??0)+(l?.height??window.innerHeight)),f=r.height-n.height,p=Math.max(c,d-u-f),m=e.style.height,h=e.scrollTop;e.style.height=`0px`;let g=aE({scrollHeight:e.scrollHeight,dictationHeight:0,lineHeight:o,paddingTotal:s}).height;return e.style.height=m,e.scrollTop=h,[{id:`auto`,height:Math.min(p,Math.max(c,g))},{id:`min`,height:c},{id:`full`,height:p}]},t[0]=a,t[1]=s);let c;t[2]!==a||t[3]!==s?(c={surfaceRef:a,initialPoint:`auto`,getPoints:s},t[2]=a,t[3]=s,t[4]=c):c=t[4];let l=vl(c),{reset:u}=l,d;t[5]===u?d=t[6]:(d=()=>{u()},t[5]=u,t[6]=d);let f;t[7]!==o||t[8]!==i||t[9]!==u?(f=[o,i,u],t[7]=o,t[8]=i,t[9]=u,t[10]=f):f=t[10],(0,Z.useLayoutEffect)(d,f);let p;t[11]!==o||t[12]!==l?(p=()=>{o&&l.snapPoint===`full`&&l.settleAt(`full`,void 0,!1)},t[11]=o,t[12]=l,t[13]=p):p=t[13];let m=J(p),h;t[14]===o?h=t[15]:(h=()=>o?window:null,t[14]=o,t[15]=h),Wn(`resize`,m,h);let g;t[16]===o?g=t[17]:(g=()=>o?window:null,t[16]=o,t[17]=g),Wn(`yuri:keyboard-settled`,m,g);let _;t[18]===o?_=t[19]:(_=()=>o?window.visualViewport:null,t[18]=o,t[19]=_),Wn(`resize`,m,_);let v;t[20]===o?v=t[21]:(v=()=>o?window.visualViewport:null,t[20]=o,t[21]=v),Wn(`scroll`,m,v);let y=o&&(l.dragging||l.settling||l.snapPoint!==`auto`),b;return t[22]!==o||t[23]!==l||t[24]!==y?(b={...l,visible:o,manualHeight:y},t[22]=o,t[23]=l,t[24]=y,t[25]=b):b=t[25],b}var cE=(0,Z.memo)(function(e){let t=(0,Q.c)(23),{inputRef:n,draftID:r,ariaLabel:i,onManualHeightChange:a}=e,o=(0,Z.useRef)(null),s;t[0]!==r||t[1]!==n?(s={enabled:!0,hasContent:!0,draftID:r,inputRef:n},t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=sE(s),{snapPoint:l,manualHeight:u,dragging:d,settling:f}=c,p,m;t[3]!==d||t[4]!==u||t[5]!==a||t[6]!==f||t[7]!==l?(p=()=>{let e=o.current?.closest(`[data-mobile-composer-surface]`);e&&(e.dataset.composerHeightSnap=l,e.toggleAttribute(`data-composer-height-manual`,u),d||f?e.dataset.mobileComposerResizing=`true`:delete e.dataset.mobileComposerResizing),a(u)},m=[l,u,d,f,a],t[3]=d,t[4]=u,t[5]=a,t[6]=f,t[7]=l,t[8]=p,t[9]=m):(p=t[8],m=t[9]),(0,Z.useLayoutEffect)(p,m);let h,g;t[10]===a?(h=t[11],g=t[12]):(h=()=>{let e=o.current?.closest(`[data-mobile-composer-surface]`);return()=>{e?.removeAttribute(`data-composer-height-snap`),e?.removeAttribute(`data-composer-height-manual`),e?.removeAttribute(`data-mobile-composer-resizing`),a(!1)}},g=[a],t[10]=a,t[11]=h,t[12]=g),(0,Z.useLayoutEffect)(h,g);let _=l===`min`?0:l===`auto`?1:2,v;return t[13]!==i||t[14]!==c.handleClick||t[15]!==c.handleKeyDown||t[16]!==c.handleLostPointerCapture||t[17]!==c.handlePointerCancel||t[18]!==c.handlePointerDown||t[19]!==c.handlePointerMove||t[20]!==c.handlePointerUp||t[21]!==_?(v=(0,$.jsx)(bl,{ref:o,"data-mobile-composer-snap-handle":!0,"aria-label":i,"aria-valuemin":0,"aria-valuemax":2,"aria-valuenow":_,className:`absolute top-1 left-1/2 z-40 h-2.5 w-20 -translate-x-1/2 items-center`,onPointerDown:c.handlePointerDown,onPointerMove:c.handlePointerMove,onPointerUp:c.handlePointerUp,onPointerCancel:c.handlePointerCancel,onLostPointerCapture:c.handleLostPointerCapture,onClick:c.handleClick,onKeyDown:c.handleKeyDown}),t[13]=i,t[14]=c.handleClick,t[15]=c.handleKeyDown,t[16]=c.handleLostPointerCapture,t[17]=c.handlePointerCancel,t[18]=c.handlePointerDown,t[19]=c.handlePointerMove,t[20]=c.handlePointerUp,t[21]=_,t[22]=v):v=t[22],v}),lE=.5,uE=`--yuri-mobile-composer-swap`,dE=`--yuri-native-composer-dock`,fE=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),pE=(e,t,n)=>Math.min(n,Math.max(t,e)),mE=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,hE=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return mE(e,n)?e:n},gE=(e,t)=>t?hE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?hE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,_E=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:hE(e,{phase:`snapping`,rest:t,progress:n})},vE=e=>Math.round(pE(e,0,1)*1e3)/1e3,yE=(e,t,n)=>{let r=n-t;if(r>=0)return vE(e+r/80);if(n<=2)return 0;if(n>=120)return e;let i=e+r/80,a=n/t*e;return vE(Math.min(i,a))},bE=(e,t)=>e>=1?`compact`:e<=0?`expanded`:t,xE=(e,t,n={})=>{if(e.pinned||n.userDriven===!1)return e;let r=Math.max(0,t),i=n.previousDistance==null?r:Math.max(0,n.previousDistance),a=e.phase===`snapping`?hE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(r<=2)return hE(a,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn&&a.rest===`compact`&&r<i)return hE(a,{phase:`rest`,rest:`compact`,progress:1});let o=yE(a.progress,i,r);return e.phase===`snapping`&&o===a.progress?e:o===a.progress?a:Math.abs(o-a.progress)>=lE&&(o>=1||o<=0)?hE(a,{phase:`snapping`,rest:o>=1?`compact`:`expanded`,progress:o}):o>=1||o<=0?hE(a,{phase:`rest`,rest:bE(o,a.rest),progress:o}):hE(a,{phase:`tracking`,rest:a.rest,progress:o})},SE=(e,t=null)=>e.pinned?`expanded`:t||(e.progress>=.5?`compact`:`expanded`),CE=(e,t=null)=>{if(e.pinned)return hE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let n=SE(e,t),r=+(n===`compact`);return e.phase===`rest`&&e.rest===n&&e.progress===r?e:hE(e,{phase:`snapping`,rest:n,progress:r})},wE=e=>e.phase===`snapping`?hE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,TE=e=>pE(Math.max(0,e)/80,0,1),EE=(e,t=`away`)=>{let n=Math.max(0,e);return n<=2?{progress:0,rest:`bottom`}:t===`away`||n>=40?{progress:1,rest:`away`}:{progress:TE(n),rest:`bottom`}},DE=`--yuri-mobile-composer-occupancy`,OE=(e,t)=>{if(!(t>0))return null;let n=`${Math.round(t)}px`;return e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)!==n&&e.style.setProperty(DE,n),n},kE=(e,t)=>{t!==null&&e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)===t&&e.style.removeProperty(DE)},AE=e=>{for(let t of e.children)if(t instanceof HTMLElement&&t.classList.contains(`yuri-mobile-composer-foot--overlay`)&&!t.classList.contains(`invisible`))return t;return e},jE=(e,t=e)=>{for(let n of new Set([e,t]))n.style.removeProperty(uE),n.style.removeProperty(dE);delete e.dataset.yuriComposerSwapPhase,delete e.dataset.yuriComposerSwapRest,delete e.dataset.yuriNativeComposerDock},ME=(e,t,n,r=e)=>{let i=EE(t,n?.rest===`bottom`?`bottom`:`away`),a=String(i.progress),o=i.rest;return n?.progress!==a&&r.style.setProperty(dE,a),n?.rest!==o&&(e.dataset.yuriNativeComposerDock=o),{progress:a,rest:o}},NE=(e,t,n,r=e)=>{let i=String(t.progress),a=t.phase,o=t.rest;return n?.phase!==a&&(e.dataset.yuriComposerSwapPhase=a,a===`snapping`&&n&&n.phase!==`snapping`&&r.offsetWidth),n?.progress!==i&&r.style.setProperty(uE,i),n?.rest!==o&&(e.dataset.yuriComposerSwapRest=o),{progress:i,phase:a,rest:o}},PE=`box-border w-full whitespace-pre-wrap break-words px-3 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit] md:typography-ui-label`,FE=Yu(()=>Mn(()=>import(`./ToolOutputDialog-BKuVpgEu.js`),__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,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76]))),IE=[],LE=[],RE=[],zE=[],BE=/^@[^\s]+$/,VE=({inputMode:e,message:t,showCommandAutocomplete:n})=>e!==`shell`&&(n||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),HE=/^(https?:\/\/|mailto:)\S+$/i,UE=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),WE=(e,t)=>{if(e===t)return``;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;let r=e.length,i=t.length;for(;r>n&&i>n&&e[r-1]===t[i-1];)--r,--i;return t.slice(n,i)},GE=e=>e.includes(`@`)?`paste`:`manual`,KE=(e,t)=>{let n=t,r=t;for(;n>0&&/\s/.test(e[n-1]);)--n;for(;r<e.length&&/\s/.test(e[r]);)r+=1;let i=n>0&&r<e.length?` `:``;return{text:`${e.slice(0,n)}${i}${e.slice(r)}`,caret:n+i.length}},qE=(e,t)=>Te(e,t).some(e=>e.role===`user`),JE=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!ra(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6542
+ `)},dw=(e,t,n,r,i)=>{if(ew(e,n)&&XC===r.epoch){if(o()!==r.transport||c()!==r.generation){sw(e,t,{pending:!1});return}sw(e,t,i)}},fw=e=>{let t=typeof e.sessionId==`string`?e.sessionId.trim():``;return t?{sessionId:t,directory:typeof e.directory==`string`&&e.directory.trim()?e.directory:e.directory??null}:null},pw=e=>{let t=JC.get(e);t&&(rw(e),sw(e,t.turnId,{pending:!1}))},mw=e=>{let t=fw(e);if(!t)return null;let n=qC(t),r=ww.getState().sendSelection[n];if(r?.providerID&&r?.modelID)return r;let i=wi.getState().getSessionModelSelection(t.sessionId);if(i)return{providerID:i.providerId,modelID:i.modelId,agent:wi.getState().getSessionAgentSelection(t.sessionId)??void 0};let a=ni.getState();return a.currentProviderId&&a.currentModelId?{providerID:a.currentProviderId,modelID:a.currentModelId,agent:a.currentAgentName??void 0,variant:a.currentVariant??null}:null},hw=async e=>{let t=mw({sessionId:e.sessionId,directory:e.directory});if(!t)return;let n=typeof t.variant==`string`&&t.variant.trim()?t.variant.trim():void 0;await se.applySendSelection(e.sessionId,{model:{providerID:t.providerID,id:t.modelID,...n?{variant:n}:{}},...t.agent?{agent:t.agent}:{}},e.directory)},gw=(e,t)=>{let n=fw(e);if(!n)return;let r=qC(n);ww.setState(e=>({sendSelection:{...e.sendSelection,[r]:t}})),wi.getState().saveSessionModelSelection(n.sessionId,t.providerID,t.modelID),t.agent&&wi.getState().saveSessionAgentSelection(n.sessionId,t.agent)},_w=async(e,t,n,r)=>{let i=n.id,a={epoch:XC,transport:o(),generation:c()},s=new AbortController;JC.set(t,{controller:s,turnId:i});try{if(await hw(e),!ew(t,s))return;let o=await se.generateSessionAside({sessionId:e.sessionId,directory:e.directory,prompt:uw(r,n),signal:s.signal}),c=typeof o?.text==`string`?o.text.trim():``;dw(t,i,s,a,c?{answer:c,error:null,pending:!1}:{answer:``,error:`empty response`,pending:!1})}catch(e){dw(t,i,s,a,$C(e,s.signal)?{pending:!1}:{error:QC(e),pending:!1})}finally{ew(t,s)&&JC.delete(t)}},vw=async(e,t)=>{let n=typeof t==`string`?t.trim():``,r=fw(e);if(!n||!r)return;let i=qC(r);pw(i);let a=ww.getState().entries[i]??KC;ZC+=1;let o={id:`btw_${ZC}`,quotes:a.quotes,question:n,answer:``,error:null,pending:!0};aw(i,e=>({turns:[...e.turns,o].slice(-50),quotes:KC.quotes})),await _w(r,i,o,a.turns)},yw=async e=>{let t=fw(e);if(!t)return;let n=qC(t),r=ww.getState().entries[n]?.turns??[],i=r[r.length-1];i&&(pw(n),sw(n,i.id,{answer:``,error:null,pending:!0}),await _w(t,n,i,r.slice(0,-1)))},bw=(e,t)=>{let n=typeof t==`string`?t.trim():``;!n||!fw(e)||aw(qC(e),e=>e.quotes.includes(n)?null:{...e,quotes:[...e.quotes,n].slice(-10)})},xw=(e,t)=>{let n=qC(e);ww.getState().entries[n]&&aw(n,e=>t<0||t>=e.quotes.length?null:{...e,quotes:e.quotes.filter((e,n)=>n!==t)})},Sw=e=>{pw(qC(e))},Cw=e=>{let t=qC(e);rw(t),YC=YC.filter(e=>e!==t),ww.setState(e=>{let n=t in e.entries,r=t in e.sendSelection;if(!n&&!r)return e;let i=n?{...e.entries}:e.entries,a=r?{...e.sendSelection}:e.sendSelection;return n&&delete i[t],r&&delete a[t],{entries:i,sendSelection:a}})},ww=L(()=>({entries:{},sendSelection:{},setSendSelection:gw,ask:vw,retry:yw,cancel:Sw,addQuote:bw,removeQuote:xw,clear:Cw})),Tw=()=>{XC+=1;for(let{controller:e}of JC.values())e.abort();JC.clear(),YC=[],ww.setState({entries:{},sendSelection:{}})},Ew=(e=>{let t=new Map,n=()=>{let e=0;for(let n of t.values())e+=n;return e};return{hold(r){let i=(t.get(r)??0)+1;t.set(r,i),n()===1&&e.conceal();let a=!1;return()=>{if(a)return;a=!0;let i=(t.get(r)??1)-1;i<=0?t.delete(r):t.set(r,i),n()===0&&e.reveal()}}}})(Du),Dw=new Map,Ow=e=>Ew.hold(e),kw=e=>{Dw.has(e)||Dw.set(e,Ew.hold(e))},Aw=e=>{let t=Dw.get(e);t&&(Dw.delete(e),t())},jw=`btw-page`,Mw=`btw-sheet`,Nw=`text-selection`,Pw=`1.5rem`,Fw=`box-border w-full whitespace-pre-wrap break-words px-3 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit] md:typography-ui-label pt-4 pb-2`,Iw=`box-border w-full whitespace-pre-wrap break-words px-3 py-2.5 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit]`;function Lw(e){let t=(0,Q.c)(40),{turn:n,isLast:r,scope:i}=e,{t:a}=Xn(),o;t[0]!==a||t[1]!==n.error?(o=n.error===`empty response`||n.error===`session.btw failed`?a(`chat.btw.failed`):n.error,t[0]=a,t[1]=n.error,t[2]=o):o=t[2];let s=o,c=!n.pending&&!n.error&&!n.answer,l;t[3]!==a||t[4]!==n.answer?(l=async()=>{(await Yn(n.answer)).ok?Yr.success(a(`contextSidebar.actions.copied`)):Yr.error(a(`filesView.toast.copyFailed`))},t[3]=a,t[4]=n.answer,t[5]=l):l=t[5];let u=J(l),d=n.id,f;t[6]===n.quotes?f=t[7]:(f=n.quotes.map(Rw),t[6]=n.quotes,t[7]=f);let p;t[8]===n.question?p=t[9]:(p=(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words typography-markdown text-foreground`,children:n.question}),t[8]=n.question,t[9]=p);let m;t[10]!==f||t[11]!==p?(m=(0,$.jsxs)(`div`,{className:`ml-8 flex flex-col gap-1.5 self-end rounded-xl bg-[var(--surface-elevated)] px-3 py-2`,children:[f,p]}),t[10]=f,t[11]=p,t[12]=m):m=t[12];let h;t[13]!==a||t[14]!==n.pending?(h=n.pending?(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),a(`chat.btw.pending`)]}):null,t[13]=a,t[14]=n.pending,t[15]=h):h=t[15];let g;t[16]===s?g=t[17]:(g=s?(0,$.jsxs)(`p`,{role:`alert`,className:`whitespace-pre-wrap break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`mr-1.5 inline size-3.5 align-[-2px] text-[var(--status-error)]/85`,"aria-hidden":`true`}),s]}):null,t[16]=s,t[17]=g);let _;t[18]!==c||t[19]!==a?(_=c?(0,$.jsx)(`p`,{role:`status`,className:`typography-meta text-muted-foreground`,children:a(`chat.btw.cancelled`)}):null,t[18]=c,t[19]=a,t[20]=_):_=t[20];let v;t[21]===n.answer?v=t[22]:(v=n.answer?(0,$.jsx)(`div`,{className:`min-w-0 text-foreground`,children:(0,$.jsx)(Ju,{content:n.answer,enableFileReferences:!1})}):null,t[21]=n.answer,t[22]=v);let y;t[23]!==c||t[24]!==u||t[25]!==s||t[26]!==r||t[27]!==i||t[28]!==a||t[29]!==n.answer||t[30]!==n.pending?(y=!n.pending&&(n.answer||r&&(s||c))?(0,$.jsxs)(`div`,{className:`-ml-2 flex items-center gap-0.5`,children:[n.answer?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:u,"aria-label":a(`contextSidebar.actions.copy`),children:(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`})}):null,r?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:()=>void ww.getState().retry(i),"aria-label":a(`contextPanel.preview.actions.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`})}):null]}):null,t[23]=c,t[24]=u,t[25]=s,t[26]=r,t[27]=i,t[28]=a,t[29]=n.answer,t[30]=n.pending,t[31]=y):y=t[31];let b;return t[32]!==v||t[33]!==y||t[34]!==m||t[35]!==h||t[36]!==g||t[37]!==_||t[38]!==n.id?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-btw-turn":d,children:[m,h,g,_,v,y]}),t[32]=v,t[33]=y,t[34]=m,t[35]=h,t[36]=g,t[37]=_,t[38]=n.id,t[39]=b):b=t[39],b}function Rw(e,t){return(0,$.jsx)(`p`,{"data-btw-quote":!0,"data-conversation-quote":!0,className:`m-0 whitespace-pre-wrap break-words border-l-2 border-border pl-1.5 typography-meta text-muted-foreground`,children:e},t)}function zw(e){let t=(0,Q.c)(64),{scope:n,pending:r,quotes:i,foot:a}=e,{t:o}=Xn(),s;t[0]===n?s=t[1]:(s=e=>e.sendSelection[qC(n)],t[0]=n,t[1]=s);let c=ww(s),l;t[2]!==n||t[3]!==c?(l=c??mw(n),t[2]=n,t[3]=c,t[4]=l):l=t[4];let u=l,d=ni(Bw),f;bb0:{if(!u?.providerID||!u?.modelID){f=null;break bb0}let e;if(t[5]!==d||t[6]!==u.modelID||t[7]!==u.providerID){let n;t[9]===u.providerID?n=t[10]:(n=e=>e.id===u.providerID,t[9]=u.providerID,t[10]=n);let r=d.find(n);e=qr(r,u.modelID)||u.modelID,t[5]=d,t[6]=u.modelID,t[7]=u.providerID,t[8]=e}else e=t[8];f=e}let p=f,[m,h]=Z.useState(``),g=Z.useRef(null),_,v;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{let e=window.requestAnimationFrame(()=>{g.current?.focus({preventScroll:!0})});return()=>window.cancelAnimationFrame(e)},v=[],t[11]=_,t[12]=v):(_=t[11],v=t[12]),Z.useEffect(_,v);let y;t[13]!==m||t[14]!==r||t[15]!==n?(y=()=>{let e=m.trim();!e||r||(h(``),ww.getState().ask(n,e))},t[13]=m,t[14]=r,t[15]=n,t[16]=y):y=t[16];let b=J(y),x;t[17]!==p||t[18]!==u?(x=u&&p?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5 rounded-lg px-2.5 py-1`,"aria-label":p,children:[(0,$.jsx)(Ps,{modelId:u.modelID,providerId:u.providerID,className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-meta font-medium text-foreground`,children:p})]}):null,t[17]=p,t[18]=u,t[19]=x):x=t[19];let S=x,C=a!==`panel`,w=C?`yuri-mobile-composer`:`pb-3`,T=a===`page`?`bottom-safe-area`:``,E;t[20]!==w||t[21]!==T?(E=[`shrink-0 px-3 pt-1`,w,T].filter(Boolean),t[20]=w,t[21]=T,t[22]=E):E=t[22];let D=E.join(` `),O;t[23]===b?O=t[24]:(O=e=>{e.preventDefault(),b()},t[23]=b,t[24]=O);let k;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(k=e=>h(e),t[25]=k):k=t[25];let A;t[26]===n?A=t[27]:(A=()=>ww.getState().cancel(n),t[26]=n,t[27]=A);let j;t[28]===o?j=t[29]:(j=o(`chat.btw.placeholder`),t[28]=o,t[29]=j);let M;t[30]===o?M=t[31]:(M=o(`chat.chatInput.actions.sendMessageAria`),t[30]=o,t[31]=M);let N;t[32]===o?N=t[33]:(N=o(`chat.statusRow.actions.stopGeneratingAria`),t[32]=o,t[33]=N);let P;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(P={autoFocus:!0},t[34]=P):P=t[34];let F=C?`relative z-10 yuri-mobile-composer-surface`:`relative z-10`,I;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(I={borderRadius:Pw},t[35]=I):I=t[35];let L=C?Iw:Fw,R;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(R={borderTopLeftRadius:Pw,borderTopRightRadius:Pw},t[36]=R):R=t[36];let z;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(z={borderBottomLeftRadius:Pw,borderBottomRightRadius:Pw},t[37]=z):z=t[37];let B;t[38]===o?B=t[39]:(B=o(`chat.btw.removeQuoteAria`),t[38]=o,t[39]=B);let V;t[40]===n?V=t[41]:(V=e=>ww.getState().removeQuote(n,e),t[40]=n,t[41]=V);let H;t[42]!==i||t[43]!==B||t[44]!==V?(H=(0,$.jsx)(Lh,{quotes:i,removeLabel:B,onRemove:V}),t[42]=i,t[43]=B,t[44]=V,t[45]=H):H=t[45];let U;t[46]!==m||t[47]!==C||t[48]!==S||t[49]!==r||t[50]!==b||t[51]!==A||t[52]!==j||t[53]!==M||t[54]!==N||t[55]!==F||t[56]!==L||t[57]!==H?(U=(0,$.jsx)(Ul,{value:m,onChange:k,onSubmit:b,onStop:A,pending:r,disableInputWhilePending:!1,isMobile:C,placeholder:j,sendLabel:M,stopLabel:N,inputRef:g,textareaProps:P,leftControls:S,className:F,style:I,textLayoutClassName:L,inputStyle:R,footerClassName:`z-30 bg-transparent flex-shrink-0 px-2.5 py-1.5`,footerStyle:z,inputHeader:H}),t[46]=m,t[47]=C,t[48]=S,t[49]=r,t[50]=b,t[51]=A,t[52]=j,t[53]=M,t[54]=N,t[55]=F,t[56]=L,t[57]=H,t[58]=U):U=t[58];let W;return t[59]!==a||t[60]!==D||t[61]!==O||t[62]!==U?(W=(0,$.jsx)(`form`,{"data-btw-composer":!0,"data-btw-composer-foot":a,className:D,onSubmit:O,children:U}),t[59]=a,t[60]=D,t[61]=O,t[62]=U,t[63]=W):W=t[63],W}function Bw(e){return e.providers}function Vw(e){let t=(0,Q.c)(29),{scope:n,foot:r}=e,i=r===void 0?`panel`:r,{t:a}=Xn(),o;t[0]===n?o=t[1]:(o=qC(n),t[0]=n,t[1]=o);let s=o,c;t[2]===s?c=t[3]:(c=e=>(e.entries[s]??KC).turns,t[2]=s,t[3]=c);let l=ww(c),u;t[4]===s?u=t[5]:(u=e=>(e.entries[s]??KC).quotes,t[4]=s,t[5]=u);let d=ww(u),f;t[6]===l?f=t[7]:(f=l.some(Hw),t[6]=l,t[7]=f);let p=f,m=Z.useRef(null),h=l[l.length-1],g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},t[8]=g):g=t[8];let _=h?.answer,v=h?.pending,y;t[9]!==_||t[10]!==v||t[11]!==l.length?(y=[l.length,_,v],t[9]=_,t[10]=v,t[11]=l.length,t[12]=y):y=t[12],Z.useLayoutEffect(g,y);let b;t[13]===a?b=t[14]:(b=a(`chat.btw.title`),t[13]=a,t[14]=b);let x;t[15]!==n||t[16]!==a||t[17]!==l?(x=(0,$.jsx)(`div`,{ref:m,className:`overlay-scrollbar-container min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-3`,children:l.length===0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:a(`chat.btw.description`)}):(0,$.jsx)(`div`,{className:`flex flex-col gap-5`,children:l.map((e,t)=>(0,$.jsx)(Lw,{turn:e,isLast:t===l.length-1,scope:n},e.id))})}),t[15]=n,t[16]=a,t[17]=l,t[18]=x):x=t[18];let S;t[19]!==i||t[20]!==s||t[21]!==p||t[22]!==d||t[23]!==n?(S=(0,$.jsx)(zw,{scope:n,pending:p,quotes:d,foot:i},s),t[19]=i,t[20]=s,t[21]=p,t[22]=d,t[23]=n,t[24]=S):S=t[24];let C;return t[25]!==b||t[26]!==x||t[27]!==S?(C=(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-col text-foreground`,"aria-label":b,children:[x,S]}),t[25]=b,t[26]=x,t[27]=S,t[28]=C):C=t[28],C}function Hw(e){return e.pending}function Uw(e){let t=(0,Q.c)(53),{scope:n,active:r,mobile:i}=e,{t:a}=Xn(),{sessionId:o,directory:s}=n,c;t[0]===n?c=t[1]:(c=qC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===s?u=t[3]:(u=Pn(s),t[2]=s,t[3]=u);let d=u,f;t[4]===d?f=t[5]:(f=e=>e.contextPanelByDirectory[d],t[4]=d,t[5]=f);let p=K(f),m;t[6]!==r||t[7]!==p?(m=r&&!!(p?.isOpen&&p.tabs.find(e=>e.id===p.activeTabId)?.mode===`btw`),t[6]=r,t[7]=p,t[8]=m):m=t[8];let h=m,g;t[9]===p?g=t[10]:(g=p?.isOpen&&p.tabs.some(Gw),t[9]=p,t[10]=g);let _=!!g,v;t[11]!==l||t[12]!==_?(v={key:l,retained:_},t[11]=l,t[12]=_,t[13]=v):v=t[13];let y=Z.useRef(v),b,x;t[14]!==l||t[15]!==_||t[16]!==s||t[17]!==o?(b=()=>{let e={sessionId:o,directory:s},t=y.current;y.current={key:l,retained:_},t.key===l&&t.retained&&!_&&ww.getState().clear(e)},x=[l,_,o,s],t[14]=l,t[15]=_,t[16]=s,t[17]=o,t[18]=b,t[19]=x):(b=t[18],x=t[19]),Z.useEffect(b,x);let S=Z.useRef(null),C,w;t[20]!==r||t[21]!==l||t[22]!==s||t[23]!==o?(w=()=>{let e={sessionId:o,directory:s},t={key:l,active:r};S.current=t;let n=()=>so({sessionId:o,directory:s??null});return!r&&!n()&&ww.getState().cancel(e),()=>{let r=ww.getState().entries[l];queueMicrotask(()=>{let i=S.current;i!==t&&i?.key===l&&i.active||n()||qC(e)===l&&ww.getState().entries[l]===r&&ww.getState().cancel(e)})}},C=[l,r,o,s],t[20]=r,t[21]=l,t[22]=s,t[23]=o,t[24]=C,t[25]=w):(C=t[24],w=t[25]),Z.useEffect(w,C);let T;t[26]!==d||t[27]!==n?(T=()=>{ww.getState().clear(n),K.getState().closeContextPanel(d)},t[26]=d,t[27]=n,t[28]=T):T=t[28];let E=J(T),D,O;if(t[29]!==i||t[30]!==h?(D=()=>{if(!i||!h){Aw(Mw);return}return kw(Mw),Ww},O=[i,h],t[29]=i,t[30]=h,t[31]=D,t[32]=O):(D=t[31],O=t[32]),Z.useEffect(D,O),!i)return null;let k;t[33]===E?k=t[34]:(k=e=>{e||E()},t[33]=E,t[34]=k);let A;t[35]===a?A=t[36]:(A=a(`chat.btw.title`),t[35]=a,t[36]=A);let j;t[37]===a?j=t[38]:(j=a(`chat.btw.title`),t[37]=a,t[38]=j);let M;t[39]===a?M=t[40]:(M=a(`gitView.common.close`),t[39]=a,t[40]=M);let N;t[41]===a?N=t[42]:(N=a(`chat.btw.resize`),t[41]=a,t[42]=N);let P;t[43]===n?P=t[44]:(P=(0,$.jsx)(Vw,{scope:n,foot:`sheet`}),t[43]=n,t[44]=P);let F;return t[45]!==h||t[46]!==k||t[47]!==A||t[48]!==j||t[49]!==M||t[50]!==N||t[51]!==P?(F=(0,$.jsx)(yl,{id:`session-btw`,open:h,onOpenChange:k,title:A,ariaLabel:j,closeAriaLabel:M,resizeAriaLabel:N,children:P}),t[45]=h,t[46]=k,t[47]=A,t[48]=j,t[49]=M,t[50]=N,t[51]=P,t[52]=F):F=t[52],F}function Ww(){return Aw(Mw)}function Gw(e){return e.mode===`btw`}var Kw=()=>{typeof window>`u`||window.requestAnimationFrame(()=>{document.querySelector(`[data-btw-composer] textarea`)?.focus()})},qw=e=>{let t=e.directory??null;Ba({sessionId:e.sessionId,directory:t})?kw(jw):K.getState().openContextPanelTab(t??``,{mode:`btw`}),Kw()},Jw=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Yw=async({command:e,consumeCommandText:t,forkSession:n,waitForConnection:r,getDirectoryForSession:i,summarizeSession:a,onCompactError:o,onForkError:s})=>{if(t(),e===`fork`){try{await n()}catch(e){s(e)}return}try{await r();let e=i();if(!e){o();return}await a(e)}catch{o()}},Xw=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,Zw=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&e.delivery!==`queue`&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,Qw=e=>e.surfaceKind!==`primary`||!e.stagedSessionId||!e.stagedMessageId||e.stagedMessageId!==e.blurredMessageId||e.submitInFlight||e.focusHeld||e.overlayOpen||e.focusInsideComposer?{action:`keep`}:{action:`disarm`,sessionId:e.stagedSessionId},$w=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),eT=(e,t)=>{let n=At.getState();return n.bindLegacyQueue(jt(e.sessionID),e),n.stageAdmission(e,{requestID:t.requestID,queueItemID:t.queueItemID,operationID:t.operationID,messageID:t.messageID,content:t.content,createdAt:t.createdAt,attachmentCount:t.attachments.length,...t.composerDocument?{composerDocument:t.composerDocument}:{},...t.composerMentions?{composerMentions:t.composerMentions}:{}}),n.confirmAdmission(e,{requestID:t.requestID,sendConfig:t.sendConfig,attachments:t.attachments}).ok},tT=async e=>{let t=vi.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=$w(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}eT(n,a)?r+=1:i+=1}catch{try{eT(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},nT=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),rT=e=>{let t=e.ctrlEnter&&e.canQueue&&e.primary&&e.sessionIsRunning&&!e.autoReviewRunning;return e.followUpBehavior===`queue`?t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:e.primary?{kind:`submit`,delivery:`queue`}:e.queueUsable?{kind:`queue`}:{kind:`submit`,delivery:`steer`}:t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:{kind:`submit`,delivery:`steer`}},iT=e=>Object.prototype.hasOwnProperty.call(e,`permissions`)?e.permissions:e.permission,aT=e=>{let t=lc(e);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n){if(n.action===`*`&&n.resource===`*`)return n.effect===`ask`;if(n.effect===`ask`)return!0}}return!0},oT=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>aT(iT(e)));let r=e.find(e=>e?.name===n);return!r||aT(iT(r))},sT=e=>{let{permissionScopeSessionId:t,newSessionDraftOpen:n,draftPermissionAutoAcceptEnabled:r,permissionAutoAcceptEnabled:i,setDraftPermissionAutoAcceptEnabled:a,setSessionAutoAccept:o,onOpenSessionFirst:s,onToggleFailed:c}=e;if(!t){if(!n){s();return}a(!r);return}o(t,!i).catch(c)},cT=null,lT=new Set,uT=()=>{for(let e of lT)e()},dT=e=>e===`chat`||e===`assistant`,fT=()=>cT,pT=e=>{cT!==e&&(cT=e,uT())},mT=e=>{cT&&(e&&cT.surfaceID!==e||(cT=null,uT()))},hT=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},gT=e=>{let t=e.options?.delivery===`steer`?`steer`:e.options?.delivery===`queue`?`queue`:void 0,n={...t?{delivery:t}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},r=e.options?.sessionId??e.sessionID??void 0;if(!r)return n;let i=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...n,sessionId:r,directoryHint:i}},_T=(e,t,n={})=>({operation:t,surfaceID:e.surfaceID,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration,sessionID:e.sessionID,directory:e.directory??``,draftKey:e.draftKey,deliveryTarget:e.deliveryTarget,...n}),vT=e=>{if(!e.active||!e.draftKey||!e.directory)return null;let t=e.activity?.phase??`idle`,n=e.activity?.canAbort??(t===`busy`||t===`retry`);return{send:async t=>{let n=_T(e,`send`,t);return await e.selection.flush(),e.kind===`secondary`&&await e.shortcuts.submit(),e.backend.send(n)},sendQueued:async(t,n={})=>{let{manual:r,...i}=n,a=_T(e,`send`,i),o=Iy(e);if(await e.selection.flush(),!o)throw Error(`chat-input-queue-scope-incomplete`);return e.backend.sendQueued({...a,queueItemID:t,manual:r,queueScope:o})},create:async()=>{let t=_T(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=_T(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=_T(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Iy(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>ky(e,{name:t,source:`yuri`}),shortcut:async(t,n=1)=>{if(e.kind===`secondary`){t===`cycle`?await e.shortcuts.cycle(n):t===`new`?await e.shortcuts.new():t===`abort`?await e.shortcuts.abort():await e.shortcuts.submit();return}if(t===`abort`){let t=_T(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=_T(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},yT=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let i=r??t.currentAgentName;i&&e.providerID&&e.modelID&&t.saveAgentModelSelection(i,e.providerID,e.modelID,e.variant);let a=n?.sessionId,o=n?.memory;!a||!o||!e.providerID||!e.modelID||(o.saveSessionModelSelection(a,e.providerID,e.modelID),i&&o.saveSessionAgentSelection&&o.saveSessionAgentSelection(a,i),i&&(o.saveAgentModelForSession(a,i,e.providerID,e.modelID),o.saveAgentModelVariantForSession(a,i,e.providerID,e.modelID,e.variant)))},bT=(e,t,n)=>{let r=e.providers.find(e=>e.id===t);return r?(Array.isArray(r.models)?r.models:[]).some(e=>e.id===n):!1},xT=(e,t)=>e.agents.some(e=>e.name===t),ST=(e,t,n,r)=>{if(!r)return!0;let i=e.providers.find(e=>e.id===t)?.models?.find(e=>e.id===n)?.variants;return i?Array.isArray(i)?i.includes(r):typeof i==`object`&&Object.prototype.hasOwnProperty.call(i,r):!1},CT=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return ST(t,n,r,i)?i:void 0;if(a&&ST(t,n,r,a))return a},wT=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!bT(r,n.providerID,n.modelID))return null;let s=n.agent&&xT(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&xT(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&xT(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=CT({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:c});return{agent:s,providerID:n.providerID,modelID:n.modelID,variant:l,source:o,messageId:n.id}},TT=e=>{let{sessionId:t,latestUserChoice:n,latestExecution:r,catalog:i,memory:a,sessionEntity:o,fallbackAgentName:s,transcriptReady:c=!0}=e;if(c&&r){let e=wT({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=wT({sessionId:t,choice:n,catalog:i,memory:a,fallbackAgentName:s,source:`history`});if(e)return e}if(c&&a){let e=a.getSessionAgentSelection?.(t)??null,n=e&&xT(i,e)?e:s&&xT(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&bT(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&ST(i,e.providerId,e.modelId,r)?r:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let r=a.getSessionModelSelection?.(t);if(r&&bT(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&ST(i,r.providerId,r.modelId,e)?e:void 0;return{agent:n,providerID:r.providerId,modelID:r.modelId,variant:o,source:`session-memory`}}}let l=o?.model;if(l&&bT(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&xT(i,o.agent)?o.agent:void 0)??(e&&xT(i,e)?e:s&&xT(i,s)?s:void 0),r=l.variant,c=r&&ST(i,l.providerID,l.id,r)?r:void 0;return{agent:n,providerID:l.providerID,modelID:l.id,variant:c,source:`session-entity`}}return null},ET=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let{sessionId:i,memory:a}=n;a.saveSessionModelSelection(i,e.providerID,e.modelID);let o=r??t.currentAgentName;o&&a.saveSessionAgentSelection&&a.saveSessionAgentSelection(i,o),o&&(a.saveAgentModelForSession(i,o,e.providerID,e.modelID),a.saveAgentModelVariantForSession(i,o,e.providerID,e.modelID,e.variant))},DT=(e,t)=>{if((t?.expectedConfigKey===void 0||t.activeDirectoryKey===t.expectedConfigKey)&&!(!e.currentProviderId||!e.currentModelId))return{providerID:e.currentProviderId,modelID:e.currentModelId,agent:e.currentAgentName,variant:e.currentVariant}},OT=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,kT=e=>{if(e.captured?.providerID&&e.captured?.modelID)return e.captured;let t=e.surfaceSelection;if(!(!t?.providerID||!t?.modelID))return{providerID:t.providerID,modelID:t.modelID,...t.agent?{agent:t.agent}:{},...t.variant?{variant:t.variant}:{}}},AT=e=>typeof e==`string`&&e.trim().length>0?e:void 0,jT=e=>AT(e.agent)??AT(e.mode),MT=e=>AT(typeof e.model==`object`?e.model?.variant:void 0)??AT(e.variant),NT=e=>{let t=typeof e.model==`object`?e.model:void 0,n=AT(e.providerID)??AT(t?.providerID),r=AT(e.modelID)??AT(t?.modelID)??AT(t?.id);return!n||!r?null:{providerID:n,modelID:r}},PT=e=>NT(e),FT=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`||n.nativeType===`synthetic`||n.type===`synthetic`)continue;let r=NT(n);return{id:typeof n.id==`string`?n.id:void 0,agent:jT(n),providerID:r?.providerID,modelID:r?.modelID,variant:MT(n)}}return null},IT=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.nativeType===`synthetic`||n.type===`synthetic`)continue;if(n.role===`user`){if(NT(n))return null;continue}if(n.role!==`assistant`)continue;let r=PT(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:jT(n),providerID:r.providerID,modelID:r.modelID,variant:MT(n)}}return null},LT=500,RT=e=>Array.from(e).length,zT=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},BT=e=>RT(e)>=LT,VT=e=>{let t=Ht(e.text,e.references).document.references,n=t.reduce((e,t)=>{let n=t.kind===`paste`?t.index:0;return typeof n==`number`&&Number.isSafeInteger(n)&&n>=1?Math.max(e,n):e},0);if(n<2**53-1)return n+1;let r=new Set(t.flatMap(e=>e.kind===`paste`&&typeof e.index==`number`&&Number.isSafeInteger(e.index)&&e.index>=1?[e.index]:[]));for(let e=1;e<=t.length+1;e+=1)if(!r.has(e))return e;return 1},HT=(e,t)=>{let n=t??e;return typeof n!=`string`||!BT(n)?!1:Ft(typeof e==`string`?{text:``,references:[]}:e,n)},UT=(e,t,n,r,i=1)=>{let a=RT(e),o=new Set(n.map(e=>e.token));for(let n=i;n<2**53-1;n+=1){let i=`[${r({index:n,count:a})}]`;if(!(t.includes(i)||o.has(i)))return{id:`pasted-text-${n}-${zT(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},WT=e=>({text:e?.text??``,references:e?.composerReferences??[]}),GT=e=>({text:e.text,references:e.references.map(e=>({...e}))}),KT=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),qT=e=>JSON.stringify([e.text,e.references]),JT=(e,t)=>e!==null&&t!==null&&mn(e)===t,YT=(e,t,n)=>{let r=e?KT(e):null,i=r?n(r):void 0;return{document:zt(WT(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?mn(r):null}},XT=(e,t,n,r)=>{if(!t||mn(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=qT(WT(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===qT(e)?`same-document-metadata`:`external-document`},ZT=(e,t,n)=>{let r=n.newEnd-n.oldEnd;return e.flatMap(e=>{if(e.range.start<n.oldEnd&&e.range.end>n.oldStart)return[];let i=e.range.start>=n.oldEnd?{start:e.range.start+r,end:e.range.end+r}:e.range;return t.text.slice(i.start,i.end)===`@${e.value}`?[{...e,range:i}]:[]})},QT=e=>e.map((e,t)=>({mention:e,index:t})).sort((e,t)=>e.mention.range.start-t.mention.range.start||e.mention.range.end-t.mention.range.end||e.index-t.index).map(({mention:e})=>e),$T=(e,t,n,r,i=r)=>{let a=kt(e,n,r,i);return{document:a.document,mentions:ZT(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},eE=(e,t,n)=>({preview:{real:GT(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),tE=e=>({document:e.real,mentions:e.realMentions}),nE=(e,t,n,r)=>{let i=[...e,...t.map(e=>({...e,range:{start:e.range.start+r,end:e.range.end+r}}))],a=new Set;return i.filter(e=>{let t=`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return a.has(t)||n.text.slice(e.range.start,e.range.end)!==`@${e.value}`?!1:(a.add(t),!0)})},rE=(e,t)=>{let n=WT(t),r=Bt(e.document,n),i=e.document.text===n.text&&JSON.stringify(e.document.references)===JSON.stringify(n.references)?0:e.document.text.length+2;return{document:r,mentions:nE(e.mentions,t?.mentions??[],r,i)}},iE=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=fi})=>{let a=e?mn(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>YT(e,t,i.getState().getDraft).document),[d,f]=(0,Z.useState)(()=>YT(e,t,i.getState().getDraft).mentions),[p,m]=(0,Z.useState)(`compose`),[h,g]=(0,Z.useState)(0),_=(0,Z.useRef)(l),v=(0,Z.useRef)(d),y=(0,Z.useRef)(t),b=(0,Z.useRef)(r),x=(0,Z.useRef)(e),S=(0,Z.useRef)(e?KT(e):null),C=(0,Z.useRef)(a),w=(0,Z.useRef)(a),T=(0,Z.useRef)(0),E=(0,Z.useRef)(o?.revision??0),D=(0,Z.useRef)(void 0),O=(0,Z.useRef)(void 0),k=(0,Z.useRef)(Al());_.current=l,v.current=d,y.current=t,b.current=r,x.current=e,C.current=a;let A=(0,Z.useCallback)((e,t)=>{_.current=e,v.current=t,u(e),f(t)},[]),j=(0,Z.useCallback)((e,t)=>{let n=Pt(e,t);b.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{T.current+=1;let e=T.current;w.current=a;let t=YT(x.current,y.current,i.getState().getDraft),n=t.key;if(S.current=t.key,D.current=void 0,O.current=void 0,k.current=Al(),m(`compose`),E.current=t.revision,A(t.document,t.mentions),g(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!JT(S.current,a)||w.current!==a||C.current!==a||T.current!==e||E.current!==r||o?.revision!==t.revision||(E.current=t.revision,A(zt(WT(t),y.current),t.mentions))})}},[a,A,i]),(0,Z.useEffect)(()=>{if(!a||w.current!==a||O.current)return;let e=XT(_.current,o,D.current,{keyID:a,epoch:T.current,appliedRevision:E.current});if(e!==`ignore`){if(o&&(E.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&f(o.mentions);return}e===`external-document`&&o&&(D.current=void 0,A(zt(WT(o),y.current),o.mentions),m(`compose`),g(e=>e+1))}},[a,A,o]);let M=(0,Z.useCallback)((e,t)=>{let n=S.current;if(!JT(n,C.current)||O.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:QT(t)});if(!a)return;let o=WT(a);return D.current={keyID:mn(n),revision:a.revision,fingerprint:qT(o)},E.current=a.revision,A(o,a.mentions),j(r,o),a},[i,A,j]),N=(0,Z.useCallback)((e,t,n,r,i,a)=>{k.current=Ll(k.current,{before:Vl(e,t,n),after:Vl(r,i,a)})},[]),P=(0,Z.useCallback)(()=>O.current?(O.current=void 0,m(`compose`),!0):!1,[]),F=(0,Z.useCallback)(e=>(P(),M({text:e,references:[]},[])),[M,P]),I=(0,Z.useCallback)((e,t=[])=>{P();let n=Rt(e.text,e.references);return n?M(zt(n,y.current),t):void 0},[M,P]),L=(0,Z.useCallback)((e,t,n=t,r)=>{let i=P(),a=GT(_.current),o=i?[]:v.current,s=$T(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return M(s.document,c),s.removedReferences.length>0&&N(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[M,P,N]),R=(0,Z.useCallback)((e,t)=>{let n=_.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=P(),o=kt(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=ZT(a?[]:v.current,o.document,o.edit);return M(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[M,P]),z=(0,Z.useCallback)((e,t)=>{let n=_.current;return R({start:0,end:n.text.length,text:e},t)},[R]),B=(0,Z.useCallback)((e,t,n,r)=>{let i=P(),a=Ct(_.current,e,t,n,r);return M(a.document,ZT(i?[]:v.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[M,P]),V=(0,Z.useCallback)(e=>{let t=GT(_.current),n=nn(t,e);if(!n)return null;let r=P()?[]:v.current,i=ZT(r,n.document,n.edit),a=Dt(n.document.text,n.caret),o=kt(n.document,a.text,a.caret),s=ZT(i,o.document,o.edit);return M(o.document,s),N(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[M,P,N]),H=(0,Z.useCallback)(e=>{if(O.current)return null;let t=e===`undo`?jl(k.current,_.current):Hl(k.current,_.current);return!t||!M(t.snapshot.document,t.snapshot.mentions)?null:(k.current=t.history,t.snapshot.selection)},[M]),U=(0,Z.useCallback)(e=>M(_.current,e),[M]),W=(0,Z.useCallback)(e=>{let t=O.current?{document:{text:e.text,references:[]},mentions:[]}:eE(_.current,v.current,e);`preview`in t&&(O.current=t.preview),m(`history-preview`),A(t.document,t.mentions),g(e=>e+1)},[A]),ee=(0,Z.useCallback)(()=>{let e=O.current;if(!e)return;O.current=void 0,m(`compose`);let t=tE(e);A(t.document,t.mentions),g(e=>e+1)},[A]),te=(0,Z.useCallback)(()=>{let e=S.current;if(!JT(e,C.current))return null;let t=i.getState().getDraft(e);return{key:KT(e),keyID:mn(e),revision:t?.revision??0,document:GT(_.current),mentions:v.current.map(e=>({...e,range:{...e.range}})),epoch:T.current,runtime:i.getState().captureDraftRuntime()}},[i]),ne=(0,Z.useCallback)(e=>{let t=rE(e,i.getState().getDraft(e.key)),n=WT(i.getState().getDraft(e.key)),r=Ht(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:QT(t.mentions)});if(a){let e=WT(a);j(r,e)}return a},[j,i]),re=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:p,hydration:s,persistence:c,textPresetEpoch:h,getDocument:re,replacePlainDocument:F,replaceMaterializedDocument:I,applyBrowserEdit:L,applyProgrammaticEdit:R,replaceProgrammaticText:z,insertReference:B,deleteReference:V,restoreReferenceHistory:H,commitMentions:U,enterHistoryPreview:W,exitHistoryPreview:ee,captureSubmission:te,recoverSubmission:ne}),[L,R,te,U,V,l,W,ee,re,s,p,B,d,c,ne,I,F,z,H,h])};function aE(e){let t=e.maxLines??8,n=e.lineHeight*t+e.paddingTotal,r=Math.max(e.scrollHeight,e.dictationHeight);return{height:Math.min(r,n),maxHeight:n,overflowY:r>n?`auto`:`hidden`}}function oE(e){let t=(0,Q.c)(22),{inputRef:n,message:r,expanded:i,isMobile:a,dictationHeight:o,manualHeight:s}=e,c=s!==void 0&&s,[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f;t[0]!==o||t[1]!==i||t[2]!==n||t[3]!==c?(f=e=>{let t=n.current;if(!t||c)return;let r=t.scrollTop;if(i){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,u(null),t.scrollTop!==r&&(t.scrollTop=r);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let a=t.ownerDocument?.defaultView,s=a?a.getComputedStyle(t):null,l=s?parseFloat(s.lineHeight):NaN,d=s?parseFloat(s.paddingTop):NaN,f=s?parseFloat(s.paddingBottom):NaN,p=Number.isNaN(d)||Number.isNaN(f)?16:d+f,m=aE({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:o??0,lineHeight:Number.isNaN(l)?22:l,paddingTotal:p});t.style.height=`${m.height}px`,t.style.maxHeight=`${m.maxHeight}px`,t.style.overflowY=m.overflowY,t.scrollTop!==r&&(t.scrollTop=r),u(e=>e?.height===m.height&&e.maxHeight===m.maxHeight?e:{height:m.height,maxHeight:m.maxHeight})},t[0]=o,t[1]=i,t[2]=n,t[3]=c,t[4]=f):f=t[4];let p=J(f),m=c?null:r,h;t[5]!==m?.length||t[6]!==o||t[7]!==i||t[8]!==c||t[9]!==p?(h=()=>{let e=d.current,t=m?.length??0,n=!e||e.manualHeight||t<e.length||i!==e.expanded||e.dictationHeight!==null&&o===null;d.current={length:t,expanded:i,dictationHeight:o,manualHeight:c},p({allowShrink:n})},t[5]=m?.length,t[6]=o,t[7]=i,t[8]=c,t[9]=p,t[10]=h):h=t[10];let g;t[11]!==m||t[12]!==o||t[13]!==i||t[14]!==n||t[15]!==a||t[16]!==c||t[17]!==p?(g=[m,i,a,o,c,n,p],t[11]=m,t[12]=o,t[13]=i,t[14]=n,t[15]=a,t[16]=c,t[17]=p,t[18]=g):g=t[18],(0,Z.useLayoutEffect)(h,g);let _;return t[19]!==p||t[20]!==l?(_={size:l,resize:p},t[19]=p,t[20]=l,t[21]=_):_=t[21],_}function sE(e){let t=(0,Q.c)(26),{enabled:n,hasContent:r,draftID:i,inputRef:a}=e,o=n&&r,s;t[0]===a?s=t[1]:(s=()=>{let e=a.current;if(!e)return[];let t=e.closest(`[data-mobile-composer-surface]`)??e,n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=getComputedStyle(e),o=parseFloat(i.lineHeight)||22,s=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0),c=Math.max(parseFloat(i.minHeight)||0,o+s),l=window.visualViewport,u=l?.offsetTop??0;for(let e=t.parentElement;e;e=e.parentElement){let t=e.querySelector(`.yuri-mobile-detail-navigation, [data-mobile-chat-header]`);if(t){u=Math.max(u,t.getBoundingClientRect().bottom);break}}let d=Math.min(r.bottom,(l?.offsetTop??0)+(l?.height??window.innerHeight)),f=r.height-n.height,p=Math.max(c,d-u-f),m=e.style.height,h=e.scrollTop;e.style.height=`0px`;let g=aE({scrollHeight:e.scrollHeight,dictationHeight:0,lineHeight:o,paddingTotal:s}).height;return e.style.height=m,e.scrollTop=h,[{id:`auto`,height:Math.min(p,Math.max(c,g))},{id:`min`,height:c},{id:`full`,height:p}]},t[0]=a,t[1]=s);let c;t[2]!==a||t[3]!==s?(c={surfaceRef:a,initialPoint:`auto`,getPoints:s},t[2]=a,t[3]=s,t[4]=c):c=t[4];let l=vl(c),{reset:u}=l,d;t[5]===u?d=t[6]:(d=()=>{u()},t[5]=u,t[6]=d);let f;t[7]!==o||t[8]!==i||t[9]!==u?(f=[o,i,u],t[7]=o,t[8]=i,t[9]=u,t[10]=f):f=t[10],(0,Z.useLayoutEffect)(d,f);let p;t[11]!==o||t[12]!==l?(p=()=>{o&&l.snapPoint===`full`&&l.settleAt(`full`,void 0,!1)},t[11]=o,t[12]=l,t[13]=p):p=t[13];let m=J(p),h;t[14]===o?h=t[15]:(h=()=>o?window:null,t[14]=o,t[15]=h),Wn(`resize`,m,h);let g;t[16]===o?g=t[17]:(g=()=>o?window:null,t[16]=o,t[17]=g),Wn(`yuri:keyboard-settled`,m,g);let _;t[18]===o?_=t[19]:(_=()=>o?window.visualViewport:null,t[18]=o,t[19]=_),Wn(`resize`,m,_);let v;t[20]===o?v=t[21]:(v=()=>o?window.visualViewport:null,t[20]=o,t[21]=v),Wn(`scroll`,m,v);let y=o&&(l.dragging||l.settling||l.snapPoint!==`auto`),b;return t[22]!==o||t[23]!==l||t[24]!==y?(b={...l,visible:o,manualHeight:y},t[22]=o,t[23]=l,t[24]=y,t[25]=b):b=t[25],b}var cE=(0,Z.memo)(function(e){let t=(0,Q.c)(23),{inputRef:n,draftID:r,ariaLabel:i,onManualHeightChange:a}=e,o=(0,Z.useRef)(null),s;t[0]!==r||t[1]!==n?(s={enabled:!0,hasContent:!0,draftID:r,inputRef:n},t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=sE(s),{snapPoint:l,manualHeight:u,dragging:d,settling:f}=c,p,m;t[3]!==d||t[4]!==u||t[5]!==a||t[6]!==f||t[7]!==l?(p=()=>{let e=o.current?.closest(`[data-mobile-composer-surface]`);e&&(e.dataset.composerHeightSnap=l,e.toggleAttribute(`data-composer-height-manual`,u),d||f?e.dataset.mobileComposerResizing=`true`:delete e.dataset.mobileComposerResizing),a(u)},m=[l,u,d,f,a],t[3]=d,t[4]=u,t[5]=a,t[6]=f,t[7]=l,t[8]=p,t[9]=m):(p=t[8],m=t[9]),(0,Z.useLayoutEffect)(p,m);let h,g;t[10]===a?(h=t[11],g=t[12]):(h=()=>{let e=o.current?.closest(`[data-mobile-composer-surface]`);return()=>{e?.removeAttribute(`data-composer-height-snap`),e?.removeAttribute(`data-composer-height-manual`),e?.removeAttribute(`data-mobile-composer-resizing`),a(!1)}},g=[a],t[10]=a,t[11]=h,t[12]=g),(0,Z.useLayoutEffect)(h,g);let _=l===`min`?0:l===`auto`?1:2,v;return t[13]!==i||t[14]!==c.handleClick||t[15]!==c.handleKeyDown||t[16]!==c.handleLostPointerCapture||t[17]!==c.handlePointerCancel||t[18]!==c.handlePointerDown||t[19]!==c.handlePointerMove||t[20]!==c.handlePointerUp||t[21]!==_?(v=(0,$.jsx)(bl,{ref:o,"data-mobile-composer-snap-handle":!0,"aria-label":i,"aria-valuemin":0,"aria-valuemax":2,"aria-valuenow":_,className:`absolute top-1 left-1/2 z-40 h-2.5 w-20 -translate-x-1/2 items-center`,onPointerDown:c.handlePointerDown,onPointerMove:c.handlePointerMove,onPointerUp:c.handlePointerUp,onPointerCancel:c.handlePointerCancel,onLostPointerCapture:c.handleLostPointerCapture,onClick:c.handleClick,onKeyDown:c.handleKeyDown}),t[13]=i,t[14]=c.handleClick,t[15]=c.handleKeyDown,t[16]=c.handleLostPointerCapture,t[17]=c.handlePointerCancel,t[18]=c.handlePointerDown,t[19]=c.handlePointerMove,t[20]=c.handlePointerUp,t[21]=_,t[22]=v):v=t[22],v}),lE=.5,uE=`--yuri-mobile-composer-swap`,dE=`--yuri-native-composer-dock`,fE=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),pE=(e,t,n)=>Math.min(n,Math.max(t,e)),mE=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,hE=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return mE(e,n)?e:n},gE=(e,t)=>t?hE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?hE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,_E=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:hE(e,{phase:`snapping`,rest:t,progress:n})},vE=e=>Math.round(pE(e,0,1)*1e3)/1e3,yE=(e,t,n)=>{let r=n-t;if(r>=0)return vE(e+r/80);if(n<=2)return 0;if(n>=120)return e;let i=e+r/80,a=n/t*e;return vE(Math.min(i,a))},bE=(e,t)=>e>=1?`compact`:e<=0?`expanded`:t,xE=(e,t,n={})=>{if(e.pinned||n.userDriven===!1)return e;let r=Math.max(0,t),i=n.previousDistance==null?r:Math.max(0,n.previousDistance),a=e.phase===`snapping`?hE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(r<=2)return hE(a,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn&&a.rest===`compact`&&r<i)return hE(a,{phase:`rest`,rest:`compact`,progress:1});let o=yE(a.progress,i,r);return e.phase===`snapping`&&o===a.progress?e:o===a.progress?a:Math.abs(o-a.progress)>=lE&&(o>=1||o<=0)?hE(a,{phase:`snapping`,rest:o>=1?`compact`:`expanded`,progress:o}):o>=1||o<=0?hE(a,{phase:`rest`,rest:bE(o,a.rest),progress:o}):hE(a,{phase:`tracking`,rest:a.rest,progress:o})},SE=(e,t=null)=>e.pinned?`expanded`:t||(e.progress>=.5?`compact`:`expanded`),CE=(e,t=null)=>{if(e.pinned)return hE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let n=SE(e,t),r=+(n===`compact`);return e.phase===`rest`&&e.rest===n&&e.progress===r?e:hE(e,{phase:`snapping`,rest:n,progress:r})},wE=e=>e.phase===`snapping`?hE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,TE=e=>pE(Math.max(0,e)/80,0,1),EE=(e,t=`away`)=>{let n=Math.max(0,e);return n<=2?{progress:0,rest:`bottom`}:t===`away`||n>=40?{progress:1,rest:`away`}:{progress:TE(n),rest:`bottom`}},DE=`--yuri-mobile-composer-occupancy`,OE=(e,t)=>{if(!(t>0))return null;let n=`${Math.round(t)}px`;return e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)!==n&&e.style.setProperty(DE,n),n},kE=(e,t)=>{t!==null&&e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)===t&&e.style.removeProperty(DE)},AE=e=>{for(let t of e.children)if(t instanceof HTMLElement&&t.classList.contains(`yuri-mobile-composer-foot--overlay`)&&!t.classList.contains(`invisible`))return t;return e},jE=(e,t=e)=>{for(let n of new Set([e,t]))n.style.removeProperty(uE),n.style.removeProperty(dE);delete e.dataset.yuriComposerSwapPhase,delete e.dataset.yuriComposerSwapRest,delete e.dataset.yuriNativeComposerDock},ME=(e,t,n,r=e)=>{let i=EE(t,n?.rest===`bottom`?`bottom`:`away`),a=String(i.progress),o=i.rest;return n?.progress!==a&&r.style.setProperty(dE,a),n?.rest!==o&&(e.dataset.yuriNativeComposerDock=o),{progress:a,rest:o}},NE=(e,t,n,r=e)=>{let i=String(t.progress),a=t.phase,o=t.rest;return n?.phase!==a&&(e.dataset.yuriComposerSwapPhase=a,a===`snapping`&&n&&n.phase!==`snapping`&&r.offsetWidth),n?.progress!==i&&r.style.setProperty(uE,i),n?.rest!==o&&(e.dataset.yuriComposerSwapRest=o),{progress:i,phase:a,rest:o}},PE=`box-border w-full whitespace-pre-wrap break-words px-3 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit] md:typography-ui-label`,FE=Yu(()=>Mn(()=>import(`./ToolOutputDialog-DJs9w1_J.js`),__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,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76]))),IE=[],LE=[],RE=[],zE=[],BE=/^@[^\s]+$/,VE=({inputMode:e,message:t,showCommandAutocomplete:n})=>e!==`shell`&&(n||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),HE=/^(https?:\/\/|mailto:)\S+$/i,UE=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),WE=(e,t)=>{if(e===t)return``;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;let r=e.length,i=t.length;for(;r>n&&i>n&&e[r-1]===t[i-1];)--r,--i;return t.slice(n,i)},GE=e=>e.includes(`@`)?`paste`:`manual`,KE=(e,t)=>{let n=t,r=t;for(;n>0&&/\s/.test(e[n-1]);)--n;for(;r<e.length&&/\s/.test(e[r]);)r+=1;let i=n>0&&r<e.length?` `:``;return{text:`${e.slice(0,n)}${i}${e.slice(r)}`,caret:n+i.length}},qE=(e,t)=>Te(e,t).some(e=>e.role===`user`),JE=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!ra(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6543
6543
  `).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},YE=`file://`,XE=e=>{let t=e.replace(/\\/g,`/`);return/^[A-Za-z]:/.test(t)&&(t=`/${t}`),t.split(`/`).map((e,t)=>t===1&&/^[A-Za-z]:$/.test(e)?e:encodeURIComponent(e)).join(`/`)},ZE=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(YE)?t:`file://${XE(t)}`},QE=e=>{if(!e)return[];let t=[...SC(e).map(CC),...Array.from(e.files||[]).map(e=>_(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(wC)))},$E=e=>{if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=t.replace(/\\/g,`/`);return n===`/`?`/`:n.length>1?n.replace(/\/+$/,``):n},eD=e=>Zn(e.path),tD=(e,t)=>{if(!t)return e;let n=e.indexOf(t);return n===-1?e:(0,$.jsxs)($.Fragment,{children:[e.slice(0,n),(0,$.jsx)(`span`,{className:`font-medium`,children:t}),e.slice(n+t.length)]})},nD=e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?ZE(e.serverPath):e.dataUrl})),rD=(e,t)=>{let n=e.ownerDocument,r=n.defaultView;if(!r)return null;let i=r.getComputedStyle(e),a=n.createElement(`div`),o=a.style;o.position=`absolute`,o.visibility=`hidden`,o.pointerEvents=`none`,o.whiteSpace=`pre-wrap`,o.wordWrap=`break-word`,o.overflow=`hidden`,o.left=`-9999px`,o.top=`0`,o.width=`${e.clientWidth}px`,o.font=i.font,o.fontSize=i.fontSize,o.fontFamily=i.fontFamily,o.fontWeight=i.fontWeight,o.fontStyle=i.fontStyle,o.fontVariant=i.fontVariant,o.letterSpacing=i.letterSpacing,o.textTransform=i.textTransform,o.textIndent=i.textIndent,o.padding=i.padding,o.border=i.border,o.boxSizing=i.boxSizing,o.lineHeight=i.lineHeight,o.tabSize=i.tabSize,a.textContent=e.value.slice(0,t);let s=n.createElement(`span`);s.textContent=e.value.slice(t,t+1)||` `,a.appendChild(s),n.body.appendChild(a);let c=s.offsetTop,l=s.offsetLeft;return n.body.removeChild(a),{top:c,left:l}},iD=e=>{if(!e)return!1;if(e.files&&e.files.length>0)return!0;if(e.types){let t=Array.from(e.types).map(e=>e.toLowerCase());if(t.includes(`files`)||t.includes(`text/uri-list`)||t.includes(`codefiles`)||t.includes(`application/x-yuri-file-path`)||t.some(e=>e.includes(`vnd.code.tree`)))return!0}return SC(e).length>0},aD=e=>{if(!e)return[];let t=Array.from(e.files||[]);return t.length>0?t:Array.from(e.items||[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>!!e)},oD=e=>{let t=e.icon?Vs[e.icon]:null,n=e.color?Gs[e.color]:void 0,r=(0,$.jsx)(X,{name:t??`folder`,className:`h-3.5 w-3.5`,style:n?{color:n}:void 0});return(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-muted-foreground`,children:e.iconImage?(0,$.jsx)(Ls,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:eD(e)})]})},sD=Z.memo(nb),cD=Z.memo(Lm),lD=(0,$.jsx)(`span`,{"data-yuri-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`}),uD=Z.memo(Wm),dD=Z.memo(kx),fD=Z.memo(Mx),pD=Z.memo(Wb),mD=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=Xn(),r=K(e=>e.isMobile),i=Da(e=>e.revertToMessage),a=Da(e=>e.forkFromMessage),o=Da(e=>e.handleSlashRedo),[s,c]=Z.useState(null),[l,u]=Z.useState(null),[d,f]=Z.useState(!0),p=Z.useRef(dC),m=vr(),h=t||m,g=To(h),_=Ge(e??``,h,g),v=Gr(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=mC({session:v,messages:t,partsByMessageID:_.partsByMessageID},e,p.current);return p.current=n,n},[e,v,_]),b=y.revertMessageID,x=Z.useMemo(()=>{let t=v.find(t=>t.id===e);return Pe(t?.revert)},[e,v]),S=Z.useMemo(()=>y.records.map(e=>e.message),[y]),C=n(`chat.revertPopover.noTextContent`),w=Z.useMemo(()=>b?y.records.map(e=>({id:e.message.id,text:JE(e.parts,C)})):[],[C,b,y]),T=w[0]?.id;Z.useEffect(()=>{f(!0)},[b,T]);let E=J(async t=>{if(!(!e||s)){c(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{c(null)}}}),D=J(async t=>{if(!(!e||l)){u(t);try{await a(e,t)}finally{u(null)}}});return!e||w.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>f(e=>!e),"aria-expanded":!d,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),x.length>0&&(0,$.jsxs)(`span`,{className:`min-w-0 truncate typography-ui-label text-muted-foreground`,children:[n(`chat.revertPopover.files`),`: `,x.join(`, `)]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!d&&`rotate-180`),"aria-hidden":`true`})]}),!d&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:w.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(er,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{D(e.id)},children:[l===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(er,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{E(e.id)},children:[s===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});mD.displayName=`RevertedMessageDock`;function hD({projects:e,query:t,renderLabel:n,onSelect:r,selectedId:i}){return e.filter(e=>Ms(eD(e),t)||Ms(e.path,t)).map(e=>r?(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>r(e.id),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:n(e)}),e.id===i?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground`}):null]},e.id):(0,$.jsx)(Is,{value:e.id,className:`max-w-[24rem] truncate`,children:n(e)},e.id))}var gD=Z.memo(function(e){let t=(0,Q.c)(42),{t:n}=Xn(),{isVSCode:r,footerIconButtonClass:i,iconSizeClass:a,handlePickLocalFiles:o,openIssuePicker:s,openPrPicker:c,onOpenSettings:l,withTooltip:u}=e,d=u!==void 0&&u,f=!!e.onOpenMobileSheet,p;t[0]===n?p=t[1]:(p=n(`chat.chatInput.actions.attachFiles`),t[0]=n,t[1]=p);let m=p,h=o,g;t[2]!==h||t[3]!==e?(g=()=>e.onOpenAndroidPickSheet?e.onOpenAndroidPickSheet():h(),t[2]=h,t[3]=e,t[4]=g):g=t[4];let _=f?ED:void 0,v=f?DD:void 0,y=d?void 0:m,b;t[5]===a?b=t[6]:(b=Y(a,`text-current`),t[5]=a,t[6]=b);let x;t[7]===b?x=t[8]:(x=(0,$.jsx)(X,{name:`attachment-2`,className:b}),t[7]=b,t[8]=x);let S;t[9]!==m||t[10]!==i||t[11]!==g||t[12]!==_||t[13]!==v||t[14]!==y||t[15]!==x?(S=(0,$.jsx)(`button`,{type:`button`,className:i,onClick:g,onMouseDown:_,onPointerDownCapture:v,title:y,"aria-label":m,children:x}),t[9]=m,t[10]=i,t[11]=g,t[12]=_,t[13]=v,t[14]=y,t[15]=x,t[16]=S):S=t[16];let C=S,w;t[17]!==C||t[18]!==m||t[19]!==d?(w=d?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:C}),(0,$.jsx)(ec,{side:`top`,sideOffset:8,className:`yuri-composer-tooltip`,children:m})]}):C,t[17]=C,t[18]=m,t[19]=d,t[20]=w):w=t[20];let T;t[21]!==i||t[22]!==o||t[23]!==a||t[24]!==r||t[25]!==s||t[26]!==c||t[27]!==e.onMenuOpenChange||t[28]!==e.onOpenMobileSheet||t[29]!==n?(T=null,t[21]=i,t[22]=o,t[23]=a,t[24]=r,t[25]=s,t[26]=c,t[27]=e.onMenuOpenChange,t[28]=e.onOpenMobileSheet,t[29]=n,t[30]=T):T=t[30];let E;t[31]!==T||t[32]!==w?(E=(0,$.jsxs)(`div`,{className:`relative inline-flex`,children:[w,T]}),t[31]=T,t[32]=w,t[33]=E):E=t[33];let D;t[34]!==i||t[35]!==a||t[36]!==l||t[37]!==n?(D=l?(0,$.jsx)(`button`,{type:`button`,onClick:l,className:i,title:n(`chat.chatInput.actions.modelAgentSettings`),"aria-label":n(`chat.chatInput.actions.modelAgentSettings`),children:(0,$.jsx)(X,{name:`ai-agent`,className:Y(a,`text-current`)})}):null,t[34]=i,t[35]=a,t[36]=l,t[37]=n,t[38]=D):D=t[38];let O;return t[39]!==E||t[40]!==D?(O=(0,$.jsxs)(`div`,{className:`flex items-center gap-x-1.5`,children:[E,D]}),t[39]=E,t[40]=D,t[41]=O):O=t[41],O},(e,t)=>e.isVSCode===t.isVSCode&&e.footerIconButtonClass===t.footerIconButtonClass&&e.iconSizeClass===t.iconSizeClass&&e.onOpenSettings===t.onOpenSettings&&e.onMenuOpenChange===t.onMenuOpenChange&&e.onOpenMobileSheet===t.onOpenMobileSheet&&e.onOpenAndroidPickSheet===t.onOpenAndroidPickSheet&&e.withTooltip===t.withTooltip),_D=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=Xn(),r=e.enabled?`chat.chatInput.permissionAutoAccept.disable`:`chat.chatInput.permissionAutoAccept.enable`,i;t[0]!==n||t[1]!==r?(i=n(r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o=e.saving,s=e.enabled,c=e.footerIconButtonClass,l;t[3]!==e.draftEnabled||t[4]!==e.draftOpen||t[5]!==e.enabled||t[6]!==e.onOpenSessionFirst||t[7]!==e.onSetDraftEnabled||t[8]!==e.onSetSessionEnabled||t[9]!==e.onToggleFailed||t[10]!==e.sessionId?(l=()=>sT({permissionScopeSessionId:e.sessionId,newSessionDraftOpen:e.draftOpen,draftPermissionAutoAcceptEnabled:e.draftEnabled,permissionAutoAcceptEnabled:e.enabled,setDraftPermissionAutoAcceptEnabled:e.onSetDraftEnabled,setSessionAutoAccept:e.onSetSessionEnabled,onOpenSessionFirst:e.onOpenSessionFirst,onToggleFailed:e.onToggleFailed}),t[3]=e.draftEnabled,t[4]=e.draftOpen,t[5]=e.enabled,t[6]=e.onOpenSessionFirst,t[7]=e.onSetDraftEnabled,t[8]=e.onSetSessionEnabled,t[9]=e.onToggleFailed,t[10]=e.sessionId,t[11]=l):l=t[11];let u=e.enabled?`shield-check`:`shield`,d;t[12]===e.iconSizeClass?d=t[13]:(d=Y(e.iconSizeClass,`text-current`),t[12]=e.iconSizeClass,t[13]=d);let f;t[14]!==u||t[15]!==d?(f=(0,$.jsx)(X,{name:u,className:d}),t[14]=u,t[15]=d,t[16]=f):f=t[16];let p;t[17]!==a||t[18]!==e.enabled||t[19]!==e.footerIconButtonClass||t[20]!==e.saving||t[21]!==l||t[22]!==f?(p=(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:OD,onPointerDownCapture:kD,children:f})}),t[17]=a,t[18]=e.enabled,t[19]=e.footerIconButtonClass,t[20]=e.saving,t[21]=l,t[22]=f,t[23]=p):p=t[23];let m;t[24]===a?m=t[25]:(m=(0,$.jsx)(ec,{side:`top`,sideOffset:8,className:`yuri-composer-tooltip`,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(tc,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),vD=Z.memo(function(e){let t=(0,Q.c)(65),{isMobile:n,compact:r,footerIconButtonClass:i,stopFooterIconButtonClass:a,compactCircleButtonClass:o,sendIconSizeClass:s,stopIconSizeClass:c,canSend:l,canAbort:u,abortPending:d,hasContent:f,currentSessionId:p,newSessionDraftOpen:m,draftSubmitting:h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y,onPrimaryAction:b,onAbort:x}=e,S=r!==void 0&&r,{t:C}=Xn(),w=u,T,E,D,O,k;if(t[0]!==w||t[1]!==l||t[2]!==S||t[3]!==o||t[4]!==p||t[5]!==h||t[6]!==i||t[7]!==f||t[8]!==n||t[9]!==m||t[10]!==b||t[11]!==y||t[12]!==v||t[13]!==s||t[14]!==_||t[15]!==a||t[16]!==c||t[17]!==g||t[18]!==C){k=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Wx({canSend:l,hasSessionTarget:!!(p||m),draftSubmitting:!!h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:AD,onPointerDownCapture:jD}:{},t[24]=n,t[25]=r);let u=r,d=_.inFlight,x=d&&_.flightKind===`queue`,A=d&&_.flightKind!==`queue`,j;t[26]!==x||t[27]!==A||t[28]!==C?(j=C(x?`chat.chatInput.actions.queuingMessageAria`:A?`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[26]=x,t[27]=A,t[28]=C,t[29]=j):j=t[29];let M=j;T=S?o??a??i:a??i,E=c;let N=!w&&(!e.sendDisabled||d),P;t[30]!==n||t[31]!==b?(P=e=>{n&&(e.preventDefault(),b())},t[30]=n,t[31]=b,t[32]=P):P=t[32];let F;t[33]!==w||t[34]!==d||t[35]!==x||t[36]!==A||t[37]!==C?(F=C(A||!w&&d?x?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[33]=w,t[34]=d,t[35]=x,t[36]=A,t[37]=C,t[38]=F):F=t[38];let I;t[39]!==w||t[40]!==E||t[41]!==d||t[42]!==s||t[43]!==N?(I=N?(0,$.jsx)(Kl,{className:E,spinning:!!(d&&!w)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[39]=w,t[40]=E,t[41]=d,t[42]=s,t[43]=N,t[44]=I):I=t[44];let L=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":N?`true`:void 0,disabled:e.sendDisabled,"aria-busy":d||void 0,...u,onClick:P,className:Y(N?T:i,N?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":F,children:I});if(!w){k=L;break bb0}let R=!S&&(f||x),z=!e.sendDisabled&&!x,B=S&&`h-full`;t[45]===B?D=t[46]:(D=Y(`relative z-30 overflow-visible`,B),t[45]=B,t[46]=D),O=R?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":z||x?`true`:void 0,disabled:e.sendDisabled||x,"aria-busy":x||void 0,...u,onClick:e=>{e.preventDefault(),!x&&b()},className:Y(z||x?T:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,z||x?void 0:e.disabledClass),"aria-label":M,children:z||x?(0,$.jsx)(Kl,{className:E,spinning:x}):(0,$.jsx)(X,{name:`send-plane-2`,className:s})}):null}t[0]=w,t[1]=l,t[2]=S,t[3]=o,t[4]=p,t[5]=h,t[6]=i,t[7]=f,t[8]=n,t[9]=m,t[10]=b,t[11]=y,t[12]=v,t[13]=s,t[14]=_,t[15]=a,t[16]=c,t[17]=g,t[18]=C,t[19]=T,t[20]=E,t[21]=D,t[22]=O,t[23]=k}else T=t[19],E=t[20],D=t[21],O=t[22],k=t[23];if(k!==Symbol.for(`react.early_return_sentinel`))return k;let A=d||void 0,j;t[47]===T?j=t[48]:(j=Y(T,`relative z-30`),t[47]=T,t[48]=j);let M;t[49]===C?M=t[50]:(M=C(`chat.chatInput.actions.stopGeneratingAria`),t[49]=C,t[50]=M);let N;t[51]!==d||t[52]!==E?(N=d?(0,$.jsx)(Kl,{className:E,spinning:!0}):(0,$.jsx)(kl,{className:Y(E)}),t[51]=d,t[52]=E,t[53]=N):N=t[53];let P;t[54]!==d||t[55]!==x||t[56]!==A||t[57]!==j||t[58]!==M||t[59]!==N?(P=(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,onClick:x,disabled:d,"aria-busy":A,className:j,"aria-label":M,children:N}),t[54]=d,t[55]=x,t[56]=A,t[57]=j,t[58]=M,t[59]=N,t[60]=P):P=t[60];let F;return t[61]!==D||t[62]!==O||t[63]!==P?(F=(0,$.jsxs)(`div`,{className:D,children:[O,P]}),t[61]=D,t[62]=O,t[63]=P,t[64]=F):F=t[64],F},(e,t)=>e.isMobile===t.isMobile&&e.compact===t.compact&&e.footerIconButtonClass===t.footerIconButtonClass&&e.stopFooterIconButtonClass===t.stopFooterIconButtonClass&&e.compactCircleButtonClass===t.compactCircleButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&e.abortPending===t.abortPending&&e.hasContent===t.hasContent&&e.currentSessionId===t.currentSessionId&&e.newSessionDraftOpen===t.newSessionDraftOpen&&e.draftSubmitting===t.draftSubmitting&&e.submissionBlocked===t.submissionBlocked&&e.sendPhase===t.sendPhase&&e.queueFrozen===t.queueFrozen&&e.queueFallbackAvailable===t.queueFallbackAvailable&&e.onPrimaryAction===t.onPrimaryAction&&e.onAbort===t.onAbort),yD=(e,t)=>`${e}${e?e.endsWith(`
6544
6544
 
6545
6545
  `)?``:e.endsWith(`
@@ -6593,7 +6593,7 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}f
6593
6593
 
6594
6594
  `):AP(Array.from(t.childNodes).map(e=>FP(e)).join(``))},RP=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!OP.has(t.tagName.toLowerCase())}),zP=(e,t)=>{let n=e.cloneContents();if(RP(n)){let e=AP(Array.from(n.childNodes).map(e=>FP(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>LP(e)).filter(e=>e.length>0).join(`
6595
6595
 
6596
- `).trim()||AP(t)},BP=({containerRef:e})=>{let{t}=Xn(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),o=Z.useRef(!1),[s,c]=Z.useState(!1),l=Z.useRef(null),u=Z.useRef(wP),d=Z.useRef(null),f=Z.useRef(null),p=Z.useRef(null),m=Z.useRef(!1),h=Z.useRef(0),[g,_]=Z.useState(null),v=Da(e=>e.currentSessionId),y=Cd()??null,b=K(e=>e.isMobile),x=wb(),S=Tb(x).textSelectionMutation,C=x.kind===`primary`&&!!v;Z.useEffect(()=>{m.current=n.show},[n.show]),Z.useEffect(()=>()=>{f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]);let w=Z.useCallback(()=>{d.current=null,DP===w&&(DP=null),m.current&&=(f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),c(!1),r(e=>({...e,show:!1})),a(``),!1)},[]);Z.useEffect(()=>()=>{DP===w&&(DP=null)},[w]);let T=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=u.current/2,r=yP+n,i=t-yP-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),E=Z.useCallback(()=>{if(!d.current)return;DP!==w&&(DP?.(),DP=w);let{markdownText:e,rect:t}=d.current,i=!n.show,o=b?t.left+t.width/2:T(t.left+t.width/2),s=t.top-10;a(e),r({x:o,y:s,show:!0}),m.current=!0,i&&(c(!0),f.current!==null&&window.cancelAnimationFrame(f.current),f.current=window.requestAnimationFrame(()=>{c(!1),f.current=null}))},[T,w,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!l.current)return;let e=l.current.offsetWidth;!Number.isFinite(e)||e<=0||e===u.current||(u.current=e,r(e=>({...e,x:T(e.x)})))},[T,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:T(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[T,b,n.show]);let D=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){o.current||w();return}let r=AP(t.toString());if(!r){o.current||w();return}let i=NP(t,n);if(!i){o.current||w();return}let a=i.getBoundingClientRect();d.current={plainText:r,markdownText:zP(i,r),rect:a},o.current||E()},[e,w,E]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{o.current=!0,w()},r=()=>{o.current=!1,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{p.current=null,D()},10)},i=new Set,a=()=>{for(let e of MP(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,D))};a();let s=new MutationObserver(a);s.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,D),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let c=e=>{l.current&&!l.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&w()};return document.addEventListener(`mousedown`,c),()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null),s.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,D);document.removeEventListener(`selectionchange`,D),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,c)}},[e,D,w,E]),Z.useLayoutEffect(()=>{if(!b||!n.show){h.current=0,_(null);return}let e=Ow(Nw),t=0,r=0,i=()=>{let e=EP(h.current);h.current=e.height,_(t=>t&&t.left===e.left&&t.top===e.top&&t.width===e.width&&t.height===e.height?t:e)},a=e=>{i(),e<r&&(t=window.requestAnimationFrame(a))},o=()=>{r=performance.now()+320,window.cancelAnimationFrame(t),t=window.requestAnimationFrame(a)};i(),o();let s=window.visualViewport;return s?.addEventListener(`resize`,o),s?.addEventListener(`scroll`,o),window.addEventListener(`resize`,o),window.addEventListener(`yuri:keyboard-anim`,o),window.addEventListener(`yuri:keyboard-settled`,o),()=>{window.cancelAnimationFrame(t),s?.removeEventListener(`resize`,o),s?.removeEventListener(`scroll`,o),window.removeEventListener(`resize`,o),window.removeEventListener(`yuri:keyboard-anim`,o),window.removeEventListener(`yuri:keyboard-settled`,o),e()}},[b,n.show]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{l.current&&e.target instanceof Node&&l.current.contains(e.target)||w()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,w]);let O=()=>{w(),window.getSelection()?.removeAllRanges()},k=J(e=>{if(!e)return;let t=Da.getState().newSessionDraft.draftID,n=Vg(v,t);n&&($g.getState().addQuote(n,e),O(),requestAnimationFrame(()=>{Array.from(document.querySelectorAll(`textarea[data-chat-input="true"]`)).find(e=>!e.disabled&&e.getClientRects().length>0&&!e.closest(`[data-btw-composer]`))?.focus({preventScroll:!0})}))}),A=J(e=>{if(!e||!v)return;let t={sessionId:v,directory:y};ww.getState().addQuote(t,e),O(),qw(t)});if(Z.useEffect(()=>{if(!S)return;let t=t=>{let n=Mc(t,bP),r=C&&Mc(t,xP);if(!n&&!r)return;let i=window.getSelection(),a=e.current;if(!i||!a||!i.toString().trim())return;let o=NP(i,a);if(!o)return;t.preventDefault(),t.stopPropagation();let s=zP(o,i.toString());n?k(s):A(s)};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[k,A,C,S,e]),!n.show||!S)return null;let j=[{id:`chat`,label:t(`chat.textSelection.actions.addToChat`),shortcut:bP,run:()=>k(i)},...C?[{id:`side`,label:t(`chat.textSelection.actions.addToSideChat`),shortcut:xP,run:()=>A(i)}]:[]];if(b){let e=g??{left:0,top:Math.max(0,window.innerHeight-88),width:window.innerWidth,height:88};return(0,bp.createPortal)((0,$.jsx)(`div`,{ref:l,"data-text-selection-menu":!0,className:Y(`fixed z-50 flex items-center justify-center gap-2 bg-background px-4`,`transition-opacity duration-200 ease-out`,s?`opacity-0`:`opacity-100`),style:{left:e.left,top:e.top,width:e.width,height:e.height,paddingBottom:`max(0.75rem, var(--yuri-safe-area-bottom-visual, env(safe-area-inset-bottom, 0px)))`},onPointerDown:e=>{e.preventDefault()},children:j.map(e=>(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`sm`,onClick:e.run,className:`max-w-[11rem] min-w-0`,children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})},e.id))}),document.body)}return(0,bp.createPortal)((0,$.jsx)(`div`,{ref:l,"data-text-selection-menu":!0,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsx)(`div`,{className:Y(`flex items-center gap-0.5 whitespace-nowrap rounded-lg p-0.5`,`border border-[var(--interactive-border)] bg-[var(--surface-elevated)] shadow-sm`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,s?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:j.map((e,t)=>(0,$.jsxs)(Z.Fragment,{children:[t>0?(0,$.jsx)(`div`,{className:`h-3 w-px shrink-0 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{type:`button`,onClick:e.run,className:`flex h-6 items-center gap-1.5 rounded-md px-2 typography-meta text-[var(--surface-foreground)] transition-colors duration-150 hover:bg-[var(--interactive-hover)]`,children:[(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(`span`,{className:`tracking-[0.08em] text-[var(--surface-muted-foreground)]`,"aria-hidden":`true`,children:CP(e.shortcut)})]})]},e.id))})}),document.body)},VP=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),HP=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),VP(e,n)},UP=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),WP=e=>String(e).padStart(2,`0`),GP=e=>{if(!UP(e))return``;let t=new Date(e);return`${t.getFullYear()}-${WP(t.getMonth()+1)}-${WP(t.getDate())} ${WP(t.getHours())}:${WP(t.getMinutes())}`},KP=(e,t)=>{if(!UP(e))return``;let n=new Date(e),r=new Date,i=hc(n,t),a=$n(),o=rr.getState().dictionary;if(VP(n,r))return i;if(HP(n,r))return ir(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},qP=144,JP=null,YP=new Set,XP=!1,ZP=null;function QP(){for(let e of YP)e()}function $P(){return JP}function eF(){return ZP}function tF(e){return YP.add(e),()=>{YP.delete(e)}}function nF(e,t){let n=Z.useSyncExternalStore(tF,$P,eF);return t&&n===e}function rF(e){!e||JP===e||(JP=e,QP())}function iF(e){JP!==null&&(e&&JP!==e||(JP=null,QP()))}function aF(e){return e instanceof Element?e.closest(`[data-message-id]`)?.getAttribute(`data-message-id`)??null:null}function oF(){XP||typeof document>`u`||(XP=!0,document.addEventListener(`pointerdown`,e=>{JP&&aF(e.target)!==JP&&iF()},!0))}function sF(e,t){oF();let n=0,r=0,i=!1,a=e=>{e.button===0&&(i=!0,n=e.clientX,r=e.clientY)},o=e=>{if(!i)return;i=!1;let a=e.clientX-n,o=e.clientY-r;a*a+o*o>qP||rF(t)},s=()=>{i=!1};return e.addEventListener(`pointerdown`,a),e.addEventListener(`pointerup`,o),e.addEventListener(`pointercancel`,s),()=>{e.removeEventListener(`pointerdown`,a),e.removeEventListener(`pointerup`,o),e.removeEventListener(`pointercancel`,s),iF(t)}}var cF=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,lF=e=>{let t=0,n=0,r=!0;return e.map(e=>{if(typeof e.createdAt==`number`&&Number.isFinite(e.createdAt)&&typeof e.streamedAt==`number`&&Number.isFinite(e.streamedAt)?n+=Math.max(0,e.streamedAt-e.createdAt):r=!1,t+=cF(e.outputTokens)+cF(e.reasoningTokens),!r||t<=0||n<=0)return null;let i=t/(n/1e3);return Number.isFinite(i)&&i>0?i:null})},uF=e=>{let t=lF(e);return t[t.length-1]??null},dF=e=>e.completionDisposition!==`active`&&typeof e.tps==`number`&&Number.isFinite(e.tps)&&e.tps>0,fF=e=>!Number.isFinite(e)||e<=0?``:`${e.toFixed(1)} tok/s`,pF=Z.memo(e=>{let t=(0,Q.c)(5),{sessionId:n}=e,{t:r}=Xn(),i=lr(n);if(i===0)return null;let a;t[0]!==i||t[1]!==r?(a=r(`chat.sessionBackground.tasksRunning`,{count:i}),t[0]=i,t[1]=r,t[2]=a):a=t[2];let o;return t[3]===a?o=t[4]:(o=(0,$.jsx)(`span`,{className:`inline-flex h-3.5 shrink-0 items-center whitespace-nowrap text-[11px] leading-none font-normal text-muted-foreground`,"data-background-activity":`true`,children:(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:a})}),t[3]=a,t[4]=o),o});pF.displayName=`BackgroundActivityHint`;var mF=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`yuri-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`yuri-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`yuri-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`yuri-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},hF=[`search`,`read`,`list`];function gF(e){let t=Xj(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function _F(e){let t={read:0,search:0,list:0};for(let n of e){let e=gF(n);e&&(t[e]+=1)}return t}var vF=[`edit`,`command`,`other`],yF=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),bF=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function xF(e){if(!Kj(e))return null;let t=Xj(e);return yF.has(t)?`edit`:bF.has(t)?`command`:`other`}function SF(e){let t={edit:0,command:0,other:0};for(let n of e){let e=xF(n);e&&(t[e]+=1)}return t}function CF(e){return yj(e)}var wF=[...hF,...vF];function TF(e){return{..._F(e),...SF(e)}}function EF(e){return Yj(e)}function DF(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!qj(e.toolName):e.kind!=null||e.type!=null}function OF(e,t,n){for(let r=t;r<e.length;r+=1)if(DF(n(e[r])))return!0;return!1}function kF(e){return`parts`in e?e.parts.some(e=>EF(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>EF(e))}function AF(e,t,n){let r=[],i=t;for(;i<e.length&&qj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var jF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,MF=e=>{let t=(0,Q.c)(12),{added:n,removed:r}=e;if(n<=0&&r<=0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=Y(`inline-flex flex-none items-center gap-0.5 tabular-nums`,jF),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=n>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,n]}):null,t[1]=n,t[2]=a);let o;t[3]!==n||t[4]!==r?(o=n>0&&r>0?(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}):null,t[3]=n,t[4]=r,t[5]=o):o=t[5];let s;t[6]===r?s=t[7]:(s=r>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,r]}):null,t[6]=r,t[7]=s);let c;return t[8]!==a||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`span`,{className:i,children:[a,o,s]}),t[8]=a,t[9]=o,t[10]=s,t[11]=c):c=t[11],c},NF=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=Xn(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??kF({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=TF(u.map(e=>e.tool)),p=CF(u),m=wF.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:e===`list`?t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`:e===`edit`?t===1?`chat.usedGroup.editSingle`:`chat.usedGroup.editPlural`:e===`command`?t===1?`chat.usedGroup.commandSingle`:`chat.usedGroup.commandPlural`:t===1?`chat.usedGroup.otherSingle`:`chat.usedGroup.otherPlural`,{count:t})}).join(`, `),h=J(()=>{c(e=>!e)}),g=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())}),_=o(s?`chat.usedGroup.collapseAria`:`chat.usedGroup.expandAria`),v=o(d?`chat.usedGroup.running`:`chat.usedGroup.used`),y=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:ty(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":_,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,iy),onClick:h,onKeyDown:g,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,y,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(Mj,{isMobile:t,label:o(`chat.usedGroup.running`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,y,jF,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--yuri-text-shimmer-base":`var(--tools-title)`}:{}},children:v}),m?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,y,jF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(mF,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(MF,{added:p.added,removed:p.removed}),(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:ny(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a]}):null]})};function PF(e,t,n){let r=[],i=t;for(;i<e.length&&Gj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var FF=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function IF(e){if(!e||typeof e!=`object`)return null;let t=e.state;if(!t||typeof t!=`object`)return null;let n=t;if(n.metadata&&typeof n.metadata==`object`){let e=FF(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=FF(e.name);if(t)return t;let r=FF(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=FF(n.output.name);if(e)return e}return null}function LF(e){let t=[];for(let n of e){if(typeof n!=`string`)continue;let e=n.trim();e&&t.push(e)}let n=t.slice(0,3);return{visibleNames:n,hiddenCount:Math.max(0,t.length-n.length),joinedVisible:n.join(`, `)}}var RF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,zF=({activities:e,isMobile:t,children:n})=>{let{t:r}=Xn(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>Yj(e)),{joinedVisible:l,hiddenCount:u}=LF(s.map(IF)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:ty(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,iy),onClick:f,onKeyDown:p,children:[(0,$.jsx)(`span`,{className:Y(`flex flex-none items-center justify-center`,t?`size-4`:`size-3.5`),style:{color:`var(--tools-icon)`},children:c?(0,$.jsx)(Mj,{isMobile:t,label:h,className:`block`}):(0,$.jsx)(X,{name:`book`,className:`h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta flex-none font-medium`,RF,c&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...c?{"--yuri-text-shimmer-base":`var(--tools-title)`}:{}},children:h}),d?(0,$.jsx)(`span`,{className:Y(`typography-meta h-5 min-h-0 w-0 min-w-0 max-w-full flex-1 overflow-clip sm:h-6`,RF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(mF,{text:d,active:c})}):null,(0,$.jsx)(X,{name:i?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none text-muted-foreground opacity-70`})]}),i&&n?(0,$.jsxs)(`div`,{id:o,className:ny(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),n]}):null]})},BF=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=K(VF),l=n,u=typeof l.text==`string`?l.text:``,d=typeof l.content==`string`?l.content:``,f=d.length>u.length?d:u,p=l.time,m=n.sessionID,h=o===void 0||o!==`completed`,g,_;if(t[0]!==i||t[1]!==f?(g=()=>{f.trim().length!==0&&i?.(`structural`)},_=[i,f],t[0]=i,t[1]=f,t[2]=g,t[3]=_):(g=t[2],_=t[3]),Z.useEffect(g,_),!f||f.trim().length===0)return null;let v=o??`streaming`,y=h&&typeof p?.end!=`number`,b;t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==m||t[10]!==v||t[11]!==y?(b=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(xN,{part:n,sessionId:m,messageId:r,streamPhase:v,chatRenderMode:c,hasStreamingHapticLifecycle:y,onContentChange:i,onShowPopup:s})}),t[4]=c,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=m,t[10]=v,t[11]=y,t[12]=b):b=t[12];let x;t[13]===a?x=t[14]:(x=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=x);let S;return t[15]!==b||t[16]!==x?(S=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[b,x]}),t[15]=b,t[16]=x,t[17]=S):S=t[17],S});function VF(e){return e.chatRenderMode}var HF=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},UF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,WF=Y(`typography-meta font-medium`,UF),GF=Y(`typography-meta`,UF),KF=[],qF=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},JF=e=>{let t=new Set;for(let n of e)qF(n)&&n.messageId&&t.add(n.messageId);return[...t]},YF=(e,t)=>e.some(e=>{if(!t.has(e.messageId))return!1;let n=e.part;if(n.slim===!0)return!1;if(n.type===`reasoning`)return typeof n.text==`string`&&n.text.trim().length>0;if(n.type===`file`)return typeof n.url==`string`&&n.url.trim().length>0;if(n.type===`tool`){let e=n.state?.output,t=n.state?.error;return(typeof e==`string`?e.trim().length>0:e!=null)||(typeof t==`string`?t.trim().length>0:t!=null)}return!1}),XF=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=gd(n),t[0]=n,t[1]=a);let o=a;if(!o||r)return null;let s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>i(!0),t[2]=s):s=t[2];let c;return t[3]===o?c=t[4]:(c=(0,$.jsx)(`span`,{className:`inline-flex size-[18px] flex-shrink-0 items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)]`,children:(0,$.jsx)(`img`,{src:o,alt:``,"aria-hidden":`true`,loading:`lazy`,decoding:`async`,className:`size-3.5 rounded-sm`,onError:s})}),t[3]=o,t[4]=c),c},ZF=e=>e,QF=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;if(typeof i==`string`&&i.trim().length>0){let e=i.lastIndexOf(`/`);return e>=0?i.slice(e+1):i}return null},$F=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;return typeof i==`string`&&i.trim().length>0?i:null},eI=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},tI=e=>{if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t===`pending`?`pending`:t===`in_progress`||t===`in progress`||t===`inprogress`?`in_progress`:t===`completed`||t===`done`?`completed`:t===`cancelled`||t===`canceled`?`cancelled`:null},nI=e=>{if(e.length===0)return`0 tasks`;let t=0,n=0;for(let r of e){if(!r||typeof r!=`object`)continue;let e=tI(r.status);e&&(e===`pending`&&(t+=1),e===`in_progress`&&(n+=1))}let r=t+n;return r===0?`0 tasks`:`${r} ${r===1?`task`:`tasks`}`},rI=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=nI(n.todos);if(e)return e}if(Array.isArray(r)){let e=nI(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=nI(r.todos);if(e)return e}if(typeof r==`string`&&r.trim().length>0)try{let e=JSON.parse(r);if(Array.isArray(e)){let t=nI(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=nI(e.todos);if(t)return t}}catch{}return null},iI=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=(typeof n?.offset==`number`&&Number.isFinite(n.offset)?n.offset:void 0)??(typeof n?.line==`number`&&Number.isFinite(n.line)?n.line:void 0)??(typeof r?.offset==`number`&&Number.isFinite(r.offset)?r.offset:void 0)??(typeof r?.line==`number`&&Number.isFinite(r.line)?r.line:void 0);if(!(typeof i!=`number`||i<=0))return Math.floor(i)},aI=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(uk,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,GF),style:{color:`var(--tools-description)`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full flex-1 items-baseline overflow-hidden`,GF),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(uk,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},oI=e=>{let t=Dn(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},sI=e=>{let t=e.part,n=t.tool?.toLowerCase()??``,r=t.state,i=r?.input,a=r?.metadata;if(n===`grep`||n===`search`||n===`find`||n===`ripgrep`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`glob`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`websearch`||n===`web-search`||n===`search_web`||n===`codesearch`||n===`perplexity`){let e=i?.query;if(typeof e==`string`&&e.trim().length>0)return e.length>50?e.slice(0,50)+`...`:e}if(n===`skill`)return IF(t);if(n===`webfetch`||n===`fetch`||n===`curl`||n===`wget`){let e=typeof i?.url==`string`&&i.url||typeof i?.URL==`string`&&i.URL||typeof a?.url==`string`&&a.url||typeof a?.URL==`string`&&a.URL||``;if(typeof e==`string`&&e.trim().length>0)return e.trim()}return n===`todowrite`||n===`todoread`?rI(e):QF(e)},cI=e=>{let t=new Set,n=new Set;for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(!Tk(e.tool))continue;let i=typeof e.id==`string`?e.id.trim():``;if(!i)continue;let a=e.state;if(!a||typeof a!=`object`)continue;let o=a,s=Nk(e)||i;n.add(s),(o.status===`pending`||o.status===`running`)&&t.add(s)}return{active:[...t],all:[...n]}},lI=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=ty(i),t[3]=i,t[4]=u);let d=n.part,f;t[5]!==n.messageId||t[6]!==l||t[7]!==r||t[8]!==i||t[9]!==s||t[10]!==o||t[11]!==d?(f=(0,$.jsx)(iN,{part:d,messageId:n.messageId,isExpanded:r,onToggle:l,isMobile:i,onContentChange:s,onShowPopup:o,animateTailText:!1}),t[5]=n.messageId,t[6]=l,t[7]=r,t[8]=i,t[9]=s,t[10]=o,t[11]=d,t[12]=f):f=t[12];let p;return t[13]!==u||t[14]!==f?(p=(0,$.jsx)(`div`,{className:u,children:f}),t[13]=u,t[14]=f,t[15]=p):p=t[15],p},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.onToggleTool===t.onToggleTool&&e.onShowPopup===t.onShowPopup&&e.onContentChange===t.onContentChange&&e.activity.id===t.activity.id&&e.activity.messageId===t.activity.messageId&&e.activity.kind===t.activity.kind&&e.activity.endedAt===t.activity.endedAt&&kA([e.activity.part],[t.activity.part])),uI=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=ty(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(pI,{toolName:n,activities:r,isMobile:i,animateTailText:!1}),t[2]=r,t[3]=i,t[4]=n,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,$.jsx)(`div`,{className:a,children:o}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&fI(e.activities,t.activities)),dI=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!PD(r.part).trim()){n++;continue}t.push({type:`reasoning`,activity:r}),n++;continue}if(r.kind===`justification`){t.push({type:`justification`,activity:r}),n++;continue}let i=r.part.tool?.toLowerCase()??``;if(qj(i)){let r=AF(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:OF(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(Gj(i)){let r=PF(e,n,e=>e.part.tool);if(r.items.length>0){t.push({type:`tool-skill-group`,activities:r.items}),n=r.end;continue}}if(Hj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(Vj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(Uj(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},fI=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.id!==i.id||r.kind!==i.kind||r.endedAt!==i.endedAt||!kA([r.part],[i.part]))return!1}return!0},pI=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=Xn(),s=K(_I),c=xd(n,o),l;t[0]===n?l=t[1]:(l=mk(n),t[0]=n,t[1]=l);let u=l,d;t[2]===n?d=t[3]:(d=n.toLowerCase(),t[2]=n,t[3]=d);let f=d===`read`,p=Z.useContext(wn),m=Sl(),h=He(vI),g=wb(),_=g.kind===`embedded`?g.directory:h,v;t[4]===n?v=t[5]:(v=n.toLowerCase(),t[4]=n,t[5]=v);let y=v===`skill`,b;t[6]===y?b=t[7]:(b={enabled:y},t[6]=y,t[7]=b);let x=Oo(b),S;t[8]===x.data?S=t[9]:(S=x.data??[],t[8]=x.data,t[9]=S);let C=S,w;t[10]===C?w=t[11]:(w=new Map(C.map(yI)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||Yj(E.part),O;t[12]===E?O=t[13]:(O=E?sI(E):null,t[12]=E,t[13]=O);let k=O,A;if(t[14]!==k||t[15]!==E||t[16]!==T||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!E||!k){A=null;break bb0}let e=T.get(k)?.path||eI(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=oI(e);if(!r){A=null;break bb0}let i;t[19]!==k||t[20]!==r?(i={name:k,path:r},t[19]=k,t[20]=r,t[21]=i):i=t[21],A=i}t[14]=k,t[15]=E,t[16]=T,t[17]=n,t[18]=A}else A=t[18];let j=A,M;if(t[22]!==_||t[23]!==f||t[24]!==E){bb1:{if(!f||!E){M=null;break bb1}let e=$F(E);if(!e){M=null;break bb1}let n=kn(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=iI(E),t[26]=E,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],M=i}t[22]=_,t[23]=f,t[24]=E,t[25]=M}else M=t[25];let N=M,P;t[32]!==_||t[33]!==m||t[34]!==p?(P=(e,t)=>{if(!_)return;let n=An(_,e);if(!n)return;if(m){m.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(p?.editor){p.editor.openFile(n,t);return}if(!On(n,_)){XO(n,_).then(()=>{let e=K.getState(),r=_||jn(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=K.getState(),i=jn(_,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=_,t[33]=m,t[34]=p,t[35]=P):P=t[35];let F=J(P),I;t[36]!==_||t[37]!==m?(I=e=>{let t=Dn(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=K.getState(),n=_||jn(``,t);e.openContextFile(n,t)};if(_&&!On(t,_)){XO(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let te=J(ee),ne;t[48]===te?ne=t[49]:(ne=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),te())},t[48]=te,t[49]=ne);let re=J(ne),G=U&&W&&`cursor-pointer`,ie=U&&!W&&`cursor-default opacity-70`,ae;t[50]!==G||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,iy,G,ie),t[50]=G,t[51]=ie,t[52]=ae):ae=t[52];let oe=U?`soft`:void 0,se=U?te:void 0,ce=U?re:void 0,le=U?`button`:void 0,ue=U&&W?0:void 0,de=U&&!W?!0:void 0,fe=i?`size-4`:`size-3.5`,pe;t[53]===fe?pe=t[54]:(pe=Y(`inline-flex items-center justify-center flex-shrink-0`,fe),t[53]=fe,t[54]=pe);let me;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(me={color:`var(--tools-icon)`},t[55]=me):me=t[55];let he=D?(0,$.jsx)(Mj,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,ge;t[56]!==pe||t[57]!==me||t[58]!==he?(ge=(0,$.jsx)(`div`,{className:pe,style:me,children:he}),t[56]=pe,t[57]=me,t[58]=he,t[59]=ge):ge=t[59];let _e,ve;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(_e=Y(WF,`inline-flex items-center flex-shrink-0 opacity-85`),ve={color:`var(--tools-title)`},t[60]=_e,t[61]=ve):(_e=t[60],ve=t[61]);let ye;t[62]===c?ye=t[63]:(ye=(0,$.jsx)(`span`,{className:_e,style:ve,title:c,children:c}),t[62]=c,t[63]=ye);let be;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(be=f&&N?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,GF),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(Zh,{filePath:N.path,className:`h-3.5 w-3.5`}):null,aI(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=be):be=t[68];let xe;t[69]!==a||t[70]!==k||t[71]!==B?(xe=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(uk,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,GF),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=xe):xe=t[72];let Se;t[73]!==k||t[74]!==V?(Se=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:bI,className:Y(`min-w-0 flex-1 inline-flex items-center gap-1.5 underline decoration-[color:var(--status-info)] underline-offset-2 hover:opacity-90`,`truncate whitespace-nowrap`,GF),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(XF,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=Se):Se=t[75];let Ce;t[76]!==H||t[77]!==j?(Ce=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,GF),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=Ce):Ce=t[78];let we;t[79]!==k||t[80]!==H||t[81]!==j?(we=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,GF),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=we):we=t[82];let Te;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Te=!f&&!B&&!V&&!H&&k?(0,$.jsx)(uk,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,GF),style:{color:`var(--tools-description)`},children:k}):null,t[83]=a,t[84]=k,t[85]=V,t[86]=f,t[87]=B,t[88]=H,t[89]=Te):Te=t[89];let Ee;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==le||t[95]!==ue||t[96]!==de||t[97]!==ge||t[98]!==ye||t[99]!==be||t[100]!==xe||t[101]!==Se||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:le,tabIndex:ue,"aria-disabled":de,children:[ge,ye,be,xe,Se,Ce,we,Te]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=le,t[95]=ue,t[96]=de,t[97]=ge,t[98]=ye,t[99]=be,t[100]=xe,t[101]=Se,t[102]=Ce,t[103]=we,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&fI(e.activities,t.activities)),mI=Z.memo(e=>{let t=(0,Q.c)(5),{activity:n,onContentChange:r,streamPhase:i}=e,a;return t[0]!==n.messageId||t[1]!==n.part||t[2]!==r||t[3]!==i?(a=(0,$.jsx)(NN,{part:n.part,messageId:n.messageId,streamPhase:i,onContentChange:r}),t[0]=n.messageId,t[1]=n.part,t[2]=r,t[3]=i,t[4]=a):a=t[4],a}),hI=Z.memo(e=>{let t=(0,Q.c)(7),{activity:n,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}=e,s;return t[0]!==a||t[1]!==n.messageId||t[2]!==n.part||t[3]!==r||t[4]!==i||t[5]!==o?(s=(0,$.jsx)(BF,{part:n.part,messageId:n.messageId,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}),t[0]=a,t[1]=n.messageId,t[2]=n.part,t[3]=r,t[4]=i,t[5]=o,t[6]=s):s=t[6],s}),gI=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=Xn(),_=Cd()??``,v=Z.useMemo(()=>JF(t),[t]),y=Z.useRef(new Set),b=Z.useRef(new Map),x=Z.useRef(new Set),[,S]=Z.useState(0),C=Z.useRef(null),w=Z.useRef(null),T=i===`active`,E=!T&&(i===`normal`||i===`abnormal`)&&typeof o==`number`&&Number.isFinite(o)&&o>=0?HF(o):null,D=i===`normal`||i===`abnormal`,O=a===`compaction`,k=D&&!O,A=O?`fold-vertical`:`stack`,j=g(i===void 0?`chat.activity.title`:T?O?`chat.activity.compacting`:`chat.activity.active`:D?O?`chat.activity.compactionCompleted`:`chat.activity.completedStatus`:`chat.activity.title`),M=Z.useMemo(()=>{let t=[];for(let n of e)n.kind===`tool`&&t.push(n.part);return yj(t)},[e]),N=M.added>0||M.removed>0,P=Z.useMemo(()=>cI(e),[e]),F=T?P.active:P.all,I=F.slice(0,c?2:3),L=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=ft(_,i,r);if(a.status===`ready`||n&&a.status===`error`||e&&a.status!==`error`&&!x.current.has(r)||(y.current.add(r),x.current.delete(r),b.current.has(r)))continue;let o=le(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),R=J(e=>{e.stopPropagation(),L(!0)}),z=T,B=z||n,V=J(()=>{if(z)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,B||L(),s()});Z.useEffect(()=>{T||!B||L(!1,!0)},[T,B]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[B]);let H=m&&!B?Math.max(0,Math.floor(r)):0,U=!m||B||H>0,W=y.current,ee=[...W].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return ft(_,n,e).status}),te=ee.includes(`loading`),ne=ee.includes(`error`),re=ee.length>0&&ee.every(e=>e===`ready`),G=t.some(e=>W.has(e.messageId)&&qF(e)),ie=re&&!G&&!YF(t,W),ae=Z.useMemo(()=>U?ZF(e):KF,[e,U]),oe=Z.useMemo(()=>U?dI(ae.filter(e=>e.kind!==`reasoning`||PD(e.part).trim().length>0)):[],[U,ae]),se=Z.useMemo(()=>B||H===0?0:Math.max(0,oe.length-H),[B,H,oe.length]),ce=Z.useMemo(()=>B||H===0?oe:oe.slice(-H),[B,H,oe]),ue=!!m&&!(T&&!O);if((!ue||z&&!O)&&oe.length===0)return null;let de=(e,t)=>{let n=(0,$.jsx)(`div`,{className:ty(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},fe=U?ce.map((e,t)=>{switch(e.type){case`reasoning`:return de(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(mI,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return de(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(hI,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(lI,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);case`tool-static-group`:return(0,$.jsx)(uI,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(NF,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return Wj(n)?(0,$.jsx)(pI,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(iN,{part:t,messageId:e.messageId,isExpanded:l.has(e.id),onToggle:u,isMobile:c,onContentChange:f,onShowPopup:d,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(zF,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(pI,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(lI,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,pe=ce.length>0;return(0,$.jsxs)(`div`,{className:ue?ty(c):`flow-root`,children:[ue?(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-[calc(100%+1rem)] min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!z&&iy,z&&`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":z?void 0:`soft`,onClick:z?void 0:V,"aria-expanded":B,"aria-disabled":z||void 0,"aria-label":z?j:g(B?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex min-w-0 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:k?(0,$.jsxs)(`span`,{className:Y(`typography-meta inline-flex shrink-0 items-center gap-1.5 tabular-nums text-muted-foreground`,c?`h-5`:`h-6`),children:[E?g(`chat.activity.completed`,{duration:E}):j,(0,$.jsx)(X,{name:B?`arrow-down-s`:`arrow-right-s`,className:`size-3.5 shrink-0 opacity-0 group-hover/tool:opacity-70 group-focus-visible/tool:opacity-70`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(Mj,{isMobile:c,label:j,className:`block`}):(0,$.jsx)(X,{name:A,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--yuri-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:j}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]})}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center`,c?`gap-0.5`:`gap-1`),children:[F.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:I.map((e,t)=>(0,$.jsx)(gs,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:F.length})})]}):null,N?(0,$.jsx)(`span`,{"data-activity-diff-totals":``,className:`inline-flex shrink-0`,children:(0,$.jsx)(MF,{added:M.added,removed:M.removed})}):null,!z&&!k?(0,$.jsx)(X,{name:B?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)}):null]})]}):null,pe?(0,$.jsxs)(`div`,{className:z?void 0:`relative ml-2 pl-3`,children:[z?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),se>0?(0,$.jsxs)(`button`,{type:`button`,onClick:V,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,se,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:fe})]}):null,B&&(te||ne||ie)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,z?void 0:`ml-5`,ne&&`text-[var(--status-error)]`),role:ne?`alert`:`status`,children:te?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):ne?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:R,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]})});function _I(e){return e.showToolFileIcons}function vI(e){return e.currentDirectory}function yI(e){return[e.name,e]}function bI(e){e.stopPropagation()}var xI=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(gI,{...e}),t[0]=e,t[1]=n),n});function SI(e){let t=(0,Q.c)(9),{presentation:n,sessionId:r,messageId:i,directory:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={bootstrap:!1},t[0]=o):o=t[0];let s=To(a,o),c;t[1]===r?c=t[2]:(c=e=>!!e.session_execution_recovery[r],t[1]=r,t[2]=c);let l=z(s,c),u;t[3]===r?u=t[4]:(u=e=>e.session_status[r]?.type===`retry`,t[3]=r,t[4]=u);let d=z(s,u),f=Aa(r,a);if(!l&&!d){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Iv,{presentation:n}),t[5]=n,t[6]=e),e}let p;for(let e=f.length-1;e>=0;--e)if(f[e].role===`assistant`){p=f[e].id;break}if(p===i&&(d||l&&n.detail===`aborted`&&n.icon===`pause-circle`))return null;let m;return t[7]===n?m=t[8]:(m=(0,$.jsx)(Iv,{presentation:n}),t[7]=n,t[8]=m),m}function CI(e){let t=(0,Q.c)(5),n=wb();if(!e.sessionId||!n.active||!n.capabilities.compose){let n;return t[0]===e.presentation?n=t[1]:(n=(0,$.jsx)(Iv,{presentation:e.presentation}),t[0]=e.presentation,t[1]=n),n}let r=n.directory??e.directory,i;return t[2]!==e||t[3]!==r?(i=(0,$.jsx)(SI,{...e,sessionId:e.sessionId,directory:r}),t[2]=e,t[3]=r,t[4]=i):i=t[4],i}var wI={contain:`layout`},TI={containerType:`inline-size`,containerName:`message-footer`},EI=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,DI=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,OI=`size-6! p-0 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50`,kI=`size-3.5!`,AI=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,jI=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,MI=`flex items-center gap-2`,NI=`flex w-max max-w-full flex-none flex-wrap items-center gap-2 text-muted-foreground`,PI=`h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,FI=`inline-flex ${PI}`,II=`size-3.5!`,LI=`medium`,RI=e=>{let t=(0,Q.c)(6),{messageId:n,label:r,focusReveal:i}=e,a=nF(n,i),o=i?a?`inline-flex`:`hidden`:`hidden yuri-message-hover-time`,s;t[0]===o?s=t[1]:(s=Y(PI,`whitespace-nowrap`,o),t[0]=o,t[1]=s);let c=i?a?`true`:`false`:void 0,l;return t[2]!==r||t[3]!==s||t[4]!==c?(l=(0,$.jsx)(`span`,{className:s,"data-message-time":``,"data-message-time-visible":c,children:r}),t[2]=r,t[3]=s,t[4]=c,t[5]=l):l=t[5],l},zI=e=>{let t=(0,Q.c)(16),{label:n}=e,{t:r}=Xn(),i;t[0]!==n||t[1]!==r?(i=r(`chat.messageBody.meta.tpsAria`,{rate:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{weight:LI,name:`pulse`,className:II}),t[3]=a):a=t[3];let o;t[4]===n?o=t[5]:(o=(0,$.jsx)(`span`,{className:`message-footer__label`,children:n}),t[4]=n,t[5]=o);let s;t[6]!==i||t[7]!==o?(s=(0,$.jsx)($s,{asChild:!0,children:(0,$.jsxs)(`span`,{className:FI,"aria-label":i,children:[a,o]})}),t[6]=i,t[7]=o,t[8]=s):s=t[8];let c;t[9]===r?c=t[10]:(c=r(`chat.messageBody.meta.tpsTooltip`),t[9]=r,t[10]=c);let l;t[11]===c?l=t[12]:(l=(0,$.jsx)(ec,{children:c}),t[11]=c,t[12]=l);let u;return t[13]!==s||t[14]!==l?(u=(0,$.jsxs)(tc,{children:[s,l]}),t[13]=s,t[14]=l,t[15]=u):u=t[15],u},BI=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,VI=`w-full min-w-0 justify-start rounded-[var(--radius-md)] bg-transparent px-1 hover:!bg-interactive-hover focus-visible:!bg-interactive-hover active:!bg-interactive-active supports-[corner-shape:squircle]:rounded-[var(--radius-md)]`,HI=`h-7 gap-1.5`,UI=`h-6 gap-1`,WI=`text-[11px] leading-none`,GI=`size-3.5`,KI=`size-3`,qI=5,JI=Z.memo(e=>{let t=(0,Q.c)(30),{file:n,isMobile:r}=e,i=r?`gap-1 text-[11px]`:`gap-1.5 text-xs`,a;t[0]===i?a=t[1]:(a=Y(`flex min-w-0 flex-1 items-center leading-none text-muted-foreground`,i),t[0]=i,t[1]=a);let o=n.file,s=r?`h-3 w-3`:`h-3.5 w-3.5`,c;t[2]===s?c=t[3]:(c=Y(`flex-shrink-0`,s),t[2]=s,t[3]=c);let l;t[4]!==n.file||t[5]!==c?(l=(0,$.jsx)(Zh,{filePath:o,className:c}),t[4]=n.file,t[5]=c,t[6]=l):l=t[6];let u=n.file,d;t[7]===n.file?d=t[8]:(d=BI(n.file),t[7]=n.file,t[8]=d);let f;t[9]!==n.file||t[10]!==d?(f=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left text-foreground/80`,title:u,children:d}),t[9]=n.file,t[10]=d,t[11]=f):f=t[11];let p=r?`text-[11px]`:`typography-meta`,m;t[12]===p?m=t[13]:(m=Y(`inline-flex flex-shrink-0 items-center gap-0 leading-none tabular-nums`,p),t[12]=p,t[13]=m);let h;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(h={color:`var(--status-success)`},t[14]=h):h=t[14];let g;t[15]===n.additions?g=t[16]:(g=(0,$.jsxs)(`span`,{style:h,children:[`+`,n.additions]}),t[15]=n.additions,t[16]=g);let _,v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`/`}),v={color:`var(--status-error)`},t[17]=_,t[18]=v):(_=t[17],v=t[18]);let y;t[19]===n.deletions?y=t[20]:(y=(0,$.jsxs)(`span`,{style:v,children:[`-`,n.deletions]}),t[19]=n.deletions,t[20]=y);let b;t[21]!==m||t[22]!==g||t[23]!==y?(b=(0,$.jsxs)(`span`,{className:m,children:[g,_,y]}),t[21]=m,t[22]=g,t[23]=y,t[24]=b):b=t[24];let x;return t[25]!==b||t[26]!==a||t[27]!==l||t[28]!==f?(x=(0,$.jsxs)(`span`,{className:a,children:[l,f,b]}),t[25]=b,t[26]=a,t[27]=l,t[28]=f,t[29]=x):x=t[29],x}),YI=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=Xn(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?UI:HI,d;t[3]===u?d=t[4]:(d=Y(VI,u),t[3]=u,t[4]=d);let f;t[5]!==n.file||t[6]!==o?(f=o(`chat.changedFiles.actions.openFileTitle`,{path:n.file}),t[5]=n.file,t[6]=o,t[7]=f):f=t[7];let p;t[8]!==n||t[9]!==i?(p=(0,$.jsx)(JI,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),XI=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=Xn(),c=Cd(),l=wb(),u=l.directory||c,d=l.sessionId,f=Sl(),p=K(lL),m;t[0]===r?m=t[1]:(m=r??[],t[0]=r,t[1]=m);let h=m,g;t[2]===h?g=t[3]:(g=h.slice(0,qI),t[2]=h,t[3]=g);let _=g,v=Math.max(0,h.length-_.length),y=h.length>0?h.length:n,b=!!(f||!o&&u||o&&a),x;t[4]!==y||t[5]!==s?(x=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[4]=y,t[5]=s,t[6]=x):x=t[6];let S=x,C;t[7]!==v||t[8]!==s?(C=s(v===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:v}),t[7]=v,t[8]=s,t[9]=C):C=t[9];let w=C,T=Y(VI,o?UI:HI),E=o?KI:GI,D;t[10]===o?D=t[11]:(D=o?Y(WI,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=D);let O=D,k;t[12]===o?k=t[13]:(k=o?Y(WI,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=k);let A=k,j;t[14]===o?j=t[15]:(j=o?Y(WI,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=j);let M=j,N;t[16]!==u||t[17]!==d||t[18]!==a||t[19]!==o||t[20]!==f||t[21]!==i?(N=e=>{if(f){f.openTurnDiff(i,d,e);return}if(!o&&u){IN({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&IN({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[16]=u,t[17]=d,t[18]=a,t[19]=o,t[20]=f,t[21]=i,t[22]=N):N=t[22];let P=J(N),F;t[23]!==u||t[24]!==d||t[25]!==a||t[26]!==o||t[27]!==f||t[28]!==p||t[29]!==i||t[30]!==_[0]?.file?(F=()=>{if(f){f.openTurnDiff(i,d);return}if(!o&&u){p(u,{mode:`diff`,dedupeKey:`turn-diff:${d||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:d});return}let e=_[0]?.file;e&&o&&a&&u&&IN({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let te;t[46]!==S||t[47]!==A?(te=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=te):te=t[48];let ne;t[49]===E?ne=t[50]:(ne=Y(E,`opacity-60`),t[49]=E,t[50]=ne);let re;return t[51]===ne?re=t[52]:(re=(0,$.jsx)(X,{name:`arrow-right-s`,className:ne}),t[51]=ne,t[52]=re),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,te,re]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(YI,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),ZI=e=>e.type===`subtask`,QI=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},$I=e=>{if(!e||typeof e!=`object`)return null;let t=typeof e.providerID==`string`?e.providerID.trim():``,n=typeof e.modelID==`string`?e.modelID.trim():``;return!t||!n?null:`${t}/${n}`},eL=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=Cd(),{isMobile:o}=$c(),s=Da(uL),c=K(dL),l=wb(),{t:u}=Xn(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,p;t[2]===n.command?p=t[3]:(p=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=p);let m=p,h;t[4]===n.agent?h=t[5]:(h=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=h);let g=h,_;t[6]===n.prompt?_=t[7]:(_=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=_);let v=_,y;t[8]===n.taskSessionID?y=t[9]:(y=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=y);let x=y,S;t[10]===n.model?S=t[11]:(S=$I(n.model),t[10]=n.model,t[11]=S);let C=S,w=!!v&&!(o&&l.kind===`primary`),T;t[12]===u?T=t[13]:(T=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=T);let E;t[14]===T?E=t[15]:(E=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:T}),t[14]=T,t[15]=E);let D;t[16]===m?D=t[17]:(D=m?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,m]}):null,t[16]=m,t[17]=D);let O;t[18]===g?O=t[19]:(O=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,g]}):null,t[18]=g,t[19]=O);let k;t[20]===C?k=t[21]:(k=C?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:C}):null,t[20]=C,t[21]=k);let A;t[22]!==O||t[23]!==k||t[24]!==E||t[25]!==D?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E,D,O,k]}),t[22]=O,t[23]=k,t[24]=E,t[25]=D,t[26]=A):A=t[26];let j;t[27]===f?j=t[28]:(j=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=j);let M;t[29]!==r||t[30]!==v||t[31]!==w||t[32]!==u?(M=w?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(fL),children:u(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:v}):null]}):null,t[29]=r,t[30]=v,t[31]=w,t[32]=u,t[33]=M):M=t[33];let N;t[34]!==g||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==x?(N=x&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&Eb(l,x,e,()=>{if(!oa({sessionId:x,directory:e})){if(hl()||o||b()){s(x,e);return}c(e,{mode:`chat`,dedupeKey:`session:${x}`,label:f||g||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=g,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=x,t[43]=N):N=t[43];let P;return t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==N?(P=(0,$.jsxs)(`div`,{className:`mt-2`,children:[A,j,M,N]}),t[44]=A,t[45]=j,t[46]=M,t[47]=N,t[48]=P):P=t[48],P},tL=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=Cd(),i=K(pL),{isMobile:a}=$c(),{t:o}=Xn(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!b(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let c=!!s,l;t[3]!==n.state||t[4]!==o?(l=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=l):l=t[5];let u=l,d=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),f=n.description||d,p=J(()=>{!c||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:f,readOnly:!0})}),m;t[6]===p?m=t[7]:(m=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())},t[6]=p,t[7]=m);let h=J(m),g=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,_;t[8]===g?_=t[9]:(_=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,g),t[8]=g,t[9]=_);let v=c?`button`:void 0,y=c?0:void 0,x=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,S=c?p:void 0,C=c?h:void 0,w;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=w):w=t[10];let T;t[11]===f?T=t[12]:(T=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=T);let E=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,D;t[13]===E?D=t[14]:(D=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,E),t[13]=E,t[14]=D);let O;t[15]!==u||t[16]!==D?(O=(0,$.jsx)(`span`,{className:D,children:u}),t[15]=u,t[16]=D,t[17]=O):O=t[17];let k;t[18]!==T||t[19]!==O?(k=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[T,O]}),t[18]=T,t[19]=O,t[20]=k):k=t[20];let A;t[21]===n.body?A=t[22]:(A=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-clip text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Ju,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=A);let j;t[23]!==k||t[24]!==A?(j=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[k,A]}),t[23]=k,t[24]=A,t[25]=j):j=t[25];let M;return t[26]!==C||t[27]!==j||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==x||t[32]!==S?(M=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":x,onClick:S,onKeyDown:C,children:[w,j]}),t[26]=C,t[27]=j,t[28]=_,t[29]=v,t[30]=y,t[31]=x,t[32]=S,t[33]=M):M=t[33],M},nL={background:`transparent`,backgroundColor:`transparent`},rL=e=>{let t=(0,Q.c)(37),{part:n}=e,[r,i]=Z.useState(!1),a=Z.useRef(null),{t:o}=Xn(),s;t[0]===n.shellAction?s=t[1]:(s=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=s);let c=s,l=typeof n.shellAction?.output==`string`?n.shellAction.output:``,u;t[2]===n.shellAction?u=t[3]:(u=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=u);let d=u,f=l.length>0,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{a.current!==null&&typeof window<`u`&&(window.clearTimeout(a.current),a.current=null)},t[4]=p):p=t[4];let m=J(p),h,g;t[5]===m?(h=t[6],g=t[7]):(h=()=>()=>{m()},g=[m],t[5]=m,t[6]=h,t[7]=g),Z.useEffect(h,g);let _;t[8]!==m||t[9]!==f||t[10]!==l?(_=async()=>{f&&(await Yn(l)).ok&&(m(),i(!0),typeof window<`u`&&(a.current=window.setTimeout(()=>{i(!1),a.current=null},2e3)))},t[8]=m,t[9]=f,t[10]=l,t[11]=_):_=t[11];let v=J(_),y;t[12]===o?y=t[13]:(y=o(`chat.messageBody.shellCommand.title`),t[12]=o,t[13]=y);let b;t[14]===y?b=t[15]:(b=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:y}),t[14]=y,t[15]=b);let x;t[16]!==d||t[17]!==o?(x=d&&d!==`completed`?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,d===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),role:d===`error`?`alert`:`status`,children:d===`running`?o(`chat.assistantStatus.runningCommand`):d===`pending`?o(`chat.statusRow.todo.status.pending`):d===`error`?o(`chat.toolPart.error`):d}):null,t[16]=d,t[17]=o,t[18]=x):x=t[18];let S;t[19]!==r||t[20]!==v||t[21]!==f||t[22]!==o?(S=f?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,className:`ml-auto text-muted-foreground`,onClick:()=>{v()},"aria-label":o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:(0,$.jsx)(X,{name:r?`check`:`file-copy`,className:`h-3.5 w-3.5`})}):null,t[19]=r,t[20]=v,t[21]=f,t[22]=o,t[23]=S):S=t[23];let C;t[24]!==S||t[25]!==b||t[26]!==x?(C=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[b,x,S]}),t[24]=S,t[25]=b,t[26]=x,t[27]=C):C=t[27];let w;t[28]===c?w=t[29]:(w=c?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(zd,{language:`bash`,code:c,codeStyle:nL,wrap:!0})}):null,t[28]=c,t[29]=w);let T;t[30]!==f||t[31]!==l?(T=f?(0,$.jsx)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:(0,$.jsx)(`pre`,{className:`typography-meta max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-foreground/85`,tabIndex:0,children:l})}):null,t[30]=f,t[31]=l,t[32]=T):T=t[32];let E;return t[33]!==C||t[34]!==w||t[35]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-3 py-2`,children:[C,w,T]}),t[33]=C,t[34]=w,t[35]=T,t[36]=E):E=t[36],E},iL=e=>{let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.round(t),r=Math.floor(n/86400),i=Math.floor(n%86400/3600),a=Math.floor(n%3600/60),o=n%60;return[r>0?`${r}d`:``,i>0?`${i}h`:``,a>0?`${a}m`:``,o>0?`${o}s`:``].filter(Boolean).join(` `)},aL=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=Xn(),w=Ox(),T=Tb(wb()),E=K(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!ID(e):!!(ZI(e)||QI(e))),[n]),j=Z.useMemo(()=>A.map(e=>ra(e)?Vk(PD(e)):void 0),[A]),M=f?.token,N=!1,P=!!l,F=!!u,I=!!(s??a),L=!!c,R=b!==`external-actions`,z=b!==`external-content`,B=x&&b===`inline`,V=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),H=J(()=>{!I||!P||!L||typeof window>`u`||(V(),O(!0),k.current=window.setTimeout(()=>{O(!1),k.current=null},1800))});Z.useEffect(()=>{L||(O(!1),V())},[V,L]);let U=J(e=>{!l||!L||(e.stopPropagation(),e.preventDefault(),l(),I&&H())}),W=w===`mini-chat`||!T.fork?void 0:h,ee=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=KP(i,E);return e.length>0?e:null},[S,i,E]),te=Y(`yuri-user-actions-hover-scope`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),ne=!_&&v&&z?(0,$.jsx)(`div`,{className:te,...HO,children:(0,$.jsxs)(`div`,{className:Y(MI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(FI,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:LI,name:`edit`,className:II}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:LI,name:`close`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,re=(_&&z?(0,$.jsx)(`div`,{className:te,...HO,children:(0,$.jsx)(`div`,{className:Y(MI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(FI,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??ne??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:te,...HO,children:(0,$.jsxs)(`div`,{className:Y(MI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 yuri-message-hover-actions`),"data-message-action-group":`true`,children:[ee?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(FI,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:LI,name:`time`,className:II}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(ec,{children:ee})]}):null,m&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:LI,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(kI,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:LI,name:`edit`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:LI,name:g===`fork`?`loader-4`:`git-branch`,className:Y(kI,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:OI,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:LI,name:`check`,className:Y(kI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:LI,name:`file-copy`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full yuri-message-hover-scope`,...HO,"data-user-message-body":`true`,style:wI,onTouchStart:I&&P&&L?H:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,B?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:B?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:A.map((e,i)=>{if(ZI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(eL,{part:e})},e.id??`user-subtask-${i}`);if(QI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(rL,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(tL,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&PD(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ak,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Cg,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),re]}):(0,$.jsx)($.Fragment,{children:re})}),oL=Z.memo(({messageId:e,hasCopyableText:t,isTouchContext:n,onCopyMessage:r,reviewTransferAction:i,ttsText:a,sessionId:o})=>{let{t:s}=Xn(),c=Ox(),l=wb(),u=Tb(l),{isPlaying:d,play:f,stop:p,canResume:m}=uP(),h=Z.useContext(fP),g=!!(h&&h.sessionId===o&&h.messageId===e),_=d||g,v=ni(e=>e.showMessageTTSButtons),y=ni(e=>e.voiceProvider),[b,x]=Z.useState(!1),[S,C]=Z.useState(!1),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),O=Z.useRef(null),k=Z.useRef(null),A=Z.useRef(null),j=!!r,M=!!((l.sessionId||o)&&l.directory&&u.openSourceSession&&c!==`mini-chat`),N=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),P=J(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)});Z.useEffect(()=>()=>{N(),P()},[P,N]),Z.useEffect(()=>{(!t||!j)&&(x(!1),C(!1),N(),P())},[j,P,N,t]);let F=J(()=>{!n||!j||!t||typeof window>`u`||(N(),x(!0),k.current=window.setTimeout(()=>{x(!1),k.current=null},1800))}),I=J(async e=>{!r||!t||(e.stopPropagation(),e.preventDefault(),await r()!==!1&&(P(),C(!0),typeof window<`u`&&(A.current=window.setTimeout(()=>{C(!1),A.current=null},2e3)),n&&F()))}),L=J(async e=>{if(e.stopPropagation(),e.preventDefault(),!(!i||w||!t)){T(!0);try{await i.onClick()}finally{T(!1)}}}),R=J(e=>{e.stopPropagation(),e.preventDefault();let t=l.sessionId||o;!t||!l.directory||!l.openSourceSession||l.openSourceSession(t,l.directory)}),z=Z.useMemo(()=>_?s(`chat.messageBody.tts.stopSpeaking`):s(`chat.messageBody.tts.readAloudWithProvider`,{provider:y===`browser`?`Browser`:y===`openai`?`OpenAI`:y===`openai-compatible`?`Custom`:`Say`}),[_,s,y]),B=J((e=!1)=>{if(D(!1),!a.trim())return;let t=O.current?.closest(`[data-message-text-export-root]`)??void 0;f(a,e=>{e&&zn.error(s(`chat.messageBody.tts.failed`))},{target:t,restart:e})}),V=J((e,t)=>{if(!e){D(!1);return}if(_){t.cancel(),g&&h?.stop(),p();return}let n=O.current?.closest(`[data-message-text-export-root]`)??void 0;if(m(a,n)){D(!0);return}t.cancel(),B()});return(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":b||S?`true`:void 0,className:Y(OI,!t&&`opacity-50`),disabled:!t,"aria-label":s(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!t,onPointerDown:e=>e.stopPropagation(),onClick:e=>{I(e)},onFocus:()=>{t&&x(!0)},onBlur:()=>{S||x(!1)},children:S?(0,$.jsx)(X,{weight:LI,name:`check`,className:Y(kI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:LI,name:`file-copy`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:s(`chat.messageBody.actions.copyAnswer`)})]}),M?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":s(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:R,children:(0,$.jsx)(X,{weight:LI,name:`target`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:s(`chat.messageBody.actions.openSourceSession`)})]}):null,i&&c!==`mini-chat`&&u.reviewTransfer?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,disabled:w||!t,className:Y(OI,(!t||w)&&`opacity-50`),"aria-label":i.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{L(e)},children:w?(0,$.jsx)(X,{weight:LI,name:`loader-4`,className:Y(kI,`animate-spin`)}):(0,$.jsx)(X,{weight:LI,name:`arrow-left-right`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:i.tooltip})]}):null,c!==`mini-chat`&&v&&t&&a.trim()&&(0,$.jsxs)(qc,{open:E&&!_,onOpenChange:V,modal:!1,children:[(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(Yc,{asChild:!0,children:(0,$.jsx)(er,{ref:O,type:`button`,variant:`ghost`,size:`icon`,className:Y(OI,`!bg-transparent shadow-none`,_?`text-[var(--primary-base)]`:`hover:text-foreground/80`),"aria-label":s(_?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),"aria-pressed":_,onPointerDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Um,{kind:`speaker`,active:_,className:kI})})})}),(0,$.jsx)(ec,{sideOffset:6,children:z})]}),(0,$.jsxs)(Ic,{side:`top`,align:`start`,sideOffset:6,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(kc,{className:n?`min-h-11 px-3`:void 0,onSelect:()=>B(!1),children:[(0,$.jsx)(X,{name:`play`,weight:LI,className:`size-4`}),s(`chat.messageBody.tts.resume`)]}),(0,$.jsxs)(kc,{className:n?`min-h-11 px-3`:void 0,onSelect:()=>B(!0),children:[(0,$.jsx)(X,{name:`restart`,weight:LI,className:`size-4`}),s(`chat.messageBody.tts.restart`)]})]})]})]})}),sL=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,isMobile:c,alwaysShowActions:l,hasTouchInput:u,expandedTools:d,onToggleTool:f,onShowPopup:p,streamPhase:m,allowAnimation:h,onContentChange:g,hasTextContent:_=!1,onCopyMessage:v,onAuxiliaryContentComplete:y,showReasoningTraces:x=!1,shouldShowHeader:S=!1,turnGroupingContext:C,errorPresentation:w,reviewTransferDirection:T=null})=>{let E=w?.text,{t:D}=Xn(),O=Ox(),k=wb(),A=Tb(k),j=m,M=Z.useRef(null),N=Z.useRef(null),P=m===`streaming`||m===`cooldown`,F=Z.useRef({messageId:t,experiencedStreamingOrCooldown:P});F.current.messageId===t?P&&(F.current.experiencedStreamingOrCooldown=!0):F.current={messageId:t,experiencedStreamingOrCooldown:P};let I=!!(u??c),L=!!(l??c),R=c?jI:AI,z=!i,B=Z.useMemo(()=>n.filter(e=>!ID(e)).filter(e=>e.type!==`reasoning`||x&&PD(e).trim().length>0).filter(e=>e.type!==`compaction`),[n,x]),V=Z.useMemo(()=>B.filter(e=>e.type===`tool`),[B]),H=Z.useMemo(()=>B.filter(e=>e.type===`text`),[B]),U=Z.useMemo(()=>ua(H),[H]),W=K(e=>e.openContextPreview),ee=b(),te=O===`mini-chat`,ne=Z.useMemo(()=>{if(ee||c||te)return null;for(let e of H){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=_d(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of V){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=_d(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[H,c,te,ee,V]),re=Da(e=>e.forkFromMessage),G=Da(e=>e.forkTransition),ie=Da(e=>e.currentSessionId),ae=Da(e=>e.getDirectoryForSession),oe=Cd(),se=T===`review-to-original`,ce=!c&&!ee?T:null,le=Z.useMemo(()=>{let t=U.trim();if(!(!e||!oe||!t||!ce))return ce===`review-to-original`?{ariaLabel:D(`chat.messageBody.actions.sendReviewFeedback`),tooltip:D(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await ca(e,oe,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:D(`chat.messageBody.actions.sendImplementationResponse`),tooltip:D(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await Ha(e,oe,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[U,oe,ce,e,D]),[ue,de]=Z.useState(!1),fe=K(e=>e.chatRenderMode),pe=C?fe:`live`,me=K(e=>e.collapsibleThinkingBlocks),he=K(e=>e.showSplitAssistantMessageActions),ge=K(e=>e.showAssistantTps),_e=pe===`sorted`,ve=C?.isLastAssistantInTurn??!1,ye=a===`stop`,be=(ye||i||!!E)&&(C?.isTurnSettled??!0),xe=ye?`completed`:j,Se=V.length>0,Ce=Z.useMemo(()=>V.some(e=>Yj(e)),[V]),we=Yj,Te=Jj,Ee=F.current.experiencedStreamingOrCooldown,De=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(De.current.messageId!==t&&(De.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Ee||!Ca())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of V){if(n.observedPartIds.has(i.id))continue;if(!Fo(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),xi({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Ee,we,t,e,V]);let Oe=Z.useMemo(()=>V.length===0||!Ce&&V.every(e=>Te(e)),[V,Ce,Te]),ke=Z.useMemo(()=>B.filter(e=>e.type===`reasoning`),[B]),Ae=Z.useMemo(()=>ke.length===0||ke.every(e=>typeof e.time?.end==`number`),[ke]),je=typeof a!=`string`,Me=ke.length>0&&Se&&(Ce||je||!Oe),Ne=z||Se&&(Ce||je||!Oe),Pe=z||Me,Fe=Se||ke.length>0,Ie=H.length===0,Le=Fe&&Ie&&!Ne&&!Pe&&Oe&&Ae,Re=Z.useRef(!1),ze=Z.useRef(!1);Z.useEffect(()=>{ze.current=!1},[t]),Z.useEffect(()=>{if(!Le){Re.current=!1;return}Re.current||(Re.current=!0,y?.())},[Le,y]),Z.useEffect(()=>{if(z){ze.current=!1;return}if(Se){ze.current=!1;return}ke.length!==0&&(Pe||!Ae||ze.current||(ze.current=!0,g?.(`structural`)))},[z,Se,g,Ae,ke.length,Pe]);let Be=!!_&&!z,Ve=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ue||G)){de(!0);try{await re(e,t)}finally{de(!1)}}}),He=Z.useMemo(()=>{let e=C?.activityParts;return!_e||!e?[]:e},[_e,C?.activityParts]),Ue=Z.useMemo(()=>{let e=C?.activityGroupSegments;return!_e||!e?[]:e.filter(e=>e.anchorMessageId===t)},[_e,t,C?.activityGroupSegments]),We=Ue.length>0,Ge=Z.useMemo(()=>{let e=new Map,t=new Map;return He.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[He]),Ke=C?.toggleGroup,qe=C?.activityPresentationKind===`compaction`,Je=C?.isGroupExpanded===!0,Ye=_e&&qe&&!Je,Xe=_e?C?.activityOwnerMessageId===t||We:!C?.activityOwnerMessageId||C.activityOwnerMessageId===t||We,Ze=_e&&Xe&&(We||qe)&&!!Ke,Qe=UN(a,B),$e={finish:a,parts:B,streamPhase:xe,error:E,isLastAssistantInTurn:ve},et=JN($e),tt=ni(e=>e.ttsInputMode),nt=Z.useMemo(()=>{if(!ve||qe||!be||!et)return``;let e=r??n,t=GN(e);return t<0?``:PD(e[t])},[ve,qe,be,et,r,n]),rt=tt===`final`?nt:U;pP({sessionId:e??``,messageId:t,created:s??0,text:rt,targetRef:M,streaming:c&&k.active&&(j===`streaming`||j===`cooldown`),completed:c&&k.active&&i&&j!==`streaming`&&j!==`cooldown`&&!E});let it=_e&&YN($e),at=_e&&!et&&!(qe&&Je),ot=Be,st=ve&&be&&w?.variant!==`error`&&!Ye&&(_||!!E||i),ct=C?.diffStats?.hasDiffs===!0,lt=C?.isLatestTurn&&e&&k.active&&!te,ut=!te&&ve&&Qe&&be&&!Ye&&C?.diffStats?.hasDiffs===!0,dt=he&&ot&&!st&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(oL,{messageId:t,hasCopyableText:Be,isTouchContext:I,onCopyMessage:v,ttsText:rt,reviewTransferAction:le,sessionId:e}),[rt,Be,I,v,le,e,t]),pt=Z.useMemo(()=>e=>{if(!he||!_e)return null;let t=PD(e.part).trim();return t?(0,$.jsx)(oL,{hasCopyableText:!0,isTouchContext:I,onCopyMessage:async()=>(await Yn(t)).ok,ttsText:tt===`final`?``:t}):null},[_e,I,he,tt]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<B.length;t+=1){let n=B[t];!n||n.type!==`text`||at||Ge.get(n)?.kind!==`justification`&&(e=t)}return e},[Ge,at,dt,B]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Ze&&Ke&&C){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(xI,{parts:t,materializationParts:r,isExpanded:C.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:C.completionDisposition,activityPresentationKind:C.activityPresentationKind,durationMs:C.durationMs,startedAt:C.userMessageCreatedAt,onToggle:Ke,isMobile:c,expandedTools:d,onToggleTool:f,onShowPopup:p,onContentChange:g,streamPhase:xe,showHeader:!0,diffStats:C.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};Ue.length>0?Ue.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):qe&&e(`${t}:compaction-status`,[])}let r=0;for(;r<B.length;){let i=B[r];if(i.type===`text`){let a=Ge.get(i);if(at){r+=1;continue}if(Ye){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:N,"data-message-text-export-source":`true`,children:(0,$.jsx)(xN,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,allowSortedFinalStreaming:it,hasStreamingHapticLifecycle:Ee,onContentChange:g,onShowPopup:p})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:c?DI:EI,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:MI,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(Ge.get(i)?.kind===`reasoning`){r+=1;continue}if(!PD(i).trim()){r+=1;continue}x&&(me?n.push((0,$.jsx)(`div`,{className:ty(c),children:(0,$.jsx)(NN,{part:i,messageId:t,streamPhase:xe,onContentChange:g})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(xN,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,hasStreamingHapticLifecycle:Ee,onContentChange:g,onShowPopup:p},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(_e&&!Xe){r+=1;continue}if(Ge.get(i)?.kind===`tool`){r+=1;continue}if(_e&&qj(a)){let e=AF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(NF,{activities:i,isMobile:c,isTurnLive:xe!==`completed`,hasFollowingOtherType:OF(B,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return Wj(n)?(0,$.jsx)(pI,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(iN,{part:e.part,messageId:t,isExpanded:d.has(e.part.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:g,onShowPopup:p,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(Gj(a)){let e=PF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(zF,{activities:i,isMobile:c,children:i.map(e=>(0,$.jsx)(pI,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(Vj(a)){n.push((0,$.jsx)(`div`,{className:ty(c),children:(0,$.jsx)(iN,{part:e,messageId:t,isExpanded:d.has(e.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:g,onShowPopup:p,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:ty(c),children:(0,$.jsx)(pI,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:c,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}let i=n.at(-1);if(Z.isValidElement(i)&&i.props[`data-message-text-export-source`]===`true`&&xe!==`completed`&&!be&&!w&&(!C||C.isLastAssistantInTurn)){let e=i;n[n.length-1]=Z.cloneElement(e,{className:Y(typeof e.props.className==`string`?e.props.className:void 0,c?`pb-1`:`pb-1.5`),"data-live-status-text-gap":``})}return n},[Ge,Ue,L,pe,me,0,d,Ye,qe,c,Xe,_e,mt,t,ft,pt,e,g,p,f,Ze,dt,xe,w,Ee,be,x,at,it,Ke,C,B]),_t=Z.useMemo(()=>{if(!ve||!be)return;let e=C?.durationMs;if(!(typeof e!=`number`||e<=0))return iL(e)},[ve,be,C?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=GP(e);return t.length>0?t:null},[o,s]),yt=Z.useMemo(()=>{if(!ge||!ve||w?.variant===`error`)return null;let e=C?.assistantTps;if(!dF({completionDisposition:C?.completionDisposition,tps:e}))return null;let t=fF(e??0);return t.length>0?t:null},[ge,w?.variant,ve,C?.assistantTps,C?.completionDisposition]),bt=(0,$.jsxs)($.Fragment,{children:[!te&&!c&&!ee&&ne?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":D(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=oe??(ie?ae(ie):null);e&&W(e,ne)},children:(0,$.jsx)(X,{weight:LI,name:`global`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:D(`chat.messageBody.actions.openPreview`)})]}):null,!te&&!se&&A.fork?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,className:OI,"aria-label":D(`chat.messageBody.actions.forkAria`),"aria-busy":ue,disabled:ue||!!G,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Ve(e)},children:(0,$.jsx)(X,{weight:LI,name:ue?`loader-4`:`git-branch`,className:Y(kI,ue&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:D(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:M,"data-message-text-export-root":`true`,"data-speech-identity":e?`${e}:${t}`:void 0,...HO,className:Y(`relative w-full yuri-message-hover-scope`),style:wI,children:[(0,$.jsx)(BP,{containerRef:M}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,(S||C?.headerMessageId===t)&&(c?`[&>[data-message-text-export-source]:first-child]:pt-1.5`:`[&>[data-message-text-export-source]:first-child]:pt-2`)),children:[gt,w&&(0,$.jsx)(Ad,{children:(0,$.jsx)(`div`,{className:`my-1.5`,"data-assistant-error":w.variant,children:(0,$.jsx)(CI,{presentation:w,sessionId:e,messageId:t,directory:oe??void 0})})},`assistant-error`)]}),ut&&C?.diffStats?(0,$.jsx)(XI,{fileCount:C.diffStats.files,changedFiles:C.changedFiles,turnId:C.turnId,isLatestTurn:C.isLatestTurn,isMobile:c}):null,(0,$.jsx)(Cg,{files:n,messageID:t,sessionID:e,onShowPopup:p}),ht&&(0,$.jsx)(`div`,{className:Y(c?DI:EI),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:MI,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:R,"data-message-footer":`true`,style:TI,children:[(0,$.jsxs)(`div`,{className:MI,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt||lt?(0,$.jsxs)(`div`,{className:NI,children:[yt||_t?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 whitespace-nowrap`,children:[yt?(0,$.jsx)(zI,{label:yt}):null,_t?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsxs)(`span`,{className:FI,children:[(0,$.jsx)(X,{weight:LI,name:`hourglass`,className:II}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(ec,{children:_t})]}):null]}):null,lt&&e?(0,$.jsx)(pF,{sessionId:e}):null,vt?(0,$.jsx)(RI,{messageId:t,label:vt,focusReveal:c}):null]}):null,!te&&ve&&ye&&!ct?(0,$.jsx)(LN,{activityParts:C?.activityParts}):null]}),!st&&!Ye&&yt?(0,$.jsx)(`div`,{className:R,"data-message-footer":`true`,"data-message-tps":`interrupted`,style:TI,children:(0,$.jsx)(`div`,{className:NI,children:(0,$.jsx)(zI,{label:yt})})}):null]})]})}),cL=Z.memo(e=>{let t=(0,Q.c)(28),n,r;if(t[0]===e?(n=t[1],r=t[2]):({isUser:n,...r}=e,t[0]=e,t[1]=n,t[2]=r),n){let e;return t[3]!==r.agentMention||t[4]!==r.alwaysShowActions||t[5]!==r.copiedMessage||t[6]!==r.editStaged||t[7]!==r.editing||t[8]!==r.hasTextContent||t[9]!==r.hasTouchInput||t[10]!==r.isMobile||t[11]!==r.messageCreatedAt||t[12]!==r.messageId||t[13]!==r.onCancelEdit||t[14]!==r.onCopyMessage||t[15]!==r.onEdit||t[16]!==r.onFork||t[17]!==r.onRevert||t[18]!==r.onShowPopup||t[19]!==r.parts||t[20]!==r.pendingMessageAction||t[21]!==r.sessionId||t[22]!==r.sourceParts||t[23]!==r.stickyUserHeaderEnabled||t[24]!==r.userActionsMode?(e=(0,$.jsx)(aL,{sessionId:r.sessionId,messageId:r.messageId,parts:r.parts,sourceParts:r.sourceParts,messageCreatedAt:r.messageCreatedAt,isMobile:r.isMobile,alwaysShowActions:r.alwaysShowActions,hasTouchInput:r.hasTouchInput,hasTextContent:r.hasTextContent,onCopyMessage:r.onCopyMessage,copiedMessage:r.copiedMessage,onShowPopup:r.onShowPopup,agentMention:r.agentMention,onEdit:r.onEdit,onRevert:r.onRevert,onFork:r.onFork,pendingMessageAction:r.pendingMessageAction,editing:r.editing,editStaged:r.editStaged,onCancelEdit:r.onCancelEdit,userActionsMode:r.userActionsMode,stickyUserHeaderEnabled:r.stickyUserHeaderEnabled}),t[3]=r.agentMention,t[4]=r.alwaysShowActions,t[5]=r.copiedMessage,t[6]=r.editStaged,t[7]=r.editing,t[8]=r.hasTextContent,t[9]=r.hasTouchInput,t[10]=r.isMobile,t[11]=r.messageCreatedAt,t[12]=r.messageId,t[13]=r.onCancelEdit,t[14]=r.onCopyMessage,t[15]=r.onEdit,t[16]=r.onFork,t[17]=r.onRevert,t[18]=r.onShowPopup,t[19]=r.parts,t[20]=r.pendingMessageAction,t[21]=r.sessionId,t[22]=r.sourceParts,t[23]=r.stickyUserHeaderEnabled,t[24]=r.userActionsMode,t[25]=e):e=t[25],e}let i;return t[26]===r?i=t[27]:(i=(0,$.jsx)(sL,{...r}),t[26]=r,t[27]=i),i});function lL(e){return e.openContextPanelTab}function uL(e){return e.setCurrentSession}function dL(e){return e.openContextPanelTab}function fL(e){return!e}function pL(e){return e.openContextPanelTab}var mL=e=>{let t=e,n=t?.clientRole,r=t?.role;return t?.userMessageMarker===!0||n===`user`||r===`user`||t?.origin===`user`||t?.source===`user`?{role:`user`,isUser:!0}:{role:n||r||`assistant`,isUser:!1}},hL=e=>{if(typeof e!=`string`)return!1;let t=e.toLowerCase().trim();if(!t)return!1;if(t.includes(`token refresh failed`)||t.includes(`unauthorized`)||t.includes(`invalid token`)||t.includes(`expired token`))return!0;let n=t.includes(`oauth`),r=t.includes(`failed`)||t.includes(`invalid`)||t.includes(`expired`);if(n&&r)return!0;let i=/\b401\b/.test(t),a=t.includes(`auth`)||t.includes(`token`)||t.includes(`unauthorized`);return i&&a},gL={"provider.rate-limit":`chat.response.rateLimit`,"provider.auth":`chat.response.auth`,"provider.quota":`chat.response.quota`,"provider.content-filter":`chat.response.contentFilter`,"provider.transport":`chat.response.transport`,"provider.internal":`chat.response.internal`,"provider.invalid-output":`chat.response.invalidOutput`,"provider.invalid-request":`chat.response.invalidRequest`,"provider.unsupported-operation":`chat.response.unsupportedOperation`,"provider.no-route":`chat.response.noRoute`,"provider.unknown":`chat.response.providerUnknown`,"provider.timeout":`chat.response.timeout`,"permission.rejected":`chat.response.permissionRejected`,"tool.execution":`chat.response.toolExecution`,"compaction.failed":`chat.response.compactionFailed`,"compaction.unavailable":`chat.response.compactionUnavailable`,"compaction.interrupted":`chat.response.compactionInterrupted`},_L={icon:`pause-circle`,variant:`muted`};function vL(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:typeof n.message==`string`?n.message:void 0,i=typeof n.name==`string`?n.name:void 0,a=typeof n.type==`string`?n.type.trim():void 0,o=typeof n.status==`number`&&Number.isInteger(n.status)&&n.status>=100&&n.status<=599?n.status:void 0;if(!r&&!a&&!i&&o===void 0)return;let s=[a&&a!==`unknown`&&a!==`error`?a:void 0,o].filter(e=>e!==void 0).join(` · `)||void 0,c=(e,n,i=`error`,a=!1)=>({text:t(e),icon:n,variant:i,...r&&!a?{rawMessage:r}:{},...s?{detail:s}:{}});if(i===`SessionRetry`)return c(`chat.response.retrying`,`refresh`,`info`);if(a===`aborted`)return r===`Execution was interrupted repeatedly and will not be resumed automatically.`?c(`chat.response.resumeExhausted`,`error-warning`,`error`,!0):r===`Session interrupted by user`?c(`chat.response.stopped`,`stop-circle`,`muted`,!0):r===`Compaction cancelled`?c(`chat.response.compactionCancelled`,`stop-circle`,`muted`,!0):r===`Tool execution interrupted`?c(`chat.response.toolInterrupted`,_L.icon,_L.variant,!0):c(`chat.response.interrupted`,_L.icon,_L.variant,r===`Step interrupted`);if(i===`MessageAbortedError`||!a&&r?.trim().toLowerCase()===`aborted`)return c(`chat.response.stopped`,`stop-circle`,`muted`,!0);if(a&&Object.hasOwn(gL,a)){if(a===`compaction.interrupted`)return c(gL[a],_L.icon,_L.variant,r===`Compaction was interrupted`);if(a===`compaction.unavailable`)return c(gL[a],`information`,`info`,r===`Nothing to compact yet`);let e=a===`provider.auth`||a===`permission.rejected`?`lock`:a===`provider.timeout`?`time`:`error-warning`;return c(gL[a],e)}return(!a||a===`unknown`||a===`error`)&&hL(r)?c(`chat.response.auth`,`lock`):{...c(`chat.response.failed`,`error-warning`),...!r&&i?{rawMessage:i}:{}}}function yL(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.nativeType===`synthetic`&&t.description===`Continuing after restart`}function bL(e,t){if(yL(e))return{text:t(`chat.response.continuingAfterRestart`),icon:`restart`,variant:`info`}}function xL(e){return!e}function SL(e){let t=(0,Q.c)(60),{part:n,isMobile:r}=e,i=r!==void 0&&r,{t:a}=Xn(),o;t[0]!==n.id||t[1]!==n.messageID||t[2]!==n.sessionID?(o=JSON.stringify([n.sessionID,n.messageID,n.id]),t[0]=n.id,t[1]=n.messageID,t[2]=n.sessionID,t[3]=o):o=t[3];let s=o,{expanded:c,toggle:l}=BO(s),u=(0,Z.useId)(),d;t[4]!==s||t[5]!==l?(d=()=>l(s),t[4]=s,t[5]=l,t[6]=d):d=t[6];let f=J(d),p=n.status===`running`,m=n.status===`failed`,h;t[7]!==m||t[8]!==p||t[9]!==a?(h=a(p?`chat.activity.compacting`:m?`chat.activity.compactionFailed`:`chat.activity.compactionCompleted`),t[7]=m,t[8]=p,t[9]=a,t[10]=h):h=t[10];let g=h,_;t[11]!==m||t[12]!==n.error||t[13]!==a?(_=m?vL(n.error,a):void 0,t[11]=m,t[12]=n.error,t[13]=a,t[14]=_):_=t[14];let v=_,y;t[15]!==m||t[16]!==n.summary?(y=m?``:n.summary?.trim()??``,t[15]=m,t[16]=n.summary,t[17]=y):y=t[17];let b=y,x,S,C,w,T,E,D,O,k;if(t[18]!==u||t[19]!==c||t[20]!==v?.text||t[21]!==m||t[22]!==i||t[23]!==p||t[24]!==n.status||t[25]!==b||t[26]!==g||t[27]!==f){let e=Y(`shrink-0 typography-meta`,m?`text-[var(--status-error)]/85`:`text-muted-foreground`);E=`w-full min-w-0`,D=``,O=n.status;let r=i?`min-h-7`:`min-h-8`;t[37]===r?k=t[38]:(k=Y(`flex w-full items-center gap-3`,r),t[37]=r,t[38]=k),x=`separator`,S=p?`polite`:void 0,C=v?.text??g,t[39]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 border-t`,"aria-hidden":`true`}),t[39]=w):w=t[39],T=b?(0,$.jsxs)(er,{variant:`ghost`,size:`sm`,className:Y(e,ry),"aria-expanded":c,"aria-controls":u,onClick:f,children:[g,(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`size-4 transition-transform`,c&&`rotate-180`)})]}):(0,$.jsx)(`span`,{className:e,children:g}),t[18]=u,t[19]=c,t[20]=v?.text,t[21]=m,t[22]=i,t[23]=p,t[24]=n.status,t[25]=b,t[26]=g,t[27]=f,t[28]=x,t[29]=S,t[30]=C,t[31]=w,t[32]=T,t[33]=E,t[34]=D,t[35]=O,t[36]=k}else x=t[28],S=t[29],C=t[30],w=t[31],T=t[32],E=t[33],D=t[34],O=t[35],k=t[36];let A;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 border-t`,"aria-hidden":`true`}),t[40]=A):A=t[40];let j;t[41]!==x||t[42]!==S||t[43]!==C||t[44]!==w||t[45]!==T||t[46]!==D||t[47]!==O||t[48]!==k?(j=(0,$.jsxs)(`div`,{"data-compaction-card":D,"data-compaction-status":O,className:k,role:x,"aria-live":S,"aria-label":C,children:[w,T,A]}),t[41]=x,t[42]=S,t[43]=C,t[44]=w,t[45]=T,t[46]=D,t[47]=O,t[48]=k,t[49]=j):j=t[49];let M;t[50]!==u||t[51]!==c||t[52]!==p||t[53]!==n.messageID||t[54]!==b?(M=b&&c?(0,$.jsx)(`div`,{id:u,className:`py-2`,children:(0,$.jsx)(Zu,{content:b,messageId:n.messageID,isStreaming:p})}):null,t[50]=u,t[51]=c,t[52]=p,t[53]=n.messageID,t[54]=b,t[55]=M):M=t[55];let N;return t[56]!==E||t[57]!==j||t[58]!==M?(N=(0,$.jsxs)(`div`,{className:E,children:[j,M]}),t[56]=E,t[57]=j,t[58]=M,t[59]=N):N=t[59],N}var CL=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},wL=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=typeof t.model==`object`&&t.model!==null?t.model:void 0,r=typeof t.metadata==`object`&&t.metadata!==null?t.metadata:void 0,i=typeof r?.model==`object`&&r.model!==null?r.model:void 0,a=CL(t.mode)??CL(t.agent)??CL(r?.agent),o=CL(t.providerID)??CL(n?.providerID)??CL(i?.providerID),s=CL(t.modelID)??CL(n?.modelID)??CL(n?.id)??CL(i?.modelID)??CL(i?.id),c=CL(n?.variant)??CL(i?.variant)??CL(t.variant)??CL(r?.variant);return!a&&!o&&!s&&!c?null:{agentName:a,providerId:o,modelId:s,variant:c}},TL=e=>{let t=e?.providerId?.trim(),n=e?.modelId?.trim();return!t||!n?null:{providerId:t,modelId:n}},EL=e=>TL(e.assistantIdentity)??TL(e.userIdentity)??(e.allowComposerFallback?TL(e.composerSelection):null)??TL(e.sessionSelection),DL=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:qr(void 0,t)||void 0,variant:e?.variant}},OL=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),kL=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,AL=e=>!e,jL=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},ML=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),NL=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,PL=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,FL=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},IL=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},LL=e=>!e||FL(e)!==`user`?!1:e.parts.some(e=>{if(e?.type!==`text`)return!1;let t=e.text;return e.synthetic===!0&&typeof t==`string`&&t.trim().startsWith(`The following tool was executed by the user`)}),RL=e=>FL(e)===`user`?LL(e)||e.parts.some(e=>{let t=e.shellAction;return e.type===`text`&&typeof t==`object`&&!!t}):!1,zL=(e,t)=>{if(FL(e)!==`assistant`||t&&IL(e)!==t||e.parts.length!==1)return{hide:!1,details:null};let n=e.parts[0];return n?.type!==`tool`||(typeof n.tool==`string`?n.tool.toLowerCase():``)!==`bash`?{hide:!1,details:null}:{hide:!0,details:{command:typeof n.state?.input?.command==`string`?n.state.input.command:void 0,output:(typeof n.state?.output==`string`?n.state.output:void 0)??(typeof n.state?.metadata?.output==`string`?n.state.metadata.output:void 0),status:typeof n.state?.status==`string`?n.state.status:void 0}}},BL=(e,t)=>{let n=e[t];if(!n)return null;let r=n.info.id;for(let n=t+1;n<e.length;n+=1){let t=e[n];if(FL(t)===`user`)break;let{hide:i,details:a}=zL(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},VL=Yu(()=>Mn(()=>import(`./ToolOutputDialog-BKuVpgEu.js`),__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,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76]))),HL=4e3,UL=new Map,WL=new Map,GL=new Set([`bash`,`shell`,`cmd`,`terminal`]),KL=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(!n.includes(`.`))return n;let r=n.split(`.`).filter(Boolean);return r[r.length-1]??n},qL=e=>{let t=UL.get(e);return t?new Set(t):new Set},JL=(e,t)=>{if(UL.size>=HL&&!UL.has(e)){let e=UL.keys().next().value;typeof e==`string`&&UL.delete(e)}UL.set(e,new Set(t))},YL=e=>{let t=WL.get(e);return t?new Set(t):new Set},XL=(e,t)=>{if(WL.size>=HL&&!WL.has(e)){let e=WL.keys().next().value;typeof e==`string`&&WL.delete(e)}WL.set(e,new Set(t))},ZL=200,QL=new Map,$L=e=>QL.get(e),eR=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=QL.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(QL.size>=ZL&&!QL.has(e)){let e=QL.keys().next().value;typeof e==`string`&&QL.delete(e)}QL.set(e,t)}};function tR(e){let t=(0,Q.c)(3),[n,r]=Z.useState(e),i,a;return t[0]===e?(i=t[1],a=t[2]):(i=()=>{e!=null&&r(e)},a=[e],t[0]=e,t[1]=i,t[2]=a),Z.useEffect(i,a),e??n}var nR=(e,t)=>{if(typeof e==`object`&&e)return e[t]},rR=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s=!1,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=Xn(),{isMobile:m,isTablet:h,hasTouchInput:g}=$c(),_=wb(),v=Tb(_),y=m||h,b=Z.useRef(null),x=Z.useRef(null),S=J(t=>{b.current=t,x.current?.(),x.current=null,t&&m&&(x.current=sF(t,e.info.id))});Z.useEffect(()=>{let t=b.current;return x.current?.(),x.current=null,t&&m&&(x.current=sF(t,e.info.id)),()=>{x.current?.(),x.current=null}},[m,e.info.id]);let C=Da(e=>e.currentSessionId),w=Da(e=>e.revertToMessage),T=Da(e=>e.editMessagePreservingChanges),E=Da(e=>e.forkFromMessage),D=Da(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=Da(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=Da(e=>e.clearStagedMessageEdit);fe(`ui.chat_message.render`),c&&fe(`ui.chat_message.render.streaming`);let A=ni(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=K(H(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{C&&UO.getInstance().recordSessionStart(C)},[C]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[U,W]=Z.useState(()=>qL(e.info.id)),[ee,te]=Z.useState(()=>YL(e.info.id)),[ne,re]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{W(qL(e.info.id)),te(YL(e.info.id))},[e.info.id]);let G=Z.useMemo(()=>mL(e.info),[e.info]).isUser,ie=Z.useMemo(()=>Ee(e.parts),[e.parts]),ae=G&&(m||!M),oe=G&&!m&&M&&!ae,se=e.info.sessionID,{currentContextAgent:ce,savedSessionAgentSelection:le}=vy(H(e=>({currentContextAgent:c&&se?e.currentAgentContext.get(se):void 0,savedSessionAgentSelection:c&&se?e.sessionAgentSelections.get(se):void 0}))),ue=Z.useMemo(()=>ND(e.sourceParts??e.parts),[e.parts,e.sourceParts]),de=Z.useMemo(()=>G?qD(ue):ND(e.parts),[G,e.parts,ue]),pe=Z.useMemo(()=>{if(G||!t)return null;let e=nR(t.info,`clientRole`),n=nR(t.info,`role`);return(typeof e==`string`?e:typeof n==`string`?n:void 0)===`user`&&wL(t.info)||null},[G,t]),me=Z.useMemo(()=>{if(G)return;let t=nR(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=nR(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(pe?.agentName)return pe.agentName;if(se)return ce||(le??void 0)},[G,e.info,pe,se,ce,le]),he=G?null:wL(e.info),ge=he?.providerId??null,_e=he?.modelId??null,ve=wi(H(e=>{if(G||!se)return null;if(pe?.providerId&&pe?.modelId)return{providerId:pe.providerId,modelId:pe.modelId};if(me){let t=e.getAgentModelForSession(se,me);if(t?.providerId&&t?.modelId)return t}let t=e.getSessionModelSelection(se);return t?.providerId&&t?.modelId?t:null})),ye=Z.useMemo(()=>G?null:typeof ge==`string`&&ge.trim().length>0?ge:ve?.providerId??null,[G,ge,ve]),be=Z.useMemo(()=>G?null:typeof _e==`string`&&_e.trim().length>0?_e:ve?.modelId??null,[G,_e,ve]),xe=e.info.id?$L(e.info.id):void 0;G||eR(e.info.id,{agent:me,provider:ye??void 0,model:be??void 0});let Se=me??xe?.agent,Ce=ye??xe?.provider??null,we=be??xe?.model??null,Te=Z.useMemo(()=>{if(G)return;let e=Ce&&A.length>0?A.find(e=>e.id===Ce):void 0;return qr(e,we)||void 0},[G,Ce,we,A]),De=tR(Se),Oe=tR(Ce??void 0),ke=tR(we??void 0),Ae=tR(Te),je=De??void 0,Me=Oe??null,Ne=ke??null,Pe=Ae??void 0,Fe=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ie=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Le=Z.useMemo(()=>G?!0:!!(Fe&&Fe>0),[G,Fe]),Re=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),ze=Z.useMemo(()=>LD(de,{includeReasoning:j}),[de,j]),Be=Z.useMemo(()=>G?ze:!Le&&N===`sorted`?[]:ze,[N,Le,G,ze]),Ve=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`text`),[G,ze]),He=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`tool`),[G,ze]),Ue=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of He){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=KL(t.tool);!r||!GL.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=KL(t.part.tool);!n||!GL.has(n)||e.add(t.id)}return e},[P,He,a?.activityParts]),We=Z.useMemo(()=>{if(Ue.size===0&&ee.size===0)return U;let e=new Set(U);return Ue.forEach(t=>{ee.has(t)||e.add(t)}),ee.forEach(t=>{e.delete(t)}),e},[ee,Ue,U]),Ge=Z.useMemo(()=>{if(!G)return;let e=de.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[G,de]),Ke=G&&!JD(Be),qe=typeof Re!=`string`,Je=Z.useMemo(()=>G?!1:Ve.length===0||He.length===0?qe:!0,[Ve.length,He.length,qe,G]),Ye=Z.useMemo(()=>!G&&UO.getInstance().shouldAnimateMessage(e.info,C||e.info.sessionID),[e.info,C,G]),[Xe,Ze]=Z.useState(!1),Qe=Z.useMemo(()=>n?mL(n.info):null,[n]),$e=!!a,et=a?.isLastAssistantInTurn??!1,tt=NL({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),nt=Z.useMemo(()=>G?!1:$e?!et:Qe?!Qe.isUser&&Qe.role===`assistant`:!1,[$e,et,G,Qe]),rt=Z.useMemo(()=>Le?`completed`:c?l??`streaming`:`completed`,[l,c,Le]);Z.useEffect(()=>{!G||!u||d?.(e.info.id)},[u,G,e.info.id,d]),Z.useEffect(()=>{Ze(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;G||!t||t!==e.info.id||(rt===`streaming`||rt===`cooldown`)&&Ze(!0)},[o,G,e.info.id,rt,a?.headerMessageId]);let it=Z.useMemo(()=>{if(G)return!0;if(s)return!1;let t=o??a?.headerMessageId;return t?e.info.id===t?rt===`completed`||Xe||rt===`streaming`||rt===`cooldown`:!1:!0},[o,Xe,G,a,rt,e.info.id,s]),at=Z.useCallback(e=>{Yn(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),ot=G?void 0:he?.variant??a?.userMessageVariant??pe?.variant,st=!G&&typeof ot==`string`&&ot.trim().length>0?ot:void 0,ct=Z.useMemo(()=>{if(!G&&!xL($e?et:!nt))return vL(e.info?.error,p)},[$e,nt,et,G,e.info,p]),lt=ct?.text,ut=Z.useMemo(()=>{if(G){let e=Be.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
6596
+ `).trim()||AP(t)},BP=({containerRef:e})=>{let{t}=Xn(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),o=Z.useRef(!1),[s,c]=Z.useState(!1),l=Z.useRef(null),u=Z.useRef(wP),d=Z.useRef(null),f=Z.useRef(null),p=Z.useRef(null),m=Z.useRef(!1),h=Z.useRef(0),[g,_]=Z.useState(null),v=Da(e=>e.currentSessionId),y=Cd()??null,b=K(e=>e.isMobile),x=wb(),S=Tb(x).textSelectionMutation,C=x.kind===`primary`&&!!v;Z.useEffect(()=>{m.current=n.show},[n.show]),Z.useEffect(()=>()=>{f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]);let w=Z.useCallback(()=>{d.current=null,DP===w&&(DP=null),m.current&&=(f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),c(!1),r(e=>({...e,show:!1})),a(``),!1)},[]);Z.useEffect(()=>()=>{DP===w&&(DP=null)},[w]);let T=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=u.current/2,r=yP+n,i=t-yP-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),E=Z.useCallback(()=>{if(!d.current)return;DP!==w&&(DP?.(),DP=w);let{markdownText:e,rect:t}=d.current,i=!n.show,o=b?t.left+t.width/2:T(t.left+t.width/2),s=t.top-10;a(e),r({x:o,y:s,show:!0}),m.current=!0,i&&(c(!0),f.current!==null&&window.cancelAnimationFrame(f.current),f.current=window.requestAnimationFrame(()=>{c(!1),f.current=null}))},[T,w,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!l.current)return;let e=l.current.offsetWidth;!Number.isFinite(e)||e<=0||e===u.current||(u.current=e,r(e=>({...e,x:T(e.x)})))},[T,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:T(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[T,b,n.show]);let D=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){o.current||w();return}let r=AP(t.toString());if(!r){o.current||w();return}let i=NP(t,n);if(!i){o.current||w();return}let a=i.getBoundingClientRect();d.current={plainText:r,markdownText:zP(i,r),rect:a},o.current||E()},[e,w,E]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{o.current=!0,w()},r=()=>{o.current=!1,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{p.current=null,D()},10)},i=new Set,a=()=>{for(let e of MP(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,D))};a();let s=new MutationObserver(a);s.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,D),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let c=e=>{l.current&&!l.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&w()};return document.addEventListener(`mousedown`,c),()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null),s.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,D);document.removeEventListener(`selectionchange`,D),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,c)}},[e,D,w,E]),Z.useLayoutEffect(()=>{if(!b||!n.show){h.current=0,_(null);return}let e=Ow(Nw),t=0,r=0,i=()=>{let e=EP(h.current);h.current=e.height,_(t=>t&&t.left===e.left&&t.top===e.top&&t.width===e.width&&t.height===e.height?t:e)},a=e=>{i(),e<r&&(t=window.requestAnimationFrame(a))},o=()=>{r=performance.now()+320,window.cancelAnimationFrame(t),t=window.requestAnimationFrame(a)};i(),o();let s=window.visualViewport;return s?.addEventListener(`resize`,o),s?.addEventListener(`scroll`,o),window.addEventListener(`resize`,o),window.addEventListener(`yuri:keyboard-anim`,o),window.addEventListener(`yuri:keyboard-settled`,o),()=>{window.cancelAnimationFrame(t),s?.removeEventListener(`resize`,o),s?.removeEventListener(`scroll`,o),window.removeEventListener(`resize`,o),window.removeEventListener(`yuri:keyboard-anim`,o),window.removeEventListener(`yuri:keyboard-settled`,o),e()}},[b,n.show]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{l.current&&e.target instanceof Node&&l.current.contains(e.target)||w()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,w]);let O=()=>{w(),window.getSelection()?.removeAllRanges()},k=J(e=>{if(!e)return;let t=Da.getState().newSessionDraft.draftID,n=Vg(v,t);n&&($g.getState().addQuote(n,e),O(),requestAnimationFrame(()=>{Array.from(document.querySelectorAll(`textarea[data-chat-input="true"]`)).find(e=>!e.disabled&&e.getClientRects().length>0&&!e.closest(`[data-btw-composer]`))?.focus({preventScroll:!0})}))}),A=J(e=>{if(!e||!v)return;let t={sessionId:v,directory:y};ww.getState().addQuote(t,e),O(),qw(t)});if(Z.useEffect(()=>{if(!S)return;let t=t=>{let n=Mc(t,bP),r=C&&Mc(t,xP);if(!n&&!r)return;let i=window.getSelection(),a=e.current;if(!i||!a||!i.toString().trim())return;let o=NP(i,a);if(!o)return;t.preventDefault(),t.stopPropagation();let s=zP(o,i.toString());n?k(s):A(s)};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[k,A,C,S,e]),!n.show||!S)return null;let j=[{id:`chat`,label:t(`chat.textSelection.actions.addToChat`),shortcut:bP,run:()=>k(i)},...C?[{id:`side`,label:t(`chat.textSelection.actions.addToSideChat`),shortcut:xP,run:()=>A(i)}]:[]];if(b){let e=g??{left:0,top:Math.max(0,window.innerHeight-88),width:window.innerWidth,height:88};return(0,bp.createPortal)((0,$.jsx)(`div`,{ref:l,"data-text-selection-menu":!0,className:Y(`fixed z-50 flex items-center justify-center gap-2 bg-background px-4`,`transition-opacity duration-200 ease-out`,s?`opacity-0`:`opacity-100`),style:{left:e.left,top:e.top,width:e.width,height:e.height,paddingBottom:`max(0.75rem, var(--yuri-safe-area-bottom-visual, env(safe-area-inset-bottom, 0px)))`},onPointerDown:e=>{e.preventDefault()},children:j.map(e=>(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`sm`,onClick:e.run,className:`max-w-[11rem] min-w-0`,children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})},e.id))}),document.body)}return(0,bp.createPortal)((0,$.jsx)(`div`,{ref:l,"data-text-selection-menu":!0,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsx)(`div`,{className:Y(`flex items-center gap-0.5 whitespace-nowrap rounded-lg p-0.5`,`border border-[var(--interactive-border)] bg-[var(--surface-elevated)] shadow-sm`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,s?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:j.map((e,t)=>(0,$.jsxs)(Z.Fragment,{children:[t>0?(0,$.jsx)(`div`,{className:`h-3 w-px shrink-0 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{type:`button`,onClick:e.run,className:`flex h-6 items-center gap-1.5 rounded-md px-2 typography-meta text-[var(--surface-foreground)] transition-colors duration-150 hover:bg-[var(--interactive-hover)]`,children:[(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(`span`,{className:`tracking-[0.08em] text-[var(--surface-muted-foreground)]`,"aria-hidden":`true`,children:CP(e.shortcut)})]})]},e.id))})}),document.body)},VP=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),HP=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),VP(e,n)},UP=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),WP=e=>String(e).padStart(2,`0`),GP=e=>{if(!UP(e))return``;let t=new Date(e);return`${t.getFullYear()}-${WP(t.getMonth()+1)}-${WP(t.getDate())} ${WP(t.getHours())}:${WP(t.getMinutes())}`},KP=(e,t)=>{if(!UP(e))return``;let n=new Date(e),r=new Date,i=hc(n,t),a=$n(),o=rr.getState().dictionary;if(VP(n,r))return i;if(HP(n,r))return ir(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},qP=144,JP=null,YP=new Set,XP=!1,ZP=null;function QP(){for(let e of YP)e()}function $P(){return JP}function eF(){return ZP}function tF(e){return YP.add(e),()=>{YP.delete(e)}}function nF(e,t){let n=Z.useSyncExternalStore(tF,$P,eF);return t&&n===e}function rF(e){!e||JP===e||(JP=e,QP())}function iF(e){JP!==null&&(e&&JP!==e||(JP=null,QP()))}function aF(e){return e instanceof Element?e.closest(`[data-message-id]`)?.getAttribute(`data-message-id`)??null:null}function oF(){XP||typeof document>`u`||(XP=!0,document.addEventListener(`pointerdown`,e=>{JP&&aF(e.target)!==JP&&iF()},!0))}function sF(e,t){oF();let n=0,r=0,i=!1,a=e=>{e.button===0&&(i=!0,n=e.clientX,r=e.clientY)},o=e=>{if(!i)return;i=!1;let a=e.clientX-n,o=e.clientY-r;a*a+o*o>qP||rF(t)},s=()=>{i=!1};return e.addEventListener(`pointerdown`,a),e.addEventListener(`pointerup`,o),e.addEventListener(`pointercancel`,s),()=>{e.removeEventListener(`pointerdown`,a),e.removeEventListener(`pointerup`,o),e.removeEventListener(`pointercancel`,s),iF(t)}}var cF=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,lF=e=>{let t=0,n=0,r=!0;return e.map(e=>{if(typeof e.createdAt==`number`&&Number.isFinite(e.createdAt)&&typeof e.streamedAt==`number`&&Number.isFinite(e.streamedAt)?n+=Math.max(0,e.streamedAt-e.createdAt):r=!1,t+=cF(e.outputTokens)+cF(e.reasoningTokens),!r||t<=0||n<=0)return null;let i=t/(n/1e3);return Number.isFinite(i)&&i>0?i:null})},uF=e=>{let t=lF(e);return t[t.length-1]??null},dF=e=>e.completionDisposition!==`active`&&typeof e.tps==`number`&&Number.isFinite(e.tps)&&e.tps>0,fF=e=>!Number.isFinite(e)||e<=0?``:`${e.toFixed(1)} tok/s`,pF=Z.memo(e=>{let t=(0,Q.c)(5),{sessionId:n}=e,{t:r}=Xn(),i=lr(n);if(i===0)return null;let a;t[0]!==i||t[1]!==r?(a=r(`chat.sessionBackground.tasksRunning`,{count:i}),t[0]=i,t[1]=r,t[2]=a):a=t[2];let o;return t[3]===a?o=t[4]:(o=(0,$.jsx)(`span`,{className:`inline-flex h-3.5 shrink-0 items-center whitespace-nowrap text-[11px] leading-none font-normal text-muted-foreground`,"data-background-activity":`true`,children:(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:a})}),t[3]=a,t[4]=o),o});pF.displayName=`BackgroundActivityHint`;var mF=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`yuri-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`yuri-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`yuri-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`yuri-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},hF=[`search`,`read`,`list`];function gF(e){let t=Xj(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function _F(e){let t={read:0,search:0,list:0};for(let n of e){let e=gF(n);e&&(t[e]+=1)}return t}var vF=[`edit`,`command`,`other`],yF=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),bF=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function xF(e){if(!Kj(e))return null;let t=Xj(e);return yF.has(t)?`edit`:bF.has(t)?`command`:`other`}function SF(e){let t={edit:0,command:0,other:0};for(let n of e){let e=xF(n);e&&(t[e]+=1)}return t}function CF(e){return yj(e)}var wF=[...hF,...vF];function TF(e){return{..._F(e),...SF(e)}}function EF(e){return Yj(e)}function DF(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!qj(e.toolName):e.kind!=null||e.type!=null}function OF(e,t,n){for(let r=t;r<e.length;r+=1)if(DF(n(e[r])))return!0;return!1}function kF(e){return`parts`in e?e.parts.some(e=>EF(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>EF(e))}function AF(e,t,n){let r=[],i=t;for(;i<e.length&&qj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var jF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,MF=e=>{let t=(0,Q.c)(12),{added:n,removed:r}=e;if(n<=0&&r<=0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=Y(`inline-flex flex-none items-center gap-0.5 tabular-nums`,jF),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=n>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,n]}):null,t[1]=n,t[2]=a);let o;t[3]!==n||t[4]!==r?(o=n>0&&r>0?(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}):null,t[3]=n,t[4]=r,t[5]=o):o=t[5];let s;t[6]===r?s=t[7]:(s=r>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,r]}):null,t[6]=r,t[7]=s);let c;return t[8]!==a||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`span`,{className:i,children:[a,o,s]}),t[8]=a,t[9]=o,t[10]=s,t[11]=c):c=t[11],c},NF=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=Xn(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??kF({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=TF(u.map(e=>e.tool)),p=CF(u),m=wF.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:e===`list`?t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`:e===`edit`?t===1?`chat.usedGroup.editSingle`:`chat.usedGroup.editPlural`:e===`command`?t===1?`chat.usedGroup.commandSingle`:`chat.usedGroup.commandPlural`:t===1?`chat.usedGroup.otherSingle`:`chat.usedGroup.otherPlural`,{count:t})}).join(`, `),h=J(()=>{c(e=>!e)}),g=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())}),_=o(s?`chat.usedGroup.collapseAria`:`chat.usedGroup.expandAria`),v=o(d?`chat.usedGroup.running`:`chat.usedGroup.used`),y=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:ty(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":_,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,iy),onClick:h,onKeyDown:g,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,y,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(Mj,{isMobile:t,label:o(`chat.usedGroup.running`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,y,jF,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--yuri-text-shimmer-base":`var(--tools-title)`}:{}},children:v}),m?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,y,jF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(mF,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(MF,{added:p.added,removed:p.removed}),(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:ny(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a]}):null]})};function PF(e,t,n){let r=[],i=t;for(;i<e.length&&Gj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var FF=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function IF(e){if(!e||typeof e!=`object`)return null;let t=e.state;if(!t||typeof t!=`object`)return null;let n=t;if(n.metadata&&typeof n.metadata==`object`){let e=FF(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=FF(e.name);if(t)return t;let r=FF(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=FF(n.output.name);if(e)return e}return null}function LF(e){let t=[];for(let n of e){if(typeof n!=`string`)continue;let e=n.trim();e&&t.push(e)}let n=t.slice(0,3);return{visibleNames:n,hiddenCount:Math.max(0,t.length-n.length),joinedVisible:n.join(`, `)}}var RF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,zF=({activities:e,isMobile:t,children:n})=>{let{t:r}=Xn(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>Yj(e)),{joinedVisible:l,hiddenCount:u}=LF(s.map(IF)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:ty(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,iy),onClick:f,onKeyDown:p,children:[(0,$.jsx)(`span`,{className:Y(`flex flex-none items-center justify-center`,t?`size-4`:`size-3.5`),style:{color:`var(--tools-icon)`},children:c?(0,$.jsx)(Mj,{isMobile:t,label:h,className:`block`}):(0,$.jsx)(X,{name:`book`,className:`h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta flex-none font-medium`,RF,c&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...c?{"--yuri-text-shimmer-base":`var(--tools-title)`}:{}},children:h}),d?(0,$.jsx)(`span`,{className:Y(`typography-meta h-5 min-h-0 w-0 min-w-0 max-w-full flex-1 overflow-clip sm:h-6`,RF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(mF,{text:d,active:c})}):null,(0,$.jsx)(X,{name:i?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none text-muted-foreground opacity-70`})]}),i&&n?(0,$.jsxs)(`div`,{id:o,className:ny(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),n]}):null]})},BF=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=K(VF),l=n,u=typeof l.text==`string`?l.text:``,d=typeof l.content==`string`?l.content:``,f=d.length>u.length?d:u,p=l.time,m=n.sessionID,h=o===void 0||o!==`completed`,g,_;if(t[0]!==i||t[1]!==f?(g=()=>{f.trim().length!==0&&i?.(`structural`)},_=[i,f],t[0]=i,t[1]=f,t[2]=g,t[3]=_):(g=t[2],_=t[3]),Z.useEffect(g,_),!f||f.trim().length===0)return null;let v=o??`streaming`,y=h&&typeof p?.end!=`number`,b;t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==m||t[10]!==v||t[11]!==y?(b=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(xN,{part:n,sessionId:m,messageId:r,streamPhase:v,chatRenderMode:c,hasStreamingHapticLifecycle:y,onContentChange:i,onShowPopup:s})}),t[4]=c,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=m,t[10]=v,t[11]=y,t[12]=b):b=t[12];let x;t[13]===a?x=t[14]:(x=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=x);let S;return t[15]!==b||t[16]!==x?(S=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[b,x]}),t[15]=b,t[16]=x,t[17]=S):S=t[17],S});function VF(e){return e.chatRenderMode}var HF=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},UF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,WF=Y(`typography-meta font-medium`,UF),GF=Y(`typography-meta`,UF),KF=[],qF=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},JF=e=>{let t=new Set;for(let n of e)qF(n)&&n.messageId&&t.add(n.messageId);return[...t]},YF=(e,t)=>e.some(e=>{if(!t.has(e.messageId))return!1;let n=e.part;if(n.slim===!0)return!1;if(n.type===`reasoning`)return typeof n.text==`string`&&n.text.trim().length>0;if(n.type===`file`)return typeof n.url==`string`&&n.url.trim().length>0;if(n.type===`tool`){let e=n.state?.output,t=n.state?.error;return(typeof e==`string`?e.trim().length>0:e!=null)||(typeof t==`string`?t.trim().length>0:t!=null)}return!1}),XF=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=gd(n),t[0]=n,t[1]=a);let o=a;if(!o||r)return null;let s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>i(!0),t[2]=s):s=t[2];let c;return t[3]===o?c=t[4]:(c=(0,$.jsx)(`span`,{className:`inline-flex size-[18px] flex-shrink-0 items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)]`,children:(0,$.jsx)(`img`,{src:o,alt:``,"aria-hidden":`true`,loading:`lazy`,decoding:`async`,className:`size-3.5 rounded-sm`,onError:s})}),t[3]=o,t[4]=c),c},ZF=e=>e,QF=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;if(typeof i==`string`&&i.trim().length>0){let e=i.lastIndexOf(`/`);return e>=0?i.slice(e+1):i}return null},$F=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;return typeof i==`string`&&i.trim().length>0?i:null},eI=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},tI=e=>{if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t===`pending`?`pending`:t===`in_progress`||t===`in progress`||t===`inprogress`?`in_progress`:t===`completed`||t===`done`?`completed`:t===`cancelled`||t===`canceled`?`cancelled`:null},nI=e=>{if(e.length===0)return`0 tasks`;let t=0,n=0;for(let r of e){if(!r||typeof r!=`object`)continue;let e=tI(r.status);e&&(e===`pending`&&(t+=1),e===`in_progress`&&(n+=1))}let r=t+n;return r===0?`0 tasks`:`${r} ${r===1?`task`:`tasks`}`},rI=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=nI(n.todos);if(e)return e}if(Array.isArray(r)){let e=nI(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=nI(r.todos);if(e)return e}if(typeof r==`string`&&r.trim().length>0)try{let e=JSON.parse(r);if(Array.isArray(e)){let t=nI(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=nI(e.todos);if(t)return t}}catch{}return null},iI=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=(typeof n?.offset==`number`&&Number.isFinite(n.offset)?n.offset:void 0)??(typeof n?.line==`number`&&Number.isFinite(n.line)?n.line:void 0)??(typeof r?.offset==`number`&&Number.isFinite(r.offset)?r.offset:void 0)??(typeof r?.line==`number`&&Number.isFinite(r.line)?r.line:void 0);if(!(typeof i!=`number`||i<=0))return Math.floor(i)},aI=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(uk,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,GF),style:{color:`var(--tools-description)`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full flex-1 items-baseline overflow-hidden`,GF),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(uk,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},oI=e=>{let t=Dn(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},sI=e=>{let t=e.part,n=t.tool?.toLowerCase()??``,r=t.state,i=r?.input,a=r?.metadata;if(n===`grep`||n===`search`||n===`find`||n===`ripgrep`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`glob`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`websearch`||n===`web-search`||n===`search_web`||n===`codesearch`||n===`perplexity`){let e=i?.query;if(typeof e==`string`&&e.trim().length>0)return e.length>50?e.slice(0,50)+`...`:e}if(n===`skill`)return IF(t);if(n===`webfetch`||n===`fetch`||n===`curl`||n===`wget`){let e=typeof i?.url==`string`&&i.url||typeof i?.URL==`string`&&i.URL||typeof a?.url==`string`&&a.url||typeof a?.URL==`string`&&a.URL||``;if(typeof e==`string`&&e.trim().length>0)return e.trim()}return n===`todowrite`||n===`todoread`?rI(e):QF(e)},cI=e=>{let t=new Set,n=new Set;for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(!Tk(e.tool))continue;let i=typeof e.id==`string`?e.id.trim():``;if(!i)continue;let a=e.state;if(!a||typeof a!=`object`)continue;let o=a,s=Nk(e)||i;n.add(s),(o.status===`pending`||o.status===`running`)&&t.add(s)}return{active:[...t],all:[...n]}},lI=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=ty(i),t[3]=i,t[4]=u);let d=n.part,f;t[5]!==n.messageId||t[6]!==l||t[7]!==r||t[8]!==i||t[9]!==s||t[10]!==o||t[11]!==d?(f=(0,$.jsx)(iN,{part:d,messageId:n.messageId,isExpanded:r,onToggle:l,isMobile:i,onContentChange:s,onShowPopup:o,animateTailText:!1}),t[5]=n.messageId,t[6]=l,t[7]=r,t[8]=i,t[9]=s,t[10]=o,t[11]=d,t[12]=f):f=t[12];let p;return t[13]!==u||t[14]!==f?(p=(0,$.jsx)(`div`,{className:u,children:f}),t[13]=u,t[14]=f,t[15]=p):p=t[15],p},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.onToggleTool===t.onToggleTool&&e.onShowPopup===t.onShowPopup&&e.onContentChange===t.onContentChange&&e.activity.id===t.activity.id&&e.activity.messageId===t.activity.messageId&&e.activity.kind===t.activity.kind&&e.activity.endedAt===t.activity.endedAt&&kA([e.activity.part],[t.activity.part])),uI=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=ty(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(pI,{toolName:n,activities:r,isMobile:i,animateTailText:!1}),t[2]=r,t[3]=i,t[4]=n,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,$.jsx)(`div`,{className:a,children:o}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&fI(e.activities,t.activities)),dI=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!PD(r.part).trim()){n++;continue}t.push({type:`reasoning`,activity:r}),n++;continue}if(r.kind===`justification`){t.push({type:`justification`,activity:r}),n++;continue}let i=r.part.tool?.toLowerCase()??``;if(qj(i)){let r=AF(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:OF(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(Gj(i)){let r=PF(e,n,e=>e.part.tool);if(r.items.length>0){t.push({type:`tool-skill-group`,activities:r.items}),n=r.end;continue}}if(Hj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(Vj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(Uj(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},fI=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.id!==i.id||r.kind!==i.kind||r.endedAt!==i.endedAt||!kA([r.part],[i.part]))return!1}return!0},pI=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=Xn(),s=K(_I),c=xd(n,o),l;t[0]===n?l=t[1]:(l=mk(n),t[0]=n,t[1]=l);let u=l,d;t[2]===n?d=t[3]:(d=n.toLowerCase(),t[2]=n,t[3]=d);let f=d===`read`,p=Z.useContext(wn),m=Sl(),h=He(vI),g=wb(),_=g.kind===`embedded`?g.directory:h,v;t[4]===n?v=t[5]:(v=n.toLowerCase(),t[4]=n,t[5]=v);let y=v===`skill`,b;t[6]===y?b=t[7]:(b={enabled:y},t[6]=y,t[7]=b);let x=Oo(b),S;t[8]===x.data?S=t[9]:(S=x.data??[],t[8]=x.data,t[9]=S);let C=S,w;t[10]===C?w=t[11]:(w=new Map(C.map(yI)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||Yj(E.part),O;t[12]===E?O=t[13]:(O=E?sI(E):null,t[12]=E,t[13]=O);let k=O,A;if(t[14]!==k||t[15]!==E||t[16]!==T||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!E||!k){A=null;break bb0}let e=T.get(k)?.path||eI(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=oI(e);if(!r){A=null;break bb0}let i;t[19]!==k||t[20]!==r?(i={name:k,path:r},t[19]=k,t[20]=r,t[21]=i):i=t[21],A=i}t[14]=k,t[15]=E,t[16]=T,t[17]=n,t[18]=A}else A=t[18];let j=A,M;if(t[22]!==_||t[23]!==f||t[24]!==E){bb1:{if(!f||!E){M=null;break bb1}let e=$F(E);if(!e){M=null;break bb1}let n=kn(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=iI(E),t[26]=E,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],M=i}t[22]=_,t[23]=f,t[24]=E,t[25]=M}else M=t[25];let N=M,P;t[32]!==_||t[33]!==m||t[34]!==p?(P=(e,t)=>{if(!_)return;let n=An(_,e);if(!n)return;if(m){m.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(p?.editor){p.editor.openFile(n,t);return}if(!On(n,_)){XO(n,_).then(()=>{let e=K.getState(),r=_||jn(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=K.getState(),i=jn(_,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=_,t[33]=m,t[34]=p,t[35]=P):P=t[35];let F=J(P),I;t[36]!==_||t[37]!==m?(I=e=>{let t=Dn(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=K.getState(),n=_||jn(``,t);e.openContextFile(n,t)};if(_&&!On(t,_)){XO(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let te=J(ee),ne;t[48]===te?ne=t[49]:(ne=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),te())},t[48]=te,t[49]=ne);let re=J(ne),G=U&&W&&`cursor-pointer`,ie=U&&!W&&`cursor-default opacity-70`,ae;t[50]!==G||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,iy,G,ie),t[50]=G,t[51]=ie,t[52]=ae):ae=t[52];let oe=U?`soft`:void 0,se=U?te:void 0,ce=U?re:void 0,le=U?`button`:void 0,ue=U&&W?0:void 0,de=U&&!W?!0:void 0,fe=i?`size-4`:`size-3.5`,pe;t[53]===fe?pe=t[54]:(pe=Y(`inline-flex items-center justify-center flex-shrink-0`,fe),t[53]=fe,t[54]=pe);let me;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(me={color:`var(--tools-icon)`},t[55]=me):me=t[55];let he=D?(0,$.jsx)(Mj,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,ge;t[56]!==pe||t[57]!==me||t[58]!==he?(ge=(0,$.jsx)(`div`,{className:pe,style:me,children:he}),t[56]=pe,t[57]=me,t[58]=he,t[59]=ge):ge=t[59];let _e,ve;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(_e=Y(WF,`inline-flex items-center flex-shrink-0 opacity-85`),ve={color:`var(--tools-title)`},t[60]=_e,t[61]=ve):(_e=t[60],ve=t[61]);let ye;t[62]===c?ye=t[63]:(ye=(0,$.jsx)(`span`,{className:_e,style:ve,title:c,children:c}),t[62]=c,t[63]=ye);let be;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(be=f&&N?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,GF),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(Zh,{filePath:N.path,className:`h-3.5 w-3.5`}):null,aI(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=be):be=t[68];let xe;t[69]!==a||t[70]!==k||t[71]!==B?(xe=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(uk,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,GF),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=xe):xe=t[72];let Se;t[73]!==k||t[74]!==V?(Se=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:bI,className:Y(`min-w-0 flex-1 inline-flex items-center gap-1.5 underline decoration-[color:var(--status-info)] underline-offset-2 hover:opacity-90`,`truncate whitespace-nowrap`,GF),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(XF,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=Se):Se=t[75];let Ce;t[76]!==H||t[77]!==j?(Ce=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,GF),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=Ce):Ce=t[78];let we;t[79]!==k||t[80]!==H||t[81]!==j?(we=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,GF),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=we):we=t[82];let Te;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Te=!f&&!B&&!V&&!H&&k?(0,$.jsx)(uk,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,GF),style:{color:`var(--tools-description)`},children:k}):null,t[83]=a,t[84]=k,t[85]=V,t[86]=f,t[87]=B,t[88]=H,t[89]=Te):Te=t[89];let Ee;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==le||t[95]!==ue||t[96]!==de||t[97]!==ge||t[98]!==ye||t[99]!==be||t[100]!==xe||t[101]!==Se||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:le,tabIndex:ue,"aria-disabled":de,children:[ge,ye,be,xe,Se,Ce,we,Te]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=le,t[95]=ue,t[96]=de,t[97]=ge,t[98]=ye,t[99]=be,t[100]=xe,t[101]=Se,t[102]=Ce,t[103]=we,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&fI(e.activities,t.activities)),mI=Z.memo(e=>{let t=(0,Q.c)(5),{activity:n,onContentChange:r,streamPhase:i}=e,a;return t[0]!==n.messageId||t[1]!==n.part||t[2]!==r||t[3]!==i?(a=(0,$.jsx)(NN,{part:n.part,messageId:n.messageId,streamPhase:i,onContentChange:r}),t[0]=n.messageId,t[1]=n.part,t[2]=r,t[3]=i,t[4]=a):a=t[4],a}),hI=Z.memo(e=>{let t=(0,Q.c)(7),{activity:n,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}=e,s;return t[0]!==a||t[1]!==n.messageId||t[2]!==n.part||t[3]!==r||t[4]!==i||t[5]!==o?(s=(0,$.jsx)(BF,{part:n.part,messageId:n.messageId,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}),t[0]=a,t[1]=n.messageId,t[2]=n.part,t[3]=r,t[4]=i,t[5]=o,t[6]=s):s=t[6],s}),gI=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=Xn(),_=Cd()??``,v=Z.useMemo(()=>JF(t),[t]),y=Z.useRef(new Set),b=Z.useRef(new Map),x=Z.useRef(new Set),[,S]=Z.useState(0),C=Z.useRef(null),w=Z.useRef(null),T=i===`active`,E=!T&&(i===`normal`||i===`abnormal`)&&typeof o==`number`&&Number.isFinite(o)&&o>=0?HF(o):null,D=i===`normal`||i===`abnormal`,O=a===`compaction`,k=D&&!O,A=O?`fold-vertical`:`stack`,j=g(i===void 0?`chat.activity.title`:T?O?`chat.activity.compacting`:`chat.activity.active`:D?O?`chat.activity.compactionCompleted`:`chat.activity.completedStatus`:`chat.activity.title`),M=Z.useMemo(()=>{let t=[];for(let n of e)n.kind===`tool`&&t.push(n.part);return yj(t)},[e]),N=M.added>0||M.removed>0,P=Z.useMemo(()=>cI(e),[e]),F=T?P.active:P.all,I=F.slice(0,c?2:3),L=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=ft(_,i,r);if(a.status===`ready`||n&&a.status===`error`||e&&a.status!==`error`&&!x.current.has(r)||(y.current.add(r),x.current.delete(r),b.current.has(r)))continue;let o=le(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),R=J(e=>{e.stopPropagation(),L(!0)}),z=T,B=z||n,V=J(()=>{if(z)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,B||L(),s()});Z.useEffect(()=>{T||!B||L(!1,!0)},[T,B]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[B]);let H=m&&!B?Math.max(0,Math.floor(r)):0,U=!m||B||H>0,W=y.current,ee=[...W].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return ft(_,n,e).status}),te=ee.includes(`loading`),ne=ee.includes(`error`),re=ee.length>0&&ee.every(e=>e===`ready`),G=t.some(e=>W.has(e.messageId)&&qF(e)),ie=re&&!G&&!YF(t,W),ae=Z.useMemo(()=>U?ZF(e):KF,[e,U]),oe=Z.useMemo(()=>U?dI(ae.filter(e=>e.kind!==`reasoning`||PD(e.part).trim().length>0)):[],[U,ae]),se=Z.useMemo(()=>B||H===0?0:Math.max(0,oe.length-H),[B,H,oe.length]),ce=Z.useMemo(()=>B||H===0?oe:oe.slice(-H),[B,H,oe]),ue=!!m&&!(T&&!O);if((!ue||z&&!O)&&oe.length===0)return null;let de=(e,t)=>{let n=(0,$.jsx)(`div`,{className:ty(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},fe=U?ce.map((e,t)=>{switch(e.type){case`reasoning`:return de(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(mI,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return de(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(hI,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(lI,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);case`tool-static-group`:return(0,$.jsx)(uI,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(NF,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return Wj(n)?(0,$.jsx)(pI,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(iN,{part:t,messageId:e.messageId,isExpanded:l.has(e.id),onToggle:u,isMobile:c,onContentChange:f,onShowPopup:d,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(zF,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(pI,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(lI,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,pe=ce.length>0;return(0,$.jsxs)(`div`,{className:ue?ty(c):`flow-root`,children:[ue?(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-[calc(100%+1rem)] min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!z&&iy,z&&`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":z?void 0:`soft`,onClick:z?void 0:V,"aria-expanded":B,"aria-disabled":z||void 0,"aria-label":z?j:g(B?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex min-w-0 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:k?(0,$.jsxs)(`span`,{className:Y(`typography-meta inline-flex shrink-0 items-center gap-1.5 tabular-nums text-muted-foreground`,c?`h-5`:`h-6`),children:[E?g(`chat.activity.completed`,{duration:E}):j,(0,$.jsx)(X,{name:B?`arrow-down-s`:`arrow-right-s`,className:`size-3.5 shrink-0 opacity-0 group-hover/tool:opacity-70 group-focus-visible/tool:opacity-70`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(Mj,{isMobile:c,label:j,className:`block`}):(0,$.jsx)(X,{name:A,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--yuri-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:j}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]})}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center`,c?`gap-0.5`:`gap-1`),children:[F.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:I.map((e,t)=>(0,$.jsx)(gs,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:F.length})})]}):null,N?(0,$.jsx)(`span`,{"data-activity-diff-totals":``,className:`inline-flex shrink-0`,children:(0,$.jsx)(MF,{added:M.added,removed:M.removed})}):null,!z&&!k?(0,$.jsx)(X,{name:B?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)}):null]})]}):null,pe?(0,$.jsxs)(`div`,{className:z?void 0:`relative ml-2 pl-3`,children:[z?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),se>0?(0,$.jsxs)(`button`,{type:`button`,onClick:V,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,se,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:fe})]}):null,B&&(te||ne||ie)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,z?void 0:`ml-5`,ne&&`text-[var(--status-error)]`),role:ne?`alert`:`status`,children:te?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):ne?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:R,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]})});function _I(e){return e.showToolFileIcons}function vI(e){return e.currentDirectory}function yI(e){return[e.name,e]}function bI(e){e.stopPropagation()}var xI=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(gI,{...e}),t[0]=e,t[1]=n),n});function SI(e){let t=(0,Q.c)(9),{presentation:n,sessionId:r,messageId:i,directory:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={bootstrap:!1},t[0]=o):o=t[0];let s=To(a,o),c;t[1]===r?c=t[2]:(c=e=>!!e.session_execution_recovery[r],t[1]=r,t[2]=c);let l=z(s,c),u;t[3]===r?u=t[4]:(u=e=>e.session_status[r]?.type===`retry`,t[3]=r,t[4]=u);let d=z(s,u),f=Aa(r,a);if(!l&&!d){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Iv,{presentation:n}),t[5]=n,t[6]=e),e}let p;for(let e=f.length-1;e>=0;--e)if(f[e].role===`assistant`){p=f[e].id;break}if(p===i&&(d||l&&n.detail===`aborted`&&n.icon===`pause-circle`))return null;let m;return t[7]===n?m=t[8]:(m=(0,$.jsx)(Iv,{presentation:n}),t[7]=n,t[8]=m),m}function CI(e){let t=(0,Q.c)(5),n=wb();if(!e.sessionId||!n.active||!n.capabilities.compose){let n;return t[0]===e.presentation?n=t[1]:(n=(0,$.jsx)(Iv,{presentation:e.presentation}),t[0]=e.presentation,t[1]=n),n}let r=n.directory??e.directory,i;return t[2]!==e||t[3]!==r?(i=(0,$.jsx)(SI,{...e,sessionId:e.sessionId,directory:r}),t[2]=e,t[3]=r,t[4]=i):i=t[4],i}var wI={contain:`layout`},TI={containerType:`inline-size`,containerName:`message-footer`},EI=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,DI=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,OI=`size-6! p-0 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50`,kI=`size-3.5!`,AI=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,jI=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,MI=`flex items-center gap-2`,NI=`flex w-max max-w-full flex-none flex-wrap items-center gap-2 text-muted-foreground`,PI=`h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,FI=`inline-flex ${PI}`,II=`size-3.5!`,LI=`medium`,RI=e=>{let t=(0,Q.c)(6),{messageId:n,label:r,focusReveal:i}=e,a=nF(n,i),o=i?a?`inline-flex`:`hidden`:`hidden yuri-message-hover-time`,s;t[0]===o?s=t[1]:(s=Y(PI,`whitespace-nowrap`,o),t[0]=o,t[1]=s);let c=i?a?`true`:`false`:void 0,l;return t[2]!==r||t[3]!==s||t[4]!==c?(l=(0,$.jsx)(`span`,{className:s,"data-message-time":``,"data-message-time-visible":c,children:r}),t[2]=r,t[3]=s,t[4]=c,t[5]=l):l=t[5],l},zI=e=>{let t=(0,Q.c)(16),{label:n}=e,{t:r}=Xn(),i;t[0]!==n||t[1]!==r?(i=r(`chat.messageBody.meta.tpsAria`,{rate:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{weight:LI,name:`pulse`,className:II}),t[3]=a):a=t[3];let o;t[4]===n?o=t[5]:(o=(0,$.jsx)(`span`,{className:`message-footer__label`,children:n}),t[4]=n,t[5]=o);let s;t[6]!==i||t[7]!==o?(s=(0,$.jsx)($s,{asChild:!0,children:(0,$.jsxs)(`span`,{className:FI,"aria-label":i,children:[a,o]})}),t[6]=i,t[7]=o,t[8]=s):s=t[8];let c;t[9]===r?c=t[10]:(c=r(`chat.messageBody.meta.tpsTooltip`),t[9]=r,t[10]=c);let l;t[11]===c?l=t[12]:(l=(0,$.jsx)(ec,{children:c}),t[11]=c,t[12]=l);let u;return t[13]!==s||t[14]!==l?(u=(0,$.jsxs)(tc,{children:[s,l]}),t[13]=s,t[14]=l,t[15]=u):u=t[15],u},BI=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,VI=`w-full min-w-0 justify-start rounded-[var(--radius-md)] bg-transparent px-1 hover:!bg-interactive-hover focus-visible:!bg-interactive-hover active:!bg-interactive-active supports-[corner-shape:squircle]:rounded-[var(--radius-md)]`,HI=`h-7 gap-1.5`,UI=`h-6 gap-1`,WI=`text-[11px] leading-none`,GI=`size-3.5`,KI=`size-3`,qI=5,JI=Z.memo(e=>{let t=(0,Q.c)(30),{file:n,isMobile:r}=e,i=r?`gap-1 text-[11px]`:`gap-1.5 text-xs`,a;t[0]===i?a=t[1]:(a=Y(`flex min-w-0 flex-1 items-center leading-none text-muted-foreground`,i),t[0]=i,t[1]=a);let o=n.file,s=r?`h-3 w-3`:`h-3.5 w-3.5`,c;t[2]===s?c=t[3]:(c=Y(`flex-shrink-0`,s),t[2]=s,t[3]=c);let l;t[4]!==n.file||t[5]!==c?(l=(0,$.jsx)(Zh,{filePath:o,className:c}),t[4]=n.file,t[5]=c,t[6]=l):l=t[6];let u=n.file,d;t[7]===n.file?d=t[8]:(d=BI(n.file),t[7]=n.file,t[8]=d);let f;t[9]!==n.file||t[10]!==d?(f=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left text-foreground/80`,title:u,children:d}),t[9]=n.file,t[10]=d,t[11]=f):f=t[11];let p=r?`text-[11px]`:`typography-meta`,m;t[12]===p?m=t[13]:(m=Y(`inline-flex flex-shrink-0 items-center gap-0 leading-none tabular-nums`,p),t[12]=p,t[13]=m);let h;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(h={color:`var(--status-success)`},t[14]=h):h=t[14];let g;t[15]===n.additions?g=t[16]:(g=(0,$.jsxs)(`span`,{style:h,children:[`+`,n.additions]}),t[15]=n.additions,t[16]=g);let _,v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`/`}),v={color:`var(--status-error)`},t[17]=_,t[18]=v):(_=t[17],v=t[18]);let y;t[19]===n.deletions?y=t[20]:(y=(0,$.jsxs)(`span`,{style:v,children:[`-`,n.deletions]}),t[19]=n.deletions,t[20]=y);let b;t[21]!==m||t[22]!==g||t[23]!==y?(b=(0,$.jsxs)(`span`,{className:m,children:[g,_,y]}),t[21]=m,t[22]=g,t[23]=y,t[24]=b):b=t[24];let x;return t[25]!==b||t[26]!==a||t[27]!==l||t[28]!==f?(x=(0,$.jsxs)(`span`,{className:a,children:[l,f,b]}),t[25]=b,t[26]=a,t[27]=l,t[28]=f,t[29]=x):x=t[29],x}),YI=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=Xn(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?UI:HI,d;t[3]===u?d=t[4]:(d=Y(VI,u),t[3]=u,t[4]=d);let f;t[5]!==n.file||t[6]!==o?(f=o(`chat.changedFiles.actions.openFileTitle`,{path:n.file}),t[5]=n.file,t[6]=o,t[7]=f):f=t[7];let p;t[8]!==n||t[9]!==i?(p=(0,$.jsx)(JI,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),XI=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=Xn(),c=Cd(),l=wb(),u=l.directory||c,d=l.sessionId,f=Sl(),p=K(lL),m;t[0]===r?m=t[1]:(m=r??[],t[0]=r,t[1]=m);let h=m,g;t[2]===h?g=t[3]:(g=h.slice(0,qI),t[2]=h,t[3]=g);let _=g,v=Math.max(0,h.length-_.length),y=h.length>0?h.length:n,b=!!(f||!o&&u||o&&a),x;t[4]!==y||t[5]!==s?(x=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[4]=y,t[5]=s,t[6]=x):x=t[6];let S=x,C;t[7]!==v||t[8]!==s?(C=s(v===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:v}),t[7]=v,t[8]=s,t[9]=C):C=t[9];let w=C,T=Y(VI,o?UI:HI),E=o?KI:GI,D;t[10]===o?D=t[11]:(D=o?Y(WI,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=D);let O=D,k;t[12]===o?k=t[13]:(k=o?Y(WI,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=k);let A=k,j;t[14]===o?j=t[15]:(j=o?Y(WI,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=j);let M=j,N;t[16]!==u||t[17]!==d||t[18]!==a||t[19]!==o||t[20]!==f||t[21]!==i?(N=e=>{if(f){f.openTurnDiff(i,d,e);return}if(!o&&u){IN({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&IN({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[16]=u,t[17]=d,t[18]=a,t[19]=o,t[20]=f,t[21]=i,t[22]=N):N=t[22];let P=J(N),F;t[23]!==u||t[24]!==d||t[25]!==a||t[26]!==o||t[27]!==f||t[28]!==p||t[29]!==i||t[30]!==_[0]?.file?(F=()=>{if(f){f.openTurnDiff(i,d);return}if(!o&&u){p(u,{mode:`diff`,dedupeKey:`turn-diff:${d||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:d});return}let e=_[0]?.file;e&&o&&a&&u&&IN({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let te;t[46]!==S||t[47]!==A?(te=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=te):te=t[48];let ne;t[49]===E?ne=t[50]:(ne=Y(E,`opacity-60`),t[49]=E,t[50]=ne);let re;return t[51]===ne?re=t[52]:(re=(0,$.jsx)(X,{name:`arrow-right-s`,className:ne}),t[51]=ne,t[52]=re),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,te,re]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(YI,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),ZI=e=>e.type===`subtask`,QI=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},$I=e=>{if(!e||typeof e!=`object`)return null;let t=typeof e.providerID==`string`?e.providerID.trim():``,n=typeof e.modelID==`string`?e.modelID.trim():``;return!t||!n?null:`${t}/${n}`},eL=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=Cd(),{isMobile:o}=$c(),s=Da(uL),c=K(dL),l=wb(),{t:u}=Xn(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,p;t[2]===n.command?p=t[3]:(p=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=p);let m=p,h;t[4]===n.agent?h=t[5]:(h=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=h);let g=h,_;t[6]===n.prompt?_=t[7]:(_=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=_);let v=_,y;t[8]===n.taskSessionID?y=t[9]:(y=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=y);let x=y,S;t[10]===n.model?S=t[11]:(S=$I(n.model),t[10]=n.model,t[11]=S);let C=S,w=!!v&&!(o&&l.kind===`primary`),T;t[12]===u?T=t[13]:(T=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=T);let E;t[14]===T?E=t[15]:(E=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:T}),t[14]=T,t[15]=E);let D;t[16]===m?D=t[17]:(D=m?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,m]}):null,t[16]=m,t[17]=D);let O;t[18]===g?O=t[19]:(O=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,g]}):null,t[18]=g,t[19]=O);let k;t[20]===C?k=t[21]:(k=C?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:C}):null,t[20]=C,t[21]=k);let A;t[22]!==O||t[23]!==k||t[24]!==E||t[25]!==D?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E,D,O,k]}),t[22]=O,t[23]=k,t[24]=E,t[25]=D,t[26]=A):A=t[26];let j;t[27]===f?j=t[28]:(j=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=j);let M;t[29]!==r||t[30]!==v||t[31]!==w||t[32]!==u?(M=w?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(fL),children:u(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:v}):null]}):null,t[29]=r,t[30]=v,t[31]=w,t[32]=u,t[33]=M):M=t[33];let N;t[34]!==g||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==x?(N=x&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&Eb(l,x,e,()=>{if(!oa({sessionId:x,directory:e})){if(hl()||o||b()){s(x,e);return}c(e,{mode:`chat`,dedupeKey:`session:${x}`,label:f||g||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=g,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=x,t[43]=N):N=t[43];let P;return t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==N?(P=(0,$.jsxs)(`div`,{className:`mt-2`,children:[A,j,M,N]}),t[44]=A,t[45]=j,t[46]=M,t[47]=N,t[48]=P):P=t[48],P},tL=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=Cd(),i=K(pL),{isMobile:a}=$c(),{t:o}=Xn(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!b(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let c=!!s,l;t[3]!==n.state||t[4]!==o?(l=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=l):l=t[5];let u=l,d=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),f=n.description||d,p=J(()=>{!c||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:f,readOnly:!0})}),m;t[6]===p?m=t[7]:(m=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())},t[6]=p,t[7]=m);let h=J(m),g=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,_;t[8]===g?_=t[9]:(_=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,g),t[8]=g,t[9]=_);let v=c?`button`:void 0,y=c?0:void 0,x=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,S=c?p:void 0,C=c?h:void 0,w;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=w):w=t[10];let T;t[11]===f?T=t[12]:(T=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=T);let E=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,D;t[13]===E?D=t[14]:(D=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,E),t[13]=E,t[14]=D);let O;t[15]!==u||t[16]!==D?(O=(0,$.jsx)(`span`,{className:D,children:u}),t[15]=u,t[16]=D,t[17]=O):O=t[17];let k;t[18]!==T||t[19]!==O?(k=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[T,O]}),t[18]=T,t[19]=O,t[20]=k):k=t[20];let A;t[21]===n.body?A=t[22]:(A=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-clip text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Ju,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=A);let j;t[23]!==k||t[24]!==A?(j=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[k,A]}),t[23]=k,t[24]=A,t[25]=j):j=t[25];let M;return t[26]!==C||t[27]!==j||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==x||t[32]!==S?(M=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":x,onClick:S,onKeyDown:C,children:[w,j]}),t[26]=C,t[27]=j,t[28]=_,t[29]=v,t[30]=y,t[31]=x,t[32]=S,t[33]=M):M=t[33],M},nL={background:`transparent`,backgroundColor:`transparent`},rL=e=>{let t=(0,Q.c)(37),{part:n}=e,[r,i]=Z.useState(!1),a=Z.useRef(null),{t:o}=Xn(),s;t[0]===n.shellAction?s=t[1]:(s=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=s);let c=s,l=typeof n.shellAction?.output==`string`?n.shellAction.output:``,u;t[2]===n.shellAction?u=t[3]:(u=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=u);let d=u,f=l.length>0,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{a.current!==null&&typeof window<`u`&&(window.clearTimeout(a.current),a.current=null)},t[4]=p):p=t[4];let m=J(p),h,g;t[5]===m?(h=t[6],g=t[7]):(h=()=>()=>{m()},g=[m],t[5]=m,t[6]=h,t[7]=g),Z.useEffect(h,g);let _;t[8]!==m||t[9]!==f||t[10]!==l?(_=async()=>{f&&(await Yn(l)).ok&&(m(),i(!0),typeof window<`u`&&(a.current=window.setTimeout(()=>{i(!1),a.current=null},2e3)))},t[8]=m,t[9]=f,t[10]=l,t[11]=_):_=t[11];let v=J(_),y;t[12]===o?y=t[13]:(y=o(`chat.messageBody.shellCommand.title`),t[12]=o,t[13]=y);let b;t[14]===y?b=t[15]:(b=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:y}),t[14]=y,t[15]=b);let x;t[16]!==d||t[17]!==o?(x=d&&d!==`completed`?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,d===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),role:d===`error`?`alert`:`status`,children:d===`running`?o(`chat.assistantStatus.runningCommand`):d===`pending`?o(`chat.statusRow.todo.status.pending`):d===`error`?o(`chat.toolPart.error`):d}):null,t[16]=d,t[17]=o,t[18]=x):x=t[18];let S;t[19]!==r||t[20]!==v||t[21]!==f||t[22]!==o?(S=f?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,className:`ml-auto text-muted-foreground`,onClick:()=>{v()},"aria-label":o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:(0,$.jsx)(X,{name:r?`check`:`file-copy`,className:`h-3.5 w-3.5`})}):null,t[19]=r,t[20]=v,t[21]=f,t[22]=o,t[23]=S):S=t[23];let C;t[24]!==S||t[25]!==b||t[26]!==x?(C=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[b,x,S]}),t[24]=S,t[25]=b,t[26]=x,t[27]=C):C=t[27];let w;t[28]===c?w=t[29]:(w=c?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(zd,{language:`bash`,code:c,codeStyle:nL,wrap:!0})}):null,t[28]=c,t[29]=w);let T;t[30]!==f||t[31]!==l?(T=f?(0,$.jsx)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:(0,$.jsx)(`pre`,{className:`typography-meta max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-foreground/85`,tabIndex:0,children:l})}):null,t[30]=f,t[31]=l,t[32]=T):T=t[32];let E;return t[33]!==C||t[34]!==w||t[35]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-3 py-2`,children:[C,w,T]}),t[33]=C,t[34]=w,t[35]=T,t[36]=E):E=t[36],E},iL=e=>{let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.round(t),r=Math.floor(n/86400),i=Math.floor(n%86400/3600),a=Math.floor(n%3600/60),o=n%60;return[r>0?`${r}d`:``,i>0?`${i}h`:``,a>0?`${a}m`:``,o>0?`${o}s`:``].filter(Boolean).join(` `)},aL=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=Xn(),w=Ox(),T=Tb(wb()),E=K(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!ID(e):!!(ZI(e)||QI(e))),[n]),j=Z.useMemo(()=>A.map(e=>ra(e)?Vk(PD(e)):void 0),[A]),M=f?.token,N=!1,P=!!l,F=!!u,I=!!(s??a),L=!!c,R=b!==`external-actions`,z=b!==`external-content`,B=x&&b===`inline`,V=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),H=J(()=>{!I||!P||!L||typeof window>`u`||(V(),O(!0),k.current=window.setTimeout(()=>{O(!1),k.current=null},1800))});Z.useEffect(()=>{L||(O(!1),V())},[V,L]);let U=J(e=>{!l||!L||(e.stopPropagation(),e.preventDefault(),l(),I&&H())}),W=w===`mini-chat`||!T.fork?void 0:h,ee=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=KP(i,E);return e.length>0?e:null},[S,i,E]),te=Y(`yuri-user-actions-hover-scope`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),ne=!_&&v&&z?(0,$.jsx)(`div`,{className:te,...HO,children:(0,$.jsxs)(`div`,{className:Y(MI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(FI,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:LI,name:`edit`,className:II}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:LI,name:`close`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,re=(_&&z?(0,$.jsx)(`div`,{className:te,...HO,children:(0,$.jsx)(`div`,{className:Y(MI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(FI,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??ne??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:te,...HO,children:(0,$.jsxs)(`div`,{className:Y(MI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 yuri-message-hover-actions`),"data-message-action-group":`true`,children:[ee?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(FI,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:LI,name:`time`,className:II}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(ec,{children:ee})]}):null,m&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:LI,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(kI,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:LI,name:`edit`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:LI,name:g===`fork`?`loader-4`:`git-branch`,className:Y(kI,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:OI,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:LI,name:`check`,className:Y(kI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:LI,name:`file-copy`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full yuri-message-hover-scope`,...HO,"data-user-message-body":`true`,style:wI,onTouchStart:I&&P&&L?H:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,B?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:B?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:A.map((e,i)=>{if(ZI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(eL,{part:e})},e.id??`user-subtask-${i}`);if(QI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(rL,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(tL,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&PD(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ak,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Cg,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),re]}):(0,$.jsx)($.Fragment,{children:re})}),oL=Z.memo(({messageId:e,hasCopyableText:t,isTouchContext:n,onCopyMessage:r,reviewTransferAction:i,ttsText:a,sessionId:o})=>{let{t:s}=Xn(),c=Ox(),l=wb(),u=Tb(l),{isPlaying:d,play:f,stop:p,canResume:m}=uP(),h=Z.useContext(fP),g=!!(h&&h.sessionId===o&&h.messageId===e),_=d||g,v=ni(e=>e.showMessageTTSButtons),y=ni(e=>e.voiceProvider),[b,x]=Z.useState(!1),[S,C]=Z.useState(!1),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),O=Z.useRef(null),k=Z.useRef(null),A=Z.useRef(null),j=!!r,M=!!((l.sessionId||o)&&l.directory&&u.openSourceSession&&c!==`mini-chat`),N=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),P=J(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)});Z.useEffect(()=>()=>{N(),P()},[P,N]),Z.useEffect(()=>{(!t||!j)&&(x(!1),C(!1),N(),P())},[j,P,N,t]);let F=J(()=>{!n||!j||!t||typeof window>`u`||(N(),x(!0),k.current=window.setTimeout(()=>{x(!1),k.current=null},1800))}),I=J(async e=>{!r||!t||(e.stopPropagation(),e.preventDefault(),await r()!==!1&&(P(),C(!0),typeof window<`u`&&(A.current=window.setTimeout(()=>{C(!1),A.current=null},2e3)),n&&F()))}),L=J(async e=>{if(e.stopPropagation(),e.preventDefault(),!(!i||w||!t)){T(!0);try{await i.onClick()}finally{T(!1)}}}),R=J(e=>{e.stopPropagation(),e.preventDefault();let t=l.sessionId||o;!t||!l.directory||!l.openSourceSession||l.openSourceSession(t,l.directory)}),z=Z.useMemo(()=>_?s(`chat.messageBody.tts.stopSpeaking`):s(`chat.messageBody.tts.readAloudWithProvider`,{provider:y===`browser`?`Browser`:y===`openai`?`OpenAI`:y===`openai-compatible`?`Custom`:`Say`}),[_,s,y]),B=J((e=!1)=>{if(D(!1),!a.trim())return;let t=O.current?.closest(`[data-message-text-export-root]`)??void 0;f(a,e=>{e&&zn.error(s(`chat.messageBody.tts.failed`))},{target:t,restart:e})}),V=J((e,t)=>{if(!e){D(!1);return}if(_){t.cancel(),g&&h?.stop(),p();return}let n=O.current?.closest(`[data-message-text-export-root]`)??void 0;if(m(a,n)){D(!0);return}t.cancel(),B()});return(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":b||S?`true`:void 0,className:Y(OI,!t&&`opacity-50`),disabled:!t,"aria-label":s(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!t,onPointerDown:e=>e.stopPropagation(),onClick:e=>{I(e)},onFocus:()=>{t&&x(!0)},onBlur:()=>{S||x(!1)},children:S?(0,$.jsx)(X,{weight:LI,name:`check`,className:Y(kI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:LI,name:`file-copy`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:s(`chat.messageBody.actions.copyAnswer`)})]}),M?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":s(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:R,children:(0,$.jsx)(X,{weight:LI,name:`target`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:s(`chat.messageBody.actions.openSourceSession`)})]}):null,i&&c!==`mini-chat`&&u.reviewTransfer?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,disabled:w||!t,className:Y(OI,(!t||w)&&`opacity-50`),"aria-label":i.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{L(e)},children:w?(0,$.jsx)(X,{weight:LI,name:`loader-4`,className:Y(kI,`animate-spin`)}):(0,$.jsx)(X,{weight:LI,name:`arrow-left-right`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:i.tooltip})]}):null,c!==`mini-chat`&&v&&t&&a.trim()&&(0,$.jsxs)(qc,{open:E&&!_,onOpenChange:V,modal:!1,children:[(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(Yc,{asChild:!0,children:(0,$.jsx)(er,{ref:O,type:`button`,variant:`ghost`,size:`icon`,className:Y(OI,`!bg-transparent shadow-none`,_?`text-[var(--primary-base)]`:`hover:text-foreground/80`),"aria-label":s(_?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),"aria-pressed":_,onPointerDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Um,{kind:`speaker`,active:_,className:kI})})})}),(0,$.jsx)(ec,{sideOffset:6,children:z})]}),(0,$.jsxs)(Ic,{side:`top`,align:`start`,sideOffset:6,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(kc,{className:n?`min-h-11 px-3`:void 0,onSelect:()=>B(!1),children:[(0,$.jsx)(X,{name:`play`,weight:LI,className:`size-4`}),s(`chat.messageBody.tts.resume`)]}),(0,$.jsxs)(kc,{className:n?`min-h-11 px-3`:void 0,onSelect:()=>B(!0),children:[(0,$.jsx)(X,{name:`restart`,weight:LI,className:`size-4`}),s(`chat.messageBody.tts.restart`)]})]})]})]})}),sL=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,isMobile:c,alwaysShowActions:l,hasTouchInput:u,expandedTools:d,onToggleTool:f,onShowPopup:p,streamPhase:m,allowAnimation:h,onContentChange:g,hasTextContent:_=!1,onCopyMessage:v,onAuxiliaryContentComplete:y,showReasoningTraces:x=!1,shouldShowHeader:S=!1,turnGroupingContext:C,errorPresentation:w,reviewTransferDirection:T=null})=>{let E=w?.text,{t:D}=Xn(),O=Ox(),k=wb(),A=Tb(k),j=m,M=Z.useRef(null),N=Z.useRef(null),P=m===`streaming`||m===`cooldown`,F=Z.useRef({messageId:t,experiencedStreamingOrCooldown:P});F.current.messageId===t?P&&(F.current.experiencedStreamingOrCooldown=!0):F.current={messageId:t,experiencedStreamingOrCooldown:P};let I=!!(u??c),L=!!(l??c),R=c?jI:AI,z=!i,B=Z.useMemo(()=>n.filter(e=>!ID(e)).filter(e=>e.type!==`reasoning`||x&&PD(e).trim().length>0).filter(e=>e.type!==`compaction`),[n,x]),V=Z.useMemo(()=>B.filter(e=>e.type===`tool`),[B]),H=Z.useMemo(()=>B.filter(e=>e.type===`text`),[B]),U=Z.useMemo(()=>ua(H),[H]),W=K(e=>e.openContextPreview),ee=b(),te=O===`mini-chat`,ne=Z.useMemo(()=>{if(ee||c||te)return null;for(let e of H){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=_d(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of V){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=_d(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[H,c,te,ee,V]),re=Da(e=>e.forkFromMessage),G=Da(e=>e.forkTransition),ie=Da(e=>e.currentSessionId),ae=Da(e=>e.getDirectoryForSession),oe=Cd(),se=T===`review-to-original`,ce=!c&&!ee?T:null,le=Z.useMemo(()=>{let t=U.trim();if(!(!e||!oe||!t||!ce))return ce===`review-to-original`?{ariaLabel:D(`chat.messageBody.actions.sendReviewFeedback`),tooltip:D(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await ca(e,oe,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:D(`chat.messageBody.actions.sendImplementationResponse`),tooltip:D(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await Ha(e,oe,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[U,oe,ce,e,D]),[ue,de]=Z.useState(!1),fe=K(e=>e.chatRenderMode),pe=C?fe:`live`,me=K(e=>e.collapsibleThinkingBlocks),he=K(e=>e.showSplitAssistantMessageActions),ge=K(e=>e.showAssistantTps),_e=pe===`sorted`,ve=C?.isLastAssistantInTurn??!1,ye=a===`stop`,be=(ye||i||!!E)&&(C?.isTurnSettled??!0),xe=ye?`completed`:j,Se=V.length>0,Ce=Z.useMemo(()=>V.some(e=>Yj(e)),[V]),we=Yj,Te=Jj,Ee=F.current.experiencedStreamingOrCooldown,De=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(De.current.messageId!==t&&(De.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Ee||!Ca())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of V){if(n.observedPartIds.has(i.id))continue;if(!Fo(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),xi({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Ee,we,t,e,V]);let Oe=Z.useMemo(()=>V.length===0||!Ce&&V.every(e=>Te(e)),[V,Ce,Te]),ke=Z.useMemo(()=>B.filter(e=>e.type===`reasoning`),[B]),Ae=Z.useMemo(()=>ke.length===0||ke.every(e=>typeof e.time?.end==`number`),[ke]),je=typeof a!=`string`,Me=ke.length>0&&Se&&(Ce||je||!Oe),Ne=z||Se&&(Ce||je||!Oe),Pe=z||Me,Fe=Se||ke.length>0,Ie=H.length===0,Le=Fe&&Ie&&!Ne&&!Pe&&Oe&&Ae,Re=Z.useRef(!1),ze=Z.useRef(!1);Z.useEffect(()=>{ze.current=!1},[t]),Z.useEffect(()=>{if(!Le){Re.current=!1;return}Re.current||(Re.current=!0,y?.())},[Le,y]),Z.useEffect(()=>{if(z){ze.current=!1;return}if(Se){ze.current=!1;return}ke.length!==0&&(Pe||!Ae||ze.current||(ze.current=!0,g?.(`structural`)))},[z,Se,g,Ae,ke.length,Pe]);let Be=!!_&&!z,Ve=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ue||G)){de(!0);try{await re(e,t)}finally{de(!1)}}}),He=Z.useMemo(()=>{let e=C?.activityParts;return!_e||!e?[]:e},[_e,C?.activityParts]),Ue=Z.useMemo(()=>{let e=C?.activityGroupSegments;return!_e||!e?[]:e.filter(e=>e.anchorMessageId===t)},[_e,t,C?.activityGroupSegments]),We=Ue.length>0,Ge=Z.useMemo(()=>{let e=new Map,t=new Map;return He.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[He]),Ke=C?.toggleGroup,qe=C?.activityPresentationKind===`compaction`,Je=C?.isGroupExpanded===!0,Ye=_e&&qe&&!Je,Xe=_e?C?.activityOwnerMessageId===t||We:!C?.activityOwnerMessageId||C.activityOwnerMessageId===t||We,Ze=_e&&Xe&&(We||qe)&&!!Ke,Qe=UN(a,B),$e={finish:a,parts:B,streamPhase:xe,error:E,isLastAssistantInTurn:ve},et=JN($e),tt=ni(e=>e.ttsInputMode),nt=Z.useMemo(()=>{if(!ve||qe||!be||!et)return``;let e=r??n,t=GN(e);return t<0?``:PD(e[t])},[ve,qe,be,et,r,n]),rt=tt===`final`?nt:U;pP({sessionId:e??``,messageId:t,created:s??0,text:rt,targetRef:M,streaming:c&&k.active&&(j===`streaming`||j===`cooldown`),completed:c&&k.active&&i&&j!==`streaming`&&j!==`cooldown`&&!E});let it=_e&&YN($e),at=_e&&!et&&!(qe&&Je),ot=Be,st=ve&&be&&w?.variant!==`error`&&!Ye&&(_||!!E||i),ct=C?.diffStats?.hasDiffs===!0,lt=C?.isLatestTurn&&e&&k.active&&!te,ut=!te&&ve&&Qe&&be&&!Ye&&C?.diffStats?.hasDiffs===!0,dt=he&&ot&&!st&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(oL,{messageId:t,hasCopyableText:Be,isTouchContext:I,onCopyMessage:v,ttsText:rt,reviewTransferAction:le,sessionId:e}),[rt,Be,I,v,le,e,t]),pt=Z.useMemo(()=>e=>{if(!he||!_e)return null;let t=PD(e.part).trim();return t?(0,$.jsx)(oL,{hasCopyableText:!0,isTouchContext:I,onCopyMessage:async()=>(await Yn(t)).ok,ttsText:tt===`final`?``:t}):null},[_e,I,he,tt]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<B.length;t+=1){let n=B[t];!n||n.type!==`text`||at||Ge.get(n)?.kind!==`justification`&&(e=t)}return e},[Ge,at,dt,B]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Ze&&Ke&&C){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(xI,{parts:t,materializationParts:r,isExpanded:C.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:C.completionDisposition,activityPresentationKind:C.activityPresentationKind,durationMs:C.durationMs,startedAt:C.userMessageCreatedAt,onToggle:Ke,isMobile:c,expandedTools:d,onToggleTool:f,onShowPopup:p,onContentChange:g,streamPhase:xe,showHeader:!0,diffStats:C.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};Ue.length>0?Ue.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):qe&&e(`${t}:compaction-status`,[])}let r=0;for(;r<B.length;){let i=B[r];if(i.type===`text`){let a=Ge.get(i);if(at){r+=1;continue}if(Ye){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:N,"data-message-text-export-source":`true`,children:(0,$.jsx)(xN,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,allowSortedFinalStreaming:it,hasStreamingHapticLifecycle:Ee,onContentChange:g,onShowPopup:p})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:c?DI:EI,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:MI,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(Ge.get(i)?.kind===`reasoning`){r+=1;continue}if(!PD(i).trim()){r+=1;continue}x&&(me?n.push((0,$.jsx)(`div`,{className:ty(c),children:(0,$.jsx)(NN,{part:i,messageId:t,streamPhase:xe,onContentChange:g})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(xN,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,hasStreamingHapticLifecycle:Ee,onContentChange:g,onShowPopup:p},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(_e&&!Xe){r+=1;continue}if(Ge.get(i)?.kind===`tool`){r+=1;continue}if(_e&&qj(a)){let e=AF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(NF,{activities:i,isMobile:c,isTurnLive:xe!==`completed`,hasFollowingOtherType:OF(B,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return Wj(n)?(0,$.jsx)(pI,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(iN,{part:e.part,messageId:t,isExpanded:d.has(e.part.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:g,onShowPopup:p,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(Gj(a)){let e=PF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(zF,{activities:i,isMobile:c,children:i.map(e=>(0,$.jsx)(pI,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(Vj(a)){n.push((0,$.jsx)(`div`,{className:ty(c),children:(0,$.jsx)(iN,{part:e,messageId:t,isExpanded:d.has(e.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:g,onShowPopup:p,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:ty(c),children:(0,$.jsx)(pI,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:c,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}let i=n.at(-1);if(Z.isValidElement(i)&&i.props[`data-message-text-export-source`]===`true`&&xe!==`completed`&&!be&&!w&&(!C||C.isLastAssistantInTurn)){let e=i;n[n.length-1]=Z.cloneElement(e,{className:Y(typeof e.props.className==`string`?e.props.className:void 0,c?`pb-1`:`pb-1.5`),"data-live-status-text-gap":``})}return n},[Ge,Ue,L,pe,me,0,d,Ye,qe,c,Xe,_e,mt,t,ft,pt,e,g,p,f,Ze,dt,xe,w,Ee,be,x,at,it,Ke,C,B]),_t=Z.useMemo(()=>{if(!ve||!be)return;let e=C?.durationMs;if(!(typeof e!=`number`||e<=0))return iL(e)},[ve,be,C?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=GP(e);return t.length>0?t:null},[o,s]),yt=Z.useMemo(()=>{if(!ge||!ve||w?.variant===`error`)return null;let e=C?.assistantTps;if(!dF({completionDisposition:C?.completionDisposition,tps:e}))return null;let t=fF(e??0);return t.length>0?t:null},[ge,w?.variant,ve,C?.assistantTps,C?.completionDisposition]),bt=(0,$.jsxs)($.Fragment,{children:[!te&&!c&&!ee&&ne?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:OI,"aria-label":D(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=oe??(ie?ae(ie):null);e&&W(e,ne)},children:(0,$.jsx)(X,{weight:LI,name:`global`,className:kI})})}),(0,$.jsx)(ec,{sideOffset:6,children:D(`chat.messageBody.actions.openPreview`)})]}):null,!te&&!se&&A.fork?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,className:OI,"aria-label":D(`chat.messageBody.actions.forkAria`),"aria-busy":ue,disabled:ue||!!G,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Ve(e)},children:(0,$.jsx)(X,{weight:LI,name:ue?`loader-4`:`git-branch`,className:Y(kI,ue&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:D(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:M,"data-message-text-export-root":`true`,"data-speech-identity":e?`${e}:${t}`:void 0,...HO,className:Y(`relative w-full yuri-message-hover-scope`),style:wI,children:[(0,$.jsx)(BP,{containerRef:M}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,(S||C?.headerMessageId===t)&&(c?`[&>[data-message-text-export-source]:first-child]:pt-1.5`:`[&>[data-message-text-export-source]:first-child]:pt-2`)),children:[gt,w&&(0,$.jsx)(Ad,{children:(0,$.jsx)(`div`,{className:`my-1.5`,"data-assistant-error":w.variant,children:(0,$.jsx)(CI,{presentation:w,sessionId:e,messageId:t,directory:oe??void 0})})},`assistant-error`)]}),ut&&C?.diffStats?(0,$.jsx)(XI,{fileCount:C.diffStats.files,changedFiles:C.changedFiles,turnId:C.turnId,isLatestTurn:C.isLatestTurn,isMobile:c}):null,(0,$.jsx)(Cg,{files:n,messageID:t,sessionID:e,onShowPopup:p}),ht&&(0,$.jsx)(`div`,{className:Y(c?DI:EI),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:MI,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:R,"data-message-footer":`true`,style:TI,children:[(0,$.jsxs)(`div`,{className:MI,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt||lt?(0,$.jsxs)(`div`,{className:NI,children:[yt||_t?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 whitespace-nowrap`,children:[yt?(0,$.jsx)(zI,{label:yt}):null,_t?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsxs)(`span`,{className:FI,children:[(0,$.jsx)(X,{weight:LI,name:`hourglass`,className:II}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(ec,{children:_t})]}):null]}):null,lt&&e?(0,$.jsx)(pF,{sessionId:e}):null,vt?(0,$.jsx)(RI,{messageId:t,label:vt,focusReveal:c}):null]}):null,!te&&ve&&ye&&!ct?(0,$.jsx)(LN,{activityParts:C?.activityParts}):null]}),!st&&!Ye&&yt?(0,$.jsx)(`div`,{className:R,"data-message-footer":`true`,"data-message-tps":`interrupted`,style:TI,children:(0,$.jsx)(`div`,{className:NI,children:(0,$.jsx)(zI,{label:yt})})}):null]})]})}),cL=Z.memo(e=>{let t=(0,Q.c)(28),n,r;if(t[0]===e?(n=t[1],r=t[2]):({isUser:n,...r}=e,t[0]=e,t[1]=n,t[2]=r),n){let e;return t[3]!==r.agentMention||t[4]!==r.alwaysShowActions||t[5]!==r.copiedMessage||t[6]!==r.editStaged||t[7]!==r.editing||t[8]!==r.hasTextContent||t[9]!==r.hasTouchInput||t[10]!==r.isMobile||t[11]!==r.messageCreatedAt||t[12]!==r.messageId||t[13]!==r.onCancelEdit||t[14]!==r.onCopyMessage||t[15]!==r.onEdit||t[16]!==r.onFork||t[17]!==r.onRevert||t[18]!==r.onShowPopup||t[19]!==r.parts||t[20]!==r.pendingMessageAction||t[21]!==r.sessionId||t[22]!==r.sourceParts||t[23]!==r.stickyUserHeaderEnabled||t[24]!==r.userActionsMode?(e=(0,$.jsx)(aL,{sessionId:r.sessionId,messageId:r.messageId,parts:r.parts,sourceParts:r.sourceParts,messageCreatedAt:r.messageCreatedAt,isMobile:r.isMobile,alwaysShowActions:r.alwaysShowActions,hasTouchInput:r.hasTouchInput,hasTextContent:r.hasTextContent,onCopyMessage:r.onCopyMessage,copiedMessage:r.copiedMessage,onShowPopup:r.onShowPopup,agentMention:r.agentMention,onEdit:r.onEdit,onRevert:r.onRevert,onFork:r.onFork,pendingMessageAction:r.pendingMessageAction,editing:r.editing,editStaged:r.editStaged,onCancelEdit:r.onCancelEdit,userActionsMode:r.userActionsMode,stickyUserHeaderEnabled:r.stickyUserHeaderEnabled}),t[3]=r.agentMention,t[4]=r.alwaysShowActions,t[5]=r.copiedMessage,t[6]=r.editStaged,t[7]=r.editing,t[8]=r.hasTextContent,t[9]=r.hasTouchInput,t[10]=r.isMobile,t[11]=r.messageCreatedAt,t[12]=r.messageId,t[13]=r.onCancelEdit,t[14]=r.onCopyMessage,t[15]=r.onEdit,t[16]=r.onFork,t[17]=r.onRevert,t[18]=r.onShowPopup,t[19]=r.parts,t[20]=r.pendingMessageAction,t[21]=r.sessionId,t[22]=r.sourceParts,t[23]=r.stickyUserHeaderEnabled,t[24]=r.userActionsMode,t[25]=e):e=t[25],e}let i;return t[26]===r?i=t[27]:(i=(0,$.jsx)(sL,{...r}),t[26]=r,t[27]=i),i});function lL(e){return e.openContextPanelTab}function uL(e){return e.setCurrentSession}function dL(e){return e.openContextPanelTab}function fL(e){return!e}function pL(e){return e.openContextPanelTab}var mL=e=>{let t=e,n=t?.clientRole,r=t?.role;return t?.userMessageMarker===!0||n===`user`||r===`user`||t?.origin===`user`||t?.source===`user`?{role:`user`,isUser:!0}:{role:n||r||`assistant`,isUser:!1}},hL=e=>{if(typeof e!=`string`)return!1;let t=e.toLowerCase().trim();if(!t)return!1;if(t.includes(`token refresh failed`)||t.includes(`unauthorized`)||t.includes(`invalid token`)||t.includes(`expired token`))return!0;let n=t.includes(`oauth`),r=t.includes(`failed`)||t.includes(`invalid`)||t.includes(`expired`);if(n&&r)return!0;let i=/\b401\b/.test(t),a=t.includes(`auth`)||t.includes(`token`)||t.includes(`unauthorized`);return i&&a},gL={"provider.rate-limit":`chat.response.rateLimit`,"provider.auth":`chat.response.auth`,"provider.quota":`chat.response.quota`,"provider.content-filter":`chat.response.contentFilter`,"provider.transport":`chat.response.transport`,"provider.internal":`chat.response.internal`,"provider.invalid-output":`chat.response.invalidOutput`,"provider.invalid-request":`chat.response.invalidRequest`,"provider.unsupported-operation":`chat.response.unsupportedOperation`,"provider.no-route":`chat.response.noRoute`,"provider.unknown":`chat.response.providerUnknown`,"provider.timeout":`chat.response.timeout`,"permission.rejected":`chat.response.permissionRejected`,"tool.execution":`chat.response.toolExecution`,"compaction.failed":`chat.response.compactionFailed`,"compaction.unavailable":`chat.response.compactionUnavailable`,"compaction.interrupted":`chat.response.compactionInterrupted`},_L={icon:`pause-circle`,variant:`muted`};function vL(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:typeof n.message==`string`?n.message:void 0,i=typeof n.name==`string`?n.name:void 0,a=typeof n.type==`string`?n.type.trim():void 0,o=typeof n.status==`number`&&Number.isInteger(n.status)&&n.status>=100&&n.status<=599?n.status:void 0;if(!r&&!a&&!i&&o===void 0)return;let s=[a&&a!==`unknown`&&a!==`error`?a:void 0,o].filter(e=>e!==void 0).join(` · `)||void 0,c=(e,n,i=`error`,a=!1)=>({text:t(e),icon:n,variant:i,...r&&!a?{rawMessage:r}:{},...s?{detail:s}:{}});if(i===`SessionRetry`)return c(`chat.response.retrying`,`refresh`,`info`);if(a===`aborted`)return r===`Execution was interrupted repeatedly and will not be resumed automatically.`?c(`chat.response.resumeExhausted`,`error-warning`,`error`,!0):r===`Session interrupted by user`?c(`chat.response.stopped`,`stop-circle`,`muted`,!0):r===`Compaction cancelled`?c(`chat.response.compactionCancelled`,`stop-circle`,`muted`,!0):r===`Tool execution interrupted`?c(`chat.response.toolInterrupted`,_L.icon,_L.variant,!0):c(`chat.response.interrupted`,_L.icon,_L.variant,r===`Step interrupted`);if(i===`MessageAbortedError`||!a&&r?.trim().toLowerCase()===`aborted`)return c(`chat.response.stopped`,`stop-circle`,`muted`,!0);if(a&&Object.hasOwn(gL,a)){if(a===`compaction.interrupted`)return c(gL[a],_L.icon,_L.variant,r===`Compaction was interrupted`);if(a===`compaction.unavailable`)return c(gL[a],`information`,`info`,r===`Nothing to compact yet`);let e=a===`provider.auth`||a===`permission.rejected`?`lock`:a===`provider.timeout`?`time`:`error-warning`;return c(gL[a],e)}return(!a||a===`unknown`||a===`error`)&&hL(r)?c(`chat.response.auth`,`lock`):{...c(`chat.response.failed`,`error-warning`),...!r&&i?{rawMessage:i}:{}}}function yL(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.nativeType===`synthetic`&&t.description===`Continuing after restart`}function bL(e,t){if(yL(e))return{text:t(`chat.response.continuingAfterRestart`),icon:`restart`,variant:`info`}}function xL(e){return!e}function SL(e){let t=(0,Q.c)(60),{part:n,isMobile:r}=e,i=r!==void 0&&r,{t:a}=Xn(),o;t[0]!==n.id||t[1]!==n.messageID||t[2]!==n.sessionID?(o=JSON.stringify([n.sessionID,n.messageID,n.id]),t[0]=n.id,t[1]=n.messageID,t[2]=n.sessionID,t[3]=o):o=t[3];let s=o,{expanded:c,toggle:l}=BO(s),u=(0,Z.useId)(),d;t[4]!==s||t[5]!==l?(d=()=>l(s),t[4]=s,t[5]=l,t[6]=d):d=t[6];let f=J(d),p=n.status===`running`,m=n.status===`failed`,h;t[7]!==m||t[8]!==p||t[9]!==a?(h=a(p?`chat.activity.compacting`:m?`chat.activity.compactionFailed`:`chat.activity.compactionCompleted`),t[7]=m,t[8]=p,t[9]=a,t[10]=h):h=t[10];let g=h,_;t[11]!==m||t[12]!==n.error||t[13]!==a?(_=m?vL(n.error,a):void 0,t[11]=m,t[12]=n.error,t[13]=a,t[14]=_):_=t[14];let v=_,y;t[15]!==m||t[16]!==n.summary?(y=m?``:n.summary?.trim()??``,t[15]=m,t[16]=n.summary,t[17]=y):y=t[17];let b=y,x,S,C,w,T,E,D,O,k;if(t[18]!==u||t[19]!==c||t[20]!==v?.text||t[21]!==m||t[22]!==i||t[23]!==p||t[24]!==n.status||t[25]!==b||t[26]!==g||t[27]!==f){let e=Y(`shrink-0 typography-meta`,m?`text-[var(--status-error)]/85`:`text-muted-foreground`);E=`w-full min-w-0`,D=``,O=n.status;let r=i?`min-h-7`:`min-h-8`;t[37]===r?k=t[38]:(k=Y(`flex w-full items-center gap-3`,r),t[37]=r,t[38]=k),x=`separator`,S=p?`polite`:void 0,C=v?.text??g,t[39]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 border-t`,"aria-hidden":`true`}),t[39]=w):w=t[39],T=b?(0,$.jsxs)(er,{variant:`ghost`,size:`sm`,className:Y(e,ry),"aria-expanded":c,"aria-controls":u,onClick:f,children:[g,(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`size-4 transition-transform`,c&&`rotate-180`)})]}):(0,$.jsx)(`span`,{className:e,children:g}),t[18]=u,t[19]=c,t[20]=v?.text,t[21]=m,t[22]=i,t[23]=p,t[24]=n.status,t[25]=b,t[26]=g,t[27]=f,t[28]=x,t[29]=S,t[30]=C,t[31]=w,t[32]=T,t[33]=E,t[34]=D,t[35]=O,t[36]=k}else x=t[28],S=t[29],C=t[30],w=t[31],T=t[32],E=t[33],D=t[34],O=t[35],k=t[36];let A;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 border-t`,"aria-hidden":`true`}),t[40]=A):A=t[40];let j;t[41]!==x||t[42]!==S||t[43]!==C||t[44]!==w||t[45]!==T||t[46]!==D||t[47]!==O||t[48]!==k?(j=(0,$.jsxs)(`div`,{"data-compaction-card":D,"data-compaction-status":O,className:k,role:x,"aria-live":S,"aria-label":C,children:[w,T,A]}),t[41]=x,t[42]=S,t[43]=C,t[44]=w,t[45]=T,t[46]=D,t[47]=O,t[48]=k,t[49]=j):j=t[49];let M;t[50]!==u||t[51]!==c||t[52]!==p||t[53]!==n.messageID||t[54]!==b?(M=b&&c?(0,$.jsx)(`div`,{id:u,className:`py-2`,children:(0,$.jsx)(Zu,{content:b,messageId:n.messageID,isStreaming:p})}):null,t[50]=u,t[51]=c,t[52]=p,t[53]=n.messageID,t[54]=b,t[55]=M):M=t[55];let N;return t[56]!==E||t[57]!==j||t[58]!==M?(N=(0,$.jsxs)(`div`,{className:E,children:[j,M]}),t[56]=E,t[57]=j,t[58]=M,t[59]=N):N=t[59],N}var CL=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},wL=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=typeof t.model==`object`&&t.model!==null?t.model:void 0,r=typeof t.metadata==`object`&&t.metadata!==null?t.metadata:void 0,i=typeof r?.model==`object`&&r.model!==null?r.model:void 0,a=CL(t.mode)??CL(t.agent)??CL(r?.agent),o=CL(t.providerID)??CL(n?.providerID)??CL(i?.providerID),s=CL(t.modelID)??CL(n?.modelID)??CL(n?.id)??CL(i?.modelID)??CL(i?.id),c=CL(n?.variant)??CL(i?.variant)??CL(t.variant)??CL(r?.variant);return!a&&!o&&!s&&!c?null:{agentName:a,providerId:o,modelId:s,variant:c}},TL=e=>{let t=e?.providerId?.trim(),n=e?.modelId?.trim();return!t||!n?null:{providerId:t,modelId:n}},EL=e=>TL(e.assistantIdentity)??TL(e.userIdentity)??(e.allowComposerFallback?TL(e.composerSelection):null)??TL(e.sessionSelection),DL=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:qr(void 0,t)||void 0,variant:e?.variant}},OL=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),kL=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,AL=e=>!e,jL=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},ML=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),NL=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,PL=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,FL=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},IL=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},LL=e=>!e||FL(e)!==`user`?!1:e.parts.some(e=>{if(e?.type!==`text`)return!1;let t=e.text;return e.synthetic===!0&&typeof t==`string`&&t.trim().startsWith(`The following tool was executed by the user`)}),RL=e=>FL(e)===`user`?LL(e)||e.parts.some(e=>{let t=e.shellAction;return e.type===`text`&&typeof t==`object`&&!!t}):!1,zL=(e,t)=>{if(FL(e)!==`assistant`||t&&IL(e)!==t||e.parts.length!==1)return{hide:!1,details:null};let n=e.parts[0];return n?.type!==`tool`||(typeof n.tool==`string`?n.tool.toLowerCase():``)!==`bash`?{hide:!1,details:null}:{hide:!0,details:{command:typeof n.state?.input?.command==`string`?n.state.input.command:void 0,output:(typeof n.state?.output==`string`?n.state.output:void 0)??(typeof n.state?.metadata?.output==`string`?n.state.metadata.output:void 0),status:typeof n.state?.status==`string`?n.state.status:void 0}}},BL=(e,t)=>{let n=e[t];if(!n)return null;let r=n.info.id;for(let n=t+1;n<e.length;n+=1){let t=e[n];if(FL(t)===`user`)break;let{hide:i,details:a}=zL(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},VL=Yu(()=>Mn(()=>import(`./ToolOutputDialog-DJs9w1_J.js`),__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,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76]))),HL=4e3,UL=new Map,WL=new Map,GL=new Set([`bash`,`shell`,`cmd`,`terminal`]),KL=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(!n.includes(`.`))return n;let r=n.split(`.`).filter(Boolean);return r[r.length-1]??n},qL=e=>{let t=UL.get(e);return t?new Set(t):new Set},JL=(e,t)=>{if(UL.size>=HL&&!UL.has(e)){let e=UL.keys().next().value;typeof e==`string`&&UL.delete(e)}UL.set(e,new Set(t))},YL=e=>{let t=WL.get(e);return t?new Set(t):new Set},XL=(e,t)=>{if(WL.size>=HL&&!WL.has(e)){let e=WL.keys().next().value;typeof e==`string`&&WL.delete(e)}WL.set(e,new Set(t))},ZL=200,QL=new Map,$L=e=>QL.get(e),eR=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=QL.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(QL.size>=ZL&&!QL.has(e)){let e=QL.keys().next().value;typeof e==`string`&&QL.delete(e)}QL.set(e,t)}};function tR(e){let t=(0,Q.c)(3),[n,r]=Z.useState(e),i,a;return t[0]===e?(i=t[1],a=t[2]):(i=()=>{e!=null&&r(e)},a=[e],t[0]=e,t[1]=i,t[2]=a),Z.useEffect(i,a),e??n}var nR=(e,t)=>{if(typeof e==`object`&&e)return e[t]},rR=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s=!1,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=Xn(),{isMobile:m,isTablet:h,hasTouchInput:g}=$c(),_=wb(),v=Tb(_),y=m||h,b=Z.useRef(null),x=Z.useRef(null),S=J(t=>{b.current=t,x.current?.(),x.current=null,t&&m&&(x.current=sF(t,e.info.id))});Z.useEffect(()=>{let t=b.current;return x.current?.(),x.current=null,t&&m&&(x.current=sF(t,e.info.id)),()=>{x.current?.(),x.current=null}},[m,e.info.id]);let C=Da(e=>e.currentSessionId),w=Da(e=>e.revertToMessage),T=Da(e=>e.editMessagePreservingChanges),E=Da(e=>e.forkFromMessage),D=Da(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=Da(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=Da(e=>e.clearStagedMessageEdit);fe(`ui.chat_message.render`),c&&fe(`ui.chat_message.render.streaming`);let A=ni(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=K(H(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{C&&UO.getInstance().recordSessionStart(C)},[C]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[U,W]=Z.useState(()=>qL(e.info.id)),[ee,te]=Z.useState(()=>YL(e.info.id)),[ne,re]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{W(qL(e.info.id)),te(YL(e.info.id))},[e.info.id]);let G=Z.useMemo(()=>mL(e.info),[e.info]).isUser,ie=Z.useMemo(()=>Ee(e.parts),[e.parts]),ae=G&&(m||!M),oe=G&&!m&&M&&!ae,se=e.info.sessionID,{currentContextAgent:ce,savedSessionAgentSelection:le}=vy(H(e=>({currentContextAgent:c&&se?e.currentAgentContext.get(se):void 0,savedSessionAgentSelection:c&&se?e.sessionAgentSelections.get(se):void 0}))),ue=Z.useMemo(()=>ND(e.sourceParts??e.parts),[e.parts,e.sourceParts]),de=Z.useMemo(()=>G?qD(ue):ND(e.parts),[G,e.parts,ue]),pe=Z.useMemo(()=>{if(G||!t)return null;let e=nR(t.info,`clientRole`),n=nR(t.info,`role`);return(typeof e==`string`?e:typeof n==`string`?n:void 0)===`user`&&wL(t.info)||null},[G,t]),me=Z.useMemo(()=>{if(G)return;let t=nR(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=nR(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(pe?.agentName)return pe.agentName;if(se)return ce||(le??void 0)},[G,e.info,pe,se,ce,le]),he=G?null:wL(e.info),ge=he?.providerId??null,_e=he?.modelId??null,ve=wi(H(e=>{if(G||!se)return null;if(pe?.providerId&&pe?.modelId)return{providerId:pe.providerId,modelId:pe.modelId};if(me){let t=e.getAgentModelForSession(se,me);if(t?.providerId&&t?.modelId)return t}let t=e.getSessionModelSelection(se);return t?.providerId&&t?.modelId?t:null})),ye=Z.useMemo(()=>G?null:typeof ge==`string`&&ge.trim().length>0?ge:ve?.providerId??null,[G,ge,ve]),be=Z.useMemo(()=>G?null:typeof _e==`string`&&_e.trim().length>0?_e:ve?.modelId??null,[G,_e,ve]),xe=e.info.id?$L(e.info.id):void 0;G||eR(e.info.id,{agent:me,provider:ye??void 0,model:be??void 0});let Se=me??xe?.agent,Ce=ye??xe?.provider??null,we=be??xe?.model??null,Te=Z.useMemo(()=>{if(G)return;let e=Ce&&A.length>0?A.find(e=>e.id===Ce):void 0;return qr(e,we)||void 0},[G,Ce,we,A]),De=tR(Se),Oe=tR(Ce??void 0),ke=tR(we??void 0),Ae=tR(Te),je=De??void 0,Me=Oe??null,Ne=ke??null,Pe=Ae??void 0,Fe=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ie=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Le=Z.useMemo(()=>G?!0:!!(Fe&&Fe>0),[G,Fe]),Re=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),ze=Z.useMemo(()=>LD(de,{includeReasoning:j}),[de,j]),Be=Z.useMemo(()=>G?ze:!Le&&N===`sorted`?[]:ze,[N,Le,G,ze]),Ve=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`text`),[G,ze]),He=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`tool`),[G,ze]),Ue=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of He){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=KL(t.tool);!r||!GL.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=KL(t.part.tool);!n||!GL.has(n)||e.add(t.id)}return e},[P,He,a?.activityParts]),We=Z.useMemo(()=>{if(Ue.size===0&&ee.size===0)return U;let e=new Set(U);return Ue.forEach(t=>{ee.has(t)||e.add(t)}),ee.forEach(t=>{e.delete(t)}),e},[ee,Ue,U]),Ge=Z.useMemo(()=>{if(!G)return;let e=de.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[G,de]),Ke=G&&!JD(Be),qe=typeof Re!=`string`,Je=Z.useMemo(()=>G?!1:Ve.length===0||He.length===0?qe:!0,[Ve.length,He.length,qe,G]),Ye=Z.useMemo(()=>!G&&UO.getInstance().shouldAnimateMessage(e.info,C||e.info.sessionID),[e.info,C,G]),[Xe,Ze]=Z.useState(!1),Qe=Z.useMemo(()=>n?mL(n.info):null,[n]),$e=!!a,et=a?.isLastAssistantInTurn??!1,tt=NL({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),nt=Z.useMemo(()=>G?!1:$e?!et:Qe?!Qe.isUser&&Qe.role===`assistant`:!1,[$e,et,G,Qe]),rt=Z.useMemo(()=>Le?`completed`:c?l??`streaming`:`completed`,[l,c,Le]);Z.useEffect(()=>{!G||!u||d?.(e.info.id)},[u,G,e.info.id,d]),Z.useEffect(()=>{Ze(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;G||!t||t!==e.info.id||(rt===`streaming`||rt===`cooldown`)&&Ze(!0)},[o,G,e.info.id,rt,a?.headerMessageId]);let it=Z.useMemo(()=>{if(G)return!0;if(s)return!1;let t=o??a?.headerMessageId;return t?e.info.id===t?rt===`completed`||Xe||rt===`streaming`||rt===`cooldown`:!1:!0},[o,Xe,G,a,rt,e.info.id,s]),at=Z.useCallback(e=>{Yn(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),ot=G?void 0:he?.variant??a?.userMessageVariant??pe?.variant,st=!G&&typeof ot==`string`&&ot.trim().length>0?ot:void 0,ct=Z.useMemo(()=>{if(!G&&!xL($e?et:!nt))return vL(e.info?.error,p)},[$e,nt,et,G,e.info,p]),lt=ct?.text,ut=Z.useMemo(()=>{if(G){let e=Be.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
6597
6597
 
6598
6598
  `);let t=Be.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.command;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);return t.length>0?t.join(`
6599
6599
  `):Be.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
@@ -6602,7 +6602,7 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}f
6602
6602
  `),[i]),s=Gd(o,a),c=0;return(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0 space-y-0`,style:r,children:i.map((e,n)=>(0,$.jsxs)(`div`,{className:`-mx-1 px-1 border-b border-border/20 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`bg-muted/20 px-2 py-1 typography-meta font-medium text-muted-foreground border-b border-border/10 break-words -mx-1`,children:`${e.file||t?.split(`/`).pop()||`file`} (line ${e.oldStart})`}),(0,$.jsx)(`div`,{children:e.lines.map((e,t)=>{let n=s?.[c];return c+=1,(0,$.jsxs)(`div`,{className:Y(`typography-code font-mono px-2 py-0.5 flex -mx-2`,e.type===`context`&&`bg-transparent`,e.type===`removed`&&`bg-transparent`,e.type===`added`&&`bg-transparent`),style:e.type===`removed`?{backgroundColor:`var(--tools-edit-removed-bg)`}:e.type===`added`?{backgroundColor:`var(--tools-edit-added-bg)`}:{},children:[(0,$.jsx)(`span`,{className:`w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5`,style:{color:`var(--tools-edit-line-number)`,borderColor:`var(--tools-border)`},children:e.lineNumber||``}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(WV,{content:e.content,html:n})})]},t)})})]},n))})},KV=e=>{let t=(0,Q.c)(21),{content:n,filePath:r}=e,{currentTheme:i}=_s(),a;t[0]===i?a=t[1]:(a=ef(i),t[0]=i,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=n.split(`
6603
6603
  `),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=vd(r??``)||`text`,t[4]=r,t[5]=l);let u=l,d;t[6]===r?d=t[7]:(d=r?.split(`/`).pop()||`New file`,t[6]=r,t[7]=d);let f=d,p=Math.max(c.length,1),m=p===1?`line 1`:`lines 1-${p}`,h=Gd(n,u),g=o,_=`${f} (${m})`,v;t[8]===_?v=t[9]:(v=(0,$.jsx)(`div`,{className:`bg-muted/20 px-2 py-1 typography-meta font-medium text-muted-foreground border border-border/10 rounded-lg mb-1`,children:_}),t[8]=_,t[9]=v);let y;if(t[10]!==h||t[11]!==c){let e;t[13]===h?e=t[14]:(e=(e,t)=>(0,$.jsxs)(`div`,{className:`typography-code font-mono px-2 py-0.5 flex -mx-1`,children:[(0,$.jsx)(`span`,{className:`w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5`,style:{color:`var(--tools-edit-line-number)`,borderColor:`var(--tools-border)`},children:t+1}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(WV,{content:e||` `,html:h?.[t]})})]},t),t[13]=h,t[14]=e),y=c.map(e),t[10]=h,t[11]=c,t[12]=y}else y=t[12];let b;t[15]===y?b=t[16]:(b=(0,$.jsx)(`div`,{className:`space-y-0`,children:y}),t[15]=y,t[16]=b);let x;return t[17]!==g||t[18]!==v||t[19]!==b?(x=(0,$.jsxs)(`div`,{className:`w-full min-w-0`,style:g,children:[v,b]}),t[17]=g,t[18]=v,t[19]=b,t[20]=x):x=t[20],x},qV=new Set([`id`,`identifier`,`title`,`name`]),JV=e=>typeof e==`object`&&!!e&&!Array.isArray(e),YV=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),XV=e=>{let t=typeof e.id==`string`?e.id:typeof e.identifier==`string`?e.identifier:``,n=typeof e.title==`string`?e.title:typeof e.name==`string`?e.name:``;return t&&n?`${t} · ${n}`:n||t||null},ZV=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},QV=Z.memo(e=>{let t=(0,Q.c)(54),{value:n,label:r,depth:i}=e;if(Array.isArray(n)){let e;t[0]!==r||t[1]!==n.length?(e=r?`${YV(r)} (${n.length})`:`(${n.length})`,t[0]=r,t[1]=n.length,t[2]=e):e=t[2];let a=e,o=i<2,s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5 shrink-0 transition-transform group-open/json-summary:rotate-90`}),t[3]=s):s=t[3];let c;t[4]===a?c=t[5]:(c=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 py-1.5 typography-meta text-[var(--surface-foreground)] hover:text-[var(--surface-mutedForeground)]`,children:[s,(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:a})]}),t[4]=a,t[5]=c);let l;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-1 left-0 top-0 w-px bg-[var(--tools-border)] opacity-40`}),t[6]=l):l=t[6];let u;if(t[7]!==i||t[8]!==n){let e;t[10]===i?e=t[11]:(e=(e,t)=>(0,$.jsx)(QV,{value:e,depth:i+1},t),t[10]=i,t[11]=e),u=n.map(e),t[7]=i,t[8]=n,t[9]=u}else u=t[9];let d;t[12]===u?d=t[13]:(d=(0,$.jsxs)(`div`,{className:`relative ml-1 pl-3 pb-1`,children:[l,(0,$.jsx)(`div`,{className:`space-y-1`,children:u})]}),t[12]=u,t[13]=d);let f;return t[14]!==o||t[15]!==c||t[16]!==d?(f=(0,$.jsxs)(`details`,{open:o,className:`group/json-summary`,children:[c,d]}),t[14]=o,t[15]=c,t[16]=d,t[17]=f):f=t[17],f}if(JV(n)){let e;t[18]===n?e=t[19]:(e=XV(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(eH),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${YV(r)}${a?` · ${a}`:``}`:a,t[22]=a,t[23]=r,t[24]=c):c=t[24];let l=c,u;t[25]!==i||t[26]!==s?(u=(0,$.jsx)(`div`,{className:`space-y-1`,children:s.map(e=>{let[t,n]=e;return(0,$.jsx)(QV,{label:t,value:n,depth:i+1},t)})}),t[25]=i,t[26]=s,t[27]=u):u=t[27];let d=u;if(!r&&i===0){let e;t[28]===a?e=t[29]:(e=a?(0,$.jsx)(`div`,{className:`typography-meta font-medium text-[var(--surface-foreground)]`,children:a}):null,t[28]=a,t[29]=e);let n;return t[30]!==d||t[31]!==e?(n=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[e,d]}),t[30]=d,t[31]=e,t[32]=n):n=t[32],n}let f=i<2,p;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5 shrink-0 transition-transform group-open/json-summary:rotate-90`}),t[33]=p):p=t[33];let m;t[34]!==r||t[35]!==l?(m=l??(r?YV(r):`{}`),t[34]=r,t[35]=l,t[36]=m):m=t[36];let h;t[37]===m?h=t[38]:(h=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 py-1.5 typography-meta text-[var(--surface-foreground)] hover:text-[var(--surface-mutedForeground)]`,children:[p,(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:m})]}),t[37]=m,t[38]=h);let g;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-1 left-0 top-0 w-px bg-[var(--tools-border)] opacity-40`}),t[39]=g):g=t[39];let _;t[40]===d?_=t[41]:(_=(0,$.jsxs)(`div`,{className:`relative ml-1 pl-3 pb-1`,children:[g,d]}),t[40]=d,t[41]=_);let v;return t[42]!==_||t[43]!==f||t[44]!==h?(v=(0,$.jsxs)(`details`,{open:f,className:`group/json-summary`,children:[h,_]}),t[42]=_,t[43]=f,t[44]=h,t[45]=v):v=t[45],v}let a=n===null?`null`:typeof n==`boolean`?n?`true`:`false`:String(n),o;t[46]!==a||t[47]!==n?(o=typeof n==`string`&&ZV(n)?(0,$.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`truncate text-[var(--status-info)] underline underline-offset-2 hover:opacity-80`,title:n,children:n}):(0,$.jsx)(`span`,{className:Y(`min-w-0 break-words`,n===null?`text-[var(--surface-mutedForeground)]`:`text-[var(--surface-foreground)]`),children:a}),t[46]=a,t[47]=n,t[48]=o):o=t[48];let s=o,c;t[49]===r?c=t[50]:(c=r?(0,$.jsx)(`span`,{className:`truncate text-[var(--surface-mutedForeground)]`,title:r,children:YV(r)}):(0,$.jsx)(`span`,{}),t[49]=r,t[50]=c);let l;return t[51]!==s||t[52]!==c?(l=(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(6rem,auto)_minmax(0,1fr)] gap-x-2 py-1 typography-meta`,children:[c,s]}),t[51]=s,t[52]=c,t[53]=l):l=t[53],l});QV.displayName=`JsonSummaryValue`;var $V=Z.memo(e=>{let t=(0,Q.c)(2),{data:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`space-y-1`,children:(0,$.jsx)(QV,{value:n,depth:0})}),t[0]=n,t[1]=r),r});$V.displayName=`JsonSummaryView`;function eH(e){let[t]=e;return!qV.has(t)}function tH(e){let t=(0,Q.c)(20),{header:n,children:r,footer:i,afterBody:a,mobile:o,questionCard:s,onInteraction:c}=e,l=o!==void 0&&o,u=s!==void 0&&s?``:void 0,d=l?`px-3 py-2`:`px-2 py-1.5`,f;t[0]===d?f=t[1]:(f=Y(`border-b border-border/20`,d),t[0]=d,t[1]=f);let p;t[2]!==n||t[3]!==f?(p=(0,$.jsx)(`div`,{className:f,children:n}),t[2]=n,t[3]=f,t[4]=p):p=t[4];let m=l?`px-3 py-3`:`px-2 py-2`,h;t[5]===m?h=t[6]:(h=Y(m),t[5]=m,t[6]=h);let g;t[7]!==r||t[8]!==h?(g=(0,$.jsx)(`div`,{className:h,children:r}),t[7]=r,t[8]=h,t[9]=g):g=t[9];let _;t[10]!==i||t[11]!==l?(_=i?(0,$.jsx)(`div`,{className:Y(`flex flex-wrap items-center gap-1.5 border-t border-border/20`,l?`px-3 py-2`:`px-2 pb-1.5 pt-1`),children:i}):null,t[10]=i,t[11]=l,t[12]=_):_=t[12];let v;return t[13]!==a||t[14]!==c||t[15]!==_||t[16]!==u||t[17]!==p||t[18]!==g?(v=(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{"data-interaction-card":!0,"data-question-card":u,className:`-mt-1 overflow-hidden rounded-xl border border-border/30 bg-muted/10`,onClickCapture:c,onKeyDownCapture:c,onInputCapture:c,onPasteCapture:c,onCompositionStartCapture:c,children:[p,g,a,_]})})}),t[13]=a,t[14]=c,t[15]=_,t[16]=u,t[17]=p,t[18]=g,t[19]=v):v=t[19],v}var nH={margin:0,padding:`0.5rem`,fontSize:`var(--text-meta)`,lineHeight:`1.25rem`,background:`rgb(var(--muted) / 0.3)`,borderRadius:`0.25rem`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`,overflow:`visible`},rH={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},iH=e=>{let t=`h-3 w-3`,n=e.toLowerCase();return n===`edit`||n===`multiedit`||n===`str_replace`||n===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil-ai`,className:t}):n===`write`||n===`create`||n===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:t}):n===`bash`||n===`shell`||n===`cmd`||n===`terminal`||n===`shell_command`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):n===`webfetch`||n===`fetch`||n===`curl`||n===`wget`?(0,$.jsx)(X,{name:`global`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},aH=e=>{let t=e.toLowerCase();return t===`edit`||t===`multiedit`||t===`str_replace`||t===`str_replace_based_edit_tool`?`edit`:t===`write`||t===`create`||t===`file_write`?`write`:t===`bash`||t===`shell`||t===`cmd`||t===`terminal`||t===`shell_command`?`bash`:t===`webfetch`||t===`fetch`||t===`curl`||t===`wget`?`webfetch`:e},oH=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,sH=e=>{let t=(0,Q.c)(2),{data:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`rounded-lg border border-border/20 bg-muted/15 px-2 py-1 sm:px-2.5 sm:py-1.5 [&_.typography-meta]:!text-xs [&_summary]:py-1`,children:(0,$.jsx)($V,{data:n})}),t[0]=n,t[1]=r),r},cH=({permission:e,onResponse:t})=>{let{t:n}=Xn(),r=K(e=>e.isMobile),[i,a]=Z.useState(!1),[o,s]=Z.useState(!1),c=Wo,l=Oi(),u=Da(e=>e.currentSessionId),d=Z.useMemo(()=>{if(!u||e.sessionID===u)return!1;let t=l.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===u)},[e.sessionID,u,l]),f=async n=>{a(!0);try{await c(e.sessionID,e.id,n),s(!0),t?.(n)}catch(e){console.error(`[PermissionCard] Failed to respond to permission:`,e)}finally{a(!1)}};if(o)return null;let p=e.permission||`unknown`,m=p.toLowerCase(),h=(t,n=``)=>{let r=e.metadata[t];return typeof r==`string`?r:typeof r==`number`?String(r):n},g=t=>{let n=e.metadata[t];return typeof n==`number`?n:void 0},_=t=>!!e.metadata[t],v=aH(p),y=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[oH(e),t]));return(0,$.jsx)(tH,{mobile:r,header:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 sm:gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-[var(--status-warning)]`}),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] font-medium text-muted-foreground`,children:n(`sessions.sidebar.session.status.permissionRequired`)}),d?(0,$.jsx)(`span`,{className:`hidden sm:inline typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:n(`chat.questionCard.fromSubagent`)}):null]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[48%] items-center gap-1.5`,children:[iH(p),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] text-muted-foreground font-medium`,children:v})]})]}),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid w-full grid-cols-1 gap-1.5 sm:flex sm:items-center sm:flex-wrap`,children:[(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>f(`once`),disabled:i,className:`min-h-9 min-w-0 w-full gap-1.5 px-2 !text-xs leading-4 text-foreground sm:w-auto`,children:[(0,$.jsx)(X,{name:`check`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.allowOnce`)})]}),(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>f(`always`),disabled:i,className:`min-h-9 min-w-0 w-full gap-1.5 px-2 !text-xs leading-4 text-foreground sm:w-auto`,children:[(0,$.jsx)(X,{name:`arrow-right`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.alwaysAgree`)})]}),(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>f(`reject`),disabled:i,className:`min-h-9 min-w-0 w-full gap-1.5 px-2 !text-xs leading-4 text-[var(--status-error)] sm:w-auto`,children:[(0,$.jsx)(X,{name:`close`,className:`size-3.5 shrink-0 sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionToast.actions.deny`)})]})]}),i?(0,$.jsx)(`div`,{className:`flex justify-center w-full py-1 sm:w-auto sm:ml-auto typography-meta text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})}):null]}),children:(0,$.jsxs)(`div`,{className:`[&_.typography-meta]:!text-xs [&_.typography-micro]:!text-[0.6875rem]`,children:[e.patterns.length>0&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:n(`chat.permissionCard.patterns`)}),(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border/20 bg-muted/15`,children:e.patterns.map((e,t)=>(0,$.jsx)(`code`,{className:Y(`block break-all px-2 py-1.5 text-xs leading-4 sm:text-[length:var(--text-meta)]`,t>0&&`border-t border-border/15`),children:e},`${e}-${t}`))})]}),(()=>{if(m===`bash`||m===`shell`||m===`shell_command`){let e=h(`command`)||h(`cmd`)||h(`script`),t=h(`description`),r=h(`cwd`)||h(`working_directory`)||h(`directory`)||h(`path`),i=g(`timeout`);return(0,$.jsxs)($.Fragment,{children:[t&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:t}),r&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.workingDirectory`)}),` `,(0,$.jsx)(`code`,{className:`px-1 py-0.5 bg-muted/30 rounded`,children:r})]}),i&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.timeout`)}),` `,i,`ms`]}),e&&(0,$.jsx)(`div`,{children:(0,$.jsx)(zd,{language:`bash`,code:e,style:nH,codeStyle:rH.style,wrap:!0})})]})}if(m===`edit`||m===`multiedit`||m===`str_replace`||m===`str_replace_based_edit_tool`){let e=h(`path`)||h(`file_path`)||h(`filename`)||h(`filePath`),t=h(`changes`)||h(`diff`),r=_(`replace_all`)||_(`replaceAll`);return(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:(0,$.jsxs)(`span`,{className:`font-semibold`,children:[`⚠️ `,n(`chat.permissionCard.replaceAll`)]})}),t&&(0,$.jsx)($u,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(GV,{diff:t,filePath:e})})]})}if(m===`write`||m===`create`||m===`file_write`){let e=h(`path`)||h(`file_path`)||h(`filename`)||h(`filePath`),t=h(`content`)||h(`text`)||h(`data`);return t?(0,$.jsx)($u,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(KV,{content:t,filePath:e})}):null}if(m===`webfetch`||m===`fetch`||m===`curl`||m===`wget`){let t=h(`url`)||h(`uri`)||h(`endpoint`),r=h(`method`)||`GET`,i=e.metadata.headers&&typeof e.metadata.headers==`object`?e.metadata.headers:void 0,a=e.metadata.body??e.metadata.data??e.metadata.payload,o=g(`timeout`),s=h(`format`)||h(`responseType`);return(0,$.jsxs)($.Fragment,{children:[t&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.request`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold px-1.5 py-0.5 bg-primary/20 text-primary rounded`,children:r}),(0,$.jsx)(`code`,{className:`typography-meta px-2 py-1 bg-muted/30 rounded flex-1 break-all`,children:t})]})]}),i&&Object.keys(i).length>0&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.headers`)}),(0,$.jsx)($u,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(sH,{data:i})})]}),a&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.body`)}),(0,$.jsx)($u,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(sH,{data:a}):(0,$.jsx)(`pre`,{className:`typography-meta font-mono px-2 py-1.5 bg-muted/20 border border-border/20 rounded-lg whitespace-pre-wrap break-all`,children:String(a)})})]}),(o||s)&&(0,$.jsxs)(`div`,{className:`typography-micro text-muted-foreground`,children:[o&&(0,$.jsxs)(`span`,{children:[n(`chat.permissionCard.timeout`),` `,o,`ms`]}),o&&s&&(0,$.jsx)(`span`,{children:` • `}),s&&(0,$.jsxs)(`span`,{children:[n(`chat.permissionCard.responseFormat`),` `,s]})]})]})}return Object.keys(y).length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:n(`chat.permissionCard.details`)}),(0,$.jsx)($u,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(sH,{data:y})})]})})()]})})};function lH(e){let t=[];return(e.questions??[]).forEach((e,n)=>{let r=e.header?.trim(),i=r&&r.length>0?r:`Question ${n+1}`;t.push(`## ${i}`),t.push(``),t.push(e.question),t.push(``),e.multiple&&(t.push(`_Select all that apply._`),t.push(``)),e.options.forEach(e=>{let n=e.label,r=e.description?.trim();t.push(r?`- **${n}** — ${r}`:`- **${n}**`)}),t.push(``)}),t.join(`
6604
6604
  `).trimEnd()}function uH(e){let t={questions:(e.questions??[]).map(e=>({header:e.header??null,question:e.question,multiple:!!e.multiple,options:e.options.map(e=>({label:e.label,description:e.description??null}))}))};return JSON.stringify(t,null,2)}var dH=200;function fH(e){return Math.min(Math.max(e,40),dH)}var pH=`summary`,mH=Z.memo(function(e){let t=(0,Q.c)(27),{value:n,placeholder:r,disabled:i,onValueChange:a,onKeyDown:o}=e,s=Z.useRef(null),[c,l]=Z.useState(n),[u,d]=Z.useState(40),[f,p]=Z.useState(!1),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current;if(!e||document.activeElement!==e)return;let t=e.closest(`.chat-scroll`);if(!t){e.scrollIntoView({block:`nearest`});return}let n=window.visualViewport,r=t.getBoundingClientRect(),i=n?.offsetTop??0,a=n?n.offsetTop+n.height:document.documentElement.clientHeight,o=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--yuri-kb-scroll-inset`))||0,c=Math.max(r.top,i),l=Math.min(r.bottom,a-o),u=Math.max(0,l-c),d=e.closest(`[data-question-card]`),f=d?.getBoundingClientRect(),p=(d&&f&&f.height<=u?d:e).getBoundingClientRect();p.bottom>l-12?t.scrollTop+=p.bottom-l+12:p.top<c+12&&(t.scrollTop+=p.top-c-12)},t[0]=m):m=t[0];let h=J(m),g;t[1]===h?g=t[2]:(g=()=>{requestAnimationFrame(h)},t[1]=h,t[2]=g);let _=J(g),v;t[3]===h?v=t[4]:(v=()=>{let e=()=>requestAnimationFrame(h);return e(),window.addEventListener(`yuri:keyboard-settled`,e),window.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`yuri:keyboard-settled`,e),window.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`scroll`,e)}},t[3]=h,t[4]=v);let y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(y=[],t[5]=y):y=t[5],Z.useEffect(v,y);let b,x;t[6]===n?(b=t[7],x=t[8]):(b=()=>{l(n)},x=[n],t[6]=n,t[7]=b,t[8]=x),Z.useEffect(b,x);let S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>{let e=s.current;if(!e)return;e.style.height=`auto`,e.style.overflowY=`hidden`;let t=e.scrollHeight,n=fH(t),r=t>n;e.style.height=`${n}px`,e.style.overflowY=``,d(e=>e===n?e:n),p(e=>e===r?e:r)},t[9]=S):S=t[9];let C;t[10]===c?C=t[11]:(C=[c],t[10]=c,t[11]=C),Z.useLayoutEffect(S,C);let w;t[12]===a?w=t[13]:(w=e=>{let t=e.target.value;l(t),a(t)},t[12]=a,t[13]=w);let T;t[14]===u?T=t[15]:(T={height:u},t[14]=u,t[15]=T);let E=f?`overflow-y-auto`:`overflow-hidden`,D;t[16]===E?D=t[17]:(D=Y(`w-full bg-transparent border border-border/30 focus:border-primary rounded px-2 py-1 outline-none typography-meta text-foreground placeholder:text-muted-foreground/50 transition-colors resize-none`,E),t[16]=E,t[17]=D);let O;return t[18]!==i||t[19]!==_||t[20]!==c||t[21]!==o||t[22]!==r||t[23]!==T||t[24]!==D||t[25]!==w?(O=(0,$.jsx)(`textarea`,{ref:s,value:c,onChange:w,placeholder:r,disabled:i,rows:2,onKeyDown:o,onFocus:_,style:T,className:D,autoFocus:!0}),t[18]=i,t[19]=_,t[20]=c,t[21]=o,t[22]=r,t[23]=T,t[24]=D,t[25]=w,t[26]=O):O=t[26],O}),hH=({question:e})=>{let{t}=Xn(),n=Bi(e),r=ns,i=io,a=K(e=>e.isMobile),o=Oi(),s=Da(e=>e.currentSessionId),c=Z.useMemo(()=>{if(!s||e.sessionID===s)return!1;let t=o.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===s)},[e.sessionID,s,o]),l=n.scope,u=Jr(e=>e.drafts[l]?.activeTab??`0`),d=e=>Pr(l,()=>({activeTab:e})),[f,p]=Z.useState(!1),m=f||n.claimed||n.request?.state===`submitting`||n.request?.state===`uncertain`||n.request?.state===`settled`,[h,g]=Z.useState(!1),_=Jr(e=>Ki(e,l).selectedOptions),v=Jr(e=>Ki(e,l).customMode),y=Jr(e=>Ki(e,l).customTextFilled),b=Z.useMemo(()=>e.questions??[],[e.questions]),x=u===pH,S=x?-1:Math.max(0,Math.min(b.length-1,Number(u)||0)),C=x?null:b[S],w=Z.useMemo(()=>{if(x)return null;let e=C?.header?.trim();return e&&e.length>0?e:null},[C?.header,x]);Z.useEffect(()=>{g(!1)},[l]);let T=Z.useMemo(()=>{let e=b.map((e,t)=>({value:String(t),label:e.header?.trim()||`Q${t+1}`}));return b.length>1&&e.push({value:pH,label:t(`chat.questionCard.summaryTab`)}),e},[b,t]),E=e=>{if(v[e])return(Ii(l).customText[e]??``).trim()||t(`chat.questionCard.noAnswer`);let n=_[e]??[];return n.length>0?n.join(`, `):t(`chat.questionCard.noAnswer`)},D=!!C?.multiple,O=_[S]??[],k=!!v[S],A=Z.useMemo(()=>{let e=[];for(let t=0;t<b.length;t+=1){if(v[t]){y[t]||e.push(t);continue}(_[t]??[]).length===0&&e.push(t)}return e},[v,y,b.length,_]),j=Z.useMemo(()=>b.length!==0&&A.length===0,[b.length,A.length]),M=J(()=>{if(b.length===0||A.length===0)return;let e=x?-1:S;for(let t=1;t<=b.length;t+=1){let n=(e+t+b.length)%b.length;if(A.includes(n)){d(String(n));return}}d(String(A[0]))}),N=()=>{let e=[];for(let t=0;t<b.length;t+=1){if(v[t]){let n=(Ii(l).customText[t]??``).trim();e.push(n?[n]:[]);continue}e.push(_[t]??[])}return e},P=J(e=>{C&&Pr(l,t=>{let n=t.selectedOptions[S]??[],r=D?n.includes(e)?n.filter(t=>t!==e):[...n,e]:[e];return{selectedOptions:{...t.selectedOptions,[S]:r},customMode:{...t.customMode,[S]:!1},customTextFilled:t.customTextFilled[S]?{...t.customTextFilled,[S]:!1}:t.customTextFilled}})}),F=J(()=>{Pr(l,e=>({customMode:{...e.customMode,[S]:!0},selectedOptions:{...e.selectedOptions,[S]:[]},customTextFilled:{...e.customTextFilled,[S]:(e.customText[S]??``).trim().length>0}}))}),I=J(e=>{let t=e.trim().length>0;Pr(l,n=>({customText:{...n.customText,[S]:e},customTextFilled:n.customTextFilled[S]===t?n.customTextFilled:{...n.customTextFilled,[S]:t}}))}),L=J(async()=>{if(!j||m)return;let i=n.scope;p(!0);try{let t=N();await r(e.sessionID,e.id,t,n.request?.directory),zr(i),g(!0)}catch(e){Na(e)?await n.submissionClaimed(i):La(e)?(zr(i),Yr.info(t(`chat.questionCard.noLongerPending`)),g(!0)):Yr.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),R=J(e=>{Gl(e)||e.key===`Enter`&&!e.shiftKey&&(!a||e.ctrlKey||e.metaKey)&&(e.preventDefault(),j?L():M())}),z=J(async()=>{if(m)return;let r=n.scope;p(!0);try{await i(e.sessionID,e.id,n.request?.directory),zr(r),g(!0)}catch(e){Na(e)?await n.submissionClaimed(r):La(e)?(zr(r),Yr.info(t(`chat.questionCard.noLongerPending`)),g(!0)):Yr.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),B=J(async()=>{let n=lH(e);if((await Yn(n)).ok){Yr.success(t(`chat.questionCard.copiedMarkdown`));return}Yr.error(t(`chat.questionCard.copyFailed`))}),V=J(async()=>{let n=uH(e);if((await Yn(n)).ok){Yr.success(t(`chat.questionCard.copiedJson`));return}Yr.error(t(`chat.questionCard.copyFailed`))});return h||b.length===0?null:(0,$.jsxs)(tH,{mobile:a,questionCard:!0,header:(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center gap-2`,a&&`flex-wrap`),children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 typography-meta font-medium text-muted-foreground`,children:t(`chat.questionCard.inputNeeded`)}),c?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:t(`chat.questionCard.fromSubagent`)}):null,w?(0,$.jsx)(`span`,{className:`ml-auto min-w-0 truncate typography-micro font-medium text-foreground/70 px-1.5 py-0.5 rounded bg-muted/30 border border-border/20`,children:w}):null,(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-0.5`,w?null:`ml-auto`),children:[(0,$.jsx)(`button`,{type:`button`,onClick:B,title:t(`chat.questionCard.copyMarkdown`),"aria-label":t(`chat.questionCard.copyMarkdown`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`file-text`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:V,title:t(`chat.questionCard.copyJson`),"aria-label":t(`chat.questionCard.copyJson`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`code-box`,className:`h-3 w-3`})})]})]}),onInteraction:n.interaction,afterBody:(0,$.jsx)(_r,{delegation:n}),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:j?L:M,disabled:m,className:Y(`flex min-h-9 items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-success)/0.1)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[j?(0,$.jsx)(X,{name:`check`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`}),t(j?`chat.questionCard.submit`:`chat.questionCard.next`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:z,disabled:m,className:Y(`flex min-h-9 items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-error)/0.1)] text-[var(--status-error)] hover:bg-[rgb(var(--status-error)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`}),t(`chat.questionCard.dismiss`)]}),m?(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})}):null]}),children:[T.length>1?(0,$.jsx)(`div`,{className:`flex items-center gap-1 mb-2 flex-wrap`,children:T.map(e=>{let t=u===e.value,n=e.value===pH,r=n?-1:Number(e.value),i=!n&&Number.isFinite(r)&&!A.includes(r);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(e.value),className:Y(`px-2 py-0.5 typography-meta font-medium rounded transition-colors flex items-center gap-1`,t?`bg-interactive-selection/40 text-foreground`:n?`text-muted-foreground hover:text-foreground hover:bg-interactive-hover/20`:i?`text-muted-foreground/60 hover:text-muted-foreground hover:bg-interactive-hover/20`:`text-foreground/85 hover:text-foreground hover:bg-interactive-hover/20`),children:[n?(0,$.jsx)(X,{name:`list-check-3`,className:`h-3 w-3`}):null,e.label]},e.value)})}):null,x?(0,$.jsx)(`div`,{className:`space-y-2`,children:b.map((e,n)=>{let r=E(n),i=r!==t(`chat.questionCard.noAnswer`);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(String(n)),className:`w-full text-left rounded px-1.5 py-1 hover:bg-interactive-hover/20 transition-colors`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.header||t(`chat.questionCard.questionFallback`,{index:n+1})}),(0,$.jsx)(`div`,{className:Y(`typography-meta`,i?`text-foreground`:`text-muted-foreground/50 italic`),children:r})]},n)})}):C?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground mb-1.5`,children:C.question}),D?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1.5`,children:t(`chat.questionCard.selectMultiple`)}):null,(0,$.jsxs)(`div`,{className:Y(`space-y-0.5`,a&&`space-y-1`),children:[C.options.map((e,n)=>{let r=O.includes(e.label),i=/\(recommended\)/i.test(e.label);return(0,$.jsx)(`button`,{type:`button`,onClick:()=>P(e.label),disabled:m,"aria-pressed":r,className:Y(`w-full min-h-9 px-2 py-1.5 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,r?`bg-interactive-selection/20`:null,m?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`mt-0.5 shrink-0`,"aria-hidden":`true`,children:D?(0,$.jsx)(`span`,{className:Y(`flex size-4 items-center justify-center rounded border`,r?`border-primary bg-primary text-primary-foreground`:`border-border bg-background`),children:r?(0,$.jsx)(X,{name:`check`,className:`size-3`}):null}):(0,$.jsx)(`span`,{className:`flex size-4 items-center justify-center rounded-full border border-border bg-background`,children:r?(0,$.jsx)(`span`,{className:`size-2 rounded-full bg-primary`}):null})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:Y(`typography-meta break-all`,r?`text-foreground font-medium`:`text-foreground/80`),children:e.label}),i?(0,$.jsx)(`span`,{className:`typography-micro text-primary/80`,children:t(`chat.questionCard.recommended`)}):null]}),e.description?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground break-words`,children:e.description}):null]})]})},`${n}:${e.label}`)}),(0,$.jsx)(`button`,{type:`button`,onClick:F,disabled:m,"aria-pressed":k,className:Y(`w-full min-h-9 px-2 py-1.5 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,k?`bg-interactive-selection/20`:null,m?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`edit`,className:Y(`h-3.5 w-3.5`,k?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,k?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),k?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)(mH,{value:Ii(l).customText[S]??``,onValueChange:I,placeholder:t(`chat.questionCard.yourAnswer`),disabled:m,onKeyDown:R})}):null]})]}):null]})};function gH(e){if(e.type!==`external`)return e.type===`multiselect`?e.default??[]:e.type===`boolean`?e.default??!1:e.type===`number`||e.type===`integer`?e.default:e.default??(e.type===`string`?e.options?.[0]?.value:void 0)??``}var _H=({form:e,directory:t})=>{let{t:n}=Xn(),r=K(e=>e.isMobile),[i,a]=Z.useState(!1),[o,s]=Z.useState(null),[c,l]=Z.useState(()=>{let t={};for(let n of e.fields){let e=gH(n);e!==void 0&&(t[n.key]=e)}return t}),u=(e,t)=>{l(n=>({...n,[e]:t}))},d=J(async()=>{if(!i){s(null),a(!0);try{await ri({sessionID:e.sessionID,formID:e.id,answer:c,directory:t}),fr.getState().remove(e.sessionID,e.id)}catch{s(`reply`)}finally{a(!1)}}}),f=J(async()=>{if(!i){s(null),a(!0);try{await Ka({sessionID:e.sessionID,formID:e.id,directory:t}),fr.getState().remove(e.sessionID,e.id)}catch{s(`cancel`)}finally{a(!1)}}});return(0,$.jsxs)(tH,{mobile:r,header:(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:e.title||n(`chat.form.title`)}),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(er,{type:`button`,variant:`default`,size:`sm`,onClick:()=>void d(),disabled:i,children:n(`chat.form.reply`)}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void f(),disabled:i,children:n(`chat.form.cancel`)})]}),children:[(0,$.jsx)(`div`,{className:`space-y-2`,children:e.fields.map(e=>{if(e.type===`external`)return(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`block typography-meta text-primary underline`,children:e.title||e.url},e.key);if(e.type===`boolean`)return(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-meta`,children:[(0,$.jsx)(js,{checked:!!c[e.key],onChange:t=>u(e.key,t),disabled:i}),(0,$.jsx)(`span`,{children:e.title||e.key})]},e.key);if(e.type===`multiselect`){let t=Array.isArray(c[e.key])?c[e.key]:[];return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:e.title||e.key}),e.options.map(n=>(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-meta`,children:[(0,$.jsx)(js,{checked:t.includes(n.value),onChange:r=>{let i=r?[...t,n.value]:t.filter(e=>e!==n.value);u(e.key,i)},disabled:i}),(0,$.jsx)(`span`,{children:n.label})]},n.value))]},e.key)}if(e.type===`number`||e.type===`integer`)return(0,$.jsxs)(`label`,{className:`block space-y-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:e.title||e.key}),(0,$.jsx)(Qs,{type:`number`,value:typeof c[e.key]==`number`?String(c[e.key]):``,onChange:t=>u(e.key,t.target.value===``?``:Number(t.target.value)),disabled:i})]},e.key);let t=e.type===`string`?e.options:void 0;return t&&t.length>0?(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:e.title||e.key}),e.description?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:e.description}):null,(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,role:`group`,"aria-label":e.title||e.key,children:t.map(t=>(0,$.jsx)(er,{type:`button`,variant:`chip`,size:`sm`,"aria-pressed":c[e.key]===t.value,disabled:i,onClick:()=>u(e.key,t.value),children:t.label},t.value))}),e.type===`string`&&e.custom?(0,$.jsx)(Qs,{"aria-label":e.title||e.key,value:typeof c[e.key]==`string`?c[e.key]:``,disabled:i,onChange:t=>u(e.key,t.target.value)}):null]},e.key):(0,$.jsxs)(`label`,{className:`block space-y-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:e.title||e.key}),(0,$.jsx)(Qs,{value:typeof c[e.key]==`string`?c[e.key]:``,placeholder:e.type===`string`?e.placeholder:void 0,onChange:t=>u(e.key,t.target.value),disabled:i})]},e.key)})}),o?(0,$.jsx)(`div`,{role:`alert`,className:`mt-2 typography-meta text-[var(--status-error)]`,children:n(o===`reply`?`chat.questionCard.submitFailed`:`chat.questionCard.dismissFailed`)}):null]})};function vH(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function yH(e){return typeof e==`string`&&e.length>0?e:void 0}function bH(e){if(!vH(e))return null;let t=yH(e.reason),n=yH(e.provider),r=yH(e.title),i=yH(e.message),a=yH(e.label);return!t||!n||!r||!i||!a?null:{reason:t,provider:n,title:r,message:i,label:a,...yH(e.link)?{link:yH(e.link)}:{}}}function xH(e){return!vH(e)||e.type!==`retry`?!1:bH(e.action)!==null}function SH(e,t){if(!xH(e))return null;let n=e.action,r=n.reason===`account_rate_limit`?t(`chat.retry.action.account`):t(`chat.retry.action.quota`);return{title:n.title||r,message:n.message||e.message||r,label:n.label||t(`chat.retry.action.open`),...n.link?{link:n.link}:{}}}var CH=Z.memo(function({scrollRef:e,active:t,showScrollToBottom:n,onScrollToBottom:r}){let i=(0,Z.useSyncExternalStore)(xO,yO,()=>null),{t:a}=Xn(),o=Z.useRef(null),[s,c]=Z.useState(null),l=J(e=>{o.current=e,c(e?.parentElement?.querySelector(`.yuri-mobile-composer`)??null)}),u=J(()=>{let e=o.current,t=s?.querySelector(`.yuri-mobile-composer-motion-viewport`),n=s?.querySelector(`.yuri-mobile-composer-compact-layer`);if(!e||!t||!n||!n.offsetHeight)return;let r=`${e.parentElement.getBoundingClientRect().bottom-t.getBoundingClientRect().bottom+(Number.parseFloat(getComputedStyle(n).bottom)||0)+n.offsetHeight}px`;e.style.getPropertyValue(`--yuri-transcript-compact-inset`)!==r&&e.style.setProperty(`--yuri-transcript-compact-inset`,r)});qn(s,u),Z.useLayoutEffect(()=>{u()},[s]);let d=i!==null&&!!e.current?.contains(i.target);return!t||!d&&!n?null:(0,$.jsx)(`div`,{ref:l,className:`yuri-transcript-scroll-controls absolute inset-x-0 bottom-full mb-2 pointer-events-none`,children:(0,$.jsx)(`div`,{className:`chat-input-column`,children:(0,$.jsxs)(`div`,{className:`yuri-transcript-scroll-controls-row mx-auto flex items-center justify-end gap-2`,children:[n&&(0,$.jsx)(er,{size:`mobileIcon`,variant:`mobileGlass`,className:`pointer-events-auto`,onClick:r,"aria-label":a(`chat.scrollToBottom.aria`),title:a(`chat.scrollToBottom.aria`),children:(0,$.jsx)(X,{name:`arrow-down`,weight:`medium`,className:`size-5`})}),d&&(0,$.jsx)(er,{size:`mobileIcon`,variant:`mobileGlass`,className:`pointer-events-auto${i?.following?` yuri-speech-follow-active`:``}`,"aria-pressed":i?.following,onClick:()=>{i?.following&&e.current?CO(e.current):wO()},"aria-label":a(`chat.messageBody.tts.follow`),title:a(`chat.messageBody.tts.follow`),children:(0,$.jsx)(X,{name:`target`,weight:`medium`,className:`size-5`})})]})})})});function wH(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
6605
- `)}function TH(e,t=80){let n=wH(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var EH=new Set;function DH(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(EH),a,o;return n[0]!==e||n[1]!==t?(a=()=>{let n=e?.current;if(i(EH),!n||!t||typeof IntersectionObserver>`u`)return;let r=new Map,a=new Set,o=()=>{let e=new Set;for(let t of a){let n=r.get(t);n&&e.add(n)}i(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},s=new IntersectionObserver(e=>{for(let t of e)r.has(t.target)&&(t.isIntersecting&&t.intersectionRect.height>0?a.add(t.target):a.delete(t.target));o()},{root:n,threshold:0}),c=OH,l=e=>{if(r.has(e))return;let n=e.dataset.scrollSpyId??e.dataset.turnId??e.dataset.messageId,i=n?t.get(n):void 0;i&&(r.set(e,i),s.observe(e))},u=e=>{s.unobserve(e),r.delete(e),a.delete(e)};c(n,l);let d=new MutationObserver(e=>{for(let t of e){if(t.type===`attributes`&&t.target instanceof HTMLElement){u(t.target),l(t.target);continue}t.removedNodes.forEach(e=>c(e,u)),t.addedNodes.forEach(e=>c(e,l))}o()});return d.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`data-turn-id`,`data-message-id`,`data-scroll-spy-id`]}),()=>{d.disconnect(),s.disconnect()}},o=[e,t],n[0]=e,n[1]=t,n[2]=a,n[3]=o):(a=n[2],o=n[3]),Z.useEffect(a,o),r}function OH(e,t){e instanceof HTMLElement&&(e.matches(`[data-turn-id], [data-message-id]`)&&t(e),e.querySelectorAll(`[data-turn-id], [data-message-id]`).forEach(t))}var kH=160,AH=28,jH=12,MH=6,NH=30,PH=12,FH=18,IH=80,LH=4,RH=10,zH=14,BH=20,VH=48,HH=160,UH=(e,t)=>e.map(e=>{let n=t.get(e)??[],r=wH(n),i=T_(r,{citationIcons:j_(n)}),a=[],o=0;for(let e of i)a.push(r.slice(o,e.start)),o=e.end;a.push(r.slice(o));let s=a.join(` `).replace(/\s+/g,` `).trim();return{turnId:e,preview:s.length>kH?`${s.slice(0,kH)}…`:s}}),WH=[1,.6,.35,.15],GH=(e,t,n)=>{let r=n?zH:RH;if(t===null)return r;let i=WH[Math.abs(e-t)]??0;return Math.round(r+(BH-r)*i)};function KH({turnIds:e,previewsByTurnId:t,activeTurnId:n,scrollRef:r,turnByMessageId:i,repliesByTurnId:a,onSelectTurn:o,canLoadEarlier:s,isLoadingOlder:c,onLoadEarlier:l}){let{t:u}=Xn(),d=DH(r,i),f=K(e=>e.isPromptNavigatorPanelOpen),p=K(e=>e.setPromptNavigatorPanelOpen),m=Z.useRef(null),h=Z.useRef(null),[g,_]=Z.useState(null),[v,y]=Z.useState(0),[b,x]=Z.useState(!1);Z.useEffect(()=>{let e=h.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){x(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.left+MH+AH;x(r.left<i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let S=Z.useMemo(()=>UH(e,t),[t,e]),C=Math.min(S.length,NH),w=Math.max(0,S.length-C),T=Math.min(v,w),E=T+C,D=T>0,O=E<S.length,k=u(`chat.timeline.noTextContent`),A=u(`chat.promptNavigator.loadMore`),j=Z.useMemo(()=>n?S.findIndex(e=>e.turnId===n):-1,[n,S]),M=Z.useRef(T);M.current=T;let N=Z.useRef(S.length);N.current=S.length;let P=Z.useRef(null),F=Z.useRef(null),I=Z.useRef(0),L=Z.useCallback(e=>{y(t=>{let n=N.current,r=Math.min(n,NH),i=Math.max(0,n-r),a=Math.min(t,i);return e<a?e:e>=a+r?Math.min(i,e-r+1):a})},[]),R=Z.useRef(S[0]?.turnId),z=Z.useRef(S.length);Z.useLayoutEffect(()=>{let e=R.current,t=z.current,n=S.length-t;n>0&&t>0&&e&&S[0]?.turnId!==e&&(y(e=>e+n),_(e=>e===null?null:e+n)),R.current=S[0]?.turnId,z.current=S.length},[S]),Z.useEffect(()=>{if(g!==null)return;let e=j>=0?j:S.length-1;y(()=>{let t=N.current,n=Math.min(t,NH),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[j,g,S.length]);let B=Z.useCallback(e=>{let t=m.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/PH),i=Math.min(N.current,NH);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),V=Z.useCallback(()=>{I.current=0,F.current!==null&&(window.clearInterval(F.current),F.current=null)},[]),H=Z.useCallback(()=>{let e=I.current;if(e===0){V();return}let t=N.current,n=Math.max(0,t-Math.min(t,NH)),r=Math.min(M.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){V();return}M.current=i,y(i);let a=P.current;if(a!==null){let e=B(a);e!==null&&_(Math.min(t-1,i+e))}},[B,V]),U=Z.useCallback(e=>{let t=m.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=FH&&D?i=-1:r>=n.height-FH&&O&&(i=1),I.current=i,i===0){V();return}F.current===null&&(F.current=window.setInterval(H,IH))},[H,D,O,V]);Z.useEffect(()=>()=>{F.current!==null&&window.clearInterval(F.current)},[]);let W=Z.useRef(null),ee=Z.useCallback(()=>{W.current!==null&&(window.clearTimeout(W.current),W.current=null)},[]),te=Z.useCallback(()=>{ee(),W.current=window.setTimeout(()=>{W.current=null,_(null)},HH)},[ee]);Z.useEffect(()=>()=>{W.current!==null&&window.clearTimeout(W.current)},[]);let ne=Z.useCallback(e=>{ee(),P.current=e.clientY;let t=B(e.clientY);t!==null&&_(Math.min(N.current-1,M.current+t)),U(e.clientY)},[ee,B,U]),re=Z.useCallback(()=>{P.current=null,V(),te()},[te,V]),G=Z.useCallback(()=>{p(!1)},[p]),ie=Z.useCallback(e=>{if(e===null)return;let t=S[e];t&&(o(t.turnId),V(),_(null),G(),m.current?.blur())},[G,o,S,V]),ae=Z.useCallback(e=>{let t=B(e.clientY);t!==null&&ie(Math.min(S.length-1,M.current+t))},[ie,S.length,B]);Z.useEffect(()=>{if(!f)return;let e=m.current;!e||e===document.activeElement||(e.focus(),_(e=>{if(e!==null)return e;let t=j>=0?j:S.length-1;return L(t),t}))},[j,L,f,S.length]),Z.useEffect(()=>()=>{p(!1)},[p]);let oe=Z.useCallback(e=>{if(S.length===0)return;let t=g??(j>=0?j:S.length-1),n=e=>{let t=Math.max(0,Math.min(S.length-1,e));L(t),_(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(S.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),ie(t);return}e.key===`Escape`&&(e.preventDefault(),_(null),G(),m.current?.blur())},[j,G,L,ie,g,S.length]),se=Z.useCallback(()=>{V(),_(null),G()},[G,V]),ce=Z.useRef(null),le=Z.useRef(g);le.current=g;let ue=g!==null,de=Z.useRef(0);Z.useEffect(()=>{let e=ce.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),de.current+=e.deltaY;let t=Math.trunc(de.current/VH);if(t===0)return;de.current-=t*VH;let n=le.current;if(n===null)return;let r=Math.max(0,Math.min(N.current-1,n+t));r!==n&&(L(r),_(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[L,ue]);let fe=g===null?void 0:S[g],pe=fe?a?.get(fe.turnId):void 0,me=Math.max(0,T-LH),he=Math.min(S.length,E+LH),ge=S.slice(me,he),_e=D||O?`linear-gradient(to bottom, ${D?`transparent, black 14%`:`black`}, ${O?`black 86%, transparent`:`black`})`:void 0;return S.length===0?null:(0,$.jsx)(`nav`,{ref:h,"aria-label":u(`chat.promptNavigator.aria`),className:`pointer-events-none absolute left-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-start`,children:[s?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-ml-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,c?`cursor-wait opacity-70`:void 0),"aria-label":A,title:A,disabled:c,onClick:e=>{e.stopPropagation(),c||l()},children:c?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:m,role:`listbox`,tabIndex:-1,"aria-activedescendant":fe?`prompt-rail-tick-${fe.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${b?jH:AH}px`,height:`${C*PH}px`},onMouseMove:ne,onMouseLeave:re,onClick:ae,onKeyDown:oe,onBlur:se,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:_e?{maskImage:_e,WebkitMaskImage:_e}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${T*PH}px)`},children:ge.map((e,t)=>{let n=me+t,r=d.has(e.turnId),i=g===n,a=GH(n,g,r);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":i,"aria-current":r?`true`:void 0,"aria-label":e.preview.trim()||k,className:`pointer-events-none absolute left-1 flex items-center justify-start`,style:{top:`${n*PH}px`,height:`${PH}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,r?`bg-[var(--surface-foreground)]`:i?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${a}px`}})},e.turnId)})},S[0]?.turnId)}),fe&&g!==null?(0,$.jsxs)(`div`,{ref:ce,className:Y(`pointer-events-auto absolute left-full z-30 ml-3 -translate-y-1/2`,`w-[min(20rem,calc(100vw-6rem))] overflow-hidden rounded-xl`,`bg-[var(--surface-elevated)] p-3 typography-meta`),style:{top:`${(g-T+.5)*PH}px`},onMouseEnter:ee,onMouseLeave:te,onMouseMove:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),ie(g)},children:[(0,$.jsx)(`p`,{className:`truncate font-medium leading-relaxed text-[var(--surface-foreground)]`,children:fe.preview||k}),pe?(0,$.jsx)(`p`,{className:`mt-2 line-clamp-4 whitespace-pre-line [overflow-wrap:anywhere] leading-relaxed text-[var(--surface-mutedForeground)]`,children:pe}):null]}):null]})]})})}var qH=100,JH=(e,t)=>{if(e.length===0)return;let n=0,r=e.length-1,i=0;for(;n<=r;){let a=n+r>>1,o=e[a]?.top;if(o===void 0)break;if(o<=t){i=a,n=a+1;continue}r=a-1}return e[i]?.id},YH=e=>{let t=e.raf??requestAnimationFrame,n=e.caf??cancelAnimationFrame,r=e.ResizeObserver??globalThis.ResizeObserver,i=e.MutationObserver??globalThis.MutationObserver,a,o,s,c,l,u,d=!0,f=new Map,p=[],m=()=>{c===void 0&&(c=t(()=>{c=void 0,g()}))},h=()=>{let e=a;if(!e){p=[],d=!1;return}let t=e.getBoundingClientRect().top;p=[...f].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),p.sort((e,t)=>e.top-t.top),d=!1},g=()=>{let t=a;if(!t)return;d&&h();let n=JH(p,t.scrollTop+qH);!n||n===u||(u=n,e.onActive(n))},_=()=>{let e=a;if(e){if(clearTimeout(l),l=void 0,o?.disconnect(),o=void 0,r){o=new r(()=>{clearTimeout(l),l=setTimeout(()=>{d=!0,m()},100)}),o.observe(e);for(let e of f.values())o.observe(e)}if(s?.disconnect(),s=void 0,i){s=new i(()=>{d=!0,m()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}d=!0,m()}},v=e=>{a!==e&&(a=e,u=void 0,_())},y=(e,t)=>{let n=f.get(t);n&&n!==e&&o?.unobserve(n),f.set(t,e),o&&o.observe(e),d=!0,m()},b=e=>{let t=f.get(e);t&&(o?.unobserve(t),f.delete(e),d=!0,m())},x=()=>{d=!0,m()},S=()=>{for(let e of f.values())o?.unobserve(e);f.clear(),p=[],u=void 0,d=!0};return{setContainer:v,register:y,unregister:b,onScroll:m,markDirty:x,clear:S,destroy:()=>{c!==void 0&&n(c),c=void 0,clearTimeout(l),l=void 0,S(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>u}},XH=10,ZH=`${XH}vh`,QH=`56px`;`${QH}`;var $H=(e,t)=>e?56:t<=0?96:Math.max(48,XH/100*t),eU=(e,t)=>({sessionId:e,viewportKey:t}),tU=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,nU=(e,t)=>tU(e,t),rU=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),iU=150,aU=1500,oU=2,sU=350,cU=600,lU=8e3,uU=24,dU=2,fU=(e,t)=>e<t,pU=()=>typeof performance<`u`?performance.now():Date.now(),mU=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),hU=e=>e.scrollHeight-e.scrollTop-e.clientHeight,gU=e=>hU(mU(e)),_U=e=>e.scrollHeight-e.clientHeight>1,vU=(e,t)=>hU(e)<=$H(t,e.clientHeight),yU=({enabled:e=!0,scrollControllerRef:t,currentSessionId:n,viewportKey:r,sessionMessageCount:i,sessionIsWorking:a,isMobile:o,onActiveTurnChange:s,onUpwardUserIntent:c})=>{let l=Z.useRef(null),[u,d]=Z.useState(null),f=Z.useRef(null),[p,m]=Z.useState(`following`),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(`following`),S=Z.useRef(o);S.current=o;let C=Z.useRef(i);C.current=i;let w=Z.useRef(eU(n,r));w.current=eU(n,r);let T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(null),O=Z.useRef(0),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(0),M=Z.useRef(!1),N=Z.useRef(!1),P=Z.useRef(null),F=Z.useRef(0),I=Z.useRef(!1),L=Z.useRef(null),R=Z.useRef(null),z=J(()=>{F.current=pU()+450,R.current=null}),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(0),ee=Z.useRef(!1),te=Z.useRef(null),ne=Z.useRef(null),re=Z.useRef(null),G=Ko(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{l.current!==f.current&&(f.current=l.current,d(l.current))});let ie=J(e=>{x.current!==e&&(x.current=e,m(e))}),ae=J(e=>{E.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:pU()},D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{E.current=null,D.current=null},aU)}),oe=J(e=>{let t=E.current;return t?pU()-t.time>aU?(E.current=null,!1):Math.abs(e.scrollTop-t.top)<oU:!1}),se=J(()=>pU()<j.current),ce=J(()=>{V.current=!1,H.current&&=(clearTimeout(H.current),null),U.current&&=(clearTimeout(U.current),null)}),le=J(()=>{H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,ce()},cU)}),ue=J(()=>{let e=l.current;e&&(V.current=!0,W.current=e.scrollHeight,le(),U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{U.current=null,ce()},lU))}),de=J(e=>{let t=l.current;if(!t){g(!1),v(!1);return}let n=e??mU(t),r=_U(n);if(g(r),!r){v(!1);return}let i=x.current===`released`&&!vU(n,S.current);v(i)}),fe=J(()=>{O.current+=1,k.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(k.current),k.current=null),A.current?.(),A.current=null});Z.useEffect(()=>()=>fe(),[u]);let pe=J(()=>{if(!e)return;let n=l.current;if(!n)return;if(fe(),t?.current?.scrollToBottom({behavior:`auto`,reveal:!1})){ae(n),de();return}let r=O.current,i=n.style.overflowX,a=n.style.overflowY,o=n.style.scrollBehavior;n.style.scrollBehavior=`auto`,n.style.overflow=`hidden`,n.scrollTop=n.scrollHeight,n.scrollHeight,n.style.overflowX=i,n.style.overflowY=a,n.style.scrollBehavior=o;let s=()=>{ae(n),n.scrollTop=n.scrollHeight,B.current=n.scrollTop};if(s(),de(),typeof window>`u`)return;let c=0,u=()=>{fU(pU(),F.current)||fe()};n.addEventListener(`touchstart`,u,{passive:!0,once:!0}),A.current=()=>n.removeEventListener(`touchstart`,u);let d=()=>{if(r===O.current){if(gU(n)>dU&&s(),c+=1,c>=uU){k.current=null,A.current?.(),A.current=null,de();return}k.current=window.requestAnimationFrame(d)}};k.current=window.requestAnimationFrame(d)}),me=J(e=>{let n=l.current;if(n&&(ae(n),!t?.current?.scrollToBottom({behavior:e,reveal:!1}))){if(e===`smooth`){n.scrollTo({top:n.scrollHeight,behavior:e});return}n.scrollTop=n.scrollHeight}}),he=J((t,n=`auto`)=>{if(!e)return;let r=l.current;if(t&&x.current!==`following`&&ie(`following`),r&&!(!t&&x.current!==`following`)){if(gU(r)<oU){ae(r);return}me(t?n:`auto`)}}),ge=J(e=>{let t=l.current;if(!t)return;let n=e??mU(t);_U(n)&&x.current!==`released`&&(ie(`released`),de(n))}),_e=J((e=`instant`,n)=>{if(I.current=!1,ee.current=!1,ie(`following`),ce(),fe(),t?.current?.scrollToBottom({behavior:e===`smooth`?`smooth`:`auto`,...n})){let e=l.current;e&&ae(e),de();return}if(e===`instant`){pe();return}fe(),he(!0,`smooth`),de()}),ve=J(()=>{ee.current=!1,he(!0)}),ye=J(()=>{I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ie(`released`),de()}),be=J(()=>{let t=yO(),n=l.current;if(!e||!n||!t||!n.contains(t.target)||!t.following||!t.range||R.current)return;let r=mU(n);if(!_U(r))return;let i=t.range.getBoundingClientRect?.();if(!i||!i.height)return;let a=n.getBoundingClientRect(),o=Math.min(96,n.clientHeight*.2),s=S.current?o:0;if(i.top>=a.top+s&&i.bottom<=a.bottom-s)return;let c=Math.min(r.scrollHeight-r.clientHeight,Math.max(0,r.scrollTop+i.top-a.top-o));Math.abs(c-r.scrollTop)<=1||(ye(),n.scrollTo({top:c,behavior:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`instant`:`smooth`}),B.current=n.scrollTop)});Z.useEffect(()=>(be(),xO(be)),[e,u,be]);let xe=J(()=>{ee.current=!0,ye()}),Se=J(()=>{ee.current=!1}),Ce=Z.useRef(c);Ce.current=c;let we=J(()=>{l.current&&CO(l.current),!fU(pU(),F.current)&&(I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ge())}),Te=J(()=>{F.current=0,we(),Ce.current?.()}),Ee=J(()=>{te.current!==null&&(clearTimeout(te.current),te.current=null);let e=ne.current;if(e){if(!e.identity.sessionId){ne.current=null;return}G(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),ne.current=null}}),De=J(()=>{let e=w.current;if(!e.sessionId)return;let t=l.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r>0?(n+i/2)/r:0,o=Math.floor(a*C.current);ne.current=rU(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),te.current===null&&(te.current=setTimeout(()=>{te.current=null,Ee()},iU))}),Oe=J(()=>{Ee()}),ke=J(async(e=w.current)=>{if(!e.sessionId||x.current===`released`&&tU(e,T.current))return!1;ee.current=!1;let t=l.current;return t?(re.current=null,ie(`following`),z(),S.current?pe():he(!0),B.current=t.scrollTop,ue(),de(),!1):(re.current=e,ie(`following`),!1)});Z.useEffect(()=>{let e=w.current,t=T.current;tU(e,t)||(Ee(),fe(),z(),T.current=e,I.current=!1,L.current=null,E.current=null,B.current=0,ce(),ee.current=!1,ie(`following`),re.current=null,n&&n!==t?.sessionId&&UO.getInstance().recordSessionStart(n))},[n,r]),Z.useEffect(()=>{a&&!ee.current&&x.current===`following`&&he(!0)},[a]),Z.useEffect(()=>{b(p===`following`&&a)},[p,a]),Z.useLayoutEffect(()=>{if(!u)return;let e=re.current;e&&nU(e,w.current)&&ke(e)},[u,n,r]);let Ae=J(()=>{let e=l.current;if(!e)return;let t=mU(e),n=B.current;B.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;de(t);let a=yO();if(a&&e.contains(a.target)){De();return}if(ee.current){De();return}if(_U(t)){if(vU(t,S.current)){let e=Math.min(n,Math.max(0,t.scrollHeight-t.clientHeight));if(t.scrollTop<e-.5){we(),De();return}(x.current===`following`||r&&I.current)&&(ie(`following`),I.current=!1),De();return}if(x.current===`following`&&(oe(e)||se()||i)){M.current||he(!1),De();return}(x.current===`following`||!r)&&we(),De()}});Z.useEffect(()=>{!e||!u||(B.current=u.scrollTop)},[u,e]);let je=J(e=>{let t=l.current;if(t){if(e.deltaY!==0&&CO(t),e.deltaY>0){Ol(t,e.target)||(I.current=!0);return}e.deltaY>=0||zl(t,e.target)||Te()}}),Me=J(e=>{I.current=!1;let t=e.touches.item(0);R.current=t?{x:t.clientX,y:t.clientY,dx:0,dy:0}:null}),Ne=J(e=>{let t=l.current,n=e.touches.item(0);if(!n){R.current=null;return}let r=R.current;if(!r)return;let i=n.clientY-r.y,a=i*r.dy<0,o=(a?0:r.dx)+n.clientX-r.x,s=(a?0:r.dy)+i;if(R.current={x:n.clientX,y:n.clientY,dx:o,dy:s},!(Math.abs(o)>=Math.abs(s))&&t){if(Math.abs(s)>2&&CO(t),s<-2){Ol(t,e.target)||(I.current=!0);return}if(!(s<=0)){if(zl(t,e.target)){R.current.dx=0,R.current.dy=0;return}s<=2||Te()}}}),Pe=J(()=>{R.current=null}),Fe=J(e=>{let t=e.target;if(!(e.defaultPrevented||t instanceof HTMLElement&&(t.isContentEditable||t.closest(`input, textarea, select`)))){if(l.current&&[`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `].includes(e.key)&&CO(l.current),!e.altKey&&!e.ctrlKey&&!e.metaKey&&[`ArrowDown`,`PageDown`,`End`].includes(e.key)){let e=l.current;e&&!Ol(e,t)&&(I.current=!0);return}Fl(e)&&Te()}}),Ie=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&(F.current=0,we(),L.current={id:e.pointerId,y:e.clientY})}),Le=J(e=>{let t=L.current;!t||t.id!==e.pointerId||(e.clientY!==t.y&&(I.current=e.clientY>t.y),t.y=e.clientY)}),Re=J(()=>{L.current=null}),ze=J(()=>{I.current=!1}),Be=Z.useMemo(()=>()=>void 0,[]),Ve=e&&u?u:Be,He=Z.useMemo(()=>({passive:!0}),[]);Wn(`scroll`,Ae,Ve,He),Wn(`scrollend`,ze,Ve,He),Wn(`wheel`,je,Ve,He),Wn(`touchstart`,Me,Ve,He),Wn(`touchmove`,Ne,Ve,He),Wn(`touchend`,Pe,Ve,He),Wn(`touchcancel`,Pe,Ve,He),Wn(`keydown`,Fe,Ve),Wn(`pointermove`,Le,e&&typeof window<`u`?window:Be,!0),Wn(`pointerup`,Re,e&&typeof window<`u`?window:Be,!0),Wn(`pointercancel`,Re,e&&typeof window<`u`?window:Be,!0),Wn(`pointerdown`,Ie,e&&typeof window<`u`?window:Be,!0);let Ue=J(()=>{let e=l.current;if(M.current){de(e?mU(e):void 0);return}if(ee.current){de(e?mU(e):void 0);return}if(!e){de(void 0);return}let t=mU(e);if(!_U(t)){de(t);return}if(de(t),V.current){let n=t.scrollHeight>W.current+1;W.current=t.scrollHeight,hU(t)<=oU?ae(e):he(!0),n&&le();return}if(x.current===`following`){if(hU(t)<=oU){ae(e);return}he(!1)}}),We=typeof ResizeObserver<`u`,Ge=We&&e?u:null,Ke=We&&e&&u&&u.firstElementChild instanceof Element?u.firstElementChild:null;qn(Ge,Ue),qn(Ke,Ue);let qe=J(()=>{P.current!==null&&(clearTimeout(P.current),P.current=null)}),Je=J(e=>{M.current=!0,typeof e==`number`&&e>0?j.current=pU()+e+sU:j.current=Math.max(j.current,pU()+sU)}),Ye=J(e=>{let t=e.detail;if(t){if(t.open===!0){Je(),qe(),P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},1500);return}qe(),Je()}}),Xe=J(e=>{let t=e.detail;t&&(qe(),Je(t.durationMs))}),Ze=J(e=>{let t=e.detail;qe(),t?.open===!0?(N.current=!0,M.current=!0):(N.current=!1,M.current=!0,P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},sU)),de()}),Qe=e&&typeof window<`u`?window:Be;Wn(`yuri:keyboard-intent`,Ye,Qe),Wn(`yuri:keyboard-anim`,Xe,Qe),Wn(`yuri:keyboard-settled`,Ze,Qe),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{qe(),M.current=!1,N.current=!1}},[e]),Z.useEffect(()=>{e&&de()},[e,i]);let $e=J(t=>{if(e){if(t===`animation`&&(j.current=pU()+sU),de(),V.current){he(!0),le();return}x.current===`following`&&he(!1)}}),et=Z.useRef(new Map),tt=J(t=>{let n=et.current.get(t);if(n)return n;let r=()=>{e&&x.current===`following`&&he(!1)},i={onChunk:r,onComplete:()=>{e&&de()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return et.current.set(t,i),i});Z.useEffect(()=>()=>{D.current&&=(clearTimeout(D.current),null),fe(),ce(),Ee(),te.current!==null&&(clearTimeout(te.current),te.current=null)},[]);let nt=J(e=>{s?.(e)}),rt=!!s;return Z.useEffect(()=>{if(!e||!rt)return;let t=u;if(!t)return;let n=null,r=YH({onActive:e=>{e!==n&&(n=e,nt(e))}});r.setContainer(t);let i=new Map,a=e=>{let t=e.dataset.turnId;return t?(i.set(t,e),r.register(e,t),!0):!1},o=e=>{let t=e.dataset.turnId;return!t||i.get(t)!==e?!1:(i.delete(t),r.unregister(t),!0)},s=e=>{if(!(e instanceof HTMLElement))return[];let t=[];return e.matches(`[data-turn-id]`)&&t.push(e),e.querySelectorAll(`[data-turn-id]`).forEach(e=>t.push(e)),t};t.querySelectorAll(`[data-turn-id]`).forEach(a),r.markDirty();let c=new MutationObserver(e=>{let t=!1;e.forEach(e=>{e.removedNodes.forEach(e=>{s(e).forEach(e=>{o(e)&&(t=!0)})}),e.addedNodes.forEach(e=>{s(e).forEach(e=>{a(e)&&(t=!0)})})}),t&&r.markDirty()});c.observe(t,{subtree:!0,childList:!0});let l=()=>r.onScroll();return t.addEventListener(`scroll`,l,{passive:!0}),()=>{t.removeEventListener(`scroll`,l),c.disconnect(),r.destroy()}},[u,e,rt]),{scrollRef:l,state:p,isPinned:p===`following`,isOverflowing:h,isFollowingProgrammatically:y,showScrollButton:_,notifyContentChange:$e,getAnimationHandlers:tt,goToBottom:_e,scrollToBottomOnSend:ve,releaseAutoFollow:ye,beginHistoryViewportPreservation:xe,endHistoryViewportPreservation:Se,saveSnapshotNow:Oe,restoreSnapshot:ke}},bU=`--yuri-mobile-header-collapse`,xU=e=>e.closest(`.mobile-chat-screen`)?.querySelector(`:scope > [data-yuri-collapsible-header="true"]`)??null,SU=e=>{e.style.removeProperty(bU),delete e.dataset.yuriHeaderCollapsePhase,delete e.dataset.yuriHeaderCollapseRest},CU=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest===`compact`?`collapsed`:`expanded`;return n?.phase!==i&&(e.dataset.yuriHeaderCollapsePhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty(bU,r),n?.rest!==a&&(e.dataset.yuriHeaderCollapseRest=a),{progress:r,phase:i,rest:a}},wU=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),TU=`data-yuri-timeline-park-end`,EU=e=>{if(!e)return null;let t=e.getAttribute(TU);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},DU=(e,t)=>t!==null&&Number.isFinite(t)?wU({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),OU=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),kU=()=>{let e=document.documentElement;return e.classList.contains(`yuri-keyboard-open`)||e.classList.contains(`yuri-kb-animating`)},AU=e=>{if(kU()||e.querySelector(`[data-yuri-composer-dictation-active="true"]`)||e.querySelector(`[data-composer-height-snap="full"], [data-mobile-composer-resizing="true"]`))return!0;let t=document.activeElement;return t instanceof HTMLElement&&t.matches(`textarea[data-chat-input="true"]`)&&e.contains(t)},jU=e=>{let t=Z.useRef(fE()),n=Z.useRef(void 0),r=Z.useRef(void 0),i=Z.useRef(null),a=Z.useRef(null),o=Z.useRef(0),s=Z.useRef(!1),c=Z.useRef(0),l=Z.useRef(new Map),u=Z.useRef(!1),d=Z.useRef(0),f=Z.useRef(null),p=Z.useRef(null),m=Z.useRef({direction:null,px:0,at:0}),h=Z.useRef(e.enabled);h.current=e.enabled;let g=e=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null)},_=Z.useRef(null),v=e=>{let t=_.current;if(t&&t!==e&&t.parentElement===e)return t;let i=AE(e);return i!==t&&(_.current=i,n.current=void 0,r.current=void 0),i},y=Z.useRef(null),b=Z.useRef(void 0),x=(e,t)=>{let n=y.current;(!n||!n.isConnected)&&(n=xU(e),y.current=n,b.current=void 0),n&&(b.current=CU(n,t,b.current))},S=J(t=>{let r=e.scopeRef.current;if(!r)return;let i=v(r);n.current=NE(r,t,n.current,i),x(r,t)}),C=J(e=>{let n=_.current,r=v(e);return r===n?x(e,t.current):S(t.current),r}),w=J(e=>{e!==t.current&&(t.current=e,S(e))}),T=J(()=>{if(g(a),t.current.phase!==`snapping`)return;let e=t.current.rest;a.current=window.setTimeout(()=>{a.current=null;let n=wE(t.current);w(n),n.rest===`compact`&&e===`compact`&&(o.current=Date.now()+320,s.current=!0)},240)}),E=J(()=>{let n=e.scopeRef.current;!n||!h.current||w(gE(t.current,AU(n)))}),D=J(e=>s.current?Date.now()>=o.current?(s.current=!1,!1):e>=80?(s.current=!1,o.current=0,!1):!0:!1),O=()=>{m.current={direction:null,px:0,at:0}},k=()=>{let e=m.current;return!e.direction||e.px<16||e.direction===`expanded`&&(f.current??0)>=120||Date.now()-e.at>250?null:e.direction},A=J(()=>{if(g(i),!h.current||c.current>0||t.current.phase!==`tracking`)return;let e=CE(t.current,k());w(e),T()}),j=J(()=>{u.current=!1,d.current=0;for(let e of l.current.values())e.startX=e.currentX,e.startY=e.currentY}),M=J(e=>{if(!h.current)return;let t=!1;for(let n=0;n<e.changedTouches.length;n+=1){let r=e.changedTouches[n];if(!r)continue;let i=l.current.get(r.identifier);if(!i){l.current.set(r.identifier,{startX:r.clientX,startY:r.clientY,currentX:r.clientX,currentY:r.clientY});continue}i.currentX=r.clientX,i.currentY=r.clientY;let a=Math.abs(i.currentX-i.startX),o=Math.abs(i.currentY-i.startY);o>=6&&o>a&&(t=!0)}!t&&!u.current||(u.current=!0,d.current=Date.now(),s.current=!1,o.current=0)}),N=J(t=>{if(h.current){if(c.current===0){l.current.clear(),j(),O();let t=e.scrollRef.current;if(t){let e=OU(t);p.current=e,f.current=DU(e,EU(t))}}for(let e=0;e<t.changedTouches.length;e+=1){let n=t.changedTouches[e];n&&l.current.set(n.identifier,{startX:n.clientX,startY:n.clientY,currentX:n.clientX,currentY:n.clientY})}c.current=l.current.size,g(i)}}),P=J(()=>{if(!h.current)return;let n=e.scrollRef.current,o=e.scopeRef.current;if(!n||!o)return;let s=AU(o),l=OU(n),_=DU(l,EU(n)),v=f.current,y=p.current;if(f.current=_,p.current=l,n.hasAttribute(`data-yuri-timeline-anchoring`)){O(),j();return}let b=C(o);r.current=ME(o,_,r.current,b);let x=u.current&&(c.current>0||Date.now()-d.current<=1200),S=y!==null&&(y.scrollHeight!==l.scrollHeight||y.clientHeight!==l.clientHeight),E=x&&!S,k=l.scrollTop<0||y!==null&&y.scrollTop<0,M=E&&!k&&v!==null;if(!M)O();else if(_!==v){let e=_>v?`compact`:`expanded`,t=m.current,n=Math.abs(_-v);m.current={direction:e,px:t.direction===e?t.px+n:n,at:Date.now()}}let N=t.current,P=gE(N,s);if(s||(P=xE(P,_,{previousDistance:M?v:null,suppressReturn:E&&D(_),userDriven:E})),w(P),E){if(g(i),P.phase===`snapping`){(N.phase!==`snapping`||N.rest!==P.rest||N.progress!==P.progress)&&T();return}N.phase===`snapping`&&g(a),P.phase===`tracking`&&c.current===0&&(i.current=window.setTimeout(()=>{i.current=null,A()},120))}}),F=J(()=>{u.current&&(c.current>0||Date.now()-d.current<=1200)&&A()}),I=J((e,n)=>{if(h.current){for(let t=0;t<e.changedTouches.length;t+=1){let n=e.changedTouches[t];n&&l.current.delete(n.identifier)}c.current=l.current.size,!(c.current>0)&&(l.current.clear(),n&&u.current?d.current=Date.now():j(),t.current.phase===`tracking`&&(g(i),i.current=window.setTimeout(()=>{i.current=null,A()},120)))}}),L=J(e=>{I(e,!0)}),R=J(e=>{I(e,!1)}),z=J(()=>{let t=e.scopeRef.current;if(!t||typeof window>`u`)return;let n=e=>{e.preventDefault(),e.stopPropagation()};t.addEventListener(`pointerup`,n,!0),t.addEventListener(`click`,n,!0),window.setTimeout(()=>{t.removeEventListener(`pointerup`,n,!0),t.removeEventListener(`click`,n,!0)},240)}),B=J(n=>{if(!h.current)return;let r=n.target;if(!(r instanceof Element)||!r.closest(`[data-yuri-composer-compact-surface="true"]`)||r.closest(`[data-composer-action="true"]`))return;let i=r.closest(`.yuri-mobile-composer-compact-preview`);n.type===`pointerdown`&&i||n.type===`click`&&!i||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),O(),w(_E(t.current,`expanded`)),T(),z(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0}))}),[V,H]=Z.useState(null),[U,W]=Z.useState(null),ee=Z.useRef(null),te=J(e=>{e&&jE(e,_.current??e),y.current&&SU(y.current),y.current=null,b.current=void 0,_.current=null,n.current=void 0,r.current=void 0,s.current=!1,o.current=0,c.current=0,l.current.clear(),u.current=!1,d.current=0,f.current=null,p.current=null,O(),w(fE())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;ee.current&&ee.current!==n&&te(ee.current),ee.current=n,n&&C(n),H(e=>e===t?e:t),W(e=>e===n?e:n)});let ne=Z.useMemo(()=>()=>void 0,[]),re=e.enabled&&V?V:ne,G=e.enabled&&U?U:ne,ie=e.enabled&&typeof window<`u`?window:ne,ae=Z.useMemo(()=>({passive:!0}),[]);Wn(`scroll`,P,re,ae),Wn(`scrollend`,F,re,ae),Wn(`touchstart`,N,re,ae),Wn(`touchmove`,M,re,ae),Wn(`touchend`,L,re,ae),Wn(`touchcancel`,R,re,ae),Wn(`pointerdown`,B,G),Wn(`click`,B,G),Wn(`focusin`,E,G),Wn(`focusout`,E,G),Wn(`yuri:keyboard-intent`,E,ie),Wn(`yuri:keyboard-anim`,E,ie),Wn(`yuri:keyboard-settled`,E,ie),Z.useEffect(()=>{if(!e.enabled){te(ee.current),ee.current=null;return}return E(),P(),()=>{g(i),g(a)}},[e.enabled,V,U])},MU=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},NU=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},PU=e=>{if(!e)return null;let t=MU(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${NU(e)??``}`},FU=e=>({turnIds:[...e.turnIds],turnMessageStartIndexes:[...e.turnMessageStartIndexes],turnIndexById:new Map(e.turnIndexById),messageToTurnId:new Map(e.messageToTurnId),messageToTurnIndex:new Map(e.messageToTurnIndex),turnCount:e.turnCount}),IU=(e,t,n)=>{if(!e||!t)return null;if(t.length===n.length){let r=-1;for(let e=0;e<n.length;e+=1)if(t[e]!==n[e]){if(r!==-1)return null;r=e}return r===-1||r===n.length-1&&PU(t[r])===PU(n[r])?e:null}if(n.length!==t.length+1)return null;for(let e=0;e<t.length;e+=1)if(t[e]!==n[e])return null;let r=n[n.length-1];if(!r)return null;let i=MU(r),a=r.info.id,o=FU(e);if(i===`user`){let e=o.turnIds.length;return o.turnIds.push(a),o.turnMessageStartIndexes.push(n.length-1),o.turnIndexById.set(a,e),o.messageToTurnId.set(a,a),o.messageToTurnIndex.set(a,e),o.turnCount=o.turnIds.length,o}if(i!==`assistant`){let e=o.turnIds.length-1;if(e<0)return null;let t=o.turnIds[e];return t?(o.messageToTurnId.set(a,t),o.messageToTurnIndex.set(a,e),o):null}let s=NU(r);if(!s)return o;let c=o.turnIndexById.get(s);if(typeof c!=`number`||c<0)return null;let l=o.turnIds[c];return l?(o.messageToTurnId.set(a,l),o.messageToTurnIndex.set(a,c),o):null},LU=e=>{let t=[],n=[],r=new Map,i=new Map,a=new Map,o=new Map,s=-1;return e.forEach((e,c)=>{let l=MU(e),u=e.info.id;if(l===`user`){s=t.length,t.push(u),n.push(c),r.set(u,s),o.set(u,s),i.set(u,u),a.set(u,s);return}if(l!==`assistant`){if(s>=0){let e=t[s];e&&(i.set(u,e),a.set(u,s))}return}let d=NU(e);if(!d)return;let f=o.get(d);if(typeof f!=`number`||f<0)return;let p=t[f];p&&(i.set(u,p),a.set(u,f))}),{turnIds:t,turnMessageStartIndexes:n,turnIndexById:r,messageToTurnId:i,messageToTurnIndex:a,turnCount:t.length}},RU=200,zU={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},BU=()=>RU,VU=()=>Math.round(BU()*.6),HU={MAX_SESSIONS:zU.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(RU*.6),HISTORICAL_MESSAGES:RU,FETCH_BUFFER:20,HISTORY_CHUNK:RU,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:zU.ZOMBIE_TIMEOUT},UU=()=>{let e=BU(),t=VU();return{...HU,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},WU=HU,GU=600,KU=6e3,qU=.5,JU=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),YU=e=>{let t=e.getBoundingClientRect(),n=e.querySelectorAll(`[data-message-id]`);for(let e of n)if(e.getBoundingClientRect().bottom>t.top)return e;return null},XU=(e,t)=>{let n=JU(e,t);if(n||=YU(e),!n)return null;let r=n.dataset.messageId;if(!r)return null;let i=e.getBoundingClientRect();return{messageId:r,offsetTop:n.getBoundingClientRect().top-i.top}},ZU=e=>{let{container:t,quiesceMs:n=GU,maxLifetimeMs:r=KU}=e,i={messageId:e.anchor.messageId,offsetTop:e.anchor.offsetTop},a=!1,o=e.pending??!1,s=null,c=null,l=!1,u=!1,d=t.scrollTop,f=()=>{s!==null&&(clearTimeout(s),s=null)},p=()=>{c!==null&&(clearTimeout(c),c=null)},m=()=>{a||(a=!0,x.disconnect(),t.removeEventListener(`scroll`,b),f(),p())},h=()=>{f(),!(a||o)&&(s=setTimeout(()=>{s=null,m()},n))},g=()=>{p(),!(a||o)&&(c=setTimeout(()=>{c=null,m()},r))},_=()=>{if(a)return;let e=XU(t,i.messageId);if(!e){m();return}i.messageId=e.messageId,i.offsetTop=e.offsetTop,d=t.scrollTop,u=!1},v=()=>{if(a)return;if(e.isUserScrolling?.()){u=!0;return}if(u){_();return}if(Math.abs(t.scrollTop-d)>qU){_();return}let n=JU(t,i.messageId);if(!n){let e=YU(t);if(!e){m();return}let r=e.dataset.messageId;if(!r){m();return}let a=t.getBoundingClientRect();i.messageId=r,i.offsetTop=e.getBoundingClientRect().top-a.top,n=e,d=t.scrollTop}let r=t.getBoundingClientRect(),o=n.getBoundingClientRect().top-r.top-i.offsetTop;Math.abs(o)>qU&&(t.scrollTop+=o),d=t.scrollTop},y=()=>{a||l||(l=!0,queueMicrotask(()=>{l=!1,v()}))},b=()=>{e.isUserScrolling?.()?u=!0:(u||Math.abs(t.scrollTop-d)>qU)&&_(),h(),g()},x=new MutationObserver(()=>{a||(y(),h())});return x.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`style`,`class`]}),t.addEventListener(`scroll`,b,{passive:!0}),g(),h(),{rebase:_,dispose:m,settle(){a||!o||(o=!1,h(),g())}}},QU=30,$U=1200,eW=1.5,tW=e=>Math.max($U,e*eW),nW=4,rW=30,iW=4,aW=30,oW=250,sW=800,cW=1e4,lW=1500,uW=2e3,dW=dr+2e3,fW=40,pW=`history-loading-timeout`,mW=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),hW=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=pW,e},gW=(e,t,n)=>{if(e===`no-growth`){console.error(`[chat-history] load older completed without prepending messages`,t instanceof Error?t:Error(`chat history pagination returned no growth`),n);return}if(e===`timeout`){console.error(`[chat-history] load older timed out waiting for sync pagination`,t,n);return}console.error(`[chat-history] load older failed`,t,n)},_W=2500,vW=new Map,yW=()=>b()?nW:Po()?iW:QU,bW=e=>b()?e.length<=rW:!Po()||e.length<=aW,xW=(e,t)=>{if(vW.delete(e),!bW(t.messages))return;let n=yW();for(;vW.size>=n;){let e=vW.keys().next().value;if(typeof e!=`string`)break;vW.delete(e)}vW.set(e,t)},SW=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),CW=e=>e?{owner:`tanstack-core`}:{owner:`controller`},wW=(e,t)=>e?e.canLoadEarlier:t>=UU().HISTORICAL_MESSAGES,TW=e=>!(e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=tW(e.clientHeight)),EW=e=>e.hasMoreAbove?e.scrollHeightAfter-e.scrollHeightBefore>1?`stop-visible`:e.messageCountAfter>e.messageCountBefore||typeof e.oldestIdBefore==`string`&&typeof e.oldestIdAfter==`string`&&e.oldestIdBefore!==e.oldestIdAfter||e.cursorBefore==null&&e.limitAfter>e.limitBefore||typeof e.cursorAfter==`string`&&e.cursorAfter!==e.cursorBefore?e.pagesLoaded>=e.maxPages?`stop-bounded`:`continue`:`stop-no-growth`:`stop-exhausted`,DW=8,OW=1,kW=8,AW=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],jW=80,MW=new WeakMap,NW=e=>{let t=e?MW.get(e):void 0;return!!(t&&(t.touches>0||performance.now()-t.lastScrollAt<160))},PW=e=>{let t=MW.get(e);t&&(t.touches=0,t.lastScrollAt=-1/0,t.pending=null,t.settleScheduled=!1)},FW=e=>{IW(e)},IW=e=>{let t=MW.get(e);if(t)return t;let n={touches:0,lastScrollAt:-1/0,pending:null,settleScheduled:!1};e.addEventListener(`touchstart`,()=>{n.touches+=1},{passive:!0});let r=()=>{n.touches=Math.max(0,n.touches-1),n.touches===0&&n.pending&&LW(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),e.addEventListener(`scroll`,()=>{n.lastScrollAt=performance.now()},{passive:!0}),MW.set(e,n),n},LW=(e,t)=>{t.settleScheduled||typeof window>`u`||(t.settleScheduled=!0,window.requestAnimationFrame(()=>{t.settleScheduled=!1;let n=t.pending;t.pending=null,!(!n||t.touches>0||!e.isConnected)&&(Math.abs(e.scrollTop-n.anchorTop)>n.delta+jW||RW(e,n.anchorTop+n.delta))}))},RW=(e,t)=>{let n=e.style.overflowX,r=e.style.overflowY;e.style.overflow=`hidden`,e.scrollTop=t,e.scrollHeight,e.style.overflowX=n,e.style.overflowY=r,e.scrollTop=t},zW=(e,t,n)=>{let r=IW(e);if(r.touches>0&&typeof n==`number`&&n>0){r.pending=r.pending?{anchorTop:r.pending.anchorTop,delta:r.pending.delta+n}:{anchorTop:e.scrollTop,delta:n};return}r.pending=null,RW(e,t)},BW=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),VW=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:a,loadMoreMessages:o,goToBottom:s,releaseAutoFollow:l,beginHistoryViewportPreservation:d,endHistoryViewportPreservation:f,isPinned:p,showScrollButton:m,isMobile:h,onWillLoadEarlier:g})=>{let _=Z.useRef(h);_.current=h;let v=Z.useRef(null),y=Z.useRef(null),b=Z.useMemo(()=>{let t=e??``,r=t?vW.get(t):void 0;if(r&&r.messages===n)return xW(t,r),v.current=r.model,y.current=n,r.model;let i=IU(v.current,y.current,n)??LU(n);return v.current=i,y.current=n,t&&n.length>0&&xW(t,{messages:n,model:i}),i},[n,e]),[x,S]=Z.useState(!1),[C,w]=Z.useState(!1),[T,E]=Z.useState(null),D=Z.useRef(0),O=u(),k=c(),A=Z.useMemo(()=>({runtimeKey:O,runtimeGeneration:k,sessionId:e,directory:t}),[O,k,e,t]),j=Z.useRef(A);j.current=A;let M=`chat-history-error:${JSON.stringify([O,t??null,e])}`;Jn(()=>(j.current=A,()=>{j.current===A&&(j.current=null),Yr.dismiss(M)}),[A,M]);let N=Z.useRef(b),P=Z.useRef(p),F=Z.useRef(x),I=Z.useRef(C),L=Z.useRef(e),R=Z.useRef(t??null),z=Z.useRef(n),B=Z.useRef(r),V=Z.useRef([]),H=Z.useRef(!1),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),te=Z.useRef(!1),ne=Z.useRef(null),re=Z.useRef({authorized:!1,consumed:!1,top:0}),G=Z.useRef(null),ie=J(()=>{re.current={authorized:!1,consumed:F.current,top:i.current?.scrollTop??0}}),ae=()=>h?i.current??void 0:void 0,se=J(e=>{e.repeat||ie()});Wn(`touchstart`,ie,ae,{passive:!0,capture:!0}),Wn(`wheel`,ie,ae,{passive:!0,capture:!0}),Wn(`keydown`,se,ae,{capture:!0});let[ce,le]=Z.useState(A);ce!==A&&(le(A),ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),te.current=!1,F.current=!1,ee.current=null,S(!1),w(!1),E(null),D.current=0,re.current={authorized:!1,consumed:!1,top:0},G.current=null);let ue=Z.useMemo(()=>{let e=wW(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),de=Z.useRef(ue);N.current=b,P.current=p,I.current=C,de.current=ue,L.current=e,R.current=t??null,z.current=n,B.current=r,Jn(()=>{r?.complete&&Yr.dismiss(M)},[r?.complete,M]);let fe=J(()=>{te.current=!0,ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null)}),pe=J(()=>{if(typeof window>`u`){te.current=!1;return}ne.current!==null&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>{ne.current=null,te.current=!1},uW)}),me=J(()=>{let e=V.current;e.length!==0&&(V.current=[],e.forEach(e=>e()))}),he=J((e=!1)=>new Promise(t=>{if(typeof window>`u`){t();return}let n=!1,r=j.current,i=Date.now()+cW,a=()=>{n||(n=!0,window.clearTimeout(s),V.current=V.current.filter(e=>e!==a),t())},o=()=>{if(e&&r===j.current&&H.current&&Date.now()<i){s=window.setTimeout(o,i-Date.now());return}a()};V.current.push(a);let s=window.setTimeout(o,oW)})),ge=J(e=>{let t=W.current;t&&(W.current=null,t.resolve(e))}),_e=J(()=>{let e=W.current;if(e){if(e.sessionId!==L.current){ge(!1);return}if(e.kind===`turn`?a.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:a.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(ee.current={turnId:e.turnId,expiresAt:Date.now()+_W},E(e.turnId)),ge(!0);return}typeof(e.kind===`turn`?N.current.turnIndexById.get(e.id):N.current.messageToTurnIndex.get(e.id))==`number`&&ge(!1)}}),ve=Z.useRef(null),ye=J(()=>{let e=ve.current;e&&(ve.current=null,e.dispose())});Un(()=>{ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),ye(),me(),ge(!1)});let be=Z.useRef({scope:A,at:-1/0}),xe=()=>{!h&&!Po()&&(be.current={scope:A,at:Date.now()})};Wn(`wheel`,e=>{e.deltaY!==0&&e.target instanceof Node&&i.current?.contains(e.target)&&xe()},void 0,{passive:!0,capture:!0}),Wn(`scroll`,e=>{e.target===i.current&&xe()},void 0,{passive:!0,capture:!0});let Se=()=>be.current.scope===A&&Date.now()-be.current.at<sW,[Ce,we]=Z.useState({scope:A,messages:n}),Te=Po(),Ee=Ce.scope===A&&Ce.messages!==n&&BW(Ce.messages[0]?.info?.id??null,n[0]?.info?.id??null,n)&&(Te?!a.current?.isHistoryVirtualized()&&NW(i.current):!h&&Ce.messages.at(-1)===n.at(-1)&&Se()),De=Ee?Ce.messages:n;H.current=Ee&&!h&&!Te,(Ce.scope!==A||Ce.messages!==De)&&we({scope:A,messages:De});let[,Oe]=Z.useReducer(e=>e+1,0);Jn(()=>{me(),_e()},[De]);let ke=Z.useRef(null),Ae=J(()=>a.current?.captureViewportAnchor()??null),je=J(e=>a.current?.restoreViewportAnchor(e)??!1),Me=J(()=>{if(ye(),a.current?.isHistoryVirtualized())return;let e=i.current;if(!e)return;let t=Ae();if(t)return ve.current=ZU({container:e,anchor:t,pending:!0,isUserScrolling:Po()?()=>NW(e):void 0}),ve.current}),Ne=Z.useRef(null);Kn(J(()=>{let e=i.current;if(!e||!Ee||!Te&&Se())return;let t=e.scrollHeight;Ne.current={oldestId:De[0]?.info?.id??null,newestId:De.at(-1)?.info?.id??null,scrollHeight:t};let n=ke.current;if(n){let r={...n,height:t,top:e.scrollTop,anchor:Ae()};ke.current=Te?r:Object.assign(n,r)}Oe()}),Ee?50:null);let Pe=Z.useRef(null);Jn(()=>{if(!Po())return;let e=i.current;if(!e){Pe.current=null;return}let t=Pe.current;(t?.container!==e||t.scope!==A)&&(FW(e),PW(e),Pe.current={container:e,scope:A})}),Jn(()=>{ye(),U.current=null,me(),ke.current=null,Ne.current=null,a.current?.cancelViewportAnchorHold()},[A]),Jn(()=>{let e=i.current;if(!e)return;let t=ke.current;a.current?.isHistoryVirtualized()&&ye(),t&&Math.abs(e.scrollTop-t.top)>kW&&(ke.current=null,t=null);let n=Ne.current,r=De[0]?.info?.id??null,o=De[De.length-1]?.info?.id??null,c=n?SW({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:o})||BW(n.oldestId,r,De):!1;t&&t.sessionId!==L.current&&(ke.current=null,t=null);let l=t?SW({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:o})||BW(t.oldestId,r,De):!1,u=c||l,d=e=>{Ne.current={oldestId:r,newestId:o,scrollHeight:e??Ne.current?.scrollHeight??null}};if(P.current&&!t){ye(),u?(ke.current=null,s(`instant`,{reveal:!1}),d(e.scrollHeight)):d();return}let f=CW(a.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){a.current?.cancelViewportAnchorHold();let e=t.anchor;e&&je(e),d();return}let n=e.scrollHeight,r=n-t.height;if(Po()){r>0&&zW(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&je(i))&&r>0&&(e.scrollTop=t.top+r),ve.current?.rebase(),d(n);return}if(c&&n&&f.owner===`controller`){let t=e.scrollHeight,r=n.scrollHeight===null?0:t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;Po()?zW(e,t,r):e.scrollTop=t}d(t),Me();return}d()},[De,s]),Jn(()=>{if(H.current)return;let e=U.current;U.current=null,e?.()},[De]);let Fe=J(async()=>!1),Ie=J(async e=>{let t=j.current,n=()=>t===j.current&&t?.runtimeKey===u()&&t?.runtimeGeneration===c(),r=Date.now(),i=r+dW,a=R.current,o=a?Ve()?.getRequestState?.(oe(a,e)):void 0;for(de.current.historyLoading,B.current,o?.status,o?.error;de.current.historyLoading;){if(!n()||L.current!==e)return Date.now()-r,`switched`;if(Date.now()>=i){let t=a?Ve()?.getRequestState?.(oe(a,e)):void 0;return console.error(`[chat-history] historyLoading wait timed out — sync flag still true`,{sessionId:e,directory:a,elapsedMs:Date.now()-r,waitMs:dW,hostTurnPageTimeoutMs:dr,historyLoading:de.current.historyLoading,historyMeta:B.current,requestStatusAtStart:o?.status??null,requestStatusAtTimeout:t?.status??null,requestErrorAtTimeout:t?.error??null,likelyStaleLoadingFlag:t?.status===`ready`||t?.status===`error`||t==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,fW)})}return Date.now()-r,a&&Ve()?.getRequestState?.(oe(a,e))?.status,n()&&L.current===e?`cleared`:`switched`}),Le=J(async e=>{if(!L.current||F.current||H.current||!de.current.hasMoreAboveTurns)return!1;F.current=!0,fe(),S(!0);let t=L.current,n=j.current,r=()=>n===j.current&&n?.runtimeKey===u()&&n?.runtimeGeneration===c(),s=()=>n?.directory?Ve()?.getPagination(oe(n.directory,t)).cursor??null:null,l=M,p=null,m=null,h=!!e.userInitiated;h&&d();let g=()=>{if(r()){if(H.current){U.current=g;return}m?.settle(),p&&ke.current===p&&(ke.current=null,a.current?.cancelViewportAnchorHold()),h&&(h=!1,f())}};try{if(de.current.historyLoading){if(!e.userInitiated)return!1;let n=await Ie(t);if(n===`timeout`)throw hW();if(n===`switched`||!de.current.hasMoreAboveTurns)return!1}if(!r()||!L.current||L.current!==t)return!1;let n=i.current,a=z.current,c=a.length,u=a[0]?.info?.id??null,d=B.current?.limit??UU().HISTORICAL_MESSAGES;e.preserveViewport&&n&&(p={sessionId:L.current,height:n.scrollHeight,top:n.scrollTop,anchor:Ae(),oldestId:u,newestId:a[a.length-1]?.info?.id??null},ke.current=p,Ne.current={oldestId:p.oldestId,newestId:p.newestId,scrollHeight:p.height},m=Me()??null);let f=c,h=u,_=d,v=0,y=0;for(;;){if(de.current.historyLoading)if(e.userInitiated){let e=await Ie(t);if(e===`timeout`)throw g(),hW();if(e===`switched`)return g(),!1}else return g(),!1;let n=i.current?.scrollHeight??0,a=f,c=h,u=_,d=s();if(await o(t,`up`),v+=1,!r()||L.current!==t)return g(),!1;if(await he(!0),!r())return!1;if(H.current)return!0;let p=(()=>{let t=z.current;return EW({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:a,messageCountAfter:t.length,oldestIdBefore:c,oldestIdAfter:t[0]?.info?.id??null,limitBefore:u,limitAfter:B.current?.limit??_,cursorBefore:d,cursorAfter:s(),hasMoreAbove:de.current.hasMoreAboveTurns,pagesLoaded:v,maxPages:e.singlePage?1:DW})})();if(p===`continue`){let e=z.current;f=e.length,h=e[0]?.info?.id??null,_=B.current?.limit??_;continue}if(p===`stop-no-growth`){if(e.singlePage)return g(),!1;if(de.current.historyLoading){if(e.userInitiated){let e=await Ie(t);if(e===`timeout`)throw g(),hW();if(e===`switched`)return g(),!1;--v;continue}return g(),!1}if(y<OW){y+=1,--v;continue}return D.current=Date.now()+lW,g(),!1}return D.current=0,Yr.dismiss(l),!0}}catch(e){throw r()&&(D.current=Date.now()+lW),g(),e}finally{r()&&(F.current=!1,S(!1),pe(),H.current?g():he(!0).then(g))}}),{t:Re}=Xn(),ze=q({mutationKey:AW({runtimeKey:u(),sessionId:e??``}),mutationFn:async e=>{if(j.current!==e.scope||u()!==e.scope.runtimeKey||c()!==e.scope.runtimeGeneration||L.current!==e.sessionId)return!1;fe(),e.userInitiated&&l();try{return await Le({preserveViewport:!0,userInitiated:!!e.userInitiated,singlePage:e.singlePage})}finally{j.current===e.scope&&c()===e.scope.runtimeGeneration&&pe()}}}),Be=J(async e=>{let t=L.current;if(!t||!de.current.canLoadEarlier)return;let n=A,r=M,i=()=>j.current===n&&u()===n.runtimeKey&&c()===n.runtimeGeneration;if(!(ze.isPending&&ze.variables?.sessionId===t&&ze.variables?.scope===n)){e?.userInitiated&&g?.();try{let r=await ze.mutateAsync({sessionId:t,scope:n,userInitiated:!!e?.userInitiated,singlePage:e?.singlePage});if(!i())return;if(r===!1&&de.current.canLoadEarlier){let n={sessionId:t,grew:r,userInitiated:!!e?.userInitiated,canLoadEarlier:de.current.canLoadEarlier,hasMoreAboveTurns:de.current.hasMoreAboveTurns,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};gW(`no-growth`,Error(`chat history pagination returned no growth`),n)}}catch(n){let a={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:dW,hostTurnPageTimeoutMs:dr,canLoadEarlier:de.current.canLoadEarlier,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};mW(n)?gW(`timeout`,n,a):gW(`failed`,n,a),i()&&e?.userInitiated&&Yr.error(mW(n)?Re(`chat.history.loadOlderTimeout`):Re(`chat.history.loadOlderFailed`),{id:r})}}}),He=ze.isPending&&ze.variables?.sessionId===e&&ze.variables?.scope===A||x,Ue=J(e=>{if(Date.now()<D.current)return;let t=i.current;if(t){if(_.current){let n=re.current,r=t.scrollTop<n.top;if(n.top=t.scrollTop,n.consumed||(e===`upward-intent`&&(n.authorized=!0),!n.authorized||e===`scroll`&&!r))return}else if(F.current){G.current=null;return}else if(e===`upward-intent`)G.current={top:t.scrollTop};else{let e=G.current;if(!e)return;let n=t.scrollTop<e.top;if(t.scrollTop>e.top||P.current?G.current=null:e.top=t.scrollTop,!n)return}TW({source:e,isMobile:_.current,isPinned:P.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:de.current.canLoadEarlier,isLoadingOlder:F.current,pendingRevealWork:I.current})&&(_.current&&(re.current.consumed=!0),G.current=null,Be({userInitiated:!0,singlePage:_.current}))}}),We=J(()=>{Ue(`scroll`)}),Ge=J(()=>{!_.current&&!F.current&&!a.current?.isHistoryVirtualized()&&Me()?.settle(),Ue(`upward-intent`)}),Ke=J(async(t,n)=>{if(!t||!L.current)return!1;l(),w(!0);try{return L.current!==e||typeof N.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},_e()})}finally{w(!1)}}),qe=Z.useRef(null),Je=J(async(t,n)=>{if(!t||!L.current)return!1;let r=`${L.current}:${t}`;if(qe.current===r)return!1;qe.current=r;let i=L.current;l(),w(!0);try{if(L.current!==e)return!1;for(;!N.current.messageToTurnId.has(t)&&de.current.hasMoreAboveTurns;){if(L.current!==i||qe.current!==r)return!1;let e=z.current[0]?.info.id;if(await Be({userInitiated:!0,singlePage:!0}),await he(),z.current[0]?.info.id===e)break}if(L.current!==i||qe.current!==r)return!1;let a=N.current.messageToTurnId.get(t);return typeof N.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:a??null,resolve:r},_e()})}finally{qe.current===r&&(qe.current=null),w(!1)}}),Ye=J(async()=>{qe.current=null,w(!1),F.current=!1,S(!1),s(`smooth`)}),Xe=J(async()=>{w(!1),F.current=!1,S(!1),s(`instant`)}),Ze=J(e=>{let t=ee.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;ee.current=null}E(e)});return{turnIds:b.turnIds,turnStart:0,renderedMessages:De,historySignals:ue,isLoadingOlder:He,pendingRevealWork:C,activeTurnId:T,showScrollToBottom:m&&!C,turnWindowModel:b,loadEarlier:Be,revealBufferedTurns:Fe,resumeToBottom:Ye,resumeToBottomInstant:Xe,scrollToTurn:Ke,scrollToMessage:Je,handleHistoryScroll:We,handleHistoryUpwardIntent:Ge,captureViewportAnchor:Ae,restoreViewportAnchor:je,handleActiveTurnChange:Ze}},HW=12,UW=50,WW=800;function GW(e){let t=(0,Q.c)(25),{scope:n,enabled:i,cursor:a,loadedTurns:o,messages:s,scrollRef:c,loadPrevious:l}=e,[u,d]=Z.useState(null),f=Z.useRef(u),p=Z.useRef(!1),m=Z.useRef(null),h;t[0]!==u||t[1]!==a||t[2]!==i||t[3]!==o||t[4]!==n?(h=i&&!r()&&a!==null&&o<HW&&u!==n,t[0]=u,t[1]=a,t[2]=i,t[3]=o,t[4]=n,t[5]=h):h=t[5];let g=h,_;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{f.current=null,d(null)},t[6]=_):_=t[6];let v;t[7]===n?v=t[8]:(v=[n],t[7]=n,t[8]=v),Z.useEffect(_,v);let y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{m.current=null},t[9]=y):y=t[9];let b;t[10]!==a||t[11]!==g||t[12]!==s||t[13]!==n?(b=[n,g,a,s],t[10]=a,t[11]=g,t[12]=s,t[13]=n,t[14]=b):b=t[14],Z.useEffect(y,b);let x;t[15]!==g||t[16]!==c?(x=e=>{g&&e.deltaY!==0&&e.target instanceof Node&&c.current?.contains(e.target)&&(m.current=null)},t[15]=g,t[16]=c,t[17]=x):x=t[17];let S;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(S={passive:!0,capture:!0},t[18]=S):S=t[18],Wn(`wheel`,x,void 0,S);let C;t[19]!==a||t[20]!==g||t[21]!==l||t[22]!==n||t[23]!==c?(C=()=>{let e=c.current;if(f.current===n)return;if(!g||r()||!a||!e||p.current||document.visibilityState===`hidden`){m.current=null;return}let t=e.scrollHeight,i=e.scrollTop,o=m.current;if(!o||o.height!==t||o.top!==i){m.current={height:t,top:i,since:Date.now()};return}Date.now()-o.since<WW||(f.current=n,d(n),p.current=!0,l(UW).catch(KW).finally(()=>{p.current=!1}))},t[19]=a,t[20]=g,t[21]=l,t[22]=n,t[23]=c,t[24]=C):C=t[24],Kn(J(C),g?200:null)}function KW(e){console.error(`[chat-history] desktop history warmup failed`,e)}var qW=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),JW=({open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s=!1,isLoadingEarlier:c=!1,onLoadEarlier:l,onRevertMessage:u})=>{let{t:d}=Xn(),{isMobile:f}=$c(),[p,m]=Z.useState(null),[h,g]=Z.useState(``),[_,v]=Z.useState(0),y=Z.useRef(!1),b=Z.useRef(0),x=J(async(e,n,r)=>{if(y.current)return;y.current=!0;let i=b.current+1;b.current=i,m({type:e,messageId:n});try{await r(),t(!1)}finally{b.current===i&&(y.current=!1,m(null))}});if(!n)return null;let S=(0,$.jsx)(YW,{open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s,isLoadingEarlier:c,onLoadEarlier:l,onRevertMessage:u,searchQuery:h,onSearchQueryChange:g,selectedIndex:_,onSelectedIndexChange:v,pendingAction:p,runPendingMessageAction:x});return f?(0,$.jsx)(yl,{id:`conversation-timeline:${n}`,open:e,onOpenChange:t,title:(0,$.jsx)(`span`,{className:`yuri-timeline-mobile-title`,children:d(`chat.timeline.title`)}),ariaLabel:d(`chat.timeline.title`),closeAriaLabel:d(`mobile.surface.closeAria`),resizeAriaLabel:d(`mobile.sessions.sheet.resizeAria`),className:`yuri-timeline-mobile`,bodyClassName:`yuri-timeline-body`,children:S}):(0,$.jsx)(Ds,{open:e,onOpenChange:t,children:(0,$.jsx)(Cs,{presentation:`picker`,className:`yuri-timeline-dialog`,children:S})})},YW=e=>{let t=(0,Q.c)(109),{open:n,onOpenChange:r,sessionID:i,directory:a,onScrollToMessage:o,onScrollByTurnOffset:s,onResumeToLatest:c,canLoadEarlier:l,isLoadingEarlier:u,onLoadEarlier:d,onRevertMessage:f,searchQuery:p,onSearchQueryChange:m,selectedIndex:h,onSelectedIndexChange:g,pendingAction:_,runPendingMessageAction:v}=e,{t:y}=Xn(),b=wb(),x=i,S=ba(x??``,a),C=Da(ZW),w=Da(QW),T;t[0]===b.capabilities?T=t[1]:(T=qW(b.capabilities),t[0]=b.capabilities,t[1]=T);let E=T,{isMobile:D,isTablet:O}=$c(),k=D||O,A;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(A=[],t[2]=A):A=t[2];let j=Z.useRef(A),M=Z.useRef(null),N=Z.useRef(null),P=Z.useRef(!1),F=Z.useRef(!1),I=$W,L=eG,R;t[3]===S?R=t[4]:(R=S.filter(tG).map(nG),t[3]=S,t[4]=R);let z=R,B;if(t[5]!==p||t[6]!==z){bb0:{let e=p.trim();if(!e){B=z;break bb0}let t=e.toLowerCase();B=z.filter(e=>{let{message:n}=e;return wH(n.parts).toLowerCase().includes(t)})}t[5]=p,t[6]=z,t[7]=B}else B=t[7];let V=B,H;t[8]!==V.length||t[9]!==g||t[10]!==p?(H=()=>{P.current||g(p.trim()?0:Math.max(0,V.length-1))},t[8]=V.length,t[9]=g,t[10]=p,t[11]=H):H=t[11];let U;t[12]!==V||t[13]!==g||t[14]!==p?(U=[V,p,g],t[12]=V,t[13]=g,t[14]=p,t[15]=U):U=t[15],Z.useEffect(H,U);let W,ee;t[16]===V.length?(W=t[17],ee=t[18]):(W=()=>{j.current=j.current.slice(0,V.length)},ee=[V.length],t[16]=V.length,t[17]=W,t[18]=ee),Z.useEffect(W,ee);let te,ne;t[19]===h?(te=t[20],ne=t[21]):(ne=()=>{P.current||j.current[h]?.scrollIntoView({block:`nearest`})},te=[h],t[19]=h,t[20]=te,t[21]=ne),Z.useEffect(ne,te);let re;t[22]===u?re=t[23]:(re=()=>{!P.current||N.current||u||(P.current=!1)},t[22]=u,t[23]=re);let G;t[24]!==V.length||t[25]!==u?(G=[V.length,u],t[24]=V.length,t[25]=u,t[26]=G):G=t[26],Z.useEffect(re,G);let ie,ae;t[27]!==n||t[28]!==p?(ie=()=>{let e=F.current;if(F.current=n,!n||e||P.current||p.trim())return;let t=M.current;t&&(t.scrollTop=t.scrollHeight)},ae=[n,p],t[27]=n,t[28]=p,t[29]=ie,t[30]=ae):(ie=t[29],ae=t[30]),Z.useLayoutEffect(ie,ae);let oe;t[31]===u?oe=t[32]:(oe=()=>{let e=N.current,t=M.current;if(!e||!t||u)return;N.current=null;let n=j.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},t[31]=u,t[32]=oe);let se;t[33]!==V.length||t[34]!==u?(se=[V.length,u],t[33]=V.length,t[34]=u,t[35]=se):se=t[35],Z.useLayoutEffect(oe,se);let ce;t[36]===d?ce=t[37]:(ce=()=>{let e=M.current;if(e){let t=e.getBoundingClientRect().top,n=j.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(N.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}P.current=!0,d?.()},t[36]=d,t[37]=ce);let le=J(ce),ue;t[38]!==r||t[39]!==o?(ue=async e=>{await o?.(e)!==!1&&r(!1)},t[38]=r,t[39]=o,t[40]=ue):ue=t[40];let de=J(ue),fe;t[41]!==V||t[42]!==de||t[43]!==g||t[44]!==h?(fe=e=>{let t=V.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),g(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),g(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(h%t+t)%t,r=V[n];r&&de(r.message.info.id)}}},t[41]=V,t[42]=de,t[43]=g,t[44]=h,t[45]=fe):fe=t[45];let pe=J(fe),me;t[46]!==x||t[47]!==a||t[48]!==w||t[49]!==f||t[50]!==C||t[51]!==v?(me=async(e,t)=>{x&&await v(e,t,async()=>{e===`revert`?f?await f(t):await C(x,t,{directory:a}):await w(x,t,{directory:a})})},t[46]=x,t[47]=a,t[48]=w,t[49]=f,t[50]=C,t[51]=v,t[52]=me):me=t[52];let he=J(me),ge;t[53]!==D||t[54]!==y?(ge=D?null:(0,$.jsx)(xs,{className:`yuri-timeline-header`,children:(0,$.jsx)(ws,{className:`yuri-timeline-title`,children:y(`chat.timeline.title`)})}),t[53]=D,t[54]=y,t[55]=ge):ge=t[55];let _e=D&&`yuri-mobile-glass-control`,ve;t[56]===_e?ve=t[57]:(ve=Y(`yuri-timeline-search`,_e),t[56]=_e,t[57]=ve);let ye;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 text-muted-foreground`}),t[58]=ye):ye=t[58];let be=!D,xe;t[59]===y?xe=t[60]:(xe=y(`chat.timeline.searchPlaceholder`),t[59]=y,t[60]=xe);let Se;t[61]===y?Se=t[62]:(Se=y(`chat.timeline.searchPlaceholder`),t[61]=y,t[62]=Se);let Ce;t[63]===m?Ce=t[64]:(Ce=e=>m(e.target.value),t[63]=m,t[64]=Ce);let we;t[65]!==pe||t[66]!==p||t[67]!==be||t[68]!==xe||t[69]!==Se||t[70]!==Ce?(we=(0,$.jsx)(Qs,{autoFocus:be,"aria-label":xe,inputMode:`search`,placeholder:Se,value:p,onChange:Ce,onKeyDown:pe}),t[65]=pe,t[66]=p,t[67]=be,t[68]=xe,t[69]=Se,t[70]=Ce,t[71]=we):we=t[71];let Te;t[72]!==ve||t[73]!==we?(Te=(0,$.jsxs)(`div`,{className:ve,children:[ye,we]}),t[72]=ve,t[73]=we,t[74]=Te):Te=t[74];let Ee;t[75]!==l||t[76]!==le||t[77]!==u||t[78]!==d||t[79]!==y?(Ee=l&&d&&(0,$.jsx)(`div`,{className:`yuri-timeline-history`,children:(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:le,disabled:u,className:`text-muted-foreground hover:text-foreground`,children:[u&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),y(`chat.history.loadOlder`)]})}),t[75]=l,t[76]=le,t[77]=u,t[78]=d,t[79]=y,t[80]=Ee):Ee=t[80];let De;t[81]===y?De=t[82]:(De=y(`chat.timeline.title`),t[81]=y,t[82]=De);let Oe;t[83]!==E||t[84]!==k||t[85]!==V||t[86]!==he||t[87]!==de||t[88]!==g||t[89]!==_||t[90]!==p||t[91]!==h||t[92]!==y?(Oe=V.length===0?(0,$.jsx)(`div`,{className:`yuri-timeline-empty text-center text-muted-foreground`,children:y(p?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):V.map((e,t)=>{let{message:n}=e,r=TH(n.parts),i=n.info.time.created,a=I(i),o=V[t-1],s=a!==(o?I(o.message.info.time.created):null),c=L(i),l=t===h,u=p.trim()?XW(wH(n.parts),p):null;return(0,$.jsxs)(Z.Fragment,{children:[s&&(0,$.jsx)(`div`,{className:`yuri-timeline-date text-muted-foreground`,children:a}),(0,$.jsxs)(`div`,{ref:e=>{j.current[t]=e},"data-timeline-message-id":n.info.id,"data-selected":l,"data-show-actions":k,className:Y(`yuri-timeline-row hover:bg-interactive-hover/30`,l&&`bg-[color-mix(in_srgb,var(--interactive-selection)_40%,transparent)]`),onMouseEnter:()=>g(t),children:[(0,$.jsxs)(`button`,{type:`button`,className:`yuri-timeline-message`,"aria-current":l||void 0,title:r,onFocus:()=>g(t),onClick:()=>void de(n.info.id),children:[(0,$.jsx)(`time`,{className:`yuri-timeline-time text-muted-foreground`,dateTime:new Date(i).toJSON()??void 0,children:c}),(0,$.jsx)(`span`,{className:`yuri-timeline-preview text-foreground`,children:u??(r||y(`chat.timeline.noTextContent`))})]}),(0,$.jsxs)(`div`,{className:`yuri-timeline-row-actions`,children:[E.revert?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-foreground`,"aria-label":y(`chat.timeline.actions.revertFromHere`),"aria-busy":_?.type===`revert`&&_.messageId===n.info.id,disabled:_!==null,onClick:e=>{e.stopPropagation(),he(`revert`,n.info.id)},children:(0,$.jsx)(X,{name:_?.type===`revert`&&_.messageId===n.info.id?`loader-4`:`arrow-go-back`,className:Y(`h-4 w-4`,_?.type===`revert`&&_.messageId===n.info.id&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:y(`chat.timeline.actions.revertFromHere`)})]}):null,E.fork?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-foreground`,"aria-label":y(`chat.timeline.actions.forkFromHere`),"aria-busy":_?.type===`fork`&&_.messageId===n.info.id,onClick:e=>{e.stopPropagation(),he(`fork`,n.info.id)},disabled:_!==null,children:_?.type===`fork`&&_.messageId===n.info.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4`})})}),(0,$.jsx)(ec,{sideOffset:6,children:y(`chat.timeline.actions.forkFromHere`)})]}):null]})]})]},n.info.id)}),t[83]=E,t[84]=k,t[85]=V,t[86]=he,t[87]=de,t[88]=g,t[89]=_,t[90]=p,t[91]=h,t[92]=y,t[93]=Oe):Oe=t[93];let ke;t[94]!==De||t[95]!==Oe?(ke=(0,$.jsx)($u,{ref:M,outerClassName:`yuri-timeline-scroll`,className:`yuri-timeline-list`,"aria-label":De,children:Oe}),t[94]=De,t[95]=Oe,t[96]=ke):ke=t[96];let Ae;t[97]!==r||t[98]!==c||t[99]!==s||t[100]!==_||t[101]!==y?(Ae=s||c?(0,$.jsxs)(`div`,{className:`yuri-timeline-toolbar`,children:[s?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:_!==null,onClick:()=>{s?.(-1),r(!1)},children:y(`chat.timeline.actions.previousTurn`)}):null,c?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:_!==null,onClick:()=>{c?.(),r(!1)},children:y(`chat.timeline.actions.latest`)}):null]}):null,t[97]=r,t[98]=c,t[99]=s,t[100]=_,t[101]=y,t[102]=Ae):Ae=t[102];let je;return t[103]!==ge||t[104]!==Te||t[105]!==Ee||t[106]!==ke||t[107]!==Ae?(je=(0,$.jsxs)($.Fragment,{children:[ge,Te,Ee,ke,Ae]}),t[103]=ge,t[104]=Te,t[105]=Ee,t[106]=ke,t[107]=Ae,t[108]=je):je=t[108],je};function XW(e,t,n=30){let r=e.toLowerCase(),i=t.toLowerCase(),a=r.indexOf(i);if(a===-1)return null;let o=Math.max(0,a-n),s=Math.min(e.length,a+t.length+n);return`${o>0?`…`:``}${e.slice(o,s).replace(/\n/g,` `)}${s<e.length?`…`:``}`}function ZW(e){return e.revertToMessage}function QW(e){return e.forkFromMessage}function $W(e){return vc(e)}function eG(e){return nc(e)}function tG(e){return e.info.role===`user`}function nG(e){return{message:e}}var rG=e=>{let t=e.startsWith(`#`)?e.slice(1):e;if(!t)return null;let n=t.match(/^turn-(.+)$/);if(n?.[1])return{kind:`turn`,id:n[1]};let r=t.match(/^message-(.+)$/);return r?.[1]?{kind:`message`,id:r[1]}:null},iG=(e,t,n)=>{if(n===0||e.length===0)return{kind:`noop`};let r=t?e.indexOf(t):e.length-1,i=(r>=0?r:e.length-1)+n;if(i>=e.length)return{kind:`resume`};let a=e[Math.max(0,i)];return a?{kind:`turn`,turnId:a}:{kind:`noop`}},aG=e=>{if(typeof window>`u`)return;let t=e?`#${e}`:``,n=`${window.location.pathname}${window.location.search}${t}`;window.history.replaceState(window.history.state,``,n),e&&window.dispatchEvent(new HashChangeEvent(`hashchange`))},oG=e=>{e&&aG(`message-${e}`)},sG=e=>{let t=(0,Q.c)(29),{sessionId:n,turnIds:r,activeTurnId:i,scrollToTurn:a,scrollToMessage:o,resumeToBottom:s}=e,c=Z.useRef(r),l=Z.useRef(i),u,d;t[0]===r?(u=t[1],d=t[2]):(u=()=>{c.current=r},d=[r],t[0]=r,t[1]=u,t[2]=d),Z.useEffect(u,d);let f,p;t[3]===i?(f=t[4],p=t[5]):(f=()=>{l.current=i},p=[i],t[3]=i,t[4]=f,t[5]=p),Z.useEffect(f,p);let m;t[6]===a?m=t[7]:(m=async(e,t)=>e?(t?.updateHash!==!1&&aG(`turn-${e}`),a(e,{behavior:t?.behavior})):!1,t[6]=a,t[7]=m);let h=m,g;t[8]===o?g=t[9]:(g=async(e,t)=>e?(t?.updateHash!==!1&&aG(`message-${e}`),o(e,{behavior:t?.behavior})):!1,t[8]=o,t[9]=g);let _=g,v;t[10]!==s||t[11]!==h?(v=async(e,t)=>{let n=c.current,r=iG(n,l.current,e);if(r.kind===`noop`)return e===0;if(r.kind===`resume`){if(t?.resumePastEnd===!1){let e=n[n.length-1];return e?h(e,{behavior:`auto`}):!1}return aG(null),s(),!0}return h(r.turnId,{behavior:`auto`})},t[10]=s,t[11]=h,t[12]=v):v=t[12];let y=v,b;t[13]===s?b=t[14]:(b=()=>{aG(null),s()},t[13]=s,t[14]=b);let x=b,S;t[15]!==_||t[16]!==h||t[17]!==n?(S=()=>{if(!n||typeof window>`u`)return;let e=()=>{let e=rG(window.location.hash);if(e){if(e.kind===`turn`){h(e.id,{behavior:`auto`,updateHash:!1});return}_(e.id,{behavior:`auto`,updateHash:!1})}};return e(),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`hashchange`,e)}},t[15]=_,t[16]=h,t[17]=n,t[18]=S):S=t[18];let C;t[19]!==_||t[20]!==h||t[21]!==n||t[22]!==r.length?(C=[n,_,h,r.length],t[19]=_,t[20]=h,t[21]=n,t[22]=r.length,t[23]=C):C=t[23],Z.useEffect(S,C);let w;return t[24]!==x||t[25]!==y||t[26]!==_||t[27]!==h?(w={scrollToTurnId:h,scrollToMessageId:_,scrollByTurnOffset:y,resumeToLatest:x},t[24]=x,t[25]=y,t[26]=_,t[27]=h,t[28]=w):w=t[28],w},cG=2e4,lG=6e4,uG=2e3,dG=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,fG=e=>{if(e.length===0)return`0`;let t=e[e.length-1];if(!t)return`0`;let n=t.parts??[],r=n[n.length-1],i=0;for(let e of n)i+=dG(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},pG={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},mG=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:pG,shouldRefresh:!1,stalledForMs:0};if(e.sessionKey!==n)return{state:{sessionKey:n,fingerprint:a,lastMovementAt:o,lastRefreshAt:null,attempts:0},shouldRefresh:!1,stalledForMs:0};if(e.fingerprint!==a)return{state:{...e,fingerprint:a,lastMovementAt:o,attempts:0},shouldRefresh:!1,stalledForMs:0};if(!r||i)return{state:{...e,lastMovementAt:o},shouldRefresh:!1,stalledForMs:0};let s=e.lastMovementAt??o,c=o-s,l=e.lastRefreshAt===null||o-e.lastRefreshAt>=t.cooldownMs,u=c>=t.thresholdMs&&l&&e.attempts<t.maxAttempts;return{state:{...e,lastMovementAt:s,lastRefreshAt:u?o:e.lastRefreshAt,attempts:u?e.attempts+1:e.attempts},shouldRefresh:u,stalledForMs:c}},hG=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function gG(e){return!!(e.active&&e.sessionId&&e.sessionKey&&e.sessionIsWorking)}function _G(e){return e===pG?e:pG}function vG(e){let t=e.match(/^User has answered your questions:\s*(.+?)\.\s*You can now/s);if(!t)return null;let n=[],r=t[1],i=/"([^"]+)"="([^"]*(?:[^"\\]|\\.)*)"/g,a;for(;(a=i.exec(r))!==null;)n.push({question:a[1],answer:a[2]});return n.length>0?n:null}function yG(e){if(typeof e.id==`string`&&e.id)return e.id;if(typeof e.callID==`string`&&e.callID)return e.callID;let t=e.state;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t.callID;if(typeof e==`string`&&e)return e}return null}function bG(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(t.type!==`tool`||t.tool!==`question`)return!1;let n=t.state&&typeof t.state==`object`&&!Array.isArray(t.state)?t.state:{},r=typeof n.status==`string`?n.status:void 0;if(r===`error`)return!1;if(r===`pending`||r===`running`||r===void 0)return!0;if(r!==`completed`)return!1;let i=typeof n.output==`string`?n.output:``;return!i||vG(i)==null}function xG(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!bG(n))continue;let e=yG(n);e&&t.push(e)}}return t}function SG(e,t){return`${e}:${t.join(`,`)}`}function CG(e){let t=e.sessionId?.trim()??``,n=e.directory?.trim()??``;if(!t||!n||e.sessionQuestionCount>0||e.unansweredToolIds.length===0)return{recover:!1,attemptKey:null};let r=SG(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function wG(e,t,n,r){let i=(0,Q.c)(7),a=Fr(),o=Z.useRef(null),s=Z.useRef(`${e??``}:${t??``}`),c,l;i[0]!==a||i[1]!==t||i[2]!==n||i[3]!==e||i[4]!==r?(c=()=>{let i=`${e??``}:${t??``}`;s.current!==i&&(o.current=null,s.current=i);let c=CG({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:xG(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,Ei(t,l,[e]))},l=[e,t,n,r,a],i[0]=a,i[1]=t,i[2]=n,i[3]=e,i[4]=r,i[5]=c,i[6]=l):(c=i[5],l=i[6]),Z.useEffect(c,l)}var TG=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),EG=(e,t)=>({...e,key:DG(e),estimatedBytes:TG(t)}),DG=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),OG=e=>({key:e?DG(e):null,selection:e}),kG=(e,t,n)=>{let r=Math.max(1,Math.floor(n.maxEntries)),i=Math.max(0,n.maxEstimatedBytes),a=e.reduce((e,t)=>e+t.estimatedBytes,0);if(e.length<=r&&a<=i)return e;let o=[...e];for(;o.length>r||a>i;){let e=o.findIndex(e=>e.key!==t);if(e===-1)break;let[n]=o.splice(e,1);a-=n?.estimatedBytes??0}return o},AG=(e,t,n,r)=>{let i=DG(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return kG(e,i,n);let s=o||EG(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),kG(c,i,n)},jG=(e,t,n)=>{let r=TG(n),i=e.findIndex(e=>e.key===t);return i===-1||e[i].estimatedBytes===r?e:e.map((e,t)=>t===i?{...e,estimatedBytes:r}:e)},MG=(e,t)=>t&&e.some(e=>e.key===t)?t:null,NG=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?AG(e.cachedSessionViews,t.selection,n,r.estimatedBytes):kG(e.cachedSessionViews,t.key??``,n),a=!r&&e.pendingSessionView?.intent===t?e.pendingSessionView:null;return e.activeIntent===t&&!e.cacheNeedsTrim&&i===e.cachedSessionViews&&a===e.pendingSessionView?e:{activeIntent:t,cacheNeedsTrim:!1,cachedSessionViews:i,pendingSessionView:a}},PG=(e,t,n,r)=>{if(n!==t||e.activeIntent!==t||!t.selection||e.cachedSessionViews.some(e=>e.key===t.key))return e;let i={entry:EG(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},FG=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:AG(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},IG=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},LG=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},RG=e=>LG(e)?.role===`assistant`,zG=(e,t)=>{let n=LG(t);n&&(e.agentName??=IG(n.agent),e.providerId??=IG(n.providerID),e.modelId??=IG(n.modelID))},BG=e=>!!(e.agentName&&e.providerId&&e.modelId),VG=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!RG(r))&&(zG(t,r),BG(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||RG(r))&&(zG(t,r),BG(t)))break}return t},HG=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),UG=[],WG=[],GG=[],KG={type:`idle`},qG=`yuri:chat-force-scroll-bottom`,JG=()=>void 0,YG=`Quota limit reached. Retrying automatically.`,XG=1048576,ZG=XG,QG=20,$G=XG,eK=16*XG,tK={maxEntries:3,maxEstimatedBytes:32*XG},nK={maxEntries:2,maxEstimatedBytes:32*XG},rK=e=>i(()=>e()),iK={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},aK=()=>{let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 bottom-full z-0 h-11 bg-gradient-to-t from-[var(--surface-background)] to-transparent`}),e[0]=t):t=e[0],t},oK=[`a[href]`,`button`,`input`,`select`,`textarea`,`[contenteditable="true"]`,`[role="button"]`,`[role="combobox"]`,`[role="dialog"]`,`[role="listbox"]`,`[role="menu"]`,`[role="menuitem"]`,`[role="option"]`,`[role="textbox"]`,`[data-radix-popper-content-wrapper]`].join(`,`),sK=e=>e instanceof HTMLElement,cK=e=>sK(e)?!!e.closest(oK):!1,lK=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||cK(e)?!0:!t?.contains(e),uK=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=K.getState();return e||t||n||r||i||a||o},dK=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,initialPinRevealComplete:l=!1,renderedMessages:u,isLoadingOlder:d,sessionIsWorking:f,streamingMessageId:p,activeStreamingPhase:m,retryOverlay:h,handleMessageContentChange:g,getAnimationHandlers:_,handleHistoryScroll:v,scrollToBottom:y,sessionQuestions:b,sessionPermissions:x,sessionForms:S,retryActionCopy:C,isProgrammaticFollowActive:w,showLoadOlderButton:T,turnIds:E,activeTurnId:D,onSelectTurn:O,showPromptNavigator:k,canLoadEarlierPrompts:A,isLoadingOlderPrompts:j,onLoadEarlierPrompts:M,transcriptStatusRow:N,timelineHistoryAnchorToken:P})=>{let{t:F}=Xn(),I=tO({isLoadingOlder:d}),[L,R]=Z.useState({sessionId:e,directory:a,reserved:T}),z=L.sessionId===e&&L.directory===a,B=z&&L.reserved||T;(!z||L.reserved!==B)&&R({sessionId:e,directory:a,reserved:B});let V=nO({isMobile:r,isLoadingOlder:I})?(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsx)(`div`,{className:`chat-column flex items-center justify-center gap-1.5 pt-3 pb-1`,children:(0,$.jsx)(`span`,{className:`yuri-mobile-glass-control flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)]`,"aria-label":F(`chat.history.loadingMore`),children:(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`,"aria-hidden":`true`})})})}):null,H=r&&B?(0,$.jsx)(`div`,{className:Y(`flex justify-center pt-3 pb-4`,!I&&`invisible`),"aria-hidden":!I,children:(0,$.jsxs)(`span`,{role:`status`,className:`flex items-center gap-1.5 text-[var(--surface-mutedForeground)] opacity-60`,"aria-busy":I,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:F(`chat.history.loadingMore`)})]})}):null,U=Z.useRef(new Map),W=Z.useRef(new WeakMap),ee=Z.useRef(new Map),te=Z.useMemo(()=>{let e=new Map;for(let t=0;t<u.length;t+=1){let n=u[t];if(n.info.role!==`user`)continue;if(LL(n)){let r=BL(u,t)??``,i=ee.current.get(n.info.id);if(i&&i.command===r)e.set(n.info.id,i.parts);else{let t=[{type:`text`,text:r?`$ ${r}`:`/shell`}];ee.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(Ma(n.parts))continue;let r=W.current.get(n.parts);r||(r=qD(n.parts),W.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=U.current;if(t.size===e.size){let n=!0;for(let[r,i]of e)if(t.get(r)!==i){n=!1;break}if(n)return t}return U.current=e,e},[u]),ne=Z.useMemo(()=>E.filter(e=>te.has(e)),[te,E]),re=Z.useRef(new Map),G=Z.useMemo(()=>{let e=new Map,t=new Map,n;for(let r of u){if(r.info.role===`user`){te.has(r.info.id)&&(n=r.info.id),n&&e.set(r.info.id,n);continue}let i=r.info.parentID,a=i?e.get(i):n;if(!a)continue;e.set(r.info.id,a);let o=wH(r.parts).trim();o&&t.set(a,o.slice(0,600))}let r=re.current;return(r.size!==e.size||[...e].some(([e,t])=>r.get(e)!==t))&&(re.current=e),{owners:re.current,replies:t}},[te,u]),ie=Z.useMemo(()=>{if(!D||te.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(te.has(e))return e}return null},[D,te,E]),ae=J(e=>{e.defaultPrevented||cK(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,n?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":n,children:(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(ed,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:iK,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:ae,onScroll:v,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`yuri-chat-scroll-content relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[H,V,(0,$.jsx)(UV,{timelineHistoryAnchorToken:P,ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,initialPinRevealComplete:l,messages:u,sessionIsWorking:f,activeStreamingMessageId:p,activeStreamingPhase:m,retryOverlay:h,onMessageContentChange:g,getAnimationHandlers:_,isLoadingOlder:d,scrollToBottom:y,scrollRef:o,directory:a,liveStatusSlot:u.length>0?(0,$.jsx)(`div`,{className:`mb-1`,children:N??(0,$.jsx)(jR,{})}):null}),(b.length>0||x.length>0||S.length>0||C)&&(0,$.jsxs)(`div`,{children:[C?(0,$.jsxs)(`div`,{className:`mb-2 rounded-xl border border-border/20 bg-muted/10 px-2.5 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:C.title}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-1`,children:C.message}),C.link?(0,$.jsx)(`a`,{href:C.link,target:`_blank`,rel:`noreferrer`,className:`mt-2 inline-block typography-meta text-primary underline`,children:C.label}):null]}):null,b.map(e=>(0,$.jsx)(hH,{question:e},e.id)),x.map(e=>(0,$.jsx)(cH,{permission:e},e.id)),S.map(e=>(0,$.jsx)(_H,{form:e,directory:a},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?QH:ZH},"aria-hidden":`true`})]})}),(0,$.jsx)(Qu,{containerRef:o,suppressVisibility:w,userIntentOnly:!0,observeMutations:!1}),k&&ne.length>=2?(0,$.jsx)(KH,{turnIds:ne,previewsByTurnId:te,scrollRef:o,turnByMessageId:G.owners,repliesByTurnId:G.replies,activeTurnId:ie,onSelectTurn:O,canLoadEarlier:A,isLoadingOlder:j,onLoadEarlier:M}):null]})})},(e,t)=>e.currentSessionId===t.currentSessionId&&e.virtualizerKey===t.virtualizerKey&&e.isDesktopExpandedInput===t.isDesktopExpandedInput&&e.isMobile===t.isMobile&&e.stickyUserHeader===t.stickyUserHeader&&e.directory===t.directory&&e.scrollRef===t.scrollRef&&e.messageListRef===t.messageListRef&&e.pendingRevealWork===t.pendingRevealWork&&e.initialPinRevealComplete===t.initialPinRevealComplete&&e.renderedMessages===t.renderedMessages&&e.timelineHistoryAnchorToken===t.timelineHistoryAnchorToken&&e.isLoadingOlder===t.isLoadingOlder&&e.sessionIsWorking===t.sessionIsWorking&&e.streamingMessageId===t.streamingMessageId&&e.activeStreamingPhase===t.activeStreamingPhase&&e.retryOverlay===t.retryOverlay&&e.handleMessageContentChange===t.handleMessageContentChange&&e.getAnimationHandlers===t.getAnimationHandlers&&e.handleHistoryScroll===t.handleHistoryScroll&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.sessionForms===t.sessionForms&&e.retryActionCopy===t.retryActionCopy&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.turnIds===t.turnIds&&e.activeTurnId===t.activeTurnId&&e.onSelectTurn===t.onSelectTurn&&e.showPromptNavigator===t.showPromptNavigator&&e.canLoadEarlierPrompts===t.canLoadEarlierPrompts&&e.isLoadingOlderPrompts===t.isLoadingOlderPrompts&&e.onLoadEarlierPrompts===t.onLoadEarlierPrompts&&e.transcriptStatusRow===t.transcriptStatusRow);dK.displayName=`ChatViewport`;var fK=[{id:1,toolRows:[{id:`search`,titleWidth:`w-24`,detailWidth:`w-52`},{id:`read`,titleWidth:`w-20`,detailWidth:`w-36`}],textWidths:[`w-24`,`w-[92%]`,`w-[78%]`]}],pK=e=>Zn(e.path),mK=(e,t)=>{if(!t)return e;let n=e.indexOf(t);return n===-1?e:(0,$.jsxs)($.Fragment,{children:[e.slice(0,n),(0,$.jsx)(`span`,{className:`font-medium`,children:t}),e.slice(n+t.length)]})},hK=e=>{let t=Math.ceil(Math.max(0,e)/QG);return Math.min(eK,ZG+t*$G)},gK=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:s,hostedFeatures:c,assistantHistory:l,onRevertMessage:d,warning:f=null,pendingUserMessages:p=WG,onPendingUserMessagesMaterialized:m,committedDraftHandoffMessageId:h=null})=>{let g=c??oO(void 0),{t:_}=Xn();Jn(()=>{na()},[]);let v=Da(e=>e.openNewSessionDraft),y=Da(e=>e.setCurrentSession),x=Da(e=>e.newSessionDraft),S=Da(e=>e.newSessionDraft.draftSubmitting??!1),C=Da(e=>e.newSessionDraft.draftEstablishing??!1),w=Da(e=>e.forkTransition),T=pa(e=>e.projects),E=pa(e=>e.activeProjectId),D=ni(e=>e.providers),O=ih(),k=vr(),A=i??k;Jn(()=>{!n||!r||!A||us(A,r)},[n,r,A]);let j=J(e=>O.ensureSessionRenderable(e,{directory:A})),M=K(e=>e.isExpandedInput),N=K(e=>e.stickyUserHeader),P=K(e=>e.promptNavigatorEnabled),F=K(e=>e.allowPromptingSubagentSessions),I=K(e=>e.isTimelineDialogOpen),L=K(e=>e.setTimelineDialogOpen),R=_i(e=>n&&r?e.streamingMessageIds.get(r)??null:null),z=_i(e=>R?e.messageStreamStates.get(R)?.phase??null:null),B=to(r??``,A),V=hK(B);Z.useEffect(()=>{!a||!o||o(a,V)},[o,V,a]);let H=va(r??``,A).renderable,U=lo(r,A),W=Xr(r),ee=U??W,te=Rx({sessionId:r,hasSessionEntity:!!ee,hasRenderableSessionSnapshot:H,composerSurfaceKind:s?.kind}),ne=r?JSON.stringify([A,r]):null,[re,G]=Z.useState({key:ne,attempt:0}),ie=ba(r??``,A,{suspendPartUpdates:!!R,suspendPartUpdatesForMessageId:R,enabled:n}),ae=r?ie:UG,se=x.pendingUserMessage,ce=Da(e=>r?e.retainedPendingUserMessages.get(r):void 0)??WG,le=!!(h||ce.length>0),ue=Da(e=>e.clearRetainedPendingUserMessages),de=Z.useMemo(()=>{if(ce.length===0)return p;if(p.length===0)return ce;let e=new Set(p.map(e=>e.info.id));return[...p,...ce.filter(t=>!e.has(t.info.id))]},[p,ce]),fe=Z.useMemo(()=>VG(ae),[ae]),pe=Z.useMemo(()=>{if(!fe.modelId)return _(`common.unavailable`);let e=D.find(e=>e.id===fe.providerId);return qr(e,fe.modelId)||fe.modelId},[D,fe.modelId,fe.providerId,_]),me=Vo(r??``,A),he=fa(r??``,A),[ge,ve]=Z.useState(null),be=!!r&&ge===r,xe=J(()=>{if(!r||be)return;let e=r,t=A;ve(e);let n=cs(()=>{let n=Ve();if(!n)throw Error(`unbound`);return n.getTranscript(oe(t,e))});Hr(zi({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:me?{sessionID:e,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error})),(async()=>{try{await ye(t,e),await O.ensureSessionRenderable(e,{directory:t});try{let r=cs(()=>{let n=Ve();if(!n)throw Error(`unbound`);return n.getTranscript(oe(t,e))});n&&r&&Qr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){Hr(zi({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:he,error:n}))}finally{ve(t=>t===e?null:t)}})()}),Se=Qo(r??``,A).boundary,Ce=J(async e=>{if(Se.kind===`has-more`){await st(A,e,We||Ge?void 0:50);return}if(Se.kind===`unknown`){await Le(A,e);return}l&&!l.complete&&await l.fetchPrevious()}),we=ia(r??``,A),Te=Go(r??``,A),Ee=rs(A),De=we??KG,Oe=wa(r,A),ke=Io(r,A),je=fr(e=>r?e.forms[r]??GG:GG),Me=Z.useMemo(()=>je.filter(e=>!_e(e.metadata)),[je]);Z.useEffect(()=>{r&&Za({sessionID:r,directory:A}).catch(e=>{console.error(`[ChatContainer] Failed to list session forms:`,e)})},[r,A]),wG(r,A,ae,ke.length);let Ne=Z.useMemo(()=>{if(!r||Oe.length>0||ke.length>0)return!1;let e=De.type??`idle`;if(e===`busy`||e===`retry`||ZD(de,{resolvedSessionStatus:we,sessionStatusObservedAt:Te}))return!0;let t=ae[ae.length-1]?.info,n=t?.time?.created;return we&&typeof Te==`number`&&typeof n==`number`&&n<=Te||typeof Ee==`number`&&typeof n==`number`&&n<=Ee?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,de,we,ae,Oe.length,ke.length,De.type,Te,Ee]),Pe=Z.useMemo(()=>!r||De.type!==`retry`?null:{sessionId:r,message:(typeof De.message==`string`?(De.message??``).trim():``)||YG,confirmedAt:De.confirmedAt},[r,De]),[Fe,Ie]=Z.useState(0),Re=Z.useRef(null);Z.useEffect(()=>{if(!Pe||typeof Pe.confirmedAt==`number`){Re.current=null,Ie(0);return}Re.current!==Pe.sessionId&&(Re.current=Pe.sessionId,Ie(Date.now()))},[Pe]);let ze=Z.useMemo(()=>!Pe||xH(De)?null:{...Pe,fallbackTimestamp:Fe},[Pe,Fe,De]),Be=Z.useMemo(()=>SH(De,e=>_(e)),[De,_]),He=!!(r&&O.isLoading(r,{directory:A})),Ue=Z.useMemo(()=>{if(!r)return null;let e=QD({boundary:Se,assistantComplete:l?.complete??!0});return{limit:Se.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:$D({syncLoading:He,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,Se,He]),We=K(e=>e.isMobile),Ge=Sl()!==null,Ke=b(),qe=Ox(),Je=!!x?.open,Ye=Ur(e=>e.error),Xe=M,Ze=Ge||We||Ke||qe===`mini-chat`,Qe=Z.useRef(null),$e=Z.useMemo(()=>{let e=x?.selectedProjectId?T.find(e=>e.id===x.selectedProjectId)??null:null,t=E?T.find(e=>e.id===E)??null:null,n=e??t??T[0]??null;return n?pK(n):null},[E,x?.selectedProjectId,T]),et=Si(r,A),tt=a??r??``,[nt,rt]=Z.useState(null),it=Ux(nt,tt,et,fe);Jn(()=>{rt(e=>Ux(e,tt,et,fe))},[et,fe,tt]);let at=et??it?.parentTarget??null,ot=it?.execution??fe,ct=gl(),lt=ct!==null&&r===ct,ut=J(()=>{at&&y(at.id,at.directory)}),dt=at?.session?.title,ft=g.returnToParent&&at&&!lt?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`xs`,onClick:ut,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":_(`chat.container.returnToParent.aria`),title:dt?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:dt}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,pt=zx({readOnly:t,sessionIdentityPending:te,isSubagentSession:!!ee?.parentID||!!it,allowPromptingSubagentSessions:F}),mt=ot.modelId===fe.modelId?pe:ot.modelId?qr(D.find(e=>e.id===ot.providerId),ot.modelId)||ot.modelId:_(`common.unavailable`),ht=at?(0,$.jsx)(uO,{agentName:ot.agentName,providerId:ot.providerId,modelId:ot.modelId,modelName:mt}):(0,$.jsx)(uO,{}),gt=J(e=>{K.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),_t=J(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`yuri:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&&gt({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),vt=typeof window<`u`&&window.parent!==window;Wn(`message`,_t,vt?window:JG),Hn(()=>{if(!vt)return;let e=window;e.__yuriApplyChatSettingsSync=gt,window.parent.postMessage({type:`yuri:chat-settings-request`},window.location.origin)}),Un(()=>{if(typeof window>`u`)return;let e=window;e.__yuriApplyChatSettingsSync===gt&&delete e.__yuriApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Je&&v()},[e,r,Je,g.newSessionDraft,v]);let yt=Z.useRef(()=>{}),bt=J(e=>{yt.current(e)}),xt=Z.useRef(()=>{}),St=J(()=>{xt.current()}),[Ct,wt]=Z.useState(0),Tt=J(()=>{wt(e=>e+1)}),{scrollRef:Et,notifyContentChange:Dt,getAnimationHandlers:Ot,goToBottom:kt,scrollToBottomOnSend:At,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,restoreSnapshot:Pt,isPinned:Ft,isFollowingProgrammatically:It,showScrollButton:Lt}=yU({scrollControllerRef:Qe,enabled:n,currentSessionId:r,viewportKey:a,sessionMessageCount:B,sessionIsWorking:Ne,isMobile:We,onActiveTurnChange:bt,onUpwardUserIntent:St}),Rt=Z.useRef(null);jU({enabled:We,scrollRef:Et,scopeRef:Rt});let zt=Z.useRef([]),Bt=Z.useMemo(()=>{let e=MO(l?.entries??[],r,zt.current);return zt.current=e,e},[l?.entries,r]),Vt=Z.useRef([]),Ht=Z.useMemo(()=>{if(!l)return ae;let e=FO(l.entries,r,ae,Vt.current);return Vt.current=e,e},[l,r,ae]),Ut=Z.useMemo(()=>XD(Bt.length===0?Ht:r?[...Bt,AO(r),...Ht]:Bt,de),[r,Ht,Bt,de]),Wt=Z.useRef(null),Gt=Z.useMemo(()=>aO({sessionId:r,messages:Ut,retained:Wt.current}),[r,Ut]);Wt.current=Gt.retained;let Kt=Gt.messages,qt=Z.useRef(null),Jt=qt.current===r,Yt=Z.useRef(pG),Xt=r?`${A}\n${r}`:null,Zt=J(()=>fG(Kt));Z.useEffect(()=>{if(!gG({active:n,sessionId:r,sessionKey:Xt,sessionIsWorking:Ne})){Yt.current=_G(Yt.current);return}let e=r,t=A,i=setInterval(()=>{let n=Zt(),r=mG(Yt.current,{sessionKey:Xt,working:!0,streaming:!!R,fingerprint:n,now:Date.now(),thresholdMs:cG,cooldownMs:lG,maxAttempts:3});Yt.current=r.state,r.shouldRefresh&&(hG({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),Ae(t,e).catch(()=>{}))},uG);return()=>clearInterval(i)},[n,r,A,Zt,Ne,R,Xt]);let Qt=Z.useMemo(()=>{if(de.length===0)return[];let e=new Set([...Bt,...Ht].filter(e=>YD(e.parts)).map(e=>e.info.id));return de.map(e=>e.info.id).filter(t=>e.has(t))},[Ht,Bt,de]);Z.useEffect(()=>{Qt.length!==0&&(m?.(Qt),r&&ue(r,Qt))},[ue,r,Qt,m]);let $t=VW({sessionId:r,directory:A,messages:Kt,historyMeta:Ue,scrollRef:Et,messageListRef:Qe,loadMoreMessages:Ce,goToBottom:kt,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,isPinned:Ft,showScrollButton:Lt,isMobile:We,onWillLoadEarlier:Tt}),en=J(()=>{kt(`instant`)}),tn=J(()=>{At()}),nn=eO({isMobile:We,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingOlder:$t.isLoadingOlder}),rn=$t.isLoadingOlder,an=$t.loadEarlier,on=J(()=>{an({userInitiated:!0})});yt.current=$t.handleActiveTurnChange,xt.current=$t.handleHistoryUpwardIntent,Z.useEffect(()=>{(Oe.length!==0||ke.length!==0)&&Dt(`permission`)},[Dt,Oe,ke]);let sn=sG({sessionId:r,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,scrollToTurn:$t.scrollToTurn,scrollToMessage:$t.scrollToMessage,resumeToBottom:en}),cn=pt.showReadOnlyBanner?ht:t?null:(0,$.jsx)(TD,{surface:s,scrollToBottom:tn,submissionBlocked:pt.blockSubmission},`composer-input`),ln=J(e=>{sn.scrollToTurnId(e,{behavior:`smooth`})}),un=$t.historySignals.canLoadEarlier,dn=g.promptNavigator&&!We&&!Ke&&!Xe&&P&&$t.turnIds.length>=2;Z.useEffect(()=>{dn||K.getState().setPromptNavigatorPanelOpen(!1)},[dn]);let fn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||kt(`instant`)});Wn(qG,fn,n&&r&&typeof window<`u`?window:JG);let pn=J(e=>{if(!n||!r||Xe||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=K.getState();if(t!==`chat`||uK())return;let i=Et.current;if(lK(document.activeElement,i)||cK(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;sn.scrollByTurnOffset(a,{resumePastEnd:!1})});Wn(`keydown`,pn,n&&r&&!Xe&&typeof window<`u`?window:JG);let mn=Z.useRef(0),hn=J(()=>{let e=Et.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),gn=J(()=>{mn.current||=requestAnimationFrame(()=>{mn.current=0,hn()})});Jn(()=>{n&&hn()},[n,r,Xe,hn]);let _n=typeof ResizeObserver<`u`;qn(n&&_n?Et:null,gn),Wn(`resize`,gn,n&&!_n&&typeof window<`u`?window:JG),Un(()=>{mn.current&&=(cancelAnimationFrame(mn.current),0)});let vn=Z.useRef(null),q=Z.useRef(0),yn=rO({transcriptMessageCount:ae.length,pendingUserCount:de.length,historyPrefixCount:Bt.length}),bn=iO({hasTranscriptShell:yn,transcriptRecords:ae,p0Satisfied:he.p0Satisfied,hasBusyShell:Ne&&yn,hasImmediateShell:de.length>0||Bt.length>0,hasRenderableSessionSnapshot:H,prefetchStatus:me?.status,syncLoading:!!(r&&O.isLoading(r,{directory:A})),userRetrying:be,hasPaintedTranscript:Jt});bn===`pass`&&Kt.length>0&&(qt.current=r);let xn=!!r&&bn===`hydrating`;GW({scope:JSON.stringify([u(),A,r]),enabled:n&&!We&&!Ge&&!!r&&bn===`pass`&&he.p0Satisfied&&!Ne&&!Ue?.loading&&!$t.isLoadingOlder,cursor:Se.kind===`has-more`?Se.cursor:null,loadedTurns:Se.loadedTurns,messages:Kt,scrollRef:Et,loadPrevious:e=>st(A,r,e)});let Sn=!!r&&bn===`load-error`;Z.useEffect(()=>{!Sn||!r||Hr(zi({kind:`request-error`,sessionID:r,directory:A,purpose:`load-failed`,source:`network`,request:me?{sessionID:r,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error}))},[r,A,Sn,me,he]),Z.useEffect(()=>{if(!n||!r||xn)return;let e=Kt.length,t=vn.current!==r,i=!t&&q.current===0&&e>0;if(!t&&!i){vn.current===r&&(q.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(vn.current=r,q.current=e,a){jt();return}let o=()=>{Pt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,xn,jt,Pt,Kt.length]),Z.useEffect(()=>{G(e=>e.key===ne?e:{key:ne,attempt:0})},[ne]),Z.useEffect(()=>{if(!n||!r||re.key!==ne||!HG({sessionId:r,hasRenderableSessionSnapshot:H,hasCurrentSessionEntity:!!ee})||(j(r),ee||re.attempt>=2))return;let e=re.attempt+1,t=window.setTimeout(()=>{G(t=>t.key===ne&&t.attempt===re.attempt?{key:ne,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,ee,r,A,j,H,ne,re]);let Cn=w&&r&&(w.targetSessionId?r===w.targetSessionId:r===w.sourceSessionId)?w:null;if(Cn){let e=Cn.stage===`preparing`?`chat.forkTransition.preparing`:Cn.stage===`copying`?`chat.forkTransition.copying`:Cn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Cn.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${_(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(e)}),(0,$.jsx)(zv,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}if(!r&&!Je)return e&&!Ye?(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`}):(0,$.jsx)(`div`,{className:`flex flex-col h-full bg-background`,children:(0,$.jsx)(fO,{})});if(!r&&Je){if((S||C)&&se){let e=`draft:${x.draftID??`pending`}`;return(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex h-full flex-col bg-background`,We&&`yuri-chat-composer-swap-scope`),children:[(0,$.jsx)(dK,{timelineHistoryAnchorToken:Ct,currentSessionId:e,virtualizerKey:e,isDesktopExpandedInput:!1,isMobile:We,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:!1,initialPinRevealComplete:!0,renderedMessages:[se],isLoadingOlder:!1,sessionIsWorking:!0,streamingMessageId:null,activeStreamingPhase:null,retryOverlay:null,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:[],sessionPermissions:[],sessionForms:[],retryActionCopy:null,isProgrammaticFollowActive:It,showLoadOlderButton:!1,turnIds:[],activeTurnId:null,onSelectTurn:ln,showPromptNavigator:!1,canLoadEarlierPrompts:!1,isLoadingOlderPrompts:!1,onLoadEarlierPrompts:on,transcriptStatusRow:(0,$.jsx)(`div`,{className:`chat-column`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex h-[1.2rem] items-center py-0.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zv,{})]})})},e),(0,$.jsxs)(`div`,{className:Y(`invisible pointer-events-none relative z-10`,We&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`absolute inset-0 bg-background`:`bg-background`),"aria-hidden":`true`,children:[!We&&!Xe?(0,$.jsx)(aK,{}):null,cn]})]})}return S||C?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":_(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zv,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Ze&&!Xe?(0,$.jsxs)(`div`,{className:`yuri-draft-center flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-balance text-3xl font-normal tracking-tight text-foreground`,children:mK($e?_(`chat.emptyState.draftTitleWithProject`,{project:$e}):_(`chat.emptyState.draftTitle`),$e)}),(0,$.jsx)(FS,{onSubmit:e=>fi.getState().requestPresetSubmit(e),className:`yuri-draft-starters mt-8 max-w-md`})]}):null,(0,$.jsx)(`div`,{className:Y(`relative z-10 flex min-h-0`,We&&`yuri-mobile-composer-foot`,Xe?`flex-1 bg-background`:Ze?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:cn})]})}return r?Sn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[ft,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:_(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:_(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(er,{type:`button`,className:`mt-5`,onClick:xe,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):xn?(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,We&&`yuri-chat-composer-swap-scope`),children:[ft,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:(0,$.jsx)(`div`,{ref:Et,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:iK,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:fK.map(e=>(0,$.jsx)(`div`,{className:`group w-full`,children:(0,$.jsx)(`div`,{className:`chat-message-column`,children:(0,$.jsxs)(`div`,{className:`space-y-2.5 px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.toolRows.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)($d,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,t.detailWidth)})]},`${e.id}-${t.id}`))}),(0,$.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!We&&!Xe?(0,$.jsx)(aK,{}):null,cn]},`composer-foot`)]}):Kt.length===0&&!Ne?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[ft,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(fO,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,We&&`yuri-chat-composer-swap-scope`),children:[f?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:f}):null,ft,(0,$.jsx)(dK,{timelineHistoryAnchorToken:Ct,currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Xe,isMobile:We,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:$t.pendingRevealWork,initialPinRevealComplete:le,renderedMessages:$t.renderedMessages,isLoadingOlder:rn,sessionIsWorking:Ne,streamingMessageId:R,activeStreamingPhase:z,retryOverlay:ze,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:ke,sessionPermissions:Oe,sessionForms:Me,retryActionCopy:Be,isProgrammaticFollowActive:It,showLoadOlderButton:nn,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,onSelectTurn:ln,showPromptNavigator:dn,canLoadEarlierPrompts:un,isLoadingOlderPrompts:rn,onLoadEarlierPrompts:on},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!We&&!Xe?(0,$.jsx)(aK,{}):null,(0,$.jsx)(CH,{scrollRef:Et,active:n&&!Xe,showScrollToBottom:Kt.length>0&&$t.showScrollToBottom,onScrollToBottom:sn.resumeToLatest}),cn]},`composer-foot`),(0,$.jsx)(JW,{open:I,onOpenChange:L,sessionID:r??void 0,directory:A,onRevertMessage:d,onScrollToMessage:$t.scrollToMessage,onScrollByTurnOffset:sn.scrollByTurnOffset,onResumeToLatest:en,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingEarlier:rn,onLoadEarlier:on})]}):null});gK.displayName=`MemoizedChatContainerContent`;var _K=()=>{let e=(0,Q.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)($d,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)($d,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)($d,{className:`h-4 w-1/2 animate-none rounded-md`})]}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`,"data-session-view-loading":`true`,"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`mt-auto w-full pb-5 motion-safe:animate-pulse`,children:(0,$.jsxs)(`div`,{className:`chat-message-column space-y-2 px-4`,children:[t,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)($d,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)($d,{className:`h-4 w-3/5 animate-none rounded-md`})]})]})})}),e[1]=n):n=e[1],n},vK=({runtimeKey:e,...t})=>{let n=Ox(),r=vr(),i=Da(H(e=>({sessionId:e.currentSessionId,directory:e.currentSessionDirectory,draftID:e.newSessionDraft.open?e.newSessionDraft.draftID:null,draftPendingMessageId:e.newSessionDraft.open?e.newSessionDraft.pendingUserMessage?.info.id??null:null}))),a=Z.useRef(null),o=i.draftID&&i.draftPendingMessageId?`${i.draftID}:${i.draftPendingMessageId}`:null;o&&a.current?.identity!==o&&(a.current=null),Jn(()=>{!o||!i.draftPendingMessageId||(a.current={identity:o,messageId:i.draftPendingMessageId})},[o,i.draftPendingMessageId]);let s=Da(e=>i.sessionId?e.retainedPendingUserMessages.get(i.sessionId)??WG:WG),c=a.current,l=c&&s.some(e=>e.info.id===c.messageId)?c.messageId:null,u=Z.useMemo(()=>i.sessionId?{runtimeKey:e,sessionId:i.sessionId,directory:i.directory??r}:null,[e,i.directory,i.sessionId,r]),d=Z.useMemo(()=>OG(u),[u]),f=d.key,p=Po()||b()||n===`mini-chat`?nK:tK,[m,h]=Z.useState(()=>({activeIntent:d,cacheNeedsTrim:!1,cachedSessionViews:u?AG([],u,p,ZG):[],pendingSessionView:null})),g=Z.useRef(d),_=Z.useRef(f),{cacheNeedsTrim:v,cachedSessionViews:y,pendingSessionView:x}=m,S=x?.intent===d?x.entry:null,C=Z.useMemo(()=>!u||!l?null:AG([],u,p,ZG)[0]??null,[p,l,u]),w=Z.useMemo(()=>{let e=[...y];return S&&!e.some(e=>e.key===S.key)&&e.push(S),C&&!e.some(e=>e.key===C.key)&&e.push(C),e.sort((e,t)=>e.key.localeCompare(t.key))},[y,C,S]),T=MG(w,f),E=!!(f&&!T);Jn(()=>{g.current=d,_.current=f,h(e=>{let t=NG(e,d,p);return l?PG(t,d,d,ZG):t})},[p,v,l,d,f]);let D=x?.intent??null;Jn(()=>{D&&h(e=>FG(e,D,p))},[p,D]),Z.useEffect(()=>{if(!d.selection||T)return;let e=d,t=f;return Od(()=>{g.current===e&&_.current===t&&h(n=>_.current===t?PG(n,e,g.current,ZG):n)},{priority:`user-blocking`})},[T,p,d,f]);let O=J((e,t)=>{let n=g.current,r=_.current;h(i=>{if(g.current!==n||_.current!==r||i.activeIntent!==n||e!==r)return i;let a=jG(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})});return(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":E||void 0,children:[E?(0,$.jsx)(_K,{},f):null,w.map(e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:T===e.key?`visible`:`hidden`,children:(0,$.jsx)(gK,{...t,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:O,committedDraftHandoffMessageId:T===e.key?l:null})},e.key)),f?null:(0,$.jsx)(gK,{...t,sessionId:null,sessionDirectory:i.directory})]})},yK=e=>{let t=(0,Q.c)(24),{host:n,runtimeKey:r,readOnly:i}=e,a=i!==void 0&&i,o;t[0]===n?o=t[1]:(o=oO(n),t[0]=n,t[1]=o);let s=o,c;t[2]===n.onRevertMessage?c=t[3]:(c=n.onRevertMessage?{onRevertMessage:n.onRevertMessage}:{},t[2]=n.onRevertMessage,t[3]=c);let l;t[4]!==n.directory||t[5]!==n.sessionId||t[6]!==n.sessionSurface||t[7]!==c?(l={...n.sessionSurface,sessionId:n.sessionId,directory:n.directory,...c},t[4]=n.directory,t[5]=n.sessionId,t[6]=n.sessionSurface,t[7]=c,t[8]=l):l=t[8];let u=l,d=`host:${r}:${u.surfaceId}:${n.sessionId}`,f;t[9]!==n.assistantHistory||t[10]!==n.composerSurface||t[11]!==n.directory||t[12]!==n.onPendingUserMessagesMaterialized||t[13]!==n.onRevertMessage||t[14]!==n.pendingUserMessages||t[15]!==n.sessionId||t[16]!==n.warning||t[17]!==s||t[18]!==a||t[19]!==d?(f=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(gK,{autoOpenDraft:!1,readOnly:a,sessionId:n.sessionId,sessionDirectory:n.directory,sessionViewKey:d,composerSurface:n.composerSurface,hostedFeatures:s,assistantHistory:n.assistantHistory,pendingUserMessages:n.pendingUserMessages,onPendingUserMessagesMaterialized:n.onPendingUserMessagesMaterialized,onRevertMessage:n.onRevertMessage,warning:n.warning})}),t[9]=n.assistantHistory,t[10]=n.composerSurface,t[11]=n.directory,t[12]=n.onPendingUserMessagesMaterialized,t[13]=n.onRevertMessage,t[14]=n.pendingUserMessages,t[15]=n.sessionId,t[16]=n.warning,t[17]=s,t[18]=a,t[19]=d,t[20]=f):f=t[20];let p;return t[21]!==u||t[22]!==f?(p=(0,$.jsx)(Cb.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},bK=e=>{let t=(0,Q.c)(16),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({explicitSession:n,runtimeKey:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=vr(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Sb({...n,directory:o}),t[4]=o,t[5]=n,t[6]=s):s=t[6];let c=s,l=`explicit:${i}:${n.viewKey}`,u;t[7]!==o||t[8]!==n.active||t[9]!==n.sessionId||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(gK,{...r,active:n.active,sessionId:n.sessionId,sessionDirectory:o,sessionViewKey:l})}),t[7]=o,t[8]=n.active,t[9]=n.sessionId,t[10]=r,t[11]=l,t[12]=u):u=t[12];let d;return t[13]!==c||t[14]!==u?(d=(0,$.jsx)(Cb.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},xK=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(rK,u,u);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(yK,{...e,host:e.host,runtimeKey:n},r),t[0]=e,t[1]=n,t[2]=r,t[3]=i):i=t[3],i}if(e.explicitSession){let r=`${n}:${e.explicitSession.viewKey}`,i;return t[4]!==e.active||t[5]!==e.autoOpenDraft||t[6]!==e.explicitSession||t[7]!==e.readOnly||t[8]!==n||t[9]!==r?(i=(0,$.jsx)(bK,{autoOpenDraft:e.autoOpenDraft,readOnly:e.readOnly,active:e.active,explicitSession:e.explicitSession,runtimeKey:n},r),t[4]=e.active,t[5]=e.autoOpenDraft,t[6]=e.explicitSession,t[7]=e.readOnly,t[8]=n,t[9]=r,t[10]=i):i=t[10],i}let r;return t[11]!==e||t[12]!==n?(r=(0,$.jsx)(vK,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r},SK=2e4,CK=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus()?`visible`:`hidden`,wK=e=>{if(!h()&&!Fn())return;let t=S();t?.push?.setVisibility&&t.push.setVisibility({visible:e,platform:In()})},TK=e=>{let t=e?.enabled??!0;Z.useEffect(()=>{if(!t||!h()&&!Fn()||typeof window>`u`)return;if(Fn()){let e=!0,t=!1,n=null,r=()=>wK(e);Mn(async()=>{let{App:e}=await import(`./vendor-capacitor-app-B5H_XtmE.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([77,1,20])).then(async({App:i})=>{if(t)return;let a=await i.getState().catch(()=>null);a&&(e=a.isActive===!0),r();let o=await i.addListener(`appStateChange`,({isActive:t})=>{e=t===!0,r()});if(t){o.remove();return}n=()=>void o.remove()}).catch(()=>void 0);let i=window.setInterval(()=>{e&&wK(!0)},SK);return()=>{t=!0,window.clearInterval(i),n?.()}}if(typeof document>`u`)return;let e=()=>{wK(CK()===`visible`)},n=()=>{CK()===`visible`&&wK(!0)},r=()=>{wK(!1)};e();let i=window.setInterval(n,SK);return document.addEventListener(`visibilitychange`,e),window.addEventListener(`pagehide`,r),window.addEventListener(`pageshow`,e),window.addEventListener(`focus`,e),window.addEventListener(`blur`,e),()=>{window.clearInterval(i),document.removeEventListener(`visibilitychange`,e),window.removeEventListener(`pagehide`,r),window.removeEventListener(`pageshow`,e),window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,e)}},[t])},EK=`Yuri`,DK=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``).split(`/`).filter(Boolean);return t[t.length-1]??``},OK=(e,t)=>[e,t,EK].filter(e=>typeof e==`string`&&e.trim().length>0).join(` | `),kK=()=>{let e=pa(e=>{if(!e.activeProjectId)return null;let t=e.projects.find(t=>t.id===e.activeProjectId);return t&&DK(t.path)||null}),[t,n]=Z.useState(null);Z.useEffect(()=>{if(typeof window>`u`||!x()){n(null);return}let e=!1,t=async()=>{try{if(g()){e||n(null);return}let t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,r=d();if(r&&j(r,t)){e||n(null);return}let i=(await M()).hosts.find(e=>r?j(r,P(e)):!1),a=i?.label?.trim()?T(i.label.trim()):`Instance`;e||n(a)}catch{e||n(`Instance`)}};t();let r=()=>{t()};return window.addEventListener(`focus`,r),()=>{e=!0,window.removeEventListener(`focus`,r)}},[]);let r=Z.useMemo(()=>OK(e,t),[e,t]);Z.useEffect(()=>{typeof document<`u`&&(document.title=r),x()&&(async()=>{try{if(typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``))return;await nr(r)}catch{return}})()},[r])},AK=e=>{let t=[];return e.hideGit||t.push(`git`),t.push(`files`),e.showBrowser&&t.push(`browser`),t},jK=e=>e===`git`||e===`files`||e===`browser`,MK=()=>{let e=Da.getState().currentSessionId;if(!e)return``;let t=Ne().find(t=>t.id===e);return typeof t?.directory==`string`?t.directory:``},NK=async(e,t=6e3)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t),i=Date.now();try{let t=await f(e,{method:`GET`,headers:{Accept:`application/json`},signal:n.signal}),r=Date.now()-i,a=t.headers.get(`content-type`)||``,o=a.toLowerCase(),s=o.includes(`json`)&&!o.includes(`text/html`),c=``;if(s){let e=await t.json().catch(()=>null);if(Array.isArray(e))c=`json[array] len=${e.length}`;else if(e&&typeof e==`object`){let t=Object.keys(e).slice(0,8);c=`json[object] keys=${t.join(`,`)}${Object.keys(e).length>t.length?`,…`:``}`}else c=`json[${typeof e}]`}else c=a?`content-type=${a}`:`no content-type`;return{ok:t.ok&&s,status:t.status,elapsedMs:r,summary:c}}catch(e){return{ok:!1,status:0,elapsedMs:Date.now()-i,summary:`error=${n.signal.aborted||e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))?`timeout after ${t}ms`:e instanceof Error?e.message:String(e)}`}}finally{clearTimeout(r)}},PK=e=>{if(!e||!Number.isFinite(e))return`(n/a)`;try{return new Date(e).toISOString()}catch{return`(invalid)`}},FK=e=>{if(typeof e==`number`&&Number.isFinite(e)&&e>0)return Math.trunc(e);if(typeof e==`string`){let t=Number.parseInt(e,10);if(Number.isFinite(t)&&t>0)return t}return null},IK=e=>!!e&&typeof e==`object`&&!Array.isArray(e),LK=(e,t=`(n/a)`)=>typeof e==`string`?e.trim()||t:typeof e==`number`&&Number.isFinite(e)?String(e):typeof e==`boolean`?e?`true`:`false`:t,RK=(e,t,n)=>e===`node-shebang`||e===`node-launcher`?t?`node (${t})`:`node`:e===`bun-shebang`?n?`bun (${n})`:`bun`:e||`direct executable`,zK=async()=>{let e=new Date,t=typeof navigator<`u`?navigator.userAgent:`(no navigator)`,n=MK(),r=K.getState().eventStreamStatus,i=typeof window<`u`?window.location.origin:``,o=a(),s=o.health(),c=o.api(`/api/`),l=await(async()=>{if(!s)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),5e3);try{let t=await f(s,{method:`GET`,headers:{Accept:`application/json`},signal:e.signal});if(!t.ok)return null;let n=await t.json().catch(()=>null);return!n||typeof n!=`object`||Array.isArray(n)?null:n}catch{return null}finally{clearTimeout(t)}})(),u=await(async()=>{if(!c)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),7e3);try{let t=await f(o.api(`/api/config/opencode-resolution`),{method:`GET`,headers:{Accept:`application/json`},signal:e.signal}),n=t.headers.get(`content-type`)||`(none)`;if(!t.ok)return{data:null,status:t.status,error:`http ${t.status} content-type=${n}`};let r=await t.text(),i=null;try{i=JSON.parse(r)}catch{let e=r.replace(/\s+/g,` `).slice(0,120);return{data:null,status:t.status,error:`invalid json content-type=${n} body=${e||`(empty)`}`}}return!i||typeof i!=`object`||Array.isArray(i)?{data:null,status:t.status,error:`invalid json-shape content-type=${n}`}:{data:i,status:t.status,error:null}}catch(e){return{data:null,status:null,error:e instanceof Error?e.message:String(e)}}finally{clearTimeout(t)}})()||{data:null,status:null,error:null},d=(e,t=!0)=>{if(!c)return null;let r=new URL(e.replace(/^\/+/,``),c);return t&&n&&r.searchParams.set(`location[directory]`,n),r.toString()},p=c?await Promise.all([{label:`health`,path:`/info`,includeDirectory:!1},{label:`config`,path:`/config`,includeDirectory:!0},{label:`providers`,path:`/provider`,includeDirectory:!0},{label:`agents`,path:`/agent`,includeDirectory:!0,timeoutMs:12e3},{label:`commands`,path:`/command`,includeDirectory:!0,timeoutMs:1e4},{label:`project`,path:`/project`,includeDirectory:!1},{label:`location`,path:`/location`,includeDirectory:!0},{label:`sessions`,path:`/session`,includeDirectory:!0,timeoutMs:12e3},{label:`sessionActive`,path:`/session/active`,includeDirectory:!1}].map(async e=>{let t=d(e.path,e.includeDirectory!==!1);if(!t)return{label:e.label,url:`(none)`,result:null};let n=await NK(t,typeof e.timeoutMs==`number`?e.timeoutMs:void 0);return{label:e.label,url:t,result:n}})):[],m=[];m.push(`Time: ${e.toISOString()}`),m.push(`Yuri version: 0.2.27-beta.2`),m.push(`Runtime: ${i||`(unknown)`} (api=${c||`(unknown)`})`),m.push(`OpenCode SDK base: ${se.getBaseUrl()}`),m.push(`Event stream: ${r}`),m.push(`Directory: ${n||`(none)`}`),m.push(`Platform: ${t}`);let h=FK(l?.openCodePort);if(m.push(`OpenCode runtime port: ${h??`(unknown)`}`),typeof l?.openCodeRunning==`boolean`&&m.push(`OpenCode runtime running: ${l.openCodeRunning?`yes`:`no`}`),typeof l?.openCodeSecureConnection==`boolean`&&m.push(`Secure OpenCode connection: ${l.openCodeSecureConnection?`true`:`false`}`),typeof l?.openCodeAuthSource==`string`&&l.openCodeAuthSource.trim()&&m.push(`OpenCode auth source: ${l.openCodeAuthSource}`),typeof l?.openCodeServeVersion==`string`&&l.openCodeServeVersion.trim()&&m.push(`OpenCode serve version: ${l.openCodeServeVersion}`),typeof l?.openCodeCliVersion==`string`&&l.openCodeCliVersion.trim()&&m.push(`OpenCode CLI version: ${l.openCodeCliVersion}`),IK(l?.runtimeContract)){let e=l.runtimeContract,t=typeof e.phase==`string`?e.phase:`(unknown)`,n=e.executionAllowed===!0?`allowed`:`limited`,r=e.protocolCompatible===!0?`compatible`:`incompatible`;m.push(`OpenCode runtime contract: phase=${t} protocol=${r} execution=${n}`),Array.isArray(e.reasons)&&e.reasons.length>0&&m.push(`OpenCode contract reasons: ${e.reasons.filter(e=>typeof e==`string`).join(`, `)}`)}if(typeof window<`u`){let e=window.__YURI_MACOS_MAJOR__;typeof e==`number`&&Number.isFinite(e)&&e>0&&m.push(`macOS major: ${e}`)}if(/Mac OS X|Macintosh/.test(t)){m.push(``),m.push(`OpenCode CLI resolution:`);let e=IK(l?.lastOpenCodeLaunchDiagnostics)?l.lastOpenCodeLaunchDiagnostics:null,t=e&&Array.isArray(e.args)?e.args.filter(e=>typeof e==`string`):[],n=u.data,r=n&&typeof n.configured==`string`?n.configured:null,i=n&&typeof n.resolved==`string`?n.resolved:l&&typeof l.opencodeBinaryResolved==`string`?l.opencodeBinaryResolved:``,a=n&&typeof n.resolvedDir==`string`?n.resolvedDir:``,o=n&&typeof n.source==`string`?n.source:l&&typeof l.opencodeBinarySource==`string`?l.opencodeBinarySource:``,s=n&&typeof n.launchBinary==`string`?n.launchBinary:l&&typeof l.opencodeLaunchBinary==`string`?l.opencodeLaunchBinary:``,c=n&&typeof n.launchWrapperType==`string`?n.launchWrapperType:l&&typeof l.opencodeLaunchWrapperType==`string`?l.opencodeLaunchWrapperType:``,d=n&&Array.isArray(n.launchArgs)?n.launchArgs.filter(e=>typeof e==`string`):l&&Array.isArray(l.opencodeLaunchArgs)?l.opencodeLaunchArgs.filter(e=>typeof e==`string`):[],f=n&&typeof n.node==`string`?n.node:l&&typeof l.nodeBinaryResolved==`string`?l.nodeBinaryResolved:``,p=n&&typeof n.bun==`string`?n.bun:l&&typeof l.bunBinaryResolved==`string`?l.bunBinaryResolved:``,h=n&&typeof n.detectedNow==`string`?n.detectedNow:``,g=n&&typeof n.detectedSourceNow==`string`?n.detectedSourceNow:``;if(r!==null&&m.push(`- configured: ${r.trim().length===0?`(cleared)`:r}`),i){let e=a||(i.includes(`/`)?i.split(`/`).slice(0,-1).join(`/`)||`/`:``);m.push(`- opencode: ${i}${e?` (dir=${e})`:``}`)}else m.push(`- opencode: (n/a)`);m.push(`- source: ${o||`(n/a)`}`),h&&(m.push(`- detected-now: ${h}`),m.push(`- detected-source: ${g||`(n/a)`}`)),e?(m.push(`- launched-at: ${LK(e.launchedAt)}`),m.push(`- launch: ${LK(e.binary)} ${t.join(` `)}`.trim()),m.push(`- cwd: ${LK(e.cwd)}`),m.push(`- wrapper: ${LK(e.wrapperType)}`),m.push(`- runtime: ${RK(LK(e.wrapperType,``),f,p)}`),m.push(`- PATH entries: ${LK(e.pathEntryCount,`(unknown)`)}`),m.push(`- shell env: ${LK(e.hasShellEnv,`(unknown)`)} (${LK(e.shellEnvKeysCount,`?`)} keys)`)):(m.push(`- launch-binary: ${s||`(n/a)`}`),m.push(`- launch-wrapper: ${c||`(n/a)`}`),m.push(`- launch-args: ${d.length?d.join(` `):`(none)`}`),m.push(`- runtime: ${RK(c||``,f,p)}`)),!n&&u.error&&m.push(`- resolution-endpoint: ${u.error}`)}if(m.push(``),p.length){m.push(`OpenCode API probes:`);for(let e of p){if(!e.result){m.push(`- ${e.label}: (no url)`);continue}let{ok:t,status:n,elapsedMs:r,summary:i}=e.result,a=t?``:` url=${e.url}`;m.push(`- ${e.label}: ${t?`ok`:`fail`} status=${n} time=${r}ms ${i}${a}`)}}else m.push(`OpenCode API probes: (skipped)`);return m.push(``),m.push(`Generated: ${PK(Date.now())}`),m.join(`
6605
+ `)}function TH(e,t=80){let n=wH(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var EH=new Set;function DH(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(EH),a,o;return n[0]!==e||n[1]!==t?(a=()=>{let n=e?.current;if(i(EH),!n||!t||typeof IntersectionObserver>`u`)return;let r=new Map,a=new Set,o=()=>{let e=new Set;for(let t of a){let n=r.get(t);n&&e.add(n)}i(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},s=new IntersectionObserver(e=>{for(let t of e)r.has(t.target)&&(t.isIntersecting&&t.intersectionRect.height>0?a.add(t.target):a.delete(t.target));o()},{root:n,threshold:0}),c=OH,l=e=>{if(r.has(e))return;let n=e.dataset.scrollSpyId??e.dataset.turnId??e.dataset.messageId,i=n?t.get(n):void 0;i&&(r.set(e,i),s.observe(e))},u=e=>{s.unobserve(e),r.delete(e),a.delete(e)};c(n,l);let d=new MutationObserver(e=>{for(let t of e){if(t.type===`attributes`&&t.target instanceof HTMLElement){u(t.target),l(t.target);continue}t.removedNodes.forEach(e=>c(e,u)),t.addedNodes.forEach(e=>c(e,l))}o()});return d.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`data-turn-id`,`data-message-id`,`data-scroll-spy-id`]}),()=>{d.disconnect(),s.disconnect()}},o=[e,t],n[0]=e,n[1]=t,n[2]=a,n[3]=o):(a=n[2],o=n[3]),Z.useEffect(a,o),r}function OH(e,t){e instanceof HTMLElement&&(e.matches(`[data-turn-id], [data-message-id]`)&&t(e),e.querySelectorAll(`[data-turn-id], [data-message-id]`).forEach(t))}var kH=160,AH=28,jH=12,MH=6,NH=30,PH=12,FH=18,IH=80,LH=4,RH=10,zH=14,BH=20,VH=48,HH=160,UH=(e,t)=>e.map(e=>{let n=t.get(e)??[],r=wH(n),i=T_(r,{citationIcons:j_(n)}),a=[],o=0;for(let e of i)a.push(r.slice(o,e.start)),o=e.end;a.push(r.slice(o));let s=a.join(` `).replace(/\s+/g,` `).trim();return{turnId:e,preview:s.length>kH?`${s.slice(0,kH)}…`:s}}),WH=[1,.6,.35,.15],GH=(e,t,n)=>{let r=n?zH:RH;if(t===null)return r;let i=WH[Math.abs(e-t)]??0;return Math.round(r+(BH-r)*i)};function KH({turnIds:e,previewsByTurnId:t,activeTurnId:n,scrollRef:r,turnByMessageId:i,repliesByTurnId:a,onSelectTurn:o,canLoadEarlier:s,isLoadingOlder:c,onLoadEarlier:l}){let{t:u}=Xn(),d=DH(r,i),f=K(e=>e.isPromptNavigatorPanelOpen),p=K(e=>e.setPromptNavigatorPanelOpen),m=Z.useRef(null),h=Z.useRef(null),[g,_]=Z.useState(null),[v,y]=Z.useState(0),[b,x]=Z.useState(!1);Z.useEffect(()=>{let e=h.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){x(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.left+MH+AH;x(r.left<i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let S=Z.useMemo(()=>UH(e,t),[t,e]),C=Math.min(S.length,NH),w=Math.max(0,S.length-C),T=Math.min(v,w),E=T+C,D=T>0,O=E<S.length,k=u(`chat.timeline.noTextContent`),A=u(`chat.promptNavigator.loadMore`),j=Z.useMemo(()=>n?S.findIndex(e=>e.turnId===n):-1,[n,S]),M=Z.useRef(T);M.current=T;let N=Z.useRef(S.length);N.current=S.length;let P=Z.useRef(null),F=Z.useRef(null),I=Z.useRef(0),L=Z.useCallback(e=>{y(t=>{let n=N.current,r=Math.min(n,NH),i=Math.max(0,n-r),a=Math.min(t,i);return e<a?e:e>=a+r?Math.min(i,e-r+1):a})},[]),R=Z.useRef(S[0]?.turnId),z=Z.useRef(S.length);Z.useLayoutEffect(()=>{let e=R.current,t=z.current,n=S.length-t;n>0&&t>0&&e&&S[0]?.turnId!==e&&(y(e=>e+n),_(e=>e===null?null:e+n)),R.current=S[0]?.turnId,z.current=S.length},[S]),Z.useEffect(()=>{if(g!==null)return;let e=j>=0?j:S.length-1;y(()=>{let t=N.current,n=Math.min(t,NH),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[j,g,S.length]);let B=Z.useCallback(e=>{let t=m.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/PH),i=Math.min(N.current,NH);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),V=Z.useCallback(()=>{I.current=0,F.current!==null&&(window.clearInterval(F.current),F.current=null)},[]),H=Z.useCallback(()=>{let e=I.current;if(e===0){V();return}let t=N.current,n=Math.max(0,t-Math.min(t,NH)),r=Math.min(M.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){V();return}M.current=i,y(i);let a=P.current;if(a!==null){let e=B(a);e!==null&&_(Math.min(t-1,i+e))}},[B,V]),U=Z.useCallback(e=>{let t=m.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=FH&&D?i=-1:r>=n.height-FH&&O&&(i=1),I.current=i,i===0){V();return}F.current===null&&(F.current=window.setInterval(H,IH))},[H,D,O,V]);Z.useEffect(()=>()=>{F.current!==null&&window.clearInterval(F.current)},[]);let W=Z.useRef(null),ee=Z.useCallback(()=>{W.current!==null&&(window.clearTimeout(W.current),W.current=null)},[]),te=Z.useCallback(()=>{ee(),W.current=window.setTimeout(()=>{W.current=null,_(null)},HH)},[ee]);Z.useEffect(()=>()=>{W.current!==null&&window.clearTimeout(W.current)},[]);let ne=Z.useCallback(e=>{ee(),P.current=e.clientY;let t=B(e.clientY);t!==null&&_(Math.min(N.current-1,M.current+t)),U(e.clientY)},[ee,B,U]),re=Z.useCallback(()=>{P.current=null,V(),te()},[te,V]),G=Z.useCallback(()=>{p(!1)},[p]),ie=Z.useCallback(e=>{if(e===null)return;let t=S[e];t&&(o(t.turnId),V(),_(null),G(),m.current?.blur())},[G,o,S,V]),ae=Z.useCallback(e=>{let t=B(e.clientY);t!==null&&ie(Math.min(S.length-1,M.current+t))},[ie,S.length,B]);Z.useEffect(()=>{if(!f)return;let e=m.current;!e||e===document.activeElement||(e.focus(),_(e=>{if(e!==null)return e;let t=j>=0?j:S.length-1;return L(t),t}))},[j,L,f,S.length]),Z.useEffect(()=>()=>{p(!1)},[p]);let oe=Z.useCallback(e=>{if(S.length===0)return;let t=g??(j>=0?j:S.length-1),n=e=>{let t=Math.max(0,Math.min(S.length-1,e));L(t),_(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(S.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),ie(t);return}e.key===`Escape`&&(e.preventDefault(),_(null),G(),m.current?.blur())},[j,G,L,ie,g,S.length]),se=Z.useCallback(()=>{V(),_(null),G()},[G,V]),ce=Z.useRef(null),le=Z.useRef(g);le.current=g;let ue=g!==null,de=Z.useRef(0);Z.useEffect(()=>{let e=ce.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),de.current+=e.deltaY;let t=Math.trunc(de.current/VH);if(t===0)return;de.current-=t*VH;let n=le.current;if(n===null)return;let r=Math.max(0,Math.min(N.current-1,n+t));r!==n&&(L(r),_(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[L,ue]);let fe=g===null?void 0:S[g],pe=fe?a?.get(fe.turnId):void 0,me=Math.max(0,T-LH),he=Math.min(S.length,E+LH),ge=S.slice(me,he),_e=D||O?`linear-gradient(to bottom, ${D?`transparent, black 14%`:`black`}, ${O?`black 86%, transparent`:`black`})`:void 0;return S.length===0?null:(0,$.jsx)(`nav`,{ref:h,"aria-label":u(`chat.promptNavigator.aria`),className:`pointer-events-none absolute left-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-start`,children:[s?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-ml-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,c?`cursor-wait opacity-70`:void 0),"aria-label":A,title:A,disabled:c,onClick:e=>{e.stopPropagation(),c||l()},children:c?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:m,role:`listbox`,tabIndex:-1,"aria-activedescendant":fe?`prompt-rail-tick-${fe.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${b?jH:AH}px`,height:`${C*PH}px`},onMouseMove:ne,onMouseLeave:re,onClick:ae,onKeyDown:oe,onBlur:se,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:_e?{maskImage:_e,WebkitMaskImage:_e}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${T*PH}px)`},children:ge.map((e,t)=>{let n=me+t,r=d.has(e.turnId),i=g===n,a=GH(n,g,r);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":i,"aria-current":r?`true`:void 0,"aria-label":e.preview.trim()||k,className:`pointer-events-none absolute left-1 flex items-center justify-start`,style:{top:`${n*PH}px`,height:`${PH}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,r?`bg-[var(--surface-foreground)]`:i?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${a}px`}})},e.turnId)})},S[0]?.turnId)}),fe&&g!==null?(0,$.jsxs)(`div`,{ref:ce,className:Y(`pointer-events-auto absolute left-full z-30 ml-3 -translate-y-1/2`,`w-[min(20rem,calc(100vw-6rem))] overflow-hidden rounded-xl`,`bg-[var(--surface-elevated)] p-3 typography-meta`),style:{top:`${(g-T+.5)*PH}px`},onMouseEnter:ee,onMouseLeave:te,onMouseMove:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),ie(g)},children:[(0,$.jsx)(`p`,{className:`truncate font-medium leading-relaxed text-[var(--surface-foreground)]`,children:fe.preview||k}),pe?(0,$.jsx)(`p`,{className:`mt-2 line-clamp-4 whitespace-pre-line [overflow-wrap:anywhere] leading-relaxed text-[var(--surface-mutedForeground)]`,children:pe}):null]}):null]})]})})}var qH=100,JH=(e,t)=>{if(e.length===0)return;let n=0,r=e.length-1,i=0;for(;n<=r;){let a=n+r>>1,o=e[a]?.top;if(o===void 0)break;if(o<=t){i=a,n=a+1;continue}r=a-1}return e[i]?.id},YH=e=>{let t=e.raf??requestAnimationFrame,n=e.caf??cancelAnimationFrame,r=e.ResizeObserver??globalThis.ResizeObserver,i=e.MutationObserver??globalThis.MutationObserver,a,o,s,c,l,u,d=!0,f=new Map,p=[],m=()=>{c===void 0&&(c=t(()=>{c=void 0,g()}))},h=()=>{let e=a;if(!e){p=[],d=!1;return}let t=e.getBoundingClientRect().top;p=[...f].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),p.sort((e,t)=>e.top-t.top),d=!1},g=()=>{let t=a;if(!t)return;d&&h();let n=JH(p,t.scrollTop+qH);!n||n===u||(u=n,e.onActive(n))},_=()=>{let e=a;if(e){if(clearTimeout(l),l=void 0,o?.disconnect(),o=void 0,r){o=new r(()=>{clearTimeout(l),l=setTimeout(()=>{d=!0,m()},100)}),o.observe(e);for(let e of f.values())o.observe(e)}if(s?.disconnect(),s=void 0,i){s=new i(()=>{d=!0,m()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}d=!0,m()}},v=e=>{a!==e&&(a=e,u=void 0,_())},y=(e,t)=>{let n=f.get(t);n&&n!==e&&o?.unobserve(n),f.set(t,e),o&&o.observe(e),d=!0,m()},b=e=>{let t=f.get(e);t&&(o?.unobserve(t),f.delete(e),d=!0,m())},x=()=>{d=!0,m()},S=()=>{for(let e of f.values())o?.unobserve(e);f.clear(),p=[],u=void 0,d=!0};return{setContainer:v,register:y,unregister:b,onScroll:m,markDirty:x,clear:S,destroy:()=>{c!==void 0&&n(c),c=void 0,clearTimeout(l),l=void 0,S(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>u}},XH=10,ZH=`${XH}vh`,QH=`56px`;`${QH}`;var $H=(e,t)=>e?56:t<=0?96:Math.max(48,XH/100*t),eU=(e,t)=>({sessionId:e,viewportKey:t}),tU=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,nU=(e,t)=>tU(e,t),rU=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),iU=150,aU=1500,oU=2,sU=350,cU=600,lU=8e3,uU=24,dU=2,fU=(e,t)=>e<t,pU=()=>typeof performance<`u`?performance.now():Date.now(),mU=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),hU=e=>e.scrollHeight-e.scrollTop-e.clientHeight,gU=e=>hU(mU(e)),_U=e=>e.scrollHeight-e.clientHeight>1,vU=(e,t)=>hU(e)<=$H(t,e.clientHeight),yU=({enabled:e=!0,scrollControllerRef:t,currentSessionId:n,viewportKey:r,sessionMessageCount:i,sessionIsWorking:a,isMobile:o,onActiveTurnChange:s,onUpwardUserIntent:c})=>{let l=Z.useRef(null),[u,d]=Z.useState(null),f=Z.useRef(null),[p,m]=Z.useState(`following`),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(`following`),S=Z.useRef(o);S.current=o;let C=Z.useRef(i);C.current=i;let w=Z.useRef(eU(n,r));w.current=eU(n,r);let T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(null),O=Z.useRef(0),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(0),M=Z.useRef(!1),N=Z.useRef(!1),P=Z.useRef(null),F=Z.useRef(0),I=Z.useRef(!1),L=Z.useRef(null),R=Z.useRef(null),z=J(()=>{F.current=pU()+450,R.current=null}),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(0),ee=Z.useRef(!1),te=Z.useRef(null),ne=Z.useRef(null),re=Z.useRef(null),G=Ko(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{l.current!==f.current&&(f.current=l.current,d(l.current))});let ie=J(e=>{x.current!==e&&(x.current=e,m(e))}),ae=J(e=>{E.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:pU()},D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{E.current=null,D.current=null},aU)}),oe=J(e=>{let t=E.current;return t?pU()-t.time>aU?(E.current=null,!1):Math.abs(e.scrollTop-t.top)<oU:!1}),se=J(()=>pU()<j.current),ce=J(()=>{V.current=!1,H.current&&=(clearTimeout(H.current),null),U.current&&=(clearTimeout(U.current),null)}),le=J(()=>{H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,ce()},cU)}),ue=J(()=>{let e=l.current;e&&(V.current=!0,W.current=e.scrollHeight,le(),U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{U.current=null,ce()},lU))}),de=J(e=>{let t=l.current;if(!t){g(!1),v(!1);return}let n=e??mU(t),r=_U(n);if(g(r),!r){v(!1);return}let i=x.current===`released`&&!vU(n,S.current);v(i)}),fe=J(()=>{O.current+=1,k.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(k.current),k.current=null),A.current?.(),A.current=null});Z.useEffect(()=>()=>fe(),[u]);let pe=J(()=>{if(!e)return;let n=l.current;if(!n)return;if(fe(),t?.current?.scrollToBottom({behavior:`auto`,reveal:!1})){ae(n),de();return}let r=O.current,i=n.style.overflowX,a=n.style.overflowY,o=n.style.scrollBehavior;n.style.scrollBehavior=`auto`,n.style.overflow=`hidden`,n.scrollTop=n.scrollHeight,n.scrollHeight,n.style.overflowX=i,n.style.overflowY=a,n.style.scrollBehavior=o;let s=()=>{ae(n),n.scrollTop=n.scrollHeight,B.current=n.scrollTop};if(s(),de(),typeof window>`u`)return;let c=0,u=()=>{fU(pU(),F.current)||fe()};n.addEventListener(`touchstart`,u,{passive:!0,once:!0}),A.current=()=>n.removeEventListener(`touchstart`,u);let d=()=>{if(r===O.current){if(gU(n)>dU&&s(),c+=1,c>=uU){k.current=null,A.current?.(),A.current=null,de();return}k.current=window.requestAnimationFrame(d)}};k.current=window.requestAnimationFrame(d)}),me=J(e=>{let n=l.current;if(n&&(ae(n),!t?.current?.scrollToBottom({behavior:e,reveal:!1}))){if(e===`smooth`){n.scrollTo({top:n.scrollHeight,behavior:e});return}n.scrollTop=n.scrollHeight}}),he=J((t,n=`auto`)=>{if(!e)return;let r=l.current;if(t&&x.current!==`following`&&ie(`following`),r&&!(!t&&x.current!==`following`)){if(gU(r)<oU){ae(r);return}me(t?n:`auto`)}}),ge=J(e=>{let t=l.current;if(!t)return;let n=e??mU(t);_U(n)&&x.current!==`released`&&(ie(`released`),de(n))}),_e=J((e=`instant`,n)=>{if(I.current=!1,ee.current=!1,ie(`following`),ce(),fe(),t?.current?.scrollToBottom({behavior:e===`smooth`?`smooth`:`auto`,...n})){let e=l.current;e&&ae(e),de();return}if(e===`instant`){pe();return}fe(),he(!0,`smooth`),de()}),ve=J(()=>{ee.current=!1,he(!0)}),ye=J(()=>{I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ie(`released`),de()}),be=J(()=>{let t=yO(),n=l.current;if(!e||!n||!t||!n.contains(t.target)||!t.following||!t.range||R.current)return;let r=mU(n);if(!_U(r))return;let i=t.range.getBoundingClientRect?.();if(!i||!i.height)return;let a=n.getBoundingClientRect(),o=Math.min(96,n.clientHeight*.2),s=S.current?o:0;if(i.top>=a.top+s&&i.bottom<=a.bottom-s)return;let c=Math.min(r.scrollHeight-r.clientHeight,Math.max(0,r.scrollTop+i.top-a.top-o));Math.abs(c-r.scrollTop)<=1||(ye(),n.scrollTo({top:c,behavior:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`instant`:`smooth`}),B.current=n.scrollTop)});Z.useEffect(()=>(be(),xO(be)),[e,u,be]);let xe=J(()=>{ee.current=!0,ye()}),Se=J(()=>{ee.current=!1}),Ce=Z.useRef(c);Ce.current=c;let we=J(()=>{l.current&&CO(l.current),!fU(pU(),F.current)&&(I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ge())}),Te=J(()=>{F.current=0,we(),Ce.current?.()}),Ee=J(()=>{te.current!==null&&(clearTimeout(te.current),te.current=null);let e=ne.current;if(e){if(!e.identity.sessionId){ne.current=null;return}G(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),ne.current=null}}),De=J(()=>{let e=w.current;if(!e.sessionId)return;let t=l.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r>0?(n+i/2)/r:0,o=Math.floor(a*C.current);ne.current=rU(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),te.current===null&&(te.current=setTimeout(()=>{te.current=null,Ee()},iU))}),Oe=J(()=>{Ee()}),ke=J(async(e=w.current)=>{if(!e.sessionId||x.current===`released`&&tU(e,T.current))return!1;ee.current=!1;let t=l.current;return t?(re.current=null,ie(`following`),z(),S.current?pe():he(!0),B.current=t.scrollTop,ue(),de(),!1):(re.current=e,ie(`following`),!1)});Z.useEffect(()=>{let e=w.current,t=T.current;tU(e,t)||(Ee(),fe(),z(),T.current=e,I.current=!1,L.current=null,E.current=null,B.current=0,ce(),ee.current=!1,ie(`following`),re.current=null,n&&n!==t?.sessionId&&UO.getInstance().recordSessionStart(n))},[n,r]),Z.useEffect(()=>{a&&!ee.current&&x.current===`following`&&he(!0)},[a]),Z.useEffect(()=>{b(p===`following`&&a)},[p,a]),Z.useLayoutEffect(()=>{if(!u)return;let e=re.current;e&&nU(e,w.current)&&ke(e)},[u,n,r]);let Ae=J(()=>{let e=l.current;if(!e)return;let t=mU(e),n=B.current;B.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;de(t);let a=yO();if(a&&e.contains(a.target)){De();return}if(ee.current){De();return}if(_U(t)){if(vU(t,S.current)){let e=Math.min(n,Math.max(0,t.scrollHeight-t.clientHeight));if(t.scrollTop<e-.5){we(),De();return}(x.current===`following`||r&&I.current)&&(ie(`following`),I.current=!1),De();return}if(x.current===`following`&&(oe(e)||se()||i)){M.current||he(!1),De();return}(x.current===`following`||!r)&&we(),De()}});Z.useEffect(()=>{!e||!u||(B.current=u.scrollTop)},[u,e]);let je=J(e=>{let t=l.current;if(t){if(e.deltaY!==0&&CO(t),e.deltaY>0){Ol(t,e.target)||(I.current=!0);return}e.deltaY>=0||zl(t,e.target)||Te()}}),Me=J(e=>{I.current=!1;let t=e.touches.item(0);R.current=t?{x:t.clientX,y:t.clientY,dx:0,dy:0}:null}),Ne=J(e=>{let t=l.current,n=e.touches.item(0);if(!n){R.current=null;return}let r=R.current;if(!r)return;let i=n.clientY-r.y,a=i*r.dy<0,o=(a?0:r.dx)+n.clientX-r.x,s=(a?0:r.dy)+i;if(R.current={x:n.clientX,y:n.clientY,dx:o,dy:s},!(Math.abs(o)>=Math.abs(s))&&t){if(Math.abs(s)>2&&CO(t),s<-2){Ol(t,e.target)||(I.current=!0);return}if(!(s<=0)){if(zl(t,e.target)){R.current.dx=0,R.current.dy=0;return}s<=2||Te()}}}),Pe=J(()=>{R.current=null}),Fe=J(e=>{let t=e.target;if(!(e.defaultPrevented||t instanceof HTMLElement&&(t.isContentEditable||t.closest(`input, textarea, select`)))){if(l.current&&[`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `].includes(e.key)&&CO(l.current),!e.altKey&&!e.ctrlKey&&!e.metaKey&&[`ArrowDown`,`PageDown`,`End`].includes(e.key)){let e=l.current;e&&!Ol(e,t)&&(I.current=!0);return}Fl(e)&&Te()}}),Ie=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&(F.current=0,we(),L.current={id:e.pointerId,y:e.clientY})}),Le=J(e=>{let t=L.current;!t||t.id!==e.pointerId||(e.clientY!==t.y&&(I.current=e.clientY>t.y),t.y=e.clientY)}),Re=J(()=>{L.current=null}),ze=J(()=>{I.current=!1}),Be=Z.useMemo(()=>()=>void 0,[]),Ve=e&&u?u:Be,He=Z.useMemo(()=>({passive:!0}),[]);Wn(`scroll`,Ae,Ve,He),Wn(`scrollend`,ze,Ve,He),Wn(`wheel`,je,Ve,He),Wn(`touchstart`,Me,Ve,He),Wn(`touchmove`,Ne,Ve,He),Wn(`touchend`,Pe,Ve,He),Wn(`touchcancel`,Pe,Ve,He),Wn(`keydown`,Fe,Ve),Wn(`pointermove`,Le,e&&typeof window<`u`?window:Be,!0),Wn(`pointerup`,Re,e&&typeof window<`u`?window:Be,!0),Wn(`pointercancel`,Re,e&&typeof window<`u`?window:Be,!0),Wn(`pointerdown`,Ie,e&&typeof window<`u`?window:Be,!0);let Ue=J(()=>{let e=l.current;if(M.current){de(e?mU(e):void 0);return}if(ee.current){de(e?mU(e):void 0);return}if(!e){de(void 0);return}let t=mU(e);if(!_U(t)){de(t);return}if(de(t),V.current){let n=t.scrollHeight>W.current+1;W.current=t.scrollHeight,hU(t)<=oU?ae(e):he(!0),n&&le();return}if(x.current===`following`){if(hU(t)<=oU){ae(e);return}he(!1)}}),We=typeof ResizeObserver<`u`,Ge=We&&e?u:null,Ke=We&&e&&u&&u.firstElementChild instanceof Element?u.firstElementChild:null;qn(Ge,Ue),qn(Ke,Ue);let qe=J(()=>{P.current!==null&&(clearTimeout(P.current),P.current=null)}),Je=J(e=>{M.current=!0,typeof e==`number`&&e>0?j.current=pU()+e+sU:j.current=Math.max(j.current,pU()+sU)}),Ye=J(e=>{let t=e.detail;if(t){if(t.open===!0){Je(),qe(),P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},1500);return}qe(),Je()}}),Xe=J(e=>{let t=e.detail;t&&(qe(),Je(t.durationMs))}),Ze=J(e=>{let t=e.detail;qe(),t?.open===!0?(N.current=!0,M.current=!0):(N.current=!1,M.current=!0,P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},sU)),de()}),Qe=e&&typeof window<`u`?window:Be;Wn(`yuri:keyboard-intent`,Ye,Qe),Wn(`yuri:keyboard-anim`,Xe,Qe),Wn(`yuri:keyboard-settled`,Ze,Qe),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{qe(),M.current=!1,N.current=!1}},[e]),Z.useEffect(()=>{e&&de()},[e,i]);let $e=J(t=>{if(e){if(t===`animation`&&(j.current=pU()+sU),de(),V.current){he(!0),le();return}x.current===`following`&&he(!1)}}),et=Z.useRef(new Map),tt=J(t=>{let n=et.current.get(t);if(n)return n;let r=()=>{e&&x.current===`following`&&he(!1)},i={onChunk:r,onComplete:()=>{e&&de()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return et.current.set(t,i),i});Z.useEffect(()=>()=>{D.current&&=(clearTimeout(D.current),null),fe(),ce(),Ee(),te.current!==null&&(clearTimeout(te.current),te.current=null)},[]);let nt=J(e=>{s?.(e)}),rt=!!s;return Z.useEffect(()=>{if(!e||!rt)return;let t=u;if(!t)return;let n=null,r=YH({onActive:e=>{e!==n&&(n=e,nt(e))}});r.setContainer(t);let i=new Map,a=e=>{let t=e.dataset.turnId;return t?(i.set(t,e),r.register(e,t),!0):!1},o=e=>{let t=e.dataset.turnId;return!t||i.get(t)!==e?!1:(i.delete(t),r.unregister(t),!0)},s=e=>{if(!(e instanceof HTMLElement))return[];let t=[];return e.matches(`[data-turn-id]`)&&t.push(e),e.querySelectorAll(`[data-turn-id]`).forEach(e=>t.push(e)),t};t.querySelectorAll(`[data-turn-id]`).forEach(a),r.markDirty();let c=new MutationObserver(e=>{let t=!1;e.forEach(e=>{e.removedNodes.forEach(e=>{s(e).forEach(e=>{o(e)&&(t=!0)})}),e.addedNodes.forEach(e=>{s(e).forEach(e=>{a(e)&&(t=!0)})})}),t&&r.markDirty()});c.observe(t,{subtree:!0,childList:!0});let l=()=>r.onScroll();return t.addEventListener(`scroll`,l,{passive:!0}),()=>{t.removeEventListener(`scroll`,l),c.disconnect(),r.destroy()}},[u,e,rt]),{scrollRef:l,state:p,isPinned:p===`following`,isOverflowing:h,isFollowingProgrammatically:y,showScrollButton:_,notifyContentChange:$e,getAnimationHandlers:tt,goToBottom:_e,scrollToBottomOnSend:ve,releaseAutoFollow:ye,beginHistoryViewportPreservation:xe,endHistoryViewportPreservation:Se,saveSnapshotNow:Oe,restoreSnapshot:ke}},bU=`--yuri-mobile-header-collapse`,xU=e=>e.closest(`.mobile-chat-screen`)?.querySelector(`:scope > [data-yuri-collapsible-header="true"]`)??null,SU=e=>{e.style.removeProperty(bU),delete e.dataset.yuriHeaderCollapsePhase,delete e.dataset.yuriHeaderCollapseRest},CU=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest===`compact`?`collapsed`:`expanded`;return n?.phase!==i&&(e.dataset.yuriHeaderCollapsePhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty(bU,r),n?.rest!==a&&(e.dataset.yuriHeaderCollapseRest=a),{progress:r,phase:i,rest:a}},wU=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),TU=`data-yuri-timeline-park-end`,EU=e=>{if(!e)return null;let t=e.getAttribute(TU);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},DU=(e,t)=>t!==null&&Number.isFinite(t)?wU({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),OU=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),kU=()=>{let e=document.documentElement;return e.classList.contains(`yuri-keyboard-open`)||e.classList.contains(`yuri-kb-animating`)},AU=e=>{if(kU()||e.querySelector(`[data-yuri-composer-dictation-active="true"]`)||e.querySelector(`[data-composer-height-snap="full"], [data-mobile-composer-resizing="true"]`))return!0;let t=document.activeElement;return t instanceof HTMLElement&&t.matches(`textarea[data-chat-input="true"]`)&&e.contains(t)},jU=e=>{let t=Z.useRef(fE()),n=Z.useRef(void 0),r=Z.useRef(void 0),i=Z.useRef(null),a=Z.useRef(null),o=Z.useRef(0),s=Z.useRef(!1),c=Z.useRef(0),l=Z.useRef(new Map),u=Z.useRef(!1),d=Z.useRef(0),f=Z.useRef(null),p=Z.useRef(null),m=Z.useRef({direction:null,px:0,at:0}),h=Z.useRef(e.enabled);h.current=e.enabled;let g=e=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null)},_=Z.useRef(null),v=e=>{let t=_.current;if(t&&t!==e&&t.parentElement===e)return t;let i=AE(e);return i!==t&&(_.current=i,n.current=void 0,r.current=void 0),i},y=Z.useRef(null),b=Z.useRef(void 0),x=(e,t)=>{let n=y.current;(!n||!n.isConnected)&&(n=xU(e),y.current=n,b.current=void 0),n&&(b.current=CU(n,t,b.current))},S=J(t=>{let r=e.scopeRef.current;if(!r)return;let i=v(r);n.current=NE(r,t,n.current,i),x(r,t)}),C=J(e=>{let n=_.current,r=v(e);return r===n?x(e,t.current):S(t.current),r}),w=J(e=>{e!==t.current&&(t.current=e,S(e))}),T=J(()=>{if(g(a),t.current.phase!==`snapping`)return;let e=t.current.rest;a.current=window.setTimeout(()=>{a.current=null;let n=wE(t.current);w(n),n.rest===`compact`&&e===`compact`&&(o.current=Date.now()+320,s.current=!0)},240)}),E=J(()=>{let n=e.scopeRef.current;!n||!h.current||w(gE(t.current,AU(n)))}),D=J(e=>s.current?Date.now()>=o.current?(s.current=!1,!1):e>=80?(s.current=!1,o.current=0,!1):!0:!1),O=()=>{m.current={direction:null,px:0,at:0}},k=()=>{let e=m.current;return!e.direction||e.px<16||e.direction===`expanded`&&(f.current??0)>=120||Date.now()-e.at>250?null:e.direction},A=J(()=>{if(g(i),!h.current||c.current>0||t.current.phase!==`tracking`)return;let e=CE(t.current,k());w(e),T()}),j=J(()=>{u.current=!1,d.current=0;for(let e of l.current.values())e.startX=e.currentX,e.startY=e.currentY}),M=J(e=>{if(!h.current)return;let t=!1;for(let n=0;n<e.changedTouches.length;n+=1){let r=e.changedTouches[n];if(!r)continue;let i=l.current.get(r.identifier);if(!i){l.current.set(r.identifier,{startX:r.clientX,startY:r.clientY,currentX:r.clientX,currentY:r.clientY});continue}i.currentX=r.clientX,i.currentY=r.clientY;let a=Math.abs(i.currentX-i.startX),o=Math.abs(i.currentY-i.startY);o>=6&&o>a&&(t=!0)}!t&&!u.current||(u.current=!0,d.current=Date.now(),s.current=!1,o.current=0)}),N=J(t=>{if(h.current){if(c.current===0){l.current.clear(),j(),O();let t=e.scrollRef.current;if(t){let e=OU(t);p.current=e,f.current=DU(e,EU(t))}}for(let e=0;e<t.changedTouches.length;e+=1){let n=t.changedTouches[e];n&&l.current.set(n.identifier,{startX:n.clientX,startY:n.clientY,currentX:n.clientX,currentY:n.clientY})}c.current=l.current.size,g(i)}}),P=J(()=>{if(!h.current)return;let n=e.scrollRef.current,o=e.scopeRef.current;if(!n||!o)return;let s=AU(o),l=OU(n),_=DU(l,EU(n)),v=f.current,y=p.current;if(f.current=_,p.current=l,n.hasAttribute(`data-yuri-timeline-anchoring`)){O(),j();return}let b=C(o);r.current=ME(o,_,r.current,b);let x=u.current&&(c.current>0||Date.now()-d.current<=1200),S=y!==null&&(y.scrollHeight!==l.scrollHeight||y.clientHeight!==l.clientHeight),E=x&&!S,k=l.scrollTop<0||y!==null&&y.scrollTop<0,M=E&&!k&&v!==null;if(!M)O();else if(_!==v){let e=_>v?`compact`:`expanded`,t=m.current,n=Math.abs(_-v);m.current={direction:e,px:t.direction===e?t.px+n:n,at:Date.now()}}let N=t.current,P=gE(N,s);if(s||(P=xE(P,_,{previousDistance:M?v:null,suppressReturn:E&&D(_),userDriven:E})),w(P),E){if(g(i),P.phase===`snapping`){(N.phase!==`snapping`||N.rest!==P.rest||N.progress!==P.progress)&&T();return}N.phase===`snapping`&&g(a),P.phase===`tracking`&&c.current===0&&(i.current=window.setTimeout(()=>{i.current=null,A()},120))}}),F=J(()=>{u.current&&(c.current>0||Date.now()-d.current<=1200)&&A()}),I=J((e,n)=>{if(h.current){for(let t=0;t<e.changedTouches.length;t+=1){let n=e.changedTouches[t];n&&l.current.delete(n.identifier)}c.current=l.current.size,!(c.current>0)&&(l.current.clear(),n&&u.current?d.current=Date.now():j(),t.current.phase===`tracking`&&(g(i),i.current=window.setTimeout(()=>{i.current=null,A()},120)))}}),L=J(e=>{I(e,!0)}),R=J(e=>{I(e,!1)}),z=J(()=>{let t=e.scopeRef.current;if(!t||typeof window>`u`)return;let n=e=>{e.preventDefault(),e.stopPropagation()};t.addEventListener(`pointerup`,n,!0),t.addEventListener(`click`,n,!0),window.setTimeout(()=>{t.removeEventListener(`pointerup`,n,!0),t.removeEventListener(`click`,n,!0)},240)}),B=J(n=>{if(!h.current)return;let r=n.target;if(!(r instanceof Element)||!r.closest(`[data-yuri-composer-compact-surface="true"]`)||r.closest(`[data-composer-action="true"]`))return;let i=r.closest(`.yuri-mobile-composer-compact-preview`);n.type===`pointerdown`&&i||n.type===`click`&&!i||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),O(),w(_E(t.current,`expanded`)),T(),z(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0}))}),[V,H]=Z.useState(null),[U,W]=Z.useState(null),ee=Z.useRef(null),te=J(e=>{e&&jE(e,_.current??e),y.current&&SU(y.current),y.current=null,b.current=void 0,_.current=null,n.current=void 0,r.current=void 0,s.current=!1,o.current=0,c.current=0,l.current.clear(),u.current=!1,d.current=0,f.current=null,p.current=null,O(),w(fE())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;ee.current&&ee.current!==n&&te(ee.current),ee.current=n,n&&C(n),H(e=>e===t?e:t),W(e=>e===n?e:n)});let ne=Z.useMemo(()=>()=>void 0,[]),re=e.enabled&&V?V:ne,G=e.enabled&&U?U:ne,ie=e.enabled&&typeof window<`u`?window:ne,ae=Z.useMemo(()=>({passive:!0}),[]);Wn(`scroll`,P,re,ae),Wn(`scrollend`,F,re,ae),Wn(`touchstart`,N,re,ae),Wn(`touchmove`,M,re,ae),Wn(`touchend`,L,re,ae),Wn(`touchcancel`,R,re,ae),Wn(`pointerdown`,B,G),Wn(`click`,B,G),Wn(`focusin`,E,G),Wn(`focusout`,E,G),Wn(`yuri:keyboard-intent`,E,ie),Wn(`yuri:keyboard-anim`,E,ie),Wn(`yuri:keyboard-settled`,E,ie),Z.useEffect(()=>{if(!e.enabled){te(ee.current),ee.current=null;return}return E(),P(),()=>{g(i),g(a)}},[e.enabled,V,U])},MU=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},NU=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},PU=e=>{if(!e)return null;let t=MU(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${NU(e)??``}`},FU=e=>({turnIds:[...e.turnIds],turnMessageStartIndexes:[...e.turnMessageStartIndexes],turnIndexById:new Map(e.turnIndexById),messageToTurnId:new Map(e.messageToTurnId),messageToTurnIndex:new Map(e.messageToTurnIndex),turnCount:e.turnCount}),IU=(e,t,n)=>{if(!e||!t)return null;if(t.length===n.length){let r=-1;for(let e=0;e<n.length;e+=1)if(t[e]!==n[e]){if(r!==-1)return null;r=e}return r===-1||r===n.length-1&&PU(t[r])===PU(n[r])?e:null}if(n.length!==t.length+1)return null;for(let e=0;e<t.length;e+=1)if(t[e]!==n[e])return null;let r=n[n.length-1];if(!r)return null;let i=MU(r),a=r.info.id,o=FU(e);if(i===`user`){let e=o.turnIds.length;return o.turnIds.push(a),o.turnMessageStartIndexes.push(n.length-1),o.turnIndexById.set(a,e),o.messageToTurnId.set(a,a),o.messageToTurnIndex.set(a,e),o.turnCount=o.turnIds.length,o}if(i!==`assistant`){let e=o.turnIds.length-1;if(e<0)return null;let t=o.turnIds[e];return t?(o.messageToTurnId.set(a,t),o.messageToTurnIndex.set(a,e),o):null}let s=NU(r);if(!s)return o;let c=o.turnIndexById.get(s);if(typeof c!=`number`||c<0)return null;let l=o.turnIds[c];return l?(o.messageToTurnId.set(a,l),o.messageToTurnIndex.set(a,c),o):null},LU=e=>{let t=[],n=[],r=new Map,i=new Map,a=new Map,o=new Map,s=-1;return e.forEach((e,c)=>{let l=MU(e),u=e.info.id;if(l===`user`){s=t.length,t.push(u),n.push(c),r.set(u,s),o.set(u,s),i.set(u,u),a.set(u,s);return}if(l!==`assistant`){if(s>=0){let e=t[s];e&&(i.set(u,e),a.set(u,s))}return}let d=NU(e);if(!d)return;let f=o.get(d);if(typeof f!=`number`||f<0)return;let p=t[f];p&&(i.set(u,p),a.set(u,f))}),{turnIds:t,turnMessageStartIndexes:n,turnIndexById:r,messageToTurnId:i,messageToTurnIndex:a,turnCount:t.length}},RU=200,zU={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},BU=()=>RU,VU=()=>Math.round(BU()*.6),HU={MAX_SESSIONS:zU.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(RU*.6),HISTORICAL_MESSAGES:RU,FETCH_BUFFER:20,HISTORY_CHUNK:RU,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:zU.ZOMBIE_TIMEOUT},UU=()=>{let e=BU(),t=VU();return{...HU,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},WU=HU,GU=600,KU=6e3,qU=.5,JU=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),YU=e=>{let t=e.getBoundingClientRect(),n=e.querySelectorAll(`[data-message-id]`);for(let e of n)if(e.getBoundingClientRect().bottom>t.top)return e;return null},XU=(e,t)=>{let n=JU(e,t);if(n||=YU(e),!n)return null;let r=n.dataset.messageId;if(!r)return null;let i=e.getBoundingClientRect();return{messageId:r,offsetTop:n.getBoundingClientRect().top-i.top}},ZU=e=>{let{container:t,quiesceMs:n=GU,maxLifetimeMs:r=KU}=e,i={messageId:e.anchor.messageId,offsetTop:e.anchor.offsetTop},a=!1,o=e.pending??!1,s=null,c=null,l=!1,u=!1,d=t.scrollTop,f=()=>{s!==null&&(clearTimeout(s),s=null)},p=()=>{c!==null&&(clearTimeout(c),c=null)},m=()=>{a||(a=!0,x.disconnect(),t.removeEventListener(`scroll`,b),f(),p())},h=()=>{f(),!(a||o)&&(s=setTimeout(()=>{s=null,m()},n))},g=()=>{p(),!(a||o)&&(c=setTimeout(()=>{c=null,m()},r))},_=()=>{if(a)return;let e=XU(t,i.messageId);if(!e){m();return}i.messageId=e.messageId,i.offsetTop=e.offsetTop,d=t.scrollTop,u=!1},v=()=>{if(a)return;if(e.isUserScrolling?.()){u=!0;return}if(u){_();return}if(Math.abs(t.scrollTop-d)>qU){_();return}let n=JU(t,i.messageId);if(!n){let e=YU(t);if(!e){m();return}let r=e.dataset.messageId;if(!r){m();return}let a=t.getBoundingClientRect();i.messageId=r,i.offsetTop=e.getBoundingClientRect().top-a.top,n=e,d=t.scrollTop}let r=t.getBoundingClientRect(),o=n.getBoundingClientRect().top-r.top-i.offsetTop;Math.abs(o)>qU&&(t.scrollTop+=o),d=t.scrollTop},y=()=>{a||l||(l=!0,queueMicrotask(()=>{l=!1,v()}))},b=()=>{e.isUserScrolling?.()?u=!0:(u||Math.abs(t.scrollTop-d)>qU)&&_(),h(),g()},x=new MutationObserver(()=>{a||(y(),h())});return x.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`style`,`class`]}),t.addEventListener(`scroll`,b,{passive:!0}),g(),h(),{rebase:_,dispose:m,settle(){a||!o||(o=!1,h(),g())}}},QU=30,$U=1200,eW=1.5,tW=e=>Math.max($U,e*eW),nW=4,rW=30,iW=4,aW=30,oW=250,sW=800,cW=1e4,lW=1500,uW=2e3,dW=dr+2e3,fW=40,pW=`history-loading-timeout`,mW=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),hW=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=pW,e},gW=(e,t,n)=>{if(e===`no-growth`){console.error(`[chat-history] load older completed without prepending messages`,t instanceof Error?t:Error(`chat history pagination returned no growth`),n);return}if(e===`timeout`){console.error(`[chat-history] load older timed out waiting for sync pagination`,t,n);return}console.error(`[chat-history] load older failed`,t,n)},_W=2500,vW=new Map,yW=()=>b()?nW:Po()?iW:QU,bW=e=>b()?e.length<=rW:!Po()||e.length<=aW,xW=(e,t)=>{if(vW.delete(e),!bW(t.messages))return;let n=yW();for(;vW.size>=n;){let e=vW.keys().next().value;if(typeof e!=`string`)break;vW.delete(e)}vW.set(e,t)},SW=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),CW=e=>e?{owner:`tanstack-core`}:{owner:`controller`},wW=(e,t)=>e?e.canLoadEarlier:t>=UU().HISTORICAL_MESSAGES,TW=e=>!(e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=tW(e.clientHeight)),EW=e=>e.hasMoreAbove?e.scrollHeightAfter-e.scrollHeightBefore>1?`stop-visible`:e.messageCountAfter>e.messageCountBefore||typeof e.oldestIdBefore==`string`&&typeof e.oldestIdAfter==`string`&&e.oldestIdBefore!==e.oldestIdAfter||e.cursorBefore==null&&e.limitAfter>e.limitBefore||typeof e.cursorAfter==`string`&&e.cursorAfter!==e.cursorBefore?e.pagesLoaded>=e.maxPages?`stop-bounded`:`continue`:`stop-no-growth`:`stop-exhausted`,DW=8,OW=1,kW=8,AW=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],jW=80,MW=new WeakMap,NW=e=>{let t=e?MW.get(e):void 0;return!!(t&&(t.touches>0||performance.now()-t.lastScrollAt<160))},PW=e=>{let t=MW.get(e);t&&(t.touches=0,t.lastScrollAt=-1/0,t.pending=null,t.settleScheduled=!1)},FW=e=>{IW(e)},IW=e=>{let t=MW.get(e);if(t)return t;let n={touches:0,lastScrollAt:-1/0,pending:null,settleScheduled:!1};e.addEventListener(`touchstart`,()=>{n.touches+=1},{passive:!0});let r=()=>{n.touches=Math.max(0,n.touches-1),n.touches===0&&n.pending&&LW(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),e.addEventListener(`scroll`,()=>{n.lastScrollAt=performance.now()},{passive:!0}),MW.set(e,n),n},LW=(e,t)=>{t.settleScheduled||typeof window>`u`||(t.settleScheduled=!0,window.requestAnimationFrame(()=>{t.settleScheduled=!1;let n=t.pending;t.pending=null,!(!n||t.touches>0||!e.isConnected)&&(Math.abs(e.scrollTop-n.anchorTop)>n.delta+jW||RW(e,n.anchorTop+n.delta))}))},RW=(e,t)=>{let n=e.style.overflowX,r=e.style.overflowY;e.style.overflow=`hidden`,e.scrollTop=t,e.scrollHeight,e.style.overflowX=n,e.style.overflowY=r,e.scrollTop=t},zW=(e,t,n)=>{let r=IW(e);if(r.touches>0&&typeof n==`number`&&n>0){r.pending=r.pending?{anchorTop:r.pending.anchorTop,delta:r.pending.delta+n}:{anchorTop:e.scrollTop,delta:n};return}r.pending=null,RW(e,t)},BW=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),VW=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:a,loadMoreMessages:o,goToBottom:s,releaseAutoFollow:l,beginHistoryViewportPreservation:d,endHistoryViewportPreservation:f,isPinned:p,showScrollButton:m,isMobile:h,onWillLoadEarlier:g})=>{let _=Z.useRef(h);_.current=h;let v=Z.useRef(null),y=Z.useRef(null),b=Z.useMemo(()=>{let t=e??``,r=t?vW.get(t):void 0;if(r&&r.messages===n)return xW(t,r),v.current=r.model,y.current=n,r.model;let i=IU(v.current,y.current,n)??LU(n);return v.current=i,y.current=n,t&&n.length>0&&xW(t,{messages:n,model:i}),i},[n,e]),[x,S]=Z.useState(!1),[C,w]=Z.useState(!1),[T,E]=Z.useState(null),D=Z.useRef(0),O=u(),k=c(),A=Z.useMemo(()=>({runtimeKey:O,runtimeGeneration:k,sessionId:e,directory:t}),[O,k,e,t]),j=Z.useRef(A);j.current=A;let M=`chat-history-error:${JSON.stringify([O,t??null,e])}`;Jn(()=>(j.current=A,()=>{j.current===A&&(j.current=null),Yr.dismiss(M)}),[A,M]);let N=Z.useRef(b),P=Z.useRef(p),F=Z.useRef(x),I=Z.useRef(C),L=Z.useRef(e),R=Z.useRef(t??null),z=Z.useRef(n),B=Z.useRef(r),V=Z.useRef([]),H=Z.useRef(!1),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),te=Z.useRef(!1),ne=Z.useRef(null),re=Z.useRef({authorized:!1,consumed:!1,top:0}),G=Z.useRef(null),ie=J(()=>{re.current={authorized:!1,consumed:F.current,top:i.current?.scrollTop??0}}),ae=()=>h?i.current??void 0:void 0,se=J(e=>{e.repeat||ie()});Wn(`touchstart`,ie,ae,{passive:!0,capture:!0}),Wn(`wheel`,ie,ae,{passive:!0,capture:!0}),Wn(`keydown`,se,ae,{capture:!0});let[ce,le]=Z.useState(A);ce!==A&&(le(A),ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),te.current=!1,F.current=!1,ee.current=null,S(!1),w(!1),E(null),D.current=0,re.current={authorized:!1,consumed:!1,top:0},G.current=null);let ue=Z.useMemo(()=>{let e=wW(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),de=Z.useRef(ue);N.current=b,P.current=p,I.current=C,de.current=ue,L.current=e,R.current=t??null,z.current=n,B.current=r,Jn(()=>{r?.complete&&Yr.dismiss(M)},[r?.complete,M]);let fe=J(()=>{te.current=!0,ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null)}),pe=J(()=>{if(typeof window>`u`){te.current=!1;return}ne.current!==null&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>{ne.current=null,te.current=!1},uW)}),me=J(()=>{let e=V.current;e.length!==0&&(V.current=[],e.forEach(e=>e()))}),he=J((e=!1)=>new Promise(t=>{if(typeof window>`u`){t();return}let n=!1,r=j.current,i=Date.now()+cW,a=()=>{n||(n=!0,window.clearTimeout(s),V.current=V.current.filter(e=>e!==a),t())},o=()=>{if(e&&r===j.current&&H.current&&Date.now()<i){s=window.setTimeout(o,i-Date.now());return}a()};V.current.push(a);let s=window.setTimeout(o,oW)})),ge=J(e=>{let t=W.current;t&&(W.current=null,t.resolve(e))}),_e=J(()=>{let e=W.current;if(e){if(e.sessionId!==L.current){ge(!1);return}if(e.kind===`turn`?a.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:a.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(ee.current={turnId:e.turnId,expiresAt:Date.now()+_W},E(e.turnId)),ge(!0);return}typeof(e.kind===`turn`?N.current.turnIndexById.get(e.id):N.current.messageToTurnIndex.get(e.id))==`number`&&ge(!1)}}),ve=Z.useRef(null),ye=J(()=>{let e=ve.current;e&&(ve.current=null,e.dispose())});Un(()=>{ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),ye(),me(),ge(!1)});let be=Z.useRef({scope:A,at:-1/0}),xe=()=>{!h&&!Po()&&(be.current={scope:A,at:Date.now()})};Wn(`wheel`,e=>{e.deltaY!==0&&e.target instanceof Node&&i.current?.contains(e.target)&&xe()},void 0,{passive:!0,capture:!0}),Wn(`scroll`,e=>{e.target===i.current&&xe()},void 0,{passive:!0,capture:!0});let Se=()=>be.current.scope===A&&Date.now()-be.current.at<sW,[Ce,we]=Z.useState({scope:A,messages:n}),Te=Po(),Ee=Ce.scope===A&&Ce.messages!==n&&BW(Ce.messages[0]?.info?.id??null,n[0]?.info?.id??null,n)&&(Te?!a.current?.isHistoryVirtualized()&&NW(i.current):!h&&Ce.messages.at(-1)===n.at(-1)&&Se()),De=Ee?Ce.messages:n;H.current=Ee&&!h&&!Te,(Ce.scope!==A||Ce.messages!==De)&&we({scope:A,messages:De});let[,Oe]=Z.useReducer(e=>e+1,0);Jn(()=>{me(),_e()},[De]);let ke=Z.useRef(null),Ae=J(()=>a.current?.captureViewportAnchor()??null),je=J(e=>a.current?.restoreViewportAnchor(e)??!1),Me=J(()=>{if(ye(),a.current?.isHistoryVirtualized())return;let e=i.current;if(!e)return;let t=Ae();if(t)return ve.current=ZU({container:e,anchor:t,pending:!0,isUserScrolling:Po()?()=>NW(e):void 0}),ve.current}),Ne=Z.useRef(null);Kn(J(()=>{let e=i.current;if(!e||!Ee||!Te&&Se())return;let t=e.scrollHeight;Ne.current={oldestId:De[0]?.info?.id??null,newestId:De.at(-1)?.info?.id??null,scrollHeight:t};let n=ke.current;if(n){let r={...n,height:t,top:e.scrollTop,anchor:Ae()};ke.current=Te?r:Object.assign(n,r)}Oe()}),Ee?50:null);let Pe=Z.useRef(null);Jn(()=>{if(!Po())return;let e=i.current;if(!e){Pe.current=null;return}let t=Pe.current;(t?.container!==e||t.scope!==A)&&(FW(e),PW(e),Pe.current={container:e,scope:A})}),Jn(()=>{ye(),U.current=null,me(),ke.current=null,Ne.current=null,a.current?.cancelViewportAnchorHold()},[A]),Jn(()=>{let e=i.current;if(!e)return;let t=ke.current;a.current?.isHistoryVirtualized()&&ye(),t&&Math.abs(e.scrollTop-t.top)>kW&&(ke.current=null,t=null);let n=Ne.current,r=De[0]?.info?.id??null,o=De[De.length-1]?.info?.id??null,c=n?SW({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:o})||BW(n.oldestId,r,De):!1;t&&t.sessionId!==L.current&&(ke.current=null,t=null);let l=t?SW({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:o})||BW(t.oldestId,r,De):!1,u=c||l,d=e=>{Ne.current={oldestId:r,newestId:o,scrollHeight:e??Ne.current?.scrollHeight??null}};if(P.current&&!t){ye(),u?(ke.current=null,s(`instant`,{reveal:!1}),d(e.scrollHeight)):d();return}let f=CW(a.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){a.current?.cancelViewportAnchorHold();let e=t.anchor;e&&je(e),d();return}let n=e.scrollHeight,r=n-t.height;if(Po()){r>0&&zW(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&je(i))&&r>0&&(e.scrollTop=t.top+r),ve.current?.rebase(),d(n);return}if(c&&n&&f.owner===`controller`){let t=e.scrollHeight,r=n.scrollHeight===null?0:t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;Po()?zW(e,t,r):e.scrollTop=t}d(t),Me();return}d()},[De,s]),Jn(()=>{if(H.current)return;let e=U.current;U.current=null,e?.()},[De]);let Fe=J(async()=>!1),Ie=J(async e=>{let t=j.current,n=()=>t===j.current&&t?.runtimeKey===u()&&t?.runtimeGeneration===c(),r=Date.now(),i=r+dW,a=R.current,o=a?Ve()?.getRequestState?.(oe(a,e)):void 0;for(de.current.historyLoading,B.current,o?.status,o?.error;de.current.historyLoading;){if(!n()||L.current!==e)return Date.now()-r,`switched`;if(Date.now()>=i){let t=a?Ve()?.getRequestState?.(oe(a,e)):void 0;return console.error(`[chat-history] historyLoading wait timed out — sync flag still true`,{sessionId:e,directory:a,elapsedMs:Date.now()-r,waitMs:dW,hostTurnPageTimeoutMs:dr,historyLoading:de.current.historyLoading,historyMeta:B.current,requestStatusAtStart:o?.status??null,requestStatusAtTimeout:t?.status??null,requestErrorAtTimeout:t?.error??null,likelyStaleLoadingFlag:t?.status===`ready`||t?.status===`error`||t==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,fW)})}return Date.now()-r,a&&Ve()?.getRequestState?.(oe(a,e))?.status,n()&&L.current===e?`cleared`:`switched`}),Le=J(async e=>{if(!L.current||F.current||H.current||!de.current.hasMoreAboveTurns)return!1;F.current=!0,fe(),S(!0);let t=L.current,n=j.current,r=()=>n===j.current&&n?.runtimeKey===u()&&n?.runtimeGeneration===c(),s=()=>n?.directory?Ve()?.getPagination(oe(n.directory,t)).cursor??null:null,l=M,p=null,m=null,h=!!e.userInitiated;h&&d();let g=()=>{if(r()){if(H.current){U.current=g;return}m?.settle(),p&&ke.current===p&&(ke.current=null,a.current?.cancelViewportAnchorHold()),h&&(h=!1,f())}};try{if(de.current.historyLoading){if(!e.userInitiated)return!1;let n=await Ie(t);if(n===`timeout`)throw hW();if(n===`switched`||!de.current.hasMoreAboveTurns)return!1}if(!r()||!L.current||L.current!==t)return!1;let n=i.current,a=z.current,c=a.length,u=a[0]?.info?.id??null,d=B.current?.limit??UU().HISTORICAL_MESSAGES;e.preserveViewport&&n&&(p={sessionId:L.current,height:n.scrollHeight,top:n.scrollTop,anchor:Ae(),oldestId:u,newestId:a[a.length-1]?.info?.id??null},ke.current=p,Ne.current={oldestId:p.oldestId,newestId:p.newestId,scrollHeight:p.height},m=Me()??null);let f=c,h=u,_=d,v=0,y=0;for(;;){if(de.current.historyLoading)if(e.userInitiated){let e=await Ie(t);if(e===`timeout`)throw g(),hW();if(e===`switched`)return g(),!1}else return g(),!1;let n=i.current?.scrollHeight??0,a=f,c=h,u=_,d=s();if(await o(t,`up`),v+=1,!r()||L.current!==t)return g(),!1;if(await he(!0),!r())return!1;if(H.current)return!0;let p=(()=>{let t=z.current;return EW({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:a,messageCountAfter:t.length,oldestIdBefore:c,oldestIdAfter:t[0]?.info?.id??null,limitBefore:u,limitAfter:B.current?.limit??_,cursorBefore:d,cursorAfter:s(),hasMoreAbove:de.current.hasMoreAboveTurns,pagesLoaded:v,maxPages:e.singlePage?1:DW})})();if(p===`continue`){let e=z.current;f=e.length,h=e[0]?.info?.id??null,_=B.current?.limit??_;continue}if(p===`stop-no-growth`){if(e.singlePage)return g(),!1;if(de.current.historyLoading){if(e.userInitiated){let e=await Ie(t);if(e===`timeout`)throw g(),hW();if(e===`switched`)return g(),!1;--v;continue}return g(),!1}if(y<OW){y+=1,--v;continue}return D.current=Date.now()+lW,g(),!1}return D.current=0,Yr.dismiss(l),!0}}catch(e){throw r()&&(D.current=Date.now()+lW),g(),e}finally{r()&&(F.current=!1,S(!1),pe(),H.current?g():he(!0).then(g))}}),{t:Re}=Xn(),ze=q({mutationKey:AW({runtimeKey:u(),sessionId:e??``}),mutationFn:async e=>{if(j.current!==e.scope||u()!==e.scope.runtimeKey||c()!==e.scope.runtimeGeneration||L.current!==e.sessionId)return!1;fe(),e.userInitiated&&l();try{return await Le({preserveViewport:!0,userInitiated:!!e.userInitiated,singlePage:e.singlePage})}finally{j.current===e.scope&&c()===e.scope.runtimeGeneration&&pe()}}}),Be=J(async e=>{let t=L.current;if(!t||!de.current.canLoadEarlier)return;let n=A,r=M,i=()=>j.current===n&&u()===n.runtimeKey&&c()===n.runtimeGeneration;if(!(ze.isPending&&ze.variables?.sessionId===t&&ze.variables?.scope===n)){e?.userInitiated&&g?.();try{let r=await ze.mutateAsync({sessionId:t,scope:n,userInitiated:!!e?.userInitiated,singlePage:e?.singlePage});if(!i())return;if(r===!1&&de.current.canLoadEarlier){let n={sessionId:t,grew:r,userInitiated:!!e?.userInitiated,canLoadEarlier:de.current.canLoadEarlier,hasMoreAboveTurns:de.current.hasMoreAboveTurns,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};gW(`no-growth`,Error(`chat history pagination returned no growth`),n)}}catch(n){let a={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:dW,hostTurnPageTimeoutMs:dr,canLoadEarlier:de.current.canLoadEarlier,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};mW(n)?gW(`timeout`,n,a):gW(`failed`,n,a),i()&&e?.userInitiated&&Yr.error(mW(n)?Re(`chat.history.loadOlderTimeout`):Re(`chat.history.loadOlderFailed`),{id:r})}}}),He=ze.isPending&&ze.variables?.sessionId===e&&ze.variables?.scope===A||x,Ue=J(e=>{if(Date.now()<D.current)return;let t=i.current;if(t){if(_.current){let n=re.current,r=t.scrollTop<n.top;if(n.top=t.scrollTop,n.consumed||(e===`upward-intent`&&(n.authorized=!0),!n.authorized||e===`scroll`&&!r))return}else if(F.current){G.current=null;return}else if(e===`upward-intent`)G.current={top:t.scrollTop};else{let e=G.current;if(!e)return;let n=t.scrollTop<e.top;if(t.scrollTop>e.top||P.current?G.current=null:e.top=t.scrollTop,!n)return}TW({source:e,isMobile:_.current,isPinned:P.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:de.current.canLoadEarlier,isLoadingOlder:F.current,pendingRevealWork:I.current})&&(_.current&&(re.current.consumed=!0),G.current=null,Be({userInitiated:!0,singlePage:_.current}))}}),We=J(()=>{Ue(`scroll`)}),Ge=J(()=>{!_.current&&!F.current&&!a.current?.isHistoryVirtualized()&&Me()?.settle(),Ue(`upward-intent`)}),Ke=J(async(t,n)=>{if(!t||!L.current)return!1;l(),w(!0);try{return L.current!==e||typeof N.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},_e()})}finally{w(!1)}}),qe=Z.useRef(null),Je=J(async(t,n)=>{if(!t||!L.current)return!1;let r=`${L.current}:${t}`;if(qe.current===r)return!1;qe.current=r;let i=L.current;l(),w(!0);try{if(L.current!==e)return!1;for(;!N.current.messageToTurnId.has(t)&&de.current.hasMoreAboveTurns;){if(L.current!==i||qe.current!==r)return!1;let e=z.current[0]?.info.id;if(await Be({userInitiated:!0,singlePage:!0}),await he(),z.current[0]?.info.id===e)break}if(L.current!==i||qe.current!==r)return!1;let a=N.current.messageToTurnId.get(t);return typeof N.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:a??null,resolve:r},_e()})}finally{qe.current===r&&(qe.current=null),w(!1)}}),Ye=J(async()=>{qe.current=null,w(!1),F.current=!1,S(!1),s(`smooth`)}),Xe=J(async()=>{w(!1),F.current=!1,S(!1),s(`instant`)}),Ze=J(e=>{let t=ee.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;ee.current=null}E(e)});return{turnIds:b.turnIds,turnStart:0,renderedMessages:De,historySignals:ue,isLoadingOlder:He,pendingRevealWork:C,activeTurnId:T,showScrollToBottom:m&&!C,turnWindowModel:b,loadEarlier:Be,revealBufferedTurns:Fe,resumeToBottom:Ye,resumeToBottomInstant:Xe,scrollToTurn:Ke,scrollToMessage:Je,handleHistoryScroll:We,handleHistoryUpwardIntent:Ge,captureViewportAnchor:Ae,restoreViewportAnchor:je,handleActiveTurnChange:Ze}},HW=12,UW=50,WW=800;function GW(e){let t=(0,Q.c)(25),{scope:n,enabled:i,cursor:a,loadedTurns:o,messages:s,scrollRef:c,loadPrevious:l}=e,[u,d]=Z.useState(null),f=Z.useRef(u),p=Z.useRef(!1),m=Z.useRef(null),h;t[0]!==u||t[1]!==a||t[2]!==i||t[3]!==o||t[4]!==n?(h=i&&!r()&&a!==null&&o<HW&&u!==n,t[0]=u,t[1]=a,t[2]=i,t[3]=o,t[4]=n,t[5]=h):h=t[5];let g=h,_;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{f.current=null,d(null)},t[6]=_):_=t[6];let v;t[7]===n?v=t[8]:(v=[n],t[7]=n,t[8]=v),Z.useEffect(_,v);let y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{m.current=null},t[9]=y):y=t[9];let b;t[10]!==a||t[11]!==g||t[12]!==s||t[13]!==n?(b=[n,g,a,s],t[10]=a,t[11]=g,t[12]=s,t[13]=n,t[14]=b):b=t[14],Z.useEffect(y,b);let x;t[15]!==g||t[16]!==c?(x=e=>{g&&e.deltaY!==0&&e.target instanceof Node&&c.current?.contains(e.target)&&(m.current=null)},t[15]=g,t[16]=c,t[17]=x):x=t[17];let S;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(S={passive:!0,capture:!0},t[18]=S):S=t[18],Wn(`wheel`,x,void 0,S);let C;t[19]!==a||t[20]!==g||t[21]!==l||t[22]!==n||t[23]!==c?(C=()=>{let e=c.current;if(f.current===n)return;if(!g||r()||!a||!e||p.current||document.visibilityState===`hidden`){m.current=null;return}let t=e.scrollHeight,i=e.scrollTop,o=m.current;if(!o||o.height!==t||o.top!==i){m.current={height:t,top:i,since:Date.now()};return}Date.now()-o.since<WW||(f.current=n,d(n),p.current=!0,l(UW).catch(KW).finally(()=>{p.current=!1}))},t[19]=a,t[20]=g,t[21]=l,t[22]=n,t[23]=c,t[24]=C):C=t[24],Kn(J(C),g?200:null)}function KW(e){console.error(`[chat-history] desktop history warmup failed`,e)}var qW=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),JW=({open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s=!1,isLoadingEarlier:c=!1,onLoadEarlier:l,onRevertMessage:u})=>{let{t:d}=Xn(),{isMobile:f}=$c(),[p,m]=Z.useState(null),[h,g]=Z.useState(``),[_,v]=Z.useState(0),y=Z.useRef(!1),b=Z.useRef(0),x=J(async(e,n,r)=>{if(y.current)return;y.current=!0;let i=b.current+1;b.current=i,m({type:e,messageId:n});try{await r(),t(!1)}finally{b.current===i&&(y.current=!1,m(null))}});if(!n)return null;let S=(0,$.jsx)(YW,{open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s,isLoadingEarlier:c,onLoadEarlier:l,onRevertMessage:u,searchQuery:h,onSearchQueryChange:g,selectedIndex:_,onSelectedIndexChange:v,pendingAction:p,runPendingMessageAction:x});return f?(0,$.jsx)(yl,{id:`conversation-timeline:${n}`,open:e,onOpenChange:t,title:(0,$.jsx)(`span`,{className:`yuri-timeline-mobile-title`,children:d(`chat.timeline.title`)}),ariaLabel:d(`chat.timeline.title`),closeAriaLabel:d(`mobile.surface.closeAria`),resizeAriaLabel:d(`mobile.sessions.sheet.resizeAria`),className:`yuri-timeline-mobile`,bodyClassName:`yuri-timeline-body`,children:S}):(0,$.jsx)(Ds,{open:e,onOpenChange:t,children:(0,$.jsx)(Cs,{presentation:`picker`,className:`yuri-timeline-dialog`,children:S})})},YW=e=>{let t=(0,Q.c)(109),{open:n,onOpenChange:r,sessionID:i,directory:a,onScrollToMessage:o,onScrollByTurnOffset:s,onResumeToLatest:c,canLoadEarlier:l,isLoadingEarlier:u,onLoadEarlier:d,onRevertMessage:f,searchQuery:p,onSearchQueryChange:m,selectedIndex:h,onSelectedIndexChange:g,pendingAction:_,runPendingMessageAction:v}=e,{t:y}=Xn(),b=wb(),x=i,S=ba(x??``,a),C=Da(ZW),w=Da(QW),T;t[0]===b.capabilities?T=t[1]:(T=qW(b.capabilities),t[0]=b.capabilities,t[1]=T);let E=T,{isMobile:D,isTablet:O}=$c(),k=D||O,A;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(A=[],t[2]=A):A=t[2];let j=Z.useRef(A),M=Z.useRef(null),N=Z.useRef(null),P=Z.useRef(!1),F=Z.useRef(!1),I=$W,L=eG,R;t[3]===S?R=t[4]:(R=S.filter(tG).map(nG),t[3]=S,t[4]=R);let z=R,B;if(t[5]!==p||t[6]!==z){bb0:{let e=p.trim();if(!e){B=z;break bb0}let t=e.toLowerCase();B=z.filter(e=>{let{message:n}=e;return wH(n.parts).toLowerCase().includes(t)})}t[5]=p,t[6]=z,t[7]=B}else B=t[7];let V=B,H;t[8]!==V.length||t[9]!==g||t[10]!==p?(H=()=>{P.current||g(p.trim()?0:Math.max(0,V.length-1))},t[8]=V.length,t[9]=g,t[10]=p,t[11]=H):H=t[11];let U;t[12]!==V||t[13]!==g||t[14]!==p?(U=[V,p,g],t[12]=V,t[13]=g,t[14]=p,t[15]=U):U=t[15],Z.useEffect(H,U);let W,ee;t[16]===V.length?(W=t[17],ee=t[18]):(W=()=>{j.current=j.current.slice(0,V.length)},ee=[V.length],t[16]=V.length,t[17]=W,t[18]=ee),Z.useEffect(W,ee);let te,ne;t[19]===h?(te=t[20],ne=t[21]):(ne=()=>{P.current||j.current[h]?.scrollIntoView({block:`nearest`})},te=[h],t[19]=h,t[20]=te,t[21]=ne),Z.useEffect(ne,te);let re;t[22]===u?re=t[23]:(re=()=>{!P.current||N.current||u||(P.current=!1)},t[22]=u,t[23]=re);let G;t[24]!==V.length||t[25]!==u?(G=[V.length,u],t[24]=V.length,t[25]=u,t[26]=G):G=t[26],Z.useEffect(re,G);let ie,ae;t[27]!==n||t[28]!==p?(ie=()=>{let e=F.current;if(F.current=n,!n||e||P.current||p.trim())return;let t=M.current;t&&(t.scrollTop=t.scrollHeight)},ae=[n,p],t[27]=n,t[28]=p,t[29]=ie,t[30]=ae):(ie=t[29],ae=t[30]),Z.useLayoutEffect(ie,ae);let oe;t[31]===u?oe=t[32]:(oe=()=>{let e=N.current,t=M.current;if(!e||!t||u)return;N.current=null;let n=j.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},t[31]=u,t[32]=oe);let se;t[33]!==V.length||t[34]!==u?(se=[V.length,u],t[33]=V.length,t[34]=u,t[35]=se):se=t[35],Z.useLayoutEffect(oe,se);let ce;t[36]===d?ce=t[37]:(ce=()=>{let e=M.current;if(e){let t=e.getBoundingClientRect().top,n=j.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(N.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}P.current=!0,d?.()},t[36]=d,t[37]=ce);let le=J(ce),ue;t[38]!==r||t[39]!==o?(ue=async e=>{await o?.(e)!==!1&&r(!1)},t[38]=r,t[39]=o,t[40]=ue):ue=t[40];let de=J(ue),fe;t[41]!==V||t[42]!==de||t[43]!==g||t[44]!==h?(fe=e=>{let t=V.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),g(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),g(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(h%t+t)%t,r=V[n];r&&de(r.message.info.id)}}},t[41]=V,t[42]=de,t[43]=g,t[44]=h,t[45]=fe):fe=t[45];let pe=J(fe),me;t[46]!==x||t[47]!==a||t[48]!==w||t[49]!==f||t[50]!==C||t[51]!==v?(me=async(e,t)=>{x&&await v(e,t,async()=>{e===`revert`?f?await f(t):await C(x,t,{directory:a}):await w(x,t,{directory:a})})},t[46]=x,t[47]=a,t[48]=w,t[49]=f,t[50]=C,t[51]=v,t[52]=me):me=t[52];let he=J(me),ge;t[53]!==D||t[54]!==y?(ge=D?null:(0,$.jsx)(xs,{className:`yuri-timeline-header`,children:(0,$.jsx)(ws,{className:`yuri-timeline-title`,children:y(`chat.timeline.title`)})}),t[53]=D,t[54]=y,t[55]=ge):ge=t[55];let _e=D&&`yuri-mobile-glass-control`,ve;t[56]===_e?ve=t[57]:(ve=Y(`yuri-timeline-search`,_e),t[56]=_e,t[57]=ve);let ye;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 text-muted-foreground`}),t[58]=ye):ye=t[58];let be=!D,xe;t[59]===y?xe=t[60]:(xe=y(`chat.timeline.searchPlaceholder`),t[59]=y,t[60]=xe);let Se;t[61]===y?Se=t[62]:(Se=y(`chat.timeline.searchPlaceholder`),t[61]=y,t[62]=Se);let Ce;t[63]===m?Ce=t[64]:(Ce=e=>m(e.target.value),t[63]=m,t[64]=Ce);let we;t[65]!==pe||t[66]!==p||t[67]!==be||t[68]!==xe||t[69]!==Se||t[70]!==Ce?(we=(0,$.jsx)(Qs,{autoFocus:be,"aria-label":xe,inputMode:`search`,placeholder:Se,value:p,onChange:Ce,onKeyDown:pe}),t[65]=pe,t[66]=p,t[67]=be,t[68]=xe,t[69]=Se,t[70]=Ce,t[71]=we):we=t[71];let Te;t[72]!==ve||t[73]!==we?(Te=(0,$.jsxs)(`div`,{className:ve,children:[ye,we]}),t[72]=ve,t[73]=we,t[74]=Te):Te=t[74];let Ee;t[75]!==l||t[76]!==le||t[77]!==u||t[78]!==d||t[79]!==y?(Ee=l&&d&&(0,$.jsx)(`div`,{className:`yuri-timeline-history`,children:(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:le,disabled:u,className:`text-muted-foreground hover:text-foreground`,children:[u&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),y(`chat.history.loadOlder`)]})}),t[75]=l,t[76]=le,t[77]=u,t[78]=d,t[79]=y,t[80]=Ee):Ee=t[80];let De;t[81]===y?De=t[82]:(De=y(`chat.timeline.title`),t[81]=y,t[82]=De);let Oe;t[83]!==E||t[84]!==k||t[85]!==V||t[86]!==he||t[87]!==de||t[88]!==g||t[89]!==_||t[90]!==p||t[91]!==h||t[92]!==y?(Oe=V.length===0?(0,$.jsx)(`div`,{className:`yuri-timeline-empty text-center text-muted-foreground`,children:y(p?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):V.map((e,t)=>{let{message:n}=e,r=TH(n.parts),i=n.info.time.created,a=I(i),o=V[t-1],s=a!==(o?I(o.message.info.time.created):null),c=L(i),l=t===h,u=p.trim()?XW(wH(n.parts),p):null;return(0,$.jsxs)(Z.Fragment,{children:[s&&(0,$.jsx)(`div`,{className:`yuri-timeline-date text-muted-foreground`,children:a}),(0,$.jsxs)(`div`,{ref:e=>{j.current[t]=e},"data-timeline-message-id":n.info.id,"data-selected":l,"data-show-actions":k,className:Y(`yuri-timeline-row hover:bg-interactive-hover/30`,l&&`bg-[color-mix(in_srgb,var(--interactive-selection)_40%,transparent)]`),onMouseEnter:()=>g(t),children:[(0,$.jsxs)(`button`,{type:`button`,className:`yuri-timeline-message`,"aria-current":l||void 0,title:r,onFocus:()=>g(t),onClick:()=>void de(n.info.id),children:[(0,$.jsx)(`time`,{className:`yuri-timeline-time text-muted-foreground`,dateTime:new Date(i).toJSON()??void 0,children:c}),(0,$.jsx)(`span`,{className:`yuri-timeline-preview text-foreground`,children:u??(r||y(`chat.timeline.noTextContent`))})]}),(0,$.jsxs)(`div`,{className:`yuri-timeline-row-actions`,children:[E.revert?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-foreground`,"aria-label":y(`chat.timeline.actions.revertFromHere`),"aria-busy":_?.type===`revert`&&_.messageId===n.info.id,disabled:_!==null,onClick:e=>{e.stopPropagation(),he(`revert`,n.info.id)},children:(0,$.jsx)(X,{name:_?.type===`revert`&&_.messageId===n.info.id?`loader-4`:`arrow-go-back`,className:Y(`h-4 w-4`,_?.type===`revert`&&_.messageId===n.info.id&&`animate-spin`)})})}),(0,$.jsx)(ec,{sideOffset:6,children:y(`chat.timeline.actions.revertFromHere`)})]}):null,E.fork?(0,$.jsxs)(tc,{children:[(0,$.jsx)($s,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-foreground`,"aria-label":y(`chat.timeline.actions.forkFromHere`),"aria-busy":_?.type===`fork`&&_.messageId===n.info.id,onClick:e=>{e.stopPropagation(),he(`fork`,n.info.id)},disabled:_!==null,children:_?.type===`fork`&&_.messageId===n.info.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4`})})}),(0,$.jsx)(ec,{sideOffset:6,children:y(`chat.timeline.actions.forkFromHere`)})]}):null]})]})]},n.info.id)}),t[83]=E,t[84]=k,t[85]=V,t[86]=he,t[87]=de,t[88]=g,t[89]=_,t[90]=p,t[91]=h,t[92]=y,t[93]=Oe):Oe=t[93];let ke;t[94]!==De||t[95]!==Oe?(ke=(0,$.jsx)($u,{ref:M,outerClassName:`yuri-timeline-scroll`,className:`yuri-timeline-list`,"aria-label":De,children:Oe}),t[94]=De,t[95]=Oe,t[96]=ke):ke=t[96];let Ae;t[97]!==r||t[98]!==c||t[99]!==s||t[100]!==_||t[101]!==y?(Ae=s||c?(0,$.jsxs)(`div`,{className:`yuri-timeline-toolbar`,children:[s?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:_!==null,onClick:()=>{s?.(-1),r(!1)},children:y(`chat.timeline.actions.previousTurn`)}):null,c?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:_!==null,onClick:()=>{c?.(),r(!1)},children:y(`chat.timeline.actions.latest`)}):null]}):null,t[97]=r,t[98]=c,t[99]=s,t[100]=_,t[101]=y,t[102]=Ae):Ae=t[102];let je;return t[103]!==ge||t[104]!==Te||t[105]!==Ee||t[106]!==ke||t[107]!==Ae?(je=(0,$.jsxs)($.Fragment,{children:[ge,Te,Ee,ke,Ae]}),t[103]=ge,t[104]=Te,t[105]=Ee,t[106]=ke,t[107]=Ae,t[108]=je):je=t[108],je};function XW(e,t,n=30){let r=e.toLowerCase(),i=t.toLowerCase(),a=r.indexOf(i);if(a===-1)return null;let o=Math.max(0,a-n),s=Math.min(e.length,a+t.length+n);return`${o>0?`…`:``}${e.slice(o,s).replace(/\n/g,` `)}${s<e.length?`…`:``}`}function ZW(e){return e.revertToMessage}function QW(e){return e.forkFromMessage}function $W(e){return vc(e)}function eG(e){return nc(e)}function tG(e){return e.info.role===`user`}function nG(e){return{message:e}}var rG=e=>{let t=e.startsWith(`#`)?e.slice(1):e;if(!t)return null;let n=t.match(/^turn-(.+)$/);if(n?.[1])return{kind:`turn`,id:n[1]};let r=t.match(/^message-(.+)$/);return r?.[1]?{kind:`message`,id:r[1]}:null},iG=(e,t,n)=>{if(n===0||e.length===0)return{kind:`noop`};let r=t?e.indexOf(t):e.length-1,i=(r>=0?r:e.length-1)+n;if(i>=e.length)return{kind:`resume`};let a=e[Math.max(0,i)];return a?{kind:`turn`,turnId:a}:{kind:`noop`}},aG=e=>{if(typeof window>`u`)return;let t=e?`#${e}`:``,n=`${window.location.pathname}${window.location.search}${t}`;window.history.replaceState(window.history.state,``,n),e&&window.dispatchEvent(new HashChangeEvent(`hashchange`))},oG=e=>{e&&aG(`message-${e}`)},sG=e=>{let t=(0,Q.c)(29),{sessionId:n,turnIds:r,activeTurnId:i,scrollToTurn:a,scrollToMessage:o,resumeToBottom:s}=e,c=Z.useRef(r),l=Z.useRef(i),u,d;t[0]===r?(u=t[1],d=t[2]):(u=()=>{c.current=r},d=[r],t[0]=r,t[1]=u,t[2]=d),Z.useEffect(u,d);let f,p;t[3]===i?(f=t[4],p=t[5]):(f=()=>{l.current=i},p=[i],t[3]=i,t[4]=f,t[5]=p),Z.useEffect(f,p);let m;t[6]===a?m=t[7]:(m=async(e,t)=>e?(t?.updateHash!==!1&&aG(`turn-${e}`),a(e,{behavior:t?.behavior})):!1,t[6]=a,t[7]=m);let h=m,g;t[8]===o?g=t[9]:(g=async(e,t)=>e?(t?.updateHash!==!1&&aG(`message-${e}`),o(e,{behavior:t?.behavior})):!1,t[8]=o,t[9]=g);let _=g,v;t[10]!==s||t[11]!==h?(v=async(e,t)=>{let n=c.current,r=iG(n,l.current,e);if(r.kind===`noop`)return e===0;if(r.kind===`resume`){if(t?.resumePastEnd===!1){let e=n[n.length-1];return e?h(e,{behavior:`auto`}):!1}return aG(null),s(),!0}return h(r.turnId,{behavior:`auto`})},t[10]=s,t[11]=h,t[12]=v):v=t[12];let y=v,b;t[13]===s?b=t[14]:(b=()=>{aG(null),s()},t[13]=s,t[14]=b);let x=b,S;t[15]!==_||t[16]!==h||t[17]!==n?(S=()=>{if(!n||typeof window>`u`)return;let e=()=>{let e=rG(window.location.hash);if(e){if(e.kind===`turn`){h(e.id,{behavior:`auto`,updateHash:!1});return}_(e.id,{behavior:`auto`,updateHash:!1})}};return e(),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`hashchange`,e)}},t[15]=_,t[16]=h,t[17]=n,t[18]=S):S=t[18];let C;t[19]!==_||t[20]!==h||t[21]!==n||t[22]!==r.length?(C=[n,_,h,r.length],t[19]=_,t[20]=h,t[21]=n,t[22]=r.length,t[23]=C):C=t[23],Z.useEffect(S,C);let w;return t[24]!==x||t[25]!==y||t[26]!==_||t[27]!==h?(w={scrollToTurnId:h,scrollToMessageId:_,scrollByTurnOffset:y,resumeToLatest:x},t[24]=x,t[25]=y,t[26]=_,t[27]=h,t[28]=w):w=t[28],w},cG=2e4,lG=6e4,uG=2e3,dG=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,fG=e=>{if(e.length===0)return`0`;let t=e[e.length-1];if(!t)return`0`;let n=t.parts??[],r=n[n.length-1],i=0;for(let e of n)i+=dG(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},pG={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},mG=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:pG,shouldRefresh:!1,stalledForMs:0};if(e.sessionKey!==n)return{state:{sessionKey:n,fingerprint:a,lastMovementAt:o,lastRefreshAt:null,attempts:0},shouldRefresh:!1,stalledForMs:0};if(e.fingerprint!==a)return{state:{...e,fingerprint:a,lastMovementAt:o,attempts:0},shouldRefresh:!1,stalledForMs:0};if(!r||i)return{state:{...e,lastMovementAt:o},shouldRefresh:!1,stalledForMs:0};let s=e.lastMovementAt??o,c=o-s,l=e.lastRefreshAt===null||o-e.lastRefreshAt>=t.cooldownMs,u=c>=t.thresholdMs&&l&&e.attempts<t.maxAttempts;return{state:{...e,lastMovementAt:s,lastRefreshAt:u?o:e.lastRefreshAt,attempts:u?e.attempts+1:e.attempts},shouldRefresh:u,stalledForMs:c}},hG=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function gG(e){return!!(e.active&&e.sessionId&&e.sessionKey&&e.sessionIsWorking)}function _G(e){return e===pG?e:pG}function vG(e){let t=e.match(/^User has answered your questions:\s*(.+?)\.\s*You can now/s);if(!t)return null;let n=[],r=t[1],i=/"([^"]+)"="([^"]*(?:[^"\\]|\\.)*)"/g,a;for(;(a=i.exec(r))!==null;)n.push({question:a[1],answer:a[2]});return n.length>0?n:null}function yG(e){if(typeof e.id==`string`&&e.id)return e.id;if(typeof e.callID==`string`&&e.callID)return e.callID;let t=e.state;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t.callID;if(typeof e==`string`&&e)return e}return null}function bG(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(t.type!==`tool`||t.tool!==`question`)return!1;let n=t.state&&typeof t.state==`object`&&!Array.isArray(t.state)?t.state:{},r=typeof n.status==`string`?n.status:void 0;if(r===`error`)return!1;if(r===`pending`||r===`running`||r===void 0)return!0;if(r!==`completed`)return!1;let i=typeof n.output==`string`?n.output:``;return!i||vG(i)==null}function xG(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!bG(n))continue;let e=yG(n);e&&t.push(e)}}return t}function SG(e,t){return`${e}:${t.join(`,`)}`}function CG(e){let t=e.sessionId?.trim()??``,n=e.directory?.trim()??``;if(!t||!n||e.sessionQuestionCount>0||e.unansweredToolIds.length===0)return{recover:!1,attemptKey:null};let r=SG(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function wG(e,t,n,r){let i=(0,Q.c)(7),a=Fr(),o=Z.useRef(null),s=Z.useRef(`${e??``}:${t??``}`),c,l;i[0]!==a||i[1]!==t||i[2]!==n||i[3]!==e||i[4]!==r?(c=()=>{let i=`${e??``}:${t??``}`;s.current!==i&&(o.current=null,s.current=i);let c=CG({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:xG(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,Ei(t,l,[e]))},l=[e,t,n,r,a],i[0]=a,i[1]=t,i[2]=n,i[3]=e,i[4]=r,i[5]=c,i[6]=l):(c=i[5],l=i[6]),Z.useEffect(c,l)}var TG=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),EG=(e,t)=>({...e,key:DG(e),estimatedBytes:TG(t)}),DG=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),OG=e=>({key:e?DG(e):null,selection:e}),kG=(e,t,n)=>{let r=Math.max(1,Math.floor(n.maxEntries)),i=Math.max(0,n.maxEstimatedBytes),a=e.reduce((e,t)=>e+t.estimatedBytes,0);if(e.length<=r&&a<=i)return e;let o=[...e];for(;o.length>r||a>i;){let e=o.findIndex(e=>e.key!==t);if(e===-1)break;let[n]=o.splice(e,1);a-=n?.estimatedBytes??0}return o},AG=(e,t,n,r)=>{let i=DG(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return kG(e,i,n);let s=o||EG(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),kG(c,i,n)},jG=(e,t,n)=>{let r=TG(n),i=e.findIndex(e=>e.key===t);return i===-1||e[i].estimatedBytes===r?e:e.map((e,t)=>t===i?{...e,estimatedBytes:r}:e)},MG=(e,t)=>t&&e.some(e=>e.key===t)?t:null,NG=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?AG(e.cachedSessionViews,t.selection,n,r.estimatedBytes):kG(e.cachedSessionViews,t.key??``,n),a=!r&&e.pendingSessionView?.intent===t?e.pendingSessionView:null;return e.activeIntent===t&&!e.cacheNeedsTrim&&i===e.cachedSessionViews&&a===e.pendingSessionView?e:{activeIntent:t,cacheNeedsTrim:!1,cachedSessionViews:i,pendingSessionView:a}},PG=(e,t,n,r)=>{if(n!==t||e.activeIntent!==t||!t.selection||e.cachedSessionViews.some(e=>e.key===t.key))return e;let i={entry:EG(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},FG=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:AG(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},IG=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},LG=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},RG=e=>LG(e)?.role===`assistant`,zG=(e,t)=>{let n=LG(t);n&&(e.agentName??=IG(n.agent),e.providerId??=IG(n.providerID),e.modelId??=IG(n.modelID))},BG=e=>!!(e.agentName&&e.providerId&&e.modelId),VG=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!RG(r))&&(zG(t,r),BG(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||RG(r))&&(zG(t,r),BG(t)))break}return t},HG=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),UG=[],WG=[],GG=[],KG={type:`idle`},qG=`yuri:chat-force-scroll-bottom`,JG=()=>void 0,YG=`Quota limit reached. Retrying automatically.`,XG=1048576,ZG=XG,QG=20,$G=XG,eK=16*XG,tK={maxEntries:3,maxEstimatedBytes:32*XG},nK={maxEntries:2,maxEstimatedBytes:32*XG},rK=e=>i(()=>e()),iK={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},aK=()=>{let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 bottom-full z-0 h-11 bg-gradient-to-t from-[var(--surface-background)] to-transparent`}),e[0]=t):t=e[0],t},oK=[`a[href]`,`button`,`input`,`select`,`textarea`,`[contenteditable="true"]`,`[role="button"]`,`[role="combobox"]`,`[role="dialog"]`,`[role="listbox"]`,`[role="menu"]`,`[role="menuitem"]`,`[role="option"]`,`[role="textbox"]`,`[data-radix-popper-content-wrapper]`].join(`,`),sK=e=>e instanceof HTMLElement,cK=e=>sK(e)?!!e.closest(oK):!1,lK=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||cK(e)?!0:!t?.contains(e),uK=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=K.getState();return e||t||n||r||i||a||o},dK=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,initialPinRevealComplete:l=!1,renderedMessages:u,isLoadingOlder:d,sessionIsWorking:f,streamingMessageId:p,activeStreamingPhase:m,retryOverlay:h,handleMessageContentChange:g,getAnimationHandlers:_,handleHistoryScroll:v,scrollToBottom:y,sessionQuestions:b,sessionPermissions:x,sessionForms:S,retryActionCopy:C,isProgrammaticFollowActive:w,showLoadOlderButton:T,turnIds:E,activeTurnId:D,onSelectTurn:O,showPromptNavigator:k,canLoadEarlierPrompts:A,isLoadingOlderPrompts:j,onLoadEarlierPrompts:M,transcriptStatusRow:N,timelineHistoryAnchorToken:P})=>{let{t:F}=Xn(),I=tO({isLoadingOlder:d}),[L,R]=Z.useState({sessionId:e,directory:a,reserved:T}),z=L.sessionId===e&&L.directory===a,B=z&&L.reserved||T;(!z||L.reserved!==B)&&R({sessionId:e,directory:a,reserved:B});let V=nO({isMobile:r,isLoadingOlder:I})?(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsx)(`div`,{className:`chat-column flex items-center justify-center gap-1.5 pt-3 pb-1`,children:(0,$.jsx)(`span`,{className:`yuri-mobile-glass-control flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)]`,"aria-label":F(`chat.history.loadingMore`),children:(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`,"aria-hidden":`true`})})})}):null,H=r&&B?(0,$.jsx)(`div`,{className:Y(`flex justify-center pt-3 pb-4`,!I&&`invisible`),"aria-hidden":!I,children:(0,$.jsxs)(`span`,{role:`status`,className:`flex items-center gap-1.5 text-[var(--surface-mutedForeground)] opacity-60`,"aria-busy":I,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:F(`chat.history.loadingMore`)})]})}):null,U=Z.useRef(new Map),W=Z.useRef(new WeakMap),ee=Z.useRef(new Map),te=Z.useMemo(()=>{let e=new Map;for(let t=0;t<u.length;t+=1){let n=u[t];if(n.info.role!==`user`)continue;if(LL(n)){let r=BL(u,t)??``,i=ee.current.get(n.info.id);if(i&&i.command===r)e.set(n.info.id,i.parts);else{let t=[{type:`text`,text:r?`$ ${r}`:`/shell`}];ee.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(Ma(n.parts))continue;let r=W.current.get(n.parts);r||(r=qD(n.parts),W.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=U.current;if(t.size===e.size){let n=!0;for(let[r,i]of e)if(t.get(r)!==i){n=!1;break}if(n)return t}return U.current=e,e},[u]),ne=Z.useMemo(()=>E.filter(e=>te.has(e)),[te,E]),re=Z.useRef(new Map),G=Z.useMemo(()=>{let e=new Map,t=new Map,n;for(let r of u){if(r.info.role===`user`){te.has(r.info.id)&&(n=r.info.id),n&&e.set(r.info.id,n);continue}let i=r.info.parentID,a=i?e.get(i):n;if(!a)continue;e.set(r.info.id,a);let o=wH(r.parts).trim();o&&t.set(a,o.slice(0,600))}let r=re.current;return(r.size!==e.size||[...e].some(([e,t])=>r.get(e)!==t))&&(re.current=e),{owners:re.current,replies:t}},[te,u]),ie=Z.useMemo(()=>{if(!D||te.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(te.has(e))return e}return null},[D,te,E]),ae=J(e=>{e.defaultPrevented||cK(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,n?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":n,children:(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(ed,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:iK,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:ae,onScroll:v,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`yuri-chat-scroll-content relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[H,V,(0,$.jsx)(UV,{timelineHistoryAnchorToken:P,ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,initialPinRevealComplete:l,messages:u,sessionIsWorking:f,activeStreamingMessageId:p,activeStreamingPhase:m,retryOverlay:h,onMessageContentChange:g,getAnimationHandlers:_,isLoadingOlder:d,scrollToBottom:y,scrollRef:o,directory:a,liveStatusSlot:u.length>0?(0,$.jsx)(`div`,{className:`mb-1`,children:N??(0,$.jsx)(jR,{})}):null}),(b.length>0||x.length>0||S.length>0||C)&&(0,$.jsxs)(`div`,{children:[C?(0,$.jsxs)(`div`,{className:`mb-2 rounded-xl border border-border/20 bg-muted/10 px-2.5 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:C.title}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-1`,children:C.message}),C.link?(0,$.jsx)(`a`,{href:C.link,target:`_blank`,rel:`noreferrer`,className:`mt-2 inline-block typography-meta text-primary underline`,children:C.label}):null]}):null,b.map(e=>(0,$.jsx)(hH,{question:e},e.id)),x.map(e=>(0,$.jsx)(cH,{permission:e},e.id)),S.map(e=>(0,$.jsx)(_H,{form:e,directory:a},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?QH:ZH},"aria-hidden":`true`})]})}),(0,$.jsx)(Qu,{containerRef:o,suppressVisibility:w,userIntentOnly:!0,observeMutations:!1}),k&&ne.length>=2?(0,$.jsx)(KH,{turnIds:ne,previewsByTurnId:te,scrollRef:o,turnByMessageId:G.owners,repliesByTurnId:G.replies,activeTurnId:ie,onSelectTurn:O,canLoadEarlier:A,isLoadingOlder:j,onLoadEarlier:M}):null]})})},(e,t)=>e.currentSessionId===t.currentSessionId&&e.virtualizerKey===t.virtualizerKey&&e.isDesktopExpandedInput===t.isDesktopExpandedInput&&e.isMobile===t.isMobile&&e.stickyUserHeader===t.stickyUserHeader&&e.directory===t.directory&&e.scrollRef===t.scrollRef&&e.messageListRef===t.messageListRef&&e.pendingRevealWork===t.pendingRevealWork&&e.initialPinRevealComplete===t.initialPinRevealComplete&&e.renderedMessages===t.renderedMessages&&e.timelineHistoryAnchorToken===t.timelineHistoryAnchorToken&&e.isLoadingOlder===t.isLoadingOlder&&e.sessionIsWorking===t.sessionIsWorking&&e.streamingMessageId===t.streamingMessageId&&e.activeStreamingPhase===t.activeStreamingPhase&&e.retryOverlay===t.retryOverlay&&e.handleMessageContentChange===t.handleMessageContentChange&&e.getAnimationHandlers===t.getAnimationHandlers&&e.handleHistoryScroll===t.handleHistoryScroll&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.sessionForms===t.sessionForms&&e.retryActionCopy===t.retryActionCopy&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.turnIds===t.turnIds&&e.activeTurnId===t.activeTurnId&&e.onSelectTurn===t.onSelectTurn&&e.showPromptNavigator===t.showPromptNavigator&&e.canLoadEarlierPrompts===t.canLoadEarlierPrompts&&e.isLoadingOlderPrompts===t.isLoadingOlderPrompts&&e.onLoadEarlierPrompts===t.onLoadEarlierPrompts&&e.transcriptStatusRow===t.transcriptStatusRow);dK.displayName=`ChatViewport`;var fK=[{id:1,toolRows:[{id:`search`,titleWidth:`w-24`,detailWidth:`w-52`},{id:`read`,titleWidth:`w-20`,detailWidth:`w-36`}],textWidths:[`w-24`,`w-[92%]`,`w-[78%]`]}],pK=e=>Zn(e.path),mK=(e,t)=>{if(!t)return e;let n=e.indexOf(t);return n===-1?e:(0,$.jsxs)($.Fragment,{children:[e.slice(0,n),(0,$.jsx)(`span`,{className:`font-medium`,children:t}),e.slice(n+t.length)]})},hK=e=>{let t=Math.ceil(Math.max(0,e)/QG);return Math.min(eK,ZG+t*$G)},gK=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:s,hostedFeatures:c,assistantHistory:l,onRevertMessage:d,warning:f=null,pendingUserMessages:p=WG,onPendingUserMessagesMaterialized:m,committedDraftHandoffMessageId:h=null})=>{let g=c??oO(void 0),{t:_}=Xn();Jn(()=>{na()},[]);let v=Da(e=>e.openNewSessionDraft),y=Da(e=>e.setCurrentSession),x=Da(e=>e.newSessionDraft),S=Da(e=>e.newSessionDraft.draftSubmitting??!1),C=Da(e=>e.newSessionDraft.draftEstablishing??!1),w=Da(e=>e.forkTransition),T=pa(e=>e.projects),E=pa(e=>e.activeProjectId),D=ni(e=>e.providers),O=ih(),k=vr(),A=i??k;Jn(()=>{!n||!r||!A||us(A,r)},[n,r,A]);let j=J(e=>O.ensureSessionRenderable(e,{directory:A})),M=K(e=>e.isExpandedInput),N=K(e=>e.stickyUserHeader),P=K(e=>e.promptNavigatorEnabled),F=K(e=>e.allowPromptingSubagentSessions),I=K(e=>e.isTimelineDialogOpen),L=K(e=>e.setTimelineDialogOpen),R=_i(e=>n&&r?e.streamingMessageIds.get(r)??null:null),z=_i(e=>R?e.messageStreamStates.get(R)?.phase??null:null),B=to(r??``,A),V=hK(B);Z.useEffect(()=>{!a||!o||o(a,V)},[o,V,a]);let H=va(r??``,A).renderable,U=lo(r,A),W=Xr(r),ee=U??W,te=Rx({sessionId:r,hasSessionEntity:!!ee,hasRenderableSessionSnapshot:H,composerSurfaceKind:s?.kind}),ne=r?JSON.stringify([A,r]):null,[re,G]=Z.useState({key:ne,attempt:0}),ie=ba(r??``,A,{suspendPartUpdates:!!R,suspendPartUpdatesForMessageId:R,enabled:n}),ae=r?ie:UG,se=x.pendingUserMessage,ce=Da(e=>r?e.retainedPendingUserMessages.get(r):void 0)??WG,le=!!(h||ce.length>0),ue=Da(e=>e.clearRetainedPendingUserMessages),de=Z.useMemo(()=>{if(ce.length===0)return p;if(p.length===0)return ce;let e=new Set(p.map(e=>e.info.id));return[...p,...ce.filter(t=>!e.has(t.info.id))]},[p,ce]),fe=Z.useMemo(()=>VG(ae),[ae]),pe=Z.useMemo(()=>{if(!fe.modelId)return _(`common.unavailable`);let e=D.find(e=>e.id===fe.providerId);return qr(e,fe.modelId)||fe.modelId},[D,fe.modelId,fe.providerId,_]),me=Vo(r??``,A),he=fa(r??``,A),[ge,ve]=Z.useState(null),be=!!r&&ge===r,xe=J(()=>{if(!r||be)return;let e=r,t=A;ve(e);let n=cs(()=>{let n=Ve();if(!n)throw Error(`unbound`);return n.getTranscript(oe(t,e))});Hr(zi({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:me?{sessionID:e,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error})),(async()=>{try{await ye(t,e),await O.ensureSessionRenderable(e,{directory:t});try{let r=cs(()=>{let n=Ve();if(!n)throw Error(`unbound`);return n.getTranscript(oe(t,e))});n&&r&&Qr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){Hr(zi({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:he,error:n}))}finally{ve(t=>t===e?null:t)}})()}),Se=Qo(r??``,A).boundary,Ce=J(async e=>{if(Se.kind===`has-more`){await st(A,e,We||Ge?void 0:50);return}if(Se.kind===`unknown`){await Le(A,e);return}l&&!l.complete&&await l.fetchPrevious()}),we=ia(r??``,A),Te=Go(r??``,A),Ee=rs(A),De=we??KG,Oe=wa(r,A),ke=Io(r,A),je=fr(e=>r?e.forms[r]??GG:GG),Me=Z.useMemo(()=>je.filter(e=>!_e(e.metadata)),[je]);Z.useEffect(()=>{r&&Za({sessionID:r,directory:A}).catch(e=>{console.error(`[ChatContainer] Failed to list session forms:`,e)})},[r,A]),wG(r,A,ae,ke.length);let Ne=Z.useMemo(()=>{if(!r||Oe.length>0||ke.length>0)return!1;let e=De.type??`idle`;if(e===`busy`||e===`retry`||ZD(de,{resolvedSessionStatus:we,sessionStatusObservedAt:Te}))return!0;let t=ae[ae.length-1]?.info,n=t?.time?.created;return we&&typeof Te==`number`&&typeof n==`number`&&n<=Te||typeof Ee==`number`&&typeof n==`number`&&n<=Ee?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,de,we,ae,Oe.length,ke.length,De.type,Te,Ee]),Pe=Z.useMemo(()=>!r||De.type!==`retry`?null:{sessionId:r,message:(typeof De.message==`string`?(De.message??``).trim():``)||YG,confirmedAt:De.confirmedAt},[r,De]),[Fe,Ie]=Z.useState(0),Re=Z.useRef(null);Z.useEffect(()=>{if(!Pe||typeof Pe.confirmedAt==`number`){Re.current=null,Ie(0);return}Re.current!==Pe.sessionId&&(Re.current=Pe.sessionId,Ie(Date.now()))},[Pe]);let ze=Z.useMemo(()=>!Pe||xH(De)?null:{...Pe,fallbackTimestamp:Fe},[Pe,Fe,De]),Be=Z.useMemo(()=>SH(De,e=>_(e)),[De,_]),He=!!(r&&O.isLoading(r,{directory:A})),Ue=Z.useMemo(()=>{if(!r)return null;let e=QD({boundary:Se,assistantComplete:l?.complete??!0});return{limit:Se.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:$D({syncLoading:He,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,Se,He]),We=K(e=>e.isMobile),Ge=Sl()!==null,Ke=b(),qe=Ox(),Je=!!x?.open,Ye=Ur(e=>e.error),Xe=M,Ze=Ge||We||Ke||qe===`mini-chat`,Qe=Z.useRef(null),$e=Z.useMemo(()=>{let e=x?.selectedProjectId?T.find(e=>e.id===x.selectedProjectId)??null:null,t=E?T.find(e=>e.id===E)??null:null,n=e??t??T[0]??null;return n?pK(n):null},[E,x?.selectedProjectId,T]),et=Si(r,A),tt=a??r??``,[nt,rt]=Z.useState(null),it=Ux(nt,tt,et,fe);Jn(()=>{rt(e=>Ux(e,tt,et,fe))},[et,fe,tt]);let at=et??it?.parentTarget??null,ot=it?.execution??fe,ct=gl(),lt=ct!==null&&r===ct,ut=J(()=>{at&&y(at.id,at.directory)}),dt=at?.session?.title,ft=g.returnToParent&&at&&!lt?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`xs`,onClick:ut,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":_(`chat.container.returnToParent.aria`),title:dt?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:dt}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,pt=zx({readOnly:t,sessionIdentityPending:te,isSubagentSession:!!ee?.parentID||!!it,allowPromptingSubagentSessions:F}),mt=ot.modelId===fe.modelId?pe:ot.modelId?qr(D.find(e=>e.id===ot.providerId),ot.modelId)||ot.modelId:_(`common.unavailable`),ht=at?(0,$.jsx)(uO,{agentName:ot.agentName,providerId:ot.providerId,modelId:ot.modelId,modelName:mt}):(0,$.jsx)(uO,{}),gt=J(e=>{K.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),_t=J(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`yuri:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&&gt({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),vt=typeof window<`u`&&window.parent!==window;Wn(`message`,_t,vt?window:JG),Hn(()=>{if(!vt)return;let e=window;e.__yuriApplyChatSettingsSync=gt,window.parent.postMessage({type:`yuri:chat-settings-request`},window.location.origin)}),Un(()=>{if(typeof window>`u`)return;let e=window;e.__yuriApplyChatSettingsSync===gt&&delete e.__yuriApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Je&&v()},[e,r,Je,g.newSessionDraft,v]);let yt=Z.useRef(()=>{}),bt=J(e=>{yt.current(e)}),xt=Z.useRef(()=>{}),St=J(()=>{xt.current()}),[Ct,wt]=Z.useState(0),Tt=J(()=>{wt(e=>e+1)}),{scrollRef:Et,notifyContentChange:Dt,getAnimationHandlers:Ot,goToBottom:kt,scrollToBottomOnSend:At,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,restoreSnapshot:Pt,isPinned:Ft,isFollowingProgrammatically:It,showScrollButton:Lt}=yU({scrollControllerRef:Qe,enabled:n,currentSessionId:r,viewportKey:a,sessionMessageCount:B,sessionIsWorking:Ne,isMobile:We,onActiveTurnChange:bt,onUpwardUserIntent:St}),Rt=Z.useRef(null);jU({enabled:We,scrollRef:Et,scopeRef:Rt});let zt=Z.useRef([]),Bt=Z.useMemo(()=>{let e=MO(l?.entries??[],r,zt.current);return zt.current=e,e},[l?.entries,r]),Vt=Z.useRef([]),Ht=Z.useMemo(()=>{if(!l)return ae;let e=FO(l.entries,r,ae,Vt.current);return Vt.current=e,e},[l,r,ae]),Ut=Z.useMemo(()=>XD(Bt.length===0?Ht:r?[...Bt,AO(r),...Ht]:Bt,de),[r,Ht,Bt,de]),Wt=Z.useRef(null),Gt=Z.useMemo(()=>aO({sessionId:r,messages:Ut,retained:Wt.current}),[r,Ut]);Wt.current=Gt.retained;let Kt=Gt.messages,qt=Z.useRef(null),Jt=qt.current===r,Yt=Z.useRef(pG),Xt=r?`${A}\n${r}`:null,Zt=J(()=>fG(Kt));Z.useEffect(()=>{if(!gG({active:n,sessionId:r,sessionKey:Xt,sessionIsWorking:Ne})){Yt.current=_G(Yt.current);return}let e=r,t=A,i=setInterval(()=>{let n=Zt(),r=mG(Yt.current,{sessionKey:Xt,working:!0,streaming:!!R,fingerprint:n,now:Date.now(),thresholdMs:cG,cooldownMs:lG,maxAttempts:3});Yt.current=r.state,r.shouldRefresh&&(hG({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),Ae(t,e).catch(()=>{}))},uG);return()=>clearInterval(i)},[n,r,A,Zt,Ne,R,Xt]);let Qt=Z.useMemo(()=>{if(de.length===0)return[];let e=new Set([...Bt,...Ht].filter(e=>YD(e.parts)).map(e=>e.info.id));return de.map(e=>e.info.id).filter(t=>e.has(t))},[Ht,Bt,de]);Z.useEffect(()=>{Qt.length!==0&&(m?.(Qt),r&&ue(r,Qt))},[ue,r,Qt,m]);let $t=VW({sessionId:r,directory:A,messages:Kt,historyMeta:Ue,scrollRef:Et,messageListRef:Qe,loadMoreMessages:Ce,goToBottom:kt,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,isPinned:Ft,showScrollButton:Lt,isMobile:We,onWillLoadEarlier:Tt}),en=J(()=>{kt(`instant`)}),tn=J(()=>{At()}),nn=eO({isMobile:We,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingOlder:$t.isLoadingOlder}),rn=$t.isLoadingOlder,an=$t.loadEarlier,on=J(()=>{an({userInitiated:!0})});yt.current=$t.handleActiveTurnChange,xt.current=$t.handleHistoryUpwardIntent,Z.useEffect(()=>{(Oe.length!==0||ke.length!==0)&&Dt(`permission`)},[Dt,Oe,ke]);let sn=sG({sessionId:r,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,scrollToTurn:$t.scrollToTurn,scrollToMessage:$t.scrollToMessage,resumeToBottom:en}),cn=pt.showReadOnlyBanner?ht:t?null:(0,$.jsx)(TD,{surface:s,scrollToBottom:tn,submissionBlocked:pt.blockSubmission},`composer-input`),ln=J(e=>{sn.scrollToTurnId(e,{behavior:`smooth`})}),un=$t.historySignals.canLoadEarlier,dn=g.promptNavigator&&!We&&!Ke&&!Xe&&P&&$t.turnIds.length>=2;Z.useEffect(()=>{dn||K.getState().setPromptNavigatorPanelOpen(!1)},[dn]);let fn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||kt(`instant`)});Wn(qG,fn,n&&r&&typeof window<`u`?window:JG);let pn=J(e=>{if(!n||!r||Xe||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=K.getState();if(t!==`chat`||uK())return;let i=Et.current;if(lK(document.activeElement,i)||cK(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;sn.scrollByTurnOffset(a,{resumePastEnd:!1})});Wn(`keydown`,pn,n&&r&&!Xe&&typeof window<`u`?window:JG);let mn=Z.useRef(0),hn=J(()=>{let e=Et.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),gn=J(()=>{mn.current||=requestAnimationFrame(()=>{mn.current=0,hn()})});Jn(()=>{n&&hn()},[n,r,Xe,hn]);let _n=typeof ResizeObserver<`u`;qn(n&&_n?Et:null,gn),Wn(`resize`,gn,n&&!_n&&typeof window<`u`?window:JG),Un(()=>{mn.current&&=(cancelAnimationFrame(mn.current),0)});let vn=Z.useRef(null),q=Z.useRef(0),yn=rO({transcriptMessageCount:ae.length,pendingUserCount:de.length,historyPrefixCount:Bt.length}),bn=iO({hasTranscriptShell:yn,transcriptRecords:ae,p0Satisfied:he.p0Satisfied,hasBusyShell:Ne&&yn,hasImmediateShell:de.length>0||Bt.length>0,hasRenderableSessionSnapshot:H,prefetchStatus:me?.status,syncLoading:!!(r&&O.isLoading(r,{directory:A})),userRetrying:be,hasPaintedTranscript:Jt});bn===`pass`&&Kt.length>0&&(qt.current=r);let xn=!!r&&bn===`hydrating`;GW({scope:JSON.stringify([u(),A,r]),enabled:n&&!We&&!Ge&&!!r&&bn===`pass`&&he.p0Satisfied&&!Ne&&!Ue?.loading&&!$t.isLoadingOlder,cursor:Se.kind===`has-more`?Se.cursor:null,loadedTurns:Se.loadedTurns,messages:Kt,scrollRef:Et,loadPrevious:e=>st(A,r,e)});let Sn=!!r&&bn===`load-error`;Z.useEffect(()=>{!Sn||!r||Hr(zi({kind:`request-error`,sessionID:r,directory:A,purpose:`load-failed`,source:`network`,request:me?{sessionID:r,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error}))},[r,A,Sn,me,he]),Z.useEffect(()=>{if(!n||!r||xn)return;let e=Kt.length,t=vn.current!==r,i=!t&&q.current===0&&e>0;if(!t&&!i){vn.current===r&&(q.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(vn.current=r,q.current=e,a){jt();return}let o=()=>{Pt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,xn,jt,Pt,Kt.length]),Z.useEffect(()=>{G(e=>e.key===ne?e:{key:ne,attempt:0})},[ne]),Z.useEffect(()=>{if(!n||!r||re.key!==ne||!HG({sessionId:r,hasRenderableSessionSnapshot:H,hasCurrentSessionEntity:!!ee})||(j(r),ee||re.attempt>=2))return;let e=re.attempt+1,t=window.setTimeout(()=>{G(t=>t.key===ne&&t.attempt===re.attempt?{key:ne,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,ee,r,A,j,H,ne,re]);let Cn=w&&r&&(w.targetSessionId?r===w.targetSessionId:r===w.sourceSessionId)?w:null;if(Cn){let e=Cn.stage===`preparing`?`chat.forkTransition.preparing`:Cn.stage===`copying`?`chat.forkTransition.copying`:Cn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Cn.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${_(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(e)}),(0,$.jsx)(zv,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}if(!r&&!Je)return e&&!Ye?(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`}):(0,$.jsx)(`div`,{className:`flex flex-col h-full bg-background`,children:(0,$.jsx)(fO,{})});if(!r&&Je){if((S||C)&&se){let e=`draft:${x.draftID??`pending`}`;return(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex h-full flex-col bg-background`,We&&`yuri-chat-composer-swap-scope`),children:[(0,$.jsx)(dK,{timelineHistoryAnchorToken:Ct,currentSessionId:e,virtualizerKey:e,isDesktopExpandedInput:!1,isMobile:We,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:!1,initialPinRevealComplete:!0,renderedMessages:[se],isLoadingOlder:!1,sessionIsWorking:!0,streamingMessageId:null,activeStreamingPhase:null,retryOverlay:null,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:[],sessionPermissions:[],sessionForms:[],retryActionCopy:null,isProgrammaticFollowActive:It,showLoadOlderButton:!1,turnIds:[],activeTurnId:null,onSelectTurn:ln,showPromptNavigator:!1,canLoadEarlierPrompts:!1,isLoadingOlderPrompts:!1,onLoadEarlierPrompts:on,transcriptStatusRow:(0,$.jsx)(`div`,{className:`chat-column`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex h-[1.2rem] items-center py-0.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zv,{})]})})},e),(0,$.jsxs)(`div`,{className:Y(`invisible pointer-events-none relative z-10`,We&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`absolute inset-0 bg-background`:`bg-background`),"aria-hidden":`true`,children:[!We&&!Xe?(0,$.jsx)(aK,{}):null,cn]})]})}return S||C?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":_(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zv,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Ze&&!Xe?(0,$.jsxs)(`div`,{className:`yuri-draft-center flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-balance text-3xl font-normal tracking-tight text-foreground`,children:mK($e?_(`chat.emptyState.draftTitleWithProject`,{project:$e}):_(`chat.emptyState.draftTitle`),$e)}),(0,$.jsx)(FS,{onSubmit:e=>fi.getState().requestPresetSubmit(e),className:`yuri-draft-starters mt-8 max-w-md`})]}):null,(0,$.jsx)(`div`,{className:Y(`relative z-10 flex min-h-0`,We&&`yuri-mobile-composer-foot`,Xe?`flex-1 bg-background`:Ze?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:cn})]})}return r?Sn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[ft,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:_(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:_(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(er,{type:`button`,className:`mt-5`,onClick:xe,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):xn?(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,We&&`yuri-chat-composer-swap-scope`),children:[ft,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:(0,$.jsx)(`div`,{ref:Et,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:iK,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:fK.map(e=>(0,$.jsx)(`div`,{className:`group w-full`,children:(0,$.jsx)(`div`,{className:`chat-message-column`,children:(0,$.jsxs)(`div`,{className:`space-y-2.5 px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.toolRows.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)($d,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,t.detailWidth)})]},`${e.id}-${t.id}`))}),(0,$.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)($d,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!We&&!Xe?(0,$.jsx)(aK,{}):null,cn]},`composer-foot`)]}):Kt.length===0&&!Ne?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[ft,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(fO,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,We&&`yuri-chat-composer-swap-scope`),children:[f?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:f}):null,ft,(0,$.jsx)(dK,{timelineHistoryAnchorToken:Ct,currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Xe,isMobile:We,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:$t.pendingRevealWork,initialPinRevealComplete:le,renderedMessages:$t.renderedMessages,isLoadingOlder:rn,sessionIsWorking:Ne,streamingMessageId:R,activeStreamingPhase:z,retryOverlay:ze,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:ke,sessionPermissions:Oe,sessionForms:Me,retryActionCopy:Be,isProgrammaticFollowActive:It,showLoadOlderButton:nn,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,onSelectTurn:ln,showPromptNavigator:dn,canLoadEarlierPrompts:un,isLoadingOlderPrompts:rn,onLoadEarlierPrompts:on},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,We&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!We&&!Xe?(0,$.jsx)(aK,{}):null,(0,$.jsx)(CH,{scrollRef:Et,active:n&&!Xe,showScrollToBottom:Kt.length>0&&$t.showScrollToBottom,onScrollToBottom:sn.resumeToLatest}),cn]},`composer-foot`),(0,$.jsx)(JW,{open:I,onOpenChange:L,sessionID:r??void 0,directory:A,onRevertMessage:d,onScrollToMessage:$t.scrollToMessage,onScrollByTurnOffset:sn.scrollByTurnOffset,onResumeToLatest:en,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingEarlier:rn,onLoadEarlier:on})]}):null});gK.displayName=`MemoizedChatContainerContent`;var _K=()=>{let e=(0,Q.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)($d,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)($d,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)($d,{className:`h-4 w-1/2 animate-none rounded-md`})]}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`,"data-session-view-loading":`true`,"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`mt-auto w-full pb-5 motion-safe:animate-pulse`,children:(0,$.jsxs)(`div`,{className:`chat-message-column space-y-2 px-4`,children:[t,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)($d,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)($d,{className:`h-4 w-3/5 animate-none rounded-md`})]})]})})}),e[1]=n):n=e[1],n},vK=({runtimeKey:e,...t})=>{let n=Ox(),r=vr(),i=Da(H(e=>({sessionId:e.currentSessionId,directory:e.currentSessionDirectory,draftID:e.newSessionDraft.open?e.newSessionDraft.draftID:null,draftPendingMessageId:e.newSessionDraft.open?e.newSessionDraft.pendingUserMessage?.info.id??null:null}))),a=Z.useRef(null),o=i.draftID&&i.draftPendingMessageId?`${i.draftID}:${i.draftPendingMessageId}`:null;o&&a.current?.identity!==o&&(a.current=null),Jn(()=>{!o||!i.draftPendingMessageId||(a.current={identity:o,messageId:i.draftPendingMessageId})},[o,i.draftPendingMessageId]);let s=Da(e=>i.sessionId?e.retainedPendingUserMessages.get(i.sessionId)??WG:WG),c=a.current,l=c&&s.some(e=>e.info.id===c.messageId)?c.messageId:null,u=Z.useMemo(()=>i.sessionId?{runtimeKey:e,sessionId:i.sessionId,directory:i.directory??r}:null,[e,i.directory,i.sessionId,r]),d=Z.useMemo(()=>OG(u),[u]),f=d.key,p=Po()||b()||n===`mini-chat`?nK:tK,[m,h]=Z.useState(()=>({activeIntent:d,cacheNeedsTrim:!1,cachedSessionViews:u?AG([],u,p,ZG):[],pendingSessionView:null})),g=Z.useRef(d),_=Z.useRef(f),{cacheNeedsTrim:v,cachedSessionViews:y,pendingSessionView:x}=m,S=x?.intent===d?x.entry:null,C=Z.useMemo(()=>!u||!l?null:AG([],u,p,ZG)[0]??null,[p,l,u]),w=Z.useMemo(()=>{let e=[...y];return S&&!e.some(e=>e.key===S.key)&&e.push(S),C&&!e.some(e=>e.key===C.key)&&e.push(C),e.sort((e,t)=>e.key.localeCompare(t.key))},[y,C,S]),T=MG(w,f),E=!!(f&&!T);Jn(()=>{g.current=d,_.current=f,h(e=>{let t=NG(e,d,p);return l?PG(t,d,d,ZG):t})},[p,v,l,d,f]);let D=x?.intent??null;Jn(()=>{D&&h(e=>FG(e,D,p))},[p,D]),Z.useEffect(()=>{if(!d.selection||T)return;let e=d,t=f;return Od(()=>{g.current===e&&_.current===t&&h(n=>_.current===t?PG(n,e,g.current,ZG):n)},{priority:`user-blocking`})},[T,p,d,f]);let O=J((e,t)=>{let n=g.current,r=_.current;h(i=>{if(g.current!==n||_.current!==r||i.activeIntent!==n||e!==r)return i;let a=jG(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})});return(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":E||void 0,children:[E?(0,$.jsx)(_K,{},f):null,w.map(e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:T===e.key?`visible`:`hidden`,children:(0,$.jsx)(gK,{...t,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:O,committedDraftHandoffMessageId:T===e.key?l:null})},e.key)),f?null:(0,$.jsx)(gK,{...t,sessionId:null,sessionDirectory:i.directory})]})},yK=e=>{let t=(0,Q.c)(24),{host:n,runtimeKey:r,readOnly:i}=e,a=i!==void 0&&i,o;t[0]===n?o=t[1]:(o=oO(n),t[0]=n,t[1]=o);let s=o,c;t[2]===n.onRevertMessage?c=t[3]:(c=n.onRevertMessage?{onRevertMessage:n.onRevertMessage}:{},t[2]=n.onRevertMessage,t[3]=c);let l;t[4]!==n.directory||t[5]!==n.sessionId||t[6]!==n.sessionSurface||t[7]!==c?(l={...n.sessionSurface,sessionId:n.sessionId,directory:n.directory,...c},t[4]=n.directory,t[5]=n.sessionId,t[6]=n.sessionSurface,t[7]=c,t[8]=l):l=t[8];let u=l,d=`host:${r}:${u.surfaceId}:${n.sessionId}`,f;t[9]!==n.assistantHistory||t[10]!==n.composerSurface||t[11]!==n.directory||t[12]!==n.onPendingUserMessagesMaterialized||t[13]!==n.onRevertMessage||t[14]!==n.pendingUserMessages||t[15]!==n.sessionId||t[16]!==n.warning||t[17]!==s||t[18]!==a||t[19]!==d?(f=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(gK,{autoOpenDraft:!1,readOnly:a,sessionId:n.sessionId,sessionDirectory:n.directory,sessionViewKey:d,composerSurface:n.composerSurface,hostedFeatures:s,assistantHistory:n.assistantHistory,pendingUserMessages:n.pendingUserMessages,onPendingUserMessagesMaterialized:n.onPendingUserMessagesMaterialized,onRevertMessage:n.onRevertMessage,warning:n.warning})}),t[9]=n.assistantHistory,t[10]=n.composerSurface,t[11]=n.directory,t[12]=n.onPendingUserMessagesMaterialized,t[13]=n.onRevertMessage,t[14]=n.pendingUserMessages,t[15]=n.sessionId,t[16]=n.warning,t[17]=s,t[18]=a,t[19]=d,t[20]=f):f=t[20];let p;return t[21]!==u||t[22]!==f?(p=(0,$.jsx)(Cb.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},bK=e=>{let t=(0,Q.c)(16),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({explicitSession:n,runtimeKey:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=vr(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Sb({...n,directory:o}),t[4]=o,t[5]=n,t[6]=s):s=t[6];let c=s,l=`explicit:${i}:${n.viewKey}`,u;t[7]!==o||t[8]!==n.active||t[9]!==n.sessionId||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(gK,{...r,active:n.active,sessionId:n.sessionId,sessionDirectory:o,sessionViewKey:l})}),t[7]=o,t[8]=n.active,t[9]=n.sessionId,t[10]=r,t[11]=l,t[12]=u):u=t[12];let d;return t[13]!==c||t[14]!==u?(d=(0,$.jsx)(Cb.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},xK=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(rK,u,u);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(yK,{...e,host:e.host,runtimeKey:n},r),t[0]=e,t[1]=n,t[2]=r,t[3]=i):i=t[3],i}if(e.explicitSession){let r=`${n}:${e.explicitSession.viewKey}`,i;return t[4]!==e.active||t[5]!==e.autoOpenDraft||t[6]!==e.explicitSession||t[7]!==e.readOnly||t[8]!==n||t[9]!==r?(i=(0,$.jsx)(bK,{autoOpenDraft:e.autoOpenDraft,readOnly:e.readOnly,active:e.active,explicitSession:e.explicitSession,runtimeKey:n},r),t[4]=e.active,t[5]=e.autoOpenDraft,t[6]=e.explicitSession,t[7]=e.readOnly,t[8]=n,t[9]=r,t[10]=i):i=t[10],i}let r;return t[11]!==e||t[12]!==n?(r=(0,$.jsx)(vK,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r},SK=2e4,CK=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus()?`visible`:`hidden`,wK=e=>{if(!h()&&!Fn())return;let t=S();t?.push?.setVisibility&&t.push.setVisibility({visible:e,platform:In()})},TK=e=>{let t=e?.enabled??!0;Z.useEffect(()=>{if(!t||!h()&&!Fn()||typeof window>`u`)return;if(Fn()){let e=!0,t=!1,n=null,r=()=>wK(e);Mn(async()=>{let{App:e}=await import(`./vendor-capacitor-app-B5H_XtmE.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([77,1,20])).then(async({App:i})=>{if(t)return;let a=await i.getState().catch(()=>null);a&&(e=a.isActive===!0),r();let o=await i.addListener(`appStateChange`,({isActive:t})=>{e=t===!0,r()});if(t){o.remove();return}n=()=>void o.remove()}).catch(()=>void 0);let i=window.setInterval(()=>{e&&wK(!0)},SK);return()=>{t=!0,window.clearInterval(i),n?.()}}if(typeof document>`u`)return;let e=()=>{wK(CK()===`visible`)},n=()=>{CK()===`visible`&&wK(!0)},r=()=>{wK(!1)};e();let i=window.setInterval(n,SK);return document.addEventListener(`visibilitychange`,e),window.addEventListener(`pagehide`,r),window.addEventListener(`pageshow`,e),window.addEventListener(`focus`,e),window.addEventListener(`blur`,e),()=>{window.clearInterval(i),document.removeEventListener(`visibilitychange`,e),window.removeEventListener(`pagehide`,r),window.removeEventListener(`pageshow`,e),window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,e)}},[t])},EK=`Yuri`,DK=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``).split(`/`).filter(Boolean);return t[t.length-1]??``},OK=(e,t)=>[e,t,EK].filter(e=>typeof e==`string`&&e.trim().length>0).join(` | `),kK=()=>{let e=pa(e=>{if(!e.activeProjectId)return null;let t=e.projects.find(t=>t.id===e.activeProjectId);return t&&DK(t.path)||null}),[t,n]=Z.useState(null);Z.useEffect(()=>{if(typeof window>`u`||!x()){n(null);return}let e=!1,t=async()=>{try{if(g()){e||n(null);return}let t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,r=d();if(r&&j(r,t)){e||n(null);return}let i=(await M()).hosts.find(e=>r?j(r,P(e)):!1),a=i?.label?.trim()?T(i.label.trim()):`Instance`;e||n(a)}catch{e||n(`Instance`)}};t();let r=()=>{t()};return window.addEventListener(`focus`,r),()=>{e=!0,window.removeEventListener(`focus`,r)}},[]);let r=Z.useMemo(()=>OK(e,t),[e,t]);Z.useEffect(()=>{typeof document<`u`&&(document.title=r),x()&&(async()=>{try{if(typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``))return;await nr(r)}catch{return}})()},[r])},AK=e=>{let t=[];return e.hideGit||t.push(`git`),t.push(`files`),e.showBrowser&&t.push(`browser`),t},jK=e=>e===`git`||e===`files`||e===`browser`,MK=()=>{let e=Da.getState().currentSessionId;if(!e)return``;let t=Ne().find(t=>t.id===e);return typeof t?.directory==`string`?t.directory:``},NK=async(e,t=6e3)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t),i=Date.now();try{let t=await f(e,{method:`GET`,headers:{Accept:`application/json`},signal:n.signal}),r=Date.now()-i,a=t.headers.get(`content-type`)||``,o=a.toLowerCase(),s=o.includes(`json`)&&!o.includes(`text/html`),c=``;if(s){let e=await t.json().catch(()=>null);if(Array.isArray(e))c=`json[array] len=${e.length}`;else if(e&&typeof e==`object`){let t=Object.keys(e).slice(0,8);c=`json[object] keys=${t.join(`,`)}${Object.keys(e).length>t.length?`,…`:``}`}else c=`json[${typeof e}]`}else c=a?`content-type=${a}`:`no content-type`;return{ok:t.ok&&s,status:t.status,elapsedMs:r,summary:c}}catch(e){return{ok:!1,status:0,elapsedMs:Date.now()-i,summary:`error=${n.signal.aborted||e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))?`timeout after ${t}ms`:e instanceof Error?e.message:String(e)}`}}finally{clearTimeout(r)}},PK=e=>{if(!e||!Number.isFinite(e))return`(n/a)`;try{return new Date(e).toISOString()}catch{return`(invalid)`}},FK=e=>{if(typeof e==`number`&&Number.isFinite(e)&&e>0)return Math.trunc(e);if(typeof e==`string`){let t=Number.parseInt(e,10);if(Number.isFinite(t)&&t>0)return t}return null},IK=e=>!!e&&typeof e==`object`&&!Array.isArray(e),LK=(e,t=`(n/a)`)=>typeof e==`string`?e.trim()||t:typeof e==`number`&&Number.isFinite(e)?String(e):typeof e==`boolean`?e?`true`:`false`:t,RK=(e,t,n)=>e===`node-shebang`||e===`node-launcher`?t?`node (${t})`:`node`:e===`bun-shebang`?n?`bun (${n})`:`bun`:e||`direct executable`,zK=async()=>{let e=new Date,t=typeof navigator<`u`?navigator.userAgent:`(no navigator)`,n=MK(),r=K.getState().eventStreamStatus,i=typeof window<`u`?window.location.origin:``,o=a(),s=o.health(),c=o.api(`/api/`),l=await(async()=>{if(!s)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),5e3);try{let t=await f(s,{method:`GET`,headers:{Accept:`application/json`},signal:e.signal});if(!t.ok)return null;let n=await t.json().catch(()=>null);return!n||typeof n!=`object`||Array.isArray(n)?null:n}catch{return null}finally{clearTimeout(t)}})(),u=await(async()=>{if(!c)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),7e3);try{let t=await f(o.api(`/api/config/opencode-resolution`),{method:`GET`,headers:{Accept:`application/json`},signal:e.signal}),n=t.headers.get(`content-type`)||`(none)`;if(!t.ok)return{data:null,status:t.status,error:`http ${t.status} content-type=${n}`};let r=await t.text(),i=null;try{i=JSON.parse(r)}catch{let e=r.replace(/\s+/g,` `).slice(0,120);return{data:null,status:t.status,error:`invalid json content-type=${n} body=${e||`(empty)`}`}}return!i||typeof i!=`object`||Array.isArray(i)?{data:null,status:t.status,error:`invalid json-shape content-type=${n}`}:{data:i,status:t.status,error:null}}catch(e){return{data:null,status:null,error:e instanceof Error?e.message:String(e)}}finally{clearTimeout(t)}})()||{data:null,status:null,error:null},d=(e,t=!0)=>{if(!c)return null;let r=new URL(e.replace(/^\/+/,``),c);return t&&n&&r.searchParams.set(`location[directory]`,n),r.toString()},p=c?await Promise.all([{label:`health`,path:`/info`,includeDirectory:!1},{label:`config`,path:`/config`,includeDirectory:!0},{label:`providers`,path:`/provider`,includeDirectory:!0},{label:`agents`,path:`/agent`,includeDirectory:!0,timeoutMs:12e3},{label:`commands`,path:`/command`,includeDirectory:!0,timeoutMs:1e4},{label:`project`,path:`/project`,includeDirectory:!1},{label:`location`,path:`/location`,includeDirectory:!0},{label:`sessions`,path:`/session`,includeDirectory:!0,timeoutMs:12e3},{label:`sessionActive`,path:`/session/active`,includeDirectory:!1}].map(async e=>{let t=d(e.path,e.includeDirectory!==!1);if(!t)return{label:e.label,url:`(none)`,result:null};let n=await NK(t,typeof e.timeoutMs==`number`?e.timeoutMs:void 0);return{label:e.label,url:t,result:n}})):[],m=[];m.push(`Time: ${e.toISOString()}`),m.push(`Yuri version: 0.2.27-beta.3`),m.push(`Runtime: ${i||`(unknown)`} (api=${c||`(unknown)`})`),m.push(`OpenCode SDK base: ${se.getBaseUrl()}`),m.push(`Event stream: ${r}`),m.push(`Directory: ${n||`(none)`}`),m.push(`Platform: ${t}`);let h=FK(l?.openCodePort);if(m.push(`OpenCode runtime port: ${h??`(unknown)`}`),typeof l?.openCodeRunning==`boolean`&&m.push(`OpenCode runtime running: ${l.openCodeRunning?`yes`:`no`}`),typeof l?.openCodeSecureConnection==`boolean`&&m.push(`Secure OpenCode connection: ${l.openCodeSecureConnection?`true`:`false`}`),typeof l?.openCodeAuthSource==`string`&&l.openCodeAuthSource.trim()&&m.push(`OpenCode auth source: ${l.openCodeAuthSource}`),typeof l?.openCodeServeVersion==`string`&&l.openCodeServeVersion.trim()&&m.push(`OpenCode serve version: ${l.openCodeServeVersion}`),typeof l?.openCodeCliVersion==`string`&&l.openCodeCliVersion.trim()&&m.push(`OpenCode CLI version: ${l.openCodeCliVersion}`),IK(l?.runtimeContract)){let e=l.runtimeContract,t=typeof e.phase==`string`?e.phase:`(unknown)`,n=e.executionAllowed===!0?`allowed`:`limited`,r=e.protocolCompatible===!0?`compatible`:`incompatible`;m.push(`OpenCode runtime contract: phase=${t} protocol=${r} execution=${n}`),Array.isArray(e.reasons)&&e.reasons.length>0&&m.push(`OpenCode contract reasons: ${e.reasons.filter(e=>typeof e==`string`).join(`, `)}`)}if(typeof window<`u`){let e=window.__YURI_MACOS_MAJOR__;typeof e==`number`&&Number.isFinite(e)&&e>0&&m.push(`macOS major: ${e}`)}if(/Mac OS X|Macintosh/.test(t)){m.push(``),m.push(`OpenCode CLI resolution:`);let e=IK(l?.lastOpenCodeLaunchDiagnostics)?l.lastOpenCodeLaunchDiagnostics:null,t=e&&Array.isArray(e.args)?e.args.filter(e=>typeof e==`string`):[],n=u.data,r=n&&typeof n.configured==`string`?n.configured:null,i=n&&typeof n.resolved==`string`?n.resolved:l&&typeof l.opencodeBinaryResolved==`string`?l.opencodeBinaryResolved:``,a=n&&typeof n.resolvedDir==`string`?n.resolvedDir:``,o=n&&typeof n.source==`string`?n.source:l&&typeof l.opencodeBinarySource==`string`?l.opencodeBinarySource:``,s=n&&typeof n.launchBinary==`string`?n.launchBinary:l&&typeof l.opencodeLaunchBinary==`string`?l.opencodeLaunchBinary:``,c=n&&typeof n.launchWrapperType==`string`?n.launchWrapperType:l&&typeof l.opencodeLaunchWrapperType==`string`?l.opencodeLaunchWrapperType:``,d=n&&Array.isArray(n.launchArgs)?n.launchArgs.filter(e=>typeof e==`string`):l&&Array.isArray(l.opencodeLaunchArgs)?l.opencodeLaunchArgs.filter(e=>typeof e==`string`):[],f=n&&typeof n.node==`string`?n.node:l&&typeof l.nodeBinaryResolved==`string`?l.nodeBinaryResolved:``,p=n&&typeof n.bun==`string`?n.bun:l&&typeof l.bunBinaryResolved==`string`?l.bunBinaryResolved:``,h=n&&typeof n.detectedNow==`string`?n.detectedNow:``,g=n&&typeof n.detectedSourceNow==`string`?n.detectedSourceNow:``;if(r!==null&&m.push(`- configured: ${r.trim().length===0?`(cleared)`:r}`),i){let e=a||(i.includes(`/`)?i.split(`/`).slice(0,-1).join(`/`)||`/`:``);m.push(`- opencode: ${i}${e?` (dir=${e})`:``}`)}else m.push(`- opencode: (n/a)`);m.push(`- source: ${o||`(n/a)`}`),h&&(m.push(`- detected-now: ${h}`),m.push(`- detected-source: ${g||`(n/a)`}`)),e?(m.push(`- launched-at: ${LK(e.launchedAt)}`),m.push(`- launch: ${LK(e.binary)} ${t.join(` `)}`.trim()),m.push(`- cwd: ${LK(e.cwd)}`),m.push(`- wrapper: ${LK(e.wrapperType)}`),m.push(`- runtime: ${RK(LK(e.wrapperType,``),f,p)}`),m.push(`- PATH entries: ${LK(e.pathEntryCount,`(unknown)`)}`),m.push(`- shell env: ${LK(e.hasShellEnv,`(unknown)`)} (${LK(e.shellEnvKeysCount,`?`)} keys)`)):(m.push(`- launch-binary: ${s||`(n/a)`}`),m.push(`- launch-wrapper: ${c||`(n/a)`}`),m.push(`- launch-args: ${d.length?d.join(` `):`(none)`}`),m.push(`- runtime: ${RK(c||``,f,p)}`)),!n&&u.error&&m.push(`- resolution-endpoint: ${u.error}`)}if(m.push(``),p.length){m.push(`OpenCode API probes:`);for(let e of p){if(!e.result){m.push(`- ${e.label}: (no url)`);continue}let{ok:t,status:n,elapsedMs:r,summary:i}=e.result,a=t?``:` url=${e.url}`;m.push(`- ${e.label}: ${t?`ok`:`fail`} status=${n} time=${r}ms ${i}${a}`)}}else m.push(`OpenCode API probes: (skipped)`);return m.push(``),m.push(`Generated: ${PK(Date.now())}`),m.join(`
6606
6606
  `)},BK=async()=>{let e=await zK(),t=K.getState();t.setOpenCodeStatusText(e),t.setOpenCodeStatusDialogOpen(!0)},VK=(e,t)=>e===t?!0:!e||!t?!1:e.scope===t.scope&&e.sessionId===t.sessionId&&e.projectId===t.projectId,HK=e=>e?`${e.scope}:${e.projectId??``}:${e.sessionId}`:null,UK=e=>({scope:`project`,sessionId:e,projectId:null}),WK=L()(e=>({focus:null,setFocus:t=>e(e=>VK(e.focus,t)?e:{focus:t})})),GK=null,KK=0,qK=(e,t)=>{let n=new Set,r=[];for(let i of t){if(!i.sessionId)continue;let t=e===`pinned`?i.sessionId:`${i.projectId??``}:${i.sessionId}`;n.has(t)||(n.add(t),r.push(i.scope===e?i:{...i,scope:e}))}return r},JK=e=>{let t=++KK;return GK={pinned:qK(`pinned`,e.pinned),project:qK(`project`,e.project)},()=>{KK===t&&(GK=null)}},YK=()=>GK,XK=e=>!!e.parentID,ZK=(e,t)=>{if(!e)return null;let n=new Map(t.map(e=>[e.id,e])),r=n.get(e);if(!r)return e;for(;r&&XK(r);){let e=r.parentID;if(!e)break;let t=n.get(e);if(!t)return e;r=t}return r?.id??e},QK=()=>{let e=Br.getState().activeSessions;if(e.length>0)return e;let t=Se();return t.length>0?t:Ne()},$K=(e,t,n)=>{if(!t)return-1;if(n?.scope){let r=e.findIndex(e=>e.scope===n.scope&&e.sessionId===t&&(!n.projectId||e.projectId===n.projectId));if(r>=0)return r}if(n?.projectId){let r=e.findIndex(e=>e.sessionId===t&&e.projectId===n.projectId);if(r>=0)return r}return e.findIndex(e=>e.sessionId===t)},eq=e=>[...e.pinned,...e.project],tq=(e,t,n,r)=>{if(e.length===0)return null;let i=$K(e,n,r);return i<0?t>0?e[0]??null:e[e.length-1]??null:e[(i+t+e.length)%e.length]??null},nq=(e,t,n=WK.getState().focus)=>{let r=ZK(t,QK()),i=n?.sessionId===t?n:null,a=YK();return a?tq(eq(a),e,r,i):null},rq=(e,t,n=e=>{Da.getState().setCurrentSession(e.sessionId,e.directory)})=>{let r=nq(e,t);return r?(WK.getState().setFocus({scope:r.scope,sessionId:r.sessionId,projectId:r.projectId}),n(r),r):null},iq=.5,aq=.1,oq=`yuri.webviewZoomFactor`,sq=e=>Number.isFinite(e)?Math.min(3,Math.max(iq,Math.round(e*100)/100)):1,cq=()=>{if(typeof window>`u`)return 1;try{let e=window.localStorage.getItem(oq);return e?sq(Number.parseFloat(e)):1}catch{return 1}},lq=e=>{if(!(typeof window>`u`))try{window.localStorage.setItem(oq,String(e))}catch{}},uq=e=>{let t=sq(e);return typeof document<`u`&&(document.documentElement.style.zoom=t===1?``:String(t)),lq(t),t},dq=()=>{if(typeof document>`u`)return 1;let e=document.documentElement.style.zoom;if(!e)return cq();let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?sq(t):cq()},fq=()=>{if(v())return;let e=cq();e!==1&&uq(e)},pq=async()=>{if(v())try{let e=await y(`desktop_zoom_in`);if(typeof e==`number`&&Number.isFinite(e))return sq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_in failed, using CSS zoom`,e)}return uq(dq()+aq)},mq=async()=>{if(v())try{let e=await y(`desktop_zoom_out`);if(typeof e==`number`&&Number.isFinite(e))return sq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_out failed, using CSS zoom`,e)}return uq(dq()-aq)},hq=async()=>{if(v())try{let e=await y(`desktop_zoom_reset`);if(typeof e==`number`&&Number.isFinite(e))return sq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_reset failed, using CSS zoom`,e)}return uq(1)},gq=9,_q=null,vq=0,yq=({pinnedTargets:e,projectTargets:t})=>[...e,...t].slice(0,gq),bq=(e,t)=>{let n=e.findIndex(e=>e.scope===t.scope&&e.sessionId===t.sessionId&&(e.projectId??null)===(t.projectId??null));return n>=0?n+1:null},xq=e=>{let t=++vq;return _q={targets:e.targets.slice(0,gq),activate:e.activate},()=>{vq===t&&(_q=null)}},Sq=e=>{if(!Number.isInteger(e)||e<1||e>gq)return!1;let t=_q,n=t?.targets[e-1];return!t||!n?!1:(t.activate(n),!0)},Cq=e=>{let t=e.trim();if(!t)return null;let n=nf.getState(),r=n.createTab(t);return!r||r===`tab-invalid`?null:(n.setActiveTab(t,r),r)},wq=e=>{let t=e.trim();if(!t)return null;let n=K.getState();return!n.isBottomTerminalOpen&&n.activeMainTab!==`terminal`&&n.setBottomTerminalOpen(!0),Cq(t)},Tq=(e,t)=>{let n=e.trim();if(!n)return!1;let r=nf.getState(),i=r.getDirectoryState(n);if(!i||i.tabs.length<2)return!1;let a=i.tabs.findIndex(e=>e.id===i.activeTabId),o=((a>=0?a:0)+t+i.tabs.length)%i.tabs.length,s=i.tabs[o]?.id;return!s||s===i.activeTabId?!1:(r.setActiveTab(n,s),!0)},Eq=e=>{let t=e.trim();if(!t)return{closed:!1,wasLastTab:!1};let n=nf.getState(),r=n.getDirectoryState(t),i=r?.activeTabId??null;if(!r||!i)return{closed:!1,wasLastTab:!1};let a=r.tabs.length===1;return n.closeTab(t,i),{closed:!0,wasLastTab:a}},Dq=()=>typeof window>`u`||window.parent===window||!ll(window.location.search)?!1:(window.parent.postMessage({type:fl},window.location.origin),!0),Oq=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=K.getState();if(e)return!1;let n=wd();return n&&t(n)?!0:v()?(y(`desktop_close_current_window`).catch(e=>{console.warn(`[keyboard-shortcuts] failed to close current window`,e)}),!0):!1},kq=({sessionId:e,surfaceKind:t,wiringCanAbort:n,primaryCanAbort:r,pendingSend:i=!1})=>e?i||n?!0:t!==`secondary`&&r:!1,Aq=async({sessionId:e,currentProviderId:t,currentModelId:n,waitForConnectionOrThrow:r,getAuthoritativeDirectoryForSession:i,summarizeSession:a,onCompactFailed:o})=>{try{await r();let s=i(e);if(!s){o();return}await a(e,t,n,s)}catch(e){o(e)}},jq=()=>{let e=(0,Q.c)(69),{t}=Xn(),n=Da(Mq),r=Da(Nq),i=Da(Pq),a=Da(Fq),o=_a,s=K(Iq),c=K(Lq),l=K(Rq),u=K(zq),d=K(Bq),f=K(Vq),p=K(Hq),m=K(Uq),h=K(Wq),g=K(Gq),_=K(Kq),x=K(qq),S=K(Jq),C=K(Yq),w=K(Xq),T=K(Zq),E=K(Qq),D=K($q),O=K(eJ),k=He(tJ),A=pa(nJ),{themeMode:j,setThemeMode:M}=_s(),{working:N}=AR(),P=Z.useRef(null),F=Z.useRef(null),I=Z.useRef(null),L=Z.useRef(!1),R=Z.useRef(j),z,B;e[0]===j?(z=e[1],B=e[2]):(z=()=>{R.current=j},B=[j],e[0]=j,e[1]=z,e[2]=B),Z.useEffect(z,B);let V;e[3]===i?V=e[4]:(V=()=>{F.current&&=(clearTimeout(F.current),null),P.current=null,i()},e[3]=i,e[4]=V);let H=V,U;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(U=()=>{I.current&&=(clearTimeout(I.current),null),Km.getState().clear()},e[5]=U):U=e[5];let W=U,ee;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(ee=()=>{I.current&&=(clearTimeout(I.current),null);let e=Km.getState().arm(Gm);I.current=setTimeout(()=>{let{expiresAt:e}=Km.getState();e&&Date.now()>=e&&Km.getState().clear(),I.current=null},Math.max(0,e-Date.now()))},e[6]=ee):ee=e[6];let te=ee,ne;e[7]!==A?.id||e[8]!==A?.path||e[9]!==r||e[10]!==k||e[11]!==h||e[12]!==n||e[13]!==H||e[14]!==_||e[15]!==C||e[16]!==m||e[17]!==S||e[18]!==E||e[19]!==d||e[20]!==f||e[21]!==g||e[22]!==x||e[23]!==M||e[24]!==w||e[25]!==O||e[26]!==t||e[27]!==p||e[28]!==s||e[29]!==D||e[30]!==c||e[31]!==T||e[32]!==u||e[33]!==l||e[34]!==N?(ne=()=>{let e=e=>Nc(e,O),i=e=>Dc(e,O),a=rJ,j=[`[data-slot="dropdown-menu-content"]`,`[data-slot="select-content"]`,`[role="combobox"]`,`[role="listbox"]`,`[role="menu"]`,`[role="menuitem"]`,`[role="option"]`,`[data-radix-popper-content-wrapper]`].join(`,`),I=e=>e instanceof Element&&!!e.closest(j),z=aJ,B=sJ,V=cJ,U=async()=>{let e=fT(),n=e?vT(e):null;if(n&&e){try{await n.compact({providerID:e.selection.value.providerID,modelID:e.selection.value.modelID,agent:e.selection.value.agent,variant:e.selection.value.variant})}catch(e){let n=e;Yr.error(n instanceof Error?n.message:t(`chat.chatInput.toast.compactFailed`))}return}let r=Da.getState().currentSessionId;if(!r)return;let{currentProviderId:i,currentModelId:a}=ni.getState();await Aq({sessionId:r,currentProviderId:i,currentModelId:a,waitForConnectionOrThrow:Ai,getAuthoritativeDirectoryForSession:Da.getState().getAuthoritativeDirectoryForSession,summarizeSession:lJ,onCompactFailed:e=>{Yr.error(e instanceof Error?e.message:t(`chat.chatInput.toast.compactFailed`))}})},ee=t=>{let r=Km.getState().pending;if(t.repeat||t.isComposing&&!r||t.defaultPrevented&&!r||a(t.target)&&!r)return;let i=e(`leader_key`);if(r){let e=()=>{L.current=!0,window.setTimeout(()=>{L.current=!1},0)};if(i&&Mc(t,i)){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),te();return}let r=t.key.toLowerCase();if(r===`escape`){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),W();return}if(t.key===`Control`||t.key===`Shift`||t.key===`Alt`||t.key===`Meta`)return;if(t.metaKey||t.ctrlKey||t.altKey){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();return}let{activeMainTab:a,isModelSelectorOpen:o,isAgentSelectorOpen:s}=K.getState(),c=dT(a)&&!V();if(r===`m`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),window.requestAnimationFrame(()=>{S(!o,{instant:!0})});return}if(r===`a`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),C(!s,{instant:!0});return}if(r===`n`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();let r=fT(),i=r?vT(r):null;i?i.shortcut(`new`):(_(`chat`),g(!1),n());return}if(r===`c`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),U(),B();return}t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),B();return}if(!i||!Mc(t,i)||V())return;let{activeMainTab:o}=K.getState();dT(o)&&(t.preventDefault(),t.stopPropagation(),te())},ne=()=>Km.getState().pending||L.current,re=e=>{ne()&&e.preventDefault()},G=e=>{ne()&&(e.preventDefault(),e.stopPropagation())},ie=t=>{if(a(t.target)){if(!b()&&Mc(t,e(`new_terminal_tab`))){let e=wd();if(!e||!Cq(e))return;t.preventDefault(),t.stopPropagation();return}if(!b()&&Mc(t,e(`previous_terminal_tab`))){let e=wd();if(!e||!Tq(e,-1))return;t.preventDefault(),t.stopPropagation();return}if(!b()&&Mc(t,e(`next_terminal_tab`))){let e=wd();if(!e||!Tq(e,1))return;t.preventDefault(),t.stopPropagation();return}if(Mc(t,e(`close_context_panel_tab`))){let e=wd();if(!e)return;let{closed:n,wasLastTab:r}=Eq(e);if(!n)return;if(t.preventDefault(),t.stopPropagation(),r){let e=K.getState();e.setBottomTerminalOpen(!1),e.activeMainTab===`terminal`&&e.setActiveMainTab(`chat`)}return}if(Mc(t,e(`toggle_terminal`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(Mc(t,e(`toggle_bottom_panel`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(Mc(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),m(!n);return}}},ae=uJ,oe=t=>{if(t.defaultPrevented||t.isComposing||t.keyCode===229)return;if(Mc(t,e(`close_context_panel_tab`))){(Dq()||Oq())&&(t.preventDefault(),t.stopPropagation());return}if(a(t.target))return;let r=dJ;if(r(t.target)&&t.ctrlKey&&!t.metaKey&&!t.shiftKey&&!t.altKey&&t.key.toLowerCase()===`t`){t.preventDefault(),ae();return}if(Mc(t,e(`open_command_palette`))){t.preventDefault(),s();return}if(Mc(t,e(`open_timeline_dialog`))){t.preventDefault(),w(!0);return}if(Mc(t,e(`toggle_prompt_navigator`))){let{activeMainTab:e,promptNavigatorEnabled:n,isSettingsDialogOpen:r,isCommandPaletteOpen:i,isHelpDialogOpen:a,isSessionSwitcherOpen:o,isAboutDialogOpen:s,isTimelineDialogOpen:c,isMultiRunLauncherOpen:l,isImagePreviewOpen:u}=K.getState();if(!n||h||b()||e!==`chat`||r||i||a||o||s||c||l||u)return;t.preventDefault(),T();return}if(Mc(t,e(`open_status`))){t.preventDefault(),BK();return}if(Mc(t,e(`open_help`))){t.preventDefault(),c();return}if(v()&&Mc(t,e(`new_mini_chat`))){t.preventDefault(),y(`desktop_open_draft_mini_chat_window`,{directory:k||A?.path||``,projectId:A?.id??null}).catch(fJ);return}let o=Mc(t,e(`new_chat`)),C=Mc(t,e(`new_chat_worktree`));if(o||C){if(t.preventDefault(),_(`chat`),g(!1),!b()&&C){sS();return}n();return}if(Mc(t,e(`cycle_theme`))){if(t.preventDefault(),Cp()!==null&&window.parent&&window.parent!==window){window.parent.postMessage({type:`yuri:cycle-theme-request`},window.location.origin);return}let e=[`light`,`dark`,`system`],n=document.activeElement,r=(e.indexOf(R.current)+1)%e.length;M(e[r]),requestAnimationFrame(()=>{typeof document>`u`||typeof window>`u`||(document.hasFocus()||window.focus(),n&&document.contains(n)&&n.focus({preventScroll:!0}))});return}if(Gc(t,`in`,e(`zoom_in`))){t.preventDefault(),pq();return}if(Gc(t,`out`,e(`zoom_out`))){t.preventDefault(),mq();return}if(Mc(t,e(`zoom_reset`))){t.preventDefault(),hq();return}if(Mc(t,e(`open_settings`))){t.preventDefault();let{isSettingsDialogOpen:e}=K.getState();x(!e);return}if(Mc(t,e(`toggle_sidebar`))){t.preventDefault();let{isMobile:e,isSessionSwitcherOpen:n}=K.getState();e?g(!n):l();return}if(Mc(t,e(`focus_input`))){t.preventDefault(),document.querySelector(`textarea[data-chat-input="true"]`)?.focus();return}let E=e(`cycle_agent`),O=E&&!E.includes(`shift`)?Sc(`shift+${E}`):``,j=O&&Mc(t,O)?-1:+!!Mc(t,E);if(j!==0){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s}=K.getState();if(e||n||i||a||o||!dT(s)||!r(t.target))return;let c=fT(),l=c?vT(c):null;if(l){t.preventDefault(),l.shortcut(`cycle`,j);return}let u=ni.getState(),d=Ri(u.getVisibleAgents(),u.currentAgentName,j);if(!d)return;t.preventDefault(),u.setAgent(d),K.getState().addRecentAgent(d);let f=Da.getState().currentSessionId;f&&wi.getState().saveSessionAgentSelection(f,d);return}if(i(`toggle_right_sidebar`).some(e=>Mc(t,e))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),u();return}if(Mc(t,e(`open_right_sidebar_git`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),d(!0),f(`git`);return}if(Mc(t,e(`open_right_sidebar_files`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),d(!0),f(`files`);return}if(Mc(t,e(`cycle_right_sidebar_tab`))){let{isMobile:e,rightSidebarTab:n}=K.getState();if(e)return;let r=AK({hideGit:K.getState().activeMainTab===`git`,showBrowser:Ac(Uc())}),i=r[(r.indexOf(n)+1)%r.length];t.preventDefault(),d(!0),f(i);return}let N=e=>rq(e,Da.getState().currentSessionId,e=>{_(`chat`),g(!1),Da.getState().setCurrentSession(e.sessionId,e.directory)});if(i(`previous_session`).some(e=>Mc(t,e))){t.preventDefault(),N(-1);return}if(i(`next_session`).some(e=>Mc(t,e))){t.preventDefault(),N(1);return}for(let n=1;n<=9;n+=1)if(Mc(t,e(`switch_tab_${n}`))){Sq(n)&&t.preventDefault();return}if(Mc(t,e(`toggle_terminal`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),p();return}if(Mc(t,e(`open_new_terminal`))){let{isMobile:e}=K.getState();if(e||b())return;let n=wd();if(!n||!wq(n))return;t.preventDefault();return}if(Mc(t,e(`toggle_bottom_panel`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),p();return}if(Mc(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=K.getState();if(e)return;t.preventDefault(),m(!n);return}if(Mc(t,e(`open_model_selector`))){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isAboutDialogOpen:a,activeMainTab:o,isModelSelectorOpen:s}=K.getState();if(e)return;let c=n||r||i||a,l=dT(o);if(c||!l)return;t.preventDefault(),S(!s,{instant:!0});return}if(Mc(t,e(`cycle_thinking_variant`))){ae()&&t.preventDefault();return}if(Mc(t,e(`cycle_favorite_model_forward`))||Mc(t,e(`cycle_favorite_model_backward`))){let{isSettingsDialogOpen:n,isCommandPaletteOpen:r,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s,favoriteModels:c,addRecentModel:l}=K.getState();if(n)return;let u=r||i||a||o,d=dT(s);if(u||!d||c.length===0)return;t.preventDefault();let f=c.length,p=Mc(t,e(`cycle_favorite_model_forward`))?1:-1,m=fT();if(m?.selection.change){let e=m.selection.value.providerID,t=m.selection.value.modelID,n=c[(c.findIndex(n=>n.providerID===e&&n.modelID===t)+p+f)%f],r=ni.getState().providers.find(e=>e.id===n.providerID)?.models?.find(e=>e.id===n.modelID),i=r?.variants?Object.keys(r.variants):[],a=n.variant!==void 0&&i.includes(n.variant)?n.variant:void 0;m.selection.change({...m.selection.value,providerID:n.providerID,modelID:n.modelID,variant:a}),l(n.providerID,n.modelID,a);return}let{currentProviderId:h,currentModelId:g,providers:_,setProvider:v,setModel:y,setCurrentVariant:b}=ni.getState(),x=c[(c.findIndex(e=>e.providerID===h&&e.modelID===g)+p+f)%f];v(x.providerID),y(x.modelID);let S=_.find(e=>e.id===x.providerID)?.models?.find(e=>e.id===x.modelID),C=S?.variants?Object.keys(S.variants):[],w=x.variant!==void 0&&C.includes(x.variant)?x.variant:void 0;b(w),l(x.providerID,x.modelID,w);return}if(Mc(t,e(`expand_input`))){if(h)return;t.preventDefault(),D();return}if(Mc(t,e(`toggle_dictation`))){let{activeMainTab:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isSettingsDialogOpen:a}=K.getState();if(!dT(e)||n||r||i||a)return;t.preventDefault(),window.dispatchEvent(new CustomEvent(`yuri:dictation-toggle`));return}},se=e=>{if(e.key!==`Escape`||e.isComposing)return;let t=e.target,n=!!t?.closest(`[role="dialog"]`),i=!!document.querySelector(`[data-settings-view="true"]`),a=!!(t?.closest(`.terminal-viewport-container`)||t?.getAttribute(`data-terminal-hidden-input`)===`true`),s=I(t)||z(),{isSettingsDialogOpen:c,isCommandPaletteOpen:l,isHelpDialogOpen:u,isSessionSwitcherOpen:d,isAboutDialogOpen:f,isMultiRunLauncherOpen:p,isImagePreviewOpen:m,isPromptNavigatorPanelOpen:h}=K.getState();if(n||a||s){H();return}if(h){e.preventDefault(),E(!1),H();return}if(c){e.preventDefault(),x(!1),H();return}if(i){H();return}if(l||u||d||f||p||m){H();return}let g=fT(),_=g?vT(g):null,v=g?.sessionID??Da.getState().currentSessionId,y=!!(v&&Da.getState().pendingSendMessageIDs.get(v));if(!kq({sessionId:v,surfaceKind:g?.kind,wiringCanAbort:_?.canAbort,primaryCanAbort:N.canAbort,pendingSend:y})){H();return}e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();let b=Date.now(),S=P.current;if(S&&b<S){H(),_?_.abort():(v&&Vr(v),o(v??``));return}let C=g?.kind===`secondary`?b+3e3:r(3e3)??b+3e3;P.current=C,F.current&&clearTimeout(F.current);let w=Math.max(C-b,0);F.current=setTimeout(()=>{P.current&&Date.now()>=P.current&&H()},w||0)};return window.addEventListener(`keydown`,ee,!0),window.addEventListener(`beforeinput`,re,!0),window.addEventListener(`compositionstart`,G,!0),window.addEventListener(`compositionupdate`,G,!0),window.addEventListener(`compositionend`,G,!0),window.addEventListener(`keydown`,ie,!0),window.addEventListener(`keydown`,se,!0),window.addEventListener(`keydown`,oe),()=>{window.removeEventListener(`keydown`,ee,!0),window.removeEventListener(`beforeinput`,re,!0),window.removeEventListener(`compositionstart`,G,!0),window.removeEventListener(`compositionupdate`,G,!0),window.removeEventListener(`compositionend`,G,!0),window.removeEventListener(`keydown`,ie,!0),window.removeEventListener(`keydown`,se,!0),window.removeEventListener(`keydown`,oe)}},e[7]=A?.id,e[8]=A?.path,e[9]=r,e[10]=k,e[11]=h,e[12]=n,e[13]=H,e[14]=_,e[15]=C,e[16]=m,e[17]=S,e[18]=E,e[19]=d,e[20]=f,e[21]=g,e[22]=x,e[23]=M,e[24]=w,e[25]=O,e[26]=t,e[27]=p,e[28]=s,e[29]=D,e[30]=c,e[31]=T,e[32]=u,e[33]=l,e[34]=N,e[35]=ne):ne=e[35];let re=A?.id,G=A?.path,ie;e[36]!==r||e[37]!==k||e[38]!==a||e[39]!==h||e[40]!==n||e[41]!==H||e[42]!==_||e[43]!==C||e[44]!==m||e[45]!==S||e[46]!==E||e[47]!==d||e[48]!==f||e[49]!==g||e[50]!==x||e[51]!==M||e[52]!==w||e[53]!==O||e[54]!==t||e[55]!==re||e[56]!==G||e[57]!==p||e[58]!==s||e[59]!==D||e[60]!==c||e[61]!==T||e[62]!==u||e[63]!==l||e[64]!==N?(ie=[n,o,s,c,l,u,d,f,p,m,h,g,_,x,S,C,w,T,E,D,M,N,r,H,te,W,a,k,re,G,O,t],e[36]=r,e[37]=k,e[38]=a,e[39]=h,e[40]=n,e[41]=H,e[42]=_,e[43]=C,e[44]=m,e[45]=S,e[46]=E,e[47]=d,e[48]=f,e[49]=g,e[50]=x,e[51]=M,e[52]=w,e[53]=O,e[54]=t,e[55]=re,e[56]=G,e[57]=p,e[58]=s,e[59]=D,e[60]=c,e[61]=T,e[62]=u,e[63]=l,e[64]=N,e[65]=ie):ie=e[65],Z.useEffect(ne,ie);let ae,oe;e[66]===H?(ae=e[67],oe=e[68]):(oe=()=>()=>{H(),W()},ae=[H,W],e[66]=H,e[67]=ae,e[68]=oe),Z.useEffect(oe,ae)};function Mq(e){return e.openNewSessionDraft}function Nq(e){return e.armAbortPrompt}function Pq(e){return e.clearAbortPrompt}function Fq(e){return e.currentSessionId}function Iq(e){return e.toggleCommandPalette}function Lq(e){return e.toggleHelpDialog}function Rq(e){return e.toggleSidebar}function zq(e){return e.toggleRightSidebar}function Bq(e){return e.setRightSidebarOpen}function Vq(e){return e.setRightSidebarTab}function Hq(e){return e.toggleBottomTerminal}function Uq(e){return e.setBottomTerminalExpanded}function Wq(e){return e.isMobile}function Gq(e){return e.setSessionSwitcherOpen}function Kq(e){return e.setActiveMainTab}function qq(e){return e.setSettingsDialogOpen}function Jq(e){return e.setModelSelectorOpen}function Yq(e){return e.setAgentSelectorOpen}function Xq(e){return e.setTimelineDialogOpen}function Zq(e){return e.togglePromptNavigatorPanel}function Qq(e){return e.setPromptNavigatorPanelOpen}function $q(e){return e.toggleExpandedInput}function eJ(e){return e.shortcutOverrides}function tJ(e){return e.currentDirectory}function nJ(e){return e.getActiveProject()}function rJ(e){return e instanceof Element&&!!(e.closest(`[data-terminal-view="true"]`)||e.closest(`.terminal-viewport-container`)||e.getAttribute(`data-terminal-hidden-input`)===`true`)}function iJ(e){return e.getClientRects().length>0}function aJ(){let e=document.querySelectorAll(`[data-slot="dropdown-menu-content"], [data-slot="select-content"], [role="menu"], [data-radix-popper-content-wrapper]`);return Array.from(e).some(iJ)}function oJ(){document.querySelector(`textarea[data-chat-input="true"]`)?.focus({preventScroll:!0})}function sJ(){window.requestAnimationFrame(oJ)}function cJ(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i}=K.getState();return e||t||n||r||i}function lJ(e,t,n,r){return se.summarizeSession(e,t,n,r)}function uJ(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i,activeMainTab:a}=K.getState();if(e||t||n||r||i||!dT(a))return!1;let o=fT();if(o?.selection.change){let e=o.selection.catalog?.variants??[];if(e.length===0)return!1;let t=o.selection.value.variant,n=e[((t?e.indexOf(t):-1)+1)%e.length];return o.selection.change({...o.selection.value,variant:n}),!0}let s=ni.getState();if(s.getCurrentModelVariants().length===0)return!1;s.cycleCurrentVariant();let c=ni.getState().currentVariant,l=Da.getState().currentSessionId,u=ni.getState().currentAgentName,d=ni.getState().currentProviderId,f=ni.getState().currentModelId;return l&&u&&d&&f&&wi.getState().saveAgentModelVariantForSession(l,u,d,f,c),u&&d&&f&&ni.getState().saveAgentModelSelection(u,d,f,c),!0}function dJ(e){return e instanceof HTMLTextAreaElement&&e.getAttribute(`data-chat-input`)===`true`}function fJ(e){console.warn(`[keyboard-shortcuts] failed to open draft mini chat window`,e)}var pJ=3,mJ=(e,t)=>{if(typeof e!=`string`)return t;let n=e.trim().replace(/\s+/g,` `);return n?n.slice(0,48):t},hJ=(e,t)=>{let n=t?[...e.filter(e=>e.id===t),...e.filter(e=>e.id!==t)]:e,r=[],i=new Set;for(let e of n){let t=typeof e.id==`string`?e.id.trim():``;if(!(!t||i.has(t))&&(i.add(t),r.push({sessionId:t,title:mJ(e.title,`Session ${r.length+1}`)}),r.length>=pJ))break}return r},gJ=()=>{let e=(0,Q.c)(9),t=Oi(),n=Da(_J),r;e[0]!==n||e[1]!==t?(r=hJ(t,n),e[0]=n,e[1]=t,e[2]=r):r=e[2];let i=r,a;e[3]===i?a=e[4]:(a=JSON.stringify(i),e[3]=i,e[4]=a);let o=a,s,c;e[5]!==i||e[6]!==o?(s=()=>{if(!(typeof window>`u`||!h())){try{i.length===0?localStorage.removeItem(Pc):localStorage.setItem(Pc,o)}catch{return}window.__YURI_UPDATE_PWA_MANIFEST__?.()}},c=[i,o],e[5]=i,e[6]=o,e[7]=s,e[8]=c):(s=e[7],c=e[8]),Z.useEffect(s,c)};function _J(e){return e.currentSessionId}var vJ=e=>Number.isFinite(e)?`${Math.max(0,Math.round(e))}px`:`0px`,yJ=(e,t,n,r)=>{e.style.setProperty(`--yuri-wco-left-inset`,vJ(t)),e.style.setProperty(`--yuri-wco-right-inset`,vJ(n)),e.style.setProperty(`--yuri-wco-titlebar-height`,vJ(r))},bJ=()=>{let e=(0,Q.c)(1),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],Z.useEffect(xJ,t)};function xJ(){if(typeof window>`u`||!h())return;let e=document.documentElement,t=typeof window.matchMedia==`function`?window.matchMedia(`(display-mode: window-controls-overlay)`):null,n=window.navigator.windowControlsOverlay,r=()=>{if(!n||!t?.matches||!n.visible){yJ(e,0,0,0);return}let r=n.getTitlebarAreaRect(),i=Math.max(0,Number(r.x)||0),a=Math.max(0,Number(r.width)||0),o=Math.max(0,Number(r.height)||0),s=Math.max(0,window.innerWidth-(i+a));yJ(e,i,s,o)},i=()=>{r()};return r(),window.addEventListener(`resize`,r),window.addEventListener(`focus`,r),t&&(typeof t.addEventListener==`function`?t.addEventListener(`change`,i):typeof t.addListener==`function`&&t.addListener(i)),n&&typeof n.addEventListener==`function`&&n.addEventListener(`geometrychange`,r),()=>{window.removeEventListener(`resize`,r),window.removeEventListener(`focus`,r),t&&(typeof t.removeEventListener==`function`?t.removeEventListener(`change`,i):typeof t.removeListener==`function`&&t.removeListener(i)),n&&typeof n.removeEventListener==`function`&&n.removeEventListener(`geometrychange`,r),yJ(e,0,0,0)}}var SJ=3e4,CJ=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,wJ=e=>e instanceof Zo?e.status===501?`unsupported`:e.status>=400&&e.status<500&&e.status!==408&&e.status!==429&&e.code!==`revision_conflict`?`permanent`:`retry`:`retry`,TJ=(e,t)=>new Promise((n,r)=>{let i=()=>{clearTimeout(a),t.removeEventListener(`abort`,i),r(new DOMException(`Aborted`,`AbortError`))},a=setTimeout(()=>{t.removeEventListener(`abort`,i),n()},e);t.aborted?i():t.addEventListener(`abort`,i,{once:!0})}),EJ=(e,t)=>e.then(e=>{if(t?.aborted)throw new DOMException(`Aborted`,`AbortError`);return e}),DJ={fetchSnapshot:e=>EJ(ki(xn),e),refreshSnapshot:e=>EJ(yr(xn),e),fetchOrder:kr,setOrder:Tr,waitInvalidation:pi,captureRuntime:()=>({transportIdentity:o(),generation:c()}),isCurrent:e=>e.transportIdentity===o()&&e.generation===c(),sleep:TJ,createRequestID:()=>typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`worktree-order-${Date.now()}-${Math.random().toString(36).slice(2)}`},OJ=new Map,kJ=()=>{for(let e of OJ.values())e.controller.abort();OJ.clear()},AJ=(e,t,n,r=DJ)=>{OJ.get(e)?.controller.abort();let i={projectDirectory:CJ(t),orderedPaths:[...n],capture:r.captureRuntime(),controller:new AbortController,backoffMs:500,running:!1};OJ.set(e,i),jJ(e,r)},jJ=async(e,t=DJ)=>{let n=OJ.get(e);if(!(!n||n.running)){n.running=!0;try{for(;;){let n=OJ.get(e);if(!n||!t.isCurrent(n.capture)||n.controller.signal.aborted)return;let r=Mo.getState().serverRevisionByProject[e]??0;n.expectedRevision!==r&&(n.expectedRevision=r,n.requestID=t.createRequestID());try{let i=await t.setOrder({requestID:n.requestID,projectDirectory:n.projectDirectory,expectedRevision:r,orderedPaths:n.orderedPaths,signal:n.controller.signal});if(!t.isCurrent(n.capture)||OJ.get(e)!==n)return;let a=i.worktreeOrder??{projectDirectory:n.projectDirectory,orderedPaths:n.orderedPaths,revision:i.revision};Mo.getState().setServerRevision(e,a.revision),Mo.getState().resolvePendingWorktreeOrder(e,a.revision),OJ.delete(e);return}catch(r){if(n.controller.signal.aborted||!t.isCurrent(n.capture)||OJ.get(e)!==n)return;if(r instanceof Zo&&r.code===`revision_conflict`)try{let r=await t.fetchOrder(n.projectDirectory,n.controller.signal);if(OJ.get(e)!==n||!t.isCurrent(n.capture))return;Mo.getState().applyServerWorktreeOrder(e,r.orderedPaths,r.revision),n.expectedRevision=void 0,n.requestID=void 0,n.backoffMs=500;continue}catch(e){if(wJ(e)!==`retry`)return}else if(wJ(r)!==`retry`)return;if(await t.sleep(n.backoffMs,n.controller.signal).catch(()=>{}),n.backoffMs=Math.min(n.backoffMs*2,SJ),n.controller.signal.aborted)return}}}finally{OJ.get(e)===n&&(!t.isCurrent(n.capture)||n.controller.signal.aborted)&&OJ.delete(e),OJ.get(e)===n&&(n.running=!1)}}},MJ=(e,t,n,r)=>{let i=new Map(t.map(e=>[CJ(e.path),e.id]));for(let t of e){let e=i.get(CJ(t.projectDirectory));e&&r.isCurrent(n)&&Mo.getState().applyServerWorktreeOrder(e,t.orderedPaths,t.revision)}},NJ=(e,t=DJ)=>{let n=null,r=()=>n?.abort();return{start:()=>{r(),n=new AbortController;let i=n.signal,a=t.captureRuntime();(async()=>{let n=0,r=500;for(;!i.aborted&&t.isCurrent(a);)try{let r=await t.fetchSnapshot(i);if(i.aborted||!t.isCurrent(a))return;n=r.revision;let o=e();MJ(r.worktreeOrders,o,a,t);let s=new Set(r.worktreeOrders.map(e=>CJ(e.projectDirectory)));for(let e of o){let n=Mo.getState(),r=n.orderByProject[e.id];n.pendingProjectIDs[e.id]?AJ(e.id,e.path,r??[],t):r?.length&&!s.has(CJ(e.path))&&(n.markPendingWorktreeOrder(e.id),AJ(e.id,e.path,r,t))}break}catch(e){if(wJ(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,SJ)}for(;!i.aborted&&t.isCurrent(a);)try{let o=await t.waitInvalidation(n,{signal:i});if(i.aborted||!t.isCurrent(a)||o===`aborted`)return;let s=await(t.refreshSnapshot??t.fetchSnapshot)(i);if(i.aborted||!t.isCurrent(a))return;n=s.revision,MJ(s.worktreeOrders,e(),a,t),r=500}catch(e){if(wJ(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,SJ)}})()},stop:r}},PJ=()=>{let e=(0,Q.c)(2),t=pa(IJ),n;e[0]===t?n=e[1]:(n=[t],e[0]=t,e[1]=n),Z.useEffect(zJ,n)};function FJ(e){return[e.id,CJ(e.path)]}function IJ(e){return JSON.stringify(e.projects.map(FJ))}function LJ(e,t,n){return AJ(e,t,n)}function RJ(){return pa.getState().projects}function zJ(){let e=o();Mo.getState().activateWorktreeOrderRuntime(e);let t=go(LJ),n=NJ(RJ);n.start();let r=i(e=>{l(e)&&(kJ(),Mo.getState().activateWorktreeOrderRuntime(o()),n.start())});return()=>{t(),r(),n.stop(),kJ()}}var BJ=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,VJ=e=>{let t=!1,n=0,r=0,i=0,a=!1,o=new Set,s=new Map,c=new Map,l=new Set,u=new Set,d=new Map,f=new Set,p=new Set,m=new Set,h=``,g=[],_=t=>{let n=BJ(t);return e.getProjects().find(e=>BJ(e.path)===n)},v=(n,i=150,a=!1)=>{let l=BJ(n.path);if(a&&(o.has(l)||s.has(l)||c.has(l)))return;let u=c.get(l);u&&e.clearTimer(u.timer);let d=r,f=e.setTimer(()=>{!t||d!==r||(c.delete(l),s.set(l,n),y(d))},i);c.set(l,{timer:f,epoch:d})},y=(n=r)=>{if(!(!t||n!==r))for(;i<2&&s.size>0;){let n=[...s.entries()].find(([e])=>!o.has(e));if(!n)break;let[a,c]=n;s.delete(a),i+=1,o.add(a);let l=e.generation(),u=r;e.refresh(c,{isCurrent:()=>t&&u===r&&l===e.generation()}).then(n=>{if(!(!t||u!==r||l!==e.generation())){m.add(a);for(let t of n.addedDirectories){let n=BJ(t);(!e.needsSessionSync||e.needsSessionSync(n))&&f.add(n)}if(e.needsSessionSync)for(let t of n.worktrees){let n=BJ(t.path);e.needsSessionSync(n)&&f.add(n)}b(u,l),x()}}).then(()=>{t&&u===r&&l===e.generation()&&d.delete(a)}).catch(()=>{if(!t||u!==r||l!==e.generation())return;let n=(d.get(a)??0)+1;d.set(a,n),t&&u===r&&v(c,[1e3,2e3,5e3,15e3,3e4][Math.min(n-1,4)])}).finally(()=>{u===r&&(--i,o.delete(a),y(u))})}},b=(n,i)=>{if(f.size===0)return;let a=[...f];f.clear(),e.syncAdded(a).catch(()=>{if(t&&n===r&&i===e.generation()){for(let e of a)f.add(e);let o=e.setTimer(()=>{l.delete(o),t&&n===r&&b(n,i)},1e3);l.add(o)}})},x=()=>{if(m.size!==e.getProjects().length)return;let t=e.getCatalog();for(let e of p){let n=e.slice(e.indexOf(`:`)+1);[...t.entries()].some(([e,t])=>BJ(e)===n||t.some(e=>BJ(e.path)===n))||u.add(e)}},S=()=>{m.clear();for(let t of e.getProjects())v(t,0,!0)},C=()=>{let t=e.getCatalog(),r=e.getProjects(),i=new Set;for(let t of e.getActiveDirectories())t.trim()&&i.add(BJ(t));for(let e of[...p]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||p.delete(e)}for(let e of[...u]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||u.delete(e)}for(let e of i)if(!r.find(n=>{let r=BJ(n.path),i=t.get(r)?.some(t=>BJ(t.path)===e);return e===r||i})){let t=`${n}:${e}`;!u.has(t)&&!p.has(t)&&(p.add(t),S())}},w=()=>{r+=1,u.clear(),p.clear(),d.clear(),f.clear(),m.clear();for(let t of c.values())e.clearTimer(t.timer);c.clear();for(let t of l)e.clearTimer(t);l.clear(),s.clear(),o.clear(),i=0};return{start:()=>{t||e.isVSCode()||(t=!0,a=!1,g.push(e.subscribeEvents(e=>{if(e.type===`event-stream-ready`){if(!a){a=!0,S();return}n+=1,w(),S()}if(e.type===`worktree-topology-changed`&&e.projectDirectory){let t=_(e.projectDirectory);t&&v(t)}})),h=e.getProjects().map(e=>`${e.id}\u0000${BJ(e.path)}`).sort().join(`
6607
6607
  `),g.push(e.subscribeProjects(()=>{let t=e.getProjects().map(e=>`${e.id}\u0000${BJ(e.path)}`).sort().join(`
6608
6608
  `);t!==h&&(h=t,w(),S(),C())})),g.push(e.subscribeCatalog(C)),g.push(e.subscribeSessions(C)),g.push(e.subscribeRuntime(e=>{e&&(a=!1,n+=1,w(),S())})),S(),C())},stop:()=>{t=!1,w();for(let{timer:t}of c.values())e.clearTimer(t);for(c.clear(),s.clear(),i=0;g.length;)g.pop()?.()},reconcileAll:S}},HJ=null,UJ=0,WJ=()=>(HJ||=VJ({isVSCode:b,getProjects:()=>pa.getState().projects,getCatalog:()=>Da.getState().availableWorktreesByProject,getActiveDirectories:()=>{let e=Br.getState(),t=[];for(let n of e.activeSessions)typeof n.directory==`string`&&t.push(n.directory);for(let n of e.cachedDirectories)t.push(n);return t},needsSessionSync:e=>{let t=Br.getState(),n=BJ(e);return!t.loadedDirectories.has(n)&&!t.loadingDirectories.has(n)&&!t.refreshingDirectories.has(n)},refresh:qs,syncAdded:e=>Vi(e,Br.getState().activeSessions),subscribeProjects:e=>pa.subscribe(e),subscribeCatalog:e=>Da.subscribe((t,n)=>{t.availableWorktreesByProject!==n.availableWorktreesByProject&&e()}),subscribeSessions:e=>Br.subscribe((t,n)=>{(t.activeSessions!==n.activeSessions||t.cachedDirectories!==n.cachedDirectories)&&e()}),subscribeEvents:ii,subscribeRuntime:e=>i(t=>e(l(t))),generation:c,setTimer:(e,t)=>globalThis.setTimeout(e,t),clearTimer:e=>globalThis.clearTimeout(e)}),UJ+=1,HJ.start(),()=>{UJ=Math.max(0,UJ-1),UJ===0&&HJ?.stop()});function GJ(){if(S()?.runtime.isVSCode)return()=>{};let e=new gn(xn,Vc()),t=ii(e=>{(e.type===`speech-settings-changed`||e.type===`event-stream-ready`)&&xn.invalidateQueries({queryKey:Vc().queryKey,exact:!0})}),n=t=>{if(!t.data||e.options.queryKey[0]!==o())return;let n=ni.getState();Object.entries(t.data).some(([e,t])=>n[e]!==t)&&ni.setState(t.data)},r=e.subscribe(n);n(e.getCurrentResult());let a=i(()=>{ni.setState(Cr),e.setOptions(Vc()),n(e.getCurrentResult())});return()=>{a(),r(),t(),e.destroy()}}var KJ=`yuri:mini-chat-presence`,qJ=()=>{let e=ih(),t=Z.useRef(e.optimistic.add),n=Z.useRef(e.optimistic.remove),r=Z.useRef(e.optimistic.confirm);return t.current=e.optimistic.add,n.current=e.optimistic.remove,r.current=e.optimistic.confirm,Z.useEffect(()=>{Di(e=>t.current(e),e=>n.current(e),e=>r.current(e))},[]),Z.useEffect(()=>WJ(),[]),null},JJ=()=>{let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],Z.useEffect(QJ,t),null},YJ=Z.memo(function(e){let t=(0,Q.c)(3),{embeddedBackgroundWorkEnabled:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0],Z.useEffect(GJ,r);let i=Z.useSyncExternalStore(Ir,Li,Li);Ui(n&&i===`legacy-enabled`),Ci();let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=[],t[1]=a):a=t[1],Z.useEffect($J,a);let o;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(qJ,{}),t[2]=o):o=t[2],o}),XJ=Z.memo(function(e){let t=(0,Q.c)(6),{embeddedBackgroundWorkEnabled:n}=e;gJ(),bJ(),jq(),PJ();let r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0],Z.useEffect(eY,r);let i;t[1]===n?i=t[2]:(i=(0,$.jsx)(YJ,{embeddedBackgroundWorkEnabled:n}),t[1]=n,t[2]=i);let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(JJ,{}),t[3]=a):a=t[3];let o;return t[4]===i?o=t[5]:(o=(0,$.jsxs)($.Fragment,{children:[i,a]}),t[4]=i,t[5]=o),o});function ZJ(e){let t=e.data;if(t?.type!==`mini-chat-session-presence`||!t.sessionId||!t.directory)return;let n=t.viewed!==!1;Hi(t.directory,t.sessionId,n),n&&Lo(t.sessionId)}function QJ(){if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(KJ);return e.onmessage=ZJ,()=>e.close()}function $J(){let e=as(),t=os();e.start(),t.start();let n=ma(e);return()=>{n(),t.stop(),e.stop()}}function eY(){fq()}var tY=new Set,nY=new Map,rY=(e,t)=>`https://cdn.jsdelivr.net/npm/${encodeURIComponent(e.packageName).replace(`%40`,`@`).replace(`%2F`,`/`)}/files/${e.filePrefix}-latin-${t}-normal.woff2`,iY=(e,t)=>{let n=`${e.family}:${t}`;if(tY.has(n))return Promise.resolve();let r=nY.get(n);if(r)return r;if(typeof document>`u`||typeof FontFace>`u`||!document.fonts)return Promise.resolve();let i=new FontFace(e.family,`url(${rY(e,t)}) format('woff2')`,{style:`normal`,weight:String(t),display:`swap`});document.fonts.add(i);let a=i.load().then(()=>{tY.add(n)}).catch(n=>{document.fonts.delete(i),console.warn(`Failed to load font: ${e.family} ${t}`,n)}).finally(()=>{nY.delete(n)});return nY.set(n,a),a},aY=e=>e?Promise.all(e.weights.map(t=>iY(e,t))).then(()=>void 0):Promise.resolve(),oY=e=>aY(_t[e]?.source),sY=e=>aY(gt[e]?.source),cY={family:`Syne`,packageName:`@fontsource/syne`,filePrefix:`syne`,weights:[700]},lY=()=>aY(cY);function uY(){let e=(0,Q.c)(4),{uiFont:t,monoFont:n}=rf(),r,i;e[0]!==n||e[1]!==t?(r=()=>{if(typeof document>`u`)return;let e=document.documentElement,r=_t[t]?.stack??_t.system.stack,i=gt[n]?.stack??gt[`system-mono`].stack;oY(t),sY(n),e.style.setProperty(`--font-sans`,r),e.style.setProperty(`--font-heading`,r),e.style.setProperty(`--font-family-sans`,r),e.style.setProperty(`--font-mono`,i),e.style.setProperty(`--font-family-mono`,i),e.style.setProperty(`--ui-regular-font-weight`,`400`),document.body&&(document.body.style.fontFamily=r)},i=[t,n],e[0]=n,e[1]=t,e[2]=r,e[3]=i):(r=e[2],i=e[3]),Z.useEffect(r,i)}export{eC as $,ZH as A,Bp as At,uP as B,TK as C,ih as Ct,WU as D,$p as Dt,oG as E,am as Et,lF as F,Pf as Ft,uO as G,Nk as H,fF as I,df as It,kw as J,Vw as K,BP as L,cf as Lt,Tz as M,mp as Mt,mL as N,pp as Nt,VU as O,Qp as Ot,uF as P,op as Pt,ww as Q,dP as R,uf as Rt,kK as S,uh as St,VG as T,ym as Tt,Sk as U,Tk as V,JO as W,Aw as X,Ow as Y,Tw as Z,VK as _,Kv as _t,YJ as a,SS as at,jK as b,Zh as bt,bq as c,Gx as ct,pq as d,Ex as dt,US as et,mq as f,hx as ft,HK as g,my as gt,UK as h,Cb as ht,XJ as i,_S as it,UV as j,Rp as jt,yU as k,Jp as kt,xq as l,Kx as lt,JK as m,bb as mt,lY as n,yS as nt,wq as o,vS as ot,rq as p,Db as pt,jw as q,oY as r,bS as rt,yq as s,sS as st,uY as t,gS as tt,hq as u,Dx as ut,WK as v,Jv as vt,xK as w,Em as wt,AK as x,Eh as xt,BK as y,zv as yt,fP as z,of as zt};