@yuriai/web 0.2.38-beta.4 → 0.2.38
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.
- package/dist/assets/{AgentAvatar-CjZAr6nn.js → AgentAvatar-B2GEBJBG.js} +1 -1
- package/dist/assets/{AssistantContactStatus-DoZk9r1D.js → AssistantContactStatus-CGFpgAuL.js} +3 -3
- package/dist/assets/{AssistantUnreadBadge-BJHZUf6Z.js → AssistantUnreadBadge-DDw7a4MF.js} +1 -1
- package/dist/assets/{AssistantView-DkjXm6xL.js → AssistantView-DpYyl49H.js} +1 -1
- package/dist/assets/{DiagramView-Byel_g4U.js → DiagramView-CrjS-7Qg.js} +1 -1
- package/dist/assets/{FadeInOnReveal-BrPG6IFE.js → FadeInOnReveal-BWkJi5dK.js} +1 -1
- package/dist/assets/{GuiPluginPage-C6iXAYM8.js → GuiPluginPage-Ct7QUMjH.js} +1 -1
- package/dist/assets/{GuiPluginSurface-DPXPl4xG.js → GuiPluginSurface-C1a1HAzL.js} +1 -1
- package/dist/assets/{GuiPluginWindow-BdtIwEmZ.js → GuiPluginWindow-CGnY_Jp_.js} +1 -1
- package/dist/assets/{Icon-C5rHjO1K.js → Icon-Co7WGN1G.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-Cdj2zS3j.js → ImageLoadingPlaceholder-KEVw1Pg-.js} +1 -1
- package/dist/assets/{LoadingImage-Gh9OduKR.js → LoadingImage-PH45V6oj.js} +1 -1
- package/dist/assets/MarkdownRenderer-CZpY_qyH.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-H41Q6Ds9.js → MarkdownRendererImpl-v1YoJHFp.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-CJcHC4Ts.js → MarkstreamRendererImpl-UwcR7nzW.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-fdYiFD76.js → MobileDetailNavigation-B8t6gz_S.js} +1 -1
- package/dist/assets/{MobileResizableSheet-DDzgYZmt.js → MobileResizableSheet-Dd1w8a-6.js} +1 -1
- package/dist/assets/{MobileShareBridge-BNPPhHGf.js → MobileShareBridge-DCE_Ahre.js} +1 -1
- package/dist/assets/{MobileTabPageHeader-ZZPrTJl4.js → MobileTabPageHeader-BYRAlNQp.js} +1 -1
- package/dist/assets/{MultiRunWindow-DoeszXM5.js → MultiRunWindow-CxjpWlHn.js} +1 -1
- package/dist/assets/{OnboardingScreen-BrYqOlrO.js → OnboardingScreen-4LgzNqG4.js} +1 -1
- package/dist/assets/{OverlayScrollbar-8lCP3DZq.js → OverlayScrollbar-BQua3Ko6.js} +1 -1
- package/dist/assets/{SettingsView-UuXi7Uya.js → SettingsView-DxqpYiwv.js} +1 -1
- package/dist/assets/{SettingsWindow-DIYoXakh.js → SettingsWindow-DmhZHg_E.js} +1 -1
- package/dist/assets/{SetupTourDialog-BF50uUTW.js → SetupTourDialog-CzNscVSi.js} +1 -1
- package/dist/assets/{TerminalView-uVsRpvjV.js → TerminalView-BAqu9LRw.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Bz23N8ob.js → ToolOutputDialog-C5b57FEy.js} +1 -1
- package/dist/assets/{VoiceSettings-DbbeM4JG.js → VoiceSettings-D4aaoz88.js} +1 -1
- package/dist/assets/{appThemeRegistry-DE7vwd6j.js → appThemeRegistry-DDaIHQum.js} +1 -1
- package/dist/assets/{capgoAdapter-BPZyUAQO.js → capgoAdapter-CXcqPnFa.js} +1 -1
- package/dist/assets/{checkbox-Dgn0NjAK.js → checkbox-o8x1LJC4.js} +1 -1
- package/dist/assets/{collapsible-DbkDwHwV.js → collapsible-ZLW5y35Q.js} +1 -1
- package/dist/assets/{context-menu-HomYNhkr.js → context-menu-Bv2RsqQe.js} +1 -1
- package/dist/assets/{diagram-if-ktgjK.js → diagram-hqhzT9yo.js} +1 -1
- package/dist/assets/{dialog-0fjbRGoX.js → dialog-C7D331XW.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-OwF_hr-t.js → fileMentionTouchSelection-C3_guqVF.js} +1 -1
- package/dist/assets/{gitApi-dAPSCbXA.js → gitApi-BOyQ2o3N.js} +1 -1
- package/dist/assets/{input-DYmLJuhI.js → input-os0CMgxY.js} +1 -1
- package/dist/assets/{insertionBoundaries-CYfwgLf1.js → insertionBoundaries-CGcJ-kUX.js} +1 -1
- package/dist/assets/{main-CaueNFt7.js → main-DmQr5rK8.js} +4 -4
- package/dist/assets/{main-DrIci_pj.js → main-x_36xEI7.js} +2 -2
- package/dist/assets/{markdownHeightCache-D8yqNy2h.js → markdownHeightCache-BWCMEzOk.js} +1 -1
- package/dist/assets/{mcpQueries-DO2TKARf.js → mcpQueries-C3EdKlJU.js} +1 -1
- package/dist/assets/{miniChat-BTI2ObZ2.js → miniChat-Dz4oT5h0.js} +2 -2
- package/dist/assets/{mobile-Cf_sQtW6.js → mobile-C2wjDVrA.js} +2 -2
- package/dist/assets/{mobile-html-network-CsjZ_Ur0.js → mobile-html-network-DuXwrtnU.js} +2 -2
- package/dist/assets/{mobileBackNavigation-DxG3cz8q.js → mobileBackNavigation-C456iV52.js} +1 -1
- package/dist/assets/{mobileConnections-CK4dMDCg.js → mobileConnections-DrUWc7kd.js} +2 -2
- package/dist/assets/{multirun-Cd2-PUEk.js → multirun-CdraBH9O.js} +1 -1
- package/dist/assets/{native-config-C_nB8tLu.js → native-config-3LSj_OuN.js} +1 -1
- package/dist/assets/{projectMeta-apTlCt8d.js → projectMeta-CyhJE6CA.js} +1 -1
- package/dist/assets/{pwa-wwvKWKhX.js → pwa-BzFEQ5Js.js} +1 -1
- package/dist/assets/{queue-abort-optimistic-BnynR3mX.js → queue-abort-optimistic-CMMw3KSM.js} +1 -1
- package/dist/assets/{react-B-mb0CtR.js → react-BJAlol6I.js} +1 -1
- package/dist/assets/{readiness-0tATst8c.js → readiness-DmMVD6xM.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-xQdVdaLB.js → renderElectronMiniChatApp-CVNOL7vy.js} +2 -2
- package/dist/assets/{renderMobileApp-D95eHLRE.js → renderMobileApp-rVz5UaT-.js} +4 -4
- package/dist/assets/{runtimeConfig-BfzZj4LK.js → runtimeConfig-CAAd0cno.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-CjKHwDvh.js → runtimeEndpointReset-DKk9B2jX.js} +3 -3
- package/dist/assets/{select-B9Km1pk9.js → select-ClX56nrO.js} +1 -1
- package/dist/assets/{sessionLookup-8gdDN8Tx.js → sessionLookup-DC2xZn-T.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-BU0Puyy0.js → sortable-tabs-strip-BQbGMaz-.js} +1 -1
- package/dist/assets/{speechSettingsQueries-C9LCquzH.js → speechSettingsQueries-85xpCH5y.js} +1 -1
- package/dist/assets/{src-BFQde2OG.css → src-ByI2s7WK.css} +1 -1
- package/dist/assets/{textarea-bB6aD-GS.js → textarea-DpsaIedI.js} +1 -1
- package/dist/assets/{tooltip-DgWHbKz2.js → tooltip-pELJ38kd.js} +1 -1
- package/dist/assets/types-D-KYekEQ.js +2 -0
- package/dist/assets/{useAppFontEffects-DJp1u2mc.js → useAppFontEffects-CMJ-srCU.js} +39 -39
- package/dist/assets/{useDesktopWindowControlsLayout-DOmb8EnW.js → useDesktopWindowControlsLayout-DBBGRsuU.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-DmGrksdp.js → useEffectiveDirectory--tyiZ84r.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-CJBLQxTz.js → useMobileNavigationStore-Dr61mYqA.js} +4 -4
- package/dist/assets/{usePluginsStore-El9Tx9Q3.js → usePluginsStore-P6_c6c0m.js} +1 -1
- package/dist/assets/{useStreamingTextThrottle-BbUkYQhX.js → useStreamingTextThrottle-D3YtOLbE.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-CZ8YG-Hi.js → useWorkerHighlightedLines-CO7SlSqM.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/mini-chat.html +6 -6
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/dist/assets/MarkdownRenderer-DErp8UoS.js +0 -2
- package/dist/assets/types-CnJjf4tP.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-
|
|
2
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,S as n,l as r,s as i,w as a,x as o,y as s}from"./runtime-auth-mjIpsk3N.js";import{c,f as l,i as u,l as d,n as f,o as p,r as m,t as h}from"./runtime-switch-BMjl5Y5W.js";import{n as g}from"./runtime-fetch-DKZOpfzo.js";import{A as _,D as v,E as y,R as b,S as x,T as S,a as C,et as w,i as T,k as E,n as D,t as O,y as k}from"./platform-DMsFWy1a.js";import{t as A}from"./runtimeAPIRegistry-C2VogTny.js";import{_ as j,b as M,c as N,d as P,f as F,g as I,h as L,i as R,l as z,m as B,n as V,o as H,r as U,s as W,v as ee}from"./desktopHosts-DovfbQPm.js";import{r as te}from"./desktopRelayRestore-D4pbpNKN.js";import{a as G,i as ne,o as re,r as ie,s as ae,t as oe}from"./vendor-zustand-vDaAPGfl.js";import{at as se,f as ce,g as le,h as ue,m as de,ot as fe,p as pe,st as me}from"./vendor-base-ui-CzHs0bHY.js";import{$n as he,Ai as ge,Ar as _e,At as ve,Ba as ye,Cn as be,Cr as xe,Dn as Se,Dr as Ce,Dt as we,Ei as Te,Er as Ee,Et as De,Fa as Oe,Fi as ke,Fr as Ae,Ga as je,Gn as Me,Gr as Ne,Gt as Pe,Hr as Fe,Ia as Ie,Ii as Le,Ir as Re,Jn as ze,Jt as Be,Ka as Ve,Kn as He,Kr as Ue,Kt as We,Mn as Ge,Mr as Ke,Mt as qe,Na as Je,Nn as Ye,Nr as Xe,Nt as Ze,Oi as Qe,Ot as $e,Pi as et,Pr as tt,Qa as nt,Qn as rt,Qr as it,Qt as at,Rr as ot,Sn as st,Ta as ct,Tn as lt,Tr as ut,Tt as dt,Un as ft,Ut as pt,Vi as mt,Vr as ht,Vt as gt,Xn as _t,Xr as vt,Xt as yt,Yt as bt,Za as xt,Zn as St,Zr as Ct,Zt as wt,_o as Tt,_r as Et,an as Dt,bn as Ot,br as kt,bt as At,cr as jt,di as Mt,dr as Nt,ei as Pt,en as Ft,fn as It,gn as Lt,gr as Rt,hn as zt,io as Bt,ir as Vt,ja as Ht,ji as Ut,ka as Wt,ki as Gt,kn as Kt,kr as qt,lo as Jt,lr as Yt,no as Xt,nr as Zt,on as Qt,pn as $t,pr as en,qt as tn,ro as nn,rr as rn,sn as an,so as on,tr as sn,un as cn,ur as ln,wn as un,wr as dn,xn as K,xr as fn,yn as pn,yr as mn,zi as hn,zr as gn}from"./gitApiHttp-B1mApXwC.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{C as _n,a as vn,b as yn,f as bn,g as xn,o as Sn,r as q,w as Cn,x as wn,y as Tn}from"./useUIStore-BF882_0b.js";import{n as En}from"./vendor-react-DlzBev0S.js";import{i as Dn}from"./vendor-tanstack-query-core-Y_YoRHtC.js";import{c as On,i as kn,n as An,o as jn,t as Mn}from"./vendor-tanstack-react-query-B-Wpqq5J.js";import{_ as Nn,d as Pn,g as Fn,l as In,p as Ln,u as Rn}from"./fileQueries-D9l0crnM.js";import{a as zn,i as Bn,n as Vn,o as Hn,t as Un}from"./path-utils-jGozTg9d.js";import{o as Wn}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as Gn,o as Kn,r as qn}from"./useMobileHtmlPreviewStore-C03uVLfX.js";import{r as Jn}from"./bootstrap-BhC95qVC.js";import{n as Yn,t as Xn}from"./pathNormalization-ewtPqJWn.js";import{i as Zn,u as Qn}from"./vendor-pierre-diffs-BFiZ3IhI.js";import{r as $n,t as er}from"./vendor-sonner-BEHGipm5.js";import{a as tr,d as nr,h as rr,i as ir,m as ar,o as or,p as sr,r as J,s as cr}from"./vendor-reactuses-core-CuTmqEMK.js";import{n as lr,o as ur,s as dr,t as fr}from"./i18n-BU14awhU.js";import{i as pr,t as mr}from"./store-BNNIbb4k.js";import{$ as hr,$t as gr,Ai as _r,Ar as vr,B as yr,Ba as br,Bn as xr,Br as Sr,Bt as Cr,Ci as wr,Cn as Tr,D as Er,Di as Dr,Dn as Or,Dr as kr,Dt as Ar,E as jr,Ea as Mr,Ei as Nr,En as Pr,Et as Fr,Fn as Ir,G as Lr,Gi as Rr,Gn as zr,Gr as Br,H as Vr,Hn as Hr,Hr as Ur,I as Wr,Ii as Gr,In as Kr,It as qr,J as Jr,Ji as Yr,Jn as Y,Jt as Xr,K as Zr,Ki as Qr,Kn as $r,Li as ei,Ln as ti,M as ni,N as ri,Na as ii,Ni as ai,Nn as oi,O as si,Oi as ci,Or as li,Ot as ui,P as di,Pa as fi,Pi as pi,Pn as mi,Pt as hi,Qi as gi,Ra as _i,Rn as vi,Rt as yi,S as bi,Sn as xi,T as Si,Ta as Ci,Ti as wi,Tn as Ti,Tt as Ei,U as Di,Ui as Oi,Un as ki,Ur as Ai,Ut as ji,V as Mi,Vn as Ni,Vr as Pi,W as Fi,Wi as Ii,Wn as Li,Wr as Ri,Wt as zi,X as Bi,Xi as Vi,Y as Hi,Yi as Ui,Yn as Wi,Yt as Gi,Zi as Ki,Zt as qi,_ as Ji,_n as Yi,_t as Xi,a as Zi,aa as Qi,ai as $i,ar as ea,at as ta,bi as na,br as ra,bt as ia,c as aa,ca as oa,cr as sa,ct as ca,dn as la,dt as ua,en as da,er as fa,fi as pa,fn as ma,ft as ha,gn as ga,gr as _a,gt as va,h as ya,hn as ba,hr as xa,ht as Sa,i as Ca,in as wa,it as Ta,ji as Ea,k as Da,ki as Oa,kn as ka,kr as Aa,kt as ja,l as Ma,lt as Na,mn as Pa,mt as Fa,n as Ia,na as La,nn as Ra,nr as za,oi as Ba,on as Va,or as Ha,ot as Ua,p as Wa,pn as Ga,pt as Ka,qi as qa,qt as Ja,r as Ya,rr as Xa,rt as Za,sn as Qa,sr as $a,st as eo,tn as to,ui as no,un as ro,vi as io,vn as ao,vt as oo,w as so,wi as co,wn as lo,wt as uo,xa as fo,xi as po,xn as mo,xr as ho,xt as go,yi as _o,yn as vo,yt as yo,zi as bo,zn as xo,zt as So}from"./useMobileNavigationStore-CJBLQxTz.js";import"./vendor-opencode-schema-DWT45VBX.js";import{d as Co,f as wo,g as To,l as Eo,n as Do,t as Oo,u as ko}from"./fileMentionAutocompleteState-BZJqfgae.js";import{t as Ao}from"./agentColors-DWSbQXy2.js";import{t as jo}from"./dualLimitLru-D8Sphgua.js";import{a as Mo,i as No,r as Po,t as Fo}from"./AgentAvatar-CjZAr6nn.js";import{n as Io,r as Lo,t as Ro}from"./useThemeSystem-CNzUUkFn.js";import{o as zo}from"./vendor-framer-motion-DDMKlXiP.js";import{n as X}from"./Icon-C5rHjO1K.js";import{a as Bo,i as Vo,n as Ho,o as Uo,r as Wo,s as Go,t as Ko}from"./dialog-0fjbRGoX.js";import{E as qo,V as Jo,k as Yo,n as Xo}from"./gitApi-dAPSCbXA.js";import{a as Zo}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{t as Qo}from"./checkbox-Dgn0NjAK.js";import{t as $o}from"./input-DYmLJuhI.js";import{i as es,n as ts,t as ns}from"./tooltip-DgWHbKz2.js";import{$ as rs,At as is,B as as,Bt as os,Ct as ss,Dt as cs,G as ls,H as us,I as ds,K as fs,Ot as ps,P as ms,Pt as hs,St as gs,U as _s,V as vs,Vt as ys,W as bs,Z as xs,_t as Ss,bt as Cs,c as ws,dt as Ts,et as Es,ft as Ds,gt as Os,it as ks,lt as As,pt as js,r as Ms,rt as Ns,t as Ps,tt as Fs,ut as Is,wt as Ls,xt as Rs,zt as zs}from"./pwa-wwvKWKhX.js";import{t as Bs}from"./YuriLogo-DcoYyXzq.js";import{o as Vs,t as Hs}from"./react-B-mb0CtR.js";import{r as Us}from"./device-DNG0cNwQ.js";import{a as Ws,i as Gs,n as Ks,r as qs,t as Js}from"./themes-BgDJcxRc.js";import{_ as Ys,d as Xs,g as Zs,m as Qs}from"./scheduledTaskNavigation-PH-etFzZ.js";import{t as $s}from"./theme-validation-BGYdrOu7.js";import{a as ec,i as tc,n as nc,r as rc,t as ic}from"./MarkdownRenderer-DErp8UoS.js";import{S as ac,b as oc,t as sc,x as cc}from"./MobileResizableSheet-DDzgYZmt.js";import{A as lc,C as uc,D as dc,E as fc,M as pc,N as mc,O as hc,S as gc,_ as _c,b as vc,c as yc,d as bc,f as xc,g as Sc,h as Cc,j as wc,k as Tc,l as Ec,m as Dc,p as Oc,s as kc,u as Ac,v as jc,w as Mc,x as Nc,y as Pc}from"./sessionLookup-8gdDN8Tx.js";import{a as Fc,i as Ic,o as Lc,s as Rc,u as zc}from"./fileMentionTouchSelection-OwF_hr-t.js";import{C as Bc,E as Vc,O as Hc,S as Uc,T as Wc,a as Gc,b as Kc,c as qc,d as Jc,f as Yc,i as Xc,l as Zc,n as Qc,o as $c,p as el,r as tl,s as nl,t as rl,u as il,w as al,x as ol,y as sl}from"./insertionBoundaries-CYfwgLf1.js";import{c as cl,d as ll,f as ul,i as dl,n as fl,o as pl,s as ml,t as hl}from"./select-B9Km1pk9.js";import{C as gl,D as _l,E as vl,M as yl,O as bl,S as xl,T as Sl,_ as Cl,a as wl,b as Tl,c as El,d as Dl,f as Ol,g as kl,h as Al,k as jl,l as Ml,m as Nl,p as Pl,r as Fl,s as Il,t as Ll,u as Rl,v as zl,w as Bl,x as Vl,y as Hl}from"./appThemeRegistry-DE7vwd6j.js";import{a as Ul,i as Wl,n as Gl,t as Kl}from"./useDictation-CyWtsxSn.js";import{A as ql,C as Jl,D as Yl,E as Xl,F as Zl,I as Ql,L as $l,M as eu,N as tu,O as nu,P as ru,S as iu,T as au,_ as ou,a as su,b as cu,c as lu,d as uu,f as du,g as fu,h as pu,j as mu,k as hu,l as gu,m as _u,n as vu,o as yu,p as bu,r as xu,s as Su,t as Cu,u as wu,v as Tu,w as Eu,x as Du,y as Ou}from"./queue-abort-optimistic-BnynR3mX.js";import{a as ku,o as Au,t as ju,u as Mu}from"./toolHelpers-iEHVHQ9p.js";import{n as Nu,t as Pu}from"./useEffectiveDirectory-DmGrksdp.js";import{c as Fu,n as Iu,o as Lu,r as Ru}from"./image-loading-DEXNCcCm.js";import{t as zu}from"./ImageLoadingPlaceholder-Cdj2zS3j.js";import{t as Bu}from"./LoadingImage-Gh9OduKR.js";import{_ as Vu,a as Hu,c as Uu,g as Wu,l as Gu,o as Ku,t as qu,v as Ju,y as Yu}from"./vendor-dnd-kit-core-DK4OoOTr.js";import{i as Xu,n as Zu,o as Qu,s as $u,t as ed}from"./vendor-dnd-kit-sortable-Cv69eQm1.js";import{a as td,i as nd,l as rd,n as id,o as ad,s as od,t as sd}from"./FadeInOnReveal-BrPG6IFE.js";import{t as cd}from"./OverlayScrollbar-8lCP3DZq.js";import{n as ld,r as ud}from"./textarea-bB6aD-GS.js";import{n as dd,r as fd,t as pd}from"./vendor-tanstack-react-virtual-DSFNK3qc.js";import{C as md,S as hd,_ as gd,a as _d,b as vd,f as yd,g as bd,h as xd,i as Sd,l as Cd,m as wd,n as Td,o as Ed,s as Dd,u as Od,v as kd,x as Ad}from"./projectMeta-apTlCt8d.js";import{_ as jd,a as Md,f as Nd,g as Pd,h as Fd,i as Id,m as Ld,o as Rd,r as zd,s as Bd,t as Vd,v as Hd,y as Ud}from"./useWorkerHighlightedLines-CZ8YG-Hi.js";import{t as Wd}from"./vendor-cmdk-C_tivUtr.js";import{t as Gd}from"./sortable-tabs-strip-BU0Puyy0.js";import{a as Kd}from"./markdownHeightCache-D8yqNy2h.js";import{a as qd,i as Jd,n as Yd,o as Xd}from"./speechSettingsQueries-C9LCquzH.js";import{n as Zd}from"./vendor-marked-S3gCOYp1.js";import{n as Qd}from"./markdownTheme-CHNl6tUv.js";import{t as $d}from"./vendor-motion-C9oiAdx-.js";import{t as ef}from"./useStreamingTextThrottle-BbUkYQhX.js";import{n as tf,t as nf}from"./useFontPreferences-CAdw6cBK.js";var rf=e=>{if(typeof e!=`string`)return;let t=e.trim();if(t)return{location:{directory:t}}};typeof window<`u`&&(window.__opencodeDebug={getLastAssistantMessage(){let e=Wa.getState().currentSessionId;if(!e)return null;let t=vt(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=(Ct(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:(Ct(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=Wa.getState().currentSessionId;if(!t)return[];let n=vt(t);return`${n.length}`,n.forEach((e,t)=>{let n=Ct(e.id)||[];`${t}${e.role}${e.id}${n.length}`}),e?this.truncateMessages(n):n},async getAppStatus(){let e=At.getState(),t=Wa.getState(),n=Mr.getState(),r=e.currentDirectory||null,i=Kt.getDirectory()??null,a=it(),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=A(),u=typeof window<`u`&&!!window.__YURI_ELECTRON__,d=async e=>{try{return await e.json()}catch{return null}},f=async e=>{try{return await e.text()}catch{return null}},p=async e=>{try{let t=await g(e);return t.ok?await d(t):{status:t.status}}catch(e){return{error:e instanceof Error?e.message:String(e)}}},m=null,h=null,_=null,v=null;try{let e=await Kt.getSdkClient().location.get(rf(r));m=Ye(e)}catch(e){m={error:e instanceof Error?e.message:String(e)}}try{h=(await Kt.getSdkClient().location.get(rf(r)))?.project??null}catch(e){h={error:e instanceof Error?e.message:String(e)}}_=await p(`/api/config/settings`);try{let e=await g(`/api/health`),t=e.headers.get(`content-type`)||``,n=await f(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 Xo(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:m?.directory||m?.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:m,projectInfo:h,health:v},yuri:{settingsInfo:_}}},async buildDiagnosticsReport(){let e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return Ea(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=Wa.getState(),t=ka.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=Wa.getState().currentSessionId;if(!e)return[];let t=vt(e).filter(e=>e.role===`assistant`).filter(e=>{let t=Ct(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=Ct(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=Wa.getState().currentSessionId;if(!i)return{summary:null,rows:[]};let a=vt(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=Ct(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=Wa.getState().currentSessionId;if(!e)return null;let t=vt(e).filter(e=>e.role===`assistant`);if(t.length===0)return null;let n=t[t.length-1],r=(Ct(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=ka.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}}},dt(),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(me(),1),Q=En(),af=async()=>{if(typeof window>`u`)return;let e=null;try{e=Tt(`lastDirectory`)}catch(e){console.warn(`Failed to read saved directory preferences:`,e)}e&&!E()&&At.getState().setDirectory(e,{showOverlay:!1})},of=new Map,sf=e=>of.get(e)??null,cf=({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:i},a={})=>{let o=of.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 of.set(e,s),s},lf=async({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,startWatchers:i,onError:a})=>{await cf({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:a})&&i()},uf=(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 df(e){return!e||e===`idle`?null:e===`ready`?`ok`:e===`error`?`unreachable`:`auth`}function ff(e,t){let n=e.via===`relay`;return t?n:!n}function pf(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?df(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||ff(o,a))&&(u=Math.max(0,Math.round(o.latencyMs))),{statusKind:c,showViaRelay:l,latencyMs:u}}function mf({isLocal:e,isSsh:t,isRelay:n}){return e?`connection-local`:n?`connection-relay`:t?`connection-ssh`:`connection-lan`}var $=fe(),hf=`local`,gf=9e4,_f=`SSH connection cancelled`,vf=e=>te(e),yf={},bf=e=>{let t=I(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()=>!v()||!T()?``:H().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 hs().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 hs(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=h(),i=I(n)||n,a=I(t)||t,o=m(),s=e.find(e=>vf(e)===o);if(s)return{id:s.id,label:s.label,url:s.url};if(r&&L(r,n))return{id:hf,label:`Local`,url:i};let c=e.find(e=>r?L(r,P(e)):!1);if(c)return{id:c.id,label:c.label,url:I(P(c))||P(c)};if(t&&L(t,n))return{id:hf,label:`Local`,url:i};let l=e.find(e=>t?L(t,e.url):!1);return l?{id:l.id,label:l.label,url:I(l.url)||l.url}:t.startsWith(`yuri-ui://`)?{id:hf,label:`Local`,url:i}:{id:`custom`,label:ee(a||`Instance`),url:a}};function Pf({open:e,onOpenChange:t,embedded:n=!1,onHostSwitched:r,onBusyChange:i}){let{t:a}=fr(),o=q(e=>e.setSettingsDialogOpen),s=q(e=>e.setSettingsPage),l=ei(e=>e.isConnected),d=ei(e=>e.connectionPhase),[f,p]=Z.useState([]),[m,h]=Z.useState(null),[g,_]=Z.useState(()=>({...yf}));Z.useEffect(()=>{Object.assign(yf,g)},[g]);let[b,x]=Z.useState(!1),[S,C]=Z.useState(!1),[w,E]=Z.useState(!1),D=os(),O=ys(),[k,A]=Z.useState(null),F=k||O,L=Z.useRef(!1),H=J(e=>{L.current=e!==null,A(e),i?.(e!==null)}),[te,G]=Z.useState({}),[ne,re]=Z.useState({}),[ie,ae]=Z.useState({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),[oe,se]=Z.useState(``),[ce,le]=Z.useState(()=>xf()),[ue,de]=Z.useState(null),[fe,pe]=Z.useState(``),[me,he]=Z.useState(``),[ge,_e]=Z.useState(0),ve=Z.useRef(0),ye=Z.useMemo(()=>[Mf(ce),...f.map(e=>({...e,url:I(e.url)||e.url}))],[f,ce]),be=Z.useMemo(()=>new Set(Object.keys(te)),[te]),xe=Z.useMemo(()=>{let e=Nf(ye).id;return ye.filter(t=>t.id===hf||B(t,be)||t.id===e)},[ye,be,ge]);Z.useEffect(()=>c(()=>_e(e=>e+1)),[]);let Se=Z.useMemo(()=>Nf(ye),[ye,ge]),Ce=Z.useMemo(()=>u().startsWith(`relay:`),[ge]),we=Z.useMemo(()=>{let e=m||hf;return ye.find(t=>t.id===e)?.label||a(`desktopHostSwitcher.instance.local`)},[ye,m,a]),Te=J(async(e,t)=>{if(y()){E(!0),se(``);try{if(v()&&!T()){await W();return}let n=e.filter(e=>e.id!==hf);await R({hosts:n,defaultHostId:t}),p(n),h(t)}catch(e){se(e instanceof Error?e.message:a(`desktopHostSwitcher.error.failedToSave`))}finally{E(!1)}}}),Ee=J(()=>{if(v()&&!T()){W().catch(e=>no.error(String(e))),t(!1);return}s(`remote-instances`),o(!0),t(!1)}),De=Z.useCallback(async()=>{if(y()){x(!0),se(``);try{let[e,t,n]=await Promise.all([U(),T()?is().catch(()=>({instances:[]})):Promise.resolve({instances:[]}),T()?Af():Promise.resolve({})]);e.localOrigin&&le(e.localOrigin);let r={};for(let t of e.sshHostIds??[])r[t]=!0;for(let e of t.instances)r[e.id]=!0;p(e.hosts||[]),h(e.defaultHostId??null),G(r),re(n)}catch(e){se(e instanceof Error?e.message:a(`desktopHostSwitcher.error.failedToLoad`)),p([]),h(null),G({}),re({})}finally{x(!1)}}},[a]),Oe=Z.useCallback(async e=>{if(y()){C(!0);try{let t=await Sf(),n=await Promise.all(e.map(async e=>{let n=async()=>{let t=await j(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=I(v()?P(e):e.url);if(!r)return[e.id,{status:`unreachable`,latencyMs:0}];let i=e.id===hf?t:e.clientToken||``,a=await V(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;_(r)}finally{C(!1)}}},[]);Z.useEffect(()=>{if(!e){de(null),pe(``),he(``),A(null),ae({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),se(``);return}De()},[e,De]),Z.useEffect(()=>{e&&Oe(xe)},[e,xe,Oe]),Z.useEffect(()=>{if(!e||!y()||!T())return;let t=!1,n=async()=>{let e=await Af();t||re(e)};n();let r=window.setInterval(()=>{typeof document<`u`&&document.visibilityState!==`visible`||n()},1500);return()=>{t=!0,window.clearInterval(r)}},[e]);let ke=J(async e=>{if(L.current||D)return;let t=e.id===hf?ce:I(e.url)||``,n=e.id===hf?ce:I(P(e))||``,i=!!e.relay&&!e.apiUrl&&e.id!==hf;if(!t&&!i)return;if(v()){if(!n&&!e.relay||D)return;H(e.id);try{let t=e.id===hf?await Sf():null,i=await zs({host:e,inlineProgress:!0,cachedProbe:g[e.id]||null,...e.id===hf?{localApiOrigin:n,localClientToken:t}:{}});_(t=>({...t,[e.id]:i.status})),i.ok&&r?.()}finally{H(null)}return}let o=!!te[e.id];if(e.id!==hf&&o&&y()){let n=ne[e.id],i=await hs(e.id).then(t=>t.find(t=>t.id===e.id)||null).catch(()=>null);i&&(n=i,re(t=>({...t,[e.id]:i})));let o=I(n?.localUrl||e.url||``);if(n?.phase===`ready`&&o){let e=bf(o);r?.(),window.location.assign(e);return}A(e.id);let s=ve.current+1;ve.current=s,ae({open:!0,hostId:e.id,hostLabel:ee(e.label),phase:`master_connecting`,detail:null,error:null,errorCode:null});try{if(await cs(e.id),s!==ve.current)return;let n=await jf(e.id,gf,e=>{re(t=>({...t,[e.id]:e})),ae(t=>({...t,phase:e.phase,detail:e.detail||null,errorCode:e.errorCode||null}))},()=>s!==ve.current);if(s!==ve.current)return;let i=bf(I(n.localUrl||``)||t);r?.(),window.location.assign(i);return}catch(t){if(s!==ve.current)return;let n=t instanceof Error?t.message:String(t);if(n===_f)return;let r=gs(ie.errorCode,n);ae(e=>({...e,error:n,errorCode:r})),no.error(a(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:ee(e.label)}),{description:Rs(a(ss(r)),r,n)});return}finally{s===ve.current&&A(null)}}if(e.id!==hf&&y()){A(e.id);let n=await V(t,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(_(t=>({...t,[e.id]:{status:n.status,latencyMs:n.latencyMs}})),Tf(n.status)){no.error(a(`desktopHostSwitcher.toast.instanceUnreachable`,{host:ee(e.label)})),A(null);return}}let s=bf(t);r?.();try{window.location.assign(s)}catch{window.location.href=s}}),Ae=Z.useCallback(()=>{de(null),pe(``),he(``)},[]),je=Z.useCallback(e=>{e.stopPropagation()},[]),Me=Z.useCallback(async()=>{if(!ue)return;if(ue===hf){Ae();return}let e=M(me);if(!e){se(a(`desktopHostSwitcher.error.invalidUrl`));return}let t=e.persistedUrl,n=(fe||ee(t)).trim(),r=f.map(e=>e.id===ue?{...e,label:n,url:t,apiUrl:t}:e);await Te(r,m),Ae(),e.redeemUrl&&window.location.assign(e.redeemUrl)},[Ae,f,m,fe,me,ue,Te,a]),Ne=Z.useCallback(async e=>{await Te(f,e===hf?hf:e)},[f,Te]),Pe=J(async e=>{if(L.current||D)return;H(e.id);let t=e=>{no.error(a(`desktopHostSwitcher.error.failedToOpenNewWindow`),{description:e instanceof Error?e.message:String(e)})};try{if(e.relay&&e.id!==hf)await z(e.id);else{let t=e.id===hf?ce: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{H(null)}}),Fe=J(async()=>{ve.current+=1,A(null),ae(e=>({...e,open:!1,hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}));let e=bf(ce);if(v()){if(D)return;let e=await Sf();(await zs({host:Mf(ce),localApiOrigin:ce,localClientToken:e})).ok&&r?.();return}r?.(),window.location.assign(e)}),Ie=Z.useCallback(async()=>{let e=ie.hostId||F;ve.current+=1,A(null),ae({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),!(!e||e===hf||!y())&&await ps(e).catch(()=>{})},[ie.hostId,F]),Le=Z.useCallback(()=>{let e=ie.hostId;if(!e)return;let t=ye.find(t=>t.id===e);t&&ke(t)},[ye,ke,ie.hostId]),Re=J(async e=>{if(!(!y()||L.current||D)){H(e.id);try{await cs(e.id),(await jf(e.id,gf,e=>{re(t=>({...t,[e.id]:e}))})).phase===`ready`&&no.success(a(`desktopHostSwitcher.toast.sshConnected`,{host:ee(e.label)}))}catch(t){let n=t instanceof Error?t.message:String(t);if(n!==_f){let t=gs(null,n);no.error(a(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:ee(e.label)}),{description:Rs(a(ss(t)),t,n)})}}finally{H(null)}}});if(!y())return null;let ze=y(),Be=(0,$.jsxs)($.Fragment,{children:[!n&&(0,$.jsxs)(Bo,{className:`flex-shrink-0`,children:[(0,$.jsxs)(Uo,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`connection-local`,className:`h-5 w-5`}),a(`desktopHostSwitcher.title`)]}),(0,$.jsx)(Wo,{children:a(`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:a(`desktopHostSwitcher.header.currentColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:ee(Se.label)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a(`desktopHostSwitcher.header.currentDefaultColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:ee(we)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsxs)($r,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Oe(xe),disabled:!ze||b||S,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)}),a(`desktopHostSwitcher.actions.refresh`)]})})]}),!ze&&(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:a(`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:b?(0,$.jsx)(`div`,{className:`px-2 py-2 text-muted-foreground text-sm`,children:a(`desktopHostSwitcher.state.loading`)}):xe.map(e=>{let t=e.id===hf,r=!!te[e.id],i=r&&T(),o=e.id===Se.id,s=(m||hf)===e.id,c=g[e.id]||null,u=ne[e.id]||null,f=pf({isActive:o,isSsh:i,runtimeIsConnected:l,runtimeConnectionPhase:d,currentTransportIsRelay:Ce,probe:c,sshPhase:u?.phase}),p=f.statusKind,h=f.showViaRelay,_=mf({isLocal:t,isSsh:r,isRelay:o?Ce:h||!!(e.relay&&!e.apiUrl)}),v=_===`connection-local`?a(`desktopHostSwitcher.instance.local`):_===`connection-relay`?`Relay`:_===`connection-ssh`?`SSH`:`LAN`,y=ue===e.id,b=t?ce:I(e.url)||e.url,x=e.id===hf?a(`desktopHostSwitcher.instance.local`):ee(e.label),S=e.relay&&!e.apiUrl?a(`mobile.connect.relay.badge`):ee(b);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 px-3 py-3`,n&&o&&`bg-[var(--interactive-selection)]/25`,y?`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`,y&&`pointer-events-none opacity-70`),onClick:()=>void ke(e),disabled:!!F,"aria-busy":F===e.id,"aria-current":o?`true`:void 0,"aria-label":a(`desktopHostSwitcher.actions.switchToAria`,{instance:x}),children:[(0,$.jsx)(X,{name:F===e.id?`loader-4`:_,className:Y(`size-8 shrink-0 text-muted-foreground`,F===e.id&&`animate-spin`)}),(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:x}),o&&!n&&(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:a(`desktopHostSwitcher.header.current`)}),r&&!n&&(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`})]}),n?(0,$.jsxs)(`div`,{className:`typography-micro flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:v}),f.latencyMs!=null&&(0,$.jsxs)(`span`,{children:[f.latencyMs,` ms`]}),p!==`ok`&&(0,$.jsx)(`span`,{className:Y(`truncate`,wf(p)),children:i&&(!o||F===e.id)?a(kf(u?.phase)):a(Df(p))})]}):(0,$.jsxs)(`div`,{className:Y(`typography-micro truncate`,wf(p)),children:[(0,$.jsx)(`span`,{className:Y(`mr-1 inline-block h-1.5 w-1.5 rounded-full`,Cf(p))}),i&&(!o||F===e.id)?a(kf(u?.phase)):a(Df(p)),f.latencyMs==null?``:a(`desktopHostSwitcher.status.ping`,{ms:f.latencyMs}),h?` · ${a(`settings.remoteInstances.clientAuth.state.viaRelay`)}`:``]}),!n&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70 truncate font-mono`,children:S})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&o&&(0,$.jsx)(X,{name:`check`,className:`size-4 text-foreground`,"aria-label":a(`desktopHostSwitcher.header.current`)}),i&&!t&&(u?.phase===`idle`||!u?.phase?(0,$.jsxs)($r,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 px-2.5`,disabled:!!F,onClick:t=>{t.stopPropagation(),Re(e)},children:[F===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`}),a(`desktopHostSwitcher.actions.connect`)]}):null),(0,$.jsxs)(ns,{delayDuration:600,children:[(0,$.jsx)(es,{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`,s?`bg-interactive-selection text-interactive-selection-foreground`:`text-muted-foreground/60 hover:text-foreground`),onClick:()=>void Ne(e.id),"aria-pressed":s,"aria-label":a(s?`desktopHostSwitcher.actions.defaultInstanceAria`:`desktopHostSwitcher.actions.setAsDefaultAria`),disabled:w||!s&&Ef(p),children:(0,$.jsx)(X,{name:s?`home-fill`:`home`,className:`h-4 w-4`})})}),(0,$.jsx)(ts,{sideOffset:6,children:a(s?`desktopHostSwitcher.header.default`:`desktopHostSwitcher.actions.setAsDefault`)})]}),(0,$.jsxs)(ns,{delayDuration:600,children:[(0,$.jsx)(es,{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(p)?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground/60 hover:text-foreground`),onClick:t=>{t.stopPropagation(),Pe(e)},disabled:!!F||Ef(p),"aria-busy":F===e.id,"aria-label":a(`desktopHostSwitcher.actions.openInNewWindowAria`),children:(0,$.jsx)(X,{name:F===e.id?`loader-4`:`window`,className:Y(`h-4 w-4`,F===e.id&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:Ef(p)?a(`desktopHostSwitcher.state.instanceUnreachable`):a(`desktopHostSwitcher.actions.openInNewWindow`)})]})]})]},e.id)})})}),ze&&ue&&ue!==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:a(`desktopHostSwitcher.edit.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)($r,{type:`button`,variant:`outline`,size:`sm`,onClick:Ae,disabled:w,children:a(`desktopHostSwitcher.actions.cancel`)}),(0,$.jsxs)($r,{type:`button`,size:`sm`,onClick:()=>void Me(),disabled:w,children:[w?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):null,a(`desktopHostSwitcher.actions.save`)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,$.jsx)($o,{value:fe,onChange:e=>pe(e.target.value),onKeyDown:je,placeholder:a(`desktopHostSwitcher.field.labelPlaceholder`),disabled:w}),(0,$.jsx)($o,{value:me,onChange:e=>he(e.target.value),onKeyDown:je,placeholder:a(`desktopHostSwitcher.field.urlPlaceholder`),disabled:w})]})]}),(0,$.jsx)(`div`,{className:Y(`flex-shrink-0 border-t border-[var(--interactive-border)]`,n&&`px-3 py-1`),children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`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`,n&&`rounded-xl px-3 py-3`),onClick:Ee,disabled:!!F,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:a(`desktopHostSwitcher.actions.addInstance`)})]})}),oe&&(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-status-error`,children:oe})]}),Ve=(0,$.jsx)(Ko,{open:ie.open,onOpenChange:e=>{if(!e&&F){Ie();return}ae(t=>({...t,open:e,...e?{}:{hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}}))},children:(0,$.jsxs)(Ho,{className:`w-[min(28rem,calc(100vw-2rem))] max-w-none`,children:[(0,$.jsxs)(Bo,{children:[(0,$.jsxs)(Uo,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(`h-4 w-4`,!ie.error&&`animate-spin`)}),a(`desktopHostSwitcher.ssh.connectingTo`,{host:ie.hostLabel||a(`desktopHostSwitcher.ssh.instanceFallback`)})]}),ie.error?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Wo,{className:`sr-only`,children:a(Ls(gs(ie.errorCode,ie.error)))}),(0,$.jsx)(Cs,{errorCode:ie.errorCode,detail:ie.error})]}):(0,$.jsx)(Wo,{children:ie.detail||a(kf(ie.phase))})]}),ie.error?(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,$.jsx)($r,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{Ee(),Ie()},children:a(`desktopHostSwitcher.sshError.openRemoteSettings`)}),(0,$.jsx)($r,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void Fe(),children:a(`desktopHostSwitcher.actions.switchToLocal`)}),(0,$.jsx)($r,{type:`button`,size:`sm`,onClick:Le,disabled:!ie.hostId,children:a(`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:Be}),Ve]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ko,{open:e,onOpenChange:e=>{!e&&L.current||t(e)},children:(0,$.jsx)(Ho,{className:`w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3`,children:Be})}),Ve]})}function Ff(){let e=(0,Q.c)(11),[t,n]=Z.useState(!1),{t:r}=fr();if(!y())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)($r,{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,{desktop:n=!1}={})=>{let r=!1,a=null,o,s=()=>{if(o?.(),!n)return;let i=t();if(!i)return;let a=()=>{!r&&t()===i&&i.getStatus().failureCode===`relay_authentication_rejected`&&e({kind:`relay-authentication`})};o=i.subscribeStatus(a),a()},l=()=>{if(a||r)return;let o=t();if(n&&o?.getStatus().failureCode===`relay_authentication_rejected`){e({kind:`relay-authentication`});return}let s=m(),c=f(),l=i(),u=new AbortController;a=u;let d=setTimeout(()=>u.abort(),1e4);g(`/auth/session`,{credentials:`include`,signal:u.signal}).then(a=>{r||u.signal.aborted||s!==m()||c!==f()||l!==i()||o!==t()||(a.status===401||n&&o&&a.status===403)&&e({kind:`session`,response:a,relay:!!o})}).catch(()=>{}).finally(()=>{clearTimeout(d),a===u&&(a=null)})},u=c(()=>{a?.abort(),a=null,s()});return window.addEventListener(`yuri:runtime-auth-rejected`,l),n&&window.addEventListener(`focus`,l),s(),()=>{r=!0,a?.abort(),o?.(),u(),window.removeEventListener(`yuri:runtime-auth-rejected`,l),window.removeEventListener(`focus`,l)}},Lf=e=>e.shouldUseDesktopShellPasswordLogin?`locked`:`error`,Rf=`/auth/session`,zf=4,Bf=1500,Vf=`yuri.uiAuth.trustDevice`,Hf=`desktop-local`,Uf=`desktop-local`,Wf=()=>{if(typeof window>`u`)return``;let e=window.__YURI_LOCAL_ORIGIN__;return typeof e==`string`?e.trim():``},Gf=(e,t)=>{let n=I(e),r=I(t);if(!n||!r)return!1;try{return new URL(n).origin===new URL(r).origin}catch{return!1}},Kf=()=>y(),qf=e=>{let t=e.replace(/^\[|\]$/g,``);return t===`localhost`||t===`127.0.0.1`||t===`::1`},Jf=()=>{if(!y())return!1;let e=Wf();if(!e)return!1;let t=h()||(typeof window<`u`?window.location.origin:``);if(Gf(e,t))return!0;try{let e=I(t);return!!(e&&qf(new URL(e).hostname))}catch{return!1}},Yf=()=>Jf()?{clientKind:Hf,dedupeKey:Uf}:{},Xf=async()=>await g(Rf,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}}),Zf=()=>typeof window>`u`?!1:window.localStorage.getItem(Vf)===`true`,Qf=async(e,t)=>{let n=Kf();return await g(Rf,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({password:e,trustDevice:t,issueClientToken:n,clientLabel:`Yuri Desktop`,...Yf()})})},$f=async()=>{if(!y())return``;let e=await g(`/api/client-auth/clients`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:`Yuri Desktop`,...Yf()})}).catch(()=>null);if(!e?.ok)return``;let t=await e.json().catch(()=>null);return typeof t?.token==`string`?t.token.trim():``},ep=()=>y()&&!Jf(),tp=async()=>{if(!y())return null;let e=m(),t=w(),n=e.startsWith(`host:`)?e.slice(5):t?.target===`remote`&&t.status===`ok`&&Gf(t.url,h())?t.hostId:null;if(!n)return null;let r=await U().catch(()=>null);if(m()!==e||!r)return;let i=r?.hosts.find(e=>e.id===n);if(i)return i&&F(i)?i:null},np=async(e,t)=>{if(!y()||typeof window>`u`)return null;let n=await x(`desktop_remote_password_login`,{url:h(),password:e,trustDevice:t,requestHeaders:r()}).catch(()=>null);if(!n||typeof n!=`object`)return null;let i=n.token,a=n.status;return{token:typeof i==`string`?i.trim():``,...typeof a==`number`?{status:a}:{}}},rp=async(e,t)=>{if(!y()||!t)return;let n=await U().catch(()=>null);if(!n)return;if(n.localOrigin&&Gf(n.localOrigin,e)){await R({hosts:n.hosts,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted,localClientToken:t}).catch(()=>void 0);return}let r=!1,i=n.hosts.map(n=>!Gf(P(n),e)||n.clientToken===t?n:(r=!0,{...n,clientToken:t}));r&&await R({hosts:i,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted}).catch(()=>void 0)},ip=async e=>{if(!e)return;let t=h(),i=r();await rp(t,e),d({apiBaseUrl:t,clientToken:e,requestHeaders:Object.keys(i).length>0?i:null,relay:n()})},ap=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},op=()=>{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)(Bs,{width:120,height:120})}),e[0]=t):t=e[0],t},sp=e=>{let t=(0,Q.c)(25),{onRetry:n,errorType:r,retryAfter:i,children:a}=e,o=r===void 0?`network`:r,{t:s}=fr(),c=o===`rate-limit`,l=i?Math.ceil(i/60):1,u;t[0]!==o||t[1]!==c||t[2]!==s?(u=s(c?`sessionAuth.error.rateLimitTitle`:o===`relay-auth`?`sessionAuth.error.relayAuthTitle`:`sessionAuth.error.networkTitle`),t[0]=o,t[1]=c,t[2]=s,t[3]=u):u=t[3];let d;t[4]===u?d=t[5]:(d=(0,$.jsx)(`h1`,{className:`typography-ui-header font-semibold text-destructive`,children:u}),t[4]=u,t[5]=d);let f;t[6]!==o||t[7]!==c||t[8]!==l||t[9]!==s?(f=c?s(l>1?`sessionAuth.error.rateLimitDescriptionPlural`:`sessionAuth.error.rateLimitDescriptionSingle`,{minutes:l}):s(o===`relay-auth`?`sessionAuth.error.relayAuthDescription`:`sessionAuth.error.networkDescription`),t[6]=o,t[7]=c,t[8]=l,t[9]=s,t[10]=f):f=t[10];let p;t[11]===f?p=t[12]:(p=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground max-w-xs`,children:f}),t[11]=f,t[12]=p);let m;t[13]!==d||t[14]!==p?(m=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[d,p]}),t[13]=d,t[14]=p,t[15]=m):m=t[15];let h;t[16]===s?h=t[17]:(h=s(`sessionAuth.error.retry`),t[16]=s,t[17]=h);let g;t[18]!==n||t[19]!==h?(g=(0,$.jsx)($r,{type:`button`,onClick:n,className:`w-full max-w-xs`,children:h}),t[18]=n,t[19]=h,t[20]=g):g=t[20];let _;return t[21]!==a||t[22]!==m||t[23]!==g?(_=(0,$.jsx)(ap,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[m,g,a]})}),t[21]=a,t[22]=m,t[23]=g,t[24]=_):_=t[24],_},cp=({children:e})=>{let{t:r}=fr(),a=Z.useMemo(()=>E(),[]),l=a,u=Z.useMemo(()=>y()&&!a,[a]),[d,h]=Z.useState(()=>l?`authenticated`:`pending`),[g,_]=Z.useState(``),[v,b]=Z.useState(!1),[x,S]=Z.useState(``),[C,w]=Z.useState(void 0),[T,D]=Z.useState(!1),[O,k]=Z.useState(Ds),[A,j]=Z.useState(!1),[M,N]=Z.useState(!1),[P,F]=Z.useState(()=>Zf()),[I,L]=Z.useState(null),[R,z]=Z.useState(l),B=Z.useRef(null),V=Z.useRef(l),H=Z.useRef(0);Z.useEffect(()=>()=>{H.current+=1},[]),Z.useEffect(()=>{typeof window>`u`||window.localStorage.setItem(Vf,P?`true`:`false`)},[P]);let U=Z.useCallback(async()=>{if(l)return Ds;let e=m(),t=f(),n=i(),r=()=>e===m()&&t===f()&&n===i();try{let e=await js();return r()&&k(e),e}catch{return r()&&k(Ds),Ds}},[l]);Z.useEffect(()=>{let e=!1;if(!l)return(async()=>{try{if(!window.isSecureContext||!Zo()){e||j(!1);return}e||j(!0)}catch{e||j(!1)}})(),()=>{e=!0}},[l]);let ee=Z.useRef(0),te=Z.useRef(null),G=Z.useRef(null),ne=Z.useCallback(()=>{te.current!==null&&(window.clearTimeout(te.current),te.current=null)},[]),re=Z.useCallback(()=>{ee.current=0,ne()},[ne]),ie=Z.useCallback(()=>ee.current>=zf?!1:(ee.current+=1,ne(),te.current=window.setTimeout(()=>{te.current=null,G.current?.()},Bf*ee.current),!0),[ne]);Z.useEffect(()=>ne,[ne]);let ae=Z.useCallback(async e=>{if(l){h(`authenticated`);return}let n=++H.current,r=m(),a=f(),o=i(),s=()=>n===H.current&&r===m()&&a===f()&&o===i(),c=y()?t():null;if(c?.getStatus().failureCode===`relay_authentication_rejected`){re(),h(`relay-auth-error`);return}h(e=>e===`authenticated`?e:`pending`);try{let[t,n]=await Promise.all([e??Xf(),e?Ds:U()]),r=await t.text();if(!s())return;if(t.ok){re(),h(`authenticated`),D(!1),S(``),w(void 0);return}if(t.status===401||t.status===403&&(c||y())){let i=c?!0:await tp();if(!s())return;if(i===void 0){re(),h(`error`);return}if(i){re(),D(!1),h(`pairing-expired`),w(void 0);return}if(t.status===403){if(ie())return;h(`error`);return}let a={};try{a=JSON.parse(r)}catch{a={}}re(),D(a.tunnelLocked===!0),e||k(n),h(`locked`),w(void 0);return}if(t.status===429){let e={};try{e=JSON.parse(r)}catch{e={}}re(),w(e.retryAfter),D(!1),h(`rate-limited`);return}if(ie())return;h(`error`),D(!1)}catch(e){if(!s())return;if(console.warn(`Failed to check session status:`,e),c?.getStatus().failureCode===`relay_authentication_rejected`){re(),h(`relay-auth-error`);return}let t=c?!0:await tp();if(!s())return;if(t||t===void 0){if(ie())return;h(`error`),D(!1);return}if(Lf({shouldUseDesktopShellPasswordLogin:ep()})===`locked`){h(`locked`),w(void 0),D(!1);return}if(ie())return;h(`error`),D(!1)}},[U,re,ie,l]);Z.useEffect(()=>{G.current=ae},[ae]),Z.useEffect(()=>{l||ae()},[ae,l]),Z.useEffect(()=>{if(!(l||d!==`authenticated`))return If(e=>{e.kind===`relay-authentication`?(H.current+=1,re(),h(`relay-auth-error`)):ae(e.response)},{desktop:y()})},[ae,re,l,d]),Z.useEffect(()=>{if(d===`pending`||d===`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)}},[d]),Z.useEffect(()=>{if(l)return;let e=uf(e=>{p(e)&&(_(``),S(``),w(void 0),D(!1),re(),z(!1),V.current=!1,h(`pending`),ae())}),t=c(t=>e.schedule(t));return()=>{t(),e.cancel()}},[ae,re,l]),Z.useEffect(()=>{!l&&(d===`locked`||d===`pairing-expired`)&&(V.current=!1,z(!1))},[l,d]),Z.useEffect(()=>{d===`locked`&&B.current&&(B.current.focus(),B.current.select())},[d]),Z.useEffect(()=>{if(!l&&d===`authenticated`&&!V.current){V.current=!0;let e=!1;return cf({runtimeKey:m(),initializeAppearance:ve,syncSettings:qe,applyDirectory:af,onError:(e,t)=>{console.error(`[SessionAuthGate] ${e} settings hydration failed:`,t)}},{force:!0}).then(()=>{e||z(!0)}),()=>{e=!0}}},[l,d]);let oe=async e=>{e.preventDefault(),await le(!1)},se=Z.useCallback(async()=>{L(`register`),N(!0);try{await Ss()}finally{L(null),N(!1)}await U()},[U]),ce=Z.useCallback(()=>{Ts(),L(null),N(!1)},[]),le=Z.useCallback(async e=>{if(!T&&!(!g||v)){M&&ce(),b(!0),S(``);try{if(ep()){let e=await np(g,P);if(e?.token){_(``),D(!1),await ip(e.token),h(`authenticated`);return}if(e?.status===401){S(r(`sessionAuth.error.incorrectPassword`)),D(!1),h(`locked`);return}if(e?.status===429){w(void 0),D(!1),h(`rate-limited`);return}}let t=await Qf(g,P);if(t.ok){let n=await t.json().catch(()=>null),i=Kf(),a=``;if(i&&(a=typeof n?.clientToken==`string`&&n.clientToken.trim()?n.clientToken.trim():``,a||=(await np(g,P))?.token||await $f()),_(``),D(!1),a&&await ip(a),e&&A)try{await se(),no.success(r(`sessionAuth.toast.passkeyAdded`)),h(`authenticated`);return}catch(e){if(Os(e))no.message(r(`sessionAuth.toast.passkeySetupCanceled`));else{let t=e instanceof Error?e.message:r(`sessionAuth.error.passkeySetupFailed`);no.error(t)}h(`authenticated`);return}h(`authenticated`);return}if(t.status===401){S(r(`sessionAuth.error.incorrectPassword`)),D(!1),h(`locked`);return}if(t.status===429){let e=await t.json().catch(()=>({}));w(e.retryAfter),D(!1),h(`rate-limited`);return}S(r(`sessionAuth.error.unexpectedResponse`)),D(!1),h(`error`)}catch(e){console.warn(`Failed to submit UI password:`,e);let t=ep()?await np(g,P):null;if(t?.token){_(``),D(!1),await ip(t.token),h(`authenticated`);return}if(t?.status===401){S(r(`sessionAuth.error.incorrectPassword`)),D(!1),h(`locked`);return}if(t?.status===429){w(void 0),D(!1),h(`rate-limited`);return}S(r(`sessionAuth.error.networkRetry`)),D(!1),h(`error`)}finally{b(!1)}}},[ce,M,v,T,g,se,A,r,P]),ue=Z.useCallback(async()=>{if(!(v||!A)){if(M){ce();return}N(!0),L(`auth`),S(``);try{let e=await Is(P,{issueClientToken:Kf(),clientLabel:`Yuri Desktop`,...Yf()}),t=Kf()&&typeof e?.clientToken==`string`&&e.clientToken.trim()?e.clientToken.trim():``;t&&await ip(t),_(``),h(`authenticated`)}catch(e){if(Os(e))S(``);else{let t=e instanceof Error?e.message:r(`sessionAuth.error.passkeySignInCanceled`);S(t)}}finally{L(null),N(!1)}}},[ce,M,v,A,r,P]),de=Z.useCallback(async()=>{if(!(v||T||!A)){if(M){ce();return}if(d!==`authenticated`){if(!g){S(r(`sessionAuth.error.enterPasswordForPasskey`));return}await le(!0);return}S(``);try{await se(),no.success(r(`sessionAuth.toast.passkeyAdded`))}catch(e){if(Os(e)){no.message(r(`sessionAuth.toast.passkeySetupCanceled`));return}let t=e instanceof Error?e.message:r(`sessionAuth.error.passkeySetupFailed`);no.error(t)}}},[ce,le,M,v,T,g,se,d,A,r]),fe=A&&O.enabled,pe=fe&&O.hasPasskeys;return d===`pending`||d===`authenticated`&&!R?(0,$.jsx)(op,{}):d===`error`?(0,$.jsx)(sp,{onRetry:()=>{re(),ae()},errorType:`network`,children:u&&(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:r(`sessionAuth.locked.hostSwitcherHint`)})]})}):d===`rate-limited`?(0,$.jsx)(sp,{onRetry:()=>void ae(),errorType:`rate-limit`,retryAfter:C}):d===`pairing-expired`?(0,$.jsx)(ap,{children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-xs flex-col items-center gap-6 text-center`,children:[(0,$.jsx)(X,{name:`computer`,className:`size-8 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:r(`mobile.connect.pairing.expired`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:r(`desktopHostSwitcher.pairing.reconnectHint`)})]}),(0,$.jsx)($r,{type:`button`,className:`w-full`,onClick:()=>{W().catch(()=>no.error(r(`sessionAuth.error.networkTitle`)))},children:r(`settings.remoteInstances.openLocalManager`)}),(0,$.jsx)(Ff,{})]})}):d===`relay-auth-error`?(0,$.jsx)(sp,{errorType:`relay-auth`,onRetry:()=>{let e=n();e&&(o(),s(e)),re(),ae()},children:u&&(0,$.jsx)(Ff,{})}):d===`locked`?(0,$.jsx)(ap,{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:r(T?`sessionAuth.locked.tunnelTitle`:`sessionAuth.locked.unlockTitle`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:r(T?`sessionAuth.locked.tunnelDescription`:`sessionAuth.locked.passwordDescription`)})]}),!T&&(0,$.jsxs)(`form`,{onSubmit:oe,className:`w-full space-y-2`,children:[pe&&(0,$.jsxs)($r,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>void ue(),disabled:v||M&&I!==`auth`,children:[M?(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:r(M&&I===`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)($o,{id:`yuri-ui-password`,ref:B,type:`password`,autoComplete:`current-password`,placeholder:r(`sessionAuth.password.placeholder`),value:g,onChange:e=>{_(e.target.value),x&&S(``)},className:`pl-10`,"aria-invalid":!!x||void 0,"aria-describedby":x?`yuri-ui-auth-error`:void 0,disabled:v})]}),(0,$.jsx)($r,{type:`submit`,size:`icon`,disabled:!g||v,"aria-label":r(v?`sessionAuth.actions.unlockingAria`:`sessionAuth.actions.unlockAria`),children:v?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`})})]}),fe?(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)(Qo,{checked:P,onChange:F,disabled:v,ariaLabel:r(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:r(`sessionAuth.actions.trustDevice`)})]}),(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void de(),disabled:v,children:r(M&&I===`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)(Qo,{checked:P,onChange:F,disabled:v,ariaLabel:r(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:r(`sessionAuth.actions.trustDevice`)})]}),x&&(0,$.jsx)(`p`,{id:`yuri-ui-auth-error`,className:`typography-meta text-destructive`,children:x})]}),u&&(0,$.jsxs)(`div`,{className:`w-full`,children:[(0,$.jsx)(Ff,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:r(`sessionAuth.locked.hostSwitcherHint`)})]})]})}):(0,$.jsx)($.Fragment,{children:e})},lp=e=>!!e&&typeof e==`object`&&!Array.isArray(e),up=e=>typeof e==`string`&&e.trim()?e.trim():null,dp=e=>{if(!lp(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=up(e.minimumVersion),i=up(e.targetVersion);if(!r||!i||typeof e.canInstall!=`boolean`)throw Error(`Could not check OpenCode compatibility`);return{state:t,version:up(e.version),installation:n,minimumVersion:r,targetVersion:i,canInstall:e.canInstall,guidance:up(e.guidance)}},fp=async()=>{let e=await g(`/api/opencode/compatibility`,{signal:AbortSignal.timeout(2e4)});if(!e.ok)throw Error(`Could not check OpenCode compatibility`);return dp(await e.json())},pp=async()=>{let e=await g(`/api/opencode/install-required`,{method:`POST`}),t=await e.json().catch(()=>null),n=lp(t)?t:null,r=up(n?.error);if(!e.ok||n?.success!==!0||n?.upgraded!==!0)throw Error(r||`OpenCode installation failed`);let i=up(n.version);if(!i)throw Error(r||`OpenCode installation did not report a verified version`);return{version:i}},mp=(e,t)=>e instanceof Error&&e.message.trim()?e.message.trim():t,hp=({children:e})=>{let{t}=fr(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),[o,s]=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 fp();if(!e||t!==p.current)return;r(n),n.state!==`incompatible`&&u(null)}catch{}finally{e&&t===p.current&&a(!0)}};t();let n=c(()=>{e&&(r(null),a(!1),s(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(o)return;let n=++p.current;s(e),u(null);try{if(e===`install`){let e=await pp();if(n!==p.current)return;if(!e.version)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload();return}let i=await fp();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(mp(e,t(`opencodeUpgrade.screen.failedGeneric`)))}finally{n===p.current&&s(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)(Bs,{width:120,height:120,isAnimated:!0})});if(!i)return g;if(!m||!n)return(0,$.jsx)(Vs,{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=o!==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)(Bs,{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)($r,{type:`button`,disabled:b,onClick:()=>void h(`install`),children:[(0,$.jsx)(X,{name:o===`install`?`refresh`:`download`,className:o===`install`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:o===`install`?`status`:void 0,children:o===`install`?t(_?`opencodeUpgrade.screen.updating`:`opencodeUpgrade.screen.installing`):t(_?`opencodeUpgrade.screen.update`:`opencodeUpgrade.screen.install`,{minimum:y})})]}):null,(0,$.jsxs)($r,{type:`button`,variant:n.canInstall?`ghost`:`default`,disabled:b,onClick:()=>void h(`reconnect`),children:[(0,$.jsx)(X,{name:`refresh`,className:o===`reconnect`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:o===`reconnect`?`status`:void 0,children:t(o===`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,{})})]})})},gp=e=>{let t=(0,Q.c)(14),{children:n}=e,r=q(_p),i=q(vp),a=q(yp),o=q(bp),s=q(xp),{deviceType:c,hasTouchInput:l}=Us(),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=typeof document<`u`&&_n(),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 _p(e){return e.fontSize}function vp(e){return e.codeFontSize}function yp(e){return e.applyTypography}function bp(e){return e.padding}function xp(e){return e.applyPadding}var Sp=e(se(),1),Cp={light:`#212121`,dark:`#DEDEDE`},wp=e=>{let t=/^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.exec(e);if(!t)return null;let n=t[1].length<5?[...t[1]].map(e=>e+e).join(``):t[1];return[0,2,4].map(e=>Number.parseInt(n.slice(e,e+2),16)).concat(n.length===8?Number.parseInt(n.slice(6),16)/255:1)},Tp=e=>{let t=e.slice(0,3).map(e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4});return t[0]*.2126+t[1]*.7152+t[2]*.0722},Ep=e=>{let t=Cp[e.metadata.variant],n=Tp(wp(t)),r=e.colors,i=!1,a=(e,r)=>{let a=wp(e);if(!a)return e;let o=wp(r);return Tp(a[3]===1||!o?a:a.slice(0,3).map((e,t)=>e*a[3]+o[t]*(1-a[3])))+1e-9>=n?e:(i=!0,t)},o={...r.surface,foreground:a(r.surface.foreground,r.surface.background),elevatedForeground:a(r.surface.elevatedForeground,r.surface.elevated)},s=r.chat?{...r.chat}:void 0;s?.userMessage&&(s.userMessage=a(s.userMessage,s.userMessageBackground||r.surface.elevated)),s?.assistantMessage&&(s.assistantMessage=a(s.assistantMessage,s.assistantMessageBackground||r.surface.muted));let c=r.tools?{...r.tools}:void 0;c?.title&&(c.title=a(c.title,r.surface.muted));let l=r.markdown?{...r.markdown}:void 0;if(l)for(let e of[`bold`,`italic`,`heading1`,`heading2`,`heading3`,`heading4`]){let t=l[e];if(!t)continue;let n=wp(t),i=n&&n[0]===n[1]&&n[1]===n[2],o=[r.surface.foreground,r.surface.elevatedForeground].some(e=>e.toLowerCase()===t.toLowerCase());(!e.startsWith(`heading`)||i||o)&&(l[e]=a(t,s?.background||r.surface.background))}return i?{...e,colors:{...r,surface:o,...s&&{chat:s},...c&&{tools:c},...l&&{markdown:l}}}:e},Dp=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}`},Op=class{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){e=Ep(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)),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-C5b57FEy.js","assets/rolldown-runtime-hePW80VL.js","assets/runtime-auth-mjIpsk3N.js","assets/runtime-switch-BMjl5Y5W.js","assets/runtime-fetch-DKZOpfzo.js","assets/reasoning-projection-client-BEhVknv9.js","assets/platform-DMsFWy1a.js","assets/runtimeAPIRegistry-C2VogTny.js","assets/vendor-base-ui-CzHs0bHY.js","assets/useUIStore-BF882_0b.js","assets/vendor-zustand-vDaAPGfl.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/useMobileHtmlPreviewStore-C03uVLfX.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/vendor-react-DlzBev0S.js","assets/vendor-tanstack-react-query-B-Wpqq5J.js","assets/vendor-tanstack-query-core-Y_YoRHtC.js","assets/runtime-file-resource-CL7EVzOG.js","assets/fileQueries-D9l0crnM.js","assets/runtime-file-store-BVRgEtI-.js","assets/path-utils-jGozTg9d.js","assets/runtime-file-download-DMY1k1af.js","assets/vendor-pierre-diffs-BFiZ3IhI.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-CuTmqEMK.js","assets/vendor-lodash-es-BS45jPoZ.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/i18n-BU14awhU.js","assets/bootstrap-BhC95qVC.js","assets/runtime-ead7P81A.js","assets/store-BNNIbb4k.js","assets/tour-DDI0Zg7l.js","assets/useMobileNavigationStore-Dr61mYqA.js","assets/gitApiHttp-B1mApXwC.js","assets/vendor-opencode-client-cQ47ywrT.js","assets/vendor-effect-X1Hqc7ba.js","assets/vendor-pathe-vBmvQE8f.js","assets/pathNormalization-ewtPqJWn.js","assets/vendor-sonner-BEHGipm5.js","assets/useAssistantUIStore-Du8puXWz.js","assets/vendor-zod-DZzbCm1s.js","assets/vendor-opencode-schema-DWT45VBX.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/useThemeSystem-CNzUUkFn.js","assets/vendor-framer-motion-DDMKlXiP.js","assets/Icon-Co7WGN1G.js","assets/dialog-C7D331XW.js","assets/dialog-CTYD3Sbr.css","assets/tap-LkQum5bB.js","assets/themes-BgDJcxRc.js","assets/MarkdownRenderer-CZpY_qyH.js","assets/useEffectiveDirectory--tyiZ84r.js","assets/markdownHeightCache-BWCMEzOk.js","assets/dualLimitLru-D8Sphgua.js","assets/MobileWindowStack-DGLdgoGr.js","assets/appThemeRegistry-DDaIHQum.js","assets/agentColors-DWSbQXy2.js","assets/rasterizePng-056Poix7.js","assets/toolHelpers-iEHVHQ9p.js","assets/image-loading-DEXNCcCm.js","assets/image-loading-D9Z_BASK.css","assets/ImageLoadingPlaceholder-KEVw1Pg-.js","assets/vendor-tanstack-react-virtual-DSFNK3qc.js","assets/useWorkerHighlightedLines-CO7SlSqM.js","assets/markdownTheme-CHNl6tUv.js","assets/markdown-worker-oBGEB9Eg.js","assets/mobileBackNavigation-C456iV52.js","assets/touch-gestures-CErgaXZ7.js","assets/vendor-capacitor-app-B5H_XtmE.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,S as n,l as r,s as i,w as a,x as o,y as s}from"./runtime-auth-mjIpsk3N.js";import{c,f as l,i as u,l as d,n as f,o as p,r as m,t as h}from"./runtime-switch-BMjl5Y5W.js";import{n as g}from"./runtime-fetch-DKZOpfzo.js";import{A as _,D as v,E as y,R as b,S as x,T as S,a as C,et as w,i as T,k as E,n as D,t as O,y as k}from"./platform-DMsFWy1a.js";import{t as A}from"./runtimeAPIRegistry-C2VogTny.js";import{_ as j,b as M,c as N,d as P,f as F,g as I,h as L,i as R,l as z,m as B,n as V,o as H,r as U,s as W,v as ee}from"./desktopHosts-DovfbQPm.js";import{r as te}from"./desktopRelayRestore-D4pbpNKN.js";import{a as G,i as ne,o as re,r as ie,s as ae,t as oe}from"./vendor-zustand-vDaAPGfl.js";import{at as se,f as ce,g as le,h as ue,m as de,ot as fe,p as pe,st as me}from"./vendor-base-ui-CzHs0bHY.js";import{$n as he,Ai as ge,Ar as _e,At as ve,Ba as ye,Cn as be,Cr as xe,Dn as Se,Dr as Ce,Dt as we,Ei as Te,Er as Ee,Et as De,Fa as Oe,Fi as ke,Fr as Ae,Ga as je,Gn as Me,Gr as Ne,Gt as Pe,Hr as Fe,Ia as Ie,Ii as Le,Ir as Re,Jn as ze,Jt as Be,Ka as Ve,Kn as He,Kr as Ue,Kt as We,Mn as Ge,Mr as Ke,Mt as qe,Na as Je,Nn as Ye,Nr as Xe,Nt as Ze,Oi as Qe,Ot as $e,Pi as et,Pr as tt,Qa as nt,Qn as rt,Qr as it,Qt as at,Rr as ot,Sn as st,Ta as ct,Tn as lt,Tr as ut,Tt as dt,Un as ft,Ut as pt,Vi as mt,Vr as ht,Vt as gt,Xn as _t,Xr as vt,Xt as yt,Yt as bt,Za as xt,Zn as St,Zr as Ct,Zt as wt,_o as Tt,_r as Et,an as Dt,bn as Ot,br as kt,bt as At,cr as jt,di as Mt,dr as Nt,ei as Pt,en as Ft,fn as It,gn as Lt,gr as Rt,hn as zt,io as Bt,ir as Vt,ja as Ht,ji as Ut,ka as Wt,ki as Gt,kn as Kt,kr as qt,lo as Jt,lr as Yt,no as Xt,nr as Zt,on as Qt,pn as $t,pr as en,qt as tn,ro as nn,rr as rn,sn as an,so as on,tr as sn,un as cn,ur as ln,wn as un,wr as dn,xn as K,xr as fn,yn as pn,yr as mn,zi as hn,zr as gn}from"./gitApiHttp-B1mApXwC.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{C as _n,a as vn,b as yn,f as bn,g as xn,o as Sn,r as q,w as Cn,x as wn,y as Tn}from"./useUIStore-BF882_0b.js";import{n as En}from"./vendor-react-DlzBev0S.js";import{i as Dn}from"./vendor-tanstack-query-core-Y_YoRHtC.js";import{c as On,i as kn,n as An,o as jn,t as Mn}from"./vendor-tanstack-react-query-B-Wpqq5J.js";import{_ as Nn,d as Pn,g as Fn,l as In,p as Ln,u as Rn}from"./fileQueries-D9l0crnM.js";import{a as zn,i as Bn,n as Vn,o as Hn,t as Un}from"./path-utils-jGozTg9d.js";import{o as Wn}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as Gn,o as Kn,r as qn}from"./useMobileHtmlPreviewStore-C03uVLfX.js";import{r as Jn}from"./bootstrap-BhC95qVC.js";import{n as Yn,t as Xn}from"./pathNormalization-ewtPqJWn.js";import{i as Zn,u as Qn}from"./vendor-pierre-diffs-BFiZ3IhI.js";import{r as $n,t as er}from"./vendor-sonner-BEHGipm5.js";import{a as tr,d as nr,h as rr,i as ir,m as ar,o as or,p as sr,r as J,s as cr}from"./vendor-reactuses-core-CuTmqEMK.js";import{n as lr,o as ur,s as dr,t as fr}from"./i18n-BU14awhU.js";import{i as pr,t as mr}from"./store-BNNIbb4k.js";import{$ as hr,$t as gr,Ai as _r,Ar as vr,B as yr,Ba as br,Bn as xr,Br as Sr,Bt as Cr,Ci as wr,Cn as Tr,D as Er,Di as Dr,Dn as Or,Dr as kr,Dt as Ar,E as jr,Ea as Mr,Ei as Nr,En as Pr,Et as Fr,Fn as Ir,G as Lr,Gi as Rr,Gn as zr,Gr as Br,H as Vr,Hn as Hr,Hr as Ur,I as Wr,Ii as Gr,In as Kr,It as qr,J as Jr,Ji as Yr,Jn as Y,Jt as Xr,K as Zr,Ki as Qr,Kn as $r,Li as ei,Ln as ti,M as ni,N as ri,Na as ii,Ni as ai,Nn as oi,O as si,Oi as ci,Or as li,Ot as ui,P as di,Pa as fi,Pi as pi,Pn as mi,Pt as hi,Qi as gi,Ra as _i,Rn as vi,Rt as yi,S as bi,Sn as xi,T as Si,Ta as Ci,Ti as wi,Tn as Ti,Tt as Ei,U as Di,Ui as Oi,Un as ki,Ur as Ai,Ut as ji,V as Mi,Vn as Ni,Vr as Pi,W as Fi,Wi as Ii,Wn as Li,Wr as Ri,Wt as zi,X as Bi,Xi as Vi,Y as Hi,Yi as Ui,Yn as Wi,Yt as Gi,Zi as Ki,Zt as qi,_ as Ji,_n as Yi,_t as Xi,a as Zi,aa as Qi,ai as $i,ar as ea,at as ta,bi as na,br as ra,bt as ia,c as aa,ca as oa,cr as sa,ct as ca,dn as la,dt as ua,en as da,er as fa,fi as pa,fn as ma,ft as ha,gn as ga,gr as _a,gt as va,h as ya,hn as ba,hr as xa,ht as Sa,i as Ca,in as wa,it as Ta,ji as Ea,k as Da,ki as Oa,kn as ka,kr as Aa,kt as ja,l as Ma,lt as Na,mn as Pa,mt as Fa,n as Ia,na as La,nn as Ra,nr as za,oi as Ba,on as Va,or as Ha,ot as Ua,p as Wa,pn as Ga,pt as Ka,qi as qa,qt as Ja,r as Ya,rr as Xa,rt as Za,sn as Qa,sr as $a,st as eo,tn as to,ui as no,un as ro,vi as io,vn as ao,vt as oo,w as so,wi as co,wn as lo,wt as uo,xa as fo,xi as po,xn as mo,xr as ho,xt as go,yi as _o,yn as vo,yt as yo,zi as bo,zn as xo,zt as So}from"./useMobileNavigationStore-Dr61mYqA.js";import"./vendor-opencode-schema-DWT45VBX.js";import{d as Co,f as wo,g as To,l as Eo,n as Do,t as Oo,u as ko}from"./fileMentionAutocompleteState-BZJqfgae.js";import{t as Ao}from"./agentColors-DWSbQXy2.js";import{t as jo}from"./dualLimitLru-D8Sphgua.js";import{a as Mo,i as No,r as Po,t as Fo}from"./AgentAvatar-B2GEBJBG.js";import{n as Io,r as Lo,t as Ro}from"./useThemeSystem-CNzUUkFn.js";import{o as zo}from"./vendor-framer-motion-DDMKlXiP.js";import{n as X}from"./Icon-Co7WGN1G.js";import{a as Bo,i as Vo,n as Ho,o as Uo,r as Wo,s as Go,t as Ko}from"./dialog-C7D331XW.js";import{E as qo,V as Jo,k as Yo,n as Xo}from"./gitApi-BOyQ2o3N.js";import{a as Zo}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{t as Qo}from"./checkbox-o8x1LJC4.js";import{t as $o}from"./input-os0CMgxY.js";import{i as es,n as ts,t as ns}from"./tooltip-pELJ38kd.js";import{$ as rs,At as is,B as as,Bt as os,Ct as ss,Dt as cs,G as ls,H as us,I as ds,K as fs,Ot as ps,P as ms,Pt as hs,St as gs,U as _s,V as vs,Vt as ys,W as bs,Z as xs,_t as Ss,bt as Cs,c as ws,dt as Ts,et as Es,ft as Ds,gt as Os,it as ks,lt as As,pt as js,r as Ms,rt as Ns,t as Ps,tt as Fs,ut as Is,wt as Ls,xt as Rs,zt as zs}from"./pwa-BzFEQ5Js.js";import{t as Bs}from"./YuriLogo-DcoYyXzq.js";import{o as Vs,t as Hs}from"./react-BJAlol6I.js";import{r as Us}from"./device-DNG0cNwQ.js";import{a as Ws,i as Gs,n as Ks,r as qs,t as Js}from"./themes-BgDJcxRc.js";import{_ as Ys,d as Xs,g as Zs,m as Qs}from"./scheduledTaskNavigation-PH-etFzZ.js";import{t as $s}from"./theme-validation-BGYdrOu7.js";import{a as ec,i as tc,n as nc,r as rc,t as ic}from"./MarkdownRenderer-CZpY_qyH.js";import{S as ac,b as oc,t as sc,x as cc}from"./MobileResizableSheet-Dd1w8a-6.js";import{A as lc,C as uc,D as dc,E as fc,M as pc,N as mc,O as hc,S as gc,_ as _c,b as vc,c as yc,d as bc,f as xc,g as Sc,h as Cc,j as wc,k as Tc,l as Ec,m as Dc,p as Oc,s as kc,u as Ac,v as jc,w as Mc,x as Nc,y as Pc}from"./sessionLookup-DC2xZn-T.js";import{a as Fc,i as Ic,o as Lc,s as Rc,u as zc}from"./fileMentionTouchSelection-C3_guqVF.js";import{C as Bc,E as Vc,O as Hc,S as Uc,T as Wc,a as Gc,b as Kc,c as qc,d as Jc,f as Yc,i as Xc,l as Zc,n as Qc,o as $c,p as el,r as tl,s as nl,t as rl,u as il,w as al,x as ol,y as sl}from"./insertionBoundaries-CGcJ-kUX.js";import{c as cl,d as ll,f as ul,i as dl,n as fl,o as pl,s as ml,t as hl}from"./select-ClX56nrO.js";import{C as gl,D as _l,E as vl,M as yl,O as bl,S as xl,T as Sl,_ as Cl,a as wl,b as Tl,c as El,d as Dl,f as Ol,g as kl,h as Al,k as jl,l as Ml,m as Nl,p as Pl,r as Fl,s as Il,t as Ll,u as Rl,v as zl,w as Bl,x as Vl,y as Hl}from"./appThemeRegistry-DDaIHQum.js";import{a as Ul,i as Wl,n as Gl,t as Kl}from"./useDictation-CyWtsxSn.js";import{A as ql,C as Jl,D as Yl,E as Xl,F as Zl,I as Ql,L as $l,M as eu,N as tu,O as nu,P as ru,S as iu,T as au,_ as ou,a as su,b as cu,c as lu,d as uu,f as du,g as fu,h as pu,j as mu,k as hu,l as gu,m as _u,n as vu,o as yu,p as bu,r as xu,s as Su,t as Cu,u as wu,v as Tu,w as Eu,x as Du,y as Ou}from"./queue-abort-optimistic-CMMw3KSM.js";import{a as ku,o as Au,t as ju,u as Mu}from"./toolHelpers-iEHVHQ9p.js";import{n as Nu,t as Pu}from"./useEffectiveDirectory--tyiZ84r.js";import{c as Fu,n as Iu,o as Lu,r as Ru}from"./image-loading-DEXNCcCm.js";import{t as zu}from"./ImageLoadingPlaceholder-KEVw1Pg-.js";import{t as Bu}from"./LoadingImage-PH45V6oj.js";import{_ as Vu,a as Hu,c as Uu,g as Wu,l as Gu,o as Ku,t as qu,v as Ju,y as Yu}from"./vendor-dnd-kit-core-DK4OoOTr.js";import{i as Xu,n as Zu,o as Qu,s as $u,t as ed}from"./vendor-dnd-kit-sortable-Cv69eQm1.js";import{a as td,i as nd,l as rd,n as id,o as ad,s as od,t as sd}from"./FadeInOnReveal-BWkJi5dK.js";import{t as cd}from"./OverlayScrollbar-BQua3Ko6.js";import{n as ld,r as ud}from"./textarea-DpsaIedI.js";import{n as dd,r as fd,t as pd}from"./vendor-tanstack-react-virtual-DSFNK3qc.js";import{C as md,S as hd,_ as gd,a as _d,b as vd,f as yd,g as bd,h as xd,i as Sd,l as Cd,m as wd,n as Td,o as Ed,s as Dd,u as Od,v as kd,x as Ad}from"./projectMeta-CyhJE6CA.js";import{_ as jd,a as Md,f as Nd,g as Pd,h as Fd,i as Id,m as Ld,o as Rd,r as zd,s as Bd,t as Vd,v as Hd,y as Ud}from"./useWorkerHighlightedLines-CO7SlSqM.js";import{t as Wd}from"./vendor-cmdk-C_tivUtr.js";import{t as Gd}from"./sortable-tabs-strip-BQbGMaz-.js";import{a as Kd}from"./markdownHeightCache-BWCMEzOk.js";import{a as qd,i as Jd,n as Yd,o as Xd}from"./speechSettingsQueries-85xpCH5y.js";import{n as Zd}from"./vendor-marked-S3gCOYp1.js";import{n as Qd}from"./markdownTheme-CHNl6tUv.js";import{t as $d}from"./vendor-motion-C9oiAdx-.js";import{t as ef}from"./useStreamingTextThrottle-D3YtOLbE.js";import{n as tf,t as nf}from"./useFontPreferences-CAdw6cBK.js";var rf=e=>{if(typeof e!=`string`)return;let t=e.trim();if(t)return{location:{directory:t}}};typeof window<`u`&&(window.__opencodeDebug={getLastAssistantMessage(){let e=Wa.getState().currentSessionId;if(!e)return null;let t=vt(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=(Ct(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:(Ct(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=Wa.getState().currentSessionId;if(!t)return[];let n=vt(t);return`${n.length}`,n.forEach((e,t)=>{let n=Ct(e.id)||[];`${t}${e.role}${e.id}${n.length}`}),e?this.truncateMessages(n):n},async getAppStatus(){let e=At.getState(),t=Wa.getState(),n=Mr.getState(),r=e.currentDirectory||null,i=Kt.getDirectory()??null,a=it(),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=A(),u=typeof window<`u`&&!!window.__YURI_ELECTRON__,d=async e=>{try{return await e.json()}catch{return null}},f=async e=>{try{return await e.text()}catch{return null}},p=async e=>{try{let t=await g(e);return t.ok?await d(t):{status:t.status}}catch(e){return{error:e instanceof Error?e.message:String(e)}}},m=null,h=null,_=null,v=null;try{let e=await Kt.getSdkClient().location.get(rf(r));m=Ye(e)}catch(e){m={error:e instanceof Error?e.message:String(e)}}try{h=(await Kt.getSdkClient().location.get(rf(r)))?.project??null}catch(e){h={error:e instanceof Error?e.message:String(e)}}_=await p(`/api/config/settings`);try{let e=await g(`/api/health`),t=e.headers.get(`content-type`)||``,n=await f(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 Xo(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:m?.directory||m?.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:m,projectInfo:h,health:v},yuri:{settingsInfo:_}}},async buildDiagnosticsReport(){let e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return Ea(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=Wa.getState(),t=ka.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=Wa.getState().currentSessionId;if(!e)return[];let t=vt(e).filter(e=>e.role===`assistant`).filter(e=>{let t=Ct(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=Ct(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=Wa.getState().currentSessionId;if(!i)return{summary:null,rows:[]};let a=vt(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=Ct(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=Wa.getState().currentSessionId;if(!e)return null;let t=vt(e).filter(e=>e.role===`assistant`);if(t.length===0)return null;let n=t[t.length-1],r=(Ct(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=ka.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}}},dt(),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(me(),1),Q=En(),af=async()=>{if(typeof window>`u`)return;let e=null;try{e=Tt(`lastDirectory`)}catch(e){console.warn(`Failed to read saved directory preferences:`,e)}e&&!E()&&At.getState().setDirectory(e,{showOverlay:!1})},of=new Map,sf=e=>of.get(e)??null,cf=({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:i},a={})=>{let o=of.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 of.set(e,s),s},lf=async({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,startWatchers:i,onError:a})=>{await cf({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:a})&&i()},uf=(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 df(e){return!e||e===`idle`?null:e===`ready`?`ok`:e===`error`?`unreachable`:`auth`}function ff(e,t){let n=e.via===`relay`;return t?n:!n}function pf(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?df(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||ff(o,a))&&(u=Math.max(0,Math.round(o.latencyMs))),{statusKind:c,showViaRelay:l,latencyMs:u}}function mf({isLocal:e,isSsh:t,isRelay:n}){return e?`connection-local`:n?`connection-relay`:t?`connection-ssh`:`connection-lan`}var $=fe(),hf=`local`,gf=9e4,_f=`SSH connection cancelled`,vf=e=>te(e),yf={},bf=e=>{let t=I(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()=>!v()||!T()?``:H().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 hs().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 hs(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=h(),i=I(n)||n,a=I(t)||t,o=m(),s=e.find(e=>vf(e)===o);if(s)return{id:s.id,label:s.label,url:s.url};if(r&&L(r,n))return{id:hf,label:`Local`,url:i};let c=e.find(e=>r?L(r,P(e)):!1);if(c)return{id:c.id,label:c.label,url:I(P(c))||P(c)};if(t&&L(t,n))return{id:hf,label:`Local`,url:i};let l=e.find(e=>t?L(t,e.url):!1);return l?{id:l.id,label:l.label,url:I(l.url)||l.url}:t.startsWith(`yuri-ui://`)?{id:hf,label:`Local`,url:i}:{id:`custom`,label:ee(a||`Instance`),url:a}};function Pf({open:e,onOpenChange:t,embedded:n=!1,onHostSwitched:r,onBusyChange:i}){let{t:a}=fr(),o=q(e=>e.setSettingsDialogOpen),s=q(e=>e.setSettingsPage),l=ei(e=>e.isConnected),d=ei(e=>e.connectionPhase),[f,p]=Z.useState([]),[m,h]=Z.useState(null),[g,_]=Z.useState(()=>({...yf}));Z.useEffect(()=>{Object.assign(yf,g)},[g]);let[b,x]=Z.useState(!1),[S,C]=Z.useState(!1),[w,E]=Z.useState(!1),D=os(),O=ys(),[k,A]=Z.useState(null),F=k||O,L=Z.useRef(!1),H=J(e=>{L.current=e!==null,A(e),i?.(e!==null)}),[te,G]=Z.useState({}),[ne,re]=Z.useState({}),[ie,ae]=Z.useState({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),[oe,se]=Z.useState(``),[ce,le]=Z.useState(()=>xf()),[ue,de]=Z.useState(null),[fe,pe]=Z.useState(``),[me,he]=Z.useState(``),[ge,_e]=Z.useState(0),ve=Z.useRef(0),ye=Z.useMemo(()=>[Mf(ce),...f.map(e=>({...e,url:I(e.url)||e.url}))],[f,ce]),be=Z.useMemo(()=>new Set(Object.keys(te)),[te]),xe=Z.useMemo(()=>{let e=Nf(ye).id;return ye.filter(t=>t.id===hf||B(t,be)||t.id===e)},[ye,be,ge]);Z.useEffect(()=>c(()=>_e(e=>e+1)),[]);let Se=Z.useMemo(()=>Nf(ye),[ye,ge]),Ce=Z.useMemo(()=>u().startsWith(`relay:`),[ge]),we=Z.useMemo(()=>{let e=m||hf;return ye.find(t=>t.id===e)?.label||a(`desktopHostSwitcher.instance.local`)},[ye,m,a]),Te=J(async(e,t)=>{if(y()){E(!0),se(``);try{if(v()&&!T()){await W();return}let n=e.filter(e=>e.id!==hf);await R({hosts:n,defaultHostId:t}),p(n),h(t)}catch(e){se(e instanceof Error?e.message:a(`desktopHostSwitcher.error.failedToSave`))}finally{E(!1)}}}),Ee=J(()=>{if(v()&&!T()){W().catch(e=>no.error(String(e))),t(!1);return}s(`remote-instances`),o(!0),t(!1)}),De=Z.useCallback(async()=>{if(y()){x(!0),se(``);try{let[e,t,n]=await Promise.all([U(),T()?is().catch(()=>({instances:[]})):Promise.resolve({instances:[]}),T()?Af():Promise.resolve({})]);e.localOrigin&&le(e.localOrigin);let r={};for(let t of e.sshHostIds??[])r[t]=!0;for(let e of t.instances)r[e.id]=!0;p(e.hosts||[]),h(e.defaultHostId??null),G(r),re(n)}catch(e){se(e instanceof Error?e.message:a(`desktopHostSwitcher.error.failedToLoad`)),p([]),h(null),G({}),re({})}finally{x(!1)}}},[a]),Oe=Z.useCallback(async e=>{if(y()){C(!0);try{let t=await Sf(),n=await Promise.all(e.map(async e=>{let n=async()=>{let t=await j(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=I(v()?P(e):e.url);if(!r)return[e.id,{status:`unreachable`,latencyMs:0}];let i=e.id===hf?t:e.clientToken||``,a=await V(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;_(r)}finally{C(!1)}}},[]);Z.useEffect(()=>{if(!e){de(null),pe(``),he(``),A(null),ae({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),se(``);return}De()},[e,De]),Z.useEffect(()=>{e&&Oe(xe)},[e,xe,Oe]),Z.useEffect(()=>{if(!e||!y()||!T())return;let t=!1,n=async()=>{let e=await Af();t||re(e)};n();let r=window.setInterval(()=>{typeof document<`u`&&document.visibilityState!==`visible`||n()},1500);return()=>{t=!0,window.clearInterval(r)}},[e]);let ke=J(async e=>{if(L.current||D)return;let t=e.id===hf?ce:I(e.url)||``,n=e.id===hf?ce:I(P(e))||``,i=!!e.relay&&!e.apiUrl&&e.id!==hf;if(!t&&!i)return;if(v()){if(!n&&!e.relay||D)return;H(e.id);try{let t=e.id===hf?await Sf():null,i=await zs({host:e,inlineProgress:!0,cachedProbe:g[e.id]||null,...e.id===hf?{localApiOrigin:n,localClientToken:t}:{}});_(t=>({...t,[e.id]:i.status})),i.ok&&r?.()}finally{H(null)}return}let o=!!te[e.id];if(e.id!==hf&&o&&y()){let n=ne[e.id],i=await hs(e.id).then(t=>t.find(t=>t.id===e.id)||null).catch(()=>null);i&&(n=i,re(t=>({...t,[e.id]:i})));let o=I(n?.localUrl||e.url||``);if(n?.phase===`ready`&&o){let e=bf(o);r?.(),window.location.assign(e);return}A(e.id);let s=ve.current+1;ve.current=s,ae({open:!0,hostId:e.id,hostLabel:ee(e.label),phase:`master_connecting`,detail:null,error:null,errorCode:null});try{if(await cs(e.id),s!==ve.current)return;let n=await jf(e.id,gf,e=>{re(t=>({...t,[e.id]:e})),ae(t=>({...t,phase:e.phase,detail:e.detail||null,errorCode:e.errorCode||null}))},()=>s!==ve.current);if(s!==ve.current)return;let i=bf(I(n.localUrl||``)||t);r?.(),window.location.assign(i);return}catch(t){if(s!==ve.current)return;let n=t instanceof Error?t.message:String(t);if(n===_f)return;let r=gs(ie.errorCode,n);ae(e=>({...e,error:n,errorCode:r})),no.error(a(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:ee(e.label)}),{description:Rs(a(ss(r)),r,n)});return}finally{s===ve.current&&A(null)}}if(e.id!==hf&&y()){A(e.id);let n=await V(t,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(_(t=>({...t,[e.id]:{status:n.status,latencyMs:n.latencyMs}})),Tf(n.status)){no.error(a(`desktopHostSwitcher.toast.instanceUnreachable`,{host:ee(e.label)})),A(null);return}}let s=bf(t);r?.();try{window.location.assign(s)}catch{window.location.href=s}}),Ae=Z.useCallback(()=>{de(null),pe(``),he(``)},[]),je=Z.useCallback(e=>{e.stopPropagation()},[]),Me=Z.useCallback(async()=>{if(!ue)return;if(ue===hf){Ae();return}let e=M(me);if(!e){se(a(`desktopHostSwitcher.error.invalidUrl`));return}let t=e.persistedUrl,n=(fe||ee(t)).trim(),r=f.map(e=>e.id===ue?{...e,label:n,url:t,apiUrl:t}:e);await Te(r,m),Ae(),e.redeemUrl&&window.location.assign(e.redeemUrl)},[Ae,f,m,fe,me,ue,Te,a]),Ne=Z.useCallback(async e=>{await Te(f,e===hf?hf:e)},[f,Te]),Pe=J(async e=>{if(L.current||D)return;H(e.id);let t=e=>{no.error(a(`desktopHostSwitcher.error.failedToOpenNewWindow`),{description:e instanceof Error?e.message:String(e)})};try{if(e.relay&&e.id!==hf)await z(e.id);else{let t=e.id===hf?ce: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{H(null)}}),Fe=J(async()=>{ve.current+=1,A(null),ae(e=>({...e,open:!1,hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}));let e=bf(ce);if(v()){if(D)return;let e=await Sf();(await zs({host:Mf(ce),localApiOrigin:ce,localClientToken:e})).ok&&r?.();return}r?.(),window.location.assign(e)}),Ie=Z.useCallback(async()=>{let e=ie.hostId||F;ve.current+=1,A(null),ae({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),!(!e||e===hf||!y())&&await ps(e).catch(()=>{})},[ie.hostId,F]),Le=Z.useCallback(()=>{let e=ie.hostId;if(!e)return;let t=ye.find(t=>t.id===e);t&&ke(t)},[ye,ke,ie.hostId]),Re=J(async e=>{if(!(!y()||L.current||D)){H(e.id);try{await cs(e.id),(await jf(e.id,gf,e=>{re(t=>({...t,[e.id]:e}))})).phase===`ready`&&no.success(a(`desktopHostSwitcher.toast.sshConnected`,{host:ee(e.label)}))}catch(t){let n=t instanceof Error?t.message:String(t);if(n!==_f){let t=gs(null,n);no.error(a(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:ee(e.label)}),{description:Rs(a(ss(t)),t,n)})}}finally{H(null)}}});if(!y())return null;let ze=y(),Be=(0,$.jsxs)($.Fragment,{children:[!n&&(0,$.jsxs)(Bo,{className:`flex-shrink-0`,children:[(0,$.jsxs)(Uo,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`connection-local`,className:`h-5 w-5`}),a(`desktopHostSwitcher.title`)]}),(0,$.jsx)(Wo,{children:a(`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:a(`desktopHostSwitcher.header.currentColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:ee(Se.label)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a(`desktopHostSwitcher.header.currentDefaultColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:ee(we)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsxs)($r,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Oe(xe),disabled:!ze||b||S,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)}),a(`desktopHostSwitcher.actions.refresh`)]})})]}),!ze&&(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:a(`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:b?(0,$.jsx)(`div`,{className:`px-2 py-2 text-muted-foreground text-sm`,children:a(`desktopHostSwitcher.state.loading`)}):xe.map(e=>{let t=e.id===hf,r=!!te[e.id],i=r&&T(),o=e.id===Se.id,s=(m||hf)===e.id,c=g[e.id]||null,u=ne[e.id]||null,f=pf({isActive:o,isSsh:i,runtimeIsConnected:l,runtimeConnectionPhase:d,currentTransportIsRelay:Ce,probe:c,sshPhase:u?.phase}),p=f.statusKind,h=f.showViaRelay,_=mf({isLocal:t,isSsh:r,isRelay:o?Ce:h||!!(e.relay&&!e.apiUrl)}),v=_===`connection-local`?a(`desktopHostSwitcher.instance.local`):_===`connection-relay`?`Relay`:_===`connection-ssh`?`SSH`:`LAN`,y=ue===e.id,b=t?ce:I(e.url)||e.url,x=e.id===hf?a(`desktopHostSwitcher.instance.local`):ee(e.label),S=e.relay&&!e.apiUrl?a(`mobile.connect.relay.badge`):ee(b);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 px-3 py-3`,n&&o&&`bg-[var(--interactive-selection)]/25`,y?`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`,y&&`pointer-events-none opacity-70`),onClick:()=>void ke(e),disabled:!!F,"aria-busy":F===e.id,"aria-current":o?`true`:void 0,"aria-label":a(`desktopHostSwitcher.actions.switchToAria`,{instance:x}),children:[(0,$.jsx)(X,{name:F===e.id?`loader-4`:_,className:Y(`size-8 shrink-0 text-muted-foreground`,F===e.id&&`animate-spin`)}),(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:x}),o&&!n&&(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:a(`desktopHostSwitcher.header.current`)}),r&&!n&&(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`})]}),n?(0,$.jsxs)(`div`,{className:`typography-micro flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:v}),f.latencyMs!=null&&(0,$.jsxs)(`span`,{children:[f.latencyMs,` ms`]}),p!==`ok`&&(0,$.jsx)(`span`,{className:Y(`truncate`,wf(p)),children:i&&(!o||F===e.id)?a(kf(u?.phase)):a(Df(p))})]}):(0,$.jsxs)(`div`,{className:Y(`typography-micro truncate`,wf(p)),children:[(0,$.jsx)(`span`,{className:Y(`mr-1 inline-block h-1.5 w-1.5 rounded-full`,Cf(p))}),i&&(!o||F===e.id)?a(kf(u?.phase)):a(Df(p)),f.latencyMs==null?``:a(`desktopHostSwitcher.status.ping`,{ms:f.latencyMs}),h?` · ${a(`settings.remoteInstances.clientAuth.state.viaRelay`)}`:``]}),!n&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70 truncate font-mono`,children:S})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&o&&(0,$.jsx)(X,{name:`check`,className:`size-4 text-foreground`,"aria-label":a(`desktopHostSwitcher.header.current`)}),i&&!t&&(u?.phase===`idle`||!u?.phase?(0,$.jsxs)($r,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 px-2.5`,disabled:!!F,onClick:t=>{t.stopPropagation(),Re(e)},children:[F===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`}),a(`desktopHostSwitcher.actions.connect`)]}):null),(0,$.jsxs)(ns,{delayDuration:600,children:[(0,$.jsx)(es,{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`,s?`bg-interactive-selection text-interactive-selection-foreground`:`text-muted-foreground/60 hover:text-foreground`),onClick:()=>void Ne(e.id),"aria-pressed":s,"aria-label":a(s?`desktopHostSwitcher.actions.defaultInstanceAria`:`desktopHostSwitcher.actions.setAsDefaultAria`),disabled:w||!s&&Ef(p),children:(0,$.jsx)(X,{name:s?`home-fill`:`home`,className:`h-4 w-4`})})}),(0,$.jsx)(ts,{sideOffset:6,children:a(s?`desktopHostSwitcher.header.default`:`desktopHostSwitcher.actions.setAsDefault`)})]}),(0,$.jsxs)(ns,{delayDuration:600,children:[(0,$.jsx)(es,{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(p)?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground/60 hover:text-foreground`),onClick:t=>{t.stopPropagation(),Pe(e)},disabled:!!F||Ef(p),"aria-busy":F===e.id,"aria-label":a(`desktopHostSwitcher.actions.openInNewWindowAria`),children:(0,$.jsx)(X,{name:F===e.id?`loader-4`:`window`,className:Y(`h-4 w-4`,F===e.id&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:Ef(p)?a(`desktopHostSwitcher.state.instanceUnreachable`):a(`desktopHostSwitcher.actions.openInNewWindow`)})]})]})]},e.id)})})}),ze&&ue&&ue!==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:a(`desktopHostSwitcher.edit.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)($r,{type:`button`,variant:`outline`,size:`sm`,onClick:Ae,disabled:w,children:a(`desktopHostSwitcher.actions.cancel`)}),(0,$.jsxs)($r,{type:`button`,size:`sm`,onClick:()=>void Me(),disabled:w,children:[w?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):null,a(`desktopHostSwitcher.actions.save`)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,$.jsx)($o,{value:fe,onChange:e=>pe(e.target.value),onKeyDown:je,placeholder:a(`desktopHostSwitcher.field.labelPlaceholder`),disabled:w}),(0,$.jsx)($o,{value:me,onChange:e=>he(e.target.value),onKeyDown:je,placeholder:a(`desktopHostSwitcher.field.urlPlaceholder`),disabled:w})]})]}),(0,$.jsx)(`div`,{className:Y(`flex-shrink-0 border-t border-[var(--interactive-border)]`,n&&`px-3 py-1`),children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`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`,n&&`rounded-xl px-3 py-3`),onClick:Ee,disabled:!!F,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:a(`desktopHostSwitcher.actions.addInstance`)})]})}),oe&&(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-status-error`,children:oe})]}),Ve=(0,$.jsx)(Ko,{open:ie.open,onOpenChange:e=>{if(!e&&F){Ie();return}ae(t=>({...t,open:e,...e?{}:{hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}}))},children:(0,$.jsxs)(Ho,{className:`w-[min(28rem,calc(100vw-2rem))] max-w-none`,children:[(0,$.jsxs)(Bo,{children:[(0,$.jsxs)(Uo,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(`h-4 w-4`,!ie.error&&`animate-spin`)}),a(`desktopHostSwitcher.ssh.connectingTo`,{host:ie.hostLabel||a(`desktopHostSwitcher.ssh.instanceFallback`)})]}),ie.error?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Wo,{className:`sr-only`,children:a(Ls(gs(ie.errorCode,ie.error)))}),(0,$.jsx)(Cs,{errorCode:ie.errorCode,detail:ie.error})]}):(0,$.jsx)(Wo,{children:ie.detail||a(kf(ie.phase))})]}),ie.error?(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,$.jsx)($r,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{Ee(),Ie()},children:a(`desktopHostSwitcher.sshError.openRemoteSettings`)}),(0,$.jsx)($r,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void Fe(),children:a(`desktopHostSwitcher.actions.switchToLocal`)}),(0,$.jsx)($r,{type:`button`,size:`sm`,onClick:Le,disabled:!ie.hostId,children:a(`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:Be}),Ve]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ko,{open:e,onOpenChange:e=>{!e&&L.current||t(e)},children:(0,$.jsx)(Ho,{className:`w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3`,children:Be})}),Ve]})}function Ff(){let e=(0,Q.c)(11),[t,n]=Z.useState(!1),{t:r}=fr();if(!y())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)($r,{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,{desktop:n=!1}={})=>{let r=!1,a=null,o,s=()=>{if(o?.(),!n)return;let i=t();if(!i)return;let a=()=>{!r&&t()===i&&i.getStatus().failureCode===`relay_authentication_rejected`&&e({kind:`relay-authentication`})};o=i.subscribeStatus(a),a()},l=()=>{if(a||r)return;let o=t();if(n&&o?.getStatus().failureCode===`relay_authentication_rejected`){e({kind:`relay-authentication`});return}let s=m(),c=f(),l=i(),u=new AbortController;a=u;let d=setTimeout(()=>u.abort(),1e4);g(`/auth/session`,{credentials:`include`,signal:u.signal}).then(a=>{r||u.signal.aborted||s!==m()||c!==f()||l!==i()||o!==t()||(a.status===401||n&&o&&a.status===403)&&e({kind:`session`,response:a,relay:!!o})}).catch(()=>{}).finally(()=>{clearTimeout(d),a===u&&(a=null)})},u=c(()=>{a?.abort(),a=null,s()});return window.addEventListener(`yuri:runtime-auth-rejected`,l),n&&window.addEventListener(`focus`,l),s(),()=>{r=!0,a?.abort(),o?.(),u(),window.removeEventListener(`yuri:runtime-auth-rejected`,l),window.removeEventListener(`focus`,l)}},Lf=e=>e.shouldUseDesktopShellPasswordLogin?`locked`:`error`,Rf=`/auth/session`,zf=4,Bf=1500,Vf=`yuri.uiAuth.trustDevice`,Hf=`desktop-local`,Uf=`desktop-local`,Wf=()=>{if(typeof window>`u`)return``;let e=window.__YURI_LOCAL_ORIGIN__;return typeof e==`string`?e.trim():``},Gf=(e,t)=>{let n=I(e),r=I(t);if(!n||!r)return!1;try{return new URL(n).origin===new URL(r).origin}catch{return!1}},Kf=()=>y(),qf=e=>{let t=e.replace(/^\[|\]$/g,``);return t===`localhost`||t===`127.0.0.1`||t===`::1`},Jf=()=>{if(!y())return!1;let e=Wf();if(!e)return!1;let t=h()||(typeof window<`u`?window.location.origin:``);if(Gf(e,t))return!0;try{let e=I(t);return!!(e&&qf(new URL(e).hostname))}catch{return!1}},Yf=()=>Jf()?{clientKind:Hf,dedupeKey:Uf}:{},Xf=async()=>await g(Rf,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}}),Zf=()=>typeof window>`u`?!1:window.localStorage.getItem(Vf)===`true`,Qf=async(e,t)=>{let n=Kf();return await g(Rf,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({password:e,trustDevice:t,issueClientToken:n,clientLabel:`Yuri Desktop`,...Yf()})})},$f=async()=>{if(!y())return``;let e=await g(`/api/client-auth/clients`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:`Yuri Desktop`,...Yf()})}).catch(()=>null);if(!e?.ok)return``;let t=await e.json().catch(()=>null);return typeof t?.token==`string`?t.token.trim():``},ep=()=>y()&&!Jf(),tp=async()=>{if(!y())return null;let e=m(),t=w(),n=e.startsWith(`host:`)?e.slice(5):t?.target===`remote`&&t.status===`ok`&&Gf(t.url,h())?t.hostId:null;if(!n)return null;let r=await U().catch(()=>null);if(m()!==e||!r)return;let i=r?.hosts.find(e=>e.id===n);if(i)return i&&F(i)?i:null},np=async(e,t)=>{if(!y()||typeof window>`u`)return null;let n=await x(`desktop_remote_password_login`,{url:h(),password:e,trustDevice:t,requestHeaders:r()}).catch(()=>null);if(!n||typeof n!=`object`)return null;let i=n.token,a=n.status;return{token:typeof i==`string`?i.trim():``,...typeof a==`number`?{status:a}:{}}},rp=async(e,t)=>{if(!y()||!t)return;let n=await U().catch(()=>null);if(!n)return;if(n.localOrigin&&Gf(n.localOrigin,e)){await R({hosts:n.hosts,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted,localClientToken:t}).catch(()=>void 0);return}let r=!1,i=n.hosts.map(n=>!Gf(P(n),e)||n.clientToken===t?n:(r=!0,{...n,clientToken:t}));r&&await R({hosts:i,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted}).catch(()=>void 0)},ip=async e=>{if(!e)return;let t=h(),i=r();await rp(t,e),d({apiBaseUrl:t,clientToken:e,requestHeaders:Object.keys(i).length>0?i:null,relay:n()})},ap=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},op=()=>{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)(Bs,{width:120,height:120})}),e[0]=t):t=e[0],t},sp=e=>{let t=(0,Q.c)(25),{onRetry:n,errorType:r,retryAfter:i,children:a}=e,o=r===void 0?`network`:r,{t:s}=fr(),c=o===`rate-limit`,l=i?Math.ceil(i/60):1,u;t[0]!==o||t[1]!==c||t[2]!==s?(u=s(c?`sessionAuth.error.rateLimitTitle`:o===`relay-auth`?`sessionAuth.error.relayAuthTitle`:`sessionAuth.error.networkTitle`),t[0]=o,t[1]=c,t[2]=s,t[3]=u):u=t[3];let d;t[4]===u?d=t[5]:(d=(0,$.jsx)(`h1`,{className:`typography-ui-header font-semibold text-destructive`,children:u}),t[4]=u,t[5]=d);let f;t[6]!==o||t[7]!==c||t[8]!==l||t[9]!==s?(f=c?s(l>1?`sessionAuth.error.rateLimitDescriptionPlural`:`sessionAuth.error.rateLimitDescriptionSingle`,{minutes:l}):s(o===`relay-auth`?`sessionAuth.error.relayAuthDescription`:`sessionAuth.error.networkDescription`),t[6]=o,t[7]=c,t[8]=l,t[9]=s,t[10]=f):f=t[10];let p;t[11]===f?p=t[12]:(p=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground max-w-xs`,children:f}),t[11]=f,t[12]=p);let m;t[13]!==d||t[14]!==p?(m=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[d,p]}),t[13]=d,t[14]=p,t[15]=m):m=t[15];let h;t[16]===s?h=t[17]:(h=s(`sessionAuth.error.retry`),t[16]=s,t[17]=h);let g;t[18]!==n||t[19]!==h?(g=(0,$.jsx)($r,{type:`button`,onClick:n,className:`w-full max-w-xs`,children:h}),t[18]=n,t[19]=h,t[20]=g):g=t[20];let _;return t[21]!==a||t[22]!==m||t[23]!==g?(_=(0,$.jsx)(ap,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[m,g,a]})}),t[21]=a,t[22]=m,t[23]=g,t[24]=_):_=t[24],_},cp=({children:e})=>{let{t:r}=fr(),a=Z.useMemo(()=>E(),[]),l=a,u=Z.useMemo(()=>y()&&!a,[a]),[d,h]=Z.useState(()=>l?`authenticated`:`pending`),[g,_]=Z.useState(``),[v,b]=Z.useState(!1),[x,S]=Z.useState(``),[C,w]=Z.useState(void 0),[T,D]=Z.useState(!1),[O,k]=Z.useState(Ds),[A,j]=Z.useState(!1),[M,N]=Z.useState(!1),[P,F]=Z.useState(()=>Zf()),[I,L]=Z.useState(null),[R,z]=Z.useState(l),B=Z.useRef(null),V=Z.useRef(l),H=Z.useRef(0);Z.useEffect(()=>()=>{H.current+=1},[]),Z.useEffect(()=>{typeof window>`u`||window.localStorage.setItem(Vf,P?`true`:`false`)},[P]);let U=Z.useCallback(async()=>{if(l)return Ds;let e=m(),t=f(),n=i(),r=()=>e===m()&&t===f()&&n===i();try{let e=await js();return r()&&k(e),e}catch{return r()&&k(Ds),Ds}},[l]);Z.useEffect(()=>{let e=!1;if(!l)return(async()=>{try{if(!window.isSecureContext||!Zo()){e||j(!1);return}e||j(!0)}catch{e||j(!1)}})(),()=>{e=!0}},[l]);let ee=Z.useRef(0),te=Z.useRef(null),G=Z.useRef(null),ne=Z.useCallback(()=>{te.current!==null&&(window.clearTimeout(te.current),te.current=null)},[]),re=Z.useCallback(()=>{ee.current=0,ne()},[ne]),ie=Z.useCallback(()=>ee.current>=zf?!1:(ee.current+=1,ne(),te.current=window.setTimeout(()=>{te.current=null,G.current?.()},Bf*ee.current),!0),[ne]);Z.useEffect(()=>ne,[ne]);let ae=Z.useCallback(async e=>{if(l){h(`authenticated`);return}let n=++H.current,r=m(),a=f(),o=i(),s=()=>n===H.current&&r===m()&&a===f()&&o===i(),c=y()?t():null;if(c?.getStatus().failureCode===`relay_authentication_rejected`){re(),h(`relay-auth-error`);return}h(e=>e===`authenticated`?e:`pending`);try{let[t,n]=await Promise.all([e??Xf(),e?Ds:U()]),r=await t.text();if(!s())return;if(t.ok){re(),h(`authenticated`),D(!1),S(``),w(void 0);return}if(t.status===401||t.status===403&&(c||y())){let i=c?!0:await tp();if(!s())return;if(i===void 0){re(),h(`error`);return}if(i){re(),D(!1),h(`pairing-expired`),w(void 0);return}if(t.status===403){if(ie())return;h(`error`);return}let a={};try{a=JSON.parse(r)}catch{a={}}re(),D(a.tunnelLocked===!0),e||k(n),h(`locked`),w(void 0);return}if(t.status===429){let e={};try{e=JSON.parse(r)}catch{e={}}re(),w(e.retryAfter),D(!1),h(`rate-limited`);return}if(ie())return;h(`error`),D(!1)}catch(e){if(!s())return;if(console.warn(`Failed to check session status:`,e),c?.getStatus().failureCode===`relay_authentication_rejected`){re(),h(`relay-auth-error`);return}let t=c?!0:await tp();if(!s())return;if(t||t===void 0){if(ie())return;h(`error`),D(!1);return}if(Lf({shouldUseDesktopShellPasswordLogin:ep()})===`locked`){h(`locked`),w(void 0),D(!1);return}if(ie())return;h(`error`),D(!1)}},[U,re,ie,l]);Z.useEffect(()=>{G.current=ae},[ae]),Z.useEffect(()=>{l||ae()},[ae,l]),Z.useEffect(()=>{if(!(l||d!==`authenticated`))return If(e=>{e.kind===`relay-authentication`?(H.current+=1,re(),h(`relay-auth-error`)):ae(e.response)},{desktop:y()})},[ae,re,l,d]),Z.useEffect(()=>{if(d===`pending`||d===`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)}},[d]),Z.useEffect(()=>{if(l)return;let e=uf(e=>{p(e)&&(_(``),S(``),w(void 0),D(!1),re(),z(!1),V.current=!1,h(`pending`),ae())}),t=c(t=>e.schedule(t));return()=>{t(),e.cancel()}},[ae,re,l]),Z.useEffect(()=>{!l&&(d===`locked`||d===`pairing-expired`)&&(V.current=!1,z(!1))},[l,d]),Z.useEffect(()=>{d===`locked`&&B.current&&(B.current.focus(),B.current.select())},[d]),Z.useEffect(()=>{if(!l&&d===`authenticated`&&!V.current){V.current=!0;let e=!1;return cf({runtimeKey:m(),initializeAppearance:ve,syncSettings:qe,applyDirectory:af,onError:(e,t)=>{console.error(`[SessionAuthGate] ${e} settings hydration failed:`,t)}},{force:!0}).then(()=>{e||z(!0)}),()=>{e=!0}}},[l,d]);let oe=async e=>{e.preventDefault(),await le(!1)},se=Z.useCallback(async()=>{L(`register`),N(!0);try{await Ss()}finally{L(null),N(!1)}await U()},[U]),ce=Z.useCallback(()=>{Ts(),L(null),N(!1)},[]),le=Z.useCallback(async e=>{if(!T&&!(!g||v)){M&&ce(),b(!0),S(``);try{if(ep()){let e=await np(g,P);if(e?.token){_(``),D(!1),await ip(e.token),h(`authenticated`);return}if(e?.status===401){S(r(`sessionAuth.error.incorrectPassword`)),D(!1),h(`locked`);return}if(e?.status===429){w(void 0),D(!1),h(`rate-limited`);return}}let t=await Qf(g,P);if(t.ok){let n=await t.json().catch(()=>null),i=Kf(),a=``;if(i&&(a=typeof n?.clientToken==`string`&&n.clientToken.trim()?n.clientToken.trim():``,a||=(await np(g,P))?.token||await $f()),_(``),D(!1),a&&await ip(a),e&&A)try{await se(),no.success(r(`sessionAuth.toast.passkeyAdded`)),h(`authenticated`);return}catch(e){if(Os(e))no.message(r(`sessionAuth.toast.passkeySetupCanceled`));else{let t=e instanceof Error?e.message:r(`sessionAuth.error.passkeySetupFailed`);no.error(t)}h(`authenticated`);return}h(`authenticated`);return}if(t.status===401){S(r(`sessionAuth.error.incorrectPassword`)),D(!1),h(`locked`);return}if(t.status===429){let e=await t.json().catch(()=>({}));w(e.retryAfter),D(!1),h(`rate-limited`);return}S(r(`sessionAuth.error.unexpectedResponse`)),D(!1),h(`error`)}catch(e){console.warn(`Failed to submit UI password:`,e);let t=ep()?await np(g,P):null;if(t?.token){_(``),D(!1),await ip(t.token),h(`authenticated`);return}if(t?.status===401){S(r(`sessionAuth.error.incorrectPassword`)),D(!1),h(`locked`);return}if(t?.status===429){w(void 0),D(!1),h(`rate-limited`);return}S(r(`sessionAuth.error.networkRetry`)),D(!1),h(`error`)}finally{b(!1)}}},[ce,M,v,T,g,se,A,r,P]),ue=Z.useCallback(async()=>{if(!(v||!A)){if(M){ce();return}N(!0),L(`auth`),S(``);try{let e=await Is(P,{issueClientToken:Kf(),clientLabel:`Yuri Desktop`,...Yf()}),t=Kf()&&typeof e?.clientToken==`string`&&e.clientToken.trim()?e.clientToken.trim():``;t&&await ip(t),_(``),h(`authenticated`)}catch(e){if(Os(e))S(``);else{let t=e instanceof Error?e.message:r(`sessionAuth.error.passkeySignInCanceled`);S(t)}}finally{L(null),N(!1)}}},[ce,M,v,A,r,P]),de=Z.useCallback(async()=>{if(!(v||T||!A)){if(M){ce();return}if(d!==`authenticated`){if(!g){S(r(`sessionAuth.error.enterPasswordForPasskey`));return}await le(!0);return}S(``);try{await se(),no.success(r(`sessionAuth.toast.passkeyAdded`))}catch(e){if(Os(e)){no.message(r(`sessionAuth.toast.passkeySetupCanceled`));return}let t=e instanceof Error?e.message:r(`sessionAuth.error.passkeySetupFailed`);no.error(t)}}},[ce,le,M,v,T,g,se,d,A,r]),fe=A&&O.enabled,pe=fe&&O.hasPasskeys;return d===`pending`||d===`authenticated`&&!R?(0,$.jsx)(op,{}):d===`error`?(0,$.jsx)(sp,{onRetry:()=>{re(),ae()},errorType:`network`,children:u&&(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:r(`sessionAuth.locked.hostSwitcherHint`)})]})}):d===`rate-limited`?(0,$.jsx)(sp,{onRetry:()=>void ae(),errorType:`rate-limit`,retryAfter:C}):d===`pairing-expired`?(0,$.jsx)(ap,{children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-xs flex-col items-center gap-6 text-center`,children:[(0,$.jsx)(X,{name:`computer`,className:`size-8 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:r(`mobile.connect.pairing.expired`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:r(`desktopHostSwitcher.pairing.reconnectHint`)})]}),(0,$.jsx)($r,{type:`button`,className:`w-full`,onClick:()=>{W().catch(()=>no.error(r(`sessionAuth.error.networkTitle`)))},children:r(`settings.remoteInstances.openLocalManager`)}),(0,$.jsx)(Ff,{})]})}):d===`relay-auth-error`?(0,$.jsx)(sp,{errorType:`relay-auth`,onRetry:()=>{let e=n();e&&(o(),s(e)),re(),ae()},children:u&&(0,$.jsx)(Ff,{})}):d===`locked`?(0,$.jsx)(ap,{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:r(T?`sessionAuth.locked.tunnelTitle`:`sessionAuth.locked.unlockTitle`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:r(T?`sessionAuth.locked.tunnelDescription`:`sessionAuth.locked.passwordDescription`)})]}),!T&&(0,$.jsxs)(`form`,{onSubmit:oe,className:`w-full space-y-2`,children:[pe&&(0,$.jsxs)($r,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>void ue(),disabled:v||M&&I!==`auth`,children:[M?(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:r(M&&I===`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)($o,{id:`yuri-ui-password`,ref:B,type:`password`,autoComplete:`current-password`,placeholder:r(`sessionAuth.password.placeholder`),value:g,onChange:e=>{_(e.target.value),x&&S(``)},className:`pl-10`,"aria-invalid":!!x||void 0,"aria-describedby":x?`yuri-ui-auth-error`:void 0,disabled:v})]}),(0,$.jsx)($r,{type:`submit`,size:`icon`,disabled:!g||v,"aria-label":r(v?`sessionAuth.actions.unlockingAria`:`sessionAuth.actions.unlockAria`),children:v?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`})})]}),fe?(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)(Qo,{checked:P,onChange:F,disabled:v,ariaLabel:r(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:r(`sessionAuth.actions.trustDevice`)})]}),(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void de(),disabled:v,children:r(M&&I===`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)(Qo,{checked:P,onChange:F,disabled:v,ariaLabel:r(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:r(`sessionAuth.actions.trustDevice`)})]}),x&&(0,$.jsx)(`p`,{id:`yuri-ui-auth-error`,className:`typography-meta text-destructive`,children:x})]}),u&&(0,$.jsxs)(`div`,{className:`w-full`,children:[(0,$.jsx)(Ff,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:r(`sessionAuth.locked.hostSwitcherHint`)})]})]})}):(0,$.jsx)($.Fragment,{children:e})},lp=e=>!!e&&typeof e==`object`&&!Array.isArray(e),up=e=>typeof e==`string`&&e.trim()?e.trim():null,dp=e=>{if(!lp(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=up(e.minimumVersion),i=up(e.targetVersion);if(!r||!i||typeof e.canInstall!=`boolean`)throw Error(`Could not check OpenCode compatibility`);return{state:t,version:up(e.version),installation:n,minimumVersion:r,targetVersion:i,canInstall:e.canInstall,guidance:up(e.guidance)}},fp=async()=>{let e=await g(`/api/opencode/compatibility`,{signal:AbortSignal.timeout(2e4)});if(!e.ok)throw Error(`Could not check OpenCode compatibility`);return dp(await e.json())},pp=async()=>{let e=await g(`/api/opencode/install-required`,{method:`POST`}),t=await e.json().catch(()=>null),n=lp(t)?t:null,r=up(n?.error);if(!e.ok||n?.success!==!0||n?.upgraded!==!0)throw Error(r||`OpenCode installation failed`);let i=up(n.version);if(!i)throw Error(r||`OpenCode installation did not report a verified version`);return{version:i}},mp=(e,t)=>e instanceof Error&&e.message.trim()?e.message.trim():t,hp=({children:e})=>{let{t}=fr(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),[o,s]=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 fp();if(!e||t!==p.current)return;r(n),n.state!==`incompatible`&&u(null)}catch{}finally{e&&t===p.current&&a(!0)}};t();let n=c(()=>{e&&(r(null),a(!1),s(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(o)return;let n=++p.current;s(e),u(null);try{if(e===`install`){let e=await pp();if(n!==p.current)return;if(!e.version)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload();return}let i=await fp();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(mp(e,t(`opencodeUpgrade.screen.failedGeneric`)))}finally{n===p.current&&s(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)(Bs,{width:120,height:120,isAnimated:!0})});if(!i)return g;if(!m||!n)return(0,$.jsx)(Vs,{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=o!==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)(Bs,{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)($r,{type:`button`,disabled:b,onClick:()=>void h(`install`),children:[(0,$.jsx)(X,{name:o===`install`?`refresh`:`download`,className:o===`install`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:o===`install`?`status`:void 0,children:o===`install`?t(_?`opencodeUpgrade.screen.updating`:`opencodeUpgrade.screen.installing`):t(_?`opencodeUpgrade.screen.update`:`opencodeUpgrade.screen.install`,{minimum:y})})]}):null,(0,$.jsxs)($r,{type:`button`,variant:n.canInstall?`ghost`:`default`,disabled:b,onClick:()=>void h(`reconnect`),children:[(0,$.jsx)(X,{name:`refresh`,className:o===`reconnect`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:o===`reconnect`?`status`:void 0,children:t(o===`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,{})})]})})},gp=e=>{let t=(0,Q.c)(14),{children:n}=e,r=q(_p),i=q(vp),a=q(yp),o=q(bp),s=q(xp),{deviceType:c,hasTouchInput:l}=Us(),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=typeof document<`u`&&_n(),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 _p(e){return e.fontSize}function vp(e){return e.codeFontSize}function yp(e){return e.applyTypography}function bp(e){return e.padding}function xp(e){return e.applyPadding}var Sp=e(se(),1),Cp={light:`#212121`,dark:`#DEDEDE`},wp=e=>{let t=/^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.exec(e);if(!t)return null;let n=t[1].length<5?[...t[1]].map(e=>e+e).join(``):t[1];return[0,2,4].map(e=>Number.parseInt(n.slice(e,e+2),16)).concat(n.length===8?Number.parseInt(n.slice(6),16)/255:1)},Tp=e=>{let t=e.slice(0,3).map(e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4});return t[0]*.2126+t[1]*.7152+t[2]*.0722},Ep=e=>{let t=Cp[e.metadata.variant],n=Tp(wp(t)),r=e.colors,i=!1,a=(e,r)=>{let a=wp(e);if(!a)return e;let o=wp(r);return Tp(a[3]===1||!o?a:a.slice(0,3).map((e,t)=>e*a[3]+o[t]*(1-a[3])))+1e-9>=n?e:(i=!0,t)},o={...r.surface,foreground:a(r.surface.foreground,r.surface.background),elevatedForeground:a(r.surface.elevatedForeground,r.surface.elevated)},s=r.chat?{...r.chat}:void 0;s?.userMessage&&(s.userMessage=a(s.userMessage,s.userMessageBackground||r.surface.elevated)),s?.assistantMessage&&(s.assistantMessage=a(s.assistantMessage,s.assistantMessageBackground||r.surface.muted));let c=r.tools?{...r.tools}:void 0;c?.title&&(c.title=a(c.title,r.surface.muted));let l=r.markdown?{...r.markdown}:void 0;if(l)for(let e of[`bold`,`italic`,`heading1`,`heading2`,`heading3`,`heading4`]){let t=l[e];if(!t)continue;let n=wp(t),i=n&&n[0]===n[1]&&n[1]===n[2],o=[r.surface.foreground,r.surface.elevatedForeground].some(e=>e.toLowerCase()===t.toLowerCase());(!e.startsWith(`heading`)||i||o)&&(l[e]=a(t,s?.background||r.surface.background))}return i?{...e,colors:{...r,surface:o,...s&&{chat:s},...c&&{tools:c},...l&&{markdown:l}}}:e},Dp=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}`},Op=class{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){e=Ep(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)),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=Dp(e.colors.surface.muted),r=Dp(e.colors.surface.subtle),i=Dp(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.insertBefore(n,document.head.querySelector(`[data-yuri-plugin-style]`)),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{interactive:t}=e.colors,n=e.metadata.variant===`light`,r=[];return r.push(` --interactive-border: ${t.border};`),r.push(` --interactive-border-hover: ${t.borderHover};`),r.push(` --interactive-border-focus: ${t.borderFocus};`),r.push(` --interactive-selection: ${n?`color-mix(in srgb, var(--surface-foreground) 7%, var(--background))`:t.selection};`),r.push(` --interactive-selection-foreground: ${n?`var(--surface-foreground)`:t.selectionForeground};`),r.push(` --interactive-focus: ${t.focus};`),r.push(` --interactive-focus-ring: ${t.focusRing};`),r.push(` --interactive-cursor: ${t.cursor};`),r.push(` --interactive-hover: ${t.hover};`),r.push(` --interactive-active: ${t.active};`),r}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=E()?yn:Tn;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()}},kp=()=>Zs()?new URLSearchParams(window.location.search):null,Ap=()=>typeof window>`u`||window.matchMedia(`(prefers-color-scheme: dark)`).matches,jp=()=>{let e=kp()?.get(`themeVariant`);return e===`dark`||e===`light`?e===`dark`:Ap()},Mp=e=>$s(e.currentTheme)?e.currentTheme:null,Np=e=>Mp(e)?.metadata.variant??null,Pp=Ks,Fp=Js,Ip=()=>{let e=kp()?.get(`currentTheme`);if(!e)return null;try{let t=JSON.parse(e);return $s(t)?t:null}catch{return null}},Lp=e=>qs(e===`dark`),Rp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,zp=()=>{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`)}},Bp=e=>{let t=Pp,n=Fp,r=`system`;if(typeof window<`u`){let e=kp(),i=e?.get(`themeMode`),a=e?.get(`lightThemeId`),o=e?.get(`darkThemeId`),s=pt(`themeMode`),c=pt(`lightThemeId`),l=pt(`darkThemeId`),u=pt(`useSystemTheme`),d=pt(`selectedThemeId`),f=pt(`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=Gs(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=Gs(e);r&&(r.metadata.variant===`light`?t=r.metadata.id:n=r.metadata.id)}return{themeMode:r,lightThemeId:t,darkThemeId:n}};function Vp({children:e,defaultThemeId:t}){let n=(0,Z.useMemo)(()=>new Op,[]),[r,i]=(0,Z.useState)(()=>Bp(t)),[a,o]=(0,Z.useState)(!1),[s,l]=(0,Z.useState)(()=>jp()),[u,d]=(0,Z.useState)([]),[f,m]=(0,Z.useState)([]),h=J(e=>(m(e),()=>{m(t=>t===e?[]:t)})),[_]=(0,Z.useState)(()=>Ip()),[v,b]=(0,Z.useState)(null),[x,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(()=>typeof window>`u`||!E()?null:window.__YURI_VSCODE_THEME__||null),D=(0,Z.useMemo)(()=>E(),[]),O=(0,Z.useMemo)(()=>S(),[]),k=(0,Z.useMemo)(()=>y(),[]),A=(0,Z.useMemo)(()=>typeof window>`u`?!1:kp()!==null,[]),j=(0,Z.useMemo)(()=>{let e=[],t=new Set,n=n=>{let r=n.metadata.id;t.has(r)||(t.add(r),e.push(Ep(n)))};return D&&w&&n(w),v&&n(v),_&&n(_),u.forEach(n),Ws.forEach(n),e},[u,_,v,D,w]),M=(0,Z.useMemo)(()=>e=>j.find(t=>t.metadata.id===e),[j]),N=(0,Z.useMemo)(()=>(e,t)=>{let n=M(e);return n&&n.metadata.variant===t?n:j.find(e=>e.metadata.variant===t)??Lp(t)},[j,M]),P=(0,Z.useMemo)(()=>D&&w?M(w.metadata.id)??Ep(w):r.themeMode===`light`?N(r.lightThemeId,`light`):r.themeMode===`dark`||s?N(r.darkThemeId,`dark`):N(r.lightThemeId,`light`),[N,M,D,r,s,w]),F=(0,Z.useMemo)(()=>{if(D||A)return P;let e=f.find(e=>e.metadata.variant===P.metadata.variant);return e?Ep(e):P},[D,A,f,P]),I=J(async()=>{if(!(typeof window>`u`||D)){C(!0);try{let e=await g(`/api/config/themes`,{method:`GET`,credentials:O?`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($s);d(n)}catch{}finally{C(!1)}}});(0,Z.useEffect)(()=>{I()},[I]),(0,Z.useEffect)(()=>{if(!D)return;let e=e=>{T(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)},[D]);let L=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)}),R=J(e=>{typeof document>`u`||document.documentElement.classList.toggle(`vscode-runtime`,e)});Rp(()=>{if(typeof window>`u`)return;let e=zp();n.apply(F),R(D),L(F);let t=document.documentElement;return t.classList.remove(`light`,`dark`),t.classList.add(F.metadata.variant),e},[R,n,F,D,L]),(0,Z.useEffect)(()=>{if(r.themeMode!==`system`||typeof window>`u`||A)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>{l(e.matches)};return l(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[r.themeMode,A]),(0,Z.useEffect)(()=>{if(A||typeof window>`u`)return;Pe(`themeMode`,r.themeMode),Pe(`lightThemeId`,r.lightThemeId),Pe(`darkThemeId`,r.darkThemeId),Pe(`useSystemTheme`,String(r.themeMode===`system`)),Pe(`selectedThemeId`,P.metadata.id),Pe(`selectedThemeVariant`,P.metadata.variant===`light`?`light`:`dark`);let e=N(r.lightThemeId,`light`),t=N(r.darkThemeId,`dark`);Pe(`splashBgLight`,e.colors.surface.background),Pe(`splashFgLight`,e.colors.surface.foreground),Pe(`splashBgDark`,t.colors.surface.background),Pe(`splashFgDark`,t.colors.surface.foreground),O&&(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,P,N,O,A]),(0,Z.useEffect)(()=>{if(typeof window>`u`||A)return;let e=e=>{e.storageArea===window.localStorage&&(gt(e.key,`themeMode`)||gt(e.key,`lightThemeId`)||gt(e.key,`darkThemeId`))&&i(e=>{let t=pt(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=pt(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=pt(`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)},[A]);let z=J(e=>{let t=e.themeMode,n=e.lightThemeId,r=e.darkThemeId,a=Np(e),o=Mp(e);if(t!==`light`&&t!==`dark`&&t!==`system`||typeof n!=`string`||typeof r!=`string`)return;let s=n.trim(),c=r.trim();!s||!c||(zp(),(0,Sp.flushSync)(()=>{A&&o&&b(o),t===`system`&&a&&l(a===`dark`),i(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=z,()=>{e.__yuriApplyThemeSync===z&&delete e.__yuriApplyThemeSync}},[z]),(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||z(t.payload)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[z]),(0,Z.useEffect)(()=>{if(A||!a)return;let e=N(r.lightThemeId,`light`),t=N(r.darkThemeId,`dark`);Ze({themeId:P.metadata.id,themeVariant:P.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})},[P.metadata.id,P.metadata.variant,N,r.themeMode,r.lightThemeId,r.darkThemeId,A,a]),(0,Z.useEffect)(()=>{A||!k||(async()=>{await ur(r.themeMode,F.metadata.variant)})()},[F.metadata.variant,k,r.themeMode,A]),(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t&&(i(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}}),o(!0))};return window.addEventListener(`yuri:settings-synced`,e),()=>window.removeEventListener(`yuri:settings-synced`,e)},[]),(0,Z.useEffect)(()=>{if(!(A||typeof window>`u`))return c(e=>{p(e)&&(i(e=>{let t=pt(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=pt(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=pt(`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}}),o(!1))})},[A]);let B=J(e=>{let t=j.find(t=>t.metadata.id===e);t&&i(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`})}),V=J(e=>{i(t=>t.themeMode===e?t:{...t,themeMode:e})}),H=J(e=>{if(e){i(e=>e.themeMode===`system`?e:{...e,themeMode:`system`});return}let t=F.metadata.variant===`dark`?`dark`:`light`;i(e=>e.themeMode===t?e:{...e,themeMode:t})}),U=J(e=>{let t=j.find(t=>t.metadata.id===e&&t.metadata.variant===`light`);t&&i(e=>e.lightThemeId===t.metadata.id?e:{...e,lightThemeId:t.metadata.id})}),W=J(e=>{let t=j.find(t=>t.metadata.id===e&&t.metadata.variant===`dark`);t&&i(e=>e.darkThemeId===t.metadata.id?e:{...e,darkThemeId:t.metadata.id})}),ee=(0,Z.useMemo)(()=>({currentTheme:F,availableThemes:j,registerPluginThemes:h,setTheme:B,customThemesLoading:x,reloadCustomThemes:I,isSystemPreference:r.themeMode===`system`,setSystemPreference:H,themeMode:r.themeMode,setThemeMode:V,lightThemeId:r.lightThemeId,darkThemeId:r.darkThemeId,setLightThemePreference:U,setDarkThemePreference:W}),[j,h,F,x,r.darkThemeId,r.lightThemeId,r.themeMode,I,W,U,H,B,V]);return(0,$.jsx)(Lo.Provider,{value:ee,children:e})}var Hp=!1,Up=()=>{if(Hp||typeof window>`u`)return;Hp=!0;let e={showReasoningTraces:q.getState().showReasoningTraces,sessionTitleRefreshEnabled:q.getState().sessionTitleRefreshEnabled,sessionGoalEnabled:q.getState().sessionGoalEnabled,collapsibleThinkingBlocks:q.getState().collapsibleThinkingBlocks,showDeletionDialog:q.getState().showDeletionDialog,nativeNotificationsEnabled:q.getState().nativeNotificationsEnabled,notificationMode:q.getState().notificationMode,notifyOnSubtasks:q.getState().notifyOnSubtasks,notifyOnCompletion:q.getState().notifyOnCompletion,notifyOnError:q.getState().notifyOnError,notifyOnQuestion:q.getState().notifyOnQuestion,notifyOnPermission:q.getState().notifyOnPermission,notifyOnScheduledTasks:q.getState().notifyOnScheduledTasks,notifyOnAssistants:q.getState().notifyOnAssistants,notifyOnGoals:q.getState().notifyOnGoals,notificationTemplates:q.getState().notificationTemplates,summarizeLastMessage:q.getState().summarizeLastMessage,summaryThreshold:q.getState().summaryThreshold,summaryLength:q.getState().summaryLength,maxLastMessageLength:q.getState().maxLastMessageLength,autoDeleteEnabled:q.getState().autoDeleteEnabled,autoDeleteAfterDays:q.getState().autoDeleteAfterDays,sessionRetentionAction:q.getState().sessionRetentionAction,fontSize:q.getState().fontSize,terminalFontSize:q.getState().terminalFontSize,editorFontSize:q.getState().editorFontSize,uiFont:q.getState().uiFont,monoFont:q.getState().monoFont,padding:q.getState().padding,cornerRadius:q.getState().cornerRadius,inputBarOffset:q.getState().inputBarOffset,mobileKeyboardMode:q.getState().mobileKeyboardMode,diffLayoutPreference:q.getState().diffLayoutPreference,gitChangesViewMode:q.getState().gitChangesViewMode},t=null,n=null,r=()=>{let e=t;t=null,n=null,e&&Object.keys(e).length>0&&Ze(e)},i=e=>{t={...t??{},...e},!n&&(n=setTimeout(r,150))};q.subscribe(t=>{let n={showReasoningTraces:t.showReasoningTraces,sessionTitleRefreshEnabled:t.sessionTitleRefreshEnabled,sessionGoalEnabled:t.sessionGoalEnabled,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.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)})},Wp=(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},Gp=(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},Kp=(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},qp=(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])&&Kp(e[n],t[n]))},Jp=()=>{let e=q.getState();return{favoriteModels:e.favoriteModels,hiddenModels:e.hiddenModels,collapsedModelProviders:e.collapsedModelProviders,recentModels:e.recentModels,recentAgents:e.recentAgents,recentEfforts:e.recentEfforts}},Yp=(e,t)=>Wp(e.favoriteModels,t.favoriteModels)&&Gp(e.hiddenModels,t.hiddenModels)&&Kp(e.collapsedModelProviders,t.collapsedModelProviders)&&Wp(e.recentModels,t.recentModels)&&Kp(e.recentAgents,t.recentAgents)&&qp(e.recentEfforts,t.recentEfforts),Xp=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()]))}),Zp=()=>{if(typeof window>`u`)return()=>{};let e=null,t=null,n=!1,r=()=>{e=null;let n=Jp();t&&Yp(t,n)||(t=Xp(n),Ze(n).catch(()=>{}))},i=()=>{if(!n){n=!0;return}e!==null&&window.clearTimeout(e),e=window.setTimeout(r,1200)},a=q.subscribe((e,t)=>{Yp({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)}},Qp=!1,$p=`yuri-typography-base`,em=()=>{if(typeof document>`u`)return;let e=`:root {\n${Object.entries(Tn).map(([e,t])=>` --text-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}: ${t};`).join(`
|
|
4
4
|
`)}\n}\n`,t=document.getElementById($p);if(t){t.textContent=e;return}let n=document.createElement(`style`);n.id=$p,n.textContent=e,document.head.appendChild(n)},tm=()=>{Qp||typeof window>`u`||(Qp=!0,em())};function nm(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)(rm,r);let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(On,{client:Fn,children:n}),t[1]=n,t[2]=i),i}function rm(){return Ln(Fn)}var im=15,am=2e3,om=40,sm=2e4,cm=e=>{let t=ei(e=>e.isConnected),n=ei(e=>e.providers.length),r=ei(e=>e.agents.length),i=ei(e=>e.activeDirectoryKey),a=ei(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`?im:om;if(s.current>=e){if(l===`fast`){s.current=0,u(`slow`);return}u(`done`);return}let t=ei.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]),or(f,!o||l===`done`?null:l===`slow`?sm:am)},lm=40,um=20971520,dm=new Map,fm=0;function pm(e){return e.length*2}function mm(e,t){let n=dm.get(e);n!==void 0&&(fm-=n),dm.delete(e),dm.set(e,t),fm+=t}function hm(e,t){let n=dm.get(e);(n!==void 0||t!==void 0)&&mm(e,t??n??0)}function gm(e){let t=dm.get(e);t!==void 0&&(dm.delete(e),fm-=t)}function _m(e,t){let n=e??new Set;for(;dm.size>lm||fm>um;){let e=dm.keys().next().value;if(!e)return;if(n.has(e)){if(hm(e),dm.size<=n.size)return;continue}gm(e),t(e)}}function vm(e,t){mm(e,t)}function ym(e){gm(e)}function bm(e,t){hm(e,t)}function xm(e){let t=new Map,n=e=>{t.delete(e),ym(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=pm(r.content);return t.set(e,{...r,size:i?.isFile?i.size:void 0,mtimeMs:i?.isFile?i.mtimeMs:void 0}),vm(e,a),_m(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 bm(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 Sm(e){let t=(0,Q.c)(8),{apis:n,children:r}=e,i;t[0]===n.files?i=t[1]:(i=xm(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)(Pn.Provider,{value:o,children:r}),t[5]=o,t[6]=r,t[7]=s):s=t[7],s}var Cm=`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))`,wm=`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))`,Tm={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 Em(){let e=(0,Q.c)(2),t=Dm,[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 Dm(){return typeof document<`u`&&document.documentElement.classList.contains(`dark`)}function Om(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 km=e=>{let t=(0,Q.c)(8),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r=Em(),i=r?Cm:wm,a=Z.useRef(null);Om(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)] !text-[var(--yuri-toast-action-foreground,var(--foreground))] !px-2 !py-1 typography-meta !font-medium transition-colors`,cancelButton:`!ms-0 !me-0 !shrink-0 !rounded-[var(--radius-md)] !text-[var(--yuri-toast-cancel-foreground,var(--foreground))] !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)(er,{theme:s,className:`toaster group`,position:`bottom-right`,closeButton:!1,duration:3500,icons:Tm,toastOptions:c,style:l,...n})}),t[5]=n,t[6]=s,t[7]=u):u=t[7],u},Am=new jo({maxEntries:128,maxBytes:1048576}),jm=(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(`|`)}`,Mm=async e=>{let t=vl(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=e.agentName===void 0?void 0:Mo(Ao(e.agentName).var,vl),r=JSON.stringify([e.iconName,t,e.agentName,n?.background]),i=Am.get(r);return i===void 0&&(i=await(e.agentName===void 0?zc(e.iconName,t):Bl(No(`agent`,e.agentName,!1,n)))??``,i&&Am.set(r,i,(r.length+i.length)*2)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:i}}))},Nm=[],Pm=e=>void 0,Fm=()=>void 0;function Im(e){let t=yl()&&e.enabled&&Pl(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=Po(e.agentName),u=Ro()?.currentTheme,d=(0,Z.useRef)([]),f=(0,Z.useRef)(Nl()),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??Pm),w=J(e.onAutocompleteDismiss??Fm),T=J(e=>{typeof document>`u`||Ml(document.documentElement,e)});wl.bind({onText:(e,t,n)=>{jl({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:qt(e.text,e.attachments.map(e=>e.filename)),chipRanges:Dl(zl(e.text,e.chipHighlights),vl(`--primary`)),appearance:typeof document>`u`?`dark`:Vl(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:Tl(e.agentName||void 0),agentIdenticon:xl(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 bl(e,!0),()=>{bl(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,wl.rememberText(i.text),wl.retain(e,i);let a=Fl();return()=>{n.current=null,a(),wl.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e=>{c.current=e,n.current&&={...n.current,agentIcon:e},Al().update({agentIcon:e})};return i(``),Bl(No(`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=ul(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Al().update(a),i)return Bl(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},Al().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let D=Rl(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:[]},wl.rememberState(n.current)),Al().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await gl(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},wl.rememberState(n.current)),Al().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,D]);let O=e.autocompleteRows??Nm,k=e.autocompleteOpen===!0,A=e.autocompleteHighlightedIndex??0,j=e.autocompleteQuery??``,M=`${jm(O,k,A)}\0${j}`;(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(k&&O.length>0)){let e=Nl();Cl(f.current,e)||(f.current=e,n.current&&(n.current={...n.current,autocomplete:e},wl.rememberState(n.current)),Al().update({autocomplete:e}));return}return Mm(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:vl(`--primary-base`)||vl(`--primary`),rows:t};Cl(f.current,r)||(f.current=r,n.current&&(n.current={...n.current,autocomplete:r},wl.rememberState(n.current)),Al().update({autocomplete:r}))}),()=>{e=!0}},[t,M,u]);let N=t?zl(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&&Hl(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,wl.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=_l({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=Ol(c,s,u,{caret:e.caret});d&&Al().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}function Lm(e){return Im(e),null}var Rm=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},zm=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Io(),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},Bm=e=>{let t=ei(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 g(`/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},Vm=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}=fr(),{currentTheme:_}=Io(),v=ei(Hm),y=q(Um),b;t[0]===y?b=t[1]:(b=Fs(Ns(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(Wm),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}=Kl(O),V=k===`recording`&&P===`model_download_in_progress`,H=Bm(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,G;t[10]!==d||t[11]!==k?(te=()=>(d?.(k!==`idle`),()=>d?.(!1)),G=[k,d],t[10]=d,t[11]=k,t[12]=te,t[13]=G):(te=t[12],G=t[13]),Z.useLayoutEffect(te,G);let ne,re;t[14]!==I||t[15]!==v||t[16]!==c||t[17]!==F||t[18]!==S?(ne=()=>{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)},re=[S,v,c,F,I],t[14]=I,t[15]=v,t[16]=c,t[17]=F,t[18]=S,t[19]=ne,t[20]=re):(ne=t[19],re=t[20]),Z.useEffect(ne,re);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:Gm,onPointerDownCapture:Km},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)(zm,{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)(zm,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:Rm(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 Hm(e){return e.dictationEnabled}function Um(e){return e.shortcutOverrides}function Wm(){return!E()&&Gl()}function Gm(e){return e.preventDefault()}function Km(e){e.pointerType===`touch`&&e.preventDefault()}function qm(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 Jm({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}=fr(),f=q(e=>e.shortcutOverrides),p=Fs(Ns(`toggle_dictation`,f)),m=Kl({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]=ar(()=>{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())});ir(`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}),ir(`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}),ir(`selectstart`,e=>{D.current!==null&&e.preventDefault()},document,{capture:!0}),ir(`mousemove`,e=>{D.current!==null&&e.preventDefault()},window,{capture:!0}),ir(`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),ir(`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}),ir(`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())});ir(`blur`,()=>{C||(z(),D.current===null?h.current&&F():B())},window),ir(`visibilitychange`,()=>{C||document.hidden&&(z(),D.current===null?h.current&&F():B())},document),ir(C?`yuri:mobile-dictation-toggle`:`yuri:dictation-toggle`,()=>{I()},window),ir(`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,Sp.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)(Tc,{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)(ns,{delayDuration:0,children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{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)(Tc,{decorative:!0}):(0,$.jsx)(qm,{kind:`mic`,active:x&&!m.error,className:Y(a??`size-5`,m.error&&`text-[var(--status-error)]`)})})}),(0,$.jsx)(ts,{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 Ym=2e3,Xm=G((e,t)=>({pending:!1,expiresAt:null,arm:(t=Ym)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),Zm=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}},Qm=e=>jn({queryKey:[e.transport,`sessionChildren`,e.generation,Xn(e.directory),e.sessionID],queryFn:({signal:t})=>e.request(t),staleTime:0,gcTime:6e4,retry:!1}),$m=e=>Fn.fetchQuery(Qm(e)),eh=(e,t)=>e.id<t.id?-1:+(e.id>t.id),th=(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(eh)},nh=30,rh=new Map;function ih(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function ah(e,t){let n=Ut();if(!n)return!1;let r=n.getTranscript(mt(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>ma()}function oh(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function sh(e,t,n){let r=[...e.getState().session],i=ti.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function ch(){let e=ia(),t=Di(),n=Mi(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=Ut();if(!r||!t)return ih({kind:`unknown`,loadedTurns:0},!1);let i=mt(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return ih(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}};mi(a,t),ni(r,t),r.setState(a);for(let n of t)ke(e,n)},[n]),o=(0,Z.useCallback)((t=e)=>{let n=rh.get(t);if(n)return rh.delete(t),rh.set(t,n),n;let r=new Set;for(rh.set(t,r);rh.size>nh;){let e=rh.keys().next().value;if(!e)break;let t=[...rh.get(e)??[]];rh.delete(e),a(e,t)}return r},[e,a]),s=(0,Z.useCallback)((r,i=e)=>{let s=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=o(i),l=Ir(s.getState()),u=ro(),d=Kr({seen:c,keep:r,limit:u,preserve:l});if(a(i,d),la()){let e=new Set([r,...c,...l]),t=(Ut()?.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:ah(i,t));if(n.length>0){for(let e of n)c.delete(e);a(i,n)}}},[n,e,o,a,t]),c=(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 Gt(a,r):await Le(a,r,{background:!0})}catch{return}if(i?.isStale?.())return;let u=Ut()?.getTranscript(mt(a,r));to({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await Qa({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]),l=(0,Z.useCallback)(async(t,i)=>{await _i();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,l=n.ensureChild(o,{bootstrap:!1}),u=Kt.getScopedSdkClient(o);s(t,o);let d=r(t,o);return Zm.run({scope:l,key:d,request:async e=>{let n=l.getState(),r=Ut(),i=mt(o,t),s=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=ti.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&s&&d.kind!==`unknown`&&p?.status!==`error`&&f&&Ga(o,t)){to({directory:o,sessionID:t,store:l,isStale:e});return}let m=!!(a||!s||f),h=oh({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await pi(async()=>u.session.get({sessionID:t}));if(n&&!e()){let r=ai(je(n));e()||sh(l,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?c(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,s,c,e]),d=J(async(t,r)=>{let i=r||e;if(!t||!i)return;let a=n.ensureChild(i,{bootstrap:!1}),o=Kt.getScopedSdkClient(i),s=f(),c=u(),l=()=>s!==f()||c!==u()||n.getChild(i)!==a,d=await $m({transport:c,generation:s,directory:i,sessionID:t,request:async e=>{let n=[],r=new Set,a;do{if(e.throwIfAborted(),s!==f()||c!==u())throw new DOMException(`Session children runtime changed`,`AbortError`);let l=await o.session.list(a?{cursor:a,limit:50}:{directory:i,parentID:t,limit:50},{signal:e});if(!Array.isArray(l?.data))throw Error(`session.list children returned no data`);if(n.push(...l.data.map(je)),l.data.length<50)break;if(a=l.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(l())return null;throw e});!d||l()||a.setState(e=>{let n=th(e.session,d,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;Te(mt(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;Te(mt(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(t=>{let n=t.directory||e;Te(mt(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),y=J(async(t,r)=>{if(!t)return;await _i();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=f(),s=u(),c=()=>o!==f()||s!==u()||n.ensureChild(i,{bootstrap:!1})!==a,l=a.getState();try{if(await Le(i,t),c())return;to({directory:i,sessionID:t,store:a}),await Qa({directory:i,sessionID:t,store:a,statusBeforePull:l.session_status?.[t],statusObservedAtBeforePull:l.session_status_observed_at?.[t],hasMessages:(Ut()?.getTranscript(mt(i,t)).messageOrder.length??0)>0,isStale:c})}catch{throw Error(`refresh transcript failed`)}});return(0,Z.useMemo)(()=>({ensureSessionRenderable:l,syncSession:l,loadChildren:d,hasMore:p,isLoading:m,isComplete:h,refreshSessionTranscript:y,optimistic:{add:g,remove:_,confirm:v}}),[l,d,p,m,h,y,g,_,v])}var lh=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,uh=e=>e===`original`||e===`modified`,dh=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},fh=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!lh(t.source))return null;let n=dh(t.startLine),r=dh(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:uh(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()}},ph=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(fh).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},mh=G()(ie(ne((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:Cn(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:ph(e.drafts)}}),{name:`inline-comment-draft-store`}));function hh(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 gh(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(hh).join(`
|
|
5
5
|
|
|
@@ -6543,8 +6543,8 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,S as n,l as r,s
|
|
|
6543
6543
|
|
|
6544
6544
|
`:` `).trim():``}function Sw(e){let t=[],n=e.trim();for(;n;){let e=n.indexOf(`
|
|
6545
6545
|
|
|
6546
|
-
`);if(e>0&&e<=280){t.push(n.slice(0,e).trim()),n=n.slice(e).trimStart();continue}if(n.length<=280){t.push(n);break}let r=[...n.slice(0,280).matchAll(/[。!?.!?;;\n](?:[”’"')\]]*)\s*|\s+/gu)].reverse().find(e=>e.index>=80),i=r?r.index+r[0].length:280;/[\uD800-\uDBFF]/u.test(n[i-1])&&--i,t.push(n.slice(0,i).trim()),n=n.slice(i).trimStart()}return t}function Cw(e){let t=null,n=null,r=null,i=[],a=()=>{for(let e of i)e.removeAttribute(`data-speech-marker-inline-code`);i=[]},o=()=>{let r=Array.from(t?.getClientRects?.()??[]).filter(e=>e.width>0&&e.height>0).sort((e,t)=>e.top-t.top||e.left-t.left);if(r.length===0){for(let e of i)e.removeAttribute(`data-speech-marker-inline-code`);n?.replaceChildren();return}for(let e of i)e.hasAttribute(`data-speech-marker-inline-code`)||e.setAttribute(`data-speech-marker-inline-code`,`true`);let a=e.getBoundingClientRect(),o=getComputedStyle(t?.startContainer.parentElement??e).fontSize,s=[];for(let e of r){let t=s.find(t=>Math.min(t.bottom,e.bottom)-Math.max(t.top,e.top)>=Math.min(t.bottom-t.top,e.height)/2&&e.left<=t.right+1&&e.right>=t.left-1);t?(t.left=Math.min(t.left,e.left),t.right=Math.max(t.right,e.right),t.top=Math.min(t.top,e.top),t.bottom=Math.max(t.bottom,e.bottom)):s.push({left:e.left,right:e.right,top:e.top,bottom:e.bottom})}n||(n=document.createElement(`span`),n.className=`yuri-speech-marker-layer`,n.setAttribute(`aria-hidden`,`true`),e.setAttribute(`data-speech-marker-owner`,`true`),e.append(n)),n.style.fontSize=o;let c=s.map(t=>{let n=document.createElement(`span`);return n.className=`yuri-speech-marker-stroke`,n.style.left=`${t.left-a.left-e.clientLeft+e.scrollLeft}px`,n.style.top=`${t.top-a.top-e.clientTop+e.scrollTop}px`,n.style.width=`${t.right-t.left}px`,n.style.height=`${t.bottom-t.top}px`,n});n.replaceChildren(...c)};return{update(n){t=n;let a=[];if(t){let n=t,r=n.commonAncestorContainer,i=r instanceof Element?r:r.parentElement,o=i?.closest(`code, .inline-code`);a=(o?[o]:Array.from(i?.querySelectorAll(`code, .inline-code`)??[])).filter(t=>e.contains(t)&&!t.closest(`pre`)&&n.intersectsNode(t))}for(let e of i)a.includes(e)||e.removeAttribute(`data-speech-marker-inline-code`);i=a,o(),t&&!r&&typeof ResizeObserver<`u`&&(r=new ResizeObserver(o),r.observe(e))},stop(){r?.disconnect(),r=null,t=null,a(),n?.remove(),n=null,e.removeAttribute(`data-speech-marker-owner`)}}}var ww=null,Tw=null,Ew=null,Dw=new Set,Ow=()=>ww,kw=()=>ww?.target??null,Aw=e=>(Dw.add(e),()=>{Dw.delete(e)}),jw=()=>{for(let e of Dw)e()};function Mw(e){!ww?.following||!e.contains(ww.target)||(ww={...ww,following:!1},jw())}function Nw(){ww&&(ww={...ww,following:!0},jw())}var Pw=e=>e.replace(/[^\p{L}\p{N}]/gu,``).toLowerCase();function Fw(e,t=``,n=!0){Ew?.();let r=Symbol(`speech`);Tw=r;let i=[],a=``,o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(;o.nextNode();){let e=o.currentNode;if(!e.parentElement?.closest(`[data-speech-content]`)||e.parentElement?.closest(`button, [aria-hidden="true"], [data-message-actions], [data-message-footer]`)||n&&e.parentElement?.closest(`pre`))continue;let t=e.data,r=n?[...t.matchAll(/https?:\/\/[^\s]+|(?:^|\s)\/(?:[\w.-]+\/)*[\w.-]+/g)]:[],s=0;for(let n=0;n<t.length;){let o=r[s];if(o&&n>=o.index){n=o.index+o[0].length,s++;continue}let c=String.fromCodePoint(t.codePointAt(n)),l=Pw(c);for(let t=0;t<l.length;t++)i.push({node:e,offset:n});a+=l,n+=c.length}}let s=Pw(t),c=s?a.indexOf(s):-1,l=c>=0?c+s.length:0,u=-1,d=null,f=Cw(e),p=()=>{f.stop(),typeof CSS<`u`&&CSS.highlights&&CSS.highlights.delete(`yuri-speech`),d?.removeAttribute(`data-speech-active`),d=null};return Ew=p,ww={target:e,range:null,following:!0},jw(),{update(e,t){if(Tw!==r||!ww||t===u)return;u=t;let n=Pw(e),o=n?a.indexOf(n,l):-1,s=null;if(o>=0){let e=i[o],t=i[o+n.length-1];s=document.createRange(),s.setStart(e.node,e.offset),s.setEnd(t.node,t.offset+(t.node.data.codePointAt(t.offset)>65535?2:1)),l=o+n.length}f.update(s),typeof CSS<`u`&&CSS.highlights&&typeof Highlight<`u`?(CSS.highlights.delete(`yuri-speech`),s&&CSS.highlights.set(`yuri-speech`,new Highlight(s))):(d?.removeAttribute(`data-speech-active`),d=s?.startContainer.parentElement?.closest(`p, li, h1, h2, h3, h4, blockquote, [data-speech-content]`)??null,d?.setAttribute(`data-speech-active`,`true`)),ww={...ww,range:s},jw()},stop(){Tw===r&&(p(),Ew=null,ww=null,Tw=null,jw())}}}var Iw=600,Lw=null,Rw=null,zw=`Summarize the assistant reply for text-to-speech listening. Reply with 2-4 sentences of plain spoken prose in the same language as the reply. No markdown, no lists, no code — mention code changes briefly in words instead.`;async function Bw(e,t){try{let n=await g(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:zw,...t.providerID?{preferredProviderID:t.providerID}:{},...t.modelID?{preferredModelID:t.modelID}:{}})});if(!n.ok)return null;let r=await n.json().catch(()=>null);return typeof r?.text==`string`&&r.text.trim()?r.text.trim():null}catch{return null}}function Vw(e={}){let[t,n]=(0,Z.useState)(!1),r=(0,Z.useRef)(0),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),l=ei(e=>e.voiceProvider),u=ei(e=>e.speechRate),d=ei(e=>e.speechPitch),f=ei(e=>e.speechVolume),p=ei(e=>e.browserVoice),m=ei(e=>e.showMessageTTSButtons),h=ei(e=>e.ttsInputMode),g=l===`openai`||l===`openai-compatible`||l===`volcengine`,_=(e.enabled??m)&&l===`say`,{speak:v,stop:y,unlockAudio:b}=Xd({enabled:!1}),{speak:x,stop:S,unlockAudio:C,isAvailable:w}=bw({enabled:_}),{speak:T,stop:E,unlockAudio:D}=qd(),O=J((e,t)=>{let n=t?.dataset.speechIdentity,r=(n&&Rw?.identity===n?Rw:null)??i.current;return r?.text===e&&r.mode===h&&r.provider===l&&r.identity===n&&r.index<r.chunks.length?r:null}),k=J((e,t)=>O(e,t)!==null),A=J(()=>{Lw===A&&i.current&&i.current.index<i.current.chunks.length&&(Rw=i.current),r.current+=1,a.current!==null&&clearTimeout(a.current),o.current!==null&&clearTimeout(o.current),a.current=null,o.current=null,s.current?.stop(),s.current=null,n(!1),y(),S(),E(),Lw===A&&(Lw=null,Jd.cancelSpeech())});ir(`keydown`,e=>{e.key!==`Escape`||e.isComposing||!t||(e.preventDefault(),e.stopPropagation(),A())},()=>t?window:null,{capture:!0}),(0,Z.useEffect)(()=>Ul(A),[A]),(0,Z.useEffect)(()=>c(()=>{A(),i.current=null,Rw=null}),[A]);let j=J(async()=>{let e=l===`local`?D:l===`say`?C:g?b:null;await Promise.all([e?.(),Jd.resumeAudioContext()])});return(0,Z.useEffect)(()=>()=>{Lw===A?A():r.current+=1},[A]),{isPlaying:t,play:J(async(e,t,c)=>{if(!e.trim()){t?.();return}Lw?.(),A(),Lw=A;let m=r.current,_=!1,b=e=>{m!==r.current||_||(_=!0,o.current!==null&&clearTimeout(o.current),o.current=null,s.current?.stop(),s.current=null,Lw===A&&(Lw=null),e?(Rw=i.current,y(),S(),E(),Jd.cancelSpeech()):(Rw===i.current&&(Rw=null),i.current=null),n(!1),t?.(e))};n(!0);try{let t=c?.target?.dataset.speechIdentity,n=c?.restart?null:O(e,c?.target),C=n!==null,D=e;if(!C&&h===`summarized`&&e.length>=Iw){let{currentProviderId:t,currentModelId:n}=ei.getState(),r=await Bw(e,{providerID:t||void 0,modelID:n||void 0});r&&(D=r)}if(m!==r.current)return;let k=h===`raw`&&g,A=xw(D,D.length>280),j=k?D:A;if(!j.trim()){b();return}let M=C?n:{text:e,mode:h,provider:l,identity:t,chunks:g?[j.trim()]:Sw(j),index:0,offset:0,audioKey:{}};if(i.current=M,Rw?.identity===t&&Rw?.text===e&&(Rw=null),c?.target){let e=c.target.querySelectorAll(`[data-speech-content]`),t=h===`final`?e[e.length-1]??c.target:c.target,n=g?M.chunks[0].slice(0,M.offset):M.chunks.slice(0,M.index).join(` `);s.current=Fw(t,n,!k)}let N=async(e=0)=>{if(m!==r.current||_)return;let t=M.chunks[M.index];if(!t){b();return}let n=!1,i=()=>{o.current!==null&&clearTimeout(o.current),o.current=null},c=()=>{n||m!==r.current||g||s.current?.update(t,M.index)},h=()=>{n||m!==r.current||(n=!0,i(),M.index+=1,M.index===M.chunks.length?b():N())},D=t=>{if(!(n||m!==r.current)){if(n=!0,i(),/not.allowed|autoplay|blocked|not supported|unsupported|HTTP 4\d\d|API.key|unauthorized|forbidden|invalid|no text/i.test(t)||e>=2){b(Error(t));return}y(),S(),E(),Jd.cancelSpeech(),a.current=setTimeout(()=>{a.current=null,N(e+1)},600*(e+1))}};o.current=setTimeout(()=>D(`Speech playback stalled`),Math.max(45e3,t.length*500/Math.max(u||1,.1)));try{let i={onStart:c,onEnd:h,onError:D};if(g)await v(t,{...i,playbackKey:M.audioKey,resume:C||e>0,resumeOffset:M.offset,onProgress:e=>{n||m!==r.current||e.start<M.offset||(M.offset=e.start,s.current?.update(e.text,e.start))}});else if(l===`local`)await T(t,i);else if(l===`say`&&w)await x(t,i);else{if(await Jd.waitForVoices(),await Jd.resumeAudioContext(),m!==r.current)return;await Jd.speakText(t,navigator.language||`en-US`,h,{rate:u,pitch:d,volume:f,voiceName:p||void 0,onStart:c,onError:D})}}catch(e){D(e instanceof Error?e.message:String(e))}};await N()}catch(e){console.error(`[useMessageTTS] Playback error:`,e),b(e instanceof Error?e:Error(String(e)))}}),canResume:k,stop:A,unlock:j}}var Hw=(0,Z.createContext)(null),Uw=(0,Z.createContext)(null);function Ww(e){let t=(0,Q.c)(10),{sessionId:n,messageId:r,created:i,text:a,completed:o,streaming:s,targetRef:c}=e,l=s!==void 0&&s,u=(0,Z.useContext)(Hw),d,f;t[0]!==o||t[1]!==u||t[2]!==i||t[3]!==r||t[4]!==n||t[5]!==l||t[6]!==c||t[7]!==a?(d=()=>{if(!u?.enabled||(l&&u.streaming(n,r),!o))return;let e=0,t=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>u.rendered({sessionId:n,messageId:r,created:i,text:a,target:c?.current??void 0}))});return()=>{cancelAnimationFrame(t),cancelAnimationFrame(e)}},f=[u,n,r,i,a,o,l,c],t[0]=o,t[1]=u,t[2]=i,t[3]=r,t[4]=n,t[5]=l,t[6]=c,t[7]=a,t[8]=d,t[9]=f):(d=t[8],f=t[9]),(0,Z.useEffect)(d,f)}var Gw=144,Kw=null,qw=new Set,Jw=!1,Yw=null;function Xw(){for(let e of qw)e()}function Zw(){return Kw}function Qw(){return Yw}function $w(e){return qw.add(e),()=>{qw.delete(e)}}function eT(e,t){let n=Z.useSyncExternalStore($w,Zw,Qw);return t&&n===e}function tT(e){!e||Kw===e||(Kw=e,Xw())}function nT(e){Kw!==null&&(e&&Kw!==e||(Kw=null,Xw()))}function rT(e){return e instanceof Element?e.closest(`[data-message-id]`)?.getAttribute(`data-message-id`)??null:null}function iT(){Jw||typeof document>`u`||(Jw=!0,document.addEventListener(`pointerdown`,e=>{Kw&&rT(e.target)!==Kw&&nT()},!0))}function aT(e,t){iT();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>Gw||tT(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),nT(t)}}var oT=`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`,sT=`size-3.5!`,cT=`medium`,lT=`flex items-center gap-2`,uT={containerType:`inline-size`,containerName:`message-footer`},dT=`${lT} -ml-[5px]`,fT=`mt-2.5 mb-3 flex flex-wrap items-center gap-3`,pT=`mt-1.5 mb-2 flex flex-wrap items-center gap-3`,mT=`flex w-max max-w-full flex-none flex-wrap items-center gap-2 text-muted-foreground`,hT=`h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,gT=`inline-flex ${hT}`,_T=`size-3.5!`,vT=e=>{let t=(0,Q.c)(6),{messageId:n,label:r,focusReveal:i}=e,a=eT(n,i),o=i?a?`inline-flex`:`hidden`:`hidden yuri-message-hover-time`,s;t[0]===o?s=t[1]:(s=Y(hT,`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},yT=e=>{let t=(0,Q.c)(16),{label:n}=e,{t:r}=fr(),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:cT,name:`pulse`,className:_T}),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)(es,{asChild:!0,children:(0,$.jsxs)(`span`,{className:gT,"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)(ts,{children:c}),t[11]=c,t[12]=l);let u;return t[13]!==s||t[14]!==l?(u=(0,$.jsxs)(ns,{children:[s,l]}),t[13]=s,t[14]=l,t[15]=u):u=t[15],u},bT=Z.memo(function(e){let t=(0,Q.c)(14),{messageId:n,isMobile:r,actions:i,tps:a,duration:o,timestamp:s,activity:c,trailing:l}=e,u=r?pT:fT,d;t[0]===i?d=t[1]:(d=i?(0,$.jsx)(`div`,{className:dT,"data-message-action-group":`true`,children:i}):null,t[0]=i,t[1]=d);let f;t[2]!==c||t[3]!==o||t[4]!==r||t[5]!==n||t[6]!==s||t[7]!==a?(f=a||o||s||c?(0,$.jsxs)(`div`,{className:mT,children:[a||o?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 whitespace-nowrap`,children:[a?(0,$.jsx)(yT,{label:a}):null,o?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsxs)(`span`,{className:gT,children:[(0,$.jsx)(X,{weight:cT,name:`hourglass`,className:_T}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:o})]})}),(0,$.jsx)(ts,{children:o})]}):null]}):null,c,s?(0,$.jsx)(vT,{messageId:n,label:s,focusReveal:r}):null]}):null,t[2]=c,t[3]=o,t[4]=r,t[5]=n,t[6]=s,t[7]=a,t[8]=f):f=t[8];let p;return t[9]!==u||t[10]!==d||t[11]!==f||t[12]!==l?(p=(0,$.jsxs)(`div`,{className:u,"data-message-footer":`true`,style:uT,children:[d,f,l]}),t[9]=u,t[10]=d,t[11]=f,t[12]=l,t[13]=p):p=t[13],p}),xT=Z.memo(e=>{let t=(0,Q.c)(73),{messageId:n,hasCopyableText:r,isTouchContext:i,onCopyMessage:a,ttsText:o,sessionId:s,allowSourceSession:c}=e,l=c===void 0||c,{t:u}=fr(),d=mx(),f=Zb(),p;t[0]===f?p=t[1]:(p=Qb(f),t[0]=f,t[1]=p);let m=p,{isPlaying:h,play:g,stop:_,canResume:v}=Vw(),y=Z.useContext(Uw),b=!!(y&&y.sessionId===s&&y.messageId===n),x=h||b,S=ei(ST),C=ei(CT),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useRef(null),M=Z.useRef(null),N=!!a,P=f.sessionId||s,F=!!(l&&P&&f.directory&&m.openSourceSession&&d!==`mini-chat`),I;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(I=()=>{j.current!==null&&typeof window<`u`&&(window.clearTimeout(j.current),j.current=null)},t[2]=I):I=t[2];let L=J(I),R;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>{M.current!==null&&typeof window<`u`&&(window.clearTimeout(M.current),M.current=null)},t[3]=R):R=t[3];let z=J(R),B,V;t[4]!==z||t[5]!==L?(B=()=>()=>{L(),z()},V=[z,L],t[4]=z,t[5]=L,t[6]=B,t[7]=V):(B=t[6],V=t[7]),Z.useEffect(B,V);let H,U;t[8]!==N||t[9]!==z||t[10]!==L||t[11]!==r?(H=()=>{(!r||!N)&&(T(!1),D(!1),L(),z())},U=[N,z,L,r],t[8]=N,t[9]=z,t[10]=L,t[11]=r,t[12]=H,t[13]=U):(H=t[12],U=t[13]),Z.useEffect(H,U);let W;t[14]!==N||t[15]!==L||t[16]!==r||t[17]!==i?(W=()=>{!i||!N||!r||typeof window>`u`||(L(),T(!0),j.current=window.setTimeout(()=>{T(!1),j.current=null},1800))},t[14]=N,t[15]=L,t[16]=r,t[17]=i,t[18]=W):W=t[18];let ee=J(W),te;t[19]!==z||t[20]!==r||t[21]!==i||t[22]!==a||t[23]!==ee?(te=async e=>{!a||!r||(e.stopPropagation(),e.preventDefault(),await a()!==!1&&(z(),D(!0),typeof window<`u`&&(M.current=window.setTimeout(()=>{D(!1),M.current=null},2e3)),i&&ee()))},t[19]=z,t[20]=r,t[21]=i,t[22]=a,t[23]=ee,t[24]=te):te=t[24];let G=J(te),ne;t[25]!==l||t[26]!==s||t[27]!==f?(ne=e=>{e.stopPropagation(),e.preventDefault();let t=f.sessionId||s;!l||!t||!f.directory||!f.openSourceSession||f.openSourceSession(t,f.directory)},t[25]=l,t[26]=s,t[27]=f,t[28]=ne):ne=t[28];let re=J(ne),ie;bb0:{if(x){let e;t[29]===u?e=t[30]:(e=u(`chat.messageBody.tts.stopSpeaking`),t[29]=u,t[30]=e),ie=e;break bb0}let e=C===`browser`?`Browser`:C===`openai`?`OpenAI`:C===`openai-compatible`?`Custom`:`Say`,n;t[31]!==e||t[32]!==u?(n=u(`chat.messageBody.tts.readAloudWithProvider`,{provider:e}),t[31]=e,t[32]=u,t[33]=n):n=t[33],ie=n}let ae=ie,oe;t[34]!==g||t[35]!==u||t[36]!==o?(oe=e=>{let t=e!==void 0&&e;if(k(!1),!o.trim())return;let n=A.current?.closest(`[data-message-text-export-root]`)??void 0;g(o,e=>{e&&$n.error(u(`chat.messageBody.tts.failed`))},{target:n,restart:t})},t[34]=g,t[35]=u,t[36]=o,t[37]=oe):oe=t[37];let se=J(oe),ce;t[38]!==y||t[39]!==v||t[40]!==b||t[41]!==x||t[42]!==se||t[43]!==_||t[44]!==o?(ce=(e,t)=>{if(!e){k(!1);return}if(x){t.cancel(),b&&y?.stop(),_();return}let n=A.current?.closest(`[data-message-text-export-root]`)??void 0;if(v(o,n)){k(!0);return}t.cancel(),se()},t[38]=y,t[39]=v,t[40]=b,t[41]=x,t[42]=se,t[43]=_,t[44]=o,t[45]=ce):ce=t[45];let le=J(ce),ue;t[46]!==w||t[47]!==G||t[48]!==r||t[49]!==E||t[50]!==a||t[51]!==u?(ue=a&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":w||E?`true`:void 0,className:Y(`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`,!r&&`opacity-50`),disabled:!r,"aria-label":u(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!r,onPointerDown:wT,onClick:e=>{G(e)},onFocus:()=>{r&&T(!0)},onBlur:()=>{E||T(!1)},children:E?(0,$.jsx)(X,{weight:`medium`,name:`check`,className:Y(`size-3.5!`,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:`medium`,name:`file-copy`,className:`size-3.5!`})})}),(0,$.jsx)(ts,{sideOffset:6,children:u(`chat.messageBody.actions.copyAnswer`)})]}),t[46]=w,t[47]=G,t[48]=r,t[49]=E,t[50]=a,t[51]=u,t[52]=ue):ue=t[52];let de;t[53]!==F||t[54]!==re||t[55]!==u?(de=F?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,"aria-label":u(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:TT,onClick:re,children:(0,$.jsx)(X,{weight:cT,name:`target`,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:u(`chat.messageBody.actions.openSourceSession`)})]}):null,t[53]=F,t[54]=re,t[55]=u,t[56]=de):de=t[56];let fe;t[57]!==d||t[58]!==le||t[59]!==r||t[60]!==x||t[61]!==i||t[62]!==ae||t[63]!==S||t[64]!==se||t[65]!==u||t[66]!==O||t[67]!==o?(fe=d!==`mini-chat`&&S&&r&&o.trim()&&(0,$.jsxs)(bs,{open:O&&!x,onOpenChange:le,modal:!1,children:[(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)(xs,{asChild:!0,children:(0,$.jsx)($r,{ref:A,type:`button`,variant:`ghost`,size:`icon`,className:Y(`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`,`!bg-transparent shadow-none`,x?`text-[var(--primary-base)]`:`hover:text-foreground/80`),"aria-label":u(x?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),"aria-pressed":x,onPointerDown:ET,onClick:DT,children:(0,$.jsx)(qm,{kind:`speaker`,active:x,className:`size-3.5!`})})})}),(0,$.jsx)(ts,{sideOffset:6,children:ae})]}),(0,$.jsxs)(ls,{side:`top`,align:`start`,sideOffset:6,onClick:OT,children:[(0,$.jsxs)(fs,{className:i?`min-h-11 px-3`:void 0,onSelect:()=>se(!1),children:[(0,$.jsx)(X,{name:`play`,weight:`medium`,className:`size-4`}),u(`chat.messageBody.tts.resume`)]}),(0,$.jsxs)(fs,{className:i?`min-h-11 px-3`:void 0,onSelect:()=>se(!0),children:[(0,$.jsx)(X,{name:`restart`,weight:`medium`,className:`size-4`}),u(`chat.messageBody.tts.restart`)]})]})]}),t[57]=d,t[58]=le,t[59]=r,t[60]=x,t[61]=i,t[62]=ae,t[63]=S,t[64]=se,t[65]=u,t[66]=O,t[67]=o,t[68]=fe):fe=t[68];let pe;return t[69]!==ue||t[70]!==de||t[71]!==fe?(pe=(0,$.jsxs)($.Fragment,{children:[ue,de,fe]}),t[69]=ue,t[70]=de,t[71]=fe,t[72]=pe):pe=t[72],pe});function ST(e){return e.showMessageTTSButtons}function CT(e){return e.voiceProvider}function wT(e){return e.stopPropagation()}function TT(e){return e.stopPropagation()}function ET(e){return e.stopPropagation()}function DT(e){return e.stopPropagation()}function OT(e){return e.stopPropagation()}var kT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),AT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),kT(e,n)},jT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),MT=e=>String(e).padStart(2,`0`),NT=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(` `)},PT=e=>{if(!jT(e))return``;let t=new Date(e);return`${t.getFullYear()}-${MT(t.getMonth()+1)}-${MT(t.getDate())} ${MT(t.getHours())}:${MT(t.getMinutes())}`},FT=(e,t)=>{if(!jT(e))return``;let n=new Date(e),r=new Date,i=ds(n,t),a=lr(),o=pr.getState().dictionary;if(kT(n,r))return i;if(AT(n,r))return mr(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}`},IT={onPointerEnter:e=>{e.pointerType!==`touch`&&e.currentTarget.setAttribute(`data-message-hovered`,``)},onPointerLeave:e=>{e.currentTarget.removeAttribute(`data-message-hovered`)},onPointerCancel:e=>{e.currentTarget.removeAttribute(`data-message-hovered`)}},LT=class e{static instance;sessionStartTimes=new Map;seenMessageIds=new Set;messageCreationTimes=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}recordSessionStart(e){this.sessionStartTimes.set(e,Date.now())}getSessionStartTime(e){return this.sessionStartTimes.get(e)}shouldAnimateMessage(e,t){if(e.role!==`assistant`||this.seenMessageIds.has(e.id))return!1;let n=this.sessionStartTimes.get(t);if(!n)return this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created),!1;let r=e.time.created>n-5e3;return r||(this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created)),r}clearSession(e){this.sessionStartTimes.delete(e)}hasSessionTiming(e){return this.sessionStartTimes.has(e)}hasBeenAnimated(e){return this.seenMessageIds.has(e)}markMessageAsAnimated(e,t){this.seenMessageIds.add(e),this.messageCreationTimes.set(e,t)}clearAll(){this.sessionStartTimes.clear(),this.seenMessageIds.clear(),this.messageCreationTimes.clear()}getDebugInfo(){return{sessionStartTimes:new Map(this.sessionStartTimes),seenMessageIds:new Set(this.seenMessageIds),messageCreationTimes:new Map(this.messageCreationTimes)}}},RT=100,zT=(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},BT=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=!0,d=new Map,f=[],p=()=>{c===void 0&&(c=t(()=>{c=void 0,h()}))},m=()=>{let e=a;if(!e){f=[],u=!1;return}let t=e.getBoundingClientRect().top;f=[...d].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),f.sort((e,t)=>e.top-t.top),u=!1},h=()=>{let t=a;if(!t)return;u&&m();let n=zT(f,t.scrollTop+RT);!n||n===l||(l=n,e.onActive(n))},g=()=>{let e=a;if(e){if(o?.disconnect(),o=void 0,r){o=new r(()=>{m(),p()}),o.observe(e);for(let e of d.values())o.observe(e)}if(s?.disconnect(),s=void 0,i&&!r){s=new i(()=>{u=!0,p()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}u=!0,p()}},_=e=>{a!==e&&(a=e,l=void 0,g())},v=(e,t)=>{let n=d.get(t);n&&n!==e&&o?.unobserve(n),d.set(t,e),o&&o.observe(e),u=!0,p()},y=e=>{let t=d.get(e);t&&(o?.unobserve(t),d.delete(e),u=!0,p())},b=()=>{u=!0,p()},x=()=>{for(let e of d.values())o?.unobserve(e);d.clear(),f=[],l=void 0,u=!0};return{setContainer:_,register:v,unregister:y,onScroll:p,markDirty:b,clear:x,destroy:()=>{c!==void 0&&n(c),c=void 0,x(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>l}},VT=10,HT=`${VT}vh`,UT=`56px`;`${UT}`;var WT=(e,t)=>e?56:t<=0?96:Math.max(48,VT/100*t),GT=(e,t)=>({sessionId:e,viewportKey:t}),KT=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,qT=(e,t)=>KT(e,t),JT=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),YT=150,XT=1500,ZT=2,QT=350,$T=600,eE=8e3,tE=24,nE=2,rE=(e,t)=>e<t,iE=()=>typeof performance<`u`?performance.now():Date.now(),aE=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),oE=e=>e.scrollHeight-e.scrollTop-e.clientHeight,sE=e=>oE(aE(e)),cE=e=>e.scrollHeight-e.clientHeight>1,lE=(e,t)=>oE(e)<=WT(t,e.clientHeight),uE=({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(GT(n,r));w.current=GT(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(null),P=Z.useRef(!1),F=Z.useRef(null),I=Z.useRef(0),L=Z.useRef(!1),R=Z.useRef(null),z=Z.useRef(null),B=J(()=>{I.current=iE()+450,z.current=null}),V=Z.useRef(0),H=Z.useRef(!1),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(0),te=Z.useRef(!1),G=Z.useRef(null),ne=Z.useRef(null),re=Z.useRef(null),ie=bi(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{l.current!==f.current&&(f.current=l.current,d(l.current))});let ae=J(e=>{x.current!==e&&(x.current=e,m(e))}),oe=J(e=>{E.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:iE()},D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{E.current=null,D.current=null},XT)}),se=J(e=>{let t=E.current;return t?iE()-t.time>XT?(E.current=null,!1):Math.abs(e.scrollTop-t.top)<ZT:!1}),ce=J(()=>iE()<j.current),le=J(()=>{H.current=!1,U.current&&=(clearTimeout(U.current),null),W.current&&=(clearTimeout(W.current),null)}),ue=J(()=>{U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{U.current=null,le()},$T)}),de=J(()=>{let e=l.current;e&&(H.current=!0,ee.current=e.scrollHeight,ue(),W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{W.current=null,le()},eE))}),fe=J(e=>{let t=l.current;if(!t){g(!1),v(!1);return}let n=e??aE(t),r=cE(n);if(g(r),!r){v(!1);return}let i=x.current===`released`&&!lE(n,S.current);v(i)}),pe=J(()=>{O.current+=1,k.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(k.current),k.current=null),A.current?.(),A.current=null});Z.useEffect(()=>()=>pe(),[u]);let me=J(()=>{if(!e)return;let n=l.current;if(!n)return;if(pe(),t?.current?.scrollToBottom({behavior:`auto`,reveal:!1})){oe(n),fe();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=()=>{oe(n),n.scrollTop=n.scrollHeight,V.current=n.scrollTop};if(s(),fe(),typeof window>`u`)return;let c=0,u=()=>{rE(iE(),I.current)||pe()};n.addEventListener(`touchstart`,u,{passive:!0,once:!0}),A.current=()=>n.removeEventListener(`touchstart`,u);let d=()=>{if(r===O.current){if(sE(n)>nE&&s(),c+=1,c>=tE){k.current=null,A.current?.(),A.current=null,fe();return}k.current=window.requestAnimationFrame(d)}};k.current=window.requestAnimationFrame(d)}),he=J(e=>{let n=l.current;if(n&&(oe(n),!t?.current?.scrollToBottom({behavior:e,reveal:!1}))){if(e===`smooth`){n.scrollTo({top:n.scrollHeight,behavior:e});return}n.scrollTop=n.scrollHeight}}),ge=J((t,n=`auto`)=>{if(!e)return;let r=l.current;if(t&&x.current!==`following`&&ae(`following`),r&&!(!t&&x.current!==`following`)){if(sE(r)<ZT){oe(r);return}he(t?n:`auto`)}}),_e=J(e=>{let t=l.current;if(!t)return;let n=e??aE(t);cE(n)&&x.current!==`released`&&(ae(`released`),fe(n))}),ve=J((e=`instant`,n)=>{if(L.current=!1,te.current=!1,ae(`following`),le(),pe(),t?.current?.scrollToBottom({behavior:e===`smooth`?`smooth`:`auto`,...n})){let e=l.current;e&&oe(e),fe();return}if(e===`instant`){me();return}pe(),ge(!0,`smooth`),fe()}),ye=J(()=>{te.current=!1,ge(!0)}),be=J(()=>{L.current=!1,pe(),t?.current?.cancelScroll(),le(),ae(`released`),fe()}),xe=J(()=>{let t=Ow(),n=l.current;if(!e||!n||!t||!n.contains(t.target)||!t.following||!t.range||z.current)return;let r=aE(n);if(!cE(r))return;let i=t.range.getBoundingClientRect?.();if(!i||!i.height)return;let a=n.getBoundingClientRect(),o=r.clientHeight*.2,s=Math.min(i.height,r.clientHeight-o*2);if(i.top>=a.top+o&&i.top+s<=a.bottom-o)return;let c=(r.clientHeight-s)/2,u=Math.min(r.scrollHeight-r.clientHeight,Math.max(0,r.scrollTop+i.top-a.top-c));Math.abs(u-r.scrollTop)<=1||(be(),n.scrollTo({top:u,behavior:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`instant`:`smooth`}),V.current=n.scrollTop)});Z.useEffect(()=>(xe(),Aw(xe)),[e,u,xe]);let Se=J(()=>{te.current=!0,be()}),Ce=J(()=>{te.current=!1}),we=Z.useRef(c);we.current=c;let Te=J(()=>{l.current&&Mw(l.current),!rE(iE(),I.current)&&(L.current=!1,pe(),t?.current?.cancelScroll(),le(),_e())}),Ee=J(()=>{I.current=0,Te(),we.current?.()}),De=J(()=>{G.current!==null&&(clearTimeout(G.current),G.current=null);let e=ne.current;if(e){if(!e.identity.sessionId){ne.current=null;return}ie(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),ne.current=null}}),Oe=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=JT(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),G.current===null&&(G.current=setTimeout(()=>{G.current=null,De()},YT))}),ke=J(()=>{De()}),Ae=J(async(e=w.current)=>{if(!e.sessionId||x.current===`released`&&KT(e,T.current))return!1;te.current=!1;let t=l.current;return t?(re.current=null,ae(`following`),B(),S.current?me():ge(!0),V.current=t.scrollTop,de(),fe(),!1):(re.current=e,ae(`following`),!1)});Z.useEffect(()=>{let e=w.current,t=T.current;KT(e,t)||(De(),pe(),B(),T.current=e,L.current=!1,R.current=null,E.current=null,V.current=0,le(),te.current=!1,ae(`following`),re.current=null,n&&n!==t?.sessionId&<.getInstance().recordSessionStart(n))},[n,r]),Z.useEffect(()=>{a&&!te.current&&x.current===`following`&&ge(!0)},[a]),Z.useEffect(()=>{b(p===`following`&&a)},[p,a]),Z.useLayoutEffect(()=>{if(!u)return;let e=re.current;e&&qT(e,w.current)&&Ae(e)},[u,n,r]);let je=J(()=>{let e=l.current;if(!e)return;let t=aE(e),n=V.current;V.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;fe(t);let a=Ow();if(a&&e.contains(a.target)){Oe();return}if(te.current){Oe();return}if(cE(t)){if(lE(t,S.current)){let e=Math.min(n,Math.max(0,t.scrollHeight-t.clientHeight));if(t.scrollTop<e-.5){Te(),Oe();return}(x.current===`following`||r&&L.current)&&(ae(`following`),L.current=!1),Oe();return}if(x.current===`following`&&(se(e)||ce()||i)){M.current||ge(!1),Oe();return}(x.current===`following`||!r)&&Te(),Oe()}});Z.useEffect(()=>{!e||!u||(V.current=u.scrollTop)},[u,e]);let Me=J(e=>{let t=l.current;if(t){if(e.deltaY!==0&&Mw(t),e.deltaY>0){Oc(t,e.target)||(L.current=!0);return}e.deltaY>=0||Dc(t,e.target)||Ee()}}),Ne=J(e=>{L.current=!1;let t=e.touches.item(0);z.current=t?{x:t.clientX,y:t.clientY,dx:0,dy:0}:null}),Pe=J(e=>{let t=l.current,n=e.touches.item(0);if(!n){z.current=null;return}let r=z.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(z.current={x:n.clientX,y:n.clientY,dx:o,dy:s},!(Math.abs(o)>=Math.abs(s))&&t){if(Math.abs(s)>2&&Mw(t),s<-2){Oc(t,e.target)||(L.current=!0);return}if(!(s<=0)){if(Dc(t,e.target)){z.current.dx=0,z.current.dy=0;return}s<=2||Ee()}}}),Fe=J(()=>{z.current=null}),Ie=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)&&Mw(l.current),!e.altKey&&!e.ctrlKey&&!e.metaKey&&[`ArrowDown`,`PageDown`,`End`].includes(e.key)){let e=l.current;e&&!Oc(e,t)&&(L.current=!0);return}xc(e)&&Ee()}}),Le=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&(I.current=0,Te(),R.current={id:e.pointerId,y:e.clientY})}),Re=J(e=>{let t=R.current;!t||t.id!==e.pointerId||(e.clientY!==t.y&&(L.current=e.clientY>t.y),t.y=e.clientY)}),ze=J(()=>{R.current=null}),Be=J(()=>{L.current=!1}),Ve=Z.useMemo(()=>()=>void 0,[]),He=e&&u?u:Ve,Ue=Z.useMemo(()=>({passive:!0}),[]);ir(`scroll`,je,He,Ue),ir(`scrollend`,Be,He,Ue),Z.useEffect(()=>{if(!e||!u)return;let t={passive:!0,capture:!0};return u.addEventListener(`wheel`,Me,t),u.addEventListener(`touchstart`,Ne,t),u.addEventListener(`touchmove`,Pe,t),u.addEventListener(`touchend`,Fe,t),u.addEventListener(`touchcancel`,Fe,t),()=>{u.removeEventListener(`wheel`,Me,t),u.removeEventListener(`touchstart`,Ne,t),u.removeEventListener(`touchmove`,Pe,t),u.removeEventListener(`touchend`,Fe,t),u.removeEventListener(`touchcancel`,Fe,t)}},[e,u]),ir(`keydown`,Ie,He),ir(`pointermove`,Re,e&&typeof window<`u`?window:Ve,!0),ir(`pointerup`,ze,e&&typeof window<`u`?window:Ve,!0),ir(`pointercancel`,ze,e&&typeof window<`u`?window:Ve,!0),ir(`pointerdown`,Le,e&&typeof window<`u`?window:Ve,!0);let We=J(()=>{let e=l.current;if(M.current){fe(e?aE(e):void 0);return}if(te.current){fe(e?aE(e):void 0);return}if(!e){fe(void 0);return}let t=aE(e),n=N.current;if(n?.element===e&&n.height!==t.clientHeight&&(N.current=null,x.current===`released`)){e.scrollTop=Math.max(0,n.top+n.height-t.clientHeight),oe(e),fe(aE(e));return}if(!cE(t)){fe(t);return}if(fe(t),H.current){let n=t.scrollHeight>ee.current+1;ee.current=t.scrollHeight,oE(t)<=ZT?oe(e):ge(!0),n&&ue();return}if(x.current===`following`){if(oE(t)<=ZT){oe(e);return}ge(!1)}}),Ge=typeof ResizeObserver<`u`,Ke=Ge&&e?u:null,qe=Ge&&e&&u&&u.firstElementChild instanceof Element?u.firstElementChild:null;sr(Ke,We),sr(qe,We);let Je=J(()=>{F.current!==null&&(clearTimeout(F.current),F.current=null)}),Ye=J(e=>{M.current=!0,typeof e==`number`&&e>0?j.current=iE()+e+QT:j.current=Math.max(j.current,iE()+QT)}),Xe=J(e=>{let t=e.detail;if(t){if(t.open===!0){Ye(),Je(),F.current=setTimeout(()=>{F.current=null,P.current||(M.current=!1)},1500);return}Je(),Ye()}}),Ze=J(e=>{let t=e.detail;t&&(Je(),Ye(t.durationMs),t.nativeResize&&(M.current=!1))}),Qe=J(e=>{let t=e.detail;if(Je(),t?.nativeResize){P.current=t.open===!0,M.current=!1,j.current=iE()+QT,We();return}t?.open===!0?(P.current=!0,M.current=!0):(P.current=!1,M.current=!0,F.current=setTimeout(()=>{F.current=null,P.current||(M.current=!1)},QT)),fe()}),$e=e&&typeof window<`u`?window:Ve;ir(`yuri:keyboard-native-layout`,()=>{let e=l.current;N.current=e?{element:e,top:e.scrollTop,height:e.clientHeight}:null},$e),ir(`yuri:keyboard-intent`,Xe,$e),ir(`yuri:keyboard-anim`,Ze,$e),ir(`yuri:keyboard-settled`,Qe,$e),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{Je(),N.current=null,M.current=!1,P.current=!1}},[e]),Z.useEffect(()=>{e&&fe()},[e,i]);let et=J(t=>{if(e){if(t===`animation`&&(j.current=iE()+QT),fe(),H.current){ge(!0),ue();return}x.current===`following`&&ge(!1)}}),tt=Z.useRef(new Map),nt=J(t=>{let n=tt.current.get(t);if(n)return n;let r=()=>{e&&x.current===`following`&&ge(!1)},i={onChunk:r,onComplete:()=>{e&&fe()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return tt.current.set(t,i),i});Z.useEffect(()=>()=>{D.current&&=(clearTimeout(D.current),null),pe(),le(),De(),G.current!==null&&(clearTimeout(G.current),G.current=null)},[]);let rt=J(e=>{s?.(e)}),it=!!s;return Z.useEffect(()=>{if(!e||!it)return;let t=u;if(!t)return;let n=null,r=BT({onActive:e=>{e!==n&&(n=e,rt(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,it]),{scrollRef:l,state:p,isPinned:p===`following`,isOverflowing:h,isFollowingProgrammatically:y,showScrollButton:_,notifyContentChange:et,getAnimationHandlers:nt,goToBottom:ve,scrollToBottomOnSend:ye,releaseAutoFollow:be,beginHistoryViewportPreservation:Se,endHistoryViewportPreservation:Ce,saveSnapshotNow:ke,restoreSnapshot:Ae}},dE=(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()}}}})(wl),fE=new Map,pE=e=>dE.hold(e),mE=e=>{fE.has(e)||fE.set(e,dE.hold(e))},hE=e=>{let t=fE.get(e);t&&(fE.delete(e),t())},gE=`btw-page`,_E=`btw-sheet`,vE=`text-selection`,yE=`1.5rem`,bE=`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`,xE=`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]`,SE=Z.memo(function(e){let t=(0,Q.c)(54),{turn:n,isLast:r,sessionId:i,directory:a,isMobile:o}=e,{t:s}=fr(),{hasTouchInput:c}=Us(),l=`btw:${i}:${n.id}`,u=Z.useRef(null),d,f;t[0]!==o||t[1]!==l?(d=()=>{if(o&&u.current)return aT(u.current,l)},f=[o,l],t[0]=o,t[1]=l,t[2]=d,t[3]=f):(d=t[2],f=t[3]),Z.useEffect(d,f);let p;t[4]!==s||t[5]!==n.error?(p=n.error===`empty response`||n.error===`session.btw failed`?s(`chat.btw.failed`):n.error,t[4]=s,t[5]=n.error,t[6]=p):p=t[6];let m=p,h=!n.pending&&!n.error&&!n.answer,g;t[7]!==s||t[8]!==n.answer?(g=async()=>{let e=await Ea(n.answer);return e.ok||no.error(s(`filesView.toast.copyFailed`)),e.ok},t[7]=s,t[8]=n.answer,t[9]=g):g=t[9];let _=J(g),v=n.id,y;t[10]===n.quotes?y=t[11]:(y=n.quotes.map(AE),t[10]=n.quotes,t[11]=y);let b;t[12]===n.question?b=t[13]:(b=(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words typography-markdown text-foreground`,children:n.question}),t[12]=n.question,t[13]=b);let x;t[14]!==y||t[15]!==b?(x=(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:[y,b]}),t[14]=y,t[15]=b,t[16]=x):x=t[16];let S;t[17]!==s||t[18]!==n.pending?(S=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`}),s(`chat.btw.pending`)]}):null,t[17]=s,t[18]=n.pending,t[19]=S):S=t[19];let C;t[20]===m?C=t[21]:(C=m?(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`}),m]}):null,t[20]=m,t[21]=C);let w;t[22]!==h||t[23]!==s?(w=h?(0,$.jsx)(`p`,{role:`status`,className:`typography-meta text-muted-foreground`,children:s(`chat.btw.cancelled`)}):null,t[22]=h,t[23]=s,t[24]=w):w=t[24];let T;t[25]!==l||t[26]!==n.answer?(T=n.answer?(0,$.jsx)(`div`,{"data-speech-content":`true`,children:(0,$.jsx)(ic,{content:n.answer,messageId:l,isAnimated:!1,isStreaming:!1,variant:`assistant`,enableFileReferences:!1})}):null,t[25]=l,t[26]=n.answer,t[27]=T):T=t[27];let E;t[28]!==h||t[29]!==_||t[30]!==a||t[31]!==m||t[32]!==c||t[33]!==r||t[34]!==o||t[35]!==l||t[36]!==i||t[37]!==s||t[38]!==n.answer||t[39]!==n.completedAt||t[40]!==n.durationMs||t[41]!==n.pending?(E=!n.pending&&(n.answer||r&&(m||h))?(0,$.jsx)(bT,{messageId:l,isMobile:o,duration:n.answer&&typeof n.durationMs==`number`&&Number.isFinite(n.durationMs)&&n.durationMs>=0?NT(n.durationMs):null,timestamp:n.answer&&typeof n.completedAt==`number`&&n.completedAt>0?PT(n.completedAt):null,actions:(0,$.jsxs)($.Fragment,{children:[n.answer?(0,$.jsx)(xT,{messageId:l,hasCopyableText:!0,isTouchContext:c||o,onCopyMessage:_,ttsText:n.answer,allowSourceSession:!1}):null,r?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,onPointerDown:jE,onClick:()=>void fw.getState().retry({sessionId:i,directory:a}),"aria-label":s(`contextPanel.preview.actions.retry`),children:(0,$.jsx)(X,{name:`refresh`,weight:cT,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:s(`contextPanel.preview.actions.retry`)})]}):null]})}):null,t[28]=h,t[29]=_,t[30]=a,t[31]=m,t[32]=c,t[33]=r,t[34]=o,t[35]=l,t[36]=i,t[37]=s,t[38]=n.answer,t[39]=n.completedAt,t[40]=n.durationMs,t[41]=n.pending,t[42]=E):E=t[42];let D;t[43]!==l||t[44]!==T||t[45]!==E?(D=(0,$.jsxs)(`div`,{ref:u,"data-message-id":l,"data-message-text-export-root":`true`,"data-speech-identity":l,...IT,className:`min-w-0 text-foreground yuri-message-hover-scope`,children:[T,E]}),t[43]=l,t[44]=T,t[45]=E,t[46]=D):D=t[46];let O;return t[47]!==C||t[48]!==w||t[49]!==D||t[50]!==x||t[51]!==S||t[52]!==n.id?(O=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-btw-turn":v,children:[x,S,C,w,D]}),t[47]=C,t[48]=w,t[49]=D,t[50]=x,t[51]=S,t[52]=n.id,t[53]=O):O=t[53],O});function CE(e){let t=(0,Q.c)(64),{scope:n,pending:r,quotes:i,foot:a}=e,{t:o}=fr(),s;t[0]===n?s=t[1]:(s=e=>e.sendSelection[FC(n)],t[0]=n,t[1]=s);let c=fw(s),l;t[2]!==n||t[3]!==c?(l=c??nw(n),t[2]=n,t[3]=c,t[4]=l):l=t[4];let u=l,d=ei(wE),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=Ki(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(``),fw.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)(ll,{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=()=>fw.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:yE},t[35]=I):I=t[35];let L=C?xE:bE,R;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(R={borderTopLeftRadius:yE,borderTopRightRadius:yE},t[36]=R):R=t[36];let z;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(z={borderBottomLeftRadius:yE,borderBottomRightRadius:yE},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=>fw.getState().removeQuote(n,e),t[40]=n,t[41]=V);let H;t[42]!==i||t[43]!==B||t[44]!==V?(H=(0,$.jsx)(Oh,{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)(Nc,{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 wE(e){return e.providers}function TE(e){let t=(0,Q.c)(45),{scope:n,foot:r,active:i}=e,a=r===void 0?`panel`:r,o=i===void 0||i,{t:s}=fr(),c;t[0]===n?c=t[1]:(c=FC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===l?u=t[3]:(u=e=>(e.entries[l]??PC).turns,t[2]=l,t[3]=u);let d=fw(u),f;t[4]===l?f=t[5]:(f=e=>(e.entries[l]??PC).quotes,t[4]=l,t[5]=f);let p=fw(f),m;t[6]===d?m=t[7]:(m=d.some(EE),t[6]=d,t[7]=m);let h=m,g=`btw:${l}`,_=a!==`panel`,v;t[8]!==o||t[9]!==h||t[10]!==n.sessionId||t[11]!==g||t[12]!==_||t[13]!==d.length?(v={enabled:o,currentSessionId:n.sessionId,viewportKey:g,sessionMessageCount:d.length,sessionIsWorking:h,isMobile:_},t[8]=o,t[9]=h,t[10]=n.sessionId,t[11]=g,t[12]=_,t[13]=d.length,t[14]=v):v=t[14];let{scrollRef:y,notifyContentChange:b}=uE(v),x=d[d.length-1],S;t[15]===b?S=t[16]:(S=()=>{b(`structural`)},t[15]=b,t[16]=S);let C=x?.answer,w=x?.pending,T;t[17]!==b||t[18]!==C||t[19]!==w||t[20]!==d.length?(T=[d.length,C,w,b],t[17]=b,t[18]=C,t[19]=w,t[20]=d.length,t[21]=T):T=t[21],Z.useLayoutEffect(S,T);let E;t[22]===s?E=t[23]:(E=s(`chat.btw.title`),t[22]=s,t[23]=E);let D;t[24]!==a||t[25]!==n.directory||t[26]!==n.sessionId||t[27]!==s||t[28]!==d?(D=d.length===0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:s(`chat.btw.description`)}):d.map((e,t)=>(0,$.jsx)(SE,{turn:e,isLast:t===d.length-1,sessionId:n.sessionId,directory:n.directory,isMobile:a!==`panel`},e.id)),t[24]=a,t[25]=n.directory,t[26]=n.sessionId,t[27]=s,t[28]=d,t[29]=D):D=t[29];let O;t[30]===D?O=t[31]:(O=(0,$.jsx)(`div`,{className:`flex flex-col gap-5`,children:D}),t[30]=D,t[31]=O);let k;t[32]!==y||t[33]!==O?(k=(0,$.jsx)(`div`,{ref:y,"data-btw-transcript":!0,className:`overlay-scrollbar-container min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-3`,children:O}),t[32]=y,t[33]=O,t[34]=k):k=t[34];let A;t[35]!==a||t[36]!==l||t[37]!==h||t[38]!==p||t[39]!==n?(A=(0,$.jsx)(CE,{scope:n,pending:h,quotes:p,foot:a},l),t[35]=a,t[36]=l,t[37]=h,t[38]=p,t[39]=n,t[40]=A):A=t[40];let j;return t[41]!==E||t[42]!==k||t[43]!==A?(j=(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-col text-foreground`,"aria-label":E,children:[k,A]}),t[41]=E,t[42]=k,t[43]=A,t[44]=j):j=t[44],j}function EE(e){return e.pending}function DE(e){let t=(0,Q.c)(53),{scope:n,active:r,mobile:i}=e,{t:a}=fr(),{sessionId:o,directory:s}=n,c;t[0]===n?c=t[1]:(c=FC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===s?u=t[3]:(u=Xn(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=q(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(kE),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&&!_&&fw.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=()=>Ia({sessionId:o,directory:s??null});return!r&&!n()&&fw.getState().cancel(e),()=>{let r=fw.getState().entries[l];queueMicrotask(()=>{let i=S.current;i!==t&&i?.key===l&&i.active||n()||FC(e)===l&&fw.getState().entries[l]===r&&fw.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=()=>{fw.getState().clear(n),q.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){hE(_E);return}return mE(_E),OE},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)(TE,{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)(sc,{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 OE(){return hE(_E)}function kE(e){return e.mode===`btw`}function AE(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 jE(e){return e.stopPropagation()}var ME=()=>{typeof window>`u`||window.requestAnimationFrame(()=>{document.querySelector(`[data-btw-composer] textarea`)?.focus()})},NE=e=>{let t=e.directory??null;Ca({sessionId:e.sessionId,directory:t})?mE(gE):q.getState().openContextPanelTab(t??``,{mode:`btw`}),ME()},PE=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},FE=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()}},IE=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,LE=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&e.delivery!==`queue`&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand&&!e.nativeGoal,RE=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},zE=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),BE=(e,t)=>{let n=It.getState();return n.bindLegacyQueue(an(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},VE=async e=>{let t=Da.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=zE(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}BE(n,a)?r+=1:i+=1}catch{try{BE(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},HE=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),UE=e=>{let t=e.ctrlEnter&&e.canQueue&&e.primary&&e.sessionIsRunning;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`}},WE=e=>Object.prototype.hasOwnProperty.call(e,`permissions`)?e.permissions:e.permission,GE=e=>{let t=ms(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},KE=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>GE(WE(e)));let r=e.find(e=>e?.name===n);return!r||GE(WE(r))},qE=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)},JE=null,YE=new Set,XE=()=>{for(let e of YE)e()},ZE=e=>e===`chat`||e===`assistant`,QE=()=>JE,$E=e=>{JE!==e&&(JE=e,XE())},eD=e=>{JE&&(e&&JE.surfaceID!==e||(JE=null,XE()))},tD=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},nD=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}},rD=(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}),iD=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=rD(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=rD(e,`send`,i),o=by(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=rD(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=rD(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=rD(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:by(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>py(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=rD(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=rD(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},aD=(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)))},oD=(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},sD=(e,t)=>e.agents.some(e=>e.name===t),cD=(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},lD=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return cD(t,n,r,i)?i:void 0;if(a&&cD(t,n,r,a))return a},uD=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!oD(r,n.providerID,n.modelID))return null;let s=n.agent&&sD(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&sD(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&sD(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=lD({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}},dD=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=uD({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=uD({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&&sD(i,e)?e:s&&sD(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&oD(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&cD(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&&oD(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&cD(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&&oD(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&sD(i,o.agent)?o.agent:void 0)??(e&&sD(i,e)?e:s&&sD(i,s)?s:void 0),r=l.variant,c=r&&cD(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},fD=(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))},pD=(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}},mD=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,hD=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}:{}}},gD=e=>typeof e==`string`&&e.trim().length>0?e:void 0,_D=e=>gD(e.agent)??gD(e.mode),vD=e=>gD(typeof e.model==`object`?e.model?.variant:void 0)??gD(e.variant),yD=e=>{let t=typeof e.model==`object`?e.model:void 0,n=gD(e.providerID)??gD(t?.providerID),r=gD(e.modelID)??gD(t?.modelID)??gD(t?.id);return!n||!r?null:{providerID:n,modelID:r}},bD=e=>yD(e),xD=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=yD(n);return{id:typeof n.id==`string`?n.id:void 0,agent:_D(n),providerID:r?.providerID,modelID:r?.modelID,variant:vD(n)}}return null},SD=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(yD(n))return null;continue}if(n.role!==`assistant`)continue;let r=bD(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:_D(n),providerID:r.providerID,modelID:r.modelID,variant:vD(n)}}return null},CD=500,wD=e=>Array.from(e).length,TD=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},ED=e=>wD(e)>=CD,DD=e=>{let t=un(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},OD=(e,t)=>{let n=t??e;return typeof n!=`string`||!ED(n)?!1:$t(typeof e==`string`?{text:``,references:[]}:e,n)},kD=(e,t,n,r,i=1)=>{let a=wD(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}-${TD(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},AD=e=>({text:e?.text??``,references:e?.composerReferences??[]}),jD=e=>({text:e.text,references:e.references.map(e=>({...e}))}),MD=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),ND=e=>JSON.stringify([e.text,e.references]),PD=(e,t)=>e!==null&&t!==null&&nt(e)===t,FD=(e,t,n)=>{let r=e?MD(e):null,i=r?n(r):void 0;return{document:Lt(AD(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?nt(r):null}},ID=(e,t,n,r)=>{if(!t||nt(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=ND(AD(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===ND(e)?`same-document-metadata`:`external-document`},LD=(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}]:[]})},RD=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),zD=(e,t,n,r,i=r)=>{let a=K(e,n,r,i);return{document:a.document,mentions:LD(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},BD=(e,t,n)=>({preview:{real:jD(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),VD=e=>({document:e.real,mentions:e.realMentions}),HD=(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)})},UD=(e,t)=>{let n=AD(t),r=pn(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:HD(e.mentions,t?.mentions??[],r,i)}},WD=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=fi})=>{let a=e?nt(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)(()=>FD(e,t,i.getState().getDraft).document),[d,f]=(0,Z.useState)(()=>FD(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?MD(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)(yc());_.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=Se(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=FD(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=yc(),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||!PD(S.current,a)||w.current!==a||C.current!==a||T.current!==e||E.current!==r||o?.revision!==t.revision||(E.current=t.revision,A(Lt(AD(t),y.current),t.mentions))})}},[a,A,i]),(0,Z.useEffect)(()=>{if(!a||w.current!==a||O.current)return;let e=ID(_.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(Lt(AD(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(!PD(n,C.current)||O.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:RD(t)});if(!a)return;let o=AD(a);return D.current={keyID:nt(n),revision:a.revision,fingerprint:ND(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=Ec(k.current,{before:kc(e,t,n),after:kc(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=Bt(e.text,e.references);return n?M(Lt(n,y.current),t):void 0},[M,P]),L=(0,Z.useCallback)((e,t,n=t,r)=>{let i=P(),a=jD(_.current),o=i?[]:v.current,s=zD(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=K(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=LD(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=zt(_.current,e,t,n,r);return M(a.document,LD(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=jD(_.current),n=st(t,e);if(!n)return null;let r=P()?[]:v.current,i=LD(r,n.document,n.edit),a=Ot(n.document.text,n.caret),o=K(n.document,a.text,a.caret),s=LD(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`?bc(k.current,_.current):Ac(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:[]}:BD(_.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=VD(e);A(t.document,t.mentions),g(e=>e+1)},[A]),te=(0,Z.useCallback)(()=>{let e=S.current;if(!PD(e,C.current))return null;let t=i.getState().getDraft(e);return{key:MD(e),keyID:nt(e),revision:t?.revision??0,document:jD(_.current),mentions:v.current.map(e=>({...e,range:{...e.range}})),epoch:T.current,runtime:i.getState().captureDraftRuntime()}},[i]),G=(0,Z.useCallback)(e=>{let t=UD(e,i.getState().getDraft(e.key)),n=AD(i.getState().getDraft(e.key)),r=un(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:RD(t.mentions)});if(a){let e=AD(a);j(r,e)}return a},[j,i]),ne=(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:ne,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:G}),[L,R,te,U,V,l,W,ee,ne,s,p,B,d,c,G,I,F,z,H,h])};function GD(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 KD(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=GD({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 qD(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=GD({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=oc(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),ir(`resize`,m,h);let g;t[16]===o?g=t[17]:(g=()=>o?window:null,t[16]=o,t[17]=g),ir(`yuri:keyboard-settled`,m,g);let _;t[18]===o?_=t[19]:(_=()=>o?window.visualViewport:null,t[18]=o,t[19]=_),ir(`resize`,m,_);let v;t[20]===o?v=t[21]:(v=()=>o?window.visualViewport:null,t[20]=o,t[21]=v),ir(`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 JD=(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=qD(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)(cc,{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}),YD=.5,XD=`--yuri-mobile-composer-swap`,ZD=`--yuri-native-composer-dock`,QD=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),$D=(e,t,n)=>Math.min(n,Math.max(t,e)),eO=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,tO=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return eO(e,n)?e:n},nO=(e,t)=>t?tO(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?tO(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,rO=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:tO(e,{phase:`snapping`,rest:t,progress:n})},iO=e=>Math.round($D(e,0,1)*1e3)/1e3,aO=(e,t,n)=>{let r=n-t;if(r>=0)return iO(e+r/80);if(n<=2)return 0;if(n>=120)return e;let i=e+r/80,a=n/t*e;return iO(Math.min(i,a))},oO=(e,t)=>e>=1?`compact`:e<=0?`expanded`:t,sO=(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`?tO(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(r<=2)return tO(a,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn&&a.rest===`compact`&&r<i)return tO(a,{phase:`rest`,rest:`compact`,progress:1});let o=aO(a.progress,i,r);return e.phase===`snapping`&&o===a.progress?e:o===a.progress?a:Math.abs(o-a.progress)>=YD&&(o>=1||o<=0)?tO(a,{phase:`snapping`,rest:o>=1?`compact`:`expanded`,progress:o}):o>=1||o<=0?tO(a,{phase:`rest`,rest:oO(o,a.rest),progress:o}):tO(a,{phase:`tracking`,rest:a.rest,progress:o})},cO=(e,t=null)=>e.pinned?`expanded`:t||(e.progress>=.5?`compact`:`expanded`),lO=(e,t=null)=>{if(e.pinned)return tO(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let n=cO(e,t),r=+(n===`compact`);return e.phase===`rest`&&e.rest===n&&e.progress===r?e:tO(e,{phase:`snapping`,rest:n,progress:r})},uO=e=>e.phase===`snapping`?tO(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,dO=e=>$D(Math.max(0,e)/80,0,1),fO=(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:dO(n),rest:`bottom`}},pO=`--yuri-mobile-composer-occupancy`,mO=(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(pO,n),n},hO=(e,t)=>{t!==null&&e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)===t&&e.style.removeProperty(pO)},gO=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},_O=(e,t=e)=>{for(let n of new Set([e,t]))n.style.removeProperty(XD),n.style.removeProperty(ZD);delete e.dataset.yuriComposerSwapPhase,delete e.dataset.yuriComposerSwapRest,delete e.dataset.yuriNativeComposerDock},vO=(e,t,n,r=e)=>{let i=fO(t,n?.rest===`bottom`?`bottom`:`away`),a=String(i.progress),o=i.rest;return n?.progress!==a&&r.style.setProperty(ZD,a),n?.rest!==o&&(e.dataset.yuriNativeComposerDock=o),{progress:a,rest:o}},yO=(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(XD,i),n?.rest!==o&&(e.dataset.yuriComposerSwapRest=o),{progress:i,phase:a,rest:o}},bO=`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`,xO=ec(()=>Wn(()=>import(`./ToolOutputDialog-Bz23N8ob.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,77]))),SO=[],CO=[],wO=[],TO=/^@[^\s]+$/,EO=({inputMode:e,message:t,showCommandAutocomplete:n})=>e!==`shell`&&(n||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),DO=/^(https?:\/\/|mailto:)\S+$/i,OO=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),kO=(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)},AO=e=>e.includes(`@`)?`paste`:`manual`,jO=(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}},MO=(e,t)=>vt(e,t).some(e=>e.role===`user`),NO=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Or(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6547
|
-
`).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},PO=`file://`,FO=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(`/`)},IO=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(PO)?t:`file://${FO(t)}`},LO=e=>{if(!e)return[];let t=[...cC(e).map(lC),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(uC)))},RO=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},zO=e=>Wi(e.path),BO=(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)]})},VO=e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?IO(e.serverPath):e.dataUrl})),HO=(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}},UO=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 cC(e).length>0},WO=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)},GO=e=>{let t=e.icon?Sd[e.icon]:null,n=e.color?Td[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:`relative top-px flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-muted-foreground`,children:e.iconImage?(0,$.jsx)(_d,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:zO(e)})]})},KO=Z.memo(By),qO=Z.memo(Vm),JO=(0,$.jsx)(`span`,{"data-yuri-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`}),YO=Z.memo(Jm),XO=Z.memo(hx),ZO=Z.memo(vx),QO=Z.memo(nx),$O=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=fr(),r=q(e=>e.isMobile),i=Wa(e=>e.revertToMessage),a=Wa(e=>e.forkFromMessage),o=Wa(e=>e.handleSlashRedo),[s,c]=Z.useState(null),[l,u]=Z.useState(null),[d,f]=Z.useState(!0),p=Z.useRef(ZS),m=ia(),h=t||m,g=Di(h),_=Mt(e??``,h,g),v=Fi(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=eC({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 ft(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:NO(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)($r,{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)($r,{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))})]})})});$O.displayName=`RevertedMessageDock`;function ek({projects:e,query:t,renderLabel:n,onSelect:r,selectedId:i}){return e.filter(e=>bd(zO(e),t)||bd(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)(dl,{value:e.id,className:`max-w-[24rem] truncate`,children:n(e)},e.id))}var tk=Z.memo(function(e){let t=(0,Q.c)(42),{t:n}=fr(),{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?fk:void 0,v=f?pk: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)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:C}),(0,$.jsx)(ts,{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),nk=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=fr(),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=()=>qE({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)(es,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:mk,onPointerDownCapture:hk,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)(ts,{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)(ns,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),rk=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}=fr(),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=Ax({canSend:l,hasSessionTarget:!!(p||m),draftSubmitting:!!h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:gk,onPointerDownCapture:_k}:{},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&&(!n||!f),P=!N&&(!e.sendDisabled||d),F;t[30]!==n||t[31]!==b?(F=e=>{n&&(e.preventDefault(),b())},t[30]=n,t[31]=b,t[32]=F):F=t[32];let I;t[33]!==d||t[34]!==x||t[35]!==A||t[36]!==N||t[37]!==C?(I=C(A||!N&&d?x?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[33]=d,t[34]=x,t[35]=A,t[36]=N,t[37]=C,t[38]=I):I=t[38];let L;t[39]!==E||t[40]!==d||t[41]!==s||t[42]!==P||t[43]!==N?(L=P?(0,$.jsx)(gc,{className:E,spinning:!!(d&&!N)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[39]=E,t[40]=d,t[41]=s,t[42]=P,t[43]=N,t[44]=L):L=t[44];let R=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":P?`true`:void 0,disabled:e.sendDisabled,"aria-busy":d||void 0,...u,onClick:F,className:Y(P?T:i,P?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":I,children:L});if(!N){k=R;break bb0}let z=!n&&!S&&(f||x),B=!e.sendDisabled&&!x,V=S&&`h-full`;t[45]===V?D=t[46]:(D=Y(`relative z-30 overflow-visible`,V),t[45]=V,t[46]=D),O=z?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":B||x?`true`:void 0,disabled:e.sendDisabled||x,"aria-busy":x||void 0,...u,onClick:e=>{e.preventDefault(),!x&&b()},className:Y(B||x?T:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,B||x?void 0:e.disabledClass),"aria-label":M,children:B||x?(0,$.jsx)(gc,{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)(gc,{className:E,spinning:!0}):(0,$.jsx)(uc,{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),ik=(e,t)=>`${e}${e?e.endsWith(`
|
|
6546
|
+
`);if(e>0&&e<=280){t.push(n.slice(0,e).trim()),n=n.slice(e).trimStart();continue}if(n.length<=280){t.push(n);break}let r=[...n.slice(0,280).matchAll(/[。!?.!?;;\n](?:[”’"')\]]*)\s*|\s+/gu)].reverse().find(e=>e.index>=80),i=r?r.index+r[0].length:280;/[\uD800-\uDBFF]/u.test(n[i-1])&&--i,t.push(n.slice(0,i).trim()),n=n.slice(i).trimStart()}return t}function Cw(e){let t=null,n=null,r=null,i=[],a=()=>{for(let e of i)e.removeAttribute(`data-speech-marker-inline-code`);i=[]},o=()=>{let r=Array.from(t?.getClientRects?.()??[]).filter(e=>e.width>0&&e.height>0).sort((e,t)=>e.top-t.top||e.left-t.left);if(r.length===0){for(let e of i)e.removeAttribute(`data-speech-marker-inline-code`);n?.replaceChildren();return}for(let e of i)e.hasAttribute(`data-speech-marker-inline-code`)||e.setAttribute(`data-speech-marker-inline-code`,`true`);let a=e.getBoundingClientRect(),o=getComputedStyle(t?.startContainer.parentElement??e).fontSize,s=[];for(let e of r){let t=s.find(t=>Math.min(t.bottom,e.bottom)-Math.max(t.top,e.top)>=Math.min(t.bottom-t.top,e.height)/2&&e.left<=t.right+1&&e.right>=t.left-1);t?(t.left=Math.min(t.left,e.left),t.right=Math.max(t.right,e.right),t.top=Math.min(t.top,e.top),t.bottom=Math.max(t.bottom,e.bottom)):s.push({left:e.left,right:e.right,top:e.top,bottom:e.bottom})}n||(n=document.createElement(`span`),n.className=`yuri-speech-marker-layer`,n.setAttribute(`aria-hidden`,`true`),e.setAttribute(`data-speech-marker-owner`,`true`),e.append(n)),n.style.fontSize=o;let c=s.map(t=>{let n=document.createElement(`span`);return n.className=`yuri-speech-marker-stroke`,n.style.left=`${t.left-a.left-e.clientLeft+e.scrollLeft}px`,n.style.top=`${t.top-a.top-e.clientTop+e.scrollTop}px`,n.style.width=`${t.right-t.left}px`,n.style.height=`${t.bottom-t.top}px`,n});n.replaceChildren(...c)};return{update(n){t=n;let a=[];if(t){let n=t,r=n.commonAncestorContainer,i=r instanceof Element?r:r.parentElement,o=i?.closest(`code, .inline-code`);a=(o?[o]:Array.from(i?.querySelectorAll(`code, .inline-code`)??[])).filter(t=>e.contains(t)&&!t.closest(`pre`)&&n.intersectsNode(t))}for(let e of i)a.includes(e)||e.removeAttribute(`data-speech-marker-inline-code`);i=a,o(),t&&!r&&typeof ResizeObserver<`u`&&(r=new ResizeObserver(o),r.observe(e))},stop(){r?.disconnect(),r=null,t=null,a(),n?.remove(),n=null,e.removeAttribute(`data-speech-marker-owner`)}}}var ww=null,Tw=null,Ew=null,Dw=new Set,Ow=()=>ww,kw=()=>ww?.target??null,Aw=e=>(Dw.add(e),()=>{Dw.delete(e)}),jw=()=>{for(let e of Dw)e()};function Mw(e){!ww?.following||!e.contains(ww.target)||(ww={...ww,following:!1},jw())}function Nw(){ww&&(ww={...ww,following:!0},jw())}var Pw=e=>e.replace(/[^\p{L}\p{N}]/gu,``).toLowerCase();function Fw(e,t=``,n=!0){Ew?.();let r=Symbol(`speech`);Tw=r;let i=[],a=``,o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(;o.nextNode();){let e=o.currentNode;if(!e.parentElement?.closest(`[data-speech-content]`)||e.parentElement?.closest(`button, [aria-hidden="true"], [data-message-actions], [data-message-footer]`)||n&&e.parentElement?.closest(`pre`))continue;let t=e.data,r=n?[...t.matchAll(/https?:\/\/[^\s]+|(?:^|\s)\/(?:[\w.-]+\/)*[\w.-]+/g)]:[],s=0;for(let n=0;n<t.length;){let o=r[s];if(o&&n>=o.index){n=o.index+o[0].length,s++;continue}let c=String.fromCodePoint(t.codePointAt(n)),l=Pw(c);for(let t=0;t<l.length;t++)i.push({node:e,offset:n});a+=l,n+=c.length}}let s=Pw(t),c=s?a.indexOf(s):-1,l=c>=0?c+s.length:0,u=-1,d=null,f=Cw(e),p=()=>{f.stop(),typeof CSS<`u`&&CSS.highlights&&CSS.highlights.delete(`yuri-speech`),d?.removeAttribute(`data-speech-active`),d=null};return Ew=p,ww={target:e,range:null,following:!0},jw(),{update(e,t){if(Tw!==r||!ww||t===u)return;u=t;let n=Pw(e),o=n?a.indexOf(n,l):-1,s=null;if(o>=0){let e=i[o],t=i[o+n.length-1];s=document.createRange(),s.setStart(e.node,e.offset),s.setEnd(t.node,t.offset+(t.node.data.codePointAt(t.offset)>65535?2:1)),l=o+n.length}f.update(s),typeof CSS<`u`&&CSS.highlights&&typeof Highlight<`u`?(CSS.highlights.delete(`yuri-speech`),s&&CSS.highlights.set(`yuri-speech`,new Highlight(s))):(d?.removeAttribute(`data-speech-active`),d=s?.startContainer.parentElement?.closest(`p, li, h1, h2, h3, h4, blockquote, [data-speech-content]`)??null,d?.setAttribute(`data-speech-active`,`true`)),ww={...ww,range:s},jw()},stop(){Tw===r&&(p(),Ew=null,ww=null,Tw=null,jw())}}}var Iw=600,Lw=null,Rw=null,zw=`Summarize the assistant reply for text-to-speech listening. Reply with 2-4 sentences of plain spoken prose in the same language as the reply. No markdown, no lists, no code — mention code changes briefly in words instead.`;async function Bw(e,t){try{let n=await g(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:zw,...t.providerID?{preferredProviderID:t.providerID}:{},...t.modelID?{preferredModelID:t.modelID}:{}})});if(!n.ok)return null;let r=await n.json().catch(()=>null);return typeof r?.text==`string`&&r.text.trim()?r.text.trim():null}catch{return null}}function Vw(e={}){let[t,n]=(0,Z.useState)(!1),r=(0,Z.useRef)(0),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),l=ei(e=>e.voiceProvider),u=ei(e=>e.speechRate),d=ei(e=>e.speechPitch),f=ei(e=>e.speechVolume),p=ei(e=>e.browserVoice),m=ei(e=>e.showMessageTTSButtons),h=ei(e=>e.ttsInputMode),g=l===`openai`||l===`openai-compatible`||l===`volcengine`,_=(e.enabled??m)&&l===`say`,{speak:v,stop:y,unlockAudio:b}=Xd({enabled:!1}),{speak:x,stop:S,unlockAudio:C,isAvailable:w}=bw({enabled:_}),{speak:T,stop:E,unlockAudio:D}=qd(),O=J((e,t)=>{let n=t?.dataset.speechIdentity,r=(n&&Rw?.identity===n?Rw:null)??i.current;return r?.text===e&&r.mode===h&&r.provider===l&&r.identity===n&&r.index<r.chunks.length?r:null}),k=J((e,t)=>O(e,t)!==null),A=J(()=>{Lw===A&&i.current&&i.current.index<i.current.chunks.length&&(Rw=i.current),r.current+=1,a.current!==null&&clearTimeout(a.current),o.current!==null&&clearTimeout(o.current),a.current=null,o.current=null,s.current?.stop(),s.current=null,n(!1),y(),S(),E(),Lw===A&&(Lw=null,Jd.cancelSpeech())});ir(`keydown`,e=>{e.key!==`Escape`||e.isComposing||!t||(e.preventDefault(),e.stopPropagation(),A())},()=>t?window:null,{capture:!0}),(0,Z.useEffect)(()=>Ul(A),[A]),(0,Z.useEffect)(()=>c(()=>{A(),i.current=null,Rw=null}),[A]);let j=J(async()=>{let e=l===`local`?D:l===`say`?C:g?b:null;await Promise.all([e?.(),Jd.resumeAudioContext()])});return(0,Z.useEffect)(()=>()=>{Lw===A?A():r.current+=1},[A]),{isPlaying:t,play:J(async(e,t,c)=>{if(!e.trim()){t?.();return}Lw?.(),A(),Lw=A;let m=r.current,_=!1,b=e=>{m!==r.current||_||(_=!0,o.current!==null&&clearTimeout(o.current),o.current=null,s.current?.stop(),s.current=null,Lw===A&&(Lw=null),e?(Rw=i.current,y(),S(),E(),Jd.cancelSpeech()):(Rw===i.current&&(Rw=null),i.current=null),n(!1),t?.(e))};n(!0);try{let t=c?.target?.dataset.speechIdentity,n=c?.restart?null:O(e,c?.target),C=n!==null,D=e;if(!C&&h===`summarized`&&e.length>=Iw){let{currentProviderId:t,currentModelId:n}=ei.getState(),r=await Bw(e,{providerID:t||void 0,modelID:n||void 0});r&&(D=r)}if(m!==r.current)return;let k=h===`raw`&&g,A=xw(D,D.length>280),j=k?D:A;if(!j.trim()){b();return}let M=C?n:{text:e,mode:h,provider:l,identity:t,chunks:g?[j.trim()]:Sw(j),index:0,offset:0,audioKey:{}};if(i.current=M,Rw?.identity===t&&Rw?.text===e&&(Rw=null),c?.target){let e=c.target.querySelectorAll(`[data-speech-content]`),t=h===`final`?e[e.length-1]??c.target:c.target,n=g?M.chunks[0].slice(0,M.offset):M.chunks.slice(0,M.index).join(` `);s.current=Fw(t,n,!k)}let N=async(e=0)=>{if(m!==r.current||_)return;let t=M.chunks[M.index];if(!t){b();return}let n=!1,i=()=>{o.current!==null&&clearTimeout(o.current),o.current=null},c=()=>{n||m!==r.current||g||s.current?.update(t,M.index)},h=()=>{n||m!==r.current||(n=!0,i(),M.index+=1,M.index===M.chunks.length?b():N())},D=t=>{if(!(n||m!==r.current)){if(n=!0,i(),/not.allowed|autoplay|blocked|not supported|unsupported|HTTP 4\d\d|API.key|unauthorized|forbidden|invalid|no text/i.test(t)||e>=2){b(Error(t));return}y(),S(),E(),Jd.cancelSpeech(),a.current=setTimeout(()=>{a.current=null,N(e+1)},600*(e+1))}};o.current=setTimeout(()=>D(`Speech playback stalled`),Math.max(45e3,t.length*500/Math.max(u||1,.1)));try{let i={onStart:c,onEnd:h,onError:D};if(g)await v(t,{...i,playbackKey:M.audioKey,resume:C||e>0,resumeOffset:M.offset,onProgress:e=>{n||m!==r.current||e.start<M.offset||(M.offset=e.start,s.current?.update(e.text,e.start))}});else if(l===`local`)await T(t,i);else if(l===`say`&&w)await x(t,i);else{if(await Jd.waitForVoices(),await Jd.resumeAudioContext(),m!==r.current)return;await Jd.speakText(t,navigator.language||`en-US`,h,{rate:u,pitch:d,volume:f,voiceName:p||void 0,onStart:c,onError:D})}}catch(e){D(e instanceof Error?e.message:String(e))}};await N()}catch(e){console.error(`[useMessageTTS] Playback error:`,e),b(e instanceof Error?e:Error(String(e)))}}),canResume:k,stop:A,unlock:j}}var Hw=(0,Z.createContext)(null),Uw=(0,Z.createContext)(null);function Ww(e){let t=(0,Q.c)(10),{sessionId:n,messageId:r,created:i,text:a,completed:o,streaming:s,targetRef:c}=e,l=s!==void 0&&s,u=(0,Z.useContext)(Hw),d,f;t[0]!==o||t[1]!==u||t[2]!==i||t[3]!==r||t[4]!==n||t[5]!==l||t[6]!==c||t[7]!==a?(d=()=>{if(!u?.enabled||(l&&u.streaming(n,r),!o))return;let e=0,t=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>u.rendered({sessionId:n,messageId:r,created:i,text:a,target:c?.current??void 0}))});return()=>{cancelAnimationFrame(t),cancelAnimationFrame(e)}},f=[u,n,r,i,a,o,l,c],t[0]=o,t[1]=u,t[2]=i,t[3]=r,t[4]=n,t[5]=l,t[6]=c,t[7]=a,t[8]=d,t[9]=f):(d=t[8],f=t[9]),(0,Z.useEffect)(d,f)}var Gw=144,Kw=null,qw=new Set,Jw=!1,Yw=null;function Xw(){for(let e of qw)e()}function Zw(){return Kw}function Qw(){return Yw}function $w(e){return qw.add(e),()=>{qw.delete(e)}}function eT(e,t){let n=Z.useSyncExternalStore($w,Zw,Qw);return t&&n===e}function tT(e){!e||Kw===e||(Kw=e,Xw())}function nT(e){Kw!==null&&(e&&Kw!==e||(Kw=null,Xw()))}function rT(e){return e instanceof Element?e.closest(`[data-message-id]`)?.getAttribute(`data-message-id`)??null:null}function iT(){Jw||typeof document>`u`||(Jw=!0,document.addEventListener(`pointerdown`,e=>{Kw&&rT(e.target)!==Kw&&nT()},!0))}function aT(e,t){iT();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>Gw||tT(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),nT(t)}}var oT=`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`,sT=`size-3.5!`,cT=`medium`,lT=`flex items-center gap-2`,uT={containerType:`inline-size`,containerName:`message-footer`},dT=`${lT} -ml-[5px]`,fT=`mt-2.5 mb-3 flex flex-wrap items-center gap-3`,pT=`mt-1.5 mb-2 flex flex-wrap items-center gap-3`,mT=`flex w-max max-w-full flex-none flex-wrap items-center gap-2 text-muted-foreground`,hT=`h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,gT=`inline-flex ${hT}`,_T=`size-3.5!`,vT=e=>{let t=(0,Q.c)(6),{messageId:n,label:r,focusReveal:i}=e,a=eT(n,i),o=i?a?`inline-flex`:`hidden`:`hidden yuri-message-hover-time`,s;t[0]===o?s=t[1]:(s=Y(hT,`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},yT=e=>{let t=(0,Q.c)(16),{label:n}=e,{t:r}=fr(),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:cT,name:`pulse`,className:_T}),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)(es,{asChild:!0,children:(0,$.jsxs)(`span`,{className:gT,"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)(ts,{children:c}),t[11]=c,t[12]=l);let u;return t[13]!==s||t[14]!==l?(u=(0,$.jsxs)(ns,{children:[s,l]}),t[13]=s,t[14]=l,t[15]=u):u=t[15],u},bT=Z.memo(function(e){let t=(0,Q.c)(14),{messageId:n,isMobile:r,actions:i,tps:a,duration:o,timestamp:s,activity:c,trailing:l}=e,u=r?pT:fT,d;t[0]===i?d=t[1]:(d=i?(0,$.jsx)(`div`,{className:dT,"data-message-action-group":`true`,children:i}):null,t[0]=i,t[1]=d);let f;t[2]!==c||t[3]!==o||t[4]!==r||t[5]!==n||t[6]!==s||t[7]!==a?(f=a||o||s||c?(0,$.jsxs)(`div`,{className:mT,children:[a||o?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 whitespace-nowrap`,children:[a?(0,$.jsx)(yT,{label:a}):null,o?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsxs)(`span`,{className:gT,children:[(0,$.jsx)(X,{weight:cT,name:`hourglass`,className:_T}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:o})]})}),(0,$.jsx)(ts,{children:o})]}):null]}):null,c,s?(0,$.jsx)(vT,{messageId:n,label:s,focusReveal:r}):null]}):null,t[2]=c,t[3]=o,t[4]=r,t[5]=n,t[6]=s,t[7]=a,t[8]=f):f=t[8];let p;return t[9]!==u||t[10]!==d||t[11]!==f||t[12]!==l?(p=(0,$.jsxs)(`div`,{className:u,"data-message-footer":`true`,style:uT,children:[d,f,l]}),t[9]=u,t[10]=d,t[11]=f,t[12]=l,t[13]=p):p=t[13],p}),xT=Z.memo(e=>{let t=(0,Q.c)(73),{messageId:n,hasCopyableText:r,isTouchContext:i,onCopyMessage:a,ttsText:o,sessionId:s,allowSourceSession:c}=e,l=c===void 0||c,{t:u}=fr(),d=mx(),f=Zb(),p;t[0]===f?p=t[1]:(p=Qb(f),t[0]=f,t[1]=p);let m=p,{isPlaying:h,play:g,stop:_,canResume:v}=Vw(),y=Z.useContext(Uw),b=!!(y&&y.sessionId===s&&y.messageId===n),x=h||b,S=ei(ST),C=ei(CT),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useRef(null),M=Z.useRef(null),N=!!a,P=f.sessionId||s,F=!!(l&&P&&f.directory&&m.openSourceSession&&d!==`mini-chat`),I;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(I=()=>{j.current!==null&&typeof window<`u`&&(window.clearTimeout(j.current),j.current=null)},t[2]=I):I=t[2];let L=J(I),R;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>{M.current!==null&&typeof window<`u`&&(window.clearTimeout(M.current),M.current=null)},t[3]=R):R=t[3];let z=J(R),B,V;t[4]!==z||t[5]!==L?(B=()=>()=>{L(),z()},V=[z,L],t[4]=z,t[5]=L,t[6]=B,t[7]=V):(B=t[6],V=t[7]),Z.useEffect(B,V);let H,U;t[8]!==N||t[9]!==z||t[10]!==L||t[11]!==r?(H=()=>{(!r||!N)&&(T(!1),D(!1),L(),z())},U=[N,z,L,r],t[8]=N,t[9]=z,t[10]=L,t[11]=r,t[12]=H,t[13]=U):(H=t[12],U=t[13]),Z.useEffect(H,U);let W;t[14]!==N||t[15]!==L||t[16]!==r||t[17]!==i?(W=()=>{!i||!N||!r||typeof window>`u`||(L(),T(!0),j.current=window.setTimeout(()=>{T(!1),j.current=null},1800))},t[14]=N,t[15]=L,t[16]=r,t[17]=i,t[18]=W):W=t[18];let ee=J(W),te;t[19]!==z||t[20]!==r||t[21]!==i||t[22]!==a||t[23]!==ee?(te=async e=>{!a||!r||(e.stopPropagation(),e.preventDefault(),await a()!==!1&&(z(),D(!0),typeof window<`u`&&(M.current=window.setTimeout(()=>{D(!1),M.current=null},2e3)),i&&ee()))},t[19]=z,t[20]=r,t[21]=i,t[22]=a,t[23]=ee,t[24]=te):te=t[24];let G=J(te),ne;t[25]!==l||t[26]!==s||t[27]!==f?(ne=e=>{e.stopPropagation(),e.preventDefault();let t=f.sessionId||s;!l||!t||!f.directory||!f.openSourceSession||f.openSourceSession(t,f.directory)},t[25]=l,t[26]=s,t[27]=f,t[28]=ne):ne=t[28];let re=J(ne),ie;bb0:{if(x){let e;t[29]===u?e=t[30]:(e=u(`chat.messageBody.tts.stopSpeaking`),t[29]=u,t[30]=e),ie=e;break bb0}let e=C===`browser`?`Browser`:C===`openai`?`OpenAI`:C===`openai-compatible`?`Custom`:`Say`,n;t[31]!==e||t[32]!==u?(n=u(`chat.messageBody.tts.readAloudWithProvider`,{provider:e}),t[31]=e,t[32]=u,t[33]=n):n=t[33],ie=n}let ae=ie,oe;t[34]!==g||t[35]!==u||t[36]!==o?(oe=e=>{let t=e!==void 0&&e;if(k(!1),!o.trim())return;let n=A.current?.closest(`[data-message-text-export-root]`)??void 0;g(o,e=>{e&&$n.error(u(`chat.messageBody.tts.failed`))},{target:n,restart:t})},t[34]=g,t[35]=u,t[36]=o,t[37]=oe):oe=t[37];let se=J(oe),ce;t[38]!==y||t[39]!==v||t[40]!==b||t[41]!==x||t[42]!==se||t[43]!==_||t[44]!==o?(ce=(e,t)=>{if(!e){k(!1);return}if(x){t.cancel(),b&&y?.stop(),_();return}let n=A.current?.closest(`[data-message-text-export-root]`)??void 0;if(v(o,n)){k(!0);return}t.cancel(),se()},t[38]=y,t[39]=v,t[40]=b,t[41]=x,t[42]=se,t[43]=_,t[44]=o,t[45]=ce):ce=t[45];let le=J(ce),ue;t[46]!==w||t[47]!==G||t[48]!==r||t[49]!==E||t[50]!==a||t[51]!==u?(ue=a&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":w||E?`true`:void 0,className:Y(`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`,!r&&`opacity-50`),disabled:!r,"aria-label":u(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!r,onPointerDown:wT,onClick:e=>{G(e)},onFocus:()=>{r&&T(!0)},onBlur:()=>{E||T(!1)},children:E?(0,$.jsx)(X,{weight:`medium`,name:`check`,className:Y(`size-3.5!`,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:`medium`,name:`file-copy`,className:`size-3.5!`})})}),(0,$.jsx)(ts,{sideOffset:6,children:u(`chat.messageBody.actions.copyAnswer`)})]}),t[46]=w,t[47]=G,t[48]=r,t[49]=E,t[50]=a,t[51]=u,t[52]=ue):ue=t[52];let de;t[53]!==F||t[54]!==re||t[55]!==u?(de=F?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,"aria-label":u(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:TT,onClick:re,children:(0,$.jsx)(X,{weight:cT,name:`target`,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:u(`chat.messageBody.actions.openSourceSession`)})]}):null,t[53]=F,t[54]=re,t[55]=u,t[56]=de):de=t[56];let fe;t[57]!==d||t[58]!==le||t[59]!==r||t[60]!==x||t[61]!==i||t[62]!==ae||t[63]!==S||t[64]!==se||t[65]!==u||t[66]!==O||t[67]!==o?(fe=d!==`mini-chat`&&S&&r&&o.trim()&&(0,$.jsxs)(bs,{open:O&&!x,onOpenChange:le,modal:!1,children:[(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)(xs,{asChild:!0,children:(0,$.jsx)($r,{ref:A,type:`button`,variant:`ghost`,size:`icon`,className:Y(`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`,`!bg-transparent shadow-none`,x?`text-[var(--primary-base)]`:`hover:text-foreground/80`),"aria-label":u(x?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),"aria-pressed":x,onPointerDown:ET,onClick:DT,children:(0,$.jsx)(qm,{kind:`speaker`,active:x,className:`size-3.5!`})})})}),(0,$.jsx)(ts,{sideOffset:6,children:ae})]}),(0,$.jsxs)(ls,{side:`top`,align:`start`,sideOffset:6,onClick:OT,children:[(0,$.jsxs)(fs,{className:i?`min-h-11 px-3`:void 0,onSelect:()=>se(!1),children:[(0,$.jsx)(X,{name:`play`,weight:`medium`,className:`size-4`}),u(`chat.messageBody.tts.resume`)]}),(0,$.jsxs)(fs,{className:i?`min-h-11 px-3`:void 0,onSelect:()=>se(!0),children:[(0,$.jsx)(X,{name:`restart`,weight:`medium`,className:`size-4`}),u(`chat.messageBody.tts.restart`)]})]})]}),t[57]=d,t[58]=le,t[59]=r,t[60]=x,t[61]=i,t[62]=ae,t[63]=S,t[64]=se,t[65]=u,t[66]=O,t[67]=o,t[68]=fe):fe=t[68];let pe;return t[69]!==ue||t[70]!==de||t[71]!==fe?(pe=(0,$.jsxs)($.Fragment,{children:[ue,de,fe]}),t[69]=ue,t[70]=de,t[71]=fe,t[72]=pe):pe=t[72],pe});function ST(e){return e.showMessageTTSButtons}function CT(e){return e.voiceProvider}function wT(e){return e.stopPropagation()}function TT(e){return e.stopPropagation()}function ET(e){return e.stopPropagation()}function DT(e){return e.stopPropagation()}function OT(e){return e.stopPropagation()}var kT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),AT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),kT(e,n)},jT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),MT=e=>String(e).padStart(2,`0`),NT=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(` `)},PT=e=>{if(!jT(e))return``;let t=new Date(e);return`${t.getFullYear()}-${MT(t.getMonth()+1)}-${MT(t.getDate())} ${MT(t.getHours())}:${MT(t.getMinutes())}`},FT=(e,t)=>{if(!jT(e))return``;let n=new Date(e),r=new Date,i=ds(n,t),a=lr(),o=pr.getState().dictionary;if(kT(n,r))return i;if(AT(n,r))return mr(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}`},IT={onPointerEnter:e=>{e.pointerType!==`touch`&&e.currentTarget.setAttribute(`data-message-hovered`,``)},onPointerLeave:e=>{e.currentTarget.removeAttribute(`data-message-hovered`)},onPointerCancel:e=>{e.currentTarget.removeAttribute(`data-message-hovered`)}},LT=class e{static instance;sessionStartTimes=new Map;seenMessageIds=new Set;messageCreationTimes=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}recordSessionStart(e){this.sessionStartTimes.set(e,Date.now())}getSessionStartTime(e){return this.sessionStartTimes.get(e)}shouldAnimateMessage(e,t){if(e.role!==`assistant`||this.seenMessageIds.has(e.id))return!1;let n=this.sessionStartTimes.get(t);if(!n)return this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created),!1;let r=e.time.created>n-5e3;return r||(this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created)),r}clearSession(e){this.sessionStartTimes.delete(e)}hasSessionTiming(e){return this.sessionStartTimes.has(e)}hasBeenAnimated(e){return this.seenMessageIds.has(e)}markMessageAsAnimated(e,t){this.seenMessageIds.add(e),this.messageCreationTimes.set(e,t)}clearAll(){this.sessionStartTimes.clear(),this.seenMessageIds.clear(),this.messageCreationTimes.clear()}getDebugInfo(){return{sessionStartTimes:new Map(this.sessionStartTimes),seenMessageIds:new Set(this.seenMessageIds),messageCreationTimes:new Map(this.messageCreationTimes)}}},RT=100,zT=(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},BT=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=!0,d=new Map,f=[],p=()=>{c===void 0&&(c=t(()=>{c=void 0,h()}))},m=()=>{let e=a;if(!e){f=[],u=!1;return}let t=e.getBoundingClientRect().top;f=[...d].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),f.sort((e,t)=>e.top-t.top),u=!1},h=()=>{let t=a;if(!t)return;u&&m();let n=zT(f,t.scrollTop+RT);!n||n===l||(l=n,e.onActive(n))},g=()=>{let e=a;if(e){if(o?.disconnect(),o=void 0,r){o=new r(()=>{m(),p()}),o.observe(e);for(let e of d.values())o.observe(e)}if(s?.disconnect(),s=void 0,i&&!r){s=new i(()=>{u=!0,p()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}u=!0,p()}},_=e=>{a!==e&&(a=e,l=void 0,g())},v=(e,t)=>{let n=d.get(t);n&&n!==e&&o?.unobserve(n),d.set(t,e),o&&o.observe(e),u=!0,p()},y=e=>{let t=d.get(e);t&&(o?.unobserve(t),d.delete(e),u=!0,p())},b=()=>{u=!0,p()},x=()=>{for(let e of d.values())o?.unobserve(e);d.clear(),f=[],l=void 0,u=!0};return{setContainer:_,register:v,unregister:y,onScroll:p,markDirty:b,clear:x,destroy:()=>{c!==void 0&&n(c),c=void 0,x(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>l}},VT=10,HT=`${VT}vh`,UT=`56px`;`${UT}`;var WT=(e,t)=>e?56:t<=0?96:Math.max(48,VT/100*t),GT=(e,t)=>({sessionId:e,viewportKey:t}),KT=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,qT=(e,t)=>KT(e,t),JT=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),YT=150,XT=1500,ZT=2,QT=350,$T=600,eE=8e3,tE=24,nE=2,rE=(e,t)=>e<t,iE=()=>typeof performance<`u`?performance.now():Date.now(),aE=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),oE=e=>e.scrollHeight-e.scrollTop-e.clientHeight,sE=e=>oE(aE(e)),cE=e=>e.scrollHeight-e.clientHeight>1,lE=(e,t)=>oE(e)<=WT(t,e.clientHeight),uE=({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(GT(n,r));w.current=GT(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(null),P=Z.useRef(!1),F=Z.useRef(null),I=Z.useRef(0),L=Z.useRef(!1),R=Z.useRef(null),z=Z.useRef(null),B=J(()=>{I.current=iE()+450,z.current=null}),V=Z.useRef(0),H=Z.useRef(!1),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(0),te=Z.useRef(!1),G=Z.useRef(null),ne=Z.useRef(null),re=Z.useRef(null),ie=bi(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{l.current!==f.current&&(f.current=l.current,d(l.current))});let ae=J(e=>{x.current!==e&&(x.current=e,m(e))}),oe=J(e=>{E.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:iE()},D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{E.current=null,D.current=null},XT)}),se=J(e=>{let t=E.current;return t?iE()-t.time>XT?(E.current=null,!1):Math.abs(e.scrollTop-t.top)<ZT:!1}),ce=J(()=>iE()<j.current),le=J(()=>{H.current=!1,U.current&&=(clearTimeout(U.current),null),W.current&&=(clearTimeout(W.current),null)}),ue=J(()=>{U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{U.current=null,le()},$T)}),de=J(()=>{let e=l.current;e&&(H.current=!0,ee.current=e.scrollHeight,ue(),W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{W.current=null,le()},eE))}),fe=J(e=>{let t=l.current;if(!t){g(!1),v(!1);return}let n=e??aE(t),r=cE(n);if(g(r),!r){v(!1);return}let i=x.current===`released`&&!lE(n,S.current);v(i)}),pe=J(()=>{O.current+=1,k.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(k.current),k.current=null),A.current?.(),A.current=null});Z.useEffect(()=>()=>pe(),[u]);let me=J(()=>{if(!e)return;let n=l.current;if(!n)return;if(pe(),t?.current?.scrollToBottom({behavior:`auto`,reveal:!1})){oe(n),fe();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=()=>{oe(n),n.scrollTop=n.scrollHeight,V.current=n.scrollTop};if(s(),fe(),typeof window>`u`)return;let c=0,u=()=>{rE(iE(),I.current)||pe()};n.addEventListener(`touchstart`,u,{passive:!0,once:!0}),A.current=()=>n.removeEventListener(`touchstart`,u);let d=()=>{if(r===O.current){if(sE(n)>nE&&s(),c+=1,c>=tE){k.current=null,A.current?.(),A.current=null,fe();return}k.current=window.requestAnimationFrame(d)}};k.current=window.requestAnimationFrame(d)}),he=J(e=>{let n=l.current;if(n&&(oe(n),!t?.current?.scrollToBottom({behavior:e,reveal:!1}))){if(e===`smooth`){n.scrollTo({top:n.scrollHeight,behavior:e});return}n.scrollTop=n.scrollHeight}}),ge=J((t,n=`auto`)=>{if(!e)return;let r=l.current;if(t&&x.current!==`following`&&ae(`following`),r&&!(!t&&x.current!==`following`)){if(sE(r)<ZT){oe(r);return}he(t?n:`auto`)}}),_e=J(e=>{let t=l.current;if(!t)return;let n=e??aE(t);cE(n)&&x.current!==`released`&&(ae(`released`),fe(n))}),ve=J((e=`instant`,n)=>{if(L.current=!1,te.current=!1,ae(`following`),le(),pe(),t?.current?.scrollToBottom({behavior:e===`smooth`?`smooth`:`auto`,...n})){let e=l.current;e&&oe(e),fe();return}if(e===`instant`){me();return}pe(),ge(!0,`smooth`),fe()}),ye=J(()=>{te.current=!1,ge(!0)}),be=J(()=>{L.current=!1,pe(),t?.current?.cancelScroll(),le(),ae(`released`),fe()}),xe=J(()=>{let t=Ow(),n=l.current;if(!e||!n||!t||!n.contains(t.target)||!t.following||!t.range||z.current)return;let r=aE(n);if(!cE(r))return;let i=t.range.getBoundingClientRect?.();if(!i||!i.height)return;let a=n.getBoundingClientRect(),o=r.clientHeight*.2,s=Math.min(i.height,r.clientHeight-o*2);if(i.top>=a.top+o&&i.top+s<=a.bottom-o)return;let c=(r.clientHeight-s)/2,u=Math.min(r.scrollHeight-r.clientHeight,Math.max(0,r.scrollTop+i.top-a.top-c));Math.abs(u-r.scrollTop)<=1||(be(),n.scrollTo({top:u,behavior:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`instant`:`smooth`}),V.current=n.scrollTop)});Z.useEffect(()=>(xe(),Aw(xe)),[e,u,xe]);let Se=J(()=>{te.current=!0,be()}),Ce=J(()=>{te.current=!1}),we=Z.useRef(c);we.current=c;let Te=J(()=>{l.current&&Mw(l.current),!rE(iE(),I.current)&&(L.current=!1,pe(),t?.current?.cancelScroll(),le(),_e())}),Ee=J(()=>{I.current=0,Te(),we.current?.()}),De=J(()=>{G.current!==null&&(clearTimeout(G.current),G.current=null);let e=ne.current;if(e){if(!e.identity.sessionId){ne.current=null;return}ie(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),ne.current=null}}),Oe=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=JT(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),G.current===null&&(G.current=setTimeout(()=>{G.current=null,De()},YT))}),ke=J(()=>{De()}),Ae=J(async(e=w.current)=>{if(!e.sessionId||x.current===`released`&&KT(e,T.current))return!1;te.current=!1;let t=l.current;return t?(re.current=null,ae(`following`),B(),S.current?me():ge(!0),V.current=t.scrollTop,de(),fe(),!1):(re.current=e,ae(`following`),!1)});Z.useEffect(()=>{let e=w.current,t=T.current;KT(e,t)||(De(),pe(),B(),T.current=e,L.current=!1,R.current=null,E.current=null,V.current=0,le(),te.current=!1,ae(`following`),re.current=null,n&&n!==t?.sessionId&<.getInstance().recordSessionStart(n))},[n,r]),Z.useEffect(()=>{a&&!te.current&&x.current===`following`&&ge(!0)},[a]),Z.useEffect(()=>{b(p===`following`&&a)},[p,a]),Z.useLayoutEffect(()=>{if(!u)return;let e=re.current;e&&qT(e,w.current)&&Ae(e)},[u,n,r]);let je=J(()=>{let e=l.current;if(!e)return;let t=aE(e),n=V.current;V.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;fe(t);let a=Ow();if(a&&e.contains(a.target)){Oe();return}if(te.current){Oe();return}if(cE(t)){if(lE(t,S.current)){let e=Math.min(n,Math.max(0,t.scrollHeight-t.clientHeight));if(t.scrollTop<e-.5){Te(),Oe();return}(x.current===`following`||r&&L.current)&&(ae(`following`),L.current=!1),Oe();return}if(x.current===`following`&&(se(e)||ce()||i)){M.current||ge(!1),Oe();return}(x.current===`following`||!r)&&Te(),Oe()}});Z.useEffect(()=>{!e||!u||(V.current=u.scrollTop)},[u,e]);let Me=J(e=>{let t=l.current;if(t){if(e.deltaY!==0&&Mw(t),e.deltaY>0){Oc(t,e.target)||(L.current=!0);return}e.deltaY>=0||Dc(t,e.target)||Ee()}}),Ne=J(e=>{L.current=!1;let t=e.touches.item(0);z.current=t?{x:t.clientX,y:t.clientY,dx:0,dy:0}:null}),Pe=J(e=>{let t=l.current,n=e.touches.item(0);if(!n){z.current=null;return}let r=z.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(z.current={x:n.clientX,y:n.clientY,dx:o,dy:s},!(Math.abs(o)>=Math.abs(s))&&t){if(Math.abs(s)>2&&Mw(t),s<-2){Oc(t,e.target)||(L.current=!0);return}if(!(s<=0)){if(Dc(t,e.target)){z.current.dx=0,z.current.dy=0;return}s<=2||Ee()}}}),Fe=J(()=>{z.current=null}),Ie=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)&&Mw(l.current),!e.altKey&&!e.ctrlKey&&!e.metaKey&&[`ArrowDown`,`PageDown`,`End`].includes(e.key)){let e=l.current;e&&!Oc(e,t)&&(L.current=!0);return}xc(e)&&Ee()}}),Le=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&(I.current=0,Te(),R.current={id:e.pointerId,y:e.clientY})}),Re=J(e=>{let t=R.current;!t||t.id!==e.pointerId||(e.clientY!==t.y&&(L.current=e.clientY>t.y),t.y=e.clientY)}),ze=J(()=>{R.current=null}),Be=J(()=>{L.current=!1}),Ve=Z.useMemo(()=>()=>void 0,[]),He=e&&u?u:Ve,Ue=Z.useMemo(()=>({passive:!0}),[]);ir(`scroll`,je,He,Ue),ir(`scrollend`,Be,He,Ue),Z.useEffect(()=>{if(!e||!u)return;let t={passive:!0,capture:!0};return u.addEventListener(`wheel`,Me,t),u.addEventListener(`touchstart`,Ne,t),u.addEventListener(`touchmove`,Pe,t),u.addEventListener(`touchend`,Fe,t),u.addEventListener(`touchcancel`,Fe,t),()=>{u.removeEventListener(`wheel`,Me,t),u.removeEventListener(`touchstart`,Ne,t),u.removeEventListener(`touchmove`,Pe,t),u.removeEventListener(`touchend`,Fe,t),u.removeEventListener(`touchcancel`,Fe,t)}},[e,u]),ir(`keydown`,Ie,He),ir(`pointermove`,Re,e&&typeof window<`u`?window:Ve,!0),ir(`pointerup`,ze,e&&typeof window<`u`?window:Ve,!0),ir(`pointercancel`,ze,e&&typeof window<`u`?window:Ve,!0),ir(`pointerdown`,Le,e&&typeof window<`u`?window:Ve,!0);let We=J(()=>{let e=l.current;if(M.current){fe(e?aE(e):void 0);return}if(te.current){fe(e?aE(e):void 0);return}if(!e){fe(void 0);return}let t=aE(e),n=N.current;if(n?.element===e&&n.height!==t.clientHeight&&(N.current=null,x.current===`released`)){e.scrollTop=Math.max(0,n.top+n.height-t.clientHeight),oe(e),fe(aE(e));return}if(!cE(t)){fe(t);return}if(fe(t),H.current){let n=t.scrollHeight>ee.current+1;ee.current=t.scrollHeight,oE(t)<=ZT?oe(e):ge(!0),n&&ue();return}if(x.current===`following`){if(oE(t)<=ZT){oe(e);return}ge(!1)}}),Ge=typeof ResizeObserver<`u`,Ke=Ge&&e?u:null,qe=Ge&&e&&u&&u.firstElementChild instanceof Element?u.firstElementChild:null;sr(Ke,We),sr(qe,We);let Je=J(()=>{F.current!==null&&(clearTimeout(F.current),F.current=null)}),Ye=J(e=>{M.current=!0,typeof e==`number`&&e>0?j.current=iE()+e+QT:j.current=Math.max(j.current,iE()+QT)}),Xe=J(e=>{let t=e.detail;if(t){if(t.open===!0){Ye(),Je(),F.current=setTimeout(()=>{F.current=null,P.current||(M.current=!1)},1500);return}Je(),Ye()}}),Ze=J(e=>{let t=e.detail;t&&(Je(),Ye(t.durationMs),t.nativeResize&&(M.current=!1))}),Qe=J(e=>{let t=e.detail;if(Je(),t?.nativeResize){P.current=t.open===!0,M.current=!1,j.current=iE()+QT,We();return}t?.open===!0?(P.current=!0,M.current=!0):(P.current=!1,M.current=!0,F.current=setTimeout(()=>{F.current=null,P.current||(M.current=!1)},QT)),fe()}),$e=e&&typeof window<`u`?window:Ve;ir(`yuri:keyboard-native-layout`,()=>{let e=l.current;N.current=e?{element:e,top:e.scrollTop,height:e.clientHeight}:null},$e),ir(`yuri:keyboard-intent`,Xe,$e),ir(`yuri:keyboard-anim`,Ze,$e),ir(`yuri:keyboard-settled`,Qe,$e),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{Je(),N.current=null,M.current=!1,P.current=!1}},[e]),Z.useEffect(()=>{e&&fe()},[e,i]);let et=J(t=>{if(e){if(t===`animation`&&(j.current=iE()+QT),fe(),H.current){ge(!0),ue();return}x.current===`following`&&ge(!1)}}),tt=Z.useRef(new Map),nt=J(t=>{let n=tt.current.get(t);if(n)return n;let r=()=>{e&&x.current===`following`&&ge(!1)},i={onChunk:r,onComplete:()=>{e&&fe()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return tt.current.set(t,i),i});Z.useEffect(()=>()=>{D.current&&=(clearTimeout(D.current),null),pe(),le(),De(),G.current!==null&&(clearTimeout(G.current),G.current=null)},[]);let rt=J(e=>{s?.(e)}),it=!!s;return Z.useEffect(()=>{if(!e||!it)return;let t=u;if(!t)return;let n=null,r=BT({onActive:e=>{e!==n&&(n=e,rt(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,it]),{scrollRef:l,state:p,isPinned:p===`following`,isOverflowing:h,isFollowingProgrammatically:y,showScrollButton:_,notifyContentChange:et,getAnimationHandlers:nt,goToBottom:ve,scrollToBottomOnSend:ye,releaseAutoFollow:be,beginHistoryViewportPreservation:Se,endHistoryViewportPreservation:Ce,saveSnapshotNow:ke,restoreSnapshot:Ae}},dE=(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()}}}})(wl),fE=new Map,pE=e=>dE.hold(e),mE=e=>{fE.has(e)||fE.set(e,dE.hold(e))},hE=e=>{let t=fE.get(e);t&&(fE.delete(e),t())},gE=`btw-page`,_E=`btw-sheet`,vE=`text-selection`,yE=`1.5rem`,bE=`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`,xE=`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]`,SE=Z.memo(function(e){let t=(0,Q.c)(54),{turn:n,isLast:r,sessionId:i,directory:a,isMobile:o}=e,{t:s}=fr(),{hasTouchInput:c}=Us(),l=`btw:${i}:${n.id}`,u=Z.useRef(null),d,f;t[0]!==o||t[1]!==l?(d=()=>{if(o&&u.current)return aT(u.current,l)},f=[o,l],t[0]=o,t[1]=l,t[2]=d,t[3]=f):(d=t[2],f=t[3]),Z.useEffect(d,f);let p;t[4]!==s||t[5]!==n.error?(p=n.error===`empty response`||n.error===`session.btw failed`?s(`chat.btw.failed`):n.error,t[4]=s,t[5]=n.error,t[6]=p):p=t[6];let m=p,h=!n.pending&&!n.error&&!n.answer,g;t[7]!==s||t[8]!==n.answer?(g=async()=>{let e=await Ea(n.answer);return e.ok||no.error(s(`filesView.toast.copyFailed`)),e.ok},t[7]=s,t[8]=n.answer,t[9]=g):g=t[9];let _=J(g),v=n.id,y;t[10]===n.quotes?y=t[11]:(y=n.quotes.map(AE),t[10]=n.quotes,t[11]=y);let b;t[12]===n.question?b=t[13]:(b=(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words typography-markdown text-foreground`,children:n.question}),t[12]=n.question,t[13]=b);let x;t[14]!==y||t[15]!==b?(x=(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:[y,b]}),t[14]=y,t[15]=b,t[16]=x):x=t[16];let S;t[17]!==s||t[18]!==n.pending?(S=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`}),s(`chat.btw.pending`)]}):null,t[17]=s,t[18]=n.pending,t[19]=S):S=t[19];let C;t[20]===m?C=t[21]:(C=m?(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`}),m]}):null,t[20]=m,t[21]=C);let w;t[22]!==h||t[23]!==s?(w=h?(0,$.jsx)(`p`,{role:`status`,className:`typography-meta text-muted-foreground`,children:s(`chat.btw.cancelled`)}):null,t[22]=h,t[23]=s,t[24]=w):w=t[24];let T;t[25]!==l||t[26]!==n.answer?(T=n.answer?(0,$.jsx)(`div`,{"data-speech-content":`true`,children:(0,$.jsx)(ic,{content:n.answer,messageId:l,isAnimated:!1,isStreaming:!1,variant:`assistant`,enableFileReferences:!1})}):null,t[25]=l,t[26]=n.answer,t[27]=T):T=t[27];let E;t[28]!==h||t[29]!==_||t[30]!==a||t[31]!==m||t[32]!==c||t[33]!==r||t[34]!==o||t[35]!==l||t[36]!==i||t[37]!==s||t[38]!==n.answer||t[39]!==n.completedAt||t[40]!==n.durationMs||t[41]!==n.pending?(E=!n.pending&&(n.answer||r&&(m||h))?(0,$.jsx)(bT,{messageId:l,isMobile:o,duration:n.answer&&typeof n.durationMs==`number`&&Number.isFinite(n.durationMs)&&n.durationMs>=0?NT(n.durationMs):null,timestamp:n.answer&&typeof n.completedAt==`number`&&n.completedAt>0?PT(n.completedAt):null,actions:(0,$.jsxs)($.Fragment,{children:[n.answer?(0,$.jsx)(xT,{messageId:l,hasCopyableText:!0,isTouchContext:c||o,onCopyMessage:_,ttsText:n.answer,allowSourceSession:!1}):null,r?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,onPointerDown:jE,onClick:()=>void fw.getState().retry({sessionId:i,directory:a}),"aria-label":s(`contextPanel.preview.actions.retry`),children:(0,$.jsx)(X,{name:`refresh`,weight:cT,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:s(`contextPanel.preview.actions.retry`)})]}):null]})}):null,t[28]=h,t[29]=_,t[30]=a,t[31]=m,t[32]=c,t[33]=r,t[34]=o,t[35]=l,t[36]=i,t[37]=s,t[38]=n.answer,t[39]=n.completedAt,t[40]=n.durationMs,t[41]=n.pending,t[42]=E):E=t[42];let D;t[43]!==l||t[44]!==T||t[45]!==E?(D=(0,$.jsxs)(`div`,{ref:u,"data-message-id":l,"data-message-text-export-root":`true`,"data-speech-identity":l,...IT,className:`min-w-0 text-foreground yuri-message-hover-scope`,children:[T,E]}),t[43]=l,t[44]=T,t[45]=E,t[46]=D):D=t[46];let O;return t[47]!==C||t[48]!==w||t[49]!==D||t[50]!==x||t[51]!==S||t[52]!==n.id?(O=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-btw-turn":v,children:[x,S,C,w,D]}),t[47]=C,t[48]=w,t[49]=D,t[50]=x,t[51]=S,t[52]=n.id,t[53]=O):O=t[53],O});function CE(e){let t=(0,Q.c)(64),{scope:n,pending:r,quotes:i,foot:a}=e,{t:o}=fr(),s;t[0]===n?s=t[1]:(s=e=>e.sendSelection[FC(n)],t[0]=n,t[1]=s);let c=fw(s),l;t[2]!==n||t[3]!==c?(l=c??nw(n),t[2]=n,t[3]=c,t[4]=l):l=t[4];let u=l,d=ei(wE),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=Ki(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(``),fw.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)(ll,{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=()=>fw.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:yE},t[35]=I):I=t[35];let L=C?xE:bE,R;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(R={borderTopLeftRadius:yE,borderTopRightRadius:yE},t[36]=R):R=t[36];let z;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(z={borderBottomLeftRadius:yE,borderBottomRightRadius:yE},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=>fw.getState().removeQuote(n,e),t[40]=n,t[41]=V);let H;t[42]!==i||t[43]!==B||t[44]!==V?(H=(0,$.jsx)(Oh,{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)(Nc,{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 wE(e){return e.providers}function TE(e){let t=(0,Q.c)(45),{scope:n,foot:r,active:i}=e,a=r===void 0?`panel`:r,o=i===void 0||i,{t:s}=fr(),c;t[0]===n?c=t[1]:(c=FC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===l?u=t[3]:(u=e=>(e.entries[l]??PC).turns,t[2]=l,t[3]=u);let d=fw(u),f;t[4]===l?f=t[5]:(f=e=>(e.entries[l]??PC).quotes,t[4]=l,t[5]=f);let p=fw(f),m;t[6]===d?m=t[7]:(m=d.some(EE),t[6]=d,t[7]=m);let h=m,g=`btw:${l}`,_=a!==`panel`,v;t[8]!==o||t[9]!==h||t[10]!==n.sessionId||t[11]!==g||t[12]!==_||t[13]!==d.length?(v={enabled:o,currentSessionId:n.sessionId,viewportKey:g,sessionMessageCount:d.length,sessionIsWorking:h,isMobile:_},t[8]=o,t[9]=h,t[10]=n.sessionId,t[11]=g,t[12]=_,t[13]=d.length,t[14]=v):v=t[14];let{scrollRef:y,notifyContentChange:b}=uE(v),x=d[d.length-1],S;t[15]===b?S=t[16]:(S=()=>{b(`structural`)},t[15]=b,t[16]=S);let C=x?.answer,w=x?.pending,T;t[17]!==b||t[18]!==C||t[19]!==w||t[20]!==d.length?(T=[d.length,C,w,b],t[17]=b,t[18]=C,t[19]=w,t[20]=d.length,t[21]=T):T=t[21],Z.useLayoutEffect(S,T);let E;t[22]===s?E=t[23]:(E=s(`chat.btw.title`),t[22]=s,t[23]=E);let D;t[24]!==a||t[25]!==n.directory||t[26]!==n.sessionId||t[27]!==s||t[28]!==d?(D=d.length===0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:s(`chat.btw.description`)}):d.map((e,t)=>(0,$.jsx)(SE,{turn:e,isLast:t===d.length-1,sessionId:n.sessionId,directory:n.directory,isMobile:a!==`panel`},e.id)),t[24]=a,t[25]=n.directory,t[26]=n.sessionId,t[27]=s,t[28]=d,t[29]=D):D=t[29];let O;t[30]===D?O=t[31]:(O=(0,$.jsx)(`div`,{className:`flex flex-col gap-5`,children:D}),t[30]=D,t[31]=O);let k;t[32]!==y||t[33]!==O?(k=(0,$.jsx)(`div`,{ref:y,"data-btw-transcript":!0,className:`overlay-scrollbar-container min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-3`,children:O}),t[32]=y,t[33]=O,t[34]=k):k=t[34];let A;t[35]!==a||t[36]!==l||t[37]!==h||t[38]!==p||t[39]!==n?(A=(0,$.jsx)(CE,{scope:n,pending:h,quotes:p,foot:a},l),t[35]=a,t[36]=l,t[37]=h,t[38]=p,t[39]=n,t[40]=A):A=t[40];let j;return t[41]!==E||t[42]!==k||t[43]!==A?(j=(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-col text-foreground`,"aria-label":E,children:[k,A]}),t[41]=E,t[42]=k,t[43]=A,t[44]=j):j=t[44],j}function EE(e){return e.pending}function DE(e){let t=(0,Q.c)(53),{scope:n,active:r,mobile:i}=e,{t:a}=fr(),{sessionId:o,directory:s}=n,c;t[0]===n?c=t[1]:(c=FC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===s?u=t[3]:(u=Xn(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=q(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(kE),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&&!_&&fw.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=()=>Ia({sessionId:o,directory:s??null});return!r&&!n()&&fw.getState().cancel(e),()=>{let r=fw.getState().entries[l];queueMicrotask(()=>{let i=S.current;i!==t&&i?.key===l&&i.active||n()||FC(e)===l&&fw.getState().entries[l]===r&&fw.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=()=>{fw.getState().clear(n),q.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){hE(_E);return}return mE(_E),OE},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)(TE,{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)(sc,{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 OE(){return hE(_E)}function kE(e){return e.mode===`btw`}function AE(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 jE(e){return e.stopPropagation()}var ME=()=>{typeof window>`u`||window.requestAnimationFrame(()=>{document.querySelector(`[data-btw-composer] textarea`)?.focus()})},NE=e=>{let t=e.directory??null;Ca({sessionId:e.sessionId,directory:t})?mE(gE):q.getState().openContextPanelTab(t??``,{mode:`btw`}),ME()},PE=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},FE=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()}},IE=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,LE=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&e.delivery!==`queue`&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand&&!e.nativeGoal,RE=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},zE=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),BE=(e,t)=>{let n=It.getState();return n.bindLegacyQueue(an(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},VE=async e=>{let t=Da.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=zE(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}BE(n,a)?r+=1:i+=1}catch{try{BE(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},HE=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),UE=e=>{let t=e.ctrlEnter&&e.canQueue&&e.primary&&e.sessionIsRunning;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`}},WE=e=>Object.prototype.hasOwnProperty.call(e,`permissions`)?e.permissions:e.permission,GE=e=>{let t=ms(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},KE=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>GE(WE(e)));let r=e.find(e=>e?.name===n);return!r||GE(WE(r))},qE=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)},JE=null,YE=new Set,XE=()=>{for(let e of YE)e()},ZE=e=>e===`chat`||e===`assistant`,QE=()=>JE,$E=e=>{JE!==e&&(JE=e,XE())},eD=e=>{JE&&(e&&JE.surfaceID!==e||(JE=null,XE()))},tD=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},nD=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}},rD=(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}),iD=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=rD(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=rD(e,`send`,i),o=by(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=rD(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=rD(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=rD(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:by(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>py(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=rD(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=rD(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},aD=(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)))},oD=(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},sD=(e,t)=>e.agents.some(e=>e.name===t),cD=(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},lD=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return cD(t,n,r,i)?i:void 0;if(a&&cD(t,n,r,a))return a},uD=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!oD(r,n.providerID,n.modelID))return null;let s=n.agent&&sD(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&sD(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&sD(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=lD({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}},dD=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=uD({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=uD({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&&sD(i,e)?e:s&&sD(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&oD(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&cD(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&&oD(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&cD(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&&oD(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&sD(i,o.agent)?o.agent:void 0)??(e&&sD(i,e)?e:s&&sD(i,s)?s:void 0),r=l.variant,c=r&&cD(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},fD=(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))},pD=(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}},mD=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,hD=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}:{}}},gD=e=>typeof e==`string`&&e.trim().length>0?e:void 0,_D=e=>gD(e.agent)??gD(e.mode),vD=e=>gD(typeof e.model==`object`?e.model?.variant:void 0)??gD(e.variant),yD=e=>{let t=typeof e.model==`object`?e.model:void 0,n=gD(e.providerID)??gD(t?.providerID),r=gD(e.modelID)??gD(t?.modelID)??gD(t?.id);return!n||!r?null:{providerID:n,modelID:r}},bD=e=>yD(e),xD=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=yD(n);return{id:typeof n.id==`string`?n.id:void 0,agent:_D(n),providerID:r?.providerID,modelID:r?.modelID,variant:vD(n)}}return null},SD=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(yD(n))return null;continue}if(n.role!==`assistant`)continue;let r=bD(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:_D(n),providerID:r.providerID,modelID:r.modelID,variant:vD(n)}}return null},CD=500,wD=e=>Array.from(e).length,TD=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},ED=e=>wD(e)>=CD,DD=e=>{let t=un(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},OD=(e,t)=>{let n=t??e;return typeof n!=`string`||!ED(n)?!1:$t(typeof e==`string`?{text:``,references:[]}:e,n)},kD=(e,t,n,r,i=1)=>{let a=wD(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}-${TD(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},AD=e=>({text:e?.text??``,references:e?.composerReferences??[]}),jD=e=>({text:e.text,references:e.references.map(e=>({...e}))}),MD=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),ND=e=>JSON.stringify([e.text,e.references]),PD=(e,t)=>e!==null&&t!==null&&nt(e)===t,FD=(e,t,n)=>{let r=e?MD(e):null,i=r?n(r):void 0;return{document:Lt(AD(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?nt(r):null}},ID=(e,t,n,r)=>{if(!t||nt(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=ND(AD(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===ND(e)?`same-document-metadata`:`external-document`},LD=(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}]:[]})},RD=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),zD=(e,t,n,r,i=r)=>{let a=K(e,n,r,i);return{document:a.document,mentions:LD(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},BD=(e,t,n)=>({preview:{real:jD(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),VD=e=>({document:e.real,mentions:e.realMentions}),HD=(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)})},UD=(e,t)=>{let n=AD(t),r=pn(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:HD(e.mentions,t?.mentions??[],r,i)}},WD=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=fi})=>{let a=e?nt(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)(()=>FD(e,t,i.getState().getDraft).document),[d,f]=(0,Z.useState)(()=>FD(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?MD(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)(yc());_.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=Se(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=FD(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=yc(),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||!PD(S.current,a)||w.current!==a||C.current!==a||T.current!==e||E.current!==r||o?.revision!==t.revision||(E.current=t.revision,A(Lt(AD(t),y.current),t.mentions))})}},[a,A,i]),(0,Z.useEffect)(()=>{if(!a||w.current!==a||O.current)return;let e=ID(_.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(Lt(AD(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(!PD(n,C.current)||O.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:RD(t)});if(!a)return;let o=AD(a);return D.current={keyID:nt(n),revision:a.revision,fingerprint:ND(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=Ec(k.current,{before:kc(e,t,n),after:kc(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=Bt(e.text,e.references);return n?M(Lt(n,y.current),t):void 0},[M,P]),L=(0,Z.useCallback)((e,t,n=t,r)=>{let i=P(),a=jD(_.current),o=i?[]:v.current,s=zD(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=K(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=LD(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=zt(_.current,e,t,n,r);return M(a.document,LD(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=jD(_.current),n=st(t,e);if(!n)return null;let r=P()?[]:v.current,i=LD(r,n.document,n.edit),a=Ot(n.document.text,n.caret),o=K(n.document,a.text,a.caret),s=LD(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`?bc(k.current,_.current):Ac(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:[]}:BD(_.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=VD(e);A(t.document,t.mentions),g(e=>e+1)},[A]),te=(0,Z.useCallback)(()=>{let e=S.current;if(!PD(e,C.current))return null;let t=i.getState().getDraft(e);return{key:MD(e),keyID:nt(e),revision:t?.revision??0,document:jD(_.current),mentions:v.current.map(e=>({...e,range:{...e.range}})),epoch:T.current,runtime:i.getState().captureDraftRuntime()}},[i]),G=(0,Z.useCallback)(e=>{let t=UD(e,i.getState().getDraft(e.key)),n=AD(i.getState().getDraft(e.key)),r=un(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:RD(t.mentions)});if(a){let e=AD(a);j(r,e)}return a},[j,i]),ne=(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:ne,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:G}),[L,R,te,U,V,l,W,ee,ne,s,p,B,d,c,G,I,F,z,H,h])};function GD(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 KD(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=GD({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],_}var qD=()=>{let e=document.documentElement.classList;return e.contains(`yuri-native-ime`)&&!e.contains(`yuri-platform-android`)},JD=()=>parseFloat(document.documentElement.style.getPropertyValue(`--yuri-native-ime-lift`))||0;function YD(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=qD(),d=u?JD():0,f=u?d: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){f=Math.max(f,t.getBoundingClientRect().bottom+d);break}}let p=u?r.bottom:Math.min(r.bottom,(l?.offsetTop??0)+(l?.height??window.innerHeight)),m=r.height-n.height,h=Math.max(c,p-f-m),g=e.style.height,_=e.scrollTop;e.style.height=`0px`;let v=GD({scrollHeight:e.scrollHeight,dictationHeight:0,lineHeight:o,paddingTotal:s}).height;return e.style.height=g,e.scrollTop=_,[{id:`auto`,height:Math.min(h,Math.max(c,v))},{id:`min`,height:c},{id:`full`,height:h}]},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=oc(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),ir(`resize`,m,h);let g;t[16]===o?g=t[17]:(g=()=>o?window:null,t[16]=o,t[17]=g),ir(`yuri:keyboard-settled`,m,g);let _;t[18]===o?_=t[19]:(_=()=>o?window.visualViewport:null,t[18]=o,t[19]=_),ir(`resize`,m,_);let v;t[20]===o?v=t[21]:(v=()=>o?window.visualViewport:null,t[20]=o,t[21]=v),ir(`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 XD=(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=YD(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)(cc,{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}),ZD=.5,QD=`--yuri-mobile-composer-swap`,$D=`--yuri-native-composer-dock`,eO=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),tO=(e,t,n)=>Math.min(n,Math.max(t,e)),nO=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,rO=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return nO(e,n)?e:n},iO=(e,t)=>t?rO(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?rO(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,aO=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:rO(e,{phase:`snapping`,rest:t,progress:n})},oO=e=>Math.round(tO(e,0,1)*1e3)/1e3,sO=(e,t,n)=>{let r=n-t;if(r>=0)return oO(e+r/80);if(n<=2)return 0;if(n>=120)return e;let i=e+r/80,a=n/t*e;return oO(Math.min(i,a))},cO=(e,t)=>e>=1?`compact`:e<=0?`expanded`:t,lO=(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`?rO(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(r<=2)return rO(a,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn&&a.rest===`compact`&&r<i)return rO(a,{phase:`rest`,rest:`compact`,progress:1});let o=sO(a.progress,i,r);return e.phase===`snapping`&&o===a.progress?e:o===a.progress?a:Math.abs(o-a.progress)>=ZD&&(o>=1||o<=0)?rO(a,{phase:`snapping`,rest:o>=1?`compact`:`expanded`,progress:o}):o>=1||o<=0?rO(a,{phase:`rest`,rest:cO(o,a.rest),progress:o}):rO(a,{phase:`tracking`,rest:a.rest,progress:o})},uO=(e,t=null)=>e.pinned?`expanded`:t||(e.progress>=.5?`compact`:`expanded`),dO=(e,t=null)=>{if(e.pinned)return rO(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let n=uO(e,t),r=+(n===`compact`);return e.phase===`rest`&&e.rest===n&&e.progress===r?e:rO(e,{phase:`snapping`,rest:n,progress:r})},fO=e=>e.phase===`snapping`?rO(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,pO=e=>tO(Math.max(0,e)/80,0,1),mO=(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:pO(n),rest:`bottom`}},hO=`--yuri-mobile-composer-occupancy`,gO=(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(hO,n),n},_O=(e,t)=>{t!==null&&e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)===t&&e.style.removeProperty(hO)},vO=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},yO=(e,t=e)=>{for(let n of new Set([e,t]))n.style.removeProperty(QD),n.style.removeProperty($D);delete e.dataset.yuriComposerSwapPhase,delete e.dataset.yuriComposerSwapRest,delete e.dataset.yuriNativeComposerDock},bO=(e,t,n,r=e)=>{let i=mO(t,n?.rest===`bottom`?`bottom`:`away`),a=String(i.progress),o=i.rest;return n?.progress!==a&&r.style.setProperty($D,a),n?.rest!==o&&(e.dataset.yuriNativeComposerDock=o),{progress:a,rest:o}},xO=(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(QD,i),n?.rest!==o&&(e.dataset.yuriComposerSwapRest=o),{progress:i,phase:a,rest:o}},SO=`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`,CO=ec(()=>Wn(()=>import(`./ToolOutputDialog-C5b57FEy.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,77]))),wO=[],TO=[],EO=[],DO=/^@[^\s]+$/,OO=({inputMode:e,message:t,showCommandAutocomplete:n})=>e!==`shell`&&(n||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),kO=/^(https?:\/\/|mailto:)\S+$/i,AO=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),jO=(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)},MO=e=>e.includes(`@`)?`paste`:`manual`,NO=(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}},PO=(e,t)=>vt(e,t).some(e=>e.role===`user`),FO=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Or(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6547
|
+
`).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},IO=`file://`,LO=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(`/`)},RO=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(IO)?t:`file://${LO(t)}`},zO=e=>{if(!e)return[];let t=[...cC(e).map(lC),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(uC)))},BO=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},VO=e=>Wi(e.path),HO=(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)]})},UO=e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?RO(e.serverPath):e.dataUrl})),WO=(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}},GO=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 cC(e).length>0},KO=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)},qO=e=>{let t=e.icon?Sd[e.icon]:null,n=e.color?Td[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:`relative top-px flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-muted-foreground`,children:e.iconImage?(0,$.jsx)(_d,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:VO(e)})]})},JO=Z.memo(By),YO=Z.memo(Vm),XO=(0,$.jsx)(`span`,{"data-yuri-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`}),ZO=Z.memo(Jm),QO=Z.memo(hx),$O=Z.memo(vx),ek=Z.memo(nx),tk=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=fr(),r=q(e=>e.isMobile),i=Wa(e=>e.revertToMessage),a=Wa(e=>e.forkFromMessage),o=Wa(e=>e.handleSlashRedo),[s,c]=Z.useState(null),[l,u]=Z.useState(null),[d,f]=Z.useState(!0),p=Z.useRef(ZS),m=ia(),h=t||m,g=Di(h),_=Mt(e??``,h,g),v=Fi(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=eC({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 ft(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:FO(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)($r,{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)($r,{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))})]})})});tk.displayName=`RevertedMessageDock`;function nk({projects:e,query:t,renderLabel:n,onSelect:r,selectedId:i}){return e.filter(e=>bd(VO(e),t)||bd(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)(dl,{value:e.id,className:`max-w-[24rem] truncate`,children:n(e)},e.id))}var rk=Z.memo(function(e){let t=(0,Q.c)(42),{t:n}=fr(),{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?mk:void 0,v=f?hk: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)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:C}),(0,$.jsx)(ts,{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),ik=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=fr(),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=()=>qE({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)(es,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:gk,onPointerDownCapture:_k,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)(ts,{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)(ns,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),ak=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}=fr(),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=Ax({canSend:l,hasSessionTarget:!!(p||m),draftSubmitting:!!h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:vk,onPointerDownCapture:yk}:{},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&&(!n||!f),P=!N&&(!e.sendDisabled||d),F;t[30]!==n||t[31]!==b?(F=e=>{n&&(e.preventDefault(),b())},t[30]=n,t[31]=b,t[32]=F):F=t[32];let I;t[33]!==d||t[34]!==x||t[35]!==A||t[36]!==N||t[37]!==C?(I=C(A||!N&&d?x?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[33]=d,t[34]=x,t[35]=A,t[36]=N,t[37]=C,t[38]=I):I=t[38];let L;t[39]!==E||t[40]!==d||t[41]!==s||t[42]!==P||t[43]!==N?(L=P?(0,$.jsx)(gc,{className:E,spinning:!!(d&&!N)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[39]=E,t[40]=d,t[41]=s,t[42]=P,t[43]=N,t[44]=L):L=t[44];let R=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":P?`true`:void 0,disabled:e.sendDisabled,"aria-busy":d||void 0,...u,onClick:F,className:Y(P?T:i,P?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":I,children:L});if(!N){k=R;break bb0}let z=!n&&!S&&(f||x),B=!e.sendDisabled&&!x,V=S&&`h-full`;t[45]===V?D=t[46]:(D=Y(`relative z-30 overflow-visible`,V),t[45]=V,t[46]=D),O=z?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":B||x?`true`:void 0,disabled:e.sendDisabled||x,"aria-busy":x||void 0,...u,onClick:e=>{e.preventDefault(),!x&&b()},className:Y(B||x?T:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,B||x?void 0:e.disabledClass),"aria-label":M,children:B||x?(0,$.jsx)(gc,{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)(gc,{className:E,spinning:!0}):(0,$.jsx)(uc,{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),ok=(e,t)=>`${e}${e?e.endsWith(`
|
|
6548
6548
|
|
|
6549
6549
|
`)?``:e.endsWith(`
|
|
6550
6550
|
`)?`
|
|
@@ -6553,62 +6553,62 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,S as n,l as r,s
|
|
|
6553
6553
|
`:``}${t.endsWith(`
|
|
6554
6554
|
|
|
6555
6555
|
`)?t:t.endsWith(`
|
|
6556
|
-
`)?`${t}\n`:`${t}\n\n`}`,ak=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},ok=(e,t,n,r)=>t?on({transportIdentity:e},t):n?nn({transportIdentity:e},n):r,sk=[],ck={get:e=>Ne().get(e)?.title||e},lk=({onOpenSettings:e,scrollToBottom:t,showScrollToBottom:n=!1,onScrollToBottom:r,submissionBlocked:i=!1,surface:a})=>{let{t:o,locale:s}=fr(),l=yl(),[d,p]=Z.useState({open:!1,title:``,content:``}),[m,h]=Z.useState(`normal`),[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),[b,x]=Z.useState(!1),[S,C]=Z.useState(``),[w,T]=Z.useState(!1),[O,k]=Z.useState(``),[A,j]=Z.useState([]),[M,N]=Z.useState(0),[P,F]=Z.useState(null),I=Z.useRef(null),L=Z.useRef(null),[R,z]=Z.useState(!1),B=Z.useRef(null);Z.useEffect(()=>()=>{B.current!==null&&window.clearTimeout(B.current),I.current!==null&&window.clearTimeout(I.current),L.current!==null&&window.clearTimeout(L.current)},[]);let[V,H]=Z.useState(!1),[U,W]=Z.useState(!1),[ee,te]=Z.useState(null),G=Z.useId(),[ne,re]=Z.useState(``),[ie,ae]=Z.useState(``),[oe,se]=Z.useState(!1),[ce,le]=Z.useState(!1),ue=Z.useRef(0),de=J(()=>{ue.current=Date.now()+500}),fe=Z.useRef(0),pe=Z.useRef(!1),[me,he]=Z.useState(-1),ge=Z.useRef(()=>{}),ve=Z.useRef((...e)=>Promise.resolve().then(()=>Wa.getState().sendMessage(...e))).current,ye=Wa(e=>e.currentSessionId),xe=ei(e=>e.currentProviderId),Se=ei(e=>e.currentModelId),we=ei(e=>e.currentAgentName),Te=ei(e=>e.currentVariant),De=ei(e=>e.providers),Oe=ei(e=>e.agents),ke=ei(e=>e.getVisibleAgents),Ae=Z.useMemo(()=>ry(ke()),[ke,Oe]),je=ei(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Me=ei(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Pe=Z.useMemo(()=>{let e=De.find(e=>e.id===xe)?.models?.find(e=>e.id===Se);return uy(e)},[Se,xe,De]),Ie=Z.useMemo(()=>({providers:De,agents:Ae,variants:Pe,variantsReady:!je,modelsReady:!je,agentsReady:!Me,ready:!je&&!Me,loading:je||Me}),[De,Ae,Pe,je,Me]),Le=At(e=>e.currentDirectory),ze=Nu()??Le,{ensureSessionRenderable:Be}=ch(),Ve=Wa(Z.useMemo(()=>e=>ye?e.getDirectoryForSession(ye):null,[ye])),Ue=Na(ye??``,Ve??void 0),We=Z.useMemo(()=>xD(Ue),[Ue]),Ge=Z.useMemo(()=>SD(Ue),[Ue]),Ke=ta(ye??``,Ve??void 0).renderable,qe=hr(ye,Ve??void 0),Je=qe?.agent,Ye=qe?.model?.id,Xe=qe?.model?.providerID,Ze=qe?.model?.variant,Qe=ei(e=>e.activeDirectoryKey),$e=Z.useRef(0),et=Z.useRef(null),it=Z.useRef(null),at=Wa(e=>e.newSessionDraft),st=!!at?.open,ct=Wa(e=>e.newSessionDraft.draftSubmitting??!1),ut=Wa(e=>e.newSessionDraft.draftEstablishing??!1),dt=ct||ut,ft=Wa(e=>e.setDraftPermissionAutoAcceptEnabled),pt=uo(e=>e.autoAccept),mt=uo(e=>e.saving),gt=uo(e=>e.setSessionAutoAccept),yt=Wa(e=>e.setNewSessionDraftTarget),bt=Wa(e=>e.availableWorktreesByProject),xt=Wa(e=>e.abortPromptSessionId),Ct=Wa(e=>e.abortPromptExpiresAt),wt=Wa(e=>e.clearAbortPrompt),Tt=fi(e=>e.consumePendingInputText),Ot=fi(e=>e.pendingPresetSubmit),Mt=fi(e=>e.pendingInputText),Ft=fi(e=>e.pendingInputMode),Lt=fi(e=>e.consumePendingSyntheticParts),Rt=fi(e=>e.activeAttachmentDraft),zt=mh(Z.useMemo(()=>e=>{let t=ye??(st?`draft`:``);return t?e.drafts[t]??CO:CO},[st,ye])),Bt=go(ye??``),Vt=Z.useSyncExternalStore(c,u,u),Ut=Rt?.transportIdentity??null,Gt=Rt?.owner.kind??null,Jt=Rt?.owner.ownerID??null,Xt=Z.useMemo(()=>ok(Vt,ye,at.draftID,Ut&&Gt&&Jt?{transportIdentity:Ut,owner:{kind:Gt,ownerID:Jt}}:null),[Jt,Gt,Ut,Vt,ye,at.draftID]),$t=Xt?nt(Xt):null,en=fi(Z.useMemo(()=>e=>$t?e.draftAttachmentViews[$t]:void 0,[$t])),tn=fi(Z.useMemo(()=>e=>$t?e.drafts[$t]:void 0,[$t])),nn=Z.useMemo(()=>{if(!tn||!en)return sk;let e=tn.attachments.flatMap(e=>{let t=en[e.attachmentRefID];return t?[t]:[]});return e.length===0?sk:e},[en,tn]);Z.useEffect(()=>{Xt&&fi.getState().hydrateDraftAttachments(Xt)},[Xt]);let rn=hy(),on=q(e=>e.activeMainTab===`chat`),sn=Fa(ye??``,ze??void 0),dn=gy({kind:`primary`,surfaceID:`primary`,active:on,sessionID:ye,directory:ze??null,activity:{phase:sn?.type===`busy`?`busy`:sn?.type===`retry`?`retry`:`idle`,canAbort:sn?.type===`busy`||sn?.type===`retry`},draftKey:Xt,transportIdentity:Vt,runtimeGeneration:f(),selection:{value:{providerID:xe,modelID:Se,agent:we,variant:Te},catalog:Ie,flush:async()=>{let e=Wa.getState().currentSessionId;if(!e)return;let t=f(),n=u(),r=$e.current,i=e,a=Wa.getState().getDirectoryForSession(i)??null,o=Gr(a);if(ei.getState().activeDirectoryKey!==o&&await ei.getState().activateDirectory(a),f()!==t||u()!==n||Wa.getState().currentSessionId!==i||ei.getState().activeDirectoryKey!==o||$e.current!==r)return;await Be(i,{directory:a??void 0});let s=Wa.getState().getDirectoryForSession(i)??null,c=Gr(s);if(f()!==t||u()!==n||Wa.getState().currentSessionId!==i||s!==a||c!==o||ei.getState().activeDirectoryKey!==o||$e.current!==r)return;let l=ei.getState(),d={providers:l.providers,agents:l.getVisibleAgents()};if(d.providers.length===0||d.agents.length===0)return;let p=vt(i,s??void 0),m=xD(p),h=SD(p);if(mD({editRevision:r,pinnedHistoryMessageId:et.current,latestHistoryMessageId:m?.id??null}))return;let g=Oi.getState(),_=Ne().get(i),v=dD({sessionId:i,latestUserChoice:m,latestExecution:h,catalog:d,memory:g,sessionEntity:_?.model?{agent:_.agent,model:{id:_.model.id,providerID:_.model.providerID,variant:_.model.variant}}:_?.agent?{agent:_.agent}:null,fallbackAgentName:l.currentAgentName});if(!v)return;let y=[i,v.source,v.messageId??``,v.agent??``,v.providerID,v.modelID,v.variant??``,o].join(`|`);it.current!==y&&(fD(v,{currentAgentName:l.currentAgentName,setAgent:l.setAgent,setProvider:l.setProvider,setModel:l.setModel,setCurrentVariant:l.setCurrentVariant},{sessionId:i,memory:g}),it.current=y)},change:async e=>{$e.current+=1;let t=Wa.getState().currentSessionId;if(t){let e=Wa.getState().getDirectoryForSession(t)??void 0,n=xD(vt(t,e));et.current=n?.id??null}else et.current=null;let n=ei.getState();aD(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:Oi.getState()})}},resources:{attachments:nn,addAttachment:async e=>{Xt&&await Pa(Xt,()=>fi.getState()).addLocal(e)},removeAttachment:async e=>Xt?Pa(Xt,()=>fi.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>Xt?Pa(Xt,()=>fi.getState()).clearRootAttachments():!1,restoreAttachments:async e=>Xt?Pa(Xt,()=>fi.getState()).restoreRootAttachments(e):!1,pendingInput:Mt===null?null:{text:Mt,mode:Ft},consumePendingInput:Tt,pendingPreset:Ot,consumePendingPreset:()=>fi.getState().consumePendingPresetSubmit(),consumeSyntheticParts:Lt,restoreSyntheticParts:e=>fi.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:zt,removeInlineDraft:e=>{let t=ye??(st?`draft`:``);t&&mh.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=ye??(st?`draft`:``);!t||e.length===0||mh.setState(n=>{let r=n.drafts[t]??[],i=new Set(e.map(e=>e.id));return{drafts:{...n.drafts,[t]:[...e,...r.filter(e=>!i.has(e.id))]}}})},history:Bt,captureRuntime:()=>fi.getState().captureDraftRuntime(),getDraft:e=>fi.getState().getDraft(e),abortPrompt:{sessionID:xt,clear:wt}},backend:{send:e=>{tD(e,{transportIdentity:u(),runtimeGeneration:f()});let t=nD(e);return ve(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>lu(e.sessionID??``,{delivery:e.options?.delivery===`steer`?`steer`:void 0,queueItemID:e.queueItemID,manual:e.manual,scope:e.queueScope?{state:`bound`,...e.queueScope}:void 0}),create:async()=>Ya(),compact:async e=>Kt.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&xu(e.sessionID),hi(e.sessionID??``))},shortcuts:{cycle:e=>ge.current(e),new:()=>Ya(),abort:()=>(ye&&xu(ye),hi(ye??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),K=_y(dn,a??rn);vy(K),Z.useLayoutEffect(()=>{if(!K.active){eD(K.surfaceID);return}return $E(K),()=>eD(K.surfaceID)},[K]);let pn=iD(K),hn=K.resources??(K.kind===`primary`?dn.resources:void 0);if(!hn)throw Error(`chat-input-surface-resources-incomplete`);let _n=[...hn.attachments],vn=K.sessionID,yn=yy(K,dt),bn=K.kind===`secondary`?K.commands.hasNewDraft:st,xn=bn,Sn=K.directory??ze,Cn=K.draftKey??Xt,wn=Z.useMemo(()=>{if(K.kind===`secondary`)return xy(K,!1,!1);let e=vn?MO(vn,Ve??void 0):!1;return xy(K,e,bn)},[K,vn,Ve,bn]),Tn=(e,t,n,r,i,a,o,s,c,l)=>pn?pn.send({providerID:t,modelID:n,agent:r,variant:s,text:e,attachments:i,agentMention:a,parts:o,systemContext:o?.filter(e=>e.synthetic).map(e=>({text:e.text,synthetic:!0})),inputMode:c,options:l}):Promise.reject(Error(`chat-input-surface-incomplete`)),En=J(()=>pn?pn.abort():Promise.reject(Error(`chat-input-surface-incomplete`))),Dn=Mr(e=>e.projects),On=Mr(e=>e.activeProjectId),kn=Mr(e=>e.setActiveProjectIdOnly),An=Z.useMemo(()=>vn?Ei({autoAccept:pt,sessions:[],sessionById:Ne(),sessionID:vn}):at.permissionAutoAcceptEnabled===!0,[vn,at.permissionAutoAcceptEnabled,pt]),jn=ei(e=>e.agents),Mn=K.kind===`secondary`?K.selection.value.agent:we,Nn=K.kind===`secondary`?ry(K.selection.catalog?.agents):jn,Pn=E()||KE(Nn,Mn),In=J(()=>{no.error(o(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))}),Ln=K.selection.value,zn=K.selection.change,Bn=K.selection.catalog,Vn=J(async e=>{if(!zn)throw Error(`chat-input-surface-selection-readonly`);await zn({...e,agent:e.agent??void 0,variant:e.variant})}),Hn=Z.useMemo(()=>({selection:{providerID:Ln.providerID??``,modelID:Ln.modelID??``,agent:Ln.agent??null,variant:Ln.variant},onChange:Vn,disabled:!K.active,catalog:Bn}),[Bn,Vn,Ln.agent,Ln.modelID,Ln.providerID,Ln.variant,K.active]);Z.useEffect(()=>{$e.current=0,et.current=null,it.current=null},[ye]),Z.useEffect(()=>{if(K.kind!==`primary`||!ye||je||Me||De.length===0||Ae.length===0)return;let e=Gr(Ve);if(Qe!==e)return;let t=Oi.getState(),n={providers:De,agents:Ae};if(mD({editRevision:$e.current,pinnedHistoryMessageId:et.current,latestHistoryMessageId:We?.id??null}))return;let r=dD({sessionId:ye,latestUserChoice:We,latestExecution:Ge,catalog:n,memory:t,sessionEntity:Xe&&Ye?{agent:Je,model:{id:Ye,providerID:Xe,variant:Ze}}:Je?{agent:Je}:null,fallbackAgentName:we,transcriptReady:Ke});if(!r)return;let i=[ye,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,Qe].join(`|`);if(it.current===i)return;if((r.agent===void 0||r.agent===we)&&r.providerID===xe&&r.modelID===Se&&r.variant===Te){it.current=i;return}if(ei.getState().activeDirectoryKey!==e)return;let a=ei.getState();fD(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:ye,memory:t}),it.current=i},[K.kind,ye,We,Ge,Ke,De,Ae,je,Me,Qe,Ve,we,xe,Se,Te,Je,Ye,Xe,Ze]);let Un=ei(e=>K.kind===`primary`?e.providers:wO),Wn=K.kind===`secondary`?K.selection.catalog?.agents:void 0,Gn=Z.useMemo(()=>K.kind===`secondary`?ry(Wn):Ae,[K.kind,Wn,Ae]),Kn=K.kind===`secondary`?K.selection.catalog?.providers??wO:Un,qn=K.kind===`secondary`&&(!K.selection.catalog?.ready||!!K.selection.catalog.error),Yn=!K.active||!K.selection.change||qn,Zn=q(e=>e.isMobile),Qn=mc(),$n=q(e=>e.setImagePreviewOpen),er=J(e=>{e.image&&(p(e),$n(!0))}),tr=J(e=>{p(t=>({...t,open:e})),$n(e)}),nr=Xm(e=>e.pending),rr=q(e=>e.inputBarOffset),ar=q(e=>e.persistChatDraft),or=q(e=>e.inputSpellcheckEnabled),cr=q(e=>e.isExpandedInput),lr=q(e=>e.setExpandedInput),ur=q(e=>e.setTimelineDialogOpen),dr=WD({draftKey:Cn,sessionTitles:ck,persistenceEnabled:ar}),pr=dr.document,mr=pr.text,{replacePlainDocument:gr,replaceProgrammaticText:_r,applyBrowserEdit:vr,insertReference:yr,deleteReference:br,enterHistoryPreview:xr,exitHistoryPreview:Sr,captureSubmission:Cr,recoverSubmission:wr,confirmedFileMentions:Tr,mentions:Dr}=dr,Or=J((e,t)=>_r(e,t)),kr=Z.useMemo(()=>new Set(Tr.map(e=>e.value)),[Tr]),Ar=Z.useRef(null),Nr=Z.useRef(!1),Pr=Z.useRef(0),Fr=Z.useRef(null),Ir=Z.useRef(null),Lr=Z.useRef(0),zr=Z.useRef(!1),Br=Z.useRef(null),Vr=Z.useRef(!1),Hr=Z.useRef(null),Ur=Z.useRef([]),Wr=Z.useRef(!1),Kr=Z.useRef(null),Jr=Z.useRef(!1),Yr=Z.useRef(null),Xr=Z.useRef(mr),Zr=Z.useRef(new Set),ti=dr.getDocument,ni=J((e,t,n=[])=>Or(e,(e,r)=>{let i=[],a=new Set(n);for(let e of t){let t=0,n=`@${e}`;for(;t<r.text.length;){let o=r.text.indexOf(n,t);if(o<0)break;i.push({kind:a.has(e)?`directory`:`file`,value:e,path:e,label:e,range:{start:o,end:o+n.length}}),t=o+n.length}}let o=new Set(e.map(e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`));return[...e,...i.filter(e=>!o.has(`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`))]})),ri=Qb(Zb()),{git:ii,vscode:ai}=Rn(),oi=q(e=>e.shortcutOverrides.cycle_agent),ci=q(e=>e.shortcutOverrides),li=Z.useMemo(()=>Ns(`cycle_agent`,oi?{cycle_agent:oi}:void 0),[oi]),ui=Z.useMemo(()=>Ns(`clear_all_messages`,ci),[ci]),{currentTheme:di}=Io(),pi=Wc(),mi=Kc(Sn),gi=sl(e=>Sn?e.directories.get(Sn)?.status??null:null),_i=sl(e=>e.ensureStatus),yi=sl(e=>e.fetchStatus),[bi,wi]=Z.useState(!1),Ti=Z.useRef(null);Z.useEffect(()=>{!Sn||!ii||_i(Sn,ii)},[Sn,ii,_i]),Z.useEffect(()=>{if(!(!Sn||!ii))return sa.onGitRefreshHint(e=>{RO(e.directory)===RO(Sn)&&yi(Sn,ii)})},[Sn,ii,yi]);let Di=cr&&!Zn,ki=cr&&Zn,Ai=Di||ki,ji=`1.5rem`,Mi=o(vn||bn?m===`shell`?`chat.chatInput.placeholder.shell`:Zn?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Ni=_n,Pi=Z.useMemo(()=>new Set(Gn.map(e=>e.name.toLowerCase())),[Gn]),Fi=Z.useRef(Pi);Fi.current=Pi;let Li=EO({inputMode:m,message:mr,showCommandAutocomplete:w}),Ri=Ci({directory:Sn,enabled:Li}),zi=Z.useMemo(()=>Ri.data??[],[Ri.data]),Bi=oa({directory:Sn,enabled:m!==`shell`}),Vi=Z.useMemo(()=>Bi.data??[],[Bi.data]),Hi=Z.useMemo(()=>new Map(Vi.map(e=>[e.name.toLowerCase(),e.name])),[Vi]),Ki=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);E()&&e.add(`reload`);for(let t of zi)t.source!==`skill`&&e.add(t.name.toLowerCase());return e},[zi]),qi=Z.useMemo(()=>{if(!mr||!mr.includes(`/`)||m===`shell`||Ki.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${tt})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(mr))!==null;){let t=n[2]??``,r=n[3];if(!Ki.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length;e.push({start:i,end:i+a,style:`mentionCommand`,visual:ot({trigger:`/`,icon:`command`,label:r},mr.slice(i,i+a))})}return e},[m,Ki,mr]),Xi=Z.useMemo(()=>!mr||!mr.includes(`@`)||m===`shell`?[]:Oo(mr,{confirmedValues:kr,agentNames:Pi}),[kr,m,Pi,mr]),Zi=Z.useMemo(()=>{if(!mr||!mr.includes(`[`)||m===`shell`||Ni.length===0)return[];let e=Ni.filter(_e),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return qt(mr,e.map(e=>e.filename)).flatMap(e=>{let n=ht(mr.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:ot({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},mr.slice(e.start,e.end))}]})},[m,mr,Ni]),$i=l&&Pl(Zn)&&K.kind===`primary`,{globallyEnabled:ea,enabled:na,hint:ra,onHintChange:ia}=dc({available:Zn&&!$i}),ca=o(ra===`recording`?`chat.dictation.releaseSend`:ra===`cancelling`?`chat.dictation.releaseCancel`:ra===`editing`?`chat.dictation.releaseEdit`:ra===`processing`?`chat.dictation.processing`:`chat.dictation.inputPlaceholder`),[la,ua]=Z.useState(!1),[fa,pa]=Z.useState(!1),[ma,ha]=Z.useState(null),ga=Z.useMemo(()=>{if(!mr||m===`shell`)return null;let e=[...jc(Xi),...qi,...Zi,...ma?.draftID===$t&&ma?.text===mr?[{start:ma.start,end:ma.end,style:`dictation`}]:[],...pr.references.map(e=>({start:e.start,end:e.end,priority:103,...lt(e)}))];return Sc(mr,e)},[Zi,qi,Xi,pr.references,m,mr,ma,$t]),[_a,va]=Z.useState(null),ya=Z.useRef(null),[xa,Sa]=Z.useState(!1),[Ca,wa]=Z.useState(!1),[Ta,Ea]=Z.useState(null),[Oa,ka]=Z.useState(null),Aa=It(e=>e.followUpBehavior),ja=Z.useMemo(()=>{let e=pn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[pn]),Ia=Dh({transportIdentity:ja?.transportIdentity??``,directory:ja?.directory??``,sessionID:ja?.sessionID??``}),Ra=Z.useMemo(()=>vn?an(vn):null,[vn]),za=It(Z.useMemo(()=>e=>ja?Qt(e,ja):SO,[ja])),Ba=It(Z.useMemo(()=>e=>Ra?Qt(e,Ra):SO,[Ra])),Va=Z.useMemo(()=>Ba.length===0?za:za.length===0?Ba:[...Ba,...za],[za,Ba]),Ha=Ia.mode===`server`?SO:Va,Ua=It(Z.useMemo(()=>e=>ja?Dt(e,ja):SO,[ja])),Ga=It(e=>e.clearQueue),Ka=It(e=>e.removeFromQueue),Ja=hn.inlineDrafts,Xa=Ja.length>0,[Za,Qa,$a]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of Ja)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[Ja]),eo=J(e=>{for(let t of hn.inlineDrafts)t.source===e&&hn.removeInlineDraft(t.id)}),to=J(()=>{for(let e of hn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&hn.removeInlineDraft(e.id)}),ro=hn.history;Z.useEffect(()=>{Xr.current=mr},[mr]),Z.useLayoutEffect(()=>{h(`normal`),he(-1)},[Cn?.transportIdentity,Cn?.owner.kind,Cn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!bn||Zn)return;let e=()=>{let e=Ar.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[bn,Zn]);let io=Cx(K.kind===`primary`?vn:null,K.kind===`primary`?Sn??void 0:void 0),ao=K.activity?.phase??io.phase,oo=J(e=>{Zn&&(de(),F(e),Ar.current?.blur(),ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),co=hn.pendingInput,lo=hn.consumePendingInput;Z.useEffect(()=>{if(co===null)return;let e=lo();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=ik(Xr.current,e.text);Xr.current=t,Or(t)}else if(e.mode===`append-inline`){let t=ak(Xr.current,e.text);Xr.current=t,Or(t)}else gr(e.text);setTimeout(()=>{Ar.current?.focus()},0)}},[co,lo,gr,Or]);let fo=Mg(vn,at.draftID),po=Wg(Gg(fo)),ho=mr.trim().length>0||Ni.length>0||Xa||po.length>0,_o=K.kind===`primary`&&OC(mr,m)===`btw`,yo=Ia.mode===`server`?Ia.items.length>0:Ha.length>0||Ua.length>0,xo=!_o&&!O_(Ia.mode),Co=ho||yo,wo=Wa(e=>e.stagedMessageEdit?.sessionId===vn?e.stagedMessageEdit.messageId:null),To=ao===`busy`||ao===`retry`,ko=!_o&&(K.activity?.canAbort??To),Ao=J(()=>{let e=Ar.current,t=e?.value??ti().text;t!==ti().text&&vr(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=ti();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Ni.length>0||Xa||po.length>0}}),jo=K.surfaceID,Mo=at?.draftID??null,No=Da(Z.useMemo(()=>jr(jo),[jo])),Po=Da(Z.useMemo(()=>si(Mo),[Mo])),Fo=Z.useMemo(()=>Si(_o?null:No,!_o&&Po),[No,Po,_o]),Lo=(e=`send`)=>Da.getState().beginFlight(jo,e),Ro=()=>{Da.getState().endFlight(jo)},zo=()=>Da.getState().isInFlight(jo),Bo=Z.useRef(null);Z.useEffect(()=>{if(K.kind!==`primary`||!wo){Bo.current=null;return}if(Bo.current!==wo){if(Bo.current=wo,$i){Al().focus();return}sy(Ar)||requestAnimationFrame(()=>sy(Ar))}},[$i,wo,K.kind]);let Vo=Da(Z.useMemo(()=>Er(Mo),[Mo])),Ho=ln(Z.useMemo(()=>e=>vn?e.bySession[vn]:void 0,[vn])),Uo=Z.useMemo(()=>{if(!Ho?.length)return rt;let e=new Set(Ue.map(e=>e.id));return Ho.filter(t=>!e.has(t.id)).map(jt)},[Ho,Ue]),[Wo,Go]=Z.useState(null),[Ko,qo]=Z.useState(()=>new Set),Yo=Wo&&Wo.sessionID===vn&&Du(Wo.runtime,hn.captureRuntime())&&!Zt(Wo.sessionID,Wo.item.messageID)&&!Uo.some(e=>e.messageID===Wo.item.messageID)?Wo.item:null,Xo=Z.useMemo(()=>[...Vo,...Uo,...Yo?[Yo]:[]],[Vo,Uo,Yo]);Z.useEffect(()=>{qo(e=>{if(e.size===0)return e;let t=new Set;for(let e of Uo)t.add(e.messageID);Yo&&t.add(Yo.messageID);let n=!1;for(let r of e)if(!t.has(r)){n=!0;break}if(!n)return e;let r=new Set;for(let n of e)t.has(n)&&r.add(n);return r})},[Uo,Yo]);let Zo=Ht(Z.useMemo(()=>e=>vn?e.runningBySession[vn]===!0:!1,[vn])),Qo=J(async()=>{let e=Wa.getState().newSessionDraft.draftID;if(!e||!Da.getState().isEstablishing(e))return!1;let t=Ao();if(!t.hasContent)return!1;let n=Mg(null,e),r=n?Wg.getState().quotesByKey[n]??[]:[],i=Hg(t.document,r),a=be(i,`queue-canonical`);if(!a.ok)return no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1;if(await K.selection.flush(),!Da.getState().isEstablishing(e))return!1;let s=pD(ei.getState());if(!s?.providerID||!s?.modelID)return no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1;let c=VO(Ni);return Da.getState().enqueueEstablishingFollowUp({draftID:e,content:a.text,sendConfig:{providerID:s.providerID,modelID:s.modelID,...s.agent?{agent:s.agent}:{},...s.variant?{variant:s.variant}:{}},attachments:c,composerDocument:i})?(gr(``),n&&i!==t.document&&Wg.getState().clear(n),he(-1),lr(!1),c.length>0&&hn.clearAttachments(),!0):!1}),es=()=>{if(vn)return!1;let e=Wa.getState().newSessionDraft.draftID;return Da.getState().isEstablishing(e)?(Qo(),!0):!1},ts=J(async()=>{if(!K.active||zo())return;if(K.kind===`primary`&&vn){let e=Wa.getState().stagedMessageEdit;if(e&&e.sessionId===vn){await ls();return}}let e=Ao(),t=be(e.document);if(!t.ok){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let n={chunks:t.chunks??[],semantics:t.semantics??[]},r=t.text,a=r.trimStart(),s=n.chunks.every(e=>e.provenance===`authored`)&&m===`normal`&&a.startsWith(`/`)?Rc(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(s&&!Bc(s,e=>py(K,{name:e.name,source:`yuri`}))||i||!e.hasContent||!vn)return;if(K.kind===`primary`&&m===`normal`&&(so.getState().armed||gn(r)?.commandName.toLowerCase()===`goal`)){ls(To?{delivery:`queue`}:void 0);return}if(xo||!_u(K.deliveryTarget?.kind,Ia.mode)){ls(To?{delivery:`steer`}:void 0);return}if(n.chunks.every(e=>e.provenance===`authored`)&&kC(r,m)){ls();return}if(!Lo(`queue`))return;let c=K.transportIdentity,l=K.runtimeGeneration,d=hn.captureRuntime(),p=ja,h=K.kind===`primary`?ja?.sessionID??vn:null,g=[...hn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?un(_h(e.document.text,g),e.document.references).document:e.document,v=fo?Wg.getState().quotesByKey[fo]??[]:[],y=Hg(_,v),b=y!==_,x=be(y,`queue-canonical`);if(!x.ok){Ro(),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let S=VO(Ni),C=Cr(),w=S,T=Tu(),E=!1,D=null,O=()=>{E&&p&&(Ia.actions.unstageAdmission({requestID:T.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),E=!1),D&&p&&(It.getState().unstageAdmission(p,D),D=null)},k=async e=>{O(),C&&wr(C),w.length>0&&await hn.restoreAttachments(w),e&&hn.restoreSyntheticParts(e),g.length>0&&hn.restoreInlineDrafts(g),b&&fo&&Wg.getState().restore(fo,v)};try{if(!p){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}if(Ia.mode===`server`){if(!Cn){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}fu({stage:()=>{Ia.actions.stageAdmission({requestID:T.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:T.queueItemID,operationID:T.operationID,messageID:T.messageID,content:x.text,createdAt:T.createdAt,attachmentCount:S.length,composerDocument:y,composerMentions:Dr}}),E=!0},clearComposer:()=>{gr(``),b&&fo&&Wg.getState().clear(fo),he(-1),lr(!1)}})}else fu({stage:()=>{It.getState().bindLegacyQueue(an(p.sessionID),p),It.getState().stageAdmission(p,{requestID:T.requestID,queueItemID:T.queueItemID,operationID:T.operationID,messageID:T.messageID,content:x.text,createdAt:T.createdAt,attachmentCount:S.length,composerDocument:y,composerMentions:Dr}),D=T.requestID},clearComposer:()=>{gr(``),b&&fo&&Wg.getState().clear(fo),he(-1),lr(!1)}});if(await K.selection.flush(),!Du({transportIdentity:c,generation:l},{transportIdentity:u(),generation:f()})){await k();return}if(!Du(d,hn.captureRuntime())){await k();return}if(h&&Wa.getState().currentSessionId!==h){await k();return}if(p.transportIdentity!==u()||p.runtimeGeneration!==f()||p.sessionID!==(h??p.sessionID)||h&&Xn(Wa.getState().getDirectoryForSession(h))!==Xn(p.directory)){await k();return}let t=p,n=K.kind===`primary`?(()=>{let e=ei.getState(),t=h?Wa.getState().getDirectoryForSession(h)??null:null;return pD(e,{expectedConfigKey:Gr(t),activeDirectoryKey:e.activeDirectoryKey})})():K.selection.value.providerID&&K.selection.value.modelID?{...K.selection.value,providerID:K.selection.value.providerID,modelID:K.selection.value.modelID}:void 0;if(!cu(n)){await k();return}if(Ia.mode===`server`){if(!Cn){await k(),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let r=ou({draftKey:Cn,runtime:d,document:e.document,attachments:Ni,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?hn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??Jn()}))??null:null,a,s=[],c=t.deliveryTarget.kind===`assistant`?(()=>{let e=Xl({plan:{chunks:x.chunks??[],semantics:x.semantics??[]},agents:Gn,installedSkillNames:new Set(Qi(Fn,Sn).map(e=>e.name)),directory:Sn,root:pi||Sn,confirmedFilePaths:Tr.map(e=>e.path),confirmedDirectoryPaths:Tr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ni});return s=e.attachments,Jl({text:g.length>0?_h(e.text,g):e.text,attachments:[...S,...e.attachments],semanticParts:vo(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...pu(S),...pu(s),...(i??[]).flatMap(e=>pu(e.attachments??[],e.partID))],t=c?new Set(c.flatMap(e=>e.type===`file`?[e.attachmentID]:[])):null;a=e.filter((n,r)=>e.findIndex(e=>e.attachmentID===n.attachmentID)===r&&(!t||t.has(n.attachmentID)))}catch(e){await k(i),no.error(o(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let l=c&&i?Eu(c,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,s=await bu({capture:r,admit:async()=>{let r=await Ia.actions.admit({requestID:T.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:T.queueItemID,operationID:T.operationID,messageID:T.messageID,content:x.text,composerDocument:y,composerMentions:Dr,sendConfig:n,deliveryTarget:t.deliveryTarget,...c?{deliveryParts:c}:{},...l?{syntheticParts:l}:{},attachmentIssues:[],createdAt:T.createdAt},attachments:a});return r.status===`committed`&&(e=!0,E=!1),r},captureRuntime:hn.captureRuntime,getCurrentDraftKey:()=>Cn,getDocument:ti,consumeBody:()=>gr(``),getAttachments:()=>hn.attachments,removeAttachment:hn.removeAttachment,getInlineDrafts:()=>hn.inlineDrafts,removeInlineDraft:hn.removeInlineDraft});if(!e){await k(i),s.status===`stale`&&no.error(o(`chat.chatInput.toast.messageSendFailed`));return}if(s.status===`partial`){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}s.status===`committed`&&!Zn&&Ar.current?.focus()}catch(e){await k(i),no.error(o(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!It.getState().confirmAdmission(t,{requestID:T.requestID,sendConfig:n,attachments:S.length>0?S:void 0}).ok){await k(),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}D=null;for(let e of g)hn.removeInlineDraft(e.id);S.length>0&&hn.clearAttachments(),Zn||Ar.current?.focus()}catch(e){await k(),no.error(o(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Ro()}}),ns=J(()=>{HE(()=>ts(),()=>{no.error(o(`chat.chatInput.toast.messageSendFailed`))})}),is=J(async(e,t,n,r)=>{if(xo||!K.draftKey)return!1;try{let i=await Yi({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=fi.getState(),s=a.getDraft(K.draftKey);return A_(await ba({key:K.draftKey,expectedRevision:s?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1}}),as=J(e=>{if(!(i||xo)){if(pn){pn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}no.error(o(`chat.chatInput.toast.messageSendFailed`))}}),os=J(()=>{de(),F(`agent`),Ar.current?.blur(),ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),ss=J(()=>{Sa(!0)}),cs=J(()=>{wa(!0)}),ls=J(async e=>{if(!K.active||i)return;if(!e?.queuedOnly){let t=e?.presetText==null?Ao():null;if(jC({text:e?.presetText??t?.message??``,inputMode:m,scope:vn&&Sn?{sessionId:vn,directory:Sn}:null,hasReferences:!!(t?.document.references.length||Dr.length),allowed:K.kind===`primary`&&py(K,{name:`btw`,source:`yuri`}),ask:fw.getState().ask,clearText:()=>{gr(``),T(!1),k(``)},open:()=>{Zn&&(de(),Ar.current?.blur()),vn&&NE({sessionId:vn,directory:Sn??null})},notify:e=>no.error(o(`chat.btw.${e}`))}))return}if(es()||zo())return;let n=e?.queuedOnly??!1,r=e?.queuedMessageId,a=Wa.getState().stagedMessageEdit,s=K.kind===`primary`&&!n&&!!(vn&&a?.sessionId===vn),c=e?.presetText==null?Ao():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Ni.length>0||Xa},l=e?.presetText==null?Cr():null,d=_n,p=be(c.document,`direct-send-display`);if(!p.ok){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let h=p.text,g={chunks:p.chunks??[],semantics:p.semantics??[]},_=g.chunks.every(e=>e.provenance===`authored`),v=h.trimStart(),y=_?OC(v,m):null,b=_&&kC(h,m),x=_&&m===`normal`&&/^\/model(?:\s|$)/i.test(v),S=_&&m===`normal`&&v.startsWith(`/`)?Rc(v.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0,C=K.kind===`primary`&&m===`normal`&&(so.getState().armed||gn(h)?.commandName.toLowerCase()===`goal`),w=!C&&!s&&e?.steerAfterAdmit===!0&&To&&K.kind===`primary`,D=s||C&&e?.steerAfterAdmit?`steer`:w?`queue`:e?.delivery,O=D===`queue`&&To?`queue`:D===`steer`&&To?`steer`:void 0;if(S&&!Bc(S,e=>py(K,{name:e.name,source:`yuri`}))||n&&xo)return;if(!n&&x){T(!1),k(``),Zn?oo(`model`):(q.getState().setModelSelectorOpen(!0),ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}let A=!C&&!s&&!w&&iu({hasQueuedMessages:yo,sessionIsRunning:To,queuedOnly:n,delivery:O});if(!(!n&&y&&y!==`model`)){if(vn&&A&&xo)return;if(vn&&A&&Ia.mode===`server`){c.hasContent&&ns();return}if(vn&&A){c.hasContent&&ns();let e=Ha[0];e&&pn&&await pn.sendQueued(e.queueItemID,{options:To?{delivery:`steer`}:void 0});return}}let j=b||!n&&c.hasContent&&!r?[]:r?Ha.filter(e=>e.id===r):Ha;if(n){if(j.length===0||!vn)return}else if(!c.hasContent&&!yo||!vn&&!bn)return;if(!vn&&yn||!Lo(O===`queue`?`queue`:`send`))return;let M=!vn&&bn&&!n&&!b?Wa.getState().newSessionDraft.draftID??null:null,N=M?Nt(`msg`):void 0;if(M&&N&&!Da.getState().beginEstablishing({draftID:M,primaryMessageID:N})){Ro();return}let P=()=>{Ma(),M&&Da.getState().clearEstablishing(M)},F=e=>{let t=Wa.getState().currentSessionId,n=(t?Wa.getState().getDirectoryForSession(t):null)??Sn??``;if(!t||!n){Da.getState().clearEstablishing(e);return}VE({draftID:e,sessionID:t,directory:n,transportIdentity:u(),runtimeGeneration:f(),admitServer:Ia.mode===`server`?async e=>Ia.actions.admit({requestID:e.requestID,scope:{directory:n,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?pu(e.attachments):void 0}):void 0})},I=!n&&!b,L=K.kind===`primary`&&vn&&O===`queue`&&!n&&!b&&!y&&!C&&m===`normal`?Nt(`msg`):void 0,R=()=>{L&&Go(e=>e?.item.messageID===L?null:e)};L&&vn&&(w&&qo(e=>{if(e.has(L))return e;let t=new Set(e);return t.add(L),t}),Go({sessionID:vn,runtime:hn.captureRuntime(),item:{kind:`pending-admission`,requestID:L,queueItemID:L,operationID:L,messageID:L,content:h,createdAt:Date.now(),phase:`admitting`,attachmentCount:Ni.length,composerDocument:c.document,composerMentions:Dr}}));let z=fo?Wg.getState().quotesByKey[fo]??[]:[],B=zg(z,h)!==h,V=!1,H=()=>{!V||!fo||(Wg.getState().restore(fo,z),V=!1)};I&&(gr(``),B&&fo&&(Wg.getState().clear(fo),V=!0),he(-1),lr(!1));let U=!1,W,ee,te=hn.captureRuntime(),G=!1;try{if(LE({surfaceKind:K.kind,currentSessionId:vn,queuedOnly:n,delivery:O,resourcePolicy:b,inputMode:m,localCommand:y,nativeGoal:C})&&vn){let e=Wa.getState().getDirectoryForSession(vn)??Sn??null,t=Wa.getState().stagedMessageEdit;t&&t.sessionId===vn&&(ee={sessionId:t.sessionId,messageId:t.messageId},Wa.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=ei.getState(),r=hD({captured:pD(n,{expectedConfigKey:Gr(e),activeDirectoryKey:n.activeDirectoryKey}),surfaceSelection:K.selection.value});if(!ee&&r?.providerID&&r?.modelID){let t=VO(Ni);W=qr({sessionId:vn,directory:e,content:B?zg(z,h):h,providerID:r.providerID,modelID:r.modelID,agent:r.agent,variant:r.variant,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=K.kind===`primary`?(()=>{if(n){let e=j[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(ja?.sessionID)return ja.sessionID}return vn})():null,i=n?j[0]?.sendConfig:void 0;if(n&&i||await K.selection.flush(),e!==null&&Wa.getState().currentSessionId!==e)return;let a=async()=>{let t=i?{...i}:K.kind===`primary`?(()=>{let t=ei.getState();if(!e)return hD({captured:pD(t),surfaceSelection:K.selection.value});let n=Wa.getState().getDirectoryForSession(e)??Sn??null;return hD({captured:pD(t,{expectedConfigKey:Gr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:K.selection.value})})():K.selection.value.providerID&&K.selection.value.modelID?{...K.selection.value,providerID:K.selection.value.providerID,modelID:K.selection.value.modelID}:void 0;if(K.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=Wa.getState().getDirectoryForSession(e)??Sn??null,r=Gr(n);if(ei.getState().activeDirectoryKey!==r&&await ei.getState().activateDirectory(n),Wa.getState().currentSessionId===e){let e=ei.getState();t=hD({captured:pD(e,{expectedConfigKey:Gr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:K.selection.value})}}return t},s=await a(),u=!1,f=s?.providerID,p=s?.modelID,_=s?.agent,v=s?.variant;if(!f||!p){if(!u){u=!0;try{await ei.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),s=await a(),f=s?.providerID,p=s?.modelID,_=s?.agent,v=s?.variant}catch{}}if(!f||!p){console.warn(`Cannot send message: provider or model not selected`),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}}vn&&!n&&!b&&!C&&O!==`queue`&&await So(vn)&&await hi(vn);let x={...O?{delivery:O}:{},commitStagedMessageEdit:!n&&O!==`queue`,...W?{messageID:W.messageID,ticket:W}:L||N?{messageID:L??N}:{},...e?{sessionId:e,directoryHint:Wa.getState().getDirectoryForSession(e)??Sn??null}:K.kind===`primary`&&vn?{sessionId:vn,directoryHint:Wa.getState().getDirectoryForSession(vn)??Sn??null}:{}},S=``,T=[],D,k=[],A=new Set(Qi(Fn,Sn).map(e=>e.name)),I=[],V=b?void 0:hn.consumeSyntheticParts();for(let e=0;e<j.length;e++){let t=j[e],n=t.composerDocument&&be(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Sn,a=new Set(Qi(Fn,i).map(e=>e.name)),o=Xl({plan:r??Yl(t.content),agents:Gn,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(I.push(...o.semantics),!D&&o.agent&&(D=o.agent),e===0)S=o.text,T=mo([...VO(t.attachments),...o.attachments]);else{let e=VO(t.attachments);k.push({text:o.text,attachments:mo([...e,...o.attachments])})}}if(!n&&c.hasContent){let e=VO(Ni),t=Xl({plan:g,agents:Gn,installedSkillNames:A,directory:Sn,root:pi||Sn,confirmedFilePaths:Tr.map(e=>e.path),confirmedDirectoryPaths:Tr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ni});I.push(...t.semantics),!D&&t.agent&&(D=t.agent);let n=B?zg(z,t.text):t.text;j.length===0?(S=n,T=mo([...e,...t.attachments])):k.push({text:n,attachments:mo([...e,...t.attachments])})}let ne=vn??(bn?`draft`:null),re=[];if(!n&&ne&&!b&&(re=[...hn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),re.length>0)if(j.length===0)S=_h(S,re);else if(k.length>0){let e=k[k.length-1];e.text=_h(e.text,re)}else S=_h(S,re);if(V&&V.length>0&&k.push(...au(V)),Ta&&k.push({text:Ta.contextText,synthetic:!0}),Oa&&(k.push({text:Oa.instructionsText,synthetic:!0}),k.push({text:Oa.contextText,synthetic:!0})),k.push(...vo(I,vn&&Wa.getState().getDirectoryForSession(vn)||Sn)),!S&&T.length===0&&k.length===0)return;if(M&&N){if(!await aa({messageID:N,providerID:f,modelID:p,agent:_,text:S,attachments:T,additionalParts:k,agentMentionName:D}))return;if(!Da.getState().isEstablishing(M)){P();return}}let ie=async()=>{if(H(),P(),ja&&j.length>0&&It.setState(e=>{let t=cn(ja),n=e.queuedMessages[t]??[],r=new Set(j.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...j,...n.filter(e=>!r.has(e.id))]}}}),n)return V&&hn.restoreSyntheticParts(V),!0;hn.pendingInput?.text===c.message&&hn.consumePendingInput(),l&&wr(l);let e=!0;return d.length>0&&(e=await hn.restoreAttachments(d)),V&&hn.restoreSyntheticParts(V),re.length>0&&hn.restoreInlineDrafts(re),e};if(!b&&vn&&r){let e=ja?Qt(It.getState(),ja).find(e=>e.id===r||e.queueItemID===r):void 0;ja&&e?.queueItemID&&e.operationID&&Ka(ja,e.queueItemID,e.operationID)}else!b&&vn&&j.length>0&&ja&&Ga(ja);!n&&!b&&(gr(``),he(-1),lr(!1),IE({queuedOnly:n,resourcePolicy:b,rootAttachmentCount:d.length})&&hn.clearAttachments());let ae=()=>PE({currentSessionId:vn,messageRef:Xr,replacePlainDocument:gr}),oe=S.trimStart();if(m===`normal`&&oe.startsWith(`/`)){let e=Rc(oe.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Bc(e,e=>py(K,{name:e.name,source:`yuri`})))return;if(vn&&(e===`undo`||e===`redo`)&&AC(oe,m)&&ae(),e===`undo`&&vn){try{await Wa.getState().handleSlashUndo(vn),t?.()}catch(e){no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){AC(oe,m)&&ae(),await pn?.shortcut(`new`);return}if(e===`redo`&&vn){try{await Wa.getState().handleSlashRedo(vn),t?.()}catch(e){no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&vn){await FE({command:`fork`,consumeCommandText:ae,forkSession:()=>Wa.getState().forkCurrentSession(vn),waitForConnection:da,getDirectoryForSession:()=>Wa.getState().getDirectoryForSession(vn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&vn&&ri.timeline){ur(!0);return}if(e===`reload`&&E()){ae(),no.info(o(`chat.chatInput.toast.reloadStarted`)),La().then(()=>{no.success(o(`chat.chatInput.toast.reloadSucceeded`))},()=>{no.error(o(`chat.chatInput.toast.reloadFailed`))});return}if(e===`compact`&&vn){FE({command:`compact`,consumeCommandText:ae,forkSession:async()=>void 0,waitForConnection:da,getDirectoryForSession:()=>K.directory??``,summarizeSession:e=>Cn?K.backend.compact({operation:`compact`,surfaceID:K.surfaceID,transportIdentity:K.transportIdentity,runtimeGeneration:K.runtimeGeneration,sessionID:vn,directory:e,draftKey:Cn,deliveryTarget:K.deliveryTarget,providerID:f,modelID:p,agent:_,variant:v}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{no.error(o(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&vn){try{await da();let e=oe.replace(/^\/\u2003?summary\b/i,``).trim(),n=e?` focused on: ${e}`:``,r=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await Jo(`session.summary.visible`,{topic_line:n}),a=await Jo(`session.summary.instructions`,{topic_block:r});await Tn(i,f,p,_,[],D,[{text:a,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(vn||bn)){try{await da();let e=await Jo(`session.review.visible`),n=await Jo(`session.review.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.reviewFailed`))}return}if(e===`craft-goal`&&(vn||bn)){try{await da();let e=oe.replace(/^\/\u2003?craft-goal\b/i,``).trim(),n=await Jo(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),r=await Jo(`session.craftGoal.instructions`);await Tn(n,f,p,_,[],D,[{text:r,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(vn||bn)){try{await da();let e=await Jo(`session.catchup.visible`),n=await Jo(`session.catchup.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(vn||bn)){try{await da();let e=await Jo(`session.debug.visible`),n=await Jo(`session.debug.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(vn||bn)){try{await da();let e=await Jo(`session.weigh.visible`),n=await Jo(`session.weigh.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(vn||bn)){try{await da();let e=await Jo(`session.explore.visible`),n=await Jo(`session.explore.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.exploreFailed`))}return}}let se=vn&&Wa.getState().getDirectoryForSession(vn)||Sn;if(xn||vn&&!MO(vn,se)){let e=await bo().catch(()=>null);e&&k.push({text:Et(e),synthetic:!0})}G=!0;let ce=Tn(S,f,p,_,T,D,k.length>0?k:void 0,v,m,x);U=!0,ce.finally(()=>{R(),Ro(),ee&&Du(te,hn.captureRuntime())&&Wa.getState().endMessageEditCommit(ee.sessionId,ee.messageId)}).catch(()=>{}),M&&ce.then(()=>{F(M)}).catch(()=>{Da.getState().clearEstablishing(M)}),typeof window>`u`?t?.():window.requestAnimationFrame(()=>{t?.()}),ce.then(async()=>{if(w&&L&&e){let t=()=>{qo(e=>{if(!e.has(L))return e;let t=new Set(e);return t.delete(L),t})};if(Zt(e,L)||!Wt({sessionID:e}))t();else{let n=Wa.getState().getDirectoryForSession(e)??Sn??``;try{await St({sessionID:e,inboxID:L,directory:n})}catch{t(),ln.getState().list(e).some(e=>e.id===L)&&no.error(o(`chat.chatInput.toast.messageSendFailed`))}}}Ta&&Ea(null),Oa&&ka(null)}).catch(e=>{W&&Gi(W),ie().then(e=>{e||no.error(o(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){no.error(o(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){d.length>0&&no.error(o(`chat.chatInput.toast.sendAttachmentsFailed`));return}no.error(t||o(`chat.chatInput.toast.messageSendFailed`))}),Zn||Ar.current?.focus()}finally{G||(W&&Gi(W),ee&&Du(te,hn.captureRuntime())&&Wa.getState().endMessageEditCommit(ee.sessionId,ee.messageId)),U||(R(),I&&l&&(wr(l),H()),Ro(),M&&F(M))}}),us=J(()=>{if(OC(Ao().message,m)===`btw`){ls();return}if(es()||zo())return;let e=Ao(),t=m===`normal`&&e.hasContent&&vn&&To,n=t&&O_(Ia.mode)&&_u(K.deliveryTarget?.kind,Ia.mode),r=UE({followUpBehavior:Aa,ctrlEnter:!1,canQueue:!!t,queueUsable:!!n,primary:K.kind===`primary`,sessionIsRunning:To});r.kind===`queue`?ns():r.delivery?ls({delivery:r.delivery}):ls()}),ds=J(e=>{if(zo())return;let t=(Ar.current?.value??Xr.current).trim(),n=t?`${e}\n${t}`:e;ls({presetText:n})}),fs=J(e=>{let t=ak(ti().text,e);Or(t),Ar.current&&(Ar.current.value=t),setTimeout(()=>{Ar.current?.focus()},0)}),ps=Z.useRef(null),ms=J(()=>{ha(null);let e=ti().text;ps.current={base:e,expected:e}}),hs=J((e,t=!1)=>{let n=ps.current;if(!n)return;if(ti().text!==n.expected){ps.current=null,ha(null);return}let r=ak(n.base,e),i=e.trim();ha(t||!i?null:{draftID:$t,text:r,start:r.length-i.length-1,end:r.length-1}),r!==n.expected&&(Or(r),Ar.current&&(Ar.current.value=r),n.expected=r),t&&(ps.current=null)}),gs=J(e=>hs(e,!0)),_s=J(()=>{ha(null),ps.current=null}),vs=J(e=>{if(zo())return;let t=ak(Ar.current?.value??Xr.current,e);ls({presetText:t})}),ys=Z.useRef(null),bs=J(e=>{let t=ti().text,n=ak(t,e);ys.current={base:t,expected:n},Or(n),Ar.current&&(Ar.current.value=n)}),xs=J((e,t)=>{let n=ys.current;if(ys.current=null,!n||ti().text!==n.expected)return;let r=ak(n.base,e);Or(r),Ar.current&&(Ar.current.value=r),t&&us()}),Ss=J(e=>xs(e,!1)),Cs=J(e=>xs(e,!0)),ws=J(()=>{ys.current=null}),Ts=hn.pendingPreset,Es=hn.consumePendingPreset;Z.useEffect(()=>{if(Ts==null)return;let e=Es();e&&ds(e)},[Ts,Es,ds]);let Ds=J(()=>{gr(``),he(-1),_n.length>0&&hn.clearAttachments(),ja&&Ga(ja),T(!1),x(!1),m===`shell`&&h(`normal`)}),Os=J(e=>{if(!K.active||Mc(e))return;if(ui&&rs(e,ui)&&!nr){let t=Ar.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),Ds();return}}if(m===`shell`&&e.key===`Escape`){e.preventDefault(),h(`normal`);return}if(m===`shell`&&e.key===`Backspace`&&mr.length===0){e.preventDefault(),h(`normal`);return}if(e.key===`Backspace`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&po.length>0){let t=Ar.current,n=t?.selectionStart??0,r=t?.selectionEnd??0;if(n===0&&r===0&&fo){e.preventDefault(),Wg.getState().removeLast(fo);return}}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Ar.current,n=t?.selectionStart??mr.length,r=t?.selectionEnd??mr.length,i=br({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=jO(dr.getDocument().text,i.start);e.preventDefault(),Or(t.text),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(t.caret,t.caret),Zs()}),Qs(t.text,t.caret);return}let a=Ce(mr,_n.filter(_e).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=jO(a.text,a.caret);e.preventDefault(),Or(n.text);for(let e of _n)t.has(e.filename.toLowerCase())&&hn.removeAttachment(e.id);requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=n.caret,Ar.current.selectionEnd=n.caret),Zs()}),Qs(n.text,n.caret);return}let o=vc(mr,Hi.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=jO(o.text,o.caret);e.preventDefault(),Or(t.text),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=t.caret,Ar.current.selectionEnd=t.caret),Zs()}),Qs(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<mr.length){let n=qt(mr,_n.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=ht(mr.slice(n.start+1,n.end-1)).trim(),r=_n.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=mr[n.end]===` `?n.end+1:n.end,a=`${mr.slice(0,n.start)}${mr.slice(i)}`;e.preventDefault(),Or(a),r&&hn.removeAttachment(r.id),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=n.start,Ar.current.selectionEnd=n.start),Zs()}),Qs(a,n.start);return}let r=Dr.find(n=>(n.kind===`file`||n.kind===`directory`)&&mr.slice(n.range.start,n.range.end)===`@${n.value}`&&(t>=n.range.start&&t<n.range.end||e.key===`Backspace`&&mr[t]===` `&&n.range.end===t));if(r){let t=mr[r.range.end]===` `?r.range.end+1:r.range.end,n=`${mr.slice(0,r.range.start)}${mr.slice(t)}`;e.preventDefault(),Or(n),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=r.range.start,Ar.current.selectionEnd=r.range.start),Zs()}),Qs(n,r.range.start);return}let i=t;for(;i>0&&!/\s/.test(mr[i-1]);)--i;let a=t+1;for(;a<mr.length&&!/\s/.test(mr[a]);)a+=1;let o=mr.slice(i,a),s=o.slice(1);if(TO.test(o)&&!Fi.current.has(s.toLowerCase())&&Eo({mention:s,confirmed:kr.has(s),terminated:a<mr.length&&/\s/.test(mr[a])})){let t=mr[a]===` `?a+1:a,n=`${mr.slice(0,i)}${mr.slice(t)}`;e.preventDefault(),Or(n),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=i,Ar.current.selectionEnd=i),Zs()}),Qs(n,i);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(w&&Yr.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Yr.current.handleKeyDown(e.key);return}if(b&&Kr.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Kr.current.handleKeyDown(e.key);return}if(Di&&e.key===`Escape`){e.preventDefault(),lr(!1);return}let n=li&&!li.includes(`shift`)?As(`shift+${li}`):``,r=n&&rs(e,n)?-1:+!!rs(e,li);if(r!==0&&!w&&!b){e.preventDefault(),e.stopPropagation(),pn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Ar.current?.focus({preventScroll:!0})});return}let i=w||b,a=Ar.current?.selectionStart===0&&Ar.current?.selectionEnd===0,o=Ar.current?.selectionStart===mr.length&&Ar.current?.selectionEnd===mr.length,s=!i&&(mr.length===0||a),c=!i&&(mr.length===0||o);if(m===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Ar.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),Or(t),requestAnimationFrame(()=>{let e=Ar.current;e&&(e.selectionStart=n,e.selectionEnd=r),Zs()}),Qs(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=mr.slice(n,r);t(`${mr.slice(0,n)}${a}${s}${o}${mr.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=mr.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${mr.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&ro.length>0){if(e.preventDefault(),me===-1)he(0),xr({text:ro[0],references:[]});else if(me<ro.length-1){let e=me+1;he(e),xr({text:ro[e],references:[]})}requestAnimationFrame(()=>{Ar.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&me>=0){if(e.preventDefault(),me===0)he(-1),Sr();else{let e=me-1;he(e),xr({text:ro[e],references:[]})}return}if(!(e.key===`Enter`&&Zn&&!e.ctrlKey&&!e.metaKey)&&e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),OC(Ao().message,m)===`btw`){ls();return}if(es()||zo())return;let t=e.ctrlKey||e.metaKey,n=m===`normal`&&ho&&vn&&To,r=n&&O_(Ia.mode)&&_u(K.deliveryTarget?.kind,Ia.mode),i=UE({followUpBehavior:Aa,ctrlEnter:t,canQueue:!!n,queueUsable:!!r,primary:K.kind===`primary`,sessionIsRunning:To});i.kind===`queue`?ns():i.steerAfterAdmit?ls({steerAfterAdmit:!0}):i.delivery?ls({delivery:i.delivery}):ls()}}),ks=J(()=>{if(!Di){va(null);return}if(!w&&!b){va(null);return}let e=Ar.current,t=Ir.current;if(!e||!t)return;let n=HO(e,e.selectionStart??mr.length);if(!n)return;let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=r.top-i.top+(n.top-e.scrollTop),o=r.left-i.left+(n.left-e.scrollLeft),s=a-8,c=i.height-a-8,l=c>=260||c>=s?`below`:`above`,u=b?520:w?450:360,d=Math.max(8,Math.min(o-24,i.width-u-8)),f=Math.max(120,Math.min(260,l===`below`?c:s));va({top:l===`below`?a+22:a-6,left:d,place:l,maxHeight:f})});Z.useLayoutEffect(()=>{ks()},[ks,mr,w,b,Di]),ir(`resize`,ks,()=>Di?window:null);let js=J(()=>{ya.current&&=(clearTimeout(ya.current),null),wi(!0),ya.current=setTimeout(()=>{wi(!1),ya.current=null},1800)}),Ms=Z.useRef(new Set),[Ps,Fs]=Z.useState(()=>new Set),Is=JSON.stringify([K.transportIdentity,K.runtimeGeneration,K.surfaceID,K.directory,vn]),Ls=ko&&Ps.has(Is),Rs=J(async()=>{if(Ms.current.has(Is))return;let e=Is;Ms.current.add(e),Fs(new Set(Ms.current)),hn.abortPrompt.clear(),js();let t;try{let e=K.kind===`secondary`?pn?.shortcut(`abort`):En();await Promise.race([e,new Promise(e=>{t=setTimeout(()=>{K.kind===`secondary`&&no.error(o(`chat.chatInput.stopUnconfirmed`)),e()},5e3)})])}catch(e){console.error(`[ChatInput] abort failed`,e)}finally{clearTimeout(t),Ms.current.delete(e),Fs(new Set(Ms.current))}}),zs=J((e=1)=>{if(qn)return;let t=Qr(Gn,K.selection.value.agent??Mn,e);if(!t||!K.selection.change)return;let n=Ui({providerID:K.selection.value.providerID??``,modelID:K.selection.value.modelID??``,agent:K.selection.value.agent??null},t,Gn,Kn);K.selection.change({...K.selection.value,...n,agent:n.agent??void 0}),K.kind===`primary`&&(q.getState().addRecentAgent(t),K.sessionID&&Oi.getState().saveSessionAgentSelection(K.sessionID,t))});ge.current=zs;let[Bs,Vs]=Z.useState(null),[Hs,Us]=Z.useState(!1),Ws=Z.useRef(null),Gs=Z.useRef(!0);Z.useLayoutEffect(()=>{Gs.current=!0},[$t]),Z.useLayoutEffect(()=>{let e=Ws.current;e&&(Hs||la)&&Gs.current&&(e.scrollLeft=e.scrollWidth)},[mr,Hs,la]);let Ks=J(e=>{Vs(t=>t===e?t:e)}),qs=Zn&&!$i&&!Ai&&mr.length>0,[Js,Ys]=Z.useState(!1),{size:Xs,resize:Zs}=KD({inputRef:Ar,message:mr,expanded:Ai,isMobile:Zn,dictationHeight:Bs,manualHeight:qs&&Js});Z.useLayoutEffect(()=>{if(!Zn||!Hs)return;let e=Ar.current;e&&(e.style.overflowY=`auto`,e.scrollTop=e.scrollHeight,Ti.current&&(Ti.current.style.transform=`translateY(-${e.scrollTop}px)`))},[Zn,Hs,mr]);let Qs=J((e,t,n=`manual`,r)=>{let i=Fc({text:e,cursor:t,inputMode:m,mentionInputSource:n,insertedText:r});if(Fr.current=i,!i){T(!1),x(!1);return}if(i.kind===`slash-command`){k(i.query),T(!0),x(!1);return}T(!1),C(i.query),x(!0)}),$s=J((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(m===`normal`&&!Nr.current&&Ki.size>0&&e.includes(`/`)){let r=Lc(e,Ki,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=vr(a,o,s,(e,t)=>{let n=[...e];for(let i of Do(t.text,{agentNames:Pi,includeUnterminatedPastedReferences:r===`paste`,confirmedValues:new Set(e.flatMap(e=>e.kind===`file`||e.kind===`directory`?[e.value]:[]))}))n=Qc(n,{kind:i.kind,value:i.value,path:i.value,label:i.value,range:{start:i.start,end:i.end}});return n}),l=ti(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return u&&requestAnimationFrame(()=>{let e=Ar.current;e&&cy(u,Nr.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end))}),Qs(l.text,c.end,r,i),{document:l,selection:c}}),ec=J((e,t=`manual`)=>{if(!e)return;let n=Ar.current;if(!n){let n=mr+e;$s(n,n.length,n.length,t,e);return}let r=n.selectionStart??mr.length,i=n.selectionEnd??mr.length,a=`${mr.substring(0,r)}${e}${mr.substring(i)}`,o=r+e.length;$s(a,o,o,t,e)}),tc=J((e,t)=>{let n=new Set(fn(_n.map(e=>e.filename),e,t));if(n.size!==0)for(let e of _n)n.has(e.filename)&&hn.removeAttachment(e.id)}),nc=J(e=>{hn.removeAttachment(e.id)}),rc=J(()=>{zr.current=!1,Ur.current=[],Br.current&&=(clearTimeout(Br.current),null)}),ic=J(()=>{Br.current&&clearTimeout(Br.current),Br.current=setTimeout(()=>{rc()},700)}),oc=J(()=>{Vr.current=!1,Hr.current&&=(clearTimeout(Hr.current),null)}),cc=J(()=>{Vr.current=!0,Hr.current&&clearTimeout(Hr.current),Hr.current=setTimeout(()=>{Vr.current=!1,Hr.current=null},700)}),uc=J(e=>{!E()||!zr.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),rc())}),fc=J(e=>{if(nr)return;let t=e.nativeEvent;if(E()&&zr.current){let n=Ur.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){rc();return}}let n=e.target.value;tc(Xr.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?kO(Xr.current,n):``,a=i.includes(`@`)||Vr.current;Vr.current&&oc();let o=a?`paste`:`manual`;if(m===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);h(`shell`),gr(e),Zs(),T(!1),x(!1),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=t,Ar.current.selectionEnd=t)});return}$s(n,r,e.target.selectionEnd??r,o,i)});Z.useEffect(()=>()=>{rc(),oc()},[rc,oc]);let gc=J(e=>{let t=Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)));if(t.length===0)return;let n=t.map(e=>`@${e}`).join(` `),r=Ar.current,i=r?.selectionStart??mr.length,a=r?.selectionEnd??mr.length,o=Xc(n,mr.slice(0,i),mr.slice(a)),s=`${mr.slice(0,i)}${o}${mr.slice(a)}`;tc(mr,s),ni(s,t);let c=rl(s,i+o.length);Pr.current=c,x(!1),C(``),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(c,c),Zs(),Qs(s,c)})}),yc=J(async e=>{let t=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),n=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),r=t.length>0?t:(()=>{if(n.length<=1)return n;let e=n.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[n[0]]})(),i=LO(e.clipboardData);if(r.length===0&&i.length>0&&(vn||bn)){e.preventDefault(),gc(i);return}if(r.length===0&&m===`normal`&&(vn||bn)){let t=Ar.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=mr.slice(n,r);if(DO.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${mr.slice(0,n)}[${i}](${t})${mr.slice(r)}`,o=n+1+i.length+2+t.length+1;Or(a),requestAnimationFrame(()=>{let e=Ar.current;e&&(e.selectionStart=o,e.selectionEnd=o),Zs()}),Qs(a,o,AO(t),t);return}}}let a=e.clipboardData.getData(`text`),s=r.length>0&&i.includes(lC(a.trim().replace(/^(['"])(.*)\1$/,`$2`)))?``:a;if(r.length===0){if(m===`normal`&&OD(ti(),s)){e.preventDefault();let t=ti().text,n=Ar.current,r=n?.selectionStart??mr.length,i=n?.selectionEnd??mr.length,a=kD(s,mr,ti().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>o(`chat.chatInput.pastedTextReference`,{index:e,count:t}),DD(ti())),c=yr(r,i,{id:a.id,kind:`paste`,text:a.text,characterCount:a.characterCount,index:a.index,display:a.token},{inlineBoundaries:!0,padDocumentEdges:!0}),l=rl(c.document.text,c.caret);Ar.current&&(Ar.current.value=c.document.text),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(l,l),Zs()}),Qs(c.document.text,l),tc(t,c.document.text);return}s.includes(`@`)&&cc();return}if(!vn&&!bn){s.includes(`@`)&&cc();return}e.preventDefault();let c=mn(r,[..._n.map(e=>e.filename),...Zr.current]),l=kt(c),u=ti().text,d=Ar.current,f=d?.selectionStart??mr.length,p=d?.selectionEnd??mr.length,h=m===`normal`&&OD(ti(),s)?kD(s,mr,ti().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>o(`chat.chatInput.pastedTextReference`,{index:e,count:t}),DD(ti())):null,g=s?`${s}${/\s$/.test(s)?``:` `}${l}`:l,_=Xc(g,mr.slice(0,f),mr.slice(p));if(h){let e=yr(f,p,{id:h.id,kind:`paste`,text:h.text,characterCount:h.characterCount,index:h.index,display:h.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=rl(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${l}${e.document.text.slice(t)}`;$s(n,t+l.length,t+l.length,AO(n),l),tc(u,n)}else ec(_,AO(_)),tc(u,`${mr.slice(0,f)}${_}${mr.slice(p)}`);for(let e=0;e<r.length;e+=1){let t=c[e],n=OO(r[e],t);Zr.current.add(t);try{await hn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.clipboardAttachFailed`))}finally{Zr.current.delete(t)}}}),bc=J((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=Pc(r,i,[...qt(mr,_n.filter(_e).map(e=>e.filename)),..._c(mr,Hi.keys()),...ti().references]),o=a?.start??r,s=a?.end??i,c=mr.slice(o,s),l=Fe(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${mr.slice(0,o)}${mr.slice(s)}`;$s(e,o,o),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(o,o),Zs()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Ar.current?.setSelectionRange(o,s)})}),xc=J(e=>{bc(e,`copy`)}),Tc=J(e=>{bc(e,`cut`)}),Ec=e=>{let t=Ar.current,n=t&&document.activeElement===t?t.selectionStart??Pr.current:Pr.current;return Sl(e,n)},Dc=()=>{Pl(Zn)||Ar.current?.focus()},Oc=J(e=>{let t=Ec(mr.length),n=Ic(mr,t,Fr.current),r=mr.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():$c(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=tl(mr,o,s,`@${i}`);ni(c.text,[i],a),Pr.current=c.caret,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=c.caret,Ar.current.selectionEnd=c.caret),Zs(),Qs(c.text,c.caret)}),x(!1),C(``),Dc()}),kc=J(e=>{let t=Ec(mr.length),n=Ic(mr,t,Fr.current),r=mr.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=tl(mr,i,a,`@${e}`);Or(o.text,t=>Qc(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Pr.current=o.caret,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=o.caret,Ar.current.selectionEnd=o.caret),Zs(),Qs(o.text,o.caret)}),x(!1),C(``),Dc()}),Ac=J(e=>{Jr.current||(Jr.current=!0,(async()=>{try{let t=Wa.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){no.error(o(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await Be(e.id,{directory:t}),!Pt(e.id,t)){no.error(o(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}!Zn&&!D()&&!vi()&&xi([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=ti(),r=Ec(n.text.length),i=Ic(n.text,r,Fr.current),a=n.text.substring(0,r).lastIndexOf(`@`),s=Ne().get(e.id)?.title||e.title||e.id,c=i?.start??(a===-1?r:a),l=i?.end??r,u={id:`session:${e.id}:${Jn()}`,kind:`session`,sessionId:e.id,display:Re({trigger:`@`,icon:`chat-thread`,label:s})},d=yr(c,l,u,{inlineBoundaries:!0,padDocumentEdges:!0}),f=rl(d.document.text,d.caret);Pr.current=f,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=f,Ar.current.selectionEnd=f),Zs(),Qs(d.document.text,f)}),x(!1),C(``),Dc()}catch{no.error(o(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Jr.current=!1}})())}),zc=J(e=>{let t=ti(),n=Ec(t.text.length),r=Ic(t.text,n,Fr.current)??Uc(t.text,n);if(!r)return!1;let i=yr(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=rl(i.document.text,i.caret);return Pr.current=o,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=o,Ar.current.selectionEnd=o),Zs(),Qs(i.document.text,o),a&&(T(!1),x(!1))}),Dc(),a}),Vc=J(e=>{let t=ti(),n=Ec(t.text.length),r=Ic(t.text,n,Fr.current);if(!r)return;let i=yr(r.start,r.end,{id:`skill:${e.name}:${Jn()}`,kind:`skill`,skillName:e.name,display:Re({trigger:`@`,icon:`book-open`,label:e.name})},{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=rl(i.document.text,i.caret);Pr.current=a,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=a,Ar.current.selectionEnd=a),Zs(),Qs(i.document.text,a),x(!1),C(``)}),Dc()}),Gc=J((e,t=!1)=>{if(!py(K,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){zc({id:`skill:${e.name}:${Jn()}`,kind:`skill`,skillName:e.name,display:Re({trigger:`@`,icon:`book-open`,label:e.name})})&&k(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&zc({id:`command:${e.name}:${Jn()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:Re({trigger:`/`,icon:`command`,label:e.name})})){k(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=Lc(r,new Set([...Ki,e.name.toLowerCase()]),r.length);if(e.name===`btw`){let e=ti(),t=Uc(e.text,Ar.current?.selectionStart??e.text.length);if(t){let n=i?.text??r;Or(e.text.slice(0,t.start)+n+e.text.slice(t.end))}}else gr(i?.text??r);let a=Ar.current;if(a&&(a._commandMetadata=e),T(!1),k(``),t){ls({presetText:n});return}let o=()=>{if(!Pl(Zn)&&Ar.current){try{Ar.current.focus({preventScroll:!0})}catch{Ar.current.focus()}Ar.current.setSelectionRange(Ar.current.value.length,Ar.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)});Z.useEffect(()=>{vn&&Ar.current&&!Zn&&Ar.current.focus()},[vn,Zn]),Z.useEffect(()=>{Zn||F(null)},[Zn]);let qc=hn.abortPrompt.sessionID,Zc=hn.abortPrompt.clear;Z.useEffect(()=>{qc&&qc!==vn&&Zc()},[vn,qc,Zc]),Z.useEffect(()=>{Wr.current=!!(vn||bn)},[vn,bn]);let $c=J(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(pi||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t}),el=J(e=>{if(!UO(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Lr.current++;let t=e.dataTransfer.types?.includes(`application/x-yuri-file-path`)??!1;t!==v&&y(t),(vn||bn)&&!g&&_(!0)}),nl=J(e=>{UO(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(vn||bn)&&!g&&_(!0))}),il=J(e=>{e.preventDefault(),e.stopPropagation(),Lr.current--,Lr.current<=0&&(Lr.current=0,_(!1),y(!1),rc())}),ll=J(()=>{Lr.current=0,_(!1),y(!1),rc()}),ul=J(async e=>{if(Lr.current=0,!UO(e.dataTransfer)){rc();return}if(e.preventDefault(),e.stopPropagation(),_(!1),!vn&&!bn)return;let t=e.dataTransfer.getData(`application/x-yuri-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Ar.current,r=Xr.current;if(n){let t=n.selectionStart??Pr.current,i=n.selectionEnd??t,a=tl(r,t,i,e);Or(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Pr.current=a.caret,n.focus()})}else{let t=tl(r,r.length,r.length,e);Or(t.text)}rc();return}let n=LO(e.dataTransfer);if(n.length>0){E()&&(Ur.current=n),gc(n),E()||rc();return}let r=WO(e.dataTransfer);if(r.length>0){let e=kt(r.map(e=>e.name)),t=Xc(e,Xr.current.slice(0,Ar.current?.selectionStart??Xr.current.length),Xr.current.slice(Ar.current?.selectionEnd??Xr.current.length));ec(t);for(let e of r)try{await hn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.attachFileFailed`))}}rc()}),dl=J(e=>{UO(e.dataTransfer)&&(e.preventDefault(),E()&&(zr.current=!0,ic()))}),gl=Z.useRef(null),_l=Z.useRef(null),vl=J((e=!0)=>{ue.current=0;let t=()=>{let t=oy(Ar);if(!t||(sy(Ar),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),bl=J(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=kt(t.map(e=>e.name)),n=Xc(e,Xr.current.slice(0,Ar.current?.selectionStart??Xr.current.length),Xr.current.slice(Ar.current?.selectionEnd??Xr.current.length));ec(n)}for(let e of t)try{await hn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.attachFileFailed`))}}),xl=J(async()=>{try{let e=await ai?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6557
|
-
`);no.error(o(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(vl(!1),await bl(r),vl())}catch(e){console.error(`VS Code file pick failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.vscodePickFailed`))}}),Cl=J(()=>{if(E()){xl();return}gl.current?.click()}),wl=J(()=>{if(E()){xl();return}_l.current?.click()}),Tl=J(async()=>{if(!wc()){wl();return}try{let e=await pc(20);if(e===null){wl();return}e.length>0&&(vl(!1),await bl(e),vl())}catch(e){console.error(`Native photo pick failed`,e),no.error(o(`chat.chatInput.toast.attachFileFailed`))}}),Dl=J(async e=>{let t=e.target.files;!t||t.length===0||(vl(!1),await bl(t),e.target.value=``,vl())}),Ol=`gap-x-1.5 gap-y-0`,jl=E(),Ml=K.kind===`primary`&&xn&&!jl&&!dt,Nl=Z.useMemo(()=>(at?.selectedProjectId?Dn.find(e=>e.id===at.selectedProjectId)??null:null)||(On?Dn.find(e=>e.id===On)??null:null)||(Dn[0]??null),[On,at?.selectedProjectId,Dn]),Fl=Z.useMemo(()=>
|
|
6558
|
-
`)})),e.length!==0&&bl(e)},onRemoveAttachment:e=>{hn.removeAttachment(e)},onOpenModel:()=>oo(`model`),onCycleAgent:()=>zs(),onOpenAgent:os,showScrollToBottom:!!(n&&r),scrollAria:o(`chat.scrollToBottom.aria`),onScrollToBottom:r??(()=>{}),autocompleteOpen:A.length>0&&(w||b),autocompleteHighlightedIndex:M,autocompleteRows:A,autocompleteQuery:b?S:O,caret:Pr.current,onAutocompleteAccept:Cu,onAutocompleteDismiss:wu,chipHighlights:ga}):null,Au=Z.useRef(null);sr(Ou?Au:null,()=>{let e=Au.current?.getBoundingClientRect().height??0;El(document.documentElement,e)});let ju=Z.useRef(!1);ju.current=xa||Ca;let Mu=Z.useRef(!1),Pu=Z.useRef(0),Fu=Z.useRef(0),Iu=J(()=>{let e=Wa.getState().stagedMessageEdit;!e||e.sessionId!==vn||window.setTimeout(()=>{let t=Wa.getState().stagedMessageEdit,n=document.activeElement,r=RE({surfaceKind:K.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:zo(),focusHeld:Date.now()<Fu.current,overlayOpen:Pu.current>0||ju.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<ue.current});r.action===`disarm`&&Wa.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Zn||D()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Pu.current+=1},t=()=>{if(Pu.current=Math.max(0,Pu.current-1),Mu.current){Mu.current=!1;return}if(!pe.current||ju.current||Pu.current>0)return;if(ac()){pe.current=!1;return}pe.current=!1,Fu.current=Date.now()+600,Ar.current?.focus(),document.activeElement===Ar.current&&z(!0);let e=()=>{let e=Ar.current;!e||document.activeElement!==e||(Lu.current??e).scrollIntoView({block:`end`})};I.current!==null&&(window.clearTimeout(I.current),I.current=null),L.current!==null&&(window.clearTimeout(L.current),L.current=null),I.current=window.setTimeout(()=>{I.current=null,e()},300),L.current=window.setTimeout(()=>{L.current=null,e()},650)};return window.addEventListener(`yuri:mobile-overlay-opened`,e),window.addEventListener(`yuri:mobile-overlay-closed`,t),()=>{I.current!==null&&(window.clearTimeout(I.current),I.current=null),L.current!==null&&(window.clearTimeout(L.current),L.current=null),window.removeEventListener(`yuri:mobile-overlay-opened`,e),window.removeEventListener(`yuri:mobile-overlay-closed`,t)}},[Zn]),Z.useEffect(()=>{if(!Zn)return;if(vu){(R||Date.now()-fe.current<800)&&(pe.current=!0);return}if(!pe.current)return;let e=window.setTimeout(()=>{if(pe.current=!1,ac())return;let e=Ar.current;e&&document.activeElement!==e&&e.focus({preventScroll:D()})},180);return()=>window.clearTimeout(e)},[Zn,vu,R]),Z.useEffect(()=>{if(!Zn||D()||typeof document>`u`||R||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Ar.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[Zn,R]),Z.useEffect(()=>{re(``)},[ee]);let Lu=Z.useRef(null),Ru=!Zn&&K.kind===`primary`&&!!vn&&!Ai;Z.useLayoutEffect(()=>{if(!Ru)return;let e=Lu.current;if(!e)return;let t=e.offsetHeight;if(!(t<=0))return e.style.height=`${t}px`,()=>{e.style.height=``}},[vn,Ru]);let zu=Zn&&K.kind===`primary`&&!Ou,Bu=Z.useRef(null),Vu=Z.useRef(null),Hu=J(()=>{if(!zu)return;let e=Lu.current;if(!e?.closest(`.yuri-mobile-composer-foot--overlay`))return;let t=Au.current?.offsetHeight??0;if(Vu.current===null){if(e.offsetHeight<=0)return;Vu.current=Math.max(0,e.offsetHeight-t)}let n=mO(document.documentElement,Vu.current+t);n!==null&&(Bu.current=n)});sr(zu?Au:null,Hu),Z.useEffect(()=>{if(zu)return()=>{hO(document.documentElement,Bu.current),Bu.current=null,Vu.current=null}},[zu]);let Uu=Zn?`px-1.5 py-1.5`:jl?`px-1.5 py-1`:`px-2.5 py-1.5`,Wu=Zn?`h-8 w-8`:jl?`h-5 w-5`:`h-6 w-6`,Gu=Zn?`h-4 w-4`:jl?`h-3.5 w-3.5`:`h-4 w-4`,Ku=Zn?`h-6 w-6`:`size-full`,qu=Zn?`h-[1.125rem] w-[1.125rem]`:jl?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,Ju=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,Gv),Yu=Y(Ju,Wu),Xu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,Wu),Zu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,`h-6 w-6`);Z.useEffect(()=>()=>{ya.current&&=(clearTimeout(ya.current),null)},[]);let Qu=(0,$.jsx)(Oh,{quotes:po,removeLabel:o(`chat.btw.removeQuoteAria`),onRemove:e=>{fo&&Wg.getState().removeQuote(fo,e)}}),$u=J(()=>{de(),zs()}),ed=J(()=>oo(`model`)),td=Z.useMemo(()=>Zn?Kn.find(e=>e.id===K.selection.value.providerID):void 0,[Zn,Kn,K.selection.value.providerID]),nd=Zn?(0,$.jsxs)(`div`,{"data-composer-action":`true`,className:`composer-mobile-model-controls flex min-w-0 flex-1 items-center justify-end gap-x-1.5`,children:[(0,$.jsx)(XO,{onOpenAgentPanel:os,onCycleAgent:$u,agentName:K.selection.value.agent,agents:Gn,disabled:Yn}),(0,$.jsx)(ZO,{onOpenModel:ed,providerID:K.selection.value.providerID,modelID:K.selection.value.modelID,provider:td,variant:K.selection.value.variant})]}):null,rd=(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(qh,{attachments:_n,onShowPopup:er,onRemoveAttachedFile:nc}),K.kind===`primary`?(0,$.jsx)(Zh,{attachedFiles:_n,onAddVSCodeFile:(e,t,n)=>{Cn&&Pa(Cn,()=>fi.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Cn)return Pa(Cn,()=>fi.getState()).addVSCodeSelection(e,t)}}):null]}),id=ga?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Cc,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),ad=!Zn&&fa?(0,$.jsxs)($.Fragment,{children:[id??mr,(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`yuri-dictation-caret`,children:ma?.draftID===$t&&ma.text===mr&&(0,$.jsx)(`span`,{className:`yuri-dictation-caret-trail`},mr)})]}):id,od=Zn&&na?(0,$.jsx)($r,{variant:`ghost`,size:`icon`,className:Yu,"data-composer-action":`true`,"aria-label":o(la?`settings.voice.volcengine.finishRecording`:`chat.dictation.start`),"aria-pressed":la,disabled:!la&&(yn||Hs||ra!==null||!vn&&!bn),onClick:()=>window.dispatchEvent(new Event(`yuri:mobile-dictation-toggle`)),children:(0,$.jsx)(qm,{kind:`mic`,active:la,className:qu})}):null,sd=Zn?(0,$.jsxs)(`div`,{className:Y(`yuri-mobile-composer-compact-chrome`,ko&&`yuri-mobile-composer-compact-chrome--aborting`,Co&&!ko&&`yuri-mobile-composer-compact-chrome--sending`,n&&r&&`yuri-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(tk,{isVSCode:jl,footerIconButtonClass:Yu,iconSizeClass:qu,handlePickLocalFiles:Cl,handlePickLocalImages:wl,openIssuePicker:ss,openPrPicker:cs,onOpenMobileSheet:hu,onOpenAndroidPickSheet:Qn?gu:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`composer-mobile-actions ml-auto flex shrink-0 items-center justify-end gap-x-3`,children:[n&&r?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(fx,{placement:`compact`,visible:n,onClick:r})}):null,od,ko||Co||Ls?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(rk,{isMobile:!0,compact:!0,footerIconButtonClass:Yu,stopFooterIconButtonClass:Xu,compactCircleButtonClass:Zu,sendIconSizeClass:Gu,stopIconSizeClass:Ku,canSend:Co,canAbort:ko,abortPending:Ls,hasContent:!!ho,currentSessionId:vn,newSessionDraftOpen:bn,draftSubmitting:yn,submissionBlocked:i,sendPhase:Fo,queueFrozen:xo,queueFallbackAvailable:ko||To,onPrimaryAction:us,onAbort:Rs})}):null]})]}):null,cd=Zn?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-full-chrome flex w-full min-w-0 items-center gap-x-1.5`,"data-composer-action":`true`,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(tk,{isVSCode:jl,footerIconButtonClass:Yu,iconSizeClass:qu,handlePickLocalFiles:Cl,handlePickLocalImages:wl,openIssuePicker:ss,openPrPicker:cs,onOpenSettings:e,onOpenMobileSheet:hu,onOpenAndroidPickSheet:Qn?gu:void 0}),Pn?(0,$.jsx)(nk,{sessionId:vn,draftOpen:bn,draftEnabled:at.permissionAutoAcceptEnabled===!0,enabled:An,saving:vn?mt:!1,footerIconButtonClass:Yu,iconSizeClass:qu,onSetDraftEnabled:ft,onSetSessionEnabled:gt,onOpenSessionFirst:Ya,onToggleFailed:In}):null,(0,$.jsx)(xC,{sessionId:vn,directory:Ve??Sn,draftOpen:bn}),(0,$.jsx)(SC,{length:mr.length}),na&&(0,$.jsx)(YO,{interactionMode:`mobile`,disabled:yn||ra!==null||!vn&&!bn,onRecordingChange:ua,onActiveChange:Us,className:Yu,iconClassName:qu,onStart:ms,onPartial:hs,onInsert:gs,onCancel:_s},$t)]}),nd,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(rk,{isMobile:Zn,footerIconButtonClass:Yu,stopFooterIconButtonClass:Xu,sendIconSizeClass:Gu,stopIconSizeClass:Ku,canSend:Co,canAbort:ko,abortPending:Ls,hasContent:!!ho,currentSessionId:vn,newSessionDraftOpen:bn,draftSubmitting:yn,submissionBlocked:i,sendPhase:Fo,queueFrozen:xo,queueFallbackAvailable:ko||To,onPrimaryAction:us,onAbort:Rs})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,Ol,fa&&`[&>*:not([data-dictation-control])]:opacity-40`),children:[(0,$.jsx)(tk,{isVSCode:jl,footerIconButtonClass:Yu,iconSizeClass:qu,handlePickLocalFiles:Cl,handlePickLocalImages:wl,openIssuePicker:ss,openPrPicker:cs,onOpenSettings:e,withTooltip:!0}),Pn?(0,$.jsx)(nk,{sessionId:vn,draftOpen:bn,draftEnabled:at.permissionAutoAcceptEnabled===!0,enabled:An,saving:vn?mt:!1,footerIconButtonClass:Yu,iconSizeClass:qu,onSetDraftEnabled:ft,onSetSessionEnabled:gt,onOpenSessionFirst:Ya,onToggleFailed:In}):null,(0,$.jsx)(xC,{sessionId:vn,directory:Ve??Sn,draftOpen:bn}),(0,$.jsx)(SC,{length:mr.length}),ea&&!E()&&Gl()&&(0,$.jsx)(YO,{inputRef:Ar,onActiveChange:pa,onRecordingChange:ua,className:Yu,iconClassName:qu,onStart:ms,onPartial:hs,onInsert:gs,onCancel:_s},$t)]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,Ol,fa&&`opacity-40`),children:[(0,$.jsx)(KO,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Ar,selectionAdapter:Hn}),(0,$.jsx)(rk,{isMobile:Zn,footerIconButtonClass:Yu,stopFooterIconButtonClass:Xu,sendIconSizeClass:Gu,stopIconSizeClass:Ku,canSend:Co,canAbort:ko,abortPending:Ls,hasContent:!!ho,currentSessionId:vn,newSessionDraftOpen:bn,draftSubmitting:yn,submissionBlocked:i,sendPhase:Fo,queueFrozen:xo,queueFallbackAvailable:ko||To,onPrimaryAction:us,onAbort:Rs})]})]}),ud=J(()=>{if(Zn){Fu.current=Date.now()+600;let e=()=>{Ar.current?.focus({preventScroll:D()}),document.activeElement===Ar.current&&z(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!sy(Ar))return;let e=oy(Ar);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),dd=Ve??Sn,fd=K.kind===`secondary`?K.directory:Ve,{goal:pd,enabled:md}=dC(vn??``,dd),hd=(0,$.jsx)(fv,{onEditMessage:is,onSendMessage:as,onEditCommitted:ud,draftKey:Cn,scope:ja,draftTarget:Cn?{key:Cn,expectedRevision:()=>hn.getDraft(Cn)?.revision??`absent`}:null,clientPendingItems:Xo,compactionBarrier:Zo,steeringMessageIDs:Ko,onSteerClientPending:e=>{if(!vn||!Wt({sessionID:vn}))return;let t=Ve??Sn??``,n=vn;return qo(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n}),St({sessionID:n,inboxID:e,directory:t}).catch(()=>{qo(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),no.error(o(`chat.chatInput.toast.messageSendFailed`))})},onQueueClientPending:e=>{vn&&_t({sessionID:vn,inboxID:e,directory:Ve??Sn??``}).then(()=>{Yt(vn,e,`queue`)}).catch(()=>{no.error(o(`chat.chatInput.toast.messageSendFailed`))})},onRemoveClientPending:e=>{let t=Da.getState().removeEstablishingFollowUp(e);if(!t){vn&&He({sessionID:vn,inboxID:e,directory:Ve??Sn??``}).catch(()=>{no.error(o(`chat.chatInput.toast.messageSendFailed`))});return}t.content&&gr(t.content),t.attachments.length>0&&hn.restoreAttachments(t.attachments)},trailing:vn&&md&&pd?(0,$.jsx)(yC,{sessionId:vn,directory:dd}):null});return(0,$.jsxs)($.Fragment,{children:[ku,K.kind===`primary`&&vn?(0,$.jsx)(DE,{scope:{sessionId:vn,directory:Sn},active:K.active,mobile:Zn}):null,(0,$.jsxs)(`form`,{ref:Lu,onSubmit:e=>{e.preventDefault(),us()},onPointerDownCapture:e=>{Zn&&ay(e,de)},className:Y(`relative w-full pt-0 pb-4`,Ru&&`flex flex-col justify-end [&>.chat-input-column]:shrink-0`,Di&&`flex h-full min-h-0 flex-col pt-4`,ki&&`flex h-full min-h-0 flex-col pt-1`,Zn&&`bottom-safe-area yuri-mobile-composer`),"data-native-ios-composer":Ou?`true`:void 0,"data-mobile-expanded":ki?`true`:void 0,"data-hold-to-talk":na?`true`:void 0,"data-hold-to-talk-empty":na&&mr.length===0?`true`:void 0,"data-dictation-hint":na?ra??void 0:void 0,style:Zn&&D()&&!Ou&&rr>0&&!R?{marginBottom:`${rr}px`}:void 0,children:[xn&&!Di&&!Zn&&!jl&&!nu?(0,$.jsx)(`div`,{className:`chat-input-column mb-7 text-center`,children:(0,$.jsx)(`h1`,{className:`text-balance text-2xl font-normal tracking-tight text-foreground md:text-3xl`,children:BO(Il?o(`chat.emptyState.draftTitleWithProject`,{project:Il}):o(`chat.emptyState.draftTitle`),Il)})}):null,na&&(0,$.jsx)(hc,{containerRef:Lu,disabled:!vn&&!bn||yn||Hs,onInsert:Ss,onSend:Cs,onRelease:bs,onError:ws,onHintChange:ia},Cn?nt(Cn):vn??`new`),(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Ai&&`flex flex-1 min-h-0 flex-col`),children:[Ou?null:(0,$.jsx)(Jh,{attachments:_n,onShowPopup:er,onRemoveAttachedFile:nc}),Xa&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[$a>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:di?.colors?.surface?.elevated,borderColor:di?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:o(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:di?.colors?.status?.info},children:$a}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:to,"aria-label":o(`chat.chatInput.reviewCommentsRemove`),title:o(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Za>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:di?.colors?.surface?.elevated,borderColor:di?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:o(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:di?.colors?.status?.info},children:Za}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>eo(`preview-console`),"aria-label":o(`chat.chatInput.devServerLogsRemove`),title:o(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Qa>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:di?.colors?.surface?.elevated,borderColor:di?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:o(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:di?.colors?.status?.info},children:Qa}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>eo(`preview-annotation`),"aria-label":o(`chat.chatInput.previewContextRemove`),title:o(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),Ta&&!jl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Sa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Ta.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Ta.author.avatarUrl,alt:Ta.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,Ta.number,Ta.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:o(`chat.chatInput.linked.byAuthor`,{author:Ta.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Ta.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Ta.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Ea(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.issue.removeAria`),title:o(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),Oa&&!jl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>wa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Oa.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Oa.author.avatarUrl,alt:Oa.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[o(`chat.chatInput.linked.pr.number`,{number:Oa.number}),Oa.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:o(`chat.chatInput.linked.byAuthor`,{author:Oa.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Oa.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[Oa.head,` → `,Oa.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Oa.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{ka(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.pr.removeAria`),title:o(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)($O,{sessionId:vn,directory:Ve??Sn}),(0,$.jsxs)(`div`,{className:Zn?`relative yuri-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:Zn?`yuri-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:Zn?`yuri-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:Au,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(QO,{className:Zn?`mb-0`:void 0,showAbortStatus:bi,showAbortPrompt:!!(Di&&vn&&xt===vn&&typeof Ct==`number`&&Ct>Date.now()),showAssistantStatus:!1,showTodos:!0,insideInputColumn:!0,showPendingChanges:!bn&&ru}),!Zn&&Ml?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Nl?(0,$.jsxs)(hl,{value:Nl.id,open:oe,onValueChange:du,onOpenChange:e=>{se(e),e||ae(``)},children:[(0,$.jsx)(ml,{asChild:!0,size:`sm`,children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex h-6 min-w-0 w-fit max-w-[42vw] items-center rounded-lg !border-0 px-1.5 py-1 pr-1.5 typography-micro font-medium text-foreground/80 transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5 sm:max-w-[18rem]`,Uv),children:[(0,$.jsx)(cl,{children:GO(Nl)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`})]})}),(0,$.jsxs)(fl,{fitContent:!0,children:[(0,$.jsx)($o,{autoFocus:!0,value:ie,onChange:e=>ae(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:o(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),(0,$.jsx)(ek,{projects:Dn,query:ie,renderLabel:GO}),(0,$.jsx)(pl,{}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left typography-ui-label text-foreground hover:bg-interactive-hover`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),se(!1),requestAnimationFrame(()=>sa.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,Uv),onClick:()=>sa.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]}),Nl&&uu?(0,$.jsx)(JS,{directory:Ql,projectDirectory:Fl,label:tu,projectRootOption:ql,worktreeOptions:Zl,onSelectDirectory:mu}):null]}):null,Zn&&Ml?(0,$.jsxs)(`div`,{className:`yuri-mobile-draft-target-selectors mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Nl?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] shrink items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,Uv),onClick:()=>te(`project`),children:GO(Nl)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,Uv),onClick:()=>sa.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]}),Nl&&uu?(0,$.jsx)(JS,{directory:Ql,projectDirectory:Fl,label:tu,projectRootOption:ql,worktreeOptions:Zl,onSelectDirectory:mu,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,K.active&&vn&&fd?(0,$.jsx)(kv,{sessionId:vn,directory:fd}):null,hd]})}),(0,$.jsx)(`div`,{className:Y(!Zn&&`contents`,Zn&&`contents`,ki&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:Zn?`yuri-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(Nc,{value:mr,attachments:[],disabled:!vn&&!bn||yn&&!Fo.establishing,pending:ko||Fo.inFlight&&!Fo.establishing,isMobile:Zn,onSubmit:us,"data-mobile-composer-surface":Zn?`true`:void 0,expanded:Ai,className:Y(`relative z-10`,fa&&`!ring-0 [&_textarea]:caret-transparent`,g&&`ring-2 ring-primary ring-offset-2`,nr&&`ring-1 ring-[var(--interactive-selection)]`,Zn&&`yuri-mobile-composer-surface`),style:{borderRadius:ji,...fa?{borderColor:`var(--voice-active-fill)`}:{}},ref:Ir,onDropCapture:dl,onDragEnter:el,onDragOver:nl,onDragLeave:il,onDrop:ul,onDragEnd:ll,autoResize:!1,disableInputWhilePending:!1,contentClassName:Ai?`flex-1 min-h-0`:void 0,inputHeader:Qu,attachmentContent:rd,highlightedContent:ad,highlightRef:Ti,inputRef:Ar,textLayoutClassName:Y(bO,Ai?Y(`h-full min-h-0`,Zn?`py-2.5`:`py-4`):Zn?`py-2.5`:`pt-4 pb-2`,m===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Ai&&`flex-1 min-h-0`),inputStyle:{flex:Ai?`1 1 auto`:`none`,height:!Ai&&Xs?`${Xs.height}px`:void 0,maxHeight:!Ai&&Xs?`${Xs.maxHeight}px`:void 0,"--yuri-composer-textarea-resting-height":Ai?`100%`:Xs?`${Xs.height}px`:`auto`,"--yuri-composer-textarea-resting-max-height":!Ai&&Xs?`${Xs.maxHeight}px`:`none`,borderTopLeftRadius:ji,borderTopRightRadius:ji},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,Uu,Zn?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,Ol)),footerStyle:{borderBottomLeftRadius:ji,borderBottomRightRadius:ji},footerContent:cd,placeholder:na?ca:!Zn&&fa?o(`chat.dictation.recordingPlaceholder`):!Zn&&ea&&!E()&&Gl()?`${Mi}${s.startsWith(`zh`)?`,`:s===`ja`?`、`:`, `}${o(`chat.dictation.holdHere`)}`:Mi,onChange:(e,t)=>fc(t),textareaProps:{readOnly:nr,onCompositionStart:()=>{Nr.current=!0},onCompositionEnd:e=>{Nr.current=!1;let t=e.currentTarget;$s(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:uc,onKeyDown:Os,onCopy:xc,onCut:Tc,onPaste:yc,onDragEnter:el,onDragOver:nl,onDropCapture:dl,onDrop:ul,onDragEnd:ll,onKeyUp:ks,onClick:()=>{ks()},onScroll:e=>{ks();let t=e.currentTarget.scrollTop;Ti.current&&(Ti.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Nr.current){Pr.current=r;return}let i=Pc(n,r,[...qt(mr,_n.filter(_e).map(e=>e.filename)),..._c(mr,Hi.keys()),...pr.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Pr.current=i.end):Pr.current=n,ks()},onFocus:()=>{if(Zn){if(Date.now()<ue.current){let e=Ar.current;e&&e.blur();return}B.current!==null&&(window.clearTimeout(B.current),B.current=null),z(!0)}},onBlur:e=>{if(Nr.current=!1,Pr.current=e.currentTarget.selectionStart??Pr.current,Iu(),Zn){if(Date.now()<Fu.current){let e=Ar.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Fu.current&&document.activeElement!==e&&e.focus()},50);return}}if(fe.current=Date.now(),D()){z(!1);return}B.current!==null&&window.clearTimeout(B.current),B.current=window.setTimeout(()=>{B.current=null,z(!1)},120)}},autoCorrect:Zn?`on`:`off`,autoCapitalize:Zn?`sentences`:`off`,spellCheck:Zn||or,fillContainer:Ai,rows:1},children:[(0,$.jsx)(Hy,{}),qs?(0,$.jsx)(JD,{inputRef:Ar,draftID:Cn?nt(Cn):null,ariaLabel:o(`textarea.resizeHandleAria`),onManualHeightChange:Ys}):null,g&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:ji},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:Ju,onClick:()=>Cl(),title:o(`chat.chatInput.actions.attachFiles`),"aria-label":o(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(qu,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:o(v?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),w&&(0,$.jsx)(ol,{ref:Yr,searchQuery:O,directory:Sn,onCommandSelect:Gc,onClose:()=>T(!1),commandPolicy:Su,commandContext:wn,onRowsChange:Ou?yu:void 0,style:Di&&_a?{left:`${_a.left}px`,top:`${_a.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${_a.left+8}px))`,maxHeight:`${_a.maxHeight}px`,transform:_a.place===`above`?`translateY(-100%)`:void 0}:void 0}),b&&(0,$.jsx)(al,{ref:Kr,searchQuery:S,onFileSelect:Oc,onAgentSelect:kc,onSkillSelect:Vc,onSessionSelect:Ac,onClose:()=>x(!1),onRowsChange:Ou?yu:void 0,style:Di&&_a?{left:`${_a.left}px`,top:`${_a.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${_a.left+8}px))`,maxHeight:`${_a.maxHeight}px`,transform:_a.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Zn&&ea&&!na?(0,$.jsx)(qO,{radius:ji,isMobile:Zn,footerIconButtonClass:Yu,footerPaddingClass:Uu,iconSizeClass:qu,sendIconSizeClass:Gu,onInsert:fs,onInsertAndSend:vs,onContentHeightChange:Ks,onActiveChange:Us,disabled:yn||ra!==null||!vn&&!bn,renderTrigger:!1,topAccessory:JO},$t):null]})})]}),Zn?(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-compact-layer`,"data-yuri-composer-compact-surface":`true`,children:[sd,(0,$.jsx)(`div`,{ref:Ws,onPointerDown:()=>{Gs.current=!1},onScroll:e=>{let t=e.currentTarget;Gs.current=t.scrollWidth-t.clientWidth-t.scrollLeft<=2},className:Y(`yuri-mobile-composer-compact-preview`,!mr.trim()&&`yuri-mobile-composer-compact-preview--placeholder`),style:od?{right:`${.625+2.5*(1+Number(!!(n&&r))+Number(!!(ko||Co||Ls)))}rem`}:void 0,"aria-hidden":`true`,children:mr.trim()?mr:na?ca:Mi})]}):null]}),Zn?(0,$.jsx)(KO,{className:`hidden`,composerTextareaRef:Ar,selectionAdapter:Hn,mobilePanel:P,onMobilePanelChange:F}):null]}),bn&&!Di&&!Zn&&!jl&&!nu?(0,$.jsx)(xS,{onSubmit:ds,className:`chat-input-column mt-4`}):null]}),d.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(xO,{popup:d,onOpenChange:tr,isMobile:Zn})}):null,(0,$.jsx)(Qx,{open:xa,onOpenChange:Sa,mode:`select`,onSelect:e=>{Ea(e),ka(null)}}),(0,$.jsx)(tS,{open:Ca,onOpenChange:wa,onSelect:e=>{ka(e),Ea(null)}}),(0,$.jsx)(`input`,{ref:gl,type:`file`,multiple:!0,className:`hidden`,onChange:Dl,accept:`*/*`}),(0,$.jsx)(`input`,{ref:_l,type:`file`,multiple:!0,className:`hidden`,onChange:Dl,accept:`image/*`}),null,Qn?(0,$.jsx)(lc,{id:`android-media-pick-sheet`,open:U,onOpenChange:e=>{e||W(!1)},onPickPhotos:()=>{pe.current=!1,W(!1),requestAnimationFrame(Tl)},onPickFiles:()=>{pe.current=!1,W(!1),requestAnimationFrame(Cl)}}):null,Zn&&Ml&&Nl?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(sc,{id:`mobile-draft-project-picker-sheet-${G}`,open:ee===`project`,onOpenChange:e=>{e||te(null)},ariaLabel:o(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:o(`mobile.surface.closeAria`),resizeAriaLabel:o(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)($o,{value:ne,onChange:e=>re(e.target.value),placeholder:o(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(ld,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:(0,$.jsx)(ek,{projects:Dn,query:ne,renderLabel:GO,selectedId:Nl.id,onSelect:e=>{du(e),te(null)}})})}),(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-4 pt-1`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg border-t border-border/50 px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{te(null),sa.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},uk=e=>{let t=(0,Q.c)(3),n=hy(),r=e.surface??n;if(r&&!r.active)return null;let i=r??void 0,a;return t[0]!==e||t[1]!==i?(a=(0,$.jsx)(lk,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};uk.displayName=`ChatInput`;var dk=Z.memo(uk);function fk(e){return e.preventDefault()}function pk(e){e.preventDefault()}function mk(e){return e.preventDefault()}function hk(e){e.pointerType===`touch`&&e.preventDefault()}function gk(e){e.preventDefault()}function _k(e){e.pointerType===`touch`&&e.preventDefault()}var vk=e=>!!(e&&typeof e==`object`&&typeof e.type==`string`),yk=e=>e.filter(vk),bk=e=>{let t=e,n=t.text;return typeof n==`string`?n:t.content||t.value||``},xk=e=>/[^\s\u200B-\u200D\u2060\uFEFF]/u.test(e),Sk=e=>e.type===`text`&&!xk(bk(e)),Ck=(e,t={})=>{let{includeReasoning:n=!0}=t,r=yk(e),i=r.some(e=>!e.synthetic);return r.filter(e=>{let t=!!e.synthetic;if(e.type===`text`){if(Sk(e))return!1;let t=bk(e);if(t.includes(`<system-reminder>`)&&Rt(t).length===0)return!1}return t&&i||!n&&e.type===`reasoning`?!1:e.type!==`patch`})},wk=`GitHub issue context (JSON)`,Tk=`GitHub pull request context (JSON)`,Ek=`The user referenced these OpenCode sessions (id, title, owning directory).`,Dk=e=>typeof e==`number`&&Number.isFinite(e)&&e>0,Ok=(e,t)=>{let n=e.trimStart();if(!n.startsWith(t))return null;let r=n.indexOf(`{`);if(r<0)return null;try{return JSON.parse(n.slice(r))}catch{return null}},kk=e=>{let t=Ok(e,wk);if(t){let e=t.issue,n=e?.number,r=e?.title,i=e?.url;return!Dk(n)||typeof r!=`string`||typeof i!=`string`?null:{type:`file`,mime:`application/vnd.github.issue-link`,filename:`Issue #${n}: ${r}`,url:i}}let n=Ok(e,Tk);if(n){let e=n.pr,t=e?.number,r=e?.title,i=e?.url;return!Dk(t)||typeof r!=`string`||typeof i!=`string`?null:{type:`file`,mime:`application/vnd.github.pull-request-link`,filename:`PR #${t}: ${r}`,url:i}}return null},Ak=e=>!!e.trim().startsWith(`The following tool was executed by the user`),jk=e=>e.trimStart().startsWith(`Continue working toward the active session goal.`),Mk=e=>e.trim()===`/compact`,Nk=e=>e.flatMap(e=>{if(e.type===`compaction`)return[];if(e.type===`text`){let t=e.text;if(typeof t==`string`){let n=lo(t);if(n.trim().length===0||jk(n)||Mk(n)||n.trimStart().startsWith(Ek)||n.includes(`<system-reminder>`)&&Rt(n).length===0)return[];n!==t&&(e={...e,text:n})}}if(e.synthetic!==!0)return[e];if(e.type!==`text`)return[];let t=e.text;if(typeof t!=`string`)return[];let n=t.trimStart();return Ak(t)||n.startsWith(wk)||n.startsWith(Tk)?[e]:[]}).map(e=>{let t=e;if(t.type===`text`){let n=typeof t.text==`string`?t.text.trim():``;if(t.synthetic===!0){let e=kk(n);if(e)return e}if(n.startsWith(`The following tool was executed by the user`))return{...e,type:`text`,text:`/shell`};if(n.includes(`<system-reminder>`))return{...e,type:`text`,text:Rt(n)}}return e}),Pk=e=>e.some(e=>{if(e.type===`text`)return!Sk(e);if(e.type===`file`){let t=e,n=typeof t.mime==`string`?t.mime:``,r=typeof t.url==`string`?t.url:``;return(!!n||!!r)&&!!r&&!xe(e)}return!0}),Fk=e=>e?.length?Pk(Nk(e)):!1,Ik=(e,t)=>{if(t.length===0)return e;let n=new Map(t.map(e=>[e.info.id,e])),r=!1,i=e.map(e=>{if(Fk(e.parts))return e;let t=n.get(e.info.id);return t?(r=!0,t):e}),a=r?i:e,o=new Set(e.map(e=>e.info.id)),s=t.filter(e=>!o.has(e.info.id));return s.length===0?a:[...a,...s]},Lk=(e,t)=>{if(e.length===0)return!1;let n;for(let t of e){let e=t.info.time?.created;typeof e==`number`&&(n===void 0||e>n)&&(n=e)}return!t.resolvedSessionStatus||typeof t.sessionStatusObservedAt!=`number`||typeof n!=`number`||n>t.sessionStatusObservedAt},Rk=e=>{let t=e.boundary.kind===`exhausted`,n=e.boundary.kind===`has-more`,r=t&&!e.assistantComplete,i=n||r;return{complete:t&&e.assistantComplete,canLoadEarlier:i}},zk=e=>e.syncLoading||e.assistantLoading,Bk=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Vk=e=>e.isLoadingOlder,Hk=e=>!e.isMobile&&e.isLoadingOlder,Uk=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Wk=e=>e.hasImmediateShell||e.hasTranscriptShell&&e.hasRenderableSessionSnapshot||e.transcriptRecords?.some(e=>e.info.role===`user`?Fk(e.parts):e.parts.some(e=>e.type===`tool`||e.type===`text`&&e.text.trim().length>0))||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,Gk=e=>{let{sessionId:t,messages:n,retained:r}=e;return t?n.length>0?{messages:n,retained:{sessionId:t,messages:n}}:r?.sessionId===t?{messages:r.messages,retained:r}:{messages:n,retained:null}:{messages:n,retained:null}},Kk=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),qk=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Jk=`relative bottom-safe-area yuri-mobile-readonly-prompt-foot`,Yk=e=>{let t=(0,Q.c)(8),{providerId:n,modelId:r,label:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3.5`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{role:`img`,"aria-label":i,className:`inline-flex size-3.5 shrink-0 items-center justify-center`,children:a}),t[1]=i,t[2]=o);let s;return t[3]!==i||t[4]!==r||t[5]!==n||t[6]!==o?(s=(0,$.jsx)(ll,{modelId:r,providerId:n,alt:i,className:`size-3.5 shrink-0`,fallback:o}),t[3]=i,t[4]=r,t[5]=n,t[6]=o,t[7]=s):s=t[7],s},Xk=e=>{let t=(0,Q.c)(42),{t:n}=fr(),r=q(Zk),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Jk,i;t[0]===e?i=t[1]:(i=Y(`p-3`,e),t[0]=e,t[1]=i);let a;t[2]===n?a=t[3]:(a=n(`chat.container.readOnlySubagentPromptBanner`),t[2]=n,t[3]=a);let o;t[4]===a?o=t[5]:(o=(0,$.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-[var(--surface-background)] px-4 py-3 text-muted-foreground ${qk}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,s;t[11]!==e.agentName||t[12]!==o?(s=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=s):s=t[13];let c=s,l=e.modelName||o,u;t[14]===n?u=t[15]:(u=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=u);let d=`${u}: ${c}`,f;t[16]===n?f=t[17]:(f=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=f);let p=`${f}: ${l}`,m=r&&Jk,h;t[18]===m?h=t[19]:(h=Y(`shrink-0 border-t border-border/70 p-3`,m),t[18]=m,t[19]=h);let g=r&&`yuri-mobile-readonly-prompt-surface`,_;t[20]===g?_=t[21]:(_=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,g),t[20]=g,t[21]=_);let v;t[22]===n?v=t[23]:(v=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=v);let y;t[24]===v?y=t[25]:(y=(0,$.jsx)(`div`,{className:`text-muted-foreground ${qk}`,children:v}),t[24]=v,t[25]=y);let b;t[26]!==d||t[27]!==c||t[28]!==p||t[29]!==l||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(b=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Fo,{name:e.agentName,size:14,label:d}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:c,children:c})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Yk,{providerId:e.providerId,modelId:e.modelId,label:p}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:l,children:l})]})]}):null,t[26]=d,t[27]=c,t[28]=p,t[29]=l,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=b):b=t[34];let x;t[35]!==b||t[36]!==_||t[37]!==y?(x=(0,$.jsxs)(`div`,{className:_,children:[y,b]}),t[35]=b,t[36]=_,t[37]=y,t[38]=x):x=t[38];let S;return t[39]!==x||t[40]!==h?(S=(0,$.jsx)(`aside`,{className:h,children:x}),t[39]=x,t[40]=h,t[41]=S):S=t[41],S};function Zk(e){return e.isMobile}var Qk=Z.memo(()=>{let e=(0,Q.c)(5),{t}=fr(),{currentTheme:n}=Io(),r=oi($k),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Bs,{width:140,height:140,className:`opacity-20`}),e[0]=a):a=e[0];let o;return e[1]!==r||e[2]!==t||e[3]!==i?(o=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-full w-full gap-6`,children:[a,r?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 max-w-md text-center px-4`,children:[(0,$.jsx)(`span`,{className:`typography-markdown font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`typography-meta`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`typography-markdown`,style:{color:i},children:t(`chat.emptyState.startNewChat`)})]}),e[1]=r,e[2]=t,e[3]=i,e[4]=o):o=e[4],o});function $k(e){return e.error}var eA=`yuri_asst_session_divider:`,tA=[],nA=e=>typeof e?.info?.id==`string`&&e.info.id.startsWith(`yuri_asst_session_divider:`),rA=(e,t=0)=>({info:{id:`${eA}${e}`,role:`system`,time:{created:t}},parts:[]}),iA=e=>!!(e?.info&&typeof e.info==`object`&&e.info.yuriAssistantAdmission),aA=(e,t,n=tA)=>{if(!e.length)return tA;let r=[],i=!1,a=null;for(let n of e)n.sessionID!==t&&(i&&a!==n.sessionID&&r.push(rA(n.sessionID,Number(n.info.time?.created??0))),r.push({info:n.info,parts:n.parts,sourceSessionID:n.sessionID,sourceDirectory:n.directory}),i=!0,a=n.sessionID);return r.length===0?tA:uA(n,r)?n:r},oA=(e,t)=>{if(t.length===0)return e;if(e.length===0)return t;let n=new Map;for(let e of t)e?.id&&n.set(e.id,e);for(let t of e)t?.id&&n.set(t.id,t);let r=new Set,i=[];for(let e of t){if(!e?.id||r.has(e.id))continue;let t=n.get(e.id);t&&(i.push(t),r.add(e.id))}for(let t of e)!t?.id||r.has(t.id)||(i.push(t),r.add(t.id));return i.length===e.length&&i.every((t,n)=>t===e[n])?e:i},sA=(e,t)=>{if(!t)return e;if(e.info.role===`assistant`&&t.parts.length>0){let n=oA(e.parts,t.parts);return n===e.parts&&e.info===t.info?e:n===t.parts&&e.info===t.info&&e.parts===t.parts?t:{...e,parts:n,...t.sourceParts&&!e.sourceParts?{sourceParts:t.sourceParts}:{}}}return Fk(e.parts)?e:Fk(t.parts)?e.info===t.info&&e.parts===t.parts?t:{...e,parts:t.parts,...t.sourceParts&&!e.sourceParts?{sourceParts:t.sourceParts}:{}}:e.parts.length>0||t.parts.length===0?e:e.info===t.info&&e.parts===t.parts?t:{...e,parts:t.parts,...t.sourceParts&&!e.sourceParts?{sourceParts:t.sourceParts}:{}}},cA=(e,t,n,r=tA)=>{if(!t)return n.length>0?Array.from(n):tA;let i=new Map,a=0;for(let n of e)n.sessionID===t&&(iA(n)||i.set(n.info.id,{message:{info:n.info,parts:n.parts},order:a++}));for(let e of n){let t=i.get(e.info.id);i.set(e.info.id,{message:sA(e,t?.message),order:t?.order??a++})}if(i.size===0)return tA;let o=[...i.values()].sort((e,t)=>Number(e.message.info.time?.created??0)-Number(t.message.info.time?.created??0)||e.order-t.order).map(({message:e})=>e);return uA(r,o)?r:o},lA=(e,t)=>{if(!nA(e)||!nA(t))return!1;let n=Number(e.info.time?.created??0),r=Number(t.info.time?.created??0);return e.info.id===t.info.id&&n===r},uA=(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||!i||!(r===i||lA(r,i))&&(r?.info!==i?.info||r?.parts!==i?.parts||r.sourceSessionID!==i.sourceSessionID||r.sourceDirectory!==i.sourceDirectory))return!1}return!0},dA=()=>ae(e=>({expanded:new Set,toggle:t=>e(e=>{let n=new Set(e.expanded);return n.has(t)?n.delete(t):n.add(t),{expanded:n}})})),fA=(0,Z.createContext)(null);function pA(e){let t=(0,Q.c)(7),n=(0,Z.useContext)(fA),r;t[0]===n?r=t[1]:(r=()=>n??dA(),t[0]=n,t[1]=r);let[i]=(0,Z.useState)(r),a=n??i,o;t[2]===e?o=t[3]:(o=t=>t.expanded.has(e),t[2]=e,t[3]=o);let s=re(a,o),c=re(a,mA),l;return t[4]!==s||t[5]!==c?(l={expanded:s,toggle:c},t[4]=s,t[5]=c,t[6]=l):l=t[6],l}function mA(e){return e.toggle}var hA=(0,Z.createContext)(null);function gA(e,t){return JSON.stringify([e,t])}function _A(e){return new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`giu`)}var vA=new WeakMap;function yA(e){return e.map(e=>{if(e.type===`image`||e.type===`html`||e.type===`def`)return``;if(e.type===`space`||e.type===`br`||e.type===`hr`)return`
|
|
6559
|
-
`;if(e.type===`code`||e.type===`codespan`)return e.text;if(e.type===`list`)return e.items.map(e=>
|
|
6560
|
-
`);if(e.type===`table`)return[e.header,...e.rows].map(e=>e.map(e=>
|
|
6561
|
-
`);let t=`tokens`in e?e.tokens:void 0;if(t)return
|
|
6562
|
-
`:``);let n=`text`in e&&typeof e.text==`string`?e.text:``;if(!n.includes(`&`)||typeof document>`u`)return n;let r=document.createElement(`textarea`);return r.innerHTML=n.replace(/</g,`<`),r.value}).join(``)}function
|
|
6563
|
-
`)),FA=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=NA(e,MA);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${td(t.name)})`;i=i.replace(t.token,e)}i=i.replace(AA,(e,t,r)=>n.has(r)?`${t}[/${r}](${od(r)})`:e)}return PA(i)},IA=e=>(AA.lastIndex=0,AA.test(e)||e.includes(`[skill:`)),LA=e=>{if(typeof window>`u`)return!1;let t=window.getSelection();if(!t||t.isCollapsed||t.rangeCount===0)return!1;let n=t.getRangeAt(0);return e.contains(n.startContainer)||e.contains(n.endContainer)},RA=Z.memo(e=>{let t=(0,Q.c)(94),{part:n,messageId:r,agentMention:i,messageParts:a,variant:o}=e,s=(o===void 0?`message`:o)===`preview`,c=Z.useContext(hA),l=!s&&c?.messageId===r&&c.partId===n.id,u=n,d=u.text,f=typeof d==`string`?d:u.content||u.value||``,p;t[0]===f?p=t[1]:(p=Rg(f),t[0]=f,t[1]=p);let m=p,h=m?m.body:f,[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),b;t[2]===s?b=t[3]:(b=e=>!s&&e.collapsibleUserMessages,t[2]=s,t[3]=b);let x=q(b),S=Nu(),C;t[4]===h?C=t[5]:(C=IA(h),t[4]=h,t[5]=C);let w;t[6]!==S||t[7]!==C?(w={directory:S,enabled:C},t[6]=S,t[7]=C,t[8]=w):w=t[8];let T=oa(w),E;t[9]===T.data?E=t[10]:(E=T.data??[],t[9]=T.data,t[10]=E);let D=E,O=q(zA),{t:k}=fr(),A=x&&!g&&!l,j=Z.useRef(null),M;t[11]===D?M=t[12]:(M=new Map(D.map(BA)),t[11]=D,t[12]=M);let N=M,P;t[13]!==a||t[14]!==h?(P=w_(a,h),t[13]=a,t[14]=h,t[15]=P):P=t[15];let F=P,I;if(t[16]!==a||t[17]!==h){let e=new Map;for(let t of a??[]){if(t.type!==`text`||!Or(t))continue;let n=t.text;if(typeof n==`string`)for(let t of Tr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(h.includes(`@`))for(let[t,n]of Ne()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(h.includes(`@${r}`)||h.includes(`@${tt}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}I=Array.from(e.values()),t[16]=a,t[17]=h,t[18]=I}else I=t[18];let L=I,R;t[19]!==S||t[20]!==O||t[21]!==N?(R=e=>{let t=N.get(e),n=typeof t?.path==`string`?t.path:``,r=zn(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=S||Un(``,i)||`/`,o=()=>{O(a,i)};if(S&&!Bn(i,S)){kA(i,S).then(o);return}o()},t[19]=S,t[20]=O,t[21]=N,t[22]=R):R=t[22];let z=J(R),B;t[23]!==x||t[24]!==g?(B=()=>{let e=j.current;if(!e||!x)return;let t=()=>{x&&!g&&e.scrollHeight>e.clientHeight&&y(!0)};y(!1),t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},t[23]=x,t[24]=g,t[25]=B):B=t[25];let V;t[26]!==x||t[27]!==g||t[28]!==h?(V=[x,h,g],t[26]=x,t[27]=g,t[28]=h,t[29]=V):V=t[29],Z.useEffect(B,V);let H,U;t[30]===x?(H=t[31],U=t[32]):(H=()=>{x||(_(!1),y(!1))},U=[x],t[30]=x,t[31]=H,t[32]=U),Z.useEffect(H,U);let W;t[33]!==x||t[34]!==g||t[35]!==s||t[36]!==v||t[37]!==z?(W=e=>{if(s)return;let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??rd(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),z(n);return}let r=j.current;r&&(LA(r)||x&&!g&&v&&_(!0))},t[33]=x,t[34]=g,t[35]=s,t[36]=v,t[37]=z,t[38]=W):W=t[38];let ee=J(W),te;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(te=e=>{e.stopPropagation(),_(!1)},t[39]=te):te=t[39];let G=J(te),ne;t[40]!==i||t[41]!==F.displayNames||t[42]!==F.icons||t[43]!==L||t[44]!==N||t[45]!==h?(ne=v_(h,{skillNames:new Set(N.keys()),citationIcons:F.icons,citationDisplayNames:F.displayNames,sessionMentions:L,agentNames:i?.name?new Set([i.name.toLowerCase(),i.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),t[40]=i,t[41]=F.displayNames,t[42]=F.icons,t[43]=L,t[44]=N,t[45]=h,t[46]=ne):ne=t[46];let re=ne,ie;t[47]!==i||t[48]!==re||t[49]!==N||t[50]!==h?(ie=FA({textContent:h,agentMention:i,skillNames:new Set(N.keys()),decorateInlineReferences:!re}),t[47]=i,t[48]=re,t[49]=N,t[50]=h,t[51]=ie):ie=t[51];let ae=ie,oe;t[52]===A?oe=t[53]:(oe=(e,t)=>{if(!e)return null;let n=FA({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(nc,{content:n,className:Y(`inline w-auto align-baseline [&_.markdown-content]:contents [&_.markdown-content_p]:inline [&_[data-markdown-size-spacer]]:inline`,`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,A&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1},t)},t[52]=A,t[53]=oe);let se=oe,ce;t[54]!==s||t[55]!==z||t[56]!==se?(ce=e=>e.map((e,t)=>e.type===`text`?se(e.text,`text-${t}`):(0,$.jsx)(E_,{decoration:e.decoration,onOpenSkill:z,interactive:!s},`ref-${t}-${e.span.start}`)),t[54]=s,t[55]=z,t[56]=se,t[57]=ce):ce=t[57];let le=ce;if((!h||h.trim().length===0)&&!m?.quotes.length)return null;let ue=A&&v,de=n.id||`${r}-user-text`,fe;t[58]!==s||t[59]!==r||t[60]!==n.id?(fe=s?void 0:gA(r,n.id),t[58]=s,t[59]=r,t[60]=n.id,t[61]=fe):fe=t[61];let pe=ue?`true`:void 0,me;t[62]!==x||t[63]!==G||t[64]!==g||t[65]!==k?(me=x&&g&&(0,$.jsx)(`button`,{type:`button`,onClick:G,className:`absolute top-0 right-0 z-10 flex items-center justify-center rounded-sm bg-[var(--surface-elevated)] p-0.5 text-[var(--surface-mutedForeground)] hover:text-[var(--surface-foreground)] hover:bg-[var(--interactive-hover)] transition-colors`,"aria-label":k(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),t[62]=x,t[63]=G,t[64]=g,t[65]=k,t[66]=me):me=t[66];let he;t[67]!==r||t[68]!==n.id||t[69]!==m||t[70]!==k?(he=m&&m.quotes.length>0?(0,$.jsx)(`div`,{className:`mb-2 flex flex-col gap-1`,"data-conversation-quotes":!0,"aria-label":k(`chat.message.conversationQuotesLabel`),children:m.quotes.map((e,t)=>(0,$.jsx)(`p`,{"data-conversation-quote":!0,className:`m-0 whitespace-pre-wrap break-words border-l-2 border-border pl-3 typography-meta text-muted-foreground`,children:e},`${n.id||r}-quote-${t}`))}):null,t[67]=r,t[68]=n.id,t[69]=m,t[70]=k,t[71]=he):he=t[71];let ge;t[72]!==x||t[73]!==ee||t[74]!==A||t[75]!==g||t[76]!==s||t[77]!==v||t[78]!==ae||t[79]!==re||t[80]!==le||t[81]!==h?(ge=h.trim().length>0?(0,$.jsx)(`div`,{className:Y(`break-words font-sans`,s?`typography-meta`:`typography-markdown-body`,g&&`pb-3`,A&&`line-clamp-10`,x&&v&&!g&&`cursor-pointer`),"data-user-message-collapse":A?`true`:void 0,ref:j,onClick:ee,children:re?le(re):(0,$.jsx)(nc,{content:ae,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,A&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1})}):null,t[72]=x,t[73]=ee,t[74]=A,t[75]=g,t[76]=s,t[77]=v,t[78]=ae,t[79]=re,t[80]=le,t[81]=h,t[82]=ge):ge=t[82];let _e;t[83]!==ue||t[84]!==k?(_e=ue&&(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,className:`yuri-user-text-expand flex cursor-pointer items-center justify-start gap-1 text-left font-sans typography-markdown-body text-muted-foreground`,"aria-expanded":!1,onClick:()=>_(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_(!0))},children:[k(`chat.message.userText.showMore`),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-[1em] shrink-0`})]}),t[83]=ue,t[84]=k,t[85]=_e):_e=t[85];let ve;return t[86]!==de||t[87]!==fe||t[88]!==pe||t[89]!==me||t[90]!==he||t[91]!==ge||t[92]!==_e?(ve=(0,$.jsxs)(`div`,{className:`relative`,"data-transcript-search-part":fe,"data-user-message-clamp":pe,children:[me,he,ge,_e]},de),t[86]=de,t[87]=fe,t[88]=pe,t[89]=me,t[90]=he,t[91]=ge,t[92]=_e,t[93]=ve):ve=t[93],ve});function zA(e){return e.openContextFile}function BA(e){return[e.name,e]}var VA=[{variant:`static`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:t,children:e})},{variant:`generate-effect`,component:({children:e,className:t,...n})=>{if(e==null)return null;let r=typeof e==`string`?e:typeof e==`number`?String(e):Array.isArray(e)?e.map(e=>typeof e==`string`||typeof e==`number`?String(e):``).join(``):``;return r?(0,$.jsx)(`span`,{className:Y(`inline-block align-baseline`,t),children:r.split(``).map((e,t)=>(0,Z.createElement)($d.span,{...n,key:e+String(t),className:Y(`inline-block whitespace-pre align-baseline`),initial:{opacity:0},animate:{opacity:1},transition:{ease:`easeOut`,duration:.14,delay:Math.min(t*.0045,.14)}},e))}):null}},{variant:`glitch`,component:({children:e,className:t,...n})=>(0,$.jsxs)(`div`,{className:`group relative overflow-hidden font-medium`,children:[(0,$.jsx)(`span`,{...n,className:Y(`invisible`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 text-primary-muted transition-transform duration-500 ease-in-out`,`group-hover:-translate-y-full hover:duration-300`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 translate-y-full text-primary-muted transition-transform duration-500`,`ease-in-out hover:duration-300 group-hover:translate-y-0`,t),children:e})]})},{variant:`hover-enter`,component:({children:e,className:t,...n})=>{if(typeof e!=`string`)return null;let r=.25,i=.025,a=e.split(``).map(e=>e===` `?`\xA0`:e);return(0,$.jsxs)($d.span,{...n,className:Y(`relative block select-none overflow-hidden whitespace-nowrap text-primary-muted`,t),initial:`initial`,whileHover:`hovered`,style:{lineHeight:.9},children:[(0,$.jsx)(`div`,{children:a.map((e,t)=>(0,$.jsx)($d.span,{className:`inline-block`,variants:{initial:{y:0},hovered:{y:`-100%`}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0`),children:a.map((e,t)=>(0,$.jsx)($d.span,{className:`inline-block`,variants:{initial:{y:`100%`},hovered:{y:0}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))})]})}},{variant:`shake`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted hover:animate-text-shake`,t),children:e})},{variant:`hover-decoration`,component:({children:e,className:t,...n})=>(0,$.jsx)(`div`,{className:Y(`relative after:absolute after:bottom-0 after:left-0 after:h-px after:w-full after:origin-bottom-right`,`after:scale-x-0 after:bg-primary-muted after:transition-transform after:duration-300 after:ease-in-out hover:after:origin-bottom-left hover:after:scale-x-100`),children:(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted`,t),children:e})})}];function HA(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({variant:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`static`:i,o;t[4]===a?o=t[5]:(o=VA.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||VA[0].component,c;return t[6]!==s||t[7]!==n||t[8]!==r?(c=(0,$.jsx)(s,{...r,className:n}),t[6]=s,t[7]=n,t[8]=r,t[9]=c):c=t[9],c}var UA=e=>{let t=(0,Q.c)(42),{output:n,isMobile:r}=e,{t:i}=fr(),a=Z.useId(),[o,s]=Z.useState(!1),c;t[0]===n?c=t[1]:(c=n.slice(0,240).replace(/\s+/g,` `).trim(),t[0]=n,t[1]=c);let l=c,u;t[2]===i?u=t[3]:(u=i(`chat.toolPart.output`),t[2]=i,t[3]=u);let d=u,f;t[4]!==n||t[5]!==i?(f=async()=>{(await Ea(n)).ok?no.success(i(`chat.toolPart.copiedOutput`)):no.error(i(`chat.toolPart.copyOutputFailed`))},t[4]=n,t[5]=i,t[6]=f):f=t[6];let p=J(f),m;t[7]===i?m=t[8]:(m=i(`chat.toolPart.copyOutput`),t[7]=i,t[8]=m);let h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(X,{name:`file-copy`,className:`size-4`}),t[9]=h):h=t[9];let g;t[10]!==p||t[11]!==m?(g=(0,$.jsx)($r,{variant:`ghost`,size:`icon`,onClick:p,"aria-label":m,children:h}),t[10]=p,t[11]=m,t[12]=g):g=t[12];let _=g,v;t[13]!==o||t[14]!==n?(v=o?(0,$.jsx)(`div`,{className:`tool-output-surface overlay-scrollbar-container min-h-0 flex-1 overflow-auto p-2`,"data-tool-json-code":!0,children:(0,$.jsx)(Fd,{language:`json`,code:n,wrap:!0})}):null,t[13]=o,t[14]=n,t[15]=v):v=t[15];let y=v,b;t[16]===l?b=t[17]:(b=(0,$.jsx)(`code`,{className:`typography-code min-w-0 flex-1 truncate text-muted-foreground`,children:l}),t[16]=l,t[17]=b);let x;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>s(!0),t[18]=x):x=t[18];let S;t[19]===i?S=t[20]:(S=i(`chat.toolPart.showRawJson`),t[19]=i,t[20]=S);let C;t[21]===i?C=t[22]:(C=i(`chat.toolPart.showRawJson`),t[21]=i,t[22]=C);let w;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(X,{name:`code-box`,className:`size-4`}),t[23]=w):w=t[23];let T;t[24]!==o||t[25]!==S||t[26]!==C?(T=(0,$.jsx)($r,{size:`icon`,onClick:x,"aria-label":S,"aria-haspopup":`dialog`,"aria-expanded":o,title:C,children:w}),t[24]=o,t[25]=S,t[26]=C,t[27]=T):T=t[27];let E;t[28]!==T||t[29]!==b?(E=(0,$.jsxs)(`div`,{className:`tool-output-surface flex min-w-0 items-center gap-1 rounded-lg`,"data-tool-json-preview":!0,children:[b,T]}),t[28]=T,t[29]=b,t[30]=E):E=t[30];let D;t[31]!==y||t[32]!==_||t[33]!==a||t[34]!==r||t[35]!==o||t[36]!==i||t[37]!==d?(D=r?(0,$.jsx)(sc,{id:`tool-json-${a}`,open:o,onOpenChange:s,title:(0,$.jsx)(`span`,{className:`typography-ui-header font-semibold`,children:d}),ariaLabel:d,closeAriaLabel:i(`dialog.common.actions.close`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),trailing:_,children:y}):(0,$.jsx)(Ko,{open:o,onOpenChange:s,children:(0,$.jsxs)(Ho,{className:`h-[85dvh] max-w-5xl gap-1 overflow-hidden p-2`,showCloseButton:!1,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(Uo,{className:`min-w-0 flex-1 px-1`,children:d}),_,(0,$.jsx)($r,{variant:`ghost`,size:`icon`,onClick:()=>s(!1),"aria-label":i(`dialog.common.actions.close`),children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}),y]})}),t[31]=y,t[32]=_,t[33]=a,t[34]=r,t[35]=o,t[36]=i,t[37]=d,t[38]=D):D=t[38];let O;return t[39]!==E||t[40]!==D?(O=(0,$.jsxs)(`div`,{onClick:WA,onPointerDown:GA,children:[E,D]}),t[39]=E,t[40]=D,t[41]=O):O=t[41],O};function WA(e){return e.stopPropagation()}function GA(e){return e.stopPropagation()}var KA=e=>{let t=`h-3.5 w-3.5 flex-shrink-0`,n=`h-[13px] w-[13px] flex-shrink-0`,r=e.toLowerCase();return r===`edit`||r===`multiedit`||r===`apply_patch`||r===`patch`||r===`str_replace`||r===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil`,className:n}):r===`write`||r===`create`||r===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:n}):r===`read`||r===`view`||r===`file_read`||r===`cat`?(0,$.jsx)(X,{name:`file-text`,className:t}):r===`bash`||r===`shell`||r===`cmd`||r===`terminal`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):r===`execute`?(0,$.jsx)(X,{name:`code-box`,className:t}):r===`list`||r===`ls`||r===`dir`||r===`list_files`?(0,$.jsx)(X,{name:`folder-6`,className:t}):r===`search`||r===`grep`||r===`find`||r===`ripgrep`?(0,$.jsx)(X,{name:`menu-search`,className:t}):r===`glob`?(0,$.jsx)(X,{name:`file-search`,className:t}):r===`fetch`||r===`curl`||r===`wget`||r===`webfetch`||r===`browser`||r===`web-search`||r===`websearch`||r===`search_web`||r===`codesearch`||r===`google`||r===`bing`||r===`duckduckgo`||r===`perplexity`?(0,$.jsx)(X,{name:`global`,className:t}):r===`todowrite`||r===`todoread`?(0,$.jsx)(Ud,{className:Y(`size-3.5 text-current`,t)}):r===`structuredoutput`||r===`structured_output`?(0,$.jsx)(X,{name:`list-check-2`,className:t}):r===`skill`?(0,$.jsx)(X,{name:`book`,className:t}):r===`task`||r===`subagent`?(0,$.jsx)(X,{name:`ai-agent`,className:t}):r===`question`?(0,$.jsx)(X,{name:`survey`,className:t}):r===`lsp`?(0,$.jsx)(X,{name:`scan-2`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},qA=new Map,JA=e=>{let t=qA.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return qA.set(e,n),n},YA=(e,t)=>{let n=JA(e);return n.subscribers.add(t),t(Date.now()),n.timerId===null&&typeof window<`u`&&(n.timerId=window.setInterval(()=>{let e=Date.now();n.subscribers.forEach(t=>{t(e)})},e)),()=>{let n=qA.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),qA.delete(e)))}},XA=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(ZA),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return YA(r,a)},s=[e,r],n[0]=e,n[1]=r,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),i};function ZA(){return Date.now()}var QA=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],$A=e=>{if(e&&typeof e==`object`&&!Array.isArray(e))return e;if(typeof e!=`string`)return;let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return e}catch{return}},ej=(...e)=>{for(let t of e){let e=$A(t);if(!e)continue;let n=[e.subagent_type,e.subagentType,e.agent,e.subagent];for(let e of n){if(typeof e!=`string`)continue;let t=e.trim();if(t.length>0)return t}}},tj=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},nj=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(n.includes(`.`)){let e=n.split(`.`).filter(Boolean);return e[e.length-1]??n}return n},rj=e=>{let t=nj(e);return t===`task`||t===`subagent`},ij=e=>{let t=nj(e);return t===`shell`||t===`bash`||t===`cmd`||t===`terminal`},aj=e=>rj(e)||ij(e),oj=e=>{if(!e||typeof e!=`object`)return;let t=e;return tj(t.sessionId)??tj(t.sessionID)},sj=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>e?.type!==`subtask`||e.taskSessionID===t?e:(n=!0,{...e,taskSessionID:t}));return n?r:e},cj=e=>{if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){t.push({tool:`tool`,state:{status:`completed`,title:n}});continue}if(!n||typeof n!=`object`)continue;let e=n;t.push({id:typeof e.id==`string`?e.id:void 0,tool:typeof e.tool==`string`?e.tool:`tool`,state:{status:typeof e.state?.status==`string`?e.state.status:typeof e.status==`string`?e.status:void 0,title:typeof e.state?.title==`string`?e.state.title:typeof e.title==`string`?e.title:void 0,input:e.state?.input&&typeof e.state.input==`object`?e.state.input:void 0}})}return t},lj=e=>{if(typeof e!=`string`||e.trim().length===0)return{summaryEntries:[]};let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);if(!t?.[1])return{summaryEntries:[]};try{let e=JSON.parse(t[1].trim());return{sessionId:tj(e.sessionId)??tj(e.sessionID),status:tj(e.status),summaryEntries:cj(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},uj=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=lj(e);if(t.sessionId)return t.sessionId;let n=e.match(/task_id\s*:\s*([^\s<"']+)/i),r=e.match(/session[_\s-]?id\s*:\s*([^\s<"']+)/i);return tj((n?.[1]??r?.[1])||QA(e))},dj=e=>{let t=e.state;return oj(t?.metadata)??oj(t)??oj(t?.input)??oj(e.metadata)??uj(typeof t?.output==`string`?t.output:void 0)},fj=e=>{if(!(!e||typeof e!=`object`))return tj(e.status)},pj=/"status"\s*:\s*"running"/i,mj=/\bstatus\s*[:=]\s*["'`]?running\b/i,hj=e=>{if(typeof e!=`string`||e.trim().length===0)return!1;let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);return t?.[1]&&pj.test(t[1])?!0:mj.test(e)},gj=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,_j=(e,t)=>tj(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),vj=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},yj=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(gj);if(!t)return;let n=_j(t[1],`sessionID`)??_j(t[1],`sessionId`),r=vj(_j(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:_j(t[1],`description`),body:t[2].trim()}},bj=/<shell\s+([^>]*?)>([\s\S]*?)<\/shell>/i,xj=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(bj);if(!t)return;let n=_j(t[1],`id`),r=vj(_j(t[1],`state`));if(!(!n||!r))return{id:n,state:r,command:_j(t[1],`command`),body:t[2].trim()}},Sj=new WeakMap,Cj=e=>{let t=Sj.get(e);if(t)return t;let n=[];if(e.info.role===`assistant`)for(let t of e.parts){if(t.type!==`tool`)continue;let e=t.tool?.trim().toLowerCase();if(!e||rj(e)||e===`todowrite`||e===`todoread`)continue;let r=t.state;n.push({id:t.id,tool:t.tool,state:{status:r?.status,title:r?.title,input:r?.input&&typeof r.input==`object`?r.input:void 0}})}return Sj.set(e,n),n},wj=e=>{let t=[];for(let n of e)t.push(...Cj(n));return t},Tj=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),Ej=[`summary`,`changes`,`verification`],Dj={summary:`Summary`,changes:`Changes`,verification:`Verification`},Oj=/<(summary|changes|verification)(?:\s[^>]*)?>/i,kj=()=>RegExp(`<(${Ej.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),Aj=e=>typeof e!=`string`||e.length===0?!1:Oj.test(e),jj=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!Aj(e)?e:e.replace(kj(),(e,t,n)=>{let r=Dj[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),Mj=e=>jj(Tj(e)),Nj=e=>{if(!e.isTaskTool)return{isDelegating:!1,showAvatar:!1,title:e.displayName};let t=e.taskAgentName?e.formatName(e.taskAgentName):void 0,n=!!(e.taskSessionId||t);return!e.isFinalized&&!n?{isDelegating:!0,showAvatar:!1,title:e.delegatingLabel}:{isDelegating:!1,showAvatar:n,title:t??e.displayName}},Pj=e=>{if(!(!e||typeof e!=`object`||Array.isArray(e)))return e},Fj=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},Ij=e=>nj(e.tool??e.name),Lj=e=>Pj(e.state),Rj=e=>Pj(Lj(e)?.metadata)??Pj(e.metadata),zj=e=>Pj(Lj(e)?.input)??Pj(e.input),Bj=e=>Fj(Lj(e)?.status)?.toLowerCase(),Vj=e=>(Array.isArray(e.parts)?e.parts:Array.isArray(e.content)?e.content:[]).filter(e=>!!e&&typeof e==`object`),Hj=e=>{let t=[],n=Fj(Pj(e.metadata)?.text);n&&t.push(n);for(let n of Vj(e)){let e=Fj(n.text);e&&t.push(e)}let r=Fj(e.text);return r&&t.push(r),t},Uj=e=>{let t=Fj(e)?.toLowerCase();if(t===`completed`||t===`error`||t===`cancelled`)return t},Wj=e=>{let t=new Map,n=new Map,r=(e,n)=>{e&&t.set(e,n)},i=(e,t)=>{e&&n.set(e,t)};for(let t of e){let e=Pj(t.metadata),n=Fj(e?.source)?.toLowerCase(),a=Uj(e?.state);n===`shell`&&a&&(r(Fj(e?.shellID),a),r(Fj(e?.jobID),a),r(Fj(e?.id),a)),n===`subagent`&&a&&i(Fj(e?.childID)??Fj(e?.sessionID)??Fj(e?.sessionId),a);for(let e of Hj(t)){let t=xj(e);t&&(r(t.id,t.state),r(t.shellID,t.state),r(t.jobID,t.state));let n=yj(e);n&&i(n.sessionID,n.state)}}return{byShellOrJobID:t,byChildSessionID:n}},Gj=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return t.type!==void 0&&t.type!==`tool`||!aj(Ij(t))||Bj(t)!==`completed`?!1:fj(Rj(t))===`running`||fj(Lj(t))===`running`},Kj=e=>{if(!e||typeof e!=`object`)return!1;let t=e;if(t.type!==void 0&&t.type!==`tool`||!aj(Ij(t)))return!1;let n=Bj(t);return n===`running`||n===`pending`||n===`started`},qj=e=>{if(!e||typeof e!=`object`)return;let t=e,n=Ij(t);if(!aj(n))return;let r=Rj(t),i=zj(t);if(rj(n)){let e=oj(r)??oj(Lj(t))??oj(i),n=Fj(i?.description),a=Fj(i?.agent)??Fj(i?.subagent_type)??Fj(i?.subagentType);return{type:`subagent`,id:e,label:n??e,agent:a}}let a=Fj(r?.shellID)??Fj(Lj(t)?.shellID),o=Fj(r?.jobID)??Fj(Lj(t)?.jobID),s=Fj(i?.command),c=Fj(t.id);return{type:`shell`,id:a??o??c,label:s??a??o??c}},Jj=e=>{let t=new Set,n=new Set;for(let r of e){let e=qj(r);e?.id&&(e.type===`subagent`?t:n).add(e.id)}return{childSessionIDs:t,shellIDs:n}},Yj=(e,t,n)=>{if(!n)return;let r=Rj(t),i=Lj(t),a=[e.id,Fj(r?.shellID),Fj(r?.jobID),Fj(i?.shellID),Fj(i?.jobID),Fj(t.id)];for(let e of a){if(!e)continue;let t=n.byShellOrJobID.get(e);if(t)return t}},Xj=(e,t)=>{if(!(!t||!e.id))return t.byChildSessionID.get(e.id)},Zj=e=>{let{part:t,completions:n,childSessionStatusType:r}=e;if(!t||typeof t!=`object`)return{kind:`settled`};let i=t;if(i.type!==void 0&&i.type!==`tool`||!aj(Ij(i)))return{kind:`settled`};if(Kj(t))return{kind:`blocking`};let a=qj(t);if(!a)return{kind:`settled`};if(a.type===`shell`){let e=Yj(a,i,n);return e?{kind:`terminal`,state:e}:Gj(t)?{kind:`background-running`}:{kind:`settled`}}let o=Fj(r)?.toLowerCase();if(o===`idle`)return{kind:`settled`};if(o===`busy`||o===`retry`)return{kind:`background-running`};let s=Xj(a,n);return s?{kind:`terminal`,state:s}:Gj(t)?(a.id,{kind:`background-running`}):{kind:`settled`}},Qj=async(e,t)=>{let n=e.trim();if(!n)return{ok:!1,error:`sessionID required`};try{return await t.session.background({sessionID:n}),{ok:!0}}catch(e){return{ok:!1,error:(e instanceof Error?e.message:String(e))||`session.background failed`}}},$j=e=>{if(!e||typeof e!=`object`)return;let t=e;if(!ij(Ij(t)))return;let n=Rj(t),r=Lj(t),i=Fj(n?.shellID)??Fj(r?.shellID),a=Fj(n?.jobID)??Fj(r?.jobID),o=Fj(t.id);return{shellID:i,jobID:a,workID:i??a??o}};function eM(e){if(!e.isTaskTool||e.isFinalized)return!1;let t=e.taskSessionId?e.childSessionStatus:e.parentSessionStatus;if(t){if(t.type!==`idle`)return!1;if(typeof e.taskStartedAt==`number`&&typeof e.statusObservedAt==`number`&&e.taskStartedAt<=e.statusObservedAt)return!0}return typeof e.taskStartedAt==`number`&&typeof e.statusSnapshotAt==`number`&&e.taskStartedAt<=e.statusSnapshotAt}var tM=(e,t)=>{if(e===t)return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;let n=e,r=t;return n.input===r.input&&n.output===r.output&&n.reasoning===r.reasoning&&n.cache?.read===r.cache?.read&&n.cache?.write===r.cache?.write},nM=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},rM=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},iM=e=>e?.state,aM=e=>e?.metadata,oM=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},sM=e=>{let t=e;return t?[typeof t.text==`string`?t.text:``,typeof t.content==`string`?t.content:``,typeof t.value==`string`?t.value:``].reduce((e,t)=>t.length>e.length?t:e,``):``},cM=(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.type!==i.type||nM(r)!==nM(i))return!1;if(r.type===`compaction`){let e=r,t=i;if(e.status!==t.status||e.summary!==t.summary||e.reason!==t.reason||e.recent!==t.recent||e.error?.type!==t.error?.type||e.error?.message!==t.error?.message||e.error?.status!==t.error?.status)return!1}if(r.type===`tool`){if(iM(r)!==iM(i)||aM(r)!==aM(i)||rM(r)!==rM(i))return!1;let e=oM(r),t=oM(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=oM(r),o=oM(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(sM(r)!==sM(i))return!1;let e=r.shellAction,t=i.shellAction;if((e||t)&&(e?.command!==t?.command||e?.output!==t?.output||e?.status!==t?.status))return!1}}return!0},lM=(e,t)=>e===t||e.id===t.id&&e.role===t.role&&e.sessionID===t.sessionID&&e.finish===t.finish&&e.status===t.status&&e.error===t.error&&e.mode===t.mode&&e.agent===t.agent&&e.providerID===t.providerID&&e.modelID===t.modelID&&e.variant===t.variant&&e.clientRole===t.clientRole&&e.userMessageMarker===t.userMessageMarker&&(e.time?.created??null)===(t.time?.created??null)&&(e.time?.completed??null)===(t.time?.completed??null)&&e.time?.streamed===t.time?.streamed&&tM(e.tokens,t.tokens),uM=(e,t)=>lM(e.info,t.info)&&cM(e.parts,t.parts),dM=(e,t)=>!e||!t?e===t:uM(e,t),fM=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,pM=(e,t)=>{if(e===t)return!0;if(!e||!t)return!e&&!t;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.file!==i.file||r.additions!==i.additions||r.deletions!==i.deletions)return!1}return!0},mM=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&cM([e.part],[t.part]),hM=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.messageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.messageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!mM(a,o))return!1;r+=1,i+=1}},gM=(e,t)=>{if(e.id!==t.id||e.anchorMessageId!==t.anchorMessageId||e.afterToolPartId!==t.afterToolPartId||e.parts.length!==t.parts.length)return!1;for(let n=0;n<e.parts.length;n+=1)if(!mM(e.parts[n],t.parts[n]))return!1;return!0},_M=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),vM=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.anchorMessageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.anchorMessageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!gM(a,o))return!1;r+=1,i+=1}},yM=(e,t,n,r)=>{if(e===t)return!0;if(!e||!t)return e===t;if(r)return!0;if(e.isGroupExpanded!==t.isGroupExpanded||e.turnId!==t.turnId||e.isFirstAssistantInTurn!==t.isFirstAssistantInTurn||e.isLastAssistantInTurn!==t.isLastAssistantInTurn||e.isLatestTurn!==t.isLatestTurn||e.isWorking!==t.isWorking||e.isTurnSettled!==t.isTurnSettled||e.hasTools!==t.hasTools||e.hasReasoning!==t.hasReasoning||e.userMessageCreatedAt!==t.userMessageCreatedAt||e.userMessageVariant!==t.userMessageVariant||e.assistantTps!==t.assistantTps||(e.headerMessageId===n||t.headerMessageId===n)&&e.headerMessageId!==t.headerMessageId)return!1;let i=e.activityOwnerMessageId===n||t.activityOwnerMessageId===n;if(i&&e.activityOwnerMessageId!==t.activityOwnerMessageId||!hM(e.activityParts,t.activityParts,n))return!1;if((e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&e.activityParts!==t.activityParts){let n=Jj((e.activityParts??[]).map(e=>e.part)),r=Jj((t.activityParts??[]).map(e=>e.part));if(n.childSessionIDs.size!==r.childSessionIDs.size||n.shellIDs.size!==r.shellIDs.size||[...n.childSessionIDs].some(e=>!r.childSessionIDs.has(e))||[...n.shellIDs].some(e=>!r.shellIDs.has(e)))return!1}if(!vM(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=_M(e.activityGroupSegments,n)||_M(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!fM(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!pM(e.changedFiles,t.changedFiles))},bM=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,xM=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,SM=/(?=^diff --git\s+)/gm,CM=/^diff --git\s+/m,wM=/(?=^---\s+\S)/gm,TM=/^---\s+\S/m,EM=e=>typeof e==`object`&&!!e,DM=e=>e.replace(/\r\n/g,`
|
|
6556
|
+
`)?`${t}\n`:`${t}\n\n`}`,sk=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},ck=(e,t,n,r)=>t?on({transportIdentity:e},t):n?nn({transportIdentity:e},n):r,lk=[],uk={get:e=>Ne().get(e)?.title||e},dk=({onOpenSettings:e,scrollToBottom:t,showScrollToBottom:n=!1,onScrollToBottom:r,submissionBlocked:i=!1,surface:a})=>{let{t:o,locale:s}=fr(),l=yl(),[d,p]=Z.useState({open:!1,title:``,content:``}),[m,h]=Z.useState(`normal`),[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),[b,x]=Z.useState(!1),[S,C]=Z.useState(``),[w,T]=Z.useState(!1),[O,k]=Z.useState(``),[A,j]=Z.useState([]),[M,N]=Z.useState(0),[P,F]=Z.useState(null),I=Z.useRef(null),L=Z.useRef(null),[R,z]=Z.useState(!1),B=Z.useRef(null);Z.useEffect(()=>()=>{B.current!==null&&window.clearTimeout(B.current),I.current!==null&&window.clearTimeout(I.current),L.current!==null&&window.clearTimeout(L.current)},[]);let[V,H]=Z.useState(!1),[U,W]=Z.useState(!1),[ee,te]=Z.useState(null),G=Z.useId(),[ne,re]=Z.useState(``),[ie,ae]=Z.useState(``),[oe,se]=Z.useState(!1),[ce,le]=Z.useState(!1),ue=Z.useRef(0),de=J(()=>{ue.current=Date.now()+500}),fe=Z.useRef(0),pe=Z.useRef(!1),[me,he]=Z.useState(-1),ge=Z.useRef(()=>{}),ve=Z.useRef((...e)=>Promise.resolve().then(()=>Wa.getState().sendMessage(...e))).current,ye=Wa(e=>e.currentSessionId),xe=ei(e=>e.currentProviderId),Se=ei(e=>e.currentModelId),we=ei(e=>e.currentAgentName),Te=ei(e=>e.currentVariant),De=ei(e=>e.providers),Oe=ei(e=>e.agents),ke=ei(e=>e.getVisibleAgents),Ae=Z.useMemo(()=>ry(ke()),[ke,Oe]),je=ei(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Me=ei(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Pe=Z.useMemo(()=>{let e=De.find(e=>e.id===xe)?.models?.find(e=>e.id===Se);return uy(e)},[Se,xe,De]),Ie=Z.useMemo(()=>({providers:De,agents:Ae,variants:Pe,variantsReady:!je,modelsReady:!je,agentsReady:!Me,ready:!je&&!Me,loading:je||Me}),[De,Ae,Pe,je,Me]),Le=At(e=>e.currentDirectory),ze=Nu()??Le,{ensureSessionRenderable:Be}=ch(),Ve=Wa(Z.useMemo(()=>e=>ye?e.getDirectoryForSession(ye):null,[ye])),Ue=Na(ye??``,Ve??void 0),We=Z.useMemo(()=>xD(Ue),[Ue]),Ge=Z.useMemo(()=>SD(Ue),[Ue]),Ke=ta(ye??``,Ve??void 0).renderable,qe=hr(ye,Ve??void 0),Je=qe?.agent,Ye=qe?.model?.id,Xe=qe?.model?.providerID,Ze=qe?.model?.variant,Qe=ei(e=>e.activeDirectoryKey),$e=Z.useRef(0),et=Z.useRef(null),it=Z.useRef(null),at=Wa(e=>e.newSessionDraft),st=!!at?.open,ct=Wa(e=>e.newSessionDraft.draftSubmitting??!1),ut=Wa(e=>e.newSessionDraft.draftEstablishing??!1),dt=ct||ut,ft=Wa(e=>e.setDraftPermissionAutoAcceptEnabled),pt=uo(e=>e.autoAccept),mt=uo(e=>e.saving),gt=uo(e=>e.setSessionAutoAccept),yt=Wa(e=>e.setNewSessionDraftTarget),bt=Wa(e=>e.availableWorktreesByProject),xt=Wa(e=>e.abortPromptSessionId),Ct=Wa(e=>e.abortPromptExpiresAt),wt=Wa(e=>e.clearAbortPrompt),Tt=fi(e=>e.consumePendingInputText),Ot=fi(e=>e.pendingPresetSubmit),Mt=fi(e=>e.pendingInputText),Ft=fi(e=>e.pendingInputMode),Lt=fi(e=>e.consumePendingSyntheticParts),Rt=fi(e=>e.activeAttachmentDraft),zt=mh(Z.useMemo(()=>e=>{let t=ye??(st?`draft`:``);return t?e.drafts[t]??TO:TO},[st,ye])),Bt=go(ye??``),Vt=Z.useSyncExternalStore(c,u,u),Ut=Rt?.transportIdentity??null,Gt=Rt?.owner.kind??null,Jt=Rt?.owner.ownerID??null,Xt=Z.useMemo(()=>ck(Vt,ye,at.draftID,Ut&&Gt&&Jt?{transportIdentity:Ut,owner:{kind:Gt,ownerID:Jt}}:null),[Jt,Gt,Ut,Vt,ye,at.draftID]),$t=Xt?nt(Xt):null,en=fi(Z.useMemo(()=>e=>$t?e.draftAttachmentViews[$t]:void 0,[$t])),tn=fi(Z.useMemo(()=>e=>$t?e.drafts[$t]:void 0,[$t])),nn=Z.useMemo(()=>{if(!tn||!en)return lk;let e=tn.attachments.flatMap(e=>{let t=en[e.attachmentRefID];return t?[t]:[]});return e.length===0?lk:e},[en,tn]);Z.useEffect(()=>{Xt&&fi.getState().hydrateDraftAttachments(Xt)},[Xt]);let rn=hy(),on=q(e=>e.activeMainTab===`chat`),sn=Fa(ye??``,ze??void 0),dn=gy({kind:`primary`,surfaceID:`primary`,active:on,sessionID:ye,directory:ze??null,activity:{phase:sn?.type===`busy`?`busy`:sn?.type===`retry`?`retry`:`idle`,canAbort:sn?.type===`busy`||sn?.type===`retry`},draftKey:Xt,transportIdentity:Vt,runtimeGeneration:f(),selection:{value:{providerID:xe,modelID:Se,agent:we,variant:Te},catalog:Ie,flush:async()=>{let e=Wa.getState().currentSessionId;if(!e)return;let t=f(),n=u(),r=$e.current,i=e,a=Wa.getState().getDirectoryForSession(i)??null,o=Gr(a);if(ei.getState().activeDirectoryKey!==o&&await ei.getState().activateDirectory(a),f()!==t||u()!==n||Wa.getState().currentSessionId!==i||ei.getState().activeDirectoryKey!==o||$e.current!==r)return;await Be(i,{directory:a??void 0});let s=Wa.getState().getDirectoryForSession(i)??null,c=Gr(s);if(f()!==t||u()!==n||Wa.getState().currentSessionId!==i||s!==a||c!==o||ei.getState().activeDirectoryKey!==o||$e.current!==r)return;let l=ei.getState(),d={providers:l.providers,agents:l.getVisibleAgents()};if(d.providers.length===0||d.agents.length===0)return;let p=vt(i,s??void 0),m=xD(p),h=SD(p);if(mD({editRevision:r,pinnedHistoryMessageId:et.current,latestHistoryMessageId:m?.id??null}))return;let g=Oi.getState(),_=Ne().get(i),v=dD({sessionId:i,latestUserChoice:m,latestExecution:h,catalog:d,memory:g,sessionEntity:_?.model?{agent:_.agent,model:{id:_.model.id,providerID:_.model.providerID,variant:_.model.variant}}:_?.agent?{agent:_.agent}:null,fallbackAgentName:l.currentAgentName});if(!v)return;let y=[i,v.source,v.messageId??``,v.agent??``,v.providerID,v.modelID,v.variant??``,o].join(`|`);it.current!==y&&(fD(v,{currentAgentName:l.currentAgentName,setAgent:l.setAgent,setProvider:l.setProvider,setModel:l.setModel,setCurrentVariant:l.setCurrentVariant},{sessionId:i,memory:g}),it.current=y)},change:async e=>{$e.current+=1;let t=Wa.getState().currentSessionId;if(t){let e=Wa.getState().getDirectoryForSession(t)??void 0,n=xD(vt(t,e));et.current=n?.id??null}else et.current=null;let n=ei.getState();aD(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:Oi.getState()})}},resources:{attachments:nn,addAttachment:async e=>{Xt&&await Pa(Xt,()=>fi.getState()).addLocal(e)},removeAttachment:async e=>Xt?Pa(Xt,()=>fi.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>Xt?Pa(Xt,()=>fi.getState()).clearRootAttachments():!1,restoreAttachments:async e=>Xt?Pa(Xt,()=>fi.getState()).restoreRootAttachments(e):!1,pendingInput:Mt===null?null:{text:Mt,mode:Ft},consumePendingInput:Tt,pendingPreset:Ot,consumePendingPreset:()=>fi.getState().consumePendingPresetSubmit(),consumeSyntheticParts:Lt,restoreSyntheticParts:e=>fi.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:zt,removeInlineDraft:e=>{let t=ye??(st?`draft`:``);t&&mh.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=ye??(st?`draft`:``);!t||e.length===0||mh.setState(n=>{let r=n.drafts[t]??[],i=new Set(e.map(e=>e.id));return{drafts:{...n.drafts,[t]:[...e,...r.filter(e=>!i.has(e.id))]}}})},history:Bt,captureRuntime:()=>fi.getState().captureDraftRuntime(),getDraft:e=>fi.getState().getDraft(e),abortPrompt:{sessionID:xt,clear:wt}},backend:{send:e=>{tD(e,{transportIdentity:u(),runtimeGeneration:f()});let t=nD(e);return ve(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>lu(e.sessionID??``,{delivery:e.options?.delivery===`steer`?`steer`:void 0,queueItemID:e.queueItemID,manual:e.manual,scope:e.queueScope?{state:`bound`,...e.queueScope}:void 0}),create:async()=>Ya(),compact:async e=>Kt.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&xu(e.sessionID),hi(e.sessionID??``))},shortcuts:{cycle:e=>ge.current(e),new:()=>Ya(),abort:()=>(ye&&xu(ye),hi(ye??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),K=_y(dn,a??rn);vy(K),Z.useLayoutEffect(()=>{if(!K.active){eD(K.surfaceID);return}return $E(K),()=>eD(K.surfaceID)},[K]);let pn=iD(K),hn=K.resources??(K.kind===`primary`?dn.resources:void 0);if(!hn)throw Error(`chat-input-surface-resources-incomplete`);let _n=[...hn.attachments],vn=K.sessionID,yn=yy(K,dt),bn=K.kind===`secondary`?K.commands.hasNewDraft:st,xn=bn,Sn=K.directory??ze,Cn=K.draftKey??Xt,wn=Z.useMemo(()=>{if(K.kind===`secondary`)return xy(K,!1,!1);let e=vn?PO(vn,Ve??void 0):!1;return xy(K,e,bn)},[K,vn,Ve,bn]),Tn=(e,t,n,r,i,a,o,s,c,l)=>pn?pn.send({providerID:t,modelID:n,agent:r,variant:s,text:e,attachments:i,agentMention:a,parts:o,systemContext:o?.filter(e=>e.synthetic).map(e=>({text:e.text,synthetic:!0})),inputMode:c,options:l}):Promise.reject(Error(`chat-input-surface-incomplete`)),En=J(()=>pn?pn.abort():Promise.reject(Error(`chat-input-surface-incomplete`))),Dn=Mr(e=>e.projects),On=Mr(e=>e.activeProjectId),kn=Mr(e=>e.setActiveProjectIdOnly),An=Z.useMemo(()=>vn?Ei({autoAccept:pt,sessions:[],sessionById:Ne(),sessionID:vn}):at.permissionAutoAcceptEnabled===!0,[vn,at.permissionAutoAcceptEnabled,pt]),jn=ei(e=>e.agents),Mn=K.kind===`secondary`?K.selection.value.agent:we,Nn=K.kind===`secondary`?ry(K.selection.catalog?.agents):jn,Pn=E()||KE(Nn,Mn),In=J(()=>{no.error(o(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))}),Ln=K.selection.value,zn=K.selection.change,Bn=K.selection.catalog,Vn=J(async e=>{if(!zn)throw Error(`chat-input-surface-selection-readonly`);await zn({...e,agent:e.agent??void 0,variant:e.variant})}),Hn=Z.useMemo(()=>({selection:{providerID:Ln.providerID??``,modelID:Ln.modelID??``,agent:Ln.agent??null,variant:Ln.variant},onChange:Vn,disabled:!K.active,catalog:Bn}),[Bn,Vn,Ln.agent,Ln.modelID,Ln.providerID,Ln.variant,K.active]);Z.useEffect(()=>{$e.current=0,et.current=null,it.current=null},[ye]),Z.useEffect(()=>{if(K.kind!==`primary`||!ye||je||Me||De.length===0||Ae.length===0)return;let e=Gr(Ve);if(Qe!==e)return;let t=Oi.getState(),n={providers:De,agents:Ae};if(mD({editRevision:$e.current,pinnedHistoryMessageId:et.current,latestHistoryMessageId:We?.id??null}))return;let r=dD({sessionId:ye,latestUserChoice:We,latestExecution:Ge,catalog:n,memory:t,sessionEntity:Xe&&Ye?{agent:Je,model:{id:Ye,providerID:Xe,variant:Ze}}:Je?{agent:Je}:null,fallbackAgentName:we,transcriptReady:Ke});if(!r)return;let i=[ye,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,Qe].join(`|`);if(it.current===i)return;if((r.agent===void 0||r.agent===we)&&r.providerID===xe&&r.modelID===Se&&r.variant===Te){it.current=i;return}if(ei.getState().activeDirectoryKey!==e)return;let a=ei.getState();fD(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:ye,memory:t}),it.current=i},[K.kind,ye,We,Ge,Ke,De,Ae,je,Me,Qe,Ve,we,xe,Se,Te,Je,Ye,Xe,Ze]);let Un=ei(e=>K.kind===`primary`?e.providers:EO),Wn=K.kind===`secondary`?K.selection.catalog?.agents:void 0,Gn=Z.useMemo(()=>K.kind===`secondary`?ry(Wn):Ae,[K.kind,Wn,Ae]),Kn=K.kind===`secondary`?K.selection.catalog?.providers??EO:Un,qn=K.kind===`secondary`&&(!K.selection.catalog?.ready||!!K.selection.catalog.error),Yn=!K.active||!K.selection.change||qn,Zn=q(e=>e.isMobile),Qn=mc(),$n=q(e=>e.setImagePreviewOpen),er=J(e=>{e.image&&(p(e),$n(!0))}),tr=J(e=>{p(t=>({...t,open:e})),$n(e)}),nr=Xm(e=>e.pending),rr=q(e=>e.inputBarOffset),ar=q(e=>e.persistChatDraft),or=q(e=>e.inputSpellcheckEnabled),cr=q(e=>e.isExpandedInput),lr=q(e=>e.setExpandedInput),ur=q(e=>e.setTimelineDialogOpen),dr=WD({draftKey:Cn,sessionTitles:uk,persistenceEnabled:ar}),pr=dr.document,mr=pr.text,{replacePlainDocument:gr,replaceProgrammaticText:_r,applyBrowserEdit:vr,insertReference:yr,deleteReference:br,enterHistoryPreview:xr,exitHistoryPreview:Sr,captureSubmission:Cr,recoverSubmission:wr,confirmedFileMentions:Tr,mentions:Dr}=dr,Or=J((e,t)=>_r(e,t)),kr=Z.useMemo(()=>new Set(Tr.map(e=>e.value)),[Tr]),Ar=Z.useRef(null),Nr=Z.useRef(!1),Pr=Z.useRef(0),Fr=Z.useRef(null),Ir=Z.useRef(null),Lr=Z.useRef(0),zr=Z.useRef(!1),Br=Z.useRef(null),Vr=Z.useRef(!1),Hr=Z.useRef(null),Ur=Z.useRef([]),Wr=Z.useRef(!1),Kr=Z.useRef(null),Jr=Z.useRef(!1),Yr=Z.useRef(null),Xr=Z.useRef(mr),Zr=Z.useRef(new Set),ti=dr.getDocument,ni=J((e,t,n=[])=>Or(e,(e,r)=>{let i=[],a=new Set(n);for(let e of t){let t=0,n=`@${e}`;for(;t<r.text.length;){let o=r.text.indexOf(n,t);if(o<0)break;i.push({kind:a.has(e)?`directory`:`file`,value:e,path:e,label:e,range:{start:o,end:o+n.length}}),t=o+n.length}}let o=new Set(e.map(e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`));return[...e,...i.filter(e=>!o.has(`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`))]})),ri=Qb(Zb()),{git:ii,vscode:ai}=Rn(),oi=q(e=>e.shortcutOverrides.cycle_agent),ci=q(e=>e.shortcutOverrides),li=Z.useMemo(()=>Ns(`cycle_agent`,oi?{cycle_agent:oi}:void 0),[oi]),ui=Z.useMemo(()=>Ns(`clear_all_messages`,ci),[ci]),{currentTheme:di}=Io(),pi=Wc(),mi=Kc(Sn),gi=sl(e=>Sn?e.directories.get(Sn)?.status??null:null),_i=sl(e=>e.ensureStatus),yi=sl(e=>e.fetchStatus),[bi,wi]=Z.useState(!1),Ti=Z.useRef(null);Z.useEffect(()=>{!Sn||!ii||_i(Sn,ii)},[Sn,ii,_i]),Z.useEffect(()=>{if(!(!Sn||!ii))return sa.onGitRefreshHint(e=>{BO(e.directory)===BO(Sn)&&yi(Sn,ii)})},[Sn,ii,yi]);let Di=cr&&!Zn,ki=cr&&Zn,Ai=Di||ki,ji=`1.5rem`,Mi=o(vn||bn?m===`shell`?`chat.chatInput.placeholder.shell`:Zn?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Ni=_n,Pi=Z.useMemo(()=>new Set(Gn.map(e=>e.name.toLowerCase())),[Gn]),Fi=Z.useRef(Pi);Fi.current=Pi;let Li=OO({inputMode:m,message:mr,showCommandAutocomplete:w}),Ri=Ci({directory:Sn,enabled:Li}),zi=Z.useMemo(()=>Ri.data??[],[Ri.data]),Bi=oa({directory:Sn,enabled:m!==`shell`}),Vi=Z.useMemo(()=>Bi.data??[],[Bi.data]),Hi=Z.useMemo(()=>new Map(Vi.map(e=>[e.name.toLowerCase(),e.name])),[Vi]),Ki=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);E()&&e.add(`reload`);for(let t of zi)t.source!==`skill`&&e.add(t.name.toLowerCase());return e},[zi]),qi=Z.useMemo(()=>{if(!mr||!mr.includes(`/`)||m===`shell`||Ki.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${tt})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(mr))!==null;){let t=n[2]??``,r=n[3];if(!Ki.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length;e.push({start:i,end:i+a,style:`mentionCommand`,visual:ot({trigger:`/`,icon:`command`,label:r},mr.slice(i,i+a))})}return e},[m,Ki,mr]),Xi=Z.useMemo(()=>!mr||!mr.includes(`@`)||m===`shell`?[]:Oo(mr,{confirmedValues:kr,agentNames:Pi}),[kr,m,Pi,mr]),Zi=Z.useMemo(()=>{if(!mr||!mr.includes(`[`)||m===`shell`||Ni.length===0)return[];let e=Ni.filter(_e),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return qt(mr,e.map(e=>e.filename)).flatMap(e=>{let n=ht(mr.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:ot({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},mr.slice(e.start,e.end))}]})},[m,mr,Ni]),$i=l&&Pl(Zn)&&K.kind===`primary`,{globallyEnabled:ea,enabled:na,hint:ra,onHintChange:ia}=dc({available:Zn&&!$i}),ca=o(ra===`recording`?`chat.dictation.releaseSend`:ra===`cancelling`?`chat.dictation.releaseCancel`:ra===`editing`?`chat.dictation.releaseEdit`:ra===`processing`?`chat.dictation.processing`:`chat.dictation.inputPlaceholder`),[la,ua]=Z.useState(!1),[fa,pa]=Z.useState(!1),[ma,ha]=Z.useState(null),ga=Z.useMemo(()=>{if(!mr||m===`shell`)return null;let e=[...jc(Xi),...qi,...Zi,...ma?.draftID===$t&&ma?.text===mr?[{start:ma.start,end:ma.end,style:`dictation`}]:[],...pr.references.map(e=>({start:e.start,end:e.end,priority:103,...lt(e)}))];return Sc(mr,e)},[Zi,qi,Xi,pr.references,m,mr,ma,$t]),[_a,va]=Z.useState(null),ya=Z.useRef(null),[xa,Sa]=Z.useState(!1),[Ca,wa]=Z.useState(!1),[Ta,Ea]=Z.useState(null),[Oa,ka]=Z.useState(null),Aa=It(e=>e.followUpBehavior),ja=Z.useMemo(()=>{let e=pn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[pn]),Ia=Dh({transportIdentity:ja?.transportIdentity??``,directory:ja?.directory??``,sessionID:ja?.sessionID??``}),Ra=Z.useMemo(()=>vn?an(vn):null,[vn]),za=It(Z.useMemo(()=>e=>ja?Qt(e,ja):wO,[ja])),Ba=It(Z.useMemo(()=>e=>Ra?Qt(e,Ra):wO,[Ra])),Va=Z.useMemo(()=>Ba.length===0?za:za.length===0?Ba:[...Ba,...za],[za,Ba]),Ha=Ia.mode===`server`?wO:Va,Ua=It(Z.useMemo(()=>e=>ja?Dt(e,ja):wO,[ja])),Ga=It(e=>e.clearQueue),Ka=It(e=>e.removeFromQueue),Ja=hn.inlineDrafts,Xa=Ja.length>0,[Za,Qa,$a]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of Ja)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[Ja]),eo=J(e=>{for(let t of hn.inlineDrafts)t.source===e&&hn.removeInlineDraft(t.id)}),to=J(()=>{for(let e of hn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&hn.removeInlineDraft(e.id)}),ro=hn.history;Z.useEffect(()=>{Xr.current=mr},[mr]),Z.useLayoutEffect(()=>{h(`normal`),he(-1)},[Cn?.transportIdentity,Cn?.owner.kind,Cn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!bn||Zn)return;let e=()=>{let e=Ar.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[bn,Zn]);let io=Cx(K.kind===`primary`?vn:null,K.kind===`primary`?Sn??void 0:void 0),ao=K.activity?.phase??io.phase,oo=J(e=>{Zn&&(de(),F(e),Ar.current?.blur(),ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),co=hn.pendingInput,lo=hn.consumePendingInput;Z.useEffect(()=>{if(co===null)return;let e=lo();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=ok(Xr.current,e.text);Xr.current=t,Or(t)}else if(e.mode===`append-inline`){let t=sk(Xr.current,e.text);Xr.current=t,Or(t)}else gr(e.text);setTimeout(()=>{Ar.current?.focus()},0)}},[co,lo,gr,Or]);let fo=Mg(vn,at.draftID),po=Wg(Gg(fo)),ho=mr.trim().length>0||Ni.length>0||Xa||po.length>0,_o=K.kind===`primary`&&OC(mr,m)===`btw`,yo=Ia.mode===`server`?Ia.items.length>0:Ha.length>0||Ua.length>0,xo=!_o&&!O_(Ia.mode),Co=ho||yo,wo=Wa(e=>e.stagedMessageEdit?.sessionId===vn?e.stagedMessageEdit.messageId:null),To=ao===`busy`||ao===`retry`,ko=!_o&&(K.activity?.canAbort??To),Ao=J(()=>{let e=Ar.current,t=e?.value??ti().text;t!==ti().text&&vr(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=ti();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Ni.length>0||Xa||po.length>0}}),jo=K.surfaceID,Mo=at?.draftID??null,No=Da(Z.useMemo(()=>jr(jo),[jo])),Po=Da(Z.useMemo(()=>si(Mo),[Mo])),Fo=Z.useMemo(()=>Si(_o?null:No,!_o&&Po),[No,Po,_o]),Lo=(e=`send`)=>Da.getState().beginFlight(jo,e),Ro=()=>{Da.getState().endFlight(jo)},zo=()=>Da.getState().isInFlight(jo),Bo=Z.useRef(null);Z.useEffect(()=>{if(K.kind!==`primary`||!wo){Bo.current=null;return}if(Bo.current!==wo){if(Bo.current=wo,$i){Al().focus();return}sy(Ar)||requestAnimationFrame(()=>sy(Ar))}},[$i,wo,K.kind]);let Vo=Da(Z.useMemo(()=>Er(Mo),[Mo])),Ho=ln(Z.useMemo(()=>e=>vn?e.bySession[vn]:void 0,[vn])),Uo=Z.useMemo(()=>{if(!Ho?.length)return rt;let e=new Set(Ue.map(e=>e.id));return Ho.filter(t=>!e.has(t.id)).map(jt)},[Ho,Ue]),[Wo,Go]=Z.useState(null),[Ko,qo]=Z.useState(()=>new Set),Yo=Wo&&Wo.sessionID===vn&&Du(Wo.runtime,hn.captureRuntime())&&!Zt(Wo.sessionID,Wo.item.messageID)&&!Uo.some(e=>e.messageID===Wo.item.messageID)?Wo.item:null,Xo=Z.useMemo(()=>[...Vo,...Uo,...Yo?[Yo]:[]],[Vo,Uo,Yo]);Z.useEffect(()=>{qo(e=>{if(e.size===0)return e;let t=new Set;for(let e of Uo)t.add(e.messageID);Yo&&t.add(Yo.messageID);let n=!1;for(let r of e)if(!t.has(r)){n=!0;break}if(!n)return e;let r=new Set;for(let n of e)t.has(n)&&r.add(n);return r})},[Uo,Yo]);let Zo=Ht(Z.useMemo(()=>e=>vn?e.runningBySession[vn]===!0:!1,[vn])),Qo=J(async()=>{let e=Wa.getState().newSessionDraft.draftID;if(!e||!Da.getState().isEstablishing(e))return!1;let t=Ao();if(!t.hasContent)return!1;let n=Mg(null,e),r=n?Wg.getState().quotesByKey[n]??[]:[],i=Hg(t.document,r),a=be(i,`queue-canonical`);if(!a.ok)return no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1;if(await K.selection.flush(),!Da.getState().isEstablishing(e))return!1;let s=pD(ei.getState());if(!s?.providerID||!s?.modelID)return no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1;let c=UO(Ni);return Da.getState().enqueueEstablishingFollowUp({draftID:e,content:a.text,sendConfig:{providerID:s.providerID,modelID:s.modelID,...s.agent?{agent:s.agent}:{},...s.variant?{variant:s.variant}:{}},attachments:c,composerDocument:i})?(gr(``),n&&i!==t.document&&Wg.getState().clear(n),he(-1),lr(!1),c.length>0&&hn.clearAttachments(),!0):!1}),es=()=>{if(vn)return!1;let e=Wa.getState().newSessionDraft.draftID;return Da.getState().isEstablishing(e)?(Qo(),!0):!1},ts=J(async()=>{if(!K.active||zo())return;if(K.kind===`primary`&&vn){let e=Wa.getState().stagedMessageEdit;if(e&&e.sessionId===vn){await ls();return}}let e=Ao(),t=be(e.document);if(!t.ok){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let n={chunks:t.chunks??[],semantics:t.semantics??[]},r=t.text,a=r.trimStart(),s=n.chunks.every(e=>e.provenance===`authored`)&&m===`normal`&&a.startsWith(`/`)?Rc(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(s&&!Bc(s,e=>py(K,{name:e.name,source:`yuri`}))||i||!e.hasContent||!vn)return;if(K.kind===`primary`&&m===`normal`&&(so.getState().armed||gn(r)?.commandName.toLowerCase()===`goal`)){ls(To?{delivery:`queue`}:void 0);return}if(xo||!_u(K.deliveryTarget?.kind,Ia.mode)){ls(To?{delivery:`steer`}:void 0);return}if(n.chunks.every(e=>e.provenance===`authored`)&&kC(r,m)){ls();return}if(!Lo(`queue`))return;let c=K.transportIdentity,l=K.runtimeGeneration,d=hn.captureRuntime(),p=ja,h=K.kind===`primary`?ja?.sessionID??vn:null,g=[...hn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?un(_h(e.document.text,g),e.document.references).document:e.document,v=fo?Wg.getState().quotesByKey[fo]??[]:[],y=Hg(_,v),b=y!==_,x=be(y,`queue-canonical`);if(!x.ok){Ro(),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let S=UO(Ni),C=Cr(),w=S,T=Tu(),E=!1,D=null,O=()=>{E&&p&&(Ia.actions.unstageAdmission({requestID:T.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),E=!1),D&&p&&(It.getState().unstageAdmission(p,D),D=null)},k=async e=>{O(),C&&wr(C),w.length>0&&await hn.restoreAttachments(w),e&&hn.restoreSyntheticParts(e),g.length>0&&hn.restoreInlineDrafts(g),b&&fo&&Wg.getState().restore(fo,v)};try{if(!p){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}if(Ia.mode===`server`){if(!Cn){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}fu({stage:()=>{Ia.actions.stageAdmission({requestID:T.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:T.queueItemID,operationID:T.operationID,messageID:T.messageID,content:x.text,createdAt:T.createdAt,attachmentCount:S.length,composerDocument:y,composerMentions:Dr}}),E=!0},clearComposer:()=>{gr(``),b&&fo&&Wg.getState().clear(fo),he(-1),lr(!1)}})}else fu({stage:()=>{It.getState().bindLegacyQueue(an(p.sessionID),p),It.getState().stageAdmission(p,{requestID:T.requestID,queueItemID:T.queueItemID,operationID:T.operationID,messageID:T.messageID,content:x.text,createdAt:T.createdAt,attachmentCount:S.length,composerDocument:y,composerMentions:Dr}),D=T.requestID},clearComposer:()=>{gr(``),b&&fo&&Wg.getState().clear(fo),he(-1),lr(!1)}});if(await K.selection.flush(),!Du({transportIdentity:c,generation:l},{transportIdentity:u(),generation:f()})){await k();return}if(!Du(d,hn.captureRuntime())){await k();return}if(h&&Wa.getState().currentSessionId!==h){await k();return}if(p.transportIdentity!==u()||p.runtimeGeneration!==f()||p.sessionID!==(h??p.sessionID)||h&&Xn(Wa.getState().getDirectoryForSession(h))!==Xn(p.directory)){await k();return}let t=p,n=K.kind===`primary`?(()=>{let e=ei.getState(),t=h?Wa.getState().getDirectoryForSession(h)??null:null;return pD(e,{expectedConfigKey:Gr(t),activeDirectoryKey:e.activeDirectoryKey})})():K.selection.value.providerID&&K.selection.value.modelID?{...K.selection.value,providerID:K.selection.value.providerID,modelID:K.selection.value.modelID}:void 0;if(!cu(n)){await k();return}if(Ia.mode===`server`){if(!Cn){await k(),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let r=ou({draftKey:Cn,runtime:d,document:e.document,attachments:Ni,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?hn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??Jn()}))??null:null,a,s=[],c=t.deliveryTarget.kind===`assistant`?(()=>{let e=Xl({plan:{chunks:x.chunks??[],semantics:x.semantics??[]},agents:Gn,installedSkillNames:new Set(Qi(Fn,Sn).map(e=>e.name)),directory:Sn,root:pi||Sn,confirmedFilePaths:Tr.map(e=>e.path),confirmedDirectoryPaths:Tr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ni});return s=e.attachments,Jl({text:g.length>0?_h(e.text,g):e.text,attachments:[...S,...e.attachments],semanticParts:vo(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...pu(S),...pu(s),...(i??[]).flatMap(e=>pu(e.attachments??[],e.partID))],t=c?new Set(c.flatMap(e=>e.type===`file`?[e.attachmentID]:[])):null;a=e.filter((n,r)=>e.findIndex(e=>e.attachmentID===n.attachmentID)===r&&(!t||t.has(n.attachmentID)))}catch(e){await k(i),no.error(o(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let l=c&&i?Eu(c,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,s=await bu({capture:r,admit:async()=>{let r=await Ia.actions.admit({requestID:T.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:T.queueItemID,operationID:T.operationID,messageID:T.messageID,content:x.text,composerDocument:y,composerMentions:Dr,sendConfig:n,deliveryTarget:t.deliveryTarget,...c?{deliveryParts:c}:{},...l?{syntheticParts:l}:{},attachmentIssues:[],createdAt:T.createdAt},attachments:a});return r.status===`committed`&&(e=!0,E=!1),r},captureRuntime:hn.captureRuntime,getCurrentDraftKey:()=>Cn,getDocument:ti,consumeBody:()=>gr(``),getAttachments:()=>hn.attachments,removeAttachment:hn.removeAttachment,getInlineDrafts:()=>hn.inlineDrafts,removeInlineDraft:hn.removeInlineDraft});if(!e){await k(i),s.status===`stale`&&no.error(o(`chat.chatInput.toast.messageSendFailed`));return}if(s.status===`partial`){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}s.status===`committed`&&!Zn&&Ar.current?.focus()}catch(e){await k(i),no.error(o(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!It.getState().confirmAdmission(t,{requestID:T.requestID,sendConfig:n,attachments:S.length>0?S:void 0}).ok){await k(),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}D=null;for(let e of g)hn.removeInlineDraft(e.id);S.length>0&&hn.clearAttachments(),Zn||Ar.current?.focus()}catch(e){await k(),no.error(o(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Ro()}}),ns=J(()=>{HE(()=>ts(),()=>{no.error(o(`chat.chatInput.toast.messageSendFailed`))})}),is=J(async(e,t,n,r)=>{if(xo||!K.draftKey)return!1;try{let i=await Yi({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=fi.getState(),s=a.getDraft(K.draftKey);return A_(await ba({key:K.draftKey,expectedRevision:s?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return no.error(o(`chat.chatInput.toast.messageSendFailed`)),!1}}),as=J(e=>{if(!(i||xo)){if(pn){pn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}no.error(o(`chat.chatInput.toast.messageSendFailed`))}}),os=J(()=>{de(),F(`agent`),Ar.current?.blur(),ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),ss=J(()=>{Sa(!0)}),cs=J(()=>{wa(!0)}),ls=J(async e=>{if(!K.active||i)return;if(!e?.queuedOnly){let t=e?.presetText==null?Ao():null;if(jC({text:e?.presetText??t?.message??``,inputMode:m,scope:vn&&Sn?{sessionId:vn,directory:Sn}:null,hasReferences:!!(t?.document.references.length||Dr.length),allowed:K.kind===`primary`&&py(K,{name:`btw`,source:`yuri`}),ask:fw.getState().ask,clearText:()=>{gr(``),T(!1),k(``)},open:()=>{Zn&&(de(),Ar.current?.blur()),vn&&NE({sessionId:vn,directory:Sn??null})},notify:e=>no.error(o(`chat.btw.${e}`))}))return}if(es()||zo())return;let n=e?.queuedOnly??!1,r=e?.queuedMessageId,a=Wa.getState().stagedMessageEdit,s=K.kind===`primary`&&!n&&!!(vn&&a?.sessionId===vn),c=e?.presetText==null?Ao():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Ni.length>0||Xa},l=e?.presetText==null?Cr():null,d=_n,p=be(c.document,`direct-send-display`);if(!p.ok){no.error(o(`chat.chatInput.toast.messageSendFailed`));return}let h=p.text,g={chunks:p.chunks??[],semantics:p.semantics??[]},_=g.chunks.every(e=>e.provenance===`authored`),v=h.trimStart(),y=_?OC(v,m):null,b=_&&kC(h,m),x=_&&m===`normal`&&/^\/model(?:\s|$)/i.test(v),S=_&&m===`normal`&&v.startsWith(`/`)?Rc(v.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0,C=K.kind===`primary`&&m===`normal`&&(so.getState().armed||gn(h)?.commandName.toLowerCase()===`goal`),w=!C&&!s&&e?.steerAfterAdmit===!0&&To&&K.kind===`primary`,D=s||C&&e?.steerAfterAdmit?`steer`:w?`queue`:e?.delivery,O=D===`queue`&&To?`queue`:D===`steer`&&To?`steer`:void 0;if(S&&!Bc(S,e=>py(K,{name:e.name,source:`yuri`}))||n&&xo)return;if(!n&&x){T(!1),k(``),Zn?oo(`model`):(q.getState().setModelSelectorOpen(!0),ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}let A=!C&&!s&&!w&&iu({hasQueuedMessages:yo,sessionIsRunning:To,queuedOnly:n,delivery:O});if(!(!n&&y&&y!==`model`)){if(vn&&A&&xo)return;if(vn&&A&&Ia.mode===`server`){c.hasContent&&ns();return}if(vn&&A){c.hasContent&&ns();let e=Ha[0];e&&pn&&await pn.sendQueued(e.queueItemID,{options:To?{delivery:`steer`}:void 0});return}}let j=b||!n&&c.hasContent&&!r?[]:r?Ha.filter(e=>e.id===r):Ha;if(n){if(j.length===0||!vn)return}else if(!c.hasContent&&!yo||!vn&&!bn)return;if(!vn&&yn||!Lo(O===`queue`?`queue`:`send`))return;let M=!vn&&bn&&!n&&!b?Wa.getState().newSessionDraft.draftID??null:null,N=M?Nt(`msg`):void 0;if(M&&N&&!Da.getState().beginEstablishing({draftID:M,primaryMessageID:N})){Ro();return}let P=()=>{Ma(),M&&Da.getState().clearEstablishing(M)},F=e=>{let t=Wa.getState().currentSessionId,n=(t?Wa.getState().getDirectoryForSession(t):null)??Sn??``;if(!t||!n){Da.getState().clearEstablishing(e);return}VE({draftID:e,sessionID:t,directory:n,transportIdentity:u(),runtimeGeneration:f(),admitServer:Ia.mode===`server`?async e=>Ia.actions.admit({requestID:e.requestID,scope:{directory:n,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?pu(e.attachments):void 0}):void 0})},I=!n&&!b,L=K.kind===`primary`&&vn&&O===`queue`&&!n&&!b&&!y&&!C&&m===`normal`?Nt(`msg`):void 0,R=()=>{L&&Go(e=>e?.item.messageID===L?null:e)};L&&vn&&(w&&qo(e=>{if(e.has(L))return e;let t=new Set(e);return t.add(L),t}),Go({sessionID:vn,runtime:hn.captureRuntime(),item:{kind:`pending-admission`,requestID:L,queueItemID:L,operationID:L,messageID:L,content:h,createdAt:Date.now(),phase:`admitting`,attachmentCount:Ni.length,composerDocument:c.document,composerMentions:Dr}}));let z=fo?Wg.getState().quotesByKey[fo]??[]:[],B=zg(z,h)!==h,V=!1,H=()=>{!V||!fo||(Wg.getState().restore(fo,z),V=!1)};I&&(gr(``),B&&fo&&(Wg.getState().clear(fo),V=!0),he(-1),lr(!1));let U=!1,W,ee,te=hn.captureRuntime(),G=!1;try{if(LE({surfaceKind:K.kind,currentSessionId:vn,queuedOnly:n,delivery:O,resourcePolicy:b,inputMode:m,localCommand:y,nativeGoal:C})&&vn){let e=Wa.getState().getDirectoryForSession(vn)??Sn??null,t=Wa.getState().stagedMessageEdit;t&&t.sessionId===vn&&(ee={sessionId:t.sessionId,messageId:t.messageId},Wa.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=ei.getState(),r=hD({captured:pD(n,{expectedConfigKey:Gr(e),activeDirectoryKey:n.activeDirectoryKey}),surfaceSelection:K.selection.value});if(!ee&&r?.providerID&&r?.modelID){let t=UO(Ni);W=qr({sessionId:vn,directory:e,content:B?zg(z,h):h,providerID:r.providerID,modelID:r.modelID,agent:r.agent,variant:r.variant,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=K.kind===`primary`?(()=>{if(n){let e=j[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(ja?.sessionID)return ja.sessionID}return vn})():null,i=n?j[0]?.sendConfig:void 0;if(n&&i||await K.selection.flush(),e!==null&&Wa.getState().currentSessionId!==e)return;let a=async()=>{let t=i?{...i}:K.kind===`primary`?(()=>{let t=ei.getState();if(!e)return hD({captured:pD(t),surfaceSelection:K.selection.value});let n=Wa.getState().getDirectoryForSession(e)??Sn??null;return hD({captured:pD(t,{expectedConfigKey:Gr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:K.selection.value})})():K.selection.value.providerID&&K.selection.value.modelID?{...K.selection.value,providerID:K.selection.value.providerID,modelID:K.selection.value.modelID}:void 0;if(K.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=Wa.getState().getDirectoryForSession(e)??Sn??null,r=Gr(n);if(ei.getState().activeDirectoryKey!==r&&await ei.getState().activateDirectory(n),Wa.getState().currentSessionId===e){let e=ei.getState();t=hD({captured:pD(e,{expectedConfigKey:Gr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:K.selection.value})}}return t},s=await a(),u=!1,f=s?.providerID,p=s?.modelID,_=s?.agent,v=s?.variant;if(!f||!p){if(!u){u=!0;try{await ei.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),s=await a(),f=s?.providerID,p=s?.modelID,_=s?.agent,v=s?.variant}catch{}}if(!f||!p){console.warn(`Cannot send message: provider or model not selected`),no.error(o(`chat.chatInput.toast.messageSendFailed`));return}}vn&&!n&&!b&&!C&&O!==`queue`&&await So(vn)&&await hi(vn);let x={...O?{delivery:O}:{},commitStagedMessageEdit:!n&&O!==`queue`,...W?{messageID:W.messageID,ticket:W}:L||N?{messageID:L??N}:{},...e?{sessionId:e,directoryHint:Wa.getState().getDirectoryForSession(e)??Sn??null}:K.kind===`primary`&&vn?{sessionId:vn,directoryHint:Wa.getState().getDirectoryForSession(vn)??Sn??null}:{}},S=``,T=[],D,k=[],A=new Set(Qi(Fn,Sn).map(e=>e.name)),I=[],V=b?void 0:hn.consumeSyntheticParts();for(let e=0;e<j.length;e++){let t=j[e],n=t.composerDocument&&be(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Sn,a=new Set(Qi(Fn,i).map(e=>e.name)),o=Xl({plan:r??Yl(t.content),agents:Gn,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(I.push(...o.semantics),!D&&o.agent&&(D=o.agent),e===0)S=o.text,T=mo([...UO(t.attachments),...o.attachments]);else{let e=UO(t.attachments);k.push({text:o.text,attachments:mo([...e,...o.attachments])})}}if(!n&&c.hasContent){let e=UO(Ni),t=Xl({plan:g,agents:Gn,installedSkillNames:A,directory:Sn,root:pi||Sn,confirmedFilePaths:Tr.map(e=>e.path),confirmedDirectoryPaths:Tr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ni});I.push(...t.semantics),!D&&t.agent&&(D=t.agent);let n=B?zg(z,t.text):t.text;j.length===0?(S=n,T=mo([...e,...t.attachments])):k.push({text:n,attachments:mo([...e,...t.attachments])})}let ne=vn??(bn?`draft`:null),re=[];if(!n&&ne&&!b&&(re=[...hn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),re.length>0)if(j.length===0)S=_h(S,re);else if(k.length>0){let e=k[k.length-1];e.text=_h(e.text,re)}else S=_h(S,re);if(V&&V.length>0&&k.push(...au(V)),Ta&&k.push({text:Ta.contextText,synthetic:!0}),Oa&&(k.push({text:Oa.instructionsText,synthetic:!0}),k.push({text:Oa.contextText,synthetic:!0})),k.push(...vo(I,vn&&Wa.getState().getDirectoryForSession(vn)||Sn)),!S&&T.length===0&&k.length===0)return;if(M&&N){if(!await aa({messageID:N,providerID:f,modelID:p,agent:_,text:S,attachments:T,additionalParts:k,agentMentionName:D}))return;if(!Da.getState().isEstablishing(M)){P();return}}let ie=async()=>{if(H(),P(),ja&&j.length>0&&It.setState(e=>{let t=cn(ja),n=e.queuedMessages[t]??[],r=new Set(j.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...j,...n.filter(e=>!r.has(e.id))]}}}),n)return V&&hn.restoreSyntheticParts(V),!0;hn.pendingInput?.text===c.message&&hn.consumePendingInput(),l&&wr(l);let e=!0;return d.length>0&&(e=await hn.restoreAttachments(d)),V&&hn.restoreSyntheticParts(V),re.length>0&&hn.restoreInlineDrafts(re),e};if(!b&&vn&&r){let e=ja?Qt(It.getState(),ja).find(e=>e.id===r||e.queueItemID===r):void 0;ja&&e?.queueItemID&&e.operationID&&Ka(ja,e.queueItemID,e.operationID)}else!b&&vn&&j.length>0&&ja&&Ga(ja);!n&&!b&&(gr(``),he(-1),lr(!1),IE({queuedOnly:n,resourcePolicy:b,rootAttachmentCount:d.length})&&hn.clearAttachments());let ae=()=>PE({currentSessionId:vn,messageRef:Xr,replacePlainDocument:gr}),oe=S.trimStart();if(m===`normal`&&oe.startsWith(`/`)){let e=Rc(oe.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Bc(e,e=>py(K,{name:e.name,source:`yuri`})))return;if(vn&&(e===`undo`||e===`redo`)&&AC(oe,m)&&ae(),e===`undo`&&vn){try{await Wa.getState().handleSlashUndo(vn),t?.()}catch(e){no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){AC(oe,m)&&ae(),await pn?.shortcut(`new`);return}if(e===`redo`&&vn){try{await Wa.getState().handleSlashRedo(vn),t?.()}catch(e){no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&vn){await FE({command:`fork`,consumeCommandText:ae,forkSession:()=>Wa.getState().forkCurrentSession(vn),waitForConnection:da,getDirectoryForSession:()=>Wa.getState().getDirectoryForSession(vn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&vn&&ri.timeline){ur(!0);return}if(e===`reload`&&E()){ae(),no.info(o(`chat.chatInput.toast.reloadStarted`)),La().then(()=>{no.success(o(`chat.chatInput.toast.reloadSucceeded`))},()=>{no.error(o(`chat.chatInput.toast.reloadFailed`))});return}if(e===`compact`&&vn){FE({command:`compact`,consumeCommandText:ae,forkSession:async()=>void 0,waitForConnection:da,getDirectoryForSession:()=>K.directory??``,summarizeSession:e=>Cn?K.backend.compact({operation:`compact`,surfaceID:K.surfaceID,transportIdentity:K.transportIdentity,runtimeGeneration:K.runtimeGeneration,sessionID:vn,directory:e,draftKey:Cn,deliveryTarget:K.deliveryTarget,providerID:f,modelID:p,agent:_,variant:v}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{no.error(o(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&vn){try{await da();let e=oe.replace(/^\/\u2003?summary\b/i,``).trim(),n=e?` focused on: ${e}`:``,r=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await Jo(`session.summary.visible`,{topic_line:n}),a=await Jo(`session.summary.instructions`,{topic_block:r});await Tn(i,f,p,_,[],D,[{text:a,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(vn||bn)){try{await da();let e=await Jo(`session.review.visible`),n=await Jo(`session.review.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.reviewFailed`))}return}if(e===`craft-goal`&&(vn||bn)){try{await da();let e=oe.replace(/^\/\u2003?craft-goal\b/i,``).trim(),n=await Jo(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),r=await Jo(`session.craftGoal.instructions`);await Tn(n,f,p,_,[],D,[{text:r,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(vn||bn)){try{await da();let e=await Jo(`session.catchup.visible`),n=await Jo(`session.catchup.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(vn||bn)){try{await da();let e=await Jo(`session.debug.visible`),n=await Jo(`session.debug.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(vn||bn)){try{await da();let e=await Jo(`session.weigh.visible`),n=await Jo(`session.weigh.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(vn||bn)){try{await da();let e=await Jo(`session.explore.visible`),n=await Jo(`session.explore.instructions`);await Tn(e,f,p,_,[],D,[{text:n,synthetic:!0}],v,m,x),t?.()}catch(e){await ie(),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.exploreFailed`))}return}}let se=vn&&Wa.getState().getDirectoryForSession(vn)||Sn;if(xn||vn&&!PO(vn,se)){let e=await bo().catch(()=>null);e&&k.push({text:Et(e),synthetic:!0})}G=!0;let ce=Tn(S,f,p,_,T,D,k.length>0?k:void 0,v,m,x);U=!0,ce.finally(()=>{R(),Ro(),ee&&Du(te,hn.captureRuntime())&&Wa.getState().endMessageEditCommit(ee.sessionId,ee.messageId)}).catch(()=>{}),M&&ce.then(()=>{F(M)}).catch(()=>{Da.getState().clearEstablishing(M)}),typeof window>`u`?t?.():window.requestAnimationFrame(()=>{t?.()}),ce.then(async()=>{if(w&&L&&e){let t=()=>{qo(e=>{if(!e.has(L))return e;let t=new Set(e);return t.delete(L),t})};if(Zt(e,L)||!Wt({sessionID:e}))t();else{let n=Wa.getState().getDirectoryForSession(e)??Sn??``;try{await St({sessionID:e,inboxID:L,directory:n})}catch{t(),ln.getState().list(e).some(e=>e.id===L)&&no.error(o(`chat.chatInput.toast.messageSendFailed`))}}}Ta&&Ea(null),Oa&&ka(null)}).catch(e=>{W&&Gi(W),ie().then(e=>{e||no.error(o(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){no.error(o(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){d.length>0&&no.error(o(`chat.chatInput.toast.sendAttachmentsFailed`));return}no.error(t||o(`chat.chatInput.toast.messageSendFailed`))}),Zn||Ar.current?.focus()}finally{G||(W&&Gi(W),ee&&Du(te,hn.captureRuntime())&&Wa.getState().endMessageEditCommit(ee.sessionId,ee.messageId)),U||(R(),I&&l&&(wr(l),H()),Ro(),M&&F(M))}}),us=J(()=>{if(OC(Ao().message,m)===`btw`){ls();return}if(es()||zo())return;let e=Ao(),t=m===`normal`&&e.hasContent&&vn&&To,n=t&&O_(Ia.mode)&&_u(K.deliveryTarget?.kind,Ia.mode),r=UE({followUpBehavior:Aa,ctrlEnter:!1,canQueue:!!t,queueUsable:!!n,primary:K.kind===`primary`,sessionIsRunning:To});r.kind===`queue`?ns():r.delivery?ls({delivery:r.delivery}):ls()}),ds=J(e=>{if(zo())return;let t=(Ar.current?.value??Xr.current).trim(),n=t?`${e}\n${t}`:e;ls({presetText:n})}),fs=J(e=>{let t=sk(ti().text,e);Or(t),Ar.current&&(Ar.current.value=t),setTimeout(()=>{Ar.current?.focus()},0)}),ps=Z.useRef(null),ms=J(()=>{ha(null);let e=ti().text;ps.current={base:e,expected:e}}),hs=J((e,t=!1)=>{let n=ps.current;if(!n)return;if(ti().text!==n.expected){ps.current=null,ha(null);return}let r=sk(n.base,e),i=e.trim();ha(t||!i?null:{draftID:$t,text:r,start:r.length-i.length-1,end:r.length-1}),r!==n.expected&&(Or(r),Ar.current&&(Ar.current.value=r),n.expected=r),t&&(ps.current=null)}),gs=J(e=>hs(e,!0)),_s=J(()=>{ha(null),ps.current=null}),vs=J(e=>{if(zo())return;let t=sk(Ar.current?.value??Xr.current,e);ls({presetText:t})}),ys=Z.useRef(null),bs=J(e=>{let t=ti().text,n=sk(t,e);ys.current={base:t,expected:n},Or(n),Ar.current&&(Ar.current.value=n)}),xs=J((e,t)=>{let n=ys.current;if(ys.current=null,!n||ti().text!==n.expected)return;let r=sk(n.base,e);Or(r),Ar.current&&(Ar.current.value=r),t&&us()}),Ss=J(e=>xs(e,!1)),Cs=J(e=>xs(e,!0)),ws=J(()=>{ys.current=null}),Ts=hn.pendingPreset,Es=hn.consumePendingPreset;Z.useEffect(()=>{if(Ts==null)return;let e=Es();e&&ds(e)},[Ts,Es,ds]);let Ds=J(()=>{gr(``),he(-1),_n.length>0&&hn.clearAttachments(),ja&&Ga(ja),T(!1),x(!1),m===`shell`&&h(`normal`)}),Os=J(e=>{if(!K.active||Mc(e))return;if(ui&&rs(e,ui)&&!nr){let t=Ar.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),Ds();return}}if(m===`shell`&&e.key===`Escape`){e.preventDefault(),h(`normal`);return}if(m===`shell`&&e.key===`Backspace`&&mr.length===0){e.preventDefault(),h(`normal`);return}if(e.key===`Backspace`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&po.length>0){let t=Ar.current,n=t?.selectionStart??0,r=t?.selectionEnd??0;if(n===0&&r===0&&fo){e.preventDefault(),Wg.getState().removeLast(fo);return}}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Ar.current,n=t?.selectionStart??mr.length,r=t?.selectionEnd??mr.length,i=br({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=NO(dr.getDocument().text,i.start);e.preventDefault(),Or(t.text),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(t.caret,t.caret),Zs()}),Qs(t.text,t.caret);return}let a=Ce(mr,_n.filter(_e).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=NO(a.text,a.caret);e.preventDefault(),Or(n.text);for(let e of _n)t.has(e.filename.toLowerCase())&&hn.removeAttachment(e.id);requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=n.caret,Ar.current.selectionEnd=n.caret),Zs()}),Qs(n.text,n.caret);return}let o=vc(mr,Hi.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=NO(o.text,o.caret);e.preventDefault(),Or(t.text),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=t.caret,Ar.current.selectionEnd=t.caret),Zs()}),Qs(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<mr.length){let n=qt(mr,_n.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=ht(mr.slice(n.start+1,n.end-1)).trim(),r=_n.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=mr[n.end]===` `?n.end+1:n.end,a=`${mr.slice(0,n.start)}${mr.slice(i)}`;e.preventDefault(),Or(a),r&&hn.removeAttachment(r.id),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=n.start,Ar.current.selectionEnd=n.start),Zs()}),Qs(a,n.start);return}let r=Dr.find(n=>(n.kind===`file`||n.kind===`directory`)&&mr.slice(n.range.start,n.range.end)===`@${n.value}`&&(t>=n.range.start&&t<n.range.end||e.key===`Backspace`&&mr[t]===` `&&n.range.end===t));if(r){let t=mr[r.range.end]===` `?r.range.end+1:r.range.end,n=`${mr.slice(0,r.range.start)}${mr.slice(t)}`;e.preventDefault(),Or(n),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=r.range.start,Ar.current.selectionEnd=r.range.start),Zs()}),Qs(n,r.range.start);return}let i=t;for(;i>0&&!/\s/.test(mr[i-1]);)--i;let a=t+1;for(;a<mr.length&&!/\s/.test(mr[a]);)a+=1;let o=mr.slice(i,a),s=o.slice(1);if(DO.test(o)&&!Fi.current.has(s.toLowerCase())&&Eo({mention:s,confirmed:kr.has(s),terminated:a<mr.length&&/\s/.test(mr[a])})){let t=mr[a]===` `?a+1:a,n=`${mr.slice(0,i)}${mr.slice(t)}`;e.preventDefault(),Or(n),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=i,Ar.current.selectionEnd=i),Zs()}),Qs(n,i);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(w&&Yr.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Yr.current.handleKeyDown(e.key);return}if(b&&Kr.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Kr.current.handleKeyDown(e.key);return}if(Di&&e.key===`Escape`){e.preventDefault(),lr(!1);return}let n=li&&!li.includes(`shift`)?As(`shift+${li}`):``,r=n&&rs(e,n)?-1:+!!rs(e,li);if(r!==0&&!w&&!b){e.preventDefault(),e.stopPropagation(),pn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Ar.current?.focus({preventScroll:!0})});return}let i=w||b,a=Ar.current?.selectionStart===0&&Ar.current?.selectionEnd===0,o=Ar.current?.selectionStart===mr.length&&Ar.current?.selectionEnd===mr.length,s=!i&&(mr.length===0||a),c=!i&&(mr.length===0||o);if(m===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Ar.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),Or(t),requestAnimationFrame(()=>{let e=Ar.current;e&&(e.selectionStart=n,e.selectionEnd=r),Zs()}),Qs(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=mr.slice(n,r);t(`${mr.slice(0,n)}${a}${s}${o}${mr.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=mr.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${mr.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&ro.length>0){if(e.preventDefault(),me===-1)he(0),xr({text:ro[0],references:[]});else if(me<ro.length-1){let e=me+1;he(e),xr({text:ro[e],references:[]})}requestAnimationFrame(()=>{Ar.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&me>=0){if(e.preventDefault(),me===0)he(-1),Sr();else{let e=me-1;he(e),xr({text:ro[e],references:[]})}return}if(!(e.key===`Enter`&&Zn&&!e.ctrlKey&&!e.metaKey)&&e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),OC(Ao().message,m)===`btw`){ls();return}if(es()||zo())return;let t=e.ctrlKey||e.metaKey,n=m===`normal`&&ho&&vn&&To,r=n&&O_(Ia.mode)&&_u(K.deliveryTarget?.kind,Ia.mode),i=UE({followUpBehavior:Aa,ctrlEnter:t,canQueue:!!n,queueUsable:!!r,primary:K.kind===`primary`,sessionIsRunning:To});i.kind===`queue`?ns():i.steerAfterAdmit?ls({steerAfterAdmit:!0}):i.delivery?ls({delivery:i.delivery}):ls()}}),ks=J(()=>{if(!Di){va(null);return}if(!w&&!b){va(null);return}let e=Ar.current,t=Ir.current;if(!e||!t)return;let n=WO(e,e.selectionStart??mr.length);if(!n)return;let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=r.top-i.top+(n.top-e.scrollTop),o=r.left-i.left+(n.left-e.scrollLeft),s=a-8,c=i.height-a-8,l=c>=260||c>=s?`below`:`above`,u=b?520:w?450:360,d=Math.max(8,Math.min(o-24,i.width-u-8)),f=Math.max(120,Math.min(260,l===`below`?c:s));va({top:l===`below`?a+22:a-6,left:d,place:l,maxHeight:f})});Z.useLayoutEffect(()=>{ks()},[ks,mr,w,b,Di]),ir(`resize`,ks,()=>Di?window:null);let js=J(()=>{ya.current&&=(clearTimeout(ya.current),null),wi(!0),ya.current=setTimeout(()=>{wi(!1),ya.current=null},1800)}),Ms=Z.useRef(new Set),[Ps,Fs]=Z.useState(()=>new Set),Is=JSON.stringify([K.transportIdentity,K.runtimeGeneration,K.surfaceID,K.directory,vn]),Ls=ko&&Ps.has(Is),Rs=J(async()=>{if(Ms.current.has(Is))return;let e=Is;Ms.current.add(e),Fs(new Set(Ms.current)),hn.abortPrompt.clear(),js();let t;try{let e=K.kind===`secondary`?pn?.shortcut(`abort`):En();await Promise.race([e,new Promise(e=>{t=setTimeout(()=>{K.kind===`secondary`&&no.error(o(`chat.chatInput.stopUnconfirmed`)),e()},5e3)})])}catch(e){console.error(`[ChatInput] abort failed`,e)}finally{clearTimeout(t),Ms.current.delete(e),Fs(new Set(Ms.current))}}),zs=J((e=1)=>{if(qn)return;let t=Qr(Gn,K.selection.value.agent??Mn,e);if(!t||!K.selection.change)return;let n=Ui({providerID:K.selection.value.providerID??``,modelID:K.selection.value.modelID??``,agent:K.selection.value.agent??null},t,Gn,Kn);K.selection.change({...K.selection.value,...n,agent:n.agent??void 0}),K.kind===`primary`&&(q.getState().addRecentAgent(t),K.sessionID&&Oi.getState().saveSessionAgentSelection(K.sessionID,t))});ge.current=zs;let[Bs,Vs]=Z.useState(null),[Hs,Us]=Z.useState(!1),Ws=Z.useRef(null),Gs=Z.useRef(!0);Z.useLayoutEffect(()=>{Gs.current=!0},[$t]),Z.useLayoutEffect(()=>{let e=Ws.current;e&&(Hs||la)&&Gs.current&&(e.scrollLeft=e.scrollWidth)},[mr,Hs,la]);let Ks=J(e=>{Vs(t=>t===e?t:e)}),qs=Zn&&!$i&&!Ai&&mr.length>0,[Js,Ys]=Z.useState(!1),{size:Xs,resize:Zs}=KD({inputRef:Ar,message:mr,expanded:Ai,isMobile:Zn,dictationHeight:Bs,manualHeight:qs&&Js});Z.useLayoutEffect(()=>{if(!Zn||!Hs)return;let e=Ar.current;e&&(e.style.overflowY=`auto`,e.scrollTop=e.scrollHeight,Ti.current&&(Ti.current.style.transform=`translateY(-${e.scrollTop}px)`))},[Zn,Hs,mr]);let Qs=J((e,t,n=`manual`,r)=>{let i=Fc({text:e,cursor:t,inputMode:m,mentionInputSource:n,insertedText:r});if(Fr.current=i,!i){T(!1),x(!1);return}if(i.kind===`slash-command`){k(i.query),T(!0),x(!1);return}T(!1),C(i.query),x(!0)}),$s=J((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(m===`normal`&&!Nr.current&&Ki.size>0&&e.includes(`/`)){let r=Lc(e,Ki,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=vr(a,o,s,(e,t)=>{let n=[...e];for(let i of Do(t.text,{agentNames:Pi,includeUnterminatedPastedReferences:r===`paste`,confirmedValues:new Set(e.flatMap(e=>e.kind===`file`||e.kind===`directory`?[e.value]:[]))}))n=Qc(n,{kind:i.kind,value:i.value,path:i.value,label:i.value,range:{start:i.start,end:i.end}});return n}),l=ti(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return u&&requestAnimationFrame(()=>{let e=Ar.current;e&&cy(u,Nr.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end))}),Qs(l.text,c.end,r,i),{document:l,selection:c}}),ec=J((e,t=`manual`)=>{if(!e)return;let n=Ar.current;if(!n){let n=mr+e;$s(n,n.length,n.length,t,e);return}let r=n.selectionStart??mr.length,i=n.selectionEnd??mr.length,a=`${mr.substring(0,r)}${e}${mr.substring(i)}`,o=r+e.length;$s(a,o,o,t,e)}),tc=J((e,t)=>{let n=new Set(fn(_n.map(e=>e.filename),e,t));if(n.size!==0)for(let e of _n)n.has(e.filename)&&hn.removeAttachment(e.id)}),nc=J(e=>{hn.removeAttachment(e.id)}),rc=J(()=>{zr.current=!1,Ur.current=[],Br.current&&=(clearTimeout(Br.current),null)}),ic=J(()=>{Br.current&&clearTimeout(Br.current),Br.current=setTimeout(()=>{rc()},700)}),oc=J(()=>{Vr.current=!1,Hr.current&&=(clearTimeout(Hr.current),null)}),cc=J(()=>{Vr.current=!0,Hr.current&&clearTimeout(Hr.current),Hr.current=setTimeout(()=>{Vr.current=!1,Hr.current=null},700)}),uc=J(e=>{!E()||!zr.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),rc())}),fc=J(e=>{if(nr)return;let t=e.nativeEvent;if(E()&&zr.current){let n=Ur.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){rc();return}}let n=e.target.value;tc(Xr.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?jO(Xr.current,n):``,a=i.includes(`@`)||Vr.current;Vr.current&&oc();let o=a?`paste`:`manual`;if(m===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);h(`shell`),gr(e),Zs(),T(!1),x(!1),requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=t,Ar.current.selectionEnd=t)});return}$s(n,r,e.target.selectionEnd??r,o,i)});Z.useEffect(()=>()=>{rc(),oc()},[rc,oc]);let gc=J(e=>{let t=Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)));if(t.length===0)return;let n=t.map(e=>`@${e}`).join(` `),r=Ar.current,i=r?.selectionStart??mr.length,a=r?.selectionEnd??mr.length,o=Xc(n,mr.slice(0,i),mr.slice(a)),s=`${mr.slice(0,i)}${o}${mr.slice(a)}`;tc(mr,s),ni(s,t);let c=rl(s,i+o.length);Pr.current=c,x(!1),C(``),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(c,c),Zs(),Qs(s,c)})}),yc=J(async e=>{let t=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),n=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),r=t.length>0?t:(()=>{if(n.length<=1)return n;let e=n.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[n[0]]})(),i=zO(e.clipboardData);if(r.length===0&&i.length>0&&(vn||bn)){e.preventDefault(),gc(i);return}if(r.length===0&&m===`normal`&&(vn||bn)){let t=Ar.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=mr.slice(n,r);if(kO.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${mr.slice(0,n)}[${i}](${t})${mr.slice(r)}`,o=n+1+i.length+2+t.length+1;Or(a),requestAnimationFrame(()=>{let e=Ar.current;e&&(e.selectionStart=o,e.selectionEnd=o),Zs()}),Qs(a,o,MO(t),t);return}}}let a=e.clipboardData.getData(`text`),s=r.length>0&&i.includes(lC(a.trim().replace(/^(['"])(.*)\1$/,`$2`)))?``:a;if(r.length===0){if(m===`normal`&&OD(ti(),s)){e.preventDefault();let t=ti().text,n=Ar.current,r=n?.selectionStart??mr.length,i=n?.selectionEnd??mr.length,a=kD(s,mr,ti().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>o(`chat.chatInput.pastedTextReference`,{index:e,count:t}),DD(ti())),c=yr(r,i,{id:a.id,kind:`paste`,text:a.text,characterCount:a.characterCount,index:a.index,display:a.token},{inlineBoundaries:!0,padDocumentEdges:!0}),l=rl(c.document.text,c.caret);Ar.current&&(Ar.current.value=c.document.text),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(l,l),Zs()}),Qs(c.document.text,l),tc(t,c.document.text);return}s.includes(`@`)&&cc();return}if(!vn&&!bn){s.includes(`@`)&&cc();return}e.preventDefault();let c=mn(r,[..._n.map(e=>e.filename),...Zr.current]),l=kt(c),u=ti().text,d=Ar.current,f=d?.selectionStart??mr.length,p=d?.selectionEnd??mr.length,h=m===`normal`&&OD(ti(),s)?kD(s,mr,ti().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>o(`chat.chatInput.pastedTextReference`,{index:e,count:t}),DD(ti())):null,g=s?`${s}${/\s$/.test(s)?``:` `}${l}`:l,_=Xc(g,mr.slice(0,f),mr.slice(p));if(h){let e=yr(f,p,{id:h.id,kind:`paste`,text:h.text,characterCount:h.characterCount,index:h.index,display:h.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=rl(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${l}${e.document.text.slice(t)}`;$s(n,t+l.length,t+l.length,MO(n),l),tc(u,n)}else ec(_,MO(_)),tc(u,`${mr.slice(0,f)}${_}${mr.slice(p)}`);for(let e=0;e<r.length;e+=1){let t=c[e],n=AO(r[e],t);Zr.current.add(t);try{await hn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.clipboardAttachFailed`))}finally{Zr.current.delete(t)}}}),bc=J((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=Pc(r,i,[...qt(mr,_n.filter(_e).map(e=>e.filename)),..._c(mr,Hi.keys()),...ti().references]),o=a?.start??r,s=a?.end??i,c=mr.slice(o,s),l=Fe(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${mr.slice(0,o)}${mr.slice(s)}`;$s(e,o,o),requestAnimationFrame(()=>{Ar.current?.setSelectionRange(o,o),Zs()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Ar.current?.setSelectionRange(o,s)})}),xc=J(e=>{bc(e,`copy`)}),Tc=J(e=>{bc(e,`cut`)}),Ec=e=>{let t=Ar.current,n=t&&document.activeElement===t?t.selectionStart??Pr.current:Pr.current;return Sl(e,n)},Dc=()=>{Pl(Zn)||Ar.current?.focus()},Oc=J(e=>{let t=Ec(mr.length),n=Ic(mr,t,Fr.current),r=mr.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():$c(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=tl(mr,o,s,`@${i}`);ni(c.text,[i],a),Pr.current=c.caret,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=c.caret,Ar.current.selectionEnd=c.caret),Zs(),Qs(c.text,c.caret)}),x(!1),C(``),Dc()}),kc=J(e=>{let t=Ec(mr.length),n=Ic(mr,t,Fr.current),r=mr.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=tl(mr,i,a,`@${e}`);Or(o.text,t=>Qc(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Pr.current=o.caret,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=o.caret,Ar.current.selectionEnd=o.caret),Zs(),Qs(o.text,o.caret)}),x(!1),C(``),Dc()}),Ac=J(e=>{Jr.current||(Jr.current=!0,(async()=>{try{let t=Wa.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){no.error(o(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await Be(e.id,{directory:t}),!Pt(e.id,t)){no.error(o(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}!Zn&&!D()&&!vi()&&xi([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=ti(),r=Ec(n.text.length),i=Ic(n.text,r,Fr.current),a=n.text.substring(0,r).lastIndexOf(`@`),s=Ne().get(e.id)?.title||e.title||e.id,c=i?.start??(a===-1?r:a),l=i?.end??r,u={id:`session:${e.id}:${Jn()}`,kind:`session`,sessionId:e.id,display:Re({trigger:`@`,icon:`chat-thread`,label:s})},d=yr(c,l,u,{inlineBoundaries:!0,padDocumentEdges:!0}),f=rl(d.document.text,d.caret);Pr.current=f,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=f,Ar.current.selectionEnd=f),Zs(),Qs(d.document.text,f)}),x(!1),C(``),Dc()}catch{no.error(o(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Jr.current=!1}})())}),zc=J(e=>{let t=ti(),n=Ec(t.text.length),r=Ic(t.text,n,Fr.current)??Uc(t.text,n);if(!r)return!1;let i=yr(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=rl(i.document.text,i.caret);return Pr.current=o,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=o,Ar.current.selectionEnd=o),Zs(),Qs(i.document.text,o),a&&(T(!1),x(!1))}),Dc(),a}),Vc=J(e=>{let t=ti(),n=Ec(t.text.length),r=Ic(t.text,n,Fr.current);if(!r)return;let i=yr(r.start,r.end,{id:`skill:${e.name}:${Jn()}`,kind:`skill`,skillName:e.name,display:Re({trigger:`@`,icon:`book-open`,label:e.name})},{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=rl(i.document.text,i.caret);Pr.current=a,requestAnimationFrame(()=>{Ar.current&&(Ar.current.selectionStart=a,Ar.current.selectionEnd=a),Zs(),Qs(i.document.text,a),x(!1),C(``)}),Dc()}),Gc=J((e,t=!1)=>{if(!py(K,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){zc({id:`skill:${e.name}:${Jn()}`,kind:`skill`,skillName:e.name,display:Re({trigger:`@`,icon:`book-open`,label:e.name})})&&k(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&zc({id:`command:${e.name}:${Jn()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:Re({trigger:`/`,icon:`command`,label:e.name})})){k(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=Lc(r,new Set([...Ki,e.name.toLowerCase()]),r.length);if(e.name===`btw`){let e=ti(),t=Uc(e.text,Ar.current?.selectionStart??e.text.length);if(t){let n=i?.text??r;Or(e.text.slice(0,t.start)+n+e.text.slice(t.end))}}else gr(i?.text??r);let a=Ar.current;if(a&&(a._commandMetadata=e),T(!1),k(``),t){ls({presetText:n});return}let o=()=>{if(!Pl(Zn)&&Ar.current){try{Ar.current.focus({preventScroll:!0})}catch{Ar.current.focus()}Ar.current.setSelectionRange(Ar.current.value.length,Ar.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)});Z.useEffect(()=>{vn&&Ar.current&&!Zn&&Ar.current.focus()},[vn,Zn]),Z.useEffect(()=>{Zn||F(null)},[Zn]);let qc=hn.abortPrompt.sessionID,Zc=hn.abortPrompt.clear;Z.useEffect(()=>{qc&&qc!==vn&&Zc()},[vn,qc,Zc]),Z.useEffect(()=>{Wr.current=!!(vn||bn)},[vn,bn]);let $c=J(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(pi||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t}),el=J(e=>{if(!GO(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Lr.current++;let t=e.dataTransfer.types?.includes(`application/x-yuri-file-path`)??!1;t!==v&&y(t),(vn||bn)&&!g&&_(!0)}),nl=J(e=>{GO(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(vn||bn)&&!g&&_(!0))}),il=J(e=>{e.preventDefault(),e.stopPropagation(),Lr.current--,Lr.current<=0&&(Lr.current=0,_(!1),y(!1),rc())}),ll=J(()=>{Lr.current=0,_(!1),y(!1),rc()}),ul=J(async e=>{if(Lr.current=0,!GO(e.dataTransfer)){rc();return}if(e.preventDefault(),e.stopPropagation(),_(!1),!vn&&!bn)return;let t=e.dataTransfer.getData(`application/x-yuri-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Ar.current,r=Xr.current;if(n){let t=n.selectionStart??Pr.current,i=n.selectionEnd??t,a=tl(r,t,i,e);Or(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Pr.current=a.caret,n.focus()})}else{let t=tl(r,r.length,r.length,e);Or(t.text)}rc();return}let n=zO(e.dataTransfer);if(n.length>0){E()&&(Ur.current=n),gc(n),E()||rc();return}let r=KO(e.dataTransfer);if(r.length>0){let e=kt(r.map(e=>e.name)),t=Xc(e,Xr.current.slice(0,Ar.current?.selectionStart??Xr.current.length),Xr.current.slice(Ar.current?.selectionEnd??Xr.current.length));ec(t);for(let e of r)try{await hn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.attachFileFailed`))}}rc()}),dl=J(e=>{GO(e.dataTransfer)&&(e.preventDefault(),E()&&(zr.current=!0,ic()))}),gl=Z.useRef(null),_l=Z.useRef(null),vl=J((e=!0)=>{ue.current=0;let t=()=>{let t=oy(Ar);if(!t||(sy(Ar),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),bl=J(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=kt(t.map(e=>e.name)),n=Xc(e,Xr.current.slice(0,Ar.current?.selectionStart??Xr.current.length),Xr.current.slice(Ar.current?.selectionEnd??Xr.current.length));ec(n)}for(let e of t)try{await hn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.attachFileFailed`))}}),xl=J(async()=>{try{let e=await ai?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6557
|
+
`);no.error(o(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(vl(!1),await bl(r),vl())}catch(e){console.error(`VS Code file pick failed`,e),no.error(e instanceof Error?e.message:o(`chat.chatInput.toast.vscodePickFailed`))}}),Cl=J(()=>{if(E()){xl();return}gl.current?.click()}),wl=J(()=>{if(E()){xl();return}_l.current?.click()}),Tl=J(async()=>{if(!wc()){wl();return}try{let e=await pc(20);if(e===null){wl();return}e.length>0&&(vl(!1),await bl(e),vl())}catch(e){console.error(`Native photo pick failed`,e),no.error(o(`chat.chatInput.toast.attachFileFailed`))}}),Dl=J(async e=>{let t=e.target.files;!t||t.length===0||(vl(!1),await bl(t),e.target.value=``,vl())}),Ol=`gap-x-1.5 gap-y-0`,jl=E(),Ml=K.kind===`primary`&&xn&&!jl&&!dt,Nl=Z.useMemo(()=>(at?.selectedProjectId?Dn.find(e=>e.id===at.selectedProjectId)??null:null)||(On?Dn.find(e=>e.id===On)??null:null)||(Dn[0]??null),[On,at?.selectedProjectId,Dn]),Fl=Z.useMemo(()=>BO(Nl?.path??null),[Nl?.path]),Il=Nl?VO(Nl):null,Ll=Yc(Fl),Rl=sl(e=>Fl?e.directories.get(Fl)?.lastBranchesFetch??0:0),zl=Kc(Fl),Bl=!!Ll?.all,Vl=sl(e=>e.fetchBranches),[Hl,Ul]=Z.useState(!1);Z.useEffect(()=>{!Ml||!Fl||!ii||zl!==null||yi(Fl,ii,{silent:!0})},[yi,ii,zl,Fl,Ml]),Z.useEffect(()=>{if(!Ml||!Fl||!Nl||!ii||zl!==!0){Ul(!1);return}let e=!Rl||Date.now()-Rl>3e4;if(Bl&&!e){Ul(!1);return}let t=!1;return Ul(!Bl),Vl(Fl,ii).finally(()=>{t||Ul(!1)}),()=>{t=!0}},[Vl,ii,Nl,Rl,Bl,zl,Fl,Ml]);let Wl=Jc(Fl),Kl=Ll?.current?.trim()||Wl?.trim()||``,ql=Z.useMemo(()=>{if(!Nl)return null;let e=BO(Nl.path);return!e||!Kl?null:{value:e,label:Kl}},[Nl,Kl]),Zl=Z.useMemo(()=>{if(!Nl)return[];let e=Fl?bt.get(Fl)??bt.get(Nl.path)??[]:[];return Ji({projectRoot:BO(Nl.path)??``,rootBranch:Kl,worktrees:e,pendingBootstrapDirectory:at?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[bt,at?.bootstrapPendingDirectory,Nl,Kl,Fl]),Ql=Z.useMemo(()=>BO(at?.bootstrapPendingDirectory??null)??BO(at?.directoryOverride??null)??Fl,[at?.bootstrapPendingDirectory,at?.directoryOverride,Fl]),$l=Z.useMemo(()=>{let e=BO(at?.bootstrapPendingDirectory??null);return!!(at?.preserveDirectoryOverride||at?.pendingWorktreeRequestId||e&&e===Ql)},[at?.bootstrapPendingDirectory,at?.pendingWorktreeRequestId,at?.preserveDirectoryOverride,Ql]),eu=Z.useMemo(()=>{let e=[];return ql&&e.push(ql),e.push(...Zl),!Ql||e.some(e=>e.value===Ql)||!$l?e:[...e,{value:Ql,label:Wi(Ql)}]},[ql,Ql,$l,Zl]),tu=Z.useMemo(()=>VS({selectedDirectory:Ql,projectRootOption:ql,worktreeOptions:Zl}),[ql,Ql,Zl]),nu=mx()===`mini-chat`,ru=Z.useMemo(()=>nu||mi!==!0||!gi||gi.isClean?!1:Qy(gi.files),[gi,mi,nu]),su=Z.useMemo(()=>!Ql||ql?.value===Ql||Zl.some(e=>e.value===Ql),[ql?.value,Ql,Zl]);Z.useEffect(()=>{at?.open&&(!at.preserveDirectoryOverride&&!at.bootstrapPendingDirectory||!Ql||!su||(at.preserveDirectoryOverride&&Wa.getState().setDraftPreserveDirectoryOverride(!1),at.bootstrapPendingDirectory&&Wa.getState().setDraftBootstrapPendingDirectory(null)))},[at?.bootstrapPendingDirectory,at?.open,at?.preserveDirectoryOverride,su,Ql]);let uu=Z.useMemo(()=>zl!==!0||Hl?!1:ql?!0:Zl.length>0,[Hl,ql,zl,Zl.length]),du=J(e=>{if(Wa.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=Dn.find(t=>t.id===e);t&&(On!==e&&kn(e),yt({projectId:e,directoryOverride:t.path},{force:!0}))}),mu=J(e=>{Wa.getState().newSessionDraft?.pendingWorktreeRequestId||Nl&&yt({projectId:Nl.id,directoryOverride:e},{force:!0})});Z.useEffect(()=>{!Ml||!Nl||!Ql||at?.pendingWorktreeRequestId||at?.bootstrapPendingDirectory||at?.preserveDirectoryOverride||eu.some(e=>e.value===Ql)||yt({projectId:Nl.id,directoryOverride:Nl.path})},[eu,at?.bootstrapPendingDirectory,at?.pendingWorktreeRequestId,at?.preserveDirectoryOverride,Ql,Nl,yt,Ml]);let hu=J(()=>{de(),H(!0),Ar.current?.blur()}),gu=J(()=>{de(),W(!0),Ar.current?.blur()});Z.useEffect(()=>{if(!Zn||typeof document>`u`)return;let e=document.getElementById(`mobile-overlay-root`);e||(e=document.createElement(`div`),e.id=`mobile-overlay-root`,document.body.appendChild(e));let t=e,n=()=>le(Mx(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[jx]}),()=>r.disconnect()},[Zn]);let vu=ce||!!P||V||U||xa||Ca,yu=J(e=>{j(t=>Hc(t,e.rows)),N(t=>t===e.highlightedIndex?t:e.highlightedIndex)}),Su=J(e=>(e.name!==`btw`||K.kind===`primary`)&&py(K,e)),Cu=J(e=>{if(w){Yr.current?.acceptIndex(e,!0);return}b&&Kr.current?.acceptIndex(e)}),wu=J(()=>{Fr.current=null,T(!1),x(!1),j([]),N(0)}),Ou=$i,ku=Ou?Z.createElement(Lm,{enabled:$i,isMobile:Zn,text:mr,textPresetEpoch:dr.textPresetEpoch,placeholder:Mi,modelLabel:qa(Kn.find(e=>e.id===K.selection.value.providerID),K.selection.value.modelID,o(`chat.modelControls.selectModel`)),modelVariantLabel:K.selection.value.variant?.trim()?Ii(K.selection.value.variant):``,canSend:Co,canAbort:ko,attachmentCount:_n.length,suppressed:vu,attachAria:o(`chat.chatInput.actions.addAttachment`),attachTitle:o(`chat.chatInput.actions.addAttachment`),attachPhotosLabel:o(`chat.chatInput.actions.attachPhotos`),attachFilesLabel:o(`chat.chatInput.actions.attachFiles`),attachCancelLabel:o(`chat.chatInput.actions.attachCancel`),sendAria:o(`chat.chatInput.actions.sendMessageAria`),queueAria:o(`chat.chatInput.actions.queueMessageAria`),stopAria:o(`chat.chatInput.actions.stopGeneratingAria`),modelAria:o(`chat.modelControls.selectModel`),modelId:K.selection.value.modelID,providerId:K.selection.value.providerID,agentName:K.selection.value.agent??``,agentLabel:Rr(Gn,K.selection.value.agent??void 0),agentAria:o(`chat.modelControls.selectAgent`),attachments:_n,removeAttachmentNamedAria:e=>o(`chat.fileAttachment.actions.removeNamed`,{name:e}),onText:(e,t,n)=>{let r=Sl(e.length,n?.end??n?.start??e.length);if(Pr.current=r,t){Ar.current&&(Ar.current.value=e),Or(e);return}let i=Xr.current,a=Ee(i,e,_n.filter(_e).map(e=>e.filename)),o=a?.text??e;Ar.current&&(Ar.current.value=o),Or(o);let s=Sl(o.length,n?.end??n?.start??o.length);if(Pr.current=s,Qs(o,s),!a)return;let c=new Set(a.removedFilenames.map(e=>e.toLowerCase()));for(let e of _n)c.has(e.filename.toLowerCase())&&hn.removeAttachment(e.id)},onSend:e=>{Ar.current&&(Ar.current.value=e),kl({text:e,applyDocument:Or,submit:us})},onAbort:Rs,onAttach:de,onFiles:(e,t)=>{t.length>0&&no.error(o(`chat.chatInput.toast.someFilesSkipped`,{summary:t.join(`
|
|
6558
|
+
`)})),e.length!==0&&bl(e)},onRemoveAttachment:e=>{hn.removeAttachment(e)},onOpenModel:()=>oo(`model`),onCycleAgent:()=>zs(),onOpenAgent:os,showScrollToBottom:!!(n&&r),scrollAria:o(`chat.scrollToBottom.aria`),onScrollToBottom:r??(()=>{}),autocompleteOpen:A.length>0&&(w||b),autocompleteHighlightedIndex:M,autocompleteRows:A,autocompleteQuery:b?S:O,caret:Pr.current,onAutocompleteAccept:Cu,onAutocompleteDismiss:wu,chipHighlights:ga}):null,Au=Z.useRef(null);sr(Ou?Au:null,()=>{let e=Au.current?.getBoundingClientRect().height??0;El(document.documentElement,e)});let ju=Z.useRef(!1);ju.current=xa||Ca;let Mu=Z.useRef(!1),Pu=Z.useRef(0),Fu=Z.useRef(0),Iu=J(()=>{let e=Wa.getState().stagedMessageEdit;!e||e.sessionId!==vn||window.setTimeout(()=>{let t=Wa.getState().stagedMessageEdit,n=document.activeElement,r=RE({surfaceKind:K.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:zo(),focusHeld:Date.now()<Fu.current,overlayOpen:Pu.current>0||ju.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<ue.current});r.action===`disarm`&&Wa.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Zn||D()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Pu.current+=1},t=()=>{if(Pu.current=Math.max(0,Pu.current-1),Mu.current){Mu.current=!1;return}if(!pe.current||ju.current||Pu.current>0)return;if(ac()){pe.current=!1;return}pe.current=!1,Fu.current=Date.now()+600,Ar.current?.focus(),document.activeElement===Ar.current&&z(!0);let e=()=>{let e=Ar.current;!e||document.activeElement!==e||(Lu.current??e).scrollIntoView({block:`end`})};I.current!==null&&(window.clearTimeout(I.current),I.current=null),L.current!==null&&(window.clearTimeout(L.current),L.current=null),I.current=window.setTimeout(()=>{I.current=null,e()},300),L.current=window.setTimeout(()=>{L.current=null,e()},650)};return window.addEventListener(`yuri:mobile-overlay-opened`,e),window.addEventListener(`yuri:mobile-overlay-closed`,t),()=>{I.current!==null&&(window.clearTimeout(I.current),I.current=null),L.current!==null&&(window.clearTimeout(L.current),L.current=null),window.removeEventListener(`yuri:mobile-overlay-opened`,e),window.removeEventListener(`yuri:mobile-overlay-closed`,t)}},[Zn]),Z.useEffect(()=>{if(!Zn)return;if(vu){(R||Date.now()-fe.current<800)&&(pe.current=!0);return}if(!pe.current)return;let e=window.setTimeout(()=>{if(pe.current=!1,ac())return;let e=Ar.current;e&&document.activeElement!==e&&e.focus({preventScroll:D()})},180);return()=>window.clearTimeout(e)},[Zn,vu,R]),Z.useEffect(()=>{if(!Zn||D()||typeof document>`u`||R||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Ar.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[Zn,R]),Z.useEffect(()=>{re(``)},[ee]);let Lu=Z.useRef(null),Ru=!Zn&&K.kind===`primary`&&!!vn&&!Ai;Z.useLayoutEffect(()=>{if(!Ru)return;let e=Lu.current;if(!e)return;let t=e.offsetHeight;if(!(t<=0))return e.style.height=`${t}px`,()=>{e.style.height=``}},[vn,Ru]);let zu=Zn&&K.kind===`primary`&&!Ou,Bu=Z.useRef(null),Vu=Z.useRef(null),Hu=J(()=>{if(!zu)return;let e=Lu.current;if(!e?.closest(`.yuri-mobile-composer-foot--overlay`))return;let t=Au.current?.offsetHeight??0;if(Vu.current===null){if(e.offsetHeight<=0)return;Vu.current=Math.max(0,e.offsetHeight-t)}let n=gO(document.documentElement,Vu.current+t);n!==null&&(Bu.current=n)});sr(zu?Au:null,Hu),Z.useEffect(()=>{if(zu)return()=>{_O(document.documentElement,Bu.current),Bu.current=null,Vu.current=null}},[zu]);let Uu=Zn?`px-1.5 py-1.5`:jl?`px-1.5 py-1`:`px-2.5 py-1.5`,Wu=Zn?`h-8 w-8`:jl?`h-5 w-5`:`h-6 w-6`,Gu=Zn?`h-4 w-4`:jl?`h-3.5 w-3.5`:`h-4 w-4`,Ku=Zn?`h-6 w-6`:`size-full`,qu=Zn?`h-[1.125rem] w-[1.125rem]`:jl?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,Ju=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,Gv),Yu=Y(Ju,Wu),Xu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,Wu),Zu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,`h-6 w-6`);Z.useEffect(()=>()=>{ya.current&&=(clearTimeout(ya.current),null)},[]);let Qu=(0,$.jsx)(Oh,{quotes:po,removeLabel:o(`chat.btw.removeQuoteAria`),onRemove:e=>{fo&&Wg.getState().removeQuote(fo,e)}}),$u=J(()=>{de(),zs()}),ed=J(()=>oo(`model`)),td=Z.useMemo(()=>Zn?Kn.find(e=>e.id===K.selection.value.providerID):void 0,[Zn,Kn,K.selection.value.providerID]),nd=Zn?(0,$.jsxs)(`div`,{"data-composer-action":`true`,className:`composer-mobile-model-controls flex min-w-0 flex-1 items-center justify-end gap-x-1.5`,children:[(0,$.jsx)(QO,{onOpenAgentPanel:os,onCycleAgent:$u,agentName:K.selection.value.agent,agents:Gn,disabled:Yn}),(0,$.jsx)($O,{onOpenModel:ed,providerID:K.selection.value.providerID,modelID:K.selection.value.modelID,provider:td,variant:K.selection.value.variant})]}):null,rd=(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(qh,{attachments:_n,onShowPopup:er,onRemoveAttachedFile:nc}),K.kind===`primary`?(0,$.jsx)(Zh,{attachedFiles:_n,onAddVSCodeFile:(e,t,n)=>{Cn&&Pa(Cn,()=>fi.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Cn)return Pa(Cn,()=>fi.getState()).addVSCodeSelection(e,t)}}):null]}),id=ga?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Cc,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),ad=!Zn&&fa?(0,$.jsxs)($.Fragment,{children:[id??mr,(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`yuri-dictation-caret`,children:ma?.draftID===$t&&ma.text===mr&&(0,$.jsx)(`span`,{className:`yuri-dictation-caret-trail`},mr)})]}):id,od=Zn&&na?(0,$.jsx)($r,{variant:`ghost`,size:`icon`,className:Yu,"data-composer-action":`true`,"aria-label":o(la?`settings.voice.volcengine.finishRecording`:`chat.dictation.start`),"aria-pressed":la,disabled:!la&&(yn||Hs||ra!==null||!vn&&!bn),onClick:()=>window.dispatchEvent(new Event(`yuri:mobile-dictation-toggle`)),children:(0,$.jsx)(qm,{kind:`mic`,active:la,className:qu})}):null,sd=Zn?(0,$.jsxs)(`div`,{className:Y(`yuri-mobile-composer-compact-chrome`,ko&&`yuri-mobile-composer-compact-chrome--aborting`,Co&&!ko&&`yuri-mobile-composer-compact-chrome--sending`,n&&r&&`yuri-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(rk,{isVSCode:jl,footerIconButtonClass:Yu,iconSizeClass:qu,handlePickLocalFiles:Cl,handlePickLocalImages:wl,openIssuePicker:ss,openPrPicker:cs,onOpenMobileSheet:hu,onOpenAndroidPickSheet:Qn?gu:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`composer-mobile-actions ml-auto flex shrink-0 items-center justify-end gap-x-3`,children:[n&&r?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(fx,{placement:`compact`,visible:n,onClick:r})}):null,od,ko||Co||Ls?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(ak,{isMobile:!0,compact:!0,footerIconButtonClass:Yu,stopFooterIconButtonClass:Xu,compactCircleButtonClass:Zu,sendIconSizeClass:Gu,stopIconSizeClass:Ku,canSend:Co,canAbort:ko,abortPending:Ls,hasContent:!!ho,currentSessionId:vn,newSessionDraftOpen:bn,draftSubmitting:yn,submissionBlocked:i,sendPhase:Fo,queueFrozen:xo,queueFallbackAvailable:ko||To,onPrimaryAction:us,onAbort:Rs})}):null]})]}):null,cd=Zn?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-full-chrome flex w-full min-w-0 items-center gap-x-1.5`,"data-composer-action":`true`,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(rk,{isVSCode:jl,footerIconButtonClass:Yu,iconSizeClass:qu,handlePickLocalFiles:Cl,handlePickLocalImages:wl,openIssuePicker:ss,openPrPicker:cs,onOpenSettings:e,onOpenMobileSheet:hu,onOpenAndroidPickSheet:Qn?gu:void 0}),Pn?(0,$.jsx)(ik,{sessionId:vn,draftOpen:bn,draftEnabled:at.permissionAutoAcceptEnabled===!0,enabled:An,saving:vn?mt:!1,footerIconButtonClass:Yu,iconSizeClass:qu,onSetDraftEnabled:ft,onSetSessionEnabled:gt,onOpenSessionFirst:Ya,onToggleFailed:In}):null,(0,$.jsx)(xC,{sessionId:vn,directory:Ve??Sn,draftOpen:bn}),(0,$.jsx)(SC,{length:mr.length}),na&&(0,$.jsx)(ZO,{interactionMode:`mobile`,disabled:yn||ra!==null||!vn&&!bn,onRecordingChange:ua,onActiveChange:Us,className:Yu,iconClassName:qu,onStart:ms,onPartial:hs,onInsert:gs,onCancel:_s},$t)]}),nd,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(ak,{isMobile:Zn,footerIconButtonClass:Yu,stopFooterIconButtonClass:Xu,sendIconSizeClass:Gu,stopIconSizeClass:Ku,canSend:Co,canAbort:ko,abortPending:Ls,hasContent:!!ho,currentSessionId:vn,newSessionDraftOpen:bn,draftSubmitting:yn,submissionBlocked:i,sendPhase:Fo,queueFrozen:xo,queueFallbackAvailable:ko||To,onPrimaryAction:us,onAbort:Rs})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,Ol,fa&&`[&>*:not([data-dictation-control])]:opacity-40`),children:[(0,$.jsx)(rk,{isVSCode:jl,footerIconButtonClass:Yu,iconSizeClass:qu,handlePickLocalFiles:Cl,handlePickLocalImages:wl,openIssuePicker:ss,openPrPicker:cs,onOpenSettings:e,withTooltip:!0}),Pn?(0,$.jsx)(ik,{sessionId:vn,draftOpen:bn,draftEnabled:at.permissionAutoAcceptEnabled===!0,enabled:An,saving:vn?mt:!1,footerIconButtonClass:Yu,iconSizeClass:qu,onSetDraftEnabled:ft,onSetSessionEnabled:gt,onOpenSessionFirst:Ya,onToggleFailed:In}):null,(0,$.jsx)(xC,{sessionId:vn,directory:Ve??Sn,draftOpen:bn}),(0,$.jsx)(SC,{length:mr.length}),ea&&!E()&&Gl()&&(0,$.jsx)(ZO,{inputRef:Ar,onActiveChange:pa,onRecordingChange:ua,className:Yu,iconClassName:qu,onStart:ms,onPartial:hs,onInsert:gs,onCancel:_s},$t)]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,Ol,fa&&`opacity-40`),children:[(0,$.jsx)(JO,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Ar,selectionAdapter:Hn}),(0,$.jsx)(ak,{isMobile:Zn,footerIconButtonClass:Yu,stopFooterIconButtonClass:Xu,sendIconSizeClass:Gu,stopIconSizeClass:Ku,canSend:Co,canAbort:ko,abortPending:Ls,hasContent:!!ho,currentSessionId:vn,newSessionDraftOpen:bn,draftSubmitting:yn,submissionBlocked:i,sendPhase:Fo,queueFrozen:xo,queueFallbackAvailable:ko||To,onPrimaryAction:us,onAbort:Rs})]})]}),ud=J(()=>{if(Zn){Fu.current=Date.now()+600;let e=()=>{Ar.current?.focus({preventScroll:D()}),document.activeElement===Ar.current&&z(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!sy(Ar))return;let e=oy(Ar);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),dd=Ve??Sn,fd=K.kind===`secondary`?K.directory:Ve,{goal:pd,enabled:md}=dC(vn??``,dd),hd=(0,$.jsx)(fv,{onEditMessage:is,onSendMessage:as,onEditCommitted:ud,draftKey:Cn,scope:ja,draftTarget:Cn?{key:Cn,expectedRevision:()=>hn.getDraft(Cn)?.revision??`absent`}:null,clientPendingItems:Xo,compactionBarrier:Zo,steeringMessageIDs:Ko,onSteerClientPending:e=>{if(!vn||!Wt({sessionID:vn}))return;let t=Ve??Sn??``,n=vn;return qo(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n}),St({sessionID:n,inboxID:e,directory:t}).catch(()=>{qo(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),no.error(o(`chat.chatInput.toast.messageSendFailed`))})},onQueueClientPending:e=>{vn&&_t({sessionID:vn,inboxID:e,directory:Ve??Sn??``}).then(()=>{Yt(vn,e,`queue`)}).catch(()=>{no.error(o(`chat.chatInput.toast.messageSendFailed`))})},onRemoveClientPending:e=>{let t=Da.getState().removeEstablishingFollowUp(e);if(!t){vn&&He({sessionID:vn,inboxID:e,directory:Ve??Sn??``}).catch(()=>{no.error(o(`chat.chatInput.toast.messageSendFailed`))});return}t.content&&gr(t.content),t.attachments.length>0&&hn.restoreAttachments(t.attachments)},trailing:vn&&md&&pd?(0,$.jsx)(yC,{sessionId:vn,directory:dd}):null});return(0,$.jsxs)($.Fragment,{children:[ku,K.kind===`primary`&&vn?(0,$.jsx)(DE,{scope:{sessionId:vn,directory:Sn},active:K.active,mobile:Zn}):null,(0,$.jsxs)(`form`,{ref:Lu,onSubmit:e=>{e.preventDefault(),us()},onPointerDownCapture:e=>{Zn&&ay(e,de)},className:Y(`relative w-full pt-0 pb-4`,Ru&&`flex flex-col justify-end [&>.chat-input-column]:shrink-0`,Di&&`flex h-full min-h-0 flex-col pt-4`,ki&&`flex h-full min-h-0 flex-col pt-1`,Zn&&`bottom-safe-area yuri-mobile-composer`),"data-native-ios-composer":Ou?`true`:void 0,"data-hold-to-talk":na?`true`:void 0,"data-hold-to-talk-empty":na&&mr.length===0?`true`:void 0,"data-dictation-hint":na?ra??void 0:void 0,style:Zn&&D()&&!Ou&&rr>0&&!R?{marginBottom:`${rr}px`}:void 0,children:[xn&&!Di&&!Zn&&!jl&&!nu?(0,$.jsx)(`div`,{className:`chat-input-column mb-7 text-center`,children:(0,$.jsx)(`h1`,{className:`text-balance text-2xl font-normal tracking-tight text-foreground md:text-3xl`,children:HO(Il?o(`chat.emptyState.draftTitleWithProject`,{project:Il}):o(`chat.emptyState.draftTitle`),Il)})}):null,na&&(0,$.jsx)(hc,{containerRef:Lu,disabled:!vn&&!bn||yn||Hs,onInsert:Ss,onSend:Cs,onRelease:bs,onError:ws,onHintChange:ia},Cn?nt(Cn):vn??`new`),(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Ai&&`flex flex-1 min-h-0 flex-col`),children:[Ou?null:(0,$.jsx)(Jh,{attachments:_n,onShowPopup:er,onRemoveAttachedFile:nc}),Xa&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[$a>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:di?.colors?.surface?.elevated,borderColor:di?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:o(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:di?.colors?.status?.info},children:$a}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:to,"aria-label":o(`chat.chatInput.reviewCommentsRemove`),title:o(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Za>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:di?.colors?.surface?.elevated,borderColor:di?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:o(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:di?.colors?.status?.info},children:Za}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>eo(`preview-console`),"aria-label":o(`chat.chatInput.devServerLogsRemove`),title:o(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Qa>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:di?.colors?.surface?.elevated,borderColor:di?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:o(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:di?.colors?.status?.info},children:Qa}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>eo(`preview-annotation`),"aria-label":o(`chat.chatInput.previewContextRemove`),title:o(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),Ta&&!jl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Sa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Ta.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Ta.author.avatarUrl,alt:Ta.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,Ta.number,Ta.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:o(`chat.chatInput.linked.byAuthor`,{author:Ta.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Ta.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Ta.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Ea(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.issue.removeAria`),title:o(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),Oa&&!jl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>wa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Oa.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Oa.author.avatarUrl,alt:Oa.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[o(`chat.chatInput.linked.pr.number`,{number:Oa.number}),Oa.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:o(`chat.chatInput.linked.byAuthor`,{author:Oa.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Oa.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[Oa.head,` → `,Oa.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Oa.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{ka(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":o(`chat.chatInput.linked.pr.removeAria`),title:o(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(tk,{sessionId:vn,directory:Ve??Sn}),(0,$.jsxs)(`div`,{className:Zn?`relative yuri-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:Zn?`yuri-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:Zn?`yuri-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:Au,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(ek,{className:Zn?`mb-0`:void 0,showAbortStatus:bi,showAbortPrompt:!!(Di&&vn&&xt===vn&&typeof Ct==`number`&&Ct>Date.now()),showAssistantStatus:!1,showTodos:!0,insideInputColumn:!0,showPendingChanges:!bn&&ru}),!Zn&&Ml?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Nl?(0,$.jsxs)(hl,{value:Nl.id,open:oe,onValueChange:du,onOpenChange:e=>{se(e),e||ae(``)},children:[(0,$.jsx)(ml,{asChild:!0,size:`sm`,children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex h-6 min-w-0 w-fit max-w-[42vw] items-center rounded-lg !border-0 px-1.5 py-1 pr-1.5 typography-micro font-medium text-foreground/80 transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5 sm:max-w-[18rem]`,Uv),children:[(0,$.jsx)(cl,{children:qO(Nl)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`})]})}),(0,$.jsxs)(fl,{fitContent:!0,children:[(0,$.jsx)($o,{autoFocus:!0,value:ie,onChange:e=>ae(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:o(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),(0,$.jsx)(nk,{projects:Dn,query:ie,renderLabel:qO}),(0,$.jsx)(pl,{}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left typography-ui-label text-foreground hover:bg-interactive-hover`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),se(!1),requestAnimationFrame(()=>sa.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,Uv),onClick:()=>sa.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]}),Nl&&uu?(0,$.jsx)(JS,{directory:Ql,projectDirectory:Fl,label:tu,projectRootOption:ql,worktreeOptions:Zl,onSelectDirectory:mu}):null]}):null,Zn&&Ml?(0,$.jsxs)(`div`,{className:`yuri-mobile-draft-target-selectors mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Nl?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] shrink items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,Uv),onClick:()=>te(`project`),children:qO(Nl)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,Uv),onClick:()=>sa.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]}),Nl&&uu?(0,$.jsx)(JS,{directory:Ql,projectDirectory:Fl,label:tu,projectRootOption:ql,worktreeOptions:Zl,onSelectDirectory:mu,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,K.active&&vn&&fd?(0,$.jsx)(kv,{sessionId:vn,directory:fd}):null,hd]})}),(0,$.jsx)(`div`,{className:Y(!Zn&&`contents`,Zn&&`contents`,ki&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:Zn?`yuri-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(Nc,{value:mr,attachments:[],disabled:!vn&&!bn||yn&&!Fo.establishing,pending:ko||Fo.inFlight&&!Fo.establishing,isMobile:Zn,onSubmit:us,"data-mobile-composer-surface":Zn?`true`:void 0,expanded:Ai,className:Y(`relative z-10`,fa&&`!ring-0 [&_textarea]:caret-transparent`,g&&`ring-2 ring-primary ring-offset-2`,nr&&`ring-1 ring-[var(--interactive-selection)]`,Zn&&`yuri-mobile-composer-surface`),style:{borderRadius:ji,...fa?{borderColor:`var(--voice-active-fill)`}:{}},ref:Ir,onDropCapture:dl,onDragEnter:el,onDragOver:nl,onDragLeave:il,onDrop:ul,onDragEnd:ll,autoResize:!1,disableInputWhilePending:!1,contentClassName:Ai?`flex-1 min-h-0`:void 0,inputHeader:Qu,attachmentContent:rd,highlightedContent:ad,highlightRef:Ti,inputRef:Ar,textLayoutClassName:Y(SO,Ai?Y(`h-full min-h-0`,Zn?`py-2.5`:`py-4`):Zn?`py-2.5`:`pt-4 pb-2`,m===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Ai&&`flex-1 min-h-0`),inputStyle:{flex:Ai?`1 1 auto`:`none`,height:!Ai&&Xs?`${Xs.height}px`:void 0,maxHeight:!Ai&&Xs?`${Xs.maxHeight}px`:void 0,"--yuri-composer-textarea-resting-height":Ai?`100%`:Xs?`${Xs.height}px`:`auto`,"--yuri-composer-textarea-resting-max-height":!Ai&&Xs?`${Xs.maxHeight}px`:`none`,borderTopLeftRadius:ji,borderTopRightRadius:ji},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,Uu,Zn?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,Ol)),footerStyle:{borderBottomLeftRadius:ji,borderBottomRightRadius:ji},footerContent:cd,placeholder:na?ca:!Zn&&fa?o(`chat.dictation.recordingPlaceholder`):!Zn&&ea&&!E()&&Gl()?`${Mi}${s.startsWith(`zh`)?`,`:s===`ja`?`、`:`, `}${o(`chat.dictation.holdHere`)}`:Mi,onChange:(e,t)=>fc(t),textareaProps:{readOnly:nr,onCompositionStart:()=>{Nr.current=!0},onCompositionEnd:e=>{Nr.current=!1;let t=e.currentTarget;$s(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:uc,onKeyDown:Os,onCopy:xc,onCut:Tc,onPaste:yc,onDragEnter:el,onDragOver:nl,onDropCapture:dl,onDrop:ul,onDragEnd:ll,onKeyUp:ks,onClick:()=>{ks()},onScroll:e=>{ks();let t=e.currentTarget.scrollTop;Ti.current&&(Ti.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Nr.current){Pr.current=r;return}let i=Pc(n,r,[...qt(mr,_n.filter(_e).map(e=>e.filename)),..._c(mr,Hi.keys()),...pr.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Pr.current=i.end):Pr.current=n,ks()},onFocus:()=>{if(Zn){if(Date.now()<ue.current){let e=Ar.current;e&&e.blur();return}B.current!==null&&(window.clearTimeout(B.current),B.current=null),z(!0)}},onBlur:e=>{if(Nr.current=!1,Pr.current=e.currentTarget.selectionStart??Pr.current,Iu(),Zn){if(Date.now()<Fu.current){let e=Ar.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Fu.current&&document.activeElement!==e&&e.focus()},50);return}}if(fe.current=Date.now(),D()){z(!1);return}B.current!==null&&window.clearTimeout(B.current),B.current=window.setTimeout(()=>{B.current=null,z(!1)},120)}},autoCorrect:Zn?`on`:`off`,autoCapitalize:Zn?`sentences`:`off`,spellCheck:Zn||or,fillContainer:Ai,rows:1},children:[(0,$.jsx)(Hy,{}),qs?(0,$.jsx)(XD,{inputRef:Ar,draftID:Cn?nt(Cn):null,ariaLabel:o(`textarea.resizeHandleAria`),onManualHeightChange:Ys}):null,g&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:ji},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:Ju,onClick:()=>Cl(),title:o(`chat.chatInput.actions.attachFiles`),"aria-label":o(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(qu,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:o(v?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),w&&(0,$.jsx)(ol,{ref:Yr,searchQuery:O,directory:Sn,onCommandSelect:Gc,onClose:()=>T(!1),commandPolicy:Su,commandContext:wn,onRowsChange:Ou?yu:void 0,style:Di&&_a?{left:`${_a.left}px`,top:`${_a.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${_a.left+8}px))`,maxHeight:`${_a.maxHeight}px`,transform:_a.place===`above`?`translateY(-100%)`:void 0}:void 0}),b&&(0,$.jsx)(al,{ref:Kr,searchQuery:S,onFileSelect:Oc,onAgentSelect:kc,onSkillSelect:Vc,onSessionSelect:Ac,onClose:()=>x(!1),onRowsChange:Ou?yu:void 0,style:Di&&_a?{left:`${_a.left}px`,top:`${_a.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${_a.left+8}px))`,maxHeight:`${_a.maxHeight}px`,transform:_a.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Zn&&ea&&!na?(0,$.jsx)(YO,{radius:ji,isMobile:Zn,footerIconButtonClass:Yu,footerPaddingClass:Uu,iconSizeClass:qu,sendIconSizeClass:Gu,onInsert:fs,onInsertAndSend:vs,onContentHeightChange:Ks,onActiveChange:Us,disabled:yn||ra!==null||!vn&&!bn,renderTrigger:!1,topAccessory:XO},$t):null]})})]}),Zn?(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-compact-layer`,"data-yuri-composer-compact-surface":`true`,children:[sd,(0,$.jsx)(`div`,{ref:Ws,onPointerDown:()=>{Gs.current=!1},onScroll:e=>{let t=e.currentTarget;Gs.current=t.scrollWidth-t.clientWidth-t.scrollLeft<=2},className:Y(`yuri-mobile-composer-compact-preview`,!mr.trim()&&`yuri-mobile-composer-compact-preview--placeholder`),style:od?{right:`${.625+2.5*(1+Number(!!(n&&r))+Number(!!(ko||Co||Ls)))}rem`}:void 0,"aria-hidden":`true`,children:mr.trim()?mr:na?ca:Mi})]}):null]}),Zn?(0,$.jsx)(JO,{className:`hidden`,composerTextareaRef:Ar,selectionAdapter:Hn,mobilePanel:P,onMobilePanelChange:F}):null]}),bn&&!Di&&!Zn&&!jl&&!nu?(0,$.jsx)(xS,{onSubmit:ds,className:`chat-input-column mt-4`}):null]}),d.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(CO,{popup:d,onOpenChange:tr,isMobile:Zn})}):null,(0,$.jsx)(Qx,{open:xa,onOpenChange:Sa,mode:`select`,onSelect:e=>{Ea(e),ka(null)}}),(0,$.jsx)(tS,{open:Ca,onOpenChange:wa,onSelect:e=>{ka(e),Ea(null)}}),(0,$.jsx)(`input`,{ref:gl,type:`file`,multiple:!0,className:`hidden`,onChange:Dl,accept:`*/*`}),(0,$.jsx)(`input`,{ref:_l,type:`file`,multiple:!0,className:`hidden`,onChange:Dl,accept:`image/*`}),null,Qn?(0,$.jsx)(lc,{id:`android-media-pick-sheet`,open:U,onOpenChange:e=>{e||W(!1)},onPickPhotos:()=>{pe.current=!1,W(!1),requestAnimationFrame(Tl)},onPickFiles:()=>{pe.current=!1,W(!1),requestAnimationFrame(Cl)}}):null,Zn&&Ml&&Nl?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(sc,{id:`mobile-draft-project-picker-sheet-${G}`,open:ee===`project`,onOpenChange:e=>{e||te(null)},ariaLabel:o(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:o(`mobile.surface.closeAria`),resizeAriaLabel:o(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)($o,{value:ne,onChange:e=>re(e.target.value),placeholder:o(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(ld,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:(0,$.jsx)(nk,{projects:Dn,query:ne,renderLabel:qO,selectedId:Nl.id,onSelect:e=>{du(e),te(null)}})})}),(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-4 pt-1`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg border-t border-border/50 px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{te(null),sa.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:o(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},fk=e=>{let t=(0,Q.c)(3),n=hy(),r=e.surface??n;if(r&&!r.active)return null;let i=r??void 0,a;return t[0]!==e||t[1]!==i?(a=(0,$.jsx)(dk,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};fk.displayName=`ChatInput`;var pk=Z.memo(fk);function mk(e){return e.preventDefault()}function hk(e){e.preventDefault()}function gk(e){return e.preventDefault()}function _k(e){e.pointerType===`touch`&&e.preventDefault()}function vk(e){e.preventDefault()}function yk(e){e.pointerType===`touch`&&e.preventDefault()}var bk=e=>!!(e&&typeof e==`object`&&typeof e.type==`string`),xk=e=>e.filter(bk),Sk=e=>{let t=e,n=t.text;return typeof n==`string`?n:t.content||t.value||``},Ck=e=>/[^\s\u200B-\u200D\u2060\uFEFF]/u.test(e),wk=e=>e.type===`text`&&!Ck(Sk(e)),Tk=(e,t={})=>{let{includeReasoning:n=!0}=t,r=xk(e),i=r.some(e=>!e.synthetic);return r.filter(e=>{let t=!!e.synthetic;if(e.type===`text`){if(wk(e))return!1;let t=Sk(e);if(t.includes(`<system-reminder>`)&&Rt(t).length===0)return!1}return t&&i||!n&&e.type===`reasoning`?!1:e.type!==`patch`})},Ek=`GitHub issue context (JSON)`,Dk=`GitHub pull request context (JSON)`,Ok=`The user referenced these OpenCode sessions (id, title, owning directory).`,kk=e=>typeof e==`number`&&Number.isFinite(e)&&e>0,Ak=(e,t)=>{let n=e.trimStart();if(!n.startsWith(t))return null;let r=n.indexOf(`{`);if(r<0)return null;try{return JSON.parse(n.slice(r))}catch{return null}},jk=e=>{let t=Ak(e,Ek);if(t){let e=t.issue,n=e?.number,r=e?.title,i=e?.url;return!kk(n)||typeof r!=`string`||typeof i!=`string`?null:{type:`file`,mime:`application/vnd.github.issue-link`,filename:`Issue #${n}: ${r}`,url:i}}let n=Ak(e,Dk);if(n){let e=n.pr,t=e?.number,r=e?.title,i=e?.url;return!kk(t)||typeof r!=`string`||typeof i!=`string`?null:{type:`file`,mime:`application/vnd.github.pull-request-link`,filename:`PR #${t}: ${r}`,url:i}}return null},Mk=e=>!!e.trim().startsWith(`The following tool was executed by the user`),Nk=e=>e.trimStart().startsWith(`Continue working toward the active session goal.`),Pk=e=>e.trim()===`/compact`,Fk=e=>e.flatMap(e=>{if(e.type===`compaction`)return[];if(e.type===`text`){let t=e.text;if(typeof t==`string`){let n=lo(t);if(n.trim().length===0||Nk(n)||Pk(n)||n.trimStart().startsWith(Ok)||n.includes(`<system-reminder>`)&&Rt(n).length===0)return[];n!==t&&(e={...e,text:n})}}if(e.synthetic!==!0)return[e];if(e.type!==`text`)return[];let t=e.text;if(typeof t!=`string`)return[];let n=t.trimStart();return Mk(t)||n.startsWith(Ek)||n.startsWith(Dk)?[e]:[]}).map(e=>{let t=e;if(t.type===`text`){let n=typeof t.text==`string`?t.text.trim():``;if(t.synthetic===!0){let e=jk(n);if(e)return e}if(n.startsWith(`The following tool was executed by the user`))return{...e,type:`text`,text:`/shell`};if(n.includes(`<system-reminder>`))return{...e,type:`text`,text:Rt(n)}}return e}),Ik=e=>e.some(e=>{if(e.type===`text`)return!wk(e);if(e.type===`file`){let t=e,n=typeof t.mime==`string`?t.mime:``,r=typeof t.url==`string`?t.url:``;return(!!n||!!r)&&!!r&&!xe(e)}return!0}),Lk=e=>e?.length?Ik(Fk(e)):!1,Rk=(e,t)=>{if(t.length===0)return e;let n=new Map(t.map(e=>[e.info.id,e])),r=!1,i=e.map(e=>{if(Lk(e.parts))return e;let t=n.get(e.info.id);return t?(r=!0,t):e}),a=r?i:e,o=new Set(e.map(e=>e.info.id)),s=t.filter(e=>!o.has(e.info.id));return s.length===0?a:[...a,...s]},zk=(e,t)=>{if(e.length===0)return!1;let n;for(let t of e){let e=t.info.time?.created;typeof e==`number`&&(n===void 0||e>n)&&(n=e)}return!t.resolvedSessionStatus||typeof t.sessionStatusObservedAt!=`number`||typeof n!=`number`||n>t.sessionStatusObservedAt},Bk=e=>{let t=e.boundary.kind===`exhausted`,n=e.boundary.kind===`has-more`,r=t&&!e.assistantComplete,i=n||r;return{complete:t&&e.assistantComplete,canLoadEarlier:i}},Vk=e=>e.syncLoading||e.assistantLoading,Hk=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Uk=e=>e.isLoadingOlder,Wk=e=>!e.isMobile&&e.isLoadingOlder,Gk=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Kk=e=>e.hasImmediateShell||e.hasTranscriptShell&&e.hasRenderableSessionSnapshot||e.transcriptRecords?.some(e=>e.info.role===`user`?Lk(e.parts):e.parts.some(e=>e.type===`tool`||e.type===`text`&&e.text.trim().length>0))||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,qk=e=>{let{sessionId:t,messages:n,retained:r}=e;return t?n.length>0?{messages:n,retained:{sessionId:t,messages:n}}:r?.sessionId===t?{messages:r.messages,retained:r}:{messages:n,retained:null}:{messages:n,retained:null}},Jk=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Yk=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Xk=`relative bottom-safe-area yuri-mobile-readonly-prompt-foot`,Zk=e=>{let t=(0,Q.c)(8),{providerId:n,modelId:r,label:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3.5`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{role:`img`,"aria-label":i,className:`inline-flex size-3.5 shrink-0 items-center justify-center`,children:a}),t[1]=i,t[2]=o);let s;return t[3]!==i||t[4]!==r||t[5]!==n||t[6]!==o?(s=(0,$.jsx)(ll,{modelId:r,providerId:n,alt:i,className:`size-3.5 shrink-0`,fallback:o}),t[3]=i,t[4]=r,t[5]=n,t[6]=o,t[7]=s):s=t[7],s},Qk=e=>{let t=(0,Q.c)(42),{t:n}=fr(),r=q($k),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Xk,i;t[0]===e?i=t[1]:(i=Y(`p-3`,e),t[0]=e,t[1]=i);let a;t[2]===n?a=t[3]:(a=n(`chat.container.readOnlySubagentPromptBanner`),t[2]=n,t[3]=a);let o;t[4]===a?o=t[5]:(o=(0,$.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-[var(--surface-background)] px-4 py-3 text-muted-foreground ${Yk}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,s;t[11]!==e.agentName||t[12]!==o?(s=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=s):s=t[13];let c=s,l=e.modelName||o,u;t[14]===n?u=t[15]:(u=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=u);let d=`${u}: ${c}`,f;t[16]===n?f=t[17]:(f=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=f);let p=`${f}: ${l}`,m=r&&Xk,h;t[18]===m?h=t[19]:(h=Y(`shrink-0 border-t border-border/70 p-3`,m),t[18]=m,t[19]=h);let g=r&&`yuri-mobile-readonly-prompt-surface`,_;t[20]===g?_=t[21]:(_=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,g),t[20]=g,t[21]=_);let v;t[22]===n?v=t[23]:(v=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=v);let y;t[24]===v?y=t[25]:(y=(0,$.jsx)(`div`,{className:`text-muted-foreground ${Yk}`,children:v}),t[24]=v,t[25]=y);let b;t[26]!==d||t[27]!==c||t[28]!==p||t[29]!==l||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(b=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Fo,{name:e.agentName,size:14,label:d}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:c,children:c})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Zk,{providerId:e.providerId,modelId:e.modelId,label:p}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:l,children:l})]})]}):null,t[26]=d,t[27]=c,t[28]=p,t[29]=l,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=b):b=t[34];let x;t[35]!==b||t[36]!==_||t[37]!==y?(x=(0,$.jsxs)(`div`,{className:_,children:[y,b]}),t[35]=b,t[36]=_,t[37]=y,t[38]=x):x=t[38];let S;return t[39]!==x||t[40]!==h?(S=(0,$.jsx)(`aside`,{className:h,children:x}),t[39]=x,t[40]=h,t[41]=S):S=t[41],S};function $k(e){return e.isMobile}var eA=Z.memo(()=>{let e=(0,Q.c)(5),{t}=fr(),{currentTheme:n}=Io(),r=oi(tA),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Bs,{width:140,height:140,className:`opacity-20`}),e[0]=a):a=e[0];let o;return e[1]!==r||e[2]!==t||e[3]!==i?(o=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-full w-full gap-6`,children:[a,r?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 max-w-md text-center px-4`,children:[(0,$.jsx)(`span`,{className:`typography-markdown font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`typography-meta`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`typography-markdown`,style:{color:i},children:t(`chat.emptyState.startNewChat`)})]}),e[1]=r,e[2]=t,e[3]=i,e[4]=o):o=e[4],o});function tA(e){return e.error}var nA=`yuri_asst_session_divider:`,rA=[],iA=e=>typeof e?.info?.id==`string`&&e.info.id.startsWith(`yuri_asst_session_divider:`),aA=(e,t=0)=>({info:{id:`${nA}${e}`,role:`system`,time:{created:t}},parts:[]}),oA=e=>!!(e?.info&&typeof e.info==`object`&&e.info.yuriAssistantAdmission),sA=(e,t,n=rA)=>{if(!e.length)return rA;let r=[],i=!1,a=null;for(let n of e)n.sessionID!==t&&(i&&a!==n.sessionID&&r.push(aA(n.sessionID,Number(n.info.time?.created??0))),r.push({info:n.info,parts:n.parts,sourceSessionID:n.sessionID,sourceDirectory:n.directory}),i=!0,a=n.sessionID);return r.length===0?rA:fA(n,r)?n:r},cA=(e,t)=>{if(t.length===0)return e;if(e.length===0)return t;let n=new Map;for(let e of t)e?.id&&n.set(e.id,e);for(let t of e)t?.id&&n.set(t.id,t);let r=new Set,i=[];for(let e of t){if(!e?.id||r.has(e.id))continue;let t=n.get(e.id);t&&(i.push(t),r.add(e.id))}for(let t of e)!t?.id||r.has(t.id)||(i.push(t),r.add(t.id));return i.length===e.length&&i.every((t,n)=>t===e[n])?e:i},lA=(e,t)=>{if(!t)return e;if(e.info.role===`assistant`&&t.parts.length>0){let n=cA(e.parts,t.parts);return n===e.parts&&e.info===t.info?e:n===t.parts&&e.info===t.info&&e.parts===t.parts?t:{...e,parts:n,...t.sourceParts&&!e.sourceParts?{sourceParts:t.sourceParts}:{}}}return Lk(e.parts)?e:Lk(t.parts)?e.info===t.info&&e.parts===t.parts?t:{...e,parts:t.parts,...t.sourceParts&&!e.sourceParts?{sourceParts:t.sourceParts}:{}}:e.parts.length>0||t.parts.length===0?e:e.info===t.info&&e.parts===t.parts?t:{...e,parts:t.parts,...t.sourceParts&&!e.sourceParts?{sourceParts:t.sourceParts}:{}}},uA=(e,t,n,r=rA)=>{if(!t)return n.length>0?Array.from(n):rA;let i=new Map,a=0;for(let n of e)n.sessionID===t&&(oA(n)||i.set(n.info.id,{message:{info:n.info,parts:n.parts},order:a++}));for(let e of n){let t=i.get(e.info.id);i.set(e.info.id,{message:lA(e,t?.message),order:t?.order??a++})}if(i.size===0)return rA;let o=[...i.values()].sort((e,t)=>Number(e.message.info.time?.created??0)-Number(t.message.info.time?.created??0)||e.order-t.order).map(({message:e})=>e);return fA(r,o)?r:o},dA=(e,t)=>{if(!iA(e)||!iA(t))return!1;let n=Number(e.info.time?.created??0),r=Number(t.info.time?.created??0);return e.info.id===t.info.id&&n===r},fA=(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||!i||!(r===i||dA(r,i))&&(r?.info!==i?.info||r?.parts!==i?.parts||r.sourceSessionID!==i.sourceSessionID||r.sourceDirectory!==i.sourceDirectory))return!1}return!0},pA=()=>ae(e=>({expanded:new Set,toggle:t=>e(e=>{let n=new Set(e.expanded);return n.has(t)?n.delete(t):n.add(t),{expanded:n}})})),mA=(0,Z.createContext)(null);function hA(e){let t=(0,Q.c)(7),n=(0,Z.useContext)(mA),r;t[0]===n?r=t[1]:(r=()=>n??pA(),t[0]=n,t[1]=r);let[i]=(0,Z.useState)(r),a=n??i,o;t[2]===e?o=t[3]:(o=t=>t.expanded.has(e),t[2]=e,t[3]=o);let s=re(a,o),c=re(a,gA),l;return t[4]!==s||t[5]!==c?(l={expanded:s,toggle:c},t[4]=s,t[5]=c,t[6]=l):l=t[6],l}function gA(e){return e.toggle}var _A=(0,Z.createContext)(null);function vA(e,t){return JSON.stringify([e,t])}function yA(e){return new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`giu`)}var bA=new WeakMap;function xA(e){return e.map(e=>{if(e.type===`image`||e.type===`html`||e.type===`def`)return``;if(e.type===`space`||e.type===`br`||e.type===`hr`)return`
|
|
6559
|
+
`;if(e.type===`code`||e.type===`codespan`)return e.text;if(e.type===`list`)return e.items.map(e=>xA(e.tokens)).join(`
|
|
6560
|
+
`);if(e.type===`table`)return[e.header,...e.rows].map(e=>e.map(e=>xA(e.tokens)).join(` `)).join(`
|
|
6561
|
+
`);let t=`tokens`in e?e.tokens:void 0;if(t)return xA(t)+([`paragraph`,`heading`,`blockquote`].includes(e.type)?`
|
|
6562
|
+
`:``);let n=`text`in e&&typeof e.text==`string`?e.text:``;if(!n.includes(`&`)||typeof document>`u`)return n;let r=document.createElement(`textarea`);return r.innerHTML=n.replace(/</g,`<`),r.value}).join(``)}function SA(e){let t=bA.get(e);if(t!==void 0)return t;let n=xA(Zd.lex(e.text));return bA.set(e,n),n}function CA(e){let t=yA(e),n=new WeakMap;return r=>{if(!e.trim())return[];let i=[],a=new Set,o=new Map(r.map(e=>[e.info.id,e]));for(let s of r){let r=o.get(s.info.id);if(a.has(r.info.id))continue;a.add(r.info.id);let c=n.get(r.parts);if(!c){c=[];let i=Tk(r.info.role===`user`?Fk(r.parts):r.parts);for(let n of i){if(n.type!==`text`||n.ignored)continue;let i=0;for(let a of SA(n).matchAll(t))c.push({messageId:r.info.id,partId:n.id,occurrence:i++,query:e})}n.set(r.parts,c)}for(let e of c)i.push(e)}return i}}function wA(e,t){if(!t.trim())return[];let n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[],i=``,a;for(;a=n.nextNode();){let e=a;if(e.parentElement?.closest(`button, [aria-hidden="true"], [hidden], [data-md-code-line-numbers]`))continue;let t=i.length;i+=e.data,r.push({node:e,start:t,end:i.length})}let o=[],s=0;for(let n of i.matchAll(yA(t))){let t=n.index,i=t+n[0].length;for(;s<r.length&&r[s].end<=t;)s++;let a=r[s],c=s;for(;c<r.length&&r[c].end<i;)c++;let l=r[c];if(!a||!l)continue;let u=e.ownerDocument.createRange();u.setStart(a.node,t-a.start),u.setEnd(l.node,i-l.start),o.push(u)}return o}var TA=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:Ii(t)},EA=Z.memo(e=>{let t=(0,Q.c)(29),{isUser:n,providerID:r,modelID:i,agentName:a,modelName:o,variant:s}=e,c;t[0]!==n||t[1]!==s?(c=n?null:TA(s),t[0]=n,t[1]=s,t[2]=c):c=t[2];let l=c,u=o||`Assistant`,d,f;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(d=Y(`mb-1.5`),f=Y(`flex items-center justify-between gap-2`),t[3]=d,t[4]=f):(d=t[3],f=t[4]);let p;t[5]!==a||t[6]!==n||t[7]!==i||t[8]!==r?(p=(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:n?(0,$.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-primary/10 flex items-center justify-center`,children:(0,$.jsx)(X,{name:`user-3`,className:`h-4 w-4 text-primary`})}):(0,$.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,$.jsx)(ll,{modelId:i,providerId:r,className:`h-4 w-4`,fallback:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-4 w-4`,style:{color:`var(${Ao(a).var})`}})})})}),t[5]=a,t[6]=n,t[7]=i,t[8]=r,t[9]=p):p=t[9];let m=n?`text-primary`:`text-foreground`,h;t[10]===m?h=t[11]:(h=Y(`inline-flex min-w-0 items-center gap-1.5 font-semibold typography-ui-header tracking-tight leading-tight`,m),t[10]=m,t[11]=h);let g=n?`You`:u,_;t[12]===g?_=t[13]:(_=(0,$.jsx)(`span`,{className:`truncate`,children:g}),t[12]=g,t[13]=_);let v;t[14]===l?v=t[15]:(v=l?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-normal leading-tight text-muted-foreground`,children:l}):null,t[14]=l,t[15]=v);let y;t[16]!==h||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`h3`,{className:h,children:[_,v]}),t[16]=h,t[17]=_,t[18]=v,t[19]=y):y=t[19];let b;t[20]!==a||t[21]!==n?(b=!n&&a&&(0,$.jsxs)(`div`,{className:Y(`agent-badge inline-flex shrink-0 items-center gap-1 cursor-default rounded px-1.5 py-0 font-normal leading-none text-[10px]`,Ao(a).class),children:[(0,$.jsx)(Fo,{name:a,size:10,shape:`square`}),(0,$.jsx)(`span`,{children:a.charAt(0).toUpperCase()+a.slice(1)})]}),t[20]=a,t[21]=n,t[22]=b):b=t[22];let x;t[23]!==y||t[24]!==b?(x=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[y,b]}),t[23]=y,t[24]=b,t[25]=x):x=t[25];let S;return t[26]!==x||t[27]!==p?(S=(0,$.jsx)(`div`,{className:d,children:(0,$.jsx)(`div`,{className:f,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[p,x]})})}),t[26]=x,t[27]=p,t[28]=S):S=t[28],S}),DA=6e5,OA=new Map,kA=e=>{let t=zn(e);if(!t)return;let n=OA.get(t);if(n){if(n.expiresAt<=Date.now()){OA.delete(t);return}return n.outsideFileGrant}},AA=(e,t,n)=>{let r=zn(e);!r||!t||OA.set(r,{outsideFileGrant:t,expiresAt:typeof n==`number`&&Number.isFinite(n)?n:Date.now()+DA})},jA=async(e,t)=>{let n=zn(e);if(!n||!t||Bn(n,t))return;let r=kA(n);if(r)return r;let i=await b(n);if(!(!i.success||!i.path||!i.outsideFileGrant))return AA(i.path,i.outsideFileGrant),zn(i.path)!==n&&AA(n,i.outsideFileGrant),i.outsideFileGrant},MA=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,NA=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,PA=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),FA=(e,t)=>e.split(NA).map((e,n)=>n%2==1?e:t(e)).join(``),IA=e=>FA(e,e=>e.replace(/ *\n/g,`
|
|
6563
|
+
`)),LA=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=FA(e,PA);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${td(t.name)})`;i=i.replace(t.token,e)}i=i.replace(MA,(e,t,r)=>n.has(r)?`${t}[/${r}](${od(r)})`:e)}return IA(i)},RA=e=>(MA.lastIndex=0,MA.test(e)||e.includes(`[skill:`)),zA=e=>{if(typeof window>`u`)return!1;let t=window.getSelection();if(!t||t.isCollapsed||t.rangeCount===0)return!1;let n=t.getRangeAt(0);return e.contains(n.startContainer)||e.contains(n.endContainer)},BA=Z.memo(e=>{let t=(0,Q.c)(94),{part:n,messageId:r,agentMention:i,messageParts:a,variant:o}=e,s=(o===void 0?`message`:o)===`preview`,c=Z.useContext(_A),l=!s&&c?.messageId===r&&c.partId===n.id,u=n,d=u.text,f=typeof d==`string`?d:u.content||u.value||``,p;t[0]===f?p=t[1]:(p=Rg(f),t[0]=f,t[1]=p);let m=p,h=m?m.body:f,[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),b;t[2]===s?b=t[3]:(b=e=>!s&&e.collapsibleUserMessages,t[2]=s,t[3]=b);let x=q(b),S=Nu(),C;t[4]===h?C=t[5]:(C=RA(h),t[4]=h,t[5]=C);let w;t[6]!==S||t[7]!==C?(w={directory:S,enabled:C},t[6]=S,t[7]=C,t[8]=w):w=t[8];let T=oa(w),E;t[9]===T.data?E=t[10]:(E=T.data??[],t[9]=T.data,t[10]=E);let D=E,O=q(VA),{t:k}=fr(),A=x&&!g&&!l,j=Z.useRef(null),M;t[11]===D?M=t[12]:(M=new Map(D.map(HA)),t[11]=D,t[12]=M);let N=M,P;t[13]!==a||t[14]!==h?(P=w_(a,h),t[13]=a,t[14]=h,t[15]=P):P=t[15];let F=P,I;if(t[16]!==a||t[17]!==h){let e=new Map;for(let t of a??[]){if(t.type!==`text`||!Or(t))continue;let n=t.text;if(typeof n==`string`)for(let t of Tr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(h.includes(`@`))for(let[t,n]of Ne()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(h.includes(`@${r}`)||h.includes(`@${tt}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}I=Array.from(e.values()),t[16]=a,t[17]=h,t[18]=I}else I=t[18];let L=I,R;t[19]!==S||t[20]!==O||t[21]!==N?(R=e=>{let t=N.get(e),n=typeof t?.path==`string`?t.path:``,r=zn(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=S||Un(``,i)||`/`,o=()=>{O(a,i)};if(S&&!Bn(i,S)){jA(i,S).then(o);return}o()},t[19]=S,t[20]=O,t[21]=N,t[22]=R):R=t[22];let z=J(R),B;t[23]!==x||t[24]!==g?(B=()=>{let e=j.current;if(!e||!x)return;let t=()=>{x&&!g&&e.scrollHeight>e.clientHeight&&y(!0)};y(!1),t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},t[23]=x,t[24]=g,t[25]=B):B=t[25];let V;t[26]!==x||t[27]!==g||t[28]!==h?(V=[x,h,g],t[26]=x,t[27]=g,t[28]=h,t[29]=V):V=t[29],Z.useEffect(B,V);let H,U;t[30]===x?(H=t[31],U=t[32]):(H=()=>{x||(_(!1),y(!1))},U=[x],t[30]=x,t[31]=H,t[32]=U),Z.useEffect(H,U);let W;t[33]!==x||t[34]!==g||t[35]!==s||t[36]!==v||t[37]!==z?(W=e=>{if(s)return;let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??rd(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),z(n);return}let r=j.current;r&&(zA(r)||x&&!g&&v&&_(!0))},t[33]=x,t[34]=g,t[35]=s,t[36]=v,t[37]=z,t[38]=W):W=t[38];let ee=J(W),te;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(te=e=>{e.stopPropagation(),_(!1)},t[39]=te):te=t[39];let G=J(te),ne;t[40]!==i||t[41]!==F.displayNames||t[42]!==F.icons||t[43]!==L||t[44]!==N||t[45]!==h?(ne=v_(h,{skillNames:new Set(N.keys()),citationIcons:F.icons,citationDisplayNames:F.displayNames,sessionMentions:L,agentNames:i?.name?new Set([i.name.toLowerCase(),i.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),t[40]=i,t[41]=F.displayNames,t[42]=F.icons,t[43]=L,t[44]=N,t[45]=h,t[46]=ne):ne=t[46];let re=ne,ie;t[47]!==i||t[48]!==re||t[49]!==N||t[50]!==h?(ie=LA({textContent:h,agentMention:i,skillNames:new Set(N.keys()),decorateInlineReferences:!re}),t[47]=i,t[48]=re,t[49]=N,t[50]=h,t[51]=ie):ie=t[51];let ae=ie,oe;t[52]===A?oe=t[53]:(oe=(e,t)=>{if(!e)return null;let n=LA({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(nc,{content:n,className:Y(`inline w-auto align-baseline [&_.markdown-content]:contents [&_.markdown-content_p]:inline [&_[data-markdown-size-spacer]]:inline`,`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,A&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1},t)},t[52]=A,t[53]=oe);let se=oe,ce;t[54]!==s||t[55]!==z||t[56]!==se?(ce=e=>e.map((e,t)=>e.type===`text`?se(e.text,`text-${t}`):(0,$.jsx)(E_,{decoration:e.decoration,onOpenSkill:z,interactive:!s},`ref-${t}-${e.span.start}`)),t[54]=s,t[55]=z,t[56]=se,t[57]=ce):ce=t[57];let le=ce;if((!h||h.trim().length===0)&&!m?.quotes.length)return null;let ue=A&&v,de=n.id||`${r}-user-text`,fe;t[58]!==s||t[59]!==r||t[60]!==n.id?(fe=s?void 0:vA(r,n.id),t[58]=s,t[59]=r,t[60]=n.id,t[61]=fe):fe=t[61];let pe=ue?`true`:void 0,me;t[62]!==x||t[63]!==G||t[64]!==g||t[65]!==k?(me=x&&g&&(0,$.jsx)(`button`,{type:`button`,onClick:G,className:`absolute top-0 right-0 z-10 flex items-center justify-center rounded-sm bg-[var(--surface-elevated)] p-0.5 text-[var(--surface-mutedForeground)] hover:text-[var(--surface-foreground)] hover:bg-[var(--interactive-hover)] transition-colors`,"aria-label":k(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),t[62]=x,t[63]=G,t[64]=g,t[65]=k,t[66]=me):me=t[66];let he;t[67]!==r||t[68]!==n.id||t[69]!==m||t[70]!==k?(he=m&&m.quotes.length>0?(0,$.jsx)(`div`,{className:`mb-2 flex flex-col gap-1`,"data-conversation-quotes":!0,"aria-label":k(`chat.message.conversationQuotesLabel`),children:m.quotes.map((e,t)=>(0,$.jsx)(`p`,{"data-conversation-quote":!0,className:`m-0 whitespace-pre-wrap break-words border-l-2 border-border pl-3 typography-meta text-muted-foreground`,children:e},`${n.id||r}-quote-${t}`))}):null,t[67]=r,t[68]=n.id,t[69]=m,t[70]=k,t[71]=he):he=t[71];let ge;t[72]!==x||t[73]!==ee||t[74]!==A||t[75]!==g||t[76]!==s||t[77]!==v||t[78]!==ae||t[79]!==re||t[80]!==le||t[81]!==h?(ge=h.trim().length>0?(0,$.jsx)(`div`,{className:Y(`break-words font-sans`,s?`typography-meta`:`typography-markdown-body`,g&&`pb-3`,A&&`line-clamp-10`,x&&v&&!g&&`cursor-pointer`),"data-user-message-collapse":A?`true`:void 0,ref:j,onClick:ee,children:re?le(re):(0,$.jsx)(nc,{content:ae,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,A&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1})}):null,t[72]=x,t[73]=ee,t[74]=A,t[75]=g,t[76]=s,t[77]=v,t[78]=ae,t[79]=re,t[80]=le,t[81]=h,t[82]=ge):ge=t[82];let _e;t[83]!==ue||t[84]!==k?(_e=ue&&(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,className:`yuri-user-text-expand flex cursor-pointer items-center justify-start gap-1 text-left font-sans typography-markdown-body text-muted-foreground`,"aria-expanded":!1,onClick:()=>_(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_(!0))},children:[k(`chat.message.userText.showMore`),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-[1em] shrink-0`})]}),t[83]=ue,t[84]=k,t[85]=_e):_e=t[85];let ve;return t[86]!==de||t[87]!==fe||t[88]!==pe||t[89]!==me||t[90]!==he||t[91]!==ge||t[92]!==_e?(ve=(0,$.jsxs)(`div`,{className:`relative`,"data-transcript-search-part":fe,"data-user-message-clamp":pe,children:[me,he,ge,_e]},de),t[86]=de,t[87]=fe,t[88]=pe,t[89]=me,t[90]=he,t[91]=ge,t[92]=_e,t[93]=ve):ve=t[93],ve});function VA(e){return e.openContextFile}function HA(e){return[e.name,e]}var UA=[{variant:`static`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:t,children:e})},{variant:`generate-effect`,component:({children:e,className:t,...n})=>{if(e==null)return null;let r=typeof e==`string`?e:typeof e==`number`?String(e):Array.isArray(e)?e.map(e=>typeof e==`string`||typeof e==`number`?String(e):``).join(``):``;return r?(0,$.jsx)(`span`,{className:Y(`inline-block align-baseline`,t),children:r.split(``).map((e,t)=>(0,Z.createElement)($d.span,{...n,key:e+String(t),className:Y(`inline-block whitespace-pre align-baseline`),initial:{opacity:0},animate:{opacity:1},transition:{ease:`easeOut`,duration:.14,delay:Math.min(t*.0045,.14)}},e))}):null}},{variant:`glitch`,component:({children:e,className:t,...n})=>(0,$.jsxs)(`div`,{className:`group relative overflow-hidden font-medium`,children:[(0,$.jsx)(`span`,{...n,className:Y(`invisible`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 text-primary-muted transition-transform duration-500 ease-in-out`,`group-hover:-translate-y-full hover:duration-300`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 translate-y-full text-primary-muted transition-transform duration-500`,`ease-in-out hover:duration-300 group-hover:translate-y-0`,t),children:e})]})},{variant:`hover-enter`,component:({children:e,className:t,...n})=>{if(typeof e!=`string`)return null;let r=.25,i=.025,a=e.split(``).map(e=>e===` `?`\xA0`:e);return(0,$.jsxs)($d.span,{...n,className:Y(`relative block select-none overflow-hidden whitespace-nowrap text-primary-muted`,t),initial:`initial`,whileHover:`hovered`,style:{lineHeight:.9},children:[(0,$.jsx)(`div`,{children:a.map((e,t)=>(0,$.jsx)($d.span,{className:`inline-block`,variants:{initial:{y:0},hovered:{y:`-100%`}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0`),children:a.map((e,t)=>(0,$.jsx)($d.span,{className:`inline-block`,variants:{initial:{y:`100%`},hovered:{y:0}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))})]})}},{variant:`shake`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted hover:animate-text-shake`,t),children:e})},{variant:`hover-decoration`,component:({children:e,className:t,...n})=>(0,$.jsx)(`div`,{className:Y(`relative after:absolute after:bottom-0 after:left-0 after:h-px after:w-full after:origin-bottom-right`,`after:scale-x-0 after:bg-primary-muted after:transition-transform after:duration-300 after:ease-in-out hover:after:origin-bottom-left hover:after:scale-x-100`),children:(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted`,t),children:e})})}];function WA(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({variant:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`static`:i,o;t[4]===a?o=t[5]:(o=UA.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||UA[0].component,c;return t[6]!==s||t[7]!==n||t[8]!==r?(c=(0,$.jsx)(s,{...r,className:n}),t[6]=s,t[7]=n,t[8]=r,t[9]=c):c=t[9],c}var GA=e=>{let t=(0,Q.c)(42),{output:n,isMobile:r}=e,{t:i}=fr(),a=Z.useId(),[o,s]=Z.useState(!1),c;t[0]===n?c=t[1]:(c=n.slice(0,240).replace(/\s+/g,` `).trim(),t[0]=n,t[1]=c);let l=c,u;t[2]===i?u=t[3]:(u=i(`chat.toolPart.output`),t[2]=i,t[3]=u);let d=u,f;t[4]!==n||t[5]!==i?(f=async()=>{(await Ea(n)).ok?no.success(i(`chat.toolPart.copiedOutput`)):no.error(i(`chat.toolPart.copyOutputFailed`))},t[4]=n,t[5]=i,t[6]=f):f=t[6];let p=J(f),m;t[7]===i?m=t[8]:(m=i(`chat.toolPart.copyOutput`),t[7]=i,t[8]=m);let h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(X,{name:`file-copy`,className:`size-4`}),t[9]=h):h=t[9];let g;t[10]!==p||t[11]!==m?(g=(0,$.jsx)($r,{variant:`ghost`,size:`icon`,onClick:p,"aria-label":m,children:h}),t[10]=p,t[11]=m,t[12]=g):g=t[12];let _=g,v;t[13]!==o||t[14]!==n?(v=o?(0,$.jsx)(`div`,{className:`tool-output-surface overlay-scrollbar-container min-h-0 flex-1 overflow-auto p-2`,"data-tool-json-code":!0,children:(0,$.jsx)(Fd,{language:`json`,code:n,wrap:!0})}):null,t[13]=o,t[14]=n,t[15]=v):v=t[15];let y=v,b;t[16]===l?b=t[17]:(b=(0,$.jsx)(`code`,{className:`typography-code min-w-0 flex-1 truncate text-muted-foreground`,children:l}),t[16]=l,t[17]=b);let x;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>s(!0),t[18]=x):x=t[18];let S;t[19]===i?S=t[20]:(S=i(`chat.toolPart.showRawJson`),t[19]=i,t[20]=S);let C;t[21]===i?C=t[22]:(C=i(`chat.toolPart.showRawJson`),t[21]=i,t[22]=C);let w;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(X,{name:`code-box`,className:`size-4`}),t[23]=w):w=t[23];let T;t[24]!==o||t[25]!==S||t[26]!==C?(T=(0,$.jsx)($r,{size:`icon`,onClick:x,"aria-label":S,"aria-haspopup":`dialog`,"aria-expanded":o,title:C,children:w}),t[24]=o,t[25]=S,t[26]=C,t[27]=T):T=t[27];let E;t[28]!==T||t[29]!==b?(E=(0,$.jsxs)(`div`,{className:`tool-output-surface flex min-w-0 items-center gap-1 rounded-lg`,"data-tool-json-preview":!0,children:[b,T]}),t[28]=T,t[29]=b,t[30]=E):E=t[30];let D;t[31]!==y||t[32]!==_||t[33]!==a||t[34]!==r||t[35]!==o||t[36]!==i||t[37]!==d?(D=r?(0,$.jsx)(sc,{id:`tool-json-${a}`,open:o,onOpenChange:s,title:(0,$.jsx)(`span`,{className:`typography-ui-header font-semibold`,children:d}),ariaLabel:d,closeAriaLabel:i(`dialog.common.actions.close`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),trailing:_,children:y}):(0,$.jsx)(Ko,{open:o,onOpenChange:s,children:(0,$.jsxs)(Ho,{className:`h-[85dvh] max-w-5xl gap-1 overflow-hidden p-2`,showCloseButton:!1,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(Uo,{className:`min-w-0 flex-1 px-1`,children:d}),_,(0,$.jsx)($r,{variant:`ghost`,size:`icon`,onClick:()=>s(!1),"aria-label":i(`dialog.common.actions.close`),children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}),y]})}),t[31]=y,t[32]=_,t[33]=a,t[34]=r,t[35]=o,t[36]=i,t[37]=d,t[38]=D):D=t[38];let O;return t[39]!==E||t[40]!==D?(O=(0,$.jsxs)(`div`,{onClick:KA,onPointerDown:qA,children:[E,D]}),t[39]=E,t[40]=D,t[41]=O):O=t[41],O};function KA(e){return e.stopPropagation()}function qA(e){return e.stopPropagation()}var JA=e=>{let t=`h-3.5 w-3.5 flex-shrink-0`,n=`h-[13px] w-[13px] flex-shrink-0`,r=e.toLowerCase();return r===`edit`||r===`multiedit`||r===`apply_patch`||r===`patch`||r===`str_replace`||r===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil`,className:n}):r===`write`||r===`create`||r===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:n}):r===`read`||r===`view`||r===`file_read`||r===`cat`?(0,$.jsx)(X,{name:`file-text`,className:t}):r===`bash`||r===`shell`||r===`cmd`||r===`terminal`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):r===`execute`?(0,$.jsx)(X,{name:`code-box`,className:t}):r===`list`||r===`ls`||r===`dir`||r===`list_files`?(0,$.jsx)(X,{name:`folder-6`,className:t}):r===`search`||r===`grep`||r===`find`||r===`ripgrep`?(0,$.jsx)(X,{name:`menu-search`,className:t}):r===`glob`?(0,$.jsx)(X,{name:`file-search`,className:t}):r===`fetch`||r===`curl`||r===`wget`||r===`webfetch`||r===`browser`||r===`web-search`||r===`websearch`||r===`search_web`||r===`codesearch`||r===`google`||r===`bing`||r===`duckduckgo`||r===`perplexity`?(0,$.jsx)(X,{name:`global`,className:t}):r===`todowrite`||r===`todoread`?(0,$.jsx)(Ud,{className:Y(`size-3.5 text-current`,t)}):r===`structuredoutput`||r===`structured_output`?(0,$.jsx)(X,{name:`list-check-2`,className:t}):r===`skill`?(0,$.jsx)(X,{name:`book`,className:t}):r===`task`||r===`subagent`?(0,$.jsx)(X,{name:`ai-agent`,className:t}):r===`question`?(0,$.jsx)(X,{name:`survey`,className:t}):r===`lsp`?(0,$.jsx)(X,{name:`scan-2`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},YA=new Map,XA=e=>{let t=YA.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return YA.set(e,n),n},ZA=(e,t)=>{let n=XA(e);return n.subscribers.add(t),t(Date.now()),n.timerId===null&&typeof window<`u`&&(n.timerId=window.setInterval(()=>{let e=Date.now();n.subscribers.forEach(t=>{t(e)})},e)),()=>{let n=YA.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),YA.delete(e)))}},QA=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState($A),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return ZA(r,a)},s=[e,r],n[0]=e,n[1]=r,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),i};function $A(){return Date.now()}var ej=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],tj=e=>{if(e&&typeof e==`object`&&!Array.isArray(e))return e;if(typeof e!=`string`)return;let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return e}catch{return}},nj=(...e)=>{for(let t of e){let e=tj(t);if(!e)continue;let n=[e.subagent_type,e.subagentType,e.agent,e.subagent];for(let e of n){if(typeof e!=`string`)continue;let t=e.trim();if(t.length>0)return t}}},rj=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},ij=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(n.includes(`.`)){let e=n.split(`.`).filter(Boolean);return e[e.length-1]??n}return n},aj=e=>{let t=ij(e);return t===`task`||t===`subagent`},oj=e=>{let t=ij(e);return t===`shell`||t===`bash`||t===`cmd`||t===`terminal`},sj=e=>aj(e)||oj(e),cj=e=>{if(!e||typeof e!=`object`)return;let t=e;return rj(t.sessionId)??rj(t.sessionID)},lj=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>e?.type!==`subtask`||e.taskSessionID===t?e:(n=!0,{...e,taskSessionID:t}));return n?r:e},uj=e=>{if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){t.push({tool:`tool`,state:{status:`completed`,title:n}});continue}if(!n||typeof n!=`object`)continue;let e=n;t.push({id:typeof e.id==`string`?e.id:void 0,tool:typeof e.tool==`string`?e.tool:`tool`,state:{status:typeof e.state?.status==`string`?e.state.status:typeof e.status==`string`?e.status:void 0,title:typeof e.state?.title==`string`?e.state.title:typeof e.title==`string`?e.title:void 0,input:e.state?.input&&typeof e.state.input==`object`?e.state.input:void 0}})}return t},dj=e=>{if(typeof e!=`string`||e.trim().length===0)return{summaryEntries:[]};let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);if(!t?.[1])return{summaryEntries:[]};try{let e=JSON.parse(t[1].trim());return{sessionId:rj(e.sessionId)??rj(e.sessionID),status:rj(e.status),summaryEntries:uj(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},fj=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=dj(e);if(t.sessionId)return t.sessionId;let n=e.match(/task_id\s*:\s*([^\s<"']+)/i),r=e.match(/session[_\s-]?id\s*:\s*([^\s<"']+)/i);return rj((n?.[1]??r?.[1])||ej(e))},pj=e=>{let t=e.state;return cj(t?.metadata)??cj(t)??cj(t?.input)??cj(e.metadata)??fj(typeof t?.output==`string`?t.output:void 0)},mj=e=>{if(!(!e||typeof e!=`object`))return rj(e.status)},hj=/"status"\s*:\s*"running"/i,gj=/\bstatus\s*[:=]\s*["'`]?running\b/i,_j=e=>{if(typeof e!=`string`||e.trim().length===0)return!1;let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);return t?.[1]&&hj.test(t[1])?!0:gj.test(e)},vj=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,yj=(e,t)=>rj(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),bj=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},xj=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(vj);if(!t)return;let n=yj(t[1],`sessionID`)??yj(t[1],`sessionId`),r=bj(yj(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:yj(t[1],`description`),body:t[2].trim()}},Sj=/<shell\s+([^>]*?)>([\s\S]*?)<\/shell>/i,Cj=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(Sj);if(!t)return;let n=yj(t[1],`id`),r=bj(yj(t[1],`state`));if(!(!n||!r))return{id:n,state:r,command:yj(t[1],`command`),body:t[2].trim()}},wj=new WeakMap,Tj=e=>{let t=wj.get(e);if(t)return t;let n=[];if(e.info.role===`assistant`)for(let t of e.parts){if(t.type!==`tool`)continue;let e=t.tool?.trim().toLowerCase();if(!e||aj(e)||e===`todowrite`||e===`todoread`)continue;let r=t.state;n.push({id:t.id,tool:t.tool,state:{status:r?.status,title:r?.title,input:r?.input&&typeof r.input==`object`?r.input:void 0}})}return wj.set(e,n),n},Ej=e=>{let t=[];for(let n of e)t.push(...Tj(n));return t},Dj=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),Oj=[`summary`,`changes`,`verification`],kj={summary:`Summary`,changes:`Changes`,verification:`Verification`},Aj=/<(summary|changes|verification)(?:\s[^>]*)?>/i,jj=()=>RegExp(`<(${Oj.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),Mj=e=>typeof e!=`string`||e.length===0?!1:Aj.test(e),Nj=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!Mj(e)?e:e.replace(jj(),(e,t,n)=>{let r=kj[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),Pj=e=>Nj(Dj(e)),Fj=e=>{if(!e.isTaskTool)return{isDelegating:!1,showAvatar:!1,title:e.displayName};let t=e.taskAgentName?e.formatName(e.taskAgentName):void 0,n=!!(e.taskSessionId||t);return!e.isFinalized&&!n?{isDelegating:!0,showAvatar:!1,title:e.delegatingLabel}:{isDelegating:!1,showAvatar:n,title:t??e.displayName}},Ij=e=>{if(!(!e||typeof e!=`object`||Array.isArray(e)))return e},Lj=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},Rj=e=>ij(e.tool??e.name),zj=e=>Ij(e.state),Bj=e=>Ij(zj(e)?.metadata)??Ij(e.metadata),Vj=e=>Ij(zj(e)?.input)??Ij(e.input),Hj=e=>Lj(zj(e)?.status)?.toLowerCase(),Uj=e=>(Array.isArray(e.parts)?e.parts:Array.isArray(e.content)?e.content:[]).filter(e=>!!e&&typeof e==`object`),Wj=e=>{let t=[],n=Lj(Ij(e.metadata)?.text);n&&t.push(n);for(let n of Uj(e)){let e=Lj(n.text);e&&t.push(e)}let r=Lj(e.text);return r&&t.push(r),t},Gj=e=>{let t=Lj(e)?.toLowerCase();if(t===`completed`||t===`error`||t===`cancelled`)return t},Kj=e=>{let t=new Map,n=new Map,r=(e,n)=>{e&&t.set(e,n)},i=(e,t)=>{e&&n.set(e,t)};for(let t of e){let e=Ij(t.metadata),n=Lj(e?.source)?.toLowerCase(),a=Gj(e?.state);n===`shell`&&a&&(r(Lj(e?.shellID),a),r(Lj(e?.jobID),a),r(Lj(e?.id),a)),n===`subagent`&&a&&i(Lj(e?.childID)??Lj(e?.sessionID)??Lj(e?.sessionId),a);for(let e of Wj(t)){let t=Cj(e);t&&(r(t.id,t.state),r(t.shellID,t.state),r(t.jobID,t.state));let n=xj(e);n&&i(n.sessionID,n.state)}}return{byShellOrJobID:t,byChildSessionID:n}},qj=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return t.type!==void 0&&t.type!==`tool`||!sj(Rj(t))||Hj(t)!==`completed`?!1:mj(Bj(t))===`running`||mj(zj(t))===`running`},Jj=e=>{if(!e||typeof e!=`object`)return!1;let t=e;if(t.type!==void 0&&t.type!==`tool`||!sj(Rj(t)))return!1;let n=Hj(t);return n===`running`||n===`pending`||n===`started`},Yj=e=>{if(!e||typeof e!=`object`)return;let t=e,n=Rj(t);if(!sj(n))return;let r=Bj(t),i=Vj(t);if(aj(n)){let e=cj(r)??cj(zj(t))??cj(i),n=Lj(i?.description),a=Lj(i?.agent)??Lj(i?.subagent_type)??Lj(i?.subagentType);return{type:`subagent`,id:e,label:n??e,agent:a}}let a=Lj(r?.shellID)??Lj(zj(t)?.shellID),o=Lj(r?.jobID)??Lj(zj(t)?.jobID),s=Lj(i?.command),c=Lj(t.id);return{type:`shell`,id:a??o??c,label:s??a??o??c}},Xj=e=>{let t=new Set,n=new Set;for(let r of e){let e=Yj(r);e?.id&&(e.type===`subagent`?t:n).add(e.id)}return{childSessionIDs:t,shellIDs:n}},Zj=(e,t,n)=>{if(!n)return;let r=Bj(t),i=zj(t),a=[e.id,Lj(r?.shellID),Lj(r?.jobID),Lj(i?.shellID),Lj(i?.jobID),Lj(t.id)];for(let e of a){if(!e)continue;let t=n.byShellOrJobID.get(e);if(t)return t}},Qj=(e,t)=>{if(!(!t||!e.id))return t.byChildSessionID.get(e.id)},$j=e=>{let{part:t,completions:n,childSessionStatusType:r}=e;if(!t||typeof t!=`object`)return{kind:`settled`};let i=t;if(i.type!==void 0&&i.type!==`tool`||!sj(Rj(i)))return{kind:`settled`};if(Jj(t))return{kind:`blocking`};let a=Yj(t);if(!a)return{kind:`settled`};if(a.type===`shell`){let e=Zj(a,i,n);return e?{kind:`terminal`,state:e}:qj(t)?{kind:`background-running`}:{kind:`settled`}}let o=Lj(r)?.toLowerCase();if(o===`idle`)return{kind:`settled`};if(o===`busy`||o===`retry`)return{kind:`background-running`};let s=Qj(a,n);return s?{kind:`terminal`,state:s}:qj(t)?(a.id,{kind:`background-running`}):{kind:`settled`}},eM=async(e,t)=>{let n=e.trim();if(!n)return{ok:!1,error:`sessionID required`};try{return await t.session.background({sessionID:n}),{ok:!0}}catch(e){return{ok:!1,error:(e instanceof Error?e.message:String(e))||`session.background failed`}}},tM=e=>{if(!e||typeof e!=`object`)return;let t=e;if(!oj(Rj(t)))return;let n=Bj(t),r=zj(t),i=Lj(n?.shellID)??Lj(r?.shellID),a=Lj(n?.jobID)??Lj(r?.jobID),o=Lj(t.id);return{shellID:i,jobID:a,workID:i??a??o}};function nM(e){if(!e.isTaskTool||e.isFinalized)return!1;let t=e.taskSessionId?e.childSessionStatus:e.parentSessionStatus;if(t){if(t.type!==`idle`)return!1;if(typeof e.taskStartedAt==`number`&&typeof e.statusObservedAt==`number`&&e.taskStartedAt<=e.statusObservedAt)return!0}return typeof e.taskStartedAt==`number`&&typeof e.statusSnapshotAt==`number`&&e.taskStartedAt<=e.statusSnapshotAt}var rM=(e,t)=>{if(e===t)return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;let n=e,r=t;return n.input===r.input&&n.output===r.output&&n.reasoning===r.reasoning&&n.cache?.read===r.cache?.read&&n.cache?.write===r.cache?.write},iM=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},aM=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},oM=e=>e?.state,sM=e=>e?.metadata,cM=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},lM=e=>{let t=e;return t?[typeof t.text==`string`?t.text:``,typeof t.content==`string`?t.content:``,typeof t.value==`string`?t.value:``].reduce((e,t)=>t.length>e.length?t:e,``):``},uM=(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.type!==i.type||iM(r)!==iM(i))return!1;if(r.type===`compaction`){let e=r,t=i;if(e.status!==t.status||e.summary!==t.summary||e.reason!==t.reason||e.recent!==t.recent||e.error?.type!==t.error?.type||e.error?.message!==t.error?.message||e.error?.status!==t.error?.status)return!1}if(r.type===`tool`){if(oM(r)!==oM(i)||sM(r)!==sM(i)||aM(r)!==aM(i))return!1;let e=cM(r),t=cM(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=cM(r),o=cM(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(lM(r)!==lM(i))return!1;let e=r.shellAction,t=i.shellAction;if((e||t)&&(e?.command!==t?.command||e?.output!==t?.output||e?.status!==t?.status))return!1}}return!0},dM=(e,t)=>e===t||e.id===t.id&&e.role===t.role&&e.sessionID===t.sessionID&&e.finish===t.finish&&e.status===t.status&&e.error===t.error&&e.mode===t.mode&&e.agent===t.agent&&e.providerID===t.providerID&&e.modelID===t.modelID&&e.variant===t.variant&&e.clientRole===t.clientRole&&e.userMessageMarker===t.userMessageMarker&&(e.time?.created??null)===(t.time?.created??null)&&(e.time?.completed??null)===(t.time?.completed??null)&&e.time?.streamed===t.time?.streamed&&rM(e.tokens,t.tokens),fM=(e,t)=>dM(e.info,t.info)&&uM(e.parts,t.parts),pM=(e,t)=>!e||!t?e===t:fM(e,t),mM=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,hM=(e,t)=>{if(e===t)return!0;if(!e||!t)return!e&&!t;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.file!==i.file||r.additions!==i.additions||r.deletions!==i.deletions)return!1}return!0},gM=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&uM([e.part],[t.part]),_M=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.messageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.messageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!gM(a,o))return!1;r+=1,i+=1}},vM=(e,t)=>{if(e.id!==t.id||e.anchorMessageId!==t.anchorMessageId||e.afterToolPartId!==t.afterToolPartId||e.parts.length!==t.parts.length)return!1;for(let n=0;n<e.parts.length;n+=1)if(!gM(e.parts[n],t.parts[n]))return!1;return!0},yM=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),bM=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.anchorMessageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.anchorMessageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!vM(a,o))return!1;r+=1,i+=1}},xM=(e,t,n,r)=>{if(e===t)return!0;if(!e||!t)return e===t;if(r)return!0;if(e.isGroupExpanded!==t.isGroupExpanded||e.turnId!==t.turnId||e.isFirstAssistantInTurn!==t.isFirstAssistantInTurn||e.isLastAssistantInTurn!==t.isLastAssistantInTurn||e.isLatestTurn!==t.isLatestTurn||e.isWorking!==t.isWorking||e.isTurnSettled!==t.isTurnSettled||e.hasTools!==t.hasTools||e.hasReasoning!==t.hasReasoning||e.userMessageCreatedAt!==t.userMessageCreatedAt||e.userMessageVariant!==t.userMessageVariant||e.assistantTps!==t.assistantTps||(e.headerMessageId===n||t.headerMessageId===n)&&e.headerMessageId!==t.headerMessageId)return!1;let i=e.activityOwnerMessageId===n||t.activityOwnerMessageId===n;if(i&&e.activityOwnerMessageId!==t.activityOwnerMessageId||!_M(e.activityParts,t.activityParts,n))return!1;if((e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&e.activityParts!==t.activityParts){let n=Xj((e.activityParts??[]).map(e=>e.part)),r=Xj((t.activityParts??[]).map(e=>e.part));if(n.childSessionIDs.size!==r.childSessionIDs.size||n.shellIDs.size!==r.shellIDs.size||[...n.childSessionIDs].some(e=>!r.childSessionIDs.has(e))||[...n.shellIDs].some(e=>!r.shellIDs.has(e)))return!1}if(!bM(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=yM(e.activityGroupSegments,n)||yM(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!mM(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!hM(e.changedFiles,t.changedFiles))},SM=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,CM=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,wM=/(?=^diff --git\s+)/gm,TM=/^diff --git\s+/m,EM=/(?=^---\s+\S)/gm,DM=/^---\s+\S/m,OM=e=>typeof e==`object`&&!!e,kM=e=>e.replace(/\r\n/g,`
|
|
6564
6564
|
`).replace(/\r/g,`
|
|
6565
|
-
`).trim(),
|
|
6565
|
+
`).trim(),AM=e=>{let t=!1;return e.split(`
|
|
6566
6566
|
`).map(e=>{if(e.startsWith(`@@`))return t=!0,e;if(t)return e;let n=e.match(/^\s*(---|\+\+\+)\s+(.+)$/);if(!n)return e;let r=n[1],i=n[2]??``;return i.trim()===`/dev/null`?`${r} /dev/null`:`${r} ${i.replace(/\\/g,`/`)}`}).join(`
|
|
6567
|
-
`)},
|
|
6567
|
+
`)},jM=e=>{let t=!1;return e.split(`
|
|
6568
6568
|
`).map(e=>{if(e.startsWith(`@@`))return t=!0,e;if(!t||e.startsWith(`--- `)||e.startsWith(`+++ `)||e.startsWith(`diff --git`))return e;if(e.length===0)return` `;let n=e[0];return n===` `||n===`+`||n===`-`||n===`\\`?e:` ${e}`}).join(`
|
|
6569
|
-
`)},
|
|
6570
|
-
`),n=[...t];for(let e=0;e<t.length;e+=1){let r=(t[e]??``).match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@(.*)$/);if(!r)continue;let i=0,a=0;for(let n=e+1;n<t.length;n+=1){let e=t[n]??``;if(e.startsWith(`@@`)||e.startsWith(`--- `)||e.startsWith(`diff --git`))break;if(!e.startsWith(`\\`)){if(e.startsWith(`+`)){a+=1;continue}if(e.startsWith(`-`)){i+=1;continue}i+=1,a+=1}}n[e]=`@@ -${
|
|
6571
|
-
`)},
|
|
6572
|
-
`)){if(n.startsWith(`@@`)){if(!
|
|
6573
|
-
`),n,r;for(let e of t){let t=e.replace(/\r$/,``),i=t.match(/^@@\s+-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);if(i){let e=Number.parseInt(i[1]??``,10);Number.isFinite(e)&&(n=Math.max(1,e),Number.isFinite(r)||(r=n));continue}if(!(n===void 0||!Number.isFinite(n))&&!(t.startsWith(`+++`)||t.startsWith(`---`)||t.startsWith(`diff `))){if(t.startsWith(`+`))return n;if(t.startsWith(` `)){n+=1;continue}t.startsWith(`-`)||t.startsWith(`\\`)}}return r},
|
|
6569
|
+
`)},MM=(e,t)=>t===1?e:`${e},${t}`,NM=e=>{let t=e.split(`
|
|
6570
|
+
`),n=[...t];for(let e=0;e<t.length;e+=1){let r=(t[e]??``).match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@(.*)$/);if(!r)continue;let i=0,a=0;for(let n=e+1;n<t.length;n+=1){let e=t[n]??``;if(e.startsWith(`@@`)||e.startsWith(`--- `)||e.startsWith(`diff --git`))break;if(!e.startsWith(`\\`)){if(e.startsWith(`+`)){a+=1;continue}if(e.startsWith(`-`)){i+=1;continue}i+=1,a+=1}}n[e]=`@@ -${MM(r[1]??`0`,i)} +${MM(r[2]??`0`,a)} @@${r[3]??``}`}return n.join(`
|
|
6571
|
+
`)},PM=e=>NM(jM(AM(kM(e)))),FM=e=>{if(typeof e==`string`)return/\S/.test(e)?e:void 0;if(OM(e)){let t=e.patch;if(typeof t==`string`)return/\S/.test(t)?t:void 0}},IM=e=>{let t=(e??``).trim().replace(/\t.*$/,``);return!t||t===`/dev/null`?``:t.replace(/^[ab]\//,``)},LM=e=>{let t=e.trim().replace(/\s+/g,`-`);return t.length>0?t:`file`},RM=e=>{let t=!1;for(let n of e.split(`
|
|
6572
|
+
`)){if(n.startsWith(`@@`)){if(!CM.test(n))return!1;t=!0;continue}if(!t||n.length===0)continue;let e=n[0];if(e!==` `&&e!==`+`&&e!==`-`&&e!==`\\`)return!1}return!0},zM=e=>{let t=PM(e);if(!t||SM.test(t)||!CM.test(t)||!RM(t))return null;try{let e=Qn(t,void 0,!0);if(e.length!==1)return null;let n=e[0]?.files??[],r=n[0];return n.length!==1||!r||r.hunks.length===0?null:{patch:t,title:IM(r.name)}}catch{return null}},BM=e=>{let t=TM.test(e),n=DM.test(e);return!t&&!n?[]:e.split(t?wM:EM).map(e=>e.trim()).filter(e=>e.length>0)},VM=(e,t,n,r)=>{let i=PM(e);if(!i)return[];let a=zM(i);if(a){let e=a.title?r(a.title):r(t);return[{id:`${n}-0`,title:e,patch:a.patch,renderMode:`diff`}]}let o=[];for(let e of BM(i)){let i=zM(e),a=i?.title?r(i.title):r(t);if(!i){(CM.test(e)||TM.test(e)||DM.test(e))&&o.push({id:`${n}-${o.length}`,title:a,patch:e,renderMode:`text`});continue}o.push({id:`${n}-${o.length}`,title:a,patch:i.patch,renderMode:`diff`})}if(o.length>0)return o;if(!SM.test(i)&&CM.test(i)){let e=LM(t),a=zM(`--- ${e}\n+++ ${e}\n${i}`);if(a)return[{id:`${n}-0`,title:r(t),patch:a.patch,renderMode:`diff`}]}return[{id:`${n}-0`,title:r(t),patch:i,renderMode:`text`}]},HM=e=>{if(!OM(e))return``;for(let t of[`movePath`,`relativePath`,`filePath`,`file`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return``},UM=e=>{if(!OM(e))return null;let t=FM(e.patch)??FM(e.diff);return t?{patch:t,title:HM(e)}:null},WM=(e,t,n)=>{let r=(Array.isArray(e?.files)?e.files:[]).flatMap((e,t)=>{let r=UM(e);return r?VM(r.patch,r.title||`File ${t+1}`,`file-${t}`,n):[]});return r.length>0?r:VM(typeof t==`string`?t:``,`Diff`,`fallback`,n)},GM=e=>e.trim().replace(/\\/g,`/`).replace(/\/{2,}/g,`/`).replace(/\/+$/,``).replace(/^\.\//,``),KM=(e,t)=>{let n=GM(e),r=GM(t);if(!n||!r)return!1;if(n===r)return!0;let i=n.length>=r.length?n:r,a=n.length>=r.length?r:n;if(!a.includes(`/`))return!1;let o=a.startsWith(`/`)?a:`/${a}`;return i.endsWith(o)},qM=(e,t)=>{if(e.length!==0)return t?e.find(e=>KM(HM(e),t))??(e.length===1?e[0]:void 0):e[0]},JM=(e,t,n,r,i)=>{let a=WM(t,n,i);if(a.length===0||a.some(e=>e.renderMode!==`diff`))return[];let o=Array.isArray(t?.files)?t.files:[];if(e===`apply_patch`){if(o.length>0){let e=o.reduce((e,t)=>UM(t)?e+1:e,0);if(e>0&&e!==o.length)return[]}return new Set(a.map(e=>GM(e.title))).size===a.length?a:[]}let s=a.find(e=>KM(e.title,r))??a[0];return s?[s]:[]},YM=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e));if(typeof e==`string`){let t=Number.parseInt(e,10);if(Number.isFinite(t))return Math.max(0,t)}return null},XM=e=>{let t=0,n=0,r=0;for(let i=0;i<=e.length;i+=1){if(i<e.length&&e.charCodeAt(i)!==10)continue;let a=e.slice(r,i);a.startsWith(`+`)&&!a.startsWith(`+++`)&&(t+=1),a.startsWith(`-`)&&!a.startsWith(`---`)&&(n+=1),r=i+1}return{added:t,removed:n}},ZM=e=>{if(!e?.content||typeof e.content!=`string`)return 0;let t=1;for(let n=0;n<e.content.length;n+=1)e.content.charCodeAt(n)===10&&(t+=1);return t},QM=e=>{if(!OM(e))return{};let t=OM(e.state)?e.state:{};return{metadata:OM(t.metadata)?t.metadata:OM(e.metadata)?e.metadata:void 0,input:OM(t.input)?t.input:void 0}},$M=e=>{let{metadata:t,input:n}=QM(e),r=YM(t?.additions),i=YM(t?.deletions);if(r!==null||i!==null)return{added:r??0,removed:i??0};let a=Array.isArray(t?.files)?t.files:[],o=0,s=0,c=!1;for(let e of a){if(!OM(e))continue;let t=YM(e.additions),n=YM(e.deletions);(t!==null||n!==null)&&(c=!0,o+=t??0,s+=n??0)}if(c)return{added:o,removed:s};let l=FM(t?.patch)??FM(t?.diff);if(l){let e=XM(l);if(e.added>0||e.removed>0)return e}let u=0,d=0;for(let e of a){if(!OM(e))continue;let t=FM(e.patch)??FM(e.diff);if(!t)continue;let n=XM(t);u+=n.added,d+=n.removed}if(u>0||d>0)return{added:u,removed:d};let f=ZM(n);return f>0?{added:f,removed:0}:{added:0,removed:0}},eN=e=>{let t=0,n=0;for(let r of e){let e=$M(r);t+=e.added,n+=e.removed}return{added:t,removed:n}},tN=Z.createContext(!1),nN=()=>Z.useContext(tN),rN=`relative ml-2 pl-3`,iN=(e,t=`default`,n=!1)=>t===`todo`?`relative flex min-w-0 flex-col gap-1 py-0.5`:e?`relative flex min-w-0 flex-col ${n?`gap-0.5`:`gap-1`} py-1`:`relative flex min-w-0 flex-col gap-1 py-1 pr-1 pl-2`,aN=e=>e?`p-0`:`p-1`,oN=`1.25rem`,sN=28,cN=3,lN=4,uN=10,dN=1,fN=4,pN=e=>{let t=(0,Q.c)(17),{size:n,isMobile:r,className:i,label:a}=e,o=r!==void 0&&r,s=a===void 0?``:a,c=n??(o?12:14),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=Array.from({length:9},mN),t[0]=l):l=t[0];let u=l,d;t[1]===i?d=t[2]:(d=Y(`relative block flex-none overflow-clip`,i),t[1]=i,t[2]=d);let f;t[3]===c?f=t[4]:(f={width:c,height:c},t[3]=c,t[4]=f);let p=s?`img`:void 0,m=s||void 0,h=!s||void 0,g=`scale(${c/sN})`,_;t[5]===g?_=t[6]:(_={width:sN,height:sN,transform:g,transformOrigin:`top left`},t[5]=g,t[6]=_);let v;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(v=u.map(hN),t[7]=v):v=t[7];let y;t[8]===_?y=t[9]:(y=(0,$.jsx)(`span`,{className:`pointer-events-none absolute left-0 top-0 block`,style:_,children:v}),t[8]=_,t[9]=y);let b;return t[10]!==y||t[11]!==d||t[12]!==f||t[13]!==p||t[14]!==m||t[15]!==h?(b=(0,$.jsx)(`span`,{className:d,style:f,role:p,"aria-label":m,"aria-hidden":h,children:y}),t[10]=y,t[11]=d,t[12]=f,t[13]=p,t[14]=m,t[15]=h,t[16]=b):b=t[16],b};function mN(e,t){let n=t%cN,r=Math.floor(t/cN),i=n-dN,a=r-dN,o=i===0&&a===0;return{x:n,y:r,isCenter:o,delay:Math.hypot(i,a)*700-(o?180:0)}}function hN(e){let{x:t,y:n,isCenter:r,delay:i}=e;return(0,$.jsx)(`span`,{className:`yuri-lattice-orb-dot absolute block rounded-full bg-current`,"data-center":r?`true`:void 0,style:{left:lN+t*uN,top:lN+n*uN,width:fN,height:fN,transform:`translate(-50%, -50%)`,animationDelay:`${i}ms`}},`${t}-${n}`)}var gN=new Set([`read`,`skill`]),_N=new Set([`task`,`subagent`]),vN=new Set([`read`,`glob`,`grep`,`list`]),yN=new Set([`completed`,`error`,`failed`,`aborted`,`timeout`,`cancelled`]),bN=new Set([`pending`,`started`,`running`]),xN=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(n.includes(`.`)){let e=n.split(`.`).filter(Boolean);return e[e.length-1]??n}return n},SN=e=>!wN(e),CN=e=>_N.has(xN(e)),wN=e=>gN.has(xN(e)),TN=e=>vN.has(xN(e)),EN=e=>xN(e)===`skill`,DN=e=>{let t=xN(e);return!(!t||vN.has(t)||t===`skill`||_N.has(t)||t===`question`||t===`todowrite`||t===`todoread`)},ON=e=>TN(e)||DN(e),kN=e=>{if(!e||typeof e!=`object`)return!1;let t=e.state;if(!t||typeof t!=`object`)return!1;let n=t.status;if(typeof n==`string`){let e=n.trim().toLowerCase();if(bN.has(e))return!1;if(yN.has(e))return!0}let r=t.time;if(!r||typeof r!=`object`)return!1;let i=r.start,a=r.end;return typeof a!=`number`||!Number.isFinite(a)?!1:typeof i!=`number`||!Number.isFinite(i)||a>=i},AN=e=>!kN(e),jN=xN,MN=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,NN=Y(`typography-meta font-medium`,MN),PN=Y(`typography-meta`,MN),FN=`typography-micro !text-[length:calc(var(--text-meta)-0.0625rem)] !leading-5 tracking-normal`,IN=`flex w-full min-w-0 flex-col gap-1`,LN=e=>e.length>0?e.charAt(0).toUpperCase()+e.slice(1):e,RN=new jo({maxEntries:2e3,maxBytes:262144}),zN=(e,t=!0,n=!0)=>{let r=Array.isArray(e?.files)?e?.files:[];if(r.length<=1)return null;let i=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e));if(typeof e==`string`){let t=Number.parseInt(e,10);if(Number.isFinite(t))return Math.max(0,t)}return null},a=(e,t)=>e===null?t:t===null?e:e+t,o=new Map;for(let e of r){let t=e,n=HM(e);if(!n)continue;let r=n.split(`/`).pop()||n,s=i(t.additions),c=i(t.deletions),l=o.get(n);if(l){l.added=a(l.added,s),l.removed=a(l.removed,c);continue}o.set(n,{path:n,name:r,added:s,removed:c})}let s=Array.from(o.values());return(0,$.jsx)($.Fragment,{children:s.map(e=>{let r=e.added!==null||e.removed!==null;return(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 max-w-full items-center gap-1`,PN),style:{color:`var(--tools-description)`},children:[n?(0,$.jsx)(Hh,{filePath:e.path,className:`h-3.5 w-3.5`}):null,(0,$.jsx)(WA,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 max-w-full truncate`,PN),style:{color:`var(--tools-description)`},title:e.path,children:e.name}),r?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,e.added??0]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,e.removed??0]})]}):null]},e.path)})})},BN=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.includes(`.`)?t.split(`.`).filter(Boolean).pop()??t:t;return n===`shell`||n===`cmd`||n===`terminal`?`bash`:n===`patch`?`apply_patch`:n},VN=new Set([`bash`,`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`,`task`]),HN=new Set([`edit`,`multiedit`,`apply_patch`,`write`,`create`,`file_write`]),UN=e=>HN.has(e),WN=e=>e===`write`||e===`create`||e===`file_write`,GN=(e,t,n=Date.now())=>{let r=Math.max(0,(t??n)-e)/1e3;return r>=60?`${Math.floor(r/60)}m ${Math.floor(r%60)}s`:`${(r<.05&&t!==void 0?.1:r).toFixed(1)}s`},KN=e=>{let t=(0,Q.c)(6),{start:n,end:r,active:i}=e,a=QA(i,250),o;t[0]!==r||t[1]!==a||t[2]!==n?(o=GN(n,r,a),t[0]=r,t[1]=a,t[2]=n,t[3]=o):o=t[3];let s;return t[4]===o?s=t[5]:(s=(0,$.jsx)($.Fragment,{children:o}),t[4]=o,t[5]=s),s},qN=e=>{let t=$M({state:{metadata:e}});return t.added===0&&t.removed===0?null:t},JN=e=>{if(!e?.content||typeof e.content!=`string`)return null;let t=1;for(let n=0;n<e.content.length;n+=1)e.content.charCodeAt(n)===10&&(t+=1);return t},YN=e=>{if(!e||typeof e!=`string`)return;let t=e.split(`
|
|
6573
|
+
`),n,r;for(let e of t){let t=e.replace(/\r$/,``),i=t.match(/^@@\s+-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);if(i){let e=Number.parseInt(i[1]??``,10);Number.isFinite(e)&&(n=Math.max(1,e),Number.isFinite(r)||(r=n));continue}if(!(n===void 0||!Number.isFinite(n))&&!(t.startsWith(`+++`)||t.startsWith(`---`)||t.startsWith(`diff `))){if(t.startsWith(`+`))return n;if(t.startsWith(` `)){n+=1;continue}t.startsWith(`-`)||t.startsWith(`\\`)}}return r},XN=(e,t)=>{let n=t.replace(/\r\n/g,`
|
|
6574
6574
|
`);if(!n.trim())return;let r=(()=>{let t=(e??``).trim();return t?t.startsWith(`/`)?t.slice(1):t:`new-file`})(),i=n.split(`
|
|
6575
6575
|
`),a=i.length,o=i.map(e=>`+${e}`).join(`
|
|
6576
6576
|
`);return[`--- /dev/null`,`+++ b/${r}`,`@@ -0,0 +1,${a} @@`,o].join(`
|
|
6577
|
-
`)},
|
|
6578
|
-
`)[0].substring(0,100);if((e.tool===`task`||e.tool===`subagent`)&&a?.description&&typeof a.description==`string`)return a.description.substring(0,80);if(e.tool===`lsp`)return
|
|
6577
|
+
`)},ZN=(e,t,n)=>{if(!t||e!==`edit`&&e!==`multiedit`&&e!==`apply_patch`)return;let r=QN(e,t,n);if(r){let e=YN(r);if(Number.isFinite(e))return e}},QN=(e,t,n)=>{if(!t||e!==`edit`&&e!==`multiedit`&&e!==`apply_patch`)return;let r=Array.isArray(t.files)?t.files:[];if(r.length>0){let e=qM(r,typeof n==`string`&&n.length>0?n:void 0);if(e&&typeof e==`object`){let t=FM(e.patch)??FM(e.diff);if(t)return t}}let i=t.filediff;if(i&&typeof i==`object`){let e=FM(i.patch)??FM(i.diff);if(e)return e}let a=FM(t.patch)??FM(t.diff);if(a)return a},$N=e=>{let t=e.trim().replace(/\\/g,`/`).replace(/\/{2,}/g,`/`);return!t||t===`/`?t:t.replace(/\/+$/,``)},eP=(e,t)=>{let n=$N(e),r=$N(t);if(!n)return``;if(!r)return n;if(n===r)return`.`;let i=`${r}/`;return n.startsWith(i)?n.slice(i.length):n},tP=5,nP=e=>typeof e==`object`&&!!e,rP=e=>{if(!nP(e))return null;let t=typeof e.message==`string`?e.message.trim():``;if(!t)return null;let n=typeof e.severity==`number`&&Number.isFinite(e.severity)?Math.trunc(e.severity):void 0;if(n!==void 0&&n!==1)return null;let r=nP(e.range)?e.range:void 0,i=r&&nP(r.start)?r.start:void 0,a=typeof i?.line==`number`&&Number.isFinite(i.line)?Math.max(0,Math.trunc(i.line)):0,o=typeof i?.character==`number`&&Number.isFinite(i.character)?Math.max(0,Math.trunc(i.character)):0;return{message:t,line:a+1,character:o+1}},iP=(e,t,n)=>{let r=nP(n?.filediff)?n.filediff:void 0,i=nP(r)&&typeof r.file==`string`?r.file:null;if(e===`apply_patch`){let e=HM((Array.isArray(n?.files)?n.files:[]).find(e=>HM(e).length>0));if(e)return e;let t=FM(n?.patch)??FM(n?.diff),r=t?WM(void 0,t,e=>e).find(e=>e.renderMode===`diff`):void 0;return r?.title?r.title:i}return e===`edit`||e===`multiedit`?i||(typeof t?.filePath==`string`?t.filePath:typeof t?.file_path==`string`?t.file_path:typeof t?.path==`string`?t.path:null):e===`write`?typeof t?.filePath==`string`?t.filePath:typeof t?.file_path==`string`?t.file_path:typeof t?.path==`string`?t.path:null:null},aP=(e,t,n,r)=>{if(![`edit`,`multiedit`,`write`,`apply_patch`].includes(e))return null;let i=iP(e,t,n);if(!i||!n||!nP(n.diagnostics))return null;let a=$N(i),o=a.startsWith(`/`)?a:`${$N(r)}/${a}`.replace(/\/+/g,`/`),s=n.diagnostics[a]??n.diagnostics[o];if(!Array.isArray(s))return null;let c=s.map(e=>rP(e)).filter(e=>!!e);if(c.length===0)return null;let l=c.slice(0,tP);return{displayPath:a.startsWith(`/`)?eP(a,r):a,diagnostics:l,remaining:Math.max(0,c.length-l.length)}},oP=()=>{let e=(0,Q.c)(22),t=Ro(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=qs(!1),e[0]=n):n=e[0];let r=n,i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=qs(!0),e[1]=i):i=e[1];let a=i,o;e[2]===t?.availableThemes?o=e[3]:(o=()=>t?.availableThemes??[r,a],e[2]=t?.availableThemes,e[3]=o),t?.availableThemes;let s;e[4]===o?s=e[5]:(s=o(),e[4]=o,e[5]=s);let c=s,l=t?.lightThemeId??r.metadata.id,u=t?.darkThemeId??a.metadata.id,d;e[6]!==c||e[7]!==l?(d=c.find(e=>e.metadata.id===l)??r,e[6]=c,e[7]=l,e[8]=d):d=e[8];let f=d,p;e[9]!==c||e[10]!==u?(p=c.find(e=>e.metadata.id===u)??a,e[9]=c,e[10]=u,e[11]=p):p=e[11];let m=p,h,g;e[12]!==m||e[13]!==f?(h=()=>{Ll(f),Ll(m)},g=[m,f],e[12]=m,e[13]=f,e[14]=h,e[15]=g):(h=e[14],g=e[15]),Z.useEffect(h,g);let _=t?.currentTheme.metadata.variant??`light`,v;e[16]!==m.metadata.id||e[17]!==f.metadata.id?(v={light:f.metadata.id,dark:m.metadata.id},e[16]=m.metadata.id,e[17]=f.metadata.id,e[18]=v):v=e[18];let y=_===`dark`?`dark`:`light`,b;return e[19]!==v||e[20]!==y?(b={pierreTheme:v,pierreThemeType:y},e[19]=v,e[20]=y,e[21]=b):b=e[21],b},sP=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},cP=(e,t,n)=>{let r=t,i=r.metadata,a=r.input;if(e.tool===`apply_patch`){let e=Array.isArray(i?.files)?i?.files:[],t=HM(e[0]);return e.length>1?null:t?eP(t,n):null}if((e.tool===`edit`||e.tool===`multiedit`)&&a){let e=a?.filePath||a?.file_path||a?.path||i?.filePath||i?.file_path||i?.path;if(typeof e==`string`)return eP(e,n)}if(e.tool===`read`&&a){let e=a?.filePath||a?.file_path||a?.path||i?.filePath||i?.file_path||i?.path;if(typeof e==`string`)return eP(e,n)}if([`write`,`create`,`file_write`].includes(e.tool)&&a){let e=a?.filePath||a?.file_path||a?.path;if(typeof e==`string`)return eP(e,n)}if(e.tool===`lsp`&&a){let e=a?.filePath||a?.file_path||a?.path;if(typeof e==`string`)return eP(e,n)}return null},lP=(e,t)=>{if(!e)return``;let n=typeof e.operation==`string`?e.operation:`lsp`;if(n===`workspaceSymbol`)return`${n}${typeof e.query==`string`&&e.query.trim().length>0?` "${e.query.trim()}"`:``}`;let r=typeof e.filePath==`string`?e.filePath:typeof e.file_path==`string`?e.file_path:typeof e.path==`string`?e.path:``,i=r?eP(r,t):``;if(n===`documentSymbol`)return i?`${n} ${i}`:n;let a=typeof e.line==`number`&&Number.isFinite(e.line)?Math.trunc(e.line):void 0,o=typeof e.character==`number`&&Number.isFinite(e.character)?Math.trunc(e.character):void 0,s=a!==void 0&&o!==void 0?`:${a}:${o}`:``;return i?`${n} ${i}${s}`:n},uP=(e,t,n)=>{let r=t,i=r.metadata,a=r.input,o=cP(e,t,n);if(o)return o;if(e.tool===`apply_patch`){let e=Array.isArray(i?.files)?i?.files:[];return e.length>1?`${e.length} files`:``}if(e.tool===`question`&&a?.questions&&Array.isArray(a.questions)){let e=a.questions.length;return`Asked ${e} question${e===1?``:`s`}`}if(e.tool===`bash`&&a?.command&&typeof a.command==`string`)return a.command.split(`
|
|
6578
|
+
`)[0].substring(0,100);if((e.tool===`task`||e.tool===`subagent`)&&a?.description&&typeof a.description==`string`)return a.description.substring(0,80);if(e.tool===`lsp`)return lP(a,n);let s=a?.description||i?.description||`title`in t&&t.title||``;return typeof s==`string`?s:``},dP=e=>{let t=(0,Q.c)(17),{children:n,isMobile:r,maxHeightClass:i,className:a,outerClassName:o,disableHorizontal:s}=e,c=r!==void 0&&r,l=i===void 0?`max-h-[60vh]`:i,u=s!==void 0&&s,d;t[0]===o?d=t[1]:(d=Y(`w-full min-w-0 flex-none overflow-hidden`,o),t[0]=o,t[1]=d);let f;if(t[2]!==a||t[3]!==u||t[4]!==c||t[5]!==l){let e;t[7]===c?e=t[8]:(e=c&&aN(!0),t[7]=c,t[8]=e),f=Y(`tool-output-surface rounded-xl w-full min-w-0`,aN(c),l,u?`overflow-y-auto overflow-x-hidden`:`overflow-auto`,a,e),t[2]=a,t[3]=u,t[4]=c,t[5]=l,t[6]=f}else f=t[6];let p;t[9]===n?p=t[10]:(p=(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:n}),t[9]=n,t[10]=p);let m;t[11]!==f||t[12]!==p?(m=(0,$.jsx)(ud,{className:f,children:p}),t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==d||t[15]!==m?(h=(0,$.jsx)(`div`,{className:d,children:m}),t[14]=d,t[15]=m,t[16]=h):h=t[16],h},fP=(e,t,n,r)=>t.tool===`bash`?`bash`:Id(Md(e,t.tool,n),t.tool,r),pP=(e,t,n)=>t.tool===`bash`?e:Md(e,t.tool,n),mP=e=>{let t=(0,Q.c)(25),{output:n,part:r,metadata:i,input:a,isMobile:o}=e,s=o!==void 0&&o,c;t[0]!==i||t[1]!==n||t[2]!==r?(c=pP(n,r,i),t[0]=i,t[1]=n,t[2]=r,t[3]=c):c=t[3];let l=c,u;t[4]!==r.tool||t[5]!==l?(u=r.tool===`bash`?l.replace(/[\r\n]+$/,``):l,t[4]=r.tool,t[5]=l,t[6]=u):u=t[6];let d=u,f;t[7]!==a||t[8]!==i||t[9]!==n||t[10]!==r?(f=fP(n,r,i,a),t[7]=a,t[8]=i,t[9]=n,t[10]=r,t[11]=f):f=t[11];let p=f;if(Ld(l).isJson){let e;return t[12]!==s||t[13]!==l?(e=(0,$.jsx)(GA,{output:l,isMobile:s}),t[12]=s,t[13]=l,t[14]=e):e=t[14],e}let m=r.tool===`bash`?`typography-code text-muted-foreground/90`:void 0,h;t[15]!==s||t[16]!==r.tool?(h={...TP,...s&&r.tool===`bash`?{lineHeight:oN}:{}},t[15]=s,t[16]=r.tool,t[17]=h):h=t[17];let g;t[18]!==d||t[19]!==p||t[20]!==h?(g=(0,$.jsx)(Fd,{language:p,code:d,style:h,codeStyle:EP.style,wrap:!0}),t[18]=d,t[19]=p,t[20]=h,t[21]=g):g=t[21];let _;return t[22]!==m||t[23]!==g?(_=(0,$.jsx)(`div`,{className:m,children:g}),t[22]=m,t[23]=g,t[24]=_):_=t[24],_};mP.displayName=`ToolScrollableTextOutput`;var hP=e=>{let t=e.state?.title;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.state?.input;if(n&&typeof n==`object`){let e=n.filePath??n.file_path??n.path;if(typeof e==`string`&&e.trim().length>0)return e.trim();let t=n.url;if(typeof t==`string`&&t.trim().length>0)return t.trim()}return``},gP=new Set([`read`,`view`,`file_read`,`cat`,`write`,`create`,`file_write`,`edit`,`multiedit`,`apply_patch`]),_P=(e,t)=>{if(!gP.has(e.toLowerCase()))return!1;let n=t.trim();if(!n||n===`Patch`||/^\d+\s+files$/.test(n))return!1;if(n.includes(`/`)||n.includes(`\\`))return!0;let r=n.split(/[\\/]/).pop()||n;return r.startsWith(`.`)||r.includes(`.`)?!0:/^[A-Za-z0-9_-]+$/.test(r)},vP=e=>{let t=BN(e.tool),n=e.state?.status??``,r=hP(e);return`${e.id??``}\u0001${t}\u0001${n}\u0001${r}`},yP=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(vP(e[n])!==vP(t[n]))return!1;return!0},bP=Z.memo(e=>{let t=(0,Q.c)(10),{entry:n,isMobile:r,animateTailText:i,showToolFileIcons:a}=e,{t:o}=fr(),s;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==o){let e=BN(n.tool),c=e.length>0?e:`tool`,l=hP(n),u=l.trim().length>0,d=n.state?.status,f=Mu(c,o),p=r?`items-start`:`items-center`,m;t[6]===p?m=t[7]:(m=Y(`flex gap-1.5 min-w-0 w-full py-px`,p),t[6]=p,t[7]=m);let h,g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=Y(FN,`text-foreground/80 flex-shrink-0`),g={color:`var(--tools-title)`},t[8]=h,t[9]=g):(h=t[8],g=t[9]),s=(0,$.jsxs)(`div`,{className:m,children:[(0,$.jsx)(`span`,{className:`flex-shrink-0 scale-90 text-foreground/80`,children:JA(c)}),(0,$.jsx)(`span`,{className:h,style:g,title:f,children:f}),u?d!==`error`&&_P(c,l)?MP(l,i,!0,a,FN):d===`error`?(0,$.jsx)(`span`,{className:Y(FN,`flex-1 min-w-0 text-[var(--status-error)]`,r?`whitespace-normal break-words`:`truncate`),children:l}):(0,$.jsx)(WA,{variant:i?`generate-effect`:`static`,className:Y(FN,`flex-1 min-w-0 text-muted-foreground/70`,r?`whitespace-normal break-words`:`truncate`),style:{color:`var(--tools-description)`},title:l,children:l}):null]}),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o,t[5]=s}else s=t[5];return s},(e,t)=>e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&vP(e.entry)===vP(t.entry));bP.displayName=`TaskSummaryEntryRow`;var xP=Z.memo(e=>{let t=(0,Q.c)(24),{entries:n,isExpanded:r,isMobile:i,animateTailText:a,showToolFileIcons:o}=e,s;t[0]!==n||t[1]!==r?(s=r?n:n.slice(-6),t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=s,l=Math.max(0,n.length-c.length),u=n.length-c.length,d=r?`max-h-[40vh]`:`max-h-56`,f;t[3]===l?f=t[4]:(f=l>0?(0,$.jsxs)(`div`,{className:Y(FN,`text-muted-foreground/70`),children:[`+`,l,` more…`]}):null,t[3]=l,t[4]=f);let p;if(t[5]!==a||t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==c||t[10]!==u){let e;t[12]!==a||t[13]!==r||t[14]!==i||t[15]!==o||t[16]!==u?(e=(e,t)=>{let n=r?t:u+t,s=e.id??`${vP(e)}:${n}`;return(0,$.jsx)(bP,{entry:e,isMobile:i,animateTailText:a,showToolFileIcons:o},s)},t[12]=a,t[13]=r,t[14]=i,t[15]=o,t[16]=u,t[17]=e):e=t[17],p=c.map(e),t[5]=a,t[6]=r,t[7]=i,t[8]=o,t[9]=c,t[10]=u,t[11]=p}else p=t[11];let m;t[18]!==f||t[19]!==p?(m=(0,$.jsxs)(`div`,{className:IN,children:[f,p]}),t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==d||t[22]!==m?(h=(0,$.jsx)(dP,{maxHeightClass:d,disableHorizontal:!0,children:m}),t[21]=d,t[22]=m,t[23]=h):h=t[23],h},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&yP(e.entries,t.entries));xP.displayName=`TaskSummaryEntriesList`;var SP=e=>{let t=(0,Q.c)(44),{entries:n,isExpanded:r,isMobile:i,output:a,sessionId:o,onShowPopup:s,input:c,animateTailText:l,isActive:u}=e,d=l===void 0||l,f=u!==void 0&&u,{t:p}=fr(),m=Nu(),h=Wa(BP),g=q(VP),_=q(HP),v=Z.useContext(Pn),y=Zb(),b=y.directory||m,x;t[0]===a?x=t[1]:(x=typeof a==`string`?Pj(a):``,t[0]=a,t[1]=x);let S=x,C=S.length>0,[w,T]=Z.useState(!1),E,D,O,k;if(t[2]!==d||t[3]!==b||t[4]!==n||t[5]!==C||t[6]!==c||t[7]!==f||t[8]!==r||t[9]!==i||t[10]!==g||t[11]!==v?.runtime||t[12]!==o||t[13]!==y||t[14]!==h||t[15]!==_||t[16]!==p){k=Symbol.for(`react.early_return_sentinel`);bb0:{let e=LN(nj(c)??`subagent`),a=t=>{t.stopPropagation(),o&&b&&$b(y,o,b,()=>{if(!Zi({sessionId:o,directory:b})){if(Zs()||i||v?.runtime.isVSCode){h(o,b);return}g(b,{mode:`chat`,dedupeKey:`session:${o}`,label:e,readOnly:!0})}})};if(n.length===0&&!C&&!o){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(FN,`text-muted-foreground/70`),t[21]=e):e=t[21];let n=f?`Waiting for subagent activity...`:`No subagent session id on task metadata.`,r;t[22]===n?r=t[23]:(r=(0,$.jsx)(`div`,{className:`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,children:(0,$.jsx)(`div`,{className:e,children:n})}),t[22]=n,t[23]=r),k=r;break bb0}t[24]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,`before:absolute before:left-[0.4375rem] before:w-px before:bg-border/80 before:content-[""]`,`before:top-0 before:bottom-0`),t[24]=E):E=t[24],t[25]!==d||t[26]!==n||t[27]!==r||t[28]!==i||t[29]!==_?(D=n.length>0?(0,$.jsx)(xP,{entries:n,isExpanded:r,isMobile:i,animateTailText:d,showToolFileIcons:_}):null,t[25]=d,t[26]=n,t[27]=r,t[28]=i,t[29]=_,t[30]=D):D=t[30],O=o&&y.capabilities.navigateNestedSession&&(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-primary hover:text-primary/80 w-full`,FN),onPointerDown:UP,onClick:a,children:[(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(FN,`text-primary font-medium`),children:p(`chat.toolPart.openSubtask`,{type:e})})]})}t[2]=d,t[3]=b,t[4]=n,t[5]=C,t[6]=c,t[7]=f,t[8]=r,t[9]=i,t[10]=g,t[11]=v?.runtime,t[12]=o,t[13]=y,t[14]=h,t[15]=_,t[16]=p,t[17]=E,t[18]=D,t[19]=O,t[20]=k}else E=t[17],D=t[18],O=t[19],k=t[20];if(k!==Symbol.for(`react.early_return_sentinel`))return k;let A;t[31]!==n.length||t[32]!==C||t[33]!==w||t[34]!==s||t[35]!==o||t[36]!==p||t[37]!==S?(A=C?(0,$.jsxs)(`div`,{className:Y(`flex flex-col gap-1`,(n.length>0||o)&&`pt-1`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-foreground/80 hover:text-foreground w-full`,FN),onPointerDown:WP,onClick:e=>{e.stopPropagation(),T(GP)},children:[w?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(FN,`text-foreground/80 font-medium`),children:p(`chat.toolPart.output`)})]}),w?(0,$.jsx)(dP,{maxHeightClass:`max-h-[50vh]`,children:(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(nc,{content:S,variant:`tool`,onShowPopup:s})})}):null]}):null,t[31]=n.length,t[32]=C,t[33]=w,t[34]=s,t[35]=o,t[36]=p,t[37]=S,t[38]=A):A=t[38];let j;return t[39]!==E||t[40]!==D||t[41]!==O||t[42]!==A?(j=(0,$.jsxs)(`div`,{className:E,children:[D,O,A]}),t[39]=E,t[40]=D,t[41]=O,t[42]=A,t[43]=j):j=t[43],j},CP=`
|
|
6579
6579
|
[data-diff-header],
|
|
6580
6580
|
[data-diff] {
|
|
6581
6581
|
[data-separator] {
|
|
6582
6582
|
height: 24px !important;
|
|
6583
6583
|
}
|
|
6584
6584
|
}
|
|
6585
|
-
`,SP={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},CP={...wn.getCollapsedStyles(),padding:0,overflow:`visible`},wP={style:{background:`transparent`,backgroundColor:`transparent`}},TP={color:`var(--status-error)`},EP={color:`var(--tools-icon)`},DP={color:`var(--status-error)`},OP={color:`var(--tools-title)`},kP=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate typography-ui-label text-foreground`,t&&`flex-1`),style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},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 flex items-baseline overflow-hidden typography-ui-label`,t&&`flex-1`),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0 text-muted-foreground`,children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i})]})]})},AP=(e,t=!0,n=!0,r=!0,i=MN)=>{let a=e.lastIndexOf(`/`),o=i===NN?`h-3 w-3 flex-shrink-0`:`h-3.5 w-3.5 flex-shrink-0`;if(a===-1)return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(Hh,{filePath:e,className:o}):null,(0,$.jsx)(HA,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 truncate whitespace-nowrap`,i,n&&`flex-1`),style:{color:`var(--tools-description)`},children:e})]});let s=e.slice(0,a),c=e.slice(a+1),l=s.startsWith(`/`),u=l?s.slice(1):s;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(Hh,{filePath:e,className:o}):null,(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full items-baseline overflow-hidden`,i,n&&`flex-1`),children:[l?(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:u}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(HA,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:c})]})]})},jP=e=>{let t=(0,Q.c)(3),{diff:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={backgroundColor:`var(--syntax-base-background)`,color:`var(--syntax-base-foreground)`},t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`pre`,{className:`m-0 overflow-auto whitespace-pre-wrap break-words rounded-lg p-2 typography-code`,style:r,children:n}),t[1]=n,t[2]=i),i},MP=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1})}componentDidCatch(e){}render(){return this.state.hasError?this.props.fallback:this.props.children}},NP=Z.memo(e=>{let t=(0,Q.c)(13),{diff:n,pierreTheme:r,pierreThemeType:i,diffViewMode:a}=e,o=a===`side-by-side`?`split`:`unified`,s;t[0]!==r||t[1]!==i||t[2]!==o?(s={diffStyle:o,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:`wrap`,theme:r,themeType:i,unsafeCSS:xP},t[0]=r,t[1]=i,t[2]=o,t[3]=s):s=t[3];let c=s,l;t[4]===n?l=t[5]:(l=(0,$.jsx)(jP,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)(Zn,{patch:n,metrics:SP,options:c,className:`block w-full`}),t[6]=n,t[7]=c,t[8]=d):d=t[8];let f;return t[9]!==n||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0`,children:(0,$.jsx)(MP,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});NP.displayName=`DiffPreview`;var PP=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=fr(),{pierreTheme:s,pierreThemeType:c}=iP(),[l,u]=Z.useState(`unified`),d=t,f=d.metadata,p=d.input,m=d.output,h=typeof m==`string`&&m.length>0,g=typeof m==`string`?m:``,_=eP(f?.filediff)?f.filediff:void 0,v=NM(f?.patch)??NM(f?.diff)??NM(_?.patch)??NM(_?.diff)??null,y=Z.useMemo(()=>HM(f,v??void 0,e=>QN(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>rP(e.tool,p,f,n),[n,p,f,e.tool]),S=Z.useMemo(()=>!p||typeof p!=`object`||Object.keys(p).length===0?``:`command`in p&&typeof p.command==`string`&&e.tool===`bash`?Rd(p,e.tool):typeof p.content==`string`?p.content??``:Rd(p,e.tool),[p,e.tool]),C=!b&&S.trim().length>0,w=e.tool===`write`||e.tool===`create`||e.tool===`file_write`,T=e.tool===`todowrite`||e.tool===`todoread`,E=Z.useMemo(()=>Array.isArray(p?.todos)?JSON.stringify(p.todos):g,[p?.todos,g]),D=Z.useMemo(()=>!w||!C?void 0:JN(typeof p?.filePath==`string`?p.filePath:typeof p?.file_path==`string`?p.file_path:typeof p?.path==`string`?p.path:void 0,S),[C,p?.filePath,p?.file_path,p?.path,S,w]);Z.useEffect(()=>{u(`unified`)},[e.id]);let O=(e,t)=>(0,$.jsx)(lP,{isMobile:i,maxHeightClass:t?.maxHeightClass,className:t?.className,disableHorizontal:t?.disableHorizontal,outerClassName:t?.outerClassName,children:e}),k=()=>{let n=()=>x?(0,$.jsxs)(`div`,{className:`tool-output-surface flex flex-col gap-2 rounded-xl border p-2`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--status-error-background)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium`,style:{color:`var(--status-error)`},children:o(`chat.toolPart.lspErrors`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 min-w-0`,children:kP(x.displayPath,!1)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:x.diagnostics.map((e,t)=>(0,$.jsx)(`div`,{className:`rounded-md border px-2 py-1`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--surface-elevated)`},children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`typography-micro shrink-0`,style:{color:`var(--status-error)`},children:[`[`,e.line,`:`,e.character,`]`]}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground whitespace-pre-wrap break-words`,children:e.message})]})},`${x.displayPath}:${e.line}:${e.character}:${t}`))}),x.remaining>0?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:o(`chat.toolPart.moreErrors`,{count:x.remaining})}):null]})]}):null;if(e.tool===`question`){if(t.status===`completed`&&h){let e=aP(g);if(e&&e.length>0)return O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.question}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground whitespace-pre-wrap`,children:e.answer})]},t))}),{maxHeightClass:`max-h-[40vh]`})}if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:zd(t.error)})]});let e=p;return e?.questions&&Array.isArray(e.questions)&&e.questions.length>0?O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.questions.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[e.header?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:zd(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:zd(e.question)}),Array.isArray(e.options)&&e.options.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:e.options.map(e=>(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-muted/30 border border-border/30 text-muted-foreground`,children:zd(e.label)},zd(e.label)))}):null]},t))}),{maxHeightClass:`max-h-[40vh]`}):(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:o(`chat.toolPart.awaitingResponse`)})}return(e.tool===`task`||e.tool===`subagent`)&&h?O((0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(nc,{content:zd(g),variant:`tool`,onShowPopup:a})})):(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`||e.tool===`write`)&&(y.length>0||x)?O((0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[y.map(e=>(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:e.renderMode===`diff`?(0,$.jsx)(NP,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(jP,{diff:e.patch})},e.id)),n()]}),{className:`p-1`}):e.tool===`write`&&x?O((0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:n()}),{className:`p-1`}):w?null:h&&g.trim()?O((0,$.jsx)(fP,{output:zd(g),part:e,metadata:f,input:p,isMobile:i}),{className:e.tool===`bash`?`p-1 rounded-none`:`p-1`,maxHeightClass:e.tool===`bash`?`max-h-[46vh]`:void 0}):O((0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground/70`,children:o(`chat.toolPart.noOutputProduced`)}),{maxHeightClass:`max-h-60`})};if(T){if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:nN(i,`todo-error`),children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-none border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:t.error})]});let n=Nd(E,void 0,{listClassName:db});return(0,$.jsx)(`div`,{className:nN(i,`todo`),children:O(n??(0,$.jsx)(fP,{output:E,part:e,metadata:f,input:p,isMobile:i}),fb)})}return(0,$.jsx)(`div`,{className:nN(i,`default`,e.tool===`bash`),children:e.tool===`question`?k():(0,$.jsxs)($.Fragment,{children:[C?(0,$.jsx)(`div`,{children:O(e.tool===`bash`?(0,$.jsx)(`pre`,{className:`tool-input-text whitespace-pre-wrap break-words typography-code text-muted-foreground/90 m-0 p-0`,style:i?{lineHeight:iN}:void 0,children:S}):w&&D?(0,$.jsx)(NP,{diff:D,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(`blockquote`,{className:`tool-input-text m-0 whitespace-pre-wrap break-words typography-meta italic text-muted-foreground/70`,children:S}),{maxHeightClass:w&&D&&r?`max-h-[50vh]`:`max-h-60`,className:e.tool===`bash`?`tool-input-surface p-0 rounded-none`:`tool-input-surface`})}):null,t.status===`completed`&&`output`in t&&(0,$.jsx)(`div`,{children:k()}),t.status===`error`&&`error`in t&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:zd(t.error)})]})]})})});PP.displayName=`ToolExpandedContent`;var FP=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:s=!0})=>{let c=e.state,l=q(e=>e.showToolFileIcons),u=q(e=>e.showSubagentTaskDetails),d=q(e=>e.openContextPanelTab),f=q(e=>e.openContextDiff),p=q(e=>e.openContextToolDiff),m=q(e=>e.navigateToDiff),{t:h}=fr(),g=Nu(),_=Wa(e=>e.setCurrentSession),v=fc(),y=Zb(),b=y.directory||g||``,x=RN(e.tool),S=rj(x||e.tool),C=ij(x||e.tool),w=aj(x||e.tool),T=x===`todowrite`||x===`todoread`,E=VN(x),D=c?.status,O=DN(e),k=D===`error`||D===`failed`,[A,j]=Z.useState(!O),M=Z.useRef(e.id),N=Z.useRef(``);Z.useEffect(()=>{M.current!==e.id&&(M.current=e.id,N.current=``,j(!O))},[O,e.id]),Z.useEffect(()=>{O||j(!0)},[O]),Z.useEffect(()=>{if(!O||k||!b||!zN.has(x))return;let t=`${e.id}:${D??`unknown`}`;N.current!==t&&(N.current=t,sa.requestGitRefresh({directory:b}))},[b,k,O,x,e.id,D]);let P=O||S,F=Z.useRef(a);F.current=a;let I=Z.useRef(null);Z.useLayoutEffect(()=>{if(S||E)return;let e=I.current;if(!e){P&&F.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,P&&F.current?.(`structural`)},[n,E,S,P]);let L=c,R=L.metadata,z=e.metadata,B=L.input,V=L.time,H=Z.useMemo(()=>{let e=B?.todos;if(!T||!Array.isArray(e))return null;let t=e.filter(e=>!!e&&typeof e==`object`&&typeof e.status==`string`);return t.length===0?null:{done:t.filter(e=>e.status===`completed`).length,total:t.length}},[B,T]),U=typeof V?.start==`number`&&Number.isFinite(V.start)?V.start:void 0,W=Z.useMemo(()=>typeof L.output==`string`?L.output:void 0,[L.output]),ee=Z.useMemo(()=>lj(W),[W]),te=Z.useMemo(()=>{if(!S)return[];let e=R,t=cj(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:ee.summaryEntries},[S,R,ee.summaryEntries]),G=O&&te.length>0,ne=Z.useMemo(()=>S?oj(R)||oj(L)||oj(B)||oj(z)||(ee.sessionId?ee.sessionId:uj(W)):void 0,[B,S,R,ee.sessionId,z,L,W]),re=Z.useMemo(()=>!O||!w?!1:!!(Gj(e)||fj(R)===`running`||fj(L)===`running`||fj(z)===`running`||S&&(ee.status===`running`||hj(W))),[w,O,S,R,ee.status,e,z,L,W]),ie=!!(S&&re),ae=!!(C&&re),[oe,se]=Z.useState(!0),ce=Zr(S?ne??``:``),le=typeof e.sessionID==`string`?e.sessionID.trim():``,ue=!!(w&&re&&(S?!ce:oe)&&le),de=ca(ue?le:``,b),fe=Z.useMemo(()=>ue?Wj(de):void 0,[de,ue]),pe=S&&!O&&A,me=pe?ne:void 0,he=pe&&!ne?e.sessionID:void 0,ge=me??he,_e=Fa(he??``,b),ve=Sa(ge??``,b),ye=va(b,pe),be=Z.useMemo(()=>Zj({part:e,completions:fe,childSessionStatusType:ce?.type}),[fe,ce?.type,e]);Z.useEffect(()=>{C&&be.kind===`terminal`&&se(!1)},[be.kind,C]);let xe=!!(S&&!k&&(ce?.type===`busy`||ce?.type===`retry`||ie&&be.kind===`background-running`)&&ne),Se=!!(C&&ae&&oe&&!k&&be.kind===`background-running`&&$j(e)?.workID),Ce=Kj(e),[we,Te]=Z.useState(!1),Ee=J(async()=>{if(!Ce||we)return;let t=typeof e.sessionID==`string`?e.sessionID.trim():``;if(!t){no.error(h(`chat.sessionBackground.moveFailed`));return}Te(!0);try{let e=await Qj(t,Kt.getSdkClient());e.ok||no.error(h(`chat.sessionBackground.moveFailed`),{description:e.error})}finally{Te(!1)}}),De=!u||G?``:ne??``,Oe=ca(De,b);Lr(De,b);let ke=Z.useMemo(()=>!S||!ne||!Array.isArray(Oe)||Oe.length===0?[]:wj(Oe),[Oe,S,ne]),Ae=O&&typeof V?.end==`number`&&Number.isFinite(V.end)?V.end:void 0,je=!O&&A,Me=eM({isTaskTool:S,isFinalized:O,taskSessionId:ne,childSessionStatus:ce,parentSessionStatus:_e,statusObservedAt:ve,taskStartedAt:U,statusSnapshotAt:ye}),Ne=je&&!Me||xe||Se,Pe=!!(S&&Ne&&!k);Z.useEffect(()=>{Me&&j(!1)},[Me]);let Fe=O,Ie=Z.useMemo(()=>ke.length>0?ke:te,[ke,te]),Le=Z.useMemo(()=>Ie.map(gP).join(`\0`),[Ie]),Re=Z.useRef(null);Z.useEffect(()=>{if(!S){Re.current=null;return}let e=Re.current;Re.current=Le,e!==null&&e!==Le&&Ie.length!==0&&F.current?.(`structural`)},[S,Ie.length,Le]);let ze=Z.useMemo(()=>x===`edit`||x===`multiedit`||x===`apply_patch`?GN(R):null,[R,x]),Be=Z.useMemo(()=>x===`write`?KN(B):null,[B,x]),Ve=x===`apply_patch`&&Array.isArray(R?.files)&&(R?.files).length>1,He=x===e.tool?e:{...e,tool:x},Ue=oP(He,c,b),We=cP(He,c,b),Ge=Mu(x||e.tool,h),Ke=hr(S?ne:void 0,b),qe=hr(S?ne:void 0),Je=Nj({isTaskTool:S,isFinalized:O,taskSessionId:ne,taskAgentName:S?ej(B,R,z,Ke??qe):void 0,displayName:Ge,delegatingLabel:h(`chat.assistantStatus.delegatingTask`),formatName:FN}),Ye=S&&Je.isDelegating,Xe=Je.title,Ze=typeof e.sessionID==`string`?e.sessionID.trim():``,Qe=Z.useMemo(()=>{if(!S||!Ze)return null;let n=typeof ne==`string`&&ne.trim().length>0?ne.trim():void 0,r=typeof e.id==`string`&&e.id.trim().length>0?e.id.trim():void 0,i=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():typeof t==`string`&&t.trim().length>0?t.trim():void 0;return{sessionID:Ze,...r?{partID:r}:{},...i?{messageID:i}:{},...b?{directory:b}:{},directoryPresent:!!b,childSessionPresent:!!n,...n?{childSessionID:n}:{},...D?{toolStatus:D}:{},finalized:O,backgroundRunning:xe,effectiveActive:Ne,suppressLoading:Me,delegating:Ye,childStatus:co(ce),parentStatus:co(_e),idleConfirmed:ce?.type===`idle`,navigateCapability:y.capabilities.navigateNestedSession,surfaceKind:y.kind,...typeof U==`number`?{taskStartedAt:U}:{},...typeof ve==`number`?{statusObservedAt:ve}:{},...typeof ye==`number`?{statusSnapshotAt:ye}:{}}},[ce,b,Ne,U,Ye,O,S,t,Ze,_e,e.id,e.messageID,y.capabilities.navigateNestedSession,y.kind,D,ve,ye,Me,xe,ne]),$e=Qe?Nr(Qe):``,et=Z.useRef(Qe);et.current=Qe,Z.useEffect(()=>{let e=et.current;!e||!$e||_o(e)},[$e]);let tt=J((e,t)=>{let n=et.current;n&&io({...n,opened:e,clickSource:t})}),nt=Ye?{"data-delegating":`true`}:void 0,rt=Z.useMemo(()=>{if(x===`bash`||x===`apply_patch`||x===`lsp`||Ue&&(x===`apply_patch`||x===`edit`||x===`multiedit`||x===`write`))return null;let e=L.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=B?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Ue,x,L,B]),it=Z.useContext(Pn),at=Z.useRef(!1),ot=J(e=>{let t=e??ne;return!t||!b?!1:(at.current=!1,$b(y,t,b,()=>{if(!Zi({sessionId:t,directory:b})){if(i||it?.runtime.isVSCode){_(t,b);return}d(b,{mode:`chat`,dedupeKey:`session:${t}`,label:Xe,readOnly:!0})}}))});Z.useEffect(()=>{!at.current||!ne||tt(ot(ne),`queued-effect`)},[ne]);let st=n=>{if(S){n.stopPropagation();let e=y.capabilities.navigateNestedSession,t=e?ot():!1;tt(t,`row`),e&&!t&&(at.current=!0);return}if(E&&!b)return;let a,o,s;if(x===`edit`||x===`multiedit`||x===`apply_patch`)a=nP(x,B,R),o=YN(x,R,typeof a==`string`?a:void 0),typeof a==`string`&&(s=XN(x,R,a));else if([`write`,`create`,`file_write`].includes(x))a=B?.filePath||B?.file_path||B?.path||R?.filePath||R?.file_path||R?.path,o=1,typeof a==`string`&&typeof B?.content==`string`&&(s=JN(a,B.content));else if(x===`lsp`){a=B?.filePath||B?.file_path||B?.path;let e=B?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=Hn(b,a)||(a.startsWith(`/`)?a:b.endsWith(`/`)?b+a:`${b}/${a}`);if(E){let e=QN(r,b),n=Bn(r,b),a=n?e:r,c=s?KM(x,R,s,a,e=>QN(e,b)):[],l=(HN(x)||!n)&&c.length===1&&c[0]?[{path:a,patch:c[0].patch}]:c.map(e=>({path:e.title,patch:e.patch}));if(it?.runtime.isVSCode&&it.editor&&s){let e=`${a} (changes)`;it.editor.openDiff(``,r,e,{line:o,patch:s});return}if(l.length>0||n){v?l.length>0?v.openToolDiff({diffPath:a,patches:l,targetLine:o}):x===`apply_patch`?v.openTurnDiff(t,y.sessionId):v.openChanges({diffPath:e,staged:!1,targetLine:o}):i&&l.length===0?m(e,!1,HN(x)?`working`:`turn`,o):l.length>0?p(b,a,l,o,t,y.sessionId):f(b,e,!1,HN(x)?`working`:`turn`,o,t,y.sessionId);return}if(it?.editor){it.editor.openFile(r,o);return}kA(r,b).then(()=>{let e=q.getState(),t=Un(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(x===`lsp`){if(it?.editor){it.editor.openFile(r,o);return}let e=()=>{let e=q.getState(),t=Un(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!Bn(r,b)){kA(r,b).then(e);return}e();return}if(it?.editor){if(it.runtime.isVSCode&&s&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${QN(r,b)} (changes)`;it.editor.openDiff(``,r,e,{line:o,patch:s});return}it.editor.openFile(r,o);return}}if(x===`apply_patch`&&v){n.stopPropagation(),v.openTurnDiff(t,y.sessionId);return}if(x===`apply_patch`&&b&&!v&&!i&&!it?.runtime.isVSCode){n.stopPropagation(),d(b,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:y.sessionId});return}E||r(e.id)},ct=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),st(e))},lt=!S&&k?TP:EP,ut=!S&&k?DP:OP,dt=S&&u&&(Ie.length>0||Ne||Fe||!!ne),ft=!S&&!E&&n;return!Fe&&!je&&!S?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,Hv,S&&`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Ve?`flex-wrap items-start`:`items-center`),"data-mobile-press-feedback":`soft`,...nt,onClick:st,onKeyDown:ct,role:`button`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5`,Ve?`w-full min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`:`items-center flex-shrink-0`),children:[(0,$.jsx)(`div`,{className:Y(`relative flex-shrink-0`,i?`size-4`:`size-3.5`),children:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,style:S&&Je.showAvatar?void 0:lt,children:S&&Je.showAvatar?(0,$.jsx)(Fo,{name:ne||e.id,size:14,label:Xe}):Ne?(0,$.jsx)(dN,{isMobile:i,className:`text-[var(--tools-icon)]`,label:h(`chat.assistantStatus.usingTool`,{tool:Xe})}):H?(0,$.jsx)(Ud,{done:H.done,total:H.total,className:`size-3.5 text-current`}):KA(x||e.tool)})}),Ve?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(jN,`flex-shrink-0`),style:ut,title:Ge,children:Ge}),LN(R,s,l)]}):(0,$.jsxs)($.Fragment,{children:[Pe?(0,$.jsx)(`span`,{className:Y(jN,`shrink-0 whitespace-nowrap animate-text-shimmer`),style:{color:`var(--tools-title)`,"--yuri-text-shimmer-base":`var(--tools-title)`},title:Xe,children:Xe}):(0,$.jsx)(`span`,{className:Y(jN,`shrink-0 whitespace-nowrap`),style:ut,title:Xe,children:Xe}),(x===`bash`||C)&&typeof U==`number`&&(!O||typeof Ae==`number`||Se)?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,MN),children:(0,$.jsx)(WN,{start:U,end:typeof Ae==`number`&&!Se?Ae:void 0,active:!!(Ne&&(!Ae||Se))})}):null]})]}),!Ve&&(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,MN),style:{color:`var(--tools-description)`},children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[rt&&(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,MN,Pe&&`animate-text-shimmer`),style:Pe?{"--yuri-text-shimmer-base":`var(--surface-muted-foreground)`}:{color:`var(--tools-description)`,opacity:.8},title:rt,children:rt}),!rt&&x===`lsp`&&Ue?AP(Ue,s,!1,l):null,!rt&&x!==`lsp`&&We&&(Ue&&We===Ue?AP(Ue,s,!1,l):(0,$.jsx)(HA,{variant:s?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,MN),style:{color:`var(--tools-description)`},title:We,children:We})),ze&&(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,ze.added]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,ze.removed]})]}),Be&&(0,$.jsx)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,Be]})}),H&&(0,$.jsx)(jd,{done:H.done,total:H.total,className:`typography-meta`})]})}),Ce?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:we,className:`shrink-0 text-muted-foreground hover:text-foreground`,"data-component":`session-background-move`,"aria-label":h(we?`chat.sessionBackground.moving`:`chat.sessionBackground.moveRunning`),"aria-busy":we,onKeyDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),Ee()},children:(0,$.jsx)(X,{name:we?`loader-4`:`picture-in-picture-2`,className:Y(`size-3.5`,we&&`animate-spin`)})})}),(0,$.jsx)(ts,{side:`top`,children:h(we?`chat.sessionBackground.moving`:`chat.sessionBackground.moveRunning`)})]}):null,!E&&(!S||u)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:S?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),dt?(0,$.jsx)(bP,{entries:Ie,isExpanded:n,isMobile:i,output:W,sessionId:ne,onShowPopup:o,input:B,animateTailText:s,isActive:Ne}):null,!S&&!E&&n?(0,$.jsx)(`div`,{ref:I,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:ft?(0,$.jsxs)(`div`,{className:T?`relative ml-0.5 pl-1.5`:tN,children:[(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)`}}),(0,$.jsx)(PP,{part:He,state:c,currentDirectory:b,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},IP=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1,error:void 0})}componentDidCatch(e){}render(){if(!this.state.hasError)return this.props.children;let e=this.state.error?.message;return(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1.5 min-w-0`,Rv),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:TP,children:KA(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(jN,`flex-shrink-0`),style:DP,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(MN,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},LP=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=fr(),r=eN(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=RN(e.part.tool)||`tool`,i=Mu(a,n),t[0]=e.part.tool,t[1]=n,t[2]=i,t[3]=a):(i=t[2],a=t[3]);let o=i,s;t[4]!==r||t[5]!==e.part.id?(s=()=>!r||IN.get(e.part.id)===!0,t[4]=r,t[5]=e.part.id,t[6]=s):s=t[6];let[c,l]=Z.useState(s),u,d;if(t[7]!==r||t[8]!==c||t[9]!==e.part.id?(u=()=>{if(!(!r||c))return nd(()=>{IN.set(e.part.id,!0,e.part.id.length*2+8),Z.startTransition(()=>{l(!0)})})},d=[r,c,e.part.id],t[7]=r,t[8]=c,t[9]=e.part.id,t[10]=u,t[11]=d):(u=t[10],d=t[11]),Z.useEffect(u,d),!c){let e,n,r;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(`flex min-w-0 items-center gap-2`,Rv),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(jN,`shrink-0 text-muted-foreground`),t[12]=e,t[13]=n,t[14]=r):(e=t[12],n=t[13],r=t[14]);let i;t[15]===o?i=t[16]:(i=(0,$.jsx)(`span`,{className:r,children:o}),t[15]=o,t[16]=i);let a;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`span`,{className:`h-3 w-24 min-w-0 rounded bg-muted/40`,"aria-hidden":`true`}),t[17]=a):a=t[17];let s;return t[18]===i?s=t[19]:(s=(0,$.jsxs)(`div`,{className:e,children:[n,i,a]}),t[18]=i,t[19]=s),s}let f;t[20]===n?f=t[21]:(f=n(`chat.toolPart.error`),t[20]=n,t[21]=f);let p;t[22]===e?p=t[23]:(p=(0,$.jsx)(FP,{...e}),t[22]=e,t[23]=p);let m;return t[24]!==o||t[25]!==e.part||t[26]!==f||t[27]!==p||t[28]!==a?(m=(0,$.jsx)(IP,{displayName:o,errorLabel:f,resetKey:e.part,toolName:a,children:p}),t[24]=o,t[25]=e.part,t[26]=f,t[27]=p,t[28]=a,t[29]=m):m=t[29],m},(e,t)=>cM([e.part],[t.part])&&e.messageId===t.messageId&&e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.alwaysShowActions===t.alwaysShowActions&&e.onContentChange===t.onContentChange&&e.onShowPopup===t.onShowPopup&&e.animateTailText===t.animateTailText);function RP(e){return e.setCurrentSession}function zP(e){return e.openContextPanelTab}function BP(e){return e.showToolFileIcons}function VP(e){return e.stopPropagation()}function HP(e){return e.stopPropagation()}function UP(e){return!e}var WP=e=>e.isStreaming?e.throttledTextContent:e.textContent,GP=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,KP=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=fr(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(qP)],t[2]=n.highlights,t[3]=n.subject,t[4]=e):e=t[4],l=e.join(`
|
|
6585
|
+
`,wP={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},TP={...wn.getCollapsedStyles(),padding:0,overflow:`visible`},EP={style:{background:`transparent`,backgroundColor:`transparent`}},DP={color:`var(--status-error)`},OP={color:`var(--tools-icon)`},kP={color:`var(--status-error)`},AP={color:`var(--tools-title)`},jP=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate typography-ui-label text-foreground`,t&&`flex-1`),style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},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 flex items-baseline overflow-hidden typography-ui-label`,t&&`flex-1`),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0 text-muted-foreground`,children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i})]})]})},MP=(e,t=!0,n=!0,r=!0,i=PN)=>{let a=e.lastIndexOf(`/`),o=i===FN?`h-3 w-3 flex-shrink-0`:`h-3.5 w-3.5 flex-shrink-0`;if(a===-1)return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(Hh,{filePath:e,className:o}):null,(0,$.jsx)(WA,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 truncate whitespace-nowrap`,i,n&&`flex-1`),style:{color:`var(--tools-description)`},children:e})]});let s=e.slice(0,a),c=e.slice(a+1),l=s.startsWith(`/`),u=l?s.slice(1):s;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(Hh,{filePath:e,className:o}):null,(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full items-baseline overflow-hidden`,i,n&&`flex-1`),children:[l?(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:u}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(WA,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:c})]})]})},NP=e=>{let t=(0,Q.c)(3),{diff:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={backgroundColor:`var(--syntax-base-background)`,color:`var(--syntax-base-foreground)`},t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`pre`,{className:`m-0 overflow-auto whitespace-pre-wrap break-words rounded-lg p-2 typography-code`,style:r,children:n}),t[1]=n,t[2]=i),i},PP=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1})}componentDidCatch(e){}render(){return this.state.hasError?this.props.fallback:this.props.children}},FP=Z.memo(e=>{let t=(0,Q.c)(13),{diff:n,pierreTheme:r,pierreThemeType:i,diffViewMode:a}=e,o=a===`side-by-side`?`split`:`unified`,s;t[0]!==r||t[1]!==i||t[2]!==o?(s={diffStyle:o,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:`wrap`,theme:r,themeType:i,unsafeCSS:CP},t[0]=r,t[1]=i,t[2]=o,t[3]=s):s=t[3];let c=s,l;t[4]===n?l=t[5]:(l=(0,$.jsx)(NP,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)(Zn,{patch:n,metrics:wP,options:c,className:`block w-full`}),t[6]=n,t[7]=c,t[8]=d):d=t[8];let f;return t[9]!==n||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0`,children:(0,$.jsx)(PP,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});FP.displayName=`DiffPreview`;var IP=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=fr(),{pierreTheme:s,pierreThemeType:c}=oP(),[l,u]=Z.useState(`unified`),d=t,f=d.metadata,p=d.input,m=d.output,h=typeof m==`string`&&m.length>0,g=typeof m==`string`?m:``,_=nP(f?.filediff)?f.filediff:void 0,v=FM(f?.patch)??FM(f?.diff)??FM(_?.patch)??FM(_?.diff)??null,y=Z.useMemo(()=>WM(f,v??void 0,e=>eP(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>aP(e.tool,p,f,n),[n,p,f,e.tool]),S=Z.useMemo(()=>!p||typeof p!=`object`||Object.keys(p).length===0?``:`command`in p&&typeof p.command==`string`&&e.tool===`bash`?Rd(p,e.tool):typeof p.content==`string`?p.content??``:Rd(p,e.tool),[p,e.tool]),C=!b&&S.trim().length>0,w=e.tool===`write`||e.tool===`create`||e.tool===`file_write`,T=e.tool===`todowrite`||e.tool===`todoread`,E=Z.useMemo(()=>Array.isArray(p?.todos)?JSON.stringify(p.todos):g,[p?.todos,g]),D=Z.useMemo(()=>!w||!C?void 0:XN(typeof p?.filePath==`string`?p.filePath:typeof p?.file_path==`string`?p.file_path:typeof p?.path==`string`?p.path:void 0,S),[C,p?.filePath,p?.file_path,p?.path,S,w]);Z.useEffect(()=>{u(`unified`)},[e.id]);let O=(e,t)=>(0,$.jsx)(dP,{isMobile:i,maxHeightClass:t?.maxHeightClass,className:t?.className,disableHorizontal:t?.disableHorizontal,outerClassName:t?.outerClassName,children:e}),k=()=>{let n=()=>x?(0,$.jsxs)(`div`,{className:`tool-output-surface flex flex-col gap-2 rounded-xl border p-2`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--status-error-background)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium`,style:{color:`var(--status-error)`},children:o(`chat.toolPart.lspErrors`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 min-w-0`,children:jP(x.displayPath,!1)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:x.diagnostics.map((e,t)=>(0,$.jsx)(`div`,{className:`rounded-md border px-2 py-1`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--surface-elevated)`},children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`typography-micro shrink-0`,style:{color:`var(--status-error)`},children:[`[`,e.line,`:`,e.character,`]`]}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground whitespace-pre-wrap break-words`,children:e.message})]})},`${x.displayPath}:${e.line}:${e.character}:${t}`))}),x.remaining>0?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:o(`chat.toolPart.moreErrors`,{count:x.remaining})}):null]})]}):null;if(e.tool===`question`){if(t.status===`completed`&&h){let e=sP(g);if(e&&e.length>0)return O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.question}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground whitespace-pre-wrap`,children:e.answer})]},t))}),{maxHeightClass:`max-h-[40vh]`})}if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:zd(t.error)})]});let e=p;return e?.questions&&Array.isArray(e.questions)&&e.questions.length>0?O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.questions.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[e.header?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:zd(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:zd(e.question)}),Array.isArray(e.options)&&e.options.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:e.options.map(e=>(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-muted/30 border border-border/30 text-muted-foreground`,children:zd(e.label)},zd(e.label)))}):null]},t))}),{maxHeightClass:`max-h-[40vh]`}):(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:o(`chat.toolPart.awaitingResponse`)})}return(e.tool===`task`||e.tool===`subagent`)&&h?O((0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(nc,{content:zd(g),variant:`tool`,onShowPopup:a})})):(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`||e.tool===`write`)&&(y.length>0||x)?O((0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[y.map(e=>(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:e.renderMode===`diff`?(0,$.jsx)(FP,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(NP,{diff:e.patch})},e.id)),n()]}),{className:`p-1`}):e.tool===`write`&&x?O((0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:n()}),{className:`p-1`}):w?null:h&&g.trim()?O((0,$.jsx)(mP,{output:zd(g),part:e,metadata:f,input:p,isMobile:i}),{className:e.tool===`bash`?`p-1 rounded-none`:`p-1`,maxHeightClass:e.tool===`bash`?`max-h-[46vh]`:void 0}):O((0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground/70`,children:o(`chat.toolPart.noOutputProduced`)}),{maxHeightClass:`max-h-60`})};if(T){if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:iN(i,`todo-error`),children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-none border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:t.error})]});let n=Nd(E,void 0,{listClassName:db});return(0,$.jsx)(`div`,{className:iN(i,`todo`),children:O(n??(0,$.jsx)(mP,{output:E,part:e,metadata:f,input:p,isMobile:i}),fb)})}return(0,$.jsx)(`div`,{className:iN(i,`default`,e.tool===`bash`),children:e.tool===`question`?k():(0,$.jsxs)($.Fragment,{children:[C?(0,$.jsx)(`div`,{children:O(e.tool===`bash`?(0,$.jsx)(`pre`,{className:`tool-input-text whitespace-pre-wrap break-words typography-code text-muted-foreground/90 m-0 p-0`,style:i?{lineHeight:oN}:void 0,children:S}):w&&D?(0,$.jsx)(FP,{diff:D,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(`blockquote`,{className:`tool-input-text m-0 whitespace-pre-wrap break-words typography-meta italic text-muted-foreground/70`,children:S}),{maxHeightClass:w&&D&&r?`max-h-[50vh]`:`max-h-60`,className:e.tool===`bash`?`tool-input-surface p-0 rounded-none`:`tool-input-surface`})}):null,t.status===`completed`&&`output`in t&&(0,$.jsx)(`div`,{children:k()}),t.status===`error`&&`error`in t&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:zd(t.error)})]})]})})});IP.displayName=`ToolExpandedContent`;var LP=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:s=!0})=>{let c=e.state,l=q(e=>e.showToolFileIcons),u=q(e=>e.showSubagentTaskDetails),d=q(e=>e.openContextPanelTab),f=q(e=>e.openContextDiff),p=q(e=>e.openContextToolDiff),m=q(e=>e.navigateToDiff),{t:h}=fr(),g=Nu(),_=Wa(e=>e.setCurrentSession),v=fc(),y=Zb(),b=y.directory||g||``,x=BN(e.tool),S=aj(x||e.tool),C=oj(x||e.tool),w=sj(x||e.tool),T=x===`todowrite`||x===`todoread`,E=UN(x),D=c?.status,O=kN(e),k=D===`error`||D===`failed`,[A,j]=Z.useState(!O),M=Z.useRef(e.id),N=Z.useRef(``);Z.useEffect(()=>{M.current!==e.id&&(M.current=e.id,N.current=``,j(!O))},[O,e.id]),Z.useEffect(()=>{O||j(!0)},[O]),Z.useEffect(()=>{if(!O||k||!b||!VN.has(x))return;let t=`${e.id}:${D??`unknown`}`;N.current!==t&&(N.current=t,sa.requestGitRefresh({directory:b}))},[b,k,O,x,e.id,D]);let P=O||S,F=Z.useRef(a);F.current=a;let I=Z.useRef(null);Z.useLayoutEffect(()=>{if(S||E)return;let e=I.current;if(!e){P&&F.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,P&&F.current?.(`structural`)},[n,E,S,P]);let L=c,R=L.metadata,z=e.metadata,B=L.input,V=L.time,H=Z.useMemo(()=>{let e=B?.todos;if(!T||!Array.isArray(e))return null;let t=e.filter(e=>!!e&&typeof e==`object`&&typeof e.status==`string`);return t.length===0?null:{done:t.filter(e=>e.status===`completed`).length,total:t.length}},[B,T]),U=typeof V?.start==`number`&&Number.isFinite(V.start)?V.start:void 0,W=Z.useMemo(()=>typeof L.output==`string`?L.output:void 0,[L.output]),ee=Z.useMemo(()=>dj(W),[W]),te=Z.useMemo(()=>{if(!S)return[];let e=R,t=uj(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:ee.summaryEntries},[S,R,ee.summaryEntries]),G=O&&te.length>0,ne=Z.useMemo(()=>S?cj(R)||cj(L)||cj(B)||cj(z)||(ee.sessionId?ee.sessionId:fj(W)):void 0,[B,S,R,ee.sessionId,z,L,W]),re=Z.useMemo(()=>!O||!w?!1:!!(qj(e)||mj(R)===`running`||mj(L)===`running`||mj(z)===`running`||S&&(ee.status===`running`||_j(W))),[w,O,S,R,ee.status,e,z,L,W]),ie=!!(S&&re),ae=!!(C&&re),[oe,se]=Z.useState(!0),ce=Zr(S?ne??``:``),le=typeof e.sessionID==`string`?e.sessionID.trim():``,ue=!!(w&&re&&(S?!ce:oe)&&le),de=ca(ue?le:``,b),fe=Z.useMemo(()=>ue?Kj(de):void 0,[de,ue]),pe=S&&!O&&A,me=pe?ne:void 0,he=pe&&!ne?e.sessionID:void 0,ge=me??he,_e=Fa(he??``,b),ve=Sa(ge??``,b),ye=va(b,pe),be=Z.useMemo(()=>$j({part:e,completions:fe,childSessionStatusType:ce?.type}),[fe,ce?.type,e]);Z.useEffect(()=>{C&&be.kind===`terminal`&&se(!1)},[be.kind,C]);let xe=!!(S&&!k&&(ce?.type===`busy`||ce?.type===`retry`||ie&&be.kind===`background-running`)&&ne),Se=!!(C&&ae&&oe&&!k&&be.kind===`background-running`&&tM(e)?.workID),Ce=Jj(e),[we,Te]=Z.useState(!1),Ee=J(async()=>{if(!Ce||we)return;let t=typeof e.sessionID==`string`?e.sessionID.trim():``;if(!t){no.error(h(`chat.sessionBackground.moveFailed`));return}Te(!0);try{let e=await eM(t,Kt.getSdkClient());e.ok||no.error(h(`chat.sessionBackground.moveFailed`),{description:e.error})}finally{Te(!1)}}),De=!u||G?``:ne??``,Oe=ca(De,b);Lr(De,b);let ke=Z.useMemo(()=>!S||!ne||!Array.isArray(Oe)||Oe.length===0?[]:Ej(Oe),[Oe,S,ne]),Ae=O&&typeof V?.end==`number`&&Number.isFinite(V.end)?V.end:void 0,je=!O&&A,Me=nM({isTaskTool:S,isFinalized:O,taskSessionId:ne,childSessionStatus:ce,parentSessionStatus:_e,statusObservedAt:ve,taskStartedAt:U,statusSnapshotAt:ye}),Ne=je&&!Me||xe||Se,Pe=!!(S&&Ne&&!k);Z.useEffect(()=>{Me&&j(!1)},[Me]);let Fe=O,Ie=Z.useMemo(()=>ke.length>0?ke:te,[ke,te]),Le=Z.useMemo(()=>Ie.map(vP).join(`\0`),[Ie]),Re=Z.useRef(null);Z.useEffect(()=>{if(!S){Re.current=null;return}let e=Re.current;Re.current=Le,e!==null&&e!==Le&&Ie.length!==0&&F.current?.(`structural`)},[S,Ie.length,Le]);let ze=Z.useMemo(()=>x===`edit`||x===`multiedit`||x===`apply_patch`?qN(R):null,[R,x]),Be=Z.useMemo(()=>x===`write`?JN(B):null,[B,x]),Ve=x===`apply_patch`&&Array.isArray(R?.files)&&(R?.files).length>1,He=x===e.tool?e:{...e,tool:x},Ue=cP(He,c,b),We=uP(He,c,b),Ge=Mu(x||e.tool,h),Ke=hr(S?ne:void 0,b),qe=hr(S?ne:void 0),Je=Fj({isTaskTool:S,isFinalized:O,taskSessionId:ne,taskAgentName:S?nj(B,R,z,Ke??qe):void 0,displayName:Ge,delegatingLabel:h(`chat.assistantStatus.delegatingTask`),formatName:LN}),Ye=S&&Je.isDelegating,Xe=Je.title,Ze=typeof e.sessionID==`string`?e.sessionID.trim():``,Qe=Z.useMemo(()=>{if(!S||!Ze)return null;let n=typeof ne==`string`&&ne.trim().length>0?ne.trim():void 0,r=typeof e.id==`string`&&e.id.trim().length>0?e.id.trim():void 0,i=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():typeof t==`string`&&t.trim().length>0?t.trim():void 0;return{sessionID:Ze,...r?{partID:r}:{},...i?{messageID:i}:{},...b?{directory:b}:{},directoryPresent:!!b,childSessionPresent:!!n,...n?{childSessionID:n}:{},...D?{toolStatus:D}:{},finalized:O,backgroundRunning:xe,effectiveActive:Ne,suppressLoading:Me,delegating:Ye,childStatus:co(ce),parentStatus:co(_e),idleConfirmed:ce?.type===`idle`,navigateCapability:y.capabilities.navigateNestedSession,surfaceKind:y.kind,...typeof U==`number`?{taskStartedAt:U}:{},...typeof ve==`number`?{statusObservedAt:ve}:{},...typeof ye==`number`?{statusSnapshotAt:ye}:{}}},[ce,b,Ne,U,Ye,O,S,t,Ze,_e,e.id,e.messageID,y.capabilities.navigateNestedSession,y.kind,D,ve,ye,Me,xe,ne]),$e=Qe?Nr(Qe):``,et=Z.useRef(Qe);et.current=Qe,Z.useEffect(()=>{let e=et.current;!e||!$e||_o(e)},[$e]);let tt=J((e,t)=>{let n=et.current;n&&io({...n,opened:e,clickSource:t})}),nt=Ye?{"data-delegating":`true`}:void 0,rt=Z.useMemo(()=>{if(x===`bash`||x===`apply_patch`||x===`lsp`||Ue&&(x===`apply_patch`||x===`edit`||x===`multiedit`||x===`write`))return null;let e=L.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=B?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Ue,x,L,B]),it=Z.useContext(Pn),at=Z.useRef(!1),ot=J(e=>{let t=e??ne;return!t||!b?!1:(at.current=!1,$b(y,t,b,()=>{if(!Zi({sessionId:t,directory:b})){if(i||it?.runtime.isVSCode){_(t,b);return}d(b,{mode:`chat`,dedupeKey:`session:${t}`,label:Xe,readOnly:!0})}}))});Z.useEffect(()=>{!at.current||!ne||tt(ot(ne),`queued-effect`)},[ne]);let st=n=>{if(S){n.stopPropagation();let e=y.capabilities.navigateNestedSession,t=e?ot():!1;tt(t,`row`),e&&!t&&(at.current=!0);return}if(E&&!b)return;let a,o,s;if(x===`edit`||x===`multiedit`||x===`apply_patch`)a=iP(x,B,R),o=ZN(x,R,typeof a==`string`?a:void 0),typeof a==`string`&&(s=QN(x,R,a));else if([`write`,`create`,`file_write`].includes(x))a=B?.filePath||B?.file_path||B?.path||R?.filePath||R?.file_path||R?.path,o=1,typeof a==`string`&&typeof B?.content==`string`&&(s=XN(a,B.content));else if(x===`lsp`){a=B?.filePath||B?.file_path||B?.path;let e=B?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=Hn(b,a)||(a.startsWith(`/`)?a:b.endsWith(`/`)?b+a:`${b}/${a}`);if(E){let e=eP(r,b),n=Bn(r,b),a=n?e:r,c=s?JM(x,R,s,a,e=>eP(e,b)):[],l=(WN(x)||!n)&&c.length===1&&c[0]?[{path:a,patch:c[0].patch}]:c.map(e=>({path:e.title,patch:e.patch}));if(it?.runtime.isVSCode&&it.editor&&s){let e=`${a} (changes)`;it.editor.openDiff(``,r,e,{line:o,patch:s});return}if(l.length>0||n){v?l.length>0?v.openToolDiff({diffPath:a,patches:l,targetLine:o}):x===`apply_patch`?v.openTurnDiff(t,y.sessionId):v.openChanges({diffPath:e,staged:!1,targetLine:o}):i&&l.length===0?m(e,!1,WN(x)?`working`:`turn`,o):l.length>0?p(b,a,l,o,t,y.sessionId):f(b,e,!1,WN(x)?`working`:`turn`,o,t,y.sessionId);return}if(it?.editor){it.editor.openFile(r,o);return}jA(r,b).then(()=>{let e=q.getState(),t=Un(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(x===`lsp`){if(it?.editor){it.editor.openFile(r,o);return}let e=()=>{let e=q.getState(),t=Un(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!Bn(r,b)){jA(r,b).then(e);return}e();return}if(it?.editor){if(it.runtime.isVSCode&&s&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${eP(r,b)} (changes)`;it.editor.openDiff(``,r,e,{line:o,patch:s});return}it.editor.openFile(r,o);return}}if(x===`apply_patch`&&v){n.stopPropagation(),v.openTurnDiff(t,y.sessionId);return}if(x===`apply_patch`&&b&&!v&&!i&&!it?.runtime.isVSCode){n.stopPropagation(),d(b,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:y.sessionId});return}E||r(e.id)},ct=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),st(e))},lt=!S&&k?DP:OP,ut=!S&&k?kP:AP,dt=S&&u&&(Ie.length>0||Ne||Fe||!!ne),ft=!S&&!E&&n;return!Fe&&!je&&!S?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,Hv,S&&`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Ve?`flex-wrap items-start`:`items-center`),"data-mobile-press-feedback":`soft`,...nt,onClick:st,onKeyDown:ct,role:`button`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5`,Ve?`w-full min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`:`items-center flex-shrink-0`),children:[(0,$.jsx)(`div`,{className:Y(`relative flex-shrink-0`,i?`size-4`:`size-3.5`),children:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,style:S&&Je.showAvatar?void 0:lt,children:S&&Je.showAvatar?(0,$.jsx)(Fo,{name:ne||e.id,size:14,label:Xe}):Ne?(0,$.jsx)(pN,{isMobile:i,className:`text-[var(--tools-icon)]`,label:h(`chat.assistantStatus.usingTool`,{tool:Xe})}):H?(0,$.jsx)(Ud,{done:H.done,total:H.total,className:`size-3.5 text-current`}):JA(x||e.tool)})}),Ve?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(NN,`flex-shrink-0`),style:ut,title:Ge,children:Ge}),zN(R,s,l)]}):(0,$.jsxs)($.Fragment,{children:[Pe?(0,$.jsx)(`span`,{className:Y(NN,`shrink-0 whitespace-nowrap animate-text-shimmer`),style:{color:`var(--tools-title)`,"--yuri-text-shimmer-base":`var(--tools-title)`},title:Xe,children:Xe}):(0,$.jsx)(`span`,{className:Y(NN,`shrink-0 whitespace-nowrap`),style:ut,title:Xe,children:Xe}),(x===`bash`||C)&&typeof U==`number`&&(!O||typeof Ae==`number`||Se)?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,PN),children:(0,$.jsx)(KN,{start:U,end:typeof Ae==`number`&&!Se?Ae:void 0,active:!!(Ne&&(!Ae||Se))})}):null]})]}),!Ve&&(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,PN),style:{color:`var(--tools-description)`},children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[rt&&(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,PN,Pe&&`animate-text-shimmer`),style:Pe?{"--yuri-text-shimmer-base":`var(--surface-muted-foreground)`}:{color:`var(--tools-description)`,opacity:.8},title:rt,children:rt}),!rt&&x===`lsp`&&Ue?MP(Ue,s,!1,l):null,!rt&&x!==`lsp`&&We&&(Ue&&We===Ue?MP(Ue,s,!1,l):(0,$.jsx)(WA,{variant:s?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,PN),style:{color:`var(--tools-description)`},title:We,children:We})),ze&&(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,ze.added]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,ze.removed]})]}),Be&&(0,$.jsx)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,Be]})}),H&&(0,$.jsx)(jd,{done:H.done,total:H.total,className:`typography-meta`})]})}),Ce?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:we,className:`shrink-0 text-muted-foreground hover:text-foreground`,"data-component":`session-background-move`,"aria-label":h(we?`chat.sessionBackground.moving`:`chat.sessionBackground.moveRunning`),"aria-busy":we,onKeyDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),Ee()},children:(0,$.jsx)(X,{name:we?`loader-4`:`picture-in-picture-2`,className:Y(`size-3.5`,we&&`animate-spin`)})})}),(0,$.jsx)(ts,{side:`top`,children:h(we?`chat.sessionBackground.moving`:`chat.sessionBackground.moveRunning`)})]}):null,!E&&(!S||u)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:S?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),dt?(0,$.jsx)(SP,{entries:Ie,isExpanded:n,isMobile:i,output:W,sessionId:ne,onShowPopup:o,input:B,animateTailText:s,isActive:Ne}):null,!S&&!E&&n?(0,$.jsx)(`div`,{ref:I,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:ft?(0,$.jsxs)(`div`,{className:T?`relative ml-0.5 pl-1.5`:rN,children:[(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)`}}),(0,$.jsx)(IP,{part:He,state:c,currentDirectory:b,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},RP=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1,error:void 0})}componentDidCatch(e){}render(){if(!this.state.hasError)return this.props.children;let e=this.state.error?.message;return(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1.5 min-w-0`,Rv),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:DP,children:JA(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(NN,`flex-shrink-0`),style:kP,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(PN,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},zP=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=fr(),r=nN(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=BN(e.part.tool)||`tool`,i=Mu(a,n),t[0]=e.part.tool,t[1]=n,t[2]=i,t[3]=a):(i=t[2],a=t[3]);let o=i,s;t[4]!==r||t[5]!==e.part.id?(s=()=>!r||RN.get(e.part.id)===!0,t[4]=r,t[5]=e.part.id,t[6]=s):s=t[6];let[c,l]=Z.useState(s),u,d;if(t[7]!==r||t[8]!==c||t[9]!==e.part.id?(u=()=>{if(!(!r||c))return nd(()=>{RN.set(e.part.id,!0,e.part.id.length*2+8),Z.startTransition(()=>{l(!0)})})},d=[r,c,e.part.id],t[7]=r,t[8]=c,t[9]=e.part.id,t[10]=u,t[11]=d):(u=t[10],d=t[11]),Z.useEffect(u,d),!c){let e,n,r;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(`flex min-w-0 items-center gap-2`,Rv),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(NN,`shrink-0 text-muted-foreground`),t[12]=e,t[13]=n,t[14]=r):(e=t[12],n=t[13],r=t[14]);let i;t[15]===o?i=t[16]:(i=(0,$.jsx)(`span`,{className:r,children:o}),t[15]=o,t[16]=i);let a;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`span`,{className:`h-3 w-24 min-w-0 rounded bg-muted/40`,"aria-hidden":`true`}),t[17]=a):a=t[17];let s;return t[18]===i?s=t[19]:(s=(0,$.jsxs)(`div`,{className:e,children:[n,i,a]}),t[18]=i,t[19]=s),s}let f;t[20]===n?f=t[21]:(f=n(`chat.toolPart.error`),t[20]=n,t[21]=f);let p;t[22]===e?p=t[23]:(p=(0,$.jsx)(LP,{...e}),t[22]=e,t[23]=p);let m;return t[24]!==o||t[25]!==e.part||t[26]!==f||t[27]!==p||t[28]!==a?(m=(0,$.jsx)(RP,{displayName:o,errorLabel:f,resetKey:e.part,toolName:a,children:p}),t[24]=o,t[25]=e.part,t[26]=f,t[27]=p,t[28]=a,t[29]=m):m=t[29],m},(e,t)=>uM([e.part],[t.part])&&e.messageId===t.messageId&&e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.alwaysShowActions===t.alwaysShowActions&&e.onContentChange===t.onContentChange&&e.onShowPopup===t.onShowPopup&&e.animateTailText===t.animateTailText);function BP(e){return e.setCurrentSession}function VP(e){return e.openContextPanelTab}function HP(e){return e.showToolFileIcons}function UP(e){return e.stopPropagation()}function WP(e){return e.stopPropagation()}function GP(e){return!e}var KP=e=>e.isStreaming?e.throttledTextContent:e.textContent,qP=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,JP=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=fr(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(YP)],t[2]=n.highlights,t[3]=n.subject,t[4]=e):e=t[4],l=e.join(`
|
|
6586
6586
|
`);break bb0}let e;t[5]!==n.body||t[6]!==n.title?(e=[n.title,n.body].filter(Boolean),t[5]=n.body,t[6]=n.title,t[7]=e):e=t[7],l=e.join(`
|
|
6587
6587
|
|
|
6588
|
-
`)}let u=l,d;t[8]!==u||t[9]!==n.raw?(d=async()=>{(await Ea(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=J(d),p;t[11]!==n.kind||t[12]!==r?(p=n.kind===`commit`?r(`chat.generatedResult.commit.title`):r(`chat.generatedResult.pullRequest.title`),t[11]=n.kind,t[12]=r,t[13]=p):p=t[13];let m;t[14]===p?m=t[15]:(m=(0,$.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:p}),t[14]=p,t[15]=m);let h;t[16]===f?h=t[17]:(h=()=>{f()},t[16]=f,t[17]=h);let g;t[18]!==i||t[19]!==r?(g=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[18]=i,t[19]=r,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==r?(_=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[21]=i,t[22]=r,t[23]=_):_=t[23];let v;t[24]===i?v=t[25]:(v=i?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`}),t[24]=i,t[25]=v);let y;t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==_?(y=(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`xs`,onClick:h,title:g,"aria-label":_,className:`text-muted-foreground hover:text-foreground md:opacity-0 md:group-hover:opacity-100`,children:v}),t[26]=v,t[27]=h,t[28]=g,t[29]=_,t[30]=y):y=t[30];let b;t[31]!==y||t[32]!==m?(b=(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 px-3 py-1.5`,children:[m,y]}),t[31]=y,t[32]=m,t[33]=b):b=t[33];let x;t[34]!==n.body||t[35]!==n.highlights||t[36]!==n.kind||t[37]!==n.subject||t[38]!==n.title||t[39]!==r?(x=(0,$.jsx)(`div`,{className:`space-y-3 px-3 py-3`,children:n.kind===`commit`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n.subject}),n.highlights.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-sm text-muted-foreground`,children:n.highlights.map(
|
|
6588
|
+
`)}let u=l,d;t[8]!==u||t[9]!==n.raw?(d=async()=>{(await Ea(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=J(d),p;t[11]!==n.kind||t[12]!==r?(p=n.kind===`commit`?r(`chat.generatedResult.commit.title`):r(`chat.generatedResult.pullRequest.title`),t[11]=n.kind,t[12]=r,t[13]=p):p=t[13];let m;t[14]===p?m=t[15]:(m=(0,$.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:p}),t[14]=p,t[15]=m);let h;t[16]===f?h=t[17]:(h=()=>{f()},t[16]=f,t[17]=h);let g;t[18]!==i||t[19]!==r?(g=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[18]=i,t[19]=r,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==r?(_=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[21]=i,t[22]=r,t[23]=_):_=t[23];let v;t[24]===i?v=t[25]:(v=i?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`}),t[24]=i,t[25]=v);let y;t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==_?(y=(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`xs`,onClick:h,title:g,"aria-label":_,className:`text-muted-foreground hover:text-foreground md:opacity-0 md:group-hover:opacity-100`,children:v}),t[26]=v,t[27]=h,t[28]=g,t[29]=_,t[30]=y):y=t[30];let b;t[31]!==y||t[32]!==m?(b=(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 px-3 py-1.5`,children:[m,y]}),t[31]=y,t[32]=m,t[33]=b):b=t[33];let x;t[34]!==n.body||t[35]!==n.highlights||t[36]!==n.kind||t[37]!==n.subject||t[38]!==n.title||t[39]!==r?(x=(0,$.jsx)(`div`,{className:`space-y-3 px-3 py-3`,children:n.kind===`commit`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n.subject}),n.highlights.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-sm text-muted-foreground`,children:n.highlights.map(XP)}):null]}):(0,$.jsxs)($.Fragment,{children:[n.title?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.titleLabel`)}),(0,$.jsx)(`div`,{className:`mt-1 typography-ui-label text-foreground`,children:n.title})]}):null,n.body?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.bodyLabel`)}),(0,$.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words text-sm leading-relaxed text-muted-foreground font-sans`,children:n.body})]}):null]})}),t[34]=n.body,t[35]=n.highlights,t[36]=n.kind,t[37]=n.subject,t[38]=n.title,t[39]=r,t[40]=x):x=t[40];let S;return t[41]!==b||t[42]!==x?(S=(0,$.jsxs)(`div`,{"data-component":`generated-json-result`,className:`my-4 group overflow-clip rounded-2xl border border-border/80 bg-[var(--surface-elevated)]`,children:[b,x]}),t[41]=b,t[42]=x,t[43]=S):S=t[43],S};function YP(e){return`- ${e}`}function XP(e,t){return(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`-`}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`)}var ZP=e=>{let t=e.trim(),n=[],r=t.match(/^```(?:json)?\s*([\s\S]*?)```$/i);r?.[1]&&n.push(r[1].trim()),t.startsWith(`{`)&&t.endsWith(`}`)&&n.push(t);let i=[];for(let e of n)try{let t=JSON.parse(e);t&&typeof t==`object`&&!Array.isArray(t)&&i.push(t)}catch{}return i},QP=e=>{for(let t of ZP(e)){let e=typeof t.subject==`string`?t.subject.trim():``,n=Array.isArray(t.highlights)?t.highlights.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).slice(0,3):[];if(e)return{kind:`commit`,subject:e,highlights:n,raw:JSON.stringify({subject:e,highlights:n},null,2)};let r=typeof t.title==`string`?t.title.trim():``,i=typeof t.body==`string`?t.body.trim():``;if(r||i)return{kind:`pr`,title:r,body:i,raw:JSON.stringify({title:r,body:i},null,2)}}return null},$P=Z.memo(e=>{let t=(0,Q.c)(41),{part:n,sessionId:r,messageId:i,streamPhase:a,chatRenderMode:o,allowSortedFinalStreaming:s,hasStreamingHapticLifecycle:c,onShowPopup:l}=e,u=o===void 0?`live`:o,d=s!==void 0&&s,f=c!==void 0&&c,p=n,m=[typeof p.text==`string`?p.text:``,typeof p.content==`string`?p.content:``,typeof p.value==`string`?p.value:``].reduce(eF,``),h=(u===`live`||d)&&(a===`streaming`||a===`cooldown`);De(`ui.assistant_text_part.render`),h&&De(`ui.assistant_text_part.render.streaming`);let g=KP({textContent:m,throttledTextContent:ef({text:m,isStreaming:h,identityKey:`${i}:${n.id??`text`}`}),isStreaming:h}),_=`${i}:${n.id??`text`}`,v=Z.useRef(null),y,b;t[0]!==g||t[1]!==_||t[2]!==f||t[3]!==i||t[4]!==n.id||t[5]!==n.type||t[6]!==r?(y=()=>{if(!Oa())return;let e=n.type===`text`||n.type===`reasoning`,t=ci(v.current,{identity:_,content:g,isActive:f&&e,mode:n.type===`reasoning`?`appearance`:`changes`});v.current=t.nextState,!(!t.shouldEmit||!r)&&Dr({sessionID:r,messageID:i,partID:n.id,kind:n.type===`reasoning`?`thinking`:`text`})},b=[g,_,f,i,n.id,n.type,r],t[0]=g,t[1]=_,t[2]=f,t[3]=i,t[4]=n.id,t[5]=n.type,t[6]=r,t[7]=y,t[8]=b):(y=t[7],b=t[8]),Z.useEffect(y,b),$e(`ui.assistant_text_part.display_len`,g.length);let x=p.time,S=!!(x&&x.end!==void 0);if(n.type!==`text`&&n.type!==`reasoning`||!qP({displayTextContent:g,isFinalized:S}))return null;let C;t[9]!==g||t[10]!==S||t[11]!==h?(C=!h&&S?QP(g):null,t[9]=g,t[10]=S,t[11]=h,t[12]=C):C=t[12];let w=C;if(w){let e=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,r=n.id||`${i}-text`,a;t[13]!==i||t[14]!==n.id?(a=vA(i,n.id),t[13]=i,t[14]=n.id,t[15]=a):a=t[15];let o;t[16]===w?o=t[17]:(o=(0,$.jsx)(JP,{result:w}),t[16]=w,t[17]=o);let s;return t[18]!==o||t[19]!==e||t[20]!==r||t[21]!==a?(s=(0,$.jsx)(`div`,{className:e,"data-transcript-search-part":a,children:o},r),t[18]=o,t[19]=e,t[20]=r,t[21]=a,t[22]=s):s=t[22],s}let T=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,E=n.id||`${i}-text`,D;t[23]!==i||t[24]!==n.id?(D=vA(i,n.id),t[23]=i,t[24]=n.id,t[25]=D):D=t[25];let O=n.type===`text`?`true`:void 0,k=u===`sorted`&&!d,A=n.type===`reasoning`?`reasoning`:`assistant`,j=!h,M;t[26]!==g||t[27]!==h||t[28]!==i||t[29]!==l||t[30]!==n||t[31]!==k||t[32]!==A||t[33]!==j?(M=(0,$.jsx)(ic,{content:g,part:n,messageId:i,isAnimated:!1,isStreaming:h,disableStreamAnimation:k,variant:A,enableFileReferences:j,onShowPopup:l}),t[26]=g,t[27]=h,t[28]=i,t[29]=l,t[30]=n,t[31]=k,t[32]=A,t[33]=j,t[34]=M):M=t[34];let N;return t[35]!==O||t[36]!==M||t[37]!==T||t[38]!==E||t[39]!==D?(N=(0,$.jsx)(`div`,{className:T,"data-transcript-search-part":D,"data-speech-content":O,children:M},E),t[35]=O,t[36]=M,t[37]=T,t[38]=E,t[39]=D,t[40]=N):N=t[40],N});function eF(e,t){return t.length>e.length?t:e}var tF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,nF=Y(`typography-meta font-medium`,tF),rF=Y(`typography-meta`,tF),iF=e=>typeof e!=`string`||e.trim().length===0?``:e.split(`
|
|
6589
6589
|
`).map(e=>e.replace(/^>\s?/,``).trimEnd()).filter(e=>e.trim().length>0).join(`
|
|
6590
|
-
`).trim(),rF=80,iF=200,aF={duration:.2,ease:`easeOut`},oF=e=>e.replace(/<!--\s*-->/g,``).replace(/```[\w]*\n?([\s\S]*?)```/g,(e,t)=>t.trim()).replace(/`([^`]+)`/g,`$1`).replace(/\*{1,3}([^*]+)\*{1,3}/g,`$1`).replace(/_{1,3}([^_]+)_{1,3}/g,`$1`).replace(/^#{1,6}\s+/gm,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^>\s?/gm,``).replace(/^[-*_]{3,}\s*$/gm,``).trim(),sF=e=>{if(!e)return``;let t=oF(e).replace(/\s+/g,` `).trim();if(t.length<=rF)return t;let n=t.lastIndexOf(` `,rF),r=n>0?n:rF;return`${t.substring(0,r).trimEnd()}…`},cF=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:s})=>{let{t:c}=fr(),l=q(e=>e.isMobile),u=typeof i?.end==`number`,d=a&&!u,[f,p]=Z.useState(()=>s===!0?{expanded:!0,source:`user`}:{expanded:d,source:`auto`}),m=f.expanded,[h,g]=Z.useState(s===!0||d),_=Z.useId(),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=Z.useRef(n);x.current=n;let S=Z.useMemo(()=>sF(e),[e]),C=c(m?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),w=J(()=>{g(!0),p({expanded:!m,source:`user`}),n?.(`structural`)}),T=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),w())});if(Z.useLayoutEffect(()=>{p(e=>e.source===`user`||e.expanded||!d?e:{expanded:!0,source:`auto`})},[d]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(m||a){g(!0);return}if(!h)return;if(typeof window>`u`){g(!1);return}let e=window.setTimeout(()=>{g(!1)},iF);return()=>{window.clearTimeout(e)}},[m,a,h]),Z.useLayoutEffect(()=>{let e=v.current;if(!e)return;if(y.current?.stop(),!b.current){if(b.current=!0,!m){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=zo(e,{height:`auto`},aF);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}}e.style.overflow=`hidden`,m?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,x.current?.(`animation`));let t=zo(e,{height:m?`auto`:`0px`},aF);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,m?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}},[m]),Z.useEffect(()=>()=>{y.current?.stop(),y.current=null},[]),!e||e.trim().length===0)return null;let E=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(ic,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(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:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":m,"aria-controls":_,"aria-label":C,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,Hv),onClick:w,onKeyDown:T,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,m&&`opacity-0`,!m&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,m&&`opacity-100`,!m&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:m?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,eF),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--yuri-text-shimmer-base":`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(dN,{isMobile:l,className:`block text-[var(--tools-icon)]`})]}):m?(0,$.jsx)(`span`,{className:eF,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:eF,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,tF),style:{color:`var(--tools-description)`},children:!a&&!m&&S?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,tF),style:{color:`var(--tools-description)`,opacity:.8},title:S,children:S}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),h?(0,$.jsx)(`div`,{ref:v,id:_,"aria-hidden":!m,style:{height:m?`auto`:`0px`,overflow:m?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!m,transform:m?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:E}):(0,$.jsx)(ld,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:E})]})}):null]})},lF=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=q(uF),s=n,c=s.text||s.content||``,l;t[0]===c?l=t[1]:(l=nF(c),t[0]=c,t[1]=l);let u=l,d=s.time,f=a===void 0||a!==`completed`,p=o===`live`&&f&&typeof d?.end!=`number`,m=`${i}:${n.id??`reasoning`}`,h;t[2]!==p||t[3]!==m||t[4]!==u?(h={text:u,isStreaming:p,identityKey:m},t[2]=p,t[3]=m,t[4]=u,t[5]=h):h=t[5];let g=ef(h),_=`${i}:${n.id??`reasoning`}`,v=Z.useRef(null),y=n.sessionID,b=f&&typeof d?.end!=`number`,x,S;if(t[6]!==_||t[7]!==b||t[8]!==i||t[9]!==n.id||t[10]!==y||t[11]!==g?(x=()=>{if(!Oa())return;let e=ci(v.current,{identity:_,content:g,isActive:b,mode:`appearance`});v.current=e.nextState,!(!e.shouldEmit||!y)&&Dr({sessionID:y,messageID:i,partID:n.id,kind:`thinking`})},S=[_,b,i,n.id,y,g],t[6]=_,t[7]=b,t[8]=i,t[9]=n.id,t[10]=y,t[11]=g,t[12]=x,t[13]=S):(x=t[12],S=t[13]),Z.useEffect(x,S),!g||g.trim().length===0)return null;let C=n.id||`${i}-reasoning`,w;return t[14]!==p||t[15]!==r||t[16]!==C||t[17]!==g||t[18]!==d?(w=(0,$.jsx)(cF,{text:g,variant:`thinking`,onContentChange:r,blockId:C,time:d,isStreaming:p}),t[14]=p,t[15]=r,t[16]=C,t[17]=g,t[18]=d,t[19]=w):w=t[19],w});function uF(e){return e.chatRenderMode}var dF=(e,t)=>{let n=Hn(e,t)||zn(t);return n?Bn(n,e)?{kind:`diff`,path:Vn(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},fF=e=>{let t=q.getState(),n=dF(e.directory,e.filePath);if(n.kind===`file`){kA(n.path,e.directory).then(()=>{t.openContextFile(e.directory,n.path,{fileNotice:n.notice}),e.mobile&&t.setRightSidebarOpen(!1)});return}if(e.mobile){t.navigateToDiff(n.path,!1,`turn`),t.setRightSidebarOpen(!1);return}t.openContextDiff(e.directory,n.path,!1,`turn`,void 0,e.turnMessageId,e.sessionId)},pF=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),s=Z.useRef(null),c=Zb(),l=At(mF),u=c.directory||l,d=Kc(u),f;if(t[0]!==n||t[1]!==d){bb0:{if(d!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],f=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],f=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&Gy.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],f=e;break bb0}f=Yy(e)}t[0]=n,t[1]=d,t[2]=f}else f=t[2];let p=f;if(p.length===0)return null;let m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=m):m=t[6];let h=m,g;t[7]!==u||t[8]!==c?(g=e=>{if(!u)return;let t=q.getState();fF({directory:u,filePath:e.path,sessionId:c.sessionId,mobile:t.isMobile}),i(!1)},t[7]=u,t[8]=c,t[9]=g):g=t[9];let _=g,v=p.length,y=`${v} file${v===1?``:`s`}`,b=`${y} changed in this turn`,x;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=x):x=t[10];let S;t[11]===y?S=t[12]:(S=(0,$.jsx)(`span`,{className:`message-footer__label`,children:y}),t[11]=y,t[12]=S);let C;t[13]===r?C=t[14]:(C=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=C);let w;t[15]!==b||t[16]!==S||t[17]!==C?(w=(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)(ue,{render:(0,$.jsxs)(`button`,{ref:s,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":b,onPointerDownCapture:h,onFocusCapture:h,children:[x,S,C]})})}),t[15]=b,t[16]=S,t[17]=C,t[18]=w):w=t[18];let T;t[19]===y?T=t[20]:(T=(0,$.jsxs)(ts,{children:[y,` changed in this turn`]}),t[19]=y,t[20]=T);let E;t[21]!==w||t[22]!==T?(E=(0,$.jsxs)(ns,{children:[w,T]}),t[21]=w,t[22]=T,t[23]=E):E=t[23];let D=a||void 0,O;t[24]!==p||t[25]!==u||t[26]!==_?(O=(0,$.jsx)(pe,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(ce,{style:kb,className:`${Ob} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(Db,{files:p,currentDirectory:u,onOpenFile:_})})}),t[24]=p,t[25]=u,t[26]=_,t[27]=O):O=t[27];let k;t[28]!==D||t[29]!==O?(k=(0,$.jsx)(de,{container:D,children:O}),t[28]=D,t[29]=O,t[30]=k):k=t[30];let A;return t[31]!==r||t[32]!==E||t[33]!==k?(A=(0,$.jsxs)(le,{open:r,onOpenChange:i,children:[E,k]}),t[31]=r,t[32]=E,t[33]=k,t[34]=A):A=t[34],A});pF.displayName=`TurnChangedFilesDropdown`;function mF(e){return e.currentDirectory}var hF=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,gF=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},_F=e=>e.type!==`tool`||hF(e)?!1:!gF(e),vF=e=>{let t=0;for(let n of e)_F(n)&&(t+=1);return t},yF=(e,t)=>e===`stop`&&vF(t)===0,bF=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&xk(t)},xF=e=>{if(vF(e)!==0)return-1;for(let t=e.length-1;t>=0;--t){let n=e[t];if(bF(n))return t;if(n.type===`tool`||n.type===`reasoning`||n.type===`file`||n.type===`agent`||n.type===`subtask`)break}return-1},SF=(e,t,n)=>{if(n||!yF(e,t))return!1;for(let e of t)if(bF(e))return!0;return!1},CF=e=>e===`streaming`||e===`cooldown`,wF=e=>e.parts.some(bF),TF=e=>CF(e.streamPhase)?wF(e):!1,EF=e=>e.filter(e=>e?.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
|
|
6590
|
+
`).trim(),aF=80,oF=200,sF={duration:.2,ease:`easeOut`},cF=e=>e.replace(/<!--\s*-->/g,``).replace(/```[\w]*\n?([\s\S]*?)```/g,(e,t)=>t.trim()).replace(/`([^`]+)`/g,`$1`).replace(/\*{1,3}([^*]+)\*{1,3}/g,`$1`).replace(/_{1,3}([^_]+)_{1,3}/g,`$1`).replace(/^#{1,6}\s+/gm,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^>\s?/gm,``).replace(/^[-*_]{3,}\s*$/gm,``).trim(),lF=e=>{if(!e)return``;let t=cF(e).replace(/\s+/g,` `).trim();if(t.length<=aF)return t;let n=t.lastIndexOf(` `,aF),r=n>0?n:aF;return`${t.substring(0,r).trimEnd()}…`},uF=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:s})=>{let{t:c}=fr(),l=q(e=>e.isMobile),u=typeof i?.end==`number`,d=a&&!u,[f,p]=Z.useState(()=>s===!0?{expanded:!0,source:`user`}:{expanded:d,source:`auto`}),m=f.expanded,[h,g]=Z.useState(s===!0||d),_=Z.useId(),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=Z.useRef(n);x.current=n;let S=Z.useMemo(()=>lF(e),[e]),C=c(m?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),w=J(()=>{g(!0),p({expanded:!m,source:`user`}),n?.(`structural`)}),T=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),w())});if(Z.useLayoutEffect(()=>{p(e=>e.source===`user`||e.expanded||!d?e:{expanded:!0,source:`auto`})},[d]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(m||a){g(!0);return}if(!h)return;if(typeof window>`u`){g(!1);return}let e=window.setTimeout(()=>{g(!1)},oF);return()=>{window.clearTimeout(e)}},[m,a,h]),Z.useLayoutEffect(()=>{let e=v.current;if(!e)return;if(y.current?.stop(),!b.current){if(b.current=!0,!m){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=zo(e,{height:`auto`},sF);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}}e.style.overflow=`hidden`,m?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,x.current?.(`animation`));let t=zo(e,{height:m?`auto`:`0px`},sF);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,m?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}},[m]),Z.useEffect(()=>()=>{y.current?.stop(),y.current=null},[]),!e||e.trim().length===0)return null;let E=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(ic,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(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:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":m,"aria-controls":_,"aria-label":C,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,Hv),onClick:w,onKeyDown:T,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,m&&`opacity-0`,!m&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,m&&`opacity-100`,!m&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:m?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,nF),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--yuri-text-shimmer-base":`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(pN,{isMobile:l,className:`block text-[var(--tools-icon)]`})]}):m?(0,$.jsx)(`span`,{className:nF,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:nF,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,rF),style:{color:`var(--tools-description)`},children:!a&&!m&&S?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,rF),style:{color:`var(--tools-description)`,opacity:.8},title:S,children:S}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),h?(0,$.jsx)(`div`,{ref:v,id:_,"aria-hidden":!m,style:{height:m?`auto`:`0px`,overflow:m?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!m,transform:m?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:E}):(0,$.jsx)(ld,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:E})]})}):null]})},dF=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=q(fF),s=n,c=s.text||s.content||``,l;t[0]===c?l=t[1]:(l=iF(c),t[0]=c,t[1]=l);let u=l,d=s.time,f=a===void 0||a!==`completed`,p=o===`live`&&f&&typeof d?.end!=`number`,m=`${i}:${n.id??`reasoning`}`,h;t[2]!==p||t[3]!==m||t[4]!==u?(h={text:u,isStreaming:p,identityKey:m},t[2]=p,t[3]=m,t[4]=u,t[5]=h):h=t[5];let g=ef(h),_=`${i}:${n.id??`reasoning`}`,v=Z.useRef(null),y=n.sessionID,b=f&&typeof d?.end!=`number`,x,S;if(t[6]!==_||t[7]!==b||t[8]!==i||t[9]!==n.id||t[10]!==y||t[11]!==g?(x=()=>{if(!Oa())return;let e=ci(v.current,{identity:_,content:g,isActive:b,mode:`appearance`});v.current=e.nextState,!(!e.shouldEmit||!y)&&Dr({sessionID:y,messageID:i,partID:n.id,kind:`thinking`})},S=[_,b,i,n.id,y,g],t[6]=_,t[7]=b,t[8]=i,t[9]=n.id,t[10]=y,t[11]=g,t[12]=x,t[13]=S):(x=t[12],S=t[13]),Z.useEffect(x,S),!g||g.trim().length===0)return null;let C=n.id||`${i}-reasoning`,w;return t[14]!==p||t[15]!==r||t[16]!==C||t[17]!==g||t[18]!==d?(w=(0,$.jsx)(uF,{text:g,variant:`thinking`,onContentChange:r,blockId:C,time:d,isStreaming:p}),t[14]=p,t[15]=r,t[16]=C,t[17]=g,t[18]=d,t[19]=w):w=t[19],w});function fF(e){return e.chatRenderMode}var pF=(e,t)=>{let n=Hn(e,t)||zn(t);return n?Bn(n,e)?{kind:`diff`,path:Vn(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},mF=e=>{let t=q.getState(),n=pF(e.directory,e.filePath);if(n.kind===`file`){jA(n.path,e.directory).then(()=>{t.openContextFile(e.directory,n.path,{fileNotice:n.notice}),e.mobile&&t.setRightSidebarOpen(!1)});return}if(e.mobile){t.navigateToDiff(n.path,!1,`turn`),t.setRightSidebarOpen(!1);return}t.openContextDiff(e.directory,n.path,!1,`turn`,void 0,e.turnMessageId,e.sessionId)},hF=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),s=Z.useRef(null),c=Zb(),l=At(gF),u=c.directory||l,d=Kc(u),f;if(t[0]!==n||t[1]!==d){bb0:{if(d!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],f=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],f=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&Gy.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],f=e;break bb0}f=Yy(e)}t[0]=n,t[1]=d,t[2]=f}else f=t[2];let p=f;if(p.length===0)return null;let m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=m):m=t[6];let h=m,g;t[7]!==u||t[8]!==c?(g=e=>{if(!u)return;let t=q.getState();mF({directory:u,filePath:e.path,sessionId:c.sessionId,mobile:t.isMobile}),i(!1)},t[7]=u,t[8]=c,t[9]=g):g=t[9];let _=g,v=p.length,y=`${v} file${v===1?``:`s`}`,b=`${y} changed in this turn`,x;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=x):x=t[10];let S;t[11]===y?S=t[12]:(S=(0,$.jsx)(`span`,{className:`message-footer__label`,children:y}),t[11]=y,t[12]=S);let C;t[13]===r?C=t[14]:(C=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=C);let w;t[15]!==b||t[16]!==S||t[17]!==C?(w=(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)(ue,{render:(0,$.jsxs)(`button`,{ref:s,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":b,onPointerDownCapture:h,onFocusCapture:h,children:[x,S,C]})})}),t[15]=b,t[16]=S,t[17]=C,t[18]=w):w=t[18];let T;t[19]===y?T=t[20]:(T=(0,$.jsxs)(ts,{children:[y,` changed in this turn`]}),t[19]=y,t[20]=T);let E;t[21]!==w||t[22]!==T?(E=(0,$.jsxs)(ns,{children:[w,T]}),t[21]=w,t[22]=T,t[23]=E):E=t[23];let D=a||void 0,O;t[24]!==p||t[25]!==u||t[26]!==_?(O=(0,$.jsx)(pe,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(ce,{style:kb,className:`${Ob} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(Db,{files:p,currentDirectory:u,onOpenFile:_})})}),t[24]=p,t[25]=u,t[26]=_,t[27]=O):O=t[27];let k;t[28]!==D||t[29]!==O?(k=(0,$.jsx)(de,{container:D,children:O}),t[28]=D,t[29]=O,t[30]=k):k=t[30];let A;return t[31]!==r||t[32]!==E||t[33]!==k?(A=(0,$.jsxs)(le,{open:r,onOpenChange:i,children:[E,k]}),t[31]=r,t[32]=E,t[33]=k,t[34]=A):A=t[34],A});hF.displayName=`TurnChangedFilesDropdown`;function gF(e){return e.currentDirectory}var _F=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,vF=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},yF=e=>e.type!==`tool`||_F(e)?!1:!vF(e),bF=e=>{let t=0;for(let n of e)yF(n)&&(t+=1);return t},xF=(e,t)=>e===`stop`&&bF(t)===0,SF=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&Ck(t)},CF=e=>{if(bF(e)!==0)return-1;for(let t=e.length-1;t>=0;--t){let n=e[t];if(SF(n))return t;if(n.type===`tool`||n.type===`reasoning`||n.type===`file`||n.type===`agent`||n.type===`subtask`)break}return-1},wF=(e,t,n)=>{if(n||!xF(e,t))return!1;for(let e of t)if(SF(e))return!0;return!1},TF=e=>e===`streaming`||e===`cooldown`,EF=e=>e.parts.some(SF),DF=e=>TF(e.streamPhase)?EF(e):!1,OF=e=>e.filter(e=>e?.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
|
|
6591
6591
|
`).replace(/\n\s*\n+/g,`
|
|
6592
|
-
`),
|
|
6593
|
-
`),
|
|
6594
|
-
`;if(n===`strong`||n===`b`)return`**${r}**`;if(n===`em`||n===`i`)return`*${r}*`;if(n===`code`)return`\`${r.replace(/`/g,"\\`")}\``;if(n===`a`){let e=t.getAttribute(`href`);return e?`[${r}](${e})`:r}return r},
|
|
6595
|
-
`),
|
|
6592
|
+
`),kF=e=>{let t=Number.isFinite(e.cssInsetPx)?Math.max(0,e.cssInsetPx):0,n=e.visualHeight,r=n==null||!Number.isFinite(n)?0:Math.max(0,e.innerHeight-n-(e.visualOffsetTop??0));return Math.max(t,r)},AF=e=>{let t=Number.parseFloat(e??``);return Number.isFinite(t)?Math.max(0,t):0},jF=48,MF=88,NF=e=>{let t=e.composer;if(t&&t.height>=jF&&t.width>=jF)return{left:t.left,top:t.top,width:t.width,height:t.height};let n=e.nativeComposerHeightPx>=jF?e.nativeComposerHeightPx:e.lastHeightPx>=jF?e.lastHeightPx:MF,r=Math.max(0,e.keyboardOverlapPx);return{left:0,top:Math.max(0,e.viewportHeight-r-n),width:Math.max(0,e.viewportWidth),height:n}},PF=8,FF=`mod+l`,IF=`mod+shift+s`,LF=[`⌃`,`⌥`,`⇧`,`⌘`],RF=e=>{let t=Fs(e).split(` + `);if(!fa())return t.join(`+`);let n=t[t.length-1];return[...t.slice(0,-1).sort((e,t)=>LF.indexOf(e)-LF.indexOf(t)),n].join(``)},zF=280,BF=()=>{if(typeof document>`u`)return null;let e=null;for(let t of document.querySelectorAll(`.yuri-mobile-composer`)){let n=window.getComputedStyle(t);if(n.display===`none`||n.visibility===`hidden`)continue;let r=t.getBoundingClientRect();r.height<48||r.width<48||r.bottom<0||r.top>window.innerHeight||(!e||r.bottom>e.top+e.height)&&(e={left:r.left,top:r.top,width:r.width,height:r.height})}return e},VF=e=>{let t=document.documentElement,n=window.visualViewport;return NF({composer:BF(),viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,keyboardOverlapPx:kF({cssInsetPx:AF(t.style.getPropertyValue(`--yuri-keyboard-inset`)),innerHeight:window.innerHeight,visualHeight:n?.height,visualOffsetTop:n?.offsetTop}),nativeComposerHeightPx:AF(t.style.getPropertyValue(Il)),lastHeightPx:e})},HF=null;Sn(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),HF?.()});var UF=new Set(`address.article.aside.blockquote.dd.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.table.ul`.split(`.`)),WF=e=>e.replace(/\r\n?/g,`
|
|
6593
|
+
`),GF=e=>WF(e).trim(),KF=(e,t)=>{if(e.contains(t))return!0;let n=t instanceof ShadowRoot?t:t.getRootNode();return n instanceof ShadowRoot&&e.contains(n.host)},qF=e=>{let t=[],n=e=>{for(let r of e.querySelectorAll(`*`))r.shadowRoot&&(t.push(r.shadowRoot),n(r.shadowRoot))};return n(e),t},JF=(e,t)=>{let n=qF(t),r=e.getComposedRanges?.({shadowRoots:n})[0];if(r){let e=document.createRange();if(e.setStart(r.startContainer,r.startOffset),e.setEnd(r.endContainer,r.endOffset),KF(t,e.commonAncestorContainer))return e}if(e.rangeCount===0)return null;let i=e.getRangeAt(0);return KF(t,i.commonAncestorContainer)?i:null},YF=e=>e.replace(/\s+/g,` `).trim(),XF=e=>{if(e.nodeType===Node.TEXT_NODE)return YF(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase(),r=Array.from(t.childNodes).map(e=>XF(e)).join(``).replace(/\s+/g,` `).trim();if(!r&&n!==`br`)return``;if(n===`br`)return`
|
|
6594
|
+
`;if(n===`strong`||n===`b`)return`**${r}**`;if(n===`em`||n===`i`)return`*${r}*`;if(n===`code`)return`\`${r.replace(/`/g,"\\`")}\``;if(n===`a`){let e=t.getAttribute(`href`);return e?`[${r}](${e})`:r}return r},ZF=(e,t)=>Array.from(e.children).filter(e=>e instanceof HTMLElement&&e.tagName.toLowerCase()===`li`).map((e,n)=>{let r=t?`${n+1}. `:`- `,i=Array.from(e.childNodes).map(e=>XF(e)).join(``).replace(/\s+/g,` `).trim();return i?`${r}${i}`:``}).filter(Boolean).join(`
|
|
6595
|
+
`),QF=e=>{if(e.nodeType===Node.TEXT_NODE)return GF(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase();if(n===`pre`){let e=t.querySelector(`code`);return`\`\`\`${((e?.className||``).match(/language-([\w-]+)/)?.[1]||``).trim()}\n${WF(e?.textContent||t.textContent||``).replace(/\n$/,``)}\n\`\`\``}if(n===`code`){let e=WF(t.textContent||``).trim();return e?`\`${e.replace(/`/g,"\\`")}\``:``}if(n===`ul`)return ZF(t,!1);if(n===`ol`)return ZF(t,!0);if(n===`blockquote`)return GF(Array.from(t.childNodes).map(e=>QF(e)).join(`
|
|
6596
6596
|
`)).split(`
|
|
6597
6597
|
`).filter(e=>e.length>0).map(e=>`> ${e}`).join(`
|
|
6598
|
-
`);if(/^h[1-6]$/.test(n)){let e=Number.parseInt(n[1],10),r=
|
|
6598
|
+
`);if(/^h[1-6]$/.test(n)){let e=Number.parseInt(n[1],10),r=GF(Array.from(t.childNodes).map(e=>XF(e)).join(``));return r?`${`#`.repeat(e)} ${r}`:``}if(n===`p`||n===`div`||n===`li`)return GF(Array.from(t.childNodes).map(e=>XF(e)).join(``));let r=Array.from(t.childNodes).map(e=>QF(e)).filter(e=>e.length>0);return r.length>0?r.join(`
|
|
6599
6599
|
|
|
6600
|
-
`):
|
|
6600
|
+
`):GF(Array.from(t.childNodes).map(e=>XF(e)).join(``))},$F=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!UF.has(t.tagName.toLowerCase())}),eI=(e,t)=>{let n=e.cloneContents();if($F(n)){let e=GF(Array.from(n.childNodes).map(e=>XF(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>QF(e)).filter(e=>e.length>0).join(`
|
|
6601
6601
|
|
|
6602
|
-
`).trim()||UF(t)},$F=({containerRef:e})=>{let{t}=fr(),[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(LF),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=Wa(e=>e.currentSessionId),y=Nu()??null,b=q(e=>e.isMobile),x=Zb(),S=Qb(x).textSelectionMutation,C=x.kind===`primary`&&!!v;Z.useEffect(()=>{m.current=n.show},[n.show]);let w=Z.useCallback(()=>{d.current=null,BF===w&&(BF=null),p.current!==null&&(window.clearTimeout(p.current),p.current=null),f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),m.current&&=(c(!1),r(e=>({...e,show:!1})),a(``),!1)},[]);Z.useLayoutEffect(()=>w,[w]);let T=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=u.current/2,r=MF+n,i=t-MF-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),E=Z.useCallback(()=>{if(!d.current)return;BF!==w&&(BF?.(),BF=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=UF(t.toString());if(!r){o.current||w();return}let i=KF(t,n);if(!i){o.current||w();return}let a=i.getBoundingClientRect();d.current={plainText:r,markdownText:QF(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);let e=vn();p.current=window.setTimeout(()=>{p.current=null,vn()===e&&D()},10)},i=new Set,a=()=>{for(let e of GF(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=pE(vE),t=0,r=0,i=()=>{let e=zF(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=Wa.getState().newSessionDraft.draftID,n=Mg(v,t);n&&(Wg.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};fw.getState().addQuote(t,e),O(),NE(t)});if(Z.useEffect(()=>{if(!S)return;let t=t=>{let n=rs(t,NF),r=C&&rs(t,PF);if(!n&&!r)return;let i=window.getSelection(),a=e.current;if(!i||!a||!i.toString().trim())return;let o=KF(i,a);if(!o)return;t.preventDefault(),t.stopPropagation();let s=QF(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:NF,run:()=>k(i)},...C?[{id:`side`,label:t(`chat.textSelection.actions.addToSideChat`),shortcut:PF,run:()=>A(i)}]:[]];if(b){let e=g??{left:0,top:Math.max(0,window.innerHeight-88),width:window.innerWidth,height:88};return(0,Sp.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)($r,{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,Sp.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:IF(e.shortcut)})]})]},e.id))})}),document.body)},eI=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,tI=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+=eI(e.outputTokens)+eI(e.reasoningTokens),!r||t<=0||n<=0)return null;let i=t/(n/1e3);return Number.isFinite(i)&&i>0?i:null})},nI=e=>{let t=tI(e);return t[t.length-1]??null},rI=e=>e.completionDisposition!==`active`&&typeof e.tps==`number`&&Number.isFinite(e.tps)&&e.tps>0,iI=e=>!Number.isFinite(e)||e<=0?``:`${e.toFixed(1)} tok/s`,aI=e=>{let t=(0,Q.c)(5),{sessionId:n,scope:r}=e,{t:i}=fr(),a=yr(n,r);if(a===0)return null;let o;t[0]!==a||t[1]!==i?(o=i(`chat.sessionBackground.tasksRunning`,{count:a}),t[0]=a,t[1]=i,t[2]=o):o=t[2];let s;return t[3]===o?s=t[4]:(s=(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:o})}),t[3]=o,t[4]=s),s},oI=Z.memo(e=>{let t=(0,Q.c)(5),{sessionId:n,activityParts:r}=e,i;t[0]===r?i=t[1]:(i=Jj((r??[]).map(sI)),t[0]=r,t[1]=i);let a=i;if(a.childSessionIDs.size===0&&a.shellIDs.size===0)return null;let o;return t[2]!==a||t[3]!==n?(o=(0,$.jsx)(aI,{sessionId:n,scope:a}),t[2]=a,t[3]=n,t[4]=o):o=t[4],o});oI.displayName=`BackgroundActivityHint`;function sI(e){return e.part}var cI=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},lI=[`search`,`read`,`list`];function uI(e){let t=kN(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function dI(e){let t={read:0,search:0,list:0};for(let n of e){let e=uI(n);e&&(t[e]+=1)}return t}var fI=[`edit`,`command`,`other`],pI=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),mI=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function hI(e){if(!TN(e))return null;let t=kN(e);return pI.has(t)?`edit`:mI.has(t)?`command`:`other`}function gI(e){let t={edit:0,command:0,other:0};for(let n of e){let e=hI(n);e&&(t[e]+=1)}return t}function _I(e){return QM(e)}var vI=[...lI,...fI];function yI(e){return{...dI(e),...gI(e)}}function bI(e){return ON(e)}function xI(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!EN(e.toolName):e.kind!=null||e.type!=null}function SI(e,t,n){for(let r=t;r<e.length;r+=1)if(xI(n(e[r])))return!0;return!1}function CI(e){return`parts`in e?e.parts.some(e=>bI(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>bI(e))}function wI(e,t,n){let r=[],i=t;for(;i<e.length&&EN(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var TI=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,EI=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`,TI),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},DI=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=fr(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??CI({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=yI(u.map(e=>e.tool)),p=_I(u),m=vI.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:zv(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`,Hv),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)(dN,{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,TI,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,TI),style:{color:`var(--tools-description)`},children:(0,$.jsx)(cI,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(EI,{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:Bv(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 OI(e,t,n){let r=[],i=t;for(;i<e.length&&wN(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var kI=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function AI(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=kI(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=kI(e.name);if(t)return t;let r=kI(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=kI(n.output.name);if(e)return e}return null}function jI(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 MI=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,NI=({activities:e,isMobile:t,children:n})=>{let{t:r}=fr(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>ON(e)),{joinedVisible:l,hiddenCount:u}=jI(s.map(AI)),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:zv(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`,Hv),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)(dN,{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`,MI,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`,MI),style:{color:`var(--tools-description)`},children:(0,$.jsx)(cI,{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:Bv(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]})},PI=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=q(FI),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)(ZP,{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 FI(e){return e.chatRenderMode}var II=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},LI=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,RI=Y(`typography-meta font-medium`,LI),zI=Y(`typography-meta`,LI),BI=[],VI=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},HI=e=>{let t=new Set;for(let n of e)VI(n)&&n.messageId&&t.add(n.messageId);return[...t]},UI=(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}),WI=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=qn(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},GI=e=>e,KI=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},qI=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},JI=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},YI=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},XI=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=YI(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`}`},ZI=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=XI(n.todos);if(e)return e}if(Array.isArray(r)){let e=XI(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=XI(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=XI(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=XI(e.todos);if(t)return t}}catch{}return null},QI=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)},$I=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(HA,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,zI),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`,zI),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)(HA,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},eL=e=>{let t=zn(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},tL=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 AI(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`?ZI(e):KI(e)},nL=e=>{let t=new Set,n=new Set;for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(!rj(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=dj(e)||i;n.add(s),(o.status===`pending`||o.status===`running`)&&t.add(s)}return{active:[...t],all:[...n]}},rL=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=zv(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)(LP,{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&&cM([e.activity.part],[t.activity.part])),iL=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=zv(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(sL,{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&&oL(e.activities,t.activities)),aL=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!bk(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(EN(i)){let r=wI(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:SI(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(wN(i)){let r=OI(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(xN(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(bN(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(SN(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},oL=(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||!cM([r.part],[i.part]))return!1}return!0},sL=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=fr(),s=q(dL),c=Mu(n,o),l;t[0]===n?l=t[1]:(l=KA(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(Pn),m=fc(),h=At(fL),g=Zb(),_=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=oa(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(pL)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||ON(E.part),O;t[12]===E?O=t[13]:(O=E?tL(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||JI(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=eL(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=qI(E);if(!e){M=null;break bb1}let n=Vn(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=QI(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=Hn(_,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(!Bn(n,_)){kA(n,_).then(()=>{let e=q.getState(),r=_||Un(_,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=q.getState(),i=Un(_,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=zn(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=q.getState(),n=_||Un(``,t);e.openContextFile(n,t)};if(_&&!Bn(t,_)){kA(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),G;t[48]===te?G=t[49]:(G=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),te())},t[48]=te,t[49]=G);let ne=J(G),re=U&&W&&`cursor-pointer`,ie=U&&!W&&`cursor-default opacity-70`,ae;t[50]!==re||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,Hv,re,ie),t[50]=re,t[51]=ie,t[52]=ae):ae=t[52];let oe=U?`soft`:void 0,se=U?te:void 0,ce=U?ne: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)(dN,{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(RI,`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`,zI),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(Hh,{filePath:N.path,className:`h-3.5 w-3.5`}):null,$I(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)(HA,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,zI),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:mL,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`,zI),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(WI,{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`,zI),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`,zI),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)(HA,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,zI),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&&oL(e.activities,t.activities)),cL=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)(lF,{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}),lL=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)(PI,{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}),uL=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}=fr(),_=Nu()??``,v=Z.useMemo(()=>HI(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?II(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 QM(t)},[e]),N=M.added>0||M.removed>0,P=Z.useMemo(()=>nL(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=ge(_,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=et(_,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 ge(_,n,e).status}),te=ee.includes(`loading`),G=ee.includes(`error`),ne=ee.length>0&&ee.every(e=>e===`ready`),re=t.some(e=>W.has(e.messageId)&&VI(e)),ie=ne&&!re&&!UI(t,W),ae=Z.useMemo(()=>U?GI(e):BI,[e,U]),oe=Z.useMemo(()=>U?aL(ae.filter(e=>e.kind!==`reasoning`||bk(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]),le=!!m&&!(T&&!O);if((!le||z&&!O)&&oe.length===0)return null;let ue=(e,t)=>{let n=(0,$.jsx)(`div`,{className:zv(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},de=U?ce.map((e,t)=>{switch(e.type){case`reasoning`:return ue(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(cL,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ue(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(lL,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(rL,{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)(iL,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(DI,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return CN(n)?(0,$.jsx)(sL,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(LP,{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)(NI,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(sL,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(rL,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,fe=ce.length>0;return(0,$.jsxs)(`div`,{className:le?zv(c):`flow-root`,children:[le?(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&&Hv,z&&`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&(k?`pr-2`:`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-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)(dN,{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)(Fo,{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)(EI,{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,fe?(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:de})]}):null,B&&(te||G||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`,G&&`text-[var(--status-error)]`),role:G?`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`)})]}):G?(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)($r,{type:`button`,variant:`ghost`,size:`xs`,onClick:R,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]})});function dL(e){return e.showToolFileIcons}function fL(e){return e.currentDirectory}function pL(e){return[e.name,e]}function mL(e){e.stopPropagation()}var hL=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(uL,{...e}),t[0]=e,t[1]=n),n});function gL(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=Di(a,o),c;t[1]===r?c=t[2]:(c=e=>!!e.session_execution_recovery[r],t[1]=r,t[2]=c);let l=re(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=re(s,u),f=Na(r,a);if(!l&&!d){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Ov,{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)(Ov,{presentation:n}),t[7]=n,t[8]=m),m}function _L(e){let t=(0,Q.c)(5),n=Zb();if(!e.sessionId||!n.active||!n.capabilities.compose){let n;return t[0]===e.presentation?n=t[1]:(n=(0,$.jsx)(Ov,{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)(gL,{...e,sessionId:e.sessionId,directory:r}),t[2]=e,t[3]=r,t[4]=i):i=t[4],i}var vL={contain:`layout`},yL=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,bL=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,xL=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,SL=`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)]`,CL=`h-7 gap-1.5`,wL=`h-6 gap-1`,TL=`text-[11px] leading-none`,EL=`size-3.5`,DL=`size-3`,OL=5,kL=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)(Hh,{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=xL(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}),AL=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=fr(),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?wL:CL,d;t[3]===u?d=t[4]:(d=Y(SL,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)(kL,{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)($r,{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}),jL=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=fr(),c=Nu(),l=Zb(),u=l.directory||c,d=l.sessionId,f=fc(),p=q(HL),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,OL),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(SL,o?wL:CL),E=o?DL:EL,D;t[10]===o?D=t[11]:(D=o?Y(TL,`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(TL,`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(TL,`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){fF({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&fF({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&&fF({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(`chat.changedFiles.title`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`chat.changedFiles.title`),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 G;t[49]===E?G=t[50]:(G=Y(E,`opacity-60`),t[49]=E,t[50]=G);let ne;return t[51]===G?ne=t[52]:(ne=(0,$.jsx)(X,{name:`arrow-right-s`,className:G}),t[51]=G,t[52]=ne),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,te,ne]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(AL,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`chat.changedFiles.title`),title:s(`chat.changedFiles.title`),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]})}),ML=e=>e.type===`subtask`,NL=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},PL=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}`},FL=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=Nu(),{isMobile:o}=Us(),s=Wa(UL),c=q(WL),l=Zb(),{t:u}=fr(),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 b=y,x;t[10]===n.model?x=t[11]:(x=PL(n.model),t[10]=n.model,t[11]=x);let S=x,C=!!v&&!(o&&l.kind===`primary`),w;t[12]===u?w=t[13]:(w=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=w);let T;t[14]===w?T=t[15]:(T=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:w}),t[14]=w,t[15]=T);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]===S?k=t[21]:(k=S?(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:S}):null,t[20]=S,t[21]=k);let A;t[22]!==O||t[23]!==k||t[24]!==T||t[25]!==D?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T,D,O,k]}),t[22]=O,t[23]=k,t[24]=T,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]!==C||t[32]!==u?(M=C?(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(GL),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]=C,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]!==b?(N=b&&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&&$b(l,b,e,()=>{if(!Zi({sessionId:b,directory:e})){if(Zs()||o||E()){s(b,e);return}c(e,{mode:`chat`,dedupeKey:`session:${b}`,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]=b,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},IL=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=Nu(),i=q(KL),{isMobile:a}=Us(),{t:o}=fr(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!E(),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,b=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,x=c?p:void 0,S=c?h:void 0,C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(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]=C):C=t[10];let w;t[11]===f?w=t[12]:(w=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=w);let T=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]===T?D=t[14]:(D=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,T),t[13]=T,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]!==w||t[19]!==O?(k=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[w,O]}),t[18]=w,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)(nc,{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]!==S||t[27]!==j||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==b||t[32]!==x?(M=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":b,onClick:x,onKeyDown:S,children:[C,j]}),t[26]=S,t[27]=j,t[28]=_,t[29]=v,t[30]=y,t[31]=b,t[32]=x,t[33]=M):M=t[33],M},LL={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}=fr(),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 Ea(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)($r,{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)(Fd,{language:`bash`,code:c,codeStyle:LL,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},zL=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}=fr(),w=mx(),T=Qb(Zb()),E=q(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Sk(e):!!(ML(e)||NL(e))),[n]),j=Z.useMemo(()=>A.map(e=>Or(e)?yj(bk(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=FT(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`),G=!_&&v&&z?(0,$.jsx)(`div`,{className:te,...IT,children:(0,$.jsxs)(`div`,{className:Y(lT,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(gT,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:cT,name:`edit`,className:_T}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:cT,name:`close`,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,ne=(_&&z?(0,$.jsx)(`div`,{className:te,...IT,children:(0,$.jsx)(`div`,{className:Y(`flex items-center gap-2`,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(gT,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??G??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:te,...IT,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-2`,`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)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(gT,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:`medium`,name:`time`,className:`size-3.5!`}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(ts,{children:ee})]}):null,m&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:`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`,"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:`medium`,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(`size-3.5!`,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:`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`,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:`medium`,name:`edit`,className:`size-3.5!`})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:`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`,"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:`medium`,name:g===`fork`?`loader-4`:`git-branch`,className:Y(`size-3.5!`,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:`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`,"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:`medium`,name:`check`,className:Y(`size-3.5!`,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:`medium`,name:`file-copy`,className:`size-3.5!`})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full yuri-message-hover-scope`,...IT,"data-user-message-body":`true`,style:vL,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(ML(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(FL,{part:e})},e.id??`user-subtask-${i}`);if(NL(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)(IL,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&bk(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(RA,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(mg,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),ne]}):(0,$.jsx)($.Fragment,{children:ne})}),BL=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:b=!1,shouldShowHeader:x=!1,turnGroupingContext:S,errorPresentation:C})=>{let w=C?.text,{t:T}=fr(),D=mx(),O=Zb(),k=Qb(O),A=m,j=Z.useRef(null),M=Z.useRef(null),N=m===`streaming`||m===`cooldown`,P=Z.useRef({messageId:t,experiencedStreamingOrCooldown:N});P.current.messageId===t?N&&(P.current.experiencedStreamingOrCooldown=!0):P.current={messageId:t,experiencedStreamingOrCooldown:N};let F=!!(u??c),I=!!(l??c),L=!i,R=Z.useMemo(()=>n.filter(e=>!Sk(e)).filter(e=>e.type!==`reasoning`||b&&bk(e).trim().length>0).filter(e=>e.type!==`compaction`),[n,b]),z=Z.useMemo(()=>R.filter(e=>e.type===`tool`),[R]),B=Z.useMemo(()=>R.filter(e=>e.type===`text`),[R]),V=Z.useMemo(()=>EF(B),[B]),H=q(e=>e.openContextPreview),U=E(),W=D===`mini-chat`,ee=Z.useMemo(()=>{if(U||c||W)return null;for(let e of B){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=Gn(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 z){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=Gn(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},[B,c,W,U,z]),te=Wa(e=>e.forkFromMessage),G=Wa(e=>e.forkTransition),ne=Wa(e=>e.currentSessionId),re=Wa(e=>e.getDirectoryForSession),ie=Nu(),[ae,oe]=Z.useState(!1),se=q(e=>e.chatRenderMode),ce=S?se:`live`,le=q(e=>e.collapsibleThinkingBlocks),ue=q(e=>e.showSplitAssistantMessageActions),de=q(e=>e.showAssistantTps),fe=ce===`sorted`,pe=S?.isLastAssistantInTurn??!1,me=a===`stop`,he=(me||i||!!w)&&(S?.isTurnSettled??!0),ge=me?`completed`:A,_e=z.length>0,ve=Z.useMemo(()=>z.some(e=>ON(e)),[z]),ye=ON,be=DN,xe=P.current.experiencedStreamingOrCooldown,Se=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Se.current.messageId!==t&&(Se.current={messageId:t,initialized:!1,observedPartIds:new Set}),!xe||!Oa())return;let n=Se.current,r=!n.initialized;n.initialized=!0;for(let i of z){if(n.observedPartIds.has(i.id))continue;if(!_r(r,ye(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Dr({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[xe,ye,t,e,z]);let Ce=Z.useMemo(()=>z.length===0||!ve&&z.every(e=>be(e)),[z,ve,be]),we=Z.useMemo(()=>R.filter(e=>e.type===`reasoning`),[R]),Te=Z.useMemo(()=>we.length===0||we.every(e=>typeof e.time?.end==`number`),[we]),Ee=typeof a!=`string`,De=we.length>0&&_e&&(ve||Ee||!Ce),Oe=L||_e&&(ve||Ee||!Ce),ke=L||De,Ae=_e||we.length>0,je=B.length===0,Me=Ae&&je&&!Oe&&!ke&&Ce&&Te,Ne=Z.useRef(!1),Pe=Z.useRef(!1);Z.useEffect(()=>{Pe.current=!1},[t]),Z.useEffect(()=>{if(!Me){Ne.current=!1;return}Ne.current||(Ne.current=!0,y?.())},[Me,y]),Z.useEffect(()=>{if(L){Pe.current=!1;return}if(_e){Pe.current=!1;return}we.length!==0&&(ke||!Te||Pe.current||(Pe.current=!0,g?.(`structural`)))},[L,_e,g,Te,we.length,ke]);let Fe=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ae||G)){oe(!0);try{await te(e,t)}finally{oe(!1)}}}),Ie=Z.useMemo(()=>{let e=S?.activityParts;return!fe||!e?[]:e},[fe,S?.activityParts]),Le=Z.useMemo(()=>{let e=S?.activityGroupSegments;return!fe||!e?[]:e.filter(e=>e.anchorMessageId===t)},[fe,t,S?.activityGroupSegments]),Re=Le.length>0,ze=Z.useMemo(()=>{let e=new Map,t=new Map;return Ie.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)}}},[Ie]),Be=S?.toggleGroup,Ve=S?.activityPresentationKind===`compaction`,He=S?.isGroupExpanded===!0,Ue=fe&&Ve&&!He,We=fe?S?.activityOwnerMessageId===t||Re:!S?.activityOwnerMessageId||S.activityOwnerMessageId===t||Re,Ge=fe&&We&&(Re||Ve)&&!!Be,Ke=yF(a,R),qe={finish:a,parts:R,streamPhase:ge,error:w,isLastAssistantInTurn:pe},Je=wF(qe),Ye=ei(e=>e.ttsInputMode),Xe=Z.useMemo(()=>{if(!pe||Ve||!he||!Je)return``;let e=r??n,t=xF(e);return t<0?``:bk(e[t])},[pe,Ve,he,Je,r,n]),Ze=Ye===`final`?Xe:V;Ww({sessionId:e??``,messageId:t,created:s??0,text:Ze,targetRef:j,streaming:c&&O.active&&(A===`streaming`||A===`cooldown`),completed:c&&O.active&&i&&A!==`streaming`&&A!==`cooldown`&&!w});let Qe=fe&&TF(qe),$e=fe&&!Je&&!(Ve&&He),et=Z.useMemo(()=>{if(!de||!pe||C?.variant===`error`)return null;let e=S?.assistantTps;if(!rI({completionDisposition:S?.completionDisposition,tps:e}))return null;let t=iI(e??0);return t.length>0?t:null},[de,C?.variant,pe,S?.assistantTps,S?.completionDisposition]),tt=pe&&C?.variant!==`error`&&!Ue&&(he&&(_||!!w||i)||!!et),nt=tt?xF(r??n)>=0:!!_&&!L,rt=nt,it=S?.diffStats?.hasDiffs===!0,at=!!S?.activityParts?.length&&e&&O.active&&!W,ot=!W&&pe&&Ke&&he&&!Ue&&S?.diffStats?.hasDiffs===!0,st=ue&&rt&&!tt&&!fe,ct=Z.useMemo(()=>(0,$.jsx)(xT,{messageId:t,hasCopyableText:nt,isTouchContext:F,onCopyMessage:v,ttsText:Ze,sessionId:e}),[Ze,nt,F,v,e,t]),lt=Z.useMemo(()=>e=>{if(!ue||!fe)return null;let t=bk(e.part).trim();return t?(0,$.jsx)(xT,{hasCopyableText:!0,isTouchContext:F,onCopyMessage:async()=>(await Ea(t)).ok,ttsText:Ye===`final`?``:t}):null},[fe,F,ue,Ye]),ut=Z.useMemo(()=>{if(!st)return-1;let e=-1;for(let t=0;t<R.length;t+=1){let n=R[t];!n||n.type!==`text`||$e||ze.get(n)?.kind!==`justification`&&(e=t)}return e},[ze,$e,st,R]),dt=st&&ut<0,ft=Z.useMemo(()=>{let n=[];if(Ge&&Be&&S){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(hL,{parts:t,materializationParts:r,isExpanded:S.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:S.completionDisposition,activityPresentationKind:S.activityPresentationKind,durationMs:S.durationMs,startedAt:S.userMessageCreatedAt,onToggle:Be,isMobile:c,expandedTools:d,onToggleTool:f,onShowPopup:p,onContentChange:g,streamPhase:ge,showHeader:!0,diffStats:S.diffStats,renderJustificationActions:lt})},`progressive-group-${e}`))};Le.length>0?Le.forEach(t=>{let n=b?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ve&&e(`${t}:compaction-status`,[])}let r=0;for(;r<R.length;){let i=R[r];if(i.type===`text`){let a=ze.get(i);if($e){r+=1;continue}if(Ue){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:M,"data-message-text-export-source":`true`,children:(0,$.jsx)(ZP,{part:i,sessionId:e,messageId:t,streamPhase:ge,chatRenderMode:ce,allowSortedFinalStreaming:Qe,hasStreamingHapticLifecycle:xe,onContentChange:g,onShowPopup:p})},`assistant-text-${t}-${i.id??r}`)),st&&r===ut&&n.push((0,$.jsx)(`div`,{className:c?bL:yL,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:lT,"data-message-action-group":`true`,children:ct})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(ze.get(i)?.kind===`reasoning`){r+=1;continue}if(!bk(i).trim()){r+=1;continue}b&&(le?n.push((0,$.jsx)(`div`,{className:zv(c),children:(0,$.jsx)(lF,{part:i,messageId:t,streamPhase:ge,onContentChange:g})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(ZP,{part:i,sessionId:e,messageId:t,streamPhase:ge,chatRenderMode:ce,hasStreamingHapticLifecycle:xe,onContentChange:g,onShowPopup:p},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(fe&&!We){r+=1;continue}if(ze.get(i)?.kind===`tool`){r+=1;continue}if(fe&&EN(a)){let e=wI(R,r,e=>e.type!==`tool`||ze.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)(DI,{activities:i,isMobile:c,isTurnLive:ge!==`completed`,hasFollowingOtherType:SI(R,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 CN(n)?(0,$.jsx)(sL,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(LP,{part:e.part,messageId:t,isExpanded:d.has(e.part.id),onToggle:f,isMobile:c,alwaysShowActions:I,onContentChange:g,onShowPopup:p,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(wN(a)){let e=OI(R,r,e=>e.type!==`tool`||ze.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)(NI,{activities:i,isMobile:c,children:i.map(e=>(0,$.jsx)(sL,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(bN(a)){n.push((0,$.jsx)(`div`,{className:zv(c),children:(0,$.jsx)(LP,{part:e,messageId:t,isExpanded:d.has(e.id),onToggle:f,isMobile:c,alwaysShowActions:I,onContentChange:g,onShowPopup:p,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:zv(c),children:(0,$.jsx)(sL,{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`&&ge!==`completed`&&!he&&!C&&(!S||S.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},[ze,Le,I,ce,le,0,d,Ue,Ve,c,We,fe,ut,t,ct,lt,e,g,p,f,Ge,st,ge,C,xe,he,b,$e,Qe,Be,S,R]),pt=Z.useMemo(()=>{if(!pe||!he)return;let e=S?.durationMs;if(!(typeof e!=`number`||e<=0))return NT(e)},[pe,he,S?.durationMs]),mt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=PT(e);return t.length>0?t:null},[o,s]),ht=(0,$.jsxs)($.Fragment,{children:[!W&&!c&&!U&&ee?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,"aria-label":T(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ie??(ne?re(ne):null);e&&H(e,ee)},children:(0,$.jsx)(X,{weight:cT,name:`global`,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:T(`chat.messageBody.actions.openPreview`)})]}):null,!W&&k.fork?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,size:`icon`,variant:`ghost`,className:oT,"aria-label":T(`chat.messageBody.actions.forkAria`),"aria-busy":ae,disabled:ae||!!G,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Fe(e)},children:(0,$.jsx)(X,{weight:cT,name:ae?`loader-4`:`git-branch`,className:Y(sT,ae&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:T(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:j,"data-message-text-export-root":`true`,"data-speech-identity":e?`${e}:${t}`:void 0,...IT,className:Y(`relative w-full yuri-message-hover-scope`),style:vL,children:[(0,$.jsx)($F,{containerRef:j}),(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`,(x||S?.headerMessageId===t)&&(c?`[&>[data-message-text-export-source]:first-child]:pt-1.5`:`[&>[data-message-text-export-source]:first-child]:pt-2`)),children:[ft,C&&(0,$.jsx)(id,{children:(0,$.jsx)(`div`,{className:`my-1.5`,"data-assistant-error":C.variant,children:(0,$.jsx)(_L,{presentation:C,sessionId:e,messageId:t,directory:ie??void 0})})},`assistant-error`)]}),ot&&S?.diffStats?(0,$.jsx)(jL,{fileCount:S.diffStats.files,changedFiles:S.changedFiles,turnId:S.turnId,isLatestTurn:S.isLatestTurn,isMobile:c}):null,(0,$.jsx)(mg,{files:n,messageID:t,sessionID:e,onShowPopup:p}),dt&&(0,$.jsx)(`div`,{className:Y(c?bL:yL),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,"data-message-action-group":`true`,children:ct})}),tt&&(0,$.jsx)(bT,{messageId:t,isMobile:c,actions:(0,$.jsxs)($.Fragment,{children:[ct,ht]}),tps:et,duration:pt,timestamp:mt,activity:at&&e?(0,$.jsx)(oI,{sessionId:e,activityParts:S?.activityParts}):null,trailing:!W&&pe&&me&&!it?(0,$.jsx)(pF,{activityParts:S?.activityParts}):null})]})]})}),VL=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)(zL,{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)(BL,{...r}),t[26]=r,t[27]=i),i});function HL(e){return e.openContextPanelTab}function UL(e){return e.setCurrentSession}function WL(e){return e.openContextPanelTab}function GL(e){return!e}function KL(e){return e.openContextPanelTab}var qL=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}},JL=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},YL={"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`},XL={icon:`pause-circle`,variant:`muted`};function ZL(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`,XL.icon,XL.variant,!0):c(`chat.response.interrupted`,XL.icon,XL.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(YL,a)){if(a===`compaction.interrupted`)return c(YL[a],XL.icon,XL.variant,r===`Compaction was interrupted`);if(a===`compaction.unavailable`)return c(YL[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(YL[a],e)}return(!a||a===`unknown`||a===`error`)&&JL(r)?c(`chat.response.auth`,`lock`):{...c(`chat.response.failed`,`error-warning`),...!r&&i?{rawMessage:i}:{}}}function QL(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.nativeType===`synthetic`&&t.description===`Continuing after restart`}function $L(e,t){if(QL(e))return{text:t(`chat.response.continuingAfterRestart`),icon:`restart`,variant:`info`}}function eR(e){return!e}function tR(e){let t=(0,Q.c)(60),{part:n,isMobile:r}=e,i=r!==void 0&&r,{t:a}=fr(),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}=pA(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?ZL(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)($r,{variant:`ghost`,size:`sm`,className:Y(e,Vv),"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)(ic,{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 nR=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},rR=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=nR(t.mode)??nR(t.agent)??nR(r?.agent),o=nR(t.providerID)??nR(n?.providerID)??nR(i?.providerID),s=nR(t.modelID)??nR(n?.modelID)??nR(n?.id)??nR(i?.modelID)??nR(i?.id),c=nR(n?.variant)??nR(i?.variant)??nR(t.variant)??nR(r?.variant);return!a&&!o&&!s&&!c?null:{agentName:a,providerId:o,modelId:s,variant:c}},iR=e=>{let t=e?.providerId?.trim(),n=e?.modelId?.trim();return!t||!n?null:{providerId:t,modelId:n}},aR=e=>iR(e.assistantIdentity)??iR(e.userIdentity)??(e.allowComposerFallback?iR(e.composerSelection):null)??iR(e.sessionSelection),oR=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:Ki(void 0,t)||void 0,variant:e?.variant}},sR=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),cR=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,lR=e=>!e,uR=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},dR=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),fR=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,pR=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,mR=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},hR=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},gR=e=>!e||mR(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`)}),_R=e=>mR(e)===`user`?gR(e)||e.parts.some(e=>{let t=e.shellAction;return e.type===`text`&&typeof t==`object`&&!!t}):!1,vR=(e,t)=>{if(mR(e)!==`assistant`||t&&hR(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}}},yR=(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(mR(t)===`user`)break;let{hide:i,details:a}=vR(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},bR=ec(()=>Wn(()=>import(`./ToolOutputDialog-Bz23N8ob.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,77]))),xR=4e3,SR=new Map,CR=new Map,wR=new Set([`bash`,`shell`,`cmd`,`terminal`]),TR=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},ER=e=>{let t=SR.get(e);return t?new Set(t):new Set},DR=(e,t)=>{if(SR.size>=xR&&!SR.has(e)){let e=SR.keys().next().value;typeof e==`string`&&SR.delete(e)}SR.set(e,new Set(t))},OR=e=>{let t=CR.get(e);return t?new Set(t):new Set},kR=(e,t)=>{if(CR.size>=xR&&!CR.has(e)){let e=CR.keys().next().value;typeof e==`string`&&CR.delete(e)}CR.set(e,new Set(t))},AR=200,jR=new Map,MR=e=>jR.get(e),NR=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=jR.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(jR.size>=AR&&!jR.has(e)){let e=jR.keys().next().value;typeof e==`string`&&jR.delete(e)}jR.set(e,t)}};function PR(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 FR=(e,t)=>{if(typeof e==`object`&&e)return e[t]},IR=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})=>{let{t:f}=fr(),{isMobile:p,isTablet:m,hasTouchInput:h}=Us(),g=Zb(),_=Qb(g),v=p||m,y=Z.useRef(null),b=Z.useRef(null),x=J(t=>{y.current=t,b.current?.(),b.current=null,t&&p&&(b.current=aT(t,e.info.id))});Z.useEffect(()=>{let t=y.current;return b.current?.(),b.current=null,t&&p&&(b.current=aT(t,e.info.id)),()=>{b.current?.(),b.current=null}},[p,e.info.id]);let S=Wa(e=>e.currentSessionId),C=Wa(e=>e.revertToMessage),w=Wa(e=>e.editMessagePreservingChanges),T=Wa(e=>e.forkFromMessage),E=Wa(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=Wa(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=Wa(e=>e.clearStagedMessageEdit);De(`ui.chat_message.render`),c&&De(`ui.chat_message.render.streaming`);let k=ei(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=q(oe(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{S&<.getInstance().recordSessionStart(S)},[S]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>ER(e.info.id)),[U,W]=Z.useState(()=>OR(e.info.id)),[ee,te]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(ER(e.info.id)),W(OR(e.info.id))},[e.info.id]);let G=Z.useMemo(()=>qL(e.info),[e.info]).isUser,ne=Z.useMemo(()=>Je(e.parts),[e.parts]),re=G&&(p||!j),ie=G&&!p&&j&&!re,ae=e.info.sessionID,{currentContextAgent:se,savedSessionAgentSelection:ce}=ny(oe(e=>({currentContextAgent:c&&ae?e.currentAgentContext.get(ae):void 0,savedSessionAgentSelection:c&&ae?e.sessionAgentSelections.get(ae):void 0}))),le=Z.useMemo(()=>yk(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ue=Z.useMemo(()=>G?Nk(le):yk(e.parts),[G,e.parts,le]),de=Z.useMemo(()=>{if(G||!t)return null;let e=FR(t.info,`clientRole`),n=FR(t.info,`role`);return(typeof e==`string`?e:typeof n==`string`?n:void 0)===`user`&&rR(t.info)||null},[G,t]),fe=Z.useMemo(()=>{if(G)return;let t=FR(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=FR(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(de?.agentName)return de.agentName;if(ae)return se||(ce??void 0)},[G,e.info,de,ae,se,ce]),pe=G?null:rR(e.info),me=pe?.providerId??null,he=pe?.modelId??null,ge=Oi(oe(e=>{if(G||!ae)return null;if(de?.providerId&&de?.modelId)return{providerId:de.providerId,modelId:de.modelId};if(fe){let t=e.getAgentModelForSession(ae,fe);if(t?.providerId&&t?.modelId)return t}let t=e.getSessionModelSelection(ae);return t?.providerId&&t?.modelId?t:null})),_e=Z.useMemo(()=>G?null:typeof me==`string`&&me.trim().length>0?me:ge?.providerId??null,[G,me,ge]),ve=Z.useMemo(()=>G?null:typeof he==`string`&&he.trim().length>0?he:ge?.modelId??null,[G,he,ge]),ye=e.info.id?MR(e.info.id):void 0;G||NR(e.info.id,{agent:fe,provider:_e??void 0,model:ve??void 0});let be=fe??ye?.agent,xe=_e??ye?.provider??null,Se=ve??ye?.model??null,Ce=Z.useMemo(()=>{if(G)return;let e=xe&&k.length>0?k.find(e=>e.id===xe):void 0;return Ki(e,Se)||void 0},[G,xe,Se,k]),we=PR(be),Te=PR(xe??void 0),Ee=PR(Se??void 0),Oe=PR(Ce),ke=we??void 0,Ae=Te??null,je=Ee??null,Me=Oe??void 0,Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Pe=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Fe=Z.useMemo(()=>G?!0:!!(Ne&&Ne>0),[G,Ne]),Ie=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Le=Z.useMemo(()=>Ck(ue,{includeReasoning:A}),[ue,A]),Re=Z.useMemo(()=>G?Le:!Fe&&M===`sorted`?[]:Le,[M,Fe,G,Le]),ze=Z.useMemo(()=>G?[]:Le.filter(e=>e.type===`text`),[G,Le]),Be=Z.useMemo(()=>G?[]:Le.filter(e=>e.type===`tool`),[G,Le]),Ve=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of Be){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=TR(t.tool);!r||!wR.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=TR(t.part.tool);!n||!wR.has(n)||e.add(t.id)}return e},[N,Be,a?.activityParts]),He=Z.useMemo(()=>{if(Ve.size===0&&U.size===0)return V;let e=new Set(V);return Ve.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,Ve,V]),Ue=Z.useMemo(()=>{if(!G)return;let e=ue.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,ue]),We=G&&!Pk(Re),Ge=typeof Ie!=`string`,Ke=Z.useMemo(()=>G?!1:ze.length===0||Be.length===0?Ge:!0,[ze.length,Be.length,Ge,G]),qe=Z.useMemo(()=>!G&<.getInstance().shouldAnimateMessage(e.info,S||e.info.sessionID),[e.info,S,G]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?qL(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=fR({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),tt=Z.useMemo(()=>G?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,G,Ze]),nt=Z.useMemo(()=>Fe?`completed`:c?l??`streaming`:`completed`,[l,c,Fe]);Z.useEffect(()=>{!G||!u||d?.(e.info.id)},[u,G,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;G||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,G,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(G)return!0;if(s)return!1;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,G,a,nt,e.info.id,s]),it=Z.useCallback(e=>{Ea(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),at=G?void 0:pe?.variant??a?.userMessageVariant??de?.variant,ot=!G&&typeof at==`string`&&at.trim().length>0?at:void 0,st=Z.useMemo(()=>{if(!G&&!eR(Qe?$e:!tt))return ZL(e.info?.error,f)},[Qe,tt,$e,G,e.info,f]),ct=st?.text,lt=Z.useMemo(()=>{if(G){let e=Re.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(`
|
|
6602
|
+
`).trim()||GF(t)},tI=({containerRef:e})=>{let{t}=fr(),[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(zF),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=Wa(e=>e.currentSessionId),y=Nu()??null,b=q(e=>e.isMobile),x=Zb(),S=Qb(x).textSelectionMutation,C=x.kind===`primary`&&!!v;Z.useEffect(()=>{m.current=n.show},[n.show]);let w=Z.useCallback(()=>{d.current=null,HF===w&&(HF=null),p.current!==null&&(window.clearTimeout(p.current),p.current=null),f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),m.current&&=(c(!1),r(e=>({...e,show:!1})),a(``),!1)},[]);Z.useLayoutEffect(()=>w,[w]);let T=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=u.current/2,r=PF+n,i=t-PF-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),E=Z.useCallback(()=>{if(!d.current)return;HF!==w&&(HF?.(),HF=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=GF(t.toString());if(!r){o.current||w();return}let i=JF(t,n);if(!i){o.current||w();return}let a=i.getBoundingClientRect();d.current={plainText:r,markdownText:eI(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);let e=vn();p.current=window.setTimeout(()=>{p.current=null,vn()===e&&D()},10)},i=new Set,a=()=>{for(let e of qF(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=pE(vE),t=0,r=0,i=()=>{let e=VF(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=Wa.getState().newSessionDraft.draftID,n=Mg(v,t);n&&(Wg.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};fw.getState().addQuote(t,e),O(),NE(t)});if(Z.useEffect(()=>{if(!S)return;let t=t=>{let n=rs(t,FF),r=C&&rs(t,IF);if(!n&&!r)return;let i=window.getSelection(),a=e.current;if(!i||!a||!i.toString().trim())return;let o=JF(i,a);if(!o)return;t.preventDefault(),t.stopPropagation();let s=eI(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:FF,run:()=>k(i)},...C?[{id:`side`,label:t(`chat.textSelection.actions.addToSideChat`),shortcut:IF,run:()=>A(i)}]:[]];if(b){let e=g??{left:0,top:Math.max(0,window.innerHeight-88),width:window.innerWidth,height:88};return(0,Sp.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)($r,{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,Sp.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:RF(e.shortcut)})]})]},e.id))})}),document.body)},nI=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,rI=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+=nI(e.outputTokens)+nI(e.reasoningTokens),!r||t<=0||n<=0)return null;let i=t/(n/1e3);return Number.isFinite(i)&&i>0?i:null})},iI=e=>{let t=rI(e);return t[t.length-1]??null},aI=e=>e.completionDisposition!==`active`&&typeof e.tps==`number`&&Number.isFinite(e.tps)&&e.tps>0,oI=e=>!Number.isFinite(e)||e<=0?``:`${e.toFixed(1)} tok/s`,sI=e=>{let t=(0,Q.c)(5),{sessionId:n,scope:r}=e,{t:i}=fr(),a=yr(n,r);if(a===0)return null;let o;t[0]!==a||t[1]!==i?(o=i(`chat.sessionBackground.tasksRunning`,{count:a}),t[0]=a,t[1]=i,t[2]=o):o=t[2];let s;return t[3]===o?s=t[4]:(s=(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:o})}),t[3]=o,t[4]=s),s},cI=Z.memo(e=>{let t=(0,Q.c)(5),{sessionId:n,activityParts:r}=e,i;t[0]===r?i=t[1]:(i=Xj((r??[]).map(lI)),t[0]=r,t[1]=i);let a=i;if(a.childSessionIDs.size===0&&a.shellIDs.size===0)return null;let o;return t[2]!==a||t[3]!==n?(o=(0,$.jsx)(sI,{sessionId:n,scope:a}),t[2]=a,t[3]=n,t[4]=o):o=t[4],o});cI.displayName=`BackgroundActivityHint`;function lI(e){return e.part}var uI=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},dI=[`search`,`read`,`list`];function fI(e){let t=jN(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function pI(e){let t={read:0,search:0,list:0};for(let n of e){let e=fI(n);e&&(t[e]+=1)}return t}var mI=[`edit`,`command`,`other`],hI=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),gI=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function _I(e){if(!DN(e))return null;let t=jN(e);return hI.has(t)?`edit`:gI.has(t)?`command`:`other`}function vI(e){let t={edit:0,command:0,other:0};for(let n of e){let e=_I(n);e&&(t[e]+=1)}return t}function yI(e){return eN(e)}var bI=[...dI,...mI];function xI(e){return{...pI(e),...vI(e)}}function SI(e){return AN(e)}function CI(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!ON(e.toolName):e.kind!=null||e.type!=null}function wI(e,t,n){for(let r=t;r<e.length;r+=1)if(CI(n(e[r])))return!0;return!1}function TI(e){return`parts`in e?e.parts.some(e=>SI(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>SI(e))}function EI(e,t,n){let r=[],i=t;for(;i<e.length&&ON(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var DI=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,OI=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`,DI),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},kI=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=fr(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??TI({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=xI(u.map(e=>e.tool)),p=yI(u),m=bI.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:zv(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`,Hv),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)(pN,{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,DI,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,DI),style:{color:`var(--tools-description)`},children:(0,$.jsx)(uI,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(OI,{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:Bv(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 AI(e,t,n){let r=[],i=t;for(;i<e.length&&EN(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var jI=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function MI(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=jI(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=jI(e.name);if(t)return t;let r=jI(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=jI(n.output.name);if(e)return e}return null}function NI(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 PI=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,FI=({activities:e,isMobile:t,children:n})=>{let{t:r}=fr(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>AN(e)),{joinedVisible:l,hiddenCount:u}=NI(s.map(MI)),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:zv(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`,Hv),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)(pN,{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`,PI,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`,PI),style:{color:`var(--tools-description)`},children:(0,$.jsx)(uI,{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:Bv(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]})},II=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=q(LI),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)($P,{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 LI(e){return e.chatRenderMode}var RI=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},zI=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,BI=Y(`typography-meta font-medium`,zI),VI=Y(`typography-meta`,zI),HI=[],UI=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},WI=e=>{let t=new Set;for(let n of e)UI(n)&&n.messageId&&t.add(n.messageId);return[...t]},GI=(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}),KI=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=qn(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},qI=e=>e,JI=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},YI=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},XI=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},ZI=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},QI=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=ZI(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`}`},$I=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=QI(n.todos);if(e)return e}if(Array.isArray(r)){let e=QI(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=QI(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=QI(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=QI(e.todos);if(t)return t}}catch{}return null},eL=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)},tL=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(WA,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,VI),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`,VI),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)(WA,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},nL=e=>{let t=zn(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},rL=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 MI(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`?$I(e):JI(e)},iL=e=>{let t=new Set,n=new Set;for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(!aj(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=pj(e)||i;n.add(s),(o.status===`pending`||o.status===`running`)&&t.add(s)}return{active:[...t],all:[...n]}},aL=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=zv(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)(zP,{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&&uM([e.activity.part],[t.activity.part])),oL=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=zv(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(lL,{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&&cL(e.activities,t.activities)),sL=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Sk(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(ON(i)){let r=EI(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:wI(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(EN(i)){let r=AI(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(CN(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(SN(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(wN(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},cL=(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||!uM([r.part],[i.part]))return!1}return!0},lL=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=fr(),s=q(pL),c=Mu(n,o),l;t[0]===n?l=t[1]:(l=JA(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(Pn),m=fc(),h=At(mL),g=Zb(),_=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=oa(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(hL)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||AN(E.part),O;t[12]===E?O=t[13]:(O=E?rL(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||XI(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=nL(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=YI(E);if(!e){M=null;break bb1}let n=Vn(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=eL(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=Hn(_,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(!Bn(n,_)){jA(n,_).then(()=>{let e=q.getState(),r=_||Un(_,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=q.getState(),i=Un(_,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=zn(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=q.getState(),n=_||Un(``,t);e.openContextFile(n,t)};if(_&&!Bn(t,_)){jA(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),G;t[48]===te?G=t[49]:(G=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),te())},t[48]=te,t[49]=G);let ne=J(G),re=U&&W&&`cursor-pointer`,ie=U&&!W&&`cursor-default opacity-70`,ae;t[50]!==re||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,Hv,re,ie),t[50]=re,t[51]=ie,t[52]=ae):ae=t[52];let oe=U?`soft`:void 0,se=U?te:void 0,ce=U?ne: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)(pN,{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(BI,`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`,VI),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(Hh,{filePath:N.path,className:`h-3.5 w-3.5`}):null,tL(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)(WA,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,VI),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:gL,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`,VI),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(KI,{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`,VI),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`,VI),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)(WA,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,VI),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&&cL(e.activities,t.activities)),uL=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)(dF,{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}),dL=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)(II,{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}),fL=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}=fr(),_=Nu()??``,v=Z.useMemo(()=>WI(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?RI(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 eN(t)},[e]),N=M.added>0||M.removed>0,P=Z.useMemo(()=>iL(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=ge(_,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=et(_,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 ge(_,n,e).status}),te=ee.includes(`loading`),G=ee.includes(`error`),ne=ee.length>0&&ee.every(e=>e===`ready`),re=t.some(e=>W.has(e.messageId)&&UI(e)),ie=ne&&!re&&!GI(t,W),ae=Z.useMemo(()=>U?qI(e):HI,[e,U]),oe=Z.useMemo(()=>U?sL(ae.filter(e=>e.kind!==`reasoning`||Sk(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]),le=!!m&&!(T&&!O);if((!le||z&&!O)&&oe.length===0)return null;let ue=(e,t)=>{let n=(0,$.jsx)(`div`,{className:zv(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},de=U?ce.map((e,t)=>{switch(e.type){case`reasoning`:return ue(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(uL,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ue(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(dL,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(aL,{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)(oL,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(kI,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return TN(n)?(0,$.jsx)(lL,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(zP,{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)(FI,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(lL,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(aL,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,fe=ce.length>0;return(0,$.jsxs)(`div`,{className:le?zv(c):`flow-root`,children:[le?(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&&Hv,z&&`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&(k?`pr-2`:`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-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)(pN,{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)(Fo,{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)(OI,{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,fe?(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:de})]}):null,B&&(te||G||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`,G&&`text-[var(--status-error)]`),role:G?`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`)})]}):G?(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)($r,{type:`button`,variant:`ghost`,size:`xs`,onClick:R,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]})});function pL(e){return e.showToolFileIcons}function mL(e){return e.currentDirectory}function hL(e){return[e.name,e]}function gL(e){e.stopPropagation()}var _L=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(fL,{...e}),t[0]=e,t[1]=n),n});function vL(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=Di(a,o),c;t[1]===r?c=t[2]:(c=e=>!!e.session_execution_recovery[r],t[1]=r,t[2]=c);let l=re(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=re(s,u),f=Na(r,a);if(!l&&!d){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Ov,{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)(Ov,{presentation:n}),t[7]=n,t[8]=m),m}function yL(e){let t=(0,Q.c)(5),n=Zb();if(!e.sessionId||!n.active||!n.capabilities.compose){let n;return t[0]===e.presentation?n=t[1]:(n=(0,$.jsx)(Ov,{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)(vL,{...e,sessionId:e.sessionId,directory:r}),t[2]=e,t[3]=r,t[4]=i):i=t[4],i}var bL={contain:`layout`},xL=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,SL=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,CL=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,wL=`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)]`,TL=`h-7 gap-1.5`,EL=`h-6 gap-1`,DL=`text-[11px] leading-none`,OL=`size-3.5`,kL=`size-3`,AL=5,jL=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)(Hh,{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=CL(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}),ML=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=fr(),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?EL:TL,d;t[3]===u?d=t[4]:(d=Y(wL,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)(jL,{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)($r,{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}),NL=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=fr(),c=Nu(),l=Zb(),u=l.directory||c,d=l.sessionId,f=fc(),p=q(WL),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,AL),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(wL,o?EL:TL),E=o?kL:OL,D;t[10]===o?D=t[11]:(D=o?Y(DL,`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(DL,`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(DL,`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){mF({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&mF({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&&mF({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(`chat.changedFiles.title`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`chat.changedFiles.title`),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 G;t[49]===E?G=t[50]:(G=Y(E,`opacity-60`),t[49]=E,t[50]=G);let ne;return t[51]===G?ne=t[52]:(ne=(0,$.jsx)(X,{name:`arrow-right-s`,className:G}),t[51]=G,t[52]=ne),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,te,ne]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(ML,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`chat.changedFiles.title`),title:s(`chat.changedFiles.title`),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]})}),PL=e=>e.type===`subtask`,FL=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},IL=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}`},LL=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=Nu(),{isMobile:o}=Us(),s=Wa(GL),c=q(KL),l=Zb(),{t:u}=fr(),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 b=y,x;t[10]===n.model?x=t[11]:(x=IL(n.model),t[10]=n.model,t[11]=x);let S=x,C=!!v&&!(o&&l.kind===`primary`),w;t[12]===u?w=t[13]:(w=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=w);let T;t[14]===w?T=t[15]:(T=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:w}),t[14]=w,t[15]=T);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]===S?k=t[21]:(k=S?(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:S}):null,t[20]=S,t[21]=k);let A;t[22]!==O||t[23]!==k||t[24]!==T||t[25]!==D?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T,D,O,k]}),t[22]=O,t[23]=k,t[24]=T,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]!==C||t[32]!==u?(M=C?(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(qL),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]=C,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]!==b?(N=b&&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&&$b(l,b,e,()=>{if(!Zi({sessionId:b,directory:e})){if(Zs()||o||E()){s(b,e);return}c(e,{mode:`chat`,dedupeKey:`session:${b}`,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]=b,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},RL=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=Nu(),i=q(JL),{isMobile:a}=Us(),{t:o}=fr(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!E(),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,b=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,x=c?p:void 0,S=c?h:void 0,C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(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]=C):C=t[10];let w;t[11]===f?w=t[12]:(w=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=w);let T=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]===T?D=t[14]:(D=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,T),t[13]=T,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]!==w||t[19]!==O?(k=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[w,O]}),t[18]=w,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)(nc,{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]!==S||t[27]!==j||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==b||t[32]!==x?(M=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":b,onClick:x,onKeyDown:S,children:[C,j]}),t[26]=S,t[27]=j,t[28]=_,t[29]=v,t[30]=y,t[31]=b,t[32]=x,t[33]=M):M=t[33],M},zL={background:`transparent`,backgroundColor:`transparent`},BL=e=>{let t=(0,Q.c)(37),{part:n}=e,[r,i]=Z.useState(!1),a=Z.useRef(null),{t:o}=fr(),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 Ea(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)($r,{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)(Fd,{language:`bash`,code:c,codeStyle:zL,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},VL=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}=fr(),w=mx(),T=Qb(Zb()),E=q(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!wk(e):!!(PL(e)||FL(e))),[n]),j=Z.useMemo(()=>A.map(e=>Or(e)?xj(Sk(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=FT(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`),G=!_&&v&&z?(0,$.jsx)(`div`,{className:te,...IT,children:(0,$.jsxs)(`div`,{className:Y(lT,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(gT,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:cT,name:`edit`,className:_T}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:cT,name:`close`,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,ne=(_&&z?(0,$.jsx)(`div`,{className:te,...IT,children:(0,$.jsx)(`div`,{className:Y(`flex items-center gap-2`,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(gT,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??G??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:te,...IT,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-2`,`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)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(gT,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:`medium`,name:`time`,className:`size-3.5!`}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(ts,{children:ee})]}):null,m&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:`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`,"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:`medium`,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(`size-3.5!`,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:`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`,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:`medium`,name:`edit`,className:`size-3.5!`})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:`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`,"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:`medium`,name:g===`fork`?`loader-4`:`git-branch`,className:Y(`size-3.5!`,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:`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`,"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:`medium`,name:`check`,className:Y(`size-3.5!`,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:`medium`,name:`file-copy`,className:`size-3.5!`})})}),(0,$.jsx)(ts,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full yuri-message-hover-scope`,...IT,"data-user-message-body":`true`,style:bL,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(PL(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(LL,{part:e})},e.id??`user-subtask-${i}`);if(FL(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(BL,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(RL,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&Sk(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(BA,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(mg,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),ne]}):(0,$.jsx)($.Fragment,{children:ne})}),HL=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:b=!1,shouldShowHeader:x=!1,turnGroupingContext:S,errorPresentation:C})=>{let w=C?.text,{t:T}=fr(),D=mx(),O=Zb(),k=Qb(O),A=m,j=Z.useRef(null),M=Z.useRef(null),N=m===`streaming`||m===`cooldown`,P=Z.useRef({messageId:t,experiencedStreamingOrCooldown:N});P.current.messageId===t?N&&(P.current.experiencedStreamingOrCooldown=!0):P.current={messageId:t,experiencedStreamingOrCooldown:N};let F=!!(u??c),I=!!(l??c),L=!i,R=Z.useMemo(()=>n.filter(e=>!wk(e)).filter(e=>e.type!==`reasoning`||b&&Sk(e).trim().length>0).filter(e=>e.type!==`compaction`),[n,b]),z=Z.useMemo(()=>R.filter(e=>e.type===`tool`),[R]),B=Z.useMemo(()=>R.filter(e=>e.type===`text`),[R]),V=Z.useMemo(()=>OF(B),[B]),H=q(e=>e.openContextPreview),U=E(),W=D===`mini-chat`,ee=Z.useMemo(()=>{if(U||c||W)return null;for(let e of B){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=Gn(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 z){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=Gn(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},[B,c,W,U,z]),te=Wa(e=>e.forkFromMessage),G=Wa(e=>e.forkTransition),ne=Wa(e=>e.currentSessionId),re=Wa(e=>e.getDirectoryForSession),ie=Nu(),[ae,oe]=Z.useState(!1),se=q(e=>e.chatRenderMode),ce=S?se:`live`,le=q(e=>e.collapsibleThinkingBlocks),ue=q(e=>e.showSplitAssistantMessageActions),de=q(e=>e.showAssistantTps),fe=ce===`sorted`,pe=S?.isLastAssistantInTurn??!1,me=a===`stop`,he=(me||i||!!w)&&(S?.isTurnSettled??!0),ge=me?`completed`:A,_e=z.length>0,ve=Z.useMemo(()=>z.some(e=>AN(e)),[z]),ye=AN,be=kN,xe=P.current.experiencedStreamingOrCooldown,Se=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Se.current.messageId!==t&&(Se.current={messageId:t,initialized:!1,observedPartIds:new Set}),!xe||!Oa())return;let n=Se.current,r=!n.initialized;n.initialized=!0;for(let i of z){if(n.observedPartIds.has(i.id))continue;if(!_r(r,ye(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Dr({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[xe,ye,t,e,z]);let Ce=Z.useMemo(()=>z.length===0||!ve&&z.every(e=>be(e)),[z,ve,be]),we=Z.useMemo(()=>R.filter(e=>e.type===`reasoning`),[R]),Te=Z.useMemo(()=>we.length===0||we.every(e=>typeof e.time?.end==`number`),[we]),Ee=typeof a!=`string`,De=we.length>0&&_e&&(ve||Ee||!Ce),Oe=L||_e&&(ve||Ee||!Ce),ke=L||De,Ae=_e||we.length>0,je=B.length===0,Me=Ae&&je&&!Oe&&!ke&&Ce&&Te,Ne=Z.useRef(!1),Pe=Z.useRef(!1);Z.useEffect(()=>{Pe.current=!1},[t]),Z.useEffect(()=>{if(!Me){Ne.current=!1;return}Ne.current||(Ne.current=!0,y?.())},[Me,y]),Z.useEffect(()=>{if(L){Pe.current=!1;return}if(_e){Pe.current=!1;return}we.length!==0&&(ke||!Te||Pe.current||(Pe.current=!0,g?.(`structural`)))},[L,_e,g,Te,we.length,ke]);let Fe=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ae||G)){oe(!0);try{await te(e,t)}finally{oe(!1)}}}),Ie=Z.useMemo(()=>{let e=S?.activityParts;return!fe||!e?[]:e},[fe,S?.activityParts]),Le=Z.useMemo(()=>{let e=S?.activityGroupSegments;return!fe||!e?[]:e.filter(e=>e.anchorMessageId===t)},[fe,t,S?.activityGroupSegments]),Re=Le.length>0,ze=Z.useMemo(()=>{let e=new Map,t=new Map;return Ie.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)}}},[Ie]),Be=S?.toggleGroup,Ve=S?.activityPresentationKind===`compaction`,He=S?.isGroupExpanded===!0,Ue=fe&&Ve&&!He,We=fe?S?.activityOwnerMessageId===t||Re:!S?.activityOwnerMessageId||S.activityOwnerMessageId===t||Re,Ge=fe&&We&&(Re||Ve)&&!!Be,Ke=xF(a,R),qe={finish:a,parts:R,streamPhase:ge,error:w,isLastAssistantInTurn:pe},Je=EF(qe),Ye=ei(e=>e.ttsInputMode),Xe=Z.useMemo(()=>{if(!pe||Ve||!he||!Je)return``;let e=r??n,t=CF(e);return t<0?``:Sk(e[t])},[pe,Ve,he,Je,r,n]),Ze=Ye===`final`?Xe:V;Ww({sessionId:e??``,messageId:t,created:s??0,text:Ze,targetRef:j,streaming:c&&O.active&&(A===`streaming`||A===`cooldown`),completed:c&&O.active&&i&&A!==`streaming`&&A!==`cooldown`&&!w});let Qe=fe&&DF(qe),$e=fe&&!Je&&!(Ve&&He),et=Z.useMemo(()=>{if(!de||!pe||C?.variant===`error`)return null;let e=S?.assistantTps;if(!aI({completionDisposition:S?.completionDisposition,tps:e}))return null;let t=oI(e??0);return t.length>0?t:null},[de,C?.variant,pe,S?.assistantTps,S?.completionDisposition]),tt=pe&&C?.variant!==`error`&&!Ue&&(he&&(_||!!w||i)||!!et),nt=tt?CF(r??n)>=0:!!_&&!L,rt=nt,it=S?.diffStats?.hasDiffs===!0,at=!!S?.activityParts?.length&&e&&O.active&&!W,ot=!W&&pe&&Ke&&he&&!Ue&&S?.diffStats?.hasDiffs===!0,st=ue&&rt&&!tt&&!fe,ct=Z.useMemo(()=>(0,$.jsx)(xT,{messageId:t,hasCopyableText:nt,isTouchContext:F,onCopyMessage:v,ttsText:Ze,sessionId:e}),[Ze,nt,F,v,e,t]),lt=Z.useMemo(()=>e=>{if(!ue||!fe)return null;let t=Sk(e.part).trim();return t?(0,$.jsx)(xT,{hasCopyableText:!0,isTouchContext:F,onCopyMessage:async()=>(await Ea(t)).ok,ttsText:Ye===`final`?``:t}):null},[fe,F,ue,Ye]),ut=Z.useMemo(()=>{if(!st)return-1;let e=-1;for(let t=0;t<R.length;t+=1){let n=R[t];!n||n.type!==`text`||$e||ze.get(n)?.kind!==`justification`&&(e=t)}return e},[ze,$e,st,R]),dt=st&&ut<0,ft=Z.useMemo(()=>{let n=[];if(Ge&&Be&&S){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(_L,{parts:t,materializationParts:r,isExpanded:S.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:S.completionDisposition,activityPresentationKind:S.activityPresentationKind,durationMs:S.durationMs,startedAt:S.userMessageCreatedAt,onToggle:Be,isMobile:c,expandedTools:d,onToggleTool:f,onShowPopup:p,onContentChange:g,streamPhase:ge,showHeader:!0,diffStats:S.diffStats,renderJustificationActions:lt})},`progressive-group-${e}`))};Le.length>0?Le.forEach(t=>{let n=b?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ve&&e(`${t}:compaction-status`,[])}let r=0;for(;r<R.length;){let i=R[r];if(i.type===`text`){let a=ze.get(i);if($e){r+=1;continue}if(Ue){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:M,"data-message-text-export-source":`true`,children:(0,$.jsx)($P,{part:i,sessionId:e,messageId:t,streamPhase:ge,chatRenderMode:ce,allowSortedFinalStreaming:Qe,hasStreamingHapticLifecycle:xe,onContentChange:g,onShowPopup:p})},`assistant-text-${t}-${i.id??r}`)),st&&r===ut&&n.push((0,$.jsx)(`div`,{className:c?SL:xL,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:lT,"data-message-action-group":`true`,children:ct})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(ze.get(i)?.kind===`reasoning`){r+=1;continue}if(!Sk(i).trim()){r+=1;continue}b&&(le?n.push((0,$.jsx)(`div`,{className:zv(c),children:(0,$.jsx)(dF,{part:i,messageId:t,streamPhase:ge,onContentChange:g})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)($P,{part:i,sessionId:e,messageId:t,streamPhase:ge,chatRenderMode:ce,hasStreamingHapticLifecycle:xe,onContentChange:g,onShowPopup:p},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(fe&&!We){r+=1;continue}if(ze.get(i)?.kind===`tool`){r+=1;continue}if(fe&&ON(a)){let e=EI(R,r,e=>e.type!==`tool`||ze.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)(kI,{activities:i,isMobile:c,isTurnLive:ge!==`completed`,hasFollowingOtherType:wI(R,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 TN(n)?(0,$.jsx)(lL,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(zP,{part:e.part,messageId:t,isExpanded:d.has(e.part.id),onToggle:f,isMobile:c,alwaysShowActions:I,onContentChange:g,onShowPopup:p,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(EN(a)){let e=AI(R,r,e=>e.type!==`tool`||ze.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)(FI,{activities:i,isMobile:c,children:i.map(e=>(0,$.jsx)(lL,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(SN(a)){n.push((0,$.jsx)(`div`,{className:zv(c),children:(0,$.jsx)(zP,{part:e,messageId:t,isExpanded:d.has(e.id),onToggle:f,isMobile:c,alwaysShowActions:I,onContentChange:g,onShowPopup:p,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:zv(c),children:(0,$.jsx)(lL,{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`&&ge!==`completed`&&!he&&!C&&(!S||S.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},[ze,Le,I,ce,le,0,d,Ue,Ve,c,We,fe,ut,t,ct,lt,e,g,p,f,Ge,st,ge,C,xe,he,b,$e,Qe,Be,S,R]),pt=Z.useMemo(()=>{if(!pe||!he)return;let e=S?.durationMs;if(!(typeof e!=`number`||e<=0))return NT(e)},[pe,he,S?.durationMs]),mt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=PT(e);return t.length>0?t:null},[o,s]),ht=(0,$.jsxs)($.Fragment,{children:[!W&&!c&&!U&&ee?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,variant:`ghost`,size:`icon`,className:oT,"aria-label":T(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ie??(ne?re(ne):null);e&&H(e,ee)},children:(0,$.jsx)(X,{weight:cT,name:`global`,className:sT})})}),(0,$.jsx)(ts,{sideOffset:6,children:T(`chat.messageBody.actions.openPreview`)})]}):null,!W&&k.fork?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{type:`button`,size:`icon`,variant:`ghost`,className:oT,"aria-label":T(`chat.messageBody.actions.forkAria`),"aria-busy":ae,disabled:ae||!!G,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Fe(e)},children:(0,$.jsx)(X,{weight:cT,name:ae?`loader-4`:`git-branch`,className:Y(sT,ae&&`animate-spin`)})})}),(0,$.jsx)(ts,{sideOffset:6,children:T(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:j,"data-message-text-export-root":`true`,"data-speech-identity":e?`${e}:${t}`:void 0,...IT,className:Y(`relative w-full yuri-message-hover-scope`),style:bL,children:[(0,$.jsx)(tI,{containerRef:j}),(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`,(x||S?.headerMessageId===t)&&(c?`[&>[data-message-text-export-source]:first-child]:pt-1.5`:`[&>[data-message-text-export-source]:first-child]:pt-2`)),children:[ft,C&&(0,$.jsx)(id,{children:(0,$.jsx)(`div`,{className:`my-1.5`,"data-assistant-error":C.variant,children:(0,$.jsx)(yL,{presentation:C,sessionId:e,messageId:t,directory:ie??void 0})})},`assistant-error`)]}),ot&&S?.diffStats?(0,$.jsx)(NL,{fileCount:S.diffStats.files,changedFiles:S.changedFiles,turnId:S.turnId,isLatestTurn:S.isLatestTurn,isMobile:c}):null,(0,$.jsx)(mg,{files:n,messageID:t,sessionID:e,onShowPopup:p}),dt&&(0,$.jsx)(`div`,{className:Y(c?SL:xL),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,"data-message-action-group":`true`,children:ct})}),tt&&(0,$.jsx)(bT,{messageId:t,isMobile:c,actions:(0,$.jsxs)($.Fragment,{children:[ct,ht]}),tps:et,duration:pt,timestamp:mt,activity:at&&e?(0,$.jsx)(cI,{sessionId:e,activityParts:S?.activityParts}):null,trailing:!W&&pe&&me&&!it?(0,$.jsx)(hF,{activityParts:S?.activityParts}):null})]})]})}),UL=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)(VL,{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)(HL,{...r}),t[26]=r,t[27]=i),i});function WL(e){return e.openContextPanelTab}function GL(e){return e.setCurrentSession}function KL(e){return e.openContextPanelTab}function qL(e){return!e}function JL(e){return e.openContextPanelTab}var YL=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}},XL=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},ZL={"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`},QL={icon:`pause-circle`,variant:`muted`};function $L(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`,QL.icon,QL.variant,!0):c(`chat.response.interrupted`,QL.icon,QL.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(ZL,a)){if(a===`compaction.interrupted`)return c(ZL[a],QL.icon,QL.variant,r===`Compaction was interrupted`);if(a===`compaction.unavailable`)return c(ZL[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(ZL[a],e)}return(!a||a===`unknown`||a===`error`)&&XL(r)?c(`chat.response.auth`,`lock`):{...c(`chat.response.failed`,`error-warning`),...!r&&i?{rawMessage:i}:{}}}function eR(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.nativeType===`synthetic`&&t.description===`Continuing after restart`}function tR(e,t){if(eR(e))return{text:t(`chat.response.continuingAfterRestart`),icon:`restart`,variant:`info`}}function nR(e){return!e}function rR(e){let t=(0,Q.c)(60),{part:n,isMobile:r}=e,i=r!==void 0&&r,{t:a}=fr(),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}=hA(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?$L(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)($r,{variant:`ghost`,size:`sm`,className:Y(e,Vv),"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)(ic,{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 iR=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},aR=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=iR(t.mode)??iR(t.agent)??iR(r?.agent),o=iR(t.providerID)??iR(n?.providerID)??iR(i?.providerID),s=iR(t.modelID)??iR(n?.modelID)??iR(n?.id)??iR(i?.modelID)??iR(i?.id),c=iR(n?.variant)??iR(i?.variant)??iR(t.variant)??iR(r?.variant);return!a&&!o&&!s&&!c?null:{agentName:a,providerId:o,modelId:s,variant:c}},oR=e=>{let t=e?.providerId?.trim(),n=e?.modelId?.trim();return!t||!n?null:{providerId:t,modelId:n}},sR=e=>oR(e.assistantIdentity)??oR(e.userIdentity)??(e.allowComposerFallback?oR(e.composerSelection):null)??oR(e.sessionSelection),cR=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:Ki(void 0,t)||void 0,variant:e?.variant}},lR=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),uR=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,dR=e=>!e,fR=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},pR=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),mR=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,hR=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,gR=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},_R=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},vR=e=>!e||gR(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`)}),yR=e=>gR(e)===`user`?vR(e)||e.parts.some(e=>{let t=e.shellAction;return e.type===`text`&&typeof t==`object`&&!!t}):!1,bR=(e,t)=>{if(gR(e)!==`assistant`||t&&_R(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}}},xR=(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(gR(t)===`user`)break;let{hide:i,details:a}=bR(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},SR=ec(()=>Wn(()=>import(`./ToolOutputDialog-C5b57FEy.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,77]))),CR=4e3,wR=new Map,TR=new Map,ER=new Set([`bash`,`shell`,`cmd`,`terminal`]),DR=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},OR=e=>{let t=wR.get(e);return t?new Set(t):new Set},kR=(e,t)=>{if(wR.size>=CR&&!wR.has(e)){let e=wR.keys().next().value;typeof e==`string`&&wR.delete(e)}wR.set(e,new Set(t))},AR=e=>{let t=TR.get(e);return t?new Set(t):new Set},jR=(e,t)=>{if(TR.size>=CR&&!TR.has(e)){let e=TR.keys().next().value;typeof e==`string`&&TR.delete(e)}TR.set(e,new Set(t))},MR=200,NR=new Map,PR=e=>NR.get(e),FR=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=NR.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(NR.size>=MR&&!NR.has(e)){let e=NR.keys().next().value;typeof e==`string`&&NR.delete(e)}NR.set(e,t)}};function IR(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 LR=(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})=>{let{t:f}=fr(),{isMobile:p,isTablet:m,hasTouchInput:h}=Us(),g=Zb(),_=Qb(g),v=p||m,y=Z.useRef(null),b=Z.useRef(null),x=J(t=>{y.current=t,b.current?.(),b.current=null,t&&p&&(b.current=aT(t,e.info.id))});Z.useEffect(()=>{let t=y.current;return b.current?.(),b.current=null,t&&p&&(b.current=aT(t,e.info.id)),()=>{b.current?.(),b.current=null}},[p,e.info.id]);let S=Wa(e=>e.currentSessionId),C=Wa(e=>e.revertToMessage),w=Wa(e=>e.editMessagePreservingChanges),T=Wa(e=>e.forkFromMessage),E=Wa(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=Wa(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=Wa(e=>e.clearStagedMessageEdit);De(`ui.chat_message.render`),c&&De(`ui.chat_message.render.streaming`);let k=ei(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=q(oe(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{S&<.getInstance().recordSessionStart(S)},[S]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>OR(e.info.id)),[U,W]=Z.useState(()=>AR(e.info.id)),[ee,te]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(OR(e.info.id)),W(AR(e.info.id))},[e.info.id]);let G=Z.useMemo(()=>YL(e.info),[e.info]).isUser,ne=Z.useMemo(()=>Je(e.parts),[e.parts]),re=G&&(p||!j),ie=G&&!p&&j&&!re,ae=e.info.sessionID,{currentContextAgent:se,savedSessionAgentSelection:ce}=ny(oe(e=>({currentContextAgent:c&&ae?e.currentAgentContext.get(ae):void 0,savedSessionAgentSelection:c&&ae?e.sessionAgentSelections.get(ae):void 0}))),le=Z.useMemo(()=>xk(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ue=Z.useMemo(()=>G?Fk(le):xk(e.parts),[G,e.parts,le]),de=Z.useMemo(()=>{if(G||!t)return null;let e=LR(t.info,`clientRole`),n=LR(t.info,`role`);return(typeof e==`string`?e:typeof n==`string`?n:void 0)===`user`&&aR(t.info)||null},[G,t]),fe=Z.useMemo(()=>{if(G)return;let t=LR(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=LR(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(de?.agentName)return de.agentName;if(ae)return se||(ce??void 0)},[G,e.info,de,ae,se,ce]),pe=G?null:aR(e.info),me=pe?.providerId??null,he=pe?.modelId??null,ge=Oi(oe(e=>{if(G||!ae)return null;if(de?.providerId&&de?.modelId)return{providerId:de.providerId,modelId:de.modelId};if(fe){let t=e.getAgentModelForSession(ae,fe);if(t?.providerId&&t?.modelId)return t}let t=e.getSessionModelSelection(ae);return t?.providerId&&t?.modelId?t:null})),_e=Z.useMemo(()=>G?null:typeof me==`string`&&me.trim().length>0?me:ge?.providerId??null,[G,me,ge]),ve=Z.useMemo(()=>G?null:typeof he==`string`&&he.trim().length>0?he:ge?.modelId??null,[G,he,ge]),ye=e.info.id?PR(e.info.id):void 0;G||FR(e.info.id,{agent:fe,provider:_e??void 0,model:ve??void 0});let be=fe??ye?.agent,xe=_e??ye?.provider??null,Se=ve??ye?.model??null,Ce=Z.useMemo(()=>{if(G)return;let e=xe&&k.length>0?k.find(e=>e.id===xe):void 0;return Ki(e,Se)||void 0},[G,xe,Se,k]),we=IR(be),Te=IR(xe??void 0),Ee=IR(Se??void 0),Oe=IR(Ce),ke=we??void 0,Ae=Te??null,je=Ee??null,Me=Oe??void 0,Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Pe=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Fe=Z.useMemo(()=>G?!0:!!(Ne&&Ne>0),[G,Ne]),Ie=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Le=Z.useMemo(()=>Tk(ue,{includeReasoning:A}),[ue,A]),Re=Z.useMemo(()=>G?Le:!Fe&&M===`sorted`?[]:Le,[M,Fe,G,Le]),ze=Z.useMemo(()=>G?[]:Le.filter(e=>e.type===`text`),[G,Le]),Be=Z.useMemo(()=>G?[]:Le.filter(e=>e.type===`tool`),[G,Le]),Ve=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of Be){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=DR(t.tool);!r||!ER.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=DR(t.part.tool);!n||!ER.has(n)||e.add(t.id)}return e},[N,Be,a?.activityParts]),He=Z.useMemo(()=>{if(Ve.size===0&&U.size===0)return V;let e=new Set(V);return Ve.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,Ve,V]),Ue=Z.useMemo(()=>{if(!G)return;let e=ue.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,ue]),We=G&&!Ik(Re),Ge=typeof Ie!=`string`,Ke=Z.useMemo(()=>G?!1:ze.length===0||Be.length===0?Ge:!0,[ze.length,Be.length,Ge,G]),qe=Z.useMemo(()=>!G&<.getInstance().shouldAnimateMessage(e.info,S||e.info.sessionID),[e.info,S,G]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?YL(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=mR({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),tt=Z.useMemo(()=>G?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,G,Ze]),nt=Z.useMemo(()=>Fe?`completed`:c?l??`streaming`:`completed`,[l,c,Fe]);Z.useEffect(()=>{!G||!u||d?.(e.info.id)},[u,G,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;G||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,G,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(G)return!0;if(s)return!1;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,G,a,nt,e.info.id,s]),it=Z.useCallback(e=>{Ea(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),at=G?void 0:pe?.variant??a?.userMessageVariant??de?.variant,ot=!G&&typeof at==`string`&&at.trim().length>0?at:void 0,st=Z.useMemo(()=>{if(!G&&!nR(Qe?$e:!tt))return $L(e.info?.error,f)},[Qe,tt,$e,G,e.info,f]),ct=st?.text,lt=Z.useMemo(()=>{if(G){let e=Re.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(`
|
|
6603
6603
|
|
|
6604
6604
|
`);let t=Re.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(`
|
|
6605
6605
|
`):Re.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
|
|
6606
6606
|
`).replace(/\n\s*\n+/g,`
|
|
6607
|
-
`)}return ct&&ct.trim().length>0?ct:EF(Re)},[ct,Re,G]),ut=lt.length>0,dt=Z.useCallback(async()=>(await Ea(lt)).ok?(G&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[G,lt]),ft=J(async()=>{if(!(!ae||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(ae,e.info.id,{directory:g.directory??void 0})}catch(e){g.onRevertMessage&&$n.error(f(`chat.revert.toast.failed`),{id:`session-revert-error`,description:e&&typeof e==`object`&&`message`in e?String(e.message):String(e)})}finally{B.current=null,z(null)}}}),pt=J(()=>{if(!ae||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(ae,e.info.id,t).catch(()=>{})}),mt=J(()=>{ae&&O(ae)}),ht=Z.useCallback(async()=>{if(e.info.id,!ae||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!ae,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(ae,e.info.id)}finally{B.current=null,z(null)}}},[ae,e.info.id,T]),gt=J(t=>{let n=Ve.has(t),r=He.has(t);if(n){W(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),kR(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),DR(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),DR(e.info.id,r),r}),W(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),kR(e.info.id,r),r})}),_t=i??null,vt=Z.useRef(!1),yt=Z.useRef(!1),bt=Z.useRef(!1),xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1);Z.useEffect(()=>{yt.current=!1,bt.current=!1,xt.current=!1,St.current=!1,vt.current=!1,Ct.current=!1},[e.info.id]);let wt=Z.useCallback(()=>{G||vt.current||(vt.current=!0,r?.(`structural`))},[G,r]),Tt=q(e=>e.setImagePreviewOpen),Et=Z.useCallback(e=>{(e.image||e.mermaid||e.video)&&(te(e),Tt(!0))},[Tt]),Dt=Z.useCallback(e=>{te(t=>({...t,open:e})),Tt(e)},[Tt]),Ot=!!FR(e.info,`animationSettled`),kt=nt===`streaming`||nt===`cooldown`;kt&&(Ct.current=!0);let At=Z.useMemo(()=>!G&&Le.some(e=>e.type===`reasoning`),[G,Le]),jt=qe&&!Ot&&!kt&&!Ct.current,Mt=!G&&qe&&ze.length>0&&!Ke;Z.useEffect(()=>{if(_t?.onStreamingCandidate){if(!Mt){bt.current&&=(At&&_t?.onReasoningBlock?_t.onReasoningBlock():_t?.onReservationCancelled&&_t.onReservationCancelled(),!1);return}St.current||(St.current=!0,_t.onStreamingCandidate(),bt.current=!0)}},[_t,Mt,At]),Z.useEffect(()=>{_t?.onAnimationStart&&jt&&(xt.current||=(_t.onAnimationStart(),!0))},[_t,jt]),Z.useEffect(()=>{if(G)return;let e=_t?.onAnimatedHeightChange;if(!e||!(jt||Mt))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[jt,G,_t,Mt]);let Nt=Z.useMemo(()=>G?!0:Le.some(e=>e.type===`text`||e.type===`reasoning`?bk(e).trim().length>0:e.type===`tool`||e.type===`file`),[G,Le]),Pt=!!(a?.activityOwnerMessageId===e.info.id&&((a.activityParts?.length??0)>0||a.hasTools||a.hasReasoning)),Ft=!G&&!ne&&(Fe||!c||!!a)&&!st&&!Nt&&!Pt,It=$L(e.info,f);if(It)return(0,$.jsx)(`div`,{ref:x,className:`chat-message-column py-1.5`,id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-restart-notice":``,children:(0,$.jsx)(Ov,{presentation:It})});if(We||Ft)return null;if(ne)return(0,$.jsx)(`div`,{className:Y(`group w-full`,p?`py-2`:`py-3`),id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-compaction-status":ne.status,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(tR,{part:ne,isMobile:p})})});let Lt=!G&&rt?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,Rt=_R(e);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`w-full`,!G&&`yuri-message-hover-scope`,G?p?`pt-2`:`pt-6`:Lt,G||tt||s?`pb-0`:et?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,...IT,ref:x,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:G?Pk(Re)?(0,$.jsx)(id,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{...IT,className:Y(`relative flex`,Rt?`justify-start`:`justify-end`,p?void 0:`yuri-user-shell-hover-scope`),children:(0,$.jsxs)(`div`,{className:Y(Rt?`w-full min-w-0`:`max-w-[85%]`,ie&&!Rt?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:Rt?void 0:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:Rt?`min-w-0 text-left`:`px-3 py-1.5 shadow-none`,"data-user-message-bubble":Rt?void 0:`true`,"data-shell-result":Rt?`true`:void 0,children:(0,$.jsx)(VL,{messageId:e.info.id,parts:Re,sourceParts:le,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:gt,onShowPopup:Et,streamPhase:nt,allowAnimation:jt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ut,onCopyMessage:dt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:wt,agentMention:Ue,onEdit:!E&&_.edit?pt:void 0,onRevert:!E&&_.revert?ft:void 0,onFork:!E&&G&&_.fork?ht:void 0,editing:E,editStaged:D,onCancelEdit:D?mt:void 0,pendingMessageAction:R,errorPresentation:st,userActionsMode:re?`external-content`:`inline`,stickyUserHeaderEnabled:j&&!Rt})}),re?(0,$.jsx)(VL,{messageId:e.info.id,parts:Re,sourceParts:le,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:gt,onShowPopup:Et,streamPhase:nt,allowAnimation:jt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ut,onCopyMessage:dt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:wt,agentMention:Ue,onEdit:!E&&_.edit?pt:void 0,onRevert:!E&&_.revert?ft:void 0,onFork:!E&&G&&_.fork?ht:void 0,editing:E,editStaged:D,onCancelEdit:D?mt:void 0,pendingMessageAction:R,errorPresentation:st,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[rt&&(0,$.jsx)(wA,{isUser:G,isMobile:p,providerID:Ae,modelID:je,agentName:ke,modelName:Me,variant:ot}),!Nt&&!Pt&&!st&&c&&!Fe&&(0,$.jsxs)(`div`,{role:`status`,"aria-label":f(`common.loading`),"data-assistant-content-loading":``,className:`space-y-2 py-2`,children:[(0,$.jsx)(Kd,{className:`h-3.5 w-2/3`}),(0,$.jsx)(Kd,{className:`h-3.5 w-1/3`})]}),(0,$.jsx)(VL,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Le,sourceParts:ue,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCompletedAt:Ne??void 0,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:He,onToggleTool:gt,onShowPopup:Et,streamPhase:nt,allowAnimation:jt,onContentChange:r,shouldShowHeader:rt,hasTextContent:ut,onCopyMessage:dt,copiedMessage:I,onAuxiliaryContentComplete:wt,showReasoningTraces:A,agentMention:Ue,turnGroupingContext:a,errorPresentation:st})]})})}),ee.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(bR,{popup:ee,onOpenChange:Dt,isMobile:p})}):null]})},(e,t)=>uM({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&dM(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&dM(e.nextMessage?{info:e.nextMessage.info,parts:e.nextMessage.parts}:void 0,t.nextMessage?{info:t.nextMessage.info,parts:t.nextMessage.parts}:void 0)&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&yM(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,qL(e.message.info).isUser)),LR=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},RR=e=>{let t=e?.type;return t===`compaction`?!Ie(e):t===`text`&&LR(e).trim()===`/compact`},zR=e=>e?e.some(e=>RR(e)):!1,BR=e=>zR(e.parts),VR=e=>e?zR(e.sourceParts)||zR(e.parts):!1,HR=e=>{if(!BR(e))return e;let t=!1,n=e.parts.map(e=>e?.type!==`compaction`||Ie(e)?e:(t=!0,{type:`text`,text:`/compact`})),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},UR=e=>{let t=yk(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},WR=new WeakMap,GR=e=>{let t=WR.get(e);if(t)return t;let n=HR(UR(e)),r=n.parts,i=Ti(r),a=i===r?n:{...n,parts:i,sourceParts:r};return WR.set(e,a),a},KR={activity:`idle`,hasWorkingContext:!1,hasActiveTools:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,lifecyclePhase:null,statusText:null,isGenericStatus:!0,isWaitingForPermission:!1,canAbort:!1,compactionDeadline:null,activePartType:void 0,activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:null,turnStartedAt:void 0},qR=[],JR=`\0`,YR=new Set([`edit`,`write`,`apply_patch`]),XR={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`,execute:`chat.assistantStatus.executing`,session_rename:`chat.assistantStatus.renamingSession`,session_move:`chat.assistantStatus.movingSession`,browser:`chat.assistantStatus.usingBrowser`},ZR=[`chat.assistantStatus.working`,`chat.assistantStatus.processing`,`chat.assistantStatus.preparing`,`chat.assistantStatus.warmingUp`,`chat.assistantStatus.gearsTurning`,`chat.assistantStatus.computing`,`chat.assistantStatus.calculating`,`chat.assistantStatus.analyzing`,`chat.assistantStatus.wheelsSpinning`,`chat.assistantStatus.calibrating`,`chat.assistantStatus.synthesizing`,`chat.assistantStatus.connectingDots`,`chat.assistantStatus.inspectingLogic`,`chat.assistantStatus.weighingOptions`],QR=(e,t)=>{let n=XR[ju(e)];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},$R=e=>{let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)},ez=(e,t)=>t(ZR[$R(e)%ZR.length]??`chat.assistantStatus.working`),tz=(e,t,n)=>{let r,i;if(!Pr(e))for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)switch(n.type){case`reasoning`:{let e=n.time??sz(n);(!e||e.end===void 0)&&!r&&(r=`reasoning`);break}case`tool`:{let e=n.state?.status;if((e===`running`||e===`pending`)&&!r){let e=ju(cz(n));YR.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=oz(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=sz(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?n(`chat.assistantStatus.editingFile`):r===`tool`&&i?QR(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):ez(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},nz=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(JR),rz=e=>{let[t,n,r=`working`,i]=e.split(JR);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},iz=e=>e.type===`reasoning`,az=e=>e.type===`text`,oz=e=>{if(az(e))return e.text;let t=e;if(typeof t.text==`string`)return t.text;if(typeof t.content==`string`)return t.content;if(typeof t.value==`string`)return t.value},sz=e=>(az(e)||iz(e),e.time),cz=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function lz(e,t){let{t:n}=fr(),r=Wa(e=>e.currentSessionId),i=Wa(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Fi(e=>!!(a&&e.session_execution_recovery[a]),o??void 0),c=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),l=Wa(c),u=Na(a??``,o??void 0),d=Z.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`assistant`)return{id:t.id,index:e,finish:t.finish,error:t.error,isCompaction:t.clientRole===`compaction`,startedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,finish:void 0,error:void 0,isCompaction:!1,startedAt:void 0}},[u]),f=d.id,p=Z.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`user`&&!Oe(t))return{id:t.id,index:e,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,turnStartedAt:void 0}},[u]),m=p.id,h=ua(f??``,o??void 0,a??void 0),g=ua(m??``,o??void 0,a??void 0),_=!!m&&zR(g),v=d.isCompaction&&d.index>p.index?h.find(e=>e.type===`compaction`):void 0,y=v?.reason===`manual`?d.startedAt:p.turnStartedAt,b=!!(f&&d.index>p.index&&(v?v.status===`failed`||v.reason===`manual`&&v.status===`completed`:SF(d.finish,h,d.error))),x=Z.useMemo(()=>{let e=`${a??``}:${f??``}`;return nz(tz(f&&!d.error&&d.index>p.index?h:qR,e,n))},[a,f,d.error,d.index,p.index,h,n]),S=ha(a??``,o??void 0),C=Ka(a??``,o??void 0),w=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),T=Wa(w),{phase:E,isWorking:D}=Cx(a,o??void 0),O=!!(d.error&&d.index>p.index),k=Fa(a??``,o??void 0),A=k?.type===`retry`?k.attempt:void 0,j=k?.type===`retry`?k.next:void 0,M=Z.useMemo(()=>rz(x),[x]),N=Z.useMemo(()=>{let e=!!(T&&!T.acknowledged);return{wasAborted:e,abortActive:e}},[T]),P=Z.useMemo(()=>{if(s)return{...KR,isRecovering:!0,canAbort:D};if(O&&E!==`retry`)return{...KR,isTurnSettled:!0,canAbort:D};if(N.wasAborted)return{...KR,wasAborted:!0,abortActive:N.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(b)return{...KR,isComplete:v?.status!==`failed`,isTurnSettled:!0,turnStartedAt:y};let e=D,t=E===`busy`,r=E===`retry`,i=e&&(_||v?.status===`running`),a=`idle`;e&&(a=!i&&(M.activePartType===`tool`||M.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:A,next:j,message:k?.type===`retry`?k.message:void 0}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(M.activePartType===`tool`||M.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):M.statusText:null,isGenericStatus:!e||!i&&M.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?M.activePartType:void 0,activeToolName:e&&!i?M.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:o,turnStartedAt:y}},[s,O,E,D,b,_,v?.status,y,M,N,A,j,k,n]);return{forming:Z.useMemo(()=>({isActive:!s&&!O&&D&&M.activePartType===`text`,characterCount:0}),[s,O,D,M.activePartType]),working:Z.useMemo(()=>{if(s||P.wasAborted||P.abortActive)return P;if(l)return{...P,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!0,activePartType:void 0,activeToolName:void 0,isComplete:!1,isTurnSettled:!1,retryInfo:null};let e=S.length>0,t=C.length>0;return!e&&!t?P:t?{...P,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...P,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[s,P,l,S,C,n])}}var uz=Z.memo(()=>{let e=(0,Q.c)(15),t=Zb(),n=Wa(dz),r=Wa(fz),i=t.sessionId??n,a=t.directory??r??void 0,o;e[0]===i?o=e[1]:(o=e=>i?e.sessionAbortFlags?.get(i)??null:null,e[0]=i,e[1]=o);let s=Wa(o),c=Wa(pz),l=Wa(mz),{working:u}=lz(i,a),d=ei(hz),f=!!(s&&!s.acknowledged),p=!!(i&&c===i&&typeof l==`number`&&l>Date.now()),m=u.isWaitingForPermission||!!u.retryInfo||f||u.wasAborted||u.isWorking;if(u.isRecovering)return null;let h=f||u.wasAborted,g=f||u.abortActive,_;return e[2]!==d||e[3]!==p||e[4]!==m||e[5]!==h||e[6]!==g||e[7]!==u.isGenericStatus||e[8]!==u.isTurnSettled||e[9]!==u.isWaitingForPermission||e[10]!==u.isWorking||e[11]!==u.retryInfo||e[12]!==u.statusText||e[13]!==u.turnStartedAt?(_=(0,$.jsx)(nx,{isWorking:u.isWorking,statusText:u.statusText,isGenericStatus:u.isGenericStatus,isWaitingForPermission:u.isWaitingForPermission,wasAborted:h,abortActive:g,retryInfo:u.retryInfo,turnStartedAt:u.turnStartedAt,isTurnSettled:u.isTurnSettled,showAbortPrompt:p,showAssistantStatus:m,showTodos:!1,agentName:d}),e[2]=d,e[3]=p,e[4]=m,e[5]=h,e[6]=g,e[7]=u.isGenericStatus,e[8]=u.isTurnSettled,e[9]=u.isWaitingForPermission,e[10]=u.isWorking,e[11]=u.retryInfo,e[12]=u.statusText,e[13]=u.turnStartedAt,e[14]=_):_=e[14],_});uz.displayName=`StatusRowContainer`;function dz(e){return e.currentSessionId}function fz(e){return e.currentSessionDirectory}function pz(e){return e.abortPromptSessionId}function mz(e){return e.abortPromptExpiresAt}function hz(e){return e.currentAgentName}var gz=(e,t)=>{if(typeof e!=`object`||!e)return;let n=e[t];if(typeof n!=`string`)return;let r=n.trim();return r.length>0?r:void 0},_z=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},vz=Z.memo(e=>{let t=(0,Q.c)(36),{assistantMessage:n,userMessage:r,pendingPresentation:i,assistantIsInActiveTurn:a,isMobile:o}=e,s=ei(yz),c=ei(oe(bz)),l=n?.info.sessionID??r?.info.sessionID,u;t[0]!==a||t[1]!==l?(u=e=>({currentContextAgent:a&&l?e.currentAgentContext.get(l):void 0,savedSessionAgentSelection:a&&l?e.sessionAgentSelections.get(l):void 0}),t[0]=a,t[1]=l,t[2]=u):u=t[2];let{currentContextAgent:d,savedSessionAgentSelection:f}=ny(oe(u)),p;t[3]===r?p=t[4]:(p=r?rR(r.info):null,t[3]=r,t[4]=p);let m=p,h;t[5]===n?h=t[6]:(h=n?rR(n.info):null,t[5]=n,t[6]=h);let g=h,_;t[7]!==n||t[8]!==d||t[9]!==i?.agentName||t[10]!==f||t[11]!==m?.agentName?(_=()=>n?gz(n.info,`mode`)??gz(n.info,`agent`)??m?.agentName??d??f:i?.agentName??m?.agentName,t[7]=n,t[8]=d,t[9]=i?.agentName,t[10]=f,t[11]=m?.agentName,t[12]=_):_=t[12],i?.agentName,m?.agentName;let v;t[13]===_?v=t[14]:(v=_(),t[13]=_,t[14]=v);let y=v,b;t[15]!==y||t[16]!==l?(b=e=>{if(l&&y){let t=e.getAgentModelForSession(l,y);if(t?.providerId&&t.modelId)return t}if(!l)return null;let t=e.getSessionModelSelection(l);return t?.providerId&&t.modelId?t:null},t[15]=y,t[16]=l,t[17]=b):b=t[17];let x=Oi(b),S=!n||a,C;t[18]!==g||t[19]!==c||t[20]!==x||t[21]!==S||t[22]!==m?(C=aR({assistantIdentity:g,userIdentity:m,sessionSelection:x,composerSelection:c,allowComposerFallback:S}),t[18]=g,t[19]=c,t[20]=x,t[21]=S,t[22]=m,t[23]=C):C=t[23];let w=C,T=w?.providerId,E=w?.modelId,D=_z(y),O=_z(T),k=_z(E),A;if(t[24]!==i?.modelName||t[25]!==s||t[26]!==k||t[27]!==O){let e=O?s.find(e=>e.id===O):void 0;A=Ki(e,k??null)||i?.modelName||void 0,t[24]=i?.modelName,t[25]=s,t[26]=k,t[27]=O,t[28]=A}else A=t[28];let j=A,M=g?.variant??m?.variant??i?.variant,N=O??null,P=k??null,F=D??void 0,I;return t[29]!==o||t[30]!==j||t[31]!==N||t[32]!==P||t[33]!==F||t[34]!==M?(I=(0,$.jsx)(wA,{isUser:!1,isMobile:o,providerID:N,modelID:P,agentName:F,modelName:j,variant:M}),t[29]=o,t[30]=j,t[31]=N,t[32]=P,t[33]=F,t[34]=M,t[35]=I):I=t[35],I});function yz(e){return e.providers}function bz(e){return{providerId:e.currentProviderId,modelId:e.currentModelId}}var xz=Z.memo(e=>{let t=(0,Q.c)(19),{assistantMessages:n,messages:r,activityExpanded:i,renderMessage:a}=e,o;bb0:{let e=+(r[0]?.role===`user`);if(!r.some((t,n)=>n>=e&&t.role!==`assistant`)){o=n;break bb0}let i;t[0]===n?i=t[1]:(i=new Set(n.map(Sz)),t[0]=n,t[1]=i);let a=i,s;if(t[2]!==r||t[3]!==e||t[4]!==a){let n;t[6]!==e||t[7]!==a?(n=(t,n)=>n>=e&&(t.role!==`assistant`||a.has(t.messageId))?[t.message]:[],t[6]=e,t[7]=a,t[8]=n):n=t[8],s=r.flatMap(n),t[2]=r,t[3]=e,t[4]=a,t[5]=s}else s=t[5];o=s}let s=o,c;if(t[9]!==i||t[10]!==a||t[11]!==s){let e;t[13]!==i||t[14]!==a?(e=e=>a(e,i),t[13]=i,t[14]=a,t[15]=e):e=t[15],c=s.map(e),t[9]=i,t[10]=a,t[11]=s,t[12]=c}else c=t[12];let l;return t[16]!==i||t[17]!==c?(l=(0,$.jsx)(`div`,{className:`relative z-0`,"data-turn-assistant-activity-expanded":i,children:c}),t[16]=i,t[17]=c,t[18]=l):l=t[18],l});function Sz(e){return e.info.id}var Cz=e=>{let t=(0,Q.c)(13),{sessionId:n,directory:r,hasInlineError:i,fallbackHeader:a}=e,o=i!==void 0&&i,{t:s}=fr(),c=_a(n),l=Za(n,r??void 0),u;if(t[0]===n?u=t[1]:(u=e=>!!(e.session_execution_recovery[n]||e.session_status[n]?.type===`retry`),t[0]=n,t[1]=u),Fi(u,r??void 0)||l===void 0||!c||o||c.directory&&r&&c.directory!==r)return null;let d;t[2]!==c.error||t[3]!==s?(d=ZL(c.error,s)??{text:s(`chat.chatInput.toast.messageSendFailed`),icon:`error-warning`,variant:`error`},t[2]=c.error,t[3]=s,t[4]=d):d=t[4];let f=d,p;t[5]===a?p=t[6]:(p=a?(0,$.jsx)(`div`,{className:`pb-2`,children:a}):null,t[5]=a,t[6]=p);let m;t[7]===f?m=t[8]:(m=(0,$.jsx)(Ov,{presentation:f}),t[7]=f,t[8]=m);let h;return t[9]!==n||t[10]!==p||t[11]!==m?(h=(0,$.jsxs)(`div`,{className:`chat-message-column py-1.5`,"data-session-error":n,children:[p,m]}),t[9]=n,t[10]=p,t[11]=m,t[12]=h):h=t[12],h},wz=new Set,Tz=()=>{},Ez=()=>{},Dz=Z.memo(e=>{let t=(0,Q.c)(53),{turn:n,showSessionError:r,activityExpanded:i,showCompactionStatus:a,pendingAssistantHeader:o,assistantHeaderMessage:s,assistantHeaderIsInActiveTurn:c,preserveActiveTurnGap:l,onToggleActivity:u,stickyUserHeader:d,renderMessage:f}=e,p=r!==void 0&&r,m=o===void 0?null:o,h=c!==void 0&&c,g=l!==void 0&&l,_=d===void 0||d,v=q(Oz),y=Zb(),b=n.userMessage?.info.time?.created,x=n.userMessage??n.assistantMessages[0],S=n.activityPresentationKind===`compaction`,C;t[0]===n.userMessage?C=t[1]:(C=n.userMessage&&_R(n.userMessage),t[0]=n.userMessage,t[1]=C);let w=!!C,T=`relative w-full ${g?`pb-1`:`pb-8`}`,E=`turn-${n.turnId}`,D=n.userMessageId??n.turnId,O;t[2]!==i||t[3]!==S||t[4]!==w||t[5]!==f||t[6]!==_||t[7]!==n.userMessage?(O=!n.userMessage||S?null:_&&!w?(0,$.jsxs)(`div`,{className:`sticky top-0 z-20 relative bg-[var(--surface-background)] [overflow-anchor:none]`,children:[(0,$.jsx)(`div`,{className:`relative z-10`,children:f(n.userMessage,i)}),(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-full z-0 h-4 bg-gradient-to-b from-[var(--surface-background)] to-transparent sm:h-8`})]}):f(n.userMessage,i),t[2]=i,t[3]=S,t[4]=w,t[5]=f,t[6]=_,t[7]=n.userMessage,t[8]=O):O=t[8];let k;t[9]!==h||t[10]!==s||t[11]!==v||t[12]!==w||t[13]!==m||t[14]!==_||t[15]!==n.userMessage?(k=!w&&(m||s)?(0,$.jsx)(`div`,{className:`group w-full ${v?_?`pt-4`:`pt-0`:`pt-6`} pb-0`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(vz,{assistantMessage:s,userMessage:n.userMessage,pendingPresentation:m,assistantIsInActiveTurn:h,isMobile:v})})}):null,t[9]=h,t[10]=s,t[11]=v,t[12]=w,t[13]=m,t[14]=_,t[15]=n.userMessage,t[16]=k):k=t[16];let A;t[17]!==i||t[18]!==v||t[19]!==u||t[20]!==a||t[21]!==n.completionDisposition||t[22]!==n.durationMs||t[23]!==b?(A=a?(0,$.jsx)(`div`,{className:`group w-full ${v?`pt-4`:`pt-6`} pb-0`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(hL,{parts:[],isExpanded:i,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof b==`number`?b:void 0,onToggle:u,isMobile:v,expandedTools:wz,onToggleTool:Tz,onShowPopup:Ez,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[17]=i,t[18]=v,t[19]=u,t[20]=a,t[21]=n.completionDisposition,t[22]=n.durationMs,t[23]=b,t[24]=A):A=t[24];let j;t[25]!==i||t[26]!==f||t[27]!==n.assistantMessages||t[28]!==n.messages?(j=(0,$.jsx)(xz,{assistantMessages:n.assistantMessages,messages:n.messages,activityExpanded:i,renderMessage:f}),t[25]=i,t[26]=f,t[27]=n.assistantMessages,t[28]=n.messages,t[29]=j):j=t[29];let M;t[30]!==s||t[31]!==v||t[32]!==w||t[33]!==m||t[34]!==p||t[35]!==x||t[36]!==y||t[37]!==n.assistantMessages||t[38]!==n.userMessage?(M=p&&x&&y.active&&y.capabilities.compose&&(!y.sessionId||y.sessionId===x.info.sessionID)?(0,$.jsx)(Cz,{sessionId:x.info.sessionID,directory:x.sourceDirectory??y.directory,hasInlineError:!!n.assistantMessages.at(-1)?.info.error,fallbackHeader:!w&&!m&&!s?(0,$.jsx)(vz,{userMessage:n.userMessage,pendingPresentation:oR(rR(x.info)),assistantIsInActiveTurn:!1,isMobile:v}):void 0}):null,t[30]=s,t[31]=v,t[32]=w,t[33]=m,t[34]=p,t[35]=x,t[36]=y,t[37]=n.assistantMessages,t[38]=n.userMessage,t[39]=M):M=t[39];let N;t[40]!==k||t[41]!==A||t[42]!==j||t[43]!==M?(N=(0,$.jsxs)(`div`,{className:`yuri-message-hover-scope`,...IT,children:[k,A,j,M]}),t[40]=k,t[41]=A,t[42]=j,t[43]=M,t[44]=N):N=t[44];let P;return t[45]!==i||t[46]!==O||t[47]!==N||t[48]!==T||t[49]!==E||t[50]!==D||t[51]!==n.turnId?(P=(0,$.jsxs)(`section`,{className:T,id:E,"data-turn-id":n.turnId,"data-turn-activity-expanded":i,"data-scroll-spy-id":D,children:[O,N]}),t[45]=i,t[46]=O,t[47]=N,t[48]=T,t[49]=E,t[50]=D,t[51]=n.turnId,t[52]=P):P=t[52],P});function Oz(e){return e.isMobile}var kz=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,Az=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},jz=e=>{let t=e.text;if(typeof t==`string`&&xk(t))return t;let n=e.content;if(typeof n==`string`&&xk(n))return n},Mz=(e,t,n,r)=>({id:kz(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:Az(n)}),Nz=e=>{let t=[],n=new Map,r=!1,i=!1;e.assistantMessages.forEach(e=>{e.parts.forEach(e=>{if(e.type===`tool`){r=!0;return}e.type===`reasoning`&&jz(e)&&(i=!0)})});let a=e.assistantMessages.at(-1),o=a?xF(a.parts):-1;e.assistantMessages.forEach(r=>{let i=[];r.parts.forEach((n,s)=>{let c=n.type===`tool`,l=n.type===`reasoning`||n.type===`text`?jz(n):void 0,u=r===a&&s===o,d=null;if(c?d=`tool`:n.type===`reasoning`?d=`reasoning`:e.showTextJustificationActivity&&n.type===`text`&&l&&!u&&(d=`justification`),!d)return;let f={...Mz(e.turnId,r.info.id,n,s),kind:d};t.push(f),i.push(f)}),n.set(r.info.id,i)});let s=[],c=e.messages??e.assistantMessages.map(e=>({role:`assistant`,messageId:e.info.id,message:e})),l;for(let t of c){if(t.role!==`assistant`){if(t.message.info.nativeType===`synthetic`&&!QL(t.message.info)&&!Fk(t.message.parts))continue;l=void 0;continue}l||(l={id:t.messageId===e.assistantMessages[0]?.info.id?`${e.turnId}:activity`:`${e.turnId}:activity:${t.messageId}`,anchorMessageId:t.messageId,afterToolPartId:null,parts:[]},s.push(l)),l.parts.push(...n.get(t.messageId)??[])}let u=s.filter(e=>e.parts.length>0);return u.length===1&&(u[0].parts=t),{activityParts:t,activitySegments:u,hasTools:r,hasReasoning:i}},Pz=e=>{let t=new Map,n=new Map,r=new Map,i=new Set;e.forEach(e=>{t.set(e.turnId,e);let a=e.assistantMessages[0]?.info.id,o=e.assistantMessages[e.assistantMessages.length-1]?.info.id;e.userMessageId&&(n.set(e.userMessageId,e.turnId),i.add(e.userMessageId),r.set(e.userMessageId,{turnId:e.turnId,messageId:e.userMessageId,userMessageId:e.userMessageId,isUserMessage:!0,isAssistantMessage:!1,isFirstAssistantInTurn:!1,isLastAssistantInTurn:!1,headerMessageId:e.headerMessageId})),e.assistantMessageIds.forEach(t=>{n.set(t,e.turnId),i.add(t),r.set(t,{turnId:e.turnId,messageId:t,userMessageId:e.userMessageId,isUserMessage:!1,isAssistantMessage:!0,isFirstAssistantInTurn:t===a,isLastAssistantInTurn:t===o,headerMessageId:e.headerMessageId})});for(let t of e.messages)t.messageId!==e.userMessageId&&t.role!==`assistant`&&(n.set(t.messageId,e.turnId),r.set(t.messageId,{turnId:e.turnId,messageId:t.messageId,userMessageId:e.userMessageId,isUserMessage:!1,isAssistantMessage:!1,isFirstAssistantInTurn:!1,isLastAssistantInTurn:!1,headerMessageId:e.headerMessageId}))});let a=e.length>0?e[e.length-1]:null,o=new Set;return a&&(a.userMessageId&&o.add(a.userMessageId),a.messages.forEach(e=>{o.add(e.messageId)})),{turns:e,indexes:{turnById:t,messageToTurnId:n,messageMetaById:r},lastTurnId:a?.turnId??null,lastTurnMessageIds:o,ungroupedMessageIds:new Set}},Fz=e=>{let t=e.text;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.content;if(typeof n==`string`&&n.trim().length>0)return n},Iz=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(yF(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!bF(t))continue;let r=Fz(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:kz(n.info.id,t,e)}}}for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||t.type!==`text`)continue;let r=Fz(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:kz(n.info.id,t,e)}}}return{}},Lz=e=>{let t=e.info.summary,n=t?.diffs,r=Array.isArray(n)?n:[],i=typeof t?.diffCount==`number`&&Number.isFinite(t.diffCount)?Math.max(0,Math.trunc(t.diffCount)):void 0,a=0,o=0,s=0;r.forEach(e=>{if(!e)return;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;(t!==0||n!==0)&&(s+=1),a+=t,o+=n});let c=i??s,l=t?.hasDiffs===!0||c>0||r.length>0;if(l)return{additions:a,deletions:o,files:c,hasDiffs:l}},Rz=e=>{let t=e.info.summary?.diffs;if(!Array.isArray(t)||t.length===0)return;let n=t.map(e=>{if(!e||typeof e.file!=`string`||e.file.trim().length===0)return null;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;return t===0&&n===0?null:{file:e.file,additions:t,deletions:n}}).filter(e=>e!==null);return n.length>0?n:void 0},zz=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},Bz=e=>e.info.nativeType===`synthetic`,Vz=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},Hz=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},Uz=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},Wz=e=>{let t=e.info.time?.streamed;return typeof t==`number`&&Number.isFinite(t)?t:void 0},Gz=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},Kz=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},qz=(e,t)=>{let n=zz(e);return{messageId:e.info.id,role:n,parentMessageId:Vz(e),message:e,order:t}},Jz=(e,t)=>{let n=e?Hz(e):void 0,r,i,a,o=!1;t.forEach(e=>{let t=Uz(e);typeof t==`number`?r=Math.max(r??0,t):o=!0;let n=Wz(e);typeof n==`number`&&(i=Math.max(i??0,n)),e.parts.forEach(e=>{let t=Gz(e);typeof t==`number`&&(a=Math.max(a??0,t))})});let s=r??i??a,c=typeof n==`number`&&typeof s==`number`&&s>=n?s-n:void 0;return{isStreaming:o,isRetrying:t.length>1,startedAt:n,completedAt:r,durationMs:c}},Yz=e=>{if(e.length===0)return`active`;let t=e[e.length-1];if(!t)return`active`;let n=t.info.finish;if(t.info.error)return`abnormal`;if(n===`tool-calls`||vF(t.parts)>0)return`active`;if(n===`stop`)return`normal`;if(typeof n==`string`&&n.length>0)return`abnormal`;for(let t of e)if(typeof Uz(t)!=`number`)return`active`;return`active`},Xz=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return SF(n.finish,t.parts,n.error)},Zz=e=>VR(e)?`compaction`:`default`,Qz={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},$z=(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].message!==t[n].message)return!1;return!0},eB=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&$z(e.messages,t.messages),tB=(e,t)=>{e.summary=Iz(e.assistantMessages),e.summaryText=e.summary.text??(e.userMessage?Kz(e.userMessage):void 0),e.diffStats=e.userMessage?Lz(e.userMessage):void 0,e.changedFiles=t.showTurnChangedFiles&&e.userMessage?Rz(e.userMessage):void 0,e.completionDisposition=Yz(e.assistantMessages),e.hasConfirmedFinalBody=Xz(e.assistantMessages);for(let t=e.messages.length-1;t>=0;--t){let n=e.messages[t];if(n.role===`assistant`)break;if(n.role!==`compaction`)continue;let r=n.message.parts.find(Ie);r?.reason===`auto`&&r.status!==`failed`&&(e.completionDisposition=`active`,e.hasConfirmedFinalBody=!1);break}e.activityPresentationKind=e.userMessage?Zz(e.userMessage):`default`;let n=Nz({turnId:e.turnId,assistantMessages:e.assistantMessages,messages:e.messages,showTextJustificationActivity:t.showTextJustificationActivity}),r=t.previousProjection?.indexes.turnById.get(e.turnId);if(r){let e=new Map(r.activitySegments.map(e=>[e.anchorMessageId,e]));for(let t of n.activitySegments)for(let n of t.parts){let r=e.get(n.messageId);if(r){t.id=r.id,t.anchorMessageId=r.anchorMessageId;break}}}return e.activityParts=n.activityParts,e.activitySegments=n.activitySegments,e.hasTools=n.hasTools,e.hasReasoning=n.hasReasoning,e.stream=Jz(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},nB=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>tB(e,t));let r=n.turns.length===e.length,i=!1,a=e.map((e,a)=>{let o=n.indexes.turnById.get(e.turnId);return o&&eB(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,tB(e,t))});return r&&i?n.turns:a},rB=e=>{if(e.length<=1)return e;let t=!1,n=e.map((n,r)=>{if(r===e.length-1||n.completionDisposition!==`active`||(e[r+1]?.assistantMessages.length??0)===0)return n;t=!0;let i=e[r+1]?.startedAt,a=n.durationMs,o=n.completedAt;return typeof a!=`number`&&typeof n.startedAt==`number`&&typeof i==`number`&&i>=n.startedAt&&(o=i,a=i-n.startedAt),{...n,completionDisposition:`abnormal`,completedAt:o,durationMs:a,stream:{...n.stream,isStreaming:!1,completedAt:o??n.stream.completedAt,durationMs:a}}});return t?n:e},iB=(e,t)=>{let n={...Qz,...t},r=[],i=new Map,a=new Map,o=new Set;e.forEach((e,t)=>{let n=zz(e);if(n===`compaction`&&r.length>0){a.set(e.info.id,r[r.length-1]),o.add(e.info.id);return}let s=n===`assistant`&&r.length===0&&!Vz(e);if(n!==`user`&&!s)return;if(r.length>0&&Bz(e)){a.set(e.info.id,r[r.length-1]),o.add(e.info.id);return}let c={turnId:e.info.id,userMessageId:s?void 0:e.info.id,userMessage:s?void 0:e,headerMessageId:void 0,messages:s?[]:[qz(e,t)],assistantMessageIds:[],assistantMessages:[],activityParts:[],activitySegments:[],summary:{},summaryText:void 0,hasTools:!1,hasReasoning:!1,diffStats:void 0,changedFiles:void 0,stream:{isStreaming:!1,isRetrying:!1},completionDisposition:`active`,activityPresentationKind:`default`,hasConfirmedFinalBody:!1};r.push(c),c.userMessageId&&(i.set(c.userMessageId,c),o.add(e.info.id))});let s=r[0]?.userMessage?void 0:r[0];e.forEach((e,t)=>{let n=zz(e),r=i.get(e.info.id);r&&(s=r);let c=a.get(e.info.id);if(c){c.messages.push(qz(e,t));return}if(n!==`assistant`)return;let l=Vz(e),u=l?i.get(l):s;u&&(u.assistantMessages.push(e),u.assistantMessageIds.push(e.info.id),u.messages.push(qz(e,t)),u.headerMessageId||=e.info.id,o.add(e.info.id))});let c=n.previousProjection;if(c)for(let e of r)for(let t of e.assistantMessages){let n=c.indexes.messageToTurnId.get(t.info.id),r=n?c.indexes.turnById.get(n):void 0;if(r&&(!r.userMessage||r.userMessageId===e.userMessageId)){e.turnId=r.turnId,r.headerMessageId&&e.assistantMessageIds.includes(r.headerMessageId)&&(e.headerMessageId=r.headerMessageId);break}}let l=Pz(rB(nB(r,n))),u=new Set;return e.forEach(e=>{o.has(e.info.id)||zz(e)===`assistant`&&Vz(e)||u.add(e.info.id)}),{...l,ungroupedMessageIds:u}},aB=30,oB=4,sB=4,cB=33554432,lB=8388608,uB=new Map,dB=new Map,fB=0,pB=new WeakMap,mB=1,hB=()=>E()?oB:vi()?sB:aB,gB=()=>E()||vi()?lB:cB,_B=(e,t)=>{let n=e.length*2+256;for(let e of t.turns)n+=512,n+=e.messages.length*160,n+=e.activityParts.length*128,n+=(e.changedFiles?.length??0)*160,n+=(e.summaryText?.length??0)*2;return n},vB=e=>{uB.delete(e);let t=dB.get(e)??0;dB.delete(e),fB=Math.max(0,fB-t)},yB=e=>{let t=pB.get(e);if(t!==void 0)return t;let n=mB;return mB+=1,pB.set(e,n),n},bB=e=>e.map(e=>`${yB(e.info)}:${yB(e.parts)}:${e.parts.map(e=>yB(e)).join(`,`)}`).join(`;`),xB=(e,t,n,r)=>{let i=t.length>0?t[t.length-1]:void 0,a=i?.info?.id??``,o=i?.parts?.length??0;return[e,t.length,a,o,bB(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},SB=e=>{let t=uB.get(e);return t&&(uB.delete(e),uB.set(e,t)),t},CB=(e,t)=>{vB(e);let n=hB(),r=gB(),i=_B(e,t);if(!(i>r)){for(;uB.size>=n||fB+i>r;){let e=uB.keys().next().value;if(typeof e!=`string`)break;vB(e)}uB.set(e,t),dB.set(e,i),fB+=i}},wB=[],TB=(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},EB=e=>{if(!e.hasLiveTail)return null;if(e.turnCount===0)return e.previousStart;let t=e.previousStart??e.turnCount-1,n=Math.min(Math.max(t,0),e.turnCount-1);return!e.liveTailActive&&e.turnCount-n>12?e.turnCount-1:n},DB=(e,t)=>t===null?{staticTurns:e,streamingTurns:wB}:{staticTurns:t===0?wB:e.slice(0,t),streamingTurns:e.slice(t)},OB=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(wB),a=Z.useRef(null),o=Z.useRef(t.sessionKey),s=Z.useRef(t.showTextJustificationActivity),c=Z.useRef(t.showTurnChangedFiles);(o.current!==t.sessionKey||s.current!==t.showTextJustificationActivity||c.current!==t.showTurnChangedFiles)&&(o.current=t.sessionKey,s.current=t.showTextJustificationActivity,c.current=t.showTurnChangedFiles,n.current=null,r.current=[],i.current=wB,a.current=null);let l=Z.useMemo(()=>{let r=xB(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=SB(r);return i&&(!n.current||i===n.current)?(n.current=i,i):we(`ui.turns.projection_ms`,()=>{let i=iB(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,CB(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=a.current?.turnId,d=Z.useMemo(()=>u?l.turns.findIndex(e=>e.turnId===u):-1,[l.turns,u]),f=EB({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:d>=0?d:a.current?.index??null});return f===null?a.current=null:l.turns[f]&&(a.current={turnId:l.turns[f].turnId,index:f}),{projection:l,staticTurns:Z.useMemo(()=>{let e=DB(l.turns,f).staticTurns;return TB(r.current,e)?r.current:r.current=e},[f,l.turns]),streamingTurns:Z.useMemo(()=>{let e=DB(l.turns,f).streamingTurns;return TB(i.current,e)?i.current:i.current=e},[f,l.turns])}},kB=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},AB=(e,t)=>{if(!t.sessionId)return e;let n={name:`SessionRetry`,message:t.message,data:{message:t.message}},r=-1;for(let t=e.length-1;t>=0;--t)if(kB(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(kB(e[t])===`assistant`){i=t;break}if(i>=0)return e[i].info.error?e:e.map((e,t)=>t===i?{...e,info:{...e.info,error:n}}:e);let a=typeof t.confirmedAt==`number`?t.confirmedAt:t.fallbackTimestamp,o={info:{id:`synthetic_retry_notice_${t.sessionId}`,sessionID:t.sessionId,role:`assistant`,time:{created:a,completed:a},finish:`stop`,error:n},parts:[]},s=e.slice();return s.splice(r+1,0,o),s},jB=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=ct(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:GR({...e,parts:r})},MB=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=jB(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=jB(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=new Map(i.map(e=>[e.info.id,e])),o=iB(e.turn.messages.map(e=>a.get(e.messageId)??e.message),{showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles}).turns[0]??{...e.turn,assistantMessages:i,assistantMessageIds:i.map(e=>e.info.id)};return{...e,turn:o}},NB=[],PB=(e,t)=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===t}),FB=(e,t)=>{let n=e[t];return{kind:`ungrouped`,key:`msg:${n.info.id}`,message:n,previousMessage:t>0?e[t-1]:void 0,nextMessage:t<e.length-1?e[t+1]:void 0}},IB=(e,t,n,r)=>{let i=new Map;for(let e of t){let t=e.userMessage??e.assistantMessages?.[0];t&&i.set(t.info.id,e)}let a=[];for(let t=0;t<e.length;t+=1){let o=e[t],s=i.get(o.info.id);if(s){a.push(PB(s,r));continue}n.has(o.info.id)&&a.push(FB(e,t))}return a};function LB(e){let{messages:t,turns:n,streamingTurns:r,ungroupedMessageIds:i,lastTurnId:a}=e;if(i.size===0){if(r.length===0)return{history:n.map(e=>PB(e,a)),tail:NB};let e=r[0].turnId,t=n.findIndex(t=>t.turnId===e);return t<0?{history:n.map(e=>PB(e,a)),tail:r.map(e=>PB(e,a))}:{history:n.slice(0,t).map(e=>PB(e,a)),tail:n.slice(t).map(e=>PB(e,a))}}let o=IB(t,n,i,a);if(r.length===0){let e=t[t.length-1];if(!e||!i.has(e.info.id))return{history:o,tail:NB};let n=o.find(t=>t.kind===`ungrouped`&&t.message.info.id===e.info.id);return{history:n?o.filter(e=>e!==n):o,tail:n?[n]:NB}}let s=r[0].turnId,c=o.findIndex(e=>e.kind===`turn`&&e.turn.turnId===s);return c<0?{history:o,tail:r.map(e=>PB(e,a))}:{history:o.slice(0,c),tail:o.slice(c)}}var RB=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},zB=2,BB=2,VB=2,HB=e=>Math.min(Math.max(0,e),zB),UB=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+BB),WB=(e,t,n,r)=>{let i=dd(e);if(n===null||!Number.isFinite(n)||!r||r<=0)return i;let a=r*VB,o=n-a,s=n+r+a;return i.filter(n=>{if(n>=e.startIndex-1&&n<=e.endIndex+1)return!0;let r=t[n];return!r||r.end>=o&&r.start<=s})},GB=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)($M.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},KB=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(rc.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},qB=12,JB=16,YB=new Map,XB=e=>{let t=YB.get(e);if(t)return YB.delete(e),YB.set(e,t),t},ZB=(e,t)=>{if(t.size!==0)for(YB.delete(e),YB.set(e,t);YB.size>JB;){let e=YB.keys().next().value;if(typeof e!=`string`)break;YB.delete(e)}},QB=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??qB)),r=new Set;for(let t=Math.max(0,e.length-n);t<e.length;t+=1){let n=e[t];n&&r.add(n)}let i=t?.restore;if(i&&i.size>0){let t=new Set(e);for(let e of i)t.has(e)&&r.add(e)}return r},$B=(e,t)=>{let n=t[t.length-1];if(!n||e.has(n))return e;let r=new Set(e);return r.add(n),r},eV=({entryKeys:e,mountedIndexes:t,visibleStartIndex:n,visibleEndIndex:r,scrollDirection:i,preloadEntries:a,hydratedKeys:o})=>{if(e.length===0||t.length===0)return{visible:[],preload:[]};let s=new Set(t),c=[],l=[],u=new Set,d=(t,n)=>{if(n<0||n>=e.length||!s.has(n))return;let r=e[n];!r||o.has(r)||u.has(r)||(u.add(r),t.push(r))},f=e.length-1,p=Math.min(f,Math.max(0,Math.floor(n))),m=Math.min(f,Math.max(p,Math.floor(r)));for(let e=m;e>=p;--e)d(c,e);let h=Math.max(0,Math.floor(a)),g=()=>{let e=Math.min(f,m+h);for(let t=m+1;t<=e;t+=1)d(l,t)},_=()=>{let e=Math.max(0,p-h);for(let t=p-1;t>=e;--t)d(l,t)};return i===`backward`?(_(),g()):(g(),_()),{visible:c,preload:l}},tV=e=>{let{visible:t,preload:n}=eV(e),r=n.slice(0,Math.max(0,Math.floor(e.preloadReleaseLimit)));if(!e.allowVisibleRelease)return r;let i=e.visibleReleaseLimit,a=typeof i==`number`&&i>0?t.slice(0,Math.floor(i)):t;return a.length>0?[...a,...r]:r},nV=(e,t)=>{let n=new Set(t),r=!1,i=new Set;for(let t of e)n.has(t)?i.add(t):r=!0;return r?i:e},rV=`data-markdown-ready`,iV=`data-markdown-hydration`,aV=`data-markdown-pin-reveal`,oV=e=>[...QB(e.entryKeys,{seedCount:e.seedCount,restore:e.restore})],sV=e=>e.reason===`jump-to-latest`||!e.alreadyRevealedForScope,cV=e=>{if(e.querySelector(`[data-markdown-hydration="deferred"]`))return!1;let t=e.querySelectorAll(`[data-markdown-content]`);if(t.length===0)return!0;for(let e of t)if(!e.closest(`[data-markdown-ready="true"]`))return!1;return!0},lV=(e,t)=>{if(t.size===0)return!0;let n=e.querySelectorAll(`[data-turn-entry]`),r=!1;for(let e of n){let n=e.getAttribute(`data-turn-entry`);if(!(!n||!t.has(n))&&(r=!0,!cV(e)))return!1}return r},uV=(e,t)=>{if(e){if(t){e.style.visibility=`hidden`,e.setAttribute(aV,`pending`);return}e.style.removeProperty(`visibility`),e.setAttribute(aV,`ready`)}},dV=(e,t)=>t?{...e,visibility:`hidden`}:e,fV=({root:e,relevantKeys:t,onReady:n,timeoutMs:r=600,signal:i})=>{let a=!1,o=()=>{a||(a=!0,d(),n())},s=()=>{if(i?.aborted){o();return}lV(e,t)&&o()},c=null;if(typeof MutationObserver<`u`){c=new MutationObserver(s);let t=e instanceof Element?e:e instanceof Document?e.documentElement:null;t&&c.observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[rV,iV,`data-turn-entry`]})}let l=null;r>0&&(l=setTimeout(o,r));let u=()=>o();i?.addEventListener(`abort`,u,{once:!0});let d=()=>{c?.disconnect(),c=null,l!==null&&(clearTimeout(l),l=null),i?.removeEventListener(`abort`,u)};return s(),queueMicrotask(s),()=>{a||(a=!0,d())}},pV=e=>{let t=new Map,n=!1,r=()=>{if(n=!1,t.size===0)return;let r=new Map(t);t.clear(),e(r)};return{enqueue(e,i){t.set(e,i),!n&&(n=!0,queueMicrotask(r))},flush:r,clear(){t.clear(),n=!1},pendingCount:()=>t.size}},mV=(e,t)=>{let n=e.resizeItem.bind(e),r=!1,i=pV(e=>{let i=()=>{for(let[t,r]of e)n(t,r)};r?i():((0,Sp.flushSync)(i),t?.())});return e.resizeItem=(e,t)=>{i.enqueue(e,t)},()=>{r=!0,e.resizeItem=n,i.flush()}},hV=(e,t,n)=>{let r=n.scrollOffset??0,i=n.itemSizeCache.get(e.key);return i===void 0?e.start<r:e.start+i<=r},gV=({scopeKey:e,generation:t=0,root:n,relevantKeys:r,enabled:i=!0,initiallyRevealed:a=!1})=>{let o=`${e}:${t}`,[s,c]=Z.useState(o),[l,u]=Z.useState(i&&!a),d=Z.useRef(new Set(a?[e]:[]));i&&s!==o&&(sV({reason:t>0&&s.startsWith(`${e}:`)?`jump-to-latest`:`session-open`,alreadyRevealedForScope:d.current.has(e)})&&u(!0),c(o)),!i&&l&&u(!1);let f=r.join(`\0`),p=Z.useMemo(()=>new Set(r),[f]),m=J(()=>{d.current.add(e),u(!1)});return cr(()=>{if(!i||!l){uV(n,!1);return}if(uV(n,!0),n)return fV({root:n,relevantKeys:p,onReady:m})},[i,l,n,p,o]),i&&l},_V=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},vV=(e,t)=>e,yV=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:cR(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),bV=()=>vi()?5:12,xV=16,SV=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),CV=320,wV=168,TV=8,EV=16,DV=6,OV=12,kV=4,AV=1,jV=2,MV=6,NV=4,PV=()=>vi()?EV:TV,FV=30,IV=180,LV=80,RV=160,zV=90,BV=(e,t)=>{if(e.length===0||t.length<=e.length||e[e.length-1]?.key!==t[t.length-1]?.key)return!1;let n=e[0]?.key;return t.findIndex(e=>e.key===n)>0},VV=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(SV(r.keys,n))return r.items;t.delete(e)}},write:(n,r,i)=>{if(r.length!==0)for(t.delete(n),t.set(n,{keys:r.slice(),items:i});t.size>e;){let e=t.keys().next().value;if(typeof e!=`string`)break;t.delete(e)}}}})(xV),HV=(e,t,n)=>{if(t.size===0)return[];let r=0;return e.map((e,i)=>{let a=t.get(e)??n,o={index:i,key:e,start:r,size:a,end:r+a,lane:0};return r+=a,o})},UV=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),WV=e=>e===`collapsed`?wV:CV,GV=(e,t)=>`${e}::activity:${t}`,KV=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),qV=(e,t,n)=>{let r=Number.isFinite(e)?Math.max(0,e):0,i=Number.isFinite(t)?Math.max(r,t):r,a=Number.isFinite(n)?Math.max(0,n):0;return{marginTop:Number.isFinite(e)?Math.min(0,e):0,paddingTop:r,paddingBottom:Math.max(0,a-i),minHeight:a}},JV=(e,t)=>{if(!e)return;let n=`${Math.max(0,Number.isFinite(t)?t:0)}px`;e.style.height!==``&&(e.style.height=``),e.style.minHeight!==n&&(e.style.minHeight=n)},YV=(e,t=0)=>Math.max(e===`collapsed`?OV:DV,Math.max(0,Math.floor(t))),XV=e=>e===`collapsed`?jV:AV,ZV=e=>e===`collapsed`?NV:MV,QV=(e,t)=>{e.current=t},$V=(e,t)=>VV.read(e,t),eH=(e,t,n)=>{!n||t.length===0||VV.write(e,t,n.takeSnapshot())},tH=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},nH=(e,t)=>{if(tH(e)!==`system`)return e;let n=aH(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},rH=e=>!e||tH(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),iH=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},aH=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},oH=(e,t,n)=>{if(typeof window>`u`)return!1;let r=e;for(;r&&r!==t;){if(window.getComputedStyle(r).position===`sticky`&&r.getBoundingClientRect().top<=n+1)return!0;r=r.parentElement}return!1},sH=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,cH=(e,t=e)=>{let n=e.getBoundingClientRect(),r=Array.from(t.querySelectorAll(`[data-message-id]`)),i=r.find(t=>t.getBoundingClientRect().bottom>n.top+1&&!oH(t,e,n.top))??r.find(e=>e.getBoundingClientRect().bottom>n.top+1),a=i?.dataset.messageId;return!i||!a?null:{messageId:a,offsetTop:i.getBoundingClientRect().top-n.top}},lH=(e,t)=>{let n=t.querySelectorAll(`[data-message-id]`),r=n[n.length-1],i=r?.dataset.messageId;return!r||!i?null:{messageId:i,offsetTop:r.getBoundingClientRect().top-e.getBoundingClientRect().top}},uH=(e,t)=>{let n=cH(t,e)??lH(t,e);if(!n)return null;let r=sH(e,n.messageId)?.closest(`[data-turn-entry]`),i=r?.dataset.turnEntry;return!i||!r?null:{...n,entryKey:i,entryStart:r.getBoundingClientRect().top-e.getBoundingClientRect().top,attempts:0}},dH=e=>{let t=e,n=t.state?.metadata,r=oj(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?uj(i)??null:null},fH=e=>{if(tH(e)!==`assistant`||e.parts.length!==1)return{hide:!1,taskSessionId:null};let t=e.parts[0];if(t?.type!==`tool`)return{hide:!1,taskSessionId:null};let n=typeof t.tool==`string`?t.tool.toLowerCase():``;return n!==`task`&&n!==`subagent`?{hide:!1,taskSessionId:null}:{hide:!0,taskSessionId:dH(e.parts[0])}},pH=(e,t)=>{if(!t)return e;let n=sj(e.parts,t);return n===e.parts?e:{...e,parts:n}},mH=(e,t)=>{let n=typeof t?.command==`string`?t.command.trim():``,r=typeof t?.output==`string`?t.output:``,i=typeof t?.status==`string`?t.status.trim():``,a=[],o=!1;for(let t of e.parts){if(!o&&t?.type===`text`){let e=t.text;if(t.synthetic===!0&&typeof e==`string`&&e.trim().startsWith(`The following tool was executed by the user`)){a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),o=!0;continue}}a.push(t)}return o||a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),{...e,parts:a}},hH=e=>e.chatRenderMode!==`sorted`||e.activityPresentationKind!==`compaction`||e.hasVisibleActivitySegments||e.hasAssistantMessages?!1:e.completionDisposition===`normal`||e.completionDisposition===`abnormal`||e.completionDisposition===`active`&&e.isLastTurn&&e.sessionIsWorking,gH=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s,isInActiveTurn:c,activeStreamingPhase:l,animateUserOnMount:u,onUserAnimationConsumed:d,onContentChange:f,animationHandlers:p,scrollToBottom:m}=e,h=Zb(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:h,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=h,t[3]=g):g=t[3];let _=g,v;t[4]!==l||t[5]!==u||t[6]!==p||t[7]!==o||t[8]!==c||t[9]!==n||t[10]!==i||t[11]!==f||t[12]!==d||t[13]!==r||t[14]!==m||t[15]!==a||t[16]!==s?(v=(0,$.jsx)(IR,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:u,onUserAnimationConsumed:d,onContentChange:f,animationHandlers:p,scrollToBottom:m,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s,isInActiveTurn:c,activeStreamingPhase:l}),t[4]=l,t[5]=u,t[6]=p,t[7]=o,t[8]=c,t[9]=n,t[10]=i,t[11]=f,t[12]=d,t[13]=r,t[14]=m,t[15]=a,t[16]=s,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Xb.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return uM(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&dM(e.previousMessage,t.previousMessage)&&dM(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&yM(n,r,e.message.info.id,tH(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.animationHandlers?.onChunk===t.animationHandlers?.onChunk&&e.animationHandlers?.onComplete===t.animationHandlers?.onComplete&&e.animationHandlers?.onStreamingCandidate===t.animationHandlers?.onStreamingCandidate&&e.animationHandlers?.onAnimationStart===t.animationHandlers?.onAnimationStart&&e.animationHandlers?.onReservationCancelled===t.animationHandlers?.onReservationCancelled&&e.animationHandlers?.onReasoningBlock===t.animationHandlers?.onReasoningBlock&&e.animationHandlers?.onAnimatedHeightChange===t.animationHandlers?.onAnimatedHeightChange});gH.displayName=`MessageRow`;var _H=Z.memo(({turn:e,isLastTurn:t,sessionIsWorking:n,activityRenderMode:r,turnUiStates:i,onToggleTurnGroup:a,chatRenderMode:o,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,stickyUserHeader:u=!0,shouldAnimateUserMessage:d,onUserAnimationConsumed:f,activeStreamingMessageId:p,activeStreamingPhase:m})=>{let h=q(e=>e.showReasoningTraces),g=Z.useMemo(()=>!!e.userMessage||e.assistantMessages.some(e=>!!e.info.error||Ck(e.parts,{includeReasoning:h}).some(e=>e.type===`tool`||e.type===`file`||(e.type===`text`||e.type===`reasoning`)&&bk(e).trim().length>0)),[e.userMessage,e.assistantMessages,h]),_=Z.useRef(null);_.current===e.turnId&&!t&&e.completionDisposition!==`active`?_.current=null:t&&n&&(_.current=e.turnId);let v=_.current===e.turnId,y=Z.useRef({turnId:e.turnId,shown:!1});y.current.turnId!==e.turnId&&(y.current={turnId:e.turnId,shown:!1});let b=i.get(e.turnId),x=uR({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n||v,durationMs:e.durationMs}),S=yV({expansionDisposition:pR({isLastTurn:t,turnCompletionDisposition:e.completionDisposition,headerPresentationDisposition:x.completionDisposition,hasAssistantMessages:e.assistantMessages.length>0}),activityRenderMode:r,isLastTurn:t,isActivelyProcessing:t&&n,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),C=b?.automatic&&e.completionDisposition===`normal`&&e.hasConfirmedFinalBody&&!(t&&n),w=b&&!C?b.isExpanded:S,T=J(()=>{a(e.turnId,w)}),E=Z.useMemo(()=>{let t=e.userMessage?[e.userMessage,...e.assistantMessages]:e.assistantMessages,n=new Map;return t.forEach((e,t)=>{n.set(e.info.id,t)}),{ordered:t,lookup:n}},[e.assistantMessages,e.userMessage]),D=Z.useMemo(()=>{if(p&&e.assistantMessages.some(e=>e.info.id===p))return p;for(let t=e.assistantMessages.length-1;t>=0;--t){let n=e.assistantMessages[t];if(!_V(n))return n.info.id}return null},[p,e.assistantMessages]),O=Z.useMemo(()=>o===`live`?e.assistantMessages:vV(e.assistantMessages,D),[o,D,e.assistantMessages]),k=Z.useMemo(()=>{let e=new Map;return O.forEach((t,n)=>{e.set(t.info.id,n)}),e},[O]),A=Z.useMemo(()=>new Set(O.map(e=>e.info.id)),[O]),j=Z.useMemo(()=>e.headerMessageId&&k.has(e.headerMessageId)?e.headerMessageId:O[0]?.info.id,[e.headerMessageId,k,O]),M=Z.useMemo(()=>o===`sorted`?A.size===e.assistantMessages.length?e.activityParts:e.activityParts.filter(e=>A.has(e.messageId)):e.activityParts,[o,A,e.activityParts,e.assistantMessages.length]),N=Z.useMemo(()=>o!==`sorted`||A.size===e.assistantMessages.length?e.activitySegments:e.activitySegments.map(e=>{let t=e.parts.filter(e=>A.has(e.messageId));if(t.length===0)return null;let n=A.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null}).filter(e=>e!==null),[o,A,e.activitySegments,e.assistantMessages.length]),P=Z.useMemo(()=>{let t=e.userMessage?.info.time?.created,n=e.userMessage?.info,r=n?.model?.variant??n?.variant,i=typeof r==`string`&&r.trim().length>0?r:void 0;return{turnId:e.turnId,assistantTps:nI(e.assistantMessages.map(e=>({createdAt:e.info.time.created,streamedAt:e.info.time.streamed,outputTokens:e.info.tokens?.output,reasoningTokens:e.info.tokens?.reasoning}))),summaryBody:e.summaryText,activityParts:M,activityGroupSegments:N,headerMessageId:e.headerMessageId,hasTools:e.hasTools,hasReasoning:e.hasReasoning,activityPresentationKind:e.activityPresentationKind,diffStats:e.diffStats,changedFiles:e.changedFiles,userMessageCreatedAt:typeof t==`number`?t:void 0,userMessageVariant:i}},[e.activityPresentationKind,e.assistantMessages,e.changedFiles,e.diffStats,e.hasReasoning,e.hasTools,e.headerMessageId,e.summaryText,e.turnId,e.userMessage?.info,M,N]),F=RB((r,i)=>{let a=tH(r)===`user`,u=E.lookup.get(r.info.id),p=k.get(r.info.id)??-1,h=p>=0,g=p===0,_=p===O.length-1,v=!!j&&r.info.id===j,y=N.some(e=>e.anchorMessageId===r.info.id),b=o===`sorted`?h:v||g||_,S=O[0]?.info.id??e.headerMessageId,C=a?void 0:h?g?e.userMessage:void 0:typeof u==`number`&&u>0?E.ordered[u-1]:void 0,w=h?{turnId:e.turnId,activityOwnerMessageId:j,isFirstAssistantInTurn:g,isLastAssistantInTurn:_,isLatestTurn:t,isWorking:(t||e.completionDisposition===`active`)&&n&&(o===`sorted`?y:r.info.id===D),isTurnSettled:dR({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,hasConfirmedSettledAssistant:e.hasConfirmedFinalBody}),hasTools:e.hasTools,hasReasoning:e.hasReasoning,completionDisposition:x.completionDisposition,activityPresentationKind:e.activityPresentationKind,durationMs:x.durationMs,assistantTps:P.assistantTps,...b?{summaryBody:P.summaryBody,activityParts:P.activityParts,activityGroupSegments:P.activityGroupSegments,headerMessageId:P.headerMessageId,diffStats:P.diffStats,changedFiles:P.changedFiles,userMessageCreatedAt:P.userMessageCreatedAt,userMessageVariant:P.userMessageVariant,isGroupExpanded:i,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(gH,{message:r,previousMessage:C,nextMessage:void 0,turnGroupingContext:w,assistantHeaderMessageId:S,turnOwnsAssistantHeader:h,isInActiveTurn:!!D&&r.info.id===D,activeStreamingPhase:r.info.id===D?m:null,animateUserOnMount:d(r),onUserAnimationConsumed:f,onContentChange:s,animationHandlers:c(r.info.id),scrollToBottom:l},r.info.id)}),I=Z.useMemo(()=>O===e.assistantMessages?e:{...e,assistantMessages:O},[e,O]),L=Z.useMemo(()=>((sR({isLastTurn:t,sessionIsWorking:n,hasAssistantMessages:e.assistantMessages.length>0,activityPresentationKind:e.activityPresentationKind,hasActiveStreamingMessage:!!p})||e.assistantMessages.length>0)&&(y.current.shown=!0),!y.current.shown||e.activityPresentationKind===`compaction`?null:e.userMessage?oR(rR(e.userMessage.info)):null),[p,t,n,e.activityPresentationKind,e.assistantMessages.length,e.userMessage]);if(!g){let t=e.assistantMessages.find(e=>e.info.id===p);return t?(0,$.jsx)(vH,{message:t,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,shouldAnimateUserMessage:d,onUserAnimationConsumed:f,activeStreamingMessageId:p,activeStreamingPhase:m}):null}return(0,$.jsx)(Dz,{turn:I,showSessionError:t,activityExpanded:w,onToggleActivity:T,showCompactionStatus:hH({chatRenderMode:o,activityPresentationKind:e.activityPresentationKind,hasVisibleActivitySegments:N.length>0,hasAssistantMessages:e.assistantMessages.length>0,completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n}),pendingAssistantHeader:L,assistantHeaderMessage:O[0],assistantHeaderIsInActiveTurn:O[0]?.info.id===D,preserveActiveTurnGap:v,stickyUserHeader:u,renderMessage:F})});_H.displayName=`TurnBlock`;var vH=Z.memo(e=>{let t=(0,Q.c)(30),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d}=e,{t:f}=fr();if(nA(n)){let e;t[0]===f?e=t[1]:(e=f(`assistants.conversation.newSessionDivider`),t[0]=f,t[1]=e);let n;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[2]=n):n=t[2];let r;t[3]===f?r=t[4]:(r=f(`assistants.conversation.newSessionDivider`),t[3]=f,t[4]=r);let i;t[5]===r?i=t[6]:(i=(0,$.jsx)(`span`,{className:`shrink-0 typography-meta text-muted-foreground`,children:r}),t[5]=r,t[6]=i);let a;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[7]=a):a=t[7];let o;t[8]===i?o=t[9]:(o=(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[n,i,a]}),t[8]=i,t[9]=o);let s;return t[10]!==e||t[11]!==o?(s=(0,$.jsx)(`div`,{className:`chat-message-column px-4 py-5`,role:`separator`,"aria-label":e,children:o}),t[10]=e,t[11]=o,t[12]=s):s=t[12],s}let p;t[13]!==n||t[14]!==c?(p=c(n),t[13]=n,t[14]=c,t[15]=p):p=t[15];let m;t[16]!==o||t[17]!==n.info.id?(m=o(n.info.id),t[16]=o,t[17]=n.info.id,t[18]=m):m=t[18];let h=!!u&&n.info.id===u,g=n.info.id===u?d:null,_;return t[19]!==n||t[20]!==i||t[21]!==a||t[22]!==l||t[23]!==r||t[24]!==s||t[25]!==p||t[26]!==m||t[27]!==h||t[28]!==g?(_=(0,$.jsx)(gH,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:p,onUserAnimationConsumed:l,onContentChange:a,animationHandlers:m,scrollToBottom:s,isInActiveTurn:h,activeStreamingPhase:g}),t[19]=n,t[20]=i,t[21]=a,t[22]=l,t[23]=r,t[24]=s,t[25]=p,t[26]=m,t[27]=h,t[28]=g,t[29]=_):_=t[29],_});vH.displayName=`UngroupedMessageRow`;var yH=Z.memo(e=>{let t=(0,Q.c)(26),{entry:n,hydrateMarkdown:r,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,stickyUserHeader:s,sessionIsWorking:c,activityRenderMode:l,turnUiStates:u,onToggleTurnGroup:d,chatRenderMode:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,showLiveStatusRow:_}=e,v=r===void 0||r,y=_!==void 0&&_,b;t[0]!==h||t[1]!==g||t[2]!==l||t[3]!==f||t[4]!==n.isLastTurn||t[5]!==n.kind||t[6]!==n.message||t[7]!==n.nextMessage||t[8]!==n.previousMessage||t[9]!==n.turn||t[10]!==a||t[11]!==i||t[12]!==d||t[13]!==m||t[14]!==o||t[15]!==c||t[16]!==p||t[17]!==s||t[18]!==u?(b=n.kind===`ungrouped`?(0,$.jsx)(vH,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g}):(0,$.jsx)(_H,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:c,activityRenderMode:l,turnUiStates:u,onToggleTurnGroup:d,chatRenderMode:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,stickyUserHeader:s}),t[0]=h,t[1]=g,t[2]=l,t[3]=f,t[4]=n.isLastTurn,t[5]=n.kind,t[6]=n.message,t[7]=n.nextMessage,t[8]=n.previousMessage,t[9]=n.turn,t[10]=a,t[11]=i,t[12]=d,t[13]=m,t[14]=o,t[15]=c,t[16]=p,t[17]=s,t[18]=u,t[19]=b):b=t[19];let x=b,S;t[20]===y?S=t[21]:(S=y?(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(uz,{})}):null,t[20]=y,t[21]=S);let C;return t[22]!==x||t[23]!==v||t[24]!==S?(C=(0,$.jsxs)(KB,{enabled:v,children:[x,S]}),t[22]=x,t[23]=v,t[24]=S,t[25]=C):C=t[25],C});yH.displayName=`MessageListEntry`;var bH=Z.memo(({entries:e,historyAnchorToken:t,engine:n,contentRef:r,scrollRef:i,registerTanstackVirtualizer:a,virtualizerKey:o,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,stickyUserHeader:u,activityRenderMode:d,turnUiStates:f,onToggleTurnGroup:p,chatRenderMode:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g})=>{let[_,v]=Z.useState(e),y=Z.useSyncExternalStore(Aw,kw,()=>null),b=y&&i?.current?.contains(y)?y.closest(`[data-turn-entry]`)?.dataset.turnEntry:void 0,x=n===`tanstack`&&_.length>=bV(),S=Z.useRef(n),C=Z.useRef(null),[w,T]=Z.useReducer(e=>e+1,0);if(!x)C.current=null;else if(S.current===`none`&&x&&C.current===null){let e=r.current,t=i?.current;e&&t&&(C.current=uH(e,t))}let E=Z.useRef(!1),D=Z.useRef(0),O=Z.useRef(null),k=vi();Z.useEffect(()=>{if(!k)return;let e=i?.current;if(!e)return;let t=()=>{E.current=!0},n=()=>{E.current=!1},r=()=>{D.current=performance.now()};return e.addEventListener(`touchstart`,t,{passive:!0}),e.addEventListener(`touchend`,n,{passive:!0}),e.addEventListener(`touchcancel`,n,{passive:!0}),e.addEventListener(`scroll`,r,{passive:!0}),()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),e.removeEventListener(`scroll`,r)}},[k,i]);let A=()=>E.current||performance.now()-D.current<RV,j=_;e===_?O.current!==null&&(O.current=null):k&&BV(_,e)&&A()?O.current===null&&(O.current=performance.now()):(O.current=null,v(e),j=e);let[,M]=Z.useReducer(e=>e+1,0);or(()=>{O.current!==null&&(A()||M())},k&&O.current!==null?zV:null);let N=Z.useRef(j);N.current=j;let P=Z.useMemo(()=>j.map(e=>e.key),[j]),F=PV(),[I,L]=Z.useState(()=>HB(F));Z.useEffect(()=>{if(!(!x||I>=F))return nd(()=>{Z.startTransition(()=>{L(e=>UB(e,F))})})},[I,x,F]);let R=GV(o,d),[z]=Z.useState(()=>x?$V(R,e.map(e=>e.key)):void 0),B=Z.useRef(null),V=J(e=>{B.current=e,r.current=e}),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(new Set),ee=Z.useRef(new Set),te=Z.useRef(t),G=Z.useRef(j),ne=G.current!==j&&BV(G.current,j);if(G.current=j,te.current!==t||ne){te.current=t;let e=i?.current,n=B.current??r.current;H.current=e&&n?cH(e,n):null}let re=J(()=>{H.current=null,U.current=null});ir(`wheel`,re,void 0,{passive:!0,capture:!0}),ir(`touchstart`,re,void 0,{passive:!0,capture:!0}),ir(`pointerdown`,re,void 0,{passive:!0,capture:!0}),ir(`click`,re,void 0,{capture:!0}),ir(`keydown`,re,void 0,{capture:!0});let ie=J(()=>{let e=U.current??H.current,t=i?.current;if(!e||!t)return;let n=sH(t,e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&pe.scrollToOffset(t.scrollTop+r,{behavior:`auto`})}),ae=WV(d),oe=Z.useRef(ae),se=Z.useRef(d);se.current!==d&&(se.current=d,oe.current=ae);let ce=Z.useRef(x),le=Z.useRef(new Map),ue=Z.useRef(void 0);if(Z.useLayoutEffect(()=>{x||(ue.current=void 0)}),x&&ue.current===void 0){if(!z){let e=le.current;e.clear(),r?.current?.querySelectorAll(`[data-turn-entry]`).forEach(t=>{let n=t.dataset.turnEntry;n&&e.set(n,t.getBoundingClientRect().height)})}ue.current=z??HV(P,le.current,oe.current)}let de=Z.useMemo(()=>x?{width:i?.current?.clientWidth??0,height:i?.current?.clientHeight??0}:void 0,[x,i]),fe=Z.useMemo(()=>b?j.findIndex(e=>e.key===b):-1,[j,b]),pe=pd({count:j.length,enabled:x,initialRect:de,getScrollElement:()=>i?.current??null,estimateSize:()=>oe.current,overscan:I,rangeExtractor:e=>{let t=WB(e,pe.measurementsCache,pe.scrollOffset,pe.scrollRect?.height);return fe>=0&&!t.includes(fe)?[...t,fe].sort((e,t)=>e-t):t},measureElement:(e,t,n)=>{let r=n.options.getItemKey(n.indexFromElement(e)),i=n.itemSizeCache.get(r);if(n.options.useCachedMeasurements)return i??n.options.estimateSize(n.indexFromElement(e));let a=t?.borderBoxSize?.[0]?.blockSize;return a===void 0?t?e.getBoundingClientRect().height:i??n.options.estimateSize(n.indexFromElement(e)):a},scrollToFn:(e,t,n)=>{JV(B.current,n.getTotalSize()),fd(e,t,n)},getItemKey:e=>N.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:LV,initialOffset:()=>{if(ce.current){let e=oe.current,t=(ue.current??[]).reduce((t,n)=>t+(n.index<j.length?n.size-e:0),j.length*e);return Math.max(0,t-(i?.current?.clientHeight??0))}let e=C.current,t=e&&ue.current?.find(t=>t.key===e.entryKey);return(i?.current?.scrollTop??0)+(t&&e?t.start-e.entryStart:0)},initialMeasurementsCache:ue.current});Z.useEffect(()=>{let e=i?.current;!x||!e||pe.scrollElement===e||(pe.scrollOffset=e.scrollTop,pe._willUpdate(),pe.options.onChange?.(pe,!1))}),cr(()=>{if(!x)return;pe.shouldAdjustScrollPositionOnItemSizeChange=hV;let e=mV(pe,me);return()=>{e();for(let e of ee.current)e.style.removeProperty(`opacity`);ee.current.clear(),W.current.clear(),U.current=null}},[x,pe]);let me=J(()=>{ie();for(let e of ee.current)e.style.removeProperty(`opacity`);ee.current.clear(),U.current=null}),he=J(e=>{pe.measureElement(e),!(!e||!e.isConnected)&&W.current.add(e)});cr(()=>{if(!x||W.current.size===0)return;let e=[...W.current].filter(e=>e.isConnected).map(e=>({row:e,index:pe.indexFromElement(e),height:e.getBoundingClientRect().height}));W.current.clear();for(let{row:t,index:n,height:r}of e)ee.current.add(t),pe.resizeItem(n,r)});let ge=Z.useRef(null),_e=Z.useRef(null);x||(ge.current=null);let ve=J(()=>{if(!x)return;let e=B.current??i?.current;if(!e)return;let t=e.offsetWidth;if(!KV(ge.current,t)){ge.current===null&&t>0&&(ge.current=t);return}ge.current=t,_e.current!==null&&clearTimeout(_e.current),_e.current=setTimeout(()=>{_e.current=null;let e=i?.current,t=B.current;e&&t&&!E.current&&(U.current=cH(e,t));for(let e of pe.elementsCache.values())e.isConnected&&W.current.add(e);pe.measure()},220)}),ye=x&&typeof ResizeObserver<`u`;sr(ye?B:null,ve),sr(ye&&i?i:null,ve),rr(()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)}),cr(()=>{x&&ve()},[x]),cr(()=>{if(S.current=x?`tanstack`:`none`,!x){C.current=null;return}let e=C.current,t=i?.current;if(!e||!t)return;let n=sH(t,e.messageId);if(n){let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&pe.scrollToOffset(t.scrollTop+r,{behavior:`auto`}),C.current=null;return}let r=P.indexOf(e.entryKey);if(r<0||e.attempts>=1){C.current=null;return}e.attempts+=1,pe.scrollToIndex(r,{align:`start`}),T()},[n,P,x,pe,w]);let be=pe.getVirtualItems(),xe=be.map(e=>e.index),[Se,Ce]=Z.useState(()=>QB(P,{seedCount:YV(d),restore:XB(R)})),we=$B(Se,P);for(let e of le.current.keys())we.has(e)||(we===Se&&(we=new Set(we)),we.add(e));we!==Se&&Ce(we);let Te=Z.useRef(we);Te.current=we;let Ee=Z.useRef(null);pe.scrollDirection&&(Ee.current=pe.scrollDirection);let De=pe.range?.startIndex??be[0]?.index??Math.max(0,j.length-1),Oe=pe.range?.endIndex??be[be.length-1]?.index??Math.max(0,j.length-1),ke=pe.isScrolling,Ae=Math.max(0,Oe-De+1),je=tV({entryKeys:P,mountedIndexes:xe,visibleStartIndex:De,visibleEndIndex:Oe,scrollDirection:Ee.current,preloadEntries:YV(d,Ae),hydratedKeys:we,allowVisibleRelease:!ke,preloadReleaseLimit:ke?XV(d):kV,visibleReleaseLimit:ke?0:ZV(d)}),Me=je.join(`\0`),Ne=Z.useRef(je);Ne.current=je,Z.useEffect(()=>{if(!(!x||!Me))return nd(()=>{Z.startTransition(()=>{Ce(e=>{let t=null;for(let n of Ne.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[x,Me]),Z.useEffect(()=>{Ce(e=>nV(e,P))},[P]),Z.useEffect(()=>{if(x)return a?.(pe),()=>{eH(R,N.current.map(e=>e.key),pe),ZB(R,Te.current),a?.(null)}},[x,pe,R]);let Pe=RB((e,t=!0)=>(0,$.jsx)(yH,{entry:e,hydrateMarkdown:t,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,stickyUserHeader:u,sessionIsWorking:!1,activityRenderMode:d,turnUiStates:f,onToggleTurnGroup:p,chatRenderMode:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g},e.key));if(!x)return(0,$.jsx)(`div`,{ref:V,className:`relative w-full`,children:(0,$.jsx)(`div`,{children:j.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`yuri-chat-message-layout-boundary`,children:Pe(e)},e.key))})});if(n===`tanstack`){let e=qV(be[0]?.start??0,be[be.length-1]?.end??0,pe.getTotalSize());return(0,$.jsx)(`div`,{ref:V,className:`relative flow-root w-full`,style:{minHeight:e.minHeight},children:(0,$.jsx)(`div`,{style:{marginTop:e.marginTop,paddingTop:e.paddingTop,paddingBottom:e.paddingBottom},children:be.map((e,t)=>{let n=j[e.index];return n?(0,$.jsx)(`div`,{"data-index":e.index,ref:he,"data-turn-entry":n.key,style:{opacity:pe.itemSizeCache.has(n.key)?void 0:0,marginTop:t>0&&e.index>be[t-1].index+1?e.start-be[t-1].end:void 0},className:`yuri-chat-message-layout-boundary`,children:Pe(n,we.has(n.key))},n.key):null})})})}return null});bH.displayName=`StaticHistoryList`;var xH=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(`div`,{className:`yuri-chat-message-layout-boundary`,children:(0,$.jsx)(yH,{...e})}),t[0]=e,t[1]=n),n});xH.displayName=`TailEntry`;var SH=e=>{let t=(0,Q.c)(41),{entries:n,directory:r,sessionId:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,showTurnChangedFiles:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:_,activeStreamingPhase:v}=e,y=n.length-1,b=ua(_??``,r,i??void 0),x;bb0:{let e=n[y];if(!e){x=void 0;break bb0}let r=p===`sorted`,i;t[0]!==_||t[1]!==b||t[2]!==e||t[3]!==m||t[4]!==r?(i=MB(e,{activeStreamingMessageId:_,liveParts:b,showTextJustificationActivity:r,showTurnChangedFiles:m}),t[0]=_,t[1]=b,t[2]=e,t[3]=m,t[4]=r,t[5]=i):i=t[5],x=i}let S=x,C;if(t[6]!==_||t[7]!==v||t[8]!==u||t[9]!==p||t[10]!==n||t[11]!==o||t[12]!==S||t[13]!==y||t[14]!==a||t[15]!==f||t[16]!==g||t[17]!==s||t[18]!==l||t[19]!==h||t[20]!==c||t[21]!==d){let e;t[23]!==_||t[24]!==v||t[25]!==u||t[26]!==p||t[27]!==o||t[28]!==S||t[29]!==y||t[30]!==a||t[31]!==f||t[32]!==g||t[33]!==s||t[34]!==l||t[35]!==h||t[36]!==c||t[37]!==d?(e=(e,t)=>{let n=t===y;return(0,$.jsx)(xH,{entry:n?S??e:e,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:n?l:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:n?_:null,activeStreamingPhase:n?v:null},e.key)},t[23]=_,t[24]=v,t[25]=u,t[26]=p,t[27]=o,t[28]=S,t[29]=y,t[30]=a,t[31]=f,t[32]=g,t[33]=s,t[34]=l,t[35]=h,t[36]=c,t[37]=d,t[38]=e):e=t[38],C=n.map(e),t[6]=_,t[7]=v,t[8]=u,t[9]=p,t[10]=n,t[11]=o,t[12]=S,t[13]=y,t[14]=a,t[15]=f,t[16]=g,t[17]=s,t[18]=l,t[19]=h,t[20]=c,t[21]=d,t[22]=C}else C=t[22];let w;return t[39]===C?w=t[40]:(w=(0,$.jsx)($.Fragment,{children:C}),t[39]=C,t[40]=w),w};SH.displayName=`StreamingTailContent`;var CH=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,scrollRef:u,directory:d,liveStatusSlot:f,timelineHistoryAnchorToken:p,enableSendPark:m=!0,initialPinRevealComplete:h=!1},g)=>{De(`ui.message_list.render`);let{sessionKey:_,virtualizerKey:v}=UV(e,t),y=Z.useMemo(()=>dA(),[_,d]),b=q(e=>e.stickyUserHeader),x=q(e=>e.chatRenderMode),S=q(e=>e.activityRenderMode),C=q(e=>e.showTurnChangedFiles),[w,T]=Z.useState(()=>new Map),E=Z.useContext(hA),[D,O]=Z.useState(_);D!==_&&(O(_),T(new Map));let k=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set});cr(()=>{if(m)return()=>{queueMicrotask(()=>{Ri(e)})}},[m,e]);let A=J(c),j=J(()=>{l?.()}),M=J((e,t)=>{T(n=>{let r=new Map(n);return r.set(e,{isExpanded:lR(t)}),r})}),N=Z.useMemo(()=>we(`ui.message_list.base_display_ms`,()=>{let e=new Set,t=new Map,r=[];for(let e of n){let n=e.info?.id;typeof n==`string`&&t.set(n,e)}for(let i=0;i<n.length;i+=1){let a=n[i],o=a.info?.id;if(typeof o==`string`){if(e.has(o))continue;e.add(o)}r.push(GR(typeof o==`string`?t.get(o)??a:a))}let i=[],a=new Set,o=-1;for(let e=r.length-1;e>=0;--e)if(r[e].info.role===`assistant`){o=e;break}for(let e=0;e<r.length;e+=1){let t=r[e];if(e<o&&QL(t.info))continue;let n=nH(t,a);VR(t)&&a.add(t.info.id);let s=i.length>0?i[i.length-1]:void 0;if(rH(s)){let e=fH(n);if(e.hide){i[i.length-1]=pH(s,e.taskSessionId);continue}}if(gR(s)){let e=vR(n,iH(s));if(e.hide){i[i.length-1]=mH(s,e.details);continue}}i.push(n)}return i}),[n]),P=Z.useRef(null),F=Z.useRef(null),I=Z.useCallback(()=>{let e=F.current;e&&(F.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{I()},[I]);let L=J(()=>u?.current?u.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),R=Z.useMemo(()=>we(`ui.message_list.retry_overlay_ms`,()=>AB(N,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[N,o]),z=r||!!i,{projection:B,streamingTurns:V}=OB(R,{sessionKey:_,showTextJustificationActivity:x===`sorted`,showTurnChangedFiles:C,hasLiveTail:!0,liveTailActive:z});cr(()=>{z&&T(e=>{let t=e;for(let n of V)n.completionDisposition!==`active`||n.assistantMessages.length===0||e.has(n.turnId)||(t===e&&(t=new Map(e)),t.set(n.turnId,{isExpanded:!0,automatic:!0}));return t})},[z,V]);let H=Z.useMemo(()=>we(`ui.message_list.render_entries_ms`,()=>LB({messages:R,turns:B.turns,streamingTurns:V,ungroupedMessageIds:B.ungroupedMessageIds,lastTurnId:B.lastTurnId})),[R,B.lastTurnId,B.turns,B.ungroupedMessageIds,V]),U=H.history,W=H.tail,ee=W.length>0;ee&&z&&De(`ui.message_list.render.streaming`);let te=U,G=te.length>=bV(),ne=Z.useRef(G);QV(ne,G);let re=G?`tanstack`:`none`,ie=Z.useRef(null),ae=J(e=>{ie.current=e}),oe=Z.useMemo(()=>W.length>0?[...te,...W]:te,[te,W]),[se,ce]=Z.useState(0),[le,ue]=Z.useState(null),de=GV(v,S),fe=dV(void 0,gV({scopeKey:de,generation:se,root:le,relevantKeys:Z.useMemo(()=>oV({entryKeys:oe.map(e=>e.key),seedCount:YV(S)}),[de,se,oe.length,oe[oe.length-1]?.key,S]),enabled:!1,initiallyRevealed:h})),pe=J(e=>{s(e)}),me=J(e=>{s(e)}),he=Z.useMemo(()=>n.filter(e=>tH(e)===`user`).map(e=>e.info.id),[n]),ge=k.current,_e=ge.sessionKey!==e,ve=ge.previousOrder;_e&&(m&&ge.sessionKey!==void 0&&Ri(ge.sessionKey),ge.sessionKey=e,ge.previousOrder=he,ge.animatedIds=new Set),m&&Br({sessionId:e,sessionChanged:_e,previousUserOrder:ve,currentUserOrder:he,animatedIds:ge.animatedIds}),ge.previousOrder=he;let ye=J(e=>tH(e)===`user`&&k.current.animatedIds.has(e.info.id)),be=J(e=>{k.current.animatedIds.delete(e)}),xe=Z.useMemo(()=>{let e=new Map;return oe.forEach((t,n)=>{if(t.kind===`ungrouped`){e.set(t.message.info.id,n);return}t.turn.userMessage&&e.set(t.turn.userMessage.info.id,n),t.turn.assistantMessages.forEach(t=>{e.set(t.info.id,n)})}),e},[oe]),Se=Z.useMemo(()=>{let e=new Map;return oe.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[oe]),Ce=J(e=>xe.get(e)),Te=Z.useMemo(()=>{if(!E)return w;let e=xe.get(E.messageId),t=e===void 0?void 0:oe[e];if(t?.kind!==`turn`)return w;let n=new Map(w);return n.set(t.turn.turnId,{isExpanded:!0}),n},[oe,xe,E,w]),Ee=J(e=>{let t=L();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Oe=J((e,t=`auto`)=>{if(e<0||e>=te.length||!G)return!1;let n=ie.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),ke=J((e,t=`auto`)=>{let n=L();if(!n)return!1;let r=Ee(e);if(!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect().top-i.top+n.scrollTop-50;return n.scrollTo({top:a,behavior:t}),!0});return Z.useEffect(()=>{if(!E)return;let e=L();if(!e)return;let t=gA(E.messageId,E.partId),n=globalThis.CSS?.highlights,r=!1,i=!1,a=0,o=()=>{if(a=0,i)return;let o=e.querySelectorAll(`[data-transcript-search-part]`),s=[],c;for(let e of o){let n=SA(e,E.query);s.push(...n),e.dataset.transcriptSearchPart===t&&(c=n[E.occurrence])}if(n&&typeof Highlight<`u`){n.set(`yuri-transcript-find`,new Highlight(...s));let e=new Highlight(...c?[c]:[]);e.priority=1,n.set(`yuri-transcript-find-active`,e)}if(r||!c)return;let l=c.getBoundingClientRect();if(!l.height)return;ie.current?.cancelScroll();let u=e.getBoundingClientRect();e.scrollTo({top:e.scrollTop+l.top-u.top-e.clientHeight/2,behavior:`auto`}),r=!0},s=()=>{!a&&!i&&(a=requestAnimationFrame(o))},c=()=>{r=!0};I();let l=Ce(E.messageId);l!==void 0&&!Array.from(e.querySelectorAll(`[data-transcript-search-part]`)).some(e=>e.dataset.transcriptSearchPart===t)&&Oe(l,`auto`);let u=new MutationObserver(s);return u.observe(e,{childList:!0,characterData:!0,subtree:!0}),e.addEventListener(`wheel`,c,{passive:!0}),e.addEventListener(`touchstart`,c,{passive:!0}),e.addEventListener(`pointerdown`,c,{passive:!0}),s(),()=>{i=!0,u.disconnect(),a&&cancelAnimationFrame(a),e.removeEventListener(`wheel`,c),e.removeEventListener(`touchstart`,c),e.removeEventListener(`pointerdown`,c),n?.delete(`yuri-transcript-find`),n?.delete(`yuri-transcript-find-active`)}},[E,I,L,Oe,Ce]),Z.useEffect(()=>{if(!g)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Se.get(e);if(r===void 0)return!1;let i=L();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):ee&&r>=te.length?!1:Oe(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=xe.get(e);return r===void 0?!1:ke(e,n)||(ee&&r>=te.length?!1:Oe(r,n))},holdViewportAnchor:e=>{let t=L();if(!t||typeof window>`u`)return;I();let n=0,r=0,i=!1,a=null,o=()=>{t.removeEventListener(`touchstart`,c),t.removeEventListener(`wheel`,c),t.removeEventListener(`keydown`,c),t.removeEventListener(`pointerdown`,c)},s=()=>{i||(i=!0,a!==null&&(window.cancelAnimationFrame(a),a=null),o(),F.current?.cancel===s&&(F.current=null))},c=()=>{s()};F.current={cancel:s},t.addEventListener(`touchstart`,c,{passive:!0}),t.addEventListener(`wheel`,c,{passive:!0}),t.addEventListener(`keydown`,c),t.addEventListener(`pointerdown`,c,{passive:!0});let l=()=>{if(i)return;let o=Ee(e.messageId);if(o){let n=o.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(n)>.5?(t.scrollTop+=n,r=0):r+=1}if(n+=1,r>=FV||n>=IV){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:I,isHistoryVirtualized:()=>ne.current,captureViewportAnchor:()=>{let e=L();if(!e)return null;let t=e.getBoundingClientRect(),n=Array.from(e.querySelectorAll(`[data-message-id]`)),r=n.find(n=>{let r=n.getBoundingClientRect();return r.top>=t.top&&r.top<t.bottom&&(typeof window>`u`||!oH(n,e,t.top))})??n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!oH(n,e,t.top))??n.find(e=>e.getBoundingClientRect().bottom>t.top+1);if(!r)return null;let i=r.dataset.messageId;return i?{messageId:i,offsetTop:r.getBoundingClientRect().top-t.top}:null},restoreViewportAnchor:e=>{let t=L();if(!t||!xe.has(e.messageId))return!1;let n=()=>{let n=Ee(e.messageId);if(!n)return!1;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect().top-r.top-e.offsetTop;if(i!==0){let e=t.scrollTop+i,n=ie.current;if(G&&n){if(n.options.count!==te.length)return!0;n.scrollToOffset(e,{behavior:`auto`})}else t.scrollTop=e}return!0};if(!n()){let t=xe.get(e.messageId);if(typeof t==`number`&&t<te.length)return Oe(t,`auto`)}return n()},cancelScroll:()=>{I(),ie.current?.cancelScroll()},scrollToBottom:({behavior:e=`auto`,reveal:t=!0}={})=>(t&&ce(e=>e+1),G&&te.length>0&&ie.current?(ie.current.scrollToEnd({behavior:e}),!0):!1)};if(typeof g==`function`)return g(e),()=>{g(null)};let t=g;return t.current=e,()=>{t.current=null}},[I,te.length,xe,G,ee,Se,g]),(0,$.jsx)(fA.Provider,{value:y,children:(0,$.jsx)(`div`,{children:(0,$.jsx)(sd,{disabled:!1,children:(0,$.jsxs)(`div`,{ref:ue,className:`relative w-full`,style:fe,children:[(0,$.jsx)(sd,{disabled:G,children:(0,$.jsx)(GB,{enabled:!0,children:(0,$.jsx)(bH,{entries:te,historyAnchorToken:p,engine:re,contentRef:P,scrollRef:u,registerTanstackVirtualizer:ae,virtualizerKey:v,onMessageContentChange:pe,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,activityRenderMode:S,turnUiStates:Te,onToggleTurnGroup:M,chatRenderMode:x,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be},v)})}),(0,$.jsx)(SH,{entries:W,directory:d,sessionId:_,onMessageContentChange:me,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,sessionIsWorking:r,activityRenderMode:S,turnUiStates:Te,onToggleTurnGroup:M,chatRenderMode:x,showTurnChangedFiles:C,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,activeStreamingMessageId:i,activeStreamingPhase:a}),f]})})})})});CH.displayName=`MessageList`;var wH=Z.memo(CH),TH=e=>{let t=(0,Q.c)(3),{content:n,html:r}=e,i;return t[0]!==n||t[1]!==r?(i=r===void 0?(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,children:n}):(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,dangerouslySetInnerHTML:{__html:r}}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},EH=({diff:e,filePath:t})=>{let{currentTheme:n}=Io(),r=Z.useMemo(()=>Qd(n),[n]),i=Z.useMemo(()=>Bd(e),[e]),a=ku(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6608
|
-
`),[i]),s=Vd(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)(
|
|
6609
|
-
`),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=ku(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=Vd(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)(TH,{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},OH=new Set([`id`,`identifier`,`title`,`name`]),kH=e=>typeof e==`object`&&!!e&&!Array.isArray(e),AH=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),jH=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},MH=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},NH=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?`${AH(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)(NH,{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(kH(n)){let e;t[18]===n?e=t[19]:(e=jH(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(FH),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${AH(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)(NH,{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?AH(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`&&MH(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:AH(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});NH.displayName=`JsonSummaryValue`;var PH=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)(NH,{value:n,depth:0})}),t[0]=n,t[1]=r),r});PH.displayName=`JsonSummaryView`;function FH(e){let[t]=e;return!OH.has(t)}function IH(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 LH={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`}},zH=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})},BH=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},VH=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,HH=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)(PH,{data:n})}),t[0]=n,t[1]=r),r},UH=({permission:e,onResponse:t})=>{let{t:n}=fr(),r=q(e=>e.isMobile),[i,a]=Z.useState(!1),[o,s]=Z.useState(!1),c=Ja,l=yo(),u=Wa(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=BH(p),y=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[VH(e),t]));return(0,$.jsx)(IH,{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:[zH(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)($r,{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)($r,{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)($r,{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)(Fd,{language:`bash`,code:e,style:LH,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)(ld,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(EH,{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)(ld,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(DH,{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)(ld,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(HH,{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)(ld,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(HH,{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)(ld,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(HH,{data:y})})]})})()]})})};function WH(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(`
|
|
6610
|
-
`).trimEnd()}function GH(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 KH=200;function qH(e){return Math.min(Math.max(e,40),KH)}var JH=`summary`,YH=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=qH(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}),XH=({question:e})=>{let{t}=fr(),n=xr(e),r=Xr,i=Cr,a=q(e=>e.isMobile),o=yo(),s=Wa(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=zr(e=>e.drafts[l]?.activeTab??`0`),d=e=>Li(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),_=zr(e=>ki(e,l).selectedOptions),v=zr(e=>ki(e,l).customMode),y=zr(e=>ki(e,l).customTextFilled),b=Z.useMemo(()=>e.questions??[],[e.questions]),x=u===JH,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:JH,label:t(`chat.questionCard.summaryTab`)}),e},[b,t]),E=e=>{if(v[e])return(Hr(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=(Hr(l).customText[t]??``).trim();e.push(n?[n]:[]);continue}e.push(_[t]??[])}return e},P=J(e=>{C&&Li(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(()=>{Li(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;Li(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),Ni(i),g(!0)}catch(e){zi(e)?await n.submissionClaimed(i):ji(e)?(Ni(i),no.info(t(`chat.questionCard.noLongerPending`)),g(!0)):no.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),R=J(e=>{Mc(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),Ni(r),g(!0)}catch(e){zi(e)?await n.submissionClaimed(r):ji(e)?(Ni(r),no.info(t(`chat.questionCard.noLongerPending`)),g(!0)):no.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),B=J(async()=>{let n=WH(e);if((await Ea(n)).ok){no.success(t(`chat.questionCard.copiedMarkdown`));return}no.error(t(`chat.questionCard.copyFailed`))}),V=J(async()=>{let n=GH(e);if((await Ea(n)).ok){no.success(t(`chat.questionCard.copiedJson`));return}no.error(t(`chat.questionCard.copyFailed`))});return h||b.length===0?null:(0,$.jsxs)(IH,{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)(xo,{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===JH,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)(YH,{value:Hr(l).customText[S]??``,onValueChange:I,placeholder:t(`chat.questionCard.yourAnswer`),disabled:m,onKeyDown:R})}):null]})]}):null]})};function ZH(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 QH=({form:e,directory:t})=>{let{t:n}=fr(),r=q(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=ZH(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 ja({sessionID:e.sessionID,formID:e.id,answer:c,directory:t}),Ar.getState().remove(e.sessionID,e.id)}catch{s(`reply`)}finally{a(!1)}}}),f=J(async()=>{if(!i){s(null),a(!0);try{await ui({sessionID:e.sessionID,formID:e.id,directory:t}),Ar.getState().remove(e.sessionID,e.id)}catch{s(`cancel`)}finally{a(!1)}}});return(0,$.jsxs)(IH,{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)($r,{type:`button`,variant:`default`,size:`sm`,onClick:()=>void d(),disabled:i,children:n(`chat.form.reply`)}),(0,$.jsx)($r,{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)(Qo,{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)(Qo,{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)($o,{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)($r,{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)($o,{"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)($o,{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 $H(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function eU(e){return typeof e==`string`&&e.length>0?e:void 0}function tU(e){if(!$H(e))return null;let t=eU(e.reason),n=eU(e.provider),r=eU(e.title),i=eU(e.message),a=eU(e.label);return!t||!n||!r||!i||!a?null:{reason:t,provider:n,title:r,message:i,label:a,...eU(e.link)?{link:eU(e.link)}:{}}}function nU(e){return!$H(e)||e.type!==`retry`?!1:tU(e.action)!==null}function rU(e,t){if(!nU(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 iU=Z.memo(function({scrollRef:e,active:t,showScrollToBottom:n,onScrollToBottom:r}){let i=(0,Z.useSyncExternalStore)(Aw,Ow,()=>null),{t:a}=fr(),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-stack`),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)});sr(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)($r,{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)($r,{size:`mobileIcon`,variant:`mobileGlass`,className:`pointer-events-auto${i?.following?` yuri-speech-follow-active`:``}`,"aria-pressed":i?.following,onClick:()=>{i?.following&&e.current?Mw(e.current):Nw()},"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 aU(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
6611
|
-
`)}function oU(e,t=80){let n=aU(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var sU=new Set;function cU(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(sU),a,o;return n[0]!==e||n[1]!==t?(a=()=>{let n=e?.current;if(i(sU),!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=lU,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 lU(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 uU=160,dU=28,fU=12,pU=6,mU=30,hU=12,gU=18,_U=80,vU=4,yU=10,bU=14,xU=20,SU=48,CU=160,wU=(e,t)=>e.map(e=>{let n=t.get(e)??[],r=aU(n),i=g_(r,{citationIcons:S_(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>uU?`${s.slice(0,uU)}…`:s}}),TU=[1,.6,.35,.15],EU=(e,t,n)=>{let r=n?bU:yU;if(t===null)return r;let i=TU[Math.abs(e-t)]??0;return Math.round(r+(xU-r)*i)};function DU({turnIds:e,previewsByTurnId:t,activeTurnId:n,scrollRef:r,turnByMessageId:i,repliesByTurnId:a,onSelectTurn:o,canLoadEarlier:s,isLoadingOlder:c,onLoadEarlier:l}){let{t:u}=fr(),d=cU(r,i),f=q(e=>e.isPromptNavigatorPanelOpen),p=q(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+pU+dU;x(r.left<i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let S=Z.useMemo(()=>wU(e,t),[t,e]),C=Math.min(S.length,mU),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,mU),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,mU),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)/hU),i=Math.min(N.current,mU);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,mU)),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<=gU&&D?i=-1:r>=n.height-gU&&O&&(i=1),I.current=i,i===0){V();return}F.current===null&&(F.current=window.setInterval(H,_U))},[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)},CU)},[ee]);Z.useEffect(()=>()=>{W.current!==null&&window.clearTimeout(W.current)},[]);let G=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]),ne=Z.useCallback(()=>{P.current=null,V(),te()},[te,V]),re=Z.useCallback(()=>{p(!1)},[p]),ie=Z.useCallback(e=>{if(e===null)return;let t=S[e];t&&(o(t.turnId),V(),_(null),re(),m.current?.blur())},[re,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),re(),m.current?.blur())},[j,re,L,ie,g,S.length]),se=Z.useCallback(()=>{V(),_(null),re()},[re,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/SU);if(t===0)return;de.current-=t*SU;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?t.get(fe.turnId)??[]:[],me=fe?a?.get(fe.turnId):void 0,he=Math.max(0,T-vU),ge=Math.min(S.length,E+vU),_e=S.slice(he,ge),ve=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?fU:dU}px`,height:`${C*hU}px`},onMouseMove:G,onMouseLeave:ne,onClick:ae,onKeyDown:oe,onBlur:se,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:ve?{maskImage:ve,WebkitMaskImage:ve}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${T*hU}px)`},children:_e.map((e,t)=>{let n=he+t,r=d.has(e.turnId),i=g===n,a=EU(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*hU}px`,height:`${hU}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)*hU}px`},onMouseEnter:ee,onMouseLeave:te,onMouseMove:e=>e.stopPropagation(),onClickCapture:e=>{e.preventDefault(),e.stopPropagation(),ie(g)},children:[(0,$.jsx)(`div`,{className:`line-clamp-1 font-medium leading-relaxed text-[var(--surface-foreground)] [&_.markdown-content]:contents [&_.markdown-content_p]:inline`,children:pe.some(e=>e.type===`text`&&e.text.trim())?pe.filter(e=>e.type===`text`).map((e,t)=>(0,$.jsx)(RA,{part:e,messageId:fe.turnId,messageParts:pe,isMobile:!1,variant:`preview`},`${fe.turnId}:${e.id||t}`)):k}),me?(0,$.jsx)(`div`,{className:`mt-2 line-clamp-4 [overflow-wrap:anywhere] leading-relaxed text-[var(--surface-mutedForeground)]`,children:(0,$.jsx)(nc,{content:me,enableFileReferences:!1,disableLinkSafety:!0,className:`[&_.markdown-content]:text-inherit [&_.markdown-content]:leading-relaxed [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`})}):null]}):null]})]})})}var OU=`--yuri-mobile-header-collapse`,kU=e=>e.closest(`.mobile-chat-screen`)?.querySelector(`:scope > [data-yuri-collapsible-header="true"]`)??null,AU=e=>{e.style.removeProperty(OU),delete e.dataset.yuriHeaderCollapsePhase,delete e.dataset.yuriHeaderCollapseRest},jU=(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(OU,r),n?.rest!==a&&(e.dataset.yuriHeaderCollapseRest=a),{progress:r,phase:i,rest:a}},MU=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),NU=`data-yuri-timeline-park-end`,PU=e=>{if(!e)return null;let t=e.getAttribute(NU);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},FU=(e,t)=>t!==null&&Number.isFinite(t)?MU({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),IU=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),LU=()=>{let e=document.documentElement;return e.classList.contains(`yuri-keyboard-open`)||e.classList.contains(`yuri-kb-animating`)},RU=e=>{if(LU()||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)},zU=e=>{let t=Z.useRef(QD()),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=gO(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=kU(e),y.current=n,b.current=void 0),n&&(b.current=jU(n,t,b.current))},S=J(t=>{let r=e.scopeRef.current;if(!r)return;let i=v(r);n.current=yO(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=uO(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(nO(t.current,RU(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=lO(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=IU(t);p.current=e,f.current=FU(e,PU(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=RU(o),l=IU(n),_=FU(l,PU(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=vO(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=nO(N,s);if(s||(P=sO(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(()=>{h.current&&(g(i),s.current=!1,o.current=0,O(),j(),P(),w(rO(t.current,`expanded`)),T())}),B=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)}),V=J(t=>{if(!h.current)return;let n=t.target;if(!(n instanceof Element)||!n.closest(`[data-yuri-composer-compact-surface="true"]`)||n.closest(`[data-composer-action="true"]`))return;let r=n.closest(`.yuri-mobile-composer-compact-preview`);t.type===`pointerdown`&&r||t.type===`click`&&!r||(`preventDefault`in t&&t.preventDefault(),`stopPropagation`in t&&t.stopPropagation(),z(),B(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0}))}),[H,U]=Z.useState(null),[W,ee]=Z.useState(null),te=Z.useRef(null),G=J(e=>{e&&_O(e,_.current??e),y.current&&AU(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(QD())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;te.current&&te.current!==n&&G(te.current),te.current=n,n&&C(n),U(e=>e===t?e:t),ee(e=>e===n?e:n)});let ne=Z.useMemo(()=>()=>void 0,[]),re=e.enabled&&H?H:ne,ie=e.enabled&&W?W:ne,ae=e.enabled&&typeof window<`u`?window:ne,oe=Z.useMemo(()=>({passive:!0}),[]);return ir(`scroll`,P,re,oe),ir(`scrollend`,F,re,oe),Z.useEffect(()=>{if(!e.enabled||!H)return;let t={passive:!0,capture:!0};return H.addEventListener(`touchstart`,N,t),H.addEventListener(`touchmove`,M,t),H.addEventListener(`touchend`,L,t),H.addEventListener(`touchcancel`,R,t),()=>{H.removeEventListener(`touchstart`,N,t),H.removeEventListener(`touchmove`,M,t),H.removeEventListener(`touchend`,L,t),H.removeEventListener(`touchcancel`,R,t)}},[e.enabled,H]),ir(`pointerdown`,V,ie),ir(`click`,V,ie),ir(`focusin`,E,ie),ir(`focusout`,E,ie),ir(`yuri:keyboard-intent`,E,ae),ir(`yuri:keyboard-anim`,E,ae),ir(`yuri:keyboard-settled`,E,ae),Z.useEffect(()=>{if(!e.enabled){G(te.current),te.current=null;return}return E(),P(),()=>{g(i),g(a)}},[e.enabled,H,W]),z},BU=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},VU=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},HU=e=>{if(!e)return null;let t=BU(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${VU(e)??``}`},UU=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}),WU=(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&&HU(t[r])===HU(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=BU(r),a=r.info.id,o=UU(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=VU(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},GU=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=BU(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=VU(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}},KU=200,qU={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},JU=()=>KU,YU=()=>Math.round(JU()*.6),XU={MAX_SESSIONS:qU.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(KU*.6),HISTORICAL_MESSAGES:KU,FETCH_BUFFER:20,HISTORY_CHUNK:KU,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:qU.ZOMBIE_TIMEOUT},ZU=()=>{let e=JU(),t=YU();return{...XU,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},QU=XU,$U=600,eW=6e3,tW=.5,nW=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),rW=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},iW=(e,t)=>{let n=nW(e,t);if(n||=rW(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}},aW=e=>{let{container:t,quiesceMs:n=$U,maxLifetimeMs:r=eW}=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=iW(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)>tW){_();return}let n=nW(t,i.messageId);if(!n){let e=rW(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)>tW&&(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)>tW)&&_(),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())}}},oW=30,sW=1200,cW=1.5,lW=e=>Math.max(sW,e*cW),uW=4,dW=30,fW=4,pW=30,mW=250,hW=800,gW=1e4,_W=1500,vW=2e3,yW=wa+2e3,bW=40,xW=`history-loading-timeout`,SW=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),CW=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=xW,e},wW=(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)},TW=2500,EW=new Map,DW=()=>E()?uW:vi()?fW:oW,OW=e=>E()?e.length<=dW:!vi()||e.length<=pW,kW=(e,t)=>{if(EW.delete(e),!OW(t.messages))return;let n=DW();for(;EW.size>=n;){let e=EW.keys().next().value;if(typeof e!=`string`)break;EW.delete(e)}EW.set(e,t)},AW=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),jW=e=>e?{owner:`tanstack-core`}:{owner:`controller`},MW=(e,t)=>e?e.canLoadEarlier:t>=ZU().HISTORICAL_MESSAGES,NW=e=>!(e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=lW(e.clientHeight)),PW=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`,FW=8,IW=1,LW=8,RW=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],zW=80,BW=new WeakMap,VW=e=>{let t=e?BW.get(e):void 0;return!!(t&&(t.touches>0||performance.now()-t.lastScrollAt<160))},HW=e=>{let t=BW.get(e);t&&(t.touches=0,t.lastScrollAt=-1/0,t.pending=null,t.settleScheduled=!1)},UW=e=>{WW(e)},WW=e=>{let t=BW.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&&GW(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),e.addEventListener(`scroll`,()=>{n.lastScrollAt=performance.now()},{passive:!0}),BW.set(e,n),n},GW=(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+zW||KW(e,n.anchorTop+n.delta))}))},KW=(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},qW=(e,t,n)=>{let r=WW(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,KW(e,t)},JW=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),YW=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:a,loadMoreMessages:o,goToBottom:s,releaseAutoFollow:c,beginHistoryViewportPreservation:l,endHistoryViewportPreservation:u,isPinned:d,showScrollButton:p,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?EW.get(t):void 0;if(r&&r.messages===n)return kW(t,r),v.current=r.model,y.current=n,r.model;let i=WU(v.current,y.current,n)??GU(n);return v.current=i,y.current=n,t&&n.length>0&&kW(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=m(),k=f(),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])}`;cr(()=>(j.current=A,()=>{j.current===A&&(j.current=null),no.dismiss(M)}),[A,M]);let N=Z.useRef(b),P=Z.useRef(d),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),G=Z.useRef(null),ne=Z.useRef({authorized:!1,consumed:!1,top:0}),re=Z.useRef(null),ie=J(()=>{ne.current={authorized:!1,consumed:F.current,top:i.current?.scrollTop??0}}),ae=()=>h?i.current??void 0:void 0,oe=J(e=>{e.repeat||ie()});ir(`touchstart`,ie,ae,{passive:!0,capture:!0}),ir(`wheel`,ie,ae,{passive:!0,capture:!0}),ir(`keydown`,oe,ae,{capture:!0});let[se,ce]=Z.useState(A);se!==A&&(ce(A),G.current!==null&&typeof window<`u`&&(window.clearTimeout(G.current),G.current=null),te.current=!1,F.current=!1,ee.current=null,S(!1),w(!1),E(null),D.current=0,ne.current={authorized:!1,consumed:!1,top:0},re.current=null);let le=Z.useMemo(()=>{let e=MW(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),ue=Z.useRef(le);N.current=b,P.current=d,I.current=C,ue.current=le,L.current=e,R.current=t??null,z.current=n,B.current=r,cr(()=>{r?.complete&&no.dismiss(M)},[r?.complete,M]);let de=J(()=>{te.current=!0,G.current!==null&&typeof window<`u`&&(window.clearTimeout(G.current),G.current=null)}),fe=J(()=>{if(typeof window>`u`){te.current=!1;return}G.current!==null&&window.clearTimeout(G.current),G.current=window.setTimeout(()=>{G.current=null,te.current=!1},vW)}),pe=J(()=>{let e=V.current;e.length!==0&&(V.current=[],e.forEach(e=>e()))}),me=J((e=!1)=>new Promise(t=>{if(typeof window>`u`){t();return}let n=!1,r=j.current,i=Date.now()+gW,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,mW)})),he=J(e=>{let t=W.current;t&&(W.current=null,t.resolve(e))}),ge=J(()=>{let e=W.current;if(e){if(e.sessionId!==L.current){he(!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()+TW},E(e.turnId)),he(!0);return}typeof(e.kind===`turn`?N.current.turnIndexById.get(e.id):N.current.messageToTurnIndex.get(e.id))==`number`&&he(!1)}}),_e=Z.useRef(null),ve=J(()=>{let e=_e.current;e&&(_e.current=null,e.dispose())});rr(()=>{G.current!==null&&typeof window<`u`&&(window.clearTimeout(G.current),G.current=null),ve(),pe(),he(!1)});let ye=Z.useRef({scope:A,at:-1/0}),be=()=>{!h&&!vi()&&(ye.current={scope:A,at:Date.now()})};ir(`wheel`,e=>{e.deltaY!==0&&e.target instanceof Node&&i.current?.contains(e.target)&&be()},void 0,{passive:!0,capture:!0}),ir(`scroll`,e=>{e.target===i.current&&be()},void 0,{passive:!0,capture:!0});let xe=()=>ye.current.scope===A&&Date.now()-ye.current.at<hW,[Se,Ce]=Z.useState({scope:A,messages:n}),we=vi(),Te=Se.scope===A&&Se.messages!==n&&JW(Se.messages[0]?.info?.id??null,n[0]?.info?.id??null,n)&&(we?VW(i.current):!h&&Se.messages.at(-1)===n.at(-1)&&xe()),Ee=Te?Se.messages:n;H.current=Te,(Se.scope!==A||Se.messages!==Ee)&&Ce({scope:A,messages:Ee});let[,De]=Z.useReducer(e=>e+1,0);cr(()=>{pe(),ge()},[Ee]);let Oe=Z.useRef(null),ke=J(()=>a.current?.captureViewportAnchor()??null),Ae=J(e=>a.current?.restoreViewportAnchor(e)??!1),je=J(()=>{if(ve(),a.current?.isHistoryVirtualized())return;let e=i.current;if(!e)return;let t=ke();if(t)return _e.current=aW({container:e,anchor:t,pending:!0,isUserScrolling:vi()?()=>VW(e):void 0}),_e.current}),Me=Z.useRef(null);or(J(()=>{let e=i.current;if(!e||!Te||!we&&xe())return;let t=e.scrollHeight;Me.current={oldestId:Ee[0]?.info?.id??null,newestId:Ee.at(-1)?.info?.id??null,scrollHeight:t};let n=Oe.current;if(n){let r={...n,height:t,top:e.scrollTop,anchor:ke()};Oe.current=Object.assign(n,r)}De()}),Te?50:null);let Ne=Z.useRef(null);cr(()=>{if(!vi())return;let e=i.current;if(!e){Ne.current=null;return}let t=Ne.current;(t?.container!==e||t.scope!==A)&&(UW(e),HW(e),Ne.current={container:e,scope:A})}),cr(()=>{ve(),U.current=null,pe(),Oe.current=null,Me.current=null,a.current?.cancelViewportAnchorHold()},[A]),cr(()=>{let e=i.current;if(!e)return;let t=Oe.current;a.current?.isHistoryVirtualized()&&ve(),t&&Math.abs(e.scrollTop-t.top)>LW&&(Oe.current=null,t=null);let n=Me.current,r=Ee[0]?.info?.id??null,o=Ee[Ee.length-1]?.info?.id??null,c=n?AW({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:o})||JW(n.oldestId,r,Ee):!1;t&&t.sessionId!==L.current&&(Oe.current=null,t=null);let l=t?AW({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:o})||JW(t.oldestId,r,Ee):!1,u=c||l,d=e=>{Me.current={oldestId:r,newestId:o,scrollHeight:e??Me.current?.scrollHeight??null}};if(P.current&&!t){ve(),u?(Oe.current=null,s(`instant`,{reveal:!1}),d(e.scrollHeight)):d();return}let f=jW(a.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){a.current?.cancelViewportAnchorHold();let e=t.anchor;e&&Ae(e),d();return}let n=e.scrollHeight,r=n-t.height;if(vi()){r>0&&qW(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&Ae(i))&&r>0&&(e.scrollTop=t.top+r),_e.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;vi()?qW(e,t,r):e.scrollTop=t}d(t),je();return}d()},[Ee,s]),cr(()=>{if(H.current)return;let e=U.current;U.current=null,e?.()},[Ee]);let Pe=J(async()=>!1),Fe=J(async e=>{let t=j.current,n=()=>t===j.current&&t?.runtimeKey===m()&&t?.runtimeGeneration===f(),r=Date.now(),i=r+yW,a=R.current,o=a?Ut()?.getRequestState?.(mt(a,e)):void 0;for(ue.current.historyLoading,B.current,o?.status,o?.error;ue.current.historyLoading;){if(!n()||L.current!==e)return Date.now()-r,`switched`;if(Date.now()>=i){let t=a?Ut()?.getRequestState?.(mt(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:yW,hostTurnPageTimeoutMs:wa,historyLoading:ue.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,bW)})}return Date.now()-r,a&&Ut()?.getRequestState?.(mt(a,e))?.status,n()&&L.current===e?`cleared`:`switched`}),Ie=J(async e=>{if(!L.current||F.current||H.current||!ue.current.hasMoreAboveTurns)return!1;F.current=!0,de(),S(!0);let t=L.current,n=j.current,r=()=>n===j.current&&n?.runtimeKey===m()&&n?.runtimeGeneration===f(),s=()=>n?.directory?Ut()?.getPagination(mt(n.directory,t)).cursor??null:null,c=M,d=()=>{r()&&(F.current=!1,S(!1),fe())},p=null,h=null,g=!!e.userInitiated;g&&l();let _=()=>{if(r()){if(H.current){U.current=_;return}h?.settle(),p&&Oe.current===p&&(Oe.current=null,a.current?.cancelViewportAnchorHold()),g&&(g=!1,u())}};try{if(ue.current.historyLoading){if(!e.userInitiated)return!1;let n=await Fe(t);if(n===`timeout`)throw CW();if(n===`switched`||!ue.current.hasMoreAboveTurns)return!1}if(!r()||!L.current||L.current!==t)return!1;let n=i.current,a=z.current,l=a.length,u=a[0]?.info?.id??null,d=B.current?.limit??ZU().HISTORICAL_MESSAGES;e.preserveViewport&&n&&(p={sessionId:L.current,height:n.scrollHeight,top:n.scrollTop,anchor:ke(),oldestId:u,newestId:a[a.length-1]?.info?.id??null},Oe.current=p,Me.current={oldestId:p.oldestId,newestId:p.newestId,scrollHeight:p.height},h=je()??null);let f=l,m=u,g=d,v=0,y=0;for(;;){if(ue.current.historyLoading)if(e.userInitiated){let e=await Fe(t);if(e===`timeout`)throw _(),CW();if(e===`switched`)return _(),!1}else return _(),!1;let n=i.current?.scrollHeight??0,a=f,l=m,u=g,d=s();if(await o(t,`up`),v+=1,!r()||L.current!==t)return _(),!1;if(await me(!0),!r())return!1;if(H.current)return!0;let p=(()=>{let t=z.current;return PW({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:a,messageCountAfter:t.length,oldestIdBefore:l,oldestIdAfter:t[0]?.info?.id??null,limitBefore:u,limitAfter:B.current?.limit??g,cursorBefore:d,cursorAfter:s(),hasMoreAbove:ue.current.hasMoreAboveTurns,pagesLoaded:v,maxPages:e.singlePage?1:FW})})();if(p===`continue`){let e=z.current;f=e.length,m=e[0]?.info?.id??null,g=B.current?.limit??g;continue}if(p===`stop-no-growth`){if(e.singlePage)return _(),!1;if(ue.current.historyLoading){if(e.userInitiated){let e=await Fe(t);if(e===`timeout`)throw _(),CW();if(e===`switched`)return _(),!1;--v;continue}return _(),!1}if(y<IW){y+=1,--v;continue}return D.current=Date.now()+_W,_(),!1}return D.current=0,no.dismiss(c),!0}}catch(e){throw r()&&(D.current=Date.now()+_W),_(),e}finally{r()&&(H.current?U.current=()=>{d(),_()}:(d(),me(!0).then(_)))}}),{t:Le}=fr(),Re=An({mutationKey:RW({runtimeKey:m(),sessionId:e??``}),mutationFn:async e=>{if(j.current!==e.scope||m()!==e.scope.runtimeKey||f()!==e.scope.runtimeGeneration||L.current!==e.sessionId)return!1;de(),e.userInitiated&&c();try{return await Ie({preserveViewport:!0,userInitiated:!!e.userInitiated,singlePage:e.singlePage})}finally{j.current===e.scope&&f()===e.scope.runtimeGeneration&&fe()}}}),ze=J(async e=>{let t=L.current;if(!t||!ue.current.canLoadEarlier)return;let n=A,r=M,i=()=>j.current===n&&m()===n.runtimeKey&&f()===n.runtimeGeneration;if(!(Re.isPending&&Re.variables?.sessionId===t&&Re.variables?.scope===n)){e?.userInitiated&&g?.();try{let r=await Re.mutateAsync({sessionId:t,scope:n,userInitiated:!!e?.userInitiated,singlePage:e?.singlePage});if(!i())return;if(r===!1&&ue.current.canLoadEarlier){let n={sessionId:t,grew:r,userInitiated:!!e?.userInitiated,canLoadEarlier:ue.current.canLoadEarlier,hasMoreAboveTurns:ue.current.hasMoreAboveTurns,historyLoading:ue.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};wW(`no-growth`,Error(`chat history pagination returned no growth`),n)}}catch(n){let a={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:yW,hostTurnPageTimeoutMs:wa,canLoadEarlier:ue.current.canLoadEarlier,historyLoading:ue.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};SW(n)?wW(`timeout`,n,a):wW(`failed`,n,a),i()&&e?.userInitiated&&no.error(SW(n)?Le(`chat.history.loadOlderTimeout`):Le(`chat.history.loadOlderFailed`),{id:r})}}}),Be=Re.isPending&&Re.variables?.sessionId===e&&Re.variables?.scope===A||x,Ve=J(e=>{if(Date.now()<D.current)return;let t=i.current;if(t){if(_.current){let n=ne.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){re.current=null;return}else if(e===`upward-intent`)re.current={top:t.scrollTop};else{let e=re.current;if(!e)return;let n=t.scrollTop<e.top;if(t.scrollTop>e.top||P.current?re.current=null:e.top=t.scrollTop,!n)return}NW({source:e,isMobile:_.current,isPinned:P.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:ue.current.canLoadEarlier,isLoadingOlder:F.current,pendingRevealWork:I.current})&&(_.current&&(ne.current.consumed=!0),re.current=null,ze({userInitiated:!0,singlePage:_.current}))}}),He=J(()=>{Ve(`scroll`)}),Ue=J(()=>{!_.current&&!F.current&&!a.current?.isHistoryVirtualized()&&je()?.settle(),Ve(`upward-intent`)}),We=J(async(t,n)=>{if(!t||!L.current)return!1;c(),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},ge()})}finally{w(!1)}}),Ge=Z.useRef(null),Ke=J(async(t,n)=>{if(!t||!L.current)return!1;let r=`${L.current}:${t}`;if(Ge.current===r)return!1;Ge.current=r;let i=L.current;c(),w(!0);try{if(L.current!==e)return!1;for(;!N.current.messageToTurnId.has(t)&&ue.current.hasMoreAboveTurns;){if(L.current!==i||Ge.current!==r)return!1;let e=z.current[0]?.info.id;if(await ze({userInitiated:!0,singlePage:!0}),await me(),z.current[0]?.info.id===e)break}if(L.current!==i||Ge.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},ge()})}finally{Ge.current===r&&(Ge.current=null),w(!1)}}),qe=J(async()=>{Ge.current=null,w(!1),F.current=!1,S(!1),s(`smooth`)}),Je=J(async()=>{w(!1),F.current=!1,S(!1),s(`instant`)}),Ye=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:Ee,historySignals:le,isLoadingOlder:Be,pendingRevealWork:C,activeTurnId:T,showScrollToBottom:p&&!C,turnWindowModel:b,loadEarlier:ze,revealBufferedTurns:Pe,resumeToBottom:qe,resumeToBottomInstant:Je,scrollToTurn:We,scrollToMessage:Ke,handleHistoryScroll:He,handleHistoryUpwardIntent:Ue,captureViewportAnchor:ke,restoreViewportAnchor:Ae,handleActiveTurnChange:Ye}},XW=12,ZW=50,QW=800;function $W(e){let t=(0,Q.c)(25),{scope:n,enabled:r,cursor:i,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]!==i||t[2]!==r||t[3]!==o||t[4]!==n?(h=r&&!a()&&i!==null&&o<XW&&u!==n,t[0]=u,t[1]=i,t[2]=r,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]!==i||t[11]!==g||t[12]!==s||t[13]!==n?(b=[n,g,i,s],t[10]=i,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],ir(`wheel`,x,void 0,S);let C;t[19]!==i||t[20]!==g||t[21]!==l||t[22]!==n||t[23]!==c?(C=()=>{let e=c.current;if(f.current===n)return;if(!g||a()||!i||!e||p.current||document.visibilityState===`hidden`){m.current=null;return}let t=e.scrollHeight,r=e.scrollTop,o=m.current;if(!o||o.height!==t||o.top!==r){m.current={height:t,top:r,since:Date.now()};return}Date.now()-o.since<QW||(f.current=n,d(n),p.current=!0,l(ZW).catch(eG).finally(()=>{p.current=!1}))},t[19]=i,t[20]=g,t[21]=l,t[22]=n,t[23]=c,t[24]=C):C=t[24],or(J(C),g?200:null)}function eG(e){console.error(`[chat-history] desktop history warmup failed`,e)}var tG=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),nG=({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}=fr(),{isMobile:f}=Us(),[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)(rG,{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)(sc,{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)(Ko,{open:e,onOpenChange:t,children:(0,$.jsx)(Ho,{presentation:`picker`,className:`yuri-timeline-dialog`,children:S})})},rG=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}=fr(),b=Zb(),x=i,S=ca(x??``,a),C=Wa(aG),w=Wa(oG),T;t[0]===b.capabilities?T=t[1]:(T=tG(b.capabilities),t[0]=b.capabilities,t[1]=T);let E=T,{isMobile:D,isTablet:O}=Us(),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=sG,L=cG,R;t[3]===S?R=t[4]:(R=S.filter(lG).map(uG),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 aU(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,G;t[19]===h?(te=t[20],G=t[21]):(G=()=>{P.current||j.current[h]?.scrollIntoView({block:`nearest`})},te=[h],t[19]=h,t[20]=te,t[21]=G),Z.useEffect(G,te);let ne;t[22]===u?ne=t[23]:(ne=()=>{!P.current||N.current||u||(P.current=!1)},t[22]=u,t[23]=ne);let re;t[24]!==V.length||t[25]!==u?(re=[V.length,u],t[24]=V.length,t[25]=u,t[26]=re):re=t[26],Z.useEffect(ne,re);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)(Bo,{className:`yuri-timeline-header`,children:(0,$.jsx)(Uo,{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)($o,{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)($r,{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=oU(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()?iG(aU(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)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{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)(ts,{sideOffset:6,children:y(`chat.timeline.actions.revertFromHere`)})]}):null,E.fork?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{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)(ts,{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)(ld,{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)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:_!==null,onClick:()=>{s?.(-1),r(!1)},children:y(`chat.timeline.actions.previousTurn`)}):null,c?(0,$.jsx)($r,{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 iG(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 aG(e){return e.revertToMessage}function oG(e){return e.forkFromMessage}function sG(e){return Ad(e)}function cG(e){return hd(e)}function lG(e){return e.info.role===`user`}function uG(e){return{message:e}}function dG(e){let t=(0,Q.c)(40),{messages:n,enabled:r,canOpen:i,onNavigate:a,children:o}=e,{t:s}=fr(),[c,l]=Z.useState(!1),[u,d]=Z.useState(``),f=Z.useDeferredValue(u),[p,m]=Z.useState(0),[h,g]=Z.useState(0);!r&&c&&l(!1);let _=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),b=r&&c,x;t[0]!==f||t[1]!==b?(x=b?xA(f):null,t[0]=f,t[1]=b,t[2]=x):x=t[2];let S=x,C;t[3]!==n||t[4]!==S?(C=S?.(n)??[],t[3]=n,t[4]=S,t[5]=C):C=t[5];let w=C,T=Math.min(p,Math.max(0,w.length-1)),E=b&&u===f?w[T]??null:null,D=E?.messageId,O=E?.partId,k=E?.occurrence,A=E?.query,j;t[6]!==A||t[7]!==D||t[8]!==h||t[9]!==k||t[10]!==O?(j=D!==void 0&&O!==void 0&&k!==void 0&&A!==void 0?{messageId:D,partId:O,occurrence:k,query:A,navigationId:h}:null,t[6]=A,t[7]=D,t[8]=h,t[9]=k,t[10]=O,t[11]=j):j=t[11];let M=j,N;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(N=()=>{l(!1),y.current?.isConnected&&y.current.focus({preventScroll:!0})},t[12]=N):N=t[12];let P=J(N),F;t[13]!==a||t[14]!==w.length||t[15]!==T?(F=e=>{w.length&&(a(),m((T+e+w.length)%w.length),g(fG))},t[13]=a,t[14]=w.length,t[15]=T,t[16]=F):F=t[16];let I=J(F),L;t[17]!==i||t[18]!==P||t[19]!==r||t[20]!==a||t[21]!==b?(L=e=>{!r||e.defaultPrevented||e.isComposing||!(e.target instanceof Node&&v.current?.contains(e.target))&&!i(e)||((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`f`?(e.preventDefault(),e.stopPropagation(),b?(_.current?.focus({preventScroll:!0}),_.current?.select()):(y.current=document.activeElement instanceof HTMLElement?document.activeElement:null,a(),l(!0))):b&&e.key===`Escape`&&(e.preventDefault(),P()))},t[17]=i,t[18]=P,t[19]=r,t[20]=a,t[21]=b,t[22]=L):L=t[22],ir(`keydown`,L);let R,z;t[23]===b?(R=t[24],z=t[25]):(R=()=>{b&&_.current?.focus({preventScroll:!0})},z=[b],t[23]=b,t[24]=R,t[25]=z),Z.useEffect(R,z);let B;t[26]!==P||t[27]!==f||t[28]!==I||t[29]!==a||t[30]!==u||t[31]!==w.length||t[32]!==T||t[33]!==s||t[34]!==b?(B=b&&(0,$.jsxs)(`div`,{ref:v,role:`search`,"aria-label":s(`chat.find.label`),className:`yuri-transcript-find yuri-mobile-overlay-surface yuri-popup-surface absolute right-3 top-3 z-30 w-[min(22rem,calc(100%-1.5rem))] overflow-hidden rounded-2xl`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,children:[(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 text-foreground`}),(0,$.jsx)($o,{ref:_,bordered:!1,value:u,"aria-label":s(`chat.find.label`),placeholder:s(`chat.find.label`),onChange:e=>{a(),d(e.target.value),m(0)},onKeyDown:e=>{e.nativeEvent.isComposing||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),P()):e.key===`Enter`&&(e.preventDefault(),I(e.shiftKey?-1:1)))}}),(0,$.jsx)(`div`,{className:`yuri-transcript-find-close pl-1.5`,children:(0,$.jsx)($r,{variant:`ghost`,size:`icon`,"aria-label":s(`chat.find.close`),onClick:P,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})})]}),(0,$.jsxs)(`div`,{className:`yuri-transcript-find-navigation flex items-center gap-0.5 px-2 py-0.5`,children:[(0,$.jsx)($r,{variant:`ghost`,size:`icon`,disabled:!w.length||u!==f,"aria-label":s(`chat.find.previous`),onClick:()=>I(-1),children:(0,$.jsx)(X,{name:`arrow-up`,className:`size-4`})}),(0,$.jsx)($r,{variant:`ghost`,size:`icon`,disabled:!w.length||u!==f,"aria-label":s(`chat.find.next`),onClick:()=>I(1),children:(0,$.jsx)(X,{name:`arrow-down`,className:`size-4`})}),(0,$.jsx)(`span`,{className:`ml-auto pr-2 typography-meta tabular-nums text-muted-foreground`,role:`status`,"aria-live":`polite`,children:s(`chat.find.count`,{current:w.length?T+1:0,total:w.length})})]})]}),t[26]=P,t[27]=f,t[28]=I,t[29]=a,t[30]=u,t[31]=w.length,t[32]=T,t[33]=s,t[34]=b,t[35]=B):B=t[35];let V;return t[36]!==o||t[37]!==B||t[38]!==M?(V=(0,$.jsxs)(hA.Provider,{value:M,children:[o,B]}),t[36]=o,t[37]=B,t[38]=M,t[39]=V):V=t[39],V}function fG(e){return e+1}var pG=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},mG=(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`}},hG=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`))},gG=e=>{e&&hG(`message-${e}`)},_G=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&&hG(`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&&hG(`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=mG(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 hG(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=()=>{hG(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=pG(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},vG=2e4,yG=6e4,bG=2e3,xG=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,SG=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+=xG(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},CG={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},wG=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:CG,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}},TG=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function EG(e){return!!(e.active&&e.sessionId&&e.sessionKey&&e.sessionIsWorking)}function DG(e){return e===CG?e:CG}function OG(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 kG(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 AG(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||OG(i)==null}function jG(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!AG(n))continue;let e=kG(n);e&&t.push(e)}}return t}function MG(e,t){return`${e}:${t.join(`,`)}`}function NG(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=MG(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function PG(e,t,n,r){let i=(0,Q.c)(7),a=Mi(),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=NG({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:jG(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,ri(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 FG=[0,200,400],IG=e=>{let t=(0,Q.c)(5),{className:n}=e,r;t[0]===n?r=t[1]:(r=Y(`inline-flex`,n),t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=FG.map(LG),t[2]=i):i=t[2];let a;return t[3]===r?a=t[4]:(a=(0,$.jsxs)($.Fragment,{children:[`\xA0`,(0,$.jsx)(`span`,{className:r,"aria-hidden":`true`,children:i})]}),t[3]=r,t[4]=a),a};function LG(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var RG=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),zG=(e,t)=>({...e,key:BG(e),estimatedBytes:RG(t)}),BG=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),VG=e=>({key:e?BG(e):null,selection:e}),HG=(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},UG=(e,t,n,r)=>{let i=BG(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return HG(e,i,n);let s=o||zG(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),HG(c,i,n)},WG=(e,t,n)=>{let r=RG(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)},GG=(e,t)=>t&&e.some(e=>e.key===t)?t:null,KG=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?UG(e.cachedSessionViews,t.selection,n,r.estimatedBytes):HG(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}},qG=(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:zG(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},JG=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:UG(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},YG=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},XG=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},ZG=e=>XG(e)?.role===`assistant`,QG=(e,t)=>{let n=XG(t);n&&(e.agentName??=YG(n.agent),e.providerId??=YG(n.providerID),e.modelId??=YG(n.modelID))},$G=e=>!!(e.agentName&&e.providerId&&e.modelId),eK=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!ZG(r))&&(QG(t,r),$G(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||ZG(r))&&(QG(t,r),$G(t)))break}return t},tK=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),nK=[],rK=[],iK=[],aK={type:`idle`},oK=`yuri:chat-force-scroll-bottom`,sK=()=>void 0,cK=`Quota limit reached. Retrying automatically.`,lK=1048576,uK=lK,dK=20,fK=lK,pK=16*lK,mK={maxEntries:3,maxEstimatedBytes:32*lK},hK={maxEntries:2,maxEstimatedBytes:32*lK},gK=e=>c(()=>e()),_K={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},vK=()=>{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},yK=[`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(`,`),bK=e=>e instanceof HTMLElement,xK=e=>bK(e)?!!e.closest(yK):!1,SK=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||xK(e)?!0:!t?.contains(e),CK=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=q.getState();return e||t||n||r||i||a||o},wK=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}=fr(),I=Z.useContext(hA),L=J(()=>{I||v()}),R=Vk({isLoadingOlder:d}),[z,B]=Z.useState({sessionId:e,directory:a,reserved:T}),V=z.sessionId===e&&z.directory===a,H=V&&z.reserved||T;(!V||z.reserved!==H)&&B({sessionId:e,directory:a,reserved:H});let U=Hk({isMobile:r,isLoadingOlder:R})?(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,W=r&&H?(0,$.jsx)(`div`,{className:Y(`flex justify-center pt-3 pb-4`,!R&&`invisible`),"aria-hidden":!R,children:(0,$.jsxs)(`span`,{role:`status`,className:`flex items-center gap-1.5 text-[var(--surface-mutedForeground)] opacity-60`,"aria-busy":R,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,ee=Z.useRef(new Map),te=Z.useRef(new WeakMap),G=Z.useRef(new Map),ne=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(gR(n)){let r=yR(u,t)??``,i=G.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`}];G.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(Pr(n.parts))continue;let r=te.current.get(n.parts);r||(r=Nk(n.parts),te.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=ee.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 ee.current=e,e},[u]),re=Z.useMemo(()=>E.filter(e=>ne.has(e)),[ne,E]),ie=Z.useRef(new Map),ae=Z.useMemo(()=>{let e=new Map,t=new Map,n;for(let r of u){if(r.info.role===`user`){ne.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=aU(r.parts).trim();o&&t.set(a,o.slice(0,600))}let r=ie.current;return(r.size!==e.size||[...e].some(([e,t])=>r.get(e)!==t))&&(ie.current=e),{owners:ie.current,replies:t}},[ne,u]),oe=Z.useMemo(()=>{if(!D||ne.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(ne.has(e))return e}return null},[D,ne,E]),se=J(e=>{e.defaultPrevented||xK(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)(ud,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:_K,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:se,onScroll:L,"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:[W,U,(0,$.jsx)(wH,{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)(uz,{})}):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)(XH,{question:e},e.id)),x.map(e=>(0,$.jsx)(UH,{permission:e},e.id)),S.map(e=>(0,$.jsx)(QH,{form:e,directory:a},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?UT:HT},"aria-hidden":`true`})]})}),(0,$.jsx)(cd,{containerRef:o,suppressVisibility:w,userIntentOnly:!0,observeMutations:!1}),k&&re.length>=2?(0,$.jsx)(DU,{turnIds:re,previewsByTurnId:ne,scrollRef:o,turnByMessageId:ae.owners,repliesByTurnId:ae.replies,activeTurnId:oe,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);wK.displayName=`ChatViewport`;var TK=[{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%]`]}],EK=e=>Wi(e.path),DK=(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)]})},OK=e=>{let t=Math.ceil(Math.max(0,e)/dK);return Math.min(pK,uK+t*fK)},kK=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:u,warning:d=null,pendingUserMessages:f=rK,onPendingUserMessagesMaterialized:p,committedDraftHandoffMessageId:h=null})=>{let g=c??Kk(void 0),{t:_}=fr();cr(()=>{ya()},[]);let v=Wa(e=>e.openNewSessionDraft),y=Wa(e=>e.setCurrentSession),b=Wa(e=>e.newSessionDraft),x=Wa(e=>e.newSessionDraft.draftSubmitting??!1),S=Wa(e=>e.newSessionDraft.draftEstablishing??!1),C=Wa(e=>e.forkTransition),w=Mr(e=>e.projects),T=Mr(e=>e.activeProjectId),D=ei(e=>e.providers),O=ch(),k=ia(),A=i??k;cr(()=>{!n||!r||!A||di(A,r)},[n,r,A]);let j=J(e=>O.ensureSessionRenderable(e,{directory:A})),M=q(e=>e.isExpandedInput),N=q(e=>e.stickyUserHeader),P=q(e=>e.promptNavigatorEnabled),F=q(e=>e.allowPromptingSubagentSessions),I=q(e=>e.isTimelineDialogOpen),L=q(e=>e.setTimelineDialogOpen),R=ka(e=>n&&r?e.streamingMessageIds.get(r)??null:null),z=ka(e=>R?e.messageStreamStates.get(R)?.phase??null:null),B=Ua(r??``,A),V=OK(B);Z.useEffect(()=>{!a||!o||o(a,V)},[o,V,a]);let H=ta(r??``,A).renderable,U=hr(r,A),W=Vr(r),ee=U??W,te=wx({sessionId:r,hasSessionEntity:!!ee,hasRenderableSessionSnapshot:H,composerSurfaceKind:s?.kind}),G=r?JSON.stringify([A,r]):null,[ne,re]=Z.useState({key:G,attempt:0}),ie=ca(r??``,A,{suspendPartUpdates:!!R,suspendPartUpdatesForMessageId:R,enabled:n}),ae=r?ie:nK,oe=b.pendingUserMessage,se=Wa(e=>r?e.retainedPendingUserMessages.get(r):void 0)??rK,ce=!!(h||se.length>0),le=Wa(e=>e.clearRetainedPendingUserMessages),ue=Z.useMemo(()=>{if(se.length===0)return f;if(f.length===0)return se;let e=new Set(f.map(e=>e.info.id));return[...f,...se.filter(t=>!e.has(t.info.id))]},[f,se]),de=Z.useMemo(()=>eK(ae),[ae]),fe=Z.useMemo(()=>{if(!de.modelId)return _(`common.unavailable`);let e=D.find(e=>e.id===de.providerId);return Ki(e,de.modelId)||de.modelId},[D,de.modelId,de.providerId,_]),pe=eo(r??``,A),me=Xi(r??``,A),[he,ge]=Z.useState(null),_e=!!r&&he===r,ve=J(()=>{if(!r||_e)return;let e=r,t=A;ge(e);let n=wr(()=>{let n=Ut();if(!n)throw Error(`unbound`);return n.getTranscript(mt(t,e))});na(wi({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:pe?{sessionID:e,status:pe.status===`ready`?`ready`:pe.status,error:pe.error}:void 0,hydration:me,error:pe?.error})),(async()=>{try{await hn(t,e),await O.ensureSessionRenderable(e,{directory:t});try{let r=wr(()=>{let n=Ut();if(!n)throw Error(`unbound`);return n.getTranscript(mt(t,e))});n&&r&&po({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){na(wi({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:me,error:n}))}finally{ge(t=>t===e?null:t)}})()}),ye=oo(r??``,A).boundary,be=J(async e=>{if(ye.kind===`has-more`){await Gt(A,e,ze||Be?void 0:50);return}if(ye.kind===`unknown`){await Qe(A,e);return}l&&!l.complete&&await l.fetchPrevious()}),xe=Fa(r??``,A),Se=Sa(r??``,A),Ce=va(A),we=xe??aK,Te=Hi(r,A),Ee=Bi(r,A),De=Ar(e=>r?e.forms[r]??iK:iK),Oe=Z.useMemo(()=>De.filter(e=>!Ge(e.metadata)),[De]);Z.useEffect(()=>{r&&Fr({sessionID:r,directory:A}).catch(e=>{console.error(`[ChatContainer] Failed to list session forms:`,e)})},[r,A]),PG(r,A,ae,Ee.length);let ke=Z.useMemo(()=>{if(!r||Te.length>0||Ee.length>0)return!1;let e=we.type??`idle`;if(e===`busy`||e===`retry`||Lk(ue,{resolvedSessionStatus:xe,sessionStatusObservedAt:Se}))return!0;let t=ae[ae.length-1]?.info,n=t?.time?.created;return xe&&typeof Se==`number`&&typeof n==`number`&&n<=Se||typeof Ce==`number`&&typeof n==`number`&&n<=Ce?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,ue,xe,ae,Te.length,Ee.length,we.type,Se,Ce]),Ae=Z.useMemo(()=>!r||we.type!==`retry`?null:{sessionId:r,message:(typeof we.message==`string`?(we.message??``).trim():``)||cK,confirmedAt:we.confirmedAt},[r,we]),[je,Me]=Z.useState(0),Ne=Z.useRef(null);Z.useEffect(()=>{if(!Ae||typeof Ae.confirmedAt==`number`){Ne.current=null,Me(0);return}Ne.current!==Ae.sessionId&&(Ne.current=Ae.sessionId,Me(Date.now()))},[Ae]);let Pe=Z.useMemo(()=>!Ae||nU(we)?null:{...Ae,fallbackTimestamp:je},[Ae,je,we]),Fe=Z.useMemo(()=>rU(we,e=>_(e)),[we,_]),Ie=!!(r&&O.isLoading(r,{directory:A})),Re=Z.useMemo(()=>{if(!r)return null;let e=Rk({boundary:ye,assistantComplete:l?.complete??!0});return{limit:ye.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:zk({syncLoading:Ie,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,ye,Ie]),ze=q(e=>e.isMobile),Be=fc()!==null,Ve=E(),He=mx(),Ue=!!b?.open,We=oi(e=>e.error),Ke=M,qe=Be||ze||Ve||He===`mini-chat`,Je=Z.useRef(null),Ye=Z.useMemo(()=>{let e=b?.selectedProjectId?w.find(e=>e.id===b.selectedProjectId)??null:null,t=T?w.find(e=>e.id===T)??null:null,n=e??t??w[0]??null;return n?EK(n):null},[T,b?.selectedProjectId,w]),Xe=Jr(r,A),Ze=a??r??``,[$e,et]=Z.useState(null),tt=kx($e,Ze,Xe,de);cr(()=>{et(e=>kx(e,Ze,Xe,de))},[Xe,de,Ze]);let nt=Xe??tt?.parentTarget??null,rt=tt?.execution??de,it=Qs(),at=it!==null&&r===it,ot=J(()=>{nt&&y(nt.id,nt.directory)}),st=nt?.session?.title,ct=g.returnToParent&&nt&&!at?(0,$.jsxs)($r,{type:`button`,variant:`outline`,size:`xs`,onClick:ot,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":_(`chat.container.returnToParent.aria`),title:st?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:st}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,lt=Tx({readOnly:t,sessionIdentityPending:te,isSubagentSession:!!ee?.parentID||!!tt,allowPromptingSubagentSessions:F}),ut=rt.modelId===de.modelId?fe:rt.modelId?Ki(D.find(e=>e.id===rt.providerId),rt.modelId)||rt.modelId:_(`common.unavailable`),dt=nt?(0,$.jsx)(Xk,{agentName:rt.agentName,providerId:rt.providerId,modelId:rt.modelId,modelName:ut}):(0,$.jsx)(Xk,{}),ft=J(e=>{q.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),pt=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`&&ft({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),ht=typeof window<`u`&&window.parent!==window;ir(`message`,pt,ht?window:sK),nr(()=>{if(!ht)return;let e=window;e.__yuriApplyChatSettingsSync=ft,window.parent.postMessage({type:`yuri:chat-settings-request`},window.location.origin)}),rr(()=>{if(typeof window>`u`)return;let e=window;e.__yuriApplyChatSettingsSync===ft&&delete e.__yuriApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Ue&&v()},[e,r,Ue,g.newSessionDraft,v]);let gt=Z.useRef(()=>{}),_t=J(e=>{gt.current(e)}),vt=Z.useRef(()=>{}),yt=J(()=>{vt.current()}),[bt,xt]=Z.useState(0),St=J(()=>{xt(e=>e+1)}),{scrollRef:Ct,notifyContentChange:wt,getAnimationHandlers:Tt,goToBottom:Et,scrollToBottomOnSend:Dt,releaseAutoFollow:Ot,beginHistoryViewportPreservation:kt,endHistoryViewportPreservation:At,restoreSnapshot:jt,isPinned:Mt,isFollowingProgrammatically:Nt,showScrollButton:Pt}=uE({scrollControllerRef:Je,enabled:n,currentSessionId:r,viewportKey:a,sessionMessageCount:B,sessionIsWorking:ke,isMobile:ze,onActiveTurnChange:_t,onUpwardUserIntent:yt}),Ft=Z.useRef(null),It=zU({enabled:ze,scrollRef:Ct,scopeRef:Ft}),Lt=Z.useRef([]),Rt=Z.useMemo(()=>{let e=aA(l?.entries??[],r,Lt.current);return Lt.current=e,e},[l?.entries,r]),zt=Z.useRef([]),Bt=Z.useMemo(()=>{if(!l)return ae;let e=cA(l.entries,r,ae,zt.current);return zt.current=e,e},[l,r,ae]),Vt=Z.useMemo(()=>Ik(Rt.length===0?Bt:r?[...Rt,rA(r),...Bt]:Rt,ue),[r,Bt,Rt,ue]),Ht=Z.useRef(null),Wt=Z.useMemo(()=>Gk({sessionId:r,messages:Vt,retained:Ht.current}),[r,Vt]);Ht.current=Wt.retained;let Kt=Wt.messages,qt=Z.useRef(null),Jt=qt.current===r,Yt=Z.useRef(CG),Xt=r?`${A}\n${r}`:null,Zt=J(()=>SG(Kt));Z.useEffect(()=>{if(!EG({active:n,sessionId:r,sessionKey:Xt,sessionIsWorking:ke})){Yt.current=DG(Yt.current);return}let e=r,t=A,i=setInterval(()=>{let n=Zt(),r=wG(Yt.current,{sessionKey:Xt,working:!0,streaming:!!R,fingerprint:n,now:Date.now(),thresholdMs:vG,cooldownMs:yG,maxAttempts:3});Yt.current=r.state,r.shouldRefresh&&(TG({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),Le(t,e).catch(()=>{}))},bG);return()=>clearInterval(i)},[n,r,A,Zt,ke,R,Xt]);let Qt=Z.useMemo(()=>{if(ue.length===0)return[];let e=new Set([...Rt,...Bt].filter(e=>Fk(e.parts)).map(e=>e.info.id));return ue.map(e=>e.info.id).filter(t=>e.has(t))},[Bt,Rt,ue]);Z.useEffect(()=>{Qt.length!==0&&(p?.(Qt),r&&le(r,Qt))},[le,r,Qt,p]);let $t=YW({sessionId:r,directory:A,messages:Kt,historyMeta:Re,scrollRef:Ct,messageListRef:Je,loadMoreMessages:be,goToBottom:Et,releaseAutoFollow:Ot,beginHistoryViewportPreservation:kt,endHistoryViewportPreservation:At,isPinned:Mt,showScrollButton:Pt,isMobile:ze,onWillLoadEarlier:St}),en=J(()=>{Et(`instant`),It()}),tn=J(e=>{if(q.getState().activeMainTab!==`chat`||CK())return!1;let t=e.target;return!(t instanceof HTMLElement)||Ft.current?.contains(t)?!0:!t.closest(`input, textarea, [contenteditable="true"], .cm-editor, .monaco-editor, .terminal-viewport-container`)}),nn=J(()=>{Dt()}),rn=Bk({isMobile:ze,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingOlder:$t.isLoadingOlder}),an=$t.isLoadingOlder,on=$t.loadEarlier,sn=J(()=>{on({userInitiated:!0})});gt.current=$t.handleActiveTurnChange,vt.current=$t.handleHistoryUpwardIntent,Z.useEffect(()=>{(Te.length!==0||Ee.length!==0)&&wt(`permission`)},[wt,Te,Ee]);let cn=_G({sessionId:r,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,scrollToTurn:$t.scrollToTurn,scrollToMessage:$t.scrollToMessage,resumeToBottom:en}),ln=lt.showReadOnlyBanner?dt:t?null:(0,$.jsx)(dk,{surface:s,scrollToBottom:nn,submissionBlocked:lt.blockSubmission},`composer-input`),un=J(e=>{cn.scrollToTurnId(e,{behavior:`smooth`})}),dn=$t.historySignals.canLoadEarlier,K=g.promptNavigator&&!ze&&!Ve&&!Ke&&P&&$t.turnIds.length>=2;Z.useEffect(()=>{K||q.getState().setPromptNavigatorPanelOpen(!1)},[K]);let fn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||Et(`instant`)});ir(oK,fn,n&&r&&typeof window<`u`?window:sK);let pn=J(e=>{if(!n||!r||Ke||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=q.getState();if(t!==`chat`||CK())return;let i=Ct.current;if(SK(document.activeElement,i)||xK(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;cn.scrollByTurnOffset(a,{resumePastEnd:!1})});ir(`keydown`,pn,n&&r&&!Ke&&typeof window<`u`?window:sK);let mn=Z.useRef(0),gn=J(()=>{let e=Ct.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),_n=J(()=>{mn.current||=requestAnimationFrame(()=>{mn.current=0,gn()})});cr(()=>{n&&gn()},[n,r,Ke,gn]);let vn=typeof ResizeObserver<`u`;sr(n&&vn?Ct:null,_n),ir(`resize`,_n,n&&!vn&&typeof window<`u`?window:sK),rr(()=>{mn.current&&=(cancelAnimationFrame(mn.current),0)});let yn=Z.useRef(null),bn=Z.useRef(0),xn=Uk({transcriptMessageCount:ae.length,pendingUserCount:ue.length,historyPrefixCount:Rt.length}),Sn=Wk({hasTranscriptShell:xn,transcriptRecords:ae,p0Satisfied:me.p0Satisfied,hasBusyShell:ke&&xn,hasImmediateShell:ue.length>0||Rt.length>0,hasRenderableSessionSnapshot:H,prefetchStatus:pe?.status,syncLoading:!!(r&&O.isLoading(r,{directory:A})),userRetrying:_e,hasPaintedTranscript:Jt});Sn===`pass`&&Kt.length>0&&(qt.current=r);let Cn=!!r&&Sn===`hydrating`;$W({scope:JSON.stringify([m(),A,r]),enabled:n&&!ze&&!Be&&!!r&&Sn===`pass`&&me.p0Satisfied&&!ke&&!Re?.loading&&!$t.isLoadingOlder,cursor:ye.kind===`has-more`?ye.cursor:null,loadedTurns:ye.loadedTurns,messages:Kt,scrollRef:Ct,loadPrevious:e=>Gt(A,r,e)});let wn=!!r&&Sn===`load-error`;Z.useEffect(()=>{!wn||!r||na(wi({kind:`request-error`,sessionID:r,directory:A,purpose:`load-failed`,source:`network`,request:pe?{sessionID:r,status:pe.status===`ready`?`ready`:pe.status,error:pe.error}:void 0,hydration:me,error:pe?.error}))},[r,A,wn,pe,me]),Z.useEffect(()=>{if(!n||!r||Cn)return;let e=Kt.length,t=yn.current!==r,i=!t&&bn.current===0&&e>0;if(!t&&!i){yn.current===r&&(bn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(yn.current=r,bn.current=e,a){Ot();return}let o=()=>{jt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,Cn,Ot,jt,Kt.length]),Z.useEffect(()=>{re(e=>e.key===G?e:{key:G,attempt:0})},[G]),Z.useEffect(()=>{if(!n||!r||ne.key!==G||!tK({sessionId:r,hasRenderableSessionSnapshot:H,hasCurrentSessionEntity:!!ee})||(j(r),ee||ne.attempt>=2))return;let e=ne.attempt+1,t=window.setTimeout(()=>{re(t=>t.key===G&&t.attempt===ne.attempt?{key:G,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,ee,r,A,j,H,G,ne]);let Tn=C&&r&&(C.targetSessionId?r===C.targetSessionId:r===C.sourceSessionId)?C:null;if(Tn){let e=Tn.stage===`preparing`?`chat.forkTransition.preparing`:Tn.stage===`copying`?`chat.forkTransition.copying`:Tn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Tn.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)(IG,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}if(!r&&!Ue)return e&&!We?(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)(Qk,{})});if(!r&&Ue){if((x||S)&&oe){let e=`draft:${b.draftID??`pending`}`;return(0,$.jsxs)(`div`,{ref:Ft,className:Y(`relative flex h-full flex-col bg-background`,ze&&`yuri-chat-composer-swap-scope`),children:[(0,$.jsx)(wK,{timelineHistoryAnchorToken:bt,currentSessionId:e,virtualizerKey:e,isDesktopExpandedInput:!1,isMobile:ze,stickyUserHeader:N,directory:A,scrollRef:Ct,messageListRef:Je,pendingRevealWork:!1,initialPinRevealComplete:!0,renderedMessages:[oe],isLoadingOlder:!1,sessionIsWorking:!0,streamingMessageId:null,activeStreamingPhase:null,retryOverlay:null,handleMessageContentChange:wt,getAnimationHandlers:Tt,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:[],sessionPermissions:[],sessionForms:[],retryActionCopy:null,isProgrammaticFollowActive:Nt,showLoadOlderButton:!1,turnIds:[],activeTurnId:null,onSelectTurn:un,showPromptNavigator:!1,canLoadEarlierPrompts:!1,isLoadingOlderPrompts:!1,onLoadEarlierPrompts:sn,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)(IG,{})]})})},e),(0,$.jsxs)(`div`,{className:Y(`invisible pointer-events-none relative z-10`,ze&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Ke?`absolute inset-0 bg-background`:`bg-background`),"aria-hidden":`true`,children:[!ze&&!Ke?(0,$.jsx)(vK,{}):null,ln]})]})}return x||S?(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)(IG,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[qe&&!Ke?(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:DK(Ye?_(`chat.emptyState.draftTitleWithProject`,{project:Ye}):_(`chat.emptyState.draftTitle`),Ye)}),(0,$.jsx)(xS,{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`,ze&&`yuri-mobile-composer-foot`,Ke?`flex-1 bg-background`:qe?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:ln})]})}return r?wn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[ct,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Ke?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Ke,children:Ke?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)($r,{type:`button`,className:`mt-5`,onClick:ve,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:ln},`composer-foot`)]}):Cn?(0,$.jsxs)(`div`,{ref:Ft,className:Y(`relative flex flex-col h-full bg-background`,ze&&`yuri-chat-composer-swap-scope`),children:[ct,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Ke?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Ke,children:(0,$.jsx)(`div`,{ref:Ct,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:_K,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:TK.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)(Kd,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(Kd,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(Kd,{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)(Kd,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(Kd,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(Kd,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!ze&&!Ke?(0,$.jsx)(vK,{}):null,ln]},`composer-foot`)]}):Kt.length===0&&!ke?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[ct,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Ke?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Ke,children:Ke?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(Qk,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:ln},`composer-foot`)]}):(0,$.jsxs)(`div`,{ref:Ft,className:Y(`relative flex flex-col h-full bg-background`,ze&&`yuri-chat-composer-swap-scope`),children:[d?(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:d}):null,ct,(0,$.jsx)(dG,{messages:Kt,enabled:n&&!Ke,canOpen:tn,onNavigate:Ot,children:(0,$.jsx)(wK,{timelineHistoryAnchorToken:bt,currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Ke,isMobile:ze,stickyUserHeader:N,directory:A,scrollRef:Ct,messageListRef:Je,pendingRevealWork:$t.pendingRevealWork,initialPinRevealComplete:ce,renderedMessages:$t.renderedMessages,isLoadingOlder:an,sessionIsWorking:ke,streamingMessageId:R,activeStreamingPhase:z,retryOverlay:Pe,handleMessageContentChange:wt,getAnimationHandlers:Tt,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:Ee,sessionPermissions:Te,sessionForms:Oe,retryActionCopy:Fe,isProgrammaticFollowActive:Nt,showLoadOlderButton:rn,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,onSelectTurn:un,showPromptNavigator:K,canLoadEarlierPrompts:dn,isLoadingOlderPrompts:an,onLoadEarlierPrompts:sn},r)},`find:${a??r}`),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!ze&&!Ke?(0,$.jsx)(vK,{}):null,(0,$.jsx)(iU,{scrollRef:Ct,active:n&&!Ke,showScrollToBottom:Kt.length>0&&$t.showScrollToBottom,onScrollToBottom:cn.resumeToLatest}),ln]},`composer-foot`),(0,$.jsx)(nG,{open:I,onOpenChange:L,sessionID:r??void 0,directory:A,onRevertMessage:u,onScrollToMessage:$t.scrollToMessage,onScrollByTurnOffset:cn.scrollByTurnOffset,onResumeToLatest:en,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingEarlier:an,onLoadEarlier:sn})]}):null});kK.displayName=`MemoizedChatContainerContent`;var AK=()=>{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)(Kd,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(Kd,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(Kd,{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)(Kd,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(Kd,{className:`h-4 w-3/5 animate-none rounded-md`})]})]})})}),e[1]=n):n=e[1],n},jK=({runtimeKey:e,...t})=>{let n=mx(),r=ia(),i=Wa(oe(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),cr(()=>{!o||!i.draftPendingMessageId||(a.current={identity:o,messageId:i.draftPendingMessageId})},[o,i.draftPendingMessageId]);let s=Wa(e=>i.sessionId?e.retainedPendingUserMessages.get(i.sessionId)??rK:rK),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(()=>VG(u),[u]),f=d.key,p=vi()||E()||n===`mini-chat`?hK:mK,[m,h]=Z.useState(()=>({activeIntent:d,cacheNeedsTrim:!1,cachedSessionViews:u?UG([],u,p,uK):[],pendingSessionView:null})),g=Z.useRef(d),_=Z.useRef(f),{cacheNeedsTrim:v,cachedSessionViews:y,pendingSessionView:b}=m,x=b?.intent===d?b.entry:null,S=Z.useMemo(()=>!u||!l?null:UG([],u,p,uK)[0]??null,[p,l,u]),C=Z.useMemo(()=>{let e=[...y];return x&&!e.some(e=>e.key===x.key)&&e.push(x),S&&!e.some(e=>e.key===S.key)&&e.push(S),e.sort((e,t)=>e.key.localeCompare(t.key))},[y,S,x]),w=GG(C,f),T=!!(f&&!w);cr(()=>{g.current=d,_.current=f,h(e=>{let t=KG(e,d,p);return l?qG(t,d,d,uK):t})},[p,v,l,d,f]);let D=b?.intent??null;cr(()=>{D&&h(e=>JG(e,D,p))},[p,D]),Z.useEffect(()=>{if(!d.selection||w)return;let e=d,t=f;return nd(()=>{g.current===e&&_.current===t&&h(n=>_.current===t?qG(n,e,g.current,uK):n)},{priority:`user-blocking`})},[w,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=WG(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":T||void 0,children:[T?(0,$.jsx)(AK,{},f):null,C.map(e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:w===e.key?`visible`:`hidden`,children:(0,$.jsx)(kK,{...t,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:O,committedDraftHandoffMessageId:w===e.key?l:null})},e.key)),f?null:(0,$.jsx)(kK,{...t,sessionId:null,sessionDirectory:i.directory})]})},MK=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=Kk(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)(kK,{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)(Xb.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},NK=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=ia(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Yb({...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)(kK,{...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)(Xb.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},PK=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(gK,m,m);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(MK,{...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)(NK,{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)(jK,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r},FK=2e4,IK=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus()?`visible`:`hidden`,LK=e=>{if(!_()&&!D())return;let t=A();t?.push?.setVisibility&&t.push.setVisibility({visible:e,platform:O()})},RK=e=>{let t=e?.enabled??!0;Z.useEffect(()=>{if(!t||!_()&&!D()||typeof window>`u`)return;if(D()){let e=!0,t=!1,n=null,r=()=>LK(e);Wn(async()=>{let{App:e}=await import(`./vendor-capacitor-app-B5H_XtmE.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([78,1,14])).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&&LK(!0)},FK);return()=>{t=!0,window.clearInterval(i),n?.()}}if(typeof document>`u`)return;let e=()=>{LK(IK()===`visible`)},n=()=>{IK()===`visible`&&LK(!0)},r=()=>{LK(!1)};e();let i=window.setInterval(n,FK);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])},zK=`Yuri`,BK=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``).split(`/`).filter(Boolean);return t[t.length-1]??``},VK=(e,t)=>[e,t,zK].filter(e=>typeof e==`string`&&e.trim().length>0).join(` | `),HK=()=>{let e=Mr(e=>{if(!e.activeProjectId)return null;let t=e.projects.find(t=>t.id===e.activeProjectId);return t&&BK(t.path)||null}),[t,n]=Z.useState(null);Z.useEffect(()=>{if(typeof window>`u`||!y()){n(null);return}let e=!1,t=async()=>{try{if(S()){e||n(null);return}let t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,r=h();if(r&&L(r,t)){e||n(null);return}let i=(await U()).hosts.find(e=>r?L(r,P(e)):!1),a=i?.label?.trim()?ee(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(()=>VK(e,t),[e,t]);Z.useEffect(()=>{typeof document<`u`&&(document.title=r),y()&&(async()=>{try{if(typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``))return;await dr(r)}catch{return}})()},[r])},UK=e=>{let t=[];return e.hideGit||t.push(`git`),t.push(`files`),e.showBrowser&&t.push(`browser`),t},WK=()=>{let e=Wa.getState().currentSessionId;if(!e)return``;let t=it().find(t=>t.id===e);return typeof t?.directory==`string`?t.directory:``},GK=async(e,t=6e3)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t),i=Date.now();try{let t=await g(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)}},KK=e=>{if(!e||!Number.isFinite(e))return`(n/a)`;try{return new Date(e).toISOString()}catch{return`(invalid)`}},qK=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},JK=e=>!!e&&typeof e==`object`&&!Array.isArray(e),YK=(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,XK=(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=WK(),r=q.getState().eventStreamStatus,i=typeof window<`u`?window.location.origin:``,a=l(),o=a.health(),s=a.api(`/api/`),c=await(async()=>{if(!o)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),5e3);try{let t=await g(o,{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(!s)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),7e3);try{let t=await g(a.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(!s)return null;let r=new URL(e.replace(/^\/+/,``),s);return t&&n&&r.searchParams.set(`location[directory]`,n),r.toString()},f=s?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 GK(t,typeof e.timeoutMs==`number`?e.timeoutMs:void 0);return{label:e.label,url:t,result:n}})):[],p=[];p.push(`Time: ${e.toISOString()}`),p.push(`Yuri version: 0.2.38-beta.4`),p.push(`Runtime: ${i||`(unknown)`} (api=${s||`(unknown)`})`),p.push(`OpenCode SDK base: ${Kt.getBaseUrl()}`),p.push(`Event stream: ${r}`),p.push(`Directory: ${n||`(none)`}`),p.push(`Platform: ${t}`);let m=qK(c?.openCodePort);if(p.push(`OpenCode runtime port: ${m??`(unknown)`}`),typeof c?.openCodeRunning==`boolean`&&p.push(`OpenCode runtime running: ${c.openCodeRunning?`yes`:`no`}`),typeof c?.openCodeSecureConnection==`boolean`&&p.push(`Secure OpenCode connection: ${c.openCodeSecureConnection?`true`:`false`}`),typeof c?.openCodeAuthSource==`string`&&c.openCodeAuthSource.trim()&&p.push(`OpenCode auth source: ${c.openCodeAuthSource}`),typeof c?.openCodeServeVersion==`string`&&c.openCodeServeVersion.trim()&&p.push(`OpenCode serve version: ${c.openCodeServeVersion}`),typeof c?.openCodeCliVersion==`string`&&c.openCodeCliVersion.trim()&&p.push(`OpenCode CLI version: ${c.openCodeCliVersion}`),JK(c?.runtimeContract)){let e=c.runtimeContract,t=typeof e.phase==`string`?e.phase:`(unknown)`,n=e.executionAllowed===!0?`allowed`:`limited`,r=e.protocolCompatible===!0?`compatible`:`incompatible`;p.push(`OpenCode runtime contract: phase=${t} protocol=${r} execution=${n}`),Array.isArray(e.reasons)&&e.reasons.length>0&&p.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&&p.push(`macOS major: ${e}`)}if(/Mac OS X|Macintosh/.test(t)){p.push(``),p.push(`OpenCode CLI resolution:`);let e=JK(c?.lastOpenCodeLaunchDiagnostics)?c.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:c&&typeof c.opencodeBinaryResolved==`string`?c.opencodeBinaryResolved:``,a=n&&typeof n.resolvedDir==`string`?n.resolvedDir:``,o=n&&typeof n.source==`string`?n.source:c&&typeof c.opencodeBinarySource==`string`?c.opencodeBinarySource:``,s=n&&typeof n.launchBinary==`string`?n.launchBinary:c&&typeof c.opencodeLaunchBinary==`string`?c.opencodeLaunchBinary:``,l=n&&typeof n.launchWrapperType==`string`?n.launchWrapperType:c&&typeof c.opencodeLaunchWrapperType==`string`?c.opencodeLaunchWrapperType:``,d=n&&Array.isArray(n.launchArgs)?n.launchArgs.filter(e=>typeof e==`string`):c&&Array.isArray(c.opencodeLaunchArgs)?c.opencodeLaunchArgs.filter(e=>typeof e==`string`):[],f=n&&typeof n.node==`string`?n.node:c&&typeof c.nodeBinaryResolved==`string`?c.nodeBinaryResolved:``,m=n&&typeof n.bun==`string`?n.bun:c&&typeof c.bunBinaryResolved==`string`?c.bunBinaryResolved:``,h=n&&typeof n.detectedNow==`string`?n.detectedNow:``,g=n&&typeof n.detectedSourceNow==`string`?n.detectedSourceNow:``;if(r!==null&&p.push(`- configured: ${r.trim().length===0?`(cleared)`:r}`),i){let e=a||(i.includes(`/`)?i.split(`/`).slice(0,-1).join(`/`)||`/`:``);p.push(`- opencode: ${i}${e?` (dir=${e})`:``}`)}else p.push(`- opencode: (n/a)`);p.push(`- source: ${o||`(n/a)`}`),h&&(p.push(`- detected-now: ${h}`),p.push(`- detected-source: ${g||`(n/a)`}`)),e?(p.push(`- launched-at: ${YK(e.launchedAt)}`),p.push(`- launch: ${YK(e.binary)} ${t.join(` `)}`.trim()),p.push(`- cwd: ${YK(e.cwd)}`),p.push(`- wrapper: ${YK(e.wrapperType)}`),p.push(`- runtime: ${XK(YK(e.wrapperType,``),f,m)}`),p.push(`- PATH entries: ${YK(e.pathEntryCount,`(unknown)`)}`),p.push(`- shell env: ${YK(e.hasShellEnv,`(unknown)`)} (${YK(e.shellEnvKeysCount,`?`)} keys)`)):(p.push(`- launch-binary: ${s||`(n/a)`}`),p.push(`- launch-wrapper: ${l||`(n/a)`}`),p.push(`- launch-args: ${d.length?d.join(` `):`(none)`}`),p.push(`- runtime: ${XK(l||``,f,m)}`)),!n&&u.error&&p.push(`- resolution-endpoint: ${u.error}`)}if(p.push(``),f.length){p.push(`OpenCode API probes:`);for(let e of f){if(!e.result){p.push(`- ${e.label}: (no url)`);continue}let{ok:t,status:n,elapsedMs:r,summary:i}=e.result,a=t?``:` url=${e.url}`;p.push(`- ${e.label}: ${t?`ok`:`fail`} status=${n} time=${r}ms ${i}${a}`)}}else p.push(`OpenCode API probes: (skipped)`);return p.push(``),p.push(`Generated: ${KK(Date.now())}`),p.join(`
|
|
6612
|
-
`)},QK=async()=>{let e=await ZK(),t=q.getState();t.setOpenCodeStatusText(e),t.setOpenCodeStatusDialogOpen(!0)},$K=(e,t)=>e===t?!0:!e||!t?!1:e.scope===t.scope&&e.sessionId===t.sessionId&&e.projectId===t.projectId,eq=e=>e?`${e.scope}:${e.projectId??``}:${e.sessionId}`:null,tq=e=>({scope:`project`,sessionId:e,projectId:null}),nq=G()(e=>({focus:null,setFocus:t=>e(e=>$K(e.focus,t)?e:{focus:t})})),rq=null,iq=0,aq=(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},oq=e=>{let t=++iq;return rq={pinned:aq(`pinned`,e.pinned),project:aq(`project`,e.project)},()=>{iq===t&&(rq=null)}},sq=()=>rq,cq=e=>!!e.parentID,lq=(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&&cq(r);){let e=r.parentID;if(!e)break;let t=n.get(e);if(!t)return e;r=t}return r?.id??e},uq=()=>{let e=Ba.getState().activeSessions;if(e.length>0)return e;let t=Ue();return t.length>0?t:it()},dq=(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)},fq=e=>[...e.pinned,...e.project],pq=(e,t,n,r)=>{if(e.length===0)return null;let i=dq(e,n,r);return i<0?t>0?e[0]??null:e[e.length-1]??null:e[(i+t+e.length)%e.length]??null},mq=(e,t,n=nq.getState().focus)=>{let r=lq(t,uq()),i=n?.sessionId===t?n:null,a=sq();return a?pq(fq(a),e,r,i):null},hq=(e,t,n=e=>{Wa.getState().setCurrentSession(e.sessionId,e.directory)})=>{let r=mq(e,t);return r?(nq.getState().setFocus({scope:r.scope,sessionId:r.sessionId,projectId:r.projectId}),n(r),r):null},gq=.5,_q=.1,vq=`yuri.webviewZoomFactor`,yq=e=>Number.isFinite(e)?Math.min(3,Math.max(gq,Math.round(e*100)/100)):1,bq=()=>{if(typeof window>`u`)return 1;try{let e=window.localStorage.getItem(vq);return e?yq(Number.parseFloat(e)):1}catch{return 1}},xq=e=>{if(!(typeof window>`u`))try{window.localStorage.setItem(vq,String(e))}catch{}},Sq=e=>{let t=yq(e);return typeof document<`u`&&(document.documentElement.style.zoom=t===1?``:String(t)),xq(t),t},Cq=()=>{if(typeof document>`u`)return 1;let e=document.documentElement.style.zoom;if(!e)return bq();let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?yq(t):bq()},wq=()=>{if(C())return;let e=bq();e!==1&&Sq(e)},Tq=async()=>{if(C())try{let e=await x(`desktop_zoom_in`);if(typeof e==`number`&&Number.isFinite(e))return yq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_in failed, using CSS zoom`,e)}return Sq(Cq()+_q)},Eq=async()=>{if(C())try{let e=await x(`desktop_zoom_out`);if(typeof e==`number`&&Number.isFinite(e))return yq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_out failed, using CSS zoom`,e)}return Sq(Cq()-_q)},Dq=async()=>{if(C())try{let e=await x(`desktop_zoom_reset`);if(typeof e==`number`&&Number.isFinite(e))return yq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_reset failed, using CSS zoom`,e)}return Sq(1)},Oq=9,kq=null,Aq=0,jq=({pinnedTargets:e,projectTargets:t})=>[...e,...t].slice(0,Oq),Mq=(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},Nq=e=>{let t=++Aq;return kq={targets:e.targets.slice(0,Oq),activate:e.activate},()=>{Aq===t&&(kq=null)}},Pq=e=>{if(!Number.isInteger(e)||e<1||e>Oq)return!1;let t=kq,n=t?.targets[e-1];return!t||!n?!1:(t.activate(n),!0)},Fq=e=>{let t=e.trim();if(!t)return null;let n=tf.getState(),r=n.createTab(t);return!r||r===`tab-invalid`?null:(n.setActiveTab(t,r),r)},Iq=e=>{let t=e.trim();if(!t)return null;let n=q.getState();return!n.isBottomTerminalOpen&&n.activeMainTab!==`terminal`&&n.setBottomTerminalOpen(!0),Fq(t)},Lq=(e,t)=>{let n=e.trim();if(!n)return!1;let r=tf.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)},Rq=e=>{let t=e.trim();if(!t)return{closed:!1,wasLastTab:!1};let n=tf.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}},zq=()=>typeof window>`u`||window.parent===window||!Ys(window.location.search)?!1:(window.parent.postMessage({type:Xs},window.location.origin),!0),Bq=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=q.getState();if(e)return!1;let n=Pu();return n&&t(n)?!0:C()?(x(`desktop_close_current_window`).catch(e=>{console.warn(`[keyboard-shortcuts] failed to close current window`,e)}),!0):!1},Vq=({sessionId:e,surfaceKind:t,wiringCanAbort:n,primaryCanAbort:r,pendingSend:i=!1})=>e?i||n?!0:t!==`secondary`&&r:!1,Hq=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)}},Uq=()=>{let e=(0,Q.c)(69),{t}=fr(),n=Wa(Wq),r=Wa(Gq),i=Wa(Kq),a=Wa(qq),o=hi,s=q(Jq),c=q(Yq),l=q(Xq),u=q(Zq),d=q(Qq),f=q($q),p=q(eJ),m=q(tJ),h=q(nJ),g=q(rJ),_=q(iJ),v=q(aJ),y=q(oJ),b=q(sJ),S=q(cJ),w=q(lJ),T=q(uJ),D=q(dJ),O=q(fJ),k=At(pJ),A=Mr(mJ),{themeMode:j,setThemeMode:M}=Io(),{working:N}=lz(),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),Xm.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=Xm.getState().arm(Ym);I.current=setTimeout(()=>{let{expiresAt:e}=Xm.getState();e&&Date.now()>=e&&Xm.getState().clear(),I.current=null},Math.max(0,e-Date.now()))},e[6]=ee):ee=e[6];let te=ee,G;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]!==b||e[16]!==m||e[17]!==y||e[18]!==T||e[19]!==d||e[20]!==f||e[21]!==g||e[22]!==v||e[23]!==M||e[24]!==S||e[25]!==O||e[26]!==t||e[27]!==p||e[28]!==s||e[29]!==u||e[30]!==D||e[31]!==c||e[32]!==w||e[33]!==l||e[34]!==N?(G=()=>{let e=e=>Ns(e,O),i=e=>ks(e,O),a=hJ,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=_J,B=yJ,V=bJ,U=async()=>{let e=QE(),n=e?iD(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;no.error(n instanceof Error?n.message:t(`chat.chatInput.toast.compactFailed`))}return}let r=Wa.getState().currentSessionId;if(!r)return;let{currentProviderId:i,currentModelId:a}=ei.getState();await Hq({sessionId:r,currentProviderId:i,currentModelId:a,waitForConnectionOrThrow:da,getAuthoritativeDirectoryForSession:Wa.getState().getAuthoritativeDirectoryForSession,summarizeSession:xJ,onCompactFailed:e=>{no.error(e instanceof Error?e.message:t(`chat.chatInput.toast.compactFailed`))}})},ee=t=>{let r=Xm.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&&rs(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}=q.getState(),c=ZE(a)&&!V();if(r===`m`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),window.requestAnimationFrame(()=>{y(!o,{instant:!0})});return}if(r===`a`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),b(!s,{instant:!0});return}if(r===`n`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();let r=QE(),i=r?iD(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||!rs(t,i)||V())return;let{activeMainTab:o}=q.getState();ZE(o)&&(t.preventDefault(),t.stopPropagation(),te())},G=()=>Xm.getState().pending||L.current,ne=e=>{G()&&e.preventDefault()},re=e=>{G()&&(e.preventDefault(),e.stopPropagation())},ie=t=>{if(a(t.target)){if(!E()&&rs(t,e(`new_terminal_tab`))){let e=Pu();if(!e||!Fq(e))return;t.preventDefault(),t.stopPropagation();return}if(!E()&&rs(t,e(`previous_terminal_tab`))){let e=Pu();if(!e||!Lq(e,-1))return;t.preventDefault(),t.stopPropagation();return}if(!E()&&rs(t,e(`next_terminal_tab`))){let e=Pu();if(!e||!Lq(e,1))return;t.preventDefault(),t.stopPropagation();return}if(rs(t,e(`close_context_panel_tab`))){let e=Pu();if(!e)return;let{closed:n,wasLastTab:r}=Rq(e);if(!n)return;if(t.preventDefault(),t.stopPropagation(),r){let e=q.getState();e.setBottomTerminalOpen(!1),e.activeMainTab===`terminal`&&e.setActiveMainTab(`chat`)}return}if(rs(t,e(`toggle_terminal`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(rs(t,e(`toggle_bottom_panel`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(rs(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=q.getState();if(e)return;t.preventDefault(),t.stopPropagation(),m(!n);return}}},ae=SJ,oe=t=>{if(t.defaultPrevented||t.isComposing||t.keyCode===229)return;if(rs(t,e(`close_context_panel_tab`))){(zq()||Bq())&&(t.preventDefault(),t.stopPropagation());return}if(a(t.target))return;let r=CJ;if(r(t.target)&&t.ctrlKey&&!t.metaKey&&!t.shiftKey&&!t.altKey&&t.key.toLowerCase()===`t`){t.preventDefault(),ae();return}if(rs(t,e(`open_command_palette`))){t.preventDefault(),s();return}if(rs(t,e(`open_timeline_dialog`))){t.preventDefault(),S(!0);return}if(rs(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}=q.getState();if(!n||h||E()||e!==`chat`||r||i||a||o||s||c||l||u)return;t.preventDefault(),w();return}if(rs(t,e(`open_status`))){t.preventDefault(),QK();return}if(rs(t,e(`open_help`))){t.preventDefault(),c();return}if(C()&&rs(t,e(`new_mini_chat`))){t.preventDefault(),x(`desktop_open_draft_mini_chat_window`,{directory:k||A?.path||``,projectId:A?.id??null}).catch(wJ);return}let o=rs(t,e(`new_chat`)),b=rs(t,e(`new_chat_worktree`));if(o||b){if(t.preventDefault(),_(`chat`),g(!1),!E()&&b){qx();return}n();return}if(rs(t,e(`cycle_theme`))){if(t.preventDefault(),kp()!==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(Es(t,`in`,e(`zoom_in`))){t.preventDefault(),Tq();return}if(Es(t,`out`,e(`zoom_out`))){t.preventDefault(),Eq();return}if(rs(t,e(`zoom_reset`))){t.preventDefault(),Dq();return}if(rs(t,e(`open_settings`))){t.preventDefault();let{isSettingsDialogOpen:e}=q.getState();v(!e);return}if(rs(t,e(`toggle_sidebar`))){t.preventDefault();let{isMobile:e,isSessionSwitcherOpen:n}=q.getState();e?g(!n):l();return}if(rs(t,e(`focus_input`))){t.preventDefault(),document.querySelector(`textarea[data-chat-input="true"]`)?.focus();return}let T=e(`cycle_agent`),O=T&&!T.includes(`shift`)?As(`shift+${T}`):``,j=O&&rs(t,O)?-1:+!!rs(t,T);if(j!==0){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s}=q.getState();if(e||n||i||a||o||!ZE(s)||!r(t.target))return;let c=QE(),l=c?iD(c):null;if(l){t.preventDefault(),l.shortcut(`cycle`,j);return}let u=ei.getState(),d=Qr(u.getVisibleAgents(),u.currentAgentName,j);if(!d)return;t.preventDefault(),u.setAgent(d),q.getState().addRecentAgent(d);let f=Wa.getState().currentSessionId;f&&Oi.getState().saveSessionAgentSelection(f,d);return}if(i(`toggle_right_sidebar`).some(e=>rs(t,e))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault();let n=Pu();n&&u(n);return}if(rs(t,e(`open_right_sidebar_git`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault();let n=Pu();n&&q.getState().openContextPanel(n),d(!0),f(`git`);return}if(rs(t,e(`open_right_sidebar_files`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault();let n=Pu();n&&q.getState().openContextPanel(n),d(!0),f(`files`);return}if(rs(t,e(`cycle_right_sidebar_tab`))){let{isMobile:e,rightSidebarTab:n}=q.getState();if(e)return;let r=UK({hideGit:q.getState().activeMainTab===`git`,showBrowser:ws(Ms())}),i=r[(r.indexOf(n)+1)%r.length];t.preventDefault();let a=Pu();a&&q.getState().openContextPanel(a),d(!0),f(i);return}let N=e=>hq(e,Wa.getState().currentSessionId,e=>{_(`chat`),g(!1),Wa.getState().setCurrentSession(e.sessionId,e.directory)});if(i(`previous_session`).some(e=>rs(t,e))){t.preventDefault(),N(-1);return}if(i(`next_session`).some(e=>rs(t,e))){t.preventDefault(),N(1);return}for(let n=1;n<=9;n+=1)if(rs(t,e(`switch_tab_${n}`))){Pq(n)&&t.preventDefault();return}if(rs(t,e(`toggle_terminal`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),p();return}if(rs(t,e(`open_new_terminal`))){let{isMobile:e}=q.getState();if(e||E())return;let n=Pu();if(!n||!Iq(n))return;t.preventDefault();return}if(rs(t,e(`toggle_bottom_panel`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),p();return}if(rs(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=q.getState();if(e)return;t.preventDefault(),m(!n);return}if(rs(t,e(`open_model_selector`))){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isAboutDialogOpen:a,activeMainTab:o,isModelSelectorOpen:s}=q.getState();if(e)return;let c=n||r||i||a,l=ZE(o);if(c||!l)return;t.preventDefault(),y(!s,{instant:!0});return}if(rs(t,e(`cycle_thinking_variant`))){ae()&&t.preventDefault();return}if(rs(t,e(`cycle_favorite_model_forward`))||rs(t,e(`cycle_favorite_model_backward`))){let{isSettingsDialogOpen:n,isCommandPaletteOpen:r,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s,favoriteModels:c,addRecentModel:l}=q.getState();if(n)return;let u=r||i||a||o,d=ZE(s);if(u||!d||c.length===0)return;t.preventDefault();let f=c.length,p=rs(t,e(`cycle_favorite_model_forward`))?1:-1,m=QE();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=ei.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}=ei.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(rs(t,e(`expand_input`))){if(h)return;t.preventDefault(),D();return}if(rs(t,e(`toggle_dictation`))){let{activeMainTab:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isSettingsDialogOpen:a}=q.getState();if(!ZE(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,workStatusOverlayOpen:g}=q.getState();if(n||a||s){H();return}if(g){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),q.getState().setWorkStatusOverlayOpen(!1),H();return}if(h){e.preventDefault(),T(!1),H();return}if(c){e.preventDefault(),v(!1),H();return}if(i){H();return}if(l||u||d||f||p||m){H();return}let _=QE(),y=_?iD(_):null,b=_?.sessionID??Wa.getState().currentSessionId,x=!!(b&&Wa.getState().pendingSendMessageIDs.get(b));if(!Vq({sessionId:b,surfaceKind:_?.kind,wiringCanAbort:y?.canAbort,primaryCanAbort:N.canAbort,pendingSend:x})){H();return}e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();let S=Date.now(),C=P.current;if(C&&S<C){H(),y?y.abort():(b&&xu(b),o(b??``));return}let w=_?.kind===`secondary`?S+3e3:r(3e3)??S+3e3;P.current=w,F.current&&clearTimeout(F.current);let E=Math.max(w-S,0);F.current=setTimeout(()=>{P.current&&Date.now()>=P.current&&H()},E||0)};return window.addEventListener(`keydown`,ee,!0),window.addEventListener(`beforeinput`,ne,!0),window.addEventListener(`compositionstart`,re,!0),window.addEventListener(`compositionupdate`,re,!0),window.addEventListener(`compositionend`,re,!0),window.addEventListener(`keydown`,ie,!0),window.addEventListener(`keydown`,se,!0),window.addEventListener(`keydown`,oe),()=>{window.removeEventListener(`keydown`,ee,!0),window.removeEventListener(`beforeinput`,ne,!0),window.removeEventListener(`compositionstart`,re,!0),window.removeEventListener(`compositionupdate`,re,!0),window.removeEventListener(`compositionend`,re,!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]=b,e[16]=m,e[17]=y,e[18]=T,e[19]=d,e[20]=f,e[21]=g,e[22]=v,e[23]=M,e[24]=S,e[25]=O,e[26]=t,e[27]=p,e[28]=s,e[29]=u,e[30]=D,e[31]=c,e[32]=w,e[33]=l,e[34]=N,e[35]=G):G=e[35];let ne=A?.id,re=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]!==b||e[44]!==m||e[45]!==y||e[46]!==T||e[47]!==d||e[48]!==f||e[49]!==g||e[50]!==v||e[51]!==M||e[52]!==S||e[53]!==O||e[54]!==t||e[55]!==ne||e[56]!==re||e[57]!==p||e[58]!==s||e[59]!==u||e[60]!==D||e[61]!==c||e[62]!==w||e[63]!==l||e[64]!==N?(ie=[n,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,S,w,T,D,M,N,r,H,te,W,a,k,ne,re,O,t],e[36]=r,e[37]=k,e[38]=a,e[39]=h,e[40]=n,e[41]=H,e[42]=_,e[43]=b,e[44]=m,e[45]=y,e[46]=T,e[47]=d,e[48]=f,e[49]=g,e[50]=v,e[51]=M,e[52]=S,e[53]=O,e[54]=t,e[55]=ne,e[56]=re,e[57]=p,e[58]=s,e[59]=u,e[60]=D,e[61]=c,e[62]=w,e[63]=l,e[64]=N,e[65]=ie):ie=e[65],Z.useEffect(G,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 Wq(e){return e.openNewSessionDraft}function Gq(e){return e.armAbortPrompt}function Kq(e){return e.clearAbortPrompt}function qq(e){return e.currentSessionId}function Jq(e){return e.toggleCommandPalette}function Yq(e){return e.toggleHelpDialog}function Xq(e){return e.toggleSidebar}function Zq(e){return e.toggleContextPanel}function Qq(e){return e.setRightSidebarOpen}function $q(e){return e.setRightSidebarTab}function eJ(e){return e.toggleBottomTerminal}function tJ(e){return e.setBottomTerminalExpanded}function nJ(e){return e.isMobile}function rJ(e){return e.setSessionSwitcherOpen}function iJ(e){return e.setActiveMainTab}function aJ(e){return e.setSettingsDialogOpen}function oJ(e){return e.setModelSelectorOpen}function sJ(e){return e.setAgentSelectorOpen}function cJ(e){return e.setTimelineDialogOpen}function lJ(e){return e.togglePromptNavigatorPanel}function uJ(e){return e.setPromptNavigatorPanelOpen}function dJ(e){return e.toggleExpandedInput}function fJ(e){return e.shortcutOverrides}function pJ(e){return e.currentDirectory}function mJ(e){return e.getActiveProject()}function hJ(e){return e instanceof Element&&!!(e.closest(`[data-terminal-view="true"]`)||e.closest(`.terminal-viewport-container`)||e.getAttribute(`data-terminal-hidden-input`)===`true`)}function gJ(e){return e.getClientRects().length>0}function _J(){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(gJ)}function vJ(){document.querySelector(`textarea[data-chat-input="true"]`)?.focus({preventScroll:!0})}function yJ(){window.requestAnimationFrame(vJ)}function bJ(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i}=q.getState();return e||t||n||r||i}function xJ(e,t,n,r){return Kt.summarizeSession(e,t,n,r)}function SJ(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i,activeMainTab:a}=q.getState();if(e||t||n||r||i||!ZE(a))return!1;let o=QE();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=ei.getState();if(s.getCurrentModelVariants().length===0)return!1;s.cycleCurrentVariant();let c=ei.getState().currentVariant,l=Wa.getState().currentSessionId,u=ei.getState().currentAgentName,d=ei.getState().currentProviderId,f=ei.getState().currentModelId;return l&&u&&d&&f&&Oi.getState().saveAgentModelVariantForSession(l,u,d,f,c),u&&d&&f&&ei.getState().saveAgentModelSelection(u,d,f,c),!0}function CJ(e){return e instanceof HTMLTextAreaElement&&e.getAttribute(`data-chat-input`)===`true`}function wJ(e){console.warn(`[keyboard-shortcuts] failed to open draft mini chat window`,e)}var TJ=3,EJ=(e,t)=>{if(typeof e!=`string`)return t;let n=e.trim().replace(/\s+/g,` `);return n?n.slice(0,48):t},DJ=(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:EJ(e.title,`Session ${r.length+1}`)}),r.length>=TJ))break}return r},OJ=()=>{let e=(0,Q.c)(9),t=yo(),n=Wa(kJ),r;e[0]!==n||e[1]!==t?(r=DJ(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`||!_())){try{i.length===0?localStorage.removeItem(Ps):localStorage.setItem(Ps,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 kJ(e){return e.currentSessionId}var AJ=e=>Number.isFinite(e)?`${Math.max(0,Math.round(e))}px`:`0px`,jJ=(e,t,n,r)=>{e.style.setProperty(`--yuri-wco-left-inset`,AJ(t)),e.style.setProperty(`--yuri-wco-right-inset`,AJ(n)),e.style.setProperty(`--yuri-wco-titlebar-height`,AJ(r))},MJ=()=>{let e=(0,Q.c)(1),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],Z.useEffect(NJ,t)};function NJ(){if(typeof window>`u`||!_())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){jJ(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));jJ(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),jJ(e,0,0,0)}}var PJ=3e4,FJ=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,IJ=e=>e instanceof tu?e.status===501?`unsupported`:e.status>=400&&e.status<500&&e.status!==408&&e.status!==429&&e.code!==`revision_conflict`?`permanent`:`retry`:`retry`,LJ=(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})}),RJ=(e,t)=>e.then(e=>{if(t?.aborted)throw new DOMException(`Aborted`,`AbortError`);return e}),zJ={fetchSnapshot:e=>RJ(mu(Fn),e),refreshSnapshot:e=>RJ(eu(Fn),e),fetchOrder:Zl,setOrder:Ql,waitInvalidation:$l,captureRuntime:()=>({transportIdentity:u(),generation:f()}),isCurrent:e=>e.transportIdentity===u()&&e.generation===f(),sleep:LJ,createRequestID:()=>typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`worktree-order-${Date.now()}-${Math.random().toString(36).slice(2)}`},BJ=new Map,VJ=()=>{for(let e of BJ.values())e.controller.abort();BJ.clear()},HJ=(e,t,n,r=zJ)=>{BJ.get(e)?.controller.abort();let i={projectDirectory:FJ(t),orderedPaths:[...n],capture:r.captureRuntime(),controller:new AbortController,backoffMs:500,running:!1};BJ.set(e,i),UJ(e,r)},UJ=async(e,t=zJ)=>{let n=BJ.get(e);if(!(!n||n.running)){n.running=!0;try{for(;;){let n=BJ.get(e);if(!n||!t.isCurrent(n.capture)||n.controller.signal.aborted)return;let r=ho.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)||BJ.get(e)!==n)return;let a=i.worktreeOrder??{projectDirectory:n.projectDirectory,orderedPaths:n.orderedPaths,revision:i.revision};ho.getState().setServerRevision(e,a.revision),ho.getState().resolvePendingWorktreeOrder(e,a.revision),BJ.delete(e);return}catch(r){if(n.controller.signal.aborted||!t.isCurrent(n.capture)||BJ.get(e)!==n)return;if(r instanceof tu&&r.code===`revision_conflict`)try{let r=await t.fetchOrder(n.projectDirectory,n.controller.signal);if(BJ.get(e)!==n||!t.isCurrent(n.capture))return;ho.getState().applyServerWorktreeOrder(e,r.orderedPaths,r.revision),n.expectedRevision=void 0,n.requestID=void 0,n.backoffMs=500;continue}catch(e){if(IJ(e)!==`retry`)return}else if(IJ(r)!==`retry`)return;if(await t.sleep(n.backoffMs,n.controller.signal).catch(()=>{}),n.backoffMs=Math.min(n.backoffMs*2,PJ),n.controller.signal.aborted)return}}}finally{BJ.get(e)===n&&(!t.isCurrent(n.capture)||n.controller.signal.aborted)&&BJ.delete(e),BJ.get(e)===n&&(n.running=!1)}}},WJ=(e,t,n,r)=>{let i=new Map(t.map(e=>[FJ(e.path),e.id]));for(let t of e){let e=i.get(FJ(t.projectDirectory));e&&r.isCurrent(n)&&ho.getState().applyServerWorktreeOrder(e,t.orderedPaths,t.revision)}},GJ=(e,t=zJ)=>{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();WJ(r.worktreeOrders,o,a,t);let s=new Set(r.worktreeOrders.map(e=>FJ(e.projectDirectory)));for(let e of o){let n=ho.getState(),r=n.orderByProject[e.id];n.pendingProjectIDs[e.id]?HJ(e.id,e.path,r??[],t):r?.length&&!s.has(FJ(e.path))&&(n.markPendingWorktreeOrder(e.id),HJ(e.id,e.path,r,t))}break}catch(e){if(IJ(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,PJ)}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,WJ(s.worktreeOrders,e(),a,t),r=500}catch(e){if(IJ(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,PJ)}})()},stop:r}},KJ=()=>{let e=(0,Q.c)(2),t=Mr(JJ),n;e[0]===t?n=e[1]:(n=[t],e[0]=t,e[1]=n),Z.useEffect(ZJ,n)};function qJ(e){return[e.id,FJ(e.path)]}function JJ(e){return JSON.stringify(e.projects.map(qJ))}function YJ(e,t,n){return HJ(e,t,n)}function XJ(){return Mr.getState().projects}function ZJ(){let e=u();ho.getState().activateWorktreeOrderRuntime(e);let t=ra(YJ),n=GJ(XJ);n.start();let r=c(e=>{p(e)&&(VJ(),ho.getState().activateWorktreeOrderRuntime(u()),n.start())});return()=>{t(),r(),n.stop(),VJ()}}var QJ=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,$J=e=>{let t=!1,n=0,r=0,i=0,a=!1,o=new Set,s=new Map,c=new Map,l=new Map,u=new Map,d=new Set,f=new Set,p=new Map,m=new Set,h=new Set,g=new Set,_=``,v=[],y=(n,i=150,a=!1,c={})=>{let d=QJ(n.path);if(a&&(o.has(d)||s.has(d)||u.has(d)))return;let f=(l.get(d)??0)+1;l.set(d,f);let p=u.get(d);p&&e.clearTimer(p.timer);let m=r,h=e.setTimer(()=>{!t||m!==r||(u.delete(d),s.set(d,{project:n,refreshBatch:c,version:f}),b(m))},i);u.set(d,{timer:h,epoch:m})},b=(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,{project:u,refreshBatch:d,version:f}]=n;s.delete(a),i+=1,o.add(a);let h=e.generation(),_=r,v=()=>t&&_===r&&h===e.generation()&&l.get(a)===f;e.refresh(u,{isCurrent:v,refreshBatch:d}).then(t=>{if(v()){t.repositoryDirectory&&c.set(a,QJ(t.repositoryDirectory)),g.add(a);for(let n of t.addedDirectories){let t=QJ(n);(!e.needsSessionSync||e.needsSessionSync(t))&&m.add(t)}if(e.needsSessionSync)for(let n of t.worktrees){let t=QJ(n.path);e.needsSessionSync(t)&&m.add(t)}x(_,h),S()}}).then(()=>{v()&&p.delete(a)}).catch(()=>{if(!v())return;let e=(p.get(a)??0)+1;p.set(a,e),t&&_===r&&y(u,[1e3,2e3,5e3,15e3,3e4][Math.min(e-1,4)])}).finally(()=>{_===r&&(--i,o.delete(a),b(_))})}},x=(n,i)=>{if(m.size===0)return;let a=[...m];m.clear(),e.syncAdded(a).catch(()=>{if(t&&n===r&&i===e.generation()){for(let e of a)m.add(e);let o=e.setTimer(()=>{d.delete(o),t&&n===r&&x(n,i)},1e3);d.add(o)}})},S=()=>{if(g.size!==e.getProjects().length)return;let t=e.getCatalog();for(let e of h){let n=e.slice(e.indexOf(`:`)+1);[...t.entries()].some(([e,t])=>QJ(e)===n||t.some(e=>QJ(e.path)===n))||f.add(e)}},C=()=>{g.clear();let t={};for(let n of e.getProjects())y(n,0,!0,t)},w=()=>{let t=e.getCatalog(),r=e.getProjects(),i=new Set;for(let t of e.getActiveDirectories())t.trim()&&i.add(QJ(t));for(let e of[...h]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||h.delete(e)}for(let e of[...f]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||f.delete(e)}for(let e of i)if(!r.find(n=>{let r=QJ(n.path),i=t.get(r)?.some(t=>QJ(t.path)===e);return e===r||i})){let t=`${n}:${e}`;!f.has(t)&&!h.has(t)&&(h.add(t),C())}},T=()=>{r+=1,f.clear(),h.clear(),p.clear(),m.clear(),g.clear();for(let t of u.values())e.clearTimer(t.timer);u.clear();for(let t of d)e.clearTimer(t);d.clear(),s.clear(),o.clear(),i=0,c.clear(),l.clear()};return{start:()=>{t||e.isVSCode()||(t=!0,a=!1,v.push(e.subscribeEvents(i=>{if(i.type===`event-stream-ready`){if(!a){a=!0,C();return}n+=1,T(),C()}if(i.type===`worktree-topology-changed`&&i.projectDirectory){let n=QJ(i.projectDirectory),a={},o=c.get(n),s=e.getCatalog();for(let t of e.getProjects()){let e=QJ(t.path),r=s.get(e)?.some(t=>QJ(t.worktreeRoot??t.path)===n||t.relativePath&&e===`${n}/${t.relativePath}`),i=o&&c.has(e)?c.get(e)===o:r;(e===n||i)&&y(t,150,!1,a)}if(e.resolveRepository){let i=r,s=e.generation();(async()=>{let l=o??QJ(await e.resolveRepository(n));for(let n of e.getProjects()){let u=QJ(n.path);if(!(o&&c.has(u)))try{let o=c.get(u)??QJ(await e.resolveRepository(u));if(!t||i!==r||s!==e.generation())return;c.set(u,o),o===l&&y(n,150,!1,a)}catch{t&&i===r&&s===e.generation()&&y(n)}}})().catch(()=>{t&&i===r&&s===e.generation()&&C()})}}})),_=e.getProjects().map(e=>`${e.id}\u0000${QJ(e.path)}`).sort().join(`
|
|
6613
|
-
`),v.push(e.subscribeProjects(()=>{let t=e.getProjects().map(e=>`${e.id}\u0000${
|
|
6614
|
-
`);t!==_&&(_=t,T(),C(),w())})),v.push(e.subscribeCatalog(w)),v.push(e.subscribeSessions(w)),v.push(e.subscribeRuntime(e=>{e&&(a=!1,n+=1,T(),C())})),C(),w())},stop:()=>{t=!1,T();for(let{timer:t}of u.values())e.clearTimer(t);for(u.clear(),s.clear(),i=0;v.length;)v.pop()?.()},reconcileAll:C}},
|
|
6607
|
+
`)}return ct&&ct.trim().length>0?ct:OF(Re)},[ct,Re,G]),ut=lt.length>0,dt=Z.useCallback(async()=>(await Ea(lt)).ok?(G&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[G,lt]),ft=J(async()=>{if(!(!ae||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(ae,e.info.id,{directory:g.directory??void 0})}catch(e){g.onRevertMessage&&$n.error(f(`chat.revert.toast.failed`),{id:`session-revert-error`,description:e&&typeof e==`object`&&`message`in e?String(e.message):String(e)})}finally{B.current=null,z(null)}}}),pt=J(()=>{if(!ae||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(ae,e.info.id,t).catch(()=>{})}),mt=J(()=>{ae&&O(ae)}),ht=Z.useCallback(async()=>{if(e.info.id,!ae||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!ae,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(ae,e.info.id)}finally{B.current=null,z(null)}}},[ae,e.info.id,T]),gt=J(t=>{let n=Ve.has(t),r=He.has(t);if(n){W(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),jR(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),kR(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),kR(e.info.id,r),r}),W(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),jR(e.info.id,r),r})}),_t=i??null,vt=Z.useRef(!1),yt=Z.useRef(!1),bt=Z.useRef(!1),xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1);Z.useEffect(()=>{yt.current=!1,bt.current=!1,xt.current=!1,St.current=!1,vt.current=!1,Ct.current=!1},[e.info.id]);let wt=Z.useCallback(()=>{G||vt.current||(vt.current=!0,r?.(`structural`))},[G,r]),Tt=q(e=>e.setImagePreviewOpen),Et=Z.useCallback(e=>{(e.image||e.mermaid||e.video)&&(te(e),Tt(!0))},[Tt]),Dt=Z.useCallback(e=>{te(t=>({...t,open:e})),Tt(e)},[Tt]),Ot=!!LR(e.info,`animationSettled`),kt=nt===`streaming`||nt===`cooldown`;kt&&(Ct.current=!0);let At=Z.useMemo(()=>!G&&Le.some(e=>e.type===`reasoning`),[G,Le]),jt=qe&&!Ot&&!kt&&!Ct.current,Mt=!G&&qe&&ze.length>0&&!Ke;Z.useEffect(()=>{if(_t?.onStreamingCandidate){if(!Mt){bt.current&&=(At&&_t?.onReasoningBlock?_t.onReasoningBlock():_t?.onReservationCancelled&&_t.onReservationCancelled(),!1);return}St.current||(St.current=!0,_t.onStreamingCandidate(),bt.current=!0)}},[_t,Mt,At]),Z.useEffect(()=>{_t?.onAnimationStart&&jt&&(xt.current||=(_t.onAnimationStart(),!0))},[_t,jt]),Z.useEffect(()=>{if(G)return;let e=_t?.onAnimatedHeightChange;if(!e||!(jt||Mt))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[jt,G,_t,Mt]);let Nt=Z.useMemo(()=>G?!0:Le.some(e=>e.type===`text`||e.type===`reasoning`?Sk(e).trim().length>0:e.type===`tool`||e.type===`file`),[G,Le]),Pt=!!(a?.activityOwnerMessageId===e.info.id&&((a.activityParts?.length??0)>0||a.hasTools||a.hasReasoning)),Ft=!G&&!ne&&(Fe||!c||!!a)&&!st&&!Nt&&!Pt,It=tR(e.info,f);if(It)return(0,$.jsx)(`div`,{ref:x,className:`chat-message-column py-1.5`,id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-restart-notice":``,children:(0,$.jsx)(Ov,{presentation:It})});if(We||Ft)return null;if(ne)return(0,$.jsx)(`div`,{className:Y(`group w-full`,p?`py-2`:`py-3`),id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-compaction-status":ne.status,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(rR,{part:ne,isMobile:p})})});let Lt=!G&&rt?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,Rt=yR(e);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`w-full`,!G&&`yuri-message-hover-scope`,G?p?`pt-2`:`pt-6`:Lt,G||tt||s?`pb-0`:et?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,...IT,ref:x,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:G?Ik(Re)?(0,$.jsx)(id,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{...IT,className:Y(`relative flex`,Rt?`justify-start`:`justify-end`,p?void 0:`yuri-user-shell-hover-scope`),children:(0,$.jsxs)(`div`,{className:Y(Rt?`w-full min-w-0`:`max-w-[85%]`,ie&&!Rt?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:Rt?void 0:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:Rt?`min-w-0 text-left`:`px-3 py-1.5 shadow-none`,"data-user-message-bubble":Rt?void 0:`true`,"data-shell-result":Rt?`true`:void 0,children:(0,$.jsx)(UL,{messageId:e.info.id,parts:Re,sourceParts:le,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:gt,onShowPopup:Et,streamPhase:nt,allowAnimation:jt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ut,onCopyMessage:dt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:wt,agentMention:Ue,onEdit:!E&&_.edit?pt:void 0,onRevert:!E&&_.revert?ft:void 0,onFork:!E&&G&&_.fork?ht:void 0,editing:E,editStaged:D,onCancelEdit:D?mt:void 0,pendingMessageAction:R,errorPresentation:st,userActionsMode:re?`external-content`:`inline`,stickyUserHeaderEnabled:j&&!Rt})}),re?(0,$.jsx)(UL,{messageId:e.info.id,parts:Re,sourceParts:le,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:gt,onShowPopup:Et,streamPhase:nt,allowAnimation:jt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ut,onCopyMessage:dt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:wt,agentMention:Ue,onEdit:!E&&_.edit?pt:void 0,onRevert:!E&&_.revert?ft:void 0,onFork:!E&&G&&_.fork?ht:void 0,editing:E,editStaged:D,onCancelEdit:D?mt:void 0,pendingMessageAction:R,errorPresentation:st,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[rt&&(0,$.jsx)(EA,{isUser:G,isMobile:p,providerID:Ae,modelID:je,agentName:ke,modelName:Me,variant:ot}),!Nt&&!Pt&&!st&&c&&!Fe&&(0,$.jsxs)(`div`,{role:`status`,"aria-label":f(`common.loading`),"data-assistant-content-loading":``,className:`space-y-2 py-2`,children:[(0,$.jsx)(Kd,{className:`h-3.5 w-2/3`}),(0,$.jsx)(Kd,{className:`h-3.5 w-1/3`})]}),(0,$.jsx)(UL,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Le,sourceParts:ue,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCompletedAt:Ne??void 0,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:He,onToggleTool:gt,onShowPopup:Et,streamPhase:nt,allowAnimation:jt,onContentChange:r,shouldShowHeader:rt,hasTextContent:ut,onCopyMessage:dt,copiedMessage:I,onAuxiliaryContentComplete:wt,showReasoningTraces:A,agentMention:Ue,turnGroupingContext:a,errorPresentation:st})]})})}),ee.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(SR,{popup:ee,onOpenChange:Dt,isMobile:p})}):null]})},(e,t)=>fM({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&pM(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&pM(e.nextMessage?{info:e.nextMessage.info,parts:e.nextMessage.parts}:void 0,t.nextMessage?{info:t.nextMessage.info,parts:t.nextMessage.parts}:void 0)&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&xM(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,YL(e.message.info).isUser)),zR=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},BR=e=>{let t=e?.type;return t===`compaction`?!Ie(e):t===`text`&&zR(e).trim()===`/compact`},VR=e=>e?e.some(e=>BR(e)):!1,HR=e=>VR(e.parts),UR=e=>e?VR(e.sourceParts)||VR(e.parts):!1,WR=e=>{if(!HR(e))return e;let t=!1,n=e.parts.map(e=>e?.type!==`compaction`||Ie(e)?e:(t=!0,{type:`text`,text:`/compact`})),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},GR=e=>{let t=xk(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},KR=new WeakMap,qR=e=>{let t=KR.get(e);if(t)return t;let n=WR(GR(e)),r=n.parts,i=Ti(r),a=i===r?n:{...n,parts:i,sourceParts:r};return KR.set(e,a),a},JR={activity:`idle`,hasWorkingContext:!1,hasActiveTools:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,lifecyclePhase:null,statusText:null,isGenericStatus:!0,isWaitingForPermission:!1,canAbort:!1,compactionDeadline:null,activePartType:void 0,activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:null,turnStartedAt:void 0},YR=[],XR=`\0`,ZR=new Set([`edit`,`write`,`apply_patch`]),QR={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`,execute:`chat.assistantStatus.executing`,session_rename:`chat.assistantStatus.renamingSession`,session_move:`chat.assistantStatus.movingSession`,browser:`chat.assistantStatus.usingBrowser`},$R=[`chat.assistantStatus.working`,`chat.assistantStatus.processing`,`chat.assistantStatus.preparing`,`chat.assistantStatus.warmingUp`,`chat.assistantStatus.gearsTurning`,`chat.assistantStatus.computing`,`chat.assistantStatus.calculating`,`chat.assistantStatus.analyzing`,`chat.assistantStatus.wheelsSpinning`,`chat.assistantStatus.calibrating`,`chat.assistantStatus.synthesizing`,`chat.assistantStatus.connectingDots`,`chat.assistantStatus.inspectingLogic`,`chat.assistantStatus.weighingOptions`],ez=(e,t)=>{let n=QR[ju(e)];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},tz=e=>{let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)},nz=(e,t)=>t($R[tz(e)%$R.length]??`chat.assistantStatus.working`),rz=(e,t,n)=>{let r,i;if(!Pr(e))for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)switch(n.type){case`reasoning`:{let e=n.time??lz(n);(!e||e.end===void 0)&&!r&&(r=`reasoning`);break}case`tool`:{let e=n.state?.status;if((e===`running`||e===`pending`)&&!r){let e=ju(uz(n));ZR.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=cz(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=lz(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?n(`chat.assistantStatus.editingFile`):r===`tool`&&i?ez(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):nz(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},iz=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(XR),az=e=>{let[t,n,r=`working`,i]=e.split(XR);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},oz=e=>e.type===`reasoning`,sz=e=>e.type===`text`,cz=e=>{if(sz(e))return e.text;let t=e;if(typeof t.text==`string`)return t.text;if(typeof t.content==`string`)return t.content;if(typeof t.value==`string`)return t.value},lz=e=>(sz(e)||oz(e),e.time),uz=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function dz(e,t){let{t:n}=fr(),r=Wa(e=>e.currentSessionId),i=Wa(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Fi(e=>!!(a&&e.session_execution_recovery[a]),o??void 0),c=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),l=Wa(c),u=Na(a??``,o??void 0),d=Z.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`assistant`)return{id:t.id,index:e,finish:t.finish,error:t.error,isCompaction:t.clientRole===`compaction`,startedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,finish:void 0,error:void 0,isCompaction:!1,startedAt:void 0}},[u]),f=d.id,p=Z.useMemo(()=>{for(let e=u.length-1;e>=0;e--){let t=u[e];if(t.role===`user`&&!Oe(t))return{id:t.id,index:e,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,index:-1,turnStartedAt:void 0}},[u]),m=p.id,h=ua(f??``,o??void 0,a??void 0),g=ua(m??``,o??void 0,a??void 0),_=!!m&&VR(g),v=d.isCompaction&&d.index>p.index?h.find(e=>e.type===`compaction`):void 0,y=v?.reason===`manual`?d.startedAt:p.turnStartedAt,b=!!(f&&d.index>p.index&&(v?v.status===`failed`||v.reason===`manual`&&v.status===`completed`:wF(d.finish,h,d.error))),x=Z.useMemo(()=>{let e=`${a??``}:${f??``}`;return iz(rz(f&&!d.error&&d.index>p.index?h:YR,e,n))},[a,f,d.error,d.index,p.index,h,n]),S=ha(a??``,o??void 0),C=Ka(a??``,o??void 0),w=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),T=Wa(w),{phase:E,isWorking:D}=Cx(a,o??void 0),O=!!(d.error&&d.index>p.index),k=Fa(a??``,o??void 0),A=k?.type===`retry`?k.attempt:void 0,j=k?.type===`retry`?k.next:void 0,M=Z.useMemo(()=>az(x),[x]),N=Z.useMemo(()=>{let e=!!(T&&!T.acknowledged);return{wasAborted:e,abortActive:e}},[T]),P=Z.useMemo(()=>{if(s)return{...JR,isRecovering:!0,canAbort:D};if(O&&E!==`retry`)return{...JR,isTurnSettled:!0,canAbort:D};if(N.wasAborted)return{...JR,wasAborted:!0,abortActive:N.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(b)return{...JR,isComplete:v?.status!==`failed`,isTurnSettled:!0,turnStartedAt:y};let e=D,t=E===`busy`,r=E===`retry`,i=e&&(_||v?.status===`running`),a=`idle`;e&&(a=!i&&(M.activePartType===`tool`||M.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:A,next:j,message:k?.type===`retry`?k.message:void 0}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(M.activePartType===`tool`||M.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):M.statusText:null,isGenericStatus:!e||!i&&M.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?M.activePartType:void 0,activeToolName:e&&!i?M.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:o,turnStartedAt:y}},[s,O,E,D,b,_,v?.status,y,M,N,A,j,k,n]);return{forming:Z.useMemo(()=>({isActive:!s&&!O&&D&&M.activePartType===`text`,characterCount:0}),[s,O,D,M.activePartType]),working:Z.useMemo(()=>{if(s||P.wasAborted||P.abortActive)return P;if(l)return{...P,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!0,activePartType:void 0,activeToolName:void 0,isComplete:!1,isTurnSettled:!1,retryInfo:null};let e=S.length>0,t=C.length>0;return!e&&!t?P:t?{...P,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...P,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[s,P,l,S,C,n])}}var fz=Z.memo(()=>{let e=(0,Q.c)(15),t=Zb(),n=Wa(pz),r=Wa(mz),i=t.sessionId??n,a=t.directory??r??void 0,o;e[0]===i?o=e[1]:(o=e=>i?e.sessionAbortFlags?.get(i)??null:null,e[0]=i,e[1]=o);let s=Wa(o),c=Wa(hz),l=Wa(gz),{working:u}=dz(i,a),d=ei(_z),f=!!(s&&!s.acknowledged),p=!!(i&&c===i&&typeof l==`number`&&l>Date.now()),m=u.isWaitingForPermission||!!u.retryInfo||f||u.wasAborted||u.isWorking;if(u.isRecovering)return null;let h=f||u.wasAborted,g=f||u.abortActive,_;return e[2]!==d||e[3]!==p||e[4]!==m||e[5]!==h||e[6]!==g||e[7]!==u.isGenericStatus||e[8]!==u.isTurnSettled||e[9]!==u.isWaitingForPermission||e[10]!==u.isWorking||e[11]!==u.retryInfo||e[12]!==u.statusText||e[13]!==u.turnStartedAt?(_=(0,$.jsx)(nx,{isWorking:u.isWorking,statusText:u.statusText,isGenericStatus:u.isGenericStatus,isWaitingForPermission:u.isWaitingForPermission,wasAborted:h,abortActive:g,retryInfo:u.retryInfo,turnStartedAt:u.turnStartedAt,isTurnSettled:u.isTurnSettled,showAbortPrompt:p,showAssistantStatus:m,showTodos:!1,agentName:d}),e[2]=d,e[3]=p,e[4]=m,e[5]=h,e[6]=g,e[7]=u.isGenericStatus,e[8]=u.isTurnSettled,e[9]=u.isWaitingForPermission,e[10]=u.isWorking,e[11]=u.retryInfo,e[12]=u.statusText,e[13]=u.turnStartedAt,e[14]=_):_=e[14],_});fz.displayName=`StatusRowContainer`;function pz(e){return e.currentSessionId}function mz(e){return e.currentSessionDirectory}function hz(e){return e.abortPromptSessionId}function gz(e){return e.abortPromptExpiresAt}function _z(e){return e.currentAgentName}var vz=(e,t)=>{if(typeof e!=`object`||!e)return;let n=e[t];if(typeof n!=`string`)return;let r=n.trim();return r.length>0?r:void 0},yz=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},bz=Z.memo(e=>{let t=(0,Q.c)(36),{assistantMessage:n,userMessage:r,pendingPresentation:i,assistantIsInActiveTurn:a,isMobile:o}=e,s=ei(xz),c=ei(oe(Sz)),l=n?.info.sessionID??r?.info.sessionID,u;t[0]!==a||t[1]!==l?(u=e=>({currentContextAgent:a&&l?e.currentAgentContext.get(l):void 0,savedSessionAgentSelection:a&&l?e.sessionAgentSelections.get(l):void 0}),t[0]=a,t[1]=l,t[2]=u):u=t[2];let{currentContextAgent:d,savedSessionAgentSelection:f}=ny(oe(u)),p;t[3]===r?p=t[4]:(p=r?aR(r.info):null,t[3]=r,t[4]=p);let m=p,h;t[5]===n?h=t[6]:(h=n?aR(n.info):null,t[5]=n,t[6]=h);let g=h,_;t[7]!==n||t[8]!==d||t[9]!==i?.agentName||t[10]!==f||t[11]!==m?.agentName?(_=()=>n?vz(n.info,`mode`)??vz(n.info,`agent`)??m?.agentName??d??f:i?.agentName??m?.agentName,t[7]=n,t[8]=d,t[9]=i?.agentName,t[10]=f,t[11]=m?.agentName,t[12]=_):_=t[12],i?.agentName,m?.agentName;let v;t[13]===_?v=t[14]:(v=_(),t[13]=_,t[14]=v);let y=v,b;t[15]!==y||t[16]!==l?(b=e=>{if(l&&y){let t=e.getAgentModelForSession(l,y);if(t?.providerId&&t.modelId)return t}if(!l)return null;let t=e.getSessionModelSelection(l);return t?.providerId&&t.modelId?t:null},t[15]=y,t[16]=l,t[17]=b):b=t[17];let x=Oi(b),S=!n||a,C;t[18]!==g||t[19]!==c||t[20]!==x||t[21]!==S||t[22]!==m?(C=sR({assistantIdentity:g,userIdentity:m,sessionSelection:x,composerSelection:c,allowComposerFallback:S}),t[18]=g,t[19]=c,t[20]=x,t[21]=S,t[22]=m,t[23]=C):C=t[23];let w=C,T=w?.providerId,E=w?.modelId,D=yz(y),O=yz(T),k=yz(E),A;if(t[24]!==i?.modelName||t[25]!==s||t[26]!==k||t[27]!==O){let e=O?s.find(e=>e.id===O):void 0;A=Ki(e,k??null)||i?.modelName||void 0,t[24]=i?.modelName,t[25]=s,t[26]=k,t[27]=O,t[28]=A}else A=t[28];let j=A,M=g?.variant??m?.variant??i?.variant,N=O??null,P=k??null,F=D??void 0,I;return t[29]!==o||t[30]!==j||t[31]!==N||t[32]!==P||t[33]!==F||t[34]!==M?(I=(0,$.jsx)(EA,{isUser:!1,isMobile:o,providerID:N,modelID:P,agentName:F,modelName:j,variant:M}),t[29]=o,t[30]=j,t[31]=N,t[32]=P,t[33]=F,t[34]=M,t[35]=I):I=t[35],I});function xz(e){return e.providers}function Sz(e){return{providerId:e.currentProviderId,modelId:e.currentModelId}}var Cz=Z.memo(e=>{let t=(0,Q.c)(19),{assistantMessages:n,messages:r,activityExpanded:i,renderMessage:a}=e,o;bb0:{let e=+(r[0]?.role===`user`);if(!r.some((t,n)=>n>=e&&t.role!==`assistant`)){o=n;break bb0}let i;t[0]===n?i=t[1]:(i=new Set(n.map(wz)),t[0]=n,t[1]=i);let a=i,s;if(t[2]!==r||t[3]!==e||t[4]!==a){let n;t[6]!==e||t[7]!==a?(n=(t,n)=>n>=e&&(t.role!==`assistant`||a.has(t.messageId))?[t.message]:[],t[6]=e,t[7]=a,t[8]=n):n=t[8],s=r.flatMap(n),t[2]=r,t[3]=e,t[4]=a,t[5]=s}else s=t[5];o=s}let s=o,c;if(t[9]!==i||t[10]!==a||t[11]!==s){let e;t[13]!==i||t[14]!==a?(e=e=>a(e,i),t[13]=i,t[14]=a,t[15]=e):e=t[15],c=s.map(e),t[9]=i,t[10]=a,t[11]=s,t[12]=c}else c=t[12];let l;return t[16]!==i||t[17]!==c?(l=(0,$.jsx)(`div`,{className:`relative z-0`,"data-turn-assistant-activity-expanded":i,children:c}),t[16]=i,t[17]=c,t[18]=l):l=t[18],l});function wz(e){return e.info.id}var Tz=e=>{let t=(0,Q.c)(13),{sessionId:n,directory:r,hasInlineError:i,fallbackHeader:a}=e,o=i!==void 0&&i,{t:s}=fr(),c=_a(n),l=Za(n,r??void 0),u;if(t[0]===n?u=t[1]:(u=e=>!!(e.session_execution_recovery[n]||e.session_status[n]?.type===`retry`),t[0]=n,t[1]=u),Fi(u,r??void 0)||l===void 0||!c||o||c.directory&&r&&c.directory!==r)return null;let d;t[2]!==c.error||t[3]!==s?(d=$L(c.error,s)??{text:s(`chat.chatInput.toast.messageSendFailed`),icon:`error-warning`,variant:`error`},t[2]=c.error,t[3]=s,t[4]=d):d=t[4];let f=d,p;t[5]===a?p=t[6]:(p=a?(0,$.jsx)(`div`,{className:`pb-2`,children:a}):null,t[5]=a,t[6]=p);let m;t[7]===f?m=t[8]:(m=(0,$.jsx)(Ov,{presentation:f}),t[7]=f,t[8]=m);let h;return t[9]!==n||t[10]!==p||t[11]!==m?(h=(0,$.jsxs)(`div`,{className:`chat-message-column py-1.5`,"data-session-error":n,children:[p,m]}),t[9]=n,t[10]=p,t[11]=m,t[12]=h):h=t[12],h},Ez=new Set,Dz=()=>{},Oz=()=>{},kz=Z.memo(e=>{let t=(0,Q.c)(53),{turn:n,showSessionError:r,activityExpanded:i,showCompactionStatus:a,pendingAssistantHeader:o,assistantHeaderMessage:s,assistantHeaderIsInActiveTurn:c,preserveActiveTurnGap:l,onToggleActivity:u,stickyUserHeader:d,renderMessage:f}=e,p=r!==void 0&&r,m=o===void 0?null:o,h=c!==void 0&&c,g=l!==void 0&&l,_=d===void 0||d,v=q(Az),y=Zb(),b=n.userMessage?.info.time?.created,x=n.userMessage??n.assistantMessages[0],S=n.activityPresentationKind===`compaction`,C;t[0]===n.userMessage?C=t[1]:(C=n.userMessage&&yR(n.userMessage),t[0]=n.userMessage,t[1]=C);let w=!!C,T=`relative w-full ${g?`pb-1`:`pb-8`}`,E=`turn-${n.turnId}`,D=n.userMessageId??n.turnId,O;t[2]!==i||t[3]!==S||t[4]!==w||t[5]!==f||t[6]!==_||t[7]!==n.userMessage?(O=!n.userMessage||S?null:_&&!w?(0,$.jsxs)(`div`,{className:`sticky top-0 z-20 relative bg-[var(--surface-background)] [overflow-anchor:none]`,children:[(0,$.jsx)(`div`,{className:`relative z-10`,children:f(n.userMessage,i)}),(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-full z-0 h-4 bg-gradient-to-b from-[var(--surface-background)] to-transparent sm:h-8`})]}):f(n.userMessage,i),t[2]=i,t[3]=S,t[4]=w,t[5]=f,t[6]=_,t[7]=n.userMessage,t[8]=O):O=t[8];let k;t[9]!==h||t[10]!==s||t[11]!==v||t[12]!==w||t[13]!==m||t[14]!==_||t[15]!==n.userMessage?(k=!w&&(m||s)?(0,$.jsx)(`div`,{className:`group w-full ${v?_?`pt-4`:`pt-0`:`pt-6`} pb-0`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(bz,{assistantMessage:s,userMessage:n.userMessage,pendingPresentation:m,assistantIsInActiveTurn:h,isMobile:v})})}):null,t[9]=h,t[10]=s,t[11]=v,t[12]=w,t[13]=m,t[14]=_,t[15]=n.userMessage,t[16]=k):k=t[16];let A;t[17]!==i||t[18]!==v||t[19]!==u||t[20]!==a||t[21]!==n.completionDisposition||t[22]!==n.durationMs||t[23]!==b?(A=a?(0,$.jsx)(`div`,{className:`group w-full ${v?`pt-4`:`pt-6`} pb-0`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(_L,{parts:[],isExpanded:i,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof b==`number`?b:void 0,onToggle:u,isMobile:v,expandedTools:Ez,onToggleTool:Dz,onShowPopup:Oz,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[17]=i,t[18]=v,t[19]=u,t[20]=a,t[21]=n.completionDisposition,t[22]=n.durationMs,t[23]=b,t[24]=A):A=t[24];let j;t[25]!==i||t[26]!==f||t[27]!==n.assistantMessages||t[28]!==n.messages?(j=(0,$.jsx)(Cz,{assistantMessages:n.assistantMessages,messages:n.messages,activityExpanded:i,renderMessage:f}),t[25]=i,t[26]=f,t[27]=n.assistantMessages,t[28]=n.messages,t[29]=j):j=t[29];let M;t[30]!==s||t[31]!==v||t[32]!==w||t[33]!==m||t[34]!==p||t[35]!==x||t[36]!==y||t[37]!==n.assistantMessages||t[38]!==n.userMessage?(M=p&&x&&y.active&&y.capabilities.compose&&(!y.sessionId||y.sessionId===x.info.sessionID)?(0,$.jsx)(Tz,{sessionId:x.info.sessionID,directory:x.sourceDirectory??y.directory,hasInlineError:!!n.assistantMessages.at(-1)?.info.error,fallbackHeader:!w&&!m&&!s?(0,$.jsx)(bz,{userMessage:n.userMessage,pendingPresentation:cR(aR(x.info)),assistantIsInActiveTurn:!1,isMobile:v}):void 0}):null,t[30]=s,t[31]=v,t[32]=w,t[33]=m,t[34]=p,t[35]=x,t[36]=y,t[37]=n.assistantMessages,t[38]=n.userMessage,t[39]=M):M=t[39];let N;t[40]!==k||t[41]!==A||t[42]!==j||t[43]!==M?(N=(0,$.jsxs)(`div`,{className:`yuri-message-hover-scope`,...IT,children:[k,A,j,M]}),t[40]=k,t[41]=A,t[42]=j,t[43]=M,t[44]=N):N=t[44];let P;return t[45]!==i||t[46]!==O||t[47]!==N||t[48]!==T||t[49]!==E||t[50]!==D||t[51]!==n.turnId?(P=(0,$.jsxs)(`section`,{className:T,id:E,"data-turn-id":n.turnId,"data-turn-activity-expanded":i,"data-scroll-spy-id":D,children:[O,N]}),t[45]=i,t[46]=O,t[47]=N,t[48]=T,t[49]=E,t[50]=D,t[51]=n.turnId,t[52]=P):P=t[52],P});function Az(e){return e.isMobile}var jz=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,Mz=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},Nz=e=>{let t=e.text;if(typeof t==`string`&&Ck(t))return t;let n=e.content;if(typeof n==`string`&&Ck(n))return n},Pz=(e,t,n,r)=>({id:jz(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:Mz(n)}),Fz=e=>{let t=[],n=new Map,r=!1,i=!1;e.assistantMessages.forEach(e=>{e.parts.forEach(e=>{if(e.type===`tool`){r=!0;return}e.type===`reasoning`&&Nz(e)&&(i=!0)})});let a=e.assistantMessages.at(-1),o=a?CF(a.parts):-1;e.assistantMessages.forEach(r=>{let i=[];r.parts.forEach((n,s)=>{let c=n.type===`tool`,l=n.type===`reasoning`||n.type===`text`?Nz(n):void 0,u=r===a&&s===o,d=null;if(c?d=`tool`:n.type===`reasoning`?d=`reasoning`:e.showTextJustificationActivity&&n.type===`text`&&l&&!u&&(d=`justification`),!d)return;let f={...Pz(e.turnId,r.info.id,n,s),kind:d};t.push(f),i.push(f)}),n.set(r.info.id,i)});let s=[],c=e.messages??e.assistantMessages.map(e=>({role:`assistant`,messageId:e.info.id,message:e})),l;for(let t of c){if(t.role!==`assistant`){if(t.message.info.nativeType===`synthetic`&&!eR(t.message.info)&&!Lk(t.message.parts))continue;l=void 0;continue}l||(l={id:t.messageId===e.assistantMessages[0]?.info.id?`${e.turnId}:activity`:`${e.turnId}:activity:${t.messageId}`,anchorMessageId:t.messageId,afterToolPartId:null,parts:[]},s.push(l)),l.parts.push(...n.get(t.messageId)??[])}let u=s.filter(e=>e.parts.length>0);return u.length===1&&(u[0].parts=t),{activityParts:t,activitySegments:u,hasTools:r,hasReasoning:i}},Iz=e=>{let t=new Map,n=new Map,r=new Map,i=new Set;e.forEach(e=>{t.set(e.turnId,e);let a=e.assistantMessages[0]?.info.id,o=e.assistantMessages[e.assistantMessages.length-1]?.info.id;e.userMessageId&&(n.set(e.userMessageId,e.turnId),i.add(e.userMessageId),r.set(e.userMessageId,{turnId:e.turnId,messageId:e.userMessageId,userMessageId:e.userMessageId,isUserMessage:!0,isAssistantMessage:!1,isFirstAssistantInTurn:!1,isLastAssistantInTurn:!1,headerMessageId:e.headerMessageId})),e.assistantMessageIds.forEach(t=>{n.set(t,e.turnId),i.add(t),r.set(t,{turnId:e.turnId,messageId:t,userMessageId:e.userMessageId,isUserMessage:!1,isAssistantMessage:!0,isFirstAssistantInTurn:t===a,isLastAssistantInTurn:t===o,headerMessageId:e.headerMessageId})});for(let t of e.messages)t.messageId!==e.userMessageId&&t.role!==`assistant`&&(n.set(t.messageId,e.turnId),r.set(t.messageId,{turnId:e.turnId,messageId:t.messageId,userMessageId:e.userMessageId,isUserMessage:!1,isAssistantMessage:!1,isFirstAssistantInTurn:!1,isLastAssistantInTurn:!1,headerMessageId:e.headerMessageId}))});let a=e.length>0?e[e.length-1]:null,o=new Set;return a&&(a.userMessageId&&o.add(a.userMessageId),a.messages.forEach(e=>{o.add(e.messageId)})),{turns:e,indexes:{turnById:t,messageToTurnId:n,messageMetaById:r},lastTurnId:a?.turnId??null,lastTurnMessageIds:o,ungroupedMessageIds:new Set}},Lz=e=>{let t=e.text;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.content;if(typeof n==`string`&&n.trim().length>0)return n},Rz=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(xF(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!SF(t))continue;let r=Lz(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:jz(n.info.id,t,e)}}}for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||t.type!==`text`)continue;let r=Lz(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:jz(n.info.id,t,e)}}}return{}},zz=e=>{let t=e.info.summary,n=t?.diffs,r=Array.isArray(n)?n:[],i=typeof t?.diffCount==`number`&&Number.isFinite(t.diffCount)?Math.max(0,Math.trunc(t.diffCount)):void 0,a=0,o=0,s=0;r.forEach(e=>{if(!e)return;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;(t!==0||n!==0)&&(s+=1),a+=t,o+=n});let c=i??s,l=t?.hasDiffs===!0||c>0||r.length>0;if(l)return{additions:a,deletions:o,files:c,hasDiffs:l}},Bz=e=>{let t=e.info.summary?.diffs;if(!Array.isArray(t)||t.length===0)return;let n=t.map(e=>{if(!e||typeof e.file!=`string`||e.file.trim().length===0)return null;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;return t===0&&n===0?null:{file:e.file,additions:t,deletions:n}}).filter(e=>e!==null);return n.length>0?n:void 0},Vz=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},Hz=e=>e.info.nativeType===`synthetic`,Uz=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},Wz=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},Gz=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},Kz=e=>{let t=e.info.time?.streamed;return typeof t==`number`&&Number.isFinite(t)?t:void 0},qz=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},Jz=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},Yz=(e,t)=>{let n=Vz(e);return{messageId:e.info.id,role:n,parentMessageId:Uz(e),message:e,order:t}},Xz=(e,t)=>{let n=e?Wz(e):void 0,r,i,a,o=!1;t.forEach(e=>{let t=Gz(e);typeof t==`number`?r=Math.max(r??0,t):o=!0;let n=Kz(e);typeof n==`number`&&(i=Math.max(i??0,n)),e.parts.forEach(e=>{let t=qz(e);typeof t==`number`&&(a=Math.max(a??0,t))})});let s=r??i??a,c=typeof n==`number`&&typeof s==`number`&&s>=n?s-n:void 0;return{isStreaming:o,isRetrying:t.length>1,startedAt:n,completedAt:r,durationMs:c}},Zz=e=>{if(e.length===0)return`active`;let t=e[e.length-1];if(!t)return`active`;let n=t.info.finish;if(t.info.error)return`abnormal`;if(n===`tool-calls`||bF(t.parts)>0)return`active`;if(n===`stop`)return`normal`;if(typeof n==`string`&&n.length>0)return`abnormal`;for(let t of e)if(typeof Gz(t)!=`number`)return`active`;return`active`},Qz=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return wF(n.finish,t.parts,n.error)},$z=e=>UR(e)?`compaction`:`default`,eB={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},tB=(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].message!==t[n].message)return!1;return!0},nB=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&tB(e.messages,t.messages),rB=(e,t)=>{e.summary=Rz(e.assistantMessages),e.summaryText=e.summary.text??(e.userMessage?Jz(e.userMessage):void 0),e.diffStats=e.userMessage?zz(e.userMessage):void 0,e.changedFiles=t.showTurnChangedFiles&&e.userMessage?Bz(e.userMessage):void 0,e.completionDisposition=Zz(e.assistantMessages),e.hasConfirmedFinalBody=Qz(e.assistantMessages);for(let t=e.messages.length-1;t>=0;--t){let n=e.messages[t];if(n.role===`assistant`)break;if(n.role!==`compaction`)continue;let r=n.message.parts.find(Ie);r?.reason===`auto`&&r.status!==`failed`&&(e.completionDisposition=`active`,e.hasConfirmedFinalBody=!1);break}e.activityPresentationKind=e.userMessage?$z(e.userMessage):`default`;let n=Fz({turnId:e.turnId,assistantMessages:e.assistantMessages,messages:e.messages,showTextJustificationActivity:t.showTextJustificationActivity}),r=t.previousProjection?.indexes.turnById.get(e.turnId);if(r){let e=new Map(r.activitySegments.map(e=>[e.anchorMessageId,e]));for(let t of n.activitySegments)for(let n of t.parts){let r=e.get(n.messageId);if(r){t.id=r.id,t.anchorMessageId=r.anchorMessageId;break}}}return e.activityParts=n.activityParts,e.activitySegments=n.activitySegments,e.hasTools=n.hasTools,e.hasReasoning=n.hasReasoning,e.stream=Xz(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},iB=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>rB(e,t));let r=n.turns.length===e.length,i=!1,a=e.map((e,a)=>{let o=n.indexes.turnById.get(e.turnId);return o&&nB(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,rB(e,t))});return r&&i?n.turns:a},aB=e=>{if(e.length<=1)return e;let t=!1,n=e.map((n,r)=>{if(r===e.length-1||n.completionDisposition!==`active`||(e[r+1]?.assistantMessages.length??0)===0)return n;t=!0;let i=e[r+1]?.startedAt,a=n.durationMs,o=n.completedAt;return typeof a!=`number`&&typeof n.startedAt==`number`&&typeof i==`number`&&i>=n.startedAt&&(o=i,a=i-n.startedAt),{...n,completionDisposition:`abnormal`,completedAt:o,durationMs:a,stream:{...n.stream,isStreaming:!1,completedAt:o??n.stream.completedAt,durationMs:a}}});return t?n:e},oB=(e,t)=>{let n={...eB,...t},r=[],i=new Map,a=new Map,o=new Set;e.forEach((e,t)=>{let n=Vz(e);if(n===`compaction`&&r.length>0){a.set(e.info.id,r[r.length-1]),o.add(e.info.id);return}let s=n===`assistant`&&r.length===0&&!Uz(e);if(n!==`user`&&!s)return;if(r.length>0&&Hz(e)){a.set(e.info.id,r[r.length-1]),o.add(e.info.id);return}let c={turnId:e.info.id,userMessageId:s?void 0:e.info.id,userMessage:s?void 0:e,headerMessageId:void 0,messages:s?[]:[Yz(e,t)],assistantMessageIds:[],assistantMessages:[],activityParts:[],activitySegments:[],summary:{},summaryText:void 0,hasTools:!1,hasReasoning:!1,diffStats:void 0,changedFiles:void 0,stream:{isStreaming:!1,isRetrying:!1},completionDisposition:`active`,activityPresentationKind:`default`,hasConfirmedFinalBody:!1};r.push(c),c.userMessageId&&(i.set(c.userMessageId,c),o.add(e.info.id))});let s=r[0]?.userMessage?void 0:r[0];e.forEach((e,t)=>{let n=Vz(e),r=i.get(e.info.id);r&&(s=r);let c=a.get(e.info.id);if(c){c.messages.push(Yz(e,t));return}if(n!==`assistant`)return;let l=Uz(e),u=l?i.get(l):s;u&&(u.assistantMessages.push(e),u.assistantMessageIds.push(e.info.id),u.messages.push(Yz(e,t)),u.headerMessageId||=e.info.id,o.add(e.info.id))});let c=n.previousProjection;if(c)for(let e of r)for(let t of e.assistantMessages){let n=c.indexes.messageToTurnId.get(t.info.id),r=n?c.indexes.turnById.get(n):void 0;if(r&&(!r.userMessage||r.userMessageId===e.userMessageId)){e.turnId=r.turnId,r.headerMessageId&&e.assistantMessageIds.includes(r.headerMessageId)&&(e.headerMessageId=r.headerMessageId);break}}let l=Iz(aB(iB(r,n))),u=new Set;return e.forEach(e=>{o.has(e.info.id)||Vz(e)===`assistant`&&Uz(e)||u.add(e.info.id)}),{...l,ungroupedMessageIds:u}},sB=30,cB=4,lB=4,uB=33554432,dB=8388608,fB=new Map,pB=new Map,mB=0,hB=new WeakMap,gB=1,_B=()=>E()?cB:vi()?lB:sB,vB=()=>E()||vi()?dB:uB,yB=(e,t)=>{let n=e.length*2+256;for(let e of t.turns)n+=512,n+=e.messages.length*160,n+=e.activityParts.length*128,n+=(e.changedFiles?.length??0)*160,n+=(e.summaryText?.length??0)*2;return n},bB=e=>{fB.delete(e);let t=pB.get(e)??0;pB.delete(e),mB=Math.max(0,mB-t)},xB=e=>{let t=hB.get(e);if(t!==void 0)return t;let n=gB;return gB+=1,hB.set(e,n),n},SB=e=>e.map(e=>`${xB(e.info)}:${xB(e.parts)}:${e.parts.map(e=>xB(e)).join(`,`)}`).join(`;`),CB=(e,t,n,r)=>{let i=t.length>0?t[t.length-1]:void 0,a=i?.info?.id??``,o=i?.parts?.length??0;return[e,t.length,a,o,SB(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},wB=e=>{let t=fB.get(e);return t&&(fB.delete(e),fB.set(e,t)),t},TB=(e,t)=>{bB(e);let n=_B(),r=vB(),i=yB(e,t);if(!(i>r)){for(;fB.size>=n||mB+i>r;){let e=fB.keys().next().value;if(typeof e!=`string`)break;bB(e)}fB.set(e,t),pB.set(e,i),mB+=i}},EB=[],DB=(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},OB=e=>{if(!e.hasLiveTail)return null;if(e.turnCount===0)return e.previousStart;let t=e.previousStart??e.turnCount-1,n=Math.min(Math.max(t,0),e.turnCount-1);return!e.liveTailActive&&e.turnCount-n>12?e.turnCount-1:n},kB=(e,t)=>t===null?{staticTurns:e,streamingTurns:EB}:{staticTurns:t===0?EB:e.slice(0,t),streamingTurns:e.slice(t)},AB=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(EB),a=Z.useRef(null),o=Z.useRef(t.sessionKey),s=Z.useRef(t.showTextJustificationActivity),c=Z.useRef(t.showTurnChangedFiles);(o.current!==t.sessionKey||s.current!==t.showTextJustificationActivity||c.current!==t.showTurnChangedFiles)&&(o.current=t.sessionKey,s.current=t.showTextJustificationActivity,c.current=t.showTurnChangedFiles,n.current=null,r.current=[],i.current=EB,a.current=null);let l=Z.useMemo(()=>{let r=CB(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=wB(r);return i&&(!n.current||i===n.current)?(n.current=i,i):we(`ui.turns.projection_ms`,()=>{let i=oB(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,TB(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=a.current?.turnId,d=Z.useMemo(()=>u?l.turns.findIndex(e=>e.turnId===u):-1,[l.turns,u]),f=OB({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:d>=0?d:a.current?.index??null});return f===null?a.current=null:l.turns[f]&&(a.current={turnId:l.turns[f].turnId,index:f}),{projection:l,staticTurns:Z.useMemo(()=>{let e=kB(l.turns,f).staticTurns;return DB(r.current,e)?r.current:r.current=e},[f,l.turns]),streamingTurns:Z.useMemo(()=>{let e=kB(l.turns,f).streamingTurns;return DB(i.current,e)?i.current:i.current=e},[f,l.turns])}},jB=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},MB=(e,t)=>{if(!t.sessionId)return e;let n={name:`SessionRetry`,message:t.message,data:{message:t.message}},r=-1;for(let t=e.length-1;t>=0;--t)if(jB(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(jB(e[t])===`assistant`){i=t;break}if(i>=0)return e[i].info.error?e:e.map((e,t)=>t===i?{...e,info:{...e.info,error:n}}:e);let a=typeof t.confirmedAt==`number`?t.confirmedAt:t.fallbackTimestamp,o={info:{id:`synthetic_retry_notice_${t.sessionId}`,sessionID:t.sessionId,role:`assistant`,time:{created:a,completed:a},finish:`stop`,error:n},parts:[]},s=e.slice();return s.splice(r+1,0,o),s},NB=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=ct(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:qR({...e,parts:r})},PB=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=NB(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=NB(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=new Map(i.map(e=>[e.info.id,e])),o=oB(e.turn.messages.map(e=>a.get(e.messageId)??e.message),{showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles}).turns[0]??{...e.turn,assistantMessages:i,assistantMessageIds:i.map(e=>e.info.id)};return{...e,turn:o}},FB=[],IB=(e,t)=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===t}),LB=(e,t)=>{let n=e[t];return{kind:`ungrouped`,key:`msg:${n.info.id}`,message:n,previousMessage:t>0?e[t-1]:void 0,nextMessage:t<e.length-1?e[t+1]:void 0}},RB=(e,t,n,r)=>{let i=new Map;for(let e of t){let t=e.userMessage??e.assistantMessages?.[0];t&&i.set(t.info.id,e)}let a=[];for(let t=0;t<e.length;t+=1){let o=e[t],s=i.get(o.info.id);if(s){a.push(IB(s,r));continue}n.has(o.info.id)&&a.push(LB(e,t))}return a};function zB(e){let{messages:t,turns:n,streamingTurns:r,ungroupedMessageIds:i,lastTurnId:a}=e;if(i.size===0){if(r.length===0)return{history:n.map(e=>IB(e,a)),tail:FB};let e=r[0].turnId,t=n.findIndex(t=>t.turnId===e);return t<0?{history:n.map(e=>IB(e,a)),tail:r.map(e=>IB(e,a))}:{history:n.slice(0,t).map(e=>IB(e,a)),tail:n.slice(t).map(e=>IB(e,a))}}let o=RB(t,n,i,a);if(r.length===0){let e=t[t.length-1];if(!e||!i.has(e.info.id))return{history:o,tail:FB};let n=o.find(t=>t.kind===`ungrouped`&&t.message.info.id===e.info.id);return{history:n?o.filter(e=>e!==n):o,tail:n?[n]:FB}}let s=r[0].turnId,c=o.findIndex(e=>e.kind===`turn`&&e.turn.turnId===s);return c<0?{history:o,tail:r.map(e=>IB(e,a))}:{history:o.slice(0,c),tail:o.slice(c)}}var BB=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},VB=2,HB=2,UB=2,WB=e=>Math.min(Math.max(0,e),VB),GB=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+HB),KB=(e,t,n,r)=>{let i=dd(e);if(n===null||!Number.isFinite(n)||!r||r<=0)return i;let a=r*UB,o=n-a,s=n+r+a;return i.filter(n=>{if(n>=e.startIndex-1&&n<=e.endIndex+1)return!0;let r=t[n];return!r||r.end>=o&&r.start<=s})},qB=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(tN.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},JB=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(rc.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},YB=12,XB=16,ZB=new Map,QB=e=>{let t=ZB.get(e);if(t)return ZB.delete(e),ZB.set(e,t),t},$B=(e,t)=>{if(t.size!==0)for(ZB.delete(e),ZB.set(e,t);ZB.size>XB;){let e=ZB.keys().next().value;if(typeof e!=`string`)break;ZB.delete(e)}},eV=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??YB)),r=new Set;for(let t=Math.max(0,e.length-n);t<e.length;t+=1){let n=e[t];n&&r.add(n)}let i=t?.restore;if(i&&i.size>0){let t=new Set(e);for(let e of i)t.has(e)&&r.add(e)}return r},tV=(e,t)=>{let n=t[t.length-1];if(!n||e.has(n))return e;let r=new Set(e);return r.add(n),r},nV=({entryKeys:e,mountedIndexes:t,visibleStartIndex:n,visibleEndIndex:r,scrollDirection:i,preloadEntries:a,hydratedKeys:o})=>{if(e.length===0||t.length===0)return{visible:[],preload:[]};let s=new Set(t),c=[],l=[],u=new Set,d=(t,n)=>{if(n<0||n>=e.length||!s.has(n))return;let r=e[n];!r||o.has(r)||u.has(r)||(u.add(r),t.push(r))},f=e.length-1,p=Math.min(f,Math.max(0,Math.floor(n))),m=Math.min(f,Math.max(p,Math.floor(r)));for(let e=m;e>=p;--e)d(c,e);let h=Math.max(0,Math.floor(a)),g=()=>{let e=Math.min(f,m+h);for(let t=m+1;t<=e;t+=1)d(l,t)},_=()=>{let e=Math.max(0,p-h);for(let t=p-1;t>=e;--t)d(l,t)};return i===`backward`?(_(),g()):(g(),_()),{visible:c,preload:l}},rV=e=>{let{visible:t,preload:n}=nV(e),r=n.slice(0,Math.max(0,Math.floor(e.preloadReleaseLimit)));if(!e.allowVisibleRelease)return r;let i=e.visibleReleaseLimit,a=typeof i==`number`&&i>0?t.slice(0,Math.floor(i)):t;return a.length>0?[...a,...r]:r},iV=(e,t)=>{let n=new Set(t),r=!1,i=new Set;for(let t of e)n.has(t)?i.add(t):r=!0;return r?i:e},aV=`data-markdown-ready`,oV=`data-markdown-hydration`,sV=`data-markdown-pin-reveal`,cV=e=>[...eV(e.entryKeys,{seedCount:e.seedCount,restore:e.restore})],lV=e=>e.reason===`jump-to-latest`||!e.alreadyRevealedForScope,uV=e=>{if(e.querySelector(`[data-markdown-hydration="deferred"]`))return!1;let t=e.querySelectorAll(`[data-markdown-content]`);if(t.length===0)return!0;for(let e of t)if(!e.closest(`[data-markdown-ready="true"]`))return!1;return!0},dV=(e,t)=>{if(t.size===0)return!0;let n=e.querySelectorAll(`[data-turn-entry]`),r=!1;for(let e of n){let n=e.getAttribute(`data-turn-entry`);if(!(!n||!t.has(n))&&(r=!0,!uV(e)))return!1}return r},fV=(e,t)=>{if(e){if(t){e.style.visibility=`hidden`,e.setAttribute(sV,`pending`);return}e.style.removeProperty(`visibility`),e.setAttribute(sV,`ready`)}},pV=(e,t)=>t?{...e,visibility:`hidden`}:e,mV=({root:e,relevantKeys:t,onReady:n,timeoutMs:r=600,signal:i})=>{let a=!1,o=()=>{a||(a=!0,d(),n())},s=()=>{if(i?.aborted){o();return}dV(e,t)&&o()},c=null;if(typeof MutationObserver<`u`){c=new MutationObserver(s);let t=e instanceof Element?e:e instanceof Document?e.documentElement:null;t&&c.observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[aV,oV,`data-turn-entry`]})}let l=null;r>0&&(l=setTimeout(o,r));let u=()=>o();i?.addEventListener(`abort`,u,{once:!0});let d=()=>{c?.disconnect(),c=null,l!==null&&(clearTimeout(l),l=null),i?.removeEventListener(`abort`,u)};return s(),queueMicrotask(s),()=>{a||(a=!0,d())}},hV=e=>{let t=new Map,n=!1,r=()=>{if(n=!1,t.size===0)return;let r=new Map(t);t.clear(),e(r)};return{enqueue(e,i){t.set(e,i),!n&&(n=!0,queueMicrotask(r))},flush:r,clear(){t.clear(),n=!1},pendingCount:()=>t.size}},gV=(e,t)=>{let n=e.resizeItem.bind(e),r=!1,i=hV(e=>{let i=()=>{for(let[t,r]of e)n(t,r)};r?i():((0,Sp.flushSync)(i),t?.())});return e.resizeItem=(e,t)=>{i.enqueue(e,t)},()=>{r=!0,e.resizeItem=n,i.flush()}},_V=(e,t,n)=>{let r=n.scrollOffset??0,i=n.itemSizeCache.get(e.key);return i===void 0?e.start<r:e.start+i<=r},vV=({scopeKey:e,generation:t=0,root:n,relevantKeys:r,enabled:i=!0,initiallyRevealed:a=!1})=>{let o=`${e}:${t}`,[s,c]=Z.useState(o),[l,u]=Z.useState(i&&!a),d=Z.useRef(new Set(a?[e]:[]));i&&s!==o&&(lV({reason:t>0&&s.startsWith(`${e}:`)?`jump-to-latest`:`session-open`,alreadyRevealedForScope:d.current.has(e)})&&u(!0),c(o)),!i&&l&&u(!1);let f=r.join(`\0`),p=Z.useMemo(()=>new Set(r),[f]),m=J(()=>{d.current.add(e),u(!1)});return cr(()=>{if(!i||!l){fV(n,!1);return}if(fV(n,!0),n)return mV({root:n,relevantKeys:p,onReady:m})},[i,l,n,p,o]),i&&l},yV=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},bV=(e,t)=>e,xV=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:uR(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),SV=()=>vi()?5:12,CV=16,wV=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),TV=320,EV=168,DV=8,OV=16,kV=6,AV=12,jV=4,MV=1,NV=2,PV=6,FV=4,IV=()=>vi()?OV:DV,LV=30,RV=180,zV=80,BV=160,VV=90,HV=(e,t)=>{if(e.length===0||t.length<=e.length||e[e.length-1]?.key!==t[t.length-1]?.key)return!1;let n=e[0]?.key;return t.findIndex(e=>e.key===n)>0},UV=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(wV(r.keys,n))return r.items;t.delete(e)}},write:(n,r,i)=>{if(r.length!==0)for(t.delete(n),t.set(n,{keys:r.slice(),items:i});t.size>e;){let e=t.keys().next().value;if(typeof e!=`string`)break;t.delete(e)}}}})(CV),WV=(e,t,n)=>{if(t.size===0)return[];let r=0;return e.map((e,i)=>{let a=t.get(e)??n,o={index:i,key:e,start:r,size:a,end:r+a,lane:0};return r+=a,o})},GV=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),KV=e=>e===`collapsed`?EV:TV,qV=(e,t)=>`${e}::activity:${t}`,JV=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),YV=(e,t,n)=>{let r=Number.isFinite(e)?Math.max(0,e):0,i=Number.isFinite(t)?Math.max(r,t):r,a=Number.isFinite(n)?Math.max(0,n):0;return{marginTop:Number.isFinite(e)?Math.min(0,e):0,paddingTop:r,paddingBottom:Math.max(0,a-i),minHeight:a}},XV=(e,t)=>{if(!e)return;let n=`${Math.max(0,Number.isFinite(t)?t:0)}px`;e.style.height!==``&&(e.style.height=``),e.style.minHeight!==n&&(e.style.minHeight=n)},ZV=(e,t=0)=>Math.max(e===`collapsed`?AV:kV,Math.max(0,Math.floor(t))),QV=e=>e===`collapsed`?NV:MV,$V=e=>e===`collapsed`?FV:PV,eH=(e,t)=>{e.current=t},tH=(e,t)=>UV.read(e,t),nH=(e,t,n)=>{!n||t.length===0||UV.write(e,t,n.takeSnapshot())},rH=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},iH=(e,t)=>{if(rH(e)!==`system`)return e;let n=sH(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},aH=e=>!e||rH(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),oH=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},sH=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},cH=(e,t,n)=>{if(typeof window>`u`)return!1;let r=e;for(;r&&r!==t;){if(window.getComputedStyle(r).position===`sticky`&&r.getBoundingClientRect().top<=n+1)return!0;r=r.parentElement}return!1},lH=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,uH=(e,t=e)=>{let n=e.getBoundingClientRect(),r=Array.from(t.querySelectorAll(`[data-message-id]`)),i=r.find(t=>t.getBoundingClientRect().bottom>n.top+1&&!cH(t,e,n.top))??r.find(e=>e.getBoundingClientRect().bottom>n.top+1),a=i?.dataset.messageId;return!i||!a?null:{messageId:a,offsetTop:i.getBoundingClientRect().top-n.top}},dH=(e,t)=>{let n=t.querySelectorAll(`[data-message-id]`),r=n[n.length-1],i=r?.dataset.messageId;return!r||!i?null:{messageId:i,offsetTop:r.getBoundingClientRect().top-e.getBoundingClientRect().top}},fH=(e,t)=>{let n=uH(t,e)??dH(t,e);if(!n)return null;let r=lH(e,n.messageId)?.closest(`[data-turn-entry]`),i=r?.dataset.turnEntry;return!i||!r?null:{...n,entryKey:i,entryStart:r.getBoundingClientRect().top-e.getBoundingClientRect().top,attempts:0}},pH=e=>{let t=e,n=t.state?.metadata,r=cj(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?fj(i)??null:null},mH=e=>{if(rH(e)!==`assistant`||e.parts.length!==1)return{hide:!1,taskSessionId:null};let t=e.parts[0];if(t?.type!==`tool`)return{hide:!1,taskSessionId:null};let n=typeof t.tool==`string`?t.tool.toLowerCase():``;return n!==`task`&&n!==`subagent`?{hide:!1,taskSessionId:null}:{hide:!0,taskSessionId:pH(e.parts[0])}},hH=(e,t)=>{if(!t)return e;let n=lj(e.parts,t);return n===e.parts?e:{...e,parts:n}},gH=(e,t)=>{let n=typeof t?.command==`string`?t.command.trim():``,r=typeof t?.output==`string`?t.output:``,i=typeof t?.status==`string`?t.status.trim():``,a=[],o=!1;for(let t of e.parts){if(!o&&t?.type===`text`){let e=t.text;if(t.synthetic===!0&&typeof e==`string`&&e.trim().startsWith(`The following tool was executed by the user`)){a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),o=!0;continue}}a.push(t)}return o||a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),{...e,parts:a}},_H=e=>e.chatRenderMode!==`sorted`||e.activityPresentationKind!==`compaction`||e.hasVisibleActivitySegments||e.hasAssistantMessages?!1:e.completionDisposition===`normal`||e.completionDisposition===`abnormal`||e.completionDisposition===`active`&&e.isLastTurn&&e.sessionIsWorking,vH=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s,isInActiveTurn:c,activeStreamingPhase:l,animateUserOnMount:u,onUserAnimationConsumed:d,onContentChange:f,animationHandlers:p,scrollToBottom:m}=e,h=Zb(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:h,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=h,t[3]=g):g=t[3];let _=g,v;t[4]!==l||t[5]!==u||t[6]!==p||t[7]!==o||t[8]!==c||t[9]!==n||t[10]!==i||t[11]!==f||t[12]!==d||t[13]!==r||t[14]!==m||t[15]!==a||t[16]!==s?(v=(0,$.jsx)(RR,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:u,onUserAnimationConsumed:d,onContentChange:f,animationHandlers:p,scrollToBottom:m,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s,isInActiveTurn:c,activeStreamingPhase:l}),t[4]=l,t[5]=u,t[6]=p,t[7]=o,t[8]=c,t[9]=n,t[10]=i,t[11]=f,t[12]=d,t[13]=r,t[14]=m,t[15]=a,t[16]=s,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Xb.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return fM(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&pM(e.previousMessage,t.previousMessage)&&pM(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&xM(n,r,e.message.info.id,rH(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.animationHandlers?.onChunk===t.animationHandlers?.onChunk&&e.animationHandlers?.onComplete===t.animationHandlers?.onComplete&&e.animationHandlers?.onStreamingCandidate===t.animationHandlers?.onStreamingCandidate&&e.animationHandlers?.onAnimationStart===t.animationHandlers?.onAnimationStart&&e.animationHandlers?.onReservationCancelled===t.animationHandlers?.onReservationCancelled&&e.animationHandlers?.onReasoningBlock===t.animationHandlers?.onReasoningBlock&&e.animationHandlers?.onAnimatedHeightChange===t.animationHandlers?.onAnimatedHeightChange});vH.displayName=`MessageRow`;var yH=Z.memo(({turn:e,isLastTurn:t,sessionIsWorking:n,activityRenderMode:r,turnUiStates:i,onToggleTurnGroup:a,chatRenderMode:o,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,stickyUserHeader:u=!0,shouldAnimateUserMessage:d,onUserAnimationConsumed:f,activeStreamingMessageId:p,activeStreamingPhase:m})=>{let h=q(e=>e.showReasoningTraces),g=Z.useMemo(()=>!!e.userMessage||e.assistantMessages.some(e=>!!e.info.error||Tk(e.parts,{includeReasoning:h}).some(e=>e.type===`tool`||e.type===`file`||(e.type===`text`||e.type===`reasoning`)&&Sk(e).trim().length>0)),[e.userMessage,e.assistantMessages,h]),_=Z.useRef(null);_.current===e.turnId&&!t&&e.completionDisposition!==`active`?_.current=null:t&&n&&(_.current=e.turnId);let v=_.current===e.turnId,y=Z.useRef({turnId:e.turnId,shown:!1});y.current.turnId!==e.turnId&&(y.current={turnId:e.turnId,shown:!1});let b=i.get(e.turnId),x=fR({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n||v,durationMs:e.durationMs}),S=xV({expansionDisposition:hR({isLastTurn:t,turnCompletionDisposition:e.completionDisposition,headerPresentationDisposition:x.completionDisposition,hasAssistantMessages:e.assistantMessages.length>0}),activityRenderMode:r,isLastTurn:t,isActivelyProcessing:t&&n,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),C=b?.automatic&&e.completionDisposition===`normal`&&e.hasConfirmedFinalBody&&!(t&&n),w=b&&!C?b.isExpanded:S,T=J(()=>{a(e.turnId,w)}),E=Z.useMemo(()=>{let t=e.userMessage?[e.userMessage,...e.assistantMessages]:e.assistantMessages,n=new Map;return t.forEach((e,t)=>{n.set(e.info.id,t)}),{ordered:t,lookup:n}},[e.assistantMessages,e.userMessage]),D=Z.useMemo(()=>{if(p&&e.assistantMessages.some(e=>e.info.id===p))return p;for(let t=e.assistantMessages.length-1;t>=0;--t){let n=e.assistantMessages[t];if(!yV(n))return n.info.id}return null},[p,e.assistantMessages]),O=Z.useMemo(()=>o===`live`?e.assistantMessages:bV(e.assistantMessages,D),[o,D,e.assistantMessages]),k=Z.useMemo(()=>{let e=new Map;return O.forEach((t,n)=>{e.set(t.info.id,n)}),e},[O]),A=Z.useMemo(()=>new Set(O.map(e=>e.info.id)),[O]),j=Z.useMemo(()=>e.headerMessageId&&k.has(e.headerMessageId)?e.headerMessageId:O[0]?.info.id,[e.headerMessageId,k,O]),M=Z.useMemo(()=>o===`sorted`?A.size===e.assistantMessages.length?e.activityParts:e.activityParts.filter(e=>A.has(e.messageId)):e.activityParts,[o,A,e.activityParts,e.assistantMessages.length]),N=Z.useMemo(()=>o!==`sorted`||A.size===e.assistantMessages.length?e.activitySegments:e.activitySegments.map(e=>{let t=e.parts.filter(e=>A.has(e.messageId));if(t.length===0)return null;let n=A.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null}).filter(e=>e!==null),[o,A,e.activitySegments,e.assistantMessages.length]),P=Z.useMemo(()=>{let t=e.userMessage?.info.time?.created,n=e.userMessage?.info,r=n?.model?.variant??n?.variant,i=typeof r==`string`&&r.trim().length>0?r:void 0;return{turnId:e.turnId,assistantTps:iI(e.assistantMessages.map(e=>({createdAt:e.info.time.created,streamedAt:e.info.time.streamed,outputTokens:e.info.tokens?.output,reasoningTokens:e.info.tokens?.reasoning}))),summaryBody:e.summaryText,activityParts:M,activityGroupSegments:N,headerMessageId:e.headerMessageId,hasTools:e.hasTools,hasReasoning:e.hasReasoning,activityPresentationKind:e.activityPresentationKind,diffStats:e.diffStats,changedFiles:e.changedFiles,userMessageCreatedAt:typeof t==`number`?t:void 0,userMessageVariant:i}},[e.activityPresentationKind,e.assistantMessages,e.changedFiles,e.diffStats,e.hasReasoning,e.hasTools,e.headerMessageId,e.summaryText,e.turnId,e.userMessage?.info,M,N]),F=BB((r,i)=>{let a=rH(r)===`user`,u=E.lookup.get(r.info.id),p=k.get(r.info.id)??-1,h=p>=0,g=p===0,_=p===O.length-1,v=!!j&&r.info.id===j,y=N.some(e=>e.anchorMessageId===r.info.id),b=o===`sorted`?h:v||g||_,S=O[0]?.info.id??e.headerMessageId,C=a?void 0:h?g?e.userMessage:void 0:typeof u==`number`&&u>0?E.ordered[u-1]:void 0,w=h?{turnId:e.turnId,activityOwnerMessageId:j,isFirstAssistantInTurn:g,isLastAssistantInTurn:_,isLatestTurn:t,isWorking:(t||e.completionDisposition===`active`)&&n&&(o===`sorted`?y:r.info.id===D),isTurnSettled:pR({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,hasConfirmedSettledAssistant:e.hasConfirmedFinalBody}),hasTools:e.hasTools,hasReasoning:e.hasReasoning,completionDisposition:x.completionDisposition,activityPresentationKind:e.activityPresentationKind,durationMs:x.durationMs,assistantTps:P.assistantTps,...b?{summaryBody:P.summaryBody,activityParts:P.activityParts,activityGroupSegments:P.activityGroupSegments,headerMessageId:P.headerMessageId,diffStats:P.diffStats,changedFiles:P.changedFiles,userMessageCreatedAt:P.userMessageCreatedAt,userMessageVariant:P.userMessageVariant,isGroupExpanded:i,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(vH,{message:r,previousMessage:C,nextMessage:void 0,turnGroupingContext:w,assistantHeaderMessageId:S,turnOwnsAssistantHeader:h,isInActiveTurn:!!D&&r.info.id===D,activeStreamingPhase:r.info.id===D?m:null,animateUserOnMount:d(r),onUserAnimationConsumed:f,onContentChange:s,animationHandlers:c(r.info.id),scrollToBottom:l},r.info.id)}),I=Z.useMemo(()=>O===e.assistantMessages?e:{...e,assistantMessages:O},[e,O]),L=Z.useMemo(()=>((lR({isLastTurn:t,sessionIsWorking:n,hasAssistantMessages:e.assistantMessages.length>0,activityPresentationKind:e.activityPresentationKind,hasActiveStreamingMessage:!!p})||e.assistantMessages.length>0)&&(y.current.shown=!0),!y.current.shown||e.activityPresentationKind===`compaction`?null:e.userMessage?cR(aR(e.userMessage.info)):null),[p,t,n,e.activityPresentationKind,e.assistantMessages.length,e.userMessage]);if(!g){let t=e.assistantMessages.find(e=>e.info.id===p);return t?(0,$.jsx)(bH,{message:t,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,shouldAnimateUserMessage:d,onUserAnimationConsumed:f,activeStreamingMessageId:p,activeStreamingPhase:m}):null}return(0,$.jsx)(kz,{turn:I,showSessionError:t,activityExpanded:w,onToggleActivity:T,showCompactionStatus:_H({chatRenderMode:o,activityPresentationKind:e.activityPresentationKind,hasVisibleActivitySegments:N.length>0,hasAssistantMessages:e.assistantMessages.length>0,completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n}),pendingAssistantHeader:L,assistantHeaderMessage:O[0],assistantHeaderIsInActiveTurn:O[0]?.info.id===D,preserveActiveTurnGap:v,stickyUserHeader:u,renderMessage:F})});yH.displayName=`TurnBlock`;var bH=Z.memo(e=>{let t=(0,Q.c)(30),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d}=e,{t:f}=fr();if(iA(n)){let e;t[0]===f?e=t[1]:(e=f(`assistants.conversation.newSessionDivider`),t[0]=f,t[1]=e);let n;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[2]=n):n=t[2];let r;t[3]===f?r=t[4]:(r=f(`assistants.conversation.newSessionDivider`),t[3]=f,t[4]=r);let i;t[5]===r?i=t[6]:(i=(0,$.jsx)(`span`,{className:`shrink-0 typography-meta text-muted-foreground`,children:r}),t[5]=r,t[6]=i);let a;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[7]=a):a=t[7];let o;t[8]===i?o=t[9]:(o=(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[n,i,a]}),t[8]=i,t[9]=o);let s;return t[10]!==e||t[11]!==o?(s=(0,$.jsx)(`div`,{className:`chat-message-column px-4 py-5`,role:`separator`,"aria-label":e,children:o}),t[10]=e,t[11]=o,t[12]=s):s=t[12],s}let p;t[13]!==n||t[14]!==c?(p=c(n),t[13]=n,t[14]=c,t[15]=p):p=t[15];let m;t[16]!==o||t[17]!==n.info.id?(m=o(n.info.id),t[16]=o,t[17]=n.info.id,t[18]=m):m=t[18];let h=!!u&&n.info.id===u,g=n.info.id===u?d:null,_;return t[19]!==n||t[20]!==i||t[21]!==a||t[22]!==l||t[23]!==r||t[24]!==s||t[25]!==p||t[26]!==m||t[27]!==h||t[28]!==g?(_=(0,$.jsx)(vH,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:p,onUserAnimationConsumed:l,onContentChange:a,animationHandlers:m,scrollToBottom:s,isInActiveTurn:h,activeStreamingPhase:g}),t[19]=n,t[20]=i,t[21]=a,t[22]=l,t[23]=r,t[24]=s,t[25]=p,t[26]=m,t[27]=h,t[28]=g,t[29]=_):_=t[29],_});bH.displayName=`UngroupedMessageRow`;var xH=Z.memo(e=>{let t=(0,Q.c)(26),{entry:n,hydrateMarkdown:r,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,stickyUserHeader:s,sessionIsWorking:c,activityRenderMode:l,turnUiStates:u,onToggleTurnGroup:d,chatRenderMode:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,showLiveStatusRow:_}=e,v=r===void 0||r,y=_!==void 0&&_,b;t[0]!==h||t[1]!==g||t[2]!==l||t[3]!==f||t[4]!==n.isLastTurn||t[5]!==n.kind||t[6]!==n.message||t[7]!==n.nextMessage||t[8]!==n.previousMessage||t[9]!==n.turn||t[10]!==a||t[11]!==i||t[12]!==d||t[13]!==m||t[14]!==o||t[15]!==c||t[16]!==p||t[17]!==s||t[18]!==u?(b=n.kind===`ungrouped`?(0,$.jsx)(bH,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g}):(0,$.jsx)(yH,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:c,activityRenderMode:l,turnUiStates:u,onToggleTurnGroup:d,chatRenderMode:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,stickyUserHeader:s}),t[0]=h,t[1]=g,t[2]=l,t[3]=f,t[4]=n.isLastTurn,t[5]=n.kind,t[6]=n.message,t[7]=n.nextMessage,t[8]=n.previousMessage,t[9]=n.turn,t[10]=a,t[11]=i,t[12]=d,t[13]=m,t[14]=o,t[15]=c,t[16]=p,t[17]=s,t[18]=u,t[19]=b):b=t[19];let x=b,S;t[20]===y?S=t[21]:(S=y?(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(fz,{})}):null,t[20]=y,t[21]=S);let C;return t[22]!==x||t[23]!==v||t[24]!==S?(C=(0,$.jsxs)(JB,{enabled:v,children:[x,S]}),t[22]=x,t[23]=v,t[24]=S,t[25]=C):C=t[25],C});xH.displayName=`MessageListEntry`;var SH=Z.memo(({entries:e,historyAnchorToken:t,engine:n,contentRef:r,scrollRef:i,registerTanstackVirtualizer:a,virtualizerKey:o,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,stickyUserHeader:u,activityRenderMode:d,turnUiStates:f,onToggleTurnGroup:p,chatRenderMode:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g})=>{let[_,v]=Z.useState(e),y=Z.useSyncExternalStore(Aw,kw,()=>null),b=y&&i?.current?.contains(y)?y.closest(`[data-turn-entry]`)?.dataset.turnEntry:void 0,x=n===`tanstack`&&_.length>=SV(),S=Z.useRef(n),C=Z.useRef(null),[w,T]=Z.useReducer(e=>e+1,0);if(!x)C.current=null;else if(S.current===`none`&&x&&C.current===null){let e=r.current,t=i?.current;e&&t&&(C.current=fH(e,t))}let E=Z.useRef(!1),D=Z.useRef(0),O=Z.useRef(null),k=vi();Z.useEffect(()=>{if(!k)return;let e=i?.current;if(!e)return;let t=()=>{E.current=!0},n=()=>{E.current=!1},r=()=>{D.current=performance.now()};return e.addEventListener(`touchstart`,t,{passive:!0}),e.addEventListener(`touchend`,n,{passive:!0}),e.addEventListener(`touchcancel`,n,{passive:!0}),e.addEventListener(`scroll`,r,{passive:!0}),()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),e.removeEventListener(`scroll`,r)}},[k,i]);let A=()=>E.current||performance.now()-D.current<BV,j=_;e===_?O.current!==null&&(O.current=null):k&&HV(_,e)&&A()?O.current===null&&(O.current=performance.now()):(O.current=null,v(e),j=e);let[,M]=Z.useReducer(e=>e+1,0);or(()=>{O.current!==null&&(A()||M())},k&&O.current!==null?VV:null);let N=Z.useRef(j);N.current=j;let P=Z.useMemo(()=>j.map(e=>e.key),[j]),F=IV(),[I,L]=Z.useState(()=>WB(F));Z.useEffect(()=>{if(!(!x||I>=F))return nd(()=>{Z.startTransition(()=>{L(e=>GB(e,F))})})},[I,x,F]);let R=qV(o,d),[z]=Z.useState(()=>x?tH(R,e.map(e=>e.key)):void 0),B=Z.useRef(null),V=J(e=>{B.current=e,r.current=e}),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(new Set),ee=Z.useRef(new Set),te=Z.useRef(t),G=Z.useRef(j),ne=G.current!==j&&HV(G.current,j);if(G.current=j,te.current!==t||ne){te.current=t;let e=i?.current,n=B.current??r.current;H.current=e&&n?uH(e,n):null}let re=J(()=>{H.current=null,U.current=null});ir(`wheel`,re,void 0,{passive:!0,capture:!0}),ir(`touchstart`,re,void 0,{passive:!0,capture:!0}),ir(`pointerdown`,re,void 0,{passive:!0,capture:!0}),ir(`click`,re,void 0,{capture:!0}),ir(`keydown`,re,void 0,{capture:!0});let ie=J(()=>{let e=U.current??H.current,t=i?.current;if(!e||!t)return;let n=lH(t,e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&pe.scrollToOffset(t.scrollTop+r,{behavior:`auto`})}),ae=KV(d),oe=Z.useRef(ae),se=Z.useRef(d);se.current!==d&&(se.current=d,oe.current=ae);let ce=Z.useRef(x),le=Z.useRef(new Map),ue=Z.useRef(void 0);if(Z.useLayoutEffect(()=>{x||(ue.current=void 0)}),x&&ue.current===void 0){if(!z){let e=le.current;e.clear(),r?.current?.querySelectorAll(`[data-turn-entry]`).forEach(t=>{let n=t.dataset.turnEntry;n&&e.set(n,t.getBoundingClientRect().height)})}ue.current=z??WV(P,le.current,oe.current)}let de=Z.useMemo(()=>x?{width:i?.current?.clientWidth??0,height:i?.current?.clientHeight??0}:void 0,[x,i]),fe=Z.useMemo(()=>b?j.findIndex(e=>e.key===b):-1,[j,b]),pe=pd({count:j.length,enabled:x,initialRect:de,getScrollElement:()=>i?.current??null,estimateSize:()=>oe.current,overscan:I,rangeExtractor:e=>{let t=KB(e,pe.measurementsCache,pe.scrollOffset,pe.scrollRect?.height);return fe>=0&&!t.includes(fe)?[...t,fe].sort((e,t)=>e-t):t},measureElement:(e,t,n)=>{let r=n.options.getItemKey(n.indexFromElement(e)),i=n.itemSizeCache.get(r);if(n.options.useCachedMeasurements)return i??n.options.estimateSize(n.indexFromElement(e));let a=t?.borderBoxSize?.[0]?.blockSize;return a===void 0?t?e.getBoundingClientRect().height:i??n.options.estimateSize(n.indexFromElement(e)):a},scrollToFn:(e,t,n)=>{XV(B.current,n.getTotalSize()),fd(e,t,n)},getItemKey:e=>N.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:zV,initialOffset:()=>{if(ce.current){let e=oe.current,t=(ue.current??[]).reduce((t,n)=>t+(n.index<j.length?n.size-e:0),j.length*e);return Math.max(0,t-(i?.current?.clientHeight??0))}let e=C.current,t=e&&ue.current?.find(t=>t.key===e.entryKey);return(i?.current?.scrollTop??0)+(t&&e?t.start-e.entryStart:0)},initialMeasurementsCache:ue.current});Z.useEffect(()=>{let e=i?.current;!x||!e||pe.scrollElement===e||(pe.scrollOffset=e.scrollTop,pe._willUpdate(),pe.options.onChange?.(pe,!1))}),cr(()=>{if(!x)return;pe.shouldAdjustScrollPositionOnItemSizeChange=_V;let e=gV(pe,me);return()=>{e();for(let e of ee.current)e.style.removeProperty(`opacity`);ee.current.clear(),W.current.clear(),U.current=null}},[x,pe]);let me=J(()=>{ie();for(let e of ee.current)e.style.removeProperty(`opacity`);ee.current.clear(),U.current=null}),he=J(e=>{pe.measureElement(e),!(!e||!e.isConnected)&&W.current.add(e)});cr(()=>{if(!x||W.current.size===0)return;let e=[...W.current].filter(e=>e.isConnected).map(e=>({row:e,index:pe.indexFromElement(e),height:e.getBoundingClientRect().height}));W.current.clear();for(let{row:t,index:n,height:r}of e)ee.current.add(t),pe.resizeItem(n,r)});let ge=Z.useRef(null),_e=Z.useRef(null);x||(ge.current=null);let ve=J(()=>{if(!x)return;let e=B.current??i?.current;if(!e)return;let t=e.offsetWidth;if(!JV(ge.current,t)){ge.current===null&&t>0&&(ge.current=t);return}ge.current=t,_e.current!==null&&clearTimeout(_e.current),_e.current=setTimeout(()=>{_e.current=null;let e=i?.current,t=B.current;e&&t&&!E.current&&(U.current=uH(e,t));for(let e of pe.elementsCache.values())e.isConnected&&W.current.add(e);pe.measure()},220)}),ye=x&&typeof ResizeObserver<`u`;sr(ye?B:null,ve),sr(ye&&i?i:null,ve),rr(()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)}),cr(()=>{x&&ve()},[x]),cr(()=>{if(S.current=x?`tanstack`:`none`,!x){C.current=null;return}let e=C.current,t=i?.current;if(!e||!t)return;let n=lH(t,e.messageId);if(n){let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&pe.scrollToOffset(t.scrollTop+r,{behavior:`auto`}),C.current=null;return}let r=P.indexOf(e.entryKey);if(r<0||e.attempts>=1){C.current=null;return}e.attempts+=1,pe.scrollToIndex(r,{align:`start`}),T()},[n,P,x,pe,w]);let be=pe.getVirtualItems(),xe=be.map(e=>e.index),[Se,Ce]=Z.useState(()=>eV(P,{seedCount:ZV(d),restore:QB(R)})),we=tV(Se,P);for(let e of le.current.keys())we.has(e)||(we===Se&&(we=new Set(we)),we.add(e));we!==Se&&Ce(we);let Te=Z.useRef(we);Te.current=we;let Ee=Z.useRef(null);pe.scrollDirection&&(Ee.current=pe.scrollDirection);let De=pe.range?.startIndex??be[0]?.index??Math.max(0,j.length-1),Oe=pe.range?.endIndex??be[be.length-1]?.index??Math.max(0,j.length-1),ke=pe.isScrolling,Ae=Math.max(0,Oe-De+1),je=rV({entryKeys:P,mountedIndexes:xe,visibleStartIndex:De,visibleEndIndex:Oe,scrollDirection:Ee.current,preloadEntries:ZV(d,Ae),hydratedKeys:we,allowVisibleRelease:!ke,preloadReleaseLimit:ke?QV(d):jV,visibleReleaseLimit:ke?0:$V(d)}),Me=je.join(`\0`),Ne=Z.useRef(je);Ne.current=je,Z.useEffect(()=>{if(!(!x||!Me))return nd(()=>{Z.startTransition(()=>{Ce(e=>{let t=null;for(let n of Ne.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[x,Me]),Z.useEffect(()=>{Ce(e=>iV(e,P))},[P]),Z.useEffect(()=>{if(x)return a?.(pe),()=>{nH(R,N.current.map(e=>e.key),pe),$B(R,Te.current),a?.(null)}},[x,pe,R]);let Pe=BB((e,t=!0)=>(0,$.jsx)(xH,{entry:e,hydrateMarkdown:t,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,stickyUserHeader:u,sessionIsWorking:!1,activityRenderMode:d,turnUiStates:f,onToggleTurnGroup:p,chatRenderMode:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g},e.key));if(!x)return(0,$.jsx)(`div`,{ref:V,className:`relative w-full`,children:(0,$.jsx)(`div`,{children:j.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`yuri-chat-message-layout-boundary`,children:Pe(e)},e.key))})});if(n===`tanstack`){let e=YV(be[0]?.start??0,be[be.length-1]?.end??0,pe.getTotalSize());return(0,$.jsx)(`div`,{ref:V,className:`relative flow-root w-full`,style:{minHeight:e.minHeight},children:(0,$.jsx)(`div`,{style:{marginTop:e.marginTop,paddingTop:e.paddingTop,paddingBottom:e.paddingBottom},children:be.map((e,t)=>{let n=j[e.index];return n?(0,$.jsx)(`div`,{"data-index":e.index,ref:he,"data-turn-entry":n.key,style:{opacity:pe.itemSizeCache.has(n.key)?void 0:0,marginTop:t>0&&e.index>be[t-1].index+1?e.start-be[t-1].end:void 0},className:`yuri-chat-message-layout-boundary`,children:Pe(n,we.has(n.key))},n.key):null})})})}return null});SH.displayName=`StaticHistoryList`;var CH=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(`div`,{className:`yuri-chat-message-layout-boundary`,children:(0,$.jsx)(xH,{...e})}),t[0]=e,t[1]=n),n});CH.displayName=`TailEntry`;var wH=e=>{let t=(0,Q.c)(41),{entries:n,directory:r,sessionId:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,showTurnChangedFiles:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:_,activeStreamingPhase:v}=e,y=n.length-1,b=ua(_??``,r,i??void 0),x;bb0:{let e=n[y];if(!e){x=void 0;break bb0}let r=p===`sorted`,i;t[0]!==_||t[1]!==b||t[2]!==e||t[3]!==m||t[4]!==r?(i=PB(e,{activeStreamingMessageId:_,liveParts:b,showTextJustificationActivity:r,showTurnChangedFiles:m}),t[0]=_,t[1]=b,t[2]=e,t[3]=m,t[4]=r,t[5]=i):i=t[5],x=i}let S=x,C;if(t[6]!==_||t[7]!==v||t[8]!==u||t[9]!==p||t[10]!==n||t[11]!==o||t[12]!==S||t[13]!==y||t[14]!==a||t[15]!==f||t[16]!==g||t[17]!==s||t[18]!==l||t[19]!==h||t[20]!==c||t[21]!==d){let e;t[23]!==_||t[24]!==v||t[25]!==u||t[26]!==p||t[27]!==o||t[28]!==S||t[29]!==y||t[30]!==a||t[31]!==f||t[32]!==g||t[33]!==s||t[34]!==l||t[35]!==h||t[36]!==c||t[37]!==d?(e=(e,t)=>{let n=t===y;return(0,$.jsx)(CH,{entry:n?S??e:e,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:n?l:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:n?_:null,activeStreamingPhase:n?v:null},e.key)},t[23]=_,t[24]=v,t[25]=u,t[26]=p,t[27]=o,t[28]=S,t[29]=y,t[30]=a,t[31]=f,t[32]=g,t[33]=s,t[34]=l,t[35]=h,t[36]=c,t[37]=d,t[38]=e):e=t[38],C=n.map(e),t[6]=_,t[7]=v,t[8]=u,t[9]=p,t[10]=n,t[11]=o,t[12]=S,t[13]=y,t[14]=a,t[15]=f,t[16]=g,t[17]=s,t[18]=l,t[19]=h,t[20]=c,t[21]=d,t[22]=C}else C=t[22];let w;return t[39]===C?w=t[40]:(w=(0,$.jsx)($.Fragment,{children:C}),t[39]=C,t[40]=w),w};wH.displayName=`StreamingTailContent`;var TH=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,scrollRef:u,directory:d,liveStatusSlot:f,timelineHistoryAnchorToken:p,enableSendPark:m=!0,initialPinRevealComplete:h=!1},g)=>{De(`ui.message_list.render`);let{sessionKey:_,virtualizerKey:v}=GV(e,t),y=Z.useMemo(()=>pA(),[_,d]),b=q(e=>e.stickyUserHeader),x=q(e=>e.chatRenderMode),S=q(e=>e.activityRenderMode),C=q(e=>e.showTurnChangedFiles),[w,T]=Z.useState(()=>new Map),E=Z.useContext(_A),[D,O]=Z.useState(_);D!==_&&(O(_),T(new Map));let k=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set});cr(()=>{if(m)return()=>{queueMicrotask(()=>{Ri(e)})}},[m,e]);let A=J(c),j=J(()=>{l?.()}),M=J((e,t)=>{T(n=>{let r=new Map(n);return r.set(e,{isExpanded:dR(t)}),r})}),N=Z.useMemo(()=>we(`ui.message_list.base_display_ms`,()=>{let e=new Set,t=new Map,r=[];for(let e of n){let n=e.info?.id;typeof n==`string`&&t.set(n,e)}for(let i=0;i<n.length;i+=1){let a=n[i],o=a.info?.id;if(typeof o==`string`){if(e.has(o))continue;e.add(o)}r.push(qR(typeof o==`string`?t.get(o)??a:a))}let i=[],a=new Set,o=-1;for(let e=r.length-1;e>=0;--e)if(r[e].info.role===`assistant`){o=e;break}for(let e=0;e<r.length;e+=1){let t=r[e];if(e<o&&eR(t.info))continue;let n=iH(t,a);UR(t)&&a.add(t.info.id);let s=i.length>0?i[i.length-1]:void 0;if(aH(s)){let e=mH(n);if(e.hide){i[i.length-1]=hH(s,e.taskSessionId);continue}}if(vR(s)){let e=bR(n,oH(s));if(e.hide){i[i.length-1]=gH(s,e.details);continue}}i.push(n)}return i}),[n]),P=Z.useRef(null),F=Z.useRef(null),I=Z.useCallback(()=>{let e=F.current;e&&(F.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{I()},[I]);let L=J(()=>u?.current?u.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),R=Z.useMemo(()=>we(`ui.message_list.retry_overlay_ms`,()=>MB(N,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[N,o]),z=r||!!i,{projection:B,streamingTurns:V}=AB(R,{sessionKey:_,showTextJustificationActivity:x===`sorted`,showTurnChangedFiles:C,hasLiveTail:!0,liveTailActive:z});cr(()=>{z&&T(e=>{let t=e;for(let n of V)n.completionDisposition!==`active`||n.assistantMessages.length===0||e.has(n.turnId)||(t===e&&(t=new Map(e)),t.set(n.turnId,{isExpanded:!0,automatic:!0}));return t})},[z,V]);let H=Z.useMemo(()=>we(`ui.message_list.render_entries_ms`,()=>zB({messages:R,turns:B.turns,streamingTurns:V,ungroupedMessageIds:B.ungroupedMessageIds,lastTurnId:B.lastTurnId})),[R,B.lastTurnId,B.turns,B.ungroupedMessageIds,V]),U=H.history,W=H.tail,ee=W.length>0;ee&&z&&De(`ui.message_list.render.streaming`);let te=U,G=te.length>=SV(),ne=Z.useRef(G);eH(ne,G);let re=G?`tanstack`:`none`,ie=Z.useRef(null),ae=J(e=>{ie.current=e}),oe=Z.useMemo(()=>W.length>0?[...te,...W]:te,[te,W]),[se,ce]=Z.useState(0),[le,ue]=Z.useState(null),de=qV(v,S),fe=pV(void 0,vV({scopeKey:de,generation:se,root:le,relevantKeys:Z.useMemo(()=>cV({entryKeys:oe.map(e=>e.key),seedCount:ZV(S)}),[de,se,oe.length,oe[oe.length-1]?.key,S]),enabled:!1,initiallyRevealed:h})),pe=J(e=>{s(e)}),me=J(e=>{s(e)}),he=Z.useMemo(()=>n.filter(e=>rH(e)===`user`).map(e=>e.info.id),[n]),ge=k.current,_e=ge.sessionKey!==e,ve=ge.previousOrder;_e&&(m&&ge.sessionKey!==void 0&&Ri(ge.sessionKey),ge.sessionKey=e,ge.previousOrder=he,ge.animatedIds=new Set),m&&Br({sessionId:e,sessionChanged:_e,previousUserOrder:ve,currentUserOrder:he,animatedIds:ge.animatedIds}),ge.previousOrder=he;let ye=J(e=>rH(e)===`user`&&k.current.animatedIds.has(e.info.id)),be=J(e=>{k.current.animatedIds.delete(e)}),xe=Z.useMemo(()=>{let e=new Map;return oe.forEach((t,n)=>{if(t.kind===`ungrouped`){e.set(t.message.info.id,n);return}t.turn.userMessage&&e.set(t.turn.userMessage.info.id,n),t.turn.assistantMessages.forEach(t=>{e.set(t.info.id,n)})}),e},[oe]),Se=Z.useMemo(()=>{let e=new Map;return oe.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[oe]),Ce=J(e=>xe.get(e)),Te=Z.useMemo(()=>{if(!E)return w;let e=xe.get(E.messageId),t=e===void 0?void 0:oe[e];if(t?.kind!==`turn`)return w;let n=new Map(w);return n.set(t.turn.turnId,{isExpanded:!0}),n},[oe,xe,E,w]),Ee=J(e=>{let t=L();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Oe=J((e,t=`auto`)=>{if(e<0||e>=te.length||!G)return!1;let n=ie.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),ke=J((e,t=`auto`)=>{let n=L();if(!n)return!1;let r=Ee(e);if(!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect().top-i.top+n.scrollTop-50;return n.scrollTo({top:a,behavior:t}),!0});return Z.useEffect(()=>{if(!E)return;let e=L();if(!e)return;let t=vA(E.messageId,E.partId),n=globalThis.CSS?.highlights,r=!1,i=!1,a=0,o=()=>{if(a=0,i)return;let o=e.querySelectorAll(`[data-transcript-search-part]`),s=[],c;for(let e of o){let n=wA(e,E.query);s.push(...n),e.dataset.transcriptSearchPart===t&&(c=n[E.occurrence])}if(n&&typeof Highlight<`u`){n.set(`yuri-transcript-find`,new Highlight(...s));let e=new Highlight(...c?[c]:[]);e.priority=1,n.set(`yuri-transcript-find-active`,e)}if(r||!c)return;let l=c.getBoundingClientRect();if(!l.height)return;ie.current?.cancelScroll();let u=e.getBoundingClientRect();e.scrollTo({top:e.scrollTop+l.top-u.top-e.clientHeight/2,behavior:`auto`}),r=!0},s=()=>{!a&&!i&&(a=requestAnimationFrame(o))},c=()=>{r=!0};I();let l=Ce(E.messageId);l!==void 0&&!Array.from(e.querySelectorAll(`[data-transcript-search-part]`)).some(e=>e.dataset.transcriptSearchPart===t)&&Oe(l,`auto`);let u=new MutationObserver(s);return u.observe(e,{childList:!0,characterData:!0,subtree:!0}),e.addEventListener(`wheel`,c,{passive:!0}),e.addEventListener(`touchstart`,c,{passive:!0}),e.addEventListener(`pointerdown`,c,{passive:!0}),s(),()=>{i=!0,u.disconnect(),a&&cancelAnimationFrame(a),e.removeEventListener(`wheel`,c),e.removeEventListener(`touchstart`,c),e.removeEventListener(`pointerdown`,c),n?.delete(`yuri-transcript-find`),n?.delete(`yuri-transcript-find-active`)}},[E,I,L,Oe,Ce]),Z.useEffect(()=>{if(!g)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Se.get(e);if(r===void 0)return!1;let i=L();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):ee&&r>=te.length?!1:Oe(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=xe.get(e);return r===void 0?!1:ke(e,n)||(ee&&r>=te.length?!1:Oe(r,n))},holdViewportAnchor:e=>{let t=L();if(!t||typeof window>`u`)return;I();let n=0,r=0,i=!1,a=null,o=()=>{t.removeEventListener(`touchstart`,c),t.removeEventListener(`wheel`,c),t.removeEventListener(`keydown`,c),t.removeEventListener(`pointerdown`,c)},s=()=>{i||(i=!0,a!==null&&(window.cancelAnimationFrame(a),a=null),o(),F.current?.cancel===s&&(F.current=null))},c=()=>{s()};F.current={cancel:s},t.addEventListener(`touchstart`,c,{passive:!0}),t.addEventListener(`wheel`,c,{passive:!0}),t.addEventListener(`keydown`,c),t.addEventListener(`pointerdown`,c,{passive:!0});let l=()=>{if(i)return;let o=Ee(e.messageId);if(o){let n=o.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(n)>.5?(t.scrollTop+=n,r=0):r+=1}if(n+=1,r>=LV||n>=RV){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:I,isHistoryVirtualized:()=>ne.current,captureViewportAnchor:()=>{let e=L();if(!e)return null;let t=e.getBoundingClientRect(),n=Array.from(e.querySelectorAll(`[data-message-id]`)),r=n.find(n=>{let r=n.getBoundingClientRect();return r.top>=t.top&&r.top<t.bottom&&(typeof window>`u`||!cH(n,e,t.top))})??n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!cH(n,e,t.top))??n.find(e=>e.getBoundingClientRect().bottom>t.top+1);if(!r)return null;let i=r.dataset.messageId;return i?{messageId:i,offsetTop:r.getBoundingClientRect().top-t.top}:null},restoreViewportAnchor:e=>{let t=L();if(!t||!xe.has(e.messageId))return!1;let n=()=>{let n=Ee(e.messageId);if(!n)return!1;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect().top-r.top-e.offsetTop;if(i!==0){let e=t.scrollTop+i,n=ie.current;if(G&&n){if(n.options.count!==te.length)return!0;n.scrollToOffset(e,{behavior:`auto`})}else t.scrollTop=e}return!0};if(!n()){let t=xe.get(e.messageId);if(typeof t==`number`&&t<te.length)return Oe(t,`auto`)}return n()},cancelScroll:()=>{I(),ie.current?.cancelScroll()},scrollToBottom:({behavior:e=`auto`,reveal:t=!0}={})=>(t&&ce(e=>e+1),G&&te.length>0&&ie.current?(ie.current.scrollToEnd({behavior:e}),!0):!1)};if(typeof g==`function`)return g(e),()=>{g(null)};let t=g;return t.current=e,()=>{t.current=null}},[I,te.length,xe,G,ee,Se,g]),(0,$.jsx)(mA.Provider,{value:y,children:(0,$.jsx)(`div`,{children:(0,$.jsx)(sd,{disabled:!1,children:(0,$.jsxs)(`div`,{ref:ue,className:`relative w-full`,style:fe,children:[(0,$.jsx)(sd,{disabled:G,children:(0,$.jsx)(qB,{enabled:!0,children:(0,$.jsx)(SH,{entries:te,historyAnchorToken:p,engine:re,contentRef:P,scrollRef:u,registerTanstackVirtualizer:ae,virtualizerKey:v,onMessageContentChange:pe,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,activityRenderMode:S,turnUiStates:Te,onToggleTurnGroup:M,chatRenderMode:x,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be},v)})}),(0,$.jsx)(wH,{entries:W,directory:d,sessionId:_,onMessageContentChange:me,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,sessionIsWorking:r,activityRenderMode:S,turnUiStates:Te,onToggleTurnGroup:M,chatRenderMode:x,showTurnChangedFiles:C,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,activeStreamingMessageId:i,activeStreamingPhase:a}),f]})})})})});TH.displayName=`MessageList`;var EH=Z.memo(TH),DH=e=>{let t=(0,Q.c)(3),{content:n,html:r}=e,i;return t[0]!==n||t[1]!==r?(i=r===void 0?(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,children:n}):(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,dangerouslySetInnerHTML:{__html:r}}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},OH=({diff:e,filePath:t})=>{let{currentTheme:n}=Io(),r=Z.useMemo(()=>Qd(n),[n]),i=Z.useMemo(()=>Bd(e),[e]),a=ku(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6608
|
+
`),[i]),s=Vd(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)(DH,{content:e.content,html:n})})]},t)})})]},n))})},kH=e=>{let t=(0,Q.c)(21),{content:n,filePath:r}=e,{currentTheme:i}=Io(),a;t[0]===i?a=t[1]:(a=Qd(i),t[0]=i,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=n.split(`
|
|
6609
|
+
`),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=ku(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=Vd(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)(DH,{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},AH=new Set([`id`,`identifier`,`title`,`name`]),jH=e=>typeof e==`object`&&!!e&&!Array.isArray(e),MH=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),NH=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},PH=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},FH=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?`${MH(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)(FH,{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(jH(n)){let e;t[18]===n?e=t[19]:(e=NH(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(LH),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${MH(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)(FH,{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?MH(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`&&PH(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:MH(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});FH.displayName=`JsonSummaryValue`;var IH=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)(FH,{value:n,depth:0})}),t[0]=n,t[1]=r),r});IH.displayName=`JsonSummaryView`;function LH(e){let[t]=e;return!AH.has(t)}function RH(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 zH={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`},BH={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},VH=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})},HH=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},UH=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,WH=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)(IH,{data:n})}),t[0]=n,t[1]=r),r},GH=({permission:e,onResponse:t})=>{let{t:n}=fr(),r=q(e=>e.isMobile),[i,a]=Z.useState(!1),[o,s]=Z.useState(!1),c=Ja,l=yo(),u=Wa(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=HH(p),y=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[UH(e),t]));return(0,$.jsx)(RH,{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:[VH(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)($r,{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)($r,{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)($r,{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)(Fd,{language:`bash`,code:e,style:zH,codeStyle:BH.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)(ld,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(OH,{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)(ld,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(kH,{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)(ld,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(WH,{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)(ld,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(WH,{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)(ld,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(WH,{data:y})})]})})()]})})};function KH(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(`
|
|
6610
|
+
`).trimEnd()}function qH(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 JH=200;function YH(e){return Math.min(Math.max(e,40),JH)}var XH=`summary`,ZH=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=YH(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}),QH=({question:e})=>{let{t}=fr(),n=xr(e),r=Xr,i=Cr,a=q(e=>e.isMobile),o=yo(),s=Wa(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=zr(e=>e.drafts[l]?.activeTab??`0`),d=e=>Li(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),_=zr(e=>ki(e,l).selectedOptions),v=zr(e=>ki(e,l).customMode),y=zr(e=>ki(e,l).customTextFilled),b=Z.useMemo(()=>e.questions??[],[e.questions]),x=u===XH,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:XH,label:t(`chat.questionCard.summaryTab`)}),e},[b,t]),E=e=>{if(v[e])return(Hr(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=(Hr(l).customText[t]??``).trim();e.push(n?[n]:[]);continue}e.push(_[t]??[])}return e},P=J(e=>{C&&Li(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(()=>{Li(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;Li(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),Ni(i),g(!0)}catch(e){zi(e)?await n.submissionClaimed(i):ji(e)?(Ni(i),no.info(t(`chat.questionCard.noLongerPending`)),g(!0)):no.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),R=J(e=>{Mc(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),Ni(r),g(!0)}catch(e){zi(e)?await n.submissionClaimed(r):ji(e)?(Ni(r),no.info(t(`chat.questionCard.noLongerPending`)),g(!0)):no.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),B=J(async()=>{let n=KH(e);if((await Ea(n)).ok){no.success(t(`chat.questionCard.copiedMarkdown`));return}no.error(t(`chat.questionCard.copyFailed`))}),V=J(async()=>{let n=qH(e);if((await Ea(n)).ok){no.success(t(`chat.questionCard.copiedJson`));return}no.error(t(`chat.questionCard.copyFailed`))});return h||b.length===0?null:(0,$.jsxs)(RH,{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)(xo,{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===XH,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)(ZH,{value:Hr(l).customText[S]??``,onValueChange:I,placeholder:t(`chat.questionCard.yourAnswer`),disabled:m,onKeyDown:R})}):null]})]}):null]})};function $H(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 eU=({form:e,directory:t})=>{let{t:n}=fr(),r=q(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=$H(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 ja({sessionID:e.sessionID,formID:e.id,answer:c,directory:t}),Ar.getState().remove(e.sessionID,e.id)}catch{s(`reply`)}finally{a(!1)}}}),f=J(async()=>{if(!i){s(null),a(!0);try{await ui({sessionID:e.sessionID,formID:e.id,directory:t}),Ar.getState().remove(e.sessionID,e.id)}catch{s(`cancel`)}finally{a(!1)}}});return(0,$.jsxs)(RH,{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)($r,{type:`button`,variant:`default`,size:`sm`,onClick:()=>void d(),disabled:i,children:n(`chat.form.reply`)}),(0,$.jsx)($r,{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)(Qo,{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)(Qo,{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)($o,{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)($r,{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)($o,{"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)($o,{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 tU(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function nU(e){return typeof e==`string`&&e.length>0?e:void 0}function rU(e){if(!tU(e))return null;let t=nU(e.reason),n=nU(e.provider),r=nU(e.title),i=nU(e.message),a=nU(e.label);return!t||!n||!r||!i||!a?null:{reason:t,provider:n,title:r,message:i,label:a,...nU(e.link)?{link:nU(e.link)}:{}}}function iU(e){return!tU(e)||e.type!==`retry`?!1:rU(e.action)!==null}function aU(e,t){if(!iU(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 oU=Z.memo(function({scrollRef:e,active:t,showScrollToBottom:n,onScrollToBottom:r}){let i=(0,Z.useSyncExternalStore)(Aw,Ow,()=>null),{t:a}=fr(),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-stack`),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)});sr(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)($r,{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)($r,{size:`mobileIcon`,variant:`mobileGlass`,className:`pointer-events-auto${i?.following?` yuri-speech-follow-active`:``}`,"aria-pressed":i?.following,onClick:()=>{i?.following&&e.current?Mw(e.current):Nw()},"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 sU(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
6611
|
+
`)}function cU(e,t=80){let n=sU(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var lU=new Set;function uU(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(lU),a,o;return n[0]!==e||n[1]!==t?(a=()=>{let n=e?.current;if(i(lU),!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=dU,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 dU(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 fU=160,pU=28,mU=12,hU=6,gU=30,_U=12,vU=18,yU=80,bU=4,xU=10,SU=14,CU=20,wU=48,TU=160,EU=(e,t)=>e.map(e=>{let n=t.get(e)??[],r=sU(n),i=g_(r,{citationIcons:S_(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>fU?`${s.slice(0,fU)}…`:s}}),DU=[1,.6,.35,.15],OU=(e,t,n)=>{let r=n?SU:xU;if(t===null)return r;let i=DU[Math.abs(e-t)]??0;return Math.round(r+(CU-r)*i)};function kU({turnIds:e,previewsByTurnId:t,activeTurnId:n,scrollRef:r,turnByMessageId:i,repliesByTurnId:a,onSelectTurn:o,canLoadEarlier:s,isLoadingOlder:c,onLoadEarlier:l}){let{t:u}=fr(),d=uU(r,i),f=q(e=>e.isPromptNavigatorPanelOpen),p=q(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+hU+pU;x(r.left<i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let S=Z.useMemo(()=>EU(e,t),[t,e]),C=Math.min(S.length,gU),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,gU),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,gU),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)/_U),i=Math.min(N.current,gU);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,gU)),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<=vU&&D?i=-1:r>=n.height-vU&&O&&(i=1),I.current=i,i===0){V();return}F.current===null&&(F.current=window.setInterval(H,yU))},[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)},TU)},[ee]);Z.useEffect(()=>()=>{W.current!==null&&window.clearTimeout(W.current)},[]);let G=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]),ne=Z.useCallback(()=>{P.current=null,V(),te()},[te,V]),re=Z.useCallback(()=>{p(!1)},[p]),ie=Z.useCallback(e=>{if(e===null)return;let t=S[e];t&&(o(t.turnId),V(),_(null),re(),m.current?.blur())},[re,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),re(),m.current?.blur())},[j,re,L,ie,g,S.length]),se=Z.useCallback(()=>{V(),_(null),re()},[re,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/wU);if(t===0)return;de.current-=t*wU;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?t.get(fe.turnId)??[]:[],me=fe?a?.get(fe.turnId):void 0,he=Math.max(0,T-bU),ge=Math.min(S.length,E+bU),_e=S.slice(he,ge),ve=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?mU:pU}px`,height:`${C*_U}px`},onMouseMove:G,onMouseLeave:ne,onClick:ae,onKeyDown:oe,onBlur:se,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:ve?{maskImage:ve,WebkitMaskImage:ve}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${T*_U}px)`},children:_e.map((e,t)=>{let n=he+t,r=d.has(e.turnId),i=g===n,a=OU(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*_U}px`,height:`${_U}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)*_U}px`},onMouseEnter:ee,onMouseLeave:te,onMouseMove:e=>e.stopPropagation(),onClickCapture:e=>{e.preventDefault(),e.stopPropagation(),ie(g)},children:[(0,$.jsx)(`div`,{className:`line-clamp-1 font-medium leading-relaxed text-[var(--surface-foreground)] [&_.markdown-content]:contents [&_.markdown-content_p]:inline`,children:pe.some(e=>e.type===`text`&&e.text.trim())?pe.filter(e=>e.type===`text`).map((e,t)=>(0,$.jsx)(BA,{part:e,messageId:fe.turnId,messageParts:pe,isMobile:!1,variant:`preview`},`${fe.turnId}:${e.id||t}`)):k}),me?(0,$.jsx)(`div`,{className:`mt-2 line-clamp-4 [overflow-wrap:anywhere] leading-relaxed text-[var(--surface-mutedForeground)]`,children:(0,$.jsx)(nc,{content:me,enableFileReferences:!1,disableLinkSafety:!0,className:`[&_.markdown-content]:text-inherit [&_.markdown-content]:leading-relaxed [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`})}):null]}):null]})]})})}var AU=`--yuri-mobile-header-collapse`,jU=e=>e.closest(`.mobile-chat-screen`)?.querySelector(`:scope > [data-yuri-collapsible-header="true"]`)??null,MU=e=>{e.style.removeProperty(AU),delete e.dataset.yuriHeaderCollapsePhase,delete e.dataset.yuriHeaderCollapseRest},NU=(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(AU,r),n?.rest!==a&&(e.dataset.yuriHeaderCollapseRest=a),{progress:r,phase:i,rest:a}},PU=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),FU=`data-yuri-timeline-park-end`,IU=e=>{if(!e)return null;let t=e.getAttribute(FU);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},LU=(e,t)=>t!==null&&Number.isFinite(t)?PU({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),RU=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),zU=()=>{let e=document.documentElement;return e.classList.contains(`yuri-keyboard-open`)||e.classList.contains(`yuri-kb-animating`)},BU=e=>{if(zU()||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)},VU=e=>{let t=Z.useRef(eO()),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=vO(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=jU(e),y.current=n,b.current=void 0),n&&(b.current=NU(n,t,b.current))},S=J(t=>{let r=e.scopeRef.current;if(!r)return;let i=v(r);n.current=xO(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=fO(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(iO(t.current,BU(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=dO(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=RU(t);p.current=e,f.current=LU(e,IU(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=BU(o),l=RU(n),_=LU(l,IU(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=bO(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=iO(N,s);if(s||(P=lO(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(()=>{h.current&&(g(i),s.current=!1,o.current=0,O(),j(),P(),w(aO(t.current,`expanded`)),T())}),B=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)}),V=J(t=>{if(!h.current)return;let n=t.target;if(!(n instanceof Element)||!n.closest(`[data-yuri-composer-compact-surface="true"]`)||n.closest(`[data-composer-action="true"]`))return;let r=n.closest(`.yuri-mobile-composer-compact-preview`);t.type===`pointerdown`&&r||t.type===`click`&&!r||(`preventDefault`in t&&t.preventDefault(),`stopPropagation`in t&&t.stopPropagation(),z(),B(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0}))}),[H,U]=Z.useState(null),[W,ee]=Z.useState(null),te=Z.useRef(null),G=J(e=>{e&&yO(e,_.current??e),y.current&&MU(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(eO())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;te.current&&te.current!==n&&G(te.current),te.current=n,n&&C(n),U(e=>e===t?e:t),ee(e=>e===n?e:n)});let ne=Z.useMemo(()=>()=>void 0,[]),re=e.enabled&&H?H:ne,ie=e.enabled&&W?W:ne,ae=e.enabled&&typeof window<`u`?window:ne,oe=Z.useMemo(()=>({passive:!0}),[]);return ir(`scroll`,P,re,oe),ir(`scrollend`,F,re,oe),Z.useEffect(()=>{if(!e.enabled||!H)return;let t={passive:!0,capture:!0};return H.addEventListener(`touchstart`,N,t),H.addEventListener(`touchmove`,M,t),H.addEventListener(`touchend`,L,t),H.addEventListener(`touchcancel`,R,t),()=>{H.removeEventListener(`touchstart`,N,t),H.removeEventListener(`touchmove`,M,t),H.removeEventListener(`touchend`,L,t),H.removeEventListener(`touchcancel`,R,t)}},[e.enabled,H]),ir(`pointerdown`,V,ie),ir(`click`,V,ie),ir(`focusin`,E,ie),ir(`focusout`,E,ie),ir(`yuri:keyboard-intent`,E,ae),ir(`yuri:keyboard-anim`,E,ae),ir(`yuri:keyboard-settled`,E,ae),Z.useEffect(()=>{if(!e.enabled){G(te.current),te.current=null;return}return E(),P(),()=>{g(i),g(a)}},[e.enabled,H,W]),z},HU=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},UU=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},WU=e=>{if(!e)return null;let t=HU(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${UU(e)??``}`},GU=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}),KU=(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&&WU(t[r])===WU(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=HU(r),a=r.info.id,o=GU(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=UU(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},qU=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=HU(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=UU(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}},JU=200,YU={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},XU=()=>JU,ZU=()=>Math.round(XU()*.6),QU={MAX_SESSIONS:YU.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(JU*.6),HISTORICAL_MESSAGES:JU,FETCH_BUFFER:20,HISTORY_CHUNK:JU,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:YU.ZOMBIE_TIMEOUT},$U=()=>{let e=XU(),t=ZU();return{...QU,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},eW=QU,tW=600,nW=6e3,rW=.5,iW=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),aW=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},oW=(e,t)=>{let n=iW(e,t);if(n||=aW(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}},sW=e=>{let{container:t,quiesceMs:n=tW,maxLifetimeMs:r=nW}=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=oW(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)>rW){_();return}let n=iW(t,i.messageId);if(!n){let e=aW(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)>rW&&(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)>rW)&&_(),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())}}},cW=30,lW=1200,uW=1.5,dW=e=>Math.max(lW,e*uW),fW=4,pW=30,mW=4,hW=30,gW=250,_W=800,vW=1e4,yW=1500,bW=2e3,xW=wa+2e3,SW=40,CW=`history-loading-timeout`,wW=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),TW=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=CW,e},EW=(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)},DW=2500,OW=new Map,kW=()=>E()?fW:vi()?mW:cW,AW=e=>E()?e.length<=pW:!vi()||e.length<=hW,jW=(e,t)=>{if(OW.delete(e),!AW(t.messages))return;let n=kW();for(;OW.size>=n;){let e=OW.keys().next().value;if(typeof e!=`string`)break;OW.delete(e)}OW.set(e,t)},MW=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),NW=e=>e?{owner:`tanstack-core`}:{owner:`controller`},PW=(e,t)=>e?e.canLoadEarlier:t>=$U().HISTORICAL_MESSAGES,FW=e=>!(e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=dW(e.clientHeight)),IW=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`,LW=8,RW=1,zW=8,BW=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],VW=80,HW=new WeakMap,UW=e=>{let t=e?HW.get(e):void 0;return!!(t&&(t.touches>0||performance.now()-t.lastScrollAt<160))},WW=e=>{let t=HW.get(e);t&&(t.touches=0,t.lastScrollAt=-1/0,t.pending=null,t.settleScheduled=!1)},GW=e=>{KW(e)},KW=e=>{let t=HW.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&&qW(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),e.addEventListener(`scroll`,()=>{n.lastScrollAt=performance.now()},{passive:!0}),HW.set(e,n),n},qW=(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+VW||JW(e,n.anchorTop+n.delta))}))},JW=(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},YW=(e,t,n)=>{let r=KW(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,JW(e,t)},XW=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),ZW=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:a,loadMoreMessages:o,goToBottom:s,releaseAutoFollow:c,beginHistoryViewportPreservation:l,endHistoryViewportPreservation:u,isPinned:d,showScrollButton:p,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?OW.get(t):void 0;if(r&&r.messages===n)return jW(t,r),v.current=r.model,y.current=n,r.model;let i=KU(v.current,y.current,n)??qU(n);return v.current=i,y.current=n,t&&n.length>0&&jW(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=m(),k=f(),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])}`;cr(()=>(j.current=A,()=>{j.current===A&&(j.current=null),no.dismiss(M)}),[A,M]);let N=Z.useRef(b),P=Z.useRef(d),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),G=Z.useRef(null),ne=Z.useRef({authorized:!1,consumed:!1,top:0}),re=Z.useRef(null),ie=J(()=>{ne.current={authorized:!1,consumed:F.current,top:i.current?.scrollTop??0}}),ae=()=>h?i.current??void 0:void 0,oe=J(e=>{e.repeat||ie()});ir(`touchstart`,ie,ae,{passive:!0,capture:!0}),ir(`wheel`,ie,ae,{passive:!0,capture:!0}),ir(`keydown`,oe,ae,{capture:!0});let[se,ce]=Z.useState(A);se!==A&&(ce(A),G.current!==null&&typeof window<`u`&&(window.clearTimeout(G.current),G.current=null),te.current=!1,F.current=!1,ee.current=null,S(!1),w(!1),E(null),D.current=0,ne.current={authorized:!1,consumed:!1,top:0},re.current=null);let le=Z.useMemo(()=>{let e=PW(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),ue=Z.useRef(le);N.current=b,P.current=d,I.current=C,ue.current=le,L.current=e,R.current=t??null,z.current=n,B.current=r,cr(()=>{r?.complete&&no.dismiss(M)},[r?.complete,M]);let de=J(()=>{te.current=!0,G.current!==null&&typeof window<`u`&&(window.clearTimeout(G.current),G.current=null)}),fe=J(()=>{if(typeof window>`u`){te.current=!1;return}G.current!==null&&window.clearTimeout(G.current),G.current=window.setTimeout(()=>{G.current=null,te.current=!1},bW)}),pe=J(()=>{let e=V.current;e.length!==0&&(V.current=[],e.forEach(e=>e()))}),me=J((e=!1)=>new Promise(t=>{if(typeof window>`u`){t();return}let n=!1,r=j.current,i=Date.now()+vW,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,gW)})),he=J(e=>{let t=W.current;t&&(W.current=null,t.resolve(e))}),ge=J(()=>{let e=W.current;if(e){if(e.sessionId!==L.current){he(!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()+DW},E(e.turnId)),he(!0);return}typeof(e.kind===`turn`?N.current.turnIndexById.get(e.id):N.current.messageToTurnIndex.get(e.id))==`number`&&he(!1)}}),_e=Z.useRef(null),ve=J(()=>{let e=_e.current;e&&(_e.current=null,e.dispose())});rr(()=>{G.current!==null&&typeof window<`u`&&(window.clearTimeout(G.current),G.current=null),ve(),pe(),he(!1)});let ye=Z.useRef({scope:A,at:-1/0}),be=()=>{!h&&!vi()&&(ye.current={scope:A,at:Date.now()})};ir(`wheel`,e=>{e.deltaY!==0&&e.target instanceof Node&&i.current?.contains(e.target)&&be()},void 0,{passive:!0,capture:!0}),ir(`scroll`,e=>{e.target===i.current&&be()},void 0,{passive:!0,capture:!0});let xe=()=>ye.current.scope===A&&Date.now()-ye.current.at<_W,[Se,Ce]=Z.useState({scope:A,messages:n}),we=vi(),Te=Se.scope===A&&Se.messages!==n&&XW(Se.messages[0]?.info?.id??null,n[0]?.info?.id??null,n)&&(we?UW(i.current):!h&&Se.messages.at(-1)===n.at(-1)&&xe()),Ee=Te?Se.messages:n;H.current=Te,(Se.scope!==A||Se.messages!==Ee)&&Ce({scope:A,messages:Ee});let[,De]=Z.useReducer(e=>e+1,0);cr(()=>{pe(),ge()},[Ee]);let Oe=Z.useRef(null),ke=J(()=>a.current?.captureViewportAnchor()??null),Ae=J(e=>a.current?.restoreViewportAnchor(e)??!1),je=J(()=>{if(ve(),a.current?.isHistoryVirtualized())return;let e=i.current;if(!e)return;let t=ke();if(t)return _e.current=sW({container:e,anchor:t,pending:!0,isUserScrolling:vi()?()=>UW(e):void 0}),_e.current}),Me=Z.useRef(null);or(J(()=>{let e=i.current;if(!e||!Te||!we&&xe())return;let t=e.scrollHeight;Me.current={oldestId:Ee[0]?.info?.id??null,newestId:Ee.at(-1)?.info?.id??null,scrollHeight:t};let n=Oe.current;if(n){let r={...n,height:t,top:e.scrollTop,anchor:ke()};Oe.current=Object.assign(n,r)}De()}),Te?50:null);let Ne=Z.useRef(null);cr(()=>{if(!vi())return;let e=i.current;if(!e){Ne.current=null;return}let t=Ne.current;(t?.container!==e||t.scope!==A)&&(GW(e),WW(e),Ne.current={container:e,scope:A})}),cr(()=>{ve(),U.current=null,pe(),Oe.current=null,Me.current=null,a.current?.cancelViewportAnchorHold()},[A]),cr(()=>{let e=i.current;if(!e)return;let t=Oe.current;a.current?.isHistoryVirtualized()&&ve(),t&&Math.abs(e.scrollTop-t.top)>zW&&(Oe.current=null,t=null);let n=Me.current,r=Ee[0]?.info?.id??null,o=Ee[Ee.length-1]?.info?.id??null,c=n?MW({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:o})||XW(n.oldestId,r,Ee):!1;t&&t.sessionId!==L.current&&(Oe.current=null,t=null);let l=t?MW({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:o})||XW(t.oldestId,r,Ee):!1,u=c||l,d=e=>{Me.current={oldestId:r,newestId:o,scrollHeight:e??Me.current?.scrollHeight??null}};if(P.current&&!t){ve(),u?(Oe.current=null,s(`instant`,{reveal:!1}),d(e.scrollHeight)):d();return}let f=NW(a.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){a.current?.cancelViewportAnchorHold();let e=t.anchor;e&&Ae(e),d();return}let n=e.scrollHeight,r=n-t.height;if(vi()){r>0&&YW(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&Ae(i))&&r>0&&(e.scrollTop=t.top+r),_e.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;vi()?YW(e,t,r):e.scrollTop=t}d(t),je();return}d()},[Ee,s]),cr(()=>{if(H.current)return;let e=U.current;U.current=null,e?.()},[Ee]);let Pe=J(async()=>!1),Fe=J(async e=>{let t=j.current,n=()=>t===j.current&&t?.runtimeKey===m()&&t?.runtimeGeneration===f(),r=Date.now(),i=r+xW,a=R.current,o=a?Ut()?.getRequestState?.(mt(a,e)):void 0;for(ue.current.historyLoading,B.current,o?.status,o?.error;ue.current.historyLoading;){if(!n()||L.current!==e)return Date.now()-r,`switched`;if(Date.now()>=i){let t=a?Ut()?.getRequestState?.(mt(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:xW,hostTurnPageTimeoutMs:wa,historyLoading:ue.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,SW)})}return Date.now()-r,a&&Ut()?.getRequestState?.(mt(a,e))?.status,n()&&L.current===e?`cleared`:`switched`}),Ie=J(async e=>{if(!L.current||F.current||H.current||!ue.current.hasMoreAboveTurns)return!1;F.current=!0,de(),S(!0);let t=L.current,n=j.current,r=()=>n===j.current&&n?.runtimeKey===m()&&n?.runtimeGeneration===f(),s=()=>n?.directory?Ut()?.getPagination(mt(n.directory,t)).cursor??null:null,c=M,d=()=>{r()&&(F.current=!1,S(!1),fe())},p=null,h=null,g=!!e.userInitiated;g&&l();let _=()=>{if(r()){if(H.current){U.current=_;return}h?.settle(),p&&Oe.current===p&&(Oe.current=null,a.current?.cancelViewportAnchorHold()),g&&(g=!1,u())}};try{if(ue.current.historyLoading){if(!e.userInitiated)return!1;let n=await Fe(t);if(n===`timeout`)throw TW();if(n===`switched`||!ue.current.hasMoreAboveTurns)return!1}if(!r()||!L.current||L.current!==t)return!1;let n=i.current,a=z.current,l=a.length,u=a[0]?.info?.id??null,d=B.current?.limit??$U().HISTORICAL_MESSAGES;e.preserveViewport&&n&&(p={sessionId:L.current,height:n.scrollHeight,top:n.scrollTop,anchor:ke(),oldestId:u,newestId:a[a.length-1]?.info?.id??null},Oe.current=p,Me.current={oldestId:p.oldestId,newestId:p.newestId,scrollHeight:p.height},h=je()??null);let f=l,m=u,g=d,v=0,y=0;for(;;){if(ue.current.historyLoading)if(e.userInitiated){let e=await Fe(t);if(e===`timeout`)throw _(),TW();if(e===`switched`)return _(),!1}else return _(),!1;let n=i.current?.scrollHeight??0,a=f,l=m,u=g,d=s();if(await o(t,`up`),v+=1,!r()||L.current!==t)return _(),!1;if(await me(!0),!r())return!1;if(H.current)return!0;let p=(()=>{let t=z.current;return IW({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:a,messageCountAfter:t.length,oldestIdBefore:l,oldestIdAfter:t[0]?.info?.id??null,limitBefore:u,limitAfter:B.current?.limit??g,cursorBefore:d,cursorAfter:s(),hasMoreAbove:ue.current.hasMoreAboveTurns,pagesLoaded:v,maxPages:e.singlePage?1:LW})})();if(p===`continue`){let e=z.current;f=e.length,m=e[0]?.info?.id??null,g=B.current?.limit??g;continue}if(p===`stop-no-growth`){if(e.singlePage)return _(),!1;if(ue.current.historyLoading){if(e.userInitiated){let e=await Fe(t);if(e===`timeout`)throw _(),TW();if(e===`switched`)return _(),!1;--v;continue}return _(),!1}if(y<RW){y+=1,--v;continue}return D.current=Date.now()+yW,_(),!1}return D.current=0,no.dismiss(c),!0}}catch(e){throw r()&&(D.current=Date.now()+yW),_(),e}finally{r()&&(H.current?U.current=()=>{d(),_()}:(d(),me(!0).then(_)))}}),{t:Le}=fr(),Re=An({mutationKey:BW({runtimeKey:m(),sessionId:e??``}),mutationFn:async e=>{if(j.current!==e.scope||m()!==e.scope.runtimeKey||f()!==e.scope.runtimeGeneration||L.current!==e.sessionId)return!1;de(),e.userInitiated&&c();try{return await Ie({preserveViewport:!0,userInitiated:!!e.userInitiated,singlePage:e.singlePage})}finally{j.current===e.scope&&f()===e.scope.runtimeGeneration&&fe()}}}),ze=J(async e=>{let t=L.current;if(!t||!ue.current.canLoadEarlier)return;let n=A,r=M,i=()=>j.current===n&&m()===n.runtimeKey&&f()===n.runtimeGeneration;if(!(Re.isPending&&Re.variables?.sessionId===t&&Re.variables?.scope===n)){e?.userInitiated&&g?.();try{let r=await Re.mutateAsync({sessionId:t,scope:n,userInitiated:!!e?.userInitiated,singlePage:e?.singlePage});if(!i())return;if(r===!1&&ue.current.canLoadEarlier){let n={sessionId:t,grew:r,userInitiated:!!e?.userInitiated,canLoadEarlier:ue.current.canLoadEarlier,hasMoreAboveTurns:ue.current.hasMoreAboveTurns,historyLoading:ue.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};EW(`no-growth`,Error(`chat history pagination returned no growth`),n)}}catch(n){let a={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:xW,hostTurnPageTimeoutMs:wa,canLoadEarlier:ue.current.canLoadEarlier,historyLoading:ue.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};wW(n)?EW(`timeout`,n,a):EW(`failed`,n,a),i()&&e?.userInitiated&&no.error(wW(n)?Le(`chat.history.loadOlderTimeout`):Le(`chat.history.loadOlderFailed`),{id:r})}}}),Be=Re.isPending&&Re.variables?.sessionId===e&&Re.variables?.scope===A||x,Ve=J(e=>{if(Date.now()<D.current)return;let t=i.current;if(t){if(_.current){let n=ne.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){re.current=null;return}else if(e===`upward-intent`)re.current={top:t.scrollTop};else{let e=re.current;if(!e)return;let n=t.scrollTop<e.top;if(t.scrollTop>e.top||P.current?re.current=null:e.top=t.scrollTop,!n)return}FW({source:e,isMobile:_.current,isPinned:P.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:ue.current.canLoadEarlier,isLoadingOlder:F.current,pendingRevealWork:I.current})&&(_.current&&(ne.current.consumed=!0),re.current=null,ze({userInitiated:!0,singlePage:_.current}))}}),He=J(()=>{Ve(`scroll`)}),Ue=J(()=>{!_.current&&!F.current&&!a.current?.isHistoryVirtualized()&&je()?.settle(),Ve(`upward-intent`)}),We=J(async(t,n)=>{if(!t||!L.current)return!1;c(),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},ge()})}finally{w(!1)}}),Ge=Z.useRef(null),Ke=J(async(t,n)=>{if(!t||!L.current)return!1;let r=`${L.current}:${t}`;if(Ge.current===r)return!1;Ge.current=r;let i=L.current;c(),w(!0);try{if(L.current!==e)return!1;for(;!N.current.messageToTurnId.has(t)&&ue.current.hasMoreAboveTurns;){if(L.current!==i||Ge.current!==r)return!1;let e=z.current[0]?.info.id;if(await ze({userInitiated:!0,singlePage:!0}),await me(),z.current[0]?.info.id===e)break}if(L.current!==i||Ge.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},ge()})}finally{Ge.current===r&&(Ge.current=null),w(!1)}}),qe=J(async()=>{Ge.current=null,w(!1),F.current=!1,S(!1),s(`smooth`)}),Je=J(async()=>{w(!1),F.current=!1,S(!1),s(`instant`)}),Ye=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:Ee,historySignals:le,isLoadingOlder:Be,pendingRevealWork:C,activeTurnId:T,showScrollToBottom:p&&!C,turnWindowModel:b,loadEarlier:ze,revealBufferedTurns:Pe,resumeToBottom:qe,resumeToBottomInstant:Je,scrollToTurn:We,scrollToMessage:Ke,handleHistoryScroll:He,handleHistoryUpwardIntent:Ue,captureViewportAnchor:ke,restoreViewportAnchor:Ae,handleActiveTurnChange:Ye}},QW=12,$W=50,eG=800;function tG(e){let t=(0,Q.c)(25),{scope:n,enabled:r,cursor:i,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]!==i||t[2]!==r||t[3]!==o||t[4]!==n?(h=r&&!a()&&i!==null&&o<QW&&u!==n,t[0]=u,t[1]=i,t[2]=r,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]!==i||t[11]!==g||t[12]!==s||t[13]!==n?(b=[n,g,i,s],t[10]=i,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],ir(`wheel`,x,void 0,S);let C;t[19]!==i||t[20]!==g||t[21]!==l||t[22]!==n||t[23]!==c?(C=()=>{let e=c.current;if(f.current===n)return;if(!g||a()||!i||!e||p.current||document.visibilityState===`hidden`){m.current=null;return}let t=e.scrollHeight,r=e.scrollTop,o=m.current;if(!o||o.height!==t||o.top!==r){m.current={height:t,top:r,since:Date.now()};return}Date.now()-o.since<eG||(f.current=n,d(n),p.current=!0,l($W).catch(nG).finally(()=>{p.current=!1}))},t[19]=i,t[20]=g,t[21]=l,t[22]=n,t[23]=c,t[24]=C):C=t[24],or(J(C),g?200:null)}function nG(e){console.error(`[chat-history] desktop history warmup failed`,e)}var rG=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),iG=({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}=fr(),{isMobile:f}=Us(),[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)(aG,{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)(sc,{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)(Ko,{open:e,onOpenChange:t,children:(0,$.jsx)(Ho,{presentation:`picker`,className:`yuri-timeline-dialog`,children:S})})},aG=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}=fr(),b=Zb(),x=i,S=ca(x??``,a),C=Wa(sG),w=Wa(cG),T;t[0]===b.capabilities?T=t[1]:(T=rG(b.capabilities),t[0]=b.capabilities,t[1]=T);let E=T,{isMobile:D,isTablet:O}=Us(),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=lG,L=uG,R;t[3]===S?R=t[4]:(R=S.filter(dG).map(fG),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 sU(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,G;t[19]===h?(te=t[20],G=t[21]):(G=()=>{P.current||j.current[h]?.scrollIntoView({block:`nearest`})},te=[h],t[19]=h,t[20]=te,t[21]=G),Z.useEffect(G,te);let ne;t[22]===u?ne=t[23]:(ne=()=>{!P.current||N.current||u||(P.current=!1)},t[22]=u,t[23]=ne);let re;t[24]!==V.length||t[25]!==u?(re=[V.length,u],t[24]=V.length,t[25]=u,t[26]=re):re=t[26],Z.useEffect(ne,re);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)(Bo,{className:`yuri-timeline-header`,children:(0,$.jsx)(Uo,{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)($o,{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)($r,{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=cU(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()?oG(sU(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)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{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)(ts,{sideOffset:6,children:y(`chat.timeline.actions.revertFromHere`)})]}):null,E.fork?(0,$.jsxs)(ns,{children:[(0,$.jsx)(es,{asChild:!0,children:(0,$.jsx)($r,{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)(ts,{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)(ld,{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)($r,{type:`button`,variant:`ghost`,size:`xs`,disabled:_!==null,onClick:()=>{s?.(-1),r(!1)},children:y(`chat.timeline.actions.previousTurn`)}):null,c?(0,$.jsx)($r,{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 oG(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 sG(e){return e.revertToMessage}function cG(e){return e.forkFromMessage}function lG(e){return Ad(e)}function uG(e){return hd(e)}function dG(e){return e.info.role===`user`}function fG(e){return{message:e}}function pG(e){let t=(0,Q.c)(40),{messages:n,enabled:r,canOpen:i,onNavigate:a,children:o}=e,{t:s}=fr(),[c,l]=Z.useState(!1),[u,d]=Z.useState(``),f=Z.useDeferredValue(u),[p,m]=Z.useState(0),[h,g]=Z.useState(0);!r&&c&&l(!1);let _=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),b=r&&c,x;t[0]!==f||t[1]!==b?(x=b?CA(f):null,t[0]=f,t[1]=b,t[2]=x):x=t[2];let S=x,C;t[3]!==n||t[4]!==S?(C=S?.(n)??[],t[3]=n,t[4]=S,t[5]=C):C=t[5];let w=C,T=Math.min(p,Math.max(0,w.length-1)),E=b&&u===f?w[T]??null:null,D=E?.messageId,O=E?.partId,k=E?.occurrence,A=E?.query,j;t[6]!==A||t[7]!==D||t[8]!==h||t[9]!==k||t[10]!==O?(j=D!==void 0&&O!==void 0&&k!==void 0&&A!==void 0?{messageId:D,partId:O,occurrence:k,query:A,navigationId:h}:null,t[6]=A,t[7]=D,t[8]=h,t[9]=k,t[10]=O,t[11]=j):j=t[11];let M=j,N;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(N=()=>{l(!1),y.current?.isConnected&&y.current.focus({preventScroll:!0})},t[12]=N):N=t[12];let P=J(N),F;t[13]!==a||t[14]!==w.length||t[15]!==T?(F=e=>{w.length&&(a(),m((T+e+w.length)%w.length),g(mG))},t[13]=a,t[14]=w.length,t[15]=T,t[16]=F):F=t[16];let I=J(F),L;t[17]!==i||t[18]!==P||t[19]!==r||t[20]!==a||t[21]!==b?(L=e=>{!r||e.defaultPrevented||e.isComposing||!(e.target instanceof Node&&v.current?.contains(e.target))&&!i(e)||((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`f`?(e.preventDefault(),e.stopPropagation(),b?(_.current?.focus({preventScroll:!0}),_.current?.select()):(y.current=document.activeElement instanceof HTMLElement?document.activeElement:null,a(),l(!0))):b&&e.key===`Escape`&&(e.preventDefault(),P()))},t[17]=i,t[18]=P,t[19]=r,t[20]=a,t[21]=b,t[22]=L):L=t[22],ir(`keydown`,L);let R,z;t[23]===b?(R=t[24],z=t[25]):(R=()=>{b&&_.current?.focus({preventScroll:!0})},z=[b],t[23]=b,t[24]=R,t[25]=z),Z.useEffect(R,z);let B;t[26]!==P||t[27]!==f||t[28]!==I||t[29]!==a||t[30]!==u||t[31]!==w.length||t[32]!==T||t[33]!==s||t[34]!==b?(B=b&&(0,$.jsxs)(`div`,{ref:v,role:`search`,"aria-label":s(`chat.find.label`),className:`yuri-transcript-find yuri-mobile-overlay-surface yuri-popup-surface absolute right-3 top-3 z-30 w-[min(22rem,calc(100%-1.5rem))] overflow-hidden rounded-2xl`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,children:[(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 text-foreground`}),(0,$.jsx)($o,{ref:_,bordered:!1,value:u,"aria-label":s(`chat.find.label`),placeholder:s(`chat.find.label`),onChange:e=>{a(),d(e.target.value),m(0)},onKeyDown:e=>{e.nativeEvent.isComposing||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),P()):e.key===`Enter`&&(e.preventDefault(),I(e.shiftKey?-1:1)))}}),(0,$.jsx)(`div`,{className:`yuri-transcript-find-close pl-1.5`,children:(0,$.jsx)($r,{variant:`ghost`,size:`icon`,"aria-label":s(`chat.find.close`),onClick:P,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})})]}),(0,$.jsxs)(`div`,{className:`yuri-transcript-find-navigation flex items-center gap-0.5 px-2 py-0.5`,children:[(0,$.jsx)($r,{variant:`ghost`,size:`icon`,disabled:!w.length||u!==f,"aria-label":s(`chat.find.previous`),onClick:()=>I(-1),children:(0,$.jsx)(X,{name:`arrow-up`,className:`size-4`})}),(0,$.jsx)($r,{variant:`ghost`,size:`icon`,disabled:!w.length||u!==f,"aria-label":s(`chat.find.next`),onClick:()=>I(1),children:(0,$.jsx)(X,{name:`arrow-down`,className:`size-4`})}),(0,$.jsx)(`span`,{className:`ml-auto pr-2 typography-meta tabular-nums text-muted-foreground`,role:`status`,"aria-live":`polite`,children:s(`chat.find.count`,{current:w.length?T+1:0,total:w.length})})]})]}),t[26]=P,t[27]=f,t[28]=I,t[29]=a,t[30]=u,t[31]=w.length,t[32]=T,t[33]=s,t[34]=b,t[35]=B):B=t[35];let V;return t[36]!==o||t[37]!==B||t[38]!==M?(V=(0,$.jsxs)(_A.Provider,{value:M,children:[o,B]}),t[36]=o,t[37]=B,t[38]=M,t[39]=V):V=t[39],V}function mG(e){return e+1}var hG=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},gG=(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`}},_G=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`))},vG=e=>{e&&_G(`message-${e}`)},yG=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&&_G(`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&&_G(`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=gG(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 _G(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=()=>{_G(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=hG(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},bG=2e4,xG=6e4,SG=2e3,CG=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,wG=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+=CG(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},TG={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},EG=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:TG,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}},DG=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function OG(e){return!!(e.active&&e.sessionId&&e.sessionKey&&e.sessionIsWorking)}function kG(e){return e===TG?e:TG}function AG(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 jG(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 MG(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||AG(i)==null}function NG(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!MG(n))continue;let e=jG(n);e&&t.push(e)}}return t}function PG(e,t){return`${e}:${t.join(`,`)}`}function FG(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=PG(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function IG(e,t,n,r){let i=(0,Q.c)(7),a=Mi(),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=FG({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:NG(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,ri(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 LG=[0,200,400],RG=e=>{let t=(0,Q.c)(5),{className:n}=e,r;t[0]===n?r=t[1]:(r=Y(`inline-flex`,n),t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=LG.map(zG),t[2]=i):i=t[2];let a;return t[3]===r?a=t[4]:(a=(0,$.jsxs)($.Fragment,{children:[`\xA0`,(0,$.jsx)(`span`,{className:r,"aria-hidden":`true`,children:i})]}),t[3]=r,t[4]=a),a};function zG(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var BG=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),VG=(e,t)=>({...e,key:HG(e),estimatedBytes:BG(t)}),HG=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),UG=e=>({key:e?HG(e):null,selection:e}),WG=(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},GG=(e,t,n,r)=>{let i=HG(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return WG(e,i,n);let s=o||VG(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),WG(c,i,n)},KG=(e,t,n)=>{let r=BG(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)},qG=(e,t)=>t&&e.some(e=>e.key===t)?t:null,JG=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?GG(e.cachedSessionViews,t.selection,n,r.estimatedBytes):WG(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}},YG=(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:VG(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},XG=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:GG(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},ZG=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},QG=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},$G=e=>QG(e)?.role===`assistant`,eK=(e,t)=>{let n=QG(t);n&&(e.agentName??=ZG(n.agent),e.providerId??=ZG(n.providerID),e.modelId??=ZG(n.modelID))},tK=e=>!!(e.agentName&&e.providerId&&e.modelId),nK=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!$G(r))&&(eK(t,r),tK(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||$G(r))&&(eK(t,r),tK(t)))break}return t},rK=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),iK=[],aK=[],oK=[],sK={type:`idle`},cK=`yuri:chat-force-scroll-bottom`,lK=()=>void 0,uK=`Quota limit reached. Retrying automatically.`,dK=1048576,fK=dK,pK=20,mK=dK,hK=16*dK,gK={maxEntries:3,maxEstimatedBytes:32*dK},_K={maxEntries:2,maxEstimatedBytes:32*dK},vK=e=>c(()=>e()),yK={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},bK=()=>{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},xK=[`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(xK):!1,wK=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||CK(e)?!0:!t?.contains(e),TK=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=q.getState();return e||t||n||r||i||a||o},EK=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}=fr(),I=Z.useContext(_A),L=J(()=>{I||v()}),R=Uk({isLoadingOlder:d}),[z,B]=Z.useState({sessionId:e,directory:a,reserved:T}),V=z.sessionId===e&&z.directory===a,H=V&&z.reserved||T;(!V||z.reserved!==H)&&B({sessionId:e,directory:a,reserved:H});let U=Wk({isMobile:r,isLoadingOlder:R})?(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,W=r&&H?(0,$.jsx)(`div`,{className:Y(`flex justify-center pt-3 pb-4`,!R&&`invisible`),"aria-hidden":!R,children:(0,$.jsxs)(`span`,{role:`status`,className:`flex items-center gap-1.5 text-[var(--surface-mutedForeground)] opacity-60`,"aria-busy":R,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,ee=Z.useRef(new Map),te=Z.useRef(new WeakMap),G=Z.useRef(new Map),ne=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(vR(n)){let r=xR(u,t)??``,i=G.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`}];G.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(Pr(n.parts))continue;let r=te.current.get(n.parts);r||(r=Fk(n.parts),te.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=ee.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 ee.current=e,e},[u]),re=Z.useMemo(()=>E.filter(e=>ne.has(e)),[ne,E]),ie=Z.useRef(new Map),ae=Z.useMemo(()=>{let e=new Map,t=new Map,n;for(let r of u){if(r.info.role===`user`){ne.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=sU(r.parts).trim();o&&t.set(a,o.slice(0,600))}let r=ie.current;return(r.size!==e.size||[...e].some(([e,t])=>r.get(e)!==t))&&(ie.current=e),{owners:ie.current,replies:t}},[ne,u]),oe=Z.useMemo(()=>{if(!D||ne.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(ne.has(e))return e}return null},[D,ne,E]),se=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)(ud,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:yK,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:se,onScroll:L,"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:[W,U,(0,$.jsx)(EH,{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)(fz,{})}):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)(QH,{question:e},e.id)),x.map(e=>(0,$.jsx)(GH,{permission:e},e.id)),S.map(e=>(0,$.jsx)(eU,{form:e,directory:a},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?UT:HT},"aria-hidden":`true`})]})}),(0,$.jsx)(cd,{containerRef:o,suppressVisibility:w,userIntentOnly:!0,observeMutations:!1}),k&&re.length>=2?(0,$.jsx)(kU,{turnIds:re,previewsByTurnId:ne,scrollRef:o,turnByMessageId:ae.owners,repliesByTurnId:ae.replies,activeTurnId:oe,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);EK.displayName=`ChatViewport`;var DK=[{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%]`]}],OK=e=>Wi(e.path),kK=(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)]})},AK=e=>{let t=Math.ceil(Math.max(0,e)/pK);return Math.min(hK,fK+t*mK)},jK=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:u,warning:d=null,pendingUserMessages:f=aK,onPendingUserMessagesMaterialized:p,committedDraftHandoffMessageId:h=null})=>{let g=c??Jk(void 0),{t:_}=fr();cr(()=>{ya()},[]);let v=Wa(e=>e.openNewSessionDraft),y=Wa(e=>e.setCurrentSession),b=Wa(e=>e.newSessionDraft),x=Wa(e=>e.newSessionDraft.draftSubmitting??!1),S=Wa(e=>e.newSessionDraft.draftEstablishing??!1),C=Wa(e=>e.forkTransition),w=Mr(e=>e.projects),T=Mr(e=>e.activeProjectId),D=ei(e=>e.providers),O=ch(),k=ia(),A=i??k;cr(()=>{!n||!r||!A||di(A,r)},[n,r,A]);let j=J(e=>O.ensureSessionRenderable(e,{directory:A})),M=q(e=>e.isExpandedInput),N=q(e=>e.stickyUserHeader),P=q(e=>e.promptNavigatorEnabled),F=q(e=>e.allowPromptingSubagentSessions),I=q(e=>e.isTimelineDialogOpen),L=q(e=>e.setTimelineDialogOpen),R=ka(e=>n&&r?e.streamingMessageIds.get(r)??null:null),z=ka(e=>R?e.messageStreamStates.get(R)?.phase??null:null),B=Ua(r??``,A),V=AK(B);Z.useEffect(()=>{!a||!o||o(a,V)},[o,V,a]);let H=ta(r??``,A).renderable,U=hr(r,A),W=Vr(r),ee=U??W,te=wx({sessionId:r,hasSessionEntity:!!ee,hasRenderableSessionSnapshot:H,composerSurfaceKind:s?.kind}),G=r?JSON.stringify([A,r]):null,[ne,re]=Z.useState({key:G,attempt:0}),ie=ca(r??``,A,{suspendPartUpdates:!!R,suspendPartUpdatesForMessageId:R,enabled:n}),ae=r?ie:iK,oe=b.pendingUserMessage,se=Wa(e=>r?e.retainedPendingUserMessages.get(r):void 0)??aK,ce=!!(h||se.length>0),le=Wa(e=>e.clearRetainedPendingUserMessages),ue=Z.useMemo(()=>{if(se.length===0)return f;if(f.length===0)return se;let e=new Set(f.map(e=>e.info.id));return[...f,...se.filter(t=>!e.has(t.info.id))]},[f,se]),de=Z.useMemo(()=>nK(ae),[ae]),fe=Z.useMemo(()=>{if(!de.modelId)return _(`common.unavailable`);let e=D.find(e=>e.id===de.providerId);return Ki(e,de.modelId)||de.modelId},[D,de.modelId,de.providerId,_]),pe=eo(r??``,A),me=Xi(r??``,A),[he,ge]=Z.useState(null),_e=!!r&&he===r,ve=J(()=>{if(!r||_e)return;let e=r,t=A;ge(e);let n=wr(()=>{let n=Ut();if(!n)throw Error(`unbound`);return n.getTranscript(mt(t,e))});na(wi({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:pe?{sessionID:e,status:pe.status===`ready`?`ready`:pe.status,error:pe.error}:void 0,hydration:me,error:pe?.error})),(async()=>{try{await hn(t,e),await O.ensureSessionRenderable(e,{directory:t});try{let r=wr(()=>{let n=Ut();if(!n)throw Error(`unbound`);return n.getTranscript(mt(t,e))});n&&r&&po({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){na(wi({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:me,error:n}))}finally{ge(t=>t===e?null:t)}})()}),ye=oo(r??``,A).boundary,be=J(async e=>{if(ye.kind===`has-more`){await Gt(A,e,ze||Be?void 0:50);return}if(ye.kind===`unknown`){await Qe(A,e);return}l&&!l.complete&&await l.fetchPrevious()}),xe=Fa(r??``,A),Se=Sa(r??``,A),Ce=va(A),we=xe??sK,Te=Hi(r,A),Ee=Bi(r,A),De=Ar(e=>r?e.forms[r]??oK:oK),Oe=Z.useMemo(()=>De.filter(e=>!Ge(e.metadata)),[De]);Z.useEffect(()=>{r&&Fr({sessionID:r,directory:A}).catch(e=>{console.error(`[ChatContainer] Failed to list session forms:`,e)})},[r,A]),IG(r,A,ae,Ee.length);let ke=Z.useMemo(()=>{if(!r||Te.length>0||Ee.length>0)return!1;let e=we.type??`idle`;if(e===`busy`||e===`retry`||zk(ue,{resolvedSessionStatus:xe,sessionStatusObservedAt:Se}))return!0;let t=ae[ae.length-1]?.info,n=t?.time?.created;return xe&&typeof Se==`number`&&typeof n==`number`&&n<=Se||typeof Ce==`number`&&typeof n==`number`&&n<=Ce?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,ue,xe,ae,Te.length,Ee.length,we.type,Se,Ce]),Ae=Z.useMemo(()=>!r||we.type!==`retry`?null:{sessionId:r,message:(typeof we.message==`string`?(we.message??``).trim():``)||uK,confirmedAt:we.confirmedAt},[r,we]),[je,Me]=Z.useState(0),Ne=Z.useRef(null);Z.useEffect(()=>{if(!Ae||typeof Ae.confirmedAt==`number`){Ne.current=null,Me(0);return}Ne.current!==Ae.sessionId&&(Ne.current=Ae.sessionId,Me(Date.now()))},[Ae]);let Pe=Z.useMemo(()=>!Ae||iU(we)?null:{...Ae,fallbackTimestamp:je},[Ae,je,we]),Fe=Z.useMemo(()=>aU(we,e=>_(e)),[we,_]),Ie=!!(r&&O.isLoading(r,{directory:A})),Re=Z.useMemo(()=>{if(!r)return null;let e=Bk({boundary:ye,assistantComplete:l?.complete??!0});return{limit:ye.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:Vk({syncLoading:Ie,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,ye,Ie]),ze=q(e=>e.isMobile),Be=fc()!==null,Ve=E(),He=mx(),Ue=!!b?.open,We=oi(e=>e.error),Ke=M,qe=Be||ze||Ve||He===`mini-chat`,Je=Z.useRef(null),Ye=Z.useMemo(()=>{let e=b?.selectedProjectId?w.find(e=>e.id===b.selectedProjectId)??null:null,t=T?w.find(e=>e.id===T)??null:null,n=e??t??w[0]??null;return n?OK(n):null},[T,b?.selectedProjectId,w]),Xe=Jr(r,A),Ze=a??r??``,[$e,et]=Z.useState(null),tt=kx($e,Ze,Xe,de);cr(()=>{et(e=>kx(e,Ze,Xe,de))},[Xe,de,Ze]);let nt=Xe??tt?.parentTarget??null,rt=tt?.execution??de,it=Qs(),at=it!==null&&r===it,ot=J(()=>{nt&&y(nt.id,nt.directory)}),st=nt?.session?.title,ct=g.returnToParent&&nt&&!at?(0,$.jsxs)($r,{type:`button`,variant:`outline`,size:`xs`,onClick:ot,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":_(`chat.container.returnToParent.aria`),title:st?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:st}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,lt=Tx({readOnly:t,sessionIdentityPending:te,isSubagentSession:!!ee?.parentID||!!tt,allowPromptingSubagentSessions:F}),ut=rt.modelId===de.modelId?fe:rt.modelId?Ki(D.find(e=>e.id===rt.providerId),rt.modelId)||rt.modelId:_(`common.unavailable`),dt=nt?(0,$.jsx)(Qk,{agentName:rt.agentName,providerId:rt.providerId,modelId:rt.modelId,modelName:ut}):(0,$.jsx)(Qk,{}),ft=J(e=>{q.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),pt=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`&&ft({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),ht=typeof window<`u`&&window.parent!==window;ir(`message`,pt,ht?window:lK),nr(()=>{if(!ht)return;let e=window;e.__yuriApplyChatSettingsSync=ft,window.parent.postMessage({type:`yuri:chat-settings-request`},window.location.origin)}),rr(()=>{if(typeof window>`u`)return;let e=window;e.__yuriApplyChatSettingsSync===ft&&delete e.__yuriApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Ue&&v()},[e,r,Ue,g.newSessionDraft,v]);let gt=Z.useRef(()=>{}),_t=J(e=>{gt.current(e)}),vt=Z.useRef(()=>{}),yt=J(()=>{vt.current()}),[bt,xt]=Z.useState(0),St=J(()=>{xt(e=>e+1)}),{scrollRef:Ct,notifyContentChange:wt,getAnimationHandlers:Tt,goToBottom:Et,scrollToBottomOnSend:Dt,releaseAutoFollow:Ot,beginHistoryViewportPreservation:kt,endHistoryViewportPreservation:At,restoreSnapshot:jt,isPinned:Mt,isFollowingProgrammatically:Nt,showScrollButton:Pt}=uE({scrollControllerRef:Je,enabled:n,currentSessionId:r,viewportKey:a,sessionMessageCount:B,sessionIsWorking:ke,isMobile:ze,onActiveTurnChange:_t,onUpwardUserIntent:yt}),Ft=Z.useRef(null),It=VU({enabled:ze,scrollRef:Ct,scopeRef:Ft}),Lt=Z.useRef([]),Rt=Z.useMemo(()=>{let e=sA(l?.entries??[],r,Lt.current);return Lt.current=e,e},[l?.entries,r]),zt=Z.useRef([]),Bt=Z.useMemo(()=>{if(!l)return ae;let e=uA(l.entries,r,ae,zt.current);return zt.current=e,e},[l,r,ae]),Vt=Z.useMemo(()=>Rk(Rt.length===0?Bt:r?[...Rt,aA(r),...Bt]:Rt,ue),[r,Bt,Rt,ue]),Ht=Z.useRef(null),Wt=Z.useMemo(()=>qk({sessionId:r,messages:Vt,retained:Ht.current}),[r,Vt]);Ht.current=Wt.retained;let Kt=Wt.messages,qt=Z.useRef(null),Jt=qt.current===r,Yt=Z.useRef(TG),Xt=r?`${A}\n${r}`:null,Zt=J(()=>wG(Kt));Z.useEffect(()=>{if(!OG({active:n,sessionId:r,sessionKey:Xt,sessionIsWorking:ke})){Yt.current=kG(Yt.current);return}let e=r,t=A,i=setInterval(()=>{let n=Zt(),r=EG(Yt.current,{sessionKey:Xt,working:!0,streaming:!!R,fingerprint:n,now:Date.now(),thresholdMs:bG,cooldownMs:xG,maxAttempts:3});Yt.current=r.state,r.shouldRefresh&&(DG({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),Le(t,e).catch(()=>{}))},SG);return()=>clearInterval(i)},[n,r,A,Zt,ke,R,Xt]);let Qt=Z.useMemo(()=>{if(ue.length===0)return[];let e=new Set([...Rt,...Bt].filter(e=>Lk(e.parts)).map(e=>e.info.id));return ue.map(e=>e.info.id).filter(t=>e.has(t))},[Bt,Rt,ue]);Z.useEffect(()=>{Qt.length!==0&&(p?.(Qt),r&&le(r,Qt))},[le,r,Qt,p]);let $t=ZW({sessionId:r,directory:A,messages:Kt,historyMeta:Re,scrollRef:Ct,messageListRef:Je,loadMoreMessages:be,goToBottom:Et,releaseAutoFollow:Ot,beginHistoryViewportPreservation:kt,endHistoryViewportPreservation:At,isPinned:Mt,showScrollButton:Pt,isMobile:ze,onWillLoadEarlier:St}),en=J(()=>{Et(`instant`),It()}),tn=J(e=>{if(q.getState().activeMainTab!==`chat`||TK())return!1;let t=e.target;return!(t instanceof HTMLElement)||Ft.current?.contains(t)?!0:!t.closest(`input, textarea, [contenteditable="true"], .cm-editor, .monaco-editor, .terminal-viewport-container`)}),nn=J(()=>{Dt()}),rn=Hk({isMobile:ze,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingOlder:$t.isLoadingOlder}),an=$t.isLoadingOlder,on=$t.loadEarlier,sn=J(()=>{on({userInitiated:!0})});gt.current=$t.handleActiveTurnChange,vt.current=$t.handleHistoryUpwardIntent,Z.useEffect(()=>{(Te.length!==0||Ee.length!==0)&&wt(`permission`)},[wt,Te,Ee]);let cn=yG({sessionId:r,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,scrollToTurn:$t.scrollToTurn,scrollToMessage:$t.scrollToMessage,resumeToBottom:en}),ln=lt.showReadOnlyBanner?dt:t?null:(0,$.jsx)(pk,{surface:s,scrollToBottom:nn,submissionBlocked:lt.blockSubmission},`composer-input`),un=J(e=>{cn.scrollToTurnId(e,{behavior:`smooth`})}),dn=$t.historySignals.canLoadEarlier,K=g.promptNavigator&&!ze&&!Ve&&!Ke&&P&&$t.turnIds.length>=2;Z.useEffect(()=>{K||q.getState().setPromptNavigatorPanelOpen(!1)},[K]);let fn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||Et(`instant`)});ir(cK,fn,n&&r&&typeof window<`u`?window:lK);let pn=J(e=>{if(!n||!r||Ke||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=q.getState();if(t!==`chat`||TK())return;let i=Ct.current;if(wK(document.activeElement,i)||CK(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;cn.scrollByTurnOffset(a,{resumePastEnd:!1})});ir(`keydown`,pn,n&&r&&!Ke&&typeof window<`u`?window:lK);let mn=Z.useRef(0),gn=J(()=>{let e=Ct.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),_n=J(()=>{mn.current||=requestAnimationFrame(()=>{mn.current=0,gn()})});cr(()=>{n&&gn()},[n,r,Ke,gn]);let vn=typeof ResizeObserver<`u`;sr(n&&vn?Ct:null,_n),ir(`resize`,_n,n&&!vn&&typeof window<`u`?window:lK),rr(()=>{mn.current&&=(cancelAnimationFrame(mn.current),0)});let yn=Z.useRef(null),bn=Z.useRef(0),xn=Gk({transcriptMessageCount:ae.length,pendingUserCount:ue.length,historyPrefixCount:Rt.length}),Sn=Kk({hasTranscriptShell:xn,transcriptRecords:ae,p0Satisfied:me.p0Satisfied,hasBusyShell:ke&&xn,hasImmediateShell:ue.length>0||Rt.length>0,hasRenderableSessionSnapshot:H,prefetchStatus:pe?.status,syncLoading:!!(r&&O.isLoading(r,{directory:A})),userRetrying:_e,hasPaintedTranscript:Jt});Sn===`pass`&&Kt.length>0&&(qt.current=r);let Cn=!!r&&Sn===`hydrating`;tG({scope:JSON.stringify([m(),A,r]),enabled:n&&!ze&&!Be&&!!r&&Sn===`pass`&&me.p0Satisfied&&!ke&&!Re?.loading&&!$t.isLoadingOlder,cursor:ye.kind===`has-more`?ye.cursor:null,loadedTurns:ye.loadedTurns,messages:Kt,scrollRef:Ct,loadPrevious:e=>Gt(A,r,e)});let wn=!!r&&Sn===`load-error`;Z.useEffect(()=>{!wn||!r||na(wi({kind:`request-error`,sessionID:r,directory:A,purpose:`load-failed`,source:`network`,request:pe?{sessionID:r,status:pe.status===`ready`?`ready`:pe.status,error:pe.error}:void 0,hydration:me,error:pe?.error}))},[r,A,wn,pe,me]),Z.useEffect(()=>{if(!n||!r||Cn)return;let e=Kt.length,t=yn.current!==r,i=!t&&bn.current===0&&e>0;if(!t&&!i){yn.current===r&&(bn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(yn.current=r,bn.current=e,a){Ot();return}let o=()=>{jt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,Cn,Ot,jt,Kt.length]),Z.useEffect(()=>{re(e=>e.key===G?e:{key:G,attempt:0})},[G]),Z.useEffect(()=>{if(!n||!r||ne.key!==G||!rK({sessionId:r,hasRenderableSessionSnapshot:H,hasCurrentSessionEntity:!!ee})||(j(r),ee||ne.attempt>=2))return;let e=ne.attempt+1,t=window.setTimeout(()=>{re(t=>t.key===G&&t.attempt===ne.attempt?{key:G,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,ee,r,A,j,H,G,ne]);let Tn=C&&r&&(C.targetSessionId?r===C.targetSessionId:r===C.sourceSessionId)?C:null;if(Tn){let e=Tn.stage===`preparing`?`chat.forkTransition.preparing`:Tn.stage===`copying`?`chat.forkTransition.copying`:Tn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Tn.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)(RG,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}if(!r&&!Ue)return e&&!We?(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)(eA,{})});if(!r&&Ue){if((x||S)&&oe){let e=`draft:${b.draftID??`pending`}`;return(0,$.jsxs)(`div`,{ref:Ft,className:Y(`relative flex h-full flex-col bg-background`,ze&&`yuri-chat-composer-swap-scope`),children:[(0,$.jsx)(EK,{timelineHistoryAnchorToken:bt,currentSessionId:e,virtualizerKey:e,isDesktopExpandedInput:!1,isMobile:ze,stickyUserHeader:N,directory:A,scrollRef:Ct,messageListRef:Je,pendingRevealWork:!1,initialPinRevealComplete:!0,renderedMessages:[oe],isLoadingOlder:!1,sessionIsWorking:!0,streamingMessageId:null,activeStreamingPhase:null,retryOverlay:null,handleMessageContentChange:wt,getAnimationHandlers:Tt,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:[],sessionPermissions:[],sessionForms:[],retryActionCopy:null,isProgrammaticFollowActive:Nt,showLoadOlderButton:!1,turnIds:[],activeTurnId:null,onSelectTurn:un,showPromptNavigator:!1,canLoadEarlierPrompts:!1,isLoadingOlderPrompts:!1,onLoadEarlierPrompts:sn,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)(RG,{})]})})},e),(0,$.jsxs)(`div`,{className:Y(`invisible pointer-events-none relative z-10`,ze&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Ke?`absolute inset-0 bg-background`:`bg-background`),"aria-hidden":`true`,children:[!ze&&!Ke?(0,$.jsx)(bK,{}):null,ln]})]})}return x||S?(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)(RG,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[qe&&!Ke?(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:kK(Ye?_(`chat.emptyState.draftTitleWithProject`,{project:Ye}):_(`chat.emptyState.draftTitle`),Ye)}),(0,$.jsx)(xS,{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`,ze&&`yuri-mobile-composer-foot`,Ke?`flex-1 bg-background`:qe?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:ln})]})}return r?wn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[ct,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Ke?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Ke,children:Ke?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)($r,{type:`button`,className:`mt-5`,onClick:ve,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:ln},`composer-foot`)]}):Cn?(0,$.jsxs)(`div`,{ref:Ft,className:Y(`relative flex flex-col h-full bg-background`,ze&&`yuri-chat-composer-swap-scope`),children:[ct,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Ke?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Ke,children:(0,$.jsx)(`div`,{ref:Ct,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:yK,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:DK.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)(Kd,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(Kd,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(Kd,{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)(Kd,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(Kd,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(Kd,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!ze&&!Ke?(0,$.jsx)(bK,{}):null,ln]},`composer-foot`)]}):Kt.length===0&&!ke?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[ct,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Ke?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Ke,children:Ke?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(eA,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:ln},`composer-foot`)]}):(0,$.jsxs)(`div`,{ref:Ft,className:Y(`relative flex flex-col h-full bg-background`,ze&&`yuri-chat-composer-swap-scope`),children:[d?(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:d}):null,ct,(0,$.jsx)(pG,{messages:Kt,enabled:n&&!Ke,canOpen:tn,onNavigate:Ot,children:(0,$.jsx)(EK,{timelineHistoryAnchorToken:bt,currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Ke,isMobile:ze,stickyUserHeader:N,directory:A,scrollRef:Ct,messageListRef:Je,pendingRevealWork:$t.pendingRevealWork,initialPinRevealComplete:ce,renderedMessages:$t.renderedMessages,isLoadingOlder:an,sessionIsWorking:ke,streamingMessageId:R,activeStreamingPhase:z,retryOverlay:Pe,handleMessageContentChange:wt,getAnimationHandlers:Tt,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:Ee,sessionPermissions:Te,sessionForms:Oe,retryActionCopy:Fe,isProgrammaticFollowActive:Nt,showLoadOlderButton:rn,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,onSelectTurn:un,showPromptNavigator:K,canLoadEarlierPrompts:dn,isLoadingOlderPrompts:an,onLoadEarlierPrompts:sn},r)},`find:${a??r}`),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,ze&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Ke?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!ze&&!Ke?(0,$.jsx)(bK,{}):null,(0,$.jsx)(oU,{scrollRef:Ct,active:n&&!Ke,showScrollToBottom:Kt.length>0&&$t.showScrollToBottom,onScrollToBottom:cn.resumeToLatest}),ln]},`composer-foot`),(0,$.jsx)(iG,{open:I,onOpenChange:L,sessionID:r??void 0,directory:A,onRevertMessage:u,onScrollToMessage:$t.scrollToMessage,onScrollByTurnOffset:cn.scrollByTurnOffset,onResumeToLatest:en,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingEarlier:an,onLoadEarlier:sn})]}):null});jK.displayName=`MemoizedChatContainerContent`;var MK=()=>{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)(Kd,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(Kd,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(Kd,{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)(Kd,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(Kd,{className:`h-4 w-3/5 animate-none rounded-md`})]})]})})}),e[1]=n):n=e[1],n},NK=({runtimeKey:e,...t})=>{let n=mx(),r=ia(),i=Wa(oe(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),cr(()=>{!o||!i.draftPendingMessageId||(a.current={identity:o,messageId:i.draftPendingMessageId})},[o,i.draftPendingMessageId]);let s=Wa(e=>i.sessionId?e.retainedPendingUserMessages.get(i.sessionId)??aK:aK),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(()=>UG(u),[u]),f=d.key,p=vi()||E()||n===`mini-chat`?_K:gK,[m,h]=Z.useState(()=>({activeIntent:d,cacheNeedsTrim:!1,cachedSessionViews:u?GG([],u,p,fK):[],pendingSessionView:null})),g=Z.useRef(d),_=Z.useRef(f),{cacheNeedsTrim:v,cachedSessionViews:y,pendingSessionView:b}=m,x=b?.intent===d?b.entry:null,S=Z.useMemo(()=>!u||!l?null:GG([],u,p,fK)[0]??null,[p,l,u]),C=Z.useMemo(()=>{let e=[...y];return x&&!e.some(e=>e.key===x.key)&&e.push(x),S&&!e.some(e=>e.key===S.key)&&e.push(S),e.sort((e,t)=>e.key.localeCompare(t.key))},[y,S,x]),w=qG(C,f),T=!!(f&&!w);cr(()=>{g.current=d,_.current=f,h(e=>{let t=JG(e,d,p);return l?YG(t,d,d,fK):t})},[p,v,l,d,f]);let D=b?.intent??null;cr(()=>{D&&h(e=>XG(e,D,p))},[p,D]),Z.useEffect(()=>{if(!d.selection||w)return;let e=d,t=f;return nd(()=>{g.current===e&&_.current===t&&h(n=>_.current===t?YG(n,e,g.current,fK):n)},{priority:`user-blocking`})},[w,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=KG(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":T||void 0,children:[T?(0,$.jsx)(MK,{},f):null,C.map(e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:w===e.key?`visible`:`hidden`,children:(0,$.jsx)(jK,{...t,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:O,committedDraftHandoffMessageId:w===e.key?l:null})},e.key)),f?null:(0,$.jsx)(jK,{...t,sessionId:null,sessionDirectory:i.directory})]})},PK=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=Jk(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)(jK,{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)(Xb.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},FK=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=ia(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Yb({...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)(jK,{...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)(Xb.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},IK=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(vK,m,m);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(PK,{...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)(FK,{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)(NK,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r},LK=2e4,RK=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus()?`visible`:`hidden`,zK=e=>{if(!_()&&!D())return;let t=A();t?.push?.setVisibility&&t.push.setVisibility({visible:e,platform:O()})},BK=e=>{let t=e?.enabled??!0;Z.useEffect(()=>{if(!t||!_()&&!D()||typeof window>`u`)return;if(D()){let e=!0,t=!1,n=null,r=()=>zK(e);Wn(async()=>{let{App:e}=await import(`./vendor-capacitor-app-B5H_XtmE.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([78,1,14])).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&&zK(!0)},LK);return()=>{t=!0,window.clearInterval(i),n?.()}}if(typeof document>`u`)return;let e=()=>{zK(RK()===`visible`)},n=()=>{RK()===`visible`&&zK(!0)},r=()=>{zK(!1)};e();let i=window.setInterval(n,LK);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])},VK=`Yuri`,HK=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``).split(`/`).filter(Boolean);return t[t.length-1]??``},UK=(e,t)=>[e,t,VK].filter(e=>typeof e==`string`&&e.trim().length>0).join(` | `),WK=()=>{let e=Mr(e=>{if(!e.activeProjectId)return null;let t=e.projects.find(t=>t.id===e.activeProjectId);return t&&HK(t.path)||null}),[t,n]=Z.useState(null);Z.useEffect(()=>{if(typeof window>`u`||!y()){n(null);return}let e=!1,t=async()=>{try{if(S()){e||n(null);return}let t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,r=h();if(r&&L(r,t)){e||n(null);return}let i=(await U()).hosts.find(e=>r?L(r,P(e)):!1),a=i?.label?.trim()?ee(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(()=>UK(e,t),[e,t]);Z.useEffect(()=>{typeof document<`u`&&(document.title=r),y()&&(async()=>{try{if(typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``))return;await dr(r)}catch{return}})()},[r])},GK=e=>{let t=[];return e.hideGit||t.push(`git`),t.push(`files`),e.showBrowser&&t.push(`browser`),t},KK=()=>{let e=Wa.getState().currentSessionId;if(!e)return``;let t=it().find(t=>t.id===e);return typeof t?.directory==`string`?t.directory:``},qK=async(e,t=6e3)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t),i=Date.now();try{let t=await g(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)}},JK=e=>{if(!e||!Number.isFinite(e))return`(n/a)`;try{return new Date(e).toISOString()}catch{return`(invalid)`}},YK=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},XK=e=>!!e&&typeof e==`object`&&!Array.isArray(e),ZK=(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,QK=(e,t,n)=>e===`node-shebang`||e===`node-launcher`?t?`node (${t})`:`node`:e===`bun-shebang`?n?`bun (${n})`:`bun`:e||`direct executable`,$K=async()=>{let e=new Date,t=typeof navigator<`u`?navigator.userAgent:`(no navigator)`,n=KK(),r=q.getState().eventStreamStatus,i=typeof window<`u`?window.location.origin:``,a=l(),o=a.health(),s=a.api(`/api/`),c=await(async()=>{if(!o)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),5e3);try{let t=await g(o,{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(!s)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),7e3);try{let t=await g(a.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(!s)return null;let r=new URL(e.replace(/^\/+/,``),s);return t&&n&&r.searchParams.set(`location[directory]`,n),r.toString()},f=s?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 qK(t,typeof e.timeoutMs==`number`?e.timeoutMs:void 0);return{label:e.label,url:t,result:n}})):[],p=[];p.push(`Time: ${e.toISOString()}`),p.push(`Yuri version: 0.2.38`),p.push(`Runtime: ${i||`(unknown)`} (api=${s||`(unknown)`})`),p.push(`OpenCode SDK base: ${Kt.getBaseUrl()}`),p.push(`Event stream: ${r}`),p.push(`Directory: ${n||`(none)`}`),p.push(`Platform: ${t}`);let m=YK(c?.openCodePort);if(p.push(`OpenCode runtime port: ${m??`(unknown)`}`),typeof c?.openCodeRunning==`boolean`&&p.push(`OpenCode runtime running: ${c.openCodeRunning?`yes`:`no`}`),typeof c?.openCodeSecureConnection==`boolean`&&p.push(`Secure OpenCode connection: ${c.openCodeSecureConnection?`true`:`false`}`),typeof c?.openCodeAuthSource==`string`&&c.openCodeAuthSource.trim()&&p.push(`OpenCode auth source: ${c.openCodeAuthSource}`),typeof c?.openCodeServeVersion==`string`&&c.openCodeServeVersion.trim()&&p.push(`OpenCode serve version: ${c.openCodeServeVersion}`),typeof c?.openCodeCliVersion==`string`&&c.openCodeCliVersion.trim()&&p.push(`OpenCode CLI version: ${c.openCodeCliVersion}`),XK(c?.runtimeContract)){let e=c.runtimeContract,t=typeof e.phase==`string`?e.phase:`(unknown)`,n=e.executionAllowed===!0?`allowed`:`limited`,r=e.protocolCompatible===!0?`compatible`:`incompatible`;p.push(`OpenCode runtime contract: phase=${t} protocol=${r} execution=${n}`),Array.isArray(e.reasons)&&e.reasons.length>0&&p.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&&p.push(`macOS major: ${e}`)}if(/Mac OS X|Macintosh/.test(t)){p.push(``),p.push(`OpenCode CLI resolution:`);let e=XK(c?.lastOpenCodeLaunchDiagnostics)?c.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:c&&typeof c.opencodeBinaryResolved==`string`?c.opencodeBinaryResolved:``,a=n&&typeof n.resolvedDir==`string`?n.resolvedDir:``,o=n&&typeof n.source==`string`?n.source:c&&typeof c.opencodeBinarySource==`string`?c.opencodeBinarySource:``,s=n&&typeof n.launchBinary==`string`?n.launchBinary:c&&typeof c.opencodeLaunchBinary==`string`?c.opencodeLaunchBinary:``,l=n&&typeof n.launchWrapperType==`string`?n.launchWrapperType:c&&typeof c.opencodeLaunchWrapperType==`string`?c.opencodeLaunchWrapperType:``,d=n&&Array.isArray(n.launchArgs)?n.launchArgs.filter(e=>typeof e==`string`):c&&Array.isArray(c.opencodeLaunchArgs)?c.opencodeLaunchArgs.filter(e=>typeof e==`string`):[],f=n&&typeof n.node==`string`?n.node:c&&typeof c.nodeBinaryResolved==`string`?c.nodeBinaryResolved:``,m=n&&typeof n.bun==`string`?n.bun:c&&typeof c.bunBinaryResolved==`string`?c.bunBinaryResolved:``,h=n&&typeof n.detectedNow==`string`?n.detectedNow:``,g=n&&typeof n.detectedSourceNow==`string`?n.detectedSourceNow:``;if(r!==null&&p.push(`- configured: ${r.trim().length===0?`(cleared)`:r}`),i){let e=a||(i.includes(`/`)?i.split(`/`).slice(0,-1).join(`/`)||`/`:``);p.push(`- opencode: ${i}${e?` (dir=${e})`:``}`)}else p.push(`- opencode: (n/a)`);p.push(`- source: ${o||`(n/a)`}`),h&&(p.push(`- detected-now: ${h}`),p.push(`- detected-source: ${g||`(n/a)`}`)),e?(p.push(`- launched-at: ${ZK(e.launchedAt)}`),p.push(`- launch: ${ZK(e.binary)} ${t.join(` `)}`.trim()),p.push(`- cwd: ${ZK(e.cwd)}`),p.push(`- wrapper: ${ZK(e.wrapperType)}`),p.push(`- runtime: ${QK(ZK(e.wrapperType,``),f,m)}`),p.push(`- PATH entries: ${ZK(e.pathEntryCount,`(unknown)`)}`),p.push(`- shell env: ${ZK(e.hasShellEnv,`(unknown)`)} (${ZK(e.shellEnvKeysCount,`?`)} keys)`)):(p.push(`- launch-binary: ${s||`(n/a)`}`),p.push(`- launch-wrapper: ${l||`(n/a)`}`),p.push(`- launch-args: ${d.length?d.join(` `):`(none)`}`),p.push(`- runtime: ${QK(l||``,f,m)}`)),!n&&u.error&&p.push(`- resolution-endpoint: ${u.error}`)}if(p.push(``),f.length){p.push(`OpenCode API probes:`);for(let e of f){if(!e.result){p.push(`- ${e.label}: (no url)`);continue}let{ok:t,status:n,elapsedMs:r,summary:i}=e.result,a=t?``:` url=${e.url}`;p.push(`- ${e.label}: ${t?`ok`:`fail`} status=${n} time=${r}ms ${i}${a}`)}}else p.push(`OpenCode API probes: (skipped)`);return p.push(``),p.push(`Generated: ${JK(Date.now())}`),p.join(`
|
|
6612
|
+
`)},eq=async()=>{let e=await $K(),t=q.getState();t.setOpenCodeStatusText(e),t.setOpenCodeStatusDialogOpen(!0)},tq=(e,t)=>e===t?!0:!e||!t?!1:e.scope===t.scope&&e.sessionId===t.sessionId&&e.projectId===t.projectId,nq=e=>e?`${e.scope}:${e.projectId??``}:${e.sessionId}`:null,rq=e=>({scope:`project`,sessionId:e,projectId:null}),iq=G()(e=>({focus:null,setFocus:t=>e(e=>tq(e.focus,t)?e:{focus:t})})),aq=null,oq=0,sq=(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},cq=e=>{let t=++oq;return aq={pinned:sq(`pinned`,e.pinned),project:sq(`project`,e.project)},()=>{oq===t&&(aq=null)}},lq=()=>aq,uq=e=>!!e.parentID,dq=(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&&uq(r);){let e=r.parentID;if(!e)break;let t=n.get(e);if(!t)return e;r=t}return r?.id??e},fq=()=>{let e=Ba.getState().activeSessions;if(e.length>0)return e;let t=Ue();return t.length>0?t:it()},pq=(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)},mq=e=>[...e.pinned,...e.project],hq=(e,t,n,r)=>{if(e.length===0)return null;let i=pq(e,n,r);return i<0?t>0?e[0]??null:e[e.length-1]??null:e[(i+t+e.length)%e.length]??null},gq=(e,t,n=iq.getState().focus)=>{let r=dq(t,fq()),i=n?.sessionId===t?n:null,a=lq();return a?hq(mq(a),e,r,i):null},_q=(e,t,n=e=>{Wa.getState().setCurrentSession(e.sessionId,e.directory)})=>{let r=gq(e,t);return r?(iq.getState().setFocus({scope:r.scope,sessionId:r.sessionId,projectId:r.projectId}),n(r),r):null},vq=.5,yq=.1,bq=`yuri.webviewZoomFactor`,xq=e=>Number.isFinite(e)?Math.min(3,Math.max(vq,Math.round(e*100)/100)):1,Sq=()=>{if(typeof window>`u`)return 1;try{let e=window.localStorage.getItem(bq);return e?xq(Number.parseFloat(e)):1}catch{return 1}},Cq=e=>{if(!(typeof window>`u`))try{window.localStorage.setItem(bq,String(e))}catch{}},wq=e=>{let t=xq(e);return typeof document<`u`&&(document.documentElement.style.zoom=t===1?``:String(t)),Cq(t),t},Tq=()=>{if(typeof document>`u`)return 1;let e=document.documentElement.style.zoom;if(!e)return Sq();let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?xq(t):Sq()},Eq=()=>{if(C())return;let e=Sq();e!==1&&wq(e)},Dq=async()=>{if(C())try{let e=await x(`desktop_zoom_in`);if(typeof e==`number`&&Number.isFinite(e))return xq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_in failed, using CSS zoom`,e)}return wq(Tq()+yq)},Oq=async()=>{if(C())try{let e=await x(`desktop_zoom_out`);if(typeof e==`number`&&Number.isFinite(e))return xq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_out failed, using CSS zoom`,e)}return wq(Tq()-yq)},kq=async()=>{if(C())try{let e=await x(`desktop_zoom_reset`);if(typeof e==`number`&&Number.isFinite(e))return xq(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_reset failed, using CSS zoom`,e)}return wq(1)},Aq=9,jq=null,Mq=0,Nq=({pinnedTargets:e,projectTargets:t})=>[...e,...t].slice(0,Aq),Pq=(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},Fq=e=>{let t=++Mq;return jq={targets:e.targets.slice(0,Aq),activate:e.activate},()=>{Mq===t&&(jq=null)}},Iq=e=>{if(!Number.isInteger(e)||e<1||e>Aq)return!1;let t=jq,n=t?.targets[e-1];return!t||!n?!1:(t.activate(n),!0)},Lq=e=>{let t=e.trim();if(!t)return null;let n=tf.getState(),r=n.createTab(t);return!r||r===`tab-invalid`?null:(n.setActiveTab(t,r),r)},Rq=e=>{let t=e.trim();if(!t)return null;let n=q.getState();return!n.isBottomTerminalOpen&&n.activeMainTab!==`terminal`&&n.setBottomTerminalOpen(!0),Lq(t)},zq=(e,t)=>{let n=e.trim();if(!n)return!1;let r=tf.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)},Bq=e=>{let t=e.trim();if(!t)return{closed:!1,wasLastTab:!1};let n=tf.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}},Vq=()=>typeof window>`u`||window.parent===window||!Ys(window.location.search)?!1:(window.parent.postMessage({type:Xs},window.location.origin),!0),Hq=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=q.getState();if(e)return!1;let n=Pu();return n&&t(n)?!0:C()?(x(`desktop_close_current_window`).catch(e=>{console.warn(`[keyboard-shortcuts] failed to close current window`,e)}),!0):!1},Uq=({sessionId:e,surfaceKind:t,wiringCanAbort:n,primaryCanAbort:r,pendingSend:i=!1})=>e?i||n?!0:t!==`secondary`&&r:!1,Wq=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)}},Gq=()=>{let e=(0,Q.c)(69),{t}=fr(),n=Wa(Kq),r=Wa(qq),i=Wa(Jq),a=Wa(Yq),o=hi,s=q(Xq),c=q(Zq),l=q(Qq),u=q($q),d=q(eJ),f=q(tJ),p=q(nJ),m=q(rJ),h=q(iJ),g=q(aJ),_=q(oJ),v=q(sJ),y=q(cJ),b=q(lJ),S=q(uJ),w=q(dJ),T=q(fJ),D=q(pJ),O=q(mJ),k=At(hJ),A=Mr(gJ),{themeMode:j,setThemeMode:M}=Io(),{working:N}=dz(),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),Xm.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=Xm.getState().arm(Ym);I.current=setTimeout(()=>{let{expiresAt:e}=Xm.getState();e&&Date.now()>=e&&Xm.getState().clear(),I.current=null},Math.max(0,e-Date.now()))},e[6]=ee):ee=e[6];let te=ee,G;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]!==b||e[16]!==m||e[17]!==y||e[18]!==T||e[19]!==d||e[20]!==f||e[21]!==g||e[22]!==v||e[23]!==M||e[24]!==S||e[25]!==O||e[26]!==t||e[27]!==p||e[28]!==s||e[29]!==u||e[30]!==D||e[31]!==c||e[32]!==w||e[33]!==l||e[34]!==N?(G=()=>{let e=e=>Ns(e,O),i=e=>ks(e,O),a=_J,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=yJ,B=xJ,V=SJ,U=async()=>{let e=QE(),n=e?iD(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;no.error(n instanceof Error?n.message:t(`chat.chatInput.toast.compactFailed`))}return}let r=Wa.getState().currentSessionId;if(!r)return;let{currentProviderId:i,currentModelId:a}=ei.getState();await Wq({sessionId:r,currentProviderId:i,currentModelId:a,waitForConnectionOrThrow:da,getAuthoritativeDirectoryForSession:Wa.getState().getAuthoritativeDirectoryForSession,summarizeSession:CJ,onCompactFailed:e=>{no.error(e instanceof Error?e.message:t(`chat.chatInput.toast.compactFailed`))}})},ee=t=>{let r=Xm.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&&rs(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}=q.getState(),c=ZE(a)&&!V();if(r===`m`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),window.requestAnimationFrame(()=>{y(!o,{instant:!0})});return}if(r===`a`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),b(!s,{instant:!0});return}if(r===`n`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();let r=QE(),i=r?iD(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||!rs(t,i)||V())return;let{activeMainTab:o}=q.getState();ZE(o)&&(t.preventDefault(),t.stopPropagation(),te())},G=()=>Xm.getState().pending||L.current,ne=e=>{G()&&e.preventDefault()},re=e=>{G()&&(e.preventDefault(),e.stopPropagation())},ie=t=>{if(a(t.target)){if(!E()&&rs(t,e(`new_terminal_tab`))){let e=Pu();if(!e||!Lq(e))return;t.preventDefault(),t.stopPropagation();return}if(!E()&&rs(t,e(`previous_terminal_tab`))){let e=Pu();if(!e||!zq(e,-1))return;t.preventDefault(),t.stopPropagation();return}if(!E()&&rs(t,e(`next_terminal_tab`))){let e=Pu();if(!e||!zq(e,1))return;t.preventDefault(),t.stopPropagation();return}if(rs(t,e(`close_context_panel_tab`))){let e=Pu();if(!e)return;let{closed:n,wasLastTab:r}=Bq(e);if(!n)return;if(t.preventDefault(),t.stopPropagation(),r){let e=q.getState();e.setBottomTerminalOpen(!1),e.activeMainTab===`terminal`&&e.setActiveMainTab(`chat`)}return}if(rs(t,e(`toggle_terminal`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(rs(t,e(`toggle_bottom_panel`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(rs(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=q.getState();if(e)return;t.preventDefault(),t.stopPropagation(),m(!n);return}}},ae=wJ,oe=t=>{if(t.defaultPrevented||t.isComposing||t.keyCode===229)return;if(rs(t,e(`close_context_panel_tab`))){(Vq()||Hq())&&(t.preventDefault(),t.stopPropagation());return}if(a(t.target))return;let r=TJ;if(r(t.target)&&t.ctrlKey&&!t.metaKey&&!t.shiftKey&&!t.altKey&&t.key.toLowerCase()===`t`){t.preventDefault(),ae();return}if(rs(t,e(`open_command_palette`))){t.preventDefault(),s();return}if(rs(t,e(`open_timeline_dialog`))){t.preventDefault(),S(!0);return}if(rs(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}=q.getState();if(!n||h||E()||e!==`chat`||r||i||a||o||s||c||l||u)return;t.preventDefault(),w();return}if(rs(t,e(`open_status`))){t.preventDefault(),eq();return}if(rs(t,e(`open_help`))){t.preventDefault(),c();return}if(C()&&rs(t,e(`new_mini_chat`))){t.preventDefault(),x(`desktop_open_draft_mini_chat_window`,{directory:k||A?.path||``,projectId:A?.id??null}).catch(EJ);return}let o=rs(t,e(`new_chat`)),b=rs(t,e(`new_chat_worktree`));if(o||b){if(t.preventDefault(),_(`chat`),g(!1),!E()&&b){qx();return}n();return}if(rs(t,e(`cycle_theme`))){if(t.preventDefault(),kp()!==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(Es(t,`in`,e(`zoom_in`))){t.preventDefault(),Dq();return}if(Es(t,`out`,e(`zoom_out`))){t.preventDefault(),Oq();return}if(rs(t,e(`zoom_reset`))){t.preventDefault(),kq();return}if(rs(t,e(`open_settings`))){t.preventDefault();let{isSettingsDialogOpen:e}=q.getState();v(!e);return}if(rs(t,e(`toggle_sidebar`))){t.preventDefault();let{isMobile:e,isSessionSwitcherOpen:n}=q.getState();e?g(!n):l();return}if(rs(t,e(`focus_input`))){t.preventDefault(),document.querySelector(`textarea[data-chat-input="true"]`)?.focus();return}let T=e(`cycle_agent`),O=T&&!T.includes(`shift`)?As(`shift+${T}`):``,j=O&&rs(t,O)?-1:+!!rs(t,T);if(j!==0){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s}=q.getState();if(e||n||i||a||o||!ZE(s)||!r(t.target))return;let c=QE(),l=c?iD(c):null;if(l){t.preventDefault(),l.shortcut(`cycle`,j);return}let u=ei.getState(),d=Qr(u.getVisibleAgents(),u.currentAgentName,j);if(!d)return;t.preventDefault(),u.setAgent(d),q.getState().addRecentAgent(d);let f=Wa.getState().currentSessionId;f&&Oi.getState().saveSessionAgentSelection(f,d);return}if(i(`toggle_right_sidebar`).some(e=>rs(t,e))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault();let n=Pu();n&&u(n);return}if(rs(t,e(`open_right_sidebar_git`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault();let n=Pu();n&&q.getState().openContextPanel(n),d(!0),f(`git`);return}if(rs(t,e(`open_right_sidebar_files`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault();let n=Pu();n&&q.getState().openContextPanel(n),d(!0),f(`files`);return}if(rs(t,e(`cycle_right_sidebar_tab`))){let{isMobile:e,rightSidebarTab:n}=q.getState();if(e)return;let r=GK({hideGit:q.getState().activeMainTab===`git`,showBrowser:ws(Ms())}),i=r[(r.indexOf(n)+1)%r.length];t.preventDefault();let a=Pu();a&&q.getState().openContextPanel(a),d(!0),f(i);return}let N=e=>_q(e,Wa.getState().currentSessionId,e=>{_(`chat`),g(!1),Wa.getState().setCurrentSession(e.sessionId,e.directory)});if(i(`previous_session`).some(e=>rs(t,e))){t.preventDefault(),N(-1);return}if(i(`next_session`).some(e=>rs(t,e))){t.preventDefault(),N(1);return}for(let n=1;n<=9;n+=1)if(rs(t,e(`switch_tab_${n}`))){Iq(n)&&t.preventDefault();return}if(rs(t,e(`toggle_terminal`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),p();return}if(rs(t,e(`open_new_terminal`))){let{isMobile:e}=q.getState();if(e||E())return;let n=Pu();if(!n||!Rq(n))return;t.preventDefault();return}if(rs(t,e(`toggle_bottom_panel`))){let{isMobile:e}=q.getState();if(e)return;t.preventDefault(),p();return}if(rs(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=q.getState();if(e)return;t.preventDefault(),m(!n);return}if(rs(t,e(`open_model_selector`))){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isAboutDialogOpen:a,activeMainTab:o,isModelSelectorOpen:s}=q.getState();if(e)return;let c=n||r||i||a,l=ZE(o);if(c||!l)return;t.preventDefault(),y(!s,{instant:!0});return}if(rs(t,e(`cycle_thinking_variant`))){ae()&&t.preventDefault();return}if(rs(t,e(`cycle_favorite_model_forward`))||rs(t,e(`cycle_favorite_model_backward`))){let{isSettingsDialogOpen:n,isCommandPaletteOpen:r,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s,favoriteModels:c,addRecentModel:l}=q.getState();if(n)return;let u=r||i||a||o,d=ZE(s);if(u||!d||c.length===0)return;t.preventDefault();let f=c.length,p=rs(t,e(`cycle_favorite_model_forward`))?1:-1,m=QE();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=ei.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}=ei.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(rs(t,e(`expand_input`))){if(h)return;t.preventDefault(),D();return}if(rs(t,e(`toggle_dictation`))){let{activeMainTab:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isSettingsDialogOpen:a}=q.getState();if(!ZE(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,workStatusOverlayOpen:g}=q.getState();if(n||a||s){H();return}if(g){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),q.getState().setWorkStatusOverlayOpen(!1),H();return}if(h){e.preventDefault(),T(!1),H();return}if(c){e.preventDefault(),v(!1),H();return}if(i){H();return}if(l||u||d||f||p||m){H();return}let _=QE(),y=_?iD(_):null,b=_?.sessionID??Wa.getState().currentSessionId,x=!!(b&&Wa.getState().pendingSendMessageIDs.get(b));if(!Uq({sessionId:b,surfaceKind:_?.kind,wiringCanAbort:y?.canAbort,primaryCanAbort:N.canAbort,pendingSend:x})){H();return}e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();let S=Date.now(),C=P.current;if(C&&S<C){H(),y?y.abort():(b&&xu(b),o(b??``));return}let w=_?.kind===`secondary`?S+3e3:r(3e3)??S+3e3;P.current=w,F.current&&clearTimeout(F.current);let E=Math.max(w-S,0);F.current=setTimeout(()=>{P.current&&Date.now()>=P.current&&H()},E||0)};return window.addEventListener(`keydown`,ee,!0),window.addEventListener(`beforeinput`,ne,!0),window.addEventListener(`compositionstart`,re,!0),window.addEventListener(`compositionupdate`,re,!0),window.addEventListener(`compositionend`,re,!0),window.addEventListener(`keydown`,ie,!0),window.addEventListener(`keydown`,se,!0),window.addEventListener(`keydown`,oe),()=>{window.removeEventListener(`keydown`,ee,!0),window.removeEventListener(`beforeinput`,ne,!0),window.removeEventListener(`compositionstart`,re,!0),window.removeEventListener(`compositionupdate`,re,!0),window.removeEventListener(`compositionend`,re,!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]=b,e[16]=m,e[17]=y,e[18]=T,e[19]=d,e[20]=f,e[21]=g,e[22]=v,e[23]=M,e[24]=S,e[25]=O,e[26]=t,e[27]=p,e[28]=s,e[29]=u,e[30]=D,e[31]=c,e[32]=w,e[33]=l,e[34]=N,e[35]=G):G=e[35];let ne=A?.id,re=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]!==b||e[44]!==m||e[45]!==y||e[46]!==T||e[47]!==d||e[48]!==f||e[49]!==g||e[50]!==v||e[51]!==M||e[52]!==S||e[53]!==O||e[54]!==t||e[55]!==ne||e[56]!==re||e[57]!==p||e[58]!==s||e[59]!==u||e[60]!==D||e[61]!==c||e[62]!==w||e[63]!==l||e[64]!==N?(ie=[n,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,S,w,T,D,M,N,r,H,te,W,a,k,ne,re,O,t],e[36]=r,e[37]=k,e[38]=a,e[39]=h,e[40]=n,e[41]=H,e[42]=_,e[43]=b,e[44]=m,e[45]=y,e[46]=T,e[47]=d,e[48]=f,e[49]=g,e[50]=v,e[51]=M,e[52]=S,e[53]=O,e[54]=t,e[55]=ne,e[56]=re,e[57]=p,e[58]=s,e[59]=u,e[60]=D,e[61]=c,e[62]=w,e[63]=l,e[64]=N,e[65]=ie):ie=e[65],Z.useEffect(G,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 Kq(e){return e.openNewSessionDraft}function qq(e){return e.armAbortPrompt}function Jq(e){return e.clearAbortPrompt}function Yq(e){return e.currentSessionId}function Xq(e){return e.toggleCommandPalette}function Zq(e){return e.toggleHelpDialog}function Qq(e){return e.toggleSidebar}function $q(e){return e.toggleContextPanel}function eJ(e){return e.setRightSidebarOpen}function tJ(e){return e.setRightSidebarTab}function nJ(e){return e.toggleBottomTerminal}function rJ(e){return e.setBottomTerminalExpanded}function iJ(e){return e.isMobile}function aJ(e){return e.setSessionSwitcherOpen}function oJ(e){return e.setActiveMainTab}function sJ(e){return e.setSettingsDialogOpen}function cJ(e){return e.setModelSelectorOpen}function lJ(e){return e.setAgentSelectorOpen}function uJ(e){return e.setTimelineDialogOpen}function dJ(e){return e.togglePromptNavigatorPanel}function fJ(e){return e.setPromptNavigatorPanelOpen}function pJ(e){return e.toggleExpandedInput}function mJ(e){return e.shortcutOverrides}function hJ(e){return e.currentDirectory}function gJ(e){return e.getActiveProject()}function _J(e){return e instanceof Element&&!!(e.closest(`[data-terminal-view="true"]`)||e.closest(`.terminal-viewport-container`)||e.getAttribute(`data-terminal-hidden-input`)===`true`)}function vJ(e){return e.getClientRects().length>0}function yJ(){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(vJ)}function bJ(){document.querySelector(`textarea[data-chat-input="true"]`)?.focus({preventScroll:!0})}function xJ(){window.requestAnimationFrame(bJ)}function SJ(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i}=q.getState();return e||t||n||r||i}function CJ(e,t,n,r){return Kt.summarizeSession(e,t,n,r)}function wJ(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i,activeMainTab:a}=q.getState();if(e||t||n||r||i||!ZE(a))return!1;let o=QE();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=ei.getState();if(s.getCurrentModelVariants().length===0)return!1;s.cycleCurrentVariant();let c=ei.getState().currentVariant,l=Wa.getState().currentSessionId,u=ei.getState().currentAgentName,d=ei.getState().currentProviderId,f=ei.getState().currentModelId;return l&&u&&d&&f&&Oi.getState().saveAgentModelVariantForSession(l,u,d,f,c),u&&d&&f&&ei.getState().saveAgentModelSelection(u,d,f,c),!0}function TJ(e){return e instanceof HTMLTextAreaElement&&e.getAttribute(`data-chat-input`)===`true`}function EJ(e){console.warn(`[keyboard-shortcuts] failed to open draft mini chat window`,e)}var DJ=3,OJ=(e,t)=>{if(typeof e!=`string`)return t;let n=e.trim().replace(/\s+/g,` `);return n?n.slice(0,48):t},kJ=(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:OJ(e.title,`Session ${r.length+1}`)}),r.length>=DJ))break}return r},AJ=()=>{let e=(0,Q.c)(9),t=yo(),n=Wa(jJ),r;e[0]!==n||e[1]!==t?(r=kJ(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`||!_())){try{i.length===0?localStorage.removeItem(Ps):localStorage.setItem(Ps,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 jJ(e){return e.currentSessionId}var MJ=e=>Number.isFinite(e)?`${Math.max(0,Math.round(e))}px`:`0px`,NJ=(e,t,n,r)=>{e.style.setProperty(`--yuri-wco-left-inset`,MJ(t)),e.style.setProperty(`--yuri-wco-right-inset`,MJ(n)),e.style.setProperty(`--yuri-wco-titlebar-height`,MJ(r))},PJ=()=>{let e=(0,Q.c)(1),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],Z.useEffect(FJ,t)};function FJ(){if(typeof window>`u`||!_())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){NJ(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));NJ(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),NJ(e,0,0,0)}}var IJ=3e4,LJ=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,RJ=e=>e instanceof tu?e.status===501?`unsupported`:e.status>=400&&e.status<500&&e.status!==408&&e.status!==429&&e.code!==`revision_conflict`?`permanent`:`retry`:`retry`,zJ=(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})}),BJ=(e,t)=>e.then(e=>{if(t?.aborted)throw new DOMException(`Aborted`,`AbortError`);return e}),VJ={fetchSnapshot:e=>BJ(mu(Fn),e),refreshSnapshot:e=>BJ(eu(Fn),e),fetchOrder:Zl,setOrder:Ql,waitInvalidation:$l,captureRuntime:()=>({transportIdentity:u(),generation:f()}),isCurrent:e=>e.transportIdentity===u()&&e.generation===f(),sleep:zJ,createRequestID:()=>typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`worktree-order-${Date.now()}-${Math.random().toString(36).slice(2)}`},HJ=new Map,UJ=()=>{for(let e of HJ.values())e.controller.abort();HJ.clear()},WJ=(e,t,n,r=VJ)=>{HJ.get(e)?.controller.abort();let i={projectDirectory:LJ(t),orderedPaths:[...n],capture:r.captureRuntime(),controller:new AbortController,backoffMs:500,running:!1};HJ.set(e,i),GJ(e,r)},GJ=async(e,t=VJ)=>{let n=HJ.get(e);if(!(!n||n.running)){n.running=!0;try{for(;;){let n=HJ.get(e);if(!n||!t.isCurrent(n.capture)||n.controller.signal.aborted)return;let r=ho.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)||HJ.get(e)!==n)return;let a=i.worktreeOrder??{projectDirectory:n.projectDirectory,orderedPaths:n.orderedPaths,revision:i.revision};ho.getState().setServerRevision(e,a.revision),ho.getState().resolvePendingWorktreeOrder(e,a.revision),HJ.delete(e);return}catch(r){if(n.controller.signal.aborted||!t.isCurrent(n.capture)||HJ.get(e)!==n)return;if(r instanceof tu&&r.code===`revision_conflict`)try{let r=await t.fetchOrder(n.projectDirectory,n.controller.signal);if(HJ.get(e)!==n||!t.isCurrent(n.capture))return;ho.getState().applyServerWorktreeOrder(e,r.orderedPaths,r.revision),n.expectedRevision=void 0,n.requestID=void 0,n.backoffMs=500;continue}catch(e){if(RJ(e)!==`retry`)return}else if(RJ(r)!==`retry`)return;if(await t.sleep(n.backoffMs,n.controller.signal).catch(()=>{}),n.backoffMs=Math.min(n.backoffMs*2,IJ),n.controller.signal.aborted)return}}}finally{HJ.get(e)===n&&(!t.isCurrent(n.capture)||n.controller.signal.aborted)&&HJ.delete(e),HJ.get(e)===n&&(n.running=!1)}}},KJ=(e,t,n,r)=>{let i=new Map(t.map(e=>[LJ(e.path),e.id]));for(let t of e){let e=i.get(LJ(t.projectDirectory));e&&r.isCurrent(n)&&ho.getState().applyServerWorktreeOrder(e,t.orderedPaths,t.revision)}},qJ=(e,t=VJ)=>{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();KJ(r.worktreeOrders,o,a,t);let s=new Set(r.worktreeOrders.map(e=>LJ(e.projectDirectory)));for(let e of o){let n=ho.getState(),r=n.orderByProject[e.id];n.pendingProjectIDs[e.id]?WJ(e.id,e.path,r??[],t):r?.length&&!s.has(LJ(e.path))&&(n.markPendingWorktreeOrder(e.id),WJ(e.id,e.path,r,t))}break}catch(e){if(RJ(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,IJ)}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,KJ(s.worktreeOrders,e(),a,t),r=500}catch(e){if(RJ(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,IJ)}})()},stop:r}},JJ=()=>{let e=(0,Q.c)(2),t=Mr(XJ),n;e[0]===t?n=e[1]:(n=[t],e[0]=t,e[1]=n),Z.useEffect($J,n)};function YJ(e){return[e.id,LJ(e.path)]}function XJ(e){return JSON.stringify(e.projects.map(YJ))}function ZJ(e,t,n){return WJ(e,t,n)}function QJ(){return Mr.getState().projects}function $J(){let e=u();ho.getState().activateWorktreeOrderRuntime(e);let t=ra(ZJ),n=qJ(QJ);n.start();let r=c(e=>{p(e)&&(UJ(),ho.getState().activateWorktreeOrderRuntime(u()),n.start())});return()=>{t(),r(),n.stop(),UJ()}}var eY=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,tY=e=>{let t=!1,n=0,r=0,i=0,a=!1,o=new Set,s=new Map,c=new Map,l=new Map,u=new Map,d=new Set,f=new Set,p=new Map,m=new Set,h=new Set,g=new Set,_=``,v=[],y=(n,i=150,a=!1,c={})=>{let d=eY(n.path);if(a&&(o.has(d)||s.has(d)||u.has(d)))return;let f=(l.get(d)??0)+1;l.set(d,f);let p=u.get(d);p&&e.clearTimer(p.timer);let m=r,h=e.setTimer(()=>{!t||m!==r||(u.delete(d),s.set(d,{project:n,refreshBatch:c,version:f}),b(m))},i);u.set(d,{timer:h,epoch:m})},b=(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,{project:u,refreshBatch:d,version:f}]=n;s.delete(a),i+=1,o.add(a);let h=e.generation(),_=r,v=()=>t&&_===r&&h===e.generation()&&l.get(a)===f;e.refresh(u,{isCurrent:v,refreshBatch:d}).then(t=>{if(v()){t.repositoryDirectory&&c.set(a,eY(t.repositoryDirectory)),g.add(a);for(let n of t.addedDirectories){let t=eY(n);(!e.needsSessionSync||e.needsSessionSync(t))&&m.add(t)}if(e.needsSessionSync)for(let n of t.worktrees){let t=eY(n.path);e.needsSessionSync(t)&&m.add(t)}x(_,h),S()}}).then(()=>{v()&&p.delete(a)}).catch(()=>{if(!v())return;let e=(p.get(a)??0)+1;p.set(a,e),t&&_===r&&y(u,[1e3,2e3,5e3,15e3,3e4][Math.min(e-1,4)])}).finally(()=>{_===r&&(--i,o.delete(a),b(_))})}},x=(n,i)=>{if(m.size===0)return;let a=[...m];m.clear(),e.syncAdded(a).catch(()=>{if(t&&n===r&&i===e.generation()){for(let e of a)m.add(e);let o=e.setTimer(()=>{d.delete(o),t&&n===r&&x(n,i)},1e3);d.add(o)}})},S=()=>{if(g.size!==e.getProjects().length)return;let t=e.getCatalog();for(let e of h){let n=e.slice(e.indexOf(`:`)+1);[...t.entries()].some(([e,t])=>eY(e)===n||t.some(e=>eY(e.path)===n))||f.add(e)}},C=()=>{g.clear();let t={};for(let n of e.getProjects())y(n,0,!0,t)},w=()=>{let t=e.getCatalog(),r=e.getProjects(),i=new Set;for(let t of e.getActiveDirectories())t.trim()&&i.add(eY(t));for(let e of[...h]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||h.delete(e)}for(let e of[...f]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||f.delete(e)}for(let e of i)if(!r.find(n=>{let r=eY(n.path),i=t.get(r)?.some(t=>eY(t.path)===e);return e===r||i})){let t=`${n}:${e}`;!f.has(t)&&!h.has(t)&&(h.add(t),C())}},T=()=>{r+=1,f.clear(),h.clear(),p.clear(),m.clear(),g.clear();for(let t of u.values())e.clearTimer(t.timer);u.clear();for(let t of d)e.clearTimer(t);d.clear(),s.clear(),o.clear(),i=0,c.clear(),l.clear()};return{start:()=>{t||e.isVSCode()||(t=!0,a=!1,v.push(e.subscribeEvents(i=>{if(i.type===`event-stream-ready`){if(!a){a=!0,C();return}n+=1,T(),C()}if(i.type===`worktree-topology-changed`&&i.projectDirectory){let n=eY(i.projectDirectory),a={},o=c.get(n),s=e.getCatalog();for(let t of e.getProjects()){let e=eY(t.path),r=s.get(e)?.some(t=>eY(t.worktreeRoot??t.path)===n||t.relativePath&&e===`${n}/${t.relativePath}`),i=o&&c.has(e)?c.get(e)===o:r;(e===n||i)&&y(t,150,!1,a)}if(e.resolveRepository){let i=r,s=e.generation();(async()=>{let l=o??eY(await e.resolveRepository(n));for(let n of e.getProjects()){let u=eY(n.path);if(!(o&&c.has(u)))try{let o=c.get(u)??eY(await e.resolveRepository(u));if(!t||i!==r||s!==e.generation())return;c.set(u,o),o===l&&y(n,150,!1,a)}catch{t&&i===r&&s===e.generation()&&y(n)}}})().catch(()=>{t&&i===r&&s===e.generation()&&C()})}}})),_=e.getProjects().map(e=>`${e.id}\u0000${eY(e.path)}`).sort().join(`
|
|
6613
|
+
`),v.push(e.subscribeProjects(()=>{let t=e.getProjects().map(e=>`${e.id}\u0000${eY(e.path)}`).sort().join(`
|
|
6614
|
+
`);t!==_&&(_=t,T(),C(),w())})),v.push(e.subscribeCatalog(w)),v.push(e.subscribeSessions(w)),v.push(e.subscribeRuntime(e=>{e&&(a=!1,n+=1,T(),C())})),C(),w())},stop:()=>{t=!1,T();for(let{timer:t}of u.values())e.clearTimer(t);for(u.clear(),s.clear(),i=0;v.length;)v.pop()?.()},reconcileAll:C}},nY=null,rY=0,iY=()=>(nY||=tY({isVSCode:E,getProjects:()=>Mr.getState().projects,getCatalog:()=>Wa.getState().availableWorktreesByProject,getActiveDirectories:()=>{let e=Ba.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=Ba.getState(),n=eY(e);return!t.loadedDirectories.has(n)&&!t.loadingDirectories.has(n)&&!t.refreshingDirectories.has(n)},refresh:Dd,resolveRepository:Yo,syncAdded:e=>$i(e,Ba.getState().activeSessions),subscribeProjects:e=>Mr.subscribe(e),subscribeCatalog:e=>Wa.subscribe((t,n)=>{t.availableWorktreesByProject!==n.availableWorktreesByProject&&e()}),subscribeSessions:e=>Ba.subscribe((t,n)=>{(t.activeSessions!==n.activeSessions||t.cachedDirectories!==n.cachedDirectories)&&e()}),subscribeEvents:br,subscribeRuntime:e=>c(t=>e(p(t))),generation:f,setTimer:(e,t)=>globalThis.setTimeout(e,t),clearTimer:e=>globalThis.clearTimeout(e)}),rY+=1,nY.start(),()=>{rY=Math.max(0,rY-1),rY===0&&nY?.stop()});function aY(){if(A()?.runtime.isVSCode)return()=>{};let e=new Dn(Fn,Yd()),t=br(e=>{(e.type===`speech-settings-changed`||e.type===`event-stream-ready`)&&Fn.invalidateQueries({queryKey:Yd().queryKey,exact:!0})}),n=t=>{if(!t.data||e.options.queryKey[0]!==u())return;let n=ei.getState();Object.entries(t.data).some(([e,t])=>n[e]!==t)&&ei.setState(t.data)},r=e.subscribe(n);n(e.getCurrentResult());let i=c(()=>{ei.setState(ii),e.setOptions(Yd()),n(e.getCurrentResult())});return()=>{i(),r(),t(),e.destroy()}}var oY=`yuri:mini-chat-presence`,sY=()=>{let e=ch(),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(()=>{qi(e=>t.current(e),e=>n.current(e),e=>r.current(e))},[]),Z.useEffect(()=>iY(),[]),null},cY=()=>{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(fY,t),null},lY=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(aY,r);let i=Z.useSyncExternalStore(wu,gu,gu);du(n&&i===`legacy-enabled`),yu();let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=[],t[1]=a):a=t[1],Z.useEffect(pY,a);let o;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(sY,{}),t[2]=o):o=t[2],o}),uY=Z.memo(function(e){let t=(0,Q.c)(6),{embeddedBackgroundWorkEnabled:n}=e;AJ(),PJ(),Gq(),JJ();let r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0],Z.useEffect(mY,r);let i;t[1]===n?i=t[2]:(i=(0,$.jsx)(lY,{embeddedBackgroundWorkEnabled:n}),t[1]=n,t[2]=i);let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(cY,{}),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 dY(e){let t=e.data;if(t?.type!==`mini-chat-session-presence`||!t.sessionId||!t.directory)return;let n=t.viewed!==!1;Wr(t.directory,t.sessionId,n),n&&xa(t.sessionId)}function fY(){if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(oY);return e.onmessage=dY,()=>e.close()}function pY(){let e=nu(),t=Su();e.start(),t.start();let n=hu(e);return()=>{n(),t.stop(),e.stop()}}function mY(){Eq()}var hY=new Set,gY=new Map,_Y=(e,t)=>`https://cdn.jsdelivr.net/npm/${encodeURIComponent(e.packageName).replace(`%40`,`@`).replace(`%2F`,`/`)}/files/${e.filePrefix}-latin-${t}-normal.woff2`,vY=(e,t)=>{let n=`${e.family}:${t}`;if(hY.has(n))return Promise.resolve();let r=gY.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(${_Y(e,t)}) format('woff2')`,{style:`normal`,weight:String(t),display:`swap`});document.fonts.add(i);let a=i.load().then(()=>{hY.add(n)}).catch(n=>{document.fonts.delete(i),console.warn(`Failed to load font: ${e.family} ${t}`,n)}).finally(()=>{gY.delete(n)});return gY.set(n,a),a},yY=e=>e?Promise.all(e.weights.map(t=>vY(e,t))).then(()=>void 0):Promise.resolve(),bY=e=>yY(xn[e]?.source),xY=e=>yY(bn[e]?.source),SY={family:`Syne`,packageName:`@fontsource/syne`,filePrefix:`syne`,weights:[700]},CY=()=>yY(SY);function wY(){let e=(0,Q.c)(4),{uiFont:t,monoFont:n}=nf(),r,i;e[0]!==n||e[1]!==t?(r=()=>{if(typeof document>`u`)return;let e=document.documentElement,r=xn[t]?.stack??xn.system.stack,i=bn[n]?.stack??bn[`system-mono`].stack;bY(t),xY(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{pw as $,EH as A,Up as At,nj as B,af as Bt,IK as C,ch as Ct,eW as D,nm as Dt,vG as E,cm as Et,oI as F,Pf as Ft,mE as G,Qk as H,tI as I,mf as It,uE as J,pE as K,OF as L,uf as Lt,YL as M,gp as Mt,iI as N,hp as Nt,ZU as O,tm as Ot,rI as P,cp as Pt,Vw as Q,aj as R,sf as Rt,BK as S,mh as St,RG as T,Sm as Tt,TE as U,kA as V,gE as W,Hw as X,HT as Y,Uw as Z,tq as _,nb as _t,lY as a,oS as at,GK as b,Mv as bt,Pq as c,iS as ct,Dq as d,Mx as dt,fw as et,Oq as f,px as ft,nq as g,xb as gt,rq as h,Xb as ht,uY as i,aS as it,oB as j,Vp as jt,AU as k,Zp as kt,Fq as l,qx as lt,cq as m,qb as mt,CY as n,kS as nt,Rq as o,rS as ot,_q as p,fx as pt,hE as q,bY as r,nS as rt,Nq as s,cS as st,wY as t,BS as tt,kq as u,jx as ut,iq as v,Qv as vt,nK as w,km as wt,WK as x,Hh as xt,eq as y,Av as yt,pj as z,lf as zt};
|