@openchambery/web 1.19.0-beta.2 → 1.19.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/assets/{AssistantView-CeUftH6a.js → AssistantView-BSUBxkz8.js} +1 -1
  2. package/dist/assets/{ChatContainer-CE5B7ZoY.js → ChatContainer-CanA9Dye.js} +26 -26
  3. package/dist/assets/{ContextPanel-DjVgMdd_.js → ContextPanel-D-zm9idy.js} +3 -3
  4. package/dist/assets/{DiagramView-88VdZTFC.js → DiagramView-etLVThQw.js} +1 -1
  5. package/dist/assets/{MarkdownRendererImpl-CEt2m_LG.js → MarkdownRendererImpl-BgvKQ5fZ.js} +1 -1
  6. package/dist/assets/{MobileDetailNavigation-CHQkDyla.js → MobileDetailNavigation-BU_Ylck7.js} +1 -1
  7. package/dist/assets/{MobileShareBridge-MNVYAQpx.js → MobileShareBridge-UeR74BaG.js} +1 -1
  8. package/dist/assets/{MobileSurface-Cy5O2ftE.js → MobileSurface-BaJK1TC4.js} +1 -1
  9. package/dist/assets/{MultiRunWindow-CkLAQu2a.js → MultiRunWindow-KEhvo6JL.js} +1 -1
  10. package/dist/assets/{SettingsView-BJsctYMK.js → SettingsView-CC83BH32.js} +1 -1
  11. package/dist/assets/{SettingsWindow-Cnpe6LNU.js → SettingsWindow-DlEl2agU.js} +1 -1
  12. package/dist/assets/{TerminalView--pkloV1B.js → TerminalView-4ji7f8PT.js} +1 -1
  13. package/dist/assets/{ToolOutputDialog-UAKu6b6Z.js → ToolOutputDialog-B7vUFIz4.js} +1 -1
  14. package/dist/assets/{appThemeRegistry-rYIBRFtf.js → appThemeRegistry-BWAStv0M.js} +2 -2
  15. package/dist/assets/{gitApi-DFM6mFMX.js → gitApi-BtRkoe9k.js} +1 -1
  16. package/dist/assets/{insertionBoundaries-TTdO3GIW.js → insertionBoundaries-0QdvxqZx.js} +1 -1
  17. package/dist/assets/{main-C4oheRdM.js → main-C2gFG9wD.js} +3 -3
  18. package/dist/assets/{main-8ssH8Y4M.js → main-CKEPlKbO.js} +2 -2
  19. package/dist/assets/{miniChat-BqeOJlOz.js → miniChat-B275LhR6.js} +2 -2
  20. package/dist/assets/{mobile-DUjVfFN8.js → mobile-B4O-Iia5.js} +2 -2
  21. package/dist/assets/{multirun-BXVQPFEG.js → multirun-CzvmS64T.js} +1 -1
  22. package/dist/assets/{projectMeta-BhIldO_1.js → projectMeta-B4BZoe_0.js} +1 -1
  23. package/dist/assets/{radio-C9bw93S2.js → radio-BIFaTwYH.js} +1 -1
  24. package/dist/assets/{renderElectronMiniChatApp-B2ocXqU0.js → renderElectronMiniChatApp-DrHB3d6Y.js} +2 -2
  25. package/dist/assets/{renderMobileApp-t_yjiog8.js → renderMobileApp-BB6JMX4q.js} +5 -5
  26. package/dist/assets/{runtimeConfig-DYtQIAm-.js → runtimeConfig-BdMDmf4j.js} +1 -1
  27. package/dist/assets/{runtimeEndpointReset-ZrxbCvpe.js → runtimeEndpointReset-CqowcjzM.js} +1 -1
  28. package/dist/assets/{shikiHighlight-p0HAuVf6.js → shikiHighlight-Gt4pZGSV.js} +1 -1
  29. package/dist/assets/{src-BDOLh3pc.css → src-RGaBtbGz.css} +1 -1
  30. package/dist/assets/{useAppFontEffects-apga0HM5.js → useAppFontEffects-CbQSJicp.js} +2 -2
  31. package/dist/assets/{useDesktopWindowControlsLayout-CB7n5UfN.js → useDesktopWindowControlsLayout-BI_ZDdNF.js} +1 -1
  32. package/dist/assets/{useEffectiveDirectory-Dc_c8Epe.js → useEffectiveDirectory-DRp5lrMh.js} +1 -1
  33. package/dist/assets/{useMobileNavigationStore-FXDlG_jH.js → useMobileNavigationStore-CGSKnVbj.js} +1 -1
  34. package/dist/assets/{useSessionAutoCleanup-CJ7ugpXZ.js → useSessionAutoCleanup-C0sPQc3j.js} +1 -1
  35. package/dist/assets/{useWorkerHighlightedLines-CVxu41TS.js → useWorkerHighlightedLines-BSyHhMx_.js} +1 -1
  36. package/dist/index.html +3 -3
  37. package/dist/mini-chat.html +3 -3
  38. package/dist/mobile.html +3 -3
  39. package/package.json +1 -1
@@ -1,11 +1,11 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-UAKu6b6Z.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-DzwCfRqr.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-6sclr7B6.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-DWuULPzo.js","assets/store-DQY8Fkb0.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/utils-B1EK5zKa.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-DpjYnXxn.js","assets/dialog-DPS0W9eS.js","assets/button-C7OXr4ae.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-B89dbj3N.js","assets/vendor-pierre-diffs-BenIz2TM.js","assets/vendor-hast-util-to-html-B0p1k5Xa.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-DpDied8H.js","assets/appThemeRegistry-rYIBRFtf.js","assets/platform-CbeLpKPk.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/markdown-worker-W06-MhF5.js","assets/useEffectiveDirectory-Dc_c8Epe.js","assets/useMobileNavigationStore-FXDlG_jH.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-BHsHXCKE.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/useWorkerHighlightedLines-CVxu41TS.js","assets/tooltip-D_orJMYd.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T as i,U as a,g as o,t as s,w as c,y as l}from"./useUIStore-DzwCfRqr.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as ee,ot as te,pt as W,q as G,r as ne,st as re,u as ie,ut as ae,v as oe,wt as se,x as ce,y as le,yt as ue,z as de}from"./persistence-6sclr7B6.js";import{a as fe,i as pe,r as me,t as he}from"./vendor-zustand-B4dlGEM2.js";import{c as ge,d as _e,f as ve,l as ye,nt as be,rt as xe,tt as Se,u as Ce}from"./vendor-base-ui-CnHfUmDN.js";import{At as we,Bt as Te,Ct as Ee,Gt as De,Ht as Oe,Jt as ke,Nt as Ae,Pt as je,Rt as Me,St as Ne,Ut as Pe,Wt as Fe,jt as Ie,kt as Le,n as Re,qt as ze,t as Be,zt as Ve}from"./platform-CbeLpKPk.js";import{a as He,n as Ue,o as We}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as Ge}from"./vendor-react-DLPElpoQ.js";import{i as Ke,n as qe,s as Je,t as Ye}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Xe,R as Ze,V as Qe,c as $e}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as et,d as tt,i as nt,l as rt,n as K,o as it,r as at,u as ot}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as st,r as ct,t as lt}from"./clipboard-DWuULPzo.js";import{i as ut,t as dt}from"./store-DQY8Fkb0.js";import{$ as ft,$a as pt,$t as mt,A as ht,Aa as gt,Ai as _t,At as vt,Bi as yt,Br as bt,Ci as xt,Cn as St,D as Ct,Di as wt,Dn as Tt,Dr as Et,Dt,E as Ot,Ea as kt,Ei as At,En as jt,Eo as Mt,Er as Nt,Et as Pt,F as Ft,Fa as It,Fo as Lt,Fr as Rt,Ft as zt,G as Bt,Ga as Vt,Gi as Ht,Gr as Ut,Gt as Wt,H as Gt,Hi as Kt,Hr as qt,Ht as Jt,I as Yt,Ii as Xt,Ir as Zt,It as Qt,J as $t,Ja as en,Ji as tn,Jr as nn,Jt as rn,K as an,Ka as on,Ki as sn,Kr as cn,La as ln,Li as un,Ln as dn,M as fn,Mi as pn,Mr as mn,N as hn,Na as gn,Ni as _n,Nr as vn,O as yn,Oa as bn,Oi as q,Or as xn,Ot as Sn,P as Cn,Pa as wn,Pr as Tn,Pt as En,Q as Dn,Qa as On,Qi as kn,R as An,Ri as jn,Rn as Mn,Ro as Nn,Rr as Pn,S as Fn,Sa as In,St as Ln,T as Rn,Ta as zn,Ti as Bn,Tn as Vn,To as Hn,Ui as Un,Ur as Wn,Ut as Gn,Va as Kn,Vi as qn,Vt as Jn,W as Yn,Wi as Xn,Wn as Zn,Wr as Qn,Wt as $n,X as er,Xa as tr,Xt as nr,Y as rr,Ya as ir,Yr as ar,Yt as or,Z as sr,Za as cr,Zr as lr,Zt as ur,_a as dr,_i as fr,_r as pr,a as mr,aa as hr,ai as gr,an as _r,ao as vr,ar as yr,at as br,ba as xr,bi as Sr,bn as Cr,br as wr,ci as Tr,cn as Er,dn as Dr,dt as Or,en as kr,eo as Ar,et as jr,f as Mr,fi as Nr,fn as Pr,ft as Fr,g as Ir,ga as Lr,gt as Rr,hi as zr,hn as Br,ht as Vr,i as Hr,ii as Ur,ir as Wr,it as Gr,j as Kr,ji as qr,jt as Jr,k as Yr,ki as Xr,kr as Zr,kt as Qr,l as J,li as $r,ln as ei,lo as ti,lt as ni,m as ri,ma as ii,mi as ai,mn as oi,mt as si,n as ci,na as li,ni as ui,nn as di,nr as fi,nt as pi,oa as mi,oi as hi,on as gi,oo as _i,ot as vi,pi as yi,pn as bi,pt as xi,q as Si,qa as Ci,qi as wi,ra as Ti,ri as Ei,rn as Di,rr as Oi,rt as ki,sa as Ai,sn as ji,tn as Mi,tt as Ni,ua as Pi,un as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wa as Bi,wi as Vi,wn as Hi,x as Ui,xa as Wi,xi as Gi,xn as Ki,xt as qi,ya as Ji,yi as Yi,z as Xi,zi as Zi,zn as Qi}from"./useMobileNavigationStore-FXDlG_jH.js";import{n as $i,t as ea}from"./AgentAvatar-DDcjamcJ.js";import{n as ta,t as Y}from"./utils-B1EK5zKa.js";import{n as X}from"./Icon-DpjYnXxn.js";import{a as na,i as ra,n as ia,o as aa,r as oa,s as sa,t as ca}from"./dialog-DPS0W9eS.js";import{t as la}from"./button-C7OXr4ae.js";import{E as ua,n as da}from"./gitApi-DFM6mFMX.js";import{A as fa,C as pa,M as ma,N as ha,O as ga,S as _a,T as va,a as ya,b as ba,d as xa,g as Sa,h as Ca,i as wa,j as Ta,k as Ea,n as Da,o as Oa,p as ka,s as Aa,u as ja,v as Ma,w as Na,x as Pa}from"./projectMeta-BhIldO_1.js";import{t as Fa}from"./input-BzYA603C.js";import{i as Ia,n as La,t as Ra}from"./tooltip-D_orJMYd.js";import{n as za,t as Ba}from"./useThemeSystem-DMzWVJaW.js";import{B as Va,C as Ha,D as Ua,H as Wa,N as Ga,O as Ka,P as qa,S as Ja,W as Ya,X as Xa,Z as Za,_ as Qa,a as $a,f as eo,g as to,h as no,i as ro,it as io,k as ao,m as oo,o as so,p as co,r as lo,t as uo}from"./radio-C9bw93S2.js";import{i as fo,t as po}from"./OverlayScrollbar-Ch3J6ASR.js";import{_ as mo,a as ho,d as go,f as _o,g as vo,h as yo,i as bo,l as xo,m as So,n as Co,u as wo,v as To,x as Eo}from"./markdownTheme-B89dbj3N.js";import{n as Do,r as Oo,t as ko}from"./useRuntimeAPIs-DSLXJybW.js";import{a as Ao,c as jo,i as Mo,r as No,t as Po,u as Fo}from"./appThemeRegistry-rYIBRFtf.js";import{_ as Io,a as Lo,c as Ro,g as zo,l as Bo,o as Vo,t as Ho,v as Uo,y as Wo}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Go,n as Ko,o as qo,s as Jo,t as Yo}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as Xo,n as Zo,t as Qo}from"./url-BsaBG5-1.js";import{_ as $o,l as es,m as ts,p as ns,s as rs}from"./markdown-worker-W06-MhF5.js";import{n as is}from"./useEffectiveDirectory-Dc_c8Epe.js";import{a as as,c as os,d as ss,f as cs,i as ls,l as us,n as ds,r as fs,s as ps,t as ms}from"./FadeInOnReveal-By2F9vcI.js";import{A as hs,C as gs,D as _s,E as vs,M as ys,O as bs,S as xs,T as Ss,a as Cs,b as ws,c as Ts,f as Es,i as Ds,j as Os,k as ks,l as As,m as js,n as Ms,o as Ns,p as Ps,r as Fs,s as Is,t as Ls,u as Rs,w as zs,x as Bs}from"./insertionBoundaries-TTdO3GIW.js";import{A as Vs,C as Hs,D as Us,E as Ws,M as Gs,O as Ks,S as qs,T as Js,a as Ys,b as Xs,c as Zs,g as Qs,h as $s,i as ec,j as tc,k as nc,o as rc,p as ic,r as ac,s as oc,t as sc,v as cc,w as lc,x as uc,y as dc}from"./useWorkerHighlightedLines-CVxu41TS.js";import{t as fc}from"./vendor-cmdk-CeAGfrLo.js";import{t as pc}from"./sortable-tabs-strip-nLsPC06f.js";import{n as mc,t as hc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as gc,u as _c}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as vc,t as yc}from"./vendor-framer-motion-DFy_BSVd.js";import{t as bc}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(xe(),1),Q=Ge(),$=be(),xc=e(Se(),1),Sc=`openchamber:close-embedded-session-chat`,Cc=`openchamber:embedded-visibility`,wc=`openchamber:embedded-visibility-request`,Tc=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,Ec=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),Dc=(e,t,n,r)=>{if(typeof window>`u`)return``;let i=new URL(window.location.pathname,window.location.origin);return i.searchParams.set(`ocPanel`,`session-chat`),i.searchParams.set(`surface`,`desktop`),i.searchParams.set(`sessionId`,e),n?i.searchParams.set(`readOnly`,`1`):i.searchParams.delete(`readOnly`),t&&t.trim().length>0?i.searchParams.set(`directory`,t):i.searchParams.delete(`directory`),i.searchParams.set(`themeMode`,r.mode),i.searchParams.set(`lightThemeId`,r.lightThemeId),i.searchParams.set(`darkThemeId`,r.darkThemeId),i.searchParams.set(`themeVariant`,r.currentTheme.metadata.variant===`dark`?`dark`:`light`),i.searchParams.set(`currentTheme`,JSON.stringify(r.currentTheme)),i.hash=``,i.toString()},Oc=(e,t,n,r,i,a)=>{let o=Ec(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=Dc(n,r,i,a);return e.set(t,{signature:o,src:c}),c},kc=null,Ac=()=>{if(kc!==null)return kc;if(typeof window>`u`)return kc=!1,!1;try{return kc=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,kc}catch{return kc=!1,!1}},jc=()=>{if(!Ac())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},Mc=He(`OpenChamberMedia`);function Nc(){return Re()&&Ue.getPlatform()===`android`&&Ue.isPluginAvailable(`OpenChamberMedia`)}async function Pc(e){if(!Nc())return null;let t=await Mc.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(Ue.convertFileSrc(e.path));if(!t.ok)throw Error(`Native media fetch failed (${t.status})`);let r=await t.blob();n.push(new File([r],e.name,{type:e.mimeType}))}return n}var Fc=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Ic=1e4,Lc=15e3,Rc=3e4,zc=3e4,Bc=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;get isConnected(){return this.socket?.readyState===WebSocket.OPEN}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(!this.isConnected){if(this.connectPromise){await this.connectPromise;return}try{await a()}catch{}this.connectPromise=new Promise((e,t)=>{let n=!1,i;try{let e=r().websocket(`/api/dictation/ws`);i=Ne(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!n){n=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},Ic);i.onopen=()=>{},i.onmessage=t=>{let r;try{r=JSON.parse(String(t.data))}catch{return}if(!n&&r.type===`ready`){n=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(r)},i.onerror=()=>{window.setTimeout(()=>{n||(n=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!n){n=!0,clearTimeout(a),this.connectPromise=null;let r=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${r}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t,n){return await this.ensureConnected(),this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((r,i)=>{let a=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation start timed out`))},Lc);this.pendingStarts.set(e,{resolve:()=>{clearTimeout(a),r()},reject:e=>{clearTimeout(a),this.releaseDictation(),i(e)},timeout:a}),this.send({type:`start`,dictationId:e,format:t,options:n})||(clearTimeout(a),this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation connection lost`)))})}sendDictationStreamChunk(e,t,n){return this.send({type:`chunk`,dictationId:e,seq:t,audio:n})}finishDictationStream(e,t){return new Promise((n,r)=>{let i={resolve:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),n(e)},reject:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),r(e)},timeout:null};i.timeout=setTimeout(()=>{this.pendingFinishes.delete(e),this.releaseDictation(),r(Error(`Timed out waiting for transcription`))},zc),this.pendingFinishes.set(e,i),this.send({type:`finish`,dictationId:e,finalSeq:t})||(this.pendingFinishes.delete(e),i.reject(Error(`Dictation connection lost`)))})}cancelDictationStream(e){this.send({type:`cancel`,dictationId:e});let t=this.pendingStarts.get(e);t&&(this.pendingStarts.delete(e),t.reject(Error(`Dictation cancelled`)));let n=this.pendingFinishes.get(e);n&&(this.pendingFinishes.delete(e),n.reject(Error(`Dictation cancelled`))),this.releaseDictation(),this.scheduleIdleCloseIfReady()}handleMessage(e){let t=e.dictationId;if(t)switch(e.type){case`ack`:{let e=this.pendingStarts.get(t);e&&(this.pendingStarts.delete(t),e.resolve());return}case`partial`:for(let n of this.partialListeners)n(t,e.text??``);return;case`finish_accepted`:{let n=this.pendingFinishes.get(t);n&&typeof e.timeoutMs==`number`&&(n.timeout&&clearTimeout(n.timeout),n.timeout=setTimeout(()=>{this.pendingFinishes.delete(t),n.reject(Error(`Timed out waiting for transcription`))},e.timeoutMs+5e3));return}case`final`:{let n=this.pendingFinishes.get(t);n&&(this.pendingFinishes.delete(t),n.resolve({text:e.text??``})),this.scheduleIdleCloseIfReady();return}case`error`:{let n=Fc(e.error||`Dictation failed`,e.retryable!==!1,e.reasonCode),r=this.pendingStarts.get(t);r&&(this.pendingStarts.delete(t),r.reject(n));let i=this.pendingFinishes.get(t);i&&(this.pendingFinishes.delete(t),i.reject(n)),this.scheduleIdleCloseIfReady();return}}}send(e){if(!this.isConnected||!this.socket)return!1;try{return this.socket.send(JSON.stringify(e)),!0}catch{return!1}}notifyConnection(e){for(let t of this.connectionListeners)t(e)}rejectAllPending(e){for(let[t,n]of this.pendingStarts)this.pendingStarts.delete(t),n.reject(e);for(let[t,n]of this.pendingFinishes)this.pendingFinishes.delete(t),n.reject(e);this.activeDictations=0}releaseDictation(){this.activeDictations=Math.max(0,this.activeDictations-1),this.scheduleIdleCloseIfReady()}scheduleIdleCloseIfReady(){this.activeDictations>0||this.pendingFinishes.size>0||this.pendingStarts.size>0||(this.clearIdleCloseTimer(),this.idleCloseTimer=setTimeout(()=>{if(this.activeDictations===0&&this.pendingFinishes.size===0&&this.pendingStarts.size===0){let e=this.socket;if(this.socket=null,e){try{e.close(1e3,`idle`)}catch{}this.notifyConnection(!1)}}},Rc))}cancelAllForRuntimeSwitch(){this.clearIdleCloseTimer();let e=this.socket;if(this.socket=null,this.connectPromise=null,this.rejectAllPending(Error(`Runtime changed`)),e){try{e.close(1e3,`runtime switch`)}catch{}this.notifyConnection(!1)}}clearIdleCloseTimer(){this.idleCloseTimer&&=(clearTimeout(this.idleCloseTimer),null)}};typeof window<`u`&&window.addEventListener(`openchamber:runtime-endpoint-changed`,()=>{Bc.cancelAllForRuntimeSwitch()});var Vc=128,Hc=`audio/pcm;rate=16000;bits=16`,Uc=()=>new Promise(e=>setTimeout(e,0)),Wc=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Gc=class{client;format;createDictationId;getStartOptions;dictationId=null;sendSeq=0;segments=[];streamReady=!1;flushTimer=null;drainWaiters=[];startGeneration=0;startPromise=null;constructor(e){this.client=e.client,this.format=e.format??Hc,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Wc}getDictationId(){return this.dictationId}getFinalSeq(){return this.segments.length-1}hasSegments(){return this.segments.length>0}clearAll(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.segments=[],this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}resetStreamForReplay(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}enqueueSegment(e){if(this.segments.push(e),this.client.isConnected){if(!this.dictationId){this.startPromise||this.restartStream().catch(()=>{});return}this.flush()}}flush(){let e=this.dictationId;if(!this.client.isConnected||!e||!this.streamReady)return 0;let t=0;for(;this.sendSeq<this.segments.length&&t<Vc;){let n=this.sendSeq,r=this.segments[n];if(!this.client.sendDictationStreamChunk(e,n,r))break;this.sendSeq=n+1,t+=1}return this.hasPendingSegments()?this.scheduleFlush():this.resolveDrainWaiters(),t}async restartStream(){this.startGeneration+=1;let e=this.startGeneration,t=this.createDictationId();this.dictationId=t,this.sendSeq=0,this.streamReady=!1;let n=(async()=>{await this.client.startDictationStream(t,this.format,this.getStartOptions()),this.startGeneration===e&&this.dictationId===t&&(this.streamReady=!0,this.flush())})().catch(n=>{throw this.startGeneration===e&&this.dictationId===t&&(this.dictationId=null,this.streamReady=!1),n}).finally(()=>{this.startPromise===n&&(this.startPromise=null)});this.startPromise=n,await n}async finish(e){this.dictationId||await this.restartStream(),this.startPromise&&await this.startPromise;let t=this.dictationId;if(!t||!this.streamReady)throw Error(`Failed to start dictation stream`);return this.flush(),await this.waitForFlushDrain(),{dictationId:t,text:(await this.client.finishDictationStream(t,e)).text}}cancel(){let e=this.dictationId;this.client.isConnected&&e&&this.client.cancelDictationStream(e),this.resetStreamForReplay()}hasPendingSegments(){return this.sendSeq<this.segments.length}scheduleFlush(){this.flushTimer||=setTimeout(()=>{this.flushTimer=null,this.flush()},0)}clearScheduledFlush(){this.flushTimer&&=(clearTimeout(this.flushTimer),null)}async waitForFlushDrain(){for(;this.hasPendingSegments();){if(!this.client.isConnected||!this.dictationId||!this.streamReady)throw Error(`Failed to flush dictation stream`);await new Promise(e=>{this.drainWaiters.push(e)}),await Uc()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Kc=16e3,qc=Kc,Jc=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Yc=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Xc=(e,t,n)=>{if(e.length===0)return new Int16Array;if(t===n){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=Yc(e[n]);return t}let r=t/n,i=Math.max(1,Math.round(e.length/r)),a=new Int16Array(i);for(let t=0;t<i;t++){let n=t*r,i=Math.floor(n),o=Math.min(e.length-1,i+1),s=n-i;a[t]=Yc(e[i]*(1-s)+e[o]*s)}return a},Zc=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},Qc=e=>{let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)},$c=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),el=e=>{if(e)try{e.disconnect()}catch{}},tl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Jc()!==null;function nl(e){let t=(0,Q.c)(12),[n,r]=(0,Z.useState)(0),i=(0,Z.useRef)(e.onPcmSegment),a=(0,Z.useRef)(e.onError),o,s;t[0]!==e.onError||t[1]!==e.onPcmSegment?(o=()=>{i.current=e.onPcmSegment,a.current=e.onError},s=[e.onPcmSegment,e.onError],t[0]=e.onError,t[1]=e.onPcmSegment,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,Z.useEffect)(o,s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=$c(),t[4]=c):c=t[4];let l=(0,Z.useRef)(c),u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=async()=>{if(l.current.started)return;if(typeof navigator>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(`Microphone capture is not supported in this environment`);let e=Jc();if(!e)throw Error(`AudioContext unavailable`);let t=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0}}),n=new e;try{n.state===`suspended`&&await n.resume().catch(al);let e=n.createMediaStreamSource(t),a=n.createScriptProcessor(4096,1,1),o=n.createGain();o.gain.value=0,l.current={stream:t,context:n,source:e,processor:a,gain:o,pending:new Int16Array,started:!0},a.onaudioprocess=e=>{let t=l.current;if(!t.started)return;let a=e.inputBuffer.getChannelData(0),o=0;for(let e=0;e<a.length;e++)o+=a[e]*a[e];let s=Math.sqrt(o/Math.max(1,a.length));r(Math.min(1,Math.max(0,s*2)));let c=Xc(a,n.sampleRate,Kc);for(t.pending=Zc(t.pending,c);t.pending.length>=qc;){let e=t.pending.slice(0,qc);t.pending=t.pending.slice(qc),i.current(Qc(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(il);try{await n.close()}catch{}throw l.current=$c(),r instanceof Error?r:Error(String(r))}},t[5]=u):u=t[5];let d=u,f;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=async()=>{let e=l.current;if(e.started=!1,r(0),e.processor)try{e.processor.onaudioprocess=null}catch{}el(e.processor),el(e.source),el(e.gain),e.stream&&e.stream.getTracks().forEach(rl);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Qc(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=$c())},t[6]=f):f=t[6];let p=f,m,h;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>()=>{p().catch(e=>{a.current?.(e instanceof Error?e:Error(String(e)))})},h=[p],t[7]=m,t[8]=h):(m=t[7],h=t[8]),(0,Z.useEffect)(m,h);let g;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=async()=>{try{await d()}catch(e){let t=e,n=t instanceof Error?t:Error(String(t));throw a.current?.(n),n}},t[9]=g):g=t[9];let _;return t[10]===n?_=t[11]:(_={start:g,stop:p,volume:n},t[10]=n,t[11]=_),_}function rl(e){try{e.stop()}catch{}}function il(e){try{e.stop()}catch{}}function al(){}var ol=1e3,sl=e=>e instanceof Error?e:Error(String(e)),cl=()=>{let e=mi.getState(),t=e.sttLanguage?.trim();return e.sttProvider===`openai-compatible`?{provider:`openai-compatible`,...t?{language:t}:{},openaiCompatible:{baseUrl:e.sttServerUrl,model:e.sttModel,...e.sttApiKey?{apiKey:e.sttApiKey}:{}}}:{provider:`local`,...t?{language:t}:{},localModel:e.sttLocalModel}};function ll(e={}){let{onTranscript:t,onError:n,canStart:r}=e,[i,a]=(0,Z.useState)(`idle`),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(0),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),m=(0,Z.useRef)(i);(0,Z.useEffect)(()=>{m.current=i},[i]);let h=(0,Z.useRef)(``),g=(0,Z.useRef)(null),_=(0,Z.useRef)({starting:!1,confirming:!1,cancelling:!1}),v=(0,Z.useRef)(t),y=(0,Z.useRef)(n);(0,Z.useEffect)(()=>{v.current=t,y.current=n},[t,n]);let b=(0,Z.useRef)(null);b.current||=new Gc({client:Bc,getStartOptions:cl});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},ol)},[]),C=(0,Z.useCallback)(e=>{let t=sl(e);d(t.message);let n=t.reasonCode;p(typeof n==`string`?n:null),y.current?.(t)},[]),w=(0,Z.useCallback)(()=>{d(null),p(null)},[]),T=(0,Z.useCallback)(()=>{b.current?.clearAll(),h.current=``,s(``)},[]);(0,Z.useEffect)(()=>Bc.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Bc.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=nl({onPcmSegment:e=>{b.current?.enqueueSegment(e)},onError:e=>{y.current?.(e)}}),D=(0,Z.useRef)(E.stop);(0,Z.useEffect)(()=>{D.current=E.stop},[E.stop]);let O=(0,Z.useCallback)(e=>{l(0),a(`idle`);let t=e.trim().length>0?e.trim():h.current.trim();return T(),t?(v.current?.(t),t):null},[T]),k=(0,Z.useCallback)(e=>{b.current?.hasSegments()?a(`failed`):a(`idle`),C(e)},[C]),A=(0,Z.useCallback)(async()=>{let e=_.current;if(!(e.starting||e.confirming||e.cancelling)&&m.current===`idle`&&!(r&&!r())){e.starting=!0,w(),s(``),l(0),a(`recording`),m.current=`recording`,T();try{await E.start(),S(),await b.current?.restartStream().catch(e=>{C(e)})}catch(e){await E.stop().catch(()=>void 0),x(),a(`idle`),m.current=`idle`,C(e)}finally{e.starting=!1}}},[E,r,w,T,C,S,x]),j=(0,Z.useCallback)(async()=>{let e=_.current;if(!e.cancelling&&(m.current===`recording`||m.current===`uploading`)){e.cancelling=!0,x(),l(0),w(),a(`idle`),m.current=`idle`;try{b.current?.cancel()}catch{}T();try{await E.stop()}catch{}finally{e.cancelling=!1}}},[E,w,T,x]),M=(0,Z.useCallback)(async()=>{let e=_.current;if(e.confirming||m.current!==`recording`)return null;e.confirming=!0,w(),x();try{await E.stop(),a(`uploading`),m.current=`uploading`;let e=b.current?.getFinalSeq()??-1;if(e<0)return O(``);let t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}finally{e.confirming=!1}},[E,w,k,O,x]),N=(0,Z.useCallback)(async()=>{if(m.current!==`failed`||!b.current?.hasSegments())return null;w(),a(`uploading`),m.current=`uploading`;try{b.current.resetStreamForReplay();let e=b.current.getFinalSeq(),t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}},[w,k,O]),P=(0,Z.useCallback)(()=>{if(m.current!==`failed`)return null;let e=h.current.trim();l(0),a(`idle`),m.current=`idle`,w();try{b.current?.cancel()}catch{}return T(),e?(v.current?.(e),e):null},[w,T]),F=(0,Z.useCallback)(()=>{l(0),a(`idle`),m.current=`idle`,w(),T()},[w,T]);return(0,Z.useEffect)(()=>{if(i!==`recording`||f!==`model_download_in_progress`)return;let e=setInterval(()=>{m.current!==`recording`||b.current?.getDictationId()||b.current?.restartStream().then(()=>{w()}).catch(e=>{C(e)})},3e3);return()=>clearInterval(e)},[i,f,w,C]),(0,Z.useEffect)(()=>()=>{x(),D.current().catch(()=>void 0),b.current?.cancel()},[x]),{status:i,isRecording:i===`recording`,isProcessing:i===`uploading`,partialTranscript:o,volume:E.volume,duration:c,error:u,errorReason:f,startDictation:A,confirmDictation:M,cancelDictation:j,retryFailedDictation:N,acceptPartialTranscript:P,discardFailedDictation:F}}var ul=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},dl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=za(),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},fl=e=>{let t=mi(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 V(`/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},pl=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:c,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=st(),{currentTheme:v}=za(),y=mi(ml),b=s(hl),x;t[0]===b?x=t[1]:(x=Wa(Ya(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(gl),w=Z.useRef(null),T=Z.useRef(u),E=Z.useRef(d),D,O;t[2]!==u||t[3]!==d?(D=()=>{T.current=u,E.current=d},O=[u,d],t[2]=u,t[3]=d,t[4]=D,t[5]=O):(D=t[4],O=t[5]),Z.useEffect(D,O);let k;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(k={onTranscript:e=>{let t=w.current;w.current=null,t===`send`?E.current(e):T.current(e)}},t[6]=k):k=t[6];let{status:A,partialTranscript:j,volume:M,duration:N,error:P,errorReason:F,startDictation:I,confirmDictation:L,cancelDictation:R,retryFailedDictation:z,acceptPartialTranscript:B,discardFailedDictation:V}=ll(k),H=A===`recording`&&F===`model_download_in_progress`,U=fl(H),ee=Z.useRef(A),te,W;t[7]===A?(te=t[8],W=t[9]):(te=()=>{ee.current=A},W=[A],t[7]=A,t[8]=te,t[9]=W),Z.useEffect(te,W);let G,ne;t[10]!==f||t[11]!==A?(G=()=>{f?.(A!==`idle`)},ne=[A,f],t[10]=f,t[11]=A,t[12]=G,t[13]=ne):(G=t[12],ne=t[13]),Z.useLayoutEffect(G,ne);let re,ie;t[14]!==L||t[15]!==I?(re=()=>{let e=()=>{ee.current===`idle`?I():ee.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ie=[I,L],t[14]=L,t[15]=I,t[16]=re,t[17]=ie):(re=t[16],ie=t[17]),Z.useEffect(re,ie);let ae,oe;t[18]!==R||t[19]!==L||t[20]!==A?(ae=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},oe=[A,L,R],t[18]=R,t[19]=L,t[20]=A,t[21]=ae,t[22]=oe):(ae=t[21],oe=t[22]),Z.useEffect(ae,oe);let se=Z.useRef(null),ce=Z.useRef(null),le=Z.useRef(null),[ue,de]=Z.useState(null),fe=A!==`idle`,pe=Z.useRef(p),me,he;t[23]===p?(me=t[24],he=t[25]):(me=()=>{pe.current=p},he=[p],t[23]=p,t[24]=me,t[25]=he),Z.useEffect(me,he);let ge=Z.useRef(!1),_e;t[26]===fe?_e=t[27]:(_e=()=>{if(!fe){ge.current&&(ge.current=!1,pe.current?.(null));return}let e=ce.current,t=le.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);ge.current=!0,pe.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=fe,t[27]=_e);let ve;t[28]!==P||t[29]!==fe||t[30]!==j||t[31]!==A?(ve=[fe,j,A,P],t[28]=P,t[29]=fe,t[30]=j,t[31]=A,t[32]=ve):ve=t[32],Z.useLayoutEffect(_e,ve);let ye,be;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ye=()=>()=>{ge.current&&(ge.current=!1,pe.current?.(null))},be=[],t[33]=ye,t[34]=be):(ye=t[33],be=t[34]),Z.useEffect(ye,be);let xe,Se;if(t[35]===fe?(xe=t[36],Se=t[37]):(xe=()=>{if(!fe)return;let e=se.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&de(e.offsetHeight)},Se=[fe],t[35]=fe,t[36]=xe,t[37]=Se),Z.useLayoutEffect(xe,Se),!C||!y)return null;let Ce=A!==`idle`,we;t[38]===L?we=t[39]:(we=e=>{w.current=e,L()},t[38]=L,t[39]=we);let Te=we,Ee;t[40]===z?Ee=t[41]:(Ee=()=>{w.current=`insert`,z()},t[40]=z,t[41]=Ee);let De=Ee,Oe;bb0:{if(A===`failed`){Oe=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),Oe=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],Oe=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),Oe=e}let ke=Oe,Ae;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Ae={onMouseDown:_l,onPointerDownCapture:vl},t[49]=Ae):Ae=t[49];let je=Ae,Me;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==Ce||t[55]!==g||t[56]!==I||t[57]!==_?(Me=g?(0,$.jsx)(`button`,{type:`button`,...je,className:i,onClick:()=>{I()},disabled:l||Ce,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=Ce,t[55]=g,t[56]=I,t[57]=_,t[58]=Me):Me=t[58];let Ne;t[59]!==B||t[60]!==R||t[61]!==Te||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==ue||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==Ce||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==ke||t[75]!==n||t[76]!==De||t[77]!==c||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(Ne=Ce?(0,$.jsxs)(`div`,{ref:se,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(0,$.jsx)(`div`,{ref:ce,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:le,className:Y(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(dl,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:ke})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:ke}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ue?{height:ue}:void 0,children:[A===`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:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(dl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:ul(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.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:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...je,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...je,className:i,onClick:()=>Te(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...je,className:Y(i,`text-primary hover:text-primary`),onClick:()=>Te(`send`),title:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:c})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...je,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...je,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...je,className:i,onClick:De,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...je,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=Te,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=ue,t[67]=i,t[68]=a,t[69]=o,t[70]=Ce,t[71]=r,t[72]=H,t[73]=j,t[74]=ke,t[75]=n,t[76]=De,t[77]=c,t[78]=A,t[79]=_,t[80]=h,t[81]=M,t[82]=Ne):Ne=t[82];let Pe;return t[83]!==Me||t[84]!==Ne?(Pe=(0,$.jsxs)($.Fragment,{children:[Me,Ne]}),t[83]=Me,t[84]=Ne,t[85]=Pe):Pe=t[85],Pe};function ml(e){return e.dictationEnabled}function hl(e){return e.shortcutOverrides}function gl(){return!d()&&tl()}function _l(e){return e.preventDefault()}function vl(e){e.pointerType===`touch`&&e.preventDefault()}var yl=2e3,bl=fe((e,t)=>({pending:!1,expiresAt:null,arm:(t=yl)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),xl=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}},Sl=15e3,Cl=100,wl=new Map,Tl=new Map,El=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,Dl=e=>{let t=El(e),n=e.now??Date.now(),r=Tl.get(t);if(r&&n-r.loadedAt<Sl)return Promise.resolve(r.sessions);let i=wl.get(t);if(i)return i;let a=e.request().then(e=>{for(Tl.delete(t);Tl.size>=Cl;){let e=Tl.keys().next().value;if(typeof e!=`string`)break;Tl.delete(e)}return Tl.set(t,{loadedAt:Date.now(),sessions:e}),e});return wl.set(t,a),a.then(()=>{wl.get(t)===a&&wl.delete(t)},()=>{wl.get(t)===a&&wl.delete(t)}),a},Ol=(e,t)=>e.id<t.id?-1:+(e.id>t.id),kl=(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);return i.length===0?e:[...e,...i].sort(Ol)},Al=30;function jl(e){return e===`busy`||e===`retry`}var Ml=new Map;function Nl(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Pl(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.message;if(typeof t==`string`&&t.length>0)return t}try{return JSON.stringify(e)}catch{return String(e)}}function Fl(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${Pl(e.error)}`)}function Il(e,t){let n=In();if(!n)return!1;let r=n.getTranscript(gt(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>jn()}function Ll(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Rl(e,t,n){let r=[...e.getState().session],i=It.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function zl(){let e=oi(),t=Gn(),n=Jn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=In();if(!r||!t)return Nl({kind:`unknown`,loadedTurns:0},!1);let i=gt(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Nl(a.boundary,o?.status===`loading`)},[e]),o=(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_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};Vn(a,t),En(r,t),r.setState(a);for(let n of t)zn(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=Ml.get(t);if(n)return Ml.delete(t),Ml.set(t,n),n;let r=new Set;for(Ml.set(t,r);Ml.size>Al;){let e=Ml.keys().next().value;if(!e)break;let t=[...Ml.get(e)??[]];Ml.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=jt(a.getState()),u=Xt(),d=Tt({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),un()){let e=new Set([r,...c,...l]),t=(In()?.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:Il(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(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 xr(a,r):await Ji(a,r)}catch{return}if(i?.isStale?.())return;let u=In()?.getTranscript(gt(a,r));Ur({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await $r({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]),u=(0,Z.useCallback)(async(t,i)=>{await Nn();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=Ae.getScopedSdkClient(o);c(t,o);let d=r(t,o);return xl.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=In(),i=gt(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=It.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&yt(o,t)){Ur({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Ll({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Ti(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Fl(e,`session.get`),e});if(n.data&&!e()){let r=li(n.data);e()||Rl(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let a=r||e;if(!t||!a)return;let o=n.ensureChild(a,{bootstrap:!1}),s=Ae.getScopedSdkClient(a),c=await Dl({runtimeKey:i(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return Fl(e,`session.children`),e.data??[]}});o.setState(e=>{let n=kl(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;Ii(gt(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;Ii(gt(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;Ii(gt(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await Nn();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(jl(o))throw Error(`refresh transcript busy`);try{await kt(i,t),Ur({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Bl=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Vl=e=>e===`original`||e===`modified`,Hl=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Ul=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Bl(t.source))return null;let n=Hl(t.startLine),r=Hl(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:Vl(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()}},Wl=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(Ul).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Gl=fe()(me(pe((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:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Wl(e.drafts)}}),{name:`inline-comment-draft-store`}));function Kl(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 ql(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Kl).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-B7vUFIz4.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-DzwCfRqr.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-6sclr7B6.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-DWuULPzo.js","assets/store-DQY8Fkb0.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/utils-B1EK5zKa.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-DpjYnXxn.js","assets/dialog-DPS0W9eS.js","assets/button-C7OXr4ae.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-B89dbj3N.js","assets/vendor-pierre-diffs-BenIz2TM.js","assets/vendor-hast-util-to-html-B0p1k5Xa.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-DpDied8H.js","assets/appThemeRegistry-BWAStv0M.js","assets/platform-CbeLpKPk.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/markdown-worker-W06-MhF5.js","assets/useEffectiveDirectory-DRp5lrMh.js","assets/useMobileNavigationStore-CGSKnVbj.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-BHsHXCKE.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/useWorkerHighlightedLines-BSyHhMx_.js","assets/tooltip-D_orJMYd.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T as i,U as a,g as o,t as s,w as c,y as l}from"./useUIStore-DzwCfRqr.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as W,ot as ee,pt as G,q as K,r as te,st as ne,u as re,ut as ie,v as ae,wt as oe,x as se,y as ce,yt as le,z as ue}from"./persistence-6sclr7B6.js";import{a as de,i as fe,r as pe,t as me}from"./vendor-zustand-B4dlGEM2.js";import{c as he,d as ge,f as _e,l as ve,nt as ye,rt as be,tt as xe,u as Se}from"./vendor-base-ui-CnHfUmDN.js";import{At as Ce,Bt as we,Ct as Te,Gt as Ee,Ht as De,Jt as Oe,Nt as ke,Pt as Ae,Rt as je,St as Me,Ut as Ne,Wt as Pe,jt as Fe,kt as Ie,n as Le,qt as Re,t as ze,zt as Be}from"./platform-CbeLpKPk.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as $e,d as et,i as tt,l as nt,n as q,o as rt,r as it,u as at}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ot,r as st,t as ct}from"./clipboard-DWuULPzo.js";import{i as lt,t as ut}from"./store-DQY8Fkb0.js";import{$ as dt,$a as ft,$t as pt,A as mt,Aa as ht,Ai as gt,At as _t,Bi as vt,Br as yt,Ci as bt,Cn as xt,D as St,Di as Ct,Dn as wt,Dr as Tt,Dt as Et,E as Dt,Ea as Ot,Ei as kt,En as At,Eo as jt,Er as Mt,Et as Nt,F as Pt,Fa as Ft,Fo as It,Fr as Lt,Ft as Rt,G as zt,Ga as Bt,Gi as Vt,Gr as Ht,Gt as Ut,H as Wt,Hi as Gt,Hr as Kt,Ht as qt,I as Jt,Ii as Yt,Ir as Xt,It as Zt,J as Qt,Ja as $t,Ji as en,Jr as tn,Jt as nn,K as rn,Ka as an,Ki as on,Kr as sn,La as cn,Li as ln,Ln as un,M as dn,Mi as fn,Mr as pn,N as mn,Na as hn,Ni as gn,Nr as _n,O as vn,Oa as yn,Oi as J,Or as bn,Ot as xn,P as Sn,Pa as Cn,Pr as wn,Pt as Tn,Q as En,Qa as Dn,Qi as On,R as kn,Ri as An,Rn as jn,Ro as Mn,Rr as Nn,S as Pn,Sa as Fn,St as In,T as Ln,Ta as Rn,Ti as zn,Tn as Bn,To as Vn,Ui as Hn,Ur as Un,Ut as Wn,Va as Gn,Vi as Kn,Vt as qn,W as Jn,Wi as Yn,Wn as Xn,Wr as Zn,Wt as Qn,X as $n,Xa as er,Xt as tr,Y as nr,Ya as rr,Yr as ir,Yt as ar,Z as or,Za as sr,Zr as cr,Zt as lr,_a as ur,_i as dr,_r as fr,a as pr,aa as mr,ai as hr,an as gr,ao as _r,ar as vr,at as yr,ba as br,bi as xr,bn as Sr,br as Cr,ci as wr,cn as Tr,dn as Er,dt as Dr,en as Or,eo as kr,et as Ar,f as jr,fi as Mr,fn as Nr,ft as Pr,g as Fr,ga as Ir,gt as Lr,hi as Rr,hn as zr,ht as Br,i as Vr,ii as Hr,ir as Ur,it as Wr,j as Gr,ji as Kr,jt as qr,k as Jr,ki as Yr,kr as Xr,kt as Zr,l as Qr,li as $r,ln as ei,lo as ti,lt as ni,m as ri,ma as ii,mi as ai,mn as oi,mt as si,n as ci,na as li,ni as ui,nn as di,nr as fi,nt as pi,oa as mi,oi as hi,on as gi,oo as _i,ot as vi,pi as yi,pn as bi,pt as xi,q as Si,qa as Ci,qi as wi,ra as Ti,ri as Ei,rn as Di,rr as Oi,rt as ki,sa as Ai,sn as ji,tn as Mi,tt as Ni,ua as Pi,un as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wa as Bi,wi as Vi,wn as Hi,x as Ui,xa as Wi,xi as Gi,xn as Ki,xt as qi,ya as Ji,yi as Yi,z as Xi,zi as Zi,zn as Qi}from"./useMobileNavigationStore-CGSKnVbj.js";import{n as $i,t as ea}from"./AgentAvatar-DDcjamcJ.js";import{n as ta,t as Y}from"./utils-B1EK5zKa.js";import{n as X}from"./Icon-DpjYnXxn.js";import{a as na,i as ra,n as ia,o as aa,r as oa,s as sa,t as ca}from"./dialog-DPS0W9eS.js";import{t as la}from"./button-C7OXr4ae.js";import{E as ua,n as da}from"./gitApi-BtRkoe9k.js";import{A as fa,C as pa,M as ma,N as ha,O as ga,S as _a,T as va,a as ya,b as ba,d as xa,g as Sa,h as Ca,i as wa,j as Ta,k as Ea,n as Da,o as Oa,p as ka,s as Aa,u as ja,v as Ma,w as Na,x as Pa}from"./projectMeta-B4BZoe_0.js";import{t as Fa}from"./input-BzYA603C.js";import{i as Ia,n as La,t as Ra}from"./tooltip-D_orJMYd.js";import{n as za,t as Ba}from"./useThemeSystem-DMzWVJaW.js";import{B as Va,C as Ha,D as Ua,H as Wa,N as Ga,O as Ka,P as qa,S as Ja,W as Ya,X as Xa,Z as Za,_ as Qa,a as $a,f as eo,g as to,h as no,i as ro,it as io,k as ao,m as oo,o as so,p as co,r as lo,t as uo}from"./radio-BIFaTwYH.js";import{i as fo,t as po}from"./OverlayScrollbar-Ch3J6ASR.js";import{_ as mo,a as ho,d as go,f as _o,g as vo,h as yo,i as bo,l as xo,m as So,n as Co,u as wo,v as To,x as Eo}from"./markdownTheme-B89dbj3N.js";import{n as Do,r as Oo,t as ko}from"./useRuntimeAPIs-DSLXJybW.js";import{a as Ao,c as jo,i as Mo,r as No,t as Po,u as Fo}from"./appThemeRegistry-BWAStv0M.js";import{_ as Io,a as Lo,c as Ro,g as zo,l as Bo,o as Vo,t as Ho,v as Uo,y as Wo}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Go,n as Ko,o as qo,s as Jo,t as Yo}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as Xo,n as Zo,t as Qo}from"./url-BsaBG5-1.js";import{_ as $o,l as es,m as ts,p as ns,s as rs}from"./markdown-worker-W06-MhF5.js";import{n as is}from"./useEffectiveDirectory-DRp5lrMh.js";import{a as as,c as os,d as ss,f as cs,i as ls,l as us,n as ds,r as fs,s as ps,t as ms}from"./FadeInOnReveal-By2F9vcI.js";import{A as hs,C as gs,D as _s,E as vs,M as ys,O as bs,S as xs,T as Ss,a as Cs,b as ws,c as Ts,f as Es,i as Ds,j as Os,k as ks,l as As,m as js,n as Ms,o as Ns,p as Ps,r as Fs,s as Is,t as Ls,u as Rs,w as zs,x as Bs}from"./insertionBoundaries-0QdvxqZx.js";import{A as Vs,C as Hs,D as Us,E as Ws,M as Gs,O as Ks,S as qs,T as Js,a as Ys,b as Xs,c as Zs,g as Qs,h as $s,i as ec,j as tc,k as nc,o as rc,p as ic,r as ac,s as oc,t as sc,v as cc,w as lc,x as uc,y as dc}from"./useWorkerHighlightedLines-BSyHhMx_.js";import{t as fc}from"./vendor-cmdk-CeAGfrLo.js";import{t as pc}from"./sortable-tabs-strip-nLsPC06f.js";import{n as mc,t as hc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as gc,u as _c}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as vc,t as yc}from"./vendor-framer-motion-DFy_BSVd.js";import{t as bc}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(be(),1),Q=We(),$=ye(),xc=e(xe(),1),Sc=`openchamber:close-embedded-session-chat`,Cc=`openchamber:embedded-visibility`,wc=`openchamber:embedded-visibility-request`,Tc=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,Ec=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),Dc=(e,t,n,r)=>{if(typeof window>`u`)return``;let i=new URL(window.location.pathname,window.location.origin);return i.searchParams.set(`ocPanel`,`session-chat`),i.searchParams.set(`surface`,`desktop`),i.searchParams.set(`sessionId`,e),n?i.searchParams.set(`readOnly`,`1`):i.searchParams.delete(`readOnly`),t&&t.trim().length>0?i.searchParams.set(`directory`,t):i.searchParams.delete(`directory`),i.searchParams.set(`themeMode`,r.mode),i.searchParams.set(`lightThemeId`,r.lightThemeId),i.searchParams.set(`darkThemeId`,r.darkThemeId),i.searchParams.set(`themeVariant`,r.currentTheme.metadata.variant===`dark`?`dark`:`light`),i.searchParams.set(`currentTheme`,JSON.stringify(r.currentTheme)),i.hash=``,i.toString()},Oc=(e,t,n,r,i,a)=>{let o=Ec(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=Dc(n,r,i,a);return e.set(t,{signature:o,src:c}),c},kc=null,Ac=()=>{if(kc!==null)return kc;if(typeof window>`u`)return kc=!1,!1;try{return kc=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,kc}catch{return kc=!1,!1}},jc=()=>{if(!Ac())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},Mc=Ve(`OpenChamberMedia`);function Nc(){return Le()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function Pc(e){if(!Nc())return null;let t=await Mc.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(He.convertFileSrc(e.path));if(!t.ok)throw Error(`Native media fetch failed (${t.status})`);let r=await t.blob();n.push(new File([r],e.name,{type:e.mimeType}))}return n}var Fc=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Ic=1e4,Lc=15e3,Rc=3e4,zc=3e4,Bc=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;get isConnected(){return this.socket?.readyState===WebSocket.OPEN}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(!this.isConnected){if(this.connectPromise){await this.connectPromise;return}try{await a()}catch{}this.connectPromise=new Promise((e,t)=>{let n=!1,i;try{let e=r().websocket(`/api/dictation/ws`);i=Me(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!n){n=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},Ic);i.onopen=()=>{},i.onmessage=t=>{let r;try{r=JSON.parse(String(t.data))}catch{return}if(!n&&r.type===`ready`){n=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(r)},i.onerror=()=>{window.setTimeout(()=>{n||(n=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!n){n=!0,clearTimeout(a),this.connectPromise=null;let r=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${r}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t,n){return await this.ensureConnected(),this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((r,i)=>{let a=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation start timed out`))},Lc);this.pendingStarts.set(e,{resolve:()=>{clearTimeout(a),r()},reject:e=>{clearTimeout(a),this.releaseDictation(),i(e)},timeout:a}),this.send({type:`start`,dictationId:e,format:t,options:n})||(clearTimeout(a),this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation connection lost`)))})}sendDictationStreamChunk(e,t,n){return this.send({type:`chunk`,dictationId:e,seq:t,audio:n})}finishDictationStream(e,t){return new Promise((n,r)=>{let i={resolve:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),n(e)},reject:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),r(e)},timeout:null};i.timeout=setTimeout(()=>{this.pendingFinishes.delete(e),this.releaseDictation(),r(Error(`Timed out waiting for transcription`))},zc),this.pendingFinishes.set(e,i),this.send({type:`finish`,dictationId:e,finalSeq:t})||(this.pendingFinishes.delete(e),i.reject(Error(`Dictation connection lost`)))})}cancelDictationStream(e){this.send({type:`cancel`,dictationId:e});let t=this.pendingStarts.get(e);t&&(this.pendingStarts.delete(e),t.reject(Error(`Dictation cancelled`)));let n=this.pendingFinishes.get(e);n&&(this.pendingFinishes.delete(e),n.reject(Error(`Dictation cancelled`))),this.releaseDictation(),this.scheduleIdleCloseIfReady()}handleMessage(e){let t=e.dictationId;if(t)switch(e.type){case`ack`:{let e=this.pendingStarts.get(t);e&&(this.pendingStarts.delete(t),e.resolve());return}case`partial`:for(let n of this.partialListeners)n(t,e.text??``);return;case`finish_accepted`:{let n=this.pendingFinishes.get(t);n&&typeof e.timeoutMs==`number`&&(n.timeout&&clearTimeout(n.timeout),n.timeout=setTimeout(()=>{this.pendingFinishes.delete(t),n.reject(Error(`Timed out waiting for transcription`))},e.timeoutMs+5e3));return}case`final`:{let n=this.pendingFinishes.get(t);n&&(this.pendingFinishes.delete(t),n.resolve({text:e.text??``})),this.scheduleIdleCloseIfReady();return}case`error`:{let n=Fc(e.error||`Dictation failed`,e.retryable!==!1,e.reasonCode),r=this.pendingStarts.get(t);r&&(this.pendingStarts.delete(t),r.reject(n));let i=this.pendingFinishes.get(t);i&&(this.pendingFinishes.delete(t),i.reject(n)),this.scheduleIdleCloseIfReady();return}}}send(e){if(!this.isConnected||!this.socket)return!1;try{return this.socket.send(JSON.stringify(e)),!0}catch{return!1}}notifyConnection(e){for(let t of this.connectionListeners)t(e)}rejectAllPending(e){for(let[t,n]of this.pendingStarts)this.pendingStarts.delete(t),n.reject(e);for(let[t,n]of this.pendingFinishes)this.pendingFinishes.delete(t),n.reject(e);this.activeDictations=0}releaseDictation(){this.activeDictations=Math.max(0,this.activeDictations-1),this.scheduleIdleCloseIfReady()}scheduleIdleCloseIfReady(){this.activeDictations>0||this.pendingFinishes.size>0||this.pendingStarts.size>0||(this.clearIdleCloseTimer(),this.idleCloseTimer=setTimeout(()=>{if(this.activeDictations===0&&this.pendingFinishes.size===0&&this.pendingStarts.size===0){let e=this.socket;if(this.socket=null,e){try{e.close(1e3,`idle`)}catch{}this.notifyConnection(!1)}}},Rc))}cancelAllForRuntimeSwitch(){this.clearIdleCloseTimer();let e=this.socket;if(this.socket=null,this.connectPromise=null,this.rejectAllPending(Error(`Runtime changed`)),e){try{e.close(1e3,`runtime switch`)}catch{}this.notifyConnection(!1)}}clearIdleCloseTimer(){this.idleCloseTimer&&=(clearTimeout(this.idleCloseTimer),null)}};typeof window<`u`&&window.addEventListener(`openchamber:runtime-endpoint-changed`,()=>{Bc.cancelAllForRuntimeSwitch()});var Vc=128,Hc=`audio/pcm;rate=16000;bits=16`,Uc=()=>new Promise(e=>setTimeout(e,0)),Wc=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Gc=class{client;format;createDictationId;getStartOptions;dictationId=null;sendSeq=0;segments=[];streamReady=!1;flushTimer=null;drainWaiters=[];startGeneration=0;startPromise=null;constructor(e){this.client=e.client,this.format=e.format??Hc,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Wc}getDictationId(){return this.dictationId}getFinalSeq(){return this.segments.length-1}hasSegments(){return this.segments.length>0}clearAll(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.segments=[],this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}resetStreamForReplay(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}enqueueSegment(e){if(this.segments.push(e),this.client.isConnected){if(!this.dictationId){this.startPromise||this.restartStream().catch(()=>{});return}this.flush()}}flush(){let e=this.dictationId;if(!this.client.isConnected||!e||!this.streamReady)return 0;let t=0;for(;this.sendSeq<this.segments.length&&t<Vc;){let n=this.sendSeq,r=this.segments[n];if(!this.client.sendDictationStreamChunk(e,n,r))break;this.sendSeq=n+1,t+=1}return this.hasPendingSegments()?this.scheduleFlush():this.resolveDrainWaiters(),t}async restartStream(){this.startGeneration+=1;let e=this.startGeneration,t=this.createDictationId();this.dictationId=t,this.sendSeq=0,this.streamReady=!1;let n=(async()=>{await this.client.startDictationStream(t,this.format,this.getStartOptions()),this.startGeneration===e&&this.dictationId===t&&(this.streamReady=!0,this.flush())})().catch(n=>{throw this.startGeneration===e&&this.dictationId===t&&(this.dictationId=null,this.streamReady=!1),n}).finally(()=>{this.startPromise===n&&(this.startPromise=null)});this.startPromise=n,await n}async finish(e){this.dictationId||await this.restartStream(),this.startPromise&&await this.startPromise;let t=this.dictationId;if(!t||!this.streamReady)throw Error(`Failed to start dictation stream`);return this.flush(),await this.waitForFlushDrain(),{dictationId:t,text:(await this.client.finishDictationStream(t,e)).text}}cancel(){let e=this.dictationId;this.client.isConnected&&e&&this.client.cancelDictationStream(e),this.resetStreamForReplay()}hasPendingSegments(){return this.sendSeq<this.segments.length}scheduleFlush(){this.flushTimer||=setTimeout(()=>{this.flushTimer=null,this.flush()},0)}clearScheduledFlush(){this.flushTimer&&=(clearTimeout(this.flushTimer),null)}async waitForFlushDrain(){for(;this.hasPendingSegments();){if(!this.client.isConnected||!this.dictationId||!this.streamReady)throw Error(`Failed to flush dictation stream`);await new Promise(e=>{this.drainWaiters.push(e)}),await Uc()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Kc=16e3,qc=Kc,Jc=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Yc=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Xc=(e,t,n)=>{if(e.length===0)return new Int16Array;if(t===n){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=Yc(e[n]);return t}let r=t/n,i=Math.max(1,Math.round(e.length/r)),a=new Int16Array(i);for(let t=0;t<i;t++){let n=t*r,i=Math.floor(n),o=Math.min(e.length-1,i+1),s=n-i;a[t]=Yc(e[i]*(1-s)+e[o]*s)}return a},Zc=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},Qc=e=>{let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)},$c=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),el=e=>{if(e)try{e.disconnect()}catch{}},tl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Jc()!==null;function nl(e){let t=(0,Q.c)(12),[n,r]=(0,Z.useState)(0),i=(0,Z.useRef)(e.onPcmSegment),a=(0,Z.useRef)(e.onError),o,s;t[0]!==e.onError||t[1]!==e.onPcmSegment?(o=()=>{i.current=e.onPcmSegment,a.current=e.onError},s=[e.onPcmSegment,e.onError],t[0]=e.onError,t[1]=e.onPcmSegment,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,Z.useEffect)(o,s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=$c(),t[4]=c):c=t[4];let l=(0,Z.useRef)(c),u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=async()=>{if(l.current.started)return;if(typeof navigator>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(`Microphone capture is not supported in this environment`);let e=Jc();if(!e)throw Error(`AudioContext unavailable`);let t=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0}}),n=new e;try{n.state===`suspended`&&await n.resume().catch(al);let e=n.createMediaStreamSource(t),a=n.createScriptProcessor(4096,1,1),o=n.createGain();o.gain.value=0,l.current={stream:t,context:n,source:e,processor:a,gain:o,pending:new Int16Array,started:!0},a.onaudioprocess=e=>{let t=l.current;if(!t.started)return;let a=e.inputBuffer.getChannelData(0),o=0;for(let e=0;e<a.length;e++)o+=a[e]*a[e];let s=Math.sqrt(o/Math.max(1,a.length));r(Math.min(1,Math.max(0,s*2)));let c=Xc(a,n.sampleRate,Kc);for(t.pending=Zc(t.pending,c);t.pending.length>=qc;){let e=t.pending.slice(0,qc);t.pending=t.pending.slice(qc),i.current(Qc(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(il);try{await n.close()}catch{}throw l.current=$c(),r instanceof Error?r:Error(String(r))}},t[5]=u):u=t[5];let d=u,f;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=async()=>{let e=l.current;if(e.started=!1,r(0),e.processor)try{e.processor.onaudioprocess=null}catch{}el(e.processor),el(e.source),el(e.gain),e.stream&&e.stream.getTracks().forEach(rl);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Qc(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=$c())},t[6]=f):f=t[6];let p=f,m,h;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>()=>{p().catch(e=>{a.current?.(e instanceof Error?e:Error(String(e)))})},h=[p],t[7]=m,t[8]=h):(m=t[7],h=t[8]),(0,Z.useEffect)(m,h);let g;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=async()=>{try{await d()}catch(e){let t=e,n=t instanceof Error?t:Error(String(t));throw a.current?.(n),n}},t[9]=g):g=t[9];let _;return t[10]===n?_=t[11]:(_={start:g,stop:p,volume:n},t[10]=n,t[11]=_),_}function rl(e){try{e.stop()}catch{}}function il(e){try{e.stop()}catch{}}function al(){}var ol=1e3,sl=e=>e instanceof Error?e:Error(String(e)),cl=()=>{let e=mi.getState(),t=e.sttLanguage?.trim();return e.sttProvider===`openai-compatible`?{provider:`openai-compatible`,...t?{language:t}:{},openaiCompatible:{baseUrl:e.sttServerUrl,model:e.sttModel,...e.sttApiKey?{apiKey:e.sttApiKey}:{}}}:{provider:`local`,...t?{language:t}:{},localModel:e.sttLocalModel}};function ll(e={}){let{onTranscript:t,onError:n,canStart:r}=e,[i,a]=(0,Z.useState)(`idle`),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(0),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),m=(0,Z.useRef)(i);(0,Z.useEffect)(()=>{m.current=i},[i]);let h=(0,Z.useRef)(``),g=(0,Z.useRef)(null),_=(0,Z.useRef)({starting:!1,confirming:!1,cancelling:!1}),v=(0,Z.useRef)(t),y=(0,Z.useRef)(n);(0,Z.useEffect)(()=>{v.current=t,y.current=n},[t,n]);let b=(0,Z.useRef)(null);b.current||=new Gc({client:Bc,getStartOptions:cl});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},ol)},[]),C=(0,Z.useCallback)(e=>{let t=sl(e);d(t.message);let n=t.reasonCode;p(typeof n==`string`?n:null),y.current?.(t)},[]),w=(0,Z.useCallback)(()=>{d(null),p(null)},[]),T=(0,Z.useCallback)(()=>{b.current?.clearAll(),h.current=``,s(``)},[]);(0,Z.useEffect)(()=>Bc.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Bc.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=nl({onPcmSegment:e=>{b.current?.enqueueSegment(e)},onError:e=>{y.current?.(e)}}),D=(0,Z.useRef)(E.stop);(0,Z.useEffect)(()=>{D.current=E.stop},[E.stop]);let O=(0,Z.useCallback)(e=>{l(0),a(`idle`);let t=e.trim().length>0?e.trim():h.current.trim();return T(),t?(v.current?.(t),t):null},[T]),k=(0,Z.useCallback)(e=>{b.current?.hasSegments()?a(`failed`):a(`idle`),C(e)},[C]),A=(0,Z.useCallback)(async()=>{let e=_.current;if(!(e.starting||e.confirming||e.cancelling)&&m.current===`idle`&&!(r&&!r())){e.starting=!0,w(),s(``),l(0),a(`recording`),m.current=`recording`,T();try{await E.start(),S(),await b.current?.restartStream().catch(e=>{C(e)})}catch(e){await E.stop().catch(()=>void 0),x(),a(`idle`),m.current=`idle`,C(e)}finally{e.starting=!1}}},[E,r,w,T,C,S,x]),j=(0,Z.useCallback)(async()=>{let e=_.current;if(!e.cancelling&&(m.current===`recording`||m.current===`uploading`)){e.cancelling=!0,x(),l(0),w(),a(`idle`),m.current=`idle`;try{b.current?.cancel()}catch{}T();try{await E.stop()}catch{}finally{e.cancelling=!1}}},[E,w,T,x]),M=(0,Z.useCallback)(async()=>{let e=_.current;if(e.confirming||m.current!==`recording`)return null;e.confirming=!0,w(),x();try{await E.stop(),a(`uploading`),m.current=`uploading`;let e=b.current?.getFinalSeq()??-1;if(e<0)return O(``);let t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}finally{e.confirming=!1}},[E,w,k,O,x]),N=(0,Z.useCallback)(async()=>{if(m.current!==`failed`||!b.current?.hasSegments())return null;w(),a(`uploading`),m.current=`uploading`;try{b.current.resetStreamForReplay();let e=b.current.getFinalSeq(),t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}},[w,k,O]),P=(0,Z.useCallback)(()=>{if(m.current!==`failed`)return null;let e=h.current.trim();l(0),a(`idle`),m.current=`idle`,w();try{b.current?.cancel()}catch{}return T(),e?(v.current?.(e),e):null},[w,T]),F=(0,Z.useCallback)(()=>{l(0),a(`idle`),m.current=`idle`,w(),T()},[w,T]);return(0,Z.useEffect)(()=>{if(i!==`recording`||f!==`model_download_in_progress`)return;let e=setInterval(()=>{m.current!==`recording`||b.current?.getDictationId()||b.current?.restartStream().then(()=>{w()}).catch(e=>{C(e)})},3e3);return()=>clearInterval(e)},[i,f,w,C]),(0,Z.useEffect)(()=>()=>{x(),D.current().catch(()=>void 0),b.current?.cancel()},[x]),{status:i,isRecording:i===`recording`,isProcessing:i===`uploading`,partialTranscript:o,volume:E.volume,duration:c,error:u,errorReason:f,startDictation:A,confirmDictation:M,cancelDictation:j,retryFailedDictation:N,acceptPartialTranscript:P,discardFailedDictation:F}}var ul=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},dl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=za(),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},fl=e=>{let t=mi(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 V(`/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},pl=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:c,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=ot(),{currentTheme:v}=za(),y=mi(ml),b=s(hl),x;t[0]===b?x=t[1]:(x=Wa(Ya(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(gl),w=Z.useRef(null),T=Z.useRef(u),E=Z.useRef(d),D,O;t[2]!==u||t[3]!==d?(D=()=>{T.current=u,E.current=d},O=[u,d],t[2]=u,t[3]=d,t[4]=D,t[5]=O):(D=t[4],O=t[5]),Z.useEffect(D,O);let k;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(k={onTranscript:e=>{let t=w.current;w.current=null,t===`send`?E.current(e):T.current(e)}},t[6]=k):k=t[6];let{status:A,partialTranscript:j,volume:M,duration:N,error:P,errorReason:F,startDictation:I,confirmDictation:L,cancelDictation:R,retryFailedDictation:z,acceptPartialTranscript:B,discardFailedDictation:V}=ll(k),H=A===`recording`&&F===`model_download_in_progress`,U=fl(H),W=Z.useRef(A),ee,G;t[7]===A?(ee=t[8],G=t[9]):(ee=()=>{W.current=A},G=[A],t[7]=A,t[8]=ee,t[9]=G),Z.useEffect(ee,G);let K,te;t[10]!==f||t[11]!==A?(K=()=>{f?.(A!==`idle`)},te=[A,f],t[10]=f,t[11]=A,t[12]=K,t[13]=te):(K=t[12],te=t[13]),Z.useLayoutEffect(K,te);let ne,re;t[14]!==L||t[15]!==I?(ne=()=>{let e=()=>{W.current===`idle`?I():W.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},re=[I,L],t[14]=L,t[15]=I,t[16]=ne,t[17]=re):(ne=t[16],re=t[17]),Z.useEffect(ne,re);let ie,ae;t[18]!==R||t[19]!==L||t[20]!==A?(ie=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ae=[A,L,R],t[18]=R,t[19]=L,t[20]=A,t[21]=ie,t[22]=ae):(ie=t[21],ae=t[22]),Z.useEffect(ie,ae);let oe=Z.useRef(null),se=Z.useRef(null),ce=Z.useRef(null),[le,ue]=Z.useState(null),de=A!==`idle`,fe=Z.useRef(p),pe,me;t[23]===p?(pe=t[24],me=t[25]):(pe=()=>{fe.current=p},me=[p],t[23]=p,t[24]=pe,t[25]=me),Z.useEffect(pe,me);let he=Z.useRef(!1),ge;t[26]===de?ge=t[27]:(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[26]=de,t[27]=ge);let _e;t[28]!==P||t[29]!==de||t[30]!==j||t[31]!==A?(_e=[de,j,A,P],t[28]=P,t[29]=de,t[30]=j,t[31]=A,t[32]=_e):_e=t[32],Z.useLayoutEffect(ge,_e);let ve,ye;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ve=()=>()=>{he.current&&(he.current=!1,fe.current?.(null))},ye=[],t[33]=ve,t[34]=ye):(ve=t[33],ye=t[34]),Z.useEffect(ve,ye);let be,xe;if(t[35]===de?(be=t[36],xe=t[37]):(be=()=>{if(!de)return;let e=oe.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&ue(e.offsetHeight)},xe=[de],t[35]=de,t[36]=be,t[37]=xe),Z.useLayoutEffect(be,xe),!C||!y)return null;let Se=A!==`idle`,Ce;t[38]===L?Ce=t[39]:(Ce=e=>{w.current=e,L()},t[38]=L,t[39]=Ce);let we=Ce,Te;t[40]===z?Te=t[41]:(Te=()=>{w.current=`insert`,z()},t[40]=z,t[41]=Te);let Ee=Te,De;bb0:{if(A===`failed`){De=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),De=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],De=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),De=e}let Oe=De,ke;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(ke={onMouseDown:_l,onPointerDownCapture:vl},t[49]=ke):ke=t[49];let Ae=ke,je;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==Se||t[55]!==g||t[56]!==I||t[57]!==_?(je=g?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{I()},disabled:l||Se,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=Se,t[55]=g,t[56]=I,t[57]=_,t[58]=je):je=t[58];let Me;t[59]!==B||t[60]!==R||t[61]!==we||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==le||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==Se||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==Oe||t[75]!==n||t[76]!==Ee||t[77]!==c||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(Me=Se?(0,$.jsxs)(`div`,{ref:oe,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(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(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(dl,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:Oe})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:Oe}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:le?{height:le}:void 0,children:[A===`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:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(dl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:ul(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.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:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>we(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`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:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:c})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`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:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:Ee,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=we,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=le,t[67]=i,t[68]=a,t[69]=o,t[70]=Se,t[71]=r,t[72]=H,t[73]=j,t[74]=Oe,t[75]=n,t[76]=Ee,t[77]=c,t[78]=A,t[79]=_,t[80]=h,t[81]=M,t[82]=Me):Me=t[82];let Ne;return t[83]!==je||t[84]!==Me?(Ne=(0,$.jsxs)($.Fragment,{children:[je,Me]}),t[83]=je,t[84]=Me,t[85]=Ne):Ne=t[85],Ne};function ml(e){return e.dictationEnabled}function hl(e){return e.shortcutOverrides}function gl(){return!d()&&tl()}function _l(e){return e.preventDefault()}function vl(e){e.pointerType===`touch`&&e.preventDefault()}var yl=2e3,bl=de((e,t)=>({pending:!1,expiresAt:null,arm:(t=yl)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),xl=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}},Sl=15e3,Cl=100,wl=new Map,Tl=new Map,El=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,Dl=e=>{let t=El(e),n=e.now??Date.now(),r=Tl.get(t);if(r&&n-r.loadedAt<Sl)return Promise.resolve(r.sessions);let i=wl.get(t);if(i)return i;let a=e.request().then(e=>{for(Tl.delete(t);Tl.size>=Cl;){let e=Tl.keys().next().value;if(typeof e!=`string`)break;Tl.delete(e)}return Tl.set(t,{loadedAt:Date.now(),sessions:e}),e});return wl.set(t,a),a.then(()=>{wl.get(t)===a&&wl.delete(t)},()=>{wl.get(t)===a&&wl.delete(t)}),a},Ol=(e,t)=>e.id<t.id?-1:+(e.id>t.id),kl=(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);return i.length===0?e:[...e,...i].sort(Ol)},Al=30;function jl(e){return e===`busy`||e===`retry`}var Ml=new Map;function Nl(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Pl(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.message;if(typeof t==`string`&&t.length>0)return t}try{return JSON.stringify(e)}catch{return String(e)}}function Fl(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${Pl(e.error)}`)}function Il(e,t){let n=Fn();if(!n)return!1;let r=n.getTranscript(ht(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>An()}function Ll(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Rl(e,t,n){let r=[...e.getState().session],i=Ft.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function zl(){let e=oi(),t=Wn(),n=qn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=Fn();if(!r||!t)return Nl({kind:`unknown`,loadedTurns:0},!1);let i=ht(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Nl(a.boundary,o?.status===`loading`)},[e]),o=(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_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};Bn(a,t),Tn(r,t),r.setState(a);for(let n of t)Rn(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=Ml.get(t);if(n)return Ml.delete(t),Ml.set(t,n),n;let r=new Set;for(Ml.set(t,r);Ml.size>Al;){let e=Ml.keys().next().value;if(!e)break;let t=[...Ml.get(e)??[]];Ml.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=At(a.getState()),u=Yt(),d=wt({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),ln()){let e=new Set([r,...c,...l]),t=(Fn()?.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:Il(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(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 br(a,r):await Ji(a,r)}catch{return}if(i?.isStale?.())return;let u=Fn()?.getTranscript(ht(a,r));Hr({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await $r({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]),u=(0,Z.useCallback)(async(t,i)=>{await Mn();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=ke.getScopedSdkClient(o);c(t,o);let d=r(t,o);return xl.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Fn(),i=ht(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Ft.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&vt(o,t)){Hr({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Ll({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Ti(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Fl(e,`session.get`),e});if(n.data&&!e()){let r=li(n.data);e()||Rl(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let a=r||e;if(!t||!a)return;let o=n.ensureChild(a,{bootstrap:!1}),s=ke.getScopedSdkClient(a),c=await Dl({runtimeKey:i(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return Fl(e,`session.children`),e.data??[]}});o.setState(e=>{let n=kl(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;Ii(ht(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;Ii(ht(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;Ii(ht(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await Mn();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(jl(o))throw Error(`refresh transcript busy`);try{await Ot(i,t),Hr({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Bl=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Vl=e=>e===`original`||e===`modified`,Hl=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Ul=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Bl(t.source))return null;let n=Hl(t.startLine),r=Hl(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:Vl(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()}},Wl=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(Ul).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Gl=de()(pe(fe((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:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Wl(e.drafts)}}),{name:`inline-comment-draft-store`}));function Kl(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 ql(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Kl).join(`
3
3
 
4
4
  ---
5
5
 
6
6
  `):e.map(Kl).join(`
7
7
 
8
- `)}function Jl(e,t){if(t.length===0)return e;let n=ql(t);return e.trim()?`${e}\n\n${n}`:n}var Yl={queue:Rr(),input:Lt.getState(),download:Ln,current:e=>Rr().captureRuntime().transportIdentity===e.transportIdentity&&Rr().captureRuntime().generation===e.generation},Xl=(e,t,n,r=!1)=>({status:e,current:!1,draftDurable:r,queueDurablyRemoved:!1,attachmentIssues:[],diagnostics:[{stage:t,code:n}]}),Zl=e=>JSON.stringify(e),Ql=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),$l=52428800,eu=4,tu=((e={})=>{let t={...Yl,...e},n=new Map;return{editServerQueueItemIntoDraft:e=>{let r;try{r=t.queue.captureRuntime()}catch{return Promise.resolve(Xl(`materialize-failed`,`identity`,`runtime-capture-failed`))}let i=`${r.transportIdentity}\u0000${r.generation}\u0000${e.scopeID}\u0000${e.item.queueItemID}`,a=n.get(i);if(a)return a;let o=(async()=>{let n=t.input.captureDraftRuntime();if(r.transportIdentity!==n.transportIdentity||r.generation!==n.generation||e.targetKey.transportIdentity!==r.transportIdentity)return Xl(`materialize-failed`,`identity`,`runtime-mismatch`);if((e.item.attachmentIssues?.length??0)>0)return{...Xl(`materialize-failed`,`attachments`,`attachment-issues`),attachmentIssues:e.item.attachmentIssues};let i;try{i=await t.queue.reserveEdit({requestID:L(),scopeID:e.scopeID,revision:e.scopeRevision,item:e.item,owner:`ui-edit`,ttlMs:6e4,runtime:r})}catch{return Xl(`materialize-failed`,`materialize`,`reserve-failed`)}if(!i)return Xl(`materialize-failed`,`materialize`,`reserve-rejected`);let a=!1,o=!1,s=new AbortController,c,l=()=>{o=!0,s.abort()},u=()=>{if(o)return Promise.resolve(!1);if(c)return c;let n=(async()=>{try{let n=await t.queue.renewEdit({item:e.item,token:i.token,generation:i.generation,ttlMs:6e4,runtime:r,signal:s.signal});return!n||n.queueItemID!==e.item.queueItemID||n.token!==i.token||n.generation!==i.generation||!Number.isSafeInteger(n.expiresAt)||Date.now()>=n.expiresAt||!t.current(r)?(l(),!1):!0}catch{return l(),!1}finally{c=void 0}})();return c=n,n},d=setInterval(()=>{u()},2e4),f=async()=>{if(!a){a=!0;try{await t.queue.releaseEdit({item:e.item,token:i.token,runtime:r})}catch{return}}};try{if(!t.current(r)||o)return Xl(`materialize-failed`,`identity`,o?`lease-lost`:`runtime-stale`);let c=e.item.attachments??[];if(new Set(c.map(e=>Zl(e.occurrenceRefID))).size!==c.length)return Xl(`materialize-failed`,`attachments`,`duplicate-occurrence`);if(c.reduce((e,t)=>e+t.size,0)>$l)return Xl(`materialize-failed`,`attachments`,`attachments-too-large`);let l=Array(c.length),d=0;if(await Promise.all(Array.from({length:Math.min(eu,c.length)},async()=>{for(;!s.signal.aborted;){let n=d++;if(n>=c.length)return;let r=c[n];l[n]={attachment:r,blob:await t.download(e.item.queueItemID,r,s.signal)}}})),!t.current(r)||o)return Xl(`materialize-failed`,`identity`,o?`lease-lost`:`runtime-stale`);let f=[],p=new Map,m=new Map;for(let e=0;e<c.length;e++){let t=c[e],n=l[e];if(n.attachment.attachmentID!==t.attachmentID||!Ql(n.attachment.occurrenceRefID,t.occurrenceRefID)||n.blob.size!==t.size||n.blob.type!==t.mimeType)return Xl(`materialize-failed`,`attachments`,`attachment-mismatch`);let r=Zl(t.occurrenceRefID),i={attachmentID:t.attachmentID,attachmentRefID:r,filename:t.filename,mimeType:t.mimeType,size:t.size,locator:{kind:`blob`,blobID:t.attachmentID},source:t.source,...t.locator.kind===`server-path`?{serverPath:t.locator.path}:{}};t.occurrenceRefID[0]===`part`?p.set(t.occurrenceRefID[1],[...p.get(t.occurrenceRefID[1])??[],i]):f.push(i),m.set(r,n.blob)}if(!t.current(r))return Xl(`materialize-failed`,`identity`,`runtime-stale`);if(!await u())return Xl(`materialize-failed`,`identity`,`lease-lost`);let h,g=(e.item.syntheticParts??[]).map(e=>({partID:e.partID,text:e.text,attachments:p.get(e.partID)??[],...e.synthetic===!0?{synthetic:!0}:{}}));try{let r=await Un({content:e.item.content,composerDocument:e.item.composerDocument,composerMentions:e.item.composerMentions,draftAttachments:f,draftValues:m,syntheticParts:g}),i=await Kt({key:e.targetKey,expectedRevision:e.expectedRevision,payload:r,runtime:n,input:t.input});if(h=i.result??{status:i.status,durable:i.durable,current:i.current,errors:[],cleanupErrors:[]},i.status===`failed`&&!i.result)return Xl(`draft-rejected`,`draft`,`commit-threw`)}catch{return Xl(`draft-rejected`,`draft`,`commit-threw`)}if(!h.durable)return Xl(`draft-rejected`,`draft`,h.status);if(!t.current(r)||o)return Xl(`queue-retained`,`remove`,o?`lease-lost`:`runtime-stale`,!0);try{return await t.queue.removeReserved({requestID:L(),scopeID:e.scopeID,revision:i.revision,item:{...e.item,rowVersion:i.rowVersion},token:i.token,generation:i.generation,runtime:r})?(a=!0,{status:`committed`,current:h.current,draftDurable:!0,queueDurablyRemoved:!0,attachmentIssues:[],diagnostics:[]}):Xl(`queue-retained`,`remove`,`remove-rejected`,!0)}catch{return Xl(`queue-retained`,`remove`,`remove-failed`,!0)}}catch{return o?Xl(`materialize-failed`,`identity`,`lease-lost`):Xl(`materialize-failed`,`attachments`,`download-failed`)}finally{clearInterval(d),s.abort(),await f()}})();return n.set(i,o),o.finally(()=>{n.get(i)===o&&n.delete(i)}),o}}})(),nu=e=>tu.editServerQueueItemIntoDraft(e),ru=[],iu=(e,t=Rr(),n=An())=>{let r=(0,Z.useMemo)(()=>({transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID}),[e.directory,e.sessionID,e.transportIdentity]),i=(0,Z.useMemo)(()=>e=>b(e,{state:`bound`,...r}),[r]),a=C(i),o=(0,Z.useMemo)(()=>{let e,i,o,s={admit:t.admit,edit:t.edit,remove:t.remove,reorder:t.reorder,manualSend:t.manualSend,refresh:t.refresh,runShadowImport:t.runShadowImport,captureRuntime:t.captureRuntime,stageAdmission:t.stageAdmission,unstageAdmission:t.unstageAdmission,editIntoDraft:nu};return{subscribe:e=>{let i=t.subscribeScope(r,e),a=n.subscribe(e);return()=>{i(),a()}},getSnapshot:()=>{let c=t.getState(),l=t.captureRuntime(),u=t.getScope(r),d=t.getPendingAdmissions(r),f=n.getSnapshot(),p=e?.runtimeCapture.transportIdentity===l.transportIdentity&&e.runtimeCapture.generation===l.generation?e.runtimeCapture:l,m=c.transportIdentity===r.transportIdentity&&c.capability===`available`&&(c.authority===`active`||c.authority===`paused`),h=f.ownership===`legacy-unsupported`?`legacy`:f.ownership===`server-active`||f.ownership===`server-paused`||f.ownership===`probing`&&m?`server`:`frozen`,g=h===`server`&&d.length>0,_=h===`server`&&d.some(e=>e.phase===`uploading`||e.phase===`admitting`||e.phase===`ambiguous`),v=e?.mode===h&&e.scope===u&&e.hasPendingAdmission===g&&e.hasBlockingAdmission===_&&d===i&&a===o?e.items:h===`server`?d.length?[...u?.items??ru,...d.filter(e=>!u?.items.some(t=>t.queueItemID===e.queueItemID))]:u?.items??d:h===`frozen`?a:ru;return e?.runtimeCapture===p&&e.capability===c.capability&&e.authority===c.authority&&e.mode===h&&e.importState===c.importState&&e.hydration===c.hydration&&e.scope===u&&e.items===v&&e.hasPendingAdmission===g&&e.hasBlockingAdmission===_?e:(i=d,o=a,e={runtimeCapture:p,capability:c.capability,authority:c.authority,mode:h,importState:c.importState,hydration:c.hydration,scope:u,items:v,hasPendingAdmission:g,hasBlockingAdmission:_,actions:s},e)}}},[n,a,t,r]);return(0,Z.useSyncExternalStore)(o.subscribe,o.getSnapshot,o.getSnapshot)},au=e=>{let t=(0,Q.c)(38),{value:n,options:r,disabled:i,onChange:a}=e,{t:o}=st(),s;t[0]!==o||t[1]!==n?(s=n||o(`rightSidebar.contextNotesTodo.sendDialog.variant.default`),t[0]=o,t[1]=n,t[2]=s):s=t[2];let c=s,l=i?`cursor-not-allowed opacity-60`:`cursor-pointer hover:bg-interactive-hover/30`,u;t[3]===l?u=t[4]:(u=Y(`flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2`,l),t[3]=l,t[4]=u);let d;t[5]===c?d=t[6]:(d=(0,$.jsx)(`span`,{className:`typography-micro whitespace-nowrap font-medium capitalize`,children:c}),t[5]=c,t[6]=d);let f;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0 text-muted-foreground`}),t[7]=f):f=t[7];let p;t[8]!==u||t[9]!==d?(p=(0,$.jsxs)(`div`,{className:u,children:[d,f]}),t[8]=u,t[9]=d,t[10]=p):p=t[10];let m=p;if(i)return m;let h;t[11]===m?h=t[12]:(h=(0,$.jsx)(qa,{asChild:!0,children:m}),t[11]=m,t[12]=h);let g;t[13]===a?g=t[14]:(g=()=>a(``),t[13]=a,t[14]=g);let _=!n&&`text-primary`,v;t[15]===_?v=t[16]:(v=Y(`font-medium`,_),t[15]=_,t[16]=v);let y;t[17]===o?y=t[18]:(y=o(`rightSidebar.contextNotesTodo.sendDialog.variant.default`),t[17]=o,t[18]=y);let b;t[19]!==v||t[20]!==y?(b=(0,$.jsx)(`span`,{className:v,children:y}),t[19]=v,t[20]=y,t[21]=b):b=t[21];let x;t[22]!==b||t[23]!==g?(x=(0,$.jsx)(ao,{className:`typography-meta`,onSelect:g,children:b}),t[22]=b,t[23]=g,t[24]=x):x=t[24];let S;if(t[25]!==a||t[26]!==r||t[27]!==n){let e;t[29]!==a||t[30]!==n?(e=e=>(0,$.jsx)(ao,{className:`typography-meta`,onSelect:()=>a(e),children:(0,$.jsx)(`span`,{className:Y(`font-medium capitalize`,n===e&&`text-primary`),children:e})},e),t[29]=a,t[30]=n,t[31]=e):e=t[31],S=r.map(e),t[25]=a,t[26]=r,t[27]=n,t[28]=S}else S=t[28];let C;t[32]!==x||t[33]!==S?(C=(0,$.jsxs)(Ka,{align:`start`,className:`max-w-[220px]`,portalToBody:!0,children:[x,S]}),t[32]=x,t[33]=S,t[34]=C):C=t[34];let w;return t[35]!==C||t[36]!==h?(w=(0,$.jsxs)(Ua,{children:[h,C]}),t[35]=C,t[36]=h,t[37]=w):w=t[37],w},ou=e=>({providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,generateHandoff:!0,autoReview:!1});function su(e){let t=(0,Q.c)(161),{open:n,onOpenChange:r,projectDirectory:i,submitting:a,onConfirm:o}=e,s=a!==void 0&&a,{t:c}=st(),l=mi(_u),u=mi(gu),d=vr(hu),f=mi(mu),p=mi(pu),m=mi(fu),h=mi(du),g=mi(uu),_;t[0]!==g||t[1]!==m||t[2]!==p||t[3]!==h?(_=()=>ou({providerID:p,modelID:m,variant:h,agent:g}),t[0]=g,t[1]=m,t[2]=p,t[3]=h,t[4]=_):_=t[4];let[v,y]=Z.useState(_),b,x;t[5]!==d||t[6]!==u||t[7]!==l||t[8]!==n||t[9]!==i?(b=()=>{n&&(l({directory:i,source:`reviewFlowDialog`}),u({directory:i}),d())},x=[n,l,u,d,i],t[5]=d,t[6]=u,t[7]=l,t[8]=n,t[9]=i,t[10]=b,t[11]=x):(b=t[10],x=t[11]),Z.useEffect(b,x);let S,C;t[12]!==g||t[13]!==m||t[14]!==p||t[15]!==h||t[16]!==n?(S=()=>{n&&y(ou({providerID:p,modelID:m,variant:h,agent:g}))},C=[n,p,m,h,g],t[12]=g,t[13]=m,t[14]=p,t[15]=h,t[16]=n,t[17]=S,t[18]=C):(S=t[17],C=t[18]),Z.useEffect(S,C);let w,T;t[19]!==v.modelID||t[20]!==v.providerID||t[21]!==n||t[22]!==f?(w=()=>{if(!n||f.length===0)return;let e=f.find(e=>e.id===v.providerID)??f[0],t=Array.isArray(e?.models)?e.models:[],r=t.some(e=>e.id===v.modelID),i=t[0]?.id??``;e?.id===v.providerID&&r||y(t=>({...t,providerID:e?.id??``,modelID:r?t.modelID:i,variant:``}))},T=[n,f,v.providerID,v.modelID],t[19]=v.modelID,t[20]=v.providerID,t[21]=n,t[22]=f,t[23]=w,t[24]=T):(w=t[23],T=t[24]),Z.useEffect(w,T);let E=lu,D;if(t[25]!==v.modelID||t[26]!==v.providerID||t[27]!==f){let e;t[29]===v.providerID?e=t[30]:(e=e=>e.id===v.providerID,t[29]=v.providerID,t[30]=e),D=f.find(e)?.models?.find(e=>e.id===v.modelID),t[25]=v.modelID,t[26]=v.providerID,t[27]=f,t[28]=D}else D=t[28];let O=D,k;t[31]===O?k=t[32]:(k=O?.variants?Object.keys(O.variants):[],t[31]=O,t[32]=k);let A=k,j=A.length>0,M,N;t[33]!==v.variant||t[34]!==j?(M=()=>{j||!v.variant||y(cu)},N=[j,v.variant],t[33]=v.variant,t[34]=j,t[35]=M,t[36]=N):(M=t[35],N=t[36]),Z.useEffect(M,N);let P;t[37]!==v.modelID||t[38]!==v.providerID?(P=v.providerID.trim().length>0&&v.modelID.trim().length>0,t[37]=v.modelID,t[38]=v.providerID,t[39]=P):P=t[39];let F=P,I;t[40]!==F||t[41]!==v||t[42]!==o||t[43]!==s?(I=()=>{!F||s||o(v)},t[40]=F,t[41]=v,t[42]=o,t[43]=s,t[44]=I):I=t[44];let L=I,R,z;t[45]!==L||t[46]!==n?(R=()=>{if(!n)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),L())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},z=[n,L],t[45]=L,t[46]=n,t[47]=R,t[48]=z):(R=t[47],z=t[48]),Z.useEffect(R,z);let B;t[49]!==r||t[50]!==s?(B=e=>{s||r(e)},t[49]=r,t[50]=s,t[51]=B):B=t[51];let V;t[52]===c?V=t[53]:(V=c(`diffView.reviewDialog.title`),t[52]=c,t[53]=V);let H;t[54]===V?H=t[55]:(H=(0,$.jsx)(aa,{children:V}),t[54]=V,t[55]=H);let U;t[56]===c?U=t[57]:(U=c(`diffView.reviewDialog.description`),t[56]=c,t[57]=U);let ee;t[58]===U?ee=t[59]:(ee=(0,$.jsx)(oa,{children:U}),t[58]=U,t[59]=ee);let te;t[60]!==H||t[61]!==ee?(te=(0,$.jsxs)(na,{children:[H,ee]}),t[60]=H,t[61]=ee,t[62]=te):te=t[62];let W;t[63]===c?W=t[64]:(W=c(`diffView.reviewDialog.info`),t[63]=c,t[64]=W);let G;t[65]===W?G=t[66]:(G=(0,$.jsx)(`div`,{className:`rounded-md border border-[color:color-mix(in_srgb,var(--status-info)_35%,var(--interactive-border))] bg-[color:color-mix(in_srgb,var(--status-info)_10%,var(--surface-background))] px-3 py-2 typography-meta text-foreground`,children:W}),t[65]=W,t[66]=G);let ne=v.generateHandoff,re;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(re=e=>y(t=>({...t,generateHandoff:e})),t[67]=re):re=t[67];let ie;t[68]===c?ie=t[69]:(ie=c(`diffView.reviewDialog.generateHandoff`),t[68]=c,t[69]=ie);let ae;t[70]!==v.generateHandoff||t[71]!==s||t[72]!==ie?(ae=(0,$.jsx)(ha,{checked:ne,onChange:re,disabled:s,ariaLabel:ie}),t[70]=v.generateHandoff,t[71]=s,t[72]=ie,t[73]=ae):ae=t[73];let oe;t[74]===c?oe=t[75]:(oe=c(`diffView.reviewDialog.generateHandoff`),t[74]=c,t[75]=oe);let se;t[76]===oe?se=t[77]:(se=(0,$.jsx)(`span`,{children:oe}),t[76]=oe,t[77]=se);let ce;t[78]!==ae||t[79]!==se?(ce=(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-ui-label text-foreground`,children:[ae,se]}),t[78]=ae,t[79]=se,t[80]=ce):ce=t[80];let le=v.autoReview,ue;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(ue=e=>y(t=>({...t,autoReview:e})),t[81]=ue):ue=t[81];let de;t[82]===c?de=t[83]:(de=c(`diffView.reviewDialog.autoReview`),t[82]=c,t[83]=de);let fe;t[84]!==v.autoReview||t[85]!==s||t[86]!==de?(fe=(0,$.jsx)(ha,{checked:le,onChange:ue,disabled:s,ariaLabel:de}),t[84]=v.autoReview,t[85]=s,t[86]=de,t[87]=fe):fe=t[87];let pe;t[88]===c?pe=t[89]:(pe=c(`diffView.reviewDialog.autoReview`),t[88]=c,t[89]=pe);let me;t[90]===pe?me=t[91]:(me=(0,$.jsx)(`span`,{children:pe}),t[90]=pe,t[91]=me);let he;t[92]!==fe||t[93]!==me?(he=(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-ui-label text-foreground`,children:[fe,me]}),t[92]=fe,t[93]=me,t[94]=he):he=t[94];let ge;t[95]===c?ge=t[96]:(ge=c(`chat.modelControls.model`),t[95]=c,t[96]=ge);let _e;t[97]===ge?_e=t[98]:(_e=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:ge}),t[97]=ge,t[98]=_e);let ve;t[99]===Symbol.for(`react.memo_cache_sentinel`)?(ve=(e,t)=>{y(n=>({...n,providerID:e,modelID:t,variant:``}))},t[99]=ve):ve=t[99];let ye;t[100]!==v.modelID||t[101]!==v.providerID?(ye=(0,$.jsx)(co,{providerId:v.providerID,modelId:v.modelID,className:`max-w-[320px] justify-between`,dropdownPortalToBody:!0,onChange:ve}),t[100]=v.modelID,t[101]=v.providerID,t[102]=ye):ye=t[102];let be;t[103]!==_e||t[104]!==ye?(be=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[_e,ye]}),t[103]=_e,t[104]=ye,t[105]=be):be=t[105];let xe;t[106]===c?xe=t[107]:(xe=c(`sessions.scheduledTasks.editor.thinkingLevel.label`),t[106]=c,t[107]=xe);let Se;t[108]===xe?Se=t[109]:(Se=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:xe}),t[108]=xe,t[109]=Se);let Ce=!j||s,we;t[110]===Symbol.for(`react.memo_cache_sentinel`)?(we=e=>y(t=>({...t,variant:e})),t[110]=we):we=t[110];let Te;t[111]!==v.variant||t[112]!==Ce||t[113]!==A?(Te=(0,$.jsx)(au,{value:v.variant,options:A,disabled:Ce,onChange:we}),t[111]=v.variant,t[112]=Ce,t[113]=A,t[114]=Te):Te=t[114];let Ee;t[115]!==Se||t[116]!==Te?(Ee=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[Se,Te]}),t[115]=Se,t[116]=Te,t[117]=Ee):Ee=t[117];let De;t[118]===c?De=t[119]:(De=c(`sessions.scheduledTasks.editor.agent.label`),t[118]=c,t[119]=De);let Oe;t[120]===De?Oe=t[121]:(Oe=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:De}),t[120]=De,t[121]=Oe);let ke;t[122]===Symbol.for(`react.memo_cache_sentinel`)?(ke=e=>y(t=>({...t,agent:e})),t[122]=ke):ke=t[122];let Ae;t[123]===v.agent?Ae=t[124]:(Ae=(0,$.jsx)(no,{agentName:v.agent,filter:E,dropdownPortalToBody:!0,onChange:ke}),t[123]=v.agent,t[124]=Ae);let je;t[125]!==Oe||t[126]!==Ae?(je=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[Oe,Ae]}),t[125]=Oe,t[126]=Ae,t[127]=je):je=t[127];let Me;t[128]!==G||t[129]!==ce||t[130]!==he||t[131]!==be||t[132]!==Ee||t[133]!==je?(Me=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[G,ce,he,be,Ee,je]}),t[128]=G,t[129]=ce,t[130]=he,t[131]=be,t[132]=Ee,t[133]=je,t[134]=Me):Me=t[134];let Ne;t[135]===r?Ne=t[136]:(Ne=()=>r(!1),t[135]=r,t[136]=Ne);let Pe;t[137]===c?Pe=t[138]:(Pe=c(`diffView.reviewDialog.actions.cancel`),t[137]=c,t[138]=Pe);let Fe;t[139]!==s||t[140]!==Ne||t[141]!==Pe?(Fe=(0,$.jsx)(la,{variant:`ghost`,size:`sm`,onClick:Ne,disabled:s,children:Pe}),t[139]=s,t[140]=Ne,t[141]=Pe,t[142]=Fe):Fe=t[142];let Ie=!F||s,Le;t[143]!==s||t[144]!==c?(Le=c(s?`diffView.reviewDialog.actions.starting`:`diffView.reviewDialog.actions.start`),t[143]=s,t[144]=c,t[145]=Le):Le=t[145];let Re;t[146]!==L||t[147]!==Ie||t[148]!==Le?(Re=(0,$.jsx)(la,{size:`sm`,onClick:L,disabled:Ie,children:Le}),t[146]=L,t[147]=Ie,t[148]=Le,t[149]=Re):Re=t[149];let ze;t[150]!==Fe||t[151]!==Re?(ze=(0,$.jsxs)(ra,{children:[Fe,Re]}),t[150]=Fe,t[151]=Re,t[152]=ze):ze=t[152];let Be;t[153]!==te||t[154]!==Me||t[155]!==ze?(Be=(0,$.jsxs)(ia,{className:`max-w-md overflow-visible`,children:[te,Me,ze]}),t[153]=te,t[154]=Me,t[155]=ze,t[156]=Be):Be=t[156];let Ve;return t[157]!==n||t[158]!==B||t[159]!==Be?(Ve=(0,$.jsx)(ca,{open:n,onOpenChange:B,children:Be}),t[157]=n,t[158]=B,t[159]=Be,t[160]=Ve):Ve=t[160],Ve}function cu(e){return{...e,variant:``}}function lu(e){return tr(e.mode)}function uu(e){return e.currentAgentName||``}function du(e){return e.currentVariant||``}function fu(e){return e.currentModelId}function pu(e){return e.currentProviderId}function mu(e){return e.providers}function hu(e){return e.loadAgents}function gu(e){return e.loadAgents}function _u(e){return e.loadProviders}var vu=new Set(`3d.3d_light.abap.abap_light.abc.abc_light.actionscript.actionscript_light.ada.ada_light.adobe-illustrator.adobe-illustrator_light.adobe-photoshop.adobe-photoshop_light.adobe-swc.adobe-swc_light.adonis.adonis_light.advpl.advpl_light.amplify.amplify_light.android.android_light.angular.angular_light.antlr.antlr_light.apiblueprint.apiblueprint_light.apollo.apollo_light.applescript.applescript_light.apps-script.apps-script_light.appveyor.appveyor_light.architecture.architecture_light.arduino.arduino_light.asciidoc.asciidoc_light.assembly.assembly_light.astro.astro_light.astro-config.astro-config_light.astyle.astyle_light.audio.audio_light.aurelia.aurelia_light.authors.authors_light.auto.auto_light.autohotkey.autohotkey_light.autoit.autoit_light.azure.azure_light.azure-pipelines.azure-pipelines_light.babel.babel_light.ballerina.ballerina_light.bazel.bazel_light.bbx.bbx_light.beancount.beancount_light.bench-js.bench-js_light.bench-jsx.bench-jsx_light.bench-ts.bench-ts_light.bibliography.bibliography_light.bibtex-style.bibtex-style_light.bicep.bicep_light.biome.biome_light.bitbucket.bitbucket_light.bithound.bithound_light.blender.blender_light.blink.blink_light.blitz.blitz_light.bower.bower_light.brainfuck.brainfuck_light.browserlist.browserlist_light.bruno.bruno_light.buck.buck_light.bucklescript.bucklescript_light.buildkite.buildkite_light.bun.bun_light.c.c_light.c3.c3_light.cabal.cabal_light.caddy.caddy_light.cadence.cadence_light.cairo.cairo_light.cake.cake_light.capacitor.capacitor_light.capnp.capnp_light.cbx.cbx_light.cds.cds_light.certificate.certificate_light.changelog.changelog_light.chess.chess_light.chrome.chrome_light.circleci.circleci_light.citation.citation_light.clangd.clangd_light.claude.claude_light.cline.cline_light.clojure.clojure_light.cloudfoundry.cloudfoundry_light.cmake.cmake_light.coala.coala_light.cobol.cobol_light.coconut.coconut_light.code-climate.code-climate_light.codecov.codecov_light.codeowners.codeowners_light.coderabbit-ai.coderabbit-ai_light.coffee.coffee_light.coldfusion.coldfusion_light.coloredpetrinets.coloredpetrinets_light.command.command_light.commitizen.commitizen_light.commitlint.commitlint_light.concourse.concourse_light.conduct.conduct_light.console.console_light.contentlayer.contentlayer_light.context.context_light.contributing.contributing_light.controller.controller_light.copilot.copilot_light.cpp.cpp_light.craco.craco_light.credits.credits_light.crystal.crystal_light.csharp.csharp_light.css.css_light.css-map.css-map_light.cucumber.cucumber_light.cuda.cuda_light.cursor.cursor_light.cypress.cypress_light.d.d_light.dart.dart_generated.dart_generated_light.dart_light.database.database_light.deepsource.deepsource_light.denizenscript.denizenscript_light.deno.deno_light.dependabot.dependabot_light.dependencies-update.dependencies-update_light.dhall.dhall_light.diff.diff_light.dinophp.dinophp_light.disc.disc_light.django.django_light.dll.dll_light.docker.docker_light.doctex-installer.doctex-installer_light.document.document_light.dotjs.dotjs_light.drawio.drawio_light.drizzle.drizzle_light.drone.drone_light.duc.duc_light.dune.dune_light.edge.edge_light.editorconfig.editorconfig_light.ejs.ejs_light.elixir.elixir_light.elm.elm_light.email.email_light.ember.ember_light.epub.epub_light.erlang.erlang_light.esbuild.esbuild_light.eslint.eslint_light.excalidraw.excalidraw_light.exe.exe_light.fastlane.fastlane_light.favicon.favicon_light.figma.figma_light.firebase.firebase_light.flash.flash_light.flow.flow_light.folder.folder_light.folder-admin.folder-admin_light.folder-admin-open.folder-admin-open_light.folder-android.folder-android_light.folder-android-open.folder-android-open_light.folder-angular.folder-angular_light.folder-angular-open.folder-angular-open_light.folder-animation.folder-animation_light.folder-animation-open.folder-animation-open_light.folder-ansible.folder-ansible_light.folder-ansible-open.folder-ansible-open_light.folder-api.folder-api_light.folder-api-open.folder-api-open_light.folder-apollo.folder-apollo_light.folder-apollo-open.folder-apollo-open_light.folder-app.folder-app_light.folder-app-open.folder-app-open_light.folder-archive.folder-archive_light.folder-archive-open.folder-archive-open_light.folder-astro.folder-astro_light.folder-astro-open.folder-astro-open_light.folder-atom.folder-atom_light.folder-atom-open.folder-atom-open_light.folder-attachment.folder-attachment_light.folder-attachment-open.folder-attachment-open_light.folder-audio.folder-audio_light.folder-audio-open.folder-audio-open_light.folder-aurelia.folder-aurelia_light.folder-aurelia-open.folder-aurelia-open_light.folder-aws.folder-aws_light.folder-aws-open.folder-aws-open_light.folder-azure-pipelines.folder-azure-pipelines_light.folder-azure-pipelines-open.folder-azure-pipelines-open_light.folder-backup.folder-backup_light.folder-backup-open.folder-backup-open_light.folder-base.folder-base_light.folder-base-open.folder-base-open_light.folder-batch.folder-batch_light.folder-batch-open.folder-batch-open_light.folder-benchmark.folder-benchmark_light.folder-benchmark-open.folder-benchmark-open_light.folder-bibliography.folder-bibliography_light.folder-bibliography-open.folder-bibliography-open_light.folder-bicep.folder-bicep_light.folder-bicep-open.folder-bicep-open_light.folder-blender.folder-blender_light.folder-blender-open.folder-blender-open_light.folder-bloc.folder-bloc_light.folder-bloc-open.folder-bloc-open_light.folder-bower.folder-bower_light.folder-bower-open.folder-bower-open_light.folder-buildkite.folder-buildkite_light.folder-buildkite-open.folder-buildkite-open_light.folder-cart.folder-cart_light.folder-cart-open.folder-cart-open_light.folder-changesets.folder-changesets_light.folder-changesets-open.folder-changesets-open_light.folder-ci.folder-ci_light.folder-ci-open.folder-ci-open_light.folder-circleci.folder-circleci_light.folder-circleci-open.folder-circleci-open_light.folder-class.folder-class_light.folder-class-open.folder-class-open_light.folder-claude.folder-claude_light.folder-claude-open.folder-claude-open_light.folder-client.folder-client_light.folder-client-open.folder-client-open_light.folder-cline.folder-cline_light.folder-cline-open.folder-cline-open_light.folder-cloud-functions.folder-cloud-functions_light.folder-cloud-functions-open.folder-cloud-functions-open_light.folder-cloudflare.folder-cloudflare_light.folder-cloudflare-open.folder-cloudflare-open_light.folder-cluster.folder-cluster_light.folder-cluster-open.folder-cluster-open_light.folder-cobol.folder-cobol_light.folder-cobol-open.folder-cobol-open_light.folder-command.folder-command_light.folder-command-open.folder-command-open_light.folder-components.folder-components_light.folder-components-open.folder-components-open_light.folder-config.folder-config_light.folder-config-open.folder-config-open_light.folder-connection.folder-connection_light.folder-connection-open.folder-connection-open_light.folder-console.folder-console_light.folder-console-open.folder-console-open_light.folder-constant.folder-constant_light.folder-constant-open.folder-constant-open_light.folder-container.folder-container_light.folder-container-open.folder-container-open_light.folder-content.folder-content_light.folder-content-open.folder-content-open_light.folder-context.folder-context_light.folder-context-open.folder-context-open_light.folder-contract.folder-contract_light.folder-contract-open.folder-contract-open_light.folder-controller.folder-controller_light.folder-controller-open.folder-controller-open_light.folder-core.folder-core_light.folder-core-open.folder-core-open_light.folder-coverage.folder-coverage_light.folder-coverage-open.folder-coverage-open_light.folder-css.folder-css_light.folder-css-open.folder-css-open_light.folder-cursor.folder-cursor_light.folder-cursor-open.folder-cursor-open_light.folder-custom.folder-custom_light.folder-custom-open.folder-custom-open_light.folder-cypress.folder-cypress_light.folder-cypress-open.folder-cypress-open_light.folder-dart.folder-dart_light.folder-dart-open.folder-dart-open_light.folder-database.folder-database_light.folder-database-open.folder-database-open_light.folder-debug.folder-debug_light.folder-debug-open.folder-debug-open_light.folder-decorators.folder-decorators_light.folder-decorators-open.folder-decorators-open_light.folder-delta.folder-delta_light.folder-delta-open.folder-delta-open_light.folder-desktop.folder-desktop_light.folder-desktop-open.folder-desktop-open_light.folder-directive.folder-directive_light.folder-directive-open.folder-directive-open_light.folder-dist.folder-dist_light.folder-dist-open.folder-dist-open_light.folder-docker.folder-docker_light.folder-docker-open.folder-docker-open_light.folder-docs.folder-docs_light.folder-docs-open.folder-docs-open_light.folder-download.folder-download_light.folder-download-open.folder-download-open_light.folder-drizzle.folder-drizzle_light.folder-drizzle-open.folder-drizzle-open_light.folder-dump.folder-dump_light.folder-dump-open.folder-dump-open_light.folder-element.folder-element_light.folder-element-open.folder-element-open_light.folder-enum.folder-enum_light.folder-enum-open.folder-enum-open_light.folder-environment.folder-environment_light.folder-environment-open.folder-environment-open_light.folder-error.folder-error_light.folder-error-open.folder-error-open_light.folder-event.folder-event_light.folder-event-open.folder-event-open_light.folder-examples.folder-examples_light.folder-examples-open.folder-examples-open_light.folder-expo.folder-expo_light.folder-expo-open.folder-expo-open_light.folder-export.folder-export_light.folder-export-open.folder-export-open_light.folder-fastlane.folder-fastlane_light.folder-fastlane-open.folder-fastlane-open_light.folder-favicon.folder-favicon_light.folder-favicon-open.folder-favicon-open_light.folder-firebase.folder-firebase_light.folder-firebase-open.folder-firebase-open_light.folder-firestore.folder-firestore_light.folder-firestore-open.folder-firestore-open_light.folder-flow.folder-flow_light.folder-flow-open.folder-flow-open_light.folder-flutter.folder-flutter_light.folder-flutter-open.folder-flutter-open_light.folder-font.folder-font_light.folder-font-open.folder-font-open_light.folder-forgejo.folder-forgejo_light.folder-forgejo-open.folder-forgejo-open_light.folder-functions.folder-functions_light.folder-functions-open.folder-functions-open_light.folder-gamemaker.folder-gamemaker_light.folder-gamemaker-open.folder-gamemaker-open_light.folder-generator.folder-generator_light.folder-generator-open.folder-generator-open_light.folder-gh-workflows.folder-gh-workflows_light.folder-gh-workflows-open.folder-gh-workflows-open_light.folder-git.folder-git_light.folder-git-open.folder-git-open_light.folder-gitea.folder-gitea_light.folder-gitea-open.folder-gitea-open_light.folder-github.folder-github_light.folder-github-open.folder-github-open_light.folder-gitlab.folder-gitlab_light.folder-gitlab-open.folder-gitlab-open_light.folder-global.folder-global_light.folder-global-open.folder-global-open_light.folder-godot.folder-godot_light.folder-godot-open.folder-godot-open_light.folder-gradle.folder-gradle_light.folder-gradle-open.folder-gradle-open_light.folder-graphql.folder-graphql_light.folder-graphql-open.folder-graphql-open_light.folder-guard.folder-guard_light.folder-guard-open.folder-guard-open_light.folder-gulp.folder-gulp_light.folder-gulp-open.folder-gulp-open_light.folder-helm.folder-helm_light.folder-helm-open.folder-helm-open_light.folder-helper.folder-helper_light.folder-helper-open.folder-helper-open_light.folder-home.folder-home_light.folder-home-open.folder-home-open_light.folder-hook.folder-hook_light.folder-hook-open.folder-hook-open_light.folder-husky.folder-husky_light.folder-husky-open.folder-husky-open_light.folder-i18n.folder-i18n_light.folder-i18n-open.folder-i18n-open_light.folder-images.folder-images_light.folder-images-open.folder-images-open_light.folder-import.folder-import_light.folder-import-open.folder-import-open_light.folder-include.folder-include_light.folder-include-open.folder-include-open_light.folder-intellij.folder-intellij_light.folder-intellij-open.folder-intellij-open_light.folder-interceptor.folder-interceptor_light.folder-interceptor-open.folder-interceptor-open_light.folder-interface.folder-interface_light.folder-interface-open.folder-interface-open_light.folder-ios.folder-ios_light.folder-ios-open.folder-ios-open_light.folder-java.folder-java_light.folder-java-open.folder-java-open_light.folder-javascript.folder-javascript_light.folder-javascript-open.folder-javascript-open_light.folder-jinja.folder-jinja_light.folder-jinja-open.folder-jinja-open_light.folder-job.folder-job_light.folder-job-open.folder-job-open_light.folder-json.folder-json_light.folder-json-open.folder-json-open_light.folder-jupyter.folder-jupyter_light.folder-jupyter-open.folder-jupyter-open_light.folder-keys.folder-keys_light.folder-keys-open.folder-keys-open_light.folder-kubernetes.folder-kubernetes_light.folder-kubernetes-open.folder-kubernetes-open_light.folder-kusto.folder-kusto_light.folder-kusto-open.folder-kusto-open_light.folder-layout.folder-layout_light.folder-layout-open.folder-layout-open_light.folder-lefthook.folder-lefthook_light.folder-lefthook-open.folder-lefthook-open_light.folder-less.folder-less_light.folder-less-open.folder-less-open_light.folder-lib.folder-lib_light.folder-lib-open.folder-lib-open_light.folder-link.folder-link_light.folder-link-open.folder-link-open_light.folder-linux.folder-linux_light.folder-linux-open.folder-linux-open_light.folder-liquibase.folder-liquibase_light.folder-liquibase-open.folder-liquibase-open_light.folder-log.folder-log_light.folder-log-open.folder-log-open_light.folder-lottie.folder-lottie_light.folder-lottie-open.folder-lottie-open_light.folder-lua.folder-lua_light.folder-lua-open.folder-lua-open_light.folder-luau.folder-luau_light.folder-luau-open.folder-luau-open_light.folder-macos.folder-macos_light.folder-macos-open.folder-macos-open_light.folder-mail.folder-mail_light.folder-mail-open.folder-mail-open_light.folder-mappings.folder-mappings_light.folder-mappings-open.folder-mappings-open_light.folder-markdown.folder-markdown_light.folder-markdown-open.folder-markdown-open_light.folder-mercurial.folder-mercurial_light.folder-mercurial-open.folder-mercurial-open_light.folder-messages.folder-messages_light.folder-messages-open.folder-messages-open_light.folder-meta.folder-meta_light.folder-meta-open.folder-meta-open_light.folder-middleware.folder-middleware_light.folder-middleware-open.folder-middleware-open_light.folder-mjml.folder-mjml_light.folder-mjml-open.folder-mjml-open_light.folder-mobile.folder-mobile_light.folder-mobile-open.folder-mobile-open_light.folder-mock.folder-mock_light.folder-mock-open.folder-mock-open_light.folder-mojo.folder-mojo_light.folder-mojo-open.folder-mojo-open_light.folder-molecule.folder-molecule_light.folder-molecule-open.folder-molecule-open_light.folder-moon.folder-moon_light.folder-moon-open.folder-moon-open_light.folder-netlify.folder-netlify_light.folder-netlify-open.folder-netlify-open_light.folder-next.folder-next_light.folder-next-open.folder-next-open_light.folder-ngrx-store.folder-ngrx-store_light.folder-ngrx-store-open.folder-ngrx-store-open_light.folder-node.folder-node_light.folder-node-open.folder-node-open_light.folder-nuxt.folder-nuxt_light.folder-nuxt-open.folder-nuxt-open_light.folder-obsidian.folder-obsidian_light.folder-obsidian-open.folder-obsidian-open_light.folder-open.folder-open_light.folder-organism.folder-organism_light.folder-organism-open.folder-organism-open_light.folder-other.folder-other_light.folder-other-open.folder-other-open_light.folder-packages.folder-packages_light.folder-packages-open.folder-packages-open_light.folder-pdf.folder-pdf_light.folder-pdf-open.folder-pdf-open_light.folder-pdm.folder-pdm_light.folder-pdm-open.folder-pdm-open_light.folder-php.folder-php_light.folder-php-open.folder-php-open_light.folder-phpmailer.folder-phpmailer_light.folder-phpmailer-open.folder-phpmailer-open_light.folder-pipe.folder-pipe_light.folder-pipe-open.folder-pipe-open_light.folder-plastic.folder-plastic_light.folder-plastic-open.folder-plastic-open_light.folder-plugin.folder-plugin_light.folder-plugin-open.folder-plugin-open_light.folder-policy.folder-policy_light.folder-policy-open.folder-policy-open_light.folder-powershell.folder-powershell_light.folder-powershell-open.folder-powershell-open_light.folder-prisma.folder-prisma_light.folder-prisma-open.folder-prisma-open_light.folder-private.folder-private_light.folder-private-open.folder-private-open_light.folder-project.folder-project_light.folder-project-open.folder-project-open_light.folder-prompts.folder-prompts_light.folder-prompts-open.folder-prompts-open_light.folder-proto.folder-proto_light.folder-proto-open.folder-proto-open_light.folder-public.folder-public_light.folder-public-open.folder-public-open_light.folder-python.folder-python_light.folder-python-open.folder-python-open_light.folder-pytorch.folder-pytorch_light.folder-pytorch-open.folder-pytorch-open_light.folder-quasar.folder-quasar_light.folder-quasar-open.folder-quasar-open_light.folder-queue.folder-queue_light.folder-queue-open.folder-queue-open_light.folder-react-components.folder-react-components_light.folder-react-components-open.folder-react-components-open_light.folder-redux-reducer.folder-redux-reducer_light.folder-redux-reducer-open.folder-redux-reducer-open_light.folder-repository.folder-repository_light.folder-repository-open.folder-repository-open_light.folder-resolver.folder-resolver_light.folder-resolver-open.folder-resolver-open_light.folder-resource.folder-resource_light.folder-resource-open.folder-resource-open_light.folder-review.folder-review_light.folder-review-open.folder-review-open_light.folder-robot.folder-robot_light.folder-robot-open.folder-robot-open_light.folder-routes.folder-routes_light.folder-routes-open.folder-routes-open_light.folder-rules.folder-rules_light.folder-rules-open.folder-rules-open_light.folder-rust.folder-rust_light.folder-rust-open.folder-rust-open_light.folder-sandbox.folder-sandbox_light.folder-sandbox-open.folder-sandbox-open_light.folder-sass.folder-sass_light.folder-sass-open.folder-sass-open_light.folder-scala.folder-scala_light.folder-scala-open.folder-scala-open_light.folder-scons.folder-scons_light.folder-scons-open.folder-scons-open_light.folder-scripts.folder-scripts_light.folder-scripts-open.folder-scripts-open_light.folder-secure.folder-secure_light.folder-secure-open.folder-secure-open_light.folder-seeders.folder-seeders_light.folder-seeders-open.folder-seeders-open_light.folder-server.folder-server_light.folder-server-open.folder-server-open_light.folder-serverless.folder-serverless_light.folder-serverless-open.folder-serverless-open_light.folder-shader.folder-shader_light.folder-shader-open.folder-shader-open_light.folder-shared.folder-shared_light.folder-shared-open.folder-shared-open_light.folder-snapcraft.folder-snapcraft_light.folder-snapcraft-open.folder-snapcraft-open_light.folder-snippet.folder-snippet_light.folder-snippet-open.folder-snippet-open_light.folder-src.folder-src_light.folder-src-open.folder-src-open_light.folder-src-tauri.folder-src-tauri_light.folder-src-tauri-open.folder-src-tauri-open_light.folder-stack.folder-stack_light.folder-stack-open.folder-stack-open_light.folder-stencil.folder-stencil_light.folder-stencil-open.folder-stencil-open_light.folder-store.folder-store_light.folder-store-open.folder-store-open_light.folder-storybook.folder-storybook_light.folder-storybook-open.folder-storybook-open_light.folder-stylus.folder-stylus_light.folder-stylus-open.folder-stylus-open_light.folder-sublime.folder-sublime_light.folder-sublime-open.folder-sublime-open_light.folder-supabase.folder-supabase_light.folder-supabase-open.folder-supabase-open_light.folder-svelte.folder-svelte_light.folder-svelte-open.folder-svelte-open_light.folder-svg.folder-svg_light.folder-svg-open.folder-svg-open_light.folder-syntax.folder-syntax_light.folder-syntax-open.folder-syntax-open_light.folder-target.folder-target_light.folder-target-open.folder-target-open_light.folder-taskfile.folder-taskfile_light.folder-taskfile-open.folder-taskfile-open_light.folder-tasks.folder-tasks_light.folder-tasks-open.folder-tasks-open_light.folder-television.folder-television_light.folder-television-open.folder-television-open_light.folder-temp.folder-temp_light.folder-temp-open.folder-temp-open_light.folder-template.folder-template_light.folder-template-open.folder-template-open_light.folder-terraform.folder-terraform_light.folder-terraform-open.folder-terraform-open_light.folder-test.folder-test_light.folder-test-open.folder-test-open_light.folder-theme.folder-theme_light.folder-theme-open.folder-theme-open_light.folder-tools.folder-tools_light.folder-tools-open.folder-tools-open_light.folder-trash.folder-trash_light.folder-trash-open.folder-trash-open_light.folder-trigger.folder-trigger_light.folder-trigger-open.folder-trigger-open_light.folder-turborepo.folder-turborepo_light.folder-turborepo-open.folder-turborepo-open_light.folder-typescript.folder-typescript_light.folder-typescript-open.folder-typescript-open_light.folder-ui.folder-ui_light.folder-ui-open.folder-ui-open_light.folder-unity.folder-unity_light.folder-unity-open.folder-unity-open_light.folder-update.folder-update_light.folder-update-open.folder-update-open_light.folder-upload.folder-upload_light.folder-upload-open.folder-upload-open_light.folder-utils.folder-utils_light.folder-utils-open.folder-utils-open_light.folder-vercel.folder-vercel_light.folder-vercel-open.folder-vercel-open_light.folder-verdaccio.folder-verdaccio_light.folder-verdaccio-open.folder-verdaccio-open_light.folder-video.folder-video_light.folder-video-open.folder-video-open_light.folder-views.folder-views_light.folder-views-open.folder-views-open_light.folder-vm.folder-vm_light.folder-vm-open.folder-vm-open_light.folder-vscode.folder-vscode_light.folder-vscode-open.folder-vscode-open_light.folder-vue.folder-vue_light.folder-vue-directives.folder-vue-directives_light.folder-vue-directives-open.folder-vue-directives-open_light.folder-vue-open.folder-vue-open_light.folder-vuepress.folder-vuepress_light.folder-vuepress-open.folder-vuepress-open_light.folder-vuex-store.folder-vuex-store_light.folder-vuex-store-open.folder-vuex-store-open_light.folder-wakatime.folder-wakatime_light.folder-wakatime-open.folder-wakatime-open_light.folder-webpack.folder-webpack_light.folder-webpack-open.folder-webpack-open_light.folder-windows.folder-windows_light.folder-windows-open.folder-windows-open_light.folder-wordpress.folder-wordpress_light.folder-wordpress-open.folder-wordpress-open_light.folder-yarn.folder-yarn_light.folder-yarn-open.folder-yarn-open_light.folder-zeabur.folder-zeabur_light.folder-zeabur-open.folder-zeabur-open_light.font.font_light.forth.forth_light.fortran.fortran_light.foxpro.foxpro_light.freemarker.freemarker_light.fsharp.fsharp_light.fusebox.fusebox_light.gamemaker.gamemaker_light.garden.garden_light.gatsby.gatsby_light.gcp.gcp_light.gemfile.gemfile_light.gemini.gemini_light.gemini-ai.gemini-ai_light.git.git_light.github-actions-workflow.github-actions-workflow_light.github-sponsors.github-sponsors_light.gitlab.gitlab_light.gitpod.gitpod_light.gleam.gleam_light.gnuplot.gnuplot_light.go.go_gopher.go_gopher_light.go_light.go-mod.go-mod_light.godot.godot_light.godot-assets.godot-assets_light.gradle.gradle_light.grafana-alloy.grafana-alloy_light.grain.grain_light.graphcool.graphcool_light.graphql.graphql_light.gridsome.gridsome_light.groovy.groovy_light.grunt.grunt_light.gulp.gulp_light.h.h_light.hack.hack_light.hadolint.hadolint_light.haml.haml_light.handlebars.handlebars_light.hardhat.hardhat_light.harmonix.harmonix_light.haskell.haskell_light.haxe.haxe_light.hcl.hcl_light.helm.helm_light.heroku.heroku_light.hex.hex_light.histoire.histoire_light.hjson.hjson_light.horusec.horusec_light.hosts.hosts_light.hpp.hpp_light.html.html_light.http.http_light.huff.huff_light.hurl.hurl_light.husky.husky_light.i18n.i18n_light.idris.idris_light.ifanr-cloud.ifanr-cloud_light.image.image_light.imba.imba_light.installation.installation_light.ionic.ionic_light.istanbul.istanbul_light.jar.jar_light.java.java_light.javaclass.javaclass_light.javascript.javascript_light.javascript-map.javascript-map_light.jenkins.jenkins_light.jest.jest_light.jinja.jinja_light.jsconfig.jsconfig_light.json.json_light.jsr.jsr_light.julia.julia_light.jupyter.jupyter_light.just.just_light.karma.karma_light.kcl.kcl_light.key.key_light.keystatic.keystatic_light.kivy.kivy_light.kl.kl_light.knip.knip_light.kotlin.kotlin_light.kubernetes.kubernetes_light.kusto.kusto_light.label.label_light.laravel.laravel_light.latexmk.latexmk_light.lbx.lbx_light.lefthook.lefthook_light.lerna.lerna_light.less.less_light.liara.liara_light.lib.lib_light.lighthouse.lighthouse_light.lilypond.lilypond_light.lintstaged.lintstaged_light.liquid.liquid_light.lisp.lisp_light.livescript.livescript_light.lock.lock_light.log.log_light.lolcode.lolcode_light.lottie.lottie_light.lua.lua_light.luau.luau_light.lyric.lyric_light.makefile.makefile_light.markdoc.markdoc_light.markdoc-config.markdoc-config_light.markdown.markdown_light.markdownlint.markdownlint_light.markojs.markojs_light.mathematica.mathematica_light.matlab.matlab_light.maven.maven_light.mdsvex.mdsvex_light.mdx.mdx_light.mercurial.mercurial_light.merlin.merlin_light.mermaid.mermaid_light.meson.meson_light.minecraft.minecraft_light.minecraft-fabric.minecraft-fabric_light.mint.mint_light.mjml.mjml_light.mocha.mocha_light.modernizr.modernizr_light.mojo.mojo_light.moon.moon_light.moonscript.moonscript_light.mxml.mxml_light.nano-staged.nano-staged_light.ndst.ndst_light.nest.nest_light.netlify.netlify_light.next.next_light.nginx.nginx_light.ngrx-actions.ngrx-actions_light.ngrx-effects.ngrx-effects_light.ngrx-entity.ngrx-entity_light.ngrx-reducer.ngrx-reducer_light.ngrx-selectors.ngrx-selectors_light.ngrx-state.ngrx-state_light.nim.nim_light.nix.nix_light.nodejs.nodejs_alt.nodejs_alt_light.nodejs_light.nodemon.nodemon_light.npm.npm_light.nuget.nuget_light.nunjucks.nunjucks_light.nuxt.nuxt_light.nx.nx_light.objective-c.objective-c_light.objective-cpp.objective-cpp_light.ocaml.ocaml_light.odin.odin_light.opa.opa_light.opam.opam_light.openapi.openapi_light.otne.otne_light.oxlint.oxlint_light.packship.packship_light.palette.palette_light.panda.panda_light.parcel.parcel_light.pascal.pascal_light.pawn.pawn_light.payload.payload_light.pdf.pdf_light.pdm.pdm_light.percy.percy_light.perl.perl_light.php.php_elephant.php_elephant_light.php_elephant_pink.php_elephant_pink_light.php_light.php-cs-fixer.php-cs-fixer_light.phpstan.phpstan_light.phpunit.phpunit_light.pinejs.pinejs_light.pipeline.pipeline_light.pkl.pkl_light.plastic.plastic_light.playwright.playwright_light.plop.plop_light.pm2-ecosystem.pm2-ecosystem_light.pnpm.pnpm_light.poetry.poetry_light.postcss.postcss_light.posthtml.posthtml_light.powerpoint.powerpoint_light.powershell.powershell_light.pre-commit.pre-commit_light.prettier.prettier_light.prisma.prisma_light.processing.processing_light.prolog.prolog_light.prompt.prompt_light.proto.proto_light.protractor.protractor_light.pug.pug_light.puppet.puppet_light.puppeteer.puppeteer_light.purescript.purescript_light.python.python_light.python-misc.python-misc_light.pytorch.pytorch_light.qsharp.qsharp_light.quarto.quarto_light.quasar.quasar_light.quokka.quokka_light.qwik.qwik_light.r.r_light.racket.racket_light.raml.raml_light.razor.razor_light.rbxmk.rbxmk_light.rc.rc_light.react.react_light.react_ts.react_ts_light.readme.readme_light.reason.reason_light.red.red_light.redux-action.redux-action_light.redux-reducer.redux-reducer_light.redux-selector.redux-selector_light.redux-store.redux-store_light.regedit.regedit_light.remark.remark_light.remix.remix_light.renovate.renovate_light.replit.replit_light.rescript.rescript_light.rescript-interface.rescript-interface_light.restql.restql_light.riot.riot_light.roadmap.roadmap_light.roblox.roblox_light.robot.robot_light.robots.robots_light.rocket.rocket_light.rojo.rojo_light.rollup.rollup_light.rome.rome_light.routing.routing_light.rspec.rspec_light.rubocop.rubocop_light.ruby.ruby_light.ruff.ruff_light.rust.rust_light.salesforce.salesforce_light.san.san_light.sas.sas_light.sass.sass_light.sbt.sbt_light.scala.scala_light.scheme.scheme_light.scons.scons_light.screwdriver.screwdriver_light.search.search_light.semantic-release.semantic-release_light.semgrep.semgrep_light.sentry.sentry_light.sequelize.sequelize_light.serverless.serverless_light.settings.settings_light.shader.shader_light.silverstripe.silverstripe_light.simulink.simulink_light.siyuan.siyuan_light.sketch.sketch_light.slim.slim_light.slint.slint_light.slug.slug_light.smarty.smarty_light.sml.sml_light.snakemake.snakemake_light.snapcraft.snapcraft_light.snowpack.snowpack_light.snyk.snyk_light.solidity.solidity_light.sonarcloud.sonarcloud_light.spwn.spwn_light.stackblitz.stackblitz_light.stan.stan_light.steadybit.steadybit_light.stencil.stencil_light.stitches.stitches_light.storybook.storybook_light.stryker.stryker_light.stylable.stylable_light.stylelint.stylelint_light.stylus.stylus_light.sublime.sublime_light.subtitles.subtitles_light.supabase.supabase_light.svelte.svelte_light.svg.svg_light.svgo.svgo_light.svgr.svgr_light.swagger.swagger_light.sway.sway_light.swc.swc_light.swift.swift_light.syncpack.syncpack_light.systemd.systemd_light.table.table_light.tailwindcss.tailwindcss_light.taskfile.taskfile_light.tauri.tauri_light.taze.taze_light.tcl.tcl_light.teal.teal_light.templ.templ_light.template.template_light.terraform.terraform_light.test-js.test-js_light.test-jsx.test-jsx_light.test-ts.test-ts_light.tex.tex_light.textlint.textlint_light.tilt.tilt_light.tldraw.tldraw_light.tobi.tobi_light.tobimake.tobimake_light.todo.todo_light.toml.toml_light.travis.travis_light.tree.tree_light.trigger.trigger_light.tsconfig.tsconfig_light.tsdoc.tsdoc_light.tsil.tsil_light.tune.tune_light.turborepo.turborepo_light.twig.twig_light.twine.twine_light.typescript.typescript_light.typescript-def.typescript-def_light.typst.typst_light.umi.umi_light.uml.uml_light.unity.unity_light.unocss.unocss_light.url.url_light.uv.uv_light.vagrant.vagrant_light.vala.vala_light.vanilla-extract.vanilla-extract_light.varnish.varnish_light.vedic.vedic_light.velite.velite_light.velocity.velocity_light.vercel.vercel_light.verdaccio.verdaccio_light.verified.verified_light.verilog.verilog_light.vfl.vfl_light.video.video_light.vim.vim_light.virtual.virtual_light.visualstudio.visualstudio_light.vite.vite_light.vitest.vitest_light.vlang.vlang_light.vscode.vscode_light.vue.vue_light.vue-config.vue-config_light.vuex-store.vuex-store_light.wakatime.wakatime_light.wallaby.wallaby_light.wally.wally_light.watchman.watchman_light.webassembly.webassembly_light.webhint.webhint_light.webpack.webpack_light.wepy.wepy_light.werf.werf_light.windicss.windicss_light.wolframlanguage.wolframlanguage_light.word.word_light.wrangler.wrangler_light.wxt.wxt_light.xaml.xaml_light.xmake.xmake_light.xml.xml_light.yaml.yaml_light.yang.yang_light.yarn.yarn_light.zeabur.zeabur_light.zig.zig_light.zip.zip_light`.split(`.`)),yu=`<?xml version="1.0" encoding="UTF-8"?>
8
+ `)}function Jl(e,t){if(t.length===0)return e;let n=ql(t);return e.trim()?`${e}\n\n${n}`:n}var Yl={queue:Lr(),input:It.getState(),download:In,current:e=>Lr().captureRuntime().transportIdentity===e.transportIdentity&&Lr().captureRuntime().generation===e.generation},Xl=(e,t,n,r=!1)=>({status:e,current:!1,draftDurable:r,queueDurablyRemoved:!1,attachmentIssues:[],diagnostics:[{stage:t,code:n}]}),Zl=e=>JSON.stringify(e),Ql=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),$l=52428800,eu=4,tu=((e={})=>{let t={...Yl,...e},n=new Map;return{editServerQueueItemIntoDraft:e=>{let r;try{r=t.queue.captureRuntime()}catch{return Promise.resolve(Xl(`materialize-failed`,`identity`,`runtime-capture-failed`))}let i=`${r.transportIdentity}\u0000${r.generation}\u0000${e.scopeID}\u0000${e.item.queueItemID}`,a=n.get(i);if(a)return a;let o=(async()=>{let n=t.input.captureDraftRuntime();if(r.transportIdentity!==n.transportIdentity||r.generation!==n.generation||e.targetKey.transportIdentity!==r.transportIdentity)return Xl(`materialize-failed`,`identity`,`runtime-mismatch`);if((e.item.attachmentIssues?.length??0)>0)return{...Xl(`materialize-failed`,`attachments`,`attachment-issues`),attachmentIssues:e.item.attachmentIssues};let i;try{i=await t.queue.reserveEdit({requestID:L(),scopeID:e.scopeID,revision:e.scopeRevision,item:e.item,owner:`ui-edit`,ttlMs:6e4,runtime:r})}catch{return Xl(`materialize-failed`,`materialize`,`reserve-failed`)}if(!i)return Xl(`materialize-failed`,`materialize`,`reserve-rejected`);let a=!1,o=!1,s=new AbortController,c,l=()=>{o=!0,s.abort()},u=()=>{if(o)return Promise.resolve(!1);if(c)return c;let n=(async()=>{try{let n=await t.queue.renewEdit({item:e.item,token:i.token,generation:i.generation,ttlMs:6e4,runtime:r,signal:s.signal});return!n||n.queueItemID!==e.item.queueItemID||n.token!==i.token||n.generation!==i.generation||!Number.isSafeInteger(n.expiresAt)||Date.now()>=n.expiresAt||!t.current(r)?(l(),!1):!0}catch{return l(),!1}finally{c=void 0}})();return c=n,n},d=setInterval(()=>{u()},2e4),f=async()=>{if(!a){a=!0;try{await t.queue.releaseEdit({item:e.item,token:i.token,runtime:r})}catch{return}}};try{if(!t.current(r)||o)return Xl(`materialize-failed`,`identity`,o?`lease-lost`:`runtime-stale`);let c=e.item.attachments??[];if(new Set(c.map(e=>Zl(e.occurrenceRefID))).size!==c.length)return Xl(`materialize-failed`,`attachments`,`duplicate-occurrence`);if(c.reduce((e,t)=>e+t.size,0)>$l)return Xl(`materialize-failed`,`attachments`,`attachments-too-large`);let l=Array(c.length),d=0;if(await Promise.all(Array.from({length:Math.min(eu,c.length)},async()=>{for(;!s.signal.aborted;){let n=d++;if(n>=c.length)return;let r=c[n];l[n]={attachment:r,blob:await t.download(e.item.queueItemID,r,s.signal)}}})),!t.current(r)||o)return Xl(`materialize-failed`,`identity`,o?`lease-lost`:`runtime-stale`);let f=[],p=new Map,m=new Map;for(let e=0;e<c.length;e++){let t=c[e],n=l[e];if(n.attachment.attachmentID!==t.attachmentID||!Ql(n.attachment.occurrenceRefID,t.occurrenceRefID)||n.blob.size!==t.size||n.blob.type!==t.mimeType)return Xl(`materialize-failed`,`attachments`,`attachment-mismatch`);let r=Zl(t.occurrenceRefID),i={attachmentID:t.attachmentID,attachmentRefID:r,filename:t.filename,mimeType:t.mimeType,size:t.size,locator:{kind:`blob`,blobID:t.attachmentID},source:t.source,...t.locator.kind===`server-path`?{serverPath:t.locator.path}:{}};t.occurrenceRefID[0]===`part`?p.set(t.occurrenceRefID[1],[...p.get(t.occurrenceRefID[1])??[],i]):f.push(i),m.set(r,n.blob)}if(!t.current(r))return Xl(`materialize-failed`,`identity`,`runtime-stale`);if(!await u())return Xl(`materialize-failed`,`identity`,`lease-lost`);let h,g=(e.item.syntheticParts??[]).map(e=>({partID:e.partID,text:e.text,attachments:p.get(e.partID)??[],...e.synthetic===!0?{synthetic:!0}:{}}));try{let r=await Hn({content:e.item.content,composerDocument:e.item.composerDocument,composerMentions:e.item.composerMentions,draftAttachments:f,draftValues:m,syntheticParts:g}),i=await Gt({key:e.targetKey,expectedRevision:e.expectedRevision,payload:r,runtime:n,input:t.input});if(h=i.result??{status:i.status,durable:i.durable,current:i.current,errors:[],cleanupErrors:[]},i.status===`failed`&&!i.result)return Xl(`draft-rejected`,`draft`,`commit-threw`)}catch{return Xl(`draft-rejected`,`draft`,`commit-threw`)}if(!h.durable)return Xl(`draft-rejected`,`draft`,h.status);if(!t.current(r)||o)return Xl(`queue-retained`,`remove`,o?`lease-lost`:`runtime-stale`,!0);try{return await t.queue.removeReserved({requestID:L(),scopeID:e.scopeID,revision:i.revision,item:{...e.item,rowVersion:i.rowVersion},token:i.token,generation:i.generation,runtime:r})?(a=!0,{status:`committed`,current:h.current,draftDurable:!0,queueDurablyRemoved:!0,attachmentIssues:[],diagnostics:[]}):Xl(`queue-retained`,`remove`,`remove-rejected`,!0)}catch{return Xl(`queue-retained`,`remove`,`remove-failed`,!0)}}catch{return o?Xl(`materialize-failed`,`identity`,`lease-lost`):Xl(`materialize-failed`,`attachments`,`download-failed`)}finally{clearInterval(d),s.abort(),await f()}})();return n.set(i,o),o.finally(()=>{n.get(i)===o&&n.delete(i)}),o}}})(),nu=e=>tu.editServerQueueItemIntoDraft(e),ru=[],iu=(e,t=Lr(),n=kn())=>{let r=(0,Z.useMemo)(()=>({transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID}),[e.directory,e.sessionID,e.transportIdentity]),i=(0,Z.useMemo)(()=>e=>b(e,{state:`bound`,...r}),[r]),a=C(i),o=(0,Z.useMemo)(()=>{let e,i,o,s={admit:t.admit,edit:t.edit,remove:t.remove,reorder:t.reorder,manualSend:t.manualSend,refresh:t.refresh,runShadowImport:t.runShadowImport,captureRuntime:t.captureRuntime,stageAdmission:t.stageAdmission,unstageAdmission:t.unstageAdmission,editIntoDraft:nu};return{subscribe:e=>{let i=t.subscribeScope(r,e),a=n.subscribe(e);return()=>{i(),a()}},getSnapshot:()=>{let c=t.getState(),l=t.captureRuntime(),u=t.getScope(r),d=t.getPendingAdmissions(r),f=n.getSnapshot(),p=e?.runtimeCapture.transportIdentity===l.transportIdentity&&e.runtimeCapture.generation===l.generation?e.runtimeCapture:l,m=c.transportIdentity===r.transportIdentity&&c.capability===`available`&&(c.authority===`active`||c.authority===`paused`),h=f.ownership===`legacy-unsupported`?`legacy`:f.ownership===`server-active`||f.ownership===`server-paused`||f.ownership===`probing`&&m?`server`:`frozen`,g=h===`server`&&d.length>0,_=h===`server`&&d.some(e=>e.phase===`uploading`||e.phase===`admitting`||e.phase===`ambiguous`),v=e?.mode===h&&e.scope===u&&e.hasPendingAdmission===g&&e.hasBlockingAdmission===_&&d===i&&a===o?e.items:h===`server`?d.length?[...u?.items??ru,...d.filter(e=>!u?.items.some(t=>t.queueItemID===e.queueItemID))]:u?.items??d:h===`frozen`?a:ru;return e?.runtimeCapture===p&&e.capability===c.capability&&e.authority===c.authority&&e.mode===h&&e.importState===c.importState&&e.hydration===c.hydration&&e.scope===u&&e.items===v&&e.hasPendingAdmission===g&&e.hasBlockingAdmission===_?e:(i=d,o=a,e={runtimeCapture:p,capability:c.capability,authority:c.authority,mode:h,importState:c.importState,hydration:c.hydration,scope:u,items:v,hasPendingAdmission:g,hasBlockingAdmission:_,actions:s},e)}}},[n,a,t,r]);return(0,Z.useSyncExternalStore)(o.subscribe,o.getSnapshot,o.getSnapshot)},au=e=>{let t=(0,Q.c)(38),{value:n,options:r,disabled:i,onChange:a}=e,{t:o}=ot(),s;t[0]!==o||t[1]!==n?(s=n||o(`rightSidebar.contextNotesTodo.sendDialog.variant.default`),t[0]=o,t[1]=n,t[2]=s):s=t[2];let c=s,l=i?`cursor-not-allowed opacity-60`:`cursor-pointer hover:bg-interactive-hover/30`,u;t[3]===l?u=t[4]:(u=Y(`flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2`,l),t[3]=l,t[4]=u);let d;t[5]===c?d=t[6]:(d=(0,$.jsx)(`span`,{className:`typography-micro whitespace-nowrap font-medium capitalize`,children:c}),t[5]=c,t[6]=d);let f;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0 text-muted-foreground`}),t[7]=f):f=t[7];let p;t[8]!==u||t[9]!==d?(p=(0,$.jsxs)(`div`,{className:u,children:[d,f]}),t[8]=u,t[9]=d,t[10]=p):p=t[10];let m=p;if(i)return m;let h;t[11]===m?h=t[12]:(h=(0,$.jsx)(qa,{asChild:!0,children:m}),t[11]=m,t[12]=h);let g;t[13]===a?g=t[14]:(g=()=>a(``),t[13]=a,t[14]=g);let _=!n&&`text-primary`,v;t[15]===_?v=t[16]:(v=Y(`font-medium`,_),t[15]=_,t[16]=v);let y;t[17]===o?y=t[18]:(y=o(`rightSidebar.contextNotesTodo.sendDialog.variant.default`),t[17]=o,t[18]=y);let b;t[19]!==v||t[20]!==y?(b=(0,$.jsx)(`span`,{className:v,children:y}),t[19]=v,t[20]=y,t[21]=b):b=t[21];let x;t[22]!==b||t[23]!==g?(x=(0,$.jsx)(ao,{className:`typography-meta`,onSelect:g,children:b}),t[22]=b,t[23]=g,t[24]=x):x=t[24];let S;if(t[25]!==a||t[26]!==r||t[27]!==n){let e;t[29]!==a||t[30]!==n?(e=e=>(0,$.jsx)(ao,{className:`typography-meta`,onSelect:()=>a(e),children:(0,$.jsx)(`span`,{className:Y(`font-medium capitalize`,n===e&&`text-primary`),children:e})},e),t[29]=a,t[30]=n,t[31]=e):e=t[31],S=r.map(e),t[25]=a,t[26]=r,t[27]=n,t[28]=S}else S=t[28];let C;t[32]!==x||t[33]!==S?(C=(0,$.jsxs)(Ka,{align:`start`,className:`max-w-[220px]`,portalToBody:!0,children:[x,S]}),t[32]=x,t[33]=S,t[34]=C):C=t[34];let w;return t[35]!==C||t[36]!==h?(w=(0,$.jsxs)(Ua,{children:[h,C]}),t[35]=C,t[36]=h,t[37]=w):w=t[37],w},ou=e=>({providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,generateHandoff:!0,autoReview:!1});function su(e){let t=(0,Q.c)(161),{open:n,onOpenChange:r,projectDirectory:i,submitting:a,onConfirm:o}=e,s=a!==void 0&&a,{t:c}=ot(),l=mi(_u),u=mi(gu),d=_r(hu),f=mi(mu),p=mi(pu),m=mi(fu),h=mi(du),g=mi(uu),_;t[0]!==g||t[1]!==m||t[2]!==p||t[3]!==h?(_=()=>ou({providerID:p,modelID:m,variant:h,agent:g}),t[0]=g,t[1]=m,t[2]=p,t[3]=h,t[4]=_):_=t[4];let[v,y]=Z.useState(_),b,x;t[5]!==d||t[6]!==u||t[7]!==l||t[8]!==n||t[9]!==i?(b=()=>{n&&(l({directory:i,source:`reviewFlowDialog`}),u({directory:i}),d())},x=[n,l,u,d,i],t[5]=d,t[6]=u,t[7]=l,t[8]=n,t[9]=i,t[10]=b,t[11]=x):(b=t[10],x=t[11]),Z.useEffect(b,x);let S,C;t[12]!==g||t[13]!==m||t[14]!==p||t[15]!==h||t[16]!==n?(S=()=>{n&&y(ou({providerID:p,modelID:m,variant:h,agent:g}))},C=[n,p,m,h,g],t[12]=g,t[13]=m,t[14]=p,t[15]=h,t[16]=n,t[17]=S,t[18]=C):(S=t[17],C=t[18]),Z.useEffect(S,C);let w,T;t[19]!==v.modelID||t[20]!==v.providerID||t[21]!==n||t[22]!==f?(w=()=>{if(!n||f.length===0)return;let e=f.find(e=>e.id===v.providerID)??f[0],t=Array.isArray(e?.models)?e.models:[],r=t.some(e=>e.id===v.modelID),i=t[0]?.id??``;e?.id===v.providerID&&r||y(t=>({...t,providerID:e?.id??``,modelID:r?t.modelID:i,variant:``}))},T=[n,f,v.providerID,v.modelID],t[19]=v.modelID,t[20]=v.providerID,t[21]=n,t[22]=f,t[23]=w,t[24]=T):(w=t[23],T=t[24]),Z.useEffect(w,T);let E=lu,D;if(t[25]!==v.modelID||t[26]!==v.providerID||t[27]!==f){let e;t[29]===v.providerID?e=t[30]:(e=e=>e.id===v.providerID,t[29]=v.providerID,t[30]=e),D=f.find(e)?.models?.find(e=>e.id===v.modelID),t[25]=v.modelID,t[26]=v.providerID,t[27]=f,t[28]=D}else D=t[28];let O=D,k;t[31]===O?k=t[32]:(k=O?.variants?Object.keys(O.variants):[],t[31]=O,t[32]=k);let A=k,j=A.length>0,M,N;t[33]!==v.variant||t[34]!==j?(M=()=>{j||!v.variant||y(cu)},N=[j,v.variant],t[33]=v.variant,t[34]=j,t[35]=M,t[36]=N):(M=t[35],N=t[36]),Z.useEffect(M,N);let P;t[37]!==v.modelID||t[38]!==v.providerID?(P=v.providerID.trim().length>0&&v.modelID.trim().length>0,t[37]=v.modelID,t[38]=v.providerID,t[39]=P):P=t[39];let F=P,I;t[40]!==F||t[41]!==v||t[42]!==o||t[43]!==s?(I=()=>{!F||s||o(v)},t[40]=F,t[41]=v,t[42]=o,t[43]=s,t[44]=I):I=t[44];let L=I,R,z;t[45]!==L||t[46]!==n?(R=()=>{if(!n)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),L())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},z=[n,L],t[45]=L,t[46]=n,t[47]=R,t[48]=z):(R=t[47],z=t[48]),Z.useEffect(R,z);let B;t[49]!==r||t[50]!==s?(B=e=>{s||r(e)},t[49]=r,t[50]=s,t[51]=B):B=t[51];let V;t[52]===c?V=t[53]:(V=c(`diffView.reviewDialog.title`),t[52]=c,t[53]=V);let H;t[54]===V?H=t[55]:(H=(0,$.jsx)(aa,{children:V}),t[54]=V,t[55]=H);let U;t[56]===c?U=t[57]:(U=c(`diffView.reviewDialog.description`),t[56]=c,t[57]=U);let W;t[58]===U?W=t[59]:(W=(0,$.jsx)(oa,{children:U}),t[58]=U,t[59]=W);let ee;t[60]!==H||t[61]!==W?(ee=(0,$.jsxs)(na,{children:[H,W]}),t[60]=H,t[61]=W,t[62]=ee):ee=t[62];let G;t[63]===c?G=t[64]:(G=c(`diffView.reviewDialog.info`),t[63]=c,t[64]=G);let K;t[65]===G?K=t[66]:(K=(0,$.jsx)(`div`,{className:`rounded-md border border-[color:color-mix(in_srgb,var(--status-info)_35%,var(--interactive-border))] bg-[color:color-mix(in_srgb,var(--status-info)_10%,var(--surface-background))] px-3 py-2 typography-meta text-foreground`,children:G}),t[65]=G,t[66]=K);let te=v.generateHandoff,ne;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>y(t=>({...t,generateHandoff:e})),t[67]=ne):ne=t[67];let re;t[68]===c?re=t[69]:(re=c(`diffView.reviewDialog.generateHandoff`),t[68]=c,t[69]=re);let ie;t[70]!==v.generateHandoff||t[71]!==s||t[72]!==re?(ie=(0,$.jsx)(ha,{checked:te,onChange:ne,disabled:s,ariaLabel:re}),t[70]=v.generateHandoff,t[71]=s,t[72]=re,t[73]=ie):ie=t[73];let ae;t[74]===c?ae=t[75]:(ae=c(`diffView.reviewDialog.generateHandoff`),t[74]=c,t[75]=ae);let oe;t[76]===ae?oe=t[77]:(oe=(0,$.jsx)(`span`,{children:ae}),t[76]=ae,t[77]=oe);let se;t[78]!==ie||t[79]!==oe?(se=(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-ui-label text-foreground`,children:[ie,oe]}),t[78]=ie,t[79]=oe,t[80]=se):se=t[80];let ce=v.autoReview,le;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>y(t=>({...t,autoReview:e})),t[81]=le):le=t[81];let ue;t[82]===c?ue=t[83]:(ue=c(`diffView.reviewDialog.autoReview`),t[82]=c,t[83]=ue);let de;t[84]!==v.autoReview||t[85]!==s||t[86]!==ue?(de=(0,$.jsx)(ha,{checked:ce,onChange:le,disabled:s,ariaLabel:ue}),t[84]=v.autoReview,t[85]=s,t[86]=ue,t[87]=de):de=t[87];let fe;t[88]===c?fe=t[89]:(fe=c(`diffView.reviewDialog.autoReview`),t[88]=c,t[89]=fe);let pe;t[90]===fe?pe=t[91]:(pe=(0,$.jsx)(`span`,{children:fe}),t[90]=fe,t[91]=pe);let me;t[92]!==de||t[93]!==pe?(me=(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-ui-label text-foreground`,children:[de,pe]}),t[92]=de,t[93]=pe,t[94]=me):me=t[94];let he;t[95]===c?he=t[96]:(he=c(`chat.modelControls.model`),t[95]=c,t[96]=he);let ge;t[97]===he?ge=t[98]:(ge=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:he}),t[97]=he,t[98]=ge);let _e;t[99]===Symbol.for(`react.memo_cache_sentinel`)?(_e=(e,t)=>{y(n=>({...n,providerID:e,modelID:t,variant:``}))},t[99]=_e):_e=t[99];let ve;t[100]!==v.modelID||t[101]!==v.providerID?(ve=(0,$.jsx)(co,{providerId:v.providerID,modelId:v.modelID,className:`max-w-[320px] justify-between`,dropdownPortalToBody:!0,onChange:_e}),t[100]=v.modelID,t[101]=v.providerID,t[102]=ve):ve=t[102];let ye;t[103]!==ge||t[104]!==ve?(ye=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[ge,ve]}),t[103]=ge,t[104]=ve,t[105]=ye):ye=t[105];let be;t[106]===c?be=t[107]:(be=c(`sessions.scheduledTasks.editor.thinkingLevel.label`),t[106]=c,t[107]=be);let xe;t[108]===be?xe=t[109]:(xe=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:be}),t[108]=be,t[109]=xe);let Se=!j||s,Ce;t[110]===Symbol.for(`react.memo_cache_sentinel`)?(Ce=e=>y(t=>({...t,variant:e})),t[110]=Ce):Ce=t[110];let we;t[111]!==v.variant||t[112]!==Se||t[113]!==A?(we=(0,$.jsx)(au,{value:v.variant,options:A,disabled:Se,onChange:Ce}),t[111]=v.variant,t[112]=Se,t[113]=A,t[114]=we):we=t[114];let Te;t[115]!==xe||t[116]!==we?(Te=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[xe,we]}),t[115]=xe,t[116]=we,t[117]=Te):Te=t[117];let Ee;t[118]===c?Ee=t[119]:(Ee=c(`sessions.scheduledTasks.editor.agent.label`),t[118]=c,t[119]=Ee);let De;t[120]===Ee?De=t[121]:(De=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:Ee}),t[120]=Ee,t[121]=De);let Oe;t[122]===Symbol.for(`react.memo_cache_sentinel`)?(Oe=e=>y(t=>({...t,agent:e})),t[122]=Oe):Oe=t[122];let ke;t[123]===v.agent?ke=t[124]:(ke=(0,$.jsx)(no,{agentName:v.agent,filter:E,dropdownPortalToBody:!0,onChange:Oe}),t[123]=v.agent,t[124]=ke);let Ae;t[125]!==De||t[126]!==ke?(Ae=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[De,ke]}),t[125]=De,t[126]=ke,t[127]=Ae):Ae=t[127];let je;t[128]!==K||t[129]!==se||t[130]!==me||t[131]!==ye||t[132]!==Te||t[133]!==Ae?(je=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[K,se,me,ye,Te,Ae]}),t[128]=K,t[129]=se,t[130]=me,t[131]=ye,t[132]=Te,t[133]=Ae,t[134]=je):je=t[134];let Me;t[135]===r?Me=t[136]:(Me=()=>r(!1),t[135]=r,t[136]=Me);let Ne;t[137]===c?Ne=t[138]:(Ne=c(`diffView.reviewDialog.actions.cancel`),t[137]=c,t[138]=Ne);let Pe;t[139]!==s||t[140]!==Me||t[141]!==Ne?(Pe=(0,$.jsx)(la,{variant:`ghost`,size:`sm`,onClick:Me,disabled:s,children:Ne}),t[139]=s,t[140]=Me,t[141]=Ne,t[142]=Pe):Pe=t[142];let Fe=!F||s,Ie;t[143]!==s||t[144]!==c?(Ie=c(s?`diffView.reviewDialog.actions.starting`:`diffView.reviewDialog.actions.start`),t[143]=s,t[144]=c,t[145]=Ie):Ie=t[145];let Le;t[146]!==L||t[147]!==Fe||t[148]!==Ie?(Le=(0,$.jsx)(la,{size:`sm`,onClick:L,disabled:Fe,children:Ie}),t[146]=L,t[147]=Fe,t[148]=Ie,t[149]=Le):Le=t[149];let Re;t[150]!==Pe||t[151]!==Le?(Re=(0,$.jsxs)(ra,{children:[Pe,Le]}),t[150]=Pe,t[151]=Le,t[152]=Re):Re=t[152];let ze;t[153]!==ee||t[154]!==je||t[155]!==Re?(ze=(0,$.jsxs)(ia,{className:`max-w-md overflow-visible`,children:[ee,je,Re]}),t[153]=ee,t[154]=je,t[155]=Re,t[156]=ze):ze=t[156];let Be;return t[157]!==n||t[158]!==B||t[159]!==ze?(Be=(0,$.jsx)(ca,{open:n,onOpenChange:B,children:ze}),t[157]=n,t[158]=B,t[159]=ze,t[160]=Be):Be=t[160],Be}function cu(e){return{...e,variant:``}}function lu(e){return er(e.mode)}function uu(e){return e.currentAgentName||``}function du(e){return e.currentVariant||``}function fu(e){return e.currentModelId}function pu(e){return e.currentProviderId}function mu(e){return e.providers}function hu(e){return e.loadAgents}function gu(e){return e.loadAgents}function _u(e){return e.loadProviders}var vu=new Set(`3d.3d_light.abap.abap_light.abc.abc_light.actionscript.actionscript_light.ada.ada_light.adobe-illustrator.adobe-illustrator_light.adobe-photoshop.adobe-photoshop_light.adobe-swc.adobe-swc_light.adonis.adonis_light.advpl.advpl_light.amplify.amplify_light.android.android_light.angular.angular_light.antlr.antlr_light.apiblueprint.apiblueprint_light.apollo.apollo_light.applescript.applescript_light.apps-script.apps-script_light.appveyor.appveyor_light.architecture.architecture_light.arduino.arduino_light.asciidoc.asciidoc_light.assembly.assembly_light.astro.astro_light.astro-config.astro-config_light.astyle.astyle_light.audio.audio_light.aurelia.aurelia_light.authors.authors_light.auto.auto_light.autohotkey.autohotkey_light.autoit.autoit_light.azure.azure_light.azure-pipelines.azure-pipelines_light.babel.babel_light.ballerina.ballerina_light.bazel.bazel_light.bbx.bbx_light.beancount.beancount_light.bench-js.bench-js_light.bench-jsx.bench-jsx_light.bench-ts.bench-ts_light.bibliography.bibliography_light.bibtex-style.bibtex-style_light.bicep.bicep_light.biome.biome_light.bitbucket.bitbucket_light.bithound.bithound_light.blender.blender_light.blink.blink_light.blitz.blitz_light.bower.bower_light.brainfuck.brainfuck_light.browserlist.browserlist_light.bruno.bruno_light.buck.buck_light.bucklescript.bucklescript_light.buildkite.buildkite_light.bun.bun_light.c.c_light.c3.c3_light.cabal.cabal_light.caddy.caddy_light.cadence.cadence_light.cairo.cairo_light.cake.cake_light.capacitor.capacitor_light.capnp.capnp_light.cbx.cbx_light.cds.cds_light.certificate.certificate_light.changelog.changelog_light.chess.chess_light.chrome.chrome_light.circleci.circleci_light.citation.citation_light.clangd.clangd_light.claude.claude_light.cline.cline_light.clojure.clojure_light.cloudfoundry.cloudfoundry_light.cmake.cmake_light.coala.coala_light.cobol.cobol_light.coconut.coconut_light.code-climate.code-climate_light.codecov.codecov_light.codeowners.codeowners_light.coderabbit-ai.coderabbit-ai_light.coffee.coffee_light.coldfusion.coldfusion_light.coloredpetrinets.coloredpetrinets_light.command.command_light.commitizen.commitizen_light.commitlint.commitlint_light.concourse.concourse_light.conduct.conduct_light.console.console_light.contentlayer.contentlayer_light.context.context_light.contributing.contributing_light.controller.controller_light.copilot.copilot_light.cpp.cpp_light.craco.craco_light.credits.credits_light.crystal.crystal_light.csharp.csharp_light.css.css_light.css-map.css-map_light.cucumber.cucumber_light.cuda.cuda_light.cursor.cursor_light.cypress.cypress_light.d.d_light.dart.dart_generated.dart_generated_light.dart_light.database.database_light.deepsource.deepsource_light.denizenscript.denizenscript_light.deno.deno_light.dependabot.dependabot_light.dependencies-update.dependencies-update_light.dhall.dhall_light.diff.diff_light.dinophp.dinophp_light.disc.disc_light.django.django_light.dll.dll_light.docker.docker_light.doctex-installer.doctex-installer_light.document.document_light.dotjs.dotjs_light.drawio.drawio_light.drizzle.drizzle_light.drone.drone_light.duc.duc_light.dune.dune_light.edge.edge_light.editorconfig.editorconfig_light.ejs.ejs_light.elixir.elixir_light.elm.elm_light.email.email_light.ember.ember_light.epub.epub_light.erlang.erlang_light.esbuild.esbuild_light.eslint.eslint_light.excalidraw.excalidraw_light.exe.exe_light.fastlane.fastlane_light.favicon.favicon_light.figma.figma_light.firebase.firebase_light.flash.flash_light.flow.flow_light.folder.folder_light.folder-admin.folder-admin_light.folder-admin-open.folder-admin-open_light.folder-android.folder-android_light.folder-android-open.folder-android-open_light.folder-angular.folder-angular_light.folder-angular-open.folder-angular-open_light.folder-animation.folder-animation_light.folder-animation-open.folder-animation-open_light.folder-ansible.folder-ansible_light.folder-ansible-open.folder-ansible-open_light.folder-api.folder-api_light.folder-api-open.folder-api-open_light.folder-apollo.folder-apollo_light.folder-apollo-open.folder-apollo-open_light.folder-app.folder-app_light.folder-app-open.folder-app-open_light.folder-archive.folder-archive_light.folder-archive-open.folder-archive-open_light.folder-astro.folder-astro_light.folder-astro-open.folder-astro-open_light.folder-atom.folder-atom_light.folder-atom-open.folder-atom-open_light.folder-attachment.folder-attachment_light.folder-attachment-open.folder-attachment-open_light.folder-audio.folder-audio_light.folder-audio-open.folder-audio-open_light.folder-aurelia.folder-aurelia_light.folder-aurelia-open.folder-aurelia-open_light.folder-aws.folder-aws_light.folder-aws-open.folder-aws-open_light.folder-azure-pipelines.folder-azure-pipelines_light.folder-azure-pipelines-open.folder-azure-pipelines-open_light.folder-backup.folder-backup_light.folder-backup-open.folder-backup-open_light.folder-base.folder-base_light.folder-base-open.folder-base-open_light.folder-batch.folder-batch_light.folder-batch-open.folder-batch-open_light.folder-benchmark.folder-benchmark_light.folder-benchmark-open.folder-benchmark-open_light.folder-bibliography.folder-bibliography_light.folder-bibliography-open.folder-bibliography-open_light.folder-bicep.folder-bicep_light.folder-bicep-open.folder-bicep-open_light.folder-blender.folder-blender_light.folder-blender-open.folder-blender-open_light.folder-bloc.folder-bloc_light.folder-bloc-open.folder-bloc-open_light.folder-bower.folder-bower_light.folder-bower-open.folder-bower-open_light.folder-buildkite.folder-buildkite_light.folder-buildkite-open.folder-buildkite-open_light.folder-cart.folder-cart_light.folder-cart-open.folder-cart-open_light.folder-changesets.folder-changesets_light.folder-changesets-open.folder-changesets-open_light.folder-ci.folder-ci_light.folder-ci-open.folder-ci-open_light.folder-circleci.folder-circleci_light.folder-circleci-open.folder-circleci-open_light.folder-class.folder-class_light.folder-class-open.folder-class-open_light.folder-claude.folder-claude_light.folder-claude-open.folder-claude-open_light.folder-client.folder-client_light.folder-client-open.folder-client-open_light.folder-cline.folder-cline_light.folder-cline-open.folder-cline-open_light.folder-cloud-functions.folder-cloud-functions_light.folder-cloud-functions-open.folder-cloud-functions-open_light.folder-cloudflare.folder-cloudflare_light.folder-cloudflare-open.folder-cloudflare-open_light.folder-cluster.folder-cluster_light.folder-cluster-open.folder-cluster-open_light.folder-cobol.folder-cobol_light.folder-cobol-open.folder-cobol-open_light.folder-command.folder-command_light.folder-command-open.folder-command-open_light.folder-components.folder-components_light.folder-components-open.folder-components-open_light.folder-config.folder-config_light.folder-config-open.folder-config-open_light.folder-connection.folder-connection_light.folder-connection-open.folder-connection-open_light.folder-console.folder-console_light.folder-console-open.folder-console-open_light.folder-constant.folder-constant_light.folder-constant-open.folder-constant-open_light.folder-container.folder-container_light.folder-container-open.folder-container-open_light.folder-content.folder-content_light.folder-content-open.folder-content-open_light.folder-context.folder-context_light.folder-context-open.folder-context-open_light.folder-contract.folder-contract_light.folder-contract-open.folder-contract-open_light.folder-controller.folder-controller_light.folder-controller-open.folder-controller-open_light.folder-core.folder-core_light.folder-core-open.folder-core-open_light.folder-coverage.folder-coverage_light.folder-coverage-open.folder-coverage-open_light.folder-css.folder-css_light.folder-css-open.folder-css-open_light.folder-cursor.folder-cursor_light.folder-cursor-open.folder-cursor-open_light.folder-custom.folder-custom_light.folder-custom-open.folder-custom-open_light.folder-cypress.folder-cypress_light.folder-cypress-open.folder-cypress-open_light.folder-dart.folder-dart_light.folder-dart-open.folder-dart-open_light.folder-database.folder-database_light.folder-database-open.folder-database-open_light.folder-debug.folder-debug_light.folder-debug-open.folder-debug-open_light.folder-decorators.folder-decorators_light.folder-decorators-open.folder-decorators-open_light.folder-delta.folder-delta_light.folder-delta-open.folder-delta-open_light.folder-desktop.folder-desktop_light.folder-desktop-open.folder-desktop-open_light.folder-directive.folder-directive_light.folder-directive-open.folder-directive-open_light.folder-dist.folder-dist_light.folder-dist-open.folder-dist-open_light.folder-docker.folder-docker_light.folder-docker-open.folder-docker-open_light.folder-docs.folder-docs_light.folder-docs-open.folder-docs-open_light.folder-download.folder-download_light.folder-download-open.folder-download-open_light.folder-drizzle.folder-drizzle_light.folder-drizzle-open.folder-drizzle-open_light.folder-dump.folder-dump_light.folder-dump-open.folder-dump-open_light.folder-element.folder-element_light.folder-element-open.folder-element-open_light.folder-enum.folder-enum_light.folder-enum-open.folder-enum-open_light.folder-environment.folder-environment_light.folder-environment-open.folder-environment-open_light.folder-error.folder-error_light.folder-error-open.folder-error-open_light.folder-event.folder-event_light.folder-event-open.folder-event-open_light.folder-examples.folder-examples_light.folder-examples-open.folder-examples-open_light.folder-expo.folder-expo_light.folder-expo-open.folder-expo-open_light.folder-export.folder-export_light.folder-export-open.folder-export-open_light.folder-fastlane.folder-fastlane_light.folder-fastlane-open.folder-fastlane-open_light.folder-favicon.folder-favicon_light.folder-favicon-open.folder-favicon-open_light.folder-firebase.folder-firebase_light.folder-firebase-open.folder-firebase-open_light.folder-firestore.folder-firestore_light.folder-firestore-open.folder-firestore-open_light.folder-flow.folder-flow_light.folder-flow-open.folder-flow-open_light.folder-flutter.folder-flutter_light.folder-flutter-open.folder-flutter-open_light.folder-font.folder-font_light.folder-font-open.folder-font-open_light.folder-forgejo.folder-forgejo_light.folder-forgejo-open.folder-forgejo-open_light.folder-functions.folder-functions_light.folder-functions-open.folder-functions-open_light.folder-gamemaker.folder-gamemaker_light.folder-gamemaker-open.folder-gamemaker-open_light.folder-generator.folder-generator_light.folder-generator-open.folder-generator-open_light.folder-gh-workflows.folder-gh-workflows_light.folder-gh-workflows-open.folder-gh-workflows-open_light.folder-git.folder-git_light.folder-git-open.folder-git-open_light.folder-gitea.folder-gitea_light.folder-gitea-open.folder-gitea-open_light.folder-github.folder-github_light.folder-github-open.folder-github-open_light.folder-gitlab.folder-gitlab_light.folder-gitlab-open.folder-gitlab-open_light.folder-global.folder-global_light.folder-global-open.folder-global-open_light.folder-godot.folder-godot_light.folder-godot-open.folder-godot-open_light.folder-gradle.folder-gradle_light.folder-gradle-open.folder-gradle-open_light.folder-graphql.folder-graphql_light.folder-graphql-open.folder-graphql-open_light.folder-guard.folder-guard_light.folder-guard-open.folder-guard-open_light.folder-gulp.folder-gulp_light.folder-gulp-open.folder-gulp-open_light.folder-helm.folder-helm_light.folder-helm-open.folder-helm-open_light.folder-helper.folder-helper_light.folder-helper-open.folder-helper-open_light.folder-home.folder-home_light.folder-home-open.folder-home-open_light.folder-hook.folder-hook_light.folder-hook-open.folder-hook-open_light.folder-husky.folder-husky_light.folder-husky-open.folder-husky-open_light.folder-i18n.folder-i18n_light.folder-i18n-open.folder-i18n-open_light.folder-images.folder-images_light.folder-images-open.folder-images-open_light.folder-import.folder-import_light.folder-import-open.folder-import-open_light.folder-include.folder-include_light.folder-include-open.folder-include-open_light.folder-intellij.folder-intellij_light.folder-intellij-open.folder-intellij-open_light.folder-interceptor.folder-interceptor_light.folder-interceptor-open.folder-interceptor-open_light.folder-interface.folder-interface_light.folder-interface-open.folder-interface-open_light.folder-ios.folder-ios_light.folder-ios-open.folder-ios-open_light.folder-java.folder-java_light.folder-java-open.folder-java-open_light.folder-javascript.folder-javascript_light.folder-javascript-open.folder-javascript-open_light.folder-jinja.folder-jinja_light.folder-jinja-open.folder-jinja-open_light.folder-job.folder-job_light.folder-job-open.folder-job-open_light.folder-json.folder-json_light.folder-json-open.folder-json-open_light.folder-jupyter.folder-jupyter_light.folder-jupyter-open.folder-jupyter-open_light.folder-keys.folder-keys_light.folder-keys-open.folder-keys-open_light.folder-kubernetes.folder-kubernetes_light.folder-kubernetes-open.folder-kubernetes-open_light.folder-kusto.folder-kusto_light.folder-kusto-open.folder-kusto-open_light.folder-layout.folder-layout_light.folder-layout-open.folder-layout-open_light.folder-lefthook.folder-lefthook_light.folder-lefthook-open.folder-lefthook-open_light.folder-less.folder-less_light.folder-less-open.folder-less-open_light.folder-lib.folder-lib_light.folder-lib-open.folder-lib-open_light.folder-link.folder-link_light.folder-link-open.folder-link-open_light.folder-linux.folder-linux_light.folder-linux-open.folder-linux-open_light.folder-liquibase.folder-liquibase_light.folder-liquibase-open.folder-liquibase-open_light.folder-log.folder-log_light.folder-log-open.folder-log-open_light.folder-lottie.folder-lottie_light.folder-lottie-open.folder-lottie-open_light.folder-lua.folder-lua_light.folder-lua-open.folder-lua-open_light.folder-luau.folder-luau_light.folder-luau-open.folder-luau-open_light.folder-macos.folder-macos_light.folder-macos-open.folder-macos-open_light.folder-mail.folder-mail_light.folder-mail-open.folder-mail-open_light.folder-mappings.folder-mappings_light.folder-mappings-open.folder-mappings-open_light.folder-markdown.folder-markdown_light.folder-markdown-open.folder-markdown-open_light.folder-mercurial.folder-mercurial_light.folder-mercurial-open.folder-mercurial-open_light.folder-messages.folder-messages_light.folder-messages-open.folder-messages-open_light.folder-meta.folder-meta_light.folder-meta-open.folder-meta-open_light.folder-middleware.folder-middleware_light.folder-middleware-open.folder-middleware-open_light.folder-mjml.folder-mjml_light.folder-mjml-open.folder-mjml-open_light.folder-mobile.folder-mobile_light.folder-mobile-open.folder-mobile-open_light.folder-mock.folder-mock_light.folder-mock-open.folder-mock-open_light.folder-mojo.folder-mojo_light.folder-mojo-open.folder-mojo-open_light.folder-molecule.folder-molecule_light.folder-molecule-open.folder-molecule-open_light.folder-moon.folder-moon_light.folder-moon-open.folder-moon-open_light.folder-netlify.folder-netlify_light.folder-netlify-open.folder-netlify-open_light.folder-next.folder-next_light.folder-next-open.folder-next-open_light.folder-ngrx-store.folder-ngrx-store_light.folder-ngrx-store-open.folder-ngrx-store-open_light.folder-node.folder-node_light.folder-node-open.folder-node-open_light.folder-nuxt.folder-nuxt_light.folder-nuxt-open.folder-nuxt-open_light.folder-obsidian.folder-obsidian_light.folder-obsidian-open.folder-obsidian-open_light.folder-open.folder-open_light.folder-organism.folder-organism_light.folder-organism-open.folder-organism-open_light.folder-other.folder-other_light.folder-other-open.folder-other-open_light.folder-packages.folder-packages_light.folder-packages-open.folder-packages-open_light.folder-pdf.folder-pdf_light.folder-pdf-open.folder-pdf-open_light.folder-pdm.folder-pdm_light.folder-pdm-open.folder-pdm-open_light.folder-php.folder-php_light.folder-php-open.folder-php-open_light.folder-phpmailer.folder-phpmailer_light.folder-phpmailer-open.folder-phpmailer-open_light.folder-pipe.folder-pipe_light.folder-pipe-open.folder-pipe-open_light.folder-plastic.folder-plastic_light.folder-plastic-open.folder-plastic-open_light.folder-plugin.folder-plugin_light.folder-plugin-open.folder-plugin-open_light.folder-policy.folder-policy_light.folder-policy-open.folder-policy-open_light.folder-powershell.folder-powershell_light.folder-powershell-open.folder-powershell-open_light.folder-prisma.folder-prisma_light.folder-prisma-open.folder-prisma-open_light.folder-private.folder-private_light.folder-private-open.folder-private-open_light.folder-project.folder-project_light.folder-project-open.folder-project-open_light.folder-prompts.folder-prompts_light.folder-prompts-open.folder-prompts-open_light.folder-proto.folder-proto_light.folder-proto-open.folder-proto-open_light.folder-public.folder-public_light.folder-public-open.folder-public-open_light.folder-python.folder-python_light.folder-python-open.folder-python-open_light.folder-pytorch.folder-pytorch_light.folder-pytorch-open.folder-pytorch-open_light.folder-quasar.folder-quasar_light.folder-quasar-open.folder-quasar-open_light.folder-queue.folder-queue_light.folder-queue-open.folder-queue-open_light.folder-react-components.folder-react-components_light.folder-react-components-open.folder-react-components-open_light.folder-redux-reducer.folder-redux-reducer_light.folder-redux-reducer-open.folder-redux-reducer-open_light.folder-repository.folder-repository_light.folder-repository-open.folder-repository-open_light.folder-resolver.folder-resolver_light.folder-resolver-open.folder-resolver-open_light.folder-resource.folder-resource_light.folder-resource-open.folder-resource-open_light.folder-review.folder-review_light.folder-review-open.folder-review-open_light.folder-robot.folder-robot_light.folder-robot-open.folder-robot-open_light.folder-routes.folder-routes_light.folder-routes-open.folder-routes-open_light.folder-rules.folder-rules_light.folder-rules-open.folder-rules-open_light.folder-rust.folder-rust_light.folder-rust-open.folder-rust-open_light.folder-sandbox.folder-sandbox_light.folder-sandbox-open.folder-sandbox-open_light.folder-sass.folder-sass_light.folder-sass-open.folder-sass-open_light.folder-scala.folder-scala_light.folder-scala-open.folder-scala-open_light.folder-scons.folder-scons_light.folder-scons-open.folder-scons-open_light.folder-scripts.folder-scripts_light.folder-scripts-open.folder-scripts-open_light.folder-secure.folder-secure_light.folder-secure-open.folder-secure-open_light.folder-seeders.folder-seeders_light.folder-seeders-open.folder-seeders-open_light.folder-server.folder-server_light.folder-server-open.folder-server-open_light.folder-serverless.folder-serverless_light.folder-serverless-open.folder-serverless-open_light.folder-shader.folder-shader_light.folder-shader-open.folder-shader-open_light.folder-shared.folder-shared_light.folder-shared-open.folder-shared-open_light.folder-snapcraft.folder-snapcraft_light.folder-snapcraft-open.folder-snapcraft-open_light.folder-snippet.folder-snippet_light.folder-snippet-open.folder-snippet-open_light.folder-src.folder-src_light.folder-src-open.folder-src-open_light.folder-src-tauri.folder-src-tauri_light.folder-src-tauri-open.folder-src-tauri-open_light.folder-stack.folder-stack_light.folder-stack-open.folder-stack-open_light.folder-stencil.folder-stencil_light.folder-stencil-open.folder-stencil-open_light.folder-store.folder-store_light.folder-store-open.folder-store-open_light.folder-storybook.folder-storybook_light.folder-storybook-open.folder-storybook-open_light.folder-stylus.folder-stylus_light.folder-stylus-open.folder-stylus-open_light.folder-sublime.folder-sublime_light.folder-sublime-open.folder-sublime-open_light.folder-supabase.folder-supabase_light.folder-supabase-open.folder-supabase-open_light.folder-svelte.folder-svelte_light.folder-svelte-open.folder-svelte-open_light.folder-svg.folder-svg_light.folder-svg-open.folder-svg-open_light.folder-syntax.folder-syntax_light.folder-syntax-open.folder-syntax-open_light.folder-target.folder-target_light.folder-target-open.folder-target-open_light.folder-taskfile.folder-taskfile_light.folder-taskfile-open.folder-taskfile-open_light.folder-tasks.folder-tasks_light.folder-tasks-open.folder-tasks-open_light.folder-television.folder-television_light.folder-television-open.folder-television-open_light.folder-temp.folder-temp_light.folder-temp-open.folder-temp-open_light.folder-template.folder-template_light.folder-template-open.folder-template-open_light.folder-terraform.folder-terraform_light.folder-terraform-open.folder-terraform-open_light.folder-test.folder-test_light.folder-test-open.folder-test-open_light.folder-theme.folder-theme_light.folder-theme-open.folder-theme-open_light.folder-tools.folder-tools_light.folder-tools-open.folder-tools-open_light.folder-trash.folder-trash_light.folder-trash-open.folder-trash-open_light.folder-trigger.folder-trigger_light.folder-trigger-open.folder-trigger-open_light.folder-turborepo.folder-turborepo_light.folder-turborepo-open.folder-turborepo-open_light.folder-typescript.folder-typescript_light.folder-typescript-open.folder-typescript-open_light.folder-ui.folder-ui_light.folder-ui-open.folder-ui-open_light.folder-unity.folder-unity_light.folder-unity-open.folder-unity-open_light.folder-update.folder-update_light.folder-update-open.folder-update-open_light.folder-upload.folder-upload_light.folder-upload-open.folder-upload-open_light.folder-utils.folder-utils_light.folder-utils-open.folder-utils-open_light.folder-vercel.folder-vercel_light.folder-vercel-open.folder-vercel-open_light.folder-verdaccio.folder-verdaccio_light.folder-verdaccio-open.folder-verdaccio-open_light.folder-video.folder-video_light.folder-video-open.folder-video-open_light.folder-views.folder-views_light.folder-views-open.folder-views-open_light.folder-vm.folder-vm_light.folder-vm-open.folder-vm-open_light.folder-vscode.folder-vscode_light.folder-vscode-open.folder-vscode-open_light.folder-vue.folder-vue_light.folder-vue-directives.folder-vue-directives_light.folder-vue-directives-open.folder-vue-directives-open_light.folder-vue-open.folder-vue-open_light.folder-vuepress.folder-vuepress_light.folder-vuepress-open.folder-vuepress-open_light.folder-vuex-store.folder-vuex-store_light.folder-vuex-store-open.folder-vuex-store-open_light.folder-wakatime.folder-wakatime_light.folder-wakatime-open.folder-wakatime-open_light.folder-webpack.folder-webpack_light.folder-webpack-open.folder-webpack-open_light.folder-windows.folder-windows_light.folder-windows-open.folder-windows-open_light.folder-wordpress.folder-wordpress_light.folder-wordpress-open.folder-wordpress-open_light.folder-yarn.folder-yarn_light.folder-yarn-open.folder-yarn-open_light.folder-zeabur.folder-zeabur_light.folder-zeabur-open.folder-zeabur-open_light.font.font_light.forth.forth_light.fortran.fortran_light.foxpro.foxpro_light.freemarker.freemarker_light.fsharp.fsharp_light.fusebox.fusebox_light.gamemaker.gamemaker_light.garden.garden_light.gatsby.gatsby_light.gcp.gcp_light.gemfile.gemfile_light.gemini.gemini_light.gemini-ai.gemini-ai_light.git.git_light.github-actions-workflow.github-actions-workflow_light.github-sponsors.github-sponsors_light.gitlab.gitlab_light.gitpod.gitpod_light.gleam.gleam_light.gnuplot.gnuplot_light.go.go_gopher.go_gopher_light.go_light.go-mod.go-mod_light.godot.godot_light.godot-assets.godot-assets_light.gradle.gradle_light.grafana-alloy.grafana-alloy_light.grain.grain_light.graphcool.graphcool_light.graphql.graphql_light.gridsome.gridsome_light.groovy.groovy_light.grunt.grunt_light.gulp.gulp_light.h.h_light.hack.hack_light.hadolint.hadolint_light.haml.haml_light.handlebars.handlebars_light.hardhat.hardhat_light.harmonix.harmonix_light.haskell.haskell_light.haxe.haxe_light.hcl.hcl_light.helm.helm_light.heroku.heroku_light.hex.hex_light.histoire.histoire_light.hjson.hjson_light.horusec.horusec_light.hosts.hosts_light.hpp.hpp_light.html.html_light.http.http_light.huff.huff_light.hurl.hurl_light.husky.husky_light.i18n.i18n_light.idris.idris_light.ifanr-cloud.ifanr-cloud_light.image.image_light.imba.imba_light.installation.installation_light.ionic.ionic_light.istanbul.istanbul_light.jar.jar_light.java.java_light.javaclass.javaclass_light.javascript.javascript_light.javascript-map.javascript-map_light.jenkins.jenkins_light.jest.jest_light.jinja.jinja_light.jsconfig.jsconfig_light.json.json_light.jsr.jsr_light.julia.julia_light.jupyter.jupyter_light.just.just_light.karma.karma_light.kcl.kcl_light.key.key_light.keystatic.keystatic_light.kivy.kivy_light.kl.kl_light.knip.knip_light.kotlin.kotlin_light.kubernetes.kubernetes_light.kusto.kusto_light.label.label_light.laravel.laravel_light.latexmk.latexmk_light.lbx.lbx_light.lefthook.lefthook_light.lerna.lerna_light.less.less_light.liara.liara_light.lib.lib_light.lighthouse.lighthouse_light.lilypond.lilypond_light.lintstaged.lintstaged_light.liquid.liquid_light.lisp.lisp_light.livescript.livescript_light.lock.lock_light.log.log_light.lolcode.lolcode_light.lottie.lottie_light.lua.lua_light.luau.luau_light.lyric.lyric_light.makefile.makefile_light.markdoc.markdoc_light.markdoc-config.markdoc-config_light.markdown.markdown_light.markdownlint.markdownlint_light.markojs.markojs_light.mathematica.mathematica_light.matlab.matlab_light.maven.maven_light.mdsvex.mdsvex_light.mdx.mdx_light.mercurial.mercurial_light.merlin.merlin_light.mermaid.mermaid_light.meson.meson_light.minecraft.minecraft_light.minecraft-fabric.minecraft-fabric_light.mint.mint_light.mjml.mjml_light.mocha.mocha_light.modernizr.modernizr_light.mojo.mojo_light.moon.moon_light.moonscript.moonscript_light.mxml.mxml_light.nano-staged.nano-staged_light.ndst.ndst_light.nest.nest_light.netlify.netlify_light.next.next_light.nginx.nginx_light.ngrx-actions.ngrx-actions_light.ngrx-effects.ngrx-effects_light.ngrx-entity.ngrx-entity_light.ngrx-reducer.ngrx-reducer_light.ngrx-selectors.ngrx-selectors_light.ngrx-state.ngrx-state_light.nim.nim_light.nix.nix_light.nodejs.nodejs_alt.nodejs_alt_light.nodejs_light.nodemon.nodemon_light.npm.npm_light.nuget.nuget_light.nunjucks.nunjucks_light.nuxt.nuxt_light.nx.nx_light.objective-c.objective-c_light.objective-cpp.objective-cpp_light.ocaml.ocaml_light.odin.odin_light.opa.opa_light.opam.opam_light.openapi.openapi_light.otne.otne_light.oxlint.oxlint_light.packship.packship_light.palette.palette_light.panda.panda_light.parcel.parcel_light.pascal.pascal_light.pawn.pawn_light.payload.payload_light.pdf.pdf_light.pdm.pdm_light.percy.percy_light.perl.perl_light.php.php_elephant.php_elephant_light.php_elephant_pink.php_elephant_pink_light.php_light.php-cs-fixer.php-cs-fixer_light.phpstan.phpstan_light.phpunit.phpunit_light.pinejs.pinejs_light.pipeline.pipeline_light.pkl.pkl_light.plastic.plastic_light.playwright.playwright_light.plop.plop_light.pm2-ecosystem.pm2-ecosystem_light.pnpm.pnpm_light.poetry.poetry_light.postcss.postcss_light.posthtml.posthtml_light.powerpoint.powerpoint_light.powershell.powershell_light.pre-commit.pre-commit_light.prettier.prettier_light.prisma.prisma_light.processing.processing_light.prolog.prolog_light.prompt.prompt_light.proto.proto_light.protractor.protractor_light.pug.pug_light.puppet.puppet_light.puppeteer.puppeteer_light.purescript.purescript_light.python.python_light.python-misc.python-misc_light.pytorch.pytorch_light.qsharp.qsharp_light.quarto.quarto_light.quasar.quasar_light.quokka.quokka_light.qwik.qwik_light.r.r_light.racket.racket_light.raml.raml_light.razor.razor_light.rbxmk.rbxmk_light.rc.rc_light.react.react_light.react_ts.react_ts_light.readme.readme_light.reason.reason_light.red.red_light.redux-action.redux-action_light.redux-reducer.redux-reducer_light.redux-selector.redux-selector_light.redux-store.redux-store_light.regedit.regedit_light.remark.remark_light.remix.remix_light.renovate.renovate_light.replit.replit_light.rescript.rescript_light.rescript-interface.rescript-interface_light.restql.restql_light.riot.riot_light.roadmap.roadmap_light.roblox.roblox_light.robot.robot_light.robots.robots_light.rocket.rocket_light.rojo.rojo_light.rollup.rollup_light.rome.rome_light.routing.routing_light.rspec.rspec_light.rubocop.rubocop_light.ruby.ruby_light.ruff.ruff_light.rust.rust_light.salesforce.salesforce_light.san.san_light.sas.sas_light.sass.sass_light.sbt.sbt_light.scala.scala_light.scheme.scheme_light.scons.scons_light.screwdriver.screwdriver_light.search.search_light.semantic-release.semantic-release_light.semgrep.semgrep_light.sentry.sentry_light.sequelize.sequelize_light.serverless.serverless_light.settings.settings_light.shader.shader_light.silverstripe.silverstripe_light.simulink.simulink_light.siyuan.siyuan_light.sketch.sketch_light.slim.slim_light.slint.slint_light.slug.slug_light.smarty.smarty_light.sml.sml_light.snakemake.snakemake_light.snapcraft.snapcraft_light.snowpack.snowpack_light.snyk.snyk_light.solidity.solidity_light.sonarcloud.sonarcloud_light.spwn.spwn_light.stackblitz.stackblitz_light.stan.stan_light.steadybit.steadybit_light.stencil.stencil_light.stitches.stitches_light.storybook.storybook_light.stryker.stryker_light.stylable.stylable_light.stylelint.stylelint_light.stylus.stylus_light.sublime.sublime_light.subtitles.subtitles_light.supabase.supabase_light.svelte.svelte_light.svg.svg_light.svgo.svgo_light.svgr.svgr_light.swagger.swagger_light.sway.sway_light.swc.swc_light.swift.swift_light.syncpack.syncpack_light.systemd.systemd_light.table.table_light.tailwindcss.tailwindcss_light.taskfile.taskfile_light.tauri.tauri_light.taze.taze_light.tcl.tcl_light.teal.teal_light.templ.templ_light.template.template_light.terraform.terraform_light.test-js.test-js_light.test-jsx.test-jsx_light.test-ts.test-ts_light.tex.tex_light.textlint.textlint_light.tilt.tilt_light.tldraw.tldraw_light.tobi.tobi_light.tobimake.tobimake_light.todo.todo_light.toml.toml_light.travis.travis_light.tree.tree_light.trigger.trigger_light.tsconfig.tsconfig_light.tsdoc.tsdoc_light.tsil.tsil_light.tune.tune_light.turborepo.turborepo_light.twig.twig_light.twine.twine_light.typescript.typescript_light.typescript-def.typescript-def_light.typst.typst_light.umi.umi_light.uml.uml_light.unity.unity_light.unocss.unocss_light.url.url_light.uv.uv_light.vagrant.vagrant_light.vala.vala_light.vanilla-extract.vanilla-extract_light.varnish.varnish_light.vedic.vedic_light.velite.velite_light.velocity.velocity_light.vercel.vercel_light.verdaccio.verdaccio_light.verified.verified_light.verilog.verilog_light.vfl.vfl_light.video.video_light.vim.vim_light.virtual.virtual_light.visualstudio.visualstudio_light.vite.vite_light.vitest.vitest_light.vlang.vlang_light.vscode.vscode_light.vue.vue_light.vue-config.vue-config_light.vuex-store.vuex-store_light.wakatime.wakatime_light.wallaby.wallaby_light.wally.wally_light.watchman.watchman_light.webassembly.webassembly_light.webhint.webhint_light.webpack.webpack_light.wepy.wepy_light.werf.werf_light.windicss.windicss_light.wolframlanguage.wolframlanguage_light.word.word_light.wrangler.wrangler_light.wxt.wxt_light.xaml.xaml_light.xmake.xmake_light.xml.xml_light.yaml.yaml_light.yang.yang_light.yarn.yarn_light.zeabur.zeabur_light.zig.zig_light.zip.zip_light`.split(`.`)),yu=`<?xml version="1.0" encoding="UTF-8"?>
9
9
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">
10
10
  <defs>
11
11
  <symbol id="3d" viewBox="0 0 24 24">
@@ -6514,15 +6514,15 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
6514
6514
  </symbol>
6515
6515
  </defs>
6516
6516
  </svg>
6517
- `,bu=`oc-file-type-icon-sprite-root`;(()=>{if(typeof document>`u`||document.getElementById(bu))return;let e=()=>{if(document.getElementById(bu))return;let e=document.createElement(`div`);e.id=bu,e.setAttribute(`aria-hidden`,`true`),e.style.position=`absolute`,e.style.width=`0`,e.style.height=`0`,e.style.overflow=`hidden`,e.innerHTML=yu,document.body.appendChild(e)};if(document.body){e();return}document.addEventListener(`DOMContentLoaded`,e,{once:!0})})();var xu={dockerfile:`docker`,makefile:`makefile`,gnumakefile:`makefile`,"cmakelists.txt":`cmake`,"package-lock.json":`npm`,"yarn.lock":`yarn`,"pnpm-lock.yaml":`pnpm`,"bun.lock":`bun`,"bun.lockb":`bun`,"tsconfig.json":`tsconfig`,"jsconfig.json":`jsconfig`,".gitignore":`git`,".gitattributes":`git`,".gitmodules":`git`,".editorconfig":`editorconfig`,".npmrc":`npm`,".yarnrc":`yarn`,".prettierrc":`prettier`,".eslintrc":`eslint`,".babelrc":`babel`},Su={javascript:`javascript`,jsx:`react`,typescript:`typescript`,tsx:`react_ts`,html:`html`,handlebars:`handlebars`,twig:`twig`,liquid:`liquid`,css:`css`,scss:`sass`,sass:`sass`,less:`less`,stylus:`stylus`,json:`json`,yaml:`yaml`,toml:`toml`,xml:`xml`,ini:`settings`,properties:`settings`,bash:`console`,powershell:`powershell`,batch:`console`,python:`python`,ruby:`ruby`,erb:`ruby`,php:`php`,java:`java`,kotlin:`kotlin`,scala:`scala`,groovy:`groovy`,c:`c`,cpp:`cpp`,objectivec:`objective-c`,csharp:`csharp`,fsharp:`fsharp`,go:`go`,rust:`rust`,swift:`swift`,dart:`dart`,lua:`lua`,perl:`perl`,r:`r`,julia:`julia`,haskell:`haskell`,elixir:`elixir`,erlang:`erlang`,clojure:`clojure`,lisp:`lisp`,scheme:`scheme`,ocaml:`ocaml`,reason:`reason`,nim:`nim`,zig:`zig`,v:`vlang`,crystal:`crystal`,d:`d`,sql:`database`,graphql:`graphql`,solidity:`solidity`,nasm:`assembly`,nix:`nix`,hcl:`terraform`,puppet:`puppet`,latex:`tex`,bibtex:`bibliography`,markdown:`markdown`,asciidoc:`asciidoc`,text:`document`,vim:`vim`,makefile:`makefile`,cmake:`cmake`,diff:`diff`,prisma:`prisma`,protobuf:`proto`,thrift:`document`,wasm:`webassembly`,glsl:`shader`,hlsl:`shader`,cg:`shader`,apacheconf:`settings`,nginx:`nginx`},Cu={yml:`yaml`,mdx:`mdx`,md:`markdown`,lock:`lock`,env:`settings`,zip:`zip`,tgz:`zip`,gz:`zip`,rar:`zip`,"7z":`zip`,png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,svg:`svg`,webp:`image`,avif:`image`,bmp:`image`,ico:`favicon`,mp3:`audio`,wav:`audio`,flac:`audio`,ogg:`audio`,mp4:`video`,mov:`video`,avi:`video`,mkv:`video`,webm:`video`,pdf:`pdf`,doc:`word`,docx:`word`,ppt:`powerpoint`,pptx:`powerpoint`},wu=`document`,Tu=(e,t)=>{if(!e)return t===`light`?`${wu}_light`:wu;if(t===`light`){let t=e.endsWith(`_light`)?e:`${e}_light`;return vu.has(t)?t:e}return e},Eu=e=>typeof e==`string`&&e.trim().length>0,Du=(e,t)=>{let n=e.replace(/\\/g,`/`).split(`/`).pop()?.toLowerCase()||``;if(xu[n])return xu[n];if(n.startsWith(`.env`))return`settings`;let r=ns(e);if(r&&Su[r])return Su[r];let i=Eu(t)?t.toLowerCase():n.includes(`.`)&&n.split(`.`).pop()?.toLowerCase()||``;return i&&Cu[i]?Cu[i]:i&&vu.has(i)?i:wu},Ou=(e,t)=>{let n=t?.isDirectory?`folder`:Du(e,t?.extension);return`#${Tu(vu.has(n)?n:wu,t?.themeVariant||`dark`)}`},ku=e=>{let t=(0,Q.c)(12),{filePath:n,extension:r,isDirectory:i,className:a}=e,o=Ba()?.currentTheme.metadata.variant===`light`?`light`:`dark`,s;t[0]!==r||t[1]!==n||t[2]!==i||t[3]!==o?(s=Ou(n,{extension:r,isDirectory:i,themeVariant:o}),t[0]=r,t[1]=n,t[2]=i,t[3]=o,t[4]=s):s=t[4];let c=s,l;t[5]===a?l=t[6]:(l=Y(`block h-4 w-4 flex-shrink-0`,a),t[5]=a,t[6]=l);let u;t[7]===c?u=t[8]:(u=(0,$.jsx)(`use`,{href:c,xlinkHref:c}),t[7]=c,t[8]=u);let d;return t[9]!==l||t[10]!==u?(d=(0,$.jsx)(`svg`,{className:l,"aria-hidden":`true`,focusable:`false`,children:u}),t[9]=l,t[10]=u,t[11]=d):d=t[11],d},Au=(0,Z.memo)(()=>{let{t:e}=st(),t=(0,Z.useRef)(null),n=Lt(e=>e.addAttachedFile),r=s(e=>e.isMobile),i=Do(),a=i.runtime.isVSCode,o=r?`h-9 w-9`:`h-7 w-7`,c=r?`h-5 w-5`:`h-[1.125rem] w-[1.125rem]`,l=async t=>{for(let r=0;r<t.length;r++){let i=t[r];try{await n(i)}catch(t){console.error(`File attach failed`,t),wr.error(t instanceof Error?t.message:e(`chat.fileAttachment.toast.attachFailed`))}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:t,type:`file`,multiple:!0,className:`hidden`,onChange:async e=>{let n=e.target.files;n&&(await l(n),t.current&&(t.current.value=``))}}),(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:a?async()=>{try{let t=await i.vscode?.pickFiles?.(),n=Array.isArray(t?.files)?t.files:[],r=Array.isArray(t?.skipped)?t.skipped:[];if(r.length>0){let t=r.map(t=>`${t?.name||e(`chat.fileAttachment.fileFallback`)}: ${t?.reason||e(`chat.fileAttachment.skippedFallback`)}`).join(`
6518
- `);wr.error(e(`chat.fileAttachment.toast.someFilesSkipped`,{summary:t}))}let a=n.map(t=>{if(!t?.dataUrl)return null;try{let[n,r]=t.dataUrl.split(`,`),i=t.mimeType||n?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!r)return null;let a=atob(r),o=new Uint8Array(a.length);for(let e=0;e<a.length;e++)o[e]=a.charCodeAt(e);let s=new Blob([o],{type:i});return new File([s],t.name||e(`chat.fileAttachment.fileFallback`),{type:i})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);a.length>0&&await l(a)}catch(t){console.error(`VS Code file pick failed`,t),wr.error(t instanceof Error?t.message:e(`chat.fileAttachment.toast.vscodePickFailed`))}}:()=>t.current?.click(),className:Y(`flex items-center justify-center rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`hover:bg-muted text-muted-foreground`,o),"aria-label":e(`chat.fileAttachment.actions.attachAria`),children:(0,$.jsx)(X,{name:`attachment-2`,className:c})})}),(0,$.jsx)(La,{side:`top`,children:(0,$.jsx)(`p`,{children:e(`chat.fileAttachment.actions.attach`)})})]})]})});Au.displayName=`FileAttachmentButton`;var ju=(0,Z.memo)(e=>{let t=(0,Q.c)(78),{file:n,onRemove:r,onShowPopup:i,gallery:a,index:o}=e,s=o===void 0?0:o,{t:c}=st(),{isMobile:l,isTablet:u}=fo(),d=l||u,f=n.source!==`server`&&n.mimeType.startsWith(`image/`)&&typeof n.dataUrl==`string`&&n.dataUrl.startsWith(`data:image/`)?n.dataUrl:n.serverPath||``,p=is()??``,m=xo(f,p),h=`attachment-image:${n.id}`,g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=cs(),t[0]=g):g=t[0];let _=Z.useRef(g),v=rd,y=id,b;t[1]===n.filename?b=t[2]:(b=v(n.filename),t[1]=n.filename,t[2]=b);let x=b,S;t[3]===n.filename?S=t[4]:(S=y(n.filename),t[3]=n.filename,t[4]=S);let C=S,w;t[5]!==m||t[6]!==x||t[7]!==p||t[8]!==n.mimeType||t[9]!==f?(w=()=>{!f&&!m||To({sourceUrl:f||m,displayUrl:m||void 0,filename:x,mimeType:n.mimeType,effectiveDirectory:p})},t[5]=m,t[6]=x,t[7]=p,t[8]=n.mimeType,t[9]=f,t[10]=w):w=t[10];let T=K(w),E;t[11]!==x||t[12]!==n.mimeType||t[13]!==n.size||t[14]!==a||t[15]!==f||t[16]!==s||t[17]!==h||t[18]!==i?(E=()=>{_.current.consumeClick(h)||!i||!f||i({open:!0,title:x||`Image`,content:``,metadata:{tool:`image-preview`,filename:x,mime:n.mimeType,size:n.size},image:{url:f,mimeType:n.mimeType,filename:x,size:n.size,gallery:a,index:s}})},t[11]=x,t[12]=n.mimeType,t[13]=n.size,t[14]=a,t[15]=f,t[16]=s,t[17]=h,t[18]=i,t[19]=E):E=t[19];let D=K(E);if(!f){let e;t[20]!==C||t[21]!==n.filename?(e=(0,$.jsx)(ku,{filePath:n.filename,extension:C,className:`h-4 w-4`}),t[20]=C,t[21]=n.filename,t[22]=e):e=t[22];let i;t[23]===x?i=t[24]:(i=(0,$.jsx)(`span`,{className:`text-foreground truncate max-w-[12.5rem]`,children:x}),t[23]=x,t[24]=i);let a;t[25]===r?a=t[26]:(a=e=>{e.stopPropagation(),r()},t[25]=r,t[26]=a);let o;t[27]!==x||t[28]!==c?(o=c(`chat.fileAttachment.actions.removeNamed`,{name:x}),t[27]=x,t[28]=c,t[29]=o):o=t[29];let s;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`}),t[30]=s):s=t[30];let l;t[31]!==o||t[32]!==a?(l=(0,$.jsx)(`span`,{onClick:a,className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,"aria-label":o,children:s}),t[31]=o,t[32]=a,t[33]=l):l=t[33];let u;return t[34]!==l||t[35]!==e||t[36]!==i?(u=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 text-sm hover:opacity-80 transition-opacity text-left h-5`,children:[e,i,l]}),t[34]=l,t[35]=e,t[36]=i,t[37]=u):u=t[37],u}let O=i?`button`:void 0,k=i?0:void 0,A;t[38]!==D||t[39]!==i?(A=e=>{i&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),D())},t[38]=D,t[39]=i,t[40]=A):A=t[40];let j;t[41]!==h||t[42]!==T?(j=e=>{(e.pointerType!==`mouse`||e.button===0)&&_.current.start({pointerId:e.pointerId,key:h,clientX:e.clientX,clientY:e.clientY,onTrigger:T})},t[41]=h,t[42]=T,t[43]=j):j=t[43];let M,N,P;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(M=e=>{_.current.move(e.pointerId,e.clientX,e.clientY)},N=e=>{_.current.end(e.pointerId)},P=e=>{_.current.cancel(e.pointerId)},t[44]=M,t[45]=N,t[46]=P):(M=t[44],N=t[45],P=t[46]);let F;t[47]!==h||t[48]!==T?(F=e=>{e.preventDefault(),e.stopPropagation(),_.current.openFromContextMenu(h,T)},t[47]=h,t[48]=T,t[49]=F):F=t[49];let I=m||void 0,L;t[50]!==x||t[51]!==I?(L=(0,$.jsx)(`img`,{src:I,alt:x,className:`h-full w-full object-cover`,loading:`lazy`,draggable:!1}),t[50]=x,t[51]=I,t[52]=L):L=t[52];let R;t[53]===r?R=t[54]:(R=e=>{e.stopPropagation(),r()},t[53]=r,t[54]=R);let z=d?`opacity-100`:`opacity-0 group-hover:opacity-100`,B;t[55]===z?B=t[56]:(B=Y(`absolute top-0.5 right-0.5 h-4 w-4 rounded-full bg-transparent text-foreground hover:text-destructive flex items-center justify-center transition-opacity focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,z),t[55]=z,t[56]=B);let V;t[57]===c?V=t[58]:(V=c(`chat.fileAttachment.actions.removeImage`),t[57]=c,t[58]=V);let H;t[59]!==x||t[60]!==c?(H=c(`chat.fileAttachment.actions.removeNamed`,{name:x}),t[59]=x,t[60]=c,t[61]=H):H=t[61];let U;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,$.jsx)(X,{name:`close`,className:`h-2.5 w-2.5`}),t[62]=U):U=t[62];let ee;t[63]!==R||t[64]!==B||t[65]!==V||t[66]!==H?(ee=(0,$.jsx)(`button`,{onClick:R,className:B,title:V,"aria-label":H,children:U}),t[63]=R,t[64]=B,t[65]=V,t[66]=H,t[67]=ee):ee=t[67];let te;return t[68]!==x||t[69]!==D||t[70]!==j||t[71]!==F||t[72]!==L||t[73]!==ee||t[74]!==O||t[75]!==k||t[76]!==A?(te=(0,$.jsxs)(`div`,{role:O,tabIndex:k,onClick:D,onKeyDown:A,onPointerDown:j,onPointerMove:M,onPointerUp:N,onPointerCancel:P,onContextMenu:F,"data-attachment-preview":`true`,className:`relative h-10 w-10 rounded-lg border border-border/40 bg-muted/10 overflow-hidden flex-shrink-0 group cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"aria-label":x,children:[L,ee]}),t[68]=x,t[69]=D,t[70]=j,t[71]=F,t[72]=L,t[73]=ee,t[74]=O,t[75]=k,t[76]=A,t[77]=te):te=t[77],te});ju.displayName=`ImagePreview`;var Mu=e=>({displayName:(e=>{let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e})(e.filename),fileSize:(e=>!Number.isFinite(e)||e<=0?``:e<1024?e+` B`:e<1048576?(e/1024).toFixed(1)+` KB`:(e/1048576).toFixed(1)+` MB`)(e.size),extension:(e=>{let t=e.split(`.`);return t.length>1?t[t.length-1].toLowerCase():``})(e.filename)}),Nu=(0,Z.memo)(e=>{let t=(0,Q.c)(25),{file:n,onRemove:r}=e,{t:i}=st(),{displayName:a,extension:o}=Mu(n),s=/:\d+(?:-\d+)?$/.test(a),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c={borderColor:`var(--syntax-punctuation)`},t[0]=c):c=t[0];let l=n.vscodePath,u;t[1]===r?u=t[2]:(u=e=>{e.stopPropagation(),r()},t[1]=r,t[2]=u);let d;t[3]===i?d=t[4]:(d=i(`chat.fileAttachment.activeEditor.remove`),t[3]=i,t[4]=d);let f;t[5]===i?f=t[6]:(f=i(`chat.fileAttachment.activeEditor.remove`),t[5]=i,t[6]=f);let p;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`}),t[7]=p):p=t[7];let m;t[8]!==u||t[9]!==d||t[10]!==f?(m=(0,$.jsx)(`span`,{"data-remove-button":!0,onClick:u,className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,"aria-label":d,title:f,children:p}),t[8]=u,t[9]=d,t[10]=f,t[11]=m):m=t[11];let h;t[12]!==o||t[13]!==n.filename?(h=(0,$.jsx)(ku,{filePath:n.filename,extension:o,className:`h-4 w-4`}),t[12]=o,t[13]=n.filename,t[14]=h):h=t[14];let g=s?`whitespace-nowrap`:`truncate max-w-[12.5rem]`,_;t[15]===g?_=t[16]:(_=Y(`text-foreground`,g),t[15]=g,t[16]=_);let v;t[17]!==a||t[18]!==_?(v=(0,$.jsx)(`span`,{className:_,children:a}),t[17]=a,t[18]=_,t[19]=v):v=t[19];let y;return t[20]!==n.vscodePath||t[21]!==v||t[22]!==m||t[23]!==h?(y=(0,$.jsxs)(`button`,{type:`button`,onClick:ad,className:`inline-flex items-center gap-1 text-xs pr-1 rounded-sm border border-solid bg-transparent text-foreground not-italic hover:opacity-90 transition-colors text-left`,style:c,title:l,children:[m,h,v]}),t[20]=n.vscodePath,t[21]=v,t[22]=m,t[23]=h,t[24]=y):y=t[24],y});Nu.displayName=`VSCodeFileChip`;var Pu=(0,Z.memo)(e=>{let t=(0,Q.c)(13),{attachments:n,onShowPopup:r,onRemoveAttachedFile:i}=e,a=n,o,s,c,l;if(t[0]!==a||t[1]!==i||t[2]!==r){l=Symbol.for(`react.early_return_sentinel`);bb0:{let e=a.filter(od);if(e.length===0){l=null;break bb0}let n=e.filter(sd),u=e.filter(cd),d=n.map(ld).filter(ud);o=`flex items-center gap-2 flex-wrap`,s=n.map((e,t)=>(0,$.jsx)(ju,{file:e,onRemove:()=>i(e),onShowPopup:r,gallery:d,index:t},e.id));let f;t[7]===i?f=t[8]:(f=e=>(0,$.jsx)(Nu,{file:e,onRemove:()=>i(e)},e.id),t[7]=i,t[8]=f),c=u.map(f)}t[0]=a,t[1]=i,t[2]=r,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[9]!==o||t[10]!==s||t[11]!==c?(u=(0,$.jsxs)(`div`,{className:o,children:[s,c]}),t[9]=o,t[10]=s,t[11]=c,t[12]=u):u=t[12],u});Pu.displayName=`AttachedVSCodeFileChips`;var Fu=(0,Z.memo)(e=>{let t=(0,Q.c)(13),{attachments:n,onShowPopup:r,onRemoveAttachedFile:i}=e,a=n,o,s,c,l;if(t[0]!==a||t[1]!==i||t[2]!==r){l=Symbol.for(`react.early_return_sentinel`);bb0:{let e=a.filter(dd);if(e.length===0){l=null;break bb0}let t=e.map(fd).filter(pd);c=`pb-4 w-full px-1`,o=`flex items-center gap-1.5 flex-wrap`,s=e.map((e,n)=>(0,$.jsx)(ju,{file:e,onRemove:()=>i(e),onShowPopup:r,gallery:t,index:n},e.id))}t[0]=a,t[1]=i,t[2]=r,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;t[7]!==o||t[8]!==s?(u=(0,$.jsx)(`div`,{className:o,children:s}),t[7]=o,t[8]=s,t[9]=u):u=t[9];let d;return t[10]!==c||t[11]!==u?(d=(0,$.jsx)(`div`,{className:c,children:u}),t[10]=c,t[11]=u,t[12]=d):d=t[12],d});Fu.displayName=`AttachedFilesList`;var Iu=(e,t)=>e.some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t),Lu=(e,t,n)=>!!n&&e.some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n&&e.vscodePath===t),Ru=(0,Z.memo)(e=>{let t=(0,Q.c)(41),{attachedFiles:n,onAddVSCodeFile:r,onAddVSCodeSelection:i}=e,{t:a}=st(),o=Lt(md),s=Lt(hd);if(!Do().runtime.isVSCode||!o)return null;let{filePath:c,fileName:l,relativePath:u,selection:d,fileSize:f}=o,p;t[0]!==n||t[1]!==c?(p=Iu(n,c),t[0]=n,t[1]=c,t[2]=p):p=t[2];let m=p,h=``;d&&(h=d.startLine===d.endLine?`${d.startLine}`:`${d.startLine}-${d.endLine}`);let g=d?`${u}:${h}`:``,_;t[3]!==n||t[4]!==c||t[5]!==g?(_=Lu(n,c,g),t[3]=n,t[4]=c,t[5]=g,t[6]=_):_=t[6];let v=_;if(m&&(!d||v))return null;let y;t[7]===l?y=t[8]:(y=l.split(`.`).pop()||``,t[7]=l,t[8]=y);let b=y,x=l,S;t[9]!==l||t[10]!==c||t[11]!==f||t[12]!==r||t[13]!==s?(S=()=>{r(c,l,f),s(re(l),`append-inline`)},t[9]=l,t[10]=c,t[11]=f,t[12]=r,t[13]=s,t[14]=S):S=t[14];let C=S,w;t[15]!==c||t[16]!==i||t[17]!==d||t[18]!==g||t[19]!==s?(w=async()=>{if(!d)return;let e=new Blob([d.text],{type:`text/plain`}),t=new File([e],g,{type:`text/plain`});await i(c,t),s(re(g),`append-inline`)},t[15]=c,t[16]=i,t[17]=d,t[18]=g,t[19]=s,t[20]=w):w=t[20];let T=w,E=!!d&&!v,D=!E&&!m;if(!E&&!D)return null;let O;t[21]!==x||t[22]!==b||t[23]!==l||t[24]!==T||t[25]!==u||t[26]!==h||t[27]!==E||t[28]!==a?(O=E&&(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 text-xs pr-1 rounded-sm italic text-muted-foreground border border-dashed bg-transparent`,style:{borderColor:`var(--syntax-punctuation)`},title:u,children:[(0,$.jsx)(`button`,{type:`button`,title:a(`chat.fileAttachment.activeEditor.pinSelection`),"aria-label":a(`chat.fileAttachment.activeEditor.pinSelection`),onClick:()=>{T()},className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,children:(0,$.jsx)(X,{name:`pushpin-2`,className:`h-4 w-4`})}),(0,$.jsx)(ku,{filePath:l,extension:b,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:`${x}:${h}`})]}),t[21]=x,t[22]=b,t[23]=l,t[24]=T,t[25]=u,t[26]=h,t[27]=E,t[28]=a,t[29]=O):O=t[29];let k;t[30]!==x||t[31]!==b||t[32]!==l||t[33]!==C||t[34]!==u||t[35]!==D||t[36]!==a?(k=D&&(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 text-xs pr-1 rounded-sm italic text-muted-foreground border border-dashed bg-transparent`,style:{borderColor:`var(--syntax-punctuation)`},title:u,children:[(0,$.jsx)(`button`,{type:`button`,title:a(`chat.fileAttachment.activeEditor.addFile`,{name:x}),"aria-label":a(`chat.fileAttachment.activeEditor.addFile`,{name:x}),onClick:C,className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,children:(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`})}),(0,$.jsx)(ku,{filePath:l,extension:b,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs truncate max-w-[13.75rem]`,children:x})]}),t[30]=x,t[31]=b,t[32]=l,t[33]=C,t[34]=u,t[35]=D,t[36]=a,t[37]=k):k=t[37];let A;return t[38]!==O||t[39]!==k?(A=(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[O,k]}),t[38]=O,t[39]=k,t[40]=A):A=t[40],A});Ru.displayName=`ActiveEditorFileSuggestion`;var zu=`application/vnd.github.issue-link`,Bu=`application/vnd.github.pull-request-link`,Vu=e=>e.mime===zu?`issue`:e.mime===Bu?`pr`:null,Hu=e=>{let t=typeof e.id==`string`?e.id.trim():``;if(t)return`part:${t}`;let n=typeof e.filename==`string`?e.filename.trim().toLowerCase():``,r=typeof e.mime==`string`?e.mime.trim().toLowerCase():``;if(r.startsWith(`image/`)&&n)return`image:${n}|${r}`;let i=typeof e.url==`string`?e.url.trim():``;return i?`url:${i}`:`meta:${n}|${r}|${e.size??``}`},Uu=e=>{let t=new Map,n=[];for(let r of e){if(r.type!==`file`||!(r.mime||r.url)||Oe(r))continue;let e=Hu(r),i=t.get(e);if(i===void 0){t.set(e,n.length),n.push(r);continue}n[i]?.slim===!0&&r.slim!==!0&&(n[i]=r)}return n},Wu=(e,t)=>{let n=new Map,r=new Map;for(let e of t){if(e.type!==`file`||e.slim===!0||typeof e.url!=`string`||!e.url)continue;let t=e;typeof e.id==`string`&&e.id&&n.set(e.id,t),typeof e.filename==`string`&&e.filename&&r.set(e.filename,t)}return n.size===0&&r.size===0?Uu(e):Uu(e.map(e=>e.type!==`file`||typeof e.url==`string`&&e.url&&e.slim!==!0?e:e.id&&n.has(e.id)?n.get(e.id)??e:e.filename&&r.has(e.filename)?r.get(e.filename)??e:e))},Gu=e=>e.failed||e.repositoryStatus===`error`?`error`:e.flightActive||e.repositoryStatus===`loading`?`loading`:e.hasSlimImage&&e.repositoryStatus===`ready`?`idle`:e.repositoryStatus,Ku=e=>/^(?:data|blob|https?):/i.test(e),qu=e=>{for(let t of[e.byteSize,e.size])if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t},Ju=(e,t)=>t.some(t=>t.type===`file`&&t.mime?.startsWith(`image/`)===!0&&t.slim===!0&&!t.url&&bo(e,qu(t))),Yu=(e,t)=>t.type!==`file`||t.mime?.startsWith(`image/`)!==!0||typeof t.url!=`string`||!t.url||Ku(t.url)?!1:bo(e,qu(t)),Xu=e=>Y(`grid gap-2`,e===1?`grid-cols-1 max-w-56`:`grid-cols-2`),Zu=e=>{let t=(0,Q.c)(9),{source:n,filename:r,sizeText:i,onOpen:a,materializationStatus:o,onRetry:s}=e,c=o===void 0?`ready`:o,{t:l}=st(),u=is()??``,d=xo(n??``,u),f;return t[0]!==d||t[1]!==r||t[2]!==c||t[3]!==a||t[4]!==s||t[5]!==i||t[6]!==n||t[7]!==l?(f=(0,$.jsx)(`div`,{className:`relative aspect-square min-w-0 overflow-hidden rounded-lg border border-border/40 bg-muted/10`,"data-message-image-slot":`true`,children:n?(0,$.jsxs)(`button`,{type:`button`,onClick:a,className:`group absolute inset-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary`,"aria-label":r,children:[(0,$.jsx)(`img`,{src:d||void 0,alt:r,className:`h-full w-full object-cover`,loading:`lazy`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-t from-black/60 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity`}),(0,$.jsxs)(`div`,{className:`absolute bottom-0 left-0 right-0 p-2 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium truncate`,children:r}),i&&(0,$.jsx)(`p`,{className:`text-xs opacity-80`,children:i})]})]}):(0,$.jsxs)(`div`,{className:Y(`absolute inset-0 flex flex-col items-center justify-center gap-2 p-4 text-center typography-meta text-muted-foreground`,c===`error`&&`text-[var(--status-error)]`),role:c===`error`?`alert`:`status`,"aria-label":r,children:[c===`loading`?(0,$.jsx)(X,{name:`loader-4`,className:`size-5 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:c===`error`?`error-warning`:`file-image`,className:`size-5`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:c===`loading`?l(`chat.fileAttachment.image.loading`):c===`error`?l(`chat.fileAttachment.image.loadFailed`):r}),c===`error`&&s?(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:l(`chat.fileAttachment.image.retry`)}):null]})}),t[0]=d,t[1]=r,t[2]=c,t[3]=a,t[4]=s,t[5]=i,t[6]=n,t[7]=l,t[8]=f):f=t[8],f},Qu=e=>{let t=(0,Q.c)(11),{images:n,onLoad:r}=e,{t:i}=st(),a;t[0]===i?a=t[1]:(a=i(`chat.fileAttachment.image.loadManually`),t[0]=i,t[1]=a);let o=a,s;if(t[2]!==o||t[3]!==n||t[4]!==r){let e;t[6]!==o||t[7]!==r?(e=e=>(0,$.jsxs)(la,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>r(e.key),"aria-label":o,className:`group h-auto min-h-8 min-w-0 justify-start gap-2 whitespace-normal border border-border/30 bg-muted/60 px-2 py-1.5 text-left hover:bg-[var(--interactive-hover)]`,"data-manual-image-load-item":e.key,children:[(0,$.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md border border-border/40 bg-background/70 text-muted-foreground transition-colors group-hover:text-foreground`,children:(0,$.jsx)(X,{name:`file-image`,className:`size-4`,"aria-hidden":`true`})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate typography-meta text-foreground`,children:e.filename}),e.sizeText&&(0,$.jsx)(`span`,{className:`block text-xs leading-tight text-muted-foreground`,children:e.sizeText})]})]},e.key),t[6]=o,t[7]=r,t[8]=e):e=t[8],s=n.map(e),t[2]=o,t[3]=n,t[4]=r,t[5]=s}else s=t[5];let c;return t[9]===s?c=t[10]:(c=(0,$.jsx)(`div`,{className:`col-span-full flex flex-col gap-1.5`,"data-manual-image-load-group":`true`,children:s}),t[9]=s,t[10]=c),c},$u={threshold:.01},ed=new Set,td=(0,Z.memo)(({files:e,messageID:t,sessionID:n,onShowPopup:r,compact:i=!1})=>{let{t:a}=st(),o=is()??``,c=n||e.find(e=>typeof e.sessionID==`string`&&e.sessionID)?.sessionID||``,l=_r(t,o,c||void 0),[u,d]=Z.useState(()=>Tr(t)??[]),f=Z.useRef(null),p=Z.useRef(!1),m=Z.useRef(null),h=Z.useRef(!1),g=Z.useRef(new Set),_=Z.useRef(``),[,v]=Z.useReducer(e=>e+1,0),y=`${o}\n${c}\n${t}`;_.current!==y&&(_.current=y,p.current=!1,m.current=null,h.current=!1,g.current=new Set,d(Tr(t)??[]));for(let t of e)t.type===`file`&&t.slim===!0&&t.mime?.startsWith(`image/`)&&g.current.add(Hu(t));let b=e=>{if(!e)return`Unnamed file`;let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e},x=Z.useMemo(()=>e=>Vu(e)!==null&&typeof e.filename==`string`&&e.filename.trim().length>0?e.filename.trim():b(e.filename||e.url)||a(`chat.fileAttachment.fileFallback`),[a]),S=e=>!e||!Number.isFinite(e)||e<=0?``:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`,C=Z.useMemo(()=>Wu(e,[...l,...u]),[u,e,l]),w=wo(),T=Z.useMemo(()=>Ju(w,C),[C,w]),[E,D]=Z.useState({scope:``,keys:ed}),O=E.scope===y?E.keys:ed,k=Z.useMemo(()=>{if(!ho(w))return ed;let e=new Set;for(let t of C){let n=Hu(t);O.has(n)||Yu(w,t)&&e.add(n)}return e},[O,C,w]),A=C.filter(e=>e.mime?.startsWith(`image/`)),j=A.filter(e=>!!e.url),M=C.filter(e=>!e.mime?.startsWith(`image/`)),N=A.some(e=>e.slim===!0),P=T&&A.some(e=>e.slim===!0&&!O.has(Hu(e))),F=A.filter(e=>{let t=Hu(e);return O.has(t)?!1:e.slim===!0?T:k.has(t)}),I=new Set(F.map(Hu)),L=A.filter(e=>{let t=Hu(e);return!I.has(t)&&(g.current.has(t)||!!e.url)}),R=F.map(e=>({key:Hu(e),filename:x(e),sizeText:S(qu(e))})),z=K((e=!1)=>{if(!N||!o||!c||!t||!e&&p.current||m.current)return;p.current=!0,h.current=!1;let n=Bi(o,c,t).then(()=>{let e=Tr(t);e&&e.length>0&&d(e)}).catch(()=>{let e=Tr(t);if(e&&e.length>0){d(e);return}h.current=!0}).finally(()=>{m.current=null,v()});m.current=n,v()}),B=K(e=>{D(t=>{let n=t.scope===y?new Set(t.keys):new Set;return n.add(e),{scope:y,keys:n}}),N&&z(!0)});nt(N&&!P?f:null,e=>{e.some(e=>e.isIntersecting)&&z(!1)},$u),Z.useEffect(()=>{if(!N||P)return;let e=f.current;if(!e)return;let t=e.closest(`[data-scrollbar="chat"]`);if(!t||typeof IntersectionObserver>`u`){z(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();n.bottom>r.top&&n.top<r.bottom&&z(!1)},[o,N,t,c,P]);let V=N&&o&&c?Wi(o,c,t).status:`ready`,H=C.some(e=>e.mime?.startsWith(`image/`)===!0&&typeof e.url==`string`&&e.url.length>0&&e.slim!==!0)?`ready`:Gu({hasSlimImage:N,flightActive:!!m.current,failed:h.current,repositoryStatus:V}),U=Z.useMemo(()=>j.flatMap(e=>{if(!e.url)return[];let t=x(e)||`Image`;return[{url:e.url,mimeType:e.mime,filename:t,size:e.size}]}),[j,x]),ee=K(e=>{if(!r)return;let t=j.findIndex(t=>Hu(t)===Hu(e)),n=U[t];if(!n?.url)return;let i=n.filename||`Image`;r({open:!0,title:i,content:``,metadata:{tool:`image-preview`,filename:i,mime:n.mimeType,size:n.size},image:{url:n.url,mimeType:n.mimeType,filename:i,size:n.size,gallery:U,index:t}})});return C.length===0?null:i?(0,$.jsxs)(`div`,{ref:f,className:`space-y-1.5 mt-1.5`,"data-message-files":t,children:[M.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:M.map(e=>{let t=x(e),n=t.split(`.`).pop()||``,r=S(e.size),i=Vu(e),a=Pe(e.mime)||Fe(e.filename)||Fe(e.url);return(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:i&&e.url?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{Xo(e.url||``)},className:`inline-flex items-center bg-muted/30 border border-border/30 typography-meta gap-1 px-2 py-0.5 rounded-lg text-foreground hover:text-primary transition-colors`,children:[i===`pr`?(0,$.jsx)(X,{name:`git-pull-request`,className:`text-muted-foreground h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`github`,className:`text-muted-foreground h-3.5 w-3.5`}),(0,$.jsx)(`div`,{className:`overflow-hidden max-w-[13.75rem]`,children:(0,$.jsx)(`span`,{className:`truncate block`,title:t,children:t})})]}):(0,$.jsxs)(`div`,{className:`inline-flex items-center bg-muted/30 border border-border/30 typography-meta gap-1 px-2 py-0.5 rounded-lg`,children:[e.mime?.includes(`pdf`)?(0,$.jsx)(X,{name:`file-pdf`,className:`text-muted-foreground h-3.5 w-3.5`}):(0,$.jsx)(ku,{filePath:t,extension:n,isDirectory:a,className:`text-muted-foreground h-3.5 w-3.5`}),(0,$.jsx)(`div`,{className:`overflow-hidden max-w-[8.75rem]`,children:(0,$.jsx)(`span`,{className:`truncate block`,title:t,children:t})})]})}),(0,$.jsx)(La,{children:(0,$.jsxs)(`p`,{children:[t,r?` (${r})`:``]})})]},`file-${Hu(e)}`)})}),R.length>0?(0,$.jsx)(Qu,{images:R,onLoad:B}):null,L.length>0?(0,$.jsx)(`div`,{className:Xu(L.length),children:L.map(e=>{let t=x(e);return(0,$.jsx)(Zu,{source:e.url,filename:t,sizeText:S(qu(e)),materializationStatus:e.url?`ready`:H,onRetry:()=>z(!0),onOpen:e.url?()=>ee(e):void 0},Hu(e))})}):null]}):(0,$.jsxs)(`div`,{ref:f,"data-message-files":t,className:Y(`grid gap-2`,i?`grid-cols-1`:`grid-cols-1 sm:grid-cols-2`),children:[R.length>0?(0,$.jsx)(Qu,{images:R,onLoad:B}):null,C.map(e=>{let t=x(e),n=e.mime?.startsWith(`image/`),o=S(e.size),c=Vu(e);if(I.has(Hu(e)))return null;if(n&&e.url)return(0,$.jsx)(Zu,{source:e.url,filename:t,sizeText:o,onOpen:()=>ee(e)},Hu(e));if(n)return(0,$.jsx)(Zu,{filename:t,sizeText:o,materializationStatus:H,onRetry:()=>z(!0)},Hu(e));if(c&&e.url)return(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{Xo(e.url||``)},className:Y(`flex items-center gap-2 p-2 rounded-lg border border-border/40 bg-muted/10 hover:bg-muted/20 transition-colors text-left`,i?`text-xs`:`text-sm`),children:[(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:c===`pr`?(0,$.jsx)(X,{name:`git-pull-request`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):(0,$.jsx)(X,{name:`github`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`font-medium truncate`,children:t}),o&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})]})}),(0,$.jsx)(La,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Hu(e));let l=e.source,u=typeof l?.type==`string`?l.type:void 0,d=l&&typeof l.path==`string`?l.path:void 0,f=u===`file`&&d?d:e.url||``;return f&&ts(f)?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{s.getState().navigateToDiagram(f)},className:Y(`flex items-center gap-2 p-2 rounded-lg border border-border/40 bg-muted/10 hover:bg-muted/20 transition-colors text-left cursor-pointer`,i?`text-xs`:`text-sm`),children:[(0,$.jsx)(X,{name:`file`,className:Y(`text-muted-foreground shrink-0`,i?`h-3.5 w-3.5`:`h-4 w-4`)}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`font-medium truncate`,children:t}),(0,$.jsx)(`p`,{className:`text-xs text-status-info`,children:a(`chat.fileAttachment.openInDiagram`)})]}),(0,$.jsx)(X,{name:`external-link`,className:Y(`text-muted-foreground shrink-0`,i?`h-3 w-3`:`h-3.5 w-3.5`)})]})}),(0,$.jsx)(La,{children:(0,$.jsx)(`p`,{children:a(`chat.fileAttachment.openInDiagram`)})})]},Hu(e)):(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{r&&e.url&&r({open:!0,title:t,content:``,image:{url:e.url,mimeType:e.mime,filename:t}})},className:Y(`flex items-center gap-2 p-2 rounded-lg border border-border/40 bg-muted/10 hover:bg-muted/20 transition-colors text-left`,i?`text-xs`:`text-sm`),children:[(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:e.mime?.startsWith(`image/`)?(0,$.jsx)(X,{name:`file-image`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):Pe(e.mime)||Fe(e.filename)||Fe(e.url)?(0,$.jsx)(ku,{filePath:t,isDirectory:!0,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):e.mime?.includes(`pdf`)?(0,$.jsx)(X,{name:`file-pdf`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):(0,$.jsx)(X,{name:`file`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`font-medium truncate`,children:t}),o&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})]})}),(0,$.jsx)(La,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Hu(e))})]})});td.displayName=`MessageFilesDisplay`;var nd=(0,Z.memo)(e=>{let t=(0,Q.c)(14),{urls:n,caption:r,onShowPopup:i}=e;if(n.length===0)return null;let a;t[0]===n.length?a=t[1]:(a=Xu(n.length),t[0]=n.length,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=n.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i?.({open:!0,title:r||`Image ${t+1} of ${n.length}`,content:``,image:{url:e,gallery:n.map(gd),index:t}}),className:`relative aspect-square rounded-lg border border-border/40 bg-muted/10 overflow-hidden group`,children:[(0,$.jsx)(`img`,{src:e,alt:r||`Image ${t+1}`,className:`h-full w-full object-cover transition-transform group-hover:scale-105`,loading:`lazy`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors`})]},e)),t[2]=r,t[3]=i,t[4]=n,t[5]=o):o=t[5];let s;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];let c;t[9]===r?c=t[10]:(c=r&&(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:r}),t[9]=r,t[10]=c);let l;return t[11]!==s||t[12]!==c?(l=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[s,c]}),t[11]=s,t[12]=c,t[13]=l):l=t[13],l});nd.displayName=`ImageGallery`;function rd(e){let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e}function id(e){let t=e.split(`.`);return t.length>1?t[t.length-1].toLowerCase():``}function ad(e){e.target.closest(`[data-remove-button]`)}function od(e){return e.source===`vscode`&&e.vscodeSource===`file`}function sd(e){return e.mimeType.startsWith(`image/`)}function cd(e){return!e.mimeType.startsWith(`image/`)}function ld(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function ud(e){return e.url}function dd(e){return e.source!==`server`&&e.source!==`vscode`&&e.mimeType.startsWith(`image/`)}function fd(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function pd(e){return e.url}function md(e){return e.activeEditorFile}function hd(e){return e.setPendingInputText}function gd(e){return{url:e}}var _d=`text-[var(--primary)]`,vd=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,yd=/(^|\s)\/(\u2003)?([A-Za-z0-9][A-Za-z0-9_-]*)/g,bd=/\[skill:([A-Za-z0-9][A-Za-z0-9_-]*)\]/g,xd=/\[command:([^\]\r\n]+)\]/g,Sd=/(^|[\s([{])(@session:([A-Za-z0-9_-]+))(?=$|[\s)\]},.!?;:])/g,Cd=/@([^\s]+)/g,wd=` `,Td=e=>e.replaceAll(`\\`,`/`).split(`/`).at(-1)?.replace(/\.md$/,``)??``,Ed=e=>e.trim().toLowerCase(),Dd=(e,t)=>{let n=t>0?e[t-1]:null;return!n||/(\s|\(|\)|\[|\]|\{|\}|"|'|`|,|\.|;|:)/.test(n)},Od=e=>e.includes(`/`)||e.includes(`\\`)||e.includes(`.`),kd=(e,t)=>{e.push(t)},Ad={kind:`skill`,priority:120,shouldScan:e=>e.includes(`/`)||e.includes(`[skill:`),detect:(e,t)=>{let n=[],r=t.skillNames;bd.lastIndex=0;let i;for(;(i=bd.exec(e))!==null;){let e=i[1];kd(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(yd.lastIndex=0;(i=yd.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)||kd(n,{start:s,end:c,kind:`skill`,raw:e.slice(s,c),label:`/${o}`,payload:{kind:`skill`,skillName:o}})}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:_d,href:us(t),skillName:t}}},jd={kind:`command`,priority:115,shouldScan:(e,t)=>e.includes(`[command:`)||!!t.commandNames?.size&&e.includes(`/`),detect:(e,t)=>{let n=[];xd.lastIndex=0;let r;for(;(r=xd.exec(e))!==null;){let e=r[1],t=Td(e);t&&kd(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(yd.lastIndex=0;(r=yd.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)||kd(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:_d})},Md={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=W(e.slice(i+1,a)).trim(),s=Ed(o),c=t.citationIcons?.get(s),l=!c&&vd.test(o),u=c??(l?`image`:null);if(!u){r=a+1;continue}let d=t.citationDisplayNames?.get(s)??o;kd(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:_d,filename:t}}},Nd={kind:`session`,priority:105,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[];Sd.lastIndex=0;let r;for(;(r=Sd.exec(e))!==null;){let i=r[3],a=r.index+r[1].length,o=a+r[2].length,s=t.sessionTitles?.get(i)??i;kd(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=[`@${wd}${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&&kd(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:_d,sessionId:t}}},Pd={kind:`file`,priority:100,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[],r=t.agentNames,i=t.filePaths,a=t.allowPathHeuristics===!0;Cd.lastIndex=0;let o;for(;(o=Cd.exec(e))!==null;){let t=o.index;if(!Dd(e,t)||o[1].startsWith(`session:`))continue;let s=o[1].trim().replace(/[),.;:!?`"'>]+$/g,``);if(!s)continue;let c=t+1+s.length,l=e.slice(t,c);if(r?.has(s.toLowerCase())){kd(n,{start:t,end:c,kind:`agent`,raw:l,label:l,payload:{kind:`agent`,agentName:s}});continue}let u=s.replace(/\\/g,`/`).replace(/^\.\//,``);(i?.has(s)||i?.has(u)||i?.has(u.replace(/^\/+/,``))||a&&Od(s))&&kd(n,{start:t,end:c,kind:`file`,raw:l,label:l,payload:{kind:`file`,path:s}})}return n},decorate:e=>{if(e.kind===`agent`&&e.payload.kind===`agent`)return{kind:`agent`,label:e.label,icon:null,className:_d,href:ps(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:_d,path:t}}},Fd=[Ad,jd,Md,Nd,Pd],Id=(e,t=Fd)=>{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`?Md.decorate(e):e.kind===`agent`?Pd.decorate(e):{kind:e.kind,label:e.label,icon:null,className:_d}},Ld=[`/`,`[`,`@`],Rd=e=>{if(!e)return!1;for(let t of Ld)if(e.includes(t))return!0;return!1},zd=(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)},Bd=(e,t={},n=Fd)=>{if(!Rd(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 zd(r,i)},Vd=(e,t,n=Fd)=>{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:Id(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}]},Hd=(e,t={},n=Fd)=>{if(!Rd(e))return null;let r=Bd(e,t,n);return r.length===0?null:Vd(e,r,n)},Ud=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,Wd=e=>e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`\\\\`),Gd=(e,t)=>!!t?.startsWith(`image/`)||Ud.test(e),Kd=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,Gd(e,i)?`image`:`attachment`)}return t},qd=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=W(e.slice(r+1,i)).trim();Wd(a)&&Ud.test(a)&&t.push(a),n=i+1}return t},Jd=(e,t)=>{let n=Kd(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&&Gd(e,typeof t.mime==`string`?t.mime:void 0)&&i.push(e)}if(i.length===0)return{icons:n,displayNames:r};let a=qd(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}},Yd=e=>{switch(e.kind){case`session`:return{trigger:`@`,icon:`chat-thread`,label:e.label};case`skill`:return{trigger:`/`,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}},Xd=e=>{let t=(0,Q.c)(27),{decoration:n,onOpenSkill:r,interactive:i}=e,a=i===void 0||i,o;t[0]===n?o=t[1]:(o=Yd(n),t[0]=n,t[1]=o);let s=o,c=s?.icon??n.icon,l=s?.label??n.label,u=s?`${s.trigger}${te}`:te,d;t[2]===n.className?d=t[3]:(d=Y(`whitespace-nowrap`,n.className),t[2]=n.className,t[3]=d);let f;t[4]!==c||t[5]!==u?(f=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:z,right:z},children:(0,$.jsx)(X,{name:c,className:Y(N,`shrink-0`),"aria-hidden":`true`})})]}):null,t[4]=c,t[5]=u,t[6]=f):f=t[6];let p;t[7]!==n.kind||t[8]!==l||t[9]!==d||t[10]!==f?(p=(0,$.jsxs)(`span`,{className:d,"data-message-reference-kind":n.kind,children:[f,l]}),t[7]=n.kind,t[8]=l,t[9]=d,t[10]=f,t[11]=p):p=t[11];let m=p;if(!a)return m;if(n.kind===`skill`&&n.skillName&&r){let e;t[12]!==n.skillName||t[13]!==r?(e=e=>{e.stopPropagation(),r(n.skillName)},t[12]=n.skillName,t[13]=r,t[14]=e):e=t[14];let i;return t[15]!==m||t[16]!==n.skillName||t[17]!==e?(i=(0,$.jsx)(`button`,{type:`button`,className:`inline hover:underline`,"data-skill-name":n.skillName,onClick:e,children:m}),t[15]=m,t[16]=n.skillName,t[17]=e,t[18]=i):i=t[18],i}if(n.kind===`agent`&&n.href){let e;t[19]!==n.agentName||t[20]!==n.label?(e=n.agentName||n.label.replace(/^@/,``),t[19]=n.agentName,t[20]=n.label,t[21]=e):e=t[21];let r;t[22]===e?r=t[23]:(r=os(e),t[22]=e,t[23]=r);let i;return t[24]!==m||t[25]!==r?(i=(0,$.jsx)(`a`,{href:r,className:`inline hover:underline`,target:`_blank`,rel:`noopener noreferrer`,"data-openchamber-agent-mention":`true`,onClick:Zd,children:m}),t[24]=m,t[25]=r,t[26]=i):i=t[26],i}return m};Xd.displayName=`MessageReferenceChip`;function Zd(e){return e.stopPropagation()}var Qd=e=>e!==`frozen`,$d=(e,t)=>e.length===0?t:t.length===0?e:[...e,...t],ef=e=>e.status===`committed`&&e.current===!0,tf=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}},nf=(e,t)=>{let n=e.status??`queued`;return!t&&(n===`queued`||n===`retrying`||n===`failed`||n===`unresolved`)},rf=(e,t,n)=>Ri(e)||t||e.manualDispatchRequested===!0&&!n?.allowManualDispatchRetry?!1:[`queued`,`retrying`,`failed`,`unresolved`].includes(e.status),af=(e,t)=>!t.frozen&&!Ri(e),of=(e,t)=>!(t.frozen||Ri(e)),sf=e=>e.status===`sending`||e.status===`reconciling`,cf=e=>e.status===`sending`||e.status===`reconciling`,lf=e=>e.manualDispatchRequested===!0||e.status===`sending`||e.status===`reconciling`,uf=e=>e.status===`sending`||e.status===`reconciling`,df=8e3,ff=(e,t)=>e.transportIdentity===t.transportIdentity&&e.runtimeGeneration===t.runtimeGeneration&&S(e.directory)===S(t.directory)&&e.sessionID===t.sessionID&&e.scopeID===t.scopeID,pf=(e,t)=>e.filter(e=>ff(e,t)),mf=(e,t,n)=>e.filter(e=>ff(e,t)&&Number.isSafeInteger(e.committedRevision)&&e.committedRevision>0&&(n===void 0||n<e.committedRevision)),hf=(e,t)=>{if(t.kind===`send`)return e;if(t.kind===`edit`||t.kind===`remove`){let n=e.findIndex(e=>!Ri(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(Ri(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},gf=(e,t)=>t.reduce(hf,e),_f=(e,t)=>{let n=gf(e,t),r=n.filter(e=>Ri(e)||!uf(e));return r.length===n.length?n:r},vf=(e,t,n)=>({requestID:n,scopeID:e.scopeID,revision:e.revision,item:t}),yf=(e,t,n,r)=>({scopeID:e.scopeID,scopeRevision:e.revision,item:t,targetKey:n,expectedRevision:r}),bf=(e,t,n,r,i=e.items)=>{let a=i.filter(e=>!Ri(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}},xf=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},Sf=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}ke({source:n.source??`local`,vscodeSource:n.vscodeSource,mimeType:n.mimeType})&&t.set(r,`attachment`)}return t},Cf=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},wf=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}},Tf=e=>(e.split(`
6517
+ `,bu=`oc-file-type-icon-sprite-root`;(()=>{if(typeof document>`u`||document.getElementById(bu))return;let e=()=>{if(document.getElementById(bu))return;let e=document.createElement(`div`);e.id=bu,e.setAttribute(`aria-hidden`,`true`),e.style.position=`absolute`,e.style.width=`0`,e.style.height=`0`,e.style.overflow=`hidden`,e.innerHTML=yu,document.body.appendChild(e)};if(document.body){e();return}document.addEventListener(`DOMContentLoaded`,e,{once:!0})})();var xu={dockerfile:`docker`,makefile:`makefile`,gnumakefile:`makefile`,"cmakelists.txt":`cmake`,"package-lock.json":`npm`,"yarn.lock":`yarn`,"pnpm-lock.yaml":`pnpm`,"bun.lock":`bun`,"bun.lockb":`bun`,"tsconfig.json":`tsconfig`,"jsconfig.json":`jsconfig`,".gitignore":`git`,".gitattributes":`git`,".gitmodules":`git`,".editorconfig":`editorconfig`,".npmrc":`npm`,".yarnrc":`yarn`,".prettierrc":`prettier`,".eslintrc":`eslint`,".babelrc":`babel`},Su={javascript:`javascript`,jsx:`react`,typescript:`typescript`,tsx:`react_ts`,html:`html`,handlebars:`handlebars`,twig:`twig`,liquid:`liquid`,css:`css`,scss:`sass`,sass:`sass`,less:`less`,stylus:`stylus`,json:`json`,yaml:`yaml`,toml:`toml`,xml:`xml`,ini:`settings`,properties:`settings`,bash:`console`,powershell:`powershell`,batch:`console`,python:`python`,ruby:`ruby`,erb:`ruby`,php:`php`,java:`java`,kotlin:`kotlin`,scala:`scala`,groovy:`groovy`,c:`c`,cpp:`cpp`,objectivec:`objective-c`,csharp:`csharp`,fsharp:`fsharp`,go:`go`,rust:`rust`,swift:`swift`,dart:`dart`,lua:`lua`,perl:`perl`,r:`r`,julia:`julia`,haskell:`haskell`,elixir:`elixir`,erlang:`erlang`,clojure:`clojure`,lisp:`lisp`,scheme:`scheme`,ocaml:`ocaml`,reason:`reason`,nim:`nim`,zig:`zig`,v:`vlang`,crystal:`crystal`,d:`d`,sql:`database`,graphql:`graphql`,solidity:`solidity`,nasm:`assembly`,nix:`nix`,hcl:`terraform`,puppet:`puppet`,latex:`tex`,bibtex:`bibliography`,markdown:`markdown`,asciidoc:`asciidoc`,text:`document`,vim:`vim`,makefile:`makefile`,cmake:`cmake`,diff:`diff`,prisma:`prisma`,protobuf:`proto`,thrift:`document`,wasm:`webassembly`,glsl:`shader`,hlsl:`shader`,cg:`shader`,apacheconf:`settings`,nginx:`nginx`},Cu={yml:`yaml`,mdx:`mdx`,md:`markdown`,lock:`lock`,env:`settings`,zip:`zip`,tgz:`zip`,gz:`zip`,rar:`zip`,"7z":`zip`,png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,svg:`svg`,webp:`image`,avif:`image`,bmp:`image`,ico:`favicon`,mp3:`audio`,wav:`audio`,flac:`audio`,ogg:`audio`,mp4:`video`,mov:`video`,avi:`video`,mkv:`video`,webm:`video`,pdf:`pdf`,doc:`word`,docx:`word`,ppt:`powerpoint`,pptx:`powerpoint`},wu=`document`,Tu=(e,t)=>{if(!e)return t===`light`?`${wu}_light`:wu;if(t===`light`){let t=e.endsWith(`_light`)?e:`${e}_light`;return vu.has(t)?t:e}return e},Eu=e=>typeof e==`string`&&e.trim().length>0,Du=(e,t)=>{let n=e.replace(/\\/g,`/`).split(`/`).pop()?.toLowerCase()||``;if(xu[n])return xu[n];if(n.startsWith(`.env`))return`settings`;let r=ns(e);if(r&&Su[r])return Su[r];let i=Eu(t)?t.toLowerCase():n.includes(`.`)&&n.split(`.`).pop()?.toLowerCase()||``;return i&&Cu[i]?Cu[i]:i&&vu.has(i)?i:wu},Ou=(e,t)=>{let n=t?.isDirectory?`folder`:Du(e,t?.extension);return`#${Tu(vu.has(n)?n:wu,t?.themeVariant||`dark`)}`},ku=e=>{let t=(0,Q.c)(12),{filePath:n,extension:r,isDirectory:i,className:a}=e,o=Ba()?.currentTheme.metadata.variant===`light`?`light`:`dark`,s;t[0]!==r||t[1]!==n||t[2]!==i||t[3]!==o?(s=Ou(n,{extension:r,isDirectory:i,themeVariant:o}),t[0]=r,t[1]=n,t[2]=i,t[3]=o,t[4]=s):s=t[4];let c=s,l;t[5]===a?l=t[6]:(l=Y(`block h-4 w-4 flex-shrink-0`,a),t[5]=a,t[6]=l);let u;t[7]===c?u=t[8]:(u=(0,$.jsx)(`use`,{href:c,xlinkHref:c}),t[7]=c,t[8]=u);let d;return t[9]!==l||t[10]!==u?(d=(0,$.jsx)(`svg`,{className:l,"aria-hidden":`true`,focusable:`false`,children:u}),t[9]=l,t[10]=u,t[11]=d):d=t[11],d},Au=(0,Z.memo)(()=>{let{t:e}=ot(),t=(0,Z.useRef)(null),n=It(e=>e.addAttachedFile),r=s(e=>e.isMobile),i=Do(),a=i.runtime.isVSCode,o=r?`h-9 w-9`:`h-7 w-7`,c=r?`h-5 w-5`:`h-[1.125rem] w-[1.125rem]`,l=async t=>{for(let r=0;r<t.length;r++){let i=t[r];try{await n(i)}catch(t){console.error(`File attach failed`,t),Cr.error(t instanceof Error?t.message:e(`chat.fileAttachment.toast.attachFailed`))}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:t,type:`file`,multiple:!0,className:`hidden`,onChange:async e=>{let n=e.target.files;n&&(await l(n),t.current&&(t.current.value=``))}}),(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:a?async()=>{try{let t=await i.vscode?.pickFiles?.(),n=Array.isArray(t?.files)?t.files:[],r=Array.isArray(t?.skipped)?t.skipped:[];if(r.length>0){let t=r.map(t=>`${t?.name||e(`chat.fileAttachment.fileFallback`)}: ${t?.reason||e(`chat.fileAttachment.skippedFallback`)}`).join(`
6518
+ `);Cr.error(e(`chat.fileAttachment.toast.someFilesSkipped`,{summary:t}))}let a=n.map(t=>{if(!t?.dataUrl)return null;try{let[n,r]=t.dataUrl.split(`,`),i=t.mimeType||n?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!r)return null;let a=atob(r),o=new Uint8Array(a.length);for(let e=0;e<a.length;e++)o[e]=a.charCodeAt(e);let s=new Blob([o],{type:i});return new File([s],t.name||e(`chat.fileAttachment.fileFallback`),{type:i})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);a.length>0&&await l(a)}catch(t){console.error(`VS Code file pick failed`,t),Cr.error(t instanceof Error?t.message:e(`chat.fileAttachment.toast.vscodePickFailed`))}}:()=>t.current?.click(),className:Y(`flex items-center justify-center rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`hover:bg-muted text-muted-foreground`,o),"aria-label":e(`chat.fileAttachment.actions.attachAria`),children:(0,$.jsx)(X,{name:`attachment-2`,className:c})})}),(0,$.jsx)(La,{side:`top`,children:(0,$.jsx)(`p`,{children:e(`chat.fileAttachment.actions.attach`)})})]})]})});Au.displayName=`FileAttachmentButton`;var ju=(0,Z.memo)(e=>{let t=(0,Q.c)(78),{file:n,onRemove:r,onShowPopup:i,gallery:a,index:o}=e,s=o===void 0?0:o,{t:c}=ot(),{isMobile:l,isTablet:u}=fo(),d=l||u,f=n.source!==`server`&&n.mimeType.startsWith(`image/`)&&typeof n.dataUrl==`string`&&n.dataUrl.startsWith(`data:image/`)?n.dataUrl:n.serverPath||``,p=is()??``,m=xo(f,p),h=`attachment-image:${n.id}`,g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=cs(),t[0]=g):g=t[0];let _=Z.useRef(g),v=rd,y=id,b;t[1]===n.filename?b=t[2]:(b=v(n.filename),t[1]=n.filename,t[2]=b);let x=b,S;t[3]===n.filename?S=t[4]:(S=y(n.filename),t[3]=n.filename,t[4]=S);let C=S,w;t[5]!==m||t[6]!==x||t[7]!==p||t[8]!==n.mimeType||t[9]!==f?(w=()=>{!f&&!m||To({sourceUrl:f||m,displayUrl:m||void 0,filename:x,mimeType:n.mimeType,effectiveDirectory:p})},t[5]=m,t[6]=x,t[7]=p,t[8]=n.mimeType,t[9]=f,t[10]=w):w=t[10];let T=q(w),E;t[11]!==x||t[12]!==n.mimeType||t[13]!==n.size||t[14]!==a||t[15]!==f||t[16]!==s||t[17]!==h||t[18]!==i?(E=()=>{_.current.consumeClick(h)||!i||!f||i({open:!0,title:x||`Image`,content:``,metadata:{tool:`image-preview`,filename:x,mime:n.mimeType,size:n.size},image:{url:f,mimeType:n.mimeType,filename:x,size:n.size,gallery:a,index:s}})},t[11]=x,t[12]=n.mimeType,t[13]=n.size,t[14]=a,t[15]=f,t[16]=s,t[17]=h,t[18]=i,t[19]=E):E=t[19];let D=q(E);if(!f){let e;t[20]!==C||t[21]!==n.filename?(e=(0,$.jsx)(ku,{filePath:n.filename,extension:C,className:`h-4 w-4`}),t[20]=C,t[21]=n.filename,t[22]=e):e=t[22];let i;t[23]===x?i=t[24]:(i=(0,$.jsx)(`span`,{className:`text-foreground truncate max-w-[12.5rem]`,children:x}),t[23]=x,t[24]=i);let a;t[25]===r?a=t[26]:(a=e=>{e.stopPropagation(),r()},t[25]=r,t[26]=a);let o;t[27]!==x||t[28]!==c?(o=c(`chat.fileAttachment.actions.removeNamed`,{name:x}),t[27]=x,t[28]=c,t[29]=o):o=t[29];let s;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`}),t[30]=s):s=t[30];let l;t[31]!==o||t[32]!==a?(l=(0,$.jsx)(`span`,{onClick:a,className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,"aria-label":o,children:s}),t[31]=o,t[32]=a,t[33]=l):l=t[33];let u;return t[34]!==l||t[35]!==e||t[36]!==i?(u=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 text-sm hover:opacity-80 transition-opacity text-left h-5`,children:[e,i,l]}),t[34]=l,t[35]=e,t[36]=i,t[37]=u):u=t[37],u}let O=i?`button`:void 0,k=i?0:void 0,A;t[38]!==D||t[39]!==i?(A=e=>{i&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),D())},t[38]=D,t[39]=i,t[40]=A):A=t[40];let j;t[41]!==h||t[42]!==T?(j=e=>{(e.pointerType!==`mouse`||e.button===0)&&_.current.start({pointerId:e.pointerId,key:h,clientX:e.clientX,clientY:e.clientY,onTrigger:T})},t[41]=h,t[42]=T,t[43]=j):j=t[43];let M,N,P;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(M=e=>{_.current.move(e.pointerId,e.clientX,e.clientY)},N=e=>{_.current.end(e.pointerId)},P=e=>{_.current.cancel(e.pointerId)},t[44]=M,t[45]=N,t[46]=P):(M=t[44],N=t[45],P=t[46]);let F;t[47]!==h||t[48]!==T?(F=e=>{e.preventDefault(),e.stopPropagation(),_.current.openFromContextMenu(h,T)},t[47]=h,t[48]=T,t[49]=F):F=t[49];let I=m||void 0,L;t[50]!==x||t[51]!==I?(L=(0,$.jsx)(`img`,{src:I,alt:x,className:`h-full w-full object-cover`,loading:`lazy`,draggable:!1}),t[50]=x,t[51]=I,t[52]=L):L=t[52];let R;t[53]===r?R=t[54]:(R=e=>{e.stopPropagation(),r()},t[53]=r,t[54]=R);let z=d?`opacity-100`:`opacity-0 group-hover:opacity-100`,B;t[55]===z?B=t[56]:(B=Y(`absolute top-0.5 right-0.5 h-4 w-4 rounded-full bg-transparent text-foreground hover:text-destructive flex items-center justify-center transition-opacity focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,z),t[55]=z,t[56]=B);let V;t[57]===c?V=t[58]:(V=c(`chat.fileAttachment.actions.removeImage`),t[57]=c,t[58]=V);let H;t[59]!==x||t[60]!==c?(H=c(`chat.fileAttachment.actions.removeNamed`,{name:x}),t[59]=x,t[60]=c,t[61]=H):H=t[61];let U;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,$.jsx)(X,{name:`close`,className:`h-2.5 w-2.5`}),t[62]=U):U=t[62];let W;t[63]!==R||t[64]!==B||t[65]!==V||t[66]!==H?(W=(0,$.jsx)(`button`,{onClick:R,className:B,title:V,"aria-label":H,children:U}),t[63]=R,t[64]=B,t[65]=V,t[66]=H,t[67]=W):W=t[67];let ee;return t[68]!==x||t[69]!==D||t[70]!==j||t[71]!==F||t[72]!==L||t[73]!==W||t[74]!==O||t[75]!==k||t[76]!==A?(ee=(0,$.jsxs)(`div`,{role:O,tabIndex:k,onClick:D,onKeyDown:A,onPointerDown:j,onPointerMove:M,onPointerUp:N,onPointerCancel:P,onContextMenu:F,"data-attachment-preview":`true`,className:`relative h-10 w-10 rounded-lg border border-border/40 bg-muted/10 overflow-hidden flex-shrink-0 group cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"aria-label":x,children:[L,W]}),t[68]=x,t[69]=D,t[70]=j,t[71]=F,t[72]=L,t[73]=W,t[74]=O,t[75]=k,t[76]=A,t[77]=ee):ee=t[77],ee});ju.displayName=`ImagePreview`;var Mu=e=>({displayName:(e=>{let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e})(e.filename),fileSize:(e=>!Number.isFinite(e)||e<=0?``:e<1024?e+` B`:e<1048576?(e/1024).toFixed(1)+` KB`:(e/1048576).toFixed(1)+` MB`)(e.size),extension:(e=>{let t=e.split(`.`);return t.length>1?t[t.length-1].toLowerCase():``})(e.filename)}),Nu=(0,Z.memo)(e=>{let t=(0,Q.c)(25),{file:n,onRemove:r}=e,{t:i}=ot(),{displayName:a,extension:o}=Mu(n),s=/:\d+(?:-\d+)?$/.test(a),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c={borderColor:`var(--syntax-punctuation)`},t[0]=c):c=t[0];let l=n.vscodePath,u;t[1]===r?u=t[2]:(u=e=>{e.stopPropagation(),r()},t[1]=r,t[2]=u);let d;t[3]===i?d=t[4]:(d=i(`chat.fileAttachment.activeEditor.remove`),t[3]=i,t[4]=d);let f;t[5]===i?f=t[6]:(f=i(`chat.fileAttachment.activeEditor.remove`),t[5]=i,t[6]=f);let p;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`}),t[7]=p):p=t[7];let m;t[8]!==u||t[9]!==d||t[10]!==f?(m=(0,$.jsx)(`span`,{"data-remove-button":!0,onClick:u,className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,"aria-label":d,title:f,children:p}),t[8]=u,t[9]=d,t[10]=f,t[11]=m):m=t[11];let h;t[12]!==o||t[13]!==n.filename?(h=(0,$.jsx)(ku,{filePath:n.filename,extension:o,className:`h-4 w-4`}),t[12]=o,t[13]=n.filename,t[14]=h):h=t[14];let g=s?`whitespace-nowrap`:`truncate max-w-[12.5rem]`,_;t[15]===g?_=t[16]:(_=Y(`text-foreground`,g),t[15]=g,t[16]=_);let v;t[17]!==a||t[18]!==_?(v=(0,$.jsx)(`span`,{className:_,children:a}),t[17]=a,t[18]=_,t[19]=v):v=t[19];let y;return t[20]!==n.vscodePath||t[21]!==v||t[22]!==m||t[23]!==h?(y=(0,$.jsxs)(`button`,{type:`button`,onClick:ad,className:`inline-flex items-center gap-1 text-xs pr-1 rounded-sm border border-solid bg-transparent text-foreground not-italic hover:opacity-90 transition-colors text-left`,style:c,title:l,children:[m,h,v]}),t[20]=n.vscodePath,t[21]=v,t[22]=m,t[23]=h,t[24]=y):y=t[24],y});Nu.displayName=`VSCodeFileChip`;var Pu=(0,Z.memo)(e=>{let t=(0,Q.c)(13),{attachments:n,onShowPopup:r,onRemoveAttachedFile:i}=e,a=n,o,s,c,l;if(t[0]!==a||t[1]!==i||t[2]!==r){l=Symbol.for(`react.early_return_sentinel`);bb0:{let e=a.filter(od);if(e.length===0){l=null;break bb0}let n=e.filter(sd),u=e.filter(cd),d=n.map(ld).filter(ud);o=`flex items-center gap-2 flex-wrap`,s=n.map((e,t)=>(0,$.jsx)(ju,{file:e,onRemove:()=>i(e),onShowPopup:r,gallery:d,index:t},e.id));let f;t[7]===i?f=t[8]:(f=e=>(0,$.jsx)(Nu,{file:e,onRemove:()=>i(e)},e.id),t[7]=i,t[8]=f),c=u.map(f)}t[0]=a,t[1]=i,t[2]=r,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[9]!==o||t[10]!==s||t[11]!==c?(u=(0,$.jsxs)(`div`,{className:o,children:[s,c]}),t[9]=o,t[10]=s,t[11]=c,t[12]=u):u=t[12],u});Pu.displayName=`AttachedVSCodeFileChips`;var Fu=(0,Z.memo)(e=>{let t=(0,Q.c)(13),{attachments:n,onShowPopup:r,onRemoveAttachedFile:i}=e,a=n,o,s,c,l;if(t[0]!==a||t[1]!==i||t[2]!==r){l=Symbol.for(`react.early_return_sentinel`);bb0:{let e=a.filter(dd);if(e.length===0){l=null;break bb0}let t=e.map(fd).filter(pd);c=`pb-4 w-full px-1`,o=`flex items-center gap-1.5 flex-wrap`,s=e.map((e,n)=>(0,$.jsx)(ju,{file:e,onRemove:()=>i(e),onShowPopup:r,gallery:t,index:n},e.id))}t[0]=a,t[1]=i,t[2]=r,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;t[7]!==o||t[8]!==s?(u=(0,$.jsx)(`div`,{className:o,children:s}),t[7]=o,t[8]=s,t[9]=u):u=t[9];let d;return t[10]!==c||t[11]!==u?(d=(0,$.jsx)(`div`,{className:c,children:u}),t[10]=c,t[11]=u,t[12]=d):d=t[12],d});Fu.displayName=`AttachedFilesList`;var Iu=(e,t)=>e.some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t),Lu=(e,t,n)=>!!n&&e.some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n&&e.vscodePath===t),Ru=(0,Z.memo)(e=>{let t=(0,Q.c)(41),{attachedFiles:n,onAddVSCodeFile:r,onAddVSCodeSelection:i}=e,{t:a}=ot(),o=It(md),s=It(hd);if(!Do().runtime.isVSCode||!o)return null;let{filePath:c,fileName:l,relativePath:u,selection:d,fileSize:f}=o,p;t[0]!==n||t[1]!==c?(p=Iu(n,c),t[0]=n,t[1]=c,t[2]=p):p=t[2];let m=p,h=``;d&&(h=d.startLine===d.endLine?`${d.startLine}`:`${d.startLine}-${d.endLine}`);let g=d?`${u}:${h}`:``,_;t[3]!==n||t[4]!==c||t[5]!==g?(_=Lu(n,c,g),t[3]=n,t[4]=c,t[5]=g,t[6]=_):_=t[6];let v=_;if(m&&(!d||v))return null;let y;t[7]===l?y=t[8]:(y=l.split(`.`).pop()||``,t[7]=l,t[8]=y);let b=y,x=l,S;t[9]!==l||t[10]!==c||t[11]!==f||t[12]!==r||t[13]!==s?(S=()=>{r(c,l,f),s(ne(l),`append-inline`)},t[9]=l,t[10]=c,t[11]=f,t[12]=r,t[13]=s,t[14]=S):S=t[14];let C=S,w;t[15]!==c||t[16]!==i||t[17]!==d||t[18]!==g||t[19]!==s?(w=async()=>{if(!d)return;let e=new Blob([d.text],{type:`text/plain`}),t=new File([e],g,{type:`text/plain`});await i(c,t),s(ne(g),`append-inline`)},t[15]=c,t[16]=i,t[17]=d,t[18]=g,t[19]=s,t[20]=w):w=t[20];let T=w,E=!!d&&!v,D=!E&&!m;if(!E&&!D)return null;let O;t[21]!==x||t[22]!==b||t[23]!==l||t[24]!==T||t[25]!==u||t[26]!==h||t[27]!==E||t[28]!==a?(O=E&&(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 text-xs pr-1 rounded-sm italic text-muted-foreground border border-dashed bg-transparent`,style:{borderColor:`var(--syntax-punctuation)`},title:u,children:[(0,$.jsx)(`button`,{type:`button`,title:a(`chat.fileAttachment.activeEditor.pinSelection`),"aria-label":a(`chat.fileAttachment.activeEditor.pinSelection`),onClick:()=>{T()},className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,children:(0,$.jsx)(X,{name:`pushpin-2`,className:`h-4 w-4`})}),(0,$.jsx)(ku,{filePath:l,extension:b,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs whitespace-nowrap`,children:`${x}:${h}`})]}),t[21]=x,t[22]=b,t[23]=l,t[24]=T,t[25]=u,t[26]=h,t[27]=E,t[28]=a,t[29]=O):O=t[29];let k;t[30]!==x||t[31]!==b||t[32]!==l||t[33]!==C||t[34]!==u||t[35]!==D||t[36]!==a?(k=D&&(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 text-xs pr-1 rounded-sm italic text-muted-foreground border border-dashed bg-transparent`,style:{borderColor:`var(--syntax-punctuation)`},title:u,children:[(0,$.jsx)(`button`,{type:`button`,title:a(`chat.fileAttachment.activeEditor.addFile`,{name:x}),"aria-label":a(`chat.fileAttachment.activeEditor.addFile`,{name:x}),onClick:C,className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,children:(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`})}),(0,$.jsx)(ku,{filePath:l,extension:b,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs truncate max-w-[13.75rem]`,children:x})]}),t[30]=x,t[31]=b,t[32]=l,t[33]=C,t[34]=u,t[35]=D,t[36]=a,t[37]=k):k=t[37];let A;return t[38]!==O||t[39]!==k?(A=(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[O,k]}),t[38]=O,t[39]=k,t[40]=A):A=t[40],A});Ru.displayName=`ActiveEditorFileSuggestion`;var zu=`application/vnd.github.issue-link`,Bu=`application/vnd.github.pull-request-link`,Vu=e=>e.mime===zu?`issue`:e.mime===Bu?`pr`:null,Hu=e=>{let t=typeof e.id==`string`?e.id.trim():``;if(t)return`part:${t}`;let n=typeof e.filename==`string`?e.filename.trim().toLowerCase():``,r=typeof e.mime==`string`?e.mime.trim().toLowerCase():``;if(r.startsWith(`image/`)&&n)return`image:${n}|${r}`;let i=typeof e.url==`string`?e.url.trim():``;return i?`url:${i}`:`meta:${n}|${r}|${e.size??``}`},Uu=e=>{let t=new Map,n=[];for(let r of e){if(r.type!==`file`||!(r.mime||r.url)||De(r))continue;let e=Hu(r),i=t.get(e);if(i===void 0){t.set(e,n.length),n.push(r);continue}n[i]?.slim===!0&&r.slim!==!0&&(n[i]=r)}return n},Wu=(e,t)=>{let n=new Map,r=new Map;for(let e of t){if(e.type!==`file`||e.slim===!0||typeof e.url!=`string`||!e.url)continue;let t=e;typeof e.id==`string`&&e.id&&n.set(e.id,t),typeof e.filename==`string`&&e.filename&&r.set(e.filename,t)}return n.size===0&&r.size===0?Uu(e):Uu(e.map(e=>e.type!==`file`||typeof e.url==`string`&&e.url&&e.slim!==!0?e:e.id&&n.has(e.id)?n.get(e.id)??e:e.filename&&r.has(e.filename)?r.get(e.filename)??e:e))},Gu=e=>e.failed||e.repositoryStatus===`error`?`error`:e.flightActive||e.repositoryStatus===`loading`?`loading`:e.hasSlimImage&&e.repositoryStatus===`ready`?`idle`:e.repositoryStatus,Ku=e=>/^(?:data|blob|https?):/i.test(e),qu=e=>{for(let t of[e.byteSize,e.size])if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t},Ju=(e,t)=>t.some(t=>t.type===`file`&&t.mime?.startsWith(`image/`)===!0&&t.slim===!0&&!t.url&&bo(e,qu(t))),Yu=(e,t)=>t.type!==`file`||t.mime?.startsWith(`image/`)!==!0||typeof t.url!=`string`||!t.url||Ku(t.url)?!1:bo(e,qu(t)),Xu=e=>Y(`grid gap-2`,e===1?`grid-cols-1 max-w-56`:`grid-cols-2`),Zu=e=>{let t=(0,Q.c)(9),{source:n,filename:r,sizeText:i,onOpen:a,materializationStatus:o,onRetry:s}=e,c=o===void 0?`ready`:o,{t:l}=ot(),u=is()??``,d=xo(n??``,u),f;return t[0]!==d||t[1]!==r||t[2]!==c||t[3]!==a||t[4]!==s||t[5]!==i||t[6]!==n||t[7]!==l?(f=(0,$.jsx)(`div`,{className:`relative aspect-square min-w-0 overflow-hidden rounded-lg border border-border/40 bg-muted/10`,"data-message-image-slot":`true`,children:n?(0,$.jsxs)(`button`,{type:`button`,onClick:a,className:`group absolute inset-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary`,"aria-label":r,children:[(0,$.jsx)(`img`,{src:d||void 0,alt:r,className:`h-full w-full object-cover`,loading:`lazy`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-t from-black/60 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity`}),(0,$.jsxs)(`div`,{className:`absolute bottom-0 left-0 right-0 p-2 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium truncate`,children:r}),i&&(0,$.jsx)(`p`,{className:`text-xs opacity-80`,children:i})]})]}):(0,$.jsxs)(`div`,{className:Y(`absolute inset-0 flex flex-col items-center justify-center gap-2 p-4 text-center typography-meta text-muted-foreground`,c===`error`&&`text-[var(--status-error)]`),role:c===`error`?`alert`:`status`,"aria-label":r,children:[c===`loading`?(0,$.jsx)(X,{name:`loader-4`,className:`size-5 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:c===`error`?`error-warning`:`file-image`,className:`size-5`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:c===`loading`?l(`chat.fileAttachment.image.loading`):c===`error`?l(`chat.fileAttachment.image.loadFailed`):r}),c===`error`&&s?(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:l(`chat.fileAttachment.image.retry`)}):null]})}),t[0]=d,t[1]=r,t[2]=c,t[3]=a,t[4]=s,t[5]=i,t[6]=n,t[7]=l,t[8]=f):f=t[8],f},Qu=e=>{let t=(0,Q.c)(11),{images:n,onLoad:r}=e,{t:i}=ot(),a;t[0]===i?a=t[1]:(a=i(`chat.fileAttachment.image.loadManually`),t[0]=i,t[1]=a);let o=a,s;if(t[2]!==o||t[3]!==n||t[4]!==r){let e;t[6]!==o||t[7]!==r?(e=e=>(0,$.jsxs)(la,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>r(e.key),"aria-label":o,className:`group h-auto min-h-8 min-w-0 justify-start gap-2 whitespace-normal border border-border/30 bg-muted/60 px-2 py-1.5 text-left hover:bg-[var(--interactive-hover)]`,"data-manual-image-load-item":e.key,children:[(0,$.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md border border-border/40 bg-background/70 text-muted-foreground transition-colors group-hover:text-foreground`,children:(0,$.jsx)(X,{name:`file-image`,className:`size-4`,"aria-hidden":`true`})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate typography-meta text-foreground`,children:e.filename}),e.sizeText&&(0,$.jsx)(`span`,{className:`block text-xs leading-tight text-muted-foreground`,children:e.sizeText})]})]},e.key),t[6]=o,t[7]=r,t[8]=e):e=t[8],s=n.map(e),t[2]=o,t[3]=n,t[4]=r,t[5]=s}else s=t[5];let c;return t[9]===s?c=t[10]:(c=(0,$.jsx)(`div`,{className:`col-span-full flex flex-col gap-1.5`,"data-manual-image-load-group":`true`,children:s}),t[9]=s,t[10]=c),c},$u={threshold:.01},ed=new Set,td=(0,Z.memo)(({files:e,messageID:t,sessionID:n,onShowPopup:r,compact:i=!1})=>{let{t:a}=ot(),o=is()??``,c=n||e.find(e=>typeof e.sessionID==`string`&&e.sessionID)?.sessionID||``,l=gr(t,o,c||void 0),[u,d]=Z.useState(()=>wr(t)??[]),f=Z.useRef(null),p=Z.useRef(!1),m=Z.useRef(null),h=Z.useRef(!1),g=Z.useRef(new Set),_=Z.useRef(``),[,v]=Z.useReducer(e=>e+1,0),y=`${o}\n${c}\n${t}`;_.current!==y&&(_.current=y,p.current=!1,m.current=null,h.current=!1,g.current=new Set,d(wr(t)??[]));for(let t of e)t.type===`file`&&t.slim===!0&&t.mime?.startsWith(`image/`)&&g.current.add(Hu(t));let b=e=>{if(!e)return`Unnamed file`;let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e},x=Z.useMemo(()=>e=>Vu(e)!==null&&typeof e.filename==`string`&&e.filename.trim().length>0?e.filename.trim():b(e.filename||e.url)||a(`chat.fileAttachment.fileFallback`),[a]),S=e=>!e||!Number.isFinite(e)||e<=0?``:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`,C=Z.useMemo(()=>Wu(e,[...l,...u]),[u,e,l]),w=wo(),T=Z.useMemo(()=>Ju(w,C),[C,w]),[E,D]=Z.useState({scope:``,keys:ed}),O=E.scope===y?E.keys:ed,k=Z.useMemo(()=>{if(!ho(w))return ed;let e=new Set;for(let t of C){let n=Hu(t);O.has(n)||Yu(w,t)&&e.add(n)}return e},[O,C,w]),A=C.filter(e=>e.mime?.startsWith(`image/`)),j=A.filter(e=>!!e.url),M=C.filter(e=>!e.mime?.startsWith(`image/`)),N=A.some(e=>e.slim===!0),P=T&&A.some(e=>e.slim===!0&&!O.has(Hu(e))),F=A.filter(e=>{let t=Hu(e);return O.has(t)?!1:e.slim===!0?T:k.has(t)}),I=new Set(F.map(Hu)),L=A.filter(e=>{let t=Hu(e);return!I.has(t)&&(g.current.has(t)||!!e.url)}),R=F.map(e=>({key:Hu(e),filename:x(e),sizeText:S(qu(e))})),z=q((e=!1)=>{if(!N||!o||!c||!t||!e&&p.current||m.current)return;p.current=!0,h.current=!1;let n=Bi(o,c,t).then(()=>{let e=wr(t);e&&e.length>0&&d(e)}).catch(()=>{let e=wr(t);if(e&&e.length>0){d(e);return}h.current=!0}).finally(()=>{m.current=null,v()});m.current=n,v()}),B=q(e=>{D(t=>{let n=t.scope===y?new Set(t.keys):new Set;return n.add(e),{scope:y,keys:n}}),N&&z(!0)});tt(N&&!P?f:null,e=>{e.some(e=>e.isIntersecting)&&z(!1)},$u),Z.useEffect(()=>{if(!N||P)return;let e=f.current;if(!e)return;let t=e.closest(`[data-scrollbar="chat"]`);if(!t||typeof IntersectionObserver>`u`){z(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();n.bottom>r.top&&n.top<r.bottom&&z(!1)},[o,N,t,c,P]);let V=N&&o&&c?Wi(o,c,t).status:`ready`,H=C.some(e=>e.mime?.startsWith(`image/`)===!0&&typeof e.url==`string`&&e.url.length>0&&e.slim!==!0)?`ready`:Gu({hasSlimImage:N,flightActive:!!m.current,failed:h.current,repositoryStatus:V}),U=Z.useMemo(()=>j.flatMap(e=>{if(!e.url)return[];let t=x(e)||`Image`;return[{url:e.url,mimeType:e.mime,filename:t,size:e.size}]}),[j,x]),W=q(e=>{if(!r)return;let t=j.findIndex(t=>Hu(t)===Hu(e)),n=U[t];if(!n?.url)return;let i=n.filename||`Image`;r({open:!0,title:i,content:``,metadata:{tool:`image-preview`,filename:i,mime:n.mimeType,size:n.size},image:{url:n.url,mimeType:n.mimeType,filename:i,size:n.size,gallery:U,index:t}})});return C.length===0?null:i?(0,$.jsxs)(`div`,{ref:f,className:`space-y-1.5 mt-1.5`,"data-message-files":t,children:[M.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:M.map(e=>{let t=x(e),n=t.split(`.`).pop()||``,r=S(e.size),i=Vu(e),a=Ne(e.mime)||Pe(e.filename)||Pe(e.url);return(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:i&&e.url?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{Xo(e.url||``)},className:`inline-flex items-center bg-muted/30 border border-border/30 typography-meta gap-1 px-2 py-0.5 rounded-lg text-foreground hover:text-primary transition-colors`,children:[i===`pr`?(0,$.jsx)(X,{name:`git-pull-request`,className:`text-muted-foreground h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`github`,className:`text-muted-foreground h-3.5 w-3.5`}),(0,$.jsx)(`div`,{className:`overflow-hidden max-w-[13.75rem]`,children:(0,$.jsx)(`span`,{className:`truncate block`,title:t,children:t})})]}):(0,$.jsxs)(`div`,{className:`inline-flex items-center bg-muted/30 border border-border/30 typography-meta gap-1 px-2 py-0.5 rounded-lg`,children:[e.mime?.includes(`pdf`)?(0,$.jsx)(X,{name:`file-pdf`,className:`text-muted-foreground h-3.5 w-3.5`}):(0,$.jsx)(ku,{filePath:t,extension:n,isDirectory:a,className:`text-muted-foreground h-3.5 w-3.5`}),(0,$.jsx)(`div`,{className:`overflow-hidden max-w-[8.75rem]`,children:(0,$.jsx)(`span`,{className:`truncate block`,title:t,children:t})})]})}),(0,$.jsx)(La,{children:(0,$.jsxs)(`p`,{children:[t,r?` (${r})`:``]})})]},`file-${Hu(e)}`)})}),R.length>0?(0,$.jsx)(Qu,{images:R,onLoad:B}):null,L.length>0?(0,$.jsx)(`div`,{className:Xu(L.length),children:L.map(e=>{let t=x(e);return(0,$.jsx)(Zu,{source:e.url,filename:t,sizeText:S(qu(e)),materializationStatus:e.url?`ready`:H,onRetry:()=>z(!0),onOpen:e.url?()=>W(e):void 0},Hu(e))})}):null]}):(0,$.jsxs)(`div`,{ref:f,"data-message-files":t,className:Y(`grid gap-2`,i?`grid-cols-1`:`grid-cols-1 sm:grid-cols-2`),children:[R.length>0?(0,$.jsx)(Qu,{images:R,onLoad:B}):null,C.map(e=>{let t=x(e),n=e.mime?.startsWith(`image/`),o=S(e.size),c=Vu(e);if(I.has(Hu(e)))return null;if(n&&e.url)return(0,$.jsx)(Zu,{source:e.url,filename:t,sizeText:o,onOpen:()=>W(e)},Hu(e));if(n)return(0,$.jsx)(Zu,{filename:t,sizeText:o,materializationStatus:H,onRetry:()=>z(!0)},Hu(e));if(c&&e.url)return(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{Xo(e.url||``)},className:Y(`flex items-center gap-2 p-2 rounded-lg border border-border/40 bg-muted/10 hover:bg-muted/20 transition-colors text-left`,i?`text-xs`:`text-sm`),children:[(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:c===`pr`?(0,$.jsx)(X,{name:`git-pull-request`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):(0,$.jsx)(X,{name:`github`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`font-medium truncate`,children:t}),o&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})]})}),(0,$.jsx)(La,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Hu(e));let l=e.source,u=typeof l?.type==`string`?l.type:void 0,d=l&&typeof l.path==`string`?l.path:void 0,f=u===`file`&&d?d:e.url||``;return f&&ts(f)?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{s.getState().navigateToDiagram(f)},className:Y(`flex items-center gap-2 p-2 rounded-lg border border-border/40 bg-muted/10 hover:bg-muted/20 transition-colors text-left cursor-pointer`,i?`text-xs`:`text-sm`),children:[(0,$.jsx)(X,{name:`file`,className:Y(`text-muted-foreground shrink-0`,i?`h-3.5 w-3.5`:`h-4 w-4`)}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`font-medium truncate`,children:t}),(0,$.jsx)(`p`,{className:`text-xs text-status-info`,children:a(`chat.fileAttachment.openInDiagram`)})]}),(0,$.jsx)(X,{name:`external-link`,className:Y(`text-muted-foreground shrink-0`,i?`h-3 w-3`:`h-3.5 w-3.5`)})]})}),(0,$.jsx)(La,{children:(0,$.jsx)(`p`,{children:a(`chat.fileAttachment.openInDiagram`)})})]},Hu(e)):(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{r&&e.url&&r({open:!0,title:t,content:``,image:{url:e.url,mimeType:e.mime,filename:t}})},className:Y(`flex items-center gap-2 p-2 rounded-lg border border-border/40 bg-muted/10 hover:bg-muted/20 transition-colors text-left`,i?`text-xs`:`text-sm`),children:[(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:e.mime?.startsWith(`image/`)?(0,$.jsx)(X,{name:`file-image`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):Ne(e.mime)||Pe(e.filename)||Pe(e.url)?(0,$.jsx)(ku,{filePath:t,isDirectory:!0,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):e.mime?.includes(`pdf`)?(0,$.jsx)(X,{name:`file-pdf`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)}):(0,$.jsx)(X,{name:`file`,className:Y(`text-muted-foreground`,i?`h-3.5 w-3.5`:`h-4 w-4`)})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`font-medium truncate`,children:t}),o&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})]})}),(0,$.jsx)(La,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Hu(e))})]})});td.displayName=`MessageFilesDisplay`;var nd=(0,Z.memo)(e=>{let t=(0,Q.c)(14),{urls:n,caption:r,onShowPopup:i}=e;if(n.length===0)return null;let a;t[0]===n.length?a=t[1]:(a=Xu(n.length),t[0]=n.length,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=n.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i?.({open:!0,title:r||`Image ${t+1} of ${n.length}`,content:``,image:{url:e,gallery:n.map(gd),index:t}}),className:`relative aspect-square rounded-lg border border-border/40 bg-muted/10 overflow-hidden group`,children:[(0,$.jsx)(`img`,{src:e,alt:r||`Image ${t+1}`,className:`h-full w-full object-cover transition-transform group-hover:scale-105`,loading:`lazy`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors`})]},e)),t[2]=r,t[3]=i,t[4]=n,t[5]=o):o=t[5];let s;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];let c;t[9]===r?c=t[10]:(c=r&&(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:r}),t[9]=r,t[10]=c);let l;return t[11]!==s||t[12]!==c?(l=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[s,c]}),t[11]=s,t[12]=c,t[13]=l):l=t[13],l});nd.displayName=`ImageGallery`;function rd(e){let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e}function id(e){let t=e.split(`.`);return t.length>1?t[t.length-1].toLowerCase():``}function ad(e){e.target.closest(`[data-remove-button]`)}function od(e){return e.source===`vscode`&&e.vscodeSource===`file`}function sd(e){return e.mimeType.startsWith(`image/`)}function cd(e){return!e.mimeType.startsWith(`image/`)}function ld(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function ud(e){return e.url}function dd(e){return e.source!==`server`&&e.source!==`vscode`&&e.mimeType.startsWith(`image/`)}function fd(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function pd(e){return e.url}function md(e){return e.activeEditorFile}function hd(e){return e.setPendingInputText}function gd(e){return{url:e}}var _d=`text-[var(--primary)]`,vd=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,yd=/(^|\s)\/(\u2003)?([A-Za-z0-9][A-Za-z0-9_-]*)/g,bd=/\[skill:([A-Za-z0-9][A-Za-z0-9_-]*)\]/g,xd=/\[command:([^\]\r\n]+)\]/g,Sd=/(^|[\s([{])(@session:([A-Za-z0-9_-]+))(?=$|[\s)\]},.!?;:])/g,Cd=/@([^\s]+)/g,wd=` `,Td=e=>e.replaceAll(`\\`,`/`).split(`/`).at(-1)?.replace(/\.md$/,``)??``,Ed=e=>e.trim().toLowerCase(),Dd=(e,t)=>{let n=t>0?e[t-1]:null;return!n||/(\s|\(|\)|\[|\]|\{|\}|"|'|`|,|\.|;|:)/.test(n)},Od=e=>e.includes(`/`)||e.includes(`\\`)||e.includes(`.`),kd=(e,t)=>{e.push(t)},Ad={kind:`skill`,priority:120,shouldScan:e=>e.includes(`/`)||e.includes(`[skill:`),detect:(e,t)=>{let n=[],r=t.skillNames;bd.lastIndex=0;let i;for(;(i=bd.exec(e))!==null;){let e=i[1];kd(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(yd.lastIndex=0;(i=yd.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)||kd(n,{start:s,end:c,kind:`skill`,raw:e.slice(s,c),label:`/${o}`,payload:{kind:`skill`,skillName:o}})}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:_d,href:us(t),skillName:t}}},jd={kind:`command`,priority:115,shouldScan:(e,t)=>e.includes(`[command:`)||!!t.commandNames?.size&&e.includes(`/`),detect:(e,t)=>{let n=[];xd.lastIndex=0;let r;for(;(r=xd.exec(e))!==null;){let e=r[1],t=Td(e);t&&kd(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(yd.lastIndex=0;(r=yd.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)||kd(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:_d})},Md={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=G(e.slice(i+1,a)).trim(),s=Ed(o),c=t.citationIcons?.get(s),l=!c&&vd.test(o),u=c??(l?`image`:null);if(!u){r=a+1;continue}let d=t.citationDisplayNames?.get(s)??o;kd(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:_d,filename:t}}},Nd={kind:`session`,priority:105,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[];Sd.lastIndex=0;let r;for(;(r=Sd.exec(e))!==null;){let i=r[3],a=r.index+r[1].length,o=a+r[2].length,s=t.sessionTitles?.get(i)??i;kd(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=[`@${wd}${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&&kd(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:_d,sessionId:t}}},Pd={kind:`file`,priority:100,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[],r=t.agentNames,i=t.filePaths,a=t.allowPathHeuristics===!0;Cd.lastIndex=0;let o;for(;(o=Cd.exec(e))!==null;){let t=o.index;if(!Dd(e,t)||o[1].startsWith(`session:`))continue;let s=o[1].trim().replace(/[),.;:!?`"'>]+$/g,``);if(!s)continue;let c=t+1+s.length,l=e.slice(t,c);if(r?.has(s.toLowerCase())){kd(n,{start:t,end:c,kind:`agent`,raw:l,label:l,payload:{kind:`agent`,agentName:s}});continue}let u=s.replace(/\\/g,`/`).replace(/^\.\//,``);(i?.has(s)||i?.has(u)||i?.has(u.replace(/^\/+/,``))||a&&Od(s))&&kd(n,{start:t,end:c,kind:`file`,raw:l,label:l,payload:{kind:`file`,path:s}})}return n},decorate:e=>{if(e.kind===`agent`&&e.payload.kind===`agent`)return{kind:`agent`,label:e.label,icon:null,className:_d,href:ps(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:_d,path:t}}},Fd=[Ad,jd,Md,Nd,Pd],Id=(e,t=Fd)=>{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`?Md.decorate(e):e.kind===`agent`?Pd.decorate(e):{kind:e.kind,label:e.label,icon:null,className:_d}},Ld=[`/`,`[`,`@`],Rd=e=>{if(!e)return!1;for(let t of Ld)if(e.includes(t))return!0;return!1},zd=(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)},Bd=(e,t={},n=Fd)=>{if(!Rd(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 zd(r,i)},Vd=(e,t,n=Fd)=>{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:Id(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}]},Hd=(e,t={},n=Fd)=>{if(!Rd(e))return null;let r=Bd(e,t,n);return r.length===0?null:Vd(e,r,n)},Ud=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,Wd=e=>e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`\\\\`),Gd=(e,t)=>!!t?.startsWith(`image/`)||Ud.test(e),Kd=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,Gd(e,i)?`image`:`attachment`)}return t},qd=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=G(e.slice(r+1,i)).trim();Wd(a)&&Ud.test(a)&&t.push(a),n=i+1}return t},Jd=(e,t)=>{let n=Kd(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&&Gd(e,typeof t.mime==`string`?t.mime:void 0)&&i.push(e)}if(i.length===0)return{icons:n,displayNames:r};let a=qd(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}},Yd=e=>{switch(e.kind){case`session`:return{trigger:`@`,icon:`chat-thread`,label:e.label};case`skill`:return{trigger:`/`,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}},Xd=e=>{let t=(0,Q.c)(27),{decoration:n,onOpenSkill:r,interactive:i}=e,a=i===void 0||i,o;t[0]===n?o=t[1]:(o=Yd(n),t[0]=n,t[1]=o);let s=o,c=s?.icon??n.icon,l=s?.label??n.label,u=s?`${s.trigger}${ee}`:ee,d;t[2]===n.className?d=t[3]:(d=Y(`whitespace-nowrap`,n.className),t[2]=n.className,t[3]=d);let f;t[4]!==c||t[5]!==u?(f=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:z,right:z},children:(0,$.jsx)(X,{name:c,className:Y(N,`shrink-0`),"aria-hidden":`true`})})]}):null,t[4]=c,t[5]=u,t[6]=f):f=t[6];let p;t[7]!==n.kind||t[8]!==l||t[9]!==d||t[10]!==f?(p=(0,$.jsxs)(`span`,{className:d,"data-message-reference-kind":n.kind,children:[f,l]}),t[7]=n.kind,t[8]=l,t[9]=d,t[10]=f,t[11]=p):p=t[11];let m=p;if(!a)return m;if(n.kind===`skill`&&n.skillName&&r){let e;t[12]!==n.skillName||t[13]!==r?(e=e=>{e.stopPropagation(),r(n.skillName)},t[12]=n.skillName,t[13]=r,t[14]=e):e=t[14];let i;return t[15]!==m||t[16]!==n.skillName||t[17]!==e?(i=(0,$.jsx)(`button`,{type:`button`,className:`inline hover:underline`,"data-skill-name":n.skillName,onClick:e,children:m}),t[15]=m,t[16]=n.skillName,t[17]=e,t[18]=i):i=t[18],i}if(n.kind===`agent`&&n.href){let e;t[19]!==n.agentName||t[20]!==n.label?(e=n.agentName||n.label.replace(/^@/,``),t[19]=n.agentName,t[20]=n.label,t[21]=e):e=t[21];let r;t[22]===e?r=t[23]:(r=os(e),t[22]=e,t[23]=r);let i;return t[24]!==m||t[25]!==r?(i=(0,$.jsx)(`a`,{href:r,className:`inline hover:underline`,target:`_blank`,rel:`noopener noreferrer`,"data-openchamber-agent-mention":`true`,onClick:Zd,children:m}),t[24]=m,t[25]=r,t[26]=i):i=t[26],i}return m};Xd.displayName=`MessageReferenceChip`;function Zd(e){return e.stopPropagation()}var Qd=e=>e!==`frozen`,$d=(e,t)=>e.length===0?t:t.length===0?e:[...e,...t],ef=e=>e.status===`committed`&&e.current===!0,tf=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}},nf=(e,t)=>{let n=e.status??`queued`;return!t&&(n===`queued`||n===`retrying`||n===`failed`||n===`unresolved`)},rf=(e,t,n)=>Ri(e)||t||e.manualDispatchRequested===!0&&!n?.allowManualDispatchRetry?!1:[`queued`,`retrying`,`failed`,`unresolved`].includes(e.status),af=(e,t)=>!t.frozen&&!Ri(e),of=(e,t)=>!(t.frozen||Ri(e)),sf=e=>e.status===`sending`||e.status===`reconciling`,cf=e=>e.status===`sending`||e.status===`reconciling`,lf=e=>e.manualDispatchRequested===!0||e.status===`sending`||e.status===`reconciling`,uf=e=>e.status===`sending`||e.status===`reconciling`,df=8e3,ff=(e,t)=>e.transportIdentity===t.transportIdentity&&e.runtimeGeneration===t.runtimeGeneration&&S(e.directory)===S(t.directory)&&e.sessionID===t.sessionID&&e.scopeID===t.scopeID,pf=(e,t)=>e.filter(e=>ff(e,t)),mf=(e,t,n)=>e.filter(e=>ff(e,t)&&Number.isSafeInteger(e.committedRevision)&&e.committedRevision>0&&(n===void 0||n<e.committedRevision)),hf=(e,t)=>{if(t.kind===`send`)return e;if(t.kind===`edit`||t.kind===`remove`){let n=e.findIndex(e=>!Ri(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(Ri(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},gf=(e,t)=>t.reduce(hf,e),_f=(e,t)=>{let n=gf(e,t),r=n.filter(e=>Ri(e)||!uf(e));return r.length===n.length?n:r},vf=(e,t,n)=>({requestID:n,scopeID:e.scopeID,revision:e.revision,item:t}),yf=(e,t,n,r)=>({scopeID:e.scopeID,scopeRevision:e.revision,item:t,targetKey:n,expectedRevision:r}),bf=(e,t,n,r,i=e.items)=>{let a=i.filter(e=>!Ri(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}},xf=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},Sf=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}Oe({source:n.source??`local`,vscodeSource:n.vscodeSource,mimeType:n.mimeType})&&t.set(r,`attachment`)}return t},Cf=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},wf=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}},Tf=e=>(e.split(`
6519
6519
  `)[0]??``)+(e.includes(`
6520
- `)?`...`:``),Ef=(e,t={})=>{let n=Tf(e);if(!n)return null;let r=wf(t.composerDocument);return Hd(n,{citationIcons:Sf(t.attachments),sessionMentions:Cf(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},Df=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`))},Of=(0,Z.memo)(e=>{let t=(0,Q.c)(132),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,sendPendingTimedOut:s,abortSendPending:c,isMobile:l,onEdit:u,onSend:d,onRemove:f}=e,{t:p}=st(),m;t[0]===n?m=t[1]:(m=Ri(n),t[0]=n,t[1]=m);let h=m,g=n.queueItemID||n.id,_;t[2]!==o||t[3]!==r?(_=r&&o.has(`edit`),t[2]=o,t[3]=r,t[4]=_):_=t[4];let v=_,y;t[5]!==o||t[6]!==r?(y=r&&o.has(`remove`),t[5]=o,t[6]=r,t[7]=y):y=t[7];let b=y,x;t[8]!==o||t[9]!==r?(x=r&&o.has(`reorder`),t[8]=o,t[9]=r,t[10]=x):x=t[10];let S=x,C=r||h?void 0:n,w;t[11]!==n||t[12]!==h||t[13]!==r?(w=r&&!h&&lf(n),t[11]=n,t[12]=h,t[13]=r,t[14]=w):w=t[14];let T=w,E;t[15]===C?E=t[16]:(E=C&&cf(C),t[15]=C,t[16]=E);let D=!!E,O;t[17]!==n||t[18]!==h||t[19]!==r?(O=r&&!h&&sf(n),t[17]=n,t[18]=h,t[19]=r,t[20]=O):O=t[20];let k=O,A;t[21]!==T||t[22]!==D||t[23]!==o||t[24]!==r?(A=r&&o.has(`send`)||T||D,t[21]=T,t[22]=D,t[23]=o,t[24]=r,t[25]=A):A=t[25];let j=c||A&&!s,M=i||h,N;t[26]!==i||t[27]!==n?(N=af(n,{frozen:i}),t[26]=i,t[27]=n,t[28]=N):N=t[28];let P=N,F;t[29]!==i||t[30]!==n?(F=of(n,{frozen:i}),t[29]=i,t[30]=n,t[31]=F):F=t[31];let I=F,L=C?.owner?.state===`unbound-legacy`||M||k,R;t[32]!==M||t[33]!==a||t[34]!==n||t[35]!==j||t[36]!==s||t[37]!==r?(R=!M&&!j&&(r?rf(n,a,{allowManualDispatchRetry:s}):nf(n,a)),t[32]=M,t[33]=a,t[34]=n,t[35]=j,t[36]=s,t[37]=r,t[38]=R):R=t[38];let z=R,B=C?.failure?.recovery,V;t[39]===n?V=t[40]:(V=xf(n),t[39]=n,t[40]=V);let H=V,U=h?void 0:B?.attachments??n.attachments,ee=B?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),te;t[41]!==L||t[42]!==g?(te={id:g,disabled:L},t[41]=L,t[42]=g,t[43]=te):te=t[43];let{attributes:W,listeners:G,setNodeRef:ne,transform:re,transition:ie,isDragging:ae}=qo(te),oe;t[44]===H?oe=t[45]:(oe=Tf(H),t[44]=H,t[45]=oe);let se=oe,ce;t[46]!==U||t[47]!==ee||t[48]!==H?(ce=Ef(H,{attachments:U,composerDocument:ee}),t[46]=U,t[47]=ee,t[48]=H,t[49]=ce):ce=t[49];let le=ce,ue=h?n.attachmentCount:U?.length??0,de;t[50]!==n||t[51]!==f?(de=()=>f(n),t[50]=n,t[51]=f,t[52]=de):de=t[52];let fe=!I,pe=b||void 0,me=l?`h-7 w-3`:`size-7`,he;t[53]===me?he=t[54]:(he=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`,me),t[53]=me,t[54]=he);let ge;t[55]===p?ge=t[56]:(ge=p(`chat.queuedMessage.removeAria`),t[55]=p,t[56]=ge);let _e=b?`loader-4`:`delete-bin`,ve=l?`size-3`:`size-3.5`,ye=b&&`animate-spin`,be;t[57]!==ve||t[58]!==ye?(be=Y(ve,ye),t[57]=ve,t[58]=ye,t[59]=be):be=t[59];let xe;t[60]!==_e||t[61]!==be?(xe=(0,$.jsx)(X,{name:_e,className:be,"aria-hidden":`true`}),t[60]=_e,t[61]=be,t[62]=xe):xe=t[62];let Se;t[63]!==de||t[64]!==fe||t[65]!==pe||t[66]!==he||t[67]!==ge||t[68]!==xe?(Se=(0,$.jsx)(`button`,{type:`button`,onClick:de,disabled:fe,"aria-busy":pe,className:he,"aria-label":ge,children:xe}),t[63]=de,t[64]=fe,t[65]=pe,t[66]=he,t[67]=ge,t[68]=xe,t[69]=Se):Se=t[69];let Ce=Se,we;t[70]===re?we=t[71]:(we=Wo.Translate.toString(re),t[70]=re,t[71]=we);let Te;t[72]!==we||t[73]!==ie?(Te={transform:we,transition:ie},t[72]=we,t[73]=ie,t[74]=Te):Te=t[74];let Ee=l?`gap-1 py-0.5`:`flex gap-1.5 md:gap-2`,De=ae&&`z-10 opacity-60`,Oe;t[75]!==Ee||t[76]!==De?(Oe=Y(`flex min-w-0 items-center`,Ee,De),t[75]=Ee,t[76]=De,t[77]=Oe):Oe=t[77];let ke=S||void 0,Ae=l?`h-7 w-3`:`size-auto`,je=L?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,Me;t[78]!==Ae||t[79]!==je?(Me=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,Ae,`transition-colors`,je),t[78]=Ae,t[79]=je,t[80]=Me):Me=t[80];let Ne;t[81]===p?Ne=t[82]:(Ne=p(`chat.queuedMessage.reorderAria`),t[81]=p,t[82]=Ne);let Pe=S?`loader-4`:`draggable`,Fe=l?`size-3`:`size-3.5`,Ie=S&&`animate-spin`,Le;t[83]!==Fe||t[84]!==Ie?(Le=Y(Fe,Ie),t[83]=Fe,t[84]=Ie,t[85]=Le):Le=t[85];let Re;t[86]!==Pe||t[87]!==Le?(Re=(0,$.jsx)(X,{name:Pe,className:Le,"aria-hidden":`true`}),t[86]=Pe,t[87]=Le,t[88]=Re):Re=t[88];let ze;t[89]!==W||t[90]!==L||t[91]!==G||t[92]!==ke||t[93]!==Me||t[94]!==Ne||t[95]!==Re?(ze=(0,$.jsx)(`button`,{type:`button`,...W,...G,disabled:L,"aria-busy":ke,className:Me,"aria-label":Ne,children:Re}),t[89]=W,t[90]=L,t[91]=G,t[92]=ke,t[93]=Me,t[94]=Ne,t[95]=Re,t[96]=ze):ze=t[96];let Be=l?Ce:null,Ve=l?`text-xs leading-5`:`typography-ui-label leading-5`,He;t[97]===Ve?He=t[98]:(He=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground`,Ve),t[97]=Ve,t[98]=He);let Ue;t[99]!==se||t[100]!==le||t[101]!==p?(Ue=le?le.map(Lf):se||p(`chat.queuedMessage.empty`),t[99]=se,t[100]=le,t[101]=p,t[102]=Ue):Ue=t[102];let We;t[103]!==ue||t[104]!==p?(We=ue>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:p(`chat.queuedMessage.attachments`,{count:ue})}),t[103]=ue,t[104]=p,t[105]=We):We=t[105];let Ge;t[106]!==He||t[107]!==Ue||t[108]!==We?(Ge=(0,$.jsxs)(`span`,{className:He,children:[Ue,We]}),t[106]=He,t[107]=Ue,t[108]=We,t[109]=Ge):Ge=t[109];let Ke;t[110]!==P||t[111]!==z||t[112]!==v||t[113]!==l||t[114]!==n||t[115]!==u||t[116]!==d||t[117]!==h||t[118]!==j||t[119]!==p?(Ke=h?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.queuing`)})]}):j?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.sendingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.sending`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(n),disabled:!P,"aria-busy":v||void 0,"aria-label":p(`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`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:v?`loader-4`:`edit`,className:Y(l?`size-3`:`size-3.5`,v&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{j||d(n)},disabled:!z||j,"aria-busy":j||void 0,"aria-label":p(`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`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`send-plane`,className:Y(l?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.send`)})]})]}),t[110]=P,t[111]=z,t[112]=v,t[113]=l,t[114]=n,t[115]=u,t[116]=d,t[117]=h,t[118]=j,t[119]=p,t[120]=Ke):Ke=t[120];let qe=!l&&!h?Ce:null,Je;t[121]!==Ke||t[122]!==qe?(Je=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[Ke,qe]}),t[121]=Ke,t[122]=qe,t[123]=Je):Je=t[123];let Ye;return t[124]!==ne||t[125]!==Te||t[126]!==Oe||t[127]!==ze||t[128]!==Be||t[129]!==Ge||t[130]!==Je?(Ye=(0,$.jsxs)(`div`,{ref:ne,style:Te,className:Oe,children:[ze,Be,Ge,Je]}),t[124]=ne,t[125]=Te,t[126]=Oe,t[127]=ze,t[128]=Be,t[129]=Ge,t[130]=Je,t[131]=Ye):Ye=t[131],Ye});Of.displayName=`QueuedMessageChip`;var kf=[],Af=[],jf=[],Mf=new Set,Nf=(e,t)=>t?$d(b(e,x(t.sessionID)),b(e,t)):kf,Pf=(e,t)=>{if(!t)return Af;let n=Nf(e,t),r=[...B(e,x(t.sessionID)),...B(e,t)];return r.length===0?n:[...n,...r]},Ff=(e,t)=>{let n=e.owner;return n?n.state===`unbound-legacy`?n.sessionID===t.sessionID?x(t.sessionID):null:_(n)===_(t)?t:null:null},If=(0,Z.memo)(e=>{let t=(0,Q.c)(152),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:c,clientPendingItems:l,onRemoveClientPending:u,trailing:d}=e,f=l===void 0?jf:l,{t:p}=st(),m=s(Rf),h=o?.transportIdentity??``,g=o?.directory??``,v=o?.sessionID??``,y;t[0]!==h||t[1]!==g||t[2]!==v?(y={transportIdentity:h,directory:g,sessionID:v},t[0]=h,t[1]=g,t[2]=v,t[3]=y):y=t[3];let b=iu(y),x;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(x=new Map,t[4]=x):x=t[4];let S=Z.useRef(x);o?.runtimeGeneration,o?.transportIdentity;let w=o?.transportIdentity??``,T=o?.runtimeGeneration??-1,E;t[5]!==w||t[6]!==T?(E=[w,`messageQueue`,`scopeMutation`,T],t[5]=w,t[6]=T,t[7]=E):E=t[7];let D=E,O;t[8]===b.actions?O=t[9]:(O=e=>er(S,`${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=b.actions.captureRuntime();if(t.transportIdentity!==e.runtime.transportIdentity||t.generation!==e.runtime.generation)return Promise.resolve({status:`stale`});switch(e.kind){case`edit`:return b.actions.editIntoDraft(e.input);case`send`:return b.actions.manualSend(e.input);case`remove`:return b.actions.remove(e.input);case`reorder`:return b.actions.reorder(e.input)}throw Error(`Unsupported server queue operation`)}),t[8]=b.actions,t[9]=O);let k,A;t[10]!==b.actions||t[11]!==p?(k=(e,t)=>{let n=b.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&e.status!==`stale`&&t.kind===`edit`&&e.status!==`committed`&&wr.error(p(`chat.chatInput.toast.queueOperationFailed`))},A=(e,t)=>{let n=b.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&wr.error(p(e instanceof qi&&e.code===`unavailable`?`chat.chatInput.toast.queueOperationStatusUnknown`:`chat.chatInput.toast.queueOperationFailed`))},t[10]=b.actions,t[11]=p,t[12]=k,t[13]=A):(k=t[12],A=t[13]);let j;t[14]!==D||t[15]!==O||t[16]!==k||t[17]!==A?(j={mutationKey:D,mutationFn:O,onSuccess:k,onError:A},t[14]=D,t[15]=O,t[16]=k,t[17]=A,t[18]=j):j=t[18];let M=qe(j),N;t[19]===D?N=t[20]:(N={filters:{mutationKey:D,exact:!0,status:`pending`},select:zf},t[19]=D,t[20]=N);let P=Ke(N),F;t[21]===D?F=t[22]:(F={filters:{mutationKey:D,exact:!0,status:`success`},select:Bf},t[21]=D,t[22]=F);let I=Ke(F),R;bb0:{if(!o||!b.scope){R=null;break bb0}let e=o.runtimeGeneration??b.runtimeCapture.generation,n;t[23]!==o.directory||t[24]!==o.sessionID||t[25]!==o.transportIdentity||t[26]!==b.scope.scopeID||t[27]!==e?(n={transportIdentity:o.transportIdentity,directory:o.directory,sessionID:o.sessionID,scopeID:b.scope.scopeID,runtimeGeneration:e},t[23]=o.directory,t[24]=o.sessionID,t[25]=o.transportIdentity,t[26]=b.scope.scopeID,t[27]=e,t[28]=n):n=t[28],R=n}let z=R,B;bb1:{if(!z){let e;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[29]=e):e=t[29],B=e;break bb1}let e;if(t[30]!==z||t[31]!==P){let n;t[33]===z?n=t[34]:(n=e=>Df(e)&&e.scopeID===z.scopeID,t[33]=z,t[34]=n),e=pf(P.filter(n),z),t[30]=z,t[31]=P,t[32]=e}else e=t[32];B=e}let V=B,H;t[35]!==z||t[36]!==b.scope?.revision||t[37]!==I?(H=()=>z?mf(I.filter(Vf),z,b.scope?.revision):[],t[35]=z,t[36]=b.scope?.revision,t[37]=I,t[38]=H):H=t[38],b.scope?.revision;let U;t[39]===H?U=t[40]:(U=H(),t[39]=H,t[40]=U);let ee=U,te;t[41]!==ee||t[42]!==V?(te=[...V,...ee],t[41]=ee,t[42]=V,t[43]=te):te=t[43];let W=te,G;t[44]===o?G=t[45]:(G=e=>Pf(e,o),t[44]=o,t[45]=G);let ne=C(G);Z.useSyncExternalStore(Yt,hn,hn);let re;t[46]!==W||t[47]!==ne||t[48]!==b.items||t[49]!==b.mode?(re=b.mode===`server`?_f(b.items,W):ne,t[46]=W,t[47]=ne,t[48]=b.items,t[49]=b.mode,t[50]=re):re=t[50];let ie=re,ae;t[51]!==ie||t[52]!==f?(ae=f.length===0?ie:[...ie,...f],t[51]=ie,t[52]=f,t[53]=ae):ae=t[53];let oe=ae,se;t[54]!==o?.sessionID||t[55]!==oe?(se=()=>{let e=o?.sessionID,t=new Set;if(!e)return t;for(let n of oe){let r=n.queueItemID||n.id;r&&Cn(e,r)&&t.add(r)}return t},t[54]=o?.sessionID,t[55]=oe,t[56]=se):se=t[56],o?.sessionID;let ce;t[57]===se?ce=t[58]:(ce=se(),t[57]=se,t[58]=ce);let le=ce,ue;if(t[59]!==W){ue=new Map;for(let e of W){let t=ue.get(e.queueItemID)??new Set;t.add(e.kind),ue.set(e.queueItemID,t)}t[59]=W,t[60]=ue}else ue=t[60];let de=ue,fe;if(t[61]!==W||t[62]!==oe||t[63]!==b.mode){bb2:{let e=new Set;if(b.mode===`server`){for(let t of W)t.kind===`send`&&e.add(t.queueItemID);for(let t of oe){if(Ri(t))continue;let n=t.queueItemID;n&&lf(t)&&e.add(n)}fe=e;break bb2}for(let t of oe){if(Ri(t))continue;let n=t;cf(n)&&e.add(n.queueItemID||n.id)}fe=e}t[61]=W,t[62]=oe,t[63]=b.mode,t[64]=fe}else fe=t[64];let pe=fe,[me,he]=Z.useState(Hf),ge;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(ge=new Map,t[65]=ge):ge=t[65];let _e=Z.useRef(ge),ve,ye;t[66]!==pe||t[67]!==me?(ve=()=>{let e=_e.current,t=Date.now();for(let t of[...e.keys()])pe.has(t)||e.delete(t);he(e=>{let t=!1,n=new Set;for(let r of e)pe.has(r)?n.add(r):t=!0;return t?n:e});let n=[];for(let r of pe){if(e.has(r)||(e.set(r,t),he(e=>{if(!e.has(r))return e;let t=new Set(e);return t.delete(r),t})),me.has(r))continue;let i=df-(t-(e.get(r)??t));if(i<=0){he(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t});continue}n.push(setTimeout(()=>{_e.current.has(r)&&he(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)}},ye=[pe,me],t[66]=pe,t[67]=me,t[68]=ve,t[69]=ye):(ve=t[68],ye=t[69]),Z.useEffect(ve,ye);let be;t[70]===b.mode?be=t[71]:(be=Qd(b.mode),t[70]=b.mode,t[71]=be);let xe=!be,Se=Gt(o),Ce;t[72]!==Se||t[73]!==oe||t[74]!==b.mode?(Ce=b.mode===`server`?!1:Se||oe.some(Uf),t[72]=Se,t[73]=oe,t[74]=b.mode,t[75]=Ce):Ce=t[75];let we=Ce,Te=C(Wf),Ee;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(Ee={activationConstraint:{distance:8}},t[76]=Ee):Ee=t[76];let De;t[77]===Symbol.for(`react.memo_cache_sentinel`)?(De={activationConstraint:{delay:200,tolerance:6}},t[77]=De):De=t[77];let Oe=Uo(Io(Vo,Ee),Io(Ro,De)),ke;t[78]!==xe||t[79]!==o||t[80]!==oe||t[81]!==Te||t[82]!==M||t[83]!==b.actions||t[84]!==b.mode||t[85]!==b.scope?(ke=e=>{if(xe)return;let{active:t,over:n}=e;if(!n||t.id===n.id)return;if(b.mode===`server`){if(!o||!b.scope)return;let e=oe,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||Ri(r)||Ri(i)||sf(r)||sf(i))return;let a=b.scope,s=b.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=L(),l=bf(a,String(t.id),String(n.id),c,e);if(!l)return;M.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(Gf);return}let r=oe.filter(Kf),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=Ff(i,o),c=Ff(a,o);!s||!c||_(s)!==_(c)||Te(s,String(t.id),String(n.id),i.operationID)},t[78]=xe,t[79]=o,t[80]=oe,t[81]=Te,t[82]=M,t[83]=b.actions,t[84]=b.mode,t[85]=b.scope,t[86]=ke):ke=t[86];let Ae=K(ke),je;t[87]!==a||t[88]!==c||t[89]!==xe||t[90]!==i||t[91]!==n||t[92]!==o||t[93]!==M||t[94]!==b.actions||t[95]!==b.mode||t[96]!==b.scope?(je=e=>{if(xe||Ri(e))return;if(b.mode===`server`){if(!o||!b.scope||!a||!c)return;let t=e,n=c.expectedRevision(),r=b.scope,s=b.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;M.mutateAsync({kind:`edit`,transportIdentity:s.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:L(),runtime:s,runtimeGeneration:s.generation,input:yf(r,t,c.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(qf);return}if(!o)return;let t=e,r=Ff(t,o);if(!r)return;let s=t.queueItemID??t.id,l=t.operationID,u=tf(t);(async()=>{let e;try{e=await Promise.resolve(n(u.content,u.attachments,u.composerDocument,u.composerMentions))}catch{e=!1}e&&(i?.(),C.getState().removeFromQueue(r,s,l))})()},t[87]=a,t[88]=c,t[89]=xe,t[90]=i,t[91]=n,t[92]=o,t[93]=M,t[94]=b.actions,t[95]=b.mode,t[96]=b.scope,t[97]=je):je=t[97];let Me=K(je),Ne;t[98]!==xe||t[99]!==r||t[100]!==o||t[101]!==M||t[102]!==b.actions||t[103]!==b.mode||t[104]!==b.scope?(Ne=e=>{if(xe||Ri(e))return;if(b.mode===`server`){if(!o||!b.scope)return;let t=e,n=b.scope,r=b.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=t.queueItemID;_e.current.delete(i),he(e=>{if(!e.has(i))return e;let t=new Set(e);return t.delete(i),t});let a=L();M.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:vf(n,t,a)}).catch(Jf);return}if(!o)return;let t=e;if(!Ff(t,o))return;let n=t.queueItemID??t.id;_e.current.delete(n),he(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t}),r(n)},t[98]=xe,t[99]=r,t[100]=o,t[101]=M,t[102]=b.actions,t[103]=b.mode,t[104]=b.scope,t[105]=Ne):Ne=t[105];let Pe=K(Ne),Fe;t[106]!==f||t[107]!==xe||t[108]!==u||t[109]!==o||t[110]!==M||t[111]!==b.actions||t[112]!==b.mode||t[113]!==b.scope?(Fe=e=>{if(Ri(e)){f.some(t=>t.requestID===e.requestID)&&u?.(e.requestID);return}if(xe)return;if(b.mode===`server`){if(!o||!b.scope)return;let t=e,n=b.scope,r=b.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=L();M.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:vf(n,t,i)}).catch(Yf);return}if(!o)return;let t=e,n=Ff(t,o);n&&C.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[106]=f,t[107]=xe,t[108]=u,t[109]=o,t[110]=M,t[111]=b.actions,t[112]=b.mode,t[113]=b.scope,t[114]=Fe):Fe=t[114];let Ie=K(Fe),Le=oe.length>0&&(o||f.length>0);if(!Le&&!d)return null;let Re=m?`px-2`:`px-4`,ze;t[115]===Re?ze=t[116]:(ze=Y(`oc-composer-queue relative z-0 -mb-5 w-full`,Re),t[115]=Re,t[116]=ze);let Be=m?`rounded-[1.25rem]`:`rounded-3xl`,Ve;t[117]===Be?Ve=t[118]:(Ve=Y(`overflow-hidden border border-border/60 bg-[var(--surface-subtle)] text-foreground`,Be),t[117]=Be,t[118]=Ve);let He=m?`px-1.5 py-1`:`gap-0.5 px-3 pb-1 pt-1.5`,Ue;t[119]===He?Ue=t[120]:(Ue=Y(`flex flex-col`,He),t[119]=He,t[120]=Ue);let We;t[121]!==le||t[122]!==xe||t[123]!==Ae||t[124]!==Me||t[125]!==Ie||t[126]!==Pe||t[127]!==we||t[128]!==Le||t[129]!==m||t[130]!==de||t[131]!==oe||t[132]!==me||t[133]!==Oe||t[134]!==b.mode?(We=Le?(0,$.jsx)(Ho,{sensors:Oe,collisionDetection:Bo,onDragEnd:Ae,children:(0,$.jsx)(Yo,{items:oe.map(Xf),strategy:Jo,children:oe.map(e=>{let t=e.queueItemID||e.id;return(0,$.jsx)(Of,{message:e,server:b.mode===`server`,frozen:xe,hasDispatchLock:we,pendingOperationKinds:de.get(t)??Mf,sendPendingTimedOut:me.has(t),abortSendPending:le.has(t),isMobile:m,onEdit:Me,onSend:Pe,onRemove:Ie},t)})})}):null,t[121]=le,t[122]=xe,t[123]=Ae,t[124]=Me,t[125]=Ie,t[126]=Pe,t[127]=we,t[128]=Le,t[129]=m,t[130]=de,t[131]=oe,t[132]=me,t[133]=Oe,t[134]=b.mode,t[135]=We):We=t[135];let Ge;t[136]!==Le||t[137]!==d?(Ge=d?(0,$.jsxs)($.Fragment,{children:[Le?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,d]}):null,t[136]=Le,t[137]=d,t[138]=Ge):Ge=t[138];let Je;t[139]!==Ue||t[140]!==We||t[141]!==Ge?(Je=(0,$.jsxs)(`div`,{className:Ue,children:[We,Ge]}),t[139]=Ue,t[140]=We,t[141]=Ge,t[142]=Je):Je=t[142];let Ye=m?`h-4`:`h-5`,Xe;t[143]===Ye?Xe=t[144]:(Xe=(0,$.jsx)(`div`,{"aria-hidden":`true`,className:Ye}),t[143]=Ye,t[144]=Xe);let Ze;t[145]!==Ve||t[146]!==Je||t[147]!==Xe?(Ze=(0,$.jsxs)(`div`,{className:Ve,children:[Je,Xe]}),t[145]=Ve,t[146]=Je,t[147]=Xe,t[148]=Ze):Ze=t[148];let Qe;return t[149]!==ze||t[150]!==Ze?(Qe=(0,$.jsx)(`div`,{className:ze,children:Ze}),t[149]=ze,t[150]=Ze,t[151]=Qe):Qe=t[151],Qe});If.displayName=`QueuedMessageChips`;function Lf(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(Xd,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Rf(e){return e.isMobile}function zf(e){return e.state.variables}function Bf(e){let t=e.state.variables;if(!Df(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 Vf(e){return e!==void 0}function Hf(){return new Set}function Uf(e){return!Ri(e)&&(e.status===`sending`||e.status===`reconciling`)}function Wf(e){return e.reorderQueue}function Gf(){}function Kf(e){return!Ri(e)}function qf(){}function Jf(){}function Yf(){}function Xf(e){return e.queueItemID||e.id}var Zf=[0,200,400],Qf=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=Zf.map($f),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 $f(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var ep=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=st(),n=J(tp),r;e[0]===n?r=e[1]:(r=e=>{if(!n)return null;let t=e.runsByOriginalSessionID[n]??null;return t?.runtimeKey===i()?t:null},e[0]=n,e[1]=r);let a=wi(r),o=wi(np),c=s(rp),l=s(ip);if(!n||!a||a.status!==`running`)return null;let u;e[2]!==a.phase||e[3]!==t?(u=a.phase===`waiting_for_reviewer`?t(`chat.autoReview.status.waitingForReviewer`):t(`chat.autoReview.status.waitingForImplementer`),e[2]=a.phase,e[3]=t,e[4]=u):u=e[4];let d=u,f;e[5]!==c||e[6]!==a.directory||e[7]!==a.reviewSessionID||e[8]!==t?(f=()=>{c(a.directory,{mode:`chat`,dedupeKey:`session:${a.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=c,e[6]=a.directory,e[7]=a.reviewSessionID,e[8]=t,e[9]=f):f=e[9];let p=f,m=l?`pb-1 text-xs`:`pb-2`,h;e[10]===m?h=e[11]:(h=Y(`w-full px-1`,m),e[10]=m,e[11]=h);let g=l?`rounded-lg`:`rounded-xl`,_;e[12]===g?_=e[13]:(_=Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,g),e[12]=g,e[13]=_);let v=l?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`,y;e[14]===v?y=e[15]:(y=Y(`flex w-full items-center text-left`,v),e[14]=v,e[15]=y);let b=l?`size-3.5`:`size-4`,x;e[16]===b?x=e[17]:(x=Y(`animate-spin text-muted-foreground`,b),e[16]=b,e[17]=x);let S;e[18]===x?S=e[19]:(S=(0,$.jsx)(X,{name:`loader-4`,className:x,"aria-hidden":`true`}),e[18]=x,e[19]=S);let C;e[20]===t?C=e[21]:(C=t(`chat.autoReview.title`),e[20]=t,e[21]=C);let w;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(Qf,{}),e[22]=w):w=e[22];let T;e[23]===C?T=e[24]:(T=(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:[C,w]}),e[23]=C,e[24]=T);let E;e[25]===d?E=e[26]:(E=(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:d}),e[25]=d,e[26]=E);let D;e[27]!==T||e[28]!==E?(D=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[T,E]}),e[27]=T,e[28]=E,e[29]=D):D=e[29];let O;e[30]===t?O=e[31]:(O=t(`chat.autoReview.actions.open`),e[30]=t,e[31]=O);let k;e[32]!==p||e[33]!==O?(k=(0,$.jsx)(la,{type:`button`,variant:`secondary`,size:`xs`,onClick:p,children:O}),e[32]=p,e[33]=O,e[34]=k):k=e[34];let A;e[35]!==n||e[36]!==o?(A=()=>o(n),e[35]=n,e[36]=o,e[37]=A):A=e[37];let j;e[38]===t?j=e[39]:(j=t(`chat.autoReview.actions.stop`),e[38]=t,e[39]=j);let M;e[40]!==A||e[41]!==j?(M=(0,$.jsx)(la,{type:`button`,variant:`secondary`,size:`xs`,onClick:A,children:j}),e[40]=A,e[41]=j,e[42]=M):M=e[42];let N;e[43]!==S||e[44]!==D||e[45]!==k||e[46]!==M||e[47]!==y?(N=(0,$.jsxs)(`div`,{className:y,children:[S,D,k,M]}),e[43]=S,e[44]=D,e[45]=k,e[46]=M,e[47]=y,e[48]=N):N=e[48];let P;e[49]!==N||e[50]!==_?(P=(0,$.jsx)(`div`,{className:_,children:N}),e[49]=N,e[50]=_,e[51]=P):P=e[51];let F;return e[52]!==P||e[53]!==h?(F=(0,$.jsx)(`div`,{className:h,children:P}),e[52]=P,e[53]=h,e[54]=F):F=e[54],F});ep.displayName=`AutoReviewBanner`;function tp(e){return e.currentSessionId}function np(e){return e.stopRun}function rp(e){return e.openContextPanelTab}function ip(e){return e.isMobile}var ap=Z.forwardRef((e,t)=>{let n=(0,Q.c)(55),{searchQuery:r,onSkillSelect:i,onClose:a,directory:o,style:c}=e,l=Z.useRef(null),u=s(op),d=hs(l,u),[f,p]=Z.useState(0),m=Z.useRef(0),h=Z.useRef(!1),g;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=[],n[0]=g):g=n[0];let[_,v]=Z.useState(g),y;n[1]===Symbol.for(`react.memo_cache_sentinel`)?(y=[],n[1]=y):y=n[1];let b=Z.useRef(y),x;n[2]===o?x=n[3]:(x={directory:o},n[2]=o,n[3]=x);let S=ti(x),C;n[4]===S.data?C=n[5]:(C=S.data??[],n[4]=S.data,n[5]=C);let w=C,T,E;n[6]!==r||n[7]!==w?(T=()=>{let e=r.trim();if(!e.length){let e=[...w].sort(sp);v(e),p(0);return}let t=Or(w,e,cp);t.sort(lp),v(t.map(up)),p(0)},E=[w,r],n[6]=r,n[7]=w,n[8]=T,n[9]=E):(T=n[8],E=n[9]),Z.useEffect(T,E);let D,O;n[10]===f?(D=n[11],O=n[12]):(D=()=>{m.current=f},O=[f],n[10]=f,n[11]=D,n[12]=O),Z.useEffect(D,O);let k,A;n[13]===f?(k=n[14],A=n[15]):(A=()=>{b.current[f]?.scrollIntoView({block:`nearest`})},k=[f],n[13]=f,n[14]=k,n[15]=A),Z.useEffect(A,k);let j,M;n[16]===a?(j=n[17],M=n[18]):(j=()=>{let e=e=>{let t=e.target;!t||!l.current||l.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},M=[a],n[16]=a,n[17]=j,n[18]=M),Z.useEffect(j,M);let N,P;n[19]!==_||n[20]!==a||n[21]!==i?(N=()=>({handleKeyDown:e=>{if(e===`Escape`){a();return}if(_.length){if(e===`ArrowDown`){h.current=!0,p(e=>(e+1)%_.length);return}if(e===`ArrowUp`){h.current=!0,p(e=>(e-1+_.length)%_.length);return}if(e===`Enter`||e===`Tab`){let e=(m.current%_.length+_.length)%_.length,t=_[e];t&&i(t)}}}}),P=[_,i,a],n[19]=_,n[20]=a,n[21]=i,n[22]=N,n[23]=P):(N=n[22],P=n[23]),Z.useImperativeHandle(t,N,P);let F,I,L,R,z,B,V,H;if(n[24]!==_||n[25]!==u||n[26]!==d||n[27]!==i||n[28]!==f||n[29]!==c){let e=(e,t)=>{let n=e.scope===`project`,r=e.source||`opencode`;return(0,$.jsx)(`div`,{ref:e=>{b.current[t]=e},className:Y(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,u?`items-center`:`items-start`,t===f&&`bg-interactive-selection`),onClick:()=>i(e),onMouseMove:()=>{h.current=!1,p(t)},children:(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold truncate`,children:e.name}),(0,$.jsx)(`span`,{className:Y(`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 transition-colors`,n?`bg-[var(--status-info-background)] text-[var(--status-info)] border-[var(--status-info-border)]`:`bg-[var(--status-success-background)] text-[var(--status-success)] border-[var(--status-success-border)]`),children:e.scope}),(0,$.jsx)(`span`,{className:`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`,children:r})]}),e.description&&!u&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:e.description})]})},`${e.name}-${e.scope}`)};B=l,V=`absolute z-[100] min-w-0 w-full max-w-[450px] max-h-60 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,n[38]!==d||n[39]!==c?(H=d===void 0?c:{...c,maxHeight:d},n[38]=d,n[39]=c,n[40]=H):H=n[40],F=fa,I=!0,L=`flex-1 min-h-0`,R=`px-0 pb-2`,z=_.length?(0,$.jsx)(`div`,{children:_.map((t,n)=>e(t,n))}):(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:`No skills found`}),n[24]=_,n[25]=u,n[26]=d,n[27]=i,n[28]=f,n[29]=c,n[30]=F,n[31]=I,n[32]=L,n[33]=R,n[34]=z,n[35]=B,n[36]=V,n[37]=H}else F=n[30],I=n[31],L=n[32],R=n[33],z=n[34],B=n[35],V=n[36],H=n[37];let U;n[41]!==F||n[42]!==I||n[43]!==L||n[44]!==R||n[45]!==z?(U=(0,$.jsx)(F,{preventOverscroll:I,outerClassName:L,className:R,children:z}),n[41]=F,n[42]=I,n[43]=L,n[44]=R,n[45]=z,n[46]=U):U=n[46];let ee;n[47]===u?ee=n[48]:(ee=!u&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:`↑↓ navigate • Enter select • Esc close`}),n[47]=u,n[48]=ee);let te;return n[49]!==B||n[50]!==V||n[51]!==H||n[52]!==U||n[53]!==ee?(te=(0,$.jsxs)(`div`,{ref:B,className:V,style:H,children:[U,ee]}),n[49]=B,n[50]=V,n[51]=H,n[52]=U,n[53]=ee,n[54]=te):te=n[54],te});ap.displayName=`SkillAutocomplete`;function op(e){return e.isMobile}function sp(e,t){return e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name)}function cp(e){return[e.name,e.description??``]}function lp(e,t){return e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score}function up(e){return e.item}function dp(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 fp(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(pp).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)(dp,{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 pp(e){return e.trim()}var mp=`mobile-overlay-root`,hp=16,gp=200,_p=[],vp=0,yp=``,bp=0,xp=()=>{if(typeof document>`u`)return null;let e=document.getElementById(mp);return e||(e=document.createElement(`div`),e.id=mp,document.body.appendChild(e)),e},Sp=({open:e,title:t,onClose:n,children:r,footer:i,className:a,contentMaxHeightClassName:o,renderHeader:s,containedBody:c=!1,closeAriaLabel:l})=>{let u=Z.useRef(null),d=Z.useRef(Symbol(`mobile-overlay`)),f=Z.useRef(n);f.current=n;let[p,m]=Z.useState(!1),[h,g]=Z.useState(!1);if(typeof document<`u`&&!u.current&&(u.current=xp()),Z.useEffect(()=>{if(!e){m(!1),g(!1);return}let t=window.setTimeout(()=>m(!0),hp),n=window.setTimeout(()=>g(!0),266);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[e]),Z.useLayoutEffect(()=>{if(e)return bp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-opened`)),bp+=1,()=>{bp=Math.max(0,bp-1),bp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-closed`))}},[e]),Z.useEffect(()=>{if(!e)return;let t=d.current;_p.push(t),vp===0&&(yp=document.body.style.overflow),vp+=1,document.body.style.overflow=`hidden`;let n=e=>{e.key===`Escape`&&_p[_p.length-1]===t&&f.current()};return document.addEventListener(`keydown`,n),()=>{let e=_p.lastIndexOf(t);e>=0&&_p.splice(e,1),vp=Math.max(0,vp-1),vp===0&&(document.body.style.overflow=yp),document.removeEventListener(`keydown`,n)}},[e]),!e||!u.current)return null;let _=o??`max-h-[min(70vh,520px)]`,v=(0,$.jsx)(`div`,{className:Y(`oc-keyboard-inset-surface fixed inset-0 z-[60] flex flex-col bg-[rgb(0_0_0_/_0.45)] transition-opacity duration-200 ease-out`,!h&&`oc-keyboard-inset-snap`,p?`opacity-100`:`opacity-0`),role:`dialog`,"aria-modal":`true`,"aria-label":t,onPointerDown:Ja,onClick:e=>{Ha(e)&&n()},children:(0,$.jsxs)(`div`,{className:Y(`mt-auto flex max-h-[calc(100dvh-0.75rem)] min-h-0 w-full flex-col rounded-t-xl border-x border-t border-border/50 bg-background pb-[max(0.5rem,var(--oc-app-bottom-safe,0px),var(--oc-safe-area-bottom,env(safe-area-inset-bottom,0px)))] shadow-none pwa-overlay-panel`,`mx-auto max-w-lg`,a),style:{transform:p?`none`:`translateY(100%)`,transition:`transform ${gp}ms cubic-bezier(0.32, 0.72, 0, 1)`},onClick:e=>e.stopPropagation(),children:[(()=>{let e=(0,$.jsx)(`button`,{type:`button`,onClick:n,className:Y(`flex items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover`,c?`size-11`:`h-8 w-8`),"aria-label":l??t,children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4`})});return s?s(e):(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border/40`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:t}),e]})})(),c?(0,$.jsx)(`div`,{className:Y(`flex min-h-0 flex-1 flex-col overflow-hidden`,_),children:r}):(0,$.jsx)(fa,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:Y(`min-h-0 flex-1`,_),className:`px-2 py-2 pwa-overlay-scroll`,children:r}),i?(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/40 px-3 py-2`,children:i}):null]})});return(0,xc.createPortal)(v,u.current)},Cp=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,wp=1e3,Tp=e=>{let t=(0,Q.c)(24),{name:n,label:r,revealed:i,avatarSize:a,slotClassName:o,colorVar:s}=e,c;t[0]===o?c=t[1]:(c=Y(`inline-flex shrink-0 items-center justify-center`,o),t[0]=o,t[1]=c);let l=i?void 0:r,u;t[2]!==a||t[3]!==n||t[4]!==l?(u=(0,$.jsx)(ea,{name:n,size:a,label:l}),t[2]=a,t[3]=n,t[4]=l,t[5]=u):u=t[5];let d;t[6]!==c||t[7]!==u?(d=(0,$.jsx)(`span`,{className:c,children:u}),t[6]=c,t[7]=u,t[8]=d):d=t[8];let f=i?`grid-cols-[1fr] opacity-100`:`grid-cols-[0fr] opacity-0`,p;t[9]===f?p=t[10]:(p=Y(`grid min-w-0 items-center ease-in-out`,f),t[9]=f,t[10]=p);let m;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m={transitionProperty:`grid-template-columns, opacity`,transitionDuration:`280ms`,transitionTimingFunction:`ease-in-out`},t[11]=m):m=t[11];let h=!i,g;t[12]===s?g=t[13]:(g=s?{color:`var(${s})`}:void 0,t[12]=s,t[13]=g);let _;t[14]!==r||t[15]!==g?(_=(0,$.jsx)(`span`,{className:`flex min-w-0 items-center overflow-hidden`,children:(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap pl-1.5 pr-0.5 typography-micro leading-none font-medium`,style:g,children:r})}),t[14]=r,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==_||t[18]!==p||t[19]!==h?(v=(0,$.jsx)(`span`,{className:p,style:m,"aria-hidden":h,children:_}),t[17]=_,t[18]=p,t[19]=h,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==d?(y=(0,$.jsxs)($.Fragment,{children:[d,v]}),t[21]=v,t[22]=d,t[23]=y):y=t[23],y};function Ep(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},wp),()=>{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 Dp=`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,Op=e=>`flow-root ${e?`py-1`:`py-1.5`}`,kp=`${Dp} hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Ap=`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)]`,jp=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${Ap}`,Mp=`rounded-md ${Ap}`,Np=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},Pp=e=>{if(e)try{let t=Np();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},Fp=(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`},Ip=e=>{let t=Pp(e);return t?Fp(t.permission,`edit`):`ask`},Lp=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},Rp=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return Lp(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:Lp(n.tokens)},zp=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}},Bp=(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}},Vp=[`ask`,`allow`,`full`],Hp=`__global__`,Up=fe()(me(pe((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=Bp(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=Rp(d);if(h===0)return m||null;let g=Bp(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=Rp(o);if(s===0)return;let c=Bp(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`&&Rp(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=Ip(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Hp){let e=t().sessionAgentEditModes.get(Hp)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=Ip(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Vp.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=Ip(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Vp.indexOf(a),s=Vp.indexOf(i),c=Vp[((o>=0?o:s>=0?s:0)+1)%Vp.length];t().setSessionAgentEditMode(e,n,c,i)}}),{name:`context-store`,storage:l(),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`})),Wp=e=>Ar([...e??[]]),Gp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,Kp=(e,t)=>{let n=(0,Q.c)(16),r;n[0]===t?r=n[1]:(r=t===void 0?[]:t,n[0]=t,n[1]=r);let i=r,[a,o]=Z.useState(!1),s;n[2]===e?s=n[3]:(s=()=>{let t=e.current;if(!t)return;let n=t.scrollWidth>t.clientWidth+1;o(e=>e===n?e:n)},n[2]=e,n[3]=s);let c=s,l;n[4]===c?l=n[5]:(l=()=>{c()},n[4]=c,n[5]=l);let u;n[6]!==c||n[7]!==i?(u=[c,...i],n[6]=c,n[7]=i,n[8]=u):u=n[8],Gp(l,u);let d,f;n[9]!==c||n[10]!==e?(d=()=>{let t=e.current;if(!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{c()});return n.observe(t),()=>n.disconnect()},f=[c,e],n[9]=c,n[10]=e,n[11]=d,n[12]=f):(d=n[11],f=n[12]),Z.useEffect(d,f);let p,m;return n[13]===c?(p=n[14],m=n[15]):(p=()=>{if(typeof window>`u`||typeof ResizeObserver<`u`)return;let e=()=>c();return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},m=[c],n[13]=c,n[14]=p,n[15]=m),Z.useEffect(p,m),a};function qp(e,t){return!e&&t===`trigger-hover`}var Jp=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},Yp=e=>{let t=Jp(e);return t?(t.focus({preventScroll:!0}),!0):!1},Xp=(e,t)=>e&&!t,Zp=e=>{let t=e?.variants;return t?Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):typeof t==`object`?Object.keys(t):[]:[]},Qp=(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 Zp(i)},$p=()=>!0,em=(e,t)=>(e.commandPolicy??$p)(t),tm=Z.createContext(null),nm=()=>Z.useContext(tm),rm=e=>e,im=(e,t)=>t??e,am=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`)},om=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,sm=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},cm=(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}},lm=(e,t)=>`${e}:${t}`,um=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,dm=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},fm=(e,t)=>{let n=dm(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}}},pm=[{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}],mm={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`}},hm=e=>e.trim().toLowerCase(),gm=(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=>hm(e)))),i=[];for(let e of r){let t=mm[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},_m=e=>new Intl.NumberFormat(ct(),{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:1,minimumFractionDigits:0}).format(e),vm=e=>new Intl.NumberFormat(ct(),{style:`currency`,currency:`USD`,maximumFractionDigits:4,minimumFractionDigits:2}).format(e),ym=e=>new Intl.DateTimeFormat(ct(),{month:`short`,day:`numeric`,year:`numeric`}).format(e),bm=`__add_provider__`,xm=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},Sm=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=Cp(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},Cm=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=_m(e);return t.endsWith(`.0`)?t.slice(0,-2):t},wm=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:vm(e),Tm=e=>{let t=[];for(let n of pm)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},Em=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:ym(t)},Dm=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=st(),o=Z.useId(),{isReady:c,isUnavailable:l}=to(),u=l||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),d=mi(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=mi(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),p=i?.catalog,m=c&&(p?.ready??!d)&&!p?.loading&&!p?.error&&!i?.disabled,h=c&&(p?.ready??!f)&&!p?.loading&&!p?.error&&!i?.disabled,g=m&&h,_=mi(e=>e.providers),v=p?.providers??_,y=mi(e=>e.currentProviderId),b=mi(e=>e.currentModelId),x=i?.selection.providerID??y,S=i?.selection.modelID??b,C=mi(e=>e.currentVariant),w=i?i.selection.variant:C,T=mi(e=>e.currentAgentName),E=i?i.selection.agent??void 0:T,D=mi(e=>e.settingsDefaultVariant),O=mi(e=>e.settingsDefaultAgent),k=mi(e=>e.setProvider),A=mi(e=>e.setSelectedProvider),j=mi(e=>e.setModel),M=mi(e=>e.setCurrentVariant),N=mi(e=>e.getCurrentModelVariants),P=mi(e=>e.setAgent),F=mi(e=>e.getCurrentProvider),I=mi(e=>e.getModelMetadata),L=mi(e=>e.getCurrentAgent),R=mi(e=>e.getVisibleAgents),z=Wp(p?.agents??R()),B=Z.useMemo(()=>z.filter(e=>e.mode===`primary`),[z]),V=Z.useRef(!1);Z.useEffect(()=>{V.current||!g||(V.current=!0,je(`ModelControls:ready`,{providers:v.length,agents:z.length,currentProviderId:x,currentModelId:S,currentAgentName:E}))},[z.length,g,E,S,x,v.length]);let H=J(e=>i?null:e.currentSessionId),U=J(e=>e.getDirectoryForSession),ee=zl(),te=Vt(e=>e.getSessionModelSelection),W=Vt(e=>e.saveSessionModelSelection),G=Vt(e=>e.saveSessionAgentSelection),ne=Vt(e=>e.saveAgentModelForSession),re=Vt(e=>e.getAgentModelForSession),ie=Vt(e=>e.saveAgentModelVariantForSession),ae=Vt(e=>e.getAgentModelVariantForSession),oe=Up(e=>e.hasHydrated),se=Vt(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=s(e=>e.toggleFavoriteModel),fe=s(e=>e.reorderFavoriteModel),pe=s(e=>e.providerOrder),me=s(e=>e.setProviderOrder),he=s(e=>e.isFavoriteModel),ge=s(e=>e.addRecentModel),_e=s(e=>e.addRecentAgent),ve=s(e=>e.addRecentEffort),ye=s(e=>e.isModelSelectorOpen),be=s(e=>e.setModelSelectorOpen),xe=s(e=>e.isAgentSelectorOpen),Se=s(e=>e.setAgentSelectorOpen),Ce=s(e=>e.isModelSelectorInstant),we=s(e=>e.isAgentSelectorInstant),Te=s(e=>e.setSettingsDialogOpen),Ee=s(e=>e.setSettingsPage),De=s(e=>e.hiddenModels),Oe=s(e=>e.shortcutOverrides.cycle_agent),ke=Z.useMemo(()=>Ya(`cycle_agent`,Oe?{cycle_agent:Oe}:void 0),[Oe]),{favoriteModelsList:Ae,recentModelsList:Me}=ga({currentProviderID:x,currentModelID:S}),{isMobile:Ne}=fo(),Pe=s(e=>e.isMobile),Fe=Ne||Pe,Ie=ko(),Le=Fe,[Re,ze]=Z.useState(null),Be=n!==void 0&&typeof r==`function`,Ve=Be?n:Re,He=Be?r:ze,Ue=K(e=>{He(e),mi.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),We=K((e,t)=>{if(qp(e,t?.reason)){t?.cancel?.();return}Se(e),e&&mi.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopAgentMenu`})}),[Ge,Ke]=Z.useState(null),qe=Z.useRef(!1),Je=Z.useCallback(()=>He(null),[He]),Ye=Z.useCallback(()=>Ke(null),[]),Xe=Z.useRef(void 0),Ze=ye,Qe=be,$e=Z.useCallback(()=>{A(bm),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),ct=K((e,t)=>{if(qp(e,t?.reason)){t?.cancel?.();return}at(!1),e||(ot.current=performance.now()+200,rt(null),tt(``)),Qe(e),e&&mi.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),lt=Z.useRef(!1),ut=Z.useRef(null),dt=Z.useRef(void 0),[ft,pt]=Z.useState(new Map),[ht,gt]=Z.useState(new Set),[_t,vt]=Z.useState(0),yt=Z.useCallback(()=>{let e=()=>{let e=s.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&Yp(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),bt=Z.useCallback(e=>{let t=s.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(s.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!s.getState().isMobile&&yt())},[yt]),xt=Z.useCallback(()=>{let e=s.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Jp(t)},[t]),St=Z.useRef(ye);Z.useEffect(()=>{let e=St.current;St.current=ye,ye||(tt(``),lt.current=!1,ut.current=null,pt(new Map),gt(new Set),e&&!Le&&(at(!1),ot.current=performance.now()+200))},[ye,Le]);let[Ct,wt]=Z.useState(``);Z.useEffect(()=>{xe||wt(``)},[xe]);let Tt=Z.useMemo(()=>z.filter(e=>tr(e.mode)),[z]),Et=Z.useMemo(()=>Ct.trim()?Or(Tt,Ct.trim(),e=>[e.name,e.description??``]).map(e=>e.item):[...Tt].sort((e,t)=>e.name.localeCompare(t.name)),[Tt,Ct]),Dt=Z.useMemo(()=>{if(O){let e=Tt.find(e=>e.name===O);if(e)return e.name}let e=Tt.find(e=>e.name===`build`);return e?e.name:Tt[0]?.name},[O,Tt]),Ot=Z.useMemo(()=>ue?z.find(e=>e.name===ue):L?.(),[z,L,ue]),kt=Fe?`mobile`:Ie?`vscode`:`default`,At=kt===`mobile`?`size-5`:`size-4`,jt=Le?`typography-micro`:`typography-meta`,Mt=kt===`mobile`?`gap-x-1`:kt===`vscode`?`gap-x-2`:`gap-x-1.5`,Nt=kt===`mobile`?`h-8 w-8`:kt===`vscode`?`h-5 w-5`:`h-6 w-6`,Pt=kt===`mobile`?18:kt===`vscode`?14:16,Ft=Ep(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?va(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]),Ht=Z.useMemo(()=>Tm(zt).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Ut=Z.useMemo(()=>gm(zt,`input`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Wt=Z.useMemo(()=>gm(zt,`output`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Gt=Z.useMemo(()=>{if(p?.variantsReady===!1)return[];if(p?.variants)return[...p.variants];if(x&&S){let e=v.find(e=>e.id===x)?.models?.find(e=>e.id===S);return Zp(e)}return i?[]:N()},[S,x,N,v,i,p?.variants,p?.variantsReady]),Kt=Gt.length>0,qt=[{label:`Input`,value:wm(zt?.cost?.input)},{label:`Output`,value:wm(zt?.cost?.output)},{label:`Cache read`,value:wm(zt?.cost?.cache_read)},{label:`Cache write`,value:wm(zt?.cost?.cache_write)}],Jt=[{label:`Context`,value:Cm(zt?.limit?.context)},{label:`Output`,value:Cm(zt?.limit?.output)}],Yt=Z.useRef(void 0),Xt=Z.useRef(null),Zt=Z.useRef(null),Qt=H?U(H):void 0,$t=mt(H??``,Qt??void 0).renderable,tn=Di(H??``,Qt??void 0),nn=Z.useMemo(()=>{for(let e=tn.length-1;e>=0;--e){let t=tn[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},[tn]),rn=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&&(W(H,e,t),n&&ne(H,n,e,t)),`applied`):`model-missing`:`provider-missing`},[v,x,S,k,j,H,ne,W]),an=Z.useCallback((e,t)=>{if(i&&i.selection.providerID===e&&i.selection.modelID===t)return Qp(i.selection,i.catalog,e,t);let n=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Zp(n)},[v,i,i?.selection.providerID,i?.selection.modelID,p?.variants,p?.variantsReady]),sn=Z.useCallback((e,t)=>{let n=i?Qp(i.selection,i.catalog,e,t):[],r=n.length>0?n:an(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,an,i,D,ue]),cn=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=mi.getState().currentAgentName;return H?Vt.getState().getSessionAgentSelection(H)||ce.current||e||E:e||E},[E,H,i]),ln=Z.useCallback((e,t,n,r)=>{if(i){i.onChange({...i.selection,providerID:e,modelID:t,variant:n}).catch(()=>void 0);return}if(an(e,t).length===0){qe.current=!1,M(void 0);return}qe.current=!0,M(n),ve(e,t,n);let a=r??cn();H&&a&&ie(H,a,e,t,n)},[ve,H,an,cn,ie,i,M]),un=Z.useCallback((e,t,n,r)=>{let a=r??cn()??void 0,o=rn(e,t,a);if(o!==`applied`)return o;ln(e,t,n,a);let s=i?n:mi.getState().currentVariant;return ge(e,t,s),`applied`},[ge,ln,cn,i,rn]);Z.useEffect(()=>{if(i)return;if(!H){Zt.current=null;return}if(!oe||v.length===0||!$t||!nn?.providerID||!nn.modelID)return;let e=[H,nn.id,nn.agent??``,nn.providerID,nn.modelID,nn.variant??``].join(`|`);if(Zt.current===e)return;nn.agent&&E!==nn.agent&&P(nn.agent);let t=nn.variant&&an(nn.providerID,nn.modelID).includes(nn.variant)?nn.variant:void 0;un(nn.providerID,nn.modelID,t,nn.agent||E||void 0)===`applied`&&(nn.agent&&(G(H,nn.agent),ie(H,nn.agent,nn.providerID,nn.modelID,t)),W(H,nn.providerID,nn.modelID),Zt.current=e)},[i,H,E,oe,v,$t,nn,P,un,an,G,ie,W]),Z.useEffect(()=>{if(i)return;if(!H){Zt.current=null;return}if(!oe||v.length===0||z.length===0)return;let e=()=>{let e=te(H),t=H?Vt.getState().getSessionAgentSelection(H):null;if(t){E!==t&&P(t);let e=re(H,t);if(e){let n=rn(e.providerId,e.modelId,t);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}}if(e){let n=rn(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=re(H,e.name);if(!t)continue;E!==e.name&&P(e.name),Vt.getState().getSessionAgentSelection(H)||ce.current||G(H,e.name);let n=rn(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?Vt.getState().getSessionAgentSelection(H)||ce.current:null,t=(H?Vt.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||G(H,n.name),E!==n.name&&P(n.name),n.model?.providerID&&n.model?.modelID&&rn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!$t){ee.isLoading(H)||ee.ensureSessionRenderable(H);return}nn||t()}},[i,H,$t,nn,z,B,E,te,re,P,rn,G,oe,v,ee]),Z.useEffect(()=>{if(i||!oe)return;let e=new AbortController;return(async()=>{try{if(E!==Yt.current&&(Yt.current=E,E&&H)){let t=Xt.current===E;if(Xt.current=null,await new Promise(t=>{let n=setTimeout(t,50);e.signal.addEventListener(`abort`,()=>{clearTimeout(n),t()})}),e.signal.aborted)return;let n=re(H,E);if(n){let e=rn(n.providerId,n.modelId,E);if(e===`applied`||e===`provider-missing`)return}let r=mi.getState().getAgentModelSelection(E);if(r){let e=rn(r.providerId,r.modelId,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(W(H,r.providerId,r.modelId),ne(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=rn(i.model.providerID,i.model.modelID,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(W(H,i.model.providerID,i.model.modelID),ne(H,E,i.model.providerID,i.model.modelID));return}}}}catch(e){console.error(`[ModelControls] Agent change error:`,e)}})(),()=>{e.abort()}},[i,z,E,H,re,ne,ie,W,M,rn,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(Gt.length===0){qe.current=!1,M(void 0);return}if(w&&!Gt.includes(w)){M(void 0);return}if(!H){if(!w&&!qe.current){let e=D&&Gt.includes(D)?D:void 0;M(e)}return}let e=ae(H,E,x,S),t=e&&Gt.includes(e)?e:D&&Gt.includes(D)?D:void 0;M(t),qe.current=!1},[i,Gt,oe,H,E,x,S,w,ae,M,D]),Z.useEffect(()=>{qe.current=!1},[x,S]);let dn=Z.useCallback((e,t)=>{if(i){let n=cr(i.selection,e,z,v),r=n.providerID===i.selection.providerID&&n.modelID===i.selection.modelID;Le&&Je(),i.onChange({...n,variant:r?i.selection.variant:void 0}).then(()=>{_e(e),(t?.closeModelSelector??!0)&&Qe(!1)}).catch(()=>void 0);return}try{Xt.current=e,P(e),_e(e),(t?.closeModelSelector??!0)&&Qe(!1),H&&G(H,e),Le&&Je()}catch(e){console.error(`[ModelControls] Handle agent change error:`,e)}},[_e,z,Je,H,Le,v,G,i,P,Qe]),fn=Z.useCallback(e=>{let t=en(z,E,e);t&&dn(t,{closeModelSelector:!1})},[z,E,dn]),pn=Z.useCallback(e=>{let t=ke&&!ke.includes(`shift`)?Xa(`shift+${ke}`):``;return t&&Va(e,t)?-1:Va(e,ke)?1:null},[ke]),mn=Z.useCallback(e=>{let t=pn(e);t&&(e.preventDefault(),e.stopPropagation(),fn(t))},[pn,fn]),hn=Z.useCallback((e,t,n,r)=>{!e||!t||!n||mi.getState().saveAgentModelSelection(e,t,n,r)},[]),gn=(e,t,n)=>{let r=()=>{Qe(!1,n?.closeInstant?{instant:!0}:void 0)};if(i){Le&&Je();let a=n?.applyVariant?n.variant:sn(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??cn()??void 0,a=n?.applyVariant?un(e,t,n.variant,i):rn(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}hn(i,e,t,n?.applyVariant?n.variant:mi.getState().currentVariant),n?.applyVariant||ge(e,t,mi.getState().currentVariant),r(),Le&&Je()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},_n=(e,t)=>On(e,t,{maxLength:40}),vn=()=>v.find(e=>e.id===x)?.name||x,yn=()=>{if(!S)return a(`chat.modelControls.selectModel`);let e=Lt.find(e=>e.id===S);return _n(e,S)||a(`chat.modelControls.selectModel`)},bn=yn(),q=Z.useRef(null),xn=Kp(q,[bn,w,Le]),Sn=()=>{if(!ue){let e=B.find(e=>e.name===`build`)||B[0];return e?Cn(e.name):`Select Agent`}let e=z.find(e=>e.name===ue);return Cn(e?e.name:ue)},Cn=e=>e.charAt(0).toUpperCase()+e.slice(1),wn=Z.useCallback(e=>{Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>{Ke(e)},500)},[]),Tn=Z.useCallback(()=>{Xe.current&&clearTimeout(Xe.current)},[]);Z.useEffect(()=>()=>{Xe.current&&clearTimeout(Xe.current)},[]);let En=()=>!Le||Ge!==`model`?null:(0,$.jsx)(Sp,{open:!0,onClose:Ye,title:zt?.name||yn(),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:vn()})]}),Ht.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:Ht.map(({key:e,icon:t,label:n})=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(xm,{iconName:t,label:n},`cap-${e}`),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:n})]},e))})]}),(Ut.length>0||Wt.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:[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.input`)}),(0,$.jsx)(`div`,{className:`flex gap-1`,children:Ut.map(({key:e,icon:t,label:n})=>(0,$.jsx)(xm,{iconName:t,label:`${n} input`},`input-${e}`))})]}),Wt.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:Wt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(xm,{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:Cm(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:Cm(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:Em(zt.release_date)})]})})]}):null]})}),Dn=()=>{if(!Le||Ge!==`agent`||!Ot)return null;let e=!!(Ot.prompt&&Ot.prompt.trim().length>0),t=Ot.model?.providerID&&Ot.model?.modelID,n=Ot.temperature!==void 0||Ot.topP!==void 0,r=e=>{let t=dm(Ot.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=fm(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)(Sp,{open:!0,onClose:Ye,title:Cn(Ot.name),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[Ot.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:Ot.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:Ot.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Ot.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Ot.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:[Ot.model.providerID,` / `,Ot.model.modelID]}),n&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[Ot.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:Ot.temperature})]}),Ot.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:Ot.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)(Sm,{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)(Sm,{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)(Sm,{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`})]})})]})})},kn=()=>Le?(0,$.jsx)(oo,{open:Ve===`model`||Ve===`variant`,view:Ve===`variant`?`variant`:`model`,onViewChange:e=>He(e),onClose:Je,selectedProviderID:x||``,selectedModelID:S||``,resolveSelectedVariant:sn,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=un(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}hn(cn(),e,t,n),Je()},providers:v,favoriteModels:Ae,recentModels:Me,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??Me.find(n=>n.providerID===e&&n.modelID===t)?.variant),getMetadata:I}):null,An=()=>Le?(0,$.jsx)(Qa,{id:`mobile-agent-picker-sheet-${o}`,open:Ve===`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)(fa,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`flex flex-col gap-2 overscroll-contain`,children:Tt.map(e=>{let t=e.name===ue,n=$i(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:()=>dn(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)(ea,{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:Cn(e.name)}),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,jn=()=>(0,$.jsx)(La,{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||yn()}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:vn()})]}),(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:Ht.length>0?Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(xm,{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:Ut.length>0?Ut.map(({key:e,icon:t,label:n})=>(0,$.jsx)(xm,{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:Wt.length>0?Wt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(xm,{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`)}),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))]}),(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`)}),Jt.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:Em(zt.release_date)})]})]}):null]}):(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.metadataUnavailable`)})}),Mn=()=>{let e=(e,t)=>{if(lt.current=!0,e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return!1;let{providerID:n,modelID:r}=t,i=an(n,r);if(i.length===0)return!1;e.preventDefault(),e.stopPropagation();let a=lm(n,r),o=ft.has(a),s=ft.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 pt(e=>{let t=new Map(e);return t.set(a,d),t}),gt(e=>{let t=new Set(e);return t.add(a),t}),vt(e=>e+1),!0},t=(t,n)=>{let r=pn(t);if(r){t.preventDefault(),fn(r);return}n&&e(t,n)},n=e=>{let t=lm(e.providerID,e.modelID),n=ft.get(t),r=ht.has(t),i=cn();if(r){gn(e.providerID,e.modelID,{applyVariant:!0,variant:n,agentName:i});return}let a=an(e.providerID,e.modelID),o=e.variant!==void 0&&a.includes(e.variant)?e.variant:void 0;if(o!==void 0){gn(e.providerID,e.modelID,{applyVariant:!0,variant:o,agentName:i});return}gn(e.providerID,e.modelID,{agentName:i})},r=e=>{let t=pn(e);t&&(e.preventDefault(),e.stopPropagation(),lt.current=!0,fn(t))},i=e=>e?.trim()?on(e):a(`chat.modelControls.default`),o=(e,t)=>{let n=cn();gn(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`)},l=(e,{isSelected:t})=>{let n=an(e.providerID,e.modelID);if(n.length===0)return null;let r=lm(e.providerID,e.modelID),o=ft.has(r),s=ft.get(r),c=e.variant!==void 0&&n.includes(e.variant)?e.variant:void 0,l=o?s:t?w:c,u=ht.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=an(nt.providerID,nt.modelID),t=lm(nt.providerID,nt.modelID),n=ft.has(t),r=ft.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=On(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)(Ea,{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)(dp,{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&&Kt?on(w):null;return(0,$.jsxs)(Ra,{open:!Ze&&it,onOpenChange:s,delayDuration:200,children:[Le?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>Ue(`model`):void 0,onTouchStart:m?()=>wn(`model`):void 0,onTouchEnd:m?Tn:void 0,onTouchCancel:m?Tn:void 0,disabled:!m,className:Y(`model-controls__model-trigger min-w-0 focus:outline-none`,m?Y(`cursor-pointer`,jp):`opacity-60 cursor-not-allowed`),children:m?(0,$.jsxs)($.Fragment,{children:[x||S?(0,$.jsx)(Ea,{modelId:S,providerId:x,className:Y(At,`flex-shrink-0`)}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(At,`text-muted-foreground`)}),(0,$.jsx)(`span`,{ref:q,className:Y(`model-controls__model-label typography-micro font-medium overflow-hidden min-w-0`,Fe?`max-w-[120px]`:`max-w-[220px]`),children:(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1`,xn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:bn}),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(At,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:`typography-micro font-medium text-muted-foreground min-w-0`,children:u})]})}):(0,$.jsxs)(Ua,{open:m&&Ze,onOpenChange:m?ct:void 0,onOpenChangeComplete:e=>{e||bt(`model`)},children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,jp),children:[m?x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ea,{modelId:S,providerId:x,className:Y(At,`flex-shrink-0`)}),(0,$.jsx)(X,{name:`pencil-ai`,className:Y(At,`text-primary/60 hidden`)})]}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(At,`text-muted-foreground`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(At,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:Y(`model-controls__model-label`,jt,`font-medium whitespace-nowrap text-muted-foreground min-w-0`),children:u})]}),m&&(0,$.jsx)(`span`,{ref:q,className:Y(`model-controls__model-label overflow-hidden`,jt,`font-medium whitespace-nowrap text-foreground min-w-0`,`max-w-[260px]`),children:(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1`,xn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:bn}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})},`${x}-${S}-${w??``}`)]})})}),(0,$.jsx)(Ka,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,Ce&&um),align:`end`,alignOffset:-40,onKeyDownCapture:r,finalFocus:xt,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)(pa,{providers:v,favoriteModels:Ae,recentModels:Me,getMetadata:I,searchQuery:et,onSearchQueryChange:tt,onSelect:n,labels:c,selectedModel:x&&S?{providerID:x,modelID:S}:null,hiddenModels:De,onActiveKeyDown:t,onActiveEntryChange:e=>{dt.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:l,renderVersion:_t,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?an(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)}})]})})]}),jn()]})},Nn=()=>{if(!Ot)return(0,$.jsx)(La,{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=!!(Ot.prompt&&Ot.prompt.trim().length>0),t=Ot.model?.providerID&&Ot.model?.modelID,n=Ot.temperature!==void 0||Ot.topP!==void 0,r=e=>{let t=dm(Ot.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=fm(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)(La,{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:Cn(Ot.name)}),Ot.description&&(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:Ot.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:Ot.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Ot.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Ot.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:[Ot.model.providerID,` / `,Ot.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:[Ot.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:Ot.temperature})]}),Ot.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:Ot.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)(Sm,{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)(Sm,{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)(Sm,{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`})]})]})})},Pn=()=>{let e=Sn(),t=ue?$i(ue):null;return Le?(0,$.jsx)(`button`,{type:`button`,onClick:h?()=>Ue(`agent`):void 0,onTouchStart:h?()=>wn(`agent`):void 0,onTouchEnd:h?Tn:void 0,onTouchCancel:h?Tn:void 0,disabled:!h,className:Y(`model-controls__agent-trigger inline-flex items-center flex-shrink-0 min-w-0 focus:outline-none`,Mp,h?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:h?(0,$.jsx)(Tp,{name:ue,label:e,revealed:Ft,avatarSize:Pt,slotClassName:Nt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,Nt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(At,`flex-shrink-0 animate-spin text-muted-foreground`)})})}):(0,$.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,$.jsxs)(Ra,{delayDuration:600,children:[(0,$.jsxs)(Ua,{open:h&&xe,onOpenChange:h?We:void 0,onOpenChangeComplete:e=>{e||bt(`agent`)},children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,Mp),children:h?(0,$.jsx)(Tp,{name:ue,label:e,revealed:Ft,avatarSize:Pt,slotClassName:Nt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,Nt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(At,`flex-shrink-0 animate-spin text-muted-foreground`)})})})})}),(0,$.jsxs)(Ka,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,we&&um),onKeyDownCapture:mn,finalFocus:xt,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)(Fa,{type:`text`,placeholder:a(`chat.modelControls.searchAgents`),value:Ct,onChange:e=>wt(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)(fa,{outerClassName:`max-h-[min(400px,calc(100dvh-12rem))] flex-1`,children:(0,$.jsxs)(`div`,{className:`p-1`,children:[!Ct.trim()&&Dt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ao,{className:`typography-meta`,onSelect:()=>dn(Dt),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)(Ga,{})]}),Et.length===0?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-meta text-muted-foreground`,children:`No agents found`}):Et.map(e=>(0,$.jsx)(ao,{className:`typography-meta`,onSelect:()=>dn(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)(ea,{name:e.name,size:14}),(0,$.jsx)(`span`,{className:`font-medium`,children:Cn(e.name)})]}),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)(dp,{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`)})]})]})]}),Nn()]})})},Fn=Y(`@container/model-controls flex items-center min-w-0`,Fe&&`w-full`,e),In=Pn();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Fn,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center min-w-0 flex-1 justify-end`,Mt,Fe&&`overflow-hidden`),children:[In,Mn()]})}),kn(),An(),En(),Dn()]})},Om=[{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`}],km=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=st(),i=bl(Am),a=s(jm),o;t[0]===a?o=t[1]:(o=Wa(Ya(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let c=o;if(!i)return null;let l;t[2]===r?l=t[3]:(l=r(`chat.leaderKey.pendingAria`),t[2]=r,t[3]=l);let u;t[4]===n?u=t[5]:(u=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]=u);let d;t[6]===c?d=t[7]:(d=(0,$.jsx)(fp,{shortcut:c,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]=c,t[7]=d);let f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}),t[8]=f):f=t[8];let p;t[9]===r?p=t[10]:(p=Om.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)(dp,{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]=p);let m;return t[11]!==l||t[12]!==u||t[13]!==d||t[14]!==p?(m=(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":l,className:u,children:[d,f,p]}),t[11]=l,t[12]=u,t[13]=d,t[14]=p,t[15]=m):m=t[15],m};function Am(e){return e.pending}function jm(e){return e.shortcutOverrides}var Mm=28,Nm=8,Pm=10.5,Fm=Math.PI/2,Im=e=>Array.from({length:Nm},(t,n)=>{let r=n/Nm*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*Pm,Math.sin(r)*Pm]}),Lm=[Im(0),Im(Fm),Im(Math.PI),Im(Math.PI*1.5)],Rm=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,zm=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(`oc-morph-orb-glyph shrink-0`,i),t[0]=i,t[1]=o);let s=a/Mm,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:`oc-morph-orb-stage`,children:Lm[0].map(Bm)}),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 Bm(e,t){return(0,$.jsx)(`span`,{className:`oc-morph-orb-dot`,style:{"--m-1":Rm(Lm[0][t]),"--m-2":Rm(Lm[1][t]),"--m-3":Rm(Lm[2][t]),"--m-4":Rm(Lm[3][t])}},t)}var Vm=1200,Hm=600,Um=1e9,Wm=0xe8d4a51000,Gm=e=>e>=Wm?e:e>=Um?e*1e3:Date.now()+e;function Km({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o}){let{locale:s,t:c}=st(),[l,u]=Z.useState(null),[d,f]=Z.useState(!1),p=Z.useRef(l),m=Z.useRef(d),h=Z.useRef(!1);p.current=l,m.current=d;let g=Z.useRef(0),_=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),[b,x]=Z.useState(null),[S,C]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;C(Date.now());let t=window.setInterval(()=>C(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){x(null);return}let t=Gm(e),n=()=>{let e=Math.max(0,t-Date.now());x(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let w=K(()=>{v.current&&=(clearTimeout(v.current),null),y.current&&=(clearTimeout(y.current),null)}),T=K((e,t,n=!1)=>{w(),_.current=null,u(e),f(t),h.current=n,g.current=Date.now()}),E=K(()=>{if(v.current)return;let e=Date.now()-g.current,t=Math.max(0,Vm-e);v.current=setTimeout(()=>{v.current=null;let e=_.current;e&&T(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(!e){if(v.current&&=(clearTimeout(v.current),null),_.current=null,!p.current||y.current)return;y.current=setTimeout(()=>{y.current=null,u(null),f(!1),h.current=!1},Hm);return}if(y.current&&=(clearTimeout(y.current),null),a){w(),_.current=null;return}let t=i?c(`chat.assistantStatus.waitingForPermission`):n,o=!!i,s=!!r&&!o;if(t){if(!p.current){T(t,o,s);return}if((t!==p.current||o!==m.current)&&!(s&&h.current)){if(s){_.current={text:t,permission:o,generic:s},E();return}T(t,o,s)}}},[e,n,r,i,a,c]),Z.useEffect(()=>()=>w(),[]),!e&&!l)return null;if(a&&e){let e=b!==null&&b>0?new Intl.RelativeTimeFormat(s,{numeric:`always`,style:`short`}).format(b,`second`):null,n=e?a.attempt&&a.attempt>1?c(`chat.assistantStatus.retryingInAttempt`,{duration:e,attempt:a.attempt}):c(`chat.assistantStatus.retryingIn`,{duration:e}):a.attempt&&a.attempt>1?c(`chat.assistantStatus.retryingAttempt`,{attempt:a.attempt}):c(`chat.assistantStatus.retrying`);return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":n,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)(zm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:n})]})})}if(!l)return null;let D=l,O=typeof o==`number`&&e?ht(Math.max(0,S-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":d?`assertive`:`polite`,"aria-label":D,"data-waiting":d?`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)(zm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:D}),O?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:O}):null]})})}var qm={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Jm={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Ym={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:qm},Xm=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?qm:Jm}),Zm=Z.createContext(Ym),Qm=()=>Z.useContext(Zm),$m=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}),eh=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,th={containerType:`inline-size`,containerName:`status-row`},nh=[],rh=e=>{let t=(0,Q.c)(97),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:c,retryInfo:l,turnStartedAt:u,showAbortStatus:f,showAbortPrompt:p,showAssistantStatus:m,showTodos:h,agentName:g,leftAccessory:_}=e,v=n!==void 0&&n,y=r===void 0?null:r,b=p!==void 0&&p,x=m===void 0||m,S=h===void 0||h,{t:C}=st(),[w,T]=Z.useState(!1),E=Qm(),D=J(ih),O=E.sessionId??D,k;t[0]!==O||t[1]!==S?(k=e=>!S||!O?nh:e.todo[O]??nh,t[0]=O,t[1]=S,t[2]=k):k=t[2];let A=$n(k,E.directory??void 0),j;t[3]!==O||t[4]!==S?(j=e=>S&&O?e.sessions[O]?.todos:void 0,t[3]=O,t[4]=S,t[5]=j):j=t[5];let M=gr(j),N;bb0:{if(!O){N=nh;break bb0}if(A.length>0){N=A;break bb0}N=M??nh}let P=N,F=s(ah),I;t[6]===F?I=t[7]:(I=F||d(),t[6]=F,t[7]=I);let L=I,R;t[8]===P?R=t[9]:(R=P.filter(oh),t[8]=P,t[9]=R);let z=R,B;t[10]===z?B=t[11]:(B=z.find(sh)||z.find(ch)||null,t[10]=z,t[11]=B);let V=B,H;t[12]===z?H=t[13]:(H=z.find(lh)??null,t[12]=z,t[13]=H);let U=H,ee;t[14]===P?ee=t[15]:(ee=P.filter(uh),t[14]=P,t[15]=ee);let te=ee.length,W;t[16]===P?W=t[17]:(W=P.filter(dh),t[16]=P,t[17]=W);let G=W.length,ne;t[18]!==G||t[19]!==te?(ne={completed:G,total:te},t[18]=G,t[19]=te,t[20]=ne):ne=t[20];let re=ne,ie;t[21]===z?ie=t[22]:(ie=z.filter(fh),t[21]=z,t[22]=ie);let ae=ie.length,oe;t[23]===z?oe=t[24]:(oe=z.filter(ph),t[23]=z,t[24]=oe);let se=oe.length,ce;t[25]!==ae||t[26]!==se?(ce={active:ae,left:se},t[25]=ae,t[26]=se,t[27]=ce):ce=t[27];let le=ce,ue=S&&le.left>0,de=!!b,[fe,pe]=Z.useState(!1),me,he;t[28]!==fe||t[29]!==v?(me=()=>{if(v){pe(!0);return}if(!fe)return;let e=window.setTimeout(()=>pe(!1),600);return()=>window.clearTimeout(e)},he=[v,fe],t[28]=fe,t[29]=v,t[30]=me,t[31]=he):(me=t[30],he=t[31]),Z.useEffect(me,he);let ge=x&&(v||fe||!!o||!!f),_e=!!_,ve=!f&&!de&&(o||!c),ye=de||ge||ue||_e,be=Z.useRef(null),xe=Z.useRef(null),Se=Z.useRef(null),Ce,we;t[32]===w?(Ce=t[33],we=t[34]):(Ce=()=>{let e=xe.current,t=Se.current;if(!w||!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))},we=[w],t[32]=w,t[33]=Ce,t[34]=we),Z.useLayoutEffect(Ce,we);let Te,Ee;t[35]===w?(Te=t[36],Ee=t[37]):(Te=()=>{if(!w)return;let e=e=>{be.current&&!be.current.contains(e.target)&&T(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},Ee=[w],t[35]=w,t[36]=Te,t[37]=Ee),Z.useEffect(Te,Ee);let De;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(De=()=>T(mh),t[38]=De):De=t[38];let Oe=K(De),ke;t[39]!==le.active||t[40]!==le.left||t[41]!==C?(ke=C(`chat.statusRow.summary.activeLeft`,{active:le.active,left:le.left}),t[39]=le.active,t[40]=le.left,t[41]=C,t[42]=ke):ke=t[42];let Ae=ke,je;t[43]!==V||t[44]!==ue||t[45]!==L||t[46]!==w||t[47]!==re||t[48]!==C||t[49]!==Ae||t[50]!==Oe?(je=ue?(0,$.jsxs)(`button`,{type:`button`,onClick:Oe,className:Y(Us,`shrink-0`),"aria-label":Ae,title:Ae,children:[(0,$.jsx)(X,{name:`list-check-3`,className:Ks}),!L&&V?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,nc),children:V.content}):(0,$.jsx)(`span`,{className:`text-xs leading-4 md:text-[0.8125rem] md:leading-5`,children:C(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:Vs,"aria-hidden":`true`,children:[re.completed,`/`,re.total]}),w?(0,$.jsx)(X,{name:`arrow-up-s`,className:Ks}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Ks})]}):null,t[43]=V,t[44]=ue,t[45]=L,t[46]=w,t[47]=re,t[48]=C,t[49]=Ae,t[50]=Oe,t[51]=je):je=t[51];let Me=je;if(!ye)return null;let Ne=!_e&&`chat-column`,Pe;t[52]===Ne?Pe=t[53]:(Pe=Y(`mb-1`,Ne),t[52]=Ne,t[53]=Pe);let Fe=_e&&`px-3`,Ie;t[54]===Fe?Ie=t[55]:(Ie=Y(`flex items-center justify-between py-0.5 gap-2 h-[1.2rem]`,Fe),t[54]=Fe,t[55]=Ie);let Le=!_e&&`overflow-x-hidden`,Re;t[56]===Le?Re=t[57]:(Re=Y(`flex-1 flex items-center min-w-0 gap-2`,Le),t[56]=Le,t[57]=Re);let ze;t[58]!==g||t[59]!==O||t[60]!==de||t[61]!==i||t[62]!==F||t[63]!==a||t[64]!==v||t[65]!==_||t[66]!==l||t[67]!==ve||t[68]!==f||t[69]!==x||t[70]!==y||t[71]!==C||t[72]!==u?(ze=de?(0,$.jsx)(`div`,{className:`flex min-w-0 items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":C(`chat.statusRow.abortPrompt`),children:(0,$.jsxs)(`span`,{className:Y(`flex min-w-0 items-center typography-ui-label`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`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:C(`chat.statusRow.abortPrompt`)})]})}):x&&f?(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`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`close-circle`,className:`size-3.5`,"aria-hidden":`true`})}),C(`chat.statusRow.aborted`)]})}):x&&ve?(0,$.jsx)(Km,{isWorking:v,isMobile:F,statusText:y,isGenericStatus:i,isWaitingForPermission:a,retryInfo:l,turnStartedAt:u,agentName:g},O??`no-session`):_||null,t[58]=g,t[59]=O,t[60]=de,t[61]=i,t[62]=F,t[63]=a,t[64]=v,t[65]=_,t[66]=l,t[67]=ve,t[68]=f,t[69]=x,t[70]=y,t[71]=C,t[72]=u,t[73]=ze):ze=t[73];let Be;t[74]!==Re||t[75]!==ze?(Be=(0,$.jsx)(`div`,{className:Re,children:ze}),t[74]=Re,t[75]=ze,t[76]=Be):Be=t[76];let Ve=!_e&&`-mr-3`,He;t[77]===Ve?He=t[78]:(He=Y(`relative flex items-center gap-2 flex-shrink-0`,Ve),t[77]=Ve,t[78]=He);let Ue;t[79]!==U||t[80]!==ue||t[81]!==w||t[82]!==re||t[83]!==C||t[84]!==z?(Ue=w&&ue&&(0,$.jsxs)(`div`,{style:Ws,className:Y(Xs,`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:C(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,children:[re.completed,`/`,re.total]})]}),(0,$.jsx)(`ul`,{ref:xe,className:lc,children:z.map((e,t)=>(0,$.jsx)(dc,{todo:e,isActive:e===U,activeRef:e===U?Se:void 0},e.id??`todo-${t}`))})]}),t[79]=U,t[80]=ue,t[81]=w,t[82]=re,t[83]=C,t[84]=z,t[85]=Ue):Ue=t[85];let We;t[86]!==He||t[87]!==Ue||t[88]!==Me?(We=(0,$.jsxs)(`div`,{className:He,ref:be,children:[Me,Ue]}),t[86]=He,t[87]=Ue,t[88]=Me,t[89]=We):We=t[89];let Ge;t[90]!==Ie||t[91]!==Be||t[92]!==We?(Ge=(0,$.jsxs)(`div`,{className:Ie,children:[Be,We]}),t[90]=Ie,t[91]=Be,t[92]=We,t[93]=Ge):Ge=t[93];let Ke;return t[94]!==Pe||t[95]!==Ge?(Ke=(0,$.jsx)(`div`,{className:Pe,style:th,children:Ge}),t[94]=Pe,t[95]=Ge,t[96]=Ke):Ke=t[96],Ke};function ih(e){return e.currentSessionId}function ah(e){return e.isMobile}function oh(e){return e.status!==`cancelled`}function sh(e){return e.status===`in_progress`}function ch(e){return e.status===`pending`}function lh(e){return e.status===`in_progress`}function uh(e){return e.status!==`cancelled`}function dh(e){return e.status===`completed`}function fh(e){return e.status===`in_progress`}function ph(e){return e.status===`in_progress`||e.status===`pending`}function mh(e){return!e}var hh=Z.createContext(null),gh=e=>{let t=(0,Q.c)(3),{actions:n,children:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(hh.Provider,{value:n,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},_h=()=>Z.useContext(hh),vh=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),yh=e=>`insertions`in e,bh=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},xh=e=>{let t=0,n=0;for(let r of e.split(`
6521
- `))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},Sh=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!vh.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:bh(i.additions)??void 0,deletions:bh(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:bh(e.additions)??void 0,deletions:bh(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:bh(i.additions)??void 0,deletions:bh(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=xh(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},Ch=(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:vo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},wh=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},Th=(e,t)=>_o(e,t),Eh=(e,t)=>{let n=yh(e)&&e.relativePath?e.relativePath:Th(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},Dh=e=>yh(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},Oh=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=st(),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:Hs,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:qs,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:uc,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}=Eh(e,r),s=Dh(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`,Js),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(ku,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 flex items-baseline overflow-hidden`,title:e.path,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-foreground`,children:n})]})]}):(0,$.jsx)(`span`,{className:`truncate text-foreground`,children:n})}),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:lc,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},kh=`${Xs} origin-[var(--transform-origin)]`,Ah=Ws,jh=Z.memo(()=>{let e=(0,Q.c)(60),{t}=st(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=is()??null,o=Z.useContext(Oo),c=Bs(a),l;e[0]===a?l=e[1]:(l=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=l);let u=ws(l),d=_h(),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||c!==!0||!u||u.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]!==u.diffStats||e[8]!==u.files?(t=Ch(u.files,u.diffStats,a),e[6]=a,e[7]=u.diffStats,e[8]=u.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||c!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!yh(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=s.getState(),c=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,c);return}i.navigateToDiff(e.relativePath,c),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,D;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(Us,`max-w-full text-left`),D=()=>r(Mh),e[25]=E,e[26]=D):(E=e[25],D=e[26]);let O,k;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(X,{name:`file-edit`,className:Ks}),O=Y(nc,`shrink-0`),e[27]=O,e[28]=k):(O=e[27],k=e[28]);let A;e[29]===T?A=e[30]:(A=(0,$.jsx)(`span`,{className:O,children:T}),e[29]=T,e[30]=A);let j;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(j=Y(`status-row__changed-label`,nc),e[31]=j):j=e[31];let M;e[32]===t?M=e[33]:(M=t(`chat.pendingChanges.changedInWorkspace`),e[32]=t,e[33]=M);let N;e[34]===M?N=e[35]:(N=(0,$.jsx)(`span`,{className:j,children:M}),e[34]=M,e[35]=N);let P;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(P=Y(Vs,`items-baseline gap-0.5`),e[36]=P):P=e[36];let F;e[37]===y?F=e[38]:(F=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,y]}):null,e[37]=y,e[38]=F);let I;e[39]===b?I=e[40]:(I=b>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,b]}):null,e[39]=b,e[40]=I);let L;e[41]!==F||e[42]!==I?(L=(0,$.jsxs)(`span`,{className:P,children:[F,I]}),e[41]=F,e[42]=I,e[43]=L):L=e[43];let R;e[44]===n?R=e[45]:(R=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:Ks}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Ks}),e[44]=n,e[45]=R);let z;e[46]!==n||e[47]!==A||e[48]!==N||e[49]!==L||e[50]!==R?(z=(0,$.jsxs)(`button`,{type:`button`,className:E,onClick:D,"aria-expanded":n,children:[k,A,N,L,R]}),e[46]=n,e[47]=A,e[48]=N,e[49]=L,e[50]=R,e[51]=z):z=e[51];let B;e[52]!==a||e[53]!==h||e[54]!==S||e[55]!==n?(B=n&&(0,$.jsx)(`div`,{style:Ah,className:Y(kh,`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)(Oh,{files:h,currentDirectory:a,onOpenFile:S})}),e[52]=a,e[53]=h,e[54]=S,e[55]=n,e[56]=B):B=e[56];let V;return e[57]!==z||e[58]!==B?(V=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[z,B]}),e[57]=z,e[58]=B,e[59]=V):V=e[59],V});jh.displayName=`PendingChangesBar`;function Mh(e){return!e}var Nh=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=st(),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 oc-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`oc-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`&&`oc-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)(la,{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}),Ph=Z.createContext(`default`),Fh=()=>Z.useContext(Ph),Ih=500,Lh=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=Ci(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=Ep(d),h;t[5]===d?h=t[6]:(h=$i(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()},Ih))},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`,Mp,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)(Tp,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,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:Rh,onMouseDown:zh,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 Rh(e){return e.preventDefault()}function zh(e){return e.preventDefault()}var Bh=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}=st(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=ir(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()?on(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)(Ea,{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:Vh,onPointerDownCapture:Hh,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 Vh(e){return e.preventDefault()}function Hh(e){e.preventDefault()}var Uh={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Wh=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function Gh(e,t){let n=(0,Q.c)(6),r=Er(e??``,t),i=ei(e??``,t),a=Di(e??``,t),o=gi(e??``,t),s=ji(e??``,t),c=Fi(t),l;bb0:{if(!e){l=Uh;break bb0}if(o.length>0||s.length>0){l=Uh;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=Wh({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=Uh;break bb0}if(!y){l=Uh;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 Kh=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function qh(e){let t=(0,Q.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`path`,{d:`M200,40H56A16,16,0,0,0,40,56V200a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V56A16,16,0,0,0,200,40Z`}),t[0]=n):n=t[0];let r;return t[1]===e?r=t[2]:(r=(0,$.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,viewBox:`0 0 256 256`,...e,children:n}),t[1]=e,t[2]=r),r}var Jh=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Yh=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Xh=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Zh=(e,t)=>e.id===t.id&&e.directory===t.directory,Qh=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,$h=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Xh(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Zh(e.parentTarget,i)&&Qh(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},eg=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`}},tg=`data-mobile-overlay-active`,ng=e=>Array.from(e).some(e=>e.getAttribute(tg)!==`false`),rg=`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(`.`),ig=`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 ag(){return`${rg[Math.floor(Math.random()*rg.length)]}-${ig[Math.floor(Math.random()*ig.length)]}`}function og(e){let t=ag();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var sg=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,cg=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),lg=(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))},ug=async(e,t)=>{await Qi(e)&&await fi(t)},dg=e=>{let t=sg(e),n=Mt.getState().projects;if(n.length===0)return null;let r=Mt.getState().getActiveProject();if(r?.path){let e=sg(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=sg(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>sg(t.path).length-sg(e.path).length)[0];return i?{id:i.id,path:i.path}:null},fg=!1,pg=async(e,t)=>{try{let n=Mt.getState().projects.find(e=>e.id===t.id)??Mt.getState().projects.find(e=>sg(e.path)===sg(t.path)),r=hr(t.path);await mi.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=mi.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),lg(e,cg(mi.getState()),Vt.getState())}catch{}},mg=async(e,t,n)=>{let r=J.getState(),i=mi.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await pg(e,n),Ee.getState().setDirectory(t.path,{showOverlay:!1})},hg=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,gg=async e=>{if(fg)return null;let t=Mt.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return wr.error(`No active project`,{description:`Please select a project first.`}),null;let r=dg(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return wr.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await da(r.path)}catch{}if(!i)return wr.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;fg=!0;try{let t=Oi(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?hg(n):og(),a=n?`existing`:`new`,o=J.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 ua(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(J.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Ee.getState().setDirectory(s.path,{showOverlay:!1}));let c=await Mn(r),l=await Ts(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return yr(t,l.path),J.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Ee.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=J.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(Wr(n,e instanceof Error?e:Error(t)),J.getState().resolvePendingDraftWorktreeTarget(n,null)),J.getState().setDraftBootstrapPendingDirectory(null),wr.error(`Failed to create worktree`,{description:t}),null}finally{fg=!1}};async function _g(){return gg()}async function vg(e){let t=e.branch?.trim();return t?gg({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function yg(e,t,n,r){if(fg)return null;fg=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=dg(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await da(s.path)}catch{}if(!c)return wr.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await Mn(s),u=await ka(s.path);try{let e=await Ts(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 ug(s,e.path);let n=await J.getState().createSession(void 0,e.path);if(!n)throw await ja(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await mg(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 wr.error(`Failed to create worktree`,{description:t}),null}}finally{fg=!1}}var bg=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},xg=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 Sg({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=st(),{github:a}=Do(),o=eo(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=s(e=>e.isMobile),{isTablet:p}=fo(),m=f||p,h=Mt(e=>e.getActiveProject()),g=Ee(e=>e.currentDirectory),_=Z.useMemo(()=>h?.path?.trim()||g?.trim()||null,[h?.path,g]),[v,y]=Z.useState(``),[b,x]=Z.useState(!1),[S,C]=Z.useState(null),w=Z.useRef(0),T=Z.useMemo(()=>bg(v),[v]),E=ys(v,350),D=T?``:E.trim(),O=!!T||v===E,k=e&&O&&!!_&&!!a?.issuesList&&!(l&&c?.connected===!1),A=Ye({queryKey:I.scoped(`github-issues`,_,D),enabled:k,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(_,{page:e,...D?{query:D}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),j=O?A.data?.pages.at(-1)??null:null,M=O?A.data?.pages.flatMap(e=>e.issues??[])??[]:[],N=O&&A.hasNextPage,P=!T&&!O||A.isLoading,F=O&&A.isFetchingNextPage,L=O&&A.error?A.error instanceof Error?A.error.message:String(A.error):null,R=Z.useCallback(()=>A.refetch(),[A]),z=Z.useCallback(async()=>{try{await A.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);wr.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[A,i]);Z.useEffect(()=>{e||(++w.current,y(``),x(!1),C(null))},[e]),Z.useEffect(()=>{++w.current},[e,_]);let B=!l||c?.connected!==!1&&j?.connected!==!1,V=j?.repo?.url??null,H=Z.useCallback(()=>{d(`github`),u(!0)},[u,d]),U=Z.useCallback(()=>{let e=mi.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},[]),ee=Z.useCallback(()=>{let e=mi.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Kn(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),te=Z.useCallback((e,t)=>{let n=mi.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),W=Z.useCallback(async(e,o)=>{let s=++w.current,c=()=>w.current===s;if(n===`select`){if(!_){wr.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){wr.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(S)return;C(e);try{let n=await a.issueGet(_,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){wr.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){wr.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){wr.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){wr.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=xg({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);wr.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&C(null)}return}if(!_){wr.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){wr.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!S){C(e);try{let n=await a.issueGet(_,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){wr.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){wr.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){wr.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){wr.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(b){let e=`issue-${r.number}-${ag()}`,t=await yg(_,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 Wn(u,_,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??_}})();if(!c())return;ui(d,u).catch(()=>void 0);try{J.getState().initializeNewOpenChamberSession(d,mi.getState().agents)}catch{}t(!1);let f=mi.getState(),p=Vt.getState().lastUsedProvider,m=ee(),h=m?.providerID||f.currentProviderId||p?.providerID,g=m?.modelID||f.currentModelId||p?.modelID,v=U()||f.currentAgentName||void 0;if(!h||!g){wr.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let y=te(h,g),x=await kn(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await kn(`github.issue.review.instructions`);if(!c())return;let C=xg({repo:n.repo,issue:r,comments:l});J.getState().sendMessage(x,h,g,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],y,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);wr.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),wr.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);wr.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&C(null)}}},[b,a,n,t,r,_,U,ee,te,S,i]),G=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),ne=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),re=(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)(Fa,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:v,onChange:e=>{y(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(f?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[_?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`)}),P?(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,B===!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)(la,{variant:`outline`,size:`sm`,onClick:H,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,L?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:L}):null,T&&_&&a&&B?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,S===T&&`bg-interactive-selection/30`),onClick:()=>void W(T),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:T})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:S===T?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,M.length===0&&!P&&!L&&B&&a&&_?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:E.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,M.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`,S===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:S===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`,m?`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}`)),N&&B&&_&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void z(),disabled:F||!!S,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(F||!!S)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:F?(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":b,onClick:()=>x(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),x(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),x(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:b?(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:[V?(0,$.jsx)(la,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:V,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(la,{variant:`outline`,size:`sm`,onClick:R,disabled:P||!!S,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return f?(0,$.jsx)(Sp,{open:e,title:G,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:G}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:ne})]}),children:re}):(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(na,{className:`flex-shrink-0`,children:[(0,$.jsxs)(aa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),G]}),(0,$.jsx)(oa,{children:ne})]}),re]})})}var Cg=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},wg=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function Tg({open:e,onOpenChange:t,onSelect:n}){let{t:r}=st(),{github:i}=Do(),a=eo(),o=a.data??null,c=a.isFetched,l=s(e=>e.setSettingsDialogOpen),u=s(e=>e.setSettingsPage),d=s(e=>e.isMobile),{isTablet:f}=fo(),p=d||f,m=Mt(e=>e.getActiveProject())?.path??null,[h,g]=Z.useState(``),[_,v]=Z.useState(!1),[y,b]=Z.useState(null),x=Z.useRef(0),S=Z.useMemo(()=>Cg(h),[h]),C=ys(h,350),w=S?``:C.trim(),T=!!S||h===C,E=e&&T&&!!m&&!!i?.prsList&&!(c&&o?.connected===!1),D=Ye({queryKey:I.scoped(`github-prs`,m,w),enabled:E,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(m,{page:e,...w?{query:w}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),O=T?D.data?.pages.at(-1)??null:null,k=T?D.data?.pages.flatMap(e=>e.prs??[])??[]:[],A=T&&D.hasNextPage,j=!S&&!T||D.isLoading,M=T&&D.isFetchingNextPage,N=T&&D.error?D.error instanceof Error?D.error.message:String(D.error):null,P=K(async()=>{try{await D.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);wr.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++x.current,g(``),v(!1),b(null))},[e]),Z.useEffect(()=>{++x.current},[e,m]);let F=!c||o?.connected!==!1&&O?.connected!==!1,L=K(()=>{u(`github`),l(!0)}),R=K(async(e,a)=>{if(!m){wr.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){wr.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(y)return;let o=++x.current,s=()=>x.current===o;b(e);try{let o=await i.prContext(m,e,{includeDiff:_,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){wr.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){wr.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){wr.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await kn(`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:_,instructionsText:e,contextText:wg(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);wr.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&b(null)}}),z=r(`session.githubPrPicker.title`),B=r(`session.githubPrPicker.description`),V=(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)(Fa,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:h,onChange:e=>{g(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":_,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ha,{checked:_,onChange:e=>v(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(d?`min-h-0`:`flex-1 overflow-y-auto`),children:[m?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`)}),j?(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,F===!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)(la,{variant:`outline`,size:`sm`,onClick:L,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,N?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:N}):null,S&&m&&i&&F?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,y===S&&`bg-interactive-selection/30`),onClick:()=>void R(S),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:S})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:y===S?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,k.length===0&&!j&&!N&&F&&i&&m?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:C.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,k.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`,y===e.number&&`bg-interactive-selection/30`),onClick:()=>void R(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:y===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":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}`)),A&&F&&m&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:M||!!y,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(M||!!y)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:M?(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 d?(0,$.jsx)(Sp,{open:e,title:z,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:z}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:B})]}),children:V}):(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(na,{className:`flex-shrink-0`,children:[(0,$.jsxs)(aa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),z]}),(0,$.jsx)(oa,{children:B})]}),V]})})}function Eg(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)(fc,{"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 Dg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(11),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a,o;n[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=Y(`flex h-8 items-center gap-2 rounded-lg px-3`,`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)]`),o=(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 opacity-50`}),n[3]=a,n[4]=o):(a=n[3],o=n[4]);let s;n[5]===r?s=n[6]:(s=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[5]=r,n[6]=s);let c;return n[7]!==i||n[8]!==t||n[9]!==s?(c=(0,$.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1.5 pb-1`,children:(0,$.jsxs)(`div`,{"data-slot":`command-input-field`,className:a,children:[o,(0,$.jsx)(fc.Input,{ref:t,"data-slot":`command-input`,className:s,...i})]})}),n[7]=i,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});Dg.displayName=`CommandInput`;function Og(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)(fa,{as:fc.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 kg(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)(fc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function Ag(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)(fc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function jg(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)(fc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Mg(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)(fc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Ng=(e,t)=>`${e}:${T(t)}`,Pg=e=>e.type===`skill`||!ce(e.name);function Fg(e){let{t}=st(),n=Z.useMemo(()=>d(),[]),r=s(e=>e.globalDraftStarters),i=Mt(e=>e.activeProjectId),a=Mt(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]),[c,l]=Z.useState([]),u=Z.useMemo(()=>r??le,[r]),f=u.some(Pg)||c.some(Pg),m=Hn({directory:e,enabled:f}),h=Z.useMemo(()=>m.data??[],[m.data]),{refetch:g}=m,_=ti({directory:e,enabled:f}),v=Z.useMemo(()=>_.data??[],[_.data]),{refetch:y}=_;Z.useEffect(()=>{let e=!1;if(!o){l([]);return}return dn(o).then(t=>{e||l(t)}).catch(()=>{e||l([])}),()=>{e=!0}},[o?.id]);let b=Z.useCallback(()=>{g(),y()},[g,y]),x=Z.useMemo(()=>new Set(h.map(e=>e.name)),[h]),S=Z.useMemo(()=>new Set(v.map(e=>e.name)),[v]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=ce(e.name);return n?{id:Ng(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:x.has(e.name)?{id:Ng(r,e),ref:e,group:r,label:w(e.name),icon:oe,submitText:`/${e.name}`}:null}return S.has(e.name)?{id:Ng(r,e),ref:e,group:r,label:w(e.name),icon:P,submitText:`/${e.name}`}:null},[t,x,S,n]),E=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),D=Z.useMemo(()=>c.map(e=>C(e,`project`)).filter(e=>e!==null),[c,C]),O=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(T(t));for(let t of c)e.add(T(t));return e},[u,c]),k=Z.useMemo(()=>{let e=[];for(let r of M)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 h)t.isBuiltIn||t.source===`skill`||ce(t.name)||e.push({type:`command`,name:t.name,label:w(t.name),icon:oe,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of v)e.push({type:`skill`,name:t.name,label:w(t.name),icon:P,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!O.has(`${e.type}:${e.name}`))},[t,h,v,O,n]),A=Z.useCallback(e=>{s.getState().setGlobalDraftStarters(e),ne({draftStarters:e})},[]),j=Z.useCallback(e=>{l(e),o&&Zn(o,e)},[o]),N=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||c.some(e=>p(e,t)))return;j([...c,t])}else{let e=r??le;if(e.some(e=>p(e,t)))return;A([...e,t])}},[o,c,r,j,A]),F=Z.useCallback((e,t)=>{e===`project`?j(c.filter(e=>!p(e,t))):A((r??le).filter(e=>!p(e,t)))},[c,r,j,A]),I=Z.useCallback((e,t,n)=>{let i=e===`project`?c:r??le,a=i.findIndex(n=>Ng(e,n)===t),o=i.findIndex(t=>Ng(e,t)===n);if(a<0||o<0||a===o)return;let s=Ko([...i],a,o);e===`project`?j(s):A(s)},[c,r,j,A]);return{global:E,project:D,pinnable:k,hasProject:!!o,ensureLoaded:b,addStarter:N,removeStarter:F,reorder:I}}var Ig=`__draft-starter-trash__`,Lg=`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`,Rg=`max-h-7`,zg=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],Bg=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=st(),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}=qo(s),m;t[2]===d?m=t[3]:(m=Wo.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},Vg=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(Kg),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)(Bg,{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)(Yo,{items:o,strategy:Go,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},Hg=()=>{let e=(0,Q.c)(13),{t}=st(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:Ig},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=zo(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(Lg,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},Ug=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=st(),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)(Dg,{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)(kg,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=zg.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(Ag,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(Mg,{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)(Og,{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)(Eg,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},Wg=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=st(),[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)(sa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:Lg,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)(na,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(aa,{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)(Ug,{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)(ia,{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)(ca,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},Gg=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=st(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=Fg(is()),{isMobile:f}=fo(),[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=Uo(Io(Vo,b),Io(Ro,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)===Ig){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:Lo.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&&Rg,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)(Vg,{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)(Vg,{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 ee;t[38]!==V||t[39]!==H||t[40]!==U?(ee=(0,$.jsxs)(`div`,{ref:y,className:V,children:[H,U]}),t[38]=V,t[39]=H,t[40]=U,t[41]=ee):ee=t[41];let te;t[42]!==h||t[43]!==I||t[44]!==i?(te=I?(0,$.jsx)(`button`,{type:`button`,onClick:()=>g(qg),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:Lg,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]=te):te=t[45];let W;t[46]!==l||t[47]!==c||t[48]!==p||t[49]!==f||t[50]!==s?(W=f&&p?(0,$.jsx)(Hg,{}):(0,$.jsx)(Wg,{pinnable:s,onOpen:c,onAdd:l}),t[46]=l,t[47]=c,t[48]=p,t[49]=f,t[50]=s,t[51]=W):W=t[51];let G;t[52]!==te||t[53]!==W?(G=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 self-start`,children:[te,W]}),t[52]=te,t[53]=W,t[54]=G):G=t[54];let ne;t[55]!==R||t[56]!==ee||t[57]!==G?(ne=(0,$.jsxs)(`div`,{className:R,children:[ee,G]}),t[55]=R,t[56]=ee,t[57]=G,t[58]=ne):ne=t[58];let re;return t[59]!==F||t[60]!==S||t[61]!==ne?(re=(0,$.jsx)(Ho,{sensors:S,collisionDetection:Bo,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:ne}),t[59]=F,t[60]=S,t[61]=ne,t[62]=re):re=t[62],re};function Kg(e){return e.id}function qg(e){return!e}var Jg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(19),r,i,a,o,s,c;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5],c=n[6]):({children:r,className:i,expanded:s,focusedTone:c,style:o,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s,n[6]=c);let l=s!==void 0&&s,u=c===void 0?`primary`:c,d=l&&`min-h-0 flex-1`,f=u===`info`?`focus-within:ring-[var(--status-info)]`:`focus-within:ring-primary/50`,p;n[7]!==i||n[8]!==d||n[9]!==f?(p=Y(`relative flex flex-col overflow-visible border border-border/80 focus-within:ring-1`,d,f,i),n[7]=i,n[8]=d,n[9]=f,n[10]=p):p=n[10];let m;n[11]===o?m=n[12]:(m={borderRadius:`var(--radius-xl)`,backgroundColor:`var(--surface-subtle)`,...o},n[11]=o,n[12]=m);let h;return n[13]!==r||n[14]!==a||n[15]!==t||n[16]!==p||n[17]!==m?(h=(0,$.jsx)(`div`,{ref:t,className:p,style:m,...a,children:r}),n[13]=r,n[14]=a,n[15]=t,n[16]=p,n[17]=m,n[18]=h):h=n[18],h});Jg.displayName=`ChatComposerSurface`;var Yg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Oa,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});Yg.displayName=`ChatPromptTextarea`;var Xg=e=>{let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=Y(`flex shrink-0 items-center gap-2 bg-transparent px-2.5 py-1.5`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,$.jsx)(`div`,{className:a,"data-chat-input-footer":`true`,...i,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o},Zg=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},Qg=e=>{let t=(0,Q.c)(139),n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P,F,I,L,R,z,B;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],_=t[16],v=t[17],y=t[18],b=t[19],x=t[20],S=t[21],C=t[22],w=t[23],T=t[24],E=t[25],D=t[26],O=t[27],k=t[28],A=t[29],j=t[30],M=t[31],N=t[32],P=t[33],F=t[34],I=t[35],L=t[36],R=t[37],z=t[38],B=t[39]):({value:B,attachments:j,disabled:M,pending:N,placeholder:T,isMobile:P,onChange:x,onSubmit:w,onStop:C,onAddFiles:b,onRemoveAttachment:S,addFilesLabel:n,removeAttachmentLabel:E,sendLabel:O,stopLabel:k,hint:f,leftControls:y,rightControls:D,footerContent:c,inputHeader:m,attachmentContent:r,highlightedContent:d,highlightRef:u,inputRef:g,textareaProps:z,textLayoutClassName:R,inputClassName:p,inputOuterClassName:h,inputStyle:v,footerClassName:s,footerStyle:l,contentClassName:o,inputSectionClassName:_,autoResize:F,disableInputWhilePending:I,children:i,className:a,expanded:L,...A}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=_,t[17]=v,t[18]=y,t[19]=b,t[20]=x,t[21]=S,t[22]=C,t[23]=w,t[24]=T,t[25]=E,t[26]=D,t[27]=O,t[28]=k,t[29]=A,t[30]=j,t[31]=M,t[32]=N,t[33]=P,t[34]=F,t[35]=I,t[36]=L,t[37]=R,t[38]=z,t[39]=B);let V=j===void 0?[]:j,H=M!==void 0&&M,U=N!==void 0&&N,ee=P!==void 0&&P,te=F===void 0||F,W=I===void 0||I,G=L!==void 0&&L,ne=Z.useRef(null),re=Z.useRef(null),ie;t[40]!==te||t[41]!==G||t[42]!==z?.fillContainer?(ie=()=>{if(!te||G||z?.fillContainer)return;let e=ne.current;if(!e)return;e.style.height=`auto`;let t=Number.parseFloat(window.getComputedStyle(e).maxHeight),n=Number.isFinite(t)?Math.min(e.scrollHeight,t):e.scrollHeight;e.style.height=`${n}px`,e.style.overflowY=Number.isFinite(t)&&e.scrollHeight>t?`auto`:`hidden`},t[40]=te,t[41]=G,t[42]=z?.fillContainer,t[43]=ie):ie=t[43];let ae=z?.fillContainer,oe;t[44]!==te||t[45]!==G||t[46]!==ae||t[47]!==B?(oe=[te,G,ae,B],t[44]=te,t[45]=G,t[46]=ae,t[47]=B,t[48]=oe):oe=t[48],Z.useLayoutEffect(ie,oe);let se;t[49]!==W||t[50]!==H||t[51]!==w||t[52]!==U||t[53]!==z?(se=e=>{z?.onKeyDown?.(e),!(e.defaultPrevented||Kh(e))&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),!H&&(!U||!W)&&w())},t[49]=W,t[50]=H,t[51]=w,t[52]=U,t[53]=z,t[54]=se):se=t[54];let ce=se,le;t[55]===b?le=t[56]:(le=e=>{b?.(e.target.files),e.target.value=``},t[55]=b,t[56]=le);let ue=le,de=B.trim().length>0||V.length>0,fe=V.filter($g),pe;t[57]!==n||t[58]!==H||t[59]!==ue||t[60]!==b||t[61]!==U?(pe=b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:re,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:ue}),(0,$.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-foreground outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,onClick:()=>re.current?.click(),disabled:H||U,"aria-label":n,children:(0,$.jsx)(X,{name:`attachment-2`,className:`size-[18px]`})})]}):null,t[57]=n,t[58]=H,t[59]=ue,t[60]=b,t[61]=U,t[62]=pe):pe=t[62];let me=pe,he;t[63]!==H||t[64]!==de||t[65]!==C||t[66]!==U||t[67]!==O||t[68]!==k?(he=U&&C?(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,className:`flex size-8 shrink-0 items-center justify-center !text-black outline-none hover:!text-black dark:!text-white dark:hover:!text-white`,onClick:C,"aria-label":k,children:(0,$.jsx)(qh,{className:`size-5`})}):(0,$.jsx)(`button`,{type:`submit`,"data-composer-send":`true`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-primary outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`,disabled:H||U||!de,"aria-label":O,children:(0,$.jsx)(X,{name:U?`loader-4`:`send-plane-2`,className:Y(`size-4`,U&&`animate-spin`)})}),t[63]=H,t[64]=de,t[65]=C,t[66]=U,t[67]=O,t[68]=k,t[69]=he):he=t[69];let ge=he,_e=Jg,ve=G&&`flex-1`,ye;t[70]!==o||t[71]!==ve?(ye=Y(`relative flex min-h-0 flex-col`,ve,o),t[70]=o,t[71]=ve,t[72]=ye):ye=t[72];let be=G&&`flex min-h-0 flex-1 flex-col`,xe;t[73]!==_||t[74]!==be?(xe=Y(`overflow-hidden`,be,_),t[73]=_,t[74]=be,t[75]=xe):xe=t[75];let Se=fe.length>0?(0,$.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-3 pt-3`,"data-chat-prompt-attachments":`true`,children:fe.map(e=>(0,$.jsxs)(`div`,{className:`group relative shrink-0`,children:[(0,$.jsx)(`img`,{src:e.url,alt:e.name,className:`size-16 rounded-lg border border-border object-cover`}),S?(0,$.jsx)(`button`,{type:`button`,className:`absolute -right-1 -top-1 flex size-6 items-center justify-center rounded-full border border-border bg-[var(--surface-elevated)] shadow-sm hover:bg-[var(--interactive-hover)]`,onClick:()=>S(e.id),"aria-label":E,children:(0,$.jsx)(X,{name:`close`,className:`size-3`})}):null]},e.id))}):null,Ce=G&&`flex min-h-0 flex-1 flex-col`,we;t[76]===Ce?we=t[77]:(we=Y(`relative overflow-hidden`,Ce),t[76]=Ce,t[77]=we);let Te;t[78]!==u||t[79]!==d||t[80]!==p||t[81]!==R?(Te=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[78]=u,t[79]=d,t[80]=p,t[81]=R,t[82]=Te):Te=t[82];let Ee;t[83]===g?Ee=t[84]:(Ee=e=>{ne.current=e,Zg(g,e)},t[83]=g,t[84]=Ee);let De;t[85]===x?De=t[86]:(De=e=>x(e.target.value,e),t[85]=x,t[86]=De);let Oe=H||U&&W,ke=ee?`send`:z?.enterKeyHint,Ae=G&&`min-h-0 flex-1`,je;t[87]!==h||t[88]!==Ae?(je=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,Ae,h),t[87]=h,t[88]=Ae,t[89]=je):je=t[89];let Me=d&&`text-transparent caret-[var(--surface-foreground)]`,Ne;t[90]!==p||t[91]!==Me||t[92]!==R?(Ne=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,Me),t[90]=p,t[91]=Me,t[92]=R,t[93]=Ne):Ne=t[93];let Pe=z?.rows??1,Fe;t[94]!==ce||t[95]!==v||t[96]!==T||t[97]!==Ee||t[98]!==De||t[99]!==Oe||t[100]!==ke||t[101]!==je||t[102]!==Ne||t[103]!==Pe||t[104]!==z||t[105]!==B?(Fe=(0,$.jsx)(Yg,{...z,simple:!0,ref:Ee,"data-chat-input":`true`,value:B,onChange:De,onKeyDown:ce,disabled:Oe,placeholder:T,enterKeyHint:ke,outerClassName:je,className:Ne,style:v,rows:Pe}),t[94]=ce,t[95]=v,t[96]=T,t[97]=Ee,t[98]=De,t[99]=Oe,t[100]=ke,t[101]=je,t[102]=Ne,t[103]=Pe,t[104]=z,t[105]=B,t[106]=Fe):Fe=t[106];let Ie;t[107]!==we||t[108]!==Te||t[109]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:we,"data-composer-input-shell":`true`,children:[Te,Fe]}),t[107]=we,t[108]=Te,t[109]=Fe,t[110]=Ie):Ie=t[110];let Le;t[111]!==r||t[112]!==m||t[113]!==xe||t[114]!==Se||t[115]!==Ie?(Le=(0,$.jsxs)(`div`,{className:xe,children:[m,r,Se,Ie]}),t[111]=r,t[112]=m,t[113]=xe,t[114]=Se,t[115]=Ie,t[116]=Le):Le=t[116];let Re;t[117]!==me||t[118]!==ge||t[119]!==c||t[120]!==f||t[121]!==y||t[122]!==D?(Re=c??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:y??me}),f?(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,children:f}):(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:D??ge})]}),t[117]=me,t[118]=ge,t[119]=c,t[120]=f,t[121]=y,t[122]=D,t[123]=Re):Re=t[123];let ze;t[124]!==s||t[125]!==l||t[126]!==Re?(ze=(0,$.jsx)(Xg,{className:s,style:l,children:Re}),t[124]=s,t[125]=l,t[126]=Re,t[127]=ze):ze=t[127];let Be;t[128]!==ye||t[129]!==Le||t[130]!==ze?(Be=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ye,children:[Le,ze]}),t[128]=ye,t[129]=Le,t[130]=ze,t[131]=Be):Be=t[131];let Ve;return t[132]!==_e||t[133]!==i||t[134]!==a||t[135]!==G||t[136]!==A||t[137]!==Be?(Ve=(0,$.jsxs)(_e,{className:a,expanded:G,...A,children:[i,Be]}),t[132]=_e,t[133]=i,t[134]=a,t[135]=G,t[136]=A,t[137]=Be,t[138]=Ve):Ve=t[138],Ve};function $g(e){return e.mime.startsWith(`image/`)}var e_=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),t_=({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}=st(),[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||_),ee=Z.useMemo(()=>e_(N),[N]),te=Z.useMemo(()=>{let e=D.trim();return e?Or(t,e,e=>e).map(e=>e.item):t},[D,t]),W=Z.useMemo(()=>{let e=D.trim();return e?Or(n,e,e=>e).map(e=>e.item):n},[D,n]),G=Z.useMemo(()=>{let e=D.trim();return e?Or(m,e,e=>e.label).map(e=>e.item):m},[D,m]),ne=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||Or([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),re=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},ie=e=>{g?.(e),B(!1),O(``)},ae=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},oe=async()=>{if(!(!ee||F)){if(H){M(!0);return}I(!0);try{await a(ee,o[0]),P(``),A(!1),B(!1)}finally{I(!1)}}},se=async e=>{if(!(!ee||F)){I(!0);try{await a(ee,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},ce=()=>{M(!1)},le=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let ue=u||e||w(`gitView.branch.detachedHead`),de=d??(c?`end`:`start`),fe=v??w(`chat.chatInput.worktrees`),pe=y??w(`chat.chatInput.worktreeNew`),me=b??w(`chat.chatInput.projectRoot`),he=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":ue,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(la,{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":ue,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:ue}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),ge=(0,$.jsx)(qa,{asChild:!0,disabled:s,children:l??he}),_e=(0,$.jsxs)(Eg,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(Dg,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(Og,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(kg,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(Ag,{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:ce,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:ee}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>se(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(),oe()):e.key===`Escape`&&(e.preventDefault(),le())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:oe,disabled:!ee||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:le,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)(Mg,{onSelect:ae,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(jg,{}),(0,$.jsxs)(Ag,{heading:w(`gitView.branch.localBranches`),children:[te.map(t=>(0,$.jsxs)(Mg,{onSelect:()=>re(t),children:[(0,$.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:t}),(r?.[t]?.ahead||r?.[t]?.behind)&&(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[r[t].ahead||0,` ahead ·`,` `,r[t].behind||0,` behind`]})]}),e===t&&(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)})]},`local-${t}`)),te.length===0&&(0,$.jsx)(Mg,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(jg,{}),(0,$.jsxs)(Ag,{heading:w(`gitView.branch.remoteBranches`),children:[W.map(e=>(0,$.jsx)(Mg,{onSelect:()=>re(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),W.length===0&&(0,$.jsx)(Mg,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noRemoteBranches`)})})]}),U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(jg,{}),(0,$.jsxs)(Ag,{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:fe}),_?(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:pe}):null]}),p&&ne?(0,$.jsxs)(Mg,{onSelect:()=>ie(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:me}),(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,G.map(e=>(0,$.jsxs)(Mg,{onSelect:()=>ie(e.value),children:[(0,$.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),h===e.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`))]})]}):null]})]});if(C===`mobile-sheet`){let e=Z.cloneElement(l??he,{onClick:()=>B(!0),"data-popup-open":z?``:void 0});return(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(Qa,{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:_e})]})}return(0,$.jsxs)(Ua,{open:z,onOpenChange:B,children:[f||l?ge:(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:ge}),(0,$.jsx)(La,{sideOffset:8,children:c?ue:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(Ka,{align:de,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:_e})]})};function n_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=Or(t,i,e=>e),o=Or(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 r_(e,t){return`${e}\0${t}`}function i_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=st(),i=s(e=>e.isMobile),{github:a}=Do(),o=eo(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=Mt(e=>e.getActiveProject()),p=f?.id??null,m=f?.path??null,h=Z.useMemo(()=>m&&p?{id:p,path:m}:null,[p,m]),[g,_]=Z.useState(`issues`),[v,y]=Z.useState(``),[b,x]=Z.useState([]),[S,C]=Z.useState([]),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(null),[A,j]=Z.useState(null),[M,N]=Z.useState(null),[P,F]=Z.useState(!1),[I,L]=Z.useState(new Map),[R,z]=Z.useState(1),[B,V]=Z.useState(!1),H=Z.useRef(0),U=ys(v,350),ee=K(async e=>{if(!(!m||!a)&&!(l&&c?.connected===!1)){T(!0),k(null),z(1),V(!1);try{if(g===`issues`&&a.issuesList){let t=await a.issuesList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(t.issues??[]),z(t.page??1),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=await a.prsList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(t.prs??[]),z(t.page??1),V(!!t.hasMore))}}catch(e){k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{T(!1)}}});Z.useEffect(()=>{if(!e||!m||l&&c?.connected===!1||!a)return;if(!U.trim()){ee();return}let t=new AbortController;T(!0),k(null),z(1),V(!1);let n=g===`issues`&&a.issuesList?a.issuesList(m,{page:1,query:U.trim()}):g===`prs`&&a.prsList?a.prsList(m,{page:1,query:U.trim()}):null;if(!n){T(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(e.issues??[]),z(e.page??1),V(!!e.hasMore)):`prs`in e&&(e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(e.prs??[]),z(e.page??1),V(!!e.hasMore))))}).catch(e=>{t.signal.aborted||k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||T(!1)}),()=>t.abort()},[e,m,a,l,c,g,U,ee,r]);let te=K(async()=>{if(!(!m||!a)&&!(w||E)&&B){D(!0);try{let e=R+1;if(g===`issues`&&a.issuesList){let t=U.trim()?await a.issuesList(m,{page:e,query:U.trim()}):await a.issuesList(m,{page:e});t.connected!==!1&&(x(e=>[...e,...t.issues??[]]),z(t.page??e),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=U.trim()?await a.prsList(m,{page:e,query:U.trim()}):await a.prsList(m,{page:e});t.connected!==!1&&(C(e=>[...e,...t.prs??[]]),z(t.page??e),V(!!t.hasMore))}}catch{}finally{D(!1)}}});Z.useEffect(()=>{if(!e){_(`issues`),y(``),x([]),C([]),j(null),N(null),F(!1),k(null),L(new Map),z(1),V(!1);return}ee()},[e,ee]),Z.useEffect(()=>{H.current+=1,L(new Map)},[m,h]);let W=K(async e=>{if(!h||!e)return;let t=r_(h.path,e);if(I.has(t))return;let n=H.current;try{let i=await xa(h,{mode:`new`,branchName:e,worktreeName:e});if(n!==H.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);L(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!==H.current)return;L(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||g!==`prs`||S.forEach(e=>{e.head&&W(e.head)})},[e,g,S,m,h,W]);let G=l&&c?.connected===!0,ne=()=>{d(`github`),u(!0)},re=e=>{j(e),N(null)},ie=e=>{N(e),j(null)},ae=()=>{A?n({type:`issue`,item:A}):M&&n({type:`pr`,item:M,includeDiff:P}),t(!1)},oe=()=>{j(null),N(null),F(!1)},se=A||(M?.head&&m?I.get(r_(m,M.head))?.isValid!==!1:!1),ce=e=>!e.head||(m?I.get(r_(m,e.head)):void 0)?.isValid===!1,le=(0,$.jsx)($.Fragment,{children:G?(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)(Fa,{value:v,onChange:e=>y(e.target.value),placeholder:r(g===`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:[w&&(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`})}),O&&(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:O})]})}),!w&&!O&&g===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[b.length>0?b.map(e=>(0,$.jsx)(`button`,{onClick:()=>re(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,A?.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`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(la,{variant:`ghost`,size:`sm`,onClick:()=>void te(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(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`})})]}),!w&&!O&&g===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[S.length>0?S.map(e=>{let t=ce(e),n=e.head&&m?I.get(r_(m,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&ie(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,M?.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`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(la,{variant:`ghost`,size:`sm`,onClick:()=>void te(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(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)(la,{onClick:ne,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),ue=(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&&(A||M)&&(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:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick:oe,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`})})]}),g===`prs`&&M&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(ha,{checked:P,onChange:e=>F(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)(la,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(la,{size:`sm`,onClick:ae,disabled:!se,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(Sp,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:G?ue: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)(pc,{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:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})}),(A||M)&&(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:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick:oe,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:le}):(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(na,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(aa,{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)(pc,{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:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),le,(0,$.jsx)(ra,{className:`mt-1`,children:ue})]})})})}var a_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},o_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),s_=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),c_=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,l_=(e,t,n)=>{let r=o_(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-${c_(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}`}},u_=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},d_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function f_({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=st(),{github:a,git:o}=Do(),c=s(e=>e.isMobile),l=Z.useId(),u=eo(),d=u.data??null,f=u.isFetched,p=Mt(e=>a_(e.projects,e.activeProjectId,r)),m=p?.path??null,h=Z.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[g,_]=Z.useState(`new-branch`),[v,y]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[b,x]=Z.useState({selectedBranch:``,worktreeName:``}),S=Ps(m),C=js(m),w=ws(e=>e.fetchBranches),T=Z.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),E=Z.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),D=J(e=>e.availableWorktreesByProject),O=Z.useMemo(()=>{if(!m)return new Set;let e=D.get(m)??[];return new Set(e.map(e=>e.name))},[D,m]),k=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=ag();if(!O.has(e))return e}return`${ag()}-${Date.now().toString(36).slice(-4)}`},[O]),[A,j]=Z.useState(!1),[M,N]=Z.useState(!1),[P,F]=Z.useState(!1),[I,L]=Z.useState(!1),[R,z]=Z.useState(!1),[B,V]=Z.useState(``),[H,U]=Z.useState(``),ee=Z.useRef(null),te=Z.useRef(null),W=Z.useRef(null),G=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},[]),ie=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),ae=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;ie(t)},[ie]),oe=Z.useCallback(e=>{let t=re(e.current);ie(t)},[re,ie]),se=Z.useMemo(()=>n_({localBranches:T,remoteBranches:E,query:B}),[T,E,B]),ce=Z.useMemo(()=>n_({localBranches:T,remoteBranches:E,query:H}),[T,E,H]),le=B.trim().length>0,ue=H.trim().length>0,de=se.matching.length>0,fe=ce.matching.length>0,pe=!!(m&&o),me=Z.useCallback(()=>{!m||!o||w(m,o)},[m,o,w]);Z.useEffect(()=>{!e||!m||!o||S?.all||w(m,o)},[e,m,o,S?.all,w]),Z.useEffect(()=>{!M&&!I&&V(``)},[M,I]),Z.useEffect(()=>{!P&&!R&&U(``)},[P,R]),Z.useEffect(()=>{M&&ae(ee),I&&oe(W)},[M,I,B,ae,oe]),Z.useEffect(()=>{P&&ae(te),R&&oe(G)},[P,R,H,ae,oe]);let[he,ge]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[_e,ve]=Z.useState(!1),[ye,be]=Z.useState(null),xe=Z.useCallback(()=>{let e=mi.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},[]),Se=Z.useCallback(()=>{let e=mi.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Kn(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),Ce=Z.useCallback((e,t)=>{let n=mi.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),we=Z.useCallback(async e=>{if(!m||!a)return;let t=mi.getState(),n=Vt.getState().lastUsedProvider,r=Se(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=xe()||t.currentAgentName||void 0;if(!o||!s){wr.error(i(`session.newWorktree.error.noModelSelected`));return}let l=Ce(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(m,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(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await kn(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await kn(`github.issue.review.instructions`),d=u_({repo:t.repo,issue:t.issue,comments:n.comments??[]});await J.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),wr.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(m,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 kn(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await kn(`github.pr.review.instructions`),u=d_(t);await J.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),wr.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,m,xe,Se,Ce,i]),Te=g===`new-branch`?v:b;Z.useEffect(()=>{if(!e||!S?.all||!m||v.sourceBranch)return;let t=v.sourceBranch,n=!1;return(async()=>{try{let e=await ka(m).catch(()=>null);if(n)return;let r=localStorage.getItem(Cs),{sourceBranch:i,shouldClearSavedSourceBranch:a}=Ns({branches:S.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Cs),n||t)return;i&&y(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,S?.all,m,v.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;_(`new-branch`),x({selectedBranch:``,worktreeName:``}),N(!1),F(!1),L(!1),z(!1),V(``),U(``),ge({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=k();y({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,k]),Z.useEffect(()=>{if(g!==`new-branch`||!v.isSyncingWorktreeName)return;let e=s_(o_(v.branchName));y(t=>({...t,worktreeName:e}))},[g,v.branchName,v.isSyncingWorktreeName]);let Ee=Z.useCallback(async()=>{if(!h||!he.touched||_e)return;ye&&ye.abort();let e=new AbortController;be(e),ge(e=>({...e,isValidating:!0}));try{let t=g===`new-branch`?v.branchName:b.selectedBranch,n=Te.worktreeName,r=o_(t),a=s_(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=g===`new-branch`?v.linkedPr:null,n=t?l_(t,T,E):null,i=await xa(h,{mode:g===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(g===`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||ge(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||ge(e=>({...e,isValidating:!1}))}},[h,g,v.branchName,v.linkedPr,b.selectedBranch,Te.worktreeName,T,E,he.touched,ye,_e,i]),De=g===`new-branch`?v.branchName:b.selectedBranch;Z.useEffect(()=>{if(!e||!h||!he.touched||_e)return;let t=setTimeout(()=>{Ee()},300);return()=>clearTimeout(t)},[Te.worktreeName,De,e,h,Ee,he.touched,_e]);let Oe=async()=>{if(!h||!m){wr.error(i(`session.newWorktree.error.noActiveProject`));return}ge(e=>({...e,touched:!0}));let e=g===`new-branch`?v.branchName:b.selectedBranch,r=Te.worktreeName,a=o_(e),o=s_(r);if(!a){wr.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){wr.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}ye&&(ye.abort(),be(null)),ge(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),ve(!0);try{let e=g===`new-branch`?v.linkedPr:null,r=g===`new-branch`?v.linkedIssue:null,s=g===`new-branch`?v.linkedPr:null,c=g===`new-branch`&&v.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([Mn(h),As(m)]),f=v.sourceBranch,p=``,_=(()=>{if(e){let t=l_(e,T,E);return p=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 p=g===`new-branch`?f:``,{preferredName:a||o,mode:g===`existing-branch`?`existing`:`new`,branchName:g===`existing-branch`?void 0:a,worktreeName:o,existingBranch:g===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&g===`new-branch`?{startRef:f}:{}}})(),y=await Rs(m,_,{resolvedRootTrackingRemote:d}),x=await Aa(h,y),S=null;if(l){await Qi(h)&&await fi(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Wn(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),ve(!1),ui(a.id,e).catch(()=>void 0);try{J.getState().initializeNewOpenChamberSession(a.id,mi.getState().agents)}catch{}}else t(!1),ve(!1);let C=Is({mode:g,sourceBranch:v.sourceBranch,linkedPr:!!v.linkedPr,selectedBranch:b.selectedBranch});C&&localStorage.setItem(Cs,C),wr.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${p?` ${i(`session.newWorktree.fromSource`,{source:p})}`:``}`})}),S?we({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`);wr.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`);wr.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{ve(!1)}},ke=e=>{_(e),ge(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},Ae=e=>{if(!e){y(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${ag()}`;y(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:s_(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;y(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:s_(t.head),isSyncingWorktreeName:!0}))}},je=f&&d?.connected===!0,Me=(g===`existing-branch`?!!b.selectedBranch&&!!b.worktreeName&&!he.branchError&&!he.worktreeError:!!o_(v.branchName)&&!!v.worktreeName&&!he.branchError&&!he.worktreeError)&&!_e,Ne=()=>{y(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Pe=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,c?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,c?`w-full justify-center order-first`:`mr-auto`),children:he.touched&&(he.branchError||he.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:he.branchError||he.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,c&&`w-full`),children:[(0,$.jsx)(la,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:_e,className:Y(c&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(la,{size:`sm`,onClick:Oe,disabled:!Me||_e,className:Y(`gap-1.5`,c&&`flex-1`),children:[_e&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(_e?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[c?(0,$.jsx)(Qa,{id:`new-worktree-sheet-${l}`,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)(fa,{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)(pc,{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:g,onSelect:e=>ke(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[g===`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)(la,{variant:`outline`,size:`sm`,onClick:()=>L(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:b.selectedBranch?`text-foreground`:`text-muted-foreground`,children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(la,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:me,disabled:!pe||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(Sp,{open:I,title:i(`session.newWorktree.selectBranch`),onClose:()=>L(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:W,children:[(0,$.jsx)(Fa,{value:B,onChange:e=>V(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.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:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:s_(e.label)})),ge(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.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}`))})]}),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:()=>{x(t=>({...t,selectedBranch:e,worktreeName:s_(e)})),ge(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.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))})]}),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:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:s_(e)})),ge(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.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`)}),g===`new-branch`&&je&&(0,$.jsxs)(la,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Fa,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ge(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,he.touched&&he.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.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:v.linkedPr.head})})]}),v.linkedIssue&&!v.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:v.linkedIssue.number,title:v.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`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=s_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===s_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===s_(v.branchName)||!v.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)(Fa,{value:Te.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>ge(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,he.touched&&he.worktreeError&&`border-destructive`)})]}),g===`new-branch`&&!v.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)(la,{variant:`outline`,size:`sm`,onClick:()=>z(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:v.sourceBranch?`text-foreground`:`text-muted-foreground`,children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})}),(0,$.jsx)(Sp,{open:R,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>z(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(Fa,{value:H,onChange:e=>U(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.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:[ue&&fe&&(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:ce.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:e.value})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.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}`))})]}),ue&&!fe&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ce.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(ue?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ce.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:e})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.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))})]}),ce.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(ue?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ce.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.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}`))})]})]})]})})]}),(v.linkedIssue||v.linkedPr)&&g===`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`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.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:Ne,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`})})]}),v.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:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.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:Pe})]})}):(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(na,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(aa,{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)(pc,{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:g,onSelect:e=>ke(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[g===`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)(Ua,{open:M,onOpenChange:N,children:[(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(la,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,b.selectedBranch?`text-foreground`:`text-muted-foreground`),children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ka,{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:ee,children:(0,$.jsxs)(Eg,{shouldFilter:!1,children:[(0,$.jsx)(Dg,{placeholder:i(`session.newWorktree.searchBranches`),value:B,onValueChange:V,onKeyDown:ne}),(0,$.jsx)(Og,{disableHorizontal:!0,children:C?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(kg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[le&&de&&(0,$.jsx)(Ag,{heading:i(`session.newWorktree.matchingBranches`),children:se.matching.map(e=>(0,$.jsx)(Mg,{value:e.value,onSelect:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:s_(e.label)})),ge(e=>({...e,touched:!0})),N(!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)(jg,{}),(0,$.jsx)(Ag,{heading:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:se.otherLocal.map(e=>(0,$.jsx)(Mg,{value:e,onSelect:()=>{x(t=>({...t,selectedBranch:e,worktreeName:s_(e)})),ge(e=>({...e,touched:!0})),N(!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)(jg,{}),(0,$.jsx)(Ag,{heading:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:se.otherRemote.map(e=>(0,$.jsx)(Mg,{value:`remotes/${e}`,onSelect:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:s_(e)})),ge(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(la,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:me,disabled:!pe||C,title:i(`session.newWorktree.fetchBranches`),children:C?(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`)}),g===`new-branch`&&je&&(0,$.jsxs)(la,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Fa,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ge(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,he.touched&&he.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.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:v.linkedPr.head})})]}),v.linkedIssue&&!v.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:v.linkedIssue.number,title:v.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`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=s_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===s_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===s_(v.branchName)||!v.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)(Fa,{value:Te.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>ge(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,he.touched&&he.worktreeError&&`border-destructive`)})]}),g===`new-branch`&&!v.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)(Ua,{open:P,onOpenChange:F,children:[(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(la,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,v.sourceBranch?`text-foreground`:`text-muted-foreground`),children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ka,{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:te,children:(0,$.jsxs)(Eg,{shouldFilter:!1,children:[(0,$.jsx)(Dg,{placeholder:i(`session.newWorktree.searchBranches`),value:H,onValueChange:U,onKeyDown:ne}),(0,$.jsx)(Og,{disableHorizontal:!0,children:C?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(kg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ue&&fe&&(0,$.jsx)(Ag,{heading:i(`session.newWorktree.matchingBranches`),children:ce.matching.map(e=>(0,$.jsx)(Mg,{value:e.value,onSelect:()=>{y(t=>({...t,sourceBranch:e.value})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),ue&&!fe&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ce.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[ue&&(0,$.jsx)(jg,{}),(0,$.jsx)(Ag,{heading:i(ue?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:ce.otherLocal.map(e=>(0,$.jsx)(Mg,{value:e,onSelect:()=>{y(t=>({...t,sourceBranch:e})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),ce.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(ce.otherLocal.length>0||ue)&&(0,$.jsx)(jg,{}),(0,$.jsx)(Ag,{heading:i(ue?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:ce.otherRemote.map(e=>(0,$.jsx)(Mg,{value:`remotes/${e}`,onSelect:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})})]}),(v.linkedIssue||v.linkedPr)&&g===`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`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.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:Ne,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`})})]}),v.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:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.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)(ra,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:he.touched&&(he.branchError||he.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:he.branchError||he.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(la,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:_e,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(la,{size:`sm`,onClick:Oe,disabled:!Me||_e,className:`gap-1.5`,children:[_e&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(_e?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(i_,{open:A,onOpenChange:j,onSelect:Ae})]})}function p_(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 m_(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 h_=(e,t)=>e??t??null,g_=(e,t)=>!!e&&t!==!1,__=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:[]},v_=e=>e.replace(/^remotes\//,``).trim(),y_=e=>{let t=v_(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},b_=({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}=st(),{git:d}=Do(),f=h_(t,e),p=e,m=Bs(f),h=Bs(p),g=g_(f,m),_=p!==f&&g_(p,h),v=gs(f,d,g),y=gs(p,d,_),b=v.data,x=p===f?b:y.data,S=ws(e=>e.fetchStatus),C=ws(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=zs(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=Mt(e=>e.projects),P=Mt(e=>e.activeProjectId);Z.useEffect(()=>{d&&(f&&m===null&&S(f,d,{silent:!0}),p&&p!==f&&h===null&&S(p,d,{silent:!0}))},[S,d,m,h,f,p]);let F=Z.useMemo(()=>{let e=u(t);if(e){let t=N.find(t=>u(t.path)===e);if(t)return t.id}return P},[P,t,N]),{localBranches:I,remoteBranches:L}=Z.useMemo(()=>__(b?.all),[b]),R=x?.current?.trim()||C||null,z=!m_(n,e)&&n||R||n||l(`chat.chatInput.branch`),B=K(async()=>{if(!d)return;let e=new Set;f&&e.add(f),p&&e.add(p),await Promise.all([...e].map(async e=>{await xs(e,d),await S(e,d,{silent:!0})}))}),V=K(e=>{let t=v_(e),n=y_(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),H=K(async e=>{if(!p||!d)return;let t=v_(e);if(R!==t&&R!==y_(t))try{await d.checkoutBranch(p,t),wr.success(l(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});wr.error(n)}}),U=K(e=>{let t=v_(e);if(!t||R===t||R===y_(t))return;let n=V(t);if(n){a(n.value);return}O(t)}),ee=K(async()=>{if(!(!D||k)){A(!0);try{await H(D),O(null)}finally{A(!1)}}}),te=K(async()=>{if(!(!D||k)){A(!0);try{await vg({branch:D,projectDirectory:t??void 0})&&O(null)}finally{A(!1)}}}),W=K(async(e,t)=>{if(!p||!d)return;let n=t?.name??`origin`;try{await d.createBranch(p,e,R??`HEAD`),wr.success(l(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),wr.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);wr.warning(l(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:t})}),await B()})}catch(e){let t=e instanceof Error?e.message:l(`gitView.toast.createBranchFailed`);throw wr.error(t),e}}),G=K(()=>{let e=Mt.getState(),n=u(t),r=n?e.projects.find(e=>u(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),ne=K((e,n)=>{if(M(!1),n?.sessionId){J.getState().setCurrentSession(n.sessionId,e);return}let r=Mt.getState(),i=u(t),a=(i?r.projects.find(e=>u(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=J.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),Ee.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,Ap,o),"aria-label":z,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:z}),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)(t_,{currentBranch:R,localBranches:I,remoteBranches:L,branchInfo:b?.branches,onCheckout:U,onCreate:W,remotes:E,trigger:re,triggerLabel:z,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:G,open:w,presentation:c,onOpenChange:T}),j?(0,$.jsx)(f_,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:ne}):null,(0,$.jsx)(ca,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ia,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(na,{children:[(0,$.jsx)(aa,{children:l(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(oa,{children:l(`chat.chatInput.branchSwitch.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:k,onClick:()=>{ee()},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:[k?(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:k,onClick:()=>{te()},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:[k?(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)(ra,{children:(0,$.jsx)(`button`,{type:`button`,disabled:k,onClick:()=>O(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`)})})]})})]})},x_=[],S_=[],C_={revertMessageID:void 0,records:S_},w_=e=>e.role===`user`,T_=(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},E_=(e,t,n=C_)=>{if(!t)return C_;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return C_;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!w_(e)||!wn(i,e.id,r)||o.push({message:e,parts:a[e.id]??x_});let s=o.length===0?S_:o;return n.revertMessageID===r&&T_(n.records,s)?n:{revertMessageID:r,records:s}},D_={mentionFile:100,mentionAgent:100,mentionSession:100,mentionCommand:100,mentionSnippet:100,mentionPaste:100,code:90,codeFence:90,link:80,linkUrl:78,heading:70,blockquote:40,listMarker:35,marker:10},O_={mentionFile:`text-[var(--primary)]`,mentionAgent:`text-[var(--primary)]`,mentionSession:`text-[var(--primary)]`,mentionCommand:`text-[var(--primary)]`,mentionSnippet:`text-[var(--primary)]`,mentionPaste:`text-[var(--primary)]`,code:`rounded-[3px] bg-[var(--surface-subtle)] text-[var(--markdown-inline-code)]`,codeFence:`bg-[var(--surface-subtle)] text-[var(--markdown-inline-code)]`,link:`text-[var(--status-info)] underline`,linkUrl:`text-muted-foreground`,heading:`text-[var(--syntax-keyword)]`,blockquote:`text-muted-foreground`,listMarker:`text-[var(--syntax-keyword)]`,marker:`text-muted-foreground`},k_=`text-foreground`;function A_(e,t,n){let r=0,i=e.length;for(;r<i;){let i=e[r];if(i==="`"){let i=/^`+/.exec(e.slice(r))?.[0]??``,a=e.indexOf(i,r+i.length);if(a!==-1){let e=a+i.length;n.push({start:t+r,end:t+e,style:`code`}),r=e;continue}}if(i===`[`){let i=/^\[([^\]\n]*)\]\(([^)\n]*)\)/.exec(e.slice(r));if(i){let e=t+r,a=i[1].length,o=i[2].length,s=e+1,c=s+a,l=c+2,u=l+o,d=u+1;n.push({start:e,end:s,style:`marker`}),a>0&&n.push({start:s,end:c,style:`link`}),n.push({start:c,end:l,style:`marker`}),o>0&&n.push({start:l,end:u,style:`linkUrl`}),n.push({start:u,end:d,style:`marker`}),r+=i[0].length;continue}}r+=1}}var j_=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function M_(e){let t=j_.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function N_(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function P_(e){let t=[];if(!e)return t;let n=0,r=!1,i=``,a=e.split(`
6522
- `);for(let e=0;e<a.length;e+=1){let o=a[e],s=n,c=s+o.length;if(n=c+1,r){t.push({start:s,end:c,style:`codeFence`}),N_(o,i)&&(r=!1);continue}let l=M_(o);if(l){r=!0,i=l.marker,t.push({start:s,end:c,style:`codeFence`});continue}let u=/^(\s*)(#{1,6})(\s+)/.exec(o);if(u){let e=s+u[1].length,n=e+u[2].length;t.push({start:e,end:n,style:`marker`});let r=n+u[3].length;c>r&&(t.push({start:r,end:c,style:`heading`}),A_(o.slice(r-s),r,t));continue}let d=/^(\s*)(>+)(\s?)/.exec(o);if(d){let e=s+d[1].length,n=e+d[2].length;t.push({start:e,end:n,style:`marker`});let r=n+d[3].length;c>r&&(t.push({start:r,end:c,style:`blockquote`}),A_(o.slice(r-s),r,t));continue}let f=/^(\s*)([-*+]|\d{1,9}[.)])(\s+)/.exec(o);if(f){let e=s+f[1].length,n=e+f[2].length;t.push({start:e,end:n,style:`listMarker`});let r=n+f[3].length;A_(o.slice(r-s),r,t);continue}A_(o,s,t)}return t}function F_(e,t){if(!e||t.length===0)return null;let n=e.length,r=new Set([0,n]);for(let e of t)e.start>0&&e.start<n&&r.add(e.start),e.end>0&&e.end<n&&r.add(e.end);let i=[...r].sort((e,t)=>e-t),a=t.map((e,t)=>({range:e,index:t})).filter(e=>e.range.end>e.range.start).sort((e,t)=>e.range.start-t.range.start),o=[],s=[],c=0;for(let t=0;t<i.length-1;t+=1){let n=i[t],r=i[t+1];if(r<=n)continue;for(;c<a.length&&a[c].range.start<=n;)s.push(a[c]),c+=1;for(let e=s.length-1;e>=0;--e)s[e].range.end<=n&&s.splice(e,1);let l=null,u=-1,d=1/0;for(let{range:e,index:t}of s){let n=e.priority??D_[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??O_[l.style]:k_,p=e.slice(n,r),m=l?.visual,h=l?.skillName,g=o[o.length-1];g&&g.className===f&&R(g.visual,m)&&g.skillName===h?g.text+=p:o.push({text:p,className:f,visual:m,skillName:h})}return o.length>0?o:null}function I_(e,t){let n=new Set(Array.from(t,e=>e.toLowerCase())),r=[],i=/(^|\s)\/(\u2003)?([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/gi,a;for(;(a=i.exec(e))!==null;){let e=a[2]??``,t=a[3]||``;if(!n.has(t.toLowerCase()))continue;let i=a.index+(a[1]?.length??0);r.push({start:i,end:i+1+e.length+t.length,name:t})}return r}function L_(e,t,n){if(e===t){let t=n.find(t=>e>t.start&&e<t.end);return t?{start:t.start,end:t.end}:null}let r=n.filter(n=>n.start<t&&n.end>e);return r.length===0?null:{start:Math.min(e,...r.map(e=>e.start)),end:Math.max(t,...r.map(e=>e.end))}}function R_(e,t,n){let r=I_(e,t),i=Math.max(0,Math.min(n.selectionStart,e.length)),a=Math.max(i,Math.min(n.selectionEnd,e.length)),o=i,s=a;if(i===a)if(n.altKey)if(n.key===`Backspace`){for(;o>0&&/\s/.test(e[o-1]);)--o;for(;o>0&&!/\s/.test(e[o-1]);)--o}else{for(;s<e.length&&/\s/.test(e[s]);)s+=1;for(;s<e.length&&!/\s/.test(e[s]);)s+=1}else n.key===`Backspace`?o=Math.max(0,i-1):s=Math.min(e.length,i+1);if(o===s)return null;let c=r.filter(e=>e.start<s&&e.end>o);if(c.length===0)return null;let l=Math.min(o,...c.map(e=>e.start)),u=Math.max(s,...c.map(e=>e.end));return u<e.length&&/\s/.test(e[u])&&(l===0||/\s/.test(e[l-1]))?u+=1:u===e.length&&l>0&&/\s/.test(e[l-1])&&--l,{text:`${e.slice(0,l)}${e.slice(u)}`,caret:l,removedSkillNames:c.map(e=>e.name)}}function z_(e){return e.map(e=>({start:e.start,end:e.end,style:e.kind===`file`?`mentionFile`:e.kind===`session`?`mentionSession`:`mentionAgent`,visual:e.kind===`session`&&e.label?ae({trigger:`@`,icon:`chat-thread`,label:e.label},H({trigger:`@`,icon:`chat-thread`,label:e.label})):void 0}))}function B_(e){let t=(0,Q.c)(28),{visual:n,text:r}=e,i=n.trigger.length,a=i+n.label.length,o=a+(n.suffix?.length??0),s;t[0]!==a||t[1]!==i||t[2]!==r?(s=r.slice(i,Math.min(a,r.length)),t[0]=a,t[1]=i,t[2]=r,t[3]=s):s=t[3];let c=s,l;t[4]!==a||t[5]!==o||t[6]!==r?(l=r.slice(a,Math.min(o,r.length)),t[4]=a,t[5]=o,t[6]=r,t[7]=l):l=t[7];let u=l,d;t[8]!==o||t[9]!==r?(d=r.slice(Math.min(o,r.length)),t[8]=o,t[9]=r,t[10]=d):d=t[10];let f=d,p;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p={left:z,right:z},t[11]=p):p=t[11];let m=n.icon,h;t[12]===m?h=t[13]:(h=(0,$.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 inline-flex items-center justify-center`,style:p,children:(0,$.jsx)(X,{name:m,className:`${N} shrink-0 text-[var(--primary)]`,"aria-hidden":`true`})}),t[12]=m,t[13]=h);let g;t[14]!==h||t[15]!==n.trigger?(g=(0,$.jsxs)(`span`,{className:`relative inline-block align-baseline text-transparent leading-none`,children:[n.trigger,h]}),t[14]=h,t[15]=n.trigger,t[16]=g):g=t[16];let _;t[17]===c?_=t[18]:(_=(0,$.jsx)(`span`,{children:c}),t[17]=c,t[18]=_);let v;t[19]===u?v=t[20]:(v=u?(0,$.jsx)(`span`,{className:`text-transparent`,children:u}):null,t[19]=u,t[20]=v);let y;t[21]===f?y=t[22]:(y=f?(0,$.jsx)(`span`,{className:`text-transparent`,children:f}):null,t[21]=f,t[22]=y);let b;return t[23]!==y||t[24]!==g||t[25]!==_||t[26]!==v?(b=(0,$.jsxs)($.Fragment,{children:[g,_,v,y]}),t[23]=y,t[24]=g,t[25]=_,t[26]=v,t[27]=b):b=t[27],b}var V_=`bg-[var(--surface-subtle)]`,H_=91,U_=94,W_={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},G_={keyword:`${V_} text-[var(--syntax-keyword)]`,string:`${V_} text-[var(--syntax-string)]`,number:`${V_} text-[var(--syntax-number)]`,comment:`${V_} text-[var(--syntax-comment)]`,function:`${V_} text-[var(--syntax-function)]`,type:`${V_} text-[var(--syntax-type)]`,variable:`${V_} text-[var(--syntax-variable)]`,operator:`${V_} text-[var(--syntax-operator)]`},K_=Xe([{tag:[Qe.comment,Qe.lineComment,Qe.blockComment,Qe.docComment,Qe.meta],class:`comment`},{tag:[Qe.keyword,Qe.modifier,Qe.controlKeyword,Qe.operatorKeyword,Qe.definitionKeyword,Qe.moduleKeyword,Qe.self,Qe.null],class:`keyword`},{tag:[Qe.string,Qe.special(Qe.string),Qe.docString,Qe.character,Qe.regexp],class:`string`},{tag:[Qe.number,Qe.integer,Qe.float,Qe.bool,Qe.atom],class:`number`},{tag:[Qe.function(Qe.variableName),Qe.function(Qe.propertyName),Qe.macroName,Qe.standard(Qe.variableName)],class:`function`},{tag:[Qe.typeName,Qe.className,Qe.namespace,Qe.tagName],class:`type`},{tag:[Qe.variableName,Qe.propertyName,Qe.attributeName,Qe.labelName,Qe.definition(Qe.variableName)],class:`variable`},{tag:[Qe.operator,Qe.punctuation,Qe.bracket,Qe.derefOperator,Qe.separator],class:`operator`},{tag:[Qe.heading,Qe.heading1,Qe.heading2,Qe.heading3,Qe.heading4,Qe.heading5,Qe.heading6,Qe.strong],class:`keyword`},{tag:[Qe.emphasis,Qe.quote],class:`type`},{tag:[Qe.link,Qe.url],class:`function`},{tag:[Qe.monospace],class:`string`},{tag:[Qe.strikethrough],class:`comment`}]),q_=e=>{let t=null;for(let n of e.split(` `)){let e=n;W_[e]!==void 0&&(t===null||W_[e]>W_[t])&&(t=e)}return t?G_[t]:null},J_=2e4,Y_=e=>{if(!e)return null;try{let t=so(e);return t instanceof $e?t:null}catch{return null}};function X_(e){if(!e||!e.includes("```")&&!e.includes(`~~~`))return[];let t=[],n=e.split(`
6520
+ `)?`...`:``),Ef=(e,t={})=>{let n=Tf(e);if(!n)return null;let r=wf(t.composerDocument);return Hd(n,{citationIcons:Sf(t.attachments),sessionMentions:Cf(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},Df=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`))},Of=(0,Z.memo)(e=>{let t=(0,Q.c)(132),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,sendPendingTimedOut:s,abortSendPending:c,isMobile:l,onEdit:u,onSend:d,onRemove:f}=e,{t:p}=ot(),m;t[0]===n?m=t[1]:(m=Ri(n),t[0]=n,t[1]=m);let h=m,g=n.queueItemID||n.id,_;t[2]!==o||t[3]!==r?(_=r&&o.has(`edit`),t[2]=o,t[3]=r,t[4]=_):_=t[4];let v=_,y;t[5]!==o||t[6]!==r?(y=r&&o.has(`remove`),t[5]=o,t[6]=r,t[7]=y):y=t[7];let b=y,x;t[8]!==o||t[9]!==r?(x=r&&o.has(`reorder`),t[8]=o,t[9]=r,t[10]=x):x=t[10];let S=x,C=r||h?void 0:n,w;t[11]!==n||t[12]!==h||t[13]!==r?(w=r&&!h&&lf(n),t[11]=n,t[12]=h,t[13]=r,t[14]=w):w=t[14];let T=w,E;t[15]===C?E=t[16]:(E=C&&cf(C),t[15]=C,t[16]=E);let D=!!E,O;t[17]!==n||t[18]!==h||t[19]!==r?(O=r&&!h&&sf(n),t[17]=n,t[18]=h,t[19]=r,t[20]=O):O=t[20];let k=O,A;t[21]!==T||t[22]!==D||t[23]!==o||t[24]!==r?(A=r&&o.has(`send`)||T||D,t[21]=T,t[22]=D,t[23]=o,t[24]=r,t[25]=A):A=t[25];let j=c||A&&!s,M=i||h,N;t[26]!==i||t[27]!==n?(N=af(n,{frozen:i}),t[26]=i,t[27]=n,t[28]=N):N=t[28];let P=N,F;t[29]!==i||t[30]!==n?(F=of(n,{frozen:i}),t[29]=i,t[30]=n,t[31]=F):F=t[31];let I=F,L=C?.owner?.state===`unbound-legacy`||M||k,R;t[32]!==M||t[33]!==a||t[34]!==n||t[35]!==j||t[36]!==s||t[37]!==r?(R=!M&&!j&&(r?rf(n,a,{allowManualDispatchRetry:s}):nf(n,a)),t[32]=M,t[33]=a,t[34]=n,t[35]=j,t[36]=s,t[37]=r,t[38]=R):R=t[38];let z=R,B=C?.failure?.recovery,V;t[39]===n?V=t[40]:(V=xf(n),t[39]=n,t[40]=V);let H=V,U=h?void 0:B?.attachments??n.attachments,W=B?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),ee;t[41]!==L||t[42]!==g?(ee={id:g,disabled:L},t[41]=L,t[42]=g,t[43]=ee):ee=t[43];let{attributes:G,listeners:K,setNodeRef:te,transform:ne,transition:re,isDragging:ie}=qo(ee),ae;t[44]===H?ae=t[45]:(ae=Tf(H),t[44]=H,t[45]=ae);let oe=ae,se;t[46]!==U||t[47]!==W||t[48]!==H?(se=Ef(H,{attachments:U,composerDocument:W}),t[46]=U,t[47]=W,t[48]=H,t[49]=se):se=t[49];let ce=se,le=h?n.attachmentCount:U?.length??0,ue;t[50]!==n||t[51]!==f?(ue=()=>f(n),t[50]=n,t[51]=f,t[52]=ue):ue=t[52];let de=!I,fe=b||void 0,pe=l?`h-7 w-3`:`size-7`,me;t[53]===pe?me=t[54]:(me=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`,pe),t[53]=pe,t[54]=me);let he;t[55]===p?he=t[56]:(he=p(`chat.queuedMessage.removeAria`),t[55]=p,t[56]=he);let ge=b?`loader-4`:`delete-bin`,_e=l?`size-3`:`size-3.5`,ve=b&&`animate-spin`,ye;t[57]!==_e||t[58]!==ve?(ye=Y(_e,ve),t[57]=_e,t[58]=ve,t[59]=ye):ye=t[59];let be;t[60]!==ge||t[61]!==ye?(be=(0,$.jsx)(X,{name:ge,className:ye,"aria-hidden":`true`}),t[60]=ge,t[61]=ye,t[62]=be):be=t[62];let xe;t[63]!==ue||t[64]!==de||t[65]!==fe||t[66]!==me||t[67]!==he||t[68]!==be?(xe=(0,$.jsx)(`button`,{type:`button`,onClick:ue,disabled:de,"aria-busy":fe,className:me,"aria-label":he,children:be}),t[63]=ue,t[64]=de,t[65]=fe,t[66]=me,t[67]=he,t[68]=be,t[69]=xe):xe=t[69];let Se=xe,Ce;t[70]===ne?Ce=t[71]:(Ce=Wo.Translate.toString(ne),t[70]=ne,t[71]=Ce);let we;t[72]!==Ce||t[73]!==re?(we={transform:Ce,transition:re},t[72]=Ce,t[73]=re,t[74]=we):we=t[74];let Te=l?`gap-1 py-0.5`:`flex gap-1.5 md:gap-2`,Ee=ie&&`z-10 opacity-60`,De;t[75]!==Te||t[76]!==Ee?(De=Y(`flex min-w-0 items-center`,Te,Ee),t[75]=Te,t[76]=Ee,t[77]=De):De=t[77];let Oe=S||void 0,ke=l?`h-7 w-3`:`size-auto`,Ae=L?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,je;t[78]!==ke||t[79]!==Ae?(je=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,ke,`transition-colors`,Ae),t[78]=ke,t[79]=Ae,t[80]=je):je=t[80];let Me;t[81]===p?Me=t[82]:(Me=p(`chat.queuedMessage.reorderAria`),t[81]=p,t[82]=Me);let Ne=S?`loader-4`:`draggable`,Pe=l?`size-3`:`size-3.5`,Fe=S&&`animate-spin`,Ie;t[83]!==Pe||t[84]!==Fe?(Ie=Y(Pe,Fe),t[83]=Pe,t[84]=Fe,t[85]=Ie):Ie=t[85];let Le;t[86]!==Ne||t[87]!==Ie?(Le=(0,$.jsx)(X,{name:Ne,className:Ie,"aria-hidden":`true`}),t[86]=Ne,t[87]=Ie,t[88]=Le):Le=t[88];let Re;t[89]!==G||t[90]!==L||t[91]!==K||t[92]!==Oe||t[93]!==je||t[94]!==Me||t[95]!==Le?(Re=(0,$.jsx)(`button`,{type:`button`,...G,...K,disabled:L,"aria-busy":Oe,className:je,"aria-label":Me,children:Le}),t[89]=G,t[90]=L,t[91]=K,t[92]=Oe,t[93]=je,t[94]=Me,t[95]=Le,t[96]=Re):Re=t[96];let ze=l?Se:null,Be=l?`text-xs leading-5`:`typography-ui-label leading-5`,Ve;t[97]===Be?Ve=t[98]:(Ve=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground`,Be),t[97]=Be,t[98]=Ve);let He;t[99]!==oe||t[100]!==ce||t[101]!==p?(He=ce?ce.map(Lf):oe||p(`chat.queuedMessage.empty`),t[99]=oe,t[100]=ce,t[101]=p,t[102]=He):He=t[102];let Ue;t[103]!==le||t[104]!==p?(Ue=le>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:p(`chat.queuedMessage.attachments`,{count:le})}),t[103]=le,t[104]=p,t[105]=Ue):Ue=t[105];let We;t[106]!==Ve||t[107]!==He||t[108]!==Ue?(We=(0,$.jsxs)(`span`,{className:Ve,children:[He,Ue]}),t[106]=Ve,t[107]=He,t[108]=Ue,t[109]=We):We=t[109];let Ge;t[110]!==P||t[111]!==z||t[112]!==v||t[113]!==l||t[114]!==n||t[115]!==u||t[116]!==d||t[117]!==h||t[118]!==j||t[119]!==p?(Ge=h?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.queuing`)})]}):j?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.sendingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.sending`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(n),disabled:!P,"aria-busy":v||void 0,"aria-label":p(`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`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:v?`loader-4`:`edit`,className:Y(l?`size-3`:`size-3.5`,v&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{j||d(n)},disabled:!z||j,"aria-busy":j||void 0,"aria-label":p(`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`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`send-plane`,className:Y(l?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.send`)})]})]}),t[110]=P,t[111]=z,t[112]=v,t[113]=l,t[114]=n,t[115]=u,t[116]=d,t[117]=h,t[118]=j,t[119]=p,t[120]=Ge):Ge=t[120];let Ke=!l&&!h?Se:null,qe;t[121]!==Ge||t[122]!==Ke?(qe=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[Ge,Ke]}),t[121]=Ge,t[122]=Ke,t[123]=qe):qe=t[123];let Je;return t[124]!==te||t[125]!==we||t[126]!==De||t[127]!==Re||t[128]!==ze||t[129]!==We||t[130]!==qe?(Je=(0,$.jsxs)(`div`,{ref:te,style:we,className:De,children:[Re,ze,We,qe]}),t[124]=te,t[125]=we,t[126]=De,t[127]=Re,t[128]=ze,t[129]=We,t[130]=qe,t[131]=Je):Je=t[131],Je});Of.displayName=`QueuedMessageChip`;var kf=[],Af=[],jf=[],Mf=new Set,Nf=(e,t)=>t?$d(b(e,x(t.sessionID)),b(e,t)):kf,Pf=(e,t)=>{if(!t)return Af;let n=Nf(e,t),r=[...B(e,x(t.sessionID)),...B(e,t)];return r.length===0?n:[...n,...r]},Ff=(e,t)=>{let n=e.owner;return n?n.state===`unbound-legacy`?n.sessionID===t.sessionID?x(t.sessionID):null:_(n)===_(t)?t:null:null},If=(0,Z.memo)(e=>{let t=(0,Q.c)(152),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:c,clientPendingItems:l,onRemoveClientPending:u,trailing:d}=e,f=l===void 0?jf:l,{t:p}=ot(),m=s(Rf),h=o?.transportIdentity??``,g=o?.directory??``,v=o?.sessionID??``,y;t[0]!==h||t[1]!==g||t[2]!==v?(y={transportIdentity:h,directory:g,sessionID:v},t[0]=h,t[1]=g,t[2]=v,t[3]=y):y=t[3];let b=iu(y),x;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(x=new Map,t[4]=x):x=t[4];let S=Z.useRef(x);o?.runtimeGeneration,o?.transportIdentity;let w=o?.transportIdentity??``,T=o?.runtimeGeneration??-1,E;t[5]!==w||t[6]!==T?(E=[w,`messageQueue`,`scopeMutation`,T],t[5]=w,t[6]=T,t[7]=E):E=t[7];let D=E,O;t[8]===b.actions?O=t[9]:(O=e=>$n(S,`${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=b.actions.captureRuntime();if(t.transportIdentity!==e.runtime.transportIdentity||t.generation!==e.runtime.generation)return Promise.resolve({status:`stale`});switch(e.kind){case`edit`:return b.actions.editIntoDraft(e.input);case`send`:return b.actions.manualSend(e.input);case`remove`:return b.actions.remove(e.input);case`reorder`:return b.actions.reorder(e.input)}throw Error(`Unsupported server queue operation`)}),t[8]=b.actions,t[9]=O);let k,A;t[10]!==b.actions||t[11]!==p?(k=(e,t)=>{let n=b.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&e.status!==`stale`&&t.kind===`edit`&&e.status!==`committed`&&Cr.error(p(`chat.chatInput.toast.queueOperationFailed`))},A=(e,t)=>{let n=b.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&Cr.error(p(e instanceof qi&&e.code===`unavailable`?`chat.chatInput.toast.queueOperationStatusUnknown`:`chat.chatInput.toast.queueOperationFailed`))},t[10]=b.actions,t[11]=p,t[12]=k,t[13]=A):(k=t[12],A=t[13]);let j;t[14]!==D||t[15]!==O||t[16]!==k||t[17]!==A?(j={mutationKey:D,mutationFn:O,onSuccess:k,onError:A},t[14]=D,t[15]=O,t[16]=k,t[17]=A,t[18]=j):j=t[18];let M=Ke(j),N;t[19]===D?N=t[20]:(N={filters:{mutationKey:D,exact:!0,status:`pending`},select:zf},t[19]=D,t[20]=N);let P=Ge(N),F;t[21]===D?F=t[22]:(F={filters:{mutationKey:D,exact:!0,status:`success`},select:Bf},t[21]=D,t[22]=F);let I=Ge(F),R;bb0:{if(!o||!b.scope){R=null;break bb0}let e=o.runtimeGeneration??b.runtimeCapture.generation,n;t[23]!==o.directory||t[24]!==o.sessionID||t[25]!==o.transportIdentity||t[26]!==b.scope.scopeID||t[27]!==e?(n={transportIdentity:o.transportIdentity,directory:o.directory,sessionID:o.sessionID,scopeID:b.scope.scopeID,runtimeGeneration:e},t[23]=o.directory,t[24]=o.sessionID,t[25]=o.transportIdentity,t[26]=b.scope.scopeID,t[27]=e,t[28]=n):n=t[28],R=n}let z=R,B;bb1:{if(!z){let e;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[29]=e):e=t[29],B=e;break bb1}let e;if(t[30]!==z||t[31]!==P){let n;t[33]===z?n=t[34]:(n=e=>Df(e)&&e.scopeID===z.scopeID,t[33]=z,t[34]=n),e=pf(P.filter(n),z),t[30]=z,t[31]=P,t[32]=e}else e=t[32];B=e}let V=B,H;t[35]!==z||t[36]!==b.scope?.revision||t[37]!==I?(H=()=>z?mf(I.filter(Vf),z,b.scope?.revision):[],t[35]=z,t[36]=b.scope?.revision,t[37]=I,t[38]=H):H=t[38],b.scope?.revision;let U;t[39]===H?U=t[40]:(U=H(),t[39]=H,t[40]=U);let W=U,ee;t[41]!==W||t[42]!==V?(ee=[...V,...W],t[41]=W,t[42]=V,t[43]=ee):ee=t[43];let G=ee,K;t[44]===o?K=t[45]:(K=e=>Pf(e,o),t[44]=o,t[45]=K);let te=C(K);Z.useSyncExternalStore(Jt,mn,mn);let ne;t[46]!==G||t[47]!==te||t[48]!==b.items||t[49]!==b.mode?(ne=b.mode===`server`?_f(b.items,G):te,t[46]=G,t[47]=te,t[48]=b.items,t[49]=b.mode,t[50]=ne):ne=t[50];let re=ne,ie;t[51]!==re||t[52]!==f?(ie=f.length===0?re:[...re,...f],t[51]=re,t[52]=f,t[53]=ie):ie=t[53];let ae=ie,oe;t[54]!==o?.sessionID||t[55]!==ae?(oe=()=>{let e=o?.sessionID,t=new Set;if(!e)return t;for(let n of ae){let r=n.queueItemID||n.id;r&&Sn(e,r)&&t.add(r)}return t},t[54]=o?.sessionID,t[55]=ae,t[56]=oe):oe=t[56],o?.sessionID;let se;t[57]===oe?se=t[58]:(se=oe(),t[57]=oe,t[58]=se);let ce=se,le;if(t[59]!==G){le=new Map;for(let e of G){let t=le.get(e.queueItemID)??new Set;t.add(e.kind),le.set(e.queueItemID,t)}t[59]=G,t[60]=le}else le=t[60];let ue=le,de;if(t[61]!==G||t[62]!==ae||t[63]!==b.mode){bb2:{let e=new Set;if(b.mode===`server`){for(let t of G)t.kind===`send`&&e.add(t.queueItemID);for(let t of ae){if(Ri(t))continue;let n=t.queueItemID;n&&lf(t)&&e.add(n)}de=e;break bb2}for(let t of ae){if(Ri(t))continue;let n=t;cf(n)&&e.add(n.queueItemID||n.id)}de=e}t[61]=G,t[62]=ae,t[63]=b.mode,t[64]=de}else de=t[64];let fe=de,[pe,me]=Z.useState(Hf),he;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(he=new Map,t[65]=he):he=t[65];let ge=Z.useRef(he),_e,ve;t[66]!==fe||t[67]!==pe?(_e=()=>{let e=ge.current,t=Date.now();for(let t of[...e.keys()])fe.has(t)||e.delete(t);me(e=>{let t=!1,n=new Set;for(let r of e)fe.has(r)?n.add(r):t=!0;return t?n:e});let n=[];for(let r of fe){if(e.has(r)||(e.set(r,t),me(e=>{if(!e.has(r))return e;let t=new Set(e);return t.delete(r),t})),pe.has(r))continue;let i=df-(t-(e.get(r)??t));if(i<=0){me(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t});continue}n.push(setTimeout(()=>{ge.current.has(r)&&me(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)}},ve=[fe,pe],t[66]=fe,t[67]=pe,t[68]=_e,t[69]=ve):(_e=t[68],ve=t[69]),Z.useEffect(_e,ve);let ye;t[70]===b.mode?ye=t[71]:(ye=Qd(b.mode),t[70]=b.mode,t[71]=ye);let be=!ye,xe=Wt(o),Se;t[72]!==xe||t[73]!==ae||t[74]!==b.mode?(Se=b.mode===`server`?!1:xe||ae.some(Uf),t[72]=xe,t[73]=ae,t[74]=b.mode,t[75]=Se):Se=t[75];let Ce=Se,we=C(Wf),Te;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(Te={activationConstraint:{distance:8}},t[76]=Te):Te=t[76];let Ee;t[77]===Symbol.for(`react.memo_cache_sentinel`)?(Ee={activationConstraint:{delay:200,tolerance:6}},t[77]=Ee):Ee=t[77];let De=Uo(Io(Vo,Te),Io(Ro,Ee)),Oe;t[78]!==be||t[79]!==o||t[80]!==ae||t[81]!==we||t[82]!==M||t[83]!==b.actions||t[84]!==b.mode||t[85]!==b.scope?(Oe=e=>{if(be)return;let{active:t,over:n}=e;if(!n||t.id===n.id)return;if(b.mode===`server`){if(!o||!b.scope)return;let e=ae,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||Ri(r)||Ri(i)||sf(r)||sf(i))return;let a=b.scope,s=b.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=L(),l=bf(a,String(t.id),String(n.id),c,e);if(!l)return;M.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(Gf);return}let r=ae.filter(Kf),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=Ff(i,o),c=Ff(a,o);!s||!c||_(s)!==_(c)||we(s,String(t.id),String(n.id),i.operationID)},t[78]=be,t[79]=o,t[80]=ae,t[81]=we,t[82]=M,t[83]=b.actions,t[84]=b.mode,t[85]=b.scope,t[86]=Oe):Oe=t[86];let ke=q(Oe),Ae;t[87]!==a||t[88]!==c||t[89]!==be||t[90]!==i||t[91]!==n||t[92]!==o||t[93]!==M||t[94]!==b.actions||t[95]!==b.mode||t[96]!==b.scope?(Ae=e=>{if(be||Ri(e))return;if(b.mode===`server`){if(!o||!b.scope||!a||!c)return;let t=e,n=c.expectedRevision(),r=b.scope,s=b.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;M.mutateAsync({kind:`edit`,transportIdentity:s.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:L(),runtime:s,runtimeGeneration:s.generation,input:yf(r,t,c.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(qf);return}if(!o)return;let t=e,r=Ff(t,o);if(!r)return;let s=t.queueItemID??t.id,l=t.operationID,u=tf(t);(async()=>{let e;try{e=await Promise.resolve(n(u.content,u.attachments,u.composerDocument,u.composerMentions))}catch{e=!1}e&&(i?.(),C.getState().removeFromQueue(r,s,l))})()},t[87]=a,t[88]=c,t[89]=be,t[90]=i,t[91]=n,t[92]=o,t[93]=M,t[94]=b.actions,t[95]=b.mode,t[96]=b.scope,t[97]=Ae):Ae=t[97];let je=q(Ae),Me;t[98]!==be||t[99]!==r||t[100]!==o||t[101]!==M||t[102]!==b.actions||t[103]!==b.mode||t[104]!==b.scope?(Me=e=>{if(be||Ri(e))return;if(b.mode===`server`){if(!o||!b.scope)return;let t=e,n=b.scope,r=b.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=t.queueItemID;ge.current.delete(i),me(e=>{if(!e.has(i))return e;let t=new Set(e);return t.delete(i),t});let a=L();M.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:vf(n,t,a)}).catch(Jf);return}if(!o)return;let t=e;if(!Ff(t,o))return;let n=t.queueItemID??t.id;ge.current.delete(n),me(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t}),r(n)},t[98]=be,t[99]=r,t[100]=o,t[101]=M,t[102]=b.actions,t[103]=b.mode,t[104]=b.scope,t[105]=Me):Me=t[105];let Ne=q(Me),Pe;t[106]!==f||t[107]!==be||t[108]!==u||t[109]!==o||t[110]!==M||t[111]!==b.actions||t[112]!==b.mode||t[113]!==b.scope?(Pe=e=>{if(Ri(e)){f.some(t=>t.requestID===e.requestID)&&u?.(e.requestID);return}if(be)return;if(b.mode===`server`){if(!o||!b.scope)return;let t=e,n=b.scope,r=b.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=L();M.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:vf(n,t,i)}).catch(Yf);return}if(!o)return;let t=e,n=Ff(t,o);n&&C.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[106]=f,t[107]=be,t[108]=u,t[109]=o,t[110]=M,t[111]=b.actions,t[112]=b.mode,t[113]=b.scope,t[114]=Pe):Pe=t[114];let Fe=q(Pe),Ie=ae.length>0&&(o||f.length>0);if(!Ie&&!d)return null;let Le=m?`px-2`:`px-4`,Re;t[115]===Le?Re=t[116]:(Re=Y(`oc-composer-queue relative z-0 -mb-5 w-full`,Le),t[115]=Le,t[116]=Re);let ze=m?`rounded-[1.25rem]`:`rounded-3xl`,Be;t[117]===ze?Be=t[118]:(Be=Y(`overflow-hidden border border-border/60 bg-[var(--surface-subtle)] text-foreground`,ze),t[117]=ze,t[118]=Be);let Ve=m?`px-1.5 py-1`:`gap-0.5 px-3 pb-1 pt-1.5`,He;t[119]===Ve?He=t[120]:(He=Y(`flex flex-col`,Ve),t[119]=Ve,t[120]=He);let Ue;t[121]!==ce||t[122]!==be||t[123]!==ke||t[124]!==je||t[125]!==Fe||t[126]!==Ne||t[127]!==Ce||t[128]!==Ie||t[129]!==m||t[130]!==ue||t[131]!==ae||t[132]!==pe||t[133]!==De||t[134]!==b.mode?(Ue=Ie?(0,$.jsx)(Ho,{sensors:De,collisionDetection:Bo,onDragEnd:ke,children:(0,$.jsx)(Yo,{items:ae.map(Xf),strategy:Jo,children:ae.map(e=>{let t=e.queueItemID||e.id;return(0,$.jsx)(Of,{message:e,server:b.mode===`server`,frozen:be,hasDispatchLock:Ce,pendingOperationKinds:ue.get(t)??Mf,sendPendingTimedOut:pe.has(t),abortSendPending:ce.has(t),isMobile:m,onEdit:je,onSend:Ne,onRemove:Fe},t)})})}):null,t[121]=ce,t[122]=be,t[123]=ke,t[124]=je,t[125]=Fe,t[126]=Ne,t[127]=Ce,t[128]=Ie,t[129]=m,t[130]=ue,t[131]=ae,t[132]=pe,t[133]=De,t[134]=b.mode,t[135]=Ue):Ue=t[135];let We;t[136]!==Ie||t[137]!==d?(We=d?(0,$.jsxs)($.Fragment,{children:[Ie?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,d]}):null,t[136]=Ie,t[137]=d,t[138]=We):We=t[138];let qe;t[139]!==He||t[140]!==Ue||t[141]!==We?(qe=(0,$.jsxs)(`div`,{className:He,children:[Ue,We]}),t[139]=He,t[140]=Ue,t[141]=We,t[142]=qe):qe=t[142];let Je=m?`h-4`:`h-5`,Ye;t[143]===Je?Ye=t[144]:(Ye=(0,$.jsx)(`div`,{"aria-hidden":`true`,className:Je}),t[143]=Je,t[144]=Ye);let Xe;t[145]!==Be||t[146]!==qe||t[147]!==Ye?(Xe=(0,$.jsxs)(`div`,{className:Be,children:[qe,Ye]}),t[145]=Be,t[146]=qe,t[147]=Ye,t[148]=Xe):Xe=t[148];let Ze;return t[149]!==Re||t[150]!==Xe?(Ze=(0,$.jsx)(`div`,{className:Re,children:Xe}),t[149]=Re,t[150]=Xe,t[151]=Ze):Ze=t[151],Ze});If.displayName=`QueuedMessageChips`;function Lf(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(Xd,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Rf(e){return e.isMobile}function zf(e){return e.state.variables}function Bf(e){let t=e.state.variables;if(!Df(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 Vf(e){return e!==void 0}function Hf(){return new Set}function Uf(e){return!Ri(e)&&(e.status===`sending`||e.status===`reconciling`)}function Wf(e){return e.reorderQueue}function Gf(){}function Kf(e){return!Ri(e)}function qf(){}function Jf(){}function Yf(){}function Xf(e){return e.queueItemID||e.id}var Zf=[0,200,400],Qf=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=Zf.map($f),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 $f(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var ep=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=ot(),n=Qr(tp),r;e[0]===n?r=e[1]:(r=e=>{if(!n)return null;let t=e.runsByOriginalSessionID[n]??null;return t?.runtimeKey===i()?t:null},e[0]=n,e[1]=r);let a=wi(r),o=wi(np),c=s(rp),l=s(ip);if(!n||!a||a.status!==`running`)return null;let u;e[2]!==a.phase||e[3]!==t?(u=a.phase===`waiting_for_reviewer`?t(`chat.autoReview.status.waitingForReviewer`):t(`chat.autoReview.status.waitingForImplementer`),e[2]=a.phase,e[3]=t,e[4]=u):u=e[4];let d=u,f;e[5]!==c||e[6]!==a.directory||e[7]!==a.reviewSessionID||e[8]!==t?(f=()=>{c(a.directory,{mode:`chat`,dedupeKey:`session:${a.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=c,e[6]=a.directory,e[7]=a.reviewSessionID,e[8]=t,e[9]=f):f=e[9];let p=f,m=l?`pb-1 text-xs`:`pb-2`,h;e[10]===m?h=e[11]:(h=Y(`w-full px-1`,m),e[10]=m,e[11]=h);let g=l?`rounded-lg`:`rounded-xl`,_;e[12]===g?_=e[13]:(_=Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,g),e[12]=g,e[13]=_);let v=l?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`,y;e[14]===v?y=e[15]:(y=Y(`flex w-full items-center text-left`,v),e[14]=v,e[15]=y);let b=l?`size-3.5`:`size-4`,x;e[16]===b?x=e[17]:(x=Y(`animate-spin text-muted-foreground`,b),e[16]=b,e[17]=x);let S;e[18]===x?S=e[19]:(S=(0,$.jsx)(X,{name:`loader-4`,className:x,"aria-hidden":`true`}),e[18]=x,e[19]=S);let C;e[20]===t?C=e[21]:(C=t(`chat.autoReview.title`),e[20]=t,e[21]=C);let w;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(Qf,{}),e[22]=w):w=e[22];let T;e[23]===C?T=e[24]:(T=(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:[C,w]}),e[23]=C,e[24]=T);let E;e[25]===d?E=e[26]:(E=(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:d}),e[25]=d,e[26]=E);let D;e[27]!==T||e[28]!==E?(D=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[T,E]}),e[27]=T,e[28]=E,e[29]=D):D=e[29];let O;e[30]===t?O=e[31]:(O=t(`chat.autoReview.actions.open`),e[30]=t,e[31]=O);let k;e[32]!==p||e[33]!==O?(k=(0,$.jsx)(la,{type:`button`,variant:`secondary`,size:`xs`,onClick:p,children:O}),e[32]=p,e[33]=O,e[34]=k):k=e[34];let A;e[35]!==n||e[36]!==o?(A=()=>o(n),e[35]=n,e[36]=o,e[37]=A):A=e[37];let j;e[38]===t?j=e[39]:(j=t(`chat.autoReview.actions.stop`),e[38]=t,e[39]=j);let M;e[40]!==A||e[41]!==j?(M=(0,$.jsx)(la,{type:`button`,variant:`secondary`,size:`xs`,onClick:A,children:j}),e[40]=A,e[41]=j,e[42]=M):M=e[42];let N;e[43]!==S||e[44]!==D||e[45]!==k||e[46]!==M||e[47]!==y?(N=(0,$.jsxs)(`div`,{className:y,children:[S,D,k,M]}),e[43]=S,e[44]=D,e[45]=k,e[46]=M,e[47]=y,e[48]=N):N=e[48];let P;e[49]!==N||e[50]!==_?(P=(0,$.jsx)(`div`,{className:_,children:N}),e[49]=N,e[50]=_,e[51]=P):P=e[51];let F;return e[52]!==P||e[53]!==h?(F=(0,$.jsx)(`div`,{className:h,children:P}),e[52]=P,e[53]=h,e[54]=F):F=e[54],F});ep.displayName=`AutoReviewBanner`;function tp(e){return e.currentSessionId}function np(e){return e.stopRun}function rp(e){return e.openContextPanelTab}function ip(e){return e.isMobile}var ap=Z.forwardRef((e,t)=>{let n=(0,Q.c)(55),{searchQuery:r,onSkillSelect:i,onClose:a,directory:o,style:c}=e,l=Z.useRef(null),u=s(op),d=hs(l,u),[f,p]=Z.useState(0),m=Z.useRef(0),h=Z.useRef(!1),g;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=[],n[0]=g):g=n[0];let[_,v]=Z.useState(g),y;n[1]===Symbol.for(`react.memo_cache_sentinel`)?(y=[],n[1]=y):y=n[1];let b=Z.useRef(y),x;n[2]===o?x=n[3]:(x={directory:o},n[2]=o,n[3]=x);let S=ti(x),C;n[4]===S.data?C=n[5]:(C=S.data??[],n[4]=S.data,n[5]=C);let w=C,T,E;n[6]!==r||n[7]!==w?(T=()=>{let e=r.trim();if(!e.length){let e=[...w].sort(sp);v(e),p(0);return}let t=Dr(w,e,cp);t.sort(lp),v(t.map(up)),p(0)},E=[w,r],n[6]=r,n[7]=w,n[8]=T,n[9]=E):(T=n[8],E=n[9]),Z.useEffect(T,E);let D,O;n[10]===f?(D=n[11],O=n[12]):(D=()=>{m.current=f},O=[f],n[10]=f,n[11]=D,n[12]=O),Z.useEffect(D,O);let k,A;n[13]===f?(k=n[14],A=n[15]):(A=()=>{b.current[f]?.scrollIntoView({block:`nearest`})},k=[f],n[13]=f,n[14]=k,n[15]=A),Z.useEffect(A,k);let j,M;n[16]===a?(j=n[17],M=n[18]):(j=()=>{let e=e=>{let t=e.target;!t||!l.current||l.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},M=[a],n[16]=a,n[17]=j,n[18]=M),Z.useEffect(j,M);let N,P;n[19]!==_||n[20]!==a||n[21]!==i?(N=()=>({handleKeyDown:e=>{if(e===`Escape`){a();return}if(_.length){if(e===`ArrowDown`){h.current=!0,p(e=>(e+1)%_.length);return}if(e===`ArrowUp`){h.current=!0,p(e=>(e-1+_.length)%_.length);return}if(e===`Enter`||e===`Tab`){let e=(m.current%_.length+_.length)%_.length,t=_[e];t&&i(t)}}}}),P=[_,i,a],n[19]=_,n[20]=a,n[21]=i,n[22]=N,n[23]=P):(N=n[22],P=n[23]),Z.useImperativeHandle(t,N,P);let F,I,L,R,z,B,V,H;if(n[24]!==_||n[25]!==u||n[26]!==d||n[27]!==i||n[28]!==f||n[29]!==c){let e=(e,t)=>{let n=e.scope===`project`,r=e.source||`opencode`;return(0,$.jsx)(`div`,{ref:e=>{b.current[t]=e},className:Y(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,u?`items-center`:`items-start`,t===f&&`bg-interactive-selection`),onClick:()=>i(e),onMouseMove:()=>{h.current=!1,p(t)},children:(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold truncate`,children:e.name}),(0,$.jsx)(`span`,{className:Y(`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 transition-colors`,n?`bg-[var(--status-info-background)] text-[var(--status-info)] border-[var(--status-info-border)]`:`bg-[var(--status-success-background)] text-[var(--status-success)] border-[var(--status-success-border)]`),children:e.scope}),(0,$.jsx)(`span`,{className:`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`,children:r})]}),e.description&&!u&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:e.description})]})},`${e.name}-${e.scope}`)};B=l,V=`absolute z-[100] min-w-0 w-full max-w-[450px] max-h-60 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,n[38]!==d||n[39]!==c?(H=d===void 0?c:{...c,maxHeight:d},n[38]=d,n[39]=c,n[40]=H):H=n[40],F=fa,I=!0,L=`flex-1 min-h-0`,R=`px-0 pb-2`,z=_.length?(0,$.jsx)(`div`,{children:_.map((t,n)=>e(t,n))}):(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:`No skills found`}),n[24]=_,n[25]=u,n[26]=d,n[27]=i,n[28]=f,n[29]=c,n[30]=F,n[31]=I,n[32]=L,n[33]=R,n[34]=z,n[35]=B,n[36]=V,n[37]=H}else F=n[30],I=n[31],L=n[32],R=n[33],z=n[34],B=n[35],V=n[36],H=n[37];let U;n[41]!==F||n[42]!==I||n[43]!==L||n[44]!==R||n[45]!==z?(U=(0,$.jsx)(F,{preventOverscroll:I,outerClassName:L,className:R,children:z}),n[41]=F,n[42]=I,n[43]=L,n[44]=R,n[45]=z,n[46]=U):U=n[46];let W;n[47]===u?W=n[48]:(W=!u&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:`↑↓ navigate • Enter select • Esc close`}),n[47]=u,n[48]=W);let ee;return n[49]!==B||n[50]!==V||n[51]!==H||n[52]!==U||n[53]!==W?(ee=(0,$.jsxs)(`div`,{ref:B,className:V,style:H,children:[U,W]}),n[49]=B,n[50]=V,n[51]=H,n[52]=U,n[53]=W,n[54]=ee):ee=n[54],ee});ap.displayName=`SkillAutocomplete`;function op(e){return e.isMobile}function sp(e,t){return e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name)}function cp(e){return[e.name,e.description??``]}function lp(e,t){return e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score}function up(e){return e.item}function dp(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 fp(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(pp).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)(dp,{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 pp(e){return e.trim()}var mp=`mobile-overlay-root`,hp=16,gp=200,_p=[],vp=0,yp=``,bp=0,xp=()=>{if(typeof document>`u`)return null;let e=document.getElementById(mp);return e||(e=document.createElement(`div`),e.id=mp,document.body.appendChild(e)),e},Sp=({open:e,title:t,onClose:n,children:r,footer:i,className:a,contentMaxHeightClassName:o,renderHeader:s,containedBody:c=!1,closeAriaLabel:l})=>{let u=Z.useRef(null),d=Z.useRef(Symbol(`mobile-overlay`)),f=Z.useRef(n);f.current=n;let[p,m]=Z.useState(!1),[h,g]=Z.useState(!1);if(typeof document<`u`&&!u.current&&(u.current=xp()),Z.useEffect(()=>{if(!e){m(!1),g(!1);return}let t=window.setTimeout(()=>m(!0),hp),n=window.setTimeout(()=>g(!0),266);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[e]),Z.useLayoutEffect(()=>{if(e)return bp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-opened`)),bp+=1,()=>{bp=Math.max(0,bp-1),bp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-closed`))}},[e]),Z.useEffect(()=>{if(!e)return;let t=d.current;_p.push(t),vp===0&&(yp=document.body.style.overflow),vp+=1,document.body.style.overflow=`hidden`;let n=e=>{e.key===`Escape`&&_p[_p.length-1]===t&&f.current()};return document.addEventListener(`keydown`,n),()=>{let e=_p.lastIndexOf(t);e>=0&&_p.splice(e,1),vp=Math.max(0,vp-1),vp===0&&(document.body.style.overflow=yp),document.removeEventListener(`keydown`,n)}},[e]),!e||!u.current)return null;let _=o??`max-h-[min(70vh,520px)]`,v=(0,$.jsx)(`div`,{className:Y(`oc-keyboard-inset-surface fixed inset-0 z-[60] flex flex-col bg-[rgb(0_0_0_/_0.45)] transition-opacity duration-200 ease-out`,!h&&`oc-keyboard-inset-snap`,p?`opacity-100`:`opacity-0`),role:`dialog`,"aria-modal":`true`,"aria-label":t,onPointerDown:Ja,onClick:e=>{Ha(e)&&n()},children:(0,$.jsxs)(`div`,{className:Y(`mt-auto flex max-h-[calc(100dvh-0.75rem)] min-h-0 w-full flex-col rounded-t-xl border-x border-t border-border/50 bg-background pb-[max(0.5rem,var(--oc-app-bottom-safe,0px),var(--oc-safe-area-bottom,env(safe-area-inset-bottom,0px)))] shadow-none pwa-overlay-panel`,`mx-auto max-w-lg`,a),style:{transform:p?`none`:`translateY(100%)`,transition:`transform ${gp}ms cubic-bezier(0.32, 0.72, 0, 1)`},onClick:e=>e.stopPropagation(),children:[(()=>{let e=(0,$.jsx)(`button`,{type:`button`,onClick:n,className:Y(`flex items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover`,c?`size-11`:`h-8 w-8`),"aria-label":l??t,children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4`})});return s?s(e):(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border/40`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:t}),e]})})(),c?(0,$.jsx)(`div`,{className:Y(`flex min-h-0 flex-1 flex-col overflow-hidden`,_),children:r}):(0,$.jsx)(fa,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:Y(`min-h-0 flex-1`,_),className:`px-2 py-2 pwa-overlay-scroll`,children:r}),i?(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/40 px-3 py-2`,children:i}):null]})});return(0,xc.createPortal)(v,u.current)},Cp=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,wp=1e3,Tp=e=>{let t=(0,Q.c)(24),{name:n,label:r,revealed:i,avatarSize:a,slotClassName:o,colorVar:s}=e,c;t[0]===o?c=t[1]:(c=Y(`inline-flex shrink-0 items-center justify-center`,o),t[0]=o,t[1]=c);let l=i?void 0:r,u;t[2]!==a||t[3]!==n||t[4]!==l?(u=(0,$.jsx)(ea,{name:n,size:a,label:l}),t[2]=a,t[3]=n,t[4]=l,t[5]=u):u=t[5];let d;t[6]!==c||t[7]!==u?(d=(0,$.jsx)(`span`,{className:c,children:u}),t[6]=c,t[7]=u,t[8]=d):d=t[8];let f=i?`grid-cols-[1fr] opacity-100`:`grid-cols-[0fr] opacity-0`,p;t[9]===f?p=t[10]:(p=Y(`grid min-w-0 items-center ease-in-out`,f),t[9]=f,t[10]=p);let m;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m={transitionProperty:`grid-template-columns, opacity`,transitionDuration:`280ms`,transitionTimingFunction:`ease-in-out`},t[11]=m):m=t[11];let h=!i,g;t[12]===s?g=t[13]:(g=s?{color:`var(${s})`}:void 0,t[12]=s,t[13]=g);let _;t[14]!==r||t[15]!==g?(_=(0,$.jsx)(`span`,{className:`flex min-w-0 items-center overflow-hidden`,children:(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap pl-1.5 pr-0.5 typography-micro leading-none font-medium`,style:g,children:r})}),t[14]=r,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==_||t[18]!==p||t[19]!==h?(v=(0,$.jsx)(`span`,{className:p,style:m,"aria-hidden":h,children:_}),t[17]=_,t[18]=p,t[19]=h,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==d?(y=(0,$.jsxs)($.Fragment,{children:[d,v]}),t[21]=v,t[22]=d,t[23]=y):y=t[23],y};function Ep(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},wp),()=>{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 Dp=`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,Op=e=>`flow-root ${e?`py-1`:`py-1.5`}`,kp=`${Dp} hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Ap=`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)]`,jp=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${Ap}`,Mp=`rounded-md ${Ap}`,Np=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},Pp=e=>{if(e)try{let t=Np();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},Fp=(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`},Ip=e=>{let t=Pp(e);return t?Fp(t.permission,`edit`):`ask`},Lp=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},Rp=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return Lp(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:Lp(n.tokens)},zp=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}},Bp=(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}},Vp=[`ask`,`allow`,`full`],Hp=`__global__`,Up=de()(pe(fe((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=Bp(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=Rp(d);if(h===0)return m||null;let g=Bp(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=Rp(o);if(s===0)return;let c=Bp(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`&&Rp(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=Ip(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Hp){let e=t().sessionAgentEditModes.get(Hp)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=Ip(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Vp.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=Ip(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Vp.indexOf(a),s=Vp.indexOf(i),c=Vp[((o>=0?o:s>=0?s:0)+1)%Vp.length];t().setSessionAgentEditMode(e,n,c,i)}}),{name:`context-store`,storage:l(),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`})),Wp=e=>kr([...e??[]]),Gp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,Kp=(e,t)=>{let n=(0,Q.c)(16),r;n[0]===t?r=n[1]:(r=t===void 0?[]:t,n[0]=t,n[1]=r);let i=r,[a,o]=Z.useState(!1),s;n[2]===e?s=n[3]:(s=()=>{let t=e.current;if(!t)return;let n=t.scrollWidth>t.clientWidth+1;o(e=>e===n?e:n)},n[2]=e,n[3]=s);let c=s,l;n[4]===c?l=n[5]:(l=()=>{c()},n[4]=c,n[5]=l);let u;n[6]!==c||n[7]!==i?(u=[c,...i],n[6]=c,n[7]=i,n[8]=u):u=n[8],Gp(l,u);let d,f;n[9]!==c||n[10]!==e?(d=()=>{let t=e.current;if(!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{c()});return n.observe(t),()=>n.disconnect()},f=[c,e],n[9]=c,n[10]=e,n[11]=d,n[12]=f):(d=n[11],f=n[12]),Z.useEffect(d,f);let p,m;return n[13]===c?(p=n[14],m=n[15]):(p=()=>{if(typeof window>`u`||typeof ResizeObserver<`u`)return;let e=()=>c();return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},m=[c],n[13]=c,n[14]=p,n[15]=m),Z.useEffect(p,m),a};function qp(e,t){return!e&&t===`trigger-hover`}var Jp=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},Yp=e=>{let t=Jp(e);return t?(t.focus({preventScroll:!0}),!0):!1},Xp=(e,t)=>e&&!t,Zp=e=>{let t=e?.variants;return t?Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):typeof t==`object`?Object.keys(t):[]:[]},Qp=(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 Zp(i)},$p=()=>!0,em=(e,t)=>(e.commandPolicy??$p)(t),tm=Z.createContext(null),nm=()=>Z.useContext(tm),rm=e=>e,im=(e,t)=>t??e,am=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`)},om=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,sm=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},cm=(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}},lm=(e,t)=>`${e}:${t}`,um=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,dm=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},fm=(e,t)=>{let n=dm(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}}},pm=[{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}],mm={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`}},hm=e=>e.trim().toLowerCase(),gm=(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=>hm(e)))),i=[];for(let e of r){let t=mm[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},_m=e=>new Intl.NumberFormat(st(),{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:1,minimumFractionDigits:0}).format(e),vm=e=>new Intl.NumberFormat(st(),{style:`currency`,currency:`USD`,maximumFractionDigits:4,minimumFractionDigits:2}).format(e),ym=e=>new Intl.DateTimeFormat(st(),{month:`short`,day:`numeric`,year:`numeric`}).format(e),bm=`__add_provider__`,xm=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},Sm=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=Cp(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},Cm=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=_m(e);return t.endsWith(`.0`)?t.slice(0,-2):t},wm=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:vm(e),Tm=e=>{let t=[];for(let n of pm)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},Em=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:ym(t)},Dm=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=ot(),o=Z.useId(),{isReady:c,isUnavailable:l}=to(),u=l||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),d=mi(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=mi(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),p=i?.catalog,m=c&&(p?.ready??!d)&&!p?.loading&&!p?.error&&!i?.disabled,h=c&&(p?.ready??!f)&&!p?.loading&&!p?.error&&!i?.disabled,g=m&&h,_=mi(e=>e.providers),v=p?.providers??_,y=mi(e=>e.currentProviderId),b=mi(e=>e.currentModelId),x=i?.selection.providerID??y,S=i?.selection.modelID??b,C=mi(e=>e.currentVariant),w=i?i.selection.variant:C,T=mi(e=>e.currentAgentName),E=i?i.selection.agent??void 0:T,D=mi(e=>e.settingsDefaultVariant),O=mi(e=>e.settingsDefaultAgent),k=mi(e=>e.setProvider),A=mi(e=>e.setSelectedProvider),j=mi(e=>e.setModel),M=mi(e=>e.setCurrentVariant),N=mi(e=>e.getCurrentModelVariants),P=mi(e=>e.setAgent),F=mi(e=>e.getCurrentProvider),I=mi(e=>e.getModelMetadata),L=mi(e=>e.getCurrentAgent),R=mi(e=>e.getVisibleAgents),z=Wp(p?.agents??R()),B=Z.useMemo(()=>z.filter(e=>e.mode===`primary`),[z]),V=Z.useRef(!1);Z.useEffect(()=>{V.current||!g||(V.current=!0,Ae(`ModelControls:ready`,{providers:v.length,agents:z.length,currentProviderId:x,currentModelId:S,currentAgentName:E}))},[z.length,g,E,S,x,v.length]);let H=Qr(e=>i?null:e.currentSessionId),U=Qr(e=>e.getDirectoryForSession),W=zl(),ee=Bt(e=>e.getSessionModelSelection),G=Bt(e=>e.saveSessionModelSelection),K=Bt(e=>e.saveSessionAgentSelection),te=Bt(e=>e.saveAgentModelForSession),ne=Bt(e=>e.getAgentModelForSession),re=Bt(e=>e.saveAgentModelVariantForSession),ie=Bt(e=>e.getAgentModelVariantForSession),ae=Up(e=>e.hasHydrated),oe=Bt(e=>H?e.sessionAgentSelections.get(H)??null:null),se=Z.useRef(null);Z.useEffect(()=>{if(!H){se.current=null;return}oe&&(se.current=oe)},[H,oe]);let ce=H?se.current:null,le=i?i.selection.agent??void 0:H&&(oe||ce)||E,ue=s(e=>e.toggleFavoriteModel),de=s(e=>e.reorderFavoriteModel),fe=s(e=>e.providerOrder),pe=s(e=>e.setProviderOrder),me=s(e=>e.isFavoriteModel),he=s(e=>e.addRecentModel),ge=s(e=>e.addRecentAgent),_e=s(e=>e.addRecentEffort),ve=s(e=>e.isModelSelectorOpen),ye=s(e=>e.setModelSelectorOpen),be=s(e=>e.isAgentSelectorOpen),xe=s(e=>e.setAgentSelectorOpen),Se=s(e=>e.isModelSelectorInstant),Ce=s(e=>e.isAgentSelectorInstant),we=s(e=>e.setSettingsDialogOpen),Te=s(e=>e.setSettingsPage),Ee=s(e=>e.hiddenModels),De=s(e=>e.shortcutOverrides.cycle_agent),Oe=Z.useMemo(()=>Ya(`cycle_agent`,De?{cycle_agent:De}:void 0),[De]),{favoriteModelsList:ke,recentModelsList:je}=ga({currentProviderID:x,currentModelID:S}),{isMobile:Me}=fo(),Ne=s(e=>e.isMobile),Pe=Me||Ne,Fe=ko(),Ie=Pe,[Le,Re]=Z.useState(null),ze=n!==void 0&&typeof r==`function`,Be=ze?n:Le,Ve=ze?r:Re,He=q(e=>{Ve(e),mi.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),Ue=q((e,t)=>{if(qp(e,t?.reason)){t?.cancel?.();return}xe(e),e&&mi.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopAgentMenu`})}),[We,Ge]=Z.useState(null),Ke=Z.useRef(!1),qe=Z.useCallback(()=>Ve(null),[Ve]),Je=Z.useCallback(()=>Ge(null),[]),Ye=Z.useRef(void 0),Xe=ve,Ze=ye,Qe=Z.useCallback(()=>{A(bm),Te(`providers`),we(!0),Ze(!1),qe()},[A,Te,we,Ze,qe]),[$e,et]=Z.useState(``),[tt,nt]=Z.useState(null),[rt,it]=Z.useState(!1),at=Z.useRef(0),st=q((e,t)=>{if(qp(e,t?.reason)){t?.cancel?.();return}it(!1),e||(at.current=performance.now()+200,nt(null),et(``)),Ze(e),e&&mi.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),ct=Z.useRef(!1),lt=Z.useRef(null),ut=Z.useRef(void 0),[dt,ft]=Z.useState(new Map),[mt,ht]=Z.useState(new Set),[gt,_t]=Z.useState(0),vt=Z.useCallback(()=>{let e=()=>{let e=s.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&Yp(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),yt=Z.useCallback(e=>{let t=s.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(s.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!s.getState().isMobile&&vt())},[vt]),bt=Z.useCallback(()=>{let e=s.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Jp(t)},[t]),xt=Z.useRef(ve);Z.useEffect(()=>{let e=xt.current;xt.current=ve,ve||(et(``),ct.current=!1,lt.current=null,ft(new Map),ht(new Set),e&&!Ie&&(it(!1),at.current=performance.now()+200))},[ve,Ie]);let[St,Ct]=Z.useState(``);Z.useEffect(()=>{be||Ct(``)},[be]);let wt=Z.useMemo(()=>z.filter(e=>er(e.mode)),[z]),Tt=Z.useMemo(()=>St.trim()?Dr(wt,St.trim(),e=>[e.name,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(()=>le?z.find(e=>e.name===le):L?.(),[z,L,le]),Ot=Pe?`mobile`:Fe?`vscode`:`default`,kt=Ot===`mobile`?`size-5`:`size-4`,At=Ie?`typography-micro`:`typography-meta`,jt=Ot===`mobile`?`gap-x-1`:Ot===`vscode`?`gap-x-2`:`gap-x-1.5`,Mt=Ot===`mobile`?`h-8 w-8`:Ot===`vscode`?`h-5 w-5`:`h-6 w-6`,Nt=Ot===`mobile`?18:Ot===`vscode`?14:16,Pt=Ep(le),Ft=i?v.find(e=>e.id===x):F(),It=Array.isArray(Ft?.models)?Ft.models:[],Lt=S?It.find(e=>e.id===S):void 0,Rt=x&&S&&Lt?va(x,Lt,I(x,S)):x&&S?I(x,S):void 0,zt=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(()=>Tm(Rt).map(e=>({...e,label:zt(e.label)})),[Rt,zt]),Ht=Z.useMemo(()=>gm(Rt,`input`).map(e=>({...e,label:zt(e.label)})),[Rt,zt]),Ut=Z.useMemo(()=>gm(Rt,`output`).map(e=>({...e,label:zt(e.label)})),[Rt,zt]),Wt=Z.useMemo(()=>{if(p?.variantsReady===!1)return[];if(p?.variants)return[...p.variants];if(x&&S){let e=v.find(e=>e.id===x)?.models?.find(e=>e.id===S);return Zp(e)}return i?[]:N()},[S,x,N,v,i,p?.variants,p?.variantsReady]),Gt=Wt.length>0,Kt=[{label:`Input`,value:wm(Rt?.cost?.input)},{label:`Output`,value:wm(Rt?.cost?.output)},{label:`Cache read`,value:wm(Rt?.cost?.cache_read)},{label:`Cache write`,value:wm(Rt?.cost?.cache_write)}],qt=[{label:`Context`,value:Cm(Rt?.limit?.context)},{label:`Output`,value:Cm(Rt?.limit?.output)}],Jt=Z.useRef(void 0),Yt=Z.useRef(null),Xt=Z.useRef(null),Zt=H?U(H):void 0,Qt=pt(H??``,Zt??void 0).renderable,en=Di(H??``,Zt??void 0),tn=Z.useMemo(()=>{for(let e=en.length-1;e>=0;--e){let t=en[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},[en]),nn=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&&(G(H,e,t),n&&te(H,n,e,t)),`applied`):`model-missing`:`provider-missing`},[v,x,S,k,j,H,te,G]),rn=Z.useCallback((e,t)=>{if(i&&i.selection.providerID===e&&i.selection.modelID===t)return Qp(i.selection,i.catalog,e,t);let n=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Zp(n)},[v,i,i?.selection.providerID,i?.selection.modelID,p?.variants,p?.variantsReady]),on=Z.useCallback((e,t)=>{let n=i?Qp(i.selection,i.catalog,e,t):[],r=n.length>0?n:rn(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=le||E;if(H&&a){let n=ie(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,ie,rn,i,D,le]),sn=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=mi.getState().currentAgentName;return H?Bt.getState().getSessionAgentSelection(H)||se.current||e||E:e||E},[E,H,i]),cn=Z.useCallback((e,t,n,r)=>{if(i){i.onChange({...i.selection,providerID:e,modelID:t,variant:n}).catch(()=>void 0);return}if(rn(e,t).length===0){Ke.current=!1,M(void 0);return}Ke.current=!0,M(n),_e(e,t,n);let a=r??sn();H&&a&&re(H,a,e,t,n)},[_e,H,rn,sn,re,i,M]),ln=Z.useCallback((e,t,n,r)=>{let a=r??sn()??void 0,o=nn(e,t,a);if(o!==`applied`)return o;cn(e,t,n,a);let s=i?n:mi.getState().currentVariant;return he(e,t,s),`applied`},[he,cn,sn,i,nn]);Z.useEffect(()=>{if(i)return;if(!H){Xt.current=null;return}if(!ae||v.length===0||!Qt||!tn?.providerID||!tn.modelID)return;let e=[H,tn.id,tn.agent??``,tn.providerID,tn.modelID,tn.variant??``].join(`|`);if(Xt.current===e)return;tn.agent&&E!==tn.agent&&P(tn.agent);let t=tn.variant&&rn(tn.providerID,tn.modelID).includes(tn.variant)?tn.variant:void 0;ln(tn.providerID,tn.modelID,t,tn.agent||E||void 0)===`applied`&&(tn.agent&&(K(H,tn.agent),re(H,tn.agent,tn.providerID,tn.modelID,t)),G(H,tn.providerID,tn.modelID),Xt.current=e)},[i,H,E,ae,v,Qt,tn,P,ln,rn,K,re,G]),Z.useEffect(()=>{if(i)return;if(!H){Xt.current=null;return}if(!ae||v.length===0||z.length===0)return;let e=()=>{let e=ee(H),t=H?Bt.getState().getSessionAgentSelection(H):null;if(t){E!==t&&P(t);let e=ne(H,t);if(e){let n=nn(e.providerId,e.modelId,t);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}}if(e){let n=nn(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=ne(H,e.name);if(!t)continue;E!==e.name&&P(e.name),Bt.getState().getSessionAgentSelection(H)||se.current||K(H,e.name);let n=nn(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?Bt.getState().getSessionAgentSelection(H)||se.current:null,t=(H?Bt.getState().getSessionAgentSelection(H)||se.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||K(H,n.name),E!==n.name&&P(n.name),n.model?.providerID&&n.model?.modelID&&nn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!Qt){W.isLoading(H)||W.ensureSessionRenderable(H);return}tn||t()}},[i,H,Qt,tn,z,B,E,ee,ne,P,nn,K,ae,v,W]),Z.useEffect(()=>{if(i||!ae)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=ne(H,E);if(n){let e=nn(n.providerId,n.modelId,E);if(e===`applied`||e===`provider-missing`)return}let r=mi.getState().getAgentModelSelection(E);if(r){let e=nn(r.providerId,r.modelId,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(G(H,r.providerId,r.modelId),te(H,E,r.providerId,r.modelId),r.variant!==void 0&&(re(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=nn(i.model.providerID,i.model.modelID,E);if(e===`applied`||e===`provider-missing`){e===`applied`&&(G(H,i.model.providerID,i.model.modelID),te(H,E,i.model.providerID,i.model.modelID));return}}}}catch(e){console.error(`[ModelControls] Agent change error:`,e)}})(),()=>{e.abort()}},[i,z,E,H,ne,te,re,G,M,nn,ae]),Z.useEffect(()=>{if(i)return;if(!ae||!E){Ke.current=!1,M(void 0);return}if(!x||!S){Ke.current=!1,M(void 0);return}if(Wt.length===0){Ke.current=!1,M(void 0);return}if(w&&!Wt.includes(w)){M(void 0);return}if(!H){if(!w&&!Ke.current){let e=D&&Wt.includes(D)?D:void 0;M(e)}return}let e=ie(H,E,x,S),t=e&&Wt.includes(e)?e:D&&Wt.includes(D)?D:void 0;M(t),Ke.current=!1},[i,Wt,ae,H,E,x,S,w,ie,M,D]),Z.useEffect(()=>{Ke.current=!1},[x,S]);let un=Z.useCallback((e,t)=>{if(i){let n=sr(i.selection,e,z,v),r=n.providerID===i.selection.providerID&&n.modelID===i.selection.modelID;Ie&&qe(),i.onChange({...n,variant:r?i.selection.variant:void 0}).then(()=>{ge(e),(t?.closeModelSelector??!0)&&Ze(!1)}).catch(()=>void 0);return}try{Yt.current=e,P(e),ge(e),(t?.closeModelSelector??!0)&&Ze(!1),H&&K(H,e),Ie&&qe()}catch(e){console.error(`[ModelControls] Handle agent change error:`,e)}},[ge,z,qe,H,Ie,v,K,i,P,Ze]),dn=Z.useCallback(e=>{let t=$t(z,E,e);t&&un(t,{closeModelSelector:!1})},[z,E,un]),fn=Z.useCallback(e=>{let t=Oe&&!Oe.includes(`shift`)?Xa(`shift+${Oe}`):``;return t&&Va(e,t)?-1:Va(e,Oe)?1:null},[Oe]),pn=Z.useCallback(e=>{let t=fn(e);t&&(e.preventDefault(),e.stopPropagation(),dn(t))},[fn,dn]),mn=Z.useCallback((e,t,n,r)=>{!e||!t||!n||mi.getState().saveAgentModelSelection(e,t,n,r)},[]),hn=(e,t,n)=>{let r=()=>{Ze(!1,n?.closeInstant?{instant:!0}:void 0)};if(i){Ie&&qe();let a=n?.applyVariant?n.variant:on(e,t);i.onChange({providerID:e,modelID:t,agent:n?.agentName??i.selection.agent,variant:a}).then(()=>{he(e,t,a),r()}).catch(()=>void 0);return}try{let i=n?.agentName??sn()??void 0,a=n?.applyVariant?ln(e,t,n.variant,i):nn(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}mn(i,e,t,n?.applyVariant?n.variant:mi.getState().currentVariant),n?.applyVariant||he(e,t,mi.getState().currentVariant),r(),Ie&&qe()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},gn=(e,t)=>Dn(e,t,{maxLength:40}),_n=()=>v.find(e=>e.id===x)?.name||x,vn=()=>{if(!S)return a(`chat.modelControls.selectModel`);let e=It.find(e=>e.id===S);return gn(e,S)||a(`chat.modelControls.selectModel`)},yn=vn(),J=Z.useRef(null),bn=Kp(J,[yn,w,Ie]),xn=()=>{if(!le){let e=B.find(e=>e.name===`build`)||B[0];return e?Sn(e.name):`Select Agent`}let e=z.find(e=>e.name===le);return Sn(e?e.name:le)},Sn=e=>e.charAt(0).toUpperCase()+e.slice(1),Cn=Z.useCallback(e=>{Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ge(e)},500)},[]),wn=Z.useCallback(()=>{Ye.current&&clearTimeout(Ye.current)},[]);Z.useEffect(()=>()=>{Ye.current&&clearTimeout(Ye.current)},[]);let Tn=()=>!Ie||We!==`model`?null:(0,$.jsx)(Sp,{open:!0,onClose:Je,title:Rt?.name||vn(),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:_n()})]}),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)(xm,{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)(xm,{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)(xm,{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:Cm(Rt?.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:Cm(Rt?.limit?.output)})]})]})]}),Rt?.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:Em(Rt.release_date)})]})})]}):null]})}),En=()=>{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=dm(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=fm(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)(Sp,{open:!0,onClose:Je,title:Sn(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)(Sm,{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)(Sm,{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)(Sm,{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`})]})})]})})},On=()=>Ie?(0,$.jsx)(oo,{open:Be===`model`||Be===`variant`,view:Be===`variant`?`variant`:`model`,onViewChange:e=>Ve(e),onClose:qe,selectedProviderID:x||``,selectedModelID:S||``,resolveSelectedVariant:on,onSelect:(e,t,n)=>{if(i){qe(),i.onChange({providerID:e,modelID:t,agent:i.selection.agent,variant:n}).then(()=>{he(e,t,n)}).catch(()=>void 0);return}let r=ln(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}mn(sn(),e,t,n),qe()},providers:v,favoriteModels:ke,recentModels:je,hiddenModels:Ee,providerOrder:fe,isFavorite:me,onToggleFavorite:(e,t)=>ue(e,t,e===x&&t===S?w:ke.find(n=>n.providerID===e&&n.modelID===t)?.variant??je.find(n=>n.providerID===e&&n.modelID===t)?.variant),getMetadata:I}):null,kn=()=>Ie?(0,$.jsx)(Qa,{id:`mobile-agent-picker-sheet-${o}`,open:Be===`agent`,onOpenChange:e=>{e||qe()},ariaLabel:a(`chat.modelControls.selectAgent`),closeAriaLabel:a(`mobile.surface.closeAria`),resizeAriaLabel:a(`mobile.sessions.sheet.resizeAria`),bodyClassName:`px-2`,children:(0,$.jsx)(fa,{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===le,n=$i(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:()=>un(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)(ea,{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:Sn(e.name)}),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,An=()=>(0,$.jsx)(La,{align:`start`,sideOffset:8,className:`max-w-[320px]`,children:Rt?(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:Rt.name||vn()}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:_n()})]}),(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)(xm,{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)(xm,{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)(xm,{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))]}),Rt.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:Em(Rt.release_date)})]})]}):null]}):(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.metadataUnavailable`)})}),jn=()=>{let e=(e,t)=>{if(ct.current=!0,e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return!1;let{providerID:n,modelID:r}=t,i=rn(n,r);if(i.length===0)return!1;e.preventDefault(),e.stopPropagation();let a=lm(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}),ht(e=>{let t=new Set(e);return t.add(a),t}),_t(e=>e+1),!0},t=(t,n)=>{let r=fn(t);if(r){t.preventDefault(),dn(r);return}n&&e(t,n)},n=e=>{let t=lm(e.providerID,e.modelID),n=dt.get(t),r=mt.has(t),i=sn();if(r){hn(e.providerID,e.modelID,{applyVariant:!0,variant:n,agentName:i});return}let a=rn(e.providerID,e.modelID),o=e.variant!==void 0&&a.includes(e.variant)?e.variant:void 0;if(o!==void 0){hn(e.providerID,e.modelID,{applyVariant:!0,variant:o,agentName:i});return}hn(e.providerID,e.modelID,{agentName:i})},r=e=>{let t=fn(e);t&&(e.preventDefault(),e.stopPropagation(),ct.current=!0,dn(t))},i=e=>e?.trim()?an(e):a(`chat.modelControls.default`),o=(e,t)=>{let n=sn();hn(e.providerID,e.modelID,{applyVariant:!0,variant:t,agentName:n,closeInstant:!0})},s=e=>{e&&(Xe||performance.now()<at.current)||it(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`)},l=(e,{isSelected:t})=>{let n=rn(e.providerID,e.modelID);if(n.length===0)return null;let r=lm(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=mt.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(),nt(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(!tt)return null;let e=rn(tt.providerID,tt.modelID),t=lm(tt.providerID,tt.modelID),n=dt.has(t),r=dt.get(t),s=tt.providerID===x&&tt.modelID===S,c=tt.variant!==void 0&&e.includes(tt.variant)?tt.variant:void 0,l=n?r:s?w:c,u=Dn(tt.model,tt.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(),nt(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:()=>nt(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)(Ea,{modelId:tt.modelID,providerId:tt.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(tt,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)(dp,{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?an(w):null;return(0,$.jsxs)(Ra,{open:!Xe&&rt,onOpenChange:s,delayDuration:200,children:[Ie?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>He(`model`):void 0,onTouchStart:m?()=>Cn(`model`):void 0,onTouchEnd:m?wn:void 0,onTouchCancel:m?wn:void 0,disabled:!m,className:Y(`model-controls__model-trigger min-w-0 focus:outline-none`,m?Y(`cursor-pointer`,jp):`opacity-60 cursor-not-allowed`),children:m?(0,$.jsxs)($.Fragment,{children:[x||S?(0,$.jsx)(Ea,{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`,{ref:J,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:Y(`inline-flex min-w-0 items-center gap-1`,bn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:yn}),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:u})]})}):(0,$.jsxs)(Ua,{open:m&&Xe,onOpenChange:m?st:void 0,onOpenChangeComplete:e=>{e||yt(`model`)},children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,jp),children:[m?x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ea,{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:u})]}),m&&(0,$.jsx)(`span`,{ref:J,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:Y(`inline-flex min-w-0 items-center gap-1`,bn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:yn}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})},`${x}-${S}-${w??``}`)]})})}),(0,$.jsx)(Ka,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,Se&&um),align:`end`,alignOffset:-40,onKeyDownCapture:r,finalFocus:bt,children:tt?d():(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`p-1 border-b border-border/40`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:Qe,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)(pa,{providers:v,favoriteModels:ke,recentModels:je,getMetadata:I,searchQuery:$e,onSearchQueryChange:et,onSelect:n,labels:c,selectedModel:x&&S?{providerID:x,modelID:S}:null,hiddenModels:Ee,onActiveKeyDown:t,onActiveEntryChange:e=>{ut.current=e},onVariantKey:e,isFavorite:e=>me(e.providerID,e.modelID),onToggleFavorite:e=>ue(e.providerID,e.modelID,e.providerID===x&&e.modelID===S?w:e.variant),renderRowEnd:l,renderVersion:gt,onReorderFavorite:(e,t)=>de(e.providerID,e.modelID,t.providerID,t.modelID),reorderFavoriteAriaLabel:a(`chat.modelControls.reorderFavoriteAria`),reorderFavoriteTitle:a(`chat.modelControls.reorderFavoriteTitle`),providerOrder:fe,onReorderProvider:pe,reorderProviderTitle:a(`chat.modelControls.reorderProviderTitle`),footerContent:e=>{let t=e?rn(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:Xe&&!tt,onEscape:()=>{if(tt){nt(null);return}Ze(!1)}})]})})]}),An()]})},Mn=()=>{if(!Dt)return(0,$.jsx)(La,{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=dm(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=fm(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)(La,{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:Sn(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)(Sm,{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)(Sm,{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)(Sm,{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`})]})]})})},Nn=()=>{let e=xn(),t=le?$i(le):null;return Ie?(0,$.jsx)(`button`,{type:`button`,onClick:h?()=>He(`agent`):void 0,onTouchStart:h?()=>Cn(`agent`):void 0,onTouchEnd:h?wn:void 0,onTouchCancel:h?wn:void 0,disabled:!h,className:Y(`model-controls__agent-trigger inline-flex items-center flex-shrink-0 min-w-0 focus:outline-none`,Mp,h?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:h?(0,$.jsx)(Tp,{name:le,label:e,revealed:Pt,avatarSize:Nt,slotClassName:Mt,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)(Ra,{delayDuration:600,children:[(0,$.jsxs)(Ua,{open:h&&be,onOpenChange:h?Ue:void 0,onOpenChangeComplete:e=>{e||yt(`agent`)},children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,Mp),children:h?(0,$.jsx)(Tp,{name:le,label:e,revealed:Pt,avatarSize:Nt,slotClassName:Mt,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)(Ka,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,Ce&&um),onKeyDownCapture:pn,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)(Fa,{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(),xe(!1);return}e.stopPropagation()},className:`pl-8 h-8 typography-meta`})]})}),(0,$.jsx)(fa,{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)(ao,{className:`typography-meta`,onSelect:()=>un(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)(Ga,{})]}),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)(ao,{className:`typography-meta`,onSelect:()=>un(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)(ea,{name:e.name,size:14}),(0,$.jsx)(`span`,{className:`font-medium`,children:Sn(e.name)})]}),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)(dp,{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`)})]})]})]}),Mn()]})})},Pn=Y(`@container/model-controls flex items-center min-w-0`,Pe&&`w-full`,e),Fn=Nn();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Pn,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center min-w-0 flex-1 justify-end`,jt,Pe&&`overflow-hidden`),children:[Fn,jn()]})}),On(),kn(),Tn(),En()]})},Om=[{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`}],km=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=ot(),i=bl(Am),a=s(jm),o;t[0]===a?o=t[1]:(o=Wa(Ya(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let c=o;if(!i)return null;let l;t[2]===r?l=t[3]:(l=r(`chat.leaderKey.pendingAria`),t[2]=r,t[3]=l);let u;t[4]===n?u=t[5]:(u=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]=u);let d;t[6]===c?d=t[7]:(d=(0,$.jsx)(fp,{shortcut:c,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]=c,t[7]=d);let f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}),t[8]=f):f=t[8];let p;t[9]===r?p=t[10]:(p=Om.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)(dp,{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]=p);let m;return t[11]!==l||t[12]!==u||t[13]!==d||t[14]!==p?(m=(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":l,className:u,children:[d,f,p]}),t[11]=l,t[12]=u,t[13]=d,t[14]=p,t[15]=m):m=t[15],m};function Am(e){return e.pending}function jm(e){return e.shortcutOverrides}var Mm=28,Nm=8,Pm=10.5,Fm=Math.PI/2,Im=e=>Array.from({length:Nm},(t,n)=>{let r=n/Nm*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*Pm,Math.sin(r)*Pm]}),Lm=[Im(0),Im(Fm),Im(Math.PI),Im(Math.PI*1.5)],Rm=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,zm=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(`oc-morph-orb-glyph shrink-0`,i),t[0]=i,t[1]=o);let s=a/Mm,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:`oc-morph-orb-stage`,children:Lm[0].map(Bm)}),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 Bm(e,t){return(0,$.jsx)(`span`,{className:`oc-morph-orb-dot`,style:{"--m-1":Rm(Lm[0][t]),"--m-2":Rm(Lm[1][t]),"--m-3":Rm(Lm[2][t]),"--m-4":Rm(Lm[3][t])}},t)}var Vm=1200,Hm=600,Um=1e9,Wm=0xe8d4a51000,Gm=e=>e>=Wm?e:e>=Um?e*1e3:Date.now()+e;function Km({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o}){let{locale:s,t:c}=ot(),[l,u]=Z.useState(null),[d,f]=Z.useState(!1),p=Z.useRef(l),m=Z.useRef(d),h=Z.useRef(!1);p.current=l,m.current=d;let g=Z.useRef(0),_=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),[b,x]=Z.useState(null),[S,C]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;C(Date.now());let t=window.setInterval(()=>C(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){x(null);return}let t=Gm(e),n=()=>{let e=Math.max(0,t-Date.now());x(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let w=q(()=>{v.current&&=(clearTimeout(v.current),null),y.current&&=(clearTimeout(y.current),null)}),T=q((e,t,n=!1)=>{w(),_.current=null,u(e),f(t),h.current=n,g.current=Date.now()}),E=q(()=>{if(v.current)return;let e=Date.now()-g.current,t=Math.max(0,Vm-e);v.current=setTimeout(()=>{v.current=null;let e=_.current;e&&T(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(!e){if(v.current&&=(clearTimeout(v.current),null),_.current=null,!p.current||y.current)return;y.current=setTimeout(()=>{y.current=null,u(null),f(!1),h.current=!1},Hm);return}if(y.current&&=(clearTimeout(y.current),null),a){w(),_.current=null;return}let t=i?c(`chat.assistantStatus.waitingForPermission`):n,o=!!i,s=!!r&&!o;if(t){if(!p.current){T(t,o,s);return}if((t!==p.current||o!==m.current)&&!(s&&h.current)){if(s){_.current={text:t,permission:o,generic:s},E();return}T(t,o,s)}}},[e,n,r,i,a,c]),Z.useEffect(()=>()=>w(),[]),!e&&!l)return null;if(a&&e){let e=b!==null&&b>0?new Intl.RelativeTimeFormat(s,{numeric:`always`,style:`short`}).format(b,`second`):null,n=e?a.attempt&&a.attempt>1?c(`chat.assistantStatus.retryingInAttempt`,{duration:e,attempt:a.attempt}):c(`chat.assistantStatus.retryingIn`,{duration:e}):a.attempt&&a.attempt>1?c(`chat.assistantStatus.retryingAttempt`,{attempt:a.attempt}):c(`chat.assistantStatus.retrying`);return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":n,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)(zm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:n})]})})}if(!l)return null;let D=l,O=typeof o==`number`&&e?mt(Math.max(0,S-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":d?`assertive`:`polite`,"aria-label":D,"data-waiting":d?`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)(zm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:D}),O?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:O}):null]})})}var qm={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Jm={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Ym={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:qm},Xm=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?qm:Jm}),Zm=Z.createContext(Ym),Qm=()=>Z.useContext(Zm),$m=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}),eh=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,th={containerType:`inline-size`,containerName:`status-row`},nh=[],rh=e=>{let t=(0,Q.c)(97),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:c,retryInfo:l,turnStartedAt:u,showAbortStatus:f,showAbortPrompt:p,showAssistantStatus:m,showTodos:h,agentName:g,leftAccessory:_}=e,v=n!==void 0&&n,y=r===void 0?null:r,b=p!==void 0&&p,x=m===void 0||m,S=h===void 0||h,{t:C}=ot(),[w,T]=Z.useState(!1),E=Qm(),D=Qr(ih),O=E.sessionId??D,k;t[0]!==O||t[1]!==S?(k=e=>!S||!O?nh:e.todo[O]??nh,t[0]=O,t[1]=S,t[2]=k):k=t[2];let A=Qn(k,E.directory??void 0),j;t[3]!==O||t[4]!==S?(j=e=>S&&O?e.sessions[O]?.todos:void 0,t[3]=O,t[4]=S,t[5]=j):j=t[5];let M=hr(j),N;bb0:{if(!O){N=nh;break bb0}if(A.length>0){N=A;break bb0}N=M??nh}let P=N,F=s(ah),I;t[6]===F?I=t[7]:(I=F||d(),t[6]=F,t[7]=I);let L=I,R;t[8]===P?R=t[9]:(R=P.filter(oh),t[8]=P,t[9]=R);let z=R,B;t[10]===z?B=t[11]:(B=z.find(sh)||z.find(ch)||null,t[10]=z,t[11]=B);let V=B,H;t[12]===z?H=t[13]:(H=z.find(lh)??null,t[12]=z,t[13]=H);let U=H,W;t[14]===P?W=t[15]:(W=P.filter(uh),t[14]=P,t[15]=W);let ee=W.length,G;t[16]===P?G=t[17]:(G=P.filter(dh),t[16]=P,t[17]=G);let K=G.length,te;t[18]!==K||t[19]!==ee?(te={completed:K,total:ee},t[18]=K,t[19]=ee,t[20]=te):te=t[20];let ne=te,re;t[21]===z?re=t[22]:(re=z.filter(fh),t[21]=z,t[22]=re);let ie=re.length,ae;t[23]===z?ae=t[24]:(ae=z.filter(ph),t[23]=z,t[24]=ae);let oe=ae.length,se;t[25]!==ie||t[26]!==oe?(se={active:ie,left:oe},t[25]=ie,t[26]=oe,t[27]=se):se=t[27];let ce=se,le=S&&ce.left>0,ue=!!b,[de,fe]=Z.useState(!1),pe,me;t[28]!==de||t[29]!==v?(pe=()=>{if(v){fe(!0);return}if(!de)return;let e=window.setTimeout(()=>fe(!1),600);return()=>window.clearTimeout(e)},me=[v,de],t[28]=de,t[29]=v,t[30]=pe,t[31]=me):(pe=t[30],me=t[31]),Z.useEffect(pe,me);let he=x&&(v||de||!!o||!!f),ge=!!_,_e=!f&&!ue&&(o||!c),ve=ue||he||le||ge,ye=Z.useRef(null),be=Z.useRef(null),xe=Z.useRef(null),Se,Ce;t[32]===w?(Se=t[33],Ce=t[34]):(Se=()=>{let e=be.current,t=xe.current;if(!w||!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))},Ce=[w],t[32]=w,t[33]=Se,t[34]=Ce),Z.useLayoutEffect(Se,Ce);let we,Te;t[35]===w?(we=t[36],Te=t[37]):(we=()=>{if(!w)return;let e=e=>{ye.current&&!ye.current.contains(e.target)&&T(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},Te=[w],t[35]=w,t[36]=we,t[37]=Te),Z.useEffect(we,Te);let Ee;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=()=>T(mh),t[38]=Ee):Ee=t[38];let De=q(Ee),Oe;t[39]!==ce.active||t[40]!==ce.left||t[41]!==C?(Oe=C(`chat.statusRow.summary.activeLeft`,{active:ce.active,left:ce.left}),t[39]=ce.active,t[40]=ce.left,t[41]=C,t[42]=Oe):Oe=t[42];let ke=Oe,Ae;t[43]!==V||t[44]!==le||t[45]!==L||t[46]!==w||t[47]!==ne||t[48]!==C||t[49]!==ke||t[50]!==De?(Ae=le?(0,$.jsxs)(`button`,{type:`button`,onClick:De,className:Y(Us,`shrink-0`),"aria-label":ke,title:ke,children:[(0,$.jsx)(X,{name:`list-check-3`,className:Ks}),!L&&V?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,nc),children:V.content}):(0,$.jsx)(`span`,{className:`text-xs leading-4 md:text-[0.8125rem] md:leading-5`,children:C(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:Vs,"aria-hidden":`true`,children:[ne.completed,`/`,ne.total]}),w?(0,$.jsx)(X,{name:`arrow-up-s`,className:Ks}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Ks})]}):null,t[43]=V,t[44]=le,t[45]=L,t[46]=w,t[47]=ne,t[48]=C,t[49]=ke,t[50]=De,t[51]=Ae):Ae=t[51];let je=Ae;if(!ve)return null;let Me=!ge&&`chat-column`,Ne;t[52]===Me?Ne=t[53]:(Ne=Y(`mb-1`,Me),t[52]=Me,t[53]=Ne);let Pe=ge&&`px-3`,Fe;t[54]===Pe?Fe=t[55]:(Fe=Y(`flex items-center justify-between py-0.5 gap-2 h-[1.2rem]`,Pe),t[54]=Pe,t[55]=Fe);let Ie=!ge&&`overflow-x-hidden`,Le;t[56]===Ie?Le=t[57]:(Le=Y(`flex-1 flex items-center min-w-0 gap-2`,Ie),t[56]=Ie,t[57]=Le);let Re;t[58]!==g||t[59]!==O||t[60]!==ue||t[61]!==i||t[62]!==F||t[63]!==a||t[64]!==v||t[65]!==_||t[66]!==l||t[67]!==_e||t[68]!==f||t[69]!==x||t[70]!==y||t[71]!==C||t[72]!==u?(Re=ue?(0,$.jsx)(`div`,{className:`flex min-w-0 items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":C(`chat.statusRow.abortPrompt`),children:(0,$.jsxs)(`span`,{className:Y(`flex min-w-0 items-center typography-ui-label`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`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:C(`chat.statusRow.abortPrompt`)})]})}):x&&f?(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`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`close-circle`,className:`size-3.5`,"aria-hidden":`true`})}),C(`chat.statusRow.aborted`)]})}):x&&_e?(0,$.jsx)(Km,{isWorking:v,isMobile:F,statusText:y,isGenericStatus:i,isWaitingForPermission:a,retryInfo:l,turnStartedAt:u,agentName:g},O??`no-session`):_||null,t[58]=g,t[59]=O,t[60]=ue,t[61]=i,t[62]=F,t[63]=a,t[64]=v,t[65]=_,t[66]=l,t[67]=_e,t[68]=f,t[69]=x,t[70]=y,t[71]=C,t[72]=u,t[73]=Re):Re=t[73];let ze;t[74]!==Le||t[75]!==Re?(ze=(0,$.jsx)(`div`,{className:Le,children:Re}),t[74]=Le,t[75]=Re,t[76]=ze):ze=t[76];let Be=!ge&&`-mr-3`,Ve;t[77]===Be?Ve=t[78]:(Ve=Y(`relative flex items-center gap-2 flex-shrink-0`,Be),t[77]=Be,t[78]=Ve);let He;t[79]!==U||t[80]!==le||t[81]!==w||t[82]!==ne||t[83]!==C||t[84]!==z?(He=w&&le&&(0,$.jsxs)(`div`,{style:Ws,className:Y(Xs,`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:C(`chat.statusRow.tasksTitle`)}),(0,$.jsxs)(`span`,{className:`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,children:[ne.completed,`/`,ne.total]})]}),(0,$.jsx)(`ul`,{ref:be,className:lc,children:z.map((e,t)=>(0,$.jsx)(dc,{todo:e,isActive:e===U,activeRef:e===U?xe:void 0},e.id??`todo-${t}`))})]}),t[79]=U,t[80]=le,t[81]=w,t[82]=ne,t[83]=C,t[84]=z,t[85]=He):He=t[85];let Ue;t[86]!==Ve||t[87]!==He||t[88]!==je?(Ue=(0,$.jsxs)(`div`,{className:Ve,ref:ye,children:[je,He]}),t[86]=Ve,t[87]=He,t[88]=je,t[89]=Ue):Ue=t[89];let We;t[90]!==Fe||t[91]!==ze||t[92]!==Ue?(We=(0,$.jsxs)(`div`,{className:Fe,children:[ze,Ue]}),t[90]=Fe,t[91]=ze,t[92]=Ue,t[93]=We):We=t[93];let Ge;return t[94]!==Ne||t[95]!==We?(Ge=(0,$.jsx)(`div`,{className:Ne,style:th,children:We}),t[94]=Ne,t[95]=We,t[96]=Ge):Ge=t[96],Ge};function ih(e){return e.currentSessionId}function ah(e){return e.isMobile}function oh(e){return e.status!==`cancelled`}function sh(e){return e.status===`in_progress`}function ch(e){return e.status===`pending`}function lh(e){return e.status===`in_progress`}function uh(e){return e.status!==`cancelled`}function dh(e){return e.status===`completed`}function fh(e){return e.status===`in_progress`}function ph(e){return e.status===`in_progress`||e.status===`pending`}function mh(e){return!e}var hh=Z.createContext(null),gh=e=>{let t=(0,Q.c)(3),{actions:n,children:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(hh.Provider,{value:n,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},_h=()=>Z.useContext(hh),vh=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),yh=e=>`insertions`in e,bh=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},xh=e=>{let t=0,n=0;for(let r of e.split(`
6521
+ `))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},Sh=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!vh.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:bh(i.additions)??void 0,deletions:bh(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:bh(e.additions)??void 0,deletions:bh(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:bh(i.additions)??void 0,deletions:bh(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=xh(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},Ch=(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:vo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},wh=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},Th=(e,t)=>_o(e,t),Eh=(e,t)=>{let n=yh(e)&&e.relativePath?e.relativePath:Th(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},Dh=e=>yh(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},Oh=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=ot(),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:Hs,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:qs,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:uc,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}=Eh(e,r),s=Dh(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`,Js),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(ku,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 flex items-baseline overflow-hidden`,title:e.path,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-foreground`,children:n})]})]}):(0,$.jsx)(`span`,{className:`truncate text-foreground`,children:n})}),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:lc,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},kh=`${Xs} origin-[var(--transform-origin)]`,Ah=Ws,jh=Z.memo(()=>{let e=(0,Q.c)(60),{t}=ot(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=is()??null,o=Z.useContext(Oo),c=Bs(a),l;e[0]===a?l=e[1]:(l=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=l);let u=ws(l),d=_h(),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||c!==!0||!u||u.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]!==u.diffStats||e[8]!==u.files?(t=Ch(u.files,u.diffStats,a),e[6]=a,e[7]=u.diffStats,e[8]=u.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||c!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!yh(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=s.getState(),c=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,c);return}i.navigateToDiff(e.relativePath,c),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,D;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(Us,`max-w-full text-left`),D=()=>r(Mh),e[25]=E,e[26]=D):(E=e[25],D=e[26]);let O,k;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(X,{name:`file-edit`,className:Ks}),O=Y(nc,`shrink-0`),e[27]=O,e[28]=k):(O=e[27],k=e[28]);let A;e[29]===T?A=e[30]:(A=(0,$.jsx)(`span`,{className:O,children:T}),e[29]=T,e[30]=A);let j;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(j=Y(`status-row__changed-label`,nc),e[31]=j):j=e[31];let M;e[32]===t?M=e[33]:(M=t(`chat.pendingChanges.changedInWorkspace`),e[32]=t,e[33]=M);let N;e[34]===M?N=e[35]:(N=(0,$.jsx)(`span`,{className:j,children:M}),e[34]=M,e[35]=N);let P;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(P=Y(Vs,`items-baseline gap-0.5`),e[36]=P):P=e[36];let F;e[37]===y?F=e[38]:(F=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,y]}):null,e[37]=y,e[38]=F);let I;e[39]===b?I=e[40]:(I=b>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,b]}):null,e[39]=b,e[40]=I);let L;e[41]!==F||e[42]!==I?(L=(0,$.jsxs)(`span`,{className:P,children:[F,I]}),e[41]=F,e[42]=I,e[43]=L):L=e[43];let R;e[44]===n?R=e[45]:(R=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:Ks}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Ks}),e[44]=n,e[45]=R);let z;e[46]!==n||e[47]!==A||e[48]!==N||e[49]!==L||e[50]!==R?(z=(0,$.jsxs)(`button`,{type:`button`,className:E,onClick:D,"aria-expanded":n,children:[k,A,N,L,R]}),e[46]=n,e[47]=A,e[48]=N,e[49]=L,e[50]=R,e[51]=z):z=e[51];let B;e[52]!==a||e[53]!==h||e[54]!==S||e[55]!==n?(B=n&&(0,$.jsx)(`div`,{style:Ah,className:Y(kh,`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)(Oh,{files:h,currentDirectory:a,onOpenFile:S})}),e[52]=a,e[53]=h,e[54]=S,e[55]=n,e[56]=B):B=e[56];let V;return e[57]!==z||e[58]!==B?(V=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[z,B]}),e[57]=z,e[58]=B,e[59]=V):V=e[59],V});jh.displayName=`PendingChangesBar`;function Mh(e){return!e}var Nh=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=ot(),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 oc-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`oc-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`&&`oc-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)(la,{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}),Ph=Z.createContext(`default`),Fh=()=>Z.useContext(Ph),Ih=500,Lh=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=Ci(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=Ep(d),h;t[5]===d?h=t[6]:(h=$i(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()},Ih))},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`,Mp,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)(Tp,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,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:Rh,onMouseDown:zh,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 Rh(e){return e.preventDefault()}function zh(e){return e.preventDefault()}var Bh=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}=ot(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=rr(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()?an(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)(Ea,{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:Vh,onPointerDownCapture:Hh,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 Vh(e){return e.preventDefault()}function Hh(e){e.preventDefault()}var Uh={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Wh=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function Gh(e,t){let n=(0,Q.c)(6),r=Tr(e??``,t),i=ei(e??``,t),a=Di(e??``,t),o=gi(e??``,t),s=ji(e??``,t),c=Fi(t),l;bb0:{if(!e){l=Uh;break bb0}if(o.length>0||s.length>0){l=Uh;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=Wh({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=Uh;break bb0}if(!y){l=Uh;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 Kh=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function qh(e){let t=(0,Q.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`path`,{d:`M200,40H56A16,16,0,0,0,40,56V200a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V56A16,16,0,0,0,200,40Z`}),t[0]=n):n=t[0];let r;return t[1]===e?r=t[2]:(r=(0,$.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,viewBox:`0 0 256 256`,...e,children:n}),t[1]=e,t[2]=r),r}var Jh=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Yh=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Xh=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Zh=(e,t)=>e.id===t.id&&e.directory===t.directory,Qh=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,$h=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Xh(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Zh(e.parentTarget,i)&&Qh(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},eg=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`}},tg=`data-mobile-overlay-active`,ng=e=>Array.from(e).some(e=>e.getAttribute(tg)!==`false`),rg=`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(`.`),ig=`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 ag(){return`${rg[Math.floor(Math.random()*rg.length)]}-${ig[Math.floor(Math.random()*ig.length)]}`}function og(e){let t=ag();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var sg=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,cg=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),lg=(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))},ug=async(e,t)=>{await Qi(e)&&await fi(t)},dg=e=>{let t=sg(e),n=jt.getState().projects;if(n.length===0)return null;let r=jt.getState().getActiveProject();if(r?.path){let e=sg(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=sg(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>sg(t.path).length-sg(e.path).length)[0];return i?{id:i.id,path:i.path}:null},fg=!1,pg=async(e,t)=>{try{let n=jt.getState().projects.find(e=>e.id===t.id)??jt.getState().projects.find(e=>sg(e.path)===sg(t.path)),r=mr(t.path);await mi.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=mi.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),lg(e,cg(mi.getState()),Bt.getState())}catch{}},mg=async(e,t,n)=>{let r=Qr.getState(),i=mi.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await pg(e,n),Te.getState().setDirectory(t.path,{showOverlay:!1})},hg=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,gg=async e=>{if(fg)return null;let t=jt.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return Cr.error(`No active project`,{description:`Please select a project first.`}),null;let r=dg(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return Cr.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await da(r.path)}catch{}if(!i)return Cr.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;fg=!0;try{let t=Oi(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?hg(n):og(),a=n?`existing`:`new`,o=Qr.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 ua(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(Qr.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Te.getState().setDirectory(s.path,{showOverlay:!1}));let c=await jn(r),l=await Ts(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return vr(t,l.path),Qr.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Te.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=Qr.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(Ur(n,e instanceof Error?e:Error(t)),Qr.getState().resolvePendingDraftWorktreeTarget(n,null)),Qr.getState().setDraftBootstrapPendingDirectory(null),Cr.error(`Failed to create worktree`,{description:t}),null}finally{fg=!1}};async function _g(){return gg()}async function vg(e){let t=e.branch?.trim();return t?gg({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function yg(e,t,n,r){if(fg)return null;fg=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=dg(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await da(s.path)}catch{}if(!c)return Cr.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await jn(s),u=await ka(s.path);try{let e=await Ts(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 ug(s,e.path);let n=await Qr.getState().createSession(void 0,e.path);if(!n)throw await ja(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await mg(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 Cr.error(`Failed to create worktree`,{description:t}),null}}finally{fg=!1}}var bg=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},xg=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 Sg({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=ot(),{github:a}=Do(),o=eo(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=s(e=>e.isMobile),{isTablet:p}=fo(),m=f||p,h=jt(e=>e.getActiveProject()),g=Te(e=>e.currentDirectory),_=Z.useMemo(()=>h?.path?.trim()||g?.trim()||null,[h?.path,g]),[v,y]=Z.useState(``),[b,x]=Z.useState(!1),[S,C]=Z.useState(null),w=Z.useRef(0),T=Z.useMemo(()=>bg(v),[v]),E=ys(v,350),D=T?``:E.trim(),O=!!T||v===E,k=e&&O&&!!_&&!!a?.issuesList&&!(l&&c?.connected===!1),A=Je({queryKey:I.scoped(`github-issues`,_,D),enabled:k,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(_,{page:e,...D?{query:D}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),j=O?A.data?.pages.at(-1)??null:null,M=O?A.data?.pages.flatMap(e=>e.issues??[])??[]:[],N=O&&A.hasNextPage,P=!T&&!O||A.isLoading,F=O&&A.isFetchingNextPage,L=O&&A.error?A.error instanceof Error?A.error.message:String(A.error):null,R=Z.useCallback(()=>A.refetch(),[A]),z=Z.useCallback(async()=>{try{await A.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Cr.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[A,i]);Z.useEffect(()=>{e||(++w.current,y(``),x(!1),C(null))},[e]),Z.useEffect(()=>{++w.current},[e,_]);let B=!l||c?.connected!==!1&&j?.connected!==!1,V=j?.repo?.url??null,H=Z.useCallback(()=>{d(`github`),u(!0)},[u,d]),U=Z.useCallback(()=>{let e=mi.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},[]),W=Z.useCallback(()=>{let e=mi.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Gn(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),ee=Z.useCallback((e,t)=>{let n=mi.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),G=Z.useCallback(async(e,o)=>{let s=++w.current,c=()=>w.current===s;if(n===`select`){if(!_){Cr.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Cr.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(S)return;C(e);try{let n=await a.issueGet(_,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Cr.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Cr.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){Cr.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){Cr.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=xg({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);Cr.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&C(null)}return}if(!_){Cr.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Cr.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!S){C(e);try{let n=await a.issueGet(_,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Cr.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Cr.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){Cr.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){Cr.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(b){let e=`issue-${r.number}-${ag()}`,t=await yg(_,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 Un(u,_,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??_}})();if(!c())return;ui(d,u).catch(()=>void 0);try{Qr.getState().initializeNewOpenChamberSession(d,mi.getState().agents)}catch{}t(!1);let f=mi.getState(),p=Bt.getState().lastUsedProvider,m=W(),h=m?.providerID||f.currentProviderId||p?.providerID,g=m?.modelID||f.currentModelId||p?.modelID,v=U()||f.currentAgentName||void 0;if(!h||!g){Cr.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let y=ee(h,g),x=await On(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await On(`github.issue.review.instructions`);if(!c())return;let C=xg({repo:n.repo,issue:r,comments:l});Qr.getState().sendMessage(x,h,g,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],y,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);Cr.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),Cr.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Cr.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&C(null)}}},[b,a,n,t,r,_,U,W,ee,S,i]),K=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)(Fa,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:v,onChange:e=>{y(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(f?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[_?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`)}),P?(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,B===!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)(la,{variant:`outline`,size:`sm`,onClick:H,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,L?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:L}):null,T&&_&&a&&B?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,S===T&&`bg-interactive-selection/30`),onClick:()=>void G(T),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:T})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:S===T?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,M.length===0&&!P&&!L&&B&&a&&_?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:E.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,M.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`,S===e.number&&`bg-interactive-selection/30`),onClick:()=>void G(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:S===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`,m?`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}`)),N&&B&&_&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void z(),disabled:F||!!S,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(F||!!S)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:F?(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":b,onClick:()=>x(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),x(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),x(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:b?(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:[V?(0,$.jsx)(la,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:V,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(la,{variant:`outline`,size:`sm`,onClick:R,disabled:P||!!S,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return f?(0,$.jsx)(Sp,{open:e,title:K,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:K}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:te})]}),children:ne}):(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(na,{className:`flex-shrink-0`,children:[(0,$.jsxs)(aa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),K]}),(0,$.jsx)(oa,{children:te})]}),ne]})})}var Cg=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},wg=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function Tg({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),{github:i}=Do(),a=eo(),o=a.data??null,c=a.isFetched,l=s(e=>e.setSettingsDialogOpen),u=s(e=>e.setSettingsPage),d=s(e=>e.isMobile),{isTablet:f}=fo(),p=d||f,m=jt(e=>e.getActiveProject())?.path??null,[h,g]=Z.useState(``),[_,v]=Z.useState(!1),[y,b]=Z.useState(null),x=Z.useRef(0),S=Z.useMemo(()=>Cg(h),[h]),C=ys(h,350),w=S?``:C.trim(),T=!!S||h===C,E=e&&T&&!!m&&!!i?.prsList&&!(c&&o?.connected===!1),D=Je({queryKey:I.scoped(`github-prs`,m,w),enabled:E,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(m,{page:e,...w?{query:w}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),O=T?D.data?.pages.at(-1)??null:null,k=T?D.data?.pages.flatMap(e=>e.prs??[])??[]:[],A=T&&D.hasNextPage,j=!S&&!T||D.isLoading,M=T&&D.isFetchingNextPage,N=T&&D.error?D.error instanceof Error?D.error.message:String(D.error):null,P=q(async()=>{try{await D.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Cr.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++x.current,g(``),v(!1),b(null))},[e]),Z.useEffect(()=>{++x.current},[e,m]);let F=!c||o?.connected!==!1&&O?.connected!==!1,L=q(()=>{u(`github`),l(!0)}),R=q(async(e,a)=>{if(!m){Cr.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){Cr.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(y)return;let o=++x.current,s=()=>x.current===o;b(e);try{let o=await i.prContext(m,e,{includeDiff:_,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){Cr.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){Cr.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){Cr.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await On(`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:_,instructionsText:e,contextText:wg(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);Cr.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&b(null)}}),z=r(`session.githubPrPicker.title`),B=r(`session.githubPrPicker.description`),V=(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)(Fa,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:h,onChange:e=>{g(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":_,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ha,{checked:_,onChange:e=>v(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(d?`min-h-0`:`flex-1 overflow-y-auto`),children:[m?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`)}),j?(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,F===!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)(la,{variant:`outline`,size:`sm`,onClick:L,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,N?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:N}):null,S&&m&&i&&F?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,y===S&&`bg-interactive-selection/30`),onClick:()=>void R(S),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:S})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:y===S?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,k.length===0&&!j&&!N&&F&&i&&m?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:C.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,k.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`,y===e.number&&`bg-interactive-selection/30`),onClick:()=>void R(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:y===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":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}`)),A&&F&&m&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:M||!!y,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(M||!!y)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:M?(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 d?(0,$.jsx)(Sp,{open:e,title:z,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:z}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:B})]}),children:V}):(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(na,{className:`flex-shrink-0`,children:[(0,$.jsxs)(aa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),z]}),(0,$.jsx)(oa,{children:B})]}),V]})})}function Eg(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)(fc,{"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 Dg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(11),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a,o;n[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=Y(`flex h-8 items-center gap-2 rounded-lg px-3`,`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)]`),o=(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 opacity-50`}),n[3]=a,n[4]=o):(a=n[3],o=n[4]);let s;n[5]===r?s=n[6]:(s=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[5]=r,n[6]=s);let c;return n[7]!==i||n[8]!==t||n[9]!==s?(c=(0,$.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1.5 pb-1`,children:(0,$.jsxs)(`div`,{"data-slot":`command-input-field`,className:a,children:[o,(0,$.jsx)(fc.Input,{ref:t,"data-slot":`command-input`,className:s,...i})]})}),n[7]=i,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});Dg.displayName=`CommandInput`;function Og(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)(fa,{as:fc.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 kg(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)(fc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function Ag(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)(fc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function jg(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)(fc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Mg(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)(fc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Ng=(e,t)=>`${e}:${T(t)}`,Pg=e=>e.type===`skill`||!se(e.name);function Fg(e){let{t}=ot(),n=Z.useMemo(()=>d(),[]),r=s(e=>e.globalDraftStarters),i=jt(e=>e.activeProjectId),a=jt(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]),[c,l]=Z.useState([]),u=Z.useMemo(()=>r??ce,[r]),f=u.some(Pg)||c.some(Pg),m=Vn({directory:e,enabled:f}),h=Z.useMemo(()=>m.data??[],[m.data]),{refetch:g}=m,_=ti({directory:e,enabled:f}),v=Z.useMemo(()=>_.data??[],[_.data]),{refetch:y}=_;Z.useEffect(()=>{let e=!1;if(!o){l([]);return}return un(o).then(t=>{e||l(t)}).catch(()=>{e||l([])}),()=>{e=!0}},[o?.id]);let b=Z.useCallback(()=>{g(),y()},[g,y]),x=Z.useMemo(()=>new Set(h.map(e=>e.name)),[h]),S=Z.useMemo(()=>new Set(v.map(e=>e.name)),[v]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=se(e.name);return n?{id:Ng(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:x.has(e.name)?{id:Ng(r,e),ref:e,group:r,label:w(e.name),icon:ae,submitText:`/${e.name}`}:null}return S.has(e.name)?{id:Ng(r,e),ref:e,group:r,label:w(e.name),icon:P,submitText:`/${e.name}`}:null},[t,x,S,n]),E=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),D=Z.useMemo(()=>c.map(e=>C(e,`project`)).filter(e=>e!==null),[c,C]),O=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(T(t));for(let t of c)e.add(T(t));return e},[u,c]),k=Z.useMemo(()=>{let e=[];for(let r of M)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 h)t.isBuiltIn||t.source===`skill`||se(t.name)||e.push({type:`command`,name:t.name,label:w(t.name),icon:ae,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of v)e.push({type:`skill`,name:t.name,label:w(t.name),icon:P,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!O.has(`${e.type}:${e.name}`))},[t,h,v,O,n]),A=Z.useCallback(e=>{s.getState().setGlobalDraftStarters(e),te({draftStarters:e})},[]),j=Z.useCallback(e=>{l(e),o&&Xn(o,e)},[o]),N=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||c.some(e=>p(e,t)))return;j([...c,t])}else{let e=r??ce;if(e.some(e=>p(e,t)))return;A([...e,t])}},[o,c,r,j,A]),F=Z.useCallback((e,t)=>{e===`project`?j(c.filter(e=>!p(e,t))):A((r??ce).filter(e=>!p(e,t)))},[c,r,j,A]),I=Z.useCallback((e,t,n)=>{let i=e===`project`?c:r??ce,a=i.findIndex(n=>Ng(e,n)===t),o=i.findIndex(t=>Ng(e,t)===n);if(a<0||o<0||a===o)return;let s=Ko([...i],a,o);e===`project`?j(s):A(s)},[c,r,j,A]);return{global:E,project:D,pinnable:k,hasProject:!!o,ensureLoaded:b,addStarter:N,removeStarter:F,reorder:I}}var Ig=`__draft-starter-trash__`,Lg=`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`,Rg=`max-h-7`,zg=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],Bg=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=ot(),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}=qo(s),m;t[2]===d?m=t[3]:(m=Wo.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},Vg=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(Kg),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)(Bg,{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)(Yo,{items:o,strategy:Go,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},Hg=()=>{let e=(0,Q.c)(13),{t}=ot(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:Ig},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=zo(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(Lg,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},Ug=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=ot(),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)(Dg,{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)(kg,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=zg.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(Ag,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(Mg,{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)(Og,{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)(Eg,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},Wg=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=ot(),[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)(sa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:Lg,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)(na,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(aa,{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)(Ug,{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)(ia,{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)(ca,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},Gg=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=ot(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=Fg(is()),{isMobile:f}=fo(),[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=Uo(Io(Vo,b),Io(Ro,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)===Ig){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:Lo.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&&Rg,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)(Vg,{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)(Vg,{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(qg),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:Lg,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 G;t[46]!==l||t[47]!==c||t[48]!==p||t[49]!==f||t[50]!==s?(G=f&&p?(0,$.jsx)(Hg,{}):(0,$.jsx)(Wg,{pinnable:s,onOpen:c,onAdd:l}),t[46]=l,t[47]=c,t[48]=p,t[49]=f,t[50]=s,t[51]=G):G=t[51];let K;t[52]!==ee||t[53]!==G?(K=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 self-start`,children:[ee,G]}),t[52]=ee,t[53]=G,t[54]=K):K=t[54];let te;t[55]!==R||t[56]!==W||t[57]!==K?(te=(0,$.jsxs)(`div`,{className:R,children:[W,K]}),t[55]=R,t[56]=W,t[57]=K,t[58]=te):te=t[58];let ne;return t[59]!==F||t[60]!==S||t[61]!==te?(ne=(0,$.jsx)(Ho,{sensors:S,collisionDetection:Bo,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:te}),t[59]=F,t[60]=S,t[61]=te,t[62]=ne):ne=t[62],ne};function Kg(e){return e.id}function qg(e){return!e}var Jg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(19),r,i,a,o,s,c;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5],c=n[6]):({children:r,className:i,expanded:s,focusedTone:c,style:o,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s,n[6]=c);let l=s!==void 0&&s,u=c===void 0?`primary`:c,d=l&&`min-h-0 flex-1`,f=u===`info`?`focus-within:ring-[var(--status-info)]`:`focus-within:ring-primary/50`,p;n[7]!==i||n[8]!==d||n[9]!==f?(p=Y(`relative flex flex-col overflow-visible border border-border/80 focus-within:ring-1`,d,f,i),n[7]=i,n[8]=d,n[9]=f,n[10]=p):p=n[10];let m;n[11]===o?m=n[12]:(m={borderRadius:`var(--radius-xl)`,backgroundColor:`var(--surface-subtle)`,...o},n[11]=o,n[12]=m);let h;return n[13]!==r||n[14]!==a||n[15]!==t||n[16]!==p||n[17]!==m?(h=(0,$.jsx)(`div`,{ref:t,className:p,style:m,...a,children:r}),n[13]=r,n[14]=a,n[15]=t,n[16]=p,n[17]=m,n[18]=h):h=n[18],h});Jg.displayName=`ChatComposerSurface`;var Yg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Oa,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});Yg.displayName=`ChatPromptTextarea`;var Xg=e=>{let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=Y(`flex shrink-0 items-center gap-2 bg-transparent px-2.5 py-1.5`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,$.jsx)(`div`,{className:a,"data-chat-input-footer":`true`,...i,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o},Zg=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},Qg=e=>{let t=(0,Q.c)(139),n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P,F,I,L,R,z,B;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],_=t[16],v=t[17],y=t[18],b=t[19],x=t[20],S=t[21],C=t[22],w=t[23],T=t[24],E=t[25],D=t[26],O=t[27],k=t[28],A=t[29],j=t[30],M=t[31],N=t[32],P=t[33],F=t[34],I=t[35],L=t[36],R=t[37],z=t[38],B=t[39]):({value:B,attachments:j,disabled:M,pending:N,placeholder:T,isMobile:P,onChange:x,onSubmit:w,onStop:C,onAddFiles:b,onRemoveAttachment:S,addFilesLabel:n,removeAttachmentLabel:E,sendLabel:O,stopLabel:k,hint:f,leftControls:y,rightControls:D,footerContent:c,inputHeader:m,attachmentContent:r,highlightedContent:d,highlightRef:u,inputRef:g,textareaProps:z,textLayoutClassName:R,inputClassName:p,inputOuterClassName:h,inputStyle:v,footerClassName:s,footerStyle:l,contentClassName:o,inputSectionClassName:_,autoResize:F,disableInputWhilePending:I,children:i,className:a,expanded:L,...A}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=_,t[17]=v,t[18]=y,t[19]=b,t[20]=x,t[21]=S,t[22]=C,t[23]=w,t[24]=T,t[25]=E,t[26]=D,t[27]=O,t[28]=k,t[29]=A,t[30]=j,t[31]=M,t[32]=N,t[33]=P,t[34]=F,t[35]=I,t[36]=L,t[37]=R,t[38]=z,t[39]=B);let V=j===void 0?[]:j,H=M!==void 0&&M,U=N!==void 0&&N,W=P!==void 0&&P,ee=F===void 0||F,G=I===void 0||I,K=L!==void 0&&L,te=Z.useRef(null),ne=Z.useRef(null),re;t[40]!==ee||t[41]!==K||t[42]!==z?.fillContainer?(re=()=>{if(!ee||K||z?.fillContainer)return;let e=te.current;if(!e)return;e.style.height=`auto`;let t=Number.parseFloat(window.getComputedStyle(e).maxHeight),n=Number.isFinite(t)?Math.min(e.scrollHeight,t):e.scrollHeight;e.style.height=`${n}px`,e.style.overflowY=Number.isFinite(t)&&e.scrollHeight>t?`auto`:`hidden`},t[40]=ee,t[41]=K,t[42]=z?.fillContainer,t[43]=re):re=t[43];let ie=z?.fillContainer,ae;t[44]!==ee||t[45]!==K||t[46]!==ie||t[47]!==B?(ae=[ee,K,ie,B],t[44]=ee,t[45]=K,t[46]=ie,t[47]=B,t[48]=ae):ae=t[48],Z.useLayoutEffect(re,ae);let oe;t[49]!==G||t[50]!==H||t[51]!==w||t[52]!==U||t[53]!==z?(oe=e=>{z?.onKeyDown?.(e),!(e.defaultPrevented||Kh(e))&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),!H&&(!U||!G)&&w())},t[49]=G,t[50]=H,t[51]=w,t[52]=U,t[53]=z,t[54]=oe):oe=t[54];let se=oe,ce;t[55]===b?ce=t[56]:(ce=e=>{b?.(e.target.files),e.target.value=``},t[55]=b,t[56]=ce);let le=ce,ue=B.trim().length>0||V.length>0,de=V.filter($g),fe;t[57]!==n||t[58]!==H||t[59]!==le||t[60]!==b||t[61]!==U?(fe=b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:ne,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:le}),(0,$.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-foreground outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,onClick:()=>ne.current?.click(),disabled:H||U,"aria-label":n,children:(0,$.jsx)(X,{name:`attachment-2`,className:`size-[18px]`})})]}):null,t[57]=n,t[58]=H,t[59]=le,t[60]=b,t[61]=U,t[62]=fe):fe=t[62];let pe=fe,me;t[63]!==H||t[64]!==ue||t[65]!==C||t[66]!==U||t[67]!==O||t[68]!==k?(me=U&&C?(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,className:`flex size-8 shrink-0 items-center justify-center !text-black outline-none hover:!text-black dark:!text-white dark:hover:!text-white`,onClick:C,"aria-label":k,children:(0,$.jsx)(qh,{className:`size-5`})}):(0,$.jsx)(`button`,{type:`submit`,"data-composer-send":`true`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-primary outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`,disabled:H||U||!ue,"aria-label":O,children:(0,$.jsx)(X,{name:U?`loader-4`:`send-plane-2`,className:Y(`size-4`,U&&`animate-spin`)})}),t[63]=H,t[64]=ue,t[65]=C,t[66]=U,t[67]=O,t[68]=k,t[69]=me):me=t[69];let he=me,ge=Jg,_e=K&&`flex-1`,ve;t[70]!==o||t[71]!==_e?(ve=Y(`relative flex min-h-0 flex-col`,_e,o),t[70]=o,t[71]=_e,t[72]=ve):ve=t[72];let ye=K&&`flex min-h-0 flex-1 flex-col`,be;t[73]!==_||t[74]!==ye?(be=Y(`overflow-hidden`,ye,_),t[73]=_,t[74]=ye,t[75]=be):be=t[75];let xe=de.length>0?(0,$.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-3 pt-3`,"data-chat-prompt-attachments":`true`,children:de.map(e=>(0,$.jsxs)(`div`,{className:`group relative shrink-0`,children:[(0,$.jsx)(`img`,{src:e.url,alt:e.name,className:`size-16 rounded-lg border border-border object-cover`}),S?(0,$.jsx)(`button`,{type:`button`,className:`absolute -right-1 -top-1 flex size-6 items-center justify-center rounded-full border border-border bg-[var(--surface-elevated)] shadow-sm hover:bg-[var(--interactive-hover)]`,onClick:()=>S(e.id),"aria-label":E,children:(0,$.jsx)(X,{name:`close`,className:`size-3`})}):null]},e.id))}):null,Se=K&&`flex min-h-0 flex-1 flex-col`,Ce;t[76]===Se?Ce=t[77]:(Ce=Y(`relative overflow-hidden`,Se),t[76]=Se,t[77]=Ce);let we;t[78]!==u||t[79]!==d||t[80]!==p||t[81]!==R?(we=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[78]=u,t[79]=d,t[80]=p,t[81]=R,t[82]=we):we=t[82];let Te;t[83]===g?Te=t[84]:(Te=e=>{te.current=e,Zg(g,e)},t[83]=g,t[84]=Te);let Ee;t[85]===x?Ee=t[86]:(Ee=e=>x(e.target.value,e),t[85]=x,t[86]=Ee);let De=H||U&&G,Oe=W?`send`:z?.enterKeyHint,ke=K&&`min-h-0 flex-1`,Ae;t[87]!==h||t[88]!==ke?(Ae=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,ke,h),t[87]=h,t[88]=ke,t[89]=Ae):Ae=t[89];let je=d&&`text-transparent caret-[var(--surface-foreground)]`,Me;t[90]!==p||t[91]!==je||t[92]!==R?(Me=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,je),t[90]=p,t[91]=je,t[92]=R,t[93]=Me):Me=t[93];let Ne=z?.rows??1,Pe;t[94]!==se||t[95]!==v||t[96]!==T||t[97]!==Te||t[98]!==Ee||t[99]!==De||t[100]!==Oe||t[101]!==Ae||t[102]!==Me||t[103]!==Ne||t[104]!==z||t[105]!==B?(Pe=(0,$.jsx)(Yg,{...z,simple:!0,ref:Te,"data-chat-input":`true`,value:B,onChange:Ee,onKeyDown:se,disabled:De,placeholder:T,enterKeyHint:Oe,outerClassName:Ae,className:Me,style:v,rows:Ne}),t[94]=se,t[95]=v,t[96]=T,t[97]=Te,t[98]=Ee,t[99]=De,t[100]=Oe,t[101]=Ae,t[102]=Me,t[103]=Ne,t[104]=z,t[105]=B,t[106]=Pe):Pe=t[106];let Fe;t[107]!==Ce||t[108]!==we||t[109]!==Pe?(Fe=(0,$.jsxs)(`div`,{className:Ce,"data-composer-input-shell":`true`,children:[we,Pe]}),t[107]=Ce,t[108]=we,t[109]=Pe,t[110]=Fe):Fe=t[110];let Ie;t[111]!==r||t[112]!==m||t[113]!==be||t[114]!==xe||t[115]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:be,children:[m,r,xe,Fe]}),t[111]=r,t[112]=m,t[113]=be,t[114]=xe,t[115]=Fe,t[116]=Ie):Ie=t[116];let Le;t[117]!==pe||t[118]!==he||t[119]!==c||t[120]!==f||t[121]!==y||t[122]!==D?(Le=c??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:y??pe}),f?(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,children:f}):(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:D??he})]}),t[117]=pe,t[118]=he,t[119]=c,t[120]=f,t[121]=y,t[122]=D,t[123]=Le):Le=t[123];let Re;t[124]!==s||t[125]!==l||t[126]!==Le?(Re=(0,$.jsx)(Xg,{className:s,style:l,children:Le}),t[124]=s,t[125]=l,t[126]=Le,t[127]=Re):Re=t[127];let ze;t[128]!==ve||t[129]!==Ie||t[130]!==Re?(ze=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ve,children:[Ie,Re]}),t[128]=ve,t[129]=Ie,t[130]=Re,t[131]=ze):ze=t[131];let Be;return t[132]!==ge||t[133]!==i||t[134]!==a||t[135]!==K||t[136]!==A||t[137]!==ze?(Be=(0,$.jsxs)(ge,{className:a,expanded:K,...A,children:[i,ze]}),t[132]=ge,t[133]=i,t[134]=a,t[135]=K,t[136]=A,t[137]=ze,t[138]=Be):Be=t[138],Be};function $g(e){return e.mime.startsWith(`image/`)}var e_=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),t_=({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}=ot(),[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(()=>e_(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?Dr(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?Dr(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?Dr(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||Dr([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(``)},ie=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},ae=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)}}},oe=async e=>{if(!(!W||F)){I(!0);try{await a(W,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},se=()=>{M(!1)},ce=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let le=u||e||w(`gitView.branch.detachedHead`),ue=d??(c?`end`:`start`),de=v??w(`chat.chatInput.worktrees`),fe=y??w(`chat.chatInput.worktreeNew`),pe=b??w(`chat.chatInput.projectRoot`),me=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":le,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(la,{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":le,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:le}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),he=(0,$.jsx)(qa,{asChild:!0,disabled:s,children:l??me}),ge=(0,$.jsxs)(Eg,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(Dg,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(Og,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(kg,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(Ag,{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:se,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:()=>oe(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(),ae()):e.key===`Escape`&&(e.preventDefault(),ce())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:ae,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:ce,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)(Mg,{onSelect:ie,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(jg,{}),(0,$.jsxs)(Ag,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(Mg,{onSelect:()=>ne(t),children:[(0,$.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:t}),(r?.[t]?.ahead||r?.[t]?.behind)&&(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[r[t].ahead||0,` ahead ·`,` `,r[t].behind||0,` behind`]})]}),e===t&&(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)})]},`local-${t}`)),ee.length===0&&(0,$.jsx)(Mg,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(jg,{}),(0,$.jsxs)(Ag,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(Mg,{onSelect:()=>ne(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(Mg,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noRemoteBranches`)})})]}),U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(jg,{}),(0,$.jsxs)(Ag,{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:de}),_?(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:fe}):null]}),p&&te?(0,$.jsxs)(Mg,{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:pe}),(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,K.map(e=>(0,$.jsxs)(Mg,{onSelect:()=>re(e.value),children:[(0,$.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),h===e.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`))]})]}):null]})]});if(C===`mobile-sheet`){let e=Z.cloneElement(l??me,{onClick:()=>B(!0),"data-popup-open":z?``:void 0});return(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(Qa,{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:ge})]})}return(0,$.jsxs)(Ua,{open:z,onOpenChange:B,children:[f||l?he:(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:he}),(0,$.jsx)(La,{sideOffset:8,children:c?le:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(Ka,{align:ue,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ge})]})};function n_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=Dr(t,i,e=>e),o=Dr(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 r_(e,t){return`${e}\0${t}`}function i_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),i=s(e=>e.isMobile),{github:a}=Do(),o=eo(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=jt(e=>e.getActiveProject()),p=f?.id??null,m=f?.path??null,h=Z.useMemo(()=>m&&p?{id:p,path:m}:null,[p,m]),[g,_]=Z.useState(`issues`),[v,y]=Z.useState(``),[b,x]=Z.useState([]),[S,C]=Z.useState([]),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(null),[A,j]=Z.useState(null),[M,N]=Z.useState(null),[P,F]=Z.useState(!1),[I,L]=Z.useState(new Map),[R,z]=Z.useState(1),[B,V]=Z.useState(!1),H=Z.useRef(0),U=ys(v,350),W=q(async e=>{if(!(!m||!a)&&!(l&&c?.connected===!1)){T(!0),k(null),z(1),V(!1);try{if(g===`issues`&&a.issuesList){let t=await a.issuesList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(t.issues??[]),z(t.page??1),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=await a.prsList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(t.prs??[]),z(t.page??1),V(!!t.hasMore))}}catch(e){k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{T(!1)}}});Z.useEffect(()=>{if(!e||!m||l&&c?.connected===!1||!a)return;if(!U.trim()){W();return}let t=new AbortController;T(!0),k(null),z(1),V(!1);let n=g===`issues`&&a.issuesList?a.issuesList(m,{page:1,query:U.trim()}):g===`prs`&&a.prsList?a.prsList(m,{page:1,query:U.trim()}):null;if(!n){T(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(e.issues??[]),z(e.page??1),V(!!e.hasMore)):`prs`in e&&(e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(e.prs??[]),z(e.page??1),V(!!e.hasMore))))}).catch(e=>{t.signal.aborted||k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||T(!1)}),()=>t.abort()},[e,m,a,l,c,g,U,W,r]);let ee=q(async()=>{if(!(!m||!a)&&!(w||E)&&B){D(!0);try{let e=R+1;if(g===`issues`&&a.issuesList){let t=U.trim()?await a.issuesList(m,{page:e,query:U.trim()}):await a.issuesList(m,{page:e});t.connected!==!1&&(x(e=>[...e,...t.issues??[]]),z(t.page??e),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=U.trim()?await a.prsList(m,{page:e,query:U.trim()}):await a.prsList(m,{page:e});t.connected!==!1&&(C(e=>[...e,...t.prs??[]]),z(t.page??e),V(!!t.hasMore))}}catch{}finally{D(!1)}}});Z.useEffect(()=>{if(!e){_(`issues`),y(``),x([]),C([]),j(null),N(null),F(!1),k(null),L(new Map),z(1),V(!1);return}W()},[e,W]),Z.useEffect(()=>{H.current+=1,L(new Map)},[m,h]);let G=q(async e=>{if(!h||!e)return;let t=r_(h.path,e);if(I.has(t))return;let n=H.current;try{let i=await xa(h,{mode:`new`,branchName:e,worktreeName:e});if(n!==H.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);L(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!==H.current)return;L(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||g!==`prs`||S.forEach(e=>{e.head&&G(e.head)})},[e,g,S,m,h,G]);let K=l&&c?.connected===!0,te=()=>{d(`github`),u(!0)},ne=e=>{j(e),N(null)},re=e=>{N(e),j(null)},ie=()=>{A?n({type:`issue`,item:A}):M&&n({type:`pr`,item:M,includeDiff:P}),t(!1)},ae=()=>{j(null),N(null),F(!1)},oe=A||(M?.head&&m?I.get(r_(m,M.head))?.isValid!==!1:!1),se=e=>!e.head||(m?I.get(r_(m,e.head)):void 0)?.isValid===!1,ce=(0,$.jsx)($.Fragment,{children:K?(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)(Fa,{value:v,onChange:e=>y(e.target.value),placeholder:r(g===`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:[w&&(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`})}),O&&(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:O})]})}),!w&&!O&&g===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[b.length>0?b.map(e=>(0,$.jsx)(`button`,{onClick:()=>ne(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,A?.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`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(la,{variant:`ghost`,size:`sm`,onClick:()=>void ee(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(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`})})]}),!w&&!O&&g===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[S.length>0?S.map(e=>{let t=se(e),n=e.head&&m?I.get(r_(m,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&re(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,M?.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`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(la,{variant:`ghost`,size:`sm`,onClick:()=>void ee(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(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)(la,{onClick:te,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&&(A||M)&&(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:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.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`})})]}),g===`prs`&&M&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(ha,{checked:P,onChange:e=>F(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)(la,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(la,{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)(Sp,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:K?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)(pc,{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:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})}),(A||M)&&(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:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.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)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(na,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(aa,{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)(pc,{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:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),ce,(0,$.jsx)(ra,{className:`mt-1`,children:le})]})})})}var a_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},o_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),s_=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),c_=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,l_=(e,t,n)=>{let r=o_(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-${c_(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}`}},u_=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},d_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function f_({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ot(),{github:a,git:o}=Do(),c=s(e=>e.isMobile),l=Z.useId(),u=eo(),d=u.data??null,f=u.isFetched,p=jt(e=>a_(e.projects,e.activeProjectId,r)),m=p?.path??null,h=Z.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[g,_]=Z.useState(`new-branch`),[v,y]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[b,x]=Z.useState({selectedBranch:``,worktreeName:``}),S=Ps(m),C=js(m),w=ws(e=>e.fetchBranches),T=Z.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),E=Z.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),D=Qr(e=>e.availableWorktreesByProject),O=Z.useMemo(()=>{if(!m)return new Set;let e=D.get(m)??[];return new Set(e.map(e=>e.name))},[D,m]),k=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=ag();if(!O.has(e))return e}return`${ag()}-${Date.now().toString(36).slice(-4)}`},[O]),[A,j]=Z.useState(!1),[M,N]=Z.useState(!1),[P,F]=Z.useState(!1),[I,L]=Z.useState(!1),[R,z]=Z.useState(!1),[B,V]=Z.useState(``),[H,U]=Z.useState(``),W=Z.useRef(null),ee=Z.useRef(null),G=Z.useRef(null),K=Z.useRef(null),te=Z.useCallback(e=>{e.stopPropagation()},[]),ne=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},[]),re=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),ie=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;re(t)},[re]),ae=Z.useCallback(e=>{let t=ne(e.current);re(t)},[ne,re]),oe=Z.useMemo(()=>n_({localBranches:T,remoteBranches:E,query:B}),[T,E,B]),se=Z.useMemo(()=>n_({localBranches:T,remoteBranches:E,query:H}),[T,E,H]),ce=B.trim().length>0,le=H.trim().length>0,ue=oe.matching.length>0,de=se.matching.length>0,fe=!!(m&&o),pe=Z.useCallback(()=>{!m||!o||w(m,o)},[m,o,w]);Z.useEffect(()=>{!e||!m||!o||S?.all||w(m,o)},[e,m,o,S?.all,w]),Z.useEffect(()=>{!M&&!I&&V(``)},[M,I]),Z.useEffect(()=>{!P&&!R&&U(``)},[P,R]),Z.useEffect(()=>{M&&ie(W),I&&ae(G)},[M,I,B,ie,ae]),Z.useEffect(()=>{P&&ie(ee),R&&ae(K)},[P,R,H,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=mi.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=mi.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Gn(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),Se=Z.useCallback((e,t)=>{let n=mi.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),Ce=Z.useCallback(async e=>{if(!m||!a)return;let t=mi.getState(),n=Bt.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){Cr.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(m,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(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await On(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await On(`github.issue.review.instructions`),d=u_({repo:t.repo,issue:t.issue,comments:n.comments??[]});await Qr.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Cr.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(m,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 On(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await On(`github.pr.review.instructions`),u=d_(t);await Qr.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Cr.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,m,be,xe,Se,i]),we=g===`new-branch`?v:b;Z.useEffect(()=>{if(!e||!S?.all||!m||v.sourceBranch)return;let t=v.sourceBranch,n=!1;return(async()=>{try{let e=await ka(m).catch(()=>null);if(n)return;let r=localStorage.getItem(Cs),{sourceBranch:i,shouldClearSavedSourceBranch:a}=Ns({branches:S.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Cs),n||t)return;i&&y(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,S?.all,m,v.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;_(`new-branch`),x({selectedBranch:``,worktreeName:``}),N(!1),F(!1),L(!1),z(!1),V(``),U(``),he({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=k();y({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,k]),Z.useEffect(()=>{if(g!==`new-branch`||!v.isSyncingWorktreeName)return;let e=s_(o_(v.branchName));y(t=>({...t,worktreeName:e}))},[g,v.branchName,v.isSyncingWorktreeName]);let Te=Z.useCallback(async()=>{if(!h||!me.touched||ge)return;ve&&ve.abort();let e=new AbortController;ye(e),he(e=>({...e,isValidating:!0}));try{let t=g===`new-branch`?v.branchName:b.selectedBranch,n=we.worktreeName,r=o_(t),a=s_(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=g===`new-branch`?v.linkedPr:null,n=t?l_(t,T,E):null,i=await xa(h,{mode:g===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(g===`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}))}},[h,g,v.branchName,v.linkedPr,b.selectedBranch,we.worktreeName,T,E,me.touched,ve,ge,i]),Ee=g===`new-branch`?v.branchName:b.selectedBranch;Z.useEffect(()=>{if(!e||!h||!me.touched||ge)return;let t=setTimeout(()=>{Te()},300);return()=>clearTimeout(t)},[we.worktreeName,Ee,e,h,Te,me.touched,ge]);let De=async()=>{if(!h||!m){Cr.error(i(`session.newWorktree.error.noActiveProject`));return}he(e=>({...e,touched:!0}));let e=g===`new-branch`?v.branchName:b.selectedBranch,r=we.worktreeName,a=o_(e),o=s_(r);if(!a){Cr.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){Cr.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=g===`new-branch`?v.linkedPr:null,r=g===`new-branch`?v.linkedIssue:null,s=g===`new-branch`?v.linkedPr:null,c=g===`new-branch`&&v.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([jn(h),As(m)]),f=v.sourceBranch,p=``,_=(()=>{if(e){let t=l_(e,T,E);return p=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 p=g===`new-branch`?f:``,{preferredName:a||o,mode:g===`existing-branch`?`existing`:`new`,branchName:g===`existing-branch`?void 0:a,worktreeName:o,existingBranch:g===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&g===`new-branch`?{startRef:f}:{}}})(),y=await Rs(m,_,{resolvedRootTrackingRemote:d}),x=await Aa(h,y),S=null;if(l){await Qi(h)&&await fi(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Un(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),ui(a.id,e).catch(()=>void 0);try{Qr.getState().initializeNewOpenChamberSession(a.id,mi.getState().agents)}catch{}}else t(!1),_e(!1);let C=Is({mode:g,sourceBranch:v.sourceBranch,linkedPr:!!v.linkedPr,selectedBranch:b.selectedBranch});C&&localStorage.setItem(Cs,C),Cr.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${p?` ${i(`session.newWorktree.fromSource`,{source:p})}`:``}`})}),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`);Cr.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`);Cr.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{_e(!1)}},Oe=e=>{_(e),he(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},ke=e=>{if(!e){y(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${ag()}`;y(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:s_(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;y(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:s_(t.head),isSyncingWorktreeName:!0}))}},Ae=f&&d?.connected===!0,je=(g===`existing-branch`?!!b.selectedBranch&&!!b.worktreeName&&!me.branchError&&!me.worktreeError:!!o_(v.branchName)&&!!v.worktreeName&&!me.branchError&&!me.worktreeError)&&!ge,Me=()=>{y(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Ne=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,c?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,c?`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`,c&&`w-full`),children:[(0,$.jsx)(la,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,className:Y(c&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(la,{size:`sm`,onClick:De,disabled:!je||ge,className:Y(`gap-1.5`,c&&`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:[c?(0,$.jsx)(Qa,{id:`new-worktree-sheet-${l}`,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)(fa,{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)(pc,{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:g,onSelect:e=>Oe(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[g===`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)(la,{variant:`outline`,size:`sm`,onClick:()=>L(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:b.selectedBranch?`text-foreground`:`text-muted-foreground`,children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(la,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(Sp,{open:I,title:i(`session.newWorktree.selectBranch`),onClose:()=>L(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(Fa,{value:B,onChange:e=>V(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.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:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:s_(e.label)})),he(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.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:()=>{x(t=>({...t,selectedBranch:e,worktreeName:s_(e)})),he(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.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:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:s_(e)})),he(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.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`)}),g===`new-branch`&&Ae&&(0,$.jsxs)(la,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Fa,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.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:v.linkedPr.head})})]}),v.linkedIssue&&!v.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:v.linkedIssue.number,title:v.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`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=s_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===s_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===s_(v.branchName)||!v.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)(Fa,{value:we.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(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`)})]}),g===`new-branch`&&!v.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)(la,{variant:`outline`,size:`sm`,onClick:()=>z(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:v.sourceBranch?`text-foreground`:`text-muted-foreground`,children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})}),(0,$.jsx)(Sp,{open:R,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>z(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:K,children:[(0,$.jsx)(Fa,{value:H,onChange:e=>U(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.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:()=>{y(t=>({...t,sourceBranch:e.value})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.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:()=>{y(t=>({...t,sourceBranch:e})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.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:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.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}`))})]})]})]})})]}),(v.linkedIssue||v.linkedPr)&&g===`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`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.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`})})]}),v.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:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.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)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(na,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(aa,{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)(pc,{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:g,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:[g===`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)(Ua,{open:M,onOpenChange:N,children:[(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(la,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,b.selectedBranch?`text-foreground`:`text-muted-foreground`),children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ka,{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:W,children:(0,$.jsxs)(Eg,{shouldFilter:!1,children:[(0,$.jsx)(Dg,{placeholder:i(`session.newWorktree.searchBranches`),value:B,onValueChange:V,onKeyDown:te}),(0,$.jsx)(Og,{disableHorizontal:!0,children:C?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(kg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(Ag,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(Mg,{value:e.value,onSelect:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:s_(e.label)})),he(e=>({...e,touched:!0})),N(!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)(jg,{}),(0,$.jsx)(Ag,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(Mg,{value:e,onSelect:()=>{x(t=>({...t,selectedBranch:e,worktreeName:s_(e)})),he(e=>({...e,touched:!0})),N(!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)(jg,{}),(0,$.jsx)(Ag,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(Mg,{value:`remotes/${e}`,onSelect:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:s_(e)})),he(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(la,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||C,title:i(`session.newWorktree.fetchBranches`),children:C?(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`)}),g===`new-branch`&&Ae&&(0,$.jsxs)(la,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Fa,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.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:v.linkedPr.head})})]}),v.linkedIssue&&!v.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:v.linkedIssue.number,title:v.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`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=s_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===s_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===s_(v.branchName)||!v.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)(Fa,{value:we.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(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`)})]}),g===`new-branch`&&!v.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)(Ua,{open:P,onOpenChange:F,children:[(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(la,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,v.sourceBranch?`text-foreground`:`text-muted-foreground`),children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ka,{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:ee,children:(0,$.jsxs)(Eg,{shouldFilter:!1,children:[(0,$.jsx)(Dg,{placeholder:i(`session.newWorktree.searchBranches`),value:H,onValueChange:U,onKeyDown:te}),(0,$.jsx)(Og,{disableHorizontal:!0,children:C?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(kg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[le&&de&&(0,$.jsx)(Ag,{heading:i(`session.newWorktree.matchingBranches`),children:se.matching.map(e=>(0,$.jsx)(Mg,{value:e.value,onSelect:()=>{y(t=>({...t,sourceBranch:e.value})),F(!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)(jg,{}),(0,$.jsx)(Ag,{heading:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:se.otherLocal.map(e=>(0,$.jsx)(Mg,{value:e,onSelect:()=>{y(t=>({...t,sourceBranch:e})),F(!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)(jg,{}),(0,$.jsx)(Ag,{heading:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:se.otherRemote.map(e=>(0,$.jsx)(Mg,{value:`remotes/${e}`,onSelect:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})})]}),(v.linkedIssue||v.linkedPr)&&g===`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`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.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`})})]}),v.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:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.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)(ra,{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)(la,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(la,{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)(i_,{open:A,onOpenChange:j,onSelect:ke})]})}function p_(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 m_(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 h_=(e,t)=>e??t??null,g_=(e,t)=>!!e&&t!==!1,__=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:[]},v_=e=>e.replace(/^remotes\//,``).trim(),y_=e=>{let t=v_(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},b_=({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}=ot(),{git:d}=Do(),f=h_(t,e),p=e,m=Bs(f),h=Bs(p),g=g_(f,m),_=p!==f&&g_(p,h),v=gs(f,d,g),y=gs(p,d,_),b=v.data,x=p===f?b:y.data,S=ws(e=>e.fetchStatus),C=ws(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=zs(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=jt(e=>e.projects),P=jt(e=>e.activeProjectId);Z.useEffect(()=>{d&&(f&&m===null&&S(f,d,{silent:!0}),p&&p!==f&&h===null&&S(p,d,{silent:!0}))},[S,d,m,h,f,p]);let F=Z.useMemo(()=>{let e=u(t);if(e){let t=N.find(t=>u(t.path)===e);if(t)return t.id}return P},[P,t,N]),{localBranches:I,remoteBranches:L}=Z.useMemo(()=>__(b?.all),[b]),R=x?.current?.trim()||C||null,z=!m_(n,e)&&n||R||n||l(`chat.chatInput.branch`),B=q(async()=>{if(!d)return;let e=new Set;f&&e.add(f),p&&e.add(p),await Promise.all([...e].map(async e=>{await xs(e,d),await S(e,d,{silent:!0})}))}),V=q(e=>{let t=v_(e),n=y_(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),H=q(async e=>{if(!p||!d)return;let t=v_(e);if(R!==t&&R!==y_(t))try{await d.checkoutBranch(p,t),Cr.success(l(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});Cr.error(n)}}),U=q(e=>{let t=v_(e);if(!t||R===t||R===y_(t))return;let n=V(t);if(n){a(n.value);return}O(t)}),W=q(async()=>{if(!(!D||k)){A(!0);try{await H(D),O(null)}finally{A(!1)}}}),ee=q(async()=>{if(!(!D||k)){A(!0);try{await vg({branch:D,projectDirectory:t??void 0})&&O(null)}finally{A(!1)}}}),G=q(async(e,t)=>{if(!p||!d)return;let n=t?.name??`origin`;try{await d.createBranch(p,e,R??`HEAD`),Cr.success(l(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),Cr.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);Cr.warning(l(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:t})}),await B()})}catch(e){let t=e instanceof Error?e.message:l(`gitView.toast.createBranchFailed`);throw Cr.error(t),e}}),K=q(()=>{let e=jt.getState(),n=u(t),r=n?e.projects.find(e=>u(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),te=q((e,n)=>{if(M(!1),n?.sessionId){Qr.getState().setCurrentSession(n.sessionId,e);return}let r=jt.getState(),i=u(t),a=(i?r.projects.find(e=>u(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=Qr.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),Te.getState().setDirectory(e,{showOverlay:!1});return}o.openNewSessionDraft({...a?{selectedProjectId:a}:{},directoryOverride:e,preserveDirectoryOverride:!0})}),ne=(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,Ap,o),"aria-label":z,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:z}),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)(t_,{currentBranch:R,localBranches:I,remoteBranches:L,branchInfo:b?.branches,onCheckout:U,onCreate:G,remotes:E,trigger:ne,triggerLabel:z,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:K,open:w,presentation:c,onOpenChange:T}),j?(0,$.jsx)(f_,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:te}):null,(0,$.jsx)(ca,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ia,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(na,{children:[(0,$.jsx)(aa,{children:l(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(oa,{children:l(`chat.chatInput.branchSwitch.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:k,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:[k?(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:k,onClick:()=>{ee()},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:[k?(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)(ra,{children:(0,$.jsx)(`button`,{type:`button`,disabled:k,onClick:()=>O(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`)})})]})})]})},x_=[],S_=[],C_={revertMessageID:void 0,records:S_},w_=e=>e.role===`user`,T_=(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},E_=(e,t,n=C_)=>{if(!t)return C_;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return C_;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!w_(e)||!Cn(i,e.id,r)||o.push({message:e,parts:a[e.id]??x_});let s=o.length===0?S_:o;return n.revertMessageID===r&&T_(n.records,s)?n:{revertMessageID:r,records:s}},D_={mentionFile:100,mentionAgent:100,mentionSession:100,mentionCommand:100,mentionSnippet:100,mentionPaste:100,code:90,codeFence:90,link:80,linkUrl:78,heading:70,blockquote:40,listMarker:35,marker:10},O_={mentionFile:`text-[var(--primary)]`,mentionAgent:`text-[var(--primary)]`,mentionSession:`text-[var(--primary)]`,mentionCommand:`text-[var(--primary)]`,mentionSnippet:`text-[var(--primary)]`,mentionPaste:`text-[var(--primary)]`,code:`rounded-[3px] bg-[var(--surface-subtle)] text-[var(--markdown-inline-code)]`,codeFence:`bg-[var(--surface-subtle)] text-[var(--markdown-inline-code)]`,link:`text-[var(--status-info)] underline`,linkUrl:`text-muted-foreground`,heading:`text-[var(--syntax-keyword)]`,blockquote:`text-muted-foreground`,listMarker:`text-[var(--syntax-keyword)]`,marker:`text-muted-foreground`},k_=`text-foreground`;function A_(e,t,n){let r=0,i=e.length;for(;r<i;){let i=e[r];if(i==="`"){let i=/^`+/.exec(e.slice(r))?.[0]??``,a=e.indexOf(i,r+i.length);if(a!==-1){let e=a+i.length;n.push({start:t+r,end:t+e,style:`code`}),r=e;continue}}if(i===`[`){let i=/^\[([^\]\n]*)\]\(([^)\n]*)\)/.exec(e.slice(r));if(i){let e=t+r,a=i[1].length,o=i[2].length,s=e+1,c=s+a,l=c+2,u=l+o,d=u+1;n.push({start:e,end:s,style:`marker`}),a>0&&n.push({start:s,end:c,style:`link`}),n.push({start:c,end:l,style:`marker`}),o>0&&n.push({start:l,end:u,style:`linkUrl`}),n.push({start:u,end:d,style:`marker`}),r+=i[0].length;continue}}r+=1}}var j_=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function M_(e){let t=j_.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function N_(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function P_(e){let t=[];if(!e)return t;let n=0,r=!1,i=``,a=e.split(`
6522
+ `);for(let e=0;e<a.length;e+=1){let o=a[e],s=n,c=s+o.length;if(n=c+1,r){t.push({start:s,end:c,style:`codeFence`}),N_(o,i)&&(r=!1);continue}let l=M_(o);if(l){r=!0,i=l.marker,t.push({start:s,end:c,style:`codeFence`});continue}let u=/^(\s*)(#{1,6})(\s+)/.exec(o);if(u){let e=s+u[1].length,n=e+u[2].length;t.push({start:e,end:n,style:`marker`});let r=n+u[3].length;c>r&&(t.push({start:r,end:c,style:`heading`}),A_(o.slice(r-s),r,t));continue}let d=/^(\s*)(>+)(\s?)/.exec(o);if(d){let e=s+d[1].length,n=e+d[2].length;t.push({start:e,end:n,style:`marker`});let r=n+d[3].length;c>r&&(t.push({start:r,end:c,style:`blockquote`}),A_(o.slice(r-s),r,t));continue}let f=/^(\s*)([-*+]|\d{1,9}[.)])(\s+)/.exec(o);if(f){let e=s+f[1].length,n=e+f[2].length;t.push({start:e,end:n,style:`listMarker`});let r=n+f[3].length;A_(o.slice(r-s),r,t);continue}A_(o,s,t)}return t}function F_(e,t){if(!e||t.length===0)return null;let n=e.length,r=new Set([0,n]);for(let e of t)e.start>0&&e.start<n&&r.add(e.start),e.end>0&&e.end<n&&r.add(e.end);let i=[...r].sort((e,t)=>e-t),a=t.map((e,t)=>({range:e,index:t})).filter(e=>e.range.end>e.range.start).sort((e,t)=>e.range.start-t.range.start),o=[],s=[],c=0;for(let t=0;t<i.length-1;t+=1){let n=i[t],r=i[t+1];if(r<=n)continue;for(;c<a.length&&a[c].range.start<=n;)s.push(a[c]),c+=1;for(let e=s.length-1;e>=0;--e)s[e].range.end<=n&&s.splice(e,1);let l=null,u=-1,d=1/0;for(let{range:e,index:t}of s){let n=e.priority??D_[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??O_[l.style]:k_,p=e.slice(n,r),m=l?.visual,h=l?.skillName,g=o[o.length-1];g&&g.className===f&&R(g.visual,m)&&g.skillName===h?g.text+=p:o.push({text:p,className:f,visual:m,skillName:h})}return o.length>0?o:null}function I_(e,t){let n=new Set(Array.from(t,e=>e.toLowerCase())),r=[],i=/(^|\s)\/(\u2003)?([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/gi,a;for(;(a=i.exec(e))!==null;){let e=a[2]??``,t=a[3]||``;if(!n.has(t.toLowerCase()))continue;let i=a.index+(a[1]?.length??0);r.push({start:i,end:i+1+e.length+t.length,name:t})}return r}function L_(e,t,n){if(e===t){let t=n.find(t=>e>t.start&&e<t.end);return t?{start:t.start,end:t.end}:null}let r=n.filter(n=>n.start<t&&n.end>e);return r.length===0?null:{start:Math.min(e,...r.map(e=>e.start)),end:Math.max(t,...r.map(e=>e.end))}}function R_(e,t,n){let r=I_(e,t),i=Math.max(0,Math.min(n.selectionStart,e.length)),a=Math.max(i,Math.min(n.selectionEnd,e.length)),o=i,s=a;if(i===a)if(n.altKey)if(n.key===`Backspace`){for(;o>0&&/\s/.test(e[o-1]);)--o;for(;o>0&&!/\s/.test(e[o-1]);)--o}else{for(;s<e.length&&/\s/.test(e[s]);)s+=1;for(;s<e.length&&!/\s/.test(e[s]);)s+=1}else n.key===`Backspace`?o=Math.max(0,i-1):s=Math.min(e.length,i+1);if(o===s)return null;let c=r.filter(e=>e.start<s&&e.end>o);if(c.length===0)return null;let l=Math.min(o,...c.map(e=>e.start)),u=Math.max(s,...c.map(e=>e.end));return u<e.length&&/\s/.test(e[u])&&(l===0||/\s/.test(e[l-1]))?u+=1:u===e.length&&l>0&&/\s/.test(e[l-1])&&--l,{text:`${e.slice(0,l)}${e.slice(u)}`,caret:l,removedSkillNames:c.map(e=>e.name)}}function z_(e){return e.map(e=>({start:e.start,end:e.end,style:e.kind===`file`?`mentionFile`:e.kind===`session`?`mentionSession`:`mentionAgent`,visual:e.kind===`session`&&e.label?ie({trigger:`@`,icon:`chat-thread`,label:e.label},H({trigger:`@`,icon:`chat-thread`,label:e.label})):void 0}))}function B_(e){let t=(0,Q.c)(28),{visual:n,text:r}=e,i=n.trigger.length,a=i+n.label.length,o=a+(n.suffix?.length??0),s;t[0]!==a||t[1]!==i||t[2]!==r?(s=r.slice(i,Math.min(a,r.length)),t[0]=a,t[1]=i,t[2]=r,t[3]=s):s=t[3];let c=s,l;t[4]!==a||t[5]!==o||t[6]!==r?(l=r.slice(a,Math.min(o,r.length)),t[4]=a,t[5]=o,t[6]=r,t[7]=l):l=t[7];let u=l,d;t[8]!==o||t[9]!==r?(d=r.slice(Math.min(o,r.length)),t[8]=o,t[9]=r,t[10]=d):d=t[10];let f=d,p;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p={left:z,right:z},t[11]=p):p=t[11];let m=n.icon,h;t[12]===m?h=t[13]:(h=(0,$.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 inline-flex items-center justify-center`,style:p,children:(0,$.jsx)(X,{name:m,className:`${N} shrink-0 text-[var(--primary)]`,"aria-hidden":`true`})}),t[12]=m,t[13]=h);let g;t[14]!==h||t[15]!==n.trigger?(g=(0,$.jsxs)(`span`,{className:`relative inline-block align-baseline text-transparent leading-none`,children:[n.trigger,h]}),t[14]=h,t[15]=n.trigger,t[16]=g):g=t[16];let _;t[17]===c?_=t[18]:(_=(0,$.jsx)(`span`,{children:c}),t[17]=c,t[18]=_);let v;t[19]===u?v=t[20]:(v=u?(0,$.jsx)(`span`,{className:`text-transparent`,children:u}):null,t[19]=u,t[20]=v);let y;t[21]===f?y=t[22]:(y=f?(0,$.jsx)(`span`,{className:`text-transparent`,children:f}):null,t[21]=f,t[22]=y);let b;return t[23]!==y||t[24]!==g||t[25]!==_||t[26]!==v?(b=(0,$.jsxs)($.Fragment,{children:[g,_,v,y]}),t[23]=y,t[24]=g,t[25]=_,t[26]=v,t[27]=b):b=t[27],b}var V_=`bg-[var(--surface-subtle)]`,H_=91,U_=94,W_={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},G_={keyword:`${V_} text-[var(--syntax-keyword)]`,string:`${V_} text-[var(--syntax-string)]`,number:`${V_} text-[var(--syntax-number)]`,comment:`${V_} text-[var(--syntax-comment)]`,function:`${V_} text-[var(--syntax-function)]`,type:`${V_} text-[var(--syntax-type)]`,variable:`${V_} text-[var(--syntax-variable)]`,operator:`${V_} text-[var(--syntax-operator)]`},K_=Ye([{tag:[Ze.comment,Ze.lineComment,Ze.blockComment,Ze.docComment,Ze.meta],class:`comment`},{tag:[Ze.keyword,Ze.modifier,Ze.controlKeyword,Ze.operatorKeyword,Ze.definitionKeyword,Ze.moduleKeyword,Ze.self,Ze.null],class:`keyword`},{tag:[Ze.string,Ze.special(Ze.string),Ze.docString,Ze.character,Ze.regexp],class:`string`},{tag:[Ze.number,Ze.integer,Ze.float,Ze.bool,Ze.atom],class:`number`},{tag:[Ze.function(Ze.variableName),Ze.function(Ze.propertyName),Ze.macroName,Ze.standard(Ze.variableName)],class:`function`},{tag:[Ze.typeName,Ze.className,Ze.namespace,Ze.tagName],class:`type`},{tag:[Ze.variableName,Ze.propertyName,Ze.attributeName,Ze.labelName,Ze.definition(Ze.variableName)],class:`variable`},{tag:[Ze.operator,Ze.punctuation,Ze.bracket,Ze.derefOperator,Ze.separator],class:`operator`},{tag:[Ze.heading,Ze.heading1,Ze.heading2,Ze.heading3,Ze.heading4,Ze.heading5,Ze.heading6,Ze.strong],class:`keyword`},{tag:[Ze.emphasis,Ze.quote],class:`type`},{tag:[Ze.link,Ze.url],class:`function`},{tag:[Ze.monospace],class:`string`},{tag:[Ze.strikethrough],class:`comment`}]),q_=e=>{let t=null;for(let n of e.split(` `)){let e=n;W_[e]!==void 0&&(t===null||W_[e]>W_[t])&&(t=e)}return t?G_[t]:null},J_=2e4,Y_=e=>{if(!e)return null;try{let t=so(e);return t instanceof Qe?t:null}catch{return null}};function X_(e){if(!e||!e.includes("```")&&!e.includes(`~~~`))return[];let t=[],n=e.split(`
6523
6523
  `),r=0;for(let e=0;e<n.length;e+=1){let i=n[e];r+=i.length+1;let a=M_(i);if(!a)continue;let o=Y_(a.lang),s=r,c=[],l=e+1,u=r;for(;l<n.length;l+=1){let e=n[l];if(N_(e,a.marker)){u+=e.length+1;break}c.push(e),u+=e.length+1}if(e=l,r=u,!o||c.length===0)continue;let d=c.join(`
6524
- `);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${V_} text-[var(--syntax-foreground)]`,priority:H_}),!(d.length>J_)))try{let e=o.parser.parse(d);Ze(e,K_,(e,n,r)=>{let i=q_(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:U_})})}catch{}}return t}var Z_=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Q_=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),$_=e=>{if(!Q_(e)||/\s/.test(e))return!1;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(`/`)},ev=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?$_(n):Q_(n))?n:null},tv=(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)tv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))tv(r,t,n+1)}},nv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=ev(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=ev(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;tv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},rv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Z_){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 nv(r,i))t.add(e)}return Array.from(t)},iv=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}}},av=e=>Q_(e);function ov(e,t){let n=(0,Q.c)(5),r=ur(e,t),i=s(sv),a;n[0]===r?a=n[1]:(a=fn(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 sv(e){return e.sessionGoalEnabled}function cv(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 Ot(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 lv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},uv={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`},dv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=st(),i=s(e=>e.isMobile),{goal:a,enabled:o}=ov(e??``,t),c=cv(e??``,a),l=Er(e??``,t),u=nr(e,t),d=Z.useRef(null),[f,p]=Z.useState(!1),[m,h]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>h(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=u[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;d.current!==r&&(d.current=r,Ct(e,t))},[e,t,a,u]);let g=K(async n=>{if(!(!e||f)){p(!0);try{await yn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),wr.error(r(`chat.goal.toast.actionFailed`))}finally{p(!1)}}});if(!e||!o||!a)return null;let _=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:m)-(a.createdAt||m)),v=ht(_),y=a.tokenBudget?`${Kr(a.tokensUsed)}/${Kr(a.tokenBudget)}`:a.tokensUsed>0?Kr(a.tokensUsed):null,b=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,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=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:c??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:lv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||c||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(uv[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:v}),y?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:y}):null,b?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void g(b.next),disabled:f,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(b.labelKey),children:[(0,$.jsx)(X,{name:b.icon,className:C,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(b.labelKey)})]}):null]})});dv.displayName=`SessionGoalRow`;var fv=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=st(),{goal:i,enabled:a}=ov(e??``,t),o=Pt(e=>e.armed),s=Pt(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!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)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Rn(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),wr.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 f(),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`})})]})});fv.displayName=`SessionGoalButton`;var pv=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=st();if(!Pt(mv)||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,`/`,Yr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});pv.displayName=`SessionGoalObjectiveCounter`;function mv(e){return e.armed}var hv=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),gv=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),_v=/^\/\u2003?([^\s]+)/i,vv=/^\/\u2003?goal\b/i,yv=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(_v)?.[1]?.toLowerCase();return n&&hv.has(n)?n:null},bv=(e,t)=>yv(e,t)===`goal`?e.trimStart().replace(vv,``).trim():null,xv=(e,t)=>yv(e,t)!==null,Sv=(e,t)=>{let n=yv(e,t);return n!==null&&gv.has(n)},Cv=(e,t)=>{if(!e.includes(`/`)||t.size===0)return[];let n=RegExp(`(^|\\s)/(${te})?([A-Za-z0-9][A-Za-z0-9_-]*)(?=$|\\s)`,`g`),r=[],i;for(;(i=n.exec(e))!==null;){let e=i[3]??``;if(!t.has(e.toLowerCase()))continue;let n=i[2]??``,a=i.index+(i[1]?.length??0);r.push({start:a,end:a+1+n.length+e.length,name:e,hasSlot:n.length>0})}return r},wv=(e,t,n=e.length)=>{let r=Cv(e,t).filter(e=>!e.hasSlot);if(r.length===0)return null;let i=e,a=n;for(let e=r.length-1;e>=0;--e){let t=r[e].start+1;i=`${i.slice(0,t)}${te}${i.slice(t)}`,a>t&&(a+=te.length)}return i===e?null:{text:i,caret:a}},Tv=e=>e.startsWith(te)?e.slice(te.length):e,Ev=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Dv=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()}},Ov=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,kv=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,Av=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},jv=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Mv=(e,t)=>{let n=C.getState();return n.bindLegacyQueue(x(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},Nv=async e=>{let t=Jr.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=jv(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Mv(n,a)?r+=1:i+=1}catch{try{Mv(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Pv=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Fv=e=>e===`allow`||e===`ask`||e===`deny`,Iv=e=>{if(Fv(e))return[{permission:`*`,pattern:`*`,action:e}];if(Array.isArray(e))return e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.permission==`string`&&typeof t.pattern==`string`&&Fv(t.action)?[{permission:t.permission,pattern:t.pattern,action:t.action}]:[]});if(!e||typeof e!=`object`)return[];let t=[];for(let[n,r]of Object.entries(e))if(n!==`__originalKeys`){if(Fv(r)){t.push({permission:n,pattern:`*`,action:r});continue}if(!(!r||typeof r!=`object`||Array.isArray(r)))for(let[e,i]of Object.entries(r))Fv(i)&&t.push({permission:n,pattern:e,action:i})}return t},Lv=e=>{let t=Iv(e);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n.permission===`*`&&n.pattern===`*`)return n.action===`ask`;if(n.action===`ask`)return!0}return!0},Rv=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Lv(e.permission));let r=e.find(e=>e?.name===n);return!r||Lv(r.permission)},zv=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)},Bv=null,Vv=new Set,Hv=()=>{for(let e of Vv)e()},Uv=e=>e===`chat`||e===`assistant`,Wv=()=>Bv,Gv=e=>{Bv!==e&&(Bv=e,Hv())},Kv=e=>{Bv&&(e&&Bv.surfaceID!==e||(Bv=null,Hv()))},qv=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Jv=e=>{let t={...e.options?.delivery===`steer`?{delivery:`steer`}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},n=e.options?.sessionId??e.sessionID??void 0;if(!n)return t;let r=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...t,sessionId:n,directoryHint:r}},Yv=(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}),Xv=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=Yv(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=Yv(e,`send`,i),o=sm(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=Yv(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Yv(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Yv(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:sm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>em(e,{name:t,source:`openchamber`}),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=Yv(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Yv(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Zv=(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)))},Qv=(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},$v=(e,t)=>e.agents.some(e=>e.name===t),ey=(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},ty=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return ey(t,n,r,i)?i:void 0;if(a&&ey(t,n,r,a))return a},ny=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,sessionEntity:a,fallbackAgentName:o}=e;if(n?.providerID&&n.modelID&&Qv(r,n.providerID,n.modelID)){let e=n.agent&&$v(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&$v(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):o&&$v(r,o)?o:void 0,a=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=ty({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:a});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(i){let e=i.getSessionAgentSelection?.(t)??null,n=e&&$v(r,e)?e:o&&$v(r,o)?o:void 0;if(n){let e=i.getAgentModelForSession?.(t,n);if(e&&Qv(r,e.providerId,e.modelId)){let a=i.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=a&&ey(r,e.providerId,e.modelId,a)?a:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let a=i.getSessionModelSelection?.(t);if(a&&Qv(r,a.providerId,a.modelId)){let e=n?i.getAgentModelVariantForSession?.(t,n,a.providerId,a.modelId):void 0,o=e&&ey(r,a.providerId,a.modelId,e)?e:void 0;return{agent:n,providerID:a.providerId,modelID:a.modelId,variant:o,source:`session-memory`}}}let s=a?.model;if(s&&Qv(r,s.providerID,s.id)){let e=i?.getSessionAgentSelection?.(t)??null,n=(a?.agent&&$v(r,a.agent)?a.agent:void 0)??(e&&$v(r,e)?e:o&&$v(r,o)?o:void 0),c=s.variant,l=c&&ey(r,s.providerID,s.id,c)?c:void 0;return{agent:n,providerID:s.providerID,modelID:s.id,variant:l,source:`session-entity`}}return null},ry=(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))},iy=(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}},ay=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}:{}}},oy=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=typeof n.model?.providerID==`string`&&n.model.providerID.trim().length>0?n.model.providerID:void 0,i=typeof n.model?.modelID==`string`&&n.model.modelID.trim().length>0?n.model.modelID:void 0,a=typeof n.agent==`string`&&n.agent.trim().length>0?n.agent:typeof n.mode==`string`&&n.mode.trim().length>0?n.mode:void 0,o=n.model?.variant??n.variant,s=typeof o==`string`&&o.trim().length>0?o:void 0;return{id:typeof n.id==`string`?n.id:void 0,agent:a,providerID:r,modelID:i,variant:s}}return null},sy=500,cy=e=>Array.from(e).length,ly=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},uy=e=>cy(e)>=sy,dy=e=>{let t=v(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},fy=(e,t)=>{let n=t??e;return typeof n!=`string`||!uy(n)?!1:de(typeof e==`string`?{text:``,references:[]}:e,n)},py=(e,t,n,r,i=1)=>{let a=cy(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}-${ly(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},my=e=>({text:e.text,references:e.references.map(e=>({...e}))}),hy=e=>e.map(e=>({...e,range:{...e.range}})),gy=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),_y=(e,t,n)=>({document:my(e),mentions:hy(t),selection:{...n}}),vy=()=>({undo:[],redo:[]}),yy=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),by=(e,t)=>{let n=e.undo.at(-1);return!n||!gy(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:_y(n.before.document,n.before.mentions,n.before.selection)}},xy=(e,t)=>{let n=e.redo.at(-1);return!n||!gy(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:_y(n.after.document,n.after.mentions,n.after.selection)}},Sy=e=>({text:e?.text??``,references:e?.composerReferences??[]}),Cy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),wy=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),Ty=e=>JSON.stringify([e.text,e.references]),Ey=(e,t)=>e!==null&&t!==null&&ue(e)===t,Dy=(e,t,n)=>{let r=e?wy(e):null,i=r?n(r):void 0;return{document:D(Sy(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ue(r):null}},Oy=(e,t,n,r)=>{if(!t||ue(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=Ty(Sy(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===Ty(e)?`same-document-metadata`:`external-document`},ky=(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}]:[]})},Ay=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),jy=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:ky(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},My=(e,t,n)=>({preview:{real:Cy(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Ny=e=>({document:e.real,mentions:e.realMentions}),Py=(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)})},Fy=(e,t)=>{let n=Sy(t),r=E(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:Py(e.mentions,t?.mentions??[],r,i)}},Iy=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=Lt})=>{let a=e?ue(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)(()=>Dy(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>Dy(e,t,i.getState().getDraft).mentions),[m,h]=(0,Z.useState)(`compose`),_=(0,Z.useRef)(l),b=(0,Z.useRef)(d),x=(0,Z.useRef)(t),S=(0,Z.useRef)(r),C=(0,Z.useRef)(e),w=(0,Z.useRef)(e?wy(e):null),T=(0,Z.useRef)(a),E=(0,Z.useRef)(a),k=(0,Z.useRef)(0),A=(0,Z.useRef)(o?.revision??0),M=(0,Z.useRef)(void 0),N=(0,Z.useRef)(void 0),P=(0,Z.useRef)(vy());_.current=l,b.current=d,x.current=t,S.current=r,C.current=e,T.current=a;let F=(0,Z.useCallback)((e,t)=>{_.current=e,b.current=t,u(e),p(t)},[]),I=(0,Z.useCallback)((e,t)=>{let n=j(e,t);S.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{k.current+=1;let e=k.current;E.current=a;let t=Dy(C.current,x.current,i.getState().getDraft),n=t.key;if(w.current=t.key,M.current=void 0,N.current=void 0,P.current=vy(),h(`compose`),A.current=t.revision,F(t.document,t.mentions),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!Ey(w.current,a)||E.current!==a||T.current!==a||k.current!==e||A.current!==r||o?.revision!==t.revision||(A.current=t.revision,F(D(Sy(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=Oy(_.current,o,M.current,{keyID:a,epoch:k.current,appliedRevision:A.current});if(e!==`ignore`){if(o&&(A.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&p(o.mentions);return}e===`external-document`&&o&&(M.current=void 0,F(D(Sy(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!Ey(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Ay(t)});if(!a)return;let o=Sy(a);return M.current={keyID:ue(n),revision:a.revision,fingerprint:Ty(o)},A.current=a.revision,F(o,a.mentions),I(r,o),a},[i,F,I]),R=(0,Z.useCallback)((e,t,n,r,i,a)=>{P.current=yy(P.current,{before:_y(e,t,n),after:_y(r,i,a)})},[]),z=(0,Z.useCallback)(()=>N.current?(N.current=void 0,h(`compose`),!0):!1,[]),B=(0,Z.useCallback)(e=>(z(),L({text:e,references:[]},[])),[L,z]),V=(0,Z.useCallback)((e,t=[])=>{z();let n=se(e.text,e.references);return n?L(D(n,x.current),t):void 0},[L,z]),H=(0,Z.useCallback)((e,t,n=t,r)=>{let i=z(),a=Cy(_.current),o=i?[]:b.current,s=jy(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return L(s.document,c),s.removedReferences.length>0&&R(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}},[L,z,R]),U=(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=z(),o=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=ky(a?[]:b.current,o.document,o.edit);return L(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[L,z]),ee=(0,Z.useCallback)((e,t)=>{let n=_.current;return U({start:0,end:n.text.length,text:e},t)},[U]),te=(0,Z.useCallback)((e,t,n,r)=>{let i=z(),a=f(_.current,e,t,n,r);return L(a.document,ky(i?[]:b.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[L,z]),W=(0,Z.useCallback)(e=>{let t=Cy(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=ky(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=ky(i,o.document,o.edit);return L(o.document,s),R(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[L,z,R]),G=(0,Z.useCallback)(e=>{if(N.current)return null;let t=e===`undo`?by(P.current,_.current):xy(P.current,_.current);return!t||!L(t.snapshot.document,t.snapshot.mentions)?null:(P.current=t.history,t.snapshot.selection)},[L]),ne=(0,Z.useCallback)(e=>L(_.current,e),[L]),re=(0,Z.useCallback)(e=>{let t=N.current?{document:{text:e.text,references:[]},mentions:[]}:My(_.current,b.current,e);`preview`in t&&(N.current=t.preview),h(`history-preview`),F(t.document,t.mentions)},[F]),ie=(0,Z.useCallback)(()=>{let e=N.current;if(!e)return;N.current=void 0,h(`compose`);let t=Ny(e);F(t.document,t.mentions)},[F]),ae=(0,Z.useCallback)(()=>{let e=w.current;if(!Ey(e,T.current))return null;let t=i.getState().getDraft(e);return{key:wy(e),keyID:ue(e),revision:t?.revision??0,document:Cy(_.current),mentions:b.current.map(e=>({...e,range:{...e.range}})),epoch:k.current,runtime:i.getState().captureDraftRuntime()}},[i]),oe=(0,Z.useCallback)(e=>{let t=Fy(e,i.getState().getDraft(e.key)),n=Sy(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Ay(t.mentions)});if(a){let e=Sy(a);I(r,e)}return a},[I,i]),ce=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:m,hydration:s,persistence:c,getDocument:ce,replacePlainDocument:B,replaceMaterializedDocument:V,applyBrowserEdit:H,applyProgrammaticEdit:U,replaceProgrammaticText:ee,insertReference:te,deleteReference:W,restoreReferenceHistory:G,commitMentions:ne,enterHistoryPreview:re,exitHistoryPreview:ie,captureSubmission:ae,recoverSubmission:oe}),[H,U,ae,ne,W,l,re,ie,ce,s,m,te,d,c,oe,V,B,ee,G])};function Ly(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`}}var Ry=`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`,zy=Fo(()=>We(()=>import(`./ToolOutputDialog-UAKu6b6Z.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]))),By=[],Vy=[],Hy=[],Uy=[],Wy=/^@[^\s]+$/,Gy=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Ky=/^(https?:\/\/|mailto:)\S+$/i,qy=560,Jy=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Yy=(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)},Xy=e=>e.includes(`@`)?`paste`:`manual`,Zy=(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}},Qy=(e,t)=>Pi(e,t).some(e=>e.role===`user`),$y=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!sn(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6525
- `).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},eb=`file://`,tb=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(`/`)},nb=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(eb)?t:`file://${tb(t)}`},rb=e=>{if(!e)return[];let t=[...rv(e).map(iv),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(av)))},ib=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},ab=e=>ta(e.path),ob=(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)]})},sb=Z.memo(Dm),cb=Z.memo(pl),lb=Z.memo(Lh),ub=Z.memo(Bh),db=Z.memo(rh),fb=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=st(),r=s(e=>e.isMobile),i=J(e=>e.revertToMessage),a=J(e=>e.forkFromMessage),o=J(e=>e.handleSlashRedo),[c,l]=Z.useState(null),[u,d]=Z.useState(null),[f,p]=Z.useState(!0),m=Z.useRef(C_),h=oi(),g=t||h,_=Gn(g),v=Lr(e??``,g,_),y=$n(e=>e.session,g),b=Z.useMemo(()=>{let t=v.messageOrder.map(e=>v.messagesByID[e]).filter(e=>!!e),n=E_({session:y,messages:t,partsByMessageID:v.partsByMessageID},e,m.current);return m.current=n,n},[e,y,v]),x=b.revertMessageID,S=Z.useMemo(()=>b.records.map(e=>e.message),[b]),C=n(`chat.revertPopover.noTextContent`),w=Z.useMemo(()=>x?b.records.map(e=>({id:e.message.id,text:$y(e.parts,C)})):[],[C,x,b]),T=w[0]?.id;Z.useEffect(()=>{p(!0)},[x,T]);let E=Z.useCallback(async t=>{if(!(!e||c)){l(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{l(null)}}},[o,i,c,e,S]),D=Z.useCallback(async t=>{if(!(!e||u)){d(t);try{await a(e,t)}finally{d(null)}}},[a,u,e]);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:()=>p(e=>!e),"aria-expanded":!f,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!f&&`rotate-180`),"aria-hidden":`true`})]}),!f&&(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)(la,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{D(e.id)},children:[u===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)(la,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{E(e.id)},children:[c===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))})]})})});fb.displayName=`RevertedMessageDock`;var pb=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=st(),{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?Cb:void 0,v=f?wb:void 0,y;t[5]===a?y=t[6]:(y=Y(a,`text-current`),t[5]=a,t[6]=y);let b;t[7]===y?b=t[8]:(b=(0,$.jsx)(X,{name:`attachment-2`,className:y}),t[7]=y,t[8]=b);let x;t[9]!==m||t[10]!==i||t[11]!==g||t[12]!==_||t[13]!==v||t[14]!==b?(x=(0,$.jsx)(`button`,{type:`button`,className:i,onClick:g,onMouseDown:_,onPointerDownCapture:v,title:m,"aria-label":m,children:b}),t[9]=m,t[10]=i,t[11]=g,t[12]=_,t[13]=v,t[14]=b,t[15]=x):x=t[15];let S=x,C;t[16]!==S||t[17]!==m||t[18]!==d?(C=d?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:S}),(0,$.jsx)(La,{side:`top`,sideOffset:8,children:m})]}):S,t[16]=S,t[17]=m,t[18]=d,t[19]=C):C=t[19];let w;t[20]!==i||t[21]!==o||t[22]!==a||t[23]!==r||t[24]!==s||t[25]!==c||t[26]!==e.onMenuOpenChange||t[27]!==e.onOpenMobileSheet||t[28]!==n?(w=null,t[20]=i,t[21]=o,t[22]=a,t[23]=r,t[24]=s,t[25]=c,t[26]=e.onMenuOpenChange,t[27]=e.onOpenMobileSheet,t[28]=n,t[29]=w):w=t[29];let T;t[30]!==C||t[31]!==w?(T=(0,$.jsxs)(`div`,{className:`relative inline-flex`,children:[C,w]}),t[30]=C,t[31]=w,t[32]=T):T=t[32];let E;t[33]!==i||t[34]!==a||t[35]!==l||t[36]!==n?(E=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[33]=i,t[34]=a,t[35]=l,t[36]=n,t[37]=E):E=t[37];let D;return t[38]!==T||t[39]!==E?(D=(0,$.jsxs)(`div`,{className:`flex items-center gap-x-1.5`,children:[T,E]}),t[38]=T,t[39]=E,t[40]=D):D=t[40],D},(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),mb=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=st(),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=()=>zv({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)(Ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:Tb,onPointerDownCapture:Eb,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)(La,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Ra,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),hb=Z.memo(function(e){let t=(0,Q.c)(59),{isMobile:n,footerIconButtonClass:r,stopFooterIconButtonClass:i,sendIconSizeClass:a,stopIconSizeClass:o,canSend:s,canAbort:c,hasContent:l,currentSessionId:u,newSessionDraftOpen:d,draftSubmitting:f,submissionBlocked:p,sendPhase:m,queueFrozen:h,queueFallbackAvailable:g,onPrimaryAction:_,onAbort:v}=e,{t:y}=st(),b,x,S;if(t[0]!==c||t[1]!==s||t[2]!==u||t[3]!==f||t[4]!==r||t[5]!==l||t[6]!==n||t[7]!==d||t[8]!==_||t[9]!==g||t[10]!==h||t[11]!==a||t[12]!==m||t[13]!==p||t[14]!==y){S=Symbol.for(`react.early_return_sentinel`);bb0:{let e=eg({canSend:s,hasSessionTarget:!!(u||d),draftSubmitting:!!f,submissionBlocked:p,sendPhase:m,queueFrozen:h,queueFallbackAvailable:g}),i;t[18]===n?i=t[19]:(i=n?{onMouseDown:Db,onPointerDownCapture:Ob}:{},t[18]=n,t[19]=i);let o=i,v=m.inFlight,C=v&&m.flightKind===`queue`,w=v&&m.flightKind!==`queue`,T;t[20]!==c||t[21]!==g||t[22]!==h||t[23]!==C||t[24]!==w||t[25]!==y?(T=y(C?`chat.chatInput.actions.queuingMessageAria`:w?`chat.chatInput.actions.sendingMessageAria`:h&&g&&c?`chat.chatInput.actions.sendMessageAria`:c?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[20]=c,t[21]=g,t[22]=h,t[23]=C,t[24]=w,t[25]=y,t[26]=T):T=t[26];let E=T,D=v?`loader-4`:`send-plane-2`,O=e.sendDisabled,k;t[27]!==n||t[28]!==_?(k=e=>{n&&(e.preventDefault(),_())},t[27]=n,t[28]=_,t[29]=k):k=t[29];let A=Y(r,e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),j;t[30]!==c||t[31]!==v||t[32]!==C||t[33]!==w||t[34]!==y?(j=y(w||!c&&v?C?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[30]=c,t[31]=v,t[32]=C,t[33]=w,t[34]=y,t[35]=j):j=t[35];let M=v?`loader-4`:`send-plane-2`,N=v&&`animate-spin`,P;t[36]!==a||t[37]!==N?(P=Y(a,N),t[36]=a,t[37]=N,t[38]=P):P=t[38];let F;t[39]!==P||t[40]!==M?(F=(0,$.jsx)(X,{name:M,className:P}),t[39]=P,t[40]=M,t[41]=F):F=t[41];let I=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,disabled:O,"aria-busy":v||void 0,...o,onClick:k,className:A,"aria-label":j,children:F});if(!c){S=I;break bb0}b=`relative z-30 overflow-visible`,x=l||C?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,disabled:e.sendDisabled||C,"aria-busy":C||void 0,...o,onClick:e=>{e.preventDefault(),!C&&_()},className:Y(r,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,!e.sendDisabled&&!C?`text-primary hover:text-primary`:e.disabledClass),"aria-label":E,children:(0,$.jsx)(X,{name:D,className:Y(a,C?`animate-spin`:`-rotate-90`)})}):null}t[0]=c,t[1]=s,t[2]=u,t[3]=f,t[4]=r,t[5]=l,t[6]=n,t[7]=d,t[8]=_,t[9]=g,t[10]=h,t[11]=a,t[12]=m,t[13]=p,t[14]=y,t[15]=b,t[16]=x,t[17]=S}else b=t[15],x=t[16],S=t[17];if(S!==Symbol.for(`react.early_return_sentinel`))return S;let C=i??r,w;t[42]===C?w=t[43]:(w=Y(C,`relative z-30 !text-black hover:!text-black dark:!text-white dark:hover:!text-white`),t[42]=C,t[43]=w);let T;t[44]===y?T=t[45]:(T=y(`chat.chatInput.actions.stopGeneratingAria`),t[44]=y,t[45]=T);let E;t[46]===o?E=t[47]:(E=Y(o),t[46]=o,t[47]=E);let D;t[48]===E?D=t[49]:(D=(0,$.jsx)(qh,{className:E}),t[48]=E,t[49]=D);let O;t[50]!==v||t[51]!==w||t[52]!==T||t[53]!==D?(O=(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,onClick:v,className:w,"aria-label":T,children:D}),t[50]=v,t[51]=w,t[52]=T,t[53]=D,t[54]=O):O=t[54];let k;return t[55]!==b||t[56]!==x||t[57]!==O?(k=(0,$.jsxs)(`div`,{className:b,children:[x,O]}),t[55]=b,t[56]=x,t[57]=O,t[58]=k):k=t[58],k},(e,t)=>e.isMobile===t.isMobile&&e.footerIconButtonClass===t.footerIconButtonClass&&e.stopFooterIconButtonClass===t.stopFooterIconButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&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),gb=(e,t)=>`${e}${e?e.endsWith(`
6524
+ `);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${V_} text-[var(--syntax-foreground)]`,priority:H_}),!(d.length>J_)))try{let e=o.parser.parse(d);Xe(e,K_,(e,n,r)=>{let i=q_(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:U_})})}catch{}}return t}var Z_=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Q_=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),$_=e=>{if(!Q_(e)||/\s/.test(e))return!1;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(`/`)},ev=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?$_(n):Q_(n))?n:null},tv=(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)tv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))tv(r,t,n+1)}},nv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=ev(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=ev(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;tv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},rv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Z_){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 nv(r,i))t.add(e)}return Array.from(t)},iv=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}}},av=e=>Q_(e);function ov(e,t){let n=(0,Q.c)(5),r=lr(e,t),i=s(sv),a;n[0]===r?a=n[1]:(a=dn(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 sv(e){return e.sessionGoalEnabled}function cv(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 Dt(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 lv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},uv={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`},dv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ot(),i=s(e=>e.isMobile),{goal:a,enabled:o}=ov(e??``,t),c=cv(e??``,a),l=Tr(e??``,t),u=tr(e,t),d=Z.useRef(null),[f,p]=Z.useState(!1),[m,h]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>h(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=u[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;d.current!==r&&(d.current=r,St(e,t))},[e,t,a,u]);let g=q(async n=>{if(!(!e||f)){p(!0);try{await vn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Cr.error(r(`chat.goal.toast.actionFailed`))}finally{p(!1)}}});if(!e||!o||!a)return null;let _=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:m)-(a.createdAt||m)),v=mt(_),y=a.tokenBudget?`${Gr(a.tokensUsed)}/${Gr(a.tokenBudget)}`:a.tokensUsed>0?Gr(a.tokensUsed):null,b=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,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=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:c??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:lv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||c||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(uv[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:v}),y?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:y}):null,b?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void g(b.next),disabled:f,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(b.labelKey),children:[(0,$.jsx)(X,{name:b.icon,className:C,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(b.labelKey)})]}):null]})});dv.displayName=`SessionGoalRow`;var fv=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ot(),{goal:i,enabled:a}=ov(e??``,t),o=Nt(e=>e.armed),s=Nt(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!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)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Ln(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Cr.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 f(),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`})})]})});fv.displayName=`SessionGoalButton`;var pv=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ot();if(!Nt(mv)||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,`/`,Jr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});pv.displayName=`SessionGoalObjectiveCounter`;function mv(e){return e.armed}var hv=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),gv=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),_v=/^\/\u2003?([^\s]+)/i,vv=/^\/\u2003?goal\b/i,yv=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(_v)?.[1]?.toLowerCase();return n&&hv.has(n)?n:null},bv=(e,t)=>yv(e,t)===`goal`?e.trimStart().replace(vv,``).trim():null,xv=(e,t)=>yv(e,t)!==null,Sv=(e,t)=>{let n=yv(e,t);return n!==null&&gv.has(n)},Cv=(e,t)=>{if(!e.includes(`/`)||t.size===0)return[];let n=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)(?=$|\\s)`,`g`),r=[],i;for(;(i=n.exec(e))!==null;){let e=i[3]??``;if(!t.has(e.toLowerCase()))continue;let n=i[2]??``,a=i.index+(i[1]?.length??0);r.push({start:a,end:a+1+n.length+e.length,name:e,hasSlot:n.length>0})}return r},wv=(e,t,n=e.length)=>{let r=Cv(e,t).filter(e=>!e.hasSlot);if(r.length===0)return null;let i=e,a=n;for(let e=r.length-1;e>=0;--e){let t=r[e].start+1;i=`${i.slice(0,t)}${ee}${i.slice(t)}`,a>t&&(a+=ee.length)}return i===e?null:{text:i,caret:a}},Tv=e=>e.startsWith(ee)?e.slice(ee.length):e,Ev=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Dv=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()}},Ov=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,kv=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,Av=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},jv=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Mv=(e,t)=>{let n=C.getState();return n.bindLegacyQueue(x(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},Nv=async e=>{let t=qr.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=jv(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Mv(n,a)?r+=1:i+=1}catch{try{Mv(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Pv=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Fv=e=>e===`allow`||e===`ask`||e===`deny`,Iv=e=>{if(Fv(e))return[{permission:`*`,pattern:`*`,action:e}];if(Array.isArray(e))return e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.permission==`string`&&typeof t.pattern==`string`&&Fv(t.action)?[{permission:t.permission,pattern:t.pattern,action:t.action}]:[]});if(!e||typeof e!=`object`)return[];let t=[];for(let[n,r]of Object.entries(e))if(n!==`__originalKeys`){if(Fv(r)){t.push({permission:n,pattern:`*`,action:r});continue}if(!(!r||typeof r!=`object`||Array.isArray(r)))for(let[e,i]of Object.entries(r))Fv(i)&&t.push({permission:n,pattern:e,action:i})}return t},Lv=e=>{let t=Iv(e);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n.permission===`*`&&n.pattern===`*`)return n.action===`ask`;if(n.action===`ask`)return!0}return!0},Rv=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Lv(e.permission));let r=e.find(e=>e?.name===n);return!r||Lv(r.permission)},zv=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)},Bv=null,Vv=new Set,Hv=()=>{for(let e of Vv)e()},Uv=e=>e===`chat`||e===`assistant`,Wv=()=>Bv,Gv=e=>{Bv!==e&&(Bv=e,Hv())},Kv=e=>{Bv&&(e&&Bv.surfaceID!==e||(Bv=null,Hv()))},qv=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Jv=e=>{let t={...e.options?.delivery===`steer`?{delivery:`steer`}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},n=e.options?.sessionId??e.sessionID??void 0;if(!n)return t;let r=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...t,sessionId:n,directoryHint:r}},Yv=(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}),Xv=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=Yv(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=Yv(e,`send`,i),o=sm(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=Yv(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Yv(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Yv(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:sm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>em(e,{name:t,source:`openchamber`}),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=Yv(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Yv(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Zv=(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)))},Qv=(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},$v=(e,t)=>e.agents.some(e=>e.name===t),ey=(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},ty=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return ey(t,n,r,i)?i:void 0;if(a&&ey(t,n,r,a))return a},ny=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,sessionEntity:a,fallbackAgentName:o}=e;if(n?.providerID&&n.modelID&&Qv(r,n.providerID,n.modelID)){let e=n.agent&&$v(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&$v(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):o&&$v(r,o)?o:void 0,a=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=ty({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:a});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(i){let e=i.getSessionAgentSelection?.(t)??null,n=e&&$v(r,e)?e:o&&$v(r,o)?o:void 0;if(n){let e=i.getAgentModelForSession?.(t,n);if(e&&Qv(r,e.providerId,e.modelId)){let a=i.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=a&&ey(r,e.providerId,e.modelId,a)?a:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let a=i.getSessionModelSelection?.(t);if(a&&Qv(r,a.providerId,a.modelId)){let e=n?i.getAgentModelVariantForSession?.(t,n,a.providerId,a.modelId):void 0,o=e&&ey(r,a.providerId,a.modelId,e)?e:void 0;return{agent:n,providerID:a.providerId,modelID:a.modelId,variant:o,source:`session-memory`}}}let s=a?.model;if(s&&Qv(r,s.providerID,s.id)){let e=i?.getSessionAgentSelection?.(t)??null,n=(a?.agent&&$v(r,a.agent)?a.agent:void 0)??(e&&$v(r,e)?e:o&&$v(r,o)?o:void 0),c=s.variant,l=c&&ey(r,s.providerID,s.id,c)?c:void 0;return{agent:n,providerID:s.providerID,modelID:s.id,variant:l,source:`session-entity`}}return null},ry=(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))},iy=(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}},ay=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}:{}}},oy=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=typeof n.model?.providerID==`string`&&n.model.providerID.trim().length>0?n.model.providerID:void 0,i=typeof n.model?.modelID==`string`&&n.model.modelID.trim().length>0?n.model.modelID:void 0,a=typeof n.agent==`string`&&n.agent.trim().length>0?n.agent:typeof n.mode==`string`&&n.mode.trim().length>0?n.mode:void 0,o=n.model?.variant??n.variant,s=typeof o==`string`&&o.trim().length>0?o:void 0;return{id:typeof n.id==`string`?n.id:void 0,agent:a,providerID:r,modelID:i,variant:s}}return null},sy=500,cy=e=>Array.from(e).length,ly=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},uy=e=>cy(e)>=sy,dy=e=>{let t=v(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},fy=(e,t)=>{let n=t??e;return typeof n!=`string`||!uy(n)?!1:ue(typeof e==`string`?{text:``,references:[]}:e,n)},py=(e,t,n,r,i=1)=>{let a=cy(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}-${ly(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},my=e=>({text:e.text,references:e.references.map(e=>({...e}))}),hy=e=>e.map(e=>({...e,range:{...e.range}})),gy=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),_y=(e,t,n)=>({document:my(e),mentions:hy(t),selection:{...n}}),vy=()=>({undo:[],redo:[]}),yy=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),by=(e,t)=>{let n=e.undo.at(-1);return!n||!gy(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:_y(n.before.document,n.before.mentions,n.before.selection)}},xy=(e,t)=>{let n=e.redo.at(-1);return!n||!gy(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:_y(n.after.document,n.after.mentions,n.after.selection)}},Sy=e=>({text:e?.text??``,references:e?.composerReferences??[]}),Cy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),wy=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),Ty=e=>JSON.stringify([e.text,e.references]),Ey=(e,t)=>e!==null&&t!==null&&le(e)===t,Dy=(e,t,n)=>{let r=e?wy(e):null,i=r?n(r):void 0;return{document:D(Sy(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?le(r):null}},Oy=(e,t,n,r)=>{if(!t||le(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=Ty(Sy(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===Ty(e)?`same-document-metadata`:`external-document`},ky=(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}]:[]})},Ay=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),jy=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:ky(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},My=(e,t,n)=>({preview:{real:Cy(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Ny=e=>({document:e.real,mentions:e.realMentions}),Py=(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)})},Fy=(e,t)=>{let n=Sy(t),r=E(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:Py(e.mentions,t?.mentions??[],r,i)}},Iy=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=It})=>{let a=e?le(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)(()=>Dy(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>Dy(e,t,i.getState().getDraft).mentions),[m,h]=(0,Z.useState)(`compose`),_=(0,Z.useRef)(l),b=(0,Z.useRef)(d),x=(0,Z.useRef)(t),S=(0,Z.useRef)(r),C=(0,Z.useRef)(e),w=(0,Z.useRef)(e?wy(e):null),T=(0,Z.useRef)(a),E=(0,Z.useRef)(a),k=(0,Z.useRef)(0),A=(0,Z.useRef)(o?.revision??0),M=(0,Z.useRef)(void 0),N=(0,Z.useRef)(void 0),P=(0,Z.useRef)(vy());_.current=l,b.current=d,x.current=t,S.current=r,C.current=e,T.current=a;let F=(0,Z.useCallback)((e,t)=>{_.current=e,b.current=t,u(e),p(t)},[]),I=(0,Z.useCallback)((e,t)=>{let n=j(e,t);S.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{k.current+=1;let e=k.current;E.current=a;let t=Dy(C.current,x.current,i.getState().getDraft),n=t.key;if(w.current=t.key,M.current=void 0,N.current=void 0,P.current=vy(),h(`compose`),A.current=t.revision,F(t.document,t.mentions),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!Ey(w.current,a)||E.current!==a||T.current!==a||k.current!==e||A.current!==r||o?.revision!==t.revision||(A.current=t.revision,F(D(Sy(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=Oy(_.current,o,M.current,{keyID:a,epoch:k.current,appliedRevision:A.current});if(e!==`ignore`){if(o&&(A.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&p(o.mentions);return}e===`external-document`&&o&&(M.current=void 0,F(D(Sy(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!Ey(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Ay(t)});if(!a)return;let o=Sy(a);return M.current={keyID:le(n),revision:a.revision,fingerprint:Ty(o)},A.current=a.revision,F(o,a.mentions),I(r,o),a},[i,F,I]),R=(0,Z.useCallback)((e,t,n,r,i,a)=>{P.current=yy(P.current,{before:_y(e,t,n),after:_y(r,i,a)})},[]),z=(0,Z.useCallback)(()=>N.current?(N.current=void 0,h(`compose`),!0):!1,[]),B=(0,Z.useCallback)(e=>(z(),L({text:e,references:[]},[])),[L,z]),V=(0,Z.useCallback)((e,t=[])=>{z();let n=oe(e.text,e.references);return n?L(D(n,x.current),t):void 0},[L,z]),H=(0,Z.useCallback)((e,t,n=t,r)=>{let i=z(),a=Cy(_.current),o=i?[]:b.current,s=jy(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return L(s.document,c),s.removedReferences.length>0&&R(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}},[L,z,R]),U=(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=z(),o=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=ky(a?[]:b.current,o.document,o.edit);return L(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[L,z]),W=(0,Z.useCallback)((e,t)=>{let n=_.current;return U({start:0,end:n.text.length,text:e},t)},[U]),ee=(0,Z.useCallback)((e,t,n,r)=>{let i=z(),a=f(_.current,e,t,n,r);return L(a.document,ky(i?[]:b.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[L,z]),G=(0,Z.useCallback)(e=>{let t=Cy(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=ky(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=ky(i,o.document,o.edit);return L(o.document,s),R(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[L,z,R]),K=(0,Z.useCallback)(e=>{if(N.current)return null;let t=e===`undo`?by(P.current,_.current):xy(P.current,_.current);return!t||!L(t.snapshot.document,t.snapshot.mentions)?null:(P.current=t.history,t.snapshot.selection)},[L]),te=(0,Z.useCallback)(e=>L(_.current,e),[L]),ne=(0,Z.useCallback)(e=>{let t=N.current?{document:{text:e.text,references:[]},mentions:[]}:My(_.current,b.current,e);`preview`in t&&(N.current=t.preview),h(`history-preview`),F(t.document,t.mentions)},[F]),re=(0,Z.useCallback)(()=>{let e=N.current;if(!e)return;N.current=void 0,h(`compose`);let t=Ny(e);F(t.document,t.mentions)},[F]),ie=(0,Z.useCallback)(()=>{let e=w.current;if(!Ey(e,T.current))return null;let t=i.getState().getDraft(e);return{key:wy(e),keyID:le(e),revision:t?.revision??0,document:Cy(_.current),mentions:b.current.map(e=>({...e,range:{...e.range}})),epoch:k.current,runtime:i.getState().captureDraftRuntime()}},[i]),ae=(0,Z.useCallback)(e=>{let t=Fy(e,i.getState().getDraft(e.key)),n=Sy(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Ay(t.mentions)});if(a){let e=Sy(a);I(r,e)}return a},[I,i]),se=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:m,hydration:s,persistence:c,getDocument:se,replacePlainDocument:B,replaceMaterializedDocument:V,applyBrowserEdit:H,applyProgrammaticEdit:U,replaceProgrammaticText:W,insertReference:ee,deleteReference:G,restoreReferenceHistory:K,commitMentions:te,enterHistoryPreview:ne,exitHistoryPreview:re,captureSubmission:ie,recoverSubmission:ae}),[H,U,ie,te,G,l,ne,re,se,s,m,ee,d,c,ae,V,B,W,K])};function Ly(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`}}var Ry=`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`,zy=Fo(()=>Ue(()=>import(`./ToolOutputDialog-B7vUFIz4.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]))),By=[],Vy=[],Hy=[],Uy=[],Wy=/^@[^\s]+$/,Gy=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Ky=/^(https?:\/\/|mailto:)\S+$/i,qy=560,Jy=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Yy=(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)},Xy=e=>e.includes(`@`)?`paste`:`manual`,Zy=(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}},Qy=(e,t)=>Pi(e,t).some(e=>e.role===`user`),$y=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!on(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6525
+ `).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},eb=`file://`,tb=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(`/`)},nb=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(eb)?t:`file://${tb(t)}`},rb=e=>{if(!e)return[];let t=[...rv(e).map(iv),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(av)))},ib=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},ab=e=>ta(e.path),ob=(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)]})},sb=Z.memo(Dm),cb=Z.memo(pl),lb=Z.memo(Lh),ub=Z.memo(Bh),db=Z.memo(rh),fb=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ot(),r=s(e=>e.isMobile),i=Qr(e=>e.revertToMessage),a=Qr(e=>e.forkFromMessage),o=Qr(e=>e.handleSlashRedo),[c,l]=Z.useState(null),[u,d]=Z.useState(null),[f,p]=Z.useState(!0),m=Z.useRef(C_),h=oi(),g=t||h,_=Wn(g),v=Ir(e??``,g,_),y=Qn(e=>e.session,g),b=Z.useMemo(()=>{let t=v.messageOrder.map(e=>v.messagesByID[e]).filter(e=>!!e),n=E_({session:y,messages:t,partsByMessageID:v.partsByMessageID},e,m.current);return m.current=n,n},[e,y,v]),x=b.revertMessageID,S=Z.useMemo(()=>b.records.map(e=>e.message),[b]),C=n(`chat.revertPopover.noTextContent`),w=Z.useMemo(()=>x?b.records.map(e=>({id:e.message.id,text:$y(e.parts,C)})):[],[C,x,b]),T=w[0]?.id;Z.useEffect(()=>{p(!0)},[x,T]);let E=Z.useCallback(async t=>{if(!(!e||c)){l(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{l(null)}}},[o,i,c,e,S]),D=Z.useCallback(async t=>{if(!(!e||u)){d(t);try{await a(e,t)}finally{d(null)}}},[a,u,e]);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:()=>p(e=>!e),"aria-expanded":!f,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!f&&`rotate-180`),"aria-hidden":`true`})]}),!f&&(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)(la,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{D(e.id)},children:[u===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)(la,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{E(e.id)},children:[c===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))})]})})});fb.displayName=`RevertedMessageDock`;var pb=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=ot(),{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?Cb:void 0,v=f?wb:void 0,y;t[5]===a?y=t[6]:(y=Y(a,`text-current`),t[5]=a,t[6]=y);let b;t[7]===y?b=t[8]:(b=(0,$.jsx)(X,{name:`attachment-2`,className:y}),t[7]=y,t[8]=b);let x;t[9]!==m||t[10]!==i||t[11]!==g||t[12]!==_||t[13]!==v||t[14]!==b?(x=(0,$.jsx)(`button`,{type:`button`,className:i,onClick:g,onMouseDown:_,onPointerDownCapture:v,title:m,"aria-label":m,children:b}),t[9]=m,t[10]=i,t[11]=g,t[12]=_,t[13]=v,t[14]=b,t[15]=x):x=t[15];let S=x,C;t[16]!==S||t[17]!==m||t[18]!==d?(C=d?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:S}),(0,$.jsx)(La,{side:`top`,sideOffset:8,children:m})]}):S,t[16]=S,t[17]=m,t[18]=d,t[19]=C):C=t[19];let w;t[20]!==i||t[21]!==o||t[22]!==a||t[23]!==r||t[24]!==s||t[25]!==c||t[26]!==e.onMenuOpenChange||t[27]!==e.onOpenMobileSheet||t[28]!==n?(w=null,t[20]=i,t[21]=o,t[22]=a,t[23]=r,t[24]=s,t[25]=c,t[26]=e.onMenuOpenChange,t[27]=e.onOpenMobileSheet,t[28]=n,t[29]=w):w=t[29];let T;t[30]!==C||t[31]!==w?(T=(0,$.jsxs)(`div`,{className:`relative inline-flex`,children:[C,w]}),t[30]=C,t[31]=w,t[32]=T):T=t[32];let E;t[33]!==i||t[34]!==a||t[35]!==l||t[36]!==n?(E=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[33]=i,t[34]=a,t[35]=l,t[36]=n,t[37]=E):E=t[37];let D;return t[38]!==T||t[39]!==E?(D=(0,$.jsxs)(`div`,{className:`flex items-center gap-x-1.5`,children:[T,E]}),t[38]=T,t[39]=E,t[40]=D):D=t[40],D},(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),mb=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=ot(),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=()=>zv({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)(Ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:Tb,onPointerDownCapture:Eb,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)(La,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Ra,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),hb=Z.memo(function(e){let t=(0,Q.c)(59),{isMobile:n,footerIconButtonClass:r,stopFooterIconButtonClass:i,sendIconSizeClass:a,stopIconSizeClass:o,canSend:s,canAbort:c,hasContent:l,currentSessionId:u,newSessionDraftOpen:d,draftSubmitting:f,submissionBlocked:p,sendPhase:m,queueFrozen:h,queueFallbackAvailable:g,onPrimaryAction:_,onAbort:v}=e,{t:y}=ot(),b,x,S;if(t[0]!==c||t[1]!==s||t[2]!==u||t[3]!==f||t[4]!==r||t[5]!==l||t[6]!==n||t[7]!==d||t[8]!==_||t[9]!==g||t[10]!==h||t[11]!==a||t[12]!==m||t[13]!==p||t[14]!==y){S=Symbol.for(`react.early_return_sentinel`);bb0:{let e=eg({canSend:s,hasSessionTarget:!!(u||d),draftSubmitting:!!f,submissionBlocked:p,sendPhase:m,queueFrozen:h,queueFallbackAvailable:g}),i;t[18]===n?i=t[19]:(i=n?{onMouseDown:Db,onPointerDownCapture:Ob}:{},t[18]=n,t[19]=i);let o=i,v=m.inFlight,C=v&&m.flightKind===`queue`,w=v&&m.flightKind!==`queue`,T;t[20]!==c||t[21]!==g||t[22]!==h||t[23]!==C||t[24]!==w||t[25]!==y?(T=y(C?`chat.chatInput.actions.queuingMessageAria`:w?`chat.chatInput.actions.sendingMessageAria`:h&&g&&c?`chat.chatInput.actions.sendMessageAria`:c?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[20]=c,t[21]=g,t[22]=h,t[23]=C,t[24]=w,t[25]=y,t[26]=T):T=t[26];let E=T,D=v?`loader-4`:`send-plane-2`,O=e.sendDisabled,k;t[27]!==n||t[28]!==_?(k=e=>{n&&(e.preventDefault(),_())},t[27]=n,t[28]=_,t[29]=k):k=t[29];let A=Y(r,e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),j;t[30]!==c||t[31]!==v||t[32]!==C||t[33]!==w||t[34]!==y?(j=y(w||!c&&v?C?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[30]=c,t[31]=v,t[32]=C,t[33]=w,t[34]=y,t[35]=j):j=t[35];let M=v?`loader-4`:`send-plane-2`,N=v&&`animate-spin`,P;t[36]!==a||t[37]!==N?(P=Y(a,N),t[36]=a,t[37]=N,t[38]=P):P=t[38];let F;t[39]!==P||t[40]!==M?(F=(0,$.jsx)(X,{name:M,className:P}),t[39]=P,t[40]=M,t[41]=F):F=t[41];let I=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,disabled:O,"aria-busy":v||void 0,...o,onClick:k,className:A,"aria-label":j,children:F});if(!c){S=I;break bb0}b=`relative z-30 overflow-visible`,x=l||C?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,disabled:e.sendDisabled||C,"aria-busy":C||void 0,...o,onClick:e=>{e.preventDefault(),!C&&_()},className:Y(r,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,!e.sendDisabled&&!C?`text-primary hover:text-primary`:e.disabledClass),"aria-label":E,children:(0,$.jsx)(X,{name:D,className:Y(a,C?`animate-spin`:`-rotate-90`)})}):null}t[0]=c,t[1]=s,t[2]=u,t[3]=f,t[4]=r,t[5]=l,t[6]=n,t[7]=d,t[8]=_,t[9]=g,t[10]=h,t[11]=a,t[12]=m,t[13]=p,t[14]=y,t[15]=b,t[16]=x,t[17]=S}else b=t[15],x=t[16],S=t[17];if(S!==Symbol.for(`react.early_return_sentinel`))return S;let C=i??r,w;t[42]===C?w=t[43]:(w=Y(C,`relative z-30 !text-black hover:!text-black dark:!text-white dark:hover:!text-white`),t[42]=C,t[43]=w);let T;t[44]===y?T=t[45]:(T=y(`chat.chatInput.actions.stopGeneratingAria`),t[44]=y,t[45]=T);let E;t[46]===o?E=t[47]:(E=Y(o),t[46]=o,t[47]=E);let D;t[48]===E?D=t[49]:(D=(0,$.jsx)(qh,{className:E}),t[48]=E,t[49]=D);let O;t[50]!==v||t[51]!==w||t[52]!==T||t[53]!==D?(O=(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,onClick:v,className:w,"aria-label":T,children:D}),t[50]=v,t[51]=w,t[52]=T,t[53]=D,t[54]=O):O=t[54];let k;return t[55]!==b||t[56]!==x||t[57]!==O?(k=(0,$.jsxs)(`div`,{className:b,children:[x,O]}),t[55]=b,t[56]=x,t[57]=O,t[58]=k):k=t[58],k},(e,t)=>e.isMobile===t.isMobile&&e.footerIconButtonClass===t.footerIconButtonClass&&e.stopFooterIconButtonClass===t.stopFooterIconButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&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),gb=(e,t)=>`${e}${e?e.endsWith(`
6526
6526
 
6527
6527
  `)?``:e.endsWith(`
6528
6528
  `)?`
@@ -6531,12 +6531,12 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
6531
6531
  `:``}${t.endsWith(`
6532
6532
 
6533
6533
  `)?t:t.endsWith(`
6534
- `)?`${t}\n`:`${t}\n\n`}`,_b=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},vb=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,yb=[],bb=({onOpenSettings:e,scrollToBottom:r,showScrollToBottom:a=!1,onScrollToBottom:o,submissionBlocked:l=!1,surface:u})=>{let{t:f}=st(),[p,m]=Z.useState({open:!1,title:``,content:``}),[h,g]=Z.useState(`normal`),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(!1),[k,j]=Z.useState(``),[M,N]=Z.useState(!1),[P,I]=Z.useState(``),[R,z]=Z.useState(!1),[V,H]=Z.useState(``),[ne,re]=Z.useState(!1),[oe,se]=Z.useState(``),[ce,le]=Z.useState(null),[de,fe]=Z.useState(null),pe=Z.useRef(null),me=Z.useRef(null),[he,ge]=Z.useState(!1),_e=Z.useRef(null);Z.useEffect(()=>()=>{_e.current!==null&&window.clearTimeout(_e.current),pe.current!==null&&window.clearTimeout(pe.current),me.current!==null&&window.clearTimeout(me.current)},[]);let[ve,ye]=Z.useState(!1),[be,xe]=Z.useState(!1),[Se,Ce]=Z.useState(null),we=Z.useId(),[Oe,je]=Z.useState(``),[Ne,Pe]=Z.useState(``),[Fe,Ie]=Z.useState(!1),[Le,Be]=Z.useState(!1),He=Z.useRef(0),Ue=Z.useCallback(()=>{He.current=Date.now()+500},[]),We=Z.useRef(0),Ge=Z.useRef(!1),[Ke,qe]=Z.useState(-1),Je=Z.useRef(()=>{}),Ye=Z.useRef((...e)=>Promise.resolve().then(()=>J.getState().sendMessage(...e))).current,Xe=J(e=>e.currentSessionId),Ze=mi(e=>e.currentProviderId),Qe=mi(e=>e.currentModelId),$e=mi(e=>e.currentAgentName),et=mi(e=>e.currentVariant),tt=mi(e=>e.providers),nt=mi(e=>e.agents),rt=mi(e=>e.getVisibleAgents),it=Z.useMemo(()=>Wp(rt()),[rt,nt]),at=mi(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ot=mi(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ct=Z.useMemo(()=>{let e=tt.find(e=>e.id===Ze)?.models?.find(e=>e.id===Qe);return Zp(e)},[Qe,Ze,tt]),lt=Ee(e=>e.currentDirectory),ut=is()??lt,{ensureSessionRenderable:dt}=zl(),pt=J(Z.useCallback(e=>Xe?e.getDirectoryForSession(Xe):null,[Xe])),mt=Di(Xe??``,pt??void 0),ht=Z.useMemo(()=>oy(mt),[mt]),gt=ur(Xe,pt??void 0),_t=gt?.agent,yt=gt?.model?.id,xt=gt?.model?.providerID,St=gt?.model?.variant,Ct=mi(e=>e.activeDirectoryKey),wt=Z.useRef(0),Tt=Z.useRef(null),Et=J(e=>e.newSessionDraft),Ot=!!Et?.open,kt=J(e=>e.newSessionDraft.draftSubmitting??!1),At=J(e=>e.newSessionDraft.draftEstablishing??!1),jt=kt||At,Nt=J(e=>e.openNewSessionDraft),It=J(e=>e.setDraftPermissionAutoAcceptEnabled),Rt=Cr(e=>e.autoAccept),zt=Cr(e=>e.saving),Ht=Cr(e=>e.setSessionAutoAccept),Ut=J(e=>e.setNewSessionDraftTarget),Wt=J(e=>e.availableWorktreesByProject),Gt=J(e=>e.abortPromptSessionId),Jt=J(e=>e.clearAbortPrompt),Yt=Lt(e=>e.consumePendingInputText),Xt=Lt(e=>e.pendingPresetSubmit),Zt=Lt(e=>e.pendingInputText),Qt=Lt(e=>e.pendingInputMode),tn=Lt(e=>e.consumePendingSyntheticParts),nn=Lt(e=>e.activeAttachmentDraft),rn=Gl(Z.useCallback(e=>{let t=Xe??(Ot?`draft`:``);return t?e.drafts[t]??Vy:Vy},[Ot,Xe])),on=Br(Xe??``),sn=Z.useSyncExternalStore(t,n,n),cn=nn?.transportIdentity??null,un=nn?.owner.kind??null,dn=nn?.owner.ownerID??null,fn=Z.useMemo(()=>vb(sn,Xe,Et.draftID,cn&&un&&dn?{transportIdentity:cn,owner:{kind:un,ownerID:dn}}:null),[dn,un,cn,sn,Xe,Et.draftID]),pn=fn?ue(fn):null,mn=Lt(Z.useCallback(e=>pn?e.draftAttachmentViews[pn]:void 0,[pn])),hn=Lt(Z.useCallback(e=>pn?e.drafts[pn]:void 0,[pn])),gn=Z.useMemo(()=>{if(!hn||!mn)return yb;let e=hn.attachments.flatMap(e=>{let t=mn[e.attachmentRefID];return t?[t]:[]});return e.length===0?yb:e},[mn,hn]);Z.useEffect(()=>{fn&&Lt.getState().hydrateDraftAttachments(fn)},[fn]);let _n=nm(),vn=s(e=>e.activeMainTab===`chat`),yn=Er(Xe??``,ut??void 0),bn=rm({kind:`primary`,surfaceID:`primary`,active:vn,sessionID:Xe,directory:ut??null,activity:{phase:yn?.type===`busy`?`busy`:yn?.type===`retry`?`retry`:`idle`,canAbort:yn?.type===`busy`||yn?.type===`retry`},draftKey:fn,transportIdentity:sn,runtimeGeneration:c(),selection:{value:{providerID:Ze,modelID:Qe,agent:$e,variant:et},catalog:{providers:tt,agents:it,variants:ct,variantsReady:!at,ready:!at&&!ot,loading:at||ot},flush:async()=>{let e=J.getState().currentSessionId;if(!e)return;let t=c(),r=n(),i=wt.current,a=e,o=J.getState().getDirectoryForSession(a)??null,s=hr(o);if(mi.getState().activeDirectoryKey!==s&&await mi.getState().activateDirectory(o),c()!==t||n()!==r||J.getState().currentSessionId!==a||mi.getState().activeDirectoryKey!==s||wt.current!==i)return;await dt(a,{directory:o??void 0});let l=J.getState().getDirectoryForSession(a)??null,u=hr(l);if(c()!==t||n()!==r||J.getState().currentSessionId!==a||l!==o||u!==s||mi.getState().activeDirectoryKey!==s||wt.current!==i)return;let d=mi.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=oy(Pi(a,l??void 0)),m=Vt.getState(),h=ny({sessionId:a,latestUserChoice:p,catalog:f,memory:m,fallbackAgentName:d.currentAgentName});if(!h)return;let g=[a,h.source,h.messageId??``,h.agent??``,h.providerID,h.modelID,h.variant??``,s].join(`|`);Tt.current!==g&&(ry(h,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:a,memory:m}),Tt.current=g)},change:async e=>{wt.current+=1;let t=mi.getState();Zv(e,{currentAgentName:t.currentAgentName,setAgent:t.setAgent,setProvider:t.setProvider,setModel:t.setModel,setCurrentVariant:t.setCurrentVariant,saveAgentModelSelection:t.saveAgentModelSelection},{sessionId:J.getState().currentSessionId,memory:Vt.getState()});let n=J.getState().currentSessionId;if(n){let r=J.getState().getDirectoryForSession(n)??void 0,i=oy(Pi(n,r)),a=Vt.getState(),o=ny({sessionId:n,latestUserChoice:i,catalog:{providers:t.providers,agents:t.getVisibleAgents()},memory:a,fallbackAgentName:e.agent??t.currentAgentName});o&&(Tt.current=[n,o.source,o.messageId??``,o.agent??``,o.providerID,o.modelID,o.variant??``,mi.getState().activeDirectoryKey].join(`|`))}}},resources:{attachments:gn,addAttachment:async e=>{fn&&await qn(fn,()=>Lt.getState()).addLocal(e)},removeAttachment:async e=>fn?qn(fn,()=>Lt.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>fn?qn(fn,()=>Lt.getState()).clearRootAttachments():!1,restoreAttachments:async e=>fn?qn(fn,()=>Lt.getState()).restoreRootAttachments(e):!1,pendingInput:Zt===null?null:{text:Zt,mode:Qt},consumePendingInput:Yt,pendingPreset:Xt,consumePendingPreset:()=>Lt.getState().consumePendingPresetSubmit(),consumeSyntheticParts:tn,restoreSyntheticParts:e=>Lt.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:rn,removeInlineDraft:e=>{let t=Xe??(Ot?`draft`:``);t&&Gl.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=Xe??(Ot?`draft`:``);!t||e.length===0||Gl.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:on,captureRuntime:()=>Lt.getState().captureDraftRuntime(),getDraft:e=>Lt.getState().getDraft(e),abortPrompt:{sessionID:Gt,clear:Jt}},backend:{send:e=>{qv(e,{transportIdentity:n(),runtimeGeneration:c()});let t=Jv(e);return Ye(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Xi(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()=>Nt(),compact:async e=>Ae.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Ft(e.sessionID),Pn(e.sessionID??``))},shortcuts:{cycle:e=>Je.current(e),new:()=>Nt(),abort:()=>(Xe&&Ft(Xe),Pn(Xe??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),q=im(bn,u??_n);am(q),Z.useLayoutEffect(()=>{if(!q.active){Kv(q.surfaceID);return}return Gv(q),()=>Kv(q.surfaceID)},[q]);let xn=Xv(q),Cn=q.resources??(q.kind===`primary`?bn.resources:void 0);if(!Cn)throw Error(`chat-input-surface-resources-incomplete`);let wn=[...Cn.attachments],En=q.sessionID,On=om(q,jt),An=q.kind===`secondary`?q.commands.hasNewDraft:Ot,jn=An,Mn=q.directory??ut,Nn=q.draftKey??fn,Fn=Z.useMemo(()=>{if(q.kind===`secondary`)return cm(q,!1,!1);let e=En?Qy(En,pt??void 0):!1;return cm(q,e,An)},[q,En,pt,An]),In=(e,t,n,r,i,a,o,s,c,l)=>xn?xn.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`)),Ln=Z.useCallback(()=>xn?xn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[xn]),Rn=Mt(e=>e.projects),zn=Mt(e=>e.activeProjectId),Bn=Mt(e=>e.setActiveProjectIdOnly),[Vn,Wn]=Z.useState(!1),[Gn,Kn]=Z.useState(!1),Jn=Z.useMemo(()=>En?Ki({autoAccept:Rt,sessions:[],sessionById:Ai(),sessionID:En}):Et.permissionAutoAcceptEnabled===!0,[En,Et.permissionAutoAcceptEnabled,Rt]),Xn=mi(e=>e.agents),Zn=q.kind===`secondary`?q.selection.value.agent:$e,$n=q.kind===`secondary`?Wp(q.selection.catalog?.agents):Xn,er=d()||Rv($n,Zn),tr=Z.useCallback(()=>{wr.error(f(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[f]),nr=q.selection.value,ir=q.selection.change,ar=q.selection.catalog,or=Z.useMemo(()=>({selection:{providerID:nr.providerID??``,modelID:nr.modelID??``,agent:nr.agent??null,variant:nr.variant},onChange:async e=>{if(!ir)throw Error(`chat-input-surface-selection-readonly`);await ir({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!q.active,catalog:ar}),[ar,ir,nr.agent,nr.modelID,nr.providerID,nr.variant,q.active]);Z.useEffect(()=>{if(q.kind!==`primary`||!Xe){Xe||(Tt.current=null);return}if(at||ot||tt.length===0||it.length===0)return;let e=hr(pt);if(Ct!==e)return;let t=Vt.getState(),n=ny({sessionId:Xe,latestUserChoice:ht,catalog:{providers:tt,agents:it},memory:t,sessionEntity:xt&&yt?{agent:_t,model:{id:yt,providerID:xt,variant:St}}:_t?{agent:_t}:null,fallbackAgentName:$e});if(!n)return;let r=[Xe,n.source,n.messageId??``,n.agent??``,n.providerID,n.modelID,n.variant??``,Ct].join(`|`);if(Tt.current===r)return;if((n.agent===void 0||n.agent===$e)&&n.providerID===Ze&&n.modelID===Qe&&n.variant===et){Tt.current=r;return}if(mi.getState().activeDirectoryKey!==e)return;let i=mi.getState();ry(n,{currentAgentName:i.currentAgentName,setAgent:i.setAgent,setProvider:i.setProvider,setModel:i.setModel,setCurrentVariant:i.setCurrentVariant},{sessionId:Xe,memory:t}),Tt.current=r},[q.kind,Xe,ht,tt,it,at,ot,Ct,pt,$e,Ze,Qe,et,_t,yt,xt,St]);let dr=mi(e=>e.getVisibleAgents),fr=q.kind===`primary`?dr():Hy,pr=mi(e=>q.kind===`primary`?e.providers:Uy),gr=q.kind===`secondary`?Wp(q.selection.catalog?.agents):fr,_r=q.kind===`secondary`?q.selection.catalog?.providers??Uy:pr,vr=q.kind===`secondary`&&(!q.selection.catalog?.ready||!!q.selection.catalog.error),yr=!q.active||!q.selection.change||vr,xr=s(e=>e.isMobile),Sr=s(e=>e.setImagePreviewOpen),Tr=Z.useCallback(e=>{e.image&&(m(e),Sr(!0))},[Sr]),Dr=Z.useCallback(e=>{m(t=>({...t,open:e})),Sr(e)},[Sr]),Or=bl(e=>e.pending),kr=s(e=>e.inputBarOffset),Ar=s(e=>e.persistChatDraft),Mr=s(e=>e.inputSpellcheckEnabled),Nr=s(e=>e.isExpandedInput),Pr=s(e=>e.setExpandedInput),Lr=s(e=>e.setTimelineDialogOpen),Rr=Iy({draftKey:Nn,sessionTitles:new Map(Array.from(Ai(),([e,t])=>[e,t.title||e])),persistenceEnabled:Ar}),zr=Rr.document,Vr=zr.text,{replacePlainDocument:Ur,replaceProgrammaticText:Wr,applyBrowserEdit:Kr,insertReference:qr,deleteReference:Yr,enterHistoryPreview:Xr,exitHistoryPreview:Zr,captureSubmission:$r,recoverSubmission:ei,confirmedFileMentions:ri,mentions:ai}=Rr,oi=Z.useCallback((e,t)=>Wr(e,t),[Wr]),ci=Z.useMemo(()=>new Set(ri.map(e=>e.value)),[ri]),li=Z.useRef(null),ui=Z.useRef(!1),di=Z.useRef(0),fi=Z.useRef(Vr.length),gi=Z.useRef(null),yi=Z.useRef(0),bi=Z.useRef(!1),Ci=Z.useRef(null),Ti=Z.useRef(!1),Oi=Z.useRef(null),ji=Z.useRef([]),Mi=Z.useRef(!1),Fi=Z.useRef(null),Ii=Z.useRef(!1),Li=Z.useRef(null),Ri=Z.useRef(null),Bi=Z.useRef(null),Vi=Z.useRef(Vr),Hi=Z.useRef(new Set),Ui=Rr.getDocument,Wi=Z.useCallback((e,t,n=[])=>oi(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}`))]}),[oi]),Gi=$m(Qm()),{git:qi,vscode:Ji}=Do(),Yi=s(e=>e.shortcutOverrides.cycle_agent),Zi=s(e=>e.shortcutOverrides),Qi=Z.useMemo(()=>Ya(`cycle_agent`,Yi?{cycle_agent:Yi}:void 0),[Yi]),$i=Z.useMemo(()=>Ya(`clear_all_messages`,Zi),[Zi]),{currentTheme:ea}=za(),na=Os(),ra=Bs(Mn),ia=ws(e=>Mn?e.directories.get(Mn)?.status??null:null),aa=ws(e=>e.ensureStatus),oa=ws(e=>e.fetchStatus),[sa,ca]=Z.useState(!1),ua=Z.useRef(null),[da,pa]=Z.useState(!1);Z.useEffect(()=>{!Mn||!qi||aa(Mn,qi)},[Mn,qi,aa]),Z.useEffect(()=>{if(!(!Mn||!qi))return hi.onGitRefreshHint(e=>{ib(e.directory)===ib(Mn)&&oa(Mn,qi)})},[Mn,qi,oa]);let ha=Z.useCallback(async e=>{if(!En)return;let t=J.getState().getDirectoryForSession(En)||Mn||``;if(!t){wr.error(f(`diffView.reviewDialog.toast.noSessionDirectory`));return}Kn(!0);try{await Tn({originalSessionID:En,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}),Wn(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),wr.error(e instanceof Error?e.message:f(`diffView.reviewDialog.toast.startFailed`))}finally{Kn(!1)}},[En,Mn,f]),ga=Nr&&!xr,va=Nr&&xr,xa=ga||va,Ta=`1.5rem`,Ea=f(En||An?h===`shell`?`chat.chatInput.placeholder.shell`:xr||da?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Oa=f(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=gi.current;if(!e)return;let t=e=>{let t=e>0&&e<qy;pa(e=>e===t?e:t)};if(t(e.clientWidth),typeof ResizeObserver>`u`){let n=()=>t(e.clientWidth);return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)}let n=new ResizeObserver(n=>{t(n[0]?.contentRect.width??e.clientWidth)});return n.observe(e),()=>n.disconnect()},[]);let ka=wn,Aa=Z.useMemo(()=>new Set(gr.map(e=>e.name.toLowerCase())),[gr]),ja=Z.useRef(Aa);ja.current=Aa;let Ia=Gy({inputMode:h,message:Vr,showCommandAutocomplete:M,showSkillAutocomplete:R}),La=Hn({directory:Mn,enabled:Ia}),Ra=Z.useMemo(()=>La.data??[],[La.data]),Ba=ti({directory:Mn,enabled:Ia}),Ha=Z.useMemo(()=>Ba.data??[],[Ba.data]),Ua=Z.useMemo(()=>new Map(Ha.map(e=>[e.name.toLowerCase(),e.name])),[Ha]),Wa=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`plan-feature`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!xr&&!d()&&e.add(`handoff-review`);for(let t of Ra)e.add(t.name.toLowerCase());for(let t of Ha)e.add(t.name.toLowerCase());return e},[Ra,Ha,xr]),Ga=Z.useMemo(()=>{if(!Vr||!Vr.includes(`/`)||h===`shell`||Wa.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${te})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(Vr))!==null;){let t=n[2]??``,r=n[3];if(!Wa.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=Ua.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:ae({trigger:`/`,icon:`book-open`,label:o},Vr.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:ae({trigger:`/`,icon:`command`,label:r},Vr.slice(i,i+a))})}return e},[Ua,h,Wa,Vr]),Ka=ma(e=>e.snippets),qa=Z.useMemo(()=>{let e=new Set;for(let t of Ka){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[Ka]),Ja=Z.useMemo(()=>{if(!Vr||!Vr.includes(`#`)||h===`shell`||qa.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(Vr))!==null;){let t=n[2];if(!qa.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[h,qa,Vr]),$a=Z.useMemo(()=>!Vr||!Vr.includes(`@`)||h===`shell`?[]:Gr(Vr,{confirmedValues:ci,agentNames:Aa}),[ci,h,Aa,Vr]),eo=Z.useMemo(()=>{if(!Vr||!Vr.includes(`[`)||h===`shell`||ka.length===0)return[];let e=ka.filter(ke),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return ze(Vr,e.map(e=>e.filename)).flatMap(e=>{let n=W(Vr.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:ae({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},Vr.slice(e.start,e.end))}]})},[h,Vr,ka]),to=Z.useMemo(()=>{if(!Vr||h===`shell`)return null;let e=[...P_(Vr),...X_(Vr),...z_($a),...Ga,...Ja,...eo,...zr.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return F_(Vr,e)},[eo,Ga,Ja,$a,zr.references,h,Vr]),no=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?nb(e.serverPath):e.dataUrl})),[]),[ro,io]=Z.useState(null),ao=Z.useRef(null),[oo,so]=Z.useState(!1),[co,lo]=Z.useState(!1),[uo,fo]=Z.useState(null),[po,mo]=Z.useState(null),ho=C(e=>e.followUpBehavior),go=Z.useMemo(()=>{let e=xn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[xn]),_o=iu({transportIdentity:go?.transportIdentity??``,directory:go?.directory??``,sessionID:go?.sessionID??``}),vo=Z.useMemo(()=>En?x(En):null,[En]),yo=C(Z.useCallback(e=>go?b(e,go):By,[go])),bo=C(Z.useCallback(e=>vo?b(e,vo):By,[vo])),xo=Z.useMemo(()=>bo.length===0?yo:yo.length===0?bo:[...bo,...yo],[yo,bo]),So=_o.mode===`server`?By:xo,Co=C(Z.useCallback(e=>go?B(e,go):By,[go])),wo=C(e=>e.clearQueue),To=C(e=>e.removeFromQueue),Eo=Cn.inlineDrafts,Oo=Eo.length>0,[ko,Ao,jo]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of Eo)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[Eo]),Mo=Z.useCallback(e=>{for(let t of Cn.inlineDrafts)t.source===e&&Cn.removeInlineDraft(t.id)},[Cn]),No=Z.useCallback(()=>{for(let e of Cn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&Cn.removeInlineDraft(e.id)},[Cn]),Po=Cn.history;Z.useEffect(()=>{Vi.current=Vr},[Vr]),Z.useLayoutEffect(()=>{g(`normal`),qe(-1)},[Nn?.transportIdentity,Nn?.owner.kind,Nn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!An||xr)return;let e=()=>{let e=li.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[An,xr]);let Fo=Gh(q.kind===`primary`?En:null,q.kind===`primary`?Mn??void 0:void 0),Io=q.activity?.phase??Fo.phase,Lo=wi(Z.useCallback(e=>{if(!En)return!1;let t=e.runsByOriginalSessionID[En];return t?.status===`running`&&t.runtimeKey===i()},[En])),Ro=K(e=>{xr&&(Ue(),fe(e),li.current?.blur(),mi.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),zo=Cn.pendingInput,Bo=Cn.consumePendingInput;Z.useEffect(()=>{if(zo===null)return;let e=Bo();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=gb(Vi.current,e.text);Vi.current=t,oi(t)}else if(e.mode===`append-inline`){let t=_b(Vi.current,e.text);Vi.current=t,oi(t)}else Ur(e.text);setTimeout(()=>{li.current?.focus()},0)}},[zo,Bo,Ur,oi]);let Vo=Vr.trim().length>0||ka.length>0||Oo,Ho=_o.mode===`server`?_o.items.length>0:So.length>0||Co.length>0,Uo=!Qd(_o.mode),Wo=Vo||Ho,Go=J(e=>e.stagedMessageEdit?.sessionId===En?e.stagedMessageEdit.messageId:null),Ko=Io===`busy`||Io===`retry`,qo=q.activity?.canAbort??Ko,Jo=Z.useCallback(()=>{let e=li.current,t=e?.value??Ui().text;t!==Ui().text&&Kr(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=Ui();return{message:n.text,document:n,hasContent:n.text.trim().length>0||ka.length>0||Oo}},[Kr,Ui,Oo,ka.length]),Yo=Z.useRef(async()=>{}),Xo=q.surfaceID,Zo=Et?.draftID??null,Qo=Jr(Z.useMemo(()=>Sn(Xo),[Xo])),$o=Jr(Z.useMemo(()=>vt(Zo),[Zo])),es=Z.useMemo(()=>Dt(Qo,$o),[Qo,$o]),ts=(e=`send`)=>Jr.getState().beginFlight(Xo,e),ns=()=>{Jr.getState().endFlight(Xo)},rs=()=>Jr.getState().isInFlight(Xo),as=Z.useRef(null);Z.useEffect(()=>{if(q.kind!==`primary`||!Go){as.current=null;return}as.current!==Go&&(as.current=Go,Yp(li)||requestAnimationFrame(()=>Yp(li)))},[Go,q.kind]);let os=Jr(Z.useMemo(()=>Qr(Zo),[Zo])),ss=K(async()=>{let e=J.getState().newSessionDraft.draftID;if(!e||!Jr.getState().isEstablishing(e))return!1;let t=Jo();if(!t.hasContent)return!1;let n=G(t.document,`queue-canonical`);if(!n.ok)return wr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;if(await q.selection.flush(),!Jr.getState().isEstablishing(e))return!1;let r=iy(mi.getState());if(!r?.providerID||!r?.modelID)return wr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;let i=no(ka);return Jr.getState().enqueueEstablishingFollowUp({draftID:e,content:n.text,sendConfig:{providerID:r.providerID,modelID:r.modelID,...r.agent?{agent:r.agent}:{},...r.variant?{variant:r.variant}:{}},attachments:i,composerDocument:t.document})?(Ur(``),qe(-1),Pr(!1),i.length>0&&Cn.clearAttachments(),!0):!1}),cs=()=>{if(En)return!1;let e=J.getState().newSessionDraft.draftID;return Jr.getState().isEstablishing(e)?(ss(),!0):!1},ls=K(async()=>{if(!q.active||rs())return;if(En){let e=J.getState().stagedMessageEdit;if(e&&e.sessionId===En){J.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await qt(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{J.getState().endMessageEditCommit(e.sessionId,e.messageId)}J.getState().stagedMessageEdit===e&&J.getState().clearStagedMessageEdit(e.sessionId)}}let e=Jo(),t=G(e.document);if(!t.ok){wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:t.chunks??[],semantics:t.semantics??[]},i=t.text,a=i.trimStart(),o=r.chunks.every(e=>e.provenance===`authored`)&&h===`normal`&&a.startsWith(`/`)?Tv(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(o&&!bs(o,e=>em(q,{name:e.name,source:`openchamber`}))||l||!e.hasContent||!En)return;if(Uo||!Bt(q.deliveryTarget?.kind,_o.mode)){Yo.current(Ko?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&xv(i,h)){Yo.current();return}if(!ts(`queue`))return;let s=q.transportIdentity,u=q.runtimeGeneration,d=Cn.captureRuntime(),p=go,m=q.kind===`primary`?go?.sessionID??En:null,g=[...Cn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Jl(e.document.text,g),e.document.references).document:e.document,y=G(_,`queue-canonical`);if(!y.ok){ns(),wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let b=no(ka),w=$r(),T=b,E=rr(),D=!1,O=null,k=()=>{D&&p&&(_o.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(C.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&ei(w),T.length>0&&await Cn.restoreAttachments(T),e&&Cn.restoreSyntheticParts(e),g.length>0&&Cn.restoreInlineDrafts(g)};try{if(!p){wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(_o.mode===`server`){if(!Nn){wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}Si({stage:()=>{_o.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:ai}}),D=!0},clearComposer:()=>{Ur(``),qe(-1),Pr(!1)}})}else Si({stage:()=>{C.getState().bindLegacyQueue(x(p.sessionID),p),C.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:ai}),O=E.requestID},clearComposer:()=>{Ur(``),qe(-1),Pr(!1)}});if(await q.selection.flush(),!Dn({transportIdentity:s,generation:u},{transportIdentity:n(),generation:c()})){await A();return}if(!Dn(d,Cn.captureRuntime())){await A();return}if(m&&J.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==n()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&S(J.getState().getDirectoryForSession(m))!==S(p.directory)){await A();return}let t=p,r=q.kind===`primary`?(()=>{let e=mi.getState(),t=m?J.getState().getDirectoryForSession(m)??null:null;return iy(e,{expectedConfigKey:hr(t),activeDirectoryKey:e.activeDirectoryKey})})():q.selection.value.providerID&&q.selection.value.modelID?{...q.selection.value,providerID:q.selection.value.providerID,modelID:q.selection.value.modelID}:void 0;if(!sr(r)){await A();return}if(_o.mode===`server`){if(!Nn){await A(),wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let n=$t({draftKey:Nn,runtime:d,document:e.document,attachments:ka,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?Cn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=pi({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:gr,installedSkillNames:new Set(_i(ie,Mn).map(e=>e.name)),directory:Mn,root:na||Mn,confirmedFilePaths:ri.map(e=>e.path),confirmedDirectoryPaths:ri.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:ka});return o=e.attachments,ft({text:g.length>0?Jl(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:Fr(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...an(b),...an(o),...(i??[]).flatMap(e=>an(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 A(i),wr.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?jr(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Yn({capture:n,admit:async()=>{let n=await _o.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:ai,sendConfig:r,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return n.status===`committed`&&(e=!0,D=!1),n},captureRuntime:Cn.captureRuntime,getCurrentDraftKey:()=>Nn,getDocument:Ui,consumeBody:()=>Ur(``),getAttachments:()=>Cn.attachments,removeAttachment:Cn.removeAttachment,getInlineDrafts:()=>Cn.inlineDrafts,removeInlineDraft:Cn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!xr&&li.current?.focus()}catch(e){await A(i),wr.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)Cn.removeInlineDraft(e.id);b.length>0&&Cn.clearAttachments(),xr||li.current?.focus()}catch(e){await A(),wr.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{ns()}}),us=K(()=>{Pv(()=>ls(),()=>{wr.error(f(`chat.chatInput.toast.messageSendFailed`))})}),ds=K(async(e,t,n,r)=>{if(Uo||!q.draftKey)return!1;try{let i=await Un({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=Lt.getState(),o=a.getDraft(q.draftKey);return ef(await Kt({key:q.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(wr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return wr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1}}),fs=K(e=>{if(!(l||Uo)){if(xn){xn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}wr.error(f(`chat.chatInput.toast.messageSendFailed`))}}),ps=K(()=>{Ue(),fe(`agent`),li.current?.blur(),mi.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),ms=Z.useCallback(()=>{so(!0)},[]),hs=Z.useCallback(()=>{lo(!0)},[]),gs=async e=>{if(!q.active||l||cs()||rs())return;let t=e?.queuedOnly??!1,i=e?.queuedMessageId,a=e?.delivery===`steer`&&Ko?`steer`:void 0,o=e?.presetText==null?Jo():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||ka.length>0||Oo},u=e?.presetText==null?$r():null,p=wn,m=G(o.document,`direct-send-display`);if(!m.ok){wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let g=m.text,v={chunks:m.chunks??[],semantics:m.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?yv(x,h):null,w=y&&xv(g,h),T=y&&h===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&h===`normal`&&x.startsWith(`/`)?Tv(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!bs(E,e=>em(q,{name:e.name,source:`openchamber`}))||t&&Uo)return;if(!t&&T){N(!1),I(``),xr?Ro(`model`):(s.getState().setModelSelectorOpen(!0),mi.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&S&&S!==`model`)){if(!t&&En&&Ho&&Uo)return;if(!t&&En&&Ho&&_o.mode===`server`){o.hasContent&&us();return}if(!t&&En&&Ho){o.hasContent&&us();let e=So[0];e&&xn&&await xn.sendQueued(e.queueItemID,{options:Ko?{delivery:`steer`}:void 0});return}}let D=w?[]:i?So.filter(e=>e.id===i):So;if(t&&Lo)return;if(t){if(D.length===0||!En)return}else if(!o.hasContent&&!Ho||!En&&!An)return;if(!En&&On||!ts())return;let O=!En&&An&&!t&&!w?J.getState().newSessionDraft.draftID??null:null,k=O?ee(`msg`):void 0;if(O&&k&&!Jr.getState().beginEstablishing({draftID:O,primaryMessageID:k})){ns();return}let A=()=>{mr(),O&&Jr.getState().clearEstablishing(O)},j=e=>{let t=J.getState().currentSessionId,r=(t?J.getState().getDirectoryForSession(t):null)??Mn??``;if(!t||!r){Jr.getState().clearEstablishing(e);return}Nv({draftID:e,sessionID:t,directory:r,transportIdentity:n(),runtimeGeneration:c(),admitServer:_o.mode===`server`?async e=>_o.actions.admit({requestID:e.requestID,scope:{directory:r,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?an(e.attachments):void 0}):void 0})};if(En&&!t&&!w&&Lo){ns(),us();return}let M=!t&&!w;M&&(Ur(``),qe(-1),Pr(!1));let P=!1,F,L,R=!1;try{if(kv({surfaceKind:q.kind,currentSessionId:En,queuedOnly:t,resourcePolicy:w,inputMode:h,localCommand:S})&&En){let e=J.getState().getDirectoryForSession(En)??Mn??null,t=J.getState().stagedMessageEdit;t&&t.sessionId===En&&(L={sessionId:t.sessionId,messageId:t.messageId},J.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=mi.getState(),r=iy(n,{expectedConfigKey:hr(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=no(ka);F=bt({sessionId:En,directory:e,content:o.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=q.kind===`primary`?(()=>{if(t){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(go?.sessionID)return go.sessionID}return En})():null,n=t?D[0]?.sendConfig:void 0;if(t&&n||await q.selection.flush(),e!==null&&J.getState().currentSessionId!==e)return;let s=async()=>{let t=n?{...n}:q.kind===`primary`?(()=>{let t=mi.getState();if(!e)return ay({captured:iy(t),surfaceSelection:q.selection.value});let n=J.getState().getDirectoryForSession(e)??Mn??null;return ay({captured:iy(t,{expectedConfigKey:hr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:q.selection.value})})():q.selection.value.providerID&&q.selection.value.modelID?{...q.selection.value,providerID:q.selection.value.providerID,modelID:q.selection.value.modelID}:void 0;if(q.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=J.getState().getDirectoryForSession(e)??Mn??null,r=hr(n);if(mi.getState().activeDirectoryKey!==r&&await mi.getState().activateDirectory(n),J.getState().currentSessionId===e){let e=mi.getState();t=ay({captured:iy(e,{expectedConfigKey:hr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:q.selection.value})}}return t},c=await s(),l=!1,m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant;if(!m||!g){if(!l){l=!0;try{await mi.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await s(),m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant}catch{}}if(!m||!g){console.warn(`Cannot send message: provider or model not selected`),wr.error(f(`chat.chatInput.toast.messageSendFailed`));return}}En&&!t&&!w&&await Qn(En)&&await Pn(En);let T={...a?{delivery:a}:{},commitStagedMessageEdit:!t,...F?{messageID:F.messageID,ticket:F}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:J.getState().getDirectoryForSession(e)??Mn??null}:q.kind===`primary`&&En?{sessionId:En,directoryHint:J.getState().getDirectoryForSession(En)??Mn??null}:{}},E=``,M=[],N,I=[],z=new Set(_i(ie,Mn).map(e=>e.name)),B=[],V=w?void 0:Cn.consumeSyntheticParts();for(let e=0;e<D.length;e++){let t=D[e],n=t.composerDocument&&G(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Mn,a=new Set(_i(ie,i).map(e=>e.name)),o=pi({plan:r??ki(t.content),agents:gr,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(B.push(...o.semantics),!N&&o.agent&&(N=o.agent),e===0)E=o.text,M=xi([...no(t.attachments),...o.attachments]);else{let e=no(t.attachments);I.push({text:o.text,attachments:xi([...e,...o.attachments])})}}if(!t&&o.hasContent){let e=no(ka),t=pi({plan:v,agents:gr,installedSkillNames:z,directory:Mn,root:na||Mn,confirmedFilePaths:ri.map(e=>e.path),confirmedDirectoryPaths:ri.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:ka});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,M=xi([...e,...t.attachments])):I.push({text:t.text,attachments:xi([...e,...t.attachments])})}let H=En??(An?`draft`:null),U=[];if(!t&&H&&!w&&(U=[...Cn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Jl(E,U);else if(I.length>0){let e=I[I.length-1];e.text=Jl(e.text,U)}else E=Jl(E,U);if(V&&V.length>0&&I.push(...Ni(V)),uo&&I.push({text:uo.contextText,synthetic:!0}),po&&(I.push({text:po.instructionsText,synthetic:!0}),I.push({text:po.contextText,synthetic:!0})),I.push(...Fr(B,En&&J.getState().getDirectoryForSession(En)||Mn)),!E&&M.length===0&&I.length===0)return;if(O&&k){if(!await Hr({messageID:k,providerID:m,modelID:g,agent:y,text:E,attachments:M,additionalParts:I,agentMentionName:N}))return;if(!Jr.getState().isEstablishing(O)){A();return}}let ee=async()=>{if(A(),go&&D.length>0&&C.setState(e=>{let t=_(go),n=e.queuedMessages[t]??[],r=new Set(D.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...D,...n.filter(e=>!r.has(e.id))]}}}),t)return V&&Cn.restoreSyntheticParts(V),!0;Cn.pendingInput?.text===o.message&&Cn.consumePendingInput(),u&&ei(u);let e=!0;return p.length>0&&(e=await Cn.restoreAttachments(p)),V&&Cn.restoreSyntheticParts(V),U.length>0&&Cn.restoreInlineDrafts(U),e};if(!w&&En&&i){let e=go?b(C.getState(),go).find(e=>e.id===i||e.queueItemID===i):void 0;go&&e?.queueItemID&&e.operationID&&To(go,e.queueItemID,e.operationID)}else!w&&En&&Ho&&go&&wo(go);!t&&!w&&(Ur(``),qe(-1),Pr(!1),Ov({queuedOnly:t,resourcePolicy:w,rootAttachmentCount:p.length})&&Cn.clearAttachments());let te=()=>Ev({currentSessionId:En,messageRef:Vi,replacePlainDocument:Ur}),W=E.trimStart();if(h===`normal`&&W.startsWith(`/`)){let e=Tv(W.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!bs(e,e=>em(q,{name:e.name,source:`openchamber`})))return;if(En&&(e===`undo`||e===`redo`)&&Sv(W,h)&&te(),e===`undo`&&En){try{await J.getState().handleSlashUndo(En),r?.()}catch(e){wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){Sv(W,h)&&te(),await xn?.shortcut(`new`);return}if(e===`redo`&&En){try{await J.getState().handleSlashRedo(En),r?.()}catch(e){wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&En){await Dv({command:`fork`,consumeCommandText:te,forkSession:()=>J.getState().forkCurrentSession(En),waitForConnection:Ei,getDirectoryForSession:()=>J.getState().getDirectoryForSession(En),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&En&&Gi.timeline){Lr(!0);return}if(e===`compact`&&En){Dv({command:`compact`,consumeCommandText:te,forkSession:async()=>void 0,waitForConnection:Ei,getDirectoryForSession:()=>q.directory??``,summarizeSession:e=>Nn?q.backend.compact({operation:`compact`,surfaceID:q.surfaceID,transportIdentity:q.transportIdentity,runtimeGeneration:q.runtimeGeneration,sessionID:En,directory:e,draftKey:Nn,deliveryTarget:q.deliveryTarget,providerID:m,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{wr.error(f(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&En){try{await Ei();let e=W.replace(/^\/\u2003?summary\b/i,``).trim(),t=e?` focused on: ${e}`:``,n=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await kn(`session.summary.visible`,{topic_line:t}),a=await kn(`session.summary.instructions`,{topic_block:n});await In(i,m,g,y,[],N,[{text:a,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(En||An)){try{await Ei();let e=await kn(`session.review.visible`),t=await kn(`session.review.instructions`);await In(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&En&&!xr&&!d()){Wn(!0);return}if(e===`plan-feature`&&(En||An)){try{await Ei();let e=await kn(`session.plan.visible`),t=await kn(`session.plan.instructions`);await In(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(En||An)){A(),Pt.getState().setArmed(!0);let e=bv(W,h)??``;Ur(e),Vi.current=e,qe(-1),e||Pr(!1);return}if(e===`craft-goal`&&(En||An)){try{await Ei();let e=W.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await kn(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await kn(`session.craftGoal.instructions`);await In(t,m,g,y,[],N,[{text:n,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(En||An)){try{await Ei();let e=await kn(`session.catchup.visible`),t=await kn(`session.catchup.instructions`);await In(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(En||An)){try{await Ei();let e=await kn(`session.debug.visible`),t=await kn(`session.debug.instructions`);await In(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(En||An)){try{await Ei();let e=await kn(`session.weigh.visible`),t=await kn(`session.weigh.instructions`);await In(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(En||An)){try{await Ei();let e=await kn(`session.explore.visible`),t=await kn(`session.explore.instructions`);await In(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await ee(),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.exploreFailed`))}return}}let ne=En&&J.getState().getDirectoryForSession(En)||Mn;if(jn||En&&!Qy(En,ne)){let e=await ln().catch(()=>null);e&&I.push({text:zi(e),synthetic:!0})}try{let e=ma.getState().expandText;E=await e(E);for(let t of I)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let re=In(E,m,g,y,M,N,I.length>0?I:void 0,x,h,T);P=!0,re.finally(()=>{ns(),L&&J.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&re.then(()=>{j(O)}).catch(()=>{Jr.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),re.then(()=>{uo&&fo(null),po&&mo(null)}).catch(e=>{F&&lr(F),ee().then(e=>{e||wr.error(f(`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`)){wr.error(f(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){p.length>0&&wr.error(f(`chat.chatInput.toast.sendAttachmentsFailed`));return}wr.error(t||f(`chat.chatInput.toast.messageSendFailed`))}),xr||li.current?.focus()}finally{R||(F&&lr(F),L&&J.getState().endMessageEditCommit(L.sessionId,L.messageId)),P||(M&&u&&ei(u),ns(),O&&j(O))}};Yo.current=gs;let ys=Z.useCallback(()=>{if(cs()||rs())return;let e=Jo(),t=h===`normal`&&e.hasContent&&En&&(Ko||Lo),n=t&&Qd(_o.mode)&&Bt(q.deliveryTarget?.kind,_o.mode);ho===`queue`&&n?us():ho===`steer`&&t||ho===`queue`&&t&&!n?Yo.current(t?{delivery:`steer`}:void 0):Yo.current()},[h,Jo,En,Ko,Lo,ho,us,_o.mode,q.deliveryTarget?.kind,ss]),xs=Z.useCallback(e=>{if(rs())return;let t=(li.current?.value??Vi.current).trim(),n=t?`${e}\n${t}`:e;Yo.current({presetText:n})},[]),Cs=Z.useCallback(e=>{let t=_b(Ui().text,e);oi(t),li.current&&(li.current.value=t),setTimeout(()=>{li.current?.focus()},0)},[oi]),Ts=Z.useCallback(e=>{if(rs())return;let t=_b(li.current?.value??Vi.current,e);Yo.current({presetText:t})},[]),As=Cn.pendingPreset,js=Cn.consumePendingPreset;Z.useEffect(()=>{if(As==null)return;let e=js();e&&xs(e)},[As,js,xs]);let Ns=Z.useCallback(()=>{Ur(``),qe(-1),wn.length>0&&Cn.clearAttachments(),go&&wo(go),N(!1),z(!1),re(!1),O(!1),h===`shell`&&g(`normal`)},[wn.length,Cn,wo,go,Ur,h]),Is=e=>{if(!q.active||Kh(e))return;if($i&&Va(e,$i)&&!Or){let t=li.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),Ns();return}}if(h===`shell`&&e.key===`Escape`){e.preventDefault(),g(`normal`);return}if(h===`shell`&&e.key===`Backspace`&&Vr.length===0){e.preventDefault(),g(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=li.current,n=t?.selectionStart??Vr.length,r=t?.selectionEnd??Vr.length,i=Yr({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Zy(Rr.getDocument().text,i.start);e.preventDefault(),oi(t.text),requestAnimationFrame(()=>{li.current?.setSelectionRange(t.caret,t.caret),Js()}),Ys(t.text,t.caret);return}let a=De(Vr,wn.filter(ke).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=Zy(a.text,a.caret);e.preventDefault(),oi(n.text);for(let e of wn)t.has(e.filename.toLowerCase())&&Cn.removeAttachment(e.id);requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=n.caret,li.current.selectionEnd=n.caret),Js()}),Ys(n.text,n.caret);return}let o=R_(Vr,Ua.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Zy(o.text,o.caret);e.preventDefault(),oi(t.text),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=t.caret,li.current.selectionEnd=t.caret),Js()}),Ys(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<Vr.length){let n=ze(Vr,wn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=W(Vr.slice(n.start+1,n.end-1)).trim(),r=wn.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=Vr[n.end]===` `?n.end+1:n.end,a=`${Vr.slice(0,n.start)}${Vr.slice(i)}`;e.preventDefault(),oi(a),r&&Cn.removeAttachment(r.id),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=n.start,li.current.selectionEnd=n.start),Js()}),Ys(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(Vr[r-1]);)--r;let i=t+1;for(;i<Vr.length&&!/\s/.test(Vr[i]);)i+=1;let a=Vr.slice(r,i),o=a.slice(1);if(Wy.test(a)&&!ja.current.has(o.toLowerCase())&&ni({mention:o,confirmed:ci.has(o),terminated:i<Vr.length&&/\s/.test(Vr[i])})){let t=Vr[i]===` `?i+1:i,n=`${Vr.slice(0,r)}${Vr.slice(t)}`;e.preventDefault(),oi(n),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=r,li.current.selectionEnd=r),Js()}),Ys(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&Li.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Li.current.handleKeyDown(e.key);return}if(R&&Ri.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Ri.current.handleKeyDown(e.key);return}if(ne&&Bi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Bi.current.handleKeyDown(e.key);return}if(D&&Fi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Fi.current.handleKeyDown(e.key);return}if(ga&&e.key===`Escape`){e.preventDefault(),Pr(!1);return}let n=Qi&&!Qi.includes(`shift`)?Xa(`shift+${Qi}`):``,r=n&&Va(e,n)?-1:+!!Va(e,Qi);if(r!==0&&!M&&!R&&!ne&&!D){e.preventDefault(),e.stopPropagation(),xn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{li.current?.focus({preventScroll:!0})});return}let i=M||R||ne||D,a=li.current?.selectionStart===0&&li.current?.selectionEnd===0,o=li.current?.selectionStart===Vr.length&&li.current?.selectionEnd===Vr.length,s=!i&&(Vr.length===0||a),c=!i&&(Vr.length===0||o);if(h===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=li.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),oi(t),requestAnimationFrame(()=>{let e=li.current;e&&(e.selectionStart=n,e.selectionEnd=r),Js()}),Ys(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=Vr.slice(n,r);t(`${Vr.slice(0,n)}${a}${s}${o}${Vr.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=Vr.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${Vr.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&Po.length>0){if(e.preventDefault(),Ke===-1)qe(0),Xr({text:Po[0],references:[]});else if(Ke<Po.length-1){let e=Ke+1;qe(e),Xr({text:Po[e],references:[]})}requestAnimationFrame(()=>{li.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Ke>=0){if(e.preventDefault(),Ke===0)qe(-1),Zr();else{let e=Ke-1;qe(e),Xr({text:Po[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),cs()||rs())return;let t=e.ctrlKey||e.metaKey,n=h===`normal`&&Vo&&En&&(Ko||Lo),r=n&&Qd(_o.mode)&&Bt(q.deliveryTarget?.kind,_o.mode);ho===`queue`?t||!n?gs():r?us():gs({delivery:`steer`}):t||!n?gs():gs({delivery:`steer`})}},Rs=Z.useCallback((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}},[]),zs=Z.useCallback(()=>{if(!ga){io(null);return}if(!M&&!R&&!ne&&!D){io(null);return}let e=li.current,t=gi.current;if(!e||!t)return;let n=e.selectionStart??Vr.length,r=Rs(e,n);if(!r)return;let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=i.top-a.top+(r.top-e.scrollTop),s=i.left-a.left+(r.left-e.scrollLeft),c=o-8,l=a.height-o-8,u=l>=260||l>=c?`below`:`above`,d=D?520:M||ne?450:360,f=Math.max(8,Math.min(s-24,a.width-d-8)),p=Math.max(120,Math.min(260,u===`below`?l:c));io({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[ga,Rs,Vr.length,M,D,ne,R]);Z.useLayoutEffect(()=>{zs()},[zs,Vr,M,R,ne,D,ga]),Z.useEffect(()=>{if(!ga)return;let e=()=>zs();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[ga,zs]);let Vs=Z.useCallback(()=>{ao.current&&=(clearTimeout(ao.current),null),ca(!0),ao.current=setTimeout(()=>{ca(!1),ao.current=null},1800)},[]),Hs=Z.useCallback(()=>{if(Cn.abortPrompt.clear(),Vs(),q.kind===`secondary`){xn?.shortcut(`abort`);return}Ln()},[Ln,xn,Vs,q.kind,Cn]),Us=Z.useCallback((e=1)=>{if(vr)return;let t=en(gr,q.selection.value.agent??Zn,e);if(!t||!q.selection.change)return;let n=cr({providerID:q.selection.value.providerID??``,modelID:q.selection.value.modelID??``,agent:q.selection.value.agent??null},t,gr,_r);q.selection.change({...q.selection.value,...n,agent:n.agent??void 0}),q.kind===`primary`&&(s.getState().addRecentAgent(t),q.sessionID&&Vt.getState().saveSessionAgentSelection(q.sessionID,t))},[gr,Zn,_r,vr,q.kind,q.selection,q.sessionID]);Je.current=Us;let Ws=Z.useRef(null),[Gs,Ks]=Z.useState(null),qs=Z.useCallback(e=>{Ks(t=>t===e?t:e)},[]),Js=Z.useCallback(e=>{let t=li.current;if(!t)return;let n=t.scrollTop;if(xa){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,le(null),t.scrollTop!==n&&(t.scrollTop=n);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let r=t.ownerDocument?.defaultView,i=r?r.getComputedStyle(t):null,a=i?parseFloat(i.lineHeight):NaN,o=i?parseFloat(i.paddingTop):NaN,s=i?parseFloat(i.paddingBottom):NaN,c=Number.isNaN(o)||Number.isNaN(s)?16:o+s,l=Number.isNaN(a)?22:a,u=Ly({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:Ws.current??0,lineHeight:l,paddingTotal:c});t.style.height=`${u.height}px`,t.style.maxHeight=`${u.maxHeight}px`,t.style.overflowY=u.overflowY,t.scrollTop!==n&&(t.scrollTop=n),le(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[xa]);Z.useLayoutEffect(()=>{let e=Vr.length<fi.current;fi.current=Vr.length,Js({allowShrink:e})},[Js,Vr,xr]),Z.useLayoutEffect(()=>{Ws.current=Gs,Js({allowShrink:Gs===null})},[Js,Gs]);let Ys=Z.useCallback((e,t,n=`manual`,r)=>{if(h===`shell`){N(!1),O(!1),z(!1),re(!1);return}if(e.startsWith(`/`)){let n=e.indexOf(` `),r=e.indexOf(`
6535
- `),i=Math.min(n===-1?e.length:n,r===-1?e.length:r);if(t<=i&&n===-1){let t=Tv(e.substring(1,i));I(t),N(!0),O(!1),z(!1),re(!1);return}}N(!1);let i=e.substring(0,t),a=i.lastIndexOf(`/`);if(a!==-1){let e=a>0?i[a-1]:null,t=Tv(i.substring(a+1)),n=t.includes(` `)||t.includes(`
6534
+ `)?`${t}\n`:`${t}\n\n`}`,_b=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},vb=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,yb=[],bb=({onOpenSettings:e,scrollToBottom:r,showScrollToBottom:a=!1,onScrollToBottom:o,submissionBlocked:l=!1,surface:u})=>{let{t:f}=ot(),[p,m]=Z.useState({open:!1,title:``,content:``}),[h,g]=Z.useState(`normal`),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(!1),[k,j]=Z.useState(``),[M,N]=Z.useState(!1),[P,I]=Z.useState(``),[R,z]=Z.useState(!1),[V,H]=Z.useState(``),[te,ne]=Z.useState(!1),[ae,oe]=Z.useState(``),[se,ce]=Z.useState(null),[ue,de]=Z.useState(null),fe=Z.useRef(null),pe=Z.useRef(null),[me,he]=Z.useState(!1),ge=Z.useRef(null);Z.useEffect(()=>()=>{ge.current!==null&&window.clearTimeout(ge.current),fe.current!==null&&window.clearTimeout(fe.current),pe.current!==null&&window.clearTimeout(pe.current)},[]);let[_e,ve]=Z.useState(!1),[ye,be]=Z.useState(!1),[xe,Se]=Z.useState(null),Ce=Z.useId(),[De,Ae]=Z.useState(``),[Me,Ne]=Z.useState(``),[Pe,Fe]=Z.useState(!1),[Ie,ze]=Z.useState(!1),Ve=Z.useRef(0),He=Z.useCallback(()=>{Ve.current=Date.now()+500},[]),Ue=Z.useRef(0),We=Z.useRef(!1),[Ge,Ke]=Z.useState(-1),qe=Z.useRef(()=>{}),Je=Z.useRef((...e)=>Promise.resolve().then(()=>Qr.getState().sendMessage(...e))).current,Ye=Qr(e=>e.currentSessionId),Xe=mi(e=>e.currentProviderId),Ze=mi(e=>e.currentModelId),Qe=mi(e=>e.currentAgentName),$e=mi(e=>e.currentVariant),et=mi(e=>e.providers),tt=mi(e=>e.agents),nt=mi(e=>e.getVisibleAgents),rt=Z.useMemo(()=>Wp(nt()),[nt,tt]),it=mi(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),at=mi(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),st=Z.useMemo(()=>{let e=et.find(e=>e.id===Xe)?.models?.find(e=>e.id===Ze);return Zp(e)},[Ze,Xe,et]),ct=Te(e=>e.currentDirectory),lt=is()??ct,{ensureSessionRenderable:ut}=zl(),ft=Qr(Z.useCallback(e=>Ye?e.getDirectoryForSession(Ye):null,[Ye])),pt=Di(Ye??``,ft??void 0),mt=Z.useMemo(()=>oy(pt),[pt]),ht=lr(Ye,ft??void 0),gt=ht?.agent,vt=ht?.model?.id,bt=ht?.model?.providerID,xt=ht?.model?.variant,St=mi(e=>e.activeDirectoryKey),Ct=Z.useRef(0),wt=Z.useRef(null),Tt=Qr(e=>e.newSessionDraft),Dt=!!Tt?.open,Ot=Qr(e=>e.newSessionDraft.draftSubmitting??!1),kt=Qr(e=>e.newSessionDraft.draftEstablishing??!1),At=Ot||kt,Mt=Qr(e=>e.openNewSessionDraft),Ft=Qr(e=>e.setDraftPermissionAutoAcceptEnabled),Lt=Sr(e=>e.autoAccept),Rt=Sr(e=>e.saving),Vt=Sr(e=>e.setSessionAutoAccept),Ht=Qr(e=>e.setNewSessionDraftTarget),Ut=Qr(e=>e.availableWorktreesByProject),Wt=Qr(e=>e.abortPromptSessionId),qt=Qr(e=>e.clearAbortPrompt),Jt=It(e=>e.consumePendingInputText),Yt=It(e=>e.pendingPresetSubmit),Xt=It(e=>e.pendingInputText),Zt=It(e=>e.pendingInputMode),en=It(e=>e.consumePendingSyntheticParts),tn=It(e=>e.activeAttachmentDraft),nn=Gl(Z.useCallback(e=>{let t=Ye??(Dt?`draft`:``);return t?e.drafts[t]??Vy:Vy},[Dt,Ye])),an=zr(Ye??``),on=Z.useSyncExternalStore(t,n,n),sn=tn?.transportIdentity??null,ln=tn?.owner.kind??null,un=tn?.owner.ownerID??null,dn=Z.useMemo(()=>vb(on,Ye,Tt.draftID,sn&&ln&&un?{transportIdentity:sn,owner:{kind:ln,ownerID:un}}:null),[un,ln,sn,on,Ye,Tt.draftID]),fn=dn?le(dn):null,pn=It(Z.useCallback(e=>fn?e.draftAttachmentViews[fn]:void 0,[fn])),mn=It(Z.useCallback(e=>fn?e.drafts[fn]:void 0,[fn])),hn=Z.useMemo(()=>{if(!mn||!pn)return yb;let e=mn.attachments.flatMap(e=>{let t=pn[e.attachmentRefID];return t?[t]:[]});return e.length===0?yb:e},[pn,mn]);Z.useEffect(()=>{dn&&It.getState().hydrateDraftAttachments(dn)},[dn]);let gn=nm(),_n=s(e=>e.activeMainTab===`chat`),vn=Tr(Ye??``,lt??void 0),yn=rm({kind:`primary`,surfaceID:`primary`,active:_n,sessionID:Ye,directory:lt??null,activity:{phase:vn?.type===`busy`?`busy`:vn?.type===`retry`?`retry`:`idle`,canAbort:vn?.type===`busy`||vn?.type===`retry`},draftKey:dn,transportIdentity:on,runtimeGeneration:c(),selection:{value:{providerID:Xe,modelID:Ze,agent:Qe,variant:$e},catalog:{providers:et,agents:rt,variants:st,variantsReady:!it,ready:!it&&!at,loading:it||at},flush:async()=>{let e=Qr.getState().currentSessionId;if(!e)return;let t=c(),r=n(),i=Ct.current,a=e,o=Qr.getState().getDirectoryForSession(a)??null,s=mr(o);if(mi.getState().activeDirectoryKey!==s&&await mi.getState().activateDirectory(o),c()!==t||n()!==r||Qr.getState().currentSessionId!==a||mi.getState().activeDirectoryKey!==s||Ct.current!==i)return;await ut(a,{directory:o??void 0});let l=Qr.getState().getDirectoryForSession(a)??null,u=mr(l);if(c()!==t||n()!==r||Qr.getState().currentSessionId!==a||l!==o||u!==s||mi.getState().activeDirectoryKey!==s||Ct.current!==i)return;let d=mi.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=oy(Pi(a,l??void 0)),m=Bt.getState(),h=ny({sessionId:a,latestUserChoice:p,catalog:f,memory:m,fallbackAgentName:d.currentAgentName});if(!h)return;let g=[a,h.source,h.messageId??``,h.agent??``,h.providerID,h.modelID,h.variant??``,s].join(`|`);wt.current!==g&&(ry(h,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:a,memory:m}),wt.current=g)},change:async e=>{Ct.current+=1;let t=mi.getState();Zv(e,{currentAgentName:t.currentAgentName,setAgent:t.setAgent,setProvider:t.setProvider,setModel:t.setModel,setCurrentVariant:t.setCurrentVariant,saveAgentModelSelection:t.saveAgentModelSelection},{sessionId:Qr.getState().currentSessionId,memory:Bt.getState()});let n=Qr.getState().currentSessionId;if(n){let r=Qr.getState().getDirectoryForSession(n)??void 0,i=oy(Pi(n,r)),a=Bt.getState(),o=ny({sessionId:n,latestUserChoice:i,catalog:{providers:t.providers,agents:t.getVisibleAgents()},memory:a,fallbackAgentName:e.agent??t.currentAgentName});o&&(wt.current=[n,o.source,o.messageId??``,o.agent??``,o.providerID,o.modelID,o.variant??``,mi.getState().activeDirectoryKey].join(`|`))}}},resources:{attachments:hn,addAttachment:async e=>{dn&&await Kn(dn,()=>It.getState()).addLocal(e)},removeAttachment:async e=>dn?Kn(dn,()=>It.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>dn?Kn(dn,()=>It.getState()).clearRootAttachments():!1,restoreAttachments:async e=>dn?Kn(dn,()=>It.getState()).restoreRootAttachments(e):!1,pendingInput:Xt===null?null:{text:Xt,mode:Zt},consumePendingInput:Jt,pendingPreset:Yt,consumePendingPreset:()=>It.getState().consumePendingPresetSubmit(),consumeSyntheticParts:en,restoreSyntheticParts:e=>It.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:nn,removeInlineDraft:e=>{let t=Ye??(Dt?`draft`:``);t&&Gl.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=Ye??(Dt?`draft`:``);!t||e.length===0||Gl.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:an,captureRuntime:()=>It.getState().captureDraftRuntime(),getDraft:e=>It.getState().getDraft(e),abortPrompt:{sessionID:Wt,clear:qt}},backend:{send:e=>{qv(e,{transportIdentity:n(),runtimeGeneration:c()});let t=Jv(e);return Je(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Xi(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()=>Mt(),compact:async e=>ke.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Pt(e.sessionID),Nn(e.sessionID??``))},shortcuts:{cycle:e=>qe.current(e),new:()=>Mt(),abort:()=>(Ye&&Pt(Ye),Nn(Ye??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),J=im(yn,u??gn);am(J),Z.useLayoutEffect(()=>{if(!J.active){Kv(J.surfaceID);return}return Gv(J),()=>Kv(J.surfaceID)},[J]);let bn=Xv(J),Sn=J.resources??(J.kind===`primary`?yn.resources:void 0);if(!Sn)throw Error(`chat-input-surface-resources-incomplete`);let Cn=[...Sn.attachments],Tn=J.sessionID,Dn=om(J,At),kn=J.kind===`secondary`?J.commands.hasNewDraft:Dt,An=kn,jn=J.directory??lt,Mn=J.draftKey??dn,Pn=Z.useMemo(()=>{if(J.kind===`secondary`)return cm(J,!1,!1);let e=Tn?Qy(Tn,ft??void 0):!1;return cm(J,e,kn)},[J,Tn,ft,kn]),Fn=(e,t,n,r,i,a,o,s,c,l)=>bn?bn.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`)),In=Z.useCallback(()=>bn?bn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[bn]),Ln=jt(e=>e.projects),Rn=jt(e=>e.activeProjectId),zn=jt(e=>e.setActiveProjectIdOnly),[Bn,Un]=Z.useState(!1),[Wn,Gn]=Z.useState(!1),qn=Z.useMemo(()=>Tn?Ki({autoAccept:Lt,sessions:[],sessionById:Ai(),sessionID:Tn}):Tt.permissionAutoAcceptEnabled===!0,[Tn,Tt.permissionAutoAcceptEnabled,Lt]),Yn=mi(e=>e.agents),Xn=J.kind===`secondary`?J.selection.value.agent:Qe,Qn=J.kind===`secondary`?Wp(J.selection.catalog?.agents):Yn,$n=d()||Rv(Qn,Xn),er=Z.useCallback(()=>{Cr.error(f(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[f]),tr=J.selection.value,rr=J.selection.change,ir=J.selection.catalog,ar=Z.useMemo(()=>({selection:{providerID:tr.providerID??``,modelID:tr.modelID??``,agent:tr.agent??null,variant:tr.variant},onChange:async e=>{if(!rr)throw Error(`chat-input-surface-selection-readonly`);await rr({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!J.active,catalog:ir}),[ir,rr,tr.agent,tr.modelID,tr.providerID,tr.variant,J.active]);Z.useEffect(()=>{if(J.kind!==`primary`||!Ye){Ye||(wt.current=null);return}if(it||at||et.length===0||rt.length===0)return;let e=mr(ft);if(St!==e)return;let t=Bt.getState(),n=ny({sessionId:Ye,latestUserChoice:mt,catalog:{providers:et,agents:rt},memory:t,sessionEntity:bt&&vt?{agent:gt,model:{id:vt,providerID:bt,variant:xt}}:gt?{agent:gt}:null,fallbackAgentName:Qe});if(!n)return;let r=[Ye,n.source,n.messageId??``,n.agent??``,n.providerID,n.modelID,n.variant??``,St].join(`|`);if(wt.current===r)return;if((n.agent===void 0||n.agent===Qe)&&n.providerID===Xe&&n.modelID===Ze&&n.variant===$e){wt.current=r;return}if(mi.getState().activeDirectoryKey!==e)return;let i=mi.getState();ry(n,{currentAgentName:i.currentAgentName,setAgent:i.setAgent,setProvider:i.setProvider,setModel:i.setModel,setCurrentVariant:i.setCurrentVariant},{sessionId:Ye,memory:t}),wt.current=r},[J.kind,Ye,mt,et,rt,it,at,St,ft,Qe,Xe,Ze,$e,gt,vt,bt,xt]);let ur=mi(e=>e.getVisibleAgents),dr=J.kind===`primary`?ur():Hy,fr=mi(e=>J.kind===`primary`?e.providers:Uy),hr=J.kind===`secondary`?Wp(J.selection.catalog?.agents):dr,gr=J.kind===`secondary`?J.selection.catalog?.providers??Uy:fr,_r=J.kind===`secondary`&&(!J.selection.catalog?.ready||!!J.selection.catalog.error),vr=!J.active||!J.selection.change||_r,br=s(e=>e.isMobile),xr=s(e=>e.setImagePreviewOpen),wr=Z.useCallback(e=>{e.image&&(m(e),xr(!0))},[xr]),Er=Z.useCallback(e=>{m(t=>({...t,open:e})),xr(e)},[xr]),Dr=bl(e=>e.pending),Or=s(e=>e.inputBarOffset),kr=s(e=>e.persistChatDraft),jr=s(e=>e.inputSpellcheckEnabled),Mr=s(e=>e.isExpandedInput),Nr=s(e=>e.setExpandedInput),Ir=s(e=>e.setTimelineDialogOpen),Lr=Iy({draftKey:Mn,sessionTitles:new Map(Array.from(Ai(),([e,t])=>[e,t.title||e])),persistenceEnabled:kr}),Rr=Lr.document,Br=Rr.text,{replacePlainDocument:Hr,replaceProgrammaticText:Ur,applyBrowserEdit:Gr,insertReference:Kr,deleteReference:Jr,enterHistoryPreview:Yr,exitHistoryPreview:Xr,captureSubmission:$r,recoverSubmission:ei,confirmedFileMentions:ri,mentions:ai}=Lr,oi=Z.useCallback((e,t)=>Ur(e,t),[Ur]),ci=Z.useMemo(()=>new Set(ri.map(e=>e.value)),[ri]),li=Z.useRef(null),ui=Z.useRef(!1),di=Z.useRef(0),fi=Z.useRef(Br.length),gi=Z.useRef(null),yi=Z.useRef(0),bi=Z.useRef(!1),Ci=Z.useRef(null),Ti=Z.useRef(!1),Oi=Z.useRef(null),ji=Z.useRef([]),Mi=Z.useRef(!1),Fi=Z.useRef(null),Ii=Z.useRef(!1),Li=Z.useRef(null),Ri=Z.useRef(null),Bi=Z.useRef(null),Vi=Z.useRef(Br),Hi=Z.useRef(new Set),Ui=Lr.getDocument,Wi=Z.useCallback((e,t,n=[])=>oi(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}`))]}),[oi]),Gi=$m(Qm()),{git:qi,vscode:Ji}=Do(),Yi=s(e=>e.shortcutOverrides.cycle_agent),Zi=s(e=>e.shortcutOverrides),Qi=Z.useMemo(()=>Ya(`cycle_agent`,Yi?{cycle_agent:Yi}:void 0),[Yi]),$i=Z.useMemo(()=>Ya(`clear_all_messages`,Zi),[Zi]),{currentTheme:ea}=za(),na=Os(),ra=Bs(jn),ia=ws(e=>jn?e.directories.get(jn)?.status??null:null),aa=ws(e=>e.ensureStatus),oa=ws(e=>e.fetchStatus),[sa,ca]=Z.useState(!1),ua=Z.useRef(null),[da,pa]=Z.useState(!1);Z.useEffect(()=>{!jn||!qi||aa(jn,qi)},[jn,qi,aa]),Z.useEffect(()=>{if(!(!jn||!qi))return hi.onGitRefreshHint(e=>{ib(e.directory)===ib(jn)&&oa(jn,qi)})},[jn,qi,oa]);let ha=Z.useCallback(async e=>{if(!Tn)return;let t=Qr.getState().getDirectoryForSession(Tn)||jn||``;if(!t){Cr.error(f(`diffView.reviewDialog.toast.noSessionDirectory`));return}Gn(!0);try{await wn({originalSessionID:Tn,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}),Un(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),Cr.error(e instanceof Error?e.message:f(`diffView.reviewDialog.toast.startFailed`))}finally{Gn(!1)}},[Tn,jn,f]),ga=Mr&&!br,va=Mr&&br,xa=ga||va,Ta=`1.5rem`,Ea=f(Tn||kn?h===`shell`?`chat.chatInput.placeholder.shell`:br||da?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Oa=f(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=gi.current;if(!e)return;let t=e=>{let t=e>0&&e<qy;pa(e=>e===t?e:t)};if(t(e.clientWidth),typeof ResizeObserver>`u`){let n=()=>t(e.clientWidth);return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)}let n=new ResizeObserver(n=>{t(n[0]?.contentRect.width??e.clientWidth)});return n.observe(e),()=>n.disconnect()},[]);let ka=Cn,Aa=Z.useMemo(()=>new Set(hr.map(e=>e.name.toLowerCase())),[hr]),ja=Z.useRef(Aa);ja.current=Aa;let Ia=Gy({inputMode:h,message:Br,showCommandAutocomplete:M,showSkillAutocomplete:R}),La=Vn({directory:jn,enabled:Ia}),Ra=Z.useMemo(()=>La.data??[],[La.data]),Ba=ti({directory:jn,enabled:Ia}),Ha=Z.useMemo(()=>Ba.data??[],[Ba.data]),Ua=Z.useMemo(()=>new Map(Ha.map(e=>[e.name.toLowerCase(),e.name])),[Ha]),Wa=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`plan-feature`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!br&&!d()&&e.add(`handoff-review`);for(let t of Ra)e.add(t.name.toLowerCase());for(let t of Ha)e.add(t.name.toLowerCase());return e},[Ra,Ha,br]),Ga=Z.useMemo(()=>{if(!Br||!Br.includes(`/`)||h===`shell`||Wa.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(Br))!==null;){let t=n[2]??``,r=n[3];if(!Wa.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=Ua.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:ie({trigger:`/`,icon:`book-open`,label:o},Br.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:ie({trigger:`/`,icon:`command`,label:r},Br.slice(i,i+a))})}return e},[Ua,h,Wa,Br]),Ka=ma(e=>e.snippets),qa=Z.useMemo(()=>{let e=new Set;for(let t of Ka){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[Ka]),Ja=Z.useMemo(()=>{if(!Br||!Br.includes(`#`)||h===`shell`||qa.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(Br))!==null;){let t=n[2];if(!qa.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[h,qa,Br]),$a=Z.useMemo(()=>!Br||!Br.includes(`@`)||h===`shell`?[]:Wr(Br,{confirmedValues:ci,agentNames:Aa}),[ci,h,Aa,Br]),eo=Z.useMemo(()=>{if(!Br||!Br.includes(`[`)||h===`shell`||ka.length===0)return[];let e=ka.filter(Oe),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return Re(Br,e.map(e=>e.filename)).flatMap(e=>{let n=G(Br.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:ie({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},Br.slice(e.start,e.end))}]})},[h,Br,ka]),to=Z.useMemo(()=>{if(!Br||h===`shell`)return null;let e=[...P_(Br),...X_(Br),...z_($a),...Ga,...Ja,...eo,...Rr.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return F_(Br,e)},[eo,Ga,Ja,$a,Rr.references,h,Br]),no=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?nb(e.serverPath):e.dataUrl})),[]),[ro,io]=Z.useState(null),ao=Z.useRef(null),[oo,so]=Z.useState(!1),[co,lo]=Z.useState(!1),[uo,fo]=Z.useState(null),[po,mo]=Z.useState(null),ho=C(e=>e.followUpBehavior),go=Z.useMemo(()=>{let e=bn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[bn]),_o=iu({transportIdentity:go?.transportIdentity??``,directory:go?.directory??``,sessionID:go?.sessionID??``}),vo=Z.useMemo(()=>Tn?x(Tn):null,[Tn]),yo=C(Z.useCallback(e=>go?b(e,go):By,[go])),bo=C(Z.useCallback(e=>vo?b(e,vo):By,[vo])),xo=Z.useMemo(()=>bo.length===0?yo:yo.length===0?bo:[...bo,...yo],[yo,bo]),So=_o.mode===`server`?By:xo,Co=C(Z.useCallback(e=>go?B(e,go):By,[go])),wo=C(e=>e.clearQueue),To=C(e=>e.removeFromQueue),Eo=Sn.inlineDrafts,Oo=Eo.length>0,[ko,Ao,jo]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of Eo)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[Eo]),Mo=Z.useCallback(e=>{for(let t of Sn.inlineDrafts)t.source===e&&Sn.removeInlineDraft(t.id)},[Sn]),No=Z.useCallback(()=>{for(let e of Sn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&Sn.removeInlineDraft(e.id)},[Sn]),Po=Sn.history;Z.useEffect(()=>{Vi.current=Br},[Br]),Z.useLayoutEffect(()=>{g(`normal`),Ke(-1)},[Mn?.transportIdentity,Mn?.owner.kind,Mn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!kn||br)return;let e=()=>{let e=li.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[kn,br]);let Fo=Gh(J.kind===`primary`?Tn:null,J.kind===`primary`?jn??void 0:void 0),Io=J.activity?.phase??Fo.phase,Lo=wi(Z.useCallback(e=>{if(!Tn)return!1;let t=e.runsByOriginalSessionID[Tn];return t?.status===`running`&&t.runtimeKey===i()},[Tn])),Ro=q(e=>{br&&(He(),de(e),li.current?.blur(),mi.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),zo=Sn.pendingInput,Bo=Sn.consumePendingInput;Z.useEffect(()=>{if(zo===null)return;let e=Bo();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=gb(Vi.current,e.text);Vi.current=t,oi(t)}else if(e.mode===`append-inline`){let t=_b(Vi.current,e.text);Vi.current=t,oi(t)}else Hr(e.text);setTimeout(()=>{li.current?.focus()},0)}},[zo,Bo,Hr,oi]);let Vo=Br.trim().length>0||ka.length>0||Oo,Ho=_o.mode===`server`?_o.items.length>0:So.length>0||Co.length>0,Uo=!Qd(_o.mode),Wo=Vo||Ho,Go=Qr(e=>e.stagedMessageEdit?.sessionId===Tn?e.stagedMessageEdit.messageId:null),Ko=Io===`busy`||Io===`retry`,qo=J.activity?.canAbort??Ko,Jo=Z.useCallback(()=>{let e=li.current,t=e?.value??Ui().text;t!==Ui().text&&Gr(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=Ui();return{message:n.text,document:n,hasContent:n.text.trim().length>0||ka.length>0||Oo}},[Gr,Ui,Oo,ka.length]),Yo=Z.useRef(async()=>{}),Xo=J.surfaceID,Zo=Tt?.draftID??null,Qo=qr(Z.useMemo(()=>xn(Xo),[Xo])),$o=qr(Z.useMemo(()=>_t(Zo),[Zo])),es=Z.useMemo(()=>Et(Qo,$o),[Qo,$o]),ts=(e=`send`)=>qr.getState().beginFlight(Xo,e),ns=()=>{qr.getState().endFlight(Xo)},rs=()=>qr.getState().isInFlight(Xo),as=Z.useRef(null);Z.useEffect(()=>{if(J.kind!==`primary`||!Go){as.current=null;return}as.current!==Go&&(as.current=Go,Yp(li)||requestAnimationFrame(()=>Yp(li)))},[Go,J.kind]);let os=qr(Z.useMemo(()=>Zr(Zo),[Zo])),ss=q(async()=>{let e=Qr.getState().newSessionDraft.draftID;if(!e||!qr.getState().isEstablishing(e))return!1;let t=Jo();if(!t.hasContent)return!1;let n=K(t.document,`queue-canonical`);if(!n.ok)return Cr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;if(await J.selection.flush(),!qr.getState().isEstablishing(e))return!1;let r=iy(mi.getState());if(!r?.providerID||!r?.modelID)return Cr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;let i=no(ka);return qr.getState().enqueueEstablishingFollowUp({draftID:e,content:n.text,sendConfig:{providerID:r.providerID,modelID:r.modelID,...r.agent?{agent:r.agent}:{},...r.variant?{variant:r.variant}:{}},attachments:i,composerDocument:t.document})?(Hr(``),Ke(-1),Nr(!1),i.length>0&&Sn.clearAttachments(),!0):!1}),cs=()=>{if(Tn)return!1;let e=Qr.getState().newSessionDraft.draftID;return qr.getState().isEstablishing(e)?(ss(),!0):!1},ls=q(async()=>{if(!J.active||rs())return;if(Tn){let e=Qr.getState().stagedMessageEdit;if(e&&e.sessionId===Tn){Qr.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await Kt(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{Qr.getState().endMessageEditCommit(e.sessionId,e.messageId)}Qr.getState().stagedMessageEdit===e&&Qr.getState().clearStagedMessageEdit(e.sessionId)}}let e=Jo(),t=K(e.document);if(!t.ok){Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:t.chunks??[],semantics:t.semantics??[]},i=t.text,a=i.trimStart(),o=r.chunks.every(e=>e.provenance===`authored`)&&h===`normal`&&a.startsWith(`/`)?Tv(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(o&&!bs(o,e=>em(J,{name:e.name,source:`openchamber`}))||l||!e.hasContent||!Tn)return;if(Uo||!zt(J.deliveryTarget?.kind,_o.mode)){Yo.current(Ko?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&xv(i,h)){Yo.current();return}if(!ts(`queue`))return;let s=J.transportIdentity,u=J.runtimeGeneration,d=Sn.captureRuntime(),p=go,m=J.kind===`primary`?go?.sessionID??Tn:null,g=[...Sn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Jl(e.document.text,g),e.document.references).document:e.document,y=K(_,`queue-canonical`);if(!y.ok){ns(),Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let b=no(ka),w=$r(),T=b,E=nr(),D=!1,O=null,k=()=>{D&&p&&(_o.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(C.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&ei(w),T.length>0&&await Sn.restoreAttachments(T),e&&Sn.restoreSyntheticParts(e),g.length>0&&Sn.restoreInlineDrafts(g)};try{if(!p){Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(_o.mode===`server`){if(!Mn){Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}Si({stage:()=>{_o.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:ai}}),D=!0},clearComposer:()=>{Hr(``),Ke(-1),Nr(!1)}})}else Si({stage:()=>{C.getState().bindLegacyQueue(x(p.sessionID),p),C.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:ai}),O=E.requestID},clearComposer:()=>{Hr(``),Ke(-1),Nr(!1)}});if(await J.selection.flush(),!En({transportIdentity:s,generation:u},{transportIdentity:n(),generation:c()})){await A();return}if(!En(d,Sn.captureRuntime())){await A();return}if(m&&Qr.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==n()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&S(Qr.getState().getDirectoryForSession(m))!==S(p.directory)){await A();return}let t=p,r=J.kind===`primary`?(()=>{let e=mi.getState(),t=m?Qr.getState().getDirectoryForSession(m)??null:null;return iy(e,{expectedConfigKey:mr(t),activeDirectoryKey:e.activeDirectoryKey})})():J.selection.value.providerID&&J.selection.value.modelID?{...J.selection.value,providerID:J.selection.value.providerID,modelID:J.selection.value.modelID}:void 0;if(!or(r)){await A();return}if(_o.mode===`server`){if(!Mn){await A(),Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let n=Qt({draftKey:Mn,runtime:d,document:e.document,attachments:ka,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?Sn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=pi({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:hr,installedSkillNames:new Set(_i(re,jn).map(e=>e.name)),directory:jn,root:na||jn,confirmedFilePaths:ri.map(e=>e.path),confirmedDirectoryPaths:ri.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:ka});return o=e.attachments,dt({text:g.length>0?Jl(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:Pr(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...rn(b),...rn(o),...(i??[]).flatMap(e=>rn(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 A(i),Cr.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Ar(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Jn({capture:n,admit:async()=>{let n=await _o.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:ai,sendConfig:r,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return n.status===`committed`&&(e=!0,D=!1),n},captureRuntime:Sn.captureRuntime,getCurrentDraftKey:()=>Mn,getDocument:Ui,consumeBody:()=>Hr(``),getAttachments:()=>Sn.attachments,removeAttachment:Sn.removeAttachment,getInlineDrafts:()=>Sn.inlineDrafts,removeInlineDraft:Sn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!br&&li.current?.focus()}catch(e){await A(i),Cr.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)Sn.removeInlineDraft(e.id);b.length>0&&Sn.clearAttachments(),br||li.current?.focus()}catch(e){await A(),Cr.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{ns()}}),us=q(()=>{Pv(()=>ls(),()=>{Cr.error(f(`chat.chatInput.toast.messageSendFailed`))})}),ds=q(async(e,t,n,r)=>{if(Uo||!J.draftKey)return!1;try{let i=await Hn({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=It.getState(),o=a.getDraft(J.draftKey);return ef(await Gt({key:J.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(Cr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return Cr.error(f(`chat.chatInput.toast.messageSendFailed`)),!1}}),fs=q(e=>{if(!(l||Uo)){if(bn){bn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}Cr.error(f(`chat.chatInput.toast.messageSendFailed`))}}),ps=q(()=>{He(),de(`agent`),li.current?.blur(),mi.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),ms=Z.useCallback(()=>{so(!0)},[]),hs=Z.useCallback(()=>{lo(!0)},[]),gs=async e=>{if(!J.active||l||cs()||rs())return;let t=e?.queuedOnly??!1,i=e?.queuedMessageId,a=e?.delivery===`steer`&&Ko?`steer`:void 0,o=e?.presetText==null?Jo():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||ka.length>0||Oo},u=e?.presetText==null?$r():null,p=Cn,m=K(o.document,`direct-send-display`);if(!m.ok){Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}let g=m.text,v={chunks:m.chunks??[],semantics:m.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?yv(x,h):null,w=y&&xv(g,h),T=y&&h===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&h===`normal`&&x.startsWith(`/`)?Tv(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!bs(E,e=>em(J,{name:e.name,source:`openchamber`}))||t&&Uo)return;if(!t&&T){N(!1),I(``),br?Ro(`model`):(s.getState().setModelSelectorOpen(!0),mi.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&S&&S!==`model`)){if(!t&&Tn&&Ho&&Uo)return;if(!t&&Tn&&Ho&&_o.mode===`server`){o.hasContent&&us();return}if(!t&&Tn&&Ho){o.hasContent&&us();let e=So[0];e&&bn&&await bn.sendQueued(e.queueItemID,{options:Ko?{delivery:`steer`}:void 0});return}}let D=w?[]:i?So.filter(e=>e.id===i):So;if(t&&Lo)return;if(t){if(D.length===0||!Tn)return}else if(!o.hasContent&&!Ho||!Tn&&!kn)return;if(!Tn&&Dn||!ts())return;let O=!Tn&&kn&&!t&&!w?Qr.getState().newSessionDraft.draftID??null:null,k=O?W(`msg`):void 0;if(O&&k&&!qr.getState().beginEstablishing({draftID:O,primaryMessageID:k})){ns();return}let A=()=>{pr(),O&&qr.getState().clearEstablishing(O)},j=e=>{let t=Qr.getState().currentSessionId,r=(t?Qr.getState().getDirectoryForSession(t):null)??jn??``;if(!t||!r){qr.getState().clearEstablishing(e);return}Nv({draftID:e,sessionID:t,directory:r,transportIdentity:n(),runtimeGeneration:c(),admitServer:_o.mode===`server`?async e=>_o.actions.admit({requestID:e.requestID,scope:{directory:r,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?rn(e.attachments):void 0}):void 0})};if(Tn&&!t&&!w&&Lo){ns(),us();return}let M=!t&&!w;M&&(Hr(``),Ke(-1),Nr(!1));let P=!1,F,L,R=!1;try{if(kv({surfaceKind:J.kind,currentSessionId:Tn,queuedOnly:t,resourcePolicy:w,inputMode:h,localCommand:S})&&Tn){let e=Qr.getState().getDirectoryForSession(Tn)??jn??null,t=Qr.getState().stagedMessageEdit;t&&t.sessionId===Tn&&(L={sessionId:t.sessionId,messageId:t.messageId},Qr.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=mi.getState(),r=iy(n,{expectedConfigKey:mr(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=no(ka);F=yt({sessionId:Tn,directory:e,content:o.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=J.kind===`primary`?(()=>{if(t){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(go?.sessionID)return go.sessionID}return Tn})():null,n=t?D[0]?.sendConfig:void 0;if(t&&n||await J.selection.flush(),e!==null&&Qr.getState().currentSessionId!==e)return;let s=async()=>{let t=n?{...n}:J.kind===`primary`?(()=>{let t=mi.getState();if(!e)return ay({captured:iy(t),surfaceSelection:J.selection.value});let n=Qr.getState().getDirectoryForSession(e)??jn??null;return ay({captured:iy(t,{expectedConfigKey:mr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:J.selection.value})})():J.selection.value.providerID&&J.selection.value.modelID?{...J.selection.value,providerID:J.selection.value.providerID,modelID:J.selection.value.modelID}:void 0;if(J.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=Qr.getState().getDirectoryForSession(e)??jn??null,r=mr(n);if(mi.getState().activeDirectoryKey!==r&&await mi.getState().activateDirectory(n),Qr.getState().currentSessionId===e){let e=mi.getState();t=ay({captured:iy(e,{expectedConfigKey:mr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:J.selection.value})}}return t},c=await s(),l=!1,m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant;if(!m||!g){if(!l){l=!0;try{await mi.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await s(),m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant}catch{}}if(!m||!g){console.warn(`Cannot send message: provider or model not selected`),Cr.error(f(`chat.chatInput.toast.messageSendFailed`));return}}Tn&&!t&&!w&&await Zn(Tn)&&await Nn(Tn);let T={...a?{delivery:a}:{},commitStagedMessageEdit:!t,...F?{messageID:F.messageID,ticket:F}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:Qr.getState().getDirectoryForSession(e)??jn??null}:J.kind===`primary`&&Tn?{sessionId:Tn,directoryHint:Qr.getState().getDirectoryForSession(Tn)??jn??null}:{}},E=``,M=[],N,I=[],z=new Set(_i(re,jn).map(e=>e.name)),B=[],V=w?void 0:Sn.consumeSyntheticParts();for(let e=0;e<D.length;e++){let t=D[e],n=t.composerDocument&&K(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:jn,a=new Set(_i(re,i).map(e=>e.name)),o=pi({plan:r??ki(t.content),agents:hr,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(B.push(...o.semantics),!N&&o.agent&&(N=o.agent),e===0)E=o.text,M=xi([...no(t.attachments),...o.attachments]);else{let e=no(t.attachments);I.push({text:o.text,attachments:xi([...e,...o.attachments])})}}if(!t&&o.hasContent){let e=no(ka),t=pi({plan:v,agents:hr,installedSkillNames:z,directory:jn,root:na||jn,confirmedFilePaths:ri.map(e=>e.path),confirmedDirectoryPaths:ri.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:ka});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,M=xi([...e,...t.attachments])):I.push({text:t.text,attachments:xi([...e,...t.attachments])})}let H=Tn??(kn?`draft`:null),U=[];if(!t&&H&&!w&&(U=[...Sn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Jl(E,U);else if(I.length>0){let e=I[I.length-1];e.text=Jl(e.text,U)}else E=Jl(E,U);if(V&&V.length>0&&I.push(...Ni(V)),uo&&I.push({text:uo.contextText,synthetic:!0}),po&&(I.push({text:po.instructionsText,synthetic:!0}),I.push({text:po.contextText,synthetic:!0})),I.push(...Pr(B,Tn&&Qr.getState().getDirectoryForSession(Tn)||jn)),!E&&M.length===0&&I.length===0)return;if(O&&k){if(!await Vr({messageID:k,providerID:m,modelID:g,agent:y,text:E,attachments:M,additionalParts:I,agentMentionName:N}))return;if(!qr.getState().isEstablishing(O)){A();return}}let W=async()=>{if(A(),go&&D.length>0&&C.setState(e=>{let t=_(go),n=e.queuedMessages[t]??[],r=new Set(D.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...D,...n.filter(e=>!r.has(e.id))]}}}),t)return V&&Sn.restoreSyntheticParts(V),!0;Sn.pendingInput?.text===o.message&&Sn.consumePendingInput(),u&&ei(u);let e=!0;return p.length>0&&(e=await Sn.restoreAttachments(p)),V&&Sn.restoreSyntheticParts(V),U.length>0&&Sn.restoreInlineDrafts(U),e};if(!w&&Tn&&i){let e=go?b(C.getState(),go).find(e=>e.id===i||e.queueItemID===i):void 0;go&&e?.queueItemID&&e.operationID&&To(go,e.queueItemID,e.operationID)}else!w&&Tn&&Ho&&go&&wo(go);!t&&!w&&(Hr(``),Ke(-1),Nr(!1),Ov({queuedOnly:t,resourcePolicy:w,rootAttachmentCount:p.length})&&Sn.clearAttachments());let ee=()=>Ev({currentSessionId:Tn,messageRef:Vi,replacePlainDocument:Hr}),G=E.trimStart();if(h===`normal`&&G.startsWith(`/`)){let e=Tv(G.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!bs(e,e=>em(J,{name:e.name,source:`openchamber`})))return;if(Tn&&(e===`undo`||e===`redo`)&&Sv(G,h)&&ee(),e===`undo`&&Tn){try{await Qr.getState().handleSlashUndo(Tn),r?.()}catch(e){Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){Sv(G,h)&&ee(),await bn?.shortcut(`new`);return}if(e===`redo`&&Tn){try{await Qr.getState().handleSlashRedo(Tn),r?.()}catch(e){Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Tn){await Dv({command:`fork`,consumeCommandText:ee,forkSession:()=>Qr.getState().forkCurrentSession(Tn),waitForConnection:Ei,getDirectoryForSession:()=>Qr.getState().getDirectoryForSession(Tn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Tn&&Gi.timeline){Ir(!0);return}if(e===`compact`&&Tn){Dv({command:`compact`,consumeCommandText:ee,forkSession:async()=>void 0,waitForConnection:Ei,getDirectoryForSession:()=>J.directory??``,summarizeSession:e=>Mn?J.backend.compact({operation:`compact`,surfaceID:J.surfaceID,transportIdentity:J.transportIdentity,runtimeGeneration:J.runtimeGeneration,sessionID:Tn,directory:e,draftKey:Mn,deliveryTarget:J.deliveryTarget,providerID:m,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{Cr.error(f(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Tn){try{await Ei();let e=G.replace(/^\/\u2003?summary\b/i,``).trim(),t=e?` focused on: ${e}`:``,n=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await On(`session.summary.visible`,{topic_line:t}),a=await On(`session.summary.instructions`,{topic_block:n});await Fn(i,m,g,y,[],N,[{text:a,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Tn||kn)){try{await Ei();let e=await On(`session.review.visible`),t=await On(`session.review.instructions`);await Fn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Tn&&!br&&!d()){Un(!0);return}if(e===`plan-feature`&&(Tn||kn)){try{await Ei();let e=await On(`session.plan.visible`),t=await On(`session.plan.instructions`);await Fn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(Tn||kn)){A(),Nt.getState().setArmed(!0);let e=bv(G,h)??``;Hr(e),Vi.current=e,Ke(-1),e||Nr(!1);return}if(e===`craft-goal`&&(Tn||kn)){try{await Ei();let e=G.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await On(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await On(`session.craftGoal.instructions`);await Fn(t,m,g,y,[],N,[{text:n,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Tn||kn)){try{await Ei();let e=await On(`session.catchup.visible`),t=await On(`session.catchup.instructions`);await Fn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Tn||kn)){try{await Ei();let e=await On(`session.debug.visible`),t=await On(`session.debug.instructions`);await Fn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Tn||kn)){try{await Ei();let e=await On(`session.weigh.visible`),t=await On(`session.weigh.instructions`);await Fn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Tn||kn)){try{await Ei();let e=await On(`session.explore.visible`),t=await On(`session.explore.instructions`);await Fn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.exploreFailed`))}return}}let te=Tn&&Qr.getState().getDirectoryForSession(Tn)||jn;if(An||Tn&&!Qy(Tn,te)){let e=await cn().catch(()=>null);e&&I.push({text:zi(e),synthetic:!0})}try{let e=ma.getState().expandText;E=await e(E);for(let t of I)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let ne=Fn(E,m,g,y,M,N,I.length>0?I:void 0,x,h,T);P=!0,ne.finally(()=>{ns(),L&&Qr.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&ne.then(()=>{j(O)}).catch(()=>{qr.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),ne.then(()=>{uo&&fo(null),po&&mo(null)}).catch(e=>{F&&cr(F),W().then(e=>{e||Cr.error(f(`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`)){Cr.error(f(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){p.length>0&&Cr.error(f(`chat.chatInput.toast.sendAttachmentsFailed`));return}Cr.error(t||f(`chat.chatInput.toast.messageSendFailed`))}),br||li.current?.focus()}finally{R||(F&&cr(F),L&&Qr.getState().endMessageEditCommit(L.sessionId,L.messageId)),P||(M&&u&&ei(u),ns(),O&&j(O))}};Yo.current=gs;let ys=Z.useCallback(()=>{if(cs()||rs())return;let e=Jo(),t=h===`normal`&&e.hasContent&&Tn&&(Ko||Lo),n=t&&Qd(_o.mode)&&zt(J.deliveryTarget?.kind,_o.mode);ho===`queue`&&n?us():ho===`steer`&&t||ho===`queue`&&t&&!n?Yo.current(t?{delivery:`steer`}:void 0):Yo.current()},[h,Jo,Tn,Ko,Lo,ho,us,_o.mode,J.deliveryTarget?.kind,ss]),xs=Z.useCallback(e=>{if(rs())return;let t=(li.current?.value??Vi.current).trim(),n=t?`${e}\n${t}`:e;Yo.current({presetText:n})},[]),Cs=Z.useCallback(e=>{let t=_b(Ui().text,e);oi(t),li.current&&(li.current.value=t),setTimeout(()=>{li.current?.focus()},0)},[oi]),Ts=Z.useCallback(e=>{if(rs())return;let t=_b(li.current?.value??Vi.current,e);Yo.current({presetText:t})},[]),As=Sn.pendingPreset,js=Sn.consumePendingPreset;Z.useEffect(()=>{if(As==null)return;let e=js();e&&xs(e)},[As,js,xs]);let Ns=Z.useCallback(()=>{Hr(``),Ke(-1),Cn.length>0&&Sn.clearAttachments(),go&&wo(go),N(!1),z(!1),ne(!1),O(!1),h===`shell`&&g(`normal`)},[Cn.length,Sn,wo,go,Hr,h]),Is=e=>{if(!J.active||Kh(e))return;if($i&&Va(e,$i)&&!Dr){let t=li.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),Ns();return}}if(h===`shell`&&e.key===`Escape`){e.preventDefault(),g(`normal`);return}if(h===`shell`&&e.key===`Backspace`&&Br.length===0){e.preventDefault(),g(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=li.current,n=t?.selectionStart??Br.length,r=t?.selectionEnd??Br.length,i=Jr({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Zy(Lr.getDocument().text,i.start);e.preventDefault(),oi(t.text),requestAnimationFrame(()=>{li.current?.setSelectionRange(t.caret,t.caret),Js()}),Ys(t.text,t.caret);return}let a=Ee(Br,Cn.filter(Oe).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=Zy(a.text,a.caret);e.preventDefault(),oi(n.text);for(let e of Cn)t.has(e.filename.toLowerCase())&&Sn.removeAttachment(e.id);requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=n.caret,li.current.selectionEnd=n.caret),Js()}),Ys(n.text,n.caret);return}let o=R_(Br,Ua.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Zy(o.text,o.caret);e.preventDefault(),oi(t.text),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=t.caret,li.current.selectionEnd=t.caret),Js()}),Ys(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<Br.length){let n=Re(Br,Cn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=G(Br.slice(n.start+1,n.end-1)).trim(),r=Cn.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=Br[n.end]===` `?n.end+1:n.end,a=`${Br.slice(0,n.start)}${Br.slice(i)}`;e.preventDefault(),oi(a),r&&Sn.removeAttachment(r.id),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=n.start,li.current.selectionEnd=n.start),Js()}),Ys(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(Br[r-1]);)--r;let i=t+1;for(;i<Br.length&&!/\s/.test(Br[i]);)i+=1;let a=Br.slice(r,i),o=a.slice(1);if(Wy.test(a)&&!ja.current.has(o.toLowerCase())&&ni({mention:o,confirmed:ci.has(o),terminated:i<Br.length&&/\s/.test(Br[i])})){let t=Br[i]===` `?i+1:i,n=`${Br.slice(0,r)}${Br.slice(t)}`;e.preventDefault(),oi(n),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=r,li.current.selectionEnd=r),Js()}),Ys(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&Li.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Li.current.handleKeyDown(e.key);return}if(R&&Ri.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Ri.current.handleKeyDown(e.key);return}if(te&&Bi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Bi.current.handleKeyDown(e.key);return}if(D&&Fi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Fi.current.handleKeyDown(e.key);return}if(ga&&e.key===`Escape`){e.preventDefault(),Nr(!1);return}let n=Qi&&!Qi.includes(`shift`)?Xa(`shift+${Qi}`):``,r=n&&Va(e,n)?-1:+!!Va(e,Qi);if(r!==0&&!M&&!R&&!te&&!D){e.preventDefault(),e.stopPropagation(),bn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{li.current?.focus({preventScroll:!0})});return}let i=M||R||te||D,a=li.current?.selectionStart===0&&li.current?.selectionEnd===0,o=li.current?.selectionStart===Br.length&&li.current?.selectionEnd===Br.length,s=!i&&(Br.length===0||a),c=!i&&(Br.length===0||o);if(h===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=li.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),oi(t),requestAnimationFrame(()=>{let e=li.current;e&&(e.selectionStart=n,e.selectionEnd=r),Js()}),Ys(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=Br.slice(n,r);t(`${Br.slice(0,n)}${a}${s}${o}${Br.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=Br.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${Br.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&Po.length>0){if(e.preventDefault(),Ge===-1)Ke(0),Yr({text:Po[0],references:[]});else if(Ge<Po.length-1){let e=Ge+1;Ke(e),Yr({text:Po[e],references:[]})}requestAnimationFrame(()=>{li.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Ge>=0){if(e.preventDefault(),Ge===0)Ke(-1),Xr();else{let e=Ge-1;Ke(e),Yr({text:Po[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),cs()||rs())return;let t=e.ctrlKey||e.metaKey,n=h===`normal`&&Vo&&Tn&&(Ko||Lo),r=n&&Qd(_o.mode)&&zt(J.deliveryTarget?.kind,_o.mode);ho===`queue`?t||!n?gs():r?us():gs({delivery:`steer`}):t||!n?gs():gs({delivery:`steer`})}},Rs=Z.useCallback((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}},[]),zs=Z.useCallback(()=>{if(!ga){io(null);return}if(!M&&!R&&!te&&!D){io(null);return}let e=li.current,t=gi.current;if(!e||!t)return;let n=e.selectionStart??Br.length,r=Rs(e,n);if(!r)return;let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=i.top-a.top+(r.top-e.scrollTop),s=i.left-a.left+(r.left-e.scrollLeft),c=o-8,l=a.height-o-8,u=l>=260||l>=c?`below`:`above`,d=D?520:M||te?450:360,f=Math.max(8,Math.min(s-24,a.width-d-8)),p=Math.max(120,Math.min(260,u===`below`?l:c));io({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[ga,Rs,Br.length,M,D,te,R]);Z.useLayoutEffect(()=>{zs()},[zs,Br,M,R,te,D,ga]),Z.useEffect(()=>{if(!ga)return;let e=()=>zs();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[ga,zs]);let Vs=Z.useCallback(()=>{ao.current&&=(clearTimeout(ao.current),null),ca(!0),ao.current=setTimeout(()=>{ca(!1),ao.current=null},1800)},[]),Hs=Z.useCallback(()=>{if(Sn.abortPrompt.clear(),Vs(),J.kind===`secondary`){bn?.shortcut(`abort`);return}In()},[In,bn,Vs,J.kind,Sn]),Us=Z.useCallback((e=1)=>{if(_r)return;let t=$t(hr,J.selection.value.agent??Xn,e);if(!t||!J.selection.change)return;let n=sr({providerID:J.selection.value.providerID??``,modelID:J.selection.value.modelID??``,agent:J.selection.value.agent??null},t,hr,gr);J.selection.change({...J.selection.value,...n,agent:n.agent??void 0}),J.kind===`primary`&&(s.getState().addRecentAgent(t),J.sessionID&&Bt.getState().saveSessionAgentSelection(J.sessionID,t))},[hr,Xn,gr,_r,J.kind,J.selection,J.sessionID]);qe.current=Us;let Ws=Z.useRef(null),[Gs,Ks]=Z.useState(null),qs=Z.useCallback(e=>{Ks(t=>t===e?t:e)},[]),Js=Z.useCallback(e=>{let t=li.current;if(!t)return;let n=t.scrollTop;if(xa){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,ce(null),t.scrollTop!==n&&(t.scrollTop=n);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let r=t.ownerDocument?.defaultView,i=r?r.getComputedStyle(t):null,a=i?parseFloat(i.lineHeight):NaN,o=i?parseFloat(i.paddingTop):NaN,s=i?parseFloat(i.paddingBottom):NaN,c=Number.isNaN(o)||Number.isNaN(s)?16:o+s,l=Number.isNaN(a)?22:a,u=Ly({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:Ws.current??0,lineHeight:l,paddingTotal:c});t.style.height=`${u.height}px`,t.style.maxHeight=`${u.maxHeight}px`,t.style.overflowY=u.overflowY,t.scrollTop!==n&&(t.scrollTop=n),ce(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[xa]);Z.useLayoutEffect(()=>{let e=Br.length<fi.current;fi.current=Br.length,Js({allowShrink:e})},[Js,Br,br]),Z.useLayoutEffect(()=>{Ws.current=Gs,Js({allowShrink:Gs===null})},[Js,Gs]);let Ys=Z.useCallback((e,t,n=`manual`,r)=>{if(h===`shell`){N(!1),O(!1),z(!1),ne(!1);return}if(e.startsWith(`/`)){let n=e.indexOf(` `),r=e.indexOf(`
6535
+ `),i=Math.min(n===-1?e.length:n,r===-1?e.length:r);if(t<=i&&n===-1){let t=Tv(e.substring(1,i));I(t),N(!0),O(!1),z(!1),ne(!1);return}}N(!1);let i=e.substring(0,t),a=i.lastIndexOf(`/`);if(a!==-1){let e=a>0?i[a-1]:null,t=Tv(i.substring(a+1)),n=t.includes(` `)||t.includes(`
6536
6536
  `);if((!e||/\s/.test(e))&&!n){H(t),z(!0),O(!1);return}}z(!1),H(``);let o=i.lastIndexOf(`#`);if(o!==-1){let e=o>0?i[o-1]:null,t=i.substring(o+1);if((!e||/\s/.test(e))&&!t.includes(` `)&&!t.includes(`
6537
- `)){se(t),re(!0),O(!1);return}}re(!1);let s=vi({value:e,cursorPosition:t,inputSource:n,insertedText:r});s===null?O(!1):(j(s),O(!0))},[h,I,j,N,O,z,re,H,se]),Xs=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(h===`normal`&&!ui.current&&Wa.size>0&&e.includes(`/`)){let r=wv(e,Wa,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=Kr(a,o,s,(e,t)=>{let n=[...e];for(let e of br(t.text,{agentNames:Aa,includeUnterminatedPastedReferences:r===`paste`}))n=Ms(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=Ui(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=li.current;e&&Xp(u,ui.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),Js()}),Ys(l.text,c.end,r,i),{document:l,selection:c}},[Js,Kr,Ui,h,Aa,Wa,Ys]),Zs=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=li.current;if(!n){let n=Vr+e;Xs(n,n.length,n.length,t,e);return}let r=n.selectionStart??Vr.length,i=n.selectionEnd??Vr.length,a=`${Vr.substring(0,r)}${e}${Vr.substring(i)}`,o=r+e.length;Xs(a,o,o,t,e)},[Xs,Vr]),Qs=K((e,t)=>{let n=new Set(Te(wn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of wn)n.has(e.filename)&&Cn.removeAttachment(e.id)}),$s=Z.useCallback(e=>{Cn.removeAttachment(e.id)},[Cn]),ec=Z.useCallback(()=>{bi.current=!1,ji.current=[],Ci.current&&=(clearTimeout(Ci.current),null)},[]),tc=Z.useCallback(()=>{Ci.current&&clearTimeout(Ci.current),Ci.current=setTimeout(()=>{ec()},700)},[ec]),nc=Z.useCallback(()=>{Ti.current=!1,Oi.current&&=(clearTimeout(Oi.current),null)},[]),rc=Z.useCallback(()=>{Ti.current=!0,Oi.current&&clearTimeout(Oi.current),Oi.current=setTimeout(()=>{Ti.current=!1,Oi.current=null},700)},[]),ic=Z.useCallback(e=>{!d()||!bi.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),ec())},[ec]),ac=e=>{if(Or)return;let t=e.nativeEvent;if(d()&&bi.current){let n=ji.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){ec();return}}let n=e.target.value;Qs(Vi.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Yy(Vi.current,n):``,a=i.includes(`@`)||Ti.current;Ti.current&&nc();let o=a?`paste`:`manual`;if(h===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);g(`shell`),Ur(e),Js(),N(!1),z(!1),O(!1),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=t,li.current.selectionEnd=t)});return}Xs(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{ec(),nc()},[ec,nc]);let oc=Z.useCallback(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=li.current,i=r?.selectionStart??Vr.length,a=r?.selectionEnd??Vr.length,o=Ds(n,Vr.slice(0,i),Vr.slice(a)),s=`${Vr.slice(0,i)}${o}${Vr.slice(a)}`;Qs(Vr,s),Wi(s,t)},[Vr,Wi,Qs]),sc=Z.useCallback(async e=>{let t=rb(e.clipboardData);if(t.length>0&&(En||An)){e.preventDefault(),oc(t);return}if(h===`normal`&&(En||An)){let t=li.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=Vr.slice(n,r);if(Ky.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${Vr.slice(0,n)}[${i}](${t})${Vr.slice(r)}`,o=n+1+i.length+2+t.length+1;oi(a),requestAnimationFrame(()=>{let e=li.current;e&&(e.selectionStart=o,e.selectionEnd=o),Js()}),Ys(a,o,Xy(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(h===`normal`&&fy(Ui(),a)){e.preventDefault();let t=Ui().text,n=li.current,r=n?.selectionStart??Vr.length,i=n?.selectionEnd??Vr.length,o=py(a,Vr,Ui().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})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),dy(Ui())),s=qr(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=Ls(s.document.text,s.caret);li.current&&(li.current.value=s.document.text),requestAnimationFrame(()=>{li.current?.setSelectionRange(c,c),Js()}),Ys(s.document.text,c),Qs(t,s.document.text);return}a.includes(`@`)&&rc();return}if(!En&&!An){a.includes(`@`)&&rc();return}e.preventDefault();let o=Me(i,[...wn.map(e=>e.filename),...Hi.current]),s=Ve(o),c=Ui().text,l=li.current,u=l?.selectionStart??Vr.length,d=l?.selectionEnd??Vr.length,p=h===`normal`&&fy(Ui(),a)?py(a,Vr,Ui().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})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),dy(Ui())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=Ds(m,Vr.slice(0,u),Vr.slice(d));if(p){let e=qr(u,d,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=Ls(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;Xs(n,t+s.length,t+s.length,Xy(n),s),Qs(c,n)}else Zs(g,Xy(g)),Qs(c,`${Vr.slice(0,u)}${g}${Vr.slice(d)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Jy(i[e],t);Hi.current.add(t);try{await Cn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.clipboardAttachFailed`))}finally{Hi.current.delete(t)}}},[Cn,oc,wn,Js,En,Ui,h,qr,rc,Vr,An,Zs,f,Ys,Xs,oi,Qs]),cc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=L_(r,i,[...ze(Vr,wn.filter(ke).map(e=>e.filename)),...I_(Vr,Ua.keys()),...Ui().references]),o=a?.start??r,s=a?.end??i,c=Vr.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${Vr.slice(0,o)}${Vr.slice(s)}`;Xs(e,o,o),requestAnimationFrame(()=>{li.current?.setSelectionRange(o,o),Js()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{li.current?.setSelectionRange(o,s)})},[Js,wn,Ua,Xs,Ui,Vr]),lc=Z.useCallback(e=>{cc(e,`copy`)},[cc]),uc=Z.useCallback(e=>{cc(e,`cut`)},[cc]),dc=e=>{let t=li.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??di.current:di.current,Vr.length),r=Vr.substring(0,n).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():xc(e.path)||e.name,a=e.isDirectory?[i]:[],o=Fs(Vr,r===-1?n:r,n,`@${i}`);Wi(o.text,[i],a),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=o.caret,li.current.selectionEnd=o.caret),Js(),Ys(o.text,o.caret)}),O(!1),j(``),li.current?.focus()},fc=e=>{let t=li.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??di.current:di.current,Vr.length),r=Vr.substring(0,n).lastIndexOf(`@`),i=Fs(Vr,r===-1?n:r,n,`@${e}`);oi(i.text,t=>Ms(t,{kind:`agent`,value:e,path:e,label:e,range:{start:i.start,end:i.end}})),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=i.caret,li.current.selectionEnd=i.caret),Js(),Ys(i.text,i.caret)}),O(!1),j(``),li.current?.focus()},pc=K(e=>{Ii.current||(Ii.current=!0,(async()=>{try{let t=J.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){wr.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await dt(e.id,{directory:t}),!ii(e.id,t)){wr.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}si([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=Ui(),r=li.current?.selectionStart??n.text.length,i=n.text.substring(0,r).lastIndexOf(`@`),a=Ai().get(e.id)?.title||e.title||e.id,o=i===-1?r:i,s={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:a})},c=qr(o,r,s,{inlineBoundaries:!0,padDocumentEdges:!0}),l=Ls(c.document.text,c.caret);requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=l,li.current.selectionEnd=l),Js(),Ys(c.document.text,l)}),O(!1),j(``),li.current?.focus()}catch{wr.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Ii.current=!1}})())}),mc=K(e=>{let t=Ui(),n=li.current?.selectionStart??t.text.length,r=_s(t.text,n);if(!r)return!1;let i=qr(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=Ls(i.document.text,i.caret);return requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=o,li.current.selectionEnd=o),Js(),Ys(i.document.text,o),a&&(N(!1),z(!1))}),li.current?.focus(),a}),hc=e=>{mc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&H(``)},gc=(e,t)=>{let n=li.current?.selectionStart??Vr.length,r=Vr.substring(0,n).lastIndexOf(`#`),i=r===-1?n:r,a=`${Vr.substring(0,i)}#${t} ${Vr.substring(n)}`;oi(a);let o=i+t.length+2;requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=o,li.current.selectionEnd=o),Js(),Ys(a,o)}),re(!1),se(``),li.current?.focus()},_c=(e,t=!1)=>{if(!em(q,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){mc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&I(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&mc({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){I(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=wv(r,new Set([...Wa,e.name.toLowerCase()]),r.length);Ur(i?.text??r);let a=li.current;if(a&&(a._commandMetadata=e),N(!1),I(``),t){gs({presetText:n});return}let o=()=>{if(li.current){try{li.current.focus({preventScroll:!0})}catch{li.current.focus()}li.current.setSelectionRange(li.current.value.length,li.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{En&&li.current&&!xr&&li.current.focus()},[En,xr]),Z.useEffect(()=>{xr||fe(null)},[xr]);let vc=Cn.abortPrompt.sessionID,yc=Cn.abortPrompt.clear;Z.useEffect(()=>{vc&&vc!==En&&yc()},[En,vc,yc]),Z.useEffect(()=>{Mi.current=!!(En||An)},[En,An]);let bc=Z.useCallback(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-openchamber-file-path`)||t.some(e=>e.includes(`vnd.code.tree`)))return!0}return rv(e).length>0},[]),Q=Z.useCallback(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)},[]),xc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(na||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[na]),Sc=e=>{if(!bc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),yi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==T&&E(t),(En||An)&&!y&&w(!0)},Cc=e=>{bc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(En||An)&&!y&&w(!0))},wc=e=>{e.preventDefault(),e.stopPropagation(),yi.current--,yi.current<=0&&(yi.current=0,w(!1),E(!1),ec())},Tc=()=>{yi.current=0,w(!1),E(!1),ec()},Ec=async e=>{if(yi.current=0,!bc(e.dataTransfer)){ec();return}if(e.preventDefault(),e.stopPropagation(),w(!1),!En&&!An)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=li.current,r=Vi.current;if(n){let t=n.selectionStart??di.current,i=n.selectionEnd??t,a=Fs(r,t,i,e);oi(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,di.current=a.caret,n.focus()})}else{let t=Fs(r,r.length,r.length,e);oi(t.text)}ec();return}let n=rb(e.dataTransfer);if(n.length>0){d()&&(ji.current=n),oc(n),d()||ec();return}let r=Q(e.dataTransfer);if(r.length>0){let e=Ve(r.map(e=>e.name)),t=Ds(e,Vi.current.slice(0,li.current?.selectionStart??Vi.current.length),Vi.current.slice(li.current?.selectionEnd??Vi.current.length));Zs(t);for(let e of r)try{await Cn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}}ec()},Dc=e=>{bc(e.dataTransfer)&&(e.preventDefault(),d()&&(bi.current=!0,tc()))},Oc=Z.useRef(null),kc=Z.useRef(null),Ac=K((e=!0)=>{He.current=0;let t=()=>{let t=Jp(li);if(!t||(Yp(li),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),jc=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Ve(t.map(e=>e.name)),n=Ds(e,Vi.current.slice(0,li.current?.selectionStart??Vi.current.length),Vi.current.slice(li.current?.selectionEnd??Vi.current.length));Zs(n)}for(let e of t)try{await Cn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}},[Cn,Zs,f]),Mc=Z.useCallback(async()=>{try{let e=await Ji?.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(`
6538
- `);wr.error(f(`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&&(Ac(!1),await jc(r),Ac())}catch(e){console.error(`VS Code file pick failed`,e),wr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.vscodePickFailed`))}},[jc,Ac,f,Ji]),Fc=Z.useCallback(()=>{if(d()){Mc();return}Oc.current?.click()},[Mc]),Ic=Z.useCallback(()=>{if(d()){Mc();return}kc.current?.click()},[Mc]),Lc=Z.useCallback(async()=>{if(!Nc()){Ic();return}try{let e=await Pc(20);if(e===null){Ic();return}e.length>0&&(Ac(!1),await jc(e),Ac())}catch(e){console.error(`Native photo pick failed`,e),wr.error(f(`chat.chatInput.toast.attachFileFailed`))}},[jc,Ac,Ic,f]),Rc=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(Ac(!1),await jc(t),e.target.value=``,Ac())},[jc,Ac]),zc=`gap-x-1.5 gap-y-0`,Bc=d(),Vc=q.kind===`primary`&&jn&&!Bc,Hc=Z.useMemo(()=>(Et?.selectedProjectId?Rn.find(e=>e.id===Et.selectedProjectId)??null:null)||(zn?Rn.find(e=>e.id===zn)??null:null)||(Rn[0]??null),[zn,Et?.selectedProjectId,Rn]),Uc=Z.useMemo(()=>ib(Hc?.path??null),[Hc?.path]),Wc=Hc?ab(Hc):null,Gc=Ps(Uc),Kc=ws(e=>Uc?e.directories.get(Uc)?.lastBranchesFetch??0:0),qc=Bs(Uc),Jc=!!Gc?.all,Yc=ws(e=>e.fetchBranches),[Xc,Zc]=Z.useState(!1);Z.useEffect(()=>{!Vc||!Uc||!qi||qc!==null||oa(Uc,qi,{silent:!0})},[oa,qi,qc,Uc,Vc]),Z.useEffect(()=>{if(!Vc||!Uc||!Hc||!qi||qc!==!0){Zc(!1);return}let e=!Kc||Date.now()-Kc>3e4;if(Jc&&!e){Zc(!1);return}let t=!1;return Zc(!Jc),Yc(Uc,qi).finally(()=>{t||Zc(!1)}),()=>{t=!0}},[Yc,qi,Hc,Kc,Jc,qc,Uc,Vc]);let Qc=Es(Uc),$c=Gc?.current?.trim()||Qc?.trim()||``,el=Z.useMemo(()=>{if(!Hc)return null;let e=ib(Hc.path);return!e||!$c?null:{value:e,label:$c}},[Hc,$c]),tl=Z.useMemo(()=>{if(!Hc)return[];let e=Uc?Wt.get(Uc)??Wt.get(Hc.path)??[]:[];return Ir({projectRoot:ib(Hc.path)??``,rootBranch:$c,worktrees:e,pendingBootstrapDirectory:Et?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[Wt,Et?.bootstrapPendingDirectory,Hc,$c,Uc]),nl=Z.useMemo(()=>ib(Et?.bootstrapPendingDirectory??null)??ib(Et?.directoryOverride??null)??Uc,[Et?.bootstrapPendingDirectory,Et?.directoryOverride,Uc]),rl=Z.useMemo(()=>{let e=ib(Et?.bootstrapPendingDirectory??null);return!!(Et?.preserveDirectoryOverride||Et?.pendingWorktreeRequestId||e&&e===nl)},[Et?.bootstrapPendingDirectory,Et?.pendingWorktreeRequestId,Et?.preserveDirectoryOverride,nl]),il=Z.useMemo(()=>{let e=[];return el&&e.push(el),e.push(...tl),!nl||e.some(e=>e.value===nl)||!rl?e:[...e,{value:nl,label:ta(nl)}]},[el,nl,rl,tl]),al=Z.useMemo(()=>p_({selectedDirectory:nl,projectRootOption:el,worktreeOptions:tl}),[el,nl,tl]),ol=Fh()===`mini-chat`,sl=Z.useMemo(()=>ol||ra!==!0||!ia||ia.isClean?!1:wh(ia.files),[ia,ra,ol]),cl=Z.useMemo(()=>!nl||el?.value===nl||tl.some(e=>e.value===nl),[el?.value,nl,tl]);Z.useEffect(()=>{Et?.open&&(!Et.preserveDirectoryOverride&&!Et.bootstrapPendingDirectory||!nl||!cl||(Et.preserveDirectoryOverride&&J.getState().setDraftPreserveDirectoryOverride(!1),Et.bootstrapPendingDirectory&&J.getState().setDraftBootstrapPendingDirectory(null)))},[Et?.bootstrapPendingDirectory,Et?.open,Et?.preserveDirectoryOverride,cl,nl]);let ll=Z.useMemo(()=>qc!==!0||Xc?!1:el?!0:tl.length>0,[Xc,el,qc,tl.length]),ul=Z.useCallback(e=>{if(J.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=Rn.find(t=>t.id===e);t&&(zn!==e&&Bn(e),Ut({projectId:e,directoryOverride:t.path},{force:!0}))},[zn,Rn,Bn,Ut]),dl=Z.useCallback(e=>{J.getState().newSessionDraft?.pendingWorktreeRequestId||Hc&&Ut({projectId:Hc.id,directoryOverride:e},{force:!0})},[Hc,Ut]),fl=Z.useCallback(e=>{let t=e.icon?wa[e.icon]:null,n=e.color?Da[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)(ya,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:ab(e)})]})},[]);Z.useEffect(()=>{!Vc||!Hc||!nl||Et?.pendingWorktreeRequestId||Et?.bootstrapPendingDirectory||Et?.preserveDirectoryOverride||il.some(e=>e.value===nl)||Ut({projectId:Hc.id,directoryOverride:Hc.path})},[il,Et?.bootstrapPendingDirectory,Et?.pendingWorktreeRequestId,Et?.preserveDirectoryOverride,nl,Hc,Ut,Vc]);let pl=Z.useCallback(()=>{Ue(),ye(!0),li.current?.blur()},[Ue]),ml=Z.useCallback(()=>{Ue(),xe(!0),li.current?.blur()},[Ue]);Z.useEffect(()=>{if(!xr||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=()=>Be(ng(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[tg]}),()=>r.disconnect()},[xr]);let hl=Le||!!de||ve||be||oo||co,gl=Z.useRef(!1);gl.current=oo||co;let _l=Z.useRef(!1),vl=Z.useRef(0),yl=Z.useRef(0),xl=K(()=>{let e=J.getState().stagedMessageEdit;!e||e.sessionId!==En||window.setTimeout(()=>{let t=J.getState().stagedMessageEdit,n=document.activeElement,r=Av({surfaceKind:q.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:rs(),focusHeld:Date.now()<yl.current,overlayOpen:vl.current>0||gl.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<He.current});r.action===`disarm`&&J.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!xr||Re()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{vl.current+=1},t=()=>{if(vl.current=Math.max(0,vl.current-1),_l.current){_l.current=!1;return}if(!Ge.current||gl.current||vl.current>0)return;if(Za()){Ge.current=!1;return}Ge.current=!1,yl.current=Date.now()+600,li.current?.focus(),document.activeElement===li.current&&ge(!0);let e=()=>{let e=li.current;!e||document.activeElement!==e||(Sl.current??e).scrollIntoView({block:`end`})};pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null),me.current!==null&&(window.clearTimeout(me.current),me.current=null),pe.current=window.setTimeout(()=>{pe.current=null,e()},300),me.current=window.setTimeout(()=>{me.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null),me.current!==null&&(window.clearTimeout(me.current),me.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[xr]),Z.useEffect(()=>{if(!xr)return;if(hl){(he||Date.now()-We.current<800)&&(Ge.current=!0);return}if(!Ge.current)return;let e=window.setTimeout(()=>{if(Ge.current=!1,Za())return;let e=li.current;e&&document.activeElement!==e&&e.focus({preventScroll:Re()})},180);return()=>window.clearTimeout(e)},[xr,hl,he]),Z.useEffect(()=>{if(!xr||Re()||typeof document>`u`||he||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==li.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[xr,he]),Z.useEffect(()=>{je(``)},[Se]);let Sl=Z.useRef(null),Cl=xr?`px-1.5 py-1.5`:Bc?`px-1.5 py-1`:`px-2.5 py-1.5`,wl=xr?`h-8 w-8`:Bc?`h-5 w-5`:`h-6 w-6`,Tl=xr?`h-4 w-4`:Bc?`h-3.5 w-3.5`:`h-4 w-4`,El=xr?`h-5 w-5`:Bc?`h-4 w-4`:`h-5 w-5`,Dl=xr?`h-[1.125rem] w-[1.125rem]`:Bc?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,Ol=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,Mp),kl=Y(Ol,wl),Al=kl;Z.useEffect(()=>()=>{ao.current&&=(clearTimeout(ao.current),null)},[]);let jl=xr?(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)(lb,{onOpenAgentPanel:ps,onCycleAgent:()=>{Ue(),Us()},agentName:q.selection.value.agent,agents:gr,disabled:yr}),(0,$.jsx)(ub,{onOpenModel:()=>Ro(`model`),providerID:q.selection.value.providerID,modelID:q.selection.value.modelID,provider:_r.find(e=>e.id===q.selection.value.providerID),variant:q.selection.value.variant})]}):null,Ml=(0,$.jsxs)(`div`,{className:`oc-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(Pu,{attachments:wn,onShowPopup:Tr,onRemoveAttachedFile:$s}),q.kind===`primary`?(0,$.jsx)(Ru,{attachedFiles:wn,onAddVSCodeFile:(e,t,n)=>{Nn&&qn(Nn,()=>Lt.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Nn)return qn(Nn,()=>Lt.getState()).addVSCodeSelection(e,t)}}):null]}),Nl=to?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(B_,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),Pl=xr?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,qo&&`oc-mobile-composer-compact-chrome--aborting`,a&&o&&`oc-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)(pb,{isVSCode:Bc,footerIconButtonClass:kl,iconSizeClass:Dl,handlePickLocalFiles:Fc,handlePickLocalImages:Ic,openIssuePicker:ms,openPrPicker:hs,onOpenMobileSheet:pl,onOpenAndroidPickSheet:Nc()?ml:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[a&&o?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(Nh,{placement:`compact`,visible:a,onClick:o})}):null,qo?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(hb,{isMobile:!0,footerIconButtonClass:kl,stopFooterIconButtonClass:Al,sendIconSizeClass:Tl,stopIconSizeClass:El,canSend:Wo,canAbort:!0,hasContent:!1,currentSessionId:En,newSessionDraftOpen:An,draftSubmitting:On,submissionBlocked:l,sendPhase:es,queueFrozen:Uo,queueFallbackAvailable:qo||Ko,onPrimaryAction:ys,onAbort:Hs})}):null]})]}):null,Fl=xr?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`oc-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)(pb,{isVSCode:Bc,footerIconButtonClass:kl,iconSizeClass:Dl,handlePickLocalFiles:Fc,handlePickLocalImages:Ic,openIssuePicker:ms,openPrPicker:hs,onOpenSettings:e,onOpenMobileSheet:pl,onOpenAndroidPickSheet:Nc()?ml:void 0}),er?(0,$.jsx)(mb,{sessionId:En,draftOpen:An,draftEnabled:Et.permissionAutoAcceptEnabled===!0,enabled:Jn,saving:En?zt:!1,footerIconButtonClass:kl,iconSizeClass:Dl,onSetDraftEnabled:It,onSetSessionEnabled:Ht,onOpenSessionFirst:Nt,onToggleFailed:tr}):null,(0,$.jsx)(fv,{sessionId:En,directory:pt??Mn,draftOpen:An}),(0,$.jsx)(pv,{length:Vr.length})]}),jl,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(hb,{isMobile:xr,footerIconButtonClass:kl,stopFooterIconButtonClass:Al,sendIconSizeClass:Tl,stopIconSizeClass:El,canSend:Wo,canAbort:qo,hasContent:!!Vo,currentSessionId:En,newSessionDraftOpen:An,draftSubmitting:On,submissionBlocked:l,sendPhase:es,queueFrozen:Uo,queueFallbackAvailable:qo||Ko,onPrimaryAction:ys,onAbort:Hs})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,zc),children:[(0,$.jsx)(pb,{isVSCode:Bc,footerIconButtonClass:kl,iconSizeClass:Dl,handlePickLocalFiles:Fc,handlePickLocalImages:Ic,openIssuePicker:ms,openPrPicker:hs,onOpenSettings:e,withTooltip:!0}),er?(0,$.jsx)(mb,{sessionId:En,draftOpen:An,draftEnabled:Et.permissionAutoAcceptEnabled===!0,enabled:Jn,saving:En?zt:!1,footerIconButtonClass:kl,iconSizeClass:Dl,onSetDraftEnabled:It,onSetSessionEnabled:Ht,onOpenSessionFirst:Nt,onToggleFailed:tr}):null,(0,$.jsx)(fv,{sessionId:En,directory:pt??Mn,draftOpen:An}),(0,$.jsx)(pv,{length:Vr.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,zc),children:[(0,$.jsx)(sb,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:li,selectionAdapter:or}),(0,$.jsx)(cb,{radius:Ta,isMobile:xr,footerIconButtonClass:kl,footerPaddingClass:Cl,iconSizeClass:Dl,sendIconSizeClass:Tl,onInsert:Cs,onInsertAndSend:Ts,onContentHeightChange:qs,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(hb,{isMobile:xr,footerIconButtonClass:kl,stopFooterIconButtonClass:Al,sendIconSizeClass:Tl,stopIconSizeClass:El,canSend:Wo,canAbort:qo,hasContent:!!Vo,currentSessionId:En,newSessionDraftOpen:An,draftSubmitting:On,submissionBlocked:l,sendPhase:es,queueFrozen:Uo,queueFallbackAvailable:qo||Ko,onPrimaryAction:ys,onAbort:Hs})]})]}),Il=K(()=>{if(xr){yl.current=Date.now()+600;let e=()=>{li.current?.focus({preventScroll:Re()}),document.activeElement===li.current&&ge(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Yp(li))return;let e=Jp(li);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),Ll=pt??Mn,{goal:Rl,enabled:Bl}=ov(En??``,Ll),Vl=(0,$.jsx)(If,{onEditMessage:ds,onSendMessage:fs,onEditCommitted:Il,draftKey:Nn,scope:go,draftTarget:Nn?{key:Nn,expectedRevision:()=>Cn.getDraft(Nn)?.revision??`absent`}:null,clientPendingItems:os,onRemoveClientPending:e=>{let t=Jr.getState().removeEstablishingFollowUp(e);t&&(t.content&&Ur(t.content),t.attachments.length>0&&Cn.restoreAttachments(t.attachments))},trailing:En&&Bl&&Rl?(0,$.jsx)(dv,{sessionId:En,directory:Ll}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:Sl,onSubmit:e=>{e.preventDefault(),ys()},onPointerDownCapture:e=>{if(!xr)return;let t=e.target;t instanceof Element&&(t.closest(`textarea[data-chat-input="true"]`)||t.closest(`[data-chat-prompt-attachments="true"]`)||t.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(Ue(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,ga&&`flex h-full min-h-0 flex-col pt-4`,va&&`flex h-full min-h-0 flex-col pt-1`,xr&&`bottom-safe-area oc-mobile-composer`),style:xr&&Re()&&kr>0&&!he?{marginBottom:`${kr}px`}:void 0,children:[jn&&!ga&&!xr&&!Bc&&!ol?(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:ob(Wc?f(`chat.emptyState.draftTitleWithProject`,{project:Wc}):f(`chat.emptyState.draftTitle`),Wc)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,xa&&`flex flex-1 min-h-0 flex-col`),children:[(0,$.jsx)(Fu,{attachments:wn,onShowPopup:Tr,onRemoveAttachedFile:$s}),(0,$.jsx)(ep,{}),Oo&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[jo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ea?.colors?.surface?.elevated,borderColor:ea?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ea?.colors?.status?.info},children:jo}),(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:No,"aria-label":f(`chat.chatInput.reviewCommentsRemove`),title:f(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,ko>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ea?.colors?.surface?.elevated,borderColor:ea?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ea?.colors?.status?.info},children:ko}),(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(`preview-console`),"aria-label":f(`chat.chatInput.devServerLogsRemove`),title:f(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Ao>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ea?.colors?.surface?.elevated,borderColor:ea?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ea?.colors?.status?.info},children:Ao}),(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(`preview-annotation`),"aria-label":f(`chat.chatInput.previewContextRemove`),title:f(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),uo&&!Bc&&(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:()=>so(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[uo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:uo.author.avatarUrl,alt:uo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,uo.number,uo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:uo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:uo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:uo.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":f(`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:()=>{fo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.removeAria`),title:f(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),po&&!Bc&&(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:()=>lo(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[po.author?.avatarUrl&&(0,$.jsx)(`img`,{src:po.author.avatarUrl,alt:po.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[f(`chat.chatInput.linked.pr.number`,{number:po.number}),po.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:po.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:po.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[po.head,` → `,po.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:po.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":f(`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:()=>{mo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.removeAria`),title:f(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(fb,{sessionId:En,directory:pt??Mn}),(0,$.jsxs)(`div`,{className:xr?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:xr?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsxs)(`div`,{className:xr?`oc-mobile-composer-reveal`:`contents`,children:[(0,$.jsx)(db,{showAbortStatus:sa,showAssistantStatus:!1,showTodos:!0,leftAccessory:An||!sl?null:(0,$.jsx)(jh,{})}),!xr&&Vc?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Hc?(0,$.jsxs)(Ca,{value:Hc.id,open:Fe,onValueChange:ul,onOpenChange:e=>{Ie(e),e||Pe(``)},children:[(0,$.jsx)(Pa,{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]`,Ap),children:[(0,$.jsx)(_a,{children:fl(Hc)}),(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)(Sa,{fitContent:!0,children:[(0,$.jsx)(Fa,{autoFocus:!0,value:Ne,onChange:e=>Pe(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),Rn.filter(e=>Na(ab(e),Ne)||Na(e.path,Ne)).map(e=>(0,$.jsx)(Ma,{value:e.id,className:`max-w-[24rem] truncate`,children:fl(e)},e.id)),(0,$.jsx)(ba,{}),(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(),Ie(!1),requestAnimationFrame(()=>hi.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`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`,Ap),onClick:()=>hi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),Hc&&ll?(0,$.jsx)(b_,{directory:nl,projectDirectory:Uc,label:al,projectRootOption:el,worktreeOptions:tl,onSelectDirectory:dl}):null]}):null,xr&&Vc?(0,$.jsxs)(`div`,{className:`oc-mobile-draft-target-selectors mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Hc?(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`,Ap),onClick:()=>Ce(`project`),children:fl(Hc)}):(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`,Ap),onClick:()=>hi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),Hc&&ll?(0,$.jsx)(b_,{directory:nl,projectDirectory:Uc,label:al,projectRootOption:el,worktreeOptions:tl,onSelectDirectory:dl,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,Vl]}),(0,$.jsx)(`div`,{className:Y(!xr&&`contents`,xr&&`contents`,va&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:xr?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(Qg,{value:Vr,attachments:[],disabled:!En&&!An||On&&!es.establishing,pending:qo||es.inFlight&&!es.establishing,isMobile:xr,onSubmit:ys,"data-mobile-composer-surface":xr?`true`:void 0,"data-session-swipe-surface":xr?`true`:void 0,expanded:xa,focusedTone:h===`shell`?`info`:`primary`,className:Y(`relative z-10`,y&&`ring-2 ring-primary ring-offset-2`,Or&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,xr&&`oc-mobile-composer-surface`),style:{borderRadius:Ta},ref:gi,onDropCapture:Dc,onDragEnter:Sc,onDragOver:Cc,onDragLeave:wc,onDrop:Ec,onDragEnd:Tc,autoResize:!1,disableInputWhilePending:!1,contentClassName:xa?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:Ml,highlightedContent:Nl,highlightRef:ua,inputRef:li,textLayoutClassName:Y(Ry,xa?Y(`h-full min-h-0`,xr?`py-2.5`:`py-4`):xr?`py-2.5`:`pt-4 pb-2`,h===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(xa&&`flex-1 min-h-0`),inputStyle:{flex:xa?`1 1 auto`:`none`,height:!xa&&ce?`${ce.height}px`:void 0,maxHeight:!xa&&ce?`${ce.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":xa?`100%`:ce?`${ce.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!xa&&ce?`${ce.maxHeight}px`:`none`,borderTopLeftRadius:Ta,borderTopRightRadius:Ta},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,Cl,xr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,zc)),footerStyle:{borderBottomLeftRadius:Ta,borderBottomRightRadius:Ta},footerContent:Fl,placeholder:Ea,onChange:(e,t)=>ac(t),textareaProps:{readOnly:Or,onCompositionStart:()=>{ui.current=!0},onCompositionEnd:e=>{ui.current=!1;let t=e.currentTarget;Xs(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:ic,onKeyDown:Is,onCopy:lc,onCut:uc,onPaste:sc,onDragEnter:Sc,onDragOver:Cc,onDropCapture:Dc,onDrop:Ec,onDragEnd:Tc,onKeyUp:zs,onClick:()=>{zs()},onScroll:e=>{zs();let t=e.currentTarget.scrollTop;ua.current&&(ua.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(ui.current){di.current=r;return}let i=L_(n,r,[...ze(Vr,wn.filter(ke).map(e=>e.filename)),...I_(Vr,Ua.keys()),...zr.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),di.current=i.end):di.current=n,zs()},onFocus:()=>{if(xr){if(Date.now()<He.current){let e=li.current;e&&e.blur();return}_e.current!==null&&(window.clearTimeout(_e.current),_e.current=null),ge(!0)}},onBlur:e=>{if(ui.current=!1,di.current=e.currentTarget.selectionStart??di.current,xl(),xr){if(Date.now()<yl.current){let e=li.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<yl.current&&document.activeElement!==e&&e.focus()},50);return}}if(We.current=Date.now(),Re()){ge(!1);return}_e.current!==null&&window.clearTimeout(_e.current),_e.current=window.setTimeout(()=>{_e.current=null,ge(!1)},120)}},autoCorrect:xr?`on`:`off`,autoCapitalize:xr?`sentences`:`off`,spellCheck:xr||Mr,fillContainer:xa,rows:1},children:[(0,$.jsx)(km,{}),y&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ta},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:Ol,onClick:()=>Fc(),title:f(`chat.chatInput.actions.attachFiles`),"aria-label":f(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(Dl,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:f(T?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(vs,{ref:Li,searchQuery:P,directory:Mn,onCommandSelect:_c,onClose:()=>N(!1),commandPolicy:e=>em(q,e),commandContext:Fn,style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0}),R&&(0,$.jsx)(ap,{ref:Ri,searchQuery:V,directory:Mn,onSkillSelect:hc,onClose:()=>z(!1),style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0}),ne&&(0,$.jsx)(Ss,{ref:Bi,searchQuery:oe,onSnippetSelect:gc,onClose:()=>re(!1),style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(ks,{ref:Fi,searchQuery:k,onFileSelect:dc,onAgentSelect:fc,onSessionSelect:pc,onClose:()=>O(!1),style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),xr?(0,$.jsx)(cb,{radius:Ta,isMobile:xr,footerIconButtonClass:kl,footerPaddingClass:Cl,iconSizeClass:Dl,sendIconSizeClass:Tl,onInsert:Cs,onInsertAndSend:Ts,onContentHeightChange:qs,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),xr?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[Pl,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!Vr.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:Vr.trim()?Vr:Oa})]}):null]}),xr?(0,$.jsx)(sb,{className:`hidden`,composerTextareaRef:li,selectionAdapter:or,mobilePanel:de,onMobilePanelChange:fe}):null]}),An&&!ga&&!xr&&!Bc&&!ol?(0,$.jsx)(Gg,{onSubmit:xs,className:`chat-input-column mt-4`}):null]}),p.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(zy,{popup:p,onOpenChange:Dr,isMobile:xr})}):null,(0,$.jsx)(Sg,{open:oo,onOpenChange:so,mode:`select`,onSelect:e=>{fo(e),mo(null)}}),(0,$.jsx)(Tg,{open:co,onOpenChange:lo,onSelect:e=>{mo(e),fo(null)}}),(0,$.jsx)(su,{open:Vn,onOpenChange:Wn,projectDirectory:pt??Mn??null,submitting:Gn,onConfirm:ha}),(0,$.jsx)(`input`,{ref:Oc,type:`file`,multiple:!0,className:`hidden`,onChange:Rc,accept:`*/*`}),(0,$.jsx)(`input`,{ref:kc,type:`file`,multiple:!0,className:`hidden`,onChange:Rc,accept:`image/*`}),null,xr?(0,$.jsx)(Qa,{id:`android-media-pick-sheet`,open:be,onOpenChange:e=>{e||xe(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:f(`chat.chatInput.actions.addAttachment`)}),ariaLabel:f(`chat.chatInput.actions.addAttachment`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Ge.current=!1,xe(!1),requestAnimationFrame(Lc)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Ge.current=!1,xe(!1),requestAnimationFrame(Fc)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,xr&&Vc&&Hc?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(Qa,{id:`mobile-draft-project-picker-sheet-${we}`,open:Se===`project`,onOpenChange:e=>{e||Ce(null)},ariaLabel:f(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`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)(Fa,{value:Oe,onChange:e=>je(e.target.value),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(fa,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:Rn.filter(e=>Na(ab(e),Oe)||Na(e.path,Oe)).map(e=>(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:()=>{ul(e.id),Ce(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:fl(e)}),e.id===Hc.id?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground`}):null]},e.id))})}),(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:()=>{Ce(null),hi.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},xb=e=>{let t=(0,Q.c)(3),n=nm(),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)(bb,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};xb.displayName=`ChatInput`;var Sb=Z.memo(xb);function Cb(e){return e.preventDefault()}function wb(e){e.preventDefault()}function Tb(e){return e.preventDefault()}function Eb(e){e.pointerType===`touch`&&e.preventDefault()}function Db(e){e.preventDefault()}function Ob(e){e.pointerType===`touch`&&e.preventDefault()}function kb(){let e=(0,Q.c)(47),{t}=st(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>mo(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=K(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],jo(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await cc(n),wr.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}wr.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=K(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Re()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,disabled:i,onClick:C,children:[E,O]})})}),e[34]=i,e[35]=C,e[36]=E,e[37]=O,e[38]=k):k=e[38];let A;return e[39]!==d||e[40]!==s||e[41]!==S||e[42]!==k||e[43]!==b||e[44]!==x||e[45]!==_?(A=(0,$.jsx)(`div`,{ref:o,children:(0,$.jsx)(Qa,{id:`image-save-actions-sheet`,open:s,onOpenChange:d,title:b,ariaLabel:_,closeAriaLabel:x,resizeAriaLabel:S,fitContent:!0,children:k})}),e[39]=d,e[40]=s,e[41]=S,e[42]=k,e[43]=b,e[44]=x,e[45]=_,e[46]=A):A=e[46],A}var Ab=(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(At(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]},jb=(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},Mb=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}},Nb=e=>e.syncLoading||e.assistantLoading,Pb=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Fb=e=>e.isLoadingOlder,Ib=e=>!e.isMobile&&e.isLoadingOlder,Lb=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Rb=e=>e.p0Satisfied||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,zb=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}},Bb=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Vb=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Hb=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Ub=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)(Ea,{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},Wb=e=>{let t=(0,Q.c)(42),{t:n}=st(),r=s(Gb),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Hb,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 ${Vb}`,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,c;t[11]!==e.agentName||t[12]!==o?(c=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=c):c=t[13];let l=c,u=e.modelName||o,d;t[14]===n?d=t[15]:(d=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=d);let f=`${d}: ${l}`,p;t[16]===n?p=t[17]:(p=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=p);let m=`${p}: ${u}`,h=r&&Hb,g;t[18]===h?g=t[19]:(g=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] p-3`,h),t[18]=h,t[19]=g);let _=r&&`oc-mobile-readonly-prompt-surface`,v;t[20]===_?v=t[21]:(v=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,_),t[20]=_,t[21]=v);let y;t[22]===n?y=t[23]:(y=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=y);let b;t[24]===y?b=t[25]:(b=(0,$.jsx)(`div`,{className:`text-muted-foreground ${Vb}`,children:y}),t[24]=y,t[25]=b);let x;t[26]!==f||t[27]!==l||t[28]!==m||t[29]!==u||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(x=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)(ea,{name:e.agentName,size:14,label:f}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:l,children:l})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Ub,{providerId:e.providerId,modelId:e.modelId,label:m}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:u,children:u})]})]}):null,t[26]=f,t[27]=l,t[28]=m,t[29]=u,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=x):x=t[34];let S;t[35]!==x||t[36]!==v||t[37]!==b?(S=(0,$.jsxs)(`div`,{className:v,children:[b,x]}),t[35]=x,t[36]=v,t[37]=b,t[38]=S):S=t[38];let C;return t[39]!==S||t[40]!==g?(C=(0,$.jsx)(`aside`,{className:g,children:S}),t[39]=S,t[40]=g,t[41]=C):C=t[41],C};function Gb(e){return e.isMobile}var Kb=Z.memo(()=>{let e=(0,Q.c)(5),{t}=st(),{currentTheme:n}=za(),r=Hi(qb),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(io,{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 qb(e){return e.error}var Jb=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)}}},Yb=`oc:legend-timeline`,Xb=()=>{try{return typeof localStorage>`u`||localStorage.getItem(Yb)!==`0`}catch{return!0}},Zb=fe(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t}),legendTimelineEnabled:Xb(),setLegendTimelineEnabled:t=>{try{typeof localStorage<`u`&&localStorage.setItem(Yb,t?`1`:`0`)}catch{}e({legendTimelineEnabled:t})}})),Qb=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:on(t)},$b=Z.memo(e=>{let t=(0,Q.c)(31),{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?Qb(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)(Ea,{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(${$i(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]!==r||t[23]!==n?(x=!n&&o&&(0,$.jsxs)(`div`,{className:Y(`agent-badge inline-flex items-center gap-1 cursor-default rounded font-normal leading-tight`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,$i(o).class),children:[(0,$.jsx)(ea,{name:o,size:10}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=r,t[23]=n,t[24]=x):x=t[24];let S;t[25]!==b||t[26]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b,x]}),t[25]=b,t[26]=x,t[27]=S):S=t[27];let C;return t[28]!==S||t[29]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m,S]})})}),t[28]=S,t[29]=m,t[30]=C):C=t[30],C}),ex=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,tx=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,nx=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#x27;`),rx=(e,t)=>e.split(tx).map((e,n)=>n%2==1?e:t(e)).join(``),ix=e=>rx(e,e=>e.replace(/ *\n/g,`
6539
- `)),ax=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=rx(e,nx);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${ps(t.name)})`;i=i.replace(t.token,e)}i=i.replace(ex,(e,t,r)=>n.has(r)?`${t}[/${r}](${us(r)})`:e)}return ix(i)},ox=e=>(ex.lastIndex=0,ex.test(e)||e.includes(`[skill:`)),sx=e=>e===`markdown`?`markdown`:`plain`,cx=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)},lx=Z.memo(({part:e,messageId:t,agentMention:n,messageParts:r})=>{let i=e,a=i.text,o=typeof a==`string`?a:i.content||i.value||``,[c,l]=Z.useState(!1),[u,d]=Z.useState(!1),f=s(e=>e.userMessageRenderingMode),p=s(e=>e.collapsibleUserMessages),m=is(),h=ti({directory:m,enabled:ox(o)}),g=Z.useMemo(()=>h.data??[],[h.data]),_=s(e=>e.openContextFile),{t:v}=st(),y=sx(f),b=p&&!c,x=Z.useRef(null),S=Z.useMemo(()=>new Map(g.map(e=>[e.name,e])),[g]),C=Z.useMemo(()=>Jd(r,o),[r,o]),w=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!sn(t))continue;let n=t.text;if(typeof n==`string`)for(let t of Vr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of Ai()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${te}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),T=K(e=>{let t=S.get(e),n=typeof t?.path==`string`?t.path:``,r=yo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=m||go(``,i)||`/`,o=()=>{_(a,i)};if(m&&!So(i,m)){as(i,m).then(o);return}o()});Z.useEffect(()=>{let e=x.current;if(!e)return;let t=()=>{p&&!c&&d(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[p,o,c]),Z.useEffect(()=>{p||(l(!1),d(!1))},[p]);let E=K(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??ss(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),T(n);return}let r=x.current;r&&(cx(r)||p&&!c&&u&&l(!0))}),D=K(e=>{e.stopPropagation(),l(!1)}),O=Z.useMemo(()=>Hd(o,{skillNames:new Set(S.keys()),citationIcons:C.icons,citationDisplayNames:C.displayNames,sessionMentions:w,agentNames:n?.name?new Set([n.name.toLowerCase(),n.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),[n,C,w,S,o]),k=Z.useMemo(()=>ax({textContent:o,agentMention:n,skillNames:new Set(S.keys()),decorateInlineReferences:!O}),[n,O,S,o]),A=(e,t)=>{if(!e)return null;if(y===`markdown`){let n=ax({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(Mo,{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`,b&&[`[&_.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)}return(0,$.jsx)(Z.Fragment,{children:e},t)},j=e=>e.map((e,t)=>e.type===`text`?A(e.text,`text-${t}`):(0,$.jsx)(Xd,{decoration:e.decoration,onOpenSkill:T},`ref-${t}-${e.span.start}`)),M=Z.useMemo(()=>{if(O)return j(O);let e=[],t=0,r=!1,i;for(ex.lastIndex=0;(i=ex.exec(o))!==null;){let n=i[1]||``,r=i[2],a=i.index+n.length;S.has(r)&&(i.index>t&&e.push(o.slice(t,i.index)),n&&e.push(n),e.push((0,$.jsxs)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:e=>{e.stopPropagation(),T(r)},children:[`/`,r]},`skill-${a}-${r}`)),t=a+r.length+1)}t<o.length&&e.push(o.slice(t));let a=e.length>0?e:[o];return!n?.token||!o.includes(n.token)?a:a.flatMap((e,t)=>{if(r||typeof e!=`string`)return e;let i=e.indexOf(n.token);return i===-1?e:(r=!0,[e.slice(0,i),(0,$.jsx)(`a`,{href:os(n.name),className:`text-primary hover:underline`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:n.token},`agent-${t}`),e.slice(i+n.token.length)])})},[n,T,O,j,S,o]);return!o||o.trim().length===0?null:(0,$.jsxs)(`div`,{className:`relative`,children:[p&&c&&(0,$.jsx)(`button`,{type:`button`,onClick:D,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":v(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,c&&`pb-3`,y===`plain`&&`whitespace-pre-wrap`,b&&`line-clamp-10`,p&&u&&!c&&`cursor-pointer`),ref:x,onClick:E,children:y===`markdown`?O?j(O):(0,$.jsx)(Mo,{content:k,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,b&&[`[&_.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}):M})]},e.id||`${t}-user-text`)}),ux=[{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)(vc.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)(vc.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)(vc.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)(vc.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 dx(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=ux.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||ux[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 fx=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===`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===`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===`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`?(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===`plan_enter`?(0,$.jsx)(X,{name:`file-list-2`,className:t}):r===`plan_exit`?(0,$.jsx)(X,{name:`task`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},px=new Map,mx=e=>{let t=px.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return px.set(e,n),n},hx=(e,t)=>{let n=mx(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=px.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),px.delete(e)))}},gx=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(_x),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return hx(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 _x(){return Date.now()}var vx=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],yx=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},bx=e=>{if(!e||typeof e!=`object`)return;let t=e;return yx(t.sessionId)??yx(t.sessionID)},xx=(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},Sx=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},Cx=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:yx(e.sessionId)??yx(e.sessionID),status:yx(e.status),summaryEntries:Sx(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},wx=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=Cx(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 yx((n?.[1]??r?.[1])||vx(e))},Tx=e=>{if(!(!e||typeof e!=`object`))return yx(e.status)},Ex=/"status"\s*:\s*"running"/i,Dx=/\bstatus\s*[:=]\s*["'`]?running\b/i,Ox=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]&&Ex.test(t[1])?!0:Dx.test(e)},kx=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,Ax=(e,t)=>yx(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),jx=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},Mx=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(kx);if(!t)return;let n=Ax(t[1],`sessionID`)??Ax(t[1],`sessionId`),r=jx(Ax(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:Ax(t[1],`description`),body:t[2].trim()}},Nx=new WeakMap,Px=e=>{let t=Nx.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||e===`task`||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 Nx.set(e,n),n},Fx=e=>{let t=[];for(let n of e)t.push(...Px(n));return t},Ix=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),Lx=[`summary`,`changes`,`verification`],Rx={summary:`Summary`,changes:`Changes`,verification:`Verification`},zx=/<(summary|changes|verification)(?:\s[^>]*)?>/i,Bx=()=>RegExp(`<(${Lx.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),Vx=e=>typeof e!=`string`||e.length===0?!1:zx.test(e),Hx=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!Vx(e)?e:e.replace(Bx(),(e,t,n)=>{let r=Rx[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),Ux=e=>Hx(Ix(e)),Wx=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}};function Gx(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 Kx=(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},qx=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},Jx=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},Yx=e=>e?.state,Xx=e=>e?.metadata,Zx=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},Qx=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,``):``},$x=(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||qx(r)!==qx(i))return!1;if(r.type===`tool`){if(Yx(r)!==Yx(i)||Xx(r)!==Xx(i)||Jx(r)!==Jx(i))return!1;let e=Zx(r),t=Zx(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=Zx(r),o=Zx(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(Qx(r)!==Qx(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},eS=(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.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)&&Kx(e.tokens,t.tokens),tS=(e,t)=>eS(e.info,t.info)&&$x(e.parts,t.parts),nS=(e,t)=>!e||!t?e===t:tS(e,t),rS=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,iS=(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},aS=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&$x([e.part],[t.part]),oS=(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(!aS(a,o))return!1;r+=1,i+=1}},sS=(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(!aS(e.parts[n],t.parts[n]))return!1;return!0},cS=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),lS=(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(!sS(a,o))return!1;r+=1,i+=1}},uS=(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.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||!oS(e.activityParts,t.activityParts,n)||!lS(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=cS(e.activityGroupSegments,n)||cS(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!rS(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!iS(e.changedFiles,t.changedFiles))},dS=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,fS=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,pS=/(?=^diff --git\s+)/gm,mS=/^diff --git\s+/m,hS=/(?=^---\s+\S)/gm,gS=/^---\s+\S/m,_S=e=>typeof e==`object`&&!!e,vS=e=>e.replace(/\r\n/g,`
6537
+ `)){oe(t),ne(!0),O(!1);return}}ne(!1);let s=vi({value:e,cursorPosition:t,inputSource:n,insertedText:r});s===null?O(!1):(j(s),O(!0))},[h,I,j,N,O,z,ne,H,oe]),Xs=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(h===`normal`&&!ui.current&&Wa.size>0&&e.includes(`/`)){let r=wv(e,Wa,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=Gr(a,o,s,(e,t)=>{let n=[...e];for(let e of yr(t.text,{agentNames:Aa,includeUnterminatedPastedReferences:r===`paste`}))n=Ms(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=Ui(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=li.current;e&&Xp(u,ui.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),Js()}),Ys(l.text,c.end,r,i),{document:l,selection:c}},[Js,Gr,Ui,h,Aa,Wa,Ys]),Zs=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=li.current;if(!n){let n=Br+e;Xs(n,n.length,n.length,t,e);return}let r=n.selectionStart??Br.length,i=n.selectionEnd??Br.length,a=`${Br.substring(0,r)}${e}${Br.substring(i)}`,o=r+e.length;Xs(a,o,o,t,e)},[Xs,Br]),Qs=q((e,t)=>{let n=new Set(we(Cn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of Cn)n.has(e.filename)&&Sn.removeAttachment(e.id)}),$s=Z.useCallback(e=>{Sn.removeAttachment(e.id)},[Sn]),ec=Z.useCallback(()=>{bi.current=!1,ji.current=[],Ci.current&&=(clearTimeout(Ci.current),null)},[]),tc=Z.useCallback(()=>{Ci.current&&clearTimeout(Ci.current),Ci.current=setTimeout(()=>{ec()},700)},[ec]),nc=Z.useCallback(()=>{Ti.current=!1,Oi.current&&=(clearTimeout(Oi.current),null)},[]),rc=Z.useCallback(()=>{Ti.current=!0,Oi.current&&clearTimeout(Oi.current),Oi.current=setTimeout(()=>{Ti.current=!1,Oi.current=null},700)},[]),ic=Z.useCallback(e=>{!d()||!bi.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),ec())},[ec]),ac=e=>{if(Dr)return;let t=e.nativeEvent;if(d()&&bi.current){let n=ji.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){ec();return}}let n=e.target.value;Qs(Vi.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Yy(Vi.current,n):``,a=i.includes(`@`)||Ti.current;Ti.current&&nc();let o=a?`paste`:`manual`;if(h===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);g(`shell`),Hr(e),Js(),N(!1),z(!1),O(!1),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=t,li.current.selectionEnd=t)});return}Xs(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{ec(),nc()},[ec,nc]);let oc=Z.useCallback(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=li.current,i=r?.selectionStart??Br.length,a=r?.selectionEnd??Br.length,o=Ds(n,Br.slice(0,i),Br.slice(a)),s=`${Br.slice(0,i)}${o}${Br.slice(a)}`;Qs(Br,s),Wi(s,t)},[Br,Wi,Qs]),sc=Z.useCallback(async e=>{let t=rb(e.clipboardData);if(t.length>0&&(Tn||kn)){e.preventDefault(),oc(t);return}if(h===`normal`&&(Tn||kn)){let t=li.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=Br.slice(n,r);if(Ky.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${Br.slice(0,n)}[${i}](${t})${Br.slice(r)}`,o=n+1+i.length+2+t.length+1;oi(a),requestAnimationFrame(()=>{let e=li.current;e&&(e.selectionStart=o,e.selectionEnd=o),Js()}),Ys(a,o,Xy(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(h===`normal`&&fy(Ui(),a)){e.preventDefault();let t=Ui().text,n=li.current,r=n?.selectionStart??Br.length,i=n?.selectionEnd??Br.length,o=py(a,Br,Ui().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})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),dy(Ui())),s=Kr(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=Ls(s.document.text,s.caret);li.current&&(li.current.value=s.document.text),requestAnimationFrame(()=>{li.current?.setSelectionRange(c,c),Js()}),Ys(s.document.text,c),Qs(t,s.document.text);return}a.includes(`@`)&&rc();return}if(!Tn&&!kn){a.includes(`@`)&&rc();return}e.preventDefault();let o=je(i,[...Cn.map(e=>e.filename),...Hi.current]),s=Be(o),c=Ui().text,l=li.current,u=l?.selectionStart??Br.length,d=l?.selectionEnd??Br.length,p=h===`normal`&&fy(Ui(),a)?py(a,Br,Ui().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})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),dy(Ui())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=Ds(m,Br.slice(0,u),Br.slice(d));if(p){let e=Kr(u,d,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=Ls(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;Xs(n,t+s.length,t+s.length,Xy(n),s),Qs(c,n)}else Zs(g,Xy(g)),Qs(c,`${Br.slice(0,u)}${g}${Br.slice(d)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Jy(i[e],t);Hi.current.add(t);try{await Sn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.clipboardAttachFailed`))}finally{Hi.current.delete(t)}}},[Sn,oc,Cn,Js,Tn,Ui,h,Kr,rc,Br,kn,Zs,f,Ys,Xs,oi,Qs]),cc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=L_(r,i,[...Re(Br,Cn.filter(Oe).map(e=>e.filename)),...I_(Br,Ua.keys()),...Ui().references]),o=a?.start??r,s=a?.end??i,c=Br.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${Br.slice(0,o)}${Br.slice(s)}`;Xs(e,o,o),requestAnimationFrame(()=>{li.current?.setSelectionRange(o,o),Js()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{li.current?.setSelectionRange(o,s)})},[Js,Cn,Ua,Xs,Ui,Br]),lc=Z.useCallback(e=>{cc(e,`copy`)},[cc]),uc=Z.useCallback(e=>{cc(e,`cut`)},[cc]),dc=e=>{let t=li.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??di.current:di.current,Br.length),r=Br.substring(0,n).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():xc(e.path)||e.name,a=e.isDirectory?[i]:[],o=Fs(Br,r===-1?n:r,n,`@${i}`);Wi(o.text,[i],a),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=o.caret,li.current.selectionEnd=o.caret),Js(),Ys(o.text,o.caret)}),O(!1),j(``),li.current?.focus()},fc=e=>{let t=li.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??di.current:di.current,Br.length),r=Br.substring(0,n).lastIndexOf(`@`),i=Fs(Br,r===-1?n:r,n,`@${e}`);oi(i.text,t=>Ms(t,{kind:`agent`,value:e,path:e,label:e,range:{start:i.start,end:i.end}})),requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=i.caret,li.current.selectionEnd=i.caret),Js(),Ys(i.text,i.caret)}),O(!1),j(``),li.current?.focus()},pc=q(e=>{Ii.current||(Ii.current=!0,(async()=>{try{let t=Qr.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){Cr.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await ut(e.id,{directory:t}),!ii(e.id,t)){Cr.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}si([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=Ui(),r=li.current?.selectionStart??n.text.length,i=n.text.substring(0,r).lastIndexOf(`@`),a=Ai().get(e.id)?.title||e.title||e.id,o=i===-1?r:i,s={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:a})},c=Kr(o,r,s,{inlineBoundaries:!0,padDocumentEdges:!0}),l=Ls(c.document.text,c.caret);requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=l,li.current.selectionEnd=l),Js(),Ys(c.document.text,l)}),O(!1),j(``),li.current?.focus()}catch{Cr.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Ii.current=!1}})())}),mc=q(e=>{let t=Ui(),n=li.current?.selectionStart??t.text.length,r=_s(t.text,n);if(!r)return!1;let i=Kr(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=Ls(i.document.text,i.caret);return requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=o,li.current.selectionEnd=o),Js(),Ys(i.document.text,o),a&&(N(!1),z(!1))}),li.current?.focus(),a}),hc=e=>{mc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&H(``)},gc=(e,t)=>{let n=li.current?.selectionStart??Br.length,r=Br.substring(0,n).lastIndexOf(`#`),i=r===-1?n:r,a=`${Br.substring(0,i)}#${t} ${Br.substring(n)}`;oi(a);let o=i+t.length+2;requestAnimationFrame(()=>{li.current&&(li.current.selectionStart=o,li.current.selectionEnd=o),Js(),Ys(a,o)}),ne(!1),oe(``),li.current?.focus()},_c=(e,t=!1)=>{if(!em(J,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){mc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&I(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&mc({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){I(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=wv(r,new Set([...Wa,e.name.toLowerCase()]),r.length);Hr(i?.text??r);let a=li.current;if(a&&(a._commandMetadata=e),N(!1),I(``),t){gs({presetText:n});return}let o=()=>{if(li.current){try{li.current.focus({preventScroll:!0})}catch{li.current.focus()}li.current.setSelectionRange(li.current.value.length,li.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Tn&&li.current&&!br&&li.current.focus()},[Tn,br]),Z.useEffect(()=>{br||de(null)},[br]);let vc=Sn.abortPrompt.sessionID,yc=Sn.abortPrompt.clear;Z.useEffect(()=>{vc&&vc!==Tn&&yc()},[Tn,vc,yc]),Z.useEffect(()=>{Mi.current=!!(Tn||kn)},[Tn,kn]);let bc=Z.useCallback(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-openchamber-file-path`)||t.some(e=>e.includes(`vnd.code.tree`)))return!0}return rv(e).length>0},[]),Q=Z.useCallback(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)},[]),xc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(na||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[na]),Sc=e=>{if(!bc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),yi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==T&&E(t),(Tn||kn)&&!y&&w(!0)},Cc=e=>{bc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Tn||kn)&&!y&&w(!0))},wc=e=>{e.preventDefault(),e.stopPropagation(),yi.current--,yi.current<=0&&(yi.current=0,w(!1),E(!1),ec())},Tc=()=>{yi.current=0,w(!1),E(!1),ec()},Ec=async e=>{if(yi.current=0,!bc(e.dataTransfer)){ec();return}if(e.preventDefault(),e.stopPropagation(),w(!1),!Tn&&!kn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=li.current,r=Vi.current;if(n){let t=n.selectionStart??di.current,i=n.selectionEnd??t,a=Fs(r,t,i,e);oi(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,di.current=a.caret,n.focus()})}else{let t=Fs(r,r.length,r.length,e);oi(t.text)}ec();return}let n=rb(e.dataTransfer);if(n.length>0){d()&&(ji.current=n),oc(n),d()||ec();return}let r=Q(e.dataTransfer);if(r.length>0){let e=Be(r.map(e=>e.name)),t=Ds(e,Vi.current.slice(0,li.current?.selectionStart??Vi.current.length),Vi.current.slice(li.current?.selectionEnd??Vi.current.length));Zs(t);for(let e of r)try{await Sn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}}ec()},Dc=e=>{bc(e.dataTransfer)&&(e.preventDefault(),d()&&(bi.current=!0,tc()))},Oc=Z.useRef(null),kc=Z.useRef(null),Ac=q((e=!0)=>{Ve.current=0;let t=()=>{let t=Jp(li);if(!t||(Yp(li),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),jc=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Be(t.map(e=>e.name)),n=Ds(e,Vi.current.slice(0,li.current?.selectionStart??Vi.current.length),Vi.current.slice(li.current?.selectionEnd??Vi.current.length));Zs(n)}for(let e of t)try{await Sn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}},[Sn,Zs,f]),Mc=Z.useCallback(async()=>{try{let e=await Ji?.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(`
6538
+ `);Cr.error(f(`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&&(Ac(!1),await jc(r),Ac())}catch(e){console.error(`VS Code file pick failed`,e),Cr.error(e instanceof Error?e.message:f(`chat.chatInput.toast.vscodePickFailed`))}},[jc,Ac,f,Ji]),Fc=Z.useCallback(()=>{if(d()){Mc();return}Oc.current?.click()},[Mc]),Ic=Z.useCallback(()=>{if(d()){Mc();return}kc.current?.click()},[Mc]),Lc=Z.useCallback(async()=>{if(!Nc()){Ic();return}try{let e=await Pc(20);if(e===null){Ic();return}e.length>0&&(Ac(!1),await jc(e),Ac())}catch(e){console.error(`Native photo pick failed`,e),Cr.error(f(`chat.chatInput.toast.attachFileFailed`))}},[jc,Ac,Ic,f]),Rc=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(Ac(!1),await jc(t),e.target.value=``,Ac())},[jc,Ac]),zc=`gap-x-1.5 gap-y-0`,Bc=d(),Vc=J.kind===`primary`&&An&&!Bc,Hc=Z.useMemo(()=>(Tt?.selectedProjectId?Ln.find(e=>e.id===Tt.selectedProjectId)??null:null)||(Rn?Ln.find(e=>e.id===Rn)??null:null)||(Ln[0]??null),[Rn,Tt?.selectedProjectId,Ln]),Uc=Z.useMemo(()=>ib(Hc?.path??null),[Hc?.path]),Wc=Hc?ab(Hc):null,Gc=Ps(Uc),Kc=ws(e=>Uc?e.directories.get(Uc)?.lastBranchesFetch??0:0),qc=Bs(Uc),Jc=!!Gc?.all,Yc=ws(e=>e.fetchBranches),[Xc,Zc]=Z.useState(!1);Z.useEffect(()=>{!Vc||!Uc||!qi||qc!==null||oa(Uc,qi,{silent:!0})},[oa,qi,qc,Uc,Vc]),Z.useEffect(()=>{if(!Vc||!Uc||!Hc||!qi||qc!==!0){Zc(!1);return}let e=!Kc||Date.now()-Kc>3e4;if(Jc&&!e){Zc(!1);return}let t=!1;return Zc(!Jc),Yc(Uc,qi).finally(()=>{t||Zc(!1)}),()=>{t=!0}},[Yc,qi,Hc,Kc,Jc,qc,Uc,Vc]);let Qc=Es(Uc),$c=Gc?.current?.trim()||Qc?.trim()||``,el=Z.useMemo(()=>{if(!Hc)return null;let e=ib(Hc.path);return!e||!$c?null:{value:e,label:$c}},[Hc,$c]),tl=Z.useMemo(()=>{if(!Hc)return[];let e=Uc?Ut.get(Uc)??Ut.get(Hc.path)??[]:[];return Fr({projectRoot:ib(Hc.path)??``,rootBranch:$c,worktrees:e,pendingBootstrapDirectory:Tt?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[Ut,Tt?.bootstrapPendingDirectory,Hc,$c,Uc]),nl=Z.useMemo(()=>ib(Tt?.bootstrapPendingDirectory??null)??ib(Tt?.directoryOverride??null)??Uc,[Tt?.bootstrapPendingDirectory,Tt?.directoryOverride,Uc]),rl=Z.useMemo(()=>{let e=ib(Tt?.bootstrapPendingDirectory??null);return!!(Tt?.preserveDirectoryOverride||Tt?.pendingWorktreeRequestId||e&&e===nl)},[Tt?.bootstrapPendingDirectory,Tt?.pendingWorktreeRequestId,Tt?.preserveDirectoryOverride,nl]),il=Z.useMemo(()=>{let e=[];return el&&e.push(el),e.push(...tl),!nl||e.some(e=>e.value===nl)||!rl?e:[...e,{value:nl,label:ta(nl)}]},[el,nl,rl,tl]),al=Z.useMemo(()=>p_({selectedDirectory:nl,projectRootOption:el,worktreeOptions:tl}),[el,nl,tl]),ol=Fh()===`mini-chat`,sl=Z.useMemo(()=>ol||ra!==!0||!ia||ia.isClean?!1:wh(ia.files),[ia,ra,ol]),cl=Z.useMemo(()=>!nl||el?.value===nl||tl.some(e=>e.value===nl),[el?.value,nl,tl]);Z.useEffect(()=>{Tt?.open&&(!Tt.preserveDirectoryOverride&&!Tt.bootstrapPendingDirectory||!nl||!cl||(Tt.preserveDirectoryOverride&&Qr.getState().setDraftPreserveDirectoryOverride(!1),Tt.bootstrapPendingDirectory&&Qr.getState().setDraftBootstrapPendingDirectory(null)))},[Tt?.bootstrapPendingDirectory,Tt?.open,Tt?.preserveDirectoryOverride,cl,nl]);let ll=Z.useMemo(()=>qc!==!0||Xc?!1:el?!0:tl.length>0,[Xc,el,qc,tl.length]),ul=Z.useCallback(e=>{if(Qr.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=Ln.find(t=>t.id===e);t&&(Rn!==e&&zn(e),Ht({projectId:e,directoryOverride:t.path},{force:!0}))},[Rn,Ln,zn,Ht]),dl=Z.useCallback(e=>{Qr.getState().newSessionDraft?.pendingWorktreeRequestId||Hc&&Ht({projectId:Hc.id,directoryOverride:e},{force:!0})},[Hc,Ht]),fl=Z.useCallback(e=>{let t=e.icon?wa[e.icon]:null,n=e.color?Da[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)(ya,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:ab(e)})]})},[]);Z.useEffect(()=>{!Vc||!Hc||!nl||Tt?.pendingWorktreeRequestId||Tt?.bootstrapPendingDirectory||Tt?.preserveDirectoryOverride||il.some(e=>e.value===nl)||Ht({projectId:Hc.id,directoryOverride:Hc.path})},[il,Tt?.bootstrapPendingDirectory,Tt?.pendingWorktreeRequestId,Tt?.preserveDirectoryOverride,nl,Hc,Ht,Vc]);let pl=Z.useCallback(()=>{He(),ve(!0),li.current?.blur()},[He]),ml=Z.useCallback(()=>{He(),be(!0),li.current?.blur()},[He]);Z.useEffect(()=>{if(!br||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=()=>ze(ng(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[tg]}),()=>r.disconnect()},[br]);let hl=Ie||!!ue||_e||ye||oo||co,gl=Z.useRef(!1);gl.current=oo||co;let _l=Z.useRef(!1),vl=Z.useRef(0),yl=Z.useRef(0),xl=q(()=>{let e=Qr.getState().stagedMessageEdit;!e||e.sessionId!==Tn||window.setTimeout(()=>{let t=Qr.getState().stagedMessageEdit,n=document.activeElement,r=Av({surfaceKind:J.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:rs(),focusHeld:Date.now()<yl.current,overlayOpen:vl.current>0||gl.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<Ve.current});r.action===`disarm`&&Qr.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!br||Le()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{vl.current+=1},t=()=>{if(vl.current=Math.max(0,vl.current-1),_l.current){_l.current=!1;return}if(!We.current||gl.current||vl.current>0)return;if(Za()){We.current=!1;return}We.current=!1,yl.current=Date.now()+600,li.current?.focus(),document.activeElement===li.current&&he(!0);let e=()=>{let e=li.current;!e||document.activeElement!==e||(Sl.current??e).scrollIntoView({block:`end`})};fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null),pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null),fe.current=window.setTimeout(()=>{fe.current=null,e()},300),pe.current=window.setTimeout(()=>{pe.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null),pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[br]),Z.useEffect(()=>{if(!br)return;if(hl){(me||Date.now()-Ue.current<800)&&(We.current=!0);return}if(!We.current)return;let e=window.setTimeout(()=>{if(We.current=!1,Za())return;let e=li.current;e&&document.activeElement!==e&&e.focus({preventScroll:Le()})},180);return()=>window.clearTimeout(e)},[br,hl,me]),Z.useEffect(()=>{if(!br||Le()||typeof document>`u`||me||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==li.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[br,me]),Z.useEffect(()=>{Ae(``)},[xe]);let Sl=Z.useRef(null),Cl=br?`px-1.5 py-1.5`:Bc?`px-1.5 py-1`:`px-2.5 py-1.5`,wl=br?`h-8 w-8`:Bc?`h-5 w-5`:`h-6 w-6`,Tl=br?`h-4 w-4`:Bc?`h-3.5 w-3.5`:`h-4 w-4`,El=br?`h-5 w-5`:Bc?`h-4 w-4`:`h-5 w-5`,Dl=br?`h-[1.125rem] w-[1.125rem]`:Bc?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,Ol=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,Mp),kl=Y(Ol,wl),Al=kl;Z.useEffect(()=>()=>{ao.current&&=(clearTimeout(ao.current),null)},[]);let jl=br?(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)(lb,{onOpenAgentPanel:ps,onCycleAgent:()=>{He(),Us()},agentName:J.selection.value.agent,agents:hr,disabled:vr}),(0,$.jsx)(ub,{onOpenModel:()=>Ro(`model`),providerID:J.selection.value.providerID,modelID:J.selection.value.modelID,provider:gr.find(e=>e.id===J.selection.value.providerID),variant:J.selection.value.variant})]}):null,Ml=(0,$.jsxs)(`div`,{className:`oc-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(Pu,{attachments:Cn,onShowPopup:wr,onRemoveAttachedFile:$s}),J.kind===`primary`?(0,$.jsx)(Ru,{attachedFiles:Cn,onAddVSCodeFile:(e,t,n)=>{Mn&&Kn(Mn,()=>It.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Mn)return Kn(Mn,()=>It.getState()).addVSCodeSelection(e,t)}}):null]}),Nl=to?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(B_,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),Pl=br?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,qo&&`oc-mobile-composer-compact-chrome--aborting`,a&&o&&`oc-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)(pb,{isVSCode:Bc,footerIconButtonClass:kl,iconSizeClass:Dl,handlePickLocalFiles:Fc,handlePickLocalImages:Ic,openIssuePicker:ms,openPrPicker:hs,onOpenMobileSheet:pl,onOpenAndroidPickSheet:Nc()?ml:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[a&&o?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(Nh,{placement:`compact`,visible:a,onClick:o})}):null,qo?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(hb,{isMobile:!0,footerIconButtonClass:kl,stopFooterIconButtonClass:Al,sendIconSizeClass:Tl,stopIconSizeClass:El,canSend:Wo,canAbort:!0,hasContent:!1,currentSessionId:Tn,newSessionDraftOpen:kn,draftSubmitting:Dn,submissionBlocked:l,sendPhase:es,queueFrozen:Uo,queueFallbackAvailable:qo||Ko,onPrimaryAction:ys,onAbort:Hs})}):null]})]}):null,Fl=br?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`oc-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)(pb,{isVSCode:Bc,footerIconButtonClass:kl,iconSizeClass:Dl,handlePickLocalFiles:Fc,handlePickLocalImages:Ic,openIssuePicker:ms,openPrPicker:hs,onOpenSettings:e,onOpenMobileSheet:pl,onOpenAndroidPickSheet:Nc()?ml:void 0}),$n?(0,$.jsx)(mb,{sessionId:Tn,draftOpen:kn,draftEnabled:Tt.permissionAutoAcceptEnabled===!0,enabled:qn,saving:Tn?Rt:!1,footerIconButtonClass:kl,iconSizeClass:Dl,onSetDraftEnabled:Ft,onSetSessionEnabled:Vt,onOpenSessionFirst:Mt,onToggleFailed:er}):null,(0,$.jsx)(fv,{sessionId:Tn,directory:ft??jn,draftOpen:kn}),(0,$.jsx)(pv,{length:Br.length})]}),jl,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(hb,{isMobile:br,footerIconButtonClass:kl,stopFooterIconButtonClass:Al,sendIconSizeClass:Tl,stopIconSizeClass:El,canSend:Wo,canAbort:qo,hasContent:!!Vo,currentSessionId:Tn,newSessionDraftOpen:kn,draftSubmitting:Dn,submissionBlocked:l,sendPhase:es,queueFrozen:Uo,queueFallbackAvailable:qo||Ko,onPrimaryAction:ys,onAbort:Hs})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,zc),children:[(0,$.jsx)(pb,{isVSCode:Bc,footerIconButtonClass:kl,iconSizeClass:Dl,handlePickLocalFiles:Fc,handlePickLocalImages:Ic,openIssuePicker:ms,openPrPicker:hs,onOpenSettings:e,withTooltip:!0}),$n?(0,$.jsx)(mb,{sessionId:Tn,draftOpen:kn,draftEnabled:Tt.permissionAutoAcceptEnabled===!0,enabled:qn,saving:Tn?Rt:!1,footerIconButtonClass:kl,iconSizeClass:Dl,onSetDraftEnabled:Ft,onSetSessionEnabled:Vt,onOpenSessionFirst:Mt,onToggleFailed:er}):null,(0,$.jsx)(fv,{sessionId:Tn,directory:ft??jn,draftOpen:kn}),(0,$.jsx)(pv,{length:Br.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,zc),children:[(0,$.jsx)(sb,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:li,selectionAdapter:ar}),(0,$.jsx)(cb,{radius:Ta,isMobile:br,footerIconButtonClass:kl,footerPaddingClass:Cl,iconSizeClass:Dl,sendIconSizeClass:Tl,onInsert:Cs,onInsertAndSend:Ts,onContentHeightChange:qs,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(hb,{isMobile:br,footerIconButtonClass:kl,stopFooterIconButtonClass:Al,sendIconSizeClass:Tl,stopIconSizeClass:El,canSend:Wo,canAbort:qo,hasContent:!!Vo,currentSessionId:Tn,newSessionDraftOpen:kn,draftSubmitting:Dn,submissionBlocked:l,sendPhase:es,queueFrozen:Uo,queueFallbackAvailable:qo||Ko,onPrimaryAction:ys,onAbort:Hs})]})]}),Il=q(()=>{if(br){yl.current=Date.now()+600;let e=()=>{li.current?.focus({preventScroll:Le()}),document.activeElement===li.current&&he(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Yp(li))return;let e=Jp(li);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),Ll=ft??jn,{goal:Rl,enabled:Bl}=ov(Tn??``,Ll),Vl=(0,$.jsx)(If,{onEditMessage:ds,onSendMessage:fs,onEditCommitted:Il,draftKey:Mn,scope:go,draftTarget:Mn?{key:Mn,expectedRevision:()=>Sn.getDraft(Mn)?.revision??`absent`}:null,clientPendingItems:os,onRemoveClientPending:e=>{let t=qr.getState().removeEstablishingFollowUp(e);t&&(t.content&&Hr(t.content),t.attachments.length>0&&Sn.restoreAttachments(t.attachments))},trailing:Tn&&Bl&&Rl?(0,$.jsx)(dv,{sessionId:Tn,directory:Ll}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:Sl,onSubmit:e=>{e.preventDefault(),ys()},onPointerDownCapture:e=>{if(!br)return;let t=e.target;t instanceof Element&&(t.closest(`textarea[data-chat-input="true"]`)||t.closest(`[data-chat-prompt-attachments="true"]`)||t.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(He(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,ga&&`flex h-full min-h-0 flex-col pt-4`,va&&`flex h-full min-h-0 flex-col pt-1`,br&&`bottom-safe-area oc-mobile-composer`),style:br&&Le()&&Or>0&&!me?{marginBottom:`${Or}px`}:void 0,children:[An&&!ga&&!br&&!Bc&&!ol?(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:ob(Wc?f(`chat.emptyState.draftTitleWithProject`,{project:Wc}):f(`chat.emptyState.draftTitle`),Wc)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,xa&&`flex flex-1 min-h-0 flex-col`),children:[(0,$.jsx)(Fu,{attachments:Cn,onShowPopup:wr,onRemoveAttachedFile:$s}),(0,$.jsx)(ep,{}),Oo&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[jo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ea?.colors?.surface?.elevated,borderColor:ea?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ea?.colors?.status?.info},children:jo}),(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:No,"aria-label":f(`chat.chatInput.reviewCommentsRemove`),title:f(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,ko>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ea?.colors?.surface?.elevated,borderColor:ea?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ea?.colors?.status?.info},children:ko}),(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(`preview-console`),"aria-label":f(`chat.chatInput.devServerLogsRemove`),title:f(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Ao>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ea?.colors?.surface?.elevated,borderColor:ea?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ea?.colors?.status?.info},children:Ao}),(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(`preview-annotation`),"aria-label":f(`chat.chatInput.previewContextRemove`),title:f(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),uo&&!Bc&&(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:()=>so(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[uo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:uo.author.avatarUrl,alt:uo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,uo.number,uo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:uo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:uo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:uo.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":f(`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:()=>{fo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.removeAria`),title:f(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),po&&!Bc&&(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:()=>lo(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[po.author?.avatarUrl&&(0,$.jsx)(`img`,{src:po.author.avatarUrl,alt:po.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[f(`chat.chatInput.linked.pr.number`,{number:po.number}),po.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:po.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:po.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[po.head,` → `,po.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:po.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":f(`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:()=>{mo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.removeAria`),title:f(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(fb,{sessionId:Tn,directory:ft??jn}),(0,$.jsxs)(`div`,{className:br?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:br?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsxs)(`div`,{className:br?`oc-mobile-composer-reveal`:`contents`,children:[(0,$.jsx)(db,{showAbortStatus:sa,showAssistantStatus:!1,showTodos:!0,leftAccessory:kn||!sl?null:(0,$.jsx)(jh,{})}),!br&&Vc?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Hc?(0,$.jsxs)(Ca,{value:Hc.id,open:Pe,onValueChange:ul,onOpenChange:e=>{Fe(e),e||Ne(``)},children:[(0,$.jsx)(Pa,{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]`,Ap),children:[(0,$.jsx)(_a,{children:fl(Hc)}),(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)(Sa,{fitContent:!0,children:[(0,$.jsx)(Fa,{autoFocus:!0,value:Me,onChange:e=>Ne(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),Ln.filter(e=>Na(ab(e),Me)||Na(e.path,Me)).map(e=>(0,$.jsx)(Ma,{value:e.id,className:`max-w-[24rem] truncate`,children:fl(e)},e.id)),(0,$.jsx)(ba,{}),(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(),Fe(!1),requestAnimationFrame(()=>hi.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`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`,Ap),onClick:()=>hi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),Hc&&ll?(0,$.jsx)(b_,{directory:nl,projectDirectory:Uc,label:al,projectRootOption:el,worktreeOptions:tl,onSelectDirectory:dl}):null]}):null,br&&Vc?(0,$.jsxs)(`div`,{className:`oc-mobile-draft-target-selectors mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Hc?(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`,Ap),onClick:()=>Se(`project`),children:fl(Hc)}):(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`,Ap),onClick:()=>hi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),Hc&&ll?(0,$.jsx)(b_,{directory:nl,projectDirectory:Uc,label:al,projectRootOption:el,worktreeOptions:tl,onSelectDirectory:dl,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,Vl]}),(0,$.jsx)(`div`,{className:Y(!br&&`contents`,br&&`contents`,va&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:br?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(Qg,{value:Br,attachments:[],disabled:!Tn&&!kn||Dn&&!es.establishing,pending:qo||es.inFlight&&!es.establishing,isMobile:br,onSubmit:ys,"data-mobile-composer-surface":br?`true`:void 0,"data-session-swipe-surface":br?`true`:void 0,expanded:xa,focusedTone:h===`shell`?`info`:`primary`,className:Y(`relative z-10`,y&&`ring-2 ring-primary ring-offset-2`,Dr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,br&&`oc-mobile-composer-surface`),style:{borderRadius:Ta},ref:gi,onDropCapture:Dc,onDragEnter:Sc,onDragOver:Cc,onDragLeave:wc,onDrop:Ec,onDragEnd:Tc,autoResize:!1,disableInputWhilePending:!1,contentClassName:xa?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:Ml,highlightedContent:Nl,highlightRef:ua,inputRef:li,textLayoutClassName:Y(Ry,xa?Y(`h-full min-h-0`,br?`py-2.5`:`py-4`):br?`py-2.5`:`pt-4 pb-2`,h===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(xa&&`flex-1 min-h-0`),inputStyle:{flex:xa?`1 1 auto`:`none`,height:!xa&&se?`${se.height}px`:void 0,maxHeight:!xa&&se?`${se.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":xa?`100%`:se?`${se.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!xa&&se?`${se.maxHeight}px`:`none`,borderTopLeftRadius:Ta,borderTopRightRadius:Ta},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,Cl,br?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,zc)),footerStyle:{borderBottomLeftRadius:Ta,borderBottomRightRadius:Ta},footerContent:Fl,placeholder:Ea,onChange:(e,t)=>ac(t),textareaProps:{readOnly:Dr,onCompositionStart:()=>{ui.current=!0},onCompositionEnd:e=>{ui.current=!1;let t=e.currentTarget;Xs(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:ic,onKeyDown:Is,onCopy:lc,onCut:uc,onPaste:sc,onDragEnter:Sc,onDragOver:Cc,onDropCapture:Dc,onDrop:Ec,onDragEnd:Tc,onKeyUp:zs,onClick:()=>{zs()},onScroll:e=>{zs();let t=e.currentTarget.scrollTop;ua.current&&(ua.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(ui.current){di.current=r;return}let i=L_(n,r,[...Re(Br,Cn.filter(Oe).map(e=>e.filename)),...I_(Br,Ua.keys()),...Rr.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),di.current=i.end):di.current=n,zs()},onFocus:()=>{if(br){if(Date.now()<Ve.current){let e=li.current;e&&e.blur();return}ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),he(!0)}},onBlur:e=>{if(ui.current=!1,di.current=e.currentTarget.selectionStart??di.current,xl(),br){if(Date.now()<yl.current){let e=li.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<yl.current&&document.activeElement!==e&&e.focus()},50);return}}if(Ue.current=Date.now(),Le()){he(!1);return}ge.current!==null&&window.clearTimeout(ge.current),ge.current=window.setTimeout(()=>{ge.current=null,he(!1)},120)}},autoCorrect:br?`on`:`off`,autoCapitalize:br?`sentences`:`off`,spellCheck:br||jr,fillContainer:xa,rows:1},children:[(0,$.jsx)(km,{}),y&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ta},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:Ol,onClick:()=>Fc(),title:f(`chat.chatInput.actions.attachFiles`),"aria-label":f(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(Dl,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:f(T?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(vs,{ref:Li,searchQuery:P,directory:jn,onCommandSelect:_c,onClose:()=>N(!1),commandPolicy:e=>em(J,e),commandContext:Pn,style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0}),R&&(0,$.jsx)(ap,{ref:Ri,searchQuery:V,directory:jn,onSkillSelect:hc,onClose:()=>z(!1),style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0}),te&&(0,$.jsx)(Ss,{ref:Bi,searchQuery:ae,onSnippetSelect:gc,onClose:()=>ne(!1),style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(ks,{ref:Fi,searchQuery:k,onFileSelect:dc,onAgentSelect:fc,onSessionSelect:pc,onClose:()=>O(!1),style:ga&&ro?{left:`${ro.left}px`,top:`${ro.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${ro.left+8}px))`,maxHeight:`${ro.maxHeight}px`,transform:ro.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),br?(0,$.jsx)(cb,{radius:Ta,isMobile:br,footerIconButtonClass:kl,footerPaddingClass:Cl,iconSizeClass:Dl,sendIconSizeClass:Tl,onInsert:Cs,onInsertAndSend:Ts,onContentHeightChange:qs,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),br?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[Pl,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!Br.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:Br.trim()?Br:Oa})]}):null]}),br?(0,$.jsx)(sb,{className:`hidden`,composerTextareaRef:li,selectionAdapter:ar,mobilePanel:ue,onMobilePanelChange:de}):null]}),kn&&!ga&&!br&&!Bc&&!ol?(0,$.jsx)(Gg,{onSubmit:xs,className:`chat-input-column mt-4`}):null]}),p.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(zy,{popup:p,onOpenChange:Er,isMobile:br})}):null,(0,$.jsx)(Sg,{open:oo,onOpenChange:so,mode:`select`,onSelect:e=>{fo(e),mo(null)}}),(0,$.jsx)(Tg,{open:co,onOpenChange:lo,onSelect:e=>{mo(e),fo(null)}}),(0,$.jsx)(su,{open:Bn,onOpenChange:Un,projectDirectory:ft??jn??null,submitting:Wn,onConfirm:ha}),(0,$.jsx)(`input`,{ref:Oc,type:`file`,multiple:!0,className:`hidden`,onChange:Rc,accept:`*/*`}),(0,$.jsx)(`input`,{ref:kc,type:`file`,multiple:!0,className:`hidden`,onChange:Rc,accept:`image/*`}),null,br?(0,$.jsx)(Qa,{id:`android-media-pick-sheet`,open:ye,onOpenChange:e=>{e||be(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:f(`chat.chatInput.actions.addAttachment`)}),ariaLabel:f(`chat.chatInput.actions.addAttachment`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{We.current=!1,be(!1),requestAnimationFrame(Lc)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{We.current=!1,be(!1),requestAnimationFrame(Fc)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,br&&Vc&&Hc?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(Qa,{id:`mobile-draft-project-picker-sheet-${Ce}`,open:xe===`project`,onOpenChange:e=>{e||Se(null)},ariaLabel:f(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`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)(Fa,{value:De,onChange:e=>Ae(e.target.value),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(fa,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:Ln.filter(e=>Na(ab(e),De)||Na(e.path,De)).map(e=>(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:()=>{ul(e.id),Se(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:fl(e)}),e.id===Hc.id?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground`}):null]},e.id))})}),(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:()=>{Se(null),hi.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},xb=e=>{let t=(0,Q.c)(3),n=nm(),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)(bb,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};xb.displayName=`ChatInput`;var Sb=Z.memo(xb);function Cb(e){return e.preventDefault()}function wb(e){e.preventDefault()}function Tb(e){return e.preventDefault()}function Eb(e){e.pointerType===`touch`&&e.preventDefault()}function Db(e){e.preventDefault()}function Ob(e){e.pointerType===`touch`&&e.preventDefault()}function kb(){let e=(0,Q.c)(47),{t}=ot(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>mo(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=q(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],jo(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await cc(n),Cr.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}Cr.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=q(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Le()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,disabled:i,onClick:C,children:[E,O]})})}),e[34]=i,e[35]=C,e[36]=E,e[37]=O,e[38]=k):k=e[38];let A;return e[39]!==d||e[40]!==s||e[41]!==S||e[42]!==k||e[43]!==b||e[44]!==x||e[45]!==_?(A=(0,$.jsx)(`div`,{ref:o,children:(0,$.jsx)(Qa,{id:`image-save-actions-sheet`,open:s,onOpenChange:d,title:b,ariaLabel:_,closeAriaLabel:x,resizeAriaLabel:S,fitContent:!0,children:k})}),e[39]=d,e[40]=s,e[41]=S,e[42]=k,e[43]=b,e[44]=x,e[45]=_,e[46]=A):A=e[46],A}var Ab=(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(kt(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]},jb=(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},Mb=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}},Nb=e=>e.syncLoading||e.assistantLoading,Pb=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Fb=e=>e.isLoadingOlder,Ib=e=>!e.isMobile&&e.isLoadingOlder,Lb=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Rb=e=>e.p0Satisfied||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,zb=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}},Bb=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Vb=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Hb=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Ub=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)(Ea,{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},Wb=e=>{let t=(0,Q.c)(42),{t:n}=ot(),r=s(Gb),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Hb,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 ${Vb}`,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,c;t[11]!==e.agentName||t[12]!==o?(c=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=c):c=t[13];let l=c,u=e.modelName||o,d;t[14]===n?d=t[15]:(d=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=d);let f=`${d}: ${l}`,p;t[16]===n?p=t[17]:(p=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=p);let m=`${p}: ${u}`,h=r&&Hb,g;t[18]===h?g=t[19]:(g=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] p-3`,h),t[18]=h,t[19]=g);let _=r&&`oc-mobile-readonly-prompt-surface`,v;t[20]===_?v=t[21]:(v=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,_),t[20]=_,t[21]=v);let y;t[22]===n?y=t[23]:(y=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=y);let b;t[24]===y?b=t[25]:(b=(0,$.jsx)(`div`,{className:`text-muted-foreground ${Vb}`,children:y}),t[24]=y,t[25]=b);let x;t[26]!==f||t[27]!==l||t[28]!==m||t[29]!==u||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(x=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)(ea,{name:e.agentName,size:14,label:f}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:l,children:l})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Ub,{providerId:e.providerId,modelId:e.modelId,label:m}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:u,children:u})]})]}):null,t[26]=f,t[27]=l,t[28]=m,t[29]=u,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=x):x=t[34];let S;t[35]!==x||t[36]!==v||t[37]!==b?(S=(0,$.jsxs)(`div`,{className:v,children:[b,x]}),t[35]=x,t[36]=v,t[37]=b,t[38]=S):S=t[38];let C;return t[39]!==S||t[40]!==g?(C=(0,$.jsx)(`aside`,{className:g,children:S}),t[39]=S,t[40]=g,t[41]=C):C=t[41],C};function Gb(e){return e.isMobile}var Kb=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ot(),{currentTheme:n}=za(),r=Hi(qb),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(io,{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 qb(e){return e.error}var Jb=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)}}},Yb=`oc:legend-timeline`,Xb=()=>{try{return typeof localStorage>`u`||localStorage.getItem(Yb)!==`0`}catch{return!0}},Zb=de(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t}),legendTimelineEnabled:Xb(),setLegendTimelineEnabled:t=>{try{typeof localStorage<`u`&&localStorage.setItem(Yb,t?`1`:`0`)}catch{}e({legendTimelineEnabled:t})}})),Qb=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:an(t)},$b=Z.memo(e=>{let t=(0,Q.c)(31),{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?Qb(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)(Ea,{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(${$i(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]!==r||t[23]!==n?(x=!n&&o&&(0,$.jsxs)(`div`,{className:Y(`agent-badge inline-flex items-center gap-1 cursor-default rounded font-normal leading-tight`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,$i(o).class),children:[(0,$.jsx)(ea,{name:o,size:10}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=r,t[23]=n,t[24]=x):x=t[24];let S;t[25]!==b||t[26]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b,x]}),t[25]=b,t[26]=x,t[27]=S):S=t[27];let C;return t[28]!==S||t[29]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m,S]})})}),t[28]=S,t[29]=m,t[30]=C):C=t[30],C}),ex=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,tx=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,nx=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#x27;`),rx=(e,t)=>e.split(tx).map((e,n)=>n%2==1?e:t(e)).join(``),ix=e=>rx(e,e=>e.replace(/ *\n/g,`
6539
+ `)),ax=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=rx(e,nx);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${ps(t.name)})`;i=i.replace(t.token,e)}i=i.replace(ex,(e,t,r)=>n.has(r)?`${t}[/${r}](${us(r)})`:e)}return ix(i)},ox=e=>(ex.lastIndex=0,ex.test(e)||e.includes(`[skill:`)),sx=e=>e===`markdown`?`markdown`:`plain`,cx=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)},lx=Z.memo(({part:e,messageId:t,agentMention:n,messageParts:r})=>{let i=e,a=i.text,o=typeof a==`string`?a:i.content||i.value||``,[c,l]=Z.useState(!1),[u,d]=Z.useState(!1),f=s(e=>e.userMessageRenderingMode),p=s(e=>e.collapsibleUserMessages),m=is(),h=ti({directory:m,enabled:ox(o)}),g=Z.useMemo(()=>h.data??[],[h.data]),_=s(e=>e.openContextFile),{t:v}=ot(),y=sx(f),b=p&&!c,x=Z.useRef(null),S=Z.useMemo(()=>new Map(g.map(e=>[e.name,e])),[g]),C=Z.useMemo(()=>Jd(r,o),[r,o]),w=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!on(t))continue;let n=t.text;if(typeof n==`string`)for(let t of Br(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of Ai()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${ee}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),T=q(e=>{let t=S.get(e),n=typeof t?.path==`string`?t.path:``,r=yo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=m||go(``,i)||`/`,o=()=>{_(a,i)};if(m&&!So(i,m)){as(i,m).then(o);return}o()});Z.useEffect(()=>{let e=x.current;if(!e)return;let t=()=>{p&&!c&&d(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[p,o,c]),Z.useEffect(()=>{p||(l(!1),d(!1))},[p]);let E=q(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??ss(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),T(n);return}let r=x.current;r&&(cx(r)||p&&!c&&u&&l(!0))}),D=q(e=>{e.stopPropagation(),l(!1)}),O=Z.useMemo(()=>Hd(o,{skillNames:new Set(S.keys()),citationIcons:C.icons,citationDisplayNames:C.displayNames,sessionMentions:w,agentNames:n?.name?new Set([n.name.toLowerCase(),n.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),[n,C,w,S,o]),k=Z.useMemo(()=>ax({textContent:o,agentMention:n,skillNames:new Set(S.keys()),decorateInlineReferences:!O}),[n,O,S,o]),A=(e,t)=>{if(!e)return null;if(y===`markdown`){let n=ax({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(Mo,{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`,b&&[`[&_.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)}return(0,$.jsx)(Z.Fragment,{children:e},t)},j=e=>e.map((e,t)=>e.type===`text`?A(e.text,`text-${t}`):(0,$.jsx)(Xd,{decoration:e.decoration,onOpenSkill:T},`ref-${t}-${e.span.start}`)),M=Z.useMemo(()=>{if(O)return j(O);let e=[],t=0,r=!1,i;for(ex.lastIndex=0;(i=ex.exec(o))!==null;){let n=i[1]||``,r=i[2],a=i.index+n.length;S.has(r)&&(i.index>t&&e.push(o.slice(t,i.index)),n&&e.push(n),e.push((0,$.jsxs)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:e=>{e.stopPropagation(),T(r)},children:[`/`,r]},`skill-${a}-${r}`)),t=a+r.length+1)}t<o.length&&e.push(o.slice(t));let a=e.length>0?e:[o];return!n?.token||!o.includes(n.token)?a:a.flatMap((e,t)=>{if(r||typeof e!=`string`)return e;let i=e.indexOf(n.token);return i===-1?e:(r=!0,[e.slice(0,i),(0,$.jsx)(`a`,{href:os(n.name),className:`text-primary hover:underline`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:n.token},`agent-${t}`),e.slice(i+n.token.length)])})},[n,T,O,j,S,o]);return!o||o.trim().length===0?null:(0,$.jsxs)(`div`,{className:`relative`,children:[p&&c&&(0,$.jsx)(`button`,{type:`button`,onClick:D,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":v(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,c&&`pb-3`,y===`plain`&&`whitespace-pre-wrap`,b&&`line-clamp-10`,p&&u&&!c&&`cursor-pointer`),ref:x,onClick:E,children:y===`markdown`?O?j(O):(0,$.jsx)(Mo,{content:k,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,b&&[`[&_.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}):M})]},e.id||`${t}-user-text`)}),ux=[{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)(vc.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)(vc.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)(vc.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)(vc.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 dx(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=ux.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||ux[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 fx=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===`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===`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===`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`?(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===`plan_enter`?(0,$.jsx)(X,{name:`file-list-2`,className:t}):r===`plan_exit`?(0,$.jsx)(X,{name:`task`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},px=new Map,mx=e=>{let t=px.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return px.set(e,n),n},hx=(e,t)=>{let n=mx(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=px.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),px.delete(e)))}},gx=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(_x),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return hx(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 _x(){return Date.now()}var vx=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],yx=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},bx=e=>{if(!e||typeof e!=`object`)return;let t=e;return yx(t.sessionId)??yx(t.sessionID)},xx=(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},Sx=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},Cx=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:yx(e.sessionId)??yx(e.sessionID),status:yx(e.status),summaryEntries:Sx(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},wx=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=Cx(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 yx((n?.[1]??r?.[1])||vx(e))},Tx=e=>{if(!(!e||typeof e!=`object`))return yx(e.status)},Ex=/"status"\s*:\s*"running"/i,Dx=/\bstatus\s*[:=]\s*["'`]?running\b/i,Ox=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]&&Ex.test(t[1])?!0:Dx.test(e)},kx=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,Ax=(e,t)=>yx(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),jx=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},Mx=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(kx);if(!t)return;let n=Ax(t[1],`sessionID`)??Ax(t[1],`sessionId`),r=jx(Ax(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:Ax(t[1],`description`),body:t[2].trim()}},Nx=new WeakMap,Px=e=>{let t=Nx.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||e===`task`||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 Nx.set(e,n),n},Fx=e=>{let t=[];for(let n of e)t.push(...Px(n));return t},Ix=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),Lx=[`summary`,`changes`,`verification`],Rx={summary:`Summary`,changes:`Changes`,verification:`Verification`},zx=/<(summary|changes|verification)(?:\s[^>]*)?>/i,Bx=()=>RegExp(`<(${Lx.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),Vx=e=>typeof e!=`string`||e.length===0?!1:zx.test(e),Hx=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!Vx(e)?e:e.replace(Bx(),(e,t,n)=>{let r=Rx[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),Ux=e=>Hx(Ix(e)),Wx=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}};function Gx(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 Kx=(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},qx=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},Jx=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},Yx=e=>e?.state,Xx=e=>e?.metadata,Zx=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},Qx=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,``):``},$x=(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||qx(r)!==qx(i))return!1;if(r.type===`tool`){if(Yx(r)!==Yx(i)||Xx(r)!==Xx(i)||Jx(r)!==Jx(i))return!1;let e=Zx(r),t=Zx(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=Zx(r),o=Zx(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(Qx(r)!==Qx(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},eS=(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.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)&&Kx(e.tokens,t.tokens),tS=(e,t)=>eS(e.info,t.info)&&$x(e.parts,t.parts),nS=(e,t)=>!e||!t?e===t:tS(e,t),rS=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,iS=(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},aS=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&$x([e.part],[t.part]),oS=(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(!aS(a,o))return!1;r+=1,i+=1}},sS=(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(!aS(e.parts[n],t.parts[n]))return!1;return!0},cS=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),lS=(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(!sS(a,o))return!1;r+=1,i+=1}},uS=(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.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||!oS(e.activityParts,t.activityParts,n)||!lS(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=cS(e.activityGroupSegments,n)||cS(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!rS(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!iS(e.changedFiles,t.changedFiles))},dS=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,fS=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,pS=/(?=^diff --git\s+)/gm,mS=/^diff --git\s+/m,hS=/(?=^---\s+\S)/gm,gS=/^---\s+\S/m,_S=e=>typeof e==`object`&&!!e,vS=e=>e.replace(/\r\n/g,`
6540
6540
  `).replace(/\r/g,`
6541
6541
  `).trim(),yS=e=>{let t=!1;return e.split(`
6542
6542
  `).map(e=>{if(e.startsWith(`@@`))return t=!0,e;if(t)return e;let n=e.match(/^\s*(---|\+\+\+)\s+(.+)$/);if(!n)return e;let r=n[1],i=n[2]??``;return i.trim()===`/dev/null`?`${r} /dev/null`:`${r} ${i.replace(/\\/g,`/`)}`}).join(`
@@ -6551,19 +6551,19 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
6551
6551
  `),a=i.length,o=i.map(e=>`+${e}`).join(`
6552
6552
  `);return[`--- /dev/null`,`+++ b/${r}`,`@@ -0,0 +1,${a} @@`,o].join(`
6553
6553
  `)},MC=(e,t,n)=>{if(!t||e!==`edit`&&e!==`multiedit`&&e!==`apply_patch`)return;let r=NC(e,t,n);if(r){let e=AC(r);if(Number.isFinite(e))return e}},NC=(e,t,n)=>{if(!t||e!==`edit`&&e!==`multiedit`&&e!==`apply_patch`)return;let r=Array.isArray(t.files)?t.files:[];if(r.length>0){let e=typeof n==`string`&&n.length>0?n:void 0,t=e?r.find(t=>{if(!t||typeof t!=`object`)return!1;let n=t;return n.relativePath===e||n.filePath===e||n.movePath===e}):r[0];if(t&&typeof t==`object`){let e=wS(t.patch)??wS(t.diff);if(e)return e}}let i=t.filediff;if(i&&typeof i==`object`){let e=wS(i.patch)??wS(i.diff);if(e)return e}let a=wS(t.patch)??wS(t.diff);if(a)return a},PC=e=>{let t=e.trim().replace(/\\/g,`/`).replace(/\/{2,}/g,`/`);return!t||t===`/`?t:t.replace(/\/+$/,``)},FC=(e,t)=>{let n=PC(e),r=PC(t);if(!n)return``;if(!r)return n;if(n===r)return`.`;let i=`${r}/`;return n.startsWith(i)?n.slice(i.length):n},IC=5,LC=e=>typeof e==`object`&&!!e,RC=e=>{if(!LC(e))return null;let t=typeof e.message==`string`?e.message.trim():``;if(!t)return null;let n=typeof e.severity==`number`&&Number.isFinite(e.severity)?Math.trunc(e.severity):void 0;if(n!==void 0&&n!==1)return null;let r=LC(e.range)?e.range:void 0,i=r&&LC(r.start)?r.start:void 0,a=typeof i?.line==`number`&&Number.isFinite(i.line)?Math.max(0,Math.trunc(i.line)):0,o=typeof i?.character==`number`&&Number.isFinite(i.character)?Math.max(0,Math.trunc(i.character)):0;return{message:t,line:a+1,character:o+1}},zC=(e,t,n)=>{let r=LC(n?.filediff)?n.filediff:void 0,i=LC(r)&&typeof r.file==`string`?r.file:null;if(e===`apply_patch`){let e=(Array.isArray(n?.files)?n.files:[]).find(e=>LC(e)?typeof e.movePath==`string`||typeof e.filePath==`string`||typeof e.relativePath==`string`:!1);if(LC(e))return typeof e.movePath==`string`?e.movePath:typeof e.filePath==`string`?e.filePath:typeof e.relativePath==`string`?e.relativePath:i;let t=wS(n?.patch)??wS(n?.diff),r=t?MS(void 0,t,e=>e).find(e=>e.renderMode===`diff`):void 0;return r?.title?r.title:i}return e===`edit`||e===`multiedit`?i||(typeof t?.filePath==`string`?t.filePath:typeof t?.file_path==`string`?t.file_path:typeof t?.path==`string`?t.path:null):e===`write`?typeof t?.filePath==`string`?t.filePath:typeof t?.file_path==`string`?t.file_path:typeof t?.path==`string`?t.path:null:null},BC=(e,t,n,r)=>{if(![`edit`,`multiedit`,`write`,`apply_patch`].includes(e))return null;let i=zC(e,t,n);if(!i||!n||!LC(n.diagnostics))return null;let a=PC(i),o=a.startsWith(`/`)?a:`${PC(r)}/${a}`.replace(/\/+/g,`/`),s=n.diagnostics[a]??n.diagnostics[o];if(!Array.isArray(s))return null;let c=s.map(e=>RC(e)).filter(e=>!!e);if(c.length===0)return null;let l=c.slice(0,IC);return{displayPath:a.startsWith(`/`)?FC(a,r):a,diagnostics:l,remaining:Math.max(0,c.length-l.length)}},VC=()=>{let e=(0,Q.c)(22),t=Ba(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=Eo(!1),e[0]=n):n=e[0];let r=n,i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=Eo(!0),e[1]=i):i=e[1];let a=i,o;e[2]===t?.availableThemes?o=e[3]:(o=()=>t?.availableThemes??[r,a],e[2]=t?.availableThemes,e[3]=o),t?.availableThemes;let s;e[4]===o?s=e[5]:(s=o(),e[4]=o,e[5]=s);let c=s,l=t?.lightThemeId??r.metadata.id,u=t?.darkThemeId??a.metadata.id,d;e[6]!==c||e[7]!==l?(d=c.find(e=>e.metadata.id===l)??r,e[6]=c,e[7]=l,e[8]=d):d=e[8];let f=d,p;e[9]!==c||e[10]!==u?(p=c.find(e=>e.metadata.id===u)??a,e[9]=c,e[10]=u,e[11]=p):p=e[11];let m=p,h,g;e[12]!==m||e[13]!==f?(h=()=>{Po(f),Po(m)},g=[m,f],e[12]=m,e[13]=f,e[14]=h,e[15]=g):(h=e[14],g=e[15]),Z.useEffect(h,g);let _=t?.currentTheme.metadata.variant??`light`,v;e[16]!==m.metadata.id||e[17]!==f.metadata.id?(v={light:f.metadata.id,dark:m.metadata.id},e[16]=m.metadata.id,e[17]=f.metadata.id,e[18]=v):v=e[18];let y=_===`dark`?`dark`:`light`,b;return e[19]!==v||e[20]!==y?(b={pierreTheme:v,pierreThemeType:y},e[19]=v,e[20]=y,e[21]=b):b=e[21],b},HC=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},UC=(e,t,n)=>{let r=t,i=r.metadata,a=r.input;if(e.tool===`apply_patch`){let e=Array.isArray(i?.files)?i?.files:[],t=e[0],r=t?.relativePath||t?.filePath;return e.length>1?null:typeof r==`string`?FC(r,n):null}if((e.tool===`edit`||e.tool===`multiedit`)&&a){let e=a?.filePath||a?.file_path||a?.path||i?.filePath||i?.file_path||i?.path;if(typeof e==`string`)return FC(e,n)}if(e.tool===`read`&&a){let e=a?.filePath||a?.file_path||a?.path||i?.filePath||i?.file_path||i?.path;if(typeof e==`string`)return FC(e,n)}if([`write`,`create`,`file_write`].includes(e.tool)&&a){let e=a?.filePath||a?.file_path||a?.path;if(typeof e==`string`)return FC(e,n)}if(e.tool===`lsp`&&a){let e=a?.filePath||a?.file_path||a?.path;if(typeof e==`string`)return FC(e,n)}return null},WC=(e,t)=>{if(!e)return``;let n=typeof e.operation==`string`?e.operation:`lsp`;if(n===`workspaceSymbol`)return`${n}${typeof e.query==`string`&&e.query.trim().length>0?` "${e.query.trim()}"`:``}`;let r=typeof e.filePath==`string`?e.filePath:typeof e.file_path==`string`?e.file_path:typeof e.path==`string`?e.path:``,i=r?FC(r,t):``;if(n===`documentSymbol`)return i?`${n} ${i}`:n;let a=typeof e.line==`number`&&Number.isFinite(e.line)?Math.trunc(e.line):void 0,o=typeof e.character==`number`&&Number.isFinite(e.character)?Math.trunc(e.character):void 0,s=a!==void 0&&o!==void 0?`:${a}:${o}`:``;return i?`${n} ${i}${s}`:n},GC=(e,t,n)=>{let r=t,i=r.metadata,a=r.input,o=UC(e,t,n);if(o)return o;if(e.tool===`apply_patch`){let e=Array.isArray(i?.files)?i?.files:[];return e.length>1?`${e.length} files`:``}if(e.tool===`question`&&a?.questions&&Array.isArray(a.questions)){let e=a.questions.length;return`Asked ${e} question${e===1?``:`s`}`}if(e.tool===`bash`&&a?.command&&typeof a.command==`string`)return a.command.split(`
6554
- `)[0].substring(0,100);if(e.tool===`task`&&a?.description&&typeof a.description==`string`)return a.description.substring(0,80);if(e.tool===`lsp`)return WC(a,n);let s=a?.description||i?.description||`title`in t&&t.title||``;return typeof s==`string`?s:``},KC=e=>{let t=(0,Q.c)(17),{children:n,isMobile:r,maxHeightClass:i,className:a,outerClassName:o,disableHorizontal:s}=e,c=r!==void 0&&r,l=i===void 0?`max-h-[60vh]`:i,u=s!==void 0&&s,d;t[0]===o?d=t[1]:(d=Y(`w-full min-w-0 flex-none overflow-hidden`,o),t[0]=o,t[1]=d);let f;if(t[2]!==a||t[3]!==u||t[4]!==c||t[5]!==l){let e;t[7]===c?e=t[8]:(e=c&&zS(!0),t[7]=c,t[8]=e),f=Y(`tool-output-surface rounded-xl w-full min-w-0`,zS(c),l,u?`overflow-y-auto overflow-x-hidden`:`overflow-auto`,a,e),t[2]=a,t[3]=u,t[4]=c,t[5]=l,t[6]=f}else f=t[6];let p;t[9]===n?p=t[10]:(p=(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:n}),t[9]=n,t[10]=p);let m;t[11]!==f||t[12]!==p?(m=(0,$.jsx)(Ta,{className:f,children:p}),t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==d||t[15]!==m?(h=(0,$.jsx)(`div`,{className:d,children:m}),t[14]=d,t[15]=m,t[16]=h):h=t[16],h},qC=(e,t,n,r)=>t.tool===`bash`?`bash`:Ys(rc(e,t.tool,n),t.tool,r),JC=(e,t,n)=>t.tool===`bash`?e:rc(e,t.tool,n),YC=e=>{let t=(0,Q.c)(80),{output:n,part:r,metadata:i,input:a,isMobile:o}=e,s=o!==void 0&&o,{t:c}=st(),l;t[0]!==i||t[1]!==n||t[2]!==r?(l=JC(n,r,i),t[0]=i,t[1]=n,t[2]=r,t[3]=l):l=t[3];let u=l,d;t[4]!==a||t[5]!==i||t[6]!==n||t[7]!==r?(d=qC(n,r,i,a),t[4]=a,t[5]=i,t[6]=n,t[7]=r,t[8]=d):d=t[8];let f=d,p;t[9]===u?p=t[10]:(p=$s(u),t[9]=u,t[10]=p);let m=p,[h,g]=Z.useState(`formatted`),[_,v]=Z.useState(!1),y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{g(`formatted`),v(!1)},t[11]=y):y=t[11];let b;t[12]===u?b=t[13]:(b=[u],t[12]=u,t[13]=b),Z.useEffect(y,b);let x;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(x=(e,t)=>{t.stopPropagation(),g(e)},t[14]=x):x=t[14];let S=K(x),C;t[15]!==u||t[16]!==c?(C=async e=>{if(e.stopPropagation(),!(await lt(u)).ok){wr.error(c(`chat.toolPart.copyOutputFailed`));return}v(!0),typeof window<`u`&&window.setTimeout(()=>v(!1),1200)},t[15]=u,t[16]=c,t[17]=C):C=t[17];let w=K(C);if(m.isJson){let e=h===`formatted`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,n;t[18]===e?n=t[19]:(n=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,e),t[18]=e,t[19]=n);let r;t[20]===S?r=t[21]:(r=e=>S(`formatted`,e),t[20]=S,t[21]=r);let i;t[22]===c?i=t[23]:(i=c(`chat.toolPart.showFormattedJson`),t[22]=c,t[23]=i);let a;t[24]===c?a=t[25]:(a=c(`chat.toolPart.showFormattedJson`),t[24]=c,t[25]=a);let o;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(X,{name:`node-tree`,className:`h-3.5 w-3.5`}),t[26]=o):o=t[26];let s;t[27]!==n||t[28]!==r||t[29]!==i||t[30]!==a?(s=(0,$.jsx)(la,{variant:`ghost`,size:`icon`,className:n,onClick:r,onPointerDown:xw,"aria-label":i,title:a,children:o}),t[27]=n,t[28]=r,t[29]=i,t[30]=a,t[31]=s):s=t[31];let l=h===`raw`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,d;t[32]===l?d=t[33]:(d=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,l),t[32]=l,t[33]=d);let f;t[34]===S?f=t[35]:(f=e=>S(`raw`,e),t[34]=S,t[35]=f);let p;t[36]===c?p=t[37]:(p=c(`chat.toolPart.showRawJson`),t[36]=c,t[37]=p);let g;t[38]===c?g=t[39]:(g=c(`chat.toolPart.showRawJson`),t[38]=c,t[39]=g);let v;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(X,{name:`code-box`,className:`h-3.5 w-3.5`}),t[40]=v):v=t[40];let y;t[41]!==d||t[42]!==f||t[43]!==p||t[44]!==g?(y=(0,$.jsx)(la,{variant:`ghost`,size:`icon`,className:d,onClick:f,onPointerDown:Sw,"aria-label":p,title:g,children:v}),t[41]=d,t[42]=f,t[43]=p,t[44]=g,t[45]=y):y=t[45];let b;t[46]!==_||t[47]!==c?(b=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[46]=_,t[47]=c,t[48]=b):b=t[48];let x;t[49]!==_||t[50]!==c?(x=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[49]=_,t[50]=c,t[51]=x):x=t[51];let C=_?`check`:`file-copy`,T;t[52]===C?T=t[53]:(T=(0,$.jsx)(X,{name:C,className:`h-3.5 w-3.5`}),t[52]=C,t[53]=T);let E;t[54]!==w||t[55]!==b||t[56]!==x||t[57]!==T?(E=(0,$.jsx)(la,{variant:`ghost`,size:`icon`,className:`h-6 w-6 rounded-md bg-[var(--surface-elevated)]/80 text-muted-foreground hover:text-foreground`,onClick:w,onPointerDown:Cw,"aria-label":b,title:x,children:T}),t[54]=w,t[55]=b,t[56]=x,t[57]=T,t[58]=E):E=t[58];let D;t[59]!==s||t[60]!==y||t[61]!==E?(D=(0,$.jsxs)(`div`,{className:`absolute right-2 top-2 z-10 flex items-center gap-1`,children:[s,y,E]}),t[59]=s,t[60]=y,t[61]=E,t[62]=D):D=t[62];let O;t[63]!==m.data||t[64]!==h||t[65]!==u?(O=h===`formatted`?(0,$.jsx)(ac,{data:m.data,initiallyExpandedDepth:1,maxHeight:`400px`}):(0,$.jsx)(`div`,{className:`typography-code pr-12 text-muted-foreground/90`,children:(0,$.jsx)(Qs,{language:`json`,code:u,style:ow,codeStyle:sw.style,wrap:!0})}),t[63]=m.data,t[64]=h,t[65]=u,t[66]=O):O=t[66];let k;return t[67]!==D||t[68]!==O?(k=(0,$.jsxs)(`div`,{className:`tool-output-surface relative p-2 rounded-xl w-full min-w-0`,children:[D,O]}),t[67]=D,t[68]=O,t[69]=k):k=t[69],k}let T=r.tool===`bash`?`typography-code text-muted-foreground/90`:void 0,E;t[70]!==s||t[71]!==r.tool?(E={...ow,...s&&r.tool===`bash`?{lineHeight:BS}:{}},t[70]=s,t[71]=r.tool,t[72]=E):E=t[72];let D;t[73]!==f||t[74]!==u||t[75]!==E?(D=(0,$.jsx)(Qs,{language:f,code:u,style:E,codeStyle:sw.style,wrap:!0}),t[73]=f,t[74]=u,t[75]=E,t[76]=D):D=t[76];let O;return t[77]!==D||t[78]!==T?(O=(0,$.jsx)(`div`,{className:T,children:D}),t[77]=D,t[78]=T,t[79]=O):O=t[79],O};YC.displayName=`ToolScrollableTextOutput`;var XC=e=>{let t=e.state?.title;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.state?.input;if(n&&typeof n==`object`){let e=n.filePath??n.file_path??n.path;if(typeof e==`string`&&e.trim().length>0)return e.trim();let t=n.url;if(typeof t==`string`&&t.trim().length>0)return t.trim()}return``},ZC=new Set([`read`,`view`,`file_read`,`cat`,`write`,`create`,`file_write`,`edit`,`multiedit`,`apply_patch`]),QC=(e,t)=>{if(!ZC.has(e.toLowerCase()))return!1;let n=t.trim();if(!n||n===`Patch`||/^\d+\s+files$/.test(n))return!1;if(n.includes(`/`)||n.includes(`\\`))return!0;let r=n.split(/[\\/]/).pop()||n;return r.startsWith(`.`)||r.includes(`.`)?!0:/^[A-Za-z0-9_-]+$/.test(r)},$C=e=>{let t=bC(e.tool),n=e.state?.status??``,r=XC(e);return`${e.id??``}\u0001${t}\u0001${n}\u0001${r}`},ew=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if($C(e[n])!==$C(t[n]))return!1;return!0},tw=Z.memo(e=>{let t=(0,Q.c)(10),{entry:n,isMobile:r,animateTailText:i,showToolFileIcons:a}=e,{t:o}=st(),s;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==o){let e=bC(n.tool),c=e.length>0?e:`tool`,l=XC(n),u=l.trim().length>0,d=n.state?.status,f=$o(c,o),p=r?`items-start`:`items-center`,m;t[6]===p?m=t[7]:(m=Y(`flex gap-1.5 min-w-0 w-full py-px`,p),t[6]=p,t[7]=m);let h,g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=Y(pC,`text-foreground/80 flex-shrink-0`),g={color:`var(--tools-title)`},t[8]=h,t[9]=g):(h=t[8],g=t[9]),s=(0,$.jsxs)(`div`,{className:m,children:[(0,$.jsx)(`span`,{className:`flex-shrink-0 scale-90 text-foreground/80`,children:fx(c)}),(0,$.jsx)(`span`,{className:h,style:g,title:f,children:f}),u?d!==`error`&&QC(c,l)?pw(l,i,!0,a,pC):d===`error`?(0,$.jsx)(`span`,{className:Y(pC,`flex-1 min-w-0 text-[var(--status-error)]`,r?`whitespace-normal break-words`:`truncate`),children:l}):(0,$.jsx)(dx,{variant:i?`generate-effect`:`static`,className:Y(pC,`flex-1 min-w-0 text-muted-foreground/70`,r?`whitespace-normal break-words`:`truncate`),style:{color:`var(--tools-description)`},title:l,children:l}):null]}),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o,t[5]=s}else s=t[5];return s},(e,t)=>e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&$C(e.entry)===$C(t.entry));tw.displayName=`TaskSummaryEntryRow`;var nw=Z.memo(e=>{let t=(0,Q.c)(24),{entries:n,isExpanded:r,isMobile:i,animateTailText:a,showToolFileIcons:o}=e,s;t[0]!==n||t[1]!==r?(s=r?n:n.slice(-6),t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=s,l=Math.max(0,n.length-c.length),u=n.length-c.length,d=r?`max-h-[40vh]`:`max-h-56`,f;t[3]===l?f=t[4]:(f=l>0?(0,$.jsxs)(`div`,{className:Y(pC,`text-muted-foreground/70`),children:[`+`,l,` more…`]}):null,t[3]=l,t[4]=f);let p;if(t[5]!==a||t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==c||t[10]!==u){let e;t[12]!==a||t[13]!==r||t[14]!==i||t[15]!==o||t[16]!==u?(e=(e,t)=>{let n=r?t:u+t,s=e.id??`${$C(e)}:${n}`;return(0,$.jsx)(tw,{entry:e,isMobile:i,animateTailText:a,showToolFileIcons:o},s)},t[12]=a,t[13]=r,t[14]=i,t[15]=o,t[16]=u,t[17]=e):e=t[17],p=c.map(e),t[5]=a,t[6]=r,t[7]=i,t[8]=o,t[9]=c,t[10]=u,t[11]=p}else p=t[11];let m;t[18]!==f||t[19]!==p?(m=(0,$.jsxs)(`div`,{className:mC,children:[f,p]}),t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==d||t[22]!==m?(h=(0,$.jsx)(KC,{maxHeightClass:d,disableHorizontal:!0,children:m}),t[21]=d,t[22]=m,t[23]=h):h=t[23],h},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&ew(e.entries,t.entries));nw.displayName=`TaskSummaryEntriesList`;var rw=e=>{let t=(0,Q.c)(44),{entries:n,isExpanded:r,isMobile:i,output:a,sessionId:o,onShowPopup:c,input:l,animateTailText:u,isActive:d}=e,f=u===void 0||u,p=d!==void 0&&d,{t:m}=st(),h=is(),g=J(ww),_=s(Tw),v=s(Ew),y=Z.useContext(Oo),b=Qm(),x=b.directory||h,S;t[0]===a?S=t[1]:(S=typeof a==`string`?Ux(a):``,t[0]=a,t[1]=S);let C=S,w=C.length>0,[T,E]=Z.useState(!1),D,O,k,A;if(t[2]!==f||t[3]!==x||t[4]!==n||t[5]!==w||t[6]!==l||t[7]!==p||t[8]!==r||t[9]!==i||t[10]!==_||t[11]!==y?.runtime||t[12]!==o||t[13]!==b||t[14]!==g||t[15]!==v||t[16]!==m){A=Symbol.for(`react.early_return_sentinel`);bb0:{let e=_C(gC(l)??`subagent`),a=t=>{t.stopPropagation(),o&&x&&eh(b,o,x,()=>{if(!ci({sessionId:o,directory:x})){if(Ac()||i||y?.runtime.isVSCode){g(o,x);return}_(x,{mode:`chat`,dedupeKey:`session:${o}`,label:e,readOnly:!0})}})};if(n.length===0&&!w&&!o){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(pC,`text-muted-foreground/70`),t[21]=e):e=t[21];let n=p?`Waiting for subagent activity...`:`No subagent session id on task metadata.`,r;t[22]===n?r=t[23]:(r=(0,$.jsx)(`div`,{className:`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,children:(0,$.jsx)(`div`,{className:e,children:n})}),t[22]=n,t[23]=r),A=r;break bb0}t[24]===Symbol.for(`react.memo_cache_sentinel`)?(D=Y(`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,`before:absolute before:left-[0.4375rem] before:w-px before:bg-border/80 before:content-[""]`,`before:top-0 before:bottom-0`),t[24]=D):D=t[24],t[25]!==f||t[26]!==n||t[27]!==r||t[28]!==i||t[29]!==v?(O=n.length>0?(0,$.jsx)(nw,{entries:n,isExpanded:r,isMobile:i,animateTailText:f,showToolFileIcons:v}):null,t[25]=f,t[26]=n,t[27]=r,t[28]=i,t[29]=v,t[30]=O):O=t[30],k=o&&b.capabilities.navigateNestedSession&&(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-primary hover:text-primary/80 w-full`,pC),onPointerDown:Dw,onClick:a,children:[(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(pC,`text-primary font-medium`),children:m(`chat.toolPart.openSubtask`,{type:e})})]})}t[2]=f,t[3]=x,t[4]=n,t[5]=w,t[6]=l,t[7]=p,t[8]=r,t[9]=i,t[10]=_,t[11]=y?.runtime,t[12]=o,t[13]=b,t[14]=g,t[15]=v,t[16]=m,t[17]=D,t[18]=O,t[19]=k,t[20]=A}else D=t[17],O=t[18],k=t[19],A=t[20];if(A!==Symbol.for(`react.early_return_sentinel`))return A;let j;t[31]!==n.length||t[32]!==w||t[33]!==T||t[34]!==c||t[35]!==o||t[36]!==m||t[37]!==C?(j=w?(0,$.jsxs)(`div`,{className:Y(`flex flex-col gap-1`,(n.length>0||o)&&`pt-1`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-foreground/80 hover:text-foreground w-full`,pC),onPointerDown:Ow,onClick:e=>{e.stopPropagation(),E(kw)},children:[T?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(pC,`text-foreground/80 font-medium`),children:m(`chat.toolPart.output`)})]}),T?(0,$.jsx)(KC,{maxHeightClass:`max-h-[50vh]`,children:(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Mo,{content:C,variant:`tool`,onShowPopup:c})})}):null]}):null,t[31]=n.length,t[32]=w,t[33]=T,t[34]=c,t[35]=o,t[36]=m,t[37]=C,t[38]=j):j=t[38];let M;return t[39]!==D||t[40]!==O||t[41]!==k||t[42]!==j?(M=(0,$.jsxs)(`div`,{className:D,children:[O,k,j]}),t[39]=D,t[40]=O,t[41]=k,t[42]=j,t[43]=M):M=t[43],M},iw=`
6554
+ `)[0].substring(0,100);if(e.tool===`task`&&a?.description&&typeof a.description==`string`)return a.description.substring(0,80);if(e.tool===`lsp`)return WC(a,n);let s=a?.description||i?.description||`title`in t&&t.title||``;return typeof s==`string`?s:``},KC=e=>{let t=(0,Q.c)(17),{children:n,isMobile:r,maxHeightClass:i,className:a,outerClassName:o,disableHorizontal:s}=e,c=r!==void 0&&r,l=i===void 0?`max-h-[60vh]`:i,u=s!==void 0&&s,d;t[0]===o?d=t[1]:(d=Y(`w-full min-w-0 flex-none overflow-hidden`,o),t[0]=o,t[1]=d);let f;if(t[2]!==a||t[3]!==u||t[4]!==c||t[5]!==l){let e;t[7]===c?e=t[8]:(e=c&&zS(!0),t[7]=c,t[8]=e),f=Y(`tool-output-surface rounded-xl w-full min-w-0`,zS(c),l,u?`overflow-y-auto overflow-x-hidden`:`overflow-auto`,a,e),t[2]=a,t[3]=u,t[4]=c,t[5]=l,t[6]=f}else f=t[6];let p;t[9]===n?p=t[10]:(p=(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:n}),t[9]=n,t[10]=p);let m;t[11]!==f||t[12]!==p?(m=(0,$.jsx)(Ta,{className:f,children:p}),t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==d||t[15]!==m?(h=(0,$.jsx)(`div`,{className:d,children:m}),t[14]=d,t[15]=m,t[16]=h):h=t[16],h},qC=(e,t,n,r)=>t.tool===`bash`?`bash`:Ys(rc(e,t.tool,n),t.tool,r),JC=(e,t,n)=>t.tool===`bash`?e:rc(e,t.tool,n),YC=e=>{let t=(0,Q.c)(80),{output:n,part:r,metadata:i,input:a,isMobile:o}=e,s=o!==void 0&&o,{t:c}=ot(),l;t[0]!==i||t[1]!==n||t[2]!==r?(l=JC(n,r,i),t[0]=i,t[1]=n,t[2]=r,t[3]=l):l=t[3];let u=l,d;t[4]!==a||t[5]!==i||t[6]!==n||t[7]!==r?(d=qC(n,r,i,a),t[4]=a,t[5]=i,t[6]=n,t[7]=r,t[8]=d):d=t[8];let f=d,p;t[9]===u?p=t[10]:(p=$s(u),t[9]=u,t[10]=p);let m=p,[h,g]=Z.useState(`formatted`),[_,v]=Z.useState(!1),y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{g(`formatted`),v(!1)},t[11]=y):y=t[11];let b;t[12]===u?b=t[13]:(b=[u],t[12]=u,t[13]=b),Z.useEffect(y,b);let x;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(x=(e,t)=>{t.stopPropagation(),g(e)},t[14]=x):x=t[14];let S=q(x),C;t[15]!==u||t[16]!==c?(C=async e=>{if(e.stopPropagation(),!(await ct(u)).ok){Cr.error(c(`chat.toolPart.copyOutputFailed`));return}v(!0),typeof window<`u`&&window.setTimeout(()=>v(!1),1200)},t[15]=u,t[16]=c,t[17]=C):C=t[17];let w=q(C);if(m.isJson){let e=h===`formatted`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,n;t[18]===e?n=t[19]:(n=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,e),t[18]=e,t[19]=n);let r;t[20]===S?r=t[21]:(r=e=>S(`formatted`,e),t[20]=S,t[21]=r);let i;t[22]===c?i=t[23]:(i=c(`chat.toolPart.showFormattedJson`),t[22]=c,t[23]=i);let a;t[24]===c?a=t[25]:(a=c(`chat.toolPart.showFormattedJson`),t[24]=c,t[25]=a);let o;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(X,{name:`node-tree`,className:`h-3.5 w-3.5`}),t[26]=o):o=t[26];let s;t[27]!==n||t[28]!==r||t[29]!==i||t[30]!==a?(s=(0,$.jsx)(la,{variant:`ghost`,size:`icon`,className:n,onClick:r,onPointerDown:xw,"aria-label":i,title:a,children:o}),t[27]=n,t[28]=r,t[29]=i,t[30]=a,t[31]=s):s=t[31];let l=h===`raw`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,d;t[32]===l?d=t[33]:(d=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,l),t[32]=l,t[33]=d);let f;t[34]===S?f=t[35]:(f=e=>S(`raw`,e),t[34]=S,t[35]=f);let p;t[36]===c?p=t[37]:(p=c(`chat.toolPart.showRawJson`),t[36]=c,t[37]=p);let g;t[38]===c?g=t[39]:(g=c(`chat.toolPart.showRawJson`),t[38]=c,t[39]=g);let v;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(X,{name:`code-box`,className:`h-3.5 w-3.5`}),t[40]=v):v=t[40];let y;t[41]!==d||t[42]!==f||t[43]!==p||t[44]!==g?(y=(0,$.jsx)(la,{variant:`ghost`,size:`icon`,className:d,onClick:f,onPointerDown:Sw,"aria-label":p,title:g,children:v}),t[41]=d,t[42]=f,t[43]=p,t[44]=g,t[45]=y):y=t[45];let b;t[46]!==_||t[47]!==c?(b=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[46]=_,t[47]=c,t[48]=b):b=t[48];let x;t[49]!==_||t[50]!==c?(x=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[49]=_,t[50]=c,t[51]=x):x=t[51];let C=_?`check`:`file-copy`,T;t[52]===C?T=t[53]:(T=(0,$.jsx)(X,{name:C,className:`h-3.5 w-3.5`}),t[52]=C,t[53]=T);let E;t[54]!==w||t[55]!==b||t[56]!==x||t[57]!==T?(E=(0,$.jsx)(la,{variant:`ghost`,size:`icon`,className:`h-6 w-6 rounded-md bg-[var(--surface-elevated)]/80 text-muted-foreground hover:text-foreground`,onClick:w,onPointerDown:Cw,"aria-label":b,title:x,children:T}),t[54]=w,t[55]=b,t[56]=x,t[57]=T,t[58]=E):E=t[58];let D;t[59]!==s||t[60]!==y||t[61]!==E?(D=(0,$.jsxs)(`div`,{className:`absolute right-2 top-2 z-10 flex items-center gap-1`,children:[s,y,E]}),t[59]=s,t[60]=y,t[61]=E,t[62]=D):D=t[62];let O;t[63]!==m.data||t[64]!==h||t[65]!==u?(O=h===`formatted`?(0,$.jsx)(ac,{data:m.data,initiallyExpandedDepth:1,maxHeight:`400px`}):(0,$.jsx)(`div`,{className:`typography-code pr-12 text-muted-foreground/90`,children:(0,$.jsx)(Qs,{language:`json`,code:u,style:ow,codeStyle:sw.style,wrap:!0})}),t[63]=m.data,t[64]=h,t[65]=u,t[66]=O):O=t[66];let k;return t[67]!==D||t[68]!==O?(k=(0,$.jsxs)(`div`,{className:`tool-output-surface relative p-2 rounded-xl w-full min-w-0`,children:[D,O]}),t[67]=D,t[68]=O,t[69]=k):k=t[69],k}let T=r.tool===`bash`?`typography-code text-muted-foreground/90`:void 0,E;t[70]!==s||t[71]!==r.tool?(E={...ow,...s&&r.tool===`bash`?{lineHeight:BS}:{}},t[70]=s,t[71]=r.tool,t[72]=E):E=t[72];let D;t[73]!==f||t[74]!==u||t[75]!==E?(D=(0,$.jsx)(Qs,{language:f,code:u,style:E,codeStyle:sw.style,wrap:!0}),t[73]=f,t[74]=u,t[75]=E,t[76]=D):D=t[76];let O;return t[77]!==D||t[78]!==T?(O=(0,$.jsx)(`div`,{className:T,children:D}),t[77]=D,t[78]=T,t[79]=O):O=t[79],O};YC.displayName=`ToolScrollableTextOutput`;var XC=e=>{let t=e.state?.title;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.state?.input;if(n&&typeof n==`object`){let e=n.filePath??n.file_path??n.path;if(typeof e==`string`&&e.trim().length>0)return e.trim();let t=n.url;if(typeof t==`string`&&t.trim().length>0)return t.trim()}return``},ZC=new Set([`read`,`view`,`file_read`,`cat`,`write`,`create`,`file_write`,`edit`,`multiedit`,`apply_patch`]),QC=(e,t)=>{if(!ZC.has(e.toLowerCase()))return!1;let n=t.trim();if(!n||n===`Patch`||/^\d+\s+files$/.test(n))return!1;if(n.includes(`/`)||n.includes(`\\`))return!0;let r=n.split(/[\\/]/).pop()||n;return r.startsWith(`.`)||r.includes(`.`)?!0:/^[A-Za-z0-9_-]+$/.test(r)},$C=e=>{let t=bC(e.tool),n=e.state?.status??``,r=XC(e);return`${e.id??``}\u0001${t}\u0001${n}\u0001${r}`},ew=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if($C(e[n])!==$C(t[n]))return!1;return!0},tw=Z.memo(e=>{let t=(0,Q.c)(10),{entry:n,isMobile:r,animateTailText:i,showToolFileIcons:a}=e,{t:o}=ot(),s;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==o){let e=bC(n.tool),c=e.length>0?e:`tool`,l=XC(n),u=l.trim().length>0,d=n.state?.status,f=$o(c,o),p=r?`items-start`:`items-center`,m;t[6]===p?m=t[7]:(m=Y(`flex gap-1.5 min-w-0 w-full py-px`,p),t[6]=p,t[7]=m);let h,g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=Y(pC,`text-foreground/80 flex-shrink-0`),g={color:`var(--tools-title)`},t[8]=h,t[9]=g):(h=t[8],g=t[9]),s=(0,$.jsxs)(`div`,{className:m,children:[(0,$.jsx)(`span`,{className:`flex-shrink-0 scale-90 text-foreground/80`,children:fx(c)}),(0,$.jsx)(`span`,{className:h,style:g,title:f,children:f}),u?d!==`error`&&QC(c,l)?pw(l,i,!0,a,pC):d===`error`?(0,$.jsx)(`span`,{className:Y(pC,`flex-1 min-w-0 text-[var(--status-error)]`,r?`whitespace-normal break-words`:`truncate`),children:l}):(0,$.jsx)(dx,{variant:i?`generate-effect`:`static`,className:Y(pC,`flex-1 min-w-0 text-muted-foreground/70`,r?`whitespace-normal break-words`:`truncate`),style:{color:`var(--tools-description)`},title:l,children:l}):null]}),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o,t[5]=s}else s=t[5];return s},(e,t)=>e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&$C(e.entry)===$C(t.entry));tw.displayName=`TaskSummaryEntryRow`;var nw=Z.memo(e=>{let t=(0,Q.c)(24),{entries:n,isExpanded:r,isMobile:i,animateTailText:a,showToolFileIcons:o}=e,s;t[0]!==n||t[1]!==r?(s=r?n:n.slice(-6),t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=s,l=Math.max(0,n.length-c.length),u=n.length-c.length,d=r?`max-h-[40vh]`:`max-h-56`,f;t[3]===l?f=t[4]:(f=l>0?(0,$.jsxs)(`div`,{className:Y(pC,`text-muted-foreground/70`),children:[`+`,l,` more…`]}):null,t[3]=l,t[4]=f);let p;if(t[5]!==a||t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==c||t[10]!==u){let e;t[12]!==a||t[13]!==r||t[14]!==i||t[15]!==o||t[16]!==u?(e=(e,t)=>{let n=r?t:u+t,s=e.id??`${$C(e)}:${n}`;return(0,$.jsx)(tw,{entry:e,isMobile:i,animateTailText:a,showToolFileIcons:o},s)},t[12]=a,t[13]=r,t[14]=i,t[15]=o,t[16]=u,t[17]=e):e=t[17],p=c.map(e),t[5]=a,t[6]=r,t[7]=i,t[8]=o,t[9]=c,t[10]=u,t[11]=p}else p=t[11];let m;t[18]!==f||t[19]!==p?(m=(0,$.jsxs)(`div`,{className:mC,children:[f,p]}),t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==d||t[22]!==m?(h=(0,$.jsx)(KC,{maxHeightClass:d,disableHorizontal:!0,children:m}),t[21]=d,t[22]=m,t[23]=h):h=t[23],h},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&ew(e.entries,t.entries));nw.displayName=`TaskSummaryEntriesList`;var rw=e=>{let t=(0,Q.c)(44),{entries:n,isExpanded:r,isMobile:i,output:a,sessionId:o,onShowPopup:c,input:l,animateTailText:u,isActive:d}=e,f=u===void 0||u,p=d!==void 0&&d,{t:m}=ot(),h=is(),g=Qr(ww),_=s(Tw),v=s(Ew),y=Z.useContext(Oo),b=Qm(),x=b.directory||h,S;t[0]===a?S=t[1]:(S=typeof a==`string`?Ux(a):``,t[0]=a,t[1]=S);let C=S,w=C.length>0,[T,E]=Z.useState(!1),D,O,k,A;if(t[2]!==f||t[3]!==x||t[4]!==n||t[5]!==w||t[6]!==l||t[7]!==p||t[8]!==r||t[9]!==i||t[10]!==_||t[11]!==y?.runtime||t[12]!==o||t[13]!==b||t[14]!==g||t[15]!==v||t[16]!==m){A=Symbol.for(`react.early_return_sentinel`);bb0:{let e=_C(gC(l)??`subagent`),a=t=>{t.stopPropagation(),o&&x&&eh(b,o,x,()=>{if(!ci({sessionId:o,directory:x})){if(Ac()||i||y?.runtime.isVSCode){g(o,x);return}_(x,{mode:`chat`,dedupeKey:`session:${o}`,label:e,readOnly:!0})}})};if(n.length===0&&!w&&!o){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(pC,`text-muted-foreground/70`),t[21]=e):e=t[21];let n=p?`Waiting for subagent activity...`:`No subagent session id on task metadata.`,r;t[22]===n?r=t[23]:(r=(0,$.jsx)(`div`,{className:`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,children:(0,$.jsx)(`div`,{className:e,children:n})}),t[22]=n,t[23]=r),A=r;break bb0}t[24]===Symbol.for(`react.memo_cache_sentinel`)?(D=Y(`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,`before:absolute before:left-[0.4375rem] before:w-px before:bg-border/80 before:content-[""]`,`before:top-0 before:bottom-0`),t[24]=D):D=t[24],t[25]!==f||t[26]!==n||t[27]!==r||t[28]!==i||t[29]!==v?(O=n.length>0?(0,$.jsx)(nw,{entries:n,isExpanded:r,isMobile:i,animateTailText:f,showToolFileIcons:v}):null,t[25]=f,t[26]=n,t[27]=r,t[28]=i,t[29]=v,t[30]=O):O=t[30],k=o&&b.capabilities.navigateNestedSession&&(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-primary hover:text-primary/80 w-full`,pC),onPointerDown:Dw,onClick:a,children:[(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(pC,`text-primary font-medium`),children:m(`chat.toolPart.openSubtask`,{type:e})})]})}t[2]=f,t[3]=x,t[4]=n,t[5]=w,t[6]=l,t[7]=p,t[8]=r,t[9]=i,t[10]=_,t[11]=y?.runtime,t[12]=o,t[13]=b,t[14]=g,t[15]=v,t[16]=m,t[17]=D,t[18]=O,t[19]=k,t[20]=A}else D=t[17],O=t[18],k=t[19],A=t[20];if(A!==Symbol.for(`react.early_return_sentinel`))return A;let j;t[31]!==n.length||t[32]!==w||t[33]!==T||t[34]!==c||t[35]!==o||t[36]!==m||t[37]!==C?(j=w?(0,$.jsxs)(`div`,{className:Y(`flex flex-col gap-1`,(n.length>0||o)&&`pt-1`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-foreground/80 hover:text-foreground w-full`,pC),onPointerDown:Ow,onClick:e=>{e.stopPropagation(),E(kw)},children:[T?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(pC,`text-foreground/80 font-medium`),children:m(`chat.toolPart.output`)})]}),T?(0,$.jsx)(KC,{maxHeightClass:`max-h-[50vh]`,children:(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Mo,{content:C,variant:`tool`,onShowPopup:c})})}):null]}):null,t[31]=n.length,t[32]=w,t[33]=T,t[34]=c,t[35]=o,t[36]=m,t[37]=C,t[38]=j):j=t[38];let M;return t[39]!==D||t[40]!==O||t[41]!==k||t[42]!==j?(M=(0,$.jsxs)(`div`,{className:D,children:[O,k,j]}),t[39]=D,t[40]=O,t[41]=k,t[42]=j,t[43]=M):M=t[43],M},iw=`
6555
6555
  [data-diff-header],
6556
6556
  [data-diff] {
6557
6557
  [data-separator] {
6558
6558
  height: 24px !important;
6559
6559
  }
6560
6560
  }
6561
- `,aw={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},ow={...o.getCollapsedStyles(),padding:0,overflow:`visible`},sw={style:{background:`transparent`,backgroundColor:`transparent`}},cw={color:`var(--status-error)`},lw={color:`var(--tools-icon)`},uw={color:`var(--status-error)`},dw={color:`var(--tools-title)`},fw=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate typography-ui-label text-foreground`,t&&`flex-1`),style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 flex items-baseline overflow-hidden typography-ui-label`,t&&`flex-1`),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0 text-muted-foreground`,children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i})]})]})},pw=(e,t=!0,n=!0,r=!0,i=fC)=>{let a=e.lastIndexOf(`/`),o=i===pC?`h-3 w-3 flex-shrink-0`:`h-3.5 w-3.5 flex-shrink-0`;if(a===-1)return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(ku,{filePath:e,className:o}):null,(0,$.jsx)(dx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 truncate whitespace-nowrap`,i,n&&`flex-1`),style:{color:`var(--tools-description)`},children:e})]});let s=e.slice(0,a),c=e.slice(a+1),l=s.startsWith(`/`),u=l?s.slice(1):s;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(ku,{filePath:e,className:o}):null,(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full items-baseline overflow-hidden`,i,n&&`flex-1`),children:[l?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:u}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(dx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:c})]})]})},mw=e=>{let t=(0,Q.c)(3),{diff:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={backgroundColor:`var(--syntax-base-background)`,color:`var(--syntax-base-foreground)`},t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`pre`,{className:`m-0 overflow-auto whitespace-pre-wrap break-words rounded-lg p-2 typography-code`,style:r,children:n}),t[1]=n,t[2]=i),i},hw=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1})}componentDidCatch(e){}render(){return this.state.hasError?this.props.fallback:this.props.children}},gw=Z.memo(e=>{let t=(0,Q.c)(13),{diff:n,pierreTheme:r,pierreThemeType:i,diffViewMode:a}=e,o=a===`side-by-side`?`split`:`unified`,s;t[0]!==r||t[1]!==i||t[2]!==o?(s={diffStyle:o,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:`wrap`,theme:r,themeType:i,unsafeCSS:iw},t[0]=r,t[1]=i,t[2]=o,t[3]=s):s=t[3];let c=s,l;t[4]===n?l=t[5]:(l=(0,$.jsx)(mw,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)(gc,{patch:n,metrics:aw,options:c,className:`block w-full`}),t[6]=n,t[7]=c,t[8]=d):d=t[8];let f;return t[9]!==n||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0`,children:(0,$.jsx)(hw,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});gw.displayName=`DiffPreview`;var _w=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=st(),{pierreTheme:s,pierreThemeType:c}=VC(),[l,u]=Z.useState(`unified`),d=t,f=d.metadata,p=d.input,m=d.output,h=typeof m==`string`&&m.length>0,g=typeof m==`string`?m:``,_=LC(f?.filediff)?f.filediff:void 0,v=wS(f?.patch)??wS(f?.diff)??wS(_?.patch)??wS(_?.diff)??null,y=Z.useMemo(()=>MS(f,v??void 0,e=>FC(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>BC(e.tool,p,f,n),[n,p,f,e.tool]),S=Z.useMemo(()=>!p||typeof p!=`object`||Object.keys(p).length===0?``:`command`in p&&typeof p.command==`string`&&e.tool===`bash`?oc(p,e.tool):typeof p.content==`string`?p.content??``:oc(p,e.tool),[p,e.tool]),C=!b&&S.trim().length>0,w=e.tool===`write`||e.tool===`create`||e.tool===`file_write`,T=e.tool===`todowrite`||e.tool===`todoread`,E=Z.useMemo(()=>Array.isArray(p?.todos)?JSON.stringify(p.todos):g,[p?.todos,g]),D=Z.useMemo(()=>!w||!C?void 0:jC(typeof p?.filePath==`string`?p.filePath:typeof p?.file_path==`string`?p.file_path:typeof p?.path==`string`?p.path:void 0,S),[C,p?.filePath,p?.file_path,p?.path,S,w]);Z.useEffect(()=>{u(`unified`)},[e.id]);let O=(e,t)=>(0,$.jsx)(KC,{isMobile:i,maxHeightClass:t?.maxHeightClass,className:t?.className,disableHorizontal:t?.disableHorizontal,outerClassName:t?.outerClassName,children:e}),k=()=>{let n=()=>x?(0,$.jsxs)(`div`,{className:`tool-output-surface flex flex-col gap-2 rounded-xl border p-2`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--status-error-background)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium`,style:{color:`var(--status-error)`},children:o(`chat.toolPart.lspErrors`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 min-w-0`,children:fw(x.displayPath,!1)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:x.diagnostics.map((e,t)=>(0,$.jsx)(`div`,{className:`rounded-md border px-2 py-1`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--surface-elevated)`},children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`typography-micro shrink-0`,style:{color:`var(--status-error)`},children:[`[`,e.line,`:`,e.character,`]`]}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground whitespace-pre-wrap break-words`,children:e.message})]})},`${x.displayPath}:${e.line}:${e.character}:${t}`))}),x.remaining>0?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:o(`chat.toolPart.moreErrors`,{count:x.remaining})}):null]})]}):null;if(e.tool===`question`){if(t.status===`completed`&&h){let e=HC(g);if(e&&e.length>0)return O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.question}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground whitespace-pre-wrap`,children:e.answer})]},t))}),{maxHeightClass:`max-h-[40vh]`})}if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:ec(t.error)})]});let e=p;return e?.questions&&Array.isArray(e.questions)&&e.questions.length>0?O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.questions.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[e.header?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:ec(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:ec(e.question)}),Array.isArray(e.options)&&e.options.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:e.options.map(e=>(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-muted/30 border border-border/30 text-muted-foreground`,children:ec(e.label)},ec(e.label)))}):null]},t))}),{maxHeightClass:`max-h-[40vh]`}):(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:o(`chat.toolPart.awaitingResponse`)})}return e.tool===`task`&&h?O((0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Mo,{content:ec(g),variant:`tool`,onShowPopup:a})})):(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`||e.tool===`write`)&&(y.length>0||x)?O((0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[y.map(e=>(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:e.renderMode===`diff`?(0,$.jsx)(gw,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(mw,{diff:e.patch})},e.id)),n()]}),{className:`p-1`}):e.tool===`write`&&x?O((0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:n()}),{className:`p-1`}):w?null:h&&g.trim()?O((0,$.jsx)(YC,{output:ec(g),part:e,metadata:f,input:p,isMobile:i}),{className:e.tool===`bash`?`p-1 rounded-none`:`p-1`,maxHeightClass:e.tool===`bash`?`max-h-[46vh]`:void 0}):O((0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground/70`,children:o(`chat.toolPart.noOutputProduced`)}),{maxHeightClass:`max-h-60`})};if(T){if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:RS(i,`todo-error`),children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-none border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:t.error})]});let n=ic(E,void 0,{listClassName:tc});return(0,$.jsx)(`div`,{className:RS(i,`todo`),children:O(n??(0,$.jsx)(YC,{output:E,part:e,metadata:f,input:p,isMobile:i}),Gs)})}return(0,$.jsx)(`div`,{className:RS(i,`default`,e.tool===`bash`),children:e.tool===`question`?k():(0,$.jsxs)($.Fragment,{children:[C?(0,$.jsx)(`div`,{children:O(e.tool===`bash`?(0,$.jsx)(`pre`,{className:`tool-input-text whitespace-pre-wrap break-words typography-code text-muted-foreground/90 m-0 p-0`,style:i?{lineHeight:BS}:void 0,children:S}):w&&D?(0,$.jsx)(gw,{diff:D,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(`blockquote`,{className:`tool-input-text m-0 whitespace-pre-wrap break-words typography-meta italic text-muted-foreground/70`,children:S}),{maxHeightClass:w&&D&&r?`max-h-[50vh]`:`max-h-60`,className:e.tool===`bash`?`tool-input-surface p-0 rounded-none`:`tool-input-surface`})}):null,t.status===`completed`&&`output`in t&&(0,$.jsx)(`div`,{children:k()}),t.status===`error`&&`error`in t&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:ec(t.error)})]})]})})});_w.displayName=`ToolExpandedContent`;var vw=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:c=!0})=>{let l=e.state,u=s(e=>e.showToolFileIcons),d=s(e=>e.showSubagentTaskDetails),f=s(e=>e.openContextPanelTab),p=s(e=>e.openContextDiff),m=s(e=>e.openContextToolDiff),h=s(e=>e.navigateToDiff),{t:g}=st(),_=is(),v=J(e=>e.setCurrentSession),y=_h(),b=Qm(),x=b.directory||_||``,S=bC(e.tool),C=S===`task`,w=S===`todowrite`||S===`todoread`,T=wC(S),E=l?.status,D=sC(e),O=E===`error`||E===`failed`,[k,A]=Z.useState(!D),j=Z.useRef(e.id),M=Z.useRef(``);Z.useEffect(()=>{j.current!==e.id&&(j.current=e.id,M.current=``,A(!D))},[D,e.id]),Z.useEffect(()=>{D||A(!0)},[D]),Z.useEffect(()=>{if(!D||O||!x||!SC.has(S))return;let t=`${e.id}:${E??`unknown`}`;M.current!==t&&(M.current=t,hi.requestGitRefresh({directory:x}))},[x,O,D,S,e.id,E]);let N=D||C,P=Z.useRef(a);P.current=a;let F=Z.useRef(null);Z.useLayoutEffect(()=>{if(C||T)return;let e=F.current;if(!e){N&&P.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,N&&P.current?.(`structural`)},[n,T,C,N]);let I=l,L=I.metadata,R=e.metadata,z=I.input,B=I.time,[V,H]=Z.useState(()=>({start:typeof B?.start==`number`?B.start:void 0,end:typeof B?.end==`number`?B.end:void 0})),[U,ee]=Z.useState(void 0),[te,W]=Z.useState(void 0);Z.useEffect(()=>{H({}),ee(void 0),W(void 0)},[e.id]),Z.useEffect(()=>{D||typeof B?.start!=`number`&&ee(e=>e??Date.now())},[D,B?.start]),Z.useEffect(()=>{H(e=>{let t={...e},n=!1;return typeof B?.start==`number`&&(typeof e.start!=`number`||B.start<e.start)&&(t.start=B.start,n=!0),typeof B?.end==`number`&&(typeof e.end!=`number`||B.end>e.end)&&(t.end=B.end,n=!0),n?t:e})},[B?.end,B?.start]);let G=Z.useMemo(()=>{if(typeof U==`number`)return U;let e=[V.start,B?.start].filter(e=>typeof e==`number`);if(e.length!==0)return Math.min(...e)},[U,V.start,B?.start]),ne=Z.useMemo(()=>typeof I.output==`string`?I.output:void 0,[I.output]),re=Z.useMemo(()=>Cx(ne),[ne]),ie=Z.useMemo(()=>{if(!C)return[];let e=L,t=Sx(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:re.summaryEntries},[C,L,re.summaryEntries]),ae=D&&ie.length>0,oe=Z.useMemo(()=>C?bx(L)||bx(I)||bx(z)||bx(R)||(re.sessionId?re.sessionId:wx(ne)):void 0,[z,C,L,re.sessionId,R,I,ne]),se=Z.useMemo(()=>C&&D&&!!(Tx(L)===`running`||Tx(I)===`running`||Tx(R)===`running`||re.status===`running`||Ox(ne)),[C,D,L,re.status,R,I,ne]),[ce,le]=Z.useState(!0),ue=C&&(!D&&k||se&&ce),de=ue?oe:void 0,fe=ue&&!oe?e.sessionID:void 0,pe=de??fe,me=Er(de??``,x),he=Er(fe??``,x),ge=ei(pe??``,x),_e=Fi(x,ue),ve=!!(se&&me?.type===`idle`&&typeof G==`number`&&(typeof ge==`number`&&G<=ge||typeof _e==`number`&&G<=_e));Z.useEffect(()=>{ve&&le(!1)},[ve]);let ye=!!(se&&ce&&oe&&me?.type!==`idle`),be=!d||ae?``:oe??``,xe=di(be,x);Wt(be,x);let Se=Z.useMemo(()=>!C||!oe||!Array.isArray(xe)||xe.length===0?[]:Fx(xe),[xe,C,oe]);Z.useEffect(()=>{if(typeof B?.end==`number`||typeof V.end==`number`){W(void 0);return}typeof G==`number`&&D&&W(e=>e??Date.now())},[G,D,V.end,B?.end]);let Ce=D?V.end??B?.end??te:void 0,we=!D&&k,Te=Gx({isTaskTool:C,isFinalized:D,taskSessionId:oe,childSessionStatus:me,parentSessionStatus:he,statusObservedAt:ge,taskStartedAt:G,statusSnapshotAt:_e}),Ee=we&&!Te||ye,De=!!(C&&Ee&&!O);Z.useEffect(()=>{Te&&A(!1)},[Te]);let Oe=D,ke=Z.useMemo(()=>Se.length>0?Se:ie,[Se,ie]),Ae=Z.useMemo(()=>ke.map($C).join(`\0`),[ke]),je=Z.useRef(null);Z.useEffect(()=>{if(!C){je.current=null;return}let e=je.current;je.current=Ae,e!==null&&e!==Ae&&ke.length!==0&&P.current?.(`structural`)},[C,ke.length,Ae]);let Me=Z.useMemo(()=>S===`edit`||S===`multiedit`||S===`apply_patch`?OC(L):null,[L,S]),Ne=Z.useMemo(()=>S===`write`?kC(z):null,[z,S]),Pe=S===`apply_patch`&&Array.isArray(L?.files)&&(L?.files).length>1,Fe=S===e.tool?e:{...e,tool:S},Ie=UC(Fe,l,x),Le=GC(Fe,l,x),Re=$o(S||e.tool,g),ze=ur(C?oe:void 0,x),Be=ur(C?oe:void 0),Ve=C?gC(z,L,R,ze??Be):void 0,He=Wx({isTaskTool:C,isFinalized:D,taskSessionId:oe,taskAgentName:Ve,displayName:Re,delegatingLabel:g(`chat.assistantStatus.delegatingTask`),formatName:_C}),Ue=C&&He.isDelegating,We=He.title,Ge=typeof e.sessionID==`string`?e.sessionID.trim():``,Ke=Z.useMemo(()=>{if(!C||!Ge)return null;let n=typeof oe==`string`&&oe.trim().length>0?oe.trim():void 0,r=typeof e.id==`string`&&e.id.trim().length>0?e.id.trim():void 0,i=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():typeof t==`string`&&t.trim().length>0?t.trim():void 0;return{sessionID:Ge,...r?{partID:r}:{},...i?{messageID:i}:{},...x?{directory:x}:{},directoryPresent:!!x,childSessionPresent:!!n,...n?{childSessionID:n}:{},...E?{toolStatus:E}:{},finalized:D,backgroundRunning:ye,effectiveActive:Ee,suppressLoading:Te,delegating:Ue,childStatus:Li(me),parentStatus:Li(he),idleConfirmed:ve,navigateCapability:b.capabilities.navigateNestedSession,surfaceKind:b.kind,...typeof G==`number`?{taskStartedAt:G}:{},...typeof ge==`number`?{statusObservedAt:ge}:{},...typeof _e==`number`?{statusSnapshotAt:_e}:{}}},[ve,me,x,Ee,G,Ue,D,C,t,Ge,he,e.id,e.messageID,b.capabilities.navigateNestedSession,b.kind,E,ge,_e,Te,ye,oe]),qe=Ke?Sr(Ke):``,Je=Z.useRef(Ke);Je.current=Ke,Z.useEffect(()=>{let e=Je.current;!e||!qe||yi(e)},[qe]);let Ye=K((e,t)=>{let n=Je.current;n&&Nr({...n,opened:e,clickSource:t})}),Xe=Ue?{"data-delegating":`true`}:void 0,Ze=Z.useMemo(()=>{if(S===`bash`||S===`apply_patch`||S===`lsp`||Ie&&(S===`apply_patch`||S===`edit`||S===`multiedit`||S===`write`))return null;let e=I.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=z?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Ie,S,I,z]),Qe=Z.useContext(Oo),$e=Z.useRef(!1),et=K(e=>{let t=e??oe;return!t||!x?!1:($e.current=!1,eh(b,t,x,()=>{if(!ci({sessionId:t,directory:x})){if(i||Qe?.runtime.isVSCode){v(t,x);return}f(x,{mode:`chat`,dedupeKey:`session:${t}`,label:We,readOnly:!0})}}))});Z.useEffect(()=>{!$e.current||!oe||Ye(et(oe),`queued-effect`)},[oe]);let tt=n=>{if(C){n.stopPropagation();let e=b.capabilities.navigateNestedSession,t=e?et():!1;Ye(t,`row`),e&&!t&&($e.current=!0);return}if(T&&!x)return;let a,o,c;if(S===`edit`||S===`multiedit`||S===`apply_patch`)a=zC(S,z,L),o=MC(S,L,typeof a==`string`?a:void 0),typeof a==`string`&&(c=NC(S,L,a));else if([`write`,`create`,`file_write`].includes(S))a=z?.filePath||z?.file_path||z?.path||L?.filePath||L?.file_path||L?.path,o=1,typeof a==`string`&&typeof z?.content==`string`&&(c=jC(a,z.content));else if(S===`lsp`){a=z?.filePath||z?.file_path||z?.path;let e=z?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=vo(x,a)||(a.startsWith(`/`)?a:x.endsWith(`/`)?x+a:`${x}/${a}`);if(T){let e=FC(r,x),n=(c?PS(S,L,c,e,e=>FC(e,x)):[]).map(e=>({path:e.title,patch:e.patch}));if(Qe?.runtime.isVSCode&&Qe.editor&&c){let t=`${e} (changes)`;Qe.editor.openDiff(``,r,t,{line:o,patch:c});return}if(So(r,x)){y?n.length>0?y.openToolDiff({diffPath:e,patches:n,targetLine:o}):S===`apply_patch`?y.openTurnDiff(t,b.sessionId):y.openChanges({diffPath:e,staged:!1,targetLine:o}):i?h(e,!1,`turn`,o):n.length>0?m(x,e,n,o,t,b.sessionId):p(x,e,!1,`turn`,o,t,b.sessionId);return}if(Qe?.editor){Qe.editor.openFile(r,o);return}as(r,x).then(()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(S===`lsp`){if(Qe?.editor){Qe.editor.openFile(r,o);return}let e=()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!So(r,x)){as(r,x).then(e);return}e();return}if(Qe?.editor){if(Qe.runtime.isVSCode&&c&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${FC(r,x)} (changes)`;Qe.editor.openDiff(``,r,e,{line:o,patch:c});return}Qe.editor.openFile(r,o);return}}if(S===`apply_patch`&&y){n.stopPropagation(),y.openTurnDiff(t,b.sessionId);return}if(S===`apply_patch`&&x&&!y&&!i&&!Qe?.runtime.isVSCode){n.stopPropagation(),f(x,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:b.sessionId});return}T||r(e.id)},nt=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),tt(e))},rt=!C&&O?cw:lw,it=!C&&O?uw:dw,at=C&&d&&(ke.length>0||Ee||Oe||!!oe),ot=!C&&!T&&n;return!Oe&&!we&&!C?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,kp,C&&`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Pe?`flex-wrap items-start`:`items-center`),"data-mobile-press-feedback":`soft`,...Xe,onClick:tt,onKeyDown:nt,role:`button`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5`,Pe?`w-full min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`:`items-center flex-shrink-0`),children:[(0,$.jsx)(`div`,{className:Y(`relative flex-shrink-0`,i?`size-4`:`size-3.5`),children:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,style:C&&He.showAvatar?void 0:rt,children:C&&He.showAvatar?(0,$.jsx)(ea,{name:e.id||Ve||`subagent`,size:14,label:We}):Ee?(0,$.jsx)(qS,{isMobile:i,className:`text-[var(--tools-icon)]`,label:g(`chat.assistantStatus.usingTool`,{tool:We})}):fx(S||e.tool)})}),Pe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(dC,`flex-shrink-0`),style:it,title:Re,children:Re}),yC(L,c,u)]}):(0,$.jsxs)($.Fragment,{children:[De?(0,$.jsx)(`span`,{className:Y(dC,`shrink-0 whitespace-nowrap animate-text-shimmer`),style:{color:`var(--tools-title)`,"--oc-text-shimmer-base":`var(--tools-title)`},title:We,children:We}):(0,$.jsx)(`span`,{className:Y(dC,`shrink-0 whitespace-nowrap`),style:it,title:We,children:We}),S===`bash`&&typeof G==`number`?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,fC),children:(0,$.jsx)(EC,{start:G,end:typeof Ce==`number`?Ce:void 0,active:!!(Ee&&typeof Ce!=`number`)})}):null]})]}),!Pe&&(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,fC),style:{color:`var(--tools-description)`},children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[Ze&&(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,fC,De&&`animate-text-shimmer`),style:{color:`var(--tools-description)`,...De?{"--oc-text-shimmer-base":`var(--tools-description)`}:{opacity:.8}},title:Ze,children:Ze}),!Ze&&S===`lsp`&&Ie?pw(Ie,c,!1,u):null,!Ze&&S!==`lsp`&&Le&&(Ie&&Le===Ie?pw(Ie,c,!1,u):(0,$.jsx)(dx,{variant:c?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,fC),style:{color:`var(--tools-description)`},title:Le,children:Le})),Me&&(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,Me.added]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,Me.removed]})]}),Ne&&(0,$.jsx)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,Ne]})})]})}),!T&&(!C||d)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:C?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),at?(0,$.jsx)(rw,{entries:ke,isExpanded:n,isMobile:i,output:ne,sessionId:oe,onShowPopup:o,input:z,animateTailText:c,isActive:Ee}):null,!C&&!T&&n?(0,$.jsx)(`div`,{ref:F,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:ot?(0,$.jsxs)(`div`,{className:w?`relative ml-0.5 pl-1.5`:LS,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),(0,$.jsx)(_w,{part:e,state:l,currentDirectory:x,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},yw=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1,error:void 0})}componentDidCatch(e){}render(){if(!this.state.hasError)return this.props.children;let e=this.state.error?.message;return(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1.5 min-w-0`,Dp),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:cw,children:fx(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(dC,`flex-shrink-0`),style:uw,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(fC,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},bw=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=st(),r=IS(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=bC(e.part.tool)||`tool`,i=$o(a,n),t[0]=e.part.tool,t[1]=n,t[2]=i,t[3]=a):(i=t[2],a=t[3]);let o=i,s;t[4]!==r||t[5]!==e.part.id?(s=()=>!r||vC.get(e.part.id)===!0,t[4]=r,t[5]=e.part.id,t[6]=s):s=t[6];let[c,l]=Z.useState(s),u,d;if(t[7]!==r||t[8]!==c||t[9]!==e.part.id?(u=()=>{if(!(!r||c))return ls(()=>{vC.set(e.part.id,!0,e.part.id.length*2+8),Z.startTransition(()=>{l(!0)})})},d=[r,c,e.part.id],t[7]=r,t[8]=c,t[9]=e.part.id,t[10]=u,t[11]=d):(u=t[10],d=t[11]),Z.useEffect(u,d),!c){let e,n,r;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(`flex min-w-0 items-center gap-2`,Dp),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(dC,`shrink-0 text-muted-foreground`),t[12]=e,t[13]=n,t[14]=r):(e=t[12],n=t[13],r=t[14]);let i;t[15]===o?i=t[16]:(i=(0,$.jsx)(`span`,{className:r,children:o}),t[15]=o,t[16]=i);let a;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`span`,{className:`h-3 w-24 min-w-0 rounded bg-muted/40`,"aria-hidden":`true`}),t[17]=a):a=t[17];let s;return t[18]===i?s=t[19]:(s=(0,$.jsxs)(`div`,{className:e,children:[n,i,a]}),t[18]=i,t[19]=s),s}let f;t[20]===n?f=t[21]:(f=n(`chat.toolPart.error`),t[20]=n,t[21]=f);let p;t[22]===e?p=t[23]:(p=(0,$.jsx)(vw,{...e}),t[22]=e,t[23]=p);let m;return t[24]!==o||t[25]!==e.part||t[26]!==f||t[27]!==p||t[28]!==a?(m=(0,$.jsx)(yw,{displayName:o,errorLabel:f,resetKey:e.part,toolName:a,children:p}),t[24]=o,t[25]=e.part,t[26]=f,t[27]=p,t[28]=a,t[29]=m):m=t[29],m},(e,t)=>$x([e.part],[t.part])&&e.messageId===t.messageId&&e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.alwaysShowActions===t.alwaysShowActions&&e.onContentChange===t.onContentChange&&e.onShowPopup===t.onShowPopup&&e.animateTailText===t.animateTailText);function xw(e){return e.stopPropagation()}function Sw(e){return e.stopPropagation()}function Cw(e){return e.stopPropagation()}function ww(e){return e.setCurrentSession}function Tw(e){return e.openContextPanelTab}function Ew(e){return e.showToolFileIcons}function Dw(e){return e.stopPropagation()}function Ow(e){return e.stopPropagation()}function kw(e){return!e}var Aw=(e,t,n)=>{let r=t-e;return Math.max(0,n-r)},jw=e=>{e.timer&&=(clearTimeout(e.timer),null)},Mw=({text:e,isStreaming:t,throttleMs:n=fs(Be()).textThrottleMs,identityKey:r})=>{let[i,a]=Z.useState(e),o=Z.useRef(e),s=Z.useRef(i),c=Z.useRef({timer:null,pendingText:e,lastEmitAt:0});return Z.useEffect(()=>{o.current=e},[e]),Z.useEffect(()=>{s.current=i},[i]),Z.useEffect(()=>{let e=c.current;jw(e),e.pendingText=o.current,e.lastEmitAt=0,a(o.current)},[r]),Z.useEffect(()=>{let r=c.current;r.pendingText=e;let i=s.current,o=t&&i.length>e.length?i:e;if(!t){jw(r),r.lastEmitAt=Date.now(),a(o);return}let l=Date.now(),u=Aw(r.lastEmitAt,l,n);if(u<=0){jw(r),r.lastEmitAt=l,a(o);return}return jw(r),r.timer=setTimeout(()=>{r.timer=null,r.lastEmitAt=Date.now(),a(e=>t&&e.length>r.pendingText.length?e:r.pendingText)},u),()=>{jw(r)}},[t,e,n]),Z.useEffect(()=>{let e=c.current;return()=>{jw(e)}},[]),i},Nw=e=>e.isStreaming?e.throttledTextContent:e.textContent,Pw=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,Fw=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=st(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(Iw)],t[2]=n.highlights,t[3]=n.subject,t[4]=e):e=t[4],l=e.join(`
6561
+ `,aw={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},ow={...o.getCollapsedStyles(),padding:0,overflow:`visible`},sw={style:{background:`transparent`,backgroundColor:`transparent`}},cw={color:`var(--status-error)`},lw={color:`var(--tools-icon)`},uw={color:`var(--status-error)`},dw={color:`var(--tools-title)`},fw=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate typography-ui-label text-foreground`,t&&`flex-1`),style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 flex items-baseline overflow-hidden typography-ui-label`,t&&`flex-1`),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0 text-muted-foreground`,children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i})]})]})},pw=(e,t=!0,n=!0,r=!0,i=fC)=>{let a=e.lastIndexOf(`/`),o=i===pC?`h-3 w-3 flex-shrink-0`:`h-3.5 w-3.5 flex-shrink-0`;if(a===-1)return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(ku,{filePath:e,className:o}):null,(0,$.jsx)(dx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 truncate whitespace-nowrap`,i,n&&`flex-1`),style:{color:`var(--tools-description)`},children:e})]});let s=e.slice(0,a),c=e.slice(a+1),l=s.startsWith(`/`),u=l?s.slice(1):s;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(ku,{filePath:e,className:o}):null,(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full items-baseline overflow-hidden`,i,n&&`flex-1`),children:[l?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:u}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(dx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:c})]})]})},mw=e=>{let t=(0,Q.c)(3),{diff:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={backgroundColor:`var(--syntax-base-background)`,color:`var(--syntax-base-foreground)`},t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`pre`,{className:`m-0 overflow-auto whitespace-pre-wrap break-words rounded-lg p-2 typography-code`,style:r,children:n}),t[1]=n,t[2]=i),i},hw=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1})}componentDidCatch(e){}render(){return this.state.hasError?this.props.fallback:this.props.children}},gw=Z.memo(e=>{let t=(0,Q.c)(13),{diff:n,pierreTheme:r,pierreThemeType:i,diffViewMode:a}=e,o=a===`side-by-side`?`split`:`unified`,s;t[0]!==r||t[1]!==i||t[2]!==o?(s={diffStyle:o,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:`wrap`,theme:r,themeType:i,unsafeCSS:iw},t[0]=r,t[1]=i,t[2]=o,t[3]=s):s=t[3];let c=s,l;t[4]===n?l=t[5]:(l=(0,$.jsx)(mw,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)(gc,{patch:n,metrics:aw,options:c,className:`block w-full`}),t[6]=n,t[7]=c,t[8]=d):d=t[8];let f;return t[9]!==n||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0`,children:(0,$.jsx)(hw,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});gw.displayName=`DiffPreview`;var _w=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=ot(),{pierreTheme:s,pierreThemeType:c}=VC(),[l,u]=Z.useState(`unified`),d=t,f=d.metadata,p=d.input,m=d.output,h=typeof m==`string`&&m.length>0,g=typeof m==`string`?m:``,_=LC(f?.filediff)?f.filediff:void 0,v=wS(f?.patch)??wS(f?.diff)??wS(_?.patch)??wS(_?.diff)??null,y=Z.useMemo(()=>MS(f,v??void 0,e=>FC(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>BC(e.tool,p,f,n),[n,p,f,e.tool]),S=Z.useMemo(()=>!p||typeof p!=`object`||Object.keys(p).length===0?``:`command`in p&&typeof p.command==`string`&&e.tool===`bash`?oc(p,e.tool):typeof p.content==`string`?p.content??``:oc(p,e.tool),[p,e.tool]),C=!b&&S.trim().length>0,w=e.tool===`write`||e.tool===`create`||e.tool===`file_write`,T=e.tool===`todowrite`||e.tool===`todoread`,E=Z.useMemo(()=>Array.isArray(p?.todos)?JSON.stringify(p.todos):g,[p?.todos,g]),D=Z.useMemo(()=>!w||!C?void 0:jC(typeof p?.filePath==`string`?p.filePath:typeof p?.file_path==`string`?p.file_path:typeof p?.path==`string`?p.path:void 0,S),[C,p?.filePath,p?.file_path,p?.path,S,w]);Z.useEffect(()=>{u(`unified`)},[e.id]);let O=(e,t)=>(0,$.jsx)(KC,{isMobile:i,maxHeightClass:t?.maxHeightClass,className:t?.className,disableHorizontal:t?.disableHorizontal,outerClassName:t?.outerClassName,children:e}),k=()=>{let n=()=>x?(0,$.jsxs)(`div`,{className:`tool-output-surface flex flex-col gap-2 rounded-xl border p-2`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--status-error-background)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium`,style:{color:`var(--status-error)`},children:o(`chat.toolPart.lspErrors`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 min-w-0`,children:fw(x.displayPath,!1)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:x.diagnostics.map((e,t)=>(0,$.jsx)(`div`,{className:`rounded-md border px-2 py-1`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--surface-elevated)`},children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`typography-micro shrink-0`,style:{color:`var(--status-error)`},children:[`[`,e.line,`:`,e.character,`]`]}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground whitespace-pre-wrap break-words`,children:e.message})]})},`${x.displayPath}:${e.line}:${e.character}:${t}`))}),x.remaining>0?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:o(`chat.toolPart.moreErrors`,{count:x.remaining})}):null]})]}):null;if(e.tool===`question`){if(t.status===`completed`&&h){let e=HC(g);if(e&&e.length>0)return O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.question}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground whitespace-pre-wrap`,children:e.answer})]},t))}),{maxHeightClass:`max-h-[40vh]`})}if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:ec(t.error)})]});let e=p;return e?.questions&&Array.isArray(e.questions)&&e.questions.length>0?O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.questions.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[e.header?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:ec(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:ec(e.question)}),Array.isArray(e.options)&&e.options.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:e.options.map(e=>(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-muted/30 border border-border/30 text-muted-foreground`,children:ec(e.label)},ec(e.label)))}):null]},t))}),{maxHeightClass:`max-h-[40vh]`}):(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:o(`chat.toolPart.awaitingResponse`)})}return e.tool===`task`&&h?O((0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Mo,{content:ec(g),variant:`tool`,onShowPopup:a})})):(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`||e.tool===`write`)&&(y.length>0||x)?O((0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[y.map(e=>(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:e.renderMode===`diff`?(0,$.jsx)(gw,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(mw,{diff:e.patch})},e.id)),n()]}),{className:`p-1`}):e.tool===`write`&&x?O((0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:n()}),{className:`p-1`}):w?null:h&&g.trim()?O((0,$.jsx)(YC,{output:ec(g),part:e,metadata:f,input:p,isMobile:i}),{className:e.tool===`bash`?`p-1 rounded-none`:`p-1`,maxHeightClass:e.tool===`bash`?`max-h-[46vh]`:void 0}):O((0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground/70`,children:o(`chat.toolPart.noOutputProduced`)}),{maxHeightClass:`max-h-60`})};if(T){if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:RS(i,`todo-error`),children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-none border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:t.error})]});let n=ic(E,void 0,{listClassName:tc});return(0,$.jsx)(`div`,{className:RS(i,`todo`),children:O(n??(0,$.jsx)(YC,{output:E,part:e,metadata:f,input:p,isMobile:i}),Gs)})}return(0,$.jsx)(`div`,{className:RS(i,`default`,e.tool===`bash`),children:e.tool===`question`?k():(0,$.jsxs)($.Fragment,{children:[C?(0,$.jsx)(`div`,{children:O(e.tool===`bash`?(0,$.jsx)(`pre`,{className:`tool-input-text whitespace-pre-wrap break-words typography-code text-muted-foreground/90 m-0 p-0`,style:i?{lineHeight:BS}:void 0,children:S}):w&&D?(0,$.jsx)(gw,{diff:D,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(`blockquote`,{className:`tool-input-text m-0 whitespace-pre-wrap break-words typography-meta italic text-muted-foreground/70`,children:S}),{maxHeightClass:w&&D&&r?`max-h-[50vh]`:`max-h-60`,className:e.tool===`bash`?`tool-input-surface p-0 rounded-none`:`tool-input-surface`})}):null,t.status===`completed`&&`output`in t&&(0,$.jsx)(`div`,{children:k()}),t.status===`error`&&`error`in t&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:ec(t.error)})]})]})})});_w.displayName=`ToolExpandedContent`;var vw=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:c=!0})=>{let l=e.state,u=s(e=>e.showToolFileIcons),d=s(e=>e.showSubagentTaskDetails),f=s(e=>e.openContextPanelTab),p=s(e=>e.openContextDiff),m=s(e=>e.openContextToolDiff),h=s(e=>e.navigateToDiff),{t:g}=ot(),_=is(),v=Qr(e=>e.setCurrentSession),y=_h(),b=Qm(),x=b.directory||_||``,S=bC(e.tool),C=S===`task`,w=S===`todowrite`||S===`todoread`,T=wC(S),E=l?.status,D=sC(e),O=E===`error`||E===`failed`,[k,A]=Z.useState(!D),j=Z.useRef(e.id),M=Z.useRef(``);Z.useEffect(()=>{j.current!==e.id&&(j.current=e.id,M.current=``,A(!D))},[D,e.id]),Z.useEffect(()=>{D||A(!0)},[D]),Z.useEffect(()=>{if(!D||O||!x||!SC.has(S))return;let t=`${e.id}:${E??`unknown`}`;M.current!==t&&(M.current=t,hi.requestGitRefresh({directory:x}))},[x,O,D,S,e.id,E]);let N=D||C,P=Z.useRef(a);P.current=a;let F=Z.useRef(null);Z.useLayoutEffect(()=>{if(C||T)return;let e=F.current;if(!e){N&&P.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,N&&P.current?.(`structural`)},[n,T,C,N]);let I=l,L=I.metadata,R=e.metadata,z=I.input,B=I.time,[V,H]=Z.useState(()=>({start:typeof B?.start==`number`?B.start:void 0,end:typeof B?.end==`number`?B.end:void 0})),[U,W]=Z.useState(void 0),[ee,G]=Z.useState(void 0);Z.useEffect(()=>{H({}),W(void 0),G(void 0)},[e.id]),Z.useEffect(()=>{D||typeof B?.start!=`number`&&W(e=>e??Date.now())},[D,B?.start]),Z.useEffect(()=>{H(e=>{let t={...e},n=!1;return typeof B?.start==`number`&&(typeof e.start!=`number`||B.start<e.start)&&(t.start=B.start,n=!0),typeof B?.end==`number`&&(typeof e.end!=`number`||B.end>e.end)&&(t.end=B.end,n=!0),n?t:e})},[B?.end,B?.start]);let K=Z.useMemo(()=>{if(typeof U==`number`)return U;let e=[V.start,B?.start].filter(e=>typeof e==`number`);if(e.length!==0)return Math.min(...e)},[U,V.start,B?.start]),te=Z.useMemo(()=>typeof I.output==`string`?I.output:void 0,[I.output]),ne=Z.useMemo(()=>Cx(te),[te]),re=Z.useMemo(()=>{if(!C)return[];let e=L,t=Sx(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:ne.summaryEntries},[C,L,ne.summaryEntries]),ie=D&&re.length>0,ae=Z.useMemo(()=>C?bx(L)||bx(I)||bx(z)||bx(R)||(ne.sessionId?ne.sessionId:wx(te)):void 0,[z,C,L,ne.sessionId,R,I,te]),oe=Z.useMemo(()=>C&&D&&!!(Tx(L)===`running`||Tx(I)===`running`||Tx(R)===`running`||ne.status===`running`||Ox(te)),[C,D,L,ne.status,R,I,te]),[se,ce]=Z.useState(!0),le=C&&(!D&&k||oe&&se),ue=le?ae:void 0,de=le&&!ae?e.sessionID:void 0,fe=ue??de,pe=Tr(ue??``,x),me=Tr(de??``,x),he=ei(fe??``,x),ge=Fi(x,le),_e=!!(oe&&pe?.type===`idle`&&typeof K==`number`&&(typeof he==`number`&&K<=he||typeof ge==`number`&&K<=ge));Z.useEffect(()=>{_e&&ce(!1)},[_e]);let ve=!!(oe&&se&&ae&&pe?.type!==`idle`),ye=!d||ie?``:ae??``,be=di(ye,x);Ut(ye,x);let xe=Z.useMemo(()=>!C||!ae||!Array.isArray(be)||be.length===0?[]:Fx(be),[be,C,ae]);Z.useEffect(()=>{if(typeof B?.end==`number`||typeof V.end==`number`){G(void 0);return}typeof K==`number`&&D&&G(e=>e??Date.now())},[K,D,V.end,B?.end]);let Se=D?V.end??B?.end??ee:void 0,Ce=!D&&k,we=Gx({isTaskTool:C,isFinalized:D,taskSessionId:ae,childSessionStatus:pe,parentSessionStatus:me,statusObservedAt:he,taskStartedAt:K,statusSnapshotAt:ge}),Te=Ce&&!we||ve,Ee=!!(C&&Te&&!O);Z.useEffect(()=>{we&&A(!1)},[we]);let De=D,Oe=Z.useMemo(()=>xe.length>0?xe:re,[xe,re]),ke=Z.useMemo(()=>Oe.map($C).join(`\0`),[Oe]),Ae=Z.useRef(null);Z.useEffect(()=>{if(!C){Ae.current=null;return}let e=Ae.current;Ae.current=ke,e!==null&&e!==ke&&Oe.length!==0&&P.current?.(`structural`)},[C,Oe.length,ke]);let je=Z.useMemo(()=>S===`edit`||S===`multiedit`||S===`apply_patch`?OC(L):null,[L,S]),Me=Z.useMemo(()=>S===`write`?kC(z):null,[z,S]),Ne=S===`apply_patch`&&Array.isArray(L?.files)&&(L?.files).length>1,Pe=S===e.tool?e:{...e,tool:S},Fe=UC(Pe,l,x),Ie=GC(Pe,l,x),Le=$o(S||e.tool,g),Re=lr(C?ae:void 0,x),ze=lr(C?ae:void 0),Be=C?gC(z,L,R,Re??ze):void 0,Ve=Wx({isTaskTool:C,isFinalized:D,taskSessionId:ae,taskAgentName:Be,displayName:Le,delegatingLabel:g(`chat.assistantStatus.delegatingTask`),formatName:_C}),He=C&&Ve.isDelegating,Ue=Ve.title,We=typeof e.sessionID==`string`?e.sessionID.trim():``,Ge=Z.useMemo(()=>{if(!C||!We)return null;let n=typeof ae==`string`&&ae.trim().length>0?ae.trim():void 0,r=typeof e.id==`string`&&e.id.trim().length>0?e.id.trim():void 0,i=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():typeof t==`string`&&t.trim().length>0?t.trim():void 0;return{sessionID:We,...r?{partID:r}:{},...i?{messageID:i}:{},...x?{directory:x}:{},directoryPresent:!!x,childSessionPresent:!!n,...n?{childSessionID:n}:{},...E?{toolStatus:E}:{},finalized:D,backgroundRunning:ve,effectiveActive:Te,suppressLoading:we,delegating:He,childStatus:Li(pe),parentStatus:Li(me),idleConfirmed:_e,navigateCapability:b.capabilities.navigateNestedSession,surfaceKind:b.kind,...typeof K==`number`?{taskStartedAt:K}:{},...typeof he==`number`?{statusObservedAt:he}:{},...typeof ge==`number`?{statusSnapshotAt:ge}:{}}},[_e,pe,x,Te,K,He,D,C,t,We,me,e.id,e.messageID,b.capabilities.navigateNestedSession,b.kind,E,he,ge,we,ve,ae]),Ke=Ge?xr(Ge):``,qe=Z.useRef(Ge);qe.current=Ge,Z.useEffect(()=>{let e=qe.current;!e||!Ke||yi(e)},[Ke]);let Je=q((e,t)=>{let n=qe.current;n&&Mr({...n,opened:e,clickSource:t})}),Ye=He?{"data-delegating":`true`}:void 0,Xe=Z.useMemo(()=>{if(S===`bash`||S===`apply_patch`||S===`lsp`||Fe&&(S===`apply_patch`||S===`edit`||S===`multiedit`||S===`write`))return null;let e=I.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=z?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Fe,S,I,z]),Ze=Z.useContext(Oo),Qe=Z.useRef(!1),$e=q(e=>{let t=e??ae;return!t||!x?!1:(Qe.current=!1,eh(b,t,x,()=>{if(!ci({sessionId:t,directory:x})){if(i||Ze?.runtime.isVSCode){v(t,x);return}f(x,{mode:`chat`,dedupeKey:`session:${t}`,label:Ue,readOnly:!0})}}))});Z.useEffect(()=>{!Qe.current||!ae||Je($e(ae),`queued-effect`)},[ae]);let et=n=>{if(C){n.stopPropagation();let e=b.capabilities.navigateNestedSession,t=e?$e():!1;Je(t,`row`),e&&!t&&(Qe.current=!0);return}if(T&&!x)return;let a,o,c;if(S===`edit`||S===`multiedit`||S===`apply_patch`)a=zC(S,z,L),o=MC(S,L,typeof a==`string`?a:void 0),typeof a==`string`&&(c=NC(S,L,a));else if([`write`,`create`,`file_write`].includes(S))a=z?.filePath||z?.file_path||z?.path||L?.filePath||L?.file_path||L?.path,o=1,typeof a==`string`&&typeof z?.content==`string`&&(c=jC(a,z.content));else if(S===`lsp`){a=z?.filePath||z?.file_path||z?.path;let e=z?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=vo(x,a)||(a.startsWith(`/`)?a:x.endsWith(`/`)?x+a:`${x}/${a}`);if(T){let e=FC(r,x),n=(c?PS(S,L,c,e,e=>FC(e,x)):[]).map(e=>({path:e.title,patch:e.patch}));if(Ze?.runtime.isVSCode&&Ze.editor&&c){let t=`${e} (changes)`;Ze.editor.openDiff(``,r,t,{line:o,patch:c});return}if(So(r,x)){y?n.length>0?y.openToolDiff({diffPath:e,patches:n,targetLine:o}):S===`apply_patch`?y.openTurnDiff(t,b.sessionId):y.openChanges({diffPath:e,staged:!1,targetLine:o}):i?h(e,!1,`turn`,o):n.length>0?m(x,e,n,o,t,b.sessionId):p(x,e,!1,`turn`,o,t,b.sessionId);return}if(Ze?.editor){Ze.editor.openFile(r,o);return}as(r,x).then(()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(S===`lsp`){if(Ze?.editor){Ze.editor.openFile(r,o);return}let e=()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!So(r,x)){as(r,x).then(e);return}e();return}if(Ze?.editor){if(Ze.runtime.isVSCode&&c&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${FC(r,x)} (changes)`;Ze.editor.openDiff(``,r,e,{line:o,patch:c});return}Ze.editor.openFile(r,o);return}}if(S===`apply_patch`&&y){n.stopPropagation(),y.openTurnDiff(t,b.sessionId);return}if(S===`apply_patch`&&x&&!y&&!i&&!Ze?.runtime.isVSCode){n.stopPropagation(),f(x,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:b.sessionId});return}T||r(e.id)},tt=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),et(e))},nt=!C&&O?cw:lw,rt=!C&&O?uw:dw,it=C&&d&&(Oe.length>0||Te||De||!!ae),at=!C&&!T&&n;return!De&&!Ce&&!C?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,kp,C&&`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Ne?`flex-wrap items-start`:`items-center`),"data-mobile-press-feedback":`soft`,...Ye,onClick:et,onKeyDown:tt,role:`button`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5`,Ne?`w-full min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`:`items-center flex-shrink-0`),children:[(0,$.jsx)(`div`,{className:Y(`relative flex-shrink-0`,i?`size-4`:`size-3.5`),children:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,style:C&&Ve.showAvatar?void 0:nt,children:C&&Ve.showAvatar?(0,$.jsx)(ea,{name:e.id||Be||`subagent`,size:14,label:Ue}):Te?(0,$.jsx)(qS,{isMobile:i,className:`text-[var(--tools-icon)]`,label:g(`chat.assistantStatus.usingTool`,{tool:Ue})}):fx(S||e.tool)})}),Ne?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(dC,`flex-shrink-0`),style:rt,title:Le,children:Le}),yC(L,c,u)]}):(0,$.jsxs)($.Fragment,{children:[Ee?(0,$.jsx)(`span`,{className:Y(dC,`shrink-0 whitespace-nowrap animate-text-shimmer`),style:{color:`var(--tools-title)`,"--oc-text-shimmer-base":`var(--tools-title)`},title:Ue,children:Ue}):(0,$.jsx)(`span`,{className:Y(dC,`shrink-0 whitespace-nowrap`),style:rt,title:Ue,children:Ue}),S===`bash`&&typeof K==`number`?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,fC),children:(0,$.jsx)(EC,{start:K,end:typeof Se==`number`?Se:void 0,active:!!(Te&&typeof Se!=`number`)})}):null]})]}),!Ne&&(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,fC),style:{color:`var(--tools-description)`},children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[Xe&&(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,fC,Ee&&`animate-text-shimmer`),style:{color:`var(--tools-description)`,...Ee?{"--oc-text-shimmer-base":`var(--tools-description)`}:{opacity:.8}},title:Xe,children:Xe}),!Xe&&S===`lsp`&&Fe?pw(Fe,c,!1,u):null,!Xe&&S!==`lsp`&&Ie&&(Fe&&Ie===Fe?pw(Fe,c,!1,u):(0,$.jsx)(dx,{variant:c?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,fC),style:{color:`var(--tools-description)`},title:Ie,children:Ie})),je&&(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,je.added]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,je.removed]})]}),Me&&(0,$.jsx)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,Me]})})]})}),!T&&(!C||d)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:C?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),it?(0,$.jsx)(rw,{entries:Oe,isExpanded:n,isMobile:i,output:te,sessionId:ae,onShowPopup:o,input:z,animateTailText:c,isActive:Te}):null,!C&&!T&&n?(0,$.jsx)(`div`,{ref:F,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:at?(0,$.jsxs)(`div`,{className:w?`relative ml-0.5 pl-1.5`:LS,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),(0,$.jsx)(_w,{part:e,state:l,currentDirectory:x,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},yw=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1,error:void 0})}componentDidCatch(e){}render(){if(!this.state.hasError)return this.props.children;let e=this.state.error?.message;return(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1.5 min-w-0`,Dp),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:cw,children:fx(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(dC,`flex-shrink-0`),style:uw,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(fC,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},bw=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=ot(),r=IS(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=bC(e.part.tool)||`tool`,i=$o(a,n),t[0]=e.part.tool,t[1]=n,t[2]=i,t[3]=a):(i=t[2],a=t[3]);let o=i,s;t[4]!==r||t[5]!==e.part.id?(s=()=>!r||vC.get(e.part.id)===!0,t[4]=r,t[5]=e.part.id,t[6]=s):s=t[6];let[c,l]=Z.useState(s),u,d;if(t[7]!==r||t[8]!==c||t[9]!==e.part.id?(u=()=>{if(!(!r||c))return ls(()=>{vC.set(e.part.id,!0,e.part.id.length*2+8),Z.startTransition(()=>{l(!0)})})},d=[r,c,e.part.id],t[7]=r,t[8]=c,t[9]=e.part.id,t[10]=u,t[11]=d):(u=t[10],d=t[11]),Z.useEffect(u,d),!c){let e,n,r;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(`flex min-w-0 items-center gap-2`,Dp),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(dC,`shrink-0 text-muted-foreground`),t[12]=e,t[13]=n,t[14]=r):(e=t[12],n=t[13],r=t[14]);let i;t[15]===o?i=t[16]:(i=(0,$.jsx)(`span`,{className:r,children:o}),t[15]=o,t[16]=i);let a;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`span`,{className:`h-3 w-24 min-w-0 rounded bg-muted/40`,"aria-hidden":`true`}),t[17]=a):a=t[17];let s;return t[18]===i?s=t[19]:(s=(0,$.jsxs)(`div`,{className:e,children:[n,i,a]}),t[18]=i,t[19]=s),s}let f;t[20]===n?f=t[21]:(f=n(`chat.toolPart.error`),t[20]=n,t[21]=f);let p;t[22]===e?p=t[23]:(p=(0,$.jsx)(vw,{...e}),t[22]=e,t[23]=p);let m;return t[24]!==o||t[25]!==e.part||t[26]!==f||t[27]!==p||t[28]!==a?(m=(0,$.jsx)(yw,{displayName:o,errorLabel:f,resetKey:e.part,toolName:a,children:p}),t[24]=o,t[25]=e.part,t[26]=f,t[27]=p,t[28]=a,t[29]=m):m=t[29],m},(e,t)=>$x([e.part],[t.part])&&e.messageId===t.messageId&&e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.alwaysShowActions===t.alwaysShowActions&&e.onContentChange===t.onContentChange&&e.onShowPopup===t.onShowPopup&&e.animateTailText===t.animateTailText);function xw(e){return e.stopPropagation()}function Sw(e){return e.stopPropagation()}function Cw(e){return e.stopPropagation()}function ww(e){return e.setCurrentSession}function Tw(e){return e.openContextPanelTab}function Ew(e){return e.showToolFileIcons}function Dw(e){return e.stopPropagation()}function Ow(e){return e.stopPropagation()}function kw(e){return!e}var Aw=(e,t,n)=>{let r=t-e;return Math.max(0,n-r)},jw=e=>{e.timer&&=(clearTimeout(e.timer),null)},Mw=({text:e,isStreaming:t,throttleMs:n=fs(ze()).textThrottleMs,identityKey:r})=>{let[i,a]=Z.useState(e),o=Z.useRef(e),s=Z.useRef(i),c=Z.useRef({timer:null,pendingText:e,lastEmitAt:0});return Z.useEffect(()=>{o.current=e},[e]),Z.useEffect(()=>{s.current=i},[i]),Z.useEffect(()=>{let e=c.current;jw(e),e.pendingText=o.current,e.lastEmitAt=0,a(o.current)},[r]),Z.useEffect(()=>{let r=c.current;r.pendingText=e;let i=s.current,o=t&&i.length>e.length?i:e;if(!t){jw(r),r.lastEmitAt=Date.now(),a(o);return}let l=Date.now(),u=Aw(r.lastEmitAt,l,n);if(u<=0){jw(r),r.lastEmitAt=l,a(o);return}return jw(r),r.timer=setTimeout(()=>{r.timer=null,r.lastEmitAt=Date.now(),a(e=>t&&e.length>r.pendingText.length?e:r.pendingText)},u),()=>{jw(r)}},[t,e,n]),Z.useEffect(()=>{let e=c.current;return()=>{jw(e)}},[]),i},Nw=e=>e.isStreaming?e.throttledTextContent:e.textContent,Pw=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,Fw=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=ot(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(Iw)],t[2]=n.highlights,t[3]=n.subject,t[4]=e):e=t[4],l=e.join(`
6562
6562
  `);break bb0}let e;t[5]!==n.body||t[6]!==n.title?(e=[n.title,n.body].filter(Boolean),t[5]=n.body,t[6]=n.title,t[7]=e):e=t[7],l=e.join(`
6563
6563
 
6564
- `)}let u=l,d;t[8]!==u||t[9]!==n.raw?(d=async()=>{(await lt(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=K(d),p;t[11]!==n.kind||t[12]!==r?(p=n.kind===`commit`?r(`chat.generatedResult.commit.title`):r(`chat.generatedResult.pullRequest.title`),t[11]=n.kind,t[12]=r,t[13]=p):p=t[13];let m;t[14]===p?m=t[15]:(m=(0,$.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:p}),t[14]=p,t[15]=m);let h;t[16]===f?h=t[17]:(h=()=>{f()},t[16]=f,t[17]=h);let g;t[18]!==i||t[19]!==r?(g=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[18]=i,t[19]=r,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==r?(_=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[21]=i,t[22]=r,t[23]=_):_=t[23];let v;t[24]===i?v=t[25]:(v=i?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`}),t[24]=i,t[25]=v);let y;t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==_?(y=(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`xs`,onClick:h,title:g,"aria-label":_,className:`text-muted-foreground hover:text-foreground md:opacity-0 md:group-hover:opacity-100`,children:v}),t[26]=v,t[27]=h,t[28]=g,t[29]=_,t[30]=y):y=t[30];let b;t[31]!==y||t[32]!==m?(b=(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 px-3 py-1.5`,children:[m,y]}),t[31]=y,t[32]=m,t[33]=b):b=t[33];let x;t[34]!==n.body||t[35]!==n.highlights||t[36]!==n.kind||t[37]!==n.subject||t[38]!==n.title||t[39]!==r?(x=(0,$.jsx)(`div`,{className:`space-y-3 px-3 py-3`,children:n.kind===`commit`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n.subject}),n.highlights.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-sm text-muted-foreground`,children:n.highlights.map(Lw)}):null]}):(0,$.jsxs)($.Fragment,{children:[n.title?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.titleLabel`)}),(0,$.jsx)(`div`,{className:`mt-1 typography-ui-label text-foreground`,children:n.title})]}):null,n.body?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.bodyLabel`)}),(0,$.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words text-sm leading-relaxed text-muted-foreground font-sans`,children:n.body})]}):null]})}),t[34]=n.body,t[35]=n.highlights,t[36]=n.kind,t[37]=n.subject,t[38]=n.title,t[39]=r,t[40]=x):x=t[40];let S;return t[41]!==b||t[42]!==x?(S=(0,$.jsxs)(`div`,{"data-component":`generated-json-result`,className:`my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]`,children:[b,x]}),t[41]=b,t[42]=x,t[43]=S):S=t[43],S};function Iw(e){return`- ${e}`}function Lw(e,t){return(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`-`}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`)}var Rw=e=>{let t=e.trim(),n=[],r=t.match(/^```(?:json)?\s*([\s\S]*?)```$/i);r?.[1]&&n.push(r[1].trim()),t.startsWith(`{`)&&t.endsWith(`}`)&&n.push(t);let i=[];for(let e of n)try{let t=JSON.parse(e);t&&typeof t==`object`&&!Array.isArray(t)&&i.push(t)}catch{}return i},zw=e=>{for(let t of Rw(e)){let e=typeof t.subject==`string`?t.subject.trim():``,n=Array.isArray(t.highlights)?t.highlights.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).slice(0,3):[];if(e)return{kind:`commit`,subject:e,highlights:n,raw:JSON.stringify({subject:e,highlights:n},null,2)};let r=typeof t.title==`string`?t.title.trim():``,i=typeof t.body==`string`?t.body.trim():``;if(r||i)return{kind:`pr`,title:r,body:i,raw:JSON.stringify({title:r,body:i},null,2)}}return null},Bw=Z.memo(e=>{let t=(0,Q.c)(32),{part:n,sessionId:r,messageId:i,streamPhase:a,chatRenderMode:o,allowSortedFinalStreaming:s,hasStreamingHapticLifecycle:c,onShowPopup:l}=e,u=o===void 0?`live`:o,d=s!==void 0&&s,f=c!==void 0&&c,p=n,m=[typeof p.text==`string`?p.text:``,typeof p.content==`string`?p.content:``,typeof p.value==`string`?p.value:``].reduce(Vw,``),h=(u===`live`||d)&&(a===`streaming`||a===`cooldown`);Le(`ui.assistant_text_part.render`),h&&Le(`ui.assistant_text_part.render.streaming`);let g=Nw({textContent:m,throttledTextContent:Mw({text:m,isStreaming:h,identityKey:`${i}:${n.id??`text`}`}),isStreaming:h}),_=`${i}:${n.id??`text`}`,v=Z.useRef(null),y,b;t[0]!==g||t[1]!==_||t[2]!==f||t[3]!==i||t[4]!==n.id||t[5]!==n.type||t[6]!==r?(y=()=>{if(!xn())return;let e=n.type===`text`||n.type===`reasoning`,t=Et(v.current,{identity:_,content:g,isActive:f&&e,mode:n.type===`reasoning`?`appearance`:`changes`});v.current=t.nextState,!(!t.shouldEmit||!r)&&Nt({sessionID:r,messageID:i,partID:n.id,kind:n.type===`reasoning`?`thinking`:`text`})},b=[g,_,f,i,n.id,n.type,r],t[0]=g,t[1]=_,t[2]=f,t[3]=i,t[4]=n.id,t[5]=n.type,t[6]=r,t[7]=y,t[8]=b):(y=t[7],b=t[8]),Z.useEffect(y,b),Ie(`ui.assistant_text_part.display_len`,g.length);let x=p.time,S=!!(x&&x.end!==void 0);if(n.type!==`text`&&n.type!==`reasoning`||!Pw({displayTextContent:g,isFinalized:S}))return null;let C;t[9]!==g||t[10]!==S||t[11]!==h?(C=!h&&S?zw(g):null,t[9]=g,t[10]=S,t[11]=h,t[12]=C):C=t[12];let w=C;if(w){let e=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,r=n.id||`${i}-text`,a;t[13]===w?a=t[14]:(a=(0,$.jsx)(Fw,{result:w}),t[13]=w,t[14]=a);let o;return t[15]!==e||t[16]!==r||t[17]!==a?(o=(0,$.jsx)(`div`,{className:e,children:a},r),t[15]=e,t[16]=r,t[17]=a,t[18]=o):o=t[18],o}let T=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,E=n.id||`${i}-text`,D=u===`sorted`&&!d,O=n.type===`reasoning`?`reasoning`:`assistant`,k;t[19]!==g||t[20]!==S||t[21]!==h||t[22]!==i||t[23]!==l||t[24]!==n||t[25]!==O||t[26]!==D?(k=(0,$.jsx)(No,{content:g,part:n,messageId:i,isAnimated:!1,isStreaming:h,disableStreamAnimation:D,variant:O,enableFileReferences:S,onShowPopup:l}),t[19]=g,t[20]=S,t[21]=h,t[22]=i,t[23]=l,t[24]=n,t[25]=O,t[26]=D,t[27]=k):k=t[27];let A;return t[28]!==k||t[29]!==T||t[30]!==E?(A=(0,$.jsx)(`div`,{className:T,children:k},E),t[28]=k,t[29]=T,t[30]=E,t[31]=A):A=t[31],A});function Vw(e,t){return t.length>e.length?t:e}var Hw=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,Uw=Y(`typography-meta font-medium`,Hw),Ww=Y(`typography-meta`,Hw),Gw=e=>typeof e!=`string`||e.trim().length===0?``:e.split(`
6564
+ `)}let u=l,d;t[8]!==u||t[9]!==n.raw?(d=async()=>{(await ct(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=q(d),p;t[11]!==n.kind||t[12]!==r?(p=n.kind===`commit`?r(`chat.generatedResult.commit.title`):r(`chat.generatedResult.pullRequest.title`),t[11]=n.kind,t[12]=r,t[13]=p):p=t[13];let m;t[14]===p?m=t[15]:(m=(0,$.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:p}),t[14]=p,t[15]=m);let h;t[16]===f?h=t[17]:(h=()=>{f()},t[16]=f,t[17]=h);let g;t[18]!==i||t[19]!==r?(g=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[18]=i,t[19]=r,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==r?(_=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[21]=i,t[22]=r,t[23]=_):_=t[23];let v;t[24]===i?v=t[25]:(v=i?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`}),t[24]=i,t[25]=v);let y;t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==_?(y=(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`xs`,onClick:h,title:g,"aria-label":_,className:`text-muted-foreground hover:text-foreground md:opacity-0 md:group-hover:opacity-100`,children:v}),t[26]=v,t[27]=h,t[28]=g,t[29]=_,t[30]=y):y=t[30];let b;t[31]!==y||t[32]!==m?(b=(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 px-3 py-1.5`,children:[m,y]}),t[31]=y,t[32]=m,t[33]=b):b=t[33];let x;t[34]!==n.body||t[35]!==n.highlights||t[36]!==n.kind||t[37]!==n.subject||t[38]!==n.title||t[39]!==r?(x=(0,$.jsx)(`div`,{className:`space-y-3 px-3 py-3`,children:n.kind===`commit`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n.subject}),n.highlights.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-sm text-muted-foreground`,children:n.highlights.map(Lw)}):null]}):(0,$.jsxs)($.Fragment,{children:[n.title?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.titleLabel`)}),(0,$.jsx)(`div`,{className:`mt-1 typography-ui-label text-foreground`,children:n.title})]}):null,n.body?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.bodyLabel`)}),(0,$.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words text-sm leading-relaxed text-muted-foreground font-sans`,children:n.body})]}):null]})}),t[34]=n.body,t[35]=n.highlights,t[36]=n.kind,t[37]=n.subject,t[38]=n.title,t[39]=r,t[40]=x):x=t[40];let S;return t[41]!==b||t[42]!==x?(S=(0,$.jsxs)(`div`,{"data-component":`generated-json-result`,className:`my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]`,children:[b,x]}),t[41]=b,t[42]=x,t[43]=S):S=t[43],S};function Iw(e){return`- ${e}`}function Lw(e,t){return(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`-`}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`)}var Rw=e=>{let t=e.trim(),n=[],r=t.match(/^```(?:json)?\s*([\s\S]*?)```$/i);r?.[1]&&n.push(r[1].trim()),t.startsWith(`{`)&&t.endsWith(`}`)&&n.push(t);let i=[];for(let e of n)try{let t=JSON.parse(e);t&&typeof t==`object`&&!Array.isArray(t)&&i.push(t)}catch{}return i},zw=e=>{for(let t of Rw(e)){let e=typeof t.subject==`string`?t.subject.trim():``,n=Array.isArray(t.highlights)?t.highlights.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).slice(0,3):[];if(e)return{kind:`commit`,subject:e,highlights:n,raw:JSON.stringify({subject:e,highlights:n},null,2)};let r=typeof t.title==`string`?t.title.trim():``,i=typeof t.body==`string`?t.body.trim():``;if(r||i)return{kind:`pr`,title:r,body:i,raw:JSON.stringify({title:r,body:i},null,2)}}return null},Bw=Z.memo(e=>{let t=(0,Q.c)(32),{part:n,sessionId:r,messageId:i,streamPhase:a,chatRenderMode:o,allowSortedFinalStreaming:s,hasStreamingHapticLifecycle:c,onShowPopup:l}=e,u=o===void 0?`live`:o,d=s!==void 0&&s,f=c!==void 0&&c,p=n,m=[typeof p.text==`string`?p.text:``,typeof p.content==`string`?p.content:``,typeof p.value==`string`?p.value:``].reduce(Vw,``),h=(u===`live`||d)&&(a===`streaming`||a===`cooldown`);Ie(`ui.assistant_text_part.render`),h&&Ie(`ui.assistant_text_part.render.streaming`);let g=Nw({textContent:m,throttledTextContent:Mw({text:m,isStreaming:h,identityKey:`${i}:${n.id??`text`}`}),isStreaming:h}),_=`${i}:${n.id??`text`}`,v=Z.useRef(null),y,b;t[0]!==g||t[1]!==_||t[2]!==f||t[3]!==i||t[4]!==n.id||t[5]!==n.type||t[6]!==r?(y=()=>{if(!bn())return;let e=n.type===`text`||n.type===`reasoning`,t=Tt(v.current,{identity:_,content:g,isActive:f&&e,mode:n.type===`reasoning`?`appearance`:`changes`});v.current=t.nextState,!(!t.shouldEmit||!r)&&Mt({sessionID:r,messageID:i,partID:n.id,kind:n.type===`reasoning`?`thinking`:`text`})},b=[g,_,f,i,n.id,n.type,r],t[0]=g,t[1]=_,t[2]=f,t[3]=i,t[4]=n.id,t[5]=n.type,t[6]=r,t[7]=y,t[8]=b):(y=t[7],b=t[8]),Z.useEffect(y,b),Fe(`ui.assistant_text_part.display_len`,g.length);let x=p.time,S=!!(x&&x.end!==void 0);if(n.type!==`text`&&n.type!==`reasoning`||!Pw({displayTextContent:g,isFinalized:S}))return null;let C;t[9]!==g||t[10]!==S||t[11]!==h?(C=!h&&S?zw(g):null,t[9]=g,t[10]=S,t[11]=h,t[12]=C):C=t[12];let w=C;if(w){let e=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,r=n.id||`${i}-text`,a;t[13]===w?a=t[14]:(a=(0,$.jsx)(Fw,{result:w}),t[13]=w,t[14]=a);let o;return t[15]!==e||t[16]!==r||t[17]!==a?(o=(0,$.jsx)(`div`,{className:e,children:a},r),t[15]=e,t[16]=r,t[17]=a,t[18]=o):o=t[18],o}let T=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,E=n.id||`${i}-text`,D=u===`sorted`&&!d,O=n.type===`reasoning`?`reasoning`:`assistant`,k;t[19]!==g||t[20]!==S||t[21]!==h||t[22]!==i||t[23]!==l||t[24]!==n||t[25]!==O||t[26]!==D?(k=(0,$.jsx)(No,{content:g,part:n,messageId:i,isAnimated:!1,isStreaming:h,disableStreamAnimation:D,variant:O,enableFileReferences:S,onShowPopup:l}),t[19]=g,t[20]=S,t[21]=h,t[22]=i,t[23]=l,t[24]=n,t[25]=O,t[26]=D,t[27]=k):k=t[27];let A;return t[28]!==k||t[29]!==T||t[30]!==E?(A=(0,$.jsx)(`div`,{className:T,children:k},E),t[28]=k,t[29]=T,t[30]=E,t[31]=A):A=t[31],A});function Vw(e,t){return t.length>e.length?t:e}var Hw=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,Uw=Y(`typography-meta font-medium`,Hw),Ww=Y(`typography-meta`,Hw),Gw=e=>typeof e!=`string`||e.trim().length===0?``:e.split(`
6565
6565
  `).map(e=>e.replace(/^>\s?/,``).trimEnd()).filter(e=>e.trim().length>0).join(`
6566
- `).trim(),Kw=80,qw=200,Jw={duration:.2,ease:`easeOut`},Yw=e=>e.replace(/<!--\s*-->/g,``).replace(/```[\w]*\n?([\s\S]*?)```/g,(e,t)=>t.trim()).replace(/`([^`]+)`/g,`$1`).replace(/\*{1,3}([^*]+)\*{1,3}/g,`$1`).replace(/_{1,3}([^_]+)_{1,3}/g,`$1`).replace(/^#{1,6}\s+/gm,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^>\s?/gm,``).replace(/^[-*_]{3,}\s*$/gm,``).trim(),Xw=e=>{if(!e)return``;let t=Yw(e).replace(/\s+/g,` `).trim();if(t.length<=Kw)return t;let n=t.lastIndexOf(` `,Kw),r=n>0?n:Kw;return`${t.substring(0,r).trimEnd()}…`},Zw=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:c})=>{let{t:l}=st(),u=s(e=>e.isMobile),d=typeof i?.end==`number`,f=a&&!d,[p,m]=Z.useState(()=>c===!0?{expanded:!0,source:`user`}:{expanded:f,source:`auto`}),h=p.source===`auto`?f&&p.expanded:p.expanded,[g,_]=Z.useState(c===!0||f),v=Z.useId(),y=Z.useRef(null),b=Z.useRef(null),x=Z.useRef(!1),S=Z.useRef(n);S.current=n;let C=Z.useMemo(()=>Xw(e),[e]),w=l(h?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),T=K(()=>{_(!0),m({expanded:!h,source:`user`}),n?.(`structural`)}),E=K(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())});if(Z.useLayoutEffect(()=>{m(e=>e.source===`user`||e.expanded===f?e:{expanded:f,source:`auto`})},[f]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(h||a){_(!0);return}if(!g)return;if(typeof window>`u`){_(!1);return}let e=window.setTimeout(()=>{_(!1)},qw);return()=>{window.clearTimeout(e)}},[h,a,g]),Z.useLayoutEffect(()=>{let e=y.current;if(!e)return;if(b.current?.stop(),!x.current){if(x.current=!0,!h){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=yc(e,{height:`auto`},Jw);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}}e.style.overflow=`hidden`,h?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,S.current?.(`animation`));let t=yc(e,{height:h?`auto`:`0px`},Jw);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,h?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}},[h]),Z.useEffect(()=>()=>{b.current?.stop(),b.current=null},[]),!e||e.trim().length===0)return null;let D=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(No,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":h,"aria-controls":v,"aria-label":w,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,kp),onClick:T,onKeyDown:E,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,h&&`opacity-0`,!h&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,h&&`opacity-100`,!h&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:h?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,Uw),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--oc-text-shimmer-base":`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(qS,{isMobile:u,className:`block text-[var(--tools-icon)]`})]}):h?(0,$.jsx)(`span`,{className:Uw,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:Uw,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,Ww),style:{color:`var(--tools-description)`},children:!a&&!h&&C?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,Ww),style:{color:`var(--tools-description)`,opacity:.8},title:C,children:C}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),g?(0,$.jsx)(`div`,{ref:y,id:v,"aria-hidden":!h,style:{height:h?`auto`:`0px`,overflow:h?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!h,transform:h?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:D}):(0,$.jsx)(fa,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:D})]})}):null]})},Qw=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=s($w),c=n,l=c.text||c.content||``,u;t[0]===l?u=t[1]:(u=Gw(l),t[0]=l,t[1]=u);let d=u,f=c.time,p=a===void 0||a!==`completed`,m=o===`live`&&p&&typeof f?.end!=`number`,h=`${i}:${n.id??`reasoning`}`,g;t[2]!==m||t[3]!==h||t[4]!==d?(g={text:d,isStreaming:m,identityKey:h},t[2]=m,t[3]=h,t[4]=d,t[5]=g):g=t[5];let _=Mw(g),v=`${i}:${n.id??`reasoning`}`,y=Z.useRef(null),b=n.sessionID,x=p&&typeof f?.end!=`number`,S,C;if(t[6]!==v||t[7]!==x||t[8]!==i||t[9]!==n.id||t[10]!==b||t[11]!==_?(S=()=>{if(!xn())return;let e=Et(y.current,{identity:v,content:_,isActive:x,mode:`appearance`});y.current=e.nextState,!(!e.shouldEmit||!b)&&Nt({sessionID:b,messageID:i,partID:n.id,kind:`thinking`})},C=[v,x,i,n.id,b,_],t[6]=v,t[7]=x,t[8]=i,t[9]=n.id,t[10]=b,t[11]=_,t[12]=S,t[13]=C):(S=t[12],C=t[13]),Z.useEffect(S,C),!_||_.trim().length===0)return null;let w=n.id||`${i}-reasoning`,T;return t[14]!==m||t[15]!==r||t[16]!==w||t[17]!==_||t[18]!==f?(T=(0,$.jsx)(Zw,{text:_,variant:`thinking`,onContentChange:r,blockId:w,time:f,isStreaming:m}),t[14]=m,t[15]=r,t[16]=w,t[17]=_,t[18]=f,t[19]=T):T=t[19],T});function $w(e){return e.chatRenderMode}var eT=(e,t)=>{let n=vo(e,t)||yo(t);return n?So(n,e)?{kind:`diff`,path:_o(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},tT=e=>{let t=s.getState(),n=eT(e.directory,e.filePath);if(n.kind===`file`){as(n.path,e.directory).then(()=>{t.openContextFile(e.directory,n.path,{fileNotice:n.notice}),e.mobile&&t.setRightSidebarOpen(!1)});return}if(e.mobile){t.navigateToDiff(n.path,!1,`turn`),t.setRightSidebarOpen(!1);return}t.openContextDiff(e.directory,n.path,!1,`turn`,void 0,e.turnMessageId,e.sessionId)},nT=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),c=Z.useRef(null),l=Qm(),u=Ee(rT),d=l.directory||u,f=Bs(d),p;if(t[0]!==n||t[1]!==f){bb0:{if(f!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],p=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],p=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&vh.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],p=e;break bb0}p=Sh(e)}t[0]=n,t[1]=f,t[2]=p}else p=t[2];let m=p;if(m.length===0)return null;let h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{let e=c.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=h):h=t[6];let g=h,_;t[7]!==d||t[8]!==l?(_=e=>{if(!d)return;let t=s.getState();tT({directory:d,filePath:e.path,sessionId:l.sessionId,mobile:t.isMobile}),i(!1)},t[7]=d,t[8]=l,t[9]=_):_=t[9];let v=_,y=m.length,b=`${y} file${y===1?``:`s`}`,x=`${b} changed in this turn`,S;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=S):S=t[10];let C;t[11]===b?C=t[12]:(C=(0,$.jsx)(`span`,{className:`message-footer__label`,children:b}),t[11]=b,t[12]=C);let w;t[13]===r?w=t[14]:(w=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=w);let T;t[15]!==x||t[16]!==C||t[17]!==w?(T=(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(_e,{render:(0,$.jsxs)(`button`,{ref:c,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":x,onPointerDownCapture:g,onFocusCapture:g,children:[S,C,w]})})}),t[15]=x,t[16]=C,t[17]=w,t[18]=T):T=t[18];let E;t[19]===b?E=t[20]:(E=(0,$.jsxs)(La,{children:[b,` changed in this turn`]}),t[19]=b,t[20]=E);let D;t[21]!==T||t[22]!==E?(D=(0,$.jsxs)(Ra,{children:[T,E]}),t[21]=T,t[22]=E,t[23]=D):D=t[23];let O=a||void 0,k;t[24]!==m||t[25]!==d||t[26]!==v?(k=(0,$.jsx)(ye,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(ge,{style:Ah,className:`${kh} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(Oh,{files:m,currentDirectory:d,onOpenFile:v})})}),t[24]=m,t[25]=d,t[26]=v,t[27]=k):k=t[27];let A;t[28]!==O||t[29]!==k?(A=(0,$.jsx)(Ce,{container:O,children:k}),t[28]=O,t[29]=k,t[30]=A):A=t[30];let j;return t[31]!==r||t[32]!==D||t[33]!==A?(j=(0,$.jsxs)(ve,{open:r,onOpenChange:i,children:[D,A]}),t[31]=r,t[32]=D,t[33]=A,t[34]=j):j=t[34],j});nT.displayName=`TurnChangedFilesDropdown`;function rT(e){return e.currentDirectory}var iT=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,aT=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},oT=e=>e.type!==`tool`||iT(e)?!1:!aT(e),sT=e=>{let t=0;for(let n of e)oT(n)&&(t+=1);return t},cT=(e,t)=>e===`stop`&&sT(t)===0,lT=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},uT=(e,t,n)=>{if(n||!cT(e,t))return!1;for(let e of t)if(lT(e))return!0;return!1},dT=e=>e===`streaming`||e===`cooldown`,fT=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,pT=e=>e.error||e.isLastAssistantInTurn===!1?!1:cT(e.finish,e.parts)?!0:!dT(e.streamPhase)||typeof e.finish==`string`&&e.finish!==`stop`?!1:sT(e.parts)===0,mT=e=>dT(e.streamPhase)?pT(e):!1,hT=3e4,gT=new Map,_T=new Map;async function vT(e){let t=Date.now(),n=gT.get(e);if(n&&t-n.checkedAt<hT)return n.available;let r=_T.get(e);if(r)return r;let i=(async()=>{try{let t=await V(`/api/tts/status`);if(!t.ok)return gT.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return gT.set(e,{available:n,checkedAt:Date.now()}),n}catch{return gT.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{_T.delete(e)}})();return _T.set(e,i),i}var yT=null;function bT(){return yT||=new(window.AudioContext||window.webkitAudioContext),yT}function xT(e={}){let r=e.enabled??!0,i=e.availabilityMode??`auto`,[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=mi(e=>e.currentProviderId),h=mi(e=>e.currentModelId),g=mi(e=>e.openaiApiKey),_=mi(e=>e.openaiCompatibleUrl),v=mi(e=>e.openaiCompatibleApiKey),y=(0,Z.useCallback)(async()=>{let e=++p.current,t=n(),a=r=>(e===p.current&&n()===t&&c(r),r);if(!r)return a(!1);let o=!!(g&&g.trim().length>0),s=!!(_&&_.trim().length>0);if(i===`openai-compatible`)return a(s);if(o||i===`auto`&&s)return a(!0);try{return a(await vT(t))}catch{return a(!1)}},[i,r,g,_]);(0,Z.useEffect)(()=>{y()},[y]),(0,Z.useEffect)(()=>t(()=>{y()}),[y]);let b=(0,Z.useCallback)(()=>{let e=f.current;if(f.current=null,e?.abort.abort(),d.current){try{d.current.onended=null,d.current.stop()}catch{}d.current=null}o(!1)},[]),x=(0,Z.useCallback)(async()=>{try{let e=bT();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useServerTTS] Failed to unlock audio:`,e)}},[]),S=(0,Z.useCallback)(async(e,t)=>{if(b(),!e.trim()){u(`No text to speak`),t?.onError?.(`No text to speak`);return}u(null);let n={abort:new AbortController};f.current=n;try{let r=bT();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),a=r.createBufferSource();a.buffer=i,a.connect(r.destination),a.start(0);let s=t?.voice||`nova`,c=await V(`/api/tts/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:s,model:t?.model||void 0,speed:t?.speed||.9,instructions:t?.instructions,summarize:!1,providerId:t?.providerId||m||void 0,modelId:t?.modelId||h||void 0,apiKey:t?.baseURL?v||void 0:g||void 0,baseURL:t?.baseURL||void 0}),signal:n.abort.signal});if(f.current!==n)return;if(!c.ok){let e=await c.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${c.status}`)}let l=await(await c.blob()).arrayBuffer();if(f.current!==n)return;let u=await r.decodeAudioData(l);if(f.current!==n)return;let p=r.createBufferSource();p.buffer=u;let _=t?.pitch??1;_!==1&&(p.detune.value=(_-1)*1200);let y=t?.volume??1,b=r.createGain();if(b.gain.value=y,p.connect(b),b.connect(r.destination),d.current=p,p.onended=()=>{f.current===n&&d.current===p&&(o(!1),d.current=null,f.current=null,t?.onEnd?.())},o(!0),t?.onStart?.(),f.current!==n||d.current!==p)return;p.start(0)}catch(e){if(e.name===`AbortError`||f.current!==n)return;let r=e instanceof Error?e.message:`Failed to speak`;console.error(`[useServerTTS] Error:`,r),u(r),t?.onError?.(r),o(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[b,m,h,g,v]);return(0,Z.useEffect)(()=>()=>{b()},[b]),{isPlaying:a,isAvailable:s,error:l,speak:S,stop:b,checkAvailability:y,unlockAudio:x}}var ST=3e4,CT=null,wT=null;async function TT(){return CT&&Date.now()-CT.checkedAt<ST?CT:wT||(wT=(async()=>{try{let e=await V(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return CT=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return CT=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return CT=e,e}finally{wT=null}})(),wT)}var ET=null;function DT(){return ET||=new(window.AudioContext||window.webkitAudioContext),ET}function OT(e={}){let t=e.enabled??!0,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useCallback)(async()=>{try{let e=DT();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useSayTTS] Failed to unlock audio:`,e)}},[]),p=(0,Z.useCallback)(async()=>{if(!t)return a(!1),s([]),!1;try{let e=await TT();return a(e.available),s(e.voices),e.available}catch{return a(!1),s([]),!1}},[t]);(0,Z.useEffect)(()=>{p()},[p]);let m=(0,Z.useCallback)(()=>{if(u.current){try{u.current.stop()}catch{}u.current=null}d.current&&=(d.current.abort(),null),r(!1)},[]),h=(0,Z.useCallback)(async(e,t)=>{if(m(),!e.trim()){l(`No text to speak`),t?.onError?.(`No text to speak`);return}l(null);try{d.current=new AbortController;let n=await V(`/api/tts/say/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:t?.voice||`Samantha`,rate:t?.rate||200}),signal:d.current.signal});if(!n.ok){let e=await n.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${n.status}`)}let i=await n.blob(),a=await i.arrayBuffer();i.size;let o=DT();o.state===`suspended`&&await o.resume();let s=await o.decodeAudioData(a),c=o.createBufferSource();c.buffer=s,c.connect(o.destination),u.current=c,c.onended=()=>{r(!1),u.current=null,t?.onEnd?.()},r(!0),t?.onStart?.(),c.start(0)}catch(e){if(e.name===`AbortError`)return;let n=e instanceof Error?e.message:`Failed to speak`;console.error(`[useSayTTS] Error:`,n),l(n),t?.onError?.(n),r(!1)}},[m]);return(0,Z.useEffect)(()=>()=>{m()},[m]),{isPlaying:n,isAvailable:i,voices:o,error:c,speak:h,stop:m,checkAvailability:p,unlockAudio:f}}function kT(e){return e?e.replace(/```[\s\S]*?```/g,``).replace(/`([^`\n]*)`/g,`$1`).replace(/[*_~#]/g,``).replace(/https?:\/\/[^\s]+/g,``).replace(/(^|\s)\/(?:[\w.-]+\/)*[\w.-]+/g,`$1`).replace(/([\w.])\/([\w.])/g,`$1 slash $2`).replace(/^\s*[$#>]\s*/gm,``).replace(/[[\]{}()<>|&;]/g,` `).replace(/\\/g,``).replace(/\s+/g,` `).trim():``}var AT=600,jT=`Summarize the assistant reply for text-to-speech listening. Reply with 2-4 sentences of plain spoken prose in the same language as the reply. No markdown, no lists, no code — mention code changes briefly in words instead.`;async function MT(e,t){try{let n=await V(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:jT,...t.providerID?{preferredProviderID:t.providerID}:{},...t.modelID?{preferredModelID:t.modelID}:{}})});if(!n.ok)return null;let r=await n.json().catch(()=>null);return typeof r?.text==`string`&&r.text.trim()?r.text.trim():null}catch{return null}}function NT(){let[e,t]=(0,Z.useState)(!1),n=mi(e=>e.voiceProvider),r=mi(e=>e.speechRate),i=mi(e=>e.speechPitch),a=mi(e=>e.speechVolume),o=mi(e=>e.sayVoice),s=mi(e=>e.localTtsVoiceId),c=mi(e=>e.browserVoice),l=mi(e=>e.openaiVoice),u=mi(e=>e.openaiCompatibleVoice),d=mi(e=>e.openaiCompatibleUrl),f=mi(e=>e.openaiCompatibleTtsModel),p=mi(e=>e.showMessageTTSButtons),m=mi(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=xT({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=OT({enabled:_}),{speak:w,stop:T}=$a(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),ro.cancelSpeech()},[y,S,T]);return{isPlaying:e,play:(0,Z.useCallback)(async e=>{if(e.trim()){E(),t(!0);try{let p=e;if(m===`summarized`&&e.length>=AT){let{currentProviderId:t,currentModelId:n}=mi.getState(),r=await MT(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=kT(p),y=g?p:_;if(h&&b)await v(y,{voice:n===`openai-compatible`?u:l,model:n===`openai-compatible`?f:void 0,speed:r,pitch:i,volume:a,summarize:!1,baseURL:n===`openai-compatible`?d:void 0,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`local`)await w(_,{speakerId:s,speed:r,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`say`&&C){let e=Math.round(100+(r-.5)*200);await x(_,{voice:o,rate:e,onEnd:()=>t(!1),onError:()=>t(!1)})}else await ro.waitForVoices(),await ro.resumeAudioContext(),await ro.speakText(_,navigator.language||`en-US`,()=>t(!1),{rate:r,pitch:i,volume:a,voiceName:c||void 0})}catch(e){console.error(`[useMessageTTS] Playback error:`,e),t(!1)}}},[n,h,r,i,a,o,c,l,u,d,f,b,C,m,v,x,w,s,E]),stop:E}}var PT=8,FT=280,IT=null;Mr(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),IT&&(0,xc.flushSync)(IT)});var LT=new Set(`address.article.aside.blockquote.dd.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.table.ul`.split(`.`)),RT=e=>e.replace(/\r\n?/g,`
6566
+ `).trim(),Kw=80,qw=200,Jw={duration:.2,ease:`easeOut`},Yw=e=>e.replace(/<!--\s*-->/g,``).replace(/```[\w]*\n?([\s\S]*?)```/g,(e,t)=>t.trim()).replace(/`([^`]+)`/g,`$1`).replace(/\*{1,3}([^*]+)\*{1,3}/g,`$1`).replace(/_{1,3}([^_]+)_{1,3}/g,`$1`).replace(/^#{1,6}\s+/gm,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^>\s?/gm,``).replace(/^[-*_]{3,}\s*$/gm,``).trim(),Xw=e=>{if(!e)return``;let t=Yw(e).replace(/\s+/g,` `).trim();if(t.length<=Kw)return t;let n=t.lastIndexOf(` `,Kw),r=n>0?n:Kw;return`${t.substring(0,r).trimEnd()}…`},Zw=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:c})=>{let{t:l}=ot(),u=s(e=>e.isMobile),d=typeof i?.end==`number`,f=a&&!d,[p,m]=Z.useState(()=>c===!0?{expanded:!0,source:`user`}:{expanded:f,source:`auto`}),h=p.source===`auto`?f&&p.expanded:p.expanded,[g,_]=Z.useState(c===!0||f),v=Z.useId(),y=Z.useRef(null),b=Z.useRef(null),x=Z.useRef(!1),S=Z.useRef(n);S.current=n;let C=Z.useMemo(()=>Xw(e),[e]),w=l(h?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),T=q(()=>{_(!0),m({expanded:!h,source:`user`}),n?.(`structural`)}),E=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())});if(Z.useLayoutEffect(()=>{m(e=>e.source===`user`||e.expanded===f?e:{expanded:f,source:`auto`})},[f]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(h||a){_(!0);return}if(!g)return;if(typeof window>`u`){_(!1);return}let e=window.setTimeout(()=>{_(!1)},qw);return()=>{window.clearTimeout(e)}},[h,a,g]),Z.useLayoutEffect(()=>{let e=y.current;if(!e)return;if(b.current?.stop(),!x.current){if(x.current=!0,!h){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=yc(e,{height:`auto`},Jw);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}}e.style.overflow=`hidden`,h?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,S.current?.(`animation`));let t=yc(e,{height:h?`auto`:`0px`},Jw);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,h?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}},[h]),Z.useEffect(()=>()=>{b.current?.stop(),b.current=null},[]),!e||e.trim().length===0)return null;let D=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(No,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":h,"aria-controls":v,"aria-label":w,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,kp),onClick:T,onKeyDown:E,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,h&&`opacity-0`,!h&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,h&&`opacity-100`,!h&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:h?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,Uw),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--oc-text-shimmer-base":`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(qS,{isMobile:u,className:`block text-[var(--tools-icon)]`})]}):h?(0,$.jsx)(`span`,{className:Uw,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:Uw,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,Ww),style:{color:`var(--tools-description)`},children:!a&&!h&&C?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,Ww),style:{color:`var(--tools-description)`,opacity:.8},title:C,children:C}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),g?(0,$.jsx)(`div`,{ref:y,id:v,"aria-hidden":!h,style:{height:h?`auto`:`0px`,overflow:h?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!h,transform:h?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:D}):(0,$.jsx)(fa,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:D})]})}):null]})},Qw=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=s($w),c=n,l=c.text||c.content||``,u;t[0]===l?u=t[1]:(u=Gw(l),t[0]=l,t[1]=u);let d=u,f=c.time,p=a===void 0||a!==`completed`,m=o===`live`&&p&&typeof f?.end!=`number`,h=`${i}:${n.id??`reasoning`}`,g;t[2]!==m||t[3]!==h||t[4]!==d?(g={text:d,isStreaming:m,identityKey:h},t[2]=m,t[3]=h,t[4]=d,t[5]=g):g=t[5];let _=Mw(g),v=`${i}:${n.id??`reasoning`}`,y=Z.useRef(null),b=n.sessionID,x=p&&typeof f?.end!=`number`,S,C;if(t[6]!==v||t[7]!==x||t[8]!==i||t[9]!==n.id||t[10]!==b||t[11]!==_?(S=()=>{if(!bn())return;let e=Tt(y.current,{identity:v,content:_,isActive:x,mode:`appearance`});y.current=e.nextState,!(!e.shouldEmit||!b)&&Mt({sessionID:b,messageID:i,partID:n.id,kind:`thinking`})},C=[v,x,i,n.id,b,_],t[6]=v,t[7]=x,t[8]=i,t[9]=n.id,t[10]=b,t[11]=_,t[12]=S,t[13]=C):(S=t[12],C=t[13]),Z.useEffect(S,C),!_||_.trim().length===0)return null;let w=n.id||`${i}-reasoning`,T;return t[14]!==m||t[15]!==r||t[16]!==w||t[17]!==_||t[18]!==f?(T=(0,$.jsx)(Zw,{text:_,variant:`thinking`,onContentChange:r,blockId:w,time:f,isStreaming:m}),t[14]=m,t[15]=r,t[16]=w,t[17]=_,t[18]=f,t[19]=T):T=t[19],T});function $w(e){return e.chatRenderMode}var eT=(e,t)=>{let n=vo(e,t)||yo(t);return n?So(n,e)?{kind:`diff`,path:_o(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},tT=e=>{let t=s.getState(),n=eT(e.directory,e.filePath);if(n.kind===`file`){as(n.path,e.directory).then(()=>{t.openContextFile(e.directory,n.path,{fileNotice:n.notice}),e.mobile&&t.setRightSidebarOpen(!1)});return}if(e.mobile){t.navigateToDiff(n.path,!1,`turn`),t.setRightSidebarOpen(!1);return}t.openContextDiff(e.directory,n.path,!1,`turn`,void 0,e.turnMessageId,e.sessionId)},nT=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),c=Z.useRef(null),l=Qm(),u=Te(rT),d=l.directory||u,f=Bs(d),p;if(t[0]!==n||t[1]!==f){bb0:{if(f!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],p=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],p=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&vh.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],p=e;break bb0}p=Sh(e)}t[0]=n,t[1]=f,t[2]=p}else p=t[2];let m=p;if(m.length===0)return null;let h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{let e=c.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=h):h=t[6];let g=h,_;t[7]!==d||t[8]!==l?(_=e=>{if(!d)return;let t=s.getState();tT({directory:d,filePath:e.path,sessionId:l.sessionId,mobile:t.isMobile}),i(!1)},t[7]=d,t[8]=l,t[9]=_):_=t[9];let v=_,y=m.length,b=`${y} file${y===1?``:`s`}`,x=`${b} changed in this turn`,S;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=S):S=t[10];let C;t[11]===b?C=t[12]:(C=(0,$.jsx)(`span`,{className:`message-footer__label`,children:b}),t[11]=b,t[12]=C);let w;t[13]===r?w=t[14]:(w=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=w);let T;t[15]!==x||t[16]!==C||t[17]!==w?(T=(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ge,{render:(0,$.jsxs)(`button`,{ref:c,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":x,onPointerDownCapture:g,onFocusCapture:g,children:[S,C,w]})})}),t[15]=x,t[16]=C,t[17]=w,t[18]=T):T=t[18];let E;t[19]===b?E=t[20]:(E=(0,$.jsxs)(La,{children:[b,` changed in this turn`]}),t[19]=b,t[20]=E);let D;t[21]!==T||t[22]!==E?(D=(0,$.jsxs)(Ra,{children:[T,E]}),t[21]=T,t[22]=E,t[23]=D):D=t[23];let O=a||void 0,k;t[24]!==m||t[25]!==d||t[26]!==v?(k=(0,$.jsx)(ve,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(he,{style:Ah,className:`${kh} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(Oh,{files:m,currentDirectory:d,onOpenFile:v})})}),t[24]=m,t[25]=d,t[26]=v,t[27]=k):k=t[27];let A;t[28]!==O||t[29]!==k?(A=(0,$.jsx)(Se,{container:O,children:k}),t[28]=O,t[29]=k,t[30]=A):A=t[30];let j;return t[31]!==r||t[32]!==D||t[33]!==A?(j=(0,$.jsxs)(_e,{open:r,onOpenChange:i,children:[D,A]}),t[31]=r,t[32]=D,t[33]=A,t[34]=j):j=t[34],j});nT.displayName=`TurnChangedFilesDropdown`;function rT(e){return e.currentDirectory}var iT=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,aT=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},oT=e=>e.type!==`tool`||iT(e)?!1:!aT(e),sT=e=>{let t=0;for(let n of e)oT(n)&&(t+=1);return t},cT=(e,t)=>e===`stop`&&sT(t)===0,lT=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},uT=(e,t,n)=>{if(n||!cT(e,t))return!1;for(let e of t)if(lT(e))return!0;return!1},dT=e=>e===`streaming`||e===`cooldown`,fT=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,pT=e=>e.error||e.isLastAssistantInTurn===!1?!1:cT(e.finish,e.parts)?!0:!dT(e.streamPhase)||typeof e.finish==`string`&&e.finish!==`stop`?!1:sT(e.parts)===0,mT=e=>dT(e.streamPhase)?pT(e):!1,hT=3e4,gT=new Map,_T=new Map;async function vT(e){let t=Date.now(),n=gT.get(e);if(n&&t-n.checkedAt<hT)return n.available;let r=_T.get(e);if(r)return r;let i=(async()=>{try{let t=await V(`/api/tts/status`);if(!t.ok)return gT.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return gT.set(e,{available:n,checkedAt:Date.now()}),n}catch{return gT.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{_T.delete(e)}})();return _T.set(e,i),i}var yT=null;function bT(){return yT||=new(window.AudioContext||window.webkitAudioContext),yT}function xT(e={}){let r=e.enabled??!0,i=e.availabilityMode??`auto`,[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=mi(e=>e.currentProviderId),h=mi(e=>e.currentModelId),g=mi(e=>e.openaiApiKey),_=mi(e=>e.openaiCompatibleUrl),v=mi(e=>e.openaiCompatibleApiKey),y=(0,Z.useCallback)(async()=>{let e=++p.current,t=n(),a=r=>(e===p.current&&n()===t&&c(r),r);if(!r)return a(!1);let o=!!(g&&g.trim().length>0),s=!!(_&&_.trim().length>0);if(i===`openai-compatible`)return a(s);if(o||i===`auto`&&s)return a(!0);try{return a(await vT(t))}catch{return a(!1)}},[i,r,g,_]);(0,Z.useEffect)(()=>{y()},[y]),(0,Z.useEffect)(()=>t(()=>{y()}),[y]);let b=(0,Z.useCallback)(()=>{let e=f.current;if(f.current=null,e?.abort.abort(),d.current){try{d.current.onended=null,d.current.stop()}catch{}d.current=null}o(!1)},[]),x=(0,Z.useCallback)(async()=>{try{let e=bT();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useServerTTS] Failed to unlock audio:`,e)}},[]),S=(0,Z.useCallback)(async(e,t)=>{if(b(),!e.trim()){u(`No text to speak`),t?.onError?.(`No text to speak`);return}u(null);let n={abort:new AbortController};f.current=n;try{let r=bT();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),a=r.createBufferSource();a.buffer=i,a.connect(r.destination),a.start(0);let s=t?.voice||`nova`,c=await V(`/api/tts/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:s,model:t?.model||void 0,speed:t?.speed||.9,instructions:t?.instructions,summarize:!1,providerId:t?.providerId||m||void 0,modelId:t?.modelId||h||void 0,apiKey:t?.baseURL?v||void 0:g||void 0,baseURL:t?.baseURL||void 0}),signal:n.abort.signal});if(f.current!==n)return;if(!c.ok){let e=await c.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${c.status}`)}let l=await(await c.blob()).arrayBuffer();if(f.current!==n)return;let u=await r.decodeAudioData(l);if(f.current!==n)return;let p=r.createBufferSource();p.buffer=u;let _=t?.pitch??1;_!==1&&(p.detune.value=(_-1)*1200);let y=t?.volume??1,b=r.createGain();if(b.gain.value=y,p.connect(b),b.connect(r.destination),d.current=p,p.onended=()=>{f.current===n&&d.current===p&&(o(!1),d.current=null,f.current=null,t?.onEnd?.())},o(!0),t?.onStart?.(),f.current!==n||d.current!==p)return;p.start(0)}catch(e){if(e.name===`AbortError`||f.current!==n)return;let r=e instanceof Error?e.message:`Failed to speak`;console.error(`[useServerTTS] Error:`,r),u(r),t?.onError?.(r),o(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[b,m,h,g,v]);return(0,Z.useEffect)(()=>()=>{b()},[b]),{isPlaying:a,isAvailable:s,error:l,speak:S,stop:b,checkAvailability:y,unlockAudio:x}}var ST=3e4,CT=null,wT=null;async function TT(){return CT&&Date.now()-CT.checkedAt<ST?CT:wT||(wT=(async()=>{try{let e=await V(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return CT=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return CT=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return CT=e,e}finally{wT=null}})(),wT)}var ET=null;function DT(){return ET||=new(window.AudioContext||window.webkitAudioContext),ET}function OT(e={}){let t=e.enabled??!0,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useCallback)(async()=>{try{let e=DT();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useSayTTS] Failed to unlock audio:`,e)}},[]),p=(0,Z.useCallback)(async()=>{if(!t)return a(!1),s([]),!1;try{let e=await TT();return a(e.available),s(e.voices),e.available}catch{return a(!1),s([]),!1}},[t]);(0,Z.useEffect)(()=>{p()},[p]);let m=(0,Z.useCallback)(()=>{if(u.current){try{u.current.stop()}catch{}u.current=null}d.current&&=(d.current.abort(),null),r(!1)},[]),h=(0,Z.useCallback)(async(e,t)=>{if(m(),!e.trim()){l(`No text to speak`),t?.onError?.(`No text to speak`);return}l(null);try{d.current=new AbortController;let n=await V(`/api/tts/say/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:t?.voice||`Samantha`,rate:t?.rate||200}),signal:d.current.signal});if(!n.ok){let e=await n.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${n.status}`)}let i=await n.blob(),a=await i.arrayBuffer();i.size;let o=DT();o.state===`suspended`&&await o.resume();let s=await o.decodeAudioData(a),c=o.createBufferSource();c.buffer=s,c.connect(o.destination),u.current=c,c.onended=()=>{r(!1),u.current=null,t?.onEnd?.()},r(!0),t?.onStart?.(),c.start(0)}catch(e){if(e.name===`AbortError`)return;let n=e instanceof Error?e.message:`Failed to speak`;console.error(`[useSayTTS] Error:`,n),l(n),t?.onError?.(n),r(!1)}},[m]);return(0,Z.useEffect)(()=>()=>{m()},[m]),{isPlaying:n,isAvailable:i,voices:o,error:c,speak:h,stop:m,checkAvailability:p,unlockAudio:f}}function kT(e){return e?e.replace(/```[\s\S]*?```/g,``).replace(/`([^`\n]*)`/g,`$1`).replace(/[*_~#]/g,``).replace(/https?:\/\/[^\s]+/g,``).replace(/(^|\s)\/(?:[\w.-]+\/)*[\w.-]+/g,`$1`).replace(/([\w.])\/([\w.])/g,`$1 slash $2`).replace(/^\s*[$#>]\s*/gm,``).replace(/[[\]{}()<>|&;]/g,` `).replace(/\\/g,``).replace(/\s+/g,` `).trim():``}var AT=600,jT=`Summarize the assistant reply for text-to-speech listening. Reply with 2-4 sentences of plain spoken prose in the same language as the reply. No markdown, no lists, no code — mention code changes briefly in words instead.`;async function MT(e,t){try{let n=await V(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:jT,...t.providerID?{preferredProviderID:t.providerID}:{},...t.modelID?{preferredModelID:t.modelID}:{}})});if(!n.ok)return null;let r=await n.json().catch(()=>null);return typeof r?.text==`string`&&r.text.trim()?r.text.trim():null}catch{return null}}function NT(){let[e,t]=(0,Z.useState)(!1),n=mi(e=>e.voiceProvider),r=mi(e=>e.speechRate),i=mi(e=>e.speechPitch),a=mi(e=>e.speechVolume),o=mi(e=>e.sayVoice),s=mi(e=>e.localTtsVoiceId),c=mi(e=>e.browserVoice),l=mi(e=>e.openaiVoice),u=mi(e=>e.openaiCompatibleVoice),d=mi(e=>e.openaiCompatibleUrl),f=mi(e=>e.openaiCompatibleTtsModel),p=mi(e=>e.showMessageTTSButtons),m=mi(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=xT({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=OT({enabled:_}),{speak:w,stop:T}=$a(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),ro.cancelSpeech()},[y,S,T]);return{isPlaying:e,play:(0,Z.useCallback)(async e=>{if(e.trim()){E(),t(!0);try{let p=e;if(m===`summarized`&&e.length>=AT){let{currentProviderId:t,currentModelId:n}=mi.getState(),r=await MT(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=kT(p),y=g?p:_;if(h&&b)await v(y,{voice:n===`openai-compatible`?u:l,model:n===`openai-compatible`?f:void 0,speed:r,pitch:i,volume:a,summarize:!1,baseURL:n===`openai-compatible`?d:void 0,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`local`)await w(_,{speakerId:s,speed:r,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`say`&&C){let e=Math.round(100+(r-.5)*200);await x(_,{voice:o,rate:e,onEnd:()=>t(!1),onError:()=>t(!1)})}else await ro.waitForVoices(),await ro.resumeAudioContext(),await ro.speakText(_,navigator.language||`en-US`,()=>t(!1),{rate:r,pitch:i,volume:a,voiceName:c||void 0})}catch(e){console.error(`[useMessageTTS] Playback error:`,e),t(!1)}}},[n,h,r,i,a,o,c,l,u,d,f,b,C,m,v,x,w,s,E]),stop:E}}var PT=8,FT=280,IT=null;jr(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),IT&&(0,xc.flushSync)(IT)});var LT=new Set(`address.article.aside.blockquote.dd.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.table.ul`.split(`.`)),RT=e=>e.replace(/\r\n?/g,`
6567
6567
  `),zT=e=>RT(e).trim(),BT=(e,t)=>{if(e.contains(t))return!0;let n=t instanceof ShadowRoot?t:t.getRootNode();return n instanceof ShadowRoot&&e.contains(n.host)},VT=e=>{let t=[],n=e=>{for(let r of e.querySelectorAll(`*`))r.shadowRoot&&(t.push(r.shadowRoot),n(r.shadowRoot))};return n(e),t},HT=(e,t)=>{let n=VT(t),r=e.getComposedRanges?.({shadowRoots:n})[0];if(r){let e=document.createRange();if(e.setStart(r.startContainer,r.startOffset),e.setEnd(r.endContainer,r.endOffset),BT(t,e.commonAncestorContainer))return e}if(e.rangeCount===0)return null;let i=e.getRangeAt(0);return BT(t,i.commonAncestorContainer)?i:null},UT=e=>e.replace(/\s+/g,` `).trim(),WT=e=>{if(e.nodeType===Node.TEXT_NODE)return UT(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase(),r=Array.from(t.childNodes).map(e=>WT(e)).join(``).replace(/\s+/g,` `).trim();if(!r&&n!==`br`)return``;if(n===`br`)return`
6568
6568
  `;if(n===`strong`||n===`b`)return`**${r}**`;if(n===`em`||n===`i`)return`*${r}*`;if(n===`code`)return`\`${r.replace(/`/g,"\\`")}\``;if(n===`a`){let e=t.getAttribute(`href`);return e?`[${r}](${e})`:r}return r},GT=(e,t)=>Array.from(e.children).filter(e=>e instanceof HTMLElement&&e.tagName.toLowerCase()===`li`).map((e,n)=>{let r=t?`${n+1}. `:`- `,i=Array.from(e.childNodes).map(e=>WT(e)).join(``).replace(/\s+/g,` `).trim();return i?`${r}${i}`:``}).filter(Boolean).join(`
6569
6569
  `),KT=e=>{if(e.nodeType===Node.TEXT_NODE)return zT(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase();if(n===`pre`){let e=t.querySelector(`code`);return`\`\`\`${((e?.className||``).match(/language-([\w-]+)/)?.[1]||``).trim()}\n${RT(e?.textContent||t.textContent||``).replace(/\n$/,``)}\n\`\`\``}if(n===`code`){let e=RT(t.textContent||``).trim();return e?`\`${e.replace(/`/g,"\\`")}\``:``}if(n===`ul`)return GT(t,!1);if(n===`ol`)return GT(t,!0);if(n===`blockquote`)return zT(Array.from(t.childNodes).map(e=>KT(e)).join(`
@@ -6573,13 +6573,13 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
6573
6573
 
6574
6574
  `):zT(Array.from(t.childNodes).map(e=>WT(e)).join(``))},qT=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!LT.has(t.tagName.toLowerCase())}),JT=(e,t)=>{let n=e.cloneContents();if(qT(n)){let e=zT(Array.from(n.childNodes).map(e=>WT(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>KT(e)).filter(e=>e.length>0).join(`
6575
6575
 
6576
- `).trim()||zT(t)},YT=({containerRef:e})=>{let{t}=st(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,c]=Z.useState(``),l=Z.useRef(!1),[u,d]=Z.useState(!1),f=Z.useRef(null),p=Z.useRef(FT),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(null),_=Z.useRef(!1),v=J(e=>e.createSession),y=Lt(e=>e.setPendingInputText),b=s(e=>e.isMobile),x=$m(Qm()).textSelectionMutation;Z.useEffect(()=>{_.current=n.show},[n.show]),Z.useEffect(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]);let S=Z.useCallback(()=>{m.current=null,IT===S&&(IT=null),_.current&&=(h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),d(!1),r(e=>({...e,show:!1})),a(``),c(``),!1)},[]);Z.useEffect(()=>()=>{IT===S&&(IT=null)},[S]);let C=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=p.current/2,r=PT+n,i=t-PT-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),w=Z.useCallback(()=>{if(!m.current)return;IT!==S&&(IT?.(),IT=S);let{plainText:e,markdownText:t,rect:i}=m.current,o=!n.show,s=b?i.left+i.width/2:C(i.left+i.width/2),l=i.top-10;a(e),c(t),r({x:s,y:l,show:!0}),_.current=!0,o&&(d(!0),h.current!==null&&window.cancelAnimationFrame(h.current),h.current=window.requestAnimationFrame(()=>{d(!1),h.current=null}))},[C,S,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!f.current)return;let e=f.current.offsetWidth;!Number.isFinite(e)||e<=0||e===p.current||(p.current=e,r(e=>({...e,x:C(e.x)})))},[C,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:C(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[C,b,n.show]);let T=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||S();return}let r=zT(t.toString());if(!r){l.current||S();return}let i=HT(t,n);if(!i){l.current||S();return}let a=i.getBoundingClientRect();m.current={plainText:r,markdownText:JT(i,r),rect:a},l.current||w()},[e,S,w]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,S()},r=()=>{l.current=!1,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{g.current=null,T()},10)},i=new Set,a=()=>{for(let e of VT(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,T))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,T),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{f.current&&!f.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&S()};return document.addEventListener(`mousedown`,s),()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,T);document.removeEventListener(`selectionchange`,T),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,T,S,w]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{f.current&&e.target instanceof Node&&f.current.contains(e.target)||S()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,S]);let E=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;y(t,`append`),S(),window.getSelection()?.removeAllRanges()},[y,S]),D=Z.useCallback(()=>{E(o)},[E,o]);Z.useEffect(()=>{let t=t=>{if(!x||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=HT(n,r);i&&(t.preventDefault(),E(JT(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[E,x,e]);let O=Z.useCallback(async()=>{i&&(await v(void 0,null,null)&&y(i,`replace`),S(),window.getSelection()?.removeAllRanges())},[i,v,y,S]),k=Z.useCallback(async()=>{if(!i)return;let e=await lt(i);e.ok||console.error(`Failed to copy:`,e.error),S(),window.getSelection()?.removeAllRanges()},[i,S]);return n.show?b?(0,xc.createPortal)((0,$.jsx)(`div`,{ref:f,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,xc.createPortal)((0,$.jsx)(`div`,{ref:f,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(fp,{shortcut:`⌘+I`})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},XT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),ZT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),XT(e,n)},QT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),$T=(e,t)=>{if(!QT(e))return``;let n=new Date(e),r=new Date,i=lo(n,t),a=ct(),o=ut.getState().dictionary;if(XT(n,r))return i;if(ZT(n,r))return dt(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}`},eE=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,tE=e=>e,nE=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=tE(n);if(e.type!==`tool`)continue;let r=e.state,i=r?.time?.start,a=r?.time?.end;typeof i!=`number`||!Number.isFinite(i)||typeof a!=`number`||!Number.isFinite(a)||a<i||(t+=a-i)}return t},rE=(e,t,n,r)=>{let i=(typeof e==`number`&&Number.isFinite(e)&&e>0&&typeof t==`number`&&Number.isFinite(t)&&t>e?t-e:null)??(typeof r==`number`&&Number.isFinite(r)&&r>0?r:null);if(i===null)return null;let a=i-nE(n);return!Number.isFinite(a)||a<=0?null:a},iE=e=>{let t=rE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=eE(e.outputTokens)+eE(e.reasoningTokens);if(n<=0)return null;let r=t/1e3;if(r<=0)return null;let i=n/r;return!Number.isFinite(i)||i<=0?null:i},aE=e=>{if(!Number.isFinite(e)||e<=0)return``;if(e>=1e3){let t=e/1e3;return`${t>=10?t.toFixed(0):t.toFixed(1)}k tok/s`}return e>=100?`${Math.round(e)} tok/s`:e>=10?`${e.toFixed(1)} tok/s`:`${e.toFixed(2)} tok/s`},oE=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=K(f),m;t[5]===i?m=t[6]:(m=Y(`oc-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:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-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},sE=[`search`,`read`,`list`];function cE(e){let t=lC(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function lE(e){let t={read:0,search:0,list:0};for(let n of e){let e=cE(n);e&&(t[e]+=1)}return t}function uE(e){return cC(e)}function dE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!aC(e.toolName):e.kind!=null||e.type!=null}function fE(e,t,n){for(let r=t;r<e.length;r+=1)if(dE(n(e[r])))return!0;return!1}function pE(e){return`parts`in e?e.parts.some(e=>uE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>uE(e))}function mE(e,t,n){let r=[],i=t;for(;i<e.length&&aC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var hE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,gE=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=st(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??pE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=lE(u.map(e=>e.tool)),p=sE.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`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=K(()=>{c(e=>!e)}),h=K(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:Op(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,kp),onClick:m,onKeyDown:h,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,v,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(qS,{isMobile:t,label:o(`chat.contextGroup.exploring`),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`,v,hE,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:_}),p?(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`,v,hE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(oE,{text:p,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(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:`relative ml-2 pl-3 pt-0.5`,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 _E(e,t,n){let r=[],i=t;for(;i<e.length&&oC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var vE=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function yE(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=vE(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=vE(e.name);if(t)return t;let r=vE(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=vE(n.output.name);if(e)return e}return null}function bE(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 xE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,SE=({activities:e,isMobile:t,children:n})=>{let{t:r}=st(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>cC(e)),{joinedVisible:l,hiddenCount:u}=bE(s.map(yE)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=K(()=>{a(e=>!e)}),p=K(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:Op(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`,kp),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)(qS,{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`,xE,c&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...c?{"--oc-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`,xE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(oE,{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:`relative ml-2 pl-3 pt-0.5`,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]})},CE=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:c}=e,l=s(wE),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==c||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(Bw,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:c})}),t[4]=l,t[5]=r,t[6]=i,t[7]=c,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=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]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function wE(e){return e.chatRenderMode}var TE=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},EE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,DE=Y(`typography-meta font-medium`,EE),OE=Y(`typography-meta`,EE),kE=[],AE=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},jE=e=>{let t=new Set;for(let n of e)AE(n)&&n.messageId&&t.add(n.messageId);return[...t]},ME=(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}),NE=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=Zo(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},PE=e=>e,FE=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},IE=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},LE=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},RE=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},zE=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=RE(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`}`},BE=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=zE(n.todos);if(e)return e}if(Array.isArray(r)){let e=zE(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=zE(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=zE(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=zE(e.todos);if(t)return t}}catch{}return null},VE=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)},HE=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(dx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,OE),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`,OE),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)(dx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},UE=e=>{let t=yo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},WE=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 yE(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`?BE(e):FE(e)},GE=e=>{let t=[],n=[];for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(e.tool?.trim().toLowerCase()!==`task`)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;n.push(i),(o.status===`pending`||o.status===`running`)&&t.push(i)}return{active:t,all:n}},KE=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=K(c),u;t[3]===i?u=t[4]:(u=Op(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)(bw,{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&&$x([e.activity.part],[t.activity.part])),qE=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=Op(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(XE,{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&&YE(e.activities,t.activities)),JE=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Xr(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(aC(i)){let r=mE(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:fE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(oC(i)){let r=_E(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(rC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(nC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(iC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},YE=(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||!$x([r.part],[i.part]))return!1}return!0},XE=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=st(),c=s(eD),l=$o(n,o),u;t[0]===n?u=t[1]:(u=fx(n),t[0]=n,t[1]=u);let d=u,f;t[2]===n?f=t[3]:(f=n.toLowerCase(),t[2]=n,t[3]=f);let p=f===`read`,m=Z.useContext(Oo),h=_h(),g=Ee(tD),_=Qm(),v=_.kind===`embedded`?_.directory:g,y;t[4]===n?y=t[5]:(y=n.toLowerCase(),t[4]=n,t[5]=y);let b=y===`skill`,x;t[6]===b?x=t[7]:(x={enabled:b},t[6]=b,t[7]=x);let S=ti(x),C;t[8]===S.data?C=t[9]:(C=S.data??[],t[8]=S.data,t[9]=C);let w=C,T;t[10]===w?T=t[11]:(T=new Map(w.map(nD)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||cC(D.part),k;t[12]===D?k=t[13]:(k=D?WE(D):null,t[12]=D,t[13]=k);let A=k,j;if(t[14]!==A||t[15]!==D||t[16]!==E||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!D||!A){j=null;break bb0}let e=E.get(A)?.path||LE(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=UE(e);if(!r){j=null;break bb0}let i;t[19]!==A||t[20]!==r?(i={name:A,path:r},t[19]=A,t[20]=r,t[21]=i):i=t[21],j=i}t[14]=A,t[15]=D,t[16]=E,t[17]=n,t[18]=j}else j=t[18];let M=j,N;if(t[22]!==v||t[23]!==p||t[24]!==D){bb1:{if(!p||!D){N=null;break bb1}let e=IE(D);if(!e){N=null;break bb1}let n=_o(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=VE(D),t[26]=D,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],N=i}t[22]=v,t[23]=p,t[24]=D,t[25]=N}else N=t[25];let P=N,F;t[32]!==v||t[33]!==h||t[34]!==m?(F=(e,t)=>{if(!v)return;let n=vo(v,e);if(!n)return;if(h){h.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(m?.editor){m.editor.openFile(n,t);return}if(!So(n,v)){as(n,v).then(()=>{let e=s.getState(),r=v||go(v,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=s.getState(),i=go(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=K(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=yo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=s.getState(),n=v||go(``,t);e.openContextFile(n,t)};if(v&&!So(t,v)){as(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=K(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,ee=!!(P||M),te=!!(P&&v||M),W;t[41]!==te||t[42]!==I||t[43]!==R||t[44]!==ee||t[45]!==P||t[46]!==M?(W=()=>{if(!(!ee||!te)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=te,t[42]=I,t[43]=R,t[44]=ee,t[45]=P,t[46]=M,t[47]=W):W=t[47];let G=K(W),ne;t[48]===G?ne=t[49]:(ne=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),G())},t[48]=G,t[49]=ne);let re=K(ne),ie=ee&&te&&`cursor-pointer`,ae=ee&&!te&&`cursor-default opacity-70`,oe;t[50]!==ie||t[51]!==ae?(oe=Y(`flex w-full items-center gap-x-1.5 min-w-0`,kp,ie,ae),t[50]=ie,t[51]=ae,t[52]=oe):oe=t[52];let se=ee?`soft`:void 0,ce=ee?G:void 0,le=ee?re:void 0,ue=ee?`button`:void 0,de=ee&&te?0:void 0,fe=ee&&!te?!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=O?(0,$.jsx)(qS,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,_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(DE,`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]===l?be=t[63]:(be=(0,$.jsx)(`span`,{className:ve,style:ye,title:l,children:l}),t[62]=l,t[63]=be);let xe;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==c?(xe=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,OE),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[c?(0,$.jsx)(ku,{filePath:P.path,className:`h-3.5 w-3.5`}):null,HE(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=c,t[68]=xe):xe=t[68];let Se;t[69]!==a||t[70]!==A||t[71]!==V?(Se=V&&A?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(dx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,OE),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=Se):Se=t[72];let Ce;t[73]!==A||t[74]!==H?(Ce=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:rD,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`,OE),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(NE,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=Ce):Ce=t[75];let we;t[76]!==U||t[77]!==M?(we=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,OE),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=we):we=t[78];let Te;t[79]!==A||t[80]!==U||t[81]!==M?(Te=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,OE),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=Te):Te=t[82];let De;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(De=!p&&!V&&!H&&!U&&A?(0,$.jsx)(dx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,OE),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=De):De=t[89];let Oe;return t[90]!==oe||t[91]!==se||t[92]!==ce||t[93]!==le||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]!==De?(Oe=(0,$.jsxs)(`div`,{className:oe,"data-mobile-press-feedback":se,onClick:ce,onKeyDown:le,role:ue,tabIndex:de,"aria-disabled":fe,children:[_e,be,xe,Se,Ce,we,Te,De]}),t[90]=oe,t[91]=se,t[92]=ce,t[93]=le,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]=De,t[105]=Oe):Oe=t[105],Oe},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&YE(e.activities,t.activities)),ZE=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)(Qw,{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}),QE=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)(CE,{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}),$E=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}=st(),_=is()??``,v=Z.useMemo(()=>jE(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?TE(o):null,D=i===`normal`||i===`abnormal`,O=a===`compaction`,k=O?`fold-vertical`:`stack`,A=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`),j=Z.useMemo(()=>GE(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=K((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=Wi(_,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=Bi(_,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)}}),F=K(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=K(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),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)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].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 Wi(_,n,e).status}),U=H.includes(`loading`),ee=H.includes(`error`),te=H.length>0&&H.every(e=>e===`ready`),W=t.some(e=>V.has(e.messageId)&&AE(e)),G=te&&!W&&!ME(t,V),ne=Z.useMemo(()=>B?PE(e):kE,[e,B]),re=Z.useMemo(()=>B?JE(ne):[],[B,ne]),ie=Z.useMemo(()=>L||z===0?0:Math.max(0,re.length-z),[L,z,re.length]),ae=Z.useMemo(()=>L||z===0?re:re.slice(-z),[L,z,re]);if((!m||I&&!O)&&re.length===0)return null;let oe=(e,t)=>{let n=(0,$.jsx)(`div`,{className:Op(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},se=B?ae.map((e,t)=>{switch(e.type){case`reasoning`:return oe(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(ZE,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return oe(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(QE,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(KE,{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)(qE,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(gE,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(XE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(SE,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(XE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(KE,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,ce=ae.length>0;return m?(0,$.jsxs)(`div`,{className:Op(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&kp,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),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)(qS,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,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)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),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 justify-end`,c?`gap-0.5`:`gap-1`),children:[M.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:N.map((e,t)=>(0,$.jsx)(ea,{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:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`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`)})]})]}),ce?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?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)`}}),ie>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,ie,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:se})]}):null,L&&(U||ee||G)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,ee&&`text-[var(--status-error)]`),role:ee?`alert`:`status`,children:U?(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`)})]}):ee?(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)(la,{type:`button`,variant:`ghost`,size:`xs`,onClick:F,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]}):(0,$.jsx)(`div`,{className:Op(c),children:se})});function eD(e){return e.showToolFileIcons}function tD(e){return e.currentDirectory}function nD(e){return[e.name,e]}function rD(e){e.stopPropagation()}var iD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)($E,{...e}),t[0]=e,t[1]=n),n}),aD={contain:`layout`},oD={containerType:`inline-size`,containerName:`message-footer`},sD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,cD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,lD=`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`,uD=`size-3.5!`,dD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,fD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,pD=`flex items-center gap-2`,mD=`flex items-center gap-2 text-muted-foreground`,hD=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,gD=`size-3.5!`,_D=`medium`,vD=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,yD=`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)]`,bD=`h-7 gap-1.5`,xD=`h-6 gap-1`,SD=`text-[11px] leading-none`,CD=`size-3.5`,wD=`size-3`,TD=5,ED=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)(ku,{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=vD(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}),DD=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=st(),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=K(s),l=!r,u=i?xD:bD,d;t[3]===u?d=t[4]:(d=Y(yD,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)(ED,{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)(la,{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}),OD=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:c}=st(),l=is(),u=Qm(),d=u.directory||l,f=u.sessionId,p=_h(),m=s(HD),h;t[0]===r?h=t[1]:(h=r??[],t[0]=r,t[1]=h);let g=h,_;t[2]===g?_=t[3]:(_=g.slice(0,TD),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==c?(S=c(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=c,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==c?(w=c(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=c,t[9]=w):w=t[9];let T=w,E=Y(yD,o?xD:bD),D=o?wD:CD,O;t[10]===o?O=t[11]:(O=o?Y(SD,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=O);let k=O,A;t[12]===o?A=t[13]:(A=o?Y(SD,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=A);let j=A,M;t[14]===o?M=t[15]:(M=o?Y(SD,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=M);let N=M,P;t[16]!==d||t[17]!==f||t[18]!==a||t[19]!==o||t[20]!==p||t[21]!==i?(P=e=>{if(p){p.openTurnDiff(i,f,e);return}if(!o&&d){tT({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&tT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=K(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&tT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=K(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===c?V=t[35]:(V=c(`diffView.actions.reviewAria`),t[34]=c,t[35]=V);let H;t[36]===c?H=t[37]:(H=c(`diffView.actions.reviewAria`),t[36]=c,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let ee=`turn-changes-${i}`,te;t[40]===c?te=t[41]:(te=c(`chat.changedFiles.title`),t[40]=c,t[41]=te);let W;t[42]!==ee||t[43]!==te||t[44]!==k?(W=(0,$.jsx)(`span`,{id:ee,className:k,children:te}),t[42]=ee,t[43]=te,t[44]=k,t[45]=W):W=t[45];let G;t[46]!==C||t[47]!==j?(G=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=G):G=t[48];let ne;t[49]===D?ne=t[50]:(ne=Y(D,`opacity-60`),t[49]=D,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:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,W,G,re]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(DD,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":c(`diffView.actions.reviewAria`),title:c(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),kD=e=>e.type===`subtask`,AD=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},jD=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}`},MD=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=is(),{isMobile:o}=fo(),c=J(UD),l=s(WD),u=Qm(),{t:f}=st(),p;t[0]===n.description?p=t[1]:(p=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=p);let m=p,h;t[2]===n.command?h=t[3]:(h=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=h);let g=h,_;t[4]===n.agent?_=t[5]:(_=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=_);let v=_,y;t[6]===n.prompt?y=t[7]:(y=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=y);let b=y,x;t[8]===n.taskSessionID?x=t[9]:(x=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=x);let S=x,C;t[10]===n.model?C=t[11]:(C=jD(n.model),t[10]=n.model,t[11]=C);let w=C,T=!!b&&!(o&&u.kind===`primary`),E;t[12]===f?E=t[13]:(E=f(`chat.messageBody.subtask.title`),t[12]=f,t[13]=E);let D;t[14]===E?D=t[15]:(D=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:E}),t[14]=E,t[15]=D);let O;t[16]===g?O=t[17]:(O=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,g]}):null,t[16]=g,t[17]=O);let k;t[18]===v?k=t[19]:(k=v?(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:[`@`,v]}):null,t[18]=v,t[19]=k);let A;t[20]===w?A=t[21]:(A=w?(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:w}):null,t[20]=w,t[21]=A);let j;t[22]!==k||t[23]!==A||t[24]!==D||t[25]!==O?(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D,O,k,A]}),t[22]=k,t[23]=A,t[24]=D,t[25]=O,t[26]=j):j=t[26];let M;t[27]===m?M=t[28]:(M=m?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:m}):null,t[27]=m,t[28]=M);let N;t[29]!==r||t[30]!==b||t[31]!==T||t[32]!==f?(N=T?(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(GD),children:f(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:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==c||t[41]!==f||t[42]!==S?(P=S&&u.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=u.directory||a;e&&eh(u,S,e,()=>{if(!ci({sessionId:S,directory:e})){if(Ac()||o||d()){c(S,e);return}l(e,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=c,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},ND=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=is(),i=s(KD),{isMobile:a}=fo(),{t:o}=st(),c;t[0]!==r||t[1]!==a?(c=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=c):c=t[2];let l=!!c,u;t[3]!==n.state||t[4]!==o?(u=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]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=K(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=K(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=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`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(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]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=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`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Mo,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=j);let M;t[23]!==A||t[24]!==j?(M=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[A,j]}),t[23]=A,t[24]=j,t[25]=M):M=t[25];let N;return t[26]!==w||t[27]!==M||t[28]!==y||t[29]!==b||t[30]!==x||t[31]!==S||t[32]!==C?(N=(0,$.jsxs)(`div`,{className:y,role:b,tabIndex:x,"aria-label":S,onClick:C,onKeyDown:w,children:[T,M]}),t[26]=w,t[27]=M,t[28]=y,t[29]=b,t[30]=x,t[31]=S,t[32]=C,t[33]=N):N=t[33],N},PD={background:`transparent`,backgroundColor:`transparent`},FD=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=st(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=K(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await lt(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=K(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Qs,{language:`bash`,code:u,codeStyle:PD,wrap:!0})}):null,t[23]=u,t[24]=E);let D;t[25]!==a||t[26]!==x||t[27]!==r||t[28]!==h||t[29]!==d||t[30]!==c?(D=h?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(qD),children:c(r?`chat.messageBody.shellCommand.hideOutput`:`chat.messageBody.shellCommand.showOutput`)}),(0,$.jsx)(`button`,{type:`button`,className:`inline-flex items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>{x()},"aria-label":c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:a?(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`h-3.5 w-3.5`})})]}),r?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 max-h-56 overflow-auto font-mono text-foreground/85`,children:(0,$.jsx)(Qs,{language:`bash`,code:d,codeStyle:PD,wrap:!0})}):null]}):null,t[25]=a,t[26]=x,t[27]=r,t[28]=h,t[29]=d,t[30]=c,t[31]=D):D=t[31];let O;return t[32]!==T||t[33]!==E||t[34]!==D?(O=(0,$.jsxs)(`div`,{className:`mt-2`,children:[T,E,D]}),t[32]=T,t[33]=E,t[34]=D,t[35]=O):O=t[35],O},ID=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},LD=(e,t)=>{if(t&&typeof t==`object`)return{output:typeof t.output==`number`&&Number.isFinite(t.output)?Math.max(0,t.output):0,reasoning:typeof t.reasoning==`number`&&Number.isFinite(t.reasoning)?Math.max(0,t.reasoning):0};for(let t of e){let e=t.tokens;if(!(!e||typeof e!=`object`))return{output:typeof e.output==`number`&&Number.isFinite(e.output)?Math.max(0,e.output):0,reasoning:typeof e.reasoning==`number`&&Number.isFinite(e.reasoning)?Math.max(0,e.reasoning):0}}return{output:0,reasoning:0}},RD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:c,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=st(),T=Fh(),E=$m(Qm()),D=s(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!qr(e):!!(kD(e)||AD(e))),[n]),M=Z.useMemo(()=>j.map(e=>sn(e)?Mx(Xr(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(c??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=K(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=K(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let ee=K(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),te=T===`mini-chat`||!E.fork?void 0:g,W=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=$T(i,D);return e.length>0?e:null},[C,i,D]),G=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),ne=!v&&y&&B?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(pD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(hD,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:_D,name:`edit`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:_D,name:`close`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,re=(v&&B?(0,$.jsx)(`div`,{className:G,children:(0,$.jsx)(`div`,{className:Y(pD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(hD,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??ne??((F&&R||m||h||te)&&B?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(pD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[W?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(hD,`mr-1`),"aria-label":`Message time: ${W}`,children:[(0,$.jsx)(X,{weight:_D,name:`time`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:W})]})}),(0,$.jsx)(La,{children:W})]}):null,h&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.revertAria`),"aria-busy":_===`revert`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),h()},children:(0,$.jsx)(X,{weight:_D,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(uD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:_D,name:`edit`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),te&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.forkAria`),"aria-busy":_===`fork`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),te()},children:(0,$.jsx)(X,{weight:_D,name:_===`fork`?`loader-4`:`git-branch`,className:Y(uD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:lD,"aria-label":w(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:ee,onFocus:()=>k(!0),onBlur:()=>{I||k(!1)},children:I?(0,$.jsx)(X,{weight:_D,name:`check`,className:Y(uD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:_D,name:`file-copy`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:aD,onTouchStart:L&&F&&R?U:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,V?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:V?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:j.map((e,i)=>{if(kD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(MD,{part:e})},e.id??`user-subtask-${i}`);if(AD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(FD,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ND,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Xr(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(lx,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(td,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),re]}):(0,$.jsx)($.Fragment,{children:re})}),zD=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=st(),s=Fh(),c=Qm(),l=$m(c),{isPlaying:u,play:d,stop:f}=NT(),p=mi(e=>e.showMessageTTSButtons),m=mi(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=K(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=K(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=K(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=K(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=K(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=K(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=K(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(lD,!e&&`opacity-50`),disabled:!e,"aria-label":o(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!e,onPointerDown:e=>e.stopPropagation(),onClick:e=>{O(e)},onFocus:()=>{e&&g(!0)},onBlur:()=>{_||g(!1)},children:_?(0,$.jsx)(X,{weight:_D,name:`check`,className:Y(uD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:_D,name:`file-copy`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:_D,name:`target`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(lD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:_D,name:`loader-4`,className:Y(uD,`animate-spin`)}):(0,$.jsx)(X,{weight:_D,name:`arrow-left-right`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:Y(lD,u?`text-green-500`:`hover:text-foreground/80`),"aria-label":o(u?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),onPointerDown:e=>e.stopPropagation(),onClick:M,children:u?(0,$.jsx)(X,{weight:_D,name:`stop`,className:uD}):(0,$.jsx)(X,{weight:_D,name:`volume-up`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:j})]})]})}),BD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:c,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=st(),A=Fh(),j=$m(Qm()),M=_,N=Z.useRef(null),P=Z.useRef(null),F=_===`streaming`||_===`cooldown`,I=Z.useRef({messageId:t,experiencedStreamingOrCooldown:F});I.current.messageId===t?F&&(I.current.experiencedStreamingOrCooldown=!0):I.current={messageId:t,experiencedStreamingOrCooldown:F};let L=!!(p??u),R=!!(f??u),z=u?fD:dD,B=!i,V=Z.useMemo(()=>n.filter(e=>!qr(e)).filter(e=>e.type!==`compaction`),[n]),H=Z.useMemo(()=>V.filter(e=>e.type===`tool`),[V]),U=Z.useMemo(()=>V.filter(e=>e.type===`text`),[V]),ee=Z.useMemo(()=>tn(U),[U]),te=s(e=>e.openContextPreview),W=d(),G=A===`mini-chat`,ne=Z.useMemo(()=>{if(W||u||G)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=Qo(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 H){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=Qo(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},[U,u,G,W,H]),re=J(e=>e.forkFromMessage),ie=J(e=>e.forkTransition),ae=J(e=>e.currentSessionId),oe=J(e=>e.getDirectoryForSession),se=is(),ce=D===`review-to-original`,le=!u&&!W?D:null,ue=Z.useMemo(()=>{let t=ee.trim();if(!(!e||!se||!t||!le))return le===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await vn(e,se,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await mn(e,se,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[ee,se,le,e,O]),[de,fe]=Z.useState(!1),pe=s(e=>e.chatRenderMode),me=s(e=>e.collapsibleThinkingBlocks),he=s(e=>e.showSplitAssistantMessageActions),ge=s(e=>e.showAssistantTps),_e=s(e=>e.timeFormatPreference),ve=pe===`sorted`,ye=w?.isLastAssistantInTurn??!1,be=a===`stop`,xe=(be||i||!!T)&&(w?.isTurnSettled??!0),Se=be?`completed`:M,Ce=H.length>0,we=Z.useMemo(()=>H.some(e=>cC(e)),[H]),Te=cC,Ee=sC,De=I.current.experiencedStreamingOrCooldown,Oe=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Oe.current.messageId!==t&&(Oe.current={messageId:t,initialized:!1,observedPartIds:new Set}),!De||!xn())return;let n=Oe.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Zr(r,Te(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Nt({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[De,Te,t,e,H]);let ke=Z.useMemo(()=>H.length===0||!we&&H.every(e=>Ee(e)),[H,we,Ee]),Ae=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),je=Z.useMemo(()=>Ae.length===0||Ae.every(e=>typeof e.time?.end==`number`),[Ae]),Me=typeof a!=`string`,Ne=Ae.length>0&&Ce&&(we||Me||!ke),Pe=B||Ce&&(we||Me||!ke),Fe=B||Ne,Ie=Ce||Ae.length>0,Le=U.length===0,Re=Ie&&Le&&!Pe&&!Fe&&ke&&je,ze=Z.useRef(!1),Be=Z.useRef(!1);Z.useEffect(()=>{Be.current=!1},[t]),Z.useEffect(()=>{if(!Re){ze.current=!1;return}ze.current||(ze.current=!0,S?.())},[Re,S]),Z.useEffect(()=>{if(B){Be.current=!1;return}if(Ce){Be.current=!1;return}Ae.length!==0&&(Fe||!je||Be.current||(Be.current=!0,y?.(`structural`)))},[B,Ce,y,je,Ae.length,Fe]);let Ve=!!b&&!B,He=K(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||de||ie)){fe(!0);try{await re(e,t)}finally{fe(!1)}}}),Ue=Z.useMemo(()=>{let e=w?.activityParts;return!ve||!e?[]:e},[ve,w?.activityParts]),We=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!ve||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ve,t,w?.activityGroupSegments]),Ge=We.length>0,Ke=Z.useMemo(()=>{let e=new Map,t=new Map;return Ue.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)}}},[Ue]),qe=w?.toggleGroup,Je=w?.activityPresentationKind===`compaction`,Ye=w?.isGroupExpanded===!0,Xe=ve&&Je&&!Ye,Ze=ve?w?.activityOwnerMessageId===t||Ge:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||Ge,Qe=ve&&Ze&&(Ge||Je)&&!!qe,$e=cT(a,V),et={finish:a,parts:V,streamPhase:Se,error:T,isLastAssistantInTurn:ye},tt=pT(et),nt=ve&&mT(et),rt=ve&&!tt&&!(Je&&Ye),it=!!T,at=E===`info`?`information`:`error-warning`,ot=Ve,ct=ye&&xe&&!Xe&&(b||!!T||i),ut=w?.diffStats?.hasDiffs===!0,dt=!G&&ye&&$e&&xe&&!Xe&&w?.diffStats?.hasDiffs===!0,ft=he&&ot&&!ct&&!ve,pt=Z.useMemo(()=>(0,$.jsx)(zD,{hasCopyableText:Ve,isTouchContext:L,onCopyMessage:x,ttsText:ee,reviewTransferAction:ue,sessionId:e}),[ee,Ve,L,x,ue,e]),mt=Z.useMemo(()=>e=>{if(!he||!ve)return null;let t=Xr(e.part).trim();return t?(0,$.jsx)(zD,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await lt(t)).ok,ttsText:t}):null},[ve,L,he]),ht=Z.useMemo(()=>{if(!ft)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||rt||Ke.get(n)?.kind!==`justification`&&(e=t)}return e},[Ke,rt,ft,V]),gt=ft&&ht<0,_t=Z.useMemo(()=>{let n=[];if(Qe&&qe&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(iD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:qe,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:Se,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:mt})},`progressive-group-${e}`))};We.length>0?We.forEach(t=>{let n=C?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Je&&e(`${t}:compaction-status`,[])}let r=0;for(;r<V.length;){let i=V[r];if(i.type===`text`){let a=Ke.get(i);if(rt){r+=1;continue}if(Xe){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(Bw,{part:i,sessionId:e,messageId:t,streamPhase:Se,chatRenderMode:pe,allowSortedFinalStreaming:nt,hasStreamingHapticLifecycle:De,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),ft&&r===ht&&n.push((0,$.jsx)(`div`,{className:u?cD:sD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:pD,"data-message-action-group":`true`,children:pt})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(Ke.get(i)?.kind===`reasoning`){r+=1;continue}if(!Xr(i).trim()){r+=1;continue}C&&(me?n.push((0,$.jsx)(`div`,{className:Op(u),children:(0,$.jsx)(Qw,{part:i,messageId:t,streamPhase:Se,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(Bw,{part:i,sessionId:e,messageId:t,streamPhase:Se,chatRenderMode:pe,hasStreamingHapticLifecycle:De,onContentChange:y,onShowPopup:g},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(ve&&!Ze){r+=1;continue}if(Ke.get(i)?.kind===`tool`){r+=1;continue}if(aC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!aC(r.tool?.toLowerCase()??``)||Ke.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(gE,{activities:e,isMobile:u,isTurnLive:Se!==`completed`,hasFollowingOtherType:fE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(XE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(oC(a)){let e=_E(V,r,e=>e.type!==`tool`||Ke.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)(SE,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(XE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(nC(a)){n.push((0,$.jsx)(`div`,{className:Op(u),children:(0,$.jsx)(bw,{part:e,messageId:t,isExpanded:m.has(e.id),onToggle:h,isMobile:u,alwaysShowActions:R,onContentChange:y,onShowPopup:g,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:Op(u),children:(0,$.jsx)(XE,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[Ke,We,R,pe,me,0,m,Xe,Je,u,Ze,ve,ht,t,pt,mt,e,y,g,h,Qe,ft,Se,De,C,rt,nt,qe,w,V]),vt=Z.useMemo(()=>{if(!ye||!xe)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return ID(e)},[ye,xe,w?.durationMs]),yt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof c==`number`&&c>0?c:null;if(e===null)return null;let t=$T(e,_e);return t.length>0?t:null},[o,c,_e,k]),bt=Z.useMemo(()=>{if(!ge||!ye||!xe)return null;let e=r??n,t=LD(e,l),i=iE({createdAt:c,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=aE(i);return a.length>0?a:null},[ge,ye,xe,n,r,l,c,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!G&&!u&&!W&&ne?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=se??(ae?oe(ae):null);e&&te(e,ne)},children:(0,$.jsx)(X,{weight:_D,name:`global`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!G&&!ce&&j.fork?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,size:`icon`,variant:`ghost`,className:lD,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":de,disabled:de||!!ie,onPointerDown:e=>e.stopPropagation(),onClick:e=>{He(e)},children:(0,$.jsx)(X,{weight:_D,name:de?`loader-4`:`git-branch`,className:Y(uD,de&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:N,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:aD,children:[(0,$.jsx)(YT,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[_t,it&&(0,$.jsx)(ds,{children:(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:at,weight:_D,className:Y(uD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:at,weight:E===`info`?_D:void 0,className:Y(`shrink-0`,E===`info`?Y(uD,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,E===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,u?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(Mo,{content:T??``,onShowPopup:g,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),dt&&w?.diffStats?(0,$.jsx)(OD,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(td,{files:n,messageID:t,sessionID:e,onShowPopup:g}),gt&&(0,$.jsx)(`div`,{className:Y(u?cD:sD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:pD,"data-message-action-group":`true`,children:pt})}),ct&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:oD,children:[(0,$.jsxs)(`div`,{className:pD,"data-message-action-group":`true`,children:[pt,xt]}),bt||vt||yt?(0,$.jsxs)(`div`,{className:mD,children:[bt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:hD,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:_D,name:`pulse`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(La,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,vt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:hD,children:[(0,$.jsx)(X,{weight:_D,name:`hourglass`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(La,{children:vt})]}):null,yt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:hD,"aria-label":`Message time: ${yt}`,children:[(0,$.jsx)(X,{weight:_D,name:`time`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(La,{children:yt})]}):null]}):null,!G&&ye&&be&&!ut?(0,$.jsx)(nT,{activityParts:w?.activityParts}):null]})]})]})}),VD=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)(RD,{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)(BD,{...r}),t[26]=r,t[27]=i),i});function HD(e){return e.openContextPanelTab}function UD(e){return e.setCurrentSession}function WD(e){return e.openContextPanelTab}function GD(e){return!e}function KD(e){return e.openContextPanelTab}function qD(e){return!e}var JD=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}},YD=`Authentication failed for this provider. Please re-authenticate and retry.`,XD=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},ZD=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,QD=e=>!e,$D=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},eO=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),tO=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,nO=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,rO=Fo(()=>We(()=>import(`./ToolOutputDialog-UAKu6b6Z.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]))),iO=4e3,aO=new Map,oO=new Map,sO=new Set([`bash`,`shell`,`cmd`,`terminal`]),cO=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},lO=e=>{let t=aO.get(e);return t?new Set(t):new Set},uO=(e,t)=>{if(aO.size>=iO&&!aO.has(e)){let e=aO.keys().next().value;typeof e==`string`&&aO.delete(e)}aO.set(e,new Set(t))},dO=e=>{let t=oO.get(e);return t?new Set(t):new Set},fO=(e,t)=>{if(oO.size>=iO&&!oO.has(e)){let e=oO.keys().next().value;typeof e==`string`&&oO.delete(e)}oO.set(e,new Set(t))},pO=200,mO=new Map,hO=e=>mO.get(e),gO=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=mO.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(mO.size>=pO&&!mO.has(e)){let e=mO.keys().next().value;typeof e==`string`&&mO.delete(e)}mO.set(e,t)}};function _O(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 vO=(e,t)=>{if(typeof e==`object`&&e)return e[t]},yO=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{isMobile:p,isTablet:m,hasTouchInput:h}=fo(),g=Qm(),_=$m(g),v=p||m,y=Z.useRef(null),b=J(e=>e.currentSessionId),x=Vt(e=>e.getAgentModelForSession),S=Vt(e=>e.getSessionModelSelection),C=J(e=>e.revertToMessage),w=J(e=>e.editMessagePreservingChanges),T=J(e=>e.forkFromMessage),E=J(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=J(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=J(e=>e.clearStagedMessageEdit);Le(`ui.chat_message.render`),c&&Le(`ui.chat_message.render.streaming`);let k=mi(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=s(he(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Jb.getInstance().recordSessionStart(b)},[b]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>lO(e.info.id)),[U,ee]=Z.useState(()=>dO(e.info.id)),[te,W]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(lO(e.info.id)),ee(dO(e.info.id))},[e.info.id]);let G=Z.useMemo(()=>JD(e.info),[e.info]).isUser,ne=G&&(p||!j),re=G&&!p&&j&&!ne,ie=e.info.sessionID,ae=Zb(e=>e.planModeEnabled),{currentContextAgent:oe,savedSessionAgentSelection:se}=Up(he(e=>({currentContextAgent:c&&ie?e.currentAgentContext.get(ie):void 0,savedSessionAgentSelection:c&&ie?e.sessionAgentSelections.get(ie):void 0}))),ce=Z.useMemo(()=>pn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),le=Z.useMemo(()=>G?q(ce,{planModeEnabled:ae}):pn(e.parts),[G,e.parts,ae,ce]),ue=Z.useMemo(()=>{if(G||!t)return null;let e=vO(t.info,`clientRole`),n=vO(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=vO(t.info,`mode`),i=vO(t.info,`agent`),a=vO(t.info,`providerID`),o=vO(t.info,`modelID`),s=vO(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=vO(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[G,t]),de=Z.useMemo(()=>{if(!ae||G||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[G,ae,t]),fe=Z.useMemo(()=>{if(G)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&de&&ue?.agentName)return ue.agentName;let n=vO(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=vO(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(ue?.agentName)return ue.agentName;if(ie)return oe||(se??void 0)},[G,e.info,de,ue,ie,oe,se]),pe=G?null:vO(e.info,`providerID`),me=G?null:vO(e.info,`modelID`),ge=Z.useMemo(()=>{if(G||!ie)return null;if(ue?.providerId&&ue?.modelId)return{providerId:ue.providerId,modelId:ue.modelId};if(fe){let e=x(ie,fe);if(e?.providerId&&e?.modelId)return e}let e=S(ie);return e?.providerId&&e?.modelId?e:null},[G,ie,fe,ue,x,S]),_e=Z.useMemo(()=>G?null:typeof pe==`string`&&pe.trim().length>0?pe:ge?.providerId??null,[G,pe,ge]),ve=Z.useMemo(()=>G?null:typeof me==`string`&&me.trim().length>0?me:ge?.modelId??null,[G,me,ge]),ye=e.info.id?hO(e.info.id):void 0;G||gO(e.info.id,{agent:fe,provider:_e??void 0,model:ve??void 0});let be=fe??ye?.agent,xe=_e??ye?.provider??null,Se=ve??ye?.model??null,Ce=Z.useMemo(()=>{if(G)return;let e=xe&&k.length>0?k.find(e=>e.id===xe):void 0;return pt(e,Se)||void 0},[G,xe,Se,k]),we=Z.useMemo(()=>{if(G||!_e||!ve)return!1;let e=k.find(e=>e.id===_e);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===ve)?.variants;return!!(t&&Object.keys(t).length>0)},[G,ve,_e,k]),Te=_O(be),Ee=_O(xe??void 0),De=_O(Se??void 0),Oe=_O(Ce),ke=Te??void 0,Ae=Ee??null,je=De??null,Me=Oe??void 0,Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Pe=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Fe=Z.useMemo(()=>G?!0:!!(Ne&&Ne>0),[G,Ne]),Ie=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Re=Z.useMemo(()=>{if(G)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[G,e.info]),ze=Z.useMemo(()=>_t(le,{includeReasoning:A}),[le,A]),Be=Z.useMemo(()=>G?ze:!Fe&&M===`sorted`?[]:ze,[M,Fe,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(!N)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=cO(t.tool);!r||!sO.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=cO(t.part.tool);!n||!sO.has(n)||e.add(t.id)}return e},[N,He,a?.activityParts]),We=Z.useMemo(()=>{if(Ue.size===0&&U.size===0)return V;let e=new Set(V);return Ue.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,Ue,V]),Ge=Z.useMemo(()=>{if(!G)return;let e=le.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,le]),Ke=G&&!wt(Be),qe=typeof Ie!=`string`,Je=Z.useMemo(()=>G?!1:Ve.length===0||He.length===0?qe:!0,[Ve.length,He.length,qe,G]),Ye=Z.useMemo(()=>!G&&Jb.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,G]),[Xe,Ze]=Z.useState(!1),Qe=Z.useMemo(()=>n?JD(n.info):null,[n]),$e=!!a,et=a?.isLastAssistantInTurn??!1,tt=tO({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),nt=Z.useMemo(()=>G?!1:$e?!et:Qe?!Qe.isUser&&Qe.role===`assistant`:!1,[$e,et,G,Qe]),rt=Z.useMemo(()=>Fe?`completed`:c?l??`streaming`:`completed`,[l,c,Fe]);Z.useEffect(()=>{!G||!u||d?.(e.info.id)},[u,G,e.info.id,d]),Z.useEffect(()=>{Ze(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;G||!t||t!==e.info.id||(rt===`streaming`||rt===`cooldown`)&&Ze(!0)},[o,G,e.info.id,rt,a?.headerMessageId]);let it=Z.useMemo(()=>{if(G)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?rt===`completed`||Xe||rt===`streaming`||rt===`cooldown`:!1:!0},[o,Xe,G,a,rt,e.info.id]),at=Z.useCallback(e=>{lt(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),ot=G?void 0:a?.userMessageVariant??ue?.variant,st=!G&&we&&typeof ot==`string`&&ot.trim().length>0?ot:void 0,ct=Z.useMemo(()=>{if(G)return;let t=e.info?.error;if(!t)return;let n=typeof t.data?.message==`string`?t.data.message:void 0,r=typeof t.message==`string`?t.message:void 0,i=typeof t.name==`string`?t.name:void 0,a=n||r||i;if(a)return i===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${a}\``,variant:`info`}:XD(a)?{text:YD,variant:`error`}:a.trim().toLowerCase()===`aborted`?{text:`The running turn was stopped before OpenCode could send the next message.`,variant:`info`}:{text:`Opencode failed to send message with error:\n\`${a}\``,variant:`error`}},[G,e.info]),ut=ct?.text,dt=ct?.variant,ft=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(`
6576
+ `).trim()||zT(t)},YT=({containerRef:e})=>{let{t}=ot(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,c]=Z.useState(``),l=Z.useRef(!1),[u,d]=Z.useState(!1),f=Z.useRef(null),p=Z.useRef(FT),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(null),_=Z.useRef(!1),v=Qr(e=>e.createSession),y=It(e=>e.setPendingInputText),b=s(e=>e.isMobile),x=$m(Qm()).textSelectionMutation;Z.useEffect(()=>{_.current=n.show},[n.show]),Z.useEffect(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]);let S=Z.useCallback(()=>{m.current=null,IT===S&&(IT=null),_.current&&=(h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),d(!1),r(e=>({...e,show:!1})),a(``),c(``),!1)},[]);Z.useEffect(()=>()=>{IT===S&&(IT=null)},[S]);let C=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=p.current/2,r=PT+n,i=t-PT-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),w=Z.useCallback(()=>{if(!m.current)return;IT!==S&&(IT?.(),IT=S);let{plainText:e,markdownText:t,rect:i}=m.current,o=!n.show,s=b?i.left+i.width/2:C(i.left+i.width/2),l=i.top-10;a(e),c(t),r({x:s,y:l,show:!0}),_.current=!0,o&&(d(!0),h.current!==null&&window.cancelAnimationFrame(h.current),h.current=window.requestAnimationFrame(()=>{d(!1),h.current=null}))},[C,S,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!f.current)return;let e=f.current.offsetWidth;!Number.isFinite(e)||e<=0||e===p.current||(p.current=e,r(e=>({...e,x:C(e.x)})))},[C,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:C(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[C,b,n.show]);let T=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||S();return}let r=zT(t.toString());if(!r){l.current||S();return}let i=HT(t,n);if(!i){l.current||S();return}let a=i.getBoundingClientRect();m.current={plainText:r,markdownText:JT(i,r),rect:a},l.current||w()},[e,S,w]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,S()},r=()=>{l.current=!1,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{g.current=null,T()},10)},i=new Set,a=()=>{for(let e of VT(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,T))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,T),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{f.current&&!f.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&S()};return document.addEventListener(`mousedown`,s),()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,T);document.removeEventListener(`selectionchange`,T),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,T,S,w]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{f.current&&e.target instanceof Node&&f.current.contains(e.target)||S()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,S]);let E=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;y(t,`append`),S(),window.getSelection()?.removeAllRanges()},[y,S]),D=Z.useCallback(()=>{E(o)},[E,o]);Z.useEffect(()=>{let t=t=>{if(!x||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=HT(n,r);i&&(t.preventDefault(),E(JT(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[E,x,e]);let O=Z.useCallback(async()=>{i&&(await v(void 0,null,null)&&y(i,`replace`),S(),window.getSelection()?.removeAllRanges())},[i,v,y,S]),k=Z.useCallback(async()=>{if(!i)return;let e=await ct(i);e.ok||console.error(`Failed to copy:`,e.error),S(),window.getSelection()?.removeAllRanges()},[i,S]);return n.show?b?(0,xc.createPortal)((0,$.jsx)(`div`,{ref:f,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,xc.createPortal)((0,$.jsx)(`div`,{ref:f,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(fp,{shortcut:`⌘+I`})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},XT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),ZT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),XT(e,n)},QT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),$T=(e,t)=>{if(!QT(e))return``;let n=new Date(e),r=new Date,i=lo(n,t),a=st(),o=lt.getState().dictionary;if(XT(n,r))return i;if(ZT(n,r))return ut(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}`},eE=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,tE=e=>e,nE=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=tE(n);if(e.type!==`tool`)continue;let r=e.state,i=r?.time?.start,a=r?.time?.end;typeof i!=`number`||!Number.isFinite(i)||typeof a!=`number`||!Number.isFinite(a)||a<i||(t+=a-i)}return t},rE=(e,t,n,r)=>{let i=(typeof e==`number`&&Number.isFinite(e)&&e>0&&typeof t==`number`&&Number.isFinite(t)&&t>e?t-e:null)??(typeof r==`number`&&Number.isFinite(r)&&r>0?r:null);if(i===null)return null;let a=i-nE(n);return!Number.isFinite(a)||a<=0?null:a},iE=e=>{let t=rE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=eE(e.outputTokens)+eE(e.reasoningTokens);if(n<=0)return null;let r=t/1e3;if(r<=0)return null;let i=n/r;return!Number.isFinite(i)||i<=0?null:i},aE=e=>{if(!Number.isFinite(e)||e<=0)return``;if(e>=1e3){let t=e/1e3;return`${t>=10?t.toFixed(0):t.toFixed(1)}k tok/s`}return e>=100?`${Math.round(e)} tok/s`:e>=10?`${e.toFixed(1)} tok/s`:`${e.toFixed(2)} tok/s`},oE=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=q(f),m;t[5]===i?m=t[6]:(m=Y(`oc-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:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-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},sE=[`search`,`read`,`list`];function cE(e){let t=lC(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function lE(e){let t={read:0,search:0,list:0};for(let n of e){let e=cE(n);e&&(t[e]+=1)}return t}function uE(e){return cC(e)}function dE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!aC(e.toolName):e.kind!=null||e.type!=null}function fE(e,t,n){for(let r=t;r<e.length;r+=1)if(dE(n(e[r])))return!0;return!1}function pE(e){return`parts`in e?e.parts.some(e=>uE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>uE(e))}function mE(e,t,n){let r=[],i=t;for(;i<e.length&&aC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var hE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,gE=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=ot(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??pE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=lE(u.map(e=>e.tool)),p=sE.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`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=q(()=>{c(e=>!e)}),h=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:Op(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,kp),onClick:m,onKeyDown:h,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,v,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(qS,{isMobile:t,label:o(`chat.contextGroup.exploring`),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`,v,hE,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:_}),p?(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`,v,hE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(oE,{text:p,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(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:`relative ml-2 pl-3 pt-0.5`,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 _E(e,t,n){let r=[],i=t;for(;i<e.length&&oC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var vE=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function yE(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=vE(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=vE(e.name);if(t)return t;let r=vE(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=vE(n.output.name);if(e)return e}return null}function bE(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 xE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,SE=({activities:e,isMobile:t,children:n})=>{let{t:r}=ot(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>cC(e)),{joinedVisible:l,hiddenCount:u}=bE(s.map(yE)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=q(()=>{a(e=>!e)}),p=q(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:Op(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`,kp),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)(qS,{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`,xE,c&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...c?{"--oc-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`,xE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(oE,{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:`relative ml-2 pl-3 pt-0.5`,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]})},CE=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:c}=e,l=s(wE),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==c||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(Bw,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:c})}),t[4]=l,t[5]=r,t[6]=i,t[7]=c,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=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]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function wE(e){return e.chatRenderMode}var TE=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},EE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,DE=Y(`typography-meta font-medium`,EE),OE=Y(`typography-meta`,EE),kE=[],AE=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},jE=e=>{let t=new Set;for(let n of e)AE(n)&&n.messageId&&t.add(n.messageId);return[...t]},ME=(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}),NE=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=Zo(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},PE=e=>e,FE=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},IE=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},LE=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},RE=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},zE=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=RE(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`}`},BE=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=zE(n.todos);if(e)return e}if(Array.isArray(r)){let e=zE(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=zE(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=zE(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=zE(e.todos);if(t)return t}}catch{}return null},VE=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)},HE=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(dx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,OE),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`,OE),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)(dx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},UE=e=>{let t=yo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},WE=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 yE(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`?BE(e):FE(e)},GE=e=>{let t=[],n=[];for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(e.tool?.trim().toLowerCase()!==`task`)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;n.push(i),(o.status===`pending`||o.status===`running`)&&t.push(i)}return{active:t,all:n}},KE=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=q(c),u;t[3]===i?u=t[4]:(u=Op(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)(bw,{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&&$x([e.activity.part],[t.activity.part])),qE=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=Op(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(XE,{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&&YE(e.activities,t.activities)),JE=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Yr(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(aC(i)){let r=mE(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:fE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(oC(i)){let r=_E(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(rC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(nC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(iC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},YE=(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||!$x([r.part],[i.part]))return!1}return!0},XE=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ot(),c=s(eD),l=$o(n,o),u;t[0]===n?u=t[1]:(u=fx(n),t[0]=n,t[1]=u);let d=u,f;t[2]===n?f=t[3]:(f=n.toLowerCase(),t[2]=n,t[3]=f);let p=f===`read`,m=Z.useContext(Oo),h=_h(),g=Te(tD),_=Qm(),v=_.kind===`embedded`?_.directory:g,y;t[4]===n?y=t[5]:(y=n.toLowerCase(),t[4]=n,t[5]=y);let b=y===`skill`,x;t[6]===b?x=t[7]:(x={enabled:b},t[6]=b,t[7]=x);let S=ti(x),C;t[8]===S.data?C=t[9]:(C=S.data??[],t[8]=S.data,t[9]=C);let w=C,T;t[10]===w?T=t[11]:(T=new Map(w.map(nD)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||cC(D.part),k;t[12]===D?k=t[13]:(k=D?WE(D):null,t[12]=D,t[13]=k);let A=k,j;if(t[14]!==A||t[15]!==D||t[16]!==E||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!D||!A){j=null;break bb0}let e=E.get(A)?.path||LE(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=UE(e);if(!r){j=null;break bb0}let i;t[19]!==A||t[20]!==r?(i={name:A,path:r},t[19]=A,t[20]=r,t[21]=i):i=t[21],j=i}t[14]=A,t[15]=D,t[16]=E,t[17]=n,t[18]=j}else j=t[18];let M=j,N;if(t[22]!==v||t[23]!==p||t[24]!==D){bb1:{if(!p||!D){N=null;break bb1}let e=IE(D);if(!e){N=null;break bb1}let n=_o(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=VE(D),t[26]=D,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],N=i}t[22]=v,t[23]=p,t[24]=D,t[25]=N}else N=t[25];let P=N,F;t[32]!==v||t[33]!==h||t[34]!==m?(F=(e,t)=>{if(!v)return;let n=vo(v,e);if(!n)return;if(h){h.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(m?.editor){m.editor.openFile(n,t);return}if(!So(n,v)){as(n,v).then(()=>{let e=s.getState(),r=v||go(v,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=s.getState(),i=go(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=q(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=yo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=s.getState(),n=v||go(``,t);e.openContextFile(n,t)};if(v&&!So(t,v)){as(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=q(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,W=!!(P||M),ee=!!(P&&v||M),G;t[41]!==ee||t[42]!==I||t[43]!==R||t[44]!==W||t[45]!==P||t[46]!==M?(G=()=>{if(!(!W||!ee)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=ee,t[42]=I,t[43]=R,t[44]=W,t[45]=P,t[46]=M,t[47]=G):G=t[47];let K=q(G),te;t[48]===K?te=t[49]:(te=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K())},t[48]=K,t[49]=te);let ne=q(te),re=W&&ee&&`cursor-pointer`,ie=W&&!ee&&`cursor-default opacity-70`,ae;t[50]!==re||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,kp,re,ie),t[50]=re,t[51]=ie,t[52]=ae):ae=t[52];let oe=W?`soft`:void 0,se=W?K:void 0,ce=W?ne:void 0,le=W?`button`:void 0,ue=W&&ee?0:void 0,de=W&&!ee?!0:void 0,fe=i?`size-4`:`size-3.5`,pe;t[53]===fe?pe=t[54]:(pe=Y(`inline-flex items-center justify-center flex-shrink-0`,fe),t[53]=fe,t[54]=pe);let me;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(me={color:`var(--tools-icon)`},t[55]=me):me=t[55];let he=O?(0,$.jsx)(qS,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,ge;t[56]!==pe||t[57]!==me||t[58]!==he?(ge=(0,$.jsx)(`div`,{className:pe,style:me,children:he}),t[56]=pe,t[57]=me,t[58]=he,t[59]=ge):ge=t[59];let _e,ve;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(_e=Y(DE,`inline-flex items-center flex-shrink-0 opacity-85`),ve={color:`var(--tools-title)`},t[60]=_e,t[61]=ve):(_e=t[60],ve=t[61]);let ye;t[62]===l?ye=t[63]:(ye=(0,$.jsx)(`span`,{className:_e,style:ve,title:l,children:l}),t[62]=l,t[63]=ye);let be;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==c?(be=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,OE),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[c?(0,$.jsx)(ku,{filePath:P.path,className:`h-3.5 w-3.5`}):null,HE(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=c,t[68]=be):be=t[68];let xe;t[69]!==a||t[70]!==A||t[71]!==V?(xe=V&&A?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(dx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,OE),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=xe):xe=t[72];let Se;t[73]!==A||t[74]!==H?(Se=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:rD,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`,OE),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(NE,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=Se):Se=t[75];let Ce;t[76]!==U||t[77]!==M?(Ce=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,OE),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=Ce):Ce=t[78];let we;t[79]!==A||t[80]!==U||t[81]!==M?(we=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,OE),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=we):we=t[82];let Ee;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Ee=!p&&!V&&!H&&!U&&A?(0,$.jsx)(dx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,OE),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=Ee):Ee=t[89];let De;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==le||t[95]!==ue||t[96]!==de||t[97]!==ge||t[98]!==ye||t[99]!==be||t[100]!==xe||t[101]!==Se||t[102]!==Ce||t[103]!==we||t[104]!==Ee?(De=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:le,tabIndex:ue,"aria-disabled":de,children:[ge,ye,be,xe,Se,Ce,we,Ee]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=le,t[95]=ue,t[96]=de,t[97]=ge,t[98]=ye,t[99]=be,t[100]=xe,t[101]=Se,t[102]=Ce,t[103]=we,t[104]=Ee,t[105]=De):De=t[105],De},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&YE(e.activities,t.activities)),ZE=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)(Qw,{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}),QE=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)(CE,{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}),$E=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}=ot(),_=is()??``,v=Z.useMemo(()=>jE(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?TE(o):null,D=i===`normal`||i===`abnormal`,O=a===`compaction`,k=O?`fold-vertical`:`stack`,A=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`),j=Z.useMemo(()=>GE(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=q((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=Wi(_,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=Bi(_,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)}}),F=q(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=q(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),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)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].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 Wi(_,n,e).status}),U=H.includes(`loading`),W=H.includes(`error`),ee=H.length>0&&H.every(e=>e===`ready`),G=t.some(e=>V.has(e.messageId)&&AE(e)),K=ee&&!G&&!ME(t,V),te=Z.useMemo(()=>B?PE(e):kE,[e,B]),ne=Z.useMemo(()=>B?JE(te):[],[B,te]),re=Z.useMemo(()=>L||z===0?0:Math.max(0,ne.length-z),[L,z,ne.length]),ie=Z.useMemo(()=>L||z===0?ne:ne.slice(-z),[L,z,ne]);if((!m||I&&!O)&&ne.length===0)return null;let ae=(e,t)=>{let n=(0,$.jsx)(`div`,{className:Op(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},oe=B?ie.map((e,t)=>{switch(e.type){case`reasoning`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(ZE,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(QE,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(KE,{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)(qE,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(gE,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(XE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(SE,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(XE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(KE,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,se=ie.length>0;return m?(0,$.jsxs)(`div`,{className:Op(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&kp,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),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)(qS,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,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)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),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 justify-end`,c?`gap-0.5`:`gap-1`),children:[M.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:N.map((e,t)=>(0,$.jsx)(ea,{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:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`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`)})]})]}),se?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?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)`}}),re>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,re,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:oe})]}):null,L&&(U||W||K)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,W&&`text-[var(--status-error)]`),role:W?`alert`:`status`,children:U?(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`)})]}):W?(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)(la,{type:`button`,variant:`ghost`,size:`xs`,onClick:F,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]}):(0,$.jsx)(`div`,{className:Op(c),children:oe})});function eD(e){return e.showToolFileIcons}function tD(e){return e.currentDirectory}function nD(e){return[e.name,e]}function rD(e){e.stopPropagation()}var iD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)($E,{...e}),t[0]=e,t[1]=n),n}),aD={contain:`layout`},oD={containerType:`inline-size`,containerName:`message-footer`},sD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,cD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,lD=`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`,uD=`size-3.5!`,dD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,fD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,pD=`flex items-center gap-2`,mD=`flex items-center gap-2 text-muted-foreground`,hD=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,gD=`size-3.5!`,_D=`medium`,vD=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,yD=`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)]`,bD=`h-7 gap-1.5`,xD=`h-6 gap-1`,SD=`text-[11px] leading-none`,CD=`size-3.5`,wD=`size-3`,TD=5,ED=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)(ku,{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=vD(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}),DD=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ot(),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=q(s),l=!r,u=i?xD:bD,d;t[3]===u?d=t[4]:(d=Y(yD,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)(ED,{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)(la,{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}),OD=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:c}=ot(),l=is(),u=Qm(),d=u.directory||l,f=u.sessionId,p=_h(),m=s(HD),h;t[0]===r?h=t[1]:(h=r??[],t[0]=r,t[1]=h);let g=h,_;t[2]===g?_=t[3]:(_=g.slice(0,TD),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==c?(S=c(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=c,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==c?(w=c(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=c,t[9]=w):w=t[9];let T=w,E=Y(yD,o?xD:bD),D=o?wD:CD,O;t[10]===o?O=t[11]:(O=o?Y(SD,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=O);let k=O,A;t[12]===o?A=t[13]:(A=o?Y(SD,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=A);let j=A,M;t[14]===o?M=t[15]:(M=o?Y(SD,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=M);let N=M,P;t[16]!==d||t[17]!==f||t[18]!==a||t[19]!==o||t[20]!==p||t[21]!==i?(P=e=>{if(p){p.openTurnDiff(i,f,e);return}if(!o&&d){tT({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&tT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=q(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&tT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=q(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===c?V=t[35]:(V=c(`diffView.actions.reviewAria`),t[34]=c,t[35]=V);let H;t[36]===c?H=t[37]:(H=c(`diffView.actions.reviewAria`),t[36]=c,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let W=`turn-changes-${i}`,ee;t[40]===c?ee=t[41]:(ee=c(`chat.changedFiles.title`),t[40]=c,t[41]=ee);let G;t[42]!==W||t[43]!==ee||t[44]!==k?(G=(0,$.jsx)(`span`,{id:W,className:k,children:ee}),t[42]=W,t[43]=ee,t[44]=k,t[45]=G):G=t[45];let K;t[46]!==C||t[47]!==j?(K=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=K):K=t[48];let te;t[49]===D?te=t[50]:(te=Y(D,`opacity-60`),t[49]=D,t[50]=te);let ne;return t[51]===te?ne=t[52]:(ne=(0,$.jsx)(X,{name:`arrow-right-s`,className:te}),t[51]=te,t[52]=ne),(0,$.jsxs)(`section`,{className:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,G,K,ne]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(DD,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":c(`diffView.actions.reviewAria`),title:c(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),kD=e=>e.type===`subtask`,AD=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},jD=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}`},MD=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=is(),{isMobile:o}=fo(),c=Qr(UD),l=s(WD),u=Qm(),{t:f}=ot(),p;t[0]===n.description?p=t[1]:(p=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=p);let m=p,h;t[2]===n.command?h=t[3]:(h=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=h);let g=h,_;t[4]===n.agent?_=t[5]:(_=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=_);let v=_,y;t[6]===n.prompt?y=t[7]:(y=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=y);let b=y,x;t[8]===n.taskSessionID?x=t[9]:(x=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=x);let S=x,C;t[10]===n.model?C=t[11]:(C=jD(n.model),t[10]=n.model,t[11]=C);let w=C,T=!!b&&!(o&&u.kind===`primary`),E;t[12]===f?E=t[13]:(E=f(`chat.messageBody.subtask.title`),t[12]=f,t[13]=E);let D;t[14]===E?D=t[15]:(D=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:E}),t[14]=E,t[15]=D);let O;t[16]===g?O=t[17]:(O=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,g]}):null,t[16]=g,t[17]=O);let k;t[18]===v?k=t[19]:(k=v?(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:[`@`,v]}):null,t[18]=v,t[19]=k);let A;t[20]===w?A=t[21]:(A=w?(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:w}):null,t[20]=w,t[21]=A);let j;t[22]!==k||t[23]!==A||t[24]!==D||t[25]!==O?(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D,O,k,A]}),t[22]=k,t[23]=A,t[24]=D,t[25]=O,t[26]=j):j=t[26];let M;t[27]===m?M=t[28]:(M=m?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:m}):null,t[27]=m,t[28]=M);let N;t[29]!==r||t[30]!==b||t[31]!==T||t[32]!==f?(N=T?(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(GD),children:f(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:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==c||t[41]!==f||t[42]!==S?(P=S&&u.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=u.directory||a;e&&eh(u,S,e,()=>{if(!ci({sessionId:S,directory:e})){if(Ac()||o||d()){c(S,e);return}l(e,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=c,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},ND=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=is(),i=s(KD),{isMobile:a}=fo(),{t:o}=ot(),c;t[0]!==r||t[1]!==a?(c=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=c):c=t[2];let l=!!c,u;t[3]!==n.state||t[4]!==o?(u=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]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=q(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=q(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=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`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(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]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=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`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Mo,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=j);let M;t[23]!==A||t[24]!==j?(M=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[A,j]}),t[23]=A,t[24]=j,t[25]=M):M=t[25];let N;return t[26]!==w||t[27]!==M||t[28]!==y||t[29]!==b||t[30]!==x||t[31]!==S||t[32]!==C?(N=(0,$.jsxs)(`div`,{className:y,role:b,tabIndex:x,"aria-label":S,onClick:C,onKeyDown:w,children:[T,M]}),t[26]=w,t[27]=M,t[28]=y,t[29]=b,t[30]=x,t[31]=S,t[32]=C,t[33]=N):N=t[33],N},PD={background:`transparent`,backgroundColor:`transparent`},FD=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ot(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=q(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await ct(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=q(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Qs,{language:`bash`,code:u,codeStyle:PD,wrap:!0})}):null,t[23]=u,t[24]=E);let D;t[25]!==a||t[26]!==x||t[27]!==r||t[28]!==h||t[29]!==d||t[30]!==c?(D=h?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(qD),children:c(r?`chat.messageBody.shellCommand.hideOutput`:`chat.messageBody.shellCommand.showOutput`)}),(0,$.jsx)(`button`,{type:`button`,className:`inline-flex items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>{x()},"aria-label":c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:a?(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`h-3.5 w-3.5`})})]}),r?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 max-h-56 overflow-auto font-mono text-foreground/85`,children:(0,$.jsx)(Qs,{language:`bash`,code:d,codeStyle:PD,wrap:!0})}):null]}):null,t[25]=a,t[26]=x,t[27]=r,t[28]=h,t[29]=d,t[30]=c,t[31]=D):D=t[31];let O;return t[32]!==T||t[33]!==E||t[34]!==D?(O=(0,$.jsxs)(`div`,{className:`mt-2`,children:[T,E,D]}),t[32]=T,t[33]=E,t[34]=D,t[35]=O):O=t[35],O},ID=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},LD=(e,t)=>{if(t&&typeof t==`object`)return{output:typeof t.output==`number`&&Number.isFinite(t.output)?Math.max(0,t.output):0,reasoning:typeof t.reasoning==`number`&&Number.isFinite(t.reasoning)?Math.max(0,t.reasoning):0};for(let t of e){let e=t.tokens;if(!(!e||typeof e!=`object`))return{output:typeof e.output==`number`&&Number.isFinite(e.output)?Math.max(0,e.output):0,reasoning:typeof e.reasoning==`number`&&Number.isFinite(e.reasoning)?Math.max(0,e.reasoning):0}}return{output:0,reasoning:0}},RD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:c,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=ot(),T=Fh(),E=$m(Qm()),D=s(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Kr(e):!!(kD(e)||AD(e))),[n]),M=Z.useMemo(()=>j.map(e=>on(e)?Mx(Yr(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(c??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=q(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=q(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let W=q(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),ee=T===`mini-chat`||!E.fork?void 0:g,G=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=$T(i,D);return e.length>0?e:null},[C,i,D]),K=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),te=!v&&y&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(pD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(hD,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:_D,name:`edit`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:_D,name:`close`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,ne=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(pD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(hD,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??te??((F&&R||m||h||ee)&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(pD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[G?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(hD,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:_D,name:`time`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(La,{children:G})]}):null,h&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.revertAria`),"aria-busy":_===`revert`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),h()},children:(0,$.jsx)(X,{weight:_D,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(uD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:_D,name:`edit`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":w(`chat.messageBody.actions.forkAria`),"aria-busy":_===`fork`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),ee()},children:(0,$.jsx)(X,{weight:_D,name:_===`fork`?`loader-4`:`git-branch`,className:Y(uD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:lD,"aria-label":w(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:W,onFocus:()=>k(!0),onBlur:()=>{I||k(!1)},children:I?(0,$.jsx)(X,{weight:_D,name:`check`,className:Y(uD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:_D,name:`file-copy`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:aD,onTouchStart:L&&F&&R?U:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,V?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:V?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:j.map((e,i)=>{if(kD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(MD,{part:e})},e.id??`user-subtask-${i}`);if(AD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(FD,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ND,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Yr(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(lx,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(td,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),ne]}):(0,$.jsx)($.Fragment,{children:ne})}),zD=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ot(),s=Fh(),c=Qm(),l=$m(c),{isPlaying:u,play:d,stop:f}=NT(),p=mi(e=>e.showMessageTTSButtons),m=mi(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=q(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=q(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=q(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=q(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=q(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=q(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=q(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(lD,!e&&`opacity-50`),disabled:!e,"aria-label":o(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!e,onPointerDown:e=>e.stopPropagation(),onClick:e=>{O(e)},onFocus:()=>{e&&g(!0)},onBlur:()=>{_||g(!1)},children:_?(0,$.jsx)(X,{weight:_D,name:`check`,className:Y(uD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:_D,name:`file-copy`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:_D,name:`target`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(lD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:_D,name:`loader-4`,className:Y(uD,`animate-spin`)}):(0,$.jsx)(X,{weight:_D,name:`arrow-left-right`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:Y(lD,u?`text-green-500`:`hover:text-foreground/80`),"aria-label":o(u?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),onPointerDown:e=>e.stopPropagation(),onClick:M,children:u?(0,$.jsx)(X,{weight:_D,name:`stop`,className:uD}):(0,$.jsx)(X,{weight:_D,name:`volume-up`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:j})]})]})}),BD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:c,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=ot(),A=Fh(),j=$m(Qm()),M=_,N=Z.useRef(null),P=Z.useRef(null),F=_===`streaming`||_===`cooldown`,I=Z.useRef({messageId:t,experiencedStreamingOrCooldown:F});I.current.messageId===t?F&&(I.current.experiencedStreamingOrCooldown=!0):I.current={messageId:t,experiencedStreamingOrCooldown:F};let L=!!(p??u),R=!!(f??u),z=u?fD:dD,B=!i,V=Z.useMemo(()=>n.filter(e=>!Kr(e)).filter(e=>e.type!==`compaction`),[n]),H=Z.useMemo(()=>V.filter(e=>e.type===`tool`),[V]),U=Z.useMemo(()=>V.filter(e=>e.type===`text`),[V]),W=Z.useMemo(()=>en(U),[U]),ee=s(e=>e.openContextPreview),G=d(),K=A===`mini-chat`,te=Z.useMemo(()=>{if(G||u||K)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=Qo(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 H){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=Qo(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},[U,u,K,G,H]),ne=Qr(e=>e.forkFromMessage),re=Qr(e=>e.forkTransition),ie=Qr(e=>e.currentSessionId),ae=Qr(e=>e.getDirectoryForSession),oe=is(),se=D===`review-to-original`,ce=!u&&!G?D:null,le=Z.useMemo(()=>{let t=W.trim();if(!(!e||!oe||!t||!ce))return ce===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await _n(e,oe,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await pn(e,oe,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[W,oe,ce,e,O]),[ue,de]=Z.useState(!1),fe=s(e=>e.chatRenderMode),pe=s(e=>e.collapsibleThinkingBlocks),me=s(e=>e.showSplitAssistantMessageActions),he=s(e=>e.showAssistantTps),ge=s(e=>e.timeFormatPreference),_e=fe===`sorted`,ve=w?.isLastAssistantInTurn??!1,ye=a===`stop`,be=(ye||i||!!T)&&(w?.isTurnSettled??!0),xe=ye?`completed`:M,Se=H.length>0,Ce=Z.useMemo(()=>H.some(e=>cC(e)),[H]),we=cC,Te=sC,Ee=I.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||!bn())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Xr(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Mt({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Ee,we,t,e,H]);let Oe=Z.useMemo(()=>H.length===0||!Ce&&H.every(e=>Te(e)),[H,Ce,Te]),ke=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),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=B||Se&&(Ce||je||!Oe),Pe=B||Me,Fe=Se||ke.length>0,Ie=U.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,S?.())},[Le,S]),Z.useEffect(()=>{if(B){ze.current=!1;return}if(Se){ze.current=!1;return}ke.length!==0&&(Pe||!Ae||ze.current||(ze.current=!0,y?.(`structural`)))},[B,Se,y,Ae,ke.length,Pe]);let Be=!!b&&!B,Ve=q(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ue||re)){de(!0);try{await ne(e,t)}finally{de(!1)}}}),He=Z.useMemo(()=>{let e=w?.activityParts;return!_e||!e?[]:e},[_e,w?.activityParts]),Ue=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!_e||!e?[]:e.filter(e=>e.anchorMessageId===t)},[_e,t,w?.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=w?.toggleGroup,qe=w?.activityPresentationKind===`compaction`,Je=w?.isGroupExpanded===!0,Ye=_e&&qe&&!Je,Xe=_e?w?.activityOwnerMessageId===t||We:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||We,Ze=_e&&Xe&&(We||qe)&&!!Ke,Qe=cT(a,V),$e={finish:a,parts:V,streamPhase:xe,error:T,isLastAssistantInTurn:ve},et=pT($e),tt=_e&&mT($e),nt=_e&&!et&&!(qe&&Je),rt=!!T,it=E===`info`?`information`:`error-warning`,at=Be,st=ve&&be&&!Ye&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&ve&&Qe&&be&&!Ye&&w?.diffStats?.hasDiffs===!0,dt=me&&at&&!st&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(zD,{hasCopyableText:Be,isTouchContext:L,onCopyMessage:x,ttsText:W,reviewTransferAction:le,sessionId:e}),[W,Be,L,x,le,e]),pt=Z.useMemo(()=>e=>{if(!me||!_e)return null;let t=Yr(e.part).trim();return t?(0,$.jsx)(zD,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ct(t)).ok,ttsText:t}):null},[_e,L,me]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||nt||Ge.get(n)?.kind!==`justification`&&(e=t)}return e},[Ge,nt,dt,V]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Ze&&Ke&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(iD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:Ke,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:xe,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};Ue.length>0?Ue.forEach(t=>{let n=C?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<V.length;){let i=V[r];if(i.type===`text`){let a=Ge.get(i);if(nt){r+=1;continue}if(Ye){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(Bw,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:fe,allowSortedFinalStreaming:tt,hasStreamingHapticLifecycle:Ee,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:u?cD:sD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:pD,"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(!Yr(i).trim()){r+=1;continue}C&&(pe?n.push((0,$.jsx)(`div`,{className:Op(u),children:(0,$.jsx)(Qw,{part:i,messageId:t,streamPhase:xe,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(Bw,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:fe,hasStreamingHapticLifecycle:Ee,onContentChange:y,onShowPopup:g},`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(aC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!aC(r.tool?.toLowerCase()??``)||Ge.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(gE,{activities:e,isMobile:u,isTurnLive:xe!==`completed`,hasFollowingOtherType:fE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(XE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(oC(a)){let e=_E(V,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)(SE,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(XE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(nC(a)){n.push((0,$.jsx)(`div`,{className:Op(u),children:(0,$.jsx)(bw,{part:e,messageId:t,isExpanded:m.has(e.id),onToggle:h,isMobile:u,alwaysShowActions:R,onContentChange:y,onShowPopup:g,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:Op(u),children:(0,$.jsx)(XE,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[Ge,Ue,R,fe,pe,0,m,Ye,qe,u,Xe,_e,mt,t,ft,pt,e,y,g,h,Ze,dt,xe,Ee,C,nt,tt,Ke,w,V]),_t=Z.useMemo(()=>{if(!ve||!be)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return ID(e)},[ve,be,w?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof c==`number`&&c>0?c:null;if(e===null)return null;let t=$T(e,ge);return t.length>0?t:null},[o,c,ge,k]),yt=Z.useMemo(()=>{if(!he||!ve||!be)return null;let e=r??n,t=LD(e,l),i=iE({createdAt:c,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=aE(i);return a.length>0?a:null},[he,ve,be,n,r,l,c,o,w?.durationMs]),bt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&te?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:lD,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=oe??(ie?ae(ie):null);e&&ee(e,te)},children:(0,$.jsx)(X,{weight:_D,name:`global`,className:uD})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!se&&j.fork?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,size:`icon`,variant:`ghost`,className:lD,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":ue,disabled:ue||!!re,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Ve(e)},children:(0,$.jsx)(X,{weight:_D,name:ue?`loader-4`:`git-branch`,className:Y(uD,ue&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:N,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:aD,children:[(0,$.jsx)(YT,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[gt,rt&&(0,$.jsx)(ds,{children:(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:it,weight:_D,className:Y(uD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:it,weight:E===`info`?_D:void 0,className:Y(`shrink-0`,E===`info`?Y(uD,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,E===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,u?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(Mo,{content:T??``,onShowPopup:g,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),ut&&w?.diffStats?(0,$.jsx)(OD,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(td,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?cD:sD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:pD,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:oD,children:[(0,$.jsxs)(`div`,{className:pD,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt?(0,$.jsxs)(`div`,{className:mD,children:[yt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:hD,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:yt}),children:[(0,$.jsx)(X,{weight:_D,name:`pulse`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(La,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,_t?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:hD,children:[(0,$.jsx)(X,{weight:_D,name:`hourglass`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(La,{children:_t})]}):null,vt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:hD,"aria-label":`Message time: ${vt}`,children:[(0,$.jsx)(X,{weight:_D,name:`time`,className:gD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(La,{children:vt})]}):null]}):null,!K&&ve&&ye&&!lt?(0,$.jsx)(nT,{activityParts:w?.activityParts}):null]})]})]})}),VD=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)(RD,{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)(BD,{...r}),t[26]=r,t[27]=i),i});function HD(e){return e.openContextPanelTab}function UD(e){return e.setCurrentSession}function WD(e){return e.openContextPanelTab}function GD(e){return!e}function KD(e){return e.openContextPanelTab}function qD(e){return!e}var JD=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}},YD=`Authentication failed for this provider. Please re-authenticate and retry.`,XD=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},ZD=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,QD=e=>!e,$D=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},eO=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),tO=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,nO=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,rO=Fo(()=>Ue(()=>import(`./ToolOutputDialog-B7vUFIz4.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]))),iO=4e3,aO=new Map,oO=new Map,sO=new Set([`bash`,`shell`,`cmd`,`terminal`]),cO=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},lO=e=>{let t=aO.get(e);return t?new Set(t):new Set},uO=(e,t)=>{if(aO.size>=iO&&!aO.has(e)){let e=aO.keys().next().value;typeof e==`string`&&aO.delete(e)}aO.set(e,new Set(t))},dO=e=>{let t=oO.get(e);return t?new Set(t):new Set},fO=(e,t)=>{if(oO.size>=iO&&!oO.has(e)){let e=oO.keys().next().value;typeof e==`string`&&oO.delete(e)}oO.set(e,new Set(t))},pO=200,mO=new Map,hO=e=>mO.get(e),gO=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=mO.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(mO.size>=pO&&!mO.has(e)){let e=mO.keys().next().value;typeof e==`string`&&mO.delete(e)}mO.set(e,t)}};function _O(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 vO=(e,t)=>{if(typeof e==`object`&&e)return e[t]},yO=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{isMobile:p,isTablet:m,hasTouchInput:h}=fo(),g=Qm(),_=$m(g),v=p||m,y=Z.useRef(null),b=Qr(e=>e.currentSessionId),x=Bt(e=>e.getAgentModelForSession),S=Bt(e=>e.getSessionModelSelection),C=Qr(e=>e.revertToMessage),w=Qr(e=>e.editMessagePreservingChanges),T=Qr(e=>e.forkFromMessage),E=Qr(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=Qr(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=Qr(e=>e.clearStagedMessageEdit);Ie(`ui.chat_message.render`),c&&Ie(`ui.chat_message.render.streaming`);let k=mi(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=s(me(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Jb.getInstance().recordSessionStart(b)},[b]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>lO(e.info.id)),[U,W]=Z.useState(()=>dO(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(lO(e.info.id)),W(dO(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>JD(e.info),[e.info]).isUser,te=K&&(p||!j),ne=K&&!p&&j&&!te,re=e.info.sessionID,ie=Zb(e=>e.planModeEnabled),{currentContextAgent:ae,savedSessionAgentSelection:oe}=Up(me(e=>({currentContextAgent:c&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:c&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>fn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>K?J(se,{planModeEnabled:ie}):fn(e.parts),[K,e.parts,ie,se]),le=Z.useMemo(()=>{if(K||!t)return null;let e=vO(t.info,`clientRole`),n=vO(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=vO(t.info,`mode`),i=vO(t.info,`agent`),a=vO(t.info,`providerID`),o=vO(t.info,`modelID`),s=vO(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=vO(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[K,t]),ue=Z.useMemo(()=>{if(!ie||K||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[K,ie,t]),de=Z.useMemo(()=>{if(K)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&ue&&le?.agentName)return le.agentName;let n=vO(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=vO(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(le?.agentName)return le.agentName;if(re)return ae||(oe??void 0)},[K,e.info,ue,le,re,ae,oe]),fe=K?null:vO(e.info,`providerID`),pe=K?null:vO(e.info,`modelID`),he=Z.useMemo(()=>{if(K||!re)return null;if(le?.providerId&&le?.modelId)return{providerId:le.providerId,modelId:le.modelId};if(de){let e=x(re,de);if(e?.providerId&&e?.modelId)return e}let e=S(re);return e?.providerId&&e?.modelId?e:null},[K,re,de,le,x,S]),ge=Z.useMemo(()=>K?null:typeof fe==`string`&&fe.trim().length>0?fe:he?.providerId??null,[K,fe,he]),_e=Z.useMemo(()=>K?null:typeof pe==`string`&&pe.trim().length>0?pe:he?.modelId??null,[K,pe,he]),ve=e.info.id?hO(e.info.id):void 0;K||gO(e.info.id,{agent:de,provider:ge??void 0,model:_e??void 0});let ye=de??ve?.agent,be=ge??ve?.provider??null,xe=_e??ve?.model??null,Se=Z.useMemo(()=>{if(K)return;let e=be&&k.length>0?k.find(e=>e.id===be):void 0;return ft(e,xe)||void 0},[K,be,xe,k]),Ce=Z.useMemo(()=>{if(K||!ge||!_e)return!1;let e=k.find(e=>e.id===ge);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===_e)?.variants;return!!(t&&Object.keys(t).length>0)},[K,_e,ge,k]),we=_O(ye),Te=_O(be??void 0),Ee=_O(xe??void 0),De=_O(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,je=De??void 0,Me=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Pe=Z.useMemo(()=>K?!0:!!(Me&&Me>0),[K,Me]),Fe=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Le=Z.useMemo(()=>{if(K)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[K,e.info]),Re=Z.useMemo(()=>gt(ce,{includeReasoning:A}),[ce,A]),ze=Z.useMemo(()=>K?Re:!Pe&&M===`sorted`?[]:Re,[M,Pe,K,Re]),Be=Z.useMemo(()=>K?[]:Re.filter(e=>e.type===`text`),[K,Re]),Ve=Z.useMemo(()=>K?[]:Re.filter(e=>e.type===`tool`),[K,Re]),He=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of Ve){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=cO(t.tool);!r||!sO.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=cO(t.part.tool);!n||!sO.has(n)||e.add(t.id)}return e},[N,Ve,a?.activityParts]),Ue=Z.useMemo(()=>{if(He.size===0&&U.size===0)return V;let e=new Set(V);return He.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,He,V]),We=Z.useMemo(()=>{if(!K)return;let e=ce.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}`}},[K,ce]),Ge=K&&!Ct(ze),Ke=typeof Fe!=`string`,qe=Z.useMemo(()=>K?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,K]),Je=Z.useMemo(()=>!K&&Jb.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?JD(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=tO({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),tt=Z.useMemo(()=>K?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,K,Ze]),nt=Z.useMemo(()=>Pe?`completed`:c?l??`streaming`:`completed`,[l,c,Pe]);Z.useEffect(()=>{!K||!u||d?.(e.info.id)},[u,K,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;K||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,K,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(K)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,K,a,nt,e.info.id]),it=Z.useCallback(e=>{ct(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),at=K?void 0:a?.userMessageVariant??le?.variant,ot=!K&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,st=Z.useMemo(()=>{if(K)return;let t=e.info?.error;if(!t)return;let n=typeof t.data?.message==`string`?t.data.message:void 0,r=typeof t.message==`string`?t.message:void 0,i=typeof t.name==`string`?t.name:void 0,a=n||r||i;if(a)return i===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${a}\``,variant:`info`}:XD(a)?{text:YD,variant:`error`}:a.trim().toLowerCase()===`aborted`?{text:`The running turn was stopped before OpenCode could send the next message.`,variant:`info`}:{text:`Opencode failed to send message with error:\n\`${a}\``,variant:`error`}},[K,e.info]),lt=st?.text,ut=st?.variant,dt=Z.useMemo(()=>{if(K){let e=ze.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(`
6577
6577
 
6578
- `);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(`
6579
- `):Be.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
6578
+ `);let t=ze.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(`
6579
+ `):ze.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
6580
6580
  `).replace(/\n\s*\n+/g,`
6581
- `)}return ut&&ut.trim().length>0?ut:tn(Be)},[ut,Be,G]),mt=ft.length>0,ht=Z.useCallback(async()=>(await lt(ft)).ok?(G&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[G,ft]),gt=Z.useCallback(async()=>{if(!(!ie||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(ie,e.info.id,{directory:g.directory??void 0})}finally{B.current=null,z(null)}}},[ie,e.info.id,C,g]),vt=K(()=>{if(!ie||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(ie,e.info.id,t).catch(()=>{})}),yt=K(()=>{ie&&O(ie)}),bt=Z.useCallback(async()=>{if(e.info.id,!ie||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!ie,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(ie,e.info.id)}finally{B.current=null,z(null)}}},[ie,e.info.id,T]),xt=K(t=>{let n=Ue.has(t),r=We.has(t);if(n){ee(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),fO(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),uO(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),uO(e.info.id,r),r}),ee(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),fO(e.info.id,r),r})}),St=i??null,Ct=Z.useRef(!1),Tt=Z.useRef(!1),Et=Z.useRef(!1),Dt=Z.useRef(!1),Ot=Z.useRef(!1),kt=Z.useRef(!1);Z.useEffect(()=>{Tt.current=!1,Et.current=!1,Dt.current=!1,Ot.current=!1,Ct.current=!1,kt.current=!1},[e.info.id]);let At=Z.useCallback(()=>{G||Ct.current||(Ct.current=!0,r?.(`structural`))},[G,r]),jt=s(e=>e.setImagePreviewOpen),Mt=Z.useCallback(e=>{(e.image||e.mermaid)&&(W(e),jt(!0))},[jt]),Nt=Z.useCallback(e=>{W(t=>({...t,open:e})),jt(e)},[jt]),Pt=!!vO(e.info,`animationSettled`),Ft=rt===`streaming`||rt===`cooldown`;Ft&&(kt.current=!0);let It=Z.useMemo(()=>!G&&ze.some(e=>e.type===`reasoning`),[G,ze]),Lt=Ye&&!Pt&&!Ft&&!kt.current,Rt=!G&&Ye&&Ve.length>0&&!Je;return Z.useEffect(()=>{if(St?.onStreamingCandidate){if(!Rt){Et.current&&=(It&&St?.onReasoningBlock?St.onReasoningBlock():St?.onReservationCancelled&&St.onReservationCancelled(),!1);return}Ot.current||(Ot.current=!0,St.onStreamingCandidate(),Et.current=!0)}},[St,Rt,It]),Z.useEffect(()=>{St?.onAnimationStart&&Lt&&(Dt.current||=(St.onAnimationStart(),!0))},[St,Lt]),Z.useEffect(()=>{if(G)return;let e=St?.onAnimatedHeightChange;if(!e||!(Lt||Rt))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[Lt,G,St,Rt]),Ke?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,G?p?`pt-2`:`pt-6`:!G&&it?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,G||nt?`pb-0`:tt?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:y,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:G?wt(Be)?(0,$.jsx)(ds,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,p?void 0:`group/user-shell`),children:(0,$.jsxs)(`div`,{className:Y(`max-w-[85%]`,re?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:`px-3 py-1.5 shadow-none border border-primary/5`,children:(0,$.jsx)(VD,{messageId:e.info.id,parts:Be,sourceParts:ce,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:at,expandedTools:V,onToggleTool:xt,onShowPopup:Mt,streamPhase:rt,allowAnimation:Lt,onContentChange:r,shouldShowHeader:!1,hasTextContent:mt,onCopyMessage:ht,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:At,agentMention:Ge,onEdit:!E&&_.edit?vt:void 0,onRevert:!E&&_.revert?gt:void 0,onFork:!E&&G&&_.fork?bt:void 0,editing:E,editStaged:D,onCancelEdit:D?yt:void 0,pendingMessageAction:R,errorMessage:ut,errorVariant:dt,userActionsMode:ne?`external-content`:`inline`,stickyUserHeaderEnabled:j})}),ne?(0,$.jsx)(VD,{messageId:e.info.id,parts:Be,sourceParts:ce,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCreatedAt:Pe??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:at,expandedTools:V,onToggleTool:xt,onShowPopup:Mt,streamPhase:rt,allowAnimation:Lt,onContentChange:r,shouldShowHeader:!1,hasTextContent:mt,onCopyMessage:ht,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:At,agentMention:Ge,onEdit:!E&&_.edit?vt:void 0,onRevert:!E&&_.revert?gt:void 0,onFork:!E&&G&&_.fork?bt:void 0,editing:E,editStaged:D,onCancelEdit:D?yt:void 0,pendingMessageAction:R,errorMessage:ut,errorVariant:dt,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[it&&(0,$.jsx)($b,{isUser:G,isMobile:p,providerID:Ae,modelID:je,agentName:ke,modelName:Me,variant:st}),(0,$.jsx)(VD,{sessionId:e.info.sessionID,messageId:e.info.id,parts:ze,sourceParts:le,isUser:G,isMessageCompleted:Fe,messageFinish:Ie,messageCompletedAt:Ne??void 0,messageCreatedAt:Pe??void 0,messageTokens:Re,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:at,expandedTools:We,onToggleTool:xt,onShowPopup:Mt,streamPhase:rt,allowAnimation:Lt,onContentChange:r,shouldShowHeader:it,hasTextContent:mt,onCopyMessage:ht,copiedMessage:I,onAuxiliaryContentComplete:At,showReasoningTraces:A,agentMention:Ge,turnGroupingContext:a,errorMessage:ut,errorVariant:dt,reviewTransferDirection:f})]})})}),te.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(rO,{popup:te,onOpenChange:Nt,isMobile:p})}):null]})},(e,t)=>tS({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&nS(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&nS(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.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&uS(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,JD(e.message.info).isUser)),bO=Z.memo(e=>{let t=(0,Q.c)(10),{assistantMessages:n,activityExpanded:r,renderMessage:i}=e,a;if(t[0]!==r||t[1]!==n||t[2]!==i){let e;t[4]!==r||t[5]!==i?(e=e=>i(e,r),t[4]=r,t[5]=i,t[6]=e):e=t[6],a=n.map(e),t[0]=r,t[1]=n,t[2]=i,t[3]=a}else a=t[3];let o;return t[7]!==r||t[8]!==a?(o=(0,$.jsx)(`div`,{className:`relative z-0`,"data-turn-assistant-activity-expanded":r,children:a}),t[7]=r,t[8]=a,t[9]=o):o=t[9],o}),xO=new Set,SO=()=>{},CO=()=>{},wO=Z.memo(e=>{let t=(0,Q.c)(32),{turn:n,activityExpanded:r,showCompactionStatus:i,pendingAssistantHeader:a,onToggleActivity:o,stickyUserHeader:c,renderMessage:l}=e,u=a===void 0?null:a,d=c===void 0||c,f=s(TO),p=n.userMessage.info.time?.created,m=n.activityPresentationKind===`compaction`,h=`turn-${n.turnId}`,g;t[0]!==r||t[1]!==m||t[2]!==l||t[3]!==d||t[4]!==n.userMessage?(g=m?null:d?(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:l(n.userMessage,r)}),(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`})]}):l(n.userMessage,r),t[0]=r,t[1]=m,t[2]=l,t[3]=d,t[4]=n.userMessage,t[5]=g):g=t[5];let _;t[6]!==f||t[7]!==u||t[8]!==d||t[9]!==n.assistantMessages?(_=u?(0,$.jsx)(`div`,{className:`group w-full ${f?d?`pt-4`:`pt-0`:`pt-6`} ${n.assistantMessages.length===0?`pb-1`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)($b,{isUser:!1,isMobile:f,providerID:u.providerID,modelID:u.modelID,agentName:u.agentName,modelName:u.modelName,variant:u.variant})})}):null,t[6]=f,t[7]=u,t[8]=d,t[9]=n.assistantMessages,t[10]=_):_=t[10];let v;t[11]!==r||t[12]!==f||t[13]!==o||t[14]!==i||t[15]!==n.assistantMessages||t[16]!==n.completionDisposition||t[17]!==n.durationMs||t[18]!==p?(v=i?(0,$.jsx)(`div`,{className:`group w-full ${f?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(iD,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof p==`number`?p:void 0,onToggle:o,isMobile:f,expandedTools:xO,onToggleTool:SO,onShowPopup:CO,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[11]=r,t[12]=f,t[13]=o,t[14]=i,t[15]=n.assistantMessages,t[16]=n.completionDisposition,t[17]=n.durationMs,t[18]=p,t[19]=v):v=t[19];let y;t[20]!==r||t[21]!==l||t[22]!==n.assistantMessages?(y=(0,$.jsx)(bO,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:l}),t[20]=r,t[21]=l,t[22]=n.assistantMessages,t[23]=y):y=t[23];let b;return t[24]!==r||t[25]!==h||t[26]!==g||t[27]!==_||t[28]!==v||t[29]!==y||t[30]!==n.turnId?(b=(0,$.jsxs)(`section`,{className:`relative w-full`,id:h,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[g,_,v,y]}),t[24]=r,t[25]=h,t[26]=g,t[27]=_,t[28]=v,t[29]=y,t[30]=n.turnId,t[31]=b):b=t[31],b});function TO(e){return e.isMobile}var EO=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},DO=e=>{let t=e?.type;return t===`compaction`||t===`text`&&EO(e).trim()===`/compact`},OO=e=>e?e.some(e=>DO(e)):!1,kO=e=>OO(e.parts),AO=e=>e?OO(e.sourceParts)||OO(e.parts):!1,jO=e=>{if(!kO(e))return e;let t=!1,n=e.parts.map(e=>e?.type===`compaction`?(t=!0,{type:`text`,text:`/compact`}):e),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},MO=e=>{let t=pn(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},NO=new WeakMap,PO=e=>{let t=NO.get(e);if(t)return t;let n=jO(MO(e)),r=n.parts,i=Xn(r),a=i===r?n:{...n,parts:i,sourceParts:r};return NO.set(e,a),a},FO=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,IO=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},LO=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},RO=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},zO=(e,t,n,r)=>({id:FO(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:IO(n)}),BO=e=>{let t=[],n=!1,r=!1;e.assistantMessages.forEach(e=>{e.parts.forEach(e=>{if(e.type===`tool`){n=!0;return}e.type===`reasoning`&&LO(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&cT(RO(t),t.parts));e.assistantMessages.forEach(n=>{let r=RO(n),a=n.parts.some(e=>e.type===`tool`);n.parts.forEach((o,s)=>{let c=o.type===`tool`,l=o.type===`reasoning`||o.type===`text`?LO(o):void 0,u=FO(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&cT(r,n.parts)&&e.summarySourceMessageId===n.info.id&&e.summarySourcePartId===u,f=null;c?f=`tool`:o.type===`reasoning`?f=`reasoning`:e.showTextJustificationActivity&&o.type===`text`&&l&&!d&&(i||a||typeof r==`string`&&r!==`stop`)&&(f=`justification`),f&&t.push({...zO(e.turnId,n.info.id,o,s),kind:f})})});let a=[];if(t.length>0){let n=e.assistantMessages[0]?.info.id;n&&a.push({id:`${e.turnId}:activity`,anchorMessageId:n,afterToolPartId:null,parts:t})}return{activityParts:t,activitySegments:a,hasTools:n,hasReasoning:r}},VO=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;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})})});let a=e.length>0?e[e.length-1]:null,o=new Set;return a&&(o.add(a.userMessageId),a.assistantMessageIds.forEach(e=>{o.add(e)})),{turns:e,indexes:{turnById:t,messageToTurnId:n,messageMetaById:r},lastTurnId:a?.turnId??null,lastTurnMessageIds:o,ungroupedMessageIds:new Set}},HO=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},UO=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(cT(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!lT(t))continue;let r=HO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:FO(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=HO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:FO(n.info.id,t,e)}}}return{}},WO=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}},GO=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},KO=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},qO=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},JO=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},YO=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},XO=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},ZO=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},QO=(e,t)=>{let n=KO(e);return{messageId:e.info.id,role:n,parentMessageId:qO(e),message:e,order:t}},$O=(e,t)=>{let n=JO(e),r,i,a=!1;t.forEach(e=>{let t=YO(e);typeof t==`number`?r=Math.max(r??0,t):a=!0,e.parts.forEach(e=>{let t=XO(e);typeof t==`number`&&(i=Math.max(i??0,t))})});let o=r??i,s=typeof n==`number`&&typeof o==`number`&&o>=n?o-n:void 0;return{isStreaming:a,isRetrying:t.length>1,startedAt:n,completedAt:r,durationMs:s}},ek=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`||sT(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 YO(t)!=`number`)return`active`;return`active`},tk=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return uT(n.finish,t.parts,n.error)},nk=e=>AO(e)?`compaction`:`default`,rk={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},ik=(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},ak=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&ik(e.assistantMessages,t.assistantMessages),ok=(e,t)=>{e.summary=UO(e.assistantMessages),e.summaryText=e.summary.text??ZO(e.userMessage),e.diffStats=WO(e.userMessage),e.changedFiles=t.showTurnChangedFiles?GO(e.userMessage):void 0,e.completionDisposition=ek(e.assistantMessages),e.hasConfirmedFinalBody=tk(e.assistantMessages),e.activityPresentationKind=nk(e.userMessage);let n=BO({turnId:e.turnId,assistantMessages:e.assistantMessages,summarySourceMessageId:e.summary.sourceMessageId,summarySourcePartId:e.summary.sourcePartId,showTextJustificationActivity:t.showTextJustificationActivity});return e.activityParts=n.activityParts,e.activitySegments=n.activitySegments,e.hasTools=n.hasTools,e.hasReasoning=n.hasReasoning,e.stream=$O(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},sk=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>ok(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&&ak(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,ok(e,t))});return r&&i?n.turns:a},ck=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},lk=(e,t)=>{let n={...rk,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(KO(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[QO(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(n),i.set(n.userMessageId,n),a.add(e.info.id)}),e.forEach((e,t)=>{if(KO(e)!==`assistant`)return;let n=qO(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(QO(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=VO(ck(sk(r,n))),s=new Set;return e.forEach(e=>{KO(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},uk=30,dk=4,fk=4,pk=33554432,mk=8388608,hk=new Map,gk=new Map,_k=0,vk=new WeakMap,yk=1,bk=()=>d()?dk:Zi()?fk:uk,xk=()=>d()||Zi()?mk:pk,Sk=(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},Ck=e=>{hk.delete(e);let t=gk.get(e)??0;gk.delete(e),_k=Math.max(0,_k-t)},wk=e=>{let t=vk.get(e);if(t!==void 0)return t;let n=yk;return yk+=1,vk.set(e,n),n},Tk=e=>e.map(e=>`${wk(e.info)}:${wk(e.parts)}:${e.parts.map(e=>wk(e)).join(`,`)}`).join(`;`),Ek=(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,Tk(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},Dk=e=>{let t=hk.get(e);return t&&(hk.delete(e),hk.set(e,t)),t},Ok=(e,t)=>{Ck(e);let n=bk(),r=xk(),i=Sk(e,t);if(!(i>r)){for(;hk.size>=n||_k+i>r;){let e=hk.keys().next().value;if(typeof e!=`string`)break;Ck(e)}hk.set(e,t),gk.set(e,i),_k+=i}},kk=[],Ak=(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},jk=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},Mk=(e,t)=>t===null?{staticTurns:e,streamingTurns:kk}:{staticTurns:t===0?kk:e.slice(0,t),streamingTurns:e.slice(t)},Nk=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(kk),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=kk,a.current=null);let l=Z.useMemo(()=>{let r=Ek(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=Dk(r);return i?(n.current=i,i):we(`ui.turns.projection_ms`,()=>{let i=lk(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,Ok(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=jk({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=Mk(l.turns,u).staticTurns;return Ak(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=Mk(l.turns,u).streamingTurns;return Ak(i.current,e)?i.current:i.current=e},[u,l.turns])}},Pk=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},Fk=(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(Pk(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(Pk(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},Ik=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=gn(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:PO({...e,parts:r})},Lk=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=Ik(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=Ik(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=lk([e.turn.userMessage,...i],{showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles}).turns[0]??{...e.turn,assistantMessages:i,assistantMessageIds:i.map(e=>e.info.id)};return{...e,turn:a}},Rk=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},zk=2,Bk=2,Vk=e=>Math.min(Math.max(0,e),zk),Hk=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+Bk),Uk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(FS.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Wk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ao.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Gk=12,Kk=16,qk=new Map,Jk=e=>{let t=qk.get(e);if(t)return qk.delete(e),qk.set(e,t),t},Yk=(e,t)=>{if(t.size!==0)for(qk.delete(e),qk.set(e,t);qk.size>Kk;){let e=qk.keys().next().value;if(typeof e!=`string`)break;qk.delete(e)}},Xk=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Gk)),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},Zk=(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},Qk=({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}},$k=e=>{let{visible:t,preload:n}=Qk(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},eA=(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},tA=e=>{if(!e)return;let{contentLength:t,scroll:n,scrollLength:r}=e;return typeof t==`number`&&typeof n==`number`&&typeof r==`number`&&Number.isFinite(t)?t-(n+r)<=40:e.isNearEnd??e.isAtEnd},nA={itemVisiblePercentThreshold:0},rA=100,iA=new Set,aA=Z.createContext(iA),oA=({entry:e,index:t,renderEntryRef:n})=>{let r=Z.useContext(aA);return(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:n.current?.(e,t,r.has(e.key))})},sA=Z.memo(({entries:e,timelineCacheKey:t,estimatedItemSize:n,hydrationTuning:r,renderEntry:i,rowInvalidationKey:a,scrollElementRef:o,registerList:s,anchoredEndSpace:c,composerOverlayHeight:l=0,followEnabled:u=!0,sessionIsWorking:d=!1,onIsAtEndChange:f,onScroll:p,header:m,footer:h,className:g,style:_,contentContainerClassName:v,contentContainerStyle:y})=>{let b=Z.useRef(null),x=Z.useMemo(()=>e.map(e=>e.key),[e]),S=Z.useRef(x);S.current=x;let C=Z.useRef(r);C.current=r;let w=Z.useCallback(e=>{b.current=e,s?.(e)},[s]),T=Z.useCallback(e=>{o&&(o.current=e?.getScrollableNode?.()??null)},[o]),[E,D]=Z.useState(()=>Xk(x,{restore:Jk(t)??null})),O=Z.useRef(E);O.current=E;let k=Z.useRef(0),A=Z.useRef(0),j=Z.useRef(!0),M=Z.useRef(null),N=Z.useRef(!1),P=Z.useMemo(()=>Zk(E,x),[E,x]);Z.useEffect(()=>{D(e=>eA(e,x))},[x]),Z.useEffect(()=>()=>{Yk(t,O.current)},[t]);let F=K(()=>{N.current=!1;let e=b.current;if(!e)return;let t=S.current;if(t.length===0)return;let n=e.getState(),r=t.length-1,i=Math.max(0,Math.floor(n.startBuffered)),a=Math.min(r,Math.floor(n.endBuffered));if(!Number.isFinite(i)||!Number.isFinite(a)||a<i)return;let o=[];for(let e=i;e<=a;e+=1)o.push(e);let s=Math.max(0,Math.floor(n.start)),c=Math.min(r,Math.floor(n.end)),l=Math.max(0,c-s+1),u=Date.now()-k.current>=rA,d=C.current,f=d.resolvePreloadEntries(l),p=$k({entryKeys:t,mountedIndexes:o,visibleStartIndex:s,visibleEndIndex:c,scrollDirection:M.current,preloadEntries:f,hydratedKeys:O.current,allowVisibleRelease:u,preloadReleaseLimit:u?f:d.resolvePreloadReleaseWhileScrolling(),visibleReleaseLimit:d.resolveVisibleReleaseLimit()});p.length!==0&&Z.startTransition(()=>{D(e=>{let t=!1,n=new Set(e);for(let e of p)n.has(e)||(n.add(e),t=!0);return t?n:e})})}),I=K(()=>{N.current||(N.current=!0,ls(F))}),L=K(()=>{I()}),R=K(()=>{k.current=Date.now();let e=b.current;if(e){let t=e.getState(),n=t.scroll;Number.isFinite(n)&&n!==A.current&&(M.current=n>A.current?`forward`:`backward`,A.current=n);let r=tA(t)??t.isAtEnd;r!==j.current&&(j.current=r,f?.(r))}p?.(),I()}),z=Z.useCallback(e=>e.key,[]),B=Z.useCallback(e=>e.kind,[]),V=Z.useRef(i);V.current=i;let H=Z.useCallback(({item:e,index:t})=>(0,$.jsx)(oA,{entry:e,index:t,renderEntryRef:V}),[]),U=Z.useMemo(()=>c||!u?!1:{animated:d,on:{dataChange:!0,itemLayout:!0,layout:!0,footerLayout:!0}},[c,u,d]);return(0,$.jsx)(aA.Provider,{value:P,children:(0,$.jsx)(bc,{ref:w,refScrollView:T,data:e,extraData:a,keyExtractor:z,getItemType:B,renderItem:H,estimatedItemSize:n,initialScrollAtEnd:!0,recycleItems:!1,...c?{anchoredEndSpace:c}:{},contentInsetEndAdjustment:l,maintainScrollAtEnd:U,maintainVisibleContentPosition:{data:!0,size:!1},onScroll:R,onViewableItemsChanged:L,viewabilityConfig:nA,ListHeaderComponent:m,ListFooterComponent:h,className:g,style:_,contentContainerClassName:v,contentContainerStyle:y})})}),cA=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},lA=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},uA=e=>!e||cA(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`)}),dA=(e,t)=>{if(cA(e)!==`assistant`||t&&lA(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}}},fA=(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(cA(t)===`user`)break;let{hide:i,details:a}=dA(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},pA=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},mA=(e,t)=>{if(e.length===0)return[];if(e.filter(pA).length===e.length)return e;if(t){let n=e.findIndex(e=>e.info.id===t);if(n>=0)return e.slice(0,n+1)}return e},hA=e=>{if(e.chatRenderMode!==`sorted`)return null;let t=e.streamingAssistantMessageId;if(!t)return null;let n=e.assistants.find(e=>e.info.id===t);if(!n)return null;let r=n.info,i=fT({finish:r.finish,isMessageCompleted:pA(n),activeStreamingPhase:e.activeStreamingPhase});return pT({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},gA=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},_A=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=gA(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},vA=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},yA=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=vA(t.mode)??vA(t.agent),r=vA(t.providerID),i=vA(t.modelID),a=vA(t.model?.variant)??vA(t.variant);return!n&&!r&&!i&&!a?null:{agentName:n,providerId:r,modelId:i,variant:a}},bA=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:pt(void 0,t)||void 0,variant:e?.variant}},xA=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),SA=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:ZD(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),CA=5,wA=[],TA=new Set,EA=[],DA=16,OA=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),kA=320,AA=168,jA=8,MA=16,NA=6,PA=12,FA=4,IA=1,LA=2,RA=6,zA=4,BA=()=>Zi()?MA:jA,VA=30,HA=180,UA=5,WA=2,GA=120,KA=1200,qA=80,JA=160,YA=1500,XA=1.5,ZA=90,QA=(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},$A=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(OA(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)}}}})(DA),ej=(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})},tj=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),nj=e=>e===`collapsed`?AA:kA,rj=(e,t)=>`${e}::activity:${t}`,ij=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),aj=(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{paddingTop:r,paddingBottom:Math.max(0,a-i),minHeight:a}},oj=(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)},sj=(e,t=0)=>Math.max(e===`collapsed`?PA:NA,Math.max(0,Math.floor(t))),cj=e=>e===`collapsed`?LA:IA,lj=e=>e===`collapsed`?zA:RA,uj=e=>e===`collapsed`?WA:UA,dj=(e,t)=>{e.current=t},fj=(e,t)=>$A.read(e,t),pj=(e,t,n)=>{!n||t.length===0||$A.write(e,t,n.takeSnapshot())},mj=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},hj=(e,t)=>{if(mj(e)!==`system`)return e;let n=vj(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},gj=e=>!e||mj(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),_j=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},vj=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},yj=(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},bj=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,xj=(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&&!yj(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}},Sj=(e,t)=>{let n=xj(t,e);if(!n)return null;let r=bj(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},Cj=e=>{let t=e,n=t.state?.metadata,r=bx(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?wx(i)??null:null},wj=e=>{if(mj(e)!==`assistant`||e.parts.length!==1)return{hide:!1,taskSessionId:null};let t=e.parts[0];return t?.type!==`tool`||(typeof t.tool==`string`?t.tool.toLowerCase():``)!==`task`?{hide:!1,taskSessionId:null}:{hide:!0,taskSessionId:Cj(e.parts[0])}},Tj=(e,t)=>{if(!t)return e;let n=xx(e.parts,t);return n===e.parts?e:{...e,parts:n}},Ej=(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}},Dj=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,Oj=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,reviewTransferDirection:m}=e,h=Qm(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:h,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=h,t[3]=g):g=t[3];let _=g,v;t[4]!==c||t[5]!==l||t[6]!==f||t[7]!==o||t[8]!==s||t[9]!==n||t[10]!==i||t[11]!==d||t[12]!==u||t[13]!==r||t[14]!==m||t[15]!==p||t[16]!==a?(v=(0,$.jsx)(yO,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,reviewTransferDirection:m}),t[4]=c,t[5]=l,t[6]=f,t[7]=o,t[8]=s,t[9]=n,t[10]=i,t[11]=d,t[12]=u,t[13]=r,t[14]=m,t[15]=p,t[16]=a,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Zm.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return tS(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&nS(e.previousMessage,t.previousMessage)&&nS(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&uS(n,r,e.message.info.id,mj(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&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});Oj.displayName=`MessageRow`;var kj=Z.memo(e=>{let t=(0,Q.c)(109),{turn:n,isLastTurn:r,sessionIsWorking:i,activityRenderMode:a,turnUiStates:o,onToggleTurnGroup:s,chatRenderMode:c,onMessageContentChange:l,getAnimationHandlers:u,scrollToBottom:d,stickyUserHeader:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_}=e,v=f===void 0||f,y;t[0]!==n.turnId||t[1]!==o?(y=o.get(n.turnId),t[0]=n.turnId,t[1]=o,t[2]=y):y=t[2];let b=y,x;if(t[3]!==a||t[4]!==r||t[5]!==i||t[6]!==n.assistantMessages.length||t[7]!==n.completionDisposition||t[8]!==n.durationMs||t[9]!==n.hasConfirmedFinalBody){let e=$D({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=SA({expansionDisposition:nO({isLastTurn:r,turnCompletionDisposition:n.completionDisposition,headerPresentationDisposition:e.completionDisposition,hasAssistantMessages:n.assistantMessages.length>0}),activityRenderMode:a,isLastTurn:r,isActivelyProcessing:r&&i,hasConfirmedFinalBody:n.hasConfirmedFinalBody}),t[3]=a,t[4]=r,t[5]=i,t[6]=n.assistantMessages.length,t[7]=n.completionDisposition,t[8]=n.durationMs,t[9]=n.hasConfirmedFinalBody,t[10]=x}else x=t[10];let S=x,C=b?b.isExpanded:S,w;t[11]!==S||t[12]!==s||t[13]!==n.turnId?(w=()=>{s(n.turnId,S)},t[11]=S,t[12]=s,t[13]=n.turnId,t[14]=w):w=t[14];let T=K(w),E;if(t[15]!==n.assistantMessages||t[16]!==n.userMessage){let e=[n.userMessage,...n.assistantMessages],r=new Map;e.forEach((e,t)=>{r.set(e.info.id,t)}),E={ordered:e,lookup:r},t[15]=n.assistantMessages,t[16]=n.userMessage,t[17]=E}else E=t[17];let D=E,O;bb0:{if(h&&n.assistantMessages.some(e=>e.info.id===h)){O=h;break bb0}for(let e=n.assistantMessages.length-1;e>=0;--e){let t=n.assistantMessages[e];if(!pA(t)){O=t.info.id;break bb0}}O=null}let k=O,A;t[18]!==g||t[19]!==c||t[20]!==k||t[21]!==n.assistantMessages?(A=hA({chatRenderMode:c,assistants:n.assistantMessages,streamingAssistantMessageId:k,activeStreamingPhase:g}),t[18]=g,t[19]=c,t[20]=k,t[21]=n.assistantMessages,t[22]=A):A=t[22];let j=A,M;bb1:{if(c===`live`){M=n.assistantMessages;break bb1}let e;t[23]!==k||t[24]!==n.assistantMessages?(e=mA(n.assistantMessages,k),t[23]=k,t[24]=n.assistantMessages,t[25]=e):e=t[25],M=e}let N=M,P;t[26]===N?P=t[27]:(P=new Map,N.forEach((e,t)=>{P.set(e.info.id,t)}),t[26]=N,t[27]=P);let F=P,I;t[28]===N?I=t[29]:(I=new Set(N.map(Rj)),t[28]=N,t[29]=I);let L=I,R=N[0]?.info.id,z;bb2:{if(c!==`sorted`){z=n.activityParts;break bb2}let e;t[30]!==n.activityParts||t[31]!==n.assistantMessages.length||t[32]!==L?(e=L.size===n.assistantMessages.length?n.activityParts:n.activityParts.filter(e=>L.has(e.messageId)),t[30]=n.activityParts,t[31]=n.assistantMessages.length,t[32]=L,t[33]=e):e=t[33];let r=e,i;t[34]!==j||t[35]!==r?(i=gA(r,j),t[34]=j,t[35]=r,t[36]=i):i=t[36],z=i}let B=z,V;bb3:{if(c!==`sorted`){V=n.activitySegments;break bb3}if(j){let e;t[37]!==j||t[38]!==n.activitySegments?(e=_A(n.activitySegments,j),t[37]=j,t[38]=n.activitySegments,t[39]=e):e=t[39],V=e;break bb3}if(L.size===n.assistantMessages.length){V=n.activitySegments;break bb3}let e;if(t[40]!==n.activitySegments||t[41]!==L){let r;t[43]===L?r=t[44]:(r=e=>{let t=e.parts.filter(e=>L.has(e.messageId));if(t.length===0)return null;let n=L.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null},t[43]=L,t[44]=r),e=n.activitySegments.map(r).filter(zj),t[40]=n.activitySegments,t[41]=L,t[42]=e}else e=t[42];V=e}let H=V,U=n.userMessage.info.time?.created,ee=n.userMessage.info,te=ee?.model?.variant??ee?.variant,W=typeof te==`string`&&te.trim().length>0?te:void 0,G=typeof U==`number`?U:void 0,ne;t[45]!==G||t[46]!==n.activityPresentationKind||t[47]!==n.changedFiles||t[48]!==n.diffStats||t[49]!==n.hasReasoning||t[50]!==n.hasTools||t[51]!==n.headerMessageId||t[52]!==n.summaryText||t[53]!==n.turnId||t[54]!==W||t[55]!==B||t[56]!==H?(ne={turnId:n.turnId,summaryBody:n.summaryText,activityParts:B,activityGroupSegments:H,headerMessageId:n.headerMessageId,hasTools:n.hasTools,hasReasoning:n.hasReasoning,activityPresentationKind:n.activityPresentationKind,diffStats:n.diffStats,changedFiles:n.changedFiles,userMessageCreatedAt:G,userMessageVariant:W},t[45]=G,t[46]=n.activityPresentationKind,t[47]=n.changedFiles,t[48]=n.diffStats,t[49]=n.hasReasoning,t[50]=n.hasTools,t[51]=n.headerMessageId,t[52]=n.summaryText,t[53]=n.turnId,t[54]=W,t[55]=B,t[56]=H,t[57]=ne):ne=t[57];let re=ne,ie;t[58]!==g||t[59]!==R||t[60]!==c||t[61]!==u||t[62]!==T||t[63]!==r||t[64]!==D.lookup||t[65]!==D.ordered||t[66]!==l||t[67]!==m||t[68]!==_||t[69]!==d||t[70]!==i||t[71]!==p||t[72]!==k||t[73]!==n.activityPresentationKind||t[74]!==n.completionDisposition||t[75]!==n.durationMs||t[76]!==n.hasConfirmedFinalBody||t[77]!==n.hasReasoning||t[78]!==n.hasTools||t[79]!==n.headerMessageId||t[80]!==n.turnId||t[81]!==n.userMessage||t[82]!==re||t[83]!==H||t[84]!==F||t[85]!==N[0]?.info.id||t[86]!==N.length?(ie=(e,t)=>{let a=mj(e)===`user`,o=D.lookup.get(e.info.id),s=F.get(e.info.id)??-1,f=s>=0,h=s===0,v=s===N.length-1,y=!!R&&e.info.id===R,b=H.some(t=>t.anchorMessageId===e.info.id),x=c===`sorted`?f:y||h||v,S=N[0]?.info.id??n.headerMessageId,C=a?void 0:f?h?n.userMessage:void 0:typeof o==`number`&&o>0?D.ordered[o-1]:void 0,w=$D({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs}),E=f?{turnId:n.turnId,activityOwnerMessageId:R,isFirstAssistantInTurn:h,isLastAssistantInTurn:v,isLatestTurn:r,isWorking:(r||n.completionDisposition===`active`)&&i&&(c===`sorted`?b:e.info.id===k),isTurnSettled:eO({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,hasConfirmedSettledAssistant:n.hasConfirmedFinalBody}),hasTools:n.hasTools,hasReasoning:n.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:n.activityPresentationKind,durationMs:w.durationMs,...x?{summaryBody:re.summaryBody,activityParts:re.activityParts,activityGroupSegments:re.activityGroupSegments,headerMessageId:re.headerMessageId,diffStats:re.diffStats,changedFiles:re.changedFiles,userMessageCreatedAt:re.userMessageCreatedAt,userMessageVariant:re.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(Oj,{message:e,previousMessage:C,nextMessage:void 0,turnGroupingContext:E,assistantHeaderMessageId:S,isInActiveTurn:!!k&&e.info.id===k,activeStreamingPhase:e.info.id===k?g:null,reviewTransferDirection:_,animateUserOnMount:p(e),onUserAnimationConsumed:m,onContentChange:l,animationHandlers:u(e.info.id),scrollToBottom:d},e.info.id)},t[58]=g,t[59]=R,t[60]=c,t[61]=u,t[62]=T,t[63]=r,t[64]=D.lookup,t[65]=D.ordered,t[66]=l,t[67]=m,t[68]=_,t[69]=d,t[70]=i,t[71]=p,t[72]=k,t[73]=n.activityPresentationKind,t[74]=n.completionDisposition,t[75]=n.durationMs,t[76]=n.hasConfirmedFinalBody,t[77]=n.hasReasoning,t[78]=n.hasTools,t[79]=n.headerMessageId,t[80]=n.turnId,t[81]=n.userMessage,t[82]=re,t[83]=H,t[84]=F,t[85]=N[0]?.info.id,t[86]=N.length,t[87]=ie):ie=t[87];let ae=Rk(ie),oe;bb4:{if(N===n.assistantMessages){oe=n;break bb4}let e;t[88]!==n||t[89]!==N?(e={...n,assistantMessages:N},t[88]=n,t[89]=N,t[90]=e):e=t[90],oe=e}let se=oe,ce;bb5:{if(!xA({isLastTurn:r,sessionIsWorking:i,hasAssistantMessages:n.assistantMessages.length>0,activityPresentationKind:n.activityPresentationKind,hasActiveStreamingMessage:!!h})){ce=null;break bb5}let e;t[91]===n.userMessage.info?e=t[92]:(e=bA(yA(n.userMessage.info)),t[91]=n.userMessage.info,t[92]=e),ce=e}let le=ce,ue=H.length>0,de=n.assistantMessages.length>0,fe;t[93]!==c||t[94]!==r||t[95]!==i||t[96]!==ue||t[97]!==de||t[98]!==n.activityPresentationKind||t[99]!==n.completionDisposition?(fe=Dj({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:ue,hasAssistantMessages:de,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[93]=c,t[94]=r,t[95]=i,t[96]=ue,t[97]=de,t[98]=n.activityPresentationKind,t[99]=n.completionDisposition,t[100]=fe):fe=t[100];let pe;return t[101]!==T||t[102]!==C||t[103]!==le||t[104]!==ae||t[105]!==se||t[106]!==v||t[107]!==fe?(pe=(0,$.jsx)(wO,{turn:se,activityExpanded:C,onToggleActivity:T,showCompactionStatus:fe,pendingAssistantHeader:le,stickyUserHeader:v,renderMessage:ae}),t[101]=T,t[102]=C,t[103]=le,t[104]=ae,t[105]=se,t[106]=v,t[107]=fe,t[108]=pe):pe=t[108],pe});kj.displayName=`TurnBlock`;var Aj=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}=st();if(xt(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)(Oj,{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});Aj.displayName=`UngroupedMessageRow`;var jj=Z.memo(e=>{let t=(0,Q.c)(29),{entry:n,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}=e;if(n.kind===`ungrouped`){let e;return t[0]!==m||t[1]!==h||t[2]!==n.message||t[3]!==n.nextMessage||t[4]!==n.previousMessage||t[5]!==i||t[6]!==r||t[7]!==p||t[8]!==g||t[9]!==a||t[10]!==f?(e=(0,$.jsx)(Aj,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}),t[0]=m,t[1]=h,t[2]=n.message,t[3]=n.nextMessage,t[4]=n.previousMessage,t[5]=i,t[6]=r,t[7]=p,t[8]=g,t[9]=a,t[10]=f,t[11]=e):e=t[11],e}let _;return t[12]!==m||t[13]!==h||t[14]!==c||t[15]!==d||t[16]!==n.isLastTurn||t[17]!==n.turn||t[18]!==i||t[19]!==r||t[20]!==u||t[21]!==p||t[22]!==g||t[23]!==a||t[24]!==s||t[25]!==f||t[26]!==o||t[27]!==l?(_=(0,$.jsx)(kj,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o}),t[12]=m,t[13]=h,t[14]=c,t[15]=d,t[16]=n.isLastTurn,t[17]=n.turn,t[18]=i,t[19]=r,t[20]=u,t[21]=p,t[22]=g,t[23]=a,t[24]=s,t[25]=f,t[26]=o,t[27]=l,t[28]=_):_=t[28],_});jj.displayName=`MessageListEntry`;var Mj=Z.memo(({entries:e,engine:t,contentRef:n,scrollRef:r,registerTanstackVirtualizer:i,virtualizerKey:a,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g})=>{let _=t===`tanstack`,v=Z.useRef(t),y=Z.useRef(null),[b,x]=Z.useReducer(e=>e+1,0);if(t===`none`)y.current=null;else if(v.current===`none`&&_&&y.current===null){let e=n.current,t=r?.current;e&&t&&(y.current=Sj(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&Zi();Z.useEffect(()=>{if(!T)return;let e=r?.current;if(!e)return;let t=()=>{S.current=!0},n=()=>{S.current=!1},i=()=>{C.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`,i,{passive:!0}),()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),e.removeEventListener(`scroll`,i)}},[T,r]);let E=()=>S.current||performance.now()-C.current<JA,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*XA},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&QA(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<YA)?w.current===null&&(w.current=performance.now()):(w.current=null,k(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);et(()=>{if(w.current===null)return;let e=performance.now()-w.current>=YA;(!E()||D()||e)&&j()},T?ZA:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=BA(),[F,I]=Z.useState(()=>Vk(P));Z.useEffect(()=>{if(!(!_||F>=P))return ls(()=>{Z.startTransition(()=>{I(e=>Hk(e,P))})})},[F,_,P]);let L=rj(a,u),[R]=Z.useState(()=>_?fj(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=nj(u),V=Z.useRef(B),H=Z.useRef(u);H.current!==u&&(H.current=u,V.current=B);let U=Z.useRef(_),ee=Z.useRef(new Map),te=Z.useRef(void 0);Z.useLayoutEffect(()=>{if(_)return;let e=n?.current;if(!e)return;let t=ee.current;t.clear(),e.querySelectorAll(`[data-turn-entry]`).forEach(e=>{let n=e.dataset.turnEntry;n&&t.set(n,e.getBoundingClientRect().height)}),te.current=void 0}),_&&te.current===void 0&&(te.current=R??ej(N,ee.current,V.current));let W=hc({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{oj(z.current,n.getTotalSize()),mc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:qA,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:te.current}),G=Z.useRef(null),ne=Z.useRef(null);_||(G.current=null);let re=K(()=>{if(!_)return;let e=z.current??r?.current;if(!e)return;let t=e.offsetWidth;if(!ij(G.current,t)){G.current===null&&t>0&&(G.current=t);return}G.current=t,ne.current!==null&&clearTimeout(ne.current),ne.current=setTimeout(()=>{ne.current=null,W.measure()},220)}),ie=_&&typeof ResizeObserver<`u`;ot(ie?z:null,re),ot(ie&&r?r:null,re),tt(()=>{ne.current!==null&&(clearTimeout(ne.current),ne.current=null)}),it(()=>{_&&re()},[_]),it(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=bj(n,e.messageId);if(i){let t=i.getBoundingClientRect().top-n.getBoundingClientRect().top-e.offsetTop;Math.abs(t)>.5&&(n.scrollTop+=t),y.current=null;return}let a=N.indexOf(e.entryKey);if(a<0||e.attempts>=1){y.current=null;return}e.attempts+=1,W.scrollToIndex(a,{align:`start`}),x()},[t,N,_,W,b]);let ae=W.getVirtualItems(),oe=ae.map(e=>e.index),[se,ce]=Z.useState(()=>Xk(N,{seedCount:sj(u),restore:Jk(L)})),le=Zk(se,N);le!==se&&ce(le);let ue=Z.useRef(le);ue.current=le;let de=Z.useRef(null);W.scrollDirection&&(de.current=W.scrollDirection);let fe=W.range?.startIndex??ae[0]?.index??Math.max(0,A.length-1),pe=W.range?.endIndex??ae[ae.length-1]?.index??Math.max(0,A.length-1),me=W.isScrolling,he=Math.max(0,pe-fe+1),ge=$k({entryKeys:N,mountedIndexes:oe,visibleStartIndex:fe,visibleEndIndex:pe,scrollDirection:de.current,preloadEntries:sj(u,he),hydratedKeys:le,allowVisibleRelease:!me,preloadReleaseLimit:me?cj(u):FA,visibleReleaseLimit:me?0:lj(u)}),_e=ge.join(`\0`),ve=Z.useRef(ge);ve.current=ge,Z.useEffect(()=>{if(!(!_||!_e))return ls(()=>{Z.startTransition(()=>{ce(e=>{let t=null;for(let n of ve.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,_e]),Z.useEffect(()=>{ce(e=>eA(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=W.itemSizeCache,t=uj(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(KA,Math.max(GA,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(W),()=>{pj(L,M.current.map(e=>e.key),W),Yk(L,ue.current),i?.(null)}},[_,W,L]);let ye=Rk((e,t=!0)=>(0,$.jsx)(Wk,{enabled:t,children:(0,$.jsx)(jj,{entry:e,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,sessionIsWorking:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g},e.key)}));if(t===`none`)return(0,$.jsx)(`div`,{ref:n,className:`relative w-full`,children:A.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:ye(e)},e.key))});if(t===`tanstack`){let e=aj(ae[0]?.start??0,ae[ae.length-1]?.end??0,W.getTotalSize());return(0,$.jsx)(`div`,{ref:z,className:`relative w-full`,style:{minHeight:e.minHeight},children:(0,$.jsx)(`div`,{style:{paddingTop:e.paddingTop,paddingBottom:e.paddingBottom},children:ae.map(e=>{let t=A[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:W.measureElement,"data-turn-entry":t.key,className:`oc-chat-message-layout-boundary`,children:ye(t,le.has(t.key))},t.key):null})})})}return null});Mj.displayName=`StaticHistoryList`;var Nj=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(`div`,{className:`oc-chat-message-layout-boundary`,children:(0,$.jsx)(jj,{...e})}),t[0]=e,t[1]=n),n});Nj.displayName=`TailEntry`;var Pj=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=_r(_??``,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=Lk(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)(Nj,{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};Pj.displayName=`StreamingTailContent`;var Fj=e=>{let t=(0,Q.c)(63),{historyEntries:n,tailEntries:r,timelineCacheKey:i,directory:a,sessionId:o,scrollRef:s,registerList:c,onHistoryContentChange:l,onTailContentChange:u,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,showTurnChangedFiles:y,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w,header:T,footer:E,scrollClassName:D,scrollStyle:O,onScroll:k,followEnabled:A,onIsAtEndChange:j}=e,M=A===void 0||A,N=n.length,P=r.length>0?r[r.length-1]:void 0,F=P?.key??null,I=_r(S??``,a,o??void 0),L;bb0:{if(!P){L=r;break bb0}let e=v===`sorted`,n;t[0]!==S||t[1]!==I||t[2]!==P||t[3]!==y||t[4]!==e?(n=Lk(P,{activeStreamingMessageId:S,liveParts:I,showTextJustificationActivity:e,showTurnChangedFiles:y}),t[0]=S,t[1]=I,t[2]=P,t[3]=y,t[4]=e,t[5]=n):n=t[5];let i=n;if(i===P){L=r;break bb0}let a;t[6]!==i||t[7]!==r?(a=r.slice(),a[a.length-1]=i,t[6]=i,t[7]=r,t[8]=a):a=t[8],L=a}let R=L,z;t[9]!==n||t[10]!==R?(z=R.length>0?[...n,...R]:n,t[9]=n,t[10]=R,t[11]=z):z=t[11];let B=z,V;t[12]===h?V=t[13]:(V={resolvePreloadEntries:e=>sj(h,e),resolvePreloadReleaseWhileScrolling:()=>cj(h),resolveVisibleReleaseLimit:()=>lj(h)},t[12]=h,t[13]=V);let H=V,U;t[14]!==S||t[15]!==C||t[16]!==h||t[17]!==v||t[18]!==N||t[19]!==F||t[20]!==w||t[21]!==m||t[22]!==y||t[23]!==p||t[24]!==g?(U={historyCount:N,newestTailKey:F,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,chatRenderMode:v,showTurnChangedFiles:y,stickyUserHeader:p,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w},t[14]=S,t[15]=C,t[16]=h,t[17]=v,t[18]=N,t[19]=F,t[20]=w,t[21]=m,t[22]=y,t[23]=p,t[24]=g,t[25]=U):U=t[25];let ee=U,te;t[26]!==S||t[27]!==C||t[28]!==h||t[29]!==v||t[30]!==d||t[31]!==N||t[32]!==F||t[33]!==l||t[34]!==u||t[35]!==_||t[36]!==x||t[37]!==w||t[38]!==f||t[39]!==m||t[40]!==b||t[41]!==p||t[42]!==g?(te=(e,t,n)=>{let r=t>=N,i=F!==null&&e.key===F;return(0,$.jsx)(ms,{disabled:!r,children:(0,$.jsx)(Wk,{enabled:n,children:(0,$.jsx)(jj,{entry:e,onMessageContentChange:r?u:l,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:i?m:!1,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:i?S:null,activeStreamingPhase:i?C:null,reviewTransferDirection:w})})})},t[26]=S,t[27]=C,t[28]=h,t[29]=v,t[30]=d,t[31]=N,t[32]=F,t[33]=l,t[34]=u,t[35]=_,t[36]=x,t[37]=w,t[38]=f,t[39]=m,t[40]=b,t[41]=p,t[42]=g,t[43]=te):te=t[43];let W=Rk(te),G;t[44]===h?G=t[45]:(G=nj(h),t[44]=h,t[45]=G);let ne;return t[46]!==B||t[47]!==M||t[48]!==E||t[49]!==T||t[50]!==H||t[51]!==j||t[52]!==k||t[53]!==c||t[54]!==W||t[55]!==ee||t[56]!==D||t[57]!==s||t[58]!==O||t[59]!==m||t[60]!==G||t[61]!==i?(ne=(0,$.jsx)(Uk,{enabled:!0,children:(0,$.jsx)(sA,{entries:B,timelineCacheKey:i,estimatedItemSize:G,hydrationTuning:H,renderEntry:W,rowInvalidationKey:ee,scrollElementRef:s,registerList:c,followEnabled:M,sessionIsWorking:m,header:T,footer:E,className:D,style:O,onScroll:k,onIsAtEndChange:j})}),t[46]=B,t[47]=M,t[48]=E,t[49]=T,t[50]=H,t[51]=j,t[52]=k,t[53]=c,t[54]=W,t[55]=ee,t[56]=D,t[57]=s,t[58]=O,t[59]=m,t[60]=G,t[61]=i,t[62]=ne):ne=t[62],ne};Fj.displayName=`LegendTimelineHost`;var Ij=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:c,getAnimationHandlers:l,scrollToBottom:u,scrollRef:d,directory:f,headerSlot:p,footerSlot:m,timelineScrollClassName:h,timelineScrollStyle:g,timelineOnScroll:_,timelineFollowEnabled:v,timelineOnIsAtEndChange:y},b)=>{Le(`ui.message_list.render`);let{sessionKey:x,virtualizerKey:S}=tj(e,t),C=s(e=>e.stickyUserHeader),w=s(e=>e.chatRenderMode),T=s(e=>e.activityRenderMode),E=s(e=>e.showTurnChangedFiles),D=pr(e=>e.reviewTransferBySessionId.get(x)??null),[O,k]=Z.useState(()=>new Map),A=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),j=K(l),M=K(()=>{u?.()}),N=K((e,t)=>{k(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:QD(i)}),r})}),P=Z.useMemo(()=>we(`ui.message_list.base_display_ms`,()=>{let e=new Set,t=new Map,r=[];for(let e of n){let n=e.info?.id;typeof n==`string`&&t.set(n,e)}for(let i=0;i<n.length;i+=1){let a=n[i],o=a.info?.id;if(typeof o==`string`){if(e.has(o))continue;e.add(o)}r.push(PO(typeof o==`string`?t.get(o)??a:a))}let i=[],a=new Set;for(let e=0;e<r.length;e+=1){let t=r[e],n=hj(t,a);AO(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(gj(o)){let e=wj(n);if(e.hide){i[i.length-1]=Tj(o,e.taskSessionId);continue}}if(uA(o)){let e=dA(n,_j(o));if(e.hide){i[i.length-1]=Ej(o,e.details);continue}}i.push(n)}return i}),[n]),F=Z.useRef(null),I=Z.useRef(null),L=Z.useCallback(()=>{let e=I.current;e&&(I.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{L()},[L]);let R=K(()=>d?.current?d.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),z=Z.useMemo(()=>we(`ui.message_list.retry_overlay_ms`,()=>Fk(P,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[P,o]),B=r||!!i,V=Z.useRef(B),H=Z.useRef(x);H.current!==x&&(H.current=x,V.current=!1),B&&(V.current=!0);let{projection:U,staticTurns:ee,streamingTurns:te}=Nk(z,{sessionKey:x,showTextJustificationActivity:w===`sorted`,showTurnChangedFiles:E,hasLiveTail:B||V.current,liveTailActive:B}),W=U.ungroupedMessageIds.size>0,G=W?z:wA,ne=W?U.ungroupedMessageIds:TA,re=Z.useMemo(()=>we(`ui.message_list.render_entries_ms`,()=>{let e=ee.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===U.lastTurnId}));if(ne.size===0)return e;let t=new Map;e.forEach(e=>{t.set(e.turn.userMessage.info.id,e)});let n=[];return G.forEach((e,r)=>{let i=t.get(e.info.id);if(i){n.push(i);return}ne.has(e.info.id)&&n.push({kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:r>0?G[r-1]:void 0,nextMessage:r<G.length-1?G[r+1]:void 0})}),n}),[U.lastTurnId,G,ne,ee]),ie=Z.useMemo(()=>{if(te.length>0)return te.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===U.lastTurnId}));if(U.ungroupedMessageIds.size===0)return EA;let e=z[z.length-1];return!e||!U.ungroupedMessageIds.has(e.info.id)?EA:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:z.length>1?z[z.length-2]:void 0,nextMessage:void 0}]},[z,U.lastTurnId,U.ungroupedMessageIds,te]),ae=ie.length>0;ae&&B&&Le(`ui.message_list.render.streaming`);let oe=re,se=oe.length>=CA,ce=Z.useRef(se);dj(ce,se);let le=se?`tanstack`:`none`,ue=Zb(e=>e.legendTimelineEnabled),de=Z.useRef(null),fe=K(e=>{de.current=e}),pe=Z.useRef(null),me=K(e=>{pe.current=e}),he=Z.useMemo(()=>ie.length>0?[...oe,...ie]:oe,[oe,ie]),ge=K(e=>{c(e)}),_e=K(e=>{c(e)}),ve=Z.useMemo(()=>n.filter(e=>mj(e)===`user`).map(e=>e.info.id),[n]);{let t=A.current;t.sessionKey!==e&&(t.sessionKey=e,t.previousOrder=ve,t.animatedIds=new Set);let n=t.previousOrder;if(ve.length>n.length&&n.every((e,t)=>ve[t]===e)&&Zt(e))for(let r=n.length;r<ve.length;r+=1){let n=ve[r];if(n&&!t.animatedIds.has(n)){if(!Rt(e))break;t.animatedIds.add(n)}}t.previousOrder=ve}let ye=K(e=>mj(e)===`user`&&A.current.animatedIds.has(e.info.id)),be=K(e=>{A.current.animatedIds.delete(e)}),xe=Z.useMemo(()=>{let e=new Map;return he.forEach((t,n)=>{if(t.kind===`ungrouped`){e.set(t.message.info.id,n);return}e.set(t.turn.userMessage.info.id,n),t.turn.assistantMessages.forEach(t=>{e.set(t.info.id,n)})}),e},[he]),Se=Z.useMemo(()=>{let e=new Map;return he.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[he]),Ce=K(e=>{let t=R();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Te=K((e,t=`auto`)=>{if(e<0||e>=oe.length)return!1;if(ue){let n=de.current;return n?(n.scrollToIndex({index:e,animated:t===`smooth`,viewOffset:0}),!0):!1}if(!se)return!1;let n=pe.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),Ee=K((e,t=`auto`)=>{let n=R();if(!n)return!1;let r=Ce(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(!b)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Se.get(e);if(r===void 0)return!1;let i=R();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):ae&&r>=oe.length?!1:Te(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=xe.get(e);return r===void 0?!1:Ee(e,n)||(ae&&r>=oe.length?!1:Te(r,n))},holdViewportAnchor:e=>{let t=R();if(!t||typeof window>`u`)return;L();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(),I.current?.cancel===s&&(I.current=null))},c=()=>{s()};I.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=Ce(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>=VA||n>=HA){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:L,isHistoryVirtualized:()=>ue?!0:ce.current,captureViewportAnchor:()=>{let e=R();if(!e)return null;let t=e.getBoundingClientRect(),n=Array.from(e.querySelectorAll(`[data-message-id]`)),r=n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!yj(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=R();if(!t||!xe.has(e.messageId))return!1;let n=()=>{let n=Ce(e.messageId);if(!n)return!1;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect().top-r.top-e.offsetTop;return i!==0&&(t.scrollTop+=i),!0};if(!n()){let t=xe.get(e.messageId);if(typeof t==`number`&&t<oe.length)return Te(t,`auto`)}return n()},scrollToBottom:()=>{if(ue){de.current?.scrollToEnd({animated:!1});return}if(se&&oe.length>0&&pe.current){pe.current.scrollToEnd();return}let e=R();e&&(e.scrollTop=e.scrollHeight)}};if(typeof b==`function`)return b(e),()=>{b(null)};let t=b;return t.current=e,()=>{t.current=null}},[L,oe.length,ue,xe,se,ae,Se,b]),ue?(0,$.jsx)(Fj,{historyEntries:oe,tailEntries:ie,timelineCacheKey:rj(S,T),directory:f,sessionId:x,scrollRef:d,registerList:fe,onHistoryContentChange:ge,onTailContentChange:_e,getAnimationHandlers:j,scrollToBottom:M,stickyUserHeader:C,sessionIsWorking:r,activityRenderMode:T,turnUiStates:O,onToggleTurnGroup:N,chatRenderMode:w,showTurnChangedFiles:E,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:D,header:p,footer:m,scrollClassName:h,scrollStyle:g,onScroll:_,followEnabled:v,onIsAtEndChange:y},S):(0,$.jsx)(`div`,{children:(0,$.jsx)(ms,{disabled:!1,children:(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(ms,{disabled:se,children:(0,$.jsx)(Uk,{enabled:!0,children:(0,$.jsx)(Mj,{entries:oe,engine:le,contentRef:F,scrollRef:d,registerTanstackVirtualizer:me,virtualizerKey:S,onMessageContentChange:ge,getAnimationHandlers:j,scrollToBottom:M,stickyUserHeader:C,activityRenderMode:T,turnUiStates:O,onToggleTurnGroup:N,chatRenderMode:w,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,reviewTransferDirection:D},S)})}),(0,$.jsx)(Pj,{entries:ie,directory:f,sessionId:x,onMessageContentChange:_e,getAnimationHandlers:j,scrollToBottom:M,stickyUserHeader:C,sessionIsWorking:r,activityRenderMode:T,turnUiStates:O,onToggleTurnGroup:N,chatRenderMode:w,showTurnChangedFiles:E,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:D})]})})})});Ij.displayName=`MessageList`;var Lj=Z.memo(Ij);function Rj(e){return e.info.id}function zj(e){return e!==null}var Bj=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},Vj=({diff:e,filePath:t})=>{let{currentTheme:n}=za(),r=Z.useMemo(()=>Co(n),[n]),i=Z.useMemo(()=>Zs(e),[e]),a=ns(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
6581
+ `)}return lt&&lt.trim().length>0?lt:en(ze)},[lt,ze,K]),pt=dt.length>0,mt=Z.useCallback(async()=>(await ct(dt)).ok?(K&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[K,dt]),ht=Z.useCallback(async()=>{if(!(!re||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(re,e.info.id,{directory:g.directory??void 0})}finally{B.current=null,z(null)}}},[re,e.info.id,C,g]),_t=q(()=>{if(!re||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(re,e.info.id,t).catch(()=>{})}),vt=q(()=>{re&&O(re)}),yt=Z.useCallback(async()=>{if(e.info.id,!re||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!re,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(re,e.info.id)}finally{B.current=null,z(null)}}},[re,e.info.id,T]),bt=q(t=>{let n=He.has(t),r=Ue.has(t);if(n){W(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),fO(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),uO(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),uO(e.info.id,r),r}),W(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),fO(e.info.id,r),r})}),xt=i??null,St=Z.useRef(!1),wt=Z.useRef(!1),Tt=Z.useRef(!1),Et=Z.useRef(!1),Dt=Z.useRef(!1),Ot=Z.useRef(!1);Z.useEffect(()=>{wt.current=!1,Tt.current=!1,Et.current=!1,Dt.current=!1,St.current=!1,Ot.current=!1},[e.info.id]);let kt=Z.useCallback(()=>{K||St.current||(St.current=!0,r?.(`structural`))},[K,r]),At=s(e=>e.setImagePreviewOpen),jt=Z.useCallback(e=>{(e.image||e.mermaid)&&(G(e),At(!0))},[At]),Mt=Z.useCallback(e=>{G(t=>({...t,open:e})),At(e)},[At]),Nt=!!vO(e.info,`animationSettled`),Pt=nt===`streaming`||nt===`cooldown`;Pt&&(Ot.current=!0);let Ft=Z.useMemo(()=>!K&&Re.some(e=>e.type===`reasoning`),[K,Re]),It=Je&&!Nt&&!Pt&&!Ot.current,Lt=!K&&Je&&Be.length>0&&!qe;return Z.useEffect(()=>{if(xt?.onStreamingCandidate){if(!Lt){Tt.current&&=(Ft&&xt?.onReasoningBlock?xt.onReasoningBlock():xt?.onReservationCancelled&&xt.onReservationCancelled(),!1);return}Dt.current||(Dt.current=!0,xt.onStreamingCandidate(),Tt.current=!0)}},[xt,Lt,Ft]),Z.useEffect(()=>{xt?.onAnimationStart&&It&&(Et.current||=(xt.onAnimationStart(),!0))},[xt,It]),Z.useEffect(()=>{if(K)return;let e=xt?.onAnimatedHeightChange;if(!e||!(It||Lt))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[It,K,xt,Lt]),Ge?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,K?p?`pt-2`:`pt-6`:!K&&rt?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,K||tt?`pb-0`:et?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:y,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:K?Ct(ze)?(0,$.jsx)(ds,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,p?void 0:`group/user-shell`),children:(0,$.jsxs)(`div`,{className:Y(`max-w-[85%]`,ne?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:`px-3 py-1.5 shadow-none border border-primary/5`,children:(0,$.jsx)(VD,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:bt,onShowPopup:jt,streamPhase:nt,allowAnimation:It,onContentChange:r,shouldShowHeader:!1,hasTextContent:pt,onCopyMessage:mt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:kt,agentMention:We,onEdit:!E&&_.edit?_t:void 0,onRevert:!E&&_.revert?ht:void 0,onFork:!E&&K&&_.fork?yt:void 0,editing:E,editStaged:D,onCancelEdit:D?vt:void 0,pendingMessageAction:R,errorMessage:lt,errorVariant:ut,userActionsMode:te?`external-content`:`inline`,stickyUserHeaderEnabled:j})}),te?(0,$.jsx)(VD,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:bt,onShowPopup:jt,streamPhase:nt,allowAnimation:It,onContentChange:r,shouldShowHeader:!1,hasTextContent:pt,onCopyMessage:mt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:kt,agentMention:We,onEdit:!E&&_.edit?_t:void 0,onRevert:!E&&_.revert?ht:void 0,onFork:!E&&K&&_.fork?yt:void 0,editing:E,editStaged:D,onCancelEdit:D?vt:void 0,pendingMessageAction:R,errorMessage:lt,errorVariant:ut,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[rt&&(0,$.jsx)($b,{isUser:K,isMobile:p,providerID:ke,modelID:Ae,agentName:Oe,modelName:je,variant:ot}),(0,$.jsx)(VD,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Re,sourceParts:ce,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCompletedAt:Me??void 0,messageCreatedAt:Ne??void 0,messageTokens:Le,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:Ue,onToggleTool:bt,onShowPopup:jt,streamPhase:nt,allowAnimation:It,onContentChange:r,shouldShowHeader:rt,hasTextContent:pt,onCopyMessage:mt,copiedMessage:I,onAuxiliaryContentComplete:kt,showReasoningTraces:A,agentMention:We,turnGroupingContext:a,errorMessage:lt,errorVariant:ut,reviewTransferDirection:f})]})})}),ee.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(rO,{popup:ee,onOpenChange:Mt,isMobile:p})}):null]})},(e,t)=>tS({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&nS(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&nS(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.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&uS(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,JD(e.message.info).isUser)),bO=Z.memo(e=>{let t=(0,Q.c)(10),{assistantMessages:n,activityExpanded:r,renderMessage:i}=e,a;if(t[0]!==r||t[1]!==n||t[2]!==i){let e;t[4]!==r||t[5]!==i?(e=e=>i(e,r),t[4]=r,t[5]=i,t[6]=e):e=t[6],a=n.map(e),t[0]=r,t[1]=n,t[2]=i,t[3]=a}else a=t[3];let o;return t[7]!==r||t[8]!==a?(o=(0,$.jsx)(`div`,{className:`relative z-0`,"data-turn-assistant-activity-expanded":r,children:a}),t[7]=r,t[8]=a,t[9]=o):o=t[9],o}),xO=new Set,SO=()=>{},CO=()=>{},wO=Z.memo(e=>{let t=(0,Q.c)(32),{turn:n,activityExpanded:r,showCompactionStatus:i,pendingAssistantHeader:a,onToggleActivity:o,stickyUserHeader:c,renderMessage:l}=e,u=a===void 0?null:a,d=c===void 0||c,f=s(TO),p=n.userMessage.info.time?.created,m=n.activityPresentationKind===`compaction`,h=`turn-${n.turnId}`,g;t[0]!==r||t[1]!==m||t[2]!==l||t[3]!==d||t[4]!==n.userMessage?(g=m?null:d?(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:l(n.userMessage,r)}),(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`})]}):l(n.userMessage,r),t[0]=r,t[1]=m,t[2]=l,t[3]=d,t[4]=n.userMessage,t[5]=g):g=t[5];let _;t[6]!==f||t[7]!==u||t[8]!==d||t[9]!==n.assistantMessages?(_=u?(0,$.jsx)(`div`,{className:`group w-full ${f?d?`pt-4`:`pt-0`:`pt-6`} ${n.assistantMessages.length===0?`pb-1`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)($b,{isUser:!1,isMobile:f,providerID:u.providerID,modelID:u.modelID,agentName:u.agentName,modelName:u.modelName,variant:u.variant})})}):null,t[6]=f,t[7]=u,t[8]=d,t[9]=n.assistantMessages,t[10]=_):_=t[10];let v;t[11]!==r||t[12]!==f||t[13]!==o||t[14]!==i||t[15]!==n.assistantMessages||t[16]!==n.completionDisposition||t[17]!==n.durationMs||t[18]!==p?(v=i?(0,$.jsx)(`div`,{className:`group w-full ${f?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(iD,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof p==`number`?p:void 0,onToggle:o,isMobile:f,expandedTools:xO,onToggleTool:SO,onShowPopup:CO,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[11]=r,t[12]=f,t[13]=o,t[14]=i,t[15]=n.assistantMessages,t[16]=n.completionDisposition,t[17]=n.durationMs,t[18]=p,t[19]=v):v=t[19];let y;t[20]!==r||t[21]!==l||t[22]!==n.assistantMessages?(y=(0,$.jsx)(bO,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:l}),t[20]=r,t[21]=l,t[22]=n.assistantMessages,t[23]=y):y=t[23];let b;return t[24]!==r||t[25]!==h||t[26]!==g||t[27]!==_||t[28]!==v||t[29]!==y||t[30]!==n.turnId?(b=(0,$.jsxs)(`section`,{className:`relative w-full`,id:h,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[g,_,v,y]}),t[24]=r,t[25]=h,t[26]=g,t[27]=_,t[28]=v,t[29]=y,t[30]=n.turnId,t[31]=b):b=t[31],b});function TO(e){return e.isMobile}var EO=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},DO=e=>{let t=e?.type;return t===`compaction`||t===`text`&&EO(e).trim()===`/compact`},OO=e=>e?e.some(e=>DO(e)):!1,kO=e=>OO(e.parts),AO=e=>e?OO(e.sourceParts)||OO(e.parts):!1,jO=e=>{if(!kO(e))return e;let t=!1,n=e.parts.map(e=>e?.type===`compaction`?(t=!0,{type:`text`,text:`/compact`}):e),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},MO=e=>{let t=fn(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},NO=new WeakMap,PO=e=>{let t=NO.get(e);if(t)return t;let n=jO(MO(e)),r=n.parts,i=Yn(r),a=i===r?n:{...n,parts:i,sourceParts:r};return NO.set(e,a),a},FO=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,IO=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},LO=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},RO=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},zO=(e,t,n,r)=>({id:FO(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:IO(n)}),BO=e=>{let t=[],n=!1,r=!1;e.assistantMessages.forEach(e=>{e.parts.forEach(e=>{if(e.type===`tool`){n=!0;return}e.type===`reasoning`&&LO(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&cT(RO(t),t.parts));e.assistantMessages.forEach(n=>{let r=RO(n),a=n.parts.some(e=>e.type===`tool`);n.parts.forEach((o,s)=>{let c=o.type===`tool`,l=o.type===`reasoning`||o.type===`text`?LO(o):void 0,u=FO(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&cT(r,n.parts)&&e.summarySourceMessageId===n.info.id&&e.summarySourcePartId===u,f=null;c?f=`tool`:o.type===`reasoning`?f=`reasoning`:e.showTextJustificationActivity&&o.type===`text`&&l&&!d&&(i||a||typeof r==`string`&&r!==`stop`)&&(f=`justification`),f&&t.push({...zO(e.turnId,n.info.id,o,s),kind:f})})});let a=[];if(t.length>0){let n=e.assistantMessages[0]?.info.id;n&&a.push({id:`${e.turnId}:activity`,anchorMessageId:n,afterToolPartId:null,parts:t})}return{activityParts:t,activitySegments:a,hasTools:n,hasReasoning:r}},VO=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;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})})});let a=e.length>0?e[e.length-1]:null,o=new Set;return a&&(o.add(a.userMessageId),a.assistantMessageIds.forEach(e=>{o.add(e)})),{turns:e,indexes:{turnById:t,messageToTurnId:n,messageMetaById:r},lastTurnId:a?.turnId??null,lastTurnMessageIds:o,ungroupedMessageIds:new Set}},HO=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},UO=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(cT(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!lT(t))continue;let r=HO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:FO(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=HO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:FO(n.info.id,t,e)}}}return{}},WO=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}},GO=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},KO=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},qO=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},JO=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},YO=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},XO=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},ZO=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},QO=(e,t)=>{let n=KO(e);return{messageId:e.info.id,role:n,parentMessageId:qO(e),message:e,order:t}},$O=(e,t)=>{let n=JO(e),r,i,a=!1;t.forEach(e=>{let t=YO(e);typeof t==`number`?r=Math.max(r??0,t):a=!0,e.parts.forEach(e=>{let t=XO(e);typeof t==`number`&&(i=Math.max(i??0,t))})});let o=r??i,s=typeof n==`number`&&typeof o==`number`&&o>=n?o-n:void 0;return{isStreaming:a,isRetrying:t.length>1,startedAt:n,completedAt:r,durationMs:s}},ek=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`||sT(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 YO(t)!=`number`)return`active`;return`active`},tk=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return uT(n.finish,t.parts,n.error)},nk=e=>AO(e)?`compaction`:`default`,rk={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},ik=(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},ak=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&ik(e.assistantMessages,t.assistantMessages),ok=(e,t)=>{e.summary=UO(e.assistantMessages),e.summaryText=e.summary.text??ZO(e.userMessage),e.diffStats=WO(e.userMessage),e.changedFiles=t.showTurnChangedFiles?GO(e.userMessage):void 0,e.completionDisposition=ek(e.assistantMessages),e.hasConfirmedFinalBody=tk(e.assistantMessages),e.activityPresentationKind=nk(e.userMessage);let n=BO({turnId:e.turnId,assistantMessages:e.assistantMessages,summarySourceMessageId:e.summary.sourceMessageId,summarySourcePartId:e.summary.sourcePartId,showTextJustificationActivity:t.showTextJustificationActivity});return e.activityParts=n.activityParts,e.activitySegments=n.activitySegments,e.hasTools=n.hasTools,e.hasReasoning=n.hasReasoning,e.stream=$O(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},sk=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>ok(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&&ak(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,ok(e,t))});return r&&i?n.turns:a},ck=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},lk=(e,t)=>{let n={...rk,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(KO(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[QO(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(n),i.set(n.userMessageId,n),a.add(e.info.id)}),e.forEach((e,t)=>{if(KO(e)!==`assistant`)return;let n=qO(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(QO(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=VO(ck(sk(r,n))),s=new Set;return e.forEach(e=>{KO(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},uk=30,dk=4,fk=4,pk=33554432,mk=8388608,hk=new Map,gk=new Map,_k=0,vk=new WeakMap,yk=1,bk=()=>d()?dk:Zi()?fk:uk,xk=()=>d()||Zi()?mk:pk,Sk=(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},Ck=e=>{hk.delete(e);let t=gk.get(e)??0;gk.delete(e),_k=Math.max(0,_k-t)},wk=e=>{let t=vk.get(e);if(t!==void 0)return t;let n=yk;return yk+=1,vk.set(e,n),n},Tk=e=>e.map(e=>`${wk(e.info)}:${wk(e.parts)}:${e.parts.map(e=>wk(e)).join(`,`)}`).join(`;`),Ek=(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,Tk(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},Dk=e=>{let t=hk.get(e);return t&&(hk.delete(e),hk.set(e,t)),t},Ok=(e,t)=>{Ck(e);let n=bk(),r=xk(),i=Sk(e,t);if(!(i>r)){for(;hk.size>=n||_k+i>r;){let e=hk.keys().next().value;if(typeof e!=`string`)break;Ck(e)}hk.set(e,t),gk.set(e,i),_k+=i}},kk=[],Ak=(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},jk=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},Mk=(e,t)=>t===null?{staticTurns:e,streamingTurns:kk}:{staticTurns:t===0?kk:e.slice(0,t),streamingTurns:e.slice(t)},Nk=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(kk),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=kk,a.current=null);let l=Z.useMemo(()=>{let r=Ek(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=Dk(r);return i?(n.current=i,i):Ce(`ui.turns.projection_ms`,()=>{let i=lk(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,Ok(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=jk({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=Mk(l.turns,u).staticTurns;return Ak(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=Mk(l.turns,u).streamingTurns;return Ak(i.current,e)?i.current:i.current=e},[u,l.turns])}},Pk=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},Fk=(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(Pk(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(Pk(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},Ik=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=hn(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:PO({...e,parts:r})},Lk=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=Ik(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=Ik(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=lk([e.turn.userMessage,...i],{showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles}).turns[0]??{...e.turn,assistantMessages:i,assistantMessageIds:i.map(e=>e.info.id)};return{...e,turn:a}},Rk=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},zk=2,Bk=2,Vk=e=>Math.min(Math.max(0,e),zk),Hk=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+Bk),Uk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(FS.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Wk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ao.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Gk=12,Kk=16,qk=new Map,Jk=e=>{let t=qk.get(e);if(t)return qk.delete(e),qk.set(e,t),t},Yk=(e,t)=>{if(t.size!==0)for(qk.delete(e),qk.set(e,t);qk.size>Kk;){let e=qk.keys().next().value;if(typeof e!=`string`)break;qk.delete(e)}},Xk=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Gk)),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},Zk=(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},Qk=({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}},$k=e=>{let{visible:t,preload:n}=Qk(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},eA=(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},tA=e=>{if(!e)return;let{contentLength:t,scroll:n,scrollLength:r}=e;return typeof t==`number`&&typeof n==`number`&&typeof r==`number`&&Number.isFinite(t)?t-(n+r)<=40:e.isNearEnd??e.isAtEnd},nA={itemVisiblePercentThreshold:0},rA=100,iA=new Set,aA=Z.createContext(iA),oA=({entry:e,index:t,renderEntryRef:n})=>{let r=Z.useContext(aA);return(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:n.current?.(e,t,r.has(e.key))})},sA=Z.memo(({entries:e,timelineCacheKey:t,estimatedItemSize:n,hydrationTuning:r,renderEntry:i,rowInvalidationKey:a,scrollElementRef:o,scrollElementDataset:s,registerList:c,anchoredEndSpace:l,composerOverlayHeight:u=0,followEnabled:d=!0,sessionIsWorking:f=!1,onIsAtEndChange:p,onScroll:m,header:h,footer:g,className:_,style:v,contentContainerClassName:y,contentContainerStyle:b})=>{let x=Z.useRef(null),S=Z.useMemo(()=>e.map(e=>e.key),[e]),C=Z.useRef(S);C.current=S;let w=Z.useRef(r);w.current=r;let T=Z.useCallback(e=>{x.current=e,c?.(e)},[c]),E=Z.useCallback(e=>{let t=e?.getScrollableNode?.()??null;if(t&&s)for(let[e,n]of Object.entries(s))t.dataset[e]=n;o&&(o.current=t)},[o,s]),[D,O]=Z.useState(()=>Xk(S,{restore:Jk(t)??null})),k=Z.useRef(D);k.current=D;let A=Z.useRef(0),j=Z.useRef(0),M=Z.useRef(!0),N=Z.useRef(null),P=Z.useRef(!1),F=Z.useMemo(()=>Zk(D,S),[D,S]);Z.useEffect(()=>{O(e=>eA(e,S))},[S]),Z.useEffect(()=>()=>{Yk(t,k.current)},[t]);let I=q(()=>{P.current=!1;let e=x.current;if(!e)return;let t=C.current;if(t.length===0)return;let n=e.getState(),r=t.length-1,i=Math.max(0,Math.floor(n.startBuffered)),a=Math.min(r,Math.floor(n.endBuffered));if(!Number.isFinite(i)||!Number.isFinite(a)||a<i)return;let o=[];for(let e=i;e<=a;e+=1)o.push(e);let s=Math.max(0,Math.floor(n.start)),c=Math.min(r,Math.floor(n.end)),l=Math.max(0,c-s+1),u=Date.now()-A.current>=rA,d=w.current,f=d.resolvePreloadEntries(l),p=$k({entryKeys:t,mountedIndexes:o,visibleStartIndex:s,visibleEndIndex:c,scrollDirection:N.current,preloadEntries:f,hydratedKeys:k.current,allowVisibleRelease:u,preloadReleaseLimit:u?f:d.resolvePreloadReleaseWhileScrolling(),visibleReleaseLimit:d.resolveVisibleReleaseLimit()});p.length!==0&&Z.startTransition(()=>{O(e=>{let t=!1,n=new Set(e);for(let e of p)n.has(e)||(n.add(e),t=!0);return t?n:e})})}),L=q(()=>{P.current||(P.current=!0,ls(I))}),R=q(()=>{L()}),z=q(()=>{A.current=Date.now();let e=x.current;if(e){let t=e.getState(),n=t.scroll;Number.isFinite(n)&&n!==j.current&&(N.current=n>j.current?`forward`:`backward`,j.current=n);let r=tA(t)??t.isAtEnd;r!==M.current&&(M.current=r,p?.(r))}m?.(),L()}),B=Z.useCallback(e=>e.key,[]),V=Z.useCallback(e=>e.kind,[]),H=Z.useRef(i);H.current=i;let U=Z.useCallback(({item:e,index:t})=>(0,$.jsx)(oA,{entry:e,index:t,renderEntryRef:H}),[]),W=Z.useMemo(()=>l||!d?!1:{animated:f,on:{dataChange:!0,itemLayout:!0,layout:!0,footerLayout:!0}},[l,d,f]);return(0,$.jsx)(aA.Provider,{value:F,children:(0,$.jsx)(bc,{ref:T,refScrollView:E,data:e,extraData:a,keyExtractor:B,getItemType:V,renderItem:U,estimatedItemSize:n,initialScrollAtEnd:!0,recycleItems:!1,...l?{anchoredEndSpace:l}:{},contentInsetEndAdjustment:u,maintainScrollAtEnd:W,maintainVisibleContentPosition:{data:!0,size:!1},onScroll:z,onViewableItemsChanged:R,viewabilityConfig:nA,ListHeaderComponent:h,ListFooterComponent:g,className:_,style:v,contentContainerClassName:y,contentContainerStyle:b})})}),cA=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},lA=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},uA=e=>!e||cA(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`)}),dA=(e,t)=>{if(cA(e)!==`assistant`||t&&lA(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}}},fA=(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(cA(t)===`user`)break;let{hide:i,details:a}=dA(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},pA=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},mA=(e,t)=>{if(e.length===0)return[];if(e.filter(pA).length===e.length)return e;if(t){let n=e.findIndex(e=>e.info.id===t);if(n>=0)return e.slice(0,n+1)}return e},hA=e=>{if(e.chatRenderMode!==`sorted`)return null;let t=e.streamingAssistantMessageId;if(!t)return null;let n=e.assistants.find(e=>e.info.id===t);if(!n)return null;let r=n.info,i=fT({finish:r.finish,isMessageCompleted:pA(n),activeStreamingPhase:e.activeStreamingPhase});return pT({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},gA=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},_A=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=gA(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},vA=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},yA=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=vA(t.mode)??vA(t.agent),r=vA(t.providerID),i=vA(t.modelID),a=vA(t.model?.variant)??vA(t.variant);return!n&&!r&&!i&&!a?null:{agentName:n,providerId:r,modelId:i,variant:a}},bA=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:ft(void 0,t)||void 0,variant:e?.variant}},xA=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),SA=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:ZD(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),CA=5,wA=[],TA=new Set,EA=[],DA=16,OA=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),kA=320,AA=168,jA=8,MA=16,NA=6,PA=12,FA=4,IA=1,LA=2,RA=6,zA=4,BA=()=>Zi()?MA:jA,VA=30,HA=180,UA=5,WA=2,GA=120,KA=1200,qA=80,JA=160,YA=1500,XA=1.5,ZA=90,QA=(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},$A=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(OA(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)}}}})(DA),ej=(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})},tj=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),nj=e=>e===`collapsed`?AA:kA,rj=(e,t)=>`${e}::activity:${t}`,ij=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),aj=(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{paddingTop:r,paddingBottom:Math.max(0,a-i),minHeight:a}},oj=(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)},sj=(e,t=0)=>Math.max(e===`collapsed`?PA:NA,Math.max(0,Math.floor(t))),cj=e=>e===`collapsed`?LA:IA,lj=e=>e===`collapsed`?zA:RA,uj=e=>e===`collapsed`?WA:UA,dj=(e,t)=>{e.current=t},fj=(e,t)=>$A.read(e,t),pj=(e,t,n)=>{!n||t.length===0||$A.write(e,t,n.takeSnapshot())},mj=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},hj=(e,t)=>{if(mj(e)!==`system`)return e;let n=vj(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},gj=e=>!e||mj(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),_j=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},vj=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},yj=(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},bj=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,xj=(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&&!yj(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}},Sj=(e,t)=>{let n=xj(t,e);if(!n)return null;let r=bj(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},Cj=e=>{let t=e,n=t.state?.metadata,r=bx(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?wx(i)??null:null},wj=e=>{if(mj(e)!==`assistant`||e.parts.length!==1)return{hide:!1,taskSessionId:null};let t=e.parts[0];return t?.type!==`tool`||(typeof t.tool==`string`?t.tool.toLowerCase():``)!==`task`?{hide:!1,taskSessionId:null}:{hide:!0,taskSessionId:Cj(e.parts[0])}},Tj=(e,t)=>{if(!t)return e;let n=xx(e.parts,t);return n===e.parts?e:{...e,parts:n}},Ej=(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}},Dj=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,Oj=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,reviewTransferDirection:m}=e,h=Qm(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:h,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=h,t[3]=g):g=t[3];let _=g,v;t[4]!==c||t[5]!==l||t[6]!==f||t[7]!==o||t[8]!==s||t[9]!==n||t[10]!==i||t[11]!==d||t[12]!==u||t[13]!==r||t[14]!==m||t[15]!==p||t[16]!==a?(v=(0,$.jsx)(yO,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,reviewTransferDirection:m}),t[4]=c,t[5]=l,t[6]=f,t[7]=o,t[8]=s,t[9]=n,t[10]=i,t[11]=d,t[12]=u,t[13]=r,t[14]=m,t[15]=p,t[16]=a,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Zm.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return tS(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&nS(e.previousMessage,t.previousMessage)&&nS(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&uS(n,r,e.message.info.id,mj(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&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});Oj.displayName=`MessageRow`;var kj=Z.memo(e=>{let t=(0,Q.c)(109),{turn:n,isLastTurn:r,sessionIsWorking:i,activityRenderMode:a,turnUiStates:o,onToggleTurnGroup:s,chatRenderMode:c,onMessageContentChange:l,getAnimationHandlers:u,scrollToBottom:d,stickyUserHeader:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_}=e,v=f===void 0||f,y;t[0]!==n.turnId||t[1]!==o?(y=o.get(n.turnId),t[0]=n.turnId,t[1]=o,t[2]=y):y=t[2];let b=y,x;if(t[3]!==a||t[4]!==r||t[5]!==i||t[6]!==n.assistantMessages.length||t[7]!==n.completionDisposition||t[8]!==n.durationMs||t[9]!==n.hasConfirmedFinalBody){let e=$D({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=SA({expansionDisposition:nO({isLastTurn:r,turnCompletionDisposition:n.completionDisposition,headerPresentationDisposition:e.completionDisposition,hasAssistantMessages:n.assistantMessages.length>0}),activityRenderMode:a,isLastTurn:r,isActivelyProcessing:r&&i,hasConfirmedFinalBody:n.hasConfirmedFinalBody}),t[3]=a,t[4]=r,t[5]=i,t[6]=n.assistantMessages.length,t[7]=n.completionDisposition,t[8]=n.durationMs,t[9]=n.hasConfirmedFinalBody,t[10]=x}else x=t[10];let S=x,C=b?b.isExpanded:S,w;t[11]!==S||t[12]!==s||t[13]!==n.turnId?(w=()=>{s(n.turnId,S)},t[11]=S,t[12]=s,t[13]=n.turnId,t[14]=w):w=t[14];let T=q(w),E;if(t[15]!==n.assistantMessages||t[16]!==n.userMessage){let e=[n.userMessage,...n.assistantMessages],r=new Map;e.forEach((e,t)=>{r.set(e.info.id,t)}),E={ordered:e,lookup:r},t[15]=n.assistantMessages,t[16]=n.userMessage,t[17]=E}else E=t[17];let D=E,O;bb0:{if(h&&n.assistantMessages.some(e=>e.info.id===h)){O=h;break bb0}for(let e=n.assistantMessages.length-1;e>=0;--e){let t=n.assistantMessages[e];if(!pA(t)){O=t.info.id;break bb0}}O=null}let k=O,A;t[18]!==g||t[19]!==c||t[20]!==k||t[21]!==n.assistantMessages?(A=hA({chatRenderMode:c,assistants:n.assistantMessages,streamingAssistantMessageId:k,activeStreamingPhase:g}),t[18]=g,t[19]=c,t[20]=k,t[21]=n.assistantMessages,t[22]=A):A=t[22];let j=A,M;bb1:{if(c===`live`){M=n.assistantMessages;break bb1}let e;t[23]!==k||t[24]!==n.assistantMessages?(e=mA(n.assistantMessages,k),t[23]=k,t[24]=n.assistantMessages,t[25]=e):e=t[25],M=e}let N=M,P;t[26]===N?P=t[27]:(P=new Map,N.forEach((e,t)=>{P.set(e.info.id,t)}),t[26]=N,t[27]=P);let F=P,I;t[28]===N?I=t[29]:(I=new Set(N.map(Rj)),t[28]=N,t[29]=I);let L=I,R=N[0]?.info.id,z;bb2:{if(c!==`sorted`){z=n.activityParts;break bb2}let e;t[30]!==n.activityParts||t[31]!==n.assistantMessages.length||t[32]!==L?(e=L.size===n.assistantMessages.length?n.activityParts:n.activityParts.filter(e=>L.has(e.messageId)),t[30]=n.activityParts,t[31]=n.assistantMessages.length,t[32]=L,t[33]=e):e=t[33];let r=e,i;t[34]!==j||t[35]!==r?(i=gA(r,j),t[34]=j,t[35]=r,t[36]=i):i=t[36],z=i}let B=z,V;bb3:{if(c!==`sorted`){V=n.activitySegments;break bb3}if(j){let e;t[37]!==j||t[38]!==n.activitySegments?(e=_A(n.activitySegments,j),t[37]=j,t[38]=n.activitySegments,t[39]=e):e=t[39],V=e;break bb3}if(L.size===n.assistantMessages.length){V=n.activitySegments;break bb3}let e;if(t[40]!==n.activitySegments||t[41]!==L){let r;t[43]===L?r=t[44]:(r=e=>{let t=e.parts.filter(e=>L.has(e.messageId));if(t.length===0)return null;let n=L.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null},t[43]=L,t[44]=r),e=n.activitySegments.map(r).filter(zj),t[40]=n.activitySegments,t[41]=L,t[42]=e}else e=t[42];V=e}let H=V,U=n.userMessage.info.time?.created,W=n.userMessage.info,ee=W?.model?.variant??W?.variant,G=typeof ee==`string`&&ee.trim().length>0?ee:void 0,K=typeof U==`number`?U:void 0,te;t[45]!==K||t[46]!==n.activityPresentationKind||t[47]!==n.changedFiles||t[48]!==n.diffStats||t[49]!==n.hasReasoning||t[50]!==n.hasTools||t[51]!==n.headerMessageId||t[52]!==n.summaryText||t[53]!==n.turnId||t[54]!==G||t[55]!==B||t[56]!==H?(te={turnId:n.turnId,summaryBody:n.summaryText,activityParts:B,activityGroupSegments:H,headerMessageId:n.headerMessageId,hasTools:n.hasTools,hasReasoning:n.hasReasoning,activityPresentationKind:n.activityPresentationKind,diffStats:n.diffStats,changedFiles:n.changedFiles,userMessageCreatedAt:K,userMessageVariant:G},t[45]=K,t[46]=n.activityPresentationKind,t[47]=n.changedFiles,t[48]=n.diffStats,t[49]=n.hasReasoning,t[50]=n.hasTools,t[51]=n.headerMessageId,t[52]=n.summaryText,t[53]=n.turnId,t[54]=G,t[55]=B,t[56]=H,t[57]=te):te=t[57];let ne=te,re;t[58]!==g||t[59]!==R||t[60]!==c||t[61]!==u||t[62]!==T||t[63]!==r||t[64]!==D.lookup||t[65]!==D.ordered||t[66]!==l||t[67]!==m||t[68]!==_||t[69]!==d||t[70]!==i||t[71]!==p||t[72]!==k||t[73]!==n.activityPresentationKind||t[74]!==n.completionDisposition||t[75]!==n.durationMs||t[76]!==n.hasConfirmedFinalBody||t[77]!==n.hasReasoning||t[78]!==n.hasTools||t[79]!==n.headerMessageId||t[80]!==n.turnId||t[81]!==n.userMessage||t[82]!==ne||t[83]!==H||t[84]!==F||t[85]!==N[0]?.info.id||t[86]!==N.length?(re=(e,t)=>{let a=mj(e)===`user`,o=D.lookup.get(e.info.id),s=F.get(e.info.id)??-1,f=s>=0,h=s===0,v=s===N.length-1,y=!!R&&e.info.id===R,b=H.some(t=>t.anchorMessageId===e.info.id),x=c===`sorted`?f:y||h||v,S=N[0]?.info.id??n.headerMessageId,C=a?void 0:f?h?n.userMessage:void 0:typeof o==`number`&&o>0?D.ordered[o-1]:void 0,w=$D({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs}),E=f?{turnId:n.turnId,activityOwnerMessageId:R,isFirstAssistantInTurn:h,isLastAssistantInTurn:v,isLatestTurn:r,isWorking:(r||n.completionDisposition===`active`)&&i&&(c===`sorted`?b:e.info.id===k),isTurnSettled:eO({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,hasConfirmedSettledAssistant:n.hasConfirmedFinalBody}),hasTools:n.hasTools,hasReasoning:n.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:n.activityPresentationKind,durationMs:w.durationMs,...x?{summaryBody:ne.summaryBody,activityParts:ne.activityParts,activityGroupSegments:ne.activityGroupSegments,headerMessageId:ne.headerMessageId,diffStats:ne.diffStats,changedFiles:ne.changedFiles,userMessageCreatedAt:ne.userMessageCreatedAt,userMessageVariant:ne.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(Oj,{message:e,previousMessage:C,nextMessage:void 0,turnGroupingContext:E,assistantHeaderMessageId:S,isInActiveTurn:!!k&&e.info.id===k,activeStreamingPhase:e.info.id===k?g:null,reviewTransferDirection:_,animateUserOnMount:p(e),onUserAnimationConsumed:m,onContentChange:l,animationHandlers:u(e.info.id),scrollToBottom:d},e.info.id)},t[58]=g,t[59]=R,t[60]=c,t[61]=u,t[62]=T,t[63]=r,t[64]=D.lookup,t[65]=D.ordered,t[66]=l,t[67]=m,t[68]=_,t[69]=d,t[70]=i,t[71]=p,t[72]=k,t[73]=n.activityPresentationKind,t[74]=n.completionDisposition,t[75]=n.durationMs,t[76]=n.hasConfirmedFinalBody,t[77]=n.hasReasoning,t[78]=n.hasTools,t[79]=n.headerMessageId,t[80]=n.turnId,t[81]=n.userMessage,t[82]=ne,t[83]=H,t[84]=F,t[85]=N[0]?.info.id,t[86]=N.length,t[87]=re):re=t[87];let ie=Rk(re),ae;bb4:{if(N===n.assistantMessages){ae=n;break bb4}let e;t[88]!==n||t[89]!==N?(e={...n,assistantMessages:N},t[88]=n,t[89]=N,t[90]=e):e=t[90],ae=e}let oe=ae,se;bb5:{if(!xA({isLastTurn:r,sessionIsWorking:i,hasAssistantMessages:n.assistantMessages.length>0,activityPresentationKind:n.activityPresentationKind,hasActiveStreamingMessage:!!h})){se=null;break bb5}let e;t[91]===n.userMessage.info?e=t[92]:(e=bA(yA(n.userMessage.info)),t[91]=n.userMessage.info,t[92]=e),se=e}let ce=se,le=H.length>0,ue=n.assistantMessages.length>0,de;t[93]!==c||t[94]!==r||t[95]!==i||t[96]!==le||t[97]!==ue||t[98]!==n.activityPresentationKind||t[99]!==n.completionDisposition?(de=Dj({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:le,hasAssistantMessages:ue,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[93]=c,t[94]=r,t[95]=i,t[96]=le,t[97]=ue,t[98]=n.activityPresentationKind,t[99]=n.completionDisposition,t[100]=de):de=t[100];let fe;return t[101]!==T||t[102]!==C||t[103]!==ce||t[104]!==ie||t[105]!==oe||t[106]!==v||t[107]!==de?(fe=(0,$.jsx)(wO,{turn:oe,activityExpanded:C,onToggleActivity:T,showCompactionStatus:de,pendingAssistantHeader:ce,stickyUserHeader:v,renderMessage:ie}),t[101]=T,t[102]=C,t[103]=ce,t[104]=ie,t[105]=oe,t[106]=v,t[107]=de,t[108]=fe):fe=t[108],fe});kj.displayName=`TurnBlock`;var Aj=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}=ot();if(bt(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)(Oj,{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});Aj.displayName=`UngroupedMessageRow`;var jj=Z.memo(e=>{let t=(0,Q.c)(29),{entry:n,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}=e;if(n.kind===`ungrouped`){let e;return t[0]!==m||t[1]!==h||t[2]!==n.message||t[3]!==n.nextMessage||t[4]!==n.previousMessage||t[5]!==i||t[6]!==r||t[7]!==p||t[8]!==g||t[9]!==a||t[10]!==f?(e=(0,$.jsx)(Aj,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}),t[0]=m,t[1]=h,t[2]=n.message,t[3]=n.nextMessage,t[4]=n.previousMessage,t[5]=i,t[6]=r,t[7]=p,t[8]=g,t[9]=a,t[10]=f,t[11]=e):e=t[11],e}let _;return t[12]!==m||t[13]!==h||t[14]!==c||t[15]!==d||t[16]!==n.isLastTurn||t[17]!==n.turn||t[18]!==i||t[19]!==r||t[20]!==u||t[21]!==p||t[22]!==g||t[23]!==a||t[24]!==s||t[25]!==f||t[26]!==o||t[27]!==l?(_=(0,$.jsx)(kj,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o}),t[12]=m,t[13]=h,t[14]=c,t[15]=d,t[16]=n.isLastTurn,t[17]=n.turn,t[18]=i,t[19]=r,t[20]=u,t[21]=p,t[22]=g,t[23]=a,t[24]=s,t[25]=f,t[26]=o,t[27]=l,t[28]=_):_=t[28],_});jj.displayName=`MessageListEntry`;var Mj=Z.memo(({entries:e,engine:t,contentRef:n,scrollRef:r,registerTanstackVirtualizer:i,virtualizerKey:a,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g})=>{let _=t===`tanstack`,v=Z.useRef(t),y=Z.useRef(null),[b,x]=Z.useReducer(e=>e+1,0);if(t===`none`)y.current=null;else if(v.current===`none`&&_&&y.current===null){let e=n.current,t=r?.current;e&&t&&(y.current=Sj(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&Zi();Z.useEffect(()=>{if(!T)return;let e=r?.current;if(!e)return;let t=()=>{S.current=!0},n=()=>{S.current=!1},i=()=>{C.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`,i,{passive:!0}),()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),e.removeEventListener(`scroll`,i)}},[T,r]);let E=()=>S.current||performance.now()-C.current<JA,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*XA},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&QA(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<YA)?w.current===null&&(w.current=performance.now()):(w.current=null,k(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);$e(()=>{if(w.current===null)return;let e=performance.now()-w.current>=YA;(!E()||D()||e)&&j()},T?ZA:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=BA(),[F,I]=Z.useState(()=>Vk(P));Z.useEffect(()=>{if(!(!_||F>=P))return ls(()=>{Z.startTransition(()=>{I(e=>Hk(e,P))})})},[F,_,P]);let L=rj(a,u),[R]=Z.useState(()=>_?fj(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=nj(u),V=Z.useRef(B),H=Z.useRef(u);H.current!==u&&(H.current=u,V.current=B);let U=Z.useRef(_),W=Z.useRef(new Map),ee=Z.useRef(void 0);Z.useLayoutEffect(()=>{if(_)return;let e=n?.current;if(!e)return;let t=W.current;t.clear(),e.querySelectorAll(`[data-turn-entry]`).forEach(e=>{let n=e.dataset.turnEntry;n&&t.set(n,e.getBoundingClientRect().height)}),ee.current=void 0}),_&&ee.current===void 0&&(ee.current=R??ej(N,W.current,V.current));let G=hc({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{oj(z.current,n.getTotalSize()),mc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:qA,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:ee.current}),K=Z.useRef(null),te=Z.useRef(null);_||(K.current=null);let ne=q(()=>{if(!_)return;let e=z.current??r?.current;if(!e)return;let t=e.offsetWidth;if(!ij(K.current,t)){K.current===null&&t>0&&(K.current=t);return}K.current=t,te.current!==null&&clearTimeout(te.current),te.current=setTimeout(()=>{te.current=null,G.measure()},220)}),re=_&&typeof ResizeObserver<`u`;at(re?z:null,ne),at(re&&r?r:null,ne),et(()=>{te.current!==null&&(clearTimeout(te.current),te.current=null)}),rt(()=>{_&&ne()},[_]),rt(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=bj(n,e.messageId);if(i){let t=i.getBoundingClientRect().top-n.getBoundingClientRect().top-e.offsetTop;Math.abs(t)>.5&&(n.scrollTop+=t),y.current=null;return}let a=N.indexOf(e.entryKey);if(a<0||e.attempts>=1){y.current=null;return}e.attempts+=1,G.scrollToIndex(a,{align:`start`}),x()},[t,N,_,G,b]);let ie=G.getVirtualItems(),ae=ie.map(e=>e.index),[oe,se]=Z.useState(()=>Xk(N,{seedCount:sj(u),restore:Jk(L)})),ce=Zk(oe,N);ce!==oe&&se(ce);let le=Z.useRef(ce);le.current=ce;let ue=Z.useRef(null);G.scrollDirection&&(ue.current=G.scrollDirection);let de=G.range?.startIndex??ie[0]?.index??Math.max(0,A.length-1),fe=G.range?.endIndex??ie[ie.length-1]?.index??Math.max(0,A.length-1),pe=G.isScrolling,me=Math.max(0,fe-de+1),he=$k({entryKeys:N,mountedIndexes:ae,visibleStartIndex:de,visibleEndIndex:fe,scrollDirection:ue.current,preloadEntries:sj(u,me),hydratedKeys:ce,allowVisibleRelease:!pe,preloadReleaseLimit:pe?cj(u):FA,visibleReleaseLimit:pe?0:lj(u)}),ge=he.join(`\0`),_e=Z.useRef(he);_e.current=he,Z.useEffect(()=>{if(!(!_||!ge))return ls(()=>{Z.startTransition(()=>{se(e=>{let t=null;for(let n of _e.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,ge]),Z.useEffect(()=>{se(e=>eA(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=G.itemSizeCache,t=uj(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(KA,Math.max(GA,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(G),()=>{pj(L,M.current.map(e=>e.key),G),Yk(L,le.current),i?.(null)}},[_,G,L]);let ve=Rk((e,t=!0)=>(0,$.jsx)(Wk,{enabled:t,children:(0,$.jsx)(jj,{entry:e,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,sessionIsWorking:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g},e.key)}));if(t===`none`)return(0,$.jsx)(`div`,{ref:n,className:`relative w-full`,children:A.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:ve(e)},e.key))});if(t===`tanstack`){let e=aj(ie[0]?.start??0,ie[ie.length-1]?.end??0,G.getTotalSize());return(0,$.jsx)(`div`,{ref:z,className:`relative w-full`,style:{minHeight:e.minHeight},children:(0,$.jsx)(`div`,{style:{paddingTop:e.paddingTop,paddingBottom:e.paddingBottom},children:ie.map(e=>{let t=A[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:G.measureElement,"data-turn-entry":t.key,className:`oc-chat-message-layout-boundary`,children:ve(t,ce.has(t.key))},t.key):null})})})}return null});Mj.displayName=`StaticHistoryList`;var Nj=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(`div`,{className:`oc-chat-message-layout-boundary`,children:(0,$.jsx)(jj,{...e})}),t[0]=e,t[1]=n),n});Nj.displayName=`TailEntry`;var Pj=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=gr(_??``,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=Lk(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)(Nj,{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};Pj.displayName=`StreamingTailContent`;var Fj=e=>{let t=(0,Q.c)(64),{historyEntries:n,tailEntries:r,timelineCacheKey:i,directory:a,sessionId:o,scrollRef:s,registerList:c,onHistoryContentChange:l,onTailContentChange:u,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,showTurnChangedFiles:y,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w,header:T,footer:E,scrollClassName:D,scrollStyle:O,scrollDataset:k,onScroll:A,followEnabled:j,onIsAtEndChange:M}=e,N=j===void 0||j,P=n.length,F=r.length>0?r[r.length-1]:void 0,I=F?.key??null,L=gr(S??``,a,o??void 0),R;bb0:{if(!F){R=r;break bb0}let e=v===`sorted`,n;t[0]!==S||t[1]!==L||t[2]!==F||t[3]!==y||t[4]!==e?(n=Lk(F,{activeStreamingMessageId:S,liveParts:L,showTextJustificationActivity:e,showTurnChangedFiles:y}),t[0]=S,t[1]=L,t[2]=F,t[3]=y,t[4]=e,t[5]=n):n=t[5];let i=n;if(i===F){R=r;break bb0}let a;t[6]!==i||t[7]!==r?(a=r.slice(),a[a.length-1]=i,t[6]=i,t[7]=r,t[8]=a):a=t[8],R=a}let z=R,B;t[9]!==n||t[10]!==z?(B=z.length>0?[...n,...z]:n,t[9]=n,t[10]=z,t[11]=B):B=t[11];let V=B,H;t[12]===h?H=t[13]:(H={resolvePreloadEntries:e=>sj(h,e),resolvePreloadReleaseWhileScrolling:()=>cj(h),resolveVisibleReleaseLimit:()=>lj(h)},t[12]=h,t[13]=H);let U=H,W;t[14]!==S||t[15]!==C||t[16]!==h||t[17]!==v||t[18]!==P||t[19]!==I||t[20]!==w||t[21]!==m||t[22]!==y||t[23]!==p||t[24]!==g?(W={historyCount:P,newestTailKey:I,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,chatRenderMode:v,showTurnChangedFiles:y,stickyUserHeader:p,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w},t[14]=S,t[15]=C,t[16]=h,t[17]=v,t[18]=P,t[19]=I,t[20]=w,t[21]=m,t[22]=y,t[23]=p,t[24]=g,t[25]=W):W=t[25];let ee=W,G;t[26]!==S||t[27]!==C||t[28]!==h||t[29]!==v||t[30]!==d||t[31]!==P||t[32]!==I||t[33]!==l||t[34]!==u||t[35]!==_||t[36]!==x||t[37]!==w||t[38]!==f||t[39]!==m||t[40]!==b||t[41]!==p||t[42]!==g?(G=(e,t,n)=>{let r=t>=P,i=I!==null&&e.key===I;return(0,$.jsx)(ms,{disabled:!r,children:(0,$.jsx)(Wk,{enabled:n,children:(0,$.jsx)(jj,{entry:e,onMessageContentChange:r?u:l,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:i?m:!1,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:i?S:null,activeStreamingPhase:i?C:null,reviewTransferDirection:w})})})},t[26]=S,t[27]=C,t[28]=h,t[29]=v,t[30]=d,t[31]=P,t[32]=I,t[33]=l,t[34]=u,t[35]=_,t[36]=x,t[37]=w,t[38]=f,t[39]=m,t[40]=b,t[41]=p,t[42]=g,t[43]=G):G=t[43];let K=Rk(G),te;t[44]===h?te=t[45]:(te=nj(h),t[44]=h,t[45]=te);let ne;return t[46]!==V||t[47]!==N||t[48]!==E||t[49]!==T||t[50]!==U||t[51]!==M||t[52]!==A||t[53]!==c||t[54]!==K||t[55]!==ee||t[56]!==D||t[57]!==k||t[58]!==s||t[59]!==O||t[60]!==m||t[61]!==te||t[62]!==i?(ne=(0,$.jsx)(Uk,{enabled:!0,children:(0,$.jsx)(sA,{entries:V,timelineCacheKey:i,estimatedItemSize:te,hydrationTuning:U,renderEntry:K,rowInvalidationKey:ee,scrollElementRef:s,registerList:c,followEnabled:N,sessionIsWorking:m,header:T,footer:E,className:D,style:O,scrollElementDataset:k,onScroll:A,onIsAtEndChange:M})}),t[46]=V,t[47]=N,t[48]=E,t[49]=T,t[50]=U,t[51]=M,t[52]=A,t[53]=c,t[54]=K,t[55]=ee,t[56]=D,t[57]=k,t[58]=s,t[59]=O,t[60]=m,t[61]=te,t[62]=i,t[63]=ne):ne=t[63],ne};Fj.displayName=`LegendTimelineHost`;var Ij=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:c,getAnimationHandlers:l,scrollToBottom:u,scrollRef:d,directory:f,headerSlot:p,footerSlot:m,timelineScrollClassName:h,timelineScrollStyle:g,timelineScrollDataset:_,timelineOnScroll:v,timelineFollowEnabled:y,timelineOnIsAtEndChange:b},x)=>{Ie(`ui.message_list.render`);let{sessionKey:S,virtualizerKey:C}=tj(e,t),w=s(e=>e.stickyUserHeader),T=s(e=>e.chatRenderMode),E=s(e=>e.activityRenderMode),D=s(e=>e.showTurnChangedFiles),O=fr(e=>e.reviewTransferBySessionId.get(S)??null),[k,A]=Z.useState(()=>new Map),j=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),M=q(l),N=q(()=>{u?.()}),P=q((e,t)=>{A(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:QD(i)}),r})}),F=Z.useMemo(()=>Ce(`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(PO(typeof o==`string`?t.get(o)??a:a))}let i=[],a=new Set;for(let e=0;e<r.length;e+=1){let t=r[e],n=hj(t,a);AO(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(gj(o)){let e=wj(n);if(e.hide){i[i.length-1]=Tj(o,e.taskSessionId);continue}}if(uA(o)){let e=dA(n,_j(o));if(e.hide){i[i.length-1]=Ej(o,e.details);continue}}i.push(n)}return i}),[n]),I=Z.useRef(null),L=Z.useRef(null),R=Z.useCallback(()=>{let e=L.current;e&&(L.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{R()},[R]);let z=q(()=>d?.current?d.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),B=Z.useMemo(()=>Ce(`ui.message_list.retry_overlay_ms`,()=>Fk(F,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[F,o]),V=r||!!i,H=Z.useRef(V),U=Z.useRef(S);U.current!==S&&(U.current=S,H.current=!1),V&&(H.current=!0);let{projection:W,staticTurns:ee,streamingTurns:G}=Nk(B,{sessionKey:S,showTextJustificationActivity:T===`sorted`,showTurnChangedFiles:D,hasLiveTail:V||H.current,liveTailActive:V}),K=W.ungroupedMessageIds.size>0,te=K?B:wA,ne=K?W.ungroupedMessageIds:TA,re=Z.useMemo(()=>Ce(`ui.message_list.render_entries_ms`,()=>{let e=ee.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===W.lastTurnId}));if(ne.size===0)return e;let t=new Map;e.forEach(e=>{t.set(e.turn.userMessage.info.id,e)});let n=[];return te.forEach((e,r)=>{let i=t.get(e.info.id);if(i){n.push(i);return}ne.has(e.info.id)&&n.push({kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:r>0?te[r-1]:void 0,nextMessage:r<te.length-1?te[r+1]:void 0})}),n}),[W.lastTurnId,te,ne,ee]),ie=Z.useMemo(()=>{if(G.length>0)return G.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===W.lastTurnId}));if(W.ungroupedMessageIds.size===0)return EA;let e=B[B.length-1];return!e||!W.ungroupedMessageIds.has(e.info.id)?EA:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:B.length>1?B[B.length-2]:void 0,nextMessage:void 0}]},[B,W.lastTurnId,W.ungroupedMessageIds,G]),ae=ie.length>0;ae&&V&&Ie(`ui.message_list.render.streaming`);let oe=re,se=oe.length>=CA,ce=Z.useRef(se);dj(ce,se);let le=se?`tanstack`:`none`,ue=Zb(e=>e.legendTimelineEnabled),de=Z.useRef(null),fe=q(e=>{de.current=e}),pe=Z.useRef(null),me=q(e=>{pe.current=e}),he=Z.useMemo(()=>ie.length>0?[...oe,...ie]:oe,[oe,ie]),ge=q(e=>{c(e)}),_e=q(e=>{c(e)}),ve=Z.useMemo(()=>n.filter(e=>mj(e)===`user`).map(e=>e.info.id),[n]);{let t=j.current;t.sessionKey!==e&&(t.sessionKey=e,t.previousOrder=ve,t.animatedIds=new Set);let n=t.previousOrder;if(ve.length>n.length&&n.every((e,t)=>ve[t]===e)&&Xt(e))for(let r=n.length;r<ve.length;r+=1){let n=ve[r];if(n&&!t.animatedIds.has(n)){if(!Lt(e))break;t.animatedIds.add(n)}}t.previousOrder=ve}let ye=q(e=>mj(e)===`user`&&j.current.animatedIds.has(e.info.id)),be=q(e=>{j.current.animatedIds.delete(e)}),xe=Z.useMemo(()=>{let e=new Map;return he.forEach((t,n)=>{if(t.kind===`ungrouped`){e.set(t.message.info.id,n);return}e.set(t.turn.userMessage.info.id,n),t.turn.assistantMessages.forEach(t=>{e.set(t.info.id,n)})}),e},[he]),Se=Z.useMemo(()=>{let e=new Map;return he.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[he]),we=q(e=>{let t=z();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Te=q((e,t=`auto`)=>{if(e<0||e>=oe.length)return!1;if(ue){let n=de.current;return n?(n.scrollToIndex({index:e,animated:t===`smooth`,viewOffset:0}),!0):!1}if(!se)return!1;let n=pe.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),Ee=q((e,t=`auto`)=>{let n=z();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(!x)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Se.get(e);if(r===void 0)return!1;let i=z();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):ae&&r>=oe.length?!1:Te(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=xe.get(e);return r===void 0?!1:Ee(e,n)||(ae&&r>=oe.length?!1:Te(r,n))},holdViewportAnchor:e=>{let t=z();if(!t||typeof window>`u`)return;R();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(),L.current?.cancel===s&&(L.current=null))},c=()=>{s()};L.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>=VA||n>=HA){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:R,isHistoryVirtualized:()=>ue?!0:ce.current,captureViewportAnchor:()=>{let e=z();if(!e)return null;let t=e.getBoundingClientRect(),n=Array.from(e.querySelectorAll(`[data-message-id]`)),r=n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!yj(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=z();if(!t||!xe.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;return i!==0&&(t.scrollTop+=i),!0};if(!n()){let t=xe.get(e.messageId);if(typeof t==`number`&&t<oe.length)return Te(t,`auto`)}return n()},scrollToBottom:()=>{if(ue){de.current?.scrollToEnd({animated:!1});return}if(se&&oe.length>0&&pe.current){pe.current.scrollToEnd();return}let e=z();e&&(e.scrollTop=e.scrollHeight)}};if(typeof x==`function`)return x(e),()=>{x(null)};let t=x;return t.current=e,()=>{t.current=null}},[R,oe.length,ue,xe,se,ae,Se,x]),ue?(0,$.jsx)(Fj,{historyEntries:oe,tailEntries:ie,timelineCacheKey:rj(C,E),directory:f,sessionId:S,scrollRef:d,registerList:fe,onHistoryContentChange:ge,onTailContentChange:_e,getAnimationHandlers:M,scrollToBottom:N,stickyUserHeader:w,sessionIsWorking:r,activityRenderMode:E,turnUiStates:k,onToggleTurnGroup:P,chatRenderMode:T,showTurnChangedFiles:D,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:O,header:p,footer:m,scrollClassName:h,scrollStyle:g,scrollDataset:_,onScroll:v,followEnabled:y,onIsAtEndChange:b},C):(0,$.jsx)(`div`,{children:(0,$.jsx)(ms,{disabled:!1,children:(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(ms,{disabled:se,children:(0,$.jsx)(Uk,{enabled:!0,children:(0,$.jsx)(Mj,{entries:oe,engine:le,contentRef:I,scrollRef:d,registerTanstackVirtualizer:me,virtualizerKey:C,onMessageContentChange:ge,getAnimationHandlers:M,scrollToBottom:N,stickyUserHeader:w,activityRenderMode:E,turnUiStates:k,onToggleTurnGroup:P,chatRenderMode:T,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,reviewTransferDirection:O},C)})}),(0,$.jsx)(Pj,{entries:ie,directory:f,sessionId:S,onMessageContentChange:_e,getAnimationHandlers:M,scrollToBottom:N,stickyUserHeader:w,sessionIsWorking:r,activityRenderMode:E,turnUiStates:k,onToggleTurnGroup:P,chatRenderMode:T,showTurnChangedFiles:D,shouldAnimateUserMessage:ye,onUserAnimationConsumed:be,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:O})]})})})});Ij.displayName=`MessageList`;var Lj=Z.memo(Ij);function Rj(e){return e.info.id}function zj(e){return e!==null}var Bj=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},Vj=({diff:e,filePath:t})=>{let{currentTheme:n}=za(),r=Z.useMemo(()=>Co(n),[n]),i=Z.useMemo(()=>Zs(e),[e]),a=ns(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
6582
6582
  `),[i]),s=sc(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)(Bj,{content:e.content,html:n})})]},t)})})]},n))})},Hj=e=>{let t=(0,Q.c)(21),{content:n,filePath:r}=e,{currentTheme:i}=za(),a;t[0]===i?a=t[1]:(a=Co(i),t[0]=i,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=n.split(`
6583
- `),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=ns(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=sc(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)(Bj,{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},Uj=new Set([`id`,`identifier`,`title`,`name`]),Wj=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Gj=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),Kj=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},qj=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},Jj=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?`${Gj(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)(Jj,{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(Wj(n)){let e;t[18]===n?e=t[19]:(e=Kj(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(Xj),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${Gj(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)(Jj,{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?Gj(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`&&qj(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:Gj(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});Jj.displayName=`JsonSummaryValue`;var Yj=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)(Jj,{value:n,depth:0})}),t[0]=n,t[1]=r),r});Yj.displayName=`JsonSummaryView`;function Xj(e){let[t]=e;return!Uj.has(t)}var Zj={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`},Qj={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},$j=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})},eM=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},tM=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,nM=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)(Yj,{data:n})}),t[0]=n,t[1]=r),r},rM=({permission:e,onResponse:t})=>{let{t:n}=st(),[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=nn,c=bi(),l=J(e=>e.currentSessionId),u=Z.useMemo(()=>{if(!l||e.sessionID===l)return!1;let t=c.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===l)},[e.sessionID,l,c]),d=async n=>{i(!0);try{await s(e.sessionID,e.id,n),o(!0),t?.(n)}catch(e){console.error(`[PermissionCard] Failed to respond to permission:`,e)}finally{i(!1)}};if(a)return null;let f=e.permission||`unknown`,p=f.toLowerCase(),m=(t,n=``)=>{let r=e.metadata[t];return typeof r==`string`?r:typeof r==`number`?String(r):n},h=t=>{let n=e.metadata[t];return typeof n==`number`?n:void 0},g=t=>!!e.metadata[t],_=eM(f),v=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[tM(e),t]));return(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{className:`-mt-1 overflow-hidden border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2.5 py-2 sm:px-2 sm:py-1.5 border-b border-border/20 bg-muted/5`,children:(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`)}),u?(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:[$j(f),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] text-muted-foreground font-medium`,children:_})]})]})}),(0,$.jsxs)(`div`,{className:`px-2.5 py-2 sm:px-2 [&_.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(p===`bash`||p===`shell`||p===`shell_command`){let e=m(`command`)||m(`cmd`)||m(`script`),t=m(`description`),r=m(`cwd`)||m(`working_directory`)||m(`directory`)||m(`path`),i=h(`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)(Qs,{language:`bash`,code:e,style:Zj,codeStyle:Qj.style,wrap:!0})})]})}if(p===`edit`||p===`multiedit`||p===`str_replace`||p===`str_replace_based_edit_tool`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`changes`)||m(`diff`),r=g(`replace_all`)||g(`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)(fa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(Vj,{diff:t,filePath:e})})]})}if(p===`write`||p===`create`||p===`file_write`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`content`)||m(`text`)||m(`data`);return t?(0,$.jsx)(fa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(Hj,{content:t,filePath:e})}):null}if(p===`webfetch`||p===`fetch`||p===`curl`||p===`wget`){let t=m(`url`)||m(`uri`)||m(`endpoint`),r=m(`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=h(`timeout`),s=m(`format`)||m(`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)(fa,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(nM,{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)(fa,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(nM,{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(v).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)(fa,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(nM,{data:v})})]})})()]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-1 border-t border-border/20 px-1.5 py-1.5 sm:flex sm:items-center sm:flex-wrap sm:px-2 sm:py-1`,children:[(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`once`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,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)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`always`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,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)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`reject`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-[var(--status-error)] sm:h-6 sm:w-auto sm:px-2`,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`)})]}),r&&(0,$.jsx)(`div`,{className:`col-span-3 flex justify-center w-full sm:w-auto sm:ml-auto py-1 sm:py-0 typography-meta text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})})]})]})})})};function iM(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(`
6584
- `).trimEnd()}function aM(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)}function oM({scrollHeight:e,currentHeight:t}){let n=Math.min(Math.max(e,40),200);return t===n?null:n}var sM=`summary`,cM=Z.memo(function(e){let t=(0,Q.c)(31),{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(`--oc-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=K(m),g;t[1]===h?g=t[2]:(g=()=>{requestAnimationFrame(h)},t[1]=h,t[2]=g);let _=K(g),v;t[3]===h?v=t[4]:(v=()=>{let e=()=>requestAnimationFrame(h);return e(),window.addEventListener(`oc:keyboard-settled`,e),window.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`oc: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]!==u||t[10]!==f?(S=()=>{let e=s.current;if(!e)return;let t=oM({scrollHeight:e.scrollHeight,currentHeight:u}),n=e.scrollHeight>(t??u);f!==n&&p(n),t!==null&&d(t)},t[9]=u,t[10]=f,t[11]=S):S=t[11];let C;t[12]!==u||t[13]!==f||t[14]!==c?(C=[u,f,c],t[12]=u,t[13]=f,t[14]=c,t[15]=C):C=t[15],Z.useLayoutEffect(S,C);let w;t[16]===a?w=t[17]:(w=e=>{let t=e.target.value;l(t),a(t)},t[16]=a,t[17]=w);let T;t[18]===u?T=t[19]:(T={height:u},t[18]=u,t[19]=T);let E=f?`overflow-y-auto`:`overflow-hidden`,D;t[20]===E?D=t[21]:(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[20]=E,t[21]=D);let O;return t[22]!==i||t[23]!==_||t[24]!==c||t[25]!==o||t[26]!==r||t[27]!==T||t[28]!==D||t[29]!==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[22]=i,t[23]=_,t[24]=c,t[25]=o,t[26]=r,t[27]=T,t[28]=D,t[29]=w,t[30]=O):O=t[30],O}),lM=({question:e})=>{let{t}=st(),n=ar,r=cn,i=s(e=>e.isMobile),a=bi(),o=J(e=>e.currentSessionId),c=Z.useMemo(()=>{if(!o||e.sessionID===o)return!1;let t=a.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===o)},[e.sessionID,o,a]),[l,u]=Z.useState(`0`),[d,f]=Z.useState(!1),[p,m]=Z.useState(!1),[h,g]=Z.useState({}),[_,v]=Z.useState({}),y=Z.useRef({}),[b,x]=Z.useState({}),S=Z.useMemo(()=>e.questions??[],[e.questions]),C=l===sM,w=C?-1:Math.max(0,Math.min(S.length-1,Number(l)||0)),T=C?null:S[w],E=Z.useMemo(()=>{if(C)return null;let e=T?.header?.trim();return e&&e.length>0?e:null},[T?.header,C]);Z.useEffect(()=>{u(`0`),g({}),v({}),y.current={},x({}),m(!1)},[e.id]);let D=Z.useMemo(()=>{let e=S.map((e,t)=>({value:String(t),label:e.header?.trim()||`Q${t+1}`}));return S.length>1&&e.push({value:sM,label:t(`chat.questionCard.summaryTab`)}),e},[S,t]),O=Z.useCallback(e=>{if(_[e])return(y.current[e]??``).trim()||t(`chat.questionCard.noAnswer`);let n=h[e]??[];return n.length>0?n.join(`, `):t(`chat.questionCard.noAnswer`)},[_,h,t]),k=!!T?.multiple,A=h[w]??[],j=!!_[w],M=Z.useMemo(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){b[t]||e.push(t);continue}(h[t]??[]).length===0&&e.push(t)}return e},[_,b,S.length,h]),N=Z.useMemo(()=>S.length!==0&&M.length===0,[S.length,M.length]),P=Z.useCallback(()=>{if(S.length===0||M.length===0)return;let e=C?-1:w;for(let t=1;t<=S.length;t+=1){let n=(e+t+S.length)%S.length;if(M.includes(n)){u(String(n));return}}u(String(M[0]))},[w,C,S.length,M]),F=Z.useCallback(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){let n=(y.current[t]??``).trim();e.push(n?[n]:[]);continue}e.push(h[t]??[])}return e},[_,S.length,h]),I=Z.useCallback(e=>{T&&(v(e=>({...e,[w]:!1})),x(e=>e[w]?{...e,[w]:!1}:e),g(t=>{let n=t[w]??[];if(k){let r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,[w]:r}}return{...t,[w]:[e]}}))},[w,T,k]),L=Z.useCallback(()=>{v(e=>({...e,[w]:!0})),g(e=>({...e,[w]:[]}));let e=(y.current[w]??``).trim().length>0;x(t=>t[w]===e?t:{...t,[w]:e})},[w]),R=Z.useCallback(e=>{y.current[w]=e;let t=e.trim().length>0;x(e=>e[w]===t?e:{...e,[w]:t})},[w]),z=Z.useCallback(async()=>{if(N){f(!0);try{let t=F();await n(e.sessionID,e.id,t),m(!0)}catch(e){Ut(e)?(wr.info(t(`chat.questionCard.noLongerPending`)),m(!0)):wr.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}}},[F,e.id,e.sessionID,N,n,t]),B=Z.useCallback(e=>{Kh(e)||e.key===`Enter`&&!e.shiftKey&&(!i||e.ctrlKey||e.metaKey)&&(e.preventDefault(),N?z():P())},[z,P,i,N]),V=Z.useCallback(async()=>{f(!0);try{await r(e.sessionID,e.id),m(!0)}catch(e){Ut(e)?(wr.info(t(`chat.questionCard.noLongerPending`)),m(!0)):wr.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}},[e.id,e.sessionID,r,t]),H=Z.useCallback(async()=>{let n=iM(e);if((await lt(n)).ok){wr.success(t(`chat.questionCard.copiedMarkdown`));return}wr.error(t(`chat.questionCard.copyFailed`))},[e,t]),U=Z.useCallback(async()=>{let n=aM(e);if((await lt(n)).ok){wr.success(t(`chat.questionCard.copiedJson`));return}wr.error(t(`chat.questionCard.copyFailed`))},[e,t]);return p||S.length===0?null:(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{"data-question-card":!0,className:`-mt-1 border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1.5 border-b border-border/20`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`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,E?(0,$.jsx)(`span`,{className:`ml-auto typography-micro font-medium text-foreground/70 px-1.5 py-0.5 rounded bg-muted/30 border border-border/20`,children:E}):null,(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-0.5`,E?null:`ml-auto`),children:[(0,$.jsx)(`button`,{type:`button`,onClick:H,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:U,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`})})]})]})}),(0,$.jsxs)(`div`,{className:`px-2 py-2`,children:[D.length>1?(0,$.jsx)(`div`,{className:`flex items-center gap-1 mb-2 flex-wrap`,children:D.map(e=>{let t=l===e.value,n=e.value===sM,r=n?-1:Number(e.value),i=!n&&Number.isFinite(r)&&!M.includes(r);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(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,C?(0,$.jsx)(`div`,{className:`space-y-2`,children:S.map((e,n)=>{let r=O(n),i=r!==t(`chat.questionCard.noAnswer`);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(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)})}):T?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground mb-1.5`,children:T.question}),k?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1.5`,children:t(`chat.questionCard.selectMultiple`)}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[T.options.map((e,n)=>{let r=A.includes(e.label),i=/\(recommended\)/i.test(e.label);return(0,$.jsx)(`button`,{type:`button`,onClick:()=>I(e.label),disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,r?`bg-interactive-selection/20`:null,d?`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`,children:k?(0,$.jsx)(ha,{checked:r,onChange:()=>I(e.label),disabled:d}):(0,$.jsx)(uo,{checked:r,onChange:()=>I(e.label),disabled:d})}),(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:L,disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,j?`bg-interactive-selection/20`:null,d?`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`,j?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,j?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),j?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)(cM,{value:y.current[w]??``,onValueChange:R,placeholder:t(`chat.questionCard.yourAnswer`),disabled:d,onKeyDown:B})}):null]})]}):null]}),(0,$.jsxs)(`div`,{className:`px-2 pb-1.5 pt-1 flex items-center gap-1.5 border-t border-border/20`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:N?z:P,disabled:d,className:Y(`flex 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:[N?(0,$.jsx)(X,{name:`check`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`}),t(N?`chat.questionCard.submit`:`chat.questionCard.next`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:V,disabled:d,className:Y(`flex 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`)]}),d?(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]})]})})})},uM={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,retryInfo:null,turnStartedAt:void 0},dM=[],fM=`\0`,pM=new Set([`edit`,`write`,`multiedit`,`apply_patch`]),mM={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,multiedit:`chat.assistantStatus.editingFiles`,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`,plan_enter:`chat.assistantStatus.switchingToPlanning`,plan_exit:`chat.assistantStatus.switchingToBuilding`},hM=[`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`],gM=(e,t)=>{let n=mM[e];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},_M=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)},vM=(e,t)=>t(hM[_M(e)%hM.length]??`chat.assistantStatus.working`),yM=(e,t,n)=>{let r,i;if(!Ht(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??TM(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=EM(n);pM.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=wM(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=TM(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?i===`multiedit`?gM(i,n):n(`chat.assistantStatus.editingFile`):r===`tool`&&i?gM(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):vM(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},bM=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(fM),xM=e=>{let[t,n,r=`working`,i]=e.split(fM);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},SM=e=>e.type===`reasoning`,CM=e=>e.type===`text`,wM=e=>{if(CM(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},TM=e=>(CM(e)||SM(e),e.time),EM=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function DM(e,t){let{t:n}=st(),r=J(e=>e.currentSessionId),i=J(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),c=J(s),l=Di(a??``,o??void 0),u=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--)if(l[e].role===`assistant`)return l[e].id;return null},[l]),d=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--){let t=l[e];if(t.role===`user`)return{id:t.id,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,turnStartedAt:void 0}},[l]),f=d.id,p=_r(u??``,o??void 0,a??void 0),m=_r(f??``,o??void 0,a??void 0),h=!!f&&OO(m),g=Z.useMemo(()=>{let e=`${a??``}:${u??``}`;return bM(yM(u?p:dM,e,n))},[a,u,p,n]),_=gi(a??``,o??void 0),v=ji(a??``,o??void 0),y=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),b=J(y),{phase:x,isWorking:S}=Gh(a,o??void 0),C=Er(a??``,o??void 0),w=C?.type===`retry`?C.attempt:void 0,T=C?.type===`retry`?C.next:void 0,E=Z.useMemo(()=>xM(g),[g]),D=Z.useMemo(()=>{let e=!!(b&&!b.acknowledged);return{wasAborted:e,abortActive:e}},[b]),O=Z.useMemo(()=>{if(D.wasAborted)return{...uM,wasAborted:!0,abortActive:D.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};let e=S,t=x===`busy`,r=x===`retry`,i=e&&h,a=`idle`;e&&(a=!i&&(E.activePartType===`tool`||E.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:w,next:T}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(E.activePartType===`tool`||E.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):E.statusText:null,isGenericStatus:!e||!i&&E.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?E.activePartType:void 0,activeToolName:e&&!i?E.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,retryInfo:o,turnStartedAt:d.turnStartedAt}},[x,S,h,d.turnStartedAt,E,D,w,T,n]);return{forming:Z.useMemo(()=>({isActive:S&&E.activePartType===`text`,characterCount:0}),[S,E.activePartType]),working:Z.useMemo(()=>{if(O.wasAborted||O.abortActive)return O;if(c)return{...O,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null};let e=_.length>0,t=v.length>0;return!e&&!t?O:t?{...O,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...O,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[O,c,_,v,n])}}var OM=Z.memo(()=>{let e=(0,Q.c)(13),t=Qm(),n=J(kM),r=J(AM),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=J(o),c=J(jM),l=J(MM),{working:u}=DM(i,a),d=mi(NM),f=!!(s&&!s.acknowledged),p=!!(i&&c===i&&typeof l==`number`&&l>Date.now()),m=f||u.wasAborted,h=f||u.abortActive,g;return e[2]!==d||e[3]!==p||e[4]!==m||e[5]!==h||e[6]!==u.isGenericStatus||e[7]!==u.isWaitingForPermission||e[8]!==u.isWorking||e[9]!==u.retryInfo||e[10]!==u.statusText||e[11]!==u.turnStartedAt?(g=(0,$.jsx)(rh,{isWorking:u.isWorking,statusText:u.statusText,isGenericStatus:u.isGenericStatus,isWaitingForPermission:u.isWaitingForPermission,wasAborted:m,abortActive:h,retryInfo:u.retryInfo,turnStartedAt:u.turnStartedAt,showAbortPrompt:p,showAssistantStatus:!0,showTodos:!1,agentName:d}),e[2]=d,e[3]=p,e[4]=m,e[5]=h,e[6]=u.isGenericStatus,e[7]=u.isWaitingForPermission,e[8]=u.isWorking,e[9]=u.retryInfo,e[10]=u.statusText,e[11]=u.turnStartedAt,e[12]=g):g=e[12],g});OM.displayName=`StatusRowContainer`;function kM(e){return e.currentSessionId}function AM(e){return e.currentSessionDirectory}function jM(e){return e.abortPromptSessionId}function MM(e){return e.abortPromptExpiresAt}function NM(e){return e.currentAgentName}var PM=e=>!!e&&typeof e==`object`&&!Array.isArray(e);function FM(e){let t=e?.metadata;if(!PM(t))return null;let n=t.openchamber;if(!PM(n))return null;let r=n.assist;if(!PM(r))return null;let i=typeof r.recap==`string`?r.recap.trim():``,a=typeof r.forMessageID==`string`?r.forMessageID:``;return!a||!i?null:{recap:i,forMessageID:a,generatedAt:typeof r.generatedAt==`number`?r.generatedAt:0}}var IM=6e4;function LM(e,t){let n=oi(),r=t||n,i=Gn(r);return dr(e,r,i)}function RM(e,t){let n=(0,Q.c)(14),r=ur(e,t),i=Er(e,t),a=LM(e,t),o=s(BM),c=!i||i.type===`idle`,l;n[0]===r?l=n[1]:(l=FM(r),n[0]=r,n[1]=l);let u=l,d=u&&a&&a.role===`assistant`&&a.id===u.forMessageID&&c?u:null,f=a?.timestamp??0,[,p]=Z.useReducer(zM,0),m=d?Date.now()-f>=IM:!1,h;n[2]!==d||n[3]!==p||n[4]!==f||n[5]!==m?(h=()=>{if(!d||m||!f)return;let e=IM-(Date.now()-f);if(e<=0)return;let t=setTimeout(p,e+250);return()=>clearTimeout(t)},n[2]=d,n[3]=p,n[4]=f,n[5]=m,n[6]=h):h=n[6];let g;n[7]!==d||n[8]!==f||n[9]!==m?(g=[d,m,f],n[7]=d,n[8]=f,n[9]=m,n[10]=g):g=n[10],Z.useEffect(h,g);let _=o&&d&&d.recap&&m?d.recap:null,v;return n[11]!==d||n[12]!==_?(v={assist:d,visibleRecap:_},n[11]=d,n[12]=_,n[13]=v):v=n[13],v}function zM(e){return e+1}function BM(e){return e.sessionRecapEnabled}var VM=Z.memo(e=>{let t=(0,Q.c)(13),{sessionId:n,directory:r,isMobile:i}=e,{visibleRecap:a}=RM(n,r),{t:o}=st();if(!a)return null;let s;t[0]===o?s=t[1]:(s=o(`chat.recap.aria`),t[0]=o,t[1]=s);let c=`typography-markdown-body text-muted-foreground/70 ${i?`line-clamp-4`:`line-clamp-2`}`,l;t[2]===o?l=t[3]:(l=o(`chat.recap.label`),t[2]=o,t[3]=l);let u;t[4]===l?u=t[5]:(u=(0,$.jsxs)(`span`,{className:`italic text-muted-foreground/50`,children:[l,` `]}),t[4]=l,t[5]=u);let d;t[6]!==c||t[7]!==u||t[8]!==a?(d=(0,$.jsxs)(`span`,{className:c,children:[u,a]}),t[6]=c,t[7]=u,t[8]=a,t[9]=d):d=t[9];let f;return t[10]!==s||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`chat-message-column`,children:(0,$.jsx)(`div`,{className:`-mt-6`,"aria-label":s,children:d})}),t[10]=s,t[11]=d,t[12]=f):f=t[12],f});VM.displayName=`SessionRecapNote`;function HM(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
6585
- `)}function UM(e,t=80){let n=HM(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var WM=160,GM=28,KM=12,qM=6,JM=30,YM=12,XM=18,ZM=80,QM=4,$M=10,eN=14,tN=20,nN=54,rN=4,iN=8,aN=2,oN=160,sN=(e,t)=>e.map(e=>({turnId:e,preview:UM(t.get(e)??[],WM)})),cN=[1,.6,.35,.15],lN=(e,t,n)=>{let r=n?eN:$M;if(t===null)return r;let i=cN[Math.abs(e-t)]??0;return Math.round(r+(tN-r)*i)};function uN({turnIds:e,previewsByTurnId:t,activeTurnId:n,onSelectTurn:r,canLoadEarlier:i,isLoadingOlder:a,onLoadEarlier:o}){let{t:c}=st(),l=s(e=>e.isPromptNavigatorPanelOpen),u=s(e=>e.setPromptNavigatorPanelOpen),d=Z.useRef(null),f=Z.useRef(null),[p,m]=Z.useState(null),[h,g]=Z.useState(0),[_,v]=Z.useState(!1);Z.useEffect(()=>{let e=f.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){v(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.right-qM-GM;v(r.right>i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let y=Z.useMemo(()=>sN(e,t),[t,e]),b=Math.min(y.length,JM),x=Math.max(0,y.length-b),S=Math.min(h,x),C=S+b,w=S>0,T=C<y.length,E=c(`chat.timeline.noTextContent`),D=c(`chat.promptNavigator.currentPrompt`),O=c(`chat.promptNavigator.loadMore`),k=Z.useMemo(()=>n?y.findIndex(e=>e.turnId===n):-1,[n,y]),A=Z.useRef(S);A.current=S;let j=Z.useRef(y.length);j.current=y.length;let M=Z.useRef(null),N=Z.useRef(null),P=Z.useRef(0),F=Z.useCallback(e=>{g(t=>{let n=j.current,r=Math.min(n,JM),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})},[]),I=Z.useRef(y[0]?.turnId),L=Z.useRef(y.length);Z.useLayoutEffect(()=>{let e=I.current,t=L.current,n=y.length-t;n>0&&t>0&&e&&y[0]?.turnId!==e&&(g(e=>e+n),m(e=>e===null?null:e+n)),I.current=y[0]?.turnId,L.current=y.length},[y]),Z.useEffect(()=>{if(p!==null)return;let e=k>=0?k:y.length-1;g(()=>{let t=j.current,n=Math.min(t,JM),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[k,p,y.length]);let R=Z.useCallback(e=>{let t=d.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/YM),i=Math.min(j.current,JM);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),z=Z.useCallback(()=>{P.current=0,N.current!==null&&(window.clearInterval(N.current),N.current=null)},[]),B=Z.useCallback(()=>{let e=P.current;if(e===0){z();return}let t=j.current,n=Math.max(0,t-Math.min(t,JM)),r=Math.min(A.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){z();return}A.current=i,g(i);let a=M.current;if(a!==null){let e=R(a);e!==null&&m(Math.min(t-1,i+e))}},[R,z]),V=Z.useCallback(e=>{let t=d.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=XM&&w?i=-1:r>=n.height-XM&&T&&(i=1),P.current=i,i===0){z();return}N.current===null&&(N.current=window.setInterval(B,ZM))},[B,w,T,z]);Z.useEffect(()=>()=>{N.current!==null&&window.clearInterval(N.current)},[]);let H=Z.useRef(null),U=Z.useCallback(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),ee=Z.useCallback(()=>{U(),H.current=window.setTimeout(()=>{H.current=null,m(null)},oN)},[U]);Z.useEffect(()=>()=>{H.current!==null&&window.clearTimeout(H.current)},[]);let te=Z.useCallback(e=>{U(),M.current=e.clientY;let t=R(e.clientY);t!==null&&m(Math.min(j.current-1,A.current+t)),V(e.clientY)},[U,R,V]),W=Z.useCallback(()=>{M.current=null,z(),ee()},[ee,z]),G=Z.useCallback(()=>{u(!1)},[u]),ne=Z.useCallback(e=>{if(e===null)return;let t=y[e];t&&(r(t.turnId),z(),m(null),G(),d.current?.blur())},[G,r,y,z]),re=Z.useCallback(e=>{let t=R(e.clientY);t!==null&&ne(Math.min(y.length-1,A.current+t))},[ne,y.length,R]);Z.useEffect(()=>{if(!l)return;let e=d.current;!e||e===document.activeElement||(e.focus(),m(e=>{if(e!==null)return e;let t=k>=0?k:y.length-1;return F(t),t}))},[k,F,l,y.length]),Z.useEffect(()=>()=>{u(!1)},[u]);let ie=Z.useCallback(e=>{if(y.length===0)return;let t=p??(k>=0?k:y.length-1),n=e=>{let t=Math.max(0,Math.min(y.length-1,e));F(t),m(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(y.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),ne(t);return}e.key===`Escape`&&(e.preventDefault(),m(null),G(),d.current?.blur())},[k,G,F,ne,p,y.length]),ae=Z.useCallback(()=>{z(),m(null),G()},[G,z]),oe=Z.useRef(null),se=Z.useRef(p);se.current=p;let ce=p!==null,le=Z.useRef(0);Z.useEffect(()=>{let e=oe.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),le.current+=e.deltaY;let t=Math.trunc(le.current/nN);if(t===0)return;le.current-=t*nN;let n=se.current;if(n===null)return;let r=Math.max(0,Math.min(j.current-1,n+t));r!==n&&(F(r),m(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[F,ce]);let ue=p===null?void 0:y[p],de=Math.min(y.length,iN),fe=de*nN,pe=y.length*nN-fe,me=e=>Math.max(0,Math.min(pe,e)),he=Z.useRef(null),ge=0;if(p===null)he.current=null;else if(he.current===null)ge=me(p*nN-(fe-nN)/2),he.current=ge;else{let e=he.current,t=(p-aN)*nN,n=(p+1+aN)*nN-fe;e>t?e=t:e<n&&(e=n),ge=me(e),he.current=ge}let _e=Math.floor(ge/nN),ve=Math.max(0,_e-QM),ye=Math.min(y.length,_e+de+QM),be=ge>0,xe=ge<pe,Se=be||xe?`linear-gradient(to bottom, ${be?`transparent, black 10%`:`black`}, ${xe?`black 90%, transparent`:`black`})`:void 0,Ce=Math.max(0,S-QM),we=Math.min(y.length,C+QM),Te=y.slice(Ce,we),Ee=w||T?`linear-gradient(to bottom, ${w?`transparent, black 14%`:`black`}, ${T?`black 86%, transparent`:`black`})`:void 0;return y.length===0?null:(0,$.jsx)(`nav`,{ref:f,"aria-label":c(`chat.promptNavigator.aria`),className:`pointer-events-none absolute right-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-end`,children:[i?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-mr-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)]`,a?`cursor-wait opacity-70`:void 0),"aria-label":O,title:O,disabled:a,onClick:e=>{e.stopPropagation(),a||o()},children:a?(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:d,role:`listbox`,tabIndex:-1,"aria-activedescendant":ue?`prompt-rail-tick-${ue.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${_?KM:GM}px`,height:`${b*YM}px`},onMouseMove:te,onMouseLeave:W,onClick:re,onKeyDown:ie,onBlur:ae,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:Ee?{maskImage:Ee,WebkitMaskImage:Ee}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${S*YM}px)`},children:Te.map((e,t)=>{let r=Ce+t,i=e.turnId===n,a=p===r,o=lN(r,p,i);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,"aria-label":e.preview.trim()||E,className:`pointer-events-none absolute right-1 flex items-center justify-end`,style:{top:`${r*YM}px`,height:`${YM}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,i?`bg-[var(--surface-foreground)]`:a?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${o}px`}})},e.turnId)})},y[0]?.turnId)}),ue&&p!==null?(0,$.jsx)(`div`,{ref:oe,className:Y(`pointer-events-auto absolute right-full top-1/2 z-30 mr-3 -translate-y-1/2`,`w-[min(20rem,calc(100vw-6rem))] overflow-hidden rounded-xl`,`border border-[var(--interactive-border)]/60 bg-[var(--surface-elevated)] py-1 shadow-md`),onMouseEnter:U,onMouseLeave:ee,onMouseMove:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(`div`,{className:`relative overflow-hidden`,style:{height:`${de*nN}px`,maskImage:Se,WebkitMaskImage:Se},children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-200 ease-out`,style:{height:`${y.length*nN}px`,transform:`translateY(-${ge}px)`},children:y.slice(ve,ye).map((e,t)=>{let r=ve+t,i=e.turnId===n,a=p===r;return(0,$.jsx)(`div`,{role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,title:i?D:void 0,className:`absolute inset-x-0 cursor-pointer px-1.5`,style:{top:`${r*nN+rN}px`,height:`46px`},onMouseMove:()=>{U(),se.current!==r&&(F(r),m(r))},onClick:()=>ne(r),children:(0,$.jsx)(`div`,{className:Y(`flex h-full items-center rounded-lg border px-2 transition-colors`,i?`border-transparent bg-[var(--interactive-selection)]`:a?`border-[var(--interactive-border)]/60 bg-[var(--interactive-hover)]`:`border-[var(--interactive-border)]/40`),children:(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 line-clamp-2 [overflow-wrap:anywhere] typography-meta`,i?`text-[var(--interactive-selectionForeground)]`:`text-[var(--surface-mutedForeground)]`),children:e.preview.trim()||E})})},e.turnId)})})})}):null]})]})})}var dN=100,fN=(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},pN=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=fN(p,t.scrollTop+dN);!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}},mN=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return!1;switch(e.key){case`ArrowUp`:case`PageUp`:case`Home`:return!0;default:return!1}},hN=(e,t)=>{let n=t instanceof Element?t:t instanceof Node?t.parentElement:null;for(;n&&n!==e;){if(n instanceof HTMLElement&&n.scrollTop>0&&n.scrollHeight>n.clientHeight+1)return!0;n=n.parentElement}return!1},gN=e=>{let t=(0,Q.c)(15),{scrollRef:n,enabled:r,onUpwardIntent:i}=e,a=r===void 0||r,o=Z.useRef(null),s;t[0]===i?s=t[1]:(s=()=>{i()},t[0]=i,t[1]=s);let c=K(s),l;t[2]!==c||t[3]!==n?(l=e=>{let t=n.current;t&&(e.deltaY>=0||t instanceof HTMLElement&&(hN(t,e.target)||c()))},t[2]=c,t[3]=n,t[4]=l):l=t[4];let u=K(l),d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>{let t=e.touches.item(0);o.current=t?t.clientY:null},t[5]=d):d=t[5];let f=K(d),p;t[6]!==c||t[7]!==n?(p=e=>{let t=n.current,r=e.touches.item(0);if(!r){o.current=null;return}let i=o.current;o.current=r.clientY,i!==null&&(r.clientY-i<=2||!t||!(t instanceof HTMLElement)||hN(t,e.target)||c())},t[6]=c,t[7]=n,t[8]=p):p=t[8];let m=K(p),h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{o.current=null},t[9]=h):h=t[9];let g=K(h),_;t[10]===c?_=t[11]:(_=e=>{mN(e)&&c()},t[10]=c,t[11]=_);let v=K(_),[y,b]=Z.useState(null),x;t[12]===n?x=t[13]:(x=()=>{let e=n.current??null;b(t=>t===e?t:e)},t[12]=n,t[13]=x),Z.useEffect(x);let S=a&&y?y:_N,C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C={passive:!0},t[14]=C):C=t[14];let w=C;at(`wheel`,u,S,w),at(`touchstart`,f,S,w),at(`touchmove`,m,S,w),at(`touchend`,g,S,w),at(`touchcancel`,g,S,w),at(`keydown`,v,S)};function _N(){}var vN=(e,t)=>({sessionId:e,viewportKey:t}),yN=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,bN=(e,t)=>yN(e,t),xN=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),SN=.1,CN=40,wN=150,TN=1500,EN=2,DN=350,ON=600,kN=8e3,AN=24,jN=2,MN=(e,t)=>e<t,NN=()=>typeof performance<`u`?performance.now():Date.now(),PN=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),FN=(e,t)=>e?CN:t<=0?96:Math.max(48,t*SN),IN=e=>e.scrollHeight-e.scrollTop-e.clientHeight,LN=e=>IN(PN(e)),RN=e=>e.scrollHeight-e.clientHeight>1,zN=(e,t)=>IN(e)<=FN(t,e.clientHeight),BN=({enabled:e=!0,currentSessionId:t,viewportKey:n,sessionMessageCount:r,sessionIsWorking:i,isMobile:a,onActiveTurnChange:o,onUpwardUserIntent:s})=>{let c=Z.useRef(null),[l,u]=Z.useState(null),d=Z.useRef(null),[f,p]=Z.useState(`following`),[m,h]=Z.useState(!1),[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),b=Z.useRef(`following`),x=Z.useRef(a);x.current=a;let S=Z.useRef(r);S.current=r;let C=Z.useRef(vN(t,n));C.current=vN(t,n);let w=Z.useRef(null),T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(0),O=Z.useRef(null),k=Z.useRef(null),A=Z.useRef(0),j=Z.useRef(!1),M=Z.useRef(!1),N=Z.useRef(null),P=Z.useRef(0),F=K(()=>{P.current=NN()+450}),I=Z.useRef(0),L=Z.useRef(!1),R=Z.useRef(null),z=Z.useRef(null),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),ee=Z.useRef(null),te=Fn(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{c.current!==d.current&&(d.current=c.current,u(c.current))});let W=K(e=>{b.current!==e&&(b.current=e,p(e))}),G=K(e=>{T.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:NN()},E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{T.current=null,E.current=null},TN)}),ne=K(e=>{let t=T.current;return t?NN()-t.time>TN?(T.current=null,!1):Math.abs(e.scrollTop-t.top)<EN:!1}),re=K(()=>NN()<A.current),ie=K(()=>{L.current=!1,R.current&&=(clearTimeout(R.current),null),z.current&&=(clearTimeout(z.current),null)}),ae=K(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,ie()},ON)}),oe=K(()=>{let e=c.current;e&&(L.current=!0,B.current=e.scrollHeight,ae(),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{z.current=null,ie()},kN))}),se=K(e=>{let t=c.current;if(!t){h(!1),_(!1);return}let n=e??PN(t),r=RN(n);if(h(r),!r){_(!1);return}let i=b.current===`released`&&!zN(n,x.current);_(i)}),ce=K(()=>{D.current+=1,O.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(O.current),O.current=null),k.current?.(),k.current=null});Z.useEffect(()=>()=>ce(),[l]);let le=K(()=>{if(!e)return;let t=c.current;if(!t)return;ce();let n=D.current,r=t.style.overflow,i=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,t.style.overflow=`hidden`,t.scrollTop=t.scrollHeight,t.scrollHeight,t.style.overflow=r,t.style.scrollBehavior=i;let a=()=>{G(t),t.scrollTop=t.scrollHeight,I.current=t.scrollTop};if(a(),se(),typeof window>`u`)return;let o=0,s=()=>{MN(NN(),P.current)||ce()};t.addEventListener(`touchstart`,s,{passive:!0,once:!0}),k.current=()=>t.removeEventListener(`touchstart`,s);let l=()=>{if(n===D.current){if(LN(t)>jN&&a(),o+=1,o>=AN){O.current=null,k.current?.(),k.current=null,se();return}O.current=window.requestAnimationFrame(l)}};O.current=window.requestAnimationFrame(l)}),ue=K(e=>{let t=c.current;if(t){if(G(t),e===`smooth`){t.scrollTo({top:t.scrollHeight,behavior:e});return}t.scrollTop=t.scrollHeight}}),de=K((t,n=`auto`)=>{if(!e)return;let r=c.current;if(t&&b.current!==`following`&&W(`following`),r&&!(!t&&b.current!==`following`)){if(LN(r)<EN){G(r);return}ue(t?n:`auto`)}}),fe=K(e=>{let t=c.current;if(!t)return;let n=e??PN(t);if(!RN(n)){W(`following`);return}b.current!==`released`&&(W(`released`),se(n))}),pe=K((e=`instant`)=>{if(V.current=!1,W(`following`),ie(),e===`instant`){le();return}ce(),de(!0,`smooth`),se()}),me=K(()=>{V.current=!1,de(!0)}),he=K(()=>{ce(),ie(),W(`released`),se()}),ge=K(()=>{V.current=!0,he()}),_e=K(()=>{V.current=!1}),ve=Z.useRef(s);ve.current=s;let ye=K(()=>{MN(NN(),P.current)||(ce(),ie(),fe())}),be=K(()=>{ye(),ve.current?.()}),xe=K(()=>{H.current!==null&&(clearTimeout(H.current),H.current=null);let e=U.current;if(e){if(!e.identity.sessionId){U.current=null;return}te(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),U.current=null}}),Se=K(()=>{let e=C.current;if(!e.sessionId)return;let t=c.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r>0?(n+i/2)/r:0,o=Math.floor(a*S.current);U.current=xN(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),H.current===null&&(H.current=setTimeout(()=>{H.current=null,xe()},wN))}),Ce=K(()=>{xe()}),we=K(async(e=C.current)=>{if(!e.sessionId)return!1;V.current=!1;let t=Ui(e.sessionId,e.viewportKey);return c.current?(ee.current=null,I.current=t?.scrollPosition?.scrollTop??0,W(`following`),F(),x.current?le():de(!0),oe(),se(),!1):(ee.current=e,W(`following`),!1)});Z.useEffect(()=>{let e=C.current,n=w.current;yN(e,n)||(xe(),ce(),F(),w.current=e,T.current=null,I.current=0,ie(),V.current=!1,W(`following`),ee.current=null,t&&t!==n?.sessionId&&Jb.getInstance().recordSessionStart(t))},[t,n]),Z.useEffect(()=>{i&&!V.current&&b.current===`following`&&de(!0)},[i]),Z.useEffect(()=>{y(f===`following`&&i)},[f,i]),Z.useLayoutEffect(()=>{if(!l)return;let e=ee.current;e&&bN(e,C.current)&&we(e)},[l,t,n]);let Te=K(()=>{let e=c.current;if(!e)return;let t=PN(e),n=I.current;I.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(se(t),V.current){Se();return}if(!RN(t)){W(`following`);return}if(zN(t,x.current)){let e=IN(t)<=EN;(r||b.current===`following`||e)&&W(`following`),Se();return}if(b.current===`following`&&(ne(e)||re()||i)){j.current||de(!1),Se();return}fe(t),Se()});Z.useEffect(()=>{!e||!l||(I.current=l.scrollTop)},[l,e]);let Ee=Z.useRef(null),De=K(e=>{let t=c.current;t&&(e.deltaY>=0||hN(t,e.target)||be())}),Oe=K(e=>{let t=e.touches.item(0);Ee.current=t?t.clientY:null}),ke=K(e=>{let t=c.current,n=e.touches.item(0);if(!n){Ee.current=null;return}let r=Ee.current;Ee.current=n.clientY,r!==null&&(n.clientY-r<=2||t&&(hN(t,e.target)||be()))}),Ae=K(()=>{Ee.current=null}),je=K(e=>{mN(e)&&be()}),Me=K(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&ye()}),Ne=Z.useMemo(()=>()=>void 0,[]),Pe=e&&l?l:Ne,Fe=Z.useMemo(()=>({passive:!0}),[]);at(`scroll`,Te,Pe,Fe),at(`wheel`,De,Pe,Fe),at(`touchstart`,Oe,Pe,Fe),at(`touchmove`,ke,Pe,Fe),at(`touchend`,Ae,Pe,Fe),at(`touchcancel`,Ae,Pe,Fe),at(`keydown`,je,Pe),at(`pointerdown`,Me,e&&typeof window<`u`?window:Ne,!0);let Ie=K(()=>{let e=c.current;if(j.current){se(e?PN(e):void 0);return}if(V.current){se(e?PN(e):void 0);return}if(!e){se(void 0);return}let t=PN(e);if(!RN(t)){W(`following`),se(t);return}if(se(t),L.current){let n=t.scrollHeight>B.current+1;B.current=t.scrollHeight,IN(t)<=EN?G(e):de(!0),n&&ae();return}if(b.current===`following`){if(IN(t)<=EN){G(e);return}de(!1)}}),Le=typeof ResizeObserver<`u`,Re=Le&&e?l:null,ze=Le&&e&&l&&l.firstElementChild instanceof Element?l.firstElementChild:null;ot(Re,Ie),ot(ze,Ie);let Be=K(()=>{N.current!==null&&(clearTimeout(N.current),N.current=null)}),Ve=K(e=>{j.current=!0,typeof e==`number`&&e>0?A.current=NN()+e+DN:A.current=Math.max(A.current,NN()+DN)}),He=K(e=>{let t=e.detail;if(t){if(t.open===!0){Ve(),Be(),N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},1500);return}Be(),Ve()}}),Ue=K(e=>{let t=e.detail;t&&(Be(),Ve(t.durationMs))}),We=K(e=>{let t=e.detail;Be(),t?.open===!0?(M.current=!0,j.current=!0):(M.current=!1,j.current=!0,N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},DN)),se()}),Ge=e&&typeof window<`u`?window:Ne;at(`oc:keyboard-intent`,He,Ge),at(`oc:keyboard-anim`,Ue,Ge),at(`oc:keyboard-settled`,We,Ge),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{Be(),j.current=!1,M.current=!1}},[e]),Z.useEffect(()=>{e&&se()},[e,r]);let Ke=K(t=>{if(e){if(t===`animation`&&(A.current=NN()+DN),se(),L.current){de(!0),ae();return}b.current===`following`&&de(!1)}}),qe=Z.useRef(new Map),Je=K(t=>{let n=qe.current.get(t);if(n)return n;let r=()=>{e&&b.current===`following`&&de(!1)},i={onChunk:r,onComplete:()=>{e&&se()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return qe.current.set(t,i),i});Z.useEffect(()=>()=>{E.current&&=(clearTimeout(E.current),null),ce(),ie(),xe(),H.current!==null&&(clearTimeout(H.current),H.current=null)},[]);let Ye=K(e=>{o?.(e)}),Xe=!!o;return Z.useEffect(()=>{if(!e||!Xe)return;let t=l;if(!t)return;let n=null,r=pN({onActive:e=>{e!==n&&(n=e,Ye(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 u=()=>r.onScroll();return t.addEventListener(`scroll`,u,{passive:!0}),()=>{t.removeEventListener(`scroll`,u),c.disconnect(),r.destroy()}},[l,e,Xe]),{scrollRef:c,state:f,isPinned:f===`following`,isOverflowing:m,isFollowingProgrammatically:v,showScrollButton:g,notifyContentChange:Ke,getAnimationHandlers:Je,goToBottom:pe,scrollToBottomOnSend:me,releaseAutoFollow:he,beginHistoryViewportPreservation:ge,endHistoryViewportPreservation:_e,saveSnapshotNow:Ce,restoreSnapshot:we}},VN=`--oc-mobile-composer-swap`,HN=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),UN=(e,t,n)=>Math.min(n,Math.max(t,e)),WN=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,GN=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return WN(e,n)?e:n},KN=e=>Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),qN=(e,t)=>t?GN(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?GN(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,JN=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:GN(e,{phase:`snapping`,rest:t,progress:n})},YN=e=>UN(e/80,0,1),XN=e=>e>=80?1:UN(e/80,0,1),ZN=(e,t,n={})=>{if(e.pinned)return e;let r=Math.max(0,t),i=e.phase===`snapping`?GN(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(i.rest===`expanded`){if(r<=2||n.holdExpanded)return GN(i,{phase:`rest`,rest:`expanded`,progress:0});let e=YN(r);return e>=1?GN(i,{phase:`rest`,rest:`compact`,progress:1}):GN(i,{phase:`tracking`,rest:`expanded`,progress:e})}if(r<=2)return GN(i,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn)return GN(i,{phase:`rest`,rest:`compact`,progress:1});if(n.towardBottom&&r>=80)return GN(i,{phase:`snapping`,rest:`expanded`,progress:0});let a=XN(r);return a>=1?GN(i,{phase:`rest`,rest:`compact`,progress:1}):GN(i,{phase:`tracking`,rest:`compact`,progress:a})},QN=e=>e.pinned?`expanded`:e.rest===`expanded`?e.progress>=.5?`compact`:`expanded`:e.progress<=.5?`expanded`:`compact`,$N=e=>{if(e.pinned)return GN(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let t=QN(e),n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:GN(e,{phase:`snapping`,rest:t,progress:n})},eP=e=>e.phase===`snapping`?GN(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,tP=e=>{e.style.removeProperty(VN),delete e.dataset.ocComposerSwapPhase,delete e.dataset.ocComposerSwapRest},nP=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest;return n?.phase!==i&&(e.dataset.ocComposerSwapPhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty(VN,r),n?.rest!==a&&(e.dataset.ocComposerSwapRest=a),{progress:r,phase:i,rest:a}},rP=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),iP=()=>{let e=document.documentElement;return e.classList.contains(`oc-keyboard-open`)||e.classList.contains(`oc-kb-animating`)},aP=e=>{if(iP()||e.querySelector(`[data-oc-composer-dictation-active="true"]`))return!0;let t=document.activeElement;return t instanceof HTMLElement&&t.matches(`textarea[data-chat-input="true"]`)&&e.contains(t)},oP=e=>{let t=Z.useRef(HN()),n=Z.useRef(void 0),r=Z.useRef(null),i=Z.useRef(null),a=Z.useRef(0),o=Z.useRef(!1),s=Z.useRef(0),c=Z.useRef(null),l=Z.useRef(0),u=Z.useRef(0),d=Z.useRef(!1),f=Z.useRef(e.enabled);f.current=e.enabled;let p=e=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null)},m=K(t=>{let r=e.scopeRef.current;r&&(n.current=nP(r,t,n.current))}),h=K(e=>{e!==t.current&&(t.current=e,m(e))}),g=K(()=>{if(p(i),t.current.phase!==`snapping`)return;let e=t.current.rest;i.current=window.setTimeout(()=>{i.current=null;let n=eP(t.current);h(n),n.rest===`compact`&&e===`compact`&&(a.current=Date.now()+320,o.current=!0)},240)}),_=K(()=>{let n=e.scopeRef.current;!n||!f.current||h(qN(t.current,aP(n)))}),v=K(e=>o.current?Date.now()>=a.current?(o.current=!1,!1):e>=80?(o.current=!1,a.current=0,!1):!0:!1),y=K(()=>{if(p(r),!f.current||s.current>0||t.current.phase!==`tracking`)return;let e=$N(t.current);h(e),g()}),b=K(()=>{f.current&&(s.current+=1,p(r))}),x=K(()=>{if(!f.current)return;let n=e.scrollRef.current,i=e.scopeRef.current;if(!n||!i)return;let a=aP(i),o=rP(n),m=KN(o),_=c.current;c.current=m;let b=_===null?0:_-m;b>0?(u.current=0,o.scrollTop>0&&(l.current+=b)):b<0&&(l.current=0,u.current+=-b,u.current>=24&&(d.current=!1)),m<=2&&(d.current=!1);let x=qN(t.current,a);if(!a){let e=x.rest===`compact`;x=ZN(x,m,{suppressReturn:v(m),towardBottom:l.current>=24,holdExpanded:d.current}),e&&x.rest===`expanded`&&m>2&&(d.current=!0,l.current=0)}if(h(x),p(r),x.phase===`snapping`){g();return}x.phase===`tracking`&&s.current===0&&(r.current=window.setTimeout(()=>{r.current=null,y()},120))}),S=K(()=>{y()}),C=K(()=>{f.current&&(s.current=Math.max(0,s.current-1),!(s.current>0)&&t.current.phase===`tracking`&&(p(r),r.current=window.setTimeout(()=>{r.current=null,y()},120)))}),w=K(()=>{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)}),T=K(n=>{if(!f.current)return;let r=n.target;r instanceof Element&&r.closest(`[data-oc-composer-compact-surface="true"]`)&&(r.closest(`[data-composer-action="true"]`)||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),d.current=!0,l.current=0,u.current=0,h(JN(t.current,`expanded`)),g(),w(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0})))}),[E,D]=Z.useState(null),[O,k]=Z.useState(null),A=Z.useRef(null),j=K(e=>{e&&tP(e),n.current=void 0,o.current=!1,a.current=0,s.current=0,c.current=null,l.current=0,u.current=0,d.current=!1,h(HN())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;A.current&&A.current!==n&&j(A.current),A.current=n,D(e=>e===t?e:t),k(e=>e===n?e:n)});let M=Z.useMemo(()=>()=>void 0,[]),N=e.enabled&&E?E:M,P=e.enabled&&O?O:M,F=e.enabled&&typeof window<`u`?window:M,I=Z.useMemo(()=>({passive:!0}),[]);at(`scroll`,x,N,I),at(`scrollend`,S,N,I),at(`touchstart`,b,N,I),at(`touchend`,C,N,I),at(`touchcancel`,C,N,I),at(`pointerdown`,T,P),at(`focusin`,_,P),at(`focusout`,_,P),at(`oc:keyboard-intent`,_,F),at(`oc:keyboard-anim`,_,F),at(`oc:keyboard-settled`,_,F),Z.useEffect(()=>{if(!e.enabled){j(A.current),A.current=null;return}return _(),x(),()=>{p(r),p(i)}},[e.enabled,E,O])},sP=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},cP=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},lP=e=>{if(!e)return null;let t=sP(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${cP(e)??``}`},uP=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}),dP=(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&&lP(t[r])===lP(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=sP(r),a=r.info.id,o=uP(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=cP(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},fP=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=sP(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=cP(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}},pP=200,mP={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},hP=()=>pP,gP=()=>Math.round(hP()*.6),_P={MAX_SESSIONS:mP.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(pP*.6),HISTORICAL_MESSAGES:pP,FETCH_BUFFER:20,HISTORY_CHUNK:pP,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:mP.ZOMBIE_TIMEOUT},vP=()=>{let e=hP(),t=gP();return{..._P,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},yP=_P,bP=600,xP=6e3,SP=.5,CP=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),wP=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},TP=(e,t)=>{let n=CP(e,t);if(n||=wP(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}},EP=e=>{let{container:t,quiesceMs:n=bP,maxLifetimeMs:r=xP}=e,i={messageId:e.anchor.messageId,offsetTop:e.anchor.offsetTop},a=!1,o=null,s=null,c=!1,l=t.scrollTop,u=()=>{o!==null&&(clearTimeout(o),o=null)},d=()=>{s!==null&&(clearTimeout(s),s=null)},f=()=>{a||(a=!0,y.disconnect(),t.removeEventListener(`scroll`,v),u(),d())},p=()=>{u(),!a&&(o=setTimeout(()=>{o=null,f()},n))},m=()=>{d(),!a&&(s=setTimeout(()=>{s=null,f()},r))},h=()=>{if(a)return;let e=TP(t,i.messageId);if(!e){f();return}i.messageId=e.messageId,i.offsetTop=e.offsetTop,l=t.scrollTop},g=()=>{if(a)return;if(Math.abs(t.scrollTop-l)>SP){h();return}let e=CP(t,i.messageId);if(!e){let n=wP(t);if(!n){f();return}let r=n.dataset.messageId;if(!r){f();return}let a=t.getBoundingClientRect();i.messageId=r,i.offsetTop=n.getBoundingClientRect().top-a.top,e=n,l=t.scrollTop}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect().top-n.top-i.offsetTop;Math.abs(r)>SP&&(t.scrollTop+=r),l=t.scrollTop},_=()=>{a||c||(c=!0,queueMicrotask(()=>{c=!1,g()}))},v=()=>{h(),p(),m()},y=new MutationObserver(()=>{a||(_(),p())});return y.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`style`,`class`]}),t.addEventListener(`scroll`,v,{passive:!0}),m(),p(),{rebase:h,dispose:f}},DP=30,OP=1200,kP=1.5,AP=e=>Math.max(OP,e*kP),jP=4,MP=30,NP=4,PP=30,FP=250,IP=2e3,LP=_n+2e3,RP=40,zP=`history-loading-timeout`,BP=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),VP=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=zP,e},HP=(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)},UP=2500,WP=new Map,GP=()=>d()?jP:Zi()?NP:DP,KP=e=>d()?e.length<=MP:!Zi()||e.length<=PP,qP=(e,t)=>{if(WP.delete(e),!KP(t.messages))return;let n=GP();for(;WP.size>=n;){let e=WP.keys().next().value;if(typeof e!=`string`)break;WP.delete(e)}WP.set(e,t)},JP=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),YP=e=>e?{owner:`tanstack-core`}:{owner:`controller`},XP=(e,t)=>e?e.canLoadEarlier:t>=vP().HISTORICAL_MESSAGES,ZP=e=>!(e.isMobile||e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=AP(e.clientHeight)),QP=e=>e.pagesLoaded>=e.maxPages?`stop-bounded`: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.limitAfter>e.limitBefore?`continue`:`stop-no-growth`:`stop-exhausted`,$P=1,eF=8,tF=e=>!(!e.enabled||e.isMobile||!e.sessionReady||!e.messageReady||e.historyLoading||!e.canLoadEarlier||!e.isPinned||e.fillBlocked||e.pendingRevealWork||e.isLoadingOlder||!e.hasMessages||e.clientHeight<=0||e.scrollHeight>e.clientHeight+48),nF=e=>[`chat-timeline-auto-fill`,e.runtimeKey,e.sessionId,e.oldestMessageId,e.messageCount,e.canLoadEarlier],rF=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],iF=20,aF=4,oF=80,sF=new WeakMap,cF=new WeakMap,lF=e=>{let t=cF.get(e)??{generation:0};return t.generation+=1,cF.set(e,t),t.generation},uF=e=>{let t=sF.get(e);t&&(t.touches=0,t.pending=null,t.settleScheduled=!1),lF(e)},dF=e=>{fF(e)},fF=e=>{let t=sF.get(e);if(t)return t;let n={touches: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&&pF(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),sF.set(e,n),n},pF=(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+oF||mF(e,n.anchorTop+n.delta))}))},mF=(e,t)=>{let n=lF(e),r=e.style.overflow;if(e.style.overflow=`hidden`,e.scrollTop=t,e.scrollHeight,e.style.overflow=r,e.scrollTop=t,typeof window>`u`)return;let i=!1,a=0,o=()=>{i=!0};e.addEventListener(`touchstart`,o,{passive:!0,once:!0});let s=()=>{if(!i){if((cF.get(e)?.generation??0)!==n){e.removeEventListener(`touchstart`,o);return}e.scrollTop<t-aF&&(e.scrollTop=t),a+=1,a<iF?window.requestAnimationFrame(s):e.removeEventListener(`touchstart`,o)}};window.requestAnimationFrame(s)},hF=(e,t,n)=>{let r=fF(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,mF(e,t)},gF=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),_F=(e,t)=>e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight?e:t,vF=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:a,messageListRef:o,loadMoreMessages:s,goToBottom:c,releaseAutoFollow:l,beginHistoryViewportPreservation:u,endHistoryViewportPreservation:d,isPinned:f,showScrollButton:p,autoFillEnabled:m=!1})=>{let h=Z.useRef(null),g=Z.useRef(null),_=Z.useMemo(()=>{let t=e??``,r=t?WP.get(t):void 0;if(r&&r.messages===n)return qP(t,r),h.current=r.model,g.current=n,r.model;let i=dP(h.current,g.current,n)??fP(n);return h.current=i,g.current=n,t&&n.length>0&&qP(t,{messages:n,model:i}),i},[n,e]),[v,y]=Z.useState(!1),[b,x]=Z.useState(!1),[S,C]=Z.useState(null),[w,T]=Z.useState(!1),[E,D]=Z.useState(null),[O,k]=Z.useState({scrollHeight:0,clientHeight:0}),A=Z.useRef(_),j=Z.useRef(f),M=Z.useRef(v),N=Z.useRef(b),P=Z.useRef(e),F=Z.useRef(t??null),I=Z.useRef(n),L=Z.useRef(r),R=Z.useRef(E),z=Z.useRef([]),B=Z.useRef(null),V=Z.useRef(null),H=Z.useRef(!1),U=Z.useRef(null),[ee,te]=Z.useState(e);ee!==e&&(te(e),U.current!==null&&typeof window<`u`&&(window.clearTimeout(U.current),U.current=null),H.current=!1,M.current=!1,V.current=null,y(!1),x(!1),C(null),T(!1),R.current=null,D(null),k({scrollHeight:0,clientHeight:0}));let W=Z.useMemo(()=>{let e=r?.limit!==E&&XP(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),G=Z.useRef(W);A.current=_,j.current=f,N.current=b,G.current=W,P.current=e,F.current=t??null,I.current=n,L.current=r,R.current=E;let ne=K(()=>{H.current=!0,U.current!==null&&typeof window<`u`&&(window.clearTimeout(U.current),U.current=null)}),re=K(()=>{if(typeof window>`u`){H.current=!1;return}U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,H.current=!1},IP)}),ie=K(()=>{let e=z.current;e.length!==0&&(z.current=[],e.forEach(e=>e()))}),ae=K(()=>new Promise(e=>{if(typeof window>`u`){e();return}let t=!1,n=()=>{t||(t=!0,window.clearTimeout(r),e())};z.current.push(n);let r=window.setTimeout(n,FP)})),oe=K(e=>{let t=B.current;t&&(B.current=null,t.resolve(e))}),se=K(()=>{let e=B.current;if(e){if(e.sessionId!==P.current){oe(!1);return}if(e.kind===`turn`?o.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:o.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(V.current={turnId:e.turnId,expiresAt:Date.now()+UP},C(e.turnId)),oe(!0);return}typeof(e.kind===`turn`?A.current.turnIndexById.get(e.id):A.current.messageToTurnIndex.get(e.id))==`number`&&oe(!1)}}),ce=Z.useRef(null),le=K(()=>{let e=ce.current;e&&(ce.current=null,e.dispose())});tt(()=>{U.current!==null&&typeof window<`u`&&(window.clearTimeout(U.current),U.current=null),le(),ie(),oe(!1)});let ue=n;it(()=>{ie(),se()},[ue]);let de=K(()=>{let e=a.current;if(!e){k(e=>_F(e,{scrollHeight:0,clientHeight:0}));return}k(t=>_F(t,{scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))});ot(typeof ResizeObserver<`u`?a:null,de),it(()=>{de()},[e,v]);let fe=Z.useRef(null),pe=K(()=>o.current?.captureViewportAnchor()??null),me=K(e=>o.current?.restoreViewportAnchor(e)??!1),he=K(()=>{if(Zi())return;le();let e=a.current;if(!e)return;let t=pe();t&&(ce.current=EP({container:e,anchor:t}))}),ge=Z.useRef(null);it(()=>{if(!Zi())return;let e=a.current;e&&(dF(e),uF(e))},[e,a]),it(()=>{le(),fe.current=null,ge.current=null,o.current?.cancelViewportAnchorHold()},[e]),it(()=>{let e=a.current;if(!e)return;let t=fe.current;t&&Math.abs(e.scrollTop-t.top)>eF&&(fe.current=null,t=null);let n=ge.current,r=ue[0]?.info?.id??null,i=ue[ue.length-1]?.info?.id??null,s=n?JP({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:i})||gF(n.oldestId,r,ue):!1;t&&t.sessionId!==P.current&&(fe.current=null,t=null);let l=t?JP({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:i})||gF(t.oldestId,r,ue):!1,u=s||l,d=e=>{ge.current={oldestId:r,newestId:i,scrollHeight:e??ge.current?.scrollHeight??0}};if(j.current&&!t){le(),u?(fe.current=null,c(`instant`),d(e.scrollHeight)):d();return}let f=YP(o.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){o.current?.cancelViewportAnchorHold();let e=t.anchor;e&&me(e),d();return}let n=e.scrollHeight,r=n-t.height;if(Zi()){r>0&&hF(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&me(i))&&r>0&&(e.scrollTop=t.top+r),d(n);return}if(s&&n&&f.owner===`controller`){let t=e.scrollHeight,r=t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;Zi()?hF(e,t,r):e.scrollTop=t}d(t),he();return}d()},[ue,c]);let _e=K(async()=>!1),ve=K(async e=>{let t=Date.now(),n=t+LP,r=F.current,i=r?In()?.getRequestState?.(gt(r,e)):void 0;for(G.current.historyLoading,L.current,i?.status,i?.error;G.current.historyLoading;){if(P.current!==e)return Date.now()-t,`switched`;if(Date.now()>=n){let n=r?In()?.getRequestState?.(gt(r,e)):void 0;return console.error(`[chat-history] historyLoading wait timed out — sync flag still true`,{sessionId:e,directory:r,elapsedMs:Date.now()-t,waitMs:LP,hostTurnPageTimeoutMs:_n,historyLoading:G.current.historyLoading,historyMeta:L.current,requestStatusAtStart:i?.status??null,requestStatusAtTimeout:n?.status??null,requestErrorAtTimeout:n?.error??null,likelyStaleLoadingFlag:n?.status===`ready`||n?.status===`error`||n==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,RP)})}return Date.now()-t,r&&In()?.getRequestState?.(gt(r,e))?.status,P.current===e?`cleared`:`switched`}),ye=K(async e=>{if(!P.current||M.current||!G.current.hasMoreAboveTurns)return!1;M.current=!0,ne(),y(!0);let t=P.current,n=null,r=!!e.userInitiated;r&&u();let i=()=>{n&&fe.current===n&&(fe.current=null,o.current?.cancelViewportAnchorHold()),r&&(r=!1,d())};try{if(G.current.historyLoading){if(!e.userInitiated)return!1;let n=await ve(t);if(n===`timeout`)throw VP();if(n===`switched`||!G.current.hasMoreAboveTurns)return!1}if(!P.current||P.current!==t)return!1;let r=a.current,o=I.current,c=o.length,l=o[0]?.info?.id??null,u=L.current?.limit??vP().HISTORICAL_MESSAGES;e.preserveViewport&&r&&(n={sessionId:P.current,height:r.scrollHeight,top:r.scrollTop,anchor:pe(),oldestId:l,newestId:o[o.length-1]?.info?.id??null},fe.current=n,he());let d=c,f=l,p=u,m=0;for(;;){if(G.current.historyLoading)if(e.userInitiated){let e=await ve(t);if(e===`timeout`)throw i(),VP();if(e===`switched`)return i(),!1}else return i(),!1;let n=a.current?.scrollHeight??0,r=d,o=f,c=p;if(await s(t,`up`),m+=1,P.current!==t)return i(),!1;await ae();let l=I.current,u=l.length,h=l[0]?.info?.id??null,g=L.current?.limit??p,_=QP({scrollHeightBefore:n,scrollHeightAfter:a.current?.scrollHeight??n,messageCountBefore:r,messageCountAfter:u,oldestIdBefore:o,oldestIdAfter:h,limitBefore:c,limitAfter:g,hasMoreAbove:G.current.hasMoreAboveTurns,pagesLoaded:m,maxPages:$P});if(_===`continue`){d=u,f=h,p=g;continue}if(_===`stop-no-growth`){if(G.current.historyLoading){if(e.userInitiated){let e=await ve(t);if(e===`timeout`)throw i(),VP();if(e===`switched`)return i(),!1;--m;continue}return i(),!1}let n=L.current?.limit??c;return R.current=n,D(n),G.current={...G.current,hasMoreAboveTurns:!1,canLoadEarlier:!1},i(),!1}return!0}}catch(e){throw i(),e}finally{M.current=!1,y(!1),re(),ae().then(i)}}),{t:be}=st(),xe=qe({mutationKey:rF({runtimeKey:i(),sessionId:e??``}),mutationFn:async e=>{if(P.current!==e.sessionId)return!1;ne(),e.userInitiated&&l();try{return await ye({preserveViewport:!0,userInitiated:!!e.userInitiated})}finally{re()}}}),Se=K(async e=>{let t=P.current;if(t&&!(xe.isPending&&xe.variables?.sessionId===t))try{let n=await xe.mutateAsync({sessionId:t,userInitiated:!!e?.userInitiated});if(n===!1&&G.current.canLoadEarlier){let r={sessionId:t,grew:n,userInitiated:!!e?.userInitiated,canLoadEarlier:G.current.canLoadEarlier,hasMoreAboveTurns:G.current.hasMoreAboveTurns,historyLoading:G.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null};HP(`no-growth`,Error(`chat history pagination returned no growth`),r),e?.userInitiated&&wr.error(be(`chat.history.loadOlderFailed`))}}catch(n){let r={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:LP,hostTurnPageTimeoutMs:_n,canLoadEarlier:G.current.canLoadEarlier,historyLoading:G.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null};BP(n)?HP(`timeout`,n,r):HP(`failed`,n,r),e?.userInitiated&&wr.error(BP(n)?be(`chat.history.loadOlderTimeout`):be(`chat.history.loadOlderFailed`))}}),Ce=xe.isPending&&xe.variables?.sessionId===e||v,we=n[0]?.info?.id??null,Te=tF({enabled:m,isMobile:Zi(),sessionReady:!!e,messageReady:n.length>0||!!r,historyLoading:W.historyLoading,canLoadEarlier:W.canLoadEarlier,isPinned:f,fillBlocked:w,scrollHeight:O.scrollHeight,clientHeight:O.clientHeight,pendingRevealWork:b,isLoadingOlder:!1,hasMessages:n.length>0});Je({queryKey:nF({runtimeKey:i(),sessionId:e??``,oldestMessageId:we,messageCount:n.length,canLoadEarlier:W.canLoadEarlier}),enabled:!!e&&Te,staleTime:1/0,gcTime:0,retry:(e,t)=>t?.code===`auto-fill-busy`&&e<40,retryDelay:50,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,queryFn:async()=>{let e=P.current;if(!e)return{status:`skip`};if(G.current.historyLoading||M.current){let e=Error(`auto-fill-busy`);throw e.code=`auto-fill-busy`,e}if(!G.current.canLoadEarlier)return{status:`skip`};let t=a.current;if(!t||t.clientHeight<=0)return{status:`skip`};if(t.scrollHeight>t.clientHeight+48)return{status:`tall`};try{let t=await ye({preserveViewport:!0});return t?{status:`grew`}:(G.current.canLoadEarlier&&HP(`no-growth`,Error(`chat history pagination returned no growth`),{sessionId:e,source:`auto-fill`,grew:t,canLoadEarlier:G.current.canLoadEarlier,hasMoreAboveTurns:G.current.hasMoreAboveTurns,historyLoading:G.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null}),T(!0),{status:`blocked`})}catch(t){if(t?.code===`auto-fill-busy`)throw t;let n={sessionId:e,source:`auto-fill`,waitMs:LP,canLoadEarlier:G.current.canLoadEarlier,historyLoading:G.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null};throw BP(t)?HP(`timeout`,t,n):HP(`failed`,t,n),T(!0),t instanceof Error?t:Error(`chat timeline auto-fill failed`)}}});let Ee=K(e=>{let t=a.current;t&&ZP({source:e,isMobile:Zi(),isPinned:j.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:G.current.canLoadEarlier,isLoadingOlder:M.current,pendingRevealWork:N.current})&&Se({userInitiated:!0})}),De=K(()=>{Ee(`scroll`)}),Oe=K(()=>{Ee(`upward-intent`)}),ke=K(async(t,n)=>{if(!t||!P.current)return!1;l(),x(!0);try{return P.current!==e||typeof A.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{B.current={sessionId:P.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},se()})}finally{x(!1)}}),Ae=K(async(t,n)=>{if(!t||!P.current)return!1;l(),x(!0);try{if(P.current!==e)return!1;let r=A.current.messageToTurnId.get(t);return typeof A.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(i=>{B.current={sessionId:P.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:r??null,resolve:i},se()})}finally{x(!1)}}),je=K(async()=>{x(!1),M.current=!1,y(!1),c(`smooth`)}),Me=K(async()=>{x(!1),M.current=!1,y(!1),c(`instant`)}),Ne=K(e=>{let t=V.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;V.current=null}C(e)});return{turnIds:_.turnIds,turnStart:0,renderedMessages:ue,historySignals:W,isLoadingOlder:Ce,pendingRevealWork:b,activeTurnId:S,showScrollToBottom:p&&!b,turnWindowModel:_,loadEarlier:Se,revealBufferedTurns:_e,resumeToBottom:je,resumeToBottomInstant:Me,scrollToTurn:ke,scrollToMessage:Ae,handleHistoryScroll:De,handleHistoryUpwardIntent:Oe,captureViewportAnchor:pe,restoreViewportAnchor:me,handleActiveTurnChange:Ne}},yF=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),bF=({open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s=!1,isLoadingEarlier:c=!1,onLoadEarlier:l,onRevertMessage:u})=>{let{t:d}=st(),f=Qm(),p=n,m=di(p??``,r),h=J(e=>e.revertToMessage),g=J(e=>e.forkFromMessage),_=yF(f.capabilities),{isMobile:v,isTablet:y}=fo(),b=v||y,[x,S]=Z.useState(null),C=Z.useRef(!1),[w,T]=Z.useState(``),[E,D]=Z.useState(0),O=Z.useRef([]),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(!1),M=Z.useRef(e),N=e=>new Date(e).toLocaleDateString(ct(),{year:`numeric`,month:`short`,day:`numeric`}),P=e=>new Date(e).toLocaleTimeString(ct(),{hour:`numeric`,minute:`2-digit`}),F=Z.useMemo(()=>m.filter(e=>e.info.role===`user`).map(e=>({message:e})),[m]),I=Z.useMemo(()=>{let e=w.trim();if(!e)return F;let t=e.toLowerCase();return F.filter(({message:e})=>HM(e.parts).toLowerCase().includes(t))},[F,w]);Z.useEffect(()=>{j.current||D(w.trim()?0:Math.max(0,I.length-1))},[I,w]),Z.useEffect(()=>{O.current=O.current.slice(0,I.length)},[I.length]),Z.useEffect(()=>{j.current||O.current[E]?.scrollIntoView({block:`nearest`})},[E]),Z.useEffect(()=>{!j.current||A.current||c||(j.current=!1)},[I.length,c]),Z.useLayoutEffect(()=>{let t=M.current;if(M.current=e,!e||t||j.current||w.trim())return;let n=k.current;n&&(n.scrollTop=n.scrollHeight)},[e,w]),Z.useLayoutEffect(()=>{let e=A.current,t=k.current;if(!e||!t||c)return;A.current=null;let n=O.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},[I.length,c]);let L=K(()=>{let e=k.current;if(e){let t=e.getBoundingClientRect().top,n=O.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(A.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}j.current=!0,l?.()}),R=K(async e=>{await i?.(e)!==!1&&t(!1)}),z=K(e=>{let t=I.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),D(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),D(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(E%t+t)%t,r=I[n];r&&R(r.message.info.id)}}}),B=K(async(e,n)=>{if(!(!p||C.current)){C.current=!0,S({type:e,messageId:n});try{e===`revert`?u?await u(n):await h(p,n,{directory:r}):await g(p,n,{directory:r}),t(!1)}finally{C.current=!1,S(null)}}});return p?(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(na,{children:[(0,$.jsxs)(aa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),d(`chat.timeline.title`)]}),(0,$.jsx)(oa,{children:d(`chat.timeline.description`)})]}),(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)(Fa,{autoFocus:!0,placeholder:d(`chat.timeline.searchPlaceholder`),value:w,onChange:e=>T(e.target.value),onKeyDown:z,className:`pl-9 w-full`})]}),s&&l&&(0,$.jsx)(`div`,{className:`flex justify-center py-1`,children:(0,$.jsxs)(la,{type:`button`,variant:`link`,size:`sm`,onClick:L,disabled:c,className:`h-auto px-1 py-0 text-muted-foreground hover:text-foreground`,children:[c&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),d(`chat.history.loadOlder`)]})}),(0,$.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto`,children:I.length===0?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:d(w?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):I.map(({message:e},t)=>{let n=UM(e.parts),r=e.info.time.created,i=N(r),a=I[t-1],o=i!==(a?N(a.message.info.time.created):null),s=P(r),c=t===E,l=w.trim()?xF(HM(e.parts),w):null;return(0,$.jsxs)(Z.Fragment,{children:[o&&(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:i}),(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`})]}),(0,$.jsxs)(`div`,{ref:e=>{O.current[t]=e},"data-timeline-message-id":e.info.id,className:Y(`group flex items-center gap-3 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,c&&`bg-interactive-selection text-interactive-selection-foreground`),onClick:()=>void R(e.info.id),onMouseEnter:()=>D(t),children:[(0,$.jsx)(`span`,{className:Y(`typography-meta w-16 flex-shrink-0 text-right tabular-nums`,c?`text-interactive-selection-foreground/70`:`text-muted-foreground`),children:s}),(0,$.jsxs)(`p`,{className:Y(`flex-1 min-w-0 typography-micro truncate`,c?`text-interactive-selection-foreground`:`text-foreground`),children:[l??(n||d(`chat.timeline.noTextContent`)),!l&&n&&n.length>=80&&`…`]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:(0,$.jsxs)(`div`,{className:Y(`gap-1`,b?`flex`:`hidden group-hover:flex`),children:[_.revert?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`revert`&&x.messageId===e.info.id,disabled:x!==null,onClick:t=>{t.stopPropagation(),B(`revert`,e.info.id)},children:(0,$.jsx)(X,{name:x?.type===`revert`&&x.messageId===e.info.id?`loader-4`:`arrow-go-back`,className:Y(`h-4 w-4`,x?.type===`revert`&&x.messageId===e.info.id&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:d(`chat.timeline.actions.revertFromHere`)})]}):null,_.fork?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`fork`&&x.messageId===e.info.id,onClick:t=>{t.stopPropagation(),B(`fork`,e.info.id)},disabled:x!==null,children:x?.type===`fork`&&x.messageId===e.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)(La,{sideOffset:6,children:d(`chat.timeline.actions.forkFromHere`)})]}):null]})})]})]},e.info.id)})}),(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:d(`chat.timeline.actions.title`)}),(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{a?.(-1),t(!1)},children:d(`chat.timeline.actions.previousTurn`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{o?.(),t(!1)},children:d(`chat.timeline.actions.latest`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:d(`chat.timeline.help.clickMessage`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`arrow-go-back`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:d(`chat.timeline.help.undoToPoint`)})]}),_.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:d(`chat.timeline.help.createSessionFromHere`)})]}):null]})]})]})}):null};function xF(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?`…`:``}`}var SF=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},CF=(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`}},wF=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)},TF=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&&wF(`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&&wF(`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=CF(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 wF(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=()=>{wF(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=SF(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},EF=2e4,DF=6e4,OF=2e3,kF=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,AF=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+=kF(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},jF={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},MF=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:jF,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}},NF=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)},PF=(e,t)=>{let n=(0,Q.c)(7),r=Zb(FF),i=J(IF),a=J(LF),o,s;n[0]!==a||n[1]!==i||n[2]!==t||n[3]!==r||n[4]!==e?(o=()=>{if(r&&e&&!a(e)){for(let n of t)if(n.info.role===`assistant`)for(let t of n.parts){let n=t;if(n.type!==`text`)continue;let r=n.text||``;if(r.includes(`The plan at `)||r.includes(`User has requested to enter plan mode`)){i(e);return}}}},s=[r,e,t,i,a],n[0]=a,n[1]=i,n[2]=t,n[3]=r,n[4]=e,n[5]=o,n[6]=s):(o=n[5],s=n[6]),Z.useEffect(o,s)};function FF(e){return e.planModeEnabled}function IF(e){return e.markSessionPlanAvailable}function LF(e){return e.isSessionPlanAvailable}function RF(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 zF(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 BF(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||RF(i)==null}function VF(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!BF(n))continue;let e=zF(n);e&&t.push(e)}}return t}function HF(e,t){return`${e}:${t.join(`,`)}`}function UF(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=HF(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function WF(e,t,n,r){let i=(0,Q.c)(7),a=Jn(),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=UF({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:VF(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,zt(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 GF=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),KF=(e,t)=>({...e,key:qF(e),estimatedBytes:GF(t)}),qF=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),JF=e=>({key:e?qF(e):null,selection:e}),YF=(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},XF=(e,t,n,r)=>{let i=qF(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return YF(e,i,n);let s=o||KF(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),YF(c,i,n)},ZF=(e,t,n)=>{let r=GF(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)},QF=(e,t)=>t&&e.some(e=>e.key===t)?t:null,$F=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?XF(e.cachedSessionViews,t.selection,n,r.estimatedBytes):YF(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}},eI=(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:KF(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},tI=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:XF(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},nI=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},rI=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},iI=e=>rI(e)?.role===`assistant`,aI=(e,t)=>{let n=rI(t);n&&(e.agentName??=nI(n.agent),e.providerId??=nI(n.providerID),e.modelId??=nI(n.modelID))},oI=e=>!!(e.agentName&&e.providerId&&e.modelId),sI=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!iI(r))&&(aI(t,r),oI(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||iI(r))&&(aI(t,r),oI(t)))break}return t},cI=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),lI=[],uI=[],dI={type:`idle`},fI=`openchamber:chat-force-scroll-bottom`,pI=()=>void 0,mI=`Quota limit reached. Retrying automatically.`,hI=1048576,gI=hI,_I=20,vI=hI,yI=16*hI,bI={maxEntries:3,maxEstimatedBytes:32*hI},xI={maxEntries:2,maxEstimatedBytes:32*hI},SI=e=>t(()=>e()),CI={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},wI=[`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(`,`),TI=e=>e instanceof HTMLElement,EI=e=>TI(e)?!!e.closest(wI):!1,DI=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||EI(e)?!0:!t?.contains(e),OI=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=s.getState();return e||t||n||r||i||a||o},kI=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,renderedMessages:l,isLoadingOlder:u,sessionIsWorking:d,streamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,handleMessageContentChange:h,getAnimationHandlers:g,handleHistoryScroll:_,handleHistoryUpwardIntent:v,onTimelineIsAtEndChange:y,scrollToBottom:b,sessionQuestions:x,sessionPermissions:S,isProgrammaticFollowActive:C,showLoadOlderButton:w,onLoadOlder:T,turnIds:E,activeTurnId:D,onSelectTurn:O,showPromptNavigator:k,canLoadEarlierPrompts:A,isLoadingOlderPrompts:j,onLoadEarlierPrompts:M})=>{let{t:N}=st(),P=Zb(e=>e.legendTimelineEnabled),F=Fb({isLoadingOlder:u}),I=Ib({isMobile:r,isLoadingOlder:F}),L=Z.useRef(new Map),R=Z.useRef(new WeakMap),z=Z.useRef(new Map),B=Z.useMemo(()=>{let e=new Map;for(let t=0;t<l.length;t+=1){let n=l[t];if(n.info.role!==`user`)continue;if(uA(n)){let r=fA(l,t)??``,i=z.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`}];z.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(Ht(n.parts))continue;let r=R.current.get(n.parts);r||(r=q(n.parts),R.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=L.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 L.current=e,e},[l]),V=Z.useMemo(()=>E.filter(e=>B.has(e)),[B,E]),H=Z.useMemo(()=>{if(!D||B.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(B.has(e))return e}return null},[D,B,E]),U=K(e=>{e.defaultPrevented||EI(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return gN({scrollRef:o,enabled:P,onUpwardIntent:v}),P?(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)(Lj,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:b,scrollRef:o,directory:a,timelineScrollClassName:Y(`absolute inset-0 z-0 chat-scroll overlay-scrollbar-target`,r&&`chat-scroll-foot-inset`),timelineScrollStyle:CI,timelineOnScroll:_,timelineFollowEnabled:!c,timelineOnIsAtEndChange:y,headerSlot:(0,$.jsxs)($.Fragment,{children:[w&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(la,{variant:`secondary`,size:`sm`,onClick:T,disabled:F,"aria-busy":F,children:[F&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),N(`chat.history.loadOlder`)]})}),I&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:N(`chat.history.loadingMore`)})]})})]}),footerSlot:(0,$.jsxs)($.Fragment,{children:[(x.length>0||S.length>0)&&(0,$.jsxs)(`div`,{children:[x.map(e=>(0,$.jsx)(lM,{question:e},e.id)),S.map(e=>(0,$.jsx)(rM,{permission:e},e.id))]}),(0,$.jsx)(VM,{sessionId:e,directory:a,isMobile:r}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(OM,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?`40px`:`10vh`},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:C,userIntentOnly:!0,observeMutations:!1}),k&&V.length>=2?(0,$.jsx)(uN,{turnIds:V,previewsByTurnId:B,activeTurnId:H,onSelectTurn:O,canLoadEarlier:A,isLoadingOlder:j,onLoadEarlier:M}):null]})}):(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)(Ta,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:CI,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:U,onScroll:_,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[w&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(la,{variant:`secondary`,size:`sm`,onClick:T,disabled:F,"aria-busy":F,children:[F&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),N(`chat.history.loadOlder`)]})}),I&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:N(`chat.history.loadingMore`)})]})}),(0,$.jsx)(Lj,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:b,scrollRef:o,directory:a}),(x.length>0||S.length>0)&&(0,$.jsxs)(`div`,{children:[x.map(e=>(0,$.jsx)(lM,{question:e},e.id)),S.map(e=>(0,$.jsx)(rM,{permission:e},e.id))]}),(0,$.jsx)(VM,{sessionId:e,directory:a,isMobile:r}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(OM,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?`40px`:`10vh`},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:C,userIntentOnly:!0,observeMutations:!1}),k&&V.length>=2?(0,$.jsx)(uN,{turnIds:V,previewsByTurnId:B,activeTurnId:H,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.renderedMessages===t.renderedMessages&&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.handleHistoryUpwardIntent===t.handleHistoryUpwardIntent&&e.onTimelineIsAtEndChange===t.onTimelineIsAtEndChange&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.onLoadOlder===t.onLoadOlder&&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);kI.displayName=`ChatViewport`;var AI=[{id:1,toolRows:[{id:`search`,titleWidth:`w-24`,detailWidth:`w-52`},{id:`read`,titleWidth:`w-20`,detailWidth:`w-36`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-64`}],textWidths:[`w-24`,`w-[92%]`,`w-[78%]`]},{id:2,toolRows:[{id:`read`,titleWidth:`w-20`,detailWidth:`w-40`},{id:`search`,titleWidth:`w-24`,detailWidth:`w-48`}],textWidths:[`w-20`,`w-[88%]`,`w-[70%]`]},{id:3,toolRows:[{id:`shell`,titleWidth:`w-28`,detailWidth:`w-44`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-56`}],textWidths:[`w-24`,`w-[84%]`,`w-[64%]`]}],jI=e=>ta(e.path),MI=(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)]})},NI=e=>{let t=Math.ceil(Math.max(0,e)/_I);return Math.min(yI,gI+t*vI)},PI=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:c,hostedFeatures:l,assistantHistory:u,onRevertMessage:f,warning:p=null,pendingUserMessages:m=uI,onPendingUserMessagesMaterialized:h})=>{let g=l??Bb(void 0),{t:_}=st();it(()=>{ri()},[]);let v=J(e=>e.openNewSessionDraft),y=J(e=>e.setCurrentSession),b=J(e=>e.newSessionDraft),x=J(e=>e.newSessionDraft.draftSubmitting??!1),S=J(e=>e.newSessionDraft.draftEstablishing??!1),C=J(e=>e.forkTransition),w=Mt(e=>e.projects),T=Mt(e=>e.activeProjectId),E=mi(e=>e.providers),D=zl(),O=oi(),k=i??O;it(()=>{!n||!r||!k||Qt(k,r)},[n,r,k]);let A=K(e=>D.ensureSessionRenderable(e,{directory:k})),j=s(e=>e.isExpandedInput),M=s(e=>e.stickyUserHeader),N=s(e=>e.promptNavigatorEnabled),P=s(e=>e.allowPromptingSubagentSessions),F=s(e=>e.isTimelineDialogOpen),I=s(e=>e.setTimelineDialogOpen),L=St(e=>n&&r?e.streamingMessageIds.get(r)??null:null),R=St(e=>L?e.messageStreamStates.get(L)?.phase??null:null),z=kr(r??``,k),B=NI(z);Z.useEffect(()=>{!a||!o||o(a,B)},[o,B,a]);let V=mt(r??``,k).renderable,H=ur(r,k),U=Jt(r),ee=H??U,te=Jh({sessionId:r,hasSessionEntity:!!ee,hasRenderableSessionSnapshot:V,composerSurfaceKind:c?.kind}),W=r?JSON.stringify([k,r]):null,[G,ne]=Z.useState({key:W,attempt:0}),re=di(r??``,k,{suspendPartUpdates:!!L,suspendPartUpdatesForMessageId:L}),ie=r?re:lI,ae=b.pendingUserMessage,oe=J(e=>r?e.retainedPendingUserMessages.get(r):void 0)??uI,se=J(e=>e.clearRetainedPendingUserMessages),ce=Z.useMemo(()=>{if(oe.length===0)return m;if(m.length===0)return oe;let e=new Set(m.map(e=>e.info.id));return[...m,...oe.filter(t=>!e.has(t.info.id))]},[m,oe]),le=Z.useMemo(()=>sI(ie),[ie]),ue=Z.useMemo(()=>{if(!le.modelId)return _(`common.unavailable`);let e=E.find(e=>e.id===le.providerId);return pt(e,le.modelId)||le.modelId},[E,le.modelId,le.providerId,_]),de=Mi(r??``,k),fe=Dr(r??``,k),[pe,me]=Z.useState(null),he=!!r&&pe===r,ge=K(()=>{if(!r||he)return;let e=r,t=k;me(e);let n=fr(()=>{let n=In();if(!n)throw Error(`unbound`);return n.getTranscript(gt(t,e))});ai(Yi({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:de?{sessionID:e,status:de.status===`ready`?`ready`:de.status,error:de.error}:void 0,hydration:fe,error:de?.error})),(async()=>{try{await bn(t,e),await D.ensureSessionRenderable(e,{directory:t});try{let r=fr(()=>{let n=In();if(!n)throw Error(`unbound`);return n.getTranscript(gt(t,e))});n&&r&&zr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){ai(Yi({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:fe,error:n}))}finally{me(t=>t===e?null:t)}})()}),_e=Pr(r??``,k).boundary,ve=K(async e=>{if(_e.kind===`has-more`){await xr(k,e);return}if(_e.kind===`unknown`){await Ji(k,e);return}u&&!u.complete&&await u.fetchPrevious()});PF(r??``,ie);let ye=Er(r??``,k),be=ei(r??``,k),xe=Fi(k),Se=ye??dI,Ce=or(r,k),we=nr(r,k);WF(r,k,ie,we.length);let Te=Z.useMemo(()=>{if(!r||Ce.length>0||we.length>0)return!1;let e=Se.type??`idle`;if(e===`busy`||e===`retry`||jb(ce,{resolvedSessionStatus:ye,sessionStatusObservedAt:be}))return!0;let t=ie[ie.length-1]?.info,n=t?.time?.created;return ye&&typeof be==`number`&&typeof n==`number`&&n<=be||typeof xe==`number`&&typeof n==`number`&&n<=xe?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,ce,ye,ie,Ce.length,we.length,Se.type,be,xe]),Ee=Z.useMemo(()=>!r||Se.type!==`retry`?null:{sessionId:r,message:(typeof Se.message==`string`?(Se.message??``).trim():``)||mI,confirmedAt:Se.confirmedAt},[r,Se]),[De,Oe]=Z.useState(0),ke=Z.useRef(null);Z.useEffect(()=>{if(!Ee||typeof Ee.confirmedAt==`number`){ke.current=null,Oe(0);return}ke.current!==Ee.sessionId&&(ke.current=Ee.sessionId,Oe(Date.now()))},[Ee]);let Ae=Z.useMemo(()=>Ee?{...Ee,fallbackTimestamp:De}:null,[Ee,De]),je=!!(r&&D.isLoading(r,{directory:k})),Me=Z.useMemo(()=>{if(!r)return null;let e=Mb({boundary:_e,assistantComplete:u?.complete??!0});return{limit:_e.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:Nb({syncLoading:je,assistantLoading:!!u?.loading})}},[u?.complete,u?.loading,r,_e,je]),Ne=s(e=>e.isMobile),Pe=_h()!==null,Fe=d(),Ie=Fh(),Le=!!b?.open,Re=Hi(e=>e.error),ze=j,Be=Pe||Ne||Fe||Ie===`mini-chat`,Ve=Z.useRef(null),He=Z.useMemo(()=>{let e=b?.selectedProjectId?w.find(e=>e.id===b.selectedProjectId)??null:null,t=T?w.find(e=>e.id===T)??null:null,n=e??t??w[0]??null;return n?jI(n):null},[T,b?.selectedProjectId,w]),Ue=rn(r,k),We=a??r??``,[Ge,Ke]=Z.useState(null),qe=$h(Ge,We,Ue,le);it(()=>{Ke(e=>$h(e,We,Ue,le))},[Ue,le,We]);let Je=Ue??qe?.parentTarget??null,Ye=qe?.execution??le,Xe=jc(),Ze=Xe!==null&&r===Xe,Qe=K(()=>{Je&&y(Je.id,Je.directory)}),$e=Je?.session?.title,et=g.returnToParent&&Je&&!Ze?(0,$.jsxs)(la,{type:`button`,variant:`outline`,size:`xs`,onClick:Qe,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":_(`chat.container.returnToParent.aria`),title:$e?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:$e}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,nt=Yh({readOnly:t,sessionIdentityPending:te,isSubagentSession:!!ee?.parentID||!!qe,allowPromptingSubagentSessions:P}),ct=Ye.modelId===le.modelId?ue:Ye.modelId?pt(E.find(e=>e.id===Ye.providerId),Ye.modelId)||Ye.modelId:_(`common.unavailable`),lt=Je?(0,$.jsx)(Wb,{agentName:Ye.agentName,providerId:Ye.providerId,modelId:Ye.modelId,modelName:ct}):(0,$.jsx)(Wb,{}),ut=K(e=>{s.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),dt=K(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`openchamber:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&&ut({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),ft=typeof window<`u`&&window.parent!==window;at(`message`,dt,ft?window:pI),rt(()=>{if(!ft)return;let e=window;e.__openchamberApplyChatSettingsSync=ut,window.parent.postMessage({type:`openchamber:chat-settings-request`},window.location.origin)}),tt(()=>{if(typeof window>`u`)return;let e=window;e.__openchamberApplyChatSettingsSync===ut&&delete e.__openchamberApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Le&&v()},[e,r,Le,g.newSessionDraft,v]);let ht=Z.useRef(()=>{}),_t=K(e=>{ht.current(e)}),vt=Z.useRef(()=>{}),yt=K(()=>{vt.current()}),bt=Zb(e=>e.legendTimelineEnabled),[xt,Ct]=Z.useState(!0),wt=K(e=>{Ct(e)}),{scrollRef:Tt,notifyContentChange:Et,getAnimationHandlers:Dt,goToBottom:Ot,scrollToBottomOnSend:jt,releaseAutoFollow:Nt,beginHistoryViewportPreservation:Pt,endHistoryViewportPreservation:Ft,restoreSnapshot:It,isPinned:Rt,isFollowingProgrammatically:zt,showScrollButton:Bt}=BN({enabled:n&&!bt,currentSessionId:r,viewportKey:a,sessionMessageCount:z,sessionIsWorking:Te,isMobile:Ne,onActiveTurnChange:_t,onUpwardUserIntent:yt}),Vt=Z.useRef(null);oP({enabled:Ne,scrollRef:Tt,scopeRef:Vt});let Ht=Z.useRef([]),Ut=Z.useMemo(()=>{let e=Bn(u?.entries??[],r,Ht.current);return Ht.current=e,e},[u?.entries,r]),Wt=Z.useRef([]),Gt=Z.useMemo(()=>{if(!u)return ie;let e=Vi(u.entries,r,ie,Wt.current);return Wt.current=e,e},[u,r,ie]),Kt=Z.useMemo(()=>Ab(Ut.length===0?Gt:r?[...Ut,Gi(r),...Gt]:Ut,ce),[r,Gt,Ut,ce]),qt=Z.useRef(null),Yt=Z.useMemo(()=>zb({sessionId:r,messages:Kt,retained:qt.current}),[r,Kt]);qt.current=Yt.retained;let Xt=Yt.messages,Zt=Z.useRef(null),$t=Zt.current===r,en=Z.useRef(jF),tn=r?`${k}\n${r}`:null,nn=K(()=>AF(Xt));Z.useEffect(()=>{if(!r||!tn||!Te){en.current={...en.current,lastMovementAt:null};return}let e=r,t=k,n=setInterval(()=>{let n=nn(),r=MF(en.current,{sessionKey:tn,working:!0,streaming:!!L,fingerprint:n,now:Date.now(),thresholdMs:EF,cooldownMs:DF,maxAttempts:3});en.current=r.state,r.shouldRefresh&&(NF({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),kt(t,e).catch(()=>{}))},OF);return()=>clearInterval(n)},[r,k,nn,Te,L,tn]);let an=Z.useMemo(()=>{if(ce.length===0)return[];let e=new Set([...Ut,...Gt].filter(e=>At(e.parts)).map(e=>e.info.id));return ce.map(e=>e.info.id).filter(t=>e.has(t))},[Gt,Ut,ce]);Z.useEffect(()=>{an.length!==0&&(h?.(an),r&&se(r,an))},[se,r,an,h]);let on=vF({sessionId:r,directory:k,messages:Xt,historyMeta:Me,scrollRef:Tt,messageListRef:Ve,loadMoreMessages:ve,goToBottom:Ot,releaseAutoFollow:Nt,beginHistoryViewportPreservation:Pt,endHistoryViewportPreservation:Ft,isPinned:bt?xt:Rt,showScrollButton:bt?!xt:Bt,autoFillEnabled:n&&!ze}),sn=K(()=>{Ot(`instant`)}),cn=Pb({isMobile:Ne,canLoadEarlier:on.historySignals.canLoadEarlier,isLoadingOlder:on.isLoadingOlder}),ln=on.isLoadingOlder,un=on.loadEarlier,dn=K(()=>{un({userInitiated:!0})});ht.current=on.handleActiveTurnChange,vt.current=on.handleHistoryUpwardIntent,Z.useEffect(()=>{(Ce.length!==0||we.length!==0)&&Et(`permission`)},[Et,Ce,we]);let fn=TF({sessionId:r,turnIds:on.turnIds,activeTurnId:on.activeTurnId,scrollToTurn:on.scrollToTurn,scrollToMessage:on.scrollToMessage,resumeToBottom:on.resumeToBottomInstant}),pn=nt.showReadOnlyBanner?lt:t?null:(0,$.jsx)(Sb,{surface:c,scrollToBottom:jt,showScrollToBottom:Ne&&on.showScrollToBottom,onScrollToBottom:fn.resumeToLatest,submissionBlocked:nt.blockSubmission}),mn=K(e=>{fn.scrollToTurnId(e,{behavior:`smooth`})}),hn=on.historySignals.canLoadEarlier,gn=g.promptNavigator&&!Ne&&!Fe&&!ze&&N&&on.turnIds.length>=2;Z.useEffect(()=>{gn||s.getState().setPromptNavigatorPanelOpen(!1)},[gn]);let _n=K(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||Ot(`instant`)});at(fI,_n,n&&r&&typeof window<`u`?window:pI);let vn=K(e=>{if(!n||!r||ze||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=s.getState();if(t!==`chat`||OI())return;let i=Tt.current;if(DI(document.activeElement,i)||EI(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;fn.scrollByTurnOffset(a,{resumePastEnd:!1})});at(`keydown`,vn,n&&r&&!ze&&typeof window<`u`?window:pI);let yn=Z.useRef(0),q=K(()=>{let e=Tt.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),xn=K(()=>{yn.current||=requestAnimationFrame(()=>{yn.current=0,q()})});it(()=>{n&&q()},[n,r,ze,q]);let Sn=typeof ResizeObserver<`u`;ot(n&&Sn?Tt:null,xn),at(`resize`,xn,n&&!Sn&&typeof window<`u`?window:pI),tt(()=>{yn.current&&=(cancelAnimationFrame(yn.current),0)});let Cn=Z.useRef(null),wn=Z.useRef(0),Tn=Lb({transcriptMessageCount:ie.length,pendingUserCount:ce.length,historyPrefixCount:Ut.length}),En=Rb({hasTranscriptShell:Tn,p0Satisfied:fe.p0Satisfied,hasBusyShell:Te&&Tn,hasImmediateShell:ce.length>0||Ut.length>0,hasRenderableSessionSnapshot:V,prefetchStatus:de?.status,syncLoading:!!(r&&D.isLoading(r,{directory:k})),userRetrying:he,hasPaintedTranscript:$t});En===`pass`&&Xt.length>0&&(Zt.current=r);let Dn=!!r&&En===`hydrating`,On=!!r&&En===`load-error`;Z.useEffect(()=>{!On||!r||ai(Yi({kind:`request-error`,sessionID:r,directory:k,purpose:`load-failed`,source:`network`,request:de?{sessionID:r,status:de.status===`ready`?`ready`:de.status,error:de.error}:void 0,hydration:fe,error:de?.error}))},[r,k,On,de,fe]),Z.useEffect(()=>{if(!n||!r||Dn)return;let e=Xt.length,t=Cn.current!==r,i=!t&&wn.current===0&&e>0;if(!t&&!i){Cn.current===r&&(wn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(Cn.current=r,wn.current=e,a){Nt();return}let o=()=>{It()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,Dn,Nt,It,Xt.length]),Z.useEffect(()=>{ne(e=>e.key===W?e:{key:W,attempt:0})},[W]),Z.useEffect(()=>{if(!n||!r||G.key!==W||!cI({sessionId:r,hasRenderableSessionSnapshot:V,hasCurrentSessionEntity:!!ee})||(A(r),ee||G.attempt>=2))return;let e=G.attempt+1,t=window.setTimeout(()=>{ne(t=>t.key===W&&t.attempt===G.attempt?{key:W,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,ee,r,k,A,V,W,G]);let kn=C&&r&&(C.targetSessionId?r===C.targetSessionId:r===C.sourceSessionId)?C:null;if(kn){let e=kn.stage===`preparing`?`chat.forkTransition.preparing`:kn.stage===`copying`?`chat.forkTransition.copying`:kn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(kn.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${_(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(e)}),(0,$.jsx)(Qf,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}return!r&&!Le?e&&!Re?(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)(Kb,{})}):!r&&Le?(x||S)&&ae?(0,$.jsx)(`div`,{className:`relative flex h-full flex-col bg-background`,children:(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:(0,$.jsxs)(Ta,{className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll`,style:CI,children:[(0,$.jsx)(Lj,{sessionKey:`draft:${b.draftID??`pending`}`,messages:[ae],sessionIsWorking:!0,isLoadingOlder:!1,onMessageContentChange:Et,getAnimationHandlers:Dt,scrollToBottom:sn}),(0,$.jsxs)(`div`,{className:`chat-message-column px-4 pb-10 pt-2 typography-meta text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Qf,{})]})]})})}):x||S?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":_(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Qf,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Be&&!ze?(0,$.jsxs)(`div`,{className:`oc-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:MI(He?_(`chat.emptyState.draftTitleWithProject`,{project:He}):_(`chat.emptyState.draftTitle`),He)}),(0,$.jsx)(Gg,{onSubmit:e=>Lt.getState().requestPresetSubmit(e),className:`oc-draft-starters mt-8 max-w-md`})]}):null,(0,$.jsx)(`div`,{className:Y(`relative z-10 flex min-h-0`,Ne&&`oc-mobile-composer-foot`,ze?`flex-1 bg-background`:Be?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:pn})]}):r?On?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[et,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,ze?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":ze,children:ze?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:_(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:_(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(la,{type:`button`,className:`mt-5`,onClick:ge,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Ne&&`oc-mobile-composer-foot`,ze?`flex-1 min-h-0 bg-background`:`bg-background`),children:pn})]}):Dn?(0,$.jsxs)(`div`,{ref:Vt,className:Y(`relative flex flex-col h-full bg-background`,Ne&&`oc-chat-composer-swap-scope`),children:[et,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,ze?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":ze,children:(0,$.jsx)(`div`,{ref:Tt,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:CI,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:AI.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)(es,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(es,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(es,{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)(es,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(es,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(es,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Ne&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,ze?`flex-1 min-h-0 bg-background`:`bg-background`),children:pn})]}):Xt.length===0&&!Te?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[et,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,ze?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":ze,children:ze?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(Kb,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Ne&&`oc-mobile-composer-foot`,ze?`flex-1 min-h-0 bg-background`:`bg-background`),children:pn}),(0,$.jsx)(kb,{})]}):(0,$.jsxs)(`div`,{ref:Vt,className:Y(`relative flex flex-col h-full bg-background`,Ne&&`oc-chat-composer-swap-scope`),children:[p?(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:p}):null,et,(0,$.jsx)(kI,{currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:ze,isMobile:Ne,stickyUserHeader:M,directory:k,scrollRef:Tt,messageListRef:Ve,pendingRevealWork:on.pendingRevealWork,renderedMessages:on.renderedMessages,isLoadingOlder:ln,sessionIsWorking:Te,streamingMessageId:L,activeStreamingPhase:R,retryOverlay:Ae,handleMessageContentChange:Et,getAnimationHandlers:Dt,handleHistoryScroll:on.handleHistoryScroll,handleHistoryUpwardIntent:on.handleHistoryUpwardIntent,onTimelineIsAtEndChange:wt,scrollToBottom:sn,sessionQuestions:we,sessionPermissions:Ce,isProgrammaticFollowActive:zt,showLoadOlderButton:cn,onLoadOlder:dn,turnIds:on.turnIds,activeTurnId:on.activeTurnId,onSelectTurn:mn,showPromptNavigator:gn,canLoadEarlierPrompts:hn,isLoadingOlderPrompts:ln,onLoadEarlierPrompts:dn},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,Ne&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,ze?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!ze&&Xt.length>0&&(Ne?(0,$.jsx)(Nh,{placement:`expanded`,visible:on.showScrollToBottom,onClick:fn.resumeToLatest}):(0,$.jsx)(Nh,{visible:on.showScrollToBottom,onClick:fn.resumeToLatest})),pn]}),(0,$.jsx)(kb,{}),(0,$.jsx)(bF,{open:F,onOpenChange:I,sessionID:r??void 0,directory:k,onRevertMessage:f,onScrollToMessage:on.scrollToMessage,onScrollByTurnOffset:fn.scrollByTurnOffset,onResumeToLatest:sn,canLoadEarlier:on.historySignals.canLoadEarlier,isLoadingEarlier:ln,onLoadEarlier:dn})]}):null});PI.displayName=`MemoizedChatContainerContent`;var FI=()=>{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)(es,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(es,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(es,{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-6 px-4`,children:[t,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(es,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(es,{className:`h-4 w-3/5 animate-none rounded-md`})]}),(0,$.jsx)(es,{className:`h-24 w-full animate-none rounded-xl`})]})})}),e[1]=n):n=e[1],n},II=e=>{let t=(0,Q.c)(63),n,r;t[0]===e?(n=t[1],r=t[2]):({runtimeKey:r,...n}=e,t[0]=e,t[1]=n,t[2]=r);let i=Fh(),a=oi(),o=J(he(BI)),s;bb0:{if(!o.sessionId){s=null;break bb0}let e=o.directory??a,n;t[3]!==r||t[4]!==o.sessionId||t[5]!==e?(n={runtimeKey:r,sessionId:o.sessionId,directory:e},t[3]=r,t[4]=o.sessionId,t[5]=e,t[6]=n):n=t[6],s=n}let c=s,l;t[7]===c?l=t[8]:(l=JF(c),t[7]=c,t[8]=l);let u=l,f=u.key,p=Zi()||d()||i===`mini-chat`?xI:bI,m;t[9]!==p||t[10]!==c||t[11]!==u?(m=()=>({activeIntent:u,cacheNeedsTrim:!1,cachedSessionViews:c?XF([],c,p,gI):[],pendingSessionView:null}),t[9]=p,t[10]=c,t[11]=u,t[12]=m):m=t[12];let[h,g]=Z.useState(m),_=Z.useRef(u),v=Z.useRef(f),{cacheNeedsTrim:y,cachedSessionViews:b,pendingSessionView:x}=h,S=x?.intent===u?x.entry:null,C;if(t[13]!==b||t[14]!==S){let e=[...b];S&&!e.some(e=>e.key===S.key)&&e.push(S),C=e.sort(VI),t[13]=b,t[14]=S,t[15]=C}else C=t[15];let w=C,T;t[16]!==w||t[17]!==f?(T=QF(w,f),t[16]=w,t[17]=f,t[18]=T):T=t[18];let E=T,D=!!(f&&!E),O;t[19]!==p||t[20]!==u||t[21]!==f?(O=()=>{_.current=u,v.current=f,g(e=>$F(e,u,p))},t[19]=p,t[20]=u,t[21]=f,t[22]=O):O=t[22];let k;t[23]!==p||t[24]!==y||t[25]!==u||t[26]!==f?(k=[p,y,u,f],t[23]=p,t[24]=y,t[25]=u,t[26]=f,t[27]=k):k=t[27],it(O,k);let A=x?.intent??null,j,M;t[28]!==p||t[29]!==A?(j=()=>{A&&g(e=>tI(e,A,p))},M=[p,A],t[28]=p,t[29]=A,t[30]=j,t[31]=M):(j=t[30],M=t[31]),it(j,M);let N;t[32]!==E||t[33]!==u||t[34]!==f?(N=()=>{if(!u.selection||E)return;let e=u,t=f;return ls(()=>{_.current===e&&v.current===t&&g(n=>v.current===t?eI(n,e,_.current,gI):n)},{priority:`user-blocking`})},t[32]=E,t[33]=u,t[34]=f,t[35]=N):N=t[35];let P;t[36]!==E||t[37]!==p||t[38]!==u||t[39]!==f?(P=[E,p,u,f],t[36]=E,t[37]=p,t[38]=u,t[39]=f,t[40]=P):P=t[40],Z.useEffect(N,P);let F;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(F=(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=ZF(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})},t[41]=F):F=t[41];let I=K(F),L=D||void 0,R;t[42]!==D||t[43]!==f?(R=D?(0,$.jsx)(FI,{},f):null,t[42]=D,t[43]=f,t[44]=R):R=t[44];let z;if(t[45]!==E||t[46]!==I||t[47]!==n||t[48]!==w){let e;t[50]!==E||t[51]!==I||t[52]!==n?(e=e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:E===e.key?`visible`:`hidden`,children:(0,$.jsx)(PI,{...n,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:I})},e.key),t[50]=E,t[51]=I,t[52]=n,t[53]=e):e=t[53],z=w.map(e),t[45]=E,t[46]=I,t[47]=n,t[48]=w,t[49]=z}else z=t[49];let B;t[54]!==n||t[55]!==o.directory||t[56]!==f?(B=f?null:(0,$.jsx)(PI,{...n,sessionId:null,sessionDirectory:o.directory}),t[54]=n,t[55]=o.directory,t[56]=f,t[57]=B):B=t[57];let V;return t[58]!==L||t[59]!==R||t[60]!==z||t[61]!==B?(V=(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":L,children:[R,z,B]}),t[58]=L,t[59]=R,t[60]=z,t[61]=B,t[62]=V):V=t[62],V},LI=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=Bb(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)(PI,{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)(Zm.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},RI=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=oi(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Xm({...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)(PI,{...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)(Zm.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},zI=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(SI,i,i);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(LI,{...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)(RI,{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)(II,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r};function BI(e){return{sessionId:e.currentSessionId,directory:e.currentSessionDirectory}}function VI(e,t){return e.key.localeCompare(t.key)}export{wc as $,Ph as A,Sp as B,Ag as C,_g as D,Og as E,Jm as F,su as G,fp as H,Zm as I,zl as J,au as K,Zp as L,gh as M,_h as N,yg as O,qm as P,Cc as Q,Wp as R,kg as S,Mg as T,Qf as U,dp as V,ku as W,bl as X,yl as Y,Sc as Z,Wv as _,BN as a,t_ as b,JD as c,aE as d,Oc as et,YT as f,Xv as g,Wb as h,gP as i,Nh as j,og as k,iE as l,Zb as m,sI as n,Tc as nt,DM as o,NT as p,Gl as q,yP as r,Lj as s,zI as t,Ac as tt,rE as u,Uv as v,Dg as w,Eg as x,f_ as y,zp as z};
6583
+ `),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=ns(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=sc(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)(Bj,{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},Uj=new Set([`id`,`identifier`,`title`,`name`]),Wj=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Gj=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),Kj=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},qj=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},Jj=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?`${Gj(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)(Jj,{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(Wj(n)){let e;t[18]===n?e=t[19]:(e=Kj(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(Xj),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${Gj(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)(Jj,{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?Gj(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`&&qj(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:Gj(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});Jj.displayName=`JsonSummaryValue`;var Yj=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)(Jj,{value:n,depth:0})}),t[0]=n,t[1]=r),r});Yj.displayName=`JsonSummaryView`;function Xj(e){let[t]=e;return!Uj.has(t)}var Zj={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`},Qj={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},$j=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})},eM=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},tM=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,nM=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)(Yj,{data:n})}),t[0]=n,t[1]=r),r},rM=({permission:e,onResponse:t})=>{let{t:n}=ot(),[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=tn,c=bi(),l=Qr(e=>e.currentSessionId),u=Z.useMemo(()=>{if(!l||e.sessionID===l)return!1;let t=c.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===l)},[e.sessionID,l,c]),d=async n=>{i(!0);try{await s(e.sessionID,e.id,n),o(!0),t?.(n)}catch(e){console.error(`[PermissionCard] Failed to respond to permission:`,e)}finally{i(!1)}};if(a)return null;let f=e.permission||`unknown`,p=f.toLowerCase(),m=(t,n=``)=>{let r=e.metadata[t];return typeof r==`string`?r:typeof r==`number`?String(r):n},h=t=>{let n=e.metadata[t];return typeof n==`number`?n:void 0},g=t=>!!e.metadata[t],_=eM(f),v=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[tM(e),t]));return(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{className:`-mt-1 overflow-hidden border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2.5 py-2 sm:px-2 sm:py-1.5 border-b border-border/20 bg-muted/5`,children:(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`)}),u?(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:[$j(f),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] text-muted-foreground font-medium`,children:_})]})]})}),(0,$.jsxs)(`div`,{className:`px-2.5 py-2 sm:px-2 [&_.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(p===`bash`||p===`shell`||p===`shell_command`){let e=m(`command`)||m(`cmd`)||m(`script`),t=m(`description`),r=m(`cwd`)||m(`working_directory`)||m(`directory`)||m(`path`),i=h(`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)(Qs,{language:`bash`,code:e,style:Zj,codeStyle:Qj.style,wrap:!0})})]})}if(p===`edit`||p===`multiedit`||p===`str_replace`||p===`str_replace_based_edit_tool`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`changes`)||m(`diff`),r=g(`replace_all`)||g(`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)(fa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(Vj,{diff:t,filePath:e})})]})}if(p===`write`||p===`create`||p===`file_write`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`content`)||m(`text`)||m(`data`);return t?(0,$.jsx)(fa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(Hj,{content:t,filePath:e})}):null}if(p===`webfetch`||p===`fetch`||p===`curl`||p===`wget`){let t=m(`url`)||m(`uri`)||m(`endpoint`),r=m(`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=h(`timeout`),s=m(`format`)||m(`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)(fa,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(nM,{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)(fa,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(nM,{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(v).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)(fa,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(nM,{data:v})})]})})()]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-1 border-t border-border/20 px-1.5 py-1.5 sm:flex sm:items-center sm:flex-wrap sm:px-2 sm:py-1`,children:[(0,$.jsxs)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`once`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,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)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`always`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,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)(la,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`reject`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-[var(--status-error)] sm:h-6 sm:w-auto sm:px-2`,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`)})]}),r&&(0,$.jsx)(`div`,{className:`col-span-3 flex justify-center w-full sm:w-auto sm:ml-auto py-1 sm:py-0 typography-meta text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})})]})]})})})};function iM(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(`
6584
+ `).trimEnd()}function aM(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)}function oM({scrollHeight:e,currentHeight:t}){let n=Math.min(Math.max(e,40),200);return t===n?null:n}var sM=`summary`,cM=Z.memo(function(e){let t=(0,Q.c)(31),{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(`--oc-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=q(m),g;t[1]===h?g=t[2]:(g=()=>{requestAnimationFrame(h)},t[1]=h,t[2]=g);let _=q(g),v;t[3]===h?v=t[4]:(v=()=>{let e=()=>requestAnimationFrame(h);return e(),window.addEventListener(`oc:keyboard-settled`,e),window.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`oc: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]!==u||t[10]!==f?(S=()=>{let e=s.current;if(!e)return;let t=oM({scrollHeight:e.scrollHeight,currentHeight:u}),n=e.scrollHeight>(t??u);f!==n&&p(n),t!==null&&d(t)},t[9]=u,t[10]=f,t[11]=S):S=t[11];let C;t[12]!==u||t[13]!==f||t[14]!==c?(C=[u,f,c],t[12]=u,t[13]=f,t[14]=c,t[15]=C):C=t[15],Z.useLayoutEffect(S,C);let w;t[16]===a?w=t[17]:(w=e=>{let t=e.target.value;l(t),a(t)},t[16]=a,t[17]=w);let T;t[18]===u?T=t[19]:(T={height:u},t[18]=u,t[19]=T);let E=f?`overflow-y-auto`:`overflow-hidden`,D;t[20]===E?D=t[21]:(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[20]=E,t[21]=D);let O;return t[22]!==i||t[23]!==_||t[24]!==c||t[25]!==o||t[26]!==r||t[27]!==T||t[28]!==D||t[29]!==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[22]=i,t[23]=_,t[24]=c,t[25]=o,t[26]=r,t[27]=T,t[28]=D,t[29]=w,t[30]=O):O=t[30],O}),lM=({question:e})=>{let{t}=ot(),n=ir,r=sn,i=s(e=>e.isMobile),a=bi(),o=Qr(e=>e.currentSessionId),c=Z.useMemo(()=>{if(!o||e.sessionID===o)return!1;let t=a.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===o)},[e.sessionID,o,a]),[l,u]=Z.useState(`0`),[d,f]=Z.useState(!1),[p,m]=Z.useState(!1),[h,g]=Z.useState({}),[_,v]=Z.useState({}),y=Z.useRef({}),[b,x]=Z.useState({}),S=Z.useMemo(()=>e.questions??[],[e.questions]),C=l===sM,w=C?-1:Math.max(0,Math.min(S.length-1,Number(l)||0)),T=C?null:S[w],E=Z.useMemo(()=>{if(C)return null;let e=T?.header?.trim();return e&&e.length>0?e:null},[T?.header,C]);Z.useEffect(()=>{u(`0`),g({}),v({}),y.current={},x({}),m(!1)},[e.id]);let D=Z.useMemo(()=>{let e=S.map((e,t)=>({value:String(t),label:e.header?.trim()||`Q${t+1}`}));return S.length>1&&e.push({value:sM,label:t(`chat.questionCard.summaryTab`)}),e},[S,t]),O=Z.useCallback(e=>{if(_[e])return(y.current[e]??``).trim()||t(`chat.questionCard.noAnswer`);let n=h[e]??[];return n.length>0?n.join(`, `):t(`chat.questionCard.noAnswer`)},[_,h,t]),k=!!T?.multiple,A=h[w]??[],j=!!_[w],M=Z.useMemo(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){b[t]||e.push(t);continue}(h[t]??[]).length===0&&e.push(t)}return e},[_,b,S.length,h]),N=Z.useMemo(()=>S.length!==0&&M.length===0,[S.length,M.length]),P=Z.useCallback(()=>{if(S.length===0||M.length===0)return;let e=C?-1:w;for(let t=1;t<=S.length;t+=1){let n=(e+t+S.length)%S.length;if(M.includes(n)){u(String(n));return}}u(String(M[0]))},[w,C,S.length,M]),F=Z.useCallback(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){let n=(y.current[t]??``).trim();e.push(n?[n]:[]);continue}e.push(h[t]??[])}return e},[_,S.length,h]),I=Z.useCallback(e=>{T&&(v(e=>({...e,[w]:!1})),x(e=>e[w]?{...e,[w]:!1}:e),g(t=>{let n=t[w]??[];if(k){let r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,[w]:r}}return{...t,[w]:[e]}}))},[w,T,k]),L=Z.useCallback(()=>{v(e=>({...e,[w]:!0})),g(e=>({...e,[w]:[]}));let e=(y.current[w]??``).trim().length>0;x(t=>t[w]===e?t:{...t,[w]:e})},[w]),R=Z.useCallback(e=>{y.current[w]=e;let t=e.trim().length>0;x(e=>e[w]===t?e:{...e,[w]:t})},[w]),z=Z.useCallback(async()=>{if(N){f(!0);try{let t=F();await n(e.sessionID,e.id,t),m(!0)}catch(e){Ht(e)?(Cr.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Cr.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}}},[F,e.id,e.sessionID,N,n,t]),B=Z.useCallback(e=>{Kh(e)||e.key===`Enter`&&!e.shiftKey&&(!i||e.ctrlKey||e.metaKey)&&(e.preventDefault(),N?z():P())},[z,P,i,N]),V=Z.useCallback(async()=>{f(!0);try{await r(e.sessionID,e.id),m(!0)}catch(e){Ht(e)?(Cr.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Cr.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}},[e.id,e.sessionID,r,t]),H=Z.useCallback(async()=>{let n=iM(e);if((await ct(n)).ok){Cr.success(t(`chat.questionCard.copiedMarkdown`));return}Cr.error(t(`chat.questionCard.copyFailed`))},[e,t]),U=Z.useCallback(async()=>{let n=aM(e);if((await ct(n)).ok){Cr.success(t(`chat.questionCard.copiedJson`));return}Cr.error(t(`chat.questionCard.copyFailed`))},[e,t]);return p||S.length===0?null:(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{"data-question-card":!0,className:`-mt-1 border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1.5 border-b border-border/20`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`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,E?(0,$.jsx)(`span`,{className:`ml-auto typography-micro font-medium text-foreground/70 px-1.5 py-0.5 rounded bg-muted/30 border border-border/20`,children:E}):null,(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-0.5`,E?null:`ml-auto`),children:[(0,$.jsx)(`button`,{type:`button`,onClick:H,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:U,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`})})]})]})}),(0,$.jsxs)(`div`,{className:`px-2 py-2`,children:[D.length>1?(0,$.jsx)(`div`,{className:`flex items-center gap-1 mb-2 flex-wrap`,children:D.map(e=>{let t=l===e.value,n=e.value===sM,r=n?-1:Number(e.value),i=!n&&Number.isFinite(r)&&!M.includes(r);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(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,C?(0,$.jsx)(`div`,{className:`space-y-2`,children:S.map((e,n)=>{let r=O(n),i=r!==t(`chat.questionCard.noAnswer`);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(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)})}):T?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground mb-1.5`,children:T.question}),k?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1.5`,children:t(`chat.questionCard.selectMultiple`)}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[T.options.map((e,n)=>{let r=A.includes(e.label),i=/\(recommended\)/i.test(e.label);return(0,$.jsx)(`button`,{type:`button`,onClick:()=>I(e.label),disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,r?`bg-interactive-selection/20`:null,d?`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`,children:k?(0,$.jsx)(ha,{checked:r,onChange:()=>I(e.label),disabled:d}):(0,$.jsx)(uo,{checked:r,onChange:()=>I(e.label),disabled:d})}),(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:L,disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,j?`bg-interactive-selection/20`:null,d?`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`,j?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,j?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),j?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)(cM,{value:y.current[w]??``,onValueChange:R,placeholder:t(`chat.questionCard.yourAnswer`),disabled:d,onKeyDown:B})}):null]})]}):null]}),(0,$.jsxs)(`div`,{className:`px-2 pb-1.5 pt-1 flex items-center gap-1.5 border-t border-border/20`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:N?z:P,disabled:d,className:Y(`flex 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:[N?(0,$.jsx)(X,{name:`check`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`}),t(N?`chat.questionCard.submit`:`chat.questionCard.next`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:V,disabled:d,className:Y(`flex 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`)]}),d?(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]})]})})})},uM={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,retryInfo:null,turnStartedAt:void 0},dM=[],fM=`\0`,pM=new Set([`edit`,`write`,`multiedit`,`apply_patch`]),mM={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,multiedit:`chat.assistantStatus.editingFiles`,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`,plan_enter:`chat.assistantStatus.switchingToPlanning`,plan_exit:`chat.assistantStatus.switchingToBuilding`},hM=[`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`],gM=(e,t)=>{let n=mM[e];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},_M=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)},vM=(e,t)=>t(hM[_M(e)%hM.length]??`chat.assistantStatus.working`),yM=(e,t,n)=>{let r,i;if(!Vt(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??TM(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=EM(n);pM.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=wM(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=TM(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?i===`multiedit`?gM(i,n):n(`chat.assistantStatus.editingFile`):r===`tool`&&i?gM(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):vM(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},bM=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(fM),xM=e=>{let[t,n,r=`working`,i]=e.split(fM);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},SM=e=>e.type===`reasoning`,CM=e=>e.type===`text`,wM=e=>{if(CM(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},TM=e=>(CM(e)||SM(e),e.time),EM=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function DM(e,t){let{t:n}=ot(),r=Qr(e=>e.currentSessionId),i=Qr(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),c=Qr(s),l=Di(a??``,o??void 0),u=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--)if(l[e].role===`assistant`)return l[e].id;return null},[l]),d=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--){let t=l[e];if(t.role===`user`)return{id:t.id,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,turnStartedAt:void 0}},[l]),f=d.id,p=gr(u??``,o??void 0,a??void 0),m=gr(f??``,o??void 0,a??void 0),h=!!f&&OO(m),g=Z.useMemo(()=>{let e=`${a??``}:${u??``}`;return bM(yM(u?p:dM,e,n))},[a,u,p,n]),_=gi(a??``,o??void 0),v=ji(a??``,o??void 0),y=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),b=Qr(y),{phase:x,isWorking:S}=Gh(a,o??void 0),C=Tr(a??``,o??void 0),w=C?.type===`retry`?C.attempt:void 0,T=C?.type===`retry`?C.next:void 0,E=Z.useMemo(()=>xM(g),[g]),D=Z.useMemo(()=>{let e=!!(b&&!b.acknowledged);return{wasAborted:e,abortActive:e}},[b]),O=Z.useMemo(()=>{if(D.wasAborted)return{...uM,wasAborted:!0,abortActive:D.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};let e=S,t=x===`busy`,r=x===`retry`,i=e&&h,a=`idle`;e&&(a=!i&&(E.activePartType===`tool`||E.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:w,next:T}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(E.activePartType===`tool`||E.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):E.statusText:null,isGenericStatus:!e||!i&&E.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?E.activePartType:void 0,activeToolName:e&&!i?E.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,retryInfo:o,turnStartedAt:d.turnStartedAt}},[x,S,h,d.turnStartedAt,E,D,w,T,n]);return{forming:Z.useMemo(()=>({isActive:S&&E.activePartType===`text`,characterCount:0}),[S,E.activePartType]),working:Z.useMemo(()=>{if(O.wasAborted||O.abortActive)return O;if(c)return{...O,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null};let e=_.length>0,t=v.length>0;return!e&&!t?O:t?{...O,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...O,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[O,c,_,v,n])}}var OM=Z.memo(()=>{let e=(0,Q.c)(13),t=Qm(),n=Qr(kM),r=Qr(AM),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=Qr(o),c=Qr(jM),l=Qr(MM),{working:u}=DM(i,a),d=mi(NM),f=!!(s&&!s.acknowledged),p=!!(i&&c===i&&typeof l==`number`&&l>Date.now()),m=f||u.wasAborted,h=f||u.abortActive,g;return e[2]!==d||e[3]!==p||e[4]!==m||e[5]!==h||e[6]!==u.isGenericStatus||e[7]!==u.isWaitingForPermission||e[8]!==u.isWorking||e[9]!==u.retryInfo||e[10]!==u.statusText||e[11]!==u.turnStartedAt?(g=(0,$.jsx)(rh,{isWorking:u.isWorking,statusText:u.statusText,isGenericStatus:u.isGenericStatus,isWaitingForPermission:u.isWaitingForPermission,wasAborted:m,abortActive:h,retryInfo:u.retryInfo,turnStartedAt:u.turnStartedAt,showAbortPrompt:p,showAssistantStatus:!0,showTodos:!1,agentName:d}),e[2]=d,e[3]=p,e[4]=m,e[5]=h,e[6]=u.isGenericStatus,e[7]=u.isWaitingForPermission,e[8]=u.isWorking,e[9]=u.retryInfo,e[10]=u.statusText,e[11]=u.turnStartedAt,e[12]=g):g=e[12],g});OM.displayName=`StatusRowContainer`;function kM(e){return e.currentSessionId}function AM(e){return e.currentSessionDirectory}function jM(e){return e.abortPromptSessionId}function MM(e){return e.abortPromptExpiresAt}function NM(e){return e.currentAgentName}var PM=e=>!!e&&typeof e==`object`&&!Array.isArray(e);function FM(e){let t=e?.metadata;if(!PM(t))return null;let n=t.openchamber;if(!PM(n))return null;let r=n.assist;if(!PM(r))return null;let i=typeof r.recap==`string`?r.recap.trim():``,a=typeof r.forMessageID==`string`?r.forMessageID:``;return!a||!i?null:{recap:i,forMessageID:a,generatedAt:typeof r.generatedAt==`number`?r.generatedAt:0}}var IM=6e4;function LM(e,t){let n=oi(),r=t||n,i=Wn(r);return ur(e,r,i)}function RM(e,t){let n=(0,Q.c)(14),r=lr(e,t),i=Tr(e,t),a=LM(e,t),o=s(BM),c=!i||i.type===`idle`,l;n[0]===r?l=n[1]:(l=FM(r),n[0]=r,n[1]=l);let u=l,d=u&&a&&a.role===`assistant`&&a.id===u.forMessageID&&c?u:null,f=a?.timestamp??0,[,p]=Z.useReducer(zM,0),m=d?Date.now()-f>=IM:!1,h;n[2]!==d||n[3]!==p||n[4]!==f||n[5]!==m?(h=()=>{if(!d||m||!f)return;let e=IM-(Date.now()-f);if(e<=0)return;let t=setTimeout(p,e+250);return()=>clearTimeout(t)},n[2]=d,n[3]=p,n[4]=f,n[5]=m,n[6]=h):h=n[6];let g;n[7]!==d||n[8]!==f||n[9]!==m?(g=[d,m,f],n[7]=d,n[8]=f,n[9]=m,n[10]=g):g=n[10],Z.useEffect(h,g);let _=o&&d&&d.recap&&m?d.recap:null,v;return n[11]!==d||n[12]!==_?(v={assist:d,visibleRecap:_},n[11]=d,n[12]=_,n[13]=v):v=n[13],v}function zM(e){return e+1}function BM(e){return e.sessionRecapEnabled}var VM=Z.memo(e=>{let t=(0,Q.c)(13),{sessionId:n,directory:r,isMobile:i}=e,{visibleRecap:a}=RM(n,r),{t:o}=ot();if(!a)return null;let s;t[0]===o?s=t[1]:(s=o(`chat.recap.aria`),t[0]=o,t[1]=s);let c=`typography-markdown-body text-muted-foreground/70 ${i?`line-clamp-4`:`line-clamp-2`}`,l;t[2]===o?l=t[3]:(l=o(`chat.recap.label`),t[2]=o,t[3]=l);let u;t[4]===l?u=t[5]:(u=(0,$.jsxs)(`span`,{className:`italic text-muted-foreground/50`,children:[l,` `]}),t[4]=l,t[5]=u);let d;t[6]!==c||t[7]!==u||t[8]!==a?(d=(0,$.jsxs)(`span`,{className:c,children:[u,a]}),t[6]=c,t[7]=u,t[8]=a,t[9]=d):d=t[9];let f;return t[10]!==s||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`chat-message-column`,children:(0,$.jsx)(`div`,{className:`-mt-6`,"aria-label":s,children:d})}),t[10]=s,t[11]=d,t[12]=f):f=t[12],f});VM.displayName=`SessionRecapNote`;function HM(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
6585
+ `)}function UM(e,t=80){let n=HM(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var WM=160,GM=28,KM=12,qM=6,JM=30,YM=12,XM=18,ZM=80,QM=4,$M=10,eN=14,tN=20,nN=54,rN=4,iN=8,aN=2,oN=160,sN=(e,t)=>e.map(e=>({turnId:e,preview:UM(t.get(e)??[],WM)})),cN=[1,.6,.35,.15],lN=(e,t,n)=>{let r=n?eN:$M;if(t===null)return r;let i=cN[Math.abs(e-t)]??0;return Math.round(r+(tN-r)*i)};function uN({turnIds:e,previewsByTurnId:t,activeTurnId:n,onSelectTurn:r,canLoadEarlier:i,isLoadingOlder:a,onLoadEarlier:o}){let{t:c}=ot(),l=s(e=>e.isPromptNavigatorPanelOpen),u=s(e=>e.setPromptNavigatorPanelOpen),d=Z.useRef(null),f=Z.useRef(null),[p,m]=Z.useState(null),[h,g]=Z.useState(0),[_,v]=Z.useState(!1);Z.useEffect(()=>{let e=f.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){v(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.right-qM-GM;v(r.right>i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let y=Z.useMemo(()=>sN(e,t),[t,e]),b=Math.min(y.length,JM),x=Math.max(0,y.length-b),S=Math.min(h,x),C=S+b,w=S>0,T=C<y.length,E=c(`chat.timeline.noTextContent`),D=c(`chat.promptNavigator.currentPrompt`),O=c(`chat.promptNavigator.loadMore`),k=Z.useMemo(()=>n?y.findIndex(e=>e.turnId===n):-1,[n,y]),A=Z.useRef(S);A.current=S;let j=Z.useRef(y.length);j.current=y.length;let M=Z.useRef(null),N=Z.useRef(null),P=Z.useRef(0),F=Z.useCallback(e=>{g(t=>{let n=j.current,r=Math.min(n,JM),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})},[]),I=Z.useRef(y[0]?.turnId),L=Z.useRef(y.length);Z.useLayoutEffect(()=>{let e=I.current,t=L.current,n=y.length-t;n>0&&t>0&&e&&y[0]?.turnId!==e&&(g(e=>e+n),m(e=>e===null?null:e+n)),I.current=y[0]?.turnId,L.current=y.length},[y]),Z.useEffect(()=>{if(p!==null)return;let e=k>=0?k:y.length-1;g(()=>{let t=j.current,n=Math.min(t,JM),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[k,p,y.length]);let R=Z.useCallback(e=>{let t=d.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/YM),i=Math.min(j.current,JM);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),z=Z.useCallback(()=>{P.current=0,N.current!==null&&(window.clearInterval(N.current),N.current=null)},[]),B=Z.useCallback(()=>{let e=P.current;if(e===0){z();return}let t=j.current,n=Math.max(0,t-Math.min(t,JM)),r=Math.min(A.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){z();return}A.current=i,g(i);let a=M.current;if(a!==null){let e=R(a);e!==null&&m(Math.min(t-1,i+e))}},[R,z]),V=Z.useCallback(e=>{let t=d.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=XM&&w?i=-1:r>=n.height-XM&&T&&(i=1),P.current=i,i===0){z();return}N.current===null&&(N.current=window.setInterval(B,ZM))},[B,w,T,z]);Z.useEffect(()=>()=>{N.current!==null&&window.clearInterval(N.current)},[]);let H=Z.useRef(null),U=Z.useCallback(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),W=Z.useCallback(()=>{U(),H.current=window.setTimeout(()=>{H.current=null,m(null)},oN)},[U]);Z.useEffect(()=>()=>{H.current!==null&&window.clearTimeout(H.current)},[]);let ee=Z.useCallback(e=>{U(),M.current=e.clientY;let t=R(e.clientY);t!==null&&m(Math.min(j.current-1,A.current+t)),V(e.clientY)},[U,R,V]),G=Z.useCallback(()=>{M.current=null,z(),W()},[W,z]),K=Z.useCallback(()=>{u(!1)},[u]),te=Z.useCallback(e=>{if(e===null)return;let t=y[e];t&&(r(t.turnId),z(),m(null),K(),d.current?.blur())},[K,r,y,z]),ne=Z.useCallback(e=>{let t=R(e.clientY);t!==null&&te(Math.min(y.length-1,A.current+t))},[te,y.length,R]);Z.useEffect(()=>{if(!l)return;let e=d.current;!e||e===document.activeElement||(e.focus(),m(e=>{if(e!==null)return e;let t=k>=0?k:y.length-1;return F(t),t}))},[k,F,l,y.length]),Z.useEffect(()=>()=>{u(!1)},[u]);let re=Z.useCallback(e=>{if(y.length===0)return;let t=p??(k>=0?k:y.length-1),n=e=>{let t=Math.max(0,Math.min(y.length-1,e));F(t),m(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(y.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),te(t);return}e.key===`Escape`&&(e.preventDefault(),m(null),K(),d.current?.blur())},[k,K,F,te,p,y.length]),ie=Z.useCallback(()=>{z(),m(null),K()},[K,z]),ae=Z.useRef(null),oe=Z.useRef(p);oe.current=p;let se=p!==null,ce=Z.useRef(0);Z.useEffect(()=>{let e=ae.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),ce.current+=e.deltaY;let t=Math.trunc(ce.current/nN);if(t===0)return;ce.current-=t*nN;let n=oe.current;if(n===null)return;let r=Math.max(0,Math.min(j.current-1,n+t));r!==n&&(F(r),m(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[F,se]);let le=p===null?void 0:y[p],ue=Math.min(y.length,iN),de=ue*nN,fe=y.length*nN-de,pe=e=>Math.max(0,Math.min(fe,e)),me=Z.useRef(null),he=0;if(p===null)me.current=null;else if(me.current===null)he=pe(p*nN-(de-nN)/2),me.current=he;else{let e=me.current,t=(p-aN)*nN,n=(p+1+aN)*nN-de;e>t?e=t:e<n&&(e=n),he=pe(e),me.current=he}let ge=Math.floor(he/nN),_e=Math.max(0,ge-QM),ve=Math.min(y.length,ge+ue+QM),ye=he>0,be=he<fe,xe=ye||be?`linear-gradient(to bottom, ${ye?`transparent, black 10%`:`black`}, ${be?`black 90%, transparent`:`black`})`:void 0,Se=Math.max(0,S-QM),Ce=Math.min(y.length,C+QM),we=y.slice(Se,Ce),Te=w||T?`linear-gradient(to bottom, ${w?`transparent, black 14%`:`black`}, ${T?`black 86%, transparent`:`black`})`:void 0;return y.length===0?null:(0,$.jsx)(`nav`,{ref:f,"aria-label":c(`chat.promptNavigator.aria`),className:`pointer-events-none absolute right-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-end`,children:[i?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-mr-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)]`,a?`cursor-wait opacity-70`:void 0),"aria-label":O,title:O,disabled:a,onClick:e=>{e.stopPropagation(),a||o()},children:a?(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:d,role:`listbox`,tabIndex:-1,"aria-activedescendant":le?`prompt-rail-tick-${le.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${_?KM:GM}px`,height:`${b*YM}px`},onMouseMove:ee,onMouseLeave:G,onClick:ne,onKeyDown:re,onBlur:ie,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:Te?{maskImage:Te,WebkitMaskImage:Te}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${S*YM}px)`},children:we.map((e,t)=>{let r=Se+t,i=e.turnId===n,a=p===r,o=lN(r,p,i);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,"aria-label":e.preview.trim()||E,className:`pointer-events-none absolute right-1 flex items-center justify-end`,style:{top:`${r*YM}px`,height:`${YM}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,i?`bg-[var(--surface-foreground)]`:a?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${o}px`}})},e.turnId)})},y[0]?.turnId)}),le&&p!==null?(0,$.jsx)(`div`,{ref:ae,className:Y(`pointer-events-auto absolute right-full top-1/2 z-30 mr-3 -translate-y-1/2`,`w-[min(20rem,calc(100vw-6rem))] overflow-hidden rounded-xl`,`border border-[var(--interactive-border)]/60 bg-[var(--surface-elevated)] py-1 shadow-md`),onMouseEnter:U,onMouseLeave:W,onMouseMove:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(`div`,{className:`relative overflow-hidden`,style:{height:`${ue*nN}px`,maskImage:xe,WebkitMaskImage:xe},children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-200 ease-out`,style:{height:`${y.length*nN}px`,transform:`translateY(-${he}px)`},children:y.slice(_e,ve).map((e,t)=>{let r=_e+t,i=e.turnId===n,a=p===r;return(0,$.jsx)(`div`,{role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,title:i?D:void 0,className:`absolute inset-x-0 cursor-pointer px-1.5`,style:{top:`${r*nN+rN}px`,height:`46px`},onMouseMove:()=>{U(),oe.current!==r&&(F(r),m(r))},onClick:()=>te(r),children:(0,$.jsx)(`div`,{className:Y(`flex h-full items-center rounded-lg border px-2 transition-colors`,i?`border-transparent bg-[var(--interactive-selection)]`:a?`border-[var(--interactive-border)]/60 bg-[var(--interactive-hover)]`:`border-[var(--interactive-border)]/40`),children:(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 line-clamp-2 [overflow-wrap:anywhere] typography-meta`,i?`text-[var(--interactive-selectionForeground)]`:`text-[var(--surface-mutedForeground)]`),children:e.preview.trim()||E})})},e.turnId)})})})}):null]})]})})}var dN=100,fN=(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},pN=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=fN(p,t.scrollTop+dN);!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}},mN=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return!1;switch(e.key){case`ArrowUp`:case`PageUp`:case`Home`:return!0;default:return!1}},hN=(e,t)=>{let n=t instanceof Element?t:t instanceof Node?t.parentElement:null;for(;n&&n!==e;){if(n instanceof HTMLElement&&n.scrollTop>0&&n.scrollHeight>n.clientHeight+1)return!0;n=n.parentElement}return!1},gN=e=>{let t=(0,Q.c)(15),{scrollRef:n,enabled:r,onUpwardIntent:i}=e,a=r===void 0||r,o=Z.useRef(null),s;t[0]===i?s=t[1]:(s=()=>{i()},t[0]=i,t[1]=s);let c=q(s),l;t[2]!==c||t[3]!==n?(l=e=>{let t=n.current;t&&(e.deltaY>=0||t instanceof HTMLElement&&(hN(t,e.target)||c()))},t[2]=c,t[3]=n,t[4]=l):l=t[4];let u=q(l),d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>{let t=e.touches.item(0);o.current=t?t.clientY:null},t[5]=d):d=t[5];let f=q(d),p;t[6]!==c||t[7]!==n?(p=e=>{let t=n.current,r=e.touches.item(0);if(!r){o.current=null;return}let i=o.current;o.current=r.clientY,i!==null&&(r.clientY-i<=2||!t||!(t instanceof HTMLElement)||hN(t,e.target)||c())},t[6]=c,t[7]=n,t[8]=p):p=t[8];let m=q(p),h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{o.current=null},t[9]=h):h=t[9];let g=q(h),_;t[10]===c?_=t[11]:(_=e=>{mN(e)&&c()},t[10]=c,t[11]=_);let v=q(_),[y,b]=Z.useState(null),x;t[12]===n?x=t[13]:(x=()=>{let e=n.current??null;b(t=>t===e?t:e)},t[12]=n,t[13]=x),Z.useEffect(x);let S=a&&y?y:_N,C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C={passive:!0},t[14]=C):C=t[14];let w=C;it(`wheel`,u,S,w),it(`touchstart`,f,S,w),it(`touchmove`,m,S,w),it(`touchend`,g,S,w),it(`touchcancel`,g,S,w),it(`keydown`,v,S)};function _N(){}var vN=(e,t)=>({sessionId:e,viewportKey:t}),yN=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,bN=(e,t)=>yN(e,t),xN=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),SN=.1,CN=40,wN=150,TN=1500,EN=2,DN=350,ON=600,kN=8e3,AN=24,jN=2,MN=(e,t)=>e<t,NN=()=>typeof performance<`u`?performance.now():Date.now(),PN=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),FN=(e,t)=>e?CN:t<=0?96:Math.max(48,t*SN),IN=e=>e.scrollHeight-e.scrollTop-e.clientHeight,LN=e=>IN(PN(e)),RN=e=>e.scrollHeight-e.clientHeight>1,zN=(e,t)=>IN(e)<=FN(t,e.clientHeight),BN=({enabled:e=!0,currentSessionId:t,viewportKey:n,sessionMessageCount:r,sessionIsWorking:i,isMobile:a,onActiveTurnChange:o,onUpwardUserIntent:s})=>{let c=Z.useRef(null),[l,u]=Z.useState(null),d=Z.useRef(null),[f,p]=Z.useState(`following`),[m,h]=Z.useState(!1),[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),b=Z.useRef(`following`),x=Z.useRef(a);x.current=a;let S=Z.useRef(r);S.current=r;let C=Z.useRef(vN(t,n));C.current=vN(t,n);let w=Z.useRef(null),T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(0),O=Z.useRef(null),k=Z.useRef(null),A=Z.useRef(0),j=Z.useRef(!1),M=Z.useRef(!1),N=Z.useRef(null),P=Z.useRef(0),F=q(()=>{P.current=NN()+450}),I=Z.useRef(0),L=Z.useRef(!1),R=Z.useRef(null),z=Z.useRef(null),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(null),ee=Pn(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{c.current!==d.current&&(d.current=c.current,u(c.current))});let G=q(e=>{b.current!==e&&(b.current=e,p(e))}),K=q(e=>{T.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:NN()},E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{T.current=null,E.current=null},TN)}),te=q(e=>{let t=T.current;return t?NN()-t.time>TN?(T.current=null,!1):Math.abs(e.scrollTop-t.top)<EN:!1}),ne=q(()=>NN()<A.current),re=q(()=>{L.current=!1,R.current&&=(clearTimeout(R.current),null),z.current&&=(clearTimeout(z.current),null)}),ie=q(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,re()},ON)}),ae=q(()=>{let e=c.current;e&&(L.current=!0,B.current=e.scrollHeight,ie(),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{z.current=null,re()},kN))}),oe=q(e=>{let t=c.current;if(!t){h(!1),_(!1);return}let n=e??PN(t),r=RN(n);if(h(r),!r){_(!1);return}let i=b.current===`released`&&!zN(n,x.current);_(i)}),se=q(()=>{D.current+=1,O.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(O.current),O.current=null),k.current?.(),k.current=null});Z.useEffect(()=>()=>se(),[l]);let ce=q(()=>{if(!e)return;let t=c.current;if(!t)return;se();let n=D.current,r=t.style.overflow,i=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,t.style.overflow=`hidden`,t.scrollTop=t.scrollHeight,t.scrollHeight,t.style.overflow=r,t.style.scrollBehavior=i;let a=()=>{K(t),t.scrollTop=t.scrollHeight,I.current=t.scrollTop};if(a(),oe(),typeof window>`u`)return;let o=0,s=()=>{MN(NN(),P.current)||se()};t.addEventListener(`touchstart`,s,{passive:!0,once:!0}),k.current=()=>t.removeEventListener(`touchstart`,s);let l=()=>{if(n===D.current){if(LN(t)>jN&&a(),o+=1,o>=AN){O.current=null,k.current?.(),k.current=null,oe();return}O.current=window.requestAnimationFrame(l)}};O.current=window.requestAnimationFrame(l)}),le=q(e=>{let t=c.current;if(t){if(K(t),e===`smooth`){t.scrollTo({top:t.scrollHeight,behavior:e});return}t.scrollTop=t.scrollHeight}}),ue=q((t,n=`auto`)=>{if(!e)return;let r=c.current;if(t&&b.current!==`following`&&G(`following`),r&&!(!t&&b.current!==`following`)){if(LN(r)<EN){K(r);return}le(t?n:`auto`)}}),de=q(e=>{let t=c.current;if(!t)return;let n=e??PN(t);if(!RN(n)){G(`following`);return}b.current!==`released`&&(G(`released`),oe(n))}),fe=q((e=`instant`)=>{if(V.current=!1,G(`following`),re(),e===`instant`){ce();return}se(),ue(!0,`smooth`),oe()}),pe=q(()=>{V.current=!1,ue(!0)}),me=q(()=>{se(),re(),G(`released`),oe()}),he=q(()=>{V.current=!0,me()}),ge=q(()=>{V.current=!1}),_e=Z.useRef(s);_e.current=s;let ve=q(()=>{MN(NN(),P.current)||(se(),re(),de())}),ye=q(()=>{ve(),_e.current?.()}),be=q(()=>{H.current!==null&&(clearTimeout(H.current),H.current=null);let e=U.current;if(e){if(!e.identity.sessionId){U.current=null;return}ee(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),U.current=null}}),xe=q(()=>{let e=C.current;if(!e.sessionId)return;let t=c.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r>0?(n+i/2)/r:0,o=Math.floor(a*S.current);U.current=xN(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),H.current===null&&(H.current=setTimeout(()=>{H.current=null,be()},wN))}),Se=q(()=>{be()}),Ce=q(async(e=C.current)=>{if(!e.sessionId)return!1;V.current=!1;let t=Ui(e.sessionId,e.viewportKey);return c.current?(W.current=null,I.current=t?.scrollPosition?.scrollTop??0,G(`following`),F(),x.current?ce():ue(!0),ae(),oe(),!1):(W.current=e,G(`following`),!1)});Z.useEffect(()=>{let e=C.current,n=w.current;yN(e,n)||(be(),se(),F(),w.current=e,T.current=null,I.current=0,re(),V.current=!1,G(`following`),W.current=null,t&&t!==n?.sessionId&&Jb.getInstance().recordSessionStart(t))},[t,n]),Z.useEffect(()=>{i&&!V.current&&b.current===`following`&&ue(!0)},[i]),Z.useEffect(()=>{y(f===`following`&&i)},[f,i]),Z.useLayoutEffect(()=>{if(!l)return;let e=W.current;e&&bN(e,C.current)&&Ce(e)},[l,t,n]);let we=q(()=>{let e=c.current;if(!e)return;let t=PN(e),n=I.current;I.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(oe(t),V.current){xe();return}if(!RN(t)){G(`following`);return}if(zN(t,x.current)){let e=IN(t)<=EN;(r||b.current===`following`||e)&&G(`following`),xe();return}if(b.current===`following`&&(te(e)||ne()||i)){j.current||ue(!1),xe();return}de(t),xe()});Z.useEffect(()=>{!e||!l||(I.current=l.scrollTop)},[l,e]);let Te=Z.useRef(null),Ee=q(e=>{let t=c.current;t&&(e.deltaY>=0||hN(t,e.target)||ye())}),De=q(e=>{let t=e.touches.item(0);Te.current=t?t.clientY:null}),Oe=q(e=>{let t=c.current,n=e.touches.item(0);if(!n){Te.current=null;return}let r=Te.current;Te.current=n.clientY,r!==null&&(n.clientY-r<=2||t&&(hN(t,e.target)||ye()))}),ke=q(()=>{Te.current=null}),Ae=q(e=>{mN(e)&&ye()}),je=q(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&ve()}),Me=Z.useMemo(()=>()=>void 0,[]),Ne=e&&l?l:Me,Pe=Z.useMemo(()=>({passive:!0}),[]);it(`scroll`,we,Ne,Pe),it(`wheel`,Ee,Ne,Pe),it(`touchstart`,De,Ne,Pe),it(`touchmove`,Oe,Ne,Pe),it(`touchend`,ke,Ne,Pe),it(`touchcancel`,ke,Ne,Pe),it(`keydown`,Ae,Ne),it(`pointerdown`,je,e&&typeof window<`u`?window:Me,!0);let Fe=q(()=>{let e=c.current;if(j.current){oe(e?PN(e):void 0);return}if(V.current){oe(e?PN(e):void 0);return}if(!e){oe(void 0);return}let t=PN(e);if(!RN(t)){G(`following`),oe(t);return}if(oe(t),L.current){let n=t.scrollHeight>B.current+1;B.current=t.scrollHeight,IN(t)<=EN?K(e):ue(!0),n&&ie();return}if(b.current===`following`){if(IN(t)<=EN){K(e);return}ue(!1)}}),Ie=typeof ResizeObserver<`u`,Le=Ie&&e?l:null,Re=Ie&&e&&l&&l.firstElementChild instanceof Element?l.firstElementChild:null;at(Le,Fe),at(Re,Fe);let ze=q(()=>{N.current!==null&&(clearTimeout(N.current),N.current=null)}),Be=q(e=>{j.current=!0,typeof e==`number`&&e>0?A.current=NN()+e+DN:A.current=Math.max(A.current,NN()+DN)}),Ve=q(e=>{let t=e.detail;if(t){if(t.open===!0){Be(),ze(),N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},1500);return}ze(),Be()}}),He=q(e=>{let t=e.detail;t&&(ze(),Be(t.durationMs))}),Ue=q(e=>{let t=e.detail;ze(),t?.open===!0?(M.current=!0,j.current=!0):(M.current=!1,j.current=!0,N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},DN)),oe()}),We=e&&typeof window<`u`?window:Me;it(`oc:keyboard-intent`,Ve,We),it(`oc:keyboard-anim`,He,We),it(`oc:keyboard-settled`,Ue,We),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{ze(),j.current=!1,M.current=!1}},[e]),Z.useEffect(()=>{e&&oe()},[e,r]);let Ge=q(t=>{if(e){if(t===`animation`&&(A.current=NN()+DN),oe(),L.current){ue(!0),ie();return}b.current===`following`&&ue(!1)}}),Ke=Z.useRef(new Map),qe=q(t=>{let n=Ke.current.get(t);if(n)return n;let r=()=>{e&&b.current===`following`&&ue(!1)},i={onChunk:r,onComplete:()=>{e&&oe()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return Ke.current.set(t,i),i});Z.useEffect(()=>()=>{E.current&&=(clearTimeout(E.current),null),se(),re(),be(),H.current!==null&&(clearTimeout(H.current),H.current=null)},[]);let Je=q(e=>{o?.(e)}),Ye=!!o;return Z.useEffect(()=>{if(!e||!Ye)return;let t=l;if(!t)return;let n=null,r=pN({onActive:e=>{e!==n&&(n=e,Je(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 u=()=>r.onScroll();return t.addEventListener(`scroll`,u,{passive:!0}),()=>{t.removeEventListener(`scroll`,u),c.disconnect(),r.destroy()}},[l,e,Ye]),{scrollRef:c,state:f,isPinned:f===`following`,isOverflowing:m,isFollowingProgrammatically:v,showScrollButton:g,notifyContentChange:Ge,getAnimationHandlers:qe,goToBottom:fe,scrollToBottomOnSend:pe,releaseAutoFollow:me,beginHistoryViewportPreservation:he,endHistoryViewportPreservation:ge,saveSnapshotNow:Se,restoreSnapshot:Ce}},VN=`--oc-mobile-composer-swap`,HN=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),UN=(e,t,n)=>Math.min(n,Math.max(t,e)),WN=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,GN=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return WN(e,n)?e:n},KN=e=>Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),qN=(e,t)=>t?GN(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?GN(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,JN=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:GN(e,{phase:`snapping`,rest:t,progress:n})},YN=e=>UN(e/80,0,1),XN=e=>e>=80?1:UN(e/80,0,1),ZN=(e,t,n={})=>{if(e.pinned)return e;let r=Math.max(0,t),i=e.phase===`snapping`?GN(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(i.rest===`expanded`){if(r<=2||n.holdExpanded)return GN(i,{phase:`rest`,rest:`expanded`,progress:0});let e=YN(r);return e>=1?GN(i,{phase:`rest`,rest:`compact`,progress:1}):GN(i,{phase:`tracking`,rest:`expanded`,progress:e})}if(r<=2)return GN(i,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn)return GN(i,{phase:`rest`,rest:`compact`,progress:1});if(n.towardBottom&&r>=80)return GN(i,{phase:`snapping`,rest:`expanded`,progress:0});let a=XN(r);return a>=1?GN(i,{phase:`rest`,rest:`compact`,progress:1}):GN(i,{phase:`tracking`,rest:`compact`,progress:a})},QN=e=>e.pinned?`expanded`:e.rest===`expanded`?e.progress>=.5?`compact`:`expanded`:e.progress<=.5?`expanded`:`compact`,$N=e=>{if(e.pinned)return GN(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let t=QN(e),n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:GN(e,{phase:`snapping`,rest:t,progress:n})},eP=e=>e.phase===`snapping`?GN(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,tP=e=>{e.style.removeProperty(VN),delete e.dataset.ocComposerSwapPhase,delete e.dataset.ocComposerSwapRest},nP=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest;return n?.phase!==i&&(e.dataset.ocComposerSwapPhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty(VN,r),n?.rest!==a&&(e.dataset.ocComposerSwapRest=a),{progress:r,phase:i,rest:a}},rP=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),iP=()=>{let e=document.documentElement;return e.classList.contains(`oc-keyboard-open`)||e.classList.contains(`oc-kb-animating`)},aP=e=>{if(iP()||e.querySelector(`[data-oc-composer-dictation-active="true"]`))return!0;let t=document.activeElement;return t instanceof HTMLElement&&t.matches(`textarea[data-chat-input="true"]`)&&e.contains(t)},oP=e=>{let t=Z.useRef(HN()),n=Z.useRef(void 0),r=Z.useRef(null),i=Z.useRef(null),a=Z.useRef(0),o=Z.useRef(!1),s=Z.useRef(0),c=Z.useRef(null),l=Z.useRef(0),u=Z.useRef(0),d=Z.useRef(!1),f=Z.useRef(e.enabled);f.current=e.enabled;let p=e=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null)},m=q(t=>{let r=e.scopeRef.current;r&&(n.current=nP(r,t,n.current))}),h=q(e=>{e!==t.current&&(t.current=e,m(e))}),g=q(()=>{if(p(i),t.current.phase!==`snapping`)return;let e=t.current.rest;i.current=window.setTimeout(()=>{i.current=null;let n=eP(t.current);h(n),n.rest===`compact`&&e===`compact`&&(a.current=Date.now()+320,o.current=!0)},240)}),_=q(()=>{let n=e.scopeRef.current;!n||!f.current||h(qN(t.current,aP(n)))}),v=q(e=>o.current?Date.now()>=a.current?(o.current=!1,!1):e>=80?(o.current=!1,a.current=0,!1):!0:!1),y=q(()=>{if(p(r),!f.current||s.current>0||t.current.phase!==`tracking`)return;let e=$N(t.current);h(e),g()}),b=q(()=>{f.current&&(s.current+=1,p(r))}),x=q(()=>{if(!f.current)return;let n=e.scrollRef.current,i=e.scopeRef.current;if(!n||!i)return;let a=aP(i),o=rP(n),m=KN(o),_=c.current;c.current=m;let b=_===null?0:_-m;b>0?(u.current=0,o.scrollTop>0&&(l.current+=b)):b<0&&(l.current=0,u.current+=-b,u.current>=24&&(d.current=!1)),m<=2&&(d.current=!1);let x=qN(t.current,a);if(!a){let e=x.rest===`compact`;x=ZN(x,m,{suppressReturn:v(m),towardBottom:l.current>=24,holdExpanded:d.current}),e&&x.rest===`expanded`&&m>2&&(d.current=!0,l.current=0)}if(h(x),p(r),x.phase===`snapping`){g();return}x.phase===`tracking`&&s.current===0&&(r.current=window.setTimeout(()=>{r.current=null,y()},120))}),S=q(()=>{y()}),C=q(()=>{f.current&&(s.current=Math.max(0,s.current-1),!(s.current>0)&&t.current.phase===`tracking`&&(p(r),r.current=window.setTimeout(()=>{r.current=null,y()},120)))}),w=q(()=>{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)}),T=q(n=>{if(!f.current)return;let r=n.target;r instanceof Element&&r.closest(`[data-oc-composer-compact-surface="true"]`)&&(r.closest(`[data-composer-action="true"]`)||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),d.current=!0,l.current=0,u.current=0,h(JN(t.current,`expanded`)),g(),w(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0})))}),[E,D]=Z.useState(null),[O,k]=Z.useState(null),A=Z.useRef(null),j=q(e=>{e&&tP(e),n.current=void 0,o.current=!1,a.current=0,s.current=0,c.current=null,l.current=0,u.current=0,d.current=!1,h(HN())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;A.current&&A.current!==n&&j(A.current),A.current=n,D(e=>e===t?e:t),k(e=>e===n?e:n)});let M=Z.useMemo(()=>()=>void 0,[]),N=e.enabled&&E?E:M,P=e.enabled&&O?O:M,F=e.enabled&&typeof window<`u`?window:M,I=Z.useMemo(()=>({passive:!0}),[]);it(`scroll`,x,N,I),it(`scrollend`,S,N,I),it(`touchstart`,b,N,I),it(`touchend`,C,N,I),it(`touchcancel`,C,N,I),it(`pointerdown`,T,P),it(`focusin`,_,P),it(`focusout`,_,P),it(`oc:keyboard-intent`,_,F),it(`oc:keyboard-anim`,_,F),it(`oc:keyboard-settled`,_,F),Z.useEffect(()=>{if(!e.enabled){j(A.current),A.current=null;return}return _(),x(),()=>{p(r),p(i)}},[e.enabled,E,O])},sP=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},cP=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},lP=e=>{if(!e)return null;let t=sP(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${cP(e)??``}`},uP=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}),dP=(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&&lP(t[r])===lP(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=sP(r),a=r.info.id,o=uP(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=cP(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},fP=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=sP(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=cP(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}},pP=200,mP={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},hP=()=>pP,gP=()=>Math.round(hP()*.6),_P={MAX_SESSIONS:mP.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(pP*.6),HISTORICAL_MESSAGES:pP,FETCH_BUFFER:20,HISTORY_CHUNK:pP,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:mP.ZOMBIE_TIMEOUT},vP=()=>{let e=hP(),t=gP();return{..._P,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},yP=_P,bP=600,xP=6e3,SP=.5,CP=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),wP=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},TP=(e,t)=>{let n=CP(e,t);if(n||=wP(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}},EP=e=>{let{container:t,quiesceMs:n=bP,maxLifetimeMs:r=xP}=e,i={messageId:e.anchor.messageId,offsetTop:e.anchor.offsetTop},a=!1,o=null,s=null,c=!1,l=t.scrollTop,u=()=>{o!==null&&(clearTimeout(o),o=null)},d=()=>{s!==null&&(clearTimeout(s),s=null)},f=()=>{a||(a=!0,y.disconnect(),t.removeEventListener(`scroll`,v),u(),d())},p=()=>{u(),!a&&(o=setTimeout(()=>{o=null,f()},n))},m=()=>{d(),!a&&(s=setTimeout(()=>{s=null,f()},r))},h=()=>{if(a)return;let e=TP(t,i.messageId);if(!e){f();return}i.messageId=e.messageId,i.offsetTop=e.offsetTop,l=t.scrollTop},g=()=>{if(a)return;if(Math.abs(t.scrollTop-l)>SP){h();return}let e=CP(t,i.messageId);if(!e){let n=wP(t);if(!n){f();return}let r=n.dataset.messageId;if(!r){f();return}let a=t.getBoundingClientRect();i.messageId=r,i.offsetTop=n.getBoundingClientRect().top-a.top,e=n,l=t.scrollTop}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect().top-n.top-i.offsetTop;Math.abs(r)>SP&&(t.scrollTop+=r),l=t.scrollTop},_=()=>{a||c||(c=!0,queueMicrotask(()=>{c=!1,g()}))},v=()=>{h(),p(),m()},y=new MutationObserver(()=>{a||(_(),p())});return y.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`style`,`class`]}),t.addEventListener(`scroll`,v,{passive:!0}),m(),p(),{rebase:h,dispose:f}},DP=30,OP=1200,kP=1.5,AP=e=>Math.max(OP,e*kP),jP=4,MP=30,NP=4,PP=30,FP=250,IP=2e3,LP=gn+2e3,RP=40,zP=`history-loading-timeout`,BP=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),VP=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=zP,e},HP=(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)},UP=2500,WP=new Map,GP=()=>d()?jP:Zi()?NP:DP,KP=e=>d()?e.length<=MP:!Zi()||e.length<=PP,qP=(e,t)=>{if(WP.delete(e),!KP(t.messages))return;let n=GP();for(;WP.size>=n;){let e=WP.keys().next().value;if(typeof e!=`string`)break;WP.delete(e)}WP.set(e,t)},JP=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),YP=e=>e?{owner:`tanstack-core`}:{owner:`controller`},XP=(e,t)=>e?e.canLoadEarlier:t>=vP().HISTORICAL_MESSAGES,ZP=e=>!(e.isMobile||e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=AP(e.clientHeight)),QP=e=>e.pagesLoaded>=e.maxPages?`stop-bounded`: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.limitAfter>e.limitBefore?`continue`:`stop-no-growth`:`stop-exhausted`,$P=1,eF=8,tF=e=>!(!e.enabled||e.isMobile||!e.sessionReady||!e.messageReady||e.historyLoading||!e.canLoadEarlier||!e.isPinned||e.fillBlocked||e.pendingRevealWork||e.isLoadingOlder||!e.hasMessages||e.clientHeight<=0||e.scrollHeight>e.clientHeight+48),nF=e=>[`chat-timeline-auto-fill`,e.runtimeKey,e.sessionId,e.oldestMessageId,e.messageCount,e.canLoadEarlier],rF=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],iF=20,aF=4,oF=80,sF=new WeakMap,cF=new WeakMap,lF=e=>{let t=cF.get(e)??{generation:0};return t.generation+=1,cF.set(e,t),t.generation},uF=e=>{let t=sF.get(e);t&&(t.touches=0,t.pending=null,t.settleScheduled=!1),lF(e)},dF=e=>{fF(e)},fF=e=>{let t=sF.get(e);if(t)return t;let n={touches: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&&pF(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),sF.set(e,n),n},pF=(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+oF||mF(e,n.anchorTop+n.delta))}))},mF=(e,t)=>{let n=lF(e),r=e.style.overflow;if(e.style.overflow=`hidden`,e.scrollTop=t,e.scrollHeight,e.style.overflow=r,e.scrollTop=t,typeof window>`u`)return;let i=!1,a=0,o=()=>{i=!0};e.addEventListener(`touchstart`,o,{passive:!0,once:!0});let s=()=>{if(!i){if((cF.get(e)?.generation??0)!==n){e.removeEventListener(`touchstart`,o);return}e.scrollTop<t-aF&&(e.scrollTop=t),a+=1,a<iF?window.requestAnimationFrame(s):e.removeEventListener(`touchstart`,o)}};window.requestAnimationFrame(s)},hF=(e,t,n)=>{let r=fF(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,mF(e,t)},gF=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),_F=(e,t)=>e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight?e:t,vF=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:a,messageListRef:o,loadMoreMessages:s,goToBottom:c,releaseAutoFollow:l,beginHistoryViewportPreservation:u,endHistoryViewportPreservation:d,isPinned:f,showScrollButton:p,autoFillEnabled:m=!1})=>{let h=Z.useRef(null),g=Z.useRef(null),_=Z.useMemo(()=>{let t=e??``,r=t?WP.get(t):void 0;if(r&&r.messages===n)return qP(t,r),h.current=r.model,g.current=n,r.model;let i=dP(h.current,g.current,n)??fP(n);return h.current=i,g.current=n,t&&n.length>0&&qP(t,{messages:n,model:i}),i},[n,e]),[v,y]=Z.useState(!1),[b,x]=Z.useState(!1),[S,C]=Z.useState(null),[w,T]=Z.useState(!1),[E,D]=Z.useState(null),[O,k]=Z.useState({scrollHeight:0,clientHeight:0}),A=Z.useRef(_),j=Z.useRef(f),M=Z.useRef(v),N=Z.useRef(b),P=Z.useRef(e),F=Z.useRef(t??null),I=Z.useRef(n),L=Z.useRef(r),R=Z.useRef(E),z=Z.useRef([]),B=Z.useRef(null),V=Z.useRef(null),H=Z.useRef(!1),U=Z.useRef(null),[W,ee]=Z.useState(e);W!==e&&(ee(e),U.current!==null&&typeof window<`u`&&(window.clearTimeout(U.current),U.current=null),H.current=!1,M.current=!1,V.current=null,y(!1),x(!1),C(null),T(!1),R.current=null,D(null),k({scrollHeight:0,clientHeight:0}));let G=Z.useMemo(()=>{let e=r?.limit!==E&&XP(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),K=Z.useRef(G);A.current=_,j.current=f,N.current=b,K.current=G,P.current=e,F.current=t??null,I.current=n,L.current=r,R.current=E;let te=q(()=>{H.current=!0,U.current!==null&&typeof window<`u`&&(window.clearTimeout(U.current),U.current=null)}),ne=q(()=>{if(typeof window>`u`){H.current=!1;return}U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,H.current=!1},IP)}),re=q(()=>{let e=z.current;e.length!==0&&(z.current=[],e.forEach(e=>e()))}),ie=q(()=>new Promise(e=>{if(typeof window>`u`){e();return}let t=!1,n=()=>{t||(t=!0,window.clearTimeout(r),e())};z.current.push(n);let r=window.setTimeout(n,FP)})),ae=q(e=>{let t=B.current;t&&(B.current=null,t.resolve(e))}),oe=q(()=>{let e=B.current;if(e){if(e.sessionId!==P.current){ae(!1);return}if(e.kind===`turn`?o.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:o.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(V.current={turnId:e.turnId,expiresAt:Date.now()+UP},C(e.turnId)),ae(!0);return}typeof(e.kind===`turn`?A.current.turnIndexById.get(e.id):A.current.messageToTurnIndex.get(e.id))==`number`&&ae(!1)}}),se=Z.useRef(null),ce=q(()=>{let e=se.current;e&&(se.current=null,e.dispose())});et(()=>{U.current!==null&&typeof window<`u`&&(window.clearTimeout(U.current),U.current=null),ce(),re(),ae(!1)});let le=n;rt(()=>{re(),oe()},[le]);let ue=q(()=>{let e=a.current;if(!e){k(e=>_F(e,{scrollHeight:0,clientHeight:0}));return}k(t=>_F(t,{scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))});at(typeof ResizeObserver<`u`?a:null,ue),rt(()=>{ue()},[e,v]);let de=Z.useRef(null),fe=q(()=>o.current?.captureViewportAnchor()??null),pe=q(e=>o.current?.restoreViewportAnchor(e)??!1),me=q(()=>{if(Zi())return;ce();let e=a.current;if(!e)return;let t=fe();t&&(se.current=EP({container:e,anchor:t}))}),he=Z.useRef(null);rt(()=>{if(!Zi())return;let e=a.current;e&&(dF(e),uF(e))},[e,a]),rt(()=>{ce(),de.current=null,he.current=null,o.current?.cancelViewportAnchorHold()},[e]),rt(()=>{let e=a.current;if(!e)return;let t=de.current;t&&Math.abs(e.scrollTop-t.top)>eF&&(de.current=null,t=null);let n=he.current,r=le[0]?.info?.id??null,i=le[le.length-1]?.info?.id??null,s=n?JP({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:i})||gF(n.oldestId,r,le):!1;t&&t.sessionId!==P.current&&(de.current=null,t=null);let l=t?JP({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:i})||gF(t.oldestId,r,le):!1,u=s||l,d=e=>{he.current={oldestId:r,newestId:i,scrollHeight:e??he.current?.scrollHeight??0}};if(j.current&&!t){ce(),u?(de.current=null,c(`instant`),d(e.scrollHeight)):d();return}let f=YP(o.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){o.current?.cancelViewportAnchorHold();let e=t.anchor;e&&pe(e),d();return}let n=e.scrollHeight,r=n-t.height;if(Zi()){r>0&&hF(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&pe(i))&&r>0&&(e.scrollTop=t.top+r),d(n);return}if(s&&n&&f.owner===`controller`){let t=e.scrollHeight,r=t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;Zi()?hF(e,t,r):e.scrollTop=t}d(t),me();return}d()},[le,c]);let ge=q(async()=>!1),_e=q(async e=>{let t=Date.now(),n=t+LP,r=F.current,i=r?Fn()?.getRequestState?.(ht(r,e)):void 0;for(K.current.historyLoading,L.current,i?.status,i?.error;K.current.historyLoading;){if(P.current!==e)return Date.now()-t,`switched`;if(Date.now()>=n){let n=r?Fn()?.getRequestState?.(ht(r,e)):void 0;return console.error(`[chat-history] historyLoading wait timed out — sync flag still true`,{sessionId:e,directory:r,elapsedMs:Date.now()-t,waitMs:LP,hostTurnPageTimeoutMs:gn,historyLoading:K.current.historyLoading,historyMeta:L.current,requestStatusAtStart:i?.status??null,requestStatusAtTimeout:n?.status??null,requestErrorAtTimeout:n?.error??null,likelyStaleLoadingFlag:n?.status===`ready`||n?.status===`error`||n==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,RP)})}return Date.now()-t,r&&Fn()?.getRequestState?.(ht(r,e))?.status,P.current===e?`cleared`:`switched`}),ve=q(async e=>{if(!P.current||M.current||!K.current.hasMoreAboveTurns)return!1;M.current=!0,te(),y(!0);let t=P.current,n=null,r=!!e.userInitiated;r&&u();let i=()=>{n&&de.current===n&&(de.current=null,o.current?.cancelViewportAnchorHold()),r&&(r=!1,d())};try{if(K.current.historyLoading){if(!e.userInitiated)return!1;let n=await _e(t);if(n===`timeout`)throw VP();if(n===`switched`||!K.current.hasMoreAboveTurns)return!1}if(!P.current||P.current!==t)return!1;let r=a.current,o=I.current,c=o.length,l=o[0]?.info?.id??null,u=L.current?.limit??vP().HISTORICAL_MESSAGES;e.preserveViewport&&r&&(n={sessionId:P.current,height:r.scrollHeight,top:r.scrollTop,anchor:fe(),oldestId:l,newestId:o[o.length-1]?.info?.id??null},de.current=n,me());let d=c,f=l,p=u,m=0;for(;;){if(K.current.historyLoading)if(e.userInitiated){let e=await _e(t);if(e===`timeout`)throw i(),VP();if(e===`switched`)return i(),!1}else return i(),!1;let n=a.current?.scrollHeight??0,r=d,o=f,c=p;if(await s(t,`up`),m+=1,P.current!==t)return i(),!1;await ie();let l=I.current,u=l.length,h=l[0]?.info?.id??null,g=L.current?.limit??p,_=QP({scrollHeightBefore:n,scrollHeightAfter:a.current?.scrollHeight??n,messageCountBefore:r,messageCountAfter:u,oldestIdBefore:o,oldestIdAfter:h,limitBefore:c,limitAfter:g,hasMoreAbove:K.current.hasMoreAboveTurns,pagesLoaded:m,maxPages:$P});if(_===`continue`){d=u,f=h,p=g;continue}if(_===`stop-no-growth`){if(K.current.historyLoading){if(e.userInitiated){let e=await _e(t);if(e===`timeout`)throw i(),VP();if(e===`switched`)return i(),!1;--m;continue}return i(),!1}let n=L.current?.limit??c;return R.current=n,D(n),K.current={...K.current,hasMoreAboveTurns:!1,canLoadEarlier:!1},i(),!1}return!0}}catch(e){throw i(),e}finally{M.current=!1,y(!1),ne(),ie().then(i)}}),{t:ye}=ot(),be=Ke({mutationKey:rF({runtimeKey:i(),sessionId:e??``}),mutationFn:async e=>{if(P.current!==e.sessionId)return!1;te(),e.userInitiated&&l();try{return await ve({preserveViewport:!0,userInitiated:!!e.userInitiated})}finally{ne()}}}),xe=q(async e=>{let t=P.current;if(t&&!(be.isPending&&be.variables?.sessionId===t))try{let n=await be.mutateAsync({sessionId:t,userInitiated:!!e?.userInitiated});if(n===!1&&K.current.canLoadEarlier){let r={sessionId:t,grew:n,userInitiated:!!e?.userInitiated,canLoadEarlier:K.current.canLoadEarlier,hasMoreAboveTurns:K.current.hasMoreAboveTurns,historyLoading:K.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null};HP(`no-growth`,Error(`chat history pagination returned no growth`),r),e?.userInitiated&&Cr.error(ye(`chat.history.loadOlderFailed`))}}catch(n){let r={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:LP,hostTurnPageTimeoutMs:gn,canLoadEarlier:K.current.canLoadEarlier,historyLoading:K.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null};BP(n)?HP(`timeout`,n,r):HP(`failed`,n,r),e?.userInitiated&&Cr.error(BP(n)?ye(`chat.history.loadOlderTimeout`):ye(`chat.history.loadOlderFailed`))}}),Se=be.isPending&&be.variables?.sessionId===e||v,Ce=n[0]?.info?.id??null,we=tF({enabled:m,isMobile:Zi(),sessionReady:!!e,messageReady:n.length>0||!!r,historyLoading:G.historyLoading,canLoadEarlier:G.canLoadEarlier,isPinned:f,fillBlocked:w,scrollHeight:O.scrollHeight,clientHeight:O.clientHeight,pendingRevealWork:b,isLoadingOlder:!1,hasMessages:n.length>0});qe({queryKey:nF({runtimeKey:i(),sessionId:e??``,oldestMessageId:Ce,messageCount:n.length,canLoadEarlier:G.canLoadEarlier}),enabled:!!e&&we,staleTime:1/0,gcTime:0,retry:(e,t)=>t?.code===`auto-fill-busy`&&e<40,retryDelay:50,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,queryFn:async()=>{let e=P.current;if(!e)return{status:`skip`};if(K.current.historyLoading||M.current){let e=Error(`auto-fill-busy`);throw e.code=`auto-fill-busy`,e}if(!K.current.canLoadEarlier)return{status:`skip`};let t=a.current;if(!t||t.clientHeight<=0)return{status:`skip`};if(t.scrollHeight>t.clientHeight+48)return{status:`tall`};try{let t=await ve({preserveViewport:!0});return t?{status:`grew`}:(K.current.canLoadEarlier&&HP(`no-growth`,Error(`chat history pagination returned no growth`),{sessionId:e,source:`auto-fill`,grew:t,canLoadEarlier:K.current.canLoadEarlier,hasMoreAboveTurns:K.current.hasMoreAboveTurns,historyLoading:K.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null}),T(!0),{status:`blocked`})}catch(t){if(t?.code===`auto-fill-busy`)throw t;let n={sessionId:e,source:`auto-fill`,waitMs:LP,canLoadEarlier:K.current.canLoadEarlier,historyLoading:K.current.historyLoading,historyMeta:L.current,messageCount:I.current.length,oldestMessageId:I.current[0]?.info?.id??null};throw BP(t)?HP(`timeout`,t,n):HP(`failed`,t,n),T(!0),t instanceof Error?t:Error(`chat timeline auto-fill failed`)}}});let Te=q(e=>{let t=a.current;t&&ZP({source:e,isMobile:Zi(),isPinned:j.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:K.current.canLoadEarlier,isLoadingOlder:M.current,pendingRevealWork:N.current})&&xe({userInitiated:!0})}),Ee=q(()=>{Te(`scroll`)}),De=q(()=>{Te(`upward-intent`)}),Oe=q(async(t,n)=>{if(!t||!P.current)return!1;l(),x(!0);try{return P.current!==e||typeof A.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{B.current={sessionId:P.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},oe()})}finally{x(!1)}}),ke=q(async(t,n)=>{if(!t||!P.current)return!1;l(),x(!0);try{if(P.current!==e)return!1;let r=A.current.messageToTurnId.get(t);return typeof A.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(i=>{B.current={sessionId:P.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:r??null,resolve:i},oe()})}finally{x(!1)}}),Ae=q(async()=>{x(!1),M.current=!1,y(!1),c(`smooth`)}),je=q(async()=>{x(!1),M.current=!1,y(!1),c(`instant`)}),Me=q(e=>{let t=V.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;V.current=null}C(e)});return{turnIds:_.turnIds,turnStart:0,renderedMessages:le,historySignals:G,isLoadingOlder:Se,pendingRevealWork:b,activeTurnId:S,showScrollToBottom:p&&!b,turnWindowModel:_,loadEarlier:xe,revealBufferedTurns:ge,resumeToBottom:Ae,resumeToBottomInstant:je,scrollToTurn:Oe,scrollToMessage:ke,handleHistoryScroll:Ee,handleHistoryUpwardIntent:De,captureViewportAnchor:fe,restoreViewportAnchor:pe,handleActiveTurnChange:Me}},yF=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),bF=({open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s=!1,isLoadingEarlier:c=!1,onLoadEarlier:l,onRevertMessage:u})=>{let{t:d}=ot(),f=Qm(),p=n,m=di(p??``,r),h=Qr(e=>e.revertToMessage),g=Qr(e=>e.forkFromMessage),_=yF(f.capabilities),{isMobile:v,isTablet:y}=fo(),b=v||y,[x,S]=Z.useState(null),C=Z.useRef(!1),[w,T]=Z.useState(``),[E,D]=Z.useState(0),O=Z.useRef([]),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(!1),M=Z.useRef(e),N=e=>new Date(e).toLocaleDateString(st(),{year:`numeric`,month:`short`,day:`numeric`}),P=e=>new Date(e).toLocaleTimeString(st(),{hour:`numeric`,minute:`2-digit`}),F=Z.useMemo(()=>m.filter(e=>e.info.role===`user`).map(e=>({message:e})),[m]),I=Z.useMemo(()=>{let e=w.trim();if(!e)return F;let t=e.toLowerCase();return F.filter(({message:e})=>HM(e.parts).toLowerCase().includes(t))},[F,w]);Z.useEffect(()=>{j.current||D(w.trim()?0:Math.max(0,I.length-1))},[I,w]),Z.useEffect(()=>{O.current=O.current.slice(0,I.length)},[I.length]),Z.useEffect(()=>{j.current||O.current[E]?.scrollIntoView({block:`nearest`})},[E]),Z.useEffect(()=>{!j.current||A.current||c||(j.current=!1)},[I.length,c]),Z.useLayoutEffect(()=>{let t=M.current;if(M.current=e,!e||t||j.current||w.trim())return;let n=k.current;n&&(n.scrollTop=n.scrollHeight)},[e,w]),Z.useLayoutEffect(()=>{let e=A.current,t=k.current;if(!e||!t||c)return;A.current=null;let n=O.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},[I.length,c]);let L=q(()=>{let e=k.current;if(e){let t=e.getBoundingClientRect().top,n=O.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(A.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}j.current=!0,l?.()}),R=q(async e=>{await i?.(e)!==!1&&t(!1)}),z=q(e=>{let t=I.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),D(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),D(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(E%t+t)%t,r=I[n];r&&R(r.message.info.id)}}}),B=q(async(e,n)=>{if(!(!p||C.current)){C.current=!0,S({type:e,messageId:n});try{e===`revert`?u?await u(n):await h(p,n,{directory:r}):await g(p,n,{directory:r}),t(!1)}finally{C.current=!1,S(null)}}});return p?(0,$.jsx)(ca,{open:e,onOpenChange:t,children:(0,$.jsxs)(ia,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(na,{children:[(0,$.jsxs)(aa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),d(`chat.timeline.title`)]}),(0,$.jsx)(oa,{children:d(`chat.timeline.description`)})]}),(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)(Fa,{autoFocus:!0,placeholder:d(`chat.timeline.searchPlaceholder`),value:w,onChange:e=>T(e.target.value),onKeyDown:z,className:`pl-9 w-full`})]}),s&&l&&(0,$.jsx)(`div`,{className:`flex justify-center py-1`,children:(0,$.jsxs)(la,{type:`button`,variant:`link`,size:`sm`,onClick:L,disabled:c,className:`h-auto px-1 py-0 text-muted-foreground hover:text-foreground`,children:[c&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),d(`chat.history.loadOlder`)]})}),(0,$.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto`,children:I.length===0?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:d(w?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):I.map(({message:e},t)=>{let n=UM(e.parts),r=e.info.time.created,i=N(r),a=I[t-1],o=i!==(a?N(a.message.info.time.created):null),s=P(r),c=t===E,l=w.trim()?xF(HM(e.parts),w):null;return(0,$.jsxs)(Z.Fragment,{children:[o&&(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:i}),(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`})]}),(0,$.jsxs)(`div`,{ref:e=>{O.current[t]=e},"data-timeline-message-id":e.info.id,className:Y(`group flex items-center gap-3 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,c&&`bg-interactive-selection text-interactive-selection-foreground`),onClick:()=>void R(e.info.id),onMouseEnter:()=>D(t),children:[(0,$.jsx)(`span`,{className:Y(`typography-meta w-16 flex-shrink-0 text-right tabular-nums`,c?`text-interactive-selection-foreground/70`:`text-muted-foreground`),children:s}),(0,$.jsxs)(`p`,{className:Y(`flex-1 min-w-0 typography-micro truncate`,c?`text-interactive-selection-foreground`:`text-foreground`),children:[l??(n||d(`chat.timeline.noTextContent`)),!l&&n&&n.length>=80&&`…`]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:(0,$.jsxs)(`div`,{className:Y(`gap-1`,b?`flex`:`hidden group-hover:flex`),children:[_.revert?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`revert`&&x.messageId===e.info.id,disabled:x!==null,onClick:t=>{t.stopPropagation(),B(`revert`,e.info.id)},children:(0,$.jsx)(X,{name:x?.type===`revert`&&x.messageId===e.info.id?`loader-4`:`arrow-go-back`,className:Y(`h-4 w-4`,x?.type===`revert`&&x.messageId===e.info.id&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:d(`chat.timeline.actions.revertFromHere`)})]}):null,_.fork?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(la,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`fork`&&x.messageId===e.info.id,onClick:t=>{t.stopPropagation(),B(`fork`,e.info.id)},disabled:x!==null,children:x?.type===`fork`&&x.messageId===e.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)(La,{sideOffset:6,children:d(`chat.timeline.actions.forkFromHere`)})]}):null]})})]})]},e.info.id)})}),(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:d(`chat.timeline.actions.title`)}),(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{a?.(-1),t(!1)},children:d(`chat.timeline.actions.previousTurn`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{o?.(),t(!1)},children:d(`chat.timeline.actions.latest`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:d(`chat.timeline.help.clickMessage`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`arrow-go-back`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:d(`chat.timeline.help.undoToPoint`)})]}),_.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:d(`chat.timeline.help.createSessionFromHere`)})]}):null]})]})]})}):null};function xF(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?`…`:``}`}var SF=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},CF=(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`}},wF=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)},TF=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&&wF(`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&&wF(`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=CF(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 wF(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=()=>{wF(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=SF(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},EF=2e4,DF=6e4,OF=2e3,kF=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,AF=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+=kF(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},jF={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},MF=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:jF,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}},NF=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)},PF=(e,t)=>{let n=(0,Q.c)(7),r=Zb(FF),i=Qr(IF),a=Qr(LF),o,s;n[0]!==a||n[1]!==i||n[2]!==t||n[3]!==r||n[4]!==e?(o=()=>{if(r&&e&&!a(e)){for(let n of t)if(n.info.role===`assistant`)for(let t of n.parts){let n=t;if(n.type!==`text`)continue;let r=n.text||``;if(r.includes(`The plan at `)||r.includes(`User has requested to enter plan mode`)){i(e);return}}}},s=[r,e,t,i,a],n[0]=a,n[1]=i,n[2]=t,n[3]=r,n[4]=e,n[5]=o,n[6]=s):(o=n[5],s=n[6]),Z.useEffect(o,s)};function FF(e){return e.planModeEnabled}function IF(e){return e.markSessionPlanAvailable}function LF(e){return e.isSessionPlanAvailable}function RF(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 zF(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 BF(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||RF(i)==null}function VF(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!BF(n))continue;let e=zF(n);e&&t.push(e)}}return t}function HF(e,t){return`${e}:${t.join(`,`)}`}function UF(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=HF(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function WF(e,t,n,r){let i=(0,Q.c)(7),a=qn(),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=UF({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:VF(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,Rt(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 GF=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),KF=(e,t)=>({...e,key:qF(e),estimatedBytes:GF(t)}),qF=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),JF=e=>({key:e?qF(e):null,selection:e}),YF=(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},XF=(e,t,n,r)=>{let i=qF(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return YF(e,i,n);let s=o||KF(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),YF(c,i,n)},ZF=(e,t,n)=>{let r=GF(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)},QF=(e,t)=>t&&e.some(e=>e.key===t)?t:null,$F=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?XF(e.cachedSessionViews,t.selection,n,r.estimatedBytes):YF(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}},eI=(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:KF(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},tI=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:XF(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},nI=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},rI=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},iI=e=>rI(e)?.role===`assistant`,aI=(e,t)=>{let n=rI(t);n&&(e.agentName??=nI(n.agent),e.providerId??=nI(n.providerID),e.modelId??=nI(n.modelID))},oI=e=>!!(e.agentName&&e.providerId&&e.modelId),sI=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!iI(r))&&(aI(t,r),oI(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||iI(r))&&(aI(t,r),oI(t)))break}return t},cI=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),lI=[],uI=[],dI={type:`idle`},fI=`openchamber:chat-force-scroll-bottom`,pI=()=>void 0,mI=`Quota limit reached. Retrying automatically.`,hI=1048576,gI=hI,_I=20,vI=hI,yI=16*hI,bI={maxEntries:3,maxEstimatedBytes:32*hI},xI={maxEntries:2,maxEstimatedBytes:32*hI},SI=e=>t(()=>e()),CI={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},wI={scrollbar:`chat`},TI=`calc(max(0.625rem, var(--oc-safe-area-top, 0px)) + var(--oc-mobile-detail-navigation-height) + 1.25rem)`,EI=`calc(40px + var(--oc-chat-foot-inset))`,DI=[`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(`,`),OI=e=>e instanceof HTMLElement,kI=e=>OI(e)?!!e.closest(DI):!1,AI=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||kI(e)?!0:!t?.contains(e),jI=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=s.getState();return e||t||n||r||i||a||o},MI=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,renderedMessages:l,isLoadingOlder:u,sessionIsWorking:d,streamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,handleMessageContentChange:h,getAnimationHandlers:g,handleHistoryScroll:_,handleHistoryUpwardIntent:v,onTimelineIsAtEndChange:y,scrollToBottom:b,sessionQuestions:x,sessionPermissions:S,isProgrammaticFollowActive:C,showLoadOlderButton:w,onLoadOlder:T,turnIds:E,activeTurnId:D,onSelectTurn:O,showPromptNavigator:k,canLoadEarlierPrompts:A,isLoadingOlderPrompts:j,onLoadEarlierPrompts:M})=>{let{t:N}=ot(),P=Zb(e=>e.legendTimelineEnabled),F=Fb({isLoadingOlder:u}),I=Ib({isMobile:r,isLoadingOlder:F}),L=Z.useRef(new Map),R=Z.useRef(new WeakMap),z=Z.useRef(new Map),B=Z.useMemo(()=>{let e=new Map;for(let t=0;t<l.length;t+=1){let n=l[t];if(n.info.role!==`user`)continue;if(uA(n)){let r=fA(l,t)??``,i=z.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`}];z.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(Vt(n.parts))continue;let r=R.current.get(n.parts);r||(r=J(n.parts),R.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=L.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 L.current=e,e},[l]),V=Z.useMemo(()=>E.filter(e=>B.has(e)),[B,E]),H=Z.useMemo(()=>{if(!D||B.has(D))return D;let e=E.indexOf(D);for(let t=e-1;t>=0;--t){let e=E[t];if(B.has(e))return e}return null},[D,B,E]),U=q(e=>{e.defaultPrevented||kI(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return gN({scrollRef:o,enabled:P,onUpwardIntent:v}),P?(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)(Lj,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:b,scrollRef:o,directory:a,timelineScrollClassName:`absolute inset-0 z-0 chat-scroll overlay-scrollbar-target`,timelineScrollStyle:CI,timelineScrollDataset:wI,timelineOnScroll:_,timelineFollowEnabled:!c,timelineOnIsAtEndChange:y,headerSlot:(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:TI},"aria-hidden":`true`}),w&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(la,{variant:`secondary`,size:`sm`,onClick:T,disabled:F,"aria-busy":F,children:[F&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),N(`chat.history.loadOlder`)]})}),I&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:N(`chat.history.loadingMore`)})]})})]}),footerSlot:(0,$.jsxs)($.Fragment,{children:[(x.length>0||S.length>0)&&(0,$.jsxs)(`div`,{children:[x.map(e=>(0,$.jsx)(lM,{question:e},e.id)),S.map(e=>(0,$.jsx)(rM,{permission:e},e.id))]}),(0,$.jsx)(VM,{sessionId:e,directory:a,isMobile:r}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(OM,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?EI:`10vh`},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:C,userIntentOnly:!0,observeMutations:!1}),k&&V.length>=2?(0,$.jsx)(uN,{turnIds:V,previewsByTurnId:B,activeTurnId:H,onSelectTurn:O,canLoadEarlier:A,isLoadingOlder:j,onLoadEarlier:M}):null]})}):(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)(Ta,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:CI,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:U,onScroll:_,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`oc-chat-scroll-content relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[w&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(la,{variant:`secondary`,size:`sm`,onClick:T,disabled:F,"aria-busy":F,children:[F&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),N(`chat.history.loadOlder`)]})}),I&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:N(`chat.history.loadingMore`)})]})}),(0,$.jsx)(Lj,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:b,scrollRef:o,directory:a}),(x.length>0||S.length>0)&&(0,$.jsxs)(`div`,{children:[x.map(e=>(0,$.jsx)(lM,{question:e},e.id)),S.map(e=>(0,$.jsx)(rM,{permission:e},e.id))]}),(0,$.jsx)(VM,{sessionId:e,directory:a,isMobile:r}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(OM,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?`40px`:`10vh`},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:C,userIntentOnly:!0,observeMutations:!1}),k&&V.length>=2?(0,$.jsx)(uN,{turnIds:V,previewsByTurnId:B,activeTurnId:H,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.renderedMessages===t.renderedMessages&&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.handleHistoryUpwardIntent===t.handleHistoryUpwardIntent&&e.onTimelineIsAtEndChange===t.onTimelineIsAtEndChange&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.onLoadOlder===t.onLoadOlder&&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);MI.displayName=`ChatViewport`;var NI=[{id:1,toolRows:[{id:`search`,titleWidth:`w-24`,detailWidth:`w-52`},{id:`read`,titleWidth:`w-20`,detailWidth:`w-36`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-64`}],textWidths:[`w-24`,`w-[92%]`,`w-[78%]`]},{id:2,toolRows:[{id:`read`,titleWidth:`w-20`,detailWidth:`w-40`},{id:`search`,titleWidth:`w-24`,detailWidth:`w-48`}],textWidths:[`w-20`,`w-[88%]`,`w-[70%]`]},{id:3,toolRows:[{id:`shell`,titleWidth:`w-28`,detailWidth:`w-44`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-56`}],textWidths:[`w-24`,`w-[84%]`,`w-[64%]`]}],PI=e=>ta(e.path),FI=(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)]})},II=e=>{let t=Math.ceil(Math.max(0,e)/_I);return Math.min(yI,gI+t*vI)},LI=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:c,hostedFeatures:l,assistantHistory:u,onRevertMessage:f,warning:p=null,pendingUserMessages:m=uI,onPendingUserMessagesMaterialized:h})=>{let g=l??Bb(void 0),{t:_}=ot();rt(()=>{ri()},[]);let v=Qr(e=>e.openNewSessionDraft),y=Qr(e=>e.setCurrentSession),b=Qr(e=>e.newSessionDraft),x=Qr(e=>e.newSessionDraft.draftSubmitting??!1),S=Qr(e=>e.newSessionDraft.draftEstablishing??!1),C=Qr(e=>e.forkTransition),w=jt(e=>e.projects),T=jt(e=>e.activeProjectId),E=mi(e=>e.providers),D=zl(),O=oi(),k=i??O;rt(()=>{!n||!r||!k||Zt(k,r)},[n,r,k]);let A=q(e=>D.ensureSessionRenderable(e,{directory:k})),j=s(e=>e.isExpandedInput),M=s(e=>e.stickyUserHeader),N=s(e=>e.promptNavigatorEnabled),P=s(e=>e.allowPromptingSubagentSessions),F=s(e=>e.isTimelineDialogOpen),I=s(e=>e.setTimelineDialogOpen),L=xt(e=>n&&r?e.streamingMessageIds.get(r)??null:null),R=xt(e=>L?e.messageStreamStates.get(L)?.phase??null:null),z=Or(r??``,k),B=II(z);Z.useEffect(()=>{!a||!o||o(a,B)},[o,B,a]);let V=pt(r??``,k).renderable,H=lr(r,k),U=qt(r),W=H??U,ee=Jh({sessionId:r,hasSessionEntity:!!W,hasRenderableSessionSnapshot:V,composerSurfaceKind:c?.kind}),G=r?JSON.stringify([k,r]):null,[K,te]=Z.useState({key:G,attempt:0}),ne=di(r??``,k,{suspendPartUpdates:!!L,suspendPartUpdatesForMessageId:L}),re=r?ne:lI,ie=b.pendingUserMessage,ae=Qr(e=>r?e.retainedPendingUserMessages.get(r):void 0)??uI,oe=Qr(e=>e.clearRetainedPendingUserMessages),se=Z.useMemo(()=>{if(ae.length===0)return m;if(m.length===0)return ae;let e=new Set(m.map(e=>e.info.id));return[...m,...ae.filter(t=>!e.has(t.info.id))]},[m,ae]),ce=Z.useMemo(()=>sI(re),[re]),le=Z.useMemo(()=>{if(!ce.modelId)return _(`common.unavailable`);let e=E.find(e=>e.id===ce.providerId);return ft(e,ce.modelId)||ce.modelId},[E,ce.modelId,ce.providerId,_]),ue=Mi(r??``,k),de=Er(r??``,k),[fe,pe]=Z.useState(null),me=!!r&&fe===r,he=q(()=>{if(!r||me)return;let e=r,t=k;pe(e);let n=dr(()=>{let n=Fn();if(!n)throw Error(`unbound`);return n.getTranscript(ht(t,e))});ai(Yi({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:ue?{sessionID:e,status:ue.status===`ready`?`ready`:ue.status,error:ue.error}:void 0,hydration:de,error:ue?.error})),(async()=>{try{await yn(t,e),await D.ensureSessionRenderable(e,{directory:t});try{let r=dr(()=>{let n=Fn();if(!n)throw Error(`unbound`);return n.getTranscript(ht(t,e))});n&&r&&Rr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){ai(Yi({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:de,error:n}))}finally{pe(t=>t===e?null:t)}})()}),ge=Nr(r??``,k).boundary,_e=q(async e=>{if(ge.kind===`has-more`){await br(k,e);return}if(ge.kind===`unknown`){await Ji(k,e);return}u&&!u.complete&&await u.fetchPrevious()});PF(r??``,re);let ve=Tr(r??``,k),ye=ei(r??``,k),be=Fi(k),xe=ve??dI,Se=ar(r,k),Ce=tr(r,k);WF(r,k,re,Ce.length);let we=Z.useMemo(()=>{if(!r||Se.length>0||Ce.length>0)return!1;let e=xe.type??`idle`;if(e===`busy`||e===`retry`||jb(se,{resolvedSessionStatus:ve,sessionStatusObservedAt:ye}))return!0;let t=re[re.length-1]?.info,n=t?.time?.created;return ve&&typeof ye==`number`&&typeof n==`number`&&n<=ye||typeof be==`number`&&typeof n==`number`&&n<=be?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,se,ve,re,Se.length,Ce.length,xe.type,ye,be]),Te=Z.useMemo(()=>!r||xe.type!==`retry`?null:{sessionId:r,message:(typeof xe.message==`string`?(xe.message??``).trim():``)||mI,confirmedAt:xe.confirmedAt},[r,xe]),[Ee,De]=Z.useState(0),Oe=Z.useRef(null);Z.useEffect(()=>{if(!Te||typeof Te.confirmedAt==`number`){Oe.current=null,De(0);return}Oe.current!==Te.sessionId&&(Oe.current=Te.sessionId,De(Date.now()))},[Te]);let ke=Z.useMemo(()=>Te?{...Te,fallbackTimestamp:Ee}:null,[Te,Ee]),Ae=!!(r&&D.isLoading(r,{directory:k})),je=Z.useMemo(()=>{if(!r)return null;let e=Mb({boundary:ge,assistantComplete:u?.complete??!0});return{limit:ge.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:Nb({syncLoading:Ae,assistantLoading:!!u?.loading})}},[u?.complete,u?.loading,r,ge,Ae]),Me=s(e=>e.isMobile),Ne=_h()!==null,Pe=d(),Fe=Fh(),Ie=!!b?.open,Le=Hi(e=>e.error),Re=j,ze=Ne||Me||Pe||Fe===`mini-chat`,Be=Z.useRef(null),Ve=Z.useMemo(()=>{let e=b?.selectedProjectId?w.find(e=>e.id===b.selectedProjectId)??null:null,t=T?w.find(e=>e.id===T)??null:null,n=e??t??w[0]??null;return n?PI(n):null},[T,b?.selectedProjectId,w]),He=nn(r,k),Ue=a??r??``,[We,Ge]=Z.useState(null),Ke=$h(We,Ue,He,ce);rt(()=>{Ge(e=>$h(e,Ue,He,ce))},[He,ce,Ue]);let qe=He??Ke?.parentTarget??null,Je=Ke?.execution??ce,Ye=jc(),Xe=Ye!==null&&r===Ye,Ze=q(()=>{qe&&y(qe.id,qe.directory)}),Qe=qe?.session?.title,$e=g.returnToParent&&qe&&!Xe?(0,$.jsxs)(la,{type:`button`,variant:`outline`,size:`xs`,onClick:Ze,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":_(`chat.container.returnToParent.aria`),title:Qe?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:Qe}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,tt=Yh({readOnly:t,sessionIdentityPending:ee,isSubagentSession:!!W?.parentID||!!Ke,allowPromptingSubagentSessions:P}),st=Je.modelId===ce.modelId?le:Je.modelId?ft(E.find(e=>e.id===Je.providerId),Je.modelId)||Je.modelId:_(`common.unavailable`),ct=qe?(0,$.jsx)(Wb,{agentName:Je.agentName,providerId:Je.providerId,modelId:Je.modelId,modelName:st}):(0,$.jsx)(Wb,{}),lt=q(e=>{s.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),ut=q(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`openchamber:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&&lt({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),dt=typeof window<`u`&&window.parent!==window;it(`message`,ut,dt?window:pI),nt(()=>{if(!dt)return;let e=window;e.__openchamberApplyChatSettingsSync=lt,window.parent.postMessage({type:`openchamber:chat-settings-request`},window.location.origin)}),et(()=>{if(typeof window>`u`)return;let e=window;e.__openchamberApplyChatSettingsSync===lt&&delete e.__openchamberApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Ie&&v()},[e,r,Ie,g.newSessionDraft,v]);let mt=Z.useRef(()=>{}),gt=q(e=>{mt.current(e)}),_t=Z.useRef(()=>{}),vt=q(()=>{_t.current()}),yt=Zb(e=>e.legendTimelineEnabled),[bt,St]=Z.useState(!0),Ct=q(e=>{St(e)}),{scrollRef:wt,notifyContentChange:Tt,getAnimationHandlers:Et,goToBottom:Dt,scrollToBottomOnSend:At,releaseAutoFollow:Mt,beginHistoryViewportPreservation:Nt,endHistoryViewportPreservation:Pt,restoreSnapshot:Ft,isPinned:Lt,isFollowingProgrammatically:Rt,showScrollButton:zt}=BN({enabled:n&&!yt,currentSessionId:r,viewportKey:a,sessionMessageCount:z,sessionIsWorking:we,isMobile:Me,onActiveTurnChange:gt,onUpwardUserIntent:vt}),Bt=Z.useRef(null);oP({enabled:Me,scrollRef:wt,scopeRef:Bt});let Vt=Z.useRef([]),Ht=Z.useMemo(()=>{let e=zn(u?.entries??[],r,Vt.current);return Vt.current=e,e},[u?.entries,r]),Ut=Z.useRef([]),Wt=Z.useMemo(()=>{if(!u)return re;let e=Vi(u.entries,r,re,Ut.current);return Ut.current=e,e},[u,r,re]),Gt=Z.useMemo(()=>Ab(Ht.length===0?Wt:r?[...Ht,Gi(r),...Wt]:Ht,se),[r,Wt,Ht,se]),Kt=Z.useRef(null),Jt=Z.useMemo(()=>zb({sessionId:r,messages:Gt,retained:Kt.current}),[r,Gt]);Kt.current=Jt.retained;let Yt=Jt.messages,Xt=Z.useRef(null),Qt=Xt.current===r,$t=Z.useRef(jF),en=r?`${k}\n${r}`:null,tn=q(()=>AF(Yt));Z.useEffect(()=>{if(!r||!en||!we){$t.current={...$t.current,lastMovementAt:null};return}let e=r,t=k,n=setInterval(()=>{let n=tn(),r=MF($t.current,{sessionKey:en,working:!0,streaming:!!L,fingerprint:n,now:Date.now(),thresholdMs:EF,cooldownMs:DF,maxAttempts:3});$t.current=r.state,r.shouldRefresh&&(NF({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),Ot(t,e).catch(()=>{}))},OF);return()=>clearInterval(n)},[r,k,tn,we,L,en]);let rn=Z.useMemo(()=>{if(se.length===0)return[];let e=new Set([...Ht,...Wt].filter(e=>kt(e.parts)).map(e=>e.info.id));return se.map(e=>e.info.id).filter(t=>e.has(t))},[Wt,Ht,se]);Z.useEffect(()=>{rn.length!==0&&(h?.(rn),r&&oe(r,rn))},[oe,r,rn,h]);let an=vF({sessionId:r,directory:k,messages:Yt,historyMeta:je,scrollRef:wt,messageListRef:Be,loadMoreMessages:_e,goToBottom:Dt,releaseAutoFollow:Mt,beginHistoryViewportPreservation:Nt,endHistoryViewportPreservation:Pt,isPinned:yt?bt:Lt,showScrollButton:yt?!bt:zt,autoFillEnabled:n&&!Re}),on=q(()=>{Dt(`instant`)}),sn=Pb({isMobile:Me,canLoadEarlier:an.historySignals.canLoadEarlier,isLoadingOlder:an.isLoadingOlder}),cn=an.isLoadingOlder,ln=an.loadEarlier,un=q(()=>{ln({userInitiated:!0})});mt.current=an.handleActiveTurnChange,_t.current=an.handleHistoryUpwardIntent,Z.useEffect(()=>{(Se.length!==0||Ce.length!==0)&&Tt(`permission`)},[Tt,Se,Ce]);let dn=TF({sessionId:r,turnIds:an.turnIds,activeTurnId:an.activeTurnId,scrollToTurn:an.scrollToTurn,scrollToMessage:an.scrollToMessage,resumeToBottom:an.resumeToBottomInstant}),fn=tt.showReadOnlyBanner?ct:t?null:(0,$.jsx)(Sb,{surface:c,scrollToBottom:At,showScrollToBottom:Me&&an.showScrollToBottom,onScrollToBottom:dn.resumeToLatest,submissionBlocked:tt.blockSubmission}),pn=q(e=>{dn.scrollToTurnId(e,{behavior:`smooth`})}),mn=an.historySignals.canLoadEarlier,hn=g.promptNavigator&&!Me&&!Pe&&!Re&&N&&an.turnIds.length>=2;Z.useEffect(()=>{hn||s.getState().setPromptNavigatorPanelOpen(!1)},[hn]);let gn=q(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||Dt(`instant`)});it(fI,gn,n&&r&&typeof window<`u`?window:pI);let _n=q(e=>{if(!n||!r||Re||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=s.getState();if(t!==`chat`||jI())return;let i=wt.current;if(AI(document.activeElement,i)||kI(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;dn.scrollByTurnOffset(a,{resumePastEnd:!1})});it(`keydown`,_n,n&&r&&!Re&&typeof window<`u`?window:pI);let vn=Z.useRef(0),J=q(()=>{let e=wt.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),bn=q(()=>{vn.current||=requestAnimationFrame(()=>{vn.current=0,J()})});rt(()=>{n&&J()},[n,r,Re,J]);let xn=typeof ResizeObserver<`u`;at(n&&xn?wt:null,bn),it(`resize`,bn,n&&!xn&&typeof window<`u`?window:pI),et(()=>{vn.current&&=(cancelAnimationFrame(vn.current),0)});let Sn=Z.useRef(null),Cn=Z.useRef(0),wn=Lb({transcriptMessageCount:re.length,pendingUserCount:se.length,historyPrefixCount:Ht.length}),Tn=Rb({hasTranscriptShell:wn,p0Satisfied:de.p0Satisfied,hasBusyShell:we&&wn,hasImmediateShell:se.length>0||Ht.length>0,hasRenderableSessionSnapshot:V,prefetchStatus:ue?.status,syncLoading:!!(r&&D.isLoading(r,{directory:k})),userRetrying:me,hasPaintedTranscript:Qt});Tn===`pass`&&Yt.length>0&&(Xt.current=r);let En=!!r&&Tn===`hydrating`,Dn=!!r&&Tn===`load-error`;Z.useEffect(()=>{!Dn||!r||ai(Yi({kind:`request-error`,sessionID:r,directory:k,purpose:`load-failed`,source:`network`,request:ue?{sessionID:r,status:ue.status===`ready`?`ready`:ue.status,error:ue.error}:void 0,hydration:de,error:ue?.error}))},[r,k,Dn,ue,de]),Z.useEffect(()=>{if(!n||!r||En)return;let e=Yt.length,t=Sn.current!==r,i=!t&&Cn.current===0&&e>0;if(!t&&!i){Sn.current===r&&(Cn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(Sn.current=r,Cn.current=e,a){Mt();return}let o=()=>{Ft()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,En,Mt,Ft,Yt.length]),Z.useEffect(()=>{te(e=>e.key===G?e:{key:G,attempt:0})},[G]),Z.useEffect(()=>{if(!n||!r||K.key!==G||!cI({sessionId:r,hasRenderableSessionSnapshot:V,hasCurrentSessionEntity:!!W})||(A(r),W||K.attempt>=2))return;let e=K.attempt+1,t=window.setTimeout(()=>{te(t=>t.key===G&&t.attempt===K.attempt?{key:G,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,W,r,k,A,V,G,K]);let On=C&&r&&(C.targetSessionId?r===C.targetSessionId:r===C.sourceSessionId)?C:null;if(On){let e=On.stage===`preparing`?`chat.forkTransition.preparing`:On.stage===`copying`?`chat.forkTransition.copying`:On.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(On.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${_(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(e)}),(0,$.jsx)(Qf,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}return!r&&!Ie?e&&!Le?(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)(Kb,{})}):!r&&Ie?(x||S)&&ie?(0,$.jsx)(`div`,{className:`relative flex h-full flex-col bg-background`,children:(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:(0,$.jsxs)(Ta,{className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll`,style:CI,children:[(0,$.jsx)(Lj,{sessionKey:`draft:${b.draftID??`pending`}`,messages:[ie],sessionIsWorking:!0,isLoadingOlder:!1,onMessageContentChange:Tt,getAnimationHandlers:Et,scrollToBottom:on}),(0,$.jsxs)(`div`,{className:`chat-message-column px-4 pb-10 pt-2 typography-meta text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Qf,{})]})]})})}):x||S?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":_(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Qf,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[ze&&!Re?(0,$.jsxs)(`div`,{className:`oc-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:FI(Ve?_(`chat.emptyState.draftTitleWithProject`,{project:Ve}):_(`chat.emptyState.draftTitle`),Ve)}),(0,$.jsx)(Gg,{onSubmit:e=>It.getState().requestPresetSubmit(e),className:`oc-draft-starters mt-8 max-w-md`})]}):null,(0,$.jsx)(`div`,{className:Y(`relative z-10 flex min-h-0`,Me&&`oc-mobile-composer-foot`,Re?`flex-1 bg-background`:ze?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:fn})]}):r?Dn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[$e,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Re?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Re,children:Re?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:_(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:_(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(la,{type:`button`,className:`mt-5`,onClick:he,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Me&&`oc-mobile-composer-foot`,Re?`flex-1 min-h-0 bg-background`:`bg-background`),children:fn})]}):En?(0,$.jsxs)(`div`,{ref:Bt,className:Y(`relative flex flex-col h-full bg-background`,Me&&`oc-chat-composer-swap-scope`),children:[$e,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Re?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Re,children:(0,$.jsx)(`div`,{ref:wt,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:CI,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:NI.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)(es,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(es,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(es,{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)(es,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(es,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(es,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Me&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,Re?`flex-1 min-h-0 bg-background`:`bg-background`),children:fn})]}):Yt.length===0&&!we?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[$e,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Re?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Re,children:Re?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(Kb,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,Me&&`oc-mobile-composer-foot`,Re?`flex-1 min-h-0 bg-background`:`bg-background`),children:fn}),(0,$.jsx)(kb,{})]}):(0,$.jsxs)(`div`,{ref:Bt,className:Y(`relative flex flex-col h-full bg-background`,Me&&`oc-chat-composer-swap-scope`),children:[p?(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:p}):null,$e,(0,$.jsx)(MI,{currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Re,isMobile:Me,stickyUserHeader:M,directory:k,scrollRef:wt,messageListRef:Be,pendingRevealWork:an.pendingRevealWork,renderedMessages:an.renderedMessages,isLoadingOlder:cn,sessionIsWorking:we,streamingMessageId:L,activeStreamingPhase:R,retryOverlay:ke,handleMessageContentChange:Tt,getAnimationHandlers:Et,handleHistoryScroll:an.handleHistoryScroll,handleHistoryUpwardIntent:an.handleHistoryUpwardIntent,onTimelineIsAtEndChange:Ct,scrollToBottom:on,sessionQuestions:Ce,sessionPermissions:Se,isProgrammaticFollowActive:Rt,showLoadOlderButton:sn,onLoadOlder:un,turnIds:an.turnIds,activeTurnId:an.activeTurnId,onSelectTurn:pn,showPromptNavigator:hn,canLoadEarlierPrompts:mn,isLoadingOlderPrompts:cn,onLoadEarlierPrompts:un},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,Me&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,Re?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!Re&&Yt.length>0&&(Me?(0,$.jsx)(Nh,{placement:`expanded`,visible:an.showScrollToBottom,onClick:dn.resumeToLatest}):(0,$.jsx)(Nh,{visible:an.showScrollToBottom,onClick:dn.resumeToLatest})),fn]}),(0,$.jsx)(kb,{}),(0,$.jsx)(bF,{open:F,onOpenChange:I,sessionID:r??void 0,directory:k,onRevertMessage:f,onScrollToMessage:an.scrollToMessage,onScrollByTurnOffset:dn.scrollByTurnOffset,onResumeToLatest:on,canLoadEarlier:an.historySignals.canLoadEarlier,isLoadingEarlier:cn,onLoadEarlier:un})]}):null});LI.displayName=`MemoizedChatContainerContent`;var RI=()=>{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)(es,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(es,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(es,{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-6 px-4`,children:[t,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(es,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(es,{className:`h-4 w-3/5 animate-none rounded-md`})]}),(0,$.jsx)(es,{className:`h-24 w-full animate-none rounded-xl`})]})})}),e[1]=n):n=e[1],n},zI=e=>{let t=(0,Q.c)(63),n,r;t[0]===e?(n=t[1],r=t[2]):({runtimeKey:r,...n}=e,t[0]=e,t[1]=n,t[2]=r);let i=Fh(),a=oi(),o=Qr(me(UI)),s;bb0:{if(!o.sessionId){s=null;break bb0}let e=o.directory??a,n;t[3]!==r||t[4]!==o.sessionId||t[5]!==e?(n={runtimeKey:r,sessionId:o.sessionId,directory:e},t[3]=r,t[4]=o.sessionId,t[5]=e,t[6]=n):n=t[6],s=n}let c=s,l;t[7]===c?l=t[8]:(l=JF(c),t[7]=c,t[8]=l);let u=l,f=u.key,p=Zi()||d()||i===`mini-chat`?xI:bI,m;t[9]!==p||t[10]!==c||t[11]!==u?(m=()=>({activeIntent:u,cacheNeedsTrim:!1,cachedSessionViews:c?XF([],c,p,gI):[],pendingSessionView:null}),t[9]=p,t[10]=c,t[11]=u,t[12]=m):m=t[12];let[h,g]=Z.useState(m),_=Z.useRef(u),v=Z.useRef(f),{cacheNeedsTrim:y,cachedSessionViews:b,pendingSessionView:x}=h,S=x?.intent===u?x.entry:null,C;if(t[13]!==b||t[14]!==S){let e=[...b];S&&!e.some(e=>e.key===S.key)&&e.push(S),C=e.sort(WI),t[13]=b,t[14]=S,t[15]=C}else C=t[15];let w=C,T;t[16]!==w||t[17]!==f?(T=QF(w,f),t[16]=w,t[17]=f,t[18]=T):T=t[18];let E=T,D=!!(f&&!E),O;t[19]!==p||t[20]!==u||t[21]!==f?(O=()=>{_.current=u,v.current=f,g(e=>$F(e,u,p))},t[19]=p,t[20]=u,t[21]=f,t[22]=O):O=t[22];let k;t[23]!==p||t[24]!==y||t[25]!==u||t[26]!==f?(k=[p,y,u,f],t[23]=p,t[24]=y,t[25]=u,t[26]=f,t[27]=k):k=t[27],rt(O,k);let A=x?.intent??null,j,M;t[28]!==p||t[29]!==A?(j=()=>{A&&g(e=>tI(e,A,p))},M=[p,A],t[28]=p,t[29]=A,t[30]=j,t[31]=M):(j=t[30],M=t[31]),rt(j,M);let N;t[32]!==E||t[33]!==u||t[34]!==f?(N=()=>{if(!u.selection||E)return;let e=u,t=f;return ls(()=>{_.current===e&&v.current===t&&g(n=>v.current===t?eI(n,e,_.current,gI):n)},{priority:`user-blocking`})},t[32]=E,t[33]=u,t[34]=f,t[35]=N):N=t[35];let P;t[36]!==E||t[37]!==p||t[38]!==u||t[39]!==f?(P=[E,p,u,f],t[36]=E,t[37]=p,t[38]=u,t[39]=f,t[40]=P):P=t[40],Z.useEffect(N,P);let F;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(F=(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=ZF(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})},t[41]=F):F=t[41];let I=q(F),L=D||void 0,R;t[42]!==D||t[43]!==f?(R=D?(0,$.jsx)(RI,{},f):null,t[42]=D,t[43]=f,t[44]=R):R=t[44];let z;if(t[45]!==E||t[46]!==I||t[47]!==n||t[48]!==w){let e;t[50]!==E||t[51]!==I||t[52]!==n?(e=e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:E===e.key?`visible`:`hidden`,children:(0,$.jsx)(LI,{...n,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:I})},e.key),t[50]=E,t[51]=I,t[52]=n,t[53]=e):e=t[53],z=w.map(e),t[45]=E,t[46]=I,t[47]=n,t[48]=w,t[49]=z}else z=t[49];let B;t[54]!==n||t[55]!==o.directory||t[56]!==f?(B=f?null:(0,$.jsx)(LI,{...n,sessionId:null,sessionDirectory:o.directory}),t[54]=n,t[55]=o.directory,t[56]=f,t[57]=B):B=t[57];let V;return t[58]!==L||t[59]!==R||t[60]!==z||t[61]!==B?(V=(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":L,children:[R,z,B]}),t[58]=L,t[59]=R,t[60]=z,t[61]=B,t[62]=V):V=t[62],V},BI=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=Bb(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)(LI,{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)(Zm.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},VI=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=oi(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Xm({...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)(LI,{...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)(Zm.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},HI=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(SI,i,i);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(BI,{...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)(VI,{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)(zI,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r};function UI(e){return{sessionId:e.currentSessionId,directory:e.currentSessionDirectory}}function WI(e,t){return e.key.localeCompare(t.key)}export{wc as $,Ph as A,Sp as B,Ag as C,_g as D,Og as E,Jm as F,su as G,fp as H,Zm as I,zl as J,au as K,Zp as L,gh as M,_h as N,yg as O,qm as P,Cc as Q,Wp as R,kg as S,Mg as T,Qf as U,dp as V,ku as W,bl as X,yl as Y,Sc as Z,Wv as _,BN as a,t_ as b,JD as c,aE as d,Oc as et,YT as f,Xv as g,Wb as h,gP as i,Nh as j,og as k,iE as l,Zb as m,sI as n,Tc as nt,DM as o,NT as p,Gl as q,yP as r,Lj as s,HI as t,Ac as tt,rE as u,Uv as v,Dg as w,Eg as x,f_ as y,zp as z};