@openchambery/web 1.18.2-beta.21 → 1.18.2-beta.23

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 (47) hide show
  1. package/dist/assets/{AssistantView-C00aiEHK.js → AssistantView-BwOGfQdf.js} +1 -1
  2. package/dist/assets/{ChatContainer-BDFeDKu-.js → ChatContainer-BhuJ17NV.js} +5 -5
  3. package/dist/assets/{DiagramView-CUfSFI3e.js → DiagramView-BZDrlrBa.js} +1 -1
  4. package/dist/assets/{MarkdownRendererImpl-Cen6E9Lj.js → MarkdownRendererImpl-_B10-P_d.js} +1 -1
  5. package/dist/assets/{MobileDetailNavigation-DILi0tN7.js → MobileDetailNavigation-B4ou1pP8.js} +1 -1
  6. package/dist/assets/{MobileShareBridge-PZMRiieI.js → MobileShareBridge-BFvNHNJt.js} +1 -1
  7. package/dist/assets/{MobileSurface-BLYcR0tO.js → MobileSurface-DWSNe5Oc.js} +1 -1
  8. package/dist/assets/{MultiRunWindow-D_2mWZyv.js → MultiRunWindow-C_n1QW0Q.js} +1 -1
  9. package/dist/assets/{OverlayScrollbar-BgMLtMIq.js → OverlayScrollbar-Mi_WH4jv.js} +1 -1
  10. package/dist/assets/{SettingsView-CbDBfQp1.js → SettingsView-BXzpHbAd.js} +1 -1
  11. package/dist/assets/{SettingsWindow-Br7XLcSd.js → SettingsWindow-ChZzPrmx.js} +1 -1
  12. package/dist/assets/{TerminalView-CM5jRKlj.js → TerminalView-DHnpuSPa.js} +1 -1
  13. package/dist/assets/{ToolOutputDialog-D3U6aTZ4.js → ToolOutputDialog-C1R-GCPB.js} +1 -1
  14. package/dist/assets/{appThemeRegistry-CDxBJNNB.js → appThemeRegistry-Ck9e8eEr.js} +2 -2
  15. package/dist/assets/assistant-guide-hero-wide-DiFIThB0.jpg +0 -0
  16. package/dist/assets/{context-menu-DBOMervd.js → context-menu-CjVxtovr.js} +1 -1
  17. package/dist/assets/{gitApi-BQT3QXD2.js → gitApi-Ctgr4Y9i.js} +1 -1
  18. package/dist/assets/{insertionBoundaries-9a0RuIDc.js → insertionBoundaries-BEvkmerk.js} +1 -1
  19. package/dist/assets/{main-CEqSDnE2.js → main-DakgzbmV.js} +2 -2
  20. package/dist/assets/{main-BGfX81Y9.js → main-mPlXr40-.js} +4 -4
  21. package/dist/assets/{miniChat-CKucSAhg.js → miniChat-BvWaAk95.js} +2 -2
  22. package/dist/assets/{mobile-C4bTWKry.js → mobile-BBcoCHM3.js} +2 -2
  23. package/dist/assets/{multirun-DeNtSkgb.js → multirun-Dc_oCEXn.js} +1 -1
  24. package/dist/assets/{projectMeta-BunN9pH5.js → projectMeta-BbjPDSpU.js} +2 -2
  25. package/dist/assets/radio-CQrbmLB7.js +1 -0
  26. package/dist/assets/{renderElectronMiniChatApp-D8-FDgWE.js → renderElectronMiniChatApp-C7FdCciX.js} +2 -2
  27. package/dist/assets/{renderMobileApp-CdU0aJ-e.js → renderMobileApp-Bhv28XIT.js} +5 -5
  28. package/dist/assets/{runtimeEndpointReset-CK1GhIsm.js → runtimeEndpointReset-DhSRMf7G.js} +1 -1
  29. package/dist/assets/{sortable-tabs-strip-pWlBorwQ.js → sortable-tabs-strip-yvKEEQEL.js} +1 -1
  30. package/dist/assets/{src-8kQFmtjw.css → src-7UHu0sNZ.css} +1 -1
  31. package/dist/assets/{useAppFontEffects-IEUQDvE8.js → useAppFontEffects-BiZhEY4g.js} +2 -2
  32. package/dist/assets/{useDesktopWindowControlsLayout-MlqJX89k.js → useDesktopWindowControlsLayout-D3lc4TXT.js} +1 -1
  33. package/dist/assets/{useEffectiveDirectory-GbhkdO6m.js → useEffectiveDirectory-DD7JGLuB.js} +1 -1
  34. package/dist/assets/{useMobileNavigationStore-DQHF_ETu.js → useMobileNavigationStore-DEUCakMd.js} +1 -1
  35. package/dist/assets/{useSessionAutoCleanup-BuU_S_Sh.js → useSessionAutoCleanup-X6napv6d.js} +1 -1
  36. package/dist/assets/{useWorkerHighlightedLines-Ca6OgNHF.js → useWorkerHighlightedLines-B6gvEO9K.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/mini-chat.html +2 -2
  39. package/dist/mobile.html +2 -2
  40. package/package.json +1 -1
  41. package/server/lib/assistants/DOCUMENTATION.md +2 -2
  42. package/server/lib/assistants/history-state.js +23 -0
  43. package/server/lib/assistants/history-state.test.js +51 -0
  44. package/server/lib/assistants/service.js +37 -11
  45. package/server/lib/assistants/service.test.js +106 -2
  46. package/dist/assets/assistant-guide-hero-BeUHQcxE.jpg +0 -0
  47. package/dist/assets/radio-Bziafaje.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-D3U6aTZ4.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-5agS8bsW.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-D1lIuyqO.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-BnElHSnO.js","assets/store-CUWqzRt7.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/utils-BxJEIWv5.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-DiIuWOuC.js","assets/dialog-COrLBm9O.js","assets/button-DaAoVF4X.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-D-aLQZaM.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-CDxBJNNB.js","assets/useMobileNavigationStore-DQHF_ETu.js","assets/gitApiHttp-BxGAFLTf.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-Bq3cPj2x.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-BDyY0vt6.js","assets/useEffectiveDirectory-GbhkdO6m.js","assets/useWorkerHighlightedLines-Ca6OgNHF.js","assets/tooltip-BLugzWq-.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T as i,W as a,g as o,j as s,t as c,y as l}from"./useUIStore-5agS8bsW.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-D1lIuyqO.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,Dt as Te,Et as Ee,Ft as De,It as Oe,Pt as ke,Rt as Ae,Tt as je,Ut as Me,Vt as Ne,Wt as Pe,kt as Fe,vt as Ie,yt as Le,zt as Re}from"./gitApiHttp-BxGAFLTf.js";import{a as ze,n as Be,o as Ve}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as He}from"./vendor-react-DLPElpoQ.js";import{i as Ue,n as We,s as Ge,t as Ke}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as qe,R as Je,V as Ye,c as Xe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as Ze,d as Qe,i as $e,l as et,n as q,o as tt,r as nt,u as rt}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as it,r as at,t as ot}from"./clipboard-BnElHSnO.js";import{i as st,t as ct}from"./store-CUWqzRt7.js";import{$ as lt,$a as ut,$r as dt,$t as ft,A as pt,Ai as mt,An as ht,Ao as gt,Ar as _t,B as vt,Ba as yt,Br as bt,Bt as xt,Ca as St,Ci as Ct,Cn as wt,Cr as Tt,Ct as Et,D as Dt,Da as Ot,Di as kt,Dt as At,E as jt,Ei as Mt,Er as Nt,Et as Pt,F as Ft,Fa as It,Fi as Lt,Fn as Rt,Fr as zt,G as Bt,Gr as Vt,Gt as Ht,Ha as Ut,Hi as Wt,Hn as Gt,Hr as Kt,Ht as qt,I as Jt,Ia as Yt,Ii as Xt,In as Zt,J as Qt,Jr as $t,Jt as en,K as tn,Ki as nn,Kr as rn,Kt as an,L as on,La as sn,Li as cn,Ln as ln,Lr as un,M as dn,Mi as fn,Mr as pn,Mt as mn,N as hn,Ni as gn,Nr as _n,Nt as vn,O as yn,Oi as bn,Oo as xn,Ot as Sn,P as Cn,Pa as wn,Pi as Tn,Pn as En,Q as Dn,Qt as On,Ra as kn,Ri as An,Rt as jn,S as Mn,Si as Nn,Sn as Pn,T as Fn,Ta as In,Ti as Ln,To as Rn,Tr as zn,Tt as Bn,U as Vn,Ua as Hn,Un,Ur as Wn,Va as Gn,Vr as Kn,Vt as qn,Wa as Jn,X as Yn,Xa as Xn,Xi as Zn,Xt as Qn,Y as $n,Ya as er,Yi as tr,Z as nr,Zi as rr,Zt as ir,_i as ar,_n as or,a as sr,an as cr,at as lr,ba as ur,bi as dr,bn as fr,ca as pr,cn as mr,ct as hr,da as gr,di as _r,dn as vr,dt as yr,ea as br,ei as xr,en as Sr,er as Cr,et as wr,f as Tr,fa as Er,fi as Dr,fn as Or,ft as kr,g as Ar,ga as jr,gi as Mr,go as Nr,ha as Pr,hi as Fr,ho as Ir,hr as Lr,ht as Rr,i as zr,ia as Br,ii as Vr,in as Hr,it as Ur,j as Wr,ja as Gr,ji as Kr,jo as qr,jr as Jr,jt as Yr,k as Xr,ki as Zr,kr as Qr,l as J,la as $r,li as ei,ln as ti,lt as ni,m as ri,ma as ii,mi as ai,n as oi,ni as si,nn as ci,nr as li,nt as ui,oa as di,oi as fi,on as pi,pt as mi,q as hi,qi as gi,qt as _i,ri as vi,rn as yi,rr as bi,rt as xi,sa as Si,sn as Ci,ti as wi,tr as Ti,tt as Ei,ua as Di,ui as Oi,un as ki,ut as Ai,va as ji,vi as Mi,vn as Ni,vr as Pi,vt as Fi,w as Ii,wa as Li,wi as Ri,wn as zi,wr as Bi,wt as Vi,x as Hi,xi as Ui,xn as Wi,yt as Gi,z as Ki,za as qi,zr as Ji,zt as Yi}from"./useMobileNavigationStore-DQHF_ETu.js";import{n as Xi,t as Zi}from"./AgentAvatar-B4fj9PIe.js";import{n as Qi,t as Y}from"./utils-BxJEIWv5.js";import{n as X}from"./Icon-DiIuWOuC.js";import{a as $i,i as ea,n as ta,o as na,r as ra,s as ia,t as aa}from"./dialog-COrLBm9O.js";import{t as oa}from"./button-DaAoVF4X.js";import{E as sa,n as ca}from"./gitApi-BQT3QXD2.js";import{A as la,C as ua,M as da,N as fa,O as pa,S as ma,T as ha,a as ga,b as _a,d as va,g as ya,h as ba,i as xa,j as Sa,k as Ca,n as wa,o as Ta,p as Ea,s as Da,u as Oa,v as ka,w as Aa,x as ja}from"./projectMeta-BunN9pH5.js";import{t as Ma}from"./input-XiL2-2gG.js";import{i as Na,n as Pa,t as Fa}from"./tooltip-BLugzWq-.js";import{n as Ia,t as La}from"./useThemeSystem-DMzWVJaW.js";import{D as Ra,E as za,M as Ba,N as Va,O as Ha,Q as Ua,S as Wa,U as Ga,V as Ka,X as qa,Y as Ja,_ as Ya,a as Xa,f as Za,g as Qa,h as $a,i as eo,m as to,o as no,p as ro,r as io,t as ao,x as oo,z as so}from"./radio-Bziafaje.js";import{i as co,t as lo}from"./OverlayScrollbar-BgMLtMIq.js";import{_ as uo,a as fo,d as po,f as mo,g as ho,h as go,i as _o,l as vo,m as yo,n as bo,u as xo,v as So,x as Co}from"./markdownTheme-D-aLQZaM.js";import{n as wo,r as To,t as Eo}from"./useRuntimeAPIs-DSLXJybW.js";import{a as Do,c as Oo,i as ko,r as Ao,t as jo,u as Mo}from"./appThemeRegistry-CDxBJNNB.js";import{_ as No,a as Po,c as Fo,g as Io,l as Lo,o as Ro,t as zo,v as Bo,y as Vo}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Ho,n as Uo,o as Wo,s as Go,t as Ko}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as qo,n as Jo,t as Yo}from"./url-DMs_PgIC.js";import{_ as Xo,l as Zo,m as Qo,p as $o,s as es}from"./markdown-worker-BDyY0vt6.js";import{n as ts}from"./useEffectiveDirectory-GbhkdO6m.js";import{a as ns,c as rs,d as is,f as as,i as os,l as ss,n as cs,r as ls,s as us,t as ds}from"./FadeInOnReveal-CKKU6fKI.js";import{A as fs,C as ps,D as ms,E as hs,M as gs,O as _s,S as vs,T as ys,a as bs,b as xs,c as Ss,f as Cs,i as ws,j as Ts,k as Es,l as Ds,m as Os,n as ks,o as As,p as js,r as Ms,s as Ns,t as Ps,u as Fs,w as Is,x as Ls}from"./insertionBoundaries-9a0RuIDc.js";import{A as Rs,C as zs,D as Bs,E as Vs,M as Hs,O as Us,S as Ws,T as Gs,a as Ks,b as qs,c as Js,g as Ys,h as Xs,i as Zs,j as Qs,k as $s,o as ec,p as tc,r as nc,s as rc,t as ic,v as ac,w as oc,x as sc,y as cc}from"./useWorkerHighlightedLines-Ca6OgNHF.js";import{t as lc}from"./vendor-cmdk-CeAGfrLo.js";import{t as uc}from"./sortable-tabs-strip-pWlBorwQ.js";import{n as dc,t as fc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as pc,u as mc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as hc,t as gc}from"./vendor-framer-motion-DFy_BSVd.js";var Z=e(be(),1),Q=He(),$=ye(),_c=e(xe(),1),vc=`openchamber:close-embedded-session-chat`,yc=`openchamber:embedded-visibility`,bc=`openchamber:embedded-visibility-request`,xc=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,Sc=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),Cc=(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()},wc=(e,t,n,r,i,a)=>{let o=Sc(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=Cc(n,r,i,a);return e.set(t,{signature:o,src:c}),c},Tc=null,Ec=()=>{if(Tc!==null)return Tc;if(typeof window>`u`)return Tc=!1,!1;try{return Tc=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,Tc}catch{return Tc=!1,!1}},Dc=()=>{if(!Ec())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},Oc=ze(`OpenChamberMedia`);function kc(){return qr()&&Be.getPlatform()===`android`&&Be.isPluginAvailable(`OpenChamberMedia`)}async function Ac(e){if(!kc())return null;let t=await Oc.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(Be.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 jc=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Mc=1e4,Nc=15e3,Pc=3e4,Fc=3e4,Ic=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=Ie(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`))}},Mc);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`))},Nc);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`))},Fc),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=jc(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)}}},Pc))}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`,()=>{Ic.cancelAllForRuntimeSwitch()});var Lc=128,Rc=`audio/pcm;rate=16000;bits=16`,zc=()=>new Promise(e=>setTimeout(e,0)),Bc=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Vc=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??Rc,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Bc}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<Lc;){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 zc()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Hc=16e3,Uc=Hc,Wc=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Gc=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Kc=(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]=Gc(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]=Gc(e[i]*(1-s)+e[o]*s)}return a},qc=(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},Jc=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)},Yc=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Xc=e=>{if(e)try{e.disconnect()}catch{}},Zc=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Wc()!==null;function Qc(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=Yc(),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=Wc();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(tl);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=Kc(a,n.sampleRate,Hc);for(t.pending=qc(t.pending,c);t.pending.length>=Uc;){let e=t.pending.slice(0,Uc);t.pending=t.pending.slice(Uc),i.current(Jc(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(el);try{await n.close()}catch{}throw l.current=Yc(),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{}Xc(e.processor),Xc(e.source),Xc(e.gain),e.stream&&e.stream.getTracks().forEach($c);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Jc(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Yc())},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 $c(e){try{e.stop()}catch{}}function el(e){try{e.stop()}catch{}}function tl(){}var nl=1e3,rl=e=>e instanceof Error?e:Error(String(e)),il=()=>{let e=Zn.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 al(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 Vc({client:Ic,getStartOptions:il});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},nl)},[]),C=(0,Z.useCallback)(e=>{let t=rl(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)(()=>Ic.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Ic.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Qc({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 ol=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},sl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ia(),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},cl=e=>{let t=Zn(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},ll=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=it(),{currentTheme:v}=Ia(),y=Zn(ul),b=c(dl),x;t[0]===b?x=t[1]:(x=Ka(Ga(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(fl),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}=al(k),H=A===`recording`&&F===`model_download_in_progress`,U=cl(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:pl,onPointerDownCapture:ml},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]!==s||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)(sl,{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)(sl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:ol(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:s})})]}):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]=s,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 ul(e){return e.dictationEnabled}function dl(e){return e.shortcutOverrides}function fl(){return!d()&&Zc()}function pl(e){return e.preventDefault()}function ml(e){e.pointerType===`touch`&&e.preventDefault()}var hl=2e3,gl=de((e,t)=>({pending:!1,expiresAt:null,arm:(t=hl)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),_l=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}},vl=15e3,yl=100,bl=new Map,xl=new Map,Sl=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,Cl=e=>{let t=Sl(e),n=e.now??Date.now(),r=xl.get(t);if(r&&n-r.loadedAt<vl)return Promise.resolve(r.sessions);let i=bl.get(t);if(i)return i;let a=e.request().then(e=>{for(xl.delete(t);xl.size>=yl;){let e=xl.keys().next().value;if(typeof e!=`string`)break;xl.delete(e)}return xl.set(t,{loadedAt:Date.now(),sessions:e}),e});return bl.set(t,a),a.then(()=>{bl.get(t)===a&&bl.delete(t)},()=>{bl.get(t)===a&&bl.delete(t)}),a},wl=(e,t)=>e.id<t.id?-1:+(e.id>t.id),Tl=(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(wl)},El=30;function Dl(e){return e===`busy`||e===`retry`}var Ol=new Map;function kl(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Al(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 jl(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${Al(e.error)}`)}function Ml(e,t){let n=Er();if(!n)return!1;let r=n.getTranscript(ur(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>bn()}function Nl(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Pl(e,t,n){let r=[...e.getState().session],i=In.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Fl(){let e=vr(),t=xt(),r=jn(),i=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=Er();if(!r||!t)return kl({kind:`unknown`,loadedTurns:0},!1);let i=ur(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return kl(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let n=r.getChild(e);if(!n)return;let i=n.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}};Pn(a,t),Yr(n,t),n.setState(a);for(let n of t)Pr(e,n)},[r]),s=(0,Z.useCallback)((t=e)=>{let n=Ol.get(t);if(n)return Ol.delete(t),Ol.set(t,n),n;let r=new Set;for(Ol.set(t,r);Ol.size>El;){let e=Ol.keys().next().value;if(!e)break;let t=[...Ol.get(e)??[]];Ol.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((n,i=e)=>{let a=i===e?t:r.ensureChild(i,{bootstrap:!1}),c=s(i),l=wt(a.getState()),u=Mt(),d=zi({seen:c,keep:n,limit:u,preserve:l});if(o(i,d),kt()){let e=new Set([n,...c,...l]),t=(Er()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),r=(t.length>0?t:Array.from(c)).filter(t=>t===n||e.has(t)?!1:Ml(i,t));if(r.length>0){for(let e of r)c.delete(e);o(i,r)}}},[r,e,s,o,t]),l=(0,Z.useCallback)(async(n,i)=>{let a=i?.directory??e;if(!n||!a||a===`global`)return;let o=a===e?t:r.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[n],l=s.session_status_observed_at?.[n];try{i?.purpose===`prepend`||i?.before?await Di(a,n):await $r(a,n)}catch{return}if(i?.isStale?.())return;let u=Er()?.getTranscript(ur(a,n));wi({directory:a,sessionID:n,store:o,transcript:u,isStale:i?.isStale}),await vi({directory:a,sessionID:n,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[r,t,e]),u=(0,Z.useCallback)(async(t,n)=>{await xn();let a=typeof n==`boolean`?n:n?.force,o=typeof n==`object`?n.directory??e:e,s=r.ensureChild(o,{bootstrap:!1}),u=Fe.getScopedSdkClient(o);c(t,o);let d=i(t,o);return _l.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Er(),i=ur(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=In.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&mt(o,t)){wi({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Nl({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await gi(async()=>{let e=await u.session.get({sessionID:t,directory:o});return jl(e,`session.get`),e});if(n.data&&!e()){let r=nn(n.data);e()||Pl(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()])}})},[r,i,c,l,e]),d=(0,Z.useCallback)(async(t,i)=>{let a=i||e;if(!t||!a)return;let o=r.ensureChild(a,{bootstrap:!1}),s=Fe.getScopedSdkClient(a),c=await Cl({runtimeKey:n(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return jl(e,`session.children`),e.data??[]}});o.setState(e=>{let n=Tl(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[r,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;pr(ur(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;pr(ur(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;pr(ur(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,n)=>{if(!t)return;await xn();let i=n?.directory??e;if(!i||i===`global`)return;let a=r.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(Dl(o))throw Error(`refresh transcript busy`);try{await jr(i,t),wi({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[r,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 Il=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Ll=e=>e===`original`||e===`modified`,Rl=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},zl=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Il(t.source))return null;let n=Rl(t.startLine),r=Rl(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:Ll(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()}},Bl=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(zl).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Vl=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:Bl(e.drafts)}}),{name:`inline-comment-draft-store`}));function Hl(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 Ul(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Hl).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-C1R-GCPB.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-5agS8bsW.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-D1lIuyqO.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-BnElHSnO.js","assets/store-CUWqzRt7.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/utils-BxJEIWv5.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-DiIuWOuC.js","assets/dialog-COrLBm9O.js","assets/button-DaAoVF4X.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-D-aLQZaM.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-Ck9e8eEr.js","assets/useMobileNavigationStore-DEUCakMd.js","assets/gitApiHttp-BxGAFLTf.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-Bq3cPj2x.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-BDyY0vt6.js","assets/useEffectiveDirectory-DD7JGLuB.js","assets/useWorkerHighlightedLines-B6gvEO9K.js","assets/tooltip-BLugzWq-.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T as i,W as a,g as o,j as s,t as c,y as l}from"./useUIStore-5agS8bsW.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-D1lIuyqO.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,Dt as Te,Et as Ee,Ft as De,It as Oe,Pt as ke,Rt as Ae,Tt as je,Ut as Me,Vt as Ne,Wt as Pe,kt as Fe,vt as Ie,yt as Le,zt as Re}from"./gitApiHttp-BxGAFLTf.js";import{a as ze,n as Be,o as Ve}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as He}from"./vendor-react-DLPElpoQ.js";import{i as Ue,n as We,s as Ge,t as Ke}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as qe,R as Je,V as Ye,c as Xe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as Ze,d as Qe,i as $e,l as et,n as q,o as tt,r as nt,u as rt}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as it,r as at,t as ot}from"./clipboard-BnElHSnO.js";import{i as st,t as ct}from"./store-CUWqzRt7.js";import{$ as lt,$a as ut,$r as dt,$t as ft,A as pt,Ai as mt,An as ht,Ao as gt,Ar as _t,B as vt,Ba as yt,Br as bt,Bt as xt,Ca as St,Ci as Ct,Cn as wt,Cr as Tt,Ct as Et,D as Dt,Da as Ot,Di as kt,Dt as At,E as jt,Ei as Mt,Er as Nt,Et as Pt,F as Ft,Fa as It,Fi as Lt,Fn as Rt,Fr as zt,G as Bt,Gr as Vt,Gt as Ht,Ha as Ut,Hi as Wt,Hn as Gt,Hr as Kt,Ht as qt,I as Jt,Ia as Yt,Ii as Xt,In as Zt,J as Qt,Jr as $t,Jt as en,K as tn,Ki as nn,Kr as rn,Kt as an,L as on,La as sn,Li as cn,Ln as ln,Lr as un,M as dn,Mi as fn,Mr as pn,Mt as mn,N as hn,Ni as gn,Nr as _n,Nt as vn,O as yn,Oi as bn,Oo as xn,Ot as Sn,P as Cn,Pa as wn,Pi as Tn,Pn as En,Q as Dn,Qt as On,Ra as kn,Ri as An,Rt as jn,S as Mn,Si as Nn,Sn as Pn,T as Fn,Ta as In,Ti as Ln,To as Rn,Tr as zn,Tt as Bn,U as Vn,Ua as Hn,Un,Ur as Wn,Va as Gn,Vr as Kn,Vt as qn,Wa as Jn,X as Yn,Xa as Xn,Xi as Zn,Xt as Qn,Y as $n,Ya as er,Yi as tr,Z as nr,Zi as rr,Zt as ir,_i as ar,_n as or,a as sr,an as cr,at as lr,ba as ur,bi as dr,bn as fr,ca as pr,cn as mr,ct as hr,da as gr,di as _r,dn as vr,dt as yr,ea as br,ei as xr,en as Sr,er as Cr,et as wr,f as Tr,fa as Er,fi as Dr,fn as Or,ft as kr,g as Ar,ga as jr,gi as Mr,go as Nr,ha as Pr,hi as Fr,ho as Ir,hr as Lr,ht as Rr,i as zr,ia as Br,ii as Vr,in as Hr,it as Ur,j as Wr,ja as Gr,ji as Kr,jo as qr,jr as Jr,jt as Yr,k as Xr,ki as Zr,kr as Qr,l as J,la as $r,li as ei,ln as ti,lt as ni,m as ri,ma as ii,mi as ai,n as oi,ni as si,nn as ci,nr as li,nt as ui,oa as di,oi as fi,on as pi,pt as mi,q as hi,qi as gi,qt as _i,ri as vi,rn as yi,rr as bi,rt as xi,sa as Si,sn as Ci,ti as wi,tr as Ti,tt as Ei,ua as Di,ui as Oi,un as ki,ut as Ai,va as ji,vi as Mi,vn as Ni,vr as Pi,vt as Fi,w as Ii,wa as Li,wi as Ri,wn as zi,wr as Bi,wt as Vi,x as Hi,xi as Ui,xn as Wi,yt as Gi,z as Ki,za as qi,zr as Ji,zt as Yi}from"./useMobileNavigationStore-DEUCakMd.js";import{n as Xi,t as Zi}from"./AgentAvatar-B4fj9PIe.js";import{n as Qi,t as Y}from"./utils-BxJEIWv5.js";import{n as X}from"./Icon-DiIuWOuC.js";import{a as $i,i as ea,n as ta,o as na,r as ra,s as ia,t as aa}from"./dialog-COrLBm9O.js";import{t as oa}from"./button-DaAoVF4X.js";import{E as sa,n as ca}from"./gitApi-Ctgr4Y9i.js";import{A as la,C as ua,M as da,N as fa,O as pa,S as ma,T as ha,a as ga,b as _a,d as va,g as ya,h as ba,i as xa,j as Sa,k as Ca,n as wa,o as Ta,p as Ea,s as Da,u as Oa,v as ka,w as Aa,x as ja}from"./projectMeta-BbjPDSpU.js";import{t as Ma}from"./input-XiL2-2gG.js";import{i as Na,n as Pa,t as Fa}from"./tooltip-BLugzWq-.js";import{n as Ia,t as La}from"./useThemeSystem-DMzWVJaW.js";import{D as Ra,E as za,M as Ba,N as Va,O as Ha,Q as Ua,S as Wa,U as Ga,V as Ka,X as qa,Y as Ja,_ as Ya,a as Xa,f as Za,g as Qa,h as $a,i as eo,m as to,o as no,p as ro,r as io,t as ao,x as oo,z as so}from"./radio-CQrbmLB7.js";import{i as co,t as lo}from"./OverlayScrollbar-Mi_WH4jv.js";import{_ as uo,a as fo,d as po,f as mo,g as ho,h as go,i as _o,l as vo,m as yo,n as bo,u as xo,v as So,x as Co}from"./markdownTheme-D-aLQZaM.js";import{n as wo,r as To,t as Eo}from"./useRuntimeAPIs-DSLXJybW.js";import{a as Do,c as Oo,i as ko,r as Ao,t as jo,u as Mo}from"./appThemeRegistry-Ck9e8eEr.js";import{_ as No,a as Po,c as Fo,g as Io,l as Lo,o as Ro,t as zo,v as Bo,y as Vo}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Ho,n as Uo,o as Wo,s as Go,t as Ko}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as qo,n as Jo,t as Yo}from"./url-DMs_PgIC.js";import{_ as Xo,l as Zo,m as Qo,p as $o,s as es}from"./markdown-worker-BDyY0vt6.js";import{n as ts}from"./useEffectiveDirectory-DD7JGLuB.js";import{a as ns,c as rs,d as is,f as as,i as os,l as ss,n as cs,r as ls,s as us,t as ds}from"./FadeInOnReveal-CKKU6fKI.js";import{A as fs,C as ps,D as ms,E as hs,M as gs,O as _s,S as vs,T as ys,a as bs,b as xs,c as Ss,f as Cs,i as ws,j as Ts,k as Es,l as Ds,m as Os,n as ks,o as As,p as js,r as Ms,s as Ns,t as Ps,u as Fs,w as Is,x as Ls}from"./insertionBoundaries-BEvkmerk.js";import{A as Rs,C as zs,D as Bs,E as Vs,M as Hs,O as Us,S as Ws,T as Gs,a as Ks,b as qs,c as Js,g as Ys,h as Xs,i as Zs,j as Qs,k as $s,o as ec,p as tc,r as nc,s as rc,t as ic,v as ac,w as oc,x as sc,y as cc}from"./useWorkerHighlightedLines-B6gvEO9K.js";import{t as lc}from"./vendor-cmdk-CeAGfrLo.js";import{t as uc}from"./sortable-tabs-strip-yvKEEQEL.js";import{n as dc,t as fc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as pc,u as mc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as hc,t as gc}from"./vendor-framer-motion-DFy_BSVd.js";var Z=e(be(),1),Q=He(),$=ye(),_c=e(xe(),1),vc=`openchamber:close-embedded-session-chat`,yc=`openchamber:embedded-visibility`,bc=`openchamber:embedded-visibility-request`,xc=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,Sc=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),Cc=(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()},wc=(e,t,n,r,i,a)=>{let o=Sc(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=Cc(n,r,i,a);return e.set(t,{signature:o,src:c}),c},Tc=null,Ec=()=>{if(Tc!==null)return Tc;if(typeof window>`u`)return Tc=!1,!1;try{return Tc=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,Tc}catch{return Tc=!1,!1}},Dc=()=>{if(!Ec())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},Oc=ze(`OpenChamberMedia`);function kc(){return qr()&&Be.getPlatform()===`android`&&Be.isPluginAvailable(`OpenChamberMedia`)}async function Ac(e){if(!kc())return null;let t=await Oc.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(Be.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 jc=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Mc=1e4,Nc=15e3,Pc=3e4,Fc=3e4,Ic=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=Ie(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`))}},Mc);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`))},Nc);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`))},Fc),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=jc(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)}}},Pc))}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`,()=>{Ic.cancelAllForRuntimeSwitch()});var Lc=128,Rc=`audio/pcm;rate=16000;bits=16`,zc=()=>new Promise(e=>setTimeout(e,0)),Bc=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Vc=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??Rc,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Bc}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<Lc;){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 zc()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Hc=16e3,Uc=Hc,Wc=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Gc=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Kc=(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]=Gc(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]=Gc(e[i]*(1-s)+e[o]*s)}return a},qc=(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},Jc=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)},Yc=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Xc=e=>{if(e)try{e.disconnect()}catch{}},Zc=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Wc()!==null;function Qc(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=Yc(),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=Wc();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(tl);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=Kc(a,n.sampleRate,Hc);for(t.pending=qc(t.pending,c);t.pending.length>=Uc;){let e=t.pending.slice(0,Uc);t.pending=t.pending.slice(Uc),i.current(Jc(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(el);try{await n.close()}catch{}throw l.current=Yc(),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{}Xc(e.processor),Xc(e.source),Xc(e.gain),e.stream&&e.stream.getTracks().forEach($c);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Jc(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Yc())},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 $c(e){try{e.stop()}catch{}}function el(e){try{e.stop()}catch{}}function tl(){}var nl=1e3,rl=e=>e instanceof Error?e:Error(String(e)),il=()=>{let e=Zn.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 al(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 Vc({client:Ic,getStartOptions:il});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},nl)},[]),C=(0,Z.useCallback)(e=>{let t=rl(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)(()=>Ic.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Ic.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Qc({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 ol=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},sl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ia(),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},cl=e=>{let t=Zn(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},ll=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=it(),{currentTheme:v}=Ia(),y=Zn(ul),b=c(dl),x;t[0]===b?x=t[1]:(x=Ka(Ga(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(fl),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}=al(k),H=A===`recording`&&F===`model_download_in_progress`,U=cl(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:pl,onPointerDownCapture:ml},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]!==s||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)(sl,{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)(sl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:ol(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:s})})]}):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]=s,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 ul(e){return e.dictationEnabled}function dl(e){return e.shortcutOverrides}function fl(){return!d()&&Zc()}function pl(e){return e.preventDefault()}function ml(e){e.pointerType===`touch`&&e.preventDefault()}var hl=2e3,gl=de((e,t)=>({pending:!1,expiresAt:null,arm:(t=hl)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),_l=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}},vl=15e3,yl=100,bl=new Map,xl=new Map,Sl=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,Cl=e=>{let t=Sl(e),n=e.now??Date.now(),r=xl.get(t);if(r&&n-r.loadedAt<vl)return Promise.resolve(r.sessions);let i=bl.get(t);if(i)return i;let a=e.request().then(e=>{for(xl.delete(t);xl.size>=yl;){let e=xl.keys().next().value;if(typeof e!=`string`)break;xl.delete(e)}return xl.set(t,{loadedAt:Date.now(),sessions:e}),e});return bl.set(t,a),a.then(()=>{bl.get(t)===a&&bl.delete(t)},()=>{bl.get(t)===a&&bl.delete(t)}),a},wl=(e,t)=>e.id<t.id?-1:+(e.id>t.id),Tl=(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(wl)},El=30;function Dl(e){return e===`busy`||e===`retry`}var Ol=new Map;function kl(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Al(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 jl(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${Al(e.error)}`)}function Ml(e,t){let n=Er();if(!n)return!1;let r=n.getTranscript(ur(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>bn()}function Nl(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Pl(e,t,n){let r=[...e.getState().session],i=In.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Fl(){let e=vr(),t=xt(),r=jn(),i=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=Er();if(!r||!t)return kl({kind:`unknown`,loadedTurns:0},!1);let i=ur(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return kl(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let n=r.getChild(e);if(!n)return;let i=n.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}};Pn(a,t),Yr(n,t),n.setState(a);for(let n of t)Pr(e,n)},[r]),s=(0,Z.useCallback)((t=e)=>{let n=Ol.get(t);if(n)return Ol.delete(t),Ol.set(t,n),n;let r=new Set;for(Ol.set(t,r);Ol.size>El;){let e=Ol.keys().next().value;if(!e)break;let t=[...Ol.get(e)??[]];Ol.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((n,i=e)=>{let a=i===e?t:r.ensureChild(i,{bootstrap:!1}),c=s(i),l=wt(a.getState()),u=Mt(),d=zi({seen:c,keep:n,limit:u,preserve:l});if(o(i,d),kt()){let e=new Set([n,...c,...l]),t=(Er()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),r=(t.length>0?t:Array.from(c)).filter(t=>t===n||e.has(t)?!1:Ml(i,t));if(r.length>0){for(let e of r)c.delete(e);o(i,r)}}},[r,e,s,o,t]),l=(0,Z.useCallback)(async(n,i)=>{let a=i?.directory??e;if(!n||!a||a===`global`)return;let o=a===e?t:r.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[n],l=s.session_status_observed_at?.[n];try{i?.purpose===`prepend`||i?.before?await Di(a,n):await $r(a,n)}catch{return}if(i?.isStale?.())return;let u=Er()?.getTranscript(ur(a,n));wi({directory:a,sessionID:n,store:o,transcript:u,isStale:i?.isStale}),await vi({directory:a,sessionID:n,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[r,t,e]),u=(0,Z.useCallback)(async(t,n)=>{await xn();let a=typeof n==`boolean`?n:n?.force,o=typeof n==`object`?n.directory??e:e,s=r.ensureChild(o,{bootstrap:!1}),u=Fe.getScopedSdkClient(o);c(t,o);let d=i(t,o);return _l.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Er(),i=ur(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=In.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&mt(o,t)){wi({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Nl({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await gi(async()=>{let e=await u.session.get({sessionID:t,directory:o});return jl(e,`session.get`),e});if(n.data&&!e()){let r=nn(n.data);e()||Pl(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()])}})},[r,i,c,l,e]),d=(0,Z.useCallback)(async(t,i)=>{let a=i||e;if(!t||!a)return;let o=r.ensureChild(a,{bootstrap:!1}),s=Fe.getScopedSdkClient(a),c=await Cl({runtimeKey:n(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return jl(e,`session.children`),e.data??[]}});o.setState(e=>{let n=Tl(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[r,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;pr(ur(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;pr(ur(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;pr(ur(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,n)=>{if(!t)return;await xn();let i=n?.directory??e;if(!i||i===`global`)return;let a=r.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(Dl(o))throw Error(`refresh transcript busy`);try{await jr(i,t),wi({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[r,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 Il=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Ll=e=>e===`original`||e===`modified`,Rl=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},zl=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Il(t.source))return null;let n=Rl(t.startLine),r=Rl(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:Ll(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()}},Bl=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(zl).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Vl=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:Bl(e.drafts)}}),{name:`inline-comment-draft-store`}));function Hl(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 Ul(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Hl).join(`
3
3
 
4
4
  ---
5
5
 
@@ -6517,11 +6517,11 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T
6517
6517
  `,gu=`oc-file-type-icon-sprite-root`;(()=>{if(typeof document>`u`||document.getElementById(gu))return;let e=()=>{if(document.getElementById(gu))return;let e=document.createElement(`div`);e.id=gu,e.setAttribute(`aria-hidden`,`true`),e.style.position=`absolute`,e.style.width=`0`,e.style.height=`0`,e.style.overflow=`hidden`,e.innerHTML=hu,document.body.appendChild(e)};if(document.body){e();return}document.addEventListener(`DOMContentLoaded`,e,{once:!0})})();var _u={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`},vu={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`},yu={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`},bu=`document`,xu=(e,t)=>{if(!e)return t===`light`?`${bu}_light`:bu;if(t===`light`){let t=e.endsWith(`_light`)?e:`${e}_light`;return mu.has(t)?t:e}return e},Su=e=>typeof e==`string`&&e.trim().length>0,Cu=(e,t)=>{let n=e.replace(/\\/g,`/`).split(`/`).pop()?.toLowerCase()||``;if(_u[n])return _u[n];if(n.startsWith(`.env`))return`settings`;let r=$o(e);if(r&&vu[r])return vu[r];let i=Su(t)?t.toLowerCase():n.includes(`.`)&&n.split(`.`).pop()?.toLowerCase()||``;return i&&yu[i]?yu[i]:i&&mu.has(i)?i:bu},wu=(e,t)=>{let n=t?.isDirectory?`folder`:Cu(e,t?.extension);return`#${xu(mu.has(n)?n:bu,t?.themeVariant||`dark`)}`},Tu=e=>{let t=(0,Q.c)(12),{filePath:n,extension:r,isDirectory:i,className:a}=e,o=La()?.currentTheme.metadata.variant===`light`?`light`:`dark`,s;t[0]!==r||t[1]!==n||t[2]!==i||t[3]!==o?(s=wu(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},Eu=(0,Z.memo)(()=>{let{t:e}=it(),t=(0,Z.useRef)(null),n=Rn(e=>e.addAttachedFile),r=c(e=>e.isMobile),i=wo(),a=i.runtime.isVSCode,o=r?`h-9 w-9`:`h-7 w-7`,s=r?`h-5 w-5`:`h-[18px] w-[18px]`,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),Pi.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)(Fa,{children:[(0,$.jsx)(Na,{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
6518
  `);Pi.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),Pi.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:s})})}),(0,$.jsx)(Pa,{side:`top`,children:(0,$.jsx)(`p`,{children:e(`chat.fileAttachment.actions.attach`)})})]})]})});Eu.displayName=`FileAttachmentButton`;var Du=(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}=it(),{isMobile:l,isTablet:u}=co(),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=ts()??``,m=vo(f,p),h=`attachment-image:${n.id}`,g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=as(),t[0]=g):g=t[0];let _=Z.useRef(g),v=$u,y=ed,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||So({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)(Tu,{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-[200px]`,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,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});Du.displayName=`ImagePreview`;var Ou=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)}),ku=(0,Z.memo)(e=>{let t=(0,Q.c)(25),{file:n,onRemove:r}=e,{t:i}=it(),{displayName:a,extension:o}=Ou(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)(Tu,{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-[200px]`,_;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:td,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});ku.displayName=`VSCodeFileChip`;var Au=(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(nd);if(e.length===0){l=null;break bb0}let n=e.filter(rd),u=e.filter(id),d=n.map(ad).filter(od);o=`flex items-center gap-2 flex-wrap`,s=n.map((e,t)=>(0,$.jsx)(Du,{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)(ku,{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});Au.displayName=`AttachedVSCodeFileChips`;var ju=(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(sd);if(e.length===0){l=null;break bb0}let t=e.map(cd).filter(ld);c=`pb-4 w-full px-1`,o=`flex items-center gap-1.5 flex-wrap`,s=e.map((e,n)=>(0,$.jsx)(Du,{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});ju.displayName=`AttachedFilesList`;var Mu=(e,t)=>e.some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t),Nu=(e,t,n)=>!!n&&e.some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n&&e.vscodePath===t),Pu=(0,Z.memo)(e=>{let t=(0,Q.c)(41),{attachedFiles:n,onAddVSCodeFile:r,onAddVSCodeSelection:i}=e,{t:a}=it(),o=Rn(ud),s=Rn(dd);if(!wo().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=Mu(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?(_=Nu(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)(Tu,{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)(Tu,{filePath:l,extension:b,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs truncate max-w-[220px]`,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});Pu.displayName=`ActiveEditorFileSuggestion`;var Fu=`application/vnd.github.issue-link`,Iu=`application/vnd.github.pull-request-link`,Lu=e=>e.mime===Fu?`issue`:e.mime===Iu?`pr`:null,Ru=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??``}`},zu=e=>{let t=new Map,n=[];for(let r of e){if(r.type!==`file`||!(r.mime||r.url)||Ae(r))continue;let e=Ru(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},Bu=(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?zu(e):zu(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))},Vu=e=>e.failed||e.repositoryStatus===`error`?`error`:e.flightActive||e.repositoryStatus===`loading`?`loading`:e.hasSlimImage&&e.repositoryStatus===`ready`?`idle`:e.repositoryStatus,Hu=e=>/^(?:data|blob|https?):/i.test(e),Uu=e=>{for(let t of[e.byteSize,e.size])if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t},Wu=(e,t)=>t.some(t=>t.type===`file`&&t.mime?.startsWith(`image/`)===!0&&t.slim===!0&&!t.url&&_o(e,Uu(t))),Gu=(e,t)=>t.type!==`file`||t.mime?.startsWith(`image/`)!==!0||typeof t.url!=`string`||!t.url||Hu(t.url)?!1:_o(e,Uu(t)),Ku=e=>Y(`grid gap-2`,e===1?`grid-cols-1 max-w-56`:`grid-cols-2`),qu=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}=it(),u=ts()??``,d=vo(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)(oa,{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},Ju=e=>{let t=(0,Q.c)(11),{images:n,onLoad:r}=e,{t:i}=it(),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)(oa,{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},Yu={threshold:.01},Xu=new Set,Zu=(0,Z.memo)(({files:e,messageID:t,sessionID:n,onShowPopup:r,compact:i=!1})=>{let{t:a}=it(),o=ts()??``,s=n||e.find(e=>typeof e.sessionID==`string`&&e.sessionID)?.sessionID||``,l=ci(t,o,s||void 0),[u,d]=Z.useState(()=>fi(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${s}\n${t}`;_.current!==y&&(_.current=y,p.current=!1,m.current=null,h.current=!1,g.current=new Set,d(fi(t)??[]));for(let t of e)t.type===`file`&&t.slim===!0&&t.mime?.startsWith(`image/`)&&g.current.add(Ru(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=>Lu(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(()=>Bu(e,[...l,...u]),[u,e,l]),w=xo(),T=Z.useMemo(()=>Wu(w,C),[C,w]),[E,D]=Z.useState({scope:``,keys:Xu}),O=E.scope===y?E.keys:Xu,k=Z.useMemo(()=>{if(!fo(w))return Xu;let e=new Set;for(let t of C){let n=Ru(t);O.has(n)||Gu(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(Ru(e))),F=A.filter(e=>{let t=Ru(e);return O.has(t)?!1:e.slim===!0?T:k.has(t)}),I=new Set(F.map(Ru)),L=A.filter(e=>{let t=Ru(e);return!I.has(t)&&(g.current.has(t)||!!e.url)}),R=F.map(e=>({key:Ru(e),filename:x(e),sizeText:S(Uu(e))})),z=q((e=!1)=>{if(!N||!o||!s||!t||!e&&p.current||m.current)return;p.current=!0,h.current=!1;let n=ii(o,s,t).then(()=>{let e=fi(t);e&&e.length>0&&d(e)}).catch(()=>{let e=fi(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)});$e(N&&!P?f:null,e=>{e.some(e=>e.isIntersecting)&&z(!1)},Yu),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,s,P]);let V=N&&o&&s?gr(o,s,t).status:`ready`,H=C.some(e=>e.mime?.startsWith(`image/`)===!0&&typeof e.url==`string`&&e.url.length>0&&e.slim!==!0)?`ready`:Vu({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=>Ru(t)===Ru(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=Lu(e),a=Re(e.mime)||we(e.filename)||we(e.url);return(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:i&&e.url?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{qo(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-[220px]`,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)(Tu,{filePath:t,extension:n,isDirectory:a,className:`text-muted-foreground h-3.5 w-3.5`}),(0,$.jsx)(`div`,{className:`overflow-hidden max-w-[140px]`,children:(0,$.jsx)(`span`,{className:`truncate block`,title:t,children:t})})]})}),(0,$.jsx)(Pa,{children:(0,$.jsxs)(`p`,{children:[t,r?` (${r})`:``]})})]},`file-${Ru(e)}`)})}),R.length>0?(0,$.jsx)(Ju,{images:R,onLoad:B}):null,L.length>0?(0,$.jsx)(`div`,{className:Ku(L.length),children:L.map(e=>{let t=x(e);return(0,$.jsx)(qu,{source:e.url,filename:t,sizeText:S(Uu(e)),materializationStatus:e.url?`ready`:H,onRetry:()=>z(!0),onOpen:e.url?()=>W(e):void 0},Ru(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)(Ju,{images:R,onLoad:B}):null,C.map(e=>{let t=x(e),n=e.mime?.startsWith(`image/`),o=S(e.size),s=Lu(e);if(I.has(Ru(e)))return null;if(n&&e.url)return(0,$.jsx)(qu,{source:e.url,filename:t,sizeText:o,onOpen:()=>W(e)},Ru(e));if(n)return(0,$.jsx)(qu,{filename:t,sizeText:o,materializationStatus:H,onRetry:()=>z(!0)},Ru(e));if(s&&e.url)return(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{qo(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:s===`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)(Pa,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Ru(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&&Qo(f)?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{c.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)(Pa,{children:(0,$.jsx)(`p`,{children:a(`chat.fileAttachment.openInDiagram`)})})]},Ru(e)):(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{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`)}):Re(e.mime)||we(e.filename)||we(e.url)?(0,$.jsx)(Tu,{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)(Pa,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Ru(e))})]})});Zu.displayName=`MessageFilesDisplay`;var Qu=(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=Ku(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(fd),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});Qu.displayName=`ImageGallery`;function $u(e){let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e}function ed(e){let t=e.split(`.`);return t.length>1?t[t.length-1].toLowerCase():``}function td(e){e.target.closest(`[data-remove-button]`)}function nd(e){return e.source===`vscode`&&e.vscodeSource===`file`}function rd(e){return e.mimeType.startsWith(`image/`)}function id(e){return!e.mimeType.startsWith(`image/`)}function ad(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function od(e){return e.url}function sd(e){return e.source!==`server`&&e.source!==`vscode`&&e.mimeType.startsWith(`image/`)}function cd(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function ld(e){return e.url}function ud(e){return e.activeEditorFile}function dd(e){return e.setPendingInputText}function fd(e){return{url:e}}var pd=`text-[var(--primary)]`,md=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,hd=/(^|\s)\/(\u2003)?([A-Za-z0-9][A-Za-z0-9_-]*)/g,gd=/\[skill:([A-Za-z0-9][A-Za-z0-9_-]*)\]/g,_d=/\[command:([^\]\r\n]+)\]/g,vd=/(^|[\s([{])(@session:([A-Za-z0-9_-]+))(?=$|[\s)\]},.!?;:])/g,yd=/@([^\s]+)/g,bd=` `,xd=e=>e.replaceAll(`\\`,`/`).split(`/`).at(-1)?.replace(/\.md$/,``)??``,Sd=e=>e.trim().toLowerCase(),Cd=(e,t)=>{let n=t>0?e[t-1]:null;return!n||/(\s|\(|\)|\[|\]|\{|\}|"|'|`|,|\.|;|:)/.test(n)},wd=e=>e.includes(`/`)||e.includes(`\\`)||e.includes(`.`),Td=(e,t)=>{e.push(t)},Ed={kind:`skill`,priority:120,shouldScan:e=>e.includes(`/`)||e.includes(`[skill:`),detect:(e,t)=>{let n=[],r=t.skillNames;gd.lastIndex=0;let i;for(;(i=gd.exec(e))!==null;){let e=i[1];Td(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(hd.lastIndex=0;(i=hd.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)||Td(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:pd,href:ss(t),skillName:t}}},Dd={kind:`command`,priority:115,shouldScan:(e,t)=>e.includes(`[command:`)||!!t.commandNames?.size&&e.includes(`/`),detect:(e,t)=>{let n=[];_d.lastIndex=0;let r;for(;(r=_d.exec(e))!==null;){let e=r[1],t=xd(e);t&&Td(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(hd.lastIndex=0;(r=hd.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)||Td(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:pd})},Od={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=Sd(o),c=t.citationIcons?.get(s),l=!c&&md.test(o),u=c??(l?`image`:null);if(!u){r=a+1;continue}let d=t.citationDisplayNames?.get(s)??o;Td(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:pd,filename:t}}},kd={kind:`session`,priority:105,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[];vd.lastIndex=0;let r;for(;(r=vd.exec(e))!==null;){let i=r[3],a=r.index+r[1].length,o=a+r[2].length,s=t.sessionTitles?.get(i)??i;Td(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=[`@${bd}${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&&Td(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:pd,sessionId:t}}},Ad={kind:`file`,priority:100,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[],r=t.agentNames,i=t.filePaths,a=t.allowPathHeuristics===!0;yd.lastIndex=0;let o;for(;(o=yd.exec(e))!==null;){let t=o.index;if(!Cd(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())){Td(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&&wd(s))&&Td(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:pd,href:us(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:pd,path:t}}},jd=[Ed,Dd,Od,kd,Ad],Md=(e,t=jd)=>{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`?Od.decorate(e):e.kind===`agent`?Ad.decorate(e):{kind:e.kind,label:e.label,icon:null,className:pd}},Nd=[`/`,`[`,`@`],Pd=e=>{if(!e)return!1;for(let t of Nd)if(e.includes(t))return!0;return!1},Fd=(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)},Id=(e,t={},n=jd)=>{if(!Pd(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 Fd(r,i)},Ld=(e,t,n=jd)=>{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:Md(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}]},Rd=(e,t={},n=jd)=>{if(!Pd(e))return null;let r=Id(e,t,n);return r.length===0?null:Ld(e,r,n)},zd=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,Bd=e=>e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`\\\\`),Vd=(e,t)=>!!t?.startsWith(`image/`)||zd.test(e),Hd=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,Vd(e,i)?`image`:`attachment`)}return t},Ud=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();Bd(a)&&zd.test(a)&&t.push(a),n=i+1}return t},Wd=(e,t)=>{let n=Hd(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&&Vd(e,typeof t.mime==`string`?t.mime:void 0)&&i.push(e)}if(i.length===0)return{icons:n,displayNames:r};let a=Ud(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}},Gd=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}},Kd=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=Gd(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=rs(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:qd,children:m}),t[24]=m,t[25]=r,t[26]=i):i=t[26],i}return m};Kd.displayName=`MessageReferenceChip`;function qd(e){return e.stopPropagation()}var Jd=e=>e!==`frozen`,Yd=(e,t)=>e.length===0?t:t.length===0?e:[...e,...t],Xd=e=>e.status===`committed`&&e.current===!0,Zd=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}},Qd=(e,t)=>{let n=e.status??`queued`;return!t&&(n===`queued`||n===`retrying`||n===`failed`||n===`unresolved`)},$d=(e,t)=>Rr(e)||t?!1:[`queued`,`retrying`,`failed`,`unresolved`].includes(e.status),ef=(e,t)=>!t.frozen&&!Rr(e),tf=(e,t)=>!(t.frozen||Rr(e)),nf=e=>e.status===`sending`||e.status===`reconciling`,rf=e=>e.manualDispatchRequested===!0||e.status===`sending`||e.status===`reconciling`,af=e=>e.manualDispatchRequested===!0||e.status===`sending`||e.status===`reconciling`,of=(e,t)=>e.transportIdentity===t.transportIdentity&&e.runtimeGeneration===t.runtimeGeneration&&S(e.directory)===S(t.directory)&&e.sessionID===t.sessionID&&e.scopeID===t.scopeID,sf=(e,t)=>e.filter(e=>of(e,t)),cf=(e,t,n)=>e.filter(e=>of(e,t)&&Number.isSafeInteger(e.committedRevision)&&e.committedRevision>0&&(n===void 0||n<e.committedRevision)),lf=(e,t)=>{if(t.kind===`edit`||t.kind===`remove`||t.kind===`send`){let n=e.findIndex(e=>!Rr(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(Rr(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},uf=(e,t)=>t.reduce(lf,e),df=(e,t)=>{let n=uf(e,t),r=n.filter(e=>Rr(e)||!af(e));return r.length===n.length?n:r},ff=(e,t,n)=>({requestID:n,scopeID:e.scopeID,revision:e.revision,item:t}),pf=(e,t,n,r)=>({scopeID:e.scopeID,scopeRevision:e.revision,item:t,targetKey:n,expectedRevision:r}),mf=(e,t,n,r,i=e.items)=>{let a=i.filter(e=>!Rr(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}},hf=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},gf=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}Pe({source:n.source??`local`,vscodeSource:n.vscodeSource,mimeType:n.mimeType})&&t.set(r,`attachment`)}return t},_f=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},vf=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}},yf=e=>(e.split(`
6519
6519
  `)[0]??``)+(e.includes(`
6520
- `)?`...`:``),bf=(e,t={})=>{let n=yf(e);if(!n)return null;let r=vf(t.composerDocument);return Rd(n,{citationIcons:gf(t.attachments),sessionMentions:_f(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},xf=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`))},Sf=(0,Z.memo)(e=>{let t=(0,Q.c)(127),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,isMobile:s,onEdit:c,onSend:l,onRemove:u}=e,{t:d}=it(),f;t[0]===n?f=t[1]:(f=Rr(n),t[0]=n,t[1]=f);let p=f,m=n.queueItemID||n.id,h;t[2]!==o||t[3]!==r?(h=r&&o.has(`edit`),t[2]=o,t[3]=r,t[4]=h):h=t[4];let g=h,_;t[5]!==o||t[6]!==r?(_=r&&o.has(`remove`),t[5]=o,t[6]=r,t[7]=_):_=t[7];let v=_,y;t[8]!==o||t[9]!==r?(y=r&&o.has(`reorder`),t[8]=o,t[9]=r,t[10]=y):y=t[10];let b=y,x;t[11]!==n||t[12]!==p||t[13]!==r?(x=r&&!p&&rf(n),t[11]=n,t[12]=p,t[13]=r,t[14]=x):x=t[14];let S=x,C;t[15]!==n||t[16]!==p||t[17]!==r?(C=r&&!p&&nf(n),t[15]=n,t[16]=p,t[17]=r,t[18]=C):C=t[18];let w=C,T;t[19]!==S||t[20]!==o||t[21]!==r?(T=r&&o.has(`send`)||S,t[19]=S,t[20]=o,t[21]=r,t[22]=T):T=t[22];let E=T,D=i||p,O;t[23]!==i||t[24]!==n?(O=ef(n,{frozen:i}),t[23]=i,t[24]=n,t[25]=O):O=t[25];let k=O,A;t[26]!==i||t[27]!==n?(A=tf(n,{frozen:i}),t[26]=i,t[27]=n,t[28]=A):A=t[28];let j=A,M=r?void 0:n,N=M?.owner?.state===`unbound-legacy`||D||w,P;t[29]!==D||t[30]!==a||t[31]!==n||t[32]!==r?(P=!D&&(r?$d(n,a):Qd(n,a)),t[29]=D,t[30]=a,t[31]=n,t[32]=r,t[33]=P):P=t[33];let F=P,I=M?.failure?.recovery,L;t[34]===n?L=t[35]:(L=hf(n),t[34]=n,t[35]=L);let R=L,z=p?void 0:I?.attachments??n.attachments,B=I?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),V;t[36]!==N||t[37]!==m?(V={id:m,disabled:N},t[36]=N,t[37]=m,t[38]=V):V=t[38];let{attributes:H,listeners:U,setNodeRef:W,transform:ee,transition:G,isDragging:K}=Wo(V),te;t[39]===R?te=t[40]:(te=yf(R),t[39]=R,t[40]=te);let ne=te,re;t[41]!==z||t[42]!==B||t[43]!==R?(re=bf(R,{attachments:z,composerDocument:B}),t[41]=z,t[42]=B,t[43]=R,t[44]=re):re=t[44];let ie=re,ae=p?n.attachmentCount:z?.length??0,oe;t[45]!==n||t[46]!==u?(oe=()=>u(n),t[45]=n,t[46]=u,t[47]=oe):oe=t[47];let se=!j,ce=v||void 0,le=s?`h-7 w-3`:`size-7`,ue;t[48]===le?ue=t[49]:(ue=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`,le),t[48]=le,t[49]=ue);let de;t[50]===d?de=t[51]:(de=d(`chat.queuedMessage.removeAria`),t[50]=d,t[51]=de);let fe=v?`loader-4`:`delete-bin`,pe=s?`size-3`:`size-3.5`,me=v&&`animate-spin`,he;t[52]!==pe||t[53]!==me?(he=Y(pe,me),t[52]=pe,t[53]=me,t[54]=he):he=t[54];let ge;t[55]!==fe||t[56]!==he?(ge=(0,$.jsx)(X,{name:fe,className:he,"aria-hidden":`true`}),t[55]=fe,t[56]=he,t[57]=ge):ge=t[57];let _e;t[58]!==oe||t[59]!==se||t[60]!==ce||t[61]!==ue||t[62]!==de||t[63]!==ge?(_e=(0,$.jsx)(`button`,{type:`button`,onClick:oe,disabled:se,"aria-busy":ce,className:ue,"aria-label":de,children:ge}),t[58]=oe,t[59]=se,t[60]=ce,t[61]=ue,t[62]=de,t[63]=ge,t[64]=_e):_e=t[64];let ve=_e,ye;t[65]===ee?ye=t[66]:(ye=Vo.Translate.toString(ee),t[65]=ee,t[66]=ye);let be;t[67]!==ye||t[68]!==G?(be={transform:ye,transition:G},t[67]=ye,t[68]=G,t[69]=be):be=t[69];let xe=s?`gap-1 py-0.5`:`flex gap-1.5 md:gap-2`,Se=K&&`z-10 opacity-60`,Ce;t[70]!==xe||t[71]!==Se?(Ce=Y(`flex min-w-0 items-center`,xe,Se),t[70]=xe,t[71]=Se,t[72]=Ce):Ce=t[72];let we=b||void 0,Te=s?`h-7 w-3`:`size-auto`,Ee=N?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,De;t[73]!==Te||t[74]!==Ee?(De=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,Te,`transition-colors`,Ee),t[73]=Te,t[74]=Ee,t[75]=De):De=t[75];let Oe;t[76]===d?Oe=t[77]:(Oe=d(`chat.queuedMessage.reorderAria`),t[76]=d,t[77]=Oe);let ke=b?`loader-4`:`draggable`,Ae=s?`size-3`:`size-3.5`,je=b&&`animate-spin`,Me;t[78]!==Ae||t[79]!==je?(Me=Y(Ae,je),t[78]=Ae,t[79]=je,t[80]=Me):Me=t[80];let Ne;t[81]!==ke||t[82]!==Me?(Ne=(0,$.jsx)(X,{name:ke,className:Me,"aria-hidden":`true`}),t[81]=ke,t[82]=Me,t[83]=Ne):Ne=t[83];let Pe;t[84]!==H||t[85]!==N||t[86]!==U||t[87]!==we||t[88]!==De||t[89]!==Oe||t[90]!==Ne?(Pe=(0,$.jsx)(`button`,{type:`button`,...H,...U,disabled:N,"aria-busy":we,className:De,"aria-label":Oe,children:Ne}),t[84]=H,t[85]=N,t[86]=U,t[87]=we,t[88]=De,t[89]=Oe,t[90]=Ne,t[91]=Pe):Pe=t[91];let Fe=s?ve:null,Ie=s?`text-xs leading-5`:`typography-ui-label leading-5`,Le;t[92]===Ie?Le=t[93]:(Le=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground`,Ie),t[92]=Ie,t[93]=Le);let Re;t[94]!==ne||t[95]!==ie||t[96]!==d?(Re=ie?ie.map(jf):ne||d(`chat.queuedMessage.empty`),t[94]=ne,t[95]=ie,t[96]=d,t[97]=Re):Re=t[97];let ze;t[98]!==ae||t[99]!==d?(ze=ae>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:d(`chat.queuedMessage.attachments`,{count:ae})}),t[98]=ae,t[99]=d,t[100]=ze):ze=t[100];let Be;t[101]!==Le||t[102]!==Re||t[103]!==ze?(Be=(0,$.jsxs)(`span`,{className:Le,children:[Re,ze]}),t[101]=Le,t[102]=Re,t[103]=ze,t[104]=Be):Be=t[104];let Ve;t[105]!==k||t[106]!==F||t[107]!==g||t[108]!==s||t[109]!==n||t[110]!==c||t[111]!==l||t[112]!==p||t[113]!==E||t[114]!==d?(Ve=p?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,s?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":d(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(s?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:d(`chat.queuedMessage.queuing`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(n),disabled:!k,"aria-busy":g||void 0,"aria-label":d(`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`,s?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:g?`loader-4`:`edit`,className:Y(s?`size-3`:`size-3.5`,g&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,s?`leading-none`:`typography-ui-label`),children:d(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(n),disabled:!F,"aria-busy":E||void 0,"aria-label":d(`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`,s?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:E?`loader-4`:`send-plane`,className:Y(s?`size-3`:`size-3.5`,E&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,s?`leading-none`:`typography-ui-label`),children:d(`chat.queuedMessage.send`)})]})]}),t[105]=k,t[106]=F,t[107]=g,t[108]=s,t[109]=n,t[110]=c,t[111]=l,t[112]=p,t[113]=E,t[114]=d,t[115]=Ve):Ve=t[115];let He=!s&&!p?ve:null,Ue;t[116]!==Ve||t[117]!==He?(Ue=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[Ve,He]}),t[116]=Ve,t[117]=He,t[118]=Ue):Ue=t[118];let We;return t[119]!==W||t[120]!==be||t[121]!==Ce||t[122]!==Pe||t[123]!==Fe||t[124]!==Be||t[125]!==Ue?(We=(0,$.jsxs)(`div`,{ref:W,style:be,className:Ce,children:[Pe,Fe,Be,Ue]}),t[119]=W,t[120]=be,t[121]=Ce,t[122]=Pe,t[123]=Fe,t[124]=Be,t[125]=Ue,t[126]=We):We=t[126],We});Sf.displayName=`QueuedMessageChip`;var Cf=[],wf=[],Tf=[],Ef=new Set,Df=(e,t)=>t?Yd(b(e,x(t.sessionID)),b(e,t)):Cf,Of=(e,t)=>{if(!t)return wf;let n=Df(e,t),r=[...B(e,x(t.sessionID)),...B(e,t)];return r.length===0?n:[...n,...r]},kf=(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},Af=(0,Z.memo)(e=>{let t=(0,Q.c)(137),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:s,clientPendingItems:l,onRemoveClientPending:u,trailing:d}=e,f=l===void 0?Tf:l,{t:p}=it(),m=c(Mf),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=eu(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=>nr(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`&&Pi.error(p(`chat.chatInput.toast.queueOperationFailed`))},A=(e,t)=>{let n=b.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&Pi.error(p(e instanceof Fi&&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=We(j),N;t[19]===D?N=t[20]:(N={filters:{mutationKey:D,exact:!0,status:`pending`},select:Nf},t[19]=D,t[20]=N);let P=Ue(N),F;t[21]===D?F=t[22]:(F={filters:{mutationKey:D,exact:!0,status:`success`},select:Pf},t[21]=D,t[22]=F);let I=Ue(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=>xf(e)&&e.scopeID===z.scopeID,t[33]=z,t[34]=n),e=sf(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?cf(I.filter(Ff),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=>Of(e,o),t[44]=o,t[45]=K);let te=C(K);Z.useSyncExternalStore(on,Cn,Cn);let ne;t[46]!==G||t[47]!==f||t[48]!==te||t[49]!==o?.sessionID||t[50]!==b.items||t[51]!==b.mode?(ne=()=>{let e=o?.sessionID,t=b.mode===`server`?df(b.items,G):te,n=f.length===0?t:[...t,...f];if(!e)return n;let r=n.filter(t=>!Ft(e,t.queueItemID??``));return r.length===n.length?n:r},t[46]=G,t[47]=f,t[48]=te,t[49]=o?.sessionID,t[50]=b.items,t[51]=b.mode,t[52]=ne):ne=t[52],o?.sessionID;let re;t[53]===ne?re=t[54]:(re=ne(),t[53]=ne,t[54]=re);let ie=re,ae;if(t[55]!==G){ae=new Map;for(let e of G){let t=ae.get(e.queueItemID)??new Set;t.add(e.kind),ae.set(e.queueItemID,t)}t[55]=G,t[56]=ae}else ae=t[56];let oe=ae,se;t[57]===b.mode?se=t[58]:(se=Jd(b.mode),t[57]=b.mode,t[58]=se);let ce=!se,le=Vn(o),ue;t[59]!==le||t[60]!==ie||t[61]!==b.mode?(ue=b.mode===`server`?!1:le||ie.some(If),t[59]=le,t[60]=ie,t[61]=b.mode,t[62]=ue):ue=t[62];let de=ue,fe=C(Lf),pe;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(pe={activationConstraint:{distance:8}},t[63]=pe):pe=t[63];let me;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(me={activationConstraint:{delay:200,tolerance:6}},t[64]=me):me=t[64];let he=Bo(No(Ro,pe),No(Fo,me)),ge;t[65]!==ce||t[66]!==o||t[67]!==ie||t[68]!==fe||t[69]!==M||t[70]!==b.actions||t[71]!==b.mode||t[72]!==b.scope?(ge=e=>{if(ce)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=ie,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||Rr(r)||Rr(i)||nf(r)||nf(i))return;let a=b.scope,s=b.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=L(),l=mf(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(Rf);return}let r=ie.filter(zf),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=kf(i,o),c=kf(a,o);!s||!c||_(s)!==_(c)||fe(s,String(t.id),String(n.id),i.operationID)},t[65]=ce,t[66]=o,t[67]=ie,t[68]=fe,t[69]=M,t[70]=b.actions,t[71]=b.mode,t[72]=b.scope,t[73]=ge):ge=t[73];let _e=q(ge),ve;t[74]!==a||t[75]!==s||t[76]!==ce||t[77]!==i||t[78]!==n||t[79]!==o||t[80]!==M||t[81]!==b.actions||t[82]!==b.mode||t[83]!==b.scope?(ve=e=>{if(ce||Rr(e))return;if(b.mode===`server`){if(!o||!b.scope||!a||!s)return;let t=e,n=s.expectedRevision(),r=b.scope,c=b.actions.captureRuntime();if(c.transportIdentity!==o.transportIdentity||c.generation!==o.runtimeGeneration)return;M.mutateAsync({kind:`edit`,transportIdentity:c.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:L(),runtime:c,runtimeGeneration:c.generation,input:pf(r,t,s.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(Bf);return}if(!o)return;let t=e,r=kf(t,o);if(!r)return;let c=t.queueItemID??t.id,l=t.operationID,u=Zd(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,c,l))})()},t[74]=a,t[75]=s,t[76]=ce,t[77]=i,t[78]=n,t[79]=o,t[80]=M,t[81]=b.actions,t[82]=b.mode,t[83]=b.scope,t[84]=ve):ve=t[84];let ye=q(ve),be;t[85]!==ce||t[86]!==r||t[87]!==o||t[88]!==M||t[89]!==b.actions||t[90]!==b.mode||t[91]!==b.scope?(be=e=>{if(ce||Rr(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=L();M.mutateAsync({kind:`send`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:i,runtime:r,runtimeGeneration:r.generation,input:ff(n,t,i)}).catch(Vf);return}if(!o)return;let t=e;kf(t,o)&&r(t.queueItemID??t.id)},t[85]=ce,t[86]=r,t[87]=o,t[88]=M,t[89]=b.actions,t[90]=b.mode,t[91]=b.scope,t[92]=be):be=t[92];let xe=q(be),Se;t[93]!==f||t[94]!==ce||t[95]!==u||t[96]!==o||t[97]!==M||t[98]!==b.actions||t[99]!==b.mode||t[100]!==b.scope?(Se=e=>{if(Rr(e)){f.some(t=>t.requestID===e.requestID)&&u?.(e.requestID);return}if(ce)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:ff(n,t,i)}).catch(Hf);return}if(!o)return;let t=e,n=kf(t,o);n&&C.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[93]=f,t[94]=ce,t[95]=u,t[96]=o,t[97]=M,t[98]=b.actions,t[99]=b.mode,t[100]=b.scope,t[101]=Se):Se=t[101];let Ce=q(Se),we=ie.length>0&&(o||f.length>0);if(!we&&!d)return null;let Te=m?`px-2`:`px-4`,Ee;t[102]===Te?Ee=t[103]:(Ee=Y(`oc-composer-queue relative z-0 -mb-5 w-full`,Te),t[102]=Te,t[103]=Ee);let De=m?`rounded-[1.25rem]`:`rounded-3xl`,Oe;t[104]===De?Oe=t[105]:(Oe=Y(`overflow-hidden border border-border/60 bg-[var(--surface-subtle)] text-foreground`,De),t[104]=De,t[105]=Oe);let ke=m?`px-1.5 py-1`:`gap-0.5 px-3 pb-1 pt-1.5`,Ae;t[106]===ke?Ae=t[107]:(Ae=Y(`flex flex-col`,ke),t[106]=ke,t[107]=Ae);let je;t[108]!==ce||t[109]!==_e||t[110]!==ye||t[111]!==Ce||t[112]!==xe||t[113]!==de||t[114]!==we||t[115]!==m||t[116]!==oe||t[117]!==ie||t[118]!==he||t[119]!==b.mode?(je=we?(0,$.jsx)(zo,{sensors:he,collisionDetection:Lo,onDragEnd:_e,children:(0,$.jsx)(Ko,{items:ie.map(Uf),strategy:Go,children:ie.map(e=>(0,$.jsx)(Sf,{message:e,server:b.mode===`server`,frozen:ce,hasDispatchLock:de,pendingOperationKinds:oe.get(e.queueItemID||e.id)??Ef,isMobile:m,onEdit:ye,onSend:xe,onRemove:Ce},e.queueItemID||e.id))})}):null,t[108]=ce,t[109]=_e,t[110]=ye,t[111]=Ce,t[112]=xe,t[113]=de,t[114]=we,t[115]=m,t[116]=oe,t[117]=ie,t[118]=he,t[119]=b.mode,t[120]=je):je=t[120];let Me;t[121]!==we||t[122]!==d?(Me=d?(0,$.jsxs)($.Fragment,{children:[we?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,d]}):null,t[121]=we,t[122]=d,t[123]=Me):Me=t[123];let Ne;t[124]!==Ae||t[125]!==je||t[126]!==Me?(Ne=(0,$.jsxs)(`div`,{className:Ae,children:[je,Me]}),t[124]=Ae,t[125]=je,t[126]=Me,t[127]=Ne):Ne=t[127];let Pe=m?`h-4`:`h-5`,Fe;t[128]===Pe?Fe=t[129]:(Fe=(0,$.jsx)(`div`,{"aria-hidden":`true`,className:Pe}),t[128]=Pe,t[129]=Fe);let Ie;t[130]!==Oe||t[131]!==Ne||t[132]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:Oe,children:[Ne,Fe]}),t[130]=Oe,t[131]=Ne,t[132]=Fe,t[133]=Ie):Ie=t[133];let Le;return t[134]!==Ee||t[135]!==Ie?(Le=(0,$.jsx)(`div`,{className:Ee,children:Ie}),t[134]=Ee,t[135]=Ie,t[136]=Le):Le=t[136],Le});Af.displayName=`QueuedMessageChips`;function jf(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(Kd,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Mf(e){return e.isMobile}function Nf(e){return e.state.variables}function Pf(e){let t=e.state.variables;if(!xf(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 Ff(e){return e!==void 0}function If(e){return!Rr(e)&&(e.status===`sending`||e.status===`reconciling`)}function Lf(e){return e.reorderQueue}function Rf(){}function zf(e){return!Rr(e)}function Bf(){}function Vf(){}function Hf(){}function Uf(e){return e.queueItemID||e.id}var Wf=[0,200,400],Gf=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=Wf.map(Kf),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 Kf(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var qf=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=it(),r=J(Jf),i;e[0]===r?i=e[1]:(i=e=>{if(!r)return null;let t=e.runsByOriginalSessionID[r]??null;return t?.runtimeKey===n()?t:null},e[0]=r,e[1]=i);let a=cn(i),o=cn(Yf),s=c(Xf),l=c(Zf);if(!r||!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]!==s||e[6]!==a.directory||e[7]!==a.reviewSessionID||e[8]!==t?(f=()=>{s(a.directory,{mode:`chat`,dedupeKey:`session:${a.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=s,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)(Gf,{}),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)(oa,{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]!==r||e[36]!==o?(A=()=>o(r),e[35]=r,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)(oa,{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});qf.displayName=`AutoReviewBanner`;function Jf(e){return e.currentSessionId}function Yf(e){return e.stopRun}function Xf(e){return e.openContextPanelTab}function Zf(e){return e.isMobile}var Qf=Z.forwardRef((e,t)=>{let n=(0,Q.c)(55),{searchQuery:r,onSkillSelect:i,onClose:a,directory:o,style:s}=e,l=Z.useRef(null),u=c($f),d=fs(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=ut(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(ep);v(e),p(0);return}let t=hr(w,e,tp);t.sort(np),v(t.map(rp)),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]!==s){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]!==s?(H=d===void 0?s:{...s,maxHeight:d},n[38]=d,n[39]=s,n[40]=H):H=n[40],F=la,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]=s,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});Qf.displayName=`SkillAutocomplete`;function $f(e){return e.isMobile}function ep(e,t){return e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name)}function tp(e){return[e.name,e.description??``]}function np(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 rp(e){return e.item}function ip(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 ap(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(op).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)(ip,{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 op(e){return e.trim()}var sp=`mobile-overlay-root`,cp=16,lp=200,up=[],dp=0,fp=``,pp=0,mp=()=>{if(typeof document>`u`)return null;let e=document.getElementById(sp);return e||(e=document.createElement(`div`),e.id=sp,document.body.appendChild(e)),e},hp=({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=mp()),Z.useEffect(()=>{if(!e){m(!1),g(!1);return}let t=window.setTimeout(()=>m(!0),cp),n=window.setTimeout(()=>g(!0),266);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[e]),Z.useLayoutEffect(()=>{if(e)return pp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-opened`)),pp+=1,()=>{pp=Math.max(0,pp-1),pp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-closed`))}},[e]),Z.useEffect(()=>{if(!e)return;let t=d.current;up.push(t),dp===0&&(fp=document.body.style.overflow),dp+=1,document.body.style.overflow=`hidden`;let n=e=>{e.key===`Escape`&&up[up.length-1]===t&&f.current()};return document.addEventListener(`keydown`,n),()=>{let e=up.lastIndexOf(t);e>=0&&up.splice(e,1),dp=Math.max(0,dp-1),dp===0&&(document.body.style.overflow=fp),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:oo,onClick:e=>{Wa(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 ${lp}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)(la,{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,_c.createPortal)(v,u.current)},gp=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,_p=1e3,vp=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)(Zi,{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 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:`min-w-0 overflow-hidden`,children:(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap pl-1.5 pr-0.5 typography-micro 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 yp(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},_p),()=>{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 bp=`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,xp=e=>`flow-root ${e?`py-1`:`py-1.5`}`,Sp=`${bp} hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Cp=`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)]`,wp=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${Cp}`,Tp=`rounded-md ${Cp}`,Ep=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},Dp=e=>{if(e)try{let t=Ep();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},Op=(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`},kp=e=>{let t=Dp(e);return t?Op(t.permission,`edit`):`ask`},Ap=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},jp=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return Ap(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:Ap(n.tokens)},Mp=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}},Np=(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}},Pp=[`ask`,`allow`,`full`],Fp=`__global__`,Ip=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=Np(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=jp(d);if(h===0)return m||null;let g=Np(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=jp(o);if(s===0)return;let c=Np(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`&&jp(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=kp(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Fp){let e=t().sessionAgentEditModes.get(Fp)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=kp(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Pp.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=kp(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Pp.indexOf(a),s=Pp.indexOf(i),c=Pp[((o>=0?o:s>=0?s:0)+1)%Pp.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`})),Lp=e=>Jn([...e??[]]),Rp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,zp=(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],Rp(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 Bp(e,t){return!e&&t===`trigger-hover`}var Vp=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},Hp=e=>{let t=Vp(e);return t?(t.focus({preventScroll:!0}),!0):!1},Up=(e,t)=>e&&!t,Wp=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):[]:[]},Gp=(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 Wp(i)},Kp=()=>!0,qp=(e,t)=>(e.commandPolicy??Kp)(t),Jp=Z.createContext(null),Yp=()=>Z.useContext(Jp),Xp=e=>e,Zp=(e,t)=>t??e,Qp=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`)},$p=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,em=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},tm=(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}},nm=(e,t)=>`${e}:${t}`,rm=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,im=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},am=(e,t)=>{let n=im(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}}},om=[{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}],sm={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`}},cm=e=>e.trim().toLowerCase(),lm=(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=>cm(e)))),i=[];for(let e of r){let t=sm[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},um=e=>new Intl.NumberFormat(at(),{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:1,minimumFractionDigits:0}).format(e),dm=e=>new Intl.NumberFormat(at(),{style:`currency`,currency:`USD`,maximumFractionDigits:4,minimumFractionDigits:2}).format(e),fm=e=>new Intl.DateTimeFormat(at(),{month:`short`,day:`numeric`,year:`numeric`}).format(e),pm=`__add_provider__`,mm=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},hm=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=gp(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},gm=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=um(e);return t.endsWith(`.0`)?t.slice(0,-2):t},_m=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:dm(e),vm=e=>{let t=[];for(let n of om)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},ym=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:fm(t)},bm=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=it(),o=Z.useId(),{isReady:s,isUnavailable:l}=Qa(),u=l||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),d=Zn(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=Zn(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),p=i?.catalog,m=s&&(p?.ready??!d)&&!p?.loading&&!p?.error&&!i?.disabled,h=s&&(p?.ready??!f)&&!p?.loading&&!p?.error&&!i?.disabled,g=m&&h,_=Zn(e=>e.providers),v=p?.providers??_,y=Zn(e=>e.currentProviderId),b=Zn(e=>e.currentModelId),x=i?.selection.providerID??y,S=i?.selection.modelID??b,C=Zn(e=>e.currentVariant),w=i?i.selection.variant:C,T=Zn(e=>e.currentAgentName),E=i?i.selection.agent??void 0:T,D=Zn(e=>e.settingsDefaultVariant),O=Zn(e=>e.settingsDefaultAgent),k=Zn(e=>e.setProvider),A=Zn(e=>e.setSelectedProvider),j=Zn(e=>e.setModel),M=Zn(e=>e.setCurrentVariant),N=Zn(e=>e.getCurrentModelVariants),P=Zn(e=>e.setAgent),F=Zn(e=>e.getCurrentProvider),I=Zn(e=>e.getModelMetadata),L=Zn(e=>e.getCurrentAgent),R=Zn(e=>e.getVisibleAgents),z=Lp(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,Ce(`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),W=Fl(),ee=It(e=>e.getSessionModelSelection),G=It(e=>e.saveSessionModelSelection),K=It(e=>e.saveSessionAgentSelection),te=It(e=>e.saveAgentModelForSession),ne=It(e=>e.getAgentModelForSession),re=It(e=>e.saveAgentModelVariantForSession),ie=It(e=>e.getAgentModelVariantForSession),ae=Ip(e=>e.hasHydrated),oe=It(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=c(e=>e.toggleFavoriteModel),de=c(e=>e.reorderFavoriteModel),fe=c(e=>e.providerOrder),pe=c(e=>e.setProviderOrder),me=c(e=>e.isFavoriteModel),he=c(e=>e.addRecentModel),ge=c(e=>e.addRecentAgent),_e=c(e=>e.addRecentEffort),ve=c(e=>e.isModelSelectorOpen),ye=c(e=>e.setModelSelectorOpen),be=c(e=>e.isAgentSelectorOpen),xe=c(e=>e.setAgentSelectorOpen),Se=c(e=>e.isModelSelectorInstant),we=c(e=>e.isAgentSelectorInstant),Te=c(e=>e.setSettingsDialogOpen),Ee=c(e=>e.setSettingsPage),De=c(e=>e.hiddenModels),Oe=c(e=>e.shortcutOverrides.cycle_agent),ke=Z.useMemo(()=>Ga(`cycle_agent`,Oe?{cycle_agent:Oe}:void 0),[Oe]),{favoriteModelsList:Ae,recentModelsList:je}=pa(),{isMobile:Me}=co(),Ne=c(e=>e.isMobile),Pe=Me||Ne,Fe=Eo(),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),Zn.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),Ue=q((e,t)=>{if(Bp(e,t?.reason)){t?.cancel?.();return}xe(e),e&&Zn.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(pm),Ee(`providers`),Te(!0),Ze(!1),qe()},[A,Ee,Te,Ze,qe]),[$e,et]=Z.useState(``),[tt,nt]=Z.useState(null),[rt,at]=Z.useState(!1),ot=Z.useRef(0),st=q((e,t)=>{if(Bp(e,t?.reason)){t?.cancel?.();return}at(!1),e||(ot.current=performance.now()+200,nt(null),et(``)),Ze(e),e&&Zn.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),ct=Z.useRef(!1),lt=Z.useRef(null),ut=Z.useRef(void 0),[dt,ft]=Z.useState(new Map),[pt,mt]=Z.useState(new Set),[ht,gt]=Z.useState(0),_t=Z.useCallback(()=>{let e=()=>{let e=c.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&Hp(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),vt=Z.useCallback(e=>{let t=c.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(c.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!c.getState().isMobile&&_t())},[_t]),bt=Z.useCallback(()=>{let e=c.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Vp(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),mt(new Set),e&&!Ie&&(at(!1),ot.current=performance.now()+200))},[ve,Ie]);let[St,Ct]=Z.useState(``);Z.useEffect(()=>{be||Ct(``)},[be]);let wt=Z.useMemo(()=>z.filter(e=>yt(e.mode)),[z]),Tt=Z.useMemo(()=>St.trim()?hr(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=yp(le),Ft=i?v.find(e=>e.id===x):F(),Lt=Array.isArray(Ft?.models)?Ft.models:[],Rt=S?Lt.find(e=>e.id===S):void 0,zt=x&&S&&Rt?ha(x,Rt,I(x,S)):x&&S?I(x,S):void 0,Bt=Z.useCallback(e=>e===`Tool calling`?a(`chat.modelControls.capability.toolCalling`):e===`Reasoning`?a(`chat.modelControls.capability.reasoning`):e===`Text`?a(`chat.modelControls.modality.text`):e===`Image`?a(`chat.modelControls.modality.image`):e===`Video`?a(`chat.modelControls.modality.video`):e===`Audio`?a(`chat.modelControls.modality.audio`):e===`PDF`?a(`chat.modelControls.modality.pdf`):e,[a]),Vt=Z.useMemo(()=>vm(zt).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Ht=Z.useMemo(()=>lm(zt,`input`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Wt=Z.useMemo(()=>lm(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 Wp(e)}return i?[]:N()},[S,x,N,v,i,p?.variants,p?.variantsReady]),Kt=Gt.length>0,qt=[{label:`Input`,value:_m(zt?.cost?.input)},{label:`Output`,value:_m(zt?.cost?.output)},{label:`Cache read`,value:_m(zt?.cost?.cache_read)},{label:`Cache write`,value:_m(zt?.cost?.cache_write)}],Jt=[{label:`Context`,value:gm(zt?.limit?.context)},{label:`Output`,value:gm(zt?.limit?.output)}],Xt=Z.useRef(void 0),Zt=Z.useRef(null),Qt=Z.useRef(null),$t=H?U(H):void 0,en=Qn(H??``,$t??void 0).renderable,tn=Sr(H??``,$t??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&&(G(H,e,t),n&&te(H,n,e,t)),`applied`):`model-missing`:`provider-missing`},[v,x,S,k,j,H,te,G]),an=Z.useCallback((e,t)=>{if(i){let n=Gp(i.selection,i.catalog,e,t);if(n.length>0||i.catalog?.variants||i.catalog?.variantsReady===!1||i.selection.providerID!==e||i.selection.modelID!==t)return n;let r=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Wp(r)}let n=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Wp(n)},[S,x,v,i,p?.variants,p?.variantsReady]),on=Z.useCallback((e,t)=>{let n=i?Gp(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=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,an,i,D,le]),sn=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=Zn.getState().currentAgentName;return H?It.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(an(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,an,sn,re,i,M]),ln=Z.useCallback((e,t,n,r)=>{let i=r??sn()??void 0,a=rn(e,t,i);return a===`applied`?(he(e,t),cn(e,t,n,i),`applied`):a},[he,cn,sn,rn]);Z.useEffect(()=>{if(i)return;if(!H){Qt.current=null;return}if(!ae||v.length===0||!en||!nn?.providerID||!nn.modelID)return;let e=[H,nn.id,nn.agent??``,nn.providerID,nn.modelID,nn.variant??``].join(`|`);if(Qt.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;ln(nn.providerID,nn.modelID,t,nn.agent||E||void 0)===`applied`&&(nn.agent&&(K(H,nn.agent),re(H,nn.agent,nn.providerID,nn.modelID,t)),G(H,nn.providerID,nn.modelID),Qt.current=e)},[i,H,E,ae,v,en,nn,P,ln,an,K,re,G]),Z.useEffect(()=>{if(i)return;if(!H){Qt.current=null;return}if(!ae||v.length===0||z.length===0)return;let e=()=>{let e=ee(H),t=H?It.getState().getSessionAgentSelection(H):null;if(t){E!==t&&P(t);let e=ne(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=ne(H,e.name);if(!t)continue;E!==e.name&&P(e.name),It.getState().getSessionAgentSelection(H)||se.current||K(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?It.getState().getSessionAgentSelection(H)||se.current:null,t=(H?It.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&&rn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!en){W.isLoading(H)||W.ensureSessionRenderable(H);return}nn||t()}},[i,H,en,nn,z,B,E,ee,ne,P,rn,K,ae,v,W]),Z.useEffect(()=>{if(i||!ae)return;let e=new AbortController;return(async()=>{try{if(E!==Xt.current&&(Xt.current=E,E&&H)){let t=Zt.current===E;if(Zt.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=rn(n.providerId,n.modelId,E);if(e===`applied`||e===`provider-missing`)return}let r=Zn.getState().getAgentModelSelection(E);if(r){let e=rn(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=rn(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,rn,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(Gt.length===0){Ke.current=!1,M(void 0);return}if(w&&!Gt.includes(w)){M(void 0);return}if(!H){if(!w&&!Ke.current){let e=D&&Gt.includes(D)?D:void 0;M(e)}return}let e=ie(H,E,x,S),t=e&&Gt.includes(e)?e:D&&Gt.includes(D)?D:void 0;M(t),Ke.current=!1},[i,Gt,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=Gn(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{Zt.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=kn(z,E,e);t&&un(t,{closeModelSelector:!1})},[z,E,un]),fn=Z.useCallback(e=>{let t=ke&&!ke.includes(`shift`)?Ja(`shift+${ke}`):``;return t&&so(e,t)?-1:so(e,ke)?1:null},[ke]),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||Zn.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),r()}).catch(()=>void 0);return}try{let i=n?.agentName??sn()??void 0,a=n?.applyVariant?ln(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}mn(i,e,t,n?.applyVariant?n.variant:Zn.getState().currentVariant),n?.applyVariant||he(e,t),r(),Ie&&qe()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},gn=(e,t)=>Ut(e,t,{maxLength:40}),_n=()=>v.find(e=>e.id===x)?.name||x,vn=()=>{if(!S)return a(`chat.modelControls.selectModel`);let e=Lt.find(e=>e.id===S);return gn(e,S)||a(`chat.modelControls.selectModel`)},yn=vn(),bn=Z.useRef(null),xn=zp(bn,[yn,w,Ie]),Sn=()=>{if(!le){let e=B.find(e=>e.name===`build`)||B[0];return e?Cn(e.name):`Select Agent`}let e=z.find(e=>e.name===le);return Cn(e?e.name:le)},Cn=e=>e.charAt(0).toUpperCase()+e.slice(1),wn=Z.useCallback(e=>{Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ge(e)},500)},[]),Tn=Z.useCallback(()=>{Ye.current&&clearTimeout(Ye.current)},[]);Z.useEffect(()=>()=>{Ye.current&&clearTimeout(Ye.current)},[]);let En=()=>!Ie||We!==`model`?null:(0,$.jsx)(hp,{open:!0,onClose:Je,title:zt?.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)(mm,{iconName:t,label:n},`cap-${e}`),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:n})]},e))})]}),(Ht.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:[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)(mm,{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)(mm,{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:gm(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:gm(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:ym(zt.release_date)})]})})]}):null]})}),Dn=()=>{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=im(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=am(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)(hp,{open:!0,onClose:Je,title:Cn(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)(hm,{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)(hm,{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)(hm,{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)(to,{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)}).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:Ae,recentModels:je,hiddenModels:De,providerOrder:fe,isFavorite:me,onToggleFavorite:ue,getMetadata:I}):null,An=()=>Ie?(0,$.jsx)(Ya,{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)(la,{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=Xi(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)(Zi,{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)(Pa,{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||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)(mm,{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)(mm,{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)(mm,{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:ym(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(ct.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=nm(n,r),o=dt.has(a),s=dt.get(a),c=o?s:x===n&&S===r?w:void 0,l=[void 0,...i],u=l.indexOf(c),d=l[((u>=0?u:0)+(e.key===`ArrowRight`?1:-1)+l.length)%l.length];return ft(e=>{let t=new Map(e);return t.set(a,d),t}),mt(e=>{let t=new Set(e);return t.add(a),t}),gt(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=nm(e.providerID,e.modelID),n=dt.get(t),r=pt.has(t),i=sn();hn(e.providerID,e.modelID,r?{applyVariant:!0,variant:n,agentName:i}:{agentName:i})},r=e=>{let t=fn(e);t&&(e.preventDefault(),e.stopPropagation(),ct.current=!0,dn(t))},i=e=>e?.trim()?Yt(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()<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})=>{if(an(e.providerID,e.modelID).length===0)return null;let n=nm(e.providerID,e.modelID),r=dt.has(n),o=dt.get(n),s=r?o:t?w:void 0,c=pt.has(n);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`,c||s?`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(s)}),(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=an(tt.providerID,tt.modelID),t=nm(tt.providerID,tt.modelID),n=dt.has(t),r=dt.get(t),s=tt.providerID===x&&tt.modelID===S,c=n?r:s?w:void 0,l=Ut(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)(Ca,{modelId:tt.modelID,providerId:tt.providerID,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate typography-meta font-medium text-foreground`,children:l}),(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===c||!e&&!c;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)(ip,{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?Yt(w):null;return(0,$.jsxs)(Fa,{open:!Xe&&rt,onOpenChange:s,delayDuration:200,children:[Ie?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>He(`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`,wp):`opacity-60 cursor-not-allowed`),children:m?(0,$.jsxs)($.Fragment,{children:[x||S?(0,$.jsx)(Ca,{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:bn,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`,xn&&`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)(za,{open:m&&Xe,onOpenChange:m?st:void 0,onOpenChangeComplete:e=>{e||vt(`model`)},children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(Va,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,wp),children:[m?x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ca,{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:bn,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`,xn&&`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)(Ra,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,Se&&rm),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)(ua,{providers:v,favoriteModels:Ae,recentModels:je,getMetadata:I,searchQuery:$e,onSearchQueryChange:et,onSelect:n,labels:c,selectedModel:x&&S?{providerID:x,modelID:S}:null,hiddenModels:De,onActiveKeyDown:t,onActiveEntryChange:e=>{ut.current=e},onVariantKey:e,isFavorite:e=>me(e.providerID,e.modelID),onToggleFavorite:e=>ue(e.providerID,e.modelID),renderRowEnd:l,renderVersion:ht,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?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:Xe&&!tt,onEscape:()=>{if(tt){nt(null);return}Ze(!1)}})]})})]}),jn()]})},Nn=()=>{if(!Dt)return(0,$.jsx)(Pa,{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=im(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=am(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)(Pa,{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(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)(hm,{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)(hm,{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)(hm,{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=le?Xi(le):null;return Ie?(0,$.jsx)(`button`,{type:`button`,onClick:h?()=>He(`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`,Tp,h?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:h?(0,$.jsx)(vp,{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)(Fa,{delayDuration:600,children:[(0,$.jsxs)(za,{open:h&&be,onOpenChange:h?Ue:void 0,onOpenChangeComplete:e=>{e||vt(`agent`)},children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(Va,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,Tp),children:h?(0,$.jsx)(vp,{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)(Ra,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,we&&rm),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)(Ma,{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)(la,{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)(Ha,{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)(Ba,{})]}),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)(Ha,{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)(Zi,{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)(ip,{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`,Pe&&`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`,jt,Pe&&`overflow-hidden`),children:[In,Mn()]})}),On(),An(),En(),Dn()]})},xm=[{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`}],Sm=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=it(),i=gl(Cm),a=c(wm),o;t[0]===a?o=t[1]:(o=Ka(Ga(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let s=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]===s?d=t[7]:(d=(0,$.jsx)(ap,{shortcut:s,className:`opacity-[0.35] [&_[data-slot=kbd]]:rounded-md [&_[data-slot=kbd]]:border-0 [&_[data-slot=kbd]]:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] [&_[data-slot=kbd]]:text-muted-foreground/65 [&_[data-slot=kbd]]:shadow-none`}),t[6]=s,t[7]=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=xm.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)(ip,{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 Cm(e){return e.pending}function wm(e){return e.shortcutOverrides}var Tm=28,Em=8,Dm=10.5,Om=Math.PI/2,km=e=>Array.from({length:Em},(t,n)=>{let r=n/Em*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*Dm,Math.sin(r)*Dm]}),Am=[km(0),km(Om),km(Math.PI),km(Math.PI*1.5)],jm=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,Mm=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/Tm,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:Am[0].map(Nm)}),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 Nm(e,t){return(0,$.jsx)(`span`,{className:`oc-morph-orb-dot`,style:{"--m-1":jm(Am[0][t]),"--m-2":jm(Am[1][t]),"--m-3":jm(Am[2][t]),"--m-4":jm(Am[3][t])}},t)}var Pm=1200,Fm=1e9,Im=0xe8d4a51000,Lm=e=>e>=Im?e:e>=Fm?e*1e3:Date.now()+e;function Rm({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o}){let{locale:s,t:c}=it(),[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,b]=Z.useState(null),[x,S]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;S(Date.now());let t=window.setInterval(()=>S(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){b(null);return}let t=Lm(e),n=()=>{let e=Math.max(0,t-Date.now());b(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let C=q(()=>{v.current&&=(clearTimeout(v.current),null)}),w=q((e,t,n=!1)=>{C(),_.current=null,u(e),f(t),h.current=n,g.current=Date.now()}),T=q(()=>{if(v.current)return;let e=Date.now()-g.current,t=Math.max(0,Pm-e);v.current=setTimeout(()=>{v.current=null;let e=_.current;e&&w(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(!e){C(),_.current=null,u(null),f(!1),h.current=!1;return}if(a){C(),_.current=null;return}let t=i?c(`chat.assistantStatus.waitingForPermission`):n,o=!!i,s=!!r&&!o;if(t){if(!p.current){w(t,o,s);return}if((t!==p.current||o!==m.current)&&!(s&&h.current)){if(Date.now()-g.current>=Pm){w(t,o,s);return}_.current={text:t,permission:o,generic:s},T()}}},[e,n,r,i,a,c]),Z.useEffect(()=>()=>C(),[]),!e)return null;if(a){let e=y!==null&&y>0?new Intl.RelativeTimeFormat(s,{numeric:`always`,style:`short`}).format(y,`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)(Mm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:n})]})})}if(!l)return null;let E=l,D=typeof o==`number`?pt(Math.max(0,x-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":d?`assertive`:`polite`,"aria-label":E,"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)(Mm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:E}),D?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:D}):null]})})}var zm={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Bm={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Vm={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:zm},Hm=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?zm:Bm}),Um=Z.createContext(Vm),Wm=()=>Z.useContext(Um),Gm=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}),Km=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,qm={containerType:`inline-size`,containerName:`status-row`},Jm=[],Ym=e=>{let t=(0,Q.c)(93),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:s,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}=it(),[w,T]=Z.useState(!1),E=Wm(),D=J(Xm),O=E.sessionId??D,k;t[0]!==O||t[1]!==S?(k=e=>!S||!O?Jm:e.todo[O]??Jm,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=si(j),N;bb0:{if(!O){N=Jm;break bb0}if(A.length>0){N=A;break bb0}N=M??Jm}let P=N,F=c(Zm),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(Qm),t[8]=P,t[9]=R);let z=R,B;t[10]===z?B=t[11]:(B=z.find($m)||z.find(eh)||null,t[10]=z,t[11]=B);let V=B,H;t[12]===z?H=t[13]:(H=z.find(th)??null,t[12]=z,t[13]=H);let U=H,W;t[14]===P?W=t[15]:(W=P.filter(nh),t[14]=P,t[15]=W);let ee=W.length,G;t[16]===P?G=t[17]:(G=P.filter(rh),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(ih),t[21]=z,t[22]=re);let ie=re.length,ae;t[23]===z?ae=t[24]:(ae=z.filter(ah),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=x&&(v||!!o||!!f),fe=!!_,pe=!f&&!ue&&(o||!s),me=ue||de||le||fe,he=Z.useRef(null),ge=Z.useRef(null),_e=Z.useRef(null),ve,ye;t[28]===w?(ve=t[29],ye=t[30]):(ve=()=>{let e=ge.current,t=_e.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))},ye=[w],t[28]=w,t[29]=ve,t[30]=ye),Z.useLayoutEffect(ve,ye);let be,xe;t[31]===w?(be=t[32],xe=t[33]):(be=()=>{if(!w)return;let e=e=>{he.current&&!he.current.contains(e.target)&&T(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},xe=[w],t[31]=w,t[32]=be,t[33]=xe),Z.useEffect(be,xe);let Se;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(Se=()=>T(oh),t[34]=Se):Se=t[34];let Ce=q(Se),we;t[35]!==ce.active||t[36]!==ce.left||t[37]!==C?(we=C(`chat.statusRow.summary.activeLeft`,{active:ce.active,left:ce.left}),t[35]=ce.active,t[36]=ce.left,t[37]=C,t[38]=we):we=t[38];let Te=we,Ee;t[39]!==V||t[40]!==le||t[41]!==L||t[42]!==w||t[43]!==ne||t[44]!==C||t[45]!==Te||t[46]!==Ce?(Ee=le?(0,$.jsxs)(`button`,{type:`button`,onClick:Ce,className:Y(Bs,`shrink-0`),"aria-label":Te,title:Te,children:[(0,$.jsx)(X,{name:`list-check-3`,className:Us}),!L&&V?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,$s),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:Rs,"aria-hidden":`true`,children:[ne.completed,`/`,ne.total]}),w?(0,$.jsx)(X,{name:`arrow-up-s`,className:Us}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Us})]}):null,t[39]=V,t[40]=le,t[41]=L,t[42]=w,t[43]=ne,t[44]=C,t[45]=Te,t[46]=Ce,t[47]=Ee):Ee=t[47];let De=Ee;if(!me)return null;let Oe=!fe&&`chat-column`,ke;t[48]===Oe?ke=t[49]:(ke=Y(`mb-1`,Oe),t[48]=Oe,t[49]=ke);let Ae=fe&&`px-3`,je;t[50]===Ae?je=t[51]:(je=Y(`flex items-center justify-between py-0.5 gap-2 h-[1.2rem]`,Ae),t[50]=Ae,t[51]=je);let Me=!fe&&`overflow-x-hidden`,Ne;t[52]===Me?Ne=t[53]:(Ne=Y(`flex-1 flex items-center min-w-0 gap-2`,Me),t[52]=Me,t[53]=Ne);let Pe;t[54]!==g||t[55]!==O||t[56]!==ue||t[57]!==i||t[58]!==F||t[59]!==a||t[60]!==v||t[61]!==_||t[62]!==l||t[63]!==pe||t[64]!==f||t[65]!==x||t[66]!==y||t[67]!==C||t[68]!==u?(Pe=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&&pe?(0,$.jsx)(Rm,{isWorking:v,isMobile:F,statusText:y,isGenericStatus:i,isWaitingForPermission:a,retryInfo:l,turnStartedAt:u,agentName:g},O??`no-session`):_||null,t[54]=g,t[55]=O,t[56]=ue,t[57]=i,t[58]=F,t[59]=a,t[60]=v,t[61]=_,t[62]=l,t[63]=pe,t[64]=f,t[65]=x,t[66]=y,t[67]=C,t[68]=u,t[69]=Pe):Pe=t[69];let Fe;t[70]!==Ne||t[71]!==Pe?(Fe=(0,$.jsx)(`div`,{className:Ne,children:Pe}),t[70]=Ne,t[71]=Pe,t[72]=Fe):Fe=t[72];let Ie=!fe&&`-mr-3`,Le;t[73]===Ie?Le=t[74]:(Le=Y(`relative flex items-center gap-2 flex-shrink-0`,Ie),t[73]=Ie,t[74]=Le);let Re;t[75]!==U||t[76]!==le||t[77]!==w||t[78]!==ne||t[79]!==C||t[80]!==z?(Re=w&&le&&(0,$.jsxs)(`div`,{style:Vs,className:Y(qs,`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:ge,className:oc,children:z.map((e,t)=>(0,$.jsx)(cc,{todo:e,isActive:e===U,activeRef:e===U?_e:void 0},e.id??`todo-${t}`))})]}),t[75]=U,t[76]=le,t[77]=w,t[78]=ne,t[79]=C,t[80]=z,t[81]=Re):Re=t[81];let ze;t[82]!==Le||t[83]!==Re||t[84]!==De?(ze=(0,$.jsxs)(`div`,{className:Le,ref:he,children:[De,Re]}),t[82]=Le,t[83]=Re,t[84]=De,t[85]=ze):ze=t[85];let Be;t[86]!==je||t[87]!==Fe||t[88]!==ze?(Be=(0,$.jsxs)(`div`,{className:je,children:[Fe,ze]}),t[86]=je,t[87]=Fe,t[88]=ze,t[89]=Be):Be=t[89];let Ve;return t[90]!==ke||t[91]!==Be?(Ve=(0,$.jsx)(`div`,{className:ke,style:qm,children:Be}),t[90]=ke,t[91]=Be,t[92]=Ve):Ve=t[92],Ve};function Xm(e){return e.currentSessionId}function Zm(e){return e.isMobile}function Qm(e){return e.status!==`cancelled`}function $m(e){return e.status===`in_progress`}function eh(e){return e.status===`pending`}function th(e){return e.status===`in_progress`}function nh(e){return e.status!==`cancelled`}function rh(e){return e.status===`completed`}function ih(e){return e.status===`in_progress`}function ah(e){return e.status===`in_progress`||e.status===`pending`}function oh(e){return!e}var sh=Z.createContext(null),ch=e=>{let t=(0,Q.c)(3),{actions:n,children:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(sh.Provider,{value:n,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},lh=()=>Z.useContext(sh),uh=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),dh=e=>`insertions`in e,fh=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},ph=e=>{let t=0,n=0;for(let r of e.split(`
6520
+ `)?`...`:``),bf=(e,t={})=>{let n=yf(e);if(!n)return null;let r=vf(t.composerDocument);return Rd(n,{citationIcons:gf(t.attachments),sessionMentions:_f(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},xf=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`))},Sf=(0,Z.memo)(e=>{let t=(0,Q.c)(127),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,isMobile:s,onEdit:c,onSend:l,onRemove:u}=e,{t:d}=it(),f;t[0]===n?f=t[1]:(f=Rr(n),t[0]=n,t[1]=f);let p=f,m=n.queueItemID||n.id,h;t[2]!==o||t[3]!==r?(h=r&&o.has(`edit`),t[2]=o,t[3]=r,t[4]=h):h=t[4];let g=h,_;t[5]!==o||t[6]!==r?(_=r&&o.has(`remove`),t[5]=o,t[6]=r,t[7]=_):_=t[7];let v=_,y;t[8]!==o||t[9]!==r?(y=r&&o.has(`reorder`),t[8]=o,t[9]=r,t[10]=y):y=t[10];let b=y,x;t[11]!==n||t[12]!==p||t[13]!==r?(x=r&&!p&&rf(n),t[11]=n,t[12]=p,t[13]=r,t[14]=x):x=t[14];let S=x,C;t[15]!==n||t[16]!==p||t[17]!==r?(C=r&&!p&&nf(n),t[15]=n,t[16]=p,t[17]=r,t[18]=C):C=t[18];let w=C,T;t[19]!==S||t[20]!==o||t[21]!==r?(T=r&&o.has(`send`)||S,t[19]=S,t[20]=o,t[21]=r,t[22]=T):T=t[22];let E=T,D=i||p,O;t[23]!==i||t[24]!==n?(O=ef(n,{frozen:i}),t[23]=i,t[24]=n,t[25]=O):O=t[25];let k=O,A;t[26]!==i||t[27]!==n?(A=tf(n,{frozen:i}),t[26]=i,t[27]=n,t[28]=A):A=t[28];let j=A,M=r?void 0:n,N=M?.owner?.state===`unbound-legacy`||D||w,P;t[29]!==D||t[30]!==a||t[31]!==n||t[32]!==r?(P=!D&&(r?$d(n,a):Qd(n,a)),t[29]=D,t[30]=a,t[31]=n,t[32]=r,t[33]=P):P=t[33];let F=P,I=M?.failure?.recovery,L;t[34]===n?L=t[35]:(L=hf(n),t[34]=n,t[35]=L);let R=L,z=p?void 0:I?.attachments??n.attachments,B=I?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),V;t[36]!==N||t[37]!==m?(V={id:m,disabled:N},t[36]=N,t[37]=m,t[38]=V):V=t[38];let{attributes:H,listeners:U,setNodeRef:W,transform:ee,transition:G,isDragging:K}=Wo(V),te;t[39]===R?te=t[40]:(te=yf(R),t[39]=R,t[40]=te);let ne=te,re;t[41]!==z||t[42]!==B||t[43]!==R?(re=bf(R,{attachments:z,composerDocument:B}),t[41]=z,t[42]=B,t[43]=R,t[44]=re):re=t[44];let ie=re,ae=p?n.attachmentCount:z?.length??0,oe;t[45]!==n||t[46]!==u?(oe=()=>u(n),t[45]=n,t[46]=u,t[47]=oe):oe=t[47];let se=!j,ce=v||void 0,le=s?`h-7 w-3`:`size-7`,ue;t[48]===le?ue=t[49]:(ue=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`,le),t[48]=le,t[49]=ue);let de;t[50]===d?de=t[51]:(de=d(`chat.queuedMessage.removeAria`),t[50]=d,t[51]=de);let fe=v?`loader-4`:`delete-bin`,pe=s?`size-3`:`size-3.5`,me=v&&`animate-spin`,he;t[52]!==pe||t[53]!==me?(he=Y(pe,me),t[52]=pe,t[53]=me,t[54]=he):he=t[54];let ge;t[55]!==fe||t[56]!==he?(ge=(0,$.jsx)(X,{name:fe,className:he,"aria-hidden":`true`}),t[55]=fe,t[56]=he,t[57]=ge):ge=t[57];let _e;t[58]!==oe||t[59]!==se||t[60]!==ce||t[61]!==ue||t[62]!==de||t[63]!==ge?(_e=(0,$.jsx)(`button`,{type:`button`,onClick:oe,disabled:se,"aria-busy":ce,className:ue,"aria-label":de,children:ge}),t[58]=oe,t[59]=se,t[60]=ce,t[61]=ue,t[62]=de,t[63]=ge,t[64]=_e):_e=t[64];let ve=_e,ye;t[65]===ee?ye=t[66]:(ye=Vo.Translate.toString(ee),t[65]=ee,t[66]=ye);let be;t[67]!==ye||t[68]!==G?(be={transform:ye,transition:G},t[67]=ye,t[68]=G,t[69]=be):be=t[69];let xe=s?`gap-1 py-0.5`:`flex gap-1.5 md:gap-2`,Se=K&&`z-10 opacity-60`,Ce;t[70]!==xe||t[71]!==Se?(Ce=Y(`flex min-w-0 items-center`,xe,Se),t[70]=xe,t[71]=Se,t[72]=Ce):Ce=t[72];let we=b||void 0,Te=s?`h-7 w-3`:`size-auto`,Ee=N?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,De;t[73]!==Te||t[74]!==Ee?(De=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,Te,`transition-colors`,Ee),t[73]=Te,t[74]=Ee,t[75]=De):De=t[75];let Oe;t[76]===d?Oe=t[77]:(Oe=d(`chat.queuedMessage.reorderAria`),t[76]=d,t[77]=Oe);let ke=b?`loader-4`:`draggable`,Ae=s?`size-3`:`size-3.5`,je=b&&`animate-spin`,Me;t[78]!==Ae||t[79]!==je?(Me=Y(Ae,je),t[78]=Ae,t[79]=je,t[80]=Me):Me=t[80];let Ne;t[81]!==ke||t[82]!==Me?(Ne=(0,$.jsx)(X,{name:ke,className:Me,"aria-hidden":`true`}),t[81]=ke,t[82]=Me,t[83]=Ne):Ne=t[83];let Pe;t[84]!==H||t[85]!==N||t[86]!==U||t[87]!==we||t[88]!==De||t[89]!==Oe||t[90]!==Ne?(Pe=(0,$.jsx)(`button`,{type:`button`,...H,...U,disabled:N,"aria-busy":we,className:De,"aria-label":Oe,children:Ne}),t[84]=H,t[85]=N,t[86]=U,t[87]=we,t[88]=De,t[89]=Oe,t[90]=Ne,t[91]=Pe):Pe=t[91];let Fe=s?ve:null,Ie=s?`text-xs leading-5`:`typography-ui-label leading-5`,Le;t[92]===Ie?Le=t[93]:(Le=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground`,Ie),t[92]=Ie,t[93]=Le);let Re;t[94]!==ne||t[95]!==ie||t[96]!==d?(Re=ie?ie.map(jf):ne||d(`chat.queuedMessage.empty`),t[94]=ne,t[95]=ie,t[96]=d,t[97]=Re):Re=t[97];let ze;t[98]!==ae||t[99]!==d?(ze=ae>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:d(`chat.queuedMessage.attachments`,{count:ae})}),t[98]=ae,t[99]=d,t[100]=ze):ze=t[100];let Be;t[101]!==Le||t[102]!==Re||t[103]!==ze?(Be=(0,$.jsxs)(`span`,{className:Le,children:[Re,ze]}),t[101]=Le,t[102]=Re,t[103]=ze,t[104]=Be):Be=t[104];let Ve;t[105]!==k||t[106]!==F||t[107]!==g||t[108]!==s||t[109]!==n||t[110]!==c||t[111]!==l||t[112]!==p||t[113]!==E||t[114]!==d?(Ve=p?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,s?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":d(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(s?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:d(`chat.queuedMessage.queuing`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(n),disabled:!k,"aria-busy":g||void 0,"aria-label":d(`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`,s?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:g?`loader-4`:`edit`,className:Y(s?`size-3`:`size-3.5`,g&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,s?`leading-none`:`typography-ui-label`),children:d(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(n),disabled:!F,"aria-busy":E||void 0,"aria-label":d(`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`,s?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:E?`loader-4`:`send-plane`,className:Y(s?`size-3`:`size-3.5`,E&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,s?`leading-none`:`typography-ui-label`),children:d(`chat.queuedMessage.send`)})]})]}),t[105]=k,t[106]=F,t[107]=g,t[108]=s,t[109]=n,t[110]=c,t[111]=l,t[112]=p,t[113]=E,t[114]=d,t[115]=Ve):Ve=t[115];let He=!s&&!p?ve:null,Ue;t[116]!==Ve||t[117]!==He?(Ue=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[Ve,He]}),t[116]=Ve,t[117]=He,t[118]=Ue):Ue=t[118];let We;return t[119]!==W||t[120]!==be||t[121]!==Ce||t[122]!==Pe||t[123]!==Fe||t[124]!==Be||t[125]!==Ue?(We=(0,$.jsxs)(`div`,{ref:W,style:be,className:Ce,children:[Pe,Fe,Be,Ue]}),t[119]=W,t[120]=be,t[121]=Ce,t[122]=Pe,t[123]=Fe,t[124]=Be,t[125]=Ue,t[126]=We):We=t[126],We});Sf.displayName=`QueuedMessageChip`;var Cf=[],wf=[],Tf=[],Ef=new Set,Df=(e,t)=>t?Yd(b(e,x(t.sessionID)),b(e,t)):Cf,Of=(e,t)=>{if(!t)return wf;let n=Df(e,t),r=[...B(e,x(t.sessionID)),...B(e,t)];return r.length===0?n:[...n,...r]},kf=(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},Af=(0,Z.memo)(e=>{let t=(0,Q.c)(137),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:s,clientPendingItems:l,onRemoveClientPending:u,trailing:d}=e,f=l===void 0?Tf:l,{t:p}=it(),m=c(Mf),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=eu(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=>nr(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`&&Pi.error(p(`chat.chatInput.toast.queueOperationFailed`))},A=(e,t)=>{let n=b.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&Pi.error(p(e instanceof Fi&&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=We(j),N;t[19]===D?N=t[20]:(N={filters:{mutationKey:D,exact:!0,status:`pending`},select:Nf},t[19]=D,t[20]=N);let P=Ue(N),F;t[21]===D?F=t[22]:(F={filters:{mutationKey:D,exact:!0,status:`success`},select:Pf},t[21]=D,t[22]=F);let I=Ue(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=>xf(e)&&e.scopeID===z.scopeID,t[33]=z,t[34]=n),e=sf(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?cf(I.filter(Ff),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=>Of(e,o),t[44]=o,t[45]=K);let te=C(K);Z.useSyncExternalStore(on,Cn,Cn);let ne;t[46]!==G||t[47]!==f||t[48]!==te||t[49]!==o?.sessionID||t[50]!==b.items||t[51]!==b.mode?(ne=()=>{let e=o?.sessionID,t=b.mode===`server`?df(b.items,G):te,n=f.length===0?t:[...t,...f];if(!e)return n;let r=n.filter(t=>!Ft(e,t.queueItemID??``));return r.length===n.length?n:r},t[46]=G,t[47]=f,t[48]=te,t[49]=o?.sessionID,t[50]=b.items,t[51]=b.mode,t[52]=ne):ne=t[52],o?.sessionID;let re;t[53]===ne?re=t[54]:(re=ne(),t[53]=ne,t[54]=re);let ie=re,ae;if(t[55]!==G){ae=new Map;for(let e of G){let t=ae.get(e.queueItemID)??new Set;t.add(e.kind),ae.set(e.queueItemID,t)}t[55]=G,t[56]=ae}else ae=t[56];let oe=ae,se;t[57]===b.mode?se=t[58]:(se=Jd(b.mode),t[57]=b.mode,t[58]=se);let ce=!se,le=Vn(o),ue;t[59]!==le||t[60]!==ie||t[61]!==b.mode?(ue=b.mode===`server`?!1:le||ie.some(If),t[59]=le,t[60]=ie,t[61]=b.mode,t[62]=ue):ue=t[62];let de=ue,fe=C(Lf),pe;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(pe={activationConstraint:{distance:8}},t[63]=pe):pe=t[63];let me;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(me={activationConstraint:{delay:200,tolerance:6}},t[64]=me):me=t[64];let he=Bo(No(Ro,pe),No(Fo,me)),ge;t[65]!==ce||t[66]!==o||t[67]!==ie||t[68]!==fe||t[69]!==M||t[70]!==b.actions||t[71]!==b.mode||t[72]!==b.scope?(ge=e=>{if(ce)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=ie,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||Rr(r)||Rr(i)||nf(r)||nf(i))return;let a=b.scope,s=b.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=L(),l=mf(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(Rf);return}let r=ie.filter(zf),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=kf(i,o),c=kf(a,o);!s||!c||_(s)!==_(c)||fe(s,String(t.id),String(n.id),i.operationID)},t[65]=ce,t[66]=o,t[67]=ie,t[68]=fe,t[69]=M,t[70]=b.actions,t[71]=b.mode,t[72]=b.scope,t[73]=ge):ge=t[73];let _e=q(ge),ve;t[74]!==a||t[75]!==s||t[76]!==ce||t[77]!==i||t[78]!==n||t[79]!==o||t[80]!==M||t[81]!==b.actions||t[82]!==b.mode||t[83]!==b.scope?(ve=e=>{if(ce||Rr(e))return;if(b.mode===`server`){if(!o||!b.scope||!a||!s)return;let t=e,n=s.expectedRevision(),r=b.scope,c=b.actions.captureRuntime();if(c.transportIdentity!==o.transportIdentity||c.generation!==o.runtimeGeneration)return;M.mutateAsync({kind:`edit`,transportIdentity:c.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:L(),runtime:c,runtimeGeneration:c.generation,input:pf(r,t,s.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(Bf);return}if(!o)return;let t=e,r=kf(t,o);if(!r)return;let c=t.queueItemID??t.id,l=t.operationID,u=Zd(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,c,l))})()},t[74]=a,t[75]=s,t[76]=ce,t[77]=i,t[78]=n,t[79]=o,t[80]=M,t[81]=b.actions,t[82]=b.mode,t[83]=b.scope,t[84]=ve):ve=t[84];let ye=q(ve),be;t[85]!==ce||t[86]!==r||t[87]!==o||t[88]!==M||t[89]!==b.actions||t[90]!==b.mode||t[91]!==b.scope?(be=e=>{if(ce||Rr(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=L();M.mutateAsync({kind:`send`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:i,runtime:r,runtimeGeneration:r.generation,input:ff(n,t,i)}).catch(Vf);return}if(!o)return;let t=e;kf(t,o)&&r(t.queueItemID??t.id)},t[85]=ce,t[86]=r,t[87]=o,t[88]=M,t[89]=b.actions,t[90]=b.mode,t[91]=b.scope,t[92]=be):be=t[92];let xe=q(be),Se;t[93]!==f||t[94]!==ce||t[95]!==u||t[96]!==o||t[97]!==M||t[98]!==b.actions||t[99]!==b.mode||t[100]!==b.scope?(Se=e=>{if(Rr(e)){f.some(t=>t.requestID===e.requestID)&&u?.(e.requestID);return}if(ce)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:ff(n,t,i)}).catch(Hf);return}if(!o)return;let t=e,n=kf(t,o);n&&C.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[93]=f,t[94]=ce,t[95]=u,t[96]=o,t[97]=M,t[98]=b.actions,t[99]=b.mode,t[100]=b.scope,t[101]=Se):Se=t[101];let Ce=q(Se),we=ie.length>0&&(o||f.length>0);if(!we&&!d)return null;let Te=m?`px-2`:`px-4`,Ee;t[102]===Te?Ee=t[103]:(Ee=Y(`oc-composer-queue relative z-0 -mb-5 w-full`,Te),t[102]=Te,t[103]=Ee);let De=m?`rounded-[1.25rem]`:`rounded-3xl`,Oe;t[104]===De?Oe=t[105]:(Oe=Y(`overflow-hidden border border-border/60 bg-[var(--surface-subtle)] text-foreground`,De),t[104]=De,t[105]=Oe);let ke=m?`px-1.5 py-1`:`gap-0.5 px-3 pb-1 pt-1.5`,Ae;t[106]===ke?Ae=t[107]:(Ae=Y(`flex flex-col`,ke),t[106]=ke,t[107]=Ae);let je;t[108]!==ce||t[109]!==_e||t[110]!==ye||t[111]!==Ce||t[112]!==xe||t[113]!==de||t[114]!==we||t[115]!==m||t[116]!==oe||t[117]!==ie||t[118]!==he||t[119]!==b.mode?(je=we?(0,$.jsx)(zo,{sensors:he,collisionDetection:Lo,onDragEnd:_e,children:(0,$.jsx)(Ko,{items:ie.map(Uf),strategy:Go,children:ie.map(e=>(0,$.jsx)(Sf,{message:e,server:b.mode===`server`,frozen:ce,hasDispatchLock:de,pendingOperationKinds:oe.get(e.queueItemID||e.id)??Ef,isMobile:m,onEdit:ye,onSend:xe,onRemove:Ce},e.queueItemID||e.id))})}):null,t[108]=ce,t[109]=_e,t[110]=ye,t[111]=Ce,t[112]=xe,t[113]=de,t[114]=we,t[115]=m,t[116]=oe,t[117]=ie,t[118]=he,t[119]=b.mode,t[120]=je):je=t[120];let Me;t[121]!==we||t[122]!==d?(Me=d?(0,$.jsxs)($.Fragment,{children:[we?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,d]}):null,t[121]=we,t[122]=d,t[123]=Me):Me=t[123];let Ne;t[124]!==Ae||t[125]!==je||t[126]!==Me?(Ne=(0,$.jsxs)(`div`,{className:Ae,children:[je,Me]}),t[124]=Ae,t[125]=je,t[126]=Me,t[127]=Ne):Ne=t[127];let Pe=m?`h-4`:`h-5`,Fe;t[128]===Pe?Fe=t[129]:(Fe=(0,$.jsx)(`div`,{"aria-hidden":`true`,className:Pe}),t[128]=Pe,t[129]=Fe);let Ie;t[130]!==Oe||t[131]!==Ne||t[132]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:Oe,children:[Ne,Fe]}),t[130]=Oe,t[131]=Ne,t[132]=Fe,t[133]=Ie):Ie=t[133];let Le;return t[134]!==Ee||t[135]!==Ie?(Le=(0,$.jsx)(`div`,{className:Ee,children:Ie}),t[134]=Ee,t[135]=Ie,t[136]=Le):Le=t[136],Le});Af.displayName=`QueuedMessageChips`;function jf(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(Kd,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Mf(e){return e.isMobile}function Nf(e){return e.state.variables}function Pf(e){let t=e.state.variables;if(!xf(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 Ff(e){return e!==void 0}function If(e){return!Rr(e)&&(e.status===`sending`||e.status===`reconciling`)}function Lf(e){return e.reorderQueue}function Rf(){}function zf(e){return!Rr(e)}function Bf(){}function Vf(){}function Hf(){}function Uf(e){return e.queueItemID||e.id}var Wf=[0,200,400],Gf=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=Wf.map(Kf),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 Kf(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var qf=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=it(),r=J(Jf),i;e[0]===r?i=e[1]:(i=e=>{if(!r)return null;let t=e.runsByOriginalSessionID[r]??null;return t?.runtimeKey===n()?t:null},e[0]=r,e[1]=i);let a=cn(i),o=cn(Yf),s=c(Xf),l=c(Zf);if(!r||!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]!==s||e[6]!==a.directory||e[7]!==a.reviewSessionID||e[8]!==t?(f=()=>{s(a.directory,{mode:`chat`,dedupeKey:`session:${a.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=s,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)(Gf,{}),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)(oa,{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]!==r||e[36]!==o?(A=()=>o(r),e[35]=r,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)(oa,{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});qf.displayName=`AutoReviewBanner`;function Jf(e){return e.currentSessionId}function Yf(e){return e.stopRun}function Xf(e){return e.openContextPanelTab}function Zf(e){return e.isMobile}var Qf=Z.forwardRef((e,t)=>{let n=(0,Q.c)(55),{searchQuery:r,onSkillSelect:i,onClose:a,directory:o,style:s}=e,l=Z.useRef(null),u=c($f),d=fs(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=ut(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(ep);v(e),p(0);return}let t=hr(w,e,tp);t.sort(np),v(t.map(rp)),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]!==s){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]!==s?(H=d===void 0?s:{...s,maxHeight:d},n[38]=d,n[39]=s,n[40]=H):H=n[40],F=la,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]=s,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});Qf.displayName=`SkillAutocomplete`;function $f(e){return e.isMobile}function ep(e,t){return e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name)}function tp(e){return[e.name,e.description??``]}function np(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 rp(e){return e.item}function ip(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 ap(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(op).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)(ip,{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 op(e){return e.trim()}var sp=`mobile-overlay-root`,cp=16,lp=200,up=[],dp=0,fp=``,pp=0,mp=()=>{if(typeof document>`u`)return null;let e=document.getElementById(sp);return e||(e=document.createElement(`div`),e.id=sp,document.body.appendChild(e)),e},hp=({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=mp()),Z.useEffect(()=>{if(!e){m(!1),g(!1);return}let t=window.setTimeout(()=>m(!0),cp),n=window.setTimeout(()=>g(!0),266);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[e]),Z.useLayoutEffect(()=>{if(e)return pp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-opened`)),pp+=1,()=>{pp=Math.max(0,pp-1),pp===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-closed`))}},[e]),Z.useEffect(()=>{if(!e)return;let t=d.current;up.push(t),dp===0&&(fp=document.body.style.overflow),dp+=1,document.body.style.overflow=`hidden`;let n=e=>{e.key===`Escape`&&up[up.length-1]===t&&f.current()};return document.addEventListener(`keydown`,n),()=>{let e=up.lastIndexOf(t);e>=0&&up.splice(e,1),dp=Math.max(0,dp-1),dp===0&&(document.body.style.overflow=fp),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:oo,onClick:e=>{Wa(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 ${lp}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)(la,{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,_c.createPortal)(v,u.current)},gp=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,_p=1e3,vp=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)(Zi,{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 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:`min-w-0 overflow-hidden`,children:(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap pl-1.5 pr-0.5 typography-micro 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 yp(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},_p),()=>{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 bp=`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,xp=e=>`flow-root ${e?`py-1`:`py-1.5`}`,Sp=`${bp} hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Cp=`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)]`,wp=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${Cp}`,Tp=`rounded-md ${Cp}`,Ep=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},Dp=e=>{if(e)try{let t=Ep();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},Op=(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`},kp=e=>{let t=Dp(e);return t?Op(t.permission,`edit`):`ask`},Ap=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},jp=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return Ap(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:Ap(n.tokens)},Mp=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}},Np=(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}},Pp=[`ask`,`allow`,`full`],Fp=`__global__`,Ip=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=Np(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=jp(d);if(h===0)return m||null;let g=Np(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=jp(o);if(s===0)return;let c=Np(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`&&jp(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=kp(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Fp){let e=t().sessionAgentEditModes.get(Fp)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=kp(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Pp.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=kp(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Pp.indexOf(a),s=Pp.indexOf(i),c=Pp[((o>=0?o:s>=0?s:0)+1)%Pp.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`})),Lp=e=>Jn([...e??[]]),Rp=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,zp=(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],Rp(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 Bp(e,t){return!e&&t===`trigger-hover`}var Vp=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},Hp=e=>{let t=Vp(e);return t?(t.focus({preventScroll:!0}),!0):!1},Up=(e,t)=>e&&!t,Wp=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):[]:[]},Gp=(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 Wp(i)},Kp=()=>!0,qp=(e,t)=>(e.commandPolicy??Kp)(t),Jp=Z.createContext(null),Yp=()=>Z.useContext(Jp),Xp=e=>e,Zp=(e,t)=>t??e,Qp=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`)},$p=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,em=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},tm=(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}},nm=(e,t)=>`${e}:${t}`,rm=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,im=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},am=(e,t)=>{let n=im(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}}},om=[{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}],sm={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`}},cm=e=>e.trim().toLowerCase(),lm=(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=>cm(e)))),i=[];for(let e of r){let t=sm[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},um=e=>new Intl.NumberFormat(at(),{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:1,minimumFractionDigits:0}).format(e),dm=e=>new Intl.NumberFormat(at(),{style:`currency`,currency:`USD`,maximumFractionDigits:4,minimumFractionDigits:2}).format(e),fm=e=>new Intl.DateTimeFormat(at(),{month:`short`,day:`numeric`,year:`numeric`}).format(e),pm=`__add_provider__`,mm=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},hm=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=gp(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},gm=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=um(e);return t.endsWith(`.0`)?t.slice(0,-2):t},_m=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:dm(e),vm=e=>{let t=[];for(let n of om)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},ym=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:fm(t)},bm=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=it(),o=Z.useId(),{isReady:s,isUnavailable:l}=Qa(),u=l||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),d=Zn(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=Zn(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),p=i?.catalog,m=s&&(p?.ready??!d)&&!p?.loading&&!p?.error&&!i?.disabled,h=s&&(p?.ready??!f)&&!p?.loading&&!p?.error&&!i?.disabled,g=m&&h,_=Zn(e=>e.providers),v=p?.providers??_,y=Zn(e=>e.currentProviderId),b=Zn(e=>e.currentModelId),x=i?.selection.providerID??y,S=i?.selection.modelID??b,C=Zn(e=>e.currentVariant),w=i?i.selection.variant:C,T=Zn(e=>e.currentAgentName),E=i?i.selection.agent??void 0:T,D=Zn(e=>e.settingsDefaultVariant),O=Zn(e=>e.settingsDefaultAgent),k=Zn(e=>e.setProvider),A=Zn(e=>e.setSelectedProvider),j=Zn(e=>e.setModel),M=Zn(e=>e.setCurrentVariant),N=Zn(e=>e.getCurrentModelVariants),P=Zn(e=>e.setAgent),F=Zn(e=>e.getCurrentProvider),I=Zn(e=>e.getModelMetadata),L=Zn(e=>e.getCurrentAgent),R=Zn(e=>e.getVisibleAgents),z=Lp(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,Ce(`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),W=Fl(),ee=It(e=>e.getSessionModelSelection),G=It(e=>e.saveSessionModelSelection),K=It(e=>e.saveSessionAgentSelection),te=It(e=>e.saveAgentModelForSession),ne=It(e=>e.getAgentModelForSession),re=It(e=>e.saveAgentModelVariantForSession),ie=It(e=>e.getAgentModelVariantForSession),ae=Ip(e=>e.hasHydrated),oe=It(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=c(e=>e.toggleFavoriteModel),de=c(e=>e.reorderFavoriteModel),fe=c(e=>e.providerOrder),pe=c(e=>e.setProviderOrder),me=c(e=>e.isFavoriteModel),he=c(e=>e.addRecentModel),ge=c(e=>e.addRecentAgent),_e=c(e=>e.addRecentEffort),ve=c(e=>e.isModelSelectorOpen),ye=c(e=>e.setModelSelectorOpen),be=c(e=>e.isAgentSelectorOpen),xe=c(e=>e.setAgentSelectorOpen),Se=c(e=>e.isModelSelectorInstant),we=c(e=>e.isAgentSelectorInstant),Te=c(e=>e.setSettingsDialogOpen),Ee=c(e=>e.setSettingsPage),De=c(e=>e.hiddenModels),Oe=c(e=>e.shortcutOverrides.cycle_agent),ke=Z.useMemo(()=>Ga(`cycle_agent`,Oe?{cycle_agent:Oe}:void 0),[Oe]),{favoriteModelsList:Ae,recentModelsList:je}=pa({currentProviderID:x,currentModelID:S}),{isMobile:Me}=co(),Ne=c(e=>e.isMobile),Pe=Me||Ne,Fe=Eo(),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),Zn.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),Ue=q((e,t)=>{if(Bp(e,t?.reason)){t?.cancel?.();return}xe(e),e&&Zn.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(pm),Ee(`providers`),Te(!0),Ze(!1),qe()},[A,Ee,Te,Ze,qe]),[$e,et]=Z.useState(``),[tt,nt]=Z.useState(null),[rt,at]=Z.useState(!1),ot=Z.useRef(0),st=q((e,t)=>{if(Bp(e,t?.reason)){t?.cancel?.();return}at(!1),e||(ot.current=performance.now()+200,nt(null),et(``)),Ze(e),e&&Zn.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),ct=Z.useRef(!1),lt=Z.useRef(null),ut=Z.useRef(void 0),[dt,ft]=Z.useState(new Map),[pt,mt]=Z.useState(new Set),[ht,gt]=Z.useState(0),_t=Z.useCallback(()=>{let e=()=>{let e=c.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&Hp(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),vt=Z.useCallback(e=>{let t=c.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(c.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!c.getState().isMobile&&_t())},[_t]),bt=Z.useCallback(()=>{let e=c.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Vp(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),mt(new Set),e&&!Ie&&(at(!1),ot.current=performance.now()+200))},[ve,Ie]);let[St,Ct]=Z.useState(``);Z.useEffect(()=>{be||Ct(``)},[be]);let wt=Z.useMemo(()=>z.filter(e=>yt(e.mode)),[z]),Tt=Z.useMemo(()=>St.trim()?hr(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=yp(le),Ft=i?v.find(e=>e.id===x):F(),Lt=Array.isArray(Ft?.models)?Ft.models:[],Rt=S?Lt.find(e=>e.id===S):void 0,zt=x&&S&&Rt?ha(x,Rt,I(x,S)):x&&S?I(x,S):void 0,Bt=Z.useCallback(e=>e===`Tool calling`?a(`chat.modelControls.capability.toolCalling`):e===`Reasoning`?a(`chat.modelControls.capability.reasoning`):e===`Text`?a(`chat.modelControls.modality.text`):e===`Image`?a(`chat.modelControls.modality.image`):e===`Video`?a(`chat.modelControls.modality.video`):e===`Audio`?a(`chat.modelControls.modality.audio`):e===`PDF`?a(`chat.modelControls.modality.pdf`):e,[a]),Vt=Z.useMemo(()=>vm(zt).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Ht=Z.useMemo(()=>lm(zt,`input`).map(e=>({...e,label:Bt(e.label)})),[zt,Bt]),Wt=Z.useMemo(()=>lm(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 Wp(e)}return i?[]:N()},[S,x,N,v,i,p?.variants,p?.variantsReady]),Kt=Gt.length>0,qt=[{label:`Input`,value:_m(zt?.cost?.input)},{label:`Output`,value:_m(zt?.cost?.output)},{label:`Cache read`,value:_m(zt?.cost?.cache_read)},{label:`Cache write`,value:_m(zt?.cost?.cache_write)}],Jt=[{label:`Context`,value:gm(zt?.limit?.context)},{label:`Output`,value:gm(zt?.limit?.output)}],Xt=Z.useRef(void 0),Zt=Z.useRef(null),Qt=Z.useRef(null),$t=H?U(H):void 0,en=Qn(H??``,$t??void 0).renderable,tn=Sr(H??``,$t??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&&(G(H,e,t),n&&te(H,n,e,t)),`applied`):`model-missing`:`provider-missing`},[v,x,S,k,j,H,te,G]),an=Z.useCallback((e,t)=>{if(i){let n=Gp(i.selection,i.catalog,e,t);if(n.length>0||i.catalog?.variants||i.catalog?.variantsReady===!1||i.selection.providerID!==e||i.selection.modelID!==t)return n;let r=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Wp(r)}let n=v.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Wp(n)},[S,x,v,i,p?.variants,p?.variantsReady]),on=Z.useCallback((e,t)=>{let n=i?Gp(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=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,an,i,D,le]),sn=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=Zn.getState().currentAgentName;return H?It.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(an(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,an,sn,re,i,M]),ln=Z.useCallback((e,t,n,r)=>{let i=r??sn()??void 0,a=rn(e,t,i);return a===`applied`?(he(e,t),cn(e,t,n,i),`applied`):a},[he,cn,sn,rn]);Z.useEffect(()=>{if(i)return;if(!H){Qt.current=null;return}if(!ae||v.length===0||!en||!nn?.providerID||!nn.modelID)return;let e=[H,nn.id,nn.agent??``,nn.providerID,nn.modelID,nn.variant??``].join(`|`);if(Qt.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;ln(nn.providerID,nn.modelID,t,nn.agent||E||void 0)===`applied`&&(nn.agent&&(K(H,nn.agent),re(H,nn.agent,nn.providerID,nn.modelID,t)),G(H,nn.providerID,nn.modelID),Qt.current=e)},[i,H,E,ae,v,en,nn,P,ln,an,K,re,G]),Z.useEffect(()=>{if(i)return;if(!H){Qt.current=null;return}if(!ae||v.length===0||z.length===0)return;let e=()=>{let e=ee(H),t=H?It.getState().getSessionAgentSelection(H):null;if(t){E!==t&&P(t);let e=ne(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=ne(H,e.name);if(!t)continue;E!==e.name&&P(e.name),It.getState().getSessionAgentSelection(H)||se.current||K(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?It.getState().getSessionAgentSelection(H)||se.current:null,t=(H?It.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&&rn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!en){W.isLoading(H)||W.ensureSessionRenderable(H);return}nn||t()}},[i,H,en,nn,z,B,E,ee,ne,P,rn,K,ae,v,W]),Z.useEffect(()=>{if(i||!ae)return;let e=new AbortController;return(async()=>{try{if(E!==Xt.current&&(Xt.current=E,E&&H)){let t=Zt.current===E;if(Zt.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=rn(n.providerId,n.modelId,E);if(e===`applied`||e===`provider-missing`)return}let r=Zn.getState().getAgentModelSelection(E);if(r){let e=rn(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=rn(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,rn,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(Gt.length===0){Ke.current=!1,M(void 0);return}if(w&&!Gt.includes(w)){M(void 0);return}if(!H){if(!w&&!Ke.current){let e=D&&Gt.includes(D)?D:void 0;M(e)}return}let e=ie(H,E,x,S),t=e&&Gt.includes(e)?e:D&&Gt.includes(D)?D:void 0;M(t),Ke.current=!1},[i,Gt,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=Gn(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{Zt.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=kn(z,E,e);t&&un(t,{closeModelSelector:!1})},[z,E,un]),fn=Z.useCallback(e=>{let t=ke&&!ke.includes(`shift`)?Ja(`shift+${ke}`):``;return t&&so(e,t)?-1:so(e,ke)?1:null},[ke]),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||Zn.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),r()}).catch(()=>void 0);return}try{let i=n?.agentName??sn()??void 0,a=n?.applyVariant?ln(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}mn(i,e,t,n?.applyVariant?n.variant:Zn.getState().currentVariant),n?.applyVariant||he(e,t),r(),Ie&&qe()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},gn=(e,t)=>Ut(e,t,{maxLength:40}),_n=()=>v.find(e=>e.id===x)?.name||x,vn=()=>{if(!S)return a(`chat.modelControls.selectModel`);let e=Lt.find(e=>e.id===S);return gn(e,S)||a(`chat.modelControls.selectModel`)},yn=vn(),bn=Z.useRef(null),xn=zp(bn,[yn,w,Ie]),Sn=()=>{if(!le){let e=B.find(e=>e.name===`build`)||B[0];return e?Cn(e.name):`Select Agent`}let e=z.find(e=>e.name===le);return Cn(e?e.name:le)},Cn=e=>e.charAt(0).toUpperCase()+e.slice(1),wn=Z.useCallback(e=>{Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ge(e)},500)},[]),Tn=Z.useCallback(()=>{Ye.current&&clearTimeout(Ye.current)},[]);Z.useEffect(()=>()=>{Ye.current&&clearTimeout(Ye.current)},[]);let En=()=>!Ie||We!==`model`?null:(0,$.jsx)(hp,{open:!0,onClose:Je,title:zt?.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)(mm,{iconName:t,label:n},`cap-${e}`),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:n})]},e))})]}),(Ht.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:[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)(mm,{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)(mm,{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:gm(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:gm(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:ym(zt.release_date)})]})})]}):null]})}),Dn=()=>{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=im(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=am(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)(hp,{open:!0,onClose:Je,title:Cn(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)(hm,{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)(hm,{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)(hm,{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)(to,{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)}).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:Ae,recentModels:je,hiddenModels:De,providerOrder:fe,isFavorite:me,onToggleFavorite:ue,getMetadata:I}):null,An=()=>Ie?(0,$.jsx)(Ya,{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)(la,{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=Xi(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)(Zi,{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)(Pa,{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||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)(mm,{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)(mm,{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)(mm,{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:ym(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(ct.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=nm(n,r),o=dt.has(a),s=dt.get(a),c=o?s:x===n&&S===r?w:void 0,l=[void 0,...i],u=l.indexOf(c),d=l[((u>=0?u:0)+(e.key===`ArrowRight`?1:-1)+l.length)%l.length];return ft(e=>{let t=new Map(e);return t.set(a,d),t}),mt(e=>{let t=new Set(e);return t.add(a),t}),gt(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=nm(e.providerID,e.modelID),n=dt.get(t),r=pt.has(t),i=sn();hn(e.providerID,e.modelID,r?{applyVariant:!0,variant:n,agentName:i}:{agentName:i})},r=e=>{let t=fn(e);t&&(e.preventDefault(),e.stopPropagation(),ct.current=!0,dn(t))},i=e=>e?.trim()?Yt(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()<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})=>{if(an(e.providerID,e.modelID).length===0)return null;let n=nm(e.providerID,e.modelID),r=dt.has(n),o=dt.get(n),s=r?o:t?w:void 0,c=pt.has(n);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`,c||s?`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(s)}),(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=an(tt.providerID,tt.modelID),t=nm(tt.providerID,tt.modelID),n=dt.has(t),r=dt.get(t),s=tt.providerID===x&&tt.modelID===S,c=n?r:s?w:void 0,l=Ut(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)(Ca,{modelId:tt.modelID,providerId:tt.providerID,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate typography-meta font-medium text-foreground`,children:l}),(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===c||!e&&!c;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)(ip,{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?Yt(w):null;return(0,$.jsxs)(Fa,{open:!Xe&&rt,onOpenChange:s,delayDuration:200,children:[Ie?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>He(`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`,wp):`opacity-60 cursor-not-allowed`),children:m?(0,$.jsxs)($.Fragment,{children:[x||S?(0,$.jsx)(Ca,{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:bn,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`,xn&&`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)(za,{open:m&&Xe,onOpenChange:m?st:void 0,onOpenChangeComplete:e=>{e||vt(`model`)},children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(Va,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,wp),children:[m?x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ca,{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:bn,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`,xn&&`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)(Ra,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,Se&&rm),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)(ua,{providers:v,favoriteModels:Ae,recentModels:je,getMetadata:I,searchQuery:$e,onSearchQueryChange:et,onSelect:n,labels:c,selectedModel:x&&S?{providerID:x,modelID:S}:null,hiddenModels:De,onActiveKeyDown:t,onActiveEntryChange:e=>{ut.current=e},onVariantKey:e,isFavorite:e=>me(e.providerID,e.modelID),onToggleFavorite:e=>ue(e.providerID,e.modelID),renderRowEnd:l,renderVersion:ht,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?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:Xe&&!tt,onEscape:()=>{if(tt){nt(null);return}Ze(!1)}})]})})]}),jn()]})},Nn=()=>{if(!Dt)return(0,$.jsx)(Pa,{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=im(Dt.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=am(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)(Pa,{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(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)(hm,{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)(hm,{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)(hm,{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=le?Xi(le):null;return Ie?(0,$.jsx)(`button`,{type:`button`,onClick:h?()=>He(`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`,Tp,h?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:h?(0,$.jsx)(vp,{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)(Fa,{delayDuration:600,children:[(0,$.jsxs)(za,{open:h&&be,onOpenChange:h?Ue:void 0,onOpenChangeComplete:e=>{e||vt(`agent`)},children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(Va,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,Tp),children:h?(0,$.jsx)(vp,{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)(Ra,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,we&&rm),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)(Ma,{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)(la,{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)(Ha,{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)(Ba,{})]}),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)(Ha,{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)(Zi,{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)(ip,{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`,Pe&&`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`,jt,Pe&&`overflow-hidden`),children:[In,Mn()]})}),On(),An(),En(),Dn()]})},xm=[{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`}],Sm=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=it(),i=gl(Cm),a=c(wm),o;t[0]===a?o=t[1]:(o=Ka(Ga(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let s=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]===s?d=t[7]:(d=(0,$.jsx)(ap,{shortcut:s,className:`opacity-[0.35] [&_[data-slot=kbd]]:rounded-md [&_[data-slot=kbd]]:border-0 [&_[data-slot=kbd]]:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] [&_[data-slot=kbd]]:text-muted-foreground/65 [&_[data-slot=kbd]]:shadow-none`}),t[6]=s,t[7]=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=xm.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)(ip,{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 Cm(e){return e.pending}function wm(e){return e.shortcutOverrides}var Tm=28,Em=8,Dm=10.5,Om=Math.PI/2,km=e=>Array.from({length:Em},(t,n)=>{let r=n/Em*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*Dm,Math.sin(r)*Dm]}),Am=[km(0),km(Om),km(Math.PI),km(Math.PI*1.5)],jm=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,Mm=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/Tm,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:Am[0].map(Nm)}),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 Nm(e,t){return(0,$.jsx)(`span`,{className:`oc-morph-orb-dot`,style:{"--m-1":jm(Am[0][t]),"--m-2":jm(Am[1][t]),"--m-3":jm(Am[2][t]),"--m-4":jm(Am[3][t])}},t)}var Pm=1200,Fm=1e9,Im=0xe8d4a51000,Lm=e=>e>=Im?e:e>=Fm?e*1e3:Date.now()+e;function Rm({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o}){let{locale:s,t:c}=it(),[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,b]=Z.useState(null),[x,S]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;S(Date.now());let t=window.setInterval(()=>S(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){b(null);return}let t=Lm(e),n=()=>{let e=Math.max(0,t-Date.now());b(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let C=q(()=>{v.current&&=(clearTimeout(v.current),null)}),w=q((e,t,n=!1)=>{C(),_.current=null,u(e),f(t),h.current=n,g.current=Date.now()}),T=q(()=>{if(v.current)return;let e=Date.now()-g.current,t=Math.max(0,Pm-e);v.current=setTimeout(()=>{v.current=null;let e=_.current;e&&w(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(!e){C(),_.current=null,u(null),f(!1),h.current=!1;return}if(a){C(),_.current=null;return}let t=i?c(`chat.assistantStatus.waitingForPermission`):n,o=!!i,s=!!r&&!o;if(t){if(!p.current){w(t,o,s);return}if((t!==p.current||o!==m.current)&&!(s&&h.current)){if(Date.now()-g.current>=Pm){w(t,o,s);return}_.current={text:t,permission:o,generic:s},T()}}},[e,n,r,i,a,c]),Z.useEffect(()=>()=>C(),[]),!e)return null;if(a){let e=y!==null&&y>0?new Intl.RelativeTimeFormat(s,{numeric:`always`,style:`short`}).format(y,`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)(Mm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:n})]})})}if(!l)return null;let E=l,D=typeof o==`number`?pt(Math.max(0,x-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":d?`assertive`:`polite`,"aria-label":E,"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)(Mm,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:E}),D?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:D}):null]})})}var zm={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Bm={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Vm={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:zm},Hm=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?zm:Bm}),Um=Z.createContext(Vm),Wm=()=>Z.useContext(Um),Gm=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}),Km=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,qm={containerType:`inline-size`,containerName:`status-row`},Jm=[],Ym=e=>{let t=(0,Q.c)(93),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:s,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}=it(),[w,T]=Z.useState(!1),E=Wm(),D=J(Xm),O=E.sessionId??D,k;t[0]!==O||t[1]!==S?(k=e=>!S||!O?Jm:e.todo[O]??Jm,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=si(j),N;bb0:{if(!O){N=Jm;break bb0}if(A.length>0){N=A;break bb0}N=M??Jm}let P=N,F=c(Zm),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(Qm),t[8]=P,t[9]=R);let z=R,B;t[10]===z?B=t[11]:(B=z.find($m)||z.find(eh)||null,t[10]=z,t[11]=B);let V=B,H;t[12]===z?H=t[13]:(H=z.find(th)??null,t[12]=z,t[13]=H);let U=H,W;t[14]===P?W=t[15]:(W=P.filter(nh),t[14]=P,t[15]=W);let ee=W.length,G;t[16]===P?G=t[17]:(G=P.filter(rh),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(ih),t[21]=z,t[22]=re);let ie=re.length,ae;t[23]===z?ae=t[24]:(ae=z.filter(ah),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=x&&(v||!!o||!!f),fe=!!_,pe=!f&&!ue&&(o||!s),me=ue||de||le||fe,he=Z.useRef(null),ge=Z.useRef(null),_e=Z.useRef(null),ve,ye;t[28]===w?(ve=t[29],ye=t[30]):(ve=()=>{let e=ge.current,t=_e.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))},ye=[w],t[28]=w,t[29]=ve,t[30]=ye),Z.useLayoutEffect(ve,ye);let be,xe;t[31]===w?(be=t[32],xe=t[33]):(be=()=>{if(!w)return;let e=e=>{he.current&&!he.current.contains(e.target)&&T(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},xe=[w],t[31]=w,t[32]=be,t[33]=xe),Z.useEffect(be,xe);let Se;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(Se=()=>T(oh),t[34]=Se):Se=t[34];let Ce=q(Se),we;t[35]!==ce.active||t[36]!==ce.left||t[37]!==C?(we=C(`chat.statusRow.summary.activeLeft`,{active:ce.active,left:ce.left}),t[35]=ce.active,t[36]=ce.left,t[37]=C,t[38]=we):we=t[38];let Te=we,Ee;t[39]!==V||t[40]!==le||t[41]!==L||t[42]!==w||t[43]!==ne||t[44]!==C||t[45]!==Te||t[46]!==Ce?(Ee=le?(0,$.jsxs)(`button`,{type:`button`,onClick:Ce,className:Y(Bs,`shrink-0`),"aria-label":Te,title:Te,children:[(0,$.jsx)(X,{name:`list-check-3`,className:Us}),!L&&V?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,$s),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:Rs,"aria-hidden":`true`,children:[ne.completed,`/`,ne.total]}),w?(0,$.jsx)(X,{name:`arrow-up-s`,className:Us}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Us})]}):null,t[39]=V,t[40]=le,t[41]=L,t[42]=w,t[43]=ne,t[44]=C,t[45]=Te,t[46]=Ce,t[47]=Ee):Ee=t[47];let De=Ee;if(!me)return null;let Oe=!fe&&`chat-column`,ke;t[48]===Oe?ke=t[49]:(ke=Y(`mb-1`,Oe),t[48]=Oe,t[49]=ke);let Ae=fe&&`px-3`,je;t[50]===Ae?je=t[51]:(je=Y(`flex items-center justify-between py-0.5 gap-2 h-[1.2rem]`,Ae),t[50]=Ae,t[51]=je);let Me=!fe&&`overflow-x-hidden`,Ne;t[52]===Me?Ne=t[53]:(Ne=Y(`flex-1 flex items-center min-w-0 gap-2`,Me),t[52]=Me,t[53]=Ne);let Pe;t[54]!==g||t[55]!==O||t[56]!==ue||t[57]!==i||t[58]!==F||t[59]!==a||t[60]!==v||t[61]!==_||t[62]!==l||t[63]!==pe||t[64]!==f||t[65]!==x||t[66]!==y||t[67]!==C||t[68]!==u?(Pe=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&&pe?(0,$.jsx)(Rm,{isWorking:v,isMobile:F,statusText:y,isGenericStatus:i,isWaitingForPermission:a,retryInfo:l,turnStartedAt:u,agentName:g},O??`no-session`):_||null,t[54]=g,t[55]=O,t[56]=ue,t[57]=i,t[58]=F,t[59]=a,t[60]=v,t[61]=_,t[62]=l,t[63]=pe,t[64]=f,t[65]=x,t[66]=y,t[67]=C,t[68]=u,t[69]=Pe):Pe=t[69];let Fe;t[70]!==Ne||t[71]!==Pe?(Fe=(0,$.jsx)(`div`,{className:Ne,children:Pe}),t[70]=Ne,t[71]=Pe,t[72]=Fe):Fe=t[72];let Ie=!fe&&`-mr-3`,Le;t[73]===Ie?Le=t[74]:(Le=Y(`relative flex items-center gap-2 flex-shrink-0`,Ie),t[73]=Ie,t[74]=Le);let Re;t[75]!==U||t[76]!==le||t[77]!==w||t[78]!==ne||t[79]!==C||t[80]!==z?(Re=w&&le&&(0,$.jsxs)(`div`,{style:Vs,className:Y(qs,`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:ge,className:oc,children:z.map((e,t)=>(0,$.jsx)(cc,{todo:e,isActive:e===U,activeRef:e===U?_e:void 0},e.id??`todo-${t}`))})]}),t[75]=U,t[76]=le,t[77]=w,t[78]=ne,t[79]=C,t[80]=z,t[81]=Re):Re=t[81];let ze;t[82]!==Le||t[83]!==Re||t[84]!==De?(ze=(0,$.jsxs)(`div`,{className:Le,ref:he,children:[De,Re]}),t[82]=Le,t[83]=Re,t[84]=De,t[85]=ze):ze=t[85];let Be;t[86]!==je||t[87]!==Fe||t[88]!==ze?(Be=(0,$.jsxs)(`div`,{className:je,children:[Fe,ze]}),t[86]=je,t[87]=Fe,t[88]=ze,t[89]=Be):Be=t[89];let Ve;return t[90]!==ke||t[91]!==Be?(Ve=(0,$.jsx)(`div`,{className:ke,style:qm,children:Be}),t[90]=ke,t[91]=Be,t[92]=Ve):Ve=t[92],Ve};function Xm(e){return e.currentSessionId}function Zm(e){return e.isMobile}function Qm(e){return e.status!==`cancelled`}function $m(e){return e.status===`in_progress`}function eh(e){return e.status===`pending`}function th(e){return e.status===`in_progress`}function nh(e){return e.status!==`cancelled`}function rh(e){return e.status===`completed`}function ih(e){return e.status===`in_progress`}function ah(e){return e.status===`in_progress`||e.status===`pending`}function oh(e){return!e}var sh=Z.createContext(null),ch=e=>{let t=(0,Q.c)(3),{actions:n,children:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(sh.Provider,{value:n,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},lh=()=>Z.useContext(sh),uh=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),dh=e=>`insertions`in e,fh=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},ph=e=>{let t=0,n=0;for(let r of e.split(`
6521
6521
  `))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},mh=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!uh.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:fh(i.additions)??void 0,deletions:fh(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:fh(e.additions)??void 0,deletions:fh(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:fh(i.additions)??void 0,deletions:fh(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=ph(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},hh=(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:ho(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},gh=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},_h=(e,t)=>mo(e,t),vh=(e,t)=>{let n=dh(e)&&e.relativePath?e.relativePath:_h(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},yh=e=>dh(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},bh=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=it(),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:zs,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Ws,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:sc,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}=vh(e,r),s=yh(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`,Gs),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(Tu,{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:oc,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},xh=`${qs} origin-[var(--transform-origin)]`,Sh=Vs,Ch=Z.memo(()=>{let e=(0,Q.c)(60),{t}=it(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=ts()??null,o=Z.useContext(To),s=Ls(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=xs(l),d=lh(),f,p;e[2]===n?(f=e[3],p=e[4]):(f=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},p=[n],e[2]=n,e[3]=f,e[4]=p),Z.useEffect(f,p);let m;bb0:{if(!a||s!==!0||!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=hh(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||s!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!dh(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=c.getState(),s=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,s);return}i.navigateToDiff(e.relativePath,s),i.setRightSidebarOpen(!1)},e[18]=a,e[19]=d,e[20]=o?.editor,e[21]=x):x=e[21];let S=x,C=h.length,w;e[22]!==C||e[23]!==t?(w=t(C===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:C}),e[22]=C,e[23]=t,e[24]=w):w=e[24];let T=w,E,D;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(Bs,`max-w-full text-left`),D=()=>r(wh),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:Us}),O=Y($s,`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`,$s),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(Rs,`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:Us}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Us}),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:Sh,className:Y(xh,`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)(bh,{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});Ch.displayName=`PendingChangesBar`;function wh(e){return!e}var Th=Z.createContext(`default`),Eh=()=>Z.useContext(Th),Dh=500,Oh=e=>{let t=(0,Q.c)(30),{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=sn(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=yp(d),h;t[5]===d?h=t[6]:(h=Xi(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()},Dh))},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`,Tp,i),t[16]=i,t[17]=D);let O;t[18]!==g.var||t[19]!==p||t[20]!==d||t[21]!==m?(O=(0,$.jsx)(vp,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-6 w-6`,colorVar:g.var}),t[18]=g.var,t[19]=p,t[20]=d,t[21]=m,t[22]=O):O=t[22];let k;return t[23]!==p||t[24]!==u||t[25]!==b||t[26]!==S||t[27]!==D||t[28]!==O?(k=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:kh,onMouseDown:Ah,className:D,title:p,"aria-label":p,children:O}),t[23]=p,t[24]=u,t[25]=b,t[26]=S,t[27]=D,t[28]=O,t[29]=k):k=t[29],k};function kh(e){return e.preventDefault()}function Ah(e){return e.preventDefault()}var jh=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}=it(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=qi(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()?Yt(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)(Ca,{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:Mh,onPointerDownCapture:Nh,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 Mh(e){return e.preventDefault()}function Nh(e){e.preventDefault()}var Ph={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1};function Fh(e,t){let n=(0,Q.c)(3),r=cr(e??``,t),i=pi(e??``,t),a=Sr(e??``,t),o=yi(e??``,t),s=Hr(e??``,t),c=Ci(t),l;bb0:{if(!e){l=Ph;break bb0}if(o.length>0||s.length>0){l=Ph;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=u?.time?.created,p=!!(d&&typeof c==`number`&&typeof f==`number`&&f<=c),m=r!==void 0,h=m&&t!==`idle`,g=h||d&&!p;if(m&&!h&&(!d||m&&!h&&typeof i==`number`&&typeof f==`number`&&f<=i)){l=Ph;break bb0}if(!g){l=Ph;break bb0}let _=h?t:`busy`,v=t===`busy`||!h&&d,y;n[0]!==_||n[1]!==v?(y={phase:_,isWorking:!0,isBusy:v,isCooldown:!1},n[0]=_,n[1]=v,n[2]=y):y=n[2],l=y}return l}var Ih=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function Lh(e){let t=(0,Q.c)(4),n,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`path`,{d:`M208,56V200a8,8,0,0,1-8,8H56a8,8,0,0,1-8-8V56a8,8,0,0,1,8-8H200A8,8,0,0,1,208,56Z`,opacity:`0.2`}),r=(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,40Zm0,160H56V56H200V200Z`}),t[0]=n,t[1]=r):(n=t[0],r=t[1]);let i;return t[2]===e?i=t[3]:(i=(0,$.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,viewBox:`0 0 256 256`,...e,children:[n,r]}),t[2]=e,t[3]=i),i}var Rh=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),zh=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Bh=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Vh=(e,t)=>e.id===t.id&&e.directory===t.directory,Hh=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Uh=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Bh(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Vh(e.parentTarget,i)&&Hh(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},Wh=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`}},Gh=`data-mobile-overlay-active`,Kh=e=>Array.from(e).some(e=>e.getAttribute(Gh)!==`false`),qh=`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(`.`),Jh=`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 Yh(){return`${qh[Math.floor(Math.random()*qh.length)]}-${Jh[Math.floor(Math.random()*Jh.length)]}`}function Xh(e){let t=Yh();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var Zh=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,Qh=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),$h=(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))},eg=async(e,t)=>{await ln(e)&&await Cr(t)},tg=e=>{let t=Zh(e),n=Nr.getState().projects;if(n.length===0)return null;let r=Nr.getState().getActiveProject();if(r?.path){let e=Zh(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=Zh(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>Zh(t.path).length-Zh(e.path).length)[0];return i?{id:i.id,path:i.path}:null},ng=!1,rg=async(e,t)=>{try{let n=Nr.getState().projects.find(e=>e.id===t.id)??Nr.getState().projects.find(e=>Zh(e.path)===Zh(t.path)),r=tr(t.path);await Zn.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Zn.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),$h(e,Qh(Zn.getState()),It.getState())}catch{}},ig=async(e,t,n)=>{let r=J.getState(),i=Zn.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await rg(e,n),Le.getState().setDirectory(t.path,{showOverlay:!1})},ag=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,og=async e=>{if(ng)return null;let t=Nr.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return Pi.error(`No active project`,{description:`Please select a project first.`}),null;let r=tg(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return Pi.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await ca(r.path)}catch{}if(!i)return Pi.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;ng=!0;try{let t=Ti(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?ag(n):Xh(),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 sa(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}),Le.getState().setDirectory(s.path,{showOverlay:!1}));let c=await Zt(r),l=await Ss(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return bi(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}),Le.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&&(li(n,e instanceof Error?e:Error(t)),J.getState().resolvePendingDraftWorktreeTarget(n,null)),J.getState().setDraftBootstrapPendingDirectory(null),Pi.error(`Failed to create worktree`,{description:t}),null}finally{ng=!1}};async function sg(){return og()}async function cg(e){let t=e.branch?.trim();return t?og({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function lg(e,t,n,r){if(ng)return null;ng=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=tg(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await ca(s.path)}catch{}if(!c)return Pi.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await Zt(s),u=await Ea(s.path);try{let e=await Ss(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 eg(s,e.path);let n=await J.getState().createSession(void 0,e.path);if(!n)throw await Oa(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await ig(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 Pi.error(`Failed to create worktree`,{description:t}),null}}finally{ng=!1}}var ug=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},dg=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 fg({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=it(),{github:a}=wo(),o=Za(),s=o.data??null,l=o.isFetched,u=c(e=>e.setSettingsDialogOpen),d=c(e=>e.setSettingsPage),f=c(e=>e.isMobile),{isTablet:p}=co(),m=f||p,h=Nr(e=>e.getActiveProject()),g=Le(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(()=>ug(v),[v]),E=gs(v,350),D=T?``:E.trim(),O=!!T||v===E,k=e&&O&&!!_&&!!a?.issuesList&&!(l&&s?.connected===!1),A=Ke({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);Pi.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||s?.connected!==!1&&j?.connected!==!1,V=j?.repo?.url??null,H=Z.useCallback(()=>{d(`github`),u(!0)},[u,d]),U=Z.useCallback(()=>{let e=Zn.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=Zn.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Gr(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=Zn.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(!_){Pi.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Pi.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){Pi.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Pi.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){Pi.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){Pi.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=dg({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);Pi.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&C(null)}return}if(!_){Pi.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Pi.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){Pi.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Pi.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){Pi.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){Pi.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}-${Yh()}`,t=await lg(_,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 bt(u,_,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??_}})();if(!c())return;dt(d,u).catch(()=>void 0);try{J.getState().initializeNewOpenChamberSession(d,Zn.getState().agents)}catch{}t(!1);let f=Zn.getState(),p=It.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){Pi.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let y=ee(h,g),x=await Wt(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await Wt(`github.issue.review.instructions`);if(!c())return;let C=dg({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);Pi.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),Pi.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Pi.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)(Ma,{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)(oa,{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)(oa,{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)(oa,{variant:`outline`,size:`sm`,onClick:R,disabled:P||!!S,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return f?(0,$.jsx)(hp,{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)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)($i,{className:`flex-shrink-0`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),K]}),(0,$.jsx)(ra,{children:te})]}),ne]})})}var pg=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},mg=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function hg({open:e,onOpenChange:t,onSelect:n}){let{t:r}=it(),{github:i}=wo(),a=Za(),o=a.data??null,s=a.isFetched,l=c(e=>e.setSettingsDialogOpen),u=c(e=>e.setSettingsPage),d=c(e=>e.isMobile),{isTablet:f}=co(),p=d||f,m=Nr(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(()=>pg(h),[h]),C=gs(h,350),w=S?``:C.trim(),T=!!S||h===C,E=e&&T&&!!m&&!!i?.prsList&&!(s&&o?.connected===!1),D=Ke({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);Pi.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=!s||o?.connected!==!1&&O?.connected!==!1,L=q(()=>{u(`github`),l(!0)}),R=q(async(e,a)=>{if(!m){Pi.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){Pi.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){Pi.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){Pi.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){Pi.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await Wt(`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:mg(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);Pi.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)(Ma,{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)(fa,{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)(oa,{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)(hp,{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)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)($i,{className:`flex-shrink-0`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),z]}),(0,$.jsx)(ra,{children:B})]}),V]})})}function gg(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)(lc,{"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 _g=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)(lc.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});_g.displayName=`CommandInput`;function vg(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)(la,{as:lc.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 yg(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)(lc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function bg(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)(lc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function xg(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)(lc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Sg(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)(lc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Cg=(e,t)=>`${e}:${T(t)}`,wg=e=>e.type===`skill`||!se(e.name);function Tg(e){let{t}=it(),n=Z.useMemo(()=>d(),[]),r=c(e=>e.globalDraftStarters),i=Nr(e=>e.activeProjectId),a=Nr(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[s,l]=Z.useState([]),u=Z.useMemo(()=>r??ce,[r]),f=u.some(wg)||s.some(wg),m=Ir({directory:e,enabled:f}),h=Z.useMemo(()=>m.data??[],[m.data]),{refetch:g}=m,_=ut({directory:e,enabled:f}),v=Z.useMemo(()=>_.data??[],[_.data]),{refetch:y}=_;Z.useEffect(()=>{let e=!1;if(!o){l([]);return}return En(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:Cg(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:x.has(e.name)?{id:Cg(r,e),ref:e,group:r,label:w(e.name),icon:ae,submitText:`/${e.name}`}:null}return S.has(e.name)?{id:Cg(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(()=>s.map(e=>C(e,`project`)).filter(e=>e!==null),[s,C]),O=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(T(t));for(let t of s)e.add(T(t));return e},[u,s]),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=>{c.getState().setGlobalDraftStarters(e),te({draftStarters:e})},[]),j=Z.useCallback(e=>{l(e),o&&Gt(o,e)},[o]),N=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||s.some(e=>p(e,t)))return;j([...s,t])}else{let e=r??ce;if(e.some(e=>p(e,t)))return;A([...e,t])}},[o,s,r,j,A]),F=Z.useCallback((e,t)=>{e===`project`?j(s.filter(e=>!p(e,t))):A((r??ce).filter(e=>!p(e,t)))},[s,r,j,A]),I=Z.useCallback((e,t,n)=>{let i=e===`project`?s:r??ce,a=i.findIndex(n=>Cg(e,n)===t),o=i.findIndex(t=>Cg(e,t)===n);if(a<0||o<0||a===o)return;let c=Uo([...i],a,o);e===`project`?j(c):A(c)},[s,r,j,A]);return{global:E,project:D,pinnable:k,hasProject:!!o,ensureLoaded:b,addStarter:N,removeStarter:F,reorder:I}}var Eg=`__draft-starter-trash__`,Dg=`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`,Og=`max-h-7`,kg=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],Ag=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=it(),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}=Wo(s),m;t[2]===d?m=t[3]:(m=Vo.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},jg=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(Ig),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)(Ag,{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)(Ko,{items:o,strategy:Ho,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},Mg=()=>{let e=(0,Q.c)(13),{t}=it(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:Eg},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=Io(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(Dg,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},Ng=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=it(),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)(_g,{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)(yg,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=kg.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(bg,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(Sg,{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)(vg,{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)(gg,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},Pg=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=it(),[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)(ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:Dg,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)($i,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(na,{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)(Ng,{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)(ta,{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)(aa,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},Fg=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=it(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=Tg(ts()),{isMobile:f}=co(),[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=Bo(No(Ro,b),No(Fo,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)===Eg){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:Po.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&&Og,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)(jg,{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)(jg,{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(Lg),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:Dg,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)(Mg,{}):(0,$.jsx)(Pg,{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)(zo,{sensors:S,collisionDetection:Lo,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 Ig(e){return e.id}function Lg(e){return!e}var Rg=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});Rg.displayName=`ChatComposerSurface`;var zg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Ta,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});zg.displayName=`ChatPromptTextarea`;var Bg=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},Vg=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},Hg=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||Ih(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(Ug),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`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-[var(--status-error)] outline-none hover:bg-[var(--interactive-hover)]`,onClick:C,"aria-label":k,children:(0,$.jsx)(Lh,{className:`size-5`})}):(0,$.jsx)(`button`,{type:`submit`,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=Rg,_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,Vg(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)(zg,{...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)(Bg,{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 Ug(e){return e.mime.startsWith(`image/`)}var Wg=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),Gg=({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}=it(),[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(()=>Wg(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?hr(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?hr(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?hr(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||hr([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)(oa,{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)(Va,{asChild:!0,disabled:s,children:l??me}),ge=(0,$.jsxs)(gg,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(_g,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(vg,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(yg,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(bg,{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)(Sg,{onSelect:ie,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(xg,{}),(0,$.jsxs)(bg,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(Sg,{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)(Sg,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(xg,{}),(0,$.jsxs)(bg,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(Sg,{onSelect:()=>ne(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(Sg,{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)(xg,{}),(0,$.jsxs)(bg,{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)(Sg,{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)(Sg,{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)(Ya,{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)(za,{open:z,onOpenChange:B,children:[f||l?he:(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:he}),(0,$.jsx)(Pa,{sideOffset:8,children:c?le:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(Ra,{align:ue,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ge})]})};function Kg(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=hr(t,i,e=>e),o=hr(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 qg(e,t){return`${e}\0${t}`}function Jg({open:e,onOpenChange:t,onSelect:n}){let{t:r}=it(),i=c(e=>e.isMobile),{github:a}=wo(),o=Za(),s=o.data??null,l=o.isFetched,u=c(e=>e.setSettingsDialogOpen),d=c(e=>e.setSettingsPage),f=Nr(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=gs(v,350),W=q(async e=>{if(!(!m||!a)&&!(l&&s?.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&&s?.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,s,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=qg(h.path,e);if(I.has(t))return;let n=H.current;try{let i=await va(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&&s?.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(qg(m,M.head))?.isValid!==!1:!1),se=e=>!e.head||(m?I.get(qg(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)(Ma,{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)(oa,{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(qg(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)(oa,{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)(oa,{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)(fa,{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)(oa,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(oa,{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)(hp,{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)(uc,{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)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)($i,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(na,{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)(uc,{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)(ea,{className:`mt-1`,children:le})]})})})}var Yg=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},Xg=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),Zg=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),Qg=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,$g=(e,t,n)=>{let r=Xg(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-${Qg(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}`}},e_=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},t_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function n_({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=it(),{github:a,git:o}=wo(),s=c(e=>e.isMobile),l=Z.useId(),u=Za(),d=u.data??null,f=u.isFetched,p=Nr(e=>Yg(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=js(m),C=Os(m),w=xs(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=Yh();if(!O.has(e))return e}return`${Yh()}-${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(()=>Kg({localBranches:T,remoteBranches:E,query:B}),[T,E,B]),se=Z.useMemo(()=>Kg({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=Zn.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=Zn.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Gr(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=Zn.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=Zn.getState(),n=It.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){Pi.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 Wt(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await Wt(`github.issue.review.instructions`),d=e_({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}),Pi.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 Wt(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await Wt(`github.pr.review.instructions`),u=t_(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}),Pi.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 Ea(m).catch(()=>null);if(n)return;let r=localStorage.getItem(bs),{sourceBranch:i,shouldClearSavedSourceBranch:a}=As({branches:S.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(bs),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=Zg(Xg(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=Xg(t),a=Zg(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?$g(t,T,E):null,i=await va(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){Pi.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=Xg(e),o=Zg(r);if(!a){Pi.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){Pi.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([Zt(h),Ds(m)]),f=v.sourceBranch,p=``,_=(()=>{if(e){let t=$g(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 Fs(m,_,{resolvedRootTrackingRemote:d}),x=await Da(h,y),S=null;if(l){await ln(h)&&await Cr(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await bt(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),dt(a.id,e).catch(()=>void 0);try{J.getState().initializeNewOpenChamberSession(a.id,Zn.getState().agents)}catch{}}else t(!1),_e(!1);let C=Ns({mode:g,sourceBranch:v.sourceBranch,linkedPr:!!v.linkedPr,selectedBranch:b.selectedBranch});C&&localStorage.setItem(bs,C),Pi.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`);Pi.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`);Pi.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}-${Yh()}`;y(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:Zg(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:Zg(t.head),isSyncingWorktreeName:!0}))}},Ae=f&&d?.connected===!0,je=(g===`existing-branch`?!!b.selectedBranch&&!!b.worktreeName&&!me.branchError&&!me.worktreeError:!!Xg(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`,s?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,s?`w-full justify-center order-first`:`mr-auto`),children:me.touched&&(me.branchError||me.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:me.branchError||me.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s&&`w-full`),children:[(0,$.jsx)(oa,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,className:Y(s&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(oa,{size:`sm`,onClick:De,disabled:!je||ge,className:Y(`gap-1.5`,s&&`flex-1`),children:[ge&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(ge?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[s?(0,$.jsx)(Ya,{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)(la,{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)(uc,{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)(oa,{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)(oa,{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)(hp,{open:I,title:i(`session.newWorktree.selectBranch`),onClose:()=>L(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(Ma,{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:Zg(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:Zg(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:Zg(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)(oa,{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)(Ma,{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=Zg(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===Zg(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===Zg(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)(Ma,{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)(oa,{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)(hp,{open:R,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>z(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:K,children:[(0,$.jsx)(Ma,{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)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)($i,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(na,{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)(uc,{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)(za,{open:M,onOpenChange:N,children:[(0,$.jsx)(Va,{asChild:!0,children:(0,$.jsxs)(oa,{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)(Ra,{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)(gg,{shouldFilter:!1,children:[(0,$.jsx)(_g,{placeholder:i(`session.newWorktree.searchBranches`),value:B,onValueChange:V,onKeyDown:te}),(0,$.jsx)(vg,{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)(yg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(bg,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(Sg,{value:e.value,onSelect:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:Zg(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)(xg,{}),(0,$.jsx)(bg,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(Sg,{value:e,onSelect:()=>{x(t=>({...t,selectedBranch:e,worktreeName:Zg(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)(xg,{}),(0,$.jsx)(bg,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(Sg,{value:`remotes/${e}`,onSelect:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:Zg(e)})),he(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(oa,{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)(oa,{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)(Ma,{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=Zg(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===Zg(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===Zg(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)(Ma,{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)(za,{open:P,onOpenChange:F,children:[(0,$.jsx)(Va,{asChild:!0,children:(0,$.jsxs)(oa,{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)(Ra,{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)(gg,{shouldFilter:!1,children:[(0,$.jsx)(_g,{placeholder:i(`session.newWorktree.searchBranches`),value:H,onValueChange:U,onKeyDown:te}),(0,$.jsx)(vg,{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)(yg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[le&&de&&(0,$.jsx)(bg,{heading:i(`session.newWorktree.matchingBranches`),children:se.matching.map(e=>(0,$.jsx)(Sg,{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)(xg,{}),(0,$.jsx)(bg,{heading:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:se.otherLocal.map(e=>(0,$.jsx)(Sg,{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)(xg,{}),(0,$.jsx)(bg,{heading:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:se.otherRemote.map(e=>(0,$.jsx)(Sg,{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)(ea,{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)(oa,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(oa,{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)(Jg,{open:A,onOpenChange:j,onSelect:ke})]})}function r_(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 i_(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 a_=(e,t)=>e??t??null,o_=(e,t)=>!!e&&t!==!1,s_=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:[]},c_=e=>e.replace(/^remotes\//,``).trim(),l_=e=>{let t=c_(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},u_=({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}=it(),{git:d}=wo(),f=a_(t,e),p=e,m=Ls(f),h=Ls(p),g=o_(f,m),_=p!==f&&o_(p,h),v=ps(f,d,g),y=ps(p,d,_),b=v.data,x=p===f?b:y.data,S=xs(e=>e.fetchStatus),C=xs(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=Is(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=Nr(e=>e.projects),P=Nr(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(()=>s_(b?.all),[b]),R=x?.current?.trim()||C||null,z=!i_(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 vs(e,d),await S(e,d,{silent:!0})}))}),V=q(e=>{let t=c_(e),n=l_(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=c_(e);if(R!==t&&R!==l_(t))try{await d.checkoutBranch(p,t),Pi.success(l(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});Pi.error(n)}}),U=q(e=>{let t=c_(e);if(!t||R===t||R===l_(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 cg({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`),Pi.success(l(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),Pi.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);Pi.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 Pi.error(t),e}}),K=q(()=>{let e=Nr.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){J.getState().setCurrentSession(n.sessionId,e);return}let r=Nr.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}),Le.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,Cp,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)(Gg,{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)(n_,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:te}):null,(0,$.jsx)(aa,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ta,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)($i,{children:[(0,$.jsx)(na,{children:l(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(ra,{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)(ea,{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`)})})]})})]})},d_=[],f_=[],p_={revertMessageID:void 0,records:f_},m_=e=>e.role===`user`,h_=(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},g_=(e,t,n=p_)=>{if(!t)return p_;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return p_;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!m_(e)||!Li(i,e.id,r)||o.push({message:e,parts:a[e.id]??d_});let s=o.length===0?f_:o;return n.revertMessageID===r&&h_(n.records,s)?n:{revertMessageID:r,records:s}},__={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},v_={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`},y_=`text-foreground`;function b_(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 x_=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function S_(e){let t=x_.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function C_(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function w_(e){let t=[];if(!e)return t;let n=0,r=!1,i=``,a=e.split(`
6522
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`}),C_(o,i)&&(r=!1);continue}let l=S_(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`}),b_(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`}),b_(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;b_(o.slice(r-s),r,t);continue}b_(o,s,t)}return t}function T_(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??__[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??v_[l.style]:y_,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 E_(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 D_(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 O_(e,t,n){let r=E_(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 k_(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 A_(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 j_=`bg-[var(--surface-subtle)]`,M_=91,N_=94,P_={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},F_={keyword:`${j_} text-[var(--syntax-keyword)]`,string:`${j_} text-[var(--syntax-string)]`,number:`${j_} text-[var(--syntax-number)]`,comment:`${j_} text-[var(--syntax-comment)]`,function:`${j_} text-[var(--syntax-function)]`,type:`${j_} text-[var(--syntax-type)]`,variable:`${j_} text-[var(--syntax-variable)]`,operator:`${j_} text-[var(--syntax-operator)]`},I_=qe([{tag:[Ye.comment,Ye.lineComment,Ye.blockComment,Ye.docComment,Ye.meta],class:`comment`},{tag:[Ye.keyword,Ye.modifier,Ye.controlKeyword,Ye.operatorKeyword,Ye.definitionKeyword,Ye.moduleKeyword,Ye.self,Ye.null],class:`keyword`},{tag:[Ye.string,Ye.special(Ye.string),Ye.docString,Ye.character,Ye.regexp],class:`string`},{tag:[Ye.number,Ye.integer,Ye.float,Ye.bool,Ye.atom],class:`number`},{tag:[Ye.function(Ye.variableName),Ye.function(Ye.propertyName),Ye.macroName,Ye.standard(Ye.variableName)],class:`function`},{tag:[Ye.typeName,Ye.className,Ye.namespace,Ye.tagName],class:`type`},{tag:[Ye.variableName,Ye.propertyName,Ye.attributeName,Ye.labelName,Ye.definition(Ye.variableName)],class:`variable`},{tag:[Ye.operator,Ye.punctuation,Ye.bracket,Ye.derefOperator,Ye.separator],class:`operator`},{tag:[Ye.heading,Ye.heading1,Ye.heading2,Ye.heading3,Ye.heading4,Ye.heading5,Ye.heading6,Ye.strong],class:`keyword`},{tag:[Ye.emphasis,Ye.quote],class:`type`},{tag:[Ye.link,Ye.url],class:`function`},{tag:[Ye.monospace],class:`string`},{tag:[Ye.strikethrough],class:`comment`}]),L_=e=>{let t=null;for(let n of e.split(` `)){let e=n;P_[e]!==void 0&&(t===null||P_[e]>P_[t])&&(t=e)}return t?F_[t]:null},R_=2e4,z_=e=>{if(!e)return null;try{let t=no(e);return t instanceof Xe?t:null}catch{return null}};function B_(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=S_(i);if(!a)continue;let o=z_(a.lang),s=r,c=[],l=e+1,u=r;for(;l<n.length;l+=1){let e=n[l];if(C_(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:`${j_} text-[var(--syntax-foreground)]`,priority:M_}),!(d.length>R_)))try{let e=o.parser.parse(d);Je(e,I_,(e,n,r)=>{let i=L_(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:N_})})}catch{}}return t}var V_=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],H_=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),U_=e=>{if(!H_(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(`/`)},W_=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?U_(n):H_(n))?n:null},G_=(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)G_(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))G_(r,t,n+1)}},K_=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=W_(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=W_(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;G_(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},q_=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of V_){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 K_(r,i))t.add(e)}return Array.from(t)},J_=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}}},Y_=e=>H_(e);function X_(e,t){let n=(0,Q.c)(5),r=en(e,t),i=c(Z_),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 Z_(e){return e.sessionGoalEnabled}function Q_(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 jt(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 $_={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},ev={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`},tv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=it(),i=c(e=>e.isMobile),{goal:a,enabled:o}=X_(e??``,t),s=Q_(e??``,a),l=cr(e??``,t),u=_i(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,Dt(e,t))},[e,t,a,u]);let g=q(async n=>{if(!(!e||f)){p(!0);try{await yn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Pi.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=pt(_),y=a.tokenBudget?`${Wr(a.tokensUsed)}/${Wr(a.tokenBudget)}`:a.tokensUsed>0?Wr(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:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:$_[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||s||``}),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(ev[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]})});tv.displayName=`SessionGoalRow`;var nv=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=it(),{goal:i,enabled:a}=X_(e??``,t),o=Et(e=>e.armed),s=Et(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 Fn(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Pi.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`})})]})});nv.displayName=`SessionGoalButton`;var rv=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=it();if(!Et(iv)||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,`/`,Xr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});rv.displayName=`SessionGoalObjectiveCounter`;function iv(e){return e.armed}var av=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),ov=new Set([`compact`,`fork`,`undo`,`redo`]),sv=/^\/\u2003?([^\s]+)/i,cv=/^\/\u2003?goal\b/i,lv=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(sv)?.[1]?.toLowerCase();return n&&av.has(n)?n:null},uv=(e,t)=>lv(e,t)===`goal`?e.trimStart().replace(cv,``).trim():null,dv=(e,t)=>lv(e,t)!==null,fv=(e,t)=>{let n=lv(e,t);return n!==null&&ov.has(n)},pv=(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},mv=(e,t,n=e.length)=>{let r=pv(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}},hv=e=>e.startsWith(ee)?e.slice(ee.length):e,gv=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},_v=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()}},vv=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,yv=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,bv=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},xv=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Sv=(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},Cv=async e=>{let t=Sn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=xv(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Sv(n,a)?r+=1:i+=1}catch{try{Sv(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},wv=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Tv=e=>e===`allow`||e===`ask`||e===`deny`,Ev=e=>{if(Tv(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`&&Tv(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(Tv(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))Tv(i)&&t.push({permission:n,pattern:e,action:i})}return t},Dv=e=>{let t=Ev(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},Ov=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Dv(e.permission));let r=e.find(e=>e?.name===n);return!r||Dv(r.permission)},kv=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)},Av=null,jv=new Set,Mv=()=>{for(let e of jv)e()},Nv=e=>e===`chat`||e===`assistant`,Pv=()=>Av,Fv=e=>{Av!==e&&(Av=e,Mv())},Iv=e=>{Av&&(e&&Av.surfaceID!==e||(Av=null,Mv()))},Lv=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Rv=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}},zv=(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}),Bv=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=zv(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=zv(e,`send`,i),o=em(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=zv(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=zv(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=zv(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:em(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>qp(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=zv(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=zv(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Vv=(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)))},Hv=(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},Uv=(e,t)=>e.agents.some(e=>e.name===t),Wv=(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},Gv=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Wv(t,n,r,i)?i:void 0;if(a&&Wv(t,n,r,a))return a},Kv=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,fallbackAgentName:a}=e;if(n?.providerID&&n.modelID&&Hv(r,n.providerID,n.modelID)){let e=n.agent&&Uv(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Uv(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Uv(r,a)?a:void 0,o=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=Gv({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:o});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(!i)return null;let o=i.getSessionAgentSelection?.(t)??null,s=o&&Uv(r,o)?o:a&&Uv(r,a)?a:void 0;if(s){let e=i.getAgentModelForSession?.(t,s);if(e&&Hv(r,e.providerId,e.modelId)){let n=i.getAgentModelVariantForSession?.(t,s,e.providerId,e.modelId),a=n&&Wv(r,e.providerId,e.modelId,n)?n:void 0;return{agent:s,providerID:e.providerId,modelID:e.modelId,variant:a,source:`session-memory`}}}let c=i.getSessionModelSelection?.(t);if(c&&Hv(r,c.providerId,c.modelId)){let e=s?i.getAgentModelVariantForSession?.(t,s,c.providerId,c.modelId):void 0,n=e&&Wv(r,c.providerId,c.modelId,e)?e:void 0;return{agent:s,providerID:c.providerId,modelID:c.modelId,variant:n,source:`session-memory`}}return null},qv=(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))},Jv=(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}},Yv=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}:{}}},Xv=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},Zv=500,Qv=e=>Array.from(e).length,$v=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},ey=e=>Qv(e)>=Zv,ty=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},ny=(e,t)=>{let n=t??e;return typeof n!=`string`||!ey(n)?!1:ue(typeof e==`string`?{text:``,references:[]}:e,n)},ry=(e,t,n,r,i=1)=>{let a=Qv(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}-${$v(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},iy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),ay=e=>e.map(e=>({...e,range:{...e.range}})),oy=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),sy=(e,t,n)=>({document:iy(e),mentions:ay(t),selection:{...n}}),cy=()=>({undo:[],redo:[]}),ly=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),uy=(e,t)=>{let n=e.undo.at(-1);return!n||!oy(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:sy(n.before.document,n.before.mentions,n.before.selection)}},dy=(e,t)=>{let n=e.redo.at(-1);return!n||!oy(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:sy(n.after.document,n.after.mentions,n.after.selection)}},fy=e=>({text:e?.text??``,references:e?.composerReferences??[]}),py=e=>({text:e.text,references:e.references.map(e=>({...e}))}),my=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),hy=e=>JSON.stringify([e.text,e.references]),gy=(e,t)=>e!==null&&t!==null&&le(e)===t,_y=(e,t,n)=>{let r=e?my(e):null,i=r?n(r):void 0;return{document:D(fy(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?le(r):null}},vy=(e,t,n,r)=>{if(!t||le(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=hy(fy(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===hy(e)?`same-document-metadata`:`external-document`},yy=(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}]:[]})},by=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),xy=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:yy(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},Sy=(e,t,n)=>({preview:{real:py(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Cy=e=>({document:e.real,mentions:e.realMentions}),wy=(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)})},Ty=(e,t)=>{let n=fy(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:wy(e.mentions,t?.mentions??[],r,i)}},Ey=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=Rn})=>{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)(()=>_y(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>_y(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?my(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)(cy());_.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=_y(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=cy(),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||!gy(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(fy(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=vy(_.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(fy(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!gy(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:by(t)});if(!a)return;let o=fy(a);return M.current={keyID:le(n),revision:a.revision,fingerprint:hy(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=ly(P.current,{before:sy(e,t,n),after:sy(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)=>{let r=z(),i=py(_.current),a=r?[]:b.current,o=xy(i,a,e,t,n);return L(o.document,o.mentions),o.removedReferences.length>0&&R(i,a,{start:o.selectionStart,end:o.selectionEnd},o.document,o.mentions,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd,requiresTextCorrection:o.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=yy(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,yy(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=py(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=yy(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=yy(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`?uy(P.current,_.current):dy(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:[]}:Sy(_.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=Cy(e);F(t.document,t.mentions)},[F]),ie=(0,Z.useCallback)(()=>{let e=w.current;if(!gy(e,T.current))return null;let t=i.getState().getDraft(e);return{key:my(e),keyID:le(e),revision:t?.revision??0,document:py(_.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=Ty(e,i.getState().getDraft(e.key)),n=fy(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:by(t.mentions)});if(a){let e=fy(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 Dy(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 Oy=`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`,ky=Mo(()=>Ve(()=>import(`./ToolOutputDialog-D3U6aTZ4.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]))),Ay=[],jy=[],My=[],Ny=[],Py=/^@[^\s]+$/,Fy=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Iy=/^(https?:\/\/|mailto:)\S+$/i,Ly=560,Ry=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),zy=(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)},By=e=>e.includes(`@`)?`paste`:`manual`,Vy=(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}},Hy=(e,t)=>br(e,t).some(e=>e.role===`user`),Uy=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Xt(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6524
+ `);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${j_} text-[var(--syntax-foreground)]`,priority:M_}),!(d.length>R_)))try{let e=o.parser.parse(d);Je(e,I_,(e,n,r)=>{let i=L_(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:N_})})}catch{}}return t}var V_=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],H_=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),U_=e=>{if(!H_(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(`/`)},W_=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?U_(n):H_(n))?n:null},G_=(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)G_(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))G_(r,t,n+1)}},K_=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=W_(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=W_(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;G_(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},q_=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of V_){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 K_(r,i))t.add(e)}return Array.from(t)},J_=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}}},Y_=e=>H_(e);function X_(e,t){let n=(0,Q.c)(5),r=en(e,t),i=c(Z_),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 Z_(e){return e.sessionGoalEnabled}function Q_(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 jt(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 $_={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},ev={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`},tv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=it(),i=c(e=>e.isMobile),{goal:a,enabled:o}=X_(e??``,t),s=Q_(e??``,a),l=cr(e??``,t),u=_i(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,Dt(e,t))},[e,t,a,u]);let g=q(async n=>{if(!(!e||f)){p(!0);try{await yn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Pi.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=pt(_),y=a.tokenBudget?`${Wr(a.tokensUsed)}/${Wr(a.tokenBudget)}`:a.tokensUsed>0?Wr(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:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:$_[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||s||``}),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(ev[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]})});tv.displayName=`SessionGoalRow`;var nv=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=it(),{goal:i,enabled:a}=X_(e??``,t),o=Et(e=>e.armed),s=Et(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 Fn(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Pi.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`})})]})});nv.displayName=`SessionGoalButton`;var rv=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=it();if(!Et(iv)||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,`/`,Xr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});rv.displayName=`SessionGoalObjectiveCounter`;function iv(e){return e.armed}var av=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),ov=new Set([`compact`,`fork`,`undo`,`redo`]),sv=/^\/\u2003?([^\s]+)/i,cv=/^\/\u2003?goal\b/i,lv=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(sv)?.[1]?.toLowerCase();return n&&av.has(n)?n:null},uv=(e,t)=>lv(e,t)===`goal`?e.trimStart().replace(cv,``).trim():null,dv=(e,t)=>lv(e,t)!==null,fv=(e,t)=>{let n=lv(e,t);return n!==null&&ov.has(n)},pv=(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},mv=(e,t,n=e.length)=>{let r=pv(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}},hv=e=>e.startsWith(ee)?e.slice(ee.length):e,gv=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},_v=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()}},vv=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,yv=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,bv=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},xv=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Sv=(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},Cv=async e=>{let t=Sn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=xv(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Sv(n,a)?r+=1:i+=1}catch{try{Sv(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},wv=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Tv=e=>e===`allow`||e===`ask`||e===`deny`,Ev=e=>{if(Tv(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`&&Tv(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(Tv(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))Tv(i)&&t.push({permission:n,pattern:e,action:i})}return t},Dv=e=>{let t=Ev(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},Ov=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Dv(e.permission));let r=e.find(e=>e?.name===n);return!r||Dv(r.permission)},kv=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)},Av=null,jv=new Set,Mv=()=>{for(let e of jv)e()},Nv=e=>e===`chat`||e===`assistant`,Pv=()=>Av,Fv=e=>{Av!==e&&(Av=e,Mv())},Iv=e=>{Av&&(e&&Av.surfaceID!==e||(Av=null,Mv()))},Lv=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Rv=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}},zv=(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}),Bv=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=zv(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=zv(e,`send`,i),o=em(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=zv(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=zv(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=zv(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:em(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>qp(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=zv(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=zv(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Vv=(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)))},Hv=(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},Uv=(e,t)=>e.agents.some(e=>e.name===t),Wv=(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},Gv=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Wv(t,n,r,i)?i:void 0;if(a&&Wv(t,n,r,a))return a},Kv=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,fallbackAgentName:a}=e;if(n?.providerID&&n.modelID&&Hv(r,n.providerID,n.modelID)){let e=n.agent&&Uv(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Uv(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Uv(r,a)?a:void 0,o=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=Gv({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:o});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(!i)return null;let o=i.getSessionAgentSelection?.(t)??null,s=o&&Uv(r,o)?o:a&&Uv(r,a)?a:void 0;if(s){let e=i.getAgentModelForSession?.(t,s);if(e&&Hv(r,e.providerId,e.modelId)){let n=i.getAgentModelVariantForSession?.(t,s,e.providerId,e.modelId),a=n&&Wv(r,e.providerId,e.modelId,n)?n:void 0;return{agent:s,providerID:e.providerId,modelID:e.modelId,variant:a,source:`session-memory`}}}let c=i.getSessionModelSelection?.(t);if(c&&Hv(r,c.providerId,c.modelId)){let e=s?i.getAgentModelVariantForSession?.(t,s,c.providerId,c.modelId):void 0,n=e&&Wv(r,c.providerId,c.modelId,e)?e:void 0;return{agent:s,providerID:c.providerId,modelID:c.modelId,variant:n,source:`session-memory`}}return null},qv=(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))},Jv=(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}},Yv=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}:{}}},Xv=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},Zv=500,Qv=e=>Array.from(e).length,$v=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},ey=e=>Qv(e)>=Zv,ty=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},ny=(e,t)=>{let n=t??e;return typeof n!=`string`||!ey(n)?!1:ue(typeof e==`string`?{text:``,references:[]}:e,n)},ry=(e,t,n,r,i=1)=>{let a=Qv(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}-${$v(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},iy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),ay=e=>e.map(e=>({...e,range:{...e.range}})),oy=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),sy=(e,t,n)=>({document:iy(e),mentions:ay(t),selection:{...n}}),cy=()=>({undo:[],redo:[]}),ly=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),uy=(e,t)=>{let n=e.undo.at(-1);return!n||!oy(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:sy(n.before.document,n.before.mentions,n.before.selection)}},dy=(e,t)=>{let n=e.redo.at(-1);return!n||!oy(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:sy(n.after.document,n.after.mentions,n.after.selection)}},fy=e=>({text:e?.text??``,references:e?.composerReferences??[]}),py=e=>({text:e.text,references:e.references.map(e=>({...e}))}),my=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),hy=e=>JSON.stringify([e.text,e.references]),gy=(e,t)=>e!==null&&t!==null&&le(e)===t,_y=(e,t,n)=>{let r=e?my(e):null,i=r?n(r):void 0;return{document:D(fy(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?le(r):null}},vy=(e,t,n,r)=>{if(!t||le(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=hy(fy(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===hy(e)?`same-document-metadata`:`external-document`},yy=(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}]:[]})},by=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),xy=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:yy(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},Sy=(e,t,n)=>({preview:{real:py(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Cy=e=>({document:e.real,mentions:e.realMentions}),wy=(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)})},Ty=(e,t)=>{let n=fy(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:wy(e.mentions,t?.mentions??[],r,i)}},Ey=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=Rn})=>{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)(()=>_y(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>_y(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?my(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)(cy());_.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=_y(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=cy(),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||!gy(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(fy(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=vy(_.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(fy(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!gy(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:by(t)});if(!a)return;let o=fy(a);return M.current={keyID:le(n),revision:a.revision,fingerprint:hy(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=ly(P.current,{before:sy(e,t,n),after:sy(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)=>{let r=z(),i=py(_.current),a=r?[]:b.current,o=xy(i,a,e,t,n);return L(o.document,o.mentions),o.removedReferences.length>0&&R(i,a,{start:o.selectionStart,end:o.selectionEnd},o.document,o.mentions,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd,requiresTextCorrection:o.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=yy(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,yy(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=py(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=yy(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=yy(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`?uy(P.current,_.current):dy(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:[]}:Sy(_.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=Cy(e);F(t.document,t.mentions)},[F]),ie=(0,Z.useCallback)(()=>{let e=w.current;if(!gy(e,T.current))return null;let t=i.getState().getDraft(e);return{key:my(e),keyID:le(e),revision:t?.revision??0,document:py(_.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=Ty(e,i.getState().getDraft(e.key)),n=fy(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:by(t.mentions)});if(a){let e=fy(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 Dy(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 Oy=`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`,ky=Mo(()=>Ve(()=>import(`./ToolOutputDialog-C1R-GCPB.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]))),Ay=[],jy=[],My=[],Ny=[],Py=/^@[^\s]+$/,Fy=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Iy=/^(https?:\/\/|mailto:)\S+$/i,Ly=560,Ry=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),zy=(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)},By=e=>e.includes(`@`)?`paste`:`manual`,Vy=(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}},Hy=(e,t)=>br(e,t).some(e=>e.role===`user`),Uy=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Xt(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6525
6525
  `).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},Wy=`file://`,Gy=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(`/`)},Ky=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Wy)?t:`file://${Gy(t)}`},qy=e=>{if(!e)return[];let t=[...q_(e).map(J_),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(Y_)))},Jy=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},Yy=e=>Qi(e.path),Xy=(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)]})},Zy=Z.memo(bm),Qy=Z.memo(ll),$y=Z.memo(Oh),eb=Z.memo(jh),tb=Z.memo(Ym),nb=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=it(),r=c(e=>e.isMobile),i=J(e=>e.revertToMessage),a=J(e=>e.forkFromMessage),o=J(e=>e.handleSlashRedo),[s,l]=Z.useState(null),[u,d]=Z.useState(null),[f,p]=Z.useState(!0),m=Z.useRef(p_),h=vr(),g=t||h,_=xt(g),v=di(e??``,g,_),y=qn(e=>e.session,g),b=Z.useMemo(()=>{let t=v.messageOrder.map(e=>v.messagesByID[e]).filter(e=>!!e),n=g_({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:Uy(e.parts,C)})):[],[C,x,b]),T=w[0]?.id;Z.useEffect(()=>{p(!0)},[x,T]);let E=Z.useCallback(async t=>{if(!(!e||s)){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,s,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)(oa,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||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)(oa,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||u),onClick:()=>{E(e.id)},children:[s===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});nb.displayName=`RevertedMessageDock`;var rb=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=it(),{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?pb:void 0,v=f?mb: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)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:S}),(0,$.jsx)(Pa,{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),ib=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=it(),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=()=>kv({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)(Na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:hb,onPointerDownCapture:gb,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)(Pa,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Fa,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),ab=Z.memo(function(e){let t=(0,Q.c)(59),{isMobile:n,footerIconButtonClass:r,sendIconSizeClass:i,stopIconSizeClass:a,canSend:o,canAbort:s,hasContent:c,currentSessionId:l,newSessionDraftOpen:u,draftSubmitting:d,submissionBlocked:f,sendPhase:p,queueFrozen:m,queueFallbackAvailable:h,onPrimaryAction:g,onAbort:_}=e,{t:v}=it(),y,b,x;if(t[0]!==s||t[1]!==o||t[2]!==l||t[3]!==d||t[4]!==r||t[5]!==c||t[6]!==n||t[7]!==u||t[8]!==g||t[9]!==h||t[10]!==m||t[11]!==i||t[12]!==p||t[13]!==f||t[14]!==v){x=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Wh({canSend:o,hasSessionTarget:!!(l||u),draftSubmitting:!!d,submissionBlocked:f,sendPhase:p,queueFrozen:m,queueFallbackAvailable:h}),a;t[18]===n?a=t[19]:(a=n?{onMouseDown:_b,onPointerDownCapture:vb}:{},t[18]=n,t[19]=a);let _=a,S=p.inFlight,C=S&&p.flightKind===`queue`,w=S&&p.flightKind!==`queue`,T;t[20]!==s||t[21]!==h||t[22]!==m||t[23]!==C||t[24]!==w||t[25]!==v?(T=v(C?`chat.chatInput.actions.queuingMessageAria`:w?`chat.chatInput.actions.sendingMessageAria`:m&&h&&s?`chat.chatInput.actions.sendMessageAria`:s?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[20]=s,t[21]=h,t[22]=m,t[23]=C,t[24]=w,t[25]=v,t[26]=T):T=t[26];let E=T,D=S?`loader-4`:`send-plane-2`,O=e.sendDisabled,k;t[27]!==n||t[28]!==g?(k=e=>{n&&(e.preventDefault(),g())},t[27]=n,t[28]=g,t[29]=k):k=t[29];let A=Y(r,e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),j;t[30]!==s||t[31]!==S||t[32]!==C||t[33]!==w||t[34]!==v?(j=v(w||!s&&S?C?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[30]=s,t[31]=S,t[32]=C,t[33]=w,t[34]=v,t[35]=j):j=t[35];let M=S?`loader-4`:`send-plane-2`,N=S&&`animate-spin`,P;t[36]!==i||t[37]!==N?(P=Y(i,N),t[36]=i,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`,disabled:O,"aria-busy":S||void 0,..._,onClick:k,className:A,"aria-label":j,children:F});if(!s){x=I;break bb0}y=`relative z-30 overflow-visible`,b=c||C?(0,$.jsx)(`button`,{type:`button`,disabled:e.sendDisabled||C,"aria-busy":C||void 0,..._,onClick:e=>{e.preventDefault(),!C&&g()},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(i,C?`animate-spin`:`-rotate-90`)})}):null}t[0]=s,t[1]=o,t[2]=l,t[3]=d,t[4]=r,t[5]=c,t[6]=n,t[7]=u,t[8]=g,t[9]=h,t[10]=m,t[11]=i,t[12]=p,t[13]=f,t[14]=v,t[15]=y,t[16]=b,t[17]=x}else y=t[15],b=t[16],x=t[17];if(x!==Symbol.for(`react.early_return_sentinel`))return x;let S;t[42]===r?S=t[43]:(S=Y(r,`relative z-30 text-[var(--status-error)] hover:text-[var(--status-error)]`),t[42]=r,t[43]=S);let C;t[44]===v?C=t[45]:(C=v(`chat.chatInput.actions.stopGeneratingAria`),t[44]=v,t[45]=C);let w;t[46]===a?w=t[47]:(w=Y(a),t[46]=a,t[47]=w);let T;t[48]===w?T=t[49]:(T=(0,$.jsx)(Lh,{className:w}),t[48]=w,t[49]=T);let E;t[50]!==_||t[51]!==S||t[52]!==C||t[53]!==T?(E=(0,$.jsx)(`button`,{type:`button`,onClick:_,className:S,"aria-label":C,children:T}),t[50]=_,t[51]=S,t[52]=C,t[53]=T,t[54]=E):E=t[54];let D;return t[55]!==y||t[56]!==b||t[57]!==E?(D=(0,$.jsxs)(`div`,{className:y,children:[b,E]}),t[55]=y,t[56]=b,t[57]=E,t[58]=D):D=t[58],D},(e,t)=>e.isMobile===t.isMobile&&e.footerIconButtonClass===t.footerIconButtonClass&&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),ob=(e,t)=>`${e}${e?e.endsWith(`
6526
6526
 
6527
6527
  `)?``:e.endsWith(`
@@ -6573,7 +6573,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T
6573
6573
 
6574
6574
  `):MT(Array.from(t.childNodes).map(e=>LT(e)).join(``))},BT=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!AT.has(t.tagName.toLowerCase())}),VT=(e,t)=>{let n=e.cloneContents();if(BT(n)){let e=MT(Array.from(n.childNodes).map(e=>LT(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>zT(e)).filter(e=>e.length>0).join(`
6575
6575
 
6576
- `).trim()||MT(t)},HT=({containerRef:e})=>{let{t}=it(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),l=Z.useRef(!1),[u,f]=Z.useState(!1),[p,m]=Z.useState(!1),h=Z.useRef(null),g=Z.useRef(OT),_=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=J(e=>e.createSession),S=J(e=>e.currentSessionId),C=Rn(e=>e.setPendingInputText),w=c(e=>e.isMobile),T=Nr(e=>e.projects),E=J(e=>e.availableWorktreesByProject),D=ts(),O=ki(),k=Gm(Wm()).textSelectionMutation;Z.useEffect(()=>{b.current=n.show},[n.show]),Z.useEffect(()=>()=>{v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),y.current!==null&&(window.clearTimeout(y.current),y.current=null)},[]);let A=Z.useCallback(()=>{_.current=null,kT===A&&(kT=null),b.current&&=(v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),f(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{kT===A&&(kT=null)},[A]);let j=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=g.current/2,r=DT+n,i=t-DT-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),M=Z.useCallback(()=>{if(!_.current)return;kT!==A&&(kT?.(),kT=A);let{plainText:e,markdownText:t,rect:i}=_.current,o=!n.show,c=w?i.left+i.width/2:j(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),b.current=!0,o&&(f(!0),v.current!==null&&window.cancelAnimationFrame(v.current),v.current=window.requestAnimationFrame(()=>{f(!1),v.current=null}))},[j,A,w,n.show]);Z.useLayoutEffect(()=>{if(!n.show||w||!h.current)return;let e=h.current.offsetWidth;!Number.isFinite(e)||e<=0||e===g.current||(g.current=e,r(e=>({...e,x:j(e.x)})))},[j,w,n.show]),Z.useEffect(()=>{if(!n.show||w)return;let e=()=>{r(e=>({...e,x:j(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[j,w,n.show]);let N=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||A();return}let r=MT(t.toString());if(!r){l.current||A();return}let i=FT(t,n);if(!i){l.current||A();return}let a=i.getBoundingClientRect();_.current={plainText:r,markdownText:VT(i,r),rect:a},l.current||M()},[e,A,M]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,A()},r=()=>{l.current=!1,y.current!==null&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>{y.current=null,N()},10)},i=new Set,a=()=>{for(let e of PT(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,N))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,N),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{h.current&&!h.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&A()};return document.addEventListener(`mousedown`,s),()=>{y.current!==null&&(window.clearTimeout(y.current),y.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,N);document.removeEventListener(`selectionchange`,N),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,N,A,M]);let P=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;C(t,`append`),A(),window.getSelection()?.removeAllRanges()},[C,A]),F=Z.useCallback(()=>{P(o)},[P,o]);Z.useEffect(()=>{let t=t=>{if(!k||!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=FT(n,r);i&&(t.preventDefault(),P(VT(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[P,k,e]);let I=Z.useCallback(async()=>{i&&(await x(void 0,null,null)&&C(i,`replace`),A(),window.getSelection()?.removeAllRanges())},[i,x,C,A]),L=Z.useCallback(async()=>{if(!i)return;let e=await ot(i);e.ok||console.error(`Failed to copy:`,e.error),A(),window.getSelection()?.removeAllRanges()},[i,A]),R=Z.useMemo(()=>S?O.find(e=>e.id===S)??null:null,[S,O]),z=Z.useMemo(()=>{let e=D??(typeof R?.directory==`string`?R.directory:``),t=wn(T,E,e);return t?{id:t.id,path:t.path}:null},[E,R?.directory,D,T]),B=Z.useCallback(async()=>{if(!i||!z){z||Pi.error(t(`chat.textSelection.toast.noProject`));return}try{m(!0);let e=await hn(o||i,S),n=await Rt(z),r=ET(n.notes,e);if(!await Un(z,{notes:r,todos:n.todos})){Pi.error(t(`chat.textSelection.toast.addToNotesFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-notes-updated`,{detail:{projectId:z.id}})),Pi.success(t(`chat.textSelection.toast.addToNotesSuccess`)),A(),window.getSelection()?.removeAllRanges()}catch(e){let n=e instanceof Error?e.message:void 0;Pi.error(t(`chat.textSelection.toast.addToNotesFailed`),n?{description:n}:void 0)}finally{m(!1)}},[z,S,A,i,o,t]);return n.show?w?(0,_c.createPortal)((0,$.jsx)(`div`,{ref:h,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:[k?(0,$.jsxs)(`button`,{onClick:F,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,k?(0,$.jsxs)(`button`,{onClick:I,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:L,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(--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`)})]}),k&&!d()?(0,$.jsxs)(`button`,{onClick:B,disabled:p,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(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80 disabled:opacity-60 disabled:cursor-not-allowed`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 flex-shrink-0 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToNotes`)})]}):null]})}),document.body):(0,_c.createPortal)((0,$.jsx)(`div`,{ref:h,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:[k?(0,$.jsxs)(`button`,{onClick:F,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)(ap,{shortcut:`⌘+I`})]}):null,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,k?(0,$.jsxs)(`button`,{onClick:I,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,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:L,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`)})]}),k&&!d()?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}),(0,$.jsxs)(`button`,{onClick:B,disabled:p,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)] disabled:opacity-60 disabled:cursor-not-allowed`,`transition-colors duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToNotes`)})]})]}):null]})}),document.body):null},UT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),WT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),UT(e,n)},GT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),KT=(e,t)=>{if(!GT(e))return``;let n=new Date(e),r=new Date,i=io(n,t),a=at(),o=st.getState().dictionary;if(UT(n,r))return i;if(WT(n,r))return ct(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}`},qT=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,JT=e=>e,YT=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=JT(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},XT=(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-YT(n);return!Number.isFinite(a)||a<=0?null:a},ZT=e=>{let t=XT(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=qT(e.outputTokens)+qT(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},QT=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`},$T=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},eE=[`search`,`read`,`list`];function tE(e){let t=ZS(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function nE(e){let t={read:0,search:0,list:0};for(let n of e){let e=tE(n);e&&(t[e]+=1)}return t}function rE(e){return XS(e)}function iE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!qS(e.toolName):e.kind!=null||e.type!=null}function aE(e,t,n){for(let r=t;r<e.length;r+=1)if(iE(n(e[r])))return!0;return!1}function oE(e){return`parts`in e?e.parts.some(e=>rE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>rE(e))}function sE(e,t,n){let r=[],i=t;for(;i<e.length&&qS(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var cE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,lE=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=it(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??oE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=nE(u.map(e=>e.tool)),p=eE.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:xp(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 w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Sp),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)(FS,{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,cE,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,cE),style:{color:`var(--tools-description)`},children:(0,$.jsx)($T,{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 uE(e,t,n){let r=[],i=t;for(;i<e.length&&JS(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var dE=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function fE(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=dE(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=dE(e.name);if(t)return t;let r=dE(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=dE(n.output.name);if(e)return e}return null}function pE(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 mE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,hE=({activities:e,isMobile:t,children:n})=>{let{t:r}=it(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>XS(e)),{joinedVisible:l,hiddenCount:u}=pE(s.map(fE)),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:xp(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 w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Sp),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)(FS,{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`,mE,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`,mE),style:{color:`var(--tools-description)`},children:(0,$.jsx)($T,{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]})},gE=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,l=c(_E),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]!==s||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)(Ow,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:s})}),t[4]=l,t[5]=r,t[6]=i,t[7]=s,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 _E(e){return e.chatRenderMode}var vE=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},yE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,bE=Y(`typography-meta font-medium`,yE),xE=Y(`typography-meta`,yE),SE=[],CE=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},wE=e=>{let t=new Set;for(let n of e)CE(n)&&n.messageId&&t.add(n.messageId);return[...t]},TE=(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}),EE=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=Jo(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},DE=e=>e,OE=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},kE=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},AE=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},jE=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},ME=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=jE(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`}`},NE=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=ME(n.todos);if(e)return e}if(Array.isArray(r)){let e=ME(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=ME(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=ME(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=ME(e.todos);if(t)return t}}catch{}return null},PE=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)},FE=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)($b,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,xE),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`,xE),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)($b,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},IE=e=>{let t=go(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},LE=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 fE(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`?NE(e):OE(e)},RE=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}},zE=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=xp(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)(cw,{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&&Vx([e.activity.part],[t.activity.part])),BE=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=xp(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(UE,{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&&HE(e.activities,t.activities)),VE=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Jw(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(qS(i)){let r=sE(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:aE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(JS(i)){let r=uE(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(GS(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(WS(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(KS(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},HE=(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||!Vx([r.part],[i.part]))return!1}return!0},UE=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=it(),s=c(qE),l=Xo(n,o),u;t[0]===n?u=t[1]:(u=ex(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(To),h=lh(),g=Le(JE),_=Wm(),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=ut(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(YE)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||XS(D.part),k;t[12]===D?k=t[13]:(k=D?LE(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||AE(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=IE(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=kE(D);if(!e){N=null;break bb1}let n=mo(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=PE(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=ho(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(!yo(n,v)){ns(n,v).then(()=>{let e=c.getState(),r=v||po(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=c.getState(),i=po(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=go(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=c.getState(),n=v||po(``,t);e.openContextFile(n,t)};if(v&&!yo(t,v)){ns(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`,Sp,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)(FS,{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(bE,`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]!==s?(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`,xE),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[s?(0,$.jsx)(Tu,{filePath:P.path,className:`h-3.5 w-3.5`}):null,FE(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=s,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)($b,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,xE),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:XE,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`,xE),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(EE,{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`,xE),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`,xE),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 Te;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Te=!p&&!V&&!H&&!U&&A?(0,$.jsx)($b,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,xE),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]=Te):Te=t[89];let Ee;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==le||t[95]!==ue||t[96]!==de||t[97]!==ge||t[98]!==ye||t[99]!==be||t[100]!==xe||t[101]!==Se||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:le,tabIndex:ue,"aria-disabled":de,children:[ge,ye,be,xe,Se,Ce,we,Te]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=le,t[95]=ue,t[96]=de,t[97]=ge,t[98]=ye,t[99]=be,t[100]=xe,t[101]=Se,t[102]=Ce,t[103]=we,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&HE(e.activities,t.activities)),WE=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)(Bw,{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}),GE=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)(gE,{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}),KE=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}=it(),_=ts()??``,v=Z.useMemo(()=>wE(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?vE(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(()=>RE(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=gr(_,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=ii(_,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=q(()=>{let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,n||P(),s()});Z.useEffect(()=>{T||!n||P(!1,!0)},[T,n]),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)},[n]);let L=m&&!n?Math.max(0,Math.floor(r)):0,R=!m||n||L>0,z=y.current,B=[...z].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 gr(_,n,e).status}),V=B.includes(`loading`),H=B.includes(`error`),U=B.length>0&&B.every(e=>e===`ready`),W=t.some(e=>z.has(e.messageId)&&CE(e)),ee=U&&!W&&!TE(t,z),G=Z.useMemo(()=>R?DE(e):SE,[e,R]),K=Z.useMemo(()=>R?VE(G):[],[R,G]),te=Z.useMemo(()=>n||L===0?0:Math.max(0,K.length-L),[n,L,K.length]),ne=Z.useMemo(()=>n||L===0?K:K.slice(-L),[n,L,K]);if(!m&&K.length===0)return null;let re=(e,t)=>{let n=(0,$.jsx)(`div`,{className:xp(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ie=R?ne.map((e,t)=>{switch(e.type){case`reasoning`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(WE,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(GE,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(zE,{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)(BE,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(lE,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(UE,{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)(hE,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(UE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(zE,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,ae=ne.length>0;return m?(0,$.jsxs)(`div`,{className:xp(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`,Sp,c&&`pr-0`),"data-mobile-press-feedback":`soft`,onClick:I,"aria-expanded":n,"aria-label":g(n?`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)(FS,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-[14px] w-[14px]`})}),(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)(Zi,{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,(0,$.jsx)(X,{name:n?`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`)})]})]}),ae?(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3`,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)`}}),te>0?(0,$.jsxs)(`button`,{type:`button`,onClick:I,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,te,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ie})]}):null,n&&(V||H||ee)?(0,$.jsx)(`div`,{className:Y(`typography-meta ml-5 flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,H&&`text-[var(--status-error)]`),role:H?`alert`:`status`,children:V?(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`)})]}):H?(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)(oa,{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:xp(c),children:ie})});function qE(e){return e.showToolFileIcons}function JE(e){return e.currentDirectory}function YE(e){return[e.name,e]}function XE(e){e.stopPropagation()}var ZE=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(KE,{...e}),t[0]=e,t[1]=n),n}),QE={contain:`layout`},$E={containerType:`inline-size`,containerName:`message-footer`},eD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,tD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,nD=`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`,rD=`size-3.5!`,iD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,aD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,oD=`flex items-center gap-2`,sD=`flex items-center gap-2 text-muted-foreground`,cD=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,lD=`size-3.5!`,uD=`medium`,dD=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,fD=`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)]`,pD=`h-7 gap-1.5`,mD=`h-6 gap-1`,hD=`text-[11px] leading-none`,gD=`size-3.5`,_D=`size-3`,vD=5,yD=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)(Tu,{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=dD(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}),bD=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=it(),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?mD:pD,d;t[3]===u?d=t[4]:(d=Y(fD,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)(yD,{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)(oa,{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}),xD=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=it(),l=ts(),u=Wm(),d=u.directory||l,f=u.sessionId,p=lh(),m=c(FD),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,vD),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]!==s?(S=s(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=s,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==s?(w=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=s,t[9]=w):w=t[9];let T=w,E=Y(fD,o?mD:pD),D=o?_D:gD,O;t[10]===o?O=t[11]:(O=o?Y(hD,`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(hD,`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(hD,`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){Uw({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&Uw({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&&Uw({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]===s?V=t[35]:(V=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=V);let H;t[36]===s?H=t[37]:(H=s(`diffView.actions.reviewAria`),t[36]=s,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]===s?ee=t[41]:(ee=s(`chat.changedFiles.title`),t[40]=s,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)(oa,{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)(bD,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(oa,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":s(`diffView.actions.reviewAria`),title:s(`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]})}),SD=e=>e.type===`subtask`,CD=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},wD=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}`},TD=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=ts(),{isMobile:o}=co(),s=J(ID),l=c(LD),u=Wm(),{t:f}=it(),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=wD(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(RD),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]!==s||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:()=>{a&&Km(u,S,a,()=>{if(!oi({sessionId:S,directory:a})){if(Ec()||o||d()){s(S,a);return}l(a,{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]=s,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},ED=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=ts(),i=c(zD),{isMobile:a}=co(),{t:o}=it(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let l=!!s,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)(ko,{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},DD={background:`transparent`,backgroundColor:`transparent`},OD=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}=it(),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 ot(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)(Ys,{language:`bash`,code:u,codeStyle:DD,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(BD),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)(Ys,{language:`bash`,code:d,codeStyle:DD,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},kD=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},AD=(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}},jD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,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}=it(),T=Eh(),E=Gm(Wm()),D=c(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Yw(e):!!(SD(e)||CD(e))),[n]),M=Z.useMemo(()=>j.map(e=>Xt(e)?bx(Jw(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(s??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=KT(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(oD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(cD,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:uD,name:`edit`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:uD,name:`close`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,ne=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(oD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(cD,`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(oD,`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)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(cD,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:uD,name:`time`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(Pa,{children:G})]}):null,h&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"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:uD,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(rD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:uD,name:`edit`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"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:uD,name:_===`fork`?`loader-4`:`git-branch`,className:Y(rD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:nD,"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:uD,name:`check`,className:Y(rD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:uD,name:`file-copy`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:QE,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(SD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(TD,{part:e})},e.id??`user-subtask-${i}`);if(CD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(OD,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ED,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Jw(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(Zb,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Zu,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),ne]}):(0,$.jsx)($.Fragment,{children:ne})}),MD=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=it(),s=Eh(),c=Wm(),l=Gm(c),{isPlaying:u,play:d,stop:f}=TT(),p=Zn(e=>e.showMessageTTSButtons),m=Zn(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)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(nD,!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:uD,name:`check`,className:Y(rD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:uD,name:`file-copy`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:uD,name:`target`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(nD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:uD,name:`loader-4`,className:Y(rD,`animate-spin`)}):(0,$.jsx)(X,{weight:uD,name:`arrow-left-right`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:Y(nD,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:uD,name:`stop`,className:rD}):(0,$.jsx)(X,{weight:uD,name:`volume-up`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:j})]})]})}),ND=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,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}=it(),A=Eh(),j=Gm(Wm()),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?aD:iD,B=!i,V=Z.useMemo(()=>n.filter(e=>!Yw(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(()=>An(U),[U]),ee=c(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=Yo(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=Yo(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=J(e=>e.forkFromMessage),re=J(e=>e.forkTransition),ie=J(e=>e.currentSessionId),ae=J(e=>e.getDirectoryForSession),oe=ts(),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 _t(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 Qr(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=c(e=>e.chatRenderMode),pe=c(e=>e.collapsibleThinkingBlocks),me=c(e=>e.showSplitAssistantMessageActions),he=c(e=>e.showAssistantTps),ge=c(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=>XS(e)),[H]),we=XS,Te=YS,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||!zn())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Nt(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Tt({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=tT(a,V),$e={finish:a,parts:V,streamPhase:xe,error:T,isLastAssistantInTurn:ve},et=aT($e),tt=_e&&oT($e),nt=_e&&!et&&!(qe&&Je),rt=!!T,at=E===`info`?`information`:`error-warning`,st=Be,ct=ve&&be&&!Ye&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&ve&&Qe&&be&&!Ye&&w?.diffStats?.hasDiffs===!0,dt=me&&st&&!ct&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(MD,{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=Jw(e.part).trim();return t?(0,$.jsx)(MD,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ot(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)(ZE,{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)(Ow,{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?tD:eD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:oD,"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(!Jw(i).trim()){r+=1;continue}C&&(pe?n.push((0,$.jsx)(`div`,{className:xp(u),children:(0,$.jsx)(Bw,{part:i,messageId:t,streamPhase:xe,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(Ow,{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(qS(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!qS(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)(lE,{activities:e,isMobile:u,isTurnLive:xe!==`completed`,hasFollowingOtherType:aE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(UE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(JS(a)){let e=uE(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)(hE,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(UE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(WS(a)){n.push((0,$.jsx)(`div`,{className:xp(u),children:(0,$.jsx)(cw,{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:xp(u),children:(0,$.jsx)(UE,{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]),vt=Z.useMemo(()=>{if(!ve||!be)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return kD(e)},[ve,be,w?.durationMs]),yt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=KT(e,ge);return t.length>0?t:null},[o,s,ge,k]),bt=Z.useMemo(()=>{if(!he||!ve||!be)return null;let e=r??n,t=AD(e,l),i=ZT({createdAt:s,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=QT(i);return a.length>0?a:null},[he,ve,be,n,r,l,s,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&te?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"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:uD,name:`global`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!se&&j.fork?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,size:`icon`,variant:`ghost`,className:nD,"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:uD,name:ue?`loader-4`:`git-branch`,className:Y(rD,ue&&`animate-spin`)})})}),(0,$.jsx)(Pa,{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:QE,children:[(0,$.jsx)(HT,{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)(cs,{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:uD,className:Y(rD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:at,weight:E===`info`?uD:void 0,className:Y(`shrink-0`,E===`info`?Y(rD,`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)(ko,{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)(xD,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(Zu,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?tD:eD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:oD,"data-message-action-group":`true`,children:ft})}),ct&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:$E,children:[(0,$.jsxs)(`div`,{className:oD,"data-message-action-group":`true`,children:[ft,xt]}),bt||vt||yt?(0,$.jsxs)(`div`,{className:sD,children:[bt?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cD,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:uD,name:`pulse`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(Pa,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,vt?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cD,children:[(0,$.jsx)(X,{weight:uD,name:`hourglass`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Pa,{children:vt})]}):null,yt?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cD,"aria-label":`Message time: ${yt}`,children:[(0,$.jsx)(X,{weight:uD,name:`time`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Pa,{children:yt})]}):null]}):null,!K&&ve&&ye&&!lt?(0,$.jsx)(Ww,{activityParts:w?.activityParts}):null]})]})]})}),PD=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)(jD,{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)(ND,{...r}),t[26]=r,t[27]=i),i});function FD(e){return e.openContextPanelTab}function ID(e){return e.setCurrentSession}function LD(e){return e.openContextPanelTab}function RD(e){return!e}function zD(e){return e.openContextPanelTab}function BD(e){return!e}var VD=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}},HD=`Authentication failed for this provider. Please re-authenticate and retry.`,UD=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},WD=Mo(()=>Ve(()=>import(`./ToolOutputDialog-D3U6aTZ4.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]))),GD=4e3,KD=new Map,qD=new Map,JD=new Set([`bash`,`shell`,`cmd`,`terminal`]),YD=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},XD=e=>{let t=KD.get(e);return t?new Set(t):new Set},ZD=(e,t)=>{if(KD.size>=GD&&!KD.has(e)){let e=KD.keys().next().value;typeof e==`string`&&KD.delete(e)}KD.set(e,new Set(t))},QD=e=>{let t=qD.get(e);return t?new Set(t):new Set},$D=(e,t)=>{if(qD.size>=GD&&!qD.has(e)){let e=qD.keys().next().value;typeof e==`string`&&qD.delete(e)}qD.set(e,new Set(t))},eO=200,tO=new Map,nO=e=>tO.get(e),rO=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=tO.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(tO.size>=eO&&!tO.has(e)){let e=tO.keys().next().value;typeof e==`string`&&tO.delete(e)}tO.set(e,t)}};function iO(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 aO=(e,t)=>{if(typeof e==`object`&&e)return e[t]},oO=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{isMobile:p,isTablet:m,hasTouchInput:h}=co(),g=Wm(),_=Gm(g),v=p||m,y=Z.useRef(null),b=J(e=>e.currentSessionId),x=It(e=>e.getAgentModelForSession),S=It(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);je(`ui.chat_message.render`),s&&je(`ui.chat_message.render.streaming`);let k=Zn(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=c(me(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Rb.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(()=>XD(e.info.id)),[U,W]=Z.useState(()=>QD(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(XD(e.info.id)),W(QD(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>VD(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}=Ip(me(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>qw(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>K?Ri(se,{planModeEnabled:ie}):qw(e.parts),[K,e.parts,ie,se]),le=Z.useMemo(()=>{if(K||!t)return null;let e=aO(t.info,`clientRole`),n=aO(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=aO(t.info,`mode`),i=aO(t.info,`agent`),a=aO(t.info,`providerID`),o=aO(t.info,`modelID`),s=aO(t.info,`variant`),c=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,l=typeof a==`string`&&a.trim().length>0?a:void 0,u=typeof o==`string`&&o.trim().length>0?o:void 0,d=typeof s==`string`&&s.trim().length>0?s:void 0;return!c&&!l&&!u&&!d?null:{agentName:c,providerId:l,modelId:u,variant:d}},[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=aO(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=aO(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:aO(e.info,`providerID`),pe=K?null:aO(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?nO(e.info.id):void 0;K||rO(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 Hn(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=iO(ye),Te=iO(be??void 0),Ee=iO(xe??void 0),De=iO(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,Me=De??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(()=>K?!0:!!(Ne&&Ne>0),[K,Ne]),Ie=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(()=>Xw(ce,{includeReasoning:A}),[ce,A]),ze=Z.useMemo(()=>K?Re:!Fe&&M===`sorted`?[]:Re,[M,Fe,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=YD(t.tool);!r||!JD.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=YD(t.part.tool);!n||!JD.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&&ze.length===0,Ke=typeof Ie!=`string`,qe=Z.useMemo(()=>K?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,K]),Je=Z.useMemo(()=>!K&&Rb.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?VD(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=a?.isWorking===!0||s,tt=Z.useMemo(()=>K?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,K,Ze]),nt=Z.useMemo(()=>Fe?`completed`:s?l??`streaming`:`completed`,[l,s,Fe]);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=>{ot(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),at=K?void 0:a?.userMessageVariant??le?.variant,st=!K&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,ct=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`}:UD(a)?{text:HD,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=ct?.text,ut=ct?.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(`
6576
+ `).trim()||MT(t)},HT=({containerRef:e})=>{let{t}=it(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),l=Z.useRef(!1),[u,f]=Z.useState(!1),[p,m]=Z.useState(!1),h=Z.useRef(null),g=Z.useRef(OT),_=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=J(e=>e.createSession),S=J(e=>e.currentSessionId),C=Rn(e=>e.setPendingInputText),w=c(e=>e.isMobile),T=Nr(e=>e.projects),E=J(e=>e.availableWorktreesByProject),D=ts(),O=ki(),k=Gm(Wm()).textSelectionMutation;Z.useEffect(()=>{b.current=n.show},[n.show]),Z.useEffect(()=>()=>{v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),y.current!==null&&(window.clearTimeout(y.current),y.current=null)},[]);let A=Z.useCallback(()=>{_.current=null,kT===A&&(kT=null),b.current&&=(v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),f(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{kT===A&&(kT=null)},[A]);let j=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=g.current/2,r=DT+n,i=t-DT-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),M=Z.useCallback(()=>{if(!_.current)return;kT!==A&&(kT?.(),kT=A);let{plainText:e,markdownText:t,rect:i}=_.current,o=!n.show,c=w?i.left+i.width/2:j(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),b.current=!0,o&&(f(!0),v.current!==null&&window.cancelAnimationFrame(v.current),v.current=window.requestAnimationFrame(()=>{f(!1),v.current=null}))},[j,A,w,n.show]);Z.useLayoutEffect(()=>{if(!n.show||w||!h.current)return;let e=h.current.offsetWidth;!Number.isFinite(e)||e<=0||e===g.current||(g.current=e,r(e=>({...e,x:j(e.x)})))},[j,w,n.show]),Z.useEffect(()=>{if(!n.show||w)return;let e=()=>{r(e=>({...e,x:j(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[j,w,n.show]);let N=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||A();return}let r=MT(t.toString());if(!r){l.current||A();return}let i=FT(t,n);if(!i){l.current||A();return}let a=i.getBoundingClientRect();_.current={plainText:r,markdownText:VT(i,r),rect:a},l.current||M()},[e,A,M]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,A()},r=()=>{l.current=!1,y.current!==null&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>{y.current=null,N()},10)},i=new Set,a=()=>{for(let e of PT(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,N))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,N),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{h.current&&!h.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&A()};return document.addEventListener(`mousedown`,s),()=>{y.current!==null&&(window.clearTimeout(y.current),y.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,N);document.removeEventListener(`selectionchange`,N),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,N,A,M]);let P=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;C(t,`append`),A(),window.getSelection()?.removeAllRanges()},[C,A]),F=Z.useCallback(()=>{P(o)},[P,o]);Z.useEffect(()=>{let t=t=>{if(!k||!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=FT(n,r);i&&(t.preventDefault(),P(VT(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[P,k,e]);let I=Z.useCallback(async()=>{i&&(await x(void 0,null,null)&&C(i,`replace`),A(),window.getSelection()?.removeAllRanges())},[i,x,C,A]),L=Z.useCallback(async()=>{if(!i)return;let e=await ot(i);e.ok||console.error(`Failed to copy:`,e.error),A(),window.getSelection()?.removeAllRanges()},[i,A]),R=Z.useMemo(()=>S?O.find(e=>e.id===S)??null:null,[S,O]),z=Z.useMemo(()=>{let e=D??(typeof R?.directory==`string`?R.directory:``),t=wn(T,E,e);return t?{id:t.id,path:t.path}:null},[E,R?.directory,D,T]),B=Z.useCallback(async()=>{if(!i||!z){z||Pi.error(t(`chat.textSelection.toast.noProject`));return}try{m(!0);let e=await hn(o||i,S),n=await Rt(z),r=ET(n.notes,e);if(!await Un(z,{notes:r,todos:n.todos})){Pi.error(t(`chat.textSelection.toast.addToNotesFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-notes-updated`,{detail:{projectId:z.id}})),Pi.success(t(`chat.textSelection.toast.addToNotesSuccess`)),A(),window.getSelection()?.removeAllRanges()}catch(e){let n=e instanceof Error?e.message:void 0;Pi.error(t(`chat.textSelection.toast.addToNotesFailed`),n?{description:n}:void 0)}finally{m(!1)}},[z,S,A,i,o,t]);return n.show?w?(0,_c.createPortal)((0,$.jsx)(`div`,{ref:h,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:[k?(0,$.jsxs)(`button`,{onClick:F,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,k?(0,$.jsxs)(`button`,{onClick:I,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:L,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(--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`)})]}),k&&!d()?(0,$.jsxs)(`button`,{onClick:B,disabled:p,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(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80 disabled:opacity-60 disabled:cursor-not-allowed`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 flex-shrink-0 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToNotes`)})]}):null]})}),document.body):(0,_c.createPortal)((0,$.jsx)(`div`,{ref:h,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:[k?(0,$.jsxs)(`button`,{onClick:F,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)(ap,{shortcut:`⌘+I`})]}):null,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,k?(0,$.jsxs)(`button`,{onClick:I,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,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:L,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`)})]}),k&&!d()?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}),(0,$.jsxs)(`button`,{onClick:B,disabled:p,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)] disabled:opacity-60 disabled:cursor-not-allowed`,`transition-colors duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToNotes`)})]})]}):null]})}),document.body):null},UT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),WT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),UT(e,n)},GT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),KT=(e,t)=>{if(!GT(e))return``;let n=new Date(e),r=new Date,i=io(n,t),a=at(),o=st.getState().dictionary;if(UT(n,r))return i;if(WT(n,r))return ct(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}`},qT=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,JT=e=>e,YT=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=JT(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},XT=(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-YT(n);return!Number.isFinite(a)||a<=0?null:a},ZT=e=>{let t=XT(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=qT(e.outputTokens)+qT(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},QT=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`},$T=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},eE=[`search`,`read`,`list`];function tE(e){let t=ZS(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function nE(e){let t={read:0,search:0,list:0};for(let n of e){let e=tE(n);e&&(t[e]+=1)}return t}function rE(e){return XS(e)}function iE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!qS(e.toolName):e.kind!=null||e.type!=null}function aE(e,t,n){for(let r=t;r<e.length;r+=1)if(iE(n(e[r])))return!0;return!1}function oE(e){return`parts`in e?e.parts.some(e=>rE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>rE(e))}function sE(e,t,n){let r=[],i=t;for(;i<e.length&&qS(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var cE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,lE=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=it(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??oE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=nE(u.map(e=>e.tool)),p=eE.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:xp(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 w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Sp),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)(FS,{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,cE,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,cE),style:{color:`var(--tools-description)`},children:(0,$.jsx)($T,{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 uE(e,t,n){let r=[],i=t;for(;i<e.length&&JS(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var dE=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function fE(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=dE(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=dE(e.name);if(t)return t;let r=dE(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=dE(n.output.name);if(e)return e}return null}function pE(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 mE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,hE=({activities:e,isMobile:t,children:n})=>{let{t:r}=it(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>XS(e)),{joinedVisible:l,hiddenCount:u}=pE(s.map(fE)),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:xp(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 w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Sp),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)(FS,{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`,mE,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`,mE),style:{color:`var(--tools-description)`},children:(0,$.jsx)($T,{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]})},gE=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,l=c(_E),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]!==s||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)(Ow,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:s})}),t[4]=l,t[5]=r,t[6]=i,t[7]=s,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 _E(e){return e.chatRenderMode}var vE=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},yE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,bE=Y(`typography-meta font-medium`,yE),xE=Y(`typography-meta`,yE),SE=[],CE=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},wE=e=>{let t=new Set;for(let n of e)CE(n)&&n.messageId&&t.add(n.messageId);return[...t]},TE=(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}),EE=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=Jo(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},DE=e=>e,OE=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},kE=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},AE=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},jE=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},ME=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=jE(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`}`},NE=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=ME(n.todos);if(e)return e}if(Array.isArray(r)){let e=ME(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=ME(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=ME(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=ME(e.todos);if(t)return t}}catch{}return null},PE=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)},FE=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)($b,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,xE),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`,xE),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)($b,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},IE=e=>{let t=go(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},LE=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 fE(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`?NE(e):OE(e)},RE=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}},zE=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=xp(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)(cw,{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&&Vx([e.activity.part],[t.activity.part])),BE=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=xp(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(UE,{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&&HE(e.activities,t.activities)),VE=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Jw(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(qS(i)){let r=sE(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:aE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(JS(i)){let r=uE(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(GS(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(WS(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(KS(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},HE=(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||!Vx([r.part],[i.part]))return!1}return!0},UE=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=it(),s=c(qE),l=Xo(n,o),u;t[0]===n?u=t[1]:(u=ex(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(To),h=lh(),g=Le(JE),_=Wm(),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=ut(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(YE)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||XS(D.part),k;t[12]===D?k=t[13]:(k=D?LE(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||AE(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=IE(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=kE(D);if(!e){N=null;break bb1}let n=mo(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=PE(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=ho(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(!yo(n,v)){ns(n,v).then(()=>{let e=c.getState(),r=v||po(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=c.getState(),i=po(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=go(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=c.getState(),n=v||po(``,t);e.openContextFile(n,t)};if(v&&!yo(t,v)){ns(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`,Sp,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)(FS,{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(bE,`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]!==s?(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`,xE),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[s?(0,$.jsx)(Tu,{filePath:P.path,className:`h-3.5 w-3.5`}):null,FE(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=s,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)($b,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,xE),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:XE,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`,xE),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(EE,{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`,xE),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`,xE),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 Te;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Te=!p&&!V&&!H&&!U&&A?(0,$.jsx)($b,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,xE),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]=Te):Te=t[89];let Ee;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==le||t[95]!==ue||t[96]!==de||t[97]!==ge||t[98]!==ye||t[99]!==be||t[100]!==xe||t[101]!==Se||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:le,tabIndex:ue,"aria-disabled":de,children:[ge,ye,be,xe,Se,Ce,we,Te]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=le,t[95]=ue,t[96]=de,t[97]=ge,t[98]=ye,t[99]=be,t[100]=xe,t[101]=Se,t[102]=Ce,t[103]=we,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&HE(e.activities,t.activities)),WE=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)(Bw,{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}),GE=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)(gE,{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}),KE=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}=it(),_=ts()??``,v=Z.useMemo(()=>wE(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?vE(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(()=>RE(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=gr(_,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=ii(_,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=q(()=>{let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,n||P(),s()});Z.useEffect(()=>{T||!n||P(!1,!0)},[T,n]),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)},[n]);let L=m&&!n?Math.max(0,Math.floor(r)):0,R=!m||n||L>0,z=y.current,B=[...z].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 gr(_,n,e).status}),V=B.includes(`loading`),H=B.includes(`error`),U=B.length>0&&B.every(e=>e===`ready`),W=t.some(e=>z.has(e.messageId)&&CE(e)),ee=U&&!W&&!TE(t,z),G=Z.useMemo(()=>R?DE(e):SE,[e,R]),K=Z.useMemo(()=>R?VE(G):[],[R,G]),te=Z.useMemo(()=>n||L===0?0:Math.max(0,K.length-L),[n,L,K.length]),ne=Z.useMemo(()=>n||L===0?K:K.slice(-L),[n,L,K]);if(!m&&K.length===0)return null;let re=(e,t)=>{let n=(0,$.jsx)(`div`,{className:xp(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ie=R?ne.map((e,t)=>{switch(e.type){case`reasoning`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(WE,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(GE,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(zE,{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)(BE,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(lE,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(UE,{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)(hE,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(UE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(zE,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,ae=ne.length>0;return m?(0,$.jsxs)(`div`,{className:xp(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`,Sp,c&&`pr-0`),"data-mobile-press-feedback":`soft`,onClick:I,"aria-expanded":n,"aria-label":g(n?`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)(FS,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-[14px] w-[14px]`})}),(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)(Zi,{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,(0,$.jsx)(X,{name:n?`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`)})]})]}),ae?(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3`,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)`}}),te>0?(0,$.jsxs)(`button`,{type:`button`,onClick:I,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,te,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ie})]}):null,n&&(V||H||ee)?(0,$.jsx)(`div`,{className:Y(`typography-meta ml-5 flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,H&&`text-[var(--status-error)]`),role:H?`alert`:`status`,children:V?(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`)})]}):H?(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)(oa,{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:xp(c),children:ie})});function qE(e){return e.showToolFileIcons}function JE(e){return e.currentDirectory}function YE(e){return[e.name,e]}function XE(e){e.stopPropagation()}var ZE=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(KE,{...e}),t[0]=e,t[1]=n),n}),QE={contain:`layout`},$E={containerType:`inline-size`,containerName:`message-footer`},eD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,tD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,nD=`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`,rD=`size-3.5!`,iD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,aD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,oD=`flex items-center gap-2`,sD=`flex items-center gap-2 text-muted-foreground`,cD=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,lD=`size-3.5!`,uD=`medium`,dD=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,fD=`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)]`,pD=`h-7 gap-1.5`,mD=`h-6 gap-1`,hD=`text-[11px] leading-none`,gD=`size-3.5`,_D=`size-3`,vD=5,yD=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)(Tu,{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=dD(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}),bD=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=it(),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?mD:pD,d;t[3]===u?d=t[4]:(d=Y(fD,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)(yD,{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)(oa,{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}),xD=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=it(),l=ts(),u=Wm(),d=u.directory||l,f=u.sessionId,p=lh(),m=c(FD),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,vD),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]!==s?(S=s(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=s,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==s?(w=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=s,t[9]=w):w=t[9];let T=w,E=Y(fD,o?mD:pD),D=o?_D:gD,O;t[10]===o?O=t[11]:(O=o?Y(hD,`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(hD,`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(hD,`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){Uw({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&Uw({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&&Uw({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]===s?V=t[35]:(V=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=V);let H;t[36]===s?H=t[37]:(H=s(`diffView.actions.reviewAria`),t[36]=s,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]===s?ee=t[41]:(ee=s(`chat.changedFiles.title`),t[40]=s,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)(oa,{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)(bD,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(oa,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":s(`diffView.actions.reviewAria`),title:s(`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]})}),SD=e=>e.type===`subtask`,CD=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},wD=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}`},TD=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=ts(),{isMobile:o}=co(),s=J(ID),l=c(LD),u=Wm(),{t:f}=it(),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=wD(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(RD),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]!==s||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:()=>{a&&Km(u,S,a,()=>{if(!oi({sessionId:S,directory:a})){if(Ec()||o||d()){s(S,a);return}l(a,{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]=s,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},ED=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=ts(),i=c(zD),{isMobile:a}=co(),{t:o}=it(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let l=!!s,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)(ko,{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},DD={background:`transparent`,backgroundColor:`transparent`},OD=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}=it(),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 ot(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)(Ys,{language:`bash`,code:u,codeStyle:DD,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(BD),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)(Ys,{language:`bash`,code:d,codeStyle:DD,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},kD=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},AD=(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}},jD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,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}=it(),T=Eh(),E=Gm(Wm()),D=c(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Yw(e):!!(SD(e)||CD(e))),[n]),M=Z.useMemo(()=>j.map(e=>Xt(e)?bx(Jw(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(s??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=KT(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(oD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(cD,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:uD,name:`edit`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:uD,name:`close`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,ne=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(oD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(cD,`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(oD,`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)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(cD,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:uD,name:`time`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(Pa,{children:G})]}):null,h&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"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:uD,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(rD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:uD,name:`edit`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"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:uD,name:_===`fork`?`loader-4`:`git-branch`,className:Y(rD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:nD,"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:uD,name:`check`,className:Y(rD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:uD,name:`file-copy`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:QE,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(SD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(TD,{part:e})},e.id??`user-subtask-${i}`);if(CD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(OD,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ED,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Jw(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(Zb,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Zu,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),ne]}):(0,$.jsx)($.Fragment,{children:ne})}),MD=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=it(),s=Eh(),c=Wm(),l=Gm(c),{isPlaying:u,play:d,stop:f}=TT(),p=Zn(e=>e.showMessageTTSButtons),m=Zn(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)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(nD,!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:uD,name:`check`,className:Y(rD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:uD,name:`file-copy`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:uD,name:`target`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(nD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:uD,name:`loader-4`,className:Y(rD,`animate-spin`)}):(0,$.jsx)(X,{weight:uD,name:`arrow-left-right`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:Y(nD,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:uD,name:`stop`,className:rD}):(0,$.jsx)(X,{weight:uD,name:`volume-up`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:j})]})]})}),ND=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,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}=it(),A=Eh(),j=Gm(Wm()),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?aD:iD,B=!i,V=Z.useMemo(()=>n.filter(e=>!Yw(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(()=>An(U),[U]),ee=c(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=Yo(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=Yo(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=J(e=>e.forkFromMessage),re=J(e=>e.forkTransition),ie=J(e=>e.currentSessionId),ae=J(e=>e.getDirectoryForSession),oe=ts(),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 _t(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 Qr(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=c(e=>e.chatRenderMode),pe=c(e=>e.collapsibleThinkingBlocks),me=c(e=>e.showSplitAssistantMessageActions),he=c(e=>e.showAssistantTps),ge=c(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=>XS(e)),[H]),we=XS,Te=YS,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||!zn())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Nt(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Tt({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=tT(a,V),$e={finish:a,parts:V,streamPhase:xe,error:T,isLastAssistantInTurn:ve},et=aT($e),tt=_e&&oT($e),nt=_e&&!et&&!(qe&&Je),rt=!!T,at=E===`info`?`information`:`error-warning`,st=Be,ct=ve&&be&&!Ye&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&ve&&Qe&&be&&!Ye&&w?.diffStats?.hasDiffs===!0,dt=me&&st&&!ct&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(MD,{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=Jw(e.part).trim();return t?(0,$.jsx)(MD,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ot(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)(ZE,{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)(Ow,{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?tD:eD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:oD,"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(!Jw(i).trim()){r+=1;continue}C&&(pe?n.push((0,$.jsx)(`div`,{className:xp(u),children:(0,$.jsx)(Bw,{part:i,messageId:t,streamPhase:xe,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(Ow,{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(qS(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!qS(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)(lE,{activities:e,isMobile:u,isTurnLive:xe!==`completed`,hasFollowingOtherType:aE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(UE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(JS(a)){let e=uE(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)(hE,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(UE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(WS(a)){n.push((0,$.jsx)(`div`,{className:xp(u),children:(0,$.jsx)(cw,{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:xp(u),children:(0,$.jsx)(UE,{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]),vt=Z.useMemo(()=>{if(!ve||!be)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return kD(e)},[ve,be,w?.durationMs]),yt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=KT(e,ge);return t.length>0?t:null},[o,s,ge,k]),bt=Z.useMemo(()=>{if(!he||!ve||!be)return null;let e=r??n,t=AD(e,l),i=ZT({createdAt:s,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=QT(i);return a.length>0?a:null},[he,ve,be,n,r,l,s,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&te?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,variant:`ghost`,size:`icon`,className:nD,"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:uD,name:`global`,className:rD})})}),(0,$.jsx)(Pa,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!se&&j.fork?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsx)(oa,{type:`button`,size:`icon`,variant:`ghost`,className:nD,"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:uD,name:ue?`loader-4`:`git-branch`,className:Y(rD,ue&&`animate-spin`)})})}),(0,$.jsx)(Pa,{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:QE,children:[(0,$.jsx)(HT,{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)(cs,{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:uD,className:Y(rD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:at,weight:E===`info`?uD:void 0,className:Y(`shrink-0`,E===`info`?Y(rD,`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)(ko,{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)(xD,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(Zu,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?tD:eD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:oD,"data-message-action-group":`true`,children:ft})}),ct&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:$E,children:[(0,$.jsxs)(`div`,{className:oD,"data-message-action-group":`true`,children:[ft,xt]}),bt||vt||yt?(0,$.jsxs)(`div`,{className:sD,children:[bt?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cD,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:uD,name:`pulse`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(Pa,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,vt?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cD,children:[(0,$.jsx)(X,{weight:uD,name:`hourglass`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Pa,{children:vt})]}):null,yt?(0,$.jsxs)(Fa,{children:[(0,$.jsx)(Na,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cD,"aria-label":`Message time: ${yt}`,children:[(0,$.jsx)(X,{weight:uD,name:`time`,className:lD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Pa,{children:yt})]}):null]}):null,!K&&ve&&ye&&!lt?(0,$.jsx)(Ww,{activityParts:w?.activityParts}):null]})]})]})}),PD=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)(jD,{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)(ND,{...r}),t[26]=r,t[27]=i),i});function FD(e){return e.openContextPanelTab}function ID(e){return e.setCurrentSession}function LD(e){return e.openContextPanelTab}function RD(e){return!e}function zD(e){return e.openContextPanelTab}function BD(e){return!e}var VD=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}},HD=`Authentication failed for this provider. Please re-authenticate and retry.`,UD=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},WD=Mo(()=>Ve(()=>import(`./ToolOutputDialog-C1R-GCPB.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]))),GD=4e3,KD=new Map,qD=new Map,JD=new Set([`bash`,`shell`,`cmd`,`terminal`]),YD=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},XD=e=>{let t=KD.get(e);return t?new Set(t):new Set},ZD=(e,t)=>{if(KD.size>=GD&&!KD.has(e)){let e=KD.keys().next().value;typeof e==`string`&&KD.delete(e)}KD.set(e,new Set(t))},QD=e=>{let t=qD.get(e);return t?new Set(t):new Set},$D=(e,t)=>{if(qD.size>=GD&&!qD.has(e)){let e=qD.keys().next().value;typeof e==`string`&&qD.delete(e)}qD.set(e,new Set(t))},eO=200,tO=new Map,nO=e=>tO.get(e),rO=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=tO.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(tO.size>=eO&&!tO.has(e)){let e=tO.keys().next().value;typeof e==`string`&&tO.delete(e)}tO.set(e,t)}};function iO(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 aO=(e,t)=>{if(typeof e==`object`&&e)return e[t]},oO=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{isMobile:p,isTablet:m,hasTouchInput:h}=co(),g=Wm(),_=Gm(g),v=p||m,y=Z.useRef(null),b=J(e=>e.currentSessionId),x=It(e=>e.getAgentModelForSession),S=It(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);je(`ui.chat_message.render`),s&&je(`ui.chat_message.render.streaming`);let k=Zn(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=c(me(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Rb.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(()=>XD(e.info.id)),[U,W]=Z.useState(()=>QD(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(XD(e.info.id)),W(QD(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>VD(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}=Ip(me(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>qw(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>K?Ri(se,{planModeEnabled:ie}):qw(e.parts),[K,e.parts,ie,se]),le=Z.useMemo(()=>{if(K||!t)return null;let e=aO(t.info,`clientRole`),n=aO(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=aO(t.info,`mode`),i=aO(t.info,`agent`),a=aO(t.info,`providerID`),o=aO(t.info,`modelID`),s=aO(t.info,`variant`),c=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,l=typeof a==`string`&&a.trim().length>0?a:void 0,u=typeof o==`string`&&o.trim().length>0?o:void 0,d=typeof s==`string`&&s.trim().length>0?s:void 0;return!c&&!l&&!u&&!d?null:{agentName:c,providerId:l,modelId:u,variant:d}},[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=aO(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=aO(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:aO(e.info,`providerID`),pe=K?null:aO(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?nO(e.info.id):void 0;K||rO(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 Hn(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=iO(ye),Te=iO(be??void 0),Ee=iO(xe??void 0),De=iO(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,Me=De??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(()=>K?!0:!!(Ne&&Ne>0),[K,Ne]),Ie=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(()=>Xw(ce,{includeReasoning:A}),[ce,A]),ze=Z.useMemo(()=>K?Re:!Fe&&M===`sorted`?[]:Re,[M,Fe,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=YD(t.tool);!r||!JD.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=YD(t.part.tool);!n||!JD.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&&ze.length===0,Ke=typeof Ie!=`string`,qe=Z.useMemo(()=>K?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,K]),Je=Z.useMemo(()=>!K&&Rb.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?VD(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=a?.isWorking===!0||s,tt=Z.useMemo(()=>K?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,K,Ze]),nt=Z.useMemo(()=>Fe?`completed`:s?l??`streaming`:`completed`,[l,s,Fe]);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=>{ot(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),at=K?void 0:a?.userMessageVariant??le?.variant,st=!K&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,ct=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`}:UD(a)?{text:HD,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=ct?.text,ut=ct?.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
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
6579
  `):ze.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`