@yuriai/web 0.2.0-beta.7 → 0.2.0-beta.9
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/README.md +4 -0
- package/dist/assets/{AgentAvatar-CMpCBSy_.js → AgentAvatar-RbwoyGL7.js} +1 -1
- package/dist/assets/{AssistantView-CfyUDUVG.js → AssistantView-CTu_YqYq.js} +3 -3
- package/dist/assets/{DiagramView-CZg5AAli.js → DiagramView-BIhEoeWx.js} +1 -1
- package/dist/assets/{FadeInOnReveal-ANDXEIE7.js → FadeInOnReveal-Dt1nUq5y.js} +1 -1
- package/dist/assets/{GuiPluginSurface-CqqJymvB.js → GuiPluginSurface-68HtzOv6.js} +1 -1
- package/dist/assets/{GuiPluginWindow-B2G2-nAK.js → GuiPluginWindow-CMUyR2_9.js} +1 -1
- package/dist/assets/{Icon-DgrlwLKs.js → Icon-GJTjieJN.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-DdaN0XMj.js → ImageLoadingPlaceholder-C4VZA5iQ.js} +1 -1
- package/dist/assets/{LoadingImage-BJc5SC-0.js → LoadingImage-BZjPXN_m.js} +1 -1
- package/dist/assets/{MarkdownRenderer-DZwskKzl.js → MarkdownRenderer-DnCTLWjR.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-BQhcJNsK.js → MarkdownRendererImpl-C8HsL6On.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-CsURmqQY.js → MarkstreamRendererImpl-B1M5pAJe.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-CH4Oyt33.js → MobileDetailNavigation-BdSsbh04.js} +1 -1
- package/dist/assets/MobileResizableSheet-B8kpq7AR.js +1 -0
- package/dist/assets/{MobileShareBridge-DEDl3YCM.js → MobileShareBridge-r5Q2J_Sc.js} +2 -2
- package/dist/assets/{MobileTabPageHeader-C7Bkm6-_.js → MobileTabPageHeader-BRtaISjE.js} +1 -1
- package/dist/assets/{MultiRunWindow-DI0-Ur1w.js → MultiRunWindow-BPORsCa7.js} +1 -1
- package/dist/assets/{OnboardingScreen-BH__JnO0.js → OnboardingScreen-BssiDW_8.js} +1 -1
- package/dist/assets/{OverlayScrollbar-bByT588g.js → OverlayScrollbar-DWZJpEVx.js} +1 -1
- package/dist/assets/SettingsView-BxRekjws.js +26 -0
- package/dist/assets/{SettingsWindow-BJQyV3do.js → SettingsWindow-BsEMguoj.js} +1 -1
- package/dist/assets/{TerminalView-DRwLYPvJ.js → TerminalView-6hKAHFJ7.js} +1 -1
- package/dist/assets/{ToolOutputDialog-O25CmHgA.js → ToolOutputDialog-CkZORaFS.js} +1 -1
- package/dist/assets/{YuriLogo-Qr_mhaKp.js → YuriLogo-jfvSPXYV.js} +1 -1
- package/dist/assets/{appThemeRegistry-B-rbBHC4.js → appThemeRegistry-DdmE_Iv3.js} +1 -1
- package/dist/assets/{assistant-attachment-cache-DNbxU1Fq.js → assistant-attachment-cache-DWMcn4cE.js} +1 -1
- package/dist/assets/{button-BuhP8T0R.js → button-BgnrCA96.js} +1 -1
- package/dist/assets/{capgoAdapter-BgDvFDUs.js → capgoAdapter-Czek7cOG.js} +1 -1
- package/dist/assets/{collapsible-CwLF0o1c.js → collapsible-gafrZ0Tr.js} +1 -1
- package/dist/assets/desktop-dp2Z0toS.js +1 -0
- package/dist/assets/{desktopHosts-CjH4TGh8.js → desktopHosts-ByGjetLz.js} +1 -1
- package/dist/assets/{desktopRelayRestore-BLJo3sm7.js → desktopRelayRestore-DIO6vl1K.js} +1 -1
- package/dist/assets/{device-BVEAUyle.js → device-Dd4YwDwq.js} +1 -1
- package/dist/assets/{diagram-BIYywJNf.js → diagram-BIjHGw1_.js} +1 -1
- package/dist/assets/{dialog-BUEUatKm.js → dialog-D6jRorvP.js} +1 -1
- package/dist/assets/{dropdown-menu.styles-tzNMk1yW.js → dropdown-menu.styles-BKQriop5.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-C6ylhQkG.js → fileMentionTouchSelection-BSSggGfQ.js} +1 -1
- package/dist/assets/{fileReferenceActions-DuYvTiGf.js → fileReferenceActions-D625rOTl.js} +1 -1
- package/dist/assets/{gitApi-4JPWt45Y.js → gitApi-BkhGiTtu.js} +1 -1
- package/dist/assets/gui-BCPFcL_m.js +1 -0
- package/dist/assets/host-C6DQGHTV.js +1 -0
- package/dist/assets/{image-loading-CU4V_A1c.js → image-loading-Ctpxfqla.js} +1 -1
- package/dist/assets/{input-BVgNVYou.js → input-CDVEeuDT.js} +1 -1
- package/dist/assets/{insertionBoundaries-BSPv205d.js → insertionBoundaries-8-NDZp_y.js} +1 -1
- package/dist/assets/{main-CETRwACI.js → main-C6Yw42Pk.js} +12 -12
- package/dist/assets/{main-foDhMZ24.js → main-UQKItVb4.js} +2 -2
- package/dist/assets/{markdownHeightCache-BceTKVDK.js → markdownHeightCache-Dv5LnHPc.js} +1 -1
- package/dist/assets/{mcpQueries-AswEbyXP.js → mcpQueries-CyI_Hol5.js} +1 -1
- package/dist/assets/miniChat-tf1jH68G.js +2 -0
- package/dist/assets/mobile-C7dS2AHt.js +2 -0
- package/dist/assets/{mobileBackNavigation-C03Z5phB.js → mobileBackNavigation-Bcg-mihS.js} +1 -1
- package/dist/assets/{multirun-CWGx21Ol.js → multirun-xh4jfDx_.js} +1 -1
- package/dist/assets/native-BMAEg2E6.js +1 -0
- package/dist/assets/{native-config-DC-Ccre6.js → native-config-CKpFI_5o.js} +1 -1
- package/dist/assets/native-errors-06if6eu-.js +1 -0
- package/dist/assets/{persistence-D-W3L37Z.js → persistence-BfjCXjLZ.js} +1 -1
- package/dist/assets/{platform-CQG2KlHW.js → platform-Dcd-lkPn.js} +3 -3
- package/dist/assets/{projectMeta-6Sbr-Iiw.js → projectMeta-QJd1QrkI.js} +1 -1
- package/dist/assets/readiness-C1vgtBOT.js +1 -0
- package/dist/assets/{renderElectronMiniChatApp-CQHm04xq.js → renderElectronMiniChatApp-B84E6SfM.js} +2 -2
- package/dist/assets/{renderMobileApp-D4lOGRzz.js → renderMobileApp-PhdK6y6v.js} +4 -4
- package/dist/assets/{runtime-file-download-BdNCQkDe.js → runtime-file-download-CwP-HoXN.js} +1 -1
- package/dist/assets/{runtime-file-resource-DdAheq3y.js → runtime-file-resource-h3yIw4HU.js} +1 -1
- package/dist/assets/{runtime-file-store-hFlndg-n.js → runtime-file-store-BVRgEtI-.js} +1 -1
- package/dist/assets/runtimeConfig-CJCKi9-y.js +2 -0
- package/dist/assets/runtimeEndpointReset-Dxl8XtfH.js +149 -0
- package/dist/assets/{scheduledTaskNavigation-Cy2nZl_A.js → scheduledTaskNavigation-B7WhY2Fp.js} +1 -1
- package/dist/assets/{sessionChangeSummary-C70M_uHA.js → sessionChangeSummary-CY9vQ5i1.js} +1 -1
- package/dist/assets/{sessionLookup-CCOa3Jeq.js → sessionLookup-D1uJyExH.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-CAkRGa2f.js → sortable-tabs-strip-C4STfRdG.js} +1 -1
- package/dist/assets/{speechSettingsQueries-CIcSgao2.js → speechSettingsQueries-tUWgMwuK.js} +2 -2
- package/dist/assets/src-r07HspQy.css +2 -0
- package/dist/assets/{terminalApi-DY0KJOiK.js → terminalApi-CJx_hK4K.js} +1 -1
- package/dist/assets/{textarea-BLvbQAIG.js → textarea-DI9j9018.js} +1 -1
- package/dist/assets/{tooltip-jf98dFQe.js → tooltip-BHHwyMVd.js} +1 -1
- package/dist/assets/{types-D5ocrnEK.js → types-BmLypFZI.js} +1 -1
- package/dist/assets/{useAppFontEffects-DSR2ev_Q.js → useAppFontEffects-BeFXBNUc.js} +16 -16
- package/dist/assets/{useDesktopWindowControlsLayout-pyawlD_R.js → useDesktopWindowControlsLayout-BkdDy7r3.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-W6wf50T7.js → useEffectiveDirectory-RivT6KwZ.js} +1 -1
- package/dist/assets/{useFontPreferences-CH3iNDUl.js → useFontPreferences-Bwzz0JNf.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BTF3FUmY.js → useMobileNavigationStore-BQHfCZ55.js} +8 -8
- package/dist/assets/{useWorkerHighlightedLines-Dhr3xUQY.js → useWorkerHighlightedLines-BszN5sdj.js} +1 -1
- package/dist/assets/{vendor-effect-DXlObQuU.js → vendor-effect-DV9F8PTZ.js} +1 -1
- package/dist/assets/vendor-opencode-client-fxfj4IA_.js +12 -0
- package/dist/assets/{vendor-opencode-plugin-BglYYlJt.js → vendor-opencode-plugin-CQ5ogY33.js} +1 -1
- package/dist/assets/{vendor-solid-js-B2FO7pdm.js → vendor-solid-js-Dmt4_-Zk.js} +1 -1
- package/dist/index.html +17 -17
- package/dist/mini-chat.html +17 -17
- package/dist/mobile.html +17 -17
- package/package.json +1 -1
- package/server/index.d.ts +2 -0
- package/server/index.js +8 -1
- package/server/lib/content-search/DOCUMENTATION.md +5 -1
- package/server/lib/content-search/runtime.js +24 -0
- package/server/lib/content-search/runtime.test.js +19 -0
- package/server/lib/opencode/DOCUMENTATION.md +5 -0
- package/server/lib/opencode/gui-plugin-source.js +14 -0
- package/server/lib/opencode/gui-plugin-source.test.js +28 -0
- package/server/lib/opencode/plugin-gui-response.d.ts +7 -0
- package/server/lib/opencode/plugin-gui-response.js +62 -0
- package/server/lib/opencode/plugin-gui-response.test.js +89 -0
- package/server/lib/opencode/proxy.js +32 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -0
- package/server/lib/request-cors.js +2 -2
- package/server/lib/request-cors.test.js +3 -0
- package/server/lib/session-index/DOCUMENTATION.md +4 -0
- package/server/lib/session-index/sync-runtime.js +3 -0
- package/server/lib/session-index/sync-runtime.test.js +18 -0
- package/server/plugin-gui-proxy.test.js +134 -0
- package/dist/assets/MobileResizableSheet-xE71zG4E.js +0 -1
- package/dist/assets/SettingsView-BVmOocRh.js +0 -26
- package/dist/assets/desktop-DpAcrF1h.js +0 -1
- package/dist/assets/gui-B56BgPNQ.js +0 -1
- package/dist/assets/host-Bs4ljApp.js +0 -1
- package/dist/assets/miniChat-Dsodcwqi.js +0 -2
- package/dist/assets/mobile-C4F47gek.js +0 -2
- package/dist/assets/readiness-DWh0yJFu.js +0 -1
- package/dist/assets/runtimeConfig-5btjngJ7.js +0 -2
- package/dist/assets/runtimeEndpointReset-NHpx5wGb.js +0 -149
- package/dist/assets/src-BR-siHj2.css +0 -2
- package/dist/assets/vendor-opencode-client-BcpAhe9I.js +0 -12
|
@@ -1,7 +1,7 @@
|
|
|
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{S as t,l as n,w as r}from"./runtime-auth-ef9W7A43.js";import{c as i,f as a,i as o,l as s,n as c,o as l,r as u,t as d}from"./runtime-switch-CAZiOV2G.js";import{n as f}from"./runtime-fetch-BAN5Gnnp.js";import{_ as p,b as m,d as h,g,k as _,m as v,t as y,v as b,x}from"./desktop-DpAcrF1h.js";import{t as S}from"./runtimeAPIRegistry-C2VogTny.js";import{c as C,f as w,g as T,h as E,i as D,m as O,n as k,o as A,p as j,r as M,s as N,u as P,v as F}from"./desktopHosts-CjH4TGh8.js";import{r as I}from"./desktopRelayRestore-BLJo3sm7.js";import{a as L,i as R,o as z,r as B,s as V,t as H}from"./vendor-zustand-o69pgTEK.js";import{d as U,f as W,it as ee,l as te,nt as ne,p as re,rt as G,u as ie}from"./vendor-base-ui-CdzJ6My_.js";import{At as ae,Ci as oe,Cn as se,Cr as ce,Ct as le,Di as ue,Dn as de,Dr as fe,En as pe,Er as me,Hn as he,In as ge,It as _e,Kn as ve,Li as ye,Ln as be,Lt as xe,Mi as Se,Mn as Ce,Nr as we,Nt as Te,Oi as Ee,On as De,Or as Oe,Ot as ke,Qt as Ae,Ri as je,Sn as Me,Sr as Ne,Ti as Pe,Tn as Fe,Vn as Ie,Wn as Le,Xt as Re,Yt as ze,_i as Be,an as Ve,br as He,cn as Ue,en as We,fn as Ge,hn as Ke,jn as qe,jr as Je,jt as Ye,kn as Xe,kt as Ze,mn as Qe,n as $e,nn as et,on as tt,pn as nt,qt as rt,rn as it,rr as at,sn as ot,t as st,tn as ct,vn as lt,vr as ut,xi as dt,xn as ft,xr as pt,yn as mt,zi as ht}from"./platform-CQG2KlHW.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{_ as gt,b as _t,c as vt,f as yt,g as bt,h as xt,n as K,y as St}from"./useUIStore-NMQx_cnG.js";import{$ as Ct,A as wt,B as Tt,C as Et,Ct as Dt,F as Ot,G as kt,J as At,K as jt,L as Mt,M as Nt,Ot as Pt,Pt as Ft,Q as It,R as Lt,S as Rt,T as zt,Tt as Bt,V as Vt,W as Ht,X as Ut,Y as Wt,_ as Gt,at as Kt,b as qt,f as Jt,ft as Yt,g as Xt,i as Zt,it as Qt,j as $t,lt as en,m as tn,ot as nn,pt as rn,q as an,r as on,rt as sn,st as cn,t as ln,tt as un,v as dn,vt as fn,wt as pn,x as mn,y as hn,yt as gn}from"./persistence-D-W3L37Z.js";import{n as _n}from"./vendor-react-BP2cRVqX.js";import{i as vn}from"./vendor-tanstack-query-core-BWz0ose6.js";import{c as yn,i as bn,n as q,o as xn,t as Sn}from"./vendor-tanstack-react-query-CdqCAt40.js";import{a as Cn,n as wn,o as Tn}from"./queryRuntime-BuRnpVtK.js";import{d as En,l as Dn,u as On}from"./fileQueries-DbUx7NwP.js";import{a as kn,i as An,n as jn,o as Mn,t as Nn}from"./path-utils-jGozTg9d.js";import{o as Pn}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as Fn,t as In}from"./pathNormalization-ewtPqJWn.js";import{i as Ln,u as Rn}from"./vendor-pierre-diffs-DPBtNDJ5.js";import{r as zn,t as Bn}from"./vendor-sonner-ZS8XIOVl.js";import{a as Vn,f as Hn,i as Un,m as Wn,n as J,o as Gn,p as Kn,r as qn,u as Jn}from"./vendor-reactuses-core-BpfIZ1tg.js";import{d as Yn,f as Xn,i as Zn,l as Qn,p as $n,r as Y,t as er,v as tr,y as nr}from"./button-BuhP8T0R.js";import{i as rr,t as ir}from"./store-BhjP3zxz.js";import{$ as ar,$i as or,$n as sr,$t as cr,A as lr,Aa as ur,An as dr,At as fr,B as pr,Bn as mr,C as hr,Ca as gr,Cn as _r,Co as vr,Ct as yr,D as br,Di as xr,Dn as Sr,Dt as Cr,E as wr,Ea as Tr,Ei as Er,En as Dr,Et as Or,F as kr,Fa as Ar,Fi as jr,Fn as Mr,Ft as Nr,G as Pr,Ga as Fr,Gi as Ir,Gr as Lr,Gt as Rr,H as zr,Hn as Br,Ht as Vr,I as Hr,Ia as Ur,Ii as Wr,In as Gr,It as Kr,J as qr,Ji as Jr,Jn as Yr,K as Xr,Ka as Zr,Ki as Qr,Kr as $r,Kt as ei,L as ti,La as ni,Ln as ri,M as ii,Ma as ai,Mi as oi,Mn as si,N as ci,Na as li,Ni as ui,Nn as di,Nr as fi,O as pi,Oi as mi,On as hi,Ot as gi,P as _i,Pa as vi,Pi as yi,Pn as bi,Pr as xi,Pt as Si,Q as Ci,Qi as wi,Qn as Ti,Qr as Ei,Qt as Di,R as Oi,Ra as ki,Rn as Ai,Rr as ji,Rt as Mi,Si as Ni,St as Pi,T as Fi,Tn as Ii,Tt as Li,U as Ri,Ua as zi,Un as Bi,Ut as Vi,V as Hi,Vn as Ui,W as Wi,Wi as Gi,Wr as Ki,Wt as qi,X as Ji,Xi as Yi,Xr as Xi,Xt as Zi,Y as Qi,Ya as $i,Yi as ea,Yt as ta,Z as na,Zi as ra,Zr as ia,Zt as aa,_i as oa,_n as sa,_r as ca,_t as la,aa as ua,ai as da,an as fa,ar as pa,at as ma,ba as ha,bi as ga,bn as _a,bo as va,bt as ya,c as ba,ca as xa,ci as Sa,cn as Ca,d as wa,da as Ta,di as Ea,dn as Da,do as Oa,dt as ka,ea as Aa,ei as ja,et as Ma,fa as Na,fi as Pa,fn as Fa,fo as Ia,ft as La,g as Ra,ga as za,gi as Ba,gn as Va,gr as Ha,gt as Ua,hn as Wa,i as Ga,ia as Ka,ii as qa,in as Ja,it as Ya,j as Xa,ja as Za,ji as Qa,jt as $a,k as eo,ki as to,kt as no,la as ro,m as io,mi as ao,mn as oo,mt as so,n as co,na as lo,ni as uo,nr as fo,nt as po,oa as mo,oi as ho,on as go,ot as _o,pn as vo,pt as yo,q as bo,qi as xo,qn as So,qr as Co,qt as wo,r as To,ra as Eo,rn as Do,rr as Oo,rt as ko,s as Ao,sa as jo,si as Mo,sn as No,so as Po,ta as Fo,tr as Io,tt as Lo,ua as Ro,ui as zo,un as Bo,v as Vo,vi as Ho,vn as Uo,vr as Wo,vt as Go,wa as Ko,wn as qo,wo as Jo,wt as Yo,xa as Xo,xt as Zo,yi as Qo,yn as $o,yo as es,yr as ts,yt as ns,z as rs,za as is,zn as as}from"./useMobileNavigationStore-BTF3FUmY.js";import{t as os}from"./agentColors-DWSbQXy2.js";import{t as ss}from"./dualLimitLru-D8Sphgua.js";import{i as cs,n as ls,r as us,t as ds}from"./AgentAvatar-CMpCBSy_.js";import{n as fs,r as ps,t as ms}from"./useThemeSystem-8jhE4Zyk.js";import{n as X}from"./Icon-DgrlwLKs.js";import{a as hs,i as gs,n as _s,o as vs,r as ys,s as bs,t as xs}from"./dialog-BUEUatKm.js";import{E as Ss,n as Cs}from"./gitApi-4JPWt45Y.js";import{a as ws}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{A as Ts,C as Es,D as Ds,O as Os,S as ks,_ as As,a as js,b as Ms,f as Ns,h as Ps,i as Fs,k as Is,l as Ls,m as Rs,n as zs,o as Bs,s as Vs,u as Hs,w as Us,x as Ws,y as Gs}from"./projectMeta-6Sbr-Iiw.js";import{t as Ks}from"./input-BVgNVYou.js";import{i as qs,n as Js,t as Ys}from"./tooltip-jf98dFQe.js";import{$ as Xs,At as Zs,B as Qs,Bt as $s,Ft as ec,Gt as tc,H as nc,Ht as rc,J as ic,Jt as ac,K as oc,Kt as sc,L as cc,Ot as lc,Pt as uc,Q as dc,Qt as fc,R as pc,Rt as mc,St as hc,Vt as gc,X as _c,Y as vc,Z as yc,_t as bc,an as xc,at as Sc,d as Cc,et as wc,ft as Tc,gt as Ec,i as Dc,in as Oc,it as kc,jt as Ac,kt as jc,lt as Mc,mt as Nc,n as Pc,nt as Fc,o as Ic,on as Lc,pt as Rc,q as zc,rt as Bc,tt as Vc,ut as Hc,z as Uc,zt as Wc}from"./speechSettingsQueries-CIcSgao2.js";import{t as Gc}from"./YuriLogo-Qr_mhaKp.js";import{r as Kc}from"./device-BVEAUyle.js";import{c as qc,d as Jc,f as Yc,l as Xc,n as Zc,o as Qc,p as $c,r as el,u as tl}from"./image-loading-CU4V_A1c.js";import{S as nl,a as rl,c as il,g as al,l as ol,o as sl,x as cl,y as ll}from"./dropdown-menu.styles-tzNMk1yW.js";import{b as ul,t as dl,x as fl,y as pl}from"./MobileResizableSheet-xE71zG4E.js";import{A as ml,D as hl,E as gl,O as _l,S as vl,T as yl,_ as bl,a as xl,b as Sl,c as Cl,d as wl,f as Tl,g as El,h as Dl,j as Ol,k as kl,l as Al,m as jl,o as Ml,p as Nl,s as Pl,u as Fl,v as Il,w as Ll,x as Rl,y as zl}from"./sessionChangeSummary-C70M_uHA.js";import{o as Bl}from"./vendor-framer-motion-DsGBcZHB.js";import{a as Vl,i as Hl,o as Ul,s as Wl,u as Gl}from"./fileMentionTouchSelection-C6ylhQkG.js";import{C as Kl,D as ql,E as Jl,O as Yl,S as Xl,T as Zl,a as Ql,b as $l,c as eu,d as tu,f as nu,i as ru,j as iu,k as au,l as ou,n as su,o as cu,p as lu,r as uu,s as du,t as fu,u as pu,w as mu,x as hu,y as gu}from"./insertionBoundaries-BSPv205d.js";import{C as _u,D as vu,E as yu,O as bu,S as xu,T as Su,_ as Cu,a as wu,b as Tu,c as Eu,d as Du,f as Ou,g as ku,h as Au,j as ju,l as Mu,m as Nu,o as Pu,p as Fu,r as Iu,s as Lu,t as Ru,u as zu,v as Bu,w as Vu,x as Hu,y as Uu}from"./appThemeRegistry-B-rbBHC4.js";import{a as Wu,n as Gu,o as Ku,r as qu,t as Ju}from"./MarkdownRenderer-DZwskKzl.js";import{t as Yu}from"./OverlayScrollbar-bByT588g.js";import{n as Xu,r as Zu}from"./textarea-BLvbQAIG.js";import{_ as Qu,a as $u,c as ed,g as td,l as nd,o as rd,t as id,v as ad,y as od}from"./vendor-dnd-kit-core-5pNnzVdw.js";import{i as sd,n as cd,o as ld,s as ud,t as dd}from"./vendor-dnd-kit-sortable-Dm50I0m7.js";import{a as fd,n as pd,t as md}from"./url-MRa-FtQa.js";import{a as hd,o as gd,t as _d,u as vd}from"./toolHelpers-DL452NVK.js";import{t as yd}from"./react-BYRXYlGz.js";import{n as bd,t as xd}from"./useEffectiveDirectory-W6wf50T7.js";import{t as Sd}from"./ImageLoadingPlaceholder-DdaN0XMj.js";import{t as Cd}from"./LoadingImage-BJc5SC-0.js";import{a as wd,i as Td,l as Ed,n as Dd,o as Od,r as kd,s as Ad,t as jd}from"./FadeInOnReveal-ANDXEIE7.js";import{A as Md,C as Nd,D as Pd,E as Fd,O as Id,S as Ld,T as Rd,_ as zd,a as Bd,b as Vd,c as Hd,g as Ud,h as Wd,i as Gd,k as Kd,o as qd,p as Jd,r as Yd,s as Xd,t as Zd,v as Qd,w as $d,x as ef,y as tf}from"./useWorkerHighlightedLines-Dhr3xUQY.js";import{t as nf}from"./vendor-cmdk-RDxC-9Iz.js";import{t as rf}from"./sortable-tabs-strip-CAkRGa2f.js";import{a as af}from"./markdownHeightCache-BceTKVDK.js";import{n as of,t as sf}from"./vendor-tanstack-react-virtual-B_EO--9t.js";import{n as cf}from"./markdownTheme-DHoKvD6O.js";import{t as lf}from"./vendor-motion-CIQx6DBb.js";import{n as uf,t as df}from"./useFontPreferences-CH3iNDUl.js";var ff=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=Ie(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=(he(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:(he(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=Ie(t);return`${n.length}`,n.forEach((e,t)=>{let n=he(e.id)||[];`${t}${e.role}${e.id}${n.length}`}),e?this.truncateMessages(n):n},async getAppStatus(){let e=le.getState(),t=wa.getState(),n=Ia.getState(),r=e.currentDirectory||null,i=Te.getDirectory()??null,a=Le(),o=new Set,s={};a.forEach(e=>{let t=e.directory;typeof t==`string`&&t.trim().length>0?(o.add(t),s[t]=(s[t]??0)+1):s[`(none)`]=(s[`(none)`]??0)+1});let c=(()=>{if(typeof window>`u`)return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem(`lastDirectory`),homeDirectory:window.localStorage.getItem(`homeDirectory`)}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}})(),l=S(),u=typeof window<`u`&&!!window.__YURI_ELECTRON__,d=async e=>{try{return await e.json()}catch{return null}},p=async e=>{try{return await e.text()}catch{return null}},m=async e=>{try{let t=await f(e);return t.ok?await d(t):{status:t.status}}catch(e){return{error:e instanceof Error?e.message:String(e)}}},h=null,g=null,_=null,v=null;try{let e=await Te.getSdkClient().location.get(ff(r));h=xe(e)}catch(e){h={error:e instanceof Error?e.message:String(e)}}try{g=(await Te.getSdkClient().location.get(ff(r)))?.project??null}catch(e){g={error:e instanceof Error?e.message:String(e)}}_=await m(`/api/config/settings`);try{let e=await f(`/api/health`),t=e.headers.get(`content-type`)||``,n=await p(e),r=t.toLowerCase().includes(`application/json`),i=null;if(r&&n)try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)&&(i=e)}catch{i=null}v={status:e.status,ok:e.ok,contentType:t,type:r?`json`:`html`,openCodePort:i?.openCodePort??null,openCodeRunning:i?.openCodeRunning??null,openCodeSecureConnection:i?.openCodeSecureConnection??null,openCodeAuthSource:i?.openCodeAuthSource??null,isOpenCodeReady:i?.isOpenCodeReady??null,lastOpenCodeError:i?.lastOpenCodeError??null,preview:n?n.slice(0,120):null}}catch(e){v={error:e instanceof Error?e.message:String(e)}}let y={isGitRepo:null};if(r)try{y.isGitRepo=await Cs(r)}catch(e){y={isGitRepo:null,error:e instanceof Error?e.message:String(e)}}let b=n.projects.map(e=>({id:e.id,path:e.path,label:e.label}));return{runtime:{platform:l?.runtime?.platform??null,isDesktop:u,isVSCode:!!l?.runtime?.isVSCode,hasRuntimeApis:!!l,desktopServerOrigin:null},location:typeof window<`u`?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:r,opencodeDirectory:h?.directory||h?.worktree||i,homeDirectory:e.homeDirectory||null,isHomeReady:e.isHomeReady,hasPersistedDirectory:e.hasPersistedDirectory,isSwitchingDirectory:e.isSwitchingDirectory},projects:{total:n.projects.length,activeProjectId:n.activeProjectId,samples:b},sessions:{total:a.length,currentSessionId:t.currentSessionId,lastLoadedDirectory:t.lastLoadedDirectory,uniqueDirectories:o.size,directorySamples:Array.from(o).slice(0,5),directoryCounts:s},worktrees:{available:t.availableWorktrees.length,metadataEntries:t.worktreeMetadata.size},git:y,localStorage:c,opencode:{pathInfo:h,projectInfo:g,health:v},yuri:{settingsInfo:_}}},async buildDiagnosticsReport(){let e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return Yn(e)},async copyDiagnosticsReport(){let e=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(e),report:e}},checkLastMessage(){let e=this.getLastAssistantMessage();if(!e)return!1;let t=e.isEmpty||e.isEmptyResponse;return t&&(console.error(`[ALERT] PROBLEMATIC MESSAGE DETECTED!`),e.messageId,e.isEmpty,e.isEmptyResponse,e.partsCount,e.parts.length>0&&e.parts),t},getStreamingState(){let e=wa.getState(),t=dr.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=Ie(e).filter(e=>e.role===`assistant`).filter(e=>{let t=he(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=he(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=Ie(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=he(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=Ie(e).filter(e=>e.role===`assistant`);if(t.length===0)return null;let n=t[t.length-1],r=(he(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=dr.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}}},ke(),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(ee(),1),Q=_n(),pf=async()=>{if(typeof window>`u`)return;let e=null;try{e=Ft(`lastDirectory`)}catch(e){console.warn(`Failed to read saved directory preferences:`,e)}e&&!m()&&le.getState().setDirectory(e,{showOverlay:!1})},mf=new Map,hf=e=>mf.get(e)??null,gf=({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:i},a={})=>{let o=mf.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 mf.set(e,s),s},_f=async({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,startWatchers:i,onError:a})=>{await gf({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:a})&&i()},vf=(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 yf(e){return!e||e===`idle`?null:e===`ready`?`ok`:e===`error`?`unreachable`:`auth`}function bf(e,t){let n=e.via===`relay`;return t?n:!n}function xf(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?yf(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||bf(o,a))&&(u=Math.max(0,Math.round(o.latencyMs))),{statusKind:c,showViaRelay:l,latencyMs:u}}var $=G(),Sf=`local`,Cf=9e4,wf=`SSH connection cancelled`,Tf=e=>I(e),Ef={},Df=e=>{let t=O(e);if(!t)return e.trim();try{let e=new URL(t);return e.pathname.endsWith(`/`)||(e.pathname=`${e.pathname}/`),e.toString()}catch{return t}},Of=()=>typeof window>`u`?``:window.__YURI_LOCAL_ORIGIN__||window.location.origin,kf=async()=>b()?A().catch(()=>``):``,Af=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`,jf=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`,Mf=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Nf=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Pf=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`,Ff=e=>new Promise(t=>window.setTimeout(t,e)),If=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`}},Lf=async()=>{let e=await fc().catch(()=>[]),t={};for(let n of e)t[n.id]=n;return t},Rf=async(e,t,n,r)=>{let i=Date.now()+t;for(;Date.now()<i;){if(r?.())throw Error(wf);let t=(await fc(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 Ff(700)}throw r?.()?Error(wf):Error(`Timed out waiting for SSH connection`)},zf=e=>({id:Sf,label:`Local`,url:e||Of()}),Bf=e=>{let t=typeof window>`u`?``:window.location.href,n=e.find(e=>e.id===Sf)?.url||Of(),r=d(),i=O(n)||n,a=O(t)||t,o=u(),s=e.find(e=>e.relay&&Tf(e)===o);if(s)return{id:s.id,label:s.label,url:s.url};if(r&&j(r,n))return{id:Sf,label:`Local`,url:i};let c=e.find(e=>r?j(r,P(e)):!1);if(c)return{id:c.id,label:c.label,url:O(P(c))||P(c)};if(t&&j(t,n))return{id:Sf,label:`Local`,url:i};let l=e.find(e=>t?j(t,e.url):!1);return l?{id:l.id,label:l.label,url:O(l.url)||l.url}:t.startsWith(`yuri-ui://`)?{id:Sf,label:`Local`,url:i}:{id:`custom`,label:T(a||`Instance`),url:a}};function Vf({open:e,onOpenChange:t,embedded:n=!1,onHostSwitched:r,onBusyChange:a}){let{t:s}=Xn(),c=K(e=>e.setSettingsDialogOpen),l=K(e=>e.setSettingsPage),u=Ko(e=>e.isConnected),d=Ko(e=>e.connectionPhase),[f,m]=Z.useState([]),[h,g]=Z.useState(null),[_,v]=Z.useState(()=>({...Ef}));Z.useEffect(()=>{Object.assign(Ef,_)},[_]);let[y,x]=Z.useState(!1),[S,A]=Z.useState(!1),[j,I]=Z.useState(!1),L=xc(),R=Lc(),[z,B]=Z.useState(null),V=z||R,H=Z.useRef(!1),U=J(e=>{H.current=e!==null,B(e),a?.(e!==null)}),[W,ee]=Z.useState({}),[te,ne]=Z.useState({}),[re,G]=Z.useState({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),[ie,ae]=Z.useState(``),[oe,se]=Z.useState(()=>Of()),[ce,le]=Z.useState(null),[ue,de]=Z.useState(``),[fe,pe]=Z.useState(``),[me,he]=Z.useState(0),ge=Z.useRef(0),_e=Z.useMemo(()=>[zf(oe),...f.map(e=>({...e,url:O(e.url)||e.url}))],[f,oe]),ve=Z.useMemo(()=>new Set(Object.keys(W)),[W]),ye=Z.useMemo(()=>_e.filter(e=>e.id===Sf||w(e,ve)),[_e,ve]);Z.useEffect(()=>i(()=>he(e=>e+1)),[]);let be=Z.useMemo(()=>Bf(_e),[_e,me]),xe=Z.useMemo(()=>o().startsWith(`relay:`),[me]),Se=Z.useMemo(()=>{let e=h||Sf;return _e.find(t=>t.id===e)?.label||s(`desktopHostSwitcher.instance.local`)},[_e,h,s]),Ce=Z.useCallback(async(e,t)=>{if(p()){I(!0),ae(``);try{let n=e.filter(e=>e.id!==Sf);await D({hosts:n,defaultHostId:t}),m(n),g(t)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToSave`))}finally{I(!1)}}},[s]),we=Z.useCallback(()=>{l(`remote-instances`),c(!0),t(!1)},[t,c,l]),Te=Z.useCallback(async()=>{if(p()){x(!0),ae(``);try{let[e,t,n]=await Promise.all([M(),ac().catch(()=>({instances:[]})),Lf()]);e.localOrigin&&se(e.localOrigin);let r={};for(let e of t.instances)r[e.id]=!0;m(e.hosts||[]),g(e.defaultHostId??null),ee(r),ne(n)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToLoad`)),m([]),g(null),ee({}),ne({})}finally{x(!1)}}},[s]),Ee=Z.useCallback(async e=>{if(p()){A(!0);try{let t=await kf(),n=await Promise.all(e.map(async e=>{let n=async()=>{let t=await E(e.relay,{clientToken:e.clientToken||null}).catch(()=>({status:`unreachable`,latencyMs:0}));return{status:t.status,latencyMs:t.latencyMs,...t.status===`ok`?{via:`relay`}:{}}};if(e.relay&&!e.apiUrl)return[e.id,await n()];let r=O(b()?P(e):e.url);if(!r)return[e.id,{status:`unreachable`,latencyMs:0}];let i=e.id===Sf?t:e.clientToken||``,a=await k(r,{clientToken:i||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(Mf(a.status)&&e.relay){let t=await n();if(t.status===`ok`)return[e.id,t]}return[e.id,{status:a.status,latencyMs:a.latencyMs}]})),r={};for(let[e,t]of n)r[e]=t;v(r)}finally{A(!1)}}},[]);Z.useEffect(()=>{if(!e){le(null),de(``),pe(``),B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),ae(``);return}Te()},[e,Te]),Z.useEffect(()=>{e&&Ee(ye)},[e,ye,Ee]),Z.useEffect(()=>{if(!e||!p())return;let t=!1,n=async()=>{let e=await Lf();t||ne(e)};n();let r=window.setInterval(()=>{typeof document<`u`&&document.visibilityState!==`visible`||n()},1500);return()=>{t=!0,window.clearInterval(r)}},[e]);let De=J(async e=>{if(H.current||L)return;let t=e.id===Sf?oe:O(e.url)||``,n=e.id===Sf?oe:O(P(e))||``,i=!!e.relay&&!e.apiUrl&&e.id!==Sf;if(!t&&!i)return;if(b()){if(!n&&!e.relay||L)return;U(e.id);try{let t=e.id===Sf?await kf():null,i=await Oc({host:e,inlineProgress:!0,cachedProbe:_[e.id]||null,...e.id===Sf?{localApiOrigin:n,localClientToken:t}:{}});v(t=>({...t,[e.id]:i.status})),i.ok&&r?.()}finally{U(null)}return}let a=!!W[e.id];if(e.id!==Sf&&a&&p()){let n=te[e.id],i=await fc(e.id).then(t=>t.find(t=>t.id===e.id)||null).catch(()=>null);i&&(n=i,ne(t=>({...t,[e.id]:i})));let a=O(n?.localUrl||e.url||``);if(n?.phase===`ready`&&a){let e=Df(a);r?.(),window.location.assign(e);return}B(e.id);let o=ge.current+1;ge.current=o,G({open:!0,hostId:e.id,hostLabel:T(e.label),phase:`master_connecting`,detail:null,error:null,errorCode:null});try{if(await tc(e.id),o!==ge.current)return;let n=await Rf(e.id,Cf,e=>{ne(t=>({...t,[e.id]:e})),G(t=>({...t,phase:e.phase,detail:e.detail||null,errorCode:e.errorCode||null}))},()=>o!==ge.current);if(o!==ge.current)return;let i=Df(O(n.localUrl||``)||t);r?.(),window.location.assign(i);return}catch(t){if(o!==ge.current)return;let n=t instanceof Error?t.message:String(t);if(n===wf)return;let r=$s(re.errorCode,n);G(e=>({...e,error:n,errorCode:r})),ji.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Wc(s(gc(r)),r,n)});return}finally{o===ge.current&&B(null)}}if(e.id!==Sf&&p()){B(e.id);let n=await k(t,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(v(t=>({...t,[e.id]:{status:n.status,latencyMs:n.latencyMs}})),Mf(n.status)){ji.error(s(`desktopHostSwitcher.toast.instanceUnreachable`,{host:T(e.label)})),B(null);return}}let o=Df(t);r?.();try{window.location.assign(o)}catch{window.location.href=o}}),Oe=Z.useCallback(()=>{le(null),de(``),pe(``)},[]),ke=Z.useCallback(e=>{e.stopPropagation()},[]),Ae=Z.useCallback(async()=>{if(!ce)return;if(ce===Sf){Oe();return}let e=F(fe);if(!e){ae(s(`desktopHostSwitcher.error.invalidUrl`));return}let t=e.persistedUrl,n=(ue||T(t)).trim(),r=f.map(e=>e.id===ce?{...e,label:n,url:t,apiUrl:t}:e);await Ce(r,h),Oe(),e.redeemUrl&&window.location.assign(e.redeemUrl)},[Oe,f,h,ue,fe,ce,Ce,s]),je=Z.useCallback(async e=>{await Ce(f,e===Sf?Sf:e)},[f,Ce]),Me=J(async e=>{if(H.current||L)return;U(e.id);let t=e=>{ji.error(s(`desktopHostSwitcher.error.failedToOpenNewWindow`),{description:e instanceof Error?e.message:String(e)})};try{if(e.relay&&e.id!==Sf)await C(e.id);else{let t=e.id===Sf?oe:P(e);if(!t)return;let n=Df(t);await N(n,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null})}r?.()}catch(e){t(e)}finally{U(null)}}),Ne=J(async()=>{ge.current+=1,B(null),G(e=>({...e,open:!1,hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}));let e=Df(oe);if(b()){if(L)return;let e=await kf();(await Oc({host:zf(oe),localApiOrigin:oe,localClientToken:e})).ok&&r?.();return}r?.(),window.location.assign(e)}),Pe=Z.useCallback(async()=>{let e=re.hostId||V;ge.current+=1,B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),!(!e||e===Sf||!p())&&await sc(e).catch(()=>{})},[re.hostId,V]),Fe=Z.useCallback(()=>{let e=re.hostId;if(!e)return;let t=_e.find(t=>t.id===e);t&&De(t)},[_e,De,re.hostId]),Ie=J(async e=>{if(!(!p()||H.current||L)){U(e.id);try{await tc(e.id),(await Rf(e.id,Cf,e=>{ne(t=>({...t,[e.id]:e}))})).phase===`ready`&&ji.success(s(`desktopHostSwitcher.toast.sshConnected`,{host:T(e.label)}))}catch(t){let n=t instanceof Error?t.message:String(t);if(n!==wf){let t=$s(null,n);ji.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Wc(s(gc(t)),t,n)})}}finally{U(null)}}});if(!p())return null;let Le=p(),Re=(0,$.jsxs)($.Fragment,{children:[n?(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-[var(--interactive-border)] px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex items-baseline gap-1.5 typography-ui-label`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.current`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`•`}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.default`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(Se)})]}),(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors`,`hover:text-foreground hover:bg-interactive-hover`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),onClick:()=>void Ee(ye),disabled:!Le||y||S,"aria-label":s(`desktopHostSwitcher.actions.refreshInstancesAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)})})]})}):(0,$.jsxs)(hs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`server`,className:`h-5 w-5`}),s(`desktopHostSwitcher.title`)]}),(0,$.jsx)(ys,{children:s(`desktopHostSwitcher.description`)})]}),!n&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentDefaultColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(Se)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsxs)(er,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Ee(ye),disabled:!Le||y||S,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)}),s(`desktopHostSwitcher.actions.refresh`)]})})]}),!Le&&(0,$.jsx)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.state.limitedOnPage`)})}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:Y(`space-y-1`,n&&`space-y-1.5 px-3 py-1`),children:y?(0,$.jsx)(`div`,{className:`px-2 py-2 text-muted-foreground text-sm`,children:s(`desktopHostSwitcher.state.loading`)}):ye.map(e=>{let t=e.id===Sf,r=!!W[e.id],i=e.id===be.id,a=(h||Sf)===e.id,o=_[e.id]||null,c=te[e.id]||null,l=xf({isActive:i,isSsh:r,runtimeIsConnected:u,runtimeConnectionPhase:d,currentTransportIsRelay:xe,probe:o,sshPhase:c?.phase}),f=l.statusKind,p=l.showViaRelay,m=ce===e.id,g=t?oe:O(e.url)||e.url,v=e.id===Sf?s(`desktopHostSwitcher.instance.local`):T(e.label),y=e.relay&&!e.apiUrl?s(`mobile.connect.relay.badge`):T(g);return(0,$.jsxs)(`div`,{className:Y(`app-region-no-drag group flex items-center gap-2 px-2.5 py-2 rounded-md overflow-hidden`,n&&`rounded-xl bg-[var(--surface-muted)] px-3 py-2.5`,n&&i&&`bg-[var(--interactive-selection)]/25`,m?`bg-interactive-hover/20`:`hover:bg-interactive-hover/30`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-2 flex-1 min-w-0 text-left`,m&&`pointer-events-none opacity-70`),onClick:()=>void De(e),disabled:!!V,"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.switchToAria`,{instance:v}),children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,$.jsx)(`span`,{className:Y(`h-2 w-2 rounded-full flex-shrink-0`,Af(f))}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium truncate text-foreground`,children:v}),i&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 text-muted-foreground bg-muted px-1 rounded leading-none pb-px border border-border/50`,children:s(`desktopHostSwitcher.header.current`)}),r&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 px-1 rounded leading-none pb-px text-[var(--status-info)] bg-[var(--status-info)]/10`,children:`SSH`})]}),(0,$.jsxs)(`div`,{className:Y(`typography-micro truncate`,jf(f)),children:[r&&(!i||V===e.id)?s(If(c?.phase)):s(Pf(f)),l.latencyMs==null?``:s(`desktopHostSwitcher.status.ping`,{ms:l.latencyMs}),p?` · ${s(`settings.remoteInstances.clientAuth.state.viaRelay`)}`:``]}),(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70 truncate font-mono`,children:y})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[r&&!t&&(c?.phase===`idle`||!c?.phase?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 px-2.5`,disabled:!!V,onClick:t=>{t.stopPropagation(),Ie(e)},children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(X,{name:`plug-2`,className:`h-3.5 w-3.5`}),s(`desktopHostSwitcher.actions.connect`)]}):(0,$.jsx)(`div`,{className:`h-8 w-8 opacity-0 pointer-events-none`,"aria-hidden":`true`})),(0,$.jsxs)(Ys,{delayDuration:600,children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`app-region-no-drag h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors`,a?`text-primary hover:text-primary/80`:`text-muted-foreground/60 hover:text-primary/80`),onClick:()=>void je(e.id),"aria-label":s(a?`desktopHostSwitcher.actions.defaultInstanceAria`:`desktopHostSwitcher.actions.setAsDefaultAria`),disabled:j||!a&&Nf(f),children:a?(0,$.jsx)(X,{name:`star-fill`,className:`h-4 w-4`}):(0,$.jsx)(X,{name:`star`,className:`h-4 w-4`})})}),(0,$.jsx)(Js,{sideOffset:6,children:s(a?`desktopHostSwitcher.header.default`:`desktopHostSwitcher.actions.setAsDefault`)})]}),(0,$.jsxs)(Ys,{delayDuration:600,children:[(0,$.jsx)(qs,{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`,Nf(f)?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground/60 hover:text-foreground`),onClick:t=>{t.stopPropagation(),Me(e)},disabled:!!V||Nf(f),"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.openInNewWindowAria`),children:(0,$.jsx)(X,{name:V===e.id?`loader-4`:`window`,className:Y(`h-4 w-4`,V===e.id&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:Nf(f)?s(`desktopHostSwitcher.state.instanceUnreachable`):s(`desktopHostSwitcher.actions.openInNewWindow`)})]})]})]},e.id)})})}),Le&&ce&&ce!==Sf&&(0,$.jsxs)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground`,children:s(`desktopHostSwitcher.edit.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(er,{type:`button`,variant:`outline`,size:`sm`,onClick:Oe,disabled:j,children:s(`desktopHostSwitcher.actions.cancel`)}),(0,$.jsxs)(er,{type:`button`,size:`sm`,onClick:()=>void Ae(),disabled:j,children:[j?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):null,s(`desktopHostSwitcher.actions.save`)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,$.jsx)(Ks,{value:ue,onChange:e=>de(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.labelPlaceholder`),disabled:j}),(0,$.jsx)(Ks,{value:fe,onChange:e=>pe(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.urlPlaceholder`),disabled:j})]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 border-t border-[var(--interactive-border)]`,children:(0,$.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-2 py-2 text-left text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,onClick:we,disabled:!!V,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:s(`desktopHostSwitcher.actions.addInstance`)})]})}),ie&&(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-status-error`,children:ie})]}),ze=(0,$.jsx)(xs,{open:re.open,onOpenChange:e=>{if(!e&&V){Pe();return}G(t=>({...t,open:e,...e?{}:{hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}}))},children:(0,$.jsxs)(_s,{className:`w-[min(28rem,calc(100vw-2rem))] max-w-none`,children:[(0,$.jsxs)(hs,{children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(`h-4 w-4`,!re.error&&`animate-spin`)}),s(`desktopHostSwitcher.ssh.connectingTo`,{host:re.hostLabel||s(`desktopHostSwitcher.ssh.instanceFallback`)})]}),re.error?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ys,{className:`sr-only`,children:s(rc($s(re.errorCode,re.error)))}),(0,$.jsx)(mc,{errorCode:re.errorCode,detail:re.error})]}):(0,$.jsx)(ys,{children:re.detail||s(If(re.phase))})]}),re.error?(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{we(),Pe()},children:s(`desktopHostSwitcher.sshError.openRemoteSettings`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void Ne(),children:s(`desktopHostSwitcher.actions.switchToLocal`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,onClick:Fe,disabled:!re.hostId,children:s(`desktopHostSwitcher.actions.retry`)})]}):null]})});return n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-full max-h-[70vh] flex flex-col overflow-hidden gap-2`,children:Re}),ze]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xs,{open:e,onOpenChange:e=>{!e&&H.current||t(e)},children:(0,$.jsx)(_s,{className:`w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3`,children:Re})}),ze]})}function Hf(){let e=(0,Q.c)(11),[t,n]=Z.useState(!1),{t:r}=Xn();if(!p())return null;let i,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>n(!0),a=(0,$.jsx)(X,{name:`server`,className:`h-4 w-4`}),e[0]=i,e[1]=a):(i=e[0],a=e[1]);let o;e[2]===r?o=e[3]:(o=r(`desktopHostSwitcher.actions.switchInstance`),e[2]=r,e[3]=o);let s;e[4]===o?s=e[5]:(s=(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,"data-yuri-host-switcher":!0,className:`w-full justify-center`,onClick:i,children:[a,o]}),e[4]=o,e[5]=s);let c;e[6]===t?c=e[7]:(c=(0,$.jsx)(Vf,{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 Uf=e=>e.shouldUseDesktopShellPasswordLogin?`locked`:`error`,Wf=`/auth/session`,Gf=4,Kf=1500,qf=`yuri.uiAuth.trustDevice`,Jf=`desktop-local`,Yf=`desktop-local`,Xf=()=>{if(typeof window>`u`)return``;let e=window.__YURI_LOCAL_ORIGIN__;return typeof e==`string`?e.trim():``},Zf=(e,t)=>{let n=O(e),r=O(t);if(!n||!r)return!1;try{return new URL(n).origin===new URL(r).origin}catch{return!1}},Qf=()=>p(),$f=e=>{let t=e.replace(/^\[|\]$/g,``);return t===`localhost`||t===`127.0.0.1`||t===`::1`},ep=()=>{if(!p())return!1;let e=Xf();if(!e)return!1;let t=d()||(typeof window<`u`?window.location.origin:``);if(Zf(e,t))return!0;try{let e=O(t);return!!(e&&$f(new URL(e).hostname))}catch{return!1}},tp=()=>ep()?{clientKind:Jf,dedupeKey:Yf}:{},np=async()=>await f(Wf,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}}),rp=()=>typeof window>`u`?!1:window.localStorage.getItem(qf)===`true`,ip=async(e,t)=>{let n=Qf();return await f(Wf,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({password:e,trustDevice:t,issueClientToken:n,clientLabel:`Yuri Desktop`,...tp()})})},ap=async()=>{if(!p())return``;let e=await f(`/api/client-auth/clients`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:`Yuri Desktop`,...tp()})}).catch(()=>null);if(!e?.ok)return``;let t=await e.json().catch(()=>null);return typeof t?.token==`string`?t.token.trim():``},op=()=>p()&&!ep(),sp=async(e,t)=>{if(!p()||typeof window>`u`)return null;let r=await v(`desktop_remote_password_login`,{url:d(),password:e,trustDevice:t,requestHeaders:n()}).catch(()=>null);if(!r||typeof r!=`object`)return null;let i=r.token,a=r.status;return{token:typeof i==`string`?i.trim():``,...typeof a==`number`?{status:a}:{}}},cp=async(e,t)=>{if(!p()||!t)return;let n=await M().catch(()=>null);if(!n)return;if(n.localOrigin&&Zf(n.localOrigin,e)){await D({hosts:n.hosts,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted,localClientToken:t}).catch(()=>void 0);return}let r=!1,i=n.hosts.map(n=>!Zf(P(n),e)||n.clientToken===t?n:(r=!0,{...n,clientToken:t}));r&&await D({hosts:i,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted}).catch(()=>void 0)},lp=async e=>{if(!e)return;let r=d(),i=n();await cp(r,e),s({apiBaseUrl:r,clientToken:e,requestHeaders:Object.keys(i).length>0?i:null,relay:t()})},up=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},dp=()=>{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)(Gc,{width:120,height:120})}),e[0]=t):t=e[0],t},fp=e=>{let t=(0,Q.c)(23),{onRetry:n,errorType:r,retryAfter:i,children:a}=e,o=r===void 0?`network`:r,{t:s}=Xn(),c=o===`rate-limit`,l=i?Math.ceil(i/60):1,u;t[0]!==c||t[1]!==s?(u=s(c?`sessionAuth.error.rateLimitTitle`:`sessionAuth.error.networkTitle`),t[0]=c,t[1]=s,t[2]=u):u=t[2];let d;t[3]===u?d=t[4]:(d=(0,$.jsx)(`h1`,{className:`typography-ui-header font-semibold text-destructive`,children:u}),t[3]=u,t[4]=d);let f;t[5]!==c||t[6]!==l||t[7]!==s?(f=c?s(l>1?`sessionAuth.error.rateLimitDescriptionPlural`:`sessionAuth.error.rateLimitDescriptionSingle`,{minutes:l}):s(`sessionAuth.error.networkDescription`),t[5]=c,t[6]=l,t[7]=s,t[8]=f):f=t[8];let p;t[9]===f?p=t[10]:(p=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground max-w-xs`,children:f}),t[9]=f,t[10]=p);let m;t[11]!==d||t[12]!==p?(m=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[d,p]}),t[11]=d,t[12]=p,t[13]=m):m=t[13];let h;t[14]===s?h=t[15]:(h=s(`sessionAuth.error.retry`),t[14]=s,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(er,{type:`button`,onClick:n,className:`w-full max-w-xs`,children:h}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;return t[19]!==a||t[20]!==m||t[21]!==g?(_=(0,$.jsx)(up,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[m,g,a]})}),t[19]=a,t[20]=m,t[21]=g,t[22]=_):_=t[22],_},pp=({children:e})=>{let{t}=Xn(),n=Z.useMemo(()=>m(),[]),r=n,a=Z.useMemo(()=>p()&&!n,[n]),[o,s]=Z.useState(()=>r?`authenticated`:`pending`),[c,d]=Z.useState(``),[f,h]=Z.useState(!1),[g,_]=Z.useState(``),[v,y]=Z.useState(void 0),[b,x]=Z.useState(!1),[S,C]=Z.useState(Zs),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(()=>rp()),[A,j]=Z.useState(null),[M,N]=Z.useState(r),P=Z.useRef(null),F=Z.useRef(r);Z.useEffect(()=>{typeof window>`u`||window.localStorage.setItem(qf,O?`true`:`false`)},[O]);let I=Z.useCallback(async()=>{if(r)return Zs;try{let e=await Ac();return C(e),e}catch{return C(Zs),Zs}},[r]);Z.useEffect(()=>{let e=!1;if(!r)return(async()=>{try{if(!window.isSecureContext||!ws()){e||T(!1);return}e||T(!0)}catch{e||T(!1)}})(),()=>{e=!0}},[r]);let L=Z.useRef(0),R=Z.useRef(null),z=Z.useRef(null),B=Z.useCallback(()=>{R.current!==null&&(window.clearTimeout(R.current),R.current=null)},[]),V=Z.useCallback(()=>{L.current=0,B()},[B]),H=Z.useCallback(()=>L.current>=Gf?!1:(L.current+=1,B(),R.current=window.setTimeout(()=>{R.current=null,z.current?.()},Kf*L.current),!0),[B]);Z.useEffect(()=>B,[B]);let U=Z.useCallback(async()=>{if(r){s(`authenticated`);return}s(e=>e===`authenticated`?e:`pending`);try{let[e,t]=await Promise.all([np(),I()]),n=await e.text();if(e.ok){V(),s(`authenticated`),x(!1),_(``),y(void 0);return}if(e.status===401){let e={};try{e=JSON.parse(n)}catch{e={}}V(),x(e.tunnelLocked===!0),C(t),s(`locked`),y(void 0);return}if(e.status===429){let e={};try{e=JSON.parse(n)}catch{e={}}V(),y(e.retryAfter),x(!1),s(`rate-limited`);return}if(H())return;s(`error`),x(!1)}catch(e){if(console.warn(`Failed to check session status:`,e),Uf({shouldUseDesktopShellPasswordLogin:op()})===`locked`){s(`locked`),y(void 0),x(!1);return}if(H())return;s(`error`),x(!1)}},[I,V,H,r]);Z.useEffect(()=>{z.current=U},[U]),Z.useEffect(()=>{r||U()},[U,r]),Z.useEffect(()=>{if(o===`pending`||o===`authenticated`||typeof document>`u`)return;let e=document.getElementById(`initial-loading`);if(!e)return;e.classList.add(`fade-out`);let t=window.setTimeout(()=>{e.remove()},300);return()=>{window.clearTimeout(t)}},[o]),Z.useEffect(()=>{if(r)return;let e=vf(e=>{l(e)&&(d(``),_(``),y(void 0),x(!1),V(),N(!1),F.current=!1,s(`pending`),U())}),t=i(t=>e.schedule(t));return()=>{t(),e.cancel()}},[U,V,r]),Z.useEffect(()=>{!r&&o===`locked`&&(F.current=!1,N(!1))},[r,o]),Z.useEffect(()=>{o===`locked`&&P.current&&(P.current.focus(),P.current.select())},[o]),Z.useEffect(()=>{if(!r&&o===`authenticated`&&!F.current){F.current=!0;let e=!1;return gf({runtimeKey:u(),initializeAppearance:ln,syncSettings:on,applyDirectory:pf,onError:(e,t)=>{console.error(`[SessionAuthGate] ${e} settings hydration failed:`,t)}},{force:!0}).then(()=>{e||N(!0)}),()=>{e=!0}}},[r,o]);let W=async e=>{e.preventDefault(),await ne(!1)},ee=Z.useCallback(async()=>{j(`register`),D(!0);try{await ec()}finally{j(null),D(!1)}await I()},[I]),te=Z.useCallback(()=>{jc(),j(null),D(!1)},[]),ne=Z.useCallback(async e=>{if(!b&&!(!c||f)){E&&te(),h(!0),_(``);try{if(op()){let e=await sp(c,O);if(e?.token){d(``),x(!1),await lp(e.token),s(`authenticated`);return}if(e?.status===401){_(t(`sessionAuth.error.incorrectPassword`)),x(!1),s(`locked`);return}if(e?.status===429){y(void 0),x(!1),s(`rate-limited`);return}}let n=await ip(c,O);if(n.ok){let r=await n.json().catch(()=>null),i=Qf(),a=``;if(i&&(a=typeof r?.clientToken==`string`&&r.clientToken.trim()?r.clientToken.trim():``,a||=(await sp(c,O))?.token||await ap()),d(``),x(!1),a&&await lp(a),e&&w)try{await ee(),ji.success(t(`sessionAuth.toast.passkeyAdded`)),s(`authenticated`);return}catch(e){if(uc(e))ji.message(t(`sessionAuth.toast.passkeySetupCanceled`));else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);ji.error(n)}s(`authenticated`);return}s(`authenticated`);return}if(n.status===401){_(t(`sessionAuth.error.incorrectPassword`)),x(!1),s(`locked`);return}if(n.status===429){let e=await n.json().catch(()=>({}));y(e.retryAfter),x(!1),s(`rate-limited`);return}_(t(`sessionAuth.error.unexpectedResponse`)),x(!1),s(`error`)}catch(e){console.warn(`Failed to submit UI password:`,e);let n=op()?await sp(c,O):null;if(n?.token){d(``),x(!1),await lp(n.token),s(`authenticated`);return}if(n?.status===401){_(t(`sessionAuth.error.incorrectPassword`)),x(!1),s(`locked`);return}if(n?.status===429){y(void 0),x(!1),s(`rate-limited`);return}_(t(`sessionAuth.error.networkRetry`)),x(!1),s(`error`)}finally{h(!1)}}},[te,E,f,b,c,ee,w,t,O]),re=Z.useCallback(async()=>{if(!(f||!w)){if(E){te();return}D(!0),j(`auth`),_(``);try{let e=await lc(O,{issueClientToken:Qf(),clientLabel:`Yuri Desktop`,...tp()}),t=Qf()&&typeof e?.clientToken==`string`&&e.clientToken.trim()?e.clientToken.trim():``;t&&await lp(t),d(``),s(`authenticated`)}catch(e){if(uc(e))_(``);else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySignInCanceled`);_(n)}}finally{j(null),D(!1)}}},[te,E,f,w,t,O]),G=Z.useCallback(async()=>{if(!(f||b||!w)){if(E){te();return}if(o!==`authenticated`){if(!c){_(t(`sessionAuth.error.enterPasswordForPasskey`));return}await ne(!0);return}_(``);try{await ee(),ji.success(t(`sessionAuth.toast.passkeyAdded`))}catch(e){if(uc(e)){ji.message(t(`sessionAuth.toast.passkeySetupCanceled`));return}let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);ji.error(n)}}},[te,ne,E,f,b,c,ee,o,w,t]),ie=w&&S.enabled,ae=ie&&S.hasPasskeys;return o===`pending`||o===`authenticated`&&!M?(0,$.jsx)(dp,{}):o===`error`?(0,$.jsx)(fp,{onRetry:()=>{V(),U()},errorType:`network`,children:a&&(0,$.jsxs)(`div`,{className:`w-full max-w-xs`,children:[(0,$.jsx)(Hf,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})}):o===`rate-limited`?(0,$.jsx)(fp,{onRetry:()=>void U(),errorType:`rate-limit`,retryAfter:v}):o===`locked`?(0,$.jsx)(up,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 w-full max-w-xs`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-1 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:t(b?`sessionAuth.locked.tunnelTitle`:`sessionAuth.locked.unlockTitle`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(b?`sessionAuth.locked.tunnelDescription`:`sessionAuth.locked.passwordDescription`)})]}),!b&&(0,$.jsxs)(`form`,{onSubmit:W,className:`w-full space-y-2`,children:[ae&&(0,$.jsxs)(er,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>void re(),disabled:f||E&&A!==`auth`,children:[E?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:t(E&&A===`auth`?`sessionAuth.actions.cancelPasskey`:`sessionAuth.actions.usePasskey`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(X,{name:`lock`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60`}),(0,$.jsx)(Ks,{id:`yuri-ui-password`,ref:P,type:`password`,autoComplete:`current-password`,placeholder:t(`sessionAuth.password.placeholder`),value:c,onChange:e=>{d(e.target.value),g&&_(``)},className:`pl-10`,"aria-invalid":!!g||void 0,"aria-describedby":g?`yuri-ui-auth-error`:void 0,disabled:f})]}),(0,$.jsx)(er,{type:`submit`,size:`icon`,disabled:!c||f,"aria-label":t(f?`sessionAuth.actions.unlockingAria`:`sessionAuth.actions.unlockAria`),children:f?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`})})]}),ie?(0,$.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(Ts,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void G(),disabled:f,children:t(E&&A===`register`?`sessionAuth.actions.cancelPasskeySetup`:`sessionAuth.actions.addPasskey`)})]}):(0,$.jsxs)(`label`,{className:`flex items-center justify-center gap-2 pt-1 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(Ts,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),g&&(0,$.jsx)(`p`,{id:`yuri-ui-auth-error`,className:`typography-meta text-destructive`,children:g})]}),a&&(0,$.jsxs)(`div`,{className:`w-full`,children:[(0,$.jsx)(Hf,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})]})}):(0,$.jsx)($.Fragment,{children:e})},mp=e=>!!e&&typeof e==`object`&&!Array.isArray(e),hp=e=>typeof e==`string`&&e.trim()?e.trim():null,gp=e=>{if(!mp(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=hp(e.minimumVersion),i=hp(e.targetVersion);if(!r||!i||typeof e.canInstall!=`boolean`)throw Error(`Could not check OpenCode compatibility`);return{state:t,version:hp(e.version),installation:n,minimumVersion:r,targetVersion:i,canInstall:e.canInstall,guidance:hp(e.guidance)}},_p=async()=>{let e=await f(`/api/opencode/compatibility`,{signal:AbortSignal.timeout(2e4)});if(!e.ok)throw Error(`Could not check OpenCode compatibility`);return gp(await e.json())},vp=async()=>{let e=await f(`/api/opencode/install-required`,{method:`POST`}),t=await e.json().catch(()=>null),n=mp(t)?t:null,r=hp(n?.error);if(!e.ok||n?.success!==!0||n?.upgraded!==!0)throw Error(r||`OpenCode installation failed`);let i=hp(n.version);if(!i)throw Error(r||`OpenCode installation did not report a verified version`);return{version:i}},yp=(e,t)=>e instanceof Error&&e.message.trim()?e.message.trim():t,bp=({children:e})=>{let{t}=Xn(),[n,r]=Z.useState(null),[a,o]=Z.useState(!1),[s,c]=Z.useState(null),[l,u]=Z.useState(null),d=Z.useId(),f=Z.useRef(null),p=Z.useRef(0);Z.useEffect(()=>{let e=!0,t=async()=>{let t=++p.current;try{let n=await _p();if(!e||t!==p.current)return;r(n),n.state!==`incompatible`&&u(null)}catch{}finally{e&&t===p.current&&o(!0)}};t();let n=i(()=>{e&&(r(null),o(!1),c(null),u(null),t())});return()=>{e=!1,p.current+=1,n()}},[]);let m=n?.state===`incompatible`;Z.useEffect(()=>{m&&(document.getElementById(`initial-loading`)?.remove(),f.current?.focus())},[m]);let h=J(async e=>{if(s)return;let n=++p.current;c(e),u(null);try{if(e===`install`){let e=await vp();if(n!==p.current)return;if(!e.version)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload();return}let i=await _p();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(yp(e,t(`opencodeUpgrade.screen.failedGeneric`)))}finally{n===p.current&&c(null)}});if(!a)return null;if(!m||!n)return(0,$.jsx)($.Fragment,{children:e});let g=!!n.version?.startsWith(`2.`),_=n.installation===`bundled`?`opencodeUpgrade.screen.bundled`:n.installation===`external`?g?`opencodeUpgrade.screen.outdatedExternal`:`opencodeUpgrade.screen.external`:g?`opencodeUpgrade.screen.outdatedLocal`:`opencodeUpgrade.screen.local`,v=n.minimumVersion,y=s!==null;return(0,$.jsx)(`section`,{className:`app-region-drag flex h-full min-h-dvh min-h-0 items-center justify-center overflow-y-auto bg-background px-4 py-10 text-foreground select-none sm:px-6`,"aria-labelledby":d,"aria-busy":y,"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)(Gc,{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(g?`opencodeUpgrade.screen.outdatedTitle`:`opencodeUpgrade.screen.title`)}),(0,$.jsxs)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground text-balance`,children:[t(_,{version:n.version??``,minimum:v}),n.canInstall?(0,$.jsxs)($.Fragment,{children:[` `,t(`opencodeUpgrade.screen.installDescription`,{minimum:v})]}):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:[v,`+`]})]}):null,l?(0,$.jsxs)(`p`,{role:`alert`,className:`mt-5 w-full break-words rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] px-3 py-2 text-left text-sm text-[var(--status-error-text)]`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t(`opencodeUpgrade.screen.failedTitle`)}),` `,l]}):null,(0,$.jsxs)(`div`,{className:`app-region-no-drag mt-7 flex w-full flex-wrap items-center justify-center gap-2`,children:[n.canInstall?(0,$.jsxs)(er,{type:`button`,disabled:y,onClick:()=>void h(`install`),children:[(0,$.jsx)(X,{name:s===`install`?`refresh`:`download`,className:s===`install`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`install`?`status`:void 0,children:s===`install`?t(g?`opencodeUpgrade.screen.updating`:`opencodeUpgrade.screen.installing`):t(g?`opencodeUpgrade.screen.update`:`opencodeUpgrade.screen.install`,{minimum:v})})]}):null,(0,$.jsxs)(er,{type:`button`,variant:n.canInstall?`ghost`:`default`,disabled:y,onClick:()=>void h(`reconnect`),children:[(0,$.jsx)(X,{name:`refresh`,className:s===`reconnect`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`reconnect`?`status`:void 0,children:t(s===`reconnect`?`opencodeUpgrade.screen.reconnecting`:`opencodeUpgrade.screen.reconnect`)})]})]}),(0,$.jsxs)(`a`,{className:`app-region-no-drag mt-6 inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,href:`https://opencode.ai/download`,target:`_blank`,rel:`noopener noreferrer`,children:[t(`opencodeUpgrade.screen.guide`),(0,$.jsx)(X,{name:`external-link`,className:`size-3`})]}),(0,$.jsx)(`div`,{className:`app-region-no-drag mt-3 w-full`,children:(0,$.jsx)(Hf,{})})]})})},xp=e=>{let t=(0,Q.c)(14),{children:n}=e,r=K(Sp),i=K(Cp),a=K(wp),o=K(Tp),s=K(Ep),{deviceType:c,hasTouchInput:l}=Kc(),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=typeof document<`u`&&St(),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 Sp(e){return e.fontSize}function Cp(e){return e.codeFontSize}function wp(e){return e.applyTypography}function Tp(e){return e.padding}function Ep(e){return e.applyPadding}var Dp=e(ne(),1),Op=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}`},kp=class{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){let t=[];return t.push(...this.generateTailwindVariables(e)),t.push(...this.generatePrimaryColors(e.colors.primary)),t.push(...this.generateSurfaceColors(e.colors.surface)),t.push(...this.generateInteractiveColors(e.colors.interactive)),t.push(...this.generateStatusColors(e.colors.status)),t.push(...this.generatePullRequestColors(e)),t.push(...this.generateSyntaxColors(e.colors.syntax)),t.push(...this.generateComponentColors(e.colors,e)),t.push(...this.generateTypographyVariables()),e.config&&t.push(...this.generateConfigVariables(e.config)),t.join(`
|
|
3
|
-
`)}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=Op(e.colors.surface.muted),r=Op(e.colors.surface.subtle),i=Op(e.colors.interactive.border);t.push(` --sidebar-base: ${e.colors.surface.muted} !important;`),n&&t.push(` --sidebar-base-rgb: ${n} !important;`),t.push(` --sidebar: var(--sidebar-base) !important;`),t.push(` --sidebar-foreground: ${e.colors.surface.mutedForeground} !important;`),t.push(` --sidebar-primary: ${e.colors.primary.base} !important;`),t.push(` --sidebar-primary-foreground: ${e.colors.primary.foreground} !important;`),t.push(` --sidebar-accent-base: ${e.colors.surface.subtle} !important;`),r&&t.push(` --sidebar-accent-base-rgb: ${r} !important;`),t.push(` --sidebar-accent: var(--sidebar-accent-base) !important;`),t.push(` --sidebar-accent-foreground: ${e.colors.surface.foreground} !important;`),t.push(` --sidebar-border: ${e.colors.interactive.border} !important;`),i&&t.push(` --sidebar-border-rgb: ${i} !important;`),t.push(` --sidebar-ring: ${e.colors.interactive.focusRing} !important;`);let a=e.metadata.variant===`dark`,o=a?.15:.5,s=a?.1:.3,c=a?.42:.52;if(n)t.push(` --sidebar-overlay-strong: rgb(${n} / ${o}) !important;`),t.push(` --sidebar-overlay-soft: rgb(${n} / ${s}) !important;`),t.push(` --sidebar-vibrancy-overlay: rgb(${n} / ${c}) !important;`);else{let n=e.colors.surface.muted;t.push(` --sidebar-overlay-strong: ${this.opacity(n,o)} !important;`),t.push(` --sidebar-overlay-soft: ${this.opacity(n,s)} !important;`),t.push(` --sidebar-vibrancy-overlay: ${this.opacity(n,c)} !important;`)}return e.colors.charts?.series&&Array.isArray(e.colors.charts.series)&&e.colors.charts.series.forEach((e,n)=>{t.push(` --chart-${n+1}: ${e};`)}),e.colors.loading?(t.push(` --loading-spinner: ${e.colors.loading.spinner||e.colors.primary.base};`),t.push(` --loading-spinner-track: ${e.colors.loading.spinnerTrack||e.colors.surface.muted};`)):(t.push(` --loading-spinner: ${e.colors.primary.base};`),t.push(` --loading-spinner-track: ${e.colors.surface.muted};`)),t}apply(e){let t=this.generate(e),n=document.createElement(`style`);n.id=`opencode-theme-variables`;let r=``;e.metadata.variant===`dark`?(r=`:root {\n${t}\n}\n\n.dark {\n${t}\n}`,document.documentElement.classList.add(`dark`),document.documentElement.classList.remove(`light`)):(r=`:root {\n${t}\n}\n\n:root:not(.dark) {\n${t}\n}`,document.documentElement.classList.remove(`dark`),document.documentElement.classList.add(`light`)),n.textContent=r;let i=document.getElementById(`opencode-theme-variables`);i&&i.remove(),document.head.appendChild(n),document.documentElement.setAttribute(`data-theme`,e.metadata.variant);let a=typeof window<`u`&&window.__YURI_ELECTRON__?.runtime===`electron`&&window.__YURI_ELECTRON__?.macVibrancy===!0;document.documentElement.toggleAttribute(`data-yuri-vibrancy`,a),a&&document.documentElement.toggleAttribute(`data-yuri-vibrancy-ready`,!0)}generatePrimaryColors(e){let t=[];return t.push(` --primary-base: ${e.base};`),t.push(` --primary-hover: ${e.hover||this.darken(e.base,10)};`),t.push(` --primary-active: ${e.active||this.darken(e.base,20)};`),t.push(` --primary-foreground: ${e.foreground||`#ffffff`};`),t.push(` --primary-muted: ${e.muted||this.opacity(e.base,.5)};`),t.push(` --primary-emphasis: ${e.emphasis||this.lighten(e.base,10)};`),t}generateSurfaceColors(e){let t=[];return t.push(` --surface-background: ${e.background};`),t.push(` --surface-foreground: ${e.foreground};`),t.push(` --surface-muted: ${e.muted};`),t.push(` --surface-muted-foreground: ${e.mutedForeground};`),t.push(` --surface-elevated: ${e.elevated};`),t.push(` --surface-elevated-foreground: ${e.elevatedForeground};`),t.push(` --surface-overlay: ${e.overlay};`),t.push(` --surface-subtle: ${e.subtle};`),t}generateInteractiveColors(e){let t=[];return t.push(` --interactive-border: ${e.border};`),t.push(` --interactive-border-hover: ${e.borderHover};`),t.push(` --interactive-border-focus: ${e.borderFocus};`),t.push(` --interactive-selection: ${e.selection};`),t.push(` --interactive-selection-foreground: ${e.selectionForeground};`),t.push(` --interactive-focus: ${e.focus};`),t.push(` --interactive-focus-ring: ${e.focusRing};`),t.push(` --interactive-cursor: ${e.cursor};`),t.push(` --interactive-hover: ${e.hover};`),t.push(` --interactive-active: ${e.active};`),t}generateStatusColors(e){let t=[];return t.push(` --status-error: ${e.error};`),t.push(` --status-error-foreground: ${e.errorForeground};`),t.push(` --status-error-background: ${e.errorBackground};`),t.push(` --status-error-border: ${e.errorBorder};`),t.push(` --status-warning: ${e.warning};`),t.push(` --status-warning-foreground: ${e.warningForeground};`),t.push(` --status-warning-background: ${e.warningBackground};`),t.push(` --status-warning-border: ${e.warningBorder};`),t.push(` --status-success: ${e.success};`),t.push(` --status-success-foreground: ${e.successForeground};`),t.push(` --status-success-background: ${e.successBackground};`),t.push(` --status-success-border: ${e.successBorder};`),t.push(` --status-info: ${e.info};`),t.push(` --status-info-foreground: ${e.infoForeground};`),t.push(` --status-info-background: ${e.infoBackground};`),t.push(` --status-info-border: ${e.infoBorder};`),t}generatePullRequestColors(e){let t=[],n=e.colors.pr;return t.push(` --pr-open: ${n?.open||e.colors.status.success};`),t.push(` --pr-draft: ${n?.draft||e.colors.surface.mutedForeground};`),t.push(` --pr-blocked: ${n?.blocked||e.colors.status.warning};`),t.push(` --pr-merged: ${n?.merged||(e.metadata.variant===`dark`?`#8957e5`:`#8250df`)};`),t.push(` --pr-closed: ${n?.closed||e.colors.status.error};`),t}generateSyntaxColors(e){let t=[];t.push(` --syntax-background: ${e.base.background};`),t.push(` --syntax-foreground: ${e.base.foreground};`),t.push(` --syntax-comment: ${e.base.comment};`),t.push(` --syntax-keyword: ${e.base.keyword};`),t.push(` --syntax-string: ${e.base.string};`),t.push(` --syntax-number: ${e.base.number};`),t.push(` --syntax-function: ${e.base.function};`),t.push(` --syntax-variable: ${e.base.variable};`),t.push(` --syntax-type: ${e.base.type};`),t.push(` --syntax-operator: ${e.base.operator};`);let n=this.generateSyntaxTokens(e);for(let[e,r]of Object.entries(n))t.push(` --syntax-${this.kebabCase(e)}: ${r};`);return t}generateSyntaxTokens(e){let t=e.base,n=e.tokens||{};return{commentDoc:n.commentDoc||this.lighten(t.comment,10),stringEscape:n.stringEscape||this.darken(t.string,20),stringInterpolation:n.stringInterpolation||t.variable,stringRegex:n.stringRegex||this.adjustHue(t.string,15),keywordControl:n.keywordControl||t.keyword,keywordOperator:n.keywordOperator||t.operator,keywordImport:n.keywordImport||this.lighten(t.keyword,10),keywordReturn:n.keywordReturn||this.emphasize(t.keyword),functionCall:n.functionCall||this.lighten(t.function,5),functionBuiltin:n.functionBuiltin||this.darken(t.function,10),method:n.method||t.function,methodCall:n.methodCall||this.lighten(t.function,5),variableBuiltin:n.variableBuiltin||this.emphasize(t.variable),variableProperty:n.variableProperty||this.lighten(t.variable,10),variableReadonly:n.variableReadonly||t.number,parameter:n.parameter||t.variable,typePrimitive:n.typePrimitive||this.darken(t.type,10),typeInterface:n.typeInterface||t.type,className:n.className||this.emphasize(t.type),enum:n.enum||t.type,boolean:n.boolean||t.number,null:n.null||this.opacity(t.number,.7),constant:n.constant||t.number,punctuation:n.punctuation||this.opacity(t.foreground,.7),delimiter:n.delimiter||this.opacity(t.foreground,.8),bracket:n.bracket||t.foreground,tag:n.tag||t.keyword,tagAttribute:n.tagAttribute||t.variable,tagAttributeValue:n.tagAttributeValue||t.string,tagBracket:n.tagBracket||this.opacity(t.foreground,.8),decorator:n.decorator||t.function,annotation:n.annotation||t.function,namespace:n.namespace||this.opacity(t.type,.8),module:n.module||this.opacity(t.type,.8),...n}}generateComponentColors(e,t){let n=[];return e.markdown?n.push(...this.generateMarkdownColors(e.markdown,t)):n.push(...this.generateDefaultMarkdownColors(t)),e.chat?n.push(...this.generateChatColors(e.chat,t)):n.push(...this.generateDefaultChatColors(t)),e.tools?n.push(...this.generateToolColors(e.tools,t)):n.push(...this.generateDefaultToolColors(t)),n}generateMarkdownColors(e,t){let n=[],r=t.colors.primary.base,i=t.colors.chat?.background||t.colors.surface.background;return n.push(` --markdown-heading1: ${e.heading1||r};`),n.push(` --markdown-heading2: ${e.heading2||this.opacity(r,.9)};`),n.push(` --markdown-heading3: ${e.heading3||this.opacity(r,.8)};`),n.push(` --markdown-heading4: ${e.heading4||t.colors.surface.foreground};`),n.push(` --markdown-link: ${e.link||r};`),n.push(` --markdown-link-hover: ${e.linkHover||t.colors.primary.hover||this.darken(r,10)};`),n.push(` --markdown-inline-code: ${e.inlineCode||t.colors.syntax.base.string};`),n.push(` --markdown-inline-code-bg: ${e.inlineCodeBackground||i};`),n.push(` --markdown-blockquote: ${e.blockquote||t.colors.surface.mutedForeground};`),n.push(` --markdown-blockquote-border: ${e.blockquoteBorder||t.colors.interactive.border};`),n.push(` --markdown-list-marker: ${r};`),n.push(` --markdown-bold: ${e.bold||t.colors.surface.foreground};`),n.push(` --markdown-italic: ${e.italic||this.opacity(t.colors.surface.foreground,.9)};`),n.push(` --markdown-strikethrough: ${e.strikethrough||t.colors.surface.mutedForeground};`),n.push(` --markdown-hr: ${e.hr||t.colors.interactive.border};`),n}generateDefaultMarkdownColors(e){let t=[],n=e.colors.primary.base,r=e.colors.chat?.background||e.colors.surface.background;return t.push(` --markdown-heading1: ${n};`),t.push(` --markdown-heading2: ${this.opacity(n,.9)};`),t.push(` --markdown-heading3: ${this.opacity(n,.8)};`),t.push(` --markdown-heading4: ${e.colors.surface.foreground};`),t.push(` --markdown-link: ${n};`),t.push(` --markdown-link-hover: ${e.colors.primary.hover||this.darken(n,10)};`),t.push(` --markdown-inline-code: ${e.colors.syntax.base.string};`),t.push(` --markdown-inline-code-bg: ${r};`),t.push(` --markdown-blockquote: ${e.colors.surface.mutedForeground};`),t.push(` --markdown-blockquote-border: ${e.colors.interactive.border};`),t.push(` --markdown-list-marker: ${n};`),t.push(` --markdown-bold: ${e.colors.surface.foreground};`),t.push(` --markdown-italic: ${this.opacity(e.colors.surface.foreground,.9)};`),t.push(` --markdown-strikethrough: ${e.colors.surface.mutedForeground};`),t.push(` --markdown-hr: ${e.colors.interactive.border};`),t}generateChatColors(e,t){let n=[],r=e.background||t.colors.surface.background,i=e.composerSkill||this.getDefaultComposerSkillColor(t);return n.push(` --chat-background: ${r};`),n.push(` --chat-user-message: ${e.userMessage||t.colors.surface.foreground};`),n.push(` --chat-user-message-bg: ${e.userMessageBackground||t.colors.surface.elevated};`),n.push(` --chat-assistant-message: ${e.assistantMessage||t.colors.surface.foreground};`),n.push(` --chat-assistant-message-bg: ${e.assistantMessageBackground||t.colors.surface.muted};`),n.push(` --chat-timestamp: ${e.timestamp||t.colors.surface.mutedForeground};`),n.push(` --chat-divider: ${e.divider||t.colors.interactive.border};`),n.push(` --chat-typing: ${e.typing||t.colors.surface.mutedForeground};`),n.push(` --chat-composer-skill: ${i};`),n}generateDefaultChatColors(e){let t=[];return t.push(` --chat-background: ${e.colors.surface.background};`),t.push(` --chat-user-message: ${e.colors.surface.foreground};`),t.push(` --chat-user-message-bg: ${e.colors.surface.elevated};`),t.push(` --chat-assistant-message: ${e.colors.surface.foreground};`),t.push(` --chat-assistant-message-bg: ${e.colors.surface.muted};`),t.push(` --chat-timestamp: ${e.colors.surface.mutedForeground};`),t.push(` --chat-divider: ${e.colors.interactive.border};`),t.push(` --chat-typing: ${e.colors.surface.mutedForeground};`),t.push(` --chat-composer-skill: ${this.getDefaultComposerSkillColor(e)};`),t}getDefaultComposerSkillColor(e){return e.metadata.variant===`dark`?this.lighten(e.colors.status.warning,25):e.colors.status.warning}generateToolColors(e,t){let n=[];return n.push(` --tools-background: ${e?.background||this.opacity(t.colors.surface.muted,.2)};`),n.push(` --tools-border: ${e?.border||this.opacity(t.colors.interactive.border,.3)};`),n.push(` --tools-header-hover: ${e?.headerHover||this.opacity(t.colors.surface.muted,.3)};`),n.push(` --tools-icon: ${e?.icon||t.colors.surface.mutedForeground};`),n.push(` --tools-title: color-mix(in srgb, ${e?.title||t.colors.surface.foreground} 50%, ${t.colors.surface.mutedForeground});`),n.push(` --tools-description: ${e?.description||this.opacity(t.colors.surface.mutedForeground,.6)};`),e?.edit?(n.push(` --tools-edit-added: ${e.edit.added||t.colors.status.success};`),n.push(` --tools-edit-added-bg: ${e.edit.addedBackground||t.colors.status.successBackground};`),n.push(` --tools-edit-removed: ${e.edit.removed||t.colors.status.error};`),n.push(` --tools-edit-removed-bg: ${e.edit.removedBackground||t.colors.status.errorBackground};`),n.push(` --tools-edit-modified: ${e.edit.modified||t.colors.status.info};`),n.push(` --tools-edit-modified-bg: ${e.edit.modifiedBackground||t.colors.status.infoBackground};`),n.push(` --tools-edit-line-number: ${e.edit.lineNumber||this.opacity(t.colors.surface.mutedForeground,.6)};`)):(n.push(` --tools-edit-added: ${t.colors.status.success};`),n.push(` --tools-edit-added-bg: ${t.colors.status.successBackground};`),n.push(` --tools-edit-removed: ${t.colors.status.error};`),n.push(` --tools-edit-removed-bg: ${t.colors.status.errorBackground};`),n.push(` --tools-edit-modified: ${t.colors.status.info};`),n.push(` --tools-edit-modified-bg: ${t.colors.status.infoBackground};`),n.push(` --tools-edit-line-number: ${this.opacity(t.colors.surface.mutedForeground,.6)};`)),n}generateDefaultToolColors(e){let t=[];return t.push(` --tools-background: ${this.opacity(e.colors.surface.muted,.2)};`),t.push(` --tools-border: ${this.opacity(e.colors.interactive.border,.3)};`),t.push(` --tools-header-hover: ${this.opacity(e.colors.surface.muted,.3)};`),t.push(` --tools-icon: ${e.colors.surface.mutedForeground};`),t.push(` --tools-title: color-mix(in srgb, ${e.colors.surface.foreground} 50%, ${e.colors.surface.mutedForeground});`),t.push(` --tools-description: ${this.opacity(e.colors.surface.mutedForeground,.6)};`),t.push(` --tools-edit-added: ${e.colors.status.success};`),t.push(` --tools-edit-added-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.successBackground),.15)};`),t.push(` --tools-edit-removed: ${e.colors.status.error};`),t.push(` --tools-edit-removed-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.errorBackground),.15)};`),t.push(` --tools-edit-modified: ${e.colors.status.info};`),t.push(` --tools-edit-modified-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.infoBackground),.15)};`),t.push(` --tools-edit-line-number: ${this.opacity(e.colors.surface.mutedForeground,.6)};`),t}generateConfigVariables(e){let t=[];return e?(e.fonts&&(e.fonts.sans&&(t.push(` --font-sans: ${e.fonts.sans};`),t.push(` --font-family-sans: ${e.fonts.sans};`)),e.fonts.mono&&(t.push(` --font-mono: ${e.fonts.mono};`),t.push(` --font-family-mono: ${e.fonts.mono};`)),e.fonts.heading&&t.push(` --font-heading: ${e.fonts.heading};`)),e.transitions&&(e.transitions.fast&&t.push(` --transition-fast: ${e.transitions.fast};`),e.transitions.normal&&t.push(` --transition-normal: ${e.transitions.normal};`),e.transitions.slow&&t.push(` --transition-slow: ${e.transitions.slow};`)),t):t}generateTypographyVariables(){let e=[],t=m()?bt:xt;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()}},Ap=()=>cl()?new URLSearchParams(window.location.search):null,jp=()=>typeof window>`u`||window.matchMedia(`(prefers-color-scheme: dark)`).matches,Mp=()=>{let e=Ap()?.get(`themeVariant`);return e===`dark`||e===`light`?e===`dark`:jp()},Np=(e,t)=>t.reduce((e,t)=>e&&typeof e==`object`?e[t]:void 0,e),Pp=e=>typeof e==`string`&&e.trim().length>0,Fp=e=>{if(!e||typeof e!=`object`)return!1;for(let t of[[`metadata`,`id`],[`metadata`,`name`],[`metadata`,`variant`],[`colors`,`primary`,`base`],[`colors`,`primary`,`foreground`],[`colors`,`surface`,`background`],[`colors`,`surface`,`foreground`],[`colors`,`surface`,`muted`],[`colors`,`surface`,`mutedForeground`],[`colors`,`surface`,`elevated`],[`colors`,`surface`,`elevatedForeground`],[`colors`,`surface`,`subtle`],[`colors`,`interactive`,`border`],[`colors`,`interactive`,`selection`],[`colors`,`interactive`,`selectionForeground`],[`colors`,`interactive`,`focusRing`],[`colors`,`interactive`,`hover`],[`colors`,`status`,`error`],[`colors`,`status`,`errorForeground`],[`colors`,`status`,`errorBackground`],[`colors`,`status`,`errorBorder`],[`colors`,`status`,`warning`],[`colors`,`status`,`warningForeground`],[`colors`,`status`,`warningBackground`],[`colors`,`status`,`warningBorder`],[`colors`,`status`,`success`],[`colors`,`status`,`successForeground`],[`colors`,`status`,`successBackground`],[`colors`,`status`,`successBorder`],[`colors`,`status`,`info`],[`colors`,`status`,`infoForeground`],[`colors`,`status`,`infoBackground`],[`colors`,`status`,`infoBorder`],[`colors`,`syntax`,`base`,`background`],[`colors`,`syntax`,`base`,`foreground`],[`colors`,`syntax`,`base`,`keyword`],[`colors`,`syntax`,`base`,`string`],[`colors`,`syntax`,`base`,`number`],[`colors`,`syntax`,`base`,`function`],[`colors`,`syntax`,`base`,`variable`],[`colors`,`syntax`,`base`,`type`],[`colors`,`syntax`,`base`,`comment`],[`colors`,`syntax`,`base`,`operator`],[`colors`,`syntax`,`highlights`,`diffAdded`],[`colors`,`syntax`,`highlights`,`diffRemoved`],[`colors`,`syntax`,`highlights`,`lineNumber`]])if(!Pp(Np(e,t)))return!1;let t=Np(e,[`metadata`,`variant`]);return t===`light`||t===`dark`},Ip=e=>Fp(e.currentTheme)?e.currentTheme:null,Lp=e=>Ip(e)?.metadata.variant??null,Rp=tl,zp=Xc,Bp=()=>{let e=Ap()?.get(`currentTheme`);if(!e)return null;try{let t=JSON.parse(e);return Fp(t)?t:null}catch{return null}},Vp=e=>Jc(e===`dark`),Hp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,Up=()=>{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`)}},Wp=e=>{let t=Rp,n=zp,r=`system`;if(typeof window<`u`){let e=Ap(),i=e?.get(`themeMode`),a=e?.get(`lightThemeId`),o=e?.get(`darkThemeId`),s=tn(`themeMode`),c=tn(`lightThemeId`),l=tn(`darkThemeId`),u=tn(`useSystemTheme`),d=tn(`selectedThemeId`),f=tn(`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=Yc(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=Yc(e);r&&(r.metadata.variant===`light`?t=r.metadata.id:n=r.metadata.id)}return{themeMode:r,lightThemeId:t,darkThemeId:n}};function Gp({children:e,defaultThemeId:t}){let n=(0,Z.useMemo)(()=>new kp,[]),[r,a]=(0,Z.useState)(()=>Wp(t)),[o,s]=(0,Z.useState)(!1),[c,u]=(0,Z.useState)(()=>Mp()),[d,h]=(0,Z.useState)([]),[_]=(0,Z.useState)(()=>Bp()),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(()=>typeof window>`u`||!m()?null:window.__YURI_VSCODE_THEME__||null),w=(0,Z.useMemo)(()=>m(),[]),T=(0,Z.useMemo)(()=>g(),[]),E=(0,Z.useMemo)(()=>p(),[]),D=(0,Z.useMemo)(()=>typeof window>`u`?!1:Ap()!==null,[]),O=(0,Z.useMemo)(()=>{let e=[],t=new Set,n=n=>{let r=n.metadata.id;t.has(r)||(t.add(r),e.push(n))};return w&&S&&n(S),v&&n(v),_&&n(_),d.forEach(n),$c.forEach(n),e},[d,_,v,w,S]),k=(0,Z.useMemo)(()=>e=>O.find(t=>t.metadata.id===e),[O]),A=(0,Z.useMemo)(()=>(e,t)=>{let n=k(e);return n&&n.metadata.variant===t?n:O.find(e=>e.metadata.variant===t)??Vp(t)},[O,k]),j=(0,Z.useMemo)(()=>w&&S?S:r.themeMode===`light`?A(r.lightThemeId,`light`):r.themeMode===`dark`||c?A(r.darkThemeId,`dark`):A(r.lightThemeId,`light`),[A,w,r,c,S]),M=J(async()=>{if(!(typeof window>`u`||w)){x(!0);try{let e=await f(`/api/config/themes`,{method:`GET`,credentials:T?`omit`:`include`,headers:{Accept:`application/json`}});if(e.status===401||!e.ok)return;let t=await e.json(),n=(Array.isArray(t?.themes)?t.themes:[]).filter(Fp);h(n)}catch{}finally{x(!1)}}});(0,Z.useEffect)(()=>{M()},[M]),(0,Z.useEffect)(()=>{if(!w)return;let e=e=>{C(e)},t=t=>{let n=t.detail;n?.theme&&e(n.theme)},n=window.__YURI_VSCODE_THEME__;return n&&e(n),window.addEventListener(`yuri:vscode-theme`,t),()=>window.removeEventListener(`yuri:vscode-theme`,t)},[w]);let N=J(e=>{if(typeof document>`u`)return;let t=document.documentElement.hasAttribute(`data-yuri-vibrancy`)||window.__YURI_ELECTRON__?.macVibrancy===!0?`transparent`:e.colors.surface.background;document.body.style.backgroundColor=t;let n=document.querySelector(`meta[name="theme-color"]`);n||(n=document.createElement(`meta`),n.setAttribute(`name`,`theme-color`),document.head.appendChild(n)),n.setAttribute(`content`,t);let r=e.metadata.variant===`dark`?`(prefers-color-scheme: dark)`:`(prefers-color-scheme: light)`,i=document.querySelector(`meta[name="theme-color"][media="${r}"]`);i||(i=document.createElement(`meta`),i.setAttribute(`name`,`theme-color`),i.setAttribute(`media`,r),document.head.appendChild(i)),i.setAttribute(`content`,t)}),P=J(e=>{typeof document>`u`||document.documentElement.classList.toggle(`vscode-runtime`,e)});Hp(()=>{if(typeof window>`u`)return;let e=Up();n.apply(j),P(w),N(j);let t=document.documentElement;return t.classList.remove(`light`,`dark`),t.classList.add(j.metadata.variant),e},[P,n,j,w,N]),(0,Z.useEffect)(()=>{if(r.themeMode!==`system`||typeof window>`u`||D)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>{u(e.matches)};return u(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[r.themeMode,D]),(0,Z.useEffect)(()=>{if(D||typeof window>`u`)return;Xt(`themeMode`,r.themeMode),Xt(`lightThemeId`,r.lightThemeId),Xt(`darkThemeId`,r.darkThemeId),Xt(`useSystemTheme`,String(r.themeMode===`system`)),Xt(`selectedThemeId`,j.metadata.id),Xt(`selectedThemeVariant`,j.metadata.variant===`light`?`light`:`dark`);let e=A(r.lightThemeId,`light`),t=A(r.darkThemeId,`dark`);Xt(`splashBgLight`,e.colors.surface.background),Xt(`splashFgLight`,e.colors.surface.foreground),Xt(`splashBgDark`,t.colors.surface.background),Xt(`splashFgDark`,t.colors.surface.foreground),T&&(localStorage.setItem(`themeMode`,r.themeMode),localStorage.setItem(`useSystemTheme`,String(r.themeMode===`system`)),localStorage.setItem(`splashBgLight`,e.colors.surface.background),localStorage.setItem(`splashFgLight`,e.colors.surface.foreground),localStorage.setItem(`splashBgDark`,t.colors.surface.background),localStorage.setItem(`splashFgDark`,t.colors.surface.foreground))},[r,j,A,T,D]),(0,Z.useEffect)(()=>{if(typeof window>`u`||D)return;let e=e=>{e.storageArea===window.localStorage&&(Jt(e.key,`themeMode`)||Jt(e.key,`lightThemeId`)||Jt(e.key,`darkThemeId`))&&a(e=>{let t=tn(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=tn(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=tn(`darkThemeId`),o=typeof a==`string`&&a.trim().length>0?a.trim():e.darkThemeId;return n===e.themeMode&&i===e.lightThemeId&&o===e.darkThemeId?e:{themeMode:n,lightThemeId:i,darkThemeId:o}})};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[D]);let F=J(e=>{let t=e.themeMode,n=e.lightThemeId,r=e.darkThemeId,i=Lp(e),o=Ip(e);if(t!==`light`&&t!==`dark`&&t!==`system`||typeof n!=`string`||typeof r!=`string`)return;let s=n.trim(),c=r.trim();!s||!c||(Up(),(0,Dp.flushSync)(()=>{D&&o&&y(o),t===`system`&&i&&u(i===`dark`),a(e=>e.themeMode===t&&e.lightThemeId===s&&e.darkThemeId===c?e:{themeMode:t,lightThemeId:s,darkThemeId:c})}))});(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=window;return e.__yuriApplyThemeSync=F,()=>{e.__yuriApplyThemeSync===F&&delete e.__yuriApplyThemeSync}},[F]),(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin)return;let t=e.data;t?.type!==`yuri:theme-sync`||!t.payload||F(t.payload)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[F]),(0,Z.useEffect)(()=>{if(D||!o)return;let e=A(r.lightThemeId,`light`),t=A(r.darkThemeId,`dark`);Zt({themeId:j.metadata.id,themeVariant:j.metadata.variant===`light`?`light`:`dark`,useSystemTheme:r.themeMode===`system`,lightThemeId:r.lightThemeId,darkThemeId:r.darkThemeId,splashBgLight:e.colors.surface.background,splashFgLight:e.colors.surface.foreground,splashBgDark:t.colors.surface.background,splashFgDark:t.colors.surface.foreground})},[j.metadata.id,j.metadata.variant,A,r.themeMode,r.lightThemeId,r.darkThemeId,D,o]),(0,Z.useEffect)(()=>{D||!E||(async()=>{await tr(r.themeMode,j.metadata.variant)})()},[j.metadata.variant,E,r.themeMode,D]),(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t&&(a(e=>{let n=e.themeMode;t.useSystemTheme===!0?n=`system`:t.useSystemTheme===!1&&(t.themeVariant===`dark`||t.themeVariant===`light`)&&(n=t.themeVariant);let r=e.lightThemeId;typeof t.lightThemeId==`string`&&t.lightThemeId.length>0&&(r=t.lightThemeId.trim());let i=e.darkThemeId;return typeof t.darkThemeId==`string`&&t.darkThemeId.length>0&&(i=t.darkThemeId.trim()),n===e.themeMode&&r===e.lightThemeId&&i===e.darkThemeId?e:{themeMode:n,lightThemeId:r,darkThemeId:i}}),s(!0))};return window.addEventListener(`yuri:settings-synced`,e),()=>window.removeEventListener(`yuri:settings-synced`,e)},[]),(0,Z.useEffect)(()=>{if(!(D||typeof window>`u`))return i(e=>{l(e)&&(a(e=>{let t=tn(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=tn(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=tn(`darkThemeId`),o=typeof a==`string`&&a.trim().length>0?a.trim():e.darkThemeId;return n===e.themeMode&&i===e.lightThemeId&&o===e.darkThemeId?e:{themeMode:n,lightThemeId:i,darkThemeId:o}}),s(!1))})},[D]);let I=J(e=>{let t=O.find(t=>t.metadata.id===e);t&&a(e=>t.metadata.variant===`dark`?e.darkThemeId===t.metadata.id&&e.themeMode===`dark`?e:{...e,darkThemeId:t.metadata.id,themeMode:`dark`}:e.lightThemeId===t.metadata.id&&e.themeMode===`light`?e:{...e,lightThemeId:t.metadata.id,themeMode:`light`})}),L=J(e=>{a(t=>t.themeMode===e?t:{...t,themeMode:e})}),R=J(e=>{if(e){a(e=>e.themeMode===`system`?e:{...e,themeMode:`system`});return}let t=j.metadata.variant===`dark`?`dark`:`light`;a(e=>e.themeMode===t?e:{...e,themeMode:t})}),z=J(e=>{let t=O.find(t=>t.metadata.id===e&&t.metadata.variant===`light`);t&&a(e=>e.lightThemeId===t.metadata.id?e:{...e,lightThemeId:t.metadata.id})}),B=J(e=>{let t=O.find(t=>t.metadata.id===e&&t.metadata.variant===`dark`);t&&a(e=>e.darkThemeId===t.metadata.id?e:{...e,darkThemeId:t.metadata.id})}),V=(0,Z.useMemo)(()=>({currentTheme:j,availableThemes:O,setTheme:I,customThemesLoading:b,reloadCustomThemes:M,isSystemPreference:r.themeMode===`system`,setSystemPreference:R,themeMode:r.themeMode,setThemeMode:L,lightThemeId:r.lightThemeId,darkThemeId:r.darkThemeId,setLightThemePreference:z,setDarkThemePreference:B}),[O,j,b,r.darkThemeId,r.lightThemeId,r.themeMode,M,B,z,R,I,L]);return(0,$.jsx)(ps.Provider,{value:V,children:e})}var Kp=!1,qp=()=>{if(Kp||typeof window>`u`)return;Kp=!0;let e={showReasoningTraces:K.getState().showReasoningTraces,sessionTitleRefreshEnabled:K.getState().sessionTitleRefreshEnabled,sessionGoalEnabled:K.getState().sessionGoalEnabled,sessionGoalDefaultBudgetEnabled:K.getState().sessionGoalDefaultBudgetEnabled,sessionGoalDefaultBudget:K.getState().sessionGoalDefaultBudget,collapsibleThinkingBlocks:K.getState().collapsibleThinkingBlocks,showDeletionDialog:K.getState().showDeletionDialog,nativeNotificationsEnabled:K.getState().nativeNotificationsEnabled,notificationMode:K.getState().notificationMode,notifyOnSubtasks:K.getState().notifyOnSubtasks,notifyOnCompletion:K.getState().notifyOnCompletion,notifyOnError:K.getState().notifyOnError,notifyOnQuestion:K.getState().notifyOnQuestion,notificationTemplates:K.getState().notificationTemplates,summarizeLastMessage:K.getState().summarizeLastMessage,summaryThreshold:K.getState().summaryThreshold,summaryLength:K.getState().summaryLength,maxLastMessageLength:K.getState().maxLastMessageLength,autoDeleteEnabled:K.getState().autoDeleteEnabled,autoDeleteAfterDays:K.getState().autoDeleteAfterDays,sessionRetentionAction:K.getState().sessionRetentionAction,fontSize:K.getState().fontSize,terminalFontSize:K.getState().terminalFontSize,editorFontSize:K.getState().editorFontSize,uiFont:K.getState().uiFont,monoFont:K.getState().monoFont,padding:K.getState().padding,cornerRadius:K.getState().cornerRadius,inputBarOffset:K.getState().inputBarOffset,mobileKeyboardMode:K.getState().mobileKeyboardMode,diffLayoutPreference:K.getState().diffLayoutPreference,gitChangesViewMode:K.getState().gitChangesViewMode},t=null,n=null,r=()=>{let e=t;t=null,n=null,e&&Object.keys(e).length>0&&Zt(e)},i=e=>{t={...t??{},...e},!n&&(n=setTimeout(r,150))};K.subscribe(t=>{let n={showReasoningTraces:t.showReasoningTraces,sessionTitleRefreshEnabled:t.sessionTitleRefreshEnabled,sessionGoalEnabled:t.sessionGoalEnabled,sessionGoalDefaultBudgetEnabled:t.sessionGoalDefaultBudgetEnabled,sessionGoalDefaultBudget:t.sessionGoalDefaultBudget,collapsibleThinkingBlocks:t.collapsibleThinkingBlocks,showDeletionDialog:t.showDeletionDialog,nativeNotificationsEnabled:t.nativeNotificationsEnabled,notificationMode:t.notificationMode,notifyOnSubtasks:t.notifyOnSubtasks,notifyOnCompletion:t.notifyOnCompletion,notifyOnError:t.notifyOnError,notifyOnQuestion:t.notifyOnQuestion,notificationTemplates:t.notificationTemplates,summarizeLastMessage:t.summarizeLastMessage,summaryThreshold:t.summaryThreshold,summaryLength:t.summaryLength,maxLastMessageLength:t.maxLastMessageLength,autoDeleteEnabled:t.autoDeleteEnabled,autoDeleteAfterDays:t.autoDeleteAfterDays,sessionRetentionAction:t.sessionRetentionAction,fontSize:t.fontSize,terminalFontSize:t.terminalFontSize,editorFontSize:t.editorFontSize,uiFont:t.uiFont,monoFont:t.monoFont,padding:t.padding,cornerRadius:t.cornerRadius,inputBarOffset:t.inputBarOffset,mobileKeyboardMode:t.mobileKeyboardMode,diffLayoutPreference:t.diffLayoutPreference,gitChangesViewMode:t.gitChangesViewMode},r={};n.showReasoningTraces!==e.showReasoningTraces&&(r.showReasoningTraces=n.showReasoningTraces),n.sessionTitleRefreshEnabled!==e.sessionTitleRefreshEnabled&&(r.sessionTitleRefreshEnabled=n.sessionTitleRefreshEnabled),n.sessionGoalEnabled!==e.sessionGoalEnabled&&(r.sessionGoalEnabled=n.sessionGoalEnabled),n.sessionGoalDefaultBudgetEnabled!==e.sessionGoalDefaultBudgetEnabled&&(r.sessionGoalDefaultBudgetEnabled=n.sessionGoalDefaultBudgetEnabled),n.sessionGoalDefaultBudget!==e.sessionGoalDefaultBudget&&(r.sessionGoalDefaultBudget=n.sessionGoalDefaultBudget),n.collapsibleThinkingBlocks!==e.collapsibleThinkingBlocks&&(r.collapsibleThinkingBlocks=n.collapsibleThinkingBlocks),n.showDeletionDialog!==e.showDeletionDialog&&(r.showDeletionDialog=n.showDeletionDialog),n.nativeNotificationsEnabled!==e.nativeNotificationsEnabled&&(r.nativeNotificationsEnabled=n.nativeNotificationsEnabled),n.notificationMode!==e.notificationMode&&(r.notificationMode=n.notificationMode),n.notifyOnSubtasks!==e.notifyOnSubtasks&&(r.notifyOnSubtasks=n.notifyOnSubtasks),n.notifyOnCompletion!==e.notifyOnCompletion&&(r.notifyOnCompletion=n.notifyOnCompletion),n.notifyOnError!==e.notifyOnError&&(r.notifyOnError=n.notifyOnError),n.notifyOnQuestion!==e.notifyOnQuestion&&(r.notifyOnQuestion=n.notifyOnQuestion),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)})},Jp=(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},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(e[n]?.providerID!==t[n]?.providerID||e[n]?.modelID!==t[n]?.modelID)return!1;return!0},Xp=(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},Zp=(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])&&Xp(e[n],t[n]))},Qp=()=>{let e=K.getState();return{favoriteModels:e.favoriteModels,hiddenModels:e.hiddenModels,collapsedModelProviders:e.collapsedModelProviders,recentModels:e.recentModels,recentAgents:e.recentAgents,recentEfforts:e.recentEfforts}},$p=(e,t)=>Jp(e.favoriteModels,t.favoriteModels)&&Yp(e.hiddenModels,t.hiddenModels)&&Xp(e.collapsedModelProviders,t.collapsedModelProviders)&&Jp(e.recentModels,t.recentModels)&&Xp(e.recentAgents,t.recentAgents)&&Zp(e.recentEfforts,t.recentEfforts),em=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()]))}),tm=()=>{if(typeof window>`u`)return()=>{};let e=null,t=null,n=!1,r=()=>{e=null;let n=Qp();t&&$p(t,n)||(t=em(n),Zt(n).catch(()=>{}))},i=()=>{if(!n){n=!0;return}e!==null&&window.clearTimeout(e),e=window.setTimeout(r,1200)},a=K.subscribe((e,t)=>{$p({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)}},nm=!1,rm=`yuri-typography-base`,im=()=>{if(typeof document>`u`)return;let e=`:root {\n${Object.entries(xt).map(([e,t])=>` --text-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}: ${t};`).join(`
|
|
4
|
-
`)}\n}\n`,t=document.getElementById(rm);if(t){t.textContent=e;return}let n=document.createElement(`style`);n.id=rm,n.textContent=e,document.head.appendChild(n)},am=()=>{nm||typeof window>`u`||(nm=!0,im())};function om(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)(sm,r);let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(yn,{client:Cn,children:n}),t[1]=n,t[2]=i),i}function sm(){return wn(Cn)}var cm=15,lm=2e3,um=40,dm=2e4,fm=e=>{let t=Ko(e=>e.isConnected),n=Ko(e=>e.providers.length),r=Ko(e=>e.agents.length),i=Ko(e=>e.activeDirectoryKey),a=Ko(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`?cm:um;if(s.current>=e){if(l===`fast`){s.current=0,u(`slow`);return}u(`done`);return}let t=Ko.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]),Vn(f,!o||l===`done`?null:l===`slow`?dm:lm)},pm=40,mm=20971520,hm=new Map,gm=0;function _m(e){return e.length*2}function vm(e,t){let n=hm.get(e);n!==void 0&&(gm-=n),hm.delete(e),hm.set(e,t),gm+=t}function ym(e,t){let n=hm.get(e);(n!==void 0||t!==void 0)&&vm(e,t??n??0)}function bm(e){let t=hm.get(e);t!==void 0&&(hm.delete(e),gm-=t)}function xm(e,t){let n=e??new Set;for(;hm.size>pm||gm>mm;){let e=hm.keys().next().value;if(!e)return;if(n.has(e)){if(ym(e),hm.size<=n.size)return;continue}bm(e),t(e)}}function Sm(e,t){vm(e,t)}function Cm(e){bm(e)}function wm(e,t){ym(e,t)}function Tm(e){let t=new Map,n=e=>{t.delete(e),Cm(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=_m(r.content);return t.set(e,{...r,size:i?.isFile?i.size:void 0,mtimeMs:i?.isFile?i.mtimeMs:void 0}),Sm(e,a),xm(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 wm(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 Em(e){let t=(0,Q.c)(8),{apis:n,children:r}=e,i;t[0]===n.files?i=t[1]:(i=Tm(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)(En.Provider,{value:o,children:r}),t[5]=o,t[6]=r,t[7]=s):s=t[7],s}var Dm=`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))`,Om=`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))`,km={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 Am(){let e=(0,Q.c)(2),t=jm,[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 jm(){return typeof document<`u`&&document.documentElement.classList.contains(`dark`)}function Mm(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 Nm=e=>{let t=(0,Q.c)(8),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r=Am(),i=r?Dm:Om,a=Z.useRef(null);Mm(i,a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o={display:`contents`},t[2]=o):o=t[2];let s=r?`dark`:`light`,c,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c={classNames:{toast:`group/toast toast !flex !min-w-[min(var(--width),calc(100vw-2rem))] !max-w-[calc(100vw-2rem)] !items-center !rounded-[var(--yuri-toast-radius,var(--radius-xl))] !border-0 !px-[var(--yuri-toast-padding-x,0.875rem)] !py-[var(--yuri-toast-padding-y,0.75rem)] !gap-[var(--yuri-toast-gap,0.625rem)] !text-foreground`,content:`!min-w-0 !flex-1 !text-left`,title:`typography-ui-label !font-medium !text-foreground`,description:`typography-meta !text-muted-foreground !mt-0`,actionButton:`!ms-0 !me-0 !shrink-0 !rounded-[var(--radius-md)] !bg-[var(--yuri-toast-action-background,var(--surface-muted))] !text-[var(--yuri-toast-action-foreground,var(--foreground))] hover:!opacity-85 !px-2 !py-1 typography-meta !font-medium transition-opacity`,cancelButton:`!ms-0 !me-0 !shrink-0 !rounded-[var(--radius-md)] !bg-[var(--yuri-toast-cancel-background,var(--interactive-hover))] !text-[var(--yuri-toast-cancel-foreground,var(--foreground))] hover:!bg-[var(--interactive-active)] !px-2 !py-1 typography-meta !font-medium transition-colors`,closeButton:`!rounded-[var(--radius-md)] !bg-[var(--interactive-hover)] !text-foreground hover:!bg-[var(--interactive-active)]`,icon:`!shrink-0 !text-[var(--yuri-toast-status-color,var(--muted-foreground))]`,success:`[&_[data-icon]]:!text-[var(--status-success)]`,error:`[&_[data-icon]]:!text-[var(--status-error)]`,warning:`[&_[data-icon]]:!text-[var(--status-warning)]`,info:`[&_[data-icon]]:!text-[var(--status-info)]`},style:{borderRadius:`var(--radius-xl)`,backgroundColor:`var(--yuri-toast-background, var(--surface-elevated))`}},l={"--normal-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--normal-text":`var(--foreground)`,"--normal-border":`transparent`,"--error-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--error-text":`var(--foreground)`,"--error-border":`transparent`,"--success-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--success-text":`var(--foreground)`,"--success-border":`transparent`,"--warning-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--warning-text":`var(--foreground)`,"--warning-border":`transparent`,"--info-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--info-text":`var(--foreground)`,"--info-border":`transparent`},t[3]=c,t[4]=l):(c=t[3],l=t[4]);let u;return t[5]!==n||t[6]!==s?(u=(0,$.jsx)(`div`,{ref:a,style:o,children:(0,$.jsx)(Bn,{theme:s,className:`toaster group`,position:`bottom-right`,closeButton:!1,duration:3500,icons:km,toastOptions:c,style:l,...n})}),t[5]=n,t[6]=s,t[7]=u):u=t[7],u},Pm=new ss({maxEntries:128,maxBytes:1048576}),Fm=(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(`|`)}`,Im=async e=>{let t=Su(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=e.agentName===void 0?void 0:cs(os(e.agentName).var,Su),r=JSON.stringify([e.iconName,t,e.agentName,n?.background]),i=Pm.get(r);return i===void 0&&(i=await(e.agentName===void 0?Gl(e.iconName,t):_u(us(`agent`,e.agentName,!1,n)))??``,i&&Pm.set(r,i,(r.length+i.length)*2)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:i}}))},Lm=[],Rm=e=>void 0,zm=()=>void 0;function Bm(e){let t=ju()&&e.enabled&&Ou(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=ls(e.agentName),u=ms()?.currentTheme,d=(0,Z.useRef)([]),f=(0,Z.useRef)(Fu()),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??Rm),w=J(e.onAutocompleteDismiss??zm),T=J(e=>{typeof document>`u`||Eu(document.documentElement,e)});wu.bind({onText:(e,t,n)=>{bu({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:qe(e.text,e.attachments.map(e=>e.filename)),chipRanges:zu(Cu(e.text,e.chipHighlights),Su(`--primary`)),appearance:typeof document>`u`?`dark`:Tu(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:Uu(e.agentName||void 0),agentIdenticon:Hu(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 vu(e,!0),()=>{vu(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,wu.rememberText(i.text),wu.retain(e,i);let a=Iu();return()=>{n.current=null,a(),wu.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e=>{c.current=e,n.current&&={...n.current,agentIcon:e},Nu().update({agentIcon:e})};return i(``),_u(us(`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=Is(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Nu().update(a),i)return _u(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},Nu().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let D=Mu(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:[]},wu.rememberState(n.current)),Nu().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await xu(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},wu.rememberState(n.current)),Nu().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,D]);let O=e.autocompleteRows??Lm,k=e.autocompleteOpen===!0,A=e.autocompleteHighlightedIndex??0,j=e.autocompleteQuery??``,M=`${Fm(O,k,A)}\0${j}`;(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(k&&O.length>0)){let e=Fu();ku(f.current,e)||(f.current=e,n.current&&(n.current={...n.current,autocomplete:e},wu.rememberState(n.current)),Nu().update({autocomplete:e}));return}return Im(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:Su(`--primary-base`)||Su(`--primary`),rows:t};ku(f.current,r)||(f.current=r,n.current&&(n.current={...n.current,autocomplete:r},wu.rememberState(n.current)),Nu().update({autocomplete:r}))}),()=>{e=!0}},[t,M,u]);let N=t?Cu(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&&Bu(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,wu.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=yu({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=Du(c,s,u,{caret:e.caret});d&&Nu().update(d)},[t,e.text,e.textPresetEpoch,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,D,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,N]),t}var Vm=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},Hm=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=fs(),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},Um=e=>{let t=Ko(e=>e.sttLocalModel),[n,r]=Z.useState(null);return Z.useEffect(()=>{if(!e){r(null);return}let n=!1,i=async()=>{try{let e=await f(`/api/dictation/status`,{query:{provider:`local`,localModel:t}});if(!e.ok||n)return;let i=await e.json(),a=Array.isArray(i?.models)?i.models.find(e=>e.id===t):null;n||r(typeof a?.downloadProgress==`number`?a.downloadProgress:null)}catch{}};i();let a=setInterval(()=>{i()},2e3);return()=>{n=!0,clearInterval(a)}},[e,t]),e?n:null},Wm=e=>{let t=(0,Q.c)(89),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:c,onInsert:l,onInsertAndSend:u,onActiveChange:d,onContentHeightChange:f,renderTrigger:p,topAccessory:m}=e,h=p===void 0||p,{t:g}=Xn(),{currentTheme:_}=fs(),v=Ko(Gm),y=K(Km),b;t[0]===y?b=t[1]:(b=Nc(Ec(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(qm),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}=rl(O),V=k===`recording`&&P===`model_download_in_progress`,H=Um(V),U=Z.useRef(k),W,ee;t[7]===k?(W=t[8],ee=t[9]):(W=()=>{U.current=k},ee=[k],t[7]=k,t[8]=W,t[9]=ee),Z.useEffect(W,ee);let te,ne;t[10]!==d||t[11]!==k?(te=()=>(d?.(k!==`idle`),()=>d?.(!1)),ne=[k,d],t[10]=d,t[11]=k,t[12]=te,t[13]=ne):(te=t[12],ne=t[13]),Z.useLayoutEffect(te,ne);let re,G;t[14]!==I||t[15]!==v||t[16]!==c||t[17]!==F||t[18]!==S?(re=()=>{if(!S||!v||c)return;let e=()=>{U.current===`idle`?F():U.current===`recording`&&(C.current=`insert`,I())};return window.addEventListener(`yuri:dictation-toggle`,e),()=>window.removeEventListener(`yuri:dictation-toggle`,e)},G=[S,v,c,F,I],t[14]=I,t[15]=v,t[16]=c,t[17]=F,t[18]=S,t[19]=re,t[20]=G):(re=t[19],G=t[20]),Z.useEffect(re,G);let ie,ae;t[21]!==L||t[22]!==I||t[23]!==k?(ie=()=>{if(k!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),C.current=`insert`,I();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),L())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ae=[k,I,L],t[21]=L,t[22]=I,t[23]=k,t[24]=ie,t[25]=ae):(ie=t[24],ae=t[25]),Z.useEffect(ie,ae);let oe=Z.useRef(null),se=Z.useRef(null),ce=Z.useRef(null),[le,ue]=Z.useState(null),de=k!==`idle`,fe=Z.useRef(f),pe,me;t[26]===f?(pe=t[27],me=t[28]):(pe=()=>{fe.current=f},me=[f],t[26]=f,t[27]=pe,t[28]=me),Z.useEffect(pe,me);let he=Z.useRef(!1),ge;t[29]===de?ge=t[30]:(ge=()=>{if(!de){he.current&&(he.current=!1,fe.current?.(null));return}let e=se.current,t=ce.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);he.current=!0,fe.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[29]=de,t[30]=ge);let _e;t[31]!==N||t[32]!==de||t[33]!==A||t[34]!==k?(_e=[de,A,k,N],t[31]=N,t[32]=de,t[33]=A,t[34]=k,t[35]=_e):_e=t[35],Z.useLayoutEffect(ge,_e);let ve,ye;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(ve=()=>()=>{he.current&&(he.current=!1,fe.current?.(null))},ye=[],t[36]=ve,t[37]=ye):(ve=t[36],ye=t[37]),Z.useEffect(ve,ye);let be,xe;if(t[38]===de?(be=t[39],xe=t[40]):(be=()=>{if(!de)return;let e=oe.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&ue(e.offsetHeight)},xe=[de],t[38]=de,t[39]=be,t[40]=xe),Z.useLayoutEffect(be,xe),!S||!v)return null;let Se=k!==`idle`,Ce;t[41]===I?Ce=t[42]:(Ce=e=>{C.current=e,I()},t[41]=I,t[42]=Ce);let we=Ce,Te;t[43]===R?Te=t[44]:(Te=()=>{C.current=`insert`,R()},t[43]=R,t[44]=Te);let Ee=Te,De;bb0:{if(k===`failed`){De=``;break bb0}if(k===`uploading`){let e;t[45]===g?e=t[46]:(e=g(`chat.dictation.processing`),t[45]=g,t[46]=e),De=e;break bb0}if(V){let e;t[47]!==H||t[48]!==g?(e=H===null?g(`chat.dictation.downloadingModel`):g(`chat.dictation.downloadingModelProgress`,{percent:String(H)}),t[47]=H,t[48]=g,t[49]=e):e=t[49],De=e;break bb0}let e;t[50]===g?e=t[51]:(e=g(`chat.dictation.listening`),t[50]=g,t[51]=e),De=e}let Oe=De,ke;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(ke={onMouseDown:Jm,onPointerDownCapture:Ym},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)(Hm,{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)(Hm,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:Vm(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 Gm(e){return e.dictationEnabled}function Km(e){return e.shortcutOverrides}function qm(){return!m()&&sl()}function Jm(e){return e.preventDefault()}function Ym(e){e.pointerType===`touch`&&e.preventDefault()}function Xm(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 Zm({onInsert:e,onPartial:t,onStart:n,onCancel:r,className:i,iconClassName:a,inputRef:o,onRecordingChange:s,onActiveChange:c,interactionMode:l=`desktop`,disabled:u=!1}){let{t:d}=Xn(),f=K(e=>e.shortcutOverrides),p=Nc(Ec(`toggle_dictation`,f)),m=rl({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]=Kn(()=>{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())});qn(`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}),qn(`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}),qn(`selectstart`,e=>{D.current!==null&&e.preventDefault()},document,{capture:!0}),qn(`mousemove`,e=>{D.current!==null&&e.preventDefault()},window,{capture:!0}),qn(`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),qn(`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}),qn(`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())});qn(`blur`,()=>{C||(z(),D.current===null?h.current&&F():B())},window),qn(`visibilitychange`,()=>{C||document.hidden&&(z(),D.current===null?h.current&&F():B())},document),qn(C?`yuri:mobile-dictation-toggle`:`yuri:dictation-toggle`,()=>{I()},window),qn(`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,Dp.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)(hl,{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)(Ys,{delayDuration:0,children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{variant:`ghost`,size:`icon`,className:Y(`shadow-none`,i),"aria-label":V,"aria-pressed":x,"aria-busy":w,disabled:S||v||u&&!x,onClick:()=>{I()},onBlur:C?void 0:F,children:w?(0,$.jsx)(hl,{decorative:!0}):(0,$.jsx)(Xm,{kind:`mic`,active:x&&!m.error,className:Y(a??`size-5`,m.error&&`text-[var(--status-error)]`)})})}),(0,$.jsx)(Js,{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 Qm=2e3,$m=L((e,t)=>({pending:!1,expiresAt:null,arm:(t=Qm)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),eh=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}},th=e=>xn({queryKey:[e.transport,`sessionChildren`,e.generation,In(e.directory),e.sessionID],queryFn:({signal:t})=>e.request(t),staleTime:0,gcTime:6e4,retry:!1}),nh=e=>Cn.fetchQuery(th(e)),rh=(e,t)=>e.id<t.id?-1:+(e.id>t.id),ih=(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(rh)},ah=30,oh=new Map;function sh(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function ch(e,t){let n=ce();if(!n)return!1;let r=n.getTranscript(we(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>Qr()}function lh(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function uh(e,t,n){let r=[...e.getState().session],i=Ro.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function dh(){let e=$o(),t=qi(),n=Vr(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=ce();if(!r||!t)return sh({kind:`unknown`,loadedTurns:0},!1);let i=we(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return sh(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}};di(a,t),Si(r,t),r.setState(a);for(let n of t)fe(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=oh.get(t);if(n)return oh.delete(t),oh.set(t,n),n;let r=new Set;for(oh.set(t,r);oh.size>ah;){let e=oh.keys().next().value;if(!e)break;let t=[...oh.get(e)??[]];oh.delete(e),a(e,t)}return r},[e,a]),l=(0,Z.useCallback)((r,i=e)=>{let o=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=bi(o.getState()),u=Gi(),d=Mr({seen:c,keep:r,limit:u,preserve:l});if(a(i,d),Ir()){let e=new Set([r,...c,...l]),t=(ce()?.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:ch(i,t));if(n.length>0){for(let e of n)c.delete(e);a(i,n)}}},[n,e,s,a,t]),u=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await pt(a,r):await Oe(a,r,{background:!0})}catch{return}if(i?.isStale?.())return;let u=ce()?.getTranscript(we(a,r));Ho({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await Wr({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),d=(0,Z.useCallback)(async(t,i)=>{await vr();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),c=Te.getScopedSdkClient(o);l(t,o);let d=r(t,o);return eh.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=ce(),i=we(o,t),l=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Ro.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&l&&d.kind!==`unknown`&&p?.status!==`error`&&f&&Jr(o,t)){Ho({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!l||f),h=lh({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Xo(async()=>c.session.get({sessionID:t}));if(n&&!e()){let r=ha(ye(n));e()||uh(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?u(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,l,u,e]),f=J(async(t,r)=>{let i=r||e;if(!t||!i)return;let a=n.ensureChild(i,{bootstrap:!1}),s=Te.getScopedSdkClient(i),l=c(),u=o(),d=()=>l!==c()||u!==o()||n.getChild(i)!==a,f=await nh({transport:u,generation:l,directory:i,sessionID:t,request:async e=>{let n=[],r=new Set,a;do{if(e.throwIfAborted(),l!==c()||u!==o())throw new DOMException(`Session children runtime changed`,`AbortError`);let d=await s.session.list(a?{cursor:a,limit:50}:{directory:i,parentID:t,limit:50},{signal:e});if(!Array.isArray(d?.data))throw Error(`session.list children returned no data`);if(n.push(...d.data.map(ye)),d.data.length<50)break;if(a=d.cursor?.next??void 0,!a||r.has(a))throw Error(`session.list children pagination did not advance`);r.add(a)}while(a);return n}}).catch(e=>{if(d())return null;throw e});!f||d()||a.setState(e=>{let n=ih(e.session,f,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})}),p=(0,Z.useCallback)((t,n)=>{let r=i(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,i]),m=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).loading,[e,i]),h=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).complete,[e,i]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;ut(we(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;ut(we(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(t=>{let n=t.directory||e;ut(we(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),y=J(async(t,r)=>{if(!t)return;await vr();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),s=c(),l=o(),u=()=>s!==c()||l!==o()||n.ensureChild(i,{bootstrap:!1})!==a,d=a.getState();try{if(await Oe(i,t),u())return;Ho({directory:i,sessionID:t,store:a}),await Wr({directory:i,sessionID:t,store:a,statusBeforePull:d.session_status?.[t],statusObservedAtBeforePull:d.session_status_observed_at?.[t],hasMessages:(ce()?.getTranscript(we(i,t)).messageOrder.length??0)>0,isStale:u})}catch{throw Error(`refresh transcript failed`)}});return(0,Z.useMemo)(()=>({ensureSessionRenderable:d,syncSession:d,loadChildren:f,hasMore:p,isLoading:m,isComplete:h,refreshSessionTranscript:y,optimistic:{add:g,remove:_,confirm:v}}),[d,f,p,m,h,y,g,_,v])}var fh=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,ph=e=>e===`original`||e===`modified`,mh=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},hh=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!fh(t.source))return null;let n=mh(t.startLine),r=mh(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:ph(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()}},gh=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(hh).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},_h=L()(B(R((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`yuri-inline-comment-drafts`,storage:_t(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:gh(e.drafts)}}),{name:`inline-comment-draft-store`}));function vh(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 yh(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(vh).join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-CkZORaFS.js","assets/rolldown-runtime-hePW80VL.js","assets/runtime-auth-ef9W7A43.js","assets/runtime-switch-CAZiOV2G.js","assets/runtime-fetch-BAN5Gnnp.js","assets/desktop-dp2Z0toS.js","assets/runtimeAPIRegistry-C2VogTny.js","assets/vendor-base-ui-CdzJ6My_.js","assets/platform-Dcd-lkPn.js","assets/vendor-zustand-o69pgTEK.js","assets/vendor-opencode-client-fxfj4IA_.js","assets/vendor-effect-DV9F8PTZ.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/useUIStore-NMQx_cnG.js","assets/persistence-BfjCXjLZ.js","assets/vendor-react-BP2cRVqX.js","assets/queryRuntime-BuRnpVtK.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/pathNormalization-ewtPqJWn.js","assets/vendor-pathe-vBmvQE8f.js","assets/runtime-file-resource-h3yIw4HU.js","assets/fileQueries-DbUx7NwP.js","assets/vendor-tanstack-react-query-CdqCAt40.js","assets/runtime-file-store-BVRgEtI-.js","assets/path-utils-jGozTg9d.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/runtime-file-download-CwP-HoXN.js","assets/vendor-pierre-diffs-DPBtNDJ5.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-BpfIZ1tg.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-BgnrCA96.js","assets/store-BhjP3zxz.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/useThemeSystem-8jhE4Zyk.js","assets/Icon-GJTjieJN.js","assets/dialog-D6jRorvP.js","assets/image-loading-Ctpxfqla.js","assets/image-loading-D9Z_BASK.css","assets/MobileWindowStack-DGLdgoGr.js","assets/appThemeRegistry-DdmE_Iv3.js","assets/useMobileNavigationStore-BQHfCZ55.js","assets/vendor-sonner-ZS8XIOVl.js","assets/useAssistantUIStore-D7JZlg_Q.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/agentColors-DWSbQXy2.js","assets/rasterizePng-056Poix7.js","assets/MarkdownRenderer-DnCTLWjR.js","assets/useEffectiveDirectory-RivT6KwZ.js","assets/markdownHeightCache-Dv5LnHPc.js","assets/dualLimitLru-D8Sphgua.js","assets/toolHelpers-DL452NVK.js","assets/ImageLoadingPlaceholder-C4VZA5iQ.js","assets/useWorkerHighlightedLines-BszN5sdj.js","assets/tooltip-BHHwyMVd.js","assets/vendor-tanstack-react-virtual-B_EO--9t.js","assets/markdownTheme-DHoKvD6O.js","assets/markdown-worker-oBGEB9Eg.js","assets/mobileBackNavigation-Bcg-mihS.js","assets/ToolOutputDialog-CbGuK5bP.css","assets/vendor-capacitor-app-B5H_XtmE.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}from"./runtime-auth-ef9W7A43.js";import{c as i,f as a,i as o,l as s,n as c,o as l,r as u,t as d}from"./runtime-switch-CAZiOV2G.js";import{n as f}from"./runtime-fetch-BAN5Gnnp.js";import{C as p,M as m,_ as h,b as g,m as _,t as v,w as y,x as b,y as x}from"./desktop-dp2Z0toS.js";import{t as S}from"./runtimeAPIRegistry-C2VogTny.js";import{c as C,f as w,g as T,h as E,i as D,m as O,n as k,o as A,p as j,r as M,s as N,u as P,v as F}from"./desktopHosts-ByGjetLz.js";import{r as I}from"./desktopRelayRestore-DIO6vl1K.js";import{a as L,i as R,o as z,r as B,s as V,t as H}from"./vendor-zustand-o69pgTEK.js";import{d as U,f as W,it as ee,l as te,nt as ne,p as re,rt as G,u as ie}from"./vendor-base-ui-CdzJ6My_.js";import{At as ae,Ci as oe,Cn as se,Cr as ce,Ct as le,Di as ue,Dn as de,Dr as fe,En as pe,Er as me,Hn as he,In as ge,It as _e,Kn as ve,Li as ye,Ln as be,Lt as xe,Mi as Se,Mn as Ce,Nr as we,Nt as Te,Oi as Ee,On as De,Or as Oe,Ot as ke,Qt as Ae,Ri as je,Sn as Me,Sr as Ne,Ti as Pe,Tn as Fe,Vn as Ie,Wn as Le,Xt as Re,Yt as ze,_i as Be,an as Ve,br as He,cn as Ue,en as We,fn as Ge,hn as Ke,jn as qe,jr as Je,jt as Ye,kn as Xe,kt as Ze,mn as Qe,n as $e,nn as et,on as tt,pn as nt,qt as rt,rn as it,rr as at,sn as ot,t as st,tn as ct,vn as lt,vr as ut,xi as dt,xn as ft,xr as pt,yn as mt,zi as ht}from"./platform-Dcd-lkPn.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{_ as gt,b as _t,c as vt,f as yt,g as bt,h as xt,n as K,y as St}from"./useUIStore-NMQx_cnG.js";import{$ as Ct,A as wt,B as Tt,C as Et,Ct as Dt,F as Ot,G as kt,J as At,K as jt,L as Mt,M as Nt,Ot as Pt,Pt as Ft,Q as It,R as Lt,S as Rt,T as zt,Tt as Bt,V as Vt,W as Ht,X as Ut,Y as Wt,_ as Gt,at as Kt,b as qt,f as Jt,ft as Yt,g as Xt,i as Zt,it as Qt,j as $t,lt as en,m as tn,ot as nn,pt as rn,q as an,r as on,rt as sn,st as cn,t as ln,tt as un,v as dn,vt as fn,wt as pn,x as mn,y as hn,yt as gn}from"./persistence-BfjCXjLZ.js";import{n as _n}from"./vendor-react-BP2cRVqX.js";import{i as vn}from"./vendor-tanstack-query-core-BWz0ose6.js";import{c as yn,i as bn,n as q,o as xn,t as Sn}from"./vendor-tanstack-react-query-CdqCAt40.js";import{a as Cn,n as wn,o as Tn}from"./queryRuntime-BuRnpVtK.js";import{d as En,l as Dn,u as On}from"./fileQueries-DbUx7NwP.js";import{a as kn,i as An,n as jn,o as Mn,t as Nn}from"./path-utils-jGozTg9d.js";import{o as Pn}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as Fn,t as In}from"./pathNormalization-ewtPqJWn.js";import{i as Ln,u as Rn}from"./vendor-pierre-diffs-DPBtNDJ5.js";import{r as zn,t as Bn}from"./vendor-sonner-ZS8XIOVl.js";import{a as Vn,f as Hn,i as Un,m as Wn,n as J,o as Gn,p as Kn,r as qn,u as Jn}from"./vendor-reactuses-core-BpfIZ1tg.js";import{d as Yn,f as Xn,i as Zn,l as Qn,p as $n,r as Y,t as er,v as tr,y as nr}from"./button-BgnrCA96.js";import{i as rr,t as ir}from"./store-BhjP3zxz.js";import{$ as ar,$i as or,$n as sr,$t as cr,A as lr,Aa as ur,An as dr,At as fr,B as pr,Bn as mr,C as hr,Ca as gr,Cn as _r,Co as vr,Ct as yr,D as br,Di as xr,Dn as Sr,Dt as Cr,E as wr,Ea as Tr,Ei as Er,En as Dr,Et as Or,F as kr,Fa as Ar,Fi as jr,Fn as Mr,Ft as Nr,G as Pr,Ga as Fr,Gi as Ir,Gr as Lr,Gt as Rr,H as zr,Hn as Br,Ht as Vr,I as Hr,Ia as Ur,Ii as Wr,In as Gr,It as Kr,J as qr,Ji as Jr,Jn as Yr,K as Xr,Ka as Zr,Ki as Qr,Kr as $r,Kt as ei,L as ti,La as ni,Ln as ri,M as ii,Ma as ai,Mi as oi,Mn as si,N as ci,Na as li,Ni as ui,Nn as di,Nr as fi,O as pi,Oi as mi,On as hi,Ot as gi,P as _i,Pa as vi,Pi as yi,Pn as bi,Pr as xi,Pt as Si,Q as Ci,Qi as wi,Qn as Ti,Qr as Ei,Qt as Di,R as Oi,Ra as ki,Rn as Ai,Rr as ji,Rt as Mi,Si as Ni,St as Pi,T as Fi,Tn as Ii,Tt as Li,U as Ri,Ua as zi,Un as Bi,Ut as Vi,V as Hi,Vn as Ui,W as Wi,Wi as Gi,Wr as Ki,Wt as qi,X as Ji,Xi as Yi,Xr as Xi,Xt as Zi,Y as Qi,Ya as $i,Yi as ea,Yt as ta,Z as na,Zi as ra,Zr as ia,Zt as aa,_i as oa,_n as sa,_r as ca,_t as la,aa as ua,ai as da,an as fa,ar as pa,at as ma,ba as ha,bi as ga,bn as _a,bo as va,bt as ya,c as ba,ca as xa,ci as Sa,cn as Ca,d as wa,da as Ta,di as Ea,dn as Da,do as Oa,dt as ka,ea as Aa,ei as ja,et as Ma,fa as Na,fi as Pa,fn as Fa,fo as Ia,ft as La,g as Ra,ga as za,gi as Ba,gn as Va,gr as Ha,gt as Ua,hn as Wa,i as Ga,ia as Ka,ii as qa,in as Ja,it as Ya,j as Xa,ja as Za,ji as Qa,jt as $a,k as eo,ki as to,kt as no,la as ro,m as io,mi as ao,mn as oo,mt as so,n as co,na as lo,ni as uo,nr as fo,nt as po,oa as mo,oi as ho,on as go,ot as _o,pn as vo,pt as yo,q as bo,qi as xo,qn as So,qr as Co,qt as wo,r as To,ra as Eo,rn as Do,rr as Oo,rt as ko,s as Ao,sa as jo,si as Mo,sn as No,so as Po,ta as Fo,tr as Io,tt as Lo,ua as Ro,ui as zo,un as Bo,v as Vo,vi as Ho,vn as Uo,vr as Wo,vt as Go,wa as Ko,wn as qo,wo as Jo,wt as Yo,xa as Xo,xt as Zo,yi as Qo,yn as $o,yo as es,yr as ts,yt as ns,z as rs,za as is,zn as as}from"./useMobileNavigationStore-BQHfCZ55.js";import{t as os}from"./agentColors-DWSbQXy2.js";import{t as ss}from"./dualLimitLru-D8Sphgua.js";import{i as cs,n as ls,r as us,t as ds}from"./AgentAvatar-RbwoyGL7.js";import{n as fs,r as ps,t as ms}from"./useThemeSystem-8jhE4Zyk.js";import{n as X}from"./Icon-GJTjieJN.js";import{a as hs,i as gs,n as _s,o as vs,r as ys,s as bs,t as xs}from"./dialog-D6jRorvP.js";import{E as Ss,n as Cs}from"./gitApi-BkhGiTtu.js";import{a as ws}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{A as Ts,C as Es,D as Ds,O as Os,S as ks,_ as As,a as js,b as Ms,f as Ns,h as Ps,i as Fs,k as Is,l as Ls,m as Rs,n as zs,o as Bs,s as Vs,u as Hs,w as Us,x as Ws,y as Gs}from"./projectMeta-QJd1QrkI.js";import{t as Ks}from"./input-CDVEeuDT.js";import{i as qs,n as Js,t as Ys}from"./tooltip-BHHwyMVd.js";import{$ as Xs,At as Zs,B as Qs,Bt as $s,Ft as ec,Gt as tc,H as nc,Ht as rc,J as ic,Jt as ac,K as oc,Kt as sc,L as cc,Ot as lc,Pt as uc,Q as dc,Qt as fc,R as pc,Rt as mc,St as hc,Vt as gc,X as _c,Y as vc,Z as yc,_t as bc,an as xc,at as Sc,d as Cc,et as wc,ft as Tc,gt as Ec,i as Dc,in as Oc,it as kc,jt as Ac,kt as jc,lt as Mc,mt as Nc,n as Pc,nt as Fc,o as Ic,on as Lc,pt as Rc,q as zc,rt as Bc,tt as Vc,ut as Hc,z as Uc,zt as Wc}from"./speechSettingsQueries-tUWgMwuK.js";import{t as Gc}from"./YuriLogo-jfvSPXYV.js";import{r as Kc}from"./device-Dd4YwDwq.js";import{c as qc,d as Jc,f as Yc,l as Xc,n as Zc,o as Qc,p as $c,r as el,u as tl}from"./image-loading-Ctpxfqla.js";import{S as nl,a as rl,c as il,g as al,l as ol,o as sl,x as cl,y as ll}from"./dropdown-menu.styles-BKQriop5.js";import{S as ul,b as dl,t as fl,x as pl}from"./MobileResizableSheet-B8kpq7AR.js";import{A as ml,D as hl,E as gl,O as _l,S as vl,T as yl,_ as bl,a as xl,b as Sl,c as Cl,d as wl,f as Tl,g as El,h as Dl,j as Ol,k as kl,l as Al,m as jl,o as Ml,p as Nl,s as Pl,u as Fl,v as Il,w as Ll,x as Rl,y as zl}from"./sessionChangeSummary-CY9vQ5i1.js";import{o as Bl}from"./vendor-framer-motion-DsGBcZHB.js";import{a as Vl,i as Hl,o as Ul,s as Wl,u as Gl}from"./fileMentionTouchSelection-BSSggGfQ.js";import{C as Kl,D as ql,E as Jl,O as Yl,S as Xl,T as Zl,a as Ql,b as $l,c as eu,d as tu,f as nu,i as ru,j as iu,k as au,l as ou,n as su,o as cu,p as lu,r as uu,s as du,t as fu,u as pu,w as mu,x as hu,y as gu}from"./insertionBoundaries-8-NDZp_y.js";import{C as _u,D as vu,E as yu,O as bu,S as xu,T as Su,_ as Cu,a as wu,b as Tu,c as Eu,d as Du,f as Ou,g as ku,h as Au,j as ju,l as Mu,m as Nu,o as Pu,p as Fu,r as Iu,s as Lu,t as Ru,u as zu,v as Bu,w as Vu,x as Hu,y as Uu}from"./appThemeRegistry-DdmE_Iv3.js";import{a as Wu,n as Gu,o as Ku,r as qu,t as Ju}from"./MarkdownRenderer-DnCTLWjR.js";import{t as Yu}from"./OverlayScrollbar-DWZJpEVx.js";import{n as Xu,r as Zu}from"./textarea-DI9j9018.js";import{_ as Qu,a as $u,c as ed,g as td,l as nd,o as rd,t as id,v as ad,y as od}from"./vendor-dnd-kit-core-5pNnzVdw.js";import{i as sd,n as cd,o as ld,s as ud,t as dd}from"./vendor-dnd-kit-sortable-Dm50I0m7.js";import{a as fd,n as pd,t as md}from"./url-MRa-FtQa.js";import{a as hd,o as gd,t as _d,u as vd}from"./toolHelpers-DL452NVK.js";import{t as yd}from"./react-BYRXYlGz.js";import{n as bd,t as xd}from"./useEffectiveDirectory-RivT6KwZ.js";import{t as Sd}from"./ImageLoadingPlaceholder-C4VZA5iQ.js";import{t as Cd}from"./LoadingImage-BZjPXN_m.js";import{a as wd,i as Td,l as Ed,n as Dd,o as Od,r as kd,s as Ad,t as jd}from"./FadeInOnReveal-Dt1nUq5y.js";import{A as Md,C as Nd,D as Pd,E as Fd,O as Id,S as Ld,T as Rd,_ as zd,a as Bd,b as Vd,c as Hd,g as Ud,h as Wd,i as Gd,k as Kd,o as qd,p as Jd,r as Yd,s as Xd,t as Zd,v as Qd,w as $d,x as ef,y as tf}from"./useWorkerHighlightedLines-BszN5sdj.js";import{t as nf}from"./vendor-cmdk-RDxC-9Iz.js";import{t as rf}from"./sortable-tabs-strip-C4STfRdG.js";import{a as af}from"./markdownHeightCache-Dv5LnHPc.js";import{n as of,t as sf}from"./vendor-tanstack-react-virtual-B_EO--9t.js";import{n as cf}from"./markdownTheme-DHoKvD6O.js";import{t as lf}from"./vendor-motion-CIQx6DBb.js";import{n as uf,t as df}from"./useFontPreferences-Bwzz0JNf.js";var ff=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=Ie(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=(he(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:(he(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=Ie(t);return`${n.length}`,n.forEach((e,t)=>{let n=he(e.id)||[];`${t}${e.role}${e.id}${n.length}`}),e?this.truncateMessages(n):n},async getAppStatus(){let e=le.getState(),t=wa.getState(),n=Ia.getState(),r=e.currentDirectory||null,i=Te.getDirectory()??null,a=Le(),o=new Set,s={};a.forEach(e=>{let t=e.directory;typeof t==`string`&&t.trim().length>0?(o.add(t),s[t]=(s[t]??0)+1):s[`(none)`]=(s[`(none)`]??0)+1});let c=(()=>{if(typeof window>`u`)return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem(`lastDirectory`),homeDirectory:window.localStorage.getItem(`homeDirectory`)}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}})(),l=S(),u=typeof window<`u`&&!!window.__YURI_ELECTRON__,d=async e=>{try{return await e.json()}catch{return null}},p=async e=>{try{return await e.text()}catch{return null}},m=async e=>{try{let t=await f(e);return t.ok?await d(t):{status:t.status}}catch(e){return{error:e instanceof Error?e.message:String(e)}}},h=null,g=null,_=null,v=null;try{let e=await Te.getSdkClient().location.get(ff(r));h=xe(e)}catch(e){h={error:e instanceof Error?e.message:String(e)}}try{g=(await Te.getSdkClient().location.get(ff(r)))?.project??null}catch(e){g={error:e instanceof Error?e.message:String(e)}}_=await m(`/api/config/settings`);try{let e=await f(`/api/health`),t=e.headers.get(`content-type`)||``,n=await p(e),r=t.toLowerCase().includes(`application/json`),i=null;if(r&&n)try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)&&(i=e)}catch{i=null}v={status:e.status,ok:e.ok,contentType:t,type:r?`json`:`html`,openCodePort:i?.openCodePort??null,openCodeRunning:i?.openCodeRunning??null,openCodeSecureConnection:i?.openCodeSecureConnection??null,openCodeAuthSource:i?.openCodeAuthSource??null,isOpenCodeReady:i?.isOpenCodeReady??null,lastOpenCodeError:i?.lastOpenCodeError??null,preview:n?n.slice(0,120):null}}catch(e){v={error:e instanceof Error?e.message:String(e)}}let y={isGitRepo:null};if(r)try{y.isGitRepo=await Cs(r)}catch(e){y={isGitRepo:null,error:e instanceof Error?e.message:String(e)}}let b=n.projects.map(e=>({id:e.id,path:e.path,label:e.label}));return{runtime:{platform:l?.runtime?.platform??null,isDesktop:u,isVSCode:!!l?.runtime?.isVSCode,hasRuntimeApis:!!l,desktopServerOrigin:null},location:typeof window<`u`?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:r,opencodeDirectory:h?.directory||h?.worktree||i,homeDirectory:e.homeDirectory||null,isHomeReady:e.isHomeReady,hasPersistedDirectory:e.hasPersistedDirectory,isSwitchingDirectory:e.isSwitchingDirectory},projects:{total:n.projects.length,activeProjectId:n.activeProjectId,samples:b},sessions:{total:a.length,currentSessionId:t.currentSessionId,lastLoadedDirectory:t.lastLoadedDirectory,uniqueDirectories:o.size,directorySamples:Array.from(o).slice(0,5),directoryCounts:s},worktrees:{available:t.availableWorktrees.length,metadataEntries:t.worktreeMetadata.size},git:y,localStorage:c,opencode:{pathInfo:h,projectInfo:g,health:v},yuri:{settingsInfo:_}}},async buildDiagnosticsReport(){let e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return Yn(e)},async copyDiagnosticsReport(){let e=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(e),report:e}},checkLastMessage(){let e=this.getLastAssistantMessage();if(!e)return!1;let t=e.isEmpty||e.isEmptyResponse;return t&&(console.error(`[ALERT] PROBLEMATIC MESSAGE DETECTED!`),e.messageId,e.isEmpty,e.isEmptyResponse,e.partsCount,e.parts.length>0&&e.parts),t},getStreamingState(){let e=wa.getState(),t=dr.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=Ie(e).filter(e=>e.role===`assistant`).filter(e=>{let t=he(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=he(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=Ie(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=he(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=Ie(e).filter(e=>e.role===`assistant`);if(t.length===0)return null;let n=t[t.length-1],r=(he(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=dr.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}}},ke(),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(ee(),1),Q=_n(),pf=async()=>{if(typeof window>`u`)return;let e=null;try{e=Ft(`lastDirectory`)}catch(e){console.warn(`Failed to read saved directory preferences:`,e)}e&&!p()&&le.getState().setDirectory(e,{showOverlay:!1})},mf=new Map,hf=e=>mf.get(e)??null,gf=({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:i},a={})=>{let o=mf.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 mf.set(e,s),s},_f=async({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,startWatchers:i,onError:a})=>{await gf({runtimeKey:e,initializeAppearance:t,syncSettings:n,applyDirectory:r,onError:a})&&i()},vf=(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 yf(e){return!e||e===`idle`?null:e===`ready`?`ok`:e===`error`?`unreachable`:`auth`}function bf(e,t){let n=e.via===`relay`;return t?n:!n}function xf(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?yf(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||bf(o,a))&&(u=Math.max(0,Math.round(o.latencyMs))),{statusKind:c,showViaRelay:l,latencyMs:u}}var $=G(),Sf=`local`,Cf=9e4,wf=`SSH connection cancelled`,Tf=e=>I(e),Ef={},Df=e=>{let t=O(e);if(!t)return e.trim();try{let e=new URL(t);return e.pathname.endsWith(`/`)||(e.pathname=`${e.pathname}/`),e.toString()}catch{return t}},Of=()=>typeof window>`u`?``:window.__YURI_LOCAL_ORIGIN__||window.location.origin,kf=async()=>b()?A().catch(()=>``):``,Af=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`,jf=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`,Mf=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Nf=e=>e===`unreachable`||e===`wrong-service`||e===`incompatible`,Pf=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`,Ff=e=>new Promise(t=>window.setTimeout(t,e)),If=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`}},Lf=async()=>{let e=await fc().catch(()=>[]),t={};for(let n of e)t[n.id]=n;return t},Rf=async(e,t,n,r)=>{let i=Date.now()+t;for(;Date.now()<i;){if(r?.())throw Error(wf);let t=(await fc(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 Ff(700)}throw r?.()?Error(wf):Error(`Timed out waiting for SSH connection`)},zf=e=>({id:Sf,label:`Local`,url:e||Of()}),Bf=e=>{let t=typeof window>`u`?``:window.location.href,n=e.find(e=>e.id===Sf)?.url||Of(),r=d(),i=O(n)||n,a=O(t)||t,o=u(),s=e.find(e=>e.relay&&Tf(e)===o);if(s)return{id:s.id,label:s.label,url:s.url};if(r&&j(r,n))return{id:Sf,label:`Local`,url:i};let c=e.find(e=>r?j(r,P(e)):!1);if(c)return{id:c.id,label:c.label,url:O(P(c))||P(c)};if(t&&j(t,n))return{id:Sf,label:`Local`,url:i};let l=e.find(e=>t?j(t,e.url):!1);return l?{id:l.id,label:l.label,url:O(l.url)||l.url}:t.startsWith(`yuri-ui://`)?{id:Sf,label:`Local`,url:i}:{id:`custom`,label:T(a||`Instance`),url:a}};function Vf({open:e,onOpenChange:t,embedded:n=!1,onHostSwitched:r,onBusyChange:a}){let{t:s}=Xn(),c=K(e=>e.setSettingsDialogOpen),l=K(e=>e.setSettingsPage),u=Ko(e=>e.isConnected),d=Ko(e=>e.connectionPhase),[f,p]=Z.useState([]),[m,h]=Z.useState(null),[_,v]=Z.useState(()=>({...Ef}));Z.useEffect(()=>{Object.assign(Ef,_)},[_]);let[y,x]=Z.useState(!1),[S,A]=Z.useState(!1),[j,I]=Z.useState(!1),L=xc(),R=Lc(),[z,B]=Z.useState(null),V=z||R,H=Z.useRef(!1),U=J(e=>{H.current=e!==null,B(e),a?.(e!==null)}),[W,ee]=Z.useState({}),[te,ne]=Z.useState({}),[re,G]=Z.useState({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),[ie,ae]=Z.useState(``),[oe,se]=Z.useState(()=>Of()),[ce,le]=Z.useState(null),[ue,de]=Z.useState(``),[fe,pe]=Z.useState(``),[me,he]=Z.useState(0),ge=Z.useRef(0),_e=Z.useMemo(()=>[zf(oe),...f.map(e=>({...e,url:O(e.url)||e.url}))],[f,oe]),ve=Z.useMemo(()=>new Set(Object.keys(W)),[W]),ye=Z.useMemo(()=>_e.filter(e=>e.id===Sf||w(e,ve)),[_e,ve]);Z.useEffect(()=>i(()=>he(e=>e+1)),[]);let be=Z.useMemo(()=>Bf(_e),[_e,me]),xe=Z.useMemo(()=>o().startsWith(`relay:`),[me]),Se=Z.useMemo(()=>{let e=m||Sf;return _e.find(t=>t.id===e)?.label||s(`desktopHostSwitcher.instance.local`)},[_e,m,s]),Ce=Z.useCallback(async(e,t)=>{if(g()){I(!0),ae(``);try{let n=e.filter(e=>e.id!==Sf);await D({hosts:n,defaultHostId:t}),p(n),h(t)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToSave`))}finally{I(!1)}}},[s]),we=Z.useCallback(()=>{l(`remote-instances`),c(!0),t(!1)},[t,c,l]),Te=Z.useCallback(async()=>{if(g()){x(!0),ae(``);try{let[e,t,n]=await Promise.all([M(),ac().catch(()=>({instances:[]})),Lf()]);e.localOrigin&&se(e.localOrigin);let r={};for(let e of t.instances)r[e.id]=!0;p(e.hosts||[]),h(e.defaultHostId??null),ee(r),ne(n)}catch(e){ae(e instanceof Error?e.message:s(`desktopHostSwitcher.error.failedToLoad`)),p([]),h(null),ee({}),ne({})}finally{x(!1)}}},[s]),Ee=Z.useCallback(async e=>{if(g()){A(!0);try{let t=await kf(),n=await Promise.all(e.map(async e=>{let n=async()=>{let t=await E(e.relay,{clientToken:e.clientToken||null}).catch(()=>({status:`unreachable`,latencyMs:0}));return{status:t.status,latencyMs:t.latencyMs,...t.status===`ok`?{via:`relay`}:{}}};if(e.relay&&!e.apiUrl)return[e.id,await n()];let r=O(b()?P(e):e.url);if(!r)return[e.id,{status:`unreachable`,latencyMs:0}];let i=e.id===Sf?t:e.clientToken||``,a=await k(r,{clientToken:i||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(Mf(a.status)&&e.relay){let t=await n();if(t.status===`ok`)return[e.id,t]}return[e.id,{status:a.status,latencyMs:a.latencyMs}]})),r={};for(let[e,t]of n)r[e]=t;v(r)}finally{A(!1)}}},[]);Z.useEffect(()=>{if(!e){le(null),de(``),pe(``),B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),ae(``);return}Te()},[e,Te]),Z.useEffect(()=>{e&&Ee(ye)},[e,ye,Ee]),Z.useEffect(()=>{if(!e||!g())return;let t=!1,n=async()=>{let e=await Lf();t||ne(e)};n();let r=window.setInterval(()=>{typeof document<`u`&&document.visibilityState!==`visible`||n()},1500);return()=>{t=!0,window.clearInterval(r)}},[e]);let De=J(async e=>{if(H.current||L)return;let t=e.id===Sf?oe:O(e.url)||``,n=e.id===Sf?oe:O(P(e))||``,i=!!e.relay&&!e.apiUrl&&e.id!==Sf;if(!t&&!i)return;if(b()){if(!n&&!e.relay||L)return;U(e.id);try{let t=e.id===Sf?await kf():null,i=await Oc({host:e,inlineProgress:!0,cachedProbe:_[e.id]||null,...e.id===Sf?{localApiOrigin:n,localClientToken:t}:{}});v(t=>({...t,[e.id]:i.status})),i.ok&&r?.()}finally{U(null)}return}let a=!!W[e.id];if(e.id!==Sf&&a&&g()){let n=te[e.id],i=await fc(e.id).then(t=>t.find(t=>t.id===e.id)||null).catch(()=>null);i&&(n=i,ne(t=>({...t,[e.id]:i})));let a=O(n?.localUrl||e.url||``);if(n?.phase===`ready`&&a){let e=Df(a);r?.(),window.location.assign(e);return}B(e.id);let o=ge.current+1;ge.current=o,G({open:!0,hostId:e.id,hostLabel:T(e.label),phase:`master_connecting`,detail:null,error:null,errorCode:null});try{if(await tc(e.id),o!==ge.current)return;let n=await Rf(e.id,Cf,e=>{ne(t=>({...t,[e.id]:e})),G(t=>({...t,phase:e.phase,detail:e.detail||null,errorCode:e.errorCode||null}))},()=>o!==ge.current);if(o!==ge.current)return;let i=Df(O(n.localUrl||``)||t);r?.(),window.location.assign(i);return}catch(t){if(o!==ge.current)return;let n=t instanceof Error?t.message:String(t);if(n===wf)return;let r=$s(re.errorCode,n);G(e=>({...e,error:n,errorCode:r})),ji.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Wc(s(gc(r)),r,n)});return}finally{o===ge.current&&B(null)}}if(e.id!==Sf&&g()){B(e.id);let n=await k(t,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null}).catch(()=>({status:`unreachable`,latencyMs:0}));if(v(t=>({...t,[e.id]:{status:n.status,latencyMs:n.latencyMs}})),Mf(n.status)){ji.error(s(`desktopHostSwitcher.toast.instanceUnreachable`,{host:T(e.label)})),B(null);return}}let o=Df(t);r?.();try{window.location.assign(o)}catch{window.location.href=o}}),Oe=Z.useCallback(()=>{le(null),de(``),pe(``)},[]),ke=Z.useCallback(e=>{e.stopPropagation()},[]),Ae=Z.useCallback(async()=>{if(!ce)return;if(ce===Sf){Oe();return}let e=F(fe);if(!e){ae(s(`desktopHostSwitcher.error.invalidUrl`));return}let t=e.persistedUrl,n=(ue||T(t)).trim(),r=f.map(e=>e.id===ce?{...e,label:n,url:t,apiUrl:t}:e);await Ce(r,m),Oe(),e.redeemUrl&&window.location.assign(e.redeemUrl)},[Oe,f,m,ue,fe,ce,Ce,s]),je=Z.useCallback(async e=>{await Ce(f,e===Sf?Sf:e)},[f,Ce]),Me=J(async e=>{if(H.current||L)return;U(e.id);let t=e=>{ji.error(s(`desktopHostSwitcher.error.failedToOpenNewWindow`),{description:e instanceof Error?e.message:String(e)})};try{if(e.relay&&e.id!==Sf)await C(e.id);else{let t=e.id===Sf?oe:P(e);if(!t)return;let n=Df(t);await N(n,{clientToken:e.clientToken||null,requestHeaders:e.requestHeaders||null})}r?.()}catch(e){t(e)}finally{U(null)}}),Ne=J(async()=>{ge.current+=1,B(null),G(e=>({...e,open:!1,hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}));let e=Df(oe);if(b()){if(L)return;let e=await kf();(await Oc({host:zf(oe),localApiOrigin:oe,localClientToken:e})).ok&&r?.();return}r?.(),window.location.assign(e)}),Pe=Z.useCallback(async()=>{let e=re.hostId||V;ge.current+=1,B(null),G({open:!1,hostId:null,hostLabel:``,phase:`idle`,detail:null,error:null,errorCode:null}),!(!e||e===Sf||!g())&&await sc(e).catch(()=>{})},[re.hostId,V]),Fe=Z.useCallback(()=>{let e=re.hostId;if(!e)return;let t=_e.find(t=>t.id===e);t&&De(t)},[_e,De,re.hostId]),Ie=J(async e=>{if(!(!g()||H.current||L)){U(e.id);try{await tc(e.id),(await Rf(e.id,Cf,e=>{ne(t=>({...t,[e.id]:e}))})).phase===`ready`&&ji.success(s(`desktopHostSwitcher.toast.sshConnected`,{host:T(e.label)}))}catch(t){let n=t instanceof Error?t.message:String(t);if(n!==wf){let t=$s(null,n);ji.error(s(`desktopHostSwitcher.toast.sshFailedToConnect`,{host:T(e.label)}),{description:Wc(s(gc(t)),t,n)})}}finally{U(null)}}});if(!g())return null;let Le=g(),Re=(0,$.jsxs)($.Fragment,{children:[n?(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-[var(--interactive-border)] px-3 py-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex items-baseline gap-1.5 typography-ui-label`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.current`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`•`}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s(`desktopHostSwitcher.header.default`)}),(0,$.jsx)(`span`,{className:`max-w-[9rem] truncate text-muted-foreground`,children:T(Se)})]}),(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors`,`hover:text-foreground hover:bg-interactive-hover`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),onClick:()=>void Ee(ye),disabled:!Le||y||S,"aria-label":s(`desktopHostSwitcher.actions.refreshInstancesAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)})})]})}):(0,$.jsxs)(hs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`server`,className:`h-5 w-5`}),s(`desktopHostSwitcher.title`)]}),(0,$.jsx)(ys,{children:s(`desktopHostSwitcher.description`)})]}),!n&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(be.label)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.header.currentDefaultColon`)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:T(Se)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsxs)(er,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Ee(ye),disabled:!Le||y||S,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,S&&`animate-spin`)}),s(`desktopHostSwitcher.actions.refresh`)]})})]}),!Le&&(0,$.jsx)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:s(`desktopHostSwitcher.state.limitedOnPage`)})}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:Y(`space-y-1`,n&&`space-y-1.5 px-3 py-1`),children:y?(0,$.jsx)(`div`,{className:`px-2 py-2 text-muted-foreground text-sm`,children:s(`desktopHostSwitcher.state.loading`)}):ye.map(e=>{let t=e.id===Sf,r=!!W[e.id],i=e.id===be.id,a=(m||Sf)===e.id,o=_[e.id]||null,c=te[e.id]||null,l=xf({isActive:i,isSsh:r,runtimeIsConnected:u,runtimeConnectionPhase:d,currentTransportIsRelay:xe,probe:o,sshPhase:c?.phase}),f=l.statusKind,p=l.showViaRelay,h=ce===e.id,g=t?oe:O(e.url)||e.url,v=e.id===Sf?s(`desktopHostSwitcher.instance.local`):T(e.label),y=e.relay&&!e.apiUrl?s(`mobile.connect.relay.badge`):T(g);return(0,$.jsxs)(`div`,{className:Y(`app-region-no-drag group flex items-center gap-2 px-2.5 py-2 rounded-md overflow-hidden`,n&&`rounded-xl bg-[var(--surface-muted)] px-3 py-2.5`,n&&i&&`bg-[var(--interactive-selection)]/25`,h?`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`,h&&`pointer-events-none opacity-70`),onClick:()=>void De(e),disabled:!!V,"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.switchToAria`,{instance:v}),children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,$.jsx)(`span`,{className:Y(`h-2 w-2 rounded-full flex-shrink-0`,Af(f))}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium truncate text-foreground`,children:v}),i&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 text-muted-foreground bg-muted px-1 rounded leading-none pb-px border border-border/50`,children:s(`desktopHostSwitcher.header.current`)}),r&&(0,$.jsx)(`span`,{className:`typography-micro flex-shrink-0 px-1 rounded leading-none pb-px text-[var(--status-info)] bg-[var(--status-info)]/10`,children:`SSH`})]}),(0,$.jsxs)(`div`,{className:Y(`typography-micro truncate`,jf(f)),children:[r&&(!i||V===e.id)?s(If(c?.phase)):s(Pf(f)),l.latencyMs==null?``:s(`desktopHostSwitcher.status.ping`,{ms:l.latencyMs}),p?` · ${s(`settings.remoteInstances.clientAuth.state.viaRelay`)}`:``]}),(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70 truncate font-mono`,children:y})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[r&&!t&&(c?.phase===`idle`||!c?.phase?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 px-2.5`,disabled:!!V,onClick:t=>{t.stopPropagation(),Ie(e)},children:[V===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(X,{name:`plug-2`,className:`h-3.5 w-3.5`}),s(`desktopHostSwitcher.actions.connect`)]}):(0,$.jsx)(`div`,{className:`h-8 w-8 opacity-0 pointer-events-none`,"aria-hidden":`true`})),(0,$.jsxs)(Ys,{delayDuration:600,children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`app-region-no-drag h-8 w-8 rounded-md inline-flex items-center justify-center hover:bg-interactive-hover transition-colors`,a?`text-primary hover:text-primary/80`:`text-muted-foreground/60 hover:text-primary/80`),onClick:()=>void je(e.id),"aria-label":s(a?`desktopHostSwitcher.actions.defaultInstanceAria`:`desktopHostSwitcher.actions.setAsDefaultAria`),disabled:j||!a&&Nf(f),children:a?(0,$.jsx)(X,{name:`star-fill`,className:`h-4 w-4`}):(0,$.jsx)(X,{name:`star`,className:`h-4 w-4`})})}),(0,$.jsx)(Js,{sideOffset:6,children:s(a?`desktopHostSwitcher.header.default`:`desktopHostSwitcher.actions.setAsDefault`)})]}),(0,$.jsxs)(Ys,{delayDuration:600,children:[(0,$.jsx)(qs,{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`,Nf(f)?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground/60 hover:text-foreground`),onClick:t=>{t.stopPropagation(),Me(e)},disabled:!!V||Nf(f),"aria-busy":V===e.id,"aria-label":s(`desktopHostSwitcher.actions.openInNewWindowAria`),children:(0,$.jsx)(X,{name:V===e.id?`loader-4`:`window`,className:Y(`h-4 w-4`,V===e.id&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:Nf(f)?s(`desktopHostSwitcher.state.instanceUnreachable`):s(`desktopHostSwitcher.actions.openInNewWindow`)})]})]})]},e.id)})})}),Le&&ce&&ce!==Sf&&(0,$.jsxs)(`div`,{className:`flex-shrink-0 rounded-lg border border-border/50 bg-muted/20 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground`,children:s(`desktopHostSwitcher.edit.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(er,{type:`button`,variant:`outline`,size:`sm`,onClick:Oe,disabled:j,children:s(`desktopHostSwitcher.actions.cancel`)}),(0,$.jsxs)(er,{type:`button`,size:`sm`,onClick:()=>void Ae(),disabled:j,children:[j?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):null,s(`desktopHostSwitcher.actions.save`)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,$.jsx)(Ks,{value:ue,onChange:e=>de(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.labelPlaceholder`),disabled:j}),(0,$.jsx)(Ks,{value:fe,onChange:e=>pe(e.target.value),onKeyDown:ke,placeholder:s(`desktopHostSwitcher.field.urlPlaceholder`),disabled:j})]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 border-t border-[var(--interactive-border)]`,children:(0,$.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-2 py-2 text-left text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,onClick:we,disabled:!!V,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:s(`desktopHostSwitcher.actions.addInstance`)})]})}),ie&&(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-status-error`,children:ie})]}),ze=(0,$.jsx)(xs,{open:re.open,onOpenChange:e=>{if(!e&&V){Pe();return}G(t=>({...t,open:e,...e?{}:{hostId:null,error:null,errorCode:null,detail:null,phase:`idle`}}))},children:(0,$.jsxs)(_s,{className:`w-[min(28rem,calc(100vw-2rem))] max-w-none`,children:[(0,$.jsxs)(hs,{children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(`h-4 w-4`,!re.error&&`animate-spin`)}),s(`desktopHostSwitcher.ssh.connectingTo`,{host:re.hostLabel||s(`desktopHostSwitcher.ssh.instanceFallback`)})]}),re.error?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ys,{className:`sr-only`,children:s(rc($s(re.errorCode,re.error)))}),(0,$.jsx)(mc,{errorCode:re.errorCode,detail:re.error})]}):(0,$.jsx)(ys,{children:re.detail||s(If(re.phase))})]}),re.error?(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{we(),Pe()},children:s(`desktopHostSwitcher.sshError.openRemoteSettings`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void Ne(),children:s(`desktopHostSwitcher.actions.switchToLocal`)}),(0,$.jsx)(er,{type:`button`,size:`sm`,onClick:Fe,disabled:!re.hostId,children:s(`desktopHostSwitcher.actions.retry`)})]}):null]})});return n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-full max-h-[70vh] flex flex-col overflow-hidden gap-2`,children:Re}),ze]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xs,{open:e,onOpenChange:e=>{!e&&H.current||t(e)},children:(0,$.jsx)(_s,{className:`w-[min(42rem,calc(100vw-2rem))] max-w-none max-h-[70vh] flex flex-col overflow-hidden gap-3`,children:Re})}),ze]})}function Hf(){let e=(0,Q.c)(11),[t,n]=Z.useState(!1),{t:r}=Xn();if(!g())return null;let i,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>n(!0),a=(0,$.jsx)(X,{name:`server`,className:`h-4 w-4`}),e[0]=i,e[1]=a):(i=e[0],a=e[1]);let o;e[2]===r?o=e[3]:(o=r(`desktopHostSwitcher.actions.switchInstance`),e[2]=r,e[3]=o);let s;e[4]===o?s=e[5]:(s=(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,"data-yuri-host-switcher":!0,className:`w-full justify-center`,onClick:i,children:[a,o]}),e[4]=o,e[5]=s);let c;e[6]===t?c=e[7]:(c=(0,$.jsx)(Vf,{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 Uf=e=>e.shouldUseDesktopShellPasswordLogin?`locked`:`error`,Wf=`/auth/session`,Gf=4,Kf=1500,qf=`yuri.uiAuth.trustDevice`,Jf=`desktop-local`,Yf=`desktop-local`,Xf=()=>{if(typeof window>`u`)return``;let e=window.__YURI_LOCAL_ORIGIN__;return typeof e==`string`?e.trim():``},Zf=(e,t)=>{let n=O(e),r=O(t);if(!n||!r)return!1;try{return new URL(n).origin===new URL(r).origin}catch{return!1}},Qf=()=>g(),$f=e=>{let t=e.replace(/^\[|\]$/g,``);return t===`localhost`||t===`127.0.0.1`||t===`::1`},ep=()=>{if(!g())return!1;let e=Xf();if(!e)return!1;let t=d()||(typeof window<`u`?window.location.origin:``);if(Zf(e,t))return!0;try{let e=O(t);return!!(e&&$f(new URL(e).hostname))}catch{return!1}},tp=()=>ep()?{clientKind:Jf,dedupeKey:Yf}:{},np=async()=>await f(Wf,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}}),rp=()=>typeof window>`u`?!1:window.localStorage.getItem(qf)===`true`,ip=async(e,t)=>{let n=Qf();return await f(Wf,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({password:e,trustDevice:t,issueClientToken:n,clientLabel:`Yuri Desktop`,...tp()})})},ap=async()=>{if(!g())return``;let e=await f(`/api/client-auth/clients`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:`Yuri Desktop`,...tp()})}).catch(()=>null);if(!e?.ok)return``;let t=await e.json().catch(()=>null);return typeof t?.token==`string`?t.token.trim():``},op=()=>g()&&!ep(),sp=async(e,t)=>{if(!g()||typeof window>`u`)return null;let r=await h(`desktop_remote_password_login`,{url:d(),password:e,trustDevice:t,requestHeaders:n()}).catch(()=>null);if(!r||typeof r!=`object`)return null;let i=r.token,a=r.status;return{token:typeof i==`string`?i.trim():``,...typeof a==`number`?{status:a}:{}}},cp=async(e,t)=>{if(!g()||!t)return;let n=await M().catch(()=>null);if(!n)return;if(n.localOrigin&&Zf(n.localOrigin,e)){await D({hosts:n.hosts,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted,localClientToken:t}).catch(()=>void 0);return}let r=!1,i=n.hosts.map(n=>!Zf(P(n),e)||n.clientToken===t?n:(r=!0,{...n,clientToken:t}));r&&await D({hosts:i,defaultHostId:n.defaultHostId,initialHostChoiceCompleted:n.initialHostChoiceCompleted}).catch(()=>void 0)},lp=async e=>{if(!e)return;let r=d(),i=n();await cp(r,e),s({apiBaseUrl:r,clientToken:e,requestHeaders:Object.keys(i).length>0?i:null,relay:t()})},up=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},dp=()=>{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)(Gc,{width:120,height:120})}),e[0]=t):t=e[0],t},fp=e=>{let t=(0,Q.c)(23),{onRetry:n,errorType:r,retryAfter:i,children:a}=e,o=r===void 0?`network`:r,{t:s}=Xn(),c=o===`rate-limit`,l=i?Math.ceil(i/60):1,u;t[0]!==c||t[1]!==s?(u=s(c?`sessionAuth.error.rateLimitTitle`:`sessionAuth.error.networkTitle`),t[0]=c,t[1]=s,t[2]=u):u=t[2];let d;t[3]===u?d=t[4]:(d=(0,$.jsx)(`h1`,{className:`typography-ui-header font-semibold text-destructive`,children:u}),t[3]=u,t[4]=d);let f;t[5]!==c||t[6]!==l||t[7]!==s?(f=c?s(l>1?`sessionAuth.error.rateLimitDescriptionPlural`:`sessionAuth.error.rateLimitDescriptionSingle`,{minutes:l}):s(`sessionAuth.error.networkDescription`),t[5]=c,t[6]=l,t[7]=s,t[8]=f):f=t[8];let p;t[9]===f?p=t[10]:(p=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground max-w-xs`,children:f}),t[9]=f,t[10]=p);let m;t[11]!==d||t[12]!==p?(m=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[d,p]}),t[11]=d,t[12]=p,t[13]=m):m=t[13];let h;t[14]===s?h=t[15]:(h=s(`sessionAuth.error.retry`),t[14]=s,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(er,{type:`button`,onClick:n,className:`w-full max-w-xs`,children:h}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;return t[19]!==a||t[20]!==m||t[21]!==g?(_=(0,$.jsx)(up,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[m,g,a]})}),t[19]=a,t[20]=m,t[21]=g,t[22]=_):_=t[22],_},pp=({children:e})=>{let{t}=Xn(),n=Z.useMemo(()=>p(),[]),r=n,a=Z.useMemo(()=>g()&&!n,[n]),[o,s]=Z.useState(()=>r?`authenticated`:`pending`),[c,d]=Z.useState(``),[f,m]=Z.useState(!1),[h,_]=Z.useState(``),[v,y]=Z.useState(void 0),[b,x]=Z.useState(!1),[S,C]=Z.useState(Zs),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(()=>rp()),[A,j]=Z.useState(null),[M,N]=Z.useState(r),P=Z.useRef(null),F=Z.useRef(r);Z.useEffect(()=>{typeof window>`u`||window.localStorage.setItem(qf,O?`true`:`false`)},[O]);let I=Z.useCallback(async()=>{if(r)return Zs;try{let e=await Ac();return C(e),e}catch{return C(Zs),Zs}},[r]);Z.useEffect(()=>{let e=!1;if(!r)return(async()=>{try{if(!window.isSecureContext||!ws()){e||T(!1);return}e||T(!0)}catch{e||T(!1)}})(),()=>{e=!0}},[r]);let L=Z.useRef(0),R=Z.useRef(null),z=Z.useRef(null),B=Z.useCallback(()=>{R.current!==null&&(window.clearTimeout(R.current),R.current=null)},[]),V=Z.useCallback(()=>{L.current=0,B()},[B]),H=Z.useCallback(()=>L.current>=Gf?!1:(L.current+=1,B(),R.current=window.setTimeout(()=>{R.current=null,z.current?.()},Kf*L.current),!0),[B]);Z.useEffect(()=>B,[B]);let U=Z.useCallback(async()=>{if(r){s(`authenticated`);return}s(e=>e===`authenticated`?e:`pending`);try{let[e,t]=await Promise.all([np(),I()]),n=await e.text();if(e.ok){V(),s(`authenticated`),x(!1),_(``),y(void 0);return}if(e.status===401){let e={};try{e=JSON.parse(n)}catch{e={}}V(),x(e.tunnelLocked===!0),C(t),s(`locked`),y(void 0);return}if(e.status===429){let e={};try{e=JSON.parse(n)}catch{e={}}V(),y(e.retryAfter),x(!1),s(`rate-limited`);return}if(H())return;s(`error`),x(!1)}catch(e){if(console.warn(`Failed to check session status:`,e),Uf({shouldUseDesktopShellPasswordLogin:op()})===`locked`){s(`locked`),y(void 0),x(!1);return}if(H())return;s(`error`),x(!1)}},[I,V,H,r]);Z.useEffect(()=>{z.current=U},[U]),Z.useEffect(()=>{r||U()},[U,r]),Z.useEffect(()=>{if(o===`pending`||o===`authenticated`||typeof document>`u`)return;let e=document.getElementById(`initial-loading`);if(!e)return;e.classList.add(`fade-out`);let t=window.setTimeout(()=>{e.remove()},300);return()=>{window.clearTimeout(t)}},[o]),Z.useEffect(()=>{if(r)return;let e=vf(e=>{l(e)&&(d(``),_(``),y(void 0),x(!1),V(),N(!1),F.current=!1,s(`pending`),U())}),t=i(t=>e.schedule(t));return()=>{t(),e.cancel()}},[U,V,r]),Z.useEffect(()=>{!r&&o===`locked`&&(F.current=!1,N(!1))},[r,o]),Z.useEffect(()=>{o===`locked`&&P.current&&(P.current.focus(),P.current.select())},[o]),Z.useEffect(()=>{if(!r&&o===`authenticated`&&!F.current){F.current=!0;let e=!1;return gf({runtimeKey:u(),initializeAppearance:ln,syncSettings:on,applyDirectory:pf,onError:(e,t)=>{console.error(`[SessionAuthGate] ${e} settings hydration failed:`,t)}},{force:!0}).then(()=>{e||N(!0)}),()=>{e=!0}}},[r,o]);let W=async e=>{e.preventDefault(),await ne(!1)},ee=Z.useCallback(async()=>{j(`register`),D(!0);try{await ec()}finally{j(null),D(!1)}await I()},[I]),te=Z.useCallback(()=>{jc(),j(null),D(!1)},[]),ne=Z.useCallback(async e=>{if(!b&&!(!c||f)){E&&te(),m(!0),_(``);try{if(op()){let e=await sp(c,O);if(e?.token){d(``),x(!1),await lp(e.token),s(`authenticated`);return}if(e?.status===401){_(t(`sessionAuth.error.incorrectPassword`)),x(!1),s(`locked`);return}if(e?.status===429){y(void 0),x(!1),s(`rate-limited`);return}}let n=await ip(c,O);if(n.ok){let r=await n.json().catch(()=>null),i=Qf(),a=``;if(i&&(a=typeof r?.clientToken==`string`&&r.clientToken.trim()?r.clientToken.trim():``,a||=(await sp(c,O))?.token||await ap()),d(``),x(!1),a&&await lp(a),e&&w)try{await ee(),ji.success(t(`sessionAuth.toast.passkeyAdded`)),s(`authenticated`);return}catch(e){if(uc(e))ji.message(t(`sessionAuth.toast.passkeySetupCanceled`));else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);ji.error(n)}s(`authenticated`);return}s(`authenticated`);return}if(n.status===401){_(t(`sessionAuth.error.incorrectPassword`)),x(!1),s(`locked`);return}if(n.status===429){let e=await n.json().catch(()=>({}));y(e.retryAfter),x(!1),s(`rate-limited`);return}_(t(`sessionAuth.error.unexpectedResponse`)),x(!1),s(`error`)}catch(e){console.warn(`Failed to submit UI password:`,e);let n=op()?await sp(c,O):null;if(n?.token){d(``),x(!1),await lp(n.token),s(`authenticated`);return}if(n?.status===401){_(t(`sessionAuth.error.incorrectPassword`)),x(!1),s(`locked`);return}if(n?.status===429){y(void 0),x(!1),s(`rate-limited`);return}_(t(`sessionAuth.error.networkRetry`)),x(!1),s(`error`)}finally{m(!1)}}},[te,E,f,b,c,ee,w,t,O]),re=Z.useCallback(async()=>{if(!(f||!w)){if(E){te();return}D(!0),j(`auth`),_(``);try{let e=await lc(O,{issueClientToken:Qf(),clientLabel:`Yuri Desktop`,...tp()}),t=Qf()&&typeof e?.clientToken==`string`&&e.clientToken.trim()?e.clientToken.trim():``;t&&await lp(t),d(``),s(`authenticated`)}catch(e){if(uc(e))_(``);else{let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySignInCanceled`);_(n)}}finally{j(null),D(!1)}}},[te,E,f,w,t,O]),G=Z.useCallback(async()=>{if(!(f||b||!w)){if(E){te();return}if(o!==`authenticated`){if(!c){_(t(`sessionAuth.error.enterPasswordForPasskey`));return}await ne(!0);return}_(``);try{await ee(),ji.success(t(`sessionAuth.toast.passkeyAdded`))}catch(e){if(uc(e)){ji.message(t(`sessionAuth.toast.passkeySetupCanceled`));return}let n=e instanceof Error?e.message:t(`sessionAuth.error.passkeySetupFailed`);ji.error(n)}}},[te,ne,E,f,b,c,ee,o,w,t]),ie=w&&S.enabled,ae=ie&&S.hasPasskeys;return o===`pending`||o===`authenticated`&&!M?(0,$.jsx)(dp,{}):o===`error`?(0,$.jsx)(fp,{onRetry:()=>{V(),U()},errorType:`network`,children:a&&(0,$.jsxs)(`div`,{className:`w-full max-w-xs`,children:[(0,$.jsx)(Hf,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})}):o===`rate-limited`?(0,$.jsx)(fp,{onRetry:()=>void U(),errorType:`rate-limit`,retryAfter:v}):o===`locked`?(0,$.jsx)(up,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 w-full max-w-xs`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-1 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:t(b?`sessionAuth.locked.tunnelTitle`:`sessionAuth.locked.unlockTitle`)}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(b?`sessionAuth.locked.tunnelDescription`:`sessionAuth.locked.passwordDescription`)})]}),!b&&(0,$.jsxs)(`form`,{onSubmit:W,className:`w-full space-y-2`,children:[ae&&(0,$.jsxs)(er,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>void re(),disabled:f||E&&A!==`auth`,children:[E?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:t(E&&A===`auth`?`sessionAuth.actions.cancelPasskey`:`sessionAuth.actions.usePasskey`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(X,{name:`lock`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground/60`}),(0,$.jsx)(Ks,{id:`yuri-ui-password`,ref:P,type:`password`,autoComplete:`current-password`,placeholder:t(`sessionAuth.password.placeholder`),value:c,onChange:e=>{d(e.target.value),h&&_(``)},className:`pl-10`,"aria-invalid":!!h||void 0,"aria-describedby":h?`yuri-ui-auth-error`:void 0,disabled:f})]}),(0,$.jsx)(er,{type:`submit`,size:`icon`,disabled:!c||f,"aria-label":t(f?`sessionAuth.actions.unlockingAria`:`sessionAuth.actions.unlockAria`),children:f?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`lock-unlock`,className:`h-4 w-4`})})]}),ie?(0,$.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(Ts,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void G(),disabled:f,children:t(E&&A===`register`?`sessionAuth.actions.cancelPasskeySetup`:`sessionAuth.actions.addPasskey`)})]}):(0,$.jsxs)(`label`,{className:`flex items-center justify-center gap-2 pt-1 text-center typography-micro text-muted-foreground`,children:[(0,$.jsx)(Ts,{checked:O,onChange:k,disabled:f,ariaLabel:t(`sessionAuth.actions.trustDeviceAria`),className:`size-4`,iconClassName:`size-4`}),(0,$.jsx)(`span`,{children:t(`sessionAuth.actions.trustDevice`)})]}),h&&(0,$.jsx)(`p`,{id:`yuri-ui-auth-error`,className:`typography-meta text-destructive`,children:h})]}),a&&(0,$.jsxs)(`div`,{className:`w-full`,children:[(0,$.jsx)(Hf,{}),(0,$.jsx)(`p`,{className:`mt-1 text-center typography-micro text-muted-foreground`,children:t(`sessionAuth.locked.hostSwitcherHint`)})]})]})}):(0,$.jsx)($.Fragment,{children:e})},mp=e=>!!e&&typeof e==`object`&&!Array.isArray(e),hp=e=>typeof e==`string`&&e.trim()?e.trim():null,gp=e=>{if(!mp(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=hp(e.minimumVersion),i=hp(e.targetVersion);if(!r||!i||typeof e.canInstall!=`boolean`)throw Error(`Could not check OpenCode compatibility`);return{state:t,version:hp(e.version),installation:n,minimumVersion:r,targetVersion:i,canInstall:e.canInstall,guidance:hp(e.guidance)}},_p=async()=>{let e=await f(`/api/opencode/compatibility`,{signal:AbortSignal.timeout(2e4)});if(!e.ok)throw Error(`Could not check OpenCode compatibility`);return gp(await e.json())},vp=async()=>{let e=await f(`/api/opencode/install-required`,{method:`POST`}),t=await e.json().catch(()=>null),n=mp(t)?t:null,r=hp(n?.error);if(!e.ok||n?.success!==!0||n?.upgraded!==!0)throw Error(r||`OpenCode installation failed`);let i=hp(n.version);if(!i)throw Error(r||`OpenCode installation did not report a verified version`);return{version:i}},yp=(e,t)=>e instanceof Error&&e.message.trim()?e.message.trim():t,bp=({children:e})=>{let{t}=Xn(),[n,r]=Z.useState(null),[a,o]=Z.useState(!1),[s,c]=Z.useState(null),[l,u]=Z.useState(null),d=Z.useId(),f=Z.useRef(null),p=Z.useRef(0);Z.useEffect(()=>{let e=!0,t=async()=>{let t=++p.current;try{let n=await _p();if(!e||t!==p.current)return;r(n),n.state!==`incompatible`&&u(null)}catch{}finally{e&&t===p.current&&o(!0)}};t();let n=i(()=>{e&&(r(null),o(!1),c(null),u(null),t())});return()=>{e=!1,p.current+=1,n()}},[]);let m=n?.state===`incompatible`;Z.useEffect(()=>{m&&(document.getElementById(`initial-loading`)?.remove(),f.current?.focus())},[m]);let h=J(async e=>{if(s)return;let n=++p.current;c(e),u(null);try{if(e===`install`){let e=await vp();if(n!==p.current)return;if(!e.version)throw Error(t(`opencodeUpgrade.screen.failedGeneric`));window.location.reload();return}let i=await _p();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(yp(e,t(`opencodeUpgrade.screen.failedGeneric`)))}finally{n===p.current&&c(null)}});if(!a)return null;if(!m||!n)return(0,$.jsx)($.Fragment,{children:e});let g=!!n.version?.startsWith(`2.`),_=n.installation===`bundled`?`opencodeUpgrade.screen.bundled`:n.installation===`external`?g?`opencodeUpgrade.screen.outdatedExternal`:`opencodeUpgrade.screen.external`:g?`opencodeUpgrade.screen.outdatedLocal`:`opencodeUpgrade.screen.local`,v=n.minimumVersion,y=s!==null;return(0,$.jsx)(`section`,{className:`app-region-drag flex h-full min-h-dvh min-h-0 items-center justify-center overflow-y-auto bg-background px-4 py-10 text-foreground select-none sm:px-6`,"aria-labelledby":d,"aria-busy":y,"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)(Gc,{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(g?`opencodeUpgrade.screen.outdatedTitle`:`opencodeUpgrade.screen.title`)}),(0,$.jsxs)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground text-balance`,children:[t(_,{version:n.version??``,minimum:v}),n.canInstall?(0,$.jsxs)($.Fragment,{children:[` `,t(`opencodeUpgrade.screen.installDescription`,{minimum:v})]}):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:[v,`+`]})]}):null,l?(0,$.jsxs)(`p`,{role:`alert`,className:`mt-5 w-full break-words rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] px-3 py-2 text-left text-sm text-[var(--status-error-text)]`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t(`opencodeUpgrade.screen.failedTitle`)}),` `,l]}):null,(0,$.jsxs)(`div`,{className:`app-region-no-drag mt-7 flex w-full flex-wrap items-center justify-center gap-2`,children:[n.canInstall?(0,$.jsxs)(er,{type:`button`,disabled:y,onClick:()=>void h(`install`),children:[(0,$.jsx)(X,{name:s===`install`?`refresh`:`download`,className:s===`install`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`install`?`status`:void 0,children:s===`install`?t(g?`opencodeUpgrade.screen.updating`:`opencodeUpgrade.screen.installing`):t(g?`opencodeUpgrade.screen.update`:`opencodeUpgrade.screen.install`,{minimum:v})})]}):null,(0,$.jsxs)(er,{type:`button`,variant:n.canInstall?`ghost`:`default`,disabled:y,onClick:()=>void h(`reconnect`),children:[(0,$.jsx)(X,{name:`refresh`,className:s===`reconnect`?`size-4 motion-safe:animate-spin`:`size-4`}),(0,$.jsx)(`span`,{role:s===`reconnect`?`status`:void 0,children:t(s===`reconnect`?`opencodeUpgrade.screen.reconnecting`:`opencodeUpgrade.screen.reconnect`)})]})]}),(0,$.jsxs)(`a`,{className:`app-region-no-drag mt-6 inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,href:`https://opencode.ai/download`,target:`_blank`,rel:`noopener noreferrer`,children:[t(`opencodeUpgrade.screen.guide`),(0,$.jsx)(X,{name:`external-link`,className:`size-3`})]}),(0,$.jsx)(`div`,{className:`app-region-no-drag mt-3 w-full`,children:(0,$.jsx)(Hf,{})})]})})},xp=e=>{let t=(0,Q.c)(14),{children:n}=e,r=K(Sp),i=K(Cp),a=K(wp),o=K(Tp),s=K(Ep),{deviceType:c,hasTouchInput:l}=Kc(),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=typeof document<`u`&&St(),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 Sp(e){return e.fontSize}function Cp(e){return e.codeFontSize}function wp(e){return e.applyTypography}function Tp(e){return e.padding}function Ep(e){return e.applyPadding}var Dp=e(ne(),1),Op=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}`},kp=class{inheritanceMap=new Map;constructor(){this.initializeInheritanceMap()}generate(e){let t=[];return t.push(...this.generateTailwindVariables(e)),t.push(...this.generatePrimaryColors(e.colors.primary)),t.push(...this.generateSurfaceColors(e.colors.surface)),t.push(...this.generateInteractiveColors(e.colors.interactive)),t.push(...this.generateStatusColors(e.colors.status)),t.push(...this.generatePullRequestColors(e)),t.push(...this.generateSyntaxColors(e.colors.syntax)),t.push(...this.generateComponentColors(e.colors,e)),t.push(...this.generateTypographyVariables()),e.config&&t.push(...this.generateConfigVariables(e.config)),t.join(`
|
|
3
|
+
`)}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=Op(e.colors.surface.muted),r=Op(e.colors.surface.subtle),i=Op(e.colors.interactive.border);t.push(` --sidebar-base: ${e.colors.surface.muted} !important;`),n&&t.push(` --sidebar-base-rgb: ${n} !important;`),t.push(` --sidebar: var(--sidebar-base) !important;`),t.push(` --sidebar-foreground: ${e.colors.surface.mutedForeground} !important;`),t.push(` --sidebar-primary: ${e.colors.primary.base} !important;`),t.push(` --sidebar-primary-foreground: ${e.colors.primary.foreground} !important;`),t.push(` --sidebar-accent-base: ${e.colors.surface.subtle} !important;`),r&&t.push(` --sidebar-accent-base-rgb: ${r} !important;`),t.push(` --sidebar-accent: var(--sidebar-accent-base) !important;`),t.push(` --sidebar-accent-foreground: ${e.colors.surface.foreground} !important;`),t.push(` --sidebar-border: ${e.colors.interactive.border} !important;`),i&&t.push(` --sidebar-border-rgb: ${i} !important;`),t.push(` --sidebar-ring: ${e.colors.interactive.focusRing} !important;`);let a=e.metadata.variant===`dark`,o=a?.15:.5,s=a?.1:.3,c=a?.42:.52;if(n)t.push(` --sidebar-overlay-strong: rgb(${n} / ${o}) !important;`),t.push(` --sidebar-overlay-soft: rgb(${n} / ${s}) !important;`),t.push(` --sidebar-vibrancy-overlay: rgb(${n} / ${c}) !important;`);else{let n=e.colors.surface.muted;t.push(` --sidebar-overlay-strong: ${this.opacity(n,o)} !important;`),t.push(` --sidebar-overlay-soft: ${this.opacity(n,s)} !important;`),t.push(` --sidebar-vibrancy-overlay: ${this.opacity(n,c)} !important;`)}return e.colors.charts?.series&&Array.isArray(e.colors.charts.series)&&e.colors.charts.series.forEach((e,n)=>{t.push(` --chart-${n+1}: ${e};`)}),e.colors.loading?(t.push(` --loading-spinner: ${e.colors.loading.spinner||e.colors.primary.base};`),t.push(` --loading-spinner-track: ${e.colors.loading.spinnerTrack||e.colors.surface.muted};`)):(t.push(` --loading-spinner: ${e.colors.primary.base};`),t.push(` --loading-spinner-track: ${e.colors.surface.muted};`)),t}apply(e){let t=this.generate(e),n=document.createElement(`style`);n.id=`opencode-theme-variables`;let r=``;e.metadata.variant===`dark`?(r=`:root {\n${t}\n}\n\n.dark {\n${t}\n}`,document.documentElement.classList.add(`dark`),document.documentElement.classList.remove(`light`)):(r=`:root {\n${t}\n}\n\n:root:not(.dark) {\n${t}\n}`,document.documentElement.classList.remove(`dark`),document.documentElement.classList.add(`light`)),n.textContent=r;let i=document.getElementById(`opencode-theme-variables`);i&&i.remove(),document.head.appendChild(n),document.documentElement.setAttribute(`data-theme`,e.metadata.variant);let a=typeof window<`u`&&window.__YURI_ELECTRON__?.runtime===`electron`&&window.__YURI_ELECTRON__?.macVibrancy===!0;document.documentElement.toggleAttribute(`data-yuri-vibrancy`,a),a&&document.documentElement.toggleAttribute(`data-yuri-vibrancy-ready`,!0)}generatePrimaryColors(e){let t=[];return t.push(` --primary-base: ${e.base};`),t.push(` --primary-hover: ${e.hover||this.darken(e.base,10)};`),t.push(` --primary-active: ${e.active||this.darken(e.base,20)};`),t.push(` --primary-foreground: ${e.foreground||`#ffffff`};`),t.push(` --primary-muted: ${e.muted||this.opacity(e.base,.5)};`),t.push(` --primary-emphasis: ${e.emphasis||this.lighten(e.base,10)};`),t}generateSurfaceColors(e){let t=[];return t.push(` --surface-background: ${e.background};`),t.push(` --surface-foreground: ${e.foreground};`),t.push(` --surface-muted: ${e.muted};`),t.push(` --surface-muted-foreground: ${e.mutedForeground};`),t.push(` --surface-elevated: ${e.elevated};`),t.push(` --surface-elevated-foreground: ${e.elevatedForeground};`),t.push(` --surface-overlay: ${e.overlay};`),t.push(` --surface-subtle: ${e.subtle};`),t}generateInteractiveColors(e){let t=[];return t.push(` --interactive-border: ${e.border};`),t.push(` --interactive-border-hover: ${e.borderHover};`),t.push(` --interactive-border-focus: ${e.borderFocus};`),t.push(` --interactive-selection: ${e.selection};`),t.push(` --interactive-selection-foreground: ${e.selectionForeground};`),t.push(` --interactive-focus: ${e.focus};`),t.push(` --interactive-focus-ring: ${e.focusRing};`),t.push(` --interactive-cursor: ${e.cursor};`),t.push(` --interactive-hover: ${e.hover};`),t.push(` --interactive-active: ${e.active};`),t}generateStatusColors(e){let t=[];return t.push(` --status-error: ${e.error};`),t.push(` --status-error-foreground: ${e.errorForeground};`),t.push(` --status-error-background: ${e.errorBackground};`),t.push(` --status-error-border: ${e.errorBorder};`),t.push(` --status-warning: ${e.warning};`),t.push(` --status-warning-foreground: ${e.warningForeground};`),t.push(` --status-warning-background: ${e.warningBackground};`),t.push(` --status-warning-border: ${e.warningBorder};`),t.push(` --status-success: ${e.success};`),t.push(` --status-success-foreground: ${e.successForeground};`),t.push(` --status-success-background: ${e.successBackground};`),t.push(` --status-success-border: ${e.successBorder};`),t.push(` --status-info: ${e.info};`),t.push(` --status-info-foreground: ${e.infoForeground};`),t.push(` --status-info-background: ${e.infoBackground};`),t.push(` --status-info-border: ${e.infoBorder};`),t}generatePullRequestColors(e){let t=[],n=e.colors.pr;return t.push(` --pr-open: ${n?.open||e.colors.status.success};`),t.push(` --pr-draft: ${n?.draft||e.colors.surface.mutedForeground};`),t.push(` --pr-blocked: ${n?.blocked||e.colors.status.warning};`),t.push(` --pr-merged: ${n?.merged||(e.metadata.variant===`dark`?`#8957e5`:`#8250df`)};`),t.push(` --pr-closed: ${n?.closed||e.colors.status.error};`),t}generateSyntaxColors(e){let t=[];t.push(` --syntax-background: ${e.base.background};`),t.push(` --syntax-foreground: ${e.base.foreground};`),t.push(` --syntax-comment: ${e.base.comment};`),t.push(` --syntax-keyword: ${e.base.keyword};`),t.push(` --syntax-string: ${e.base.string};`),t.push(` --syntax-number: ${e.base.number};`),t.push(` --syntax-function: ${e.base.function};`),t.push(` --syntax-variable: ${e.base.variable};`),t.push(` --syntax-type: ${e.base.type};`),t.push(` --syntax-operator: ${e.base.operator};`);let n=this.generateSyntaxTokens(e);for(let[e,r]of Object.entries(n))t.push(` --syntax-${this.kebabCase(e)}: ${r};`);return t}generateSyntaxTokens(e){let t=e.base,n=e.tokens||{};return{commentDoc:n.commentDoc||this.lighten(t.comment,10),stringEscape:n.stringEscape||this.darken(t.string,20),stringInterpolation:n.stringInterpolation||t.variable,stringRegex:n.stringRegex||this.adjustHue(t.string,15),keywordControl:n.keywordControl||t.keyword,keywordOperator:n.keywordOperator||t.operator,keywordImport:n.keywordImport||this.lighten(t.keyword,10),keywordReturn:n.keywordReturn||this.emphasize(t.keyword),functionCall:n.functionCall||this.lighten(t.function,5),functionBuiltin:n.functionBuiltin||this.darken(t.function,10),method:n.method||t.function,methodCall:n.methodCall||this.lighten(t.function,5),variableBuiltin:n.variableBuiltin||this.emphasize(t.variable),variableProperty:n.variableProperty||this.lighten(t.variable,10),variableReadonly:n.variableReadonly||t.number,parameter:n.parameter||t.variable,typePrimitive:n.typePrimitive||this.darken(t.type,10),typeInterface:n.typeInterface||t.type,className:n.className||this.emphasize(t.type),enum:n.enum||t.type,boolean:n.boolean||t.number,null:n.null||this.opacity(t.number,.7),constant:n.constant||t.number,punctuation:n.punctuation||this.opacity(t.foreground,.7),delimiter:n.delimiter||this.opacity(t.foreground,.8),bracket:n.bracket||t.foreground,tag:n.tag||t.keyword,tagAttribute:n.tagAttribute||t.variable,tagAttributeValue:n.tagAttributeValue||t.string,tagBracket:n.tagBracket||this.opacity(t.foreground,.8),decorator:n.decorator||t.function,annotation:n.annotation||t.function,namespace:n.namespace||this.opacity(t.type,.8),module:n.module||this.opacity(t.type,.8),...n}}generateComponentColors(e,t){let n=[];return e.markdown?n.push(...this.generateMarkdownColors(e.markdown,t)):n.push(...this.generateDefaultMarkdownColors(t)),e.chat?n.push(...this.generateChatColors(e.chat,t)):n.push(...this.generateDefaultChatColors(t)),e.tools?n.push(...this.generateToolColors(e.tools,t)):n.push(...this.generateDefaultToolColors(t)),n}generateMarkdownColors(e,t){let n=[],r=t.colors.primary.base,i=t.colors.chat?.background||t.colors.surface.background;return n.push(` --markdown-heading1: ${e.heading1||r};`),n.push(` --markdown-heading2: ${e.heading2||this.opacity(r,.9)};`),n.push(` --markdown-heading3: ${e.heading3||this.opacity(r,.8)};`),n.push(` --markdown-heading4: ${e.heading4||t.colors.surface.foreground};`),n.push(` --markdown-link: ${e.link||r};`),n.push(` --markdown-link-hover: ${e.linkHover||t.colors.primary.hover||this.darken(r,10)};`),n.push(` --markdown-inline-code: ${e.inlineCode||t.colors.syntax.base.string};`),n.push(` --markdown-inline-code-bg: ${e.inlineCodeBackground||i};`),n.push(` --markdown-blockquote: ${e.blockquote||t.colors.surface.mutedForeground};`),n.push(` --markdown-blockquote-border: ${e.blockquoteBorder||t.colors.interactive.border};`),n.push(` --markdown-list-marker: ${r};`),n.push(` --markdown-bold: ${e.bold||t.colors.surface.foreground};`),n.push(` --markdown-italic: ${e.italic||this.opacity(t.colors.surface.foreground,.9)};`),n.push(` --markdown-strikethrough: ${e.strikethrough||t.colors.surface.mutedForeground};`),n.push(` --markdown-hr: ${e.hr||t.colors.interactive.border};`),n}generateDefaultMarkdownColors(e){let t=[],n=e.colors.primary.base,r=e.colors.chat?.background||e.colors.surface.background;return t.push(` --markdown-heading1: ${n};`),t.push(` --markdown-heading2: ${this.opacity(n,.9)};`),t.push(` --markdown-heading3: ${this.opacity(n,.8)};`),t.push(` --markdown-heading4: ${e.colors.surface.foreground};`),t.push(` --markdown-link: ${n};`),t.push(` --markdown-link-hover: ${e.colors.primary.hover||this.darken(n,10)};`),t.push(` --markdown-inline-code: ${e.colors.syntax.base.string};`),t.push(` --markdown-inline-code-bg: ${r};`),t.push(` --markdown-blockquote: ${e.colors.surface.mutedForeground};`),t.push(` --markdown-blockquote-border: ${e.colors.interactive.border};`),t.push(` --markdown-list-marker: ${n};`),t.push(` --markdown-bold: ${e.colors.surface.foreground};`),t.push(` --markdown-italic: ${this.opacity(e.colors.surface.foreground,.9)};`),t.push(` --markdown-strikethrough: ${e.colors.surface.mutedForeground};`),t.push(` --markdown-hr: ${e.colors.interactive.border};`),t}generateChatColors(e,t){let n=[],r=e.background||t.colors.surface.background,i=e.composerSkill||this.getDefaultComposerSkillColor(t);return n.push(` --chat-background: ${r};`),n.push(` --chat-user-message: ${e.userMessage||t.colors.surface.foreground};`),n.push(` --chat-user-message-bg: ${e.userMessageBackground||t.colors.surface.elevated};`),n.push(` --chat-assistant-message: ${e.assistantMessage||t.colors.surface.foreground};`),n.push(` --chat-assistant-message-bg: ${e.assistantMessageBackground||t.colors.surface.muted};`),n.push(` --chat-timestamp: ${e.timestamp||t.colors.surface.mutedForeground};`),n.push(` --chat-divider: ${e.divider||t.colors.interactive.border};`),n.push(` --chat-typing: ${e.typing||t.colors.surface.mutedForeground};`),n.push(` --chat-composer-skill: ${i};`),n}generateDefaultChatColors(e){let t=[];return t.push(` --chat-background: ${e.colors.surface.background};`),t.push(` --chat-user-message: ${e.colors.surface.foreground};`),t.push(` --chat-user-message-bg: ${e.colors.surface.elevated};`),t.push(` --chat-assistant-message: ${e.colors.surface.foreground};`),t.push(` --chat-assistant-message-bg: ${e.colors.surface.muted};`),t.push(` --chat-timestamp: ${e.colors.surface.mutedForeground};`),t.push(` --chat-divider: ${e.colors.interactive.border};`),t.push(` --chat-typing: ${e.colors.surface.mutedForeground};`),t.push(` --chat-composer-skill: ${this.getDefaultComposerSkillColor(e)};`),t}getDefaultComposerSkillColor(e){return e.metadata.variant===`dark`?this.lighten(e.colors.status.warning,25):e.colors.status.warning}generateToolColors(e,t){let n=[];return n.push(` --tools-background: ${e?.background||this.opacity(t.colors.surface.muted,.2)};`),n.push(` --tools-border: ${e?.border||this.opacity(t.colors.interactive.border,.3)};`),n.push(` --tools-header-hover: ${e?.headerHover||this.opacity(t.colors.surface.muted,.3)};`),n.push(` --tools-icon: ${e?.icon||t.colors.surface.mutedForeground};`),n.push(` --tools-title: color-mix(in srgb, ${e?.title||t.colors.surface.foreground} 50%, ${t.colors.surface.mutedForeground});`),n.push(` --tools-description: ${e?.description||this.opacity(t.colors.surface.mutedForeground,.6)};`),e?.edit?(n.push(` --tools-edit-added: ${e.edit.added||t.colors.status.success};`),n.push(` --tools-edit-added-bg: ${e.edit.addedBackground||t.colors.status.successBackground};`),n.push(` --tools-edit-removed: ${e.edit.removed||t.colors.status.error};`),n.push(` --tools-edit-removed-bg: ${e.edit.removedBackground||t.colors.status.errorBackground};`),n.push(` --tools-edit-modified: ${e.edit.modified||t.colors.status.info};`),n.push(` --tools-edit-modified-bg: ${e.edit.modifiedBackground||t.colors.status.infoBackground};`),n.push(` --tools-edit-line-number: ${e.edit.lineNumber||this.opacity(t.colors.surface.mutedForeground,.6)};`)):(n.push(` --tools-edit-added: ${t.colors.status.success};`),n.push(` --tools-edit-added-bg: ${t.colors.status.successBackground};`),n.push(` --tools-edit-removed: ${t.colors.status.error};`),n.push(` --tools-edit-removed-bg: ${t.colors.status.errorBackground};`),n.push(` --tools-edit-modified: ${t.colors.status.info};`),n.push(` --tools-edit-modified-bg: ${t.colors.status.infoBackground};`),n.push(` --tools-edit-line-number: ${this.opacity(t.colors.surface.mutedForeground,.6)};`)),n}generateDefaultToolColors(e){let t=[];return t.push(` --tools-background: ${this.opacity(e.colors.surface.muted,.2)};`),t.push(` --tools-border: ${this.opacity(e.colors.interactive.border,.3)};`),t.push(` --tools-header-hover: ${this.opacity(e.colors.surface.muted,.3)};`),t.push(` --tools-icon: ${e.colors.surface.mutedForeground};`),t.push(` --tools-title: color-mix(in srgb, ${e.colors.surface.foreground} 50%, ${e.colors.surface.mutedForeground});`),t.push(` --tools-description: ${this.opacity(e.colors.surface.mutedForeground,.6)};`),t.push(` --tools-edit-added: ${e.colors.status.success};`),t.push(` --tools-edit-added-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.successBackground),.15)};`),t.push(` --tools-edit-removed: ${e.colors.status.error};`),t.push(` --tools-edit-removed-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.errorBackground),.15)};`),t.push(` --tools-edit-modified: ${e.colors.status.info};`),t.push(` --tools-edit-modified-bg: ${this.addTransparency(this.removeTransparency(e.colors.status.infoBackground),.15)};`),t.push(` --tools-edit-line-number: ${this.opacity(e.colors.surface.mutedForeground,.6)};`),t}generateConfigVariables(e){let t=[];return e?(e.fonts&&(e.fonts.sans&&(t.push(` --font-sans: ${e.fonts.sans};`),t.push(` --font-family-sans: ${e.fonts.sans};`)),e.fonts.mono&&(t.push(` --font-mono: ${e.fonts.mono};`),t.push(` --font-family-mono: ${e.fonts.mono};`)),e.fonts.heading&&t.push(` --font-heading: ${e.fonts.heading};`)),e.transitions&&(e.transitions.fast&&t.push(` --transition-fast: ${e.transitions.fast};`),e.transitions.normal&&t.push(` --transition-normal: ${e.transitions.normal};`),e.transitions.slow&&t.push(` --transition-slow: ${e.transitions.slow};`)),t):t}generateTypographyVariables(){let e=[],t=p()?bt:xt;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()}},Ap=()=>cl()?new URLSearchParams(window.location.search):null,jp=()=>typeof window>`u`||window.matchMedia(`(prefers-color-scheme: dark)`).matches,Mp=()=>{let e=Ap()?.get(`themeVariant`);return e===`dark`||e===`light`?e===`dark`:jp()},Np=(e,t)=>t.reduce((e,t)=>e&&typeof e==`object`?e[t]:void 0,e),Pp=e=>typeof e==`string`&&e.trim().length>0,Fp=e=>{if(!e||typeof e!=`object`)return!1;for(let t of[[`metadata`,`id`],[`metadata`,`name`],[`metadata`,`variant`],[`colors`,`primary`,`base`],[`colors`,`primary`,`foreground`],[`colors`,`surface`,`background`],[`colors`,`surface`,`foreground`],[`colors`,`surface`,`muted`],[`colors`,`surface`,`mutedForeground`],[`colors`,`surface`,`elevated`],[`colors`,`surface`,`elevatedForeground`],[`colors`,`surface`,`subtle`],[`colors`,`interactive`,`border`],[`colors`,`interactive`,`selection`],[`colors`,`interactive`,`selectionForeground`],[`colors`,`interactive`,`focusRing`],[`colors`,`interactive`,`hover`],[`colors`,`status`,`error`],[`colors`,`status`,`errorForeground`],[`colors`,`status`,`errorBackground`],[`colors`,`status`,`errorBorder`],[`colors`,`status`,`warning`],[`colors`,`status`,`warningForeground`],[`colors`,`status`,`warningBackground`],[`colors`,`status`,`warningBorder`],[`colors`,`status`,`success`],[`colors`,`status`,`successForeground`],[`colors`,`status`,`successBackground`],[`colors`,`status`,`successBorder`],[`colors`,`status`,`info`],[`colors`,`status`,`infoForeground`],[`colors`,`status`,`infoBackground`],[`colors`,`status`,`infoBorder`],[`colors`,`syntax`,`base`,`background`],[`colors`,`syntax`,`base`,`foreground`],[`colors`,`syntax`,`base`,`keyword`],[`colors`,`syntax`,`base`,`string`],[`colors`,`syntax`,`base`,`number`],[`colors`,`syntax`,`base`,`function`],[`colors`,`syntax`,`base`,`variable`],[`colors`,`syntax`,`base`,`type`],[`colors`,`syntax`,`base`,`comment`],[`colors`,`syntax`,`base`,`operator`],[`colors`,`syntax`,`highlights`,`diffAdded`],[`colors`,`syntax`,`highlights`,`diffRemoved`],[`colors`,`syntax`,`highlights`,`lineNumber`]])if(!Pp(Np(e,t)))return!1;let t=Np(e,[`metadata`,`variant`]);return t===`light`||t===`dark`},Ip=e=>Fp(e.currentTheme)?e.currentTheme:null,Lp=e=>Ip(e)?.metadata.variant??null,Rp=tl,zp=Xc,Bp=()=>{let e=Ap()?.get(`currentTheme`);if(!e)return null;try{let t=JSON.parse(e);return Fp(t)?t:null}catch{return null}},Vp=e=>Jc(e===`dark`),Hp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,Up=()=>{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`)}},Wp=e=>{let t=Rp,n=zp,r=`system`;if(typeof window<`u`){let e=Ap(),i=e?.get(`themeMode`),a=e?.get(`lightThemeId`),o=e?.get(`darkThemeId`),s=tn(`themeMode`),c=tn(`lightThemeId`),l=tn(`darkThemeId`),u=tn(`useSystemTheme`),d=tn(`selectedThemeId`),f=tn(`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=Yc(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=Yc(e);r&&(r.metadata.variant===`light`?t=r.metadata.id:n=r.metadata.id)}return{themeMode:r,lightThemeId:t,darkThemeId:n}};function Gp({children:e,defaultThemeId:t}){let n=(0,Z.useMemo)(()=>new kp,[]),[r,a]=(0,Z.useState)(()=>Wp(t)),[o,s]=(0,Z.useState)(!1),[c,u]=(0,Z.useState)(()=>Mp()),[d,m]=(0,Z.useState)([]),[h]=(0,Z.useState)(()=>Bp()),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(()=>typeof window>`u`||!p()?null:window.__YURI_VSCODE_THEME__||null),w=(0,Z.useMemo)(()=>p(),[]),T=(0,Z.useMemo)(()=>x(),[]),E=(0,Z.useMemo)(()=>g(),[]),D=(0,Z.useMemo)(()=>typeof window>`u`?!1:Ap()!==null,[]),O=(0,Z.useMemo)(()=>{let e=[],t=new Set,n=n=>{let r=n.metadata.id;t.has(r)||(t.add(r),e.push(n))};return w&&S&&n(S),_&&n(_),h&&n(h),d.forEach(n),$c.forEach(n),e},[d,h,_,w,S]),k=(0,Z.useMemo)(()=>e=>O.find(t=>t.metadata.id===e),[O]),A=(0,Z.useMemo)(()=>(e,t)=>{let n=k(e);return n&&n.metadata.variant===t?n:O.find(e=>e.metadata.variant===t)??Vp(t)},[O,k]),j=(0,Z.useMemo)(()=>w&&S?S:r.themeMode===`light`?A(r.lightThemeId,`light`):r.themeMode===`dark`||c?A(r.darkThemeId,`dark`):A(r.lightThemeId,`light`),[A,w,r,c,S]),M=J(async()=>{if(!(typeof window>`u`||w)){b(!0);try{let e=await f(`/api/config/themes`,{method:`GET`,credentials:T?`omit`:`include`,headers:{Accept:`application/json`}});if(e.status===401||!e.ok)return;let t=await e.json(),n=(Array.isArray(t?.themes)?t.themes:[]).filter(Fp);m(n)}catch{}finally{b(!1)}}});(0,Z.useEffect)(()=>{M()},[M]),(0,Z.useEffect)(()=>{if(!w)return;let e=e=>{C(e)},t=t=>{let n=t.detail;n?.theme&&e(n.theme)},n=window.__YURI_VSCODE_THEME__;return n&&e(n),window.addEventListener(`yuri:vscode-theme`,t),()=>window.removeEventListener(`yuri:vscode-theme`,t)},[w]);let N=J(e=>{if(typeof document>`u`)return;let t=document.documentElement.hasAttribute(`data-yuri-vibrancy`)||window.__YURI_ELECTRON__?.macVibrancy===!0?`transparent`:e.colors.surface.background;document.body.style.backgroundColor=t;let n=document.querySelector(`meta[name="theme-color"]`);n||(n=document.createElement(`meta`),n.setAttribute(`name`,`theme-color`),document.head.appendChild(n)),n.setAttribute(`content`,t);let r=e.metadata.variant===`dark`?`(prefers-color-scheme: dark)`:`(prefers-color-scheme: light)`,i=document.querySelector(`meta[name="theme-color"][media="${r}"]`);i||(i=document.createElement(`meta`),i.setAttribute(`name`,`theme-color`),i.setAttribute(`media`,r),document.head.appendChild(i)),i.setAttribute(`content`,t)}),P=J(e=>{typeof document>`u`||document.documentElement.classList.toggle(`vscode-runtime`,e)});Hp(()=>{if(typeof window>`u`)return;let e=Up();n.apply(j),P(w),N(j);let t=document.documentElement;return t.classList.remove(`light`,`dark`),t.classList.add(j.metadata.variant),e},[P,n,j,w,N]),(0,Z.useEffect)(()=>{if(r.themeMode!==`system`||typeof window>`u`||D)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>{u(e.matches)};return u(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[r.themeMode,D]),(0,Z.useEffect)(()=>{if(D||typeof window>`u`)return;Xt(`themeMode`,r.themeMode),Xt(`lightThemeId`,r.lightThemeId),Xt(`darkThemeId`,r.darkThemeId),Xt(`useSystemTheme`,String(r.themeMode===`system`)),Xt(`selectedThemeId`,j.metadata.id),Xt(`selectedThemeVariant`,j.metadata.variant===`light`?`light`:`dark`);let e=A(r.lightThemeId,`light`),t=A(r.darkThemeId,`dark`);Xt(`splashBgLight`,e.colors.surface.background),Xt(`splashFgLight`,e.colors.surface.foreground),Xt(`splashBgDark`,t.colors.surface.background),Xt(`splashFgDark`,t.colors.surface.foreground),T&&(localStorage.setItem(`themeMode`,r.themeMode),localStorage.setItem(`useSystemTheme`,String(r.themeMode===`system`)),localStorage.setItem(`splashBgLight`,e.colors.surface.background),localStorage.setItem(`splashFgLight`,e.colors.surface.foreground),localStorage.setItem(`splashBgDark`,t.colors.surface.background),localStorage.setItem(`splashFgDark`,t.colors.surface.foreground))},[r,j,A,T,D]),(0,Z.useEffect)(()=>{if(typeof window>`u`||D)return;let e=e=>{e.storageArea===window.localStorage&&(Jt(e.key,`themeMode`)||Jt(e.key,`lightThemeId`)||Jt(e.key,`darkThemeId`))&&a(e=>{let t=tn(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=tn(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=tn(`darkThemeId`),o=typeof a==`string`&&a.trim().length>0?a.trim():e.darkThemeId;return n===e.themeMode&&i===e.lightThemeId&&o===e.darkThemeId?e:{themeMode:n,lightThemeId:i,darkThemeId:o}})};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[D]);let F=J(e=>{let t=e.themeMode,n=e.lightThemeId,r=e.darkThemeId,i=Lp(e),o=Ip(e);if(t!==`light`&&t!==`dark`&&t!==`system`||typeof n!=`string`||typeof r!=`string`)return;let s=n.trim(),c=r.trim();!s||!c||(Up(),(0,Dp.flushSync)(()=>{D&&o&&v(o),t===`system`&&i&&u(i===`dark`),a(e=>e.themeMode===t&&e.lightThemeId===s&&e.darkThemeId===c?e:{themeMode:t,lightThemeId:s,darkThemeId:c})}))});(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=window;return e.__yuriApplyThemeSync=F,()=>{e.__yuriApplyThemeSync===F&&delete e.__yuriApplyThemeSync}},[F]),(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin)return;let t=e.data;t?.type!==`yuri:theme-sync`||!t.payload||F(t.payload)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[F]),(0,Z.useEffect)(()=>{if(D||!o)return;let e=A(r.lightThemeId,`light`),t=A(r.darkThemeId,`dark`);Zt({themeId:j.metadata.id,themeVariant:j.metadata.variant===`light`?`light`:`dark`,useSystemTheme:r.themeMode===`system`,lightThemeId:r.lightThemeId,darkThemeId:r.darkThemeId,splashBgLight:e.colors.surface.background,splashFgLight:e.colors.surface.foreground,splashBgDark:t.colors.surface.background,splashFgDark:t.colors.surface.foreground})},[j.metadata.id,j.metadata.variant,A,r.themeMode,r.lightThemeId,r.darkThemeId,D,o]),(0,Z.useEffect)(()=>{D||!E||(async()=>{await tr(r.themeMode,j.metadata.variant)})()},[j.metadata.variant,E,r.themeMode,D]),(0,Z.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t&&(a(e=>{let n=e.themeMode;t.useSystemTheme===!0?n=`system`:t.useSystemTheme===!1&&(t.themeVariant===`dark`||t.themeVariant===`light`)&&(n=t.themeVariant);let r=e.lightThemeId;typeof t.lightThemeId==`string`&&t.lightThemeId.length>0&&(r=t.lightThemeId.trim());let i=e.darkThemeId;return typeof t.darkThemeId==`string`&&t.darkThemeId.length>0&&(i=t.darkThemeId.trim()),n===e.themeMode&&r===e.lightThemeId&&i===e.darkThemeId?e:{themeMode:n,lightThemeId:r,darkThemeId:i}}),s(!0))};return window.addEventListener(`yuri:settings-synced`,e),()=>window.removeEventListener(`yuri:settings-synced`,e)},[]),(0,Z.useEffect)(()=>{if(!(D||typeof window>`u`))return i(e=>{l(e)&&(a(e=>{let t=tn(`themeMode`),n=t===`light`||t===`dark`||t===`system`?t:e.themeMode,r=tn(`lightThemeId`),i=typeof r==`string`&&r.trim().length>0?r.trim():e.lightThemeId,a=tn(`darkThemeId`),o=typeof a==`string`&&a.trim().length>0?a.trim():e.darkThemeId;return n===e.themeMode&&i===e.lightThemeId&&o===e.darkThemeId?e:{themeMode:n,lightThemeId:i,darkThemeId:o}}),s(!1))})},[D]);let I=J(e=>{let t=O.find(t=>t.metadata.id===e);t&&a(e=>t.metadata.variant===`dark`?e.darkThemeId===t.metadata.id&&e.themeMode===`dark`?e:{...e,darkThemeId:t.metadata.id,themeMode:`dark`}:e.lightThemeId===t.metadata.id&&e.themeMode===`light`?e:{...e,lightThemeId:t.metadata.id,themeMode:`light`})}),L=J(e=>{a(t=>t.themeMode===e?t:{...t,themeMode:e})}),R=J(e=>{if(e){a(e=>e.themeMode===`system`?e:{...e,themeMode:`system`});return}let t=j.metadata.variant===`dark`?`dark`:`light`;a(e=>e.themeMode===t?e:{...e,themeMode:t})}),z=J(e=>{let t=O.find(t=>t.metadata.id===e&&t.metadata.variant===`light`);t&&a(e=>e.lightThemeId===t.metadata.id?e:{...e,lightThemeId:t.metadata.id})}),B=J(e=>{let t=O.find(t=>t.metadata.id===e&&t.metadata.variant===`dark`);t&&a(e=>e.darkThemeId===t.metadata.id?e:{...e,darkThemeId:t.metadata.id})}),V=(0,Z.useMemo)(()=>({currentTheme:j,availableThemes:O,setTheme:I,customThemesLoading:y,reloadCustomThemes:M,isSystemPreference:r.themeMode===`system`,setSystemPreference:R,themeMode:r.themeMode,setThemeMode:L,lightThemeId:r.lightThemeId,darkThemeId:r.darkThemeId,setLightThemePreference:z,setDarkThemePreference:B}),[O,j,y,r.darkThemeId,r.lightThemeId,r.themeMode,M,B,z,R,I,L]);return(0,$.jsx)(ps.Provider,{value:V,children:e})}var Kp=!1,qp=()=>{if(Kp||typeof window>`u`)return;Kp=!0;let e={showReasoningTraces:K.getState().showReasoningTraces,sessionTitleRefreshEnabled:K.getState().sessionTitleRefreshEnabled,sessionGoalEnabled:K.getState().sessionGoalEnabled,sessionGoalDefaultBudgetEnabled:K.getState().sessionGoalDefaultBudgetEnabled,sessionGoalDefaultBudget:K.getState().sessionGoalDefaultBudget,collapsibleThinkingBlocks:K.getState().collapsibleThinkingBlocks,showDeletionDialog:K.getState().showDeletionDialog,nativeNotificationsEnabled:K.getState().nativeNotificationsEnabled,notificationMode:K.getState().notificationMode,notifyOnSubtasks:K.getState().notifyOnSubtasks,notifyOnCompletion:K.getState().notifyOnCompletion,notifyOnError:K.getState().notifyOnError,notifyOnQuestion:K.getState().notifyOnQuestion,notificationTemplates:K.getState().notificationTemplates,summarizeLastMessage:K.getState().summarizeLastMessage,summaryThreshold:K.getState().summaryThreshold,summaryLength:K.getState().summaryLength,maxLastMessageLength:K.getState().maxLastMessageLength,autoDeleteEnabled:K.getState().autoDeleteEnabled,autoDeleteAfterDays:K.getState().autoDeleteAfterDays,sessionRetentionAction:K.getState().sessionRetentionAction,fontSize:K.getState().fontSize,terminalFontSize:K.getState().terminalFontSize,editorFontSize:K.getState().editorFontSize,uiFont:K.getState().uiFont,monoFont:K.getState().monoFont,padding:K.getState().padding,cornerRadius:K.getState().cornerRadius,inputBarOffset:K.getState().inputBarOffset,mobileKeyboardMode:K.getState().mobileKeyboardMode,diffLayoutPreference:K.getState().diffLayoutPreference,gitChangesViewMode:K.getState().gitChangesViewMode},t=null,n=null,r=()=>{let e=t;t=null,n=null,e&&Object.keys(e).length>0&&Zt(e)},i=e=>{t={...t??{},...e},!n&&(n=setTimeout(r,150))};K.subscribe(t=>{let n={showReasoningTraces:t.showReasoningTraces,sessionTitleRefreshEnabled:t.sessionTitleRefreshEnabled,sessionGoalEnabled:t.sessionGoalEnabled,sessionGoalDefaultBudgetEnabled:t.sessionGoalDefaultBudgetEnabled,sessionGoalDefaultBudget:t.sessionGoalDefaultBudget,collapsibleThinkingBlocks:t.collapsibleThinkingBlocks,showDeletionDialog:t.showDeletionDialog,nativeNotificationsEnabled:t.nativeNotificationsEnabled,notificationMode:t.notificationMode,notifyOnSubtasks:t.notifyOnSubtasks,notifyOnCompletion:t.notifyOnCompletion,notifyOnError:t.notifyOnError,notifyOnQuestion:t.notifyOnQuestion,notificationTemplates:t.notificationTemplates,summarizeLastMessage:t.summarizeLastMessage,summaryThreshold:t.summaryThreshold,summaryLength:t.summaryLength,maxLastMessageLength:t.maxLastMessageLength,autoDeleteEnabled:t.autoDeleteEnabled,autoDeleteAfterDays:t.autoDeleteAfterDays,sessionRetentionAction:t.sessionRetentionAction,fontSize:t.fontSize,terminalFontSize:t.terminalFontSize,editorFontSize:t.editorFontSize,uiFont:t.uiFont,monoFont:t.monoFont,padding:t.padding,cornerRadius:t.cornerRadius,inputBarOffset:t.inputBarOffset,mobileKeyboardMode:t.mobileKeyboardMode,diffLayoutPreference:t.diffLayoutPreference,gitChangesViewMode:t.gitChangesViewMode},r={};n.showReasoningTraces!==e.showReasoningTraces&&(r.showReasoningTraces=n.showReasoningTraces),n.sessionTitleRefreshEnabled!==e.sessionTitleRefreshEnabled&&(r.sessionTitleRefreshEnabled=n.sessionTitleRefreshEnabled),n.sessionGoalEnabled!==e.sessionGoalEnabled&&(r.sessionGoalEnabled=n.sessionGoalEnabled),n.sessionGoalDefaultBudgetEnabled!==e.sessionGoalDefaultBudgetEnabled&&(r.sessionGoalDefaultBudgetEnabled=n.sessionGoalDefaultBudgetEnabled),n.sessionGoalDefaultBudget!==e.sessionGoalDefaultBudget&&(r.sessionGoalDefaultBudget=n.sessionGoalDefaultBudget),n.collapsibleThinkingBlocks!==e.collapsibleThinkingBlocks&&(r.collapsibleThinkingBlocks=n.collapsibleThinkingBlocks),n.showDeletionDialog!==e.showDeletionDialog&&(r.showDeletionDialog=n.showDeletionDialog),n.nativeNotificationsEnabled!==e.nativeNotificationsEnabled&&(r.nativeNotificationsEnabled=n.nativeNotificationsEnabled),n.notificationMode!==e.notificationMode&&(r.notificationMode=n.notificationMode),n.notifyOnSubtasks!==e.notifyOnSubtasks&&(r.notifyOnSubtasks=n.notifyOnSubtasks),n.notifyOnCompletion!==e.notifyOnCompletion&&(r.notifyOnCompletion=n.notifyOnCompletion),n.notifyOnError!==e.notifyOnError&&(r.notifyOnError=n.notifyOnError),n.notifyOnQuestion!==e.notifyOnQuestion&&(r.notifyOnQuestion=n.notifyOnQuestion),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)})},Jp=(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},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(e[n]?.providerID!==t[n]?.providerID||e[n]?.modelID!==t[n]?.modelID)return!1;return!0},Xp=(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},Zp=(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])&&Xp(e[n],t[n]))},Qp=()=>{let e=K.getState();return{favoriteModels:e.favoriteModels,hiddenModels:e.hiddenModels,collapsedModelProviders:e.collapsedModelProviders,recentModels:e.recentModels,recentAgents:e.recentAgents,recentEfforts:e.recentEfforts}},$p=(e,t)=>Jp(e.favoriteModels,t.favoriteModels)&&Yp(e.hiddenModels,t.hiddenModels)&&Xp(e.collapsedModelProviders,t.collapsedModelProviders)&&Jp(e.recentModels,t.recentModels)&&Xp(e.recentAgents,t.recentAgents)&&Zp(e.recentEfforts,t.recentEfforts),em=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()]))}),tm=()=>{if(typeof window>`u`)return()=>{};let e=null,t=null,n=!1,r=()=>{e=null;let n=Qp();t&&$p(t,n)||(t=em(n),Zt(n).catch(()=>{}))},i=()=>{if(!n){n=!0;return}e!==null&&window.clearTimeout(e),e=window.setTimeout(r,1200)},a=K.subscribe((e,t)=>{$p({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)}},nm=!1,rm=`yuri-typography-base`,im=()=>{if(typeof document>`u`)return;let e=`:root {\n${Object.entries(xt).map(([e,t])=>` --text-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}: ${t};`).join(`
|
|
4
|
+
`)}\n}\n`,t=document.getElementById(rm);if(t){t.textContent=e;return}let n=document.createElement(`style`);n.id=rm,n.textContent=e,document.head.appendChild(n)},am=()=>{nm||typeof window>`u`||(nm=!0,im())};function om(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)(sm,r);let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(yn,{client:Cn,children:n}),t[1]=n,t[2]=i),i}function sm(){return wn(Cn)}var cm=15,lm=2e3,um=40,dm=2e4,fm=e=>{let t=Ko(e=>e.isConnected),n=Ko(e=>e.providers.length),r=Ko(e=>e.agents.length),i=Ko(e=>e.activeDirectoryKey),a=Ko(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`?cm:um;if(s.current>=e){if(l===`fast`){s.current=0,u(`slow`);return}u(`done`);return}let t=Ko.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]),Vn(f,!o||l===`done`?null:l===`slow`?dm:lm)},pm=40,mm=20971520,hm=new Map,gm=0;function _m(e){return e.length*2}function vm(e,t){let n=hm.get(e);n!==void 0&&(gm-=n),hm.delete(e),hm.set(e,t),gm+=t}function ym(e,t){let n=hm.get(e);(n!==void 0||t!==void 0)&&vm(e,t??n??0)}function bm(e){let t=hm.get(e);t!==void 0&&(hm.delete(e),gm-=t)}function xm(e,t){let n=e??new Set;for(;hm.size>pm||gm>mm;){let e=hm.keys().next().value;if(!e)return;if(n.has(e)){if(ym(e),hm.size<=n.size)return;continue}bm(e),t(e)}}function Sm(e,t){vm(e,t)}function Cm(e){bm(e)}function wm(e,t){ym(e,t)}function Tm(e){let t=new Map,n=e=>{t.delete(e),Cm(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=_m(r.content);return t.set(e,{...r,size:i?.isFile?i.size:void 0,mtimeMs:i?.isFile?i.mtimeMs:void 0}),Sm(e,a),xm(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 wm(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 Em(e){let t=(0,Q.c)(8),{apis:n,children:r}=e,i;t[0]===n.files?i=t[1]:(i=Tm(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)(En.Provider,{value:o,children:r}),t[5]=o,t[6]=r,t[7]=s):s=t[7],s}var Dm=`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))`,Om=`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))`,km={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 Am(){let e=(0,Q.c)(2),t=jm,[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 jm(){return typeof document<`u`&&document.documentElement.classList.contains(`dark`)}function Mm(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 Nm=e=>{let t=(0,Q.c)(8),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r=Am(),i=r?Dm:Om,a=Z.useRef(null);Mm(i,a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o={display:`contents`},t[2]=o):o=t[2];let s=r?`dark`:`light`,c,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c={classNames:{toast:`group/toast toast !flex !min-w-[min(var(--width),calc(100vw-2rem))] !max-w-[calc(100vw-2rem)] !items-center !rounded-[var(--yuri-toast-radius,var(--radius-xl))] !border-0 !px-[var(--yuri-toast-padding-x,0.875rem)] !py-[var(--yuri-toast-padding-y,0.75rem)] !gap-[var(--yuri-toast-gap,0.625rem)] !text-foreground`,content:`!min-w-0 !flex-1 !text-left`,title:`typography-ui-label !font-medium !text-foreground`,description:`typography-meta !text-muted-foreground !mt-0`,actionButton:`!ms-0 !me-0 !shrink-0 !rounded-[var(--radius-md)] !bg-[var(--yuri-toast-action-background,var(--surface-muted))] !text-[var(--yuri-toast-action-foreground,var(--foreground))] hover:!opacity-85 !px-2 !py-1 typography-meta !font-medium transition-opacity`,cancelButton:`!ms-0 !me-0 !shrink-0 !rounded-[var(--radius-md)] !bg-[var(--yuri-toast-cancel-background,var(--interactive-hover))] !text-[var(--yuri-toast-cancel-foreground,var(--foreground))] hover:!bg-[var(--interactive-active)] !px-2 !py-1 typography-meta !font-medium transition-colors`,closeButton:`!rounded-[var(--radius-md)] !bg-[var(--interactive-hover)] !text-foreground hover:!bg-[var(--interactive-active)]`,icon:`!shrink-0 !text-[var(--yuri-toast-status-color,var(--muted-foreground))]`,success:`[&_[data-icon]]:!text-[var(--status-success)]`,error:`[&_[data-icon]]:!text-[var(--status-error)]`,warning:`[&_[data-icon]]:!text-[var(--status-warning)]`,info:`[&_[data-icon]]:!text-[var(--status-info)]`},style:{borderRadius:`var(--radius-xl)`,backgroundColor:`var(--yuri-toast-background, var(--surface-elevated))`}},l={"--normal-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--normal-text":`var(--foreground)`,"--normal-border":`transparent`,"--error-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--error-text":`var(--foreground)`,"--error-border":`transparent`,"--success-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--success-text":`var(--foreground)`,"--success-border":`transparent`,"--warning-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--warning-text":`var(--foreground)`,"--warning-border":`transparent`,"--info-bg":`var(--yuri-toast-background, var(--surface-elevated))`,"--info-text":`var(--foreground)`,"--info-border":`transparent`},t[3]=c,t[4]=l):(c=t[3],l=t[4]);let u;return t[5]!==n||t[6]!==s?(u=(0,$.jsx)(`div`,{ref:a,style:o,children:(0,$.jsx)(Bn,{theme:s,className:`toaster group`,position:`bottom-right`,closeButton:!1,duration:3500,icons:km,toastOptions:c,style:l,...n})}),t[5]=n,t[6]=s,t[7]=u):u=t[7],u},Pm=new ss({maxEntries:128,maxBytes:1048576}),Fm=(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(`|`)}`,Im=async e=>{let t=Su(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=e.agentName===void 0?void 0:cs(os(e.agentName).var,Su),r=JSON.stringify([e.iconName,t,e.agentName,n?.background]),i=Pm.get(r);return i===void 0&&(i=await(e.agentName===void 0?Gl(e.iconName,t):_u(us(`agent`,e.agentName,!1,n)))??``,i&&Pm.set(r,i,(r.length+i.length)*2)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:i}}))},Lm=[],Rm=e=>void 0,zm=()=>void 0;function Bm(e){let t=ju()&&e.enabled&&Ou(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=ls(e.agentName),u=ms()?.currentTheme,d=(0,Z.useRef)([]),f=(0,Z.useRef)(Fu()),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??Rm),w=J(e.onAutocompleteDismiss??zm),T=J(e=>{typeof document>`u`||Eu(document.documentElement,e)});wu.bind({onText:(e,t,n)=>{bu({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:qe(e.text,e.attachments.map(e=>e.filename)),chipRanges:zu(Cu(e.text,e.chipHighlights),Su(`--primary`)),appearance:typeof document>`u`?`dark`:Tu(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:Uu(e.agentName||void 0),agentIdenticon:Hu(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 vu(e,!0),()=>{vu(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,wu.rememberText(i.text),wu.retain(e,i);let a=Iu();return()=>{n.current=null,a(),wu.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e=>{c.current=e,n.current&&={...n.current,agentIcon:e},Nu().update({agentIcon:e})};return i(``),_u(us(`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=Is(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Nu().update(a),i)return _u(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},Nu().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let D=Mu(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:[]},wu.rememberState(n.current)),Nu().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await xu(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},wu.rememberState(n.current)),Nu().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,D]);let O=e.autocompleteRows??Lm,k=e.autocompleteOpen===!0,A=e.autocompleteHighlightedIndex??0,j=e.autocompleteQuery??``,M=`${Fm(O,k,A)}\0${j}`;(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(k&&O.length>0)){let e=Fu();ku(f.current,e)||(f.current=e,n.current&&(n.current={...n.current,autocomplete:e},wu.rememberState(n.current)),Nu().update({autocomplete:e}));return}return Im(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:Su(`--primary-base`)||Su(`--primary`),rows:t};ku(f.current,r)||(f.current=r,n.current&&(n.current={...n.current,autocomplete:r},wu.rememberState(n.current)),Nu().update({autocomplete:r}))}),()=>{e=!0}},[t,M,u]);let N=t?Cu(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&&Bu(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,wu.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=yu({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=Du(c,s,u,{caret:e.caret});d&&Nu().update(d)},[t,e.text,e.textPresetEpoch,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,D,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,N]),t}var Vm=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},Hm=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=fs(),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},Um=e=>{let t=Ko(e=>e.sttLocalModel),[n,r]=Z.useState(null);return Z.useEffect(()=>{if(!e){r(null);return}let n=!1,i=async()=>{try{let e=await f(`/api/dictation/status`,{query:{provider:`local`,localModel:t}});if(!e.ok||n)return;let i=await e.json(),a=Array.isArray(i?.models)?i.models.find(e=>e.id===t):null;n||r(typeof a?.downloadProgress==`number`?a.downloadProgress:null)}catch{}};i();let a=setInterval(()=>{i()},2e3);return()=>{n=!0,clearInterval(a)}},[e,t]),e?n:null},Wm=e=>{let t=(0,Q.c)(89),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:c,onInsert:l,onInsertAndSend:u,onActiveChange:d,onContentHeightChange:f,renderTrigger:p,topAccessory:m}=e,h=p===void 0||p,{t:g}=Xn(),{currentTheme:_}=fs(),v=Ko(Gm),y=K(Km),b;t[0]===y?b=t[1]:(b=Nc(Ec(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(qm),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}=rl(O),V=k===`recording`&&P===`model_download_in_progress`,H=Um(V),U=Z.useRef(k),W,ee;t[7]===k?(W=t[8],ee=t[9]):(W=()=>{U.current=k},ee=[k],t[7]=k,t[8]=W,t[9]=ee),Z.useEffect(W,ee);let te,ne;t[10]!==d||t[11]!==k?(te=()=>(d?.(k!==`idle`),()=>d?.(!1)),ne=[k,d],t[10]=d,t[11]=k,t[12]=te,t[13]=ne):(te=t[12],ne=t[13]),Z.useLayoutEffect(te,ne);let re,G;t[14]!==I||t[15]!==v||t[16]!==c||t[17]!==F||t[18]!==S?(re=()=>{if(!S||!v||c)return;let e=()=>{U.current===`idle`?F():U.current===`recording`&&(C.current=`insert`,I())};return window.addEventListener(`yuri:dictation-toggle`,e),()=>window.removeEventListener(`yuri:dictation-toggle`,e)},G=[S,v,c,F,I],t[14]=I,t[15]=v,t[16]=c,t[17]=F,t[18]=S,t[19]=re,t[20]=G):(re=t[19],G=t[20]),Z.useEffect(re,G);let ie,ae;t[21]!==L||t[22]!==I||t[23]!==k?(ie=()=>{if(k!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),C.current=`insert`,I();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),L())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ae=[k,I,L],t[21]=L,t[22]=I,t[23]=k,t[24]=ie,t[25]=ae):(ie=t[24],ae=t[25]),Z.useEffect(ie,ae);let oe=Z.useRef(null),se=Z.useRef(null),ce=Z.useRef(null),[le,ue]=Z.useState(null),de=k!==`idle`,fe=Z.useRef(f),pe,me;t[26]===f?(pe=t[27],me=t[28]):(pe=()=>{fe.current=f},me=[f],t[26]=f,t[27]=pe,t[28]=me),Z.useEffect(pe,me);let he=Z.useRef(!1),ge;t[29]===de?ge=t[30]:(ge=()=>{if(!de){he.current&&(he.current=!1,fe.current?.(null));return}let e=se.current,t=ce.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);he.current=!0,fe.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[29]=de,t[30]=ge);let _e;t[31]!==N||t[32]!==de||t[33]!==A||t[34]!==k?(_e=[de,A,k,N],t[31]=N,t[32]=de,t[33]=A,t[34]=k,t[35]=_e):_e=t[35],Z.useLayoutEffect(ge,_e);let ve,ye;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(ve=()=>()=>{he.current&&(he.current=!1,fe.current?.(null))},ye=[],t[36]=ve,t[37]=ye):(ve=t[36],ye=t[37]),Z.useEffect(ve,ye);let be,xe;if(t[38]===de?(be=t[39],xe=t[40]):(be=()=>{if(!de)return;let e=oe.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&ue(e.offsetHeight)},xe=[de],t[38]=de,t[39]=be,t[40]=xe),Z.useLayoutEffect(be,xe),!S||!v)return null;let Se=k!==`idle`,Ce;t[41]===I?Ce=t[42]:(Ce=e=>{C.current=e,I()},t[41]=I,t[42]=Ce);let we=Ce,Te;t[43]===R?Te=t[44]:(Te=()=>{C.current=`insert`,R()},t[43]=R,t[44]=Te);let Ee=Te,De;bb0:{if(k===`failed`){De=``;break bb0}if(k===`uploading`){let e;t[45]===g?e=t[46]:(e=g(`chat.dictation.processing`),t[45]=g,t[46]=e),De=e;break bb0}if(V){let e;t[47]!==H||t[48]!==g?(e=H===null?g(`chat.dictation.downloadingModel`):g(`chat.dictation.downloadingModelProgress`,{percent:String(H)}),t[47]=H,t[48]=g,t[49]=e):e=t[49],De=e;break bb0}let e;t[50]===g?e=t[51]:(e=g(`chat.dictation.listening`),t[50]=g,t[51]=e),De=e}let Oe=De,ke;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(ke={onMouseDown:Jm,onPointerDownCapture:Ym},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)(Hm,{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)(Hm,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:Vm(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 Gm(e){return e.dictationEnabled}function Km(e){return e.shortcutOverrides}function qm(){return!p()&&sl()}function Jm(e){return e.preventDefault()}function Ym(e){e.pointerType===`touch`&&e.preventDefault()}function Xm(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 Zm({onInsert:e,onPartial:t,onStart:n,onCancel:r,className:i,iconClassName:a,inputRef:o,onRecordingChange:s,onActiveChange:c,interactionMode:l=`desktop`,disabled:u=!1}){let{t:d}=Xn(),f=K(e=>e.shortcutOverrides),p=Nc(Ec(`toggle_dictation`,f)),m=rl({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]=Kn(()=>{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())});qn(`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}),qn(`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}),qn(`selectstart`,e=>{D.current!==null&&e.preventDefault()},document,{capture:!0}),qn(`mousemove`,e=>{D.current!==null&&e.preventDefault()},window,{capture:!0}),qn(`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),qn(`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}),qn(`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())});qn(`blur`,()=>{C||(z(),D.current===null?h.current&&F():B())},window),qn(`visibilitychange`,()=>{C||document.hidden&&(z(),D.current===null?h.current&&F():B())},document),qn(C?`yuri:mobile-dictation-toggle`:`yuri:dictation-toggle`,()=>{I()},window),qn(`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,Dp.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)(hl,{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)(Ys,{delayDuration:0,children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{variant:`ghost`,size:`icon`,className:Y(`shadow-none`,i),"aria-label":V,"aria-pressed":x,"aria-busy":w,disabled:S||v||u&&!x,onClick:()=>{I()},onBlur:C?void 0:F,children:w?(0,$.jsx)(hl,{decorative:!0}):(0,$.jsx)(Xm,{kind:`mic`,active:x&&!m.error,className:Y(a??`size-5`,m.error&&`text-[var(--status-error)]`)})})}),(0,$.jsx)(Js,{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 Qm=2e3,$m=L((e,t)=>({pending:!1,expiresAt:null,arm:(t=Qm)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),eh=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}},th=e=>xn({queryKey:[e.transport,`sessionChildren`,e.generation,In(e.directory),e.sessionID],queryFn:({signal:t})=>e.request(t),staleTime:0,gcTime:6e4,retry:!1}),nh=e=>Cn.fetchQuery(th(e)),rh=(e,t)=>e.id<t.id?-1:+(e.id>t.id),ih=(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(rh)},ah=30,oh=new Map;function sh(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function ch(e,t){let n=ce();if(!n)return!1;let r=n.getTranscript(we(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>Qr()}function lh(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function uh(e,t,n){let r=[...e.getState().session],i=Ro.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function dh(){let e=$o(),t=qi(),n=Vr(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=ce();if(!r||!t)return sh({kind:`unknown`,loadedTurns:0},!1);let i=we(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return sh(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}};di(a,t),Si(r,t),r.setState(a);for(let n of t)fe(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=oh.get(t);if(n)return oh.delete(t),oh.set(t,n),n;let r=new Set;for(oh.set(t,r);oh.size>ah;){let e=oh.keys().next().value;if(!e)break;let t=[...oh.get(e)??[]];oh.delete(e),a(e,t)}return r},[e,a]),l=(0,Z.useCallback)((r,i=e)=>{let o=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=bi(o.getState()),u=Gi(),d=Mr({seen:c,keep:r,limit:u,preserve:l});if(a(i,d),Ir()){let e=new Set([r,...c,...l]),t=(ce()?.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:ch(i,t));if(n.length>0){for(let e of n)c.delete(e);a(i,n)}}},[n,e,s,a,t]),u=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await pt(a,r):await Oe(a,r,{background:!0})}catch{return}if(i?.isStale?.())return;let u=ce()?.getTranscript(we(a,r));Ho({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await Wr({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),d=(0,Z.useCallback)(async(t,i)=>{await vr();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),c=Te.getScopedSdkClient(o);l(t,o);let d=r(t,o);return eh.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=ce(),i=we(o,t),l=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Ro.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&l&&d.kind!==`unknown`&&p?.status!==`error`&&f&&Jr(o,t)){Ho({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!l||f),h=lh({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Xo(async()=>c.session.get({sessionID:t}));if(n&&!e()){let r=ha(ye(n));e()||uh(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?u(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,l,u,e]),f=J(async(t,r)=>{let i=r||e;if(!t||!i)return;let a=n.ensureChild(i,{bootstrap:!1}),s=Te.getScopedSdkClient(i),l=c(),u=o(),d=()=>l!==c()||u!==o()||n.getChild(i)!==a,f=await nh({transport:u,generation:l,directory:i,sessionID:t,request:async e=>{let n=[],r=new Set,a;do{if(e.throwIfAborted(),l!==c()||u!==o())throw new DOMException(`Session children runtime changed`,`AbortError`);let d=await s.session.list(a?{cursor:a,limit:50}:{directory:i,parentID:t,limit:50},{signal:e});if(!Array.isArray(d?.data))throw Error(`session.list children returned no data`);if(n.push(...d.data.map(ye)),d.data.length<50)break;if(a=d.cursor?.next??void 0,!a||r.has(a))throw Error(`session.list children pagination did not advance`);r.add(a)}while(a);return n}}).catch(e=>{if(d())return null;throw e});!f||d()||a.setState(e=>{let n=ih(e.session,f,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})}),p=(0,Z.useCallback)((t,n)=>{let r=i(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,i]),m=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).loading,[e,i]),h=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).complete,[e,i]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;ut(we(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;ut(we(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(t=>{let n=t.directory||e;ut(we(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),y=J(async(t,r)=>{if(!t)return;await vr();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),s=c(),l=o(),u=()=>s!==c()||l!==o()||n.ensureChild(i,{bootstrap:!1})!==a,d=a.getState();try{if(await Oe(i,t),u())return;Ho({directory:i,sessionID:t,store:a}),await Wr({directory:i,sessionID:t,store:a,statusBeforePull:d.session_status?.[t],statusObservedAtBeforePull:d.session_status_observed_at?.[t],hasMessages:(ce()?.getTranscript(we(i,t)).messageOrder.length??0)>0,isStale:u})}catch{throw Error(`refresh transcript failed`)}});return(0,Z.useMemo)(()=>({ensureSessionRenderable:d,syncSession:d,loadChildren:f,hasMore:p,isLoading:m,isComplete:h,refreshSessionTranscript:y,optimistic:{add:g,remove:_,confirm:v}}),[d,f,p,m,h,y,g,_,v])}var fh=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,ph=e=>e===`original`||e===`modified`,mh=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},hh=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!fh(t.source))return null;let n=mh(t.startLine),r=mh(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:ph(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()}},gh=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(hh).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},_h=L()(B(R((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`yuri-inline-comment-drafts`,storage:_t(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:gh(e.drafts)}}),{name:`inline-comment-draft-store`}));function vh(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 yh(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(vh).join(`
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -6528,8 +6528,8 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}f
|
|
|
6528
6528
|
|
|
6529
6529
|
`);return t?`${n}\n\n${t}`:n},n_=(e,t)=>{let n=t_(t,e);return{text:n,offset:n===e?0:n.length-e.length}},r_=(e,t)=>t===0?e.slice():e.map(e=>({...e,start:e.start+t,end:e.end+t})),i_=(e,t)=>{let n=n_(e.text,t);return n.offset===0?e:{...e,text:n.text,references:r_(e.references,n.offset)}},a_=(e,t)=>{if(!(t in e))return e;let n={...e};return delete n[t],n},o_=L(e=>({quotesByKey:{},addQuote:(t,n)=>e(e=>{let r=e.quotesByKey[t]??qg,i=Yg(r,n);return i===r?e:{quotesByKey:{...e.quotesByKey,[t]:i}}}),removeQuote:(t,n)=>e(e=>{let r=e.quotesByKey[t];if(!r||n<0||n>=r.length)return e;let i=r.filter((e,t)=>t!==n);return{quotesByKey:i.length===0?a_(e.quotesByKey,t):{...e.quotesByKey,[t]:i}}}),removeLast:t=>e(e=>{let n=e.quotesByKey[t];if(!n||n.length===0)return e;let r=n.slice(0,-1);return{quotesByKey:r.length===0?a_(e.quotesByKey,t):{...e.quotesByKey,[t]:r}}}),clear:t=>e(e=>({quotesByKey:a_(e.quotesByKey,t)})),restore:(t,n)=>e(e=>n.length===0?{quotesByKey:a_(e.quotesByKey,t)}:{quotesByKey:{...e.quotesByKey,[t]:n}})})),s_=e=>t=>e?t.quotesByKey[e]??qg:qg;async function c_(e){let t=it(),n=()=>ot(t)&&e.isCurrent();if(!n()||e.targetKey.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.generation)return!1;let r=await Ae(e);if(!n()||!r.current)return!1;let i=r.items.find(t=>t.id===e.inboxID);if(!i||i.delivery!==`queue`)throw Error(`inbox-edit-no-longer-queued`);let a=[],o=i.payload.text,s=e=>{if(e===void 0)return[];if(!Array.isArray(e)||e.some(e=>!e||typeof e!=`object`))throw Error(`inbox-edit-invalid-payload`);return e};for(let e of s(i.payload.skills)){if(!Dt(e.id))throw Error(`inbox-edit-invalid-skill`);je(o).some(t=>t.id===e.id)||(o+=`\n[skill:${e.id}]`)}a.push({type:`text`,text:o});for(let e of s(i.payload.files)){let t=typeof e.mime==`string`&&e.mime?e.mime:`application/octet-stream`,n=e.source&&typeof e.source==`object`&&`type`in e.source&&e.source.type===`uri`&&`uri`in e.source?e.source.uri:void 0,r=typeof e.data==`string`&&e.data?`data:${t};base64,${e.data}`:typeof e.uri==`string`&&e.uri?e.uri:n;if(typeof r!=`string`||!r)throw Error(`inbox-edit-invalid-file`);a.push({type:`file`,url:r,filename:e.name,mime:t})}for(let e of s(i.payload.agents)){if(typeof e.name!=`string`||!e.name)throw Error(`inbox-edit-invalid-agent`);a.push({type:`agent`,name:e.name})}let c=await or(a,{directory:e.directory});if(!n())return!1;let l=await Yi({key:e.targetKey,expectedRevision:e.expectedRevision,payload:c,runtime:t});if(l.status!==`committed`||!l.current||!l.durable)throw Error(`inbox-edit-draft-not-committed`);let u=async()=>{l.previous&&l.result?.record&&await ra({key:e.targetKey,restoredRevision:l.result.record.revision,previous:l.previous,runtime:t})};if(!n())return await u(),!1;try{await ze(e)}catch(e){let t=e&&typeof e==`object`&&`status`in e?e.status:void 0;throw typeof t==`number`&&t>=400&&t<500&&await u(),e}return ot(t)?(Ve(e.sessionID,e.inboxID,`cancelled`),n()):!1}var l_=`text-[var(--primary)]`,u_=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,d_=/(^|\s)\/(\u2003)?([A-Za-z0-9][A-Za-z0-9_-]*)/g,f_=fn(),p_=/\[command:([^\]\r\n]+)\]/g,m_=/(^|[\s([{])(@session:([A-Za-z0-9_-]+))(?=$|[\s)\]},.!?;:])/g,h_=/@([^\s]+)/g,g_=` `,__=e=>e.replaceAll(`\\`,`/`).split(`/`).at(-1)?.replace(/\.md$/,``)??``,v_=e=>e.trim().toLowerCase(),y_=(e,t)=>{let n=t>0?e[t-1]:null;return!n||/(\s|\(|\)|\[|\]|\{|\}|"|'|`|,|\.|;|:)/.test(n)},b_=e=>!so(e)&&(e.includes(`/`)||e.includes(`\\`)||e.includes(`.`)),x_=(e,t)=>{e.push(t)},S_={kind:`skill`,priority:120,shouldScan:e=>e.includes(`/`)||e.includes(`@`)||e.includes(`[skill:`),detect:(e,t)=>{let n=[],r=t.skillNames;f_.lastIndex=0;let i;for(;(i=f_.exec(e))!==null;){let e=i[1];x_(n,{start:i.index,end:i.index+i[0].length,kind:`skill`,raw:i[0],label:`@${e}`,payload:{kind:`skill`,skillName:e}})}if(!r||r.size===0)return n;let a=new Map(Array.from(r,e=>[e.toLowerCase(),e]));for(d_.lastIndex=0;(i=d_.exec(e))!==null;){let t=i[2]??``,r=i[3]||``,o=a.get(r.toLowerCase());if(!o)continue;let s=i.index+i[1].length,c=s+1+t.length+r.length;n.some(e=>e.start<c&&e.end>s)||x_(n,{start:s,end:c,kind:`skill`,raw:e.slice(s,c),label:`/${o}`,payload:{kind:`skill`,skillName:o}})}let o=t.agentNames,s=/(^|\s)@(\u2003)?([^\s)\]},.!?;:]+)(?=$|[\s)\]},.!?;:])/gu;for(;(i=s.exec(e))!==null;){let t=i[2]??``,r=i[3]||``,s=a.get(r.toLowerCase());if(!s||o?.has(r.toLowerCase()))continue;let c=i.index+i[1].length,l=c+1+t.length+r.length;n.some(e=>e.start<l&&e.end>c)||x_(n,{start:c,end:l,kind:`skill`,raw:e.slice(c,l),label:`@${s}`,payload:{kind:`skill`,skillName:s}})}return n},decorate:e=>{let t=e.payload.kind===`skill`?e.payload.skillName:e.label.slice(1);return{kind:`skill`,label:e.label,icon:`book-open`,className:l_,href:Ad(t),skillName:t}}},C_={kind:`command`,priority:115,shouldScan:(e,t)=>e.includes(`[command:`)||!!t.commandNames?.size&&e.includes(`/`),detect:(e,t)=>{let n=[];p_.lastIndex=0;let r;for(;(r=p_.exec(e))!==null;){let e=r[1],t=__(e);t&&x_(n,{start:r.index,end:r.index+r[0].length,kind:`command`,raw:r[0],label:`/${t}`,payload:{kind:`command`,commandName:t,reference:e}})}let i=t.commandNames;if(!i||i.size===0)return n;let a=new Map(Array.from(i,e=>[e.toLowerCase(),e]));for(d_.lastIndex=0;(r=d_.exec(e))!==null;){let t=r[2]??``,i=r[3]||``,o=a.get(i.toLowerCase());if(!o)continue;let s=r.index+r[1].length,c=s+1+t.length+i.length;n.some(e=>e.start<c&&e.end>s)||x_(n,{start:s,end:c,kind:`command`,raw:e.slice(s,c),label:`/${o}`,payload:{kind:`command`,commandName:o}})}return n},decorate:e=>({kind:`command`,label:e.label,icon:`command`,className:l_})},w_={kind:`image`,priority:110,shouldScan:e=>e.includes(`[`),detect:(e,t)=>{let n=[],r=0;for(;r<e.length;){let i=e.indexOf(`[`,r);if(i===-1)break;let a=e.indexOf(`]`,i+1);if(a===-1)break;if(e[a+1]===`(`){r=a+1;continue}let o=Yt(e.slice(i+1,a)).trim(),s=v_(o),c=t.citationIcons?.get(s),l=!c&&u_.test(o),u=c??(l?`image`:null);if(!u){r=a+1;continue}let d=t.citationDisplayNames?.get(s)??(u===`image`&&o.replaceAll(`\\`,`/`).split(`/`).at(-1)||o);x_(n,{start:i,end:a+1,kind:u,raw:e.slice(i,a+1),label:d,payload:u===`image`?{kind:`image`,filename:d}:{kind:`attachment`,filename:d}}),r=a+1}return n},decorate:e=>{let t=e.payload.kind===`image`||e.payload.kind===`attachment`?e.payload.filename:e.label;return{kind:e.kind===`attachment`?`attachment`:`image`,label:t,icon:e.kind===`attachment`?`attachment-2`:`file-image`,className:l_,filename:t}}},T_={kind:`session`,priority:105,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[];m_.lastIndex=0;let r;for(;(r=m_.exec(e))!==null;){let i=r[3],a=r.index+r[1].length,o=a+r[2].length,s=t.sessionTitles?.get(i)??i;x_(n,{start:a,end:o,kind:`session`,raw:e.slice(a,o),label:s,payload:{kind:`session`,sessionId:i,sessionLabel:s}})}let i=[...t.sessionMentions??[]].filter(e=>e.sessionLabel.length>0).sort((e,t)=>t.sessionLabel.length-e.sessionLabel.length);for(let t of i){let r=[`@${g_}${t.sessionLabel}`,`@${t.sessionLabel}`];for(let i of r){let r=e.indexOf(i);for(;r!==-1;){let a=r+i.length,o=r===0||/[\s([{]/.test(e[r-1]),s=a===e.length||/[\s)\]},.!?;:]/.test(e[a]),c=n.some(e=>e.start<a&&e.end>r);o&&s&&!c&&x_(n,{start:r,end:a,kind:`session`,raw:e.slice(r,a),label:t.sessionLabel,payload:{kind:`session`,sessionId:t.sessionId,sessionLabel:t.sessionLabel}}),r=e.indexOf(i,a)}}}return n},decorate:e=>{let t=e.payload.kind===`session`?e.payload.sessionId:void 0;return{kind:`session`,label:e.payload.kind===`session`?e.payload.sessionLabel:e.label,icon:`chat-thread`,className:l_,sessionId:t}}},E_={kind:`file`,priority:100,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[],r=t.agentNames,i=t.filePaths,a=t.allowPathHeuristics===!0;h_.lastIndex=0;let o;for(;(o=h_.exec(e))!==null;){let t=o.index;if(!y_(e,t)||o[1].startsWith(`session:`))continue;let s=La(e,t,i)??(a?yo(e,t):null);if(s&&(s.value.includes(` `)||s.value.includes(` `))){let r=e.slice(t,s.end);x_(n,{start:t,end:s.end,kind:`file`,raw:r,label:r,payload:{kind:`file`,path:s.value}}),h_.lastIndex=s.end;continue}let c=o[1].trim().replace(/[),.;:!?`"'>]+$/g,``);if(!c)continue;let l=t+1+c.length,u=e.slice(t,l);if(r?.has(c.toLowerCase())){x_(n,{start:t,end:l,kind:`agent`,raw:u,label:u,payload:{kind:`agent`,agentName:c}});continue}let d=c.replace(/\\/g,`/`).replace(/^\.\//,``);(i?.has(c)||i?.has(d)||i?.has(d.replace(/^\/+/,``))||a&&b_(c))&&x_(n,{start:t,end:l,kind:`file`,raw:u,label:u,payload:{kind:`file`,path:c}})}return n},decorate:e=>{if(e.kind===`agent`&&e.payload.kind===`agent`)return{kind:`agent`,label:e.label,icon:null,className:l_,href:wd(e.payload.agentName),agentName:e.payload.agentName};let t=e.payload.kind===`file`?e.payload.path:e.label;return{kind:`file`,label:e.label,icon:null,className:l_,path:t}}},D_=[S_,C_,w_,T_,E_],O_=(e,t=D_)=>{let n=t.find(t=>t.kind===e.kind)??t.find(t=>t.decorate(e).kind===e.kind);return n?n.decorate(e):e.kind===`image`||e.kind===`attachment`?w_.decorate(e):e.kind===`agent`?E_.decorate(e):{kind:e.kind,label:e.label,icon:null,className:l_}},k_=[`/`,`[`,`@`],A_=e=>{if(!e)return!1;for(let t of k_)if(e.includes(t))return!0;return!1},j_=(e,t)=>{if(e.length<=1)return e;let n=[...e].sort((e,n)=>{let r=(t.get(n)??0)-(t.get(e)??0);return r===0?e.start===n.start?n.end-n.start-(e.end-e.start):e.start-n.start:r}),r=[];for(let e of n)r.some(t=>e.start<t.end&&e.end>t.start)||r.push(e);return r.sort((e,t)=>e.start-t.start||e.end-t.end)},M_=(e,t={},n=D_)=>{if(!A_(e))return[];let r=[],i=new Map;for(let a of n)if(a.shouldScan(e,t))for(let n of a.detect(e,t))r.push(n),i.set(n,a.priority);return j_(r,i)},N_=(e,t,n=D_)=>{if(!e)return[];if(t.length===0)return[{type:`text`,text:e}];let r=[],i=0;for(let a of t)a.start<i||a.end<=a.start||a.end>e.length||(a.start>i&&r.push({type:`text`,text:e.slice(i,a.start)}),r.push({type:`reference`,span:a,decoration:O_(a,n)}),i=a.end);return i<e.length&&r.push({type:`text`,text:e.slice(i)}),r.length>0?r:[{type:`text`,text:e}]},P_=(e,t={},n=D_)=>{if(!A_(e))return null;let r=M_(e,t,n);return r.length===0?null:N_(e,r,n)},F_=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,I_=e=>e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`\\\\`),L_=(e,t)=>!!t?.startsWith(`image/`)||F_.test(e),R_=e=>{let t=new Map;if(!e||e.length===0)return t;for(let n of e){if(n.type!==`file`)continue;let e=typeof n.filename==`string`?n.filename.trim():``;if(!e)continue;let r=e.toLowerCase(),i=typeof n.mime==`string`?n.mime:void 0;t.set(r,L_(e,i)?`image`:`attachment`)}return t},z_=e=>{let t=[],n=0;for(;n<e.length;){let r=e.indexOf(`[`,n);if(r===-1)break;let i=e.indexOf(`]`,r+1);if(i===-1)break;if(e[i+1]===`(`){n=i+1;continue}let a=Yt(e.slice(r+1,i)).trim();I_(a)&&F_.test(a)&&t.push(a),n=i+1}return t},B_=(e,t)=>{let n=R_(e),r=new Map;if(!t||!e?.length)return{icons:n,displayNames:r};let i=[];for(let t of e){if(t.type!==`file`)continue;let e=typeof t.filename==`string`?t.filename.trim():``;e&&L_(e,typeof t.mime==`string`?t.mime:void 0)&&i.push(e)}if(i.length===0)return{icons:n,displayNames:r};let a=z_(t),o=(e,t)=>{let i=e.toLowerCase();r.set(i,t),n.set(i,`image`)};if(i.length===1){for(let e of a)o(e,i[0]);return{icons:n,displayNames:r}}return a.forEach((e,t)=>{let n=i[t];n&&o(e,n)}),{icons:n,displayNames:r}},V_=e=>{switch(e.kind){case`session`:return{trigger:`@`,icon:`chat-thread`,label:e.label};case`skill`:return{trigger:e.label.startsWith(`/`)?`/`:`@`,icon:`book-open`,label:e.label.replace(/^[@/]/,``)};case`command`:return{trigger:`/`,icon:`command`,label:e.label.replace(/^\//,``)};case`image`:return{trigger:`[`,icon:`file-image`,label:e.label,suffix:`]`};case`attachment`:return{trigger:`[`,icon:`attachment-2`,label:e.label,suffix:`]`};case`file`:case`agent`:return}},H_=e=>{let t=(0,Q.c)(28),{decoration:n,onOpenSkill:r,interactive:i}=e,a=i===void 0||i,o;t[0]===n?o=t[1]:(o=V_(n),t[0]=n,t[1]=o);let s=o,c=s?.icon??n.icon,l=s?.label??n.label,u=s?`${s.trigger}${Kt}`:Kt,d=n.kind===`file`?`whitespace-pre-wrap break-words`:`whitespace-nowrap`,f;t[2]!==n.className||t[3]!==d?(f=Y(d,n.className),t[2]=n.className,t[3]=d,t[4]=f):f=t[4];let p;t[5]!==c||t[6]!==u?(p=c?(0,$.jsxs)(`span`,{className:`relative inline-block shrink-0 align-baseline leading-none`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`text-transparent`,children:u}),(0,$.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 inline-flex items-center justify-center`,style:{left:sn,right:sn},children:(0,$.jsx)(X,{name:c,className:Y(Qt,`shrink-0`),"aria-hidden":`true`})})]}):null,t[5]=c,t[6]=u,t[7]=p):p=t[7];let m;t[8]!==n.kind||t[9]!==l||t[10]!==f||t[11]!==p?(m=(0,$.jsxs)(`span`,{className:f,"data-message-reference-kind":n.kind,children:[p,l]}),t[8]=n.kind,t[9]=l,t[10]=f,t[11]=p,t[12]=m):m=t[12];let h=m;if(!a)return h;if(n.kind===`skill`&&n.skillName&&r){let e;t[13]!==n.skillName||t[14]!==r?(e=e=>{e.stopPropagation(),r(n.skillName)},t[13]=n.skillName,t[14]=r,t[15]=e):e=t[15];let i;return t[16]!==h||t[17]!==n.skillName||t[18]!==e?(i=(0,$.jsx)(`button`,{type:`button`,className:`inline hover:underline`,"data-skill-name":n.skillName,onClick:e,children:h}),t[16]=h,t[17]=n.skillName,t[18]=e,t[19]=i):i=t[19],i}if(n.kind===`agent`&&n.href){let e;t[20]!==n.agentName||t[21]!==n.label?(e=n.agentName||n.label.replace(/^@/,``),t[20]=n.agentName,t[21]=n.label,t[22]=e):e=t[22];let r;t[23]===e?r=t[24]:(r=Od(e),t[23]=e,t[24]=r);let i;return t[25]!==h||t[26]!==r?(i=(0,$.jsx)(`a`,{href:r,className:`inline hover:underline`,target:`_blank`,rel:`noopener noreferrer`,"data-yuri-agent-mention":`true`,onClick:U_,children:h}),t[25]=h,t[26]=r,t[27]=i):i=t[27],i}return h};H_.displayName=`MessageReferenceChip`;function U_(e){return e.stopPropagation()}var W_=e=>e!==`frozen`,G_=(e,t)=>e.length===0?t:t.length===0?e:[...e,...t],K_=e=>e.status===`committed`&&e.current===!0,q_=e=>{let t=e.failure?.recovery;return{content:t?.content??e.content,attachments:t?.attachments??e.attachments,composerDocument:t?.composerDocument??e.composerDocument,composerMentions:t?.composerMentions??e.composerMentions}},J_=(e,t)=>{let n=e.status??`queued`;return!t&&(n===`queued`||n===`retrying`||n===`failed`||n===`unresolved`)},Y_=(e,t,n)=>Go(e)||t||e.manualDispatchRequested===!0&&!n?.allowManualDispatchRetry?!1:[`queued`,`retrying`,`failed`,`unresolved`].includes(e.status),X_=(e,t)=>!t.frozen&&!Go(e),Z_=(e,t)=>!(t.frozen||Go(e)),Q_=e=>e.status===`sending`||e.status===`reconciling`,$_=e=>e.status===`sending`||e.status===`reconciling`,ev=e=>e.manualDispatchRequested===!0||e.status===`sending`||e.status===`reconciling`,tv=e=>e.status===`sending`||e.status===`reconciling`,nv=8e3,rv=(e,t)=>e.transportIdentity===t.transportIdentity&&e.runtimeGeneration===t.runtimeGeneration&&In(e.directory)===In(t.directory)&&e.sessionID===t.sessionID&&e.scopeID===t.scopeID,iv=(e,t)=>e.filter(e=>rv(e,t)),av=(e,t,n)=>e.filter(e=>rv(e,t)&&Number.isSafeInteger(e.committedRevision)&&e.committedRevision>0&&(n===void 0||n<e.committedRevision)),ov=(e,t)=>{if(t.kind===`send`)return e;if(t.kind===`edit`||t.kind===`remove`){let n=e.findIndex(e=>!Go(e)&&e.queueItemID===t.queueItemID);return n<0?e:[...e.slice(0,n),...e.slice(n+1)]}if(t.kind===`reorder`){let n=t.queueItemIDs;if(!n)return e;let r=new Map,i=[],a=[];for(let t of e){if(Go(t)){a.push(t);continue}i.push(t),r.set(t.queueItemID,t)}let o=[],s=new Set;for(let e of n){let t=r.get(e);t&&!s.has(e)&&(o.push(t),s.add(e))}let c=i.filter(e=>!s.has(e.queueItemID)),l=[...o,...c,...a];return l.every((t,n)=>t===e[n])?e:l}return e},sv=(e,t)=>t.reduce(ov,e),cv=(e,t)=>{let n=sv(e,t),r=n.filter(e=>Go(e)||!tv(e));return r.length===n.length?n:r},lv=(e,t,n)=>({requestID:n,scopeID:e.scopeID,revision:e.revision,item:t}),uv=(e,t,n,r)=>({scopeID:e.scopeID,scopeRevision:e.revision,item:t,targetKey:n,expectedRevision:r}),dv=(e,t,n,r,i=e.items)=>{let a=i.filter(e=>!Go(e)).map(e=>e.queueItemID),o=a.indexOf(t),s=a.indexOf(n);if(o<0||s<0||o===s)return null;let[c]=a.splice(o,1);if(!c)return null;a.splice(s,0,c);let l=new Set(a),u=0,d=e.items.map(e=>l.has(e.queueItemID)?a[u++]??e.queueItemID:e.queueItemID);return{requestID:r,scopeID:e.scopeID,revision:e.revision,queueItemIDs:d}},fv=e=>{let t=e.failure?.recovery,n=t?.composerDocument?.text??e.composerDocument?.text;return typeof n==`string`&&n.length>0?n:t?.content??e.content},pv=e=>{let t=new Map;for(let n of e??[]){let e=typeof n.filename==`string`?n.filename.trim():``;if(!e)continue;let r=e.toLowerCase();if(n.mimeType?.startsWith(`image/`)){t.set(r,`image`);continue}Ce({source:n.source??`local`,vscodeSource:n.vscodeSource,mimeType:n.mimeType})&&t.set(r,`attachment`)}return t},mv=e=>{let t=[];for(let n of e?.references??[]){if(n.kind!==`session`||typeof n.sessionId!=`string`)continue;let e=(typeof n.display==`string`?n.display:``).replace(/^@\u2003?/,``).trim()||n.sessionId;t.push({sessionId:n.sessionId,sessionLabel:e})}return t},hv=e=>{let t=new Set,n=new Set;for(let r of e?.references??[]){if(r.kind===`skill`&&typeof r.skillName==`string`&&r.skillName){t.add(r.skillName);continue}r.kind===`command`&&typeof r.commandName==`string`&&r.commandName&&n.add(r.commandName)}return{skillNames:t.size>0?t:void 0,commandNames:n.size>0?n:void 0}},gv=e=>(e.split(`
|
|
6530
6530
|
`)[0]??``)+(e.includes(`
|
|
6531
|
-
`)?`...`:``),_v=(e,t={})=>{let n=gv(e);if(!n)return null;let r=hv(t.composerDocument);return P_(n,{citationIcons:pv(t.attachments),sessionMentions:mv(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},vv=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return(t.kind===`edit`||t.kind===`send`||t.kind===`remove`||t.kind===`reorder`)&&typeof t.transportIdentity==`string`&&typeof t.runtimeGeneration==`number`&&Number.isSafeInteger(t.runtimeGeneration)&&t.runtimeGeneration>=0&&typeof t.directory==`string`&&typeof t.sessionID==`string`&&typeof t.scopeID==`string`&&typeof t.queueItemID==`string`&&(t.queueItemIDs===void 0||Array.isArray(t.queueItemIDs)&&t.queueItemIDs.every(e=>typeof e==`string`))},yv=(0,Z.memo)(e=>{let t=(0,Q.c)(157),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,sendPendingTimedOut:s,abortSendPending:c,steering:l,isMobile:u,inboxEditable:d,onEdit:f,onSend:p,onQueue:m,onRemove:h,compactionBarrier:g}=e,_=g!==void 0&&g,{t:v}=Xn(),y;t[0]===n?y=t[1]:(y=Ue(n),t[0]=n,t[1]=y);let b=y,x;t[2]!==n||t[3]!==p?(x={mutationFn:async()=>{await p(n)}},t[2]=n,t[3]=p,t[4]=x):x=t[4];let S=q(x),C;t[5]!==n||t[6]!==f?(C={mutationFn:async()=>{await f(n)}},t[5]=n,t[6]=f,t[7]=C):C=t[7];let w=q(C),T;t[8]===n?T=t[9]:(T=Go(n),t[8]=n,t[9]=T);let E=T,D=n.queueItemID||n.id,O;t[10]!==w.isPending||t[11]!==o||t[12]!==r?(O=w.isPending||r&&o.has(`edit`),t[10]=w.isPending,t[11]=o,t[12]=r,t[13]=O):O=t[13];let k=O,A;t[14]!==o||t[15]!==r?(A=r&&o.has(`remove`),t[14]=o,t[15]=r,t[16]=A):A=t[16];let j=A,M;t[17]!==o||t[18]!==r?(M=r&&o.has(`reorder`),t[17]=o,t[18]=r,t[19]=M):M=t[19];let N=M,P=r||E?void 0:n,F;t[20]!==n||t[21]!==E||t[22]!==r?(F=r&&!E&&ev(n),t[20]=n,t[21]=E,t[22]=r,t[23]=F):F=t[23];let I=F,L;t[24]===P?L=t[25]:(L=P&&$_(P),t[24]=P,t[25]=L);let R=!!L,z;t[26]!==n||t[27]!==E||t[28]!==r?(z=r&&!E&&Q_(n),t[26]=n,t[27]=E,t[28]=r,t[29]=z):z=t[29];let B=z,V;t[30]!==I||t[31]!==R||t[32]!==o||t[33]!==r?(V=r&&o.has(`send`)||I||R,t[30]=I,t[31]=R,t[32]=o,t[33]=r,t[34]=V):V=t[34];let H=V,U=l||b&&(S.isPending||n.delivery===`steer`)||c||H&&!s,W=i||E,ee;t[35]!==k||t[36]!==i||t[37]!==b||t[38]!==d||t[39]!==n||t[40]!==U?(ee=b?d&&!i&&!k&&!U&&n.delivery===`queue`:X_(n,{frozen:i}),t[35]=k,t[36]=i,t[37]=b,t[38]=d,t[39]=n,t[40]=U,t[41]=ee):ee=t[41];let te=ee,ne;t[42]!==k||t[43]!==i||t[44]!==b||t[45]!==n?(ne=b?!i&&!k:Z_(n,{frozen:i}),t[42]=k,t[43]=i,t[44]=b,t[45]=n,t[46]=ne):ne=t[46];let re=ne,G=b||P?.owner?.state===`unbound-legacy`||W||B,ie=b&&_,ae;t[47]!==W||t[48]!==k||t[49]!==i||t[50]!==a||t[51]!==b||t[52]!==n||t[53]!==U||t[54]!==s||t[55]!==r||t[56]!==ie?(ae=b?!i&&!k&&!U&&n.delivery===`queue`&&!ie:!W&&!U&&(r?Y_(n,a,{allowManualDispatchRetry:s}):J_(n,a)),t[47]=W,t[48]=k,t[49]=i,t[50]=a,t[51]=b,t[52]=n,t[53]=U,t[54]=s,t[55]=r,t[56]=ie,t[57]=ae):ae=t[57];let oe=ae,se=b&&!i&&n.delivery===`steer`&&!ie,ce=P?.failure?.recovery,le;t[58]===n?le=t[59]:(le=fv(n),t[58]=n,t[59]=le);let ue=le,de=E||b?void 0:ce?.attachments??(`attachments`in n?n.attachments:void 0),fe=ce?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),pe;t[60]!==G||t[61]!==D?(pe={id:D,disabled:G},t[60]=G,t[61]=D,t[62]=pe):pe=t[62];let{attributes:me,listeners:he,setNodeRef:ge,transform:_e,transition:ve,isDragging:ye}=ld(pe),be;t[63]===ue?be=t[64]:(be=gv(ue),t[63]=ue,t[64]=be);let xe=be,Se;t[65]!==de||t[66]!==fe||t[67]!==ue?(Se=_v(ue,{attachments:de,composerDocument:fe}),t[65]=de,t[66]=fe,t[67]=ue,t[68]=Se):Se=t[68];let Ce=Se,we=E||b?n.attachmentCount:de?.length??0,Te;t[69]!==n||t[70]!==h?(Te=()=>h(n),t[69]=n,t[70]=h,t[71]=Te):Te=t[71];let Ee=!re,De=j||void 0,Oe=u?`h-7 w-3`:`size-6`,ke;t[72]===Oe?ke=t[73]:(ke=Y(`inline-flex shrink-0 items-center justify-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,Oe),t[72]=Oe,t[73]=ke);let Ae;t[74]===v?Ae=t[75]:(Ae=v(`chat.queuedMessage.removeAria`),t[74]=v,t[75]=Ae);let je=j?`loader-4`:`delete-bin`,Me=u?`size-3`:`size-3.5`,Ne=j&&`animate-spin`,Pe;t[76]!==Me||t[77]!==Ne?(Pe=Y(Me,Ne),t[76]=Me,t[77]=Ne,t[78]=Pe):Pe=t[78];let Fe;t[79]!==je||t[80]!==Pe?(Fe=(0,$.jsx)(X,{name:je,className:Pe,"aria-hidden":`true`}),t[79]=je,t[80]=Pe,t[81]=Fe):Fe=t[81];let Ie;t[82]!==Te||t[83]!==Ee||t[84]!==De||t[85]!==ke||t[86]!==Ae||t[87]!==Fe?(Ie=(0,$.jsx)(`button`,{type:`button`,onClick:Te,disabled:Ee,"aria-busy":De,className:ke,"aria-label":Ae,children:Fe}),t[82]=Te,t[83]=Ee,t[84]=De,t[85]=ke,t[86]=Ae,t[87]=Fe,t[88]=Ie):Ie=t[88];let Le=Ie,Re;t[89]===_e?Re=t[90]:(Re=od.Translate.toString(_e),t[89]=_e,t[90]=Re);let ze;t[91]!==Re||t[92]!==ve?(ze={transform:Re,transition:ve},t[91]=Re,t[92]=ve,t[93]=ze):ze=t[93];let Be=u?`gap-1 py-0.5`:`flex gap-1.5 py-px md:gap-2`,Ve=ye&&`z-10 opacity-60`,He;t[94]!==Be||t[95]!==Ve?(He=Y(`flex min-w-0 items-center`,Be,Ve),t[94]=Be,t[95]=Ve,t[96]=He):He=t[96];let We=N||void 0,Ge=u?`h-7 w-3`:`size-auto`,Ke=G?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,qe;t[97]!==Ge||t[98]!==Ke?(qe=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,Ge,`transition-colors`,Ke),t[97]=Ge,t[98]=Ke,t[99]=qe):qe=t[99];let Je;t[100]===v?Je=t[101]:(Je=v(`chat.queuedMessage.reorderAria`),t[100]=v,t[101]=Je);let Ye=N?`loader-4`:`draggable`,Xe=u?`size-3`:`size-3.5`,Ze=N&&`animate-spin`,Qe;t[102]!==Xe||t[103]!==Ze?(Qe=Y(Xe,Ze),t[102]=Xe,t[103]=Ze,t[104]=Qe):Qe=t[104];let $e;t[105]!==Ye||t[106]!==Qe?($e=(0,$.jsx)(X,{name:Ye,className:Qe,"aria-hidden":`true`}),t[105]=Ye,t[106]=Qe,t[107]=$e):$e=t[107];let et;t[108]!==me||t[109]!==G||t[110]!==he||t[111]!==We||t[112]!==qe||t[113]!==Je||t[114]!==$e?(et=(0,$.jsx)(`button`,{type:`button`,...me,...he,disabled:G,"aria-busy":We,className:qe,"aria-label":Je,children:$e}),t[108]=me,t[109]=G,t[110]=he,t[111]=We,t[112]=qe,t[113]=Je,t[114]=$e,t[115]=et):et=t[115];let tt=u?Le:null,nt=u?`text-xs leading-5`:`typography-ui-label leading-5`,rt;t[116]===nt?rt=t[117]:(rt=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground [&>[data-message-reference-kind]]:min-w-0 [&>[data-message-reference-kind]]:truncate`,nt),t[116]=nt,t[117]=rt);let it;t[118]!==xe||t[119]!==Ce||t[120]!==v?(it=Ce?Ce.map(kv):xe||v(`chat.queuedMessage.empty`),t[118]=xe,t[119]=Ce,t[120]=v,t[121]=it):it=t[121];let at;t[122]!==we||t[123]!==v?(at=we>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:v(`chat.queuedMessage.attachments`,{count:we})}),t[122]=we,t[123]=v,t[124]=at):at=t[124];let ot;t[125]!==rt||t[126]!==it||t[127]!==at?(ot=(0,$.jsxs)(`span`,{className:rt,children:[it,at]}),t[125]=rt,t[126]=it,t[127]=at,t[128]=ot):ot=t[128];let st;t[129]!==te||t[130]!==se||t[131]!==oe||t[132]!==k||t[133]!==b||t[134]!==w||t[135]!==S||t[136]!==u||t[137]!==n||t[138]!==f||t[139]!==m||t[140]!==p||t[141]!==E||t[142]!==U||t[143]!==v||t[144]!==ie?(st=U&&!ie?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,u?`h-7 text-[11px] leading-none`:`h-6 typography-ui-label`),"aria-live":`polite`,"aria-label":v(`chat.queuedMessage.sendingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(u?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:v(`chat.queuedMessage.sending`)})]}):E?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,u?`h-7 text-[11px] leading-none`:`h-6 typography-ui-label`),"aria-live":`polite`,"aria-label":v(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(u?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:v(`chat.queuedMessage.queuing`)})]}):ie?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,u?`h-7 text-[11px] leading-none`:`h-6 typography-ui-label`),"aria-live":`polite`,"aria-label":v(`chat.queuedMessage.waitingForCompactionAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(u?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:v(`chat.queuedMessage.waitingForCompaction`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{b?w.mutate():f(n)},disabled:!te,"aria-busy":k||void 0,"aria-label":v(`chat.queuedMessage.edit`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,u?`h-7 gap-1.5 px-0 text-[11px]`:`h-6 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:k?`loader-4`:`edit`,className:Y(u?`size-3`:`size-3.5`,k&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium capitalize`,u?`leading-none`:`typography-ui-label`),children:v(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{U||(b?S.mutate():p(n))},disabled:!oe||U,"aria-busy":U||void 0,"aria-label":v(`chat.queuedMessage.send`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,u?`h-7 gap-1.5 px-0 text-[11px]`:`h-6 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`send-plane`,className:Y(u?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium capitalize`,u?`leading-none`:`typography-ui-label`),children:v(`chat.queuedMessage.send`)})]}),se?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>m?.(n),disabled:!se,"aria-label":v(`chat.queuedMessage.title`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,u?`h-7 gap-1.5 px-0 text-[11px]`:`h-6 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`time`,className:Y(u?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,u?`leading-none`:`typography-ui-label`),children:v(`chat.queuedMessage.title`)})]}):null]}),t[129]=te,t[130]=se,t[131]=oe,t[132]=k,t[133]=b,t[134]=w,t[135]=S,t[136]=u,t[137]=n,t[138]=f,t[139]=m,t[140]=p,t[141]=E,t[142]=U,t[143]=v,t[144]=ie,t[145]=st):st=t[145];let ct=!u&&!E?Le:null,lt;t[146]!==st||t[147]!==ct?(lt=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[st,ct]}),t[146]=st,t[147]=ct,t[148]=lt):lt=t[148];let ut;return t[149]!==ge||t[150]!==ze||t[151]!==He||t[152]!==et||t[153]!==tt||t[154]!==ot||t[155]!==lt?(ut=(0,$.jsxs)(`div`,{ref:ge,role:`group`,style:ze,className:He,children:[et,tt,ot,lt]}),t[149]=ge,t[150]=ze,t[151]=He,t[152]=et,t[153]=tt,t[154]=ot,t[155]=lt,t[156]=ut):ut=t[156],ut});yv.displayName=`QueuedMessageChip`;var bv=[],xv=[],Sv=[],Cv=new Set,wv=new Set,Tv=(e,t)=>t?G_($t(e,Nt(t.sessionID)),$t(e,t)):bv,Ev=(e,t)=>{if(!t)return xv;let n=Tv(e,t),r=[...wt(e,Nt(t.sessionID)),...wt(e,t)];return r.length===0?n:[...n,...r]},Dv=(e,t)=>{let n=e.owner;return n?n.state===`unbound-legacy`?n.sessionID===t.sessionID?Nt(t.sessionID):null:Ot(n)===Ot(t)?t:null:null},Ov=(0,Z.memo)(e=>{let t=(0,Q.c)(173),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:s,clientPendingItems:c,onRemoveClientPending:l,onSteerClientPending:u,onQueueClientPending:d,compactionBarrier:f,steeringMessageIDs:p,trailing:m}=e,h=c===void 0?Sv:c,g=f!==void 0&&f,_=p===void 0?wv:p,{t:v}=Xn(),y=K(Av),b=o?.transportIdentity??``,x=o?.directory??``,S=o?.sessionID??``,C;t[0]!==b||t[1]!==x||t[2]!==S?(C={transportIdentity:b,directory:x,sessionID:S},t[0]=b,t[1]=x,t[2]=S,t[3]=C):C=t[3];let w=Ah(C),T;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(T=new Map,t[4]=T):T=t[4];let E=Z.useRef(T);o?.runtimeGeneration,o?.transportIdentity;let D=o?.transportIdentity??``,O=o?.runtimeGeneration??-1,k;t[5]!==O||t[6]!==D?(k=[D,`messageQueue`,`scopeMutation`,O],t[5]=O,t[6]=D,t[7]=k):k=t[7];let A=k,j;t[8]===w.actions?j=t[9]:(j=e=>Ji(E,`${e.transportIdentity}\u0000${e.runtimeGeneration}\u0000${e.directory}\u0000${e.sessionID}\u0000${e.scopeID}`,()=>{if(e.transportIdentity!==e.runtime.transportIdentity||e.runtimeGeneration!==e.runtime.generation)return Promise.resolve({status:`stale`});let t=w.actions.captureRuntime();if(t.transportIdentity!==e.runtime.transportIdentity||t.generation!==e.runtime.generation)return Promise.resolve({status:`stale`});switch(e.kind){case`edit`:return w.actions.editIntoDraft(e.input);case`send`:return w.actions.manualSend(e.input);case`remove`:return w.actions.remove(e.input);case`reorder`:return w.actions.reorder(e.input)}throw Error(`Unsupported server queue operation`)}),t[8]=w.actions,t[9]=j);let M,N;t[10]!==w.actions||t[11]!==v?(M=(e,t)=>{let n=w.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&e.status!==`stale`&&t.kind===`edit`&&e.status!==`committed`&&ji.error(v(`chat.chatInput.toast.queueOperationFailed`))},N=(e,t)=>{let n=w.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&ji.error(v(e instanceof Zo&&e.code===`unavailable`?`chat.chatInput.toast.queueOperationStatusUnknown`:`chat.chatInput.toast.queueOperationFailed`))},t[10]=w.actions,t[11]=v,t[12]=M,t[13]=N):(M=t[12],N=t[13]);let P;t[14]!==A||t[15]!==j||t[16]!==M||t[17]!==N?(P={mutationKey:A,mutationFn:j,onSuccess:M,onError:N},t[14]=A,t[15]=j,t[16]=M,t[17]=N,t[18]=P):P=t[18];let F=q(P),I;t[19]===A?I=t[20]:(I={filters:{mutationKey:A,exact:!0,status:`pending`},select:jv},t[19]=A,t[20]=I);let L=bn(I),R;t[21]===A?R=t[22]:(R={filters:{mutationKey:A,exact:!0,status:`success`},select:Mv},t[21]=A,t[22]=R);let z=bn(R),B;bb0:{if(!o||!w.scope){B=null;break bb0}let e=o.runtimeGeneration??w.runtimeCapture.generation,n;t[23]!==o.directory||t[24]!==o.sessionID||t[25]!==o.transportIdentity||t[26]!==w.scope.scopeID||t[27]!==e?(n={transportIdentity:o.transportIdentity,directory:o.directory,sessionID:o.sessionID,scopeID:w.scope.scopeID,runtimeGeneration:e},t[23]=o.directory,t[24]=o.sessionID,t[25]=o.transportIdentity,t[26]=w.scope.scopeID,t[27]=e,t[28]=n):n=t[28],B=n}let V=B,H;bb1:{if(!V){let e;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[29]=e):e=t[29],H=e;break bb1}let e;if(t[30]!==V||t[31]!==L){let n;t[33]===V?n=t[34]:(n=e=>vv(e)&&e.scopeID===V.scopeID,t[33]=V,t[34]=n),e=iv(L.filter(n),V),t[30]=V,t[31]=L,t[32]=e}else e=t[32];H=e}let U=H,W;t[35]!==V||t[36]!==w.scope?.revision||t[37]!==z?(W=()=>V?av(z.filter(Nv),V,w.scope?.revision):[],t[35]=V,t[36]=w.scope?.revision,t[37]=z,t[38]=W):W=t[38],w.scope?.revision;let ee;t[39]===W?ee=t[40]:(ee=W(),t[39]=W,t[40]=ee);let te=ee,ne;t[41]!==te||t[42]!==U?(ne=[...U,...te],t[41]=te,t[42]=U,t[43]=ne):ne=t[43];let re=ne,G;t[44]===o?G=t[45]:(G=e=>Ev(e,o),t[44]=o,t[45]=G);let ie=Mt(G);Z.useSyncExternalStore(Hr,ci,ci);let ae;t[46]!==re||t[47]!==ie||t[48]!==w.items||t[49]!==w.mode?(ae=w.mode===`server`?cv(w.items,re):ie,t[46]=re,t[47]=ie,t[48]=w.items,t[49]=w.mode,t[50]=ae):ae=t[50];let oe=ae,se;t[51]!==oe||t[52]!==h?(se=h.length===0?oe:[...oe,...h],t[51]=oe,t[52]=h,t[53]=se):se=t[53];let ce=se,le;t[54]!==o?.sessionID||t[55]!==ce?(le=()=>{let e=o?.sessionID,t=new Set;if(!e)return t;for(let n of ce){let r=n.queueItemID||n.id;r&&_i(e,r)&&t.add(r)}return t},t[54]=o?.sessionID,t[55]=ce,t[56]=le):le=t[56],o?.sessionID;let ue;t[57]===le?ue=t[58]:(ue=le(),t[57]=le,t[58]=ue);let de=ue,fe;if(t[59]!==re){fe=new Map;for(let e of re){let t=fe.get(e.queueItemID)??new Set;t.add(e.kind),fe.set(e.queueItemID,t)}t[59]=re,t[60]=fe}else fe=t[60];let pe=fe,me;if(t[61]!==re||t[62]!==ce||t[63]!==w.mode){bb2:{let e=new Set;if(w.mode===`server`){for(let t of re)t.kind===`send`&&e.add(t.queueItemID);for(let t of ce){if(Go(t))continue;let n=t.queueItemID;n&&ev(t)&&e.add(n)}me=e;break bb2}for(let t of ce){if(Go(t))continue;let n=t;$_(n)&&e.add(n.queueItemID||n.id)}me=e}t[61]=re,t[62]=ce,t[63]=w.mode,t[64]=me}else me=t[64];let he=me,[ge,_e]=Z.useState(Pv),ve;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(ve=new Map,t[65]=ve):ve=t[65];let ye=Z.useRef(ve),be,xe;t[66]!==he||t[67]!==ge?(be=()=>{let e=ye.current,t=Date.now();for(let t of[...e.keys()])he.has(t)||e.delete(t);_e(e=>{let t=!1,n=new Set;for(let r of e)he.has(r)?n.add(r):t=!0;return t?n:e});let n=[];for(let r of he){if(e.has(r)||(e.set(r,t),_e(e=>{if(!e.has(r))return e;let t=new Set(e);return t.delete(r),t})),ge.has(r))continue;let i=nv-(t-(e.get(r)??t));if(i<=0){_e(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t});continue}n.push(setTimeout(()=>{ye.current.has(r)&&_e(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t})},i))}return()=>{for(let e of n)clearTimeout(e)}},xe=[he,ge],t[66]=he,t[67]=ge,t[68]=be,t[69]=xe):(be=t[68],xe=t[69]),Z.useEffect(be,xe);let Se;t[70]===w.mode?Se=t[71]:(Se=W_(w.mode),t[70]=w.mode,t[71]=Se);let Ce=!Se,we=zr(o),Te;t[72]!==we||t[73]!==ce||t[74]!==w.mode?(Te=w.mode===`server`?!1:we||ce.some(Fv),t[72]=we,t[73]=ce,t[74]=w.mode,t[75]=Te):Te=t[75];let Ee=Te,De=Mt(Iv),Oe;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={activationConstraint:{distance:8}},t[76]=Oe):Oe=t[76];let ke;t[77]===Symbol.for(`react.memo_cache_sentinel`)?(ke={activationConstraint:{delay:200,tolerance:6}},t[77]=ke):ke=t[77];let Ae=ad(Qu(rd,Oe),Qu(ed,ke)),je;t[78]!==Ce||t[79]!==o||t[80]!==ce||t[81]!==De||t[82]!==F||t[83]!==w.actions||t[84]!==w.mode||t[85]!==w.scope?(je=e=>{if(Ce)return;let{active:t,over:n}=e;if(!n||t.id===n.id)return;if(w.mode===`server`){if(!o||!w.scope)return;let e=ce,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||Go(r)||Go(i)||Q_(r)||Q_(i))return;let a=w.scope,s=w.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=Ct(),l=dv(a,String(t.id),String(n.id),c,e);if(!l)return;F.mutateAsync({kind:`reorder`,transportIdentity:s.transportIdentity,directory:a.directory,sessionID:a.sessionID,scopeID:a.scopeID,queueItemID:String(t.id),queueItemIDs:l.queueItemIDs,requestID:c,runtime:s,runtimeGeneration:s.generation,input:l}).catch(Lv);return}let r=ce.filter(Rv),i=r.find(e=>(e.queueItemID??e.id)===t.id),a=r.find(e=>(e.queueItemID??e.id)===n.id);if(!i||!a||!o)return;let s=Dv(i,o),c=Dv(a,o);!s||!c||Ot(s)!==Ot(c)||De(s,String(t.id),String(n.id),i.operationID)},t[78]=Ce,t[79]=o,t[80]=ce,t[81]=De,t[82]=F,t[83]=w.actions,t[84]=w.mode,t[85]=w.scope,t[86]=je):je=t[86];let Me=J(je),Ne=Z.useRef(!0),Pe,Fe;t[87]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=()=>(Ne.current=!0,()=>{Ne.current=!1}),Fe=[],t[87]=Pe,t[88]=Fe):(Pe=t[87],Fe=t[88]),Z.useEffect(Pe,Fe);let Ie;t[89]!==s||t[90]!==Ce||t[91]!==o?.directory||t[92]!==o?.runtimeGeneration||t[93]!==o?.sessionID||t[94]!==o?.transportIdentity?(Ie=(e,t)=>Ne.current&&!Ce&&o?.transportIdentity===e.transportIdentity&&o?.runtimeGeneration===e.runtimeGeneration&&o?.sessionID===e.sessionID&&o?.directory===e.directory&&!!(s&&gn(s.key)===gn(t)),t[89]=s,t[90]=Ce,t[91]=o?.directory,t[92]=o?.runtimeGeneration,t[93]=o?.sessionID,t[94]=o?.transportIdentity,t[95]=Ie):Ie=t[95];let Le=J(Ie),Re;t[96]!==a||t[97]!==s||t[98]!==Ce||t[99]!==Le||t[100]!==i||t[101]!==n||t[102]!==o||t[103]!==F||t[104]!==w.actions||t[105]!==w.mode||t[106]!==w.scope||t[107]!==v?(Re=e=>{if(Ce||Go(e))return;if(Ue(e)){if(!o||!s||e.delivery!==`queue`)return;let t=o,n=s.key;return c_({sessionID:t.sessionID,inboxID:e.queueItemID,directory:t.directory,targetKey:n,expectedRevision:s.expectedRevision(),runtimeGeneration:t.runtimeGeneration,isCurrent:()=>Le(t,n)}).then(e=>{e&&Le(t,n)&&i?.()}).catch(()=>{ji.error(v(`chat.chatInput.toast.messageSendFailed`))})}if(w.mode===`server`){if(!o||!w.scope||!a||!s)return;let t=e,n=s.expectedRevision(),r=w.scope,c=w.actions.captureRuntime();if(c.transportIdentity!==o.transportIdentity||c.generation!==o.runtimeGeneration)return;F.mutateAsync({kind:`edit`,transportIdentity:c.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:Ct(),runtime:c,runtimeGeneration:c.generation,input:uv(r,t,s.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(zv);return}if(!o)return;let t=e,r=Dv(t,o);if(!r)return;let c=t.queueItemID??t.id,l=t.operationID,u=q_(t);(async()=>{let e;try{e=await Promise.resolve(n(u.content,u.attachments,u.composerDocument,u.composerMentions))}catch{e=!1}e&&(i?.(),Mt.getState().removeFromQueue(r,c,l))})()},t[96]=a,t[97]=s,t[98]=Ce,t[99]=Le,t[100]=i,t[101]=n,t[102]=o,t[103]=F,t[104]=w.actions,t[105]=w.mode,t[106]=w.scope,t[107]=v,t[108]=Re):Re=t[108];let ze=J(Re),Be;t[109]!==g||t[110]!==Ce||t[111]!==r||t[112]!==u||t[113]!==o||t[114]!==F||t[115]!==w.actions||t[116]!==w.mode||t[117]!==w.scope?(Be=e=>{if(Ue(e))return g?void 0:u?.(e.queueItemID);if(Ce||Go(e))return;if(w.mode===`server`){if(!o||!w.scope)return;let t=e,n=w.scope,r=w.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=t.queueItemID;ye.current.delete(i),_e(e=>{if(!e.has(i))return e;let t=new Set(e);return t.delete(i),t});let a=Ct();F.mutateAsync({kind:`send`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:a,runtime:r,runtimeGeneration:r.generation,input:lv(n,t,a)}).catch(Bv);return}if(!o)return;let t=e;if(!Dv(t,o))return;let n=t.queueItemID??t.id;ye.current.delete(n),_e(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t}),r(n)},t[109]=g,t[110]=Ce,t[111]=r,t[112]=u,t[113]=o,t[114]=F,t[115]=w.actions,t[116]=w.mode,t[117]=w.scope,t[118]=Be):Be=t[118];let Ve=J(Be),He;t[119]!==g||t[120]!==d?(He=e=>{g||Ue(e)&&d?.(e.queueItemID)},t[119]=g,t[120]=d,t[121]=He):He=t[121];let We=J(He),Ge;t[122]!==h||t[123]!==Ce||t[124]!==l||t[125]!==o||t[126]!==F||t[127]!==w.actions||t[128]!==w.mode||t[129]!==w.scope?(Ge=e=>{if(Ue(e)){l?.(e.requestID);return}if(Go(e)){h.some(t=>t.requestID===e.requestID)&&l?.(e.requestID);return}if(Ce)return;if(w.mode===`server`){if(!o||!w.scope)return;let t=e,n=w.scope,r=w.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=Ct();F.mutateAsync({kind:`remove`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:i,runtime:r,runtimeGeneration:r.generation,input:lv(n,t,i)}).catch(Vv);return}if(!o)return;let t=e,n=Dv(t,o);n&&Mt.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[122]=h,t[123]=Ce,t[124]=l,t[125]=o,t[126]=F,t[127]=w.actions,t[128]=w.mode,t[129]=w.scope,t[130]=Ge):Ge=t[130];let Ke=J(Ge),qe=ce.length>0&&(o||h.length>0);if(!qe&&!m)return null;let Je=y?`px-2`:`px-4`,Ye;t[131]===Je?Ye=t[132]:(Ye=Y(`yuri-composer-queue relative z-0 -mb-5 w-full`,Je),t[131]=Je,t[132]=Ye);let Xe=y?`rounded-[1.25rem]`:`rounded-3xl`,Ze;t[133]===Xe?Ze=t[134]:(Ze=Y(`overflow-hidden border border-[color-mix(in_srgb,var(--interactive-border)_50%,transparent)] bg-[var(--surface-background)] text-foreground dark:border-transparent dark:bg-[color-mix(in_srgb,var(--surface-background),var(--surface-foreground)_4%)]`,Xe),t[133]=Xe,t[134]=Ze);let Qe=y?`px-1.5 py-1`:`gap-0.5 px-3 py-1`,$e;t[135]===Qe?$e=t[136]:($e=Y(`flex flex-col`,Qe),t[135]=Qe,t[136]=$e);let et;t[137]!==de||t[138]!==g||t[139]!==s||t[140]!==Ce||t[141]!==Me||t[142]!==ze||t[143]!==We||t[144]!==Ke||t[145]!==Ve||t[146]!==Ee||t[147]!==qe||t[148]!==y||t[149]!==pe||t[150]!==o||t[151]!==ce||t[152]!==ge||t[153]!==Ae||t[154]!==w.mode||t[155]!==_?(et=qe?(0,$.jsx)(id,{sensors:Ae,collisionDetection:nd,onDragEnd:Me,children:(0,$.jsx)(dd,{items:ce.map(Hv),strategy:ud,children:ce.map(e=>{let t=e.queueItemID||e.id;return(0,$.jsx)(yv,{message:e,server:w.mode===`server`,frozen:Ce,hasDispatchLock:Ee,pendingOperationKinds:pe.get(t)??Cv,sendPendingTimedOut:ge.has(t),abortSendPending:de.has(t),steering:_.has(t)||!!(e.messageID&&_.has(e.messageID)),isMobile:y,inboxEditable:!!(o&&s),onEdit:ze,onSend:Ve,onQueue:We,onRemove:Ke,compactionBarrier:g},t)})})}):null,t[137]=de,t[138]=g,t[139]=s,t[140]=Ce,t[141]=Me,t[142]=ze,t[143]=We,t[144]=Ke,t[145]=Ve,t[146]=Ee,t[147]=qe,t[148]=y,t[149]=pe,t[150]=o,t[151]=ce,t[152]=ge,t[153]=Ae,t[154]=w.mode,t[155]=_,t[156]=et):et=t[156];let tt;t[157]!==qe||t[158]!==m?(tt=m?(0,$.jsxs)($.Fragment,{children:[qe?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,m]}):null,t[157]=qe,t[158]=m,t[159]=tt):tt=t[159];let nt;t[160]!==$e||t[161]!==et||t[162]!==tt?(nt=(0,$.jsxs)(`div`,{"data-yuri-queue-card-body":``,className:$e,children:[et,tt]}),t[160]=$e,t[161]=et,t[162]=tt,t[163]=nt):nt=t[163];let rt=y?`h-4`:`h-5`,it;t[164]===rt?it=t[165]:(it=(0,$.jsx)(`div`,{"data-yuri-queue-composer-overlap":``,"aria-hidden":`true`,className:rt}),t[164]=rt,t[165]=it);let at;t[166]!==Ze||t[167]!==nt||t[168]!==it?(at=(0,$.jsxs)(`div`,{"data-yuri-queue-card":``,className:Ze,children:[nt,it]}),t[166]=Ze,t[167]=nt,t[168]=it,t[169]=at):at=t[169];let ot;return t[170]!==Ye||t[171]!==at?(ot=(0,$.jsx)(`div`,{className:Ye,children:at}),t[170]=Ye,t[171]=at,t[172]=ot):ot=t[172],ot});Ov.displayName=`QueuedMessageChips`;function kv(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(H_,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Av(e){return e.isMobile}function jv(e){return e.state.variables}function Mv(e){let t=e.state.variables;if(!vv(t)||t.kind!==`send`)return;let n=e.state.data;if(!n||n.status!==`committed`)return;let r=`committedRevision`in n&&typeof n.committedRevision==`number`&&Number.isSafeInteger(n.committedRevision)?n.committedRevision:void 0,i=`scope`in n&&n.scope&&typeof n.scope.revision==`number`&&Number.isSafeInteger(n.scope.revision)?n.scope.revision:void 0,a=r??i;if(!(a===void 0||a<=0))return{...t,kind:`send`,committedRevision:a}}function Nv(e){return e!==void 0}function Pv(){return new Set}function Fv(e){return!Go(e)&&(e.status===`sending`||e.status===`reconciling`)}function Iv(e){return e.reorderQueue}function Lv(){}function Rv(e){return!Go(e)}function zv(){}function Bv(){}function Vv(){}function Hv(e){return e.queueItemID||e.id}function Uv(e){let t=(0,Q.c)(21),{presentation:n}=e,{text:r,icon:i,variant:a,rawMessage:o,detail:s}=n,c=a===`error`?`alert`:`status`,l;t[0]===i?l=t[1]:(l=(0,$.jsx)(`span`,{className:`inline-flex h-5 shrink-0 items-center`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:i,className:`size-3.5`})}),t[0]=i,t[1]=l);let u;t[2]!==s||t[3]!==o||t[4]!==r?(u=[r,s,o].filter(Boolean),t[2]=s,t[3]=o,t[4]=r,t[5]=u):u=t[5];let d=u.join(` · `),f;t[6]===s?f=t[7]:(f=s?(0,$.jsx)(`span`,{className:`ml-1.5 text-muted-foreground/60`,children:s}):null,t[6]=s,t[7]=f);let p;t[8]!==o||t[9]!==r?(p=o&&o!==r?(0,$.jsx)(`span`,{className:`ml-1.5 text-muted-foreground/80`,children:o}):null,t[8]=o,t[9]=r,t[10]=p):p=t[10];let m;t[11]!==d||t[12]!==f||t[13]!==p||t[14]!==r?(m=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,title:d,children:[r,f,p]}),t[11]=d,t[12]=f,t[13]=p,t[14]=r,t[15]=m):m=t[15];let h;return t[16]!==c||t[17]!==l||t[18]!==m||t[19]!==a?(h=(0,$.jsxs)(`div`,{role:c,"data-response-status":a,className:`flex w-full min-w-0 items-start gap-1.5 typography-meta leading-5 text-muted-foreground`,children:[l,m]}),t[16]=c,t[17]=l,t[18]=m,t[19]=a,t[20]=h):h=t[20],h}function Wv(e){let t=(0,Q.c)(7),{sessionId:n,directory:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={bootstrap:!1},t[0]=i):i=t[0];let a=qi(r,i),o;t[1]===n?o=t[2]:(o=e=>e.session_execution_recovery[n]?.reason===`shutdown`,t[1]=n,t[2]=o);let s=z(a,o),{t:c}=Xn();if(!s)return null;let l;t[3]===c?l=t[4]:(l=c(`chat.sessionRecovery.awaitingConfirmation`),t[3]=c,t[4]=l);let u;return t[5]===l?u=t[6]:(u=(0,$.jsx)(`div`,{className:`px-4 py-1.5`,"aria-live":`polite`,children:(0,$.jsx)(Uv,{presentation:{text:l,icon:`restart`,variant:`info`}})}),t[5]=l,t[6]=u),u}var Gv=[0,200,400],Kv=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=Gv.map(qv),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 qv(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var Jv=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=Xn(),n=wa(Yv),r;e[0]===n?r=e[1]:(r=e=>{if(!n)return null;let t=e.runsByOriginalSessionID[n]??null;return t?.runtimeKey===u()?t:null},e[0]=n,e[1]=r);let i=Ta(r),a=Ta(Xv),o=K(Zv),s=K(Qv);if(!n||!i||i.status!==`running`)return null;let c;e[2]!==i.phase||e[3]!==t?(c=i.phase===`waiting_for_reviewer`?t(`chat.autoReview.status.waitingForReviewer`):t(`chat.autoReview.status.waitingForImplementer`),e[2]=i.phase,e[3]=t,e[4]=c):c=e[4];let l=c,d;e[5]!==o||e[6]!==i.directory||e[7]!==i.reviewSessionID||e[8]!==t?(d=()=>{o(i.directory,{mode:`chat`,dedupeKey:`session:${i.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=o,e[6]=i.directory,e[7]=i.reviewSessionID,e[8]=t,e[9]=d):d=e[9];let f=d,p=s?`pb-1 text-xs`:`pb-2`,m;e[10]===p?m=e[11]:(m=Y(`w-full px-1`,p),e[10]=p,e[11]=m);let h=s?`rounded-lg`:`rounded-xl`,g;e[12]===h?g=e[13]:(g=Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,h),e[12]=h,e[13]=g);let _=s?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`,v;e[14]===_?v=e[15]:(v=Y(`flex w-full items-center text-left`,_),e[14]=_,e[15]=v);let y=s?`size-3.5`:`size-4`,b;e[16]===y?b=e[17]:(b=Y(`animate-spin text-muted-foreground`,y),e[16]=y,e[17]=b);let x;e[18]===b?x=e[19]:(x=(0,$.jsx)(X,{name:`loader-4`,className:b,"aria-hidden":`true`}),e[18]=b,e[19]=x);let S;e[20]===t?S=e[21]:(S=t(`chat.autoReview.title`),e[20]=t,e[21]=S);let C;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Kv,{}),e[22]=C):C=e[22];let w;e[23]===S?w=e[24]:(w=(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:[S,C]}),e[23]=S,e[24]=w);let T;e[25]===l?T=e[26]:(T=(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:l}),e[25]=l,e[26]=T);let E;e[27]!==w||e[28]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[w,T]}),e[27]=w,e[28]=T,e[29]=E):E=e[29];let D;e[30]===t?D=e[31]:(D=t(`chat.autoReview.actions.open`),e[30]=t,e[31]=D);let O;e[32]!==f||e[33]!==D?(O=(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`xs`,onClick:f,children:D}),e[32]=f,e[33]=D,e[34]=O):O=e[34];let k;e[35]!==n||e[36]!==a?(k=()=>a(n),e[35]=n,e[36]=a,e[37]=k):k=e[37];let A;e[38]===t?A=e[39]:(A=t(`chat.autoReview.actions.stop`),e[38]=t,e[39]=A);let j;e[40]!==k||e[41]!==A?(j=(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`xs`,onClick:k,children:A}),e[40]=k,e[41]=A,e[42]=j):j=e[42];let M;e[43]!==x||e[44]!==E||e[45]!==O||e[46]!==j||e[47]!==v?(M=(0,$.jsxs)(`div`,{className:v,children:[x,E,O,j]}),e[43]=x,e[44]=E,e[45]=O,e[46]=j,e[47]=v,e[48]=M):M=e[48];let N;e[49]!==M||e[50]!==g?(N=(0,$.jsx)(`div`,{className:g,children:M}),e[49]=M,e[50]=g,e[51]=N):N=e[51];let P;return e[52]!==N||e[53]!==m?(P=(0,$.jsx)(`div`,{className:m,children:N}),e[52]=N,e[53]=m,e[54]=P):P=e[54],P});Jv.displayName=`AutoReviewBanner`;function Yv(e){return e.currentSessionId}function Xv(e){return e.stopRun}function Zv(e){return e.openContextPanelTab}function Qv(e){return e.isMobile}function $v(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`pointer-events-none inline-flex h-5 min-w-5 shrink-0 select-none items-center justify-center`,`rounded-md border border-[var(--interactive-border)] bg-[var(--surface-muted)]`,`px-1.5 font-mono typography-micro font-medium leading-none normal-case`,`text-[var(--surface-muted-foreground)] whitespace-nowrap`,`shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.12)]`,`dark:shadow-[inset_0_-1px_0_0_rgba(255,255,255,0.08)]`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`kbd`,{"data-slot":`kbd`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function ey(e){let t=(0,Q.c)(15),{shortcut:n,className:r,tone:i}=e,a=i===void 0?`default`:i,o,s,c,l;if(t[0]!==r||t[1]!==n||t[2]!==a){l=Symbol.for(`react.early_return_sentinel`);bb0:{let e=n.split(`+`).map(ty).filter(Boolean);if(e.length===0){l=null;break bb0}o=`shortcut-kbd`,t[7]===r?s=t[8]:(s=Y(`inline-flex items-center gap-1 whitespace-nowrap normal-case`,r),t[7]=r,t[8]=s);let i;t[9]===a?i=t[10]:(i=(e,t)=>(0,$.jsxs)(Z.Fragment,{children:[t>0?(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-[var(--surface-muted-foreground)]`,children:`+`}):null,(0,$.jsx)($v,{className:Y(a===`selection`&&`border-[var(--interactive-selection)] bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`),children:/^[a-z]$/i.test(e)?e.toUpperCase():e})]},`${e}-${t}`),t[9]=a,t[10]=i),c=e.map(i)}t[0]=r,t[1]=n,t[2]=a,t[3]=o,t[4]=s,t[5]=c,t[6]=l}else o=t[3],s=t[4],c=t[5],l=t[6];if(l!==Symbol.for(`react.early_return_sentinel`))return l;let u;return t[11]!==o||t[12]!==s||t[13]!==c?(u=(0,$.jsx)(`span`,{"data-slot":o,className:s,children:c}),t[11]=o,t[12]=s,t[13]=c,t[14]=u):u=t[14],u}function ty(e){return e.trim()}var ny=e=>e===`full`||e===`allow`?{text:`var(--status-info)`,border:`color-mix(in srgb, var(--status-info) 25%, transparent)`,background:`color-mix(in srgb, var(--status-info) 4%, transparent)`,borderWidth:1.5}:null,ry=1e3,iy=e=>{let t=(0,Q.c)(27),{name:n,label:r,revealed:i,avatarSize:a,slotClassName:o,labelGapClassName:s,colorVar:c}=e,l=s===void 0?`pl-1.5 pr-0.5`:s,u;t[0]===o?u=t[1]:(u=Y(`inline-flex shrink-0 items-center justify-center`,o),t[0]=o,t[1]=u);let d=i?void 0:r,f;t[2]!==a||t[3]!==n||t[4]!==d?(f=(0,$.jsx)(ds,{name:n,size:a,label:d}),t[2]=a,t[3]=n,t[4]=d,t[5]=f):f=t[5];let p;t[6]!==u||t[7]!==f?(p=(0,$.jsx)(`span`,{className:u,children:f}),t[6]=u,t[7]=f,t[8]=p):p=t[8];let m=i?`grid-cols-[1fr] opacity-100`:`grid-cols-[0fr] opacity-0`,h;t[9]===m?h=t[10]:(h=Y(`grid min-w-0 items-center ease-in-out`,m),t[9]=m,t[10]=h);let g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(g={transitionProperty:`grid-template-columns, opacity`,transitionDuration:`280ms`,transitionTimingFunction:`ease-in-out`},t[11]=g):g=t[11];let _=!i,v;t[12]===l?v=t[13]:(v=Y(`inline-block whitespace-nowrap typography-micro leading-none font-medium`,l),t[12]=l,t[13]=v);let y;t[14]===c?y=t[15]:(y=c?{color:`var(${c})`}:void 0,t[14]=c,t[15]=y);let b;t[16]!==r||t[17]!==v||t[18]!==y?(b=(0,$.jsx)(`span`,{className:`flex min-w-0 items-center overflow-hidden`,children:(0,$.jsx)(`span`,{className:v,style:y,children:r})}),t[16]=r,t[17]=v,t[18]=y,t[19]=b):b=t[19];let x;t[20]!==b||t[21]!==h||t[22]!==_?(x=(0,$.jsx)(`span`,{className:h,style:g,"aria-hidden":_,children:b}),t[20]=b,t[21]=h,t[22]=_,t[23]=x):x=t[23];let S;return t[24]!==x||t[25]!==p?(S=(0,$.jsxs)($.Fragment,{children:[p,x]}),t[24]=x,t[25]=p,t[26]=S):S=t[26],S};function ay(e){let t=(0,Q.c)(5),[n,r]=Z.useState(!1),i=Z.useRef(void 0),a=Z.useRef(!1),o=Z.useRef(null),s,c;t[0]===e?(s=t[1],c=t[2]):(s=()=>{if(!a.current){a.current=!0,i.current=e;return}if(e===i.current)return;let t=i.current;if(i.current=e,!t||!e){r(!1);return}return r(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{r(!1),o.current=null},ry),()=>{o.current&&=(clearTimeout(o.current),null)}},c=[e],t[0]=e,t[1]=s,t[2]=c),Z.useEffect(s,c);let l,u;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>()=>{o.current&&clearTimeout(o.current)},u=[],t[3]=l,t[4]=u):(l=t[3],u=t[4]),Z.useEffect(l,u),n}var oy=`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,sy=e=>`flow-root ${e?`py-1`:`py-1.5`}`,cy=e=>`relative ml-2 flex flex-col pl-3 ${e?`gap-1 pt-1`:`gap-1.5 pt-1.5`}`,ly=`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,uy=`${oy} ${ly}`,dy=`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] data-[popup-open]:!bg-[color-mix(in_srgb,var(--surface-foreground)_10%,transparent)] data-[state=open]:!bg-[color-mix(in_srgb,var(--surface-foreground)_10%,transparent)]`,fy=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${dy}`,py=`rounded-md ${dy}`,my=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},hy=e=>{if(e)try{let t=my();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},gy=(e,t)=>{if(!e||e.length===0)return`ask`;for(let n=e.length-1;n>=0;--n){let r=e[n];if(r.permission===t&&r.pattern===`*`)return r.action}for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.permission===`*`&&n.pattern===`*`)return n.action}return`ask`},_y=e=>{let t=hy(e);return t?gy(t.permission,`edit`):`ask`},vy=e=>{if(!e||typeof e!=`object`)return 0;let t=e.input??0,n=e.output??0,r=e.reasoning??0,i=e.cache&&typeof e.cache==`object`?e.cache.read??0:0,a=e.cache&&typeof e.cache==`object`?e.cache.write??0:0;return t+n+r+i+a},yy=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return vy(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:vy(n.tokens)},by=e=>{if(!e||typeof e!=`object`)return{percent:0,hasInput:!1};let t=e.input??0,n=e.cache&&typeof e.cache==`object`?e.cache.read??0:0,r=e.cache&&typeof e.cache==`object`?e.cache.write??0:0,i=t+n+r;return i<=0?{percent:0,hasInput:!1}:{percent:Math.min(100,Math.max(0,Math.max(0,n)/i*100)),hasInput:!0}},xy=(e,t,n)=>{let r=Number.isFinite(t)?Math.max(t,0):0,i=Number.isFinite(n)&&n>0,a=i?Math.max(n,0):0,o=Math.min(Math.min(i?a:32e3,32e3),r),s=r>0?Math.max(r-o,1):0,c=s>0?e/s*100:0;return{percentage:Math.min(c,100),contextLimit:r,outputLimit:a,thresholdLimit:s||1,normalizedOutput:o}},Sy=[`ask`,`allow`,`full`],Cy=`__global__`,wy=L()(B(R((e,t)=>({sessionModelSelections:new Map,sessionAgentSelections:new Map,sessionAgentModelSelections:new Map,sessionAgentModelVariantSelections:new Map,currentAgentContext:new Map,sessionContextUsage:new Map,sessionAgentEditModes:new Map,hasHydrated:typeof window>`u`,saveSessionModelSelection:(t,n,r)=>{e(e=>{let i=new Map(e.sessionModelSelections);return i.set(t,{providerId:n,modelId:r}),{sessionModelSelections:i}})},getSessionModelSelection:e=>{let{sessionModelSelections:n}=t();return n.get(e)||null},saveSessionAgentSelection:(t,n)=>{e(e=>{let r=new Map(e.sessionAgentSelections);r.set(t,n);let i=new Map(e.currentAgentContext);return i.set(t,n),{sessionAgentSelections:r,currentAgentContext:i}})},getSessionAgentSelection:e=>{let{sessionAgentSelections:n}=t();return n.get(e)||null},saveAgentModelForSession:(t,n,r,i)=>{e(e=>{let a=new Map(e.sessionAgentModelSelections),o=a.get(t);return o=o?new Map(o):new Map,o.set(n,{providerId:r,modelId:i}),a.set(t,o),{sessionAgentModelSelections:a}})},getAgentModelForSession:(e,n)=>{let{sessionAgentModelSelections:r}=t(),i=r.get(e);return i&&i.get(n)||null},saveAgentModelVariantForSession:(t,n,r,i,a)=>{e(e=>{let o=new Map(e.sessionAgentModelVariantSelections),s=o.get(t);s=s?new Map(s):new Map;let c=s.get(n);c=c?new Map(c):new Map;let l=`${r}/${i}`;return a===void 0?(c.delete(l),c.size===0?(s.delete(n),s.size===0?o.delete(t):o.set(t,s)):(s.set(n,c),o.set(t,s))):(c.set(l,a),s.set(n,c),o.set(t,s)),{sessionAgentModelVariantSelections:o}})},getAgentModelVariantForSession:(e,n,r,i)=>{let{sessionAgentModelVariantSelections:a}=t(),o=a.get(e);if(!o)return;let s=o.get(n);if(s)return s.get(`${r}/${i}`)},getContextUsage:(n,r,i,a)=>{if(!n)return null;let o=xy(0,r,i),s=o.contextLimit,c=o.normalizedOutput??0,l=o.thresholdLimit;if(s===0||l===0)return null;let u=(a.get(n)||[]).filter(e=>e.info.role===`assistant`);if(u.length===0)return null;let d=u[u.length-1],f=d.info.id,p=t=>{let r=()=>{e(e=>{let r=e.sessionContextUsage.get(n);if(r&&r.totalTokens===t.totalTokens&&r.percentage===t.percentage&&r.contextLimit===t.contextLimit&&(r.outputLimit??0)===(t.outputLimit??0)&&(r.normalizedOutput??0)===(t.normalizedOutput??0)&&r.thresholdLimit===t.thresholdLimit&&r.lastMessageId===t.lastMessageId)return e;let i=new Map(e.sessionContextUsage);return i.set(n,t),{sessionContextUsage:i}})};typeof queueMicrotask==`function`?queueMicrotask(r):typeof window<`u`?window.setTimeout(r,0):setTimeout(r,0)},m=t().sessionContextUsage.get(n);if(m&&m.lastMessageId===f){let e=m.normalizedOutput??m.outputLimit??0,t=m.contextLimit!==s||e!==c||m.thresholdLimit!==l;if(t&&m.totalTokens>0){let e=m.totalTokens/l*100,t={totalTokens:m.totalTokens,percentage:Math.min(e,100),contextLimit:s,outputLimit:o.outputLimit,normalizedOutput:c,thresholdLimit:l,lastMessageId:f};return p(t),t}if(!t&&m.totalTokens>0)return m}let h=yy(d);if(h===0)return m||null;let g=xy(h,r,i),_={totalTokens:h,percentage:g.percentage,contextLimit:g.contextLimit,outputLimit:g.outputLimit,normalizedOutput:g.normalizedOutput,thresholdLimit:g.thresholdLimit,lastMessageId:f};return p(_),_},updateSessionContextUsage:(t,n,r,i)=>{let a=(i.get(t)||[]).filter(e=>e.info.role===`assistant`);if(a.length===0)return;let o=a[a.length-1],s=yy(o);if(s===0)return;let c=xy(s,n,r);e(e=>{let n=new Map(e.sessionContextUsage);return n.set(t,{totalTokens:s,percentage:c.percentage,contextLimit:c.contextLimit,outputLimit:c.outputLimit,normalizedOutput:c.normalizedOutput,thresholdLimit:c.thresholdLimit,lastMessageId:o.info.id}),{sessionContextUsage:n}})},initializeSessionContextUsage:(e,n,r,i)=>{let a=t().sessionContextUsage.get(e);(!a||a.totalTokens===0)&&t().updateSessionContextUsage(e,n,r,i)},pollForTokenUpdates:(e,n,r,i=10)=>{let a=0,o=()=>{a++;let s=(r.get(e)||[]).find(e=>e.info.id===n);if(s&&s.info.role===`assistant`&&yy(s)>0){t().updateSessionContextUsage(e,0,0,r);return}a<i&&setTimeout(o,1e3)};setTimeout(o,2e3)},getCurrentAgent:e=>{let{currentAgentContext:n}=t();return n.get(e)},getSessionAgentEditMode:(e,n,r=_y(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Cy){let e=t().sessionAgentEditModes.get(Cy)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=_y(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Sy.includes(r)&&e(e=>{let i=new Map(e.sessionAgentEditModes),o=new Map(i.get(t)??new Map);return r===a?(o.delete(n),o.size===0?i.delete(t):i.set(t,o)):(o.set(n,r),i.set(t,o)),{sessionAgentEditModes:i}})},toggleSessionAgentEditMode:(e,n,r=_y(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Sy.indexOf(a),s=Sy.indexOf(i),c=Sy[((o>=0?o:s>=0?s:0)+1)%Sy.length];t().setSessionAgentEditMode(e,n,c,i)}}),{name:`context-store`,storage:_t(),partialize:e=>({sessionModelSelections:Array.from(e.sessionModelSelections.entries()),sessionAgentSelections:Array.from(e.sessionAgentSelections.entries()),sessionAgentModelSelections:Array.from(e.sessionAgentModelSelections.entries()).map(([e,t])=>[e,Array.from(t.entries())]),sessionAgentModelVariantSelections:Array.from(e.sessionAgentModelVariantSelections.entries()).map(([e,t])=>[e,Array.from(t.entries()).map(([e,t])=>[e,Array.from(t.entries())])]),currentAgentContext:Array.from(e.currentAgentContext.entries()),sessionContextUsage:Array.from(e.sessionContextUsage.entries()),sessionAgentEditModes:Array.from(e.sessionAgentEditModes.entries()).map(([e,t])=>[e,Array.from(t.entries())])}),merge:(e,t)=>{let n=new Map;e?.sessionAgentModelSelections&&e.sessionAgentModelSelections.forEach(([e,t])=>{n.set(e,new Map(t))});let r=new Map;e?.sessionAgentModelVariantSelections&&e.sessionAgentModelVariantSelections.forEach(([e,t])=>{let n=new Map;t.forEach(([e,t])=>{n.set(e,new Map(t))}),r.set(e,n)});let i=new Map;return e?.sessionAgentEditModes&&e.sessionAgentEditModes.forEach(([e,t])=>{i.set(e,new Map(t))}),{...t,...e,sessionModelSelections:new Map(e?.sessionModelSelections||[]),sessionAgentSelections:new Map(e?.sessionAgentSelections||[]),sessionAgentModelSelections:n,sessionAgentModelVariantSelections:r,currentAgentContext:new Map(e?.currentAgentContext||[]),sessionContextUsage:new Map(e?.sessionContextUsage||[]),sessionAgentEditModes:i,hasHydrated:!0}}}),{name:`context-store`})),Ty=e=>is([...e??[]]);function Ey(e,t){return!e&&t===`trigger-hover`}var Dy=(e,t)=>{let n=e.target;n instanceof Element&&e.currentTarget.contains(n)&&(n.closest(`textarea[data-chat-input="true"]`)||n.closest(`[data-chat-prompt-attachments="true"]`)||n.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(t(),e.preventDefault()))},Oy=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},ky=e=>{let t=Oy(e);return t?(t.focus({preventScroll:!0}),!0):!1},Ay=(e,t)=>e&&!t,jy=(e,t)=>{if(!e)return t;let n=e.ready&&!e.loading;return{modelsReady:!e.error&&(e.modelsReady??n),agentsReady:!e.error&&(e.agentsReady??n)}},My=e=>{let t=e?.variants;if(!t)return[];if(Array.isArray(t)){let e=[],n=new Set;for(let r of t){let t=typeof r==`string`?r:r&&typeof r==`object`&&!Array.isArray(r)&&typeof r.id==`string`?r.id:``;!t||n.has(t)||(n.add(t),e.push(t))}return e}return typeof t==`object`?Object.keys(t):[]},Ny=(e,t,n,r)=>{if(e.providerID!==n||e.modelID!==r||t?.variantsReady===!1)return[];if(t?.variants)return[...t.variants];let i=(t?.providers?.find(e=>e.id===n))?.models?.find(e=>e.id===r);return My(i)},Py=()=>!0,Fy=(e,t)=>(e.commandPolicy??Py)(t),Iy=Z.createContext(null),Ly=()=>Z.useContext(Iy),Ry=e=>e,zy=(e,t)=>t??e,By=e=>{if(e.kind!==`primary`&&(!e.sessionID||!e.directory||!e.draftKey||!e.transportIdentity||!Number.isSafeInteger(e.runtimeGeneration)||!e.resources||typeof e.resources.busy!=`boolean`||!e.activity||!e.commands||!e.shortcuts))throw Error(`chat-input-secondary-surface-incomplete`)},Vy=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,Hy=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},Uy=(e,t,n)=>{if(e.kind===`secondary`){if(!e.commands)throw Error(`chat-input-secondary-commands-incomplete`);return e.commands}return e.commands?e.commands:{sessionID:e.sessionID,hasMessages:t,hasNewDraft:n}},Wy=(e,t)=>`${e}:${t}`,Gy=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,Ky=e=>{if(!Array.isArray(e))return null;let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;typeof e.permission==`string`&&typeof e.pattern==`string`&&typeof e.action==`string`&&(e.action===`allow`||e.action===`ask`||e.action===`deny`)&&t.push({permission:e.permission,pattern:e.pattern,action:e.action})}return t},qy=(e,t)=>{let n=Ky(e);if(!(!n||n.length===0)){for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.permission===t&&r.pattern===`*`)return r.action}for(let e=n.length-1;e>=0;--e){let t=n[e];if(t.permission===`*`&&t.pattern===`*`)return t.action}}},Jy=[{key:`tool_call`,icon:`tools`,label:`Tool calling`,isActive:e=>e?.tool_call===!0},{key:`reasoning`,icon:`brain-ai-3`,label:`Reasoning`,isActive:e=>e?.reasoning===!0}],Yy={text:{icon:`text`,label:`Text`},image:{icon:`file-image`,label:`Image`},video:{icon:`file-video`,label:`Video`},audio:{icon:`file-music`,label:`Audio`},pdf:{icon:`file-pdf`,label:`PDF`}},Xy=e=>e.trim().toLowerCase(),Zy=(e,t)=>{let n=t===`input`?e?.modalities?.input:e?.modalities?.output;if(!Array.isArray(n)||n.length===0)return[];let r=Array.from(new Set(n.map(e=>Xy(e)))),i=[];for(let e of r){let t=Yy[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},Qy=e=>_c(e),$y=e=>wc(e),eb=e=>yc(e),tb=`__add_provider__`,nb=e=>{let t=(0,Q.c)(5),{iconName:n,label:r}=e,i;t[0]===n?i=t[1]:(i=(0,$.jsx)(X,{name:n,className:`size-3.5`}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,$.jsx)(`span`,{className:`flex size-5 items-center justify-center rounded-xl bg-muted/60 text-muted-foreground`,title:r,"aria-label":r,role:`img`,children:i}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a},rb=e=>{let t=(0,Q.c)(18),{mode:n,className:r}=e,i;t[0]===r?i=t[1]:(i=Y(r,`flex-shrink-0`),t[0]=r,t[1]=i);let a=i,o;t[2]===n?o=t[3]:(o=ny(n),t[2]=n,t[3]=o);let s=o,c=s?s.text:`var(--foreground)`,l;t[4]===c?l=t[5]:(l={color:c},t[4]=c,t[5]=l);let u=l;if(n===`full`){let e;return t[6]!==a||t[7]!==u?(e=(0,$.jsx)(X,{name:`pencil-ai`,className:a,style:u}),t[6]=a,t[7]=u,t[8]=e):e=t[8],e}if(n===`allow`){let e;return t[9]!==a||t[10]!==u?(e=(0,$.jsx)(X,{name:`checkbox-circle`,className:a,style:u}),t[9]=a,t[10]=u,t[11]=e):e=t[11],e}if(n===`deny`){let e;return t[12]!==a||t[13]!==u?(e=(0,$.jsx)(X,{name:`close-circle`,className:a,style:u}),t[12]=a,t[13]=u,t[14]=e):e=t[14],e}let d;return t[15]!==a||t[16]!==u?(d=(0,$.jsx)(X,{name:`question`,className:a,style:u}),t[15]=a,t[16]=u,t[17]=d):d=t[17],d},ib=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=Qy(e);return t.endsWith(`.0`)?t.slice(0,-2):t},ab=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:$y(e),ob=e=>{let t=[];for(let n of Jy)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},sb=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:eb(t)},cb=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=Xn(),o=Z.useId(),{isReady:s,isUnavailable:c}=Fc(),l=c||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),u=Ko(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),d=Ko(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=i?.catalog,p=jy(f,{modelsReady:!u,agentsReady:!d}),m=s&&p.modelsReady&&!i?.disabled,h=s&&p.agentsReady&&!i?.disabled,g=m&&h,_=Ko(e=>e.providers),v=f?.providers??_,y=Ko(e=>e.currentProviderId),b=Ko(e=>e.currentModelId),x=i?.selection.providerID??y,S=i?.selection.modelID??b,C=Ko(e=>e.currentVariant),w=i?i.selection.variant:C,T=Ko(e=>e.currentAgentName),E=i?i.selection.agent??void 0:T,D=Ko(e=>e.settingsDefaultVariant),O=Ko(e=>e.settingsDefaultAgent),k=Ko(e=>e.setProvider),A=Ko(e=>e.setSelectedProvider),j=Ko(e=>e.setModel),M=Ko(e=>e.setCurrentVariant),N=Ko(e=>e.getCurrentModelVariants),P=Ko(e=>e.setAgent),F=Ko(e=>e.getCurrentProvider),I=Ko(e=>e.getModelMetadata),L=Ko(e=>e.getCurrentAgent),R=Ko(e=>e.getVisibleAgents),z=Ty(f?.agents??R()),B=Z.useMemo(()=>z.filter(e=>e.mode===`primary`),[z]),V=Z.useRef(!1);Z.useEffect(()=>{V.current||!g||(V.current=!0,Ke(`ModelControls:ready`,{providers:v.length,agents:z.length,currentProviderId:x,currentModelId:S,currentAgentName:E}))},[z.length,g,E,S,x,v.length]);let H=wa(e=>i?null:e.currentSessionId),U=wa(e=>e.getDirectoryForSession),W=dh(),ee=ur(e=>e.getSessionModelSelection),te=ur(e=>e.saveSessionModelSelection),ne=ur(e=>e.saveSessionAgentSelection),re=ur(e=>e.saveAgentModelForSession),G=ur(e=>e.getAgentModelForSession),ie=ur(e=>e.saveAgentModelVariantForSession),ae=ur(e=>e.getAgentModelVariantForSession),oe=wy(e=>e.hasHydrated),se=ur(e=>H?e.sessionAgentSelections.get(H)??null:null),ce=Z.useRef(null);Z.useEffect(()=>{if(!H){ce.current=null;return}se&&(ce.current=se)},[H,se]);let le=H?ce.current:null,ue=i?i.selection.agent??void 0:H&&(se||le)||E,de=K(e=>e.toggleFavoriteModel),fe=K(e=>e.reorderFavoriteModel),pe=K(e=>e.providerOrder),me=K(e=>e.setProviderOrder),he=K(e=>e.isFavoriteModel),ge=K(e=>e.addRecentModel),_e=K(e=>e.addRecentAgent),ve=K(e=>e.addRecentEffort),ye=K(e=>e.isModelSelectorOpen),be=K(e=>e.setModelSelectorOpen),xe=K(e=>e.isAgentSelectorOpen),Se=K(e=>e.setAgentSelectorOpen),Ce=K(e=>e.isModelSelectorInstant),we=K(e=>e.isAgentSelectorInstant),Te=K(e=>e.setSettingsDialogOpen),Ee=K(e=>e.setSettingsPage),De=K(e=>e.hiddenModels),Oe=K(e=>e.shortcutOverrides.cycle_agent),ke=Z.useMemo(()=>Ec(`cycle_agent`,Oe?{cycle_agent:Oe}:void 0),[Oe]),{favoriteModelsList:Ae,recentModelsList:je}=Ds({currentProviderID:x,currentModelID:S}),{isMobile:Me}=Kc(),Ne=K(e=>e.isMobile),Pe=Me||Ne,Fe=Dn(),Ie=Pe,[Le,Re]=Z.useState(null),ze=n!==void 0&&typeof r==`function`,Be=ze?n:Le,Ve=ze?r:Re,He=J(e=>{Ve(e),Ko.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),Ue=J((e,t)=>{if(Ey(e,t?.reason)){t?.cancel?.();return}Se(e),e&&Ko.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopAgentMenu`})}),[We,Ge]=Z.useState(null),qe=Z.useRef(!1),Je=Z.useCallback(()=>Ve(null),[Ve]),Ye=Z.useCallback(()=>Ge(null),[]),Xe=Z.useRef(void 0),Ze=ye,Qe=be,$e=Z.useCallback(()=>{A(tb),Ee(`providers`),Te(!0),Qe(!1),Je()},[A,Ee,Te,Qe,Je]),[et,tt]=Z.useState(``),[nt,rt]=Z.useState(null),[it,at]=Z.useState(!1),ot=Z.useRef(0),st=J((e,t)=>{if(Ey(e,t?.reason)){t?.cancel?.();return}at(!1),e||(ot.current=performance.now()+200,rt(null),tt(``)),Qe(e),e&&Ko.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),ct=Z.useRef(!1),lt=Z.useRef(null),ut=Z.useRef(void 0),[dt,ft]=Z.useState(new Map),[pt,mt]=Z.useState(new Set),[gt,_t]=Z.useState(0),vt=Z.useCallback(()=>{let e=()=>{let e=K.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&ky(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),yt=Z.useCallback(e=>{let t=K.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(K.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!K.getState().isMobile&&vt())},[vt]),bt=Z.useCallback(()=>{let e=K.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Oy(t)},[t]),xt=Z.useRef(ye);Z.useEffect(()=>{let e=xt.current;xt.current=ye,ye||(tt(``),ct.current=!1,lt.current=null,ft(new Map),mt(new Set),e&&!Ie&&(at(!1),ot.current=performance.now()+200))},[ye,Ie]);let[St,Ct]=Z.useState(``);Z.useEffect(()=>{xe||Ct(``)},[xe]);let wt=Z.useMemo(()=>z.filter(e=>Ar(e.mode)),[z]),Tt=Z.useMemo(()=>St.trim()?Bi(wt,St.trim(),e=>[e.name,ht(e),e.description??``]).map(e=>e.item):[...wt].sort((e,t)=>e.name.localeCompare(t.name)),[wt,St]),Et=Z.useMemo(()=>{if(O){let e=wt.find(e=>e.name===O);if(e)return e.name}let e=wt.find(e=>e.name===`build`);return e?e.name:wt[0]?.name},[O,wt]),Dt=Z.useMemo(()=>ue?z.find(e=>e.name===ue):L?.(),[z,L,ue]),Ot=Pe?`mobile`:Fe?`vscode`:`default`,kt=Ot===`mobile`?`size-5`:`size-4`,At=Ie?`typography-micro`:`typography-meta`,jt=Ot===`mobile`?`gap-x-0.5`:Ot===`vscode`?`gap-x-2`:`gap-x-1.5`,Mt=Ot===`mobile`?`h-8 w-7`:`h-6 w-6`,Nt=Ot===`mobile`?24:20,Pt=Ot===`mobile`?`pl-1 pr-0.5`:`pl-1.5 pr-0.5`,Ft=ay(ue),It=i?v.find(e=>e.id===x):F(),Lt=Array.isArray(It?.models)?It.models:[],Rt=S?Lt.find(e=>e.id===S):void 0,zt=x&&S&&Rt?Us(x,Rt,I(x,S)):x&&S?I(x,S):void 0,Bt=Z.useCallback(e=>e===`Tool calling`?a(`chat.modelControls.capability.toolCalling`):e===`Reasoning`?a(`chat.modelControls.capability.reasoning`):e===`Text`?a(`chat.modelControls.modality.text`):e===`Image`?a(`chat.modelControls.modality.image`):e===`Video`?a(`chat.modelControls.modality.video`):e===`Audio`?a(`chat.modelControls.modality.audio`):e===`PDF`?a(`chat.modelControls.modality.pdf`):e,[a]),Vt=Z.useMemo(()=>ob(zt).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Ht=Z.useMemo(()=>Zy(zt,`input`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Ut=Z.useMemo(()=>Zy(zt,`output`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Wt=Z.useMemo(()=>{if(f?.variantsReady===!1)return[];if(f?.variants)return[...f.variants];if(x&&S){let e=v.find(e=>e.id===x)?.models?.find(e=>e.id===S);return My(e)}return i?[]:N()},[S,x,N,v,i,f?.variants,f?.variantsReady]),Gt=Wt.length>0,Kt=[{label:`Input`,value:ab(zt?.cost?.input)},{label:`Output`,value:ab(zt?.cost?.output)},{label:`Cache read`,value:ab(zt?.cost?.cache_read)},{label:`Cache write`,value:ab(zt?.cost?.cache_write)}],qt=[{label:`Context`,value:ib(zt?.limit?.context)},{label:`Output`,value:ib(zt?.limit?.output)}],Jt=Z.useRef(void 0),Yt=Z.useRef(null),Xt=Z.useRef(null),Zt=H?U(H):void 0,Qt=Ja(H??``,Zt??void 0).renderable,$t=Ca(H??``,Zt??void 0),en=Z.useMemo(()=>{for(let e=$t.length-1;e>=0;--e){let t=$t[e];if(t.role!==`user`)continue;let n=typeof t.model?.providerID==`string`&&t.model.providerID.trim().length>0?t.model.providerID:void 0,r=typeof t.model?.modelID==`string`&&t.model.modelID.trim().length>0?t.model.modelID:void 0,i=typeof t.agent==`string`&&t.agent.trim().length>0?t.agent:typeof t.mode==`string`&&t.mode.trim().length>0?t.mode:void 0,a=t.model?.variant??t.variant,o=typeof a==`string`&&a.trim().length>0?a:void 0;return{id:t.id,agent:i,providerID:n,modelID:r,variant:o}}return null},[$t]),tn=Z.useCallback((e,t,n)=>{if(!e||!t)return`model-missing`;let r=v.find(t=>t.id===e);return r?(Array.isArray(r.models)?r.models:[]).find(e=>e.id===t)?x===e&&S===t?`applied`:(k(e),j(t),H&&(te(H,e,t),n&&re(H,n,e,t)),`applied`):`model-missing`:`provider-missing`},[v,x,S,k,j,H,re,te]),nn=Z.useCallback((e,t)=>{if(i&&i.selection.providerID===e&&i.selection.modelID===t)return Ny(i.selection,i.catalog,e,t);let n=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return My(n)},[v,i,i?.selection.providerID,i?.selection.modelID,f?.variants,f?.variantsReady]),rn=Z.useCallback((e,t)=>{let n=i?Ny(i.selection,i.catalog,e,t):[],r=n.length>0?n:nn(e,t);if(r.length===0)return;if(i){let n=i.selection.variant;if(i.selection.providerID===e&&i.selection.modelID===t&&n&&r.includes(n))return n}let a=ue||E;if(H&&a){let n=ae(H,a,e,t);if(n&&r.includes(n))return n}if(x===e&&S===t&&w&&r.includes(w))return w;if(!H&&D&&r.includes(D))return D},[E,S,x,H,w,ae,nn,i,D,ue]),an=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=Ko.getState().currentAgentName;return H?ur.getState().getSessionAgentSelection(H)||ce.current||e||E:e||E},[E,H,i]),on=Z.useCallback((e,t,n,r)=>{if(i){i.onChange({...i.selection,providerID:e,modelID:t,variant:n}).catch(()=>void 0);return}if(nn(e,t).length===0){qe.current=!1,M(void 0);return}qe.current=!0,M(n),ve(e,t,n);let a=r??an();H&&a&&ie(H,a,e,t,n)},[ve,H,nn,an,ie,i,M]),sn=Z.useCallback((e,t,n,r)=>{let a=r??an()??void 0,o=tn(e,t,a);if(o!==`applied`)return o;on(e,t,n,a);let s=i?n:Ko.getState().currentVariant;return ge(e,t,s),`applied`},[ge,on,an,i,tn]);Z.useEffect(()=>{if(i)return;if(!H){Xt.current=null;return}if(!oe||v.length===0||!Qt||!en?.providerID||!en.modelID)return;let e=[H,en.id,en.agent??``,en.providerID,en.modelID,en.variant??``].join(`|`);if(Xt.current===e)return;en.agent&&E!==en.agent&&P(en.agent);let t=en.variant&&nn(en.providerID,en.modelID).includes(en.variant)?en.variant:void 0;sn(en.providerID,en.modelID,t,en.agent||E||void 0)===`applied`&&(en.agent&&(ne(H,en.agent),ie(H,en.agent,en.providerID,en.modelID,t)),te(H,en.providerID,en.modelID),Xt.current=e)},[i,H,E,oe,v,Qt,en,P,sn,nn,ne,ie,te]),Z.useEffect(()=>{if(i)return;if(!H){Xt.current=null;return}if(!oe||v.length===0||z.length===0)return;let e=()=>{let e=ee(H),t=H?ur.getState().getSessionAgentSelection(H):null;if(t){E!==t&&P(t);let e=G(H,t);if(e){let n=tn(e.providerId,e.modelId,t);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}}if(e){let n=tn(e.providerId,e.modelId,t||E||void 0);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}for(let e of z){let t=G(H,e.name);if(!t)continue;E!==e.name&&P(e.name),ur.getState().getSessionAgentSelection(H)||ce.current||ne(H,e.name);let n=tn(t.providerId,t.modelId,e.name);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}return`continue`},t=()=>{if(z.length===0)return;let e=H?ur.getState().getSessionAgentSelection(H)||ce.current:null,t=(H?ur.getState().getSessionAgentSelection(H)||ce.current:null)||E;if(t&&z.some(e=>e.name===t)){E!==t&&P(t);return}let n=z.find(e=>e.name===`build`)||B[0]||z[0];n&&(e||ne(H,n.name),E!==n.name&&P(n.name),n.model?.providerID&&n.model?.modelID&&tn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!Qt){W.isLoading(H)||W.ensureSessionRenderable(H);return}en||t()}},[i,H,Qt,en,z,B,E,ee,G,P,tn,ne,oe,v,W]),Z.useEffect(()=>{if(i||!oe)return;let e=new AbortController;return(async()=>{try{if(E!==Jt.current&&(Jt.current=E,E&&H)){let t=Yt.current===E;if(Yt.current=null,await new Promise(t=>{let n=setTimeout(t,50);e.signal.addEventListener(`abort`,()=>{clearTimeout(n),t()})}),e.signal.aborted)return;let n=G(H,E);if(n){let e=tn(n.providerId,n.modelId,E);if(e===`applied`||e===`provider-missing`)return}let r=Ko.getState().getAgentModelSelection(E);if(r){let e=tn(r.providerId,r.modelId,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(te(H,r.providerId,r.modelId),re(H,E,r.providerId,r.modelId),r.variant!==void 0&&(ie(H,E,r.providerId,r.modelId,r.variant),M(r.variant)));return}}let i=t?z.find(e=>e.name===E):void 0;if(i?.model?.providerID&&i.model.modelID){let e=tn(i.model.providerID,i.model.modelID,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(te(H,i.model.providerID,i.model.modelID),re(H,E,i.model.providerID,i.model.modelID));return}}}}catch(e){console.error(`[ModelControls] Agent change error:`,e)}})(),()=>{e.abort()}},[i,z,E,H,G,re,ie,te,M,tn,oe]),Z.useEffect(()=>{if(i)return;if(!oe||!E){qe.current=!1,M(void 0);return}if(!x||!S){qe.current=!1,M(void 0);return}if(Wt.length===0){qe.current=!1,M(void 0);return}if(w&&!Wt.includes(w)){M(void 0);return}if(!H){if(!w&&!qe.current){let e=D&&Wt.includes(D)?D:void 0;M(e)}return}let e=ae(H,E,x,S),t=e&&Wt.includes(e)?e:D&&Wt.includes(D)?D:void 0;M(t),qe.current=!1},[i,Wt,oe,H,E,x,S,w,ae,M,D]),Z.useEffect(()=>{qe.current=!1},[x,S]);let cn=Z.useCallback((e,t)=>{if(i){let n=Ur(i.selection,e,z,v),r=n.providerID===i.selection.providerID&&n.modelID===i.selection.modelID;Ie&&Je(),i.onChange({...n,variant:r?i.selection.variant:void 0}).then(()=>{_e(e),(t?.closeModelSelector??!0)&&Qe(!1)}).catch(()=>void 0);return}try{Yt.current=e,P(e),_e(e),(t?.closeModelSelector??!0)&&Qe(!1),H&&ne(H,e),Ie&&Je()}catch(e){console.error(`[ModelControls] Handle agent change error:`,e)}},[_e,z,Je,H,Ie,v,ne,i,P,Qe]),ln=Z.useCallback(e=>{let t=li(z,E,e);t&&cn(t,{closeModelSelector:!1})},[z,E,cn]),un=Z.useCallback(e=>{let t=ke&&!ke.includes(`shift`)?hc(`shift+${ke}`):``;return t&&Tc(e,t)?-1:Tc(e,ke)?1:null},[ke]),dn=Z.useCallback(e=>{let t=un(e);t&&(e.preventDefault(),e.stopPropagation(),ln(t))},[un,ln]),fn=Z.useCallback((e,t,n,r)=>{!e||!t||!n||Ko.getState().saveAgentModelSelection(e,t,n,r)},[]),pn=(e,t,n)=>{let r=()=>{Qe(!1,n?.closeInstant?{instant:!0}:void 0)};if(i){Ie&&Je();let a=n?.applyVariant?n.variant:rn(e,t);i.onChange({providerID:e,modelID:t,agent:n?.agentName??i.selection.agent,variant:a}).then(()=>{ge(e,t,a),r()}).catch(()=>void 0);return}try{let i=n?.agentName??an()??void 0,a=n?.applyVariant?sn(e,t,n.variant,i):tn(e,t,i);if(a!==`applied`){a===`provider-missing`?console.error(`[ModelControls] Provider not available for selection:`,e):a===`model-missing`&&console.error(`[ModelControls] Model not available for selection:`,{providerId:e,modelId:t});return}fn(i,e,t,n?.applyVariant?n.variant:Ko.getState().currentVariant),n?.applyVariant||ge(e,t,Ko.getState().currentVariant),r(),Ie&&Je()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},mn=(e,t)=>ni(e,t,{maxLength:40}),hn=()=>v.find(e=>e.id===x)?.name||x,gn=()=>{if(!S)return a(`chat.modelControls.selectModel`);let e=Lt.find(e=>e.id===S);return mn(e,S)||a(`chat.modelControls.selectModel`)},_n=gn(),vn=()=>{if(!ue){let e=B.find(e=>e.name===`build`)||B[0];return e?yn(ht(e)):a(`chat.modelControls.selectAgent`)}let e=z.find(e=>e.name===ue);return yn(e?ht(e):ue)},yn=e=>e.charAt(0).toUpperCase()+e.slice(1),bn=Z.useCallback(e=>{Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>{Ge(e)},500)},[]),q=Z.useCallback(()=>{Xe.current&&clearTimeout(Xe.current)},[]);Z.useEffect(()=>()=>{Xe.current&&clearTimeout(Xe.current)},[]);let xn=()=>!Ie||We!==`model`?null:(0,$.jsx)(zc,{open:!0,onClose:Ye,title:zt?.name||gn(),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-0.5`,children:a(`chat.modelControls.provider`)}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground font-medium`,children:hn()})]}),Vt.length>0&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.capabilities`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Vt.map(({key:e,icon:t,label:n})=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(nb,{iconName:t,label:n},`cap-${e}`),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:n})]},e))})]}),(Ht.length>0||Ut.length>0)&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.modalities`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[Ht.length>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-12`,children:a(`chat.modelControls.input`)}),(0,$.jsx)(`div`,{className:`flex gap-1`,children:Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} input`},`input-${e}`))})]}),Ut.length>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-12`,children:a(`chat.modelControls.output`)}),(0,$.jsx)(`div`,{className:`flex gap-1`,children:Ut.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} output`},`output-${e}`))})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.limits`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.context`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:ib(zt?.limit?.context)})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.output`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:ib(zt?.limit?.output)})]})]})]}),zt?.release_date?(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.metadata`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.release`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:sb(zt.release_date)})]})})]}):null]})}),Sn=()=>{if(!Ie||We!==`agent`||!Dt)return null;let e=!!(Dt.prompt&&Dt.prompt.trim().length>0),t=Dt.model?.providerID&&Dt.model?.modelID,n=Dt.temperature!==void 0||Dt.topP!==void 0,r=e=>{let t=Ky(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=qy(t,e)??`ask`;return n?{mode:`ask`,label:a(`chat.modelControls.permissionLabel.custom`)}:r===`allow`?{mode:`allow`,label:a(`chat.modelControls.permissionLabel.allow`)}:r===`deny`?{mode:`deny`,label:a(`chat.modelControls.permissionLabel.deny`)}:{mode:`ask`,label:a(`chat.modelControls.permissionLabel.ask`)}},i=r(`edit`),o=r(`bash`),s=r(`webfetch`);return(0,$.jsx)(zc,{open:!0,onClose:Ye,title:yn(Dt.name),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[Dt.description&&(0,$.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:Dt.description})}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-0.5`,children:a(`chat.modelControls.mode`)}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground font-medium`,children:Dt.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Dt.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Dt.mode===`all`?a(`chat.modelControls.modeValue.all`):a(`chat.modelControls.modeValue.none`)})]}),(t||n)&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.model`)}),t&&(0,$.jsxs)(`div`,{className:`typography-meta text-foreground font-medium mb-1`,children:[Dt.model.providerID,` / `,Dt.model.modelID]}),n&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[Dt.temperature!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.temperature`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.temperature})]}),Dt.topP!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.topP`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.topP})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.permissions`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.edit`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:i.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:i.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.bash`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:o.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:o.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.webFetch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:s.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:s.label})]})]})]})]}),e&&(0,$.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.customPrompt`)}),(0,$.jsx)(X,{name:`checkbox-circle`,className:`size-4 text-foreground`})]})})]})})},Cn=()=>Ie?(0,$.jsx)(vc,{open:Be===`model`||Be===`variant`,view:Be===`variant`?`variant`:`model`,onViewChange:e=>Ve(e),onClose:Je,selectedProviderID:x||``,selectedModelID:S||``,resolveSelectedVariant:rn,onSelect:(e,t,n)=>{if(i){Je(),i.onChange({providerID:e,modelID:t,agent:i.selection.agent,variant:n}).then(()=>{ge(e,t,n)}).catch(()=>void 0);return}let r=sn(e,t,n);if(r!==`applied`){r===`provider-missing`?console.error(`[ModelControls] Provider not available for selection:`,e):r===`model-missing`&&console.error(`[ModelControls] Model not available for selection:`,{providerId:e,modelId:t});return}fn(an(),e,t,n),Je()},providers:v,favoriteModels:Ae,recentModels:je,hiddenModels:De,providerOrder:pe,isFavorite:he,onToggleFavorite:(e,t)=>de(e,t,e===x&&t===S?w:Ae.find(n=>n.providerID===e&&n.modelID===t)?.variant??je.find(n=>n.providerID===e&&n.modelID===t)?.variant),getMetadata:I}):null,wn=()=>Ie?(0,$.jsx)(dl,{id:`mobile-agent-picker-sheet-${o}`,open:Be===`agent`,onOpenChange:e=>{e||Je()},ariaLabel:a(`chat.modelControls.selectAgent`),closeAriaLabel:a(`mobile.surface.closeAria`),resizeAriaLabel:a(`mobile.sessions.sheet.resizeAria`),bodyClassName:`px-2`,children:(0,$.jsx)(Xu,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`flex flex-col gap-2 overscroll-contain`,children:wt.map(e=>{let t=e.name===ue,n=os(e.name);return(0,$.jsx)(`button`,{type:`button`,className:Y(`flex w-full flex-col gap-1.5 rounded-xl border px-3 py-2.5 text-left`,`focus:outline-none focus-visible:ring-2 focus-visible:ring-primary`,`touch-manipulation cursor-pointer transition-colors`,`active:bg-interactive-hover`,t?`border-primary/50 bg-interactive-selection/20`:`border-border/40 hover:bg-interactive-hover/50`),onClick:()=>cn(e.name),children:(0,$.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[1.125rem_minmax(0,1fr)_auto] items-start gap-x-2`,children:[(0,$.jsx)(ds,{name:e.name,size:18}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block typography-ui-label font-semibold`,style:t?{color:`var(${n.var})`}:void 0,children:yn(ht(e))}),e.description&&(0,$.jsx)(`span`,{className:`mt-1 block min-w-0 whitespace-normal break-words typography-micro text-muted-foreground`,children:e.description})]}),t&&(0,$.jsx)(X,{name:`check`,className:`size-4 shrink-0 text-primary`})]})},e.name)})})}):null,Tn=()=>(0,$.jsx)(Js,{align:`start`,sideOffset:8,className:`max-w-[320px]`,children:zt?(0,$.jsxs)(`div`,{className:`flex min-w-[240px] flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-foreground`,children:zt.name||gn()}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:hn()})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.capabilities`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:Vt.length>0?Vt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:n},`cap-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a(`chat.modelControls.modeValue.none`)})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.modalities`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:a(`chat.modelControls.input`)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:Ht.length>0?Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} input`},`input-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:`-`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:a(`chat.modelControls.output`)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:Ut.length>0?Ut.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} output`},`output-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:`-`})})]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.costPerMillion`)}),Kt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.limits`)}),qt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),zt.release_date?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.metadata`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:a(`chat.modelControls.release`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:sb(zt.release_date)})]})]}):null]}):(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.metadataUnavailable`)})}),En=()=>{let e=(e,t)=>{if(ct.current=!0,e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return!1;let{providerID:n,modelID:r}=t,i=nn(n,r);if(i.length===0)return!1;e.preventDefault(),e.stopPropagation();let a=Wy(n,r),o=dt.has(a),s=dt.get(a),c=o?s:x===n&&S===r?w:void 0,l=[void 0,...i],u=l.indexOf(c),d=l[((u>=0?u:0)+(e.key===`ArrowRight`?1:-1)+l.length)%l.length];return ft(e=>{let t=new Map(e);return t.set(a,d),t}),mt(e=>{let t=new Set(e);return t.add(a),t}),_t(e=>e+1),!0},t=(t,n)=>{let r=un(t);if(r){t.preventDefault(),ln(r);return}n&&e(t,n)},n=e=>{let t=Wy(e.providerID,e.modelID),n=dt.get(t),r=pt.has(t),i=an();if(r){pn(e.providerID,e.modelID,{applyVariant:!0,variant:n,agentName:i});return}let a=nn(e.providerID,e.modelID),o=e.variant!==void 0&&a.includes(e.variant)?e.variant:void 0;if(o!==void 0){pn(e.providerID,e.modelID,{applyVariant:!0,variant:o,agentName:i});return}pn(e.providerID,e.modelID,{agentName:i})},r=e=>{let t=un(e);t&&(e.preventDefault(),e.stopPropagation(),ct.current=!0,ln(t))},i=e=>e?.trim()?Za(e):a(`chat.modelControls.default`),o=(e,t)=>{let n=an();pn(e.providerID,e.modelID,{applyVariant:!0,variant:t,agentName:n,closeInstant:!0})},s=e=>{e&&(Ze||performance.now()<ot.current)||at(e)},c={searchPlaceholder:a(`chat.modelControls.searchModels`),noResults:a(`chat.modelControls.noModelsFound`),favorites:a(`chat.modelControls.favorites`),recent:a(`chat.modelControls.recent`),keyboardHint:a(`chat.modelControls.keyboardHintNavigate`),favorite:a(`chat.modelControls.favoriteAria`),unfavorite:a(`chat.modelControls.unfavoriteAria`),provider:a(`chat.modelControls.provider`),capabilities:a(`chat.modelControls.capabilities`),capabilityToolCalling:a(`chat.modelControls.capability.toolCalling`),capabilityReasoning:a(`chat.modelControls.capability.reasoning`),modalityImage:a(`chat.modelControls.modality.image`),modalityVideo:a(`chat.modelControls.modality.video`),modalityAudio:a(`chat.modelControls.modality.audio`),costPerMillion:a(`chat.modelControls.costPerMillion`),costInput:a(`chat.modelControls.costInput`),costOutput:a(`chat.modelControls.costOutput`)},u=(e,{isSelected:t})=>{let n=nn(e.providerID,e.modelID);if(n.length===0)return null;let r=Wy(e.providerID,e.modelID),o=dt.has(r),s=dt.get(r),c=e.variant!==void 0&&n.includes(e.variant)?e.variant:void 0,l=o?s:t?w:c,u=pt.has(r);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`group/thinking flex shrink-0 items-center gap-0.5 rounded-md px-1.5 py-0.5 typography-micro font-medium transition-colors`,u||l?`text-foreground/80`:`text-muted-foreground`,`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] hover:text-foreground`),onClick:t=>{t.preventDefault(),t.stopPropagation(),rt(e)},"aria-label":a(`chat.modelControls.showThinkingModes`),children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),(0,$.jsx)(`span`,{className:`max-w-20 truncate`,children:i(l)}),(0,$.jsx)(X,{name:`arrow-right-s`,className:`size-3 opacity-60 transition-transform group-hover/thinking:translate-x-px`})]})},d=()=>{if(!nt)return null;let e=nn(nt.providerID,nt.modelID),t=Wy(nt.providerID,nt.modelID),n=dt.has(t),r=dt.get(t),s=nt.providerID===x&&nt.modelID===S,c=nt.variant!==void 0&&e.includes(nt.variant)?nt.variant:void 0,l=n?r:s?w:c,u=ni(nt.model,nt.modelID,{maxLength:40});return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,onKeyDownCapture:e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),rt(null))},children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-border/40 px-1.5 py-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground`,onClick:()=>rt(null),"aria-label":a(`header.actions.backAria`),children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-3.5`})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,$.jsx)(Os,{modelId:nt.modelID,providerId:nt.providerID,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate typography-meta font-medium text-foreground`,children:u}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`shrink-0 text-border`,children:`·`}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),a(`chat.modelControls.thinking`)]})]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 p-1`,role:`listbox`,"aria-label":a(`chat.modelControls.thinking`),children:[void 0,...e].map(e=>{let t=e===l||!e&&!l;return(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:Y(`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left typography-meta transition-colors`,t?`bg-interactive-selection text-interactive-selection-foreground`:`text-foreground hover:bg-interactive-hover/50`),onClick:()=>o(nt,e),children:[(0,$.jsx)(`span`,{className:Y(`truncate font-medium`,!e&&!t&&`text-muted-foreground`),children:i(e)}),t?(0,$.jsx)(X,{name:`check`,className:`size-3.5 shrink-0 text-primary`}):(0,$.jsx)(`span`,{className:`size-3.5 shrink-0`,"aria-hidden":`true`})]},e??`__default`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border/40 px-2 py-1.5 typography-micro text-muted-foreground`,children:[(0,$.jsx)($v,{className:`h-4 min-w-4 rounded-[3px] px-1 text-[10px] font-medium tracking-tight shadow-none`,children:`Esc`}),(0,$.jsx)(`span`,{children:a(`header.actions.backAria`)}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-border`,children:`·`}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintThinking`)})]})]})},f=w&&Gt?Za(w):null;return(0,$.jsxs)(Ys,{open:!Ze&&it,onOpenChange:s,delayDuration:200,children:[Ie?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>He(`model`):void 0,onTouchStart:m?()=>bn(`model`):void 0,onTouchEnd:m?q:void 0,onTouchCancel:m?q:void 0,disabled:!m,className:Y(`model-controls__model-trigger min-w-0 focus:outline-none`,m?Y(`cursor-pointer`,fy):`opacity-60 cursor-not-allowed`),children:m?(0,$.jsxs)($.Fragment,{children:[x||S?(0,$.jsx)(Os,{modelId:S,providerId:x,className:Y(kt,`flex-shrink-0`)}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(kt,`text-muted-foreground`)}),(0,$.jsx)(`span`,{className:Y(`model-controls__model-label typography-micro font-medium overflow-hidden min-w-0`,Pe?`max-w-[120px]`:`max-w-[220px]`),children:(0,$.jsxs)(`span`,{className:`inline-flex max-w-full min-w-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:_n}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:`typography-micro font-medium text-muted-foreground min-w-0`,children:l})]})}):(0,$.jsxs)(Bc,{open:m&&Ze,onOpenChange:m?st:void 0,onOpenChangeComplete:e=>{e||yt(`model`)},children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,fy),children:[m?x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Os,{modelId:S,providerId:x,className:Y(kt,`flex-shrink-0`)}),(0,$.jsx)(X,{name:`pencil-ai`,className:Y(kt,`text-primary/60 hidden`)})]}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(kt,`text-muted-foreground`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:Y(`model-controls__model-label`,At,`font-medium whitespace-nowrap text-muted-foreground min-w-0`),children:l})]}),m&&(0,$.jsx)(`span`,{className:Y(`model-controls__model-label overflow-hidden`,At,`font-medium whitespace-nowrap text-foreground min-w-0`,`max-w-[260px]`),children:(0,$.jsxs)(`span`,{className:`inline-flex max-w-full min-w-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:_n}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})},`${x}-${S}-${w??``}`)]})})}),(0,$.jsx)(kc,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,Ce&&Gy),align:`end`,alignOffset:-40,onKeyDownCapture:r,finalFocus:bt,children:nt?d():(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`p-1 border-b border-border/40`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:$e,className:`typography-meta group flex w-full items-center gap-1 rounded-md px-2 py-1.5 cursor-pointer hover:bg-interactive-hover/50`,children:[(0,$.jsx)(`span`,{className:`flex size-4 items-center justify-center text-muted-foreground`,children:(0,$.jsx)(X,{name:`add`,className:`size-4 -mr-0.5`})}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`chat.modelControls.addNewProvider`)})]})}),(0,$.jsx)(ks,{providers:v,favoriteModels:Ae,recentModels:je,getMetadata:I,searchQuery:et,onSearchQueryChange:tt,onSelect:n,labels:c,selectedModel:x&&S?{providerID:x,modelID:S}:null,hiddenModels:De,onActiveKeyDown:t,onActiveEntryChange:e=>{ut.current=e},onVariantKey:e,isFavorite:e=>he(e.providerID,e.modelID),onToggleFavorite:e=>de(e.providerID,e.modelID,e.providerID===x&&e.modelID===S?w:e.variant),renderRowEnd:u,renderVersion:gt,onReorderFavorite:(e,t)=>fe(e.providerID,e.modelID,t.providerID,t.modelID),reorderFavoriteAriaLabel:a(`chat.modelControls.reorderFavoriteAria`),reorderFavoriteTitle:a(`chat.modelControls.reorderFavoriteTitle`),providerOrder:pe,onReorderProvider:me,reorderProviderTitle:a(`chat.modelControls.reorderProviderTitle`),footerContent:e=>{let t=e?nn(e.providerID,e.modelID).length>0:!1;return(0,$.jsxs)(`div`,{className:`flex items-center gap-x-2 whitespace-nowrap overflow-hidden`,children:[(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintNavigate`)}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintSwitchAgent`,{shortcut:`Tab`})}),t?(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintThinking`)}):null]})},tooltipsEnabled:Ze&&!nt,onEscape:()=>{if(nt){rt(null);return}Qe(!1)}})]})})]}),Tn()]})},On=()=>{if(!Dt)return(0,$.jsx)(Js,{align:`start`,sideOffset:8,className:`max-w-[320px]`,children:(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.noAgentSelected`)})});let e=!!(Dt.prompt&&Dt.prompt.trim().length>0),t=Dt.model?.providerID&&Dt.model?.modelID,n=Dt.temperature!==void 0||Dt.topP!==void 0,r=e=>{let t=Ky(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=qy(t,e)??`ask`;return n?{mode:`ask`,label:a(`chat.modelControls.permissionLabel.custom`)}:r===`allow`?{mode:`allow`,label:a(`chat.modelControls.permissionLabel.allow`)}:r===`deny`?{mode:`deny`,label:a(`chat.modelControls.permissionLabel.deny`)}:{mode:`ask`,label:a(`chat.modelControls.permissionLabel.ask`)}},i=r(`edit`),o=r(`bash`),s=r(`webfetch`);return(0,$.jsx)(Js,{align:`start`,sideOffset:8,className:`max-w-[280px]`,children:(0,$.jsxs)(`div`,{className:`flex min-w-[200px] flex-col gap-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-foreground`,children:yn(Dt.name)}),Dt.description&&(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:Dt.description})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.mode`)}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:Dt.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Dt.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Dt.mode===`all`?a(`chat.modelControls.modeValue.all`):a(`chat.modelControls.modeValue.none`)})]}),(t||n)&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.model`)}),t?(0,$.jsxs)(`span`,{className:`typography-meta text-foreground`,children:[Dt.model.providerID,` / `,Dt.model.modelID]}):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a(`chat.modelControls.modeValue.none`)}),n&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 mt-0.5`,children:[Dt.temperature!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.temperature`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.temperature})]}),Dt.topP!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.topP`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.topP})]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.permissions`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-16`,children:a(`chat.modelControls.edit`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:i.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground w-12`,children:i.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-16`,children:a(`chat.modelControls.bash`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:o.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground w-12`,children:o.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-16`,children:a(`chat.modelControls.webFetch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:s.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground w-12`,children:s.label})]})]})]}),e&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.customPrompt`)}),(0,$.jsx)(X,{name:`checkbox-circle`,className:`size-4 text-foreground`})]})]})})},kn=()=>{let e=vn(),t=ue?os(ue):null;return Ie?(0,$.jsx)(`button`,{type:`button`,onClick:h?()=>He(`agent`):void 0,onTouchStart:h?()=>bn(`agent`):void 0,onTouchEnd:h?q:void 0,onTouchCancel:h?q:void 0,disabled:!h,className:Y(`model-controls__agent-trigger inline-flex items-center flex-shrink-0 min-w-0 focus:outline-none`,py,h?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:h?(0,$.jsx)(iy,{name:ue,label:e,revealed:Ft,avatarSize:Nt,slotClassName:Mt,labelGapClassName:Pt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,Mt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`flex-shrink-0 animate-spin text-muted-foreground`)})})}):(0,$.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,$.jsxs)(Ys,{delayDuration:600,children:[(0,$.jsxs)(Bc,{open:h&&xe,onOpenChange:h?Ue:void 0,onOpenChangeComplete:e=>{e||yt(`agent`)},children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,py),children:h?(0,$.jsx)(iy,{name:ue,label:e,revealed:Ft,avatarSize:Nt,slotClassName:Mt,labelGapClassName:Pt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,Mt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`flex-shrink-0 animate-spin text-muted-foreground`)})})})})}),(0,$.jsxs)(kc,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,we&&Gy),onKeyDownCapture:dn,finalFocus:bt,children:[(0,$.jsx)(`div`,{className:`p-1.5 pb-1`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-2.5 top-1/2 -translate-y-1/2 size-3.5 text-muted-foreground`}),(0,$.jsx)(Ks,{type:`text`,placeholder:a(`chat.modelControls.searchAgents`),value:St,onChange:e=>Ct(e.target.value),onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),Se(!1);return}e.stopPropagation()},className:`pl-8 h-8 typography-meta`})]})}),(0,$.jsx)(Xu,{outerClassName:`max-h-[min(400px,calc(100dvh-12rem))] flex-1`,children:(0,$.jsxs)(`div`,{className:`p-1`,children:[!St.trim()&&Et&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sc,{className:`typography-meta`,onSelect:()=>cn(Et),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{name:`arrow-go-back`,className:`size-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`font-medium`,children:a(`chat.modelControls.resetToDefault`)})]})}),(0,$.jsx)(Mc,{})]}),Tt.length===0?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-meta text-muted-foreground`,children:`No agents found`}):Tt.map(e=>(0,$.jsx)(Sc,{className:`typography-meta`,onSelect:()=>cn(e.name),children:(0,$.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col gap-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(ds,{name:e.name,size:14}),(0,$.jsx)(`span`,{className:`font-medium`,children:yn(ht(e))})]}),e.description&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground min-w-0 max-w-full ml-5 break-words`,children:e.description})]})},e.name))]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border/40 px-2 py-1.5 typography-micro text-muted-foreground`,children:[(0,$.jsx)($v,{className:`h-4 min-w-4 rounded-[3px] px-1 text-[10px] font-medium tracking-tight shadow-none`,children:`Tab`}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintSwitchAgentLabel`)})]})]})]}),On()]})})},An=Y(`@container/model-controls flex items-center min-w-0`,Pe&&`w-full`,e),jn=kn();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:An,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center min-w-0 flex-1 justify-end`,jt,Pe&&`overflow-hidden`),children:[jn,En()]})}),Cn(),wn(),xn(),Sn()]})},lb=[{key:`M`,labelKey:`chat.leaderKey.action.model`},{key:`A`,labelKey:`chat.leaderKey.action.agent`},{key:`N`,labelKey:`chat.leaderKey.action.newSession`},{key:`C`,labelKey:`chat.leaderKey.action.compact`}],ub=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=Xn(),i=$m(db),a=K(fb),o;t[0]===a?o=t[1]:(o=Nc(Ec(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let s=o;if(!i)return null;let c;t[2]===r?c=t[3]:(c=r(`chat.leaderKey.pendingAria`),t[2]=r,t[3]=c);let l;t[4]===n?l=t[5]:(l=Y(`pointer-events-none absolute left-1/2 top-0 z-20 -translate-x-1/2 -translate-y-[calc(100%+0.4rem)]`,`inline-flex max-w-[calc(100cqw-1rem)] items-center gap-2 overflow-x-auto rounded-lg border px-2.5 py-1.5`,`border-[var(--interactive-border)] bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)]`,`shadow-sm animate-in fade-in-0 zoom-in-95 duration-150 whitespace-nowrap`,n),t[4]=n,t[5]=l);let u;t[6]===s?u=t[7]:(u=(0,$.jsx)(ey,{shortcut:s,className:`opacity-[0.35] [&_[data-slot=kbd]]:rounded-md [&_[data-slot=kbd]]:border-0 [&_[data-slot=kbd]]:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] [&_[data-slot=kbd]]:text-muted-foreground/65 [&_[data-slot=kbd]]:shadow-none`}),t[6]=s,t[7]=u);let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}),t[8]=d):d=t[8];let f;t[9]===r?f=t[10]:(f=lb.map((e,t)=>(0,$.jsxs)(Z.Fragment,{children:[t>0?(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}):null,(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 typography-micro`,children:[(0,$.jsx)($v,{className:`rounded-md border-0 bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] text-muted-foreground/65 shadow-none`,children:e.key}),(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(e.labelKey)})]})]},e.key)),t[9]=r,t[10]=f);let p;return t[11]!==c||t[12]!==l||t[13]!==u||t[14]!==f?(p=(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":c,className:l,children:[u,d,f]}),t[11]=c,t[12]=l,t[13]=u,t[14]=f,t[15]=p):p=t[15],p};function db(e){return e.pending}function fb(e){return e.shortcutOverrides}var pb=28,mb=8,hb=10.5,gb=Math.PI/2,_b=e=>Array.from({length:mb},(t,n)=>{let r=n/mb*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*hb,Math.sin(r)*hb]}),vb=[_b(0),_b(gb),_b(Math.PI),_b(Math.PI*1.5)],yb=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,bb=e=>{let t=(0,Q.c)(9),{size:n,isMobile:r,className:i}=e,a=n??(r!==void 0&&r?12:14),o;t[0]===i?o=t[1]:(o=Y(`yuri-morph-orb-glyph shrink-0`,i),t[0]=i,t[1]=o);let s=a/pb,c;t[2]!==a||t[3]!==s?(c={width:a,height:a,"--orb-k":s},t[2]=a,t[3]=s,t[4]=c):c=t[4];let l=c,u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(`span`,{className:`yuri-morph-orb-stage`,children:vb[0].map(xb)}),t[5]=u):u=t[5];let d;return t[6]!==o||t[7]!==l?(d=(0,$.jsx)(`span`,{className:o,style:l,"aria-hidden":`true`,children:u}),t[6]=o,t[7]=l,t[8]=d):d=t[8],d};function xb(e,t){return(0,$.jsx)(`span`,{className:`yuri-morph-orb-dot`,style:{"--m-1":yb(vb[0][t]),"--m-2":yb(vb[1][t]),"--m-3":yb(vb[2][t]),"--m-4":yb(vb[3][t])}},t)}var Sb=1200,Cb=600;function wb({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o,isTurnSettled:s=!1}){let{locale:c,t:l}=Xn(),[u,d]=Z.useState(null),[f,p]=Z.useState(!1),m=Z.useRef(u),h=Z.useRef(f),g=Z.useRef(!1);m.current=u,h.current=f;let _=Z.useRef(0),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(null),[x,S]=Z.useState(null),[C,w]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;w(Date.now());let t=window.setInterval(()=>w(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){S(null);return}let t=e,n=()=>{let e=Math.max(0,t-Date.now());S(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let T=J(()=>{y.current&&=(clearTimeout(y.current),null),b.current&&=(clearTimeout(b.current),null)}),E=J((e,t,n=!1)=>{T(),v.current=null,d(e),p(t),g.current=n,_.current=Date.now()}),D=J(()=>{if(y.current)return;let e=Date.now()-_.current,t=Math.max(0,Sb-e);y.current=setTimeout(()=>{y.current=null;let e=v.current;e&&E(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(s){T(),v.current=null,m.current&&(d(null),p(!1),g.current=!1);return}if(!e){if(y.current&&=(clearTimeout(y.current),null),v.current=null,!m.current||b.current)return;b.current=setTimeout(()=>{b.current=null,d(null),p(!1),g.current=!1},Cb);return}if(b.current&&=(clearTimeout(b.current),null),a){T(),v.current=null;return}let t=i?l(`chat.assistantStatus.waitingForPermission`):n,o=!!i,c=!!r&&!o;if(t){if(!m.current){E(t,o,c);return}if((t!==m.current||o!==h.current)&&!(c&&g.current)){if(c){v.current={text:t,permission:o,generic:c},D();return}E(t,o,c)}}},[e,s,n,r,i,a,l]),Z.useEffect(()=>()=>T(),[]),s||!e&&!u)return null;if(a&&e){let e=x!==null&&x>0?new Intl.RelativeTimeFormat(c,{numeric:`always`,style:`short`}).format(x,`second`):null,n=e?a.attempt&&a.attempt>0?l(`chat.assistantStatus.retryingInAttempt`,{duration:e,attempt:a.attempt}):l(`chat.assistantStatus.retryingIn`,{duration:e}):a.attempt&&a.attempt>0?l(`chat.assistantStatus.retryingAttempt`,{attempt:a.attempt}):l(`chat.assistantStatus.retrying`),r=a.message?`${n} · ${a.message}`:n;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":r,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center ${t?`gap-1 typography-meta !text-[length:var(--text-meta)]`:`gap-1.5 typography-ui-header`}`,children:[(0,$.jsx)(`span`,{className:`inline-flex flex-none items-center justify-center ${t?`h-5 w-4`:`h-6 w-3.5`}`,children:(0,$.jsx)(bb,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 whitespace-normal break-words`,children:r})]})})}if(!u)return null;let O=u,k=typeof o==`number`&&e?lr(Math.max(0,C-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":f?`assertive`:`polite`,"aria-label":O,"data-waiting":f?`true`:void 0,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center ${t?`gap-1 typography-meta !text-[length:var(--text-meta)]`:`gap-1.5 typography-ui-header`}`,children:[(0,$.jsx)(`span`,{className:`inline-flex flex-none items-center justify-center ${t?`h-5 w-4`:`h-6 w-3.5`}`,children:(0,$.jsx)(bb,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:O}),k?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:k}):null]})})}var Tb={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Eb={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Db={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:Tb},Ob=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?Tb:Eb}),kb=Z.createContext(Db),Ab=()=>Z.useContext(kb),jb=e=>({fork:e.capabilities.forkSession,revert:e.capabilities.mutateSession,edit:e.capabilities.mutateSession,reviewTransfer:e.capabilities.mutateSession,timeline:e.capabilities.openTimeline,textSelectionMutation:e.capabilities.textSelectionActions,openSourceSession:!!e.openSourceSession}),Mb=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,Nb={containerType:`inline-size`,containerName:`status-row`},Pb=[],Fb=e=>{let t=(0,Q.c)(102),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:s,retryInfo:c,turnStartedAt:l,isTurnSettled:u,showAbortStatus:d,showAbortPrompt:f,showAssistantStatus:p,showTodos:h,agentName:g,leftAccessory:_,className:v}=e,y=n!==void 0&&n,b=r===void 0?null:r,x=u!==void 0&&u,S=f!==void 0&&f,C=p===void 0||p,w=h===void 0||h,{t:T}=Xn(),[E,D]=Z.useState(!1),O=Ab(),k=wa(Ib),A=O.sessionId??k,j;t[0]!==A||t[1]!==w?(j=e=>!w||!A?Pb:e.todo[A]??Pb,t[0]=A,t[1]=w,t[2]=j):j=t[2];let M=Rr(j,O.directory??void 0),N;t[3]!==A||t[4]!==w?(N=e=>w&&A?e.sessions[A]?.todos:void 0,t[3]=A,t[4]=w,t[5]=N):N=t[5];let P=Qo(N),F;bb0:{if(!A){F=Pb;break bb0}if(M.length>0){F=M;break bb0}F=P??Pb}let I=F,L=K(Lb),R;t[6]===L?R=t[7]:(R=L||m(),t[6]=L,t[7]=R);let z=R,B;t[8]===I?B=t[9]:(B=I.filter(Rb),t[8]=I,t[9]=B);let V=B,H;t[10]===V?H=t[11]:(H=V.find(zb)||V.find(Bb)||null,t[10]=V,t[11]=H);let U=H,W;t[12]===V?W=t[13]:(W=V.find(Vb)??null,t[12]=V,t[13]=W);let ee=W,te;t[14]===I?te=t[15]:(te=I.filter(Hb),t[14]=I,t[15]=te);let ne=te.length,re;t[16]===I?re=t[17]:(re=I.filter(Ub),t[16]=I,t[17]=re);let G=re.length,ie;t[18]!==G||t[19]!==ne?(ie={completed:G,total:ne},t[18]=G,t[19]=ne,t[20]=ie):ie=t[20];let ae=ie,oe;t[21]===V?oe=t[22]:(oe=V.filter(Wb),t[21]=V,t[22]=oe);let se=oe.length,ce;t[23]===V?ce=t[24]:(ce=V.filter(Gb),t[23]=V,t[24]=ce);let le=ce.length,ue;t[25]!==se||t[26]!==le?(ue={active:se,left:le},t[25]=se,t[26]=le,t[27]=ue):ue=t[27];let de=ue,fe=w&&de.left>0,pe=!!S,[me,he]=Z.useState(!1),ge,_e;t[28]!==me||t[29]!==x||t[30]!==y?(ge=()=>{if(x){he(!1);return}if(y){he(!0);return}if(!me)return;let e=window.setTimeout(()=>he(!1),600);return()=>window.clearTimeout(e)},_e=[y,me,x],t[28]=me,t[29]=x,t[30]=y,t[31]=ge,t[32]=_e):(ge=t[31],_e=t[32]),Z.useEffect(ge,_e);let ve=C&&(!x&&(y||me)||!!o||!!d),ye=!!_,be=!d&&!pe&&(o||!s),xe=pe||ve||fe||ye,Se=Z.useRef(null),Ce=Z.useRef(null),we=Z.useRef(null),Te,Ee;t[33]===E?(Te=t[34],Ee=t[35]):(Te=()=>{let e=Ce.current,t=we.current;if(!E||!e||!t)return;let n=t.offsetTop-e.offsetTop-(e.clientHeight-t.offsetHeight)/2,r=e.scrollHeight-e.clientHeight;e.scrollTop=Math.min(r,Math.max(0,n))},Ee=[E],t[33]=E,t[34]=Te,t[35]=Ee),Z.useLayoutEffect(Te,Ee);let De,Oe;t[36]===E?(De=t[37],Oe=t[38]):(De=()=>{if(!E)return;let e=e=>{Se.current&&!Se.current.contains(e.target)&&D(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},Oe=[E],t[36]=E,t[37]=De,t[38]=Oe),Z.useEffect(De,Oe);let ke;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(ke=()=>D(Kb),t[39]=ke):ke=t[39];let Ae=J(ke),je;t[40]!==de.active||t[41]!==de.left||t[42]!==T?(je=T(`chat.statusRow.summary.activeLeft`,{active:de.active,left:de.left}),t[40]=de.active,t[41]=de.left,t[42]=T,t[43]=je):je=t[43];let Me=je,Ne;t[44]!==U||t[45]!==fe||t[46]!==z||t[47]!==E||t[48]!==ae||t[49]!==T||t[50]!==Me||t[51]!==Ae?(Ne=fe?(0,$.jsxs)(`button`,{type:`button`,onClick:Ae,className:Y(Rd,`shrink-0`),"aria-label":Me,title:Me,children:[(0,$.jsx)(X,{name:`list-check-3`,className:Fd}),!z&&U?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,Pd),children:U.content}):(0,$.jsx)(`span`,{className:`text-xs leading-4 md:text-[0.8125rem] md:leading-5`,children:T(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:Id,"aria-hidden":`true`,children:[ae.completed,`/`,ae.total]}),E?(0,$.jsx)(X,{name:`arrow-up-s`,className:Fd}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Fd})]}):null,t[44]=U,t[45]=fe,t[46]=z,t[47]=E,t[48]=ae,t[49]=T,t[50]=Me,t[51]=Ae,t[52]=Ne):Ne=t[52];let Pe=Ne;if(!xe)return null;let Fe=!ye&&`chat-column -mt-1`,Ie;t[53]!==v||t[54]!==ye||t[55]!==L||t[56]!==Fe?(Ie=Y(`mb-1`,Fe,!ye&&sy(L),v),t[53]=v,t[54]=ye,t[55]=L,t[56]=Fe,t[57]=Ie):Ie=t[57];let Le=ye&&`px-3`,Re;t[58]===Le?Re=t[59]:(Re=Y(`flex items-center justify-between py-0.5 gap-2`,Le),t[58]=Le,t[59]=Re);let ze=!ye&&`overflow-x-hidden`,Be;t[60]===ze?Be=t[61]:(Be=Y(`flex-1 flex items-center min-w-0 gap-2`,ze),t[60]=ze,t[61]=Be);let Ve;t[62]!==g||t[63]!==A||t[64]!==pe||t[65]!==i||t[66]!==L||t[67]!==x||t[68]!==a||t[69]!==y||t[70]!==_||t[71]!==c||t[72]!==be||t[73]!==d||t[74]!==C||t[75]!==b||t[76]!==T||t[77]!==l?(Ve=pe?(0,$.jsx)(`div`,{className:`flex min-w-0 items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":T(`chat.statusRow.abortPrompt`),children:(0,$.jsxs)(`span`,{className:Y(`flex min-w-0 items-center typography-ui-label`,L?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,L?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5`,"aria-hidden":`true`})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer truncate whitespace-nowrap`,children:T(`chat.statusRow.abortPrompt`)})]})}):C&&d?(0,$.jsx)(`div`,{className:`flex h-full items-center text-[var(--status-error)]`,children:(0,$.jsxs)(`span`,{className:Y(`flex items-center typography-ui-label`,L?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,L?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`close-circle`,className:`size-3.5`,"aria-hidden":`true`})}),T(`chat.statusRow.aborted`)]})}):C&&be?(0,$.jsx)(wb,{isWorking:y,isMobile:L,statusText:b,isGenericStatus:i,isWaitingForPermission:a,retryInfo:c,turnStartedAt:l,isTurnSettled:x,agentName:g},A??`no-session`):_||null,t[62]=g,t[63]=A,t[64]=pe,t[65]=i,t[66]=L,t[67]=x,t[68]=a,t[69]=y,t[70]=_,t[71]=c,t[72]=be,t[73]=d,t[74]=C,t[75]=b,t[76]=T,t[77]=l,t[78]=Ve):Ve=t[78];let He;t[79]!==Be||t[80]!==Ve?(He=(0,$.jsx)(`div`,{className:Be,children:Ve}),t[79]=Be,t[80]=Ve,t[81]=He):He=t[81];let Ue=!ye&&`-mr-3`,We;t[82]===Ue?We=t[83]:(We=Y(`relative flex items-center gap-2 flex-shrink-0`,Ue),t[82]=Ue,t[83]=We);let Ge;t[84]!==ee||t[85]!==fe||t[86]!==E||t[87]!==ae||t[88]!==T||t[89]!==V?(Ge=E&&fe&&(0,$.jsxs)(`div`,{style:$d,className:Y(Qd,`absolute right-0 bottom-full mb-1 z-50`,`animate-in fade-in-0 zoom-in-95 slide-in-from-bottom-2`,`duration-150`),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] px-3 py-2.5`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,children:T(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,children:[ae.completed,`/`,ae.total]})]}),(0,$.jsx)(`ul`,{ref:Ce,className:Ld,children:V.map((e,t)=>(0,$.jsx)(zd,{todo:e,isActive:e===ee,activeRef:e===ee?we:void 0},e.id??`todo-${t}`))})]}),t[84]=ee,t[85]=fe,t[86]=E,t[87]=ae,t[88]=T,t[89]=V,t[90]=Ge):Ge=t[90];let Ke;t[91]!==We||t[92]!==Ge||t[93]!==Pe?(Ke=(0,$.jsxs)(`div`,{className:We,ref:Se,children:[Pe,Ge]}),t[91]=We,t[92]=Ge,t[93]=Pe,t[94]=Ke):Ke=t[94];let qe;t[95]!==Re||t[96]!==He||t[97]!==Ke?(qe=(0,$.jsxs)(`div`,{className:Re,children:[He,Ke]}),t[95]=Re,t[96]=He,t[97]=Ke,t[98]=qe):qe=t[98];let Je;return t[99]!==Ie||t[100]!==qe?(Je=(0,$.jsx)(`div`,{className:Ie,style:Nb,children:qe}),t[99]=Ie,t[100]=qe,t[101]=Je):Je=t[101],Je};function Ib(e){return e.currentSessionId}function Lb(e){return e.isMobile}function Rb(e){return e.status!==`cancelled`}function zb(e){return e.status===`in_progress`}function Bb(e){return e.status===`pending`}function Vb(e){return e.status===`in_progress`}function Hb(e){return e.status!==`cancelled`}function Ub(e){return e.status===`completed`}function Wb(e){return e.status===`in_progress`}function Gb(e){return e.status===`in_progress`||e.status===`pending`}function Kb(e){return!e}var qb=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),Jb=e=>`insertions`in e,Yb=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},Xb=e=>{let t=0,n=0;for(let r of e.split(`
|
|
6532
|
-
`))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},Zb=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!qb.has(r.tool))continue;let e=r.state;if(e.status&&e.status!==`completed`)continue;let i=t.length,a=e.metadata,o=Array.isArray(a?.files)?a.files:[];for(let e of o){if(!e||typeof e!=`object`)continue;let i=e,a=i.relativePath||i.filePath||``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:Yb(i.additions)??void 0,deletions:Yb(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(o.length===0&&a?.filediff&&typeof a.filediff==`object`){let e=a.filediff,i=typeof e.file==`string`?e.file:``;i&&!n.has(i)&&(n.add(i),t.push({path:i,tool:r.tool,partId:r.id,messageID:r.messageID,additions:Yb(e.additions)??void 0,deletions:Yb(e.deletions)??void 0,patch:typeof e.patch==`string`?e.patch:void 0}))}if(o.length===0&&Array.isArray(a?.results))for(let e of a.results){if(!e||typeof e!=`object`)continue;let i=e.filediff;if(!i||typeof i!=`object`)continue;let a=typeof i.file==`string`?i.file:``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:Yb(i.additions)??void 0,deletions:Yb(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(t.length===i){let i=e.input,a=typeof i?.filePath==`string`?i.filePath:typeof i?.file_path==`string`?i.file_path:typeof i?.path==`string`?i.path:void 0;a&&!n.has(a)&&(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID}))}if(t.length===i){let e=typeof a?.patch==`string`?a.patch.trim():typeof a?.diff==`string`?a.diff.trim():``;if(e&&!n.has(`Diff`)){n.add(`Diff`);let i=Xb(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},Qb=(e,t,n)=>{let r=[];for(let i of e){let e=i.index?.trim()??``,a=i.working_dir?.trim()??``,o=!!(e&&e!==`?`),s=!!(a||e===`?`),c=a||e;if(!c||c===`!`)continue;let l=t?.[i.path];r.push({path:Mn(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},$b=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},ex=(e,t)=>jn(e,t),tx=(e,t)=>{let n=Jb(e)&&e.relativePath?e.relativePath:ex(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},nx=e=>Jb(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},rx=2;function ix(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t)}}function ax(e,t=rx){let n=e??``,r=n.startsWith(`/`),i=n.split(`/`).filter(Boolean);if(i.length===0)return{prefix:``,parent:``,stem:``,ext:``,name:``,leadingSlash:r};let a=i[i.length-1]??``,{stem:o,ext:s}=ix(a),c=Math.max(1,Math.floor(t)),l=Math.min(i.length-1,c-1),u=i.length-1-l,d=l>0?i.slice(u,-1).join(`/`):``,f=i.slice(0,u).join(`/`),p=f?r?`/${f}`:f:``;return{prefix:p,parent:d,stem:o,ext:s,name:a,leadingSlash:r&&!p}}function ox(e){let t=(0,Q.c)(36),{path:n,className:r,title:i,dirClassName:a,nameClassName:o}=e,s=a===void 0?`text-muted-foreground`:a,c=o===void 0?`text-foreground`:o,l;t[0]===n?l=t[1]:(l=ax(n),t[0]=n,t[1]=l);let{prefix:u,parent:d,stem:f,ext:p,leadingSlash:m}=l,h=!!(u||d),g;t[2]===r?g=t[3]:(g=Y(`flex min-w-0 items-baseline overflow-hidden`,r),t[2]=r,t[3]=g);let _=i??n,v;t[4]!==s||t[5]!==m?(v=m?(0,$.jsx)(`span`,{className:Y(`shrink-0`,s),children:`/`}):null,t[4]=s,t[5]=m,t[6]=v):v=t[6];let y;t[7]!==s||t[8]!==u?(y=u?(0,$.jsx)(`span`,{className:Y(`min-w-0 shrink-[9999] truncate`,s),children:u}):null,t[7]=s,t[8]=u,t[9]=y):y=t[9];let b;t[10]!==s||t[11]!==d||t[12]!==u?(b=d?(0,$.jsxs)(`span`,{className:Y(`shrink-0`,s),children:[u?`/`:``,d]}):null,t[10]=s,t[11]=d,t[12]=u,t[13]=b):b=t[13];let x;t[14]!==s||t[15]!==h?(x=h?(0,$.jsx)(`span`,{className:s,children:`/`}):null,t[14]=s,t[15]=h,t[16]=x):x=t[16];let S;t[17]===c?S=t[18]:(S=Y(`min-w-0 truncate`,c),t[17]=c,t[18]=S);let C;t[19]!==f||t[20]!==S?(C=(0,$.jsx)(`span`,{className:S,children:f}),t[19]=f,t[20]=S,t[21]=C):C=t[21];let w;t[22]!==p||t[23]!==c?(w=p?(0,$.jsx)(`span`,{className:Y(`shrink-0`,c),children:p}):null,t[22]=p,t[23]=c,t[24]=w):w=t[24];let T;t[25]!==C||t[26]!==w||t[27]!==x?(T=(0,$.jsxs)(`span`,{className:`flex min-w-0 shrink items-baseline`,children:[x,C,w]}),t[25]=C,t[26]=w,t[27]=x,t[28]=T):T=t[28];let E;return t[29]!==T||t[30]!==g||t[31]!==_||t[32]!==v||t[33]!==y||t[34]!==b?(E=(0,$.jsxs)(`span`,{className:g,title:_,children:[v,y,b,T]}),t[29]=T,t[30]=g,t[31]=_,t[32]=v,t[33]=y,t[34]=b,t[35]=E):E=t[35],E}var sx=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=Xn(),o;t[0]===a?o=t[1]:(o=a(`chat.changedFiles.title`),t[0]=a,t[1]=o);let s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`span`,{className:ef,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Vd,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:tf,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;if(t[9]!==r||t[10]!==n||t[11]!==i||t[12]!==a){let e;t[14]!==r||t[15]!==i||t[16]!==a?(e=(e,t)=>{let{fileName:n,dirPart:o}=tx(e,r),s=nx(e);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`relative flex w-full cursor-pointer items-center gap-2.5 outline-hidden select-none text-left hover:bg-interactive-hover`,Nd),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(ig,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(ox,{path:o?`${o}/${n}`:n,title:e.path,className:`min-w-0 flex-1`}),s.additions>0||s.deletions>0?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-baseline gap-1 text-xs tabular-nums leading-4 md:text-[0.8125rem] md:leading-5`,children:[s.additions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,s.additions]}):null,s.deletions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,s.deletions]}):null]}):null]},`${e.path}:${t}`)},t[14]=r,t[15]=i,t[16]=a,t[17]=e):e=t[17],u=n.map(e),t[9]=r,t[10]=n,t[11]=i,t[12]=a,t[13]=u}else u=t[13];let d;t[18]===u?d=t[19]:(d=(0,$.jsx)(`div`,{className:Ld,children:u}),t[18]=u,t[19]=d);let f;return t[20]!==l||t[21]!==d?(f=(0,$.jsxs)($.Fragment,{children:[l,d]}),t[20]=l,t[21]=d,t[22]=f):f=t[22],f},cx=`${Qd} origin-[var(--transform-origin)]`,lx=$d,ux=Z.memo(()=>{let e=(0,Q.c)(65),{t}=Xn(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=bd()??null,o=Z.useContext(En),s=$l(a),c;e[0]===a?c=e[1]:(c=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=c);let l=gu(c),u=gu(dx),d=Ll(),f,p;e[2]===n?(f=e[3],p=e[4]):(f=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},p=[n],e[2]=n,e[3]=f,e[4]=p),Z.useEffect(f,p);let m;bb0:{if(!a||s!==!0||!l||l.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],m=t;break bb0}let t;e[6]!==a||e[7]!==l.diffStats||e[8]!==l.files?(t=Qb(l.files,l.diffStats,a),e[6]=a,e[7]=l.diffStats,e[8]=l.files,e[9]=t):t=e[9],m=t}let h=m,g=0,_=0;if(e[10]!==g||e[11]!==h||e[12]!==_){for(let e of h)g+=e.insertions,_+=e.deletions;e[10]=g,e[11]=h,e[12]=_,e[13]=g,e[14]=_}else g=e[13],_=e[14];let v;e[15]!==g||e[16]!==_?(v={totalAdded:g,totalRemoved:_},e[15]=g,e[16]=_,e[17]=v):v=e[17];let{totalAdded:y,totalRemoved:b}=v;if(!a||s!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!Jb(e))return;r(!1);let t=e.path;if(d){d.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=K.getState(),s=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,s);return}i.navigateToDiff(e.relativePath,s),i.setRightSidebarOpen(!1)},e[18]=a,e[19]=d,e[20]=o?.editor,e[21]=x):x=e[21];let S=x,C=h.length,w;e[22]!==C||e[23]!==t?(w=t(C===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:C}),e[22]=C,e[23]=t,e[24]=w):w=e[24];let T=w,E;e[25]!==a||e[26]!==u||e[27]!==n||e[28]!==o?(E=()=>{let e=!n;r(e),!(!e||!a||!o?.git)&&u(a,o.git,{silent:!0})},e[25]=a,e[26]=u,e[27]=n,e[28]=o,e[29]=E):E=e[29];let D=E,O;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(O=Y(Rd,`yuri-pending-changes-trigger max-w-full text-left`),e[30]=O):O=e[30];let k,A;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(X,{name:`file-edit`,className:Fd}),k=Y(Pd,`shrink-0`),e[31]=k,e[32]=A):(k=e[31],A=e[32]);let j;e[33]===T?j=e[34]:(j=(0,$.jsx)(`span`,{className:k,children:T}),e[33]=T,e[34]=j);let M;e[35]===Symbol.for(`react.memo_cache_sentinel`)?(M=Y(`status-row__changed-label`,Pd),e[35]=M):M=e[35];let N;e[36]===t?N=e[37]:(N=t(`chat.pendingChanges.changedInWorkspace`),e[36]=t,e[37]=N);let P;e[38]===N?P=e[39]:(P=(0,$.jsx)(`span`,{className:M,children:N}),e[38]=N,e[39]=P);let F;e[40]===Symbol.for(`react.memo_cache_sentinel`)?(F=Y(Id,`items-baseline gap-0.5`),e[40]=F):F=e[40];let I;e[41]===y?I=e[42]:(I=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,y]}):null,e[41]=y,e[42]=I);let L;e[43]===b?L=e[44]:(L=b>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,b]}):null,e[43]=b,e[44]=L);let R;e[45]!==I||e[46]!==L?(R=(0,$.jsxs)(`span`,{className:F,children:[I,L]}),e[45]=I,e[46]=L,e[47]=R):R=e[47];let z;e[48]===n?z=e[49]:(z=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:Fd}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Fd}),e[48]=n,e[49]=z);let B;e[50]!==D||e[51]!==n||e[52]!==j||e[53]!==P||e[54]!==R||e[55]!==z?(B=(0,$.jsxs)(`button`,{type:`button`,className:O,onClick:D,"aria-expanded":n,children:[A,j,P,R,z]}),e[50]=D,e[51]=n,e[52]=j,e[53]=P,e[54]=R,e[55]=z,e[56]=B):B=e[56];let V;e[57]!==a||e[58]!==h||e[59]!==S||e[60]!==n?(V=n&&(0,$.jsx)(`div`,{style:lx,className:Y(cx,`absolute left-0 bottom-full mb-1 z-50`,`animate-in fade-in-0 zoom-in-95 slide-in-from-bottom-2`,`duration-150`),children:(0,$.jsx)(sx,{files:h,currentDirectory:a,onOpenFile:S})}),e[57]=a,e[58]=h,e[59]=S,e[60]=n,e[61]=V):V=e[61];let H;return e[62]!==B||e[63]!==V?(H=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[B,V]}),e[62]=B,e[63]=V,e[64]=H):H=e[64],H});ux.displayName=`PendingChangesBar`;function dx(e){return e.fetchStatus}var fx=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=Xn(),s=a===`compact`;if(s&&!n)return null;let c=a==="default"&&`absolute left-1/2 bottom-full mb-2 -translate-x-1/2`,l=a===`expanded`&&`absolute left-1/2 -translate-x-1/2 yuri-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`yuri-scroll-to-bottom--compact relative shrink-0`,d;t[0]!==a||t[1]!==c||t[2]!==l||t[3]!==u||t[4]!==n?(d=Y(c,l,u,n?Y(`pointer-events-auto`,a==="default"&&`opacity-100`):Y(`opacity-0 pointer-events-none`,a===`expanded`&&`yuri-scroll-to-bottom--hidden`)),t[0]=a,t[1]=c,t[2]=l,t[3]=u,t[4]=n,t[5]=d):d=t[5];let f=s?`ghost`:`outline`,p=s?`composer-mobile-actions h-8 w-8 rounded-none bg-transparent hover:bg-transparent text-foreground`:`size-8 rounded-full [corner-shape:round] bg-background/95 hover:bg-interactive-hover`,m;t[6]===p?m=t[7]:(m=Y(`p-0 shadow-none`,p),t[6]=p,t[7]=m);let h;t[8]===o?h=t[9]:(h=o(`chat.scrollToBottom.aria`),t[8]=o,t[9]=h);let g=s?`size-5`:`size-4`,_=s?`medium`:`regular`,v;t[10]!==g||t[11]!==_?(v=(0,$.jsx)(X,{name:`arrow-down`,className:g,weight:_}),t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==r||t[14]!==v||t[15]!==f||t[16]!==m||t[17]!==h?(y=(0,$.jsx)(er,{variant:f,size:`sm`,onClick:r,className:m,"aria-label":h,children:v}),t[13]=r,t[14]=v,t[15]=f,t[16]=m,t[17]=h,t[18]=y):y=t[18];let b;return t[19]!==y||t[20]!==d?(b=(0,$.jsx)(`div`,{className:d,children:y}),t[19]=y,t[20]=d,t[21]=b):b=t[21],b}),px=Z.createContext(`default`),mx=()=>Z.useContext(px),hx=500,gx=e=>{let t=(0,Q.c)(31),{onCycleAgent:n,onOpenAgentPanel:r,className:i,agentName:a,agents:o,disabled:s}=e,c;t[0]===o?c=t[1]:(c=o===void 0?[]:o,t[0]=o,t[1]=c);let l=c,u=s!==void 0&&s,d=a??void 0,f;t[2]!==l||t[3]!==d?(f=ai(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=ay(d),h;t[5]===d?h=t[6]:(h=os(d),t[5]=d,t[6]=h);let g=h,_=Z.useRef(null),v=Z.useRef(!1),y;t[7]!==u||t[8]!==r?(y=e=>{e.preventDefault(),!u&&(v.current=!1,_.current=setTimeout(()=>{v.current=!0,r()},hx))},t[7]=u,t[8]=r,t[9]=y):y=t[9];let b=y,x;t[10]!==u||t[11]!==n?(x=()=>{_.current&&=(clearTimeout(_.current),null),!u&&!v.current&&n()},t[10]=u,t[11]=n,t[12]=x):x=t[12];let S=x,C;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{_.current&&=(clearTimeout(_.current),null)},t[13]=C):C=t[13];let w=C,T,E;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(E=()=>()=>{_.current&&clearTimeout(_.current)},T=[],t[14]=T,t[15]=E):(T=t[14],E=t[15]),Z.useEffect(E,T);let D;t[16]===i?D=t[17]:(D=Y(`inline-flex flex-shrink-0 items-center select-none focus:outline-none touch-none disabled:cursor-not-allowed disabled:opacity-40`,py,i),t[16]=i,t[17]=D);let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[18]=O):O=t[18];let k;t[19]!==g.var||t[20]!==p||t[21]!==d||t[22]!==m?(k=(0,$.jsx)(iy,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,labelGapClassName:`pl-1 pr-0.5`,colorVar:g.var}),t[19]=g.var,t[20]=p,t[21]=d,t[22]=m,t[23]=k):k=t[23];let A;return t[24]!==p||t[25]!==u||t[26]!==b||t[27]!==S||t[28]!==D||t[29]!==k?(A=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:_x,onMouseDown:vx,className:D,style:O,title:p,"aria-label":p,children:k}),t[24]=p,t[25]=u,t[26]=b,t[27]=S,t[28]=D,t[29]=k,t[30]=A):A=t[30],A};function _x(e){return e.preventDefault()}function vx(e){return e.preventDefault()}var yx=e=>{let t=(0,Q.c)(28),{onOpenModel:n,className:r,providerID:i,modelID:a,provider:o,variant:s,disabled:c}=e,l=c!==void 0&&c,{t:u}=Xn(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=vi(o,a,u(`chat.modelControls.selectModel`)),t[0]=a,t[1]=o,t[2]=u,t[3]=d):d=t[3];let f=d,p;t[4]===s?p=t[5]:(p=s?.trim()?Za(s):null,t[4]=s,t[5]=p);let m=p,h=m?`${f} ${m}`:f,g;t[6]===r?g=t[7]:(g=Y(`inline-flex min-w-0 max-w-36 items-stretch`,`rounded-lg`,`focus:outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,r),t[6]=r,t[7]=g);let _;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(_={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[8]=_):_=t[8];let v;t[9]!==a||t[10]!==i?(v=a||i?(0,$.jsx)(Os,{modelId:a,providerId:i,className:`size-4 flex-shrink-0`}):null,t[9]=a,t[10]=i,t[11]=v):v=t[11];let y;t[12]===f?y=t[13]:(y=(0,$.jsx)(`span`,{className:`truncate text-[11px] leading-none font-medium text-foreground/80`,children:f}),t[12]=f,t[13]=y);let b;t[14]===m?b=t[15]:(b=m?(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] leading-none font-normal text-muted-foreground`,children:m}):null,t[14]=m,t[15]=b);let x;t[16]!==y||t[17]!==b?(x=(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[y,b]}),t[16]=y,t[17]=b,t[18]=x):x=t[18];let S;t[19]!==v||t[20]!==x?(S=(0,$.jsxs)(`span`,{className:`flex h-full w-full min-w-0 items-center gap-1`,children:[v,x]}),t[19]=v,t[20]=x,t[21]=S):S=t[21];let C;return t[22]!==h||t[23]!==l||t[24]!==n||t[25]!==S||t[26]!==g?(C=(0,$.jsx)(`button`,{type:`button`,disabled:l,onClick:n,onMouseDown:bx,onPointerDownCapture:xx,className:g,style:_,title:h,"aria-label":h,children:S}),t[22]=h,t[23]=l,t[24]=n,t[25]=S,t[26]=g,t[27]=C):C=t[27],C};function bx(e){return e.preventDefault()}function xx(e){e.preventDefault()}var Sx={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Cx=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function wx(e,t){let n=(0,Q.c)(6),r=vo(e??``,t),i=oo(e??``,t),a=Ca(e??``,t),o=Da(e??``,t),s=Fa(e??``,t),c=Wa(t),l;bb0:{if(!e){l=Sx;break bb0}if(o.length>0||s.length>0){l=Sx;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=Cx({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=Sx;break bb0}if(!y){l=Sx;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var Tx=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Ex=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Dx=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Ox=(e,t)=>e.id===t.id&&e.directory===t.directory,kx=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Ax=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Dx(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Ox(e.parentTarget,i)&&kx(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},jx=e=>{let{inFlight:t,establishing:n}=e.sendPhase,r=!n&&(e.draftSubmitting||t);return{sendDisabled:!e.canSend||!e.hasSessionTarget||e.submissionBlocked||r,queueDisabled:!e.hasSessionTarget||e.submissionBlocked||!n&&t||e.queueFrozen&&!e.queueFallbackAvailable,disabledClass:`opacity-30 pointer-events-none`}},Mx=`data-mobile-overlay-active`,Nx=e=>Array.from(e).some(e=>e.getAttribute(Mx)!==`false`),Px=`artful.bionic.cosmic.disco.focal.groovy.jammy.kinetic.lunar.noble.bold.brave.calm.eager.gentle.happy.keen.lively.merry.swift.warm.wise.bright.clever.daring.agile.crisp.fresh.lucid.quick.sharp.vivid.zealous`.split(`.`),Fx=`aardvark.beaver.chipmunk.dolphin.falcon.gopher.hedgehog.jackal.koala.lemur.mongoose.narwhal.otter.pangolin.quokka.raccoon.salamander.toucan.walrus.yak.zebra.badger.condor.dingo.egret.ferret.gecko.heron.iguana`.split(`.`);function Ix(){return`${Px[Math.floor(Math.random()*Px.length)]}-${Fx[Math.floor(Math.random()*Fx.length)]}`}function Lx(e){let t=Ix();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var Rx=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,zx=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),Bx=(e,t,n)=>{let r=t.agentName?.trim()||void 0,i=t.providerId?.trim()||void 0,a=t.modelId?.trim()||void 0;!r||!i||!a||(n.saveSessionAgentSelection(e,r),n.saveSessionModelSelection(e,i,a),n.saveAgentModelForSession(e,r,i,a),n.saveAgentModelVariantForSession(e,r,i,a,t.variant))},Vx=async(e,t)=>{await Oo(e)&&await Ha(t)},Hx=e=>{let t=Rx(e),n=Ia.getState().projects;if(n.length===0)return null;let r=Ia.getState().getActiveProject();if(r?.path){let e=Rx(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=Rx(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>Rx(t.path).length-Rx(e.path).length)[0];return i?{id:i.id,path:i.path}:null},Ux=!1,Wx=async(e,t)=>{try{let n=Ia.getState().projects.find(e=>e.id===t.id)??Ia.getState().projects.find(e=>Rx(e.path)===Rx(t.path)),r=gr(t.path);await Ko.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Ko.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),Bx(e,zx(Ko.getState()),ur.getState())}catch{}},Gx=async(e,t,n)=>{let r=wa.getState(),i=Ko.getState();r.initializeNewYuriSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await Wx(e,n),le.getState().setDirectory(t.path,{showOverlay:!1})},Kx=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,qx=async e=>{if(Ux)return null;let t=Ia.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return ji.error(`No active project`,{description:`Please select a project first.`}),null;let r=Hx(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return ji.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await Cs(r.path)}catch{}if(!i)return ji.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;Ux=!0;try{let t=ca(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?Kx(n):Lx(),a=n?`existing`:`new`,o=wa.getState();o.newSessionDraft?.open?o.overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:o.newSessionDraft.directoryOverride??r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}):o.openNewSessionDraft({selectedProjectId:r.id,directoryOverride:r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt});let s=await Ss(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(wa.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),le.getState().setDirectory(s.path,{showOverlay:!1}));let c=await fo(r),l=await eu(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return ts(t,l.path),wa.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),le.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=wa.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(Wo(n,e instanceof Error?e:Error(t)),wa.getState().resolvePendingDraftWorktreeTarget(n,null)),wa.getState().setDraftBootstrapPendingDirectory(null),ji.error(`Failed to create worktree`,{description:t}),null}finally{Ux=!1}};async function Jx(){return qx()}async function Yx(e){let t=e.branch?.trim();return t?qx({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function Xx(e,t,n,r){if(Ux)return null;Ux=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=Hx(e);if(!s)throw Error(`Project is not registered in Yuri`);let c=!1;try{c=await Cs(s.path)}catch{}if(!c)return ji.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await fo(s),u=await Ns(s.path);try{let e=await eu(s,{preferredName:a,mode:`new`,branchName:a,worktreeName:r?.worktreeName||a,startRef:i,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl,setupCommands:l,returnAfterDirectoryCreated:r?.returnAfterDirectoryCreated}),t={...e,createdFromBranch:r?.createdFromBranch||u||i,kind:o};await Vx(s,e.path);let n=await wa.getState().createSession(void 0,e.path);if(!n)throw await Ls(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await Gx(n.id,t,s),{id:n.id,branch:e.branch||a,path:e.path}}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree session`;return ji.error(`Failed to create worktree`,{description:t}),null}}finally{Ux=!1}}var Zx=e=>{let t=e.trim();if(!t)return null;let n=t.match(/\/issues\/(\d+)(?:\b|\/|$)/i);if(n){let e=Number(n[1]);return Number.isFinite(e)&&e>0?e:null}let r=t.match(/^#?(\d+)$/);if(r){let e=Number(r[1]);return Number.isFinite(e)&&e>0?e:null}return null},Qx=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`};function $x({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=Xn(),{github:a}=On(),o=oc(),s=o.data??null,c=o.isFetched,l=K(e=>e.setSettingsDialogOpen),u=K(e=>e.setSettingsPage),d=K(e=>e.isMobile),{isTablet:f}=Kc(),p=d||f,m=Ia(e=>e.getActiveProject()),h=le(e=>e.currentDirectory),g=Z.useMemo(()=>m?.path?.trim()||h?.trim()||null,[m?.path,h]),[_,v]=Z.useState(``),[y,b]=Z.useState(!1),[x,S]=Z.useState(null),C=Z.useRef(0),w=Z.useMemo(()=>Zx(_),[_]),T=au(_,350),E=w?``:T.trim(),D=!!w||_===T,O=e&&D&&!!g&&!!a?.issuesList&&!(c&&s?.connected===!1),k=Sn({queryKey:Tn.scoped(`github-issues`,g,E),enabled:O,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(g,{page:e,...E?{query:E}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),A=D?k.data?.pages.at(-1)??null:null,j=D?k.data?.pages.flatMap(e=>e.issues??[])??[]:[],M=D&&k.hasNextPage,N=!w&&!D||k.isLoading,P=D&&k.isFetchingNextPage,F=D&&k.error?k.error instanceof Error?k.error.message:String(k.error):null,I=Z.useCallback(()=>k.refetch(),[k]),L=Z.useCallback(async()=>{try{await k.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[k,i]);Z.useEffect(()=>{e||(++C.current,v(``),b(!1),S(null))},[e]),Z.useEffect(()=>{++C.current},[e,g]);let R=!c||s?.connected!==!1&&A?.connected!==!1,z=A?.repo?.url??null,B=Z.useCallback(()=>{u(`github`),l(!0)},[l,u]),V=Z.useCallback(()=>{let e=Ko.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),H=Z.useCallback(()=>{let e=Ko.getState(),t=e.settingsDefaultModel??(e.currentModelId?void 0:e.opencodeDefaultModel);if(!t)return null;let n=Po(t);if(!n)return null;let{providerId:r,modelId:i}=n;return{providerID:r,modelID:i}},[]),U=Z.useCallback((e,t)=>{let n=Ko.getState(),r=Po(n.settingsDefaultModel??n.opencodeDefaultModel),i=r?.providerId===e&&r.modelId===t?r.variant??n.settingsDefaultVariant:void 0,a=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0;return i??a},[]),W=Z.useCallback(async(e,o)=>{let s=++C.current,c=()=>C.current===s;if(n===`select`){if(!g){ji.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){ji.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(x)return;S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){ji.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){ji.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=Qx({repo:n.repo,issue:s,comments:u});r&&r({number:s.number,title:s.title,url:s.url,contextText:d,author:s.author?{login:s.author.login,avatarUrl:s.author.avatarUrl}:void 0}),t(!1)}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&S(null)}return}if(!g){ji.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){ji.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!x){S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){ji.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){ji.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(y){let e=`issue-${r.number}-${Ix()}`,t=await Xx(g,e,void 0,{returnAfterDirectoryCreated:!0});if(!t?.id)throw Error(`Failed to create worktree session`);return{sessionId:t.id,sessionDirectory:t.path}}let e=await qa(u,g,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??g}})();if(!c())return;Ba(d,u).catch(()=>void 0);try{wa.getState().initializeNewYuriSession(d,Ko.getState().agents)}catch{}t(!1);let f=Ko.getState(),p=ur.getState().lastUsedProvider,m=H(),h=m?.providerID||f.currentProviderId||p?.providerID,_=m?.modelID||f.currentModelId||p?.modelID,v=V()||f.currentAgentName||void 0;if(!h||!_){ji.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let b=U(h,_),x=await za(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await za(`github.issue.review.instructions`);if(!c())return;let C=Qx({repo:n.repo,issue:r,comments:l});wa.getState().sendMessage(x,h,_,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],b,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),ji.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&S(null)}}},[y,a,n,t,r,g,V,H,U,x,i]),ee=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),te=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),ne=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Ks,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:_,onChange:e=>{v(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(d?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[g?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.noActiveProject`)}),a?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.runtimeUnavailable`)}),N?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.issues`)]}):null,R===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:i(`session.githubIssuePicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:B,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,F?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:F}):null,w&&g&&a&&R?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===w&&`bg-interactive-selection/30`),onClick:()=>void W(w),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:i(`session.githubIssuePicker.actions.useIssue`,{number:w})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===w?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,j.length===0&&!N&&!F&&R&&a&&g?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:T.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,j.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===e.number&&`bg-interactive-selection/30`),onClick:()=>void W(e.number,e.sourceRepo),children:[(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground w-12 text-right flex-shrink-0`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsx)(`p`,{className:`typography-small text-foreground truncate`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,p?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":i(`session.githubIssuePicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),M&&R&&g&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void L(),disabled:P||!!x,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(P||!!x)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:P?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.more`)]}):i(`session.githubIssuePicker.actions.loadMore`)})}):null]}),n!==`select`&&(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:i(`session.githubIssuePicker.actions.sectionTitle`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 cursor-pointer`,role:`button`,tabIndex:0,"aria-pressed":y,onClick:()=>b(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),b(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),b(e=>!e)},"aria-label":i(`session.githubIssuePicker.actions.toggleWorktreeAria`),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:y?(0,$.jsx)(X,{name:`checkbox`,className:`h-4 w-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i(`session.githubIssuePicker.actions.createInWorktree`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/70 hidden sm:inline`,children:`(issue-<number>-<slug>)`})]}),(0,$.jsx)(`div`,{className:`hidden sm:block sm:flex-1`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[z?(0,$.jsx)(er,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:z,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:I,disabled:N||!!x,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return d?(0,$.jsx)(zc,{open:e,title:ee,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:ee}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:te})]}),children:ne}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(hs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),ee]}),(0,$.jsx)(ys,{children:te})]}),ne]})})}var eS=e=>{let t=e.trim();if(!t)return null;let n=t.match(/\/pull\/(\d+)(?:\b|\/|$)/i);if(n){let e=Number(n[1]);return Number.isFinite(e)&&e>0?e:null}let r=t.match(/^#?(\d+)$/);if(r){let e=Number(r[1]);return Number.isFinite(e)&&e>0?e:null}return null},tS=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function nS({open:e,onOpenChange:t,onSelect:n}){let{t:r}=Xn(),{github:i}=On(),a=oc(),o=a.data??null,s=a.isFetched,c=K(e=>e.setSettingsDialogOpen),l=K(e=>e.setSettingsPage),u=K(e=>e.isMobile),{isTablet:d}=Kc(),f=u||d,p=Ia(e=>e.getActiveProject())?.path??null,[m,h]=Z.useState(``),[g,_]=Z.useState(!1),[v,y]=Z.useState(null),b=Z.useRef(0),x=Z.useMemo(()=>eS(m),[m]),S=au(m,350),C=x?``:S.trim(),w=!!x||m===S,T=e&&w&&!!p&&!!i?.prsList&&!(s&&o?.connected===!1),E=Sn({queryKey:Tn.scoped(`github-prs`,p,C),enabled:T,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(p,{page:e,...C?{query:C}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),D=w?E.data?.pages.at(-1)??null:null,O=w?E.data?.pages.flatMap(e=>e.prs??[])??[]:[],k=w&&E.hasNextPage,A=!x&&!w||E.isLoading,j=w&&E.isFetchingNextPage,M=w&&E.error?E.error instanceof Error?E.error.message:String(E.error):null,N=J(async()=>{try{await E.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);ji.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++b.current,h(``),_(!1),y(null))},[e]),Z.useEffect(()=>{++b.current},[e,p]);let P=!s||o?.connected!==!1&&D?.connected!==!1,F=J(()=>{l(`github`),c(!0)}),I=J(async(e,a)=>{if(!p){ji.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){ji.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(v)return;let o=++b.current,s=()=>b.current===o;y(e);try{let o=await i.prContext(p,e,{includeDiff:g,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){ji.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){ji.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){ji.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await za(`github.pr.review.instructions`);if(!s())return;n({number:o.pr.number,title:o.pr.title,url:o.pr.url,head:o.pr.head,base:o.pr.base,includeDiff:g,instructionsText:e,contextText:tS(o),author:o.pr.author?{login:o.pr.author.login,avatarUrl:o.pr.author.avatarUrl}:void 0})}t(!1)}catch(e){if(!s())return;let t=e instanceof Error?e.message:String(e);ji.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&y(null)}}),L=r(`session.githubPrPicker.title`),R=r(`session.githubPrPicker.description`),z=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Ks,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:m,onChange:e=>{h(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":g,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Ts,{checked:g,onChange:e=>_(e),ariaLabel:r(`session.githubPrPicker.includeDiffAria`)})}),(0,$.jsx)(`span`,{className:`typography-small text-muted-foreground whitespace-nowrap`,children:r(`session.githubPrPicker.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(u?`min-h-0`:`flex-1 overflow-y-auto`),children:[p?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.noActiveProject`)}),i?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.runtimeUnavailable`)}),A?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.pullRequests`)]}):null,P===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:r(`session.githubPrPicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:F,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,M?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:M}):null,x&&p&&i&&P?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===x&&`bg-interactive-selection/30`),onClick:()=>void I(x),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:r(`session.githubPrPicker.actions.usePullRequest`,{number:x})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===x?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,O.length===0&&!A&&!M&&P&&i&&p?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:S.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,O.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===e.number&&`bg-interactive-selection/30`),onClick:()=>void I(e.number,e.sourceRepo),children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsxs)(`p`,{className:`typography-small text-foreground truncate`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground mr-1`,children:[`#`,e.number]}),e.title]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,(0,$.jsxs)(`p`,{className:`typography-meta text-muted-foreground truncate`,children:[e.head,` → `,e.base]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,f?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":r(`session.githubPrPicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),k&&P&&p&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void N(),disabled:j||!!v,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(j||!!v)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:j?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.more`)]}):r(`session.githubPrPicker.actions.loadMore`)})}):null]})]});return u?(0,$.jsx)(zc,{open:e,title:L,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:L}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:R})]}),children:z}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(hs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),L]}),(0,$.jsx)(ys,{children:R})]}),z]})})}function rS(e){let t=(0,Q.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,style:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===i?a=t[5]:(a={color:`var(--surface-elevated-foreground)`,...i},t[4]=i,t[5]=a);let o;t[6]===n?o=t[7]:(o=Y(`flex h-full w-full flex-col overflow-hidden rounded-xl`,n),t[6]=n,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,$.jsx)(nf,{"data-slot":`command`,style:a,className:o,...r}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s}var iS=Z.forwardRef((e,t)=>{let n=(0,Q.c)(16),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=(a===void 0?`default`:a)===`mobileGlass`?`yuri-mobile-glass-control rounded-full`:`bg-[var(--surface-elevated)] ring-1 ring-inset ring-border/60 transition duration-200 ease-out hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)] hover:[&:not(:focus-within)]:ring-transparent focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]`,s;n[4]===o?s=n[5]:(s=Y(`flex h-8 items-center gap-2 rounded-lg px-3`,o),n[4]=o,n[5]=s);let c;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 opacity-50`}),n[6]=c):c=n[6];let l;n[7]===r?l=n[8]:(l=Y(`placeholder:text-muted-foreground flex h-8 w-full bg-transparent typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`,r),n[7]=r,n[8]=l);let u;n[9]!==i||n[10]!==t||n[11]!==l?(u=(0,$.jsx)(nf.Input,{ref:t,"data-slot":`command-input`,className:l,...i}),n[9]=i,n[10]=t,n[11]=l,n[12]=u):u=n[12];let d;return n[13]!==s||n[14]!==u?(d=(0,$.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1.5 pb-1`,children:(0,$.jsxs)(`div`,{"data-slot":`command-input-field`,className:s,children:[c,u]})}),n[13]=s,n[14]=u,n[15]=d):d=n[15],d});iS.displayName=`CommandInput`;function aS(e){let t=(0,Q.c)(14),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:r,children:n,scrollbarClassName:o,disableHorizontal:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s;t[6]===r?s=t[7]:(s=Y(`scroll-py-1 overflow-x-hidden h-full min-h-0`,r),t[6]=r,t[7]=s);let c=o??`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,l=i??!0,u;return t[8]!==n||t[9]!==a||t[10]!==s||t[11]!==c||t[12]!==l?(u=(0,$.jsx)(Xu,{as:nf.List,"data-slot":`command-list`,outerClassName:`max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0`,className:s,scrollbarClassName:c,disableHorizontal:l,...a,children:n}),t[8]=n,t[9]=a,t[10]=s,t[11]=c,t[12]=l,t[13]=u):u=t[13],u}function oS(e){let t=(0,Q.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,$.jsx)(nf.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function sS(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(nf.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function cS(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`bg-border -mx-1 h-px`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(nf.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function lS(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(nf.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var uS=(e,t)=>`${e}:${zt(t)}`,dS=e=>e.type===`skill`||!mn(e.name);function fS(e){let{t}=Xn(),n=Z.useMemo(()=>m(),[]),r=K(e=>e.globalDraftStarters),i=Ia(e=>e.activeProjectId),a=Ia(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[s,c]=Z.useState([]),l=Z.useMemo(()=>r??hn,[r]),u=l.some(dS)||s.some(dS),d=Oa({directory:e,enabled:u}),f=Z.useMemo(()=>d.data??[],[d.data]),{refetch:p}=d,h=$i({directory:e,enabled:u}),g=Z.useMemo(()=>h.data??[],[h.data]),{refetch:_}=h;Z.useEffect(()=>{let e=!1;if(!o){c([]);return}return Io(o).then(t=>{e||c(t)}).catch(()=>{e||c([])}),()=>{e=!0}},[o?.id]);let v=Z.useCallback(()=>{p(),_()},[p,_]),y=Z.useMemo(()=>new Set(f.map(e=>e.name)),[f]),b=Z.useMemo(()=>new Set(g.map(e=>e.name)),[g]),x=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=mn(e.name);return n?{id:uS(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:y.has(e.name)?{id:uS(r,e),ref:e,group:r,label:Rt(e.name),icon:dn,submitText:`/${e.name}`}:null}return b.has(e.name)?{id:uS(r,e),ref:e,group:r,label:Rt(e.name),icon:qt,submitText:`@${e.name}`}:null},[t,y,b,n]),S=Z.useMemo(()=>l.map(e=>x(e,`global`)).filter(e=>e!==null),[l,x]),C=Z.useMemo(()=>s.map(e=>x(e,`project`)).filter(e=>e!==null),[s,x]),w=Z.useMemo(()=>{let e=new Set;for(let t of l)e.add(zt(t));for(let t of s)e.add(zt(t));return e},[l,s]),T=Z.useMemo(()=>{let e=[];for(let r of Gt)n&&r.name===`craft-goal`||e.push({type:`command`,name:r.name,label:t(r.labelKey),icon:r.icon,section:`built-in`,scope:`user`});for(let t of f)t.isBuiltIn||t.source===`skill`||mn(t.name)||e.push({type:`command`,name:t.name,label:Rt(t.name),icon:dn,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of g)e.push({type:`skill`,name:t.name,label:Rt(t.name),icon:qt,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!w.has(`${e.type}:${e.name}`))},[t,f,g,w,n]),E=Z.useCallback(e=>{K.getState().setGlobalDraftStarters(e),Zt({draftStarters:e})},[]),D=Z.useCallback(e=>{c(e),o&&pa(o,e)},[o]),O=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||s.some(e=>Et(e,t)))return;D([...s,t])}else{let e=r??hn;if(e.some(e=>Et(e,t)))return;E([...e,t])}},[o,s,r,D,E]),k=Z.useCallback((e,t)=>{e===`project`?D(s.filter(e=>!Et(e,t))):E((r??hn).filter(e=>!Et(e,t)))},[s,r,D,E]),A=Z.useCallback((e,t,n)=>{let i=e===`project`?s:r??hn,a=i.findIndex(n=>uS(e,n)===t),o=i.findIndex(t=>uS(e,t)===n);if(a<0||o<0||a===o)return;let c=cd([...i],a,o);e===`project`?D(c):E(c)},[s,r,D,E]);return{global:S,project:C,pinnable:T,hasProject:!!o,ensureLoaded:v,addStarter:O,removeStarter:k,reorder:A}}var pS=`__draft-starter-trash__`,mS=`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-foreground`,hS=`max-h-7`,gS=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],_S=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=Xn(),s;t[0]===n.id?s=t[1]:(s={id:n.id},t[0]=n.id,t[1]=s);let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=ld(s),m;t[2]===d?m=t[3]:(m=od.Translate.toString(d),t[2]=d,t[3]=m);let h;t[4]!==m||t[5]!==f?(h={transform:m,transition:f},t[4]=m,t[5]=f,t[6]=h):h=t[6];let g=p&&`z-10 opacity-60`,_;t[7]===g?_=t[8]:(_=Y(`group/chip relative`,g),t[7]=g,t[8]=_);let v;t[9]!==n.submitText||t[10]!==r?(v=()=>r(n.submitText),t[9]=n.submitText,t[10]=r,t[11]=v):v=t[11];let y=!a&&`pr-5`,b;t[12]===y?b=t[13]:(b=Y(`group inline-flex touch-none select-none items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors`,`hover:bg-[var(--interactive-hover)] hover:text-foreground`,y),t[12]=y,t[13]=b);let x;t[14]===n.icon?x=t[15]:(x=(0,$.jsx)(X,{name:n.icon,className:`h-3 w-3 shrink-0 opacity-60 transition-opacity group-hover:opacity-100`}),t[14]=n.icon,t[15]=x);let S;t[16]===n.label?S=t[17]:(S=(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:n.label}),t[16]=n.label,t[17]=S);let C;t[18]!==c||t[19]!==l||t[20]!==S||t[21]!==v||t[22]!==b||t[23]!==x?(C=(0,$.jsxs)(`button`,{type:`button`,...c,...l,onClick:v,className:b,children:[x,S]}),t[18]=c,t[19]=l,t[20]=S,t[21]=v,t[22]=b,t[23]=x,t[24]=C):C=t[24];let w;t[25]!==a||t[26]!==i||t[27]!==o?(w=a?null:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},"aria-label":o(`chat.draftStarters.remove`),title:o(`chat.draftStarters.remove`),className:`absolute right-0.5 top-1/2 hidden h-4 w-4 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:text-foreground group-hover/chip:flex`,children:(0,$.jsx)(X,{name:`close`,className:`h-2.5 w-2.5`})}),t[25]=a,t[26]=i,t[27]=o,t[28]=w):w=t[28];let T;return t[29]!==u||t[30]!==C||t[31]!==w||t[32]!==h||t[33]!==_?(T=(0,$.jsxs)(`div`,{ref:u,style:h,className:_,children:[C,w]}),t[29]=u,t[30]=C,t[31]=w,t[32]=h,t[33]=_,t[34]=T):T=t[34],T},vS=e=>{let t=(0,Q.c)(14),{items:n,onSubmit:r,onRemove:i,hideRemove:a}=e,o;t[0]===n?o=t[1]:(o=n.map(CS),t[0]=n,t[1]=o);let s;if(t[2]!==a||t[3]!==n||t[4]!==i||t[5]!==r){let e;t[7]!==a||t[8]!==i||t[9]!==r?(e=e=>(0,$.jsx)(_S,{item:e,onSubmit:r,onRemove:()=>i(e),hideRemove:a},e.id),t[7]=a,t[8]=i,t[9]=r,t[10]=e):e=t[10],s=n.map(e),t[2]=a,t[3]=n,t[4]=i,t[5]=r,t[6]=s}else s=t[6];let c;return t[11]!==o||t[12]!==s?(c=(0,$.jsx)(dd,{items:o,strategy:sd,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},yS=()=>{let e=(0,Q.c)(13),{t}=Xn(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:pS},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=td(n),a;e[1]===t?a=e[2]:(a=t(`chat.draftStarters.remove`),e[1]=t,e[2]=a);let o;e[3]===t?o=e[4]:(o=t(`chat.draftStarters.remove`),e[3]=t,e[4]=o);let s=i&&`text-destructive hover:text-destructive`,c;e[5]===s?c=e[6]:(c=Y(mS,s),e[5]=s,e[6]=c);let l;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`}),e[7]=l):l=e[7];let u;return e[8]!==r||e[9]!==a||e[10]!==o||e[11]!==c?(u=(0,$.jsx)(`button`,{type:`button`,ref:r,"aria-label":a,title:o,className:c,children:l}),e[8]=r,e[9]=a,e[10]=o,e[11]=c,e[12]=u):u=e[12],u},bS=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=Xn(),o;t[0]===i?o=t[1]:(o=Y(`min-h-0`,i),t[0]=i,t[1]=o);let s;t[2]===a?s=t[3]:(s=a(`chat.draftStarters.searchPlaceholder`),t[2]=a,t[3]=s);let c;t[4]===s?c=t[5]:(c=(0,$.jsx)(iS,{placeholder:s}),t[4]=s,t[5]=c);let l;t[6]===a?l=t[7]:(l=a(`chat.draftStarters.empty`),t[6]=a,t[7]=l);let u;t[8]===l?u=t[9]:(u=(0,$.jsx)(oS,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=gS.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(sS,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(lS,{value:`${e.section} ${e.label} ${e.name}`,onSelect:()=>r(e),children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})},`${e.type}:${e.name}`))},e.key)}),t[10]=r,t[11]=n,t[12]=a,t[13]=d):d=t[13];let f;t[14]!==u||t[15]!==d?(f=(0,$.jsxs)(aS,{children:[u,d]}),t[14]=u,t[15]=d,t[16]=f):f=t[16];let p;return t[17]!==o||t[18]!==c||t[19]!==f?(p=(0,$.jsxs)(rS,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},xS=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=Xn(),[o,s]=Z.useState(!1),c;t[0]===r?c=t[1]:(c=e=>{s(e),e&&r()},t[0]=r,t[1]=c);let l;t[2]===a?l=t[3]:(l=a(`chat.draftStarters.add`),t[2]=a,t[3]=l);let u;t[4]===a?u=t[5]:(u=a(`chat.draftStarters.add`),t[4]=a,t[5]=u);let d;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`}),t[6]=d):d=t[6];let f;t[7]!==l||t[8]!==u?(f=(0,$.jsx)(bs,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:mS,children:d})}),t[7]=l,t[8]=u,t[9]=f):f=t[9];let p;t[10]===a?p=t[11]:(p=a(`chat.draftStarters.add`),t[10]=a,t[11]=p);let m;t[12]===p?m=t[13]:(m=(0,$.jsx)(hs,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(vs,{children:p})}),t[12]=p,t[13]=m);let h;t[14]===i?h=t[15]:(h=e=>{i(e),s(!1)},t[14]=i,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(bS,{pinnable:n,onPick:h,className:`flex max-h-[60vh] flex-col`}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==m||t[20]!==g?(_=(0,$.jsxs)(_s,{className:`gap-0 overflow-hidden p-0 sm:max-w-sm`,children:[m,g]}),t[19]=m,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==o||t[23]!==c||t[24]!==_||t[25]!==f?(v=(0,$.jsxs)(xs,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},SS=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=Xn(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=fS(bd()),{isMobile:f}=Kc(),[p,m]=Z.useState(!1),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),y=Z.useRef(null),b;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(b={activationConstraint:{distance:8}},t[0]=b):b=t[0];let x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(x={activationConstraint:{delay:200,tolerance:6}},t[1]=x):x=t[1];let S=ad(Qu(rd,b),Qu(ed,x)),C;t[2]!==a||t[3]!==o?(C=e=>a.find(t=>t.id===e)??o.find(t=>t.id===e),t[2]=a,t[3]=o,t[4]=C):C=t[4];let w=C,T=a.length+o.length,E;t[5]===T?E=t[6]:(E=()=>{let e=y.current;if(!e||T===0){v(!1);return}let t=()=>{let t=e.firstElementChild?.offsetHeight??28;v(e.scrollHeight>t+4)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},t[5]=T,t[6]=E);let D;t[7]!==h||t[8]!==a||t[9]!==o||t[10]!==T?(D=[T,h,a,o],t[7]=h,t[8]=a,t[9]=o,t[10]=T,t[11]=D):D=t[11],Z.useLayoutEffect(E,D);let O,k;t[12]!==_||t[13]!==h?(O=()=>{!_&&h&&g(!1)},k=[_,h],t[12]=_,t[13]=h,t[14]=O,t[15]=k):(O=t[14],k=t[15]),Z.useEffect(O,k);let A;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>m(!0),t[16]=A):A=t[16];let j=A,M;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>m(!1),t[17]=M):M=t[17];let N=M,P;t[18]!==w||t[19]!==u||t[20]!==d?(P=e=>{m(!1);let{active:t,over:n}=e;if(!n)return;let r=String(t.id),i=w(r);if(!i)return;if(String(n.id)===pS){u(i.group,i.ref);return}let a=String(n.id);if(r===a)return;let o=w(a);o&&o.group===i.group&&d(i.group,r,a)},t[18]=w,t[19]=u,t[20]=d,t[21]=P):P=t[21];let F=P,I=_||h,L;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(L={droppable:{strategy:$u.Always}},t[22]=L):L=t[22];let R;t[23]===r?R=t[24]:(R=Y(`flex min-w-0 max-w-full items-start justify-center gap-0.5`,r),t[23]=r,t[24]=R);let z=!h&&hS,B=!h&&`overflow-clip`,V;t[25]!==z||t[26]!==B?(V=Y(`flex min-w-0 flex-1 flex-wrap items-center justify-center gap-x-0.5 gap-y-0.5`,z,B),t[25]=z,t[26]=B,t[27]=V):V=t[27];let H;t[28]!==a||t[29]!==f||t[30]!==n||t[31]!==u?(H=a.length>0?(0,$.jsx)(vS,{items:a,onSubmit:n,onRemove:e=>u(`global`,e.ref),hideRemove:f}):null,t[28]=a,t[29]=f,t[30]=n,t[31]=u,t[32]=H):H=t[32];let U;t[33]!==f||t[34]!==n||t[35]!==o||t[36]!==u?(U=o.length>0?(0,$.jsx)(vS,{items:o,onSubmit:n,onRemove:e=>u(`project`,e.ref),hideRemove:f}):null,t[33]=f,t[34]=n,t[35]=o,t[36]=u,t[37]=U):U=t[37];let W;t[38]!==V||t[39]!==H||t[40]!==U?(W=(0,$.jsxs)(`div`,{ref:y,className:V,children:[H,U]}),t[38]=V,t[39]=H,t[40]=U,t[41]=W):W=t[41];let ee;t[42]!==h||t[43]!==I||t[44]!==i?(ee=I?(0,$.jsx)(`button`,{type:`button`,onClick:()=>g(wS),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:mS,children:(0,$.jsx)(X,{name:h?`arrow-up-s`:`arrow-down-s`,className:`h-3.5 w-3.5`})}):null,t[42]=h,t[43]=I,t[44]=i,t[45]=ee):ee=t[45];let te;t[46]!==l||t[47]!==c||t[48]!==p||t[49]!==f||t[50]!==s?(te=f&&p?(0,$.jsx)(yS,{}):(0,$.jsx)(xS,{pinnable:s,onOpen:c,onAdd:l}),t[46]=l,t[47]=c,t[48]=p,t[49]=f,t[50]=s,t[51]=te):te=t[51];let ne;t[52]!==ee||t[53]!==te?(ne=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 self-start`,children:[ee,te]}),t[52]=ee,t[53]=te,t[54]=ne):ne=t[54];let re;t[55]!==R||t[56]!==W||t[57]!==ne?(re=(0,$.jsxs)(`div`,{className:R,children:[W,ne]}),t[55]=R,t[56]=W,t[57]=ne,t[58]=re):re=t[58];let G;return t[59]!==F||t[60]!==S||t[61]!==re?(G=(0,$.jsx)(id,{sensors:S,collisionDetection:nd,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:re}),t[59]=F,t[60]=S,t[61]=re,t[62]=G):G=t[62],G};function CS(e){return e.id}function wS(e){return!e}function TS(e){let t=(0,Q.c)(27),{branches:n,search:r,local:i,currentBranch:a,branchInfo:o,onCheckout:s}=e,{t:c}=Xn(),l;if(t[0]!==n||t[1]!==r){let e=r.trim();l=e?Bi(n,e,DS).map(ES):n,t[0]=n,t[1]=r,t[2]=l}else l=t[2];let u=l,d=i?`gitView.branch.localBranches`:`gitView.branch.remoteBranches`,f;t[3]!==c||t[4]!==d?(f=c(d),t[3]=c,t[4]=d,t[5]=f):f=t[5];let p;if(t[6]!==o||t[7]!==a||t[8]!==u||t[9]!==i||t[10]!==s||t[11]!==c){let e;t[13]!==o||t[14]!==a||t[15]!==i||t[16]!==s||t[17]!==c?(e=e=>(0,$.jsxs)(lS,{onSelect:()=>s(e),children:[i?(0,$.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),(o?.[e]?.ahead||o?.[e]?.behind)&&(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[o[e].ahead||0,` ahead ·`,` `,o[e].behind||0,` behind`]})]}):(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),i&&a===e&&(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:c(`gitView.branch.currentBadge`)})]},`${i?`local`:`remote`}-${e}`),t[13]=o,t[14]=a,t[15]=i,t[16]=s,t[17]=c,t[18]=e):e=t[18],p=u.map(e),t[6]=o,t[7]=a,t[8]=u,t[9]=i,t[10]=s,t[11]=c,t[12]=p}else p=t[12];let m;t[19]!==u.length||t[20]!==i||t[21]!==c?(m=u.length===0&&(0,$.jsx)(lS,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:c(i?`gitView.branch.noLocalBranches`:`gitView.branch.noRemoteBranches`)})}),t[19]=u.length,t[20]=i,t[21]=c,t[22]=m):m=t[22];let h;return t[23]!==f||t[24]!==p||t[25]!==m?(h=(0,$.jsxs)(sS,{heading:f,children:[p,m]}),t[23]=f,t[24]=p,t[25]=m,t[26]=h):h=t[26],h}function ES(e){return e.item}function DS(e){return e}function OS(e){let t=(0,Q.c)(9),{options:n,selectedDirectory:r,onSelect:i}=e,{t:a}=Xn(),o;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a){let e;t[5]!==i||t[6]!==r||t[7]!==a?(e=e=>(0,$.jsxs)(lS,{onSelect:()=>i(e.value),children:[(0,$.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),r===e.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:a(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`),t[5]=i,t[6]=r,t[7]=a,t[8]=e):e=t[8],o=n.map(e),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o}else o=t[4];return o}var kS=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),AS=({currentBranch:e,localBranches:t,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:o=[],disabled:s=!1,iconOnly:c=!1,trigger:l,triggerLabel:u,contentAlign:d,hideTooltip:f=!1,projectRootOption:p=null,worktreeOptions:m=[],selectedDirectory:h=null,onSelectDirectory:g,onCreateWorktree:_,worktreesLabel:v,worktreeNewLabel:y,projectRootLabel:b,onOpenChange:x,open:S,presentation:C=`dropdown`})=>{let{t:w}=Xn(),[T,E]=Z.useState(!1),[D,O]=Z.useState(``),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(``),[F,I]=Z.useState(!1),L=Z.useRef(null),R=Z.useId(),z=S??T,B=e=>{S===void 0&&E(e),x?.(e)},V=Z.useCallback(e=>{e.stopPropagation()},[]),H=o.length>1,U=!!(g||_),W=Z.useMemo(()=>kS(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?Bi(m,e,e=>e.label).map(e=>e.item):m},[D,m]),te=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||Bi([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),ne=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},re=e=>{g?.(e),B(!1),O(``)},G=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},ie=async()=>{if(!(!W||F)){if(H){M(!0);return}I(!0);try{await a(W,o[0]),P(``),A(!1),B(!1)}finally{I(!1)}}},ae=async e=>{if(!(!W||F)){I(!0);try{await a(W,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},oe=()=>{M(!1)},se=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let ce=u||e||w(`gitView.branch.detachedHead`),le=d??(c?`end`:`start`),ue=v??w(`chat.chatInput.worktrees`),de=y??w(`chat.chatInput.worktreeNew`),fe=b??w(`chat.chatInput.projectRoot`),pe=c?(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":ce,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(er,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":ce,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:ce}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),me=(0,$.jsx)(Hc,{asChild:!0,disabled:s,children:l??pe}),he=(0,$.jsxs)(rS,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(iS,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(aS,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(oS,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(sS,{children:j?(0,$.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:oe,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-4`})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,$.jsx)(`span`,{className:`text-foreground font-medium`,children:W}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ae(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,$.jsx)(X,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,$.jsx)(`input`,{ref:L,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:N,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{V(e),e.key===`Enter`?(e.preventDefault(),ie()):e.key===`Escape`&&(e.preventDefault(),se())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:ie,disabled:!W||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:se,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(lS,{onSelect:G,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(cS,{}),(0,$.jsx)(TS,{branches:t,search:D,local:!0,currentBranch:e,branchInfo:r,onCheckout:ne}),(0,$.jsx)(cS,{}),(0,$.jsx)(TS,{branches:n,search:D,onCheckout:ne}),U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(cS,{}),(0,$.jsxs)(sS,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:ue}),_?(0,$.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),B(!1),_()},children:de}):null]}),p&&te?(0,$.jsxs)(lS,{onSelect:()=>re(p.value),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:fe}),(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,(0,$.jsx)(OS,{options:ee,selectedDirectory:h,onSelect:re})]})]}):null]})]});if(C===`mobile-sheet`){let e=Z.cloneElement(l??pe,{onClick:()=>B(!0),"data-popup-open":z?``:void 0});return(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(dl,{id:`mobile-draft-branch-picker-sheet-${R}`,open:z,onOpenChange:B,ariaLabel:w(`gitView.branch.selectBranch`),closeAriaLabel:w(`mobile.surface.closeAria`),resizeAriaLabel:w(`mobile.sessions.sheet.resizeAria`),children:he})]})}return(0,$.jsxs)(Bc,{open:z,onOpenChange:B,children:[f||l?me:(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:me}),(0,$.jsx)(Js,{sideOffset:8,children:c?ce:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(kc,{align:le,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:he})]})};function jS(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=Bi(t,i,e=>e),o=Bi(n,i,e=>e),s=new Set(a.map(e=>e.item)),c=new Set(o.map(e=>e.item));return{matching:[...a.map(e=>({label:e.item,value:e.item,source:`local`,score:e.score})),...o.map(e=>({label:e.item,value:`remotes/${e.item}`,source:`remote`,score:e.score}))].sort((e,t)=>e.score===t.score?e.source===t.source?e.label.length===t.label.length?e.label.localeCompare(t.label,void 0,{sensitivity:`accent`}):e.label.length-t.label.length:e.source===`local`?-1:1:e.score-t.score).map(({label:e,value:t,source:n})=>({label:e,value:t,source:n})),otherLocal:t.filter(e=>!s.has(e)),otherRemote:n.filter(e=>!c.has(e))}}function MS(e,t){return`${e}\0${t}`}function NS({open:e,onOpenChange:t,onSelect:n}){let{t:r}=Xn(),i=K(e=>e.isMobile),{github:a}=On(),o=oc(),s=o.data??null,c=o.isFetched,l=K(e=>e.setSettingsDialogOpen),u=K(e=>e.setSettingsPage),d=Ia(e=>e.getActiveProject()),f=d?.id??null,p=d?.path??null,m=Z.useMemo(()=>p&&f?{id:f,path:p}:null,[f,p]),[h,g]=Z.useState(`issues`),[_,v]=Z.useState(``),[y,b]=Z.useState([]),[x,S]=Z.useState([]),[C,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState(null),[j,M]=Z.useState(null),[N,P]=Z.useState(!1),[F,I]=Z.useState(new Map),[L,R]=Z.useState(1),[z,B]=Z.useState(!1),V=Z.useRef(0),H=au(_,350),U=J(async e=>{if(!(!p||!a)&&!(c&&s?.connected===!1)){w(!0),O(null),R(1),B(!1);try{if(h===`issues`&&a.issuesList){let t=await a.issuesList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(t.issues??[]),R(t.page??1),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=await a.prsList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(t.prs??[]),R(t.page??1),B(!!t.hasMore))}}catch(e){O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{w(!1)}}});Z.useEffect(()=>{if(!e||!p||c&&s?.connected===!1||!a)return;if(!H.trim()){U();return}let t=new AbortController;w(!0),O(null),R(1),B(!1);let n=h===`issues`&&a.issuesList?a.issuesList(p,{page:1,query:H.trim()}):h===`prs`&&a.prsList?a.prsList(p,{page:1,query:H.trim()}):null;if(!n){w(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(e.issues??[]),R(e.page??1),B(!!e.hasMore)):`prs`in e&&(e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(e.prs??[]),R(e.page??1),B(!!e.hasMore))))}).catch(e=>{t.signal.aborted||O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||w(!1)}),()=>t.abort()},[e,p,a,c,s,h,H,U,r]);let W=J(async()=>{if(!(!p||!a)&&!(C||T)&&z){E(!0);try{let e=L+1;if(h===`issues`&&a.issuesList){let t=H.trim()?await a.issuesList(p,{page:e,query:H.trim()}):await a.issuesList(p,{page:e});t.connected!==!1&&(b(e=>[...e,...t.issues??[]]),R(t.page??e),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=H.trim()?await a.prsList(p,{page:e,query:H.trim()}):await a.prsList(p,{page:e});t.connected!==!1&&(S(e=>[...e,...t.prs??[]]),R(t.page??e),B(!!t.hasMore))}}catch{}finally{E(!1)}}});Z.useEffect(()=>{if(!e){g(`issues`),v(``),b([]),S([]),A(null),M(null),P(!1),O(null),I(new Map),R(1),B(!1);return}U()},[e,U]),Z.useEffect(()=>{V.current+=1,I(new Map)},[p,m]);let ee=J(async e=>{if(!m||!e)return;let t=MS(m.path,e);if(F.has(t))return;let n=V.current;try{let i=await Hs(m,{mode:`new`,branchName:e,worktreeName:e});if(n!==V.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);I(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==V.current)return;I(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||h!==`prs`||x.forEach(e=>{e.head&&ee(e.head)})},[e,h,x,p,m,ee]);let te=c&&s?.connected===!0,ne=()=>{u(`github`),l(!0)},re=e=>{A(e),M(null)},G=e=>{M(e),A(null)},ie=()=>{k?n({type:`issue`,item:k}):j&&n({type:`pr`,item:j,includeDiff:N}),t(!1)},ae=()=>{A(null),M(null),P(!1)},oe=k||(j?.head&&p?F.get(MS(p,j.head))?.isValid!==!1:!1),se=e=>!e.head||(p?F.get(MS(p,e.head)):void 0)?.isValid===!1,ce=(0,$.jsx)($.Fragment,{children:te?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Ks,{value:_,onChange:e=>v(e.target.value),placeholder:r(h===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[C&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),D&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:D})]})}),!C&&!D&&h===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[y.length>0?y.map(e=>(0,$.jsx)(`button`,{onClick:()=>re(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,k?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(er,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!C&&!D&&h===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[x.length>0?x.map(e=>{let t=se(e),n=e.head&&p?F.get(MS(p,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&G(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,j?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(er,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,$.jsx)(X,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:r(`session.githubIntegration.connect.title`)}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:r(`session.githubIntegration.connect.description`)})]}),(0,$.jsx)(er,{onClick:ne,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),le=(0,$.jsxs)(`div`,{className:Y(`w-full`,i?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-4`,i?`w-full justify-center order-1`:`flex-1`),children:[!i&&(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ae,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),h===`prs`&&j&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(Ts,{checked:N,onChange:e=>P(e),ariaLabel:r(`session.githubIntegration.includeDiffAria`)}),(0,$.jsx)(`span`,{className:`typography-small text-foreground`,children:r(`session.githubIntegration.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,i?`w-full order-2`:`justify-end`),children:[(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(er,{size:`sm`,onClick:ie,disabled:!oe,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(zc,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:te?le:void 0,renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:r(`session.githubIntegration.title`)}),e]}),(0,$.jsx)(`div`,{className:`w-full`,children:(0,$.jsx)(rf,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})}),(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ae,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),children:ce}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(hs,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),r(`session.githubIntegration.title`)]}),(0,$.jsx)(`div`,{className:`w-[220px]`,children:(0,$.jsx)(rf,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),ce,(0,$.jsx)(gs,{className:`mt-1`,children:le})]})})})}var PS=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},FS=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),IS=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``).split(`/`).join(`-`).replace(/[^A-Za-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80),LS=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,RS=(e,t,n)=>{let r=FS(e.head||``);if(!r)throw Error(`PR head branch is missing`);if(t.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};let i=n.find(e=>{let t=e.indexOf(`/`);return t<=0||t>=e.length-1?!1:e.slice(t+1)===r});if(i){let e=i.indexOf(`/`),t=i.slice(0,e);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:t,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${t}/${r}`}}let a=String(e.headLabel||``).split(`:`)[0]?.trim(),o=`pr-${LS(e.headRepo?.owner||a||`pr-head`)}`,s=e.headRepo?.sshUrl||e.headRepo?.cloneUrl||``;if(!s)throw Error(`PR head repository URL is unavailable`);return{existingBranch:`remotes/${o}/${r}`,setUpstream:!0,upstreamRemote:o,upstreamBranch:r,ensureRemoteName:o,ensureRemoteUrl:s,sourceLabel:`${o}/${r}`}},zS=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},BS=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function VS({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=Xn(),{github:a,git:o}=On(),s=K(e=>e.isMobile),c=Z.useId(),l=oc(),u=l.data??null,d=l.isFetched,f=Ia(e=>PS(e.projects,e.activeProjectId,r)),p=f?.path??null,m=Z.useMemo(()=>p&&f?{id:f.id,path:p}:null,[f,p]),[h,g]=Z.useState(`new-branch`),[_,v]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[y,b]=Z.useState({selectedBranch:``,worktreeName:``}),x=nu(p),S=lu(p),C=gu(e=>e.fetchBranches),w=Z.useMemo(()=>x?.all?x.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[x]),T=Z.useMemo(()=>x?.all?x.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[x]),E=wa(e=>e.availableWorktreesByProject),D=Z.useMemo(()=>{if(!p)return new Set;let e=E.get(p)??[];return new Set(e.map(e=>e.name))},[E,p]),O=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=Ix();if(!D.has(e))return e}return`${Ix()}-${Date.now().toString(36).slice(-4)}`},[D]),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(!1),[F,I]=Z.useState(!1),[L,R]=Z.useState(!1),[z,B]=Z.useState(``),[V,H]=Z.useState(``),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),te=Z.useRef(null),ne=Z.useCallback(e=>{e.stopPropagation()},[]),re=Z.useCallback(e=>{let t=e;for(;t&&t!==document.body;){let{overflowY:e}=window.getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null},[]),G=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),ie=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;G(t)},[G]),ae=Z.useCallback(e=>{let t=re(e.current);G(t)},[re,G]),oe=Z.useMemo(()=>jS({localBranches:w,remoteBranches:T,query:z}),[w,T,z]),se=Z.useMemo(()=>jS({localBranches:w,remoteBranches:T,query:V}),[w,T,V]),ce=z.trim().length>0,le=V.trim().length>0,ue=oe.matching.length>0,de=se.matching.length>0,fe=!!(p&&o),pe=Z.useCallback(()=>{!p||!o||C(p,o)},[p,o,C]);Z.useEffect(()=>{!e||!p||!o||x?.all||C(p,o)},[e,p,o,x?.all,C]),Z.useEffect(()=>{!j&&!F&&B(``)},[j,F]),Z.useEffect(()=>{!N&&!L&&H(``)},[N,L]),Z.useEffect(()=>{j&&ie(U),F&&ae(ee)},[j,F,z,ie,ae]),Z.useEffect(()=>{N&&ie(W),L&&ae(te)},[N,L,V,ie,ae]);let[me,he]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[ge,_e]=Z.useState(!1),[ve,ye]=Z.useState(null),be=Z.useCallback(()=>{let e=Ko.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),xe=Z.useCallback(()=>{let e=Ko.getState(),t=e.settingsDefaultModel??(e.currentModelId?void 0:e.opencodeDefaultModel);if(!t)return null;let n=Po(t);if(!n)return null;let{providerId:r,modelId:i}=n;return{providerID:r,modelID:i}},[]),Se=Z.useCallback((e,t)=>{let n=Ko.getState(),r=Po(n.settingsDefaultModel??n.opencodeDefaultModel),i=r?.providerId===e&&r.modelId===t?r.variant??n.settingsDefaultVariant:void 0,a=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0;return i??a},[]),Ce=Z.useCallback(async e=>{if(!p||!a)return;let t=Ko.getState(),n=ur.getState().lastUsedProvider,r=xe(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=be()||t.currentAgentName||void 0;if(!o||!s){ji.error(i(`session.newWorktree.error.noModelSelected`));return}let l=Se(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await za(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await za(`github.issue.review.instructions`),d=zS({repo:t.repo,issue:t.issue,comments:n.comments??[]});await wa.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),ji.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(p,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await za(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await za(`github.pr.review.instructions`),u=BS(t);await wa.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),ji.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,p,be,xe,Se,i]),we=h===`new-branch`?_:y;Z.useEffect(()=>{if(!e||!x?.all||!p||_.sourceBranch)return;let t=_.sourceBranch,n=!1;return(async()=>{try{let e=await Ns(p).catch(()=>null);if(n)return;let r=localStorage.getItem(Ql),{sourceBranch:i,shouldClearSavedSourceBranch:a}=cu({branches:x.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Ql),n||t)return;i&&v(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,x?.all,p,_.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;g(`new-branch`),b({selectedBranch:``,worktreeName:``}),M(!1),P(!1),I(!1),R(!1),B(``),H(``),he({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=O();v({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,O]),Z.useEffect(()=>{if(h!==`new-branch`||!_.isSyncingWorktreeName)return;let e=IS(FS(_.branchName));v(t=>({...t,worktreeName:e}))},[h,_.branchName,_.isSyncingWorktreeName]);let Te=Z.useCallback(async()=>{if(!m||!me.touched||ge)return;ve&&ve.abort();let e=new AbortController;ye(e),he(e=>({...e,isValidating:!0}));try{let t=h===`new-branch`?_.branchName:y.selectedBranch,n=we.worktreeName,r=FS(t),a=IS(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=h===`new-branch`?_.linkedPr:null,n=t?RS(t,w,T):null,i=await Hs(m,{mode:h===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(h===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||he(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||he(e=>({...e,isValidating:!1}))}},[m,h,_.branchName,_.linkedPr,y.selectedBranch,we.worktreeName,w,T,me.touched,ve,ge,i]),Ee=h===`new-branch`?_.branchName:y.selectedBranch;Z.useEffect(()=>{if(!e||!m||!me.touched||ge)return;let t=setTimeout(()=>{Te()},300);return()=>clearTimeout(t)},[we.worktreeName,Ee,e,m,Te,me.touched,ge]);let De=async()=>{if(!m||!p){ji.error(i(`session.newWorktree.error.noActiveProject`));return}he(e=>({...e,touched:!0}));let e=h===`new-branch`?_.branchName:y.selectedBranch,r=we.worktreeName,a=FS(e),o=IS(r);if(!a){ji.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){ji.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}ve&&(ve.abort(),ye(null)),he(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),_e(!0);try{let e=h===`new-branch`?_.linkedPr:null,r=h===`new-branch`?_.linkedIssue:null,s=h===`new-branch`?_.linkedPr:null,c=h===`new-branch`&&_.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([fo(m),ou(p)]),f=_.sourceBranch,g=``,v=(()=>{if(e){let t=RS(e,w,T);return g=t.sourceLabel,{preferredName:a||o,mode:`existing`,branchName:a,worktreeName:o,existingBranch:t.existingBranch,setupCommands:u,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return g=h===`new-branch`?f:``,{preferredName:a||o,mode:h===`existing-branch`?`existing`:`new`,branchName:h===`existing-branch`?void 0:a,worktreeName:o,existingBranch:h===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&h===`new-branch`?{startRef:f}:{}}})(),b=await pu(p,v,{resolvedRootTrackingRemote:d}),x=await Bs(m,b),S=null;if(l){await Oo(m)&&await Ha(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await qa(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),_e(!1),Ba(a.id,e).catch(()=>void 0);try{wa.getState().initializeNewYuriSession(a.id,Ko.getState().agents)}catch{}}else t(!1),_e(!1);let C=du({mode:h,sourceBranch:_.sourceBranch,linkedPr:!!_.linkedPr,selectedBranch:y.selectedBranch});C&&localStorage.setItem(Ql,C),ji.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${g?` ${i(`session.newWorktree.fromSource`,{source:g})}`:``}`})}),S?Ce({sessionId:S,directory:x.path,issue:r,pr:s,includeDiff:c}).catch(e=>{let t=e instanceof Error?e.message:i(`session.newWorktree.error.sendGitHubContextFailed`);ji.error(i(`session.newWorktree.error.sendGitHubContextFailed`),{description:t})}):n?.(x.path)}catch(e){let t=e instanceof Error?e.message:i(`session.newWorktree.error.createWorktreeFailed`);ji.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{_e(!1)}},Oe=e=>{g(e),he(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},ke=e=>{if(!e){v(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${Ix()}`;v(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:IS(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;v(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:IS(t.head),isSyncingWorktreeName:!0}))}},Ae=d&&u?.connected===!0,je=(h===`existing-branch`?!!y.selectedBranch&&!!y.worktreeName&&!me.branchError&&!me.worktreeError:!!FS(_.branchName)&&!!_.worktreeName&&!me.branchError&&!me.worktreeError)&&!ge,Me=()=>{v(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Ne=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,s?`w-full justify-center order-first`:`mr-auto`),children:me.touched&&(me.branchError||me.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:me.branchError||me.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s&&`w-full`),children:[(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,className:Y(s&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(er,{size:`sm`,onClick:De,disabled:!je||ge,className:Y(`gap-1.5`,s&&`flex-1`),children:[ge&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(ge?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[s?(0,$.jsx)(dl,{id:`new-worktree-sheet-${c}`,open:e,onOpenChange:t,title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(Xu,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`overscroll-contain px-4 pb-4 pt-2`,children:[(0,$.jsx)(`div`,{className:`w-full mb-4`,children:(0,$.jsx)(rf,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>Oe(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>I(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:y.selectedBranch?`text-foreground`:`text-muted-foreground`,children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(er,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(zc,{open:F,title:i(`session.newWorktree.selectBranch`),onClose:()=>I(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:ee,children:[(0,$.jsx)(Ks,{value:z,onChange:e=>B(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ce&&ue&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:IS(e.label)})),he(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),oe.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&Ae&&(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Ks,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=IS(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===IS(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===IS(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Ks,{value:we.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,me.touched&&me.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>R(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:_.sourceBranch?`text-foreground`:`text-muted-foreground`,children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})}),(0,$.jsx)(zc,{open:L,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>R(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:te,children:[(0,$.jsx)(Ks,{value:V,onChange:e=>H(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[le&&de&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:e.value})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),le&&!de&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),se.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:e})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),se.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:Me,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Ne})]})}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(hs,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-5 w-5`}),i(`session.newWorktree.title`)]}),(0,$.jsx)(`div`,{className:`w-[280px] shrink-0`,children:(0,$.jsx)(rf,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>Oe(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(Bc,{open:j,onOpenChange:M,children:[(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsxs)(er,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,y.selectedBranch?`text-foreground`:`text-muted-foreground`),children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(kc,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:U,children:(0,$.jsxs)(rS,{shouldFilter:!1,children:[(0,$.jsx)(iS,{placeholder:i(`session.newWorktree.searchBranches`),value:z,onValueChange:B,onKeyDown:ne}),(0,$.jsx)(aS,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(oS,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(sS,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(lS,{value:e.value,onSelect:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:IS(e.label)})),he(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[ce&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(lS,{value:e,onSelect:()=>{b(t=>({...t,selectedBranch:e,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),oe.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(oe.otherLocal.length>0||ce)&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(lS,{value:`remotes/${e}`,onSelect:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(er,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&Ae&&(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Ks,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=IS(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===IS(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===IS(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Ks,{value:we.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,me.touched&&me.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(Bc,{open:N,onOpenChange:P,children:[(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsxs)(er,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,_.sourceBranch?`text-foreground`:`text-muted-foreground`),children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(kc,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:W,children:(0,$.jsxs)(rS,{shouldFilter:!1,children:[(0,$.jsx)(iS,{placeholder:i(`session.newWorktree.searchBranches`),value:V,onValueChange:H,onKeyDown:ne}),(0,$.jsx)(aS,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(oS,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[le&&de&&(0,$.jsx)(sS,{heading:i(`session.newWorktree.matchingBranches`),children:se.matching.map(e=>(0,$.jsx)(lS,{value:e.value,onSelect:()=>{v(t=>({...t,sourceBranch:e.value})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),le&&!de&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),se.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[le&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:se.otherLocal.map(e=>(0,$.jsx)(lS,{value:e,onSelect:()=>{v(t=>({...t,sourceBranch:e})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),se.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(se.otherLocal.length>0||le)&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:se.otherRemote.map(e=>(0,$.jsx)(lS,{value:`remotes/${e}`,onSelect:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:Me,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)(gs,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:me.touched&&(me.branchError||me.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:me.branchError||me.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(er,{size:`sm`,onClick:De,disabled:!je||ge,className:`gap-1.5`,children:[ge&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(ge?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(NS,{open:k,onOpenChange:A,onSelect:ke})]})}function HS(e){let t=e.selectedDirectory??e.projectRootOption?.value??e.worktreeOptions[0]?.value??null;return t?e.projectRootOption?.value===t?e.projectRootOption.label?.trim()||null:e.worktreeOptions.find(e=>e.value===t)?.label?.trim()||null:null}function US(e,t){if(!e||!t)return!1;let n=t.replace(/\\/g,`/`).replace(/\/+$/,``);if(!n)return!1;let r=n===`/`?`/`:n.split(`/`).pop()||``;return!!r&&e===r}var WS=(e,t)=>e??t??null,GS=(e,t)=>!!e&&t!==!1,KS=e=>e?.length?{localBranches:e.filter(e=>!e.startsWith(`remotes/`)).sort(),remoteBranches:e.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort()}:{localBranches:[],remoteBranches:[]},qS=e=>e.replace(/^remotes\//,``).trim(),JS=e=>{let t=qS(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},YS=({directory:e,projectDirectory:t,label:n,projectRootOption:r,worktreeOptions:i,onSelectDirectory:a,className:o,maxWidthClassName:s=`max-w-[48vw] sm:max-w-[20rem]`,presentation:c=`dropdown`})=>{let{t:l}=Xn(),{git:u}=On(),d=WS(t,e),f=e,p=$l(d),m=$l(f),h=GS(d,p),g=f!==d&&GS(f,m),_=Xl(d,u,h),v=Xl(f,u,g),y=_.data,b=f===d?y:v.data,x=gu(e=>e.fetchStatus),S=gu(e=>f&&e.directories.get(f)?.status?.current?.trim()||null),[C,w]=Z.useState(!1),T=Kl(d,u,h&&C).data??[],[E,D]=Z.useState(null),[O,k]=Z.useState(!1),[A,j]=Z.useState(!1),M=Ia(e=>e.projects),N=Ia(e=>e.activeProjectId);Z.useEffect(()=>{u&&(d&&p===null&&x(d,u,{silent:!0}),f&&f!==d&&m===null&&x(f,u,{silent:!0}))},[x,u,p,m,d,f]);let P=Z.useMemo(()=>{let e=Fn(t);if(e){let t=M.find(t=>Fn(t.path)===e);if(t)return t.id}return N},[N,t,M]),{localBranches:F,remoteBranches:I}=Z.useMemo(()=>KS(y?.all),[y]),L=b?.current?.trim()||S||null,R=!US(n,e)&&n||L||n||l(`chat.chatInput.branch`),z=J(async()=>{if(!u)return;let e=new Set;d&&e.add(d),f&&e.add(f),await Promise.all([...e].map(async e=>{await hu(e,u),await x(e,u,{silent:!0})}))}),B=J(e=>{let t=qS(e),n=JS(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),V=J(async e=>{if(!f||!u)return;let t=qS(e);if(L!==t&&L!==JS(t))try{await u.checkoutBranch(f,t),ji.success(l(`gitView.toast.checkedOut`,{name:t})),await z()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});ji.error(n)}}),H=J(e=>{let t=qS(e);if(!t||L===t||L===JS(t))return;let n=B(t);if(n){a(n.value);return}D(t)}),U=J(async()=>{if(!(!E||O)){k(!0);try{await V(E),D(null)}finally{k(!1)}}}),W=J(async()=>{if(!(!E||O)){k(!0);try{await Yx({branch:E,projectDirectory:t??void 0})&&D(null)}finally{k(!1)}}}),ee=J(async(e,t)=>{if(!f||!u)return;let n=t?.name??`origin`;try{await u.createBranch(f,e,L??`HEAD`),ji.success(l(`gitView.toast.createdBranch`,{name:e})),D(e),u.gitPush(f,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await z(),ji.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);ji.warning(l(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:t})}),await z()})}catch(e){let t=e instanceof Error?e.message:l(`gitView.toast.createBranchFailed`);throw ji.error(t),e}}),te=J(()=>{let e=Ia.getState(),n=Fn(t),r=n?e.projects.find(e=>Fn(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),j(!0)}),ne=J((e,n)=>{if(j(!1),n?.sessionId){wa.getState().setCurrentSession(n.sessionId,e);return}let r=Ia.getState(),i=Fn(t),a=(i?r.projects.find(e=>Fn(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=wa.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),le.getState().setDirectory(e,{showOverlay:!1});return}o.openNewSessionDraft({...a?{selectedProjectId:a}:{},directoryOverride:e,preserveDirectoryOverride:!0})}),re=(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex min-w-0 w-fit items-center gap-1.5 rounded-lg !border-0 px-1.5 font-medium text-foreground/80`,c===`mobile-sheet`?`h-[26px] text-[11px] leading-none`:`h-6 py-1 pr-1.5 typography-micro transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5`,s,dy,o),"aria-label":R,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:R}),c===`dropdown`?(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`}):null]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(AS,{currentBranch:L,localBranches:F,remoteBranches:I,branchInfo:y?.branches,onCheckout:H,onCreate:ee,remotes:T,trigger:re,triggerLabel:R,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:te,open:C,presentation:c,onOpenChange:w}),A?(0,$.jsx)(VS,{open:!0,projectId:P,onOpenChange:j,onWorktreeCreated:ne}):null,(0,$.jsx)(xs,{open:!!E,onOpenChange:e=>{!e&&!O&&D(null)},children:(0,$.jsxs)(_s,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(hs,{children:[(0,$.jsx)(vs,{children:l(`chat.chatInput.branchSwitch.title`,{branch:E??``})}),(0,$.jsx)(ys,{children:l(`chat.chatInput.branchSwitch.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:O,onClick:()=>{U()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[O?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-left-right`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.checkoutHere`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.checkoutHereDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,disabled:O,onClick:()=>{W()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[O?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.createWorktree`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.createWorktreeDescription`)})]})]}),(0,$.jsx)(gs,{children:(0,$.jsx)(`button`,{type:`button`,disabled:O,onClick:()=>D(null),className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 disabled:opacity-50`,children:l(`chat.chatInput.branchSwitch.cancel`)})})]})})]})},XS=[],ZS=[],QS={revertMessageID:void 0,records:ZS},$S=e=>e.role===`user`,eC=(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||e[n]?.parts!==t[n]?.parts)return!1;return!0},tC=(e,t,n=QS)=>{if(!t)return QS;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return QS;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!$S(e)||!Se(i,e.id,r)||o.push({message:e,parts:a[e.id]??XS});let s=o.length===0?ZS:o;return n.revertMessageID===r&&eC(n.records,s)?n:{revertMessageID:r,records:s}},nC=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],rC=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),iC=e=>{if(/[\r\n]/.test(e)||!/\s/.test(e))return!1;let t=e.replace(/\\/g,`/`);if(!(t.startsWith(`//`)?t.replace(/^\/+/,``).includes(`/`):/^[A-Za-z]:\//.test(t)?t.slice(3).includes(`/`):t.startsWith(`/`)&&t.slice(1).includes(`/`)))return!1;if(t.endsWith(`/`))return!0;let n=t.split(`/`).filter(Boolean).pop()??``;return/\.[A-Za-z0-9]{1,8}$/.test(n)},aC=e=>{if(!rC(e))return!1;if(/\s/.test(e))return iC(e);if(e.startsWith(`//`)||e.startsWith(`\\\\`)){let t=e.replace(/^[\\/]+/,``);return/[\\/]/.test(t)}if(/^[A-Za-z]:[\\/]/.test(e)){let t=e.slice(3);return t.includes(`\\`)||t.includes(`/`)||t.includes(`.`)}return e.replace(/^\/+/,``).includes(`/`)},oC=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?aC(n):rC(n))?n:null},sC=(e,t,n=0)=>{if(!(n>6||e==null)){if(typeof e==`string`){t.add(e);return}if(Array.isArray(e)){for(let r of e)sC(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))sC(r,t,n+1)}},cC=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=oC(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=oC(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;sC(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},lC=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of nC){let r=``;try{r=e.getData(n)}catch{continue}let i=n===`text/plain`?{allowMultipleLines:!1,allowStructuredPayload:!1,fromPlainText:!0}:n===`text/uri-list`?{allowStructuredPayload:!1}:void 0;for(let e of cC(r,i))t.add(e)}return Array.from(t)},uC=e=>{let t=e.trim();if(!t.toLowerCase().startsWith(`file://`))return t;try{let e=new URL(t),n=decodeURIComponent(e.pathname||``);return e.hostname&&e.hostname!==`localhost`&&(n=`//${e.hostname}${n}`),/^\/[A-Za-z]:\//.test(n)&&(n=n.slice(1)),n||t}catch{let e=t.replace(/^file:\/\//i,``);try{return decodeURIComponent(e)}catch{return e}}},dC=e=>rC(e);function fC(e,t){let n=(0,Q.c)(5),r=cr(e,t),i=K(pC),a;n[0]===r?a=n[1]:(a=ii(r),n[0]=r,n[1]=a);let o;return n[2]!==i||n[3]!==a?(o={goal:a,enabled:i},n[2]=i,n[3]=a,n[4]=o):o=n[4],o}function pC(e){return e.sessionGoalEnabled}function mC(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(null),a=t?.objectiveFile?`${e}:${t.id}:${t.updatedAt}`:``,o,s;return n[0]!==a||n[1]!==e?(o=()=>{if(!a){i(null);return}let t=!0;return wr(e).then(e=>{t&&i(e)}),()=>{t=!1}},s=[a,e],n[0]=a,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),t?t.objectiveFile?r:t.objective:null}var hC={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},gC={active:`chat.goal.status.active`,paused:`chat.goal.status.paused`,blocked:`chat.goal.status.blocked`,budgetLimited:`chat.goal.status.budgetLimited`,complete:`chat.goal.status.complete`},_C=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=Xn(),i=K(e=>e.isMobile),{goal:a,enabled:o}=fC(e??``,t),s=mC(e??``,a),c=vo(e??``,t),l=Di(e,t),u=Z.useRef(null),[d,f]=Z.useState(!1),[p,m]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=l[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;u.current!==r&&(u.current=r,br(e,t))},[e,t,a,l]);let h=J(async n=>{if(!(!e||d)){f(!0);try{await pi(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),ji.error(r(`chat.goal.toast.actionFailed`))}finally{f(!1)}}});if(!e||!o||!a)return null;let g=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:p)-(a.createdAt||p)),_=lr(g),v=a.tokenBudget?`${Xa(a.tokensUsed)}/${Xa(a.tokenBudget)}`:a.tokensUsed>0?Xa(a.tokensUsed):null,y=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,b=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,x=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,S=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(S,`flex-shrink-0`),style:{color:hC[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,x),children:a.note||s||``}),a.status===`active`&&(!c||c.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,b),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(S,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,b),children:r(gC[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:_}),v?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:v}):null,y?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(y.next),disabled:d,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(y.labelKey),children:[(0,$.jsx)(X,{name:y.icon,className:S,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(y.labelKey)})]}):null]})});_C.displayName=`SessionGoalRow`;var vC=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=Xn(),{goal:i,enabled:a}=fC(e??``,t),o=Or(e=>e.armed),s=Or(e=>e.setArmed),[c,l]=Z.useState(!1);if(m()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,d=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Fi(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),ji.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void d(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});vC.displayName=`SessionGoalButton`;var yC=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=Xn();if(!Or(bC)||n===0)return null;let i=n>5e3?`text-[var(--status-error)]`:`text-muted-foreground/70`,a;t[0]===i?a=t[1]:(a=Y(`flex-shrink-0 self-center typography-micro tabular-nums`,i),t[0]=i,t[1]=a);let o;t[2]===r?o=t[3]:(o=r(`chat.goal.counter.aria`),t[2]=r,t[3]=o);let s;t[4]===r?s=t[5]:(s=r(`chat.goal.counter.aria`),t[4]=r,t[5]=s);let c;return t[6]!==n||t[7]!==a||t[8]!==o||t[9]!==s?(c=(0,$.jsxs)(`span`,{className:a,"aria-label":o,title:s,children:[n,`/`,eo]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});yC.displayName=`SessionGoalObjectiveCounter`;function bC(e){return e.armed}var xC=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`,`btw`]),SC=new Set([`new`,`compact`,`reload`,`fork`,`undo`,`redo`]),CC=/^\/\u2003?([^\s]+)/i,wC=/^\/\u2003?goal\b/i,TC=e=>e?.reloadEnabled??m(),EC=(e,t,n)=>{if(t!==`normal`)return null;let r=e.trimStart().match(CC)?.[1]?.toLowerCase();return!r||!xC.has(r)||r===`reload`&&!TC(n)?null:r},DC=(e,t,n)=>EC(e,t,n)===`goal`?e.trimStart().replace(wC,``).trim():null,OC=(e,t,n)=>EC(e,t,n)!==null,kC=(e,t,n)=>{let r=EC(e,t,n);return r!==null&&SC.has(r)};function AC(e){if(EC(e.text,e.inputMode)!==`btw`)return!1;if(!e.allowed)return!0;if(!e.scope?.sessionId)return e.notify(`sessionRequired`),!0;if(e.hasReferences)return e.notify(`plainTextRequired`),!0;let t=e.text.trimStart().replace(/^\/\u2003?btw(?:\s|$)/i,``).trim();return t&&e.ask(e.scope,t),e.clearText(),e.open(),!0}var jC=[`The user is asking a quick side question about the conversation so far.`,`Answer directly and concisely in markdown from what you already know.`,`Do not call any tools and do not take any actions.`].join(` `),MC=40,NC=Object.freeze({turns:Object.freeze([]),quotes:Object.freeze([])}),PC=e=>{let t=typeof e.sessionId==`string`?e.sessionId.trim():``,n=In(e.directory);return`${o()}\u0000${n}\u0000${t}`},FC=new Map,IC=[],LC=0,RC=0,zC=e=>e instanceof Error&&e.message.trim()?e.message:typeof e==`string`&&e.trim()?e:`session.btw failed`,BC=(e,t)=>t.aborted?!0:!e||typeof e!=`object`?!1:(`name`in e?e.name:void 0)===`AbortError`,VC=(e,t)=>FC.get(e)?.controller===t,HC=e=>!!e?.turns.some(e=>e.pending),UC=e=>{IC=IC.filter(t=>t!==e),IC.push(e)},WC=e=>{FC.get(e)?.controller.abort(),FC.delete(e)},GC=(e,t)=>{let n=Object.keys(e);if(n.length<=MC)return e;let r={...e},i=IC.filter(e=>e in r);for(let e of n)i.includes(e)||i.push(e);let a=e=>e!==t&&r[e]!==void 0&&!HC(r[e]);for(;Object.keys(r).length>MC;){let e=i.find(a)??i.find(e=>e!==t);if(!e)break;delete r[e],WC(e);let n=i.indexOf(e);n>=0&&i.splice(n,1)}return IC=i.filter(e=>e in r),r},KC=(e,t)=>{dw.setState(n=>{let r=n.entries[e]??NC,i=t(r);return!i||i===r?n:(UC(e),{entries:GC({...n.entries,[e]:i},e)})})},qC=(e,t)=>{KC(e,e=>{let n=t(e.turns);return!n||n===e.turns?null:{...e,turns:n}})},JC=(e,t,n)=>{dw.getState().entries[e]&&qC(e,e=>{let r=e.findIndex(e=>e.id===t);if(r<0)return null;let i=e.slice();return i[r]={...e[r],...n},i})},YC=e=>e.split(`
|
|
6531
|
+
`)?`...`:``),_v=(e,t={})=>{let n=gv(e);if(!n)return null;let r=hv(t.composerDocument);return P_(n,{citationIcons:pv(t.attachments),sessionMentions:mv(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},vv=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return(t.kind===`edit`||t.kind===`send`||t.kind===`remove`||t.kind===`reorder`)&&typeof t.transportIdentity==`string`&&typeof t.runtimeGeneration==`number`&&Number.isSafeInteger(t.runtimeGeneration)&&t.runtimeGeneration>=0&&typeof t.directory==`string`&&typeof t.sessionID==`string`&&typeof t.scopeID==`string`&&typeof t.queueItemID==`string`&&(t.queueItemIDs===void 0||Array.isArray(t.queueItemIDs)&&t.queueItemIDs.every(e=>typeof e==`string`))},yv=(0,Z.memo)(e=>{let t=(0,Q.c)(157),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,sendPendingTimedOut:s,abortSendPending:c,steering:l,isMobile:u,inboxEditable:d,onEdit:f,onSend:p,onQueue:m,onRemove:h,compactionBarrier:g}=e,_=g!==void 0&&g,{t:v}=Xn(),y;t[0]===n?y=t[1]:(y=Ue(n),t[0]=n,t[1]=y);let b=y,x;t[2]!==n||t[3]!==p?(x={mutationFn:async()=>{await p(n)}},t[2]=n,t[3]=p,t[4]=x):x=t[4];let S=q(x),C;t[5]!==n||t[6]!==f?(C={mutationFn:async()=>{await f(n)}},t[5]=n,t[6]=f,t[7]=C):C=t[7];let w=q(C),T;t[8]===n?T=t[9]:(T=Go(n),t[8]=n,t[9]=T);let E=T,D=n.queueItemID||n.id,O;t[10]!==w.isPending||t[11]!==o||t[12]!==r?(O=w.isPending||r&&o.has(`edit`),t[10]=w.isPending,t[11]=o,t[12]=r,t[13]=O):O=t[13];let k=O,A;t[14]!==o||t[15]!==r?(A=r&&o.has(`remove`),t[14]=o,t[15]=r,t[16]=A):A=t[16];let j=A,M;t[17]!==o||t[18]!==r?(M=r&&o.has(`reorder`),t[17]=o,t[18]=r,t[19]=M):M=t[19];let N=M,P=r||E?void 0:n,F;t[20]!==n||t[21]!==E||t[22]!==r?(F=r&&!E&&ev(n),t[20]=n,t[21]=E,t[22]=r,t[23]=F):F=t[23];let I=F,L;t[24]===P?L=t[25]:(L=P&&$_(P),t[24]=P,t[25]=L);let R=!!L,z;t[26]!==n||t[27]!==E||t[28]!==r?(z=r&&!E&&Q_(n),t[26]=n,t[27]=E,t[28]=r,t[29]=z):z=t[29];let B=z,V;t[30]!==I||t[31]!==R||t[32]!==o||t[33]!==r?(V=r&&o.has(`send`)||I||R,t[30]=I,t[31]=R,t[32]=o,t[33]=r,t[34]=V):V=t[34];let H=V,U=l||b&&(S.isPending||n.delivery===`steer`)||c||H&&!s,W=i||E,ee;t[35]!==k||t[36]!==i||t[37]!==b||t[38]!==d||t[39]!==n||t[40]!==U?(ee=b?d&&!i&&!k&&!U&&n.delivery===`queue`:X_(n,{frozen:i}),t[35]=k,t[36]=i,t[37]=b,t[38]=d,t[39]=n,t[40]=U,t[41]=ee):ee=t[41];let te=ee,ne;t[42]!==k||t[43]!==i||t[44]!==b||t[45]!==n?(ne=b?!i&&!k:Z_(n,{frozen:i}),t[42]=k,t[43]=i,t[44]=b,t[45]=n,t[46]=ne):ne=t[46];let re=ne,G=b||P?.owner?.state===`unbound-legacy`||W||B,ie=b&&_,ae;t[47]!==W||t[48]!==k||t[49]!==i||t[50]!==a||t[51]!==b||t[52]!==n||t[53]!==U||t[54]!==s||t[55]!==r||t[56]!==ie?(ae=b?!i&&!k&&!U&&n.delivery===`queue`&&!ie:!W&&!U&&(r?Y_(n,a,{allowManualDispatchRetry:s}):J_(n,a)),t[47]=W,t[48]=k,t[49]=i,t[50]=a,t[51]=b,t[52]=n,t[53]=U,t[54]=s,t[55]=r,t[56]=ie,t[57]=ae):ae=t[57];let oe=ae,se=b&&!i&&n.delivery===`steer`&&!ie,ce=P?.failure?.recovery,le;t[58]===n?le=t[59]:(le=fv(n),t[58]=n,t[59]=le);let ue=le,de=E||b?void 0:ce?.attachments??(`attachments`in n?n.attachments:void 0),fe=ce?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),pe;t[60]!==G||t[61]!==D?(pe={id:D,disabled:G},t[60]=G,t[61]=D,t[62]=pe):pe=t[62];let{attributes:me,listeners:he,setNodeRef:ge,transform:_e,transition:ve,isDragging:ye}=ld(pe),be;t[63]===ue?be=t[64]:(be=gv(ue),t[63]=ue,t[64]=be);let xe=be,Se;t[65]!==de||t[66]!==fe||t[67]!==ue?(Se=_v(ue,{attachments:de,composerDocument:fe}),t[65]=de,t[66]=fe,t[67]=ue,t[68]=Se):Se=t[68];let Ce=Se,we=E||b?n.attachmentCount:de?.length??0,Te;t[69]!==n||t[70]!==h?(Te=()=>h(n),t[69]=n,t[70]=h,t[71]=Te):Te=t[71];let Ee=!re,De=j||void 0,Oe=u?`h-7 w-3`:`size-6`,ke;t[72]===Oe?ke=t[73]:(ke=Y(`inline-flex shrink-0 items-center justify-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,Oe),t[72]=Oe,t[73]=ke);let Ae;t[74]===v?Ae=t[75]:(Ae=v(`chat.queuedMessage.removeAria`),t[74]=v,t[75]=Ae);let je=j?`loader-4`:`delete-bin`,Me=u?`size-3`:`size-3.5`,Ne=j&&`animate-spin`,Pe;t[76]!==Me||t[77]!==Ne?(Pe=Y(Me,Ne),t[76]=Me,t[77]=Ne,t[78]=Pe):Pe=t[78];let Fe;t[79]!==je||t[80]!==Pe?(Fe=(0,$.jsx)(X,{name:je,className:Pe,"aria-hidden":`true`}),t[79]=je,t[80]=Pe,t[81]=Fe):Fe=t[81];let Ie;t[82]!==Te||t[83]!==Ee||t[84]!==De||t[85]!==ke||t[86]!==Ae||t[87]!==Fe?(Ie=(0,$.jsx)(`button`,{type:`button`,onClick:Te,disabled:Ee,"aria-busy":De,className:ke,"aria-label":Ae,children:Fe}),t[82]=Te,t[83]=Ee,t[84]=De,t[85]=ke,t[86]=Ae,t[87]=Fe,t[88]=Ie):Ie=t[88];let Le=Ie,Re;t[89]===_e?Re=t[90]:(Re=od.Translate.toString(_e),t[89]=_e,t[90]=Re);let ze;t[91]!==Re||t[92]!==ve?(ze={transform:Re,transition:ve},t[91]=Re,t[92]=ve,t[93]=ze):ze=t[93];let Be=u?`gap-1 py-0.5`:`flex gap-1.5 py-px md:gap-2`,Ve=ye&&`z-10 opacity-60`,He;t[94]!==Be||t[95]!==Ve?(He=Y(`flex min-w-0 items-center`,Be,Ve),t[94]=Be,t[95]=Ve,t[96]=He):He=t[96];let We=N||void 0,Ge=u?`h-7 w-3`:`size-auto`,Ke=G?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,qe;t[97]!==Ge||t[98]!==Ke?(qe=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,Ge,`transition-colors`,Ke),t[97]=Ge,t[98]=Ke,t[99]=qe):qe=t[99];let Je;t[100]===v?Je=t[101]:(Je=v(`chat.queuedMessage.reorderAria`),t[100]=v,t[101]=Je);let Ye=N?`loader-4`:`draggable`,Xe=u?`size-3`:`size-3.5`,Ze=N&&`animate-spin`,Qe;t[102]!==Xe||t[103]!==Ze?(Qe=Y(Xe,Ze),t[102]=Xe,t[103]=Ze,t[104]=Qe):Qe=t[104];let $e;t[105]!==Ye||t[106]!==Qe?($e=(0,$.jsx)(X,{name:Ye,className:Qe,"aria-hidden":`true`}),t[105]=Ye,t[106]=Qe,t[107]=$e):$e=t[107];let et;t[108]!==me||t[109]!==G||t[110]!==he||t[111]!==We||t[112]!==qe||t[113]!==Je||t[114]!==$e?(et=(0,$.jsx)(`button`,{type:`button`,...me,...he,disabled:G,"aria-busy":We,className:qe,"aria-label":Je,children:$e}),t[108]=me,t[109]=G,t[110]=he,t[111]=We,t[112]=qe,t[113]=Je,t[114]=$e,t[115]=et):et=t[115];let tt=u?Le:null,nt=u?`text-xs leading-5`:`typography-ui-label leading-5`,rt;t[116]===nt?rt=t[117]:(rt=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground [&>[data-message-reference-kind]]:min-w-0 [&>[data-message-reference-kind]]:truncate`,nt),t[116]=nt,t[117]=rt);let it;t[118]!==xe||t[119]!==Ce||t[120]!==v?(it=Ce?Ce.map(kv):xe||v(`chat.queuedMessage.empty`),t[118]=xe,t[119]=Ce,t[120]=v,t[121]=it):it=t[121];let at;t[122]!==we||t[123]!==v?(at=we>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:v(`chat.queuedMessage.attachments`,{count:we})}),t[122]=we,t[123]=v,t[124]=at):at=t[124];let ot;t[125]!==rt||t[126]!==it||t[127]!==at?(ot=(0,$.jsxs)(`span`,{className:rt,children:[it,at]}),t[125]=rt,t[126]=it,t[127]=at,t[128]=ot):ot=t[128];let st;t[129]!==te||t[130]!==se||t[131]!==oe||t[132]!==k||t[133]!==b||t[134]!==w||t[135]!==S||t[136]!==u||t[137]!==n||t[138]!==f||t[139]!==m||t[140]!==p||t[141]!==E||t[142]!==U||t[143]!==v||t[144]!==ie?(st=U&&!ie?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,u?`h-7 text-[11px] leading-none`:`h-6 typography-ui-label`),"aria-live":`polite`,"aria-label":v(`chat.queuedMessage.sendingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(u?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:v(`chat.queuedMessage.sending`)})]}):E?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,u?`h-7 text-[11px] leading-none`:`h-6 typography-ui-label`),"aria-live":`polite`,"aria-label":v(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(u?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:v(`chat.queuedMessage.queuing`)})]}):ie?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,u?`h-7 text-[11px] leading-none`:`h-6 typography-ui-label`),"aria-live":`polite`,"aria-label":v(`chat.queuedMessage.waitingForCompactionAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(u?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:v(`chat.queuedMessage.waitingForCompaction`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{b?w.mutate():f(n)},disabled:!te,"aria-busy":k||void 0,"aria-label":v(`chat.queuedMessage.edit`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,u?`h-7 gap-1.5 px-0 text-[11px]`:`h-6 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:k?`loader-4`:`edit`,className:Y(u?`size-3`:`size-3.5`,k&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium capitalize`,u?`leading-none`:`typography-ui-label`),children:v(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{U||(b?S.mutate():p(n))},disabled:!oe||U,"aria-busy":U||void 0,"aria-label":v(`chat.queuedMessage.send`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,u?`h-7 gap-1.5 px-0 text-[11px]`:`h-6 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`send-plane`,className:Y(u?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium capitalize`,u?`leading-none`:`typography-ui-label`),children:v(`chat.queuedMessage.send`)})]}),se?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>m?.(n),disabled:!se,"aria-label":v(`chat.queuedMessage.title`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,u?`h-7 gap-1.5 px-0 text-[11px]`:`h-6 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`time`,className:Y(u?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,u?`leading-none`:`typography-ui-label`),children:v(`chat.queuedMessage.title`)})]}):null]}),t[129]=te,t[130]=se,t[131]=oe,t[132]=k,t[133]=b,t[134]=w,t[135]=S,t[136]=u,t[137]=n,t[138]=f,t[139]=m,t[140]=p,t[141]=E,t[142]=U,t[143]=v,t[144]=ie,t[145]=st):st=t[145];let ct=!u&&!E?Le:null,lt;t[146]!==st||t[147]!==ct?(lt=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[st,ct]}),t[146]=st,t[147]=ct,t[148]=lt):lt=t[148];let ut;return t[149]!==ge||t[150]!==ze||t[151]!==He||t[152]!==et||t[153]!==tt||t[154]!==ot||t[155]!==lt?(ut=(0,$.jsxs)(`div`,{ref:ge,role:`group`,style:ze,className:He,children:[et,tt,ot,lt]}),t[149]=ge,t[150]=ze,t[151]=He,t[152]=et,t[153]=tt,t[154]=ot,t[155]=lt,t[156]=ut):ut=t[156],ut});yv.displayName=`QueuedMessageChip`;var bv=[],xv=[],Sv=[],Cv=new Set,wv=new Set,Tv=(e,t)=>t?G_($t(e,Nt(t.sessionID)),$t(e,t)):bv,Ev=(e,t)=>{if(!t)return xv;let n=Tv(e,t),r=[...wt(e,Nt(t.sessionID)),...wt(e,t)];return r.length===0?n:[...n,...r]},Dv=(e,t)=>{let n=e.owner;return n?n.state===`unbound-legacy`?n.sessionID===t.sessionID?Nt(t.sessionID):null:Ot(n)===Ot(t)?t:null:null},Ov=(0,Z.memo)(e=>{let t=(0,Q.c)(173),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:s,clientPendingItems:c,onRemoveClientPending:l,onSteerClientPending:u,onQueueClientPending:d,compactionBarrier:f,steeringMessageIDs:p,trailing:m}=e,h=c===void 0?Sv:c,g=f!==void 0&&f,_=p===void 0?wv:p,{t:v}=Xn(),y=K(Av),b=o?.transportIdentity??``,x=o?.directory??``,S=o?.sessionID??``,C;t[0]!==b||t[1]!==x||t[2]!==S?(C={transportIdentity:b,directory:x,sessionID:S},t[0]=b,t[1]=x,t[2]=S,t[3]=C):C=t[3];let w=Ah(C),T;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(T=new Map,t[4]=T):T=t[4];let E=Z.useRef(T);o?.runtimeGeneration,o?.transportIdentity;let D=o?.transportIdentity??``,O=o?.runtimeGeneration??-1,k;t[5]!==O||t[6]!==D?(k=[D,`messageQueue`,`scopeMutation`,O],t[5]=O,t[6]=D,t[7]=k):k=t[7];let A=k,j;t[8]===w.actions?j=t[9]:(j=e=>Ji(E,`${e.transportIdentity}\u0000${e.runtimeGeneration}\u0000${e.directory}\u0000${e.sessionID}\u0000${e.scopeID}`,()=>{if(e.transportIdentity!==e.runtime.transportIdentity||e.runtimeGeneration!==e.runtime.generation)return Promise.resolve({status:`stale`});let t=w.actions.captureRuntime();if(t.transportIdentity!==e.runtime.transportIdentity||t.generation!==e.runtime.generation)return Promise.resolve({status:`stale`});switch(e.kind){case`edit`:return w.actions.editIntoDraft(e.input);case`send`:return w.actions.manualSend(e.input);case`remove`:return w.actions.remove(e.input);case`reorder`:return w.actions.reorder(e.input)}throw Error(`Unsupported server queue operation`)}),t[8]=w.actions,t[9]=j);let M,N;t[10]!==w.actions||t[11]!==v?(M=(e,t)=>{let n=w.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&e.status!==`stale`&&t.kind===`edit`&&e.status!==`committed`&&ji.error(v(`chat.chatInput.toast.queueOperationFailed`))},N=(e,t)=>{let n=w.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&ji.error(v(e instanceof Zo&&e.code===`unavailable`?`chat.chatInput.toast.queueOperationStatusUnknown`:`chat.chatInput.toast.queueOperationFailed`))},t[10]=w.actions,t[11]=v,t[12]=M,t[13]=N):(M=t[12],N=t[13]);let P;t[14]!==A||t[15]!==j||t[16]!==M||t[17]!==N?(P={mutationKey:A,mutationFn:j,onSuccess:M,onError:N},t[14]=A,t[15]=j,t[16]=M,t[17]=N,t[18]=P):P=t[18];let F=q(P),I;t[19]===A?I=t[20]:(I={filters:{mutationKey:A,exact:!0,status:`pending`},select:jv},t[19]=A,t[20]=I);let L=bn(I),R;t[21]===A?R=t[22]:(R={filters:{mutationKey:A,exact:!0,status:`success`},select:Mv},t[21]=A,t[22]=R);let z=bn(R),B;bb0:{if(!o||!w.scope){B=null;break bb0}let e=o.runtimeGeneration??w.runtimeCapture.generation,n;t[23]!==o.directory||t[24]!==o.sessionID||t[25]!==o.transportIdentity||t[26]!==w.scope.scopeID||t[27]!==e?(n={transportIdentity:o.transportIdentity,directory:o.directory,sessionID:o.sessionID,scopeID:w.scope.scopeID,runtimeGeneration:e},t[23]=o.directory,t[24]=o.sessionID,t[25]=o.transportIdentity,t[26]=w.scope.scopeID,t[27]=e,t[28]=n):n=t[28],B=n}let V=B,H;bb1:{if(!V){let e;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[29]=e):e=t[29],H=e;break bb1}let e;if(t[30]!==V||t[31]!==L){let n;t[33]===V?n=t[34]:(n=e=>vv(e)&&e.scopeID===V.scopeID,t[33]=V,t[34]=n),e=iv(L.filter(n),V),t[30]=V,t[31]=L,t[32]=e}else e=t[32];H=e}let U=H,W;t[35]!==V||t[36]!==w.scope?.revision||t[37]!==z?(W=()=>V?av(z.filter(Nv),V,w.scope?.revision):[],t[35]=V,t[36]=w.scope?.revision,t[37]=z,t[38]=W):W=t[38],w.scope?.revision;let ee;t[39]===W?ee=t[40]:(ee=W(),t[39]=W,t[40]=ee);let te=ee,ne;t[41]!==te||t[42]!==U?(ne=[...U,...te],t[41]=te,t[42]=U,t[43]=ne):ne=t[43];let re=ne,G;t[44]===o?G=t[45]:(G=e=>Ev(e,o),t[44]=o,t[45]=G);let ie=Mt(G);Z.useSyncExternalStore(Hr,ci,ci);let ae;t[46]!==re||t[47]!==ie||t[48]!==w.items||t[49]!==w.mode?(ae=w.mode===`server`?cv(w.items,re):ie,t[46]=re,t[47]=ie,t[48]=w.items,t[49]=w.mode,t[50]=ae):ae=t[50];let oe=ae,se;t[51]!==oe||t[52]!==h?(se=h.length===0?oe:[...oe,...h],t[51]=oe,t[52]=h,t[53]=se):se=t[53];let ce=se,le;t[54]!==o?.sessionID||t[55]!==ce?(le=()=>{let e=o?.sessionID,t=new Set;if(!e)return t;for(let n of ce){let r=n.queueItemID||n.id;r&&_i(e,r)&&t.add(r)}return t},t[54]=o?.sessionID,t[55]=ce,t[56]=le):le=t[56],o?.sessionID;let ue;t[57]===le?ue=t[58]:(ue=le(),t[57]=le,t[58]=ue);let de=ue,fe;if(t[59]!==re){fe=new Map;for(let e of re){let t=fe.get(e.queueItemID)??new Set;t.add(e.kind),fe.set(e.queueItemID,t)}t[59]=re,t[60]=fe}else fe=t[60];let pe=fe,me;if(t[61]!==re||t[62]!==ce||t[63]!==w.mode){bb2:{let e=new Set;if(w.mode===`server`){for(let t of re)t.kind===`send`&&e.add(t.queueItemID);for(let t of ce){if(Go(t))continue;let n=t.queueItemID;n&&ev(t)&&e.add(n)}me=e;break bb2}for(let t of ce){if(Go(t))continue;let n=t;$_(n)&&e.add(n.queueItemID||n.id)}me=e}t[61]=re,t[62]=ce,t[63]=w.mode,t[64]=me}else me=t[64];let he=me,[ge,_e]=Z.useState(Pv),ve;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(ve=new Map,t[65]=ve):ve=t[65];let ye=Z.useRef(ve),be,xe;t[66]!==he||t[67]!==ge?(be=()=>{let e=ye.current,t=Date.now();for(let t of[...e.keys()])he.has(t)||e.delete(t);_e(e=>{let t=!1,n=new Set;for(let r of e)he.has(r)?n.add(r):t=!0;return t?n:e});let n=[];for(let r of he){if(e.has(r)||(e.set(r,t),_e(e=>{if(!e.has(r))return e;let t=new Set(e);return t.delete(r),t})),ge.has(r))continue;let i=nv-(t-(e.get(r)??t));if(i<=0){_e(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t});continue}n.push(setTimeout(()=>{ye.current.has(r)&&_e(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t})},i))}return()=>{for(let e of n)clearTimeout(e)}},xe=[he,ge],t[66]=he,t[67]=ge,t[68]=be,t[69]=xe):(be=t[68],xe=t[69]),Z.useEffect(be,xe);let Se;t[70]===w.mode?Se=t[71]:(Se=W_(w.mode),t[70]=w.mode,t[71]=Se);let Ce=!Se,we=zr(o),Te;t[72]!==we||t[73]!==ce||t[74]!==w.mode?(Te=w.mode===`server`?!1:we||ce.some(Fv),t[72]=we,t[73]=ce,t[74]=w.mode,t[75]=Te):Te=t[75];let Ee=Te,De=Mt(Iv),Oe;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={activationConstraint:{distance:8}},t[76]=Oe):Oe=t[76];let ke;t[77]===Symbol.for(`react.memo_cache_sentinel`)?(ke={activationConstraint:{delay:200,tolerance:6}},t[77]=ke):ke=t[77];let Ae=ad(Qu(rd,Oe),Qu(ed,ke)),je;t[78]!==Ce||t[79]!==o||t[80]!==ce||t[81]!==De||t[82]!==F||t[83]!==w.actions||t[84]!==w.mode||t[85]!==w.scope?(je=e=>{if(Ce)return;let{active:t,over:n}=e;if(!n||t.id===n.id)return;if(w.mode===`server`){if(!o||!w.scope)return;let e=ce,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||Go(r)||Go(i)||Q_(r)||Q_(i))return;let a=w.scope,s=w.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=Ct(),l=dv(a,String(t.id),String(n.id),c,e);if(!l)return;F.mutateAsync({kind:`reorder`,transportIdentity:s.transportIdentity,directory:a.directory,sessionID:a.sessionID,scopeID:a.scopeID,queueItemID:String(t.id),queueItemIDs:l.queueItemIDs,requestID:c,runtime:s,runtimeGeneration:s.generation,input:l}).catch(Lv);return}let r=ce.filter(Rv),i=r.find(e=>(e.queueItemID??e.id)===t.id),a=r.find(e=>(e.queueItemID??e.id)===n.id);if(!i||!a||!o)return;let s=Dv(i,o),c=Dv(a,o);!s||!c||Ot(s)!==Ot(c)||De(s,String(t.id),String(n.id),i.operationID)},t[78]=Ce,t[79]=o,t[80]=ce,t[81]=De,t[82]=F,t[83]=w.actions,t[84]=w.mode,t[85]=w.scope,t[86]=je):je=t[86];let Me=J(je),Ne=Z.useRef(!0),Pe,Fe;t[87]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=()=>(Ne.current=!0,()=>{Ne.current=!1}),Fe=[],t[87]=Pe,t[88]=Fe):(Pe=t[87],Fe=t[88]),Z.useEffect(Pe,Fe);let Ie;t[89]!==s||t[90]!==Ce||t[91]!==o?.directory||t[92]!==o?.runtimeGeneration||t[93]!==o?.sessionID||t[94]!==o?.transportIdentity?(Ie=(e,t)=>Ne.current&&!Ce&&o?.transportIdentity===e.transportIdentity&&o?.runtimeGeneration===e.runtimeGeneration&&o?.sessionID===e.sessionID&&o?.directory===e.directory&&!!(s&&gn(s.key)===gn(t)),t[89]=s,t[90]=Ce,t[91]=o?.directory,t[92]=o?.runtimeGeneration,t[93]=o?.sessionID,t[94]=o?.transportIdentity,t[95]=Ie):Ie=t[95];let Le=J(Ie),Re;t[96]!==a||t[97]!==s||t[98]!==Ce||t[99]!==Le||t[100]!==i||t[101]!==n||t[102]!==o||t[103]!==F||t[104]!==w.actions||t[105]!==w.mode||t[106]!==w.scope||t[107]!==v?(Re=e=>{if(Ce||Go(e))return;if(Ue(e)){if(!o||!s||e.delivery!==`queue`)return;let t=o,n=s.key;return c_({sessionID:t.sessionID,inboxID:e.queueItemID,directory:t.directory,targetKey:n,expectedRevision:s.expectedRevision(),runtimeGeneration:t.runtimeGeneration,isCurrent:()=>Le(t,n)}).then(e=>{e&&Le(t,n)&&i?.()}).catch(()=>{ji.error(v(`chat.chatInput.toast.messageSendFailed`))})}if(w.mode===`server`){if(!o||!w.scope||!a||!s)return;let t=e,n=s.expectedRevision(),r=w.scope,c=w.actions.captureRuntime();if(c.transportIdentity!==o.transportIdentity||c.generation!==o.runtimeGeneration)return;F.mutateAsync({kind:`edit`,transportIdentity:c.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:Ct(),runtime:c,runtimeGeneration:c.generation,input:uv(r,t,s.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(zv);return}if(!o)return;let t=e,r=Dv(t,o);if(!r)return;let c=t.queueItemID??t.id,l=t.operationID,u=q_(t);(async()=>{let e;try{e=await Promise.resolve(n(u.content,u.attachments,u.composerDocument,u.composerMentions))}catch{e=!1}e&&(i?.(),Mt.getState().removeFromQueue(r,c,l))})()},t[96]=a,t[97]=s,t[98]=Ce,t[99]=Le,t[100]=i,t[101]=n,t[102]=o,t[103]=F,t[104]=w.actions,t[105]=w.mode,t[106]=w.scope,t[107]=v,t[108]=Re):Re=t[108];let ze=J(Re),Be;t[109]!==g||t[110]!==Ce||t[111]!==r||t[112]!==u||t[113]!==o||t[114]!==F||t[115]!==w.actions||t[116]!==w.mode||t[117]!==w.scope?(Be=e=>{if(Ue(e))return g?void 0:u?.(e.queueItemID);if(Ce||Go(e))return;if(w.mode===`server`){if(!o||!w.scope)return;let t=e,n=w.scope,r=w.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=t.queueItemID;ye.current.delete(i),_e(e=>{if(!e.has(i))return e;let t=new Set(e);return t.delete(i),t});let a=Ct();F.mutateAsync({kind:`send`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:a,runtime:r,runtimeGeneration:r.generation,input:lv(n,t,a)}).catch(Bv);return}if(!o)return;let t=e;if(!Dv(t,o))return;let n=t.queueItemID??t.id;ye.current.delete(n),_e(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t}),r(n)},t[109]=g,t[110]=Ce,t[111]=r,t[112]=u,t[113]=o,t[114]=F,t[115]=w.actions,t[116]=w.mode,t[117]=w.scope,t[118]=Be):Be=t[118];let Ve=J(Be),He;t[119]!==g||t[120]!==d?(He=e=>{g||Ue(e)&&d?.(e.queueItemID)},t[119]=g,t[120]=d,t[121]=He):He=t[121];let We=J(He),Ge;t[122]!==h||t[123]!==Ce||t[124]!==l||t[125]!==o||t[126]!==F||t[127]!==w.actions||t[128]!==w.mode||t[129]!==w.scope?(Ge=e=>{if(Ue(e)){l?.(e.requestID);return}if(Go(e)){h.some(t=>t.requestID===e.requestID)&&l?.(e.requestID);return}if(Ce)return;if(w.mode===`server`){if(!o||!w.scope)return;let t=e,n=w.scope,r=w.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=Ct();F.mutateAsync({kind:`remove`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:i,runtime:r,runtimeGeneration:r.generation,input:lv(n,t,i)}).catch(Vv);return}if(!o)return;let t=e,n=Dv(t,o);n&&Mt.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[122]=h,t[123]=Ce,t[124]=l,t[125]=o,t[126]=F,t[127]=w.actions,t[128]=w.mode,t[129]=w.scope,t[130]=Ge):Ge=t[130];let Ke=J(Ge),qe=ce.length>0&&(o||h.length>0);if(!qe&&!m)return null;let Je=y?`px-2`:`px-4`,Ye;t[131]===Je?Ye=t[132]:(Ye=Y(`yuri-composer-queue relative z-0 -mb-5 w-full`,Je),t[131]=Je,t[132]=Ye);let Xe=y?`rounded-[1.25rem]`:`rounded-3xl`,Ze;t[133]===Xe?Ze=t[134]:(Ze=Y(`overflow-hidden border border-[color-mix(in_srgb,var(--interactive-border)_50%,transparent)] bg-[var(--surface-background)] text-foreground dark:border-transparent dark:bg-[color-mix(in_srgb,var(--surface-background),var(--surface-foreground)_4%)]`,Xe),t[133]=Xe,t[134]=Ze);let Qe=y?`px-1.5 py-1`:`gap-0.5 px-3 py-1`,$e;t[135]===Qe?$e=t[136]:($e=Y(`flex flex-col`,Qe),t[135]=Qe,t[136]=$e);let et;t[137]!==de||t[138]!==g||t[139]!==s||t[140]!==Ce||t[141]!==Me||t[142]!==ze||t[143]!==We||t[144]!==Ke||t[145]!==Ve||t[146]!==Ee||t[147]!==qe||t[148]!==y||t[149]!==pe||t[150]!==o||t[151]!==ce||t[152]!==ge||t[153]!==Ae||t[154]!==w.mode||t[155]!==_?(et=qe?(0,$.jsx)(id,{sensors:Ae,collisionDetection:nd,onDragEnd:Me,children:(0,$.jsx)(dd,{items:ce.map(Hv),strategy:ud,children:ce.map(e=>{let t=e.queueItemID||e.id;return(0,$.jsx)(yv,{message:e,server:w.mode===`server`,frozen:Ce,hasDispatchLock:Ee,pendingOperationKinds:pe.get(t)??Cv,sendPendingTimedOut:ge.has(t),abortSendPending:de.has(t),steering:_.has(t)||!!(e.messageID&&_.has(e.messageID)),isMobile:y,inboxEditable:!!(o&&s),onEdit:ze,onSend:Ve,onQueue:We,onRemove:Ke,compactionBarrier:g},t)})})}):null,t[137]=de,t[138]=g,t[139]=s,t[140]=Ce,t[141]=Me,t[142]=ze,t[143]=We,t[144]=Ke,t[145]=Ve,t[146]=Ee,t[147]=qe,t[148]=y,t[149]=pe,t[150]=o,t[151]=ce,t[152]=ge,t[153]=Ae,t[154]=w.mode,t[155]=_,t[156]=et):et=t[156];let tt;t[157]!==qe||t[158]!==m?(tt=m?(0,$.jsxs)($.Fragment,{children:[qe?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,m]}):null,t[157]=qe,t[158]=m,t[159]=tt):tt=t[159];let nt;t[160]!==$e||t[161]!==et||t[162]!==tt?(nt=(0,$.jsxs)(`div`,{"data-yuri-queue-card-body":``,className:$e,children:[et,tt]}),t[160]=$e,t[161]=et,t[162]=tt,t[163]=nt):nt=t[163];let rt=y?`h-4`:`h-5`,it;t[164]===rt?it=t[165]:(it=(0,$.jsx)(`div`,{"data-yuri-queue-composer-overlap":``,"aria-hidden":`true`,className:rt}),t[164]=rt,t[165]=it);let at;t[166]!==Ze||t[167]!==nt||t[168]!==it?(at=(0,$.jsxs)(`div`,{"data-yuri-queue-card":``,className:Ze,children:[nt,it]}),t[166]=Ze,t[167]=nt,t[168]=it,t[169]=at):at=t[169];let ot;return t[170]!==Ye||t[171]!==at?(ot=(0,$.jsx)(`div`,{className:Ye,children:at}),t[170]=Ye,t[171]=at,t[172]=ot):ot=t[172],ot});Ov.displayName=`QueuedMessageChips`;function kv(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(H_,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Av(e){return e.isMobile}function jv(e){return e.state.variables}function Mv(e){let t=e.state.variables;if(!vv(t)||t.kind!==`send`)return;let n=e.state.data;if(!n||n.status!==`committed`)return;let r=`committedRevision`in n&&typeof n.committedRevision==`number`&&Number.isSafeInteger(n.committedRevision)?n.committedRevision:void 0,i=`scope`in n&&n.scope&&typeof n.scope.revision==`number`&&Number.isSafeInteger(n.scope.revision)?n.scope.revision:void 0,a=r??i;if(!(a===void 0||a<=0))return{...t,kind:`send`,committedRevision:a}}function Nv(e){return e!==void 0}function Pv(){return new Set}function Fv(e){return!Go(e)&&(e.status===`sending`||e.status===`reconciling`)}function Iv(e){return e.reorderQueue}function Lv(){}function Rv(e){return!Go(e)}function zv(){}function Bv(){}function Vv(){}function Hv(e){return e.queueItemID||e.id}function Uv(e){let t=(0,Q.c)(21),{presentation:n}=e,{text:r,icon:i,variant:a,rawMessage:o,detail:s}=n,c=a===`error`?`alert`:`status`,l;t[0]===i?l=t[1]:(l=(0,$.jsx)(`span`,{className:`inline-flex h-5 shrink-0 items-center`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:i,className:`size-3.5`})}),t[0]=i,t[1]=l);let u;t[2]!==s||t[3]!==o||t[4]!==r?(u=[r,s,o].filter(Boolean),t[2]=s,t[3]=o,t[4]=r,t[5]=u):u=t[5];let d=u.join(` · `),f;t[6]===s?f=t[7]:(f=s?(0,$.jsx)(`span`,{className:`ml-1.5 text-muted-foreground/60`,children:s}):null,t[6]=s,t[7]=f);let p;t[8]!==o||t[9]!==r?(p=o&&o!==r?(0,$.jsx)(`span`,{className:`ml-1.5 text-muted-foreground/80`,children:o}):null,t[8]=o,t[9]=r,t[10]=p):p=t[10];let m;t[11]!==d||t[12]!==f||t[13]!==p||t[14]!==r?(m=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,title:d,children:[r,f,p]}),t[11]=d,t[12]=f,t[13]=p,t[14]=r,t[15]=m):m=t[15];let h;return t[16]!==c||t[17]!==l||t[18]!==m||t[19]!==a?(h=(0,$.jsxs)(`div`,{role:c,"data-response-status":a,className:`flex w-full min-w-0 items-start gap-1.5 typography-meta leading-5 text-muted-foreground`,children:[l,m]}),t[16]=c,t[17]=l,t[18]=m,t[19]=a,t[20]=h):h=t[20],h}function Wv(e){let t=(0,Q.c)(7),{sessionId:n,directory:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={bootstrap:!1},t[0]=i):i=t[0];let a=qi(r,i),o;t[1]===n?o=t[2]:(o=e=>e.session_execution_recovery[n]?.reason===`shutdown`,t[1]=n,t[2]=o);let s=z(a,o),{t:c}=Xn();if(!s)return null;let l;t[3]===c?l=t[4]:(l=c(`chat.sessionRecovery.awaitingConfirmation`),t[3]=c,t[4]=l);let u;return t[5]===l?u=t[6]:(u=(0,$.jsx)(`div`,{className:`px-4 py-1.5`,"aria-live":`polite`,children:(0,$.jsx)(Uv,{presentation:{text:l,icon:`restart`,variant:`info`}})}),t[5]=l,t[6]=u),u}var Gv=[0,200,400],Kv=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=Gv.map(qv),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 qv(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var Jv=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=Xn(),n=wa(Yv),r;e[0]===n?r=e[1]:(r=e=>{if(!n)return null;let t=e.runsByOriginalSessionID[n]??null;return t?.runtimeKey===u()?t:null},e[0]=n,e[1]=r);let i=Ta(r),a=Ta(Xv),o=K(Zv),s=K(Qv);if(!n||!i||i.status!==`running`)return null;let c;e[2]!==i.phase||e[3]!==t?(c=i.phase===`waiting_for_reviewer`?t(`chat.autoReview.status.waitingForReviewer`):t(`chat.autoReview.status.waitingForImplementer`),e[2]=i.phase,e[3]=t,e[4]=c):c=e[4];let l=c,d;e[5]!==o||e[6]!==i.directory||e[7]!==i.reviewSessionID||e[8]!==t?(d=()=>{o(i.directory,{mode:`chat`,dedupeKey:`session:${i.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=o,e[6]=i.directory,e[7]=i.reviewSessionID,e[8]=t,e[9]=d):d=e[9];let f=d,p=s?`pb-1 text-xs`:`pb-2`,m;e[10]===p?m=e[11]:(m=Y(`w-full px-1`,p),e[10]=p,e[11]=m);let h=s?`rounded-lg`:`rounded-xl`,g;e[12]===h?g=e[13]:(g=Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,h),e[12]=h,e[13]=g);let _=s?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`,v;e[14]===_?v=e[15]:(v=Y(`flex w-full items-center text-left`,_),e[14]=_,e[15]=v);let y=s?`size-3.5`:`size-4`,b;e[16]===y?b=e[17]:(b=Y(`animate-spin text-muted-foreground`,y),e[16]=y,e[17]=b);let x;e[18]===b?x=e[19]:(x=(0,$.jsx)(X,{name:`loader-4`,className:b,"aria-hidden":`true`}),e[18]=b,e[19]=x);let S;e[20]===t?S=e[21]:(S=t(`chat.autoReview.title`),e[20]=t,e[21]=S);let C;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Kv,{}),e[22]=C):C=e[22];let w;e[23]===S?w=e[24]:(w=(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:[S,C]}),e[23]=S,e[24]=w);let T;e[25]===l?T=e[26]:(T=(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:l}),e[25]=l,e[26]=T);let E;e[27]!==w||e[28]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[w,T]}),e[27]=w,e[28]=T,e[29]=E):E=e[29];let D;e[30]===t?D=e[31]:(D=t(`chat.autoReview.actions.open`),e[30]=t,e[31]=D);let O;e[32]!==f||e[33]!==D?(O=(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`xs`,onClick:f,children:D}),e[32]=f,e[33]=D,e[34]=O):O=e[34];let k;e[35]!==n||e[36]!==a?(k=()=>a(n),e[35]=n,e[36]=a,e[37]=k):k=e[37];let A;e[38]===t?A=e[39]:(A=t(`chat.autoReview.actions.stop`),e[38]=t,e[39]=A);let j;e[40]!==k||e[41]!==A?(j=(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`xs`,onClick:k,children:A}),e[40]=k,e[41]=A,e[42]=j):j=e[42];let M;e[43]!==x||e[44]!==E||e[45]!==O||e[46]!==j||e[47]!==v?(M=(0,$.jsxs)(`div`,{className:v,children:[x,E,O,j]}),e[43]=x,e[44]=E,e[45]=O,e[46]=j,e[47]=v,e[48]=M):M=e[48];let N;e[49]!==M||e[50]!==g?(N=(0,$.jsx)(`div`,{className:g,children:M}),e[49]=M,e[50]=g,e[51]=N):N=e[51];let P;return e[52]!==N||e[53]!==m?(P=(0,$.jsx)(`div`,{className:m,children:N}),e[52]=N,e[53]=m,e[54]=P):P=e[54],P});Jv.displayName=`AutoReviewBanner`;function Yv(e){return e.currentSessionId}function Xv(e){return e.stopRun}function Zv(e){return e.openContextPanelTab}function Qv(e){return e.isMobile}function $v(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`pointer-events-none inline-flex h-5 min-w-5 shrink-0 select-none items-center justify-center`,`rounded-md border border-[var(--interactive-border)] bg-[var(--surface-muted)]`,`px-1.5 font-mono typography-micro font-medium leading-none normal-case`,`text-[var(--surface-muted-foreground)] whitespace-nowrap`,`shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.12)]`,`dark:shadow-[inset_0_-1px_0_0_rgba(255,255,255,0.08)]`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`kbd`,{"data-slot":`kbd`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function ey(e){let t=(0,Q.c)(15),{shortcut:n,className:r,tone:i}=e,a=i===void 0?`default`:i,o,s,c,l;if(t[0]!==r||t[1]!==n||t[2]!==a){l=Symbol.for(`react.early_return_sentinel`);bb0:{let e=n.split(`+`).map(ty).filter(Boolean);if(e.length===0){l=null;break bb0}o=`shortcut-kbd`,t[7]===r?s=t[8]:(s=Y(`inline-flex items-center gap-1 whitespace-nowrap normal-case`,r),t[7]=r,t[8]=s);let i;t[9]===a?i=t[10]:(i=(e,t)=>(0,$.jsxs)(Z.Fragment,{children:[t>0?(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-[var(--surface-muted-foreground)]`,children:`+`}):null,(0,$.jsx)($v,{className:Y(a===`selection`&&`border-[var(--interactive-selection)] bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`),children:/^[a-z]$/i.test(e)?e.toUpperCase():e})]},`${e}-${t}`),t[9]=a,t[10]=i),c=e.map(i)}t[0]=r,t[1]=n,t[2]=a,t[3]=o,t[4]=s,t[5]=c,t[6]=l}else o=t[3],s=t[4],c=t[5],l=t[6];if(l!==Symbol.for(`react.early_return_sentinel`))return l;let u;return t[11]!==o||t[12]!==s||t[13]!==c?(u=(0,$.jsx)(`span`,{"data-slot":o,className:s,children:c}),t[11]=o,t[12]=s,t[13]=c,t[14]=u):u=t[14],u}function ty(e){return e.trim()}var ny=e=>e===`full`||e===`allow`?{text:`var(--status-info)`,border:`color-mix(in srgb, var(--status-info) 25%, transparent)`,background:`color-mix(in srgb, var(--status-info) 4%, transparent)`,borderWidth:1.5}:null,ry=1e3,iy=e=>{let t=(0,Q.c)(27),{name:n,label:r,revealed:i,avatarSize:a,slotClassName:o,labelGapClassName:s,colorVar:c}=e,l=s===void 0?`pl-1.5 pr-0.5`:s,u;t[0]===o?u=t[1]:(u=Y(`inline-flex shrink-0 items-center justify-center`,o),t[0]=o,t[1]=u);let d=i?void 0:r,f;t[2]!==a||t[3]!==n||t[4]!==d?(f=(0,$.jsx)(ds,{name:n,size:a,label:d}),t[2]=a,t[3]=n,t[4]=d,t[5]=f):f=t[5];let p;t[6]!==u||t[7]!==f?(p=(0,$.jsx)(`span`,{className:u,children:f}),t[6]=u,t[7]=f,t[8]=p):p=t[8];let m=i?`grid-cols-[1fr] opacity-100`:`grid-cols-[0fr] opacity-0`,h;t[9]===m?h=t[10]:(h=Y(`grid min-w-0 items-center ease-in-out`,m),t[9]=m,t[10]=h);let g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(g={transitionProperty:`grid-template-columns, opacity`,transitionDuration:`280ms`,transitionTimingFunction:`ease-in-out`},t[11]=g):g=t[11];let _=!i,v;t[12]===l?v=t[13]:(v=Y(`inline-block whitespace-nowrap typography-micro leading-none font-medium`,l),t[12]=l,t[13]=v);let y;t[14]===c?y=t[15]:(y=c?{color:`var(${c})`}:void 0,t[14]=c,t[15]=y);let b;t[16]!==r||t[17]!==v||t[18]!==y?(b=(0,$.jsx)(`span`,{className:`flex min-w-0 items-center overflow-hidden`,children:(0,$.jsx)(`span`,{className:v,style:y,children:r})}),t[16]=r,t[17]=v,t[18]=y,t[19]=b):b=t[19];let x;t[20]!==b||t[21]!==h||t[22]!==_?(x=(0,$.jsx)(`span`,{className:h,style:g,"aria-hidden":_,children:b}),t[20]=b,t[21]=h,t[22]=_,t[23]=x):x=t[23];let S;return t[24]!==x||t[25]!==p?(S=(0,$.jsxs)($.Fragment,{children:[p,x]}),t[24]=x,t[25]=p,t[26]=S):S=t[26],S};function ay(e){let t=(0,Q.c)(5),[n,r]=Z.useState(!1),i=Z.useRef(void 0),a=Z.useRef(!1),o=Z.useRef(null),s,c;t[0]===e?(s=t[1],c=t[2]):(s=()=>{if(!a.current){a.current=!0,i.current=e;return}if(e===i.current)return;let t=i.current;if(i.current=e,!t||!e){r(!1);return}return r(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{r(!1),o.current=null},ry),()=>{o.current&&=(clearTimeout(o.current),null)}},c=[e],t[0]=e,t[1]=s,t[2]=c),Z.useEffect(s,c);let l,u;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>()=>{o.current&&clearTimeout(o.current)},u=[],t[3]=l,t[4]=u):(l=t[3],u=t[4]),Z.useEffect(l,u),n}var oy=`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,sy=e=>`flow-root ${e?`py-1`:`py-1.5`}`,cy=e=>`relative ml-2 flex flex-col pl-3 ${e?`gap-1 pt-1`:`gap-1.5 pt-1.5`}`,ly=`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,uy=`${oy} ${ly}`,dy=`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] data-[popup-open]:!bg-[color-mix(in_srgb,var(--surface-foreground)_10%,transparent)] data-[state=open]:!bg-[color-mix(in_srgb,var(--surface-foreground)_10%,transparent)]`,fy=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${dy}`,py=`rounded-md ${dy}`,my=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},hy=e=>{if(e)try{let t=my();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},gy=(e,t)=>{if(!e||e.length===0)return`ask`;for(let n=e.length-1;n>=0;--n){let r=e[n];if(r.permission===t&&r.pattern===`*`)return r.action}for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.permission===`*`&&n.pattern===`*`)return n.action}return`ask`},_y=e=>{let t=hy(e);return t?gy(t.permission,`edit`):`ask`},vy=e=>{if(!e||typeof e!=`object`)return 0;let t=e.input??0,n=e.output??0,r=e.reasoning??0,i=e.cache&&typeof e.cache==`object`?e.cache.read??0:0,a=e.cache&&typeof e.cache==`object`?e.cache.write??0:0;return t+n+r+i+a},yy=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return vy(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:vy(n.tokens)},by=e=>{if(!e||typeof e!=`object`)return{percent:0,hasInput:!1};let t=e.input??0,n=e.cache&&typeof e.cache==`object`?e.cache.read??0:0,r=e.cache&&typeof e.cache==`object`?e.cache.write??0:0,i=t+n+r;return i<=0?{percent:0,hasInput:!1}:{percent:Math.min(100,Math.max(0,Math.max(0,n)/i*100)),hasInput:!0}},xy=(e,t,n)=>{let r=Number.isFinite(t)?Math.max(t,0):0,i=Number.isFinite(n)&&n>0,a=i?Math.max(n,0):0,o=Math.min(Math.min(i?a:32e3,32e3),r),s=r>0?Math.max(r-o,1):0,c=s>0?e/s*100:0;return{percentage:Math.min(c,100),contextLimit:r,outputLimit:a,thresholdLimit:s||1,normalizedOutput:o}},Sy=[`ask`,`allow`,`full`],Cy=`__global__`,wy=L()(B(R((e,t)=>({sessionModelSelections:new Map,sessionAgentSelections:new Map,sessionAgentModelSelections:new Map,sessionAgentModelVariantSelections:new Map,currentAgentContext:new Map,sessionContextUsage:new Map,sessionAgentEditModes:new Map,hasHydrated:typeof window>`u`,saveSessionModelSelection:(t,n,r)=>{e(e=>{let i=new Map(e.sessionModelSelections);return i.set(t,{providerId:n,modelId:r}),{sessionModelSelections:i}})},getSessionModelSelection:e=>{let{sessionModelSelections:n}=t();return n.get(e)||null},saveSessionAgentSelection:(t,n)=>{e(e=>{let r=new Map(e.sessionAgentSelections);r.set(t,n);let i=new Map(e.currentAgentContext);return i.set(t,n),{sessionAgentSelections:r,currentAgentContext:i}})},getSessionAgentSelection:e=>{let{sessionAgentSelections:n}=t();return n.get(e)||null},saveAgentModelForSession:(t,n,r,i)=>{e(e=>{let a=new Map(e.sessionAgentModelSelections),o=a.get(t);return o=o?new Map(o):new Map,o.set(n,{providerId:r,modelId:i}),a.set(t,o),{sessionAgentModelSelections:a}})},getAgentModelForSession:(e,n)=>{let{sessionAgentModelSelections:r}=t(),i=r.get(e);return i&&i.get(n)||null},saveAgentModelVariantForSession:(t,n,r,i,a)=>{e(e=>{let o=new Map(e.sessionAgentModelVariantSelections),s=o.get(t);s=s?new Map(s):new Map;let c=s.get(n);c=c?new Map(c):new Map;let l=`${r}/${i}`;return a===void 0?(c.delete(l),c.size===0?(s.delete(n),s.size===0?o.delete(t):o.set(t,s)):(s.set(n,c),o.set(t,s))):(c.set(l,a),s.set(n,c),o.set(t,s)),{sessionAgentModelVariantSelections:o}})},getAgentModelVariantForSession:(e,n,r,i)=>{let{sessionAgentModelVariantSelections:a}=t(),o=a.get(e);if(!o)return;let s=o.get(n);if(s)return s.get(`${r}/${i}`)},getContextUsage:(n,r,i,a)=>{if(!n)return null;let o=xy(0,r,i),s=o.contextLimit,c=o.normalizedOutput??0,l=o.thresholdLimit;if(s===0||l===0)return null;let u=(a.get(n)||[]).filter(e=>e.info.role===`assistant`);if(u.length===0)return null;let d=u[u.length-1],f=d.info.id,p=t=>{let r=()=>{e(e=>{let r=e.sessionContextUsage.get(n);if(r&&r.totalTokens===t.totalTokens&&r.percentage===t.percentage&&r.contextLimit===t.contextLimit&&(r.outputLimit??0)===(t.outputLimit??0)&&(r.normalizedOutput??0)===(t.normalizedOutput??0)&&r.thresholdLimit===t.thresholdLimit&&r.lastMessageId===t.lastMessageId)return e;let i=new Map(e.sessionContextUsage);return i.set(n,t),{sessionContextUsage:i}})};typeof queueMicrotask==`function`?queueMicrotask(r):typeof window<`u`?window.setTimeout(r,0):setTimeout(r,0)},m=t().sessionContextUsage.get(n);if(m&&m.lastMessageId===f){let e=m.normalizedOutput??m.outputLimit??0,t=m.contextLimit!==s||e!==c||m.thresholdLimit!==l;if(t&&m.totalTokens>0){let e=m.totalTokens/l*100,t={totalTokens:m.totalTokens,percentage:Math.min(e,100),contextLimit:s,outputLimit:o.outputLimit,normalizedOutput:c,thresholdLimit:l,lastMessageId:f};return p(t),t}if(!t&&m.totalTokens>0)return m}let h=yy(d);if(h===0)return m||null;let g=xy(h,r,i),_={totalTokens:h,percentage:g.percentage,contextLimit:g.contextLimit,outputLimit:g.outputLimit,normalizedOutput:g.normalizedOutput,thresholdLimit:g.thresholdLimit,lastMessageId:f};return p(_),_},updateSessionContextUsage:(t,n,r,i)=>{let a=(i.get(t)||[]).filter(e=>e.info.role===`assistant`);if(a.length===0)return;let o=a[a.length-1],s=yy(o);if(s===0)return;let c=xy(s,n,r);e(e=>{let n=new Map(e.sessionContextUsage);return n.set(t,{totalTokens:s,percentage:c.percentage,contextLimit:c.contextLimit,outputLimit:c.outputLimit,normalizedOutput:c.normalizedOutput,thresholdLimit:c.thresholdLimit,lastMessageId:o.info.id}),{sessionContextUsage:n}})},initializeSessionContextUsage:(e,n,r,i)=>{let a=t().sessionContextUsage.get(e);(!a||a.totalTokens===0)&&t().updateSessionContextUsage(e,n,r,i)},pollForTokenUpdates:(e,n,r,i=10)=>{let a=0,o=()=>{a++;let s=(r.get(e)||[]).find(e=>e.info.id===n);if(s&&s.info.role===`assistant`&&yy(s)>0){t().updateSessionContextUsage(e,0,0,r);return}a<i&&setTimeout(o,1e3)};setTimeout(o,2e3)},getCurrentAgent:e=>{let{currentAgentContext:n}=t();return n.get(e)},getSessionAgentEditMode:(e,n,r=_y(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Cy){let e=t().sessionAgentEditModes.get(Cy)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=_y(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Sy.includes(r)&&e(e=>{let i=new Map(e.sessionAgentEditModes),o=new Map(i.get(t)??new Map);return r===a?(o.delete(n),o.size===0?i.delete(t):i.set(t,o)):(o.set(n,r),i.set(t,o)),{sessionAgentEditModes:i}})},toggleSessionAgentEditMode:(e,n,r=_y(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Sy.indexOf(a),s=Sy.indexOf(i),c=Sy[((o>=0?o:s>=0?s:0)+1)%Sy.length];t().setSessionAgentEditMode(e,n,c,i)}}),{name:`context-store`,storage:_t(),partialize:e=>({sessionModelSelections:Array.from(e.sessionModelSelections.entries()),sessionAgentSelections:Array.from(e.sessionAgentSelections.entries()),sessionAgentModelSelections:Array.from(e.sessionAgentModelSelections.entries()).map(([e,t])=>[e,Array.from(t.entries())]),sessionAgentModelVariantSelections:Array.from(e.sessionAgentModelVariantSelections.entries()).map(([e,t])=>[e,Array.from(t.entries()).map(([e,t])=>[e,Array.from(t.entries())])]),currentAgentContext:Array.from(e.currentAgentContext.entries()),sessionContextUsage:Array.from(e.sessionContextUsage.entries()),sessionAgentEditModes:Array.from(e.sessionAgentEditModes.entries()).map(([e,t])=>[e,Array.from(t.entries())])}),merge:(e,t)=>{let n=new Map;e?.sessionAgentModelSelections&&e.sessionAgentModelSelections.forEach(([e,t])=>{n.set(e,new Map(t))});let r=new Map;e?.sessionAgentModelVariantSelections&&e.sessionAgentModelVariantSelections.forEach(([e,t])=>{let n=new Map;t.forEach(([e,t])=>{n.set(e,new Map(t))}),r.set(e,n)});let i=new Map;return e?.sessionAgentEditModes&&e.sessionAgentEditModes.forEach(([e,t])=>{i.set(e,new Map(t))}),{...t,...e,sessionModelSelections:new Map(e?.sessionModelSelections||[]),sessionAgentSelections:new Map(e?.sessionAgentSelections||[]),sessionAgentModelSelections:n,sessionAgentModelVariantSelections:r,currentAgentContext:new Map(e?.currentAgentContext||[]),sessionContextUsage:new Map(e?.sessionContextUsage||[]),sessionAgentEditModes:i,hasHydrated:!0}}}),{name:`context-store`})),Ty=e=>is([...e??[]]);function Ey(e,t){return!e&&t===`trigger-hover`}var Dy=(e,t)=>{let n=e.target;n instanceof Element&&e.currentTarget.contains(n)&&(n.closest(`textarea[data-chat-input="true"]`)||n.closest(`[data-chat-prompt-attachments="true"]`)||n.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(t(),e.preventDefault()))},Oy=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},ky=e=>{let t=Oy(e);return t?(t.focus({preventScroll:!0}),!0):!1},Ay=(e,t)=>e&&!t,jy=(e,t)=>{if(!e)return t;let n=e.ready&&!e.loading;return{modelsReady:!e.error&&(e.modelsReady??n),agentsReady:!e.error&&(e.agentsReady??n)}},My=e=>{let t=e?.variants;if(!t)return[];if(Array.isArray(t)){let e=[],n=new Set;for(let r of t){let t=typeof r==`string`?r:r&&typeof r==`object`&&!Array.isArray(r)&&typeof r.id==`string`?r.id:``;!t||n.has(t)||(n.add(t),e.push(t))}return e}return typeof t==`object`?Object.keys(t):[]},Ny=(e,t,n,r)=>{if(e.providerID!==n||e.modelID!==r||t?.variantsReady===!1)return[];if(t?.variants)return[...t.variants];let i=(t?.providers?.find(e=>e.id===n))?.models?.find(e=>e.id===r);return My(i)},Py=()=>!0,Fy=(e,t)=>(e.commandPolicy??Py)(t),Iy=Z.createContext(null),Ly=()=>Z.useContext(Iy),Ry=e=>e,zy=(e,t)=>t??e,By=e=>{if(e.kind!==`primary`&&(!e.sessionID||!e.directory||!e.draftKey||!e.transportIdentity||!Number.isSafeInteger(e.runtimeGeneration)||!e.resources||typeof e.resources.busy!=`boolean`||!e.activity||!e.commands||!e.shortcuts))throw Error(`chat-input-secondary-surface-incomplete`)},Vy=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,Hy=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},Uy=(e,t,n)=>{if(e.kind===`secondary`){if(!e.commands)throw Error(`chat-input-secondary-commands-incomplete`);return e.commands}return e.commands?e.commands:{sessionID:e.sessionID,hasMessages:t,hasNewDraft:n}},Wy=(e,t)=>`${e}:${t}`,Gy=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,Ky=e=>{if(!Array.isArray(e))return null;let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;typeof e.permission==`string`&&typeof e.pattern==`string`&&typeof e.action==`string`&&(e.action===`allow`||e.action===`ask`||e.action===`deny`)&&t.push({permission:e.permission,pattern:e.pattern,action:e.action})}return t},qy=(e,t)=>{let n=Ky(e);if(!(!n||n.length===0)){for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.permission===t&&r.pattern===`*`)return r.action}for(let e=n.length-1;e>=0;--e){let t=n[e];if(t.permission===`*`&&t.pattern===`*`)return t.action}}},Jy=[{key:`tool_call`,icon:`tools`,label:`Tool calling`,isActive:e=>e?.tool_call===!0},{key:`reasoning`,icon:`brain-ai-3`,label:`Reasoning`,isActive:e=>e?.reasoning===!0}],Yy={text:{icon:`text`,label:`Text`},image:{icon:`file-image`,label:`Image`},video:{icon:`file-video`,label:`Video`},audio:{icon:`file-music`,label:`Audio`},pdf:{icon:`file-pdf`,label:`PDF`}},Xy=e=>e.trim().toLowerCase(),Zy=(e,t)=>{let n=t===`input`?e?.modalities?.input:e?.modalities?.output;if(!Array.isArray(n)||n.length===0)return[];let r=Array.from(new Set(n.map(e=>Xy(e)))),i=[];for(let e of r){let t=Yy[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},Qy=e=>_c(e),$y=e=>wc(e),eb=e=>yc(e),tb=`__add_provider__`,nb=e=>{let t=(0,Q.c)(5),{iconName:n,label:r}=e,i;t[0]===n?i=t[1]:(i=(0,$.jsx)(X,{name:n,className:`size-3.5`}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,$.jsx)(`span`,{className:`flex size-5 items-center justify-center rounded-xl bg-muted/60 text-muted-foreground`,title:r,"aria-label":r,role:`img`,children:i}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a},rb=e=>{let t=(0,Q.c)(18),{mode:n,className:r}=e,i;t[0]===r?i=t[1]:(i=Y(r,`flex-shrink-0`),t[0]=r,t[1]=i);let a=i,o;t[2]===n?o=t[3]:(o=ny(n),t[2]=n,t[3]=o);let s=o,c=s?s.text:`var(--foreground)`,l;t[4]===c?l=t[5]:(l={color:c},t[4]=c,t[5]=l);let u=l;if(n===`full`){let e;return t[6]!==a||t[7]!==u?(e=(0,$.jsx)(X,{name:`pencil-ai`,className:a,style:u}),t[6]=a,t[7]=u,t[8]=e):e=t[8],e}if(n===`allow`){let e;return t[9]!==a||t[10]!==u?(e=(0,$.jsx)(X,{name:`checkbox-circle`,className:a,style:u}),t[9]=a,t[10]=u,t[11]=e):e=t[11],e}if(n===`deny`){let e;return t[12]!==a||t[13]!==u?(e=(0,$.jsx)(X,{name:`close-circle`,className:a,style:u}),t[12]=a,t[13]=u,t[14]=e):e=t[14],e}let d;return t[15]!==a||t[16]!==u?(d=(0,$.jsx)(X,{name:`question`,className:a,style:u}),t[15]=a,t[16]=u,t[17]=d):d=t[17],d},ib=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=Qy(e);return t.endsWith(`.0`)?t.slice(0,-2):t},ab=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:$y(e),ob=e=>{let t=[];for(let n of Jy)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},sb=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:eb(t)},cb=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=Xn(),o=Z.useId(),{isReady:s,isUnavailable:c}=Fc(),l=c||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),u=Ko(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),d=Ko(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=i?.catalog,p=jy(f,{modelsReady:!u,agentsReady:!d}),m=s&&p.modelsReady&&!i?.disabled,h=s&&p.agentsReady&&!i?.disabled,g=m&&h,_=Ko(e=>e.providers),v=f?.providers??_,y=Ko(e=>e.currentProviderId),b=Ko(e=>e.currentModelId),x=i?.selection.providerID??y,S=i?.selection.modelID??b,C=Ko(e=>e.currentVariant),w=i?i.selection.variant:C,T=Ko(e=>e.currentAgentName),E=i?i.selection.agent??void 0:T,D=Ko(e=>e.settingsDefaultVariant),O=Ko(e=>e.settingsDefaultAgent),k=Ko(e=>e.setProvider),A=Ko(e=>e.setSelectedProvider),j=Ko(e=>e.setModel),M=Ko(e=>e.setCurrentVariant),N=Ko(e=>e.getCurrentModelVariants),P=Ko(e=>e.setAgent),F=Ko(e=>e.getCurrentProvider),I=Ko(e=>e.getModelMetadata),L=Ko(e=>e.getCurrentAgent),R=Ko(e=>e.getVisibleAgents),z=Ty(f?.agents??R()),B=Z.useMemo(()=>z.filter(e=>e.mode===`primary`),[z]),V=Z.useRef(!1);Z.useEffect(()=>{V.current||!g||(V.current=!0,Ke(`ModelControls:ready`,{providers:v.length,agents:z.length,currentProviderId:x,currentModelId:S,currentAgentName:E}))},[z.length,g,E,S,x,v.length]);let H=wa(e=>i?null:e.currentSessionId),U=wa(e=>e.getDirectoryForSession),W=dh(),ee=ur(e=>e.getSessionModelSelection),te=ur(e=>e.saveSessionModelSelection),ne=ur(e=>e.saveSessionAgentSelection),re=ur(e=>e.saveAgentModelForSession),G=ur(e=>e.getAgentModelForSession),ie=ur(e=>e.saveAgentModelVariantForSession),ae=ur(e=>e.getAgentModelVariantForSession),oe=wy(e=>e.hasHydrated),se=ur(e=>H?e.sessionAgentSelections.get(H)??null:null),ce=Z.useRef(null);Z.useEffect(()=>{if(!H){ce.current=null;return}se&&(ce.current=se)},[H,se]);let le=H?ce.current:null,ue=i?i.selection.agent??void 0:H&&(se||le)||E,de=K(e=>e.toggleFavoriteModel),fe=K(e=>e.reorderFavoriteModel),pe=K(e=>e.providerOrder),me=K(e=>e.setProviderOrder),he=K(e=>e.isFavoriteModel),ge=K(e=>e.addRecentModel),_e=K(e=>e.addRecentAgent),ve=K(e=>e.addRecentEffort),ye=K(e=>e.isModelSelectorOpen),be=K(e=>e.setModelSelectorOpen),xe=K(e=>e.isAgentSelectorOpen),Se=K(e=>e.setAgentSelectorOpen),Ce=K(e=>e.isModelSelectorInstant),we=K(e=>e.isAgentSelectorInstant),Te=K(e=>e.setSettingsDialogOpen),Ee=K(e=>e.setSettingsPage),De=K(e=>e.hiddenModels),Oe=K(e=>e.shortcutOverrides.cycle_agent),ke=Z.useMemo(()=>Ec(`cycle_agent`,Oe?{cycle_agent:Oe}:void 0),[Oe]),{favoriteModelsList:Ae,recentModelsList:je}=Ds({currentProviderID:x,currentModelID:S}),{isMobile:Me}=Kc(),Ne=K(e=>e.isMobile),Pe=Me||Ne,Fe=Dn(),Ie=Pe,[Le,Re]=Z.useState(null),ze=n!==void 0&&typeof r==`function`,Be=ze?n:Le,Ve=ze?r:Re,He=J(e=>{Ve(e),Ko.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),Ue=J((e,t)=>{if(Ey(e,t?.reason)){t?.cancel?.();return}Se(e),e&&Ko.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopAgentMenu`})}),[We,Ge]=Z.useState(null),qe=Z.useRef(!1),Je=Z.useCallback(()=>Ve(null),[Ve]),Ye=Z.useCallback(()=>Ge(null),[]),Xe=Z.useRef(void 0),Ze=ye,Qe=be,$e=Z.useCallback(()=>{A(tb),Ee(`providers`),Te(!0),Qe(!1),Je()},[A,Ee,Te,Qe,Je]),[et,tt]=Z.useState(``),[nt,rt]=Z.useState(null),[it,at]=Z.useState(!1),ot=Z.useRef(0),st=J((e,t)=>{if(Ey(e,t?.reason)){t?.cancel?.();return}at(!1),e||(ot.current=performance.now()+200,rt(null),tt(``)),Qe(e),e&&Ko.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),ct=Z.useRef(!1),lt=Z.useRef(null),ut=Z.useRef(void 0),[dt,ft]=Z.useState(new Map),[pt,mt]=Z.useState(new Set),[gt,_t]=Z.useState(0),vt=Z.useCallback(()=>{let e=()=>{let e=K.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&ky(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),yt=Z.useCallback(e=>{let t=K.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(K.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!K.getState().isMobile&&vt())},[vt]),bt=Z.useCallback(()=>{let e=K.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Oy(t)},[t]),xt=Z.useRef(ye);Z.useEffect(()=>{let e=xt.current;xt.current=ye,ye||(tt(``),ct.current=!1,lt.current=null,ft(new Map),mt(new Set),e&&!Ie&&(at(!1),ot.current=performance.now()+200))},[ye,Ie]);let[St,Ct]=Z.useState(``);Z.useEffect(()=>{xe||Ct(``)},[xe]);let wt=Z.useMemo(()=>z.filter(e=>Ar(e.mode)),[z]),Tt=Z.useMemo(()=>St.trim()?Bi(wt,St.trim(),e=>[e.name,ht(e),e.description??``]).map(e=>e.item):[...wt].sort((e,t)=>e.name.localeCompare(t.name)),[wt,St]),Et=Z.useMemo(()=>{if(O){let e=wt.find(e=>e.name===O);if(e)return e.name}let e=wt.find(e=>e.name===`build`);return e?e.name:wt[0]?.name},[O,wt]),Dt=Z.useMemo(()=>ue?z.find(e=>e.name===ue):L?.(),[z,L,ue]),Ot=Pe?`mobile`:Fe?`vscode`:`default`,kt=Ot===`mobile`?`size-5`:`size-4`,At=Ie?`typography-micro`:`typography-meta`,jt=Ot===`mobile`?`gap-x-0.5`:Ot===`vscode`?`gap-x-2`:`gap-x-1.5`,Mt=Ot===`mobile`?`h-8 w-7`:`h-6 w-6`,Nt=Ot===`mobile`?24:20,Pt=Ot===`mobile`?`pl-1 pr-0.5`:`pl-1.5 pr-0.5`,Ft=ay(ue),It=i?v.find(e=>e.id===x):F(),Lt=Array.isArray(It?.models)?It.models:[],Rt=S?Lt.find(e=>e.id===S):void 0,zt=x&&S&&Rt?Us(x,Rt,I(x,S)):x&&S?I(x,S):void 0,Bt=Z.useCallback(e=>e===`Tool calling`?a(`chat.modelControls.capability.toolCalling`):e===`Reasoning`?a(`chat.modelControls.capability.reasoning`):e===`Text`?a(`chat.modelControls.modality.text`):e===`Image`?a(`chat.modelControls.modality.image`):e===`Video`?a(`chat.modelControls.modality.video`):e===`Audio`?a(`chat.modelControls.modality.audio`):e===`PDF`?a(`chat.modelControls.modality.pdf`):e,[a]),Vt=Z.useMemo(()=>ob(zt).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Ht=Z.useMemo(()=>Zy(zt,`input`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Ut=Z.useMemo(()=>Zy(zt,`output`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Wt=Z.useMemo(()=>{if(f?.variantsReady===!1)return[];if(f?.variants)return[...f.variants];if(x&&S){let e=v.find(e=>e.id===x)?.models?.find(e=>e.id===S);return My(e)}return i?[]:N()},[S,x,N,v,i,f?.variants,f?.variantsReady]),Gt=Wt.length>0,Kt=[{label:`Input`,value:ab(zt?.cost?.input)},{label:`Output`,value:ab(zt?.cost?.output)},{label:`Cache read`,value:ab(zt?.cost?.cache_read)},{label:`Cache write`,value:ab(zt?.cost?.cache_write)}],qt=[{label:`Context`,value:ib(zt?.limit?.context)},{label:`Output`,value:ib(zt?.limit?.output)}],Jt=Z.useRef(void 0),Yt=Z.useRef(null),Xt=Z.useRef(null),Zt=H?U(H):void 0,Qt=Ja(H??``,Zt??void 0).renderable,$t=Ca(H??``,Zt??void 0),en=Z.useMemo(()=>{for(let e=$t.length-1;e>=0;--e){let t=$t[e];if(t.role!==`user`)continue;let n=typeof t.model?.providerID==`string`&&t.model.providerID.trim().length>0?t.model.providerID:void 0,r=typeof t.model?.modelID==`string`&&t.model.modelID.trim().length>0?t.model.modelID:void 0,i=typeof t.agent==`string`&&t.agent.trim().length>0?t.agent:typeof t.mode==`string`&&t.mode.trim().length>0?t.mode:void 0,a=t.model?.variant??t.variant,o=typeof a==`string`&&a.trim().length>0?a:void 0;return{id:t.id,agent:i,providerID:n,modelID:r,variant:o}}return null},[$t]),tn=Z.useCallback((e,t,n)=>{if(!e||!t)return`model-missing`;let r=v.find(t=>t.id===e);return r?(Array.isArray(r.models)?r.models:[]).find(e=>e.id===t)?x===e&&S===t?`applied`:(k(e),j(t),H&&(te(H,e,t),n&&re(H,n,e,t)),`applied`):`model-missing`:`provider-missing`},[v,x,S,k,j,H,re,te]),nn=Z.useCallback((e,t)=>{if(i&&i.selection.providerID===e&&i.selection.modelID===t)return Ny(i.selection,i.catalog,e,t);let n=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return My(n)},[v,i,i?.selection.providerID,i?.selection.modelID,f?.variants,f?.variantsReady]),rn=Z.useCallback((e,t)=>{let n=i?Ny(i.selection,i.catalog,e,t):[],r=n.length>0?n:nn(e,t);if(r.length===0)return;if(i){let n=i.selection.variant;if(i.selection.providerID===e&&i.selection.modelID===t&&n&&r.includes(n))return n}let a=ue||E;if(H&&a){let n=ae(H,a,e,t);if(n&&r.includes(n))return n}if(x===e&&S===t&&w&&r.includes(w))return w;if(!H&&D&&r.includes(D))return D},[E,S,x,H,w,ae,nn,i,D,ue]),an=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=Ko.getState().currentAgentName;return H?ur.getState().getSessionAgentSelection(H)||ce.current||e||E:e||E},[E,H,i]),on=Z.useCallback((e,t,n,r)=>{if(i){i.onChange({...i.selection,providerID:e,modelID:t,variant:n}).catch(()=>void 0);return}if(nn(e,t).length===0){qe.current=!1,M(void 0);return}qe.current=!0,M(n),ve(e,t,n);let a=r??an();H&&a&&ie(H,a,e,t,n)},[ve,H,nn,an,ie,i,M]),sn=Z.useCallback((e,t,n,r)=>{let a=r??an()??void 0,o=tn(e,t,a);if(o!==`applied`)return o;on(e,t,n,a);let s=i?n:Ko.getState().currentVariant;return ge(e,t,s),`applied`},[ge,on,an,i,tn]);Z.useEffect(()=>{if(i)return;if(!H){Xt.current=null;return}if(!oe||v.length===0||!Qt||!en?.providerID||!en.modelID)return;let e=[H,en.id,en.agent??``,en.providerID,en.modelID,en.variant??``].join(`|`);if(Xt.current===e)return;en.agent&&E!==en.agent&&P(en.agent);let t=en.variant&&nn(en.providerID,en.modelID).includes(en.variant)?en.variant:void 0;sn(en.providerID,en.modelID,t,en.agent||E||void 0)===`applied`&&(en.agent&&(ne(H,en.agent),ie(H,en.agent,en.providerID,en.modelID,t)),te(H,en.providerID,en.modelID),Xt.current=e)},[i,H,E,oe,v,Qt,en,P,sn,nn,ne,ie,te]),Z.useEffect(()=>{if(i)return;if(!H){Xt.current=null;return}if(!oe||v.length===0||z.length===0)return;let e=()=>{let e=ee(H),t=H?ur.getState().getSessionAgentSelection(H):null;if(t){E!==t&&P(t);let e=G(H,t);if(e){let n=tn(e.providerId,e.modelId,t);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}}if(e){let n=tn(e.providerId,e.modelId,t||E||void 0);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}for(let e of z){let t=G(H,e.name);if(!t)continue;E!==e.name&&P(e.name),ur.getState().getSessionAgentSelection(H)||ce.current||ne(H,e.name);let n=tn(t.providerId,t.modelId,e.name);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}return`continue`},t=()=>{if(z.length===0)return;let e=H?ur.getState().getSessionAgentSelection(H)||ce.current:null,t=(H?ur.getState().getSessionAgentSelection(H)||ce.current:null)||E;if(t&&z.some(e=>e.name===t)){E!==t&&P(t);return}let n=z.find(e=>e.name===`build`)||B[0]||z[0];n&&(e||ne(H,n.name),E!==n.name&&P(n.name),n.model?.providerID&&n.model?.modelID&&tn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!Qt){W.isLoading(H)||W.ensureSessionRenderable(H);return}en||t()}},[i,H,Qt,en,z,B,E,ee,G,P,tn,ne,oe,v,W]),Z.useEffect(()=>{if(i||!oe)return;let e=new AbortController;return(async()=>{try{if(E!==Jt.current&&(Jt.current=E,E&&H)){let t=Yt.current===E;if(Yt.current=null,await new Promise(t=>{let n=setTimeout(t,50);e.signal.addEventListener(`abort`,()=>{clearTimeout(n),t()})}),e.signal.aborted)return;let n=G(H,E);if(n){let e=tn(n.providerId,n.modelId,E);if(e===`applied`||e===`provider-missing`)return}let r=Ko.getState().getAgentModelSelection(E);if(r){let e=tn(r.providerId,r.modelId,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(te(H,r.providerId,r.modelId),re(H,E,r.providerId,r.modelId),r.variant!==void 0&&(ie(H,E,r.providerId,r.modelId,r.variant),M(r.variant)));return}}let i=t?z.find(e=>e.name===E):void 0;if(i?.model?.providerID&&i.model.modelID){let e=tn(i.model.providerID,i.model.modelID,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(te(H,i.model.providerID,i.model.modelID),re(H,E,i.model.providerID,i.model.modelID));return}}}}catch(e){console.error(`[ModelControls] Agent change error:`,e)}})(),()=>{e.abort()}},[i,z,E,H,G,re,ie,te,M,tn,oe]),Z.useEffect(()=>{if(i)return;if(!oe||!E){qe.current=!1,M(void 0);return}if(!x||!S){qe.current=!1,M(void 0);return}if(Wt.length===0){qe.current=!1,M(void 0);return}if(w&&!Wt.includes(w)){M(void 0);return}if(!H){if(!w&&!qe.current){let e=D&&Wt.includes(D)?D:void 0;M(e)}return}let e=ae(H,E,x,S),t=e&&Wt.includes(e)?e:D&&Wt.includes(D)?D:void 0;M(t),qe.current=!1},[i,Wt,oe,H,E,x,S,w,ae,M,D]),Z.useEffect(()=>{qe.current=!1},[x,S]);let cn=Z.useCallback((e,t)=>{if(i){let n=Ur(i.selection,e,z,v),r=n.providerID===i.selection.providerID&&n.modelID===i.selection.modelID;Ie&&Je(),i.onChange({...n,variant:r?i.selection.variant:void 0}).then(()=>{_e(e),(t?.closeModelSelector??!0)&&Qe(!1)}).catch(()=>void 0);return}try{Yt.current=e,P(e),_e(e),(t?.closeModelSelector??!0)&&Qe(!1),H&&ne(H,e),Ie&&Je()}catch(e){console.error(`[ModelControls] Handle agent change error:`,e)}},[_e,z,Je,H,Ie,v,ne,i,P,Qe]),ln=Z.useCallback(e=>{let t=li(z,E,e);t&&cn(t,{closeModelSelector:!1})},[z,E,cn]),un=Z.useCallback(e=>{let t=ke&&!ke.includes(`shift`)?hc(`shift+${ke}`):``;return t&&Tc(e,t)?-1:Tc(e,ke)?1:null},[ke]),dn=Z.useCallback(e=>{let t=un(e);t&&(e.preventDefault(),e.stopPropagation(),ln(t))},[un,ln]),fn=Z.useCallback((e,t,n,r)=>{!e||!t||!n||Ko.getState().saveAgentModelSelection(e,t,n,r)},[]),pn=(e,t,n)=>{let r=()=>{Qe(!1,n?.closeInstant?{instant:!0}:void 0)};if(i){Ie&&Je();let a=n?.applyVariant?n.variant:rn(e,t);i.onChange({providerID:e,modelID:t,agent:n?.agentName??i.selection.agent,variant:a}).then(()=>{ge(e,t,a),r()}).catch(()=>void 0);return}try{let i=n?.agentName??an()??void 0,a=n?.applyVariant?sn(e,t,n.variant,i):tn(e,t,i);if(a!==`applied`){a===`provider-missing`?console.error(`[ModelControls] Provider not available for selection:`,e):a===`model-missing`&&console.error(`[ModelControls] Model not available for selection:`,{providerId:e,modelId:t});return}fn(i,e,t,n?.applyVariant?n.variant:Ko.getState().currentVariant),n?.applyVariant||ge(e,t,Ko.getState().currentVariant),r(),Ie&&Je()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},mn=(e,t)=>ni(e,t,{maxLength:40}),hn=()=>v.find(e=>e.id===x)?.name||x,gn=()=>{if(!S)return a(`chat.modelControls.selectModel`);let e=Lt.find(e=>e.id===S);return mn(e,S)||a(`chat.modelControls.selectModel`)},_n=gn(),vn=()=>{if(!ue){let e=B.find(e=>e.name===`build`)||B[0];return e?yn(ht(e)):a(`chat.modelControls.selectAgent`)}let e=z.find(e=>e.name===ue);return yn(e?ht(e):ue)},yn=e=>e.charAt(0).toUpperCase()+e.slice(1),bn=Z.useCallback(e=>{Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>{Ge(e)},500)},[]),q=Z.useCallback(()=>{Xe.current&&clearTimeout(Xe.current)},[]);Z.useEffect(()=>()=>{Xe.current&&clearTimeout(Xe.current)},[]);let xn=()=>!Ie||We!==`model`?null:(0,$.jsx)(zc,{open:!0,onClose:Ye,title:zt?.name||gn(),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-0.5`,children:a(`chat.modelControls.provider`)}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground font-medium`,children:hn()})]}),Vt.length>0&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.capabilities`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Vt.map(({key:e,icon:t,label:n})=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(nb,{iconName:t,label:n},`cap-${e}`),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:n})]},e))})]}),(Ht.length>0||Ut.length>0)&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.modalities`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[Ht.length>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-12`,children:a(`chat.modelControls.input`)}),(0,$.jsx)(`div`,{className:`flex gap-1`,children:Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} input`},`input-${e}`))})]}),Ut.length>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-12`,children:a(`chat.modelControls.output`)}),(0,$.jsx)(`div`,{className:`flex gap-1`,children:Ut.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} output`},`output-${e}`))})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.limits`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.context`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:ib(zt?.limit?.context)})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.output`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:ib(zt?.limit?.output)})]})]})]}),zt?.release_date?(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.metadata`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.release`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:sb(zt.release_date)})]})})]}):null]})}),Sn=()=>{if(!Ie||We!==`agent`||!Dt)return null;let e=!!(Dt.prompt&&Dt.prompt.trim().length>0),t=Dt.model?.providerID&&Dt.model?.modelID,n=Dt.temperature!==void 0||Dt.topP!==void 0,r=e=>{let t=Ky(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=qy(t,e)??`ask`;return n?{mode:`ask`,label:a(`chat.modelControls.permissionLabel.custom`)}:r===`allow`?{mode:`allow`,label:a(`chat.modelControls.permissionLabel.allow`)}:r===`deny`?{mode:`deny`,label:a(`chat.modelControls.permissionLabel.deny`)}:{mode:`ask`,label:a(`chat.modelControls.permissionLabel.ask`)}},i=r(`edit`),o=r(`bash`),s=r(`webfetch`);return(0,$.jsx)(zc,{open:!0,onClose:Ye,title:yn(Dt.name),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[Dt.description&&(0,$.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:Dt.description})}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-0.5`,children:a(`chat.modelControls.mode`)}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground font-medium`,children:Dt.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Dt.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Dt.mode===`all`?a(`chat.modelControls.modeValue.all`):a(`chat.modelControls.modeValue.none`)})]}),(t||n)&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.model`)}),t&&(0,$.jsxs)(`div`,{className:`typography-meta text-foreground font-medium mb-1`,children:[Dt.model.providerID,` / `,Dt.model.modelID]}),n&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[Dt.temperature!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.temperature`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.temperature})]}),Dt.topP!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.topP`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.topP})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.permissions`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.edit`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:i.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:i.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.bash`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:o.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:o.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.webFetch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:s.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:s.label})]})]})]})]}),e&&(0,$.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.customPrompt`)}),(0,$.jsx)(X,{name:`checkbox-circle`,className:`size-4 text-foreground`})]})})]})})},Cn=()=>Ie?(0,$.jsx)(vc,{open:Be===`model`||Be===`variant`,view:Be===`variant`?`variant`:`model`,onViewChange:e=>Ve(e),onClose:Je,selectedProviderID:x||``,selectedModelID:S||``,resolveSelectedVariant:rn,onSelect:(e,t,n)=>{if(i){Je(),i.onChange({providerID:e,modelID:t,agent:i.selection.agent,variant:n}).then(()=>{ge(e,t,n)}).catch(()=>void 0);return}let r=sn(e,t,n);if(r!==`applied`){r===`provider-missing`?console.error(`[ModelControls] Provider not available for selection:`,e):r===`model-missing`&&console.error(`[ModelControls] Model not available for selection:`,{providerId:e,modelId:t});return}fn(an(),e,t,n),Je()},providers:v,favoriteModels:Ae,recentModels:je,hiddenModels:De,providerOrder:pe,isFavorite:he,onToggleFavorite:(e,t)=>de(e,t,e===x&&t===S?w:Ae.find(n=>n.providerID===e&&n.modelID===t)?.variant??je.find(n=>n.providerID===e&&n.modelID===t)?.variant),getMetadata:I}):null,wn=()=>Ie?(0,$.jsx)(fl,{id:`mobile-agent-picker-sheet-${o}`,open:Be===`agent`,onOpenChange:e=>{e||Je()},ariaLabel:a(`chat.modelControls.selectAgent`),closeAriaLabel:a(`mobile.surface.closeAria`),resizeAriaLabel:a(`mobile.sessions.sheet.resizeAria`),bodyClassName:`px-2`,children:(0,$.jsx)(Xu,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`flex flex-col gap-2 overscroll-contain`,children:wt.map(e=>{let t=e.name===ue,n=os(e.name);return(0,$.jsx)(`button`,{type:`button`,className:Y(`flex w-full flex-col gap-1.5 rounded-xl border px-3 py-2.5 text-left`,`focus:outline-none focus-visible:ring-2 focus-visible:ring-primary`,`touch-manipulation cursor-pointer transition-colors`,`active:bg-interactive-hover`,t?`border-primary/50 bg-interactive-selection/20`:`border-border/40 hover:bg-interactive-hover/50`),onClick:()=>cn(e.name),children:(0,$.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[1.125rem_minmax(0,1fr)_auto] items-start gap-x-2`,children:[(0,$.jsx)(ds,{name:e.name,size:18}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block typography-ui-label font-semibold`,style:t?{color:`var(${n.var})`}:void 0,children:yn(ht(e))}),e.description&&(0,$.jsx)(`span`,{className:`mt-1 block min-w-0 whitespace-normal break-words typography-micro text-muted-foreground`,children:e.description})]}),t&&(0,$.jsx)(X,{name:`check`,className:`size-4 shrink-0 text-primary`})]})},e.name)})})}):null,Tn=()=>(0,$.jsx)(Js,{align:`start`,sideOffset:8,className:`max-w-[320px]`,children:zt?(0,$.jsxs)(`div`,{className:`flex min-w-[240px] flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-foreground`,children:zt.name||gn()}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:hn()})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.capabilities`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:Vt.length>0?Vt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:n},`cap-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a(`chat.modelControls.modeValue.none`)})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.modalities`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:a(`chat.modelControls.input`)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:Ht.length>0?Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} input`},`input-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:`-`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:a(`chat.modelControls.output`)}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:Ut.length>0?Ut.map(({key:e,icon:t,label:n})=>(0,$.jsx)(nb,{iconName:t,label:`${n} output`},`output-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:`-`})})]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.costPerMillion`)}),Kt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.limits`)}),qt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),zt.release_date?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.metadata`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:a(`chat.modelControls.release`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:sb(zt.release_date)})]})]}):null]}):(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.metadataUnavailable`)})}),En=()=>{let e=(e,t)=>{if(ct.current=!0,e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return!1;let{providerID:n,modelID:r}=t,i=nn(n,r);if(i.length===0)return!1;e.preventDefault(),e.stopPropagation();let a=Wy(n,r),o=dt.has(a),s=dt.get(a),c=o?s:x===n&&S===r?w:void 0,l=[void 0,...i],u=l.indexOf(c),d=l[((u>=0?u:0)+(e.key===`ArrowRight`?1:-1)+l.length)%l.length];return ft(e=>{let t=new Map(e);return t.set(a,d),t}),mt(e=>{let t=new Set(e);return t.add(a),t}),_t(e=>e+1),!0},t=(t,n)=>{let r=un(t);if(r){t.preventDefault(),ln(r);return}n&&e(t,n)},n=e=>{let t=Wy(e.providerID,e.modelID),n=dt.get(t),r=pt.has(t),i=an();if(r){pn(e.providerID,e.modelID,{applyVariant:!0,variant:n,agentName:i});return}let a=nn(e.providerID,e.modelID),o=e.variant!==void 0&&a.includes(e.variant)?e.variant:void 0;if(o!==void 0){pn(e.providerID,e.modelID,{applyVariant:!0,variant:o,agentName:i});return}pn(e.providerID,e.modelID,{agentName:i})},r=e=>{let t=un(e);t&&(e.preventDefault(),e.stopPropagation(),ct.current=!0,ln(t))},i=e=>e?.trim()?Za(e):a(`chat.modelControls.default`),o=(e,t)=>{let n=an();pn(e.providerID,e.modelID,{applyVariant:!0,variant:t,agentName:n,closeInstant:!0})},s=e=>{e&&(Ze||performance.now()<ot.current)||at(e)},c={searchPlaceholder:a(`chat.modelControls.searchModels`),noResults:a(`chat.modelControls.noModelsFound`),favorites:a(`chat.modelControls.favorites`),recent:a(`chat.modelControls.recent`),keyboardHint:a(`chat.modelControls.keyboardHintNavigate`),favorite:a(`chat.modelControls.favoriteAria`),unfavorite:a(`chat.modelControls.unfavoriteAria`),provider:a(`chat.modelControls.provider`),capabilities:a(`chat.modelControls.capabilities`),capabilityToolCalling:a(`chat.modelControls.capability.toolCalling`),capabilityReasoning:a(`chat.modelControls.capability.reasoning`),modalityImage:a(`chat.modelControls.modality.image`),modalityVideo:a(`chat.modelControls.modality.video`),modalityAudio:a(`chat.modelControls.modality.audio`),costPerMillion:a(`chat.modelControls.costPerMillion`),costInput:a(`chat.modelControls.costInput`),costOutput:a(`chat.modelControls.costOutput`)},u=(e,{isSelected:t})=>{let n=nn(e.providerID,e.modelID);if(n.length===0)return null;let r=Wy(e.providerID,e.modelID),o=dt.has(r),s=dt.get(r),c=e.variant!==void 0&&n.includes(e.variant)?e.variant:void 0,l=o?s:t?w:c,u=pt.has(r);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`group/thinking flex shrink-0 items-center gap-0.5 rounded-md px-1.5 py-0.5 typography-micro font-medium transition-colors`,u||l?`text-foreground/80`:`text-muted-foreground`,`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] hover:text-foreground`),onClick:t=>{t.preventDefault(),t.stopPropagation(),rt(e)},"aria-label":a(`chat.modelControls.showThinkingModes`),children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),(0,$.jsx)(`span`,{className:`max-w-20 truncate`,children:i(l)}),(0,$.jsx)(X,{name:`arrow-right-s`,className:`size-3 opacity-60 transition-transform group-hover/thinking:translate-x-px`})]})},d=()=>{if(!nt)return null;let e=nn(nt.providerID,nt.modelID),t=Wy(nt.providerID,nt.modelID),n=dt.has(t),r=dt.get(t),s=nt.providerID===x&&nt.modelID===S,c=nt.variant!==void 0&&e.includes(nt.variant)?nt.variant:void 0,l=n?r:s?w:c,u=ni(nt.model,nt.modelID,{maxLength:40});return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,onKeyDownCapture:e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),rt(null))},children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-border/40 px-1.5 py-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground`,onClick:()=>rt(null),"aria-label":a(`header.actions.backAria`),children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-3.5`})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,$.jsx)(Os,{modelId:nt.modelID,providerId:nt.providerID,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate typography-meta font-medium text-foreground`,children:u}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`shrink-0 text-border`,children:`·`}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),a(`chat.modelControls.thinking`)]})]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 p-1`,role:`listbox`,"aria-label":a(`chat.modelControls.thinking`),children:[void 0,...e].map(e=>{let t=e===l||!e&&!l;return(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:Y(`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left typography-meta transition-colors`,t?`bg-interactive-selection text-interactive-selection-foreground`:`text-foreground hover:bg-interactive-hover/50`),onClick:()=>o(nt,e),children:[(0,$.jsx)(`span`,{className:Y(`truncate font-medium`,!e&&!t&&`text-muted-foreground`),children:i(e)}),t?(0,$.jsx)(X,{name:`check`,className:`size-3.5 shrink-0 text-primary`}):(0,$.jsx)(`span`,{className:`size-3.5 shrink-0`,"aria-hidden":`true`})]},e??`__default`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border/40 px-2 py-1.5 typography-micro text-muted-foreground`,children:[(0,$.jsx)($v,{className:`h-4 min-w-4 rounded-[3px] px-1 text-[10px] font-medium tracking-tight shadow-none`,children:`Esc`}),(0,$.jsx)(`span`,{children:a(`header.actions.backAria`)}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-border`,children:`·`}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintThinking`)})]})]})},f=w&&Gt?Za(w):null;return(0,$.jsxs)(Ys,{open:!Ze&&it,onOpenChange:s,delayDuration:200,children:[Ie?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>He(`model`):void 0,onTouchStart:m?()=>bn(`model`):void 0,onTouchEnd:m?q:void 0,onTouchCancel:m?q:void 0,disabled:!m,className:Y(`model-controls__model-trigger min-w-0 focus:outline-none`,m?Y(`cursor-pointer`,fy):`opacity-60 cursor-not-allowed`),children:m?(0,$.jsxs)($.Fragment,{children:[x||S?(0,$.jsx)(Os,{modelId:S,providerId:x,className:Y(kt,`flex-shrink-0`)}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(kt,`text-muted-foreground`)}),(0,$.jsx)(`span`,{className:Y(`model-controls__model-label typography-micro font-medium overflow-hidden min-w-0`,Pe?`max-w-[120px]`:`max-w-[220px]`),children:(0,$.jsxs)(`span`,{className:`inline-flex max-w-full min-w-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:_n}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:`typography-micro font-medium text-muted-foreground min-w-0`,children:l})]})}):(0,$.jsxs)(Bc,{open:m&&Ze,onOpenChange:m?st:void 0,onOpenChangeComplete:e=>{e||yt(`model`)},children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,fy),children:[m?x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Os,{modelId:S,providerId:x,className:Y(kt,`flex-shrink-0`)}),(0,$.jsx)(X,{name:`pencil-ai`,className:Y(kt,`text-primary/60 hidden`)})]}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(kt,`text-muted-foreground`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:Y(`model-controls__model-label`,At,`font-medium whitespace-nowrap text-muted-foreground min-w-0`),children:l})]}),m&&(0,$.jsx)(`span`,{className:Y(`model-controls__model-label overflow-hidden`,At,`font-medium whitespace-nowrap text-foreground min-w-0`,`max-w-[260px]`),children:(0,$.jsxs)(`span`,{className:`inline-flex max-w-full min-w-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:_n}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})},`${x}-${S}-${w??``}`)]})})}),(0,$.jsx)(kc,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,Ce&&Gy),align:`end`,alignOffset:-40,onKeyDownCapture:r,finalFocus:bt,children:nt?d():(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`p-1 border-b border-border/40`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:$e,className:`typography-meta group flex w-full items-center gap-1 rounded-md px-2 py-1.5 cursor-pointer hover:bg-interactive-hover/50`,children:[(0,$.jsx)(`span`,{className:`flex size-4 items-center justify-center text-muted-foreground`,children:(0,$.jsx)(X,{name:`add`,className:`size-4 -mr-0.5`})}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:a(`chat.modelControls.addNewProvider`)})]})}),(0,$.jsx)(ks,{providers:v,favoriteModels:Ae,recentModels:je,getMetadata:I,searchQuery:et,onSearchQueryChange:tt,onSelect:n,labels:c,selectedModel:x&&S?{providerID:x,modelID:S}:null,hiddenModels:De,onActiveKeyDown:t,onActiveEntryChange:e=>{ut.current=e},onVariantKey:e,isFavorite:e=>he(e.providerID,e.modelID),onToggleFavorite:e=>de(e.providerID,e.modelID,e.providerID===x&&e.modelID===S?w:e.variant),renderRowEnd:u,renderVersion:gt,onReorderFavorite:(e,t)=>fe(e.providerID,e.modelID,t.providerID,t.modelID),reorderFavoriteAriaLabel:a(`chat.modelControls.reorderFavoriteAria`),reorderFavoriteTitle:a(`chat.modelControls.reorderFavoriteTitle`),providerOrder:pe,onReorderProvider:me,reorderProviderTitle:a(`chat.modelControls.reorderProviderTitle`),footerContent:e=>{let t=e?nn(e.providerID,e.modelID).length>0:!1;return(0,$.jsxs)(`div`,{className:`flex items-center gap-x-2 whitespace-nowrap overflow-hidden`,children:[(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintNavigate`)}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintSwitchAgent`,{shortcut:`Tab`})}),t?(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintThinking`)}):null]})},tooltipsEnabled:Ze&&!nt,onEscape:()=>{if(nt){rt(null);return}Qe(!1)}})]})})]}),Tn()]})},On=()=>{if(!Dt)return(0,$.jsx)(Js,{align:`start`,sideOffset:8,className:`max-w-[320px]`,children:(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.noAgentSelected`)})});let e=!!(Dt.prompt&&Dt.prompt.trim().length>0),t=Dt.model?.providerID&&Dt.model?.modelID,n=Dt.temperature!==void 0||Dt.topP!==void 0,r=e=>{let t=Ky(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=qy(t,e)??`ask`;return n?{mode:`ask`,label:a(`chat.modelControls.permissionLabel.custom`)}:r===`allow`?{mode:`allow`,label:a(`chat.modelControls.permissionLabel.allow`)}:r===`deny`?{mode:`deny`,label:a(`chat.modelControls.permissionLabel.deny`)}:{mode:`ask`,label:a(`chat.modelControls.permissionLabel.ask`)}},i=r(`edit`),o=r(`bash`),s=r(`webfetch`);return(0,$.jsx)(Js,{align:`start`,sideOffset:8,className:`max-w-[280px]`,children:(0,$.jsxs)(`div`,{className:`flex min-w-[200px] flex-col gap-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-foreground`,children:yn(Dt.name)}),Dt.description&&(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:Dt.description})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.mode`)}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:Dt.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Dt.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Dt.mode===`all`?a(`chat.modelControls.modeValue.all`):a(`chat.modelControls.modeValue.none`)})]}),(t||n)&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.model`)}),t?(0,$.jsxs)(`span`,{className:`typography-meta text-foreground`,children:[Dt.model.providerID,` / `,Dt.model.modelID]}):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a(`chat.modelControls.modeValue.none`)}),n&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 mt-0.5`,children:[Dt.temperature!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.temperature`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.temperature})]}),Dt.topP!==void 0&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.topP`)}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:Dt.topP})]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.permissions`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-16`,children:a(`chat.modelControls.edit`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:i.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground w-12`,children:i.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-16`,children:a(`chat.modelControls.bash`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:o.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground w-12`,children:o.label})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80 w-16`,children:a(`chat.modelControls.webFetch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(rb,{mode:s.mode,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground w-12`,children:s.label})]})]})]}),e&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/80`,children:a(`chat.modelControls.customPrompt`)}),(0,$.jsx)(X,{name:`checkbox-circle`,className:`size-4 text-foreground`})]})]})})},kn=()=>{let e=vn(),t=ue?os(ue):null;return Ie?(0,$.jsx)(`button`,{type:`button`,onClick:h?()=>He(`agent`):void 0,onTouchStart:h?()=>bn(`agent`):void 0,onTouchEnd:h?q:void 0,onTouchCancel:h?q:void 0,disabled:!h,className:Y(`model-controls__agent-trigger inline-flex items-center flex-shrink-0 min-w-0 focus:outline-none`,py,h?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:h?(0,$.jsx)(iy,{name:ue,label:e,revealed:Ft,avatarSize:Nt,slotClassName:Mt,labelGapClassName:Pt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,Mt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`flex-shrink-0 animate-spin text-muted-foreground`)})})}):(0,$.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,$.jsxs)(Ys,{delayDuration:600,children:[(0,$.jsxs)(Bc,{open:h&&xe,onOpenChange:h?Ue:void 0,onOpenChangeComplete:e=>{e||yt(`agent`)},children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,py),children:h?(0,$.jsx)(iy,{name:ue,label:e,revealed:Ft,avatarSize:Nt,slotClassName:Mt,labelGapClassName:Pt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,Mt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(kt,`flex-shrink-0 animate-spin text-muted-foreground`)})})})})}),(0,$.jsxs)(kc,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,we&&Gy),onKeyDownCapture:dn,finalFocus:bt,children:[(0,$.jsx)(`div`,{className:`p-1.5 pb-1`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-2.5 top-1/2 -translate-y-1/2 size-3.5 text-muted-foreground`}),(0,$.jsx)(Ks,{type:`text`,placeholder:a(`chat.modelControls.searchAgents`),value:St,onChange:e=>Ct(e.target.value),onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),Se(!1);return}e.stopPropagation()},className:`pl-8 h-8 typography-meta`})]})}),(0,$.jsx)(Xu,{outerClassName:`max-h-[min(400px,calc(100dvh-12rem))] flex-1`,children:(0,$.jsxs)(`div`,{className:`p-1`,children:[!St.trim()&&Et&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sc,{className:`typography-meta`,onSelect:()=>cn(Et),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{name:`arrow-go-back`,className:`size-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`font-medium`,children:a(`chat.modelControls.resetToDefault`)})]})}),(0,$.jsx)(Mc,{})]}),Tt.length===0?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-meta text-muted-foreground`,children:`No agents found`}):Tt.map(e=>(0,$.jsx)(Sc,{className:`typography-meta`,onSelect:()=>cn(e.name),children:(0,$.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col gap-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(ds,{name:e.name,size:14}),(0,$.jsx)(`span`,{className:`font-medium`,children:yn(ht(e))})]}),e.description&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground min-w-0 max-w-full ml-5 break-words`,children:e.description})]})},e.name))]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border/40 px-2 py-1.5 typography-micro text-muted-foreground`,children:[(0,$.jsx)($v,{className:`h-4 min-w-4 rounded-[3px] px-1 text-[10px] font-medium tracking-tight shadow-none`,children:`Tab`}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintSwitchAgentLabel`)})]})]})]}),On()]})})},An=Y(`@container/model-controls flex items-center min-w-0`,Pe&&`w-full`,e),jn=kn();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:An,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center min-w-0 flex-1 justify-end`,jt,Pe&&`overflow-hidden`),children:[jn,En()]})}),Cn(),wn(),xn(),Sn()]})},lb=[{key:`M`,labelKey:`chat.leaderKey.action.model`},{key:`A`,labelKey:`chat.leaderKey.action.agent`},{key:`N`,labelKey:`chat.leaderKey.action.newSession`},{key:`C`,labelKey:`chat.leaderKey.action.compact`}],ub=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=Xn(),i=$m(db),a=K(fb),o;t[0]===a?o=t[1]:(o=Nc(Ec(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let s=o;if(!i)return null;let c;t[2]===r?c=t[3]:(c=r(`chat.leaderKey.pendingAria`),t[2]=r,t[3]=c);let l;t[4]===n?l=t[5]:(l=Y(`pointer-events-none absolute left-1/2 top-0 z-20 -translate-x-1/2 -translate-y-[calc(100%+0.4rem)]`,`inline-flex max-w-[calc(100cqw-1rem)] items-center gap-2 overflow-x-auto rounded-lg border px-2.5 py-1.5`,`border-[var(--interactive-border)] bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)]`,`shadow-sm animate-in fade-in-0 zoom-in-95 duration-150 whitespace-nowrap`,n),t[4]=n,t[5]=l);let u;t[6]===s?u=t[7]:(u=(0,$.jsx)(ey,{shortcut:s,className:`opacity-[0.35] [&_[data-slot=kbd]]:rounded-md [&_[data-slot=kbd]]:border-0 [&_[data-slot=kbd]]:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] [&_[data-slot=kbd]]:text-muted-foreground/65 [&_[data-slot=kbd]]:shadow-none`}),t[6]=s,t[7]=u);let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}),t[8]=d):d=t[8];let f;t[9]===r?f=t[10]:(f=lb.map((e,t)=>(0,$.jsxs)(Z.Fragment,{children:[t>0?(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}):null,(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 typography-micro`,children:[(0,$.jsx)($v,{className:`rounded-md border-0 bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] text-muted-foreground/65 shadow-none`,children:e.key}),(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(e.labelKey)})]})]},e.key)),t[9]=r,t[10]=f);let p;return t[11]!==c||t[12]!==l||t[13]!==u||t[14]!==f?(p=(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":c,className:l,children:[u,d,f]}),t[11]=c,t[12]=l,t[13]=u,t[14]=f,t[15]=p):p=t[15],p};function db(e){return e.pending}function fb(e){return e.shortcutOverrides}var pb=28,mb=8,hb=10.5,gb=Math.PI/2,_b=e=>Array.from({length:mb},(t,n)=>{let r=n/mb*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*hb,Math.sin(r)*hb]}),vb=[_b(0),_b(gb),_b(Math.PI),_b(Math.PI*1.5)],yb=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,bb=e=>{let t=(0,Q.c)(9),{size:n,isMobile:r,className:i}=e,a=n??(r!==void 0&&r?12:14),o;t[0]===i?o=t[1]:(o=Y(`yuri-morph-orb-glyph shrink-0`,i),t[0]=i,t[1]=o);let s=a/pb,c;t[2]!==a||t[3]!==s?(c={width:a,height:a,"--orb-k":s},t[2]=a,t[3]=s,t[4]=c):c=t[4];let l=c,u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(`span`,{className:`yuri-morph-orb-stage`,children:vb[0].map(xb)}),t[5]=u):u=t[5];let d;return t[6]!==o||t[7]!==l?(d=(0,$.jsx)(`span`,{className:o,style:l,"aria-hidden":`true`,children:u}),t[6]=o,t[7]=l,t[8]=d):d=t[8],d};function xb(e,t){return(0,$.jsx)(`span`,{className:`yuri-morph-orb-dot`,style:{"--m-1":yb(vb[0][t]),"--m-2":yb(vb[1][t]),"--m-3":yb(vb[2][t]),"--m-4":yb(vb[3][t])}},t)}var Sb=1200,Cb=600;function wb({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o,isTurnSettled:s=!1}){let{locale:c,t:l}=Xn(),[u,d]=Z.useState(null),[f,p]=Z.useState(!1),m=Z.useRef(u),h=Z.useRef(f),g=Z.useRef(!1);m.current=u,h.current=f;let _=Z.useRef(0),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(null),[x,S]=Z.useState(null),[C,w]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;w(Date.now());let t=window.setInterval(()=>w(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){S(null);return}let t=e,n=()=>{let e=Math.max(0,t-Date.now());S(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let T=J(()=>{y.current&&=(clearTimeout(y.current),null),b.current&&=(clearTimeout(b.current),null)}),E=J((e,t,n=!1)=>{T(),v.current=null,d(e),p(t),g.current=n,_.current=Date.now()}),D=J(()=>{if(y.current)return;let e=Date.now()-_.current,t=Math.max(0,Sb-e);y.current=setTimeout(()=>{y.current=null;let e=v.current;e&&E(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(s){T(),v.current=null,m.current&&(d(null),p(!1),g.current=!1);return}if(!e){if(y.current&&=(clearTimeout(y.current),null),v.current=null,!m.current||b.current)return;b.current=setTimeout(()=>{b.current=null,d(null),p(!1),g.current=!1},Cb);return}if(b.current&&=(clearTimeout(b.current),null),a){T(),v.current=null;return}let t=i?l(`chat.assistantStatus.waitingForPermission`):n,o=!!i,c=!!r&&!o;if(t){if(!m.current){E(t,o,c);return}if((t!==m.current||o!==h.current)&&!(c&&g.current)){if(c){v.current={text:t,permission:o,generic:c},D();return}E(t,o,c)}}},[e,s,n,r,i,a,l]),Z.useEffect(()=>()=>T(),[]),s||!e&&!u)return null;if(a&&e){let e=x!==null&&x>0?new Intl.RelativeTimeFormat(c,{numeric:`always`,style:`short`}).format(x,`second`):null,n=e?a.attempt&&a.attempt>0?l(`chat.assistantStatus.retryingInAttempt`,{duration:e,attempt:a.attempt}):l(`chat.assistantStatus.retryingIn`,{duration:e}):a.attempt&&a.attempt>0?l(`chat.assistantStatus.retryingAttempt`,{attempt:a.attempt}):l(`chat.assistantStatus.retrying`),r=a.message?`${n} · ${a.message}`:n;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":r,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center ${t?`gap-1 typography-meta !text-[length:var(--text-meta)]`:`gap-1.5 typography-ui-header`}`,children:[(0,$.jsx)(`span`,{className:`inline-flex flex-none items-center justify-center ${t?`h-5 w-4`:`h-6 w-3.5`}`,children:(0,$.jsx)(bb,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 whitespace-normal break-words`,children:r})]})})}if(!u)return null;let O=u,k=typeof o==`number`&&e?lr(Math.max(0,C-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":f?`assertive`:`polite`,"aria-label":O,"data-waiting":f?`true`:void 0,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center ${t?`gap-1 typography-meta !text-[length:var(--text-meta)]`:`gap-1.5 typography-ui-header`}`,children:[(0,$.jsx)(`span`,{className:`inline-flex flex-none items-center justify-center ${t?`h-5 w-4`:`h-6 w-3.5`}`,children:(0,$.jsx)(bb,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:O}),k?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:k}):null]})})}var Tb={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Eb={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Db={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:Tb},Ob=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?Tb:Eb}),kb=Z.createContext(Db),Ab=()=>Z.useContext(kb),jb=e=>({fork:e.capabilities.forkSession,revert:e.capabilities.mutateSession,edit:e.capabilities.mutateSession,reviewTransfer:e.capabilities.mutateSession,timeline:e.capabilities.openTimeline,textSelectionMutation:e.capabilities.textSelectionActions,openSourceSession:!!e.openSourceSession}),Mb=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,Nb={containerType:`inline-size`,containerName:`status-row`},Pb=[],Fb=e=>{let t=(0,Q.c)(102),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:s,retryInfo:c,turnStartedAt:l,isTurnSettled:u,showAbortStatus:d,showAbortPrompt:f,showAssistantStatus:m,showTodos:h,agentName:g,leftAccessory:_,className:v}=e,y=n!==void 0&&n,b=r===void 0?null:r,x=u!==void 0&&u,S=f!==void 0&&f,C=m===void 0||m,w=h===void 0||h,{t:T}=Xn(),[E,D]=Z.useState(!1),O=Ab(),k=wa(Ib),A=O.sessionId??k,j;t[0]!==A||t[1]!==w?(j=e=>!w||!A?Pb:e.todo[A]??Pb,t[0]=A,t[1]=w,t[2]=j):j=t[2];let M=Rr(j,O.directory??void 0),N;t[3]!==A||t[4]!==w?(N=e=>w&&A?e.sessions[A]?.todos:void 0,t[3]=A,t[4]=w,t[5]=N):N=t[5];let P=Qo(N),F;bb0:{if(!A){F=Pb;break bb0}if(M.length>0){F=M;break bb0}F=P??Pb}let I=F,L=K(Lb),R;t[6]===L?R=t[7]:(R=L||p(),t[6]=L,t[7]=R);let z=R,B;t[8]===I?B=t[9]:(B=I.filter(Rb),t[8]=I,t[9]=B);let V=B,H;t[10]===V?H=t[11]:(H=V.find(zb)||V.find(Bb)||null,t[10]=V,t[11]=H);let U=H,W;t[12]===V?W=t[13]:(W=V.find(Vb)??null,t[12]=V,t[13]=W);let ee=W,te;t[14]===I?te=t[15]:(te=I.filter(Hb),t[14]=I,t[15]=te);let ne=te.length,re;t[16]===I?re=t[17]:(re=I.filter(Ub),t[16]=I,t[17]=re);let G=re.length,ie;t[18]!==G||t[19]!==ne?(ie={completed:G,total:ne},t[18]=G,t[19]=ne,t[20]=ie):ie=t[20];let ae=ie,oe;t[21]===V?oe=t[22]:(oe=V.filter(Wb),t[21]=V,t[22]=oe);let se=oe.length,ce;t[23]===V?ce=t[24]:(ce=V.filter(Gb),t[23]=V,t[24]=ce);let le=ce.length,ue;t[25]!==se||t[26]!==le?(ue={active:se,left:le},t[25]=se,t[26]=le,t[27]=ue):ue=t[27];let de=ue,fe=w&&de.left>0,pe=!!S,[me,he]=Z.useState(!1),ge,_e;t[28]!==me||t[29]!==x||t[30]!==y?(ge=()=>{if(x){he(!1);return}if(y){he(!0);return}if(!me)return;let e=window.setTimeout(()=>he(!1),600);return()=>window.clearTimeout(e)},_e=[y,me,x],t[28]=me,t[29]=x,t[30]=y,t[31]=ge,t[32]=_e):(ge=t[31],_e=t[32]),Z.useEffect(ge,_e);let ve=C&&(!x&&(y||me)||!!o||!!d),ye=!!_,be=!d&&!pe&&(o||!s),xe=pe||ve||fe||ye,Se=Z.useRef(null),Ce=Z.useRef(null),we=Z.useRef(null),Te,Ee;t[33]===E?(Te=t[34],Ee=t[35]):(Te=()=>{let e=Ce.current,t=we.current;if(!E||!e||!t)return;let n=t.offsetTop-e.offsetTop-(e.clientHeight-t.offsetHeight)/2,r=e.scrollHeight-e.clientHeight;e.scrollTop=Math.min(r,Math.max(0,n))},Ee=[E],t[33]=E,t[34]=Te,t[35]=Ee),Z.useLayoutEffect(Te,Ee);let De,Oe;t[36]===E?(De=t[37],Oe=t[38]):(De=()=>{if(!E)return;let e=e=>{Se.current&&!Se.current.contains(e.target)&&D(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},Oe=[E],t[36]=E,t[37]=De,t[38]=Oe),Z.useEffect(De,Oe);let ke;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(ke=()=>D(Kb),t[39]=ke):ke=t[39];let Ae=J(ke),je;t[40]!==de.active||t[41]!==de.left||t[42]!==T?(je=T(`chat.statusRow.summary.activeLeft`,{active:de.active,left:de.left}),t[40]=de.active,t[41]=de.left,t[42]=T,t[43]=je):je=t[43];let Me=je,Ne;t[44]!==U||t[45]!==fe||t[46]!==z||t[47]!==E||t[48]!==ae||t[49]!==T||t[50]!==Me||t[51]!==Ae?(Ne=fe?(0,$.jsxs)(`button`,{type:`button`,onClick:Ae,className:Y(Rd,`shrink-0`),"aria-label":Me,title:Me,children:[(0,$.jsx)(X,{name:`list-check-3`,className:Fd}),!z&&U?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,Pd),children:U.content}):(0,$.jsx)(`span`,{className:`text-xs leading-4 md:text-[0.8125rem] md:leading-5`,children:T(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:Id,"aria-hidden":`true`,children:[ae.completed,`/`,ae.total]}),E?(0,$.jsx)(X,{name:`arrow-up-s`,className:Fd}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Fd})]}):null,t[44]=U,t[45]=fe,t[46]=z,t[47]=E,t[48]=ae,t[49]=T,t[50]=Me,t[51]=Ae,t[52]=Ne):Ne=t[52];let Pe=Ne;if(!xe)return null;let Fe=!ye&&`chat-column -mt-1`,Ie;t[53]!==v||t[54]!==ye||t[55]!==L||t[56]!==Fe?(Ie=Y(`mb-1`,Fe,!ye&&sy(L),v),t[53]=v,t[54]=ye,t[55]=L,t[56]=Fe,t[57]=Ie):Ie=t[57];let Le=ye&&`px-3`,Re;t[58]===Le?Re=t[59]:(Re=Y(`flex items-center justify-between py-0.5 gap-2`,Le),t[58]=Le,t[59]=Re);let ze=!ye&&`overflow-x-hidden`,Be;t[60]===ze?Be=t[61]:(Be=Y(`flex-1 flex items-center min-w-0 gap-2`,ze),t[60]=ze,t[61]=Be);let Ve;t[62]!==g||t[63]!==A||t[64]!==pe||t[65]!==i||t[66]!==L||t[67]!==x||t[68]!==a||t[69]!==y||t[70]!==_||t[71]!==c||t[72]!==be||t[73]!==d||t[74]!==C||t[75]!==b||t[76]!==T||t[77]!==l?(Ve=pe?(0,$.jsx)(`div`,{className:`flex min-w-0 items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":T(`chat.statusRow.abortPrompt`),children:(0,$.jsxs)(`span`,{className:Y(`flex min-w-0 items-center typography-ui-label`,L?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,L?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5`,"aria-hidden":`true`})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer truncate whitespace-nowrap`,children:T(`chat.statusRow.abortPrompt`)})]})}):C&&d?(0,$.jsx)(`div`,{className:`flex h-full items-center text-[var(--status-error)]`,children:(0,$.jsxs)(`span`,{className:Y(`flex items-center typography-ui-label`,L?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,L?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`close-circle`,className:`size-3.5`,"aria-hidden":`true`})}),T(`chat.statusRow.aborted`)]})}):C&&be?(0,$.jsx)(wb,{isWorking:y,isMobile:L,statusText:b,isGenericStatus:i,isWaitingForPermission:a,retryInfo:c,turnStartedAt:l,isTurnSettled:x,agentName:g},A??`no-session`):_||null,t[62]=g,t[63]=A,t[64]=pe,t[65]=i,t[66]=L,t[67]=x,t[68]=a,t[69]=y,t[70]=_,t[71]=c,t[72]=be,t[73]=d,t[74]=C,t[75]=b,t[76]=T,t[77]=l,t[78]=Ve):Ve=t[78];let He;t[79]!==Be||t[80]!==Ve?(He=(0,$.jsx)(`div`,{className:Be,children:Ve}),t[79]=Be,t[80]=Ve,t[81]=He):He=t[81];let Ue=!ye&&`-mr-3`,We;t[82]===Ue?We=t[83]:(We=Y(`relative flex items-center gap-2 flex-shrink-0`,Ue),t[82]=Ue,t[83]=We);let Ge;t[84]!==ee||t[85]!==fe||t[86]!==E||t[87]!==ae||t[88]!==T||t[89]!==V?(Ge=E&&fe&&(0,$.jsxs)(`div`,{style:$d,className:Y(Qd,`absolute right-0 bottom-full mb-1 z-50`,`animate-in fade-in-0 zoom-in-95 slide-in-from-bottom-2`,`duration-150`),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] px-3 py-2.5`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,children:T(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,children:[ae.completed,`/`,ae.total]})]}),(0,$.jsx)(`ul`,{ref:Ce,className:Ld,children:V.map((e,t)=>(0,$.jsx)(zd,{todo:e,isActive:e===ee,activeRef:e===ee?we:void 0},e.id??`todo-${t}`))})]}),t[84]=ee,t[85]=fe,t[86]=E,t[87]=ae,t[88]=T,t[89]=V,t[90]=Ge):Ge=t[90];let Ke;t[91]!==We||t[92]!==Ge||t[93]!==Pe?(Ke=(0,$.jsxs)(`div`,{className:We,ref:Se,children:[Pe,Ge]}),t[91]=We,t[92]=Ge,t[93]=Pe,t[94]=Ke):Ke=t[94];let qe;t[95]!==Re||t[96]!==He||t[97]!==Ke?(qe=(0,$.jsxs)(`div`,{className:Re,children:[He,Ke]}),t[95]=Re,t[96]=He,t[97]=Ke,t[98]=qe):qe=t[98];let Je;return t[99]!==Ie||t[100]!==qe?(Je=(0,$.jsx)(`div`,{className:Ie,style:Nb,children:qe}),t[99]=Ie,t[100]=qe,t[101]=Je):Je=t[101],Je};function Ib(e){return e.currentSessionId}function Lb(e){return e.isMobile}function Rb(e){return e.status!==`cancelled`}function zb(e){return e.status===`in_progress`}function Bb(e){return e.status===`pending`}function Vb(e){return e.status===`in_progress`}function Hb(e){return e.status!==`cancelled`}function Ub(e){return e.status===`completed`}function Wb(e){return e.status===`in_progress`}function Gb(e){return e.status===`in_progress`||e.status===`pending`}function Kb(e){return!e}var qb=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),Jb=e=>`insertions`in e,Yb=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},Xb=e=>{let t=0,n=0;for(let r of e.split(`
|
|
6532
|
+
`))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},Zb=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!qb.has(r.tool))continue;let e=r.state;if(e.status&&e.status!==`completed`)continue;let i=t.length,a=e.metadata,o=Array.isArray(a?.files)?a.files:[];for(let e of o){if(!e||typeof e!=`object`)continue;let i=e,a=i.relativePath||i.filePath||``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:Yb(i.additions)??void 0,deletions:Yb(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(o.length===0&&a?.filediff&&typeof a.filediff==`object`){let e=a.filediff,i=typeof e.file==`string`?e.file:``;i&&!n.has(i)&&(n.add(i),t.push({path:i,tool:r.tool,partId:r.id,messageID:r.messageID,additions:Yb(e.additions)??void 0,deletions:Yb(e.deletions)??void 0,patch:typeof e.patch==`string`?e.patch:void 0}))}if(o.length===0&&Array.isArray(a?.results))for(let e of a.results){if(!e||typeof e!=`object`)continue;let i=e.filediff;if(!i||typeof i!=`object`)continue;let a=typeof i.file==`string`?i.file:``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:Yb(i.additions)??void 0,deletions:Yb(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(t.length===i){let i=e.input,a=typeof i?.filePath==`string`?i.filePath:typeof i?.file_path==`string`?i.file_path:typeof i?.path==`string`?i.path:void 0;a&&!n.has(a)&&(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID}))}if(t.length===i){let e=typeof a?.patch==`string`?a.patch.trim():typeof a?.diff==`string`?a.diff.trim():``;if(e&&!n.has(`Diff`)){n.add(`Diff`);let i=Xb(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},Qb=(e,t,n)=>{let r=[];for(let i of e){let e=i.index?.trim()??``,a=i.working_dir?.trim()??``,o=!!(e&&e!==`?`),s=!!(a||e===`?`),c=a||e;if(!c||c===`!`)continue;let l=t?.[i.path];r.push({path:Mn(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},$b=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},ex=(e,t)=>jn(e,t),tx=(e,t)=>{let n=Jb(e)&&e.relativePath?e.relativePath:ex(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},nx=e=>Jb(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},rx=2;function ix(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t)}}function ax(e,t=rx){let n=e??``,r=n.startsWith(`/`),i=n.split(`/`).filter(Boolean);if(i.length===0)return{prefix:``,parent:``,stem:``,ext:``,name:``,leadingSlash:r};let a=i[i.length-1]??``,{stem:o,ext:s}=ix(a),c=Math.max(1,Math.floor(t)),l=Math.min(i.length-1,c-1),u=i.length-1-l,d=l>0?i.slice(u,-1).join(`/`):``,f=i.slice(0,u).join(`/`),p=f?r?`/${f}`:f:``;return{prefix:p,parent:d,stem:o,ext:s,name:a,leadingSlash:r&&!p}}function ox(e){let t=(0,Q.c)(36),{path:n,className:r,title:i,dirClassName:a,nameClassName:o}=e,s=a===void 0?`text-muted-foreground`:a,c=o===void 0?`text-foreground`:o,l;t[0]===n?l=t[1]:(l=ax(n),t[0]=n,t[1]=l);let{prefix:u,parent:d,stem:f,ext:p,leadingSlash:m}=l,h=!!(u||d),g;t[2]===r?g=t[3]:(g=Y(`flex min-w-0 items-baseline overflow-hidden`,r),t[2]=r,t[3]=g);let _=i??n,v;t[4]!==s||t[5]!==m?(v=m?(0,$.jsx)(`span`,{className:Y(`shrink-0`,s),children:`/`}):null,t[4]=s,t[5]=m,t[6]=v):v=t[6];let y;t[7]!==s||t[8]!==u?(y=u?(0,$.jsx)(`span`,{className:Y(`min-w-0 shrink-[9999] truncate`,s),children:u}):null,t[7]=s,t[8]=u,t[9]=y):y=t[9];let b;t[10]!==s||t[11]!==d||t[12]!==u?(b=d?(0,$.jsxs)(`span`,{className:Y(`shrink-0`,s),children:[u?`/`:``,d]}):null,t[10]=s,t[11]=d,t[12]=u,t[13]=b):b=t[13];let x;t[14]!==s||t[15]!==h?(x=h?(0,$.jsx)(`span`,{className:s,children:`/`}):null,t[14]=s,t[15]=h,t[16]=x):x=t[16];let S;t[17]===c?S=t[18]:(S=Y(`min-w-0 truncate`,c),t[17]=c,t[18]=S);let C;t[19]!==f||t[20]!==S?(C=(0,$.jsx)(`span`,{className:S,children:f}),t[19]=f,t[20]=S,t[21]=C):C=t[21];let w;t[22]!==p||t[23]!==c?(w=p?(0,$.jsx)(`span`,{className:Y(`shrink-0`,c),children:p}):null,t[22]=p,t[23]=c,t[24]=w):w=t[24];let T;t[25]!==C||t[26]!==w||t[27]!==x?(T=(0,$.jsxs)(`span`,{className:`flex min-w-0 shrink items-baseline`,children:[x,C,w]}),t[25]=C,t[26]=w,t[27]=x,t[28]=T):T=t[28];let E;return t[29]!==T||t[30]!==g||t[31]!==_||t[32]!==v||t[33]!==y||t[34]!==b?(E=(0,$.jsxs)(`span`,{className:g,title:_,children:[v,y,b,T]}),t[29]=T,t[30]=g,t[31]=_,t[32]=v,t[33]=y,t[34]=b,t[35]=E):E=t[35],E}var sx=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=Xn(),o;t[0]===a?o=t[1]:(o=a(`chat.changedFiles.title`),t[0]=a,t[1]=o);let s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`span`,{className:ef,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Vd,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:tf,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;if(t[9]!==r||t[10]!==n||t[11]!==i||t[12]!==a){let e;t[14]!==r||t[15]!==i||t[16]!==a?(e=(e,t)=>{let{fileName:n,dirPart:o}=tx(e,r),s=nx(e);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`relative flex w-full cursor-pointer items-center gap-2.5 outline-hidden select-none text-left hover:bg-interactive-hover`,Nd),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(ig,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(ox,{path:o?`${o}/${n}`:n,title:e.path,className:`min-w-0 flex-1`}),s.additions>0||s.deletions>0?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-baseline gap-1 text-xs tabular-nums leading-4 md:text-[0.8125rem] md:leading-5`,children:[s.additions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,s.additions]}):null,s.deletions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,s.deletions]}):null]}):null]},`${e.path}:${t}`)},t[14]=r,t[15]=i,t[16]=a,t[17]=e):e=t[17],u=n.map(e),t[9]=r,t[10]=n,t[11]=i,t[12]=a,t[13]=u}else u=t[13];let d;t[18]===u?d=t[19]:(d=(0,$.jsx)(`div`,{className:Ld,children:u}),t[18]=u,t[19]=d);let f;return t[20]!==l||t[21]!==d?(f=(0,$.jsxs)($.Fragment,{children:[l,d]}),t[20]=l,t[21]=d,t[22]=f):f=t[22],f},cx=`${Qd} origin-[var(--transform-origin)]`,lx=$d,ux=Z.memo(()=>{let e=(0,Q.c)(65),{t}=Xn(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=bd()??null,o=Z.useContext(En),s=$l(a),c;e[0]===a?c=e[1]:(c=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=c);let l=gu(c),u=gu(dx),d=Ll(),f,p;e[2]===n?(f=e[3],p=e[4]):(f=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},p=[n],e[2]=n,e[3]=f,e[4]=p),Z.useEffect(f,p);let m;bb0:{if(!a||s!==!0||!l||l.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],m=t;break bb0}let t;e[6]!==a||e[7]!==l.diffStats||e[8]!==l.files?(t=Qb(l.files,l.diffStats,a),e[6]=a,e[7]=l.diffStats,e[8]=l.files,e[9]=t):t=e[9],m=t}let h=m,g=0,_=0;if(e[10]!==g||e[11]!==h||e[12]!==_){for(let e of h)g+=e.insertions,_+=e.deletions;e[10]=g,e[11]=h,e[12]=_,e[13]=g,e[14]=_}else g=e[13],_=e[14];let v;e[15]!==g||e[16]!==_?(v={totalAdded:g,totalRemoved:_},e[15]=g,e[16]=_,e[17]=v):v=e[17];let{totalAdded:y,totalRemoved:b}=v;if(!a||s!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!Jb(e))return;r(!1);let t=e.path;if(d){d.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=K.getState(),s=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,s);return}i.navigateToDiff(e.relativePath,s),i.setRightSidebarOpen(!1)},e[18]=a,e[19]=d,e[20]=o?.editor,e[21]=x):x=e[21];let S=x,C=h.length,w;e[22]!==C||e[23]!==t?(w=t(C===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:C}),e[22]=C,e[23]=t,e[24]=w):w=e[24];let T=w,E;e[25]!==a||e[26]!==u||e[27]!==n||e[28]!==o?(E=()=>{let e=!n;r(e),!(!e||!a||!o?.git)&&u(a,o.git,{silent:!0})},e[25]=a,e[26]=u,e[27]=n,e[28]=o,e[29]=E):E=e[29];let D=E,O;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(O=Y(Rd,`yuri-pending-changes-trigger max-w-full text-left`),e[30]=O):O=e[30];let k,A;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(X,{name:`file-edit`,className:Fd}),k=Y(Pd,`shrink-0`),e[31]=k,e[32]=A):(k=e[31],A=e[32]);let j;e[33]===T?j=e[34]:(j=(0,$.jsx)(`span`,{className:k,children:T}),e[33]=T,e[34]=j);let M;e[35]===Symbol.for(`react.memo_cache_sentinel`)?(M=Y(`status-row__changed-label`,Pd),e[35]=M):M=e[35];let N;e[36]===t?N=e[37]:(N=t(`chat.pendingChanges.changedInWorkspace`),e[36]=t,e[37]=N);let P;e[38]===N?P=e[39]:(P=(0,$.jsx)(`span`,{className:M,children:N}),e[38]=N,e[39]=P);let F;e[40]===Symbol.for(`react.memo_cache_sentinel`)?(F=Y(Id,`items-baseline gap-0.5`),e[40]=F):F=e[40];let I;e[41]===y?I=e[42]:(I=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,y]}):null,e[41]=y,e[42]=I);let L;e[43]===b?L=e[44]:(L=b>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,b]}):null,e[43]=b,e[44]=L);let R;e[45]!==I||e[46]!==L?(R=(0,$.jsxs)(`span`,{className:F,children:[I,L]}),e[45]=I,e[46]=L,e[47]=R):R=e[47];let z;e[48]===n?z=e[49]:(z=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:Fd}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Fd}),e[48]=n,e[49]=z);let B;e[50]!==D||e[51]!==n||e[52]!==j||e[53]!==P||e[54]!==R||e[55]!==z?(B=(0,$.jsxs)(`button`,{type:`button`,className:O,onClick:D,"aria-expanded":n,children:[A,j,P,R,z]}),e[50]=D,e[51]=n,e[52]=j,e[53]=P,e[54]=R,e[55]=z,e[56]=B):B=e[56];let V;e[57]!==a||e[58]!==h||e[59]!==S||e[60]!==n?(V=n&&(0,$.jsx)(`div`,{style:lx,className:Y(cx,`absolute left-0 bottom-full mb-1 z-50`,`animate-in fade-in-0 zoom-in-95 slide-in-from-bottom-2`,`duration-150`),children:(0,$.jsx)(sx,{files:h,currentDirectory:a,onOpenFile:S})}),e[57]=a,e[58]=h,e[59]=S,e[60]=n,e[61]=V):V=e[61];let H;return e[62]!==B||e[63]!==V?(H=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[B,V]}),e[62]=B,e[63]=V,e[64]=H):H=e[64],H});ux.displayName=`PendingChangesBar`;function dx(e){return e.fetchStatus}var fx=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=Xn(),s=a===`compact`;if(s&&!n)return null;let c=a==="default"&&`absolute left-1/2 bottom-full mb-2 -translate-x-1/2`,l=a===`expanded`&&`absolute left-1/2 -translate-x-1/2 yuri-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`yuri-scroll-to-bottom--compact relative shrink-0`,d;t[0]!==a||t[1]!==c||t[2]!==l||t[3]!==u||t[4]!==n?(d=Y(c,l,u,n?Y(`pointer-events-auto`,a==="default"&&`opacity-100`):Y(`opacity-0 pointer-events-none`,a===`expanded`&&`yuri-scroll-to-bottom--hidden`)),t[0]=a,t[1]=c,t[2]=l,t[3]=u,t[4]=n,t[5]=d):d=t[5];let f=s?`ghost`:`outline`,p=s?`composer-mobile-actions h-8 w-8 rounded-none bg-transparent hover:bg-transparent text-foreground`:`size-8 rounded-full [corner-shape:round] bg-background/95 hover:bg-interactive-hover`,m;t[6]===p?m=t[7]:(m=Y(`p-0 shadow-none`,p),t[6]=p,t[7]=m);let h;t[8]===o?h=t[9]:(h=o(`chat.scrollToBottom.aria`),t[8]=o,t[9]=h);let g=s?`size-5`:`size-4`,_=s?`medium`:`regular`,v;t[10]!==g||t[11]!==_?(v=(0,$.jsx)(X,{name:`arrow-down`,className:g,weight:_}),t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==r||t[14]!==v||t[15]!==f||t[16]!==m||t[17]!==h?(y=(0,$.jsx)(er,{variant:f,size:`sm`,onClick:r,className:m,"aria-label":h,children:v}),t[13]=r,t[14]=v,t[15]=f,t[16]=m,t[17]=h,t[18]=y):y=t[18];let b;return t[19]!==y||t[20]!==d?(b=(0,$.jsx)(`div`,{className:d,children:y}),t[19]=y,t[20]=d,t[21]=b):b=t[21],b}),px=Z.createContext(`default`),mx=()=>Z.useContext(px),hx=500,gx=e=>{let t=(0,Q.c)(31),{onCycleAgent:n,onOpenAgentPanel:r,className:i,agentName:a,agents:o,disabled:s}=e,c;t[0]===o?c=t[1]:(c=o===void 0?[]:o,t[0]=o,t[1]=c);let l=c,u=s!==void 0&&s,d=a??void 0,f;t[2]!==l||t[3]!==d?(f=ai(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=ay(d),h;t[5]===d?h=t[6]:(h=os(d),t[5]=d,t[6]=h);let g=h,_=Z.useRef(null),v=Z.useRef(!1),y;t[7]!==u||t[8]!==r?(y=e=>{e.preventDefault(),!u&&(v.current=!1,_.current=setTimeout(()=>{v.current=!0,r()},hx))},t[7]=u,t[8]=r,t[9]=y):y=t[9];let b=y,x;t[10]!==u||t[11]!==n?(x=()=>{_.current&&=(clearTimeout(_.current),null),!u&&!v.current&&n()},t[10]=u,t[11]=n,t[12]=x):x=t[12];let S=x,C;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{_.current&&=(clearTimeout(_.current),null)},t[13]=C):C=t[13];let w=C,T,E;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(E=()=>()=>{_.current&&clearTimeout(_.current)},T=[],t[14]=T,t[15]=E):(T=t[14],E=t[15]),Z.useEffect(E,T);let D;t[16]===i?D=t[17]:(D=Y(`inline-flex flex-shrink-0 items-center select-none focus:outline-none touch-none disabled:cursor-not-allowed disabled:opacity-40`,py,i),t[16]=i,t[17]=D);let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[18]=O):O=t[18];let k;t[19]!==g.var||t[20]!==p||t[21]!==d||t[22]!==m?(k=(0,$.jsx)(iy,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,labelGapClassName:`pl-1 pr-0.5`,colorVar:g.var}),t[19]=g.var,t[20]=p,t[21]=d,t[22]=m,t[23]=k):k=t[23];let A;return t[24]!==p||t[25]!==u||t[26]!==b||t[27]!==S||t[28]!==D||t[29]!==k?(A=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:_x,onMouseDown:vx,className:D,style:O,title:p,"aria-label":p,children:k}),t[24]=p,t[25]=u,t[26]=b,t[27]=S,t[28]=D,t[29]=k,t[30]=A):A=t[30],A};function _x(e){return e.preventDefault()}function vx(e){return e.preventDefault()}var yx=e=>{let t=(0,Q.c)(28),{onOpenModel:n,className:r,providerID:i,modelID:a,provider:o,variant:s,disabled:c}=e,l=c!==void 0&&c,{t:u}=Xn(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=vi(o,a,u(`chat.modelControls.selectModel`)),t[0]=a,t[1]=o,t[2]=u,t[3]=d):d=t[3];let f=d,p;t[4]===s?p=t[5]:(p=s?.trim()?Za(s):null,t[4]=s,t[5]=p);let m=p,h=m?`${f} ${m}`:f,g;t[6]===r?g=t[7]:(g=Y(`inline-flex min-w-0 max-w-36 items-stretch`,`rounded-lg`,`focus:outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,r),t[6]=r,t[7]=g);let _;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(_={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[8]=_):_=t[8];let v;t[9]!==a||t[10]!==i?(v=a||i?(0,$.jsx)(Os,{modelId:a,providerId:i,className:`size-4 flex-shrink-0`}):null,t[9]=a,t[10]=i,t[11]=v):v=t[11];let y;t[12]===f?y=t[13]:(y=(0,$.jsx)(`span`,{className:`truncate text-[11px] leading-none font-medium text-foreground/80`,children:f}),t[12]=f,t[13]=y);let b;t[14]===m?b=t[15]:(b=m?(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] leading-none font-normal text-muted-foreground`,children:m}):null,t[14]=m,t[15]=b);let x;t[16]!==y||t[17]!==b?(x=(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[y,b]}),t[16]=y,t[17]=b,t[18]=x):x=t[18];let S;t[19]!==v||t[20]!==x?(S=(0,$.jsxs)(`span`,{className:`flex h-full w-full min-w-0 items-center gap-1`,children:[v,x]}),t[19]=v,t[20]=x,t[21]=S):S=t[21];let C;return t[22]!==h||t[23]!==l||t[24]!==n||t[25]!==S||t[26]!==g?(C=(0,$.jsx)(`button`,{type:`button`,disabled:l,onClick:n,onMouseDown:bx,onPointerDownCapture:xx,className:g,style:_,title:h,"aria-label":h,children:S}),t[22]=h,t[23]=l,t[24]=n,t[25]=S,t[26]=g,t[27]=C):C=t[27],C};function bx(e){return e.preventDefault()}function xx(e){e.preventDefault()}var Sx={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Cx=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function wx(e,t){let n=(0,Q.c)(6),r=vo(e??``,t),i=oo(e??``,t),a=Ca(e??``,t),o=Da(e??``,t),s=Fa(e??``,t),c=Wa(t),l;bb0:{if(!e){l=Sx;break bb0}if(o.length>0||s.length>0){l=Sx;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=Cx({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=Sx;break bb0}if(!y){l=Sx;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var Tx=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Ex=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Dx=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Ox=(e,t)=>e.id===t.id&&e.directory===t.directory,kx=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Ax=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Dx(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Ox(e.parentTarget,i)&&kx(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},jx=e=>{let{inFlight:t,establishing:n}=e.sendPhase,r=!n&&(e.draftSubmitting||t);return{sendDisabled:!e.canSend||!e.hasSessionTarget||e.submissionBlocked||r,queueDisabled:!e.hasSessionTarget||e.submissionBlocked||!n&&t||e.queueFrozen&&!e.queueFallbackAvailable,disabledClass:`opacity-30 pointer-events-none`}},Mx=`data-mobile-overlay-active`,Nx=e=>Array.from(e).some(e=>e.getAttribute(Mx)!==`false`),Px=`artful.bionic.cosmic.disco.focal.groovy.jammy.kinetic.lunar.noble.bold.brave.calm.eager.gentle.happy.keen.lively.merry.swift.warm.wise.bright.clever.daring.agile.crisp.fresh.lucid.quick.sharp.vivid.zealous`.split(`.`),Fx=`aardvark.beaver.chipmunk.dolphin.falcon.gopher.hedgehog.jackal.koala.lemur.mongoose.narwhal.otter.pangolin.quokka.raccoon.salamander.toucan.walrus.yak.zebra.badger.condor.dingo.egret.ferret.gecko.heron.iguana`.split(`.`);function Ix(){return`${Px[Math.floor(Math.random()*Px.length)]}-${Fx[Math.floor(Math.random()*Fx.length)]}`}function Lx(e){let t=Ix();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var Rx=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,zx=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),Bx=(e,t,n)=>{let r=t.agentName?.trim()||void 0,i=t.providerId?.trim()||void 0,a=t.modelId?.trim()||void 0;!r||!i||!a||(n.saveSessionAgentSelection(e,r),n.saveSessionModelSelection(e,i,a),n.saveAgentModelForSession(e,r,i,a),n.saveAgentModelVariantForSession(e,r,i,a,t.variant))},Vx=async(e,t)=>{await Oo(e)&&await Ha(t)},Hx=e=>{let t=Rx(e),n=Ia.getState().projects;if(n.length===0)return null;let r=Ia.getState().getActiveProject();if(r?.path){let e=Rx(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=Rx(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>Rx(t.path).length-Rx(e.path).length)[0];return i?{id:i.id,path:i.path}:null},Ux=!1,Wx=async(e,t)=>{try{let n=Ia.getState().projects.find(e=>e.id===t.id)??Ia.getState().projects.find(e=>Rx(e.path)===Rx(t.path)),r=gr(t.path);await Ko.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Ko.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),Bx(e,zx(Ko.getState()),ur.getState())}catch{}},Gx=async(e,t,n)=>{let r=wa.getState(),i=Ko.getState();r.initializeNewYuriSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await Wx(e,n),le.getState().setDirectory(t.path,{showOverlay:!1})},Kx=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,qx=async e=>{if(Ux)return null;let t=Ia.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return ji.error(`No active project`,{description:`Please select a project first.`}),null;let r=Hx(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return ji.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await Cs(r.path)}catch{}if(!i)return ji.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;Ux=!0;try{let t=ca(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?Kx(n):Lx(),a=n?`existing`:`new`,o=wa.getState();o.newSessionDraft?.open?o.overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:o.newSessionDraft.directoryOverride??r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}):o.openNewSessionDraft({selectedProjectId:r.id,directoryOverride:r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt});let s=await Ss(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(wa.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),le.getState().setDirectory(s.path,{showOverlay:!1}));let c=await fo(r),l=await eu(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return ts(t,l.path),wa.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),le.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=wa.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(Wo(n,e instanceof Error?e:Error(t)),wa.getState().resolvePendingDraftWorktreeTarget(n,null)),wa.getState().setDraftBootstrapPendingDirectory(null),ji.error(`Failed to create worktree`,{description:t}),null}finally{Ux=!1}};async function Jx(){return qx()}async function Yx(e){let t=e.branch?.trim();return t?qx({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function Xx(e,t,n,r){if(Ux)return null;Ux=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=Hx(e);if(!s)throw Error(`Project is not registered in Yuri`);let c=!1;try{c=await Cs(s.path)}catch{}if(!c)return ji.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await fo(s),u=await Ns(s.path);try{let e=await eu(s,{preferredName:a,mode:`new`,branchName:a,worktreeName:r?.worktreeName||a,startRef:i,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl,setupCommands:l,returnAfterDirectoryCreated:r?.returnAfterDirectoryCreated}),t={...e,createdFromBranch:r?.createdFromBranch||u||i,kind:o};await Vx(s,e.path);let n=await wa.getState().createSession(void 0,e.path);if(!n)throw await Ls(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await Gx(n.id,t,s),{id:n.id,branch:e.branch||a,path:e.path}}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree session`;return ji.error(`Failed to create worktree`,{description:t}),null}}finally{Ux=!1}}var Zx=e=>{let t=e.trim();if(!t)return null;let n=t.match(/\/issues\/(\d+)(?:\b|\/|$)/i);if(n){let e=Number(n[1]);return Number.isFinite(e)&&e>0?e:null}let r=t.match(/^#?(\d+)$/);if(r){let e=Number(r[1]);return Number.isFinite(e)&&e>0?e:null}return null},Qx=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`};function $x({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=Xn(),{github:a}=On(),o=oc(),s=o.data??null,c=o.isFetched,l=K(e=>e.setSettingsDialogOpen),u=K(e=>e.setSettingsPage),d=K(e=>e.isMobile),{isTablet:f}=Kc(),p=d||f,m=Ia(e=>e.getActiveProject()),h=le(e=>e.currentDirectory),g=Z.useMemo(()=>m?.path?.trim()||h?.trim()||null,[m?.path,h]),[_,v]=Z.useState(``),[y,b]=Z.useState(!1),[x,S]=Z.useState(null),C=Z.useRef(0),w=Z.useMemo(()=>Zx(_),[_]),T=au(_,350),E=w?``:T.trim(),D=!!w||_===T,O=e&&D&&!!g&&!!a?.issuesList&&!(c&&s?.connected===!1),k=Sn({queryKey:Tn.scoped(`github-issues`,g,E),enabled:O,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(g,{page:e,...E?{query:E}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),A=D?k.data?.pages.at(-1)??null:null,j=D?k.data?.pages.flatMap(e=>e.issues??[])??[]:[],M=D&&k.hasNextPage,N=!w&&!D||k.isLoading,P=D&&k.isFetchingNextPage,F=D&&k.error?k.error instanceof Error?k.error.message:String(k.error):null,I=Z.useCallback(()=>k.refetch(),[k]),L=Z.useCallback(async()=>{try{await k.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[k,i]);Z.useEffect(()=>{e||(++C.current,v(``),b(!1),S(null))},[e]),Z.useEffect(()=>{++C.current},[e,g]);let R=!c||s?.connected!==!1&&A?.connected!==!1,z=A?.repo?.url??null,B=Z.useCallback(()=>{u(`github`),l(!0)},[l,u]),V=Z.useCallback(()=>{let e=Ko.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),H=Z.useCallback(()=>{let e=Ko.getState(),t=e.settingsDefaultModel??(e.currentModelId?void 0:e.opencodeDefaultModel);if(!t)return null;let n=Po(t);if(!n)return null;let{providerId:r,modelId:i}=n;return{providerID:r,modelID:i}},[]),U=Z.useCallback((e,t)=>{let n=Ko.getState(),r=Po(n.settingsDefaultModel??n.opencodeDefaultModel),i=r?.providerId===e&&r.modelId===t?r.variant??n.settingsDefaultVariant:void 0,a=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0;return i??a},[]),W=Z.useCallback(async(e,o)=>{let s=++C.current,c=()=>C.current===s;if(n===`select`){if(!g){ji.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){ji.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(x)return;S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){ji.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){ji.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=Qx({repo:n.repo,issue:s,comments:u});r&&r({number:s.number,title:s.title,url:s.url,contextText:d,author:s.author?{login:s.author.login,avatarUrl:s.author.avatarUrl}:void 0}),t(!1)}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&S(null)}return}if(!g){ji.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){ji.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!x){S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){ji.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){ji.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){ji.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(y){let e=`issue-${r.number}-${Ix()}`,t=await Xx(g,e,void 0,{returnAfterDirectoryCreated:!0});if(!t?.id)throw Error(`Failed to create worktree session`);return{sessionId:t.id,sessionDirectory:t.path}}let e=await qa(u,g,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??g}})();if(!c())return;Ba(d,u).catch(()=>void 0);try{wa.getState().initializeNewYuriSession(d,Ko.getState().agents)}catch{}t(!1);let f=Ko.getState(),p=ur.getState().lastUsedProvider,m=H(),h=m?.providerID||f.currentProviderId||p?.providerID,_=m?.modelID||f.currentModelId||p?.modelID,v=V()||f.currentAgentName||void 0;if(!h||!_){ji.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let b=U(h,_),x=await za(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await za(`github.issue.review.instructions`);if(!c())return;let C=Qx({repo:n.repo,issue:r,comments:l});wa.getState().sendMessage(x,h,_,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],b,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),ji.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);ji.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&S(null)}}},[y,a,n,t,r,g,V,H,U,x,i]),ee=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),te=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),ne=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Ks,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:_,onChange:e=>{v(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(d?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[g?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.noActiveProject`)}),a?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.runtimeUnavailable`)}),N?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.issues`)]}):null,R===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:i(`session.githubIssuePicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:B,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,F?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:F}):null,w&&g&&a&&R?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===w&&`bg-interactive-selection/30`),onClick:()=>void W(w),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:i(`session.githubIssuePicker.actions.useIssue`,{number:w})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===w?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,j.length===0&&!N&&!F&&R&&a&&g?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:T.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,j.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===e.number&&`bg-interactive-selection/30`),onClick:()=>void W(e.number,e.sourceRepo),children:[(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground w-12 text-right flex-shrink-0`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsx)(`p`,{className:`typography-small text-foreground truncate`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,p?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":i(`session.githubIssuePicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),M&&R&&g&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void L(),disabled:P||!!x,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(P||!!x)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:P?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.more`)]}):i(`session.githubIssuePicker.actions.loadMore`)})}):null]}),n!==`select`&&(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:i(`session.githubIssuePicker.actions.sectionTitle`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 cursor-pointer`,role:`button`,tabIndex:0,"aria-pressed":y,onClick:()=>b(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),b(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),b(e=>!e)},"aria-label":i(`session.githubIssuePicker.actions.toggleWorktreeAria`),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:y?(0,$.jsx)(X,{name:`checkbox`,className:`h-4 w-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i(`session.githubIssuePicker.actions.createInWorktree`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/70 hidden sm:inline`,children:`(issue-<number>-<slug>)`})]}),(0,$.jsx)(`div`,{className:`hidden sm:block sm:flex-1`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[z?(0,$.jsx)(er,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:z,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:I,disabled:N||!!x,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return d?(0,$.jsx)(zc,{open:e,title:ee,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:ee}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:te})]}),children:ne}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(hs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),ee]}),(0,$.jsx)(ys,{children:te})]}),ne]})})}var eS=e=>{let t=e.trim();if(!t)return null;let n=t.match(/\/pull\/(\d+)(?:\b|\/|$)/i);if(n){let e=Number(n[1]);return Number.isFinite(e)&&e>0?e:null}let r=t.match(/^#?(\d+)$/);if(r){let e=Number(r[1]);return Number.isFinite(e)&&e>0?e:null}return null},tS=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function nS({open:e,onOpenChange:t,onSelect:n}){let{t:r}=Xn(),{github:i}=On(),a=oc(),o=a.data??null,s=a.isFetched,c=K(e=>e.setSettingsDialogOpen),l=K(e=>e.setSettingsPage),u=K(e=>e.isMobile),{isTablet:d}=Kc(),f=u||d,p=Ia(e=>e.getActiveProject())?.path??null,[m,h]=Z.useState(``),[g,_]=Z.useState(!1),[v,y]=Z.useState(null),b=Z.useRef(0),x=Z.useMemo(()=>eS(m),[m]),S=au(m,350),C=x?``:S.trim(),w=!!x||m===S,T=e&&w&&!!p&&!!i?.prsList&&!(s&&o?.connected===!1),E=Sn({queryKey:Tn.scoped(`github-prs`,p,C),enabled:T,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(p,{page:e,...C?{query:C}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),D=w?E.data?.pages.at(-1)??null:null,O=w?E.data?.pages.flatMap(e=>e.prs??[])??[]:[],k=w&&E.hasNextPage,A=!x&&!w||E.isLoading,j=w&&E.isFetchingNextPage,M=w&&E.error?E.error instanceof Error?E.error.message:String(E.error):null,N=J(async()=>{try{await E.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);ji.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++b.current,h(``),_(!1),y(null))},[e]),Z.useEffect(()=>{++b.current},[e,p]);let P=!s||o?.connected!==!1&&D?.connected!==!1,F=J(()=>{l(`github`),c(!0)}),I=J(async(e,a)=>{if(!p){ji.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){ji.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(v)return;let o=++b.current,s=()=>b.current===o;y(e);try{let o=await i.prContext(p,e,{includeDiff:g,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){ji.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){ji.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){ji.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await za(`github.pr.review.instructions`);if(!s())return;n({number:o.pr.number,title:o.pr.title,url:o.pr.url,head:o.pr.head,base:o.pr.base,includeDiff:g,instructionsText:e,contextText:tS(o),author:o.pr.author?{login:o.pr.author.login,avatarUrl:o.pr.author.avatarUrl}:void 0})}t(!1)}catch(e){if(!s())return;let t=e instanceof Error?e.message:String(e);ji.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&y(null)}}),L=r(`session.githubPrPicker.title`),R=r(`session.githubPrPicker.description`),z=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Ks,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:m,onChange:e=>{h(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":g,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Ts,{checked:g,onChange:e=>_(e),ariaLabel:r(`session.githubPrPicker.includeDiffAria`)})}),(0,$.jsx)(`span`,{className:`typography-small text-muted-foreground whitespace-nowrap`,children:r(`session.githubPrPicker.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(u?`min-h-0`:`flex-1 overflow-y-auto`),children:[p?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.noActiveProject`)}),i?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.runtimeUnavailable`)}),A?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.pullRequests`)]}):null,P===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:r(`session.githubPrPicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:F,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,M?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:M}):null,x&&p&&i&&P?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===x&&`bg-interactive-selection/30`),onClick:()=>void I(x),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:r(`session.githubPrPicker.actions.usePullRequest`,{number:x})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===x?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,O.length===0&&!A&&!M&&P&&i&&p?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:S.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,O.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===e.number&&`bg-interactive-selection/30`),onClick:()=>void I(e.number,e.sourceRepo),children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsxs)(`p`,{className:`typography-small text-foreground truncate`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground mr-1`,children:[`#`,e.number]}),e.title]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,(0,$.jsxs)(`p`,{className:`typography-meta text-muted-foreground truncate`,children:[e.head,` → `,e.base]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,f?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":r(`session.githubPrPicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),k&&P&&p&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void N(),disabled:j||!!v,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(j||!!v)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:j?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.more`)]}):r(`session.githubPrPicker.actions.loadMore`)})}):null]})]});return u?(0,$.jsx)(zc,{open:e,title:L,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:L}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:R})]}),children:z}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(hs,{className:`flex-shrink-0`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),L]}),(0,$.jsx)(ys,{children:R})]}),z]})})}function rS(e){let t=(0,Q.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,style:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===i?a=t[5]:(a={color:`var(--surface-elevated-foreground)`,...i},t[4]=i,t[5]=a);let o;t[6]===n?o=t[7]:(o=Y(`flex h-full w-full flex-col overflow-hidden rounded-xl`,n),t[6]=n,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,$.jsx)(nf,{"data-slot":`command`,style:a,className:o,...r}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s}var iS=Z.forwardRef((e,t)=>{let n=(0,Q.c)(16),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=(a===void 0?`default`:a)===`mobileGlass`?`yuri-mobile-glass-control rounded-full`:`bg-[var(--surface-elevated)] ring-1 ring-inset ring-border/60 transition duration-200 ease-out hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)] hover:[&:not(:focus-within)]:ring-transparent focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]`,s;n[4]===o?s=n[5]:(s=Y(`flex h-8 items-center gap-2 rounded-lg px-3`,o),n[4]=o,n[5]=s);let c;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 opacity-50`}),n[6]=c):c=n[6];let l;n[7]===r?l=n[8]:(l=Y(`placeholder:text-muted-foreground flex h-8 w-full bg-transparent typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`,r),n[7]=r,n[8]=l);let u;n[9]!==i||n[10]!==t||n[11]!==l?(u=(0,$.jsx)(nf.Input,{ref:t,"data-slot":`command-input`,className:l,...i}),n[9]=i,n[10]=t,n[11]=l,n[12]=u):u=n[12];let d;return n[13]!==s||n[14]!==u?(d=(0,$.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1.5 pb-1`,children:(0,$.jsxs)(`div`,{"data-slot":`command-input-field`,className:s,children:[c,u]})}),n[13]=s,n[14]=u,n[15]=d):d=n[15],d});iS.displayName=`CommandInput`;function aS(e){let t=(0,Q.c)(14),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:r,children:n,scrollbarClassName:o,disableHorizontal:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s;t[6]===r?s=t[7]:(s=Y(`scroll-py-1 overflow-x-hidden h-full min-h-0`,r),t[6]=r,t[7]=s);let c=o??`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,l=i??!0,u;return t[8]!==n||t[9]!==a||t[10]!==s||t[11]!==c||t[12]!==l?(u=(0,$.jsx)(Xu,{as:nf.List,"data-slot":`command-list`,outerClassName:`max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0`,className:s,scrollbarClassName:c,disableHorizontal:l,...a,children:n}),t[8]=n,t[9]=a,t[10]=s,t[11]=c,t[12]=l,t[13]=u):u=t[13],u}function oS(e){let t=(0,Q.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,$.jsx)(nf.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function sS(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(nf.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function cS(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`bg-border -mx-1 h-px`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(nf.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function lS(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(nf.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var uS=(e,t)=>`${e}:${zt(t)}`,dS=e=>e.type===`skill`||!mn(e.name);function fS(e){let{t}=Xn(),n=Z.useMemo(()=>p(),[]),r=K(e=>e.globalDraftStarters),i=Ia(e=>e.activeProjectId),a=Ia(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[s,c]=Z.useState([]),l=Z.useMemo(()=>r??hn,[r]),u=l.some(dS)||s.some(dS),d=Oa({directory:e,enabled:u}),f=Z.useMemo(()=>d.data??[],[d.data]),{refetch:m}=d,h=$i({directory:e,enabled:u}),g=Z.useMemo(()=>h.data??[],[h.data]),{refetch:_}=h;Z.useEffect(()=>{let e=!1;if(!o){c([]);return}return Io(o).then(t=>{e||c(t)}).catch(()=>{e||c([])}),()=>{e=!0}},[o?.id]);let v=Z.useCallback(()=>{m(),_()},[m,_]),y=Z.useMemo(()=>new Set(f.map(e=>e.name)),[f]),b=Z.useMemo(()=>new Set(g.map(e=>e.name)),[g]),x=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=mn(e.name);return n?{id:uS(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:y.has(e.name)?{id:uS(r,e),ref:e,group:r,label:Rt(e.name),icon:dn,submitText:`/${e.name}`}:null}return b.has(e.name)?{id:uS(r,e),ref:e,group:r,label:Rt(e.name),icon:qt,submitText:`@${e.name}`}:null},[t,y,b,n]),S=Z.useMemo(()=>l.map(e=>x(e,`global`)).filter(e=>e!==null),[l,x]),C=Z.useMemo(()=>s.map(e=>x(e,`project`)).filter(e=>e!==null),[s,x]),w=Z.useMemo(()=>{let e=new Set;for(let t of l)e.add(zt(t));for(let t of s)e.add(zt(t));return e},[l,s]),T=Z.useMemo(()=>{let e=[];for(let r of Gt)n&&r.name===`craft-goal`||e.push({type:`command`,name:r.name,label:t(r.labelKey),icon:r.icon,section:`built-in`,scope:`user`});for(let t of f)t.isBuiltIn||t.source===`skill`||mn(t.name)||e.push({type:`command`,name:t.name,label:Rt(t.name),icon:dn,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of g)e.push({type:`skill`,name:t.name,label:Rt(t.name),icon:qt,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!w.has(`${e.type}:${e.name}`))},[t,f,g,w,n]),E=Z.useCallback(e=>{K.getState().setGlobalDraftStarters(e),Zt({draftStarters:e})},[]),D=Z.useCallback(e=>{c(e),o&&pa(o,e)},[o]),O=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||s.some(e=>Et(e,t)))return;D([...s,t])}else{let e=r??hn;if(e.some(e=>Et(e,t)))return;E([...e,t])}},[o,s,r,D,E]),k=Z.useCallback((e,t)=>{e===`project`?D(s.filter(e=>!Et(e,t))):E((r??hn).filter(e=>!Et(e,t)))},[s,r,D,E]),A=Z.useCallback((e,t,n)=>{let i=e===`project`?s:r??hn,a=i.findIndex(n=>uS(e,n)===t),o=i.findIndex(t=>uS(e,t)===n);if(a<0||o<0||a===o)return;let c=cd([...i],a,o);e===`project`?D(c):E(c)},[s,r,D,E]);return{global:S,project:C,pinnable:T,hasProject:!!o,ensureLoaded:v,addStarter:O,removeStarter:k,reorder:A}}var pS=`__draft-starter-trash__`,mS=`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-foreground`,hS=`max-h-7`,gS=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],_S=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=Xn(),s;t[0]===n.id?s=t[1]:(s={id:n.id},t[0]=n.id,t[1]=s);let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=ld(s),m;t[2]===d?m=t[3]:(m=od.Translate.toString(d),t[2]=d,t[3]=m);let h;t[4]!==m||t[5]!==f?(h={transform:m,transition:f},t[4]=m,t[5]=f,t[6]=h):h=t[6];let g=p&&`z-10 opacity-60`,_;t[7]===g?_=t[8]:(_=Y(`group/chip relative`,g),t[7]=g,t[8]=_);let v;t[9]!==n.submitText||t[10]!==r?(v=()=>r(n.submitText),t[9]=n.submitText,t[10]=r,t[11]=v):v=t[11];let y=!a&&`pr-5`,b;t[12]===y?b=t[13]:(b=Y(`group inline-flex touch-none select-none items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors`,`hover:bg-[var(--interactive-hover)] hover:text-foreground`,y),t[12]=y,t[13]=b);let x;t[14]===n.icon?x=t[15]:(x=(0,$.jsx)(X,{name:n.icon,className:`h-3 w-3 shrink-0 opacity-60 transition-opacity group-hover:opacity-100`}),t[14]=n.icon,t[15]=x);let S;t[16]===n.label?S=t[17]:(S=(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:n.label}),t[16]=n.label,t[17]=S);let C;t[18]!==c||t[19]!==l||t[20]!==S||t[21]!==v||t[22]!==b||t[23]!==x?(C=(0,$.jsxs)(`button`,{type:`button`,...c,...l,onClick:v,className:b,children:[x,S]}),t[18]=c,t[19]=l,t[20]=S,t[21]=v,t[22]=b,t[23]=x,t[24]=C):C=t[24];let w;t[25]!==a||t[26]!==i||t[27]!==o?(w=a?null:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},"aria-label":o(`chat.draftStarters.remove`),title:o(`chat.draftStarters.remove`),className:`absolute right-0.5 top-1/2 hidden h-4 w-4 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:text-foreground group-hover/chip:flex`,children:(0,$.jsx)(X,{name:`close`,className:`h-2.5 w-2.5`})}),t[25]=a,t[26]=i,t[27]=o,t[28]=w):w=t[28];let T;return t[29]!==u||t[30]!==C||t[31]!==w||t[32]!==h||t[33]!==_?(T=(0,$.jsxs)(`div`,{ref:u,style:h,className:_,children:[C,w]}),t[29]=u,t[30]=C,t[31]=w,t[32]=h,t[33]=_,t[34]=T):T=t[34],T},vS=e=>{let t=(0,Q.c)(14),{items:n,onSubmit:r,onRemove:i,hideRemove:a}=e,o;t[0]===n?o=t[1]:(o=n.map(CS),t[0]=n,t[1]=o);let s;if(t[2]!==a||t[3]!==n||t[4]!==i||t[5]!==r){let e;t[7]!==a||t[8]!==i||t[9]!==r?(e=e=>(0,$.jsx)(_S,{item:e,onSubmit:r,onRemove:()=>i(e),hideRemove:a},e.id),t[7]=a,t[8]=i,t[9]=r,t[10]=e):e=t[10],s=n.map(e),t[2]=a,t[3]=n,t[4]=i,t[5]=r,t[6]=s}else s=t[6];let c;return t[11]!==o||t[12]!==s?(c=(0,$.jsx)(dd,{items:o,strategy:sd,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},yS=()=>{let e=(0,Q.c)(13),{t}=Xn(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:pS},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=td(n),a;e[1]===t?a=e[2]:(a=t(`chat.draftStarters.remove`),e[1]=t,e[2]=a);let o;e[3]===t?o=e[4]:(o=t(`chat.draftStarters.remove`),e[3]=t,e[4]=o);let s=i&&`text-destructive hover:text-destructive`,c;e[5]===s?c=e[6]:(c=Y(mS,s),e[5]=s,e[6]=c);let l;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`}),e[7]=l):l=e[7];let u;return e[8]!==r||e[9]!==a||e[10]!==o||e[11]!==c?(u=(0,$.jsx)(`button`,{type:`button`,ref:r,"aria-label":a,title:o,className:c,children:l}),e[8]=r,e[9]=a,e[10]=o,e[11]=c,e[12]=u):u=e[12],u},bS=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=Xn(),o;t[0]===i?o=t[1]:(o=Y(`min-h-0`,i),t[0]=i,t[1]=o);let s;t[2]===a?s=t[3]:(s=a(`chat.draftStarters.searchPlaceholder`),t[2]=a,t[3]=s);let c;t[4]===s?c=t[5]:(c=(0,$.jsx)(iS,{placeholder:s}),t[4]=s,t[5]=c);let l;t[6]===a?l=t[7]:(l=a(`chat.draftStarters.empty`),t[6]=a,t[7]=l);let u;t[8]===l?u=t[9]:(u=(0,$.jsx)(oS,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=gS.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(sS,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(lS,{value:`${e.section} ${e.label} ${e.name}`,onSelect:()=>r(e),children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})},`${e.type}:${e.name}`))},e.key)}),t[10]=r,t[11]=n,t[12]=a,t[13]=d):d=t[13];let f;t[14]!==u||t[15]!==d?(f=(0,$.jsxs)(aS,{children:[u,d]}),t[14]=u,t[15]=d,t[16]=f):f=t[16];let p;return t[17]!==o||t[18]!==c||t[19]!==f?(p=(0,$.jsxs)(rS,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},xS=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=Xn(),[o,s]=Z.useState(!1),c;t[0]===r?c=t[1]:(c=e=>{s(e),e&&r()},t[0]=r,t[1]=c);let l;t[2]===a?l=t[3]:(l=a(`chat.draftStarters.add`),t[2]=a,t[3]=l);let u;t[4]===a?u=t[5]:(u=a(`chat.draftStarters.add`),t[4]=a,t[5]=u);let d;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`}),t[6]=d):d=t[6];let f;t[7]!==l||t[8]!==u?(f=(0,$.jsx)(bs,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:mS,children:d})}),t[7]=l,t[8]=u,t[9]=f):f=t[9];let p;t[10]===a?p=t[11]:(p=a(`chat.draftStarters.add`),t[10]=a,t[11]=p);let m;t[12]===p?m=t[13]:(m=(0,$.jsx)(hs,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(vs,{children:p})}),t[12]=p,t[13]=m);let h;t[14]===i?h=t[15]:(h=e=>{i(e),s(!1)},t[14]=i,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(bS,{pinnable:n,onPick:h,className:`flex max-h-[60vh] flex-col`}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==m||t[20]!==g?(_=(0,$.jsxs)(_s,{className:`gap-0 overflow-hidden p-0 sm:max-w-sm`,children:[m,g]}),t[19]=m,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==o||t[23]!==c||t[24]!==_||t[25]!==f?(v=(0,$.jsxs)(xs,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},SS=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=Xn(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=fS(bd()),{isMobile:f}=Kc(),[p,m]=Z.useState(!1),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),y=Z.useRef(null),b;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(b={activationConstraint:{distance:8}},t[0]=b):b=t[0];let x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(x={activationConstraint:{delay:200,tolerance:6}},t[1]=x):x=t[1];let S=ad(Qu(rd,b),Qu(ed,x)),C;t[2]!==a||t[3]!==o?(C=e=>a.find(t=>t.id===e)??o.find(t=>t.id===e),t[2]=a,t[3]=o,t[4]=C):C=t[4];let w=C,T=a.length+o.length,E;t[5]===T?E=t[6]:(E=()=>{let e=y.current;if(!e||T===0){v(!1);return}let t=()=>{let t=e.firstElementChild?.offsetHeight??28;v(e.scrollHeight>t+4)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},t[5]=T,t[6]=E);let D;t[7]!==h||t[8]!==a||t[9]!==o||t[10]!==T?(D=[T,h,a,o],t[7]=h,t[8]=a,t[9]=o,t[10]=T,t[11]=D):D=t[11],Z.useLayoutEffect(E,D);let O,k;t[12]!==_||t[13]!==h?(O=()=>{!_&&h&&g(!1)},k=[_,h],t[12]=_,t[13]=h,t[14]=O,t[15]=k):(O=t[14],k=t[15]),Z.useEffect(O,k);let A;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>m(!0),t[16]=A):A=t[16];let j=A,M;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>m(!1),t[17]=M):M=t[17];let N=M,P;t[18]!==w||t[19]!==u||t[20]!==d?(P=e=>{m(!1);let{active:t,over:n}=e;if(!n)return;let r=String(t.id),i=w(r);if(!i)return;if(String(n.id)===pS){u(i.group,i.ref);return}let a=String(n.id);if(r===a)return;let o=w(a);o&&o.group===i.group&&d(i.group,r,a)},t[18]=w,t[19]=u,t[20]=d,t[21]=P):P=t[21];let F=P,I=_||h,L;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(L={droppable:{strategy:$u.Always}},t[22]=L):L=t[22];let R;t[23]===r?R=t[24]:(R=Y(`flex min-w-0 max-w-full items-start justify-center gap-0.5`,r),t[23]=r,t[24]=R);let z=!h&&hS,B=!h&&`overflow-clip`,V;t[25]!==z||t[26]!==B?(V=Y(`flex min-w-0 flex-1 flex-wrap items-center justify-center gap-x-0.5 gap-y-0.5`,z,B),t[25]=z,t[26]=B,t[27]=V):V=t[27];let H;t[28]!==a||t[29]!==f||t[30]!==n||t[31]!==u?(H=a.length>0?(0,$.jsx)(vS,{items:a,onSubmit:n,onRemove:e=>u(`global`,e.ref),hideRemove:f}):null,t[28]=a,t[29]=f,t[30]=n,t[31]=u,t[32]=H):H=t[32];let U;t[33]!==f||t[34]!==n||t[35]!==o||t[36]!==u?(U=o.length>0?(0,$.jsx)(vS,{items:o,onSubmit:n,onRemove:e=>u(`project`,e.ref),hideRemove:f}):null,t[33]=f,t[34]=n,t[35]=o,t[36]=u,t[37]=U):U=t[37];let W;t[38]!==V||t[39]!==H||t[40]!==U?(W=(0,$.jsxs)(`div`,{ref:y,className:V,children:[H,U]}),t[38]=V,t[39]=H,t[40]=U,t[41]=W):W=t[41];let ee;t[42]!==h||t[43]!==I||t[44]!==i?(ee=I?(0,$.jsx)(`button`,{type:`button`,onClick:()=>g(wS),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:mS,children:(0,$.jsx)(X,{name:h?`arrow-up-s`:`arrow-down-s`,className:`h-3.5 w-3.5`})}):null,t[42]=h,t[43]=I,t[44]=i,t[45]=ee):ee=t[45];let te;t[46]!==l||t[47]!==c||t[48]!==p||t[49]!==f||t[50]!==s?(te=f&&p?(0,$.jsx)(yS,{}):(0,$.jsx)(xS,{pinnable:s,onOpen:c,onAdd:l}),t[46]=l,t[47]=c,t[48]=p,t[49]=f,t[50]=s,t[51]=te):te=t[51];let ne;t[52]!==ee||t[53]!==te?(ne=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 self-start`,children:[ee,te]}),t[52]=ee,t[53]=te,t[54]=ne):ne=t[54];let re;t[55]!==R||t[56]!==W||t[57]!==ne?(re=(0,$.jsxs)(`div`,{className:R,children:[W,ne]}),t[55]=R,t[56]=W,t[57]=ne,t[58]=re):re=t[58];let G;return t[59]!==F||t[60]!==S||t[61]!==re?(G=(0,$.jsx)(id,{sensors:S,collisionDetection:nd,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:re}),t[59]=F,t[60]=S,t[61]=re,t[62]=G):G=t[62],G};function CS(e){return e.id}function wS(e){return!e}function TS(e){let t=(0,Q.c)(27),{branches:n,search:r,local:i,currentBranch:a,branchInfo:o,onCheckout:s}=e,{t:c}=Xn(),l;if(t[0]!==n||t[1]!==r){let e=r.trim();l=e?Bi(n,e,DS).map(ES):n,t[0]=n,t[1]=r,t[2]=l}else l=t[2];let u=l,d=i?`gitView.branch.localBranches`:`gitView.branch.remoteBranches`,f;t[3]!==c||t[4]!==d?(f=c(d),t[3]=c,t[4]=d,t[5]=f):f=t[5];let p;if(t[6]!==o||t[7]!==a||t[8]!==u||t[9]!==i||t[10]!==s||t[11]!==c){let e;t[13]!==o||t[14]!==a||t[15]!==i||t[16]!==s||t[17]!==c?(e=e=>(0,$.jsxs)(lS,{onSelect:()=>s(e),children:[i?(0,$.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),(o?.[e]?.ahead||o?.[e]?.behind)&&(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[o[e].ahead||0,` ahead ·`,` `,o[e].behind||0,` behind`]})]}):(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e}),i&&a===e&&(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:c(`gitView.branch.currentBadge`)})]},`${i?`local`:`remote`}-${e}`),t[13]=o,t[14]=a,t[15]=i,t[16]=s,t[17]=c,t[18]=e):e=t[18],p=u.map(e),t[6]=o,t[7]=a,t[8]=u,t[9]=i,t[10]=s,t[11]=c,t[12]=p}else p=t[12];let m;t[19]!==u.length||t[20]!==i||t[21]!==c?(m=u.length===0&&(0,$.jsx)(lS,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:c(i?`gitView.branch.noLocalBranches`:`gitView.branch.noRemoteBranches`)})}),t[19]=u.length,t[20]=i,t[21]=c,t[22]=m):m=t[22];let h;return t[23]!==f||t[24]!==p||t[25]!==m?(h=(0,$.jsxs)(sS,{heading:f,children:[p,m]}),t[23]=f,t[24]=p,t[25]=m,t[26]=h):h=t[26],h}function ES(e){return e.item}function DS(e){return e}function OS(e){let t=(0,Q.c)(9),{options:n,selectedDirectory:r,onSelect:i}=e,{t:a}=Xn(),o;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a){let e;t[5]!==i||t[6]!==r||t[7]!==a?(e=e=>(0,$.jsxs)(lS,{onSelect:()=>i(e.value),children:[(0,$.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),r===e.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:a(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`),t[5]=i,t[6]=r,t[7]=a,t[8]=e):e=t[8],o=n.map(e),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o}else o=t[4];return o}var kS=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),AS=({currentBranch:e,localBranches:t,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:o=[],disabled:s=!1,iconOnly:c=!1,trigger:l,triggerLabel:u,contentAlign:d,hideTooltip:f=!1,projectRootOption:p=null,worktreeOptions:m=[],selectedDirectory:h=null,onSelectDirectory:g,onCreateWorktree:_,worktreesLabel:v,worktreeNewLabel:y,projectRootLabel:b,onOpenChange:x,open:S,presentation:C=`dropdown`})=>{let{t:w}=Xn(),[T,E]=Z.useState(!1),[D,O]=Z.useState(``),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(``),[F,I]=Z.useState(!1),L=Z.useRef(null),R=Z.useId(),z=S??T,B=e=>{S===void 0&&E(e),x?.(e)},V=Z.useCallback(e=>{e.stopPropagation()},[]),H=o.length>1,U=!!(g||_),W=Z.useMemo(()=>kS(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?Bi(m,e,e=>e.label).map(e=>e.item):m},[D,m]),te=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||Bi([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),ne=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},re=e=>{g?.(e),B(!1),O(``)},G=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},ie=async()=>{if(!(!W||F)){if(H){M(!0);return}I(!0);try{await a(W,o[0]),P(``),A(!1),B(!1)}finally{I(!1)}}},ae=async e=>{if(!(!W||F)){I(!0);try{await a(W,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},oe=()=>{M(!1)},se=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let ce=u||e||w(`gitView.branch.detachedHead`),le=d??(c?`end`:`start`),ue=v??w(`chat.chatInput.worktrees`),de=y??w(`chat.chatInput.worktreeNew`),fe=b??w(`chat.chatInput.projectRoot`),pe=c?(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":ce,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(er,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":ce,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:ce}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),me=(0,$.jsx)(Hc,{asChild:!0,disabled:s,children:l??pe}),he=(0,$.jsxs)(rS,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(iS,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(aS,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(oS,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(sS,{children:j?(0,$.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:oe,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-4`})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,$.jsx)(`span`,{className:`text-foreground font-medium`,children:W}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ae(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,$.jsx)(X,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,$.jsx)(`input`,{ref:L,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:N,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{V(e),e.key===`Enter`?(e.preventDefault(),ie()):e.key===`Escape`&&(e.preventDefault(),se())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:ie,disabled:!W||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:se,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(lS,{onSelect:G,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(cS,{}),(0,$.jsx)(TS,{branches:t,search:D,local:!0,currentBranch:e,branchInfo:r,onCheckout:ne}),(0,$.jsx)(cS,{}),(0,$.jsx)(TS,{branches:n,search:D,onCheckout:ne}),U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(cS,{}),(0,$.jsxs)(sS,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:ue}),_?(0,$.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),B(!1),_()},children:de}):null]}),p&&te?(0,$.jsxs)(lS,{onSelect:()=>re(p.value),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:fe}),(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,(0,$.jsx)(OS,{options:ee,selectedDirectory:h,onSelect:re})]})]}):null]})]});if(C===`mobile-sheet`){let e=Z.cloneElement(l??pe,{onClick:()=>B(!0),"data-popup-open":z?``:void 0});return(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(fl,{id:`mobile-draft-branch-picker-sheet-${R}`,open:z,onOpenChange:B,ariaLabel:w(`gitView.branch.selectBranch`),closeAriaLabel:w(`mobile.surface.closeAria`),resizeAriaLabel:w(`mobile.sessions.sheet.resizeAria`),children:he})]})}return(0,$.jsxs)(Bc,{open:z,onOpenChange:B,children:[f||l?me:(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:me}),(0,$.jsx)(Js,{sideOffset:8,children:c?ce:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(kc,{align:le,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:he})]})};function jS(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=Bi(t,i,e=>e),o=Bi(n,i,e=>e),s=new Set(a.map(e=>e.item)),c=new Set(o.map(e=>e.item));return{matching:[...a.map(e=>({label:e.item,value:e.item,source:`local`,score:e.score})),...o.map(e=>({label:e.item,value:`remotes/${e.item}`,source:`remote`,score:e.score}))].sort((e,t)=>e.score===t.score?e.source===t.source?e.label.length===t.label.length?e.label.localeCompare(t.label,void 0,{sensitivity:`accent`}):e.label.length-t.label.length:e.source===`local`?-1:1:e.score-t.score).map(({label:e,value:t,source:n})=>({label:e,value:t,source:n})),otherLocal:t.filter(e=>!s.has(e)),otherRemote:n.filter(e=>!c.has(e))}}function MS(e,t){return`${e}\0${t}`}function NS({open:e,onOpenChange:t,onSelect:n}){let{t:r}=Xn(),i=K(e=>e.isMobile),{github:a}=On(),o=oc(),s=o.data??null,c=o.isFetched,l=K(e=>e.setSettingsDialogOpen),u=K(e=>e.setSettingsPage),d=Ia(e=>e.getActiveProject()),f=d?.id??null,p=d?.path??null,m=Z.useMemo(()=>p&&f?{id:f,path:p}:null,[f,p]),[h,g]=Z.useState(`issues`),[_,v]=Z.useState(``),[y,b]=Z.useState([]),[x,S]=Z.useState([]),[C,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState(null),[j,M]=Z.useState(null),[N,P]=Z.useState(!1),[F,I]=Z.useState(new Map),[L,R]=Z.useState(1),[z,B]=Z.useState(!1),V=Z.useRef(0),H=au(_,350),U=J(async e=>{if(!(!p||!a)&&!(c&&s?.connected===!1)){w(!0),O(null),R(1),B(!1);try{if(h===`issues`&&a.issuesList){let t=await a.issuesList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(t.issues??[]),R(t.page??1),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=await a.prsList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(t.prs??[]),R(t.page??1),B(!!t.hasMore))}}catch(e){O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{w(!1)}}});Z.useEffect(()=>{if(!e||!p||c&&s?.connected===!1||!a)return;if(!H.trim()){U();return}let t=new AbortController;w(!0),O(null),R(1),B(!1);let n=h===`issues`&&a.issuesList?a.issuesList(p,{page:1,query:H.trim()}):h===`prs`&&a.prsList?a.prsList(p,{page:1,query:H.trim()}):null;if(!n){w(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(e.issues??[]),R(e.page??1),B(!!e.hasMore)):`prs`in e&&(e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(e.prs??[]),R(e.page??1),B(!!e.hasMore))))}).catch(e=>{t.signal.aborted||O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||w(!1)}),()=>t.abort()},[e,p,a,c,s,h,H,U,r]);let W=J(async()=>{if(!(!p||!a)&&!(C||T)&&z){E(!0);try{let e=L+1;if(h===`issues`&&a.issuesList){let t=H.trim()?await a.issuesList(p,{page:e,query:H.trim()}):await a.issuesList(p,{page:e});t.connected!==!1&&(b(e=>[...e,...t.issues??[]]),R(t.page??e),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=H.trim()?await a.prsList(p,{page:e,query:H.trim()}):await a.prsList(p,{page:e});t.connected!==!1&&(S(e=>[...e,...t.prs??[]]),R(t.page??e),B(!!t.hasMore))}}catch{}finally{E(!1)}}});Z.useEffect(()=>{if(!e){g(`issues`),v(``),b([]),S([]),A(null),M(null),P(!1),O(null),I(new Map),R(1),B(!1);return}U()},[e,U]),Z.useEffect(()=>{V.current+=1,I(new Map)},[p,m]);let ee=J(async e=>{if(!m||!e)return;let t=MS(m.path,e);if(F.has(t))return;let n=V.current;try{let i=await Hs(m,{mode:`new`,branchName:e,worktreeName:e});if(n!==V.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);I(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==V.current)return;I(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||h!==`prs`||x.forEach(e=>{e.head&&ee(e.head)})},[e,h,x,p,m,ee]);let te=c&&s?.connected===!0,ne=()=>{u(`github`),l(!0)},re=e=>{A(e),M(null)},G=e=>{M(e),A(null)},ie=()=>{k?n({type:`issue`,item:k}):j&&n({type:`pr`,item:j,includeDiff:N}),t(!1)},ae=()=>{A(null),M(null),P(!1)},oe=k||(j?.head&&p?F.get(MS(p,j.head))?.isValid!==!1:!1),se=e=>!e.head||(p?F.get(MS(p,e.head)):void 0)?.isValid===!1,ce=(0,$.jsx)($.Fragment,{children:te?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Ks,{value:_,onChange:e=>v(e.target.value),placeholder:r(h===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[C&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),D&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:D})]})}),!C&&!D&&h===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[y.length>0?y.map(e=>(0,$.jsx)(`button`,{onClick:()=>re(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,k?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(er,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!C&&!D&&h===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[x.length>0?x.map(e=>{let t=se(e),n=e.head&&p?F.get(MS(p,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&G(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,j?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(er,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,$.jsx)(X,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:r(`session.githubIntegration.connect.title`)}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:r(`session.githubIntegration.connect.description`)})]}),(0,$.jsx)(er,{onClick:ne,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),le=(0,$.jsxs)(`div`,{className:Y(`w-full`,i?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-4`,i?`w-full justify-center order-1`:`flex-1`),children:[!i&&(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ae,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),h===`prs`&&j&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(Ts,{checked:N,onChange:e=>P(e),ariaLabel:r(`session.githubIntegration.includeDiffAria`)}),(0,$.jsx)(`span`,{className:`typography-small text-foreground`,children:r(`session.githubIntegration.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,i?`w-full order-2`:`justify-end`),children:[(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(er,{size:`sm`,onClick:ie,disabled:!oe,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(zc,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:te?le:void 0,renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:r(`session.githubIntegration.title`)}),e]}),(0,$.jsx)(`div`,{className:`w-full`,children:(0,$.jsx)(rf,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})}),(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ae,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),children:ce}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(hs,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),r(`session.githubIntegration.title`)]}),(0,$.jsx)(`div`,{className:`w-[220px]`,children:(0,$.jsx)(rf,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),ce,(0,$.jsx)(gs,{className:`mt-1`,children:le})]})})})}var PS=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},FS=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),IS=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``).split(`/`).join(`-`).replace(/[^A-Za-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80),LS=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,RS=(e,t,n)=>{let r=FS(e.head||``);if(!r)throw Error(`PR head branch is missing`);if(t.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};let i=n.find(e=>{let t=e.indexOf(`/`);return t<=0||t>=e.length-1?!1:e.slice(t+1)===r});if(i){let e=i.indexOf(`/`),t=i.slice(0,e);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:t,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${t}/${r}`}}let a=String(e.headLabel||``).split(`:`)[0]?.trim(),o=`pr-${LS(e.headRepo?.owner||a||`pr-head`)}`,s=e.headRepo?.sshUrl||e.headRepo?.cloneUrl||``;if(!s)throw Error(`PR head repository URL is unavailable`);return{existingBranch:`remotes/${o}/${r}`,setUpstream:!0,upstreamRemote:o,upstreamBranch:r,ensureRemoteName:o,ensureRemoteUrl:s,sourceLabel:`${o}/${r}`}},zS=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},BS=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function VS({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=Xn(),{github:a,git:o}=On(),s=K(e=>e.isMobile),c=Z.useId(),l=oc(),u=l.data??null,d=l.isFetched,f=Ia(e=>PS(e.projects,e.activeProjectId,r)),p=f?.path??null,m=Z.useMemo(()=>p&&f?{id:f.id,path:p}:null,[f,p]),[h,g]=Z.useState(`new-branch`),[_,v]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[y,b]=Z.useState({selectedBranch:``,worktreeName:``}),x=nu(p),S=lu(p),C=gu(e=>e.fetchBranches),w=Z.useMemo(()=>x?.all?x.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[x]),T=Z.useMemo(()=>x?.all?x.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[x]),E=wa(e=>e.availableWorktreesByProject),D=Z.useMemo(()=>{if(!p)return new Set;let e=E.get(p)??[];return new Set(e.map(e=>e.name))},[E,p]),O=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=Ix();if(!D.has(e))return e}return`${Ix()}-${Date.now().toString(36).slice(-4)}`},[D]),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(!1),[F,I]=Z.useState(!1),[L,R]=Z.useState(!1),[z,B]=Z.useState(``),[V,H]=Z.useState(``),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),te=Z.useRef(null),ne=Z.useCallback(e=>{e.stopPropagation()},[]),re=Z.useCallback(e=>{let t=e;for(;t&&t!==document.body;){let{overflowY:e}=window.getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null},[]),G=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),ie=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;G(t)},[G]),ae=Z.useCallback(e=>{let t=re(e.current);G(t)},[re,G]),oe=Z.useMemo(()=>jS({localBranches:w,remoteBranches:T,query:z}),[w,T,z]),se=Z.useMemo(()=>jS({localBranches:w,remoteBranches:T,query:V}),[w,T,V]),ce=z.trim().length>0,le=V.trim().length>0,ue=oe.matching.length>0,de=se.matching.length>0,fe=!!(p&&o),pe=Z.useCallback(()=>{!p||!o||C(p,o)},[p,o,C]);Z.useEffect(()=>{!e||!p||!o||x?.all||C(p,o)},[e,p,o,x?.all,C]),Z.useEffect(()=>{!j&&!F&&B(``)},[j,F]),Z.useEffect(()=>{!N&&!L&&H(``)},[N,L]),Z.useEffect(()=>{j&&ie(U),F&&ae(ee)},[j,F,z,ie,ae]),Z.useEffect(()=>{N&&ie(W),L&&ae(te)},[N,L,V,ie,ae]);let[me,he]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[ge,_e]=Z.useState(!1),[ve,ye]=Z.useState(null),be=Z.useCallback(()=>{let e=Ko.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),xe=Z.useCallback(()=>{let e=Ko.getState(),t=e.settingsDefaultModel??(e.currentModelId?void 0:e.opencodeDefaultModel);if(!t)return null;let n=Po(t);if(!n)return null;let{providerId:r,modelId:i}=n;return{providerID:r,modelID:i}},[]),Se=Z.useCallback((e,t)=>{let n=Ko.getState(),r=Po(n.settingsDefaultModel??n.opencodeDefaultModel),i=r?.providerId===e&&r.modelId===t?r.variant??n.settingsDefaultVariant:void 0,a=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0;return i??a},[]),Ce=Z.useCallback(async e=>{if(!p||!a)return;let t=Ko.getState(),n=ur.getState().lastUsedProvider,r=xe(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=be()||t.currentAgentName||void 0;if(!o||!s){ji.error(i(`session.newWorktree.error.noModelSelected`));return}let l=Se(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await za(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await za(`github.issue.review.instructions`),d=zS({repo:t.repo,issue:t.issue,comments:n.comments??[]});await wa.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),ji.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(p,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await za(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await za(`github.pr.review.instructions`),u=BS(t);await wa.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),ji.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,p,be,xe,Se,i]),we=h===`new-branch`?_:y;Z.useEffect(()=>{if(!e||!x?.all||!p||_.sourceBranch)return;let t=_.sourceBranch,n=!1;return(async()=>{try{let e=await Ns(p).catch(()=>null);if(n)return;let r=localStorage.getItem(Ql),{sourceBranch:i,shouldClearSavedSourceBranch:a}=cu({branches:x.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Ql),n||t)return;i&&v(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,x?.all,p,_.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;g(`new-branch`),b({selectedBranch:``,worktreeName:``}),M(!1),P(!1),I(!1),R(!1),B(``),H(``),he({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=O();v({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,O]),Z.useEffect(()=>{if(h!==`new-branch`||!_.isSyncingWorktreeName)return;let e=IS(FS(_.branchName));v(t=>({...t,worktreeName:e}))},[h,_.branchName,_.isSyncingWorktreeName]);let Te=Z.useCallback(async()=>{if(!m||!me.touched||ge)return;ve&&ve.abort();let e=new AbortController;ye(e),he(e=>({...e,isValidating:!0}));try{let t=h===`new-branch`?_.branchName:y.selectedBranch,n=we.worktreeName,r=FS(t),a=IS(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=h===`new-branch`?_.linkedPr:null,n=t?RS(t,w,T):null,i=await Hs(m,{mode:h===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(h===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||he(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||he(e=>({...e,isValidating:!1}))}},[m,h,_.branchName,_.linkedPr,y.selectedBranch,we.worktreeName,w,T,me.touched,ve,ge,i]),Ee=h===`new-branch`?_.branchName:y.selectedBranch;Z.useEffect(()=>{if(!e||!m||!me.touched||ge)return;let t=setTimeout(()=>{Te()},300);return()=>clearTimeout(t)},[we.worktreeName,Ee,e,m,Te,me.touched,ge]);let De=async()=>{if(!m||!p){ji.error(i(`session.newWorktree.error.noActiveProject`));return}he(e=>({...e,touched:!0}));let e=h===`new-branch`?_.branchName:y.selectedBranch,r=we.worktreeName,a=FS(e),o=IS(r);if(!a){ji.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){ji.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}ve&&(ve.abort(),ye(null)),he(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),_e(!0);try{let e=h===`new-branch`?_.linkedPr:null,r=h===`new-branch`?_.linkedIssue:null,s=h===`new-branch`?_.linkedPr:null,c=h===`new-branch`&&_.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([fo(m),ou(p)]),f=_.sourceBranch,g=``,v=(()=>{if(e){let t=RS(e,w,T);return g=t.sourceLabel,{preferredName:a||o,mode:`existing`,branchName:a,worktreeName:o,existingBranch:t.existingBranch,setupCommands:u,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return g=h===`new-branch`?f:``,{preferredName:a||o,mode:h===`existing-branch`?`existing`:`new`,branchName:h===`existing-branch`?void 0:a,worktreeName:o,existingBranch:h===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&h===`new-branch`?{startRef:f}:{}}})(),b=await pu(p,v,{resolvedRootTrackingRemote:d}),x=await Bs(m,b),S=null;if(l){await Oo(m)&&await Ha(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await qa(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),_e(!1),Ba(a.id,e).catch(()=>void 0);try{wa.getState().initializeNewYuriSession(a.id,Ko.getState().agents)}catch{}}else t(!1),_e(!1);let C=du({mode:h,sourceBranch:_.sourceBranch,linkedPr:!!_.linkedPr,selectedBranch:y.selectedBranch});C&&localStorage.setItem(Ql,C),ji.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${g?` ${i(`session.newWorktree.fromSource`,{source:g})}`:``}`})}),S?Ce({sessionId:S,directory:x.path,issue:r,pr:s,includeDiff:c}).catch(e=>{let t=e instanceof Error?e.message:i(`session.newWorktree.error.sendGitHubContextFailed`);ji.error(i(`session.newWorktree.error.sendGitHubContextFailed`),{description:t})}):n?.(x.path)}catch(e){let t=e instanceof Error?e.message:i(`session.newWorktree.error.createWorktreeFailed`);ji.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{_e(!1)}},Oe=e=>{g(e),he(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},ke=e=>{if(!e){v(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${Ix()}`;v(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:IS(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;v(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:IS(t.head),isSyncingWorktreeName:!0}))}},Ae=d&&u?.connected===!0,je=(h===`existing-branch`?!!y.selectedBranch&&!!y.worktreeName&&!me.branchError&&!me.worktreeError:!!FS(_.branchName)&&!!_.worktreeName&&!me.branchError&&!me.worktreeError)&&!ge,Me=()=>{v(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Ne=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,s?`w-full justify-center order-first`:`mr-auto`),children:me.touched&&(me.branchError||me.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:me.branchError||me.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s&&`w-full`),children:[(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,className:Y(s&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(er,{size:`sm`,onClick:De,disabled:!je||ge,className:Y(`gap-1.5`,s&&`flex-1`),children:[ge&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(ge?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[s?(0,$.jsx)(fl,{id:`new-worktree-sheet-${c}`,open:e,onOpenChange:t,title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(Xu,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`overscroll-contain px-4 pb-4 pt-2`,children:[(0,$.jsx)(`div`,{className:`w-full mb-4`,children:(0,$.jsx)(rf,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>Oe(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>I(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:y.selectedBranch?`text-foreground`:`text-muted-foreground`,children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(er,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(zc,{open:F,title:i(`session.newWorktree.selectBranch`),onClose:()=>I(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:ee,children:[(0,$.jsx)(Ks,{value:z,onChange:e=>B(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ce&&ue&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:IS(e.label)})),he(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),oe.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&Ae&&(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Ks,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=IS(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===IS(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===IS(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Ks,{value:we.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,me.touched&&me.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>R(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:_.sourceBranch?`text-foreground`:`text-muted-foreground`,children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})}),(0,$.jsx)(zc,{open:L,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>R(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:te,children:[(0,$.jsx)(Ks,{value:V,onChange:e=>H(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[le&&de&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:e.value})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),le&&!de&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),se.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:e})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),se.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:Me,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Ne})]})}):(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsxs)(_s,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(hs,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-5 w-5`}),i(`session.newWorktree.title`)]}),(0,$.jsx)(`div`,{className:`w-[280px] shrink-0`,children:(0,$.jsx)(rf,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>Oe(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(Bc,{open:j,onOpenChange:M,children:[(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsxs)(er,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,y.selectedBranch?`text-foreground`:`text-muted-foreground`),children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(kc,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:U,children:(0,$.jsxs)(rS,{shouldFilter:!1,children:[(0,$.jsx)(iS,{placeholder:i(`session.newWorktree.searchBranches`),value:z,onValueChange:B,onKeyDown:ne}),(0,$.jsx)(aS,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(oS,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(sS,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(lS,{value:e.value,onSelect:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:IS(e.label)})),he(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[ce&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(lS,{value:e,onSelect:()=>{b(t=>({...t,selectedBranch:e,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),oe.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(oe.otherLocal.length>0||ce)&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(lS,{value:`remotes/${e}`,onSelect:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:IS(e)})),he(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(er,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&Ae&&(0,$.jsxs)(er,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Ks,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=IS(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===IS(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===IS(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Ks,{value:we.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,me.touched&&me.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(Bc,{open:N,onOpenChange:P,children:[(0,$.jsx)(Hc,{asChild:!0,children:(0,$.jsxs)(er,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,_.sourceBranch?`text-foreground`:`text-muted-foreground`),children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(kc,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:W,children:(0,$.jsxs)(rS,{shouldFilter:!1,children:[(0,$.jsx)(iS,{placeholder:i(`session.newWorktree.searchBranches`),value:V,onValueChange:H,onKeyDown:ne}),(0,$.jsx)(aS,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(oS,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[le&&de&&(0,$.jsx)(sS,{heading:i(`session.newWorktree.matchingBranches`),children:se.matching.map(e=>(0,$.jsx)(lS,{value:e.value,onSelect:()=>{v(t=>({...t,sourceBranch:e.value})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),le&&!de&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),se.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[le&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:se.otherLocal.map(e=>(0,$.jsx)(lS,{value:e,onSelect:()=>{v(t=>({...t,sourceBranch:e})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),se.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(se.otherLocal.length>0||le)&&(0,$.jsx)(cS,{}),(0,$.jsx)(sS,{heading:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:se.otherRemote.map(e=>(0,$.jsx)(lS,{value:`remotes/${e}`,onSelect:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:Me,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)(gs,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:me.touched&&(me.branchError||me.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:me.branchError||me.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(er,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(er,{size:`sm`,onClick:De,disabled:!je||ge,className:`gap-1.5`,children:[ge&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(ge?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(NS,{open:k,onOpenChange:A,onSelect:ke})]})}function HS(e){let t=e.selectedDirectory??e.projectRootOption?.value??e.worktreeOptions[0]?.value??null;return t?e.projectRootOption?.value===t?e.projectRootOption.label?.trim()||null:e.worktreeOptions.find(e=>e.value===t)?.label?.trim()||null:null}function US(e,t){if(!e||!t)return!1;let n=t.replace(/\\/g,`/`).replace(/\/+$/,``);if(!n)return!1;let r=n===`/`?`/`:n.split(`/`).pop()||``;return!!r&&e===r}var WS=(e,t)=>e??t??null,GS=(e,t)=>!!e&&t!==!1,KS=e=>e?.length?{localBranches:e.filter(e=>!e.startsWith(`remotes/`)).sort(),remoteBranches:e.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort()}:{localBranches:[],remoteBranches:[]},qS=e=>e.replace(/^remotes\//,``).trim(),JS=e=>{let t=qS(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},YS=({directory:e,projectDirectory:t,label:n,projectRootOption:r,worktreeOptions:i,onSelectDirectory:a,className:o,maxWidthClassName:s=`max-w-[48vw] sm:max-w-[20rem]`,presentation:c=`dropdown`})=>{let{t:l}=Xn(),{git:u}=On(),d=WS(t,e),f=e,p=$l(d),m=$l(f),h=GS(d,p),g=f!==d&&GS(f,m),_=Xl(d,u,h),v=Xl(f,u,g),y=_.data,b=f===d?y:v.data,x=gu(e=>e.fetchStatus),S=gu(e=>f&&e.directories.get(f)?.status?.current?.trim()||null),[C,w]=Z.useState(!1),T=Kl(d,u,h&&C).data??[],[E,D]=Z.useState(null),[O,k]=Z.useState(!1),[A,j]=Z.useState(!1),M=Ia(e=>e.projects),N=Ia(e=>e.activeProjectId);Z.useEffect(()=>{u&&(d&&p===null&&x(d,u,{silent:!0}),f&&f!==d&&m===null&&x(f,u,{silent:!0}))},[x,u,p,m,d,f]);let P=Z.useMemo(()=>{let e=Fn(t);if(e){let t=M.find(t=>Fn(t.path)===e);if(t)return t.id}return N},[N,t,M]),{localBranches:F,remoteBranches:I}=Z.useMemo(()=>KS(y?.all),[y]),L=b?.current?.trim()||S||null,R=!US(n,e)&&n||L||n||l(`chat.chatInput.branch`),z=J(async()=>{if(!u)return;let e=new Set;d&&e.add(d),f&&e.add(f),await Promise.all([...e].map(async e=>{await hu(e,u),await x(e,u,{silent:!0})}))}),B=J(e=>{let t=qS(e),n=JS(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),V=J(async e=>{if(!f||!u)return;let t=qS(e);if(L!==t&&L!==JS(t))try{await u.checkoutBranch(f,t),ji.success(l(`gitView.toast.checkedOut`,{name:t})),await z()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});ji.error(n)}}),H=J(e=>{let t=qS(e);if(!t||L===t||L===JS(t))return;let n=B(t);if(n){a(n.value);return}D(t)}),U=J(async()=>{if(!(!E||O)){k(!0);try{await V(E),D(null)}finally{k(!1)}}}),W=J(async()=>{if(!(!E||O)){k(!0);try{await Yx({branch:E,projectDirectory:t??void 0})&&D(null)}finally{k(!1)}}}),ee=J(async(e,t)=>{if(!f||!u)return;let n=t?.name??`origin`;try{await u.createBranch(f,e,L??`HEAD`),ji.success(l(`gitView.toast.createdBranch`,{name:e})),D(e),u.gitPush(f,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await z(),ji.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);ji.warning(l(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:t})}),await z()})}catch(e){let t=e instanceof Error?e.message:l(`gitView.toast.createBranchFailed`);throw ji.error(t),e}}),te=J(()=>{let e=Ia.getState(),n=Fn(t),r=n?e.projects.find(e=>Fn(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),j(!0)}),ne=J((e,n)=>{if(j(!1),n?.sessionId){wa.getState().setCurrentSession(n.sessionId,e);return}let r=Ia.getState(),i=Fn(t),a=(i?r.projects.find(e=>Fn(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=wa.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),le.getState().setDirectory(e,{showOverlay:!1});return}o.openNewSessionDraft({...a?{selectedProjectId:a}:{},directoryOverride:e,preserveDirectoryOverride:!0})}),re=(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex min-w-0 w-fit items-center gap-1.5 rounded-lg !border-0 px-1.5 font-medium text-foreground/80`,c===`mobile-sheet`?`h-[26px] text-[11px] leading-none`:`h-6 py-1 pr-1.5 typography-micro transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5`,s,dy,o),"aria-label":R,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:R}),c===`dropdown`?(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`}):null]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(AS,{currentBranch:L,localBranches:F,remoteBranches:I,branchInfo:y?.branches,onCheckout:H,onCreate:ee,remotes:T,trigger:re,triggerLabel:R,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:te,open:C,presentation:c,onOpenChange:w}),A?(0,$.jsx)(VS,{open:!0,projectId:P,onOpenChange:j,onWorktreeCreated:ne}):null,(0,$.jsx)(xs,{open:!!E,onOpenChange:e=>{!e&&!O&&D(null)},children:(0,$.jsxs)(_s,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(hs,{children:[(0,$.jsx)(vs,{children:l(`chat.chatInput.branchSwitch.title`,{branch:E??``})}),(0,$.jsx)(ys,{children:l(`chat.chatInput.branchSwitch.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:O,onClick:()=>{U()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[O?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-left-right`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.checkoutHere`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.checkoutHereDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,disabled:O,onClick:()=>{W()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[O?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.createWorktree`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.createWorktreeDescription`)})]})]}),(0,$.jsx)(gs,{children:(0,$.jsx)(`button`,{type:`button`,disabled:O,onClick:()=>D(null),className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 disabled:opacity-50`,children:l(`chat.chatInput.branchSwitch.cancel`)})})]})})]})},XS=[],ZS=[],QS={revertMessageID:void 0,records:ZS},$S=e=>e.role===`user`,eC=(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||e[n]?.parts!==t[n]?.parts)return!1;return!0},tC=(e,t,n=QS)=>{if(!t)return QS;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return QS;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!$S(e)||!Se(i,e.id,r)||o.push({message:e,parts:a[e.id]??XS});let s=o.length===0?ZS:o;return n.revertMessageID===r&&eC(n.records,s)?n:{revertMessageID:r,records:s}},nC=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],rC=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),iC=e=>{if(/[\r\n]/.test(e)||!/\s/.test(e))return!1;let t=e.replace(/\\/g,`/`);if(!(t.startsWith(`//`)?t.replace(/^\/+/,``).includes(`/`):/^[A-Za-z]:\//.test(t)?t.slice(3).includes(`/`):t.startsWith(`/`)&&t.slice(1).includes(`/`)))return!1;if(t.endsWith(`/`))return!0;let n=t.split(`/`).filter(Boolean).pop()??``;return/\.[A-Za-z0-9]{1,8}$/.test(n)},aC=e=>{if(!rC(e))return!1;if(/\s/.test(e))return iC(e);if(e.startsWith(`//`)||e.startsWith(`\\\\`)){let t=e.replace(/^[\\/]+/,``);return/[\\/]/.test(t)}if(/^[A-Za-z]:[\\/]/.test(e)){let t=e.slice(3);return t.includes(`\\`)||t.includes(`/`)||t.includes(`.`)}return e.replace(/^\/+/,``).includes(`/`)},oC=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?aC(n):rC(n))?n:null},sC=(e,t,n=0)=>{if(!(n>6||e==null)){if(typeof e==`string`){t.add(e);return}if(Array.isArray(e)){for(let r of e)sC(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))sC(r,t,n+1)}},cC=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=oC(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=oC(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;sC(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},lC=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of nC){let r=``;try{r=e.getData(n)}catch{continue}let i=n===`text/plain`?{allowMultipleLines:!1,allowStructuredPayload:!1,fromPlainText:!0}:n===`text/uri-list`?{allowStructuredPayload:!1}:void 0;for(let e of cC(r,i))t.add(e)}return Array.from(t)},uC=e=>{let t=e.trim();if(!t.toLowerCase().startsWith(`file://`))return t;try{let e=new URL(t),n=decodeURIComponent(e.pathname||``);return e.hostname&&e.hostname!==`localhost`&&(n=`//${e.hostname}${n}`),/^\/[A-Za-z]:\//.test(n)&&(n=n.slice(1)),n||t}catch{let e=t.replace(/^file:\/\//i,``);try{return decodeURIComponent(e)}catch{return e}}},dC=e=>rC(e);function fC(e,t){let n=(0,Q.c)(5),r=cr(e,t),i=K(pC),a;n[0]===r?a=n[1]:(a=ii(r),n[0]=r,n[1]=a);let o;return n[2]!==i||n[3]!==a?(o={goal:a,enabled:i},n[2]=i,n[3]=a,n[4]=o):o=n[4],o}function pC(e){return e.sessionGoalEnabled}function mC(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(null),a=t?.objectiveFile?`${e}:${t.id}:${t.updatedAt}`:``,o,s;return n[0]!==a||n[1]!==e?(o=()=>{if(!a){i(null);return}let t=!0;return wr(e).then(e=>{t&&i(e)}),()=>{t=!1}},s=[a,e],n[0]=a,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),t?t.objectiveFile?r:t.objective:null}var hC={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},gC={active:`chat.goal.status.active`,paused:`chat.goal.status.paused`,blocked:`chat.goal.status.blocked`,budgetLimited:`chat.goal.status.budgetLimited`,complete:`chat.goal.status.complete`},_C=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=Xn(),i=K(e=>e.isMobile),{goal:a,enabled:o}=fC(e??``,t),s=mC(e??``,a),c=vo(e??``,t),l=Di(e,t),u=Z.useRef(null),[d,f]=Z.useState(!1),[p,m]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=l[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;u.current!==r&&(u.current=r,br(e,t))},[e,t,a,l]);let h=J(async n=>{if(!(!e||d)){f(!0);try{await pi(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),ji.error(r(`chat.goal.toast.actionFailed`))}finally{f(!1)}}});if(!e||!o||!a)return null;let g=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:p)-(a.createdAt||p)),_=lr(g),v=a.tokenBudget?`${Xa(a.tokensUsed)}/${Xa(a.tokenBudget)}`:a.tokensUsed>0?Xa(a.tokensUsed):null,y=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,b=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,x=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,S=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(S,`flex-shrink-0`),style:{color:hC[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,x),children:a.note||s||``}),a.status===`active`&&(!c||c.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,b),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(S,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,b),children:r(gC[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:_}),v?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:v}):null,y?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(y.next),disabled:d,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(y.labelKey),children:[(0,$.jsx)(X,{name:y.icon,className:S,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(y.labelKey)})]}):null]})});_C.displayName=`SessionGoalRow`;var vC=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=Xn(),{goal:i,enabled:a}=fC(e??``,t),o=Or(e=>e.armed),s=Or(e=>e.setArmed),[c,l]=Z.useState(!1);if(p()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,d=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Fi(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),ji.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void d(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});vC.displayName=`SessionGoalButton`;var yC=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=Xn();if(!Or(bC)||n===0)return null;let i=n>5e3?`text-[var(--status-error)]`:`text-muted-foreground/70`,a;t[0]===i?a=t[1]:(a=Y(`flex-shrink-0 self-center typography-micro tabular-nums`,i),t[0]=i,t[1]=a);let o;t[2]===r?o=t[3]:(o=r(`chat.goal.counter.aria`),t[2]=r,t[3]=o);let s;t[4]===r?s=t[5]:(s=r(`chat.goal.counter.aria`),t[4]=r,t[5]=s);let c;return t[6]!==n||t[7]!==a||t[8]!==o||t[9]!==s?(c=(0,$.jsxs)(`span`,{className:a,"aria-label":o,title:s,children:[n,`/`,eo]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});yC.displayName=`SessionGoalObjectiveCounter`;function bC(e){return e.armed}var xC=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`,`btw`]),SC=new Set([`new`,`compact`,`reload`,`fork`,`undo`,`redo`]),CC=/^\/\u2003?([^\s]+)/i,wC=/^\/\u2003?goal\b/i,TC=e=>e?.reloadEnabled??p(),EC=(e,t,n)=>{if(t!==`normal`)return null;let r=e.trimStart().match(CC)?.[1]?.toLowerCase();return!r||!xC.has(r)||r===`reload`&&!TC(n)?null:r},DC=(e,t,n)=>EC(e,t,n)===`goal`?e.trimStart().replace(wC,``).trim():null,OC=(e,t,n)=>EC(e,t,n)!==null,kC=(e,t,n)=>{let r=EC(e,t,n);return r!==null&&SC.has(r)};function AC(e){if(EC(e.text,e.inputMode)!==`btw`)return!1;if(!e.allowed)return!0;if(!e.scope?.sessionId)return e.notify(`sessionRequired`),!0;if(e.hasReferences)return e.notify(`plainTextRequired`),!0;let t=e.text.trimStart().replace(/^\/\u2003?btw(?:\s|$)/i,``).trim();return t&&e.ask(e.scope,t),e.clearText(),e.open(),!0}var jC=[`The user is asking a quick side question about the conversation so far.`,`Answer directly and concisely in markdown from what you already know.`,`Do not call any tools and do not take any actions.`].join(` `),MC=40,NC=Object.freeze({turns:Object.freeze([]),quotes:Object.freeze([])}),PC=e=>{let t=typeof e.sessionId==`string`?e.sessionId.trim():``,n=In(e.directory);return`${o()}\u0000${n}\u0000${t}`},FC=new Map,IC=[],LC=0,RC=0,zC=e=>e instanceof Error&&e.message.trim()?e.message:typeof e==`string`&&e.trim()?e:`session.btw failed`,BC=(e,t)=>t.aborted?!0:!e||typeof e!=`object`?!1:(`name`in e?e.name:void 0)===`AbortError`,VC=(e,t)=>FC.get(e)?.controller===t,HC=e=>!!e?.turns.some(e=>e.pending),UC=e=>{IC=IC.filter(t=>t!==e),IC.push(e)},WC=e=>{FC.get(e)?.controller.abort(),FC.delete(e)},GC=(e,t)=>{let n=Object.keys(e);if(n.length<=MC)return e;let r={...e},i=IC.filter(e=>e in r);for(let e of n)i.includes(e)||i.push(e);let a=e=>e!==t&&r[e]!==void 0&&!HC(r[e]);for(;Object.keys(r).length>MC;){let e=i.find(a)??i.find(e=>e!==t);if(!e)break;delete r[e],WC(e);let n=i.indexOf(e);n>=0&&i.splice(n,1)}return IC=i.filter(e=>e in r),r},KC=(e,t)=>{dw.setState(n=>{let r=n.entries[e]??NC,i=t(r);return!i||i===r?n:(UC(e),{entries:GC({...n.entries,[e]:i},e)})})},qC=(e,t)=>{KC(e,e=>{let n=t(e.turns);return!n||n===e.turns?null:{...e,turns:n}})},JC=(e,t,n)=>{dw.getState().entries[e]&&qC(e,e=>{let r=e.findIndex(e=>e.id===t);if(r<0)return null;let i=e.slice();return i[r]={...e[r],...n},i})},YC=e=>e.split(`
|
|
6533
6533
|
`).map(e=>`> ${e}`).join(`
|
|
6534
6534
|
`),XC=e=>e.quotes.length===0?e.question:[`Quoted from the conversation:`,...e.quotes.map(YC),e.question].join(`
|
|
6535
6535
|
|
|
@@ -6539,8 +6539,8 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}f
|
|
|
6539
6539
|
|
|
6540
6540
|
`),`Follow-up question:`,XC(t)].join(`
|
|
6541
6541
|
|
|
6542
|
-
`)},QC=(e,t,n,r,i)=>{if(VC(e,n)&&LC===r.epoch){if(o()!==r.transport||c()!==r.generation){JC(e,t,{pending:!1});return}JC(e,t,i)}},$C=e=>{let t=typeof e.sessionId==`string`?e.sessionId.trim():``;return t?{sessionId:t,directory:typeof e.directory==`string`&&e.directory.trim()?e.directory:e.directory??null}:null},ew=e=>{let t=FC.get(e);t&&(WC(e),JC(e,t.turnId,{pending:!1}))},tw=e=>{let t=$C(e);if(!t)return null;let n=PC(t),r=dw.getState().sendSelection[n];if(r?.providerID&&r?.modelID)return r;let i=ur.getState().getSessionModelSelection(t.sessionId);if(i)return{providerID:i.providerId,modelID:i.modelId,agent:ur.getState().getSessionAgentSelection(t.sessionId)??void 0};let a=Ko.getState();return a.currentProviderId&&a.currentModelId?{providerID:a.currentProviderId,modelID:a.currentModelId,agent:a.currentAgentName??void 0,variant:a.currentVariant??null}:null},nw=async e=>{let t=tw({sessionId:e.sessionId,directory:e.directory});if(!t)return;let n=typeof t.variant==`string`&&t.variant.trim()?t.variant.trim():void 0;await Te.applySendSelection(e.sessionId,{model:{providerID:t.providerID,id:t.modelID,...n?{variant:n}:{}},...t.agent?{agent:t.agent}:{}},e.directory)},rw=(e,t)=>{let n=$C(e);if(!n)return;let r=PC(n);dw.setState(e=>({sendSelection:{...e.sendSelection,[r]:t}})),ur.getState().saveSessionModelSelection(n.sessionId,t.providerID,t.modelID),t.agent&&ur.getState().saveSessionAgentSelection(n.sessionId,t.agent)},iw=async(e,t,n,r)=>{let i=n.id,a={epoch:LC,transport:o(),generation:c()},s=new AbortController;FC.set(t,{controller:s,turnId:i});try{if(await nw(e),!VC(t,s))return;let o=await Te.generateSessionAside({sessionId:e.sessionId,directory:e.directory,prompt:ZC(r,n),signal:s.signal}),c=typeof o?.text==`string`?o.text.trim():``;QC(t,i,s,a,c?{answer:c,error:null,pending:!1}:{answer:``,error:`empty response`,pending:!1})}catch(e){QC(t,i,s,a,BC(e,s.signal)?{pending:!1}:{error:zC(e),pending:!1})}finally{VC(t,s)&&FC.delete(t)}},aw=async(e,t)=>{let n=typeof t==`string`?t.trim():``,r=$C(e);if(!n||!r)return;let i=PC(r);ew(i);let a=dw.getState().entries[i]??NC;RC+=1;let o={id:`btw_${RC}`,quotes:a.quotes,question:n,answer:``,error:null,pending:!0};KC(i,e=>({turns:[...e.turns,o].slice(-50),quotes:NC.quotes})),await iw(r,i,o,a.turns)},ow=async e=>{let t=$C(e);if(!t)return;let n=PC(t),r=dw.getState().entries[n]?.turns??[],i=r[r.length-1];i&&(ew(n),JC(n,i.id,{answer:``,error:null,pending:!0}),await iw(t,n,i,r.slice(0,-1)))},sw=(e,t)=>{let n=typeof t==`string`?t.trim():``;!n||!$C(e)||KC(PC(e),e=>e.quotes.includes(n)?null:{...e,quotes:[...e.quotes,n].slice(-10)})},cw=(e,t)=>{let n=PC(e);dw.getState().entries[n]&&KC(n,e=>t<0||t>=e.quotes.length?null:{...e,quotes:e.quotes.filter((e,n)=>n!==t)})},lw=e=>{ew(PC(e))},uw=e=>{let t=PC(e);WC(t),IC=IC.filter(e=>e!==t),dw.setState(e=>{let n=t in e.entries,r=t in e.sendSelection;if(!n&&!r)return e;let i=n?{...e.entries}:e.entries,a=r?{...e.sendSelection}:e.sendSelection;return n&&delete i[t],r&&delete a[t],{entries:i,sendSelection:a}})},dw=L(()=>({entries:{},sendSelection:{},setSendSelection:rw,ask:aw,retry:ow,cancel:lw,addQuote:sw,removeQuote:cw,clear:uw})),fw=()=>{LC+=1;for(let{controller:e}of FC.values())e.abort();FC.clear(),IC=[],dw.setState({entries:{},sendSelection:{}})},pw=(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()}}}})(wu),mw=new Map,hw=e=>pw.hold(e),gw=e=>{mw.has(e)||mw.set(e,pw.hold(e))},_w=e=>{let t=mw.get(e);t&&(mw.delete(e),t())},vw=`btw-page`,yw=`btw-sheet`,bw=`text-selection`,xw=`1.5rem`,Sw=`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`,Cw=`box-border w-full whitespace-pre-wrap break-words px-3 py-2.5 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit]`;function ww(e){let t=(0,Q.c)(40),{turn:n,isLast:r,scope:i}=e,{t:a}=Xn(),o;t[0]!==a||t[1]!==n.error?(o=n.error===`empty response`||n.error===`session.btw failed`?a(`chat.btw.failed`):n.error,t[0]=a,t[1]=n.error,t[2]=o):o=t[2];let s=o,c=!n.pending&&!n.error&&!n.answer,l;t[3]!==a||t[4]!==n.answer?(l=async()=>{(await Yn(n.answer)).ok?ji.success(a(`contextSidebar.actions.copied`)):ji.error(a(`filesView.toast.copyFailed`))},t[3]=a,t[4]=n.answer,t[5]=l):l=t[5];let u=J(l),d=n.id,f;t[6]===n.quotes?f=t[7]:(f=n.quotes.map(Tw),t[6]=n.quotes,t[7]=f);let p;t[8]===n.question?p=t[9]:(p=(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words typography-markdown text-foreground`,children:n.question}),t[8]=n.question,t[9]=p);let m;t[10]!==f||t[11]!==p?(m=(0,$.jsxs)(`div`,{className:`ml-8 flex flex-col gap-1.5 self-end rounded-xl bg-[var(--surface-elevated)] px-3 py-2`,children:[f,p]}),t[10]=f,t[11]=p,t[12]=m):m=t[12];let h;t[13]!==a||t[14]!==n.pending?(h=n.pending?(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),a(`chat.btw.pending`)]}):null,t[13]=a,t[14]=n.pending,t[15]=h):h=t[15];let g;t[16]===s?g=t[17]:(g=s?(0,$.jsxs)(`p`,{role:`alert`,className:`whitespace-pre-wrap break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`mr-1.5 inline size-3.5 align-[-2px] text-[var(--status-error)]/85`,"aria-hidden":`true`}),s]}):null,t[16]=s,t[17]=g);let _;t[18]!==c||t[19]!==a?(_=c?(0,$.jsx)(`p`,{role:`status`,className:`typography-meta text-muted-foreground`,children:a(`chat.btw.cancelled`)}):null,t[18]=c,t[19]=a,t[20]=_):_=t[20];let v;t[21]===n.answer?v=t[22]:(v=n.answer?(0,$.jsx)(`div`,{className:`min-w-0 text-foreground`,children:(0,$.jsx)(Gu,{content:n.answer,enableFileReferences:!1})}):null,t[21]=n.answer,t[22]=v);let y;t[23]!==c||t[24]!==u||t[25]!==s||t[26]!==r||t[27]!==i||t[28]!==a||t[29]!==n.answer||t[30]!==n.pending?(y=!n.pending&&(n.answer||r&&(s||c))?(0,$.jsxs)(`div`,{className:`-ml-2 flex items-center gap-0.5`,children:[n.answer?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:u,"aria-label":a(`contextSidebar.actions.copy`),children:(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`})}):null,r?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:()=>void dw.getState().retry(i),"aria-label":a(`contextPanel.preview.actions.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`})}):null]}):null,t[23]=c,t[24]=u,t[25]=s,t[26]=r,t[27]=i,t[28]=a,t[29]=n.answer,t[30]=n.pending,t[31]=y):y=t[31];let b;return t[32]!==v||t[33]!==y||t[34]!==m||t[35]!==h||t[36]!==g||t[37]!==_||t[38]!==n.id?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-btw-turn":d,children:[m,h,g,_,v,y]}),t[32]=v,t[33]=y,t[34]=m,t[35]=h,t[36]=g,t[37]=_,t[38]=n.id,t[39]=b):b=t[39],b}function Tw(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 Ew(e){let t=(0,Q.c)(64),{scope:n,pending:r,quotes:i,foot:a}=e,{t:o}=Xn(),s;t[0]===n?s=t[1]:(s=e=>e.sendSelection[PC(n)],t[0]=n,t[1]=s);let c=dw(s),l;t[2]!==n||t[3]!==c?(l=c??tw(n),t[2]=n,t[3]=c,t[4]=l):l=t[4];let u=l,d=Ko(Dw),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(``),dw.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)(Os,{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=()=>dw.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:xw},t[35]=I):I=t[35];let L=C?Cw:Sw,R;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(R={borderTopLeftRadius:xw,borderTopRightRadius:xw},t[36]=R):R=t[36];let z;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(z={borderBottomLeftRadius:xw,borderBottomRightRadius:xw},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=>dw.getState().removeQuote(n,e),t[40]=n,t[41]=V);let H;t[42]!==i||t[43]!==B||t[44]!==V?(H=(0,$.jsx)(Wh,{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)(zl,{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 Dw(e){return e.providers}function Ow(e){let t=(0,Q.c)(29),{scope:n,foot:r}=e,i=r===void 0?`panel`:r,{t:a}=Xn(),o;t[0]===n?o=t[1]:(o=PC(n),t[0]=n,t[1]=o);let s=o,c;t[2]===s?c=t[3]:(c=e=>(e.entries[s]??NC).turns,t[2]=s,t[3]=c);let l=dw(c),u;t[4]===s?u=t[5]:(u=e=>(e.entries[s]??NC).quotes,t[4]=s,t[5]=u);let d=dw(u),f;t[6]===l?f=t[7]:(f=l.some(kw),t[6]=l,t[7]=f);let p=f,m=Z.useRef(null),h=l[l.length-1],g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},t[8]=g):g=t[8];let _=h?.answer,v=h?.pending,y;t[9]!==_||t[10]!==v||t[11]!==l.length?(y=[l.length,_,v],t[9]=_,t[10]=v,t[11]=l.length,t[12]=y):y=t[12],Z.useLayoutEffect(g,y);let b;t[13]===a?b=t[14]:(b=a(`chat.btw.title`),t[13]=a,t[14]=b);let x;t[15]!==n||t[16]!==a||t[17]!==l?(x=(0,$.jsx)(`div`,{ref:m,className:`overlay-scrollbar-container min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-3`,children:l.length===0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:a(`chat.btw.description`)}):(0,$.jsx)(`div`,{className:`flex flex-col gap-5`,children:l.map((e,t)=>(0,$.jsx)(ww,{turn:e,isLast:t===l.length-1,scope:n},e.id))})}),t[15]=n,t[16]=a,t[17]=l,t[18]=x):x=t[18];let S;t[19]!==i||t[20]!==s||t[21]!==p||t[22]!==d||t[23]!==n?(S=(0,$.jsx)(Ew,{scope:n,pending:p,quotes:d,foot:i},s),t[19]=i,t[20]=s,t[21]=p,t[22]=d,t[23]=n,t[24]=S):S=t[24];let C;return t[25]!==b||t[26]!==x||t[27]!==S?(C=(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-col text-foreground`,"aria-label":b,children:[x,S]}),t[25]=b,t[26]=x,t[27]=S,t[28]=C):C=t[28],C}function kw(e){return e.pending}function Aw(e){let t=(0,Q.c)(53),{scope:n,active:r,mobile:i}=e,{t:a}=Xn(),{sessionId:o,directory:s}=n,c;t[0]===n?c=t[1]:(c=PC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===s?u=t[3]:(u=In(s),t[2]=s,t[3]=u);let d=u,f;t[4]===d?f=t[5]:(f=e=>e.contextPanelByDirectory[d],t[4]=d,t[5]=f);let p=K(f),m;t[6]!==r||t[7]!==p?(m=r&&!!(p?.isOpen&&p.tabs.find(e=>e.id===p.activeTabId)?.mode===`btw`),t[6]=r,t[7]=p,t[8]=m):m=t[8];let h=m,g;t[9]===p?g=t[10]:(g=p?.isOpen&&p.tabs.some(Mw),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&&!_&&dw.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=()=>co({sessionId:o,directory:s??null});return!r&&!n()&&dw.getState().cancel(e),()=>{let r=dw.getState().entries[l];queueMicrotask(()=>{let i=S.current;i!==t&&i?.key===l&&i.active||n()||PC(e)===l&&dw.getState().entries[l]===r&&dw.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=()=>{dw.getState().clear(n),K.getState().closeContextPanel(d)},t[26]=d,t[27]=n,t[28]=T):T=t[28];let E=J(T),D,O;if(t[29]!==i||t[30]!==h?(D=()=>{if(!i||!h){_w(yw);return}return gw(yw),jw},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)(Ow,{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)(dl,{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 jw(){return _w(yw)}function Mw(e){return e.mode===`btw`}var Nw=()=>{typeof window>`u`||window.requestAnimationFrame(()=>{document.querySelector(`[data-btw-composer] textarea`)?.focus()})},Pw=e=>{let t=e.directory??null;To({sessionId:e.sessionId,directory:t})?gw(vw):K.getState().openContextPanelTab(t??``,{mode:`btw`}),Nw()},Fw=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Iw=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()}},Lw=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,Rw=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&e.delivery!==`queue`&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,zw=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},Bw=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Vw=(e,t)=>{let n=Mt.getState();return n.bindLegacyQueue(Nt(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},Hw=async e=>{let t=$a.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=Bw(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Vw(n,a)?r+=1:i+=1}catch{try{Vw(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Uw=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Ww=e=>{let t=e.ctrlEnter&&e.canQueue&&e.primary&&e.sessionIsRunning&&!e.autoReviewRunning;return e.followUpBehavior===`queue`?t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:e.primary?{kind:`submit`,delivery:`queue`}:e.queueUsable?{kind:`queue`}:{kind:`submit`,delivery:`steer`}:t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:{kind:`submit`,delivery:`steer`}},Gw=e=>Object.prototype.hasOwnProperty.call(e,`permissions`)?e.permissions:e.permission,Kw=e=>{let t=nc(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},qw=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Kw(Gw(e)));let r=e.find(e=>e?.name===n);return!r||Kw(Gw(r))},Jw=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)},Yw=null,Xw=new Set,Zw=()=>{for(let e of Xw)e()},Qw=e=>e===`chat`||e===`assistant`,$w=()=>Yw,eT=e=>{Yw!==e&&(Yw=e,Zw())},tT=e=>{Yw&&(e&&Yw.surfaceID!==e||(Yw=null,Zw()))},nT=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},rT=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}},iT=(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}),aT=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=iT(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=iT(e,`send`,i),o=Hy(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=iT(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=iT(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=iT(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Hy(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Fy(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=iT(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=iT(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},oT=(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)))},sT=(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},cT=(e,t)=>e.agents.some(e=>e.name===t),lT=(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},uT=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return lT(t,n,r,i)?i:void 0;if(a&&lT(t,n,r,a))return a},dT=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!sT(r,n.providerID,n.modelID))return null;let s=n.agent&&cT(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&cT(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&cT(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=uT({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}},fT=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=dT({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=dT({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&&cT(i,e)?e:s&&cT(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&sT(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&lT(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&&sT(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&lT(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&&sT(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&cT(i,o.agent)?o.agent:void 0)??(e&&cT(i,e)?e:s&&cT(i,s)?s:void 0),r=l.variant,c=r&&lT(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},pT=(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))},mT=(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}},hT=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,gT=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}:{}}},_T=e=>typeof e==`string`&&e.trim().length>0?e:void 0,vT=e=>_T(e.agent)??_T(e.mode),yT=e=>_T(typeof e.model==`object`?e.model?.variant:void 0)??_T(e.variant),bT=e=>{let t=typeof e.model==`object`?e.model:void 0,n=_T(e.providerID)??_T(t?.providerID),r=_T(e.modelID)??_T(t?.modelID)??_T(t?.id);return!n||!r?null:{providerID:n,modelID:r}},xT=e=>bT(e),ST=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=bT(n);return{id:typeof n.id==`string`?n.id:void 0,agent:vT(n),providerID:r?.providerID,modelID:r?.modelID,variant:yT(n)}}return null},CT=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(bT(n))return null;continue}if(n.role!==`assistant`)continue;let r=xT(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:vT(n),providerID:r.providerID,modelID:r.modelID,variant:yT(n)}}return null},wT=500,TT=e=>Array.from(e).length,ET=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},DT=e=>TT(e)>=wT,OT=e=>{let t=Wt(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},kT=(e,t)=>{let n=t??e;return typeof n!=`string`||!DT(n)?!1:Lt(typeof e==`string`?{text:``,references:[]}:e,n)},AT=(e,t,n,r,i=1)=>{let a=TT(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}-${ET(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},jT=e=>({text:e?.text??``,references:e?.composerReferences??[]}),MT=e=>({text:e.text,references:e.references.map(e=>({...e}))}),NT=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),PT=e=>JSON.stringify([e.text,e.references]),FT=(e,t)=>e!==null&&t!==null&&gn(e)===t,IT=(e,t,n)=>{let r=e?NT(e):null,i=r?n(r):void 0;return{document:Vt(jT(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?gn(r):null}},LT=(e,t,n,r)=>{if(!t||gn(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=PT(jT(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===PT(e)?`same-document-metadata`:`external-document`},RT=(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}]:[]})},zT=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),BT=(e,t,n,r,i=r)=>{let a=jt(e,n,r,i);return{document:a.document,mentions:RT(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},VT=(e,t,n)=>({preview:{real:MT(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),HT=e=>({document:e.real,mentions:e.realMentions}),UT=(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)})},WT=(e,t)=>{let n=jT(t),r=Ht(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:UT(e.mentions,t?.mentions??[],r,i)}},GT=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=va})=>{let a=e?gn(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)(()=>IT(e,t,i.getState().getDraft).document),[d,f]=(0,Z.useState)(()=>IT(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?NT(e):null),C=(0,Z.useRef)(a),w=(0,Z.useRef)(a),T=(0,Z.useRef)(0),E=(0,Z.useRef)(o?.revision??0),D=(0,Z.useRef)(void 0),O=(0,Z.useRef)(void 0),k=(0,Z.useRef)(Al());_.current=l,v.current=d,y.current=t,b.current=r,x.current=e,C.current=a;let A=(0,Z.useCallback)((e,t)=>{_.current=e,v.current=t,u(e),f(t)},[]),j=(0,Z.useCallback)((e,t)=>{let n=It(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=IT(x.current,y.current,i.getState().getDraft),n=t.key;if(S.current=t.key,D.current=void 0,O.current=void 0,k.current=Al(),m(`compose`),E.current=t.revision,A(t.document,t.mentions),g(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!FT(S.current,a)||w.current!==a||C.current!==a||T.current!==e||E.current!==r||o?.revision!==t.revision||(E.current=t.revision,A(Vt(jT(t),y.current),t.mentions))})}},[a,A,i]),(0,Z.useEffect)(()=>{if(!a||w.current!==a||O.current)return;let e=LT(_.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(Vt(jT(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(!FT(n,C.current)||O.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:zT(t)});if(!a)return;let o=jT(a);return D.current={keyID:gn(n),revision:a.revision,fingerprint:PT(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=Fl(k.current,{before:Cl(e,t,n),after:Cl(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(Vt(n,y.current),t):void 0},[M,P]),L=(0,Z.useCallback)((e,t,n=t,r)=>{let i=P(),a=MT(_.current),o=i?[]:v.current,s=BT(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=jt(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=RT(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=Tt(_.current,e,t,n,r);return M(a.document,RT(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=MT(_.current),n=an(t,e);if(!n)return null;let r=P()?[]:v.current,i=RT(r,n.document,n.edit),a=kt(n.document.text,n.caret),o=jt(n.document,a.text,a.caret),s=RT(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`?Tl(k.current,_.current):wl(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:[]}:VT(_.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=HT(e);A(t.document,t.mentions),g(e=>e+1)},[A]),te=(0,Z.useCallback)(()=>{let e=S.current;if(!FT(e,C.current))return null;let t=i.getState().getDraft(e);return{key:NT(e),keyID:gn(e),revision:t?.revision??0,document:MT(_.current),mentions:v.current.map(e=>({...e,range:{...e.range}})),epoch:T.current,runtime:i.getState().captureDraftRuntime()}},[i]),ne=(0,Z.useCallback)(e=>{let t=WT(e,i.getState().getDraft(e.key)),n=jT(i.getState().getDraft(e.key)),r=Wt(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:zT(t.mentions)});if(a){let e=jT(a);j(r,e)}return a},[j,i]),re=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:p,hydration:s,persistence:c,textPresetEpoch:h,getDocument:re,replacePlainDocument:F,replaceMaterializedDocument:I,applyBrowserEdit:L,applyProgrammaticEdit:R,replaceProgrammaticText:z,insertReference:B,deleteReference:V,restoreReferenceHistory:H,commitMentions:U,enterHistoryPreview:W,exitHistoryPreview:ee,captureSubmission:te,recoverSubmission:ne}),[L,R,te,U,V,l,W,ee,re,s,p,B,d,c,ne,I,F,z,H,h])};function KT(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 qT(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=KT({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 JT(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=KT({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=pl(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),qn(`resize`,m,h);let g;t[16]===o?g=t[17]:(g=()=>o?window:null,t[16]=o,t[17]=g),qn(`yuri:keyboard-settled`,m,g);let _;t[18]===o?_=t[19]:(_=()=>o?window.visualViewport:null,t[18]=o,t[19]=_),qn(`resize`,m,_);let v;t[20]===o?v=t[21]:(v=()=>o?window.visualViewport:null,t[20]=o,t[21]=v),qn(`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 YT=(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=JT(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)(ul,{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}),XT=.5,ZT=`--yuri-mobile-composer-swap`,QT=`--yuri-native-composer-dock`,$T=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),eE=(e,t,n)=>Math.min(n,Math.max(t,e)),tE=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,nE=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return tE(e,n)?e:n},rE=(e,t)=>t?nE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?nE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,iE=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:nE(e,{phase:`snapping`,rest:t,progress:n})},aE=e=>Math.round(eE(e,0,1)*1e3)/1e3,oE=(e,t,n)=>{let r=n-t;if(r>=0)return aE(e+r/80);if(n<=2)return 0;let i=e+r/80,a=n/t*e;return aE(Math.min(i,a))},sE=(e,t)=>e>=1?`compact`:e<=0?`expanded`:t,cE=(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`?nE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(r<=2)return nE(a,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn&&a.rest===`compact`&&r<i)return nE(a,{phase:`rest`,rest:`compact`,progress:1});let o=oE(a.progress,i,r);return e.phase===`snapping`&&o===a.progress?e:o===a.progress?a:Math.abs(o-a.progress)>=XT&&(o>=1||o<=0)?nE(a,{phase:`snapping`,rest:o>=1?`compact`:`expanded`,progress:o}):o>=1||o<=0?nE(a,{phase:`rest`,rest:sE(o,a.rest),progress:o}):nE(a,{phase:`tracking`,rest:a.rest,progress:o})},lE=(e,t=null)=>e.pinned?`expanded`:t||(e.progress>=.5?`compact`:`expanded`),uE=(e,t=null)=>{if(e.pinned)return nE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let n=lE(e,t),r=+(n===`compact`);return e.phase===`rest`&&e.rest===n&&e.progress===r?e:nE(e,{phase:`snapping`,rest:n,progress:r})},dE=e=>e.phase===`snapping`?nE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,fE=e=>eE(Math.max(0,e)/80,0,1),pE=(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:fE(n),rest:`bottom`}},mE=`--yuri-mobile-composer-occupancy`,hE=(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(mE,n),n},gE=(e,t)=>{t!==null&&e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)===t&&e.style.removeProperty(mE)},_E=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},vE=(e,t=e)=>{for(let n of new Set([e,t]))n.style.removeProperty(ZT),n.style.removeProperty(QT);delete e.dataset.yuriComposerSwapPhase,delete e.dataset.yuriComposerSwapRest,delete e.dataset.yuriNativeComposerDock},yE=(e,t,n,r=e)=>{let i=pE(t,n?.rest===`bottom`?`bottom`:`away`),a=String(i.progress),o=i.rest;return n?.progress!==a&&r.style.setProperty(QT,a),n?.rest!==o&&(e.dataset.yuriNativeComposerDock=o),{progress:a,rest:o}},bE=(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(ZT,i),n?.rest!==o&&(e.dataset.yuriComposerSwapRest=o),{progress:i,phase:a,rest:o}},xE=`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`,SE=Ku(()=>Pn(()=>import(`./ToolOutputDialog-O25CmHgA.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]))),CE=[],wE=[],TE=[],EE=[],DE=/^@[^\s]+$/,OE=({inputMode:e,message:t,showCommandAutocomplete:n})=>e!==`shell`&&(n||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),kE=/^(https?:\/\/|mailto:)\S+$/i,AE=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),jE=(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)},ME=e=>e.includes(`@`)?`paste`:`manual`,NE=(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}},PE=(e,t)=>Ie(e,t).some(e=>e.role===`user`),FE=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!ro(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6543
|
-
`).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},IE=`file://`,LE=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(`/`)},RE=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(IE)?t:`file://${LE(t)}`},zE=e=>{if(!e)return[];let t=[...lC(e).map(uC),...Array.from(e.files||[]).map(e=>h(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(dC)))},BE=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},VE=e=>Zn(e.path),HE=(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)]})},UE=e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?RE(e.serverPath):e.dataUrl})),WE=(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}},GE=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 lC(e).length>0},KE=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)},qE=e=>{let t=e.icon?Fs[e.icon]:null,n=e.color?zs[e.color]:void 0,r=(0,$.jsx)(X,{name:t??`folder`,className:`h-3.5 w-3.5`,style:n?{color:n}:void 0});return(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-muted-foreground`,children:e.iconImage?(0,$.jsx)(js,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:VE(e)})]})},JE=Z.memo(cb),YE=Z.memo(Wm),XE=(0,$.jsx)(`span`,{"data-yuri-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`}),ZE=Z.memo(Zm),QE=Z.memo(gx),$E=Z.memo(yx),eD=Z.memo(Fb),tD=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=Xn(),r=K(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(QS),m=$o(),h=t||m,g=qi(h),_=at(e??``,h,g),v=Rr(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=tC({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 rt(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:FE(e.parts,C)})):[],[C,b,y]),T=w[0]?.id;Z.useEffect(()=>{f(!0)},[b,T]);let E=J(async t=>{if(!(!e||s)){c(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{c(null)}}}),D=J(async t=>{if(!(!e||l)){u(t);try{await a(e,t)}finally{u(null)}}});return!e||w.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>f(e=>!e),"aria-expanded":!d,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),x.length>0&&(0,$.jsxs)(`span`,{className:`min-w-0 truncate typography-ui-label text-muted-foreground`,children:[n(`chat.revertPopover.files`),`: `,x.join(`, `)]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!d&&`rotate-180`),"aria-hidden":`true`})]}),!d&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:w.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(er,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{D(e.id)},children:[l===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(er,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{E(e.id)},children:[s===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});tD.displayName=`RevertedMessageDock`;function nD({projects:e,query:t,renderLabel:n,onSelect:r,selectedId:i}){return e.filter(e=>Es(VE(e),t)||Es(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)(As,{value:e.id,className:`max-w-[24rem] truncate`,children:n(e)},e.id))}var rD=Z.memo(function(e){let t=(0,Q.c)(42),{t:n}=Xn(),{isVSCode:r,footerIconButtonClass:i,iconSizeClass:a,handlePickLocalFiles:o,openIssuePicker:s,openPrPicker:c,onOpenSettings:l,withTooltip:u}=e,d=u!==void 0&&u,f=!!e.onOpenMobileSheet,p;t[0]===n?p=t[1]:(p=n(`chat.chatInput.actions.attachFiles`),t[0]=n,t[1]=p);let m=p,h=o,g;t[2]!==h||t[3]!==e?(g=()=>e.onOpenAndroidPickSheet?e.onOpenAndroidPickSheet():h(),t[2]=h,t[3]=e,t[4]=g):g=t[4];let _=f?pD:void 0,v=f?mD: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)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:C}),(0,$.jsx)(Js,{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),iD=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=Xn(),r=e.enabled?`chat.chatInput.permissionAutoAccept.disable`:`chat.chatInput.permissionAutoAccept.enable`,i;t[0]!==n||t[1]!==r?(i=n(r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o=e.saving,s=e.enabled,c=e.footerIconButtonClass,l;t[3]!==e.draftEnabled||t[4]!==e.draftOpen||t[5]!==e.enabled||t[6]!==e.onOpenSessionFirst||t[7]!==e.onSetDraftEnabled||t[8]!==e.onSetSessionEnabled||t[9]!==e.onToggleFailed||t[10]!==e.sessionId?(l=()=>Jw({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)(qs,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:hD,onPointerDownCapture:gD,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)(Js,{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)(Ys,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),aD=Z.memo(function(e){let t=(0,Q.c)(65),{isMobile:n,compact:r,footerIconButtonClass:i,stopFooterIconButtonClass:a,compactCircleButtonClass:o,sendIconSizeClass:s,stopIconSizeClass:c,canSend:l,canAbort:u,abortPending:d,hasContent:f,currentSessionId:p,newSessionDraftOpen:m,draftSubmitting:h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y,onPrimaryAction:b,onAbort:x}=e,S=r!==void 0&&r,{t:C}=Xn(),w=u,T,E,D,O,k;if(t[0]!==w||t[1]!==l||t[2]!==S||t[3]!==o||t[4]!==p||t[5]!==h||t[6]!==i||t[7]!==f||t[8]!==n||t[9]!==m||t[10]!==b||t[11]!==y||t[12]!==v||t[13]!==s||t[14]!==_||t[15]!==a||t[16]!==c||t[17]!==g||t[18]!==C){k=Symbol.for(`react.early_return_sentinel`);bb0:{let e=jx({canSend:l,hasSessionTarget:!!(p||m),draftSubmitting:!!h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:_D,onPointerDownCapture:vD}:{},t[24]=n,t[25]=r);let u=r,d=_.inFlight,x=d&&_.flightKind===`queue`,A=d&&_.flightKind!==`queue`,j;t[26]!==x||t[27]!==A||t[28]!==C?(j=C(x?`chat.chatInput.actions.queuingMessageAria`:A?`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[26]=x,t[27]=A,t[28]=C,t[29]=j):j=t[29];let M=j;T=S?o??a??i:a??i,E=c;let N=!w&&(!e.sendDisabled||d),P;t[30]!==n||t[31]!==b?(P=e=>{n&&(e.preventDefault(),b())},t[30]=n,t[31]=b,t[32]=P):P=t[32];let F;t[33]!==w||t[34]!==d||t[35]!==x||t[36]!==A||t[37]!==C?(F=C(A||!w&&d?x?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[33]=w,t[34]=d,t[35]=x,t[36]=A,t[37]=C,t[38]=F):F=t[38];let I;t[39]!==w||t[40]!==E||t[41]!==d||t[42]!==s||t[43]!==N?(I=N?(0,$.jsx)(Sl,{className:E,spinning:!!(d&&!w)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[39]=w,t[40]=E,t[41]=d,t[42]=s,t[43]=N,t[44]=I):I=t[44];let L=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":N?`true`:void 0,disabled:e.sendDisabled,"aria-busy":d||void 0,...u,onClick:P,className:Y(N?T:i,N?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":F,children:I});if(!w){k=L;break bb0}let R=!S&&(f||x),z=!e.sendDisabled&&!x,B=S&&`h-full`;t[45]===B?D=t[46]:(D=Y(`relative z-30 overflow-visible`,B),t[45]=B,t[46]=D),O=R?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":z||x?`true`:void 0,disabled:e.sendDisabled||x,"aria-busy":x||void 0,...u,onClick:e=>{e.preventDefault(),!x&&b()},className:Y(z||x?T:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,z||x?void 0:e.disabledClass),"aria-label":M,children:z||x?(0,$.jsx)(Sl,{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)(Sl,{className:E,spinning:!0}):(0,$.jsx)(Rl,{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),oD=(e,t)=>`${e}${e?e.endsWith(`
|
|
6542
|
+
`)},QC=(e,t,n,r,i)=>{if(VC(e,n)&&LC===r.epoch){if(o()!==r.transport||c()!==r.generation){JC(e,t,{pending:!1});return}JC(e,t,i)}},$C=e=>{let t=typeof e.sessionId==`string`?e.sessionId.trim():``;return t?{sessionId:t,directory:typeof e.directory==`string`&&e.directory.trim()?e.directory:e.directory??null}:null},ew=e=>{let t=FC.get(e);t&&(WC(e),JC(e,t.turnId,{pending:!1}))},tw=e=>{let t=$C(e);if(!t)return null;let n=PC(t),r=dw.getState().sendSelection[n];if(r?.providerID&&r?.modelID)return r;let i=ur.getState().getSessionModelSelection(t.sessionId);if(i)return{providerID:i.providerId,modelID:i.modelId,agent:ur.getState().getSessionAgentSelection(t.sessionId)??void 0};let a=Ko.getState();return a.currentProviderId&&a.currentModelId?{providerID:a.currentProviderId,modelID:a.currentModelId,agent:a.currentAgentName??void 0,variant:a.currentVariant??null}:null},nw=async e=>{let t=tw({sessionId:e.sessionId,directory:e.directory});if(!t)return;let n=typeof t.variant==`string`&&t.variant.trim()?t.variant.trim():void 0;await Te.applySendSelection(e.sessionId,{model:{providerID:t.providerID,id:t.modelID,...n?{variant:n}:{}},...t.agent?{agent:t.agent}:{}},e.directory)},rw=(e,t)=>{let n=$C(e);if(!n)return;let r=PC(n);dw.setState(e=>({sendSelection:{...e.sendSelection,[r]:t}})),ur.getState().saveSessionModelSelection(n.sessionId,t.providerID,t.modelID),t.agent&&ur.getState().saveSessionAgentSelection(n.sessionId,t.agent)},iw=async(e,t,n,r)=>{let i=n.id,a={epoch:LC,transport:o(),generation:c()},s=new AbortController;FC.set(t,{controller:s,turnId:i});try{if(await nw(e),!VC(t,s))return;let o=await Te.generateSessionAside({sessionId:e.sessionId,directory:e.directory,prompt:ZC(r,n),signal:s.signal}),c=typeof o?.text==`string`?o.text.trim():``;QC(t,i,s,a,c?{answer:c,error:null,pending:!1}:{answer:``,error:`empty response`,pending:!1})}catch(e){QC(t,i,s,a,BC(e,s.signal)?{pending:!1}:{error:zC(e),pending:!1})}finally{VC(t,s)&&FC.delete(t)}},aw=async(e,t)=>{let n=typeof t==`string`?t.trim():``,r=$C(e);if(!n||!r)return;let i=PC(r);ew(i);let a=dw.getState().entries[i]??NC;RC+=1;let o={id:`btw_${RC}`,quotes:a.quotes,question:n,answer:``,error:null,pending:!0};KC(i,e=>({turns:[...e.turns,o].slice(-50),quotes:NC.quotes})),await iw(r,i,o,a.turns)},ow=async e=>{let t=$C(e);if(!t)return;let n=PC(t),r=dw.getState().entries[n]?.turns??[],i=r[r.length-1];i&&(ew(n),JC(n,i.id,{answer:``,error:null,pending:!0}),await iw(t,n,i,r.slice(0,-1)))},sw=(e,t)=>{let n=typeof t==`string`?t.trim():``;!n||!$C(e)||KC(PC(e),e=>e.quotes.includes(n)?null:{...e,quotes:[...e.quotes,n].slice(-10)})},cw=(e,t)=>{let n=PC(e);dw.getState().entries[n]&&KC(n,e=>t<0||t>=e.quotes.length?null:{...e,quotes:e.quotes.filter((e,n)=>n!==t)})},lw=e=>{ew(PC(e))},uw=e=>{let t=PC(e);WC(t),IC=IC.filter(e=>e!==t),dw.setState(e=>{let n=t in e.entries,r=t in e.sendSelection;if(!n&&!r)return e;let i=n?{...e.entries}:e.entries,a=r?{...e.sendSelection}:e.sendSelection;return n&&delete i[t],r&&delete a[t],{entries:i,sendSelection:a}})},dw=L(()=>({entries:{},sendSelection:{},setSendSelection:rw,ask:aw,retry:ow,cancel:lw,addQuote:sw,removeQuote:cw,clear:uw})),fw=()=>{LC+=1;for(let{controller:e}of FC.values())e.abort();FC.clear(),IC=[],dw.setState({entries:{},sendSelection:{}})},pw=(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()}}}})(wu),mw=new Map,hw=e=>pw.hold(e),gw=e=>{mw.has(e)||mw.set(e,pw.hold(e))},_w=e=>{let t=mw.get(e);t&&(mw.delete(e),t())},vw=`btw-page`,yw=`btw-sheet`,bw=`text-selection`,xw=`1.5rem`,Sw=`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`,Cw=`box-border w-full whitespace-pre-wrap break-words px-3 py-2.5 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit]`;function ww(e){let t=(0,Q.c)(40),{turn:n,isLast:r,scope:i}=e,{t:a}=Xn(),o;t[0]!==a||t[1]!==n.error?(o=n.error===`empty response`||n.error===`session.btw failed`?a(`chat.btw.failed`):n.error,t[0]=a,t[1]=n.error,t[2]=o):o=t[2];let s=o,c=!n.pending&&!n.error&&!n.answer,l;t[3]!==a||t[4]!==n.answer?(l=async()=>{(await Yn(n.answer)).ok?ji.success(a(`contextSidebar.actions.copied`)):ji.error(a(`filesView.toast.copyFailed`))},t[3]=a,t[4]=n.answer,t[5]=l):l=t[5];let u=J(l),d=n.id,f;t[6]===n.quotes?f=t[7]:(f=n.quotes.map(Tw),t[6]=n.quotes,t[7]=f);let p;t[8]===n.question?p=t[9]:(p=(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words typography-markdown text-foreground`,children:n.question}),t[8]=n.question,t[9]=p);let m;t[10]!==f||t[11]!==p?(m=(0,$.jsxs)(`div`,{className:`ml-8 flex flex-col gap-1.5 self-end rounded-xl bg-[var(--surface-elevated)] px-3 py-2`,children:[f,p]}),t[10]=f,t[11]=p,t[12]=m):m=t[12];let h;t[13]!==a||t[14]!==n.pending?(h=n.pending?(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),a(`chat.btw.pending`)]}):null,t[13]=a,t[14]=n.pending,t[15]=h):h=t[15];let g;t[16]===s?g=t[17]:(g=s?(0,$.jsxs)(`p`,{role:`alert`,className:`whitespace-pre-wrap break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`mr-1.5 inline size-3.5 align-[-2px] text-[var(--status-error)]/85`,"aria-hidden":`true`}),s]}):null,t[16]=s,t[17]=g);let _;t[18]!==c||t[19]!==a?(_=c?(0,$.jsx)(`p`,{role:`status`,className:`typography-meta text-muted-foreground`,children:a(`chat.btw.cancelled`)}):null,t[18]=c,t[19]=a,t[20]=_):_=t[20];let v;t[21]===n.answer?v=t[22]:(v=n.answer?(0,$.jsx)(`div`,{className:`min-w-0 text-foreground`,children:(0,$.jsx)(Gu,{content:n.answer,enableFileReferences:!1})}):null,t[21]=n.answer,t[22]=v);let y;t[23]!==c||t[24]!==u||t[25]!==s||t[26]!==r||t[27]!==i||t[28]!==a||t[29]!==n.answer||t[30]!==n.pending?(y=!n.pending&&(n.answer||r&&(s||c))?(0,$.jsxs)(`div`,{className:`-ml-2 flex items-center gap-0.5`,children:[n.answer?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:u,"aria-label":a(`contextSidebar.actions.copy`),children:(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`})}):null,r?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:()=>void dw.getState().retry(i),"aria-label":a(`contextPanel.preview.actions.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`})}):null]}):null,t[23]=c,t[24]=u,t[25]=s,t[26]=r,t[27]=i,t[28]=a,t[29]=n.answer,t[30]=n.pending,t[31]=y):y=t[31];let b;return t[32]!==v||t[33]!==y||t[34]!==m||t[35]!==h||t[36]!==g||t[37]!==_||t[38]!==n.id?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-btw-turn":d,children:[m,h,g,_,v,y]}),t[32]=v,t[33]=y,t[34]=m,t[35]=h,t[36]=g,t[37]=_,t[38]=n.id,t[39]=b):b=t[39],b}function Tw(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 Ew(e){let t=(0,Q.c)(64),{scope:n,pending:r,quotes:i,foot:a}=e,{t:o}=Xn(),s;t[0]===n?s=t[1]:(s=e=>e.sendSelection[PC(n)],t[0]=n,t[1]=s);let c=dw(s),l;t[2]!==n||t[3]!==c?(l=c??tw(n),t[2]=n,t[3]=c,t[4]=l):l=t[4];let u=l,d=Ko(Dw),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(``),dw.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)(Os,{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=()=>dw.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:xw},t[35]=I):I=t[35];let L=C?Cw:Sw,R;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(R={borderTopLeftRadius:xw,borderTopRightRadius:xw},t[36]=R):R=t[36];let z;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(z={borderBottomLeftRadius:xw,borderBottomRightRadius:xw},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=>dw.getState().removeQuote(n,e),t[40]=n,t[41]=V);let H;t[42]!==i||t[43]!==B||t[44]!==V?(H=(0,$.jsx)(Wh,{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)(zl,{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 Dw(e){return e.providers}function Ow(e){let t=(0,Q.c)(29),{scope:n,foot:r}=e,i=r===void 0?`panel`:r,{t:a}=Xn(),o;t[0]===n?o=t[1]:(o=PC(n),t[0]=n,t[1]=o);let s=o,c;t[2]===s?c=t[3]:(c=e=>(e.entries[s]??NC).turns,t[2]=s,t[3]=c);let l=dw(c),u;t[4]===s?u=t[5]:(u=e=>(e.entries[s]??NC).quotes,t[4]=s,t[5]=u);let d=dw(u),f;t[6]===l?f=t[7]:(f=l.some(kw),t[6]=l,t[7]=f);let p=f,m=Z.useRef(null),h=l[l.length-1],g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},t[8]=g):g=t[8];let _=h?.answer,v=h?.pending,y;t[9]!==_||t[10]!==v||t[11]!==l.length?(y=[l.length,_,v],t[9]=_,t[10]=v,t[11]=l.length,t[12]=y):y=t[12],Z.useLayoutEffect(g,y);let b;t[13]===a?b=t[14]:(b=a(`chat.btw.title`),t[13]=a,t[14]=b);let x;t[15]!==n||t[16]!==a||t[17]!==l?(x=(0,$.jsx)(`div`,{ref:m,className:`overlay-scrollbar-container min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-3`,children:l.length===0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:a(`chat.btw.description`)}):(0,$.jsx)(`div`,{className:`flex flex-col gap-5`,children:l.map((e,t)=>(0,$.jsx)(ww,{turn:e,isLast:t===l.length-1,scope:n},e.id))})}),t[15]=n,t[16]=a,t[17]=l,t[18]=x):x=t[18];let S;t[19]!==i||t[20]!==s||t[21]!==p||t[22]!==d||t[23]!==n?(S=(0,$.jsx)(Ew,{scope:n,pending:p,quotes:d,foot:i},s),t[19]=i,t[20]=s,t[21]=p,t[22]=d,t[23]=n,t[24]=S):S=t[24];let C;return t[25]!==b||t[26]!==x||t[27]!==S?(C=(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 min-w-0 flex-col text-foreground`,"aria-label":b,children:[x,S]}),t[25]=b,t[26]=x,t[27]=S,t[28]=C):C=t[28],C}function kw(e){return e.pending}function Aw(e){let t=(0,Q.c)(53),{scope:n,active:r,mobile:i}=e,{t:a}=Xn(),{sessionId:o,directory:s}=n,c;t[0]===n?c=t[1]:(c=PC(n),t[0]=n,t[1]=c);let l=c,u;t[2]===s?u=t[3]:(u=In(s),t[2]=s,t[3]=u);let d=u,f;t[4]===d?f=t[5]:(f=e=>e.contextPanelByDirectory[d],t[4]=d,t[5]=f);let p=K(f),m;t[6]!==r||t[7]!==p?(m=r&&!!(p?.isOpen&&p.tabs.find(e=>e.id===p.activeTabId)?.mode===`btw`),t[6]=r,t[7]=p,t[8]=m):m=t[8];let h=m,g;t[9]===p?g=t[10]:(g=p?.isOpen&&p.tabs.some(Mw),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&&!_&&dw.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=()=>co({sessionId:o,directory:s??null});return!r&&!n()&&dw.getState().cancel(e),()=>{let r=dw.getState().entries[l];queueMicrotask(()=>{let i=S.current;i!==t&&i?.key===l&&i.active||n()||PC(e)===l&&dw.getState().entries[l]===r&&dw.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=()=>{dw.getState().clear(n),K.getState().closeContextPanel(d)},t[26]=d,t[27]=n,t[28]=T):T=t[28];let E=J(T),D,O;if(t[29]!==i||t[30]!==h?(D=()=>{if(!i||!h){_w(yw);return}return gw(yw),jw},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)(Ow,{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)(fl,{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 jw(){return _w(yw)}function Mw(e){return e.mode===`btw`}var Nw=()=>{typeof window>`u`||window.requestAnimationFrame(()=>{document.querySelector(`[data-btw-composer] textarea`)?.focus()})},Pw=e=>{let t=e.directory??null;To({sessionId:e.sessionId,directory:t})?gw(vw):K.getState().openContextPanelTab(t??``,{mode:`btw`}),Nw()},Fw=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Iw=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()}},Lw=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,Rw=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&e.delivery!==`queue`&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,zw=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},Bw=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Vw=(e,t)=>{let n=Mt.getState();return n.bindLegacyQueue(Nt(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},Hw=async e=>{let t=$a.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=Bw(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Vw(n,a)?r+=1:i+=1}catch{try{Vw(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Uw=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Ww=e=>{let t=e.ctrlEnter&&e.canQueue&&e.primary&&e.sessionIsRunning&&!e.autoReviewRunning;return e.followUpBehavior===`queue`?t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:e.primary?{kind:`submit`,delivery:`queue`}:e.queueUsable?{kind:`queue`}:{kind:`submit`,delivery:`steer`}:t?{kind:`submit`,steerAfterAdmit:!0}:e.ctrlEnter||!e.canQueue?{kind:`submit`}:{kind:`submit`,delivery:`steer`}},Gw=e=>Object.prototype.hasOwnProperty.call(e,`permissions`)?e.permissions:e.permission,Kw=e=>{let t=nc(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},qw=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Kw(Gw(e)));let r=e.find(e=>e?.name===n);return!r||Kw(Gw(r))},Jw=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)},Yw=null,Xw=new Set,Zw=()=>{for(let e of Xw)e()},Qw=e=>e===`chat`||e===`assistant`,$w=()=>Yw,eT=e=>{Yw!==e&&(Yw=e,Zw())},tT=e=>{Yw&&(e&&Yw.surfaceID!==e||(Yw=null,Zw()))},nT=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},rT=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}},iT=(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}),aT=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=iT(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=iT(e,`send`,i),o=Hy(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=iT(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=iT(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=iT(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Hy(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Fy(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=iT(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=iT(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},oT=(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)))},sT=(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},cT=(e,t)=>e.agents.some(e=>e.name===t),lT=(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},uT=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return lT(t,n,r,i)?i:void 0;if(a&&lT(t,n,r,a))return a},dT=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!sT(r,n.providerID,n.modelID))return null;let s=n.agent&&cT(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&cT(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&cT(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=uT({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}},fT=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=dT({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=dT({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&&cT(i,e)?e:s&&cT(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&sT(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&lT(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&&sT(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&lT(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&&sT(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&cT(i,o.agent)?o.agent:void 0)??(e&&cT(i,e)?e:s&&cT(i,s)?s:void 0),r=l.variant,c=r&&lT(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},pT=(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))},mT=(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}},hT=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,gT=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}:{}}},_T=e=>typeof e==`string`&&e.trim().length>0?e:void 0,vT=e=>_T(e.agent)??_T(e.mode),yT=e=>_T(typeof e.model==`object`?e.model?.variant:void 0)??_T(e.variant),bT=e=>{let t=typeof e.model==`object`?e.model:void 0,n=_T(e.providerID)??_T(t?.providerID),r=_T(e.modelID)??_T(t?.modelID)??_T(t?.id);return!n||!r?null:{providerID:n,modelID:r}},xT=e=>bT(e),ST=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=bT(n);return{id:typeof n.id==`string`?n.id:void 0,agent:vT(n),providerID:r?.providerID,modelID:r?.modelID,variant:yT(n)}}return null},CT=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(bT(n))return null;continue}if(n.role!==`assistant`)continue;let r=xT(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:vT(n),providerID:r.providerID,modelID:r.modelID,variant:yT(n)}}return null},wT=500,TT=e=>Array.from(e).length,ET=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},DT=e=>TT(e)>=wT,OT=e=>{let t=Wt(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},kT=(e,t)=>{let n=t??e;return typeof n!=`string`||!DT(n)?!1:Lt(typeof e==`string`?{text:``,references:[]}:e,n)},AT=(e,t,n,r,i=1)=>{let a=TT(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}-${ET(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},jT=e=>({text:e?.text??``,references:e?.composerReferences??[]}),MT=e=>({text:e.text,references:e.references.map(e=>({...e}))}),NT=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),PT=e=>JSON.stringify([e.text,e.references]),FT=(e,t)=>e!==null&&t!==null&&gn(e)===t,IT=(e,t,n)=>{let r=e?NT(e):null,i=r?n(r):void 0;return{document:Vt(jT(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?gn(r):null}},LT=(e,t,n,r)=>{if(!t||gn(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=PT(jT(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===PT(e)?`same-document-metadata`:`external-document`},RT=(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}]:[]})},zT=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),BT=(e,t,n,r,i=r)=>{let a=jt(e,n,r,i);return{document:a.document,mentions:RT(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},VT=(e,t,n)=>({preview:{real:MT(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),HT=e=>({document:e.real,mentions:e.realMentions}),UT=(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)})},WT=(e,t)=>{let n=jT(t),r=Ht(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:UT(e.mentions,t?.mentions??[],r,i)}},GT=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=va})=>{let a=e?gn(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)(()=>IT(e,t,i.getState().getDraft).document),[d,f]=(0,Z.useState)(()=>IT(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?NT(e):null),C=(0,Z.useRef)(a),w=(0,Z.useRef)(a),T=(0,Z.useRef)(0),E=(0,Z.useRef)(o?.revision??0),D=(0,Z.useRef)(void 0),O=(0,Z.useRef)(void 0),k=(0,Z.useRef)(Al());_.current=l,v.current=d,y.current=t,b.current=r,x.current=e,C.current=a;let A=(0,Z.useCallback)((e,t)=>{_.current=e,v.current=t,u(e),f(t)},[]),j=(0,Z.useCallback)((e,t)=>{let n=It(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=IT(x.current,y.current,i.getState().getDraft),n=t.key;if(S.current=t.key,D.current=void 0,O.current=void 0,k.current=Al(),m(`compose`),E.current=t.revision,A(t.document,t.mentions),g(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!FT(S.current,a)||w.current!==a||C.current!==a||T.current!==e||E.current!==r||o?.revision!==t.revision||(E.current=t.revision,A(Vt(jT(t),y.current),t.mentions))})}},[a,A,i]),(0,Z.useEffect)(()=>{if(!a||w.current!==a||O.current)return;let e=LT(_.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(Vt(jT(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(!FT(n,C.current)||O.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:zT(t)});if(!a)return;let o=jT(a);return D.current={keyID:gn(n),revision:a.revision,fingerprint:PT(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=Fl(k.current,{before:Cl(e,t,n),after:Cl(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(Vt(n,y.current),t):void 0},[M,P]),L=(0,Z.useCallback)((e,t,n=t,r)=>{let i=P(),a=MT(_.current),o=i?[]:v.current,s=BT(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=jt(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=RT(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=Tt(_.current,e,t,n,r);return M(a.document,RT(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=MT(_.current),n=an(t,e);if(!n)return null;let r=P()?[]:v.current,i=RT(r,n.document,n.edit),a=kt(n.document.text,n.caret),o=jt(n.document,a.text,a.caret),s=RT(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`?Tl(k.current,_.current):wl(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:[]}:VT(_.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=HT(e);A(t.document,t.mentions),g(e=>e+1)},[A]),te=(0,Z.useCallback)(()=>{let e=S.current;if(!FT(e,C.current))return null;let t=i.getState().getDraft(e);return{key:NT(e),keyID:gn(e),revision:t?.revision??0,document:MT(_.current),mentions:v.current.map(e=>({...e,range:{...e.range}})),epoch:T.current,runtime:i.getState().captureDraftRuntime()}},[i]),ne=(0,Z.useCallback)(e=>{let t=WT(e,i.getState().getDraft(e.key)),n=jT(i.getState().getDraft(e.key)),r=Wt(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:zT(t.mentions)});if(a){let e=jT(a);j(r,e)}return a},[j,i]),re=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:p,hydration:s,persistence:c,textPresetEpoch:h,getDocument:re,replacePlainDocument:F,replaceMaterializedDocument:I,applyBrowserEdit:L,applyProgrammaticEdit:R,replaceProgrammaticText:z,insertReference:B,deleteReference:V,restoreReferenceHistory:H,commitMentions:U,enterHistoryPreview:W,exitHistoryPreview:ee,captureSubmission:te,recoverSubmission:ne}),[L,R,te,U,V,l,W,ee,re,s,p,B,d,c,ne,I,F,z,H,h])};function KT(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 qT(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=KT({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 JT(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=KT({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=dl(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),qn(`resize`,m,h);let g;t[16]===o?g=t[17]:(g=()=>o?window:null,t[16]=o,t[17]=g),qn(`yuri:keyboard-settled`,m,g);let _;t[18]===o?_=t[19]:(_=()=>o?window.visualViewport:null,t[18]=o,t[19]=_),qn(`resize`,m,_);let v;t[20]===o?v=t[21]:(v=()=>o?window.visualViewport:null,t[20]=o,t[21]=v),qn(`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 YT=(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=JT(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)(pl,{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}),XT=.5,ZT=`--yuri-mobile-composer-swap`,QT=`--yuri-native-composer-dock`,$T=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),eE=(e,t,n)=>Math.min(n,Math.max(t,e)),tE=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,nE=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return tE(e,n)?e:n},rE=(e,t)=>t?nE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?nE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,iE=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:nE(e,{phase:`snapping`,rest:t,progress:n})},aE=e=>Math.round(eE(e,0,1)*1e3)/1e3,oE=(e,t,n)=>{let r=n-t;if(r>=0)return aE(e+r/80);if(n<=2)return 0;let i=e+r/80,a=n/t*e;return aE(Math.min(i,a))},sE=(e,t)=>e>=1?`compact`:e<=0?`expanded`:t,cE=(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`?nE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(r<=2)return nE(a,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn&&a.rest===`compact`&&r<i)return nE(a,{phase:`rest`,rest:`compact`,progress:1});let o=oE(a.progress,i,r);return e.phase===`snapping`&&o===a.progress?e:o===a.progress?a:Math.abs(o-a.progress)>=XT&&(o>=1||o<=0)?nE(a,{phase:`snapping`,rest:o>=1?`compact`:`expanded`,progress:o}):o>=1||o<=0?nE(a,{phase:`rest`,rest:sE(o,a.rest),progress:o}):nE(a,{phase:`tracking`,rest:a.rest,progress:o})},lE=(e,t=null)=>e.pinned?`expanded`:t||(e.progress>=.5?`compact`:`expanded`),uE=(e,t=null)=>{if(e.pinned)return nE(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let n=lE(e,t),r=+(n===`compact`);return e.phase===`rest`&&e.rest===n&&e.progress===r?e:nE(e,{phase:`snapping`,rest:n,progress:r})},dE=e=>e.phase===`snapping`?nE(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,fE=e=>eE(Math.max(0,e)/80,0,1),pE=(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:fE(n),rest:`bottom`}},mE=`--yuri-mobile-composer-occupancy`,hE=(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(mE,n),n},gE=(e,t)=>{t!==null&&e.style.getPropertyValue(`--yuri-mobile-composer-occupancy`)===t&&e.style.removeProperty(mE)},_E=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},vE=(e,t=e)=>{for(let n of new Set([e,t]))n.style.removeProperty(ZT),n.style.removeProperty(QT);delete e.dataset.yuriComposerSwapPhase,delete e.dataset.yuriComposerSwapRest,delete e.dataset.yuriNativeComposerDock},yE=(e,t,n,r=e)=>{let i=pE(t,n?.rest===`bottom`?`bottom`:`away`),a=String(i.progress),o=i.rest;return n?.progress!==a&&r.style.setProperty(QT,a),n?.rest!==o&&(e.dataset.yuriNativeComposerDock=o),{progress:a,rest:o}},bE=(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(ZT,i),n?.rest!==o&&(e.dataset.yuriComposerSwapRest=o),{progress:i,phase:a,rest:o}},xE=`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`,SE=Ku(()=>Pn(()=>import(`./ToolOutputDialog-CkZORaFS.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]))),CE=[],wE=[],TE=[],EE=[],DE=/^@[^\s]+$/,OE=({inputMode:e,message:t,showCommandAutocomplete:n})=>e!==`shell`&&(n||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),kE=/^(https?:\/\/|mailto:)\S+$/i,AE=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),jE=(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)},ME=e=>e.includes(`@`)?`paste`:`manual`,NE=(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}},PE=(e,t)=>Ie(e,t).some(e=>e.role===`user`),FE=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!ro(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6543
|
+
`).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},IE=`file://`,LE=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(`/`)},RE=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(IE)?t:`file://${LE(t)}`},zE=e=>{if(!e)return[];let t=[...lC(e).map(uC),...Array.from(e.files||[]).map(e=>_(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(dC)))},BE=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},VE=e=>Zn(e.path),HE=(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)]})},UE=e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?RE(e.serverPath):e.dataUrl})),WE=(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}},GE=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 lC(e).length>0},KE=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)},qE=e=>{let t=e.icon?Fs[e.icon]:null,n=e.color?zs[e.color]:void 0,r=(0,$.jsx)(X,{name:t??`folder`,className:`h-3.5 w-3.5`,style:n?{color:n}:void 0});return(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-muted-foreground`,children:e.iconImage?(0,$.jsx)(js,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:VE(e)})]})},JE=Z.memo(cb),YE=Z.memo(Wm),XE=(0,$.jsx)(`span`,{"data-yuri-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`}),ZE=Z.memo(Zm),QE=Z.memo(gx),$E=Z.memo(yx),eD=Z.memo(Fb),tD=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=Xn(),r=K(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(QS),m=$o(),h=t||m,g=qi(h),_=at(e??``,h,g),v=Rr(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=tC({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 rt(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:FE(e.parts,C)})):[],[C,b,y]),T=w[0]?.id;Z.useEffect(()=>{f(!0)},[b,T]);let E=J(async t=>{if(!(!e||s)){c(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{c(null)}}}),D=J(async t=>{if(!(!e||l)){u(t);try{await a(e,t)}finally{u(null)}}});return!e||w.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>f(e=>!e),"aria-expanded":!d,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),x.length>0&&(0,$.jsxs)(`span`,{className:`min-w-0 truncate typography-ui-label text-muted-foreground`,children:[n(`chat.revertPopover.files`),`: `,x.join(`, `)]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!d&&`rotate-180`),"aria-hidden":`true`})]}),!d&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:w.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(er,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{D(e.id)},children:[l===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(er,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{E(e.id)},children:[s===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});tD.displayName=`RevertedMessageDock`;function nD({projects:e,query:t,renderLabel:n,onSelect:r,selectedId:i}){return e.filter(e=>Es(VE(e),t)||Es(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)(As,{value:e.id,className:`max-w-[24rem] truncate`,children:n(e)},e.id))}var rD=Z.memo(function(e){let t=(0,Q.c)(42),{t:n}=Xn(),{isVSCode:r,footerIconButtonClass:i,iconSizeClass:a,handlePickLocalFiles:o,openIssuePicker:s,openPrPicker:c,onOpenSettings:l,withTooltip:u}=e,d=u!==void 0&&u,f=!!e.onOpenMobileSheet,p;t[0]===n?p=t[1]:(p=n(`chat.chatInput.actions.attachFiles`),t[0]=n,t[1]=p);let m=p,h=o,g;t[2]!==h||t[3]!==e?(g=()=>e.onOpenAndroidPickSheet?e.onOpenAndroidPickSheet():h(),t[2]=h,t[3]=e,t[4]=g):g=t[4];let _=f?pD:void 0,v=f?mD: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)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:C}),(0,$.jsx)(Js,{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),iD=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=Xn(),r=e.enabled?`chat.chatInput.permissionAutoAccept.disable`:`chat.chatInput.permissionAutoAccept.enable`,i;t[0]!==n||t[1]!==r?(i=n(r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o=e.saving,s=e.enabled,c=e.footerIconButtonClass,l;t[3]!==e.draftEnabled||t[4]!==e.draftOpen||t[5]!==e.enabled||t[6]!==e.onOpenSessionFirst||t[7]!==e.onSetDraftEnabled||t[8]!==e.onSetSessionEnabled||t[9]!==e.onToggleFailed||t[10]!==e.sessionId?(l=()=>Jw({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)(qs,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:hD,onPointerDownCapture:gD,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)(Js,{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)(Ys,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),aD=Z.memo(function(e){let t=(0,Q.c)(65),{isMobile:n,compact:r,footerIconButtonClass:i,stopFooterIconButtonClass:a,compactCircleButtonClass:o,sendIconSizeClass:s,stopIconSizeClass:c,canSend:l,canAbort:u,abortPending:d,hasContent:f,currentSessionId:p,newSessionDraftOpen:m,draftSubmitting:h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y,onPrimaryAction:b,onAbort:x}=e,S=r!==void 0&&r,{t:C}=Xn(),w=u,T,E,D,O,k;if(t[0]!==w||t[1]!==l||t[2]!==S||t[3]!==o||t[4]!==p||t[5]!==h||t[6]!==i||t[7]!==f||t[8]!==n||t[9]!==m||t[10]!==b||t[11]!==y||t[12]!==v||t[13]!==s||t[14]!==_||t[15]!==a||t[16]!==c||t[17]!==g||t[18]!==C){k=Symbol.for(`react.early_return_sentinel`);bb0:{let e=jx({canSend:l,hasSessionTarget:!!(p||m),draftSubmitting:!!h,submissionBlocked:g,sendPhase:_,queueFrozen:v,queueFallbackAvailable:y}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:_D,onPointerDownCapture:vD}:{},t[24]=n,t[25]=r);let u=r,d=_.inFlight,x=d&&_.flightKind===`queue`,A=d&&_.flightKind!==`queue`,j;t[26]!==x||t[27]!==A||t[28]!==C?(j=C(x?`chat.chatInput.actions.queuingMessageAria`:A?`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[26]=x,t[27]=A,t[28]=C,t[29]=j):j=t[29];let M=j;T=S?o??a??i:a??i,E=c;let N=!w&&(!e.sendDisabled||d),P;t[30]!==n||t[31]!==b?(P=e=>{n&&(e.preventDefault(),b())},t[30]=n,t[31]=b,t[32]=P):P=t[32];let F;t[33]!==w||t[34]!==d||t[35]!==x||t[36]!==A||t[37]!==C?(F=C(A||!w&&d?x?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[33]=w,t[34]=d,t[35]=x,t[36]=A,t[37]=C,t[38]=F):F=t[38];let I;t[39]!==w||t[40]!==E||t[41]!==d||t[42]!==s||t[43]!==N?(I=N?(0,$.jsx)(Sl,{className:E,spinning:!!(d&&!w)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[39]=w,t[40]=E,t[41]=d,t[42]=s,t[43]=N,t[44]=I):I=t[44];let L=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":N?`true`:void 0,disabled:e.sendDisabled,"aria-busy":d||void 0,...u,onClick:P,className:Y(N?T:i,N?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":F,children:I});if(!w){k=L;break bb0}let R=!S&&(f||x),z=!e.sendDisabled&&!x,B=S&&`h-full`;t[45]===B?D=t[46]:(D=Y(`relative z-30 overflow-visible`,B),t[45]=B,t[46]=D),O=R?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":z||x?`true`:void 0,disabled:e.sendDisabled||x,"aria-busy":x||void 0,...u,onClick:e=>{e.preventDefault(),!x&&b()},className:Y(z||x?T:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,z||x?void 0:e.disabledClass),"aria-label":M,children:z||x?(0,$.jsx)(Sl,{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)(Sl,{className:E,spinning:!0}):(0,$.jsx)(Rl,{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),oD=(e,t)=>`${e}${e?e.endsWith(`
|
|
6544
6544
|
|
|
6545
6545
|
`)?``:e.endsWith(`
|
|
6546
6546
|
`)?`
|
|
@@ -6549,9 +6549,9 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}f
|
|
|
6549
6549
|
`:``}${t.endsWith(`
|
|
6550
6550
|
|
|
6551
6551
|
`)?t:t.endsWith(`
|
|
6552
|
-
`)?`${t}\n`:`${t}\n\n`}`,sD=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},cD=(e,t,n,r)=>t?Pt({transportIdentity:e},t):n?pn({transportIdentity:e},n):r,lD=[],uD=({onOpenSettings:e,scrollToBottom:t,showScrollToBottom:n=!1,onScrollToBottom:r,submissionBlocked:a=!1,surface:s})=>{let{t:l,locale:d}=Xn(),f=ju(),[p,h]=Z.useState({open:!1,title:``,content:``}),[g,_]=Z.useState(`normal`),[v,y]=Z.useState(!1),[b,x]=Z.useState(!1),[S,C]=Z.useState(!1),[w,T]=Z.useState(``),[E,D]=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),ne=Z.useId(),[re,G]=Z.useState(``),[ie,ae]=Z.useState(``),[ce,ue]=Z.useState(!1),[de,fe]=Z.useState(!1),pe=Z.useRef(0),me=J(()=>{pe.current=Date.now()+500}),he=Z.useRef(0),_e=Z.useRef(!1),[ye,be]=Z.useState(-1),xe=Z.useRef(()=>{}),Se=Z.useRef((...e)=>Promise.resolve().then(()=>wa.getState().sendMessage(...e))).current,we=wa(e=>e.currentSessionId),Ee=Ko(e=>e.currentProviderId),Oe=Ko(e=>e.currentModelId),ke=Ko(e=>e.currentAgentName),Ae=Ko(e=>e.currentVariant),je=Ko(e=>e.providers),Ne=Ko(e=>e.agents),Pe=Ko(e=>e.getVisibleAgents),Fe=Z.useMemo(()=>Ty(Pe()),[Pe,Ne]),Le=Ko(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ze=Ko(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Be=Z.useMemo(()=>{let e=je.find(e=>e.id===Ee)?.models?.find(e=>e.id===Oe);return My(e)},[Oe,Ee,je]),Ve=Z.useMemo(()=>({providers:je,agents:Fe,variants:Be,variantsReady:!Le,modelsReady:!Le,agentsReady:!ze,ready:!Le&&!ze,loading:Le||ze}),[je,Fe,Be,Le,ze]),He=le(e=>e.currentDirectory),Ue=bd()??He,{ensureSessionRenderable:Ke}=dh(),Je=wa(Z.useMemo(()=>e=>we?e.getDirectoryForSession(we):null,[we])),Ye=Ca(we??``,Je??void 0),Ze=Z.useMemo(()=>ST(Ye),[Ye]),rt=Z.useMemo(()=>CT(Ye),[Ye]),it=Ja(we??``,Je??void 0).renderable,at=cr(we,Je??void 0),ot=at?.agent,st=at?.model?.id,lt=at?.model?.providerID,ut=at?.model?.variant,pt=Ko(e=>e.activeDirectoryKey),ht=Z.useRef(0),gt=Z.useRef(null),_t=Z.useRef(null),vt=wa(e=>e.newSessionDraft),yt=!!vt?.open,bt=wa(e=>e.newSessionDraft.draftSubmitting??!1),xt=wa(e=>e.newSessionDraft.draftEstablishing??!1),St=bt||xt,Tt=wa(e=>e.openNewSessionDraft),Et=wa(e=>e.setDraftPermissionAutoAcceptEnabled),Dt=_r(e=>e.autoAccept),kt=_r(e=>e.saving),jt=_r(e=>e.setSessionAutoAccept),Pt=wa(e=>e.setNewSessionDraftTarget),Ft=wa(e=>e.availableWorktreesByProject),It=wa(e=>e.abortPromptSessionId),Lt=wa(e=>e.abortPromptExpiresAt),Rt=wa(e=>e.clearAbortPrompt),zt=va(e=>e.consumePendingInputText),Bt=va(e=>e.pendingPresetSubmit),Vt=va(e=>e.pendingInputText),Ht=va(e=>e.pendingInputMode),Gt=va(e=>e.consumePendingSyntheticParts),qt=va(e=>e.activeAttachmentDraft),Jt=_h(Z.useMemo(()=>e=>{let t=we??(yt?`draft`:``);return t?e.drafts[t]??wE:wE},[yt,we])),Xt=_a(we??``),Zt=Z.useSyncExternalStore(i,o,o),Qt=qt?.transportIdentity??null,tn=qt?.owner.kind??null,nn=qt?.owner.ownerID??null,an=Z.useMemo(()=>cD(Zt,we,vt.draftID,Qt&&tn&&nn?{transportIdentity:Qt,owner:{kind:tn,ownerID:nn}}:null),[nn,tn,Qt,Zt,we,vt.draftID]),on=an?gn(an):null,sn=va(Z.useMemo(()=>e=>on?e.draftAttachmentViews[on]:void 0,[on])),ln=va(Z.useMemo(()=>e=>on?e.drafts[on]:void 0,[on])),dn=Z.useMemo(()=>{if(!ln||!sn)return lD;let e=ln.attachments.flatMap(e=>{let t=sn[e.attachmentRefID];return t?[t]:[]});return e.length===0?lD:e},[sn,ln]);Z.useEffect(()=>{an&&va.getState().hydrateDraftAttachments(an)},[an]);let fn=Ly(),pn=K(e=>e.activeMainTab===`chat`),mn=vo(we??``,Ue??void 0),hn=Ry({kind:`primary`,surfaceID:`primary`,active:pn,sessionID:we,directory:Ue??null,activity:{phase:mn?.type===`busy`?`busy`:mn?.type===`retry`?`retry`:`idle`,canAbort:mn?.type===`busy`||mn?.type===`retry`},draftKey:an,transportIdentity:Zt,runtimeGeneration:c(),selection:{value:{providerID:Ee,modelID:Oe,agent:ke,variant:Ae},catalog:Ve,flush:async()=>{let e=wa.getState().currentSessionId;if(!e)return;let t=c(),n=o(),r=ht.current,i=e,a=wa.getState().getDirectoryForSession(i)??null,s=gr(a);if(Ko.getState().activeDirectoryKey!==s&&await Ko.getState().activateDirectory(a),c()!==t||o()!==n||wa.getState().currentSessionId!==i||Ko.getState().activeDirectoryKey!==s||ht.current!==r)return;await Ke(i,{directory:a??void 0});let l=wa.getState().getDirectoryForSession(i)??null,u=gr(l);if(c()!==t||o()!==n||wa.getState().currentSessionId!==i||l!==a||u!==s||Ko.getState().activeDirectoryKey!==s||ht.current!==r)return;let d=Ko.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=Ie(i,l??void 0),m=ST(p),h=CT(p);if(hT({editRevision:r,pinnedHistoryMessageId:gt.current,latestHistoryMessageId:m?.id??null}))return;let g=ur.getState(),_=ge().get(i),v=fT({sessionId:i,latestUserChoice:m,latestExecution:h,catalog:f,memory:g,sessionEntity:_?.model?{agent:_.agent,model:{id:_.model.id,providerID:_.model.providerID,variant:_.model.variant}}:_?.agent?{agent:_.agent}:null,fallbackAgentName:d.currentAgentName});if(!v)return;let y=[i,v.source,v.messageId??``,v.agent??``,v.providerID,v.modelID,v.variant??``,s].join(`|`);_t.current!==y&&(pT(v,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:i,memory:g}),_t.current=y)},change:async e=>{ht.current+=1;let t=wa.getState().currentSessionId;if(t){let e=wa.getState().getDirectoryForSession(t)??void 0,n=ST(Ie(t,e));gt.current=n?.id??null}else gt.current=null;let n=Ko.getState();oT(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:ur.getState()})}},resources:{attachments:dn,addAttachment:async e=>{an&&await ea(an,()=>va.getState()).addLocal(e)},removeAttachment:async e=>an?ea(an,()=>va.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>an?ea(an,()=>va.getState()).clearRootAttachments():!1,restoreAttachments:async e=>an?ea(an,()=>va.getState()).restoreRootAttachments(e):!1,pendingInput:Vt===null?null:{text:Vt,mode:Ht},consumePendingInput:zt,pendingPreset:Bt,consumePendingPreset:()=>va.getState().consumePendingPresetSubmit(),consumeSyntheticParts:Gt,restoreSyntheticParts:e=>va.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:Jt,removeInlineDraft:e=>{let t=we??(yt?`draft`:``);t&&_h.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=we??(yt?`draft`:``);!t||e.length===0||_h.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:Xt,captureRuntime:()=>va.getState().captureDraftRuntime(),getDraft:e=>va.getState().getDraft(e),abortPrompt:{sessionID:It,clear:Rt}},backend:{send:e=>{nT(e,{transportIdentity:o(),runtimeGeneration:c()});let t=rT(e);return Se(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>rs(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()=>Tt(),compact:async e=>Te.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&kr(e.sessionID),ja(e.sessionID??``))},shortcuts:{cycle:e=>xe.current(e),new:()=>Tt(),abort:()=>(we&&kr(we),ja(we??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),_n=zy(hn,s??fn);By(_n),Z.useLayoutEffect(()=>{if(!_n.active){tT(_n.surfaceID);return}return eT(_n),()=>tT(_n.surfaceID)},[_n]);let vn=aT(_n),yn=_n.resources??(_n.kind===`primary`?hn.resources:void 0);if(!yn)throw Error(`chat-input-surface-resources-incomplete`);let bn=[...yn.attachments],q=_n.sessionID,xn=Vy(_n,St),Sn=_n.kind===`secondary`?_n.commands.hasNewDraft:yt,wn=Sn,Tn=_n.directory??Ue,En=_n.draftKey??an,Dn=Z.useMemo(()=>{if(_n.kind===`secondary`)return Uy(_n,!1,!1);let e=q?PE(q,Je??void 0):!1;return Uy(_n,e,Sn)},[_n,q,Je,Sn]),kn=(e,t,n,r,i,a,o,s,c,l)=>vn?vn.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`)),An=J(()=>vn?vn.abort():Promise.reject(Error(`chat-input-surface-incomplete`))),jn=Ia(e=>e.projects),Mn=Ia(e=>e.activeProjectId),Nn=Ia(e=>e.setActiveProjectIdOnly),[Pn,Fn]=Z.useState(!1),[Ln,Rn]=Z.useState(!1),zn=Z.useMemo(()=>q?qo({autoAccept:Dt,sessions:[],sessionById:ge(),sessionID:q}):vt.permissionAutoAcceptEnabled===!0,[q,vt.permissionAutoAcceptEnabled,Dt]),Bn=Ko(e=>e.agents),Vn=_n.kind===`secondary`?_n.selection.value.agent:ke,Un=_n.kind===`secondary`?Ty(_n.selection.catalog?.agents):Bn,Wn=m()||qw(Un,Vn),Gn=J(()=>{ji.error(l(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))}),Kn=_n.selection.value,Jn=_n.selection.change,Yn=_n.selection.catalog,Qn=J(async e=>{if(!Jn)throw Error(`chat-input-surface-selection-readonly`);await Jn({...e,agent:e.agent??void 0,variant:e.variant})}),$n=Z.useMemo(()=>({selection:{providerID:Kn.providerID??``,modelID:Kn.modelID??``,agent:Kn.agent??null,variant:Kn.variant},onChange:Qn,disabled:!_n.active,catalog:Yn}),[Yn,Qn,Kn.agent,Kn.modelID,Kn.providerID,Kn.variant,_n.active]);Z.useEffect(()=>{ht.current=0,gt.current=null,_t.current=null},[we]),Z.useEffect(()=>{if(_n.kind!==`primary`||!we||Le||ze||je.length===0||Fe.length===0)return;let e=gr(Je);if(pt!==e)return;let t=ur.getState(),n={providers:je,agents:Fe};if(hT({editRevision:ht.current,pinnedHistoryMessageId:gt.current,latestHistoryMessageId:Ze?.id??null}))return;let r=fT({sessionId:we,latestUserChoice:Ze,latestExecution:rt,catalog:n,memory:t,sessionEntity:lt&&st?{agent:ot,model:{id:st,providerID:lt,variant:ut}}:ot?{agent:ot}:null,fallbackAgentName:ke,transcriptReady:it});if(!r)return;let i=[we,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,pt].join(`|`);if(_t.current===i)return;if((r.agent===void 0||r.agent===ke)&&r.providerID===Ee&&r.modelID===Oe&&r.variant===Ae){_t.current=i;return}if(Ko.getState().activeDirectoryKey!==e)return;let a=Ko.getState();pT(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:we,memory:t}),_t.current=i},[_n.kind,we,Ze,rt,it,je,Fe,Le,ze,pt,Je,ke,Ee,Oe,Ae,ot,st,lt,ut]);let tr=Ko(e=>e.getVisibleAgents),nr=_n.kind===`primary`?tr():TE,rr=Ko(e=>_n.kind===`primary`?e.providers:EE),ir=_n.kind===`secondary`?Ty(_n.selection.catalog?.agents):nr,or=_n.kind===`secondary`?_n.selection.catalog?.providers??EE:rr,sr=_n.kind===`secondary`&&(!_n.selection.catalog?.ready||!!_n.selection.catalog.error),lr=!_n.active||!_n.selection.change||sr,dr=K(e=>e.isMobile),pr=Ol(),mr=K(e=>e.setImagePreviewOpen),hr=J(e=>{e.image&&(h(e),mr(!0))}),vr=J(e=>{h(t=>({...t,open:e})),mr(e)}),yr=$m(e=>e.pending),br=K(e=>e.inputBarOffset),xr=K(e=>e.persistChatDraft),Sr=K(e=>e.inputSpellcheckEnabled),wr=K(e=>e.isExpandedInput),Er=K(e=>e.setExpandedInput),Dr=K(e=>e.setTimelineDialogOpen),Ar=GT({draftKey:En,sessionTitles:new Map(Array.from(ge(),([e,t])=>[e,t.title||e])),persistenceEnabled:xr}),jr=Ar.document,Mr=jr.text,{replacePlainDocument:Nr,replaceProgrammaticText:Fr,applyBrowserEdit:Ir,insertReference:Lr,deleteReference:Rr,enterHistoryPreview:zr,exitHistoryPreview:Br,captureSubmission:Vr,recoverSubmission:Hr,confirmedFileMentions:Wr,mentions:Gr}=Ar,Kr=J((e,t)=>Fr(e,t)),Jr=Z.useMemo(()=>new Set(Wr.map(e=>e.value)),[Wr]),Yr=Z.useRef(null),Qr=Z.useRef(!1),$r=Z.useRef(0),ei=Z.useRef(null),ti=Z.useRef(null),ni=Z.useRef(0),ri=Z.useRef(!1),ii=Z.useRef(null),oi=Z.useRef(!1),si=Z.useRef(null),ci=Z.useRef([]),ui=Z.useRef(!1),di=Z.useRef(null),fi=Z.useRef(!1),pi=Z.useRef(null),mi=Z.useRef(Mr),hi=Z.useRef(new Set),_i=Ar.getDocument,yi=J((e,t,n=[])=>Kr(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}`))]})),bi=jb(Ab()),{git:xi,vscode:Si}=On(),Ti=K(e=>e.shortcutOverrides.cycle_agent),Di=K(e=>e.shortcutOverrides),Oi=Z.useMemo(()=>Ec(`cycle_agent`,Ti?{cycle_agent:Ti}:void 0),[Ti]),ki=Z.useMemo(()=>Ec(`clear_all_messages`,Di),[Di]),{currentTheme:Ai}=fs(),Mi=Yl(),Ni=$l(Tn),Pi=gu(e=>Tn?e.directories.get(Tn)?.status??null:null),Fi=gu(e=>e.ensureStatus),Ii=gu(e=>e.fetchStatus),[Li,Ri]=Z.useState(!1),Bi=Z.useRef(null);Z.useEffect(()=>{!Tn||!xi||Fi(Tn,xi)},[Tn,xi,Fi]),Z.useEffect(()=>{if(!(!Tn||!xi))return ga.onGitRefreshHint(e=>{BE(e.directory)===BE(Tn)&&Ii(Tn,xi)})},[Tn,xi,Ii]);let Vi=J(async e=>{if(!q)return;let t=wa.getState().getDirectoryForSession(q)||Tn||``;if(!t){ji.error(l(`diffView.reviewDialog.toast.noSessionDirectory`));return}Rn(!0);try{await Ei({originalSessionID:q,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),Fn(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),ji.error(e instanceof Error?e.message:l(`diffView.reviewDialog.toast.startFailed`))}finally{Rn(!1)}}),Hi=wr&&!dr,Ui=wr&&dr,Gi=Hi||Ui,Ki=`1.5rem`,qi=l(q||Sn?g===`shell`?`chat.chatInput.placeholder.shell`:dr?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Ji=bn,Xi=Z.useMemo(()=>new Set(ir.map(e=>e.name.toLowerCase())),[ir]),Zi=Z.useRef(Xi);Zi.current=Xi;let ta=OE({inputMode:g,message:Mr,showCommandAutocomplete:E}),ra=Oa({directory:Tn,enabled:ta}),ia=Z.useMemo(()=>ra.data??[],[ra.data]),aa=$i({directory:Tn,enabled:g!==`shell`}),sa=Z.useMemo(()=>aa.data??[],[aa.data]),ca=Z.useMemo(()=>new Map(sa.map(e=>[e.name.toLowerCase(),e.name])),[sa]),la=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`]);m()&&e.add(`reload`),!dr&&!m()&&e.add(`handoff-review`);for(let t of ia)t.source!==`skill`&&e.add(t.name.toLowerCase());return e},[ia,dr]),ua=Z.useMemo(()=>{if(!Mr||!Mr.includes(`/`)||g===`shell`||la.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${Kt})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(Mr))!==null;){let t=n[2]??``,r=n[3];if(!la.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:en({trigger:`/`,icon:`command`,label:r},Mr.slice(i,i+a))})}return e},[g,la,Mr]),fa=Z.useMemo(()=>!Mr||!Mr.includes(`@`)||g===`shell`?[]:ma(Mr,{confirmedValues:Jr,agentNames:Xi}),[Jr,g,Xi,Mr]),pa=Z.useMemo(()=>{if(!Mr||!Mr.includes(`[`)||g===`shell`||Ji.length===0)return[];let e=Ji.filter(Ce),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return qe(Mr,e.map(e=>e.filename)).flatMap(e=>{let n=Yt(Mr.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:en({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},Mr.slice(e.start,e.end))}]})},[g,Mr,Ji]),ha=f&&Ou(dr)&&_n.kind===`primary`,{globallyEnabled:ya,enabled:xa,hint:Sa,onHintChange:Ea}=yl({available:dr&&!ha}),Da=l(Sa===`recording`?`chat.dictation.releaseSend`:Sa===`cancelling`?`chat.dictation.releaseCancel`:Sa===`editing`?`chat.dictation.releaseEdit`:Sa===`processing`?`chat.dictation.processing`:`chat.dictation.inputPlaceholder`),[Na,Fa]=Z.useState(!1),[La,Ra]=Z.useState(!1),[Ba,Va]=Z.useState(null),Ha=Z.useMemo(()=>{if(!Mr||g===`shell`)return null;let e=[...El(fa),...ua,...pa,...Ba?.draftID===on&&Ba?.text===Mr?[{start:Ba.start,end:Ba.end,style:`dictation`}]:[],...jr.references.map(e=>({start:e.start,end:e.end,priority:103,...Ut(e)}))];return jl(Mr,e)},[pa,ua,fa,jr.references,g,Mr,Ba,on]),[Ua,Wa]=Z.useState(null),Ga=Z.useRef(null),[Ka,qa]=Z.useState(!1),[Xa,Qa]=Z.useState(!1),[eo,to]=Z.useState(null),[ro,io]=Z.useState(null),ao=Mt(e=>e.followUpBehavior),oo=Z.useMemo(()=>{let e=vn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[vn]),so=Ah({transportIdentity:oo?.transportIdentity??``,directory:oo?.directory??``,sessionID:oo?.sessionID??``}),co=Z.useMemo(()=>q?Nt(q):null,[q]),fo=Mt(Z.useMemo(()=>e=>oo?$t(e,oo):CE,[oo])),mo=Mt(Z.useMemo(()=>e=>co?$t(e,co):CE,[co])),ho=Z.useMemo(()=>mo.length===0?fo:fo.length===0?mo:[...mo,...fo],[fo,mo]),go=so.mode===`server`?CE:ho,yo=Mt(Z.useMemo(()=>e=>oo?wt(e,oo):CE,[oo])),So=Mt(e=>e.clearQueue),Co=Mt(e=>e.removeFromQueue),wo=yn.inlineDrafts,To=wo.length>0,[Eo,Do,Oo]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of wo)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[wo]),jo=J(e=>{for(let t of yn.inlineDrafts)t.source===e&&yn.removeInlineDraft(t.id)}),Mo=J(()=>{for(let e of yn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&yn.removeInlineDraft(e.id)}),No=yn.history;Z.useEffect(()=>{mi.current=Mr},[Mr]),Z.useLayoutEffect(()=>{_(`normal`),be(-1)},[En?.transportIdentity,En?.owner.kind,En?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Sn||dr)return;let e=()=>{let e=Yr.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Sn,dr]);let Po=wx(_n.kind===`primary`?q:null,_n.kind===`primary`?Tn??void 0:void 0),Io=_n.activity?.phase??Po.phase,Ro=Ta(Z.useMemo(()=>e=>{if(!q)return!1;let t=e.runsByOriginalSessionID[q];return t?.status===`running`&&t.runtimeKey===u()},[q])),zo=J(e=>{dr&&(me(),F(e),Yr.current?.blur(),Ko.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),Bo=yn.pendingInput,Ho=yn.consumePendingInput;Z.useEffect(()=>{if(Bo===null)return;let e=Ho();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=oD(mi.current,e.text);mi.current=t,Kr(t)}else if(e.mode===`append-inline`){let t=sD(mi.current,e.text);mi.current=t,Kr(t)}else Nr(e.text);setTimeout(()=>{Yr.current?.focus()},0)}},[Bo,Ho,Nr,Kr]);let Uo=Jg(q,vt.draftID),Wo=o_(s_(Uo)),Go=Mr.trim().length>0||Ji.length>0||To||Wo.length>0,Jo=_n.kind===`primary`&&EC(Mr,g)===`btw`,Yo=so.mode===`server`?so.items.length>0:go.length>0||yo.length>0,Xo=!Jo&&!W_(so.mode),Zo=Go||Yo,Qo=wa(e=>e.stagedMessageEdit?.sessionId===q?e.stagedMessageEdit.messageId:null),$o=Io===`busy`||Io===`retry`,es=!Jo&&(_n.activity?.canAbort??$o),ts=J(()=>{let e=Yr.current,t=e?.value??_i().text;t!==_i().text&&Ir(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=_i();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Ji.length>0||To||Wo.length>0}}),ns=_n.surfaceID,is=vt?.draftID??null,as=$a(Z.useMemo(()=>gi(ns),[ns])),os=$a(Z.useMemo(()=>fr(is),[is])),ss=Z.useMemo(()=>Cr(Jo?null:as,!Jo&&os),[as,os,Jo]),cs=(e=`send`)=>$a.getState().beginFlight(ns,e),ls=()=>{$a.getState().endFlight(ns)},us=()=>$a.getState().isInFlight(ns),ds=Z.useRef(null);Z.useEffect(()=>{if(_n.kind!==`primary`||!Qo){ds.current=null;return}if(ds.current!==Qo){if(ds.current=Qo,ha){Nu().focus();return}ky(Yr)||requestAnimationFrame(()=>ky(Yr))}},[ha,Qo,_n.kind]);let ps=$a(Z.useMemo(()=>no(is),[is])),ms=Qe(Z.useMemo(()=>e=>q?e.bySession[q]:void 0,[q])),hs=Z.useMemo(()=>{if(!ms?.length)return et;let e=new Set(Ye.map(e=>e.id));return ms.filter(t=>!e.has(t.id)).map(Ge)},[ms,Ye]),[gs,_s]=Z.useState(null),[vs,ys]=Z.useState(()=>new Set),bs=gs&&gs.sessionID===q&&Ci(gs.runtime,yn.captureRuntime())&&!tt(gs.sessionID,gs.item.messageID)&&!hs.some(e=>e.messageID===gs.item.messageID)?gs.item:null,xs=Z.useMemo(()=>[...ps,...hs,...bs?[bs]:[]],[ps,hs,bs]);Z.useEffect(()=>{ys(e=>{if(e.size===0)return e;let t=new Set;for(let e of hs)t.add(e.messageID);bs&&t.add(bs.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})},[hs,bs]);let Ss=oe(Z.useMemo(()=>e=>q?e.runningBySession[q]===!0:!1,[q])),Cs=J(async()=>{let e=wa.getState().newSessionDraft.draftID;if(!e||!$a.getState().isEstablishing(e))return!1;let t=ts();if(!t.hasContent)return!1;let n=Jg(null,e),r=n?o_.getState().quotesByKey[n]??[]:[],i=i_(t.document,r),a=At(i,`queue-canonical`);if(!a.ok)return ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;if(await _n.selection.flush(),!$a.getState().isEstablishing(e))return!1;let o=mT(Ko.getState());if(!o?.providerID||!o?.modelID)return ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;let s=UE(Ji);return $a.getState().enqueueEstablishingFollowUp({draftID:e,content:a.text,sendConfig:{providerID:o.providerID,modelID:o.modelID,...o.agent?{agent:o.agent}:{},...o.variant?{variant:o.variant}:{}},attachments:s,composerDocument:i})?(Nr(``),n&&i!==t.document&&o_.getState().clear(n),be(-1),Er(!1),s.length>0&&yn.clearAttachments(),!0):!1}),ws=()=>{if(q)return!1;let e=wa.getState().newSessionDraft.draftID;return $a.getState().isEstablishing(e)?(Cs(),!0):!1},Ts=J(async()=>{if(!_n.active||us())return;if(_n.kind===`primary`&&q){let e=wa.getState().stagedMessageEdit;if(e&&e.sessionId===q){await Ns();return}}let e=ts(),t=At(e.document);if(!t.ok){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let n={chunks:t.chunks??[],semantics:t.semantics??[]},r=t.text,i=r.trimStart(),s=n.chunks.every(e=>e.provenance===`authored`)&&g===`normal`&&i.startsWith(`/`)?Wl(i.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(s&&!Jl(s,e=>Fy(_n,{name:e.name,source:`yuri`}))||a||!e.hasContent||!q)return;if(Xo||!Pr(_n.deliveryTarget?.kind,so.mode)){Ns($o?{delivery:`steer`}:void 0);return}if(n.chunks.every(e=>e.provenance===`authored`)&&OC(r,g)){Ns();return}if(!cs(`queue`))return;let u=_n.transportIdentity,d=_n.runtimeGeneration,f=yn.captureRuntime(),p=oo,m=_n.kind===`primary`?oo?.sessionID??q:null,h=[...yn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=h.length>0?Wt(bh(e.document.text,h),e.document.references).document:e.document,v=Uo?o_.getState().quotesByKey[Uo]??[]:[],y=i_(_,v),b=y!==_,x=At(y,`queue-canonical`);if(!x.ok){ls(),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let S=UE(Ji),C=Vr(),w=S,T=Qi(),E=!1,D=null,O=()=>{E&&p&&(so.actions.unstageAdmission({requestID:T.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),E=!1),D&&p&&(Mt.getState().unstageAdmission(p,D),D=null)},k=async e=>{O(),C&&Hr(C),w.length>0&&await yn.restoreAttachments(w),e&&yn.restoreSyntheticParts(e),h.length>0&&yn.restoreInlineDrafts(h),b&&Uo&&o_.getState().restore(Uo,v)};try{if(!p){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(so.mode===`server`){if(!En){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}bo({stage:()=>{so.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:Gr}}),E=!0},clearComposer:()=>{Nr(``),b&&Uo&&o_.getState().clear(Uo),be(-1),Er(!1)}})}else bo({stage:()=>{Mt.getState().bindLegacyQueue(Nt(p.sessionID),p),Mt.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:Gr}),D=T.requestID},clearComposer:()=>{Nr(``),b&&Uo&&o_.getState().clear(Uo),be(-1),Er(!1)}});if(await _n.selection.flush(),!Ci({transportIdentity:u,generation:d},{transportIdentity:o(),generation:c()})){await k();return}if(!Ci(f,yn.captureRuntime())){await k();return}if(m&&wa.getState().currentSessionId!==m){await k();return}if(p.transportIdentity!==o()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&In(wa.getState().getDirectoryForSession(m))!==In(p.directory)){await k();return}let t=p,n=_n.kind===`primary`?(()=>{let e=Ko.getState(),t=m?wa.getState().getDirectoryForSession(m)??null:null;return mT(e,{expectedConfigKey:gr(t),activeDirectoryKey:e.activeDirectoryKey})})():_n.selection.value.providerID&&_n.selection.value.modelID?{..._n.selection.value,providerID:_n.selection.value.providerID,modelID:_n.selection.value.modelID}:void 0;if(!na(n)){await k();return}if(so.mode===`server`){if(!En){await k(),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let r=qr({draftKey:En,runtime:f,document:e.document,attachments:Ji,inlineDrafts:h}),i=t.deliveryTarget.kind===`assistant`?yn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??Ct()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=ko({plan:{chunks:x.chunks??[],semantics:x.semantics??[]},agents:ir,installedSkillNames:new Set(Zr(Cn,Tn).map(e=>e.name)),directory:Tn,root:Mi||Tn,confirmedFilePaths:Wr.map(e=>e.path),confirmedDirectoryPaths:Wr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ji});return o=e.attachments,Ma({text:h.length>0?bh(e.text,h):e.text,attachments:[...S,...e.attachments],semanticParts:Aa(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...Xr(S),...Xr(o),...(i??[]).flatMap(e=>Xr(e.attachments??[],e.partID))],t=s?new Set(s.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),ji.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Lo(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Wi({capture:r,admit:async()=>{let r=await so.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:Gr,sendConfig:n,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:T.createdAt},attachments:a});return r.status===`committed`&&(e=!0,E=!1),r},captureRuntime:yn.captureRuntime,getCurrentDraftKey:()=>En,getDocument:_i,consumeBody:()=>Nr(``),getAttachments:()=>yn.attachments,removeAttachment:yn.removeAttachment,getInlineDrafts:()=>yn.inlineDrafts,removeInlineDraft:yn.removeInlineDraft});if(!e){await k(i),o.status===`stale`&&ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!dr&&Yr.current?.focus()}catch(e){await k(i),ji.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!Mt.getState().confirmAdmission(t,{requestID:T.requestID,sendConfig:n,attachments:S.length>0?S:void 0}).ok){await k(),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}D=null;for(let e of h)yn.removeInlineDraft(e.id);S.length>0&&yn.clearAttachments(),dr||Yr.current?.focus()}catch(e){await k(),ji.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{ls()}}),Es=J(()=>{Uw(()=>Ts(),()=>{ji.error(l(`chat.chatInput.toast.messageSendFailed`))})}),Ds=J(async(e,t,n,r)=>{if(Xo||!_n.draftKey)return!1;try{let i=await wi({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=va.getState(),o=a.getDraft(_n.draftKey);return K_(await Yi({key:_n.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1}}),Os=J(e=>{if(!(a||Xo)){if(vn){vn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}ji.error(l(`chat.chatInput.toast.messageSendFailed`))}}),ks=J(()=>{me(),F(`agent`),Yr.current?.blur(),Ko.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),As=J(()=>{qa(!0)}),js=J(()=>{Qa(!0)}),Ns=J(async e=>{if(!_n.active||a)return;if(!e?.queuedOnly){let t=e?.presetText==null?ts():null;if(AC({text:e?.presetText??t?.message??``,inputMode:g,scope:q&&Tn?{sessionId:q,directory:Tn}:null,hasReferences:!!(t?.document.references.length||Gr.length),allowed:_n.kind===`primary`&&Fy(_n,{name:`btw`,source:`yuri`}),ask:dw.getState().ask,clearText:()=>{Nr(``),D(!1),k(``)},open:()=>{dr&&(me(),Yr.current?.blur()),q&&Pw({sessionId:q,directory:Tn??null})},notify:e=>ji.error(l(`chat.btw.${e}`))}))return}if(ws()||us())return;let n=e?.queuedOnly??!1,r=e?.queuedMessageId,i=wa.getState().stagedMessageEdit,s=_n.kind===`primary`&&!n&&!!(q&&i?.sessionId===q),u=!s&&e?.steerAfterAdmit===!0&&$o&&!Ro&&_n.kind===`primary`,d=s?`steer`:u?`queue`:e?.delivery,f=d===`queue`&&($o||Ro)?`queue`:d===`steer`&&$o?`steer`:void 0,p=e?.presetText==null?ts():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Ji.length>0||To},h=e?.presetText==null?Vr():null,_=bn,v=At(p.document,`direct-send-display`);if(!v.ok){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let y=v.text,b={chunks:v.chunks??[],semantics:v.semantics??[]},x=b.chunks.every(e=>e.provenance===`authored`),S=y.trimStart(),C=x?EC(S,g):null,w=x&&OC(y,g),T=x&&g===`normal`&&/^\/model(?:\s|$)/i.test(S),E=x&&g===`normal`&&S.startsWith(`/`)?Wl(S.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Jl(E,e=>Fy(_n,{name:e.name,source:`yuri`}))||n&&Xo)return;if(!n&&T){D(!1),k(``),dr?zo(`model`):(K.getState().setModelSelectorOpen(!0),Ko.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}let O=!s&&!u&&ar({hasQueuedMessages:Yo,sessionIsRunning:$o,autoReviewRunning:Ro,queuedOnly:n,delivery:f});if(!(!n&&C&&C!==`model`)){if(q&&O&&Xo)return;if(q&&O&&so.mode===`server`){p.hasContent&&Es();return}if(q&&O){p.hasContent&&Es();let e=go[0];e&&vn&&await vn.sendQueued(e.queueItemID,{options:$o?{delivery:`steer`}:void 0});return}}let A=w||!n&&p.hasContent&&!r?[]:r?go.filter(e=>e.id===r):go;if(n&&Ro)return;if(n){if(A.length===0||!q)return}else if(!p.hasContent&&!Yo||!q&&!Sn)return;if(!q&&xn||!cs(f===`queue`?`queue`:`send`))return;let j=!q&&Sn&&!n&&!w?wa.getState().newSessionDraft.draftID??null:null,M=j?un(`msg`):void 0;if(j&&M&&!$a.getState().beginEstablishing({draftID:j,primaryMessageID:M})){ls();return}let N=()=>{ba(),j&&$a.getState().clearEstablishing(j)},P=e=>{let t=wa.getState().currentSessionId,n=(t?wa.getState().getDirectoryForSession(t):null)??Tn??``;if(!t||!n){$a.getState().clearEstablishing(e);return}Hw({draftID:e,sessionID:t,directory:n,transportIdentity:o(),runtimeGeneration:c(),admitServer:so.mode===`server`?async e=>so.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?Xr(e.attachments):void 0}):void 0})};if(q&&!n&&!w&&!s&&Ro){ls(),Es();return}let F=!n&&!w,I=_n.kind===`primary`&&q&&f===`queue`&&!n&&!w&&!C&&g===`normal`?un(`msg`):void 0,L=()=>{I&&_s(e=>e?.item.messageID===I?null:e)};I&&q&&(u&&ys(e=>{if(e.has(I))return e;let t=new Set(e);return t.add(I),t}),_s({sessionID:q,runtime:yn.captureRuntime(),item:{kind:`pending-admission`,requestID:I,queueItemID:I,operationID:I,messageID:I,content:y,createdAt:Date.now(),phase:`admitting`,attachmentCount:Ji.length,composerDocument:p.document,composerMentions:Gr}}));let R=Uo?o_.getState().quotesByKey[Uo]??[]:[],z=t_(R,y)!==y,B=!1,V=()=>{!B||!Uo||(o_.getState().restore(Uo,R),B=!1)};F&&(Nr(``),z&&Uo&&(o_.getState().clear(Uo),B=!0),be(-1),Er(!1));let H=!1,U,W,ee=yn.captureRuntime(),te=!1;try{if(Rw({surfaceKind:_n.kind,currentSessionId:q,queuedOnly:n,delivery:f,resourcePolicy:w,inputMode:g,localCommand:C})&&q){let e=wa.getState().getDirectoryForSession(q)??Tn??null,t=wa.getState().stagedMessageEdit;t&&t.sessionId===q&&(W={sessionId:t.sessionId,messageId:t.messageId},wa.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Ko.getState(),r=gT({captured:mT(n,{expectedConfigKey:gr(e),activeDirectoryKey:n.activeDirectoryKey}),surfaceSelection:_n.selection.value});if(!W&&r?.providerID&&r?.modelID){let t=UE(Ji);U=uo({sessionId:q,directory:e,content:z?t_(R,y):y,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=_n.kind===`primary`?(()=>{if(n){let e=A[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(oo?.sessionID)return oo.sessionID}return q})():null,i=n?A[0]?.sendConfig:void 0;if(n&&i||await _n.selection.flush(),e!==null&&wa.getState().currentSessionId!==e)return;let a=async()=>{let t=i?{...i}:_n.kind===`primary`?(()=>{let t=Ko.getState();if(!e)return gT({captured:mT(t),surfaceSelection:_n.selection.value});let n=wa.getState().getDirectoryForSession(e)??Tn??null;return gT({captured:mT(t,{expectedConfigKey:gr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:_n.selection.value})})():_n.selection.value.providerID&&_n.selection.value.modelID?{..._n.selection.value,providerID:_n.selection.value.providerID,modelID:_n.selection.value.modelID}:void 0;if(_n.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=wa.getState().getDirectoryForSession(e)??Tn??null,r=gr(n);if(Ko.getState().activeDirectoryKey!==r&&await Ko.getState().activateDirectory(n),wa.getState().currentSessionId===e){let e=Ko.getState();t=gT({captured:mT(e,{expectedConfigKey:gr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:_n.selection.value})}}return t},o=await a(),s=!1,c=o?.providerID,d=o?.modelID,v=o?.agent,x=o?.variant;if(!c||!d){if(!s){s=!0;try{await Ko.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),o=await a(),c=o?.providerID,d=o?.modelID,v=o?.agent,x=o?.variant}catch{}}if(!c||!d){console.warn(`Cannot send message: provider or model not selected`),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}}q&&!n&&!w&&f!==`queue`&&await da(q)&&await ja(q);let S={...f?{delivery:f}:{},commitStagedMessageEdit:!n&&f!==`queue`,...U?{messageID:U.messageID,ticket:U}:I||M?{messageID:I??M}:{},...e?{sessionId:e,directoryHint:wa.getState().getDirectoryForSession(e)??Tn??null}:_n.kind===`primary`&&q?{sessionId:q,directoryHint:wa.getState().getDirectoryForSession(q)??Tn??null}:{}},T=``,E=[],D,O=[],k=new Set(Zr(Cn,Tn).map(e=>e.name)),F=[],B=w?void 0:yn.consumeSyntheticParts();for(let e=0;e<A.length;e++){let t=A[e],n=t.composerDocument&&At(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Tn,a=new Set(Zr(Cn,i).map(e=>e.name)),o=ko({plan:r??Ya(t.content),agents:ir,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(F.push(...o.semantics),!D&&o.agent&&(D=o.agent),e===0)T=o.text,E=Fo([...UE(t.attachments),...o.attachments]);else{let e=UE(t.attachments);O.push({text:o.text,attachments:Fo([...e,...o.attachments])})}}if(!n&&p.hasContent){let e=UE(Ji),t=ko({plan:b,agents:ir,installedSkillNames:k,directory:Tn,root:Mi||Tn,confirmedFilePaths:Wr.map(e=>e.path),confirmedDirectoryPaths:Wr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ji});F.push(...t.semantics),!D&&t.agent&&(D=t.agent);let n=z?t_(R,t.text):t.text;A.length===0?(T=n,E=Fo([...e,...t.attachments])):O.push({text:n,attachments:Fo([...e,...t.attachments])})}let ne=q??(Sn?`draft`:null),re=[];if(!n&&ne&&!w&&(re=[...yn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),re.length>0)if(A.length===0)T=bh(T,re);else if(O.length>0){let e=O[O.length-1];e.text=bh(e.text,re)}else T=bh(T,re);if(B&&B.length>0&&O.push(...po(B)),eo&&O.push({text:eo.contextText,synthetic:!0}),ro&&(O.push({text:ro.instructionsText,synthetic:!0}),O.push({text:ro.contextText,synthetic:!0})),O.push(...Aa(F,q&&wa.getState().getDirectoryForSession(q)||Tn)),!T&&E.length===0&&O.length===0)return;if(j&&M){if(!await Ao({messageID:M,providerID:c,modelID:d,agent:v,text:T,attachments:E,additionalParts:O,agentMentionName:D}))return;if(!$a.getState().isEstablishing(j)){N();return}}let G=async()=>{if(V(),N(),oo&&A.length>0&&Mt.setState(e=>{let t=Ot(oo),n=e.queuedMessages[t]??[],r=new Set(A.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...A,...n.filter(e=>!r.has(e.id))]}}}),n)return B&&yn.restoreSyntheticParts(B),!0;yn.pendingInput?.text===p.message&&yn.consumePendingInput(),h&&Hr(h);let e=!0;return _.length>0&&(e=await yn.restoreAttachments(_)),B&&yn.restoreSyntheticParts(B),re.length>0&&yn.restoreInlineDrafts(re),e};if(!w&&q&&r){let e=oo?$t(Mt.getState(),oo).find(e=>e.id===r||e.queueItemID===r):void 0;oo&&e?.queueItemID&&e.operationID&&Co(oo,e.queueItemID,e.operationID)}else!w&&q&&A.length>0&&oo&&So(oo);!n&&!w&&(Nr(``),be(-1),Er(!1),Lw({queuedOnly:n,resourcePolicy:w,rootAttachmentCount:_.length})&&yn.clearAttachments());let ie=()=>Fw({currentSessionId:q,messageRef:mi,replacePlainDocument:Nr}),ae=T.trimStart();if(g===`normal`&&ae.startsWith(`/`)){let e=Wl(ae.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Jl(e,e=>Fy(_n,{name:e.name,source:`yuri`})))return;if(q&&(e===`undo`||e===`redo`)&&kC(ae,g)&&ie(),e===`undo`&&q){try{await wa.getState().handleSlashUndo(q),t?.()}catch(e){ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){kC(ae,g)&&ie(),await vn?.shortcut(`new`);return}if(e===`redo`&&q){try{await wa.getState().handleSlashRedo(q),t?.()}catch(e){ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&q){await Iw({command:`fork`,consumeCommandText:ie,forkSession:()=>wa.getState().forkCurrentSession(q),waitForConnection:oa,getDirectoryForSession:()=>wa.getState().getDirectoryForSession(q),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&q&&bi.timeline){Dr(!0);return}if(e===`reload`&&m()){ie(),ji.info(l(`chat.chatInput.toast.reloadStarted`)),zi().then(()=>{ji.success(l(`chat.chatInput.toast.reloadSucceeded`))},()=>{ji.error(l(`chat.chatInput.toast.reloadFailed`))});return}if(e===`compact`&&q){Iw({command:`compact`,consumeCommandText:ie,forkSession:async()=>void 0,waitForConnection:oa,getDirectoryForSession:()=>_n.directory??``,summarizeSession:e=>En?_n.backend.compact({operation:`compact`,surfaceID:_n.surfaceID,transportIdentity:_n.transportIdentity,runtimeGeneration:_n.runtimeGeneration,sessionID:q,directory:e,draftKey:En,deliveryTarget:_n.deliveryTarget,providerID:c,modelID:d,agent:v,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{ji.error(l(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&q){try{await oa();let e=ae.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 za(`session.summary.visible`,{topic_line:n}),a=await za(`session.summary.instructions`,{topic_block:r});await kn(i,c,d,v,[],D,[{text:a,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(q||Sn)){try{await oa();let e=await za(`session.review.visible`),n=await za(`session.review.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&q&&!dr&&!m()){Fn(!0);return}if(e===`goal`&&(q||Sn)){N(),Or.getState().setArmed(!0);let e=DC(ae,g)??``;Nr(e),mi.current=e,be(-1),e||Er(!1);return}if(e===`craft-goal`&&(q||Sn)){try{await oa();let e=ae.replace(/^\/\u2003?craft-goal\b/i,``).trim(),n=await za(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),r=await za(`session.craftGoal.instructions`);await kn(n,c,d,v,[],D,[{text:r,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(q||Sn)){try{await oa();let e=await za(`session.catchup.visible`),n=await za(`session.catchup.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(q||Sn)){try{await oa();let e=await za(`session.debug.visible`),n=await za(`session.debug.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(q||Sn)){try{await oa();let e=await za(`session.weigh.visible`),n=await za(`session.weigh.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(q||Sn)){try{await oa();let e=await za(`session.explore.visible`),n=await za(`session.explore.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.exploreFailed`))}return}}let oe=q&&wa.getState().getDirectoryForSession(q)||Tn;if(wn||q&&!PE(q,oe)){let e=await Tr().catch(()=>null);e&&O.push({text:mt(e),synthetic:!0})}te=!0;let se=kn(T,c,d,v,E,D,O.length>0?O:void 0,x,g,S);H=!0,se.finally(()=>{L(),ls(),W&&Ci(ee,yn.captureRuntime())&&wa.getState().endMessageEditCommit(W.sessionId,W.messageId)}).catch(()=>{}),j&&se.then(()=>{P(j)}).catch(()=>{$a.getState().clearEstablishing(j)}),typeof window>`u`?t?.():window.requestAnimationFrame(()=>{t?.()}),se.then(async()=>{if(u&&I&&e){let t=()=>{ys(e=>{if(!e.has(I))return e;let t=new Set(e);return t.delete(I),t})};if(tt(e,I)||!dt({sessionID:e}))t();else{let n=wa.getState().getDirectoryForSession(e)??Tn??``;try{await ct({sessionID:e,inboxID:I,directory:n})}catch{t(),Qe.getState().list(e).some(e=>e.id===I)&&ji.error(l(`chat.chatInput.toast.messageSendFailed`))}}}eo&&to(null),ro&&io(null)}).catch(e=>{U&&Pa(U),G().then(e=>{e||ji.error(l(`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`)){ji.error(l(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){_.length>0&&ji.error(l(`chat.chatInput.toast.sendAttachmentsFailed`));return}ji.error(t||l(`chat.chatInput.toast.messageSendFailed`))}),dr||Yr.current?.focus()}finally{te||(U&&Pa(U),W&&Ci(ee,yn.captureRuntime())&&wa.getState().endMessageEditCommit(W.sessionId,W.messageId)),H||(L(),F&&h&&(Hr(h),V()),ls(),j&&P(j))}}),Fs=J(()=>{if(EC(ts().message,g)===`btw`){Ns();return}if(ws()||us())return;let e=ts(),t=g===`normal`&&e.hasContent&&q&&($o||Ro),n=t&&W_(so.mode)&&Pr(_n.deliveryTarget?.kind,so.mode),r=Ww({followUpBehavior:ao,ctrlEnter:!1,canQueue:!!t,queueUsable:!!n,primary:_n.kind===`primary`,sessionIsRunning:$o,autoReviewRunning:Ro});r.kind===`queue`?Es():r.delivery?Ns({delivery:r.delivery}):Ns()}),Is=J(e=>{if(us())return;let t=(Yr.current?.value??mi.current).trim(),n=t?`${e}\n${t}`:e;Ns({presetText:n})}),Ls=J(e=>{let t=sD(_i().text,e);Kr(t),Yr.current&&(Yr.current.value=t),setTimeout(()=>{Yr.current?.focus()},0)}),zs=Z.useRef(null),Bs=J(()=>{Va(null);let e=_i().text;zs.current={base:e,expected:e}}),Vs=J((e,t=!1)=>{let n=zs.current;if(!n)return;if(_i().text!==n.expected){zs.current=null,Va(null);return}let r=sD(n.base,e),i=e.trim();Va(t||!i?null:{draftID:on,text:r,start:r.length-i.length-1,end:r.length-1}),r!==n.expected&&(Kr(r),Yr.current&&(Yr.current.value=r),n.expected=r),t&&(zs.current=null)}),Hs=J(e=>Vs(e,!0)),Us=J(()=>{Va(null),zs.current=null}),qs=J(e=>{if(us())return;let t=sD(Yr.current?.value??mi.current,e);Ns({presetText:t})}),Js=Z.useRef(null),Ys=J(e=>{let t=_i().text,n=sD(t,e);Js.current={base:t,expected:n},Kr(n),Yr.current&&(Yr.current.value=n)}),Xs=J((e,t)=>{let n=Js.current;if(Js.current=null,!n||_i().text!==n.expected)return;let r=sD(n.base,e);Kr(r),Yr.current&&(Yr.current.value=r),t&&Fs()}),Zs=J(e=>Xs(e,!1)),Qs=J(e=>Xs(e,!0)),$s=J(()=>{Js.current=null}),ec=yn.pendingPreset,tc=yn.consumePendingPreset;Z.useEffect(()=>{if(ec==null)return;let e=tc();e&&Is(e)},[ec,tc,Is]);let nc=J(()=>{Nr(``),be(-1),bn.length>0&&yn.clearAttachments(),oo&&So(oo),D(!1),C(!1),g===`shell`&&_(`normal`)}),rc=J(e=>{if(!_n.active||vl(e))return;if(ki&&Tc(e,ki)&&!yr){let t=Yr.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),nc();return}}if(g===`shell`&&e.key===`Escape`){e.preventDefault(),_(`normal`);return}if(g===`shell`&&e.key===`Backspace`&&Mr.length===0){e.preventDefault(),_(`normal`);return}if(e.key===`Backspace`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&Wo.length>0){let t=Yr.current,n=t?.selectionStart??0,r=t?.selectionEnd??0;if(n===0&&r===0&&Uo){e.preventDefault(),o_.getState().removeLast(Uo);return}}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Yr.current,n=t?.selectionStart??Mr.length,r=t?.selectionEnd??Mr.length,i=Rr({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=NE(Ar.getDocument().text,i.start);e.preventDefault(),Kr(t.text),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(t.caret,t.caret),Dc()}),Oc(t.text,t.caret);return}let a=Xe(Mr,bn.filter(Ce).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=NE(a.text,a.caret);e.preventDefault(),Kr(n.text);for(let e of bn)t.has(e.filename.toLowerCase())&&yn.removeAttachment(e.id);requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=n.caret,Yr.current.selectionEnd=n.caret),Dc()}),Oc(n.text,n.caret);return}let o=Il(Mr,ca.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=NE(o.text,o.caret);e.preventDefault(),Kr(t.text),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=t.caret,Yr.current.selectionEnd=t.caret),Dc()}),Oc(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=qe(Mr,bn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=Yt(Mr.slice(n.start+1,n.end-1)).trim(),r=bn.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(),Kr(a),r&&yn.removeAttachment(r.id),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=n.start,Yr.current.selectionEnd=n.start),Dc()}),Oc(a,n.start);return}let r=Gr.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(),Kr(n),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=r.range.start,Yr.current.selectionEnd=r.range.start),Dc()}),Oc(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(DE.test(o)&&!Zi.current.has(s.toLowerCase())&&ka({mention:s,confirmed:Jr.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(),Kr(n),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=i,Yr.current.selectionEnd=i),Dc()}),Oc(n,i);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(E&&pi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),pi.current.handleKeyDown(e.key);return}if(S&&di.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),di.current.handleKeyDown(e.key);return}if(Hi&&e.key===`Escape`){e.preventDefault(),Er(!1);return}let n=Oi&&!Oi.includes(`shift`)?hc(`shift+${Oi}`):``,r=n&&Tc(e,n)?-1:+!!Tc(e,Oi);if(r!==0&&!E&&!S){e.preventDefault(),e.stopPropagation(),vn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Yr.current?.focus({preventScroll:!0})});return}let i=E||S,a=Yr.current?.selectionStart===0&&Yr.current?.selectionEnd===0,o=Yr.current?.selectionStart===Mr.length&&Yr.current?.selectionEnd===Mr.length,s=!i&&(Mr.length===0||a),c=!i&&(Mr.length===0||o);if(g===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Yr.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),Kr(t),requestAnimationFrame(()=>{let e=Yr.current;e&&(e.selectionStart=n,e.selectionEnd=r),Dc()}),Oc(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&&No.length>0){if(e.preventDefault(),ye===-1)be(0),zr({text:No[0],references:[]});else if(ye<No.length-1){let e=ye+1;be(e),zr({text:No[e],references:[]})}requestAnimationFrame(()=>{Yr.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&ye>=0){if(e.preventDefault(),ye===0)be(-1),Br();else{let e=ye-1;be(e),zr({text:No[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),EC(ts().message,g)===`btw`){Ns();return}if(ws()||us())return;let t=e.ctrlKey||e.metaKey,n=g===`normal`&&Go&&q&&($o||Ro),r=n&&W_(so.mode)&&Pr(_n.deliveryTarget?.kind,so.mode),i=Ww({followUpBehavior:ao,ctrlEnter:t,canQueue:!!n,queueUsable:!!r,primary:_n.kind===`primary`,sessionIsRunning:$o,autoReviewRunning:Ro});i.kind===`queue`?Es():i.steerAfterAdmit?Ns({steerAfterAdmit:!0}):i.delivery?Ns({delivery:i.delivery}):Ns()}}),ic=J(()=>{if(!Hi){Wa(null);return}if(!E&&!S){Wa(null);return}let e=Yr.current,t=ti.current;if(!e||!t)return;let n=WE(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=S?520:E?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));Wa({top:l===`below`?a+22:a-6,left:d,place:l,maxHeight:f})});Z.useLayoutEffect(()=>{ic()},[ic,Mr,E,S,Hi]),qn(`resize`,ic,()=>Hi?window:null);let ac=J(()=>{Ga.current&&=(clearTimeout(Ga.current),null),Ri(!0),Ga.current=setTimeout(()=>{Ri(!1),Ga.current=null},1800)}),oc=Z.useRef(new Set),[sc,cc]=Z.useState(()=>new Set),lc=JSON.stringify([_n.transportIdentity,_n.runtimeGeneration,_n.surfaceID,_n.directory,q]),uc=es&&sc.has(lc),dc=J(async()=>{if(oc.current.has(lc))return;let e=lc;oc.current.add(e),cc(new Set(oc.current)),yn.abortPrompt.clear(),ac();let t;try{let e=_n.kind===`secondary`?vn?.shortcut(`abort`):An();await Promise.race([e,new Promise(e=>{t=setTimeout(()=>{_n.kind===`secondary`&&ji.error(l(`chat.chatInput.stopUnconfirmed`)),e()},5e3)})])}catch(e){console.error(`[ChatInput] abort failed`,e)}finally{clearTimeout(t),oc.current.delete(e),cc(new Set(oc.current))}}),fc=J((e=1)=>{if(sr)return;let t=li(ir,_n.selection.value.agent??Vn,e);if(!t||!_n.selection.change)return;let n=Ur({providerID:_n.selection.value.providerID??``,modelID:_n.selection.value.modelID??``,agent:_n.selection.value.agent??null},t,ir,or);_n.selection.change({..._n.selection.value,...n,agent:n.agent??void 0}),_n.kind===`primary`&&(K.getState().addRecentAgent(t),_n.sessionID&&ur.getState().saveSessionAgentSelection(_n.sessionID,t))});xe.current=fc;let[pc,mc]=Z.useState(null),[gc,_c]=Z.useState(!1),vc=Z.useRef(null),yc=Z.useRef(!0);Z.useLayoutEffect(()=>{yc.current=!0},[on]),Z.useLayoutEffect(()=>{let e=vc.current;e&&(gc||Na)&&yc.current&&(e.scrollLeft=e.scrollWidth)},[Mr,gc,Na]);let bc=J(e=>{mc(t=>t===e?t:e)}),xc=dr&&!ha&&!Gi&&Mr.length>0,[Sc,Cc]=Z.useState(!1),{size:wc,resize:Dc}=qT({inputRef:Yr,message:Mr,expanded:Gi,isMobile:dr,dictationHeight:pc,manualHeight:xc&&Sc});Z.useLayoutEffect(()=>{if(!dr||!gc)return;let e=Yr.current;e&&(e.style.overflowY=`auto`,e.scrollTop=e.scrollHeight,Bi.current&&(Bi.current.style.transform=`translateY(-${e.scrollTop}px)`))},[dr,gc,Mr]);let Oc=J((e,t,n=`manual`,r)=>{let i=Vl({text:e,cursor:t,inputMode:g,mentionInputSource:n,insertedText:r});if(ei.current=i,!i){D(!1),C(!1);return}if(i.kind===`slash-command`){k(i.query),D(!0),C(!1);return}D(!1),T(i.query),C(!0)}),kc=J((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(g===`normal`&&!Qr.current&&la.size>0&&e.includes(`/`)){let r=Ul(e,la,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=Ir(a,o,s,(e,t)=>{let n=[...e];for(let i of _o(t.text,{agentNames:Xi,includeUnterminatedPastedReferences:r===`paste`,confirmedValues:new Set(e.flatMap(e=>e.kind===`file`||e.kind===`directory`?[e.value]:[]))}))n=su(n,{kind:i.kind,value:i.value,path:i.value,label:i.value,range:{start:i.start,end:i.end}});return n}),l=_i(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Yr.current;e&&Ay(u,Qr.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),Dc()}),Oc(l.text,c.end,r,i),{document:l,selection:c}}),Ac=J((e,t=`manual`)=>{if(!e)return;let n=Yr.current;if(!n){let n=Mr+e;kc(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;kc(a,o,o,t,e)}),jc=J((e,t)=>{let n=new Set(se(bn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of bn)n.has(e.filename)&&yn.removeAttachment(e.id)}),Mc=J(e=>{yn.removeAttachment(e.id)}),Nc=J(()=>{ri.current=!1,ci.current=[],ii.current&&=(clearTimeout(ii.current),null)}),Pc=J(()=>{ii.current&&clearTimeout(ii.current),ii.current=setTimeout(()=>{Nc()},700)}),Fc=J(()=>{oi.current=!1,si.current&&=(clearTimeout(si.current),null)}),Ic=J(()=>{oi.current=!0,si.current&&clearTimeout(si.current),si.current=setTimeout(()=>{oi.current=!1,si.current=null},700)}),Lc=J(e=>{!m()||!ri.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),Nc())}),Rc=J(e=>{if(yr)return;let t=e.nativeEvent;if(m()&&ri.current){let n=ci.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){Nc();return}}let n=e.target.value;jc(mi.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?jE(mi.current,n):``,a=i.includes(`@`)||oi.current;oi.current&&Fc();let o=a?`paste`:`manual`;if(g===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);_(`shell`),Nr(e),Dc(),D(!1),C(!1),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=t,Yr.current.selectionEnd=t)});return}kc(n,r,e.target.selectionEnd??r,o,i)});Z.useEffect(()=>()=>{Nc(),Fc()},[Nc,Fc]);let zc=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=Yr.current,i=r?.selectionStart??Mr.length,a=r?.selectionEnd??Mr.length,o=ru(n,Mr.slice(0,i),Mr.slice(a)),s=`${Mr.slice(0,i)}${o}${Mr.slice(a)}`;jc(Mr,s),yi(s,t);let c=fu(s,i+o.length);$r.current=c,C(!1),T(``),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(c,c),Dc(),Oc(s,c)})}),Bc=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=zE(e.clipboardData);if(r.length===0&&i.length>0&&(q||Sn)){e.preventDefault(),zc(i);return}if(r.length===0&&g===`normal`&&(q||Sn)){let t=Yr.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(kE.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;Kr(a),requestAnimationFrame(()=>{let e=Yr.current;e&&(e.selectionStart=o,e.selectionEnd=o),Dc()}),Oc(a,o,ME(t),t);return}}}let a=e.clipboardData.getData(`text`),o=r.length>0&&i.includes(uC(a.trim().replace(/^(['"])(.*)\1$/,`$2`)))?``:a;if(r.length===0){if(g===`normal`&&kT(_i(),o)){e.preventDefault();let t=_i().text,n=Yr.current,r=n?.selectionStart??Mr.length,i=n?.selectionEnd??Mr.length,a=AT(o,Mr,_i().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})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),OT(_i())),s=Lr(r,i,{id:a.id,kind:`paste`,text:a.text,characterCount:a.characterCount,index:a.index,display:a.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=fu(s.document.text,s.caret);Yr.current&&(Yr.current.value=s.document.text),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(c,c),Dc()}),Oc(s.document.text,c),jc(t,s.document.text);return}o.includes(`@`)&&Ic();return}if(!q&&!Sn){o.includes(`@`)&&Ic();return}e.preventDefault();let s=ft(r,[...bn.map(e=>e.filename),...hi.current]),c=Me(s),u=_i().text,d=Yr.current,f=d?.selectionStart??Mr.length,p=d?.selectionEnd??Mr.length,m=g===`normal`&&kT(_i(),o)?AT(o,Mr,_i().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})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),OT(_i())):null,h=o?`${o}${/\s$/.test(o)?``:` `}${c}`:c,_=ru(h,Mr.slice(0,f),Mr.slice(p));if(m){let e=Lr(f,p,{id:m.id,kind:`paste`,text:m.text,characterCount:m.characterCount,index:m.index,display:m.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=fu(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${c}${e.document.text.slice(t)}`;kc(n,t+c.length,t+c.length,ME(n),c),jc(u,n)}else Ac(_,ME(_)),jc(u,`${Mr.slice(0,f)}${_}${Mr.slice(p)}`);for(let e=0;e<r.length;e+=1){let t=s[e],n=AE(r[e],t);hi.current.add(t);try{await yn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.clipboardAttachFailed`))}finally{hi.current.delete(t)}}}),Vc=J((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=bl(r,i,[...qe(Mr,bn.filter(Ce).map(e=>e.filename)),...Dl(Mr,ca.keys()),..._i().references]),o=a?.start??r,s=a?.end??i,c=Mr.slice(o,s),l=rn(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)}`;kc(e,o,o),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(o,o),Dc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Yr.current?.setSelectionRange(o,s)})}),Hc=J(e=>{Vc(e,`copy`)}),Uc=J(e=>{Vc(e,`cut`)}),Wc=e=>{let t=Yr.current,n=t&&document.activeElement===t?t.selectionStart??$r.current:$r.current;return Vu(e,n)},Gc=()=>{Ou(dr)||Yr.current?.focus()},Kc=J(e=>{let t=Wc(Mr.length),n=Hl(Mr,t,ei.current),r=Mr.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():el(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=uu(Mr,o,s,`@${i}`);yi(c.text,[i],a),$r.current=c.caret,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=c.caret,Yr.current.selectionEnd=c.caret),Dc(),Oc(c.text,c.caret)}),C(!1),T(``),Gc()}),qc=J(e=>{let t=Wc(Mr.length),n=Hl(Mr,t,ei.current),r=Mr.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=uu(Mr,i,a,`@${e}`);Kr(o.text,t=>su(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),$r.current=o.caret,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=o.caret,Yr.current.selectionEnd=o.caret),Dc(),Oc(o.text,o.caret)}),C(!1),T(``),Gc()}),Jc=J(e=>{fi.current||(fi.current=!0,(async()=>{try{let t=wa.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){ji.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await Ke(e.id,{directory:t}),!ve(e.id,t)){ji.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}!dr&&!$e()&&!xo()&&lo([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=_i(),r=Wc(n.text.length),i=Hl(n.text,r,ei.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=ge().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,u={id:`session:${e.id}:${Ct()}`,kind:`session`,sessionId:e.id,display:cn({trigger:`@`,icon:`chat-thread`,label:o})},d=Lr(s,c,u,{inlineBoundaries:!0,padDocumentEdges:!0}),f=fu(d.document.text,d.caret);$r.current=f,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=f,Yr.current.selectionEnd=f),Dc(),Oc(d.document.text,f)}),C(!1),T(``),Gc()}catch{ji.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{fi.current=!1}})())}),Yc=J(e=>{let t=_i(),n=Wc(t.text.length),r=Hl(t.text,n,ei.current)??Zl(t.text,n);if(!r)return!1;let i=Lr(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=fu(i.document.text,i.caret);return $r.current=o,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=o,Yr.current.selectionEnd=o),Dc(),Oc(i.document.text,o),a&&(D(!1),C(!1))}),Gc(),a}),Xc=J(e=>{let t=_i(),n=Wc(t.text.length),r=Hl(t.text,n,ei.current);if(!r)return;let i=Lr(r.start,r.end,{id:`skill:${e.name}:${Ct()}`,kind:`skill`,skillName:e.name,display:cn({trigger:`@`,icon:`book-open`,label:e.name})},{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=fu(i.document.text,i.caret);$r.current=a,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=a,Yr.current.selectionEnd=a),Dc(),Oc(i.document.text,a),C(!1),T(``)}),Gc()}),Zc=J((e,t=!1)=>{if(!Fy(_n,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Yc({id:`skill:${e.name}:${Ct()}`,kind:`skill`,skillName:e.name,display:cn({trigger:`@`,icon:`book-open`,label:e.name})})&&k(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Yc({id:`command:${e.name}:${Ct()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:cn({trigger:`/`,icon:`command`,label:e.name})})){k(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=Ul(r,new Set([...la,e.name.toLowerCase()]),r.length);if(e.name===`btw`){let e=_i(),t=Zl(e.text,Yr.current?.selectionStart??e.text.length);if(t){let n=i?.text??r;Kr(e.text.slice(0,t.start)+n+e.text.slice(t.end))}}else Nr(i?.text??r);let a=Yr.current;if(a&&(a._commandMetadata=e),D(!1),k(``),t){Ns({presetText:n});return}let o=()=>{if(!Ou(dr)&&Yr.current){try{Yr.current.focus({preventScroll:!0})}catch{Yr.current.focus()}Yr.current.setSelectionRange(Yr.current.value.length,Yr.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)});Z.useEffect(()=>{q&&Yr.current&&!dr&&Yr.current.focus()},[q,dr]),Z.useEffect(()=>{dr||F(null)},[dr]);let Qc=yn.abortPrompt.sessionID,$c=yn.abortPrompt.clear;Z.useEffect(()=>{Qc&&Qc!==q&&$c()},[q,Qc,$c]),Z.useEffect(()=>{ui.current=!!(q||Sn)},[q,Sn]);let el=J(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(Mi||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t}),tl=J(e=>{if(!GE(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),ni.current++;let t=e.dataTransfer.types?.includes(`application/x-yuri-file-path`)??!1;t!==b&&x(t),(q||Sn)&&!v&&y(!0)}),nl=J(e=>{GE(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(q||Sn)&&!v&&y(!0))}),rl=J(e=>{e.preventDefault(),e.stopPropagation(),ni.current--,ni.current<=0&&(ni.current=0,y(!1),x(!1),Nc())}),il=J(()=>{ni.current=0,y(!1),x(!1),Nc()}),al=J(async e=>{if(ni.current=0,!GE(e.dataTransfer)){Nc();return}if(e.preventDefault(),e.stopPropagation(),y(!1),!q&&!Sn)return;let t=e.dataTransfer.getData(`application/x-yuri-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Yr.current,r=mi.current;if(n){let t=n.selectionStart??$r.current,i=n.selectionEnd??t,a=uu(r,t,i,e);Kr(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,$r.current=a.caret,n.focus()})}else{let t=uu(r,r.length,r.length,e);Kr(t.text)}Nc();return}let n=zE(e.dataTransfer);if(n.length>0){m()&&(ci.current=n),zc(n),m()||Nc();return}let r=KE(e.dataTransfer);if(r.length>0){let e=Me(r.map(e=>e.name)),t=ru(e,mi.current.slice(0,Yr.current?.selectionStart??mi.current.length),mi.current.slice(Yr.current?.selectionEnd??mi.current.length));Ac(t);for(let e of r)try{await yn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}}Nc()}),ol=J(e=>{GE(e.dataTransfer)&&(e.preventDefault(),m()&&(ri.current=!0,Pc()))}),cl=Z.useRef(null),ll=Z.useRef(null),ul=J((e=!0)=>{pe.current=0;let t=()=>{let t=Oy(Yr);if(!t||(ky(Yr),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),pl=J(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Me(t.map(e=>e.name)),n=ru(e,mi.current.slice(0,Yr.current?.selectionStart??mi.current.length),mi.current.slice(Yr.current?.selectionEnd??mi.current.length));Ac(n)}for(let e of t)try{await yn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}}),hl=J(async()=>{try{let e=await Si?.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(`
|
|
6553
|
-
`);ji.error(l(`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&&(
|
|
6554
|
-
`)})),e.length!==0&&pl(e)},onRemoveAttachment:e=>{yn.removeAttachment(e)},onOpenModel:()=>zo(`model`),onCycleAgent:()=>fc(),onOpenAgent:ks,showScrollToBottom:!!(n&&r),scrollAria:l(`chat.scrollToBottom.aria`),onScrollToBottom:r??(()=>{}),autocompleteOpen:A.length>0&&(E||S),autocompleteHighlightedIndex:M,autocompleteRows:A,autocompleteQuery:S?w:O,caret:$r.current,onAutocompleteAccept:Fu,onAutocompleteDismiss:Iu,chipHighlights:Ha}),zu=Z.useRef(null);Hn(Ru?zu:null,()=>{let e=zu.current?.getBoundingClientRect().height??0;Lu(document.documentElement,e)});let Bu=Z.useRef(!1);Bu.current=Ka||Xa;let Hu=Z.useRef(!1),Uu=Z.useRef(0),Wu=Z.useRef(0),Gu=J(()=>{let e=wa.getState().stagedMessageEdit;!e||e.sessionId!==q||window.setTimeout(()=>{let t=wa.getState().stagedMessageEdit,n=document.activeElement,r=zw({surfaceKind:_n.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:us(),focusHeld:Date.now()<Wu.current,overlayOpen:Uu.current>0||Bu.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<pe.current});r.action===`disarm`&&wa.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!dr||$e()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Uu.current+=1},t=()=>{if(Uu.current=Math.max(0,Uu.current-1),Hu.current){Hu.current=!1;return}if(!_e.current||Bu.current||Uu.current>0)return;if(fl()){_e.current=!1;return}_e.current=!1,Wu.current=Date.now()+600,Yr.current?.focus(),document.activeElement===Yr.current&&z(!0);let e=()=>{let e=Yr.current;!e||document.activeElement!==e||(Ku.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)}},[dr]),Z.useEffect(()=>{if(!dr)return;if(Eu){(R||Date.now()-he.current<800)&&(_e.current=!0);return}if(!_e.current)return;let e=window.setTimeout(()=>{if(_e.current=!1,fl())return;let e=Yr.current;e&&document.activeElement!==e&&e.focus({preventScroll:$e()})},180);return()=>window.clearTimeout(e)},[dr,Eu,R]),Z.useEffect(()=>{if(!dr||$e()||typeof document>`u`||R||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Yr.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[dr,R]),Z.useEffect(()=>{G(``)},[ee]);let Ku=Z.useRef(null),qu=dr&&_n.kind===`primary`&&!Ru,Ju=Z.useRef(null),Yu=Z.useRef(null),Zu=J(()=>{if(!qu)return;let e=Ku.current;if(!e?.closest(`.yuri-mobile-composer-foot--overlay`))return;let t=zu.current?.offsetHeight??0;if(Yu.current===null){if(e.offsetHeight<=0)return;Yu.current=Math.max(0,e.offsetHeight-t)}let n=hE(document.documentElement,Yu.current+t);n!==null&&(Ju.current=n)});Hn(qu?zu:null,Zu),Z.useEffect(()=>{if(qu)return()=>{gE(document.documentElement,Ju.current),Ju.current=null,Yu.current=null}},[qu]);let Qu=dr?`px-1.5 py-1.5`:Al?`px-1.5 py-1`:`px-2.5 py-1.5`,$u=dr?`h-8 w-8`:Al?`h-5 w-5`:`h-6 w-6`,ed=dr?`h-4 w-4`:Al?`h-3.5 w-3.5`:`h-4 w-4`,td=dr?`h-6 w-6`:`size-full`,nd=dr?`h-[1.125rem] w-[1.125rem]`:Al?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,rd=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,py),id=Y(rd,$u),ad=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`,$u),od=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(()=>()=>{Ga.current&&=(clearTimeout(Ga.current),null)},[]);let sd=(0,$.jsx)(Wh,{quotes:Wo,removeLabel:l(`chat.btw.removeQuoteAria`),onRemove:e=>{Uo&&o_.getState().removeQuote(Uo,e)}}),cd=dr?(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)(QE,{onOpenAgentPanel:ks,onCycleAgent:()=>{me(),fc()},agentName:_n.selection.value.agent,agents:ir,disabled:lr}),(0,$.jsx)($E,{onOpenModel:()=>zo(`model`),providerID:_n.selection.value.providerID,modelID:_n.selection.value.modelID,provider:or.find(e=>e.id===_n.selection.value.providerID),variant:_n.selection.value.variant})]}):null,ld=(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)(lg,{attachments:bn,onShowPopup:hr,onRemoveAttachedFile:Mc}),_n.kind===`primary`?(0,$.jsx)(pg,{attachedFiles:bn,onAddVSCodeFile:(e,t,n)=>{En&&ea(En,()=>va.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(En)return ea(En,()=>va.getState()).addVSCodeSelection(e,t)}}):null]}),ud=Ha?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Nl,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),dd=!dr&&La?(0,$.jsxs)($.Fragment,{children:[ud??Mr,(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`yuri-dictation-caret`,children:Ba?.draftID===on&&Ba.text===Mr&&(0,$.jsx)(`span`,{className:`yuri-dictation-caret-trail`},Mr)})]}):ud,fd=dr&&xa?(0,$.jsx)(er,{variant:`ghost`,size:`icon`,className:id,"data-composer-action":`true`,"aria-label":l(Na?`settings.voice.volcengine.finishRecording`:`chat.dictation.start`),"aria-pressed":Na,disabled:!Na&&(xn||gc||Sa!==null||!q&&!Sn),onClick:()=>window.dispatchEvent(new Event(`yuri:mobile-dictation-toggle`)),children:(0,$.jsx)(X,{name:`mic`,className:Y(nd,Na&&`text-[var(--voice-active-fill)]`)})}):null,pd=dr?(0,$.jsxs)(`div`,{className:Y(`yuri-mobile-composer-compact-chrome`,es&&`yuri-mobile-composer-compact-chrome--aborting`,Zo&&!es&&`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)(rD,{isVSCode:Al,footerIconButtonClass:id,iconSizeClass:nd,handlePickLocalFiles:xl,handlePickLocalImages:Sl,openIssuePicker:As,openPrPicker:js,onOpenMobileSheet:wu,onOpenAndroidPickSheet:pr?Tu: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,fd,es||Zo||uc?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(aD,{isMobile:!0,compact:!0,footerIconButtonClass:id,stopFooterIconButtonClass:ad,compactCircleButtonClass:od,sendIconSizeClass:ed,stopIconSizeClass:td,canSend:Zo,canAbort:es,abortPending:uc,hasContent:!1,currentSessionId:q,newSessionDraftOpen:Sn,draftSubmitting:xn,submissionBlocked:a,sendPhase:ss,queueFrozen:Xo,queueFallbackAvailable:es||$o,onPrimaryAction:Fs,onAbort:dc})}):null]})]}):null,md=dr?(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)(rD,{isVSCode:Al,footerIconButtonClass:id,iconSizeClass:nd,handlePickLocalFiles:xl,handlePickLocalImages:Sl,openIssuePicker:As,openPrPicker:js,onOpenSettings:e,onOpenMobileSheet:wu,onOpenAndroidPickSheet:pr?Tu:void 0}),Wn?(0,$.jsx)(iD,{sessionId:q,draftOpen:Sn,draftEnabled:vt.permissionAutoAcceptEnabled===!0,enabled:zn,saving:q?kt:!1,footerIconButtonClass:id,iconSizeClass:nd,onSetDraftEnabled:Et,onSetSessionEnabled:jt,onOpenSessionFirst:Tt,onToggleFailed:Gn}):null,(0,$.jsx)(vC,{sessionId:q,directory:Je??Tn,draftOpen:Sn}),(0,$.jsx)(yC,{length:Mr.length}),xa&&(0,$.jsx)(ZE,{interactionMode:`mobile`,disabled:xn||Sa!==null||!q&&!Sn,onRecordingChange:Fa,onActiveChange:_c,className:id,iconClassName:nd,onStart:Bs,onPartial:Vs,onInsert:Hs,onCancel:Us},on)]}),cd,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(aD,{isMobile:dr,footerIconButtonClass:id,stopFooterIconButtonClass:ad,sendIconSizeClass:ed,stopIconSizeClass:td,canSend:Zo,canAbort:es,abortPending:uc,hasContent:!!Go,currentSessionId:q,newSessionDraftOpen:Sn,draftSubmitting:xn,submissionBlocked:a,sendPhase:ss,queueFrozen:Xo,queueFallbackAvailable:es||$o,onPrimaryAction:Fs,onAbort:dc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,Tl,La&&`[&>*:not([data-dictation-control])]:opacity-40`),children:[(0,$.jsx)(rD,{isVSCode:Al,footerIconButtonClass:id,iconSizeClass:nd,handlePickLocalFiles:xl,handlePickLocalImages:Sl,openIssuePicker:As,openPrPicker:js,onOpenSettings:e,withTooltip:!0}),Wn?(0,$.jsx)(iD,{sessionId:q,draftOpen:Sn,draftEnabled:vt.permissionAutoAcceptEnabled===!0,enabled:zn,saving:q?kt:!1,footerIconButtonClass:id,iconSizeClass:nd,onSetDraftEnabled:Et,onSetSessionEnabled:jt,onOpenSessionFirst:Tt,onToggleFailed:Gn}):null,(0,$.jsx)(vC,{sessionId:q,directory:Je??Tn,draftOpen:Sn}),(0,$.jsx)(yC,{length:Mr.length}),ya&&!m()&&sl()&&(0,$.jsx)(ZE,{inputRef:Yr,onActiveChange:Ra,onRecordingChange:Fa,className:id,iconClassName:nd,onStart:Bs,onPartial:Vs,onInsert:Hs,onCancel:Us},on)]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,Tl,La&&`opacity-40`),children:[(0,$.jsx)(JE,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Yr,selectionAdapter:$n}),(0,$.jsx)(aD,{isMobile:dr,footerIconButtonClass:id,stopFooterIconButtonClass:ad,sendIconSizeClass:ed,stopIconSizeClass:td,canSend:Zo,canAbort:es,abortPending:uc,hasContent:!!Go,currentSessionId:q,newSessionDraftOpen:Sn,draftSubmitting:xn,submissionBlocked:a,sendPhase:ss,queueFrozen:Xo,queueFallbackAvailable:es||$o,onPrimaryAction:Fs,onAbort:dc})]})]}),hd=J(()=>{if(dr){Wu.current=Date.now()+600;let e=()=>{Yr.current?.focus({preventScroll:$e()}),document.activeElement===Yr.current&&z(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!ky(Yr))return;let e=Oy(Yr);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),gd=Je??Tn,_d=_n.kind===`secondary`?_n.directory:Je,{goal:vd,enabled:yd}=fC(q??``,gd),xd=(0,$.jsx)(Ov,{onEditMessage:Ds,onSendMessage:Os,onEditCommitted:hd,draftKey:En,scope:oo,draftTarget:En?{key:En,expectedRevision:()=>yn.getDraft(En)?.revision??`absent`}:null,clientPendingItems:xs,compactionBarrier:Ss,steeringMessageIDs:vs,onSteerClientPending:e=>{if(!q||!dt({sessionID:q}))return;let t=Je??Tn??``,n=q;return ys(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n}),ct({sessionID:n,inboxID:e,directory:t}).catch(()=>{ys(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),ji.error(l(`chat.chatInput.toast.messageSendFailed`))})},onQueueClientPending:e=>{q&&We({sessionID:q,inboxID:e,directory:Je??Tn??``}).then(()=>{nt(q,e,`queue`)}).catch(()=>{ji.error(l(`chat.chatInput.toast.messageSendFailed`))})},onRemoveClientPending:e=>{let t=$a.getState().removeEstablishingFollowUp(e);if(!t){q&&Re({sessionID:q,inboxID:e,directory:Je??Tn??``}).catch(()=>{ji.error(l(`chat.chatInput.toast.messageSendFailed`))});return}t.content&&Nr(t.content),t.attachments.length>0&&yn.restoreAttachments(t.attachments)},trailing:q&&yd&&vd?(0,$.jsx)(_C,{sessionId:q,directory:gd}):null});return(0,$.jsxs)($.Fragment,{children:[_n.kind===`primary`&&q?(0,$.jsx)(Aw,{scope:{sessionId:q,directory:Tn},active:_n.active,mobile:dr}):null,(0,$.jsxs)(`form`,{ref:Ku,onSubmit:e=>{e.preventDefault(),Fs()},onPointerDownCapture:e=>{dr&&Dy(e,me)},className:Y(`relative w-full pt-0 pb-4`,Hi&&`flex h-full min-h-0 flex-col pt-4`,Ui&&`flex h-full min-h-0 flex-col pt-1`,dr&&`bottom-safe-area yuri-mobile-composer`),"data-native-ios-composer":Ru?`true`:void 0,"data-hold-to-talk":xa?`true`:void 0,"data-hold-to-talk-empty":xa&&Mr.length===0?`true`:void 0,"data-dictation-hint":xa?Sa??void 0:void 0,style:dr&&$e()&&!Ru&&br>0&&!R?{marginBottom:`${br}px`}:void 0,children:[wn&&!Hi&&!dr&&!Al&&!vu?(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:HE(Ll?l(`chat.emptyState.draftTitleWithProject`,{project:Ll}):l(`chat.emptyState.draftTitle`),Ll)})}):null,xa&&(0,$.jsx)(gl,{containerRef:Ku,disabled:!q&&!Sn||xn||gc,onInsert:Zs,onSend:Qs,onRelease:Ys,onError:$s,onHintChange:Ea},En?gn(En):q??`new`),(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Gi&&`flex flex-1 min-h-0 flex-col`),children:[Ru?null:(0,$.jsx)(ug,{attachments:bn,onShowPopup:hr,onRemoveAttachedFile:Mc}),(0,$.jsx)(Jv,{}),To&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[Oo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:Ai?.colors?.surface?.elevated,borderColor:Ai?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:Ai?.colors?.status?.info},children:Oo}),(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:Mo,"aria-label":l(`chat.chatInput.reviewCommentsRemove`),title:l(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Eo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:Ai?.colors?.surface?.elevated,borderColor:Ai?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:Ai?.colors?.status?.info},children:Eo}),(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:()=>jo(`preview-console`),"aria-label":l(`chat.chatInput.devServerLogsRemove`),title:l(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Do>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:Ai?.colors?.surface?.elevated,borderColor:Ai?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:Ai?.colors?.status?.info},children:Do}),(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:()=>jo(`preview-annotation`),"aria-label":l(`chat.chatInput.previewContextRemove`),title:l(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),eo&&!Al&&(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:()=>qa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[eo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:eo.author.avatarUrl,alt:eo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,eo.number,eo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:eo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:eo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:eo.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":l(`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:()=>{to(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.issue.removeAria`),title:l(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),ro&&!Al&&(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:()=>Qa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[ro.author?.avatarUrl&&(0,$.jsx)(`img`,{src:ro.author.avatarUrl,alt:ro.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[l(`chat.chatInput.linked.pr.number`,{number:ro.number}),ro.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:ro.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:ro.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[ro.head,` → `,ro.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:ro.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":l(`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:()=>{io(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.pr.removeAria`),title:l(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(tD,{sessionId:q,directory:Je??Tn}),(0,$.jsxs)(`div`,{className:dr?`relative yuri-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:dr?`yuri-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:dr?`yuri-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:zu,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(eD,{className:dr?`mb-0`:void 0,showAbortStatus:Li,showAbortPrompt:!!(Hi&&q&&It===q&&typeof Lt==`number`&&Lt>Date.now()),showAssistantStatus:!1,showTodos:!0,leftAccessory:Sn||!yu?null:(0,$.jsx)(ux,{})}),!dr&&Ml?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Pl?(0,$.jsxs)(Rs,{value:Pl.id,open:ce,onValueChange:Su,onOpenChange:e=>{ue(e),e||ae(``)},children:[(0,$.jsx)(Ms,{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]`,dy),children:[(0,$.jsx)(Ws,{children:qE(Pl)}),(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)(Ps,{fitContent:!0,children:[(0,$.jsx)(Ks,{autoFocus:!0,value:ie,onChange:e=>ae(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),(0,$.jsx)(nD,{projects:jn,query:ie,renderLabel:qE}),(0,$.jsx)(Gs,{}),(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(),ue(!1),requestAnimationFrame(()=>ga.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`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`,dy),onClick:()=>ga.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Pl&&xu?(0,$.jsx)(YS,{directory:du,projectDirectory:Fl,label:_u,projectRootOption:cu,worktreeOptions:lu,onSelectDirectory:Cu}):null]}):null,dr&&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:[Pl?(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`,dy),onClick:()=>te(`project`),children:qE(Pl)}):(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`,dy),onClick:()=>ga.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Pl&&xu?(0,$.jsx)(YS,{directory:du,projectDirectory:Fl,label:_u,projectRootOption:cu,worktreeOptions:lu,onSelectDirectory:Cu,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,_n.active&&q&&_d?(0,$.jsx)(Wv,{sessionId:q,directory:_d}):null,xd]})}),(0,$.jsx)(`div`,{className:Y(!dr&&`contents`,dr&&`contents`,Ui&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:dr?`yuri-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(zl,{value:Mr,attachments:[],disabled:!q&&!Sn||xn&&!ss.establishing,pending:es||ss.inFlight&&!ss.establishing,isMobile:dr,onSubmit:Fs,"data-mobile-composer-surface":dr?`true`:void 0,expanded:Gi,className:Y(`relative z-10`,La&&`!ring-0 [&_textarea]:caret-transparent`,v&&`ring-2 ring-primary ring-offset-2`,yr&&`ring-1 ring-[var(--interactive-selection)]`,dr&&`yuri-mobile-composer-surface`),style:{borderRadius:Ki,...La?{borderColor:`var(--voice-active-fill)`}:{}},ref:ti,onDropCapture:ol,onDragEnter:tl,onDragOver:nl,onDragLeave:rl,onDrop:al,onDragEnd:il,autoResize:!1,disableInputWhilePending:!1,contentClassName:Gi?`flex-1 min-h-0`:void 0,inputHeader:sd,attachmentContent:ld,highlightedContent:dd,highlightRef:Bi,inputRef:Yr,textLayoutClassName:Y(xE,Gi?Y(`h-full min-h-0`,dr?`py-2.5`:`py-4`):dr?`py-2.5`:`pt-4 pb-2`,g===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Gi&&`flex-1 min-h-0`),inputStyle:{flex:Gi?`1 1 auto`:`none`,height:!Gi&&wc?`${wc.height}px`:void 0,maxHeight:!Gi&&wc?`${wc.maxHeight}px`:void 0,"--yuri-composer-textarea-resting-height":Gi?`100%`:wc?`${wc.height}px`:`auto`,"--yuri-composer-textarea-resting-max-height":!Gi&&wc?`${wc.maxHeight}px`:`none`,borderTopLeftRadius:Ki,borderTopRightRadius:Ki},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,Qu,dr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,Tl)),footerStyle:{borderBottomLeftRadius:Ki,borderBottomRightRadius:Ki},footerContent:md,placeholder:xa?Da:!dr&&La?l(`chat.dictation.recordingPlaceholder`):!dr&&ya&&!m()&&sl()?`${qi}${d.startsWith(`zh`)?`,`:d===`ja`?`、`:`, `}${l(`chat.dictation.holdHere`)}`:qi,onChange:(e,t)=>Rc(t),textareaProps:{readOnly:yr,onCompositionStart:()=>{Qr.current=!0},onCompositionEnd:e=>{Qr.current=!1;let t=e.currentTarget;kc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Lc,onKeyDown:rc,onCopy:Hc,onCut:Uc,onPaste:Bc,onDragEnter:tl,onDragOver:nl,onDropCapture:ol,onDrop:al,onDragEnd:il,onKeyUp:ic,onClick:()=>{ic()},onScroll:e=>{ic();let t=e.currentTarget.scrollTop;Bi.current&&(Bi.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Qr.current){$r.current=r;return}let i=bl(n,r,[...qe(Mr,bn.filter(Ce).map(e=>e.filename)),...Dl(Mr,ca.keys()),...jr.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),$r.current=i.end):$r.current=n,ic()},onFocus:()=>{if(dr){if(Date.now()<pe.current){let e=Yr.current;e&&e.blur();return}B.current!==null&&(window.clearTimeout(B.current),B.current=null),z(!0)}},onBlur:e=>{if(Qr.current=!1,$r.current=e.currentTarget.selectionStart??$r.current,Gu(),dr){if(Date.now()<Wu.current){let e=Yr.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Wu.current&&document.activeElement!==e&&e.focus()},50);return}}if(he.current=Date.now(),$e()){z(!1);return}B.current!==null&&window.clearTimeout(B.current),B.current=window.setTimeout(()=>{B.current=null,z(!1)},120)}},autoCorrect:dr?`on`:`off`,autoCapitalize:dr?`sentences`:`off`,spellCheck:dr||Sr,fillContainer:Gi,rows:1},children:[(0,$.jsx)(ub,{}),xc?(0,$.jsx)(YT,{inputRef:Yr,draftID:En?gn(En):null,ariaLabel:l(`textarea.resizeHandleAria`),onManualHeightChange:Cc}):null,v&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ki},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:rd,onClick:()=>xl(),title:l(`chat.chatInput.actions.attachFiles`),"aria-label":l(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(nd,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:l(b?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),E&&(0,$.jsx)(mu,{ref:pi,searchQuery:O,directory:Tn,onCommandSelect:Zc,onClose:()=>D(!1),commandPolicy:Pu,commandContext:Dn,onRowsChange:Ru?Mu:void 0,style:Hi&&Ua?{left:`${Ua.left}px`,top:`${Ua.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${Ua.left+8}px))`,maxHeight:`${Ua.maxHeight}px`,transform:Ua.place===`above`?`translateY(-100%)`:void 0}:void 0}),S&&(0,$.jsx)(ql,{ref:di,searchQuery:w,onFileSelect:Kc,onAgentSelect:qc,onSkillSelect:Xc,onSessionSelect:Jc,onClose:()=>C(!1),onRowsChange:Ru?Mu:void 0,style:Hi&&Ua?{left:`${Ua.left}px`,top:`${Ua.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${Ua.left+8}px))`,maxHeight:`${Ua.maxHeight}px`,transform:Ua.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),dr&&ya&&!xa?(0,$.jsx)(YE,{radius:Ki,isMobile:dr,footerIconButtonClass:id,footerPaddingClass:Qu,iconSizeClass:nd,sendIconSizeClass:ed,onInsert:Ls,onInsertAndSend:qs,onContentHeightChange:bc,onActiveChange:_c,disabled:xn||Sa!==null||!q&&!Sn,renderTrigger:!1,topAccessory:XE},on):null]})})]}),dr?(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-compact-layer`,"data-yuri-composer-compact-surface":`true`,children:[pd,(0,$.jsx)(`div`,{ref:vc,onPointerDown:()=>{yc.current=!1},onScroll:e=>{let t=e.currentTarget;yc.current=t.scrollWidth-t.clientWidth-t.scrollLeft<=2},className:Y(`yuri-mobile-composer-compact-preview`,!Mr.trim()&&`yuri-mobile-composer-compact-preview--placeholder`),style:fd?{right:`${.625+2.5*(1+Number(!!(n&&r))+Number(!!(es||Zo||uc)))}rem`}:void 0,"aria-hidden":`true`,children:Mr.trim()?Mr:xa?Da:qi})]}):null]}),dr?(0,$.jsx)(JE,{className:`hidden`,composerTextareaRef:Yr,selectionAdapter:$n,mobilePanel:P,onMobilePanelChange:F}):null]}),Sn&&!Hi&&!dr&&!Al&&!vu?(0,$.jsx)(SS,{onSubmit:Is,className:`chat-input-column mt-4`}):null]}),p.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(SE,{popup:p,onOpenChange:vr,isMobile:dr})}):null,(0,$.jsx)($x,{open:Ka,onOpenChange:qa,mode:`select`,onSelect:e=>{to(e),io(null)}}),(0,$.jsx)(nS,{open:Xa,onOpenChange:Qa,onSelect:e=>{io(e),to(null)}}),(0,$.jsx)(Nh,{open:Pn,onOpenChange:Fn,projectDirectory:Je??Tn??null,submitting:Ln,onConfirm:Vi}),(0,$.jsx)(`input`,{ref:cl,type:`file`,multiple:!0,className:`hidden`,onChange:wl,accept:`*/*`}),(0,$.jsx)(`input`,{ref:ll,type:`file`,multiple:!0,className:`hidden`,onChange:wl,accept:`image/*`}),null,pr?(0,$.jsx)(_l,{id:`android-media-pick-sheet`,open:U,onOpenChange:e=>{e||W(!1)},onPickPhotos:()=>{_e.current=!1,W(!1),requestAnimationFrame(Cl)},onPickFiles:()=>{_e.current=!1,W(!1),requestAnimationFrame(xl)}}):null,dr&&Ml&&Pl?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(dl,{id:`mobile-draft-project-picker-sheet-${ne}`,open:ee===`project`,onOpenChange:e=>{e||te(null)},ariaLabel:l(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:l(`mobile.surface.closeAria`),resizeAriaLabel:l(`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)(Ks,{value:re,onChange:e=>G(e.target.value),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(Xu,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:(0,$.jsx)(nD,{projects:jn,query:re,renderLabel:qE,selectedId:Pl.id,onSelect:e=>{Su(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),ga.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},dD=e=>{let t=(0,Q.c)(3),n=Ly(),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)(uD,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};dD.displayName=`ChatInput`;var fD=Z.memo(dD);function pD(e){return e.preventDefault()}function mD(e){e.preventDefault()}function hD(e){return e.preventDefault()}function gD(e){e.pointerType===`touch`&&e.preventDefault()}function _D(e){e.preventDefault()}function vD(e){e.pointerType===`touch`&&e.preventDefault()}var yD=e=>!!(e&&typeof e==`object`&&typeof e.type==`string`),bD=e=>e.filter(yD),xD=e=>{let t=e,n=t.text;return typeof n==`string`?n:t.content||t.value||``},SD=e=>/[^\s\u200B-\u200D\u2060\uFEFF]/u.test(e),CD=e=>e.type===`text`&&!SD(xD(e)),wD=(e,t={})=>{let{includeReasoning:n=!0}=t,r=bD(e),i=r.some(e=>!e.synthetic);return r.filter(e=>{let t=!!e.synthetic;if(e.type===`text`){if(CD(e))return!1;let t=xD(e);if(t.includes(`<system-reminder>`)&<(t).length===0)return!1}return t&&i||!n&&e.type===`reasoning`?!1:e.type!==`patch`})},TD=`GitHub issue context (JSON)`,ED=`GitHub pull request context (JSON)`,DD=`The user referenced these OpenCode sessions (id, title, owning directory).`,OD=e=>typeof e==`number`&&Number.isFinite(e)&&e>0,kD=(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}},AD=e=>{let t=kD(e,TD);if(t){let e=t.issue,n=e?.number,r=e?.title,i=e?.url;return!OD(n)||typeof r!=`string`||typeof i!=`string`?null:{type:`file`,mime:`application/vnd.github.issue-link`,filename:`Issue #${n}: ${r}`,url:i}}let n=kD(e,ED);if(n){let e=n.pr,t=e?.number,r=e?.title,i=e?.url;return!OD(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},jD=e=>!!e.trim().startsWith(`The following tool was executed by the user`),MD=e=>e.trimStart().startsWith(`Continue working toward the active session goal.`),ND=e=>e.trim()===`/compact`,PD=e=>e.flatMap(e=>{if(e.type===`compaction`)return[];if(e.type===`text`){let t=e.text;if(typeof t==`string`){let n=Ka(t);if(n.trim().length===0||MD(n)||ND(n)||n.trimStart().startsWith(DD)||n.includes(`<system-reminder>`)&<(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 jD(t)||n.startsWith(TD)||n.startsWith(ED)?[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=AD(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:lt(n)}}return e}),FD=e=>e.some(e=>{if(e.type===`text`)return!CD(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&&!Fe(e)}return!0}),ID=e=>e?.length?FD(PD(e)):!1,LD=(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(ID(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]},RD=(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},zD=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}},BD=e=>e.syncLoading||e.assistantLoading,VD=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),HD=e=>e.isLoadingOlder,UD=e=>!e.isMobile&&e.isLoadingOlder,WD=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,GD=e=>e.hasImmediateShell||e.hasTranscriptShell&&e.hasRenderableSessionSnapshot||e.transcriptRecords?.some(e=>e.info.role===`user`?ID(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`,KD=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}},qD=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),JD=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,YD=`relative bottom-safe-area yuri-mobile-readonly-prompt-foot`,XD=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)(Os,{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},ZD=e=>{let t=(0,Q.c)(42),{t:n}=Xn(),r=K(QD),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&YD,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 ${JD}`,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&&YD,h;t[18]===m?h=t[19]:(h=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] 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 ${JD}`,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)(ds,{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)(XD,{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 QD(e){return e.isMobile}var $D=Z.memo(()=>{let e=(0,Q.c)(5),{t}=Xn(),{currentTheme:n}=fs(),r=si(eO),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Gc,{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 eO(e){return e.error}var tO=`yuri_asst_session_divider:`,nO=[],rO=e=>typeof e?.info?.id==`string`&&e.info.id.startsWith(`yuri_asst_session_divider:`),iO=(e,t=0)=>({info:{id:`${tO}${e}`,role:`system`,time:{created:t}},parts:[]}),aO=e=>!!(e?.info&&typeof e.info==`object`&&e.info.yuriAssistantAdmission),oO=(e,t,n=nO)=>{if(!e.length)return nO;let r=[],i=!1,a=null;for(let n of e)n.sessionID!==t&&(i&&a!==n.sessionID&&r.push(iO(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?nO:dO(n,r)?n:r},sO=(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},cO=(e,t)=>{if(!t)return e;if(e.info.role===`assistant`&&t.parts.length>0){let n=sO(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 ID(e.parts)?e:ID(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}:{}}},lO=(e,t,n,r=nO)=>{if(!t)return n.length>0?Array.from(n):nO;let i=new Map,a=0;for(let n of e)n.sessionID===t&&(aO(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:cO(e,t?.message),order:t?.order??a++})}if(i.size===0)return nO;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 dO(r,o)?r:o},uO=(e,t)=>{if(!rO(e)||!rO(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},dO=(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||uO(r,i))&&(r?.info!==i?.info||r?.parts!==i?.parts||r.sourceSessionID!==i.sourceSessionID||r.sourceDirectory!==i.sourceDirectory))return!1}return!0},fO=()=>V(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}})})),pO=(0,Z.createContext)(null);function mO(e){let t=(0,Q.c)(7),n=(0,Z.useContext)(pO),r;t[0]===n?r=t[1]:(r=()=>n??fO(),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=z(a,o),c=z(a,hO),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 hO(e){return e.toggle}var gO={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`)}},_O=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)}}},vO=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:Za(t)},yO=Z.memo(e=>{let t=(0,Q.c)(30),{isUser:n,isMobile:r,providerID:i,modelID:a,agentName:o,modelName:s,variant:c}=e,l;t[0]!==r||t[1]!==n||t[2]!==c?(l=!n&&!r?vO(c):null,t[0]=r,t[1]=n,t[2]=c,t[3]=l):l=t[3];let u=l,d=s||`Assistant`,f,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=Y(`mb-1.5`),p=Y(`flex items-center justify-between gap-2`),t[4]=f,t[5]=p):(f=t[4],p=t[5]);let m;t[6]!==o||t[7]!==n||t[8]!==a||t[9]!==i?(m=(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)(Os,{modelId:a,providerId:i,className:`h-4 w-4`,fallback:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-4 w-4`,style:{color:`var(${os(o).var})`}})})})}),t[6]=o,t[7]=n,t[8]=a,t[9]=i,t[10]=m):m=t[10];let h=n?`text-primary`:`text-foreground`,g;t[11]===h?g=t[12]:(g=Y(`inline-flex min-w-0 items-center gap-1.5 font-semibold typography-ui-header tracking-tight leading-tight`,h),t[11]=h,t[12]=g);let _=n?`You`:d,v;t[13]===_?v=t[14]:(v=(0,$.jsx)(`span`,{className:`truncate`,children:_}),t[13]=_,t[14]=v);let y;t[15]===u?y=t[16]:(y=u?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-normal leading-tight text-muted-foreground`,children:u}):null,t[15]=u,t[16]=y);let b;t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsxs)(`h3`,{className:g,children:[v,y]}),t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20];let x;t[21]!==o||t[22]!==n?(x=!n&&o&&(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]`,os(o).class),children:[(0,$.jsx)(ds,{name:o,size:10,shape:`square`}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=n,t[23]=x):x=t[23];let S;t[24]!==b||t[25]!==x?(S=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[b,x]}),t[24]=b,t[25]=x,t[26]=S):S=t[26];let C;return t[27]!==S||t[28]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[m,S]})})}),t[27]=S,t[28]=m,t[29]=C):C=t[29],C}),bO=6e5,xO=new Map,SO=e=>{let t=kn(e);if(!t)return;let n=xO.get(t);if(n){if(n.expiresAt<=Date.now()){xO.delete(t);return}return n.outsideFileGrant}},CO=(e,t,n)=>{let r=kn(e);!r||!t||xO.set(r,{outsideFileGrant:t,expiresAt:typeof n==`number`&&Number.isFinite(n)?n:Date.now()+bO})},wO=async(e,t)=>{let n=kn(e);if(!n||!t||An(n,t))return;let r=SO(n);if(r)return r;let i=await _(n);if(!(!i.success||!i.path||!i.outsideFileGrant))return CO(i.path,i.outsideFileGrant),kn(i.path)!==n&&CO(n,i.outsideFileGrant),i.outsideFileGrant},TO=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,EO=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,DO=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),OO=(e,t)=>e.split(EO).map((e,n)=>n%2==1?e:t(e)).join(``),kO=e=>OO(e,e=>e.replace(/ *\n/g,`
|
|
6552
|
+
`)?`${t}\n`:`${t}\n\n`}`,sD=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},cD=(e,t,n,r)=>t?Pt({transportIdentity:e},t):n?pn({transportIdentity:e},n):r,lD=[],uD=({onOpenSettings:e,scrollToBottom:t,showScrollToBottom:n=!1,onScrollToBottom:r,submissionBlocked:a=!1,surface:s})=>{let{t:l,locale:d}=Xn(),f=ju(),[m,h]=Z.useState({open:!1,title:``,content:``}),[g,_]=Z.useState(`normal`),[v,y]=Z.useState(!1),[b,x]=Z.useState(!1),[S,C]=Z.useState(!1),[w,T]=Z.useState(``),[E,D]=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),ne=Z.useId(),[re,G]=Z.useState(``),[ie,ae]=Z.useState(``),[ce,ue]=Z.useState(!1),[de,fe]=Z.useState(!1),pe=Z.useRef(0),me=J(()=>{pe.current=Date.now()+500}),he=Z.useRef(0),_e=Z.useRef(!1),[ye,be]=Z.useState(-1),xe=Z.useRef(()=>{}),Se=Z.useRef((...e)=>Promise.resolve().then(()=>wa.getState().sendMessage(...e))).current,we=wa(e=>e.currentSessionId),Ee=Ko(e=>e.currentProviderId),Oe=Ko(e=>e.currentModelId),ke=Ko(e=>e.currentAgentName),Ae=Ko(e=>e.currentVariant),je=Ko(e=>e.providers),Ne=Ko(e=>e.agents),Pe=Ko(e=>e.getVisibleAgents),Fe=Z.useMemo(()=>Ty(Pe()),[Pe,Ne]),Le=Ko(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ze=Ko(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Be=Z.useMemo(()=>{let e=je.find(e=>e.id===Ee)?.models?.find(e=>e.id===Oe);return My(e)},[Oe,Ee,je]),Ve=Z.useMemo(()=>({providers:je,agents:Fe,variants:Be,variantsReady:!Le,modelsReady:!Le,agentsReady:!ze,ready:!Le&&!ze,loading:Le||ze}),[je,Fe,Be,Le,ze]),He=le(e=>e.currentDirectory),Ue=bd()??He,{ensureSessionRenderable:Ke}=dh(),Je=wa(Z.useMemo(()=>e=>we?e.getDirectoryForSession(we):null,[we])),Ye=Ca(we??``,Je??void 0),Ze=Z.useMemo(()=>ST(Ye),[Ye]),rt=Z.useMemo(()=>CT(Ye),[Ye]),it=Ja(we??``,Je??void 0).renderable,at=cr(we,Je??void 0),ot=at?.agent,st=at?.model?.id,lt=at?.model?.providerID,ut=at?.model?.variant,pt=Ko(e=>e.activeDirectoryKey),ht=Z.useRef(0),gt=Z.useRef(null),_t=Z.useRef(null),vt=wa(e=>e.newSessionDraft),yt=!!vt?.open,bt=wa(e=>e.newSessionDraft.draftSubmitting??!1),xt=wa(e=>e.newSessionDraft.draftEstablishing??!1),St=bt||xt,Tt=wa(e=>e.openNewSessionDraft),Et=wa(e=>e.setDraftPermissionAutoAcceptEnabled),Dt=_r(e=>e.autoAccept),kt=_r(e=>e.saving),jt=_r(e=>e.setSessionAutoAccept),Pt=wa(e=>e.setNewSessionDraftTarget),Ft=wa(e=>e.availableWorktreesByProject),It=wa(e=>e.abortPromptSessionId),Lt=wa(e=>e.abortPromptExpiresAt),Rt=wa(e=>e.clearAbortPrompt),zt=va(e=>e.consumePendingInputText),Bt=va(e=>e.pendingPresetSubmit),Vt=va(e=>e.pendingInputText),Ht=va(e=>e.pendingInputMode),Gt=va(e=>e.consumePendingSyntheticParts),qt=va(e=>e.activeAttachmentDraft),Jt=_h(Z.useMemo(()=>e=>{let t=we??(yt?`draft`:``);return t?e.drafts[t]??wE:wE},[yt,we])),Xt=_a(we??``),Zt=Z.useSyncExternalStore(i,o,o),Qt=qt?.transportIdentity??null,tn=qt?.owner.kind??null,nn=qt?.owner.ownerID??null,an=Z.useMemo(()=>cD(Zt,we,vt.draftID,Qt&&tn&&nn?{transportIdentity:Qt,owner:{kind:tn,ownerID:nn}}:null),[nn,tn,Qt,Zt,we,vt.draftID]),on=an?gn(an):null,sn=va(Z.useMemo(()=>e=>on?e.draftAttachmentViews[on]:void 0,[on])),ln=va(Z.useMemo(()=>e=>on?e.drafts[on]:void 0,[on])),dn=Z.useMemo(()=>{if(!ln||!sn)return lD;let e=ln.attachments.flatMap(e=>{let t=sn[e.attachmentRefID];return t?[t]:[]});return e.length===0?lD:e},[sn,ln]);Z.useEffect(()=>{an&&va.getState().hydrateDraftAttachments(an)},[an]);let fn=Ly(),pn=K(e=>e.activeMainTab===`chat`),mn=vo(we??``,Ue??void 0),hn=Ry({kind:`primary`,surfaceID:`primary`,active:pn,sessionID:we,directory:Ue??null,activity:{phase:mn?.type===`busy`?`busy`:mn?.type===`retry`?`retry`:`idle`,canAbort:mn?.type===`busy`||mn?.type===`retry`},draftKey:an,transportIdentity:Zt,runtimeGeneration:c(),selection:{value:{providerID:Ee,modelID:Oe,agent:ke,variant:Ae},catalog:Ve,flush:async()=>{let e=wa.getState().currentSessionId;if(!e)return;let t=c(),n=o(),r=ht.current,i=e,a=wa.getState().getDirectoryForSession(i)??null,s=gr(a);if(Ko.getState().activeDirectoryKey!==s&&await Ko.getState().activateDirectory(a),c()!==t||o()!==n||wa.getState().currentSessionId!==i||Ko.getState().activeDirectoryKey!==s||ht.current!==r)return;await Ke(i,{directory:a??void 0});let l=wa.getState().getDirectoryForSession(i)??null,u=gr(l);if(c()!==t||o()!==n||wa.getState().currentSessionId!==i||l!==a||u!==s||Ko.getState().activeDirectoryKey!==s||ht.current!==r)return;let d=Ko.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=Ie(i,l??void 0),m=ST(p),h=CT(p);if(hT({editRevision:r,pinnedHistoryMessageId:gt.current,latestHistoryMessageId:m?.id??null}))return;let g=ur.getState(),_=ge().get(i),v=fT({sessionId:i,latestUserChoice:m,latestExecution:h,catalog:f,memory:g,sessionEntity:_?.model?{agent:_.agent,model:{id:_.model.id,providerID:_.model.providerID,variant:_.model.variant}}:_?.agent?{agent:_.agent}:null,fallbackAgentName:d.currentAgentName});if(!v)return;let y=[i,v.source,v.messageId??``,v.agent??``,v.providerID,v.modelID,v.variant??``,s].join(`|`);_t.current!==y&&(pT(v,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:i,memory:g}),_t.current=y)},change:async e=>{ht.current+=1;let t=wa.getState().currentSessionId;if(t){let e=wa.getState().getDirectoryForSession(t)??void 0,n=ST(Ie(t,e));gt.current=n?.id??null}else gt.current=null;let n=Ko.getState();oT(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:ur.getState()})}},resources:{attachments:dn,addAttachment:async e=>{an&&await ea(an,()=>va.getState()).addLocal(e)},removeAttachment:async e=>an?ea(an,()=>va.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>an?ea(an,()=>va.getState()).clearRootAttachments():!1,restoreAttachments:async e=>an?ea(an,()=>va.getState()).restoreRootAttachments(e):!1,pendingInput:Vt===null?null:{text:Vt,mode:Ht},consumePendingInput:zt,pendingPreset:Bt,consumePendingPreset:()=>va.getState().consumePendingPresetSubmit(),consumeSyntheticParts:Gt,restoreSyntheticParts:e=>va.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:Jt,removeInlineDraft:e=>{let t=we??(yt?`draft`:``);t&&_h.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=we??(yt?`draft`:``);!t||e.length===0||_h.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:Xt,captureRuntime:()=>va.getState().captureDraftRuntime(),getDraft:e=>va.getState().getDraft(e),abortPrompt:{sessionID:It,clear:Rt}},backend:{send:e=>{nT(e,{transportIdentity:o(),runtimeGeneration:c()});let t=rT(e);return Se(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>rs(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()=>Tt(),compact:async e=>Te.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&kr(e.sessionID),ja(e.sessionID??``))},shortcuts:{cycle:e=>xe.current(e),new:()=>Tt(),abort:()=>(we&&kr(we),ja(we??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),_n=zy(hn,s??fn);By(_n),Z.useLayoutEffect(()=>{if(!_n.active){tT(_n.surfaceID);return}return eT(_n),()=>tT(_n.surfaceID)},[_n]);let vn=aT(_n),yn=_n.resources??(_n.kind===`primary`?hn.resources:void 0);if(!yn)throw Error(`chat-input-surface-resources-incomplete`);let bn=[...yn.attachments],q=_n.sessionID,xn=Vy(_n,St),Sn=_n.kind===`secondary`?_n.commands.hasNewDraft:yt,wn=Sn,Tn=_n.directory??Ue,En=_n.draftKey??an,Dn=Z.useMemo(()=>{if(_n.kind===`secondary`)return Uy(_n,!1,!1);let e=q?PE(q,Je??void 0):!1;return Uy(_n,e,Sn)},[_n,q,Je,Sn]),kn=(e,t,n,r,i,a,o,s,c,l)=>vn?vn.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`)),An=J(()=>vn?vn.abort():Promise.reject(Error(`chat-input-surface-incomplete`))),jn=Ia(e=>e.projects),Mn=Ia(e=>e.activeProjectId),Nn=Ia(e=>e.setActiveProjectIdOnly),[Pn,Fn]=Z.useState(!1),[Ln,Rn]=Z.useState(!1),zn=Z.useMemo(()=>q?qo({autoAccept:Dt,sessions:[],sessionById:ge(),sessionID:q}):vt.permissionAutoAcceptEnabled===!0,[q,vt.permissionAutoAcceptEnabled,Dt]),Bn=Ko(e=>e.agents),Vn=_n.kind===`secondary`?_n.selection.value.agent:ke,Un=_n.kind===`secondary`?Ty(_n.selection.catalog?.agents):Bn,Wn=p()||qw(Un,Vn),Gn=J(()=>{ji.error(l(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))}),Kn=_n.selection.value,Jn=_n.selection.change,Yn=_n.selection.catalog,Qn=J(async e=>{if(!Jn)throw Error(`chat-input-surface-selection-readonly`);await Jn({...e,agent:e.agent??void 0,variant:e.variant})}),$n=Z.useMemo(()=>({selection:{providerID:Kn.providerID??``,modelID:Kn.modelID??``,agent:Kn.agent??null,variant:Kn.variant},onChange:Qn,disabled:!_n.active,catalog:Yn}),[Yn,Qn,Kn.agent,Kn.modelID,Kn.providerID,Kn.variant,_n.active]);Z.useEffect(()=>{ht.current=0,gt.current=null,_t.current=null},[we]),Z.useEffect(()=>{if(_n.kind!==`primary`||!we||Le||ze||je.length===0||Fe.length===0)return;let e=gr(Je);if(pt!==e)return;let t=ur.getState(),n={providers:je,agents:Fe};if(hT({editRevision:ht.current,pinnedHistoryMessageId:gt.current,latestHistoryMessageId:Ze?.id??null}))return;let r=fT({sessionId:we,latestUserChoice:Ze,latestExecution:rt,catalog:n,memory:t,sessionEntity:lt&&st?{agent:ot,model:{id:st,providerID:lt,variant:ut}}:ot?{agent:ot}:null,fallbackAgentName:ke,transcriptReady:it});if(!r)return;let i=[we,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,pt].join(`|`);if(_t.current===i)return;if((r.agent===void 0||r.agent===ke)&&r.providerID===Ee&&r.modelID===Oe&&r.variant===Ae){_t.current=i;return}if(Ko.getState().activeDirectoryKey!==e)return;let a=Ko.getState();pT(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:we,memory:t}),_t.current=i},[_n.kind,we,Ze,rt,it,je,Fe,Le,ze,pt,Je,ke,Ee,Oe,Ae,ot,st,lt,ut]);let tr=Ko(e=>e.getVisibleAgents),nr=_n.kind===`primary`?tr():TE,rr=Ko(e=>_n.kind===`primary`?e.providers:EE),ir=_n.kind===`secondary`?Ty(_n.selection.catalog?.agents):nr,or=_n.kind===`secondary`?_n.selection.catalog?.providers??EE:rr,sr=_n.kind===`secondary`&&(!_n.selection.catalog?.ready||!!_n.selection.catalog.error),lr=!_n.active||!_n.selection.change||sr,dr=K(e=>e.isMobile),pr=Ol(),mr=K(e=>e.setImagePreviewOpen),hr=J(e=>{e.image&&(h(e),mr(!0))}),vr=J(e=>{h(t=>({...t,open:e})),mr(e)}),yr=$m(e=>e.pending),br=K(e=>e.inputBarOffset),xr=K(e=>e.persistChatDraft),Sr=K(e=>e.inputSpellcheckEnabled),wr=K(e=>e.isExpandedInput),Er=K(e=>e.setExpandedInput),Dr=K(e=>e.setTimelineDialogOpen),Ar=GT({draftKey:En,sessionTitles:new Map(Array.from(ge(),([e,t])=>[e,t.title||e])),persistenceEnabled:xr}),jr=Ar.document,Mr=jr.text,{replacePlainDocument:Nr,replaceProgrammaticText:Fr,applyBrowserEdit:Ir,insertReference:Lr,deleteReference:Rr,enterHistoryPreview:zr,exitHistoryPreview:Br,captureSubmission:Vr,recoverSubmission:Hr,confirmedFileMentions:Wr,mentions:Gr}=Ar,Kr=J((e,t)=>Fr(e,t)),Jr=Z.useMemo(()=>new Set(Wr.map(e=>e.value)),[Wr]),Yr=Z.useRef(null),Qr=Z.useRef(!1),$r=Z.useRef(0),ei=Z.useRef(null),ti=Z.useRef(null),ni=Z.useRef(0),ri=Z.useRef(!1),ii=Z.useRef(null),oi=Z.useRef(!1),si=Z.useRef(null),ci=Z.useRef([]),ui=Z.useRef(!1),di=Z.useRef(null),fi=Z.useRef(!1),pi=Z.useRef(null),mi=Z.useRef(Mr),hi=Z.useRef(new Set),_i=Ar.getDocument,yi=J((e,t,n=[])=>Kr(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}`))]})),bi=jb(Ab()),{git:xi,vscode:Si}=On(),Ti=K(e=>e.shortcutOverrides.cycle_agent),Di=K(e=>e.shortcutOverrides),Oi=Z.useMemo(()=>Ec(`cycle_agent`,Ti?{cycle_agent:Ti}:void 0),[Ti]),ki=Z.useMemo(()=>Ec(`clear_all_messages`,Di),[Di]),{currentTheme:Ai}=fs(),Mi=Yl(),Ni=$l(Tn),Pi=gu(e=>Tn?e.directories.get(Tn)?.status??null:null),Fi=gu(e=>e.ensureStatus),Ii=gu(e=>e.fetchStatus),[Li,Ri]=Z.useState(!1),Bi=Z.useRef(null);Z.useEffect(()=>{!Tn||!xi||Fi(Tn,xi)},[Tn,xi,Fi]),Z.useEffect(()=>{if(!(!Tn||!xi))return ga.onGitRefreshHint(e=>{BE(e.directory)===BE(Tn)&&Ii(Tn,xi)})},[Tn,xi,Ii]);let Vi=J(async e=>{if(!q)return;let t=wa.getState().getDirectoryForSession(q)||Tn||``;if(!t){ji.error(l(`diffView.reviewDialog.toast.noSessionDirectory`));return}Rn(!0);try{await Ei({originalSessionID:q,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),Fn(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),ji.error(e instanceof Error?e.message:l(`diffView.reviewDialog.toast.startFailed`))}finally{Rn(!1)}}),Hi=wr&&!dr,Ui=wr&&dr,Gi=Hi||Ui,Ki=`1.5rem`,qi=l(q||Sn?g===`shell`?`chat.chatInput.placeholder.shell`:dr?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Ji=bn,Xi=Z.useMemo(()=>new Set(ir.map(e=>e.name.toLowerCase())),[ir]),Zi=Z.useRef(Xi);Zi.current=Xi;let ta=OE({inputMode:g,message:Mr,showCommandAutocomplete:E}),ra=Oa({directory:Tn,enabled:ta}),ia=Z.useMemo(()=>ra.data??[],[ra.data]),aa=$i({directory:Tn,enabled:g!==`shell`}),sa=Z.useMemo(()=>aa.data??[],[aa.data]),ca=Z.useMemo(()=>new Map(sa.map(e=>[e.name.toLowerCase(),e.name])),[sa]),la=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`]);p()&&e.add(`reload`),!dr&&!p()&&e.add(`handoff-review`);for(let t of ia)t.source!==`skill`&&e.add(t.name.toLowerCase());return e},[ia,dr]),ua=Z.useMemo(()=>{if(!Mr||!Mr.includes(`/`)||g===`shell`||la.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${Kt})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(Mr))!==null;){let t=n[2]??``,r=n[3];if(!la.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:en({trigger:`/`,icon:`command`,label:r},Mr.slice(i,i+a))})}return e},[g,la,Mr]),fa=Z.useMemo(()=>!Mr||!Mr.includes(`@`)||g===`shell`?[]:ma(Mr,{confirmedValues:Jr,agentNames:Xi}),[Jr,g,Xi,Mr]),pa=Z.useMemo(()=>{if(!Mr||!Mr.includes(`[`)||g===`shell`||Ji.length===0)return[];let e=Ji.filter(Ce),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return qe(Mr,e.map(e=>e.filename)).flatMap(e=>{let n=Yt(Mr.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:en({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},Mr.slice(e.start,e.end))}]})},[g,Mr,Ji]),ha=f&&Ou(dr)&&_n.kind===`primary`,{globallyEnabled:ya,enabled:xa,hint:Sa,onHintChange:Ea}=yl({available:dr&&!ha}),Da=l(Sa===`recording`?`chat.dictation.releaseSend`:Sa===`cancelling`?`chat.dictation.releaseCancel`:Sa===`editing`?`chat.dictation.releaseEdit`:Sa===`processing`?`chat.dictation.processing`:`chat.dictation.inputPlaceholder`),[Na,Fa]=Z.useState(!1),[La,Ra]=Z.useState(!1),[Ba,Va]=Z.useState(null),Ha=Z.useMemo(()=>{if(!Mr||g===`shell`)return null;let e=[...El(fa),...ua,...pa,...Ba?.draftID===on&&Ba?.text===Mr?[{start:Ba.start,end:Ba.end,style:`dictation`}]:[],...jr.references.map(e=>({start:e.start,end:e.end,priority:103,...Ut(e)}))];return jl(Mr,e)},[pa,ua,fa,jr.references,g,Mr,Ba,on]),[Ua,Wa]=Z.useState(null),Ga=Z.useRef(null),[Ka,qa]=Z.useState(!1),[Xa,Qa]=Z.useState(!1),[eo,to]=Z.useState(null),[ro,io]=Z.useState(null),ao=Mt(e=>e.followUpBehavior),oo=Z.useMemo(()=>{let e=vn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[vn]),so=Ah({transportIdentity:oo?.transportIdentity??``,directory:oo?.directory??``,sessionID:oo?.sessionID??``}),co=Z.useMemo(()=>q?Nt(q):null,[q]),fo=Mt(Z.useMemo(()=>e=>oo?$t(e,oo):CE,[oo])),mo=Mt(Z.useMemo(()=>e=>co?$t(e,co):CE,[co])),ho=Z.useMemo(()=>mo.length===0?fo:fo.length===0?mo:[...mo,...fo],[fo,mo]),go=so.mode===`server`?CE:ho,yo=Mt(Z.useMemo(()=>e=>oo?wt(e,oo):CE,[oo])),So=Mt(e=>e.clearQueue),Co=Mt(e=>e.removeFromQueue),wo=yn.inlineDrafts,To=wo.length>0,[Eo,Do,Oo]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of wo)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[wo]),jo=J(e=>{for(let t of yn.inlineDrafts)t.source===e&&yn.removeInlineDraft(t.id)}),Mo=J(()=>{for(let e of yn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&yn.removeInlineDraft(e.id)}),No=yn.history;Z.useEffect(()=>{mi.current=Mr},[Mr]),Z.useLayoutEffect(()=>{_(`normal`),be(-1)},[En?.transportIdentity,En?.owner.kind,En?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Sn||dr)return;let e=()=>{let e=Yr.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Sn,dr]);let Po=wx(_n.kind===`primary`?q:null,_n.kind===`primary`?Tn??void 0:void 0),Io=_n.activity?.phase??Po.phase,Ro=Ta(Z.useMemo(()=>e=>{if(!q)return!1;let t=e.runsByOriginalSessionID[q];return t?.status===`running`&&t.runtimeKey===u()},[q])),zo=J(e=>{dr&&(me(),F(e),Yr.current?.blur(),Ko.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),Bo=yn.pendingInput,Ho=yn.consumePendingInput;Z.useEffect(()=>{if(Bo===null)return;let e=Ho();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=oD(mi.current,e.text);mi.current=t,Kr(t)}else if(e.mode===`append-inline`){let t=sD(mi.current,e.text);mi.current=t,Kr(t)}else Nr(e.text);setTimeout(()=>{Yr.current?.focus()},0)}},[Bo,Ho,Nr,Kr]);let Uo=Jg(q,vt.draftID),Wo=o_(s_(Uo)),Go=Mr.trim().length>0||Ji.length>0||To||Wo.length>0,Jo=_n.kind===`primary`&&EC(Mr,g)===`btw`,Yo=so.mode===`server`?so.items.length>0:go.length>0||yo.length>0,Xo=!Jo&&!W_(so.mode),Zo=Go||Yo,Qo=wa(e=>e.stagedMessageEdit?.sessionId===q?e.stagedMessageEdit.messageId:null),$o=Io===`busy`||Io===`retry`,es=!Jo&&(_n.activity?.canAbort??$o),ts=J(()=>{let e=Yr.current,t=e?.value??_i().text;t!==_i().text&&Ir(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=_i();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Ji.length>0||To||Wo.length>0}}),ns=_n.surfaceID,is=vt?.draftID??null,as=$a(Z.useMemo(()=>gi(ns),[ns])),os=$a(Z.useMemo(()=>fr(is),[is])),ss=Z.useMemo(()=>Cr(Jo?null:as,!Jo&&os),[as,os,Jo]),cs=(e=`send`)=>$a.getState().beginFlight(ns,e),ls=()=>{$a.getState().endFlight(ns)},us=()=>$a.getState().isInFlight(ns),ds=Z.useRef(null);Z.useEffect(()=>{if(_n.kind!==`primary`||!Qo){ds.current=null;return}if(ds.current!==Qo){if(ds.current=Qo,ha){Nu().focus();return}ky(Yr)||requestAnimationFrame(()=>ky(Yr))}},[ha,Qo,_n.kind]);let ps=$a(Z.useMemo(()=>no(is),[is])),ms=Qe(Z.useMemo(()=>e=>q?e.bySession[q]:void 0,[q])),hs=Z.useMemo(()=>{if(!ms?.length)return et;let e=new Set(Ye.map(e=>e.id));return ms.filter(t=>!e.has(t.id)).map(Ge)},[ms,Ye]),[gs,_s]=Z.useState(null),[vs,ys]=Z.useState(()=>new Set),bs=gs&&gs.sessionID===q&&Ci(gs.runtime,yn.captureRuntime())&&!tt(gs.sessionID,gs.item.messageID)&&!hs.some(e=>e.messageID===gs.item.messageID)?gs.item:null,xs=Z.useMemo(()=>[...ps,...hs,...bs?[bs]:[]],[ps,hs,bs]);Z.useEffect(()=>{ys(e=>{if(e.size===0)return e;let t=new Set;for(let e of hs)t.add(e.messageID);bs&&t.add(bs.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})},[hs,bs]);let Ss=oe(Z.useMemo(()=>e=>q?e.runningBySession[q]===!0:!1,[q])),Cs=J(async()=>{let e=wa.getState().newSessionDraft.draftID;if(!e||!$a.getState().isEstablishing(e))return!1;let t=ts();if(!t.hasContent)return!1;let n=Jg(null,e),r=n?o_.getState().quotesByKey[n]??[]:[],i=i_(t.document,r),a=At(i,`queue-canonical`);if(!a.ok)return ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;if(await _n.selection.flush(),!$a.getState().isEstablishing(e))return!1;let o=mT(Ko.getState());if(!o?.providerID||!o?.modelID)return ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;let s=UE(Ji);return $a.getState().enqueueEstablishingFollowUp({draftID:e,content:a.text,sendConfig:{providerID:o.providerID,modelID:o.modelID,...o.agent?{agent:o.agent}:{},...o.variant?{variant:o.variant}:{}},attachments:s,composerDocument:i})?(Nr(``),n&&i!==t.document&&o_.getState().clear(n),be(-1),Er(!1),s.length>0&&yn.clearAttachments(),!0):!1}),ws=()=>{if(q)return!1;let e=wa.getState().newSessionDraft.draftID;return $a.getState().isEstablishing(e)?(Cs(),!0):!1},Ts=J(async()=>{if(!_n.active||us())return;if(_n.kind===`primary`&&q){let e=wa.getState().stagedMessageEdit;if(e&&e.sessionId===q){await Ns();return}}let e=ts(),t=At(e.document);if(!t.ok){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let n={chunks:t.chunks??[],semantics:t.semantics??[]},r=t.text,i=r.trimStart(),s=n.chunks.every(e=>e.provenance===`authored`)&&g===`normal`&&i.startsWith(`/`)?Wl(i.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(s&&!Jl(s,e=>Fy(_n,{name:e.name,source:`yuri`}))||a||!e.hasContent||!q)return;if(Xo||!Pr(_n.deliveryTarget?.kind,so.mode)){Ns($o?{delivery:`steer`}:void 0);return}if(n.chunks.every(e=>e.provenance===`authored`)&&OC(r,g)){Ns();return}if(!cs(`queue`))return;let u=_n.transportIdentity,d=_n.runtimeGeneration,f=yn.captureRuntime(),p=oo,m=_n.kind===`primary`?oo?.sessionID??q:null,h=[...yn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=h.length>0?Wt(bh(e.document.text,h),e.document.references).document:e.document,v=Uo?o_.getState().quotesByKey[Uo]??[]:[],y=i_(_,v),b=y!==_,x=At(y,`queue-canonical`);if(!x.ok){ls(),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let S=UE(Ji),C=Vr(),w=S,T=Qi(),E=!1,D=null,O=()=>{E&&p&&(so.actions.unstageAdmission({requestID:T.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),E=!1),D&&p&&(Mt.getState().unstageAdmission(p,D),D=null)},k=async e=>{O(),C&&Hr(C),w.length>0&&await yn.restoreAttachments(w),e&&yn.restoreSyntheticParts(e),h.length>0&&yn.restoreInlineDrafts(h),b&&Uo&&o_.getState().restore(Uo,v)};try{if(!p){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(so.mode===`server`){if(!En){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}bo({stage:()=>{so.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:Gr}}),E=!0},clearComposer:()=>{Nr(``),b&&Uo&&o_.getState().clear(Uo),be(-1),Er(!1)}})}else bo({stage:()=>{Mt.getState().bindLegacyQueue(Nt(p.sessionID),p),Mt.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:Gr}),D=T.requestID},clearComposer:()=>{Nr(``),b&&Uo&&o_.getState().clear(Uo),be(-1),Er(!1)}});if(await _n.selection.flush(),!Ci({transportIdentity:u,generation:d},{transportIdentity:o(),generation:c()})){await k();return}if(!Ci(f,yn.captureRuntime())){await k();return}if(m&&wa.getState().currentSessionId!==m){await k();return}if(p.transportIdentity!==o()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&In(wa.getState().getDirectoryForSession(m))!==In(p.directory)){await k();return}let t=p,n=_n.kind===`primary`?(()=>{let e=Ko.getState(),t=m?wa.getState().getDirectoryForSession(m)??null:null;return mT(e,{expectedConfigKey:gr(t),activeDirectoryKey:e.activeDirectoryKey})})():_n.selection.value.providerID&&_n.selection.value.modelID?{..._n.selection.value,providerID:_n.selection.value.providerID,modelID:_n.selection.value.modelID}:void 0;if(!na(n)){await k();return}if(so.mode===`server`){if(!En){await k(),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let r=qr({draftKey:En,runtime:f,document:e.document,attachments:Ji,inlineDrafts:h}),i=t.deliveryTarget.kind===`assistant`?yn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??Ct()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=ko({plan:{chunks:x.chunks??[],semantics:x.semantics??[]},agents:ir,installedSkillNames:new Set(Zr(Cn,Tn).map(e=>e.name)),directory:Tn,root:Mi||Tn,confirmedFilePaths:Wr.map(e=>e.path),confirmedDirectoryPaths:Wr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ji});return o=e.attachments,Ma({text:h.length>0?bh(e.text,h):e.text,attachments:[...S,...e.attachments],semanticParts:Aa(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...Xr(S),...Xr(o),...(i??[]).flatMap(e=>Xr(e.attachments??[],e.partID))],t=s?new Set(s.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),ji.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Lo(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Wi({capture:r,admit:async()=>{let r=await so.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:Gr,sendConfig:n,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:T.createdAt},attachments:a});return r.status===`committed`&&(e=!0,E=!1),r},captureRuntime:yn.captureRuntime,getCurrentDraftKey:()=>En,getDocument:_i,consumeBody:()=>Nr(``),getAttachments:()=>yn.attachments,removeAttachment:yn.removeAttachment,getInlineDrafts:()=>yn.inlineDrafts,removeInlineDraft:yn.removeInlineDraft});if(!e){await k(i),o.status===`stale`&&ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!dr&&Yr.current?.focus()}catch(e){await k(i),ji.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!Mt.getState().confirmAdmission(t,{requestID:T.requestID,sendConfig:n,attachments:S.length>0?S:void 0}).ok){await k(),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}D=null;for(let e of h)yn.removeInlineDraft(e.id);S.length>0&&yn.clearAttachments(),dr||Yr.current?.focus()}catch(e){await k(),ji.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{ls()}}),Es=J(()=>{Uw(()=>Ts(),()=>{ji.error(l(`chat.chatInput.toast.messageSendFailed`))})}),Ds=J(async(e,t,n,r)=>{if(Xo||!_n.draftKey)return!1;try{let i=await wi({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=va.getState(),o=a.getDraft(_n.draftKey);return K_(await Yi({key:_n.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return ji.error(l(`chat.chatInput.toast.messageSendFailed`)),!1}}),Os=J(e=>{if(!(a||Xo)){if(vn){vn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}ji.error(l(`chat.chatInput.toast.messageSendFailed`))}}),ks=J(()=>{me(),F(`agent`),Yr.current?.blur(),Ko.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),As=J(()=>{qa(!0)}),js=J(()=>{Qa(!0)}),Ns=J(async e=>{if(!_n.active||a)return;if(!e?.queuedOnly){let t=e?.presetText==null?ts():null;if(AC({text:e?.presetText??t?.message??``,inputMode:g,scope:q&&Tn?{sessionId:q,directory:Tn}:null,hasReferences:!!(t?.document.references.length||Gr.length),allowed:_n.kind===`primary`&&Fy(_n,{name:`btw`,source:`yuri`}),ask:dw.getState().ask,clearText:()=>{Nr(``),D(!1),k(``)},open:()=>{dr&&(me(),Yr.current?.blur()),q&&Pw({sessionId:q,directory:Tn??null})},notify:e=>ji.error(l(`chat.btw.${e}`))}))return}if(ws()||us())return;let n=e?.queuedOnly??!1,r=e?.queuedMessageId,i=wa.getState().stagedMessageEdit,s=_n.kind===`primary`&&!n&&!!(q&&i?.sessionId===q),u=!s&&e?.steerAfterAdmit===!0&&$o&&!Ro&&_n.kind===`primary`,d=s?`steer`:u?`queue`:e?.delivery,f=d===`queue`&&($o||Ro)?`queue`:d===`steer`&&$o?`steer`:void 0,m=e?.presetText==null?ts():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Ji.length>0||To},h=e?.presetText==null?Vr():null,_=bn,v=At(m.document,`direct-send-display`);if(!v.ok){ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}let y=v.text,b={chunks:v.chunks??[],semantics:v.semantics??[]},x=b.chunks.every(e=>e.provenance===`authored`),S=y.trimStart(),C=x?EC(S,g):null,w=x&&OC(y,g),T=x&&g===`normal`&&/^\/model(?:\s|$)/i.test(S),E=x&&g===`normal`&&S.startsWith(`/`)?Wl(S.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Jl(E,e=>Fy(_n,{name:e.name,source:`yuri`}))||n&&Xo)return;if(!n&&T){D(!1),k(``),dr?zo(`model`):(K.getState().setModelSelectorOpen(!0),Ko.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}let O=!s&&!u&&ar({hasQueuedMessages:Yo,sessionIsRunning:$o,autoReviewRunning:Ro,queuedOnly:n,delivery:f});if(!(!n&&C&&C!==`model`)){if(q&&O&&Xo)return;if(q&&O&&so.mode===`server`){m.hasContent&&Es();return}if(q&&O){m.hasContent&&Es();let e=go[0];e&&vn&&await vn.sendQueued(e.queueItemID,{options:$o?{delivery:`steer`}:void 0});return}}let A=w||!n&&m.hasContent&&!r?[]:r?go.filter(e=>e.id===r):go;if(n&&Ro)return;if(n){if(A.length===0||!q)return}else if(!m.hasContent&&!Yo||!q&&!Sn)return;if(!q&&xn||!cs(f===`queue`?`queue`:`send`))return;let j=!q&&Sn&&!n&&!w?wa.getState().newSessionDraft.draftID??null:null,M=j?un(`msg`):void 0;if(j&&M&&!$a.getState().beginEstablishing({draftID:j,primaryMessageID:M})){ls();return}let N=()=>{ba(),j&&$a.getState().clearEstablishing(j)},P=e=>{let t=wa.getState().currentSessionId,n=(t?wa.getState().getDirectoryForSession(t):null)??Tn??``;if(!t||!n){$a.getState().clearEstablishing(e);return}Hw({draftID:e,sessionID:t,directory:n,transportIdentity:o(),runtimeGeneration:c(),admitServer:so.mode===`server`?async e=>so.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?Xr(e.attachments):void 0}):void 0})};if(q&&!n&&!w&&!s&&Ro){ls(),Es();return}let F=!n&&!w,I=_n.kind===`primary`&&q&&f===`queue`&&!n&&!w&&!C&&g===`normal`?un(`msg`):void 0,L=()=>{I&&_s(e=>e?.item.messageID===I?null:e)};I&&q&&(u&&ys(e=>{if(e.has(I))return e;let t=new Set(e);return t.add(I),t}),_s({sessionID:q,runtime:yn.captureRuntime(),item:{kind:`pending-admission`,requestID:I,queueItemID:I,operationID:I,messageID:I,content:y,createdAt:Date.now(),phase:`admitting`,attachmentCount:Ji.length,composerDocument:m.document,composerMentions:Gr}}));let R=Uo?o_.getState().quotesByKey[Uo]??[]:[],z=t_(R,y)!==y,B=!1,V=()=>{!B||!Uo||(o_.getState().restore(Uo,R),B=!1)};F&&(Nr(``),z&&Uo&&(o_.getState().clear(Uo),B=!0),be(-1),Er(!1));let H=!1,U,W,ee=yn.captureRuntime(),te=!1;try{if(Rw({surfaceKind:_n.kind,currentSessionId:q,queuedOnly:n,delivery:f,resourcePolicy:w,inputMode:g,localCommand:C})&&q){let e=wa.getState().getDirectoryForSession(q)??Tn??null,t=wa.getState().stagedMessageEdit;t&&t.sessionId===q&&(W={sessionId:t.sessionId,messageId:t.messageId},wa.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Ko.getState(),r=gT({captured:mT(n,{expectedConfigKey:gr(e),activeDirectoryKey:n.activeDirectoryKey}),surfaceSelection:_n.selection.value});if(!W&&r?.providerID&&r?.modelID){let t=UE(Ji);U=uo({sessionId:q,directory:e,content:z?t_(R,y):y,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=_n.kind===`primary`?(()=>{if(n){let e=A[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(oo?.sessionID)return oo.sessionID}return q})():null,i=n?A[0]?.sendConfig:void 0;if(n&&i||await _n.selection.flush(),e!==null&&wa.getState().currentSessionId!==e)return;let a=async()=>{let t=i?{...i}:_n.kind===`primary`?(()=>{let t=Ko.getState();if(!e)return gT({captured:mT(t),surfaceSelection:_n.selection.value});let n=wa.getState().getDirectoryForSession(e)??Tn??null;return gT({captured:mT(t,{expectedConfigKey:gr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:_n.selection.value})})():_n.selection.value.providerID&&_n.selection.value.modelID?{..._n.selection.value,providerID:_n.selection.value.providerID,modelID:_n.selection.value.modelID}:void 0;if(_n.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=wa.getState().getDirectoryForSession(e)??Tn??null,r=gr(n);if(Ko.getState().activeDirectoryKey!==r&&await Ko.getState().activateDirectory(n),wa.getState().currentSessionId===e){let e=Ko.getState();t=gT({captured:mT(e,{expectedConfigKey:gr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:_n.selection.value})}}return t},o=await a(),s=!1,c=o?.providerID,d=o?.modelID,v=o?.agent,x=o?.variant;if(!c||!d){if(!s){s=!0;try{await Ko.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),o=await a(),c=o?.providerID,d=o?.modelID,v=o?.agent,x=o?.variant}catch{}}if(!c||!d){console.warn(`Cannot send message: provider or model not selected`),ji.error(l(`chat.chatInput.toast.messageSendFailed`));return}}q&&!n&&!w&&f!==`queue`&&await da(q)&&await ja(q);let S={...f?{delivery:f}:{},commitStagedMessageEdit:!n&&f!==`queue`,...U?{messageID:U.messageID,ticket:U}:I||M?{messageID:I??M}:{},...e?{sessionId:e,directoryHint:wa.getState().getDirectoryForSession(e)??Tn??null}:_n.kind===`primary`&&q?{sessionId:q,directoryHint:wa.getState().getDirectoryForSession(q)??Tn??null}:{}},T=``,E=[],D,O=[],k=new Set(Zr(Cn,Tn).map(e=>e.name)),F=[],B=w?void 0:yn.consumeSyntheticParts();for(let e=0;e<A.length;e++){let t=A[e],n=t.composerDocument&&At(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Tn,a=new Set(Zr(Cn,i).map(e=>e.name)),o=ko({plan:r??Ya(t.content),agents:ir,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(F.push(...o.semantics),!D&&o.agent&&(D=o.agent),e===0)T=o.text,E=Fo([...UE(t.attachments),...o.attachments]);else{let e=UE(t.attachments);O.push({text:o.text,attachments:Fo([...e,...o.attachments])})}}if(!n&&m.hasContent){let e=UE(Ji),t=ko({plan:b,agents:ir,installedSkillNames:k,directory:Tn,root:Mi||Tn,confirmedFilePaths:Wr.map(e=>e.path),confirmedDirectoryPaths:Wr.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ji});F.push(...t.semantics),!D&&t.agent&&(D=t.agent);let n=z?t_(R,t.text):t.text;A.length===0?(T=n,E=Fo([...e,...t.attachments])):O.push({text:n,attachments:Fo([...e,...t.attachments])})}let ne=q??(Sn?`draft`:null),re=[];if(!n&&ne&&!w&&(re=[...yn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),re.length>0)if(A.length===0)T=bh(T,re);else if(O.length>0){let e=O[O.length-1];e.text=bh(e.text,re)}else T=bh(T,re);if(B&&B.length>0&&O.push(...po(B)),eo&&O.push({text:eo.contextText,synthetic:!0}),ro&&(O.push({text:ro.instructionsText,synthetic:!0}),O.push({text:ro.contextText,synthetic:!0})),O.push(...Aa(F,q&&wa.getState().getDirectoryForSession(q)||Tn)),!T&&E.length===0&&O.length===0)return;if(j&&M){if(!await Ao({messageID:M,providerID:c,modelID:d,agent:v,text:T,attachments:E,additionalParts:O,agentMentionName:D}))return;if(!$a.getState().isEstablishing(j)){N();return}}let G=async()=>{if(V(),N(),oo&&A.length>0&&Mt.setState(e=>{let t=Ot(oo),n=e.queuedMessages[t]??[],r=new Set(A.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...A,...n.filter(e=>!r.has(e.id))]}}}),n)return B&&yn.restoreSyntheticParts(B),!0;yn.pendingInput?.text===m.message&&yn.consumePendingInput(),h&&Hr(h);let e=!0;return _.length>0&&(e=await yn.restoreAttachments(_)),B&&yn.restoreSyntheticParts(B),re.length>0&&yn.restoreInlineDrafts(re),e};if(!w&&q&&r){let e=oo?$t(Mt.getState(),oo).find(e=>e.id===r||e.queueItemID===r):void 0;oo&&e?.queueItemID&&e.operationID&&Co(oo,e.queueItemID,e.operationID)}else!w&&q&&A.length>0&&oo&&So(oo);!n&&!w&&(Nr(``),be(-1),Er(!1),Lw({queuedOnly:n,resourcePolicy:w,rootAttachmentCount:_.length})&&yn.clearAttachments());let ie=()=>Fw({currentSessionId:q,messageRef:mi,replacePlainDocument:Nr}),ae=T.trimStart();if(g===`normal`&&ae.startsWith(`/`)){let e=Wl(ae.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Jl(e,e=>Fy(_n,{name:e.name,source:`yuri`})))return;if(q&&(e===`undo`||e===`redo`)&&kC(ae,g)&&ie(),e===`undo`&&q){try{await wa.getState().handleSlashUndo(q),t?.()}catch(e){ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){kC(ae,g)&&ie(),await vn?.shortcut(`new`);return}if(e===`redo`&&q){try{await wa.getState().handleSlashRedo(q),t?.()}catch(e){ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&q){await Iw({command:`fork`,consumeCommandText:ie,forkSession:()=>wa.getState().forkCurrentSession(q),waitForConnection:oa,getDirectoryForSession:()=>wa.getState().getDirectoryForSession(q),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&q&&bi.timeline){Dr(!0);return}if(e===`reload`&&p()){ie(),ji.info(l(`chat.chatInput.toast.reloadStarted`)),zi().then(()=>{ji.success(l(`chat.chatInput.toast.reloadSucceeded`))},()=>{ji.error(l(`chat.chatInput.toast.reloadFailed`))});return}if(e===`compact`&&q){Iw({command:`compact`,consumeCommandText:ie,forkSession:async()=>void 0,waitForConnection:oa,getDirectoryForSession:()=>_n.directory??``,summarizeSession:e=>En?_n.backend.compact({operation:`compact`,surfaceID:_n.surfaceID,transportIdentity:_n.transportIdentity,runtimeGeneration:_n.runtimeGeneration,sessionID:q,directory:e,draftKey:En,deliveryTarget:_n.deliveryTarget,providerID:c,modelID:d,agent:v,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{ji.error(l(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&q){try{await oa();let e=ae.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 za(`session.summary.visible`,{topic_line:n}),a=await za(`session.summary.instructions`,{topic_block:r});await kn(i,c,d,v,[],D,[{text:a,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(q||Sn)){try{await oa();let e=await za(`session.review.visible`),n=await za(`session.review.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&q&&!dr&&!p()){Fn(!0);return}if(e===`goal`&&(q||Sn)){N(),Or.getState().setArmed(!0);let e=DC(ae,g)??``;Nr(e),mi.current=e,be(-1),e||Er(!1);return}if(e===`craft-goal`&&(q||Sn)){try{await oa();let e=ae.replace(/^\/\u2003?craft-goal\b/i,``).trim(),n=await za(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),r=await za(`session.craftGoal.instructions`);await kn(n,c,d,v,[],D,[{text:r,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(q||Sn)){try{await oa();let e=await za(`session.catchup.visible`),n=await za(`session.catchup.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(q||Sn)){try{await oa();let e=await za(`session.debug.visible`),n=await za(`session.debug.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(q||Sn)){try{await oa();let e=await za(`session.weigh.visible`),n=await za(`session.weigh.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(q||Sn)){try{await oa();let e=await za(`session.explore.visible`),n=await za(`session.explore.instructions`);await kn(e,c,d,v,[],D,[{text:n,synthetic:!0}],x,g,S),t?.()}catch(e){await G(),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.exploreFailed`))}return}}let oe=q&&wa.getState().getDirectoryForSession(q)||Tn;if(wn||q&&!PE(q,oe)){let e=await Tr().catch(()=>null);e&&O.push({text:mt(e),synthetic:!0})}te=!0;let se=kn(T,c,d,v,E,D,O.length>0?O:void 0,x,g,S);H=!0,se.finally(()=>{L(),ls(),W&&Ci(ee,yn.captureRuntime())&&wa.getState().endMessageEditCommit(W.sessionId,W.messageId)}).catch(()=>{}),j&&se.then(()=>{P(j)}).catch(()=>{$a.getState().clearEstablishing(j)}),typeof window>`u`?t?.():window.requestAnimationFrame(()=>{t?.()}),se.then(async()=>{if(u&&I&&e){let t=()=>{ys(e=>{if(!e.has(I))return e;let t=new Set(e);return t.delete(I),t})};if(tt(e,I)||!dt({sessionID:e}))t();else{let n=wa.getState().getDirectoryForSession(e)??Tn??``;try{await ct({sessionID:e,inboxID:I,directory:n})}catch{t(),Qe.getState().list(e).some(e=>e.id===I)&&ji.error(l(`chat.chatInput.toast.messageSendFailed`))}}}eo&&to(null),ro&&io(null)}).catch(e=>{U&&Pa(U),G().then(e=>{e||ji.error(l(`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`)){ji.error(l(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){_.length>0&&ji.error(l(`chat.chatInput.toast.sendAttachmentsFailed`));return}ji.error(t||l(`chat.chatInput.toast.messageSendFailed`))}),dr||Yr.current?.focus()}finally{te||(U&&Pa(U),W&&Ci(ee,yn.captureRuntime())&&wa.getState().endMessageEditCommit(W.sessionId,W.messageId)),H||(L(),F&&h&&(Hr(h),V()),ls(),j&&P(j))}}),Fs=J(()=>{if(EC(ts().message,g)===`btw`){Ns();return}if(ws()||us())return;let e=ts(),t=g===`normal`&&e.hasContent&&q&&($o||Ro),n=t&&W_(so.mode)&&Pr(_n.deliveryTarget?.kind,so.mode),r=Ww({followUpBehavior:ao,ctrlEnter:!1,canQueue:!!t,queueUsable:!!n,primary:_n.kind===`primary`,sessionIsRunning:$o,autoReviewRunning:Ro});r.kind===`queue`?Es():r.delivery?Ns({delivery:r.delivery}):Ns()}),Is=J(e=>{if(us())return;let t=(Yr.current?.value??mi.current).trim(),n=t?`${e}\n${t}`:e;Ns({presetText:n})}),Ls=J(e=>{let t=sD(_i().text,e);Kr(t),Yr.current&&(Yr.current.value=t),setTimeout(()=>{Yr.current?.focus()},0)}),zs=Z.useRef(null),Bs=J(()=>{Va(null);let e=_i().text;zs.current={base:e,expected:e}}),Vs=J((e,t=!1)=>{let n=zs.current;if(!n)return;if(_i().text!==n.expected){zs.current=null,Va(null);return}let r=sD(n.base,e),i=e.trim();Va(t||!i?null:{draftID:on,text:r,start:r.length-i.length-1,end:r.length-1}),r!==n.expected&&(Kr(r),Yr.current&&(Yr.current.value=r),n.expected=r),t&&(zs.current=null)}),Hs=J(e=>Vs(e,!0)),Us=J(()=>{Va(null),zs.current=null}),qs=J(e=>{if(us())return;let t=sD(Yr.current?.value??mi.current,e);Ns({presetText:t})}),Js=Z.useRef(null),Ys=J(e=>{let t=_i().text,n=sD(t,e);Js.current={base:t,expected:n},Kr(n),Yr.current&&(Yr.current.value=n)}),Xs=J((e,t)=>{let n=Js.current;if(Js.current=null,!n||_i().text!==n.expected)return;let r=sD(n.base,e);Kr(r),Yr.current&&(Yr.current.value=r),t&&Fs()}),Zs=J(e=>Xs(e,!1)),Qs=J(e=>Xs(e,!0)),$s=J(()=>{Js.current=null}),ec=yn.pendingPreset,tc=yn.consumePendingPreset;Z.useEffect(()=>{if(ec==null)return;let e=tc();e&&Is(e)},[ec,tc,Is]);let nc=J(()=>{Nr(``),be(-1),bn.length>0&&yn.clearAttachments(),oo&&So(oo),D(!1),C(!1),g===`shell`&&_(`normal`)}),rc=J(e=>{if(!_n.active||vl(e))return;if(ki&&Tc(e,ki)&&!yr){let t=Yr.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),nc();return}}if(g===`shell`&&e.key===`Escape`){e.preventDefault(),_(`normal`);return}if(g===`shell`&&e.key===`Backspace`&&Mr.length===0){e.preventDefault(),_(`normal`);return}if(e.key===`Backspace`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&Wo.length>0){let t=Yr.current,n=t?.selectionStart??0,r=t?.selectionEnd??0;if(n===0&&r===0&&Uo){e.preventDefault(),o_.getState().removeLast(Uo);return}}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Yr.current,n=t?.selectionStart??Mr.length,r=t?.selectionEnd??Mr.length,i=Rr({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=NE(Ar.getDocument().text,i.start);e.preventDefault(),Kr(t.text),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(t.caret,t.caret),Dc()}),Oc(t.text,t.caret);return}let a=Xe(Mr,bn.filter(Ce).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=NE(a.text,a.caret);e.preventDefault(),Kr(n.text);for(let e of bn)t.has(e.filename.toLowerCase())&&yn.removeAttachment(e.id);requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=n.caret,Yr.current.selectionEnd=n.caret),Dc()}),Oc(n.text,n.caret);return}let o=Il(Mr,ca.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=NE(o.text,o.caret);e.preventDefault(),Kr(t.text),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=t.caret,Yr.current.selectionEnd=t.caret),Dc()}),Oc(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=qe(Mr,bn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=Yt(Mr.slice(n.start+1,n.end-1)).trim(),r=bn.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(),Kr(a),r&&yn.removeAttachment(r.id),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=n.start,Yr.current.selectionEnd=n.start),Dc()}),Oc(a,n.start);return}let r=Gr.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(),Kr(n),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=r.range.start,Yr.current.selectionEnd=r.range.start),Dc()}),Oc(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(DE.test(o)&&!Zi.current.has(s.toLowerCase())&&ka({mention:s,confirmed:Jr.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(),Kr(n),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=i,Yr.current.selectionEnd=i),Dc()}),Oc(n,i);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(E&&pi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),pi.current.handleKeyDown(e.key);return}if(S&&di.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),di.current.handleKeyDown(e.key);return}if(Hi&&e.key===`Escape`){e.preventDefault(),Er(!1);return}let n=Oi&&!Oi.includes(`shift`)?hc(`shift+${Oi}`):``,r=n&&Tc(e,n)?-1:+!!Tc(e,Oi);if(r!==0&&!E&&!S){e.preventDefault(),e.stopPropagation(),vn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Yr.current?.focus({preventScroll:!0})});return}let i=E||S,a=Yr.current?.selectionStart===0&&Yr.current?.selectionEnd===0,o=Yr.current?.selectionStart===Mr.length&&Yr.current?.selectionEnd===Mr.length,s=!i&&(Mr.length===0||a),c=!i&&(Mr.length===0||o);if(g===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Yr.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),Kr(t),requestAnimationFrame(()=>{let e=Yr.current;e&&(e.selectionStart=n,e.selectionEnd=r),Dc()}),Oc(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&&No.length>0){if(e.preventDefault(),ye===-1)be(0),zr({text:No[0],references:[]});else if(ye<No.length-1){let e=ye+1;be(e),zr({text:No[e],references:[]})}requestAnimationFrame(()=>{Yr.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&ye>=0){if(e.preventDefault(),ye===0)be(-1),Br();else{let e=ye-1;be(e),zr({text:No[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),EC(ts().message,g)===`btw`){Ns();return}if(ws()||us())return;let t=e.ctrlKey||e.metaKey,n=g===`normal`&&Go&&q&&($o||Ro),r=n&&W_(so.mode)&&Pr(_n.deliveryTarget?.kind,so.mode),i=Ww({followUpBehavior:ao,ctrlEnter:t,canQueue:!!n,queueUsable:!!r,primary:_n.kind===`primary`,sessionIsRunning:$o,autoReviewRunning:Ro});i.kind===`queue`?Es():i.steerAfterAdmit?Ns({steerAfterAdmit:!0}):i.delivery?Ns({delivery:i.delivery}):Ns()}}),ic=J(()=>{if(!Hi){Wa(null);return}if(!E&&!S){Wa(null);return}let e=Yr.current,t=ti.current;if(!e||!t)return;let n=WE(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=S?520:E?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));Wa({top:l===`below`?a+22:a-6,left:d,place:l,maxHeight:f})});Z.useLayoutEffect(()=>{ic()},[ic,Mr,E,S,Hi]),qn(`resize`,ic,()=>Hi?window:null);let ac=J(()=>{Ga.current&&=(clearTimeout(Ga.current),null),Ri(!0),Ga.current=setTimeout(()=>{Ri(!1),Ga.current=null},1800)}),oc=Z.useRef(new Set),[sc,cc]=Z.useState(()=>new Set),lc=JSON.stringify([_n.transportIdentity,_n.runtimeGeneration,_n.surfaceID,_n.directory,q]),uc=es&&sc.has(lc),dc=J(async()=>{if(oc.current.has(lc))return;let e=lc;oc.current.add(e),cc(new Set(oc.current)),yn.abortPrompt.clear(),ac();let t;try{let e=_n.kind===`secondary`?vn?.shortcut(`abort`):An();await Promise.race([e,new Promise(e=>{t=setTimeout(()=>{_n.kind===`secondary`&&ji.error(l(`chat.chatInput.stopUnconfirmed`)),e()},5e3)})])}catch(e){console.error(`[ChatInput] abort failed`,e)}finally{clearTimeout(t),oc.current.delete(e),cc(new Set(oc.current))}}),fc=J((e=1)=>{if(sr)return;let t=li(ir,_n.selection.value.agent??Vn,e);if(!t||!_n.selection.change)return;let n=Ur({providerID:_n.selection.value.providerID??``,modelID:_n.selection.value.modelID??``,agent:_n.selection.value.agent??null},t,ir,or);_n.selection.change({..._n.selection.value,...n,agent:n.agent??void 0}),_n.kind===`primary`&&(K.getState().addRecentAgent(t),_n.sessionID&&ur.getState().saveSessionAgentSelection(_n.sessionID,t))});xe.current=fc;let[pc,mc]=Z.useState(null),[gc,_c]=Z.useState(!1),vc=Z.useRef(null),yc=Z.useRef(!0);Z.useLayoutEffect(()=>{yc.current=!0},[on]),Z.useLayoutEffect(()=>{let e=vc.current;e&&(gc||Na)&&yc.current&&(e.scrollLeft=e.scrollWidth)},[Mr,gc,Na]);let bc=J(e=>{mc(t=>t===e?t:e)}),xc=dr&&!ha&&!Gi&&Mr.length>0,[Sc,Cc]=Z.useState(!1),{size:wc,resize:Dc}=qT({inputRef:Yr,message:Mr,expanded:Gi,isMobile:dr,dictationHeight:pc,manualHeight:xc&&Sc});Z.useLayoutEffect(()=>{if(!dr||!gc)return;let e=Yr.current;e&&(e.style.overflowY=`auto`,e.scrollTop=e.scrollHeight,Bi.current&&(Bi.current.style.transform=`translateY(-${e.scrollTop}px)`))},[dr,gc,Mr]);let Oc=J((e,t,n=`manual`,r)=>{let i=Vl({text:e,cursor:t,inputMode:g,mentionInputSource:n,insertedText:r});if(ei.current=i,!i){D(!1),C(!1);return}if(i.kind===`slash-command`){k(i.query),D(!0),C(!1);return}D(!1),T(i.query),C(!0)}),kc=J((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(g===`normal`&&!Qr.current&&la.size>0&&e.includes(`/`)){let r=Ul(e,la,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=Ir(a,o,s,(e,t)=>{let n=[...e];for(let i of _o(t.text,{agentNames:Xi,includeUnterminatedPastedReferences:r===`paste`,confirmedValues:new Set(e.flatMap(e=>e.kind===`file`||e.kind===`directory`?[e.value]:[]))}))n=su(n,{kind:i.kind,value:i.value,path:i.value,label:i.value,range:{start:i.start,end:i.end}});return n}),l=_i(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Yr.current;e&&Ay(u,Qr.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),Dc()}),Oc(l.text,c.end,r,i),{document:l,selection:c}}),Ac=J((e,t=`manual`)=>{if(!e)return;let n=Yr.current;if(!n){let n=Mr+e;kc(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;kc(a,o,o,t,e)}),jc=J((e,t)=>{let n=new Set(se(bn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of bn)n.has(e.filename)&&yn.removeAttachment(e.id)}),Mc=J(e=>{yn.removeAttachment(e.id)}),Nc=J(()=>{ri.current=!1,ci.current=[],ii.current&&=(clearTimeout(ii.current),null)}),Pc=J(()=>{ii.current&&clearTimeout(ii.current),ii.current=setTimeout(()=>{Nc()},700)}),Fc=J(()=>{oi.current=!1,si.current&&=(clearTimeout(si.current),null)}),Ic=J(()=>{oi.current=!0,si.current&&clearTimeout(si.current),si.current=setTimeout(()=>{oi.current=!1,si.current=null},700)}),Lc=J(e=>{!p()||!ri.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),Nc())}),Rc=J(e=>{if(yr)return;let t=e.nativeEvent;if(p()&&ri.current){let n=ci.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){Nc();return}}let n=e.target.value;jc(mi.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?jE(mi.current,n):``,a=i.includes(`@`)||oi.current;oi.current&&Fc();let o=a?`paste`:`manual`;if(g===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);_(`shell`),Nr(e),Dc(),D(!1),C(!1),requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=t,Yr.current.selectionEnd=t)});return}kc(n,r,e.target.selectionEnd??r,o,i)});Z.useEffect(()=>()=>{Nc(),Fc()},[Nc,Fc]);let zc=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=Yr.current,i=r?.selectionStart??Mr.length,a=r?.selectionEnd??Mr.length,o=ru(n,Mr.slice(0,i),Mr.slice(a)),s=`${Mr.slice(0,i)}${o}${Mr.slice(a)}`;jc(Mr,s),yi(s,t);let c=fu(s,i+o.length);$r.current=c,C(!1),T(``),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(c,c),Dc(),Oc(s,c)})}),Bc=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=zE(e.clipboardData);if(r.length===0&&i.length>0&&(q||Sn)){e.preventDefault(),zc(i);return}if(r.length===0&&g===`normal`&&(q||Sn)){let t=Yr.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(kE.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;Kr(a),requestAnimationFrame(()=>{let e=Yr.current;e&&(e.selectionStart=o,e.selectionEnd=o),Dc()}),Oc(a,o,ME(t),t);return}}}let a=e.clipboardData.getData(`text`),o=r.length>0&&i.includes(uC(a.trim().replace(/^(['"])(.*)\1$/,`$2`)))?``:a;if(r.length===0){if(g===`normal`&&kT(_i(),o)){e.preventDefault();let t=_i().text,n=Yr.current,r=n?.selectionStart??Mr.length,i=n?.selectionEnd??Mr.length,a=AT(o,Mr,_i().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})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),OT(_i())),s=Lr(r,i,{id:a.id,kind:`paste`,text:a.text,characterCount:a.characterCount,index:a.index,display:a.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=fu(s.document.text,s.caret);Yr.current&&(Yr.current.value=s.document.text),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(c,c),Dc()}),Oc(s.document.text,c),jc(t,s.document.text);return}o.includes(`@`)&&Ic();return}if(!q&&!Sn){o.includes(`@`)&&Ic();return}e.preventDefault();let s=ft(r,[...bn.map(e=>e.filename),...hi.current]),c=Me(s),u=_i().text,d=Yr.current,f=d?.selectionStart??Mr.length,p=d?.selectionEnd??Mr.length,m=g===`normal`&&kT(_i(),o)?AT(o,Mr,_i().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})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),OT(_i())):null,h=o?`${o}${/\s$/.test(o)?``:` `}${c}`:c,_=ru(h,Mr.slice(0,f),Mr.slice(p));if(m){let e=Lr(f,p,{id:m.id,kind:`paste`,text:m.text,characterCount:m.characterCount,index:m.index,display:m.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=fu(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${c}${e.document.text.slice(t)}`;kc(n,t+c.length,t+c.length,ME(n),c),jc(u,n)}else Ac(_,ME(_)),jc(u,`${Mr.slice(0,f)}${_}${Mr.slice(p)}`);for(let e=0;e<r.length;e+=1){let t=s[e],n=AE(r[e],t);hi.current.add(t);try{await yn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.clipboardAttachFailed`))}finally{hi.current.delete(t)}}}),Vc=J((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=bl(r,i,[...qe(Mr,bn.filter(Ce).map(e=>e.filename)),...Dl(Mr,ca.keys()),..._i().references]),o=a?.start??r,s=a?.end??i,c=Mr.slice(o,s),l=rn(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)}`;kc(e,o,o),requestAnimationFrame(()=>{Yr.current?.setSelectionRange(o,o),Dc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Yr.current?.setSelectionRange(o,s)})}),Hc=J(e=>{Vc(e,`copy`)}),Uc=J(e=>{Vc(e,`cut`)}),Wc=e=>{let t=Yr.current,n=t&&document.activeElement===t?t.selectionStart??$r.current:$r.current;return Vu(e,n)},Gc=()=>{Ou(dr)||Yr.current?.focus()},Kc=J(e=>{let t=Wc(Mr.length),n=Hl(Mr,t,ei.current),r=Mr.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():el(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=uu(Mr,o,s,`@${i}`);yi(c.text,[i],a),$r.current=c.caret,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=c.caret,Yr.current.selectionEnd=c.caret),Dc(),Oc(c.text,c.caret)}),C(!1),T(``),Gc()}),qc=J(e=>{let t=Wc(Mr.length),n=Hl(Mr,t,ei.current),r=Mr.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=uu(Mr,i,a,`@${e}`);Kr(o.text,t=>su(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),$r.current=o.caret,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=o.caret,Yr.current.selectionEnd=o.caret),Dc(),Oc(o.text,o.caret)}),C(!1),T(``),Gc()}),Jc=J(e=>{fi.current||(fi.current=!0,(async()=>{try{let t=wa.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){ji.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await Ke(e.id,{directory:t}),!ve(e.id,t)){ji.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}!dr&&!$e()&&!xo()&&lo([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=_i(),r=Wc(n.text.length),i=Hl(n.text,r,ei.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=ge().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,u={id:`session:${e.id}:${Ct()}`,kind:`session`,sessionId:e.id,display:cn({trigger:`@`,icon:`chat-thread`,label:o})},d=Lr(s,c,u,{inlineBoundaries:!0,padDocumentEdges:!0}),f=fu(d.document.text,d.caret);$r.current=f,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=f,Yr.current.selectionEnd=f),Dc(),Oc(d.document.text,f)}),C(!1),T(``),Gc()}catch{ji.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{fi.current=!1}})())}),Yc=J(e=>{let t=_i(),n=Wc(t.text.length),r=Hl(t.text,n,ei.current)??Zl(t.text,n);if(!r)return!1;let i=Lr(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=fu(i.document.text,i.caret);return $r.current=o,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=o,Yr.current.selectionEnd=o),Dc(),Oc(i.document.text,o),a&&(D(!1),C(!1))}),Gc(),a}),Xc=J(e=>{let t=_i(),n=Wc(t.text.length),r=Hl(t.text,n,ei.current);if(!r)return;let i=Lr(r.start,r.end,{id:`skill:${e.name}:${Ct()}`,kind:`skill`,skillName:e.name,display:cn({trigger:`@`,icon:`book-open`,label:e.name})},{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=fu(i.document.text,i.caret);$r.current=a,requestAnimationFrame(()=>{Yr.current&&(Yr.current.selectionStart=a,Yr.current.selectionEnd=a),Dc(),Oc(i.document.text,a),C(!1),T(``)}),Gc()}),Zc=J((e,t=!1)=>{if(!Fy(_n,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Yc({id:`skill:${e.name}:${Ct()}`,kind:`skill`,skillName:e.name,display:cn({trigger:`@`,icon:`book-open`,label:e.name})})&&k(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Yc({id:`command:${e.name}:${Ct()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:cn({trigger:`/`,icon:`command`,label:e.name})})){k(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=Ul(r,new Set([...la,e.name.toLowerCase()]),r.length);if(e.name===`btw`){let e=_i(),t=Zl(e.text,Yr.current?.selectionStart??e.text.length);if(t){let n=i?.text??r;Kr(e.text.slice(0,t.start)+n+e.text.slice(t.end))}}else Nr(i?.text??r);let a=Yr.current;if(a&&(a._commandMetadata=e),D(!1),k(``),t){Ns({presetText:n});return}let o=()=>{if(!Ou(dr)&&Yr.current){try{Yr.current.focus({preventScroll:!0})}catch{Yr.current.focus()}Yr.current.setSelectionRange(Yr.current.value.length,Yr.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)});Z.useEffect(()=>{q&&Yr.current&&!dr&&Yr.current.focus()},[q,dr]),Z.useEffect(()=>{dr||F(null)},[dr]);let Qc=yn.abortPrompt.sessionID,$c=yn.abortPrompt.clear;Z.useEffect(()=>{Qc&&Qc!==q&&$c()},[q,Qc,$c]),Z.useEffect(()=>{ui.current=!!(q||Sn)},[q,Sn]);let el=J(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(Mi||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t}),tl=J(e=>{if(!GE(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),ni.current++;let t=e.dataTransfer.types?.includes(`application/x-yuri-file-path`)??!1;t!==b&&x(t),(q||Sn)&&!v&&y(!0)}),nl=J(e=>{GE(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(q||Sn)&&!v&&y(!0))}),rl=J(e=>{e.preventDefault(),e.stopPropagation(),ni.current--,ni.current<=0&&(ni.current=0,y(!1),x(!1),Nc())}),il=J(()=>{ni.current=0,y(!1),x(!1),Nc()}),al=J(async e=>{if(ni.current=0,!GE(e.dataTransfer)){Nc();return}if(e.preventDefault(),e.stopPropagation(),y(!1),!q&&!Sn)return;let t=e.dataTransfer.getData(`application/x-yuri-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Yr.current,r=mi.current;if(n){let t=n.selectionStart??$r.current,i=n.selectionEnd??t,a=uu(r,t,i,e);Kr(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,$r.current=a.caret,n.focus()})}else{let t=uu(r,r.length,r.length,e);Kr(t.text)}Nc();return}let n=zE(e.dataTransfer);if(n.length>0){p()&&(ci.current=n),zc(n),p()||Nc();return}let r=KE(e.dataTransfer);if(r.length>0){let e=Me(r.map(e=>e.name)),t=ru(e,mi.current.slice(0,Yr.current?.selectionStart??mi.current.length),mi.current.slice(Yr.current?.selectionEnd??mi.current.length));Ac(t);for(let e of r)try{await yn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}}Nc()}),ol=J(e=>{GE(e.dataTransfer)&&(e.preventDefault(),p()&&(ri.current=!0,Pc()))}),cl=Z.useRef(null),ll=Z.useRef(null),dl=J((e=!0)=>{pe.current=0;let t=()=>{let t=Oy(Yr);if(!t||(ky(Yr),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),pl=J(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Me(t.map(e=>e.name)),n=ru(e,mi.current.slice(0,Yr.current?.selectionStart??mi.current.length),mi.current.slice(Yr.current?.selectionEnd??mi.current.length));Ac(n)}for(let e of t)try{await yn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}}),hl=J(async()=>{try{let e=await Si?.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(`
|
|
6553
|
+
`);ji.error(l(`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&&(dl(!1),await pl(r),dl())}catch(e){console.error(`VS Code file pick failed`,e),ji.error(e instanceof Error?e.message:l(`chat.chatInput.toast.vscodePickFailed`))}}),xl=J(()=>{if(p()){hl();return}cl.current?.click()}),Sl=J(()=>{if(p()){hl();return}ll.current?.click()}),Cl=J(async()=>{if(!kl()){Sl();return}try{let e=await ml(20);if(e===null){Sl();return}e.length>0&&(dl(!1),await pl(e),dl())}catch(e){console.error(`Native photo pick failed`,e),ji.error(l(`chat.chatInput.toast.attachFileFailed`))}}),wl=J(async e=>{let t=e.target.files;!t||t.length===0||(dl(!1),await pl(t),e.target.value=``,dl())}),Tl=`gap-x-1.5 gap-y-0`,Al=p(),Ml=_n.kind===`primary`&&wn&&!Al&&!St,Pl=Z.useMemo(()=>(vt?.selectedProjectId?jn.find(e=>e.id===vt.selectedProjectId)??null:null)||(Mn?jn.find(e=>e.id===Mn)??null:null)||(jn[0]??null),[Mn,vt?.selectedProjectId,jn]),Fl=Z.useMemo(()=>BE(Pl?.path??null),[Pl?.path]),Ll=Pl?VE(Pl):null,Rl=nu(Fl),Bl=gu(e=>Fl?e.directories.get(Fl)?.lastBranchesFetch??0:0),Gl=$l(Fl),Kl=!!Rl?.all,Xl=gu(e=>e.fetchBranches),[Ql,eu]=Z.useState(!1);Z.useEffect(()=>{!Ml||!Fl||!xi||Gl!==null||Ii(Fl,xi,{silent:!0})},[Ii,xi,Gl,Fl,Ml]),Z.useEffect(()=>{if(!Ml||!Fl||!Pl||!xi||Gl!==!0){eu(!1);return}let e=!Bl||Date.now()-Bl>3e4;if(Kl&&!e){eu(!1);return}let t=!1;return eu(!Kl),Xl(Fl,xi).finally(()=>{t||eu(!1)}),()=>{t=!0}},[Xl,xi,Pl,Bl,Kl,Gl,Fl,Ml]);let au=tu(Fl),ou=Rl?.current?.trim()||au?.trim()||``,cu=Z.useMemo(()=>{if(!Pl)return null;let e=BE(Pl.path);return!e||!ou?null:{value:e,label:ou}},[Pl,ou]),lu=Z.useMemo(()=>{if(!Pl)return[];let e=Fl?Ft.get(Fl)??Ft.get(Pl.path)??[]:[];return Vo({projectRoot:BE(Pl.path)??``,rootBranch:ou,worktrees:e,pendingBootstrapDirectory:vt?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[Ft,vt?.bootstrapPendingDirectory,Pl,ou,Fl]),du=Z.useMemo(()=>BE(vt?.bootstrapPendingDirectory??null)??BE(vt?.directoryOverride??null)??Fl,[vt?.bootstrapPendingDirectory,vt?.directoryOverride,Fl]),pu=Z.useMemo(()=>{let e=BE(vt?.bootstrapPendingDirectory??null);return!!(vt?.preserveDirectoryOverride||vt?.pendingWorktreeRequestId||e&&e===du)},[vt?.bootstrapPendingDirectory,vt?.pendingWorktreeRequestId,vt?.preserveDirectoryOverride,du]),hu=Z.useMemo(()=>{let e=[];return cu&&e.push(cu),e.push(...lu),!du||e.some(e=>e.value===du)||!pu?e:[...e,{value:du,label:Zn(du)}]},[cu,du,pu,lu]),_u=Z.useMemo(()=>HS({selectedDirectory:du,projectRootOption:cu,worktreeOptions:lu}),[cu,du,lu]),vu=mx()===`mini-chat`,yu=Z.useMemo(()=>vu||Ni!==!0||!Pi||Pi.isClean?!1:$b(Pi.files),[Pi,Ni,vu]),bu=Z.useMemo(()=>!du||cu?.value===du||lu.some(e=>e.value===du),[cu?.value,du,lu]);Z.useEffect(()=>{vt?.open&&(!vt.preserveDirectoryOverride&&!vt.bootstrapPendingDirectory||!du||!bu||(vt.preserveDirectoryOverride&&wa.getState().setDraftPreserveDirectoryOverride(!1),vt.bootstrapPendingDirectory&&wa.getState().setDraftBootstrapPendingDirectory(null)))},[vt?.bootstrapPendingDirectory,vt?.open,vt?.preserveDirectoryOverride,bu,du]);let xu=Z.useMemo(()=>Gl!==!0||Ql?!1:cu?!0:lu.length>0,[Ql,cu,Gl,lu.length]),Su=J(e=>{if(wa.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=jn.find(t=>t.id===e);t&&(Mn!==e&&Nn(e),Pt({projectId:e,directoryOverride:t.path},{force:!0}))}),Cu=J(e=>{wa.getState().newSessionDraft?.pendingWorktreeRequestId||Pl&&Pt({projectId:Pl.id,directoryOverride:e},{force:!0})});Z.useEffect(()=>{!Ml||!Pl||!du||vt?.pendingWorktreeRequestId||vt?.bootstrapPendingDirectory||vt?.preserveDirectoryOverride||hu.some(e=>e.value===du)||Pt({projectId:Pl.id,directoryOverride:Pl.path})},[hu,vt?.bootstrapPendingDirectory,vt?.pendingWorktreeRequestId,vt?.preserveDirectoryOverride,du,Pl,Pt,Ml]);let wu=J(()=>{me(),H(!0),Yr.current?.blur()}),Tu=J(()=>{me(),W(!0),Yr.current?.blur()});Z.useEffect(()=>{if(!dr||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=()=>fe(Nx(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[Mx]}),()=>r.disconnect()},[dr]);let Eu=de||!!P||V||U||Ka||Xa,Du=vi(or.find(e=>e.id===_n.selection.value.providerID),_n.selection.value.modelID,l(`chat.modelControls.selectModel`)),ku=_n.selection.value.variant?.trim(),Mu=J(e=>{j(t=>iu(t,e.rows)),N(t=>t===e.highlightedIndex?t:e.highlightedIndex)}),Pu=J(e=>(e.name!==`btw`||_n.kind===`primary`)&&Fy(_n,e)),Fu=J(e=>{if(E){pi.current?.acceptIndex(e,!0);return}S&&di.current?.acceptIndex(e)}),Iu=J(()=>{ei.current=null,D(!1),C(!1),j([]),N(0)}),Ru=Bm({enabled:ha,isMobile:dr,text:Mr,textPresetEpoch:Ar.textPresetEpoch,placeholder:qi,modelLabel:Du,modelVariantLabel:ku?Za(ku):``,canSend:Zo,canAbort:es,attachmentCount:bn.length,suppressed:Eu,attachAria:l(`chat.chatInput.actions.addAttachment`),attachTitle:l(`chat.chatInput.actions.addAttachment`),attachPhotosLabel:l(`chat.chatInput.actions.attachPhotos`),attachFilesLabel:l(`chat.chatInput.actions.attachFiles`),attachCancelLabel:l(`chat.chatInput.actions.attachCancel`),sendAria:l(`chat.chatInput.actions.sendMessageAria`),queueAria:l(`chat.chatInput.actions.queueMessageAria`),stopAria:l(`chat.chatInput.actions.stopGeneratingAria`),modelAria:l(`chat.modelControls.selectModel`),modelId:_n.selection.value.modelID,providerId:_n.selection.value.providerID,agentName:_n.selection.value.agent??``,agentLabel:ai(ir,_n.selection.value.agent??void 0),agentAria:l(`chat.modelControls.selectAgent`),attachments:bn,removeAttachmentNamedAria:e=>l(`chat.fileAttachment.actions.removeNamed`,{name:e}),onText:(e,t,n)=>{let r=Vu(e.length,n?.end??n?.start??e.length);if($r.current=r,t){Yr.current&&(Yr.current.value=e),Kr(e);return}let i=mi.current,a=De(i,e,bn.filter(Ce).map(e=>e.filename)),o=a?.text??e;Yr.current&&(Yr.current.value=o),Kr(o);let s=Vu(o.length,n?.end??n?.start??o.length);if($r.current=s,Oc(o,s),!a)return;let c=new Set(a.removedFilenames.map(e=>e.toLowerCase()));for(let e of bn)c.has(e.filename.toLowerCase())&&yn.removeAttachment(e.id)},onSend:e=>{Yr.current&&(Yr.current.value=e),Au({text:e,applyDocument:Kr,submit:Fs})},onAbort:dc,onAttach:me,onFiles:(e,t)=>{t.length>0&&ji.error(l(`chat.chatInput.toast.someFilesSkipped`,{summary:t.join(`
|
|
6554
|
+
`)})),e.length!==0&&pl(e)},onRemoveAttachment:e=>{yn.removeAttachment(e)},onOpenModel:()=>zo(`model`),onCycleAgent:()=>fc(),onOpenAgent:ks,showScrollToBottom:!!(n&&r),scrollAria:l(`chat.scrollToBottom.aria`),onScrollToBottom:r??(()=>{}),autocompleteOpen:A.length>0&&(E||S),autocompleteHighlightedIndex:M,autocompleteRows:A,autocompleteQuery:S?w:O,caret:$r.current,onAutocompleteAccept:Fu,onAutocompleteDismiss:Iu,chipHighlights:Ha}),zu=Z.useRef(null);Hn(Ru?zu:null,()=>{let e=zu.current?.getBoundingClientRect().height??0;Lu(document.documentElement,e)});let Bu=Z.useRef(!1);Bu.current=Ka||Xa;let Hu=Z.useRef(!1),Uu=Z.useRef(0),Wu=Z.useRef(0),Gu=J(()=>{let e=wa.getState().stagedMessageEdit;!e||e.sessionId!==q||window.setTimeout(()=>{let t=wa.getState().stagedMessageEdit,n=document.activeElement,r=zw({surfaceKind:_n.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:us(),focusHeld:Date.now()<Wu.current,overlayOpen:Uu.current>0||Bu.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<pe.current});r.action===`disarm`&&wa.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!dr||$e()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Uu.current+=1},t=()=>{if(Uu.current=Math.max(0,Uu.current-1),Hu.current){Hu.current=!1;return}if(!_e.current||Bu.current||Uu.current>0)return;if(ul()){_e.current=!1;return}_e.current=!1,Wu.current=Date.now()+600,Yr.current?.focus(),document.activeElement===Yr.current&&z(!0);let e=()=>{let e=Yr.current;!e||document.activeElement!==e||(Ku.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)}},[dr]),Z.useEffect(()=>{if(!dr)return;if(Eu){(R||Date.now()-he.current<800)&&(_e.current=!0);return}if(!_e.current)return;let e=window.setTimeout(()=>{if(_e.current=!1,ul())return;let e=Yr.current;e&&document.activeElement!==e&&e.focus({preventScroll:$e()})},180);return()=>window.clearTimeout(e)},[dr,Eu,R]),Z.useEffect(()=>{if(!dr||$e()||typeof document>`u`||R||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Yr.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[dr,R]),Z.useEffect(()=>{G(``)},[ee]);let Ku=Z.useRef(null),qu=dr&&_n.kind===`primary`&&!Ru,Ju=Z.useRef(null),Yu=Z.useRef(null),Zu=J(()=>{if(!qu)return;let e=Ku.current;if(!e?.closest(`.yuri-mobile-composer-foot--overlay`))return;let t=zu.current?.offsetHeight??0;if(Yu.current===null){if(e.offsetHeight<=0)return;Yu.current=Math.max(0,e.offsetHeight-t)}let n=hE(document.documentElement,Yu.current+t);n!==null&&(Ju.current=n)});Hn(qu?zu:null,Zu),Z.useEffect(()=>{if(qu)return()=>{gE(document.documentElement,Ju.current),Ju.current=null,Yu.current=null}},[qu]);let Qu=dr?`px-1.5 py-1.5`:Al?`px-1.5 py-1`:`px-2.5 py-1.5`,$u=dr?`h-8 w-8`:Al?`h-5 w-5`:`h-6 w-6`,ed=dr?`h-4 w-4`:Al?`h-3.5 w-3.5`:`h-4 w-4`,td=dr?`h-6 w-6`:`size-full`,nd=dr?`h-[1.125rem] w-[1.125rem]`:Al?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,rd=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,py),id=Y(rd,$u),ad=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`,$u),od=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(()=>()=>{Ga.current&&=(clearTimeout(Ga.current),null)},[]);let sd=(0,$.jsx)(Wh,{quotes:Wo,removeLabel:l(`chat.btw.removeQuoteAria`),onRemove:e=>{Uo&&o_.getState().removeQuote(Uo,e)}}),cd=dr?(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)(QE,{onOpenAgentPanel:ks,onCycleAgent:()=>{me(),fc()},agentName:_n.selection.value.agent,agents:ir,disabled:lr}),(0,$.jsx)($E,{onOpenModel:()=>zo(`model`),providerID:_n.selection.value.providerID,modelID:_n.selection.value.modelID,provider:or.find(e=>e.id===_n.selection.value.providerID),variant:_n.selection.value.variant})]}):null,ld=(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)(lg,{attachments:bn,onShowPopup:hr,onRemoveAttachedFile:Mc}),_n.kind===`primary`?(0,$.jsx)(pg,{attachedFiles:bn,onAddVSCodeFile:(e,t,n)=>{En&&ea(En,()=>va.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(En)return ea(En,()=>va.getState()).addVSCodeSelection(e,t)}}):null]}),ud=Ha?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Nl,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),dd=!dr&&La?(0,$.jsxs)($.Fragment,{children:[ud??Mr,(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`yuri-dictation-caret`,children:Ba?.draftID===on&&Ba.text===Mr&&(0,$.jsx)(`span`,{className:`yuri-dictation-caret-trail`},Mr)})]}):ud,fd=dr&&xa?(0,$.jsx)(er,{variant:`ghost`,size:`icon`,className:id,"data-composer-action":`true`,"aria-label":l(Na?`settings.voice.volcengine.finishRecording`:`chat.dictation.start`),"aria-pressed":Na,disabled:!Na&&(xn||gc||Sa!==null||!q&&!Sn),onClick:()=>window.dispatchEvent(new Event(`yuri:mobile-dictation-toggle`)),children:(0,$.jsx)(X,{name:`mic`,className:Y(nd,Na&&`text-[var(--voice-active-fill)]`)})}):null,pd=dr?(0,$.jsxs)(`div`,{className:Y(`yuri-mobile-composer-compact-chrome`,es&&`yuri-mobile-composer-compact-chrome--aborting`,Zo&&!es&&`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)(rD,{isVSCode:Al,footerIconButtonClass:id,iconSizeClass:nd,handlePickLocalFiles:xl,handlePickLocalImages:Sl,openIssuePicker:As,openPrPicker:js,onOpenMobileSheet:wu,onOpenAndroidPickSheet:pr?Tu: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,fd,es||Zo||uc?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(aD,{isMobile:!0,compact:!0,footerIconButtonClass:id,stopFooterIconButtonClass:ad,compactCircleButtonClass:od,sendIconSizeClass:ed,stopIconSizeClass:td,canSend:Zo,canAbort:es,abortPending:uc,hasContent:!1,currentSessionId:q,newSessionDraftOpen:Sn,draftSubmitting:xn,submissionBlocked:a,sendPhase:ss,queueFrozen:Xo,queueFallbackAvailable:es||$o,onPrimaryAction:Fs,onAbort:dc})}):null]})]}):null,md=dr?(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)(rD,{isVSCode:Al,footerIconButtonClass:id,iconSizeClass:nd,handlePickLocalFiles:xl,handlePickLocalImages:Sl,openIssuePicker:As,openPrPicker:js,onOpenSettings:e,onOpenMobileSheet:wu,onOpenAndroidPickSheet:pr?Tu:void 0}),Wn?(0,$.jsx)(iD,{sessionId:q,draftOpen:Sn,draftEnabled:vt.permissionAutoAcceptEnabled===!0,enabled:zn,saving:q?kt:!1,footerIconButtonClass:id,iconSizeClass:nd,onSetDraftEnabled:Et,onSetSessionEnabled:jt,onOpenSessionFirst:Tt,onToggleFailed:Gn}):null,(0,$.jsx)(vC,{sessionId:q,directory:Je??Tn,draftOpen:Sn}),(0,$.jsx)(yC,{length:Mr.length}),xa&&(0,$.jsx)(ZE,{interactionMode:`mobile`,disabled:xn||Sa!==null||!q&&!Sn,onRecordingChange:Fa,onActiveChange:_c,className:id,iconClassName:nd,onStart:Bs,onPartial:Vs,onInsert:Hs,onCancel:Us},on)]}),cd,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(aD,{isMobile:dr,footerIconButtonClass:id,stopFooterIconButtonClass:ad,sendIconSizeClass:ed,stopIconSizeClass:td,canSend:Zo,canAbort:es,abortPending:uc,hasContent:!!Go,currentSessionId:q,newSessionDraftOpen:Sn,draftSubmitting:xn,submissionBlocked:a,sendPhase:ss,queueFrozen:Xo,queueFallbackAvailable:es||$o,onPrimaryAction:Fs,onAbort:dc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,Tl,La&&`[&>*:not([data-dictation-control])]:opacity-40`),children:[(0,$.jsx)(rD,{isVSCode:Al,footerIconButtonClass:id,iconSizeClass:nd,handlePickLocalFiles:xl,handlePickLocalImages:Sl,openIssuePicker:As,openPrPicker:js,onOpenSettings:e,withTooltip:!0}),Wn?(0,$.jsx)(iD,{sessionId:q,draftOpen:Sn,draftEnabled:vt.permissionAutoAcceptEnabled===!0,enabled:zn,saving:q?kt:!1,footerIconButtonClass:id,iconSizeClass:nd,onSetDraftEnabled:Et,onSetSessionEnabled:jt,onOpenSessionFirst:Tt,onToggleFailed:Gn}):null,(0,$.jsx)(vC,{sessionId:q,directory:Je??Tn,draftOpen:Sn}),(0,$.jsx)(yC,{length:Mr.length}),ya&&!p()&&sl()&&(0,$.jsx)(ZE,{inputRef:Yr,onActiveChange:Ra,onRecordingChange:Fa,className:id,iconClassName:nd,onStart:Bs,onPartial:Vs,onInsert:Hs,onCancel:Us},on)]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,Tl,La&&`opacity-40`),children:[(0,$.jsx)(JE,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Yr,selectionAdapter:$n}),(0,$.jsx)(aD,{isMobile:dr,footerIconButtonClass:id,stopFooterIconButtonClass:ad,sendIconSizeClass:ed,stopIconSizeClass:td,canSend:Zo,canAbort:es,abortPending:uc,hasContent:!!Go,currentSessionId:q,newSessionDraftOpen:Sn,draftSubmitting:xn,submissionBlocked:a,sendPhase:ss,queueFrozen:Xo,queueFallbackAvailable:es||$o,onPrimaryAction:Fs,onAbort:dc})]})]}),hd=J(()=>{if(dr){Wu.current=Date.now()+600;let e=()=>{Yr.current?.focus({preventScroll:$e()}),document.activeElement===Yr.current&&z(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!ky(Yr))return;let e=Oy(Yr);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),gd=Je??Tn,_d=_n.kind===`secondary`?_n.directory:Je,{goal:vd,enabled:yd}=fC(q??``,gd),xd=(0,$.jsx)(Ov,{onEditMessage:Ds,onSendMessage:Os,onEditCommitted:hd,draftKey:En,scope:oo,draftTarget:En?{key:En,expectedRevision:()=>yn.getDraft(En)?.revision??`absent`}:null,clientPendingItems:xs,compactionBarrier:Ss,steeringMessageIDs:vs,onSteerClientPending:e=>{if(!q||!dt({sessionID:q}))return;let t=Je??Tn??``,n=q;return ys(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n}),ct({sessionID:n,inboxID:e,directory:t}).catch(()=>{ys(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),ji.error(l(`chat.chatInput.toast.messageSendFailed`))})},onQueueClientPending:e=>{q&&We({sessionID:q,inboxID:e,directory:Je??Tn??``}).then(()=>{nt(q,e,`queue`)}).catch(()=>{ji.error(l(`chat.chatInput.toast.messageSendFailed`))})},onRemoveClientPending:e=>{let t=$a.getState().removeEstablishingFollowUp(e);if(!t){q&&Re({sessionID:q,inboxID:e,directory:Je??Tn??``}).catch(()=>{ji.error(l(`chat.chatInput.toast.messageSendFailed`))});return}t.content&&Nr(t.content),t.attachments.length>0&&yn.restoreAttachments(t.attachments)},trailing:q&&yd&&vd?(0,$.jsx)(_C,{sessionId:q,directory:gd}):null});return(0,$.jsxs)($.Fragment,{children:[_n.kind===`primary`&&q?(0,$.jsx)(Aw,{scope:{sessionId:q,directory:Tn},active:_n.active,mobile:dr}):null,(0,$.jsxs)(`form`,{ref:Ku,onSubmit:e=>{e.preventDefault(),Fs()},onPointerDownCapture:e=>{dr&&Dy(e,me)},className:Y(`relative w-full pt-0 pb-4`,Hi&&`flex h-full min-h-0 flex-col pt-4`,Ui&&`flex h-full min-h-0 flex-col pt-1`,dr&&`bottom-safe-area yuri-mobile-composer`),"data-native-ios-composer":Ru?`true`:void 0,"data-hold-to-talk":xa?`true`:void 0,"data-hold-to-talk-empty":xa&&Mr.length===0?`true`:void 0,"data-dictation-hint":xa?Sa??void 0:void 0,style:dr&&$e()&&!Ru&&br>0&&!R?{marginBottom:`${br}px`}:void 0,children:[wn&&!Hi&&!dr&&!Al&&!vu?(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:HE(Ll?l(`chat.emptyState.draftTitleWithProject`,{project:Ll}):l(`chat.emptyState.draftTitle`),Ll)})}):null,xa&&(0,$.jsx)(gl,{containerRef:Ku,disabled:!q&&!Sn||xn||gc,onInsert:Zs,onSend:Qs,onRelease:Ys,onError:$s,onHintChange:Ea},En?gn(En):q??`new`),(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Gi&&`flex flex-1 min-h-0 flex-col`),children:[Ru?null:(0,$.jsx)(ug,{attachments:bn,onShowPopup:hr,onRemoveAttachedFile:Mc}),(0,$.jsx)(Jv,{}),To&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[Oo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:Ai?.colors?.surface?.elevated,borderColor:Ai?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:Ai?.colors?.status?.info},children:Oo}),(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:Mo,"aria-label":l(`chat.chatInput.reviewCommentsRemove`),title:l(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Eo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:Ai?.colors?.surface?.elevated,borderColor:Ai?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:Ai?.colors?.status?.info},children:Eo}),(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:()=>jo(`preview-console`),"aria-label":l(`chat.chatInput.devServerLogsRemove`),title:l(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Do>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:Ai?.colors?.surface?.elevated,borderColor:Ai?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:Ai?.colors?.status?.info},children:Do}),(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:()=>jo(`preview-annotation`),"aria-label":l(`chat.chatInput.previewContextRemove`),title:l(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),eo&&!Al&&(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:()=>qa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[eo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:eo.author.avatarUrl,alt:eo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,eo.number,eo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:eo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:eo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:eo.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":l(`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:()=>{to(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.issue.removeAria`),title:l(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),ro&&!Al&&(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:()=>Qa(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[ro.author?.avatarUrl&&(0,$.jsx)(`img`,{src:ro.author.avatarUrl,alt:ro.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[l(`chat.chatInput.linked.pr.number`,{number:ro.number}),ro.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:ro.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:ro.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[ro.head,` → `,ro.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:ro.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":l(`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:()=>{io(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.pr.removeAria`),title:l(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(tD,{sessionId:q,directory:Je??Tn}),(0,$.jsxs)(`div`,{className:dr?`relative yuri-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:dr?`yuri-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:dr?`yuri-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:zu,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(eD,{className:dr?`mb-0`:void 0,showAbortStatus:Li,showAbortPrompt:!!(Hi&&q&&It===q&&typeof Lt==`number`&&Lt>Date.now()),showAssistantStatus:!1,showTodos:!0,leftAccessory:Sn||!yu?null:(0,$.jsx)(ux,{})}),!dr&&Ml?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Pl?(0,$.jsxs)(Rs,{value:Pl.id,open:ce,onValueChange:Su,onOpenChange:e=>{ue(e),e||ae(``)},children:[(0,$.jsx)(Ms,{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]`,dy),children:[(0,$.jsx)(Ws,{children:qE(Pl)}),(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)(Ps,{fitContent:!0,children:[(0,$.jsx)(Ks,{autoFocus:!0,value:ie,onChange:e=>ae(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),(0,$.jsx)(nD,{projects:jn,query:ie,renderLabel:qE}),(0,$.jsx)(Gs,{}),(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(),ue(!1),requestAnimationFrame(()=>ga.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`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`,dy),onClick:()=>ga.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Pl&&xu?(0,$.jsx)(YS,{directory:du,projectDirectory:Fl,label:_u,projectRootOption:cu,worktreeOptions:lu,onSelectDirectory:Cu}):null]}):null,dr&&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:[Pl?(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`,dy),onClick:()=>te(`project`),children:qE(Pl)}):(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`,dy),onClick:()=>ga.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Pl&&xu?(0,$.jsx)(YS,{directory:du,projectDirectory:Fl,label:_u,projectRootOption:cu,worktreeOptions:lu,onSelectDirectory:Cu,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,_n.active&&q&&_d?(0,$.jsx)(Wv,{sessionId:q,directory:_d}):null,xd]})}),(0,$.jsx)(`div`,{className:Y(!dr&&`contents`,dr&&`contents`,Ui&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:dr?`yuri-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(zl,{value:Mr,attachments:[],disabled:!q&&!Sn||xn&&!ss.establishing,pending:es||ss.inFlight&&!ss.establishing,isMobile:dr,onSubmit:Fs,"data-mobile-composer-surface":dr?`true`:void 0,expanded:Gi,className:Y(`relative z-10`,La&&`!ring-0 [&_textarea]:caret-transparent`,v&&`ring-2 ring-primary ring-offset-2`,yr&&`ring-1 ring-[var(--interactive-selection)]`,dr&&`yuri-mobile-composer-surface`),style:{borderRadius:Ki,...La?{borderColor:`var(--voice-active-fill)`}:{}},ref:ti,onDropCapture:ol,onDragEnter:tl,onDragOver:nl,onDragLeave:rl,onDrop:al,onDragEnd:il,autoResize:!1,disableInputWhilePending:!1,contentClassName:Gi?`flex-1 min-h-0`:void 0,inputHeader:sd,attachmentContent:ld,highlightedContent:dd,highlightRef:Bi,inputRef:Yr,textLayoutClassName:Y(xE,Gi?Y(`h-full min-h-0`,dr?`py-2.5`:`py-4`):dr?`py-2.5`:`pt-4 pb-2`,g===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Gi&&`flex-1 min-h-0`),inputStyle:{flex:Gi?`1 1 auto`:`none`,height:!Gi&&wc?`${wc.height}px`:void 0,maxHeight:!Gi&&wc?`${wc.maxHeight}px`:void 0,"--yuri-composer-textarea-resting-height":Gi?`100%`:wc?`${wc.height}px`:`auto`,"--yuri-composer-textarea-resting-max-height":!Gi&&wc?`${wc.maxHeight}px`:`none`,borderTopLeftRadius:Ki,borderTopRightRadius:Ki},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,Qu,dr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,Tl)),footerStyle:{borderBottomLeftRadius:Ki,borderBottomRightRadius:Ki},footerContent:md,placeholder:xa?Da:!dr&&La?l(`chat.dictation.recordingPlaceholder`):!dr&&ya&&!p()&&sl()?`${qi}${d.startsWith(`zh`)?`,`:d===`ja`?`、`:`, `}${l(`chat.dictation.holdHere`)}`:qi,onChange:(e,t)=>Rc(t),textareaProps:{readOnly:yr,onCompositionStart:()=>{Qr.current=!0},onCompositionEnd:e=>{Qr.current=!1;let t=e.currentTarget;kc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Lc,onKeyDown:rc,onCopy:Hc,onCut:Uc,onPaste:Bc,onDragEnter:tl,onDragOver:nl,onDropCapture:ol,onDrop:al,onDragEnd:il,onKeyUp:ic,onClick:()=>{ic()},onScroll:e=>{ic();let t=e.currentTarget.scrollTop;Bi.current&&(Bi.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Qr.current){$r.current=r;return}let i=bl(n,r,[...qe(Mr,bn.filter(Ce).map(e=>e.filename)),...Dl(Mr,ca.keys()),...jr.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),$r.current=i.end):$r.current=n,ic()},onFocus:()=>{if(dr){if(Date.now()<pe.current){let e=Yr.current;e&&e.blur();return}B.current!==null&&(window.clearTimeout(B.current),B.current=null),z(!0)}},onBlur:e=>{if(Qr.current=!1,$r.current=e.currentTarget.selectionStart??$r.current,Gu(),dr){if(Date.now()<Wu.current){let e=Yr.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Wu.current&&document.activeElement!==e&&e.focus()},50);return}}if(he.current=Date.now(),$e()){z(!1);return}B.current!==null&&window.clearTimeout(B.current),B.current=window.setTimeout(()=>{B.current=null,z(!1)},120)}},autoCorrect:dr?`on`:`off`,autoCapitalize:dr?`sentences`:`off`,spellCheck:dr||Sr,fillContainer:Gi,rows:1},children:[(0,$.jsx)(ub,{}),xc?(0,$.jsx)(YT,{inputRef:Yr,draftID:En?gn(En):null,ariaLabel:l(`textarea.resizeHandleAria`),onManualHeightChange:Cc}):null,v&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ki},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:rd,onClick:()=>xl(),title:l(`chat.chatInput.actions.attachFiles`),"aria-label":l(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(nd,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:l(b?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),E&&(0,$.jsx)(mu,{ref:pi,searchQuery:O,directory:Tn,onCommandSelect:Zc,onClose:()=>D(!1),commandPolicy:Pu,commandContext:Dn,onRowsChange:Ru?Mu:void 0,style:Hi&&Ua?{left:`${Ua.left}px`,top:`${Ua.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${Ua.left+8}px))`,maxHeight:`${Ua.maxHeight}px`,transform:Ua.place===`above`?`translateY(-100%)`:void 0}:void 0}),S&&(0,$.jsx)(ql,{ref:di,searchQuery:w,onFileSelect:Kc,onAgentSelect:qc,onSkillSelect:Xc,onSessionSelect:Jc,onClose:()=>C(!1),onRowsChange:Ru?Mu:void 0,style:Hi&&Ua?{left:`${Ua.left}px`,top:`${Ua.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${Ua.left+8}px))`,maxHeight:`${Ua.maxHeight}px`,transform:Ua.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),dr&&ya&&!xa?(0,$.jsx)(YE,{radius:Ki,isMobile:dr,footerIconButtonClass:id,footerPaddingClass:Qu,iconSizeClass:nd,sendIconSizeClass:ed,onInsert:Ls,onInsertAndSend:qs,onContentHeightChange:bc,onActiveChange:_c,disabled:xn||Sa!==null||!q&&!Sn,renderTrigger:!1,topAccessory:XE},on):null]})})]}),dr?(0,$.jsxs)(`div`,{className:`yuri-mobile-composer-compact-layer`,"data-yuri-composer-compact-surface":`true`,children:[pd,(0,$.jsx)(`div`,{ref:vc,onPointerDown:()=>{yc.current=!1},onScroll:e=>{let t=e.currentTarget;yc.current=t.scrollWidth-t.clientWidth-t.scrollLeft<=2},className:Y(`yuri-mobile-composer-compact-preview`,!Mr.trim()&&`yuri-mobile-composer-compact-preview--placeholder`),style:fd?{right:`${.625+2.5*(1+Number(!!(n&&r))+Number(!!(es||Zo||uc)))}rem`}:void 0,"aria-hidden":`true`,children:Mr.trim()?Mr:xa?Da:qi})]}):null]}),dr?(0,$.jsx)(JE,{className:`hidden`,composerTextareaRef:Yr,selectionAdapter:$n,mobilePanel:P,onMobilePanelChange:F}):null]}),Sn&&!Hi&&!dr&&!Al&&!vu?(0,$.jsx)(SS,{onSubmit:Is,className:`chat-input-column mt-4`}):null]}),m.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(SE,{popup:m,onOpenChange:vr,isMobile:dr})}):null,(0,$.jsx)($x,{open:Ka,onOpenChange:qa,mode:`select`,onSelect:e=>{to(e),io(null)}}),(0,$.jsx)(nS,{open:Xa,onOpenChange:Qa,onSelect:e=>{io(e),to(null)}}),(0,$.jsx)(Nh,{open:Pn,onOpenChange:Fn,projectDirectory:Je??Tn??null,submitting:Ln,onConfirm:Vi}),(0,$.jsx)(`input`,{ref:cl,type:`file`,multiple:!0,className:`hidden`,onChange:wl,accept:`*/*`}),(0,$.jsx)(`input`,{ref:ll,type:`file`,multiple:!0,className:`hidden`,onChange:wl,accept:`image/*`}),null,pr?(0,$.jsx)(_l,{id:`android-media-pick-sheet`,open:U,onOpenChange:e=>{e||W(!1)},onPickPhotos:()=>{_e.current=!1,W(!1),requestAnimationFrame(Cl)},onPickFiles:()=>{_e.current=!1,W(!1),requestAnimationFrame(xl)}}):null,dr&&Ml&&Pl?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(fl,{id:`mobile-draft-project-picker-sheet-${ne}`,open:ee===`project`,onOpenChange:e=>{e||te(null)},ariaLabel:l(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:l(`mobile.surface.closeAria`),resizeAriaLabel:l(`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)(Ks,{value:re,onChange:e=>G(e.target.value),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(Xu,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:(0,$.jsx)(nD,{projects:jn,query:re,renderLabel:qE,selectedId:Pl.id,onSelect:e=>{Su(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),ga.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},dD=e=>{let t=(0,Q.c)(3),n=Ly(),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)(uD,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};dD.displayName=`ChatInput`;var fD=Z.memo(dD);function pD(e){return e.preventDefault()}function mD(e){e.preventDefault()}function hD(e){return e.preventDefault()}function gD(e){e.pointerType===`touch`&&e.preventDefault()}function _D(e){e.preventDefault()}function vD(e){e.pointerType===`touch`&&e.preventDefault()}var yD=e=>!!(e&&typeof e==`object`&&typeof e.type==`string`),bD=e=>e.filter(yD),xD=e=>{let t=e,n=t.text;return typeof n==`string`?n:t.content||t.value||``},SD=e=>/[^\s\u200B-\u200D\u2060\uFEFF]/u.test(e),CD=e=>e.type===`text`&&!SD(xD(e)),wD=(e,t={})=>{let{includeReasoning:n=!0}=t,r=bD(e),i=r.some(e=>!e.synthetic);return r.filter(e=>{let t=!!e.synthetic;if(e.type===`text`){if(CD(e))return!1;let t=xD(e);if(t.includes(`<system-reminder>`)&<(t).length===0)return!1}return t&&i||!n&&e.type===`reasoning`?!1:e.type!==`patch`})},TD=`GitHub issue context (JSON)`,ED=`GitHub pull request context (JSON)`,DD=`The user referenced these OpenCode sessions (id, title, owning directory).`,OD=e=>typeof e==`number`&&Number.isFinite(e)&&e>0,kD=(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}},AD=e=>{let t=kD(e,TD);if(t){let e=t.issue,n=e?.number,r=e?.title,i=e?.url;return!OD(n)||typeof r!=`string`||typeof i!=`string`?null:{type:`file`,mime:`application/vnd.github.issue-link`,filename:`Issue #${n}: ${r}`,url:i}}let n=kD(e,ED);if(n){let e=n.pr,t=e?.number,r=e?.title,i=e?.url;return!OD(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},jD=e=>!!e.trim().startsWith(`The following tool was executed by the user`),MD=e=>e.trimStart().startsWith(`Continue working toward the active session goal.`),ND=e=>e.trim()===`/compact`,PD=e=>e.flatMap(e=>{if(e.type===`compaction`)return[];if(e.type===`text`){let t=e.text;if(typeof t==`string`){let n=Ka(t);if(n.trim().length===0||MD(n)||ND(n)||n.trimStart().startsWith(DD)||n.includes(`<system-reminder>`)&<(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 jD(t)||n.startsWith(TD)||n.startsWith(ED)?[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=AD(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:lt(n)}}return e}),FD=e=>e.some(e=>{if(e.type===`text`)return!CD(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&&!Fe(e)}return!0}),ID=e=>e?.length?FD(PD(e)):!1,LD=(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(ID(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]},RD=(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},zD=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}},BD=e=>e.syncLoading||e.assistantLoading,VD=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),HD=e=>e.isLoadingOlder,UD=e=>!e.isMobile&&e.isLoadingOlder,WD=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,GD=e=>e.hasImmediateShell||e.hasTranscriptShell&&e.hasRenderableSessionSnapshot||e.transcriptRecords?.some(e=>e.info.role===`user`?ID(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`,KD=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}},qD=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),JD=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,YD=`relative bottom-safe-area yuri-mobile-readonly-prompt-foot`,XD=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)(Os,{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},ZD=e=>{let t=(0,Q.c)(42),{t:n}=Xn(),r=K(QD),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&YD,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 ${JD}`,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&&YD,h;t[18]===m?h=t[19]:(h=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] 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 ${JD}`,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)(ds,{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)(XD,{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 QD(e){return e.isMobile}var $D=Z.memo(()=>{let e=(0,Q.c)(5),{t}=Xn(),{currentTheme:n}=fs(),r=si(eO),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Gc,{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 eO(e){return e.error}var tO=`yuri_asst_session_divider:`,nO=[],rO=e=>typeof e?.info?.id==`string`&&e.info.id.startsWith(`yuri_asst_session_divider:`),iO=(e,t=0)=>({info:{id:`${tO}${e}`,role:`system`,time:{created:t}},parts:[]}),aO=e=>!!(e?.info&&typeof e.info==`object`&&e.info.yuriAssistantAdmission),oO=(e,t,n=nO)=>{if(!e.length)return nO;let r=[],i=!1,a=null;for(let n of e)n.sessionID!==t&&(i&&a!==n.sessionID&&r.push(iO(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?nO:dO(n,r)?n:r},sO=(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},cO=(e,t)=>{if(!t)return e;if(e.info.role===`assistant`&&t.parts.length>0){let n=sO(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 ID(e.parts)?e:ID(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}:{}}},lO=(e,t,n,r=nO)=>{if(!t)return n.length>0?Array.from(n):nO;let i=new Map,a=0;for(let n of e)n.sessionID===t&&(aO(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:cO(e,t?.message),order:t?.order??a++})}if(i.size===0)return nO;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 dO(r,o)?r:o},uO=(e,t)=>{if(!rO(e)||!rO(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},dO=(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||uO(r,i))&&(r?.info!==i?.info||r?.parts!==i?.parts||r.sourceSessionID!==i.sourceSessionID||r.sourceDirectory!==i.sourceDirectory))return!1}return!0},fO=()=>V(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}})})),pO=(0,Z.createContext)(null);function mO(e){let t=(0,Q.c)(7),n=(0,Z.useContext)(pO),r;t[0]===n?r=t[1]:(r=()=>n??fO(),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=z(a,o),c=z(a,hO),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 hO(e){return e.toggle}var gO={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`)}},_O=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)}}},vO=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:Za(t)},yO=Z.memo(e=>{let t=(0,Q.c)(30),{isUser:n,isMobile:r,providerID:i,modelID:a,agentName:o,modelName:s,variant:c}=e,l;t[0]!==r||t[1]!==n||t[2]!==c?(l=!n&&!r?vO(c):null,t[0]=r,t[1]=n,t[2]=c,t[3]=l):l=t[3];let u=l,d=s||`Assistant`,f,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=Y(`mb-1.5`),p=Y(`flex items-center justify-between gap-2`),t[4]=f,t[5]=p):(f=t[4],p=t[5]);let m;t[6]!==o||t[7]!==n||t[8]!==a||t[9]!==i?(m=(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)(Os,{modelId:a,providerId:i,className:`h-4 w-4`,fallback:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-4 w-4`,style:{color:`var(${os(o).var})`}})})})}),t[6]=o,t[7]=n,t[8]=a,t[9]=i,t[10]=m):m=t[10];let h=n?`text-primary`:`text-foreground`,g;t[11]===h?g=t[12]:(g=Y(`inline-flex min-w-0 items-center gap-1.5 font-semibold typography-ui-header tracking-tight leading-tight`,h),t[11]=h,t[12]=g);let _=n?`You`:d,v;t[13]===_?v=t[14]:(v=(0,$.jsx)(`span`,{className:`truncate`,children:_}),t[13]=_,t[14]=v);let y;t[15]===u?y=t[16]:(y=u?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-normal leading-tight text-muted-foreground`,children:u}):null,t[15]=u,t[16]=y);let b;t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsxs)(`h3`,{className:g,children:[v,y]}),t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20];let x;t[21]!==o||t[22]!==n?(x=!n&&o&&(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]`,os(o).class),children:[(0,$.jsx)(ds,{name:o,size:10,shape:`square`}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=n,t[23]=x):x=t[23];let S;t[24]!==b||t[25]!==x?(S=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[b,x]}),t[24]=b,t[25]=x,t[26]=S):S=t[26];let C;return t[27]!==S||t[28]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[m,S]})})}),t[27]=S,t[28]=m,t[29]=C):C=t[29],C}),bO=6e5,xO=new Map,SO=e=>{let t=kn(e);if(!t)return;let n=xO.get(t);if(n){if(n.expiresAt<=Date.now()){xO.delete(t);return}return n.outsideFileGrant}},CO=(e,t,n)=>{let r=kn(e);!r||!t||xO.set(r,{outsideFileGrant:t,expiresAt:typeof n==`number`&&Number.isFinite(n)?n:Date.now()+bO})},wO=async(e,t)=>{let n=kn(e);if(!n||!t||An(n,t))return;let r=SO(n);if(r)return r;let i=await m(n);if(!(!i.success||!i.path||!i.outsideFileGrant))return CO(i.path,i.outsideFileGrant),kn(i.path)!==n&&CO(n,i.outsideFileGrant),i.outsideFileGrant},TO=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,EO=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,DO=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),OO=(e,t)=>e.split(EO).map((e,n)=>n%2==1?e:t(e)).join(``),kO=e=>OO(e,e=>e.replace(/ *\n/g,`
|
|
6555
6555
|
`)),AO=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=OO(e,DO);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${wd(t.name)})`;i=i.replace(t.token,e)}i=i.replace(TO,(e,t,r)=>n.has(r)?`${t}[/${r}](${Ad(r)})`:e)}return kO(i)},jO=e=>(TO.lastIndex=0,TO.test(e)||e.includes(`[skill:`)),MO=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)},NO=Z.memo(e=>{let t=(0,Q.c)(84),{part:n,messageId:r,agentMention:i,messageParts:a}=e,o=n,s=o.text,c=typeof s==`string`?s:o.content||o.value||``,l;t[0]===c?l=t[1]:(l=e_(c),t[0]=c,t[1]=l);let u=l,d=u?u.body:c,[f,p]=Z.useState(!1),[m,h]=Z.useState(!1),g=K(PO),_=bd(),v;t[2]===d?v=t[3]:(v=jO(d),t[2]=d,t[3]=v);let y;t[4]!==_||t[5]!==v?(y={directory:_,enabled:v},t[4]=_,t[5]=v,t[6]=y):y=t[6];let b=$i(y),x;t[7]===b.data?x=t[8]:(x=b.data??[],t[7]=b.data,t[8]=x);let S=x,C=K(FO),{t:w}=Xn(),T=g&&!f,E=Z.useRef(null),D;t[9]===S?D=t[10]:(D=new Map(S.map(IO)),t[9]=S,t[10]=D);let O=D,k;t[11]!==a||t[12]!==d?(k=B_(a,d),t[11]=a,t[12]=d,t[13]=k):k=t[13];let A=k,j;if(t[14]!==a||t[15]!==d){let e=new Map;for(let t of a??[]){if(t.type!==`text`||!ro(t))continue;let n=t.text;if(typeof n==`string`)for(let t of Eo(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(d.includes(`@`))for(let[t,n]of ge()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(d.includes(`@${r}`)||d.includes(`@${Kt}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}j=Array.from(e.values()),t[14]=a,t[15]=d,t[16]=j}else j=t[16];let M=j,N;t[17]!==_||t[18]!==C||t[19]!==O?(N=e=>{let t=O.get(e),n=typeof t?.path==`string`?t.path:``,r=kn(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=_||Nn(``,i)||`/`,o=()=>{C(a,i)};if(_&&!An(i,_)){wO(i,_).then(o);return}o()},t[17]=_,t[18]=C,t[19]=O,t[20]=N):N=t[20];let P=J(N),F;t[21]!==g||t[22]!==f?(F=()=>{let e=E.current;if(!e)return;let t=()=>{g&&!f&&e.scrollHeight>e.clientHeight&&h(!0)};h(!1),t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},t[21]=g,t[22]=f,t[23]=F):F=t[23];let I;t[24]!==g||t[25]!==f||t[26]!==d?(I=[g,d,f],t[24]=g,t[25]=f,t[26]=d,t[27]=I):I=t[27],Z.useEffect(F,I);let L,R;t[28]===g?(L=t[29],R=t[30]):(L=()=>{g||(p(!1),h(!1))},R=[g],t[28]=g,t[29]=L,t[30]=R),Z.useEffect(L,R);let z;t[31]!==g||t[32]!==f||t[33]!==m||t[34]!==P?(z=e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??Ed(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),P(n);return}let r=E.current;r&&(MO(r)||g&&!f&&m&&p(!0))},t[31]=g,t[32]=f,t[33]=m,t[34]=P,t[35]=z):z=t[35];let B=J(z),V;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(V=e=>{e.stopPropagation(),p(!1)},t[36]=V):V=t[36];let H=J(V),U;t[37]!==i||t[38]!==A.displayNames||t[39]!==A.icons||t[40]!==M||t[41]!==O||t[42]!==d?(U=P_(d,{skillNames:new Set(O.keys()),citationIcons:A.icons,citationDisplayNames:A.displayNames,sessionMentions:M,agentNames:i?.name?new Set([i.name.toLowerCase(),i.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),t[37]=i,t[38]=A.displayNames,t[39]=A.icons,t[40]=M,t[41]=O,t[42]=d,t[43]=U):U=t[43];let W=U,ee;t[44]!==i||t[45]!==W||t[46]!==O||t[47]!==d?(ee=AO({textContent:d,agentMention:i,skillNames:new Set(O.keys()),decorateInlineReferences:!W}),t[44]=i,t[45]=W,t[46]=O,t[47]=d,t[48]=ee):ee=t[48];let te=ee,ne;t[49]===T?ne=t[50]:(ne=(e,t)=>{if(!e)return null;let n=AO({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(Gu,{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`,T&&[`[&_.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[49]=T,t[50]=ne);let re=ne,G;t[51]!==P||t[52]!==re?(G=e=>e.map((e,t)=>e.type===`text`?re(e.text,`text-${t}`):(0,$.jsx)(H_,{decoration:e.decoration,onOpenSkill:P},`ref-${t}-${e.span.start}`)),t[51]=P,t[52]=re,t[53]=G):G=t[53];let ie=G;if((!d||d.trim().length===0)&&!u?.quotes.length)return null;let ae=T&&m,oe=n.id||`${r}-user-text`,se=ae?`true`:void 0,ce;t[54]!==g||t[55]!==H||t[56]!==f||t[57]!==w?(ce=g&&f&&(0,$.jsx)(`button`,{type:`button`,onClick:H,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":w(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),t[54]=g,t[55]=H,t[56]=f,t[57]=w,t[58]=ce):ce=t[58];let le;t[59]!==r||t[60]!==n.id||t[61]!==u||t[62]!==w?(le=u&&u.quotes.length>0?(0,$.jsx)(`div`,{className:`mb-2 flex flex-col gap-1`,"data-conversation-quotes":!0,"aria-label":w(`chat.message.conversationQuotesLabel`),children:u.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[59]=r,t[60]=n.id,t[61]=u,t[62]=w,t[63]=le):le=t[63];let ue;t[64]!==g||t[65]!==B||t[66]!==T||t[67]!==f||t[68]!==m||t[69]!==te||t[70]!==W||t[71]!==ie||t[72]!==d?(ue=d.trim().length>0?(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,f&&`pb-3`,T&&`line-clamp-10`,g&&m&&!f&&`cursor-pointer`),"data-user-message-collapse":T?`true`:void 0,ref:E,onClick:B,children:W?ie(W):(0,$.jsx)(Gu,{content:te,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,T&&[`[&_.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[64]=g,t[65]=B,t[66]=T,t[67]=f,t[68]=m,t[69]=te,t[70]=W,t[71]=ie,t[72]=d,t[73]=ue):ue=t[73];let de;t[74]!==ae||t[75]!==w?(de=ae&&(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:()=>p(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p(!0))},children:[w(`chat.message.userText.showMore`),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-[1em] shrink-0`})]}),t[74]=ae,t[75]=w,t[76]=de):de=t[76];let fe;return t[77]!==oe||t[78]!==se||t[79]!==ce||t[80]!==le||t[81]!==ue||t[82]!==de?(fe=(0,$.jsxs)(`div`,{className:`relative`,"data-user-message-clamp":se,children:[ce,le,ue,de]},oe),t[77]=oe,t[78]=se,t[79]=ce,t[80]=le,t[81]=ue,t[82]=de,t[83]=fe):fe=t[83],fe});function PO(e){return e.collapsibleUserMessages}function FO(e){return e.openContextFile}function IO(e){return[e.name,e]}var LO=[{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)(lf.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)(lf.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)(lf.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)(lf.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 RO(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=LO.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||LO[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 zO=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)(X,{name:`list-check-3`,className: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})},BO=new Map,VO=e=>{let t=BO.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return BO.set(e,n),n},HO=(e,t)=>{let n=VO(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=BO.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),BO.delete(e)))}},UO=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(WO),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return HO(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 WO(){return Date.now()}var GO=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],KO=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}},qO=(...e)=>{for(let t of e){let e=KO(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}}},JO=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},YO=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},XO=e=>{let t=YO(e);return t===`task`||t===`subagent`},ZO=e=>{let t=YO(e);return t===`shell`||t===`bash`||t===`cmd`||t===`terminal`},QO=e=>XO(e)||ZO(e),$O=e=>{if(!e||typeof e!=`object`)return;let t=e;return JO(t.sessionId)??JO(t.sessionID)},ek=(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},tk=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},nk=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:JO(e.sessionId)??JO(e.sessionID),status:JO(e.status),summaryEntries:tk(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},rk=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=nk(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 JO((n?.[1]??r?.[1])||GO(e))},ik=e=>{let t=e.state;return $O(t?.metadata)??$O(t)??$O(t?.input)??$O(e.metadata)??rk(typeof t?.output==`string`?t.output:void 0)},ak=e=>{if(!(!e||typeof e!=`object`))return JO(e.status)},ok=/"status"\s*:\s*"running"/i,sk=/\bstatus\s*[:=]\s*["'`]?running\b/i,ck=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]&&ok.test(t[1])?!0:sk.test(e)},lk=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,uk=(e,t)=>JO(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),dk=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},fk=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(lk);if(!t)return;let n=uk(t[1],`sessionID`)??uk(t[1],`sessionId`),r=dk(uk(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:uk(t[1],`description`),body:t[2].trim()}},pk=/<shell\s+([^>]*?)>([\s\S]*?)<\/shell>/i,mk=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(pk);if(!t)return;let n=uk(t[1],`id`),r=dk(uk(t[1],`state`));if(!(!n||!r))return{id:n,state:r,command:uk(t[1],`command`),body:t[2].trim()}},hk=new WeakMap,gk=e=>{let t=hk.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||XO(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 hk.set(e,n),n},_k=e=>{let t=[];for(let n of e)t.push(...gk(n));return t},vk=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),yk=[`summary`,`changes`,`verification`],bk={summary:`Summary`,changes:`Changes`,verification:`Verification`},xk=/<(summary|changes|verification)(?:\s[^>]*)?>/i,Sk=()=>RegExp(`<(${yk.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),Ck=e=>typeof e!=`string`||e.length===0?!1:xk.test(e),wk=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!Ck(e)?e:e.replace(Sk(),(e,t,n)=>{let r=bk[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),Tk=e=>wk(vk(e)),Ek=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}},Dk=e=>{if(!(!e||typeof e!=`object`||Array.isArray(e)))return e},Ok=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},kk=e=>YO(e.tool??e.name),Ak=e=>Dk(e.state),jk=e=>Dk(Ak(e)?.metadata)??Dk(e.metadata),Mk=e=>Dk(Ak(e)?.input)??Dk(e.input),Nk=e=>Ok(Ak(e)?.status)?.toLowerCase(),Pk=e=>(Array.isArray(e.parts)?e.parts:Array.isArray(e.content)?e.content:[]).filter(e=>!!e&&typeof e==`object`),Fk=e=>{let t=[],n=Ok(Dk(e.metadata)?.text);n&&t.push(n);for(let n of Pk(e)){let e=Ok(n.text);e&&t.push(e)}let r=Ok(e.text);return r&&t.push(r),t},Ik=e=>{let t=Ok(e)?.toLowerCase();if(t===`completed`||t===`error`||t===`cancelled`)return t},Lk=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=Dk(t.metadata),n=Ok(e?.source)?.toLowerCase(),a=Ik(e?.state);n===`shell`&&a&&(r(Ok(e?.shellID),a),r(Ok(e?.jobID),a),r(Ok(e?.id),a)),n===`subagent`&&a&&i(Ok(e?.childID)??Ok(e?.sessionID)??Ok(e?.sessionId),a);for(let e of Fk(t)){let t=mk(e);t&&(r(t.id,t.state),r(t.shellID,t.state),r(t.jobID,t.state));let n=fk(e);n&&i(n.sessionID,n.state)}}return{byShellOrJobID:t,byChildSessionID:n}},Rk=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return t.type!==void 0&&t.type!==`tool`||!QO(kk(t))||Nk(t)!==`completed`?!1:ak(jk(t))===`running`||ak(Ak(t))===`running`},zk=e=>{if(!e||typeof e!=`object`)return!1;let t=e;if(t.type!==void 0&&t.type!==`tool`||!QO(kk(t)))return!1;let n=Nk(t);return n===`running`||n===`pending`||n===`started`},Bk=e=>{if(!e||typeof e!=`object`)return;let t=e,n=kk(t);if(!QO(n))return;let r=jk(t),i=Mk(t);if(XO(n)){let e=$O(r)??$O(Ak(t))??$O(i),n=Ok(i?.description),a=Ok(i?.agent)??Ok(i?.subagent_type)??Ok(i?.subagentType);return{type:`subagent`,id:e,label:n??e,agent:a}}let a=Ok(r?.shellID)??Ok(Ak(t)?.shellID),o=Ok(r?.jobID)??Ok(Ak(t)?.jobID),s=Ok(i?.command),c=Ok(t.id);return{type:`shell`,id:a??o??c,label:s??a??o??c}},Vk=(e,t,n)=>{if(!n)return;let r=jk(t),i=Ak(t),a=[e.id,Ok(r?.shellID),Ok(r?.jobID),Ok(i?.shellID),Ok(i?.jobID),Ok(t.id)];for(let e of a){if(!e)continue;let t=n.byShellOrJobID.get(e);if(t)return t}},Hk=(e,t)=>{if(!(!t||!e.id))return t.byChildSessionID.get(e.id)},Uk=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`||!QO(kk(i)))return{kind:`settled`};if(zk(t))return{kind:`blocking`};let a=Bk(t);if(!a)return{kind:`settled`};if(a.type===`shell`){let e=Vk(a,i,n);return e?{kind:`terminal`,state:e}:Rk(t)?{kind:`background-running`}:{kind:`settled`}}let o=Ok(r)?.toLowerCase();if(o===`idle`)return{kind:`settled`};if(o===`busy`||o===`retry`)return{kind:`background-running`};let s=Hk(a,n);return s?{kind:`terminal`,state:s}:Rk(t)?(a.id,{kind:`background-running`}):{kind:`settled`}},Wk=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`}}},Gk=e=>{if(!e||typeof e!=`object`)return;let t=e;if(!ZO(kk(t)))return;let n=jk(t),r=Ak(t),i=Ok(n?.shellID)??Ok(r?.shellID),a=Ok(n?.jobID)??Ok(r?.jobID),o=Ok(t.id);return{shellID:i,jobID:a,workID:i??a??o}};function Kk(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 qk=(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},Jk=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},Yk=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},Xk=e=>e?.state,Zk=e=>e?.metadata,Qk=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},$k=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,``):``},eA=(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||Jk(r)!==Jk(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(Xk(r)!==Xk(i)||Zk(r)!==Zk(i)||Yk(r)!==Yk(i))return!1;let e=Qk(r),t=Qk(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=Qk(r),o=Qk(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if($k(r)!==$k(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},tA=(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&&qk(e.tokens,t.tokens),nA=(e,t)=>tA(e.info,t.info)&&eA(e.parts,t.parts),rA=(e,t)=>!e||!t?e===t:nA(e,t),iA=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,aA=(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},oA=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&eA([e.part],[t.part]),sA=(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(!oA(a,o))return!1;r+=1,i+=1}},cA=(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(!oA(e.parts[n],t.parts[n]))return!1;return!0},lA=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),uA=(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(!cA(a,o))return!1;r+=1,i+=1}},dA=(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||!sA(e.activityParts,t.activityParts,n)||!uA(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=lA(e.activityGroupSegments,n)||lA(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!iA(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!aA(e.changedFiles,t.changedFiles))},fA=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,pA=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,mA=/(?=^diff --git\s+)/gm,hA=/^diff --git\s+/m,gA=/(?=^---\s+\S)/gm,_A=/^---\s+\S/m,vA=e=>typeof e==`object`&&!!e,yA=e=>e.replace(/\r\n/g,`
|
|
6556
6556
|
`).replace(/\r/g,`
|
|
6557
6557
|
`).trim(),bA=e=>{let t=!1;return e.split(`
|
|
@@ -6589,16 +6589,16 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{S as t,l as n,w as r}f
|
|
|
6589
6589
|
|
|
6590
6590
|
`):nP(Array.from(t.childNodes).map(e=>sP(e)).join(``))},uP=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!eP.has(t.tagName.toLowerCase())}),dP=(e,t)=>{let n=e.cloneContents();if(uP(n)){let e=nP(Array.from(n.childNodes).map(e=>sP(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>lP(e)).filter(e=>e.length>0).join(`
|
|
6591
6591
|
|
|
6592
|
-
`).trim()||nP(t)},fP=({containerRef:e})=>{let{t}=Xn(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),o=Z.useRef(!1),[s,c]=Z.useState(!1),l=Z.useRef(null),u=Z.useRef(XN),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=bd()??null,b=K(e=>e.isMobile),x=Ab(),S=jb(x).textSelectionMutation,C=x.kind===`primary`&&!!v;Z.useEffect(()=>{m.current=n.show},[n.show]),Z.useEffect(()=>()=>{f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]);let w=Z.useCallback(()=>{d.current=null,$N===w&&($N=null),m.current&&=(f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),c(!1),r(e=>({...e,show:!1})),a(``),!1)},[]);Z.useEffect(()=>()=>{$N===w&&($N=null)},[w]);let T=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=u.current/2,r=GN+n,i=t-GN-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),E=Z.useCallback(()=>{if(!d.current)return;$N!==w&&($N?.(),$N=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=nP(t.toString());if(!r){o.current||w();return}let i=aP(t,n);if(!i){o.current||w();return}let a=i.getBoundingClientRect();d.current={plainText:r,markdownText:dP(i,r),rect:a},o.current||E()},[e,w,E]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{o.current=!0,w()},r=()=>{o.current=!1,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{p.current=null,D()},10)},i=new Set,a=()=>{for(let e of iP(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=hw(bw),t=0,r=0,i=()=>{let e=QN(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=Jg(v,t);n&&(o_.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};dw.getState().addQuote(t,e),O(),Pw(t)});if(Z.useEffect(()=>{if(!S)return;let t=t=>{let n=Tc(t,KN),r=C&&Tc(t,qN);if(!n&&!r)return;let i=window.getSelection(),a=e.current;if(!i||!a||!i.toString().trim())return;let o=aP(i,a);if(!o)return;t.preventDefault(),t.stopPropagation();let s=dP(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:KN,run:()=>k(i)},...C?[{id:`side`,label:t(`chat.textSelection.actions.addToSideChat`),shortcut:qN,run:()=>A(i)}]:[]];if(b){let e=g??{left:0,top:Math.max(0,window.innerHeight-88),width:window.innerWidth,height:88};return(0,Dp.createPortal)((0,$.jsx)(`div`,{ref:l,"data-text-selection-menu":!0,className:Y(`fixed z-50 flex items-center justify-center gap-2 bg-background px-4`,`transition-opacity duration-200 ease-out`,s?`opacity-0`:`opacity-100`),style:{left:e.left,top:e.top,width:e.width,height:e.height,paddingBottom:`max(0.75rem, var(--yuri-safe-area-bottom-visual, env(safe-area-inset-bottom, 0px)))`},onPointerDown:e=>{e.preventDefault()},children:j.map(e=>(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`sm`,onClick:e.run,className:`max-w-[11rem] min-w-0`,children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})},e.id))}),document.body)}return(0,Dp.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:YN(e.shortcut)})]})]},e.id))})}),document.body)},pP=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),mP=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),pP(e,n)},hP=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),gP=e=>String(e).padStart(2,`0`),_P=e=>{if(!hP(e))return``;let t=new Date(e);return`${t.getFullYear()}-${gP(t.getMonth()+1)}-${gP(t.getDate())} ${gP(t.getHours())}:${gP(t.getMinutes())}`},vP=(e,t)=>{if(!hP(e))return``;let n=new Date(e),r=new Date,i=cc(n,t),a=$n(),o=rr.getState().dictionary;if(pP(n,r))return i;if(mP(n,r))return ir(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},yP=144,bP=null,xP=new Set,SP=!1,CP=null;function wP(){for(let e of xP)e()}function TP(){return bP}function EP(){return CP}function DP(e){return xP.add(e),()=>{xP.delete(e)}}function OP(e,t){let n=Z.useSyncExternalStore(DP,TP,EP);return t&&n===e}function kP(e){!e||bP===e||(bP=e,wP())}function AP(e){bP!==null&&(e&&bP!==e||(bP=null,wP()))}function jP(e){return e instanceof Element?e.closest(`[data-message-id]`)?.getAttribute(`data-message-id`)??null:null}function MP(){SP||typeof document>`u`||(SP=!0,document.addEventListener(`pointerdown`,e=>{bP&&jP(e.target)!==bP&&AP()},!0))}function NP(e,t){MP();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>yP||kP(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),AP(t)}}var PP=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,FP=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+=PP(e.outputTokens)+PP(e.reasoningTokens),!r||t<=0||n<=0)return null;let i=t/(n/1e3);return Number.isFinite(i)&&i>0?i:null})},IP=e=>{let t=FP(e);return t[t.length-1]??null},LP=e=>e.completionDisposition!==`active`&&typeof e.tps==`number`&&Number.isFinite(e.tps)&&e.tps>0,RP=e=>!Number.isFinite(e)||e<=0?``:`${e.toFixed(1)} tok/s`,zP=Z.memo(e=>{let t=(0,Q.c)(5),{sessionId:n}=e,{t:r}=Xn(),i=Zi(n);if(i===0)return null;let a;t[0]!==i||t[1]!==r?(a=r(`chat.sessionBackground.tasksRunning`,{count:i}),t[0]=i,t[1]=r,t[2]=a):a=t[2];let o;return t[3]===a?o=t[4]:(o=(0,$.jsx)(`span`,{className:`inline-flex h-3.5 shrink-0 items-center whitespace-nowrap text-[11px] leading-none font-normal text-muted-foreground`,"data-background-activity":`true`,children:(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:a})}),t[3]=a,t[4]=o),o});zP.displayName=`BackgroundActivityHint`;var BP=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},VP=[`search`,`read`,`list`];function HP(e){let t=xj(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function UP(e){let t={read:0,search:0,list:0};for(let n of e){let e=HP(n);e&&(t[e]+=1)}return t}var WP=[`edit`,`command`,`other`],GP=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),KP=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function qP(e){if(!_j(e))return null;let t=xj(e);return GP.has(t)?`edit`:KP.has(t)?`command`:`other`}function JP(e){let t={edit:0,command:0,other:0};for(let n of e){let e=qP(n);e&&(t[e]+=1)}return t}function YP(e){return WA(e)}var XP=[...VP,...WP];function ZP(e){return{...UP(e),...JP(e)}}function QP(e){return bj(e)}function $P(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!vj(e.toolName):e.kind!=null||e.type!=null}function eF(e,t,n){for(let r=t;r<e.length;r+=1)if($P(n(e[r])))return!0;return!1}function tF(e){return`parts`in e?e.parts.some(e=>QP(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>QP(e))}function nF(e,t,n){let r=[],i=t;for(;i<e.length&&vj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var rF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,iF=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`,rF),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},aF=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=Xn(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??tF({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=ZP(u.map(e=>e.tool)),p=YP(u),m=XP.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:sy(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`,uy),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)(rj,{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,rF,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,rF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(BP,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(iF,{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:cy(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 oF(e,t,n){let r=[],i=t;for(;i<e.length&&gj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var sF=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function cF(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=sF(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=sF(e.name);if(t)return t;let r=sF(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=sF(n.output.name);if(e)return e}return null}function lF(e){let t=[];for(let n of e){if(typeof n!=`string`)continue;let e=n.trim();e&&t.push(e)}let n=t.slice(0,3);return{visibleNames:n,hiddenCount:Math.max(0,t.length-n.length),joinedVisible:n.join(`, `)}}var uF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,dF=({activities:e,isMobile:t,children:n})=>{let{t:r}=Xn(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>bj(e)),{joinedVisible:l,hiddenCount:u}=lF(s.map(cF)),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:sy(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`,uy),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)(rj,{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`,uF,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`,uF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(BP,{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:cy(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]})},fF=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=K(pF),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)(YM,{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 pF(e){return e.chatRenderMode}var mF=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},hF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,gF=Y(`typography-meta font-medium`,hF),_F=Y(`typography-meta`,hF),vF=[],yF=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},bF=e=>{let t=new Set;for(let n of e)yF(n)&&n.messageId&&t.add(n.messageId);return[...t]},xF=(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}),SF=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=pd(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},CF=e=>e,wF=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},TF=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},EF=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},DF=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},OF=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=DF(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`}`},kF=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=OF(n.todos);if(e)return e}if(Array.isArray(r)){let e=OF(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=OF(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=OF(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=OF(e.todos);if(t)return t}}catch{}return null},AF=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)},jF=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(RO,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,_F),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`,_F),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)(RO,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},MF=e=>{let t=kn(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},NF=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 cF(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`?kF(e):wF(e)},PF=e=>{let t=new Set,n=new Set;for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(!XO(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=ik(e)||i;n.add(s),(o.status===`pending`||o.status===`running`)&&t.add(s)}return{active:[...t],all:[...n]}},FF=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=sy(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)(kM,{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&&eA([e.activity.part],[t.activity.part])),IF=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=sy(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(zF,{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&&RF(e.activities,t.activities)),LF=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!xD(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(vj(i)){let r=nF(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:eF(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(gj(i)){let r=oF(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(pj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(fj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(mj(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},RF=(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||!eA([r.part],[i.part]))return!1}return!0},zF=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=Xn(),s=K(UF),c=vd(n,o),l;t[0]===n?l=t[1]:(l=zO(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(En),m=Ll(),h=le(WF),g=Ab(),_=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=$i(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(GF)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||bj(E.part),O;t[12]===E?O=t[13]:(O=E?NF(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||EF(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=MF(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=TF(E);if(!e){M=null;break bb1}let n=jn(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=AF(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=Mn(_,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(!An(n,_)){wO(n,_).then(()=>{let e=K.getState(),r=_||Nn(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=K.getState(),i=Nn(_,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=kn(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=K.getState(),n=_||Nn(``,t);e.openContextFile(n,t)};if(_&&!An(t,_)){wO(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let te=J(ee),ne;t[48]===te?ne=t[49]:(ne=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),te())},t[48]=te,t[49]=ne);let re=J(ne),G=U&&W&&`cursor-pointer`,ie=U&&!W&&`cursor-default opacity-70`,ae;t[50]!==G||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,uy,G,ie),t[50]=G,t[51]=ie,t[52]=ae):ae=t[52];let oe=U?`soft`:void 0,se=U?te:void 0,ce=U?re:void 0,ue=U?`button`:void 0,de=U&&W?0:void 0,fe=U&&!W?!0:void 0,pe=i?`size-4`:`size-3.5`,me;t[53]===pe?me=t[54]:(me=Y(`inline-flex items-center justify-center flex-shrink-0`,pe),t[53]=pe,t[54]=me);let he;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(he={color:`var(--tools-icon)`},t[55]=he):he=t[55];let ge=D?(0,$.jsx)(rj,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,_e;t[56]!==me||t[57]!==he||t[58]!==ge?(_e=(0,$.jsx)(`div`,{className:me,style:he,children:ge}),t[56]=me,t[57]=he,t[58]=ge,t[59]=_e):_e=t[59];let ve,ye;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ve=Y(gF,`inline-flex items-center flex-shrink-0 opacity-85`),ye={color:`var(--tools-title)`},t[60]=ve,t[61]=ye):(ve=t[60],ye=t[61]);let be;t[62]===c?be=t[63]:(be=(0,$.jsx)(`span`,{className:ve,style:ye,title:c,children:c}),t[62]=c,t[63]=be);let xe;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(xe=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`,_F),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(ig,{filePath:N.path,className:`h-3.5 w-3.5`}):null,jF(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=xe):xe=t[68];let Se;t[69]!==a||t[70]!==k||t[71]!==B?(Se=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(RO,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,_F),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=Se):Se=t[72];let Ce;t[73]!==k||t[74]!==V?(Ce=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:KF,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`,_F),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(SF,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=Ce):Ce=t[75];let we;t[76]!==H||t[77]!==j?(we=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,_F),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=we):we=t[78];let Te;t[79]!==k||t[80]!==H||t[81]!==j?(Te=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,_F),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=Te):Te=t[82];let Ee;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Ee=!f&&!B&&!V&&!H&&k?(0,$.jsx)(RO,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,_F),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]=Ee):Ee=t[89];let De;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==ue||t[95]!==de||t[96]!==fe||t[97]!==_e||t[98]!==be||t[99]!==xe||t[100]!==Se||t[101]!==Ce||t[102]!==we||t[103]!==Te||t[104]!==Ee?(De=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:ue,tabIndex:de,"aria-disabled":fe,children:[_e,be,xe,Se,Ce,we,Te,Ee]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=ue,t[95]=de,t[96]=fe,t[97]=_e,t[98]=be,t[99]=xe,t[100]=Se,t[101]=Ce,t[102]=we,t[103]=Te,t[104]=Ee,t[105]=De):De=t[105],De},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&RF(e.activities,t.activities)),BF=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)(sN,{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}),VF=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)(fF,{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}),HF=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=Xn(),_=bd()??``,v=Z.useMemo(()=>bF(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?mF(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 WA(t)},[e]),N=M.added>0||M.removed>0,P=Z.useMemo(()=>PF(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=Ne(_,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=me(_,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 Ne(_,n,e).status}),te=ee.includes(`loading`),ne=ee.includes(`error`),re=ee.length>0&&ee.every(e=>e===`ready`),G=t.some(e=>W.has(e.messageId)&&yF(e)),ie=re&&!G&&!xF(t,W),ae=Z.useMemo(()=>U?CF(e):vF,[e,U]),oe=Z.useMemo(()=>U?LF(ae.filter(e=>e.kind!==`reasoning`||xD(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:sy(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)(BF,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ue(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(VF,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(FF,{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)(IF,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(aF,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return hj(n)?(0,$.jsx)(zF,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(kM,{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)(dF,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(zF,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(FF,{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?sy(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&&uy,z&&`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":z?void 0:`soft`,onClick:z?void 0:V,"aria-expanded":B,"aria-disabled":z||void 0,"aria-label":z?j:g(B?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex min-w-0 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:k?(0,$.jsxs)(`span`,{className:Y(`typography-meta inline-flex shrink-0 items-center gap-1.5 tabular-nums text-muted-foreground`,c?`h-5`:`h-6`),children:[E?g(`chat.activity.completed`,{duration:E}):j,(0,$.jsx)(X,{name:B?`arrow-down-s`:`arrow-right-s`,className:`size-3.5 shrink-0 opacity-0 group-hover/tool:opacity-70 group-focus-visible/tool:opacity-70`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(rj,{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)(ds,{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)(iF,{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||ne||ie)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,z?void 0:`ml-5`,ne&&`text-[var(--status-error)]`),role:ne?`alert`:`status`,children:te?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):ne?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:R,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]})});function UF(e){return e.showToolFileIcons}function WF(e){return e.currentDirectory}function GF(e){return[e.name,e]}function KF(e){e.stopPropagation()}var qF=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(HF,{...e}),t[0]=e,t[1]=n),n});function JF(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=qi(a,o),c;t[1]===r?c=t[2]:(c=e=>!!e.session_execution_recovery[r],t[1]=r,t[2]=c);let l=z(s,c),u;t[3]===r?u=t[4]:(u=e=>e.session_status[r]?.type===`retry`,t[3]=r,t[4]=u);let d=z(s,u),f=Ca(r,a);if(!l&&!d){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Uv,{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)(Uv,{presentation:n}),t[7]=n,t[8]=m),m}function YF(e){let t=(0,Q.c)(5),n=Ab();if(!e.sessionId||!n.active||!n.capabilities.compose){let n;return t[0]===e.presentation?n=t[1]:(n=(0,$.jsx)(Uv,{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)(JF,{...e,sessionId:e.sessionId,directory:r}),t[2]=e,t[3]=r,t[4]=i):i=t[4],i}var XF={contain:`layout`},ZF={containerType:`inline-size`,containerName:`message-footer`},QF=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,$F=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,eI=`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`,tI=`size-3.5!`,nI=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,rI=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,iI=`flex items-center gap-2`,aI=`flex w-max max-w-full flex-none flex-wrap items-center gap-2 text-muted-foreground`,oI=`h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,sI=`inline-flex ${oI}`,cI=`size-3.5!`,lI=`medium`,uI=e=>{let t=(0,Q.c)(6),{messageId:n,label:r,focusReveal:i}=e,a=OP(n,i),o=i?a?`inline-flex`:`hidden`:`hidden yuri-message-hover-time`,s;t[0]===o?s=t[1]:(s=Y(oI,`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},dI=e=>{let t=(0,Q.c)(16),{label:n}=e,{t:r}=Xn(),i;t[0]!==n||t[1]!==r?(i=r(`chat.messageBody.meta.tpsAria`,{rate:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{weight:lI,name:`pulse`,className:cI}),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)(qs,{asChild:!0,children:(0,$.jsxs)(`span`,{className:sI,"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)(Js,{children:c}),t[11]=c,t[12]=l);let u;return t[13]!==s||t[14]!==l?(u=(0,$.jsxs)(Ys,{children:[s,l]}),t[13]=s,t[14]=l,t[15]=u):u=t[15],u},fI=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,pI=`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)]`,mI=`h-7 gap-1.5`,hI=`h-6 gap-1`,gI=`text-[11px] leading-none`,_I=`size-3.5`,vI=`size-3`,yI=5,bI=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)(ig,{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=fI(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}),xI=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=Xn(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?hI:mI,d;t[3]===u?d=t[4]:(d=Y(pI,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)(bI,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),SI=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=Xn(),c=bd(),l=Ab(),u=l.directory||c,d=l.sessionId,f=Ll(),p=K(FI),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,yI),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(pI,o?hI:mI),E=o?vI:_I,D;t[10]===o?D=t[11]:(D=o?Y(gI,`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(gI,`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(gI,`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){uN({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&uN({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&&uN({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let te;t[46]!==S||t[47]!==A?(te=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=te):te=t[48];let ne;t[49]===E?ne=t[50]:(ne=Y(E,`opacity-60`),t[49]=E,t[50]=ne);let re;return t[51]===ne?re=t[52]:(re=(0,$.jsx)(X,{name:`arrow-right-s`,className:ne}),t[51]=ne,t[52]=re),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,te,re]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(xI,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),CI=e=>e.type===`subtask`,wI=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},TI=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}`},EI=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=bd(),{isMobile:o}=Kc(),s=wa(II),c=K(LI),l=Ab(),{t:u}=Xn(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,p;t[2]===n.command?p=t[3]:(p=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=p);let h=p,g;t[4]===n.agent?g=t[5]:(g=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=g);let _=g,v;t[6]===n.prompt?v=t[7]:(v=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=v);let y=v,b;t[8]===n.taskSessionID?b=t[9]:(b=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=b);let x=b,S;t[10]===n.model?S=t[11]:(S=TI(n.model),t[10]=n.model,t[11]=S);let C=S,w=!!y&&!(o&&l.kind===`primary`),T;t[12]===u?T=t[13]:(T=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=T);let E;t[14]===T?E=t[15]:(E=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:T}),t[14]=T,t[15]=E);let D;t[16]===h?D=t[17]:(D=h?(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:[`/`,h]}):null,t[16]=h,t[17]=D);let O;t[18]===_?O=t[19]:(O=_?(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:[`@`,_]}):null,t[18]=_,t[19]=O);let k;t[20]===C?k=t[21]:(k=C?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:C}):null,t[20]=C,t[21]=k);let A;t[22]!==O||t[23]!==k||t[24]!==E||t[25]!==D?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E,D,O,k]}),t[22]=O,t[23]=k,t[24]=E,t[25]=D,t[26]=A):A=t[26];let j;t[27]===f?j=t[28]:(j=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=j);let M;t[29]!==r||t[30]!==y||t[31]!==w||t[32]!==u?(M=w?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(RI),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:y}):null]}):null,t[29]=r,t[30]=y,t[31]=w,t[32]=u,t[33]=M):M=t[33];let N;t[34]!==_||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==x?(N=x&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&Mb(l,x,e,()=>{if(!Ga({sessionId:x,directory:e})){if(cl()||o||m()){s(x,e);return}c(e,{mode:`chat`,dedupeKey:`session:${x}`,label:f||_||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=_,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=x,t[43]=N):N=t[43];let P;return t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==N?(P=(0,$.jsxs)(`div`,{className:`mt-2`,children:[A,j,M,N]}),t[44]=A,t[45]=j,t[46]=M,t[47]=N,t[48]=P):P=t[48],P},DI=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=bd(),i=K(zI),{isMobile:a}=Kc(),{t:o}=Xn(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!m(),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})}),h;t[6]===p?h=t[7]:(h=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())},t[6]=p,t[7]=h);let g=J(h),_=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,v;t[8]===_?v=t[9]:(v=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`,_),t[8]=_,t[9]=v);let y=c?`button`:void 0,b=c?0:void 0,x=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,S=c?p:void 0,C=c?g:void 0,w;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=w):w=t[10];let T;t[11]===f?T=t[12]:(T=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=T);let E=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,D;t[13]===E?D=t[14]:(D=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,E),t[13]=E,t[14]=D);let O;t[15]!==u||t[16]!==D?(O=(0,$.jsx)(`span`,{className:D,children:u}),t[15]=u,t[16]=D,t[17]=O):O=t[17];let k;t[18]!==T||t[19]!==O?(k=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[T,O]}),t[18]=T,t[19]=O,t[20]=k):k=t[20];let A;t[21]===n.body?A=t[22]:(A=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-clip text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Gu,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=A);let j;t[23]!==k||t[24]!==A?(j=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[k,A]}),t[23]=k,t[24]=A,t[25]=j):j=t[25];let M;return t[26]!==C||t[27]!==j||t[28]!==v||t[29]!==y||t[30]!==b||t[31]!==x||t[32]!==S?(M=(0,$.jsxs)(`div`,{className:v,role:y,tabIndex:b,"aria-label":x,onClick:S,onKeyDown:C,children:[w,j]}),t[26]=C,t[27]=j,t[28]=v,t[29]=y,t[30]=b,t[31]=x,t[32]=S,t[33]=M):M=t[33],M},OI={background:`transparent`,backgroundColor:`transparent`},kI=e=>{let t=(0,Q.c)(37),{part:n}=e,[r,i]=Z.useState(!1),a=Z.useRef(null),{t:o}=Xn(),s;t[0]===n.shellAction?s=t[1]:(s=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=s);let c=s,l=typeof n.shellAction?.output==`string`?n.shellAction.output:``,u;t[2]===n.shellAction?u=t[3]:(u=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=u);let d=u,f=l.length>0,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{a.current!==null&&typeof window<`u`&&(window.clearTimeout(a.current),a.current=null)},t[4]=p):p=t[4];let m=J(p),h,g;t[5]===m?(h=t[6],g=t[7]):(h=()=>()=>{m()},g=[m],t[5]=m,t[6]=h,t[7]=g),Z.useEffect(h,g);let _;t[8]!==m||t[9]!==f||t[10]!==l?(_=async()=>{f&&(await Yn(l)).ok&&(m(),i(!0),typeof window<`u`&&(a.current=window.setTimeout(()=>{i(!1),a.current=null},2e3)))},t[8]=m,t[9]=f,t[10]=l,t[11]=_):_=t[11];let v=J(_),y;t[12]===o?y=t[13]:(y=o(`chat.messageBody.shellCommand.title`),t[12]=o,t[13]=y);let b;t[14]===y?b=t[15]:(b=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:y}),t[14]=y,t[15]=b);let x;t[16]!==d||t[17]!==o?(x=d&&d!==`completed`?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,d===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),role:d===`error`?`alert`:`status`,children:d===`running`?o(`chat.assistantStatus.runningCommand`):d===`pending`?o(`chat.statusRow.todo.status.pending`):d===`error`?o(`chat.toolPart.error`):d}):null,t[16]=d,t[17]=o,t[18]=x):x=t[18];let S;t[19]!==r||t[20]!==v||t[21]!==f||t[22]!==o?(S=f?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,className:`ml-auto text-muted-foreground`,onClick:()=>{v()},"aria-label":o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:(0,$.jsx)(X,{name:r?`check`:`file-copy`,className:`h-3.5 w-3.5`})}):null,t[19]=r,t[20]=v,t[21]=f,t[22]=o,t[23]=S):S=t[23];let C;t[24]!==S||t[25]!==b||t[26]!==x?(C=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[b,x,S]}),t[24]=S,t[25]=b,t[26]=x,t[27]=C):C=t[27];let w;t[28]===c?w=t[29]:(w=c?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Ud,{language:`bash`,code:c,codeStyle:OI,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},AI=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(` `)},jI=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=Xn(),w=mx(),T=jb(Ab()),E=K(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!CD(e):!!(CI(e)||wI(e))),[n]),j=Z.useMemo(()=>A.map(e=>ro(e)?fk(xD(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=vP(i,E);return e.length>0?e:null},[S,i,E]),te=Y(`yuri-user-actions-hover-scope`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),ne=!_&&v&&z?(0,$.jsx)(`div`,{className:te,...gO,children:(0,$.jsxs)(`div`,{className:Y(iI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(sI,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:lI,name:`edit`,className:cI}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:lI,name:`close`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,re=(_&&z?(0,$.jsx)(`div`,{className:te,...gO,children:(0,$.jsx)(`div`,{className:Y(iI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(sI,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??ne??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:te,...gO,children:(0,$.jsxs)(`div`,{className:Y(iI,`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)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(sI,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:lI,name:`time`,className:cI}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(Js,{children:ee})]}):null,m&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:lI,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(tI,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:lI,name:`edit`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:lI,name:g===`fork`?`loader-4`:`git-branch`,className:Y(tI,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:eI,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:lI,name:`check`,className:Y(tI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:lI,name:`file-copy`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full yuri-message-hover-scope`,...gO,"data-user-message-body":`true`,style:XF,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(CI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(EI,{part:e})},e.id??`user-subtask-${i}`);if(wI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(kI,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(DI,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&xD(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(NO,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Ag,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),re]}):(0,$.jsx)($.Fragment,{children:re})}),MI=Z.memo(({messageId:e,hasCopyableText:t,isTouchContext:n,onCopyMessage:r,reviewTransferAction:i,ttsText:a,sessionId:o})=>{let{t:s}=Xn(),c=mx(),l=Ab(),u=jb(l),{isPlaying:d,play:f,stop:p}=IN(),m=Z.useContext(RN),h=!!(m&&m.sessionId===o&&m.messageId===e),g=d||h,_=Ko(e=>e.showMessageTTSButtons),v=Ko(e=>e.voiceProvider),[y,b]=Z.useState(!1),[x,S]=Z.useState(!1),[C,w]=Z.useState(!1),T=Z.useRef(null),E=Z.useRef(null),D=!!r,O=!!((l.sessionId||o)&&l.directory&&u.openSourceSession&&c!==`mini-chat`),k=J(()=>{T.current!==null&&typeof window<`u`&&(window.clearTimeout(T.current),T.current=null)}),A=J(()=>{E.current!==null&&typeof window<`u`&&(window.clearTimeout(E.current),E.current=null)});Z.useEffect(()=>()=>{k(),A()},[A,k]),Z.useEffect(()=>{(!t||!D)&&(b(!1),S(!1),k(),A())},[D,A,k,t]);let j=J(()=>{!n||!D||!t||typeof window>`u`||(k(),b(!0),T.current=window.setTimeout(()=>{b(!1),T.current=null},1800))}),M=J(async e=>{!r||!t||(e.stopPropagation(),e.preventDefault(),await r()!==!1&&(A(),S(!0),typeof window<`u`&&(E.current=window.setTimeout(()=>{S(!1),E.current=null},2e3)),n&&j()))}),N=J(async e=>{if(e.stopPropagation(),e.preventDefault(),!(!i||C||!t)){w(!0);try{await i.onClick()}finally{w(!1)}}}),P=J(e=>{e.stopPropagation(),e.preventDefault();let t=l.sessionId||o;!t||!l.directory||!l.openSourceSession||l.openSourceSession(t,l.directory)}),F=Z.useMemo(()=>g?s(`chat.messageBody.tts.stopSpeaking`):s(`chat.messageBody.tts.readAloudWithProvider`,{provider:v===`browser`?`Browser`:v===`openai`?`OpenAI`:v===`openai-compatible`?`Custom`:`Say`}),[g,s,v]),I=J(e=>{if(e.stopPropagation(),e.preventDefault(),g){h&&m?.stop(),p();return}a.trim()&&f(a)});return(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":y||x?`true`:void 0,className:Y(eI,!t&&`opacity-50`),disabled:!t,"aria-label":s(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!t,onPointerDown:e=>e.stopPropagation(),onClick:e=>{M(e)},onFocus:()=>{t&&b(!0)},onBlur:()=>{x||b(!1)},children:x?(0,$.jsx)(X,{weight:lI,name:`check`,className:Y(tI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:lI,name:`file-copy`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:s(`chat.messageBody.actions.copyAnswer`)})]}),O?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":s(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:P,children:(0,$.jsx)(X,{weight:lI,name:`target`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:s(`chat.messageBody.actions.openSourceSession`)})]}):null,i&&c!==`mini-chat`&&u.reviewTransfer?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,disabled:C||!t,className:Y(eI,(!t||C)&&`opacity-50`),"aria-label":i.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{N(e)},children:C?(0,$.jsx)(X,{weight:lI,name:`loader-4`,className:Y(tI,`animate-spin`)}):(0,$.jsx)(X,{weight:lI,name:`arrow-left-right`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:i.tooltip})]}):null,c!==`mini-chat`&&_&&t&&a.trim()&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:Y(eI,`!bg-transparent shadow-none`,g?`text-[var(--primary-base)]`:`hover:text-foreground/80`),"aria-label":s(g?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),"aria-pressed":g,onPointerDown:e=>e.stopPropagation(),onClick:I,children:(0,$.jsx)(Xm,{kind:`speaker`,active:g,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:F})]})]})}),NI=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:h,allowAnimation:g,onContentChange:_,hasTextContent:v=!1,onCopyMessage:y,onAuxiliaryContentComplete:b,showReasoningTraces:x=!1,shouldShowHeader:S=!1,turnGroupingContext:C,errorPresentation:w,reviewTransferDirection:T=null})=>{let E=w?.text,{t:D}=Xn(),O=mx(),k=Ab(),A=jb(k),j=h,M=Z.useRef(null),N=Z.useRef(null),P=h===`streaming`||h===`cooldown`,F=Z.useRef({messageId:t,experiencedStreamingOrCooldown:P});F.current.messageId===t?P&&(F.current.experiencedStreamingOrCooldown=!0):F.current={messageId:t,experiencedStreamingOrCooldown:P};let I=!!(u??c),L=!!(l??c),R=c?rI:nI,z=!i,B=Z.useMemo(()=>n.filter(e=>!CD(e)).filter(e=>e.type!==`reasoning`||x&&xD(e).trim().length>0).filter(e=>e.type!==`compaction`),[n,x]),V=Z.useMemo(()=>B.filter(e=>e.type===`tool`),[B]),H=Z.useMemo(()=>B.filter(e=>e.type===`text`),[B]),U=Z.useMemo(()=>Na(H),[H]),W=K(e=>e.openContextPreview),ee=m(),te=O===`mini-chat`,ne=Z.useMemo(()=>{if(ee||c||te)return null;for(let e of H){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=md(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of V){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=md(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[H,c,te,ee,V]),re=wa(e=>e.forkFromMessage),G=wa(e=>e.forkTransition),ie=wa(e=>e.currentSessionId),ae=wa(e=>e.getDirectoryForSession),oe=bd(),se=T===`review-to-original`,ce=!c&&!ee?T:null,le=Z.useMemo(()=>{let t=U.trim();if(!(!e||!oe||!t||!ce))return ce===`review-to-original`?{ariaLabel:D(`chat.messageBody.actions.sendReviewFeedback`),tooltip:D(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await ia(e,oe,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:D(`chat.messageBody.actions.sendImplementationResponse`),tooltip:D(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await Xi(e,oe,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[U,oe,ce,e,D]),[ue,de]=Z.useState(!1),fe=K(e=>e.chatRenderMode),pe=C?fe:`live`,me=K(e=>e.collapsibleThinkingBlocks),he=K(e=>e.showSplitAssistantMessageActions),ge=K(e=>e.showAssistantTps),_e=pe===`sorted`,ve=C?.isLastAssistantInTurn??!1,ye=a===`stop`,be=(ye||i||!!E)&&(C?.isTurnSettled??!0),xe=ye?`completed`:j,Se=V.length>0,Ce=Z.useMemo(()=>V.some(e=>bj(e)),[V]),we=bj,Te=yj,Ee=F.current.experiencedStreamingOrCooldown,De=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(De.current.messageId!==t&&(De.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Ee||!$r())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of V){if(n.observedPartIds.has(i.id))continue;if(!Co(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ki({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Ee,we,t,e,V]);let Oe=Z.useMemo(()=>V.length===0||!Ce&&V.every(e=>Te(e)),[V,Ce,Te]),ke=Z.useMemo(()=>B.filter(e=>e.type===`reasoning`),[B]),Ae=Z.useMemo(()=>ke.length===0||ke.every(e=>typeof e.time?.end==`number`),[ke]),je=typeof a!=`string`,Me=ke.length>0&&Se&&(Ce||je||!Oe),Ne=z||Se&&(Ce||je||!Oe),Pe=z||Me,Fe=Se||ke.length>0,Ie=H.length===0,Le=Fe&&Ie&&!Ne&&!Pe&&Oe&&Ae,Re=Z.useRef(!1),ze=Z.useRef(!1);Z.useEffect(()=>{ze.current=!1},[t]),Z.useEffect(()=>{if(!Le){Re.current=!1;return}Re.current||(Re.current=!0,b?.())},[Le,b]),Z.useEffect(()=>{if(z){ze.current=!1;return}if(Se){ze.current=!1;return}ke.length!==0&&(Pe||!Ae||ze.current||(ze.current=!0,_?.(`structural`)))},[z,Se,_,Ae,ke.length,Pe]);let Be=!!v&&!z,Ve=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ue||G)){de(!0);try{await re(e,t)}finally{de(!1)}}}),He=Z.useMemo(()=>{let e=C?.activityParts;return!_e||!e?[]:e},[_e,C?.activityParts]),Ue=Z.useMemo(()=>{let e=C?.activityGroupSegments;return!_e||!e?[]:e.filter(e=>e.anchorMessageId===t)},[_e,t,C?.activityGroupSegments]),We=Ue.length>0,Ge=Z.useMemo(()=>{let e=new Map,t=new Map;return He.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[He]),Ke=C?.toggleGroup,qe=C?.activityPresentationKind===`compaction`,Je=C?.isGroupExpanded===!0,Ye=_e&&qe&&!Je,Xe=_e?C?.activityOwnerMessageId===t||We:!C?.activityOwnerMessageId||C.activityOwnerMessageId===t||We,Ze=_e&&Xe&&(We||qe)&&!!Ke,Qe=_N(a,B),$e={finish:a,parts:B,streamPhase:xe,error:E,isLastAssistantInTurn:ve},et=SN($e),tt=Ko(e=>e.ttsInputMode),nt=Z.useMemo(()=>{if(!ve||qe||!be||!et)return``;let e=r??n,t=yN(e);return t<0?``:xD(e[t])},[ve,qe,be,et,r,n]),rt=tt===`final`?nt:U;zN({sessionId:e??``,messageId:t,created:s??0,text:rt,streaming:c&&k.active&&(j===`streaming`||j===`cooldown`),completed:c&&k.active&&i&&j!==`streaming`&&j!==`cooldown`&&!E});let it=_e&&CN($e),at=_e&&!et&&!(qe&&Je),ot=Be,st=ve&&be&&w?.variant!==`error`&&!Ye&&(v||!!E||i),ct=C?.diffStats?.hasDiffs===!0,lt=C?.isLatestTurn&&e&&k.active&&!te,ut=!te&&ve&&Qe&&be&&!Ye&&C?.diffStats?.hasDiffs===!0,dt=he&&ot&&!st&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(MI,{messageId:t,hasCopyableText:Be,isTouchContext:I,onCopyMessage:y,ttsText:rt,reviewTransferAction:le,sessionId:e}),[rt,Be,I,y,le,e,t]),pt=Z.useMemo(()=>e=>{if(!he||!_e)return null;let t=xD(e.part).trim();return t?(0,$.jsx)(MI,{hasCopyableText:!0,isTouchContext:I,onCopyMessage:async()=>(await Yn(t)).ok,ttsText:tt===`final`?``:t}):null},[_e,I,he,tt]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<B.length;t+=1){let n=B[t];!n||n.type!==`text`||at||Ge.get(n)?.kind!==`justification`&&(e=t)}return e},[Ge,at,dt,B]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Ze&&Ke&&C){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(qF,{parts:t,materializationParts:r,isExpanded:C.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:C.completionDisposition,activityPresentationKind:C.activityPresentationKind,durationMs:C.durationMs,startedAt:C.userMessageCreatedAt,onToggle:Ke,isMobile:c,expandedTools:d,onToggleTool:f,onShowPopup:p,onContentChange:_,streamPhase:xe,showHeader:!0,diffStats:C.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};Ue.length>0?Ue.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):qe&&e(`${t}:compaction-status`,[])}let r=0;for(;r<B.length;){let i=B[r];if(i.type===`text`){let a=Ge.get(i);if(at){r+=1;continue}if(Ye){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:N,"data-message-text-export-source":`true`,children:(0,$.jsx)(YM,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,allowSortedFinalStreaming:it,hasStreamingHapticLifecycle:Ee,onContentChange:_,onShowPopup:p})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:c?$F:QF,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:iI,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(Ge.get(i)?.kind===`reasoning`){r+=1;continue}if(!xD(i).trim()){r+=1;continue}x&&(me?n.push((0,$.jsx)(`div`,{className:sy(c),children:(0,$.jsx)(sN,{part:i,messageId:t,streamPhase:xe,onContentChange:_})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(YM,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,hasStreamingHapticLifecycle:Ee,onContentChange:_,onShowPopup:p},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(_e&&!Xe){r+=1;continue}if(Ge.get(i)?.kind===`tool`){r+=1;continue}if(_e&&vj(a)){let e=nF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(aF,{activities:i,isMobile:c,isTurnLive:xe!==`completed`,hasFollowingOtherType:eF(B,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return hj(n)?(0,$.jsx)(zF,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(kM,{part:e.part,messageId:t,isExpanded:d.has(e.part.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:_,onShowPopup:p,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(gj(a)){let e=oF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(dF,{activities:i,isMobile:c,children:i.map(e=>(0,$.jsx)(zF,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(fj(a)){n.push((0,$.jsx)(`div`,{className:sy(c),children:(0,$.jsx)(kM,{part:e,messageId:t,isExpanded:d.has(e.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:_,onShowPopup:p,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:sy(c),children:(0,$.jsx)(zF,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:c,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}let i=n.at(-1);if(Z.isValidElement(i)&&i.props[`data-message-text-export-source`]===`true`&&xe!==`completed`&&!be&&!w&&(!C||C.isLastAssistantInTurn)){let e=i;n[n.length-1]=Z.cloneElement(e,{className:Y(typeof e.props.className==`string`?e.props.className:void 0,c?`pb-1`:`pb-1.5`),"data-live-status-text-gap":``})}return n},[Ge,Ue,L,pe,me,0,d,Ye,qe,c,Xe,_e,mt,t,ft,pt,e,_,p,f,Ze,dt,xe,w,Ee,be,x,at,it,Ke,C,B]),_t=Z.useMemo(()=>{if(!ve||!be)return;let e=C?.durationMs;if(!(typeof e!=`number`||e<=0))return AI(e)},[ve,be,C?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=_P(e);return t.length>0?t:null},[o,s]),yt=Z.useMemo(()=>{if(!ge||!ve||w?.variant===`error`)return null;let e=C?.assistantTps;if(!LP({completionDisposition:C?.completionDisposition,tps:e}))return null;let t=RP(e??0);return t.length>0?t:null},[ge,w?.variant,ve,C?.assistantTps,C?.completionDisposition]),bt=(0,$.jsxs)($.Fragment,{children:[!te&&!c&&!ee&&ne?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":D(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=oe??(ie?ae(ie):null);e&&W(e,ne)},children:(0,$.jsx)(X,{weight:lI,name:`global`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:D(`chat.messageBody.actions.openPreview`)})]}):null,!te&&!se&&A.fork?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,className:eI,"aria-label":D(`chat.messageBody.actions.forkAria`),"aria-busy":ue,disabled:ue||!!G,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Ve(e)},children:(0,$.jsx)(X,{weight:lI,name:ue?`loader-4`:`git-branch`,className:Y(tI,ue&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:D(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:M,"data-message-text-export-root":`true`,...gO,className:Y(`relative w-full yuri-message-hover-scope`),style:XF,children:[(0,$.jsx)(fP,{containerRef:M}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,(S||C?.headerMessageId===t)&&(c?`[&>[data-message-text-export-source]:first-child]:pt-1.5`:`[&>[data-message-text-export-source]:first-child]:pt-2`)),children:[gt,w&&(0,$.jsx)(Dd,{children:(0,$.jsx)(`div`,{className:`my-1.5`,"data-assistant-error":w.variant,children:(0,$.jsx)(YF,{presentation:w,sessionId:e,messageId:t,directory:oe??void 0})})},`assistant-error`)]}),ut&&C?.diffStats?(0,$.jsx)(SI,{fileCount:C.diffStats.files,changedFiles:C.changedFiles,turnId:C.turnId,isLatestTurn:C.isLatestTurn,isMobile:c}):null,(0,$.jsx)(Ag,{files:n,messageID:t,sessionID:e,onShowPopup:p}),ht&&(0,$.jsx)(`div`,{className:Y(c?$F:QF),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:iI,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:R,"data-message-footer":`true`,style:ZF,children:[(0,$.jsxs)(`div`,{className:iI,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt||lt?(0,$.jsxs)(`div`,{className:aI,children:[yt||_t?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 whitespace-nowrap`,children:[yt?(0,$.jsx)(dI,{label:yt}):null,_t?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsxs)(`span`,{className:sI,children:[(0,$.jsx)(X,{weight:lI,name:`hourglass`,className:cI}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(Js,{children:_t})]}):null]}):null,lt&&e?(0,$.jsx)(zP,{sessionId:e}):null,vt?(0,$.jsx)(uI,{messageId:t,label:vt,focusReveal:c}):null]}):null,!te&&ve&&ye&&!ct?(0,$.jsx)(dN,{activityParts:C?.activityParts}):null]}),!st&&!Ye&&yt?(0,$.jsx)(`div`,{className:R,"data-message-footer":`true`,"data-message-tps":`interrupted`,style:ZF,children:(0,$.jsx)(`div`,{className:aI,children:(0,$.jsx)(dI,{label:yt})})}):null]})]})}),PI=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)(jI,{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)(NI,{...r}),t[26]=r,t[27]=i),i});function FI(e){return e.openContextPanelTab}function II(e){return e.setCurrentSession}function LI(e){return e.openContextPanelTab}function RI(e){return!e}function zI(e){return e.openContextPanelTab}var BI=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}},VI=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},HI={"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`},UI={icon:`pause-circle`,variant:`muted`};function WI(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`,UI.icon,UI.variant,!0):c(`chat.response.interrupted`,UI.icon,UI.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(HI,a)){if(a===`compaction.interrupted`)return c(HI[a],UI.icon,UI.variant,r===`Compaction was interrupted`);if(a===`compaction.unavailable`)return c(HI[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(HI[a],e)}return(!a||a===`unknown`||a===`error`)&&VI(r)?c(`chat.response.auth`,`lock`):{...c(`chat.response.failed`,`error-warning`),...!r&&i?{rawMessage:i}:{}}}function GI(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.nativeType===`synthetic`&&t.description===`Continuing after restart`}function KI(e,t){if(GI(e))return{text:t(`chat.response.continuingAfterRestart`),icon:`restart`,variant:`info`}}function qI(e){return!e}function JI(e){let t=(0,Q.c)(60),{part:n,isMobile:r}=e,i=r!==void 0&&r,{t:a}=Xn(),o;t[0]!==n.id||t[1]!==n.messageID||t[2]!==n.sessionID?(o=JSON.stringify([n.sessionID,n.messageID,n.id]),t[0]=n.id,t[1]=n.messageID,t[2]=n.sessionID,t[3]=o):o=t[3];let s=o,{expanded:c,toggle:l}=mO(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?WI(n.error,a):void 0,t[11]=m,t[12]=n.error,t[13]=a,t[14]=_):_=t[14];let v=_,y;t[15]!==m||t[16]!==n.summary?(y=m?``:n.summary?.trim()??``,t[15]=m,t[16]=n.summary,t[17]=y):y=t[17];let b=y,x,S,C,w,T,E,D,O,k;if(t[18]!==u||t[19]!==c||t[20]!==v?.text||t[21]!==m||t[22]!==i||t[23]!==p||t[24]!==n.status||t[25]!==b||t[26]!==g||t[27]!==f){let e=Y(`shrink-0 typography-meta`,m?`text-[var(--status-error)]/85`:`text-muted-foreground`);E=`w-full min-w-0`,D=``,O=n.status;let r=i?`min-h-7`:`min-h-8`;t[37]===r?k=t[38]:(k=Y(`flex w-full items-center gap-3`,r),t[37]=r,t[38]=k),x=`separator`,S=p?`polite`:void 0,C=v?.text??g,t[39]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 border-t`,"aria-hidden":`true`}),t[39]=w):w=t[39],T=b?(0,$.jsxs)(er,{variant:`ghost`,size:`sm`,className:Y(e,ly),"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)(Ju,{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 YI=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},XI=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=YI(t.mode)??YI(t.agent)??YI(r?.agent),o=YI(t.providerID)??YI(n?.providerID)??YI(i?.providerID),s=YI(t.modelID)??YI(n?.modelID)??YI(n?.id)??YI(i?.modelID)??YI(i?.id),c=YI(n?.variant)??YI(i?.variant)??YI(t.variant)??YI(r?.variant);return!a&&!o&&!s&&!c?null:{agentName:a,providerId:o,modelId:s,variant:c}},ZI=e=>{let t=e?.providerId?.trim(),n=e?.modelId?.trim();return!t||!n?null:{providerId:t,modelId:n}},QI=e=>ZI(e.assistantIdentity)??ZI(e.userIdentity)??(e.allowComposerFallback?ZI(e.composerSelection):null)??ZI(e.sessionSelection),$I=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}},eL=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),tL=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,nL=e=>!e,rL=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},iL=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),aL=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,oL=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,sL=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},cL=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},lL=e=>!e||sL(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`)}),uL=e=>sL(e)===`user`?lL(e)||e.parts.some(e=>{let t=e.shellAction;return e.type===`text`&&typeof t==`object`&&!!t}):!1,dL=(e,t)=>{if(sL(e)!==`assistant`||t&&cL(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}}},fL=(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(sL(t)===`user`)break;let{hide:i,details:a}=dL(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},pL=Ku(()=>Pn(()=>import(`./ToolOutputDialog-O25CmHgA.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]))),mL=4e3,hL=new Map,gL=new Map,_L=new Set([`bash`,`shell`,`cmd`,`terminal`]),vL=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},yL=e=>{let t=hL.get(e);return t?new Set(t):new Set},bL=(e,t)=>{if(hL.size>=mL&&!hL.has(e)){let e=hL.keys().next().value;typeof e==`string`&&hL.delete(e)}hL.set(e,new Set(t))},xL=e=>{let t=gL.get(e);return t?new Set(t):new Set},SL=(e,t)=>{if(gL.size>=mL&&!gL.has(e)){let e=gL.keys().next().value;typeof e==`string`&&gL.delete(e)}gL.set(e,new Set(t))},CL=200,wL=new Map,TL=e=>wL.get(e),EL=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=wL.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(wL.size>=CL&&!wL.has(e)){let e=wL.keys().next().value;typeof e==`string`&&wL.delete(e)}wL.set(e,t)}};function DL(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 OL=(e,t)=>{if(typeof e==`object`&&e)return e[t]},kL=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s=!1,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=Xn(),{isMobile:m,isTablet:h,hasTouchInput:g}=Kc(),_=Ab(),v=jb(_),y=m||h,b=Z.useRef(null),x=Z.useRef(null),S=J(t=>{b.current=t,x.current?.(),x.current=null,t&&m&&(x.current=NP(t,e.info.id))});Z.useEffect(()=>{let t=b.current;return x.current?.(),x.current=null,t&&m&&(x.current=NP(t,e.info.id)),()=>{x.current?.(),x.current=null}},[m,e.info.id]);let C=wa(e=>e.currentSessionId),w=wa(e=>e.revertToMessage),T=wa(e=>e.editMessagePreservingChanges),E=wa(e=>e.forkFromMessage),D=wa(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=wa(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=wa(e=>e.clearStagedMessageEdit);Ze(`ui.chat_message.render`),c&&Ze(`ui.chat_message.render.streaming`);let A=Ko(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=K(H(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{C&&_O.getInstance().recordSessionStart(C)},[C]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[U,W]=Z.useState(()=>yL(e.info.id)),[ee,te]=Z.useState(()=>xL(e.info.id)),[ne,re]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{W(yL(e.info.id)),te(xL(e.info.id))},[e.info.id]);let G=Z.useMemo(()=>BI(e.info),[e.info]).isUser,ie=Z.useMemo(()=>Pe(e.parts),[e.parts]),ae=G&&(m||!M),oe=G&&!m&&M&&!ae,se=e.info.sessionID,{currentContextAgent:ce,savedSessionAgentSelection:le}=wy(H(e=>({currentContextAgent:c&&se?e.currentAgentContext.get(se):void 0,savedSessionAgentSelection:c&&se?e.sessionAgentSelections.get(se):void 0}))),ue=Z.useMemo(()=>bD(e.sourceParts??e.parts),[e.parts,e.sourceParts]),de=Z.useMemo(()=>G?PD(ue):bD(e.parts),[G,e.parts,ue]),fe=Z.useMemo(()=>{if(G||!t)return null;let e=OL(t.info,`clientRole`),n=OL(t.info,`role`);return(typeof e==`string`?e:typeof n==`string`?n:void 0)===`user`&&XI(t.info)||null},[G,t]),pe=Z.useMemo(()=>{if(G)return;let t=OL(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=OL(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(fe?.agentName)return fe.agentName;if(se)return ce||(le??void 0)},[G,e.info,fe,se,ce,le]),me=G?null:XI(e.info),he=me?.providerId??null,ge=me?.modelId??null,_e=ur(H(e=>{if(G||!se)return null;if(fe?.providerId&&fe?.modelId)return{providerId:fe.providerId,modelId:fe.modelId};if(pe){let t=e.getAgentModelForSession(se,pe);if(t?.providerId&&t?.modelId)return t}let t=e.getSessionModelSelection(se);return t?.providerId&&t?.modelId?t:null})),ve=Z.useMemo(()=>G?null:typeof he==`string`&&he.trim().length>0?he:_e?.providerId??null,[G,he,_e]),ye=Z.useMemo(()=>G?null:typeof ge==`string`&&ge.trim().length>0?ge:_e?.modelId??null,[G,ge,_e]),be=e.info.id?TL(e.info.id):void 0;G||EL(e.info.id,{agent:pe,provider:ve??void 0,model:ye??void 0});let xe=pe??be?.agent,Se=ve??be?.provider??null,Ce=ye??be?.model??null,we=Z.useMemo(()=>{if(G)return;let e=Se&&A.length>0?A.find(e=>e.id===Se):void 0;return ki(e,Ce)||void 0},[G,Se,Ce,A]),Te=Z.useMemo(()=>{if(G||!ve||!ye)return!1;let e=A.find(e=>e.id===ve);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===ye)?.variants;return!!(t&&Object.keys(t).length>0)},[G,ye,ve,A]),Ee=DL(xe),De=DL(Se??void 0),Oe=DL(Ce??void 0),ke=DL(we),Ae=Ee??void 0,je=De??null,Me=Oe??null,Ne=ke??void 0,Fe=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ie=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Le=Z.useMemo(()=>G?!0:!!(Fe&&Fe>0),[G,Fe]),Re=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),ze=Z.useMemo(()=>wD(de,{includeReasoning:j}),[de,j]),Be=Z.useMemo(()=>G?ze:!Le&&N===`sorted`?[]:ze,[N,Le,G,ze]),Ve=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`text`),[G,ze]),He=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`tool`),[G,ze]),Ue=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of He){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=vL(t.tool);!r||!_L.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=vL(t.part.tool);!n||!_L.has(n)||e.add(t.id)}return e},[P,He,a?.activityParts]),We=Z.useMemo(()=>{if(Ue.size===0&&ee.size===0)return U;let e=new Set(U);return Ue.forEach(t=>{ee.has(t)||e.add(t)}),ee.forEach(t=>{e.delete(t)}),e},[ee,Ue,U]),Ge=Z.useMemo(()=>{if(!G)return;let e=de.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[G,de]),Ke=G&&!FD(Be),qe=typeof Re!=`string`,Je=Z.useMemo(()=>G?!1:Ve.length===0||He.length===0?qe:!0,[Ve.length,He.length,qe,G]),Ye=Z.useMemo(()=>!G&&_O.getInstance().shouldAnimateMessage(e.info,C||e.info.sessionID),[e.info,C,G]),[Xe,Qe]=Z.useState(!1),$e=Z.useMemo(()=>n?BI(n.info):null,[n]),et=!!a,tt=a?.isLastAssistantInTurn??!1,nt=aL({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),rt=Z.useMemo(()=>G?!1:et?!tt:$e?!$e.isUser&&$e.role===`assistant`:!1,[et,tt,G,$e]),it=Z.useMemo(()=>Le?`completed`:c?l??`streaming`:`completed`,[l,c,Le]);Z.useEffect(()=>{!G||!u||d?.(e.info.id)},[u,G,e.info.id,d]),Z.useEffect(()=>{Qe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;G||!t||t!==e.info.id||(it===`streaming`||it===`cooldown`)&&Qe(!0)},[o,G,e.info.id,it,a?.headerMessageId]);let at=Z.useMemo(()=>{if(G)return!0;if(s)return!1;let t=o??a?.headerMessageId;return t?e.info.id===t?it===`completed`||Xe||it===`streaming`||it===`cooldown`:!1:!0},[o,Xe,G,a,it,e.info.id,s]),ot=Z.useCallback(e=>{Yn(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),st=G?void 0:a?.userMessageVariant??fe?.variant,ct=!G&&Te&&typeof st==`string`&&st.trim().length>0?st:void 0,lt=Z.useMemo(()=>{if(!G&&!qI(et?tt:!rt))return WI(e.info?.error,p)},[et,rt,tt,G,e.info,p]),ut=lt?.text,dt=Z.useMemo(()=>{if(G){let e=Be.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6592
|
+
`).trim()||nP(t)},fP=({containerRef:e})=>{let{t}=Xn(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),o=Z.useRef(!1),[s,c]=Z.useState(!1),l=Z.useRef(null),u=Z.useRef(XN),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=bd()??null,b=K(e=>e.isMobile),x=Ab(),S=jb(x).textSelectionMutation,C=x.kind===`primary`&&!!v;Z.useEffect(()=>{m.current=n.show},[n.show]),Z.useEffect(()=>()=>{f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]);let w=Z.useCallback(()=>{d.current=null,$N===w&&($N=null),m.current&&=(f.current!==null&&(window.cancelAnimationFrame(f.current),f.current=null),c(!1),r(e=>({...e,show:!1})),a(``),!1)},[]);Z.useEffect(()=>()=>{$N===w&&($N=null)},[w]);let T=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=u.current/2,r=GN+n,i=t-GN-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),E=Z.useCallback(()=>{if(!d.current)return;$N!==w&&($N?.(),$N=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=nP(t.toString());if(!r){o.current||w();return}let i=aP(t,n);if(!i){o.current||w();return}let a=i.getBoundingClientRect();d.current={plainText:r,markdownText:dP(i,r),rect:a},o.current||E()},[e,w,E]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{o.current=!0,w()},r=()=>{o.current=!1,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{p.current=null,D()},10)},i=new Set,a=()=>{for(let e of iP(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=hw(bw),t=0,r=0,i=()=>{let e=QN(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=Jg(v,t);n&&(o_.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};dw.getState().addQuote(t,e),O(),Pw(t)});if(Z.useEffect(()=>{if(!S)return;let t=t=>{let n=Tc(t,KN),r=C&&Tc(t,qN);if(!n&&!r)return;let i=window.getSelection(),a=e.current;if(!i||!a||!i.toString().trim())return;let o=aP(i,a);if(!o)return;t.preventDefault(),t.stopPropagation();let s=dP(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:KN,run:()=>k(i)},...C?[{id:`side`,label:t(`chat.textSelection.actions.addToSideChat`),shortcut:qN,run:()=>A(i)}]:[]];if(b){let e=g??{left:0,top:Math.max(0,window.innerHeight-88),width:window.innerWidth,height:88};return(0,Dp.createPortal)((0,$.jsx)(`div`,{ref:l,"data-text-selection-menu":!0,className:Y(`fixed z-50 flex items-center justify-center gap-2 bg-background px-4`,`transition-opacity duration-200 ease-out`,s?`opacity-0`:`opacity-100`),style:{left:e.left,top:e.top,width:e.width,height:e.height,paddingBottom:`max(0.75rem, var(--yuri-safe-area-bottom-visual, env(safe-area-inset-bottom, 0px)))`},onPointerDown:e=>{e.preventDefault()},children:j.map(e=>(0,$.jsx)(er,{type:`button`,variant:`secondary`,size:`sm`,onClick:e.run,className:`max-w-[11rem] min-w-0`,children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})},e.id))}),document.body)}return(0,Dp.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:YN(e.shortcut)})]})]},e.id))})}),document.body)},pP=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),mP=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),pP(e,n)},hP=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),gP=e=>String(e).padStart(2,`0`),_P=e=>{if(!hP(e))return``;let t=new Date(e);return`${t.getFullYear()}-${gP(t.getMonth()+1)}-${gP(t.getDate())} ${gP(t.getHours())}:${gP(t.getMinutes())}`},vP=(e,t)=>{if(!hP(e))return``;let n=new Date(e),r=new Date,i=cc(n,t),a=$n(),o=rr.getState().dictionary;if(pP(n,r))return i;if(mP(n,r))return ir(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},yP=144,bP=null,xP=new Set,SP=!1,CP=null;function wP(){for(let e of xP)e()}function TP(){return bP}function EP(){return CP}function DP(e){return xP.add(e),()=>{xP.delete(e)}}function OP(e,t){let n=Z.useSyncExternalStore(DP,TP,EP);return t&&n===e}function kP(e){!e||bP===e||(bP=e,wP())}function AP(e){bP!==null&&(e&&bP!==e||(bP=null,wP()))}function jP(e){return e instanceof Element?e.closest(`[data-message-id]`)?.getAttribute(`data-message-id`)??null:null}function MP(){SP||typeof document>`u`||(SP=!0,document.addEventListener(`pointerdown`,e=>{bP&&jP(e.target)!==bP&&AP()},!0))}function NP(e,t){MP();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>yP||kP(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),AP(t)}}var PP=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,FP=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+=PP(e.outputTokens)+PP(e.reasoningTokens),!r||t<=0||n<=0)return null;let i=t/(n/1e3);return Number.isFinite(i)&&i>0?i:null})},IP=e=>{let t=FP(e);return t[t.length-1]??null},LP=e=>e.completionDisposition!==`active`&&typeof e.tps==`number`&&Number.isFinite(e.tps)&&e.tps>0,RP=e=>!Number.isFinite(e)||e<=0?``:`${e.toFixed(1)} tok/s`,zP=Z.memo(e=>{let t=(0,Q.c)(5),{sessionId:n}=e,{t:r}=Xn(),i=Zi(n);if(i===0)return null;let a;t[0]!==i||t[1]!==r?(a=r(`chat.sessionBackground.tasksRunning`,{count:i}),t[0]=i,t[1]=r,t[2]=a):a=t[2];let o;return t[3]===a?o=t[4]:(o=(0,$.jsx)(`span`,{className:`inline-flex h-3.5 shrink-0 items-center whitespace-nowrap text-[11px] leading-none font-normal text-muted-foreground`,"data-background-activity":`true`,children:(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:a})}),t[3]=a,t[4]=o),o});zP.displayName=`BackgroundActivityHint`;var BP=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},VP=[`search`,`read`,`list`];function HP(e){let t=xj(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function UP(e){let t={read:0,search:0,list:0};for(let n of e){let e=HP(n);e&&(t[e]+=1)}return t}var WP=[`edit`,`command`,`other`],GP=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),KP=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function qP(e){if(!_j(e))return null;let t=xj(e);return GP.has(t)?`edit`:KP.has(t)?`command`:`other`}function JP(e){let t={edit:0,command:0,other:0};for(let n of e){let e=qP(n);e&&(t[e]+=1)}return t}function YP(e){return WA(e)}var XP=[...VP,...WP];function ZP(e){return{...UP(e),...JP(e)}}function QP(e){return bj(e)}function $P(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!vj(e.toolName):e.kind!=null||e.type!=null}function eF(e,t,n){for(let r=t;r<e.length;r+=1)if($P(n(e[r])))return!0;return!1}function tF(e){return`parts`in e?e.parts.some(e=>QP(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>QP(e))}function nF(e,t,n){let r=[],i=t;for(;i<e.length&&vj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var rF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,iF=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`,rF),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},aF=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=Xn(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??tF({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=ZP(u.map(e=>e.tool)),p=YP(u),m=XP.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:sy(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`,uy),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)(rj,{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,rF,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,rF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(BP,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(iF,{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:cy(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 oF(e,t,n){let r=[],i=t;for(;i<e.length&&gj(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var sF=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function cF(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=sF(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=sF(e.name);if(t)return t;let r=sF(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=sF(n.output.name);if(e)return e}return null}function lF(e){let t=[];for(let n of e){if(typeof n!=`string`)continue;let e=n.trim();e&&t.push(e)}let n=t.slice(0,3);return{visibleNames:n,hiddenCount:Math.max(0,t.length-n.length),joinedVisible:n.join(`, `)}}var uF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,dF=({activities:e,isMobile:t,children:n})=>{let{t:r}=Xn(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>bj(e)),{joinedVisible:l,hiddenCount:u}=lF(s.map(cF)),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:sy(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`,uy),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)(rj,{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`,uF,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`,uF),style:{color:`var(--tools-description)`},children:(0,$.jsx)(BP,{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:cy(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]})},fF=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=K(pF),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)(YM,{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 pF(e){return e.chatRenderMode}var mF=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},hF=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,gF=Y(`typography-meta font-medium`,hF),_F=Y(`typography-meta`,hF),vF=[],yF=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},bF=e=>{let t=new Set;for(let n of e)yF(n)&&n.messageId&&t.add(n.messageId);return[...t]},xF=(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}),SF=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=pd(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},CF=e=>e,wF=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},TF=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},EF=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},DF=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},OF=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=DF(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`}`},kF=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=OF(n.todos);if(e)return e}if(Array.isArray(r)){let e=OF(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=OF(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=OF(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=OF(e.todos);if(t)return t}}catch{}return null},AF=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)},jF=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(RO,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,_F),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`,_F),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)(RO,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},MF=e=>{let t=kn(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},NF=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 cF(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`?kF(e):wF(e)},PF=e=>{let t=new Set,n=new Set;for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(!XO(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=ik(e)||i;n.add(s),(o.status===`pending`||o.status===`running`)&&t.add(s)}return{active:[...t],all:[...n]}},FF=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=sy(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)(kM,{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&&eA([e.activity.part],[t.activity.part])),IF=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=sy(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(zF,{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&&RF(e.activities,t.activities)),LF=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!xD(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(vj(i)){let r=nF(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:eF(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(gj(i)){let r=oF(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(pj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(fj(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(mj(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},RF=(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||!eA([r.part],[i.part]))return!1}return!0},zF=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=Xn(),s=K(UF),c=vd(n,o),l;t[0]===n?l=t[1]:(l=zO(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(En),m=Ll(),h=le(WF),g=Ab(),_=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=$i(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(GF)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||bj(E.part),O;t[12]===E?O=t[13]:(O=E?NF(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||EF(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=MF(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=TF(E);if(!e){M=null;break bb1}let n=jn(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=AF(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=Mn(_,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(!An(n,_)){wO(n,_).then(()=>{let e=K.getState(),r=_||Nn(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=K.getState(),i=Nn(_,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=kn(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=K.getState(),n=_||Nn(``,t);e.openContextFile(n,t)};if(_&&!An(t,_)){wO(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let te=J(ee),ne;t[48]===te?ne=t[49]:(ne=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),te())},t[48]=te,t[49]=ne);let re=J(ne),G=U&&W&&`cursor-pointer`,ie=U&&!W&&`cursor-default opacity-70`,ae;t[50]!==G||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,uy,G,ie),t[50]=G,t[51]=ie,t[52]=ae):ae=t[52];let oe=U?`soft`:void 0,se=U?te:void 0,ce=U?re:void 0,ue=U?`button`:void 0,de=U&&W?0:void 0,fe=U&&!W?!0:void 0,pe=i?`size-4`:`size-3.5`,me;t[53]===pe?me=t[54]:(me=Y(`inline-flex items-center justify-center flex-shrink-0`,pe),t[53]=pe,t[54]=me);let he;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(he={color:`var(--tools-icon)`},t[55]=he):he=t[55];let ge=D?(0,$.jsx)(rj,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,_e;t[56]!==me||t[57]!==he||t[58]!==ge?(_e=(0,$.jsx)(`div`,{className:me,style:he,children:ge}),t[56]=me,t[57]=he,t[58]=ge,t[59]=_e):_e=t[59];let ve,ye;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ve=Y(gF,`inline-flex items-center flex-shrink-0 opacity-85`),ye={color:`var(--tools-title)`},t[60]=ve,t[61]=ye):(ve=t[60],ye=t[61]);let be;t[62]===c?be=t[63]:(be=(0,$.jsx)(`span`,{className:ve,style:ye,title:c,children:c}),t[62]=c,t[63]=be);let xe;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(xe=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`,_F),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(ig,{filePath:N.path,className:`h-3.5 w-3.5`}):null,jF(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=xe):xe=t[68];let Se;t[69]!==a||t[70]!==k||t[71]!==B?(Se=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(RO,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,_F),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=Se):Se=t[72];let Ce;t[73]!==k||t[74]!==V?(Ce=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:KF,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`,_F),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(SF,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=Ce):Ce=t[75];let we;t[76]!==H||t[77]!==j?(we=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,_F),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=we):we=t[78];let Te;t[79]!==k||t[80]!==H||t[81]!==j?(Te=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,_F),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=Te):Te=t[82];let Ee;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Ee=!f&&!B&&!V&&!H&&k?(0,$.jsx)(RO,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,_F),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]=Ee):Ee=t[89];let De;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==ue||t[95]!==de||t[96]!==fe||t[97]!==_e||t[98]!==be||t[99]!==xe||t[100]!==Se||t[101]!==Ce||t[102]!==we||t[103]!==Te||t[104]!==Ee?(De=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:ue,tabIndex:de,"aria-disabled":fe,children:[_e,be,xe,Se,Ce,we,Te,Ee]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=ue,t[95]=de,t[96]=fe,t[97]=_e,t[98]=be,t[99]=xe,t[100]=Se,t[101]=Ce,t[102]=we,t[103]=Te,t[104]=Ee,t[105]=De):De=t[105],De},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&RF(e.activities,t.activities)),BF=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)(sN,{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}),VF=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)(fF,{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}),HF=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=Xn(),_=bd()??``,v=Z.useMemo(()=>bF(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?mF(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 WA(t)},[e]),N=M.added>0||M.removed>0,P=Z.useMemo(()=>PF(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=Ne(_,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=me(_,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 Ne(_,n,e).status}),te=ee.includes(`loading`),ne=ee.includes(`error`),re=ee.length>0&&ee.every(e=>e===`ready`),G=t.some(e=>W.has(e.messageId)&&yF(e)),ie=re&&!G&&!xF(t,W),ae=Z.useMemo(()=>U?CF(e):vF,[e,U]),oe=Z.useMemo(()=>U?LF(ae.filter(e=>e.kind!==`reasoning`||xD(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:sy(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)(BF,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ue(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(VF,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(FF,{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)(IF,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(aF,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return hj(n)?(0,$.jsx)(zF,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(kM,{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)(dF,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(zF,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(FF,{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?sy(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&&uy,z&&`yuri-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":z?void 0:`soft`,onClick:z?void 0:V,"aria-expanded":B,"aria-disabled":z||void 0,"aria-label":z?j:g(B?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex min-w-0 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:k?(0,$.jsxs)(`span`,{className:Y(`typography-meta inline-flex shrink-0 items-center gap-1.5 tabular-nums text-muted-foreground`,c?`h-5`:`h-6`),children:[E?g(`chat.activity.completed`,{duration:E}):j,(0,$.jsx)(X,{name:B?`arrow-down-s`:`arrow-right-s`,className:`size-3.5 shrink-0 opacity-0 group-hover/tool:opacity-70 group-focus-visible/tool:opacity-70`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(rj,{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)(ds,{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)(iF,{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||ne||ie)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,z?void 0:`ml-5`,ne&&`text-[var(--status-error)]`),role:ne?`alert`:`status`,children:te?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):ne?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,onClick:R,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]})});function UF(e){return e.showToolFileIcons}function WF(e){return e.currentDirectory}function GF(e){return[e.name,e]}function KF(e){e.stopPropagation()}var qF=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(HF,{...e}),t[0]=e,t[1]=n),n});function JF(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=qi(a,o),c;t[1]===r?c=t[2]:(c=e=>!!e.session_execution_recovery[r],t[1]=r,t[2]=c);let l=z(s,c),u;t[3]===r?u=t[4]:(u=e=>e.session_status[r]?.type===`retry`,t[3]=r,t[4]=u);let d=z(s,u),f=Ca(r,a);if(!l&&!d){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Uv,{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)(Uv,{presentation:n}),t[7]=n,t[8]=m),m}function YF(e){let t=(0,Q.c)(5),n=Ab();if(!e.sessionId||!n.active||!n.capabilities.compose){let n;return t[0]===e.presentation?n=t[1]:(n=(0,$.jsx)(Uv,{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)(JF,{...e,sessionId:e.sessionId,directory:r}),t[2]=e,t[3]=r,t[4]=i):i=t[4],i}var XF={contain:`layout`},ZF={containerType:`inline-size`,containerName:`message-footer`},QF=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,$F=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,eI=`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`,tI=`size-3.5!`,nI=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,rI=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,iI=`flex items-center gap-2`,aI=`flex w-max max-w-full flex-none flex-wrap items-center gap-2 text-muted-foreground`,oI=`h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,sI=`inline-flex ${oI}`,cI=`size-3.5!`,lI=`medium`,uI=e=>{let t=(0,Q.c)(6),{messageId:n,label:r,focusReveal:i}=e,a=OP(n,i),o=i?a?`inline-flex`:`hidden`:`hidden yuri-message-hover-time`,s;t[0]===o?s=t[1]:(s=Y(oI,`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},dI=e=>{let t=(0,Q.c)(16),{label:n}=e,{t:r}=Xn(),i;t[0]!==n||t[1]!==r?(i=r(`chat.messageBody.meta.tpsAria`,{rate:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{weight:lI,name:`pulse`,className:cI}),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)(qs,{asChild:!0,children:(0,$.jsxs)(`span`,{className:sI,"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)(Js,{children:c}),t[11]=c,t[12]=l);let u;return t[13]!==s||t[14]!==l?(u=(0,$.jsxs)(Ys,{children:[s,l]}),t[13]=s,t[14]=l,t[15]=u):u=t[15],u},fI=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,pI=`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)]`,mI=`h-7 gap-1.5`,hI=`h-6 gap-1`,gI=`text-[11px] leading-none`,_I=`size-3.5`,vI=`size-3`,yI=5,bI=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)(ig,{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=fI(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}),xI=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=Xn(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?hI:mI,d;t[3]===u?d=t[4]:(d=Y(pI,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)(bI,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),SI=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=Xn(),c=bd(),l=Ab(),u=l.directory||c,d=l.sessionId,f=Ll(),p=K(FI),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,yI),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(pI,o?hI:mI),E=o?vI:_I,D;t[10]===o?D=t[11]:(D=o?Y(gI,`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(gI,`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(gI,`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){uN({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&uN({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&&uN({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let te;t[46]!==S||t[47]!==A?(te=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=te):te=t[48];let ne;t[49]===E?ne=t[50]:(ne=Y(E,`opacity-60`),t[49]=E,t[50]=ne);let re;return t[51]===ne?re=t[52]:(re=(0,$.jsx)(X,{name:`arrow-right-s`,className:ne}),t[51]=ne,t[52]=re),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,te,re]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(xI,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),CI=e=>e.type===`subtask`,wI=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},TI=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}`},EI=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=bd(),{isMobile:o}=Kc(),s=wa(II),c=K(LI),l=Ab(),{t:u}=Xn(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,m;t[2]===n.command?m=t[3]:(m=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=m);let h=m,g;t[4]===n.agent?g=t[5]:(g=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=g);let _=g,v;t[6]===n.prompt?v=t[7]:(v=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=v);let y=v,b;t[8]===n.taskSessionID?b=t[9]:(b=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=b);let x=b,S;t[10]===n.model?S=t[11]:(S=TI(n.model),t[10]=n.model,t[11]=S);let C=S,w=!!y&&!(o&&l.kind===`primary`),T;t[12]===u?T=t[13]:(T=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=T);let E;t[14]===T?E=t[15]:(E=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:T}),t[14]=T,t[15]=E);let D;t[16]===h?D=t[17]:(D=h?(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:[`/`,h]}):null,t[16]=h,t[17]=D);let O;t[18]===_?O=t[19]:(O=_?(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:[`@`,_]}):null,t[18]=_,t[19]=O);let k;t[20]===C?k=t[21]:(k=C?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:C}):null,t[20]=C,t[21]=k);let A;t[22]!==O||t[23]!==k||t[24]!==E||t[25]!==D?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E,D,O,k]}),t[22]=O,t[23]=k,t[24]=E,t[25]=D,t[26]=A):A=t[26];let j;t[27]===f?j=t[28]:(j=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=j);let M;t[29]!==r||t[30]!==y||t[31]!==w||t[32]!==u?(M=w?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(RI),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:y}):null]}):null,t[29]=r,t[30]=y,t[31]=w,t[32]=u,t[33]=M):M=t[33];let N;t[34]!==_||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==x?(N=x&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&Mb(l,x,e,()=>{if(!Ga({sessionId:x,directory:e})){if(cl()||o||p()){s(x,e);return}c(e,{mode:`chat`,dedupeKey:`session:${x}`,label:f||_||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=_,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=x,t[43]=N):N=t[43];let P;return t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==N?(P=(0,$.jsxs)(`div`,{className:`mt-2`,children:[A,j,M,N]}),t[44]=A,t[45]=j,t[46]=M,t[47]=N,t[48]=P):P=t[48],P},DI=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=bd(),i=K(zI),{isMobile:a}=Kc(),{t:o}=Xn(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!p(),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,m=J(()=>{!c||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:f,readOnly:!0})}),h;t[6]===m?h=t[7]:(h=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())},t[6]=m,t[7]=h);let g=J(h),_=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,v;t[8]===_?v=t[9]:(v=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`,_),t[8]=_,t[9]=v);let y=c?`button`:void 0,b=c?0:void 0,x=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,S=c?m:void 0,C=c?g:void 0,w;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=w):w=t[10];let T;t[11]===f?T=t[12]:(T=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=T);let E=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,D;t[13]===E?D=t[14]:(D=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,E),t[13]=E,t[14]=D);let O;t[15]!==u||t[16]!==D?(O=(0,$.jsx)(`span`,{className:D,children:u}),t[15]=u,t[16]=D,t[17]=O):O=t[17];let k;t[18]!==T||t[19]!==O?(k=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[T,O]}),t[18]=T,t[19]=O,t[20]=k):k=t[20];let A;t[21]===n.body?A=t[22]:(A=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-clip text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Gu,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=A);let j;t[23]!==k||t[24]!==A?(j=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[k,A]}),t[23]=k,t[24]=A,t[25]=j):j=t[25];let M;return t[26]!==C||t[27]!==j||t[28]!==v||t[29]!==y||t[30]!==b||t[31]!==x||t[32]!==S?(M=(0,$.jsxs)(`div`,{className:v,role:y,tabIndex:b,"aria-label":x,onClick:S,onKeyDown:C,children:[w,j]}),t[26]=C,t[27]=j,t[28]=v,t[29]=y,t[30]=b,t[31]=x,t[32]=S,t[33]=M):M=t[33],M},OI={background:`transparent`,backgroundColor:`transparent`},kI=e=>{let t=(0,Q.c)(37),{part:n}=e,[r,i]=Z.useState(!1),a=Z.useRef(null),{t:o}=Xn(),s;t[0]===n.shellAction?s=t[1]:(s=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=s);let c=s,l=typeof n.shellAction?.output==`string`?n.shellAction.output:``,u;t[2]===n.shellAction?u=t[3]:(u=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=u);let d=u,f=l.length>0,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{a.current!==null&&typeof window<`u`&&(window.clearTimeout(a.current),a.current=null)},t[4]=p):p=t[4];let m=J(p),h,g;t[5]===m?(h=t[6],g=t[7]):(h=()=>()=>{m()},g=[m],t[5]=m,t[6]=h,t[7]=g),Z.useEffect(h,g);let _;t[8]!==m||t[9]!==f||t[10]!==l?(_=async()=>{f&&(await Yn(l)).ok&&(m(),i(!0),typeof window<`u`&&(a.current=window.setTimeout(()=>{i(!1),a.current=null},2e3)))},t[8]=m,t[9]=f,t[10]=l,t[11]=_):_=t[11];let v=J(_),y;t[12]===o?y=t[13]:(y=o(`chat.messageBody.shellCommand.title`),t[12]=o,t[13]=y);let b;t[14]===y?b=t[15]:(b=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:y}),t[14]=y,t[15]=b);let x;t[16]!==d||t[17]!==o?(x=d&&d!==`completed`?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,d===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),role:d===`error`?`alert`:`status`,children:d===`running`?o(`chat.assistantStatus.runningCommand`):d===`pending`?o(`chat.statusRow.todo.status.pending`):d===`error`?o(`chat.toolPart.error`):d}):null,t[16]=d,t[17]=o,t[18]=x):x=t[18];let S;t[19]!==r||t[20]!==v||t[21]!==f||t[22]!==o?(S=f?(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`xs`,className:`ml-auto text-muted-foreground`,onClick:()=>{v()},"aria-label":o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:o(r?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:(0,$.jsx)(X,{name:r?`check`:`file-copy`,className:`h-3.5 w-3.5`})}):null,t[19]=r,t[20]=v,t[21]=f,t[22]=o,t[23]=S):S=t[23];let C;t[24]!==S||t[25]!==b||t[26]!==x?(C=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[b,x,S]}),t[24]=S,t[25]=b,t[26]=x,t[27]=C):C=t[27];let w;t[28]===c?w=t[29]:(w=c?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Ud,{language:`bash`,code:c,codeStyle:OI,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},AI=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(` `)},jI=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=Xn(),w=mx(),T=jb(Ab()),E=K(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!CD(e):!!(CI(e)||wI(e))),[n]),j=Z.useMemo(()=>A.map(e=>ro(e)?fk(xD(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=vP(i,E);return e.length>0?e:null},[S,i,E]),te=Y(`yuri-user-actions-hover-scope`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),ne=!_&&v&&z?(0,$.jsx)(`div`,{className:te,...gO,children:(0,$.jsxs)(`div`,{className:Y(iI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(sI,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:lI,name:`edit`,className:cI}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:lI,name:`close`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,re=(_&&z?(0,$.jsx)(`div`,{className:te,...gO,children:(0,$.jsx)(`div`,{className:Y(iI,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(sI,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??ne??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:te,...gO,children:(0,$.jsxs)(`div`,{className:Y(iI,`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)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(sI,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:lI,name:`time`,className:cI}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(Js,{children:ee})]}):null,m&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:lI,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(tI,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:lI,name:`edit`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:lI,name:g===`fork`?`loader-4`:`git-branch`,className:Y(tI,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:eI,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:lI,name:`check`,className:Y(tI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:lI,name:`file-copy`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full yuri-message-hover-scope`,...gO,"data-user-message-body":`true`,style:XF,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(CI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(EI,{part:e})},e.id??`user-subtask-${i}`);if(wI(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(kI,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(DI,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&xD(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(NO,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Ag,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),re]}):(0,$.jsx)($.Fragment,{children:re})}),MI=Z.memo(({messageId:e,hasCopyableText:t,isTouchContext:n,onCopyMessage:r,reviewTransferAction:i,ttsText:a,sessionId:o})=>{let{t:s}=Xn(),c=mx(),l=Ab(),u=jb(l),{isPlaying:d,play:f,stop:p}=IN(),m=Z.useContext(RN),h=!!(m&&m.sessionId===o&&m.messageId===e),g=d||h,_=Ko(e=>e.showMessageTTSButtons),v=Ko(e=>e.voiceProvider),[y,b]=Z.useState(!1),[x,S]=Z.useState(!1),[C,w]=Z.useState(!1),T=Z.useRef(null),E=Z.useRef(null),D=!!r,O=!!((l.sessionId||o)&&l.directory&&u.openSourceSession&&c!==`mini-chat`),k=J(()=>{T.current!==null&&typeof window<`u`&&(window.clearTimeout(T.current),T.current=null)}),A=J(()=>{E.current!==null&&typeof window<`u`&&(window.clearTimeout(E.current),E.current=null)});Z.useEffect(()=>()=>{k(),A()},[A,k]),Z.useEffect(()=>{(!t||!D)&&(b(!1),S(!1),k(),A())},[D,A,k,t]);let j=J(()=>{!n||!D||!t||typeof window>`u`||(k(),b(!0),T.current=window.setTimeout(()=>{b(!1),T.current=null},1800))}),M=J(async e=>{!r||!t||(e.stopPropagation(),e.preventDefault(),await r()!==!1&&(A(),S(!0),typeof window<`u`&&(E.current=window.setTimeout(()=>{S(!1),E.current=null},2e3)),n&&j()))}),N=J(async e=>{if(e.stopPropagation(),e.preventDefault(),!(!i||C||!t)){w(!0);try{await i.onClick()}finally{w(!1)}}}),P=J(e=>{e.stopPropagation(),e.preventDefault();let t=l.sessionId||o;!t||!l.directory||!l.openSourceSession||l.openSourceSession(t,l.directory)}),F=Z.useMemo(()=>g?s(`chat.messageBody.tts.stopSpeaking`):s(`chat.messageBody.tts.readAloudWithProvider`,{provider:v===`browser`?`Browser`:v===`openai`?`OpenAI`:v===`openai-compatible`?`Custom`:`Say`}),[g,s,v]),I=J(e=>{if(e.stopPropagation(),e.preventDefault(),g){h&&m?.stop(),p();return}a.trim()&&f(a)});return(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":y||x?`true`:void 0,className:Y(eI,!t&&`opacity-50`),disabled:!t,"aria-label":s(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!t,onPointerDown:e=>e.stopPropagation(),onClick:e=>{M(e)},onFocus:()=>{t&&b(!0)},onBlur:()=>{x||b(!1)},children:x?(0,$.jsx)(X,{weight:lI,name:`check`,className:Y(tI,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:lI,name:`file-copy`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:s(`chat.messageBody.actions.copyAnswer`)})]}),O?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":s(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:P,children:(0,$.jsx)(X,{weight:lI,name:`target`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:s(`chat.messageBody.actions.openSourceSession`)})]}):null,i&&c!==`mini-chat`&&u.reviewTransfer?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,disabled:C||!t,className:Y(eI,(!t||C)&&`opacity-50`),"aria-label":i.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{N(e)},children:C?(0,$.jsx)(X,{weight:lI,name:`loader-4`,className:Y(tI,`animate-spin`)}):(0,$.jsx)(X,{weight:lI,name:`arrow-left-right`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:i.tooltip})]}):null,c!==`mini-chat`&&_&&t&&a.trim()&&(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:Y(eI,`!bg-transparent shadow-none`,g?`text-[var(--primary-base)]`:`hover:text-foreground/80`),"aria-label":s(g?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),"aria-pressed":g,onPointerDown:e=>e.stopPropagation(),onClick:I,children:(0,$.jsx)(Xm,{kind:`speaker`,active:g,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:F})]})]})}),NI=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:m,streamPhase:h,allowAnimation:g,onContentChange:_,hasTextContent:v=!1,onCopyMessage:y,onAuxiliaryContentComplete:b,showReasoningTraces:x=!1,shouldShowHeader:S=!1,turnGroupingContext:C,errorPresentation:w,reviewTransferDirection:T=null})=>{let E=w?.text,{t:D}=Xn(),O=mx(),k=Ab(),A=jb(k),j=h,M=Z.useRef(null),N=Z.useRef(null),P=h===`streaming`||h===`cooldown`,F=Z.useRef({messageId:t,experiencedStreamingOrCooldown:P});F.current.messageId===t?P&&(F.current.experiencedStreamingOrCooldown=!0):F.current={messageId:t,experiencedStreamingOrCooldown:P};let I=!!(u??c),L=!!(l??c),R=c?rI:nI,z=!i,B=Z.useMemo(()=>n.filter(e=>!CD(e)).filter(e=>e.type!==`reasoning`||x&&xD(e).trim().length>0).filter(e=>e.type!==`compaction`),[n,x]),V=Z.useMemo(()=>B.filter(e=>e.type===`tool`),[B]),H=Z.useMemo(()=>B.filter(e=>e.type===`text`),[B]),U=Z.useMemo(()=>Na(H),[H]),W=K(e=>e.openContextPreview),ee=p(),te=O===`mini-chat`,ne=Z.useMemo(()=>{if(ee||c||te)return null;for(let e of H){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=md(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of V){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=md(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[H,c,te,ee,V]),re=wa(e=>e.forkFromMessage),G=wa(e=>e.forkTransition),ie=wa(e=>e.currentSessionId),ae=wa(e=>e.getDirectoryForSession),oe=bd(),se=T===`review-to-original`,ce=!c&&!ee?T:null,le=Z.useMemo(()=>{let t=U.trim();if(!(!e||!oe||!t||!ce))return ce===`review-to-original`?{ariaLabel:D(`chat.messageBody.actions.sendReviewFeedback`),tooltip:D(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await ia(e,oe,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:D(`chat.messageBody.actions.sendImplementationResponse`),tooltip:D(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await Xi(e,oe,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[U,oe,ce,e,D]),[ue,de]=Z.useState(!1),fe=K(e=>e.chatRenderMode),pe=C?fe:`live`,me=K(e=>e.collapsibleThinkingBlocks),he=K(e=>e.showSplitAssistantMessageActions),ge=K(e=>e.showAssistantTps),_e=pe===`sorted`,ve=C?.isLastAssistantInTurn??!1,ye=a===`stop`,be=(ye||i||!!E)&&(C?.isTurnSettled??!0),xe=ye?`completed`:j,Se=V.length>0,Ce=Z.useMemo(()=>V.some(e=>bj(e)),[V]),we=bj,Te=yj,Ee=F.current.experiencedStreamingOrCooldown,De=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(De.current.messageId!==t&&(De.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Ee||!$r())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of V){if(n.observedPartIds.has(i.id))continue;if(!Co(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ki({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Ee,we,t,e,V]);let Oe=Z.useMemo(()=>V.length===0||!Ce&&V.every(e=>Te(e)),[V,Ce,Te]),ke=Z.useMemo(()=>B.filter(e=>e.type===`reasoning`),[B]),Ae=Z.useMemo(()=>ke.length===0||ke.every(e=>typeof e.time?.end==`number`),[ke]),je=typeof a!=`string`,Me=ke.length>0&&Se&&(Ce||je||!Oe),Ne=z||Se&&(Ce||je||!Oe),Pe=z||Me,Fe=Se||ke.length>0,Ie=H.length===0,Le=Fe&&Ie&&!Ne&&!Pe&&Oe&&Ae,Re=Z.useRef(!1),ze=Z.useRef(!1);Z.useEffect(()=>{ze.current=!1},[t]),Z.useEffect(()=>{if(!Le){Re.current=!1;return}Re.current||(Re.current=!0,b?.())},[Le,b]),Z.useEffect(()=>{if(z){ze.current=!1;return}if(Se){ze.current=!1;return}ke.length!==0&&(Pe||!Ae||ze.current||(ze.current=!0,_?.(`structural`)))},[z,Se,_,Ae,ke.length,Pe]);let Be=!!v&&!z,Ve=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ue||G)){de(!0);try{await re(e,t)}finally{de(!1)}}}),He=Z.useMemo(()=>{let e=C?.activityParts;return!_e||!e?[]:e},[_e,C?.activityParts]),Ue=Z.useMemo(()=>{let e=C?.activityGroupSegments;return!_e||!e?[]:e.filter(e=>e.anchorMessageId===t)},[_e,t,C?.activityGroupSegments]),We=Ue.length>0,Ge=Z.useMemo(()=>{let e=new Map,t=new Map;return He.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[He]),Ke=C?.toggleGroup,qe=C?.activityPresentationKind===`compaction`,Je=C?.isGroupExpanded===!0,Ye=_e&&qe&&!Je,Xe=_e?C?.activityOwnerMessageId===t||We:!C?.activityOwnerMessageId||C.activityOwnerMessageId===t||We,Ze=_e&&Xe&&(We||qe)&&!!Ke,Qe=_N(a,B),$e={finish:a,parts:B,streamPhase:xe,error:E,isLastAssistantInTurn:ve},et=SN($e),tt=Ko(e=>e.ttsInputMode),nt=Z.useMemo(()=>{if(!ve||qe||!be||!et)return``;let e=r??n,t=yN(e);return t<0?``:xD(e[t])},[ve,qe,be,et,r,n]),rt=tt===`final`?nt:U;zN({sessionId:e??``,messageId:t,created:s??0,text:rt,streaming:c&&k.active&&(j===`streaming`||j===`cooldown`),completed:c&&k.active&&i&&j!==`streaming`&&j!==`cooldown`&&!E});let it=_e&&CN($e),at=_e&&!et&&!(qe&&Je),ot=Be,st=ve&&be&&w?.variant!==`error`&&!Ye&&(v||!!E||i),ct=C?.diffStats?.hasDiffs===!0,lt=C?.isLatestTurn&&e&&k.active&&!te,ut=!te&&ve&&Qe&&be&&!Ye&&C?.diffStats?.hasDiffs===!0,dt=he&&ot&&!st&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(MI,{messageId:t,hasCopyableText:Be,isTouchContext:I,onCopyMessage:y,ttsText:rt,reviewTransferAction:le,sessionId:e}),[rt,Be,I,y,le,e,t]),pt=Z.useMemo(()=>e=>{if(!he||!_e)return null;let t=xD(e.part).trim();return t?(0,$.jsx)(MI,{hasCopyableText:!0,isTouchContext:I,onCopyMessage:async()=>(await Yn(t)).ok,ttsText:tt===`final`?``:t}):null},[_e,I,he,tt]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<B.length;t+=1){let n=B[t];!n||n.type!==`text`||at||Ge.get(n)?.kind!==`justification`&&(e=t)}return e},[Ge,at,dt,B]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Ze&&Ke&&C){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(qF,{parts:t,materializationParts:r,isExpanded:C.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:C.completionDisposition,activityPresentationKind:C.activityPresentationKind,durationMs:C.durationMs,startedAt:C.userMessageCreatedAt,onToggle:Ke,isMobile:c,expandedTools:d,onToggleTool:f,onShowPopup:m,onContentChange:_,streamPhase:xe,showHeader:!0,diffStats:C.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};Ue.length>0?Ue.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):qe&&e(`${t}:compaction-status`,[])}let r=0;for(;r<B.length;){let i=B[r];if(i.type===`text`){let a=Ge.get(i);if(at){r+=1;continue}if(Ye){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:N,"data-message-text-export-source":`true`,children:(0,$.jsx)(YM,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,allowSortedFinalStreaming:it,hasStreamingHapticLifecycle:Ee,onContentChange:_,onShowPopup:m})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:c?$F:QF,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:iI,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(Ge.get(i)?.kind===`reasoning`){r+=1;continue}if(!xD(i).trim()){r+=1;continue}x&&(me?n.push((0,$.jsx)(`div`,{className:sy(c),children:(0,$.jsx)(sN,{part:i,messageId:t,streamPhase:xe,onContentChange:_})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(YM,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:pe,hasStreamingHapticLifecycle:Ee,onContentChange:_,onShowPopup:m},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(_e&&!Xe){r+=1;continue}if(Ge.get(i)?.kind===`tool`){r+=1;continue}if(_e&&vj(a)){let e=nF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(aF,{activities:i,isMobile:c,isTurnLive:xe!==`completed`,hasFollowingOtherType:eF(B,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return hj(n)?(0,$.jsx)(zF,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(kM,{part:e.part,messageId:t,isExpanded:d.has(e.part.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:_,onShowPopup:m,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(gj(a)){let e=oF(B,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(dF,{activities:i,isMobile:c,children:i.map(e=>(0,$.jsx)(zF,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(fj(a)){n.push((0,$.jsx)(`div`,{className:sy(c),children:(0,$.jsx)(kM,{part:e,messageId:t,isExpanded:d.has(e.id),onToggle:f,isMobile:c,alwaysShowActions:L,onContentChange:_,onShowPopup:m,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:sy(c),children:(0,$.jsx)(zF,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:c,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}let i=n.at(-1);if(Z.isValidElement(i)&&i.props[`data-message-text-export-source`]===`true`&&xe!==`completed`&&!be&&!w&&(!C||C.isLastAssistantInTurn)){let e=i;n[n.length-1]=Z.cloneElement(e,{className:Y(typeof e.props.className==`string`?e.props.className:void 0,c?`pb-1`:`pb-1.5`),"data-live-status-text-gap":``})}return n},[Ge,Ue,L,pe,me,0,d,Ye,qe,c,Xe,_e,mt,t,ft,pt,e,_,m,f,Ze,dt,xe,w,Ee,be,x,at,it,Ke,C,B]),_t=Z.useMemo(()=>{if(!ve||!be)return;let e=C?.durationMs;if(!(typeof e!=`number`||e<=0))return AI(e)},[ve,be,C?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=_P(e);return t.length>0?t:null},[o,s]),yt=Z.useMemo(()=>{if(!ge||!ve||w?.variant===`error`)return null;let e=C?.assistantTps;if(!LP({completionDisposition:C?.completionDisposition,tps:e}))return null;let t=RP(e??0);return t.length>0?t:null},[ge,w?.variant,ve,C?.assistantTps,C?.completionDisposition]),bt=(0,$.jsxs)($.Fragment,{children:[!te&&!c&&!ee&&ne?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:eI,"aria-label":D(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=oe??(ie?ae(ie):null);e&&W(e,ne)},children:(0,$.jsx)(X,{weight:lI,name:`global`,className:tI})})}),(0,$.jsx)(Js,{sideOffset:6,children:D(`chat.messageBody.actions.openPreview`)})]}):null,!te&&!se&&A.fork?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,size:`icon`,variant:`ghost`,className:eI,"aria-label":D(`chat.messageBody.actions.forkAria`),"aria-busy":ue,disabled:ue||!!G,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Ve(e)},children:(0,$.jsx)(X,{weight:lI,name:ue?`loader-4`:`git-branch`,className:Y(tI,ue&&`animate-spin`)})})}),(0,$.jsx)(Js,{sideOffset:6,children:D(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:M,"data-message-text-export-root":`true`,...gO,className:Y(`relative w-full yuri-message-hover-scope`),style:XF,children:[(0,$.jsx)(fP,{containerRef:M}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,(S||C?.headerMessageId===t)&&(c?`[&>[data-message-text-export-source]:first-child]:pt-1.5`:`[&>[data-message-text-export-source]:first-child]:pt-2`)),children:[gt,w&&(0,$.jsx)(Dd,{children:(0,$.jsx)(`div`,{className:`my-1.5`,"data-assistant-error":w.variant,children:(0,$.jsx)(YF,{presentation:w,sessionId:e,messageId:t,directory:oe??void 0})})},`assistant-error`)]}),ut&&C?.diffStats?(0,$.jsx)(SI,{fileCount:C.diffStats.files,changedFiles:C.changedFiles,turnId:C.turnId,isLatestTurn:C.isLatestTurn,isMobile:c}):null,(0,$.jsx)(Ag,{files:n,messageID:t,sessionID:e,onShowPopup:m}),ht&&(0,$.jsx)(`div`,{className:Y(c?$F:QF),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:iI,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:R,"data-message-footer":`true`,style:ZF,children:[(0,$.jsxs)(`div`,{className:iI,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt||lt?(0,$.jsxs)(`div`,{className:aI,children:[yt||_t?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 whitespace-nowrap`,children:[yt?(0,$.jsx)(dI,{label:yt}):null,_t?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsxs)(`span`,{className:sI,children:[(0,$.jsx)(X,{weight:lI,name:`hourglass`,className:cI}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(Js,{children:_t})]}):null]}):null,lt&&e?(0,$.jsx)(zP,{sessionId:e}):null,vt?(0,$.jsx)(uI,{messageId:t,label:vt,focusReveal:c}):null]}):null,!te&&ve&&ye&&!ct?(0,$.jsx)(dN,{activityParts:C?.activityParts}):null]}),!st&&!Ye&&yt?(0,$.jsx)(`div`,{className:R,"data-message-footer":`true`,"data-message-tps":`interrupted`,style:ZF,children:(0,$.jsx)(`div`,{className:aI,children:(0,$.jsx)(dI,{label:yt})})}):null]})]})}),PI=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)(jI,{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)(NI,{...r}),t[26]=r,t[27]=i),i});function FI(e){return e.openContextPanelTab}function II(e){return e.setCurrentSession}function LI(e){return e.openContextPanelTab}function RI(e){return!e}function zI(e){return e.openContextPanelTab}var BI=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}},VI=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},HI={"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`},UI={icon:`pause-circle`,variant:`muted`};function WI(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`,UI.icon,UI.variant,!0):c(`chat.response.interrupted`,UI.icon,UI.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(HI,a)){if(a===`compaction.interrupted`)return c(HI[a],UI.icon,UI.variant,r===`Compaction was interrupted`);if(a===`compaction.unavailable`)return c(HI[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(HI[a],e)}return(!a||a===`unknown`||a===`error`)&&VI(r)?c(`chat.response.auth`,`lock`):{...c(`chat.response.failed`,`error-warning`),...!r&&i?{rawMessage:i}:{}}}function GI(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.nativeType===`synthetic`&&t.description===`Continuing after restart`}function KI(e,t){if(GI(e))return{text:t(`chat.response.continuingAfterRestart`),icon:`restart`,variant:`info`}}function qI(e){return!e}function JI(e){let t=(0,Q.c)(60),{part:n,isMobile:r}=e,i=r!==void 0&&r,{t:a}=Xn(),o;t[0]!==n.id||t[1]!==n.messageID||t[2]!==n.sessionID?(o=JSON.stringify([n.sessionID,n.messageID,n.id]),t[0]=n.id,t[1]=n.messageID,t[2]=n.sessionID,t[3]=o):o=t[3];let s=o,{expanded:c,toggle:l}=mO(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?WI(n.error,a):void 0,t[11]=m,t[12]=n.error,t[13]=a,t[14]=_):_=t[14];let v=_,y;t[15]!==m||t[16]!==n.summary?(y=m?``:n.summary?.trim()??``,t[15]=m,t[16]=n.summary,t[17]=y):y=t[17];let b=y,x,S,C,w,T,E,D,O,k;if(t[18]!==u||t[19]!==c||t[20]!==v?.text||t[21]!==m||t[22]!==i||t[23]!==p||t[24]!==n.status||t[25]!==b||t[26]!==g||t[27]!==f){let e=Y(`shrink-0 typography-meta`,m?`text-[var(--status-error)]/85`:`text-muted-foreground`);E=`w-full min-w-0`,D=``,O=n.status;let r=i?`min-h-7`:`min-h-8`;t[37]===r?k=t[38]:(k=Y(`flex w-full items-center gap-3`,r),t[37]=r,t[38]=k),x=`separator`,S=p?`polite`:void 0,C=v?.text??g,t[39]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 border-t`,"aria-hidden":`true`}),t[39]=w):w=t[39],T=b?(0,$.jsxs)(er,{variant:`ghost`,size:`sm`,className:Y(e,ly),"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)(Ju,{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 YI=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},XI=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=YI(t.mode)??YI(t.agent)??YI(r?.agent),o=YI(t.providerID)??YI(n?.providerID)??YI(i?.providerID),s=YI(t.modelID)??YI(n?.modelID)??YI(n?.id)??YI(i?.modelID)??YI(i?.id),c=YI(n?.variant)??YI(i?.variant)??YI(t.variant)??YI(r?.variant);return!a&&!o&&!s&&!c?null:{agentName:a,providerId:o,modelId:s,variant:c}},ZI=e=>{let t=e?.providerId?.trim(),n=e?.modelId?.trim();return!t||!n?null:{providerId:t,modelId:n}},QI=e=>ZI(e.assistantIdentity)??ZI(e.userIdentity)??(e.allowComposerFallback?ZI(e.composerSelection):null)??ZI(e.sessionSelection),$I=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}},eL=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),tL=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,nL=e=>!e,rL=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},iL=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),aL=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,oL=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,sL=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},cL=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},lL=e=>!e||sL(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`)}),uL=e=>sL(e)===`user`?lL(e)||e.parts.some(e=>{let t=e.shellAction;return e.type===`text`&&typeof t==`object`&&!!t}):!1,dL=(e,t)=>{if(sL(e)!==`assistant`||t&&cL(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}}},fL=(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(sL(t)===`user`)break;let{hide:i,details:a}=dL(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},pL=Ku(()=>Pn(()=>import(`./ToolOutputDialog-CkZORaFS.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]))),mL=4e3,hL=new Map,gL=new Map,_L=new Set([`bash`,`shell`,`cmd`,`terminal`]),vL=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},yL=e=>{let t=hL.get(e);return t?new Set(t):new Set},bL=(e,t)=>{if(hL.size>=mL&&!hL.has(e)){let e=hL.keys().next().value;typeof e==`string`&&hL.delete(e)}hL.set(e,new Set(t))},xL=e=>{let t=gL.get(e);return t?new Set(t):new Set},SL=(e,t)=>{if(gL.size>=mL&&!gL.has(e)){let e=gL.keys().next().value;typeof e==`string`&&gL.delete(e)}gL.set(e,new Set(t))},CL=200,wL=new Map,TL=e=>wL.get(e),EL=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=wL.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(wL.size>=CL&&!wL.has(e)){let e=wL.keys().next().value;typeof e==`string`&&wL.delete(e)}wL.set(e,t)}};function DL(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 OL=(e,t)=>{if(typeof e==`object`&&e)return e[t]},kL=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,turnOwnsAssistantHeader:s=!1,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=Xn(),{isMobile:m,isTablet:h,hasTouchInput:g}=Kc(),_=Ab(),v=jb(_),y=m||h,b=Z.useRef(null),x=Z.useRef(null),S=J(t=>{b.current=t,x.current?.(),x.current=null,t&&m&&(x.current=NP(t,e.info.id))});Z.useEffect(()=>{let t=b.current;return x.current?.(),x.current=null,t&&m&&(x.current=NP(t,e.info.id)),()=>{x.current?.(),x.current=null}},[m,e.info.id]);let C=wa(e=>e.currentSessionId),w=wa(e=>e.revertToMessage),T=wa(e=>e.editMessagePreservingChanges),E=wa(e=>e.forkFromMessage),D=wa(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=wa(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=wa(e=>e.clearStagedMessageEdit);Ze(`ui.chat_message.render`),c&&Ze(`ui.chat_message.render.streaming`);let A=Ko(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=K(H(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{C&&_O.getInstance().recordSessionStart(C)},[C]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[U,W]=Z.useState(()=>yL(e.info.id)),[ee,te]=Z.useState(()=>xL(e.info.id)),[ne,re]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{W(yL(e.info.id)),te(xL(e.info.id))},[e.info.id]);let G=Z.useMemo(()=>BI(e.info),[e.info]).isUser,ie=Z.useMemo(()=>Pe(e.parts),[e.parts]),ae=G&&(m||!M),oe=G&&!m&&M&&!ae,se=e.info.sessionID,{currentContextAgent:ce,savedSessionAgentSelection:le}=wy(H(e=>({currentContextAgent:c&&se?e.currentAgentContext.get(se):void 0,savedSessionAgentSelection:c&&se?e.sessionAgentSelections.get(se):void 0}))),ue=Z.useMemo(()=>bD(e.sourceParts??e.parts),[e.parts,e.sourceParts]),de=Z.useMemo(()=>G?PD(ue):bD(e.parts),[G,e.parts,ue]),fe=Z.useMemo(()=>{if(G||!t)return null;let e=OL(t.info,`clientRole`),n=OL(t.info,`role`);return(typeof e==`string`?e:typeof n==`string`?n:void 0)===`user`&&XI(t.info)||null},[G,t]),pe=Z.useMemo(()=>{if(G)return;let t=OL(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=OL(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(fe?.agentName)return fe.agentName;if(se)return ce||(le??void 0)},[G,e.info,fe,se,ce,le]),me=G?null:XI(e.info),he=me?.providerId??null,ge=me?.modelId??null,_e=ur(H(e=>{if(G||!se)return null;if(fe?.providerId&&fe?.modelId)return{providerId:fe.providerId,modelId:fe.modelId};if(pe){let t=e.getAgentModelForSession(se,pe);if(t?.providerId&&t?.modelId)return t}let t=e.getSessionModelSelection(se);return t?.providerId&&t?.modelId?t:null})),ve=Z.useMemo(()=>G?null:typeof he==`string`&&he.trim().length>0?he:_e?.providerId??null,[G,he,_e]),ye=Z.useMemo(()=>G?null:typeof ge==`string`&&ge.trim().length>0?ge:_e?.modelId??null,[G,ge,_e]),be=e.info.id?TL(e.info.id):void 0;G||EL(e.info.id,{agent:pe,provider:ve??void 0,model:ye??void 0});let xe=pe??be?.agent,Se=ve??be?.provider??null,Ce=ye??be?.model??null,we=Z.useMemo(()=>{if(G)return;let e=Se&&A.length>0?A.find(e=>e.id===Se):void 0;return ki(e,Ce)||void 0},[G,Se,Ce,A]),Te=Z.useMemo(()=>{if(G||!ve||!ye)return!1;let e=A.find(e=>e.id===ve);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===ye)?.variants;return!!(t&&Object.keys(t).length>0)},[G,ye,ve,A]),Ee=DL(xe),De=DL(Se??void 0),Oe=DL(Ce??void 0),ke=DL(we),Ae=Ee??void 0,je=De??null,Me=Oe??null,Ne=ke??void 0,Fe=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ie=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Le=Z.useMemo(()=>G?!0:!!(Fe&&Fe>0),[G,Fe]),Re=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),ze=Z.useMemo(()=>wD(de,{includeReasoning:j}),[de,j]),Be=Z.useMemo(()=>G?ze:!Le&&N===`sorted`?[]:ze,[N,Le,G,ze]),Ve=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`text`),[G,ze]),He=Z.useMemo(()=>G?[]:ze.filter(e=>e.type===`tool`),[G,ze]),Ue=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of He){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=vL(t.tool);!r||!_L.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=vL(t.part.tool);!n||!_L.has(n)||e.add(t.id)}return e},[P,He,a?.activityParts]),We=Z.useMemo(()=>{if(Ue.size===0&&ee.size===0)return U;let e=new Set(U);return Ue.forEach(t=>{ee.has(t)||e.add(t)}),ee.forEach(t=>{e.delete(t)}),e},[ee,Ue,U]),Ge=Z.useMemo(()=>{if(!G)return;let e=de.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[G,de]),Ke=G&&!FD(Be),qe=typeof Re!=`string`,Je=Z.useMemo(()=>G?!1:Ve.length===0||He.length===0?qe:!0,[Ve.length,He.length,qe,G]),Ye=Z.useMemo(()=>!G&&_O.getInstance().shouldAnimateMessage(e.info,C||e.info.sessionID),[e.info,C,G]),[Xe,Qe]=Z.useState(!1),$e=Z.useMemo(()=>n?BI(n.info):null,[n]),et=!!a,tt=a?.isLastAssistantInTurn??!1,nt=aL({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),rt=Z.useMemo(()=>G?!1:et?!tt:$e?!$e.isUser&&$e.role===`assistant`:!1,[et,tt,G,$e]),it=Z.useMemo(()=>Le?`completed`:c?l??`streaming`:`completed`,[l,c,Le]);Z.useEffect(()=>{!G||!u||d?.(e.info.id)},[u,G,e.info.id,d]),Z.useEffect(()=>{Qe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;G||!t||t!==e.info.id||(it===`streaming`||it===`cooldown`)&&Qe(!0)},[o,G,e.info.id,it,a?.headerMessageId]);let at=Z.useMemo(()=>{if(G)return!0;if(s)return!1;let t=o??a?.headerMessageId;return t?e.info.id===t?it===`completed`||Xe||it===`streaming`||it===`cooldown`:!1:!0},[o,Xe,G,a,it,e.info.id,s]),ot=Z.useCallback(e=>{Yn(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),st=G?void 0:a?.userMessageVariant??fe?.variant,ct=!G&&Te&&typeof st==`string`&&st.trim().length>0?st:void 0,lt=Z.useMemo(()=>{if(!G&&!qI(et?tt:!rt))return WI(e.info?.error,p)},[et,rt,tt,G,e.info,p]),ut=lt?.text,dt=Z.useMemo(()=>{if(G){let e=Be.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6593
6593
|
|
|
6594
6594
|
`);let t=Be.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.command;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);return t.length>0?t.join(`
|
|
6595
6595
|
`):Be.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
|
|
6596
6596
|
`).replace(/\n\s*\n+/g,`
|
|
6597
|
-
`)}return ut&&ut.trim().length>0?ut:Na(Be)},[ut,Be,G]),ft=dt.length>0,pt=Z.useCallback(async()=>(await Yn(dt)).ok?(G&&(R(!0),setTimeout(()=>R(!1),2e3)),!0):!1,[G,dt]),mt=J(async()=>{if(!(!se||!e.info.id||V.current)){V.current=`revert`,B(`revert`);try{_.onRevertMessage?await _.onRevertMessage(e.info.id):await w(se,e.info.id,{directory:_.directory??void 0})}catch(e){_.onRevertMessage&&zn.error(p(`chat.revert.toast.failed`),{id:`session-revert-error`,description:e&&typeof e==`object`&&`message`in e?String(e.message):String(e)})}finally{V.current=null,B(null)}}}),ht=J(()=>{if(!se||!e.info.id||V.current)return;let t={info:e.info,parts:e.parts};if(_.onEditMessage){_.onEditMessage(e.info.id,t).catch(()=>{});return}T(se,e.info.id,t).catch(()=>{})}),gt=J(()=>{se&&k(se)}),_t=Z.useCallback(async()=>{if(e.info.id,!se||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!se,hasMessageId:!!e.info.id});return}if(!V.current){V.current=`fork`,B(`fork`);try{await E(se,e.info.id)}finally{V.current=null,B(null)}}},[se,e.info.id,E]),vt=J(t=>{let n=Ue.has(t),r=We.has(t);if(n){te(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),SL(e.info.id,i),i}),r||W(n=>{let r=new Set(n);return r.delete(t),bL(e.info.id,r),r});return}W(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),bL(e.info.id,r),r}),te(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),SL(e.info.id,r),r})}),yt=i??null,bt=Z.useRef(!1),xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1),wt=Z.useRef(!1),Tt=Z.useRef(!1);Z.useEffect(()=>{xt.current=!1,St.current=!1,Ct.current=!1,wt.current=!1,bt.current=!1,Tt.current=!1},[e.info.id]);let Et=Z.useCallback(()=>{G||bt.current||(bt.current=!0,r?.(`structural`))},[G,r]),Dt=K(e=>e.setImagePreviewOpen),Ot=Z.useCallback(e=>{(e.image||e.mermaid||e.video)&&(re(e),Dt(!0))},[Dt]),kt=Z.useCallback(e=>{re(t=>({...t,open:e})),Dt(e)},[Dt]),At=!!OL(e.info,`animationSettled`),jt=it===`streaming`||it===`cooldown`;jt&&(Tt.current=!0);let Mt=Z.useMemo(()=>!G&&ze.some(e=>e.type===`reasoning`),[G,ze]),Nt=Ye&&!At&&!jt&&!Tt.current,Pt=!G&&Ye&&Ve.length>0&&!Je;Z.useEffect(()=>{if(yt?.onStreamingCandidate){if(!Pt){St.current&&=(Mt&&yt?.onReasoningBlock?yt.onReasoningBlock():yt?.onReservationCancelled&&yt.onReservationCancelled(),!1);return}wt.current||(wt.current=!0,yt.onStreamingCandidate(),St.current=!0)}},[yt,Pt,Mt]),Z.useEffect(()=>{yt?.onAnimationStart&&Nt&&(Ct.current||=(yt.onAnimationStart(),!0))},[yt,Nt]),Z.useEffect(()=>{if(G)return;let e=yt?.onAnimatedHeightChange;if(!e||!(Nt||Pt))return;let t=b.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()}},[Nt,G,yt,Pt]);let Ft=Z.useMemo(()=>G?!0:ze.some(e=>e.type===`text`||e.type===`reasoning`?xD(e).trim().length>0:e.type===`tool`||e.type===`file`),[G,ze]),It=!!(a?.activityOwnerMessageId===e.info.id&&((a.activityParts?.length??0)>0||a.hasTools||a.hasReasoning)),Lt=!G&&!ie&&(Le||!c||!!a)&&!lt&&!Ft&&!It,Rt=KI(e.info,p);if(Rt)return(0,$.jsx)(`div`,{ref:S,className:`chat-message-column py-1.5`,id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-restart-notice":``,children:(0,$.jsx)(Uv,{presentation:Rt})});if(Ke||Lt)return null;if(ie)return(0,$.jsx)(`div`,{className:Y(`group w-full`,m?`py-2`:`py-3`),id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-compaction-status":ie.status,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(JI,{part:ie,isMobile:m})})});let zt=!G&&at?m?M?`pt-4`:`pt-0`:`pt-6`:`pt-0`,Bt=uL(e);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`w-full`,!G&&`yuri-message-hover-scope`,G?m?`pt-2`:`pt-6`:zt,G||rt||s?`pb-0`:nt?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,...gO,ref:S,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:G?FD(Be)?(0,$.jsx)(Dd,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{...gO,className:Y(`relative flex`,Bt?`justify-start`:`justify-end`,m?void 0:`yuri-user-shell-hover-scope`),children:(0,$.jsxs)(`div`,{className:Y(Bt?`w-full min-w-0`:`max-w-[85%]`,oe&&!Bt?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:Bt?void 0:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:Bt?`min-w-0 text-left`:`px-3 py-1.5 shadow-none`,"data-user-message-bubble":Bt?void 0:`true`,"data-shell-result":Bt?`true`:void 0,children:(0,$.jsx)(PI,{messageId:e.info.id,parts:Be,sourceParts:ue,isUser:G,isMessageCompleted:Le,messageFinish:Re,messageCreatedAt:Ie??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:ot,expandedTools:U,onToggleTool:vt,onShowPopup:Ot,streamPhase:it,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Et,agentMention:Ge,onEdit:!D&&v.edit?ht:void 0,onRevert:!D&&v.revert?mt:void 0,onFork:!D&&G&&v.fork?_t:void 0,editing:D,editStaged:O,onCancelEdit:O?gt:void 0,pendingMessageAction:z,errorPresentation:lt,userActionsMode:ae?`external-content`:`inline`,stickyUserHeaderEnabled:M&&!Bt})}),ae?(0,$.jsx)(PI,{messageId:e.info.id,parts:Be,sourceParts:ue,isUser:G,isMessageCompleted:Le,messageFinish:Re,messageCreatedAt:Ie??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:ot,expandedTools:U,onToggleTool:vt,onShowPopup:Ot,streamPhase:it,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Et,agentMention:Ge,onEdit:!D&&v.edit?ht:void 0,onRevert:!D&&v.revert?mt:void 0,onFork:!D&&G&&v.fork?_t:void 0,editing:D,editStaged:O,onCancelEdit:O?gt:void 0,pendingMessageAction:z,errorPresentation:lt,userActionsMode:`external-actions`,stickyUserHeaderEnabled:M}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[at&&(0,$.jsx)(yO,{isUser:G,isMobile:m,providerID:je,modelID:Me,agentName:Ae,modelName:Ne,variant:ct}),!Ft&&!It&&!lt&&c&&!Le&&(0,$.jsxs)(`div`,{role:`status`,"aria-label":p(`common.loading`),"data-assistant-content-loading":``,className:`space-y-2 py-2`,children:[(0,$.jsx)(af,{className:`h-3.5 w-2/3`}),(0,$.jsx)(af,{className:`h-3.5 w-1/3`})]}),(0,$.jsx)(PI,{sessionId:e.info.sessionID,messageId:e.info.id,parts:ze,sourceParts:de,isUser:G,isMessageCompleted:Le,messageFinish:Re,messageCompletedAt:Fe??void 0,messageCreatedAt:Ie??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:ot,expandedTools:We,onToggleTool:vt,onShowPopup:Ot,streamPhase:it,allowAnimation:Nt,onContentChange:r,shouldShowHeader:at,hasTextContent:ft,onCopyMessage:pt,copiedMessage:L,onAuxiliaryContentComplete:Et,showReasoningTraces:j,agentMention:Ge,turnGroupingContext:a,errorPresentation:lt,reviewTransferDirection:f})]})})}),ne.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(pL,{popup:ne,onOpenChange:kt,isMobile:m})}):null]})},(e,t)=>nA({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&rA(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&rA(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.reviewTransferDirection===t.reviewTransferDirection&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&dA(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,BI(e.message.info).isUser)),AL=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},jL=e=>{let t=e?.type;return t===`compaction`?!Ee(e):t===`text`&&AL(e).trim()===`/compact`},ML=e=>e?e.some(e=>jL(e)):!1,NL=e=>ML(e.parts),PL=e=>e?ML(e.sourceParts)||ML(e.parts):!1,FL=e=>{if(!NL(e))return e;let t=!1,n=e.parts.map(e=>e?.type!==`compaction`||Ee(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}},IL=e=>{let t=bD(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},LL=new WeakMap,RL=e=>{let t=LL.get(e);if(t)return t;let n=FL(IL(e)),r=n.parts,i=jo(r),a=i===r?n:{...n,parts:i,sourceParts:r};return LL.set(e,a),a},zL={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},BL=[],VL=`\0`,HL=new Set([`edit`,`write`,`apply_patch`]),UL={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`},WL=[`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`],GL=(e,t)=>{let n=UL[_d(e)];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},KL=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)},qL=(e,t)=>t(WL[KL(e)%WL.length]??`chat.assistantStatus.working`),JL=(e,t,n)=>{let r,i;if(!xa(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??eR(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=_d(tR(n));HL.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=$L(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=eR(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?GL(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):qL(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},YL=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(VL),XL=e=>{let[t,n,r=`working`,i]=e.split(VL);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},ZL=e=>e.type===`reasoning`,QL=e=>e.type===`text`,$L=e=>{if(QL(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},eR=e=>(QL(e)||ZL(e),e.time),tR=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function nR(e,t){let{t:n}=Xn(),r=wa(e=>e.currentSessionId),i=wa(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Rr(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=Ca(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`&&!ue(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=Bo(f??``,o??void 0,a??void 0),g=Bo(m??``,o??void 0,a??void 0),_=!!m&&ML(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`:bN(d.finish,h,d.error))),x=Z.useMemo(()=>{let e=`${a??``}:${f??``}`;return YL(JL(f&&!d.error&&d.index>p.index?h:BL,e,n))},[a,f,d.error,d.index,p.index,h,n]),S=Da(a??``,o??void 0),C=Fa(a??``,o??void 0),w=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),T=wa(w),{phase:E,isWorking:D}=wx(a,o??void 0),O=!!(d.error&&d.index>p.index),k=vo(a??``,o??void 0),A=k?.type===`retry`?k.attempt:void 0,j=k?.type===`retry`?k.next:void 0,M=Z.useMemo(()=>XL(x),[x]),N=Z.useMemo(()=>{let e=!!(T&&!T.acknowledged);return{wasAborted:e,abortActive:e}},[T]),P=Z.useMemo(()=>{if(s)return{...zL,isRecovering:!0,canAbort:D};if(O&&E!==`retry`)return{...zL,isTurnSettled:!0,canAbort:D};if(N.wasAborted)return{...zL,wasAborted:!0,abortActive:N.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(b)return{...zL,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 rR=Z.memo(()=>{let e=(0,Q.c)(15),t=Ab(),n=wa(iR),r=wa(aR),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(oR),l=wa(sR),{working:u}=nR(i,a),d=Ko(cR),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)(Fb,{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],_});rR.displayName=`StatusRowContainer`;function iR(e){return e.currentSessionId}function aR(e){return e.currentSessionDirectory}function oR(e){return e.abortPromptSessionId}function sR(e){return e.abortPromptExpiresAt}function cR(e){return e.currentAgentName}var lR=(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},uR=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},dR=Z.memo(e=>{let t=(0,Q.c)(37),{assistantMessage:n,userMessage:r,pendingPresentation:i,assistantIsInActiveTurn:a,isMobile:o}=e,s=Ko(fR),c=Ko(H(pR)),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}=wy(H(u)),p;t[3]===r?p=t[4]:(p=r?XI(r.info):null,t[3]=r,t[4]=p);let m=p,h;t[5]===n?h=t[6]:(h=n?XI(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?lR(n.info,`mode`)??lR(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=ur(b),S=!n||a,C;t[18]!==g||t[19]!==c||t[20]!==x||t[21]!==S||t[22]!==m?(C=QI({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=uR(y),O=uR(T),k=uR(E),A,j;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,j=e?.models?.find(e=>e.id===k),t[24]=i?.modelName,t[25]=s,t[26]=k,t[27]=O,t[28]=A,t[29]=j}else A=t[28],j=t[29];let M=j,N=M?.variants&&Object.keys(M.variants).length>0?m?.variant??i?.variant:void 0,P=O??null,F=k??null,I=D??void 0,L;return t[30]!==o||t[31]!==A||t[32]!==P||t[33]!==F||t[34]!==I||t[35]!==N?(L=(0,$.jsx)(yO,{isUser:!1,isMobile:o,providerID:P,modelID:F,agentName:I,modelName:A,variant:N}),t[30]=o,t[31]=A,t[32]=P,t[33]=F,t[34]=I,t[35]=N,t[36]=L):L=t[36],L});function fR(e){return e.providers}function pR(e){return{providerId:e.currentProviderId,modelId:e.currentModelId}}var mR=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(hR)),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 hR(e){return e.info.id}var gR=e=>{let t=(0,Q.c)(13),{sessionId:n,directory:r,hasInlineError:i,fallbackHeader:a}=e,o=i!==void 0&&i,{t:s}=Xn(),c=Yr(n),l=Do(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),Rr(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=WI(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)(Uv,{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},_R=new Set,vR=()=>{},yR=()=>{},bR=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=K(xR),y=Ab(),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&&uL(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)(dR,{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)(qF,{parts:[],isExpanded:i,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof b==`number`?b:void 0,onToggle:u,isMobile:v,expandedTools:_R,onToggleTool:vR,onShowPopup:yR,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)(mR,{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)(gR,{sessionId:x.info.sessionID,directory:x.sourceDirectory??y.directory,hasInlineError:!!n.assistantMessages.at(-1)?.info.error,fallbackHeader:!w&&!m&&!s?(0,$.jsx)(dR,{userMessage:n.userMessage,pendingPresentation:$I(XI(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`,...gO,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 xR(e){return e.isMobile}var SR=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,CR=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},wR=e=>{let t=e.text;if(typeof t==`string`&&SD(t))return t;let n=e.content;if(typeof n==`string`&&SD(n))return n},TR=(e,t,n,r)=>({id:SR(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:CR(n)}),ER=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`&&wR(e)&&(i=!0)})});let a=e.assistantMessages.at(-1),o=a?yN(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`?wR(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={...TR(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`&&!GI(t.message.info)&&!ID(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}},DR=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}},OR=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},kR=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(_N(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!vN(t))continue;let r=OR(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:SR(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=OR(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:SR(n.info.id,t,e)}}}return{}},AR=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}},jR=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},MR=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},NR=e=>e.info.nativeType===`synthetic`,PR=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},FR=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},IR=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},LR=e=>{let t=e.info.time?.streamed;return typeof t==`number`&&Number.isFinite(t)?t:void 0},RR=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},zR=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},BR=(e,t)=>{let n=MR(e);return{messageId:e.info.id,role:n,parentMessageId:PR(e),message:e,order:t}},VR=(e,t)=>{let n=e?FR(e):void 0,r,i,a,o=!1;t.forEach(e=>{let t=IR(e);typeof t==`number`?r=Math.max(r??0,t):o=!0;let n=LR(e);typeof n==`number`&&(i=Math.max(i??0,n)),e.parts.forEach(e=>{let t=RR(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}},HR=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`||gN(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 IR(t)!=`number`)return`active`;return`active`},UR=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return bN(n.finish,t.parts,n.error)},WR=e=>PL(e)?`compaction`:`default`,GR={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},KR=(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},qR=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&KR(e.messages,t.messages),JR=(e,t)=>{e.summary=kR(e.assistantMessages),e.summaryText=e.summary.text??(e.userMessage?zR(e.userMessage):void 0),e.diffStats=e.userMessage?AR(e.userMessage):void 0,e.changedFiles=t.showTurnChangedFiles&&e.userMessage?jR(e.userMessage):void 0,e.completionDisposition=HR(e.assistantMessages),e.hasConfirmedFinalBody=UR(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(Ee);r?.reason===`auto`&&r.status!==`failed`&&(e.completionDisposition=`active`,e.hasConfirmedFinalBody=!1);break}e.activityPresentationKind=e.userMessage?WR(e.userMessage):`default`;let n=ER({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=VR(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},YR=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>JR(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&&qR(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,JR(e,t))});return r&&i?n.turns:a},XR=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},ZR=(e,t)=>{let n={...GR,...t},r=[],i=new Map,a=new Map,o=new Set;e.forEach((e,t)=>{let n=MR(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&&!PR(e);if(n!==`user`&&!s)return;if(r.length>0&&NR(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?[]:[BR(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=MR(e),r=i.get(e.info.id);r&&(s=r);let c=a.get(e.info.id);if(c){c.messages.push(BR(e,t));return}if(n!==`assistant`)return;let l=PR(e),u=l?i.get(l):s;u&&(u.assistantMessages.push(e),u.assistantMessageIds.push(e.info.id),u.messages.push(BR(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=DR(XR(YR(r,n))),u=new Set;return e.forEach(e=>{o.has(e.info.id)||MR(e)===`assistant`&&PR(e)||u.add(e.info.id)}),{...l,ungroupedMessageIds:u}},QR=30,$R=4,ez=4,tz=33554432,nz=8388608,rz=new Map,iz=new Map,az=0,oz=new WeakMap,sz=1,cz=()=>m()?$R:xo()?ez:QR,lz=()=>m()||xo()?nz:tz,uz=(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},dz=e=>{rz.delete(e);let t=iz.get(e)??0;iz.delete(e),az=Math.max(0,az-t)},fz=e=>{let t=oz.get(e);if(t!==void 0)return t;let n=sz;return sz+=1,oz.set(e,n),n},pz=e=>e.map(e=>`${fz(e.info)}:${fz(e.parts)}:${e.parts.map(e=>fz(e)).join(`,`)}`).join(`;`),mz=(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,pz(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},hz=e=>{let t=rz.get(e);return t&&(rz.delete(e),rz.set(e,t)),t},gz=(e,t)=>{dz(e);let n=cz(),r=lz(),i=uz(e,t);if(!(i>r)){for(;rz.size>=n||az+i>r;){let e=rz.keys().next().value;if(typeof e!=`string`)break;dz(e)}rz.set(e,t),iz.set(e,i),az+=i}},_z=[],vz=(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},yz=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},bz=(e,t)=>t===null?{staticTurns:e,streamingTurns:_z}:{staticTurns:t===0?_z:e.slice(0,t),streamingTurns:e.slice(t)},xz=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(_z),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=_z,a.current=null);let l=Z.useMemo(()=>{let r=mz(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=hz(r);return i&&(!n.current||i===n.current)?(n.current=i,i):ae(`ui.turns.projection_ms`,()=>{let i=ZR(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,gz(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=yz({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=bz(l.turns,f).staticTurns;return vz(r.current,e)?r.current:r.current=e},[f,l.turns]),streamingTurns:Z.useMemo(()=>{let e=bz(l.turns,f).streamingTurns;return vz(i.current,e)?i.current:i.current=e},[f,l.turns])}},Sz=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},Cz=(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(Sz(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(Sz(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},wz=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=Be(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:RL({...e,parts:r})},Tz=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=wz(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=wz(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=ZR(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}},Ez=[],Dz=(e,t)=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===t}),Oz=(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}},kz=(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(Dz(s,r));continue}n.has(o.info.id)&&a.push(Oz(e,t))}return a};function Az(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=>Dz(e,a)),tail:Ez};let e=r[0].turnId,t=n.findIndex(t=>t.turnId===e);return t<0?{history:n.map(e=>Dz(e,a)),tail:r.map(e=>Dz(e,a))}:{history:n.slice(0,t).map(e=>Dz(e,a)),tail:n.slice(t).map(e=>Dz(e,a))}}let o=kz(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:Ez};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]:Ez}}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=>Dz(e,a))}:{history:o.slice(0,c),tail:o.slice(c)}}var jz=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},Mz=2,Nz=2,Pz=e=>Math.min(Math.max(0,e),Mz),Fz=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+Nz),Iz=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(GA.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Lz=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(qu.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Rz=12,zz=16,Bz=new Map,Vz=e=>{let t=Bz.get(e);if(t)return Bz.delete(e),Bz.set(e,t),t},Hz=(e,t)=>{if(t.size!==0)for(Bz.delete(e),Bz.set(e,t);Bz.size>zz;){let e=Bz.keys().next().value;if(typeof e!=`string`)break;Bz.delete(e)}},Uz=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Rz)),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},Wz=(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},Gz=({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}},Kz=e=>{let{visible:t,preload:n}=Gz(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},qz=(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},Jz=`data-markdown-ready`,Yz=`data-markdown-hydration`,Xz=`data-markdown-pin-reveal`,Zz=e=>[...Uz(e.entryKeys,{seedCount:e.seedCount,restore:e.restore})],Qz=e=>e.reason===`jump-to-latest`||!e.alreadyRevealedForScope,$z=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},eB=(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,!$z(e)))return!1}return r},tB=(e,t)=>{if(e){if(t){e.style.visibility=`hidden`,e.setAttribute(Xz,`pending`);return}e.style.removeProperty(`visibility`),e.setAttribute(Xz,`ready`)}},nB=(e,t)=>t?{...e,visibility:`hidden`}:e,rB=({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}eB(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:[Jz,Yz,`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())}},iB=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}},aB=(e,t)=>{let n=e.resizeItem.bind(e),r=!1,i=iB(e=>{let i=()=>{for(let[t,r]of e)n(t,r)};r?i():((0,Dp.flushSync)(i),t?.())});return e.resizeItem=(e,t)=>{i.enqueue(e,t)},()=>{r=!0,e.resizeItem=n,i.flush()}},oB=(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},sB=({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&&(Qz({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 Gn(()=>{if(!i||!l){tB(n,!1);return}if(tB(n,!0),n)return rB({root:n,relevantKeys:p,onReady:m})},[i,l,n,p,o]),i&&l},cB=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},lB=(e,t)=>e,uB=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:tL(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),dB=()=>xo()?5:12,fB=16,pB=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),mB=320,hB=168,gB=8,_B=16,vB=6,yB=12,bB=4,xB=1,SB=2,CB=6,wB=4,TB=()=>xo()?_B:gB,EB=30,DB=180,OB=80,kB=160,AB=90,jB=(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},MB=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(pB(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)}}}})(fB),NB=(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})},PB=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),FB=e=>e===`collapsed`?hB:mB,IB=(e,t)=>`${e}::activity:${t}`,LB=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),RB=(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}},zB=(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)},BB=(e,t=0)=>Math.max(e===`collapsed`?yB:vB,Math.max(0,Math.floor(t))),VB=e=>e===`collapsed`?SB:xB,HB=e=>e===`collapsed`?wB:CB,UB=(e,t)=>{e.current=t},WB=(e,t)=>MB.read(e,t),GB=(e,t,n)=>{!n||t.length===0||MB.write(e,t,n.takeSnapshot())},KB=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},qB=(e,t)=>{if(KB(e)!==`system`)return e;let n=XB(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},JB=e=>!e||KB(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),YB=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},XB=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},ZB=(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},QB=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,$B=(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&&!ZB(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}},eV=(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}},tV=(e,t)=>{let n=$B(t,e)??eV(t,e);if(!n)return null;let r=QB(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}},nV=e=>{let t=e,n=t.state?.metadata,r=$O(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?rk(i)??null:null},rV=e=>{if(KB(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:nV(e.parts[0])}},iV=(e,t)=>{if(!t)return e;let n=ek(e.parts,t);return n===e.parts?e:{...e,parts:n}},aV=(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}},oV=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,sV=Z.memo(e=>{let t=(0,Q.c)(23),{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,reviewTransferDirection:h}=e,g=Ab(),_;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==g?(_=n.sourceSessionID?{...g,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...g.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:g,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=g,t[3]=_):_=t[3];let v=_,y;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]!==h||t[15]!==m||t[16]!==a||t[17]!==s?(y=(0,$.jsx)(kL,{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,reviewTransferDirection:h}),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]=h,t[15]=m,t[16]=a,t[17]=s,t[18]=y):y=t[18];let b=y,x;return t[19]!==b||t[20]!==v||t[21]!==g?(x=v===g?b:(0,$.jsx)(kb.Provider,{value:v,children:b}),t[19]=b,t[20]=v,t[21]=g,t[22]=x):x=t[22],x},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return nA(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&rA(e.previousMessage,t.previousMessage)&&rA(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&dA(n,r,e.message.info.id,KB(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.reviewTransferDirection===t.reviewTransferDirection&&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});sV.displayName=`MessageRow`;var cV=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,reviewTransferDirection:h})=>{let g=K(e=>e.showReasoningTraces),_=Z.useMemo(()=>!!e.userMessage||e.assistantMessages.some(e=>!!e.info.error||wD(e.parts,{includeReasoning:g}).some(e=>e.type===`tool`||e.type===`file`||(e.type===`text`||e.type===`reasoning`)&&xD(e).trim().length>0)),[e.userMessage,e.assistantMessages,g]),v=Z.useRef(null);v.current===e.turnId&&!t&&e.completionDisposition!==`active`?v.current=null:t&&n&&(v.current=e.turnId);let y=v.current===e.turnId,b=Z.useRef({turnId:e.turnId,shown:!1});b.current.turnId!==e.turnId&&(b.current={turnId:e.turnId,shown:!1});let x=i.get(e.turnId),S=rL({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,durationMs:e.durationMs}),C=uB({expansionDisposition:oL({isLastTurn:t,turnCompletionDisposition:e.completionDisposition,headerPresentationDisposition:S.completionDisposition,hasAssistantMessages:e.assistantMessages.length>0}),activityRenderMode:r,isLastTurn:t,isActivelyProcessing:t&&n,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),w=x?.automatic&&e.completionDisposition===`normal`&&e.hasConfirmedFinalBody&&!(t&&n),T=x&&!w?x.isExpanded:C,E=J(()=>{a(e.turnId,T)}),D=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]),O=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(!cB(n))return n.info.id}return null},[p,e.assistantMessages]),k=Z.useMemo(()=>o===`live`?e.assistantMessages:lB(e.assistantMessages,O),[o,O,e.assistantMessages]),A=Z.useMemo(()=>{let e=new Map;return k.forEach((t,n)=>{e.set(t.info.id,n)}),e},[k]),j=Z.useMemo(()=>new Set(k.map(e=>e.info.id)),[k]),M=Z.useMemo(()=>e.headerMessageId&&A.has(e.headerMessageId)?e.headerMessageId:k[0]?.info.id,[e.headerMessageId,A,k]),N=Z.useMemo(()=>o===`sorted`?j.size===e.assistantMessages.length?e.activityParts:e.activityParts.filter(e=>j.has(e.messageId)):e.activityParts,[o,j,e.activityParts,e.assistantMessages.length]),P=Z.useMemo(()=>o!==`sorted`||j.size===e.assistantMessages.length?e.activitySegments:e.activitySegments.map(e=>{let t=e.parts.filter(e=>j.has(e.messageId));if(t.length===0)return null;let n=j.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null}).filter(e=>e!==null),[o,j,e.activitySegments,e.assistantMessages.length]),F=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:IP(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:N,activityGroupSegments:P,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,N,P]),I=jz((r,i)=>{let a=KB(r)===`user`,u=D.lookup.get(r.info.id),p=A.get(r.info.id)??-1,g=p>=0,_=p===0,v=p===k.length-1,y=!!M&&r.info.id===M,b=P.some(e=>e.anchorMessageId===r.info.id),x=o===`sorted`?g:y||_||v,S=k[0]?.info.id??e.headerMessageId,C=a?void 0:g?_?e.userMessage:void 0:typeof u==`number`&&u>0?D.ordered[u-1]:void 0,w=rL({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,durationMs:e.durationMs}),T=g?{turnId:e.turnId,activityOwnerMessageId:M,isFirstAssistantInTurn:_,isLastAssistantInTurn:v,isLatestTurn:t,isWorking:(t||e.completionDisposition===`active`)&&n&&(o===`sorted`?b:r.info.id===O),isTurnSettled:iL({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,hasConfirmedSettledAssistant:e.hasConfirmedFinalBody}),hasTools:e.hasTools,hasReasoning:e.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:e.activityPresentationKind,durationMs:w.durationMs,assistantTps:F.assistantTps,...x?{summaryBody:F.summaryBody,activityParts:F.activityParts,activityGroupSegments:F.activityGroupSegments,headerMessageId:F.headerMessageId,diffStats:F.diffStats,changedFiles:F.changedFiles,userMessageCreatedAt:F.userMessageCreatedAt,userMessageVariant:F.userMessageVariant,isGroupExpanded:i,toggleGroup:E}:{}}:void 0;return(0,$.jsx)(sV,{message:r,previousMessage:C,nextMessage:void 0,turnGroupingContext:T,assistantHeaderMessageId:S,turnOwnsAssistantHeader:g,isInActiveTurn:!!O&&r.info.id===O,activeStreamingPhase:r.info.id===O?m:null,reviewTransferDirection:h,animateUserOnMount:d(r),onUserAnimationConsumed:f,onContentChange:s,animationHandlers:c(r.info.id),scrollToBottom:l},r.info.id)}),L=Z.useMemo(()=>k===e.assistantMessages?e:{...e,assistantMessages:k},[e,k]),R=Z.useMemo(()=>((eL({isLastTurn:t,sessionIsWorking:n,hasAssistantMessages:e.assistantMessages.length>0,activityPresentationKind:e.activityPresentationKind,hasActiveStreamingMessage:!!p})||e.assistantMessages.length>0)&&(b.current.shown=!0),!b.current.shown||e.activityPresentationKind===`compaction`?null:e.userMessage?$I(XI(e.userMessage.info)):null),[p,t,n,e.activityPresentationKind,e.assistantMessages.length,e.userMessage]);if(!_){let t=e.assistantMessages.find(e=>e.info.id===p);return t?(0,$.jsx)(lV,{message:t,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,shouldAnimateUserMessage:d,onUserAnimationConsumed:f,activeStreamingMessageId:p,activeStreamingPhase:m,reviewTransferDirection:h}):null}return(0,$.jsx)(bR,{turn:L,showSessionError:t,activityExpanded:T,onToggleActivity:E,showCompactionStatus:oV({chatRenderMode:o,activityPresentationKind:e.activityPresentationKind,hasVisibleActivitySegments:P.length>0,hasAssistantMessages:e.assistantMessages.length>0,completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n}),pendingAssistantHeader:R,assistantHeaderMessage:k[0],assistantHeaderIsInActiveTurn:k[0]?.info.id===O,preserveActiveTurnGap:y,stickyUserHeader:u,renderMessage:I})});cV.displayName=`TurnBlock`;var lV=Z.memo(e=>{let t=(0,Q.c)(31),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d,reviewTransferDirection:f}=e,{t:p}=Xn();if(rO(n)){let e;t[0]===p?e=t[1]:(e=p(`assistants.conversation.newSessionDivider`),t[0]=p,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]===p?r=t[4]:(r=p(`assistants.conversation.newSessionDivider`),t[3]=p,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 m;t[13]!==n||t[14]!==c?(m=c(n),t[13]=n,t[14]=c,t[15]=m):m=t[15];let h;t[16]!==o||t[17]!==n.info.id?(h=o(n.info.id),t[16]=o,t[17]=n.info.id,t[18]=h):h=t[18];let g=!!u&&n.info.id===u,_=n.info.id===u?d:null,v;return t[19]!==n||t[20]!==i||t[21]!==a||t[22]!==l||t[23]!==r||t[24]!==f||t[25]!==s||t[26]!==m||t[27]!==h||t[28]!==g||t[29]!==_?(v=(0,$.jsx)(sV,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:m,onUserAnimationConsumed:l,onContentChange:a,animationHandlers:h,scrollToBottom:s,isInActiveTurn:g,activeStreamingPhase:_,reviewTransferDirection:f}),t[19]=n,t[20]=i,t[21]=a,t[22]=l,t[23]=r,t[24]=f,t[25]=s,t[26]=m,t[27]=h,t[28]=g,t[29]=_,t[30]=v):v=t[30],v});lV.displayName=`UngroupedMessageRow`;var uV=Z.memo(e=>{let t=(0,Q.c)(27),{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,reviewTransferDirection:_,showLiveStatusRow:v}=e,y=r===void 0||r,b=v!==void 0&&v,x;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]!==_||t[15]!==o||t[16]!==c||t[17]!==p||t[18]!==s||t[19]!==u?(x=n.kind===`ungrouped`?(0,$.jsx)(lV,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_}):(0,$.jsx)(cV,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:c,activityRenderMode:l,turnUiStates:u,onToggleTurnGroup:d,chatRenderMode:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_,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]=_,t[15]=o,t[16]=c,t[17]=p,t[18]=s,t[19]=u,t[20]=x):x=t[20];let S=x,C;t[21]===b?C=t[22]:(C=b?(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(rR,{})}):null,t[21]=b,t[22]=C);let w;return t[23]!==S||t[24]!==y||t[25]!==C?(w=(0,$.jsxs)(Lz,{enabled:y,children:[S,C]}),t[23]=S,t[24]=y,t[25]=C,t[26]=w):w=t[26],w});uV.displayName=`MessageListEntry`;var dV=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,reviewTransferDirection:_})=>{let[v,y]=Z.useState(e),b=n===`tanstack`&&v.length>=dB(),x=Z.useRef(n),S=Z.useRef(null),[C,w]=Z.useReducer(e=>e+1,0);if(!b)S.current=null;else if(x.current===`none`&&b&&S.current===null){let e=r.current,t=i?.current;e&&t&&(S.current=tV(e,t))}let T=Z.useRef(!1),E=Z.useRef(0),D=Z.useRef(null),O=xo();Z.useEffect(()=>{if(!O)return;let e=i?.current;if(!e)return;let t=()=>{T.current=!0},n=()=>{T.current=!1},r=()=>{E.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)}},[O,i]);let k=()=>T.current||performance.now()-E.current<kB,A=v;e===v?D.current!==null&&(D.current=null):O&&jB(v,e)&&k()?D.current===null&&(D.current=performance.now()):(D.current=null,y(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);Vn(()=>{D.current!==null&&(k()||j())},O&&D.current!==null?AB:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=TB(),[F,I]=Z.useState(()=>Pz(P));Z.useEffect(()=>{if(!(!b||F>=P))return Td(()=>{Z.startTransition(()=>{I(e=>Fz(e,P))})})},[F,b,P]);let L=IB(o,d),[R]=Z.useState(()=>b?WB(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=J(e=>{z.current=e,r.current=e}),V=Z.useRef(null),H=Z.useRef(null),U=Z.useRef(new Set),W=Z.useRef(new Set),ee=Z.useRef(t),te=Z.useRef(A),ne=te.current!==A&&jB(te.current,A);if(te.current=A,ee.current!==t||ne){ee.current=t;let e=i?.current,n=z.current??r.current;V.current=e&&n?$B(e,n):null}let re=J(()=>{V.current=null,H.current=null});qn(`wheel`,re,void 0,{passive:!0,capture:!0}),qn(`touchstart`,re,void 0,{passive:!0,capture:!0}),qn(`pointerdown`,re,void 0,{passive:!0,capture:!0}),qn(`click`,re,void 0,{capture:!0}),qn(`keydown`,re,void 0,{capture:!0});let G=J(()=>{let e=H.current??V.current,t=i?.current;if(!e||!t)return;let n=QB(t,e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&de.scrollToOffset(t.scrollTop+r,{behavior:`auto`})}),ie=FB(d),ae=Z.useRef(ie),oe=Z.useRef(d);oe.current!==d&&(oe.current=d,ae.current=ie);let se=Z.useRef(b),ce=Z.useRef(new Map),le=Z.useRef(void 0);if(Z.useLayoutEffect(()=>{b||(le.current=void 0)}),b&&le.current===void 0){if(!R){let e=ce.current;e.clear(),r?.current?.querySelectorAll(`[data-turn-entry]`).forEach(t=>{let n=t.dataset.turnEntry;n&&e.set(n,t.getBoundingClientRect().height)})}le.current=R??NB(N,ce.current,ae.current)}let ue=Z.useMemo(()=>b?{width:i?.current?.clientWidth??0,height:i?.current?.clientHeight??0}:void 0,[b,i]),de=sf({count:A.length,enabled:b,initialRect:ue,getScrollElement:()=>i?.current??null,estimateSize:()=>ae.current,overscan:F,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)=>{zB(z.current,n.getTotalSize()),of(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:OB,initialOffset:()=>{if(se.current){let e=ae.current,t=(le.current??[]).reduce((t,n)=>t+(n.index<A.length?n.size-e:0),A.length*e);return Math.max(0,t-(i?.current?.clientHeight??0))}let e=S.current,t=e&&le.current?.find(t=>t.key===e.entryKey);return(i?.current?.scrollTop??0)+(t&&e?t.start-e.entryStart:0)},initialMeasurementsCache:le.current});Z.useEffect(()=>{let e=i?.current;!b||!e||de.scrollElement===e||(de.scrollOffset=e.scrollTop,de._willUpdate(),de.options.onChange?.(de,!1))}),Gn(()=>{if(!b)return;de.shouldAdjustScrollPositionOnItemSizeChange=oB;let e=aB(de,fe);return()=>{e();for(let e of W.current)e.style.removeProperty(`opacity`);W.current.clear(),U.current.clear(),H.current=null}},[b,de]);let fe=J(()=>{G();for(let e of W.current)e.style.removeProperty(`opacity`);W.current.clear(),H.current=null}),pe=J(e=>{de.measureElement(e),!(!e||!e.isConnected)&&U.current.add(e)});Gn(()=>{if(!b||U.current.size===0)return;let e=[...U.current].filter(e=>e.isConnected).map(e=>({row:e,index:de.indexFromElement(e),height:e.getBoundingClientRect().height}));U.current.clear();for(let{row:t,index:n,height:r}of e)W.current.add(t),de.resizeItem(n,r)});let me=Z.useRef(null),he=Z.useRef(null);b||(me.current=null);let ge=J(()=>{if(!b)return;let e=z.current??i?.current;if(!e)return;let t=e.offsetWidth;if(!LB(me.current,t)){me.current===null&&t>0&&(me.current=t);return}me.current=t,he.current!==null&&clearTimeout(he.current),he.current=setTimeout(()=>{he.current=null;let e=i?.current,t=z.current;e&&t&&!T.current&&(H.current=$B(e,t));for(let e of de.elementsCache.values())e.isConnected&&U.current.add(e);de.measure()},220)}),_e=b&&typeof ResizeObserver<`u`;Hn(_e?z:null,ge),Hn(_e&&i?i:null,ge),Wn(()=>{he.current!==null&&(clearTimeout(he.current),he.current=null)}),Gn(()=>{b&&ge()},[b]),Gn(()=>{if(x.current=b?`tanstack`:`none`,!b){S.current=null;return}let e=S.current,t=i?.current;if(!e||!t)return;let n=QB(t,e.messageId);if(n){let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&de.scrollToOffset(t.scrollTop+r,{behavior:`auto`}),S.current=null;return}let r=N.indexOf(e.entryKey);if(r<0||e.attempts>=1){S.current=null;return}e.attempts+=1,de.scrollToIndex(r,{align:`start`}),w()},[n,N,b,de,C]);let ve=de.getVirtualItems(),ye=ve.map(e=>e.index),[be,xe]=Z.useState(()=>Uz(N,{seedCount:BB(d),restore:Vz(L)})),Se=Wz(be,N);for(let e of ce.current.keys())Se.has(e)||(Se===be&&(Se=new Set(Se)),Se.add(e));Se!==be&&xe(Se);let Ce=Z.useRef(Se);Ce.current=Se;let we=Z.useRef(null);de.scrollDirection&&(we.current=de.scrollDirection);let Te=de.range?.startIndex??ve[0]?.index??Math.max(0,A.length-1),Ee=de.range?.endIndex??ve[ve.length-1]?.index??Math.max(0,A.length-1),De=de.isScrolling,Oe=Math.max(0,Ee-Te+1),ke=Kz({entryKeys:N,mountedIndexes:ye,visibleStartIndex:Te,visibleEndIndex:Ee,scrollDirection:we.current,preloadEntries:BB(d,Oe),hydratedKeys:Se,allowVisibleRelease:!De,preloadReleaseLimit:De?VB(d):bB,visibleReleaseLimit:De?0:HB(d)}),Ae=ke.join(`\0`),je=Z.useRef(ke);je.current=ke,Z.useEffect(()=>{if(!(!b||!Ae))return Td(()=>{Z.startTransition(()=>{xe(e=>{let t=null;for(let n of je.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[b,Ae]),Z.useEffect(()=>{xe(e=>qz(e,N))},[N]),Z.useEffect(()=>{if(b)return a?.(de),()=>{GB(L,M.current.map(e=>e.key),de),Hz(L,Ce.current),a?.(null)}},[b,de,L]);let Me=jz((e,t=!0)=>(0,$.jsx)(uV,{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,reviewTransferDirection:_},e.key));if(!b)return(0,$.jsx)(`div`,{ref:B,className:`relative w-full`,children:(0,$.jsx)(`div`,{children:A.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`yuri-chat-message-layout-boundary`,children:Me(e)},e.key))})});if(n===`tanstack`){let e=RB(ve[0]?.start??0,ve[ve.length-1]?.end??0,de.getTotalSize());return(0,$.jsx)(`div`,{ref:B,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:ve.map(e=>{let t=A[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:pe,"data-turn-entry":t.key,style:{opacity:de.itemSizeCache.has(t.key)?void 0:0},className:`yuri-chat-message-layout-boundary`,children:Me(t,Se.has(t.key))},t.key):null})})})}return null});dV.displayName=`StaticHistoryList`;var fV=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)(uV,{...e})}),t[0]=e,t[1]=n),n});fV.displayName=`TailEntry`;var pV=e=>{let t=(0,Q.c)(43),{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,reviewTransferDirection:y}=e,b=n.length-1,x=Bo(_??``,r,i??void 0),S;bb0:{let e=n[b];if(!e){S=void 0;break bb0}let r=p===`sorted`,i;t[0]!==_||t[1]!==x||t[2]!==e||t[3]!==m||t[4]!==r?(i=Tz(e,{activeStreamingMessageId:_,liveParts:x,showTextJustificationActivity:r,showTurnChangedFiles:m}),t[0]=_,t[1]=x,t[2]=e,t[3]=m,t[4]=r,t[5]=i):i=t[5],S=i}let C=S,w;if(t[6]!==_||t[7]!==v||t[8]!==u||t[9]!==p||t[10]!==n||t[11]!==o||t[12]!==C||t[13]!==b||t[14]!==a||t[15]!==f||t[16]!==g||t[17]!==y||t[18]!==s||t[19]!==l||t[20]!==h||t[21]!==c||t[22]!==d){let e;t[24]!==_||t[25]!==v||t[26]!==u||t[27]!==p||t[28]!==o||t[29]!==C||t[30]!==b||t[31]!==a||t[32]!==f||t[33]!==g||t[34]!==y||t[35]!==s||t[36]!==l||t[37]!==h||t[38]!==c||t[39]!==d?(e=(e,t)=>{let n=t===b;return(0,$.jsx)(fV,{entry:n?C??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,reviewTransferDirection:y},e.key)},t[24]=_,t[25]=v,t[26]=u,t[27]=p,t[28]=o,t[29]=C,t[30]=b,t[31]=a,t[32]=f,t[33]=g,t[34]=y,t[35]=s,t[36]=l,t[37]=h,t[38]=c,t[39]=d,t[40]=e):e=t[40],w=n.map(e),t[6]=_,t[7]=v,t[8]=u,t[9]=p,t[10]=n,t[11]=o,t[12]=C,t[13]=b,t[14]=a,t[15]=f,t[16]=g,t[17]=y,t[18]=s,t[19]=l,t[20]=h,t[21]=c,t[22]=d,t[23]=w}else w=t[23];let T;return t[41]===w?T=t[42]:(T=(0,$.jsx)($.Fragment,{children:w}),t[41]=w,t[42]=T),T};pV.displayName=`StreamingTailContent`;var mV=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)=>{Ze(`ui.message_list.render`);let{sessionKey:_,virtualizerKey:v}=PB(e,t),y=Z.useMemo(()=>fO(),[_,d]),b=K(e=>e.stickyUserHeader),x=K(e=>e.chatRenderMode),S=K(e=>e.activityRenderMode),C=K(e=>e.showTurnChangedFiles),w=xi(e=>e.reviewTransferBySessionId.get(_)??null),[T,E]=Z.useState(()=>new Map),[D,O]=Z.useState(_);D!==_&&(O(_),E(new Map));let k=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set});Gn(()=>{if(m)return()=>{queueMicrotask(()=>{ua(e)})}},[m,e]);let A=J(c),j=J(()=>{l?.()}),M=J((e,t)=>{E(n=>{let r=new Map(n);return r.set(e,{isExpanded:nL(t)}),r})}),N=Z.useMemo(()=>ae(`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(RL(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&&GI(t.info))continue;let n=qB(t,a);PL(t)&&a.add(t.info.id);let s=i.length>0?i[i.length-1]:void 0;if(JB(s)){let e=rV(n);if(e.hide){i[i.length-1]=iV(s,e.taskSessionId);continue}}if(lL(s)){let e=dL(n,YB(s));if(e.hide){i[i.length-1]=aV(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(()=>ae(`ui.message_list.retry_overlay_ms`,()=>Cz(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}=xz(R,{sessionKey:_,showTextJustificationActivity:x===`sorted`,showTurnChangedFiles:C,hasLiveTail:!0,liveTailActive:z});Gn(()=>{z&&E(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(()=>ae(`ui.message_list.render_entries_ms`,()=>Az({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&&Ze(`ui.message_list.render.streaming`);let te=U,ne=te.length>=dB(),re=Z.useRef(ne);UB(re,ne);let G=ne?`tanstack`:`none`,ie=Z.useRef(null),oe=J(e=>{ie.current=e}),se=Z.useMemo(()=>W.length>0?[...te,...W]:te,[te,W]),[ce,le]=Z.useState(0),[ue,de]=Z.useState(null),fe=IB(v,S),pe=nB(void 0,sB({scopeKey:fe,generation:ce,root:ue,relevantKeys:Z.useMemo(()=>Zz({entryKeys:se.map(e=>e.key),seedCount:BB(S)}),[fe,ce,se.length,se[se.length-1]?.key,S]),enabled:!1,initiallyRevealed:h})),me=J(e=>{s(e)}),he=J(e=>{s(e)}),ge=Z.useMemo(()=>n.filter(e=>KB(e)===`user`).map(e=>e.info.id),[n]),_e=k.current,ve=_e.sessionKey!==e,ye=_e.previousOrder;ve&&(m&&_e.sessionKey!==void 0&&ua(_e.sessionKey),_e.sessionKey=e,_e.previousOrder=ge,_e.animatedIds=new Set),m&&mo({sessionId:e,sessionChanged:ve,previousUserOrder:ye,currentUserOrder:ge,animatedIds:_e.animatedIds}),_e.previousOrder=ge;let be=J(e=>KB(e)===`user`&&k.current.animatedIds.has(e.info.id)),xe=J(e=>{k.current.animatedIds.delete(e)}),Se=Z.useMemo(()=>{let e=new Map;return se.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},[se]),Ce=Z.useMemo(()=>{let e=new Map;return se.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[se]),we=J(e=>{let t=L();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Te=J((e,t=`auto`)=>{if(e<0||e>=te.length||!ne)return!1;let n=ie.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),Ee=J((e,t=`auto`)=>{let n=L();if(!n)return!1;let r=we(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(!g)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Ce.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:Te(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=Se.get(e);return r===void 0?!1:Ee(e,n)||(ee&&r>=te.length?!1:Te(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=we(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>=EB||n>=DB){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:I,isHistoryVirtualized:()=>re.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`||!ZB(n,e,t.top))})??n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!ZB(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||!Se.has(e.messageId))return!1;let n=()=>{let n=we(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(ne&&n){if(n.options.count!==te.length)return!0;n.scrollToOffset(e,{behavior:`auto`})}else t.scrollTop=e}return!0};if(!n()){let t=Se.get(e.messageId);if(typeof t==`number`&&t<te.length)return Te(t,`auto`)}return n()},cancelScroll:()=>{I(),ie.current?.cancelScroll()},scrollToBottom:({behavior:e=`auto`,reveal:t=!0}={})=>(t&&le(e=>e+1),ne&&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,Se,ne,ee,Ce,g]),(0,$.jsx)(pO.Provider,{value:y,children:(0,$.jsx)(`div`,{children:(0,$.jsx)(jd,{disabled:!1,children:(0,$.jsxs)(`div`,{ref:de,className:`relative w-full`,style:pe,children:[(0,$.jsx)(jd,{disabled:ne,children:(0,$.jsx)(Iz,{enabled:!0,children:(0,$.jsx)(dV,{entries:te,historyAnchorToken:p,engine:G,contentRef:P,scrollRef:u,registerTanstackVirtualizer:oe,virtualizerKey:v,onMessageContentChange:me,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,activityRenderMode:S,turnUiStates:T,onToggleTurnGroup:M,chatRenderMode:x,shouldAnimateUserMessage:be,onUserAnimationConsumed:xe,reviewTransferDirection:w},v)})}),(0,$.jsx)(pV,{entries:W,directory:d,sessionId:_,onMessageContentChange:he,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,sessionIsWorking:r,activityRenderMode:S,turnUiStates:T,onToggleTurnGroup:M,chatRenderMode:x,showTurnChangedFiles:C,shouldAnimateUserMessage:be,onUserAnimationConsumed:xe,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:w}),f]})})})})});mV.displayName=`MessageList`;var hV=Z.memo(mV),gV=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},_V=({diff:e,filePath:t})=>{let{currentTheme:n}=fs(),r=Z.useMemo(()=>cf(n),[n]),i=Z.useMemo(()=>Hd(e),[e]),a=hd(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6597
|
+
`)}return ut&&ut.trim().length>0?ut:Na(Be)},[ut,Be,G]),ft=dt.length>0,pt=Z.useCallback(async()=>(await Yn(dt)).ok?(G&&(R(!0),setTimeout(()=>R(!1),2e3)),!0):!1,[G,dt]),mt=J(async()=>{if(!(!se||!e.info.id||V.current)){V.current=`revert`,B(`revert`);try{_.onRevertMessage?await _.onRevertMessage(e.info.id):await w(se,e.info.id,{directory:_.directory??void 0})}catch(e){_.onRevertMessage&&zn.error(p(`chat.revert.toast.failed`),{id:`session-revert-error`,description:e&&typeof e==`object`&&`message`in e?String(e.message):String(e)})}finally{V.current=null,B(null)}}}),ht=J(()=>{if(!se||!e.info.id||V.current)return;let t={info:e.info,parts:e.parts};if(_.onEditMessage){_.onEditMessage(e.info.id,t).catch(()=>{});return}T(se,e.info.id,t).catch(()=>{})}),gt=J(()=>{se&&k(se)}),_t=Z.useCallback(async()=>{if(e.info.id,!se||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!se,hasMessageId:!!e.info.id});return}if(!V.current){V.current=`fork`,B(`fork`);try{await E(se,e.info.id)}finally{V.current=null,B(null)}}},[se,e.info.id,E]),vt=J(t=>{let n=Ue.has(t),r=We.has(t);if(n){te(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),SL(e.info.id,i),i}),r||W(n=>{let r=new Set(n);return r.delete(t),bL(e.info.id,r),r});return}W(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),bL(e.info.id,r),r}),te(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),SL(e.info.id,r),r})}),yt=i??null,bt=Z.useRef(!1),xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1),wt=Z.useRef(!1),Tt=Z.useRef(!1);Z.useEffect(()=>{xt.current=!1,St.current=!1,Ct.current=!1,wt.current=!1,bt.current=!1,Tt.current=!1},[e.info.id]);let Et=Z.useCallback(()=>{G||bt.current||(bt.current=!0,r?.(`structural`))},[G,r]),Dt=K(e=>e.setImagePreviewOpen),Ot=Z.useCallback(e=>{(e.image||e.mermaid||e.video)&&(re(e),Dt(!0))},[Dt]),kt=Z.useCallback(e=>{re(t=>({...t,open:e})),Dt(e)},[Dt]),At=!!OL(e.info,`animationSettled`),jt=it===`streaming`||it===`cooldown`;jt&&(Tt.current=!0);let Mt=Z.useMemo(()=>!G&&ze.some(e=>e.type===`reasoning`),[G,ze]),Nt=Ye&&!At&&!jt&&!Tt.current,Pt=!G&&Ye&&Ve.length>0&&!Je;Z.useEffect(()=>{if(yt?.onStreamingCandidate){if(!Pt){St.current&&=(Mt&&yt?.onReasoningBlock?yt.onReasoningBlock():yt?.onReservationCancelled&&yt.onReservationCancelled(),!1);return}wt.current||(wt.current=!0,yt.onStreamingCandidate(),St.current=!0)}},[yt,Pt,Mt]),Z.useEffect(()=>{yt?.onAnimationStart&&Nt&&(Ct.current||=(yt.onAnimationStart(),!0))},[yt,Nt]),Z.useEffect(()=>{if(G)return;let e=yt?.onAnimatedHeightChange;if(!e||!(Nt||Pt))return;let t=b.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()}},[Nt,G,yt,Pt]);let Ft=Z.useMemo(()=>G?!0:ze.some(e=>e.type===`text`||e.type===`reasoning`?xD(e).trim().length>0:e.type===`tool`||e.type===`file`),[G,ze]),It=!!(a?.activityOwnerMessageId===e.info.id&&((a.activityParts?.length??0)>0||a.hasTools||a.hasReasoning)),Lt=!G&&!ie&&(Le||!c||!!a)&&!lt&&!Ft&&!It,Rt=KI(e.info,p);if(Rt)return(0,$.jsx)(`div`,{ref:S,className:`chat-message-column py-1.5`,id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-restart-notice":``,children:(0,$.jsx)(Uv,{presentation:Rt})});if(Ke||Lt)return null;if(ie)return(0,$.jsx)(`div`,{className:Y(`group w-full`,m?`py-2`:`py-3`),id:`message-${e.info.id}`,"data-message-id":e.info.id,"data-compaction-status":ie.status,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(JI,{part:ie,isMobile:m})})});let zt=!G&&at?m?M?`pt-4`:`pt-0`:`pt-6`:`pt-0`,Bt=uL(e);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`w-full`,!G&&`yuri-message-hover-scope`,G?m?`pt-2`:`pt-6`:zt,G||rt||s?`pb-0`:nt?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,...gO,ref:S,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:G?FD(Be)?(0,$.jsx)(Dd,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{...gO,className:Y(`relative flex`,Bt?`justify-start`:`justify-end`,m?void 0:`yuri-user-shell-hover-scope`),children:(0,$.jsxs)(`div`,{className:Y(Bt?`w-full min-w-0`:`max-w-[85%]`,oe&&!Bt?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:Bt?void 0:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:Bt?`min-w-0 text-left`:`px-3 py-1.5 shadow-none`,"data-user-message-bubble":Bt?void 0:`true`,"data-shell-result":Bt?`true`:void 0,children:(0,$.jsx)(PI,{messageId:e.info.id,parts:Be,sourceParts:ue,isUser:G,isMessageCompleted:Le,messageFinish:Re,messageCreatedAt:Ie??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:ot,expandedTools:U,onToggleTool:vt,onShowPopup:Ot,streamPhase:it,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Et,agentMention:Ge,onEdit:!D&&v.edit?ht:void 0,onRevert:!D&&v.revert?mt:void 0,onFork:!D&&G&&v.fork?_t:void 0,editing:D,editStaged:O,onCancelEdit:O?gt:void 0,pendingMessageAction:z,errorPresentation:lt,userActionsMode:ae?`external-content`:`inline`,stickyUserHeaderEnabled:M&&!Bt})}),ae?(0,$.jsx)(PI,{messageId:e.info.id,parts:Be,sourceParts:ue,isUser:G,isMessageCompleted:Le,messageFinish:Re,messageCreatedAt:Ie??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:ot,expandedTools:U,onToggleTool:vt,onShowPopup:Ot,streamPhase:it,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Et,agentMention:Ge,onEdit:!D&&v.edit?ht:void 0,onRevert:!D&&v.revert?mt:void 0,onFork:!D&&G&&v.fork?_t:void 0,editing:D,editStaged:O,onCancelEdit:O?gt:void 0,pendingMessageAction:z,errorPresentation:lt,userActionsMode:`external-actions`,stickyUserHeaderEnabled:M}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[at&&(0,$.jsx)(yO,{isUser:G,isMobile:m,providerID:je,modelID:Me,agentName:Ae,modelName:Ne,variant:ct}),!Ft&&!It&&!lt&&c&&!Le&&(0,$.jsxs)(`div`,{role:`status`,"aria-label":p(`common.loading`),"data-assistant-content-loading":``,className:`space-y-2 py-2`,children:[(0,$.jsx)(af,{className:`h-3.5 w-2/3`}),(0,$.jsx)(af,{className:`h-3.5 w-1/3`})]}),(0,$.jsx)(PI,{sessionId:e.info.sessionID,messageId:e.info.id,parts:ze,sourceParts:de,isUser:G,isMessageCompleted:Le,messageFinish:Re,messageCompletedAt:Fe??void 0,messageCreatedAt:Ie??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:ot,expandedTools:We,onToggleTool:vt,onShowPopup:Ot,streamPhase:it,allowAnimation:Nt,onContentChange:r,shouldShowHeader:at,hasTextContent:ft,onCopyMessage:pt,copiedMessage:L,onAuxiliaryContentComplete:Et,showReasoningTraces:j,agentMention:Ge,turnGroupingContext:a,errorPresentation:lt,reviewTransferDirection:f})]})})}),ne.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(pL,{popup:ne,onOpenChange:kt,isMobile:m})}):null]})},(e,t)=>nA({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&rA(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&rA(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.reviewTransferDirection===t.reviewTransferDirection&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&dA(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,BI(e.message.info).isUser)),AL=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},jL=e=>{let t=e?.type;return t===`compaction`?!Ee(e):t===`text`&&AL(e).trim()===`/compact`},ML=e=>e?e.some(e=>jL(e)):!1,NL=e=>ML(e.parts),PL=e=>e?ML(e.sourceParts)||ML(e.parts):!1,FL=e=>{if(!NL(e))return e;let t=!1,n=e.parts.map(e=>e?.type!==`compaction`||Ee(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}},IL=e=>{let t=bD(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},LL=new WeakMap,RL=e=>{let t=LL.get(e);if(t)return t;let n=FL(IL(e)),r=n.parts,i=jo(r),a=i===r?n:{...n,parts:i,sourceParts:r};return LL.set(e,a),a},zL={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},BL=[],VL=`\0`,HL=new Set([`edit`,`write`,`apply_patch`]),UL={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`},WL=[`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`],GL=(e,t)=>{let n=UL[_d(e)];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},KL=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)},qL=(e,t)=>t(WL[KL(e)%WL.length]??`chat.assistantStatus.working`),JL=(e,t,n)=>{let r,i;if(!xa(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??eR(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=_d(tR(n));HL.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=$L(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=eR(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?GL(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):qL(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},YL=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(VL),XL=e=>{let[t,n,r=`working`,i]=e.split(VL);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},ZL=e=>e.type===`reasoning`,QL=e=>e.type===`text`,$L=e=>{if(QL(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},eR=e=>(QL(e)||ZL(e),e.time),tR=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function nR(e,t){let{t:n}=Xn(),r=wa(e=>e.currentSessionId),i=wa(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Rr(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=Ca(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`&&!ue(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=Bo(f??``,o??void 0,a??void 0),g=Bo(m??``,o??void 0,a??void 0),_=!!m&&ML(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`:bN(d.finish,h,d.error))),x=Z.useMemo(()=>{let e=`${a??``}:${f??``}`;return YL(JL(f&&!d.error&&d.index>p.index?h:BL,e,n))},[a,f,d.error,d.index,p.index,h,n]),S=Da(a??``,o??void 0),C=Fa(a??``,o??void 0),w=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),T=wa(w),{phase:E,isWorking:D}=wx(a,o??void 0),O=!!(d.error&&d.index>p.index),k=vo(a??``,o??void 0),A=k?.type===`retry`?k.attempt:void 0,j=k?.type===`retry`?k.next:void 0,M=Z.useMemo(()=>XL(x),[x]),N=Z.useMemo(()=>{let e=!!(T&&!T.acknowledged);return{wasAborted:e,abortActive:e}},[T]),P=Z.useMemo(()=>{if(s)return{...zL,isRecovering:!0,canAbort:D};if(O&&E!==`retry`)return{...zL,isTurnSettled:!0,canAbort:D};if(N.wasAborted)return{...zL,wasAborted:!0,abortActive:N.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(b)return{...zL,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 rR=Z.memo(()=>{let e=(0,Q.c)(15),t=Ab(),n=wa(iR),r=wa(aR),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(oR),l=wa(sR),{working:u}=nR(i,a),d=Ko(cR),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)(Fb,{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],_});rR.displayName=`StatusRowContainer`;function iR(e){return e.currentSessionId}function aR(e){return e.currentSessionDirectory}function oR(e){return e.abortPromptSessionId}function sR(e){return e.abortPromptExpiresAt}function cR(e){return e.currentAgentName}var lR=(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},uR=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},dR=Z.memo(e=>{let t=(0,Q.c)(37),{assistantMessage:n,userMessage:r,pendingPresentation:i,assistantIsInActiveTurn:a,isMobile:o}=e,s=Ko(fR),c=Ko(H(pR)),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}=wy(H(u)),p;t[3]===r?p=t[4]:(p=r?XI(r.info):null,t[3]=r,t[4]=p);let m=p,h;t[5]===n?h=t[6]:(h=n?XI(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?lR(n.info,`mode`)??lR(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=ur(b),S=!n||a,C;t[18]!==g||t[19]!==c||t[20]!==x||t[21]!==S||t[22]!==m?(C=QI({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=uR(y),O=uR(T),k=uR(E),A,j;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,j=e?.models?.find(e=>e.id===k),t[24]=i?.modelName,t[25]=s,t[26]=k,t[27]=O,t[28]=A,t[29]=j}else A=t[28],j=t[29];let M=j,N=M?.variants&&Object.keys(M.variants).length>0?m?.variant??i?.variant:void 0,P=O??null,F=k??null,I=D??void 0,L;return t[30]!==o||t[31]!==A||t[32]!==P||t[33]!==F||t[34]!==I||t[35]!==N?(L=(0,$.jsx)(yO,{isUser:!1,isMobile:o,providerID:P,modelID:F,agentName:I,modelName:A,variant:N}),t[30]=o,t[31]=A,t[32]=P,t[33]=F,t[34]=I,t[35]=N,t[36]=L):L=t[36],L});function fR(e){return e.providers}function pR(e){return{providerId:e.currentProviderId,modelId:e.currentModelId}}var mR=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(hR)),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 hR(e){return e.info.id}var gR=e=>{let t=(0,Q.c)(13),{sessionId:n,directory:r,hasInlineError:i,fallbackHeader:a}=e,o=i!==void 0&&i,{t:s}=Xn(),c=Yr(n),l=Do(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),Rr(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=WI(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)(Uv,{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},_R=new Set,vR=()=>{},yR=()=>{},bR=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=K(xR),y=Ab(),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&&uL(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)(dR,{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)(qF,{parts:[],isExpanded:i,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof b==`number`?b:void 0,onToggle:u,isMobile:v,expandedTools:_R,onToggleTool:vR,onShowPopup:yR,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)(mR,{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)(gR,{sessionId:x.info.sessionID,directory:x.sourceDirectory??y.directory,hasInlineError:!!n.assistantMessages.at(-1)?.info.error,fallbackHeader:!w&&!m&&!s?(0,$.jsx)(dR,{userMessage:n.userMessage,pendingPresentation:$I(XI(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`,...gO,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 xR(e){return e.isMobile}var SR=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,CR=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},wR=e=>{let t=e.text;if(typeof t==`string`&&SD(t))return t;let n=e.content;if(typeof n==`string`&&SD(n))return n},TR=(e,t,n,r)=>({id:SR(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:CR(n)}),ER=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`&&wR(e)&&(i=!0)})});let a=e.assistantMessages.at(-1),o=a?yN(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`?wR(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={...TR(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`&&!GI(t.message.info)&&!ID(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}},DR=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}},OR=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},kR=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(_N(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!vN(t))continue;let r=OR(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:SR(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=OR(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:SR(n.info.id,t,e)}}}return{}},AR=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}},jR=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},MR=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},NR=e=>e.info.nativeType===`synthetic`,PR=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},FR=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},IR=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},LR=e=>{let t=e.info.time?.streamed;return typeof t==`number`&&Number.isFinite(t)?t:void 0},RR=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},zR=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},BR=(e,t)=>{let n=MR(e);return{messageId:e.info.id,role:n,parentMessageId:PR(e),message:e,order:t}},VR=(e,t)=>{let n=e?FR(e):void 0,r,i,a,o=!1;t.forEach(e=>{let t=IR(e);typeof t==`number`?r=Math.max(r??0,t):o=!0;let n=LR(e);typeof n==`number`&&(i=Math.max(i??0,n)),e.parts.forEach(e=>{let t=RR(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}},HR=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`||gN(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 IR(t)!=`number`)return`active`;return`active`},UR=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return bN(n.finish,t.parts,n.error)},WR=e=>PL(e)?`compaction`:`default`,GR={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},KR=(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},qR=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&KR(e.messages,t.messages),JR=(e,t)=>{e.summary=kR(e.assistantMessages),e.summaryText=e.summary.text??(e.userMessage?zR(e.userMessage):void 0),e.diffStats=e.userMessage?AR(e.userMessage):void 0,e.changedFiles=t.showTurnChangedFiles&&e.userMessage?jR(e.userMessage):void 0,e.completionDisposition=HR(e.assistantMessages),e.hasConfirmedFinalBody=UR(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(Ee);r?.reason===`auto`&&r.status!==`failed`&&(e.completionDisposition=`active`,e.hasConfirmedFinalBody=!1);break}e.activityPresentationKind=e.userMessage?WR(e.userMessage):`default`;let n=ER({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=VR(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},YR=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>JR(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&&qR(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,JR(e,t))});return r&&i?n.turns:a},XR=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},ZR=(e,t)=>{let n={...GR,...t},r=[],i=new Map,a=new Map,o=new Set;e.forEach((e,t)=>{let n=MR(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&&!PR(e);if(n!==`user`&&!s)return;if(r.length>0&&NR(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?[]:[BR(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=MR(e),r=i.get(e.info.id);r&&(s=r);let c=a.get(e.info.id);if(c){c.messages.push(BR(e,t));return}if(n!==`assistant`)return;let l=PR(e),u=l?i.get(l):s;u&&(u.assistantMessages.push(e),u.assistantMessageIds.push(e.info.id),u.messages.push(BR(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=DR(XR(YR(r,n))),u=new Set;return e.forEach(e=>{o.has(e.info.id)||MR(e)===`assistant`&&PR(e)||u.add(e.info.id)}),{...l,ungroupedMessageIds:u}},QR=30,$R=4,ez=4,tz=33554432,nz=8388608,rz=new Map,iz=new Map,az=0,oz=new WeakMap,sz=1,cz=()=>p()?$R:xo()?ez:QR,lz=()=>p()||xo()?nz:tz,uz=(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},dz=e=>{rz.delete(e);let t=iz.get(e)??0;iz.delete(e),az=Math.max(0,az-t)},fz=e=>{let t=oz.get(e);if(t!==void 0)return t;let n=sz;return sz+=1,oz.set(e,n),n},pz=e=>e.map(e=>`${fz(e.info)}:${fz(e.parts)}:${e.parts.map(e=>fz(e)).join(`,`)}`).join(`;`),mz=(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,pz(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},hz=e=>{let t=rz.get(e);return t&&(rz.delete(e),rz.set(e,t)),t},gz=(e,t)=>{dz(e);let n=cz(),r=lz(),i=uz(e,t);if(!(i>r)){for(;rz.size>=n||az+i>r;){let e=rz.keys().next().value;if(typeof e!=`string`)break;dz(e)}rz.set(e,t),iz.set(e,i),az+=i}},_z=[],vz=(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},yz=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},bz=(e,t)=>t===null?{staticTurns:e,streamingTurns:_z}:{staticTurns:t===0?_z:e.slice(0,t),streamingTurns:e.slice(t)},xz=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(_z),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=_z,a.current=null);let l=Z.useMemo(()=>{let r=mz(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=hz(r);return i&&(!n.current||i===n.current)?(n.current=i,i):ae(`ui.turns.projection_ms`,()=>{let i=ZR(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,gz(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=yz({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=bz(l.turns,f).staticTurns;return vz(r.current,e)?r.current:r.current=e},[f,l.turns]),streamingTurns:Z.useMemo(()=>{let e=bz(l.turns,f).streamingTurns;return vz(i.current,e)?i.current:i.current=e},[f,l.turns])}},Sz=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},Cz=(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(Sz(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(Sz(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},wz=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=Be(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:RL({...e,parts:r})},Tz=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=wz(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=wz(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=ZR(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}},Ez=[],Dz=(e,t)=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===t}),Oz=(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}},kz=(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(Dz(s,r));continue}n.has(o.info.id)&&a.push(Oz(e,t))}return a};function Az(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=>Dz(e,a)),tail:Ez};let e=r[0].turnId,t=n.findIndex(t=>t.turnId===e);return t<0?{history:n.map(e=>Dz(e,a)),tail:r.map(e=>Dz(e,a))}:{history:n.slice(0,t).map(e=>Dz(e,a)),tail:n.slice(t).map(e=>Dz(e,a))}}let o=kz(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:Ez};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]:Ez}}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=>Dz(e,a))}:{history:o.slice(0,c),tail:o.slice(c)}}var jz=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},Mz=2,Nz=2,Pz=e=>Math.min(Math.max(0,e),Mz),Fz=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+Nz),Iz=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(GA.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Lz=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(qu.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Rz=12,zz=16,Bz=new Map,Vz=e=>{let t=Bz.get(e);if(t)return Bz.delete(e),Bz.set(e,t),t},Hz=(e,t)=>{if(t.size!==0)for(Bz.delete(e),Bz.set(e,t);Bz.size>zz;){let e=Bz.keys().next().value;if(typeof e!=`string`)break;Bz.delete(e)}},Uz=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Rz)),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},Wz=(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},Gz=({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}},Kz=e=>{let{visible:t,preload:n}=Gz(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},qz=(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},Jz=`data-markdown-ready`,Yz=`data-markdown-hydration`,Xz=`data-markdown-pin-reveal`,Zz=e=>[...Uz(e.entryKeys,{seedCount:e.seedCount,restore:e.restore})],Qz=e=>e.reason===`jump-to-latest`||!e.alreadyRevealedForScope,$z=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},eB=(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,!$z(e)))return!1}return r},tB=(e,t)=>{if(e){if(t){e.style.visibility=`hidden`,e.setAttribute(Xz,`pending`);return}e.style.removeProperty(`visibility`),e.setAttribute(Xz,`ready`)}},nB=(e,t)=>t?{...e,visibility:`hidden`}:e,rB=({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}eB(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:[Jz,Yz,`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())}},iB=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}},aB=(e,t)=>{let n=e.resizeItem.bind(e),r=!1,i=iB(e=>{let i=()=>{for(let[t,r]of e)n(t,r)};r?i():((0,Dp.flushSync)(i),t?.())});return e.resizeItem=(e,t)=>{i.enqueue(e,t)},()=>{r=!0,e.resizeItem=n,i.flush()}},oB=(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},sB=({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&&(Qz({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 Gn(()=>{if(!i||!l){tB(n,!1);return}if(tB(n,!0),n)return rB({root:n,relevantKeys:p,onReady:m})},[i,l,n,p,o]),i&&l},cB=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},lB=(e,t)=>e,uB=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:tL(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),dB=()=>xo()?5:12,fB=16,pB=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),mB=320,hB=168,gB=8,_B=16,vB=6,yB=12,bB=4,xB=1,SB=2,CB=6,wB=4,TB=()=>xo()?_B:gB,EB=30,DB=180,OB=80,kB=160,AB=90,jB=(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},MB=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(pB(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)}}}})(fB),NB=(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})},PB=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),FB=e=>e===`collapsed`?hB:mB,IB=(e,t)=>`${e}::activity:${t}`,LB=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),RB=(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}},zB=(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)},BB=(e,t=0)=>Math.max(e===`collapsed`?yB:vB,Math.max(0,Math.floor(t))),VB=e=>e===`collapsed`?SB:xB,HB=e=>e===`collapsed`?wB:CB,UB=(e,t)=>{e.current=t},WB=(e,t)=>MB.read(e,t),GB=(e,t,n)=>{!n||t.length===0||MB.write(e,t,n.takeSnapshot())},KB=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},qB=(e,t)=>{if(KB(e)!==`system`)return e;let n=XB(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},JB=e=>!e||KB(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),YB=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},XB=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},ZB=(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},QB=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,$B=(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&&!ZB(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}},eV=(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}},tV=(e,t)=>{let n=$B(t,e)??eV(t,e);if(!n)return null;let r=QB(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}},nV=e=>{let t=e,n=t.state?.metadata,r=$O(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?rk(i)??null:null},rV=e=>{if(KB(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:nV(e.parts[0])}},iV=(e,t)=>{if(!t)return e;let n=ek(e.parts,t);return n===e.parts?e:{...e,parts:n}},aV=(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}},oV=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,sV=Z.memo(e=>{let t=(0,Q.c)(23),{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,reviewTransferDirection:h}=e,g=Ab(),_;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==g?(_=n.sourceSessionID?{...g,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...g.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:g,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=g,t[3]=_):_=t[3];let v=_,y;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]!==h||t[15]!==m||t[16]!==a||t[17]!==s?(y=(0,$.jsx)(kL,{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,reviewTransferDirection:h}),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]=h,t[15]=m,t[16]=a,t[17]=s,t[18]=y):y=t[18];let b=y,x;return t[19]!==b||t[20]!==v||t[21]!==g?(x=v===g?b:(0,$.jsx)(kb.Provider,{value:v,children:b}),t[19]=b,t[20]=v,t[21]=g,t[22]=x):x=t[22],x},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return nA(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&rA(e.previousMessage,t.previousMessage)&&rA(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&dA(n,r,e.message.info.id,KB(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.turnOwnsAssistantHeader===t.turnOwnsAssistantHeader&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.reviewTransferDirection===t.reviewTransferDirection&&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});sV.displayName=`MessageRow`;var cV=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,reviewTransferDirection:h})=>{let g=K(e=>e.showReasoningTraces),_=Z.useMemo(()=>!!e.userMessage||e.assistantMessages.some(e=>!!e.info.error||wD(e.parts,{includeReasoning:g}).some(e=>e.type===`tool`||e.type===`file`||(e.type===`text`||e.type===`reasoning`)&&xD(e).trim().length>0)),[e.userMessage,e.assistantMessages,g]),v=Z.useRef(null);v.current===e.turnId&&!t&&e.completionDisposition!==`active`?v.current=null:t&&n&&(v.current=e.turnId);let y=v.current===e.turnId,b=Z.useRef({turnId:e.turnId,shown:!1});b.current.turnId!==e.turnId&&(b.current={turnId:e.turnId,shown:!1});let x=i.get(e.turnId),S=rL({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,durationMs:e.durationMs}),C=uB({expansionDisposition:oL({isLastTurn:t,turnCompletionDisposition:e.completionDisposition,headerPresentationDisposition:S.completionDisposition,hasAssistantMessages:e.assistantMessages.length>0}),activityRenderMode:r,isLastTurn:t,isActivelyProcessing:t&&n,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),w=x?.automatic&&e.completionDisposition===`normal`&&e.hasConfirmedFinalBody&&!(t&&n),T=x&&!w?x.isExpanded:C,E=J(()=>{a(e.turnId,T)}),D=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]),O=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(!cB(n))return n.info.id}return null},[p,e.assistantMessages]),k=Z.useMemo(()=>o===`live`?e.assistantMessages:lB(e.assistantMessages,O),[o,O,e.assistantMessages]),A=Z.useMemo(()=>{let e=new Map;return k.forEach((t,n)=>{e.set(t.info.id,n)}),e},[k]),j=Z.useMemo(()=>new Set(k.map(e=>e.info.id)),[k]),M=Z.useMemo(()=>e.headerMessageId&&A.has(e.headerMessageId)?e.headerMessageId:k[0]?.info.id,[e.headerMessageId,A,k]),N=Z.useMemo(()=>o===`sorted`?j.size===e.assistantMessages.length?e.activityParts:e.activityParts.filter(e=>j.has(e.messageId)):e.activityParts,[o,j,e.activityParts,e.assistantMessages.length]),P=Z.useMemo(()=>o!==`sorted`||j.size===e.assistantMessages.length?e.activitySegments:e.activitySegments.map(e=>{let t=e.parts.filter(e=>j.has(e.messageId));if(t.length===0)return null;let n=j.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null}).filter(e=>e!==null),[o,j,e.activitySegments,e.assistantMessages.length]),F=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:IP(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:N,activityGroupSegments:P,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,N,P]),I=jz((r,i)=>{let a=KB(r)===`user`,u=D.lookup.get(r.info.id),p=A.get(r.info.id)??-1,g=p>=0,_=p===0,v=p===k.length-1,y=!!M&&r.info.id===M,b=P.some(e=>e.anchorMessageId===r.info.id),x=o===`sorted`?g:y||_||v,S=k[0]?.info.id??e.headerMessageId,C=a?void 0:g?_?e.userMessage:void 0:typeof u==`number`&&u>0?D.ordered[u-1]:void 0,w=rL({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,durationMs:e.durationMs}),T=g?{turnId:e.turnId,activityOwnerMessageId:M,isFirstAssistantInTurn:_,isLastAssistantInTurn:v,isLatestTurn:t,isWorking:(t||e.completionDisposition===`active`)&&n&&(o===`sorted`?b:r.info.id===O),isTurnSettled:iL({completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n,hasConfirmedSettledAssistant:e.hasConfirmedFinalBody}),hasTools:e.hasTools,hasReasoning:e.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:e.activityPresentationKind,durationMs:w.durationMs,assistantTps:F.assistantTps,...x?{summaryBody:F.summaryBody,activityParts:F.activityParts,activityGroupSegments:F.activityGroupSegments,headerMessageId:F.headerMessageId,diffStats:F.diffStats,changedFiles:F.changedFiles,userMessageCreatedAt:F.userMessageCreatedAt,userMessageVariant:F.userMessageVariant,isGroupExpanded:i,toggleGroup:E}:{}}:void 0;return(0,$.jsx)(sV,{message:r,previousMessage:C,nextMessage:void 0,turnGroupingContext:T,assistantHeaderMessageId:S,turnOwnsAssistantHeader:g,isInActiveTurn:!!O&&r.info.id===O,activeStreamingPhase:r.info.id===O?m:null,reviewTransferDirection:h,animateUserOnMount:d(r),onUserAnimationConsumed:f,onContentChange:s,animationHandlers:c(r.info.id),scrollToBottom:l},r.info.id)}),L=Z.useMemo(()=>k===e.assistantMessages?e:{...e,assistantMessages:k},[e,k]),R=Z.useMemo(()=>((eL({isLastTurn:t,sessionIsWorking:n,hasAssistantMessages:e.assistantMessages.length>0,activityPresentationKind:e.activityPresentationKind,hasActiveStreamingMessage:!!p})||e.assistantMessages.length>0)&&(b.current.shown=!0),!b.current.shown||e.activityPresentationKind===`compaction`?null:e.userMessage?$I(XI(e.userMessage.info)):null),[p,t,n,e.activityPresentationKind,e.assistantMessages.length,e.userMessage]);if(!_){let t=e.assistantMessages.find(e=>e.info.id===p);return t?(0,$.jsx)(lV,{message:t,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,shouldAnimateUserMessage:d,onUserAnimationConsumed:f,activeStreamingMessageId:p,activeStreamingPhase:m,reviewTransferDirection:h}):null}return(0,$.jsx)(bR,{turn:L,showSessionError:t,activityExpanded:T,onToggleActivity:E,showCompactionStatus:oV({chatRenderMode:o,activityPresentationKind:e.activityPresentationKind,hasVisibleActivitySegments:P.length>0,hasAssistantMessages:e.assistantMessages.length>0,completionDisposition:e.completionDisposition,isLastTurn:t,sessionIsWorking:n}),pendingAssistantHeader:R,assistantHeaderMessage:k[0],assistantHeaderIsInActiveTurn:k[0]?.info.id===O,preserveActiveTurnGap:y,stickyUserHeader:u,renderMessage:I})});cV.displayName=`TurnBlock`;var lV=Z.memo(e=>{let t=(0,Q.c)(31),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d,reviewTransferDirection:f}=e,{t:p}=Xn();if(rO(n)){let e;t[0]===p?e=t[1]:(e=p(`assistants.conversation.newSessionDivider`),t[0]=p,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]===p?r=t[4]:(r=p(`assistants.conversation.newSessionDivider`),t[3]=p,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 m;t[13]!==n||t[14]!==c?(m=c(n),t[13]=n,t[14]=c,t[15]=m):m=t[15];let h;t[16]!==o||t[17]!==n.info.id?(h=o(n.info.id),t[16]=o,t[17]=n.info.id,t[18]=h):h=t[18];let g=!!u&&n.info.id===u,_=n.info.id===u?d:null,v;return t[19]!==n||t[20]!==i||t[21]!==a||t[22]!==l||t[23]!==r||t[24]!==f||t[25]!==s||t[26]!==m||t[27]!==h||t[28]!==g||t[29]!==_?(v=(0,$.jsx)(sV,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:m,onUserAnimationConsumed:l,onContentChange:a,animationHandlers:h,scrollToBottom:s,isInActiveTurn:g,activeStreamingPhase:_,reviewTransferDirection:f}),t[19]=n,t[20]=i,t[21]=a,t[22]=l,t[23]=r,t[24]=f,t[25]=s,t[26]=m,t[27]=h,t[28]=g,t[29]=_,t[30]=v):v=t[30],v});lV.displayName=`UngroupedMessageRow`;var uV=Z.memo(e=>{let t=(0,Q.c)(27),{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,reviewTransferDirection:_,showLiveStatusRow:v}=e,y=r===void 0||r,b=v!==void 0&&v,x;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]!==_||t[15]!==o||t[16]!==c||t[17]!==p||t[18]!==s||t[19]!==u?(x=n.kind===`ungrouped`?(0,$.jsx)(lV,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:i,getAnimationHandlers:a,scrollToBottom:o,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_}):(0,$.jsx)(cV,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:c,activityRenderMode:l,turnUiStates:u,onToggleTurnGroup:d,chatRenderMode:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_,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]=_,t[15]=o,t[16]=c,t[17]=p,t[18]=s,t[19]=u,t[20]=x):x=t[20];let S=x,C;t[21]===b?C=t[22]:(C=b?(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(rR,{})}):null,t[21]=b,t[22]=C);let w;return t[23]!==S||t[24]!==y||t[25]!==C?(w=(0,$.jsxs)(Lz,{enabled:y,children:[S,C]}),t[23]=S,t[24]=y,t[25]=C,t[26]=w):w=t[26],w});uV.displayName=`MessageListEntry`;var dV=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,reviewTransferDirection:_})=>{let[v,y]=Z.useState(e),b=n===`tanstack`&&v.length>=dB(),x=Z.useRef(n),S=Z.useRef(null),[C,w]=Z.useReducer(e=>e+1,0);if(!b)S.current=null;else if(x.current===`none`&&b&&S.current===null){let e=r.current,t=i?.current;e&&t&&(S.current=tV(e,t))}let T=Z.useRef(!1),E=Z.useRef(0),D=Z.useRef(null),O=xo();Z.useEffect(()=>{if(!O)return;let e=i?.current;if(!e)return;let t=()=>{T.current=!0},n=()=>{T.current=!1},r=()=>{E.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)}},[O,i]);let k=()=>T.current||performance.now()-E.current<kB,A=v;e===v?D.current!==null&&(D.current=null):O&&jB(v,e)&&k()?D.current===null&&(D.current=performance.now()):(D.current=null,y(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);Vn(()=>{D.current!==null&&(k()||j())},O&&D.current!==null?AB:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=TB(),[F,I]=Z.useState(()=>Pz(P));Z.useEffect(()=>{if(!(!b||F>=P))return Td(()=>{Z.startTransition(()=>{I(e=>Fz(e,P))})})},[F,b,P]);let L=IB(o,d),[R]=Z.useState(()=>b?WB(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=J(e=>{z.current=e,r.current=e}),V=Z.useRef(null),H=Z.useRef(null),U=Z.useRef(new Set),W=Z.useRef(new Set),ee=Z.useRef(t),te=Z.useRef(A),ne=te.current!==A&&jB(te.current,A);if(te.current=A,ee.current!==t||ne){ee.current=t;let e=i?.current,n=z.current??r.current;V.current=e&&n?$B(e,n):null}let re=J(()=>{V.current=null,H.current=null});qn(`wheel`,re,void 0,{passive:!0,capture:!0}),qn(`touchstart`,re,void 0,{passive:!0,capture:!0}),qn(`pointerdown`,re,void 0,{passive:!0,capture:!0}),qn(`click`,re,void 0,{capture:!0}),qn(`keydown`,re,void 0,{capture:!0});let G=J(()=>{let e=H.current??V.current,t=i?.current;if(!e||!t)return;let n=QB(t,e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&de.scrollToOffset(t.scrollTop+r,{behavior:`auto`})}),ie=FB(d),ae=Z.useRef(ie),oe=Z.useRef(d);oe.current!==d&&(oe.current=d,ae.current=ie);let se=Z.useRef(b),ce=Z.useRef(new Map),le=Z.useRef(void 0);if(Z.useLayoutEffect(()=>{b||(le.current=void 0)}),b&&le.current===void 0){if(!R){let e=ce.current;e.clear(),r?.current?.querySelectorAll(`[data-turn-entry]`).forEach(t=>{let n=t.dataset.turnEntry;n&&e.set(n,t.getBoundingClientRect().height)})}le.current=R??NB(N,ce.current,ae.current)}let ue=Z.useMemo(()=>b?{width:i?.current?.clientWidth??0,height:i?.current?.clientHeight??0}:void 0,[b,i]),de=sf({count:A.length,enabled:b,initialRect:ue,getScrollElement:()=>i?.current??null,estimateSize:()=>ae.current,overscan:F,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)=>{zB(z.current,n.getTotalSize()),of(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:OB,initialOffset:()=>{if(se.current){let e=ae.current,t=(le.current??[]).reduce((t,n)=>t+(n.index<A.length?n.size-e:0),A.length*e);return Math.max(0,t-(i?.current?.clientHeight??0))}let e=S.current,t=e&&le.current?.find(t=>t.key===e.entryKey);return(i?.current?.scrollTop??0)+(t&&e?t.start-e.entryStart:0)},initialMeasurementsCache:le.current});Z.useEffect(()=>{let e=i?.current;!b||!e||de.scrollElement===e||(de.scrollOffset=e.scrollTop,de._willUpdate(),de.options.onChange?.(de,!1))}),Gn(()=>{if(!b)return;de.shouldAdjustScrollPositionOnItemSizeChange=oB;let e=aB(de,fe);return()=>{e();for(let e of W.current)e.style.removeProperty(`opacity`);W.current.clear(),U.current.clear(),H.current=null}},[b,de]);let fe=J(()=>{G();for(let e of W.current)e.style.removeProperty(`opacity`);W.current.clear(),H.current=null}),pe=J(e=>{de.measureElement(e),!(!e||!e.isConnected)&&U.current.add(e)});Gn(()=>{if(!b||U.current.size===0)return;let e=[...U.current].filter(e=>e.isConnected).map(e=>({row:e,index:de.indexFromElement(e),height:e.getBoundingClientRect().height}));U.current.clear();for(let{row:t,index:n,height:r}of e)W.current.add(t),de.resizeItem(n,r)});let me=Z.useRef(null),he=Z.useRef(null);b||(me.current=null);let ge=J(()=>{if(!b)return;let e=z.current??i?.current;if(!e)return;let t=e.offsetWidth;if(!LB(me.current,t)){me.current===null&&t>0&&(me.current=t);return}me.current=t,he.current!==null&&clearTimeout(he.current),he.current=setTimeout(()=>{he.current=null;let e=i?.current,t=z.current;e&&t&&!T.current&&(H.current=$B(e,t));for(let e of de.elementsCache.values())e.isConnected&&U.current.add(e);de.measure()},220)}),_e=b&&typeof ResizeObserver<`u`;Hn(_e?z:null,ge),Hn(_e&&i?i:null,ge),Wn(()=>{he.current!==null&&(clearTimeout(he.current),he.current=null)}),Gn(()=>{b&&ge()},[b]),Gn(()=>{if(x.current=b?`tanstack`:`none`,!b){S.current=null;return}let e=S.current,t=i?.current;if(!e||!t)return;let n=QB(t,e.messageId);if(n){let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(r)>.5&&de.scrollToOffset(t.scrollTop+r,{behavior:`auto`}),S.current=null;return}let r=N.indexOf(e.entryKey);if(r<0||e.attempts>=1){S.current=null;return}e.attempts+=1,de.scrollToIndex(r,{align:`start`}),w()},[n,N,b,de,C]);let ve=de.getVirtualItems(),ye=ve.map(e=>e.index),[be,xe]=Z.useState(()=>Uz(N,{seedCount:BB(d),restore:Vz(L)})),Se=Wz(be,N);for(let e of ce.current.keys())Se.has(e)||(Se===be&&(Se=new Set(Se)),Se.add(e));Se!==be&&xe(Se);let Ce=Z.useRef(Se);Ce.current=Se;let we=Z.useRef(null);de.scrollDirection&&(we.current=de.scrollDirection);let Te=de.range?.startIndex??ve[0]?.index??Math.max(0,A.length-1),Ee=de.range?.endIndex??ve[ve.length-1]?.index??Math.max(0,A.length-1),De=de.isScrolling,Oe=Math.max(0,Ee-Te+1),ke=Kz({entryKeys:N,mountedIndexes:ye,visibleStartIndex:Te,visibleEndIndex:Ee,scrollDirection:we.current,preloadEntries:BB(d,Oe),hydratedKeys:Se,allowVisibleRelease:!De,preloadReleaseLimit:De?VB(d):bB,visibleReleaseLimit:De?0:HB(d)}),Ae=ke.join(`\0`),je=Z.useRef(ke);je.current=ke,Z.useEffect(()=>{if(!(!b||!Ae))return Td(()=>{Z.startTransition(()=>{xe(e=>{let t=null;for(let n of je.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[b,Ae]),Z.useEffect(()=>{xe(e=>qz(e,N))},[N]),Z.useEffect(()=>{if(b)return a?.(de),()=>{GB(L,M.current.map(e=>e.key),de),Hz(L,Ce.current),a?.(null)}},[b,de,L]);let Me=jz((e,t=!0)=>(0,$.jsx)(uV,{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,reviewTransferDirection:_},e.key));if(!b)return(0,$.jsx)(`div`,{ref:B,className:`relative w-full`,children:(0,$.jsx)(`div`,{children:A.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`yuri-chat-message-layout-boundary`,children:Me(e)},e.key))})});if(n===`tanstack`){let e=RB(ve[0]?.start??0,ve[ve.length-1]?.end??0,de.getTotalSize());return(0,$.jsx)(`div`,{ref:B,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:ve.map(e=>{let t=A[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:pe,"data-turn-entry":t.key,style:{opacity:de.itemSizeCache.has(t.key)?void 0:0},className:`yuri-chat-message-layout-boundary`,children:Me(t,Se.has(t.key))},t.key):null})})})}return null});dV.displayName=`StaticHistoryList`;var fV=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)(uV,{...e})}),t[0]=e,t[1]=n),n});fV.displayName=`TailEntry`;var pV=e=>{let t=(0,Q.c)(43),{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,reviewTransferDirection:y}=e,b=n.length-1,x=Bo(_??``,r,i??void 0),S;bb0:{let e=n[b];if(!e){S=void 0;break bb0}let r=p===`sorted`,i;t[0]!==_||t[1]!==x||t[2]!==e||t[3]!==m||t[4]!==r?(i=Tz(e,{activeStreamingMessageId:_,liveParts:x,showTextJustificationActivity:r,showTurnChangedFiles:m}),t[0]=_,t[1]=x,t[2]=e,t[3]=m,t[4]=r,t[5]=i):i=t[5],S=i}let C=S,w;if(t[6]!==_||t[7]!==v||t[8]!==u||t[9]!==p||t[10]!==n||t[11]!==o||t[12]!==C||t[13]!==b||t[14]!==a||t[15]!==f||t[16]!==g||t[17]!==y||t[18]!==s||t[19]!==l||t[20]!==h||t[21]!==c||t[22]!==d){let e;t[24]!==_||t[25]!==v||t[26]!==u||t[27]!==p||t[28]!==o||t[29]!==C||t[30]!==b||t[31]!==a||t[32]!==f||t[33]!==g||t[34]!==y||t[35]!==s||t[36]!==l||t[37]!==h||t[38]!==c||t[39]!==d?(e=(e,t)=>{let n=t===b;return(0,$.jsx)(fV,{entry:n?C??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,reviewTransferDirection:y},e.key)},t[24]=_,t[25]=v,t[26]=u,t[27]=p,t[28]=o,t[29]=C,t[30]=b,t[31]=a,t[32]=f,t[33]=g,t[34]=y,t[35]=s,t[36]=l,t[37]=h,t[38]=c,t[39]=d,t[40]=e):e=t[40],w=n.map(e),t[6]=_,t[7]=v,t[8]=u,t[9]=p,t[10]=n,t[11]=o,t[12]=C,t[13]=b,t[14]=a,t[15]=f,t[16]=g,t[17]=y,t[18]=s,t[19]=l,t[20]=h,t[21]=c,t[22]=d,t[23]=w}else w=t[23];let T;return t[41]===w?T=t[42]:(T=(0,$.jsx)($.Fragment,{children:w}),t[41]=w,t[42]=T),T};pV.displayName=`StreamingTailContent`;var mV=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)=>{Ze(`ui.message_list.render`);let{sessionKey:_,virtualizerKey:v}=PB(e,t),y=Z.useMemo(()=>fO(),[_,d]),b=K(e=>e.stickyUserHeader),x=K(e=>e.chatRenderMode),S=K(e=>e.activityRenderMode),C=K(e=>e.showTurnChangedFiles),w=xi(e=>e.reviewTransferBySessionId.get(_)??null),[T,E]=Z.useState(()=>new Map),[D,O]=Z.useState(_);D!==_&&(O(_),E(new Map));let k=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set});Gn(()=>{if(m)return()=>{queueMicrotask(()=>{ua(e)})}},[m,e]);let A=J(c),j=J(()=>{l?.()}),M=J((e,t)=>{E(n=>{let r=new Map(n);return r.set(e,{isExpanded:nL(t)}),r})}),N=Z.useMemo(()=>ae(`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(RL(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&&GI(t.info))continue;let n=qB(t,a);PL(t)&&a.add(t.info.id);let s=i.length>0?i[i.length-1]:void 0;if(JB(s)){let e=rV(n);if(e.hide){i[i.length-1]=iV(s,e.taskSessionId);continue}}if(lL(s)){let e=dL(n,YB(s));if(e.hide){i[i.length-1]=aV(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(()=>ae(`ui.message_list.retry_overlay_ms`,()=>Cz(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}=xz(R,{sessionKey:_,showTextJustificationActivity:x===`sorted`,showTurnChangedFiles:C,hasLiveTail:!0,liveTailActive:z});Gn(()=>{z&&E(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(()=>ae(`ui.message_list.render_entries_ms`,()=>Az({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&&Ze(`ui.message_list.render.streaming`);let te=U,ne=te.length>=dB(),re=Z.useRef(ne);UB(re,ne);let G=ne?`tanstack`:`none`,ie=Z.useRef(null),oe=J(e=>{ie.current=e}),se=Z.useMemo(()=>W.length>0?[...te,...W]:te,[te,W]),[ce,le]=Z.useState(0),[ue,de]=Z.useState(null),fe=IB(v,S),pe=nB(void 0,sB({scopeKey:fe,generation:ce,root:ue,relevantKeys:Z.useMemo(()=>Zz({entryKeys:se.map(e=>e.key),seedCount:BB(S)}),[fe,ce,se.length,se[se.length-1]?.key,S]),enabled:!1,initiallyRevealed:h})),me=J(e=>{s(e)}),he=J(e=>{s(e)}),ge=Z.useMemo(()=>n.filter(e=>KB(e)===`user`).map(e=>e.info.id),[n]),_e=k.current,ve=_e.sessionKey!==e,ye=_e.previousOrder;ve&&(m&&_e.sessionKey!==void 0&&ua(_e.sessionKey),_e.sessionKey=e,_e.previousOrder=ge,_e.animatedIds=new Set),m&&mo({sessionId:e,sessionChanged:ve,previousUserOrder:ye,currentUserOrder:ge,animatedIds:_e.animatedIds}),_e.previousOrder=ge;let be=J(e=>KB(e)===`user`&&k.current.animatedIds.has(e.info.id)),xe=J(e=>{k.current.animatedIds.delete(e)}),Se=Z.useMemo(()=>{let e=new Map;return se.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},[se]),Ce=Z.useMemo(()=>{let e=new Map;return se.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[se]),we=J(e=>{let t=L();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Te=J((e,t=`auto`)=>{if(e<0||e>=te.length||!ne)return!1;let n=ie.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),Ee=J((e,t=`auto`)=>{let n=L();if(!n)return!1;let r=we(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(!g)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Ce.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:Te(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=Se.get(e);return r===void 0?!1:Ee(e,n)||(ee&&r>=te.length?!1:Te(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=we(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>=EB||n>=DB){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:I,isHistoryVirtualized:()=>re.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`||!ZB(n,e,t.top))})??n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!ZB(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||!Se.has(e.messageId))return!1;let n=()=>{let n=we(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(ne&&n){if(n.options.count!==te.length)return!0;n.scrollToOffset(e,{behavior:`auto`})}else t.scrollTop=e}return!0};if(!n()){let t=Se.get(e.messageId);if(typeof t==`number`&&t<te.length)return Te(t,`auto`)}return n()},cancelScroll:()=>{I(),ie.current?.cancelScroll()},scrollToBottom:({behavior:e=`auto`,reveal:t=!0}={})=>(t&&le(e=>e+1),ne&&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,Se,ne,ee,Ce,g]),(0,$.jsx)(pO.Provider,{value:y,children:(0,$.jsx)(`div`,{children:(0,$.jsx)(jd,{disabled:!1,children:(0,$.jsxs)(`div`,{ref:de,className:`relative w-full`,style:pe,children:[(0,$.jsx)(jd,{disabled:ne,children:(0,$.jsx)(Iz,{enabled:!0,children:(0,$.jsx)(dV,{entries:te,historyAnchorToken:p,engine:G,contentRef:P,scrollRef:u,registerTanstackVirtualizer:oe,virtualizerKey:v,onMessageContentChange:me,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,activityRenderMode:S,turnUiStates:T,onToggleTurnGroup:M,chatRenderMode:x,shouldAnimateUserMessage:be,onUserAnimationConsumed:xe,reviewTransferDirection:w},v)})}),(0,$.jsx)(pV,{entries:W,directory:d,sessionId:_,onMessageContentChange:he,getAnimationHandlers:A,scrollToBottom:j,stickyUserHeader:b,sessionIsWorking:r,activityRenderMode:S,turnUiStates:T,onToggleTurnGroup:M,chatRenderMode:x,showTurnChangedFiles:C,shouldAnimateUserMessage:be,onUserAnimationConsumed:xe,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:w}),f]})})})})});mV.displayName=`MessageList`;var hV=Z.memo(mV),gV=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},_V=({diff:e,filePath:t})=>{let{currentTheme:n}=fs(),r=Z.useMemo(()=>cf(n),[n]),i=Z.useMemo(()=>Hd(e),[e]),a=hd(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6598
6598
|
`),[i]),s=Zd(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)(gV,{content:e.content,html:n})})]},t)})})]},n))})},vV=e=>{let t=(0,Q.c)(21),{content:n,filePath:r}=e,{currentTheme:i}=fs(),a;t[0]===i?a=t[1]:(a=cf(i),t[0]=i,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=n.split(`
|
|
6599
6599
|
`),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=hd(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=Zd(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)(gV,{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},yV=new Set([`id`,`identifier`,`title`,`name`]),bV=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xV=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),SV=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},CV=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},wV=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?`${xV(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)(wV,{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(bV(n)){let e;t[18]===n?e=t[19]:(e=SV(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(EV),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${xV(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)(wV,{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?xV(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`&&CV(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:xV(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});wV.displayName=`JsonSummaryValue`;var TV=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)(wV,{value:n,depth:0})}),t[0]=n,t[1]=r),r});TV.displayName=`JsonSummaryView`;function EV(e){let[t]=e;return!yV.has(t)}function DV(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 OV={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`},kV={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},AV=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})},jV=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},MV=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,NV=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)(TV,{data:n})}),t[0]=n,t[1]=r),r},PV=({permission:e,onResponse:t})=>{let{t:n}=Xn(),r=K(e=>e.isMobile),[i,a]=Z.useState(!1),[o,s]=Z.useState(!1),c=zo,l=Uo(),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=jV(p),y=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[MV(e),t]));return(0,$.jsx)(DV,{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:[AV(p),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] text-muted-foreground font-medium`,children:v})]})]}),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid w-full grid-cols-1 gap-1.5 sm:flex sm:items-center sm:flex-wrap`,children:[(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>f(`once`),disabled:i,className:`min-h-9 min-w-0 w-full gap-1.5 px-2 !text-xs leading-4 text-foreground sm:w-auto`,children:[(0,$.jsx)(X,{name:`check`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.allowOnce`)})]}),(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>f(`always`),disabled:i,className:`min-h-9 min-w-0 w-full gap-1.5 px-2 !text-xs leading-4 text-foreground sm:w-auto`,children:[(0,$.jsx)(X,{name:`arrow-right`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.alwaysAgree`)})]}),(0,$.jsxs)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>f(`reject`),disabled:i,className:`min-h-9 min-w-0 w-full gap-1.5 px-2 !text-xs leading-4 text-[var(--status-error)] sm:w-auto`,children:[(0,$.jsx)(X,{name:`close`,className:`size-3.5 shrink-0 sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionToast.actions.deny`)})]})]}),i?(0,$.jsx)(`div`,{className:`flex justify-center w-full py-1 sm:w-auto sm:ml-auto typography-meta text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})}):null]}),children:(0,$.jsxs)(`div`,{className:`[&_.typography-meta]:!text-xs [&_.typography-micro]:!text-[0.6875rem]`,children:[e.patterns.length>0&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:n(`chat.permissionCard.patterns`)}),(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border/20 bg-muted/15`,children:e.patterns.map((e,t)=>(0,$.jsx)(`code`,{className:Y(`block break-all px-2 py-1.5 text-xs leading-4 sm:text-[length:var(--text-meta)]`,t>0&&`border-t border-border/15`),children:e},`${e}-${t}`))})]}),(()=>{if(m===`bash`||m===`shell`||m===`shell_command`){let e=h(`command`)||h(`cmd`)||h(`script`),t=h(`description`),r=h(`cwd`)||h(`working_directory`)||h(`directory`)||h(`path`),i=g(`timeout`);return(0,$.jsxs)($.Fragment,{children:[t&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:t}),r&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.workingDirectory`)}),` `,(0,$.jsx)(`code`,{className:`px-1 py-0.5 bg-muted/30 rounded`,children:r})]}),i&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.timeout`)}),` `,i,`ms`]}),e&&(0,$.jsx)(`div`,{children:(0,$.jsx)(Ud,{language:`bash`,code:e,style:OV,codeStyle:kV.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)(Xu,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(_V,{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)(Xu,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(vV,{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)(Xu,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(NV,{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)(Xu,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(NV,{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)(Xu,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(NV,{data:y})})]})})()]})})};function FV(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(`
|
|
6600
6600
|
`).trimEnd()}function IV(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 LV=200;function RV(e){return Math.min(Math.max(e,40),LV)}var zV=`summary`,BV=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=RV(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}),VV=({question:e})=>{let{t}=Xn(),n=ri(e),r=Ea,i=ho,a=K(e=>e.isMobile),o=Uo(),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=Br(e=>e.drafts[l]?.activeTab??`0`),d=e=>Ui(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),_=Br(e=>mr(e,l).selectedOptions),v=Br(e=>mr(e,l).customMode),y=Br(e=>mr(e,l).customTextFilled),b=Z.useMemo(()=>e.questions??[],[e.questions]),x=u===zV,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:zV,label:t(`chat.questionCard.summaryTab`)}),e},[b,t]),E=e=>{if(v[e])return(as(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=(as(l).customText[t]??``).trim();e.push(n?[n]:[]);continue}e.push(_[t]??[])}return e},P=J(e=>{C&&Ui(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(()=>{Ui(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;Ui(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),Ai(i),g(!0)}catch(e){Sa(e)?await n.submissionClaimed(i):Mo(e)?(Ai(i),ji.info(t(`chat.questionCard.noLongerPending`)),g(!0)):ji.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),R=J(e=>{vl(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),Ai(r),g(!0)}catch(e){Sa(e)?await n.submissionClaimed(r):Mo(e)?(Ai(r),ji.info(t(`chat.questionCard.noLongerPending`)),g(!0)):ji.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{p(!1)}}),B=J(async()=>{let n=FV(e);if((await Yn(n)).ok){ji.success(t(`chat.questionCard.copiedMarkdown`));return}ji.error(t(`chat.questionCard.copyFailed`))}),V=J(async()=>{let n=IV(e);if((await Yn(n)).ok){ji.success(t(`chat.questionCard.copiedJson`));return}ji.error(t(`chat.questionCard.copyFailed`))});return h||b.length===0?null:(0,$.jsxs)(DV,{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)(Gr,{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===zV,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)(BV,{value:as(l).customText[S]??``,onValueChange:I,placeholder:t(`chat.questionCard.yourAnswer`),disabled:m,onKeyDown:R})}):null]})]}):null]})};function HV(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 UV=({form:e,directory:t})=>{let{t:n}=Xn(),r=K(e=>e.isMobile),[i,a]=Z.useState(!1),[o,s]=Z.useState(null),[c,l]=Z.useState(()=>{let t={};for(let n of e.fields){let e=HV(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 hi({sessionID:e.sessionID,formID:e.id,answer:c,directory:t}),Dr.getState().remove(e.sessionID,e.id)}catch{s(`reply`)}finally{a(!1)}}}),f=J(async()=>{if(!i){s(null),a(!0);try{await Sr({sessionID:e.sessionID,formID:e.id,directory:t}),Dr.getState().remove(e.sessionID,e.id)}catch{s(`cancel`)}finally{a(!1)}}});return(0,$.jsxs)(DV,{mobile:r,header:(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:e.title||n(`chat.form.title`)}),footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(er,{type:`button`,variant:`default`,size:`sm`,onClick:()=>void d(),disabled:i,children:n(`chat.form.reply`)}),(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void f(),disabled:i,children:n(`chat.form.cancel`)})]}),children:[(0,$.jsx)(`div`,{className:`space-y-2`,children:e.fields.map(e=>{if(e.type===`external`)return(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`block typography-meta text-primary underline`,children:e.title||e.url},e.key);if(e.type===`boolean`)return(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-meta`,children:[(0,$.jsx)(Ts,{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)(Ts,{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)(Ks,{type:`number`,value:typeof c[e.key]==`number`?String(c[e.key]):``,onChange:t=>u(e.key,t.target.value===``?``:Number(t.target.value)),disabled:i})]},e.key);let t=e.type===`string`?e.options:void 0;return t&&t.length>0?(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:e.title||e.key}),e.description?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:e.description}):null,(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,role:`group`,"aria-label":e.title||e.key,children:t.map(t=>(0,$.jsx)(er,{type:`button`,variant:`chip`,size:`sm`,"aria-pressed":c[e.key]===t.value,disabled:i,onClick:()=>u(e.key,t.value),children:t.label},t.value))}),e.type===`string`&&e.custom?(0,$.jsx)(Ks,{"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)(Ks,{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 WV(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function GV(e){return typeof e==`string`&&e.length>0?e:void 0}function KV(e){if(!WV(e))return null;let t=GV(e.reason),n=GV(e.provider),r=GV(e.title),i=GV(e.message),a=GV(e.label);return!t||!n||!r||!i||!a?null:{reason:t,provider:n,title:r,message:i,label:a,...GV(e.link)?{link:GV(e.link)}:{}}}function qV(e){return!WV(e)||e.type!==`retry`?!1:KV(e.action)!==null}function JV(e,t){if(!qV(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}:{}}}function YV(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
6601
|
-
`)}function XV(e,t=80){let n=YV(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var ZV=new Set;function QV(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(ZV),a,o;return n[0]!==e||n[1]!==t?(a=()=>{let n=e?.current;if(i(ZV),!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=$V,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 $V(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 eH=160,tH=28,nH=12,rH=6,iH=30,aH=12,oH=18,sH=80,cH=4,lH=10,uH=14,dH=20,fH=48,pH=160,mH=(e,t)=>e.map(e=>{let n=t.get(e)??[],r=YV(n),i=M_(r,{citationIcons:R_(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>eH?`${s.slice(0,eH)}…`:s}}),hH=[1,.6,.35,.15],gH=(e,t,n)=>{let r=n?uH:lH;if(t===null)return r;let i=hH[Math.abs(e-t)]??0;return Math.round(r+(dH-r)*i)};function _H({turnIds:e,previewsByTurnId:t,activeTurnId:n,scrollRef:r,turnByMessageId:i,repliesByTurnId:a,onSelectTurn:o,canLoadEarlier:s,isLoadingOlder:c,onLoadEarlier:l}){let{t:u}=Xn(),d=QV(r,i),f=K(e=>e.isPromptNavigatorPanelOpen),p=K(e=>e.setPromptNavigatorPanelOpen),m=Z.useRef(null),h=Z.useRef(null),[g,_]=Z.useState(null),[v,y]=Z.useState(0),[b,x]=Z.useState(!1);Z.useEffect(()=>{let e=h.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){x(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.left+rH+tH;x(r.left<i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let S=Z.useMemo(()=>mH(e,t),[t,e]),C=Math.min(S.length,iH),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,iH),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,iH),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)/aH),i=Math.min(N.current,iH);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,iH)),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<=oH&&D?i=-1:r>=n.height-oH&&O&&(i=1),I.current=i,i===0){V();return}F.current===null&&(F.current=window.setInterval(H,sH))},[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)},pH)},[ee]);Z.useEffect(()=>()=>{W.current!==null&&window.clearTimeout(W.current)},[]);let ne=Z.useCallback(e=>{ee(),P.current=e.clientY;let t=B(e.clientY);t!==null&&_(Math.min(N.current-1,M.current+t)),U(e.clientY)},[ee,B,U]),re=Z.useCallback(()=>{P.current=null,V(),te()},[te,V]),G=Z.useCallback(()=>{p(!1)},[p]),ie=Z.useCallback(e=>{if(e===null)return;let t=S[e];t&&(o(t.turnId),V(),_(null),G(),m.current?.blur())},[G,o,S,V]),ae=Z.useCallback(e=>{let t=B(e.clientY);t!==null&&ie(Math.min(S.length-1,M.current+t))},[ie,S.length,B]);Z.useEffect(()=>{if(!f)return;let e=m.current;!e||e===document.activeElement||(e.focus(),_(e=>{if(e!==null)return e;let t=j>=0?j:S.length-1;return L(t),t}))},[j,L,f,S.length]),Z.useEffect(()=>()=>{p(!1)},[p]);let oe=Z.useCallback(e=>{if(S.length===0)return;let t=g??(j>=0?j:S.length-1),n=e=>{let t=Math.max(0,Math.min(S.length-1,e));L(t),_(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(S.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),ie(t);return}e.key===`Escape`&&(e.preventDefault(),_(null),G(),m.current?.blur())},[j,G,L,ie,g,S.length]),se=Z.useCallback(()=>{V(),_(null),G()},[G,V]),ce=Z.useRef(null),le=Z.useRef(g);le.current=g;let ue=g!==null,de=Z.useRef(0);Z.useEffect(()=>{let e=ce.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),de.current+=e.deltaY;let t=Math.trunc(de.current/fH);if(t===0)return;de.current-=t*fH;let n=le.current;if(n===null)return;let r=Math.max(0,Math.min(N.current-1,n+t));r!==n&&(L(r),_(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[L,ue]);let fe=g===null?void 0:S[g],pe=fe?a?.get(fe.turnId):void 0,me=Math.max(0,T-cH),he=Math.min(S.length,E+cH),ge=S.slice(me,he),_e=D||O?`linear-gradient(to bottom, ${D?`transparent, black 14%`:`black`}, ${O?`black 86%, transparent`:`black`})`:void 0;return S.length===0?null:(0,$.jsx)(`nav`,{ref:h,"aria-label":u(`chat.promptNavigator.aria`),className:`pointer-events-none absolute left-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-start`,children:[s?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-ml-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,c?`cursor-wait opacity-70`:void 0),"aria-label":A,title:A,disabled:c,onClick:e=>{e.stopPropagation(),c||l()},children:c?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:m,role:`listbox`,tabIndex:-1,"aria-activedescendant":fe?`prompt-rail-tick-${fe.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${b?nH:tH}px`,height:`${C*aH}px`},onMouseMove:ne,onMouseLeave:re,onClick:ae,onKeyDown:oe,onBlur:se,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:_e?{maskImage:_e,WebkitMaskImage:_e}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${T*aH}px)`},children:ge.map((e,t)=>{let n=me+t,r=d.has(e.turnId),i=g===n,a=gH(n,g,r);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":i,"aria-current":r?`true`:void 0,"aria-label":e.preview.trim()||k,className:`pointer-events-none absolute left-1 flex items-center justify-start`,style:{top:`${n*aH}px`,height:`${aH}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)*aH}px`},onMouseEnter:ee,onMouseLeave:te,onMouseMove:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),ie(g)},children:[(0,$.jsx)(`p`,{className:`truncate font-medium leading-relaxed text-[var(--surface-foreground)]`,children:fe.preview||k}),pe?(0,$.jsx)(`p`,{className:`mt-2 line-clamp-4 whitespace-pre-line [overflow-wrap:anywhere] leading-relaxed text-[var(--surface-mutedForeground)]`,children:pe}):null]}):null]})]})})}var vH=100,yH=(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},bH=e=>{let t=e.raf??requestAnimationFrame,n=e.caf??cancelAnimationFrame,r=e.ResizeObserver??globalThis.ResizeObserver,i=e.MutationObserver??globalThis.MutationObserver,a,o,s,c,l,u,d=!0,f=new Map,p=[],m=()=>{c===void 0&&(c=t(()=>{c=void 0,g()}))},h=()=>{let e=a;if(!e){p=[],d=!1;return}let t=e.getBoundingClientRect().top;p=[...f].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),p.sort((e,t)=>e.top-t.top),d=!1},g=()=>{let t=a;if(!t)return;d&&h();let n=yH(p,t.scrollTop+vH);!n||n===u||(u=n,e.onActive(n))},_=()=>{let e=a;if(e){if(clearTimeout(l),l=void 0,o?.disconnect(),o=void 0,r){o=new r(()=>{clearTimeout(l),l=setTimeout(()=>{d=!0,m()},100)}),o.observe(e);for(let e of f.values())o.observe(e)}if(s?.disconnect(),s=void 0,i){s=new i(()=>{d=!0,m()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}d=!0,m()}},v=e=>{a!==e&&(a=e,u=void 0,_())},y=(e,t)=>{let n=f.get(t);n&&n!==e&&o?.unobserve(n),f.set(t,e),o&&o.observe(e),d=!0,m()},b=e=>{let t=f.get(e);t&&(o?.unobserve(t),f.delete(e),d=!0,m())},x=()=>{d=!0,m()},S=()=>{for(let e of f.values())o?.unobserve(e);f.clear(),p=[],u=void 0,d=!0};return{setContainer:v,register:y,unregister:b,onScroll:m,markDirty:x,clear:S,destroy:()=>{c!==void 0&&n(c),c=void 0,clearTimeout(l),l=void 0,S(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>u}},xH=10,SH=`${xH}vh`,CH=`56px`;`${CH}`;var wH=(e,t)=>e?56:t<=0?96:Math.max(48,xH/100*t),TH=(e,t)=>({sessionId:e,viewportKey:t}),EH=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,DH=(e,t)=>EH(e,t),OH=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),kH=150,AH=1500,jH=2,MH=350,NH=600,PH=8e3,FH=24,IH=2,LH=(e,t)=>e<t,RH=()=>typeof performance<`u`?performance.now():Date.now(),zH=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),BH=e=>e.scrollHeight-e.scrollTop-e.clientHeight,VH=e=>BH(zH(e)),HH=e=>e.scrollHeight-e.clientHeight>1,UH=(e,t)=>BH(e)<=wH(t,e.clientHeight),WH=({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(TH(n,r));w.current=TH(n,r);let T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(null),O=Z.useRef(0),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(0),M=Z.useRef(!1),N=Z.useRef(!1),P=Z.useRef(null),F=Z.useRef(0),I=Z.useRef(!1),L=Z.useRef(null),R=Z.useRef(null),z=J(()=>{F.current=RH()+450,R.current=null}),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(0),ee=Z.useRef(!1),te=Z.useRef(null),ne=Z.useRef(null),re=Z.useRef(null),G=hr(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{l.current!==f.current&&(f.current=l.current,d(l.current))});let ie=J(e=>{x.current!==e&&(x.current=e,m(e))}),ae=J(e=>{E.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:RH()},D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{E.current=null,D.current=null},AH)}),oe=J(e=>{let t=E.current;return t?RH()-t.time>AH?(E.current=null,!1):Math.abs(e.scrollTop-t.top)<jH:!1}),se=J(()=>RH()<j.current),ce=J(()=>{V.current=!1,H.current&&=(clearTimeout(H.current),null),U.current&&=(clearTimeout(U.current),null)}),le=J(()=>{H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,ce()},NH)}),ue=J(()=>{let e=l.current;e&&(V.current=!0,W.current=e.scrollHeight,le(),U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{U.current=null,ce()},PH))}),de=J(e=>{let t=l.current;if(!t){g(!1),v(!1);return}let n=e??zH(t),r=HH(n);if(g(r),!r){v(!1);return}let i=x.current===`released`&&!UH(n,S.current);v(i)}),fe=J(()=>{O.current+=1,k.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(k.current),k.current=null),A.current?.(),A.current=null});Z.useEffect(()=>()=>fe(),[u]);let pe=J(()=>{if(!e)return;let n=l.current;if(!n)return;if(fe(),t?.current?.scrollToBottom({behavior:`auto`,reveal:!1})){ae(n),de();return}let r=O.current,i=n.style.overflowX,a=n.style.overflowY,o=n.style.scrollBehavior;n.style.scrollBehavior=`auto`,n.style.overflow=`hidden`,n.scrollTop=n.scrollHeight,n.scrollHeight,n.style.overflowX=i,n.style.overflowY=a,n.style.scrollBehavior=o;let s=()=>{ae(n),n.scrollTop=n.scrollHeight,B.current=n.scrollTop};if(s(),de(),typeof window>`u`)return;let c=0,u=()=>{LH(RH(),F.current)||fe()};n.addEventListener(`touchstart`,u,{passive:!0,once:!0}),A.current=()=>n.removeEventListener(`touchstart`,u);let d=()=>{if(r===O.current){if(VH(n)>IH&&s(),c+=1,c>=FH){k.current=null,A.current?.(),A.current=null,de();return}k.current=window.requestAnimationFrame(d)}};k.current=window.requestAnimationFrame(d)}),me=J(e=>{let n=l.current;if(n&&(ae(n),!t?.current?.scrollToBottom({behavior:e,reveal:!1}))){if(e===`smooth`){n.scrollTo({top:n.scrollHeight,behavior:e});return}n.scrollTop=n.scrollHeight}}),he=J((t,n=`auto`)=>{if(!e)return;let r=l.current;if(t&&x.current!==`following`&&ie(`following`),r&&!(!t&&x.current!==`following`)){if(VH(r)<jH){ae(r);return}me(t?n:`auto`)}}),ge=J(e=>{let t=l.current;if(!t)return;let n=e??zH(t);HH(n)&&x.current!==`released`&&(ie(`released`),de(n))}),_e=J((e=`instant`,n)=>{if(I.current=!1,ee.current=!1,ie(`following`),ce(),fe(),t?.current?.scrollToBottom({behavior:e===`smooth`?`smooth`:`auto`,...n})){let e=l.current;e&&ae(e),de();return}if(e===`instant`){pe();return}fe(),he(!0,`smooth`),de()}),ve=J(()=>{ee.current=!1,he(!0)}),ye=J(()=>{I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ie(`released`),de()}),be=J(()=>{ee.current=!0,ye()}),xe=J(()=>{ee.current=!1}),Se=Z.useRef(c);Se.current=c;let Ce=J(()=>{LH(RH(),F.current)||(I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ge())}),we=J(()=>{F.current=0,Ce(),Se.current?.()}),Te=J(()=>{te.current!==null&&(clearTimeout(te.current),te.current=null);let e=ne.current;if(e){if(!e.identity.sessionId){ne.current=null;return}G(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),ne.current=null}}),Ee=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=OH(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),te.current===null&&(te.current=setTimeout(()=>{te.current=null,Te()},kH))}),De=J(()=>{Te()}),Oe=J(async(e=w.current)=>{if(!e.sessionId||x.current===`released`&&EH(e,T.current))return!1;ee.current=!1;let t=l.current;return t?(re.current=null,ie(`following`),z(),S.current?pe():he(!0),B.current=t.scrollTop,ue(),de(),!1):(re.current=e,ie(`following`),!1)});Z.useEffect(()=>{let e=w.current,t=T.current;EH(e,t)||(Te(),fe(),z(),T.current=e,I.current=!1,L.current=null,E.current=null,B.current=0,ce(),ee.current=!1,ie(`following`),re.current=null,n&&n!==t?.sessionId&&_O.getInstance().recordSessionStart(n))},[n,r]),Z.useEffect(()=>{a&&!ee.current&&x.current===`following`&&he(!0)},[a]),Z.useEffect(()=>{b(p===`following`&&a)},[p,a]),Z.useLayoutEffect(()=>{if(!u)return;let e=re.current;e&&DH(e,w.current)&&Oe(e)},[u,n,r]);let ke=J(()=>{let e=l.current;if(!e)return;let t=zH(e),n=B.current;B.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(de(t),ee.current){Ee();return}if(HH(t)){if(UH(t,S.current)){let e=Math.min(n,Math.max(0,t.scrollHeight-t.clientHeight));if(t.scrollTop<e-.5){Ce(),Ee();return}(x.current===`following`||r&&I.current)&&(ie(`following`),I.current=!1),Ee();return}if(x.current===`following`&&(oe(e)||se()||i)){M.current||he(!1),Ee();return}(x.current===`following`||!r)&&Ce(),Ee()}});Z.useEffect(()=>{!e||!u||(B.current=u.scrollTop)},[u,e]);let Ae=J(e=>{let t=l.current;if(t){if(e.deltaY>0){Ml(t,e.target)||(I.current=!0);return}e.deltaY>=0||Pl(t,e.target)||we()}}),je=J(e=>{I.current=!1;let t=e.touches.item(0);R.current=t?{x:t.clientX,y:t.clientY,dx:0,dy:0}:null}),Me=J(e=>{let t=l.current,n=e.touches.item(0);if(!n){R.current=null;return}let r=R.current;if(!r)return;let i=n.clientY-r.y,a=i*r.dy<0,o=(a?0:r.dx)+n.clientX-r.x,s=(a?0:r.dy)+i;if(R.current={x:n.clientX,y:n.clientY,dx:o,dy:s},!(Math.abs(o)>=Math.abs(s))&&t){if(s<-2){Ml(t,e.target)||(I.current=!0);return}if(!(s<=0)){if(Pl(t,e.target)){R.current.dx=0,R.current.dy=0;return}s<=2||we()}}}),Ne=J(()=>{R.current=null}),Pe=J(e=>{let t=e.target;if(!(e.defaultPrevented||t instanceof HTMLElement&&(t.isContentEditable||t.closest(`input, textarea, select`)))){if(!e.altKey&&!e.ctrlKey&&!e.metaKey&&[`ArrowDown`,`PageDown`,`End`].includes(e.key)){let e=l.current;e&&!Ml(e,t)&&(I.current=!0);return}xl(e)&&we()}}),Fe=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&(F.current=0,Ce(),L.current={id:e.pointerId,y:e.clientY})}),Ie=J(e=>{let t=L.current;!t||t.id!==e.pointerId||(e.clientY!==t.y&&(I.current=e.clientY>t.y),t.y=e.clientY)}),Le=J(()=>{L.current=null}),Re=J(()=>{I.current=!1}),ze=Z.useMemo(()=>()=>void 0,[]),Be=e&&u?u:ze,Ve=Z.useMemo(()=>({passive:!0}),[]);qn(`scroll`,ke,Be,Ve),qn(`scrollend`,Re,Be,Ve),qn(`wheel`,Ae,Be,Ve),qn(`touchstart`,je,Be,Ve),qn(`touchmove`,Me,Be,Ve),qn(`touchend`,Ne,Be,Ve),qn(`touchcancel`,Ne,Be,Ve),qn(`keydown`,Pe,Be),qn(`pointermove`,Ie,e&&typeof window<`u`?window:ze,!0),qn(`pointerup`,Le,e&&typeof window<`u`?window:ze,!0),qn(`pointercancel`,Le,e&&typeof window<`u`?window:ze,!0),qn(`pointerdown`,Fe,e&&typeof window<`u`?window:ze,!0);let He=J(()=>{let e=l.current;if(M.current){de(e?zH(e):void 0);return}if(ee.current){de(e?zH(e):void 0);return}if(!e){de(void 0);return}let t=zH(e);if(!HH(t)){de(t);return}if(de(t),V.current){let n=t.scrollHeight>W.current+1;W.current=t.scrollHeight,BH(t)<=jH?ae(e):he(!0),n&&le();return}if(x.current===`following`){if(BH(t)<=jH){ae(e);return}he(!1)}}),Ue=typeof ResizeObserver<`u`,We=Ue&&e?u:null,Ge=Ue&&e&&u&&u.firstElementChild instanceof Element?u.firstElementChild:null;Hn(We,He),Hn(Ge,He);let Ke=J(()=>{P.current!==null&&(clearTimeout(P.current),P.current=null)}),qe=J(e=>{M.current=!0,typeof e==`number`&&e>0?j.current=RH()+e+MH:j.current=Math.max(j.current,RH()+MH)}),Je=J(e=>{let t=e.detail;if(t){if(t.open===!0){qe(),Ke(),P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},1500);return}Ke(),qe()}}),Ye=J(e=>{let t=e.detail;t&&(Ke(),qe(t.durationMs))}),Xe=J(e=>{let t=e.detail;Ke(),t?.open===!0?(N.current=!0,M.current=!0):(N.current=!1,M.current=!0,P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},MH)),de()}),Ze=e&&typeof window<`u`?window:ze;qn(`yuri:keyboard-intent`,Je,Ze),qn(`yuri:keyboard-anim`,Ye,Ze),qn(`yuri:keyboard-settled`,Xe,Ze),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{Ke(),M.current=!1,N.current=!1}},[e]),Z.useEffect(()=>{e&&de()},[e,i]);let Qe=J(t=>{if(e){if(t===`animation`&&(j.current=RH()+MH),de(),V.current){he(!0),le();return}x.current===`following`&&he(!1)}}),$e=Z.useRef(new Map),et=J(t=>{let n=$e.current.get(t);if(n)return n;let r=()=>{e&&x.current===`following`&&he(!1)},i={onChunk:r,onComplete:()=>{e&&de()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return $e.current.set(t,i),i});Z.useEffect(()=>()=>{D.current&&=(clearTimeout(D.current),null),fe(),ce(),Te(),te.current!==null&&(clearTimeout(te.current),te.current=null)},[]);let tt=J(e=>{s?.(e)}),nt=!!s;return Z.useEffect(()=>{if(!e||!nt)return;let t=u;if(!t)return;let n=null,r=bH({onActive:e=>{e!==n&&(n=e,tt(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,nt]),{scrollRef:l,state:p,isPinned:p===`following`,isOverflowing:h,isFollowingProgrammatically:y,showScrollButton:_,notifyContentChange:Qe,getAnimationHandlers:et,goToBottom:_e,scrollToBottomOnSend:ve,releaseAutoFollow:ye,beginHistoryViewportPreservation:be,endHistoryViewportPreservation:xe,saveSnapshotNow:De,restoreSnapshot:Oe}},GH=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),KH=`data-yuri-timeline-park-end`,qH=e=>{if(!e)return null;let t=e.getAttribute(KH);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},JH=(e,t)=>t!==null&&Number.isFinite(t)?GH({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),YH=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),XH=()=>{let e=document.documentElement;return e.classList.contains(`yuri-keyboard-open`)||e.classList.contains(`yuri-kb-animating`)},ZH=e=>{if(XH()||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)},QH=e=>{let t=Z.useRef($T()),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=_E(e);return i!==t&&(_.current=i,n.current=void 0,r.current=void 0),i},y=J(t=>{let r=e.scopeRef.current;if(!r)return;let i=v(r);n.current=bE(r,t,n.current,i)}),b=J(e=>{let n=_.current,r=v(e);return r!==n&&y(t.current),r}),x=J(e=>{e!==t.current&&(t.current=e,y(e))}),S=J(()=>{if(g(a),t.current.phase!==`snapping`)return;let e=t.current.rest;a.current=window.setTimeout(()=>{a.current=null;let n=dE(t.current);x(n),n.rest===`compact`&&e===`compact`&&(o.current=Date.now()+320,s.current=!0)},240)}),C=J(()=>{let n=e.scopeRef.current;!n||!h.current||x(rE(t.current,ZH(n)))}),w=J(e=>s.current?Date.now()>=o.current?(s.current=!1,!1):e>=80?(s.current=!1,o.current=0,!1):!0:!1),T=()=>{m.current={direction:null,px:0,at:0}},E=()=>{let e=m.current;return!e.direction||e.px<16||Date.now()-e.at>250?null:e.direction},D=J(()=>{if(g(i),!h.current||c.current>0||t.current.phase!==`tracking`)return;let e=uE(t.current,E());x(e),S()}),O=J(()=>{u.current=!1,d.current=0;for(let e of l.current.values())e.startX=e.currentX,e.startY=e.currentY}),k=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)}),A=J(t=>{if(h.current){if(c.current===0){l.current.clear(),O(),T();let t=e.scrollRef.current;if(t){let e=YH(t);p.current=e,f.current=JH(e,qH(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)}}),j=J(()=>{if(!h.current)return;let n=e.scrollRef.current,o=e.scopeRef.current;if(!n||!o)return;let s=ZH(o),l=YH(n),_=JH(l,qH(n)),v=f.current,y=p.current;if(f.current=_,p.current=l,n.hasAttribute(`data-yuri-timeline-anchoring`)){T(),O();return}let C=b(o);r.current=yE(o,_,r.current,C);let E=u.current&&(c.current>0||Date.now()-d.current<=1200),k=y!==null&&(y.scrollHeight!==l.scrollHeight||y.clientHeight!==l.clientHeight),A=E&&!k,j=l.scrollTop<0||y!==null&&y.scrollTop<0,M=A&&!j&&v!==null;if(!M)T();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=rE(N,s);if(s||(P=cE(P,_,{previousDistance:M?v:null,suppressReturn:A&&w(_),userDriven:A})),x(P),A){if(g(i),P.phase===`snapping`){(N.phase!==`snapping`||N.rest!==P.rest||N.progress!==P.progress)&&S();return}N.phase===`snapping`&&g(a),P.phase===`tracking`&&c.current===0&&(i.current=window.setTimeout(()=>{i.current=null,D()},120))}}),M=J(()=>{u.current&&(c.current>0||Date.now()-d.current<=1200)&&D()}),N=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():O(),t.current.phase===`tracking`&&(g(i),i.current=window.setTimeout(()=>{i.current=null,D()},120)))}}),P=J(e=>{N(e,!0)}),F=J(e=>{N(e,!1)}),I=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)}),L=J(n=>{if(!h.current)return;let r=n.target;if(!(r instanceof Element)||!r.closest(`[data-yuri-composer-compact-surface="true"]`)||r.closest(`[data-composer-action="true"]`))return;let i=r.closest(`.yuri-mobile-composer-compact-preview`);n.type===`pointerdown`&&i||n.type===`click`&&!i||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),T(),x(iE(t.current,`expanded`)),S(),I(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0}))}),[R,z]=Z.useState(null),[B,V]=Z.useState(null),H=Z.useRef(null),U=J(e=>{e&&vE(e,_.current??e),_.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,T(),x($T())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;H.current&&H.current!==n&&U(H.current),H.current=n,n&&b(n),z(e=>e===t?e:t),V(e=>e===n?e:n)});let W=Z.useMemo(()=>()=>void 0,[]),ee=e.enabled&&R?R:W,te=e.enabled&&B?B:W,ne=e.enabled&&typeof window<`u`?window:W,re=Z.useMemo(()=>({passive:!0}),[]);qn(`scroll`,j,ee,re),qn(`scrollend`,M,ee,re),qn(`touchstart`,A,ee,re),qn(`touchmove`,k,ee,re),qn(`touchend`,P,ee,re),qn(`touchcancel`,F,ee,re),qn(`pointerdown`,L,te),qn(`click`,L,te),qn(`focusin`,C,te),qn(`focusout`,C,te),qn(`yuri:keyboard-intent`,C,ne),qn(`yuri:keyboard-anim`,C,ne),qn(`yuri:keyboard-settled`,C,ne),Z.useEffect(()=>{if(!e.enabled){U(H.current),H.current=null;return}return C(),j(),()=>{g(i),g(a)}},[e.enabled,R,B])},$H=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},eU=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},tU=e=>{if(!e)return null;let t=$H(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${eU(e)??``}`},nU=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}),rU=(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&&tU(t[r])===tU(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=$H(r),a=r.info.id,o=nU(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=eU(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},iU=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=$H(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=eU(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}},aU=200,oU={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},sU=()=>aU,cU=()=>Math.round(sU()*.6),lU={MAX_SESSIONS:oU.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(aU*.6),HISTORICAL_MESSAGES:aU,FETCH_BUFFER:20,HISTORY_CHUNK:aU,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:oU.ZOMBIE_TIMEOUT},uU=()=>{let e=sU(),t=cU();return{...lU,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},dU=lU,fU=600,pU=6e3,mU=.5,hU=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),gU=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},_U=(e,t)=>{let n=hU(e,t);if(n||=gU(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}},vU=e=>{let{container:t,quiesceMs:n=fU,maxLifetimeMs:r=pU}=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=_U(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)>mU){_();return}let n=hU(t,i.messageId);if(!n){let e=gU(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)>mU&&(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)>mU)&&_(),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())}}},yU=30,bU=1200,xU=1.5,SU=e=>Math.max(bU,e*xU),CU=4,wU=30,TU=4,EU=30,DU=250,OU=800,kU=1e4,AU=1500,jU=2e3,MU=Ni+2e3,NU=40,PU=`history-loading-timeout`,FU=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),IU=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=PU,e},LU=(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)},RU=2500,zU=new Map,BU=()=>m()?CU:xo()?TU:yU,VU=e=>m()?e.length<=wU:!xo()||e.length<=EU,HU=(e,t)=>{if(zU.delete(e),!VU(t.messages))return;let n=BU();for(;zU.size>=n;){let e=zU.keys().next().value;if(typeof e!=`string`)break;zU.delete(e)}zU.set(e,t)},UU=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),WU=e=>e?{owner:`tanstack-core`}:{owner:`controller`},GU=(e,t)=>e?e.canLoadEarlier:t>=uU().HISTORICAL_MESSAGES,KU=e=>!(e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=SU(e.clientHeight)),qU=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`,JU=8,YU=1,XU=8,ZU=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],QU=80,$U=new WeakMap,eW=e=>{let t=e?$U.get(e):void 0;return!!(t&&(t.touches>0||performance.now()-t.lastScrollAt<160))},tW=e=>{let t=$U.get(e);t&&(t.touches=0,t.lastScrollAt=-1/0,t.pending=null,t.settleScheduled=!1)},nW=e=>{rW(e)},rW=e=>{let t=$U.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&&iW(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),e.addEventListener(`scroll`,()=>{n.lastScrollAt=performance.now()},{passive:!0}),$U.set(e,n),n},iW=(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+QU||aW(e,n.anchorTop+n.delta))}))},aW=(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},oW=(e,t,n)=>{let r=rW(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,aW(e,t)},sW=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),cW=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:a,loadMoreMessages:o,goToBottom:s,releaseAutoFollow:l,beginHistoryViewportPreservation:d,endHistoryViewportPreservation:f,isPinned:p,showScrollButton:m,isMobile:h,onWillLoadEarlier:g})=>{let _=Z.useRef(h);_.current=h;let v=Z.useRef(null),y=Z.useRef(null),b=Z.useMemo(()=>{let t=e??``,r=t?zU.get(t):void 0;if(r&&r.messages===n)return HU(t,r),v.current=r.model,y.current=n,r.model;let i=rU(v.current,y.current,n)??iU(n);return v.current=i,y.current=n,t&&n.length>0&&HU(t,{messages:n,model:i}),i},[n,e]),[x,S]=Z.useState(!1),[C,w]=Z.useState(!1),[T,E]=Z.useState(null),D=Z.useRef(0),O=u(),k=c(),A=Z.useMemo(()=>({runtimeKey:O,runtimeGeneration:k,sessionId:e,directory:t}),[O,k,e,t]),j=Z.useRef(A);j.current=A;let M=`chat-history-error:${JSON.stringify([O,t??null,e])}`;Gn(()=>(j.current=A,()=>{j.current===A&&(j.current=null),ji.dismiss(M)}),[A,M]);let N=Z.useRef(b),P=Z.useRef(p),F=Z.useRef(x),I=Z.useRef(C),L=Z.useRef(e),R=Z.useRef(t??null),z=Z.useRef(n),B=Z.useRef(r),V=Z.useRef([]),H=Z.useRef(!1),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),te=Z.useRef(!1),ne=Z.useRef(null),re=Z.useRef({authorized:!1,consumed:!1,top:0}),G=Z.useRef(null),ie=J(()=>{re.current={authorized:!1,consumed:F.current,top:i.current?.scrollTop??0}}),ae=()=>h?i.current??void 0:void 0,oe=J(e=>{e.repeat||ie()});qn(`touchstart`,ie,ae,{passive:!0,capture:!0}),qn(`wheel`,ie,ae,{passive:!0,capture:!0}),qn(`keydown`,oe,ae,{capture:!0});let[se,le]=Z.useState(A);se!==A&&(le(A),ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),te.current=!1,F.current=!1,ee.current=null,S(!1),w(!1),E(null),D.current=0,re.current={authorized:!1,consumed:!1,top:0},G.current=null);let ue=Z.useMemo(()=>{let e=GU(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),de=Z.useRef(ue);N.current=b,P.current=p,I.current=C,de.current=ue,L.current=e,R.current=t??null,z.current=n,B.current=r,Gn(()=>{r?.complete&&ji.dismiss(M)},[r?.complete,M]);let fe=J(()=>{te.current=!0,ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null)}),pe=J(()=>{if(typeof window>`u`){te.current=!1;return}ne.current!==null&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>{ne.current=null,te.current=!1},jU)}),me=J(()=>{let e=V.current;e.length!==0&&(V.current=[],e.forEach(e=>e()))}),he=J((e=!1)=>new Promise(t=>{if(typeof window>`u`){t();return}let n=!1,r=j.current,i=Date.now()+kU,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,DU)})),ge=J(e=>{let t=W.current;t&&(W.current=null,t.resolve(e))}),_e=J(()=>{let e=W.current;if(e){if(e.sessionId!==L.current){ge(!1);return}if(e.kind===`turn`?a.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:a.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(ee.current={turnId:e.turnId,expiresAt:Date.now()+RU},E(e.turnId)),ge(!0);return}typeof(e.kind===`turn`?N.current.turnIndexById.get(e.id):N.current.messageToTurnIndex.get(e.id))==`number`&&ge(!1)}}),ve=Z.useRef(null),ye=J(()=>{let e=ve.current;e&&(ve.current=null,e.dispose())});Wn(()=>{ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),ye(),me(),ge(!1)});let be=Z.useRef({scope:A,at:-1/0}),xe=()=>{!h&&!xo()&&(be.current={scope:A,at:Date.now()})};qn(`wheel`,e=>{e.deltaY!==0&&e.target instanceof Node&&i.current?.contains(e.target)&&xe()},void 0,{passive:!0,capture:!0}),qn(`scroll`,e=>{e.target===i.current&&xe()},void 0,{passive:!0,capture:!0});let Se=()=>be.current.scope===A&&Date.now()-be.current.at<OU,[Ce,Te]=Z.useState({scope:A,messages:n}),Ee=xo(),De=Ce.scope===A&&Ce.messages!==n&&sW(Ce.messages[0]?.info?.id??null,n[0]?.info?.id??null,n)&&(Ee?!a.current?.isHistoryVirtualized()&&eW(i.current):!h&&Ce.messages.at(-1)===n.at(-1)&&Se()),Oe=De?Ce.messages:n;H.current=De&&!h&&!Ee,(Ce.scope!==A||Ce.messages!==Oe)&&Te({scope:A,messages:Oe});let[,ke]=Z.useReducer(e=>e+1,0);Gn(()=>{me(),_e()},[Oe]);let Ae=Z.useRef(null),je=J(()=>a.current?.captureViewportAnchor()??null),Me=J(e=>a.current?.restoreViewportAnchor(e)??!1),Ne=J(()=>{if(ye(),a.current?.isHistoryVirtualized())return;let e=i.current;if(!e)return;let t=je();if(t)return ve.current=vU({container:e,anchor:t,pending:!0,isUserScrolling:xo()?()=>eW(e):void 0}),ve.current}),Pe=Z.useRef(null);Vn(J(()=>{let e=i.current;if(!e||!De||!Ee&&Se())return;let t=e.scrollHeight;Pe.current={oldestId:Oe[0]?.info?.id??null,newestId:Oe.at(-1)?.info?.id??null,scrollHeight:t};let n=Ae.current;if(n){let r={...n,height:t,top:e.scrollTop,anchor:je()};Ae.current=Ee?r:Object.assign(n,r)}ke()}),De?50:null);let Fe=Z.useRef(null);Gn(()=>{if(!xo())return;let e=i.current;if(!e){Fe.current=null;return}let t=Fe.current;(t?.container!==e||t.scope!==A)&&(nW(e),tW(e),Fe.current={container:e,scope:A})}),Gn(()=>{ye(),U.current=null,me(),Ae.current=null,Pe.current=null,a.current?.cancelViewportAnchorHold()},[A]),Gn(()=>{let e=i.current;if(!e)return;let t=Ae.current;a.current?.isHistoryVirtualized()&&ye(),t&&Math.abs(e.scrollTop-t.top)>XU&&(Ae.current=null,t=null);let n=Pe.current,r=Oe[0]?.info?.id??null,o=Oe[Oe.length-1]?.info?.id??null,c=n?UU({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:o})||sW(n.oldestId,r,Oe):!1;t&&t.sessionId!==L.current&&(Ae.current=null,t=null);let l=t?UU({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:o})||sW(t.oldestId,r,Oe):!1,u=c||l,d=e=>{Pe.current={oldestId:r,newestId:o,scrollHeight:e??Pe.current?.scrollHeight??null}};if(P.current&&!t){ye(),u?(Ae.current=null,s(`instant`,{reveal:!1}),d(e.scrollHeight)):d();return}let f=WU(a.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){a.current?.cancelViewportAnchorHold();let e=t.anchor;e&&Me(e),d();return}let n=e.scrollHeight,r=n-t.height;if(xo()){r>0&&oW(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&Me(i))&&r>0&&(e.scrollTop=t.top+r),ve.current?.rebase(),d(n);return}if(c&&n&&f.owner===`controller`){let t=e.scrollHeight,r=n.scrollHeight===null?0:t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;xo()?oW(e,t,r):e.scrollTop=t}d(t),Ne();return}d()},[Oe,s]),Gn(()=>{if(H.current)return;let e=U.current;U.current=null,e?.()},[Oe]);let Ie=J(async()=>!1),Le=J(async e=>{let t=j.current,n=()=>t===j.current&&t?.runtimeKey===u()&&t?.runtimeGeneration===c(),r=Date.now(),i=r+MU,a=R.current,o=a?ce()?.getRequestState?.(we(a,e)):void 0;for(de.current.historyLoading,B.current,o?.status,o?.error;de.current.historyLoading;){if(!n()||L.current!==e)return Date.now()-r,`switched`;if(Date.now()>=i){let t=a?ce()?.getRequestState?.(we(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:MU,hostTurnPageTimeoutMs:Ni,historyLoading:de.current.historyLoading,historyMeta:B.current,requestStatusAtStart:o?.status??null,requestStatusAtTimeout:t?.status??null,requestErrorAtTimeout:t?.error??null,likelyStaleLoadingFlag:t?.status===`ready`||t?.status===`error`||t==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,NU)})}return Date.now()-r,a&&ce()?.getRequestState?.(we(a,e))?.status,n()&&L.current===e?`cleared`:`switched`}),Re=J(async e=>{if(!L.current||F.current||H.current||!de.current.hasMoreAboveTurns)return!1;F.current=!0,fe(),S(!0);let t=L.current,n=j.current,r=()=>n===j.current&&n?.runtimeKey===u()&&n?.runtimeGeneration===c(),s=()=>n?.directory?ce()?.getPagination(we(n.directory,t)).cursor??null:null,l=M,p=null,m=null,h=!!e.userInitiated;h&&d();let g=()=>{if(r()){if(H.current){U.current=g;return}m?.settle(),p&&Ae.current===p&&(Ae.current=null,a.current?.cancelViewportAnchorHold()),h&&(h=!1,f())}};try{if(de.current.historyLoading){if(!e.userInitiated)return!1;let n=await Le(t);if(n===`timeout`)throw IU();if(n===`switched`||!de.current.hasMoreAboveTurns)return!1}if(!r()||!L.current||L.current!==t)return!1;let n=i.current,a=z.current,c=a.length,u=a[0]?.info?.id??null,d=B.current?.limit??uU().HISTORICAL_MESSAGES;e.preserveViewport&&n&&(p={sessionId:L.current,height:n.scrollHeight,top:n.scrollTop,anchor:je(),oldestId:u,newestId:a[a.length-1]?.info?.id??null},Ae.current=p,Pe.current={oldestId:p.oldestId,newestId:p.newestId,scrollHeight:p.height},m=Ne()??null);let f=c,h=u,_=d,v=0,y=0;for(;;){if(de.current.historyLoading)if(e.userInitiated){let e=await Le(t);if(e===`timeout`)throw g(),IU();if(e===`switched`)return g(),!1}else return g(),!1;let n=i.current?.scrollHeight??0,a=f,c=h,u=_,d=s();if(await o(t,`up`),v+=1,!r()||L.current!==t)return g(),!1;if(await he(!0),!r())return!1;if(H.current)return!0;let p=(()=>{let t=z.current;return qU({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:a,messageCountAfter:t.length,oldestIdBefore:c,oldestIdAfter:t[0]?.info?.id??null,limitBefore:u,limitAfter:B.current?.limit??_,cursorBefore:d,cursorAfter:s(),hasMoreAbove:de.current.hasMoreAboveTurns,pagesLoaded:v,maxPages:e.singlePage?1:JU})})();if(p===`continue`){let e=z.current;f=e.length,h=e[0]?.info?.id??null,_=B.current?.limit??_;continue}if(p===`stop-no-growth`){if(e.singlePage)return g(),!1;if(de.current.historyLoading){if(e.userInitiated){let e=await Le(t);if(e===`timeout`)throw g(),IU();if(e===`switched`)return g(),!1;--v;continue}return g(),!1}if(y<YU){y+=1,--v;continue}return D.current=Date.now()+AU,g(),!1}return D.current=0,ji.dismiss(l),!0}}catch(e){throw r()&&(D.current=Date.now()+AU),g(),e}finally{r()&&(F.current=!1,S(!1),pe(),H.current?g():he(!0).then(g))}}),{t:ze}=Xn(),Be=q({mutationKey:ZU({runtimeKey:u(),sessionId:e??``}),mutationFn:async e=>{if(j.current!==e.scope||u()!==e.scope.runtimeKey||c()!==e.scope.runtimeGeneration||L.current!==e.sessionId)return!1;fe(),e.userInitiated&&l();try{return await Re({preserveViewport:!0,userInitiated:!!e.userInitiated,singlePage:e.singlePage})}finally{j.current===e.scope&&c()===e.scope.runtimeGeneration&&pe()}}}),Ve=J(async e=>{let t=L.current;if(!t||!de.current.canLoadEarlier)return;let n=A,r=M,i=()=>j.current===n&&u()===n.runtimeKey&&c()===n.runtimeGeneration;if(!(Be.isPending&&Be.variables?.sessionId===t&&Be.variables?.scope===n)){e?.userInitiated&&g?.();try{let r=await Be.mutateAsync({sessionId:t,scope:n,userInitiated:!!e?.userInitiated,singlePage:e?.singlePage});if(!i())return;if(r===!1&&de.current.canLoadEarlier){let n={sessionId:t,grew:r,userInitiated:!!e?.userInitiated,canLoadEarlier:de.current.canLoadEarlier,hasMoreAboveTurns:de.current.hasMoreAboveTurns,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};LU(`no-growth`,Error(`chat history pagination returned no growth`),n)}}catch(n){let a={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:MU,hostTurnPageTimeoutMs:Ni,canLoadEarlier:de.current.canLoadEarlier,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};FU(n)?LU(`timeout`,n,a):LU(`failed`,n,a),i()&&e?.userInitiated&&ji.error(FU(n)?ze(`chat.history.loadOlderTimeout`):ze(`chat.history.loadOlderFailed`),{id:r})}}}),He=Be.isPending&&Be.variables?.sessionId===e&&Be.variables?.scope===A||x,Ue=J(e=>{if(Date.now()<D.current)return;let t=i.current;if(t){if(_.current){let n=re.current,r=t.scrollTop<n.top;if(n.top=t.scrollTop,n.consumed||(e===`upward-intent`&&(n.authorized=!0),!n.authorized||e===`scroll`&&!r))return}else if(F.current){G.current=null;return}else if(e===`upward-intent`)G.current={top:t.scrollTop};else{let e=G.current;if(!e)return;let n=t.scrollTop<e.top;if(t.scrollTop>e.top||P.current?G.current=null:e.top=t.scrollTop,!n)return}KU({source:e,isMobile:_.current,isPinned:P.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:de.current.canLoadEarlier,isLoadingOlder:F.current,pendingRevealWork:I.current})&&(_.current&&(re.current.consumed=!0),G.current=null,Ve({userInitiated:!0,singlePage:_.current}))}}),We=J(()=>{Ue(`scroll`)}),Ge=J(()=>{!_.current&&!F.current&&!a.current?.isHistoryVirtualized()&&Ne()?.settle(),Ue(`upward-intent`)}),Ke=J(async(t,n)=>{if(!t||!L.current)return!1;l(),w(!0);try{return L.current!==e||typeof N.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},_e()})}finally{w(!1)}}),qe=Z.useRef(null),Je=J(async(t,n)=>{if(!t||!L.current)return!1;let r=`${L.current}:${t}`;if(qe.current===r)return!1;qe.current=r;let i=L.current;l(),w(!0);try{if(L.current!==e)return!1;for(;!N.current.messageToTurnId.has(t)&&de.current.hasMoreAboveTurns;){if(L.current!==i||qe.current!==r)return!1;let e=z.current[0]?.info.id;if(await Ve({userInitiated:!0,singlePage:!0}),await he(),z.current[0]?.info.id===e)break}if(L.current!==i||qe.current!==r)return!1;let a=N.current.messageToTurnId.get(t);return typeof N.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:a??null,resolve:r},_e()})}finally{qe.current===r&&(qe.current=null),w(!1)}}),Ye=J(async()=>{qe.current=null,w(!1),F.current=!1,S(!1),s(`smooth`)}),Xe=J(async()=>{w(!1),F.current=!1,S(!1),s(`instant`)}),Ze=J(e=>{let t=ee.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;ee.current=null}E(e)});return{turnIds:b.turnIds,turnStart:0,renderedMessages:Oe,historySignals:ue,isLoadingOlder:He,pendingRevealWork:C,activeTurnId:T,showScrollToBottom:m&&!C,turnWindowModel:b,loadEarlier:Ve,revealBufferedTurns:Ie,resumeToBottom:Ye,resumeToBottomInstant:Xe,scrollToTurn:Ke,scrollToMessage:Je,handleHistoryScroll:We,handleHistoryUpwardIntent:Ge,captureViewportAnchor:je,restoreViewportAnchor:Me,handleActiveTurnChange:Ze}},lW=12,uW=50,dW=800;function fW(e){let t=(0,Q.c)(25),{scope:n,enabled:i,cursor:a,loadedTurns:o,messages:s,scrollRef:c,loadPrevious:l}=e,[u,d]=Z.useState(null),f=Z.useRef(u),p=Z.useRef(!1),m=Z.useRef(null),h;t[0]!==u||t[1]!==a||t[2]!==i||t[3]!==o||t[4]!==n?(h=i&&!r()&&a!==null&&o<lW&&u!==n,t[0]=u,t[1]=a,t[2]=i,t[3]=o,t[4]=n,t[5]=h):h=t[5];let g=h,_;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{f.current=null,d(null)},t[6]=_):_=t[6];let v;t[7]===n?v=t[8]:(v=[n],t[7]=n,t[8]=v),Z.useEffect(_,v);let y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{m.current=null},t[9]=y):y=t[9];let b;t[10]!==a||t[11]!==g||t[12]!==s||t[13]!==n?(b=[n,g,a,s],t[10]=a,t[11]=g,t[12]=s,t[13]=n,t[14]=b):b=t[14],Z.useEffect(y,b);let x;t[15]!==g||t[16]!==c?(x=e=>{g&&e.deltaY!==0&&e.target instanceof Node&&c.current?.contains(e.target)&&(m.current=null)},t[15]=g,t[16]=c,t[17]=x):x=t[17];let S;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(S={passive:!0,capture:!0},t[18]=S):S=t[18],qn(`wheel`,x,void 0,S);let C;t[19]!==a||t[20]!==g||t[21]!==l||t[22]!==n||t[23]!==c?(C=()=>{let e=c.current;if(f.current===n)return;if(!g||r()||!a||!e||p.current||document.visibilityState===`hidden`){m.current=null;return}let t=e.scrollHeight,i=e.scrollTop,o=m.current;if(!o||o.height!==t||o.top!==i){m.current={height:t,top:i,since:Date.now()};return}Date.now()-o.since<dW||(f.current=n,d(n),p.current=!0,l(uW).catch(pW).finally(()=>{p.current=!1}))},t[19]=a,t[20]=g,t[21]=l,t[22]=n,t[23]=c,t[24]=C):C=t[24],Vn(J(C),g?200:null)}function pW(e){console.error(`[chat-history] desktop history warmup failed`,e)}var mW=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),hW=({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[d,f]=Z.useState(null),[p,m]=Z.useState(``),[h,g]=Z.useState(0),_=Z.useRef(!1),v=Z.useRef(0),y=J(async(e,n,r)=>{if(_.current)return;_.current=!0;let i=v.current+1;v.current=i,f({type:e,messageId:n});try{await r(),t(!1)}finally{v.current===i&&(_.current=!1,f(null))}});return n?(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsx)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:(0,$.jsx)(gW,{open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s,isLoadingEarlier:c,onLoadEarlier:l,onRevertMessage:u,searchQuery:p,onSearchQueryChange:m,selectedIndex:h,onSelectedIndexChange:g,pendingAction:d,runPendingMessageAction:y})})}):null},gW=e=>{let t=(0,Q.c)(145),{open:n,onOpenChange:r,sessionID:i,directory:a,onScrollToMessage:o,onScrollByTurnOffset:s,onResumeToLatest:c,canLoadEarlier:l,isLoadingEarlier:u,onLoadEarlier:d,onRevertMessage:f,searchQuery:p,onSearchQueryChange:m,selectedIndex:h,onSelectedIndexChange:g,pendingAction:_,runPendingMessageAction:v}=e,{t:y}=Xn(),b=Ab(),x=i,S=No(x??``,a),C=wa(vW),w=wa(yW),T;t[0]===b.capabilities?T=t[1]:(T=mW(b.capabilities),t[0]=b.capabilities,t[1]=T);let E=T,{isMobile:D,isTablet:O}=Kc(),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=bW,L=xW,R;t[3]===S?R=t[4]:(R=S.filter(SW).map(CW),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 YV(n.parts).toLowerCase().includes(t)})}t[5]=p,t[6]=z,t[7]=B}else B=t[7];let V=B,H;t[8]!==V.length||t[9]!==g||t[10]!==p?(H=()=>{P.current||g(p.trim()?0:Math.max(0,V.length-1))},t[8]=V.length,t[9]=g,t[10]=p,t[11]=H):H=t[11];let U;t[12]!==V||t[13]!==g||t[14]!==p?(U=[V,p,g],t[12]=V,t[13]=g,t[14]=p,t[15]=U):U=t[15],Z.useEffect(H,U);let W,ee;t[16]===V.length?(W=t[17],ee=t[18]):(W=()=>{j.current=j.current.slice(0,V.length)},ee=[V.length],t[16]=V.length,t[17]=W,t[18]=ee),Z.useEffect(W,ee);let te,ne;t[19]===h?(te=t[20],ne=t[21]):(ne=()=>{P.current||j.current[h]?.scrollIntoView({block:`nearest`})},te=[h],t[19]=h,t[20]=te,t[21]=ne),Z.useEffect(ne,te);let re;t[22]===u?re=t[23]:(re=()=>{!P.current||N.current||u||(P.current=!1)},t[22]=u,t[23]=re);let G;t[24]!==V.length||t[25]!==u?(G=[V.length,u],t[24]=V.length,t[25]=u,t[26]=G):G=t[26],Z.useEffect(re,G);let ie,ae;t[27]!==n||t[28]!==p?(ie=()=>{let e=F.current;if(F.current=n,!n||e||P.current||p.trim())return;let t=M.current;t&&(t.scrollTop=t.scrollHeight)},ae=[n,p],t[27]=n,t[28]=p,t[29]=ie,t[30]=ae):(ie=t[29],ae=t[30]),Z.useLayoutEffect(ie,ae);let oe;t[31]===u?oe=t[32]:(oe=()=>{let e=N.current,t=M.current;if(!e||!t||u)return;N.current=null;let n=j.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},t[31]=u,t[32]=oe);let se;t[33]!==V.length||t[34]!==u?(se=[V.length,u],t[33]=V.length,t[34]=u,t[35]=se):se=t[35],Z.useLayoutEffect(oe,se);let ce;t[36]===d?ce=t[37]:(ce=()=>{let e=M.current;if(e){let t=e.getBoundingClientRect().top,n=j.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(N.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}P.current=!0,d?.()},t[36]=d,t[37]=ce);let le=J(ce),ue;t[38]!==r||t[39]!==o?(ue=async e=>{await o?.(e)!==!1&&r(!1)},t[38]=r,t[39]=o,t[40]=ue):ue=t[40];let de=J(ue),fe;t[41]!==V||t[42]!==de||t[43]!==g||t[44]!==h?(fe=e=>{let t=V.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),g(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),g(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(h%t+t)%t,r=V[n];r&&de(r.message.info.id)}}},t[41]=V,t[42]=de,t[43]=g,t[44]=h,t[45]=fe):fe=t[45];let pe=J(fe),me;t[46]!==x||t[47]!==a||t[48]!==w||t[49]!==f||t[50]!==C||t[51]!==v?(me=async(e,t)=>{x&&await v(e,t,async()=>{e===`revert`?f?await f(t):await C(x,t,{directory:a}):await w(x,t,{directory:a})})},t[46]=x,t[47]=a,t[48]=w,t[49]=f,t[50]=C,t[51]=v,t[52]=me):me=t[52];let he=J(me),ge;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),t[53]=ge):ge=t[53];let _e;t[54]===y?_e=t[55]:(_e=y(`chat.timeline.title`),t[54]=y,t[55]=_e);let ve;t[56]===_e?ve=t[57]:(ve=(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[ge,_e]}),t[56]=_e,t[57]=ve);let ye;t[58]===y?ye=t[59]:(ye=y(`chat.timeline.description`),t[58]=y,t[59]=ye);let be;t[60]===ye?be=t[61]:(be=(0,$.jsx)(ys,{children:ye}),t[60]=ye,t[61]=be);let xe;t[62]!==ve||t[63]!==be?(xe=(0,$.jsxs)(hs,{children:[ve,be]}),t[62]=ve,t[63]=be,t[64]=xe):xe=t[64];let Se;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(Se=(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),t[65]=Se):Se=t[65];let Ce;t[66]===y?Ce=t[67]:(Ce=y(`chat.timeline.searchPlaceholder`),t[66]=y,t[67]=Ce);let we;t[68]===m?we=t[69]:(we=e=>m(e.target.value),t[68]=m,t[69]=we);let Te;t[70]!==pe||t[71]!==p||t[72]!==Ce||t[73]!==we?(Te=(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[Se,(0,$.jsx)(Ks,{autoFocus:!0,placeholder:Ce,value:p,onChange:we,onKeyDown:pe,className:`pl-9 w-full`})]}),t[70]=pe,t[71]=p,t[72]=Ce,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:`flex justify-center py-1`,children:(0,$.jsxs)(er,{type:`button`,variant:`link`,size:`sm`,onClick:le,disabled:u,className:`h-auto px-1 py-0 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]!==E.fork||t[82]!==E.revert||t[83]!==k||t[84]!==V||t[85]!==he||t[86]!==de||t[87]!==g||t[88]!==_||t[89]!==p||t[90]!==h||t[91]!==y?(De=V.length===0?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:y(p?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):V.map((e,t)=>{let{message:n}=e,r=XV(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()?_W(YV(n.parts),p):null;return(0,$.jsxs)(Z.Fragment,{children:[s&&(0,$.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-3 bg-background/95 py-2 backdrop-blur-sm`,children:[(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a}),(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`})]}),(0,$.jsxs)(`div`,{ref:e=>{j.current[t]=e},"data-timeline-message-id":n.info.id,className:Y(`group flex items-center gap-3 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,l&&`bg-interactive-selection text-interactive-selection-foreground`),onClick:()=>void de(n.info.id),onMouseEnter:()=>g(t),children:[(0,$.jsx)(`span`,{className:Y(`typography-meta w-16 flex-shrink-0 text-right tabular-nums`,l?`text-interactive-selection-foreground/70`:`text-muted-foreground`),children:c}),(0,$.jsxs)(`p`,{className:Y(`flex-1 min-w-0 typography-micro truncate`,l?`text-interactive-selection-foreground`:`text-foreground`),children:[u??(r||y(`chat.timeline.noTextContent`)),!u&&r&&r.length>=80&&`…`]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:(0,$.jsxs)(`div`,{className:Y(`gap-1`,k?`flex`:`hidden group-hover:flex`),children:[E.revert?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"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)(Js,{sideOffset:6,children:y(`chat.timeline.actions.revertFromHere`)})]}):null,E.fork?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"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)(Js,{sideOffset:6,children:y(`chat.timeline.actions.forkFromHere`)})]}):null]})})]})]},n.info.id)}),t[81]=E.fork,t[82]=E.revert,t[83]=k,t[84]=V,t[85]=he,t[86]=de,t[87]=g,t[88]=_,t[89]=p,t[90]=h,t[91]=y,t[92]=De):De=t[92];let Oe;t[93]===De?Oe=t[94]:(Oe=(0,$.jsx)(`div`,{ref:M,className:`flex-1 overflow-y-auto`,children:De}),t[93]=De,t[94]=Oe);let ke;t[95]===y?ke=t[96]:(ke=y(`chat.timeline.actions.title`),t[95]=y,t[96]=ke);let Ae;t[97]===ke?Ae=t[98]:(Ae=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:ke}),t[97]=ke,t[98]=Ae);let je;t[99]!==r||t[100]!==s?(je=()=>{s?.(-1),r(!1)},t[99]=r,t[100]=s,t[101]=je):je=t[101];let Me;t[102]===y?Me=t[103]:(Me=y(`chat.timeline.actions.previousTurn`),t[102]=y,t[103]=Me);let Ne;t[104]!==je||t[105]!==Me?(Ne=(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:je,children:Me}),t[104]=je,t[105]=Me,t[106]=Ne):Ne=t[106];let Pe;t[107]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),t[107]=Pe):Pe=t[107];let Fe;t[108]!==r||t[109]!==c?(Fe=()=>{c?.(),r(!1)},t[108]=r,t[109]=c,t[110]=Fe):Fe=t[110];let Ie;t[111]===y?Ie=t[112]:(Ie=y(`chat.timeline.actions.latest`),t[111]=y,t[112]=Ie);let Le;t[113]!==Fe||t[114]!==Ie?(Le=(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:Fe,children:Ie}),t[113]=Fe,t[114]=Ie,t[115]=Le):Le=t[115];let Re;t[116]!==Ne||t[117]!==Le?(Re=(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[Ne,Pe,Le]}),t[116]=Ne,t[117]=Le,t[118]=Re):Re=t[118];let ze;t[119]===y?ze=t[120]:(ze=y(`chat.timeline.help.clickMessage`),t[119]=y,t[120]=ze);let Be;t[121]===ze?Be=t[122]:(Be=(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:ze})}),t[121]=ze,t[122]=Be);let Ve;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Ve=(0,$.jsx)(X,{name:`arrow-go-back`,className:`h-4 w-4 flex-shrink-0`}),t[123]=Ve):Ve=t[123];let He;t[124]===y?He=t[125]:(He=y(`chat.timeline.help.undoToPoint`),t[124]=y,t[125]=He);let Ue;t[126]===He?Ue=t[127]:(Ue=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Ve,(0,$.jsx)(`span`,{children:He})]}),t[126]=He,t[127]=Ue);let We;t[128]!==E.fork||t[129]!==y?(We=E.fork?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:y(`chat.timeline.help.createSessionFromHere`)})]}):null,t[128]=E.fork,t[129]=y,t[130]=We):We=t[130];let Ge;t[131]!==Be||t[132]!==Ue||t[133]!==We?(Ge=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 typography-meta text-muted-foreground`,children:[Be,Ue,We]}),t[131]=Be,t[132]=Ue,t[133]=We,t[134]=Ge):Ge=t[134];let Ke;t[135]!==Ae||t[136]!==Re||t[137]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[Ae,Re,Ge]}),t[135]=Ae,t[136]=Re,t[137]=Ge,t[138]=Ke):Ke=t[138];let qe;return t[139]!==xe||t[140]!==Te||t[141]!==Ee||t[142]!==Oe||t[143]!==Ke?(qe=(0,$.jsxs)($.Fragment,{children:[xe,Te,Ee,Oe,Ke]}),t[139]=xe,t[140]=Te,t[141]=Ee,t[142]=Oe,t[143]=Ke,t[144]=qe):qe=t[144],qe};function _W(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 vW(e){return e.revertToMessage}function yW(e){return e.forkFromMessage}function bW(e){return dc(e)}function xW(e){return Xs(e)}function SW(e){return e.info.role===`user`}function CW(e){return{message:e}}var wW=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},TW=(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`}},EW=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`))},DW=e=>{e&&EW(`message-${e}`)},OW=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&&EW(`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&&EW(`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=TW(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 EW(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=()=>{EW(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=wW(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},kW=2e4,AW=6e4,jW=2e3,MW=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,NW=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+=MW(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},PW={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},FW=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:PW,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}},IW=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function LW(e){return!!(e.active&&e.sessionId&&e.sessionKey&&e.sessionIsWorking)}function RW(e){return e===PW?e:PW}function zW(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 BW(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 VW(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||zW(i)==null}function HW(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!VW(n))continue;let e=BW(n);e&&t.push(e)}}return t}function UW(e,t){return`${e}:${t.join(`,`)}`}function WW(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=UW(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function GW(e,t,n,r){let i=(0,Q.c)(7),a=Vr(),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=WW({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:HW(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,Nr(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 KW=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),qW=(e,t)=>({...e,key:JW(e),estimatedBytes:KW(t)}),JW=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),YW=e=>({key:e?JW(e):null,selection:e}),XW=(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},ZW=(e,t,n,r)=>{let i=JW(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return XW(e,i,n);let s=o||qW(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),XW(c,i,n)},QW=(e,t,n)=>{let r=KW(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)},$W=(e,t)=>t&&e.some(e=>e.key===t)?t:null,eG=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?ZW(e.cachedSessionViews,t.selection,n,r.estimatedBytes):XW(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}},tG=(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:qW(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},nG=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:ZW(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},rG=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},iG=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},aG=e=>iG(e)?.role===`assistant`,oG=(e,t)=>{let n=iG(t);n&&(e.agentName??=rG(n.agent),e.providerId??=rG(n.providerID),e.modelId??=rG(n.modelID))},sG=e=>!!(e.agentName&&e.providerId&&e.modelId),cG=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!aG(r))&&(oG(t,r),sG(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||aG(r))&&(oG(t,r),sG(t)))break}return t},lG=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),uG=[],dG=[],fG=[],pG={type:`idle`},mG=`yuri:chat-force-scroll-bottom`,hG=()=>void 0,gG=`Quota limit reached. Retrying automatically.`,_G=1048576,vG=_G,yG=20,bG=_G,xG=16*_G,SG={maxEntries:3,maxEstimatedBytes:32*_G},CG={maxEntries:2,maxEstimatedBytes:32*_G},wG=e=>i(()=>e()),TG={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},EG=()=>{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},DG=[`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(`,`),OG=e=>e instanceof HTMLElement,kG=e=>OG(e)?!!e.closest(DG):!1,AG=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||kG(e)?!0:!t?.contains(e),jG=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=K.getState();return e||t||n||r||i||a||o},MG=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,initialPinRevealComplete:l=!1,renderedMessages:u,isLoadingOlder:d,sessionIsWorking:f,streamingMessageId:p,activeStreamingPhase:m,retryOverlay:h,handleMessageContentChange:g,getAnimationHandlers:_,handleHistoryScroll:v,scrollToBottom:y,sessionQuestions:b,sessionPermissions:x,sessionForms:S,retryActionCopy:C,isProgrammaticFollowActive:w,showLoadOlderButton:T,turnIds:E,activeTurnId:D,onSelectTurn:O,showPromptNavigator:k,canLoadEarlierPrompts:A,isLoadingOlderPrompts:j,onLoadEarlierPrompts:M,transcriptStatusRow:N,timelineHistoryAnchorToken:P})=>{let{t:F}=Xn(),I=HD({isLoadingOlder:d}),[L,R]=Z.useState({sessionId:e,directory:a,reserved:T}),z=L.sessionId===e&&L.directory===a,B=z&&L.reserved||T;(!z||L.reserved!==B)&&R({sessionId:e,directory:a,reserved:B});let V=UD({isMobile:r,isLoadingOlder:I})?(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsx)(`div`,{className:`chat-column flex items-center justify-center gap-1.5 pt-3 pb-1`,children:(0,$.jsx)(`span`,{className:`yuri-mobile-glass-control flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)]`,"aria-label":F(`chat.history.loadingMore`),children:(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`,"aria-hidden":`true`})})})}):null,H=r&&B?(0,$.jsx)(`div`,{className:Y(`flex justify-center pt-3 pb-4`,!I&&`invisible`),"aria-hidden":!I,children:(0,$.jsxs)(`span`,{role:`status`,className:`flex items-center gap-1.5 text-[var(--surface-mutedForeground)] opacity-60`,"aria-busy":I,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:F(`chat.history.loadingMore`)})]})}):null,U=Z.useRef(new Map),W=Z.useRef(new WeakMap),ee=Z.useRef(new Map),te=Z.useMemo(()=>{let e=new Map;for(let t=0;t<u.length;t+=1){let n=u[t];if(n.info.role!==`user`)continue;if(lL(n)){let r=fL(u,t)??``,i=ee.current.get(n.info.id);if(i&&i.command===r)e.set(n.info.id,i.parts);else{let t=[{type:`text`,text:r?`$ ${r}`:`/shell`}];ee.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(xa(n.parts))continue;let r=W.current.get(n.parts);r||(r=PD(n.parts),W.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=U.current;if(t.size===e.size){let n=!0;for(let[r,i]of e)if(t.get(r)!==i){n=!1;break}if(n)return t}return U.current=e,e},[u]),ne=Z.useMemo(()=>E.filter(e=>te.has(e)),[te,E]),re=Z.useRef(new Map),G=Z.useMemo(()=>{let e=new Map,t=new Map,n;for(let r of u){if(r.info.role===`user`){te.has(r.info.id)&&(n=r.info.id),n&&e.set(r.info.id,n);continue}let i=r.info.parentID,a=i?e.get(i):n;if(!a)continue;e.set(r.info.id,a);let o=YV(r.parts).trim();o&&t.set(a,o.slice(0,600))}let r=re.current;return(r.size!==e.size||[...e].some(([e,t])=>r.get(e)!==t))&&(re.current=e),{owners:re.current,replies:t}},[te,u]),ie=Z.useMemo(()=>{if(!D||te.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(te.has(e))return e}return null},[D,te,E]),ae=J(e=>{e.defaultPrevented||kG(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)(Zu,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:TG,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:ae,onScroll:v,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`yuri-chat-scroll-content relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[H,V,(0,$.jsx)(hV,{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)(rR,{})}):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)(VV,{question:e},e.id)),x.map(e=>(0,$.jsx)(PV,{permission:e},e.id)),S.map(e=>(0,$.jsx)(UV,{form:e,directory:a},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?CH:SH},"aria-hidden":`true`})]})}),(0,$.jsx)(Yu,{containerRef:o,suppressVisibility:w,userIntentOnly:!0,observeMutations:!1}),k&&ne.length>=2?(0,$.jsx)(_H,{turnIds:ne,previewsByTurnId:te,scrollRef:o,turnByMessageId:G.owners,repliesByTurnId:G.replies,activeTurnId:ie,onSelectTurn:O,canLoadEarlier:A,isLoadingOlder:j,onLoadEarlier:M}):null]})})},(e,t)=>e.currentSessionId===t.currentSessionId&&e.virtualizerKey===t.virtualizerKey&&e.isDesktopExpandedInput===t.isDesktopExpandedInput&&e.isMobile===t.isMobile&&e.stickyUserHeader===t.stickyUserHeader&&e.directory===t.directory&&e.scrollRef===t.scrollRef&&e.messageListRef===t.messageListRef&&e.pendingRevealWork===t.pendingRevealWork&&e.initialPinRevealComplete===t.initialPinRevealComplete&&e.renderedMessages===t.renderedMessages&&e.timelineHistoryAnchorToken===t.timelineHistoryAnchorToken&&e.isLoadingOlder===t.isLoadingOlder&&e.sessionIsWorking===t.sessionIsWorking&&e.streamingMessageId===t.streamingMessageId&&e.activeStreamingPhase===t.activeStreamingPhase&&e.retryOverlay===t.retryOverlay&&e.handleMessageContentChange===t.handleMessageContentChange&&e.getAnimationHandlers===t.getAnimationHandlers&&e.handleHistoryScroll===t.handleHistoryScroll&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.sessionForms===t.sessionForms&&e.retryActionCopy===t.retryActionCopy&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.turnIds===t.turnIds&&e.activeTurnId===t.activeTurnId&&e.onSelectTurn===t.onSelectTurn&&e.showPromptNavigator===t.showPromptNavigator&&e.canLoadEarlierPrompts===t.canLoadEarlierPrompts&&e.isLoadingOlderPrompts===t.isLoadingOlderPrompts&&e.onLoadEarlierPrompts===t.onLoadEarlierPrompts&&e.transcriptStatusRow===t.transcriptStatusRow);MG.displayName=`ChatViewport`;var NG=[{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%]`]}],PG=e=>Zn(e.path),FG=(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)]})},IG=e=>{let t=Math.ceil(Math.max(0,e)/yG);return Math.min(xG,vG+t*bG)},LG=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:s,hostedFeatures:c,assistantHistory:l,onRevertMessage:d,warning:f=null,pendingUserMessages:p=dG,onPendingUserMessagesMaterialized:h,committedDraftHandoffMessageId:g=null})=>{let _=c??qD(void 0),{t:v}=Xn();Gn(()=>{Ra()},[]);let y=wa(e=>e.openNewSessionDraft),b=wa(e=>e.setCurrentSession),x=wa(e=>e.newSessionDraft),S=wa(e=>e.newSessionDraft.draftSubmitting??!1),C=wa(e=>e.newSessionDraft.draftEstablishing??!1),w=wa(e=>e.forkTransition),T=Ia(e=>e.projects),E=Ia(e=>e.activeProjectId),D=Ko(e=>e.providers),O=dh(),k=$o(),A=i??k;Gn(()=>{!n||!r||!A||Kr(A,r)},[n,r,A]);let j=J(e=>O.ensureSessionRenderable(e,{directory:A})),M=K(e=>e.isExpandedInput),N=K(e=>e.stickyUserHeader),P=K(e=>e.promptNavigatorEnabled),F=K(e=>e.allowPromptingSubagentSessions),I=K(e=>e.isTimelineDialogOpen),L=K(e=>e.setTimelineDialogOpen),R=dr(e=>n&&r?e.streamingMessageIds.get(r)??null:null),z=dr(e=>R?e.messageStreamStates.get(R)?.phase??null:null),B=fa(r??``,A),V=IG(B);Z.useEffect(()=>{!a||!o||o(a,V)},[o,V,a]);let H=Ja(r??``,A).renderable,U=cr(r,A),W=Vi(r),ee=U??W,te=Tx({sessionId:r,hasSessionEntity:!!ee,hasRenderableSessionSnapshot:H,composerSurfaceKind:s?.kind}),ne=r?JSON.stringify([A,r]):null,[re,G]=Z.useState({key:ne,attempt:0}),ie=No(r??``,A,{suspendPartUpdates:!!R,suspendPartUpdatesForMessageId:R,enabled:n}),ae=r?ie:uG,oe=x.pendingUserMessage,se=wa(e=>r?e.retainedPendingUserMessages.get(r):void 0)??dG,le=!!(g||se.length>0),ue=wa(e=>e.clearRetainedPendingUserMessages),de=Z.useMemo(()=>{if(se.length===0)return p;if(p.length===0)return se;let e=new Set(p.map(e=>e.info.id));return[...p,...se.filter(t=>!e.has(t.info.id))]},[p,se]),fe=Z.useMemo(()=>cG(ae),[ae]),pe=Z.useMemo(()=>{if(!fe.modelId)return v(`common.unavailable`);let e=D.find(e=>e.id===fe.providerId);return ki(e,fe.modelId)||fe.modelId},[D,fe.modelId,fe.providerId,v]),me=go(r??``,A),he=Va(r??``,A),[ge,ve]=Z.useState(null),ye=!!r&&ge===r,be=J(()=>{if(!r||ye)return;let e=r,t=A;ve(e);let n=Qa(()=>{let n=ce();if(!n)throw Error(`unbound`);return n.getTranscript(we(t,e))});mi(ui({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:me?{sessionID:e,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error})),(async()=>{try{await Je(t,e),await O.ensureSessionRenderable(e,{directory:t});try{let r=Qa(()=>{let n=ce();if(!n)throw Error(`unbound`);return n.getTranscript(we(t,e))});n&&r&&to({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){mi(ui({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:he,error:n}))}finally{ve(t=>t===e?null:t)}})()}),xe=sa(r??``,A).boundary,Se=J(async e=>{if(xe.kind===`has-more`){await pt(A,e,Ue||We?void 0:50);return}if(xe.kind===`unknown`){await He(A,e);return}l&&!l.complete&&await l.fetchPrevious()}),Ce=vo(r??``,A),Te=oo(r??``,A),Ee=Wa(A),De=Ce??pG,ke=aa(r,A),Ae=Di(r,A),je=Dr(e=>r?e.forms[r]??fG:fG),Me=Z.useMemo(()=>je.filter(e=>!_e(e.metadata)),[je]);Z.useEffect(()=>{r&&Ii({sessionID:r,directory:A}).catch(e=>{console.error(`[ChatContainer] Failed to list session forms:`,e)})},[r,A]),GW(r,A,ae,Ae.length);let Ne=Z.useMemo(()=>{if(!r||ke.length>0||Ae.length>0)return!1;let e=De.type??`idle`;if(e===`busy`||e===`retry`||RD(de,{resolvedSessionStatus:Ce,sessionStatusObservedAt:Te}))return!0;let t=ae[ae.length-1]?.info,n=t?.time?.created;return Ce&&typeof Te==`number`&&typeof n==`number`&&n<=Te||typeof Ee==`number`&&typeof n==`number`&&n<=Ee?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,de,Ce,ae,ke.length,Ae.length,De.type,Te,Ee]),Pe=Z.useMemo(()=>!r||De.type!==`retry`?null:{sessionId:r,message:(typeof De.message==`string`?(De.message??``).trim():``)||gG,confirmedAt:De.confirmedAt},[r,De]),[Fe,Ie]=Z.useState(0),Le=Z.useRef(null);Z.useEffect(()=>{if(!Pe||typeof Pe.confirmedAt==`number`){Le.current=null,Ie(0);return}Le.current!==Pe.sessionId&&(Le.current=Pe.sessionId,Ie(Date.now()))},[Pe]);let Re=Z.useMemo(()=>!Pe||qV(De)?null:{...Pe,fallbackTimestamp:Fe},[Pe,Fe,De]),ze=Z.useMemo(()=>JV(De,e=>v(e)),[De,v]),Be=!!(r&&O.isLoading(r,{directory:A})),Ve=Z.useMemo(()=>{if(!r)return null;let e=zD({boundary:xe,assistantComplete:l?.complete??!0});return{limit:xe.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:BD({syncLoading:Be,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,xe,Be]),Ue=K(e=>e.isMobile),We=Ll()!==null,Ge=m(),Ke=mx(),qe=!!x?.open,Ye=si(e=>e.error),Xe=M,Ze=We||Ue||Ge||Ke===`mini-chat`,Qe=Z.useRef(null),$e=Z.useMemo(()=>{let e=x?.selectedProjectId?T.find(e=>e.id===x.selectedProjectId)??null:null,t=E?T.find(e=>e.id===E)??null:null,n=e??t??T[0]??null;return n?PG(n):null},[E,x?.selectedProjectId,T]),et=ta(r,A),tt=a??r??``,[nt,rt]=Z.useState(null),it=Ax(nt,tt,et,fe);Gn(()=>{rt(e=>Ax(e,tt,et,fe))},[et,fe,tt]);let at=et??it?.parentTarget??null,ot=it?.execution??fe,st=ll(),ct=st!==null&&r===st,lt=J(()=>{at&&b(at.id,at.directory)}),ut=at?.session?.title,dt=_.returnToParent&&at&&!ct?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`xs`,onClick:lt,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":v(`chat.container.returnToParent.aria`),title:ut?.trim()?v(`chat.container.returnToParent.titleNamed`,{title:ut}):v(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),v(`chat.container.returnToParent.label`)]}):null,ft=Ex({readOnly:t,sessionIdentityPending:te,isSubagentSession:!!ee?.parentID||!!it,allowPromptingSubagentSessions:F}),mt=ot.modelId===fe.modelId?pe:ot.modelId?ki(D.find(e=>e.id===ot.providerId),ot.modelId)||ot.modelId:v(`common.unavailable`),ht=at?(0,$.jsx)(ZD,{agentName:ot.agentName,providerId:ot.providerId,modelId:ot.modelId,modelName:mt}):(0,$.jsx)(ZD,{}),gt=J(e=>{K.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),_t=J(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`yuri:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&>({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),vt=typeof window<`u`&&window.parent!==window;qn(`message`,_t,vt?window:hG),Jn(()=>{if(!vt)return;let e=window;e.__yuriApplyChatSettingsSync=gt,window.parent.postMessage({type:`yuri:chat-settings-request`},window.location.origin)}),Wn(()=>{if(typeof window>`u`)return;let e=window;e.__yuriApplyChatSettingsSync===gt&&delete e.__yuriApplyChatSettingsSync}),Z.useEffect(()=>{_.newSessionDraft&&e&&!r&&!qe&&y()},[e,r,qe,_.newSessionDraft,y]);let yt=Z.useRef(()=>{}),bt=J(e=>{yt.current(e)}),xt=Z.useRef(()=>{}),St=J(()=>{xt.current()}),[Ct,wt]=Z.useState(0),Tt=J(()=>{wt(e=>e+1)}),{scrollRef:Et,notifyContentChange:Dt,getAnimationHandlers:Ot,goToBottom:kt,scrollToBottomOnSend:At,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,restoreSnapshot:Pt,isPinned:Ft,isFollowingProgrammatically:It,showScrollButton:Lt}=WH({scrollControllerRef:Qe,enabled:n,currentSessionId:r,viewportKey:a,sessionMessageCount:B,sessionIsWorking:Ne,isMobile:Ue,onActiveTurnChange:bt,onUpwardUserIntent:St}),Rt=Z.useRef(null);QH({enabled:Ue,scrollRef:Et,scopeRef:Rt});let zt=Z.useRef([]),Bt=Z.useMemo(()=>{let e=oO(l?.entries??[],r,zt.current);return zt.current=e,e},[l?.entries,r]),Vt=Z.useRef([]),Ht=Z.useMemo(()=>{if(!l)return ae;let e=lO(l.entries,r,ae,Vt.current);return Vt.current=e,e},[l,r,ae]),Ut=Z.useMemo(()=>LD(Bt.length===0?Ht:r?[...Bt,iO(r),...Ht]:Bt,de),[r,Ht,Bt,de]),Wt=Z.useRef(null),Gt=Z.useMemo(()=>KD({sessionId:r,messages:Ut,retained:Wt.current}),[r,Ut]);Wt.current=Gt.retained;let Kt=Gt.messages,qt=Z.useRef(null),Jt=qt.current===r,Yt=Z.useRef(PW),Xt=r?`${A}\n${r}`:null,Zt=J(()=>NW(Kt));Z.useEffect(()=>{if(!LW({active:n,sessionId:r,sessionKey:Xt,sessionIsWorking:Ne})){Yt.current=RW(Yt.current);return}let e=r,t=A,i=setInterval(()=>{let n=Zt(),r=FW(Yt.current,{sessionKey:Xt,working:!0,streaming:!!R,fingerprint:n,now:Date.now(),thresholdMs:kW,cooldownMs:AW,maxAttempts:3});Yt.current=r.state,r.shouldRefresh&&(IW({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),Oe(t,e).catch(()=>{}))},jW);return()=>clearInterval(i)},[n,r,A,Zt,Ne,R,Xt]);let Qt=Z.useMemo(()=>{if(de.length===0)return[];let e=new Set([...Bt,...Ht].filter(e=>ID(e.parts)).map(e=>e.info.id));return de.map(e=>e.info.id).filter(t=>e.has(t))},[Ht,Bt,de]);Z.useEffect(()=>{Qt.length!==0&&(h?.(Qt),r&&ue(r,Qt))},[ue,r,Qt,h]);let $t=cW({sessionId:r,directory:A,messages:Kt,historyMeta:Ve,scrollRef:Et,messageListRef:Qe,loadMoreMessages:Se,goToBottom:kt,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,isPinned:Ft,showScrollButton:Lt,isMobile:Ue,onWillLoadEarlier:Tt}),en=J(()=>{kt(`instant`)}),tn=J(()=>{At()}),nn=VD({isMobile:Ue,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingOlder:$t.isLoadingOlder}),rn=$t.isLoadingOlder,an=$t.loadEarlier,on=J(()=>{an({userInitiated:!0})});yt.current=$t.handleActiveTurnChange,xt.current=$t.handleHistoryUpwardIntent,Z.useEffect(()=>{(ke.length!==0||Ae.length!==0)&&Dt(`permission`)},[Dt,ke,Ae]);let sn=OW({sessionId:r,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,scrollToTurn:$t.scrollToTurn,scrollToMessage:$t.scrollToMessage,resumeToBottom:en}),cn=ft.showReadOnlyBanner?ht:t?null:(0,$.jsx)(fD,{surface:s,scrollToBottom:tn,showScrollToBottom:Ue&&$t.showScrollToBottom,onScrollToBottom:sn.resumeToLatest,submissionBlocked:ft.blockSubmission},`composer-input`),ln=J(e=>{sn.scrollToTurnId(e,{behavior:`smooth`})}),un=$t.historySignals.canLoadEarlier,dn=_.promptNavigator&&!Ue&&!Ge&&!Xe&&P&&$t.turnIds.length>=2;Z.useEffect(()=>{dn||K.getState().setPromptNavigatorPanelOpen(!1)},[dn]);let fn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||kt(`instant`)});qn(mG,fn,n&&r&&typeof window<`u`?window:hG);let pn=J(e=>{if(!n||!r||Xe||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=K.getState();if(t!==`chat`||jG())return;let i=Et.current;if(AG(document.activeElement,i)||kG(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;sn.scrollByTurnOffset(a,{resumePastEnd:!1})});qn(`keydown`,pn,n&&r&&!Xe&&typeof window<`u`?window:hG);let mn=Z.useRef(0),hn=J(()=>{let e=Et.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),gn=J(()=>{mn.current||=requestAnimationFrame(()=>{mn.current=0,hn()})});Gn(()=>{n&&hn()},[n,r,Xe,hn]);let _n=typeof ResizeObserver<`u`;Hn(n&&_n?Et:null,gn),qn(`resize`,gn,n&&!_n&&typeof window<`u`?window:hG),Wn(()=>{mn.current&&=(cancelAnimationFrame(mn.current),0)});let vn=Z.useRef(null),yn=Z.useRef(0),bn=WD({transcriptMessageCount:ae.length,pendingUserCount:de.length,historyPrefixCount:Bt.length}),q=GD({hasTranscriptShell:bn,transcriptRecords:ae,p0Satisfied:he.p0Satisfied,hasBusyShell:Ne&&bn,hasImmediateShell:de.length>0||Bt.length>0,hasRenderableSessionSnapshot:H,prefetchStatus:me?.status,syncLoading:!!(r&&O.isLoading(r,{directory:A})),userRetrying:ye,hasPaintedTranscript:Jt});q===`pass`&&Kt.length>0&&(qt.current=r);let xn=!!r&&q===`hydrating`;fW({scope:JSON.stringify([u(),A,r]),enabled:n&&!Ue&&!We&&!!r&&q===`pass`&&he.p0Satisfied&&!Ne&&!Ve?.loading&&!$t.isLoadingOlder,cursor:xe.kind===`has-more`?xe.cursor:null,loadedTurns:xe.loadedTurns,messages:Kt,scrollRef:Et,loadPrevious:e=>pt(A,r,e)});let Sn=!!r&&q===`load-error`;Z.useEffect(()=>{!Sn||!r||mi(ui({kind:`request-error`,sessionID:r,directory:A,purpose:`load-failed`,source:`network`,request:me?{sessionID:r,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error}))},[r,A,Sn,me,he]),Z.useEffect(()=>{if(!n||!r||xn)return;let e=Kt.length,t=vn.current!==r,i=!t&&yn.current===0&&e>0;if(!t&&!i){vn.current===r&&(yn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(vn.current=r,yn.current=e,a){jt();return}let o=()=>{Pt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,xn,jt,Pt,Kt.length]),Z.useEffect(()=>{G(e=>e.key===ne?e:{key:ne,attempt:0})},[ne]),Z.useEffect(()=>{if(!n||!r||re.key!==ne||!lG({sessionId:r,hasRenderableSessionSnapshot:H,hasCurrentSessionEntity:!!ee})||(j(r),ee||re.attempt>=2))return;let e=re.attempt+1,t=window.setTimeout(()=>{G(t=>t.key===ne&&t.attempt===re.attempt?{key:ne,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,ee,r,A,j,H,ne,re]);let Cn=w&&r&&(w.targetSessionId?r===w.targetSessionId:r===w.sourceSessionId)?w:null;if(Cn){let e=Cn.stage===`preparing`?`chat.forkTransition.preparing`:Cn.stage===`copying`?`chat.forkTransition.copying`:Cn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=v(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Cn.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${v(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:v(e)}),(0,$.jsx)(Kv,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}if(!r&&!qe)return e&&!Ye?(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`}):(0,$.jsx)(`div`,{className:`flex flex-col h-full bg-background`,children:(0,$.jsx)($D,{})});if(!r&&qe){if((S||C)&&oe){let e=`draft:${x.draftID??`pending`}`;return(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex h-full flex-col bg-background`,Ue&&`yuri-chat-composer-swap-scope`),children:[(0,$.jsx)(MG,{timelineHistoryAnchorToken:Ct,currentSessionId:e,virtualizerKey:e,isDesktopExpandedInput:!1,isMobile:Ue,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:!1,initialPinRevealComplete:!0,renderedMessages:[oe],isLoadingOlder:!1,sessionIsWorking:!0,streamingMessageId:null,activeStreamingPhase:null,retryOverlay:null,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:[],sessionPermissions:[],sessionForms:[],retryActionCopy:null,isProgrammaticFollowActive:It,showLoadOlderButton:!1,turnIds:[],activeTurnId:null,onSelectTurn:ln,showPromptNavigator:!1,canLoadEarlierPrompts:!1,isLoadingOlderPrompts:!1,onLoadEarlierPrompts:on,transcriptStatusRow:(0,$.jsx)(`div`,{className:`chat-column`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex h-[1.2rem] items-center py-0.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:v(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Kv,{})]})})},e),(0,$.jsxs)(`div`,{className:Y(`invisible pointer-events-none relative z-10`,Ue&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`absolute inset-0 bg-background`:`bg-background`),"aria-hidden":`true`,children:[!Ue&&!Xe?(0,$.jsx)(EG,{}):null,cn]})]})}return S||C?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":v(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:v(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Kv,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Ze&&!Xe?(0,$.jsxs)(`div`,{className:`yuri-draft-center flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-balance text-3xl font-normal tracking-tight text-foreground`,children:FG($e?v(`chat.emptyState.draftTitleWithProject`,{project:$e}):v(`chat.emptyState.draftTitle`),$e)}),(0,$.jsx)(SS,{onSubmit:e=>va.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`,Ue&&`yuri-mobile-composer-foot`,Xe?`flex-1 bg-background`:Ze?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:cn})]})}return r?Sn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[dt,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:v(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:v(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(er,{type:`button`,className:`mt-5`,onClick:be,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),v(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):xn?(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,Ue&&`yuri-chat-composer-swap-scope`),children:[dt,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:(0,$.jsx)(`div`,{ref:Et,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:TG,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:NG.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)(af,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(af,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(af,{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)(af,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(af,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(af,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!Ue&&!Xe?(0,$.jsx)(EG,{}):null,cn]},`composer-foot`)]}):Kt.length===0&&!Ne?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[dt,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)($D,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,Ue&&`yuri-chat-composer-swap-scope`),children:[f?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:f}):null,dt,(0,$.jsx)(MG,{timelineHistoryAnchorToken:Ct,currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Xe,isMobile:Ue,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:$t.pendingRevealWork,initialPinRevealComplete:le,renderedMessages:$t.renderedMessages,isLoadingOlder:rn,sessionIsWorking:Ne,streamingMessageId:R,activeStreamingPhase:z,retryOverlay:Re,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:Ae,sessionPermissions:ke,sessionForms:Me,retryActionCopy:ze,isProgrammaticFollowActive:It,showLoadOlderButton:nn,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,onSelectTurn:ln,showPromptNavigator:dn,canLoadEarlierPrompts:un,isLoadingOlderPrompts:rn,onLoadEarlierPrompts:on},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!Ue&&!Xe?(0,$.jsx)(EG,{}):null,!Xe&&Kt.length>0&&(Ue?(0,$.jsx)(fx,{placement:`expanded`,visible:$t.showScrollToBottom,onClick:sn.resumeToLatest}):(0,$.jsx)(fx,{visible:$t.showScrollToBottom,onClick:sn.resumeToLatest})),cn]},`composer-foot`),(0,$.jsx)(hW,{open:I,onOpenChange:L,sessionID:r??void 0,directory:A,onRevertMessage:d,onScrollToMessage:$t.scrollToMessage,onScrollByTurnOffset:sn.scrollByTurnOffset,onResumeToLatest:en,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingEarlier:rn,onLoadEarlier:on})]}):null});LG.displayName=`MemoizedChatContainerContent`;var RG=()=>{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)(af,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(af,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(af,{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)(af,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(af,{className:`h-4 w-3/5 animate-none rounded-md`})]})]})})}),e[1]=n):n=e[1],n},zG=({runtimeKey:e,...t})=>{let n=mx(),r=$o(),i=wa(H(e=>({sessionId:e.currentSessionId,directory:e.currentSessionDirectory,draftID:e.newSessionDraft.open?e.newSessionDraft.draftID:null,draftPendingMessageId:e.newSessionDraft.open?e.newSessionDraft.pendingUserMessage?.info.id??null:null}))),a=Z.useRef(null),o=i.draftID&&i.draftPendingMessageId?`${i.draftID}:${i.draftPendingMessageId}`:null;o&&a.current?.identity!==o&&(a.current=null),Gn(()=>{!o||!i.draftPendingMessageId||(a.current={identity:o,messageId:i.draftPendingMessageId})},[o,i.draftPendingMessageId]);let s=wa(e=>i.sessionId?e.retainedPendingUserMessages.get(i.sessionId)??dG:dG),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(()=>YW(u),[u]),f=d.key,p=xo()||m()||n===`mini-chat`?CG:SG,[h,g]=Z.useState(()=>({activeIntent:d,cacheNeedsTrim:!1,cachedSessionViews:u?ZW([],u,p,vG):[],pendingSessionView:null})),_=Z.useRef(d),v=Z.useRef(f),{cacheNeedsTrim:y,cachedSessionViews:b,pendingSessionView:x}=h,S=x?.intent===d?x.entry:null,C=Z.useMemo(()=>!u||!l?null:ZW([],u,p,vG)[0]??null,[p,l,u]),w=Z.useMemo(()=>{let e=[...b];return S&&!e.some(e=>e.key===S.key)&&e.push(S),C&&!e.some(e=>e.key===C.key)&&e.push(C),e.sort((e,t)=>e.key.localeCompare(t.key))},[b,C,S]),T=$W(w,f),E=!!(f&&!T);Gn(()=>{_.current=d,v.current=f,g(e=>{let t=eG(e,d,p);return l?tG(t,d,d,vG):t})},[p,y,l,d,f]);let D=x?.intent??null;Gn(()=>{D&&g(e=>nG(e,D,p))},[p,D]),Z.useEffect(()=>{if(!d.selection||T)return;let e=d,t=f;return Td(()=>{_.current===e&&v.current===t&&g(n=>v.current===t?tG(n,e,_.current,vG):n)},{priority:`user-blocking`})},[T,p,d,f]);let O=J((e,t)=>{let n=_.current,r=v.current;g(i=>{if(_.current!==n||v.current!==r||i.activeIntent!==n||e!==r)return i;let a=QW(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})});return(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":E||void 0,children:[E?(0,$.jsx)(RG,{},f):null,w.map(e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:T===e.key?`visible`:`hidden`,children:(0,$.jsx)(LG,{...t,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:O,committedDraftHandoffMessageId:T===e.key?l:null})},e.key)),f?null:(0,$.jsx)(LG,{...t,sessionId:null,sessionDirectory:i.directory})]})},BG=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=qD(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)(LG,{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)(kb.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},VG=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=$o(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Ob({...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)(LG,{...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)(kb.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},HG=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(wG,u,u);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(BG,{...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)(VG,{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)(zG,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r},UG=2e4,WG=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus()?`visible`:`hidden`,GG=e=>{if(!x()&&!$e())return;let t=S();t?.push?.setVisibility&&t.push.setVisibility({visible:e,platform:st()})},KG=e=>{let t=e?.enabled??!0;Z.useEffect(()=>{if(!t||!x()&&!$e()||typeof window>`u`)return;if($e()){let e=!0,t=!1,n=null,r=()=>GG(e);Pn(async()=>{let{App:e}=await import(`./vendor-capacitor-app-B5H_XtmE.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([72,1,26])).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&&GG(!0)},UG);return()=>{t=!0,window.clearInterval(i),n?.()}}if(typeof document>`u`)return;let e=()=>{GG(WG()===`visible`)},n=()=>{WG()===`visible`&&GG(!0)},r=()=>{GG(!1)};e();let i=window.setInterval(n,UG);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])},qG=`Yuri`,JG=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``).split(`/`).filter(Boolean);return t[t.length-1]??``},YG=(e,t)=>[e,t,qG].filter(e=>typeof e==`string`&&e.trim().length>0).join(` | `),XG=()=>{let e=Ia(e=>{if(!e.activeProjectId)return null;let t=e.projects.find(t=>t.id===e.activeProjectId);return t&&JG(t.path)||null}),[t,n]=Z.useState(null);Z.useEffect(()=>{if(typeof window>`u`||!p()){n(null);return}let e=!1,t=async()=>{try{if(g()){e||n(null);return}let t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,r=d();if(r&&j(r,t)){e||n(null);return}let i=(await M()).hosts.find(e=>r?j(r,P(e)):!1),a=i?.label?.trim()?T(i.label.trim()):`Instance`;e||n(a)}catch{e||n(`Instance`)}};t();let r=()=>{t()};return window.addEventListener(`focus`,r),()=>{e=!0,window.removeEventListener(`focus`,r)}},[]);let r=Z.useMemo(()=>YG(e,t),[e,t]);Z.useEffect(()=>{typeof document<`u`&&(document.title=r),p()&&(async()=>{try{if(typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``))return;await nr(r)}catch{return}})()},[r])},ZG=e=>{let t=[];return e.hideGit||t.push(`git`),t.push(`files`),e.showBrowser&&t.push(`browser`),t},QG=e=>e===`git`||e===`files`||e===`browser`,$G=()=>{let e=wa.getState().currentSessionId;if(!e)return``;let t=Le().find(t=>t.id===e);return typeof t?.directory==`string`?t.directory:``},eK=async(e,t=6e3)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t),i=Date.now();try{let t=await f(e,{method:`GET`,headers:{Accept:`application/json`},signal:n.signal}),r=Date.now()-i,a=t.headers.get(`content-type`)||``,o=a.toLowerCase(),s=o.includes(`json`)&&!o.includes(`text/html`),c=``;if(s){let e=await t.json().catch(()=>null);if(Array.isArray(e))c=`json[array] len=${e.length}`;else if(e&&typeof e==`object`){let t=Object.keys(e).slice(0,8);c=`json[object] keys=${t.join(`,`)}${Object.keys(e).length>t.length?`,…`:``}`}else c=`json[${typeof e}]`}else c=a?`content-type=${a}`:`no content-type`;return{ok:t.ok&&s,status:t.status,elapsedMs:r,summary:c}}catch(e){return{ok:!1,status:0,elapsedMs:Date.now()-i,summary:`error=${n.signal.aborted||e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))?`timeout after ${t}ms`:e instanceof Error?e.message:String(e)}`}}finally{clearTimeout(r)}},tK=e=>{if(!e||!Number.isFinite(e))return`(n/a)`;try{return new Date(e).toISOString()}catch{return`(invalid)`}},nK=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},rK=e=>!!e&&typeof e==`object`&&!Array.isArray(e),iK=(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,aK=(e,t,n)=>e===`node-shebang`||e===`node-launcher`?t?`node (${t})`:`node`:e===`bun-shebang`?n?`bun (${n})`:`bun`:e||`direct executable`,oK=async()=>{let e=new Date,t=typeof navigator<`u`?navigator.userAgent:`(no navigator)`,n=$G(),r=K.getState().eventStreamStatus,i=typeof window<`u`?window.location.origin:``,o=a(),s=o.health(),c=o.api(`/api/`),l=await(async()=>{if(!s)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),5e3);try{let t=await f(s,{method:`GET`,headers:{Accept:`application/json`},signal:e.signal});if(!t.ok)return null;let n=await t.json().catch(()=>null);return!n||typeof n!=`object`||Array.isArray(n)?null:n}catch{return null}finally{clearTimeout(t)}})(),u=await(async()=>{if(!c)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),7e3);try{let t=await f(o.api(`/api/config/opencode-resolution`),{method:`GET`,headers:{Accept:`application/json`},signal:e.signal}),n=t.headers.get(`content-type`)||`(none)`;if(!t.ok)return{data:null,status:t.status,error:`http ${t.status} content-type=${n}`};let r=await t.text(),i=null;try{i=JSON.parse(r)}catch{let e=r.replace(/\s+/g,` `).slice(0,120);return{data:null,status:t.status,error:`invalid json content-type=${n} body=${e||`(empty)`}`}}return!i||typeof i!=`object`||Array.isArray(i)?{data:null,status:t.status,error:`invalid json-shape content-type=${n}`}:{data:i,status:t.status,error:null}}catch(e){return{data:null,status:null,error:e instanceof Error?e.message:String(e)}}finally{clearTimeout(t)}})()||{data:null,status:null,error:null},d=(e,t=!0)=>{if(!c)return null;let r=new URL(e.replace(/^\/+/,``),c);return t&&n&&r.searchParams.set(`directory`,n),r.toString()},p=c?await Promise.all([{label:`health`,path:`/health`,includeDirectory:!1},{label:`config`,path:`/config`,includeDirectory:!0},{label:`providers`,path:`/config/providers`,includeDirectory:!0},{label:`agents`,path:`/agent`,includeDirectory:!0,timeoutMs:12e3},{label:`commands`,path:`/command`,includeDirectory:!0,timeoutMs:1e4},{label:`project`,path:`/project/current`,includeDirectory:!0},{label:`path`,path:`/path`,includeDirectory:!0},{label:`sessions`,path:`/session`,includeDirectory:!0,timeoutMs:12e3},{label:`sessionStatus`,path:`/session/status`,includeDirectory:!0}].map(async e=>{let t=d(e.path,e.includeDirectory!==!1);if(!t)return{label:e.label,url:`(none)`,result:null};let n=await eK(t,typeof e.timeoutMs==`number`?e.timeoutMs:void 0);return{label:e.label,url:t,result:n}})):[],m=[];m.push(`Time: ${e.toISOString()}`),m.push(`Yuri version: 0.2.0-beta.7`),m.push(`Runtime: ${i||`(unknown)`} (api=${c||`(unknown)`})`),m.push(`OpenCode SDK base: ${Te.getBaseUrl()}`),m.push(`Event stream: ${r}`),m.push(`Directory: ${n||`(none)`}`),m.push(`Platform: ${t}`);let h=nK(l?.openCodePort);if(m.push(`OpenCode runtime port: ${h??`(unknown)`}`),typeof l?.openCodeRunning==`boolean`&&m.push(`OpenCode runtime running: ${l.openCodeRunning?`yes`:`no`}`),typeof l?.openCodeSecureConnection==`boolean`&&m.push(`Secure OpenCode connection: ${l.openCodeSecureConnection?`true`:`false`}`),typeof l?.openCodeAuthSource==`string`&&l.openCodeAuthSource.trim()&&m.push(`OpenCode auth source: ${l.openCodeAuthSource}`),typeof l?.openCodeServeVersion==`string`&&l.openCodeServeVersion.trim()&&m.push(`OpenCode serve version: ${l.openCodeServeVersion}`),typeof l?.openCodeCliVersion==`string`&&l.openCodeCliVersion.trim()&&m.push(`OpenCode CLI version: ${l.openCodeCliVersion}`),rK(l?.runtimeContract)){let e=l.runtimeContract,t=typeof e.phase==`string`?e.phase:`(unknown)`,n=e.executionAllowed===!0?`allowed`:`limited`,r=e.protocolCompatible===!0?`compatible`:`incompatible`;m.push(`OpenCode runtime contract: phase=${t} protocol=${r} execution=${n}`),Array.isArray(e.reasons)&&e.reasons.length>0&&m.push(`OpenCode contract reasons: ${e.reasons.filter(e=>typeof e==`string`).join(`, `)}`)}if(typeof window<`u`){let e=window.__YURI_MACOS_MAJOR__;typeof e==`number`&&Number.isFinite(e)&&e>0&&m.push(`macOS major: ${e}`)}if(/Mac OS X|Macintosh/.test(t)){m.push(``),m.push(`OpenCode CLI resolution:`);let e=rK(l?.lastOpenCodeLaunchDiagnostics)?l.lastOpenCodeLaunchDiagnostics:null,t=e&&Array.isArray(e.args)?e.args.filter(e=>typeof e==`string`):[],n=u.data,r=n&&typeof n.configured==`string`?n.configured:null,i=n&&typeof n.resolved==`string`?n.resolved:l&&typeof l.opencodeBinaryResolved==`string`?l.opencodeBinaryResolved:``,a=n&&typeof n.resolvedDir==`string`?n.resolvedDir:``,o=n&&typeof n.source==`string`?n.source:l&&typeof l.opencodeBinarySource==`string`?l.opencodeBinarySource:``,s=n&&typeof n.launchBinary==`string`?n.launchBinary:l&&typeof l.opencodeLaunchBinary==`string`?l.opencodeLaunchBinary:``,c=n&&typeof n.launchWrapperType==`string`?n.launchWrapperType:l&&typeof l.opencodeLaunchWrapperType==`string`?l.opencodeLaunchWrapperType:``,d=n&&Array.isArray(n.launchArgs)?n.launchArgs.filter(e=>typeof e==`string`):l&&Array.isArray(l.opencodeLaunchArgs)?l.opencodeLaunchArgs.filter(e=>typeof e==`string`):[],f=n&&typeof n.node==`string`?n.node:l&&typeof l.nodeBinaryResolved==`string`?l.nodeBinaryResolved:``,p=n&&typeof n.bun==`string`?n.bun:l&&typeof l.bunBinaryResolved==`string`?l.bunBinaryResolved:``,h=n&&typeof n.detectedNow==`string`?n.detectedNow:``,g=n&&typeof n.detectedSourceNow==`string`?n.detectedSourceNow:``;if(r!==null&&m.push(`- configured: ${r.trim().length===0?`(cleared)`:r}`),i){let e=a||(i.includes(`/`)?i.split(`/`).slice(0,-1).join(`/`)||`/`:``);m.push(`- opencode: ${i}${e?` (dir=${e})`:``}`)}else m.push(`- opencode: (n/a)`);m.push(`- source: ${o||`(n/a)`}`),h&&(m.push(`- detected-now: ${h}`),m.push(`- detected-source: ${g||`(n/a)`}`)),e?(m.push(`- launched-at: ${iK(e.launchedAt)}`),m.push(`- launch: ${iK(e.binary)} ${t.join(` `)}`.trim()),m.push(`- cwd: ${iK(e.cwd)}`),m.push(`- wrapper: ${iK(e.wrapperType)}`),m.push(`- runtime: ${aK(iK(e.wrapperType,``),f,p)}`),m.push(`- PATH entries: ${iK(e.pathEntryCount,`(unknown)`)}`),m.push(`- shell env: ${iK(e.hasShellEnv,`(unknown)`)} (${iK(e.shellEnvKeysCount,`?`)} keys)`)):(m.push(`- launch-binary: ${s||`(n/a)`}`),m.push(`- launch-wrapper: ${c||`(n/a)`}`),m.push(`- launch-args: ${d.length?d.join(` `):`(none)`}`),m.push(`- runtime: ${aK(c||``,f,p)}`)),!n&&u.error&&m.push(`- resolution-endpoint: ${u.error}`)}if(m.push(``),p.length){m.push(`OpenCode API probes:`);for(let e of p){if(!e.result){m.push(`- ${e.label}: (no url)`);continue}let{ok:t,status:n,elapsedMs:r,summary:i}=e.result,a=t?``:` url=${e.url}`;m.push(`- ${e.label}: ${t?`ok`:`fail`} status=${n} time=${r}ms ${i}${a}`)}}else m.push(`OpenCode API probes: (skipped)`);return m.push(``),m.push(`Generated: ${tK(Date.now())}`),m.join(`
|
|
6602
|
-
`)},sK=async()=>{let e=await oK(),t=K.getState();t.setOpenCodeStatusText(e),t.setOpenCodeStatusDialogOpen(!0)},cK=(e,t)=>e===t?!0:!e||!t?!1:e.scope===t.scope&&e.sessionId===t.sessionId&&e.projectId===t.projectId,lK=e=>e?`${e.scope}:${e.projectId??``}:${e.sessionId}`:null,uK=e=>({scope:`project`,sessionId:e,projectId:null}),dK=L()(e=>({focus:null,setFocus:t=>e(e=>cK(e.focus,t)?e:{focus:t})})),fK=null,pK=0,mK=(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},hK=e=>{let t=++pK;return fK={pinned:mK(`pinned`,e.pinned),project:mK(`project`,e.project)},()=>{pK===t&&(fK=null)}},gK=()=>fK,_K=e=>!!e.parentID,vK=(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&&_K(r);){let e=r.parentID;if(!e)break;let t=n.get(e);if(!t)return e;r=t}return r?.id??e},yK=()=>{let e=xi.getState().activeSessions;if(e.length>0)return e;let t=be();return t.length>0?t:Le()},bK=(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)},xK=e=>[...e.pinned,...e.project],SK=(e,t,n,r)=>{if(e.length===0)return null;let i=bK(e,n,r);return i<0?t>0?e[0]??null:e[e.length-1]??null:e[(i+t+e.length)%e.length]??null},CK=(e,t,n=dK.getState().focus)=>{let r=vK(t,yK()),i=n?.sessionId===t?n:null,a=gK();return a?SK(xK(a),e,r,i):null},wK=(e,t,n=e=>{wa.getState().setCurrentSession(e.sessionId,e.directory)})=>{let r=CK(e,t);return r?(dK.getState().setFocus({scope:r.scope,sessionId:r.sessionId,projectId:r.projectId}),n(r),r):null},TK=.5,EK=.1,DK=`yuri.webviewZoomFactor`,OK=e=>Number.isFinite(e)?Math.min(3,Math.max(TK,Math.round(e*100)/100)):1,kK=()=>{if(typeof window>`u`)return 1;try{let e=window.localStorage.getItem(DK);return e?OK(Number.parseFloat(e)):1}catch{return 1}},AK=e=>{if(!(typeof window>`u`))try{window.localStorage.setItem(DK,String(e))}catch{}},jK=e=>{let t=OK(e);return typeof document<`u`&&(document.documentElement.style.zoom=t===1?``:String(t)),AK(t),t},MK=()=>{if(typeof document>`u`)return 1;let e=document.documentElement.style.zoom;if(!e)return kK();let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?OK(t):kK()},NK=()=>{if(y())return;let e=kK();e!==1&&jK(e)},PK=async()=>{if(y())try{let e=await v(`desktop_zoom_in`);if(typeof e==`number`&&Number.isFinite(e))return OK(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_in failed, using CSS zoom`,e)}return jK(MK()+EK)},FK=async()=>{if(y())try{let e=await v(`desktop_zoom_out`);if(typeof e==`number`&&Number.isFinite(e))return OK(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_out failed, using CSS zoom`,e)}return jK(MK()-EK)},IK=async()=>{if(y())try{let e=await v(`desktop_zoom_reset`);if(typeof e==`number`&&Number.isFinite(e))return OK(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_reset failed, using CSS zoom`,e)}return jK(1)},LK=9,RK=null,zK=0,BK=({pinnedTargets:e,projectTargets:t})=>[...e,...t].slice(0,LK),VK=(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},HK=e=>{let t=++zK;return RK={targets:e.targets.slice(0,LK),activate:e.activate},()=>{zK===t&&(RK=null)}},UK=e=>{if(!Number.isInteger(e)||e<1||e>LK)return!1;let t=RK,n=t?.targets[e-1];return!t||!n?!1:(t.activate(n),!0)},WK=e=>{let t=e.trim();if(!t)return null;let n=uf.getState(),r=n.createTab(t);return!r||r===`tab-invalid`?null:(n.setActiveTab(t,r),r)},GK=e=>{let t=e.trim();if(!t)return null;let n=K.getState();return!n.isBottomTerminalOpen&&n.activeMainTab!==`terminal`&&n.setBottomTerminalOpen(!0),WK(t)},KK=(e,t)=>{let n=e.trim();if(!n)return!1;let r=uf.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)},qK=e=>{let t=e.trim();if(!t)return{closed:!1,wasLastTab:!1};let n=uf.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}},JK=()=>typeof window>`u`||window.parent===window||!nl(window.location.search)?!1:(window.parent.postMessage({type:al},window.location.origin),!0),YK=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=K.getState();if(e)return!1;let n=xd();return n&&t(n)?!0:y()?(v(`desktop_close_current_window`).catch(e=>{console.warn(`[keyboard-shortcuts] failed to close current window`,e)}),!0):!1},XK=({sessionId:e,surfaceKind:t,wiringCanAbort:n,primaryCanAbort:r,pendingSend:i=!1})=>e?i||n?!0:t!==`secondary`&&r:!1,ZK=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)}},QK=()=>{let e=(0,Q.c)(69),{t}=Xn(),n=wa($K),r=wa(eq),i=wa(tq),a=wa(nq),o=ja,s=K(rq),c=K(iq),l=K(aq),u=K(oq),d=K(sq),f=K(cq),p=K(lq),h=K(uq),g=K(dq),_=K(fq),b=K(pq),x=K(mq),S=K(hq),C=K(gq),w=K(_q),T=K(vq),E=K(yq),D=K(bq),O=K(xq),k=le(Sq),A=Ia(Cq),{themeMode:j,setThemeMode:M}=fs(),{working:N}=nR(),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),$m.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=$m.getState().arm(Qm);I.current=setTimeout(()=>{let{expiresAt:e}=$m.getState();e&&Date.now()>=e&&$m.getState().clear(),I.current=null},Math.max(0,e-Date.now()))},e[6]=ee):ee=e[6];let te=ee,ne;e[7]!==A?.id||e[8]!==A?.path||e[9]!==r||e[10]!==k||e[11]!==g||e[12]!==n||e[13]!==H||e[14]!==b||e[15]!==C||e[16]!==h||e[17]!==S||e[18]!==E||e[19]!==d||e[20]!==f||e[21]!==_||e[22]!==x||e[23]!==M||e[24]!==w||e[25]!==O||e[26]!==t||e[27]!==p||e[28]!==s||e[29]!==D||e[30]!==c||e[31]!==T||e[32]!==u||e[33]!==l||e[34]!==N?(ne=()=>{let e=e=>Ec(e,O),i=e=>bc(e,O),a=wq,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=Eq,B=Oq,V=kq,U=async()=>{let e=$w(),n=e?aT(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;ji.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}=Ko.getState();await ZK({sessionId:r,currentProviderId:i,currentModelId:a,waitForConnectionOrThrow:oa,getAuthoritativeDirectoryForSession:wa.getState().getAuthoritativeDirectoryForSession,summarizeSession:Aq,onCompactFailed:e=>{ji.error(e instanceof Error?e.message:t(`chat.chatInput.toast.compactFailed`))}})},ee=t=>{let r=$m.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&&Tc(t,i)){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),te();return}let r=t.key.toLowerCase();if(r===`escape`){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),W();return}if(t.key===`Control`||t.key===`Shift`||t.key===`Alt`||t.key===`Meta`)return;if(t.metaKey||t.ctrlKey||t.altKey){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();return}let{activeMainTab:a,isModelSelectorOpen:o,isAgentSelectorOpen:s}=K.getState(),c=Qw(a)&&!V();if(r===`m`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),window.requestAnimationFrame(()=>{S(!o,{instant:!0})});return}if(r===`a`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),C(!s,{instant:!0});return}if(r===`n`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();let r=$w(),i=r?aT(r):null;i?i.shortcut(`new`):(b(`chat`),_(!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||!Tc(t,i)||V())return;let{activeMainTab:o}=K.getState();Qw(o)&&(t.preventDefault(),t.stopPropagation(),te())},ne=()=>$m.getState().pending||L.current,re=e=>{ne()&&e.preventDefault()},G=e=>{ne()&&(e.preventDefault(),e.stopPropagation())},ie=t=>{if(a(t.target)){if(!m()&&Tc(t,e(`new_terminal_tab`))){let e=xd();if(!e||!WK(e))return;t.preventDefault(),t.stopPropagation();return}if(!m()&&Tc(t,e(`previous_terminal_tab`))){let e=xd();if(!e||!KK(e,-1))return;t.preventDefault(),t.stopPropagation();return}if(!m()&&Tc(t,e(`next_terminal_tab`))){let e=xd();if(!e||!KK(e,1))return;t.preventDefault(),t.stopPropagation();return}if(Tc(t,e(`close_context_panel_tab`))){let e=xd();if(!e)return;let{closed:n,wasLastTab:r}=qK(e);if(!n)return;if(t.preventDefault(),t.stopPropagation(),r){let e=K.getState();e.setBottomTerminalOpen(!1),e.activeMainTab===`terminal`&&e.setActiveMainTab(`chat`)}return}if(Tc(t,e(`toggle_terminal`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(Tc(t,e(`toggle_bottom_panel`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),p();return}if(Tc(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),h(!n);return}}},ae=jq,oe=t=>{if(t.defaultPrevented)return;if(Tc(t,e(`close_context_panel_tab`))){(JK()||YK())&&(t.preventDefault(),t.stopPropagation());return}if(a(t.target))return;let r=Mq;if(r(t.target)&&t.ctrlKey&&!t.metaKey&&!t.shiftKey&&!t.altKey&&t.key.toLowerCase()===`t`){t.preventDefault(),ae();return}if(Tc(t,e(`open_command_palette`))){t.preventDefault(),s();return}if(Tc(t,e(`open_timeline_dialog`))){t.preventDefault(),w(!0);return}if(Tc(t,e(`toggle_prompt_navigator`))){let{activeMainTab:e,promptNavigatorEnabled:n,isSettingsDialogOpen:r,isCommandPaletteOpen:i,isHelpDialogOpen:a,isSessionSwitcherOpen:o,isAboutDialogOpen:s,isTimelineDialogOpen:c,isMultiRunLauncherOpen:l,isImagePreviewOpen:u}=K.getState();if(!n||g||m()||e!==`chat`||r||i||a||o||s||c||l||u)return;t.preventDefault(),T();return}if(Tc(t,e(`open_status`))){t.preventDefault(),sK();return}if(Tc(t,e(`open_help`))){t.preventDefault(),c();return}if(y()&&Tc(t,e(`new_mini_chat`))){t.preventDefault(),v(`desktop_open_draft_mini_chat_window`,{directory:k||A?.path||``,projectId:A?.id??null}).catch(Nq);return}let o=Tc(t,e(`new_chat`)),C=Tc(t,e(`new_chat_worktree`));if(o||C){if(t.preventDefault(),b(`chat`),_(!1),!m()&&C){Jx();return}n();return}if(Tc(t,e(`cycle_theme`))){if(t.preventDefault(),Ap()!==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(Rc(t,`in`,e(`zoom_in`))){t.preventDefault(),PK();return}if(Rc(t,`out`,e(`zoom_out`))){t.preventDefault(),FK();return}if(Tc(t,e(`zoom_reset`))){t.preventDefault(),IK();return}if(Tc(t,e(`open_settings`))){t.preventDefault();let{isSettingsDialogOpen:e}=K.getState();x(!e);return}if(Tc(t,e(`toggle_sidebar`))){t.preventDefault();let{isMobile:e,isSessionSwitcherOpen:n}=K.getState();e?_(!n):l();return}if(Tc(t,e(`focus_input`))){t.preventDefault(),document.querySelector(`textarea[data-chat-input="true"]`)?.focus();return}let E=e(`cycle_agent`),O=E&&!E.includes(`shift`)?hc(`shift+${E}`):``,j=O&&Tc(t,O)?-1:+!!Tc(t,E);if(j!==0){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s}=K.getState();if(e||n||i||a||o||!Qw(s)||!r(t.target))return;let c=$w(),l=c?aT(c):null;if(l){t.preventDefault(),l.shortcut(`cycle`,j);return}let u=Ko.getState(),d=li(u.getVisibleAgents(),u.currentAgentName,j);if(!d)return;t.preventDefault(),u.setAgent(d),K.getState().addRecentAgent(d);let f=wa.getState().currentSessionId;f&&ur.getState().saveSessionAgentSelection(f,d);return}if(i(`toggle_right_sidebar`).some(e=>Tc(t,e))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),u();return}if(Tc(t,e(`open_right_sidebar_git`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),d(!0),f(`git`);return}if(Tc(t,e(`open_right_sidebar_files`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),d(!0),f(`files`);return}if(Tc(t,e(`cycle_right_sidebar_tab`))){let{isMobile:e,rightSidebarTab:n}=K.getState();if(e)return;let r=ZG({hideGit:K.getState().activeMainTab===`git`,showBrowser:Cc(Ic())}),i=r[(r.indexOf(n)+1)%r.length];t.preventDefault(),d(!0),f(i);return}let N=e=>wK(e,wa.getState().currentSessionId,e=>{b(`chat`),_(!1),wa.getState().setCurrentSession(e.sessionId,e.directory)});if(i(`previous_session`).some(e=>Tc(t,e))){t.preventDefault(),N(-1);return}if(i(`next_session`).some(e=>Tc(t,e))){t.preventDefault(),N(1);return}for(let n=1;n<=9;n+=1)if(Tc(t,e(`switch_tab_${n}`))){UK(n)&&t.preventDefault();return}if(Tc(t,e(`toggle_terminal`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),p();return}if(Tc(t,e(`open_new_terminal`))){let{isMobile:e}=K.getState();if(e||m())return;let n=xd();if(!n||!GK(n))return;t.preventDefault();return}if(Tc(t,e(`toggle_bottom_panel`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),p();return}if(Tc(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=K.getState();if(e)return;t.preventDefault(),h(!n);return}if(Tc(t,e(`open_model_selector`))){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isAboutDialogOpen:a,activeMainTab:o,isModelSelectorOpen:s}=K.getState();if(e)return;let c=n||r||i||a,l=Qw(o);if(c||!l)return;t.preventDefault(),S(!s,{instant:!0});return}if(Tc(t,e(`cycle_thinking_variant`))){ae()&&t.preventDefault();return}if(Tc(t,e(`cycle_favorite_model_forward`))||Tc(t,e(`cycle_favorite_model_backward`))){let{isSettingsDialogOpen:n,isCommandPaletteOpen:r,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s,favoriteModels:c,addRecentModel:l}=K.getState();if(n)return;let u=r||i||a||o,d=Qw(s);if(u||!d||c.length===0)return;t.preventDefault();let f=c.length,p=Tc(t,e(`cycle_favorite_model_forward`))?1:-1,m=$w();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=Ko.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}=Ko.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(Tc(t,e(`expand_input`))){if(g)return;t.preventDefault(),D();return}if(Tc(t,e(`toggle_dictation`))){let{activeMainTab:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isSettingsDialogOpen:a}=K.getState();if(!Qw(e)||n||r||i||a)return;t.preventDefault(),window.dispatchEvent(new CustomEvent(`yuri:dictation-toggle`));return}},se=e=>{if(e.key!==`Escape`||e.isComposing)return;let t=e.target,n=!!t?.closest(`[role="dialog"]`),i=!!document.querySelector(`[data-settings-view="true"]`),a=!!(t?.closest(`.terminal-viewport-container`)||t?.getAttribute(`data-terminal-hidden-input`)===`true`),s=I(t)||z(),{isSettingsDialogOpen:c,isCommandPaletteOpen:l,isHelpDialogOpen:u,isSessionSwitcherOpen:d,isAboutDialogOpen:f,isMultiRunLauncherOpen:p,isImagePreviewOpen:m,isPromptNavigatorPanelOpen:h}=K.getState();if(n||a||s){H();return}if(h){e.preventDefault(),E(!1),H();return}if(c){e.preventDefault(),x(!1),H();return}if(i){H();return}if(l||u||d||f||p||m){H();return}let g=$w(),_=g?aT(g):null,v=g?.sessionID??wa.getState().currentSessionId,y=!!(v&&wa.getState().pendingSendMessageIDs.get(v));if(!XK({sessionId:v,surfaceKind:g?.kind,wiringCanAbort:_?.canAbort,primaryCanAbort:N.canAbort,pendingSend:y})){H();return}e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();let b=Date.now(),S=P.current;if(S&&b<S){H(),_?_.abort():(v&&kr(v),o(v??``));return}let C=g?.kind===`secondary`?b+3e3:r(3e3)??b+3e3;P.current=C,F.current&&clearTimeout(F.current);let w=Math.max(C-b,0);F.current=setTimeout(()=>{P.current&&Date.now()>=P.current&&H()},w||0)};return window.addEventListener(`keydown`,ee,!0),window.addEventListener(`beforeinput`,re,!0),window.addEventListener(`compositionstart`,G,!0),window.addEventListener(`compositionupdate`,G,!0),window.addEventListener(`compositionend`,G,!0),window.addEventListener(`keydown`,ie,!0),window.addEventListener(`keydown`,se,!0),window.addEventListener(`keydown`,oe),()=>{window.removeEventListener(`keydown`,ee,!0),window.removeEventListener(`beforeinput`,re,!0),window.removeEventListener(`compositionstart`,G,!0),window.removeEventListener(`compositionupdate`,G,!0),window.removeEventListener(`compositionend`,G,!0),window.removeEventListener(`keydown`,ie,!0),window.removeEventListener(`keydown`,se,!0),window.removeEventListener(`keydown`,oe)}},e[7]=A?.id,e[8]=A?.path,e[9]=r,e[10]=k,e[11]=g,e[12]=n,e[13]=H,e[14]=b,e[15]=C,e[16]=h,e[17]=S,e[18]=E,e[19]=d,e[20]=f,e[21]=_,e[22]=x,e[23]=M,e[24]=w,e[25]=O,e[26]=t,e[27]=p,e[28]=s,e[29]=D,e[30]=c,e[31]=T,e[32]=u,e[33]=l,e[34]=N,e[35]=ne):ne=e[35];let re=A?.id,G=A?.path,ie;e[36]!==r||e[37]!==k||e[38]!==a||e[39]!==g||e[40]!==n||e[41]!==H||e[42]!==b||e[43]!==C||e[44]!==h||e[45]!==S||e[46]!==E||e[47]!==d||e[48]!==f||e[49]!==_||e[50]!==x||e[51]!==M||e[52]!==w||e[53]!==O||e[54]!==t||e[55]!==re||e[56]!==G||e[57]!==p||e[58]!==s||e[59]!==D||e[60]!==c||e[61]!==T||e[62]!==u||e[63]!==l||e[64]!==N?(ie=[n,o,s,c,l,u,d,f,p,h,g,_,b,x,S,C,w,T,E,D,M,N,r,H,te,W,a,k,re,G,O,t],e[36]=r,e[37]=k,e[38]=a,e[39]=g,e[40]=n,e[41]=H,e[42]=b,e[43]=C,e[44]=h,e[45]=S,e[46]=E,e[47]=d,e[48]=f,e[49]=_,e[50]=x,e[51]=M,e[52]=w,e[53]=O,e[54]=t,e[55]=re,e[56]=G,e[57]=p,e[58]=s,e[59]=D,e[60]=c,e[61]=T,e[62]=u,e[63]=l,e[64]=N,e[65]=ie):ie=e[65],Z.useEffect(ne,ie);let ae,oe;e[66]===H?(ae=e[67],oe=e[68]):(oe=()=>()=>{H(),W()},ae=[H,W],e[66]=H,e[67]=ae,e[68]=oe),Z.useEffect(oe,ae)};function $K(e){return e.openNewSessionDraft}function eq(e){return e.armAbortPrompt}function tq(e){return e.clearAbortPrompt}function nq(e){return e.currentSessionId}function rq(e){return e.toggleCommandPalette}function iq(e){return e.toggleHelpDialog}function aq(e){return e.toggleSidebar}function oq(e){return e.toggleRightSidebar}function sq(e){return e.setRightSidebarOpen}function cq(e){return e.setRightSidebarTab}function lq(e){return e.toggleBottomTerminal}function uq(e){return e.setBottomTerminalExpanded}function dq(e){return e.isMobile}function fq(e){return e.setSessionSwitcherOpen}function pq(e){return e.setActiveMainTab}function mq(e){return e.setSettingsDialogOpen}function hq(e){return e.setModelSelectorOpen}function gq(e){return e.setAgentSelectorOpen}function _q(e){return e.setTimelineDialogOpen}function vq(e){return e.togglePromptNavigatorPanel}function yq(e){return e.setPromptNavigatorPanelOpen}function bq(e){return e.toggleExpandedInput}function xq(e){return e.shortcutOverrides}function Sq(e){return e.currentDirectory}function Cq(e){return e.getActiveProject()}function wq(e){return e instanceof Element&&!!(e.closest(`[data-terminal-view="true"]`)||e.closest(`.terminal-viewport-container`)||e.getAttribute(`data-terminal-hidden-input`)===`true`)}function Tq(e){return e.getClientRects().length>0}function Eq(){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(Tq)}function Dq(){document.querySelector(`textarea[data-chat-input="true"]`)?.focus({preventScroll:!0})}function Oq(){window.requestAnimationFrame(Dq)}function kq(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i}=K.getState();return e||t||n||r||i}function Aq(e,t,n,r){return Te.summarizeSession(e,t,n,r)}function jq(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i,activeMainTab:a}=K.getState();if(e||t||n||r||i||!Qw(a))return!1;let o=$w();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=Ko.getState();if(s.getCurrentModelVariants().length===0)return!1;s.cycleCurrentVariant();let c=Ko.getState().currentVariant,l=wa.getState().currentSessionId,u=Ko.getState().currentAgentName,d=Ko.getState().currentProviderId,f=Ko.getState().currentModelId;return l&&u&&d&&f&&ur.getState().saveAgentModelVariantForSession(l,u,d,f,c),u&&d&&f&&Ko.getState().saveAgentModelSelection(u,d,f,c),!0}function Mq(e){return e instanceof HTMLTextAreaElement&&e.getAttribute(`data-chat-input`)===`true`}function Nq(e){console.warn(`[keyboard-shortcuts] failed to open draft mini chat window`,e)}var Pq=3,Fq=(e,t)=>{if(typeof e!=`string`)return t;let n=e.trim().replace(/\s+/g,` `);return n?n.slice(0,48):t},Iq=(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:Fq(e.title,`Session ${r.length+1}`)}),r.length>=Pq))break}return r},Lq=()=>{let e=(0,Q.c)(9),t=Uo(),n=wa(Rq),r;e[0]!==n||e[1]!==t?(r=Iq(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`||!x())){try{i.length===0?localStorage.removeItem(Dc):localStorage.setItem(Dc,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 Rq(e){return e.currentSessionId}var zq=e=>Number.isFinite(e)?`${Math.max(0,Math.round(e))}px`:`0px`,Bq=(e,t,n,r)=>{e.style.setProperty(`--yuri-wco-left-inset`,zq(t)),e.style.setProperty(`--yuri-wco-right-inset`,zq(n)),e.style.setProperty(`--yuri-wco-titlebar-height`,zq(r))},Vq=()=>{let e=(0,Q.c)(1),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],Z.useEffect(Hq,t)};function Hq(){if(typeof window>`u`||!x())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){Bq(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));Bq(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),Bq(e,0,0,0)}}var Uq=3e4,Wq=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,Gq=e=>e instanceof Zo?e.status===501?`unsupported`:e.status>=400&&e.status<500&&e.status!==408&&e.status!==429&&e.code!==`revision_conflict`?`permanent`:`retry`:`retry`,Kq=(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})}),qq=(e,t)=>e.then(e=>{if(t?.aborted)throw new DOMException(`Aborted`,`AbortError`);return e}),Jq={fetchSnapshot:e=>qq(ns(Cn),e),refreshSnapshot:e=>qq(ya(Cn),e),fetchOrder:yr,setOrder:Yo,waitInvalidation:Li,captureRuntime:()=>({transportIdentity:o(),generation:c()}),isCurrent:e=>e.transportIdentity===o()&&e.generation===c(),sleep:Kq,createRequestID:()=>typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`worktree-order-${Date.now()}-${Math.random().toString(36).slice(2)}`},Yq=new Map,Xq=()=>{for(let e of Yq.values())e.controller.abort();Yq.clear()},Zq=(e,t,n,r=Jq)=>{Yq.get(e)?.controller.abort();let i={projectDirectory:Wq(t),orderedPaths:[...n],capture:r.captureRuntime(),controller:new AbortController,backoffMs:500,running:!1};Yq.set(e,i),Qq(e,r)},Qq=async(e,t=Jq)=>{let n=Yq.get(e);if(!(!n||n.running)){n.running=!0;try{for(;;){let n=Yq.get(e);if(!n||!t.isCurrent(n.capture)||n.controller.signal.aborted)return;let r=sr.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)||Yq.get(e)!==n)return;let a=i.worktreeOrder??{projectDirectory:n.projectDirectory,orderedPaths:n.orderedPaths,revision:i.revision};sr.getState().setServerRevision(e,a.revision),sr.getState().resolvePendingWorktreeOrder(e,a.revision),Yq.delete(e);return}catch(r){if(n.controller.signal.aborted||!t.isCurrent(n.capture)||Yq.get(e)!==n)return;if(r instanceof Zo&&r.code===`revision_conflict`)try{let r=await t.fetchOrder(n.projectDirectory,n.controller.signal);if(Yq.get(e)!==n||!t.isCurrent(n.capture))return;sr.getState().applyServerWorktreeOrder(e,r.orderedPaths,r.revision),n.expectedRevision=void 0,n.requestID=void 0,n.backoffMs=500;continue}catch(e){if(Gq(e)!==`retry`)return}else if(Gq(r)!==`retry`)return;if(await t.sleep(n.backoffMs,n.controller.signal).catch(()=>{}),n.backoffMs=Math.min(n.backoffMs*2,Uq),n.controller.signal.aborted)return}}}finally{Yq.get(e)===n&&(!t.isCurrent(n.capture)||n.controller.signal.aborted)&&Yq.delete(e),Yq.get(e)===n&&(n.running=!1)}}},$q=(e,t,n,r)=>{let i=new Map(t.map(e=>[Wq(e.path),e.id]));for(let t of e){let e=i.get(Wq(t.projectDirectory));e&&r.isCurrent(n)&&sr.getState().applyServerWorktreeOrder(e,t.orderedPaths,t.revision)}},eJ=(e,t=Jq)=>{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();$q(r.worktreeOrders,o,a,t);let s=new Set(r.worktreeOrders.map(e=>Wq(e.projectDirectory)));for(let e of o){let n=sr.getState(),r=n.orderByProject[e.id];n.pendingProjectIDs[e.id]?Zq(e.id,e.path,r??[],t):r?.length&&!s.has(Wq(e.path))&&(n.markPendingWorktreeOrder(e.id),Zq(e.id,e.path,r,t))}break}catch(e){if(Gq(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,Uq)}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,$q(s.worktreeOrders,e(),a,t),r=500}catch(e){if(Gq(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,Uq)}})()},stop:r}},tJ=()=>{let e=(0,Q.c)(2),t=Ia(rJ),n;e[0]===t?n=e[1]:(n=[t],e[0]=t,e[1]=n),Z.useEffect(oJ,n)};function nJ(e){return[e.id,Wq(e.path)]}function rJ(e){return JSON.stringify(e.projects.map(nJ))}function iJ(e,t,n){return Zq(e,t,n)}function aJ(){return Ia.getState().projects}function oJ(){let e=o();sr.getState().activateWorktreeOrderRuntime(e);let t=Ti(iJ),n=eJ(aJ);n.start();let r=i(e=>{l(e)&&(Xq(),sr.getState().activateWorktreeOrderRuntime(o()),n.start())});return()=>{t(),r(),n.stop(),Xq()}}var sJ=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,cJ=e=>{let t=!1,n=0,r=0,i=0,a=!1,o=new Set,s=new Map,c=new Map,l=new Set,u=new Set,d=new Map,f=new Set,p=new Set,m=new Set,h=``,g=[],_=t=>{let n=sJ(t);return e.getProjects().find(e=>sJ(e.path)===n)},v=(n,i=150,a=!1)=>{let l=sJ(n.path);if(a&&(o.has(l)||s.has(l)||c.has(l)))return;let u=c.get(l);u&&e.clearTimer(u.timer);let d=r,f=e.setTimer(()=>{!t||d!==r||(c.delete(l),s.set(l,n),y(d))},i);c.set(l,{timer:f,epoch:d})},y=(n=r)=>{if(!(!t||n!==r))for(;i<2&&s.size>0;){let n=[...s.entries()].find(([e])=>!o.has(e));if(!n)break;let[a,c]=n;s.delete(a),i+=1,o.add(a);let l=e.generation(),u=r;e.refresh(c,{isCurrent:()=>t&&u===r&&l===e.generation()}).then(n=>{if(!(!t||u!==r||l!==e.generation())){m.add(a);for(let t of n.addedDirectories){let n=sJ(t);(!e.needsSessionSync||e.needsSessionSync(n))&&f.add(n)}if(e.needsSessionSync)for(let t of n.worktrees){let n=sJ(t.path);e.needsSessionSync(n)&&f.add(n)}b(u,l),x()}}).then(()=>{t&&u===r&&l===e.generation()&&d.delete(a)}).catch(()=>{if(!t||u!==r||l!==e.generation())return;let n=(d.get(a)??0)+1;d.set(a,n),t&&u===r&&v(c,[1e3,2e3,5e3,15e3,3e4][Math.min(n-1,4)])}).finally(()=>{u===r&&(--i,o.delete(a),y(u))})}},b=(n,i)=>{if(f.size===0)return;let a=[...f];f.clear(),e.syncAdded(a).catch(()=>{if(t&&n===r&&i===e.generation()){for(let e of a)f.add(e);let o=e.setTimer(()=>{l.delete(o),t&&n===r&&b(n,i)},1e3);l.add(o)}})},x=()=>{if(m.size!==e.getProjects().length)return;let t=e.getCatalog();for(let e of p){let n=e.slice(e.indexOf(`:`)+1);[...t.entries()].some(([e,t])=>sJ(e)===n||t.some(e=>sJ(e.path)===n))||u.add(e)}},S=()=>{m.clear();for(let t of e.getProjects())v(t,0,!0)},C=()=>{let t=e.getCatalog(),r=e.getProjects(),i=new Set;for(let t of e.getActiveDirectories())t.trim()&&i.add(sJ(t));for(let e of[...p]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||p.delete(e)}for(let e of[...u]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||u.delete(e)}for(let e of i)if(!r.find(n=>{let r=sJ(n.path),i=t.get(r)?.some(t=>sJ(t.path)===e);return e===r||i})){let t=`${n}:${e}`;!u.has(t)&&!p.has(t)&&(p.add(t),S())}},w=()=>{r+=1,u.clear(),p.clear(),d.clear(),f.clear(),m.clear();for(let t of c.values())e.clearTimer(t.timer);c.clear();for(let t of l)e.clearTimer(t);l.clear(),s.clear(),o.clear(),i=0};return{start:()=>{t||e.isVSCode()||(t=!0,a=!1,g.push(e.subscribeEvents(e=>{if(e.type===`event-stream-ready`){if(!a){a=!0,S();return}n+=1,w(),S()}if(e.type===`worktree-topology-changed`&&e.projectDirectory){let t=_(e.projectDirectory);t&&v(t)}})),h=e.getProjects().map(e=>`${e.id}\u0000${sJ(e.path)}`).sort().join(`
|
|
6601
|
+
`)}function XV(e,t=80){let n=YV(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var ZV=new Set;function QV(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(ZV),a,o;return n[0]!==e||n[1]!==t?(a=()=>{let n=e?.current;if(i(ZV),!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=$V,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 $V(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 eH=160,tH=28,nH=12,rH=6,iH=30,aH=12,oH=18,sH=80,cH=4,lH=10,uH=14,dH=20,fH=48,pH=160,mH=(e,t)=>e.map(e=>{let n=t.get(e)??[],r=YV(n),i=M_(r,{citationIcons:R_(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>eH?`${s.slice(0,eH)}…`:s}}),hH=[1,.6,.35,.15],gH=(e,t,n)=>{let r=n?uH:lH;if(t===null)return r;let i=hH[Math.abs(e-t)]??0;return Math.round(r+(dH-r)*i)};function _H({turnIds:e,previewsByTurnId:t,activeTurnId:n,scrollRef:r,turnByMessageId:i,repliesByTurnId:a,onSelectTurn:o,canLoadEarlier:s,isLoadingOlder:c,onLoadEarlier:l}){let{t:u}=Xn(),d=QV(r,i),f=K(e=>e.isPromptNavigatorPanelOpen),p=K(e=>e.setPromptNavigatorPanelOpen),m=Z.useRef(null),h=Z.useRef(null),[g,_]=Z.useState(null),[v,y]=Z.useState(0),[b,x]=Z.useState(!1);Z.useEffect(()=>{let e=h.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){x(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.left+rH+tH;x(r.left<i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let S=Z.useMemo(()=>mH(e,t),[t,e]),C=Math.min(S.length,iH),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,iH),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,iH),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)/aH),i=Math.min(N.current,iH);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,iH)),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<=oH&&D?i=-1:r>=n.height-oH&&O&&(i=1),I.current=i,i===0){V();return}F.current===null&&(F.current=window.setInterval(H,sH))},[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)},pH)},[ee]);Z.useEffect(()=>()=>{W.current!==null&&window.clearTimeout(W.current)},[]);let ne=Z.useCallback(e=>{ee(),P.current=e.clientY;let t=B(e.clientY);t!==null&&_(Math.min(N.current-1,M.current+t)),U(e.clientY)},[ee,B,U]),re=Z.useCallback(()=>{P.current=null,V(),te()},[te,V]),G=Z.useCallback(()=>{p(!1)},[p]),ie=Z.useCallback(e=>{if(e===null)return;let t=S[e];t&&(o(t.turnId),V(),_(null),G(),m.current?.blur())},[G,o,S,V]),ae=Z.useCallback(e=>{let t=B(e.clientY);t!==null&&ie(Math.min(S.length-1,M.current+t))},[ie,S.length,B]);Z.useEffect(()=>{if(!f)return;let e=m.current;!e||e===document.activeElement||(e.focus(),_(e=>{if(e!==null)return e;let t=j>=0?j:S.length-1;return L(t),t}))},[j,L,f,S.length]),Z.useEffect(()=>()=>{p(!1)},[p]);let oe=Z.useCallback(e=>{if(S.length===0)return;let t=g??(j>=0?j:S.length-1),n=e=>{let t=Math.max(0,Math.min(S.length-1,e));L(t),_(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(S.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),ie(t);return}e.key===`Escape`&&(e.preventDefault(),_(null),G(),m.current?.blur())},[j,G,L,ie,g,S.length]),se=Z.useCallback(()=>{V(),_(null),G()},[G,V]),ce=Z.useRef(null),le=Z.useRef(g);le.current=g;let ue=g!==null,de=Z.useRef(0);Z.useEffect(()=>{let e=ce.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),de.current+=e.deltaY;let t=Math.trunc(de.current/fH);if(t===0)return;de.current-=t*fH;let n=le.current;if(n===null)return;let r=Math.max(0,Math.min(N.current-1,n+t));r!==n&&(L(r),_(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[L,ue]);let fe=g===null?void 0:S[g],pe=fe?a?.get(fe.turnId):void 0,me=Math.max(0,T-cH),he=Math.min(S.length,E+cH),ge=S.slice(me,he),_e=D||O?`linear-gradient(to bottom, ${D?`transparent, black 14%`:`black`}, ${O?`black 86%, transparent`:`black`})`:void 0;return S.length===0?null:(0,$.jsx)(`nav`,{ref:h,"aria-label":u(`chat.promptNavigator.aria`),className:`pointer-events-none absolute left-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-start`,children:[s?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-ml-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,c?`cursor-wait opacity-70`:void 0),"aria-label":A,title:A,disabled:c,onClick:e=>{e.stopPropagation(),c||l()},children:c?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:m,role:`listbox`,tabIndex:-1,"aria-activedescendant":fe?`prompt-rail-tick-${fe.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${b?nH:tH}px`,height:`${C*aH}px`},onMouseMove:ne,onMouseLeave:re,onClick:ae,onKeyDown:oe,onBlur:se,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:_e?{maskImage:_e,WebkitMaskImage:_e}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${T*aH}px)`},children:ge.map((e,t)=>{let n=me+t,r=d.has(e.turnId),i=g===n,a=gH(n,g,r);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":i,"aria-current":r?`true`:void 0,"aria-label":e.preview.trim()||k,className:`pointer-events-none absolute left-1 flex items-center justify-start`,style:{top:`${n*aH}px`,height:`${aH}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)*aH}px`},onMouseEnter:ee,onMouseLeave:te,onMouseMove:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),ie(g)},children:[(0,$.jsx)(`p`,{className:`truncate font-medium leading-relaxed text-[var(--surface-foreground)]`,children:fe.preview||k}),pe?(0,$.jsx)(`p`,{className:`mt-2 line-clamp-4 whitespace-pre-line [overflow-wrap:anywhere] leading-relaxed text-[var(--surface-mutedForeground)]`,children:pe}):null]}):null]})]})})}var vH=100,yH=(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},bH=e=>{let t=e.raf??requestAnimationFrame,n=e.caf??cancelAnimationFrame,r=e.ResizeObserver??globalThis.ResizeObserver,i=e.MutationObserver??globalThis.MutationObserver,a,o,s,c,l,u,d=!0,f=new Map,p=[],m=()=>{c===void 0&&(c=t(()=>{c=void 0,g()}))},h=()=>{let e=a;if(!e){p=[],d=!1;return}let t=e.getBoundingClientRect().top;p=[...f].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),p.sort((e,t)=>e.top-t.top),d=!1},g=()=>{let t=a;if(!t)return;d&&h();let n=yH(p,t.scrollTop+vH);!n||n===u||(u=n,e.onActive(n))},_=()=>{let e=a;if(e){if(clearTimeout(l),l=void 0,o?.disconnect(),o=void 0,r){o=new r(()=>{clearTimeout(l),l=setTimeout(()=>{d=!0,m()},100)}),o.observe(e);for(let e of f.values())o.observe(e)}if(s?.disconnect(),s=void 0,i){s=new i(()=>{d=!0,m()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}d=!0,m()}},v=e=>{a!==e&&(a=e,u=void 0,_())},y=(e,t)=>{let n=f.get(t);n&&n!==e&&o?.unobserve(n),f.set(t,e),o&&o.observe(e),d=!0,m()},b=e=>{let t=f.get(e);t&&(o?.unobserve(t),f.delete(e),d=!0,m())},x=()=>{d=!0,m()},S=()=>{for(let e of f.values())o?.unobserve(e);f.clear(),p=[],u=void 0,d=!0};return{setContainer:v,register:y,unregister:b,onScroll:m,markDirty:x,clear:S,destroy:()=>{c!==void 0&&n(c),c=void 0,clearTimeout(l),l=void 0,S(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>u}},xH=10,SH=`${xH}vh`,CH=`56px`;`${CH}`;var wH=(e,t)=>e?56:t<=0?96:Math.max(48,xH/100*t),TH=(e,t)=>({sessionId:e,viewportKey:t}),EH=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,DH=(e,t)=>EH(e,t),OH=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),kH=150,AH=1500,jH=2,MH=350,NH=600,PH=8e3,FH=24,IH=2,LH=(e,t)=>e<t,RH=()=>typeof performance<`u`?performance.now():Date.now(),zH=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),BH=e=>e.scrollHeight-e.scrollTop-e.clientHeight,VH=e=>BH(zH(e)),HH=e=>e.scrollHeight-e.clientHeight>1,UH=(e,t)=>BH(e)<=wH(t,e.clientHeight),WH=({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(TH(n,r));w.current=TH(n,r);let T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(null),O=Z.useRef(0),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(0),M=Z.useRef(!1),N=Z.useRef(!1),P=Z.useRef(null),F=Z.useRef(0),I=Z.useRef(!1),L=Z.useRef(null),R=Z.useRef(null),z=J(()=>{F.current=RH()+450,R.current=null}),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(0),ee=Z.useRef(!1),te=Z.useRef(null),ne=Z.useRef(null),re=Z.useRef(null),G=hr(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{l.current!==f.current&&(f.current=l.current,d(l.current))});let ie=J(e=>{x.current!==e&&(x.current=e,m(e))}),ae=J(e=>{E.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:RH()},D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{E.current=null,D.current=null},AH)}),oe=J(e=>{let t=E.current;return t?RH()-t.time>AH?(E.current=null,!1):Math.abs(e.scrollTop-t.top)<jH:!1}),se=J(()=>RH()<j.current),ce=J(()=>{V.current=!1,H.current&&=(clearTimeout(H.current),null),U.current&&=(clearTimeout(U.current),null)}),le=J(()=>{H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,ce()},NH)}),ue=J(()=>{let e=l.current;e&&(V.current=!0,W.current=e.scrollHeight,le(),U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{U.current=null,ce()},PH))}),de=J(e=>{let t=l.current;if(!t){g(!1),v(!1);return}let n=e??zH(t),r=HH(n);if(g(r),!r){v(!1);return}let i=x.current===`released`&&!UH(n,S.current);v(i)}),fe=J(()=>{O.current+=1,k.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(k.current),k.current=null),A.current?.(),A.current=null});Z.useEffect(()=>()=>fe(),[u]);let pe=J(()=>{if(!e)return;let n=l.current;if(!n)return;if(fe(),t?.current?.scrollToBottom({behavior:`auto`,reveal:!1})){ae(n),de();return}let r=O.current,i=n.style.overflowX,a=n.style.overflowY,o=n.style.scrollBehavior;n.style.scrollBehavior=`auto`,n.style.overflow=`hidden`,n.scrollTop=n.scrollHeight,n.scrollHeight,n.style.overflowX=i,n.style.overflowY=a,n.style.scrollBehavior=o;let s=()=>{ae(n),n.scrollTop=n.scrollHeight,B.current=n.scrollTop};if(s(),de(),typeof window>`u`)return;let c=0,u=()=>{LH(RH(),F.current)||fe()};n.addEventListener(`touchstart`,u,{passive:!0,once:!0}),A.current=()=>n.removeEventListener(`touchstart`,u);let d=()=>{if(r===O.current){if(VH(n)>IH&&s(),c+=1,c>=FH){k.current=null,A.current?.(),A.current=null,de();return}k.current=window.requestAnimationFrame(d)}};k.current=window.requestAnimationFrame(d)}),me=J(e=>{let n=l.current;if(n&&(ae(n),!t?.current?.scrollToBottom({behavior:e,reveal:!1}))){if(e===`smooth`){n.scrollTo({top:n.scrollHeight,behavior:e});return}n.scrollTop=n.scrollHeight}}),he=J((t,n=`auto`)=>{if(!e)return;let r=l.current;if(t&&x.current!==`following`&&ie(`following`),r&&!(!t&&x.current!==`following`)){if(VH(r)<jH){ae(r);return}me(t?n:`auto`)}}),ge=J(e=>{let t=l.current;if(!t)return;let n=e??zH(t);HH(n)&&x.current!==`released`&&(ie(`released`),de(n))}),_e=J((e=`instant`,n)=>{if(I.current=!1,ee.current=!1,ie(`following`),ce(),fe(),t?.current?.scrollToBottom({behavior:e===`smooth`?`smooth`:`auto`,...n})){let e=l.current;e&&ae(e),de();return}if(e===`instant`){pe();return}fe(),he(!0,`smooth`),de()}),ve=J(()=>{ee.current=!1,he(!0)}),ye=J(()=>{I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ie(`released`),de()}),be=J(()=>{ee.current=!0,ye()}),xe=J(()=>{ee.current=!1}),Se=Z.useRef(c);Se.current=c;let Ce=J(()=>{LH(RH(),F.current)||(I.current=!1,fe(),t?.current?.cancelScroll(),ce(),ge())}),we=J(()=>{F.current=0,Ce(),Se.current?.()}),Te=J(()=>{te.current!==null&&(clearTimeout(te.current),te.current=null);let e=ne.current;if(e){if(!e.identity.sessionId){ne.current=null;return}G(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),ne.current=null}}),Ee=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=OH(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),te.current===null&&(te.current=setTimeout(()=>{te.current=null,Te()},kH))}),De=J(()=>{Te()}),Oe=J(async(e=w.current)=>{if(!e.sessionId||x.current===`released`&&EH(e,T.current))return!1;ee.current=!1;let t=l.current;return t?(re.current=null,ie(`following`),z(),S.current?pe():he(!0),B.current=t.scrollTop,ue(),de(),!1):(re.current=e,ie(`following`),!1)});Z.useEffect(()=>{let e=w.current,t=T.current;EH(e,t)||(Te(),fe(),z(),T.current=e,I.current=!1,L.current=null,E.current=null,B.current=0,ce(),ee.current=!1,ie(`following`),re.current=null,n&&n!==t?.sessionId&&_O.getInstance().recordSessionStart(n))},[n,r]),Z.useEffect(()=>{a&&!ee.current&&x.current===`following`&&he(!0)},[a]),Z.useEffect(()=>{b(p===`following`&&a)},[p,a]),Z.useLayoutEffect(()=>{if(!u)return;let e=re.current;e&&DH(e,w.current)&&Oe(e)},[u,n,r]);let ke=J(()=>{let e=l.current;if(!e)return;let t=zH(e),n=B.current;B.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(de(t),ee.current){Ee();return}if(HH(t)){if(UH(t,S.current)){let e=Math.min(n,Math.max(0,t.scrollHeight-t.clientHeight));if(t.scrollTop<e-.5){Ce(),Ee();return}(x.current===`following`||r&&I.current)&&(ie(`following`),I.current=!1),Ee();return}if(x.current===`following`&&(oe(e)||se()||i)){M.current||he(!1),Ee();return}(x.current===`following`||!r)&&Ce(),Ee()}});Z.useEffect(()=>{!e||!u||(B.current=u.scrollTop)},[u,e]);let Ae=J(e=>{let t=l.current;if(t){if(e.deltaY>0){Ml(t,e.target)||(I.current=!0);return}e.deltaY>=0||Pl(t,e.target)||we()}}),je=J(e=>{I.current=!1;let t=e.touches.item(0);R.current=t?{x:t.clientX,y:t.clientY,dx:0,dy:0}:null}),Me=J(e=>{let t=l.current,n=e.touches.item(0);if(!n){R.current=null;return}let r=R.current;if(!r)return;let i=n.clientY-r.y,a=i*r.dy<0,o=(a?0:r.dx)+n.clientX-r.x,s=(a?0:r.dy)+i;if(R.current={x:n.clientX,y:n.clientY,dx:o,dy:s},!(Math.abs(o)>=Math.abs(s))&&t){if(s<-2){Ml(t,e.target)||(I.current=!0);return}if(!(s<=0)){if(Pl(t,e.target)){R.current.dx=0,R.current.dy=0;return}s<=2||we()}}}),Ne=J(()=>{R.current=null}),Pe=J(e=>{let t=e.target;if(!(e.defaultPrevented||t instanceof HTMLElement&&(t.isContentEditable||t.closest(`input, textarea, select`)))){if(!e.altKey&&!e.ctrlKey&&!e.metaKey&&[`ArrowDown`,`PageDown`,`End`].includes(e.key)){let e=l.current;e&&!Ml(e,t)&&(I.current=!0);return}xl(e)&&we()}}),Fe=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&(F.current=0,Ce(),L.current={id:e.pointerId,y:e.clientY})}),Ie=J(e=>{let t=L.current;!t||t.id!==e.pointerId||(e.clientY!==t.y&&(I.current=e.clientY>t.y),t.y=e.clientY)}),Le=J(()=>{L.current=null}),Re=J(()=>{I.current=!1}),ze=Z.useMemo(()=>()=>void 0,[]),Be=e&&u?u:ze,Ve=Z.useMemo(()=>({passive:!0}),[]);qn(`scroll`,ke,Be,Ve),qn(`scrollend`,Re,Be,Ve),qn(`wheel`,Ae,Be,Ve),qn(`touchstart`,je,Be,Ve),qn(`touchmove`,Me,Be,Ve),qn(`touchend`,Ne,Be,Ve),qn(`touchcancel`,Ne,Be,Ve),qn(`keydown`,Pe,Be),qn(`pointermove`,Ie,e&&typeof window<`u`?window:ze,!0),qn(`pointerup`,Le,e&&typeof window<`u`?window:ze,!0),qn(`pointercancel`,Le,e&&typeof window<`u`?window:ze,!0),qn(`pointerdown`,Fe,e&&typeof window<`u`?window:ze,!0);let He=J(()=>{let e=l.current;if(M.current){de(e?zH(e):void 0);return}if(ee.current){de(e?zH(e):void 0);return}if(!e){de(void 0);return}let t=zH(e);if(!HH(t)){de(t);return}if(de(t),V.current){let n=t.scrollHeight>W.current+1;W.current=t.scrollHeight,BH(t)<=jH?ae(e):he(!0),n&&le();return}if(x.current===`following`){if(BH(t)<=jH){ae(e);return}he(!1)}}),Ue=typeof ResizeObserver<`u`,We=Ue&&e?u:null,Ge=Ue&&e&&u&&u.firstElementChild instanceof Element?u.firstElementChild:null;Hn(We,He),Hn(Ge,He);let Ke=J(()=>{P.current!==null&&(clearTimeout(P.current),P.current=null)}),qe=J(e=>{M.current=!0,typeof e==`number`&&e>0?j.current=RH()+e+MH:j.current=Math.max(j.current,RH()+MH)}),Je=J(e=>{let t=e.detail;if(t){if(t.open===!0){qe(),Ke(),P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},1500);return}Ke(),qe()}}),Ye=J(e=>{let t=e.detail;t&&(Ke(),qe(t.durationMs))}),Xe=J(e=>{let t=e.detail;Ke(),t?.open===!0?(N.current=!0,M.current=!0):(N.current=!1,M.current=!0,P.current=setTimeout(()=>{P.current=null,N.current||(M.current=!1)},MH)),de()}),Ze=e&&typeof window<`u`?window:ze;qn(`yuri:keyboard-intent`,Je,Ze),qn(`yuri:keyboard-anim`,Ye,Ze),qn(`yuri:keyboard-settled`,Xe,Ze),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{Ke(),M.current=!1,N.current=!1}},[e]),Z.useEffect(()=>{e&&de()},[e,i]);let Qe=J(t=>{if(e){if(t===`animation`&&(j.current=RH()+MH),de(),V.current){he(!0),le();return}x.current===`following`&&he(!1)}}),$e=Z.useRef(new Map),et=J(t=>{let n=$e.current.get(t);if(n)return n;let r=()=>{e&&x.current===`following`&&he(!1)},i={onChunk:r,onComplete:()=>{e&&de()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return $e.current.set(t,i),i});Z.useEffect(()=>()=>{D.current&&=(clearTimeout(D.current),null),fe(),ce(),Te(),te.current!==null&&(clearTimeout(te.current),te.current=null)},[]);let tt=J(e=>{s?.(e)}),nt=!!s;return Z.useEffect(()=>{if(!e||!nt)return;let t=u;if(!t)return;let n=null,r=bH({onActive:e=>{e!==n&&(n=e,tt(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,nt]),{scrollRef:l,state:p,isPinned:p===`following`,isOverflowing:h,isFollowingProgrammatically:y,showScrollButton:_,notifyContentChange:Qe,getAnimationHandlers:et,goToBottom:_e,scrollToBottomOnSend:ve,releaseAutoFollow:ye,beginHistoryViewportPreservation:be,endHistoryViewportPreservation:xe,saveSnapshotNow:De,restoreSnapshot:Oe}},GH=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),KH=`data-yuri-timeline-park-end`,qH=e=>{if(!e)return null;let t=e.getAttribute(KH);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},JH=(e,t)=>t!==null&&Number.isFinite(t)?GH({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),YH=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),XH=()=>{let e=document.documentElement;return e.classList.contains(`yuri-keyboard-open`)||e.classList.contains(`yuri-kb-animating`)},ZH=e=>{if(XH()||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)},QH=e=>{let t=Z.useRef($T()),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=_E(e);return i!==t&&(_.current=i,n.current=void 0,r.current=void 0),i},y=J(t=>{let r=e.scopeRef.current;if(!r)return;let i=v(r);n.current=bE(r,t,n.current,i)}),b=J(e=>{let n=_.current,r=v(e);return r!==n&&y(t.current),r}),x=J(e=>{e!==t.current&&(t.current=e,y(e))}),S=J(()=>{if(g(a),t.current.phase!==`snapping`)return;let e=t.current.rest;a.current=window.setTimeout(()=>{a.current=null;let n=dE(t.current);x(n),n.rest===`compact`&&e===`compact`&&(o.current=Date.now()+320,s.current=!0)},240)}),C=J(()=>{let n=e.scopeRef.current;!n||!h.current||x(rE(t.current,ZH(n)))}),w=J(e=>s.current?Date.now()>=o.current?(s.current=!1,!1):e>=80?(s.current=!1,o.current=0,!1):!0:!1),T=()=>{m.current={direction:null,px:0,at:0}},E=()=>{let e=m.current;return!e.direction||e.px<16||Date.now()-e.at>250?null:e.direction},D=J(()=>{if(g(i),!h.current||c.current>0||t.current.phase!==`tracking`)return;let e=uE(t.current,E());x(e),S()}),O=J(()=>{u.current=!1,d.current=0;for(let e of l.current.values())e.startX=e.currentX,e.startY=e.currentY}),k=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)}),A=J(t=>{if(h.current){if(c.current===0){l.current.clear(),O(),T();let t=e.scrollRef.current;if(t){let e=YH(t);p.current=e,f.current=JH(e,qH(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)}}),j=J(()=>{if(!h.current)return;let n=e.scrollRef.current,o=e.scopeRef.current;if(!n||!o)return;let s=ZH(o),l=YH(n),_=JH(l,qH(n)),v=f.current,y=p.current;if(f.current=_,p.current=l,n.hasAttribute(`data-yuri-timeline-anchoring`)){T(),O();return}let C=b(o);r.current=yE(o,_,r.current,C);let E=u.current&&(c.current>0||Date.now()-d.current<=1200),k=y!==null&&(y.scrollHeight!==l.scrollHeight||y.clientHeight!==l.clientHeight),A=E&&!k,j=l.scrollTop<0||y!==null&&y.scrollTop<0,M=A&&!j&&v!==null;if(!M)T();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=rE(N,s);if(s||(P=cE(P,_,{previousDistance:M?v:null,suppressReturn:A&&w(_),userDriven:A})),x(P),A){if(g(i),P.phase===`snapping`){(N.phase!==`snapping`||N.rest!==P.rest||N.progress!==P.progress)&&S();return}N.phase===`snapping`&&g(a),P.phase===`tracking`&&c.current===0&&(i.current=window.setTimeout(()=>{i.current=null,D()},120))}}),M=J(()=>{u.current&&(c.current>0||Date.now()-d.current<=1200)&&D()}),N=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():O(),t.current.phase===`tracking`&&(g(i),i.current=window.setTimeout(()=>{i.current=null,D()},120)))}}),P=J(e=>{N(e,!0)}),F=J(e=>{N(e,!1)}),I=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)}),L=J(n=>{if(!h.current)return;let r=n.target;if(!(r instanceof Element)||!r.closest(`[data-yuri-composer-compact-surface="true"]`)||r.closest(`[data-composer-action="true"]`))return;let i=r.closest(`.yuri-mobile-composer-compact-preview`);n.type===`pointerdown`&&i||n.type===`click`&&!i||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),T(),x(iE(t.current,`expanded`)),S(),I(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0}))}),[R,z]=Z.useState(null),[B,V]=Z.useState(null),H=Z.useRef(null),U=J(e=>{e&&vE(e,_.current??e),_.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,T(),x($T())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;H.current&&H.current!==n&&U(H.current),H.current=n,n&&b(n),z(e=>e===t?e:t),V(e=>e===n?e:n)});let W=Z.useMemo(()=>()=>void 0,[]),ee=e.enabled&&R?R:W,te=e.enabled&&B?B:W,ne=e.enabled&&typeof window<`u`?window:W,re=Z.useMemo(()=>({passive:!0}),[]);qn(`scroll`,j,ee,re),qn(`scrollend`,M,ee,re),qn(`touchstart`,A,ee,re),qn(`touchmove`,k,ee,re),qn(`touchend`,P,ee,re),qn(`touchcancel`,F,ee,re),qn(`pointerdown`,L,te),qn(`click`,L,te),qn(`focusin`,C,te),qn(`focusout`,C,te),qn(`yuri:keyboard-intent`,C,ne),qn(`yuri:keyboard-anim`,C,ne),qn(`yuri:keyboard-settled`,C,ne),Z.useEffect(()=>{if(!e.enabled){U(H.current),H.current=null;return}return C(),j(),()=>{g(i),g(a)}},[e.enabled,R,B])},$H=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},eU=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},tU=e=>{if(!e)return null;let t=$H(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${eU(e)??``}`},nU=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}),rU=(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&&tU(t[r])===tU(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=$H(r),a=r.info.id,o=nU(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=eU(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},iU=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=$H(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=eU(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}},aU=200,oU={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},sU=()=>aU,cU=()=>Math.round(sU()*.6),lU={MAX_SESSIONS:oU.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(aU*.6),HISTORICAL_MESSAGES:aU,FETCH_BUFFER:20,HISTORY_CHUNK:aU,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:oU.ZOMBIE_TIMEOUT},uU=()=>{let e=sU(),t=cU();return{...lU,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},dU=lU,fU=600,pU=6e3,mU=.5,hU=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),gU=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},_U=(e,t)=>{let n=hU(e,t);if(n||=gU(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}},vU=e=>{let{container:t,quiesceMs:n=fU,maxLifetimeMs:r=pU}=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=_U(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)>mU){_();return}let n=hU(t,i.messageId);if(!n){let e=gU(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)>mU&&(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)>mU)&&_(),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())}}},yU=30,bU=1200,xU=1.5,SU=e=>Math.max(bU,e*xU),CU=4,wU=30,TU=4,EU=30,DU=250,OU=800,kU=1e4,AU=1500,jU=2e3,MU=Ni+2e3,NU=40,PU=`history-loading-timeout`,FU=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),IU=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=PU,e},LU=(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)},RU=2500,zU=new Map,BU=()=>p()?CU:xo()?TU:yU,VU=e=>p()?e.length<=wU:!xo()||e.length<=EU,HU=(e,t)=>{if(zU.delete(e),!VU(t.messages))return;let n=BU();for(;zU.size>=n;){let e=zU.keys().next().value;if(typeof e!=`string`)break;zU.delete(e)}zU.set(e,t)},UU=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),WU=e=>e?{owner:`tanstack-core`}:{owner:`controller`},GU=(e,t)=>e?e.canLoadEarlier:t>=uU().HISTORICAL_MESSAGES,KU=e=>!(e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=SU(e.clientHeight)),qU=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`,JU=8,YU=1,XU=8,ZU=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],QU=80,$U=new WeakMap,eW=e=>{let t=e?$U.get(e):void 0;return!!(t&&(t.touches>0||performance.now()-t.lastScrollAt<160))},tW=e=>{let t=$U.get(e);t&&(t.touches=0,t.lastScrollAt=-1/0,t.pending=null,t.settleScheduled=!1)},nW=e=>{rW(e)},rW=e=>{let t=$U.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&&iW(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),e.addEventListener(`scroll`,()=>{n.lastScrollAt=performance.now()},{passive:!0}),$U.set(e,n),n},iW=(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+QU||aW(e,n.anchorTop+n.delta))}))},aW=(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},oW=(e,t,n)=>{let r=rW(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,aW(e,t)},sW=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),cW=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:a,loadMoreMessages:o,goToBottom:s,releaseAutoFollow:l,beginHistoryViewportPreservation:d,endHistoryViewportPreservation:f,isPinned:p,showScrollButton:m,isMobile:h,onWillLoadEarlier:g})=>{let _=Z.useRef(h);_.current=h;let v=Z.useRef(null),y=Z.useRef(null),b=Z.useMemo(()=>{let t=e??``,r=t?zU.get(t):void 0;if(r&&r.messages===n)return HU(t,r),v.current=r.model,y.current=n,r.model;let i=rU(v.current,y.current,n)??iU(n);return v.current=i,y.current=n,t&&n.length>0&&HU(t,{messages:n,model:i}),i},[n,e]),[x,S]=Z.useState(!1),[C,w]=Z.useState(!1),[T,E]=Z.useState(null),D=Z.useRef(0),O=u(),k=c(),A=Z.useMemo(()=>({runtimeKey:O,runtimeGeneration:k,sessionId:e,directory:t}),[O,k,e,t]),j=Z.useRef(A);j.current=A;let M=`chat-history-error:${JSON.stringify([O,t??null,e])}`;Gn(()=>(j.current=A,()=>{j.current===A&&(j.current=null),ji.dismiss(M)}),[A,M]);let N=Z.useRef(b),P=Z.useRef(p),F=Z.useRef(x),I=Z.useRef(C),L=Z.useRef(e),R=Z.useRef(t??null),z=Z.useRef(n),B=Z.useRef(r),V=Z.useRef([]),H=Z.useRef(!1),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),te=Z.useRef(!1),ne=Z.useRef(null),re=Z.useRef({authorized:!1,consumed:!1,top:0}),G=Z.useRef(null),ie=J(()=>{re.current={authorized:!1,consumed:F.current,top:i.current?.scrollTop??0}}),ae=()=>h?i.current??void 0:void 0,oe=J(e=>{e.repeat||ie()});qn(`touchstart`,ie,ae,{passive:!0,capture:!0}),qn(`wheel`,ie,ae,{passive:!0,capture:!0}),qn(`keydown`,oe,ae,{capture:!0});let[se,le]=Z.useState(A);se!==A&&(le(A),ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),te.current=!1,F.current=!1,ee.current=null,S(!1),w(!1),E(null),D.current=0,re.current={authorized:!1,consumed:!1,top:0},G.current=null);let ue=Z.useMemo(()=>{let e=GU(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),de=Z.useRef(ue);N.current=b,P.current=p,I.current=C,de.current=ue,L.current=e,R.current=t??null,z.current=n,B.current=r,Gn(()=>{r?.complete&&ji.dismiss(M)},[r?.complete,M]);let fe=J(()=>{te.current=!0,ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null)}),pe=J(()=>{if(typeof window>`u`){te.current=!1;return}ne.current!==null&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>{ne.current=null,te.current=!1},jU)}),me=J(()=>{let e=V.current;e.length!==0&&(V.current=[],e.forEach(e=>e()))}),he=J((e=!1)=>new Promise(t=>{if(typeof window>`u`){t();return}let n=!1,r=j.current,i=Date.now()+kU,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,DU)})),ge=J(e=>{let t=W.current;t&&(W.current=null,t.resolve(e))}),_e=J(()=>{let e=W.current;if(e){if(e.sessionId!==L.current){ge(!1);return}if(e.kind===`turn`?a.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:a.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(ee.current={turnId:e.turnId,expiresAt:Date.now()+RU},E(e.turnId)),ge(!0);return}typeof(e.kind===`turn`?N.current.turnIndexById.get(e.id):N.current.messageToTurnIndex.get(e.id))==`number`&&ge(!1)}}),ve=Z.useRef(null),ye=J(()=>{let e=ve.current;e&&(ve.current=null,e.dispose())});Wn(()=>{ne.current!==null&&typeof window<`u`&&(window.clearTimeout(ne.current),ne.current=null),ye(),me(),ge(!1)});let be=Z.useRef({scope:A,at:-1/0}),xe=()=>{!h&&!xo()&&(be.current={scope:A,at:Date.now()})};qn(`wheel`,e=>{e.deltaY!==0&&e.target instanceof Node&&i.current?.contains(e.target)&&xe()},void 0,{passive:!0,capture:!0}),qn(`scroll`,e=>{e.target===i.current&&xe()},void 0,{passive:!0,capture:!0});let Se=()=>be.current.scope===A&&Date.now()-be.current.at<OU,[Ce,Te]=Z.useState({scope:A,messages:n}),Ee=xo(),De=Ce.scope===A&&Ce.messages!==n&&sW(Ce.messages[0]?.info?.id??null,n[0]?.info?.id??null,n)&&(Ee?!a.current?.isHistoryVirtualized()&&eW(i.current):!h&&Ce.messages.at(-1)===n.at(-1)&&Se()),Oe=De?Ce.messages:n;H.current=De&&!h&&!Ee,(Ce.scope!==A||Ce.messages!==Oe)&&Te({scope:A,messages:Oe});let[,ke]=Z.useReducer(e=>e+1,0);Gn(()=>{me(),_e()},[Oe]);let Ae=Z.useRef(null),je=J(()=>a.current?.captureViewportAnchor()??null),Me=J(e=>a.current?.restoreViewportAnchor(e)??!1),Ne=J(()=>{if(ye(),a.current?.isHistoryVirtualized())return;let e=i.current;if(!e)return;let t=je();if(t)return ve.current=vU({container:e,anchor:t,pending:!0,isUserScrolling:xo()?()=>eW(e):void 0}),ve.current}),Pe=Z.useRef(null);Vn(J(()=>{let e=i.current;if(!e||!De||!Ee&&Se())return;let t=e.scrollHeight;Pe.current={oldestId:Oe[0]?.info?.id??null,newestId:Oe.at(-1)?.info?.id??null,scrollHeight:t};let n=Ae.current;if(n){let r={...n,height:t,top:e.scrollTop,anchor:je()};Ae.current=Ee?r:Object.assign(n,r)}ke()}),De?50:null);let Fe=Z.useRef(null);Gn(()=>{if(!xo())return;let e=i.current;if(!e){Fe.current=null;return}let t=Fe.current;(t?.container!==e||t.scope!==A)&&(nW(e),tW(e),Fe.current={container:e,scope:A})}),Gn(()=>{ye(),U.current=null,me(),Ae.current=null,Pe.current=null,a.current?.cancelViewportAnchorHold()},[A]),Gn(()=>{let e=i.current;if(!e)return;let t=Ae.current;a.current?.isHistoryVirtualized()&&ye(),t&&Math.abs(e.scrollTop-t.top)>XU&&(Ae.current=null,t=null);let n=Pe.current,r=Oe[0]?.info?.id??null,o=Oe[Oe.length-1]?.info?.id??null,c=n?UU({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:o})||sW(n.oldestId,r,Oe):!1;t&&t.sessionId!==L.current&&(Ae.current=null,t=null);let l=t?UU({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:o})||sW(t.oldestId,r,Oe):!1,u=c||l,d=e=>{Pe.current={oldestId:r,newestId:o,scrollHeight:e??Pe.current?.scrollHeight??null}};if(P.current&&!t){ye(),u?(Ae.current=null,s(`instant`,{reveal:!1}),d(e.scrollHeight)):d();return}let f=WU(a.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){a.current?.cancelViewportAnchorHold();let e=t.anchor;e&&Me(e),d();return}let n=e.scrollHeight,r=n-t.height;if(xo()){r>0&&oW(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&Me(i))&&r>0&&(e.scrollTop=t.top+r),ve.current?.rebase(),d(n);return}if(c&&n&&f.owner===`controller`){let t=e.scrollHeight,r=n.scrollHeight===null?0:t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;xo()?oW(e,t,r):e.scrollTop=t}d(t),Ne();return}d()},[Oe,s]),Gn(()=>{if(H.current)return;let e=U.current;U.current=null,e?.()},[Oe]);let Ie=J(async()=>!1),Le=J(async e=>{let t=j.current,n=()=>t===j.current&&t?.runtimeKey===u()&&t?.runtimeGeneration===c(),r=Date.now(),i=r+MU,a=R.current,o=a?ce()?.getRequestState?.(we(a,e)):void 0;for(de.current.historyLoading,B.current,o?.status,o?.error;de.current.historyLoading;){if(!n()||L.current!==e)return Date.now()-r,`switched`;if(Date.now()>=i){let t=a?ce()?.getRequestState?.(we(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:MU,hostTurnPageTimeoutMs:Ni,historyLoading:de.current.historyLoading,historyMeta:B.current,requestStatusAtStart:o?.status??null,requestStatusAtTimeout:t?.status??null,requestErrorAtTimeout:t?.error??null,likelyStaleLoadingFlag:t?.status===`ready`||t?.status===`error`||t==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,NU)})}return Date.now()-r,a&&ce()?.getRequestState?.(we(a,e))?.status,n()&&L.current===e?`cleared`:`switched`}),Re=J(async e=>{if(!L.current||F.current||H.current||!de.current.hasMoreAboveTurns)return!1;F.current=!0,fe(),S(!0);let t=L.current,n=j.current,r=()=>n===j.current&&n?.runtimeKey===u()&&n?.runtimeGeneration===c(),s=()=>n?.directory?ce()?.getPagination(we(n.directory,t)).cursor??null:null,l=M,p=null,m=null,h=!!e.userInitiated;h&&d();let g=()=>{if(r()){if(H.current){U.current=g;return}m?.settle(),p&&Ae.current===p&&(Ae.current=null,a.current?.cancelViewportAnchorHold()),h&&(h=!1,f())}};try{if(de.current.historyLoading){if(!e.userInitiated)return!1;let n=await Le(t);if(n===`timeout`)throw IU();if(n===`switched`||!de.current.hasMoreAboveTurns)return!1}if(!r()||!L.current||L.current!==t)return!1;let n=i.current,a=z.current,c=a.length,u=a[0]?.info?.id??null,d=B.current?.limit??uU().HISTORICAL_MESSAGES;e.preserveViewport&&n&&(p={sessionId:L.current,height:n.scrollHeight,top:n.scrollTop,anchor:je(),oldestId:u,newestId:a[a.length-1]?.info?.id??null},Ae.current=p,Pe.current={oldestId:p.oldestId,newestId:p.newestId,scrollHeight:p.height},m=Ne()??null);let f=c,h=u,_=d,v=0,y=0;for(;;){if(de.current.historyLoading)if(e.userInitiated){let e=await Le(t);if(e===`timeout`)throw g(),IU();if(e===`switched`)return g(),!1}else return g(),!1;let n=i.current?.scrollHeight??0,a=f,c=h,u=_,d=s();if(await o(t,`up`),v+=1,!r()||L.current!==t)return g(),!1;if(await he(!0),!r())return!1;if(H.current)return!0;let p=(()=>{let t=z.current;return qU({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:a,messageCountAfter:t.length,oldestIdBefore:c,oldestIdAfter:t[0]?.info?.id??null,limitBefore:u,limitAfter:B.current?.limit??_,cursorBefore:d,cursorAfter:s(),hasMoreAbove:de.current.hasMoreAboveTurns,pagesLoaded:v,maxPages:e.singlePage?1:JU})})();if(p===`continue`){let e=z.current;f=e.length,h=e[0]?.info?.id??null,_=B.current?.limit??_;continue}if(p===`stop-no-growth`){if(e.singlePage)return g(),!1;if(de.current.historyLoading){if(e.userInitiated){let e=await Le(t);if(e===`timeout`)throw g(),IU();if(e===`switched`)return g(),!1;--v;continue}return g(),!1}if(y<YU){y+=1,--v;continue}return D.current=Date.now()+AU,g(),!1}return D.current=0,ji.dismiss(l),!0}}catch(e){throw r()&&(D.current=Date.now()+AU),g(),e}finally{r()&&(F.current=!1,S(!1),pe(),H.current?g():he(!0).then(g))}}),{t:ze}=Xn(),Be=q({mutationKey:ZU({runtimeKey:u(),sessionId:e??``}),mutationFn:async e=>{if(j.current!==e.scope||u()!==e.scope.runtimeKey||c()!==e.scope.runtimeGeneration||L.current!==e.sessionId)return!1;fe(),e.userInitiated&&l();try{return await Re({preserveViewport:!0,userInitiated:!!e.userInitiated,singlePage:e.singlePage})}finally{j.current===e.scope&&c()===e.scope.runtimeGeneration&&pe()}}}),Ve=J(async e=>{let t=L.current;if(!t||!de.current.canLoadEarlier)return;let n=A,r=M,i=()=>j.current===n&&u()===n.runtimeKey&&c()===n.runtimeGeneration;if(!(Be.isPending&&Be.variables?.sessionId===t&&Be.variables?.scope===n)){e?.userInitiated&&g?.();try{let r=await Be.mutateAsync({sessionId:t,scope:n,userInitiated:!!e?.userInitiated,singlePage:e?.singlePage});if(!i())return;if(r===!1&&de.current.canLoadEarlier){let n={sessionId:t,grew:r,userInitiated:!!e?.userInitiated,canLoadEarlier:de.current.canLoadEarlier,hasMoreAboveTurns:de.current.hasMoreAboveTurns,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};LU(`no-growth`,Error(`chat history pagination returned no growth`),n)}}catch(n){let a={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:MU,hostTurnPageTimeoutMs:Ni,canLoadEarlier:de.current.canLoadEarlier,historyLoading:de.current.historyLoading,historyMeta:B.current,messageCount:z.current.length,oldestMessageId:z.current[0]?.info?.id??null};FU(n)?LU(`timeout`,n,a):LU(`failed`,n,a),i()&&e?.userInitiated&&ji.error(FU(n)?ze(`chat.history.loadOlderTimeout`):ze(`chat.history.loadOlderFailed`),{id:r})}}}),He=Be.isPending&&Be.variables?.sessionId===e&&Be.variables?.scope===A||x,Ue=J(e=>{if(Date.now()<D.current)return;let t=i.current;if(t){if(_.current){let n=re.current,r=t.scrollTop<n.top;if(n.top=t.scrollTop,n.consumed||(e===`upward-intent`&&(n.authorized=!0),!n.authorized||e===`scroll`&&!r))return}else if(F.current){G.current=null;return}else if(e===`upward-intent`)G.current={top:t.scrollTop};else{let e=G.current;if(!e)return;let n=t.scrollTop<e.top;if(t.scrollTop>e.top||P.current?G.current=null:e.top=t.scrollTop,!n)return}KU({source:e,isMobile:_.current,isPinned:P.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:de.current.canLoadEarlier,isLoadingOlder:F.current,pendingRevealWork:I.current})&&(_.current&&(re.current.consumed=!0),G.current=null,Ve({userInitiated:!0,singlePage:_.current}))}}),We=J(()=>{Ue(`scroll`)}),Ge=J(()=>{!_.current&&!F.current&&!a.current?.isHistoryVirtualized()&&Ne()?.settle(),Ue(`upward-intent`)}),Ke=J(async(t,n)=>{if(!t||!L.current)return!1;l(),w(!0);try{return L.current!==e||typeof N.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},_e()})}finally{w(!1)}}),qe=Z.useRef(null),Je=J(async(t,n)=>{if(!t||!L.current)return!1;let r=`${L.current}:${t}`;if(qe.current===r)return!1;qe.current=r;let i=L.current;l(),w(!0);try{if(L.current!==e)return!1;for(;!N.current.messageToTurnId.has(t)&&de.current.hasMoreAboveTurns;){if(L.current!==i||qe.current!==r)return!1;let e=z.current[0]?.info.id;if(await Ve({userInitiated:!0,singlePage:!0}),await he(),z.current[0]?.info.id===e)break}if(L.current!==i||qe.current!==r)return!1;let a=N.current.messageToTurnId.get(t);return typeof N.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(r=>{W.current={sessionId:L.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:a??null,resolve:r},_e()})}finally{qe.current===r&&(qe.current=null),w(!1)}}),Ye=J(async()=>{qe.current=null,w(!1),F.current=!1,S(!1),s(`smooth`)}),Xe=J(async()=>{w(!1),F.current=!1,S(!1),s(`instant`)}),Ze=J(e=>{let t=ee.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;ee.current=null}E(e)});return{turnIds:b.turnIds,turnStart:0,renderedMessages:Oe,historySignals:ue,isLoadingOlder:He,pendingRevealWork:C,activeTurnId:T,showScrollToBottom:m&&!C,turnWindowModel:b,loadEarlier:Ve,revealBufferedTurns:Ie,resumeToBottom:Ye,resumeToBottomInstant:Xe,scrollToTurn:Ke,scrollToMessage:Je,handleHistoryScroll:We,handleHistoryUpwardIntent:Ge,captureViewportAnchor:je,restoreViewportAnchor:Me,handleActiveTurnChange:Ze}},lW=12,uW=50,dW=800;function fW(e){let t=(0,Q.c)(25),{scope:n,enabled:i,cursor:a,loadedTurns:o,messages:s,scrollRef:c,loadPrevious:l}=e,[u,d]=Z.useState(null),f=Z.useRef(u),p=Z.useRef(!1),m=Z.useRef(null),h;t[0]!==u||t[1]!==a||t[2]!==i||t[3]!==o||t[4]!==n?(h=i&&!r()&&a!==null&&o<lW&&u!==n,t[0]=u,t[1]=a,t[2]=i,t[3]=o,t[4]=n,t[5]=h):h=t[5];let g=h,_;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{f.current=null,d(null)},t[6]=_):_=t[6];let v;t[7]===n?v=t[8]:(v=[n],t[7]=n,t[8]=v),Z.useEffect(_,v);let y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{m.current=null},t[9]=y):y=t[9];let b;t[10]!==a||t[11]!==g||t[12]!==s||t[13]!==n?(b=[n,g,a,s],t[10]=a,t[11]=g,t[12]=s,t[13]=n,t[14]=b):b=t[14],Z.useEffect(y,b);let x;t[15]!==g||t[16]!==c?(x=e=>{g&&e.deltaY!==0&&e.target instanceof Node&&c.current?.contains(e.target)&&(m.current=null)},t[15]=g,t[16]=c,t[17]=x):x=t[17];let S;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(S={passive:!0,capture:!0},t[18]=S):S=t[18],qn(`wheel`,x,void 0,S);let C;t[19]!==a||t[20]!==g||t[21]!==l||t[22]!==n||t[23]!==c?(C=()=>{let e=c.current;if(f.current===n)return;if(!g||r()||!a||!e||p.current||document.visibilityState===`hidden`){m.current=null;return}let t=e.scrollHeight,i=e.scrollTop,o=m.current;if(!o||o.height!==t||o.top!==i){m.current={height:t,top:i,since:Date.now()};return}Date.now()-o.since<dW||(f.current=n,d(n),p.current=!0,l(uW).catch(pW).finally(()=>{p.current=!1}))},t[19]=a,t[20]=g,t[21]=l,t[22]=n,t[23]=c,t[24]=C):C=t[24],Vn(J(C),g?200:null)}function pW(e){console.error(`[chat-history] desktop history warmup failed`,e)}var mW=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),hW=({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[d,f]=Z.useState(null),[p,m]=Z.useState(``),[h,g]=Z.useState(0),_=Z.useRef(!1),v=Z.useRef(0),y=J(async(e,n,r)=>{if(_.current)return;_.current=!0;let i=v.current+1;v.current=i,f({type:e,messageId:n});try{await r(),t(!1)}finally{v.current===i&&(_.current=!1,f(null))}});return n?(0,$.jsx)(xs,{open:e,onOpenChange:t,children:(0,$.jsx)(_s,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:(0,$.jsx)(gW,{open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s,isLoadingEarlier:c,onLoadEarlier:l,onRevertMessage:u,searchQuery:p,onSearchQueryChange:m,selectedIndex:h,onSelectedIndexChange:g,pendingAction:d,runPendingMessageAction:y})})}):null},gW=e=>{let t=(0,Q.c)(145),{open:n,onOpenChange:r,sessionID:i,directory:a,onScrollToMessage:o,onScrollByTurnOffset:s,onResumeToLatest:c,canLoadEarlier:l,isLoadingEarlier:u,onLoadEarlier:d,onRevertMessage:f,searchQuery:p,onSearchQueryChange:m,selectedIndex:h,onSelectedIndexChange:g,pendingAction:_,runPendingMessageAction:v}=e,{t:y}=Xn(),b=Ab(),x=i,S=No(x??``,a),C=wa(vW),w=wa(yW),T;t[0]===b.capabilities?T=t[1]:(T=mW(b.capabilities),t[0]=b.capabilities,t[1]=T);let E=T,{isMobile:D,isTablet:O}=Kc(),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=bW,L=xW,R;t[3]===S?R=t[4]:(R=S.filter(SW).map(CW),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 YV(n.parts).toLowerCase().includes(t)})}t[5]=p,t[6]=z,t[7]=B}else B=t[7];let V=B,H;t[8]!==V.length||t[9]!==g||t[10]!==p?(H=()=>{P.current||g(p.trim()?0:Math.max(0,V.length-1))},t[8]=V.length,t[9]=g,t[10]=p,t[11]=H):H=t[11];let U;t[12]!==V||t[13]!==g||t[14]!==p?(U=[V,p,g],t[12]=V,t[13]=g,t[14]=p,t[15]=U):U=t[15],Z.useEffect(H,U);let W,ee;t[16]===V.length?(W=t[17],ee=t[18]):(W=()=>{j.current=j.current.slice(0,V.length)},ee=[V.length],t[16]=V.length,t[17]=W,t[18]=ee),Z.useEffect(W,ee);let te,ne;t[19]===h?(te=t[20],ne=t[21]):(ne=()=>{P.current||j.current[h]?.scrollIntoView({block:`nearest`})},te=[h],t[19]=h,t[20]=te,t[21]=ne),Z.useEffect(ne,te);let re;t[22]===u?re=t[23]:(re=()=>{!P.current||N.current||u||(P.current=!1)},t[22]=u,t[23]=re);let G;t[24]!==V.length||t[25]!==u?(G=[V.length,u],t[24]=V.length,t[25]=u,t[26]=G):G=t[26],Z.useEffect(re,G);let ie,ae;t[27]!==n||t[28]!==p?(ie=()=>{let e=F.current;if(F.current=n,!n||e||P.current||p.trim())return;let t=M.current;t&&(t.scrollTop=t.scrollHeight)},ae=[n,p],t[27]=n,t[28]=p,t[29]=ie,t[30]=ae):(ie=t[29],ae=t[30]),Z.useLayoutEffect(ie,ae);let oe;t[31]===u?oe=t[32]:(oe=()=>{let e=N.current,t=M.current;if(!e||!t||u)return;N.current=null;let n=j.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},t[31]=u,t[32]=oe);let se;t[33]!==V.length||t[34]!==u?(se=[V.length,u],t[33]=V.length,t[34]=u,t[35]=se):se=t[35],Z.useLayoutEffect(oe,se);let ce;t[36]===d?ce=t[37]:(ce=()=>{let e=M.current;if(e){let t=e.getBoundingClientRect().top,n=j.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(N.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}P.current=!0,d?.()},t[36]=d,t[37]=ce);let le=J(ce),ue;t[38]!==r||t[39]!==o?(ue=async e=>{await o?.(e)!==!1&&r(!1)},t[38]=r,t[39]=o,t[40]=ue):ue=t[40];let de=J(ue),fe;t[41]!==V||t[42]!==de||t[43]!==g||t[44]!==h?(fe=e=>{let t=V.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),g(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),g(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(h%t+t)%t,r=V[n];r&&de(r.message.info.id)}}},t[41]=V,t[42]=de,t[43]=g,t[44]=h,t[45]=fe):fe=t[45];let pe=J(fe),me;t[46]!==x||t[47]!==a||t[48]!==w||t[49]!==f||t[50]!==C||t[51]!==v?(me=async(e,t)=>{x&&await v(e,t,async()=>{e===`revert`?f?await f(t):await C(x,t,{directory:a}):await w(x,t,{directory:a})})},t[46]=x,t[47]=a,t[48]=w,t[49]=f,t[50]=C,t[51]=v,t[52]=me):me=t[52];let he=J(me),ge;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),t[53]=ge):ge=t[53];let _e;t[54]===y?_e=t[55]:(_e=y(`chat.timeline.title`),t[54]=y,t[55]=_e);let ve;t[56]===_e?ve=t[57]:(ve=(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[ge,_e]}),t[56]=_e,t[57]=ve);let ye;t[58]===y?ye=t[59]:(ye=y(`chat.timeline.description`),t[58]=y,t[59]=ye);let be;t[60]===ye?be=t[61]:(be=(0,$.jsx)(ys,{children:ye}),t[60]=ye,t[61]=be);let xe;t[62]!==ve||t[63]!==be?(xe=(0,$.jsxs)(hs,{children:[ve,be]}),t[62]=ve,t[63]=be,t[64]=xe):xe=t[64];let Se;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(Se=(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),t[65]=Se):Se=t[65];let Ce;t[66]===y?Ce=t[67]:(Ce=y(`chat.timeline.searchPlaceholder`),t[66]=y,t[67]=Ce);let we;t[68]===m?we=t[69]:(we=e=>m(e.target.value),t[68]=m,t[69]=we);let Te;t[70]!==pe||t[71]!==p||t[72]!==Ce||t[73]!==we?(Te=(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[Se,(0,$.jsx)(Ks,{autoFocus:!0,placeholder:Ce,value:p,onChange:we,onKeyDown:pe,className:`pl-9 w-full`})]}),t[70]=pe,t[71]=p,t[72]=Ce,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:`flex justify-center py-1`,children:(0,$.jsxs)(er,{type:`button`,variant:`link`,size:`sm`,onClick:le,disabled:u,className:`h-auto px-1 py-0 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]!==E.fork||t[82]!==E.revert||t[83]!==k||t[84]!==V||t[85]!==he||t[86]!==de||t[87]!==g||t[88]!==_||t[89]!==p||t[90]!==h||t[91]!==y?(De=V.length===0?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:y(p?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):V.map((e,t)=>{let{message:n}=e,r=XV(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()?_W(YV(n.parts),p):null;return(0,$.jsxs)(Z.Fragment,{children:[s&&(0,$.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-3 bg-background/95 py-2 backdrop-blur-sm`,children:[(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a}),(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`})]}),(0,$.jsxs)(`div`,{ref:e=>{j.current[t]=e},"data-timeline-message-id":n.info.id,className:Y(`group flex items-center gap-3 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,l&&`bg-interactive-selection text-interactive-selection-foreground`),onClick:()=>void de(n.info.id),onMouseEnter:()=>g(t),children:[(0,$.jsx)(`span`,{className:Y(`typography-meta w-16 flex-shrink-0 text-right tabular-nums`,l?`text-interactive-selection-foreground/70`:`text-muted-foreground`),children:c}),(0,$.jsxs)(`p`,{className:Y(`flex-1 min-w-0 typography-micro truncate`,l?`text-interactive-selection-foreground`:`text-foreground`),children:[u??(r||y(`chat.timeline.noTextContent`)),!u&&r&&r.length>=80&&`…`]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:(0,$.jsxs)(`div`,{className:Y(`gap-1`,k?`flex`:`hidden group-hover:flex`),children:[E.revert?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"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)(Js,{sideOffset:6,children:y(`chat.timeline.actions.revertFromHere`)})]}):null,E.fork?(0,$.jsxs)(Ys,{children:[(0,$.jsx)(qs,{asChild:!0,children:(0,$.jsx)(er,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"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)(Js,{sideOffset:6,children:y(`chat.timeline.actions.forkFromHere`)})]}):null]})})]})]},n.info.id)}),t[81]=E.fork,t[82]=E.revert,t[83]=k,t[84]=V,t[85]=he,t[86]=de,t[87]=g,t[88]=_,t[89]=p,t[90]=h,t[91]=y,t[92]=De):De=t[92];let Oe;t[93]===De?Oe=t[94]:(Oe=(0,$.jsx)(`div`,{ref:M,className:`flex-1 overflow-y-auto`,children:De}),t[93]=De,t[94]=Oe);let ke;t[95]===y?ke=t[96]:(ke=y(`chat.timeline.actions.title`),t[95]=y,t[96]=ke);let Ae;t[97]===ke?Ae=t[98]:(Ae=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:ke}),t[97]=ke,t[98]=Ae);let je;t[99]!==r||t[100]!==s?(je=()=>{s?.(-1),r(!1)},t[99]=r,t[100]=s,t[101]=je):je=t[101];let Me;t[102]===y?Me=t[103]:(Me=y(`chat.timeline.actions.previousTurn`),t[102]=y,t[103]=Me);let Ne;t[104]!==je||t[105]!==Me?(Ne=(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:je,children:Me}),t[104]=je,t[105]=Me,t[106]=Ne):Ne=t[106];let Pe;t[107]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),t[107]=Pe):Pe=t[107];let Fe;t[108]!==r||t[109]!==c?(Fe=()=>{c?.(),r(!1)},t[108]=r,t[109]=c,t[110]=Fe):Fe=t[110];let Ie;t[111]===y?Ie=t[112]:(Ie=y(`chat.timeline.actions.latest`),t[111]=y,t[112]=Ie);let Le;t[113]!==Fe||t[114]!==Ie?(Le=(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:Fe,children:Ie}),t[113]=Fe,t[114]=Ie,t[115]=Le):Le=t[115];let Re;t[116]!==Ne||t[117]!==Le?(Re=(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[Ne,Pe,Le]}),t[116]=Ne,t[117]=Le,t[118]=Re):Re=t[118];let ze;t[119]===y?ze=t[120]:(ze=y(`chat.timeline.help.clickMessage`),t[119]=y,t[120]=ze);let Be;t[121]===ze?Be=t[122]:(Be=(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:ze})}),t[121]=ze,t[122]=Be);let Ve;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Ve=(0,$.jsx)(X,{name:`arrow-go-back`,className:`h-4 w-4 flex-shrink-0`}),t[123]=Ve):Ve=t[123];let He;t[124]===y?He=t[125]:(He=y(`chat.timeline.help.undoToPoint`),t[124]=y,t[125]=He);let Ue;t[126]===He?Ue=t[127]:(Ue=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Ve,(0,$.jsx)(`span`,{children:He})]}),t[126]=He,t[127]=Ue);let We;t[128]!==E.fork||t[129]!==y?(We=E.fork?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:y(`chat.timeline.help.createSessionFromHere`)})]}):null,t[128]=E.fork,t[129]=y,t[130]=We):We=t[130];let Ge;t[131]!==Be||t[132]!==Ue||t[133]!==We?(Ge=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 typography-meta text-muted-foreground`,children:[Be,Ue,We]}),t[131]=Be,t[132]=Ue,t[133]=We,t[134]=Ge):Ge=t[134];let Ke;t[135]!==Ae||t[136]!==Re||t[137]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[Ae,Re,Ge]}),t[135]=Ae,t[136]=Re,t[137]=Ge,t[138]=Ke):Ke=t[138];let qe;return t[139]!==xe||t[140]!==Te||t[141]!==Ee||t[142]!==Oe||t[143]!==Ke?(qe=(0,$.jsxs)($.Fragment,{children:[xe,Te,Ee,Oe,Ke]}),t[139]=xe,t[140]=Te,t[141]=Ee,t[142]=Oe,t[143]=Ke,t[144]=qe):qe=t[144],qe};function _W(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 vW(e){return e.revertToMessage}function yW(e){return e.forkFromMessage}function bW(e){return dc(e)}function xW(e){return Xs(e)}function SW(e){return e.info.role===`user`}function CW(e){return{message:e}}var wW=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},TW=(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`}},EW=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`))},DW=e=>{e&&EW(`message-${e}`)},OW=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&&EW(`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&&EW(`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=TW(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 EW(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=()=>{EW(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=wW(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},kW=2e4,AW=6e4,jW=2e3,MW=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,NW=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+=MW(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},PW={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},FW=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:PW,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}},IW=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function LW(e){return!!(e.active&&e.sessionId&&e.sessionKey&&e.sessionIsWorking)}function RW(e){return e===PW?e:PW}function zW(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 BW(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 VW(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||zW(i)==null}function HW(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!VW(n))continue;let e=BW(n);e&&t.push(e)}}return t}function UW(e,t){return`${e}:${t.join(`,`)}`}function WW(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=UW(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function GW(e,t,n,r){let i=(0,Q.c)(7),a=Vr(),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=WW({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:HW(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,Nr(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 KW=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),qW=(e,t)=>({...e,key:JW(e),estimatedBytes:KW(t)}),JW=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),YW=e=>({key:e?JW(e):null,selection:e}),XW=(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},ZW=(e,t,n,r)=>{let i=JW(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return XW(e,i,n);let s=o||qW(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),XW(c,i,n)},QW=(e,t,n)=>{let r=KW(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)},$W=(e,t)=>t&&e.some(e=>e.key===t)?t:null,eG=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?ZW(e.cachedSessionViews,t.selection,n,r.estimatedBytes):XW(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}},tG=(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:qW(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},nG=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:ZW(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},rG=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},iG=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},aG=e=>iG(e)?.role===`assistant`,oG=(e,t)=>{let n=iG(t);n&&(e.agentName??=rG(n.agent),e.providerId??=rG(n.providerID),e.modelId??=rG(n.modelID))},sG=e=>!!(e.agentName&&e.providerId&&e.modelId),cG=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!aG(r))&&(oG(t,r),sG(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||aG(r))&&(oG(t,r),sG(t)))break}return t},lG=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),uG=[],dG=[],fG=[],pG={type:`idle`},mG=`yuri:chat-force-scroll-bottom`,hG=()=>void 0,gG=`Quota limit reached. Retrying automatically.`,_G=1048576,vG=_G,yG=20,bG=_G,xG=16*_G,SG={maxEntries:3,maxEstimatedBytes:32*_G},CG={maxEntries:2,maxEstimatedBytes:32*_G},wG=e=>i(()=>e()),TG={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},EG=()=>{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},DG=[`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(`,`),OG=e=>e instanceof HTMLElement,kG=e=>OG(e)?!!e.closest(DG):!1,AG=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||kG(e)?!0:!t?.contains(e),jG=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=K.getState();return e||t||n||r||i||a||o},MG=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,initialPinRevealComplete:l=!1,renderedMessages:u,isLoadingOlder:d,sessionIsWorking:f,streamingMessageId:p,activeStreamingPhase:m,retryOverlay:h,handleMessageContentChange:g,getAnimationHandlers:_,handleHistoryScroll:v,scrollToBottom:y,sessionQuestions:b,sessionPermissions:x,sessionForms:S,retryActionCopy:C,isProgrammaticFollowActive:w,showLoadOlderButton:T,turnIds:E,activeTurnId:D,onSelectTurn:O,showPromptNavigator:k,canLoadEarlierPrompts:A,isLoadingOlderPrompts:j,onLoadEarlierPrompts:M,transcriptStatusRow:N,timelineHistoryAnchorToken:P})=>{let{t:F}=Xn(),I=HD({isLoadingOlder:d}),[L,R]=Z.useState({sessionId:e,directory:a,reserved:T}),z=L.sessionId===e&&L.directory===a,B=z&&L.reserved||T;(!z||L.reserved!==B)&&R({sessionId:e,directory:a,reserved:B});let V=UD({isMobile:r,isLoadingOlder:I})?(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsx)(`div`,{className:`chat-column flex items-center justify-center gap-1.5 pt-3 pb-1`,children:(0,$.jsx)(`span`,{className:`yuri-mobile-glass-control flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)]`,"aria-label":F(`chat.history.loadingMore`),children:(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`,"aria-hidden":`true`})})})}):null,H=r&&B?(0,$.jsx)(`div`,{className:Y(`flex justify-center pt-3 pb-4`,!I&&`invisible`),"aria-hidden":!I,children:(0,$.jsxs)(`span`,{role:`status`,className:`flex items-center gap-1.5 text-[var(--surface-mutedForeground)] opacity-60`,"aria-busy":I,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:F(`chat.history.loadingMore`)})]})}):null,U=Z.useRef(new Map),W=Z.useRef(new WeakMap),ee=Z.useRef(new Map),te=Z.useMemo(()=>{let e=new Map;for(let t=0;t<u.length;t+=1){let n=u[t];if(n.info.role!==`user`)continue;if(lL(n)){let r=fL(u,t)??``,i=ee.current.get(n.info.id);if(i&&i.command===r)e.set(n.info.id,i.parts);else{let t=[{type:`text`,text:r?`$ ${r}`:`/shell`}];ee.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(xa(n.parts))continue;let r=W.current.get(n.parts);r||(r=PD(n.parts),W.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=U.current;if(t.size===e.size){let n=!0;for(let[r,i]of e)if(t.get(r)!==i){n=!1;break}if(n)return t}return U.current=e,e},[u]),ne=Z.useMemo(()=>E.filter(e=>te.has(e)),[te,E]),re=Z.useRef(new Map),G=Z.useMemo(()=>{let e=new Map,t=new Map,n;for(let r of u){if(r.info.role===`user`){te.has(r.info.id)&&(n=r.info.id),n&&e.set(r.info.id,n);continue}let i=r.info.parentID,a=i?e.get(i):n;if(!a)continue;e.set(r.info.id,a);let o=YV(r.parts).trim();o&&t.set(a,o.slice(0,600))}let r=re.current;return(r.size!==e.size||[...e].some(([e,t])=>r.get(e)!==t))&&(re.current=e),{owners:re.current,replies:t}},[te,u]),ie=Z.useMemo(()=>{if(!D||te.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(te.has(e))return e}return null},[D,te,E]),ae=J(e=>{e.defaultPrevented||kG(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)(Zu,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:TG,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:ae,onScroll:v,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`yuri-chat-scroll-content relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[H,V,(0,$.jsx)(hV,{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)(rR,{})}):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)(VV,{question:e},e.id)),x.map(e=>(0,$.jsx)(PV,{permission:e},e.id)),S.map(e=>(0,$.jsx)(UV,{form:e,directory:a},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?CH:SH},"aria-hidden":`true`})]})}),(0,$.jsx)(Yu,{containerRef:o,suppressVisibility:w,userIntentOnly:!0,observeMutations:!1}),k&&ne.length>=2?(0,$.jsx)(_H,{turnIds:ne,previewsByTurnId:te,scrollRef:o,turnByMessageId:G.owners,repliesByTurnId:G.replies,activeTurnId:ie,onSelectTurn:O,canLoadEarlier:A,isLoadingOlder:j,onLoadEarlier:M}):null]})})},(e,t)=>e.currentSessionId===t.currentSessionId&&e.virtualizerKey===t.virtualizerKey&&e.isDesktopExpandedInput===t.isDesktopExpandedInput&&e.isMobile===t.isMobile&&e.stickyUserHeader===t.stickyUserHeader&&e.directory===t.directory&&e.scrollRef===t.scrollRef&&e.messageListRef===t.messageListRef&&e.pendingRevealWork===t.pendingRevealWork&&e.initialPinRevealComplete===t.initialPinRevealComplete&&e.renderedMessages===t.renderedMessages&&e.timelineHistoryAnchorToken===t.timelineHistoryAnchorToken&&e.isLoadingOlder===t.isLoadingOlder&&e.sessionIsWorking===t.sessionIsWorking&&e.streamingMessageId===t.streamingMessageId&&e.activeStreamingPhase===t.activeStreamingPhase&&e.retryOverlay===t.retryOverlay&&e.handleMessageContentChange===t.handleMessageContentChange&&e.getAnimationHandlers===t.getAnimationHandlers&&e.handleHistoryScroll===t.handleHistoryScroll&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.sessionForms===t.sessionForms&&e.retryActionCopy===t.retryActionCopy&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.turnIds===t.turnIds&&e.activeTurnId===t.activeTurnId&&e.onSelectTurn===t.onSelectTurn&&e.showPromptNavigator===t.showPromptNavigator&&e.canLoadEarlierPrompts===t.canLoadEarlierPrompts&&e.isLoadingOlderPrompts===t.isLoadingOlderPrompts&&e.onLoadEarlierPrompts===t.onLoadEarlierPrompts&&e.transcriptStatusRow===t.transcriptStatusRow);MG.displayName=`ChatViewport`;var NG=[{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%]`]}],PG=e=>Zn(e.path),FG=(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)]})},IG=e=>{let t=Math.ceil(Math.max(0,e)/yG);return Math.min(xG,vG+t*bG)},LG=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:s,hostedFeatures:c,assistantHistory:l,onRevertMessage:d,warning:f=null,pendingUserMessages:m=dG,onPendingUserMessagesMaterialized:h,committedDraftHandoffMessageId:g=null})=>{let _=c??qD(void 0),{t:v}=Xn();Gn(()=>{Ra()},[]);let y=wa(e=>e.openNewSessionDraft),b=wa(e=>e.setCurrentSession),x=wa(e=>e.newSessionDraft),S=wa(e=>e.newSessionDraft.draftSubmitting??!1),C=wa(e=>e.newSessionDraft.draftEstablishing??!1),w=wa(e=>e.forkTransition),T=Ia(e=>e.projects),E=Ia(e=>e.activeProjectId),D=Ko(e=>e.providers),O=dh(),k=$o(),A=i??k;Gn(()=>{!n||!r||!A||Kr(A,r)},[n,r,A]);let j=J(e=>O.ensureSessionRenderable(e,{directory:A})),M=K(e=>e.isExpandedInput),N=K(e=>e.stickyUserHeader),P=K(e=>e.promptNavigatorEnabled),F=K(e=>e.allowPromptingSubagentSessions),I=K(e=>e.isTimelineDialogOpen),L=K(e=>e.setTimelineDialogOpen),R=dr(e=>n&&r?e.streamingMessageIds.get(r)??null:null),z=dr(e=>R?e.messageStreamStates.get(R)?.phase??null:null),B=fa(r??``,A),V=IG(B);Z.useEffect(()=>{!a||!o||o(a,V)},[o,V,a]);let H=Ja(r??``,A).renderable,U=cr(r,A),W=Vi(r),ee=U??W,te=Tx({sessionId:r,hasSessionEntity:!!ee,hasRenderableSessionSnapshot:H,composerSurfaceKind:s?.kind}),ne=r?JSON.stringify([A,r]):null,[re,G]=Z.useState({key:ne,attempt:0}),ie=No(r??``,A,{suspendPartUpdates:!!R,suspendPartUpdatesForMessageId:R,enabled:n}),ae=r?ie:uG,oe=x.pendingUserMessage,se=wa(e=>r?e.retainedPendingUserMessages.get(r):void 0)??dG,le=!!(g||se.length>0),ue=wa(e=>e.clearRetainedPendingUserMessages),de=Z.useMemo(()=>{if(se.length===0)return m;if(m.length===0)return se;let e=new Set(m.map(e=>e.info.id));return[...m,...se.filter(t=>!e.has(t.info.id))]},[m,se]),fe=Z.useMemo(()=>cG(ae),[ae]),pe=Z.useMemo(()=>{if(!fe.modelId)return v(`common.unavailable`);let e=D.find(e=>e.id===fe.providerId);return ki(e,fe.modelId)||fe.modelId},[D,fe.modelId,fe.providerId,v]),me=go(r??``,A),he=Va(r??``,A),[ge,ve]=Z.useState(null),ye=!!r&&ge===r,be=J(()=>{if(!r||ye)return;let e=r,t=A;ve(e);let n=Qa(()=>{let n=ce();if(!n)throw Error(`unbound`);return n.getTranscript(we(t,e))});mi(ui({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:me?{sessionID:e,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error})),(async()=>{try{await Je(t,e),await O.ensureSessionRenderable(e,{directory:t});try{let r=Qa(()=>{let n=ce();if(!n)throw Error(`unbound`);return n.getTranscript(we(t,e))});n&&r&&to({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){mi(ui({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:he,error:n}))}finally{ve(t=>t===e?null:t)}})()}),xe=sa(r??``,A).boundary,Se=J(async e=>{if(xe.kind===`has-more`){await pt(A,e,Ue||We?void 0:50);return}if(xe.kind===`unknown`){await He(A,e);return}l&&!l.complete&&await l.fetchPrevious()}),Ce=vo(r??``,A),Te=oo(r??``,A),Ee=Wa(A),De=Ce??pG,ke=aa(r,A),Ae=Di(r,A),je=Dr(e=>r?e.forms[r]??fG:fG),Me=Z.useMemo(()=>je.filter(e=>!_e(e.metadata)),[je]);Z.useEffect(()=>{r&&Ii({sessionID:r,directory:A}).catch(e=>{console.error(`[ChatContainer] Failed to list session forms:`,e)})},[r,A]),GW(r,A,ae,Ae.length);let Ne=Z.useMemo(()=>{if(!r||ke.length>0||Ae.length>0)return!1;let e=De.type??`idle`;if(e===`busy`||e===`retry`||RD(de,{resolvedSessionStatus:Ce,sessionStatusObservedAt:Te}))return!0;let t=ae[ae.length-1]?.info,n=t?.time?.created;return Ce&&typeof Te==`number`&&typeof n==`number`&&n<=Te||typeof Ee==`number`&&typeof n==`number`&&n<=Ee?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,de,Ce,ae,ke.length,Ae.length,De.type,Te,Ee]),Pe=Z.useMemo(()=>!r||De.type!==`retry`?null:{sessionId:r,message:(typeof De.message==`string`?(De.message??``).trim():``)||gG,confirmedAt:De.confirmedAt},[r,De]),[Fe,Ie]=Z.useState(0),Le=Z.useRef(null);Z.useEffect(()=>{if(!Pe||typeof Pe.confirmedAt==`number`){Le.current=null,Ie(0);return}Le.current!==Pe.sessionId&&(Le.current=Pe.sessionId,Ie(Date.now()))},[Pe]);let Re=Z.useMemo(()=>!Pe||qV(De)?null:{...Pe,fallbackTimestamp:Fe},[Pe,Fe,De]),ze=Z.useMemo(()=>JV(De,e=>v(e)),[De,v]),Be=!!(r&&O.isLoading(r,{directory:A})),Ve=Z.useMemo(()=>{if(!r)return null;let e=zD({boundary:xe,assistantComplete:l?.complete??!0});return{limit:xe.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:BD({syncLoading:Be,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,xe,Be]),Ue=K(e=>e.isMobile),We=Ll()!==null,Ge=p(),Ke=mx(),qe=!!x?.open,Ye=si(e=>e.error),Xe=M,Ze=We||Ue||Ge||Ke===`mini-chat`,Qe=Z.useRef(null),$e=Z.useMemo(()=>{let e=x?.selectedProjectId?T.find(e=>e.id===x.selectedProjectId)??null:null,t=E?T.find(e=>e.id===E)??null:null,n=e??t??T[0]??null;return n?PG(n):null},[E,x?.selectedProjectId,T]),et=ta(r,A),tt=a??r??``,[nt,rt]=Z.useState(null),it=Ax(nt,tt,et,fe);Gn(()=>{rt(e=>Ax(e,tt,et,fe))},[et,fe,tt]);let at=et??it?.parentTarget??null,ot=it?.execution??fe,st=ll(),ct=st!==null&&r===st,lt=J(()=>{at&&b(at.id,at.directory)}),ut=at?.session?.title,dt=_.returnToParent&&at&&!ct?(0,$.jsxs)(er,{type:`button`,variant:`outline`,size:`xs`,onClick:lt,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":v(`chat.container.returnToParent.aria`),title:ut?.trim()?v(`chat.container.returnToParent.titleNamed`,{title:ut}):v(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),v(`chat.container.returnToParent.label`)]}):null,ft=Ex({readOnly:t,sessionIdentityPending:te,isSubagentSession:!!ee?.parentID||!!it,allowPromptingSubagentSessions:F}),mt=ot.modelId===fe.modelId?pe:ot.modelId?ki(D.find(e=>e.id===ot.providerId),ot.modelId)||ot.modelId:v(`common.unavailable`),ht=at?(0,$.jsx)(ZD,{agentName:ot.agentName,providerId:ot.providerId,modelId:ot.modelId,modelName:mt}):(0,$.jsx)(ZD,{}),gt=J(e=>{K.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),_t=J(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`yuri:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&>({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),vt=typeof window<`u`&&window.parent!==window;qn(`message`,_t,vt?window:hG),Jn(()=>{if(!vt)return;let e=window;e.__yuriApplyChatSettingsSync=gt,window.parent.postMessage({type:`yuri:chat-settings-request`},window.location.origin)}),Wn(()=>{if(typeof window>`u`)return;let e=window;e.__yuriApplyChatSettingsSync===gt&&delete e.__yuriApplyChatSettingsSync}),Z.useEffect(()=>{_.newSessionDraft&&e&&!r&&!qe&&y()},[e,r,qe,_.newSessionDraft,y]);let yt=Z.useRef(()=>{}),bt=J(e=>{yt.current(e)}),xt=Z.useRef(()=>{}),St=J(()=>{xt.current()}),[Ct,wt]=Z.useState(0),Tt=J(()=>{wt(e=>e+1)}),{scrollRef:Et,notifyContentChange:Dt,getAnimationHandlers:Ot,goToBottom:kt,scrollToBottomOnSend:At,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,restoreSnapshot:Pt,isPinned:Ft,isFollowingProgrammatically:It,showScrollButton:Lt}=WH({scrollControllerRef:Qe,enabled:n,currentSessionId:r,viewportKey:a,sessionMessageCount:B,sessionIsWorking:Ne,isMobile:Ue,onActiveTurnChange:bt,onUpwardUserIntent:St}),Rt=Z.useRef(null);QH({enabled:Ue,scrollRef:Et,scopeRef:Rt});let zt=Z.useRef([]),Bt=Z.useMemo(()=>{let e=oO(l?.entries??[],r,zt.current);return zt.current=e,e},[l?.entries,r]),Vt=Z.useRef([]),Ht=Z.useMemo(()=>{if(!l)return ae;let e=lO(l.entries,r,ae,Vt.current);return Vt.current=e,e},[l,r,ae]),Ut=Z.useMemo(()=>LD(Bt.length===0?Ht:r?[...Bt,iO(r),...Ht]:Bt,de),[r,Ht,Bt,de]),Wt=Z.useRef(null),Gt=Z.useMemo(()=>KD({sessionId:r,messages:Ut,retained:Wt.current}),[r,Ut]);Wt.current=Gt.retained;let Kt=Gt.messages,qt=Z.useRef(null),Jt=qt.current===r,Yt=Z.useRef(PW),Xt=r?`${A}\n${r}`:null,Zt=J(()=>NW(Kt));Z.useEffect(()=>{if(!LW({active:n,sessionId:r,sessionKey:Xt,sessionIsWorking:Ne})){Yt.current=RW(Yt.current);return}let e=r,t=A,i=setInterval(()=>{let n=Zt(),r=FW(Yt.current,{sessionKey:Xt,working:!0,streaming:!!R,fingerprint:n,now:Date.now(),thresholdMs:kW,cooldownMs:AW,maxAttempts:3});Yt.current=r.state,r.shouldRefresh&&(IW({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),Oe(t,e).catch(()=>{}))},jW);return()=>clearInterval(i)},[n,r,A,Zt,Ne,R,Xt]);let Qt=Z.useMemo(()=>{if(de.length===0)return[];let e=new Set([...Bt,...Ht].filter(e=>ID(e.parts)).map(e=>e.info.id));return de.map(e=>e.info.id).filter(t=>e.has(t))},[Ht,Bt,de]);Z.useEffect(()=>{Qt.length!==0&&(h?.(Qt),r&&ue(r,Qt))},[ue,r,Qt,h]);let $t=cW({sessionId:r,directory:A,messages:Kt,historyMeta:Ve,scrollRef:Et,messageListRef:Qe,loadMoreMessages:Se,goToBottom:kt,releaseAutoFollow:jt,beginHistoryViewportPreservation:Mt,endHistoryViewportPreservation:Nt,isPinned:Ft,showScrollButton:Lt,isMobile:Ue,onWillLoadEarlier:Tt}),en=J(()=>{kt(`instant`)}),tn=J(()=>{At()}),nn=VD({isMobile:Ue,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingOlder:$t.isLoadingOlder}),rn=$t.isLoadingOlder,an=$t.loadEarlier,on=J(()=>{an({userInitiated:!0})});yt.current=$t.handleActiveTurnChange,xt.current=$t.handleHistoryUpwardIntent,Z.useEffect(()=>{(ke.length!==0||Ae.length!==0)&&Dt(`permission`)},[Dt,ke,Ae]);let sn=OW({sessionId:r,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,scrollToTurn:$t.scrollToTurn,scrollToMessage:$t.scrollToMessage,resumeToBottom:en}),cn=ft.showReadOnlyBanner?ht:t?null:(0,$.jsx)(fD,{surface:s,scrollToBottom:tn,showScrollToBottom:Ue&&$t.showScrollToBottom,onScrollToBottom:sn.resumeToLatest,submissionBlocked:ft.blockSubmission},`composer-input`),ln=J(e=>{sn.scrollToTurnId(e,{behavior:`smooth`})}),un=$t.historySignals.canLoadEarlier,dn=_.promptNavigator&&!Ue&&!Ge&&!Xe&&P&&$t.turnIds.length>=2;Z.useEffect(()=>{dn||K.getState().setPromptNavigatorPanelOpen(!1)},[dn]);let fn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||kt(`instant`)});qn(mG,fn,n&&r&&typeof window<`u`?window:hG);let pn=J(e=>{if(!n||!r||Xe||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=K.getState();if(t!==`chat`||jG())return;let i=Et.current;if(AG(document.activeElement,i)||kG(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;sn.scrollByTurnOffset(a,{resumePastEnd:!1})});qn(`keydown`,pn,n&&r&&!Xe&&typeof window<`u`?window:hG);let mn=Z.useRef(0),hn=J(()=>{let e=Et.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),gn=J(()=>{mn.current||=requestAnimationFrame(()=>{mn.current=0,hn()})});Gn(()=>{n&&hn()},[n,r,Xe,hn]);let _n=typeof ResizeObserver<`u`;Hn(n&&_n?Et:null,gn),qn(`resize`,gn,n&&!_n&&typeof window<`u`?window:hG),Wn(()=>{mn.current&&=(cancelAnimationFrame(mn.current),0)});let vn=Z.useRef(null),yn=Z.useRef(0),bn=WD({transcriptMessageCount:ae.length,pendingUserCount:de.length,historyPrefixCount:Bt.length}),q=GD({hasTranscriptShell:bn,transcriptRecords:ae,p0Satisfied:he.p0Satisfied,hasBusyShell:Ne&&bn,hasImmediateShell:de.length>0||Bt.length>0,hasRenderableSessionSnapshot:H,prefetchStatus:me?.status,syncLoading:!!(r&&O.isLoading(r,{directory:A})),userRetrying:ye,hasPaintedTranscript:Jt});q===`pass`&&Kt.length>0&&(qt.current=r);let xn=!!r&&q===`hydrating`;fW({scope:JSON.stringify([u(),A,r]),enabled:n&&!Ue&&!We&&!!r&&q===`pass`&&he.p0Satisfied&&!Ne&&!Ve?.loading&&!$t.isLoadingOlder,cursor:xe.kind===`has-more`?xe.cursor:null,loadedTurns:xe.loadedTurns,messages:Kt,scrollRef:Et,loadPrevious:e=>pt(A,r,e)});let Sn=!!r&&q===`load-error`;Z.useEffect(()=>{!Sn||!r||mi(ui({kind:`request-error`,sessionID:r,directory:A,purpose:`load-failed`,source:`network`,request:me?{sessionID:r,status:me.status===`ready`?`ready`:me.status,error:me.error}:void 0,hydration:he,error:me?.error}))},[r,A,Sn,me,he]),Z.useEffect(()=>{if(!n||!r||xn)return;let e=Kt.length,t=vn.current!==r,i=!t&&yn.current===0&&e>0;if(!t&&!i){vn.current===r&&(yn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(vn.current=r,yn.current=e,a){jt();return}let o=()=>{Pt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,xn,jt,Pt,Kt.length]),Z.useEffect(()=>{G(e=>e.key===ne?e:{key:ne,attempt:0})},[ne]),Z.useEffect(()=>{if(!n||!r||re.key!==ne||!lG({sessionId:r,hasRenderableSessionSnapshot:H,hasCurrentSessionEntity:!!ee})||(j(r),ee||re.attempt>=2))return;let e=re.attempt+1,t=window.setTimeout(()=>{G(t=>t.key===ne&&t.attempt===re.attempt?{key:ne,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,ee,r,A,j,H,ne,re]);let Cn=w&&r&&(w.targetSessionId?r===w.targetSessionId:r===w.sourceSessionId)?w:null;if(Cn){let e=Cn.stage===`preparing`?`chat.forkTransition.preparing`:Cn.stage===`copying`?`chat.forkTransition.copying`:Cn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=v(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Cn.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${v(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:v(e)}),(0,$.jsx)(Kv,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}if(!r&&!qe)return e&&!Ye?(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`}):(0,$.jsx)(`div`,{className:`flex flex-col h-full bg-background`,children:(0,$.jsx)($D,{})});if(!r&&qe){if((S||C)&&oe){let e=`draft:${x.draftID??`pending`}`;return(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex h-full flex-col bg-background`,Ue&&`yuri-chat-composer-swap-scope`),children:[(0,$.jsx)(MG,{timelineHistoryAnchorToken:Ct,currentSessionId:e,virtualizerKey:e,isDesktopExpandedInput:!1,isMobile:Ue,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:!1,initialPinRevealComplete:!0,renderedMessages:[oe],isLoadingOlder:!1,sessionIsWorking:!0,streamingMessageId:null,activeStreamingPhase:null,retryOverlay:null,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:[],sessionPermissions:[],sessionForms:[],retryActionCopy:null,isProgrammaticFollowActive:It,showLoadOlderButton:!1,turnIds:[],activeTurnId:null,onSelectTurn:ln,showPromptNavigator:!1,canLoadEarlierPrompts:!1,isLoadingOlderPrompts:!1,onLoadEarlierPrompts:on,transcriptStatusRow:(0,$.jsx)(`div`,{className:`chat-column`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex h-[1.2rem] items-center py-0.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:v(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Kv,{})]})})},e),(0,$.jsxs)(`div`,{className:Y(`invisible pointer-events-none relative z-10`,Ue&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`absolute inset-0 bg-background`:`bg-background`),"aria-hidden":`true`,children:[!Ue&&!Xe?(0,$.jsx)(EG,{}):null,cn]})]})}return S||C?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":v(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:v(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Kv,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Ze&&!Xe?(0,$.jsxs)(`div`,{className:`yuri-draft-center flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-balance text-3xl font-normal tracking-tight text-foreground`,children:FG($e?v(`chat.emptyState.draftTitleWithProject`,{project:$e}):v(`chat.emptyState.draftTitle`),$e)}),(0,$.jsx)(SS,{onSubmit:e=>va.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`,Ue&&`yuri-mobile-composer-foot`,Xe?`flex-1 bg-background`:Ze?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:cn})]})}return r?Sn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[dt,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:v(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:v(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(er,{type:`button`,className:`mt-5`,onClick:be,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),v(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):xn?(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,Ue&&`yuri-chat-composer-swap-scope`),children:[dt,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:(0,$.jsx)(`div`,{ref:Et,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:TG,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:NG.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)(af,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(af,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(af,{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)(af,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(af,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(af,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!Ue&&!Xe?(0,$.jsx)(EG,{}):null,cn]},`composer-foot`)]}):Kt.length===0&&!Ne?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[dt,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Xe?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Xe,children:Xe?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)($D,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:cn},`composer-foot`)]}):(0,$.jsxs)(`div`,{ref:Rt,className:Y(`relative flex flex-col h-full bg-background`,Ue&&`yuri-chat-composer-swap-scope`),children:[f?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:f}):null,dt,(0,$.jsx)(MG,{timelineHistoryAnchorToken:Ct,currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Xe,isMobile:Ue,stickyUserHeader:N,directory:A,scrollRef:Et,messageListRef:Qe,pendingRevealWork:$t.pendingRevealWork,initialPinRevealComplete:le,renderedMessages:$t.renderedMessages,isLoadingOlder:rn,sessionIsWorking:Ne,streamingMessageId:R,activeStreamingPhase:z,retryOverlay:Re,handleMessageContentChange:Dt,getAnimationHandlers:Ot,handleHistoryScroll:$t.handleHistoryScroll,scrollToBottom:en,sessionQuestions:Ae,sessionPermissions:ke,sessionForms:Me,retryActionCopy:ze,isProgrammaticFollowActive:It,showLoadOlderButton:nn,turnIds:$t.turnIds,activeTurnId:$t.activeTurnId,onSelectTurn:ln,showPromptNavigator:dn,canLoadEarlierPrompts:un,isLoadingOlderPrompts:rn,onLoadEarlierPrompts:on},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,Ue&&`yuri-mobile-composer-foot yuri-mobile-composer-foot--overlay`,Xe?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!Ue&&!Xe?(0,$.jsx)(EG,{}):null,!Xe&&Kt.length>0&&(Ue?(0,$.jsx)(fx,{placement:`expanded`,visible:$t.showScrollToBottom,onClick:sn.resumeToLatest}):(0,$.jsx)(fx,{visible:$t.showScrollToBottom,onClick:sn.resumeToLatest})),cn]},`composer-foot`),(0,$.jsx)(hW,{open:I,onOpenChange:L,sessionID:r??void 0,directory:A,onRevertMessage:d,onScrollToMessage:$t.scrollToMessage,onScrollByTurnOffset:sn.scrollByTurnOffset,onResumeToLatest:en,canLoadEarlier:$t.historySignals.canLoadEarlier,isLoadingEarlier:rn,onLoadEarlier:on})]}):null});LG.displayName=`MemoizedChatContainerContent`;var RG=()=>{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)(af,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(af,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(af,{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)(af,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(af,{className:`h-4 w-3/5 animate-none rounded-md`})]})]})})}),e[1]=n):n=e[1],n},zG=({runtimeKey:e,...t})=>{let n=mx(),r=$o(),i=wa(H(e=>({sessionId:e.currentSessionId,directory:e.currentSessionDirectory,draftID:e.newSessionDraft.open?e.newSessionDraft.draftID:null,draftPendingMessageId:e.newSessionDraft.open?e.newSessionDraft.pendingUserMessage?.info.id??null:null}))),a=Z.useRef(null),o=i.draftID&&i.draftPendingMessageId?`${i.draftID}:${i.draftPendingMessageId}`:null;o&&a.current?.identity!==o&&(a.current=null),Gn(()=>{!o||!i.draftPendingMessageId||(a.current={identity:o,messageId:i.draftPendingMessageId})},[o,i.draftPendingMessageId]);let s=wa(e=>i.sessionId?e.retainedPendingUserMessages.get(i.sessionId)??dG:dG),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(()=>YW(u),[u]),f=d.key,m=xo()||p()||n===`mini-chat`?CG:SG,[h,g]=Z.useState(()=>({activeIntent:d,cacheNeedsTrim:!1,cachedSessionViews:u?ZW([],u,m,vG):[],pendingSessionView:null})),_=Z.useRef(d),v=Z.useRef(f),{cacheNeedsTrim:y,cachedSessionViews:b,pendingSessionView:x}=h,S=x?.intent===d?x.entry:null,C=Z.useMemo(()=>!u||!l?null:ZW([],u,m,vG)[0]??null,[m,l,u]),w=Z.useMemo(()=>{let e=[...b];return S&&!e.some(e=>e.key===S.key)&&e.push(S),C&&!e.some(e=>e.key===C.key)&&e.push(C),e.sort((e,t)=>e.key.localeCompare(t.key))},[b,C,S]),T=$W(w,f),E=!!(f&&!T);Gn(()=>{_.current=d,v.current=f,g(e=>{let t=eG(e,d,m);return l?tG(t,d,d,vG):t})},[m,y,l,d,f]);let D=x?.intent??null;Gn(()=>{D&&g(e=>nG(e,D,m))},[m,D]),Z.useEffect(()=>{if(!d.selection||T)return;let e=d,t=f;return Td(()=>{_.current===e&&v.current===t&&g(n=>v.current===t?tG(n,e,_.current,vG):n)},{priority:`user-blocking`})},[T,m,d,f]);let O=J((e,t)=>{let n=_.current,r=v.current;g(i=>{if(_.current!==n||v.current!==r||i.activeIntent!==n||e!==r)return i;let a=QW(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})});return(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":E||void 0,children:[E?(0,$.jsx)(RG,{},f):null,w.map(e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:T===e.key?`visible`:`hidden`,children:(0,$.jsx)(LG,{...t,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:O,committedDraftHandoffMessageId:T===e.key?l:null})},e.key)),f?null:(0,$.jsx)(LG,{...t,sessionId:null,sessionDirectory:i.directory})]})},BG=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=qD(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)(LG,{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)(kb.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},VG=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=$o(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Ob({...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)(LG,{...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)(kb.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},HG=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(wG,u,u);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(BG,{...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)(VG,{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)(zG,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r},UG=2e4,WG=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus()?`visible`:`hidden`,GG=e=>{if(!y()&&!$e())return;let t=S();t?.push?.setVisibility&&t.push.setVisibility({visible:e,platform:st()})},KG=e=>{let t=e?.enabled??!0;Z.useEffect(()=>{if(!t||!y()&&!$e()||typeof window>`u`)return;if($e()){let e=!0,t=!1,n=null,r=()=>GG(e);Pn(async()=>{let{App:e}=await import(`./vendor-capacitor-app-B5H_XtmE.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([72,1,26])).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&&GG(!0)},UG);return()=>{t=!0,window.clearInterval(i),n?.()}}if(typeof document>`u`)return;let e=()=>{GG(WG()===`visible`)},n=()=>{WG()===`visible`&&GG(!0)},r=()=>{GG(!1)};e();let i=window.setInterval(n,UG);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])},qG=`Yuri`,JG=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``).split(`/`).filter(Boolean);return t[t.length-1]??``},YG=(e,t)=>[e,t,qG].filter(e=>typeof e==`string`&&e.trim().length>0).join(` | `),XG=()=>{let e=Ia(e=>{if(!e.activeProjectId)return null;let t=e.projects.find(t=>t.id===e.activeProjectId);return t&&JG(t.path)||null}),[t,n]=Z.useState(null);Z.useEffect(()=>{if(typeof window>`u`||!g()){n(null);return}let e=!1,t=async()=>{try{if(x()){e||n(null);return}let t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,r=d();if(r&&j(r,t)){e||n(null);return}let i=(await M()).hosts.find(e=>r?j(r,P(e)):!1),a=i?.label?.trim()?T(i.label.trim()):`Instance`;e||n(a)}catch{e||n(`Instance`)}};t();let r=()=>{t()};return window.addEventListener(`focus`,r),()=>{e=!0,window.removeEventListener(`focus`,r)}},[]);let r=Z.useMemo(()=>YG(e,t),[e,t]);Z.useEffect(()=>{typeof document<`u`&&(document.title=r),g()&&(async()=>{try{if(typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``))return;await nr(r)}catch{return}})()},[r])},ZG=e=>{let t=[];return e.hideGit||t.push(`git`),t.push(`files`),e.showBrowser&&t.push(`browser`),t},QG=e=>e===`git`||e===`files`||e===`browser`,$G=()=>{let e=wa.getState().currentSessionId;if(!e)return``;let t=Le().find(t=>t.id===e);return typeof t?.directory==`string`?t.directory:``},eK=async(e,t=6e3)=>{let n=new AbortController,r=setTimeout(()=>n.abort(),t),i=Date.now();try{let t=await f(e,{method:`GET`,headers:{Accept:`application/json`},signal:n.signal}),r=Date.now()-i,a=t.headers.get(`content-type`)||``,o=a.toLowerCase(),s=o.includes(`json`)&&!o.includes(`text/html`),c=``;if(s){let e=await t.json().catch(()=>null);if(Array.isArray(e))c=`json[array] len=${e.length}`;else if(e&&typeof e==`object`){let t=Object.keys(e).slice(0,8);c=`json[object] keys=${t.join(`,`)}${Object.keys(e).length>t.length?`,…`:``}`}else c=`json[${typeof e}]`}else c=a?`content-type=${a}`:`no content-type`;return{ok:t.ok&&s,status:t.status,elapsedMs:r,summary:c}}catch(e){return{ok:!1,status:0,elapsedMs:Date.now()-i,summary:`error=${n.signal.aborted||e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))?`timeout after ${t}ms`:e instanceof Error?e.message:String(e)}`}}finally{clearTimeout(r)}},tK=e=>{if(!e||!Number.isFinite(e))return`(n/a)`;try{return new Date(e).toISOString()}catch{return`(invalid)`}},nK=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},rK=e=>!!e&&typeof e==`object`&&!Array.isArray(e),iK=(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,aK=(e,t,n)=>e===`node-shebang`||e===`node-launcher`?t?`node (${t})`:`node`:e===`bun-shebang`?n?`bun (${n})`:`bun`:e||`direct executable`,oK=async()=>{let e=new Date,t=typeof navigator<`u`?navigator.userAgent:`(no navigator)`,n=$G(),r=K.getState().eventStreamStatus,i=typeof window<`u`?window.location.origin:``,o=a(),s=o.health(),c=o.api(`/api/`),l=await(async()=>{if(!s)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),5e3);try{let t=await f(s,{method:`GET`,headers:{Accept:`application/json`},signal:e.signal});if(!t.ok)return null;let n=await t.json().catch(()=>null);return!n||typeof n!=`object`||Array.isArray(n)?null:n}catch{return null}finally{clearTimeout(t)}})(),u=await(async()=>{if(!c)return null;let e=new AbortController,t=setTimeout(()=>e.abort(),7e3);try{let t=await f(o.api(`/api/config/opencode-resolution`),{method:`GET`,headers:{Accept:`application/json`},signal:e.signal}),n=t.headers.get(`content-type`)||`(none)`;if(!t.ok)return{data:null,status:t.status,error:`http ${t.status} content-type=${n}`};let r=await t.text(),i=null;try{i=JSON.parse(r)}catch{let e=r.replace(/\s+/g,` `).slice(0,120);return{data:null,status:t.status,error:`invalid json content-type=${n} body=${e||`(empty)`}`}}return!i||typeof i!=`object`||Array.isArray(i)?{data:null,status:t.status,error:`invalid json-shape content-type=${n}`}:{data:i,status:t.status,error:null}}catch(e){return{data:null,status:null,error:e instanceof Error?e.message:String(e)}}finally{clearTimeout(t)}})()||{data:null,status:null,error:null},d=(e,t=!0)=>{if(!c)return null;let r=new URL(e.replace(/^\/+/,``),c);return t&&n&&r.searchParams.set(`directory`,n),r.toString()},p=c?await Promise.all([{label:`health`,path:`/health`,includeDirectory:!1},{label:`config`,path:`/config`,includeDirectory:!0},{label:`providers`,path:`/config/providers`,includeDirectory:!0},{label:`agents`,path:`/agent`,includeDirectory:!0,timeoutMs:12e3},{label:`commands`,path:`/command`,includeDirectory:!0,timeoutMs:1e4},{label:`project`,path:`/project/current`,includeDirectory:!0},{label:`path`,path:`/path`,includeDirectory:!0},{label:`sessions`,path:`/session`,includeDirectory:!0,timeoutMs:12e3},{label:`sessionStatus`,path:`/session/status`,includeDirectory:!0}].map(async e=>{let t=d(e.path,e.includeDirectory!==!1);if(!t)return{label:e.label,url:`(none)`,result:null};let n=await eK(t,typeof e.timeoutMs==`number`?e.timeoutMs:void 0);return{label:e.label,url:t,result:n}})):[],m=[];m.push(`Time: ${e.toISOString()}`),m.push(`Yuri version: 0.2.0-beta.9`),m.push(`Runtime: ${i||`(unknown)`} (api=${c||`(unknown)`})`),m.push(`OpenCode SDK base: ${Te.getBaseUrl()}`),m.push(`Event stream: ${r}`),m.push(`Directory: ${n||`(none)`}`),m.push(`Platform: ${t}`);let h=nK(l?.openCodePort);if(m.push(`OpenCode runtime port: ${h??`(unknown)`}`),typeof l?.openCodeRunning==`boolean`&&m.push(`OpenCode runtime running: ${l.openCodeRunning?`yes`:`no`}`),typeof l?.openCodeSecureConnection==`boolean`&&m.push(`Secure OpenCode connection: ${l.openCodeSecureConnection?`true`:`false`}`),typeof l?.openCodeAuthSource==`string`&&l.openCodeAuthSource.trim()&&m.push(`OpenCode auth source: ${l.openCodeAuthSource}`),typeof l?.openCodeServeVersion==`string`&&l.openCodeServeVersion.trim()&&m.push(`OpenCode serve version: ${l.openCodeServeVersion}`),typeof l?.openCodeCliVersion==`string`&&l.openCodeCliVersion.trim()&&m.push(`OpenCode CLI version: ${l.openCodeCliVersion}`),rK(l?.runtimeContract)){let e=l.runtimeContract,t=typeof e.phase==`string`?e.phase:`(unknown)`,n=e.executionAllowed===!0?`allowed`:`limited`,r=e.protocolCompatible===!0?`compatible`:`incompatible`;m.push(`OpenCode runtime contract: phase=${t} protocol=${r} execution=${n}`),Array.isArray(e.reasons)&&e.reasons.length>0&&m.push(`OpenCode contract reasons: ${e.reasons.filter(e=>typeof e==`string`).join(`, `)}`)}if(typeof window<`u`){let e=window.__YURI_MACOS_MAJOR__;typeof e==`number`&&Number.isFinite(e)&&e>0&&m.push(`macOS major: ${e}`)}if(/Mac OS X|Macintosh/.test(t)){m.push(``),m.push(`OpenCode CLI resolution:`);let e=rK(l?.lastOpenCodeLaunchDiagnostics)?l.lastOpenCodeLaunchDiagnostics:null,t=e&&Array.isArray(e.args)?e.args.filter(e=>typeof e==`string`):[],n=u.data,r=n&&typeof n.configured==`string`?n.configured:null,i=n&&typeof n.resolved==`string`?n.resolved:l&&typeof l.opencodeBinaryResolved==`string`?l.opencodeBinaryResolved:``,a=n&&typeof n.resolvedDir==`string`?n.resolvedDir:``,o=n&&typeof n.source==`string`?n.source:l&&typeof l.opencodeBinarySource==`string`?l.opencodeBinarySource:``,s=n&&typeof n.launchBinary==`string`?n.launchBinary:l&&typeof l.opencodeLaunchBinary==`string`?l.opencodeLaunchBinary:``,c=n&&typeof n.launchWrapperType==`string`?n.launchWrapperType:l&&typeof l.opencodeLaunchWrapperType==`string`?l.opencodeLaunchWrapperType:``,d=n&&Array.isArray(n.launchArgs)?n.launchArgs.filter(e=>typeof e==`string`):l&&Array.isArray(l.opencodeLaunchArgs)?l.opencodeLaunchArgs.filter(e=>typeof e==`string`):[],f=n&&typeof n.node==`string`?n.node:l&&typeof l.nodeBinaryResolved==`string`?l.nodeBinaryResolved:``,p=n&&typeof n.bun==`string`?n.bun:l&&typeof l.bunBinaryResolved==`string`?l.bunBinaryResolved:``,h=n&&typeof n.detectedNow==`string`?n.detectedNow:``,g=n&&typeof n.detectedSourceNow==`string`?n.detectedSourceNow:``;if(r!==null&&m.push(`- configured: ${r.trim().length===0?`(cleared)`:r}`),i){let e=a||(i.includes(`/`)?i.split(`/`).slice(0,-1).join(`/`)||`/`:``);m.push(`- opencode: ${i}${e?` (dir=${e})`:``}`)}else m.push(`- opencode: (n/a)`);m.push(`- source: ${o||`(n/a)`}`),h&&(m.push(`- detected-now: ${h}`),m.push(`- detected-source: ${g||`(n/a)`}`)),e?(m.push(`- launched-at: ${iK(e.launchedAt)}`),m.push(`- launch: ${iK(e.binary)} ${t.join(` `)}`.trim()),m.push(`- cwd: ${iK(e.cwd)}`),m.push(`- wrapper: ${iK(e.wrapperType)}`),m.push(`- runtime: ${aK(iK(e.wrapperType,``),f,p)}`),m.push(`- PATH entries: ${iK(e.pathEntryCount,`(unknown)`)}`),m.push(`- shell env: ${iK(e.hasShellEnv,`(unknown)`)} (${iK(e.shellEnvKeysCount,`?`)} keys)`)):(m.push(`- launch-binary: ${s||`(n/a)`}`),m.push(`- launch-wrapper: ${c||`(n/a)`}`),m.push(`- launch-args: ${d.length?d.join(` `):`(none)`}`),m.push(`- runtime: ${aK(c||``,f,p)}`)),!n&&u.error&&m.push(`- resolution-endpoint: ${u.error}`)}if(m.push(``),p.length){m.push(`OpenCode API probes:`);for(let e of p){if(!e.result){m.push(`- ${e.label}: (no url)`);continue}let{ok:t,status:n,elapsedMs:r,summary:i}=e.result,a=t?``:` url=${e.url}`;m.push(`- ${e.label}: ${t?`ok`:`fail`} status=${n} time=${r}ms ${i}${a}`)}}else m.push(`OpenCode API probes: (skipped)`);return m.push(``),m.push(`Generated: ${tK(Date.now())}`),m.join(`
|
|
6602
|
+
`)},sK=async()=>{let e=await oK(),t=K.getState();t.setOpenCodeStatusText(e),t.setOpenCodeStatusDialogOpen(!0)},cK=(e,t)=>e===t?!0:!e||!t?!1:e.scope===t.scope&&e.sessionId===t.sessionId&&e.projectId===t.projectId,lK=e=>e?`${e.scope}:${e.projectId??``}:${e.sessionId}`:null,uK=e=>({scope:`project`,sessionId:e,projectId:null}),dK=L()(e=>({focus:null,setFocus:t=>e(e=>cK(e.focus,t)?e:{focus:t})})),fK=null,pK=0,mK=(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},hK=e=>{let t=++pK;return fK={pinned:mK(`pinned`,e.pinned),project:mK(`project`,e.project)},()=>{pK===t&&(fK=null)}},gK=()=>fK,_K=e=>!!e.parentID,vK=(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&&_K(r);){let e=r.parentID;if(!e)break;let t=n.get(e);if(!t)return e;r=t}return r?.id??e},yK=()=>{let e=xi.getState().activeSessions;if(e.length>0)return e;let t=be();return t.length>0?t:Le()},bK=(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)},xK=e=>[...e.pinned,...e.project],SK=(e,t,n,r)=>{if(e.length===0)return null;let i=bK(e,n,r);return i<0?t>0?e[0]??null:e[e.length-1]??null:e[(i+t+e.length)%e.length]??null},CK=(e,t,n=dK.getState().focus)=>{let r=vK(t,yK()),i=n?.sessionId===t?n:null,a=gK();return a?SK(xK(a),e,r,i):null},wK=(e,t,n=e=>{wa.getState().setCurrentSession(e.sessionId,e.directory)})=>{let r=CK(e,t);return r?(dK.getState().setFocus({scope:r.scope,sessionId:r.sessionId,projectId:r.projectId}),n(r),r):null},TK=.5,EK=.1,DK=`yuri.webviewZoomFactor`,OK=e=>Number.isFinite(e)?Math.min(3,Math.max(TK,Math.round(e*100)/100)):1,kK=()=>{if(typeof window>`u`)return 1;try{let e=window.localStorage.getItem(DK);return e?OK(Number.parseFloat(e)):1}catch{return 1}},AK=e=>{if(!(typeof window>`u`))try{window.localStorage.setItem(DK,String(e))}catch{}},jK=e=>{let t=OK(e);return typeof document<`u`&&(document.documentElement.style.zoom=t===1?``:String(t)),AK(t),t},MK=()=>{if(typeof document>`u`)return 1;let e=document.documentElement.style.zoom;if(!e)return kK();let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?OK(t):kK()},NK=()=>{if(v())return;let e=kK();e!==1&&jK(e)},PK=async()=>{if(v())try{let e=await h(`desktop_zoom_in`);if(typeof e==`number`&&Number.isFinite(e))return OK(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_in failed, using CSS zoom`,e)}return jK(MK()+EK)},FK=async()=>{if(v())try{let e=await h(`desktop_zoom_out`);if(typeof e==`number`&&Number.isFinite(e))return OK(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_out failed, using CSS zoom`,e)}return jK(MK()-EK)},IK=async()=>{if(v())try{let e=await h(`desktop_zoom_reset`);if(typeof e==`number`&&Number.isFinite(e))return OK(e)}catch(e){console.warn(`[webview-zoom] desktop_zoom_reset failed, using CSS zoom`,e)}return jK(1)},LK=9,RK=null,zK=0,BK=({pinnedTargets:e,projectTargets:t})=>[...e,...t].slice(0,LK),VK=(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},HK=e=>{let t=++zK;return RK={targets:e.targets.slice(0,LK),activate:e.activate},()=>{zK===t&&(RK=null)}},UK=e=>{if(!Number.isInteger(e)||e<1||e>LK)return!1;let t=RK,n=t?.targets[e-1];return!t||!n?!1:(t.activate(n),!0)},WK=e=>{let t=e.trim();if(!t)return null;let n=uf.getState(),r=n.createTab(t);return!r||r===`tab-invalid`?null:(n.setActiveTab(t,r),r)},GK=e=>{let t=e.trim();if(!t)return null;let n=K.getState();return!n.isBottomTerminalOpen&&n.activeMainTab!==`terminal`&&n.setBottomTerminalOpen(!0),WK(t)},KK=(e,t)=>{let n=e.trim();if(!n)return!1;let r=uf.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)},qK=e=>{let t=e.trim();if(!t)return{closed:!1,wasLastTab:!1};let n=uf.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}},JK=()=>typeof window>`u`||window.parent===window||!nl(window.location.search)?!1:(window.parent.postMessage({type:al},window.location.origin),!0),YK=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=K.getState();if(e)return!1;let n=xd();return n&&t(n)?!0:v()?(h(`desktop_close_current_window`).catch(e=>{console.warn(`[keyboard-shortcuts] failed to close current window`,e)}),!0):!1},XK=({sessionId:e,surfaceKind:t,wiringCanAbort:n,primaryCanAbort:r,pendingSend:i=!1})=>e?i||n?!0:t!==`secondary`&&r:!1,ZK=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)}},QK=()=>{let e=(0,Q.c)(69),{t}=Xn(),n=wa($K),r=wa(eq),i=wa(tq),a=wa(nq),o=ja,s=K(rq),c=K(iq),l=K(aq),u=K(oq),d=K(sq),f=K(cq),m=K(lq),g=K(uq),_=K(dq),y=K(fq),b=K(pq),x=K(mq),S=K(hq),C=K(gq),w=K(_q),T=K(vq),E=K(yq),D=K(bq),O=K(xq),k=le(Sq),A=Ia(Cq),{themeMode:j,setThemeMode:M}=fs(),{working:N}=nR(),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),$m.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=$m.getState().arm(Qm);I.current=setTimeout(()=>{let{expiresAt:e}=$m.getState();e&&Date.now()>=e&&$m.getState().clear(),I.current=null},Math.max(0,e-Date.now()))},e[6]=ee):ee=e[6];let te=ee,ne;e[7]!==A?.id||e[8]!==A?.path||e[9]!==r||e[10]!==k||e[11]!==_||e[12]!==n||e[13]!==H||e[14]!==b||e[15]!==C||e[16]!==g||e[17]!==S||e[18]!==E||e[19]!==d||e[20]!==f||e[21]!==y||e[22]!==x||e[23]!==M||e[24]!==w||e[25]!==O||e[26]!==t||e[27]!==m||e[28]!==s||e[29]!==D||e[30]!==c||e[31]!==T||e[32]!==u||e[33]!==l||e[34]!==N?(ne=()=>{let e=e=>Ec(e,O),i=e=>bc(e,O),a=wq,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=Eq,B=Oq,V=kq,U=async()=>{let e=$w(),n=e?aT(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;ji.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}=Ko.getState();await ZK({sessionId:r,currentProviderId:i,currentModelId:a,waitForConnectionOrThrow:oa,getAuthoritativeDirectoryForSession:wa.getState().getAuthoritativeDirectoryForSession,summarizeSession:Aq,onCompactFailed:e=>{ji.error(e instanceof Error?e.message:t(`chat.chatInput.toast.compactFailed`))}})},ee=t=>{let r=$m.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&&Tc(t,i)){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),te();return}let r=t.key.toLowerCase();if(r===`escape`){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),W();return}if(t.key===`Control`||t.key===`Shift`||t.key===`Alt`||t.key===`Meta`)return;if(t.metaKey||t.ctrlKey||t.altKey){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();return}let{activeMainTab:a,isModelSelectorOpen:o,isAgentSelectorOpen:s}=K.getState(),c=Qw(a)&&!V();if(r===`m`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),window.requestAnimationFrame(()=>{S(!o,{instant:!0})});return}if(r===`a`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W(),C(!s,{instant:!0});return}if(r===`n`&&c){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),e(),W();let r=$w(),i=r?aT(r):null;i?i.shortcut(`new`):(b(`chat`),y(!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||!Tc(t,i)||V())return;let{activeMainTab:o}=K.getState();Qw(o)&&(t.preventDefault(),t.stopPropagation(),te())},ne=()=>$m.getState().pending||L.current,re=e=>{ne()&&e.preventDefault()},G=e=>{ne()&&(e.preventDefault(),e.stopPropagation())},ie=t=>{if(a(t.target)){if(!p()&&Tc(t,e(`new_terminal_tab`))){let e=xd();if(!e||!WK(e))return;t.preventDefault(),t.stopPropagation();return}if(!p()&&Tc(t,e(`previous_terminal_tab`))){let e=xd();if(!e||!KK(e,-1))return;t.preventDefault(),t.stopPropagation();return}if(!p()&&Tc(t,e(`next_terminal_tab`))){let e=xd();if(!e||!KK(e,1))return;t.preventDefault(),t.stopPropagation();return}if(Tc(t,e(`close_context_panel_tab`))){let e=xd();if(!e)return;let{closed:n,wasLastTab:r}=qK(e);if(!n)return;if(t.preventDefault(),t.stopPropagation(),r){let e=K.getState();e.setBottomTerminalOpen(!1),e.activeMainTab===`terminal`&&e.setActiveMainTab(`chat`)}return}if(Tc(t,e(`toggle_terminal`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),m();return}if(Tc(t,e(`toggle_bottom_panel`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),m();return}if(Tc(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=K.getState();if(e)return;t.preventDefault(),t.stopPropagation(),g(!n);return}}},ae=jq,oe=t=>{if(t.defaultPrevented)return;if(Tc(t,e(`close_context_panel_tab`))){(JK()||YK())&&(t.preventDefault(),t.stopPropagation());return}if(a(t.target))return;let r=Mq;if(r(t.target)&&t.ctrlKey&&!t.metaKey&&!t.shiftKey&&!t.altKey&&t.key.toLowerCase()===`t`){t.preventDefault(),ae();return}if(Tc(t,e(`open_command_palette`))){t.preventDefault(),s();return}if(Tc(t,e(`open_timeline_dialog`))){t.preventDefault(),w(!0);return}if(Tc(t,e(`toggle_prompt_navigator`))){let{activeMainTab:e,promptNavigatorEnabled:n,isSettingsDialogOpen:r,isCommandPaletteOpen:i,isHelpDialogOpen:a,isSessionSwitcherOpen:o,isAboutDialogOpen:s,isTimelineDialogOpen:c,isMultiRunLauncherOpen:l,isImagePreviewOpen:u}=K.getState();if(!n||_||p()||e!==`chat`||r||i||a||o||s||c||l||u)return;t.preventDefault(),T();return}if(Tc(t,e(`open_status`))){t.preventDefault(),sK();return}if(Tc(t,e(`open_help`))){t.preventDefault(),c();return}if(v()&&Tc(t,e(`new_mini_chat`))){t.preventDefault(),h(`desktop_open_draft_mini_chat_window`,{directory:k||A?.path||``,projectId:A?.id??null}).catch(Nq);return}let o=Tc(t,e(`new_chat`)),C=Tc(t,e(`new_chat_worktree`));if(o||C){if(t.preventDefault(),b(`chat`),y(!1),!p()&&C){Jx();return}n();return}if(Tc(t,e(`cycle_theme`))){if(t.preventDefault(),Ap()!==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(Rc(t,`in`,e(`zoom_in`))){t.preventDefault(),PK();return}if(Rc(t,`out`,e(`zoom_out`))){t.preventDefault(),FK();return}if(Tc(t,e(`zoom_reset`))){t.preventDefault(),IK();return}if(Tc(t,e(`open_settings`))){t.preventDefault();let{isSettingsDialogOpen:e}=K.getState();x(!e);return}if(Tc(t,e(`toggle_sidebar`))){t.preventDefault();let{isMobile:e,isSessionSwitcherOpen:n}=K.getState();e?y(!n):l();return}if(Tc(t,e(`focus_input`))){t.preventDefault(),document.querySelector(`textarea[data-chat-input="true"]`)?.focus();return}let E=e(`cycle_agent`),O=E&&!E.includes(`shift`)?hc(`shift+${E}`):``,j=O&&Tc(t,O)?-1:+!!Tc(t,E);if(j!==0){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s}=K.getState();if(e||n||i||a||o||!Qw(s)||!r(t.target))return;let c=$w(),l=c?aT(c):null;if(l){t.preventDefault(),l.shortcut(`cycle`,j);return}let u=Ko.getState(),d=li(u.getVisibleAgents(),u.currentAgentName,j);if(!d)return;t.preventDefault(),u.setAgent(d),K.getState().addRecentAgent(d);let f=wa.getState().currentSessionId;f&&ur.getState().saveSessionAgentSelection(f,d);return}if(i(`toggle_right_sidebar`).some(e=>Tc(t,e))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),u();return}if(Tc(t,e(`open_right_sidebar_git`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),d(!0),f(`git`);return}if(Tc(t,e(`open_right_sidebar_files`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),d(!0),f(`files`);return}if(Tc(t,e(`cycle_right_sidebar_tab`))){let{isMobile:e,rightSidebarTab:n}=K.getState();if(e)return;let r=ZG({hideGit:K.getState().activeMainTab===`git`,showBrowser:Cc(Ic())}),i=r[(r.indexOf(n)+1)%r.length];t.preventDefault(),d(!0),f(i);return}let N=e=>wK(e,wa.getState().currentSessionId,e=>{b(`chat`),y(!1),wa.getState().setCurrentSession(e.sessionId,e.directory)});if(i(`previous_session`).some(e=>Tc(t,e))){t.preventDefault(),N(-1);return}if(i(`next_session`).some(e=>Tc(t,e))){t.preventDefault(),N(1);return}for(let n=1;n<=9;n+=1)if(Tc(t,e(`switch_tab_${n}`))){UK(n)&&t.preventDefault();return}if(Tc(t,e(`toggle_terminal`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),m();return}if(Tc(t,e(`open_new_terminal`))){let{isMobile:e}=K.getState();if(e||p())return;let n=xd();if(!n||!GK(n))return;t.preventDefault();return}if(Tc(t,e(`toggle_bottom_panel`))){let{isMobile:e}=K.getState();if(e)return;t.preventDefault(),m();return}if(Tc(t,e(`toggle_terminal_expanded`))){let{isMobile:e,isBottomTerminalExpanded:n}=K.getState();if(e)return;t.preventDefault(),g(!n);return}if(Tc(t,e(`open_model_selector`))){let{isSettingsDialogOpen:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isAboutDialogOpen:a,activeMainTab:o,isModelSelectorOpen:s}=K.getState();if(e)return;let c=n||r||i||a,l=Qw(o);if(c||!l)return;t.preventDefault(),S(!s,{instant:!0});return}if(Tc(t,e(`cycle_thinking_variant`))){ae()&&t.preventDefault();return}if(Tc(t,e(`cycle_favorite_model_forward`))||Tc(t,e(`cycle_favorite_model_backward`))){let{isSettingsDialogOpen:n,isCommandPaletteOpen:r,isHelpDialogOpen:i,isSessionSwitcherOpen:a,isAboutDialogOpen:o,activeMainTab:s,favoriteModels:c,addRecentModel:l}=K.getState();if(n)return;let u=r||i||a||o,d=Qw(s);if(u||!d||c.length===0)return;t.preventDefault();let f=c.length,p=Tc(t,e(`cycle_favorite_model_forward`))?1:-1,m=$w();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=Ko.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}=Ko.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(Tc(t,e(`expand_input`))){if(_)return;t.preventDefault(),D();return}if(Tc(t,e(`toggle_dictation`))){let{activeMainTab:e,isCommandPaletteOpen:n,isHelpDialogOpen:r,isSessionSwitcherOpen:i,isSettingsDialogOpen:a}=K.getState();if(!Qw(e)||n||r||i||a)return;t.preventDefault(),window.dispatchEvent(new CustomEvent(`yuri:dictation-toggle`));return}},se=e=>{if(e.key!==`Escape`||e.isComposing)return;let t=e.target,n=!!t?.closest(`[role="dialog"]`),i=!!document.querySelector(`[data-settings-view="true"]`),a=!!(t?.closest(`.terminal-viewport-container`)||t?.getAttribute(`data-terminal-hidden-input`)===`true`),s=I(t)||z(),{isSettingsDialogOpen:c,isCommandPaletteOpen:l,isHelpDialogOpen:u,isSessionSwitcherOpen:d,isAboutDialogOpen:f,isMultiRunLauncherOpen:p,isImagePreviewOpen:m,isPromptNavigatorPanelOpen:h}=K.getState();if(n||a||s){H();return}if(h){e.preventDefault(),E(!1),H();return}if(c){e.preventDefault(),x(!1),H();return}if(i){H();return}if(l||u||d||f||p||m){H();return}let g=$w(),_=g?aT(g):null,v=g?.sessionID??wa.getState().currentSessionId,y=!!(v&&wa.getState().pendingSendMessageIDs.get(v));if(!XK({sessionId:v,surfaceKind:g?.kind,wiringCanAbort:_?.canAbort,primaryCanAbort:N.canAbort,pendingSend:y})){H();return}e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();let b=Date.now(),S=P.current;if(S&&b<S){H(),_?_.abort():(v&&kr(v),o(v??``));return}let C=g?.kind===`secondary`?b+3e3:r(3e3)??b+3e3;P.current=C,F.current&&clearTimeout(F.current);let w=Math.max(C-b,0);F.current=setTimeout(()=>{P.current&&Date.now()>=P.current&&H()},w||0)};return window.addEventListener(`keydown`,ee,!0),window.addEventListener(`beforeinput`,re,!0),window.addEventListener(`compositionstart`,G,!0),window.addEventListener(`compositionupdate`,G,!0),window.addEventListener(`compositionend`,G,!0),window.addEventListener(`keydown`,ie,!0),window.addEventListener(`keydown`,se,!0),window.addEventListener(`keydown`,oe),()=>{window.removeEventListener(`keydown`,ee,!0),window.removeEventListener(`beforeinput`,re,!0),window.removeEventListener(`compositionstart`,G,!0),window.removeEventListener(`compositionupdate`,G,!0),window.removeEventListener(`compositionend`,G,!0),window.removeEventListener(`keydown`,ie,!0),window.removeEventListener(`keydown`,se,!0),window.removeEventListener(`keydown`,oe)}},e[7]=A?.id,e[8]=A?.path,e[9]=r,e[10]=k,e[11]=_,e[12]=n,e[13]=H,e[14]=b,e[15]=C,e[16]=g,e[17]=S,e[18]=E,e[19]=d,e[20]=f,e[21]=y,e[22]=x,e[23]=M,e[24]=w,e[25]=O,e[26]=t,e[27]=m,e[28]=s,e[29]=D,e[30]=c,e[31]=T,e[32]=u,e[33]=l,e[34]=N,e[35]=ne):ne=e[35];let re=A?.id,G=A?.path,ie;e[36]!==r||e[37]!==k||e[38]!==a||e[39]!==_||e[40]!==n||e[41]!==H||e[42]!==b||e[43]!==C||e[44]!==g||e[45]!==S||e[46]!==E||e[47]!==d||e[48]!==f||e[49]!==y||e[50]!==x||e[51]!==M||e[52]!==w||e[53]!==O||e[54]!==t||e[55]!==re||e[56]!==G||e[57]!==m||e[58]!==s||e[59]!==D||e[60]!==c||e[61]!==T||e[62]!==u||e[63]!==l||e[64]!==N?(ie=[n,o,s,c,l,u,d,f,m,g,_,y,b,x,S,C,w,T,E,D,M,N,r,H,te,W,a,k,re,G,O,t],e[36]=r,e[37]=k,e[38]=a,e[39]=_,e[40]=n,e[41]=H,e[42]=b,e[43]=C,e[44]=g,e[45]=S,e[46]=E,e[47]=d,e[48]=f,e[49]=y,e[50]=x,e[51]=M,e[52]=w,e[53]=O,e[54]=t,e[55]=re,e[56]=G,e[57]=m,e[58]=s,e[59]=D,e[60]=c,e[61]=T,e[62]=u,e[63]=l,e[64]=N,e[65]=ie):ie=e[65],Z.useEffect(ne,ie);let ae,oe;e[66]===H?(ae=e[67],oe=e[68]):(oe=()=>()=>{H(),W()},ae=[H,W],e[66]=H,e[67]=ae,e[68]=oe),Z.useEffect(oe,ae)};function $K(e){return e.openNewSessionDraft}function eq(e){return e.armAbortPrompt}function tq(e){return e.clearAbortPrompt}function nq(e){return e.currentSessionId}function rq(e){return e.toggleCommandPalette}function iq(e){return e.toggleHelpDialog}function aq(e){return e.toggleSidebar}function oq(e){return e.toggleRightSidebar}function sq(e){return e.setRightSidebarOpen}function cq(e){return e.setRightSidebarTab}function lq(e){return e.toggleBottomTerminal}function uq(e){return e.setBottomTerminalExpanded}function dq(e){return e.isMobile}function fq(e){return e.setSessionSwitcherOpen}function pq(e){return e.setActiveMainTab}function mq(e){return e.setSettingsDialogOpen}function hq(e){return e.setModelSelectorOpen}function gq(e){return e.setAgentSelectorOpen}function _q(e){return e.setTimelineDialogOpen}function vq(e){return e.togglePromptNavigatorPanel}function yq(e){return e.setPromptNavigatorPanelOpen}function bq(e){return e.toggleExpandedInput}function xq(e){return e.shortcutOverrides}function Sq(e){return e.currentDirectory}function Cq(e){return e.getActiveProject()}function wq(e){return e instanceof Element&&!!(e.closest(`[data-terminal-view="true"]`)||e.closest(`.terminal-viewport-container`)||e.getAttribute(`data-terminal-hidden-input`)===`true`)}function Tq(e){return e.getClientRects().length>0}function Eq(){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(Tq)}function Dq(){document.querySelector(`textarea[data-chat-input="true"]`)?.focus({preventScroll:!0})}function Oq(){window.requestAnimationFrame(Dq)}function kq(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i}=K.getState();return e||t||n||r||i}function Aq(e,t,n,r){return Te.summarizeSession(e,t,n,r)}function jq(){let{isSettingsDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isSessionSwitcherOpen:r,isAboutDialogOpen:i,activeMainTab:a}=K.getState();if(e||t||n||r||i||!Qw(a))return!1;let o=$w();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=Ko.getState();if(s.getCurrentModelVariants().length===0)return!1;s.cycleCurrentVariant();let c=Ko.getState().currentVariant,l=wa.getState().currentSessionId,u=Ko.getState().currentAgentName,d=Ko.getState().currentProviderId,f=Ko.getState().currentModelId;return l&&u&&d&&f&&ur.getState().saveAgentModelVariantForSession(l,u,d,f,c),u&&d&&f&&Ko.getState().saveAgentModelSelection(u,d,f,c),!0}function Mq(e){return e instanceof HTMLTextAreaElement&&e.getAttribute(`data-chat-input`)===`true`}function Nq(e){console.warn(`[keyboard-shortcuts] failed to open draft mini chat window`,e)}var Pq=3,Fq=(e,t)=>{if(typeof e!=`string`)return t;let n=e.trim().replace(/\s+/g,` `);return n?n.slice(0,48):t},Iq=(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:Fq(e.title,`Session ${r.length+1}`)}),r.length>=Pq))break}return r},Lq=()=>{let e=(0,Q.c)(9),t=Uo(),n=wa(Rq),r;e[0]!==n||e[1]!==t?(r=Iq(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`||!y())){try{i.length===0?localStorage.removeItem(Dc):localStorage.setItem(Dc,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 Rq(e){return e.currentSessionId}var zq=e=>Number.isFinite(e)?`${Math.max(0,Math.round(e))}px`:`0px`,Bq=(e,t,n,r)=>{e.style.setProperty(`--yuri-wco-left-inset`,zq(t)),e.style.setProperty(`--yuri-wco-right-inset`,zq(n)),e.style.setProperty(`--yuri-wco-titlebar-height`,zq(r))},Vq=()=>{let e=(0,Q.c)(1),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],Z.useEffect(Hq,t)};function Hq(){if(typeof window>`u`||!y())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){Bq(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));Bq(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),Bq(e,0,0,0)}}var Uq=3e4,Wq=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,Gq=e=>e instanceof Zo?e.status===501?`unsupported`:e.status>=400&&e.status<500&&e.status!==408&&e.status!==429&&e.code!==`revision_conflict`?`permanent`:`retry`:`retry`,Kq=(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})}),qq=(e,t)=>e.then(e=>{if(t?.aborted)throw new DOMException(`Aborted`,`AbortError`);return e}),Jq={fetchSnapshot:e=>qq(ns(Cn),e),refreshSnapshot:e=>qq(ya(Cn),e),fetchOrder:yr,setOrder:Yo,waitInvalidation:Li,captureRuntime:()=>({transportIdentity:o(),generation:c()}),isCurrent:e=>e.transportIdentity===o()&&e.generation===c(),sleep:Kq,createRequestID:()=>typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`worktree-order-${Date.now()}-${Math.random().toString(36).slice(2)}`},Yq=new Map,Xq=()=>{for(let e of Yq.values())e.controller.abort();Yq.clear()},Zq=(e,t,n,r=Jq)=>{Yq.get(e)?.controller.abort();let i={projectDirectory:Wq(t),orderedPaths:[...n],capture:r.captureRuntime(),controller:new AbortController,backoffMs:500,running:!1};Yq.set(e,i),Qq(e,r)},Qq=async(e,t=Jq)=>{let n=Yq.get(e);if(!(!n||n.running)){n.running=!0;try{for(;;){let n=Yq.get(e);if(!n||!t.isCurrent(n.capture)||n.controller.signal.aborted)return;let r=sr.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)||Yq.get(e)!==n)return;let a=i.worktreeOrder??{projectDirectory:n.projectDirectory,orderedPaths:n.orderedPaths,revision:i.revision};sr.getState().setServerRevision(e,a.revision),sr.getState().resolvePendingWorktreeOrder(e,a.revision),Yq.delete(e);return}catch(r){if(n.controller.signal.aborted||!t.isCurrent(n.capture)||Yq.get(e)!==n)return;if(r instanceof Zo&&r.code===`revision_conflict`)try{let r=await t.fetchOrder(n.projectDirectory,n.controller.signal);if(Yq.get(e)!==n||!t.isCurrent(n.capture))return;sr.getState().applyServerWorktreeOrder(e,r.orderedPaths,r.revision),n.expectedRevision=void 0,n.requestID=void 0,n.backoffMs=500;continue}catch(e){if(Gq(e)!==`retry`)return}else if(Gq(r)!==`retry`)return;if(await t.sleep(n.backoffMs,n.controller.signal).catch(()=>{}),n.backoffMs=Math.min(n.backoffMs*2,Uq),n.controller.signal.aborted)return}}}finally{Yq.get(e)===n&&(!t.isCurrent(n.capture)||n.controller.signal.aborted)&&Yq.delete(e),Yq.get(e)===n&&(n.running=!1)}}},$q=(e,t,n,r)=>{let i=new Map(t.map(e=>[Wq(e.path),e.id]));for(let t of e){let e=i.get(Wq(t.projectDirectory));e&&r.isCurrent(n)&&sr.getState().applyServerWorktreeOrder(e,t.orderedPaths,t.revision)}},eJ=(e,t=Jq)=>{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();$q(r.worktreeOrders,o,a,t);let s=new Set(r.worktreeOrders.map(e=>Wq(e.projectDirectory)));for(let e of o){let n=sr.getState(),r=n.orderByProject[e.id];n.pendingProjectIDs[e.id]?Zq(e.id,e.path,r??[],t):r?.length&&!s.has(Wq(e.path))&&(n.markPendingWorktreeOrder(e.id),Zq(e.id,e.path,r,t))}break}catch(e){if(Gq(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,Uq)}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,$q(s.worktreeOrders,e(),a,t),r=500}catch(e){if(Gq(e)!==`retry`)return;await t.sleep(r,i).catch(()=>{}),r=Math.min(r*2,Uq)}})()},stop:r}},tJ=()=>{let e=(0,Q.c)(2),t=Ia(rJ),n;e[0]===t?n=e[1]:(n=[t],e[0]=t,e[1]=n),Z.useEffect(oJ,n)};function nJ(e){return[e.id,Wq(e.path)]}function rJ(e){return JSON.stringify(e.projects.map(nJ))}function iJ(e,t,n){return Zq(e,t,n)}function aJ(){return Ia.getState().projects}function oJ(){let e=o();sr.getState().activateWorktreeOrderRuntime(e);let t=Ti(iJ),n=eJ(aJ);n.start();let r=i(e=>{l(e)&&(Xq(),sr.getState().activateWorktreeOrderRuntime(o()),n.start())});return()=>{t(),r(),n.stop(),Xq()}}var sJ=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`,cJ=e=>{let t=!1,n=0,r=0,i=0,a=!1,o=new Set,s=new Map,c=new Map,l=new Set,u=new Set,d=new Map,f=new Set,p=new Set,m=new Set,h=``,g=[],_=t=>{let n=sJ(t);return e.getProjects().find(e=>sJ(e.path)===n)},v=(n,i=150,a=!1)=>{let l=sJ(n.path);if(a&&(o.has(l)||s.has(l)||c.has(l)))return;let u=c.get(l);u&&e.clearTimer(u.timer);let d=r,f=e.setTimer(()=>{!t||d!==r||(c.delete(l),s.set(l,n),y(d))},i);c.set(l,{timer:f,epoch:d})},y=(n=r)=>{if(!(!t||n!==r))for(;i<2&&s.size>0;){let n=[...s.entries()].find(([e])=>!o.has(e));if(!n)break;let[a,c]=n;s.delete(a),i+=1,o.add(a);let l=e.generation(),u=r;e.refresh(c,{isCurrent:()=>t&&u===r&&l===e.generation()}).then(n=>{if(!(!t||u!==r||l!==e.generation())){m.add(a);for(let t of n.addedDirectories){let n=sJ(t);(!e.needsSessionSync||e.needsSessionSync(n))&&f.add(n)}if(e.needsSessionSync)for(let t of n.worktrees){let n=sJ(t.path);e.needsSessionSync(n)&&f.add(n)}b(u,l),x()}}).then(()=>{t&&u===r&&l===e.generation()&&d.delete(a)}).catch(()=>{if(!t||u!==r||l!==e.generation())return;let n=(d.get(a)??0)+1;d.set(a,n),t&&u===r&&v(c,[1e3,2e3,5e3,15e3,3e4][Math.min(n-1,4)])}).finally(()=>{u===r&&(--i,o.delete(a),y(u))})}},b=(n,i)=>{if(f.size===0)return;let a=[...f];f.clear(),e.syncAdded(a).catch(()=>{if(t&&n===r&&i===e.generation()){for(let e of a)f.add(e);let o=e.setTimer(()=>{l.delete(o),t&&n===r&&b(n,i)},1e3);l.add(o)}})},x=()=>{if(m.size!==e.getProjects().length)return;let t=e.getCatalog();for(let e of p){let n=e.slice(e.indexOf(`:`)+1);[...t.entries()].some(([e,t])=>sJ(e)===n||t.some(e=>sJ(e.path)===n))||u.add(e)}},S=()=>{m.clear();for(let t of e.getProjects())v(t,0,!0)},C=()=>{let t=e.getCatalog(),r=e.getProjects(),i=new Set;for(let t of e.getActiveDirectories())t.trim()&&i.add(sJ(t));for(let e of[...p]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||p.delete(e)}for(let e of[...u]){let t=e.slice(e.indexOf(`:`)+1);i.has(t)||u.delete(e)}for(let e of i)if(!r.find(n=>{let r=sJ(n.path),i=t.get(r)?.some(t=>sJ(t.path)===e);return e===r||i})){let t=`${n}:${e}`;!u.has(t)&&!p.has(t)&&(p.add(t),S())}},w=()=>{r+=1,u.clear(),p.clear(),d.clear(),f.clear(),m.clear();for(let t of c.values())e.clearTimer(t.timer);c.clear();for(let t of l)e.clearTimer(t);l.clear(),s.clear(),o.clear(),i=0};return{start:()=>{t||e.isVSCode()||(t=!0,a=!1,g.push(e.subscribeEvents(e=>{if(e.type===`event-stream-ready`){if(!a){a=!0,S();return}n+=1,w(),S()}if(e.type===`worktree-topology-changed`&&e.projectDirectory){let t=_(e.projectDirectory);t&&v(t)}})),h=e.getProjects().map(e=>`${e.id}\u0000${sJ(e.path)}`).sort().join(`
|
|
6603
6603
|
`),g.push(e.subscribeProjects(()=>{let t=e.getProjects().map(e=>`${e.id}\u0000${sJ(e.path)}`).sort().join(`
|
|
6604
|
-
`);t!==h&&(h=t,w(),S(),C())})),g.push(e.subscribeCatalog(C)),g.push(e.subscribeSessions(C)),g.push(e.subscribeRuntime(e=>{e&&(a=!1,n+=1,w(),S())})),S(),C())},stop:()=>{t=!1,w();for(let{timer:t}of c.values())e.clearTimer(t);for(c.clear(),s.clear(),i=0;g.length;)g.pop()?.()},reconcileAll:S}},lJ=null,uJ=0,dJ=()=>(lJ||=cJ({isVSCode:
|
|
6604
|
+
`);t!==h&&(h=t,w(),S(),C())})),g.push(e.subscribeCatalog(C)),g.push(e.subscribeSessions(C)),g.push(e.subscribeRuntime(e=>{e&&(a=!1,n+=1,w(),S())})),S(),C())},stop:()=>{t=!1,w();for(let{timer:t}of c.values())e.clearTimer(t);for(c.clear(),s.clear(),i=0;g.length;)g.pop()?.()},reconcileAll:S}},lJ=null,uJ=0,dJ=()=>(lJ||=cJ({isVSCode:p,getProjects:()=>Ia.getState().projects,getCatalog:()=>wa.getState().availableWorktreesByProject,getActiveDirectories:()=>{let e=xi.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=xi.getState(),n=sJ(e);return!t.loadedDirectories.has(n)&&!t.loadingDirectories.has(n)&&!t.refreshingDirectories.has(n)},refresh:Vs,syncAdded:e=>fi(e,xi.getState().activeSessions),subscribeProjects:e=>Ia.subscribe(e),subscribeCatalog:e=>wa.subscribe((t,n)=>{t.availableWorktreesByProject!==n.availableWorktreesByProject&&e()}),subscribeSessions:e=>xi.subscribe((t,n)=>{(t.activeSessions!==n.activeSessions||t.cachedDirectories!==n.cachedDirectories)&&e()}),subscribeEvents:Jo,subscribeRuntime:e=>i(t=>e(l(t))),generation:c,setTimer:(e,t)=>globalThis.setTimeout(e,t),clearTimer:e=>globalThis.clearTimeout(e)}),uJ+=1,lJ.start(),()=>{uJ=Math.max(0,uJ-1),uJ===0&&lJ?.stop()});function fJ(){if(S()?.runtime.isVSCode)return()=>{};let e=new vn(Cn,Pc()),t=Jo(e=>{(e.type===`speech-settings-changed`||e.type===`event-stream-ready`)&&Cn.invalidateQueries({queryKey:Pc().queryKey,exact:!0})}),n=t=>{if(!t.data||e.options.queryKey[0]!==o())return;let n=Ko.getState();Object.entries(t.data).some(([e,t])=>n[e]!==t)&&Ko.setState(t.data)},r=e.subscribe(n);n(e.getCurrentResult());let a=i(()=>{Ko.setState(es),e.setOptions(Pc()),n(e.getCurrentResult())});return()=>{a(),r(),t(),e.destroy()}}var pJ=`yuri:mini-chat-presence`,mJ=()=>{let e=dh(),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(()=>{ao(e=>t.current(e),e=>n.current(e),e=>r.current(e))},[]),Z.useEffect(()=>dJ(),[]),null},hJ=()=>{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(yJ,t),null},gJ=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(fJ,r);let i=Z.useSyncExternalStore(Hi,pr,pr);Ri(n&&i===`legacy-enabled`),ti();let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=[],t[1]=a):a=t[1],Z.useEffect(bJ,a);let o;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(mJ,{}),t[2]=o):o=t[2],o}),_J=Z.memo(function(e){let t=(0,Q.c)(6),{embeddedBackgroundWorkEnabled:n}=e;Lq(),Vq(),QK(),tJ();let r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0],Z.useEffect(xJ,r);let i;t[1]===n?i=t[2]:(i=(0,$.jsx)(gJ,{embeddedBackgroundWorkEnabled:n}),t[1]=n,t[2]=i);let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(hJ,{}),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 vJ(e){let t=e.data;if(t?.type!==`mini-chat-session-presence`||!t.sessionId||!t.directory)return;let n=t.viewed!==!1;Mi(t.directory,t.sessionId,n),n&&So(t.sessionId)}function yJ(){if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(pJ);return e.onmessage=vJ,()=>e.close()}function bJ(){let e=Ua(),t=Oi();e.start(),t.start();let n=la(e);return()=>{n(),t.stop(),e.stop()}}function xJ(){NK()}var SJ=new Set,CJ=new Map,wJ=(e,t)=>`https://cdn.jsdelivr.net/npm/${encodeURIComponent(e.packageName).replace(`%40`,`@`).replace(`%2F`,`/`)}/files/${e.filePrefix}-latin-${t}-normal.woff2`,TJ=(e,t)=>{let n=`${e.family}:${t}`;if(SJ.has(n))return Promise.resolve();let r=CJ.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(${wJ(e,t)}) format('woff2')`,{style:`normal`,weight:String(t),display:`swap`});document.fonts.add(i);let a=i.load().then(()=>{SJ.add(n)}).catch(n=>{document.fonts.delete(i),console.warn(`Failed to load font: ${e.family} ${t}`,n)}).finally(()=>{CJ.delete(n)});return CJ.set(n,a),a},EJ=e=>e?Promise.all(e.weights.map(t=>TJ(e,t))).then(()=>void 0):Promise.resolve(),DJ=e=>EJ(yt[e]?.source),OJ=e=>EJ(vt[e]?.source),kJ={family:`Syne`,packageName:`@fontsource/syne`,filePrefix:`syne`,weights:[700]},AJ=()=>EJ(kJ);function jJ(){let e=(0,Q.c)(4),{uiFont:t,monoFont:n}=df(),r,i;e[0]!==n||e[1]!==t?(r=()=>{if(typeof document>`u`)return;let e=document.documentElement,r=yt[t]?.stack??yt.system.stack,i=vt[n]?.stack??vt[`system-mono`].stack;DJ(t),OJ(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{VS as $,SH as A,Gp as At,IN as B,KG as C,Nm as Ct,dU as D,am as Dt,DW as E,om as Et,FP as F,vf as Ft,ZD as G,ik as H,RP as I,hf as It,gw as J,Ow as K,fP as L,_f as Lt,ZR as M,bp as Mt,BI as N,pp as Nt,cU as O,tm as Ot,IP as P,Vf as Pt,dw as Q,LN as R,pf as Rt,XG as S,dh as St,cG as T,fm as Tt,qO as U,XO as V,SO as W,_w as X,hw as Y,fw as Z,cK as _,ey as _t,gJ as a,lS as at,QG as b,Nh as bt,VK as c,Mx as ct,PK as d,fx as dt,AS as et,FK as f,ox as ft,lK as g,$v as gt,uK as h,by as ht,_J as i,iS as it,hV as j,xp as jt,WH as k,qp as kt,HK as l,Nx as lt,hK as m,kb as mt,AJ as n,oS as nt,GK as o,aS as ot,wK as p,Eb as pt,vw as q,DJ as r,sS as rt,BK as s,Jx as st,jJ as t,rS as tt,IK as u,px as ut,dK as v,Kv as vt,HG as w,Em as wt,ZG as x,_h as xt,sK as y,ig as yt,RN as z};
|