@openchambery/web 1.19.7-beta.5 → 1.19.7-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-ziUs4sw3.js → AgentAvatar-Di8F4QJh.js} +1 -1
- package/dist/assets/{AssistantView-neqbgNaR.js → AssistantView-AWe-3bXR.js} +1 -1
- package/dist/assets/{ChatContainer-BBKcNWyJ.js → ChatContainer-XHQSSICA.js} +35 -35
- package/dist/assets/{ContextPanel-C3LRnrhI.js → ContextPanel-BT6bgBJ_.js} +3 -3
- package/dist/assets/{DiagramView-BOuujgEg.js → DiagramView-DNLNZOT6.js} +1 -1
- package/dist/assets/{FadeInOnReveal-BAlsRFJH.js → FadeInOnReveal-CV2s6YN8.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cj2Tk6Lb.js → MarkdownRendererImpl-C6E0KL8H.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-BAy5LnnX.js → MobileDetailNavigation-Sg0VMlOz.js} +1 -1
- package/dist/assets/{MobileShareBridge-C03A2Qeb.js → MobileShareBridge-QTUpK3s7.js} +2 -2
- package/dist/assets/{MobileSurface-HlOBVawn.js → MobileSurface-BasV1X13.js} +1 -1
- package/dist/assets/{MultiRunWindow-0gmV5who.js → MultiRunWindow-BxyF4Xy4.js} +1 -1
- package/dist/assets/{OnboardingScreen-CJYyR54B.js → OnboardingScreen-D6rtE7rj.js} +1 -1
- package/dist/assets/{OverlayScrollbar-C-jZ8ITG.js → OverlayScrollbar-DlNZho3q.js} +1 -1
- package/dist/assets/{SettingsView-BaHbjZ-r.js → SettingsView-BywiwJ_a.js} +1 -1
- package/dist/assets/{SettingsWindow-BT-H9i50.js → SettingsWindow-zQ1dc-wl.js} +1 -1
- package/dist/assets/{TerminalView-v4YY-9kA.js → TerminalView-BMXYfo8d.js} +1 -1
- package/dist/assets/{ToolOutputDialog-1bp7aeoj.js → ToolOutputDialog-CFFkJzQ4.js} +1 -1
- package/dist/assets/{appThemeRegistry-ChC97xjW.js → appThemeRegistry-4oEk9SR8.js} +2 -2
- package/dist/assets/{clipboard-Bz0Zm9VJ.js → clipboard-D35XSwID.js} +1 -1
- package/dist/assets/{desktopRelayRestore-LBt0CBOj.js → desktopRelayRestore-8pvI_dSc.js} +1 -1
- package/dist/assets/{dialog-HCE4eLUW.js → dialog-x2hirWBd.js} +1 -1
- package/dist/assets/{es-D9KcV5TX.js → es-C8Sqjsia.js} +1 -1
- package/dist/assets/{fileQueries-Dnn15WsA.js → fileQueries-DGHZqZHc.js} +1 -1
- package/dist/assets/{fr-DPA9qUl3.js → fr-p-Zwm_j2.js} +1 -1
- package/dist/assets/{gitApi-BZQvlhsa.js → gitApi-Dqg8EDsg.js} +1 -1
- package/dist/assets/{insertionBoundaries-CLGkUXKc.js → insertionBoundaries-BtiZxiKR.js} +1 -1
- package/dist/assets/{ja-Dsif3NoD.js → ja-B6REu1qP.js} +1 -1
- package/dist/assets/{ko-Dixx4Ctg.js → ko-CJBNH9IZ.js} +1 -1
- package/dist/assets/{main-BtZPyHBH.js → main-Blsi9j8P.js} +2 -2
- package/dist/assets/{main-W1UkNfir.js → main-D4qq97ip.js} +3 -3
- package/dist/assets/{markdownTheme-TdhQOZSN.js → markdownTheme-SPe4jOwX.js} +1 -1
- package/dist/assets/{miniChat-Dqm16yyZ.js → miniChat-QgI11lL4.js} +2 -2
- package/dist/assets/{mobile-CzSQKW-r.js → mobile-BjMMtvjD.js} +2 -2
- package/dist/assets/{multirun-cDeDA8WZ.js → multirun-C9CKfXyS.js} +1 -1
- package/dist/assets/{persistence-CmjKImz2.js → persistence-w-AiX2i4.js} +1 -1
- package/dist/assets/{pl-Bj78ZGgf.js → pl-B2cBI_7K.js} +1 -1
- package/dist/assets/{platform-skqcMARt.js → platform-4eCmsdol.js} +1 -1
- package/dist/assets/{projectMeta-DJa04ZTk.js → projectMeta-DzGPV_uF.js} +1 -1
- package/dist/assets/{pt-BR-CFL3xSAf.js → pt-BR-CrCc9hmt.js} +1 -1
- package/dist/assets/{radio-CTAfZqAa.js → radio-TX0aocEX.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-CR-zSyTR.js → renderElectronMiniChatApp-DZOBP2No.js} +2 -2
- package/dist/assets/{renderMobileApp-InxP28OZ.js → renderMobileApp-DP1_xIqJ.js} +10 -7
- package/dist/assets/{runtimeConfig-Fsa7BZKx.js → runtimeConfig-ClsErHd9.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-Bp-Y9GZS.js → runtimeEndpointReset-DoLMDfAs.js} +1 -1
- package/dist/assets/{shikiHighlight-kzkGYjXV.js → shikiHighlight-B25fE64n.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-Bj8N0VWf.js → sortable-tabs-strip-CNDgyX0B.js} +1 -1
- package/dist/assets/{store-DzpbXWX1.js → store-CL3WP48T.js} +2 -2
- package/dist/assets/{terminalApi-CNqqwjfG.js → terminalApi-CGtOtc8I.js} +1 -1
- package/dist/assets/{uk-BY60Ub3Z.js → uk-C8YKAz0x.js} +1 -1
- package/dist/assets/{useAppFontEffects-KatUA88o.js → useAppFontEffects-D1u63a6o.js} +2 -2
- package/dist/assets/{useAssistantUIStore-DaplPyb0.js → useAssistantUIStore-I0VWrB5V.js} +1 -1
- package/dist/assets/{useDesktopWindowControlsLayout-B3Vz7zfM.js → useDesktopWindowControlsLayout-DW_ouBDs.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-CoY7Yf8Y.js → useEffectiveDirectory-D976zCCc.js} +1 -1
- package/dist/assets/{useFontPreferences-D8emhcNv.js → useFontPreferences-BLZ3y6mN.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-90zAmNRR.js → useMobileNavigationStore-lcj5GHR3.js} +4 -4
- package/dist/assets/{useSessionAutoCleanup-B2UfFrMn.js → useSessionAutoCleanup-DMNa_krc.js} +1 -1
- package/dist/assets/useUIStore-CNLmCoPU.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-Cf50wR0y.js → useWorkerHighlightedLines-BQNOf2U4.js} +1 -1
- package/dist/assets/{zh-CN-Cox1LaOW.js → zh-CN-CCYwUnmB.js} +1 -1
- package/dist/assets/{zh-TW-B6RU0mxa.js → zh-TW-D8Y6py08.js} +1 -1
- package/dist/index.html +7 -7
- package/dist/mini-chat.html +7 -7
- package/dist/mobile.html +7 -7
- package/package.json +1 -1
- package/server/lib/notifications/APNS.md +4 -4
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/apns-runtime.js +139 -20
- package/server/lib/notifications/apns-runtime.test.js +66 -7
- package/server/lib/notifications/apns-titles.js +62 -62
- package/server/lib/notifications/apns-titles.test.js +3 -1
- package/server/lib/notifications/routes.js +1 -1
- package/server/lib/notifications/runtime.js +25 -49
- package/server/lib/opencode/settings-runtime.js +16 -0
- package/dist/assets/useUIStore-B7KJS5G7.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n as i,r as a,x as o}from"./runtime-switch-BkpTTbEi.js";import{$ as s,B as c,C as l,Ct as u,Dt as d,G as f,I as p,It as m,J as h,K as g,M as _,N as v,Q as y,R as b,S as x,T as S,U as C,V as w,W as T,Y as E,Z as D,_ as O,at as k,b as A,ct as j,d as M,et as N,ft as P,it as F,j as I,lt as L,mt as R,nt as z,ot as B,pt as V,q as H,r as U,st as W,u as ee,ut as G,v as K,wt as te,x as ne,y as re,yt as ie,z as ae}from"./persistence-CmjKImz2.js";import{u as oe,y as se}from"./desktop-CfLlmafK.js";import{a as ce,i as le,r as ue,t as de}from"./vendor-zustand-B4dlGEM2.js";import{c as fe,d as pe,f as me,l as he,nt as ge,rt as _e,tt as ve,u as ye}from"./vendor-base-ui-CnHfUmDN.js";import{At as be,Bt as xe,Ct as Se,Gt as Ce,Ht as we,Jt as Te,Kt as Ee,Nt as De,Pt as Oe,Rt as ke,St as Ae,Ut as je,Wt as Me,Yt as Ne,jt as Pe,kt as Fe,n as Ie,t as Le,zt as Re}from"./platform-skqcMARt.js";import{g as ze,t as q,y as Be}from"./useUIStore-B7KJS5G7.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{i as $e,u as et}from"./vendor-pierre-diffs-DX7XTPG3.js";import{a as tt,d as nt,i as rt,l as it,n as J,o as at,r as ot,u as st}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ct,r as lt,t as ut}from"./clipboard-Bz0Zm9VJ.js";import{i as dt,t as ft}from"./store-DzpbXWX1.js";import{$ as pt,$a as mt,$n as ht,$r as gt,$t as _t,A as vt,Ai as yt,At as bt,Ba as xt,Bi as St,Bn as Ct,Ci as wt,Cn as Tt,Cr as Et,Ct as Dt,D as Ot,Da as kt,Dn as At,Dr as jt,E as Mt,Ei as Nt,En as Pt,F as Ft,Fa as It,Fi as Lt,Fr as Rt,G as zt,Ga as Bt,Gt as Vt,H as Ht,Ha as Ut,Hi as Wt,Hr as Gt,I as Kt,Ii as qt,In as Jt,Ir as Yt,It as Xt,J as Zt,Ja as Qt,K as $t,Ka as en,Kt as tn,Li as nn,Ln as rn,Lr as an,Lt as on,M as sn,Mi as cn,Mo as ln,Mt as un,N as dn,Ni as fn,Nr as pn,Nt as mn,O as hn,Oa as gn,On as _n,Or as vn,Ot as yn,P as bn,Pi as xn,Q as Sn,Qi as Cn,Qn as wn,Qr as Tn,Qt as En,R as Dn,Ri as On,Rn as kn,Rr as An,Rt as jn,S as Mn,Sa as Nn,Si as Pn,Sn as Fn,Sr as In,T as Ln,Ti as Rn,Tn as zn,Ua as Bn,Ui as Vn,Ut as Hn,Va as Un,Vi as Wn,Vr as Gn,W as Kn,Wa as qn,Wr as Jn,Wt as Yn,X as Xn,Xr as Zn,Xt as Qn,Y as $n,Yr as er,Z as tr,Zi as nr,Zn as rr,Zr as ir,Zt as ar,_i as or,_n as sr,_t as cr,a as lr,aa as ur,ai as dr,an as fr,at as pr,ba as mr,bi as hr,bo as gr,bt as _r,ci as vr,cn as yr,da as br,di as xr,dn as Sr,dt as Cr,ea as wr,eo as Tr,er as Er,et as Dr,f as Or,fa as kr,fi as Ar,fn as jr,fr as Mr,g as Nr,ga as Pr,gi as Fr,gn as Ir,gt as Lr,ha as Rr,hn as zr,hr as Br,ht as Vr,i as Hr,in as Ur,it as Wr,j as Gr,ja as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kn as $r,ko as ei,kr as ti,kt as ni,l as ri,la as ii,ln as ai,m as oi,ma as si,mi as ci,mn as li,mt as ui,n as di,na as fi,ni as pi,nn as mi,nt as hi,oi as gi,pa as _i,pi as vi,pn as yi,pt as bi,q as xi,qa as Si,qi as Ci,qt as wi,rn as Ti,ro as Ei,rt as Di,si as Oi,sn as ki,ta as Ai,ti as ji,tn as Mi,tt as Ni,ui as Pi,un as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wa as Bi,wi as Vi,wr as Hi,wt as Ui,x as Wi,xi as Gi,xr as Ki,ya as qi,yi as Ji,yo as Yi,z as Xi,za as Zi,zi as Qi,zr as $i}from"./useMobileNavigationStore-90zAmNRR.js";import{a as ea,i as ta,l as na,n as ra,o as ia,r as aa,s as oa,t as sa}from"./dialog-HCE4eLUW.js";import{n as ca,t as Y}from"./utils-CTL16t2f.js";import{t as la}from"./AgentAvatar-ziUs4sw3.js";import{n as X}from"./Icon-CLpn1mIz.js";import{t as ua}from"./button-z0GOBtWi.js";import{E as da,n as fa}from"./gitApi-BZQvlhsa.js";import{A as pa,C as ma,G as ha,K as ga,M as _a,O as va,Q as ya,S as ba,T as xa,X as Sa,Z as Ca,a as wa,b as Ta,d as Ea,et as Da,g as Oa,h as ka,i as Aa,j as ja,k as Ma,n as Na,o as Pa,p as Fa,s as Ia,u as La,v as Ra,w as za,x as Ba}from"./projectMeta-DJa04ZTk.js";import{t as Va}from"./input-BG3VWTIF.js";import{i as Ha,n as Ua,t as Wa}from"./tooltip-CtH61mQh.js";import{n as Ga,t as Ka}from"./useThemeSystem-DMzWVJaW.js";import{A as qa,B as Ja,C as Ya,K as Xa,M as Za,P as Qa,_ as $a,a as eo,f as to,g as no,h as ro,i as io,m as ao,o as oo,p as so,r as co,t as lo,v as uo,w as fo,y as po}from"./radio-CTAfZqAa.js";import{i as mo,t as ho}from"./OverlayScrollbar-C-jZ8ITG.js";import{_ as go,a as _o,d as vo,f as yo,g as bo,h as xo,i as So,l as Co,m as wo,n as To,u as Eo,v as Do,x as Oo}from"./markdownTheme-TdhQOZSN.js";import{n as ko,r as Ao,t as jo}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Mo,B as No,C as Po,D as Fo,E as Io,F as Lo,H as Ro,I as zo,L as Bo,M as Vo,N as Ho,O as Uo,R as Wo,S as Go,T as Ko,U as qo,V as Jo,a as Yo,b as Xo,c as Zo,f as Qo,i as $o,j as es,k as ts,l as ns,m as rs,n as is,o as as,p as os,r as ss,s as cs,t as ls,u as us,w as ds,x as fs,z as ps}from"./insertionBoundaries-CLGkUXKc.js";import{A as ms,C as hs,D as gs,E as _s,F as vs,M as ys,N as bs,O as xs,P as Ss,R as Cs,S as ws,T as Ts,_ as Es,a as Ds,b as Os,d as ks,f as As,g as js,h as Ms,i as Ns,j as Ps,k as Fs,l as Is,m as Ls,p as Rs,r as zs,s as Bs,t as Vs,v as Hs,w as Us,x as Ws,y as Gs}from"./appThemeRegistry-ChC97xjW.js";import{_ as Ks,a as qs,c as Js,g as Ys,l as Xs,o as Zs,t as Qs,v as $s,y as ec}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as tc,n as nc,o as rc,s as ic,t as ac}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as oc,n as sc,t as cc}from"./url-KeihbE0d.js";import{d as lc,h as uc,o as dc,u as fc}from"./markdown-worker-y3ewaqAK.js";import{n as pc}from"./useEffectiveDirectory-CoY7Yf8Y.js";import{a as mc,c as hc,d as gc,f as _c,i as vc,l as yc,n as bc,r as xc,s as Sc,t as Cc}from"./FadeInOnReveal-BAlsRFJH.js";import{A as wc,C as Tc,D as Ec,E as Dc,M as Oc,O as kc,S as Ac,T as jc,a as Mc,b as Nc,c as Pc,g as Fc,h as Ic,i as Lc,j as Rc,k as zc,o as Bc,p as Vc,r as Hc,s as Uc,t as Wc,v as Gc,w as Kc,x as qc,y as Jc}from"./useWorkerHighlightedLines-Cf50wR0y.js";import{t as Yc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Xc}from"./sortable-tabs-strip-Bj8N0VWf.js";import{n as Zc,t as Qc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as $c}from"./markdownHeightCache-CvUyZT4q.js";import{i as el,t as tl}from"./vendor-framer-motion-DFy_BSVd.js";import{t as nl}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(_e(),1),Q=We(),$=ge(),rl=e(ve(),1),il=`openchamber:close-embedded-session-chat`,al=`openchamber:embedded-visibility`,ol=`openchamber:embedded-visibility-request`,sl=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,cl=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),ll=(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()},ul=(e,t,n,r,i,a)=>{let o=cl(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=ll(n,r,i,a);return e.set(t,{signature:o,src:c}),c},dl=null,fl=()=>{if(dl!==null)return dl;if(typeof window>`u`)return dl=!1,!1;try{return dl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,dl}catch{return dl=!1,!1}},pl=()=>{if(!fl())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},ml=Ve(`OpenChamberMedia`);function hl(){return Ie()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function gl(e){if(!hl())return null;let t=await ml.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(He.convertFileSrc(e.path));if(!t.ok)throw Error(`Native media fetch failed (${t.status})`);let r=await t.blob();n.push(new File([r],e.name,{type:e.mimeType}))}return n}var _l=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=bi([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>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),r.map(e=>e.item)},vl=new Map,yl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,bl=async e=>{let t=ys(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=vl.get(n);return r===void 0&&(r=await qo(e.iconName,t)??``,vl.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},xl=[],Sl=e=>void 0,Cl=()=>void 0;function wl(e){let t=Cs()&&e.enabled&&Gs(e.isMobile),n=(0,Z.useRef)(null),r=(0,Z.useRef)(e.text),i=(0,Z.useRef)(!1),a=(0,Z.useRef)(-1),o=(0,Z.useRef)(null),s=(0,Z.useRef)(``),c=(0,Z.useRef)([]),l=(0,Z.useRef)(Os()),u=J(e.onText),d=J(e.onSend),f=J(e.onAbort),p=J(e.onAttach),m=J(e.onFiles),h=J(e.onRemoveAttachment),g=J(e.onOpenModel),_=J(e.onCycleAgent),v=J(e.onOpenAgent),y=J(e.onScrollToBottom),b=J(e.onAutocompleteAccept??Sl),x=J(e.onAutocompleteDismiss??Cl),S=J(e=>{typeof document>`u`||Ms(document.documentElement,e)});Rs.bind({onText:(e,t,n)=>{vs({incoming:e,replacedText:o.current})||(o.current=null,r.current=e,i.current=!0,u(e,t,n))},onSend:e=>{r.current=e,d(e)},onAbort:f,onAttach:p,onFiles:m,onRemoveAttachment:h,onOpenModel:g,onCycleAgent:_,onOpenAgent:v,onHeight:S,onScrollToBottom:y,onAutocompleteAccept:e=>{i.current=!1,b(e)},onAutocompleteDismiss:x});let C=()=>({text:e.text,placeholder:e.placeholder,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel,modelIcon:s.current,canSend:e.canSend,canAbort:e.canAbort,attachmentCount:e.attachmentCount,attachmentPreviews:c.current,citationRanges:Te(e.text,e.attachments.map(e=>e.filename)),chipRanges:Es(Us(e.text,e.chipHighlights),ys(`--primary`)),appearance:typeof document>`u`?`dark`:gs(document.documentElement),attachAria:e.attachAria,attachTitle:e.attachTitle,attachPhotosLabel:e.attachPhotosLabel,attachFilesLabel:e.attachFilesLabel,attachCancelLabel:e.attachCancelLabel,sendAria:e.sendAria,queueAria:e.queueAria,stopAria:e.stopAria,modelAria:e.modelAria,agentAria:e.agentAria,agentLabel:e.agentLabel,agentColor:_s(e.agentName||void 0),agentIdenticon:xs(e.agentName||void 0),suppressed:e.suppressed,showScrollToBottom:e.showScrollToBottom,scrollAria:e.scrollAria,autocomplete:l.current});(0,Z.useLayoutEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement;return Ss(e,!0),()=>{Ss(e,!1)}},[t]),(0,Z.useEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement,i=C();n.current=i,r.current=i.text,Rs.rememberText(i.text),Rs.retain(e,i);let a=As();return()=>{n.current=null,a(),Rs.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=Ca(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Ws().update(a),i)return ms(i).then(t=>{if(r)return;let i=t??``;s.current=i;let a={modelIcon:i,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};n.current&&={...n.current,...a},Ws().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let w=js(e.attachments);(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e.attachments;if(i.length===0){c.current=[],n.current&&(n.current={...n.current,attachmentPreviews:[]},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await Fs(t.dataUrl):``;return{id:t.id,filename:t.filename,mime:t.mimeType,thumbnailBase64:n??``,removeAria:e.removeAttachmentNamedAria(t.filename)}})).then(e=>{r||(c.current=e,n.current&&(n.current={...n.current,attachmentPreviews:e},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,w]);let T=e.autocompleteRows??xl,E=e.autocompleteOpen===!0,D=e.autocompleteHighlightedIndex??0,O=yl(T,E,D);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(E&&T.length>0)){let e=Os();hs(l.current,e)||(l.current=e,n.current&&(n.current={...n.current,autocomplete:e},Rs.rememberState(n.current)),Ws().update({autocomplete:e}));return}return bl(T).then(t=>{if(e)return;let r={open:t.length>0,highlightedIndex:Math.max(0,Math.min(D,Math.max(t.length-1,0))),rows:t};hs(l.current,r)||(l.current=r,n.current&&(n.current={...n.current,autocomplete:r},Rs.rememberState(n.current)),Ws().update({autocomplete:r}))}),()=>{e=!0}},[t,O]);let k=t?Us(e.text,e.chipHighlights).map(e=>`${e.start}:${e.end}:${e.triggerLength}`).join(`|`):``;return(0,Z.useEffect)(()=>{if(!t)return;let s=C(),c=n.current;if(c&&Ts(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,Rs.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=bs({nextText:s.text,nativeOwnedText:r.current,echoingNative:i.current,preset:l});i.current=!1,!u.omitText&&u.forceText&&(o.current=r.current),u.omitText||(r.current=s.text);let d=Hs(c,s,u,{caret:e.caret});d&&Ws().update(d)},[t,e.text,e.textPresetEpoch,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,w,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,k]),t}var Tl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},El=1e4,Dl=15e3,Ol=3e4,kl=3e4,Al=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 o()}catch{}this.connectPromise=new Promise((e,t)=>{let r=!1,i;try{let e=n().websocket(`/api/dictation/ws`);i=Ae(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!r){r=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},El);i.onopen=()=>{},i.onmessage=t=>{let n;try{n=JSON.parse(String(t.data))}catch{return}if(!r&&n.type===`ready`){r=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(n)},i.onerror=()=>{window.setTimeout(()=>{r||(r=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!r){r=!0,clearTimeout(a),this.connectPromise=null;let n=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${n}`));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`))},Dl);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`))},kl),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=Tl(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)}}},Ol))}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`,()=>{Al.cancelAllForRuntimeSwitch()});var jl=128,Ml=`audio/pcm;rate=16000;bits=16`,Nl=()=>new Promise(e=>setTimeout(e,0)),Pl=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Fl=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??Ml,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Pl}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<jl;){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 Nl()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Il=16e3,Ll=Il,Rl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},zl=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Bl=(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]=zl(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]=zl(e[i]*(1-s)+e[o]*s)}return a},Vl=(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},Hl=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)},Ul=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Wl=e=>{if(e)try{e.disconnect()}catch{}},Gl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Rl()!==null;function Kl(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=Ul(),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=Rl();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(Yl);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=Bl(a,n.sampleRate,Il);for(t.pending=Vl(t.pending,c);t.pending.length>=Ll;){let e=t.pending.slice(0,Ll);t.pending=t.pending.slice(Ll),i.current(Hl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Jl);try{await n.close()}catch{}throw l.current=Ul(),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{}Wl(e.processor),Wl(e.source),Wl(e.gain),e.stream&&e.stream.getTracks().forEach(ql);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Hl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Ul())},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 ql(e){try{e.stop()}catch{}}function Jl(e){try{e.stop()}catch{}}function Yl(){}var Xl=1e3,Zl=e=>e instanceof Error?e:Error(String(e)),Ql=()=>{let e=Ai.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 $l(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 Fl({client:Al,getStartOptions:Ql});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},Xl)},[]),C=(0,Z.useCallback)(e=>{let t=Zl(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)(()=>Al.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Al.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Kl({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 eu=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},tu=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ga(),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},nu=e=>{let t=Ai(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 m(`/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},ru=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:c,onInsert:l,onInsertAndSend:u,onActiveChange:d,onContentHeightChange:f,renderTrigger:p,topAccessory:m}=e,h=p===void 0||p,{t:g}=ct(),{currentTheme:_}=Ga(),v=Ai(iu),y=q(au),b;t[0]===y?b=t[1]:(b=Za(Qa(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(ou),C=Z.useRef(null),w=Z.useRef(l),T=Z.useRef(u),E,D;t[2]!==l||t[3]!==u?(E=()=>{w.current=l,T.current=u},D=[l,u],t[2]=l,t[3]=u,t[4]=E,t[5]=D):(E=t[4],D=t[5]),Z.useEffect(E,D);let O;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(O={onTranscript:e=>{let t=C.current;C.current=null,t===`send`?T.current(e):w.current(e)}},t[6]=O):O=t[6];let{status:k,partialTranscript:A,volume:j,duration:M,error:N,errorReason:P,startDictation:F,confirmDictation:I,cancelDictation:L,retryFailedDictation:R,acceptPartialTranscript:z,discardFailedDictation:B}=$l(O),V=k===`recording`&&P===`model_download_in_progress`,H=nu(V),U=Z.useRef(k),W,ee;t[7]===k?(W=t[8],ee=t[9]):(W=()=>{U.current=k},ee=[k],t[7]=k,t[8]=W,t[9]=ee),Z.useEffect(W,ee);let G,K;t[10]!==d||t[11]!==k?(G=()=>{d?.(k!==`idle`)},K=[k,d],t[10]=d,t[11]=k,t[12]=G,t[13]=K):(G=t[12],K=t[13]),Z.useLayoutEffect(G,K);let te,ne;t[14]!==I||t[15]!==F?(te=()=>{let e=()=>{U.current===`idle`?F():U.current===`recording`&&(C.current=`insert`,I())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[F,I],t[14]=I,t[15]=F,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==L||t[19]!==I||t[20]!==k?(re=()=>{if(k!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),C.current=`insert`,I();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),L())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[k,I,L],t[18]=L,t[19]=I,t[20]=k,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Z.useEffect(re,ie);let ae=Z.useRef(null),oe=Z.useRef(null),se=Z.useRef(null),[ce,le]=Z.useState(null),ue=k!==`idle`,de=Z.useRef(f),fe,pe;t[23]===f?(fe=t[24],pe=t[25]):(fe=()=>{de.current=f},pe=[f],t[23]=f,t[24]=fe,t[25]=pe),Z.useEffect(fe,pe);let me=Z.useRef(!1),he;t[26]===ue?he=t[27]:(he=()=>{if(!ue){me.current&&(me.current=!1,de.current?.(null));return}let e=oe.current,t=se.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);me.current=!0,de.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=ue,t[27]=he);let ge;t[28]!==N||t[29]!==ue||t[30]!==A||t[31]!==k?(ge=[ue,A,k,N],t[28]=N,t[29]=ue,t[30]=A,t[31]=k,t[32]=ge):ge=t[32],Z.useLayoutEffect(he,ge);let _e,ve;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>()=>{me.current&&(me.current=!1,de.current?.(null))},ve=[],t[33]=_e,t[34]=ve):(_e=t[33],ve=t[34]),Z.useEffect(_e,ve);let ye,be;if(t[35]===ue?(ye=t[36],be=t[37]):(ye=()=>{if(!ue)return;let e=ae.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&le(e.offsetHeight)},be=[ue],t[35]=ue,t[36]=ye,t[37]=be),Z.useLayoutEffect(ye,be),!S||!v)return null;let xe=k!==`idle`,Se;t[38]===I?Se=t[39]:(Se=e=>{C.current=e,I()},t[38]=I,t[39]=Se);let Ce=Se,we;t[40]===R?we=t[41]:(we=()=>{C.current=`insert`,R()},t[40]=R,t[41]=we);let Te=we,Ee;bb0:{if(k===`failed`){Ee=``;break bb0}if(k===`uploading`){let e;t[42]===g?e=t[43]:(e=g(`chat.dictation.processing`),t[42]=g,t[43]=e),Ee=e;break bb0}if(V){let e;t[44]!==H||t[45]!==g?(e=H===null?g(`chat.dictation.downloadingModel`):g(`chat.dictation.downloadingModelProgress`,{percent:String(H)}),t[44]=H,t[45]=g,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===g?e=t[48]:(e=g(`chat.dictation.listening`),t[47]=g,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:su,onPointerDownCapture:cu},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==x||t[51]!==c||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==h||t[56]!==F||t[57]!==g?(Ae=h?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{F()},disabled:c||xe,title:x?`${g(`chat.dictation.start`)} (${x})`:g(`chat.dictation.start`),"aria-label":g(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=x,t[51]=c,t[52]=i,t[53]=o,t[54]=xe,t[55]=h,t[56]=F,t[57]=g,t[58]=Ae):Ae=t[58];let je;t[59]!==z||t[60]!==L||t[61]!==Ce||t[62]!==_||t[63]!==B||t[64]!==M||t[65]!==N||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==V||t[73]!==A||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==s||t[78]!==k||t[79]!==g||t[80]!==m||t[81]!==j?(je=xe?(0,$.jsxs)(`div`,{ref:ae,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:_.colors.surface.subtle},role:`dialog`,"aria-label":g(`chat.dictation.overlayAria`),children:[m,(0,$.jsx)(`div`,{ref:oe,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:se,className:Y(!A&&`translate-y-1.5`),children:[A?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:_.colors.surface.foreground},children:A}):k===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:_.colors.surface.mutedForeground},children:[(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:_.colors.surface.mutedForeground},children:De}),k===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.error},children:N||g(`chat.dictation.failed`)}):null,k===`recording`&&N&&!V?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.warning},children:N}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:_.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:_.colors.status.error}})]}),(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:eu(M)})]}):k===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:_.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-primary hover:text-primary`),onClick:()=>Ce(`send`),title:g(`chat.dictation.insertAndSend`),"aria-label":g(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:s})})]}):k===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:B,title:g(`chat.dictation.discard`),"aria-label":g(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:g(`chat.dictation.retry`),"aria-label":g(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),A.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{C.current=`insert`,z()},title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=z,t[60]=L,t[61]=Ce,t[62]=_,t[63]=B,t[64]=M,t[65]=N,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=V,t[73]=A,t[74]=De,t[75]=n,t[76]=Te,t[77]=s,t[78]=k,t[79]=g,t[80]=m,t[81]=j,t[82]=je):je=t[82];let Me;return t[83]!==Ae||t[84]!==je?(Me=(0,$.jsxs)($.Fragment,{children:[Ae,je]}),t[83]=Ae,t[84]=je,t[85]=Me):Me=t[85],Me};function iu(e){return e.dictationEnabled}function au(e){return e.shortcutOverrides}function ou(){return!se()&&Gl()}function su(e){return e.preventDefault()}function cu(e){e.pointerType===`touch`&&e.preventDefault()}var lu=2e3,uu=ce((e,t)=>({pending:!1,expiresAt:null,arm:(t=lu)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),du=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}},fu=15e3,pu=100,mu=new Map,hu=new Map,gu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,_u=e=>{let t=gu(e),n=e.now??Date.now(),r=hu.get(t);if(r&&n-r.loadedAt<fu)return Promise.resolve(r.sessions);let i=mu.get(t);if(i)return i;let a=e.request().then(e=>{for(hu.delete(t);hu.size>=pu;){let e=hu.keys().next().value;if(typeof e!=`string`)break;hu.delete(e)}return hu.set(t,{loadedAt:Date.now(),sessions:e}),e});return mu.set(t,a),a.then(()=>{mu.get(t)===a&&mu.delete(t)},()=>{mu.get(t)===a&&mu.delete(t)}),a},vu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),yu=(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(vu)},bu=30;function xu(e){return e===`busy`||e===`retry`}var Su=new Map;function Cu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function wu(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 Tu(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${wu(e.error)}`)}function Eu(e,t){let n=Pr();if(!n)return!1;let r=n.getTranscript(Bi(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>qr()}function Du(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Ou(e,t,n){let r=[...e.getState().session],i=Zr.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function ku(){let e=Ir(),t=Vt(),n=Hn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=Pr();if(!r||!t)return Cu({kind:`unknown`,loadedTurns:0},!1);let i=Bi(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Cu(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let r=n.getChild(e);if(!r)return;let i=r.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_error_at:{...i.session_error_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};At(a,t),Xt(r,t),r.setState(a);for(let n of t)qi(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=Su.get(t);if(n)return Su.delete(t),Su.set(t,n),n;let r=new Set;for(Su.set(t,r);Su.size>bu;){let e=Su.keys().next().value;if(!e)break;let t=[...Su.get(e)??[]];Su.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=_n(a.getState()),u=Qr(),d=$r({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),yt()){let e=new Set([r,...c,...l]),t=(Pr()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),n=(t.length>0?t:Array.from(c)).filter(t=>t===r||e.has(t)?!1:Eu(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await si(a,r):await _i(a,r)}catch{return}if(i?.isStale?.())return;let u=Pr()?.getTranscript(Bi(a,r));ir({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await pi({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),u=(0,Z.useCallback)(async(t,i)=>{await ln();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=De.getScopedSdkClient(o);c(t,o);let d=r(t,o);return du.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Pr(),i=Bi(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Zr.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&fn(o,t)){ir({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Du({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Cn(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Tu(e,`session.get`),e});if(n.data&&!e()){let r=nr(n.data);e()||Ou(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let i=r||e;if(!t||!i)return;let o=n.ensureChild(i,{bootstrap:!1}),s=De.getScopedSdkClient(i),c=await _u({runtimeKey:a(),directory:i,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:i});return Tu(e,`session.children`),e.data??[]}});o.setState(e=>{let n=yu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=i(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,i]),p=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).loading,[e,i]),m=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).complete,[e,i]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await ln();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(xu(o))throw Error(`refresh transcript busy`);try{await mr(i,t),ir({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Au=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,ju=e=>e===`original`||e===`modified`,Mu=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Nu=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Au(t.source))return null;let n=Mu(t.startLine),r=Mu(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:ju(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()}},Pu=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(Nu).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Fu=ce()(ue(le((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:Be(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Pu(e.drafts)}}),{name:`inline-comment-draft-store`}));function Iu(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 Lu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Iu).join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-CFFkJzQ4.js","assets/rolldown-runtime-C0FnF6B9.js","assets/persistence-w-AiX2i4.js","assets/runtime-switch-BkpTTbEi.js","assets/desktop-CfLlmafK.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/useUIStore-CNLmCoPU.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-pierre-diffs-DX7XTPG3.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.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/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-D35XSwID.js","assets/store-CL3WP48T.js","assets/dialog-x2hirWBd.js","assets/utils-CTL16t2f.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-CLpn1mIz.js","assets/button-z0GOBtWi.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-SPe4jOwX.js","assets/appThemeRegistry-4oEk9SR8.js","assets/platform-4eCmsdol.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-lcj5GHR3.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-I0VWrB5V.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-y3ewaqAK.js","assets/markdownHeightCache-CvUyZT4q.js","assets/useEffectiveDirectory-D976zCCc.js","assets/useWorkerHighlightedLines-BQNOf2U4.js","assets/tooltip-CtH61mQh.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n as i,r as a,x as o}from"./runtime-switch-BkpTTbEi.js";import{$ as s,B as c,C as l,Ct as u,Dt as d,G as f,I as p,It as m,J as h,K as g,M as _,N as v,Q as y,R as b,S as x,T as S,U as C,V as w,W as T,Y as E,Z as D,_ as O,at as k,b as A,ct as j,d as M,et as N,ft as P,it as F,j as I,lt as L,mt as R,nt as z,ot as B,pt as V,q as H,r as U,st as W,u as ee,ut as G,v as K,wt as te,x as ne,y as re,yt as ie,z as ae}from"./persistence-w-AiX2i4.js";import{u as oe,y as se}from"./desktop-CfLlmafK.js";import{a as ce,i as le,r as ue,t as de}from"./vendor-zustand-B4dlGEM2.js";import{c as fe,d as pe,f as me,l as he,nt as ge,rt as _e,tt as ve,u as ye}from"./vendor-base-ui-CnHfUmDN.js";import{At as be,Bt as xe,Ct as Se,Gt as Ce,Ht as we,Jt as Te,Kt as Ee,Nt as De,Pt as Oe,Rt as ke,St as Ae,Ut as je,Wt as Me,Yt as Ne,jt as Pe,kt as Fe,n as Ie,t as Le,zt as Re}from"./platform-4eCmsdol.js";import{g as ze,t as q,y as Be}from"./useUIStore-CNLmCoPU.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{i as $e,u as et}from"./vendor-pierre-diffs-DX7XTPG3.js";import{a as tt,d as nt,i as rt,l as it,n as J,o as at,r as ot,u as st}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ct,r as lt,t as ut}from"./clipboard-D35XSwID.js";import{i as dt,t as ft}from"./store-CL3WP48T.js";import{$ as pt,$a as mt,$n as ht,$r as gt,$t as _t,A as vt,Ai as yt,At as bt,Ba as xt,Bi as St,Bn as Ct,Ci as wt,Cn as Tt,Cr as Et,Ct as Dt,D as Ot,Da as kt,Dn as At,Dr as jt,E as Mt,Ei as Nt,En as Pt,F as Ft,Fa as It,Fi as Lt,Fr as Rt,G as zt,Ga as Bt,Gt as Vt,H as Ht,Ha as Ut,Hi as Wt,Hr as Gt,I as Kt,Ii as qt,In as Jt,Ir as Yt,It as Xt,J as Zt,Ja as Qt,K as $t,Ka as en,Kt as tn,Li as nn,Ln as rn,Lr as an,Lt as on,M as sn,Mi as cn,Mo as ln,Mt as un,N as dn,Ni as fn,Nr as pn,Nt as mn,O as hn,Oa as gn,On as _n,Or as vn,Ot as yn,P as bn,Pi as xn,Q as Sn,Qi as Cn,Qn as wn,Qr as Tn,Qt as En,R as Dn,Ri as On,Rn as kn,Rr as An,Rt as jn,S as Mn,Sa as Nn,Si as Pn,Sn as Fn,Sr as In,T as Ln,Ti as Rn,Tn as zn,Ua as Bn,Ui as Vn,Ut as Hn,Va as Un,Vi as Wn,Vr as Gn,W as Kn,Wa as qn,Wr as Jn,Wt as Yn,X as Xn,Xr as Zn,Xt as Qn,Y as $n,Yr as er,Z as tr,Zi as nr,Zn as rr,Zr as ir,Zt as ar,_i as or,_n as sr,_t as cr,a as lr,aa as ur,ai as dr,an as fr,at as pr,ba as mr,bi as hr,bo as gr,bt as _r,ci as vr,cn as yr,da as br,di as xr,dn as Sr,dt as Cr,ea as wr,eo as Tr,er as Er,et as Dr,f as Or,fa as kr,fi as Ar,fn as jr,fr as Mr,g as Nr,ga as Pr,gi as Fr,gn as Ir,gt as Lr,ha as Rr,hn as zr,hr as Br,ht as Vr,i as Hr,in as Ur,it as Wr,j as Gr,ja as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kn as $r,ko as ei,kr as ti,kt as ni,l as ri,la as ii,ln as ai,m as oi,ma as si,mi as ci,mn as li,mt as ui,n as di,na as fi,ni as pi,nn as mi,nt as hi,oi as gi,pa as _i,pi as vi,pn as yi,pt as bi,q as xi,qa as Si,qi as Ci,qt as wi,rn as Ti,ro as Ei,rt as Di,si as Oi,sn as ki,ta as Ai,ti as ji,tn as Mi,tt as Ni,ui as Pi,un as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wa as Bi,wi as Vi,wr as Hi,wt as Ui,x as Wi,xi as Gi,xr as Ki,ya as qi,yi as Ji,yo as Yi,z as Xi,za as Zi,zi as Qi,zr as $i}from"./useMobileNavigationStore-lcj5GHR3.js";import{a as ea,i as ta,l as na,n as ra,o as ia,r as aa,s as oa,t as sa}from"./dialog-x2hirWBd.js";import{n as ca,t as Y}from"./utils-CTL16t2f.js";import{t as la}from"./AgentAvatar-Di8F4QJh.js";import{n as X}from"./Icon-CLpn1mIz.js";import{t as ua}from"./button-z0GOBtWi.js";import{E as da,n as fa}from"./gitApi-Dqg8EDsg.js";import{A as pa,C as ma,G as ha,K as ga,M as _a,O as va,Q as ya,S as ba,T as xa,X as Sa,Z as Ca,a as wa,b as Ta,d as Ea,et as Da,g as Oa,h as ka,i as Aa,j as ja,k as Ma,n as Na,o as Pa,p as Fa,s as Ia,u as La,v as Ra,w as za,x as Ba}from"./projectMeta-DzGPV_uF.js";import{t as Va}from"./input-BG3VWTIF.js";import{i as Ha,n as Ua,t as Wa}from"./tooltip-CtH61mQh.js";import{n as Ga,t as Ka}from"./useThemeSystem-DMzWVJaW.js";import{A as qa,B as Ja,C as Ya,K as Xa,M as Za,P as Qa,_ as $a,a as eo,f as to,g as no,h as ro,i as io,m as ao,o as oo,p as so,r as co,t as lo,v as uo,w as fo,y as po}from"./radio-TX0aocEX.js";import{i as mo,t as ho}from"./OverlayScrollbar-DlNZho3q.js";import{_ as go,a as _o,d as vo,f as yo,g as bo,h as xo,i as So,l as Co,m as wo,n as To,u as Eo,v as Do,x as Oo}from"./markdownTheme-SPe4jOwX.js";import{n as ko,r as Ao,t as jo}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Mo,B as No,C as Po,D as Fo,E as Io,F as Lo,H as Ro,I as zo,L as Bo,M as Vo,N as Ho,O as Uo,R as Wo,S as Go,T as Ko,U as qo,V as Jo,a as Yo,b as Xo,c as Zo,f as Qo,i as $o,j as es,k as ts,l as ns,m as rs,n as is,o as as,p as os,r as ss,s as cs,t as ls,u as us,w as ds,x as fs,z as ps}from"./insertionBoundaries-BtiZxiKR.js";import{A as ms,C as hs,D as gs,E as _s,F as vs,M as ys,N as bs,O as xs,P as Ss,R as Cs,S as ws,T as Ts,_ as Es,a as Ds,b as Os,d as ks,f as As,g as js,h as Ms,i as Ns,j as Ps,k as Fs,l as Is,m as Ls,p as Rs,r as zs,s as Bs,t as Vs,v as Hs,w as Us,x as Ws,y as Gs}from"./appThemeRegistry-4oEk9SR8.js";import{_ as Ks,a as qs,c as Js,g as Ys,l as Xs,o as Zs,t as Qs,v as $s,y as ec}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as tc,n as nc,o as rc,s as ic,t as ac}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as oc,n as sc,t as cc}from"./url-KeihbE0d.js";import{d as lc,h as uc,o as dc,u as fc}from"./markdown-worker-y3ewaqAK.js";import{n as pc}from"./useEffectiveDirectory-D976zCCc.js";import{a as mc,c as hc,d as gc,f as _c,i as vc,l as yc,n as bc,r as xc,s as Sc,t as Cc}from"./FadeInOnReveal-CV2s6YN8.js";import{A as wc,C as Tc,D as Ec,E as Dc,M as Oc,O as kc,S as Ac,T as jc,a as Mc,b as Nc,c as Pc,g as Fc,h as Ic,i as Lc,j as Rc,k as zc,o as Bc,p as Vc,r as Hc,s as Uc,t as Wc,v as Gc,w as Kc,x as qc,y as Jc}from"./useWorkerHighlightedLines-BQNOf2U4.js";import{t as Yc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Xc}from"./sortable-tabs-strip-CNDgyX0B.js";import{n as Zc,t as Qc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as $c}from"./markdownHeightCache-CvUyZT4q.js";import{i as el,t as tl}from"./vendor-framer-motion-DFy_BSVd.js";import{t as nl}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(_e(),1),Q=We(),$=ge(),rl=e(ve(),1),il=`openchamber:close-embedded-session-chat`,al=`openchamber:embedded-visibility`,ol=`openchamber:embedded-visibility-request`,sl=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,cl=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),ll=(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()},ul=(e,t,n,r,i,a)=>{let o=cl(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=ll(n,r,i,a);return e.set(t,{signature:o,src:c}),c},dl=null,fl=()=>{if(dl!==null)return dl;if(typeof window>`u`)return dl=!1,!1;try{return dl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,dl}catch{return dl=!1,!1}},pl=()=>{if(!fl())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},ml=Ve(`OpenChamberMedia`);function hl(){return Ie()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function gl(e){if(!hl())return null;let t=await ml.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(He.convertFileSrc(e.path));if(!t.ok)throw Error(`Native media fetch failed (${t.status})`);let r=await t.blob();n.push(new File([r],e.name,{type:e.mimeType}))}return n}var _l=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=bi([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>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),r.map(e=>e.item)},vl=new Map,yl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,bl=async e=>{let t=ys(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=vl.get(n);return r===void 0&&(r=await qo(e.iconName,t)??``,vl.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},xl=[],Sl=e=>void 0,Cl=()=>void 0;function wl(e){let t=Cs()&&e.enabled&&Gs(e.isMobile),n=(0,Z.useRef)(null),r=(0,Z.useRef)(e.text),i=(0,Z.useRef)(!1),a=(0,Z.useRef)(-1),o=(0,Z.useRef)(null),s=(0,Z.useRef)(``),c=(0,Z.useRef)([]),l=(0,Z.useRef)(Os()),u=J(e.onText),d=J(e.onSend),f=J(e.onAbort),p=J(e.onAttach),m=J(e.onFiles),h=J(e.onRemoveAttachment),g=J(e.onOpenModel),_=J(e.onCycleAgent),v=J(e.onOpenAgent),y=J(e.onScrollToBottom),b=J(e.onAutocompleteAccept??Sl),x=J(e.onAutocompleteDismiss??Cl),S=J(e=>{typeof document>`u`||Ms(document.documentElement,e)});Rs.bind({onText:(e,t,n)=>{vs({incoming:e,replacedText:o.current})||(o.current=null,r.current=e,i.current=!0,u(e,t,n))},onSend:e=>{r.current=e,d(e)},onAbort:f,onAttach:p,onFiles:m,onRemoveAttachment:h,onOpenModel:g,onCycleAgent:_,onOpenAgent:v,onHeight:S,onScrollToBottom:y,onAutocompleteAccept:e=>{i.current=!1,b(e)},onAutocompleteDismiss:x});let C=()=>({text:e.text,placeholder:e.placeholder,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel,modelIcon:s.current,canSend:e.canSend,canAbort:e.canAbort,attachmentCount:e.attachmentCount,attachmentPreviews:c.current,citationRanges:Te(e.text,e.attachments.map(e=>e.filename)),chipRanges:Es(Us(e.text,e.chipHighlights),ys(`--primary`)),appearance:typeof document>`u`?`dark`:gs(document.documentElement),attachAria:e.attachAria,attachTitle:e.attachTitle,attachPhotosLabel:e.attachPhotosLabel,attachFilesLabel:e.attachFilesLabel,attachCancelLabel:e.attachCancelLabel,sendAria:e.sendAria,queueAria:e.queueAria,stopAria:e.stopAria,modelAria:e.modelAria,agentAria:e.agentAria,agentLabel:e.agentLabel,agentColor:_s(e.agentName||void 0),agentIdenticon:xs(e.agentName||void 0),suppressed:e.suppressed,showScrollToBottom:e.showScrollToBottom,scrollAria:e.scrollAria,autocomplete:l.current});(0,Z.useLayoutEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement;return Ss(e,!0),()=>{Ss(e,!1)}},[t]),(0,Z.useEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement,i=C();n.current=i,r.current=i.text,Rs.rememberText(i.text),Rs.retain(e,i);let a=As();return()=>{n.current=null,a(),Rs.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=Ca(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Ws().update(a),i)return ms(i).then(t=>{if(r)return;let i=t??``;s.current=i;let a={modelIcon:i,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};n.current&&={...n.current,...a},Ws().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let w=js(e.attachments);(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e.attachments;if(i.length===0){c.current=[],n.current&&(n.current={...n.current,attachmentPreviews:[]},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await Fs(t.dataUrl):``;return{id:t.id,filename:t.filename,mime:t.mimeType,thumbnailBase64:n??``,removeAria:e.removeAttachmentNamedAria(t.filename)}})).then(e=>{r||(c.current=e,n.current&&(n.current={...n.current,attachmentPreviews:e},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,w]);let T=e.autocompleteRows??xl,E=e.autocompleteOpen===!0,D=e.autocompleteHighlightedIndex??0,O=yl(T,E,D);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(E&&T.length>0)){let e=Os();hs(l.current,e)||(l.current=e,n.current&&(n.current={...n.current,autocomplete:e},Rs.rememberState(n.current)),Ws().update({autocomplete:e}));return}return bl(T).then(t=>{if(e)return;let r={open:t.length>0,highlightedIndex:Math.max(0,Math.min(D,Math.max(t.length-1,0))),rows:t};hs(l.current,r)||(l.current=r,n.current&&(n.current={...n.current,autocomplete:r},Rs.rememberState(n.current)),Ws().update({autocomplete:r}))}),()=>{e=!0}},[t,O]);let k=t?Us(e.text,e.chipHighlights).map(e=>`${e.start}:${e.end}:${e.triggerLength}`).join(`|`):``;return(0,Z.useEffect)(()=>{if(!t)return;let s=C(),c=n.current;if(c&&Ts(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,Rs.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=bs({nextText:s.text,nativeOwnedText:r.current,echoingNative:i.current,preset:l});i.current=!1,!u.omitText&&u.forceText&&(o.current=r.current),u.omitText||(r.current=s.text);let d=Hs(c,s,u,{caret:e.caret});d&&Ws().update(d)},[t,e.text,e.textPresetEpoch,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,w,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,k]),t}var Tl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},El=1e4,Dl=15e3,Ol=3e4,kl=3e4,Al=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 o()}catch{}this.connectPromise=new Promise((e,t)=>{let r=!1,i;try{let e=n().websocket(`/api/dictation/ws`);i=Ae(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!r){r=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},El);i.onopen=()=>{},i.onmessage=t=>{let n;try{n=JSON.parse(String(t.data))}catch{return}if(!r&&n.type===`ready`){r=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(n)},i.onerror=()=>{window.setTimeout(()=>{r||(r=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!r){r=!0,clearTimeout(a),this.connectPromise=null;let n=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${n}`));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`))},Dl);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`))},kl),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=Tl(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)}}},Ol))}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`,()=>{Al.cancelAllForRuntimeSwitch()});var jl=128,Ml=`audio/pcm;rate=16000;bits=16`,Nl=()=>new Promise(e=>setTimeout(e,0)),Pl=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Fl=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??Ml,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Pl}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<jl;){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 Nl()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Il=16e3,Ll=Il,Rl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},zl=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Bl=(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]=zl(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]=zl(e[i]*(1-s)+e[o]*s)}return a},Vl=(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},Hl=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)},Ul=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Wl=e=>{if(e)try{e.disconnect()}catch{}},Gl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Rl()!==null;function Kl(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=Ul(),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=Rl();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(Yl);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=Bl(a,n.sampleRate,Il);for(t.pending=Vl(t.pending,c);t.pending.length>=Ll;){let e=t.pending.slice(0,Ll);t.pending=t.pending.slice(Ll),i.current(Hl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Jl);try{await n.close()}catch{}throw l.current=Ul(),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{}Wl(e.processor),Wl(e.source),Wl(e.gain),e.stream&&e.stream.getTracks().forEach(ql);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Hl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Ul())},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 ql(e){try{e.stop()}catch{}}function Jl(e){try{e.stop()}catch{}}function Yl(){}var Xl=1e3,Zl=e=>e instanceof Error?e:Error(String(e)),Ql=()=>{let e=Ai.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 $l(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 Fl({client:Al,getStartOptions:Ql});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},Xl)},[]),C=(0,Z.useCallback)(e=>{let t=Zl(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)(()=>Al.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Al.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Kl({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 eu=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},tu=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ga(),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},nu=e=>{let t=Ai(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 m(`/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},ru=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:c,onInsert:l,onInsertAndSend:u,onActiveChange:d,onContentHeightChange:f,renderTrigger:p,topAccessory:m}=e,h=p===void 0||p,{t:g}=ct(),{currentTheme:_}=Ga(),v=Ai(iu),y=q(au),b;t[0]===y?b=t[1]:(b=Za(Qa(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(ou),C=Z.useRef(null),w=Z.useRef(l),T=Z.useRef(u),E,D;t[2]!==l||t[3]!==u?(E=()=>{w.current=l,T.current=u},D=[l,u],t[2]=l,t[3]=u,t[4]=E,t[5]=D):(E=t[4],D=t[5]),Z.useEffect(E,D);let O;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(O={onTranscript:e=>{let t=C.current;C.current=null,t===`send`?T.current(e):w.current(e)}},t[6]=O):O=t[6];let{status:k,partialTranscript:A,volume:j,duration:M,error:N,errorReason:P,startDictation:F,confirmDictation:I,cancelDictation:L,retryFailedDictation:R,acceptPartialTranscript:z,discardFailedDictation:B}=$l(O),V=k===`recording`&&P===`model_download_in_progress`,H=nu(V),U=Z.useRef(k),W,ee;t[7]===k?(W=t[8],ee=t[9]):(W=()=>{U.current=k},ee=[k],t[7]=k,t[8]=W,t[9]=ee),Z.useEffect(W,ee);let G,K;t[10]!==d||t[11]!==k?(G=()=>{d?.(k!==`idle`)},K=[k,d],t[10]=d,t[11]=k,t[12]=G,t[13]=K):(G=t[12],K=t[13]),Z.useLayoutEffect(G,K);let te,ne;t[14]!==I||t[15]!==F?(te=()=>{let e=()=>{U.current===`idle`?F():U.current===`recording`&&(C.current=`insert`,I())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[F,I],t[14]=I,t[15]=F,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==L||t[19]!==I||t[20]!==k?(re=()=>{if(k!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),C.current=`insert`,I();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),L())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[k,I,L],t[18]=L,t[19]=I,t[20]=k,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Z.useEffect(re,ie);let ae=Z.useRef(null),oe=Z.useRef(null),se=Z.useRef(null),[ce,le]=Z.useState(null),ue=k!==`idle`,de=Z.useRef(f),fe,pe;t[23]===f?(fe=t[24],pe=t[25]):(fe=()=>{de.current=f},pe=[f],t[23]=f,t[24]=fe,t[25]=pe),Z.useEffect(fe,pe);let me=Z.useRef(!1),he;t[26]===ue?he=t[27]:(he=()=>{if(!ue){me.current&&(me.current=!1,de.current?.(null));return}let e=oe.current,t=se.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);me.current=!0,de.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=ue,t[27]=he);let ge;t[28]!==N||t[29]!==ue||t[30]!==A||t[31]!==k?(ge=[ue,A,k,N],t[28]=N,t[29]=ue,t[30]=A,t[31]=k,t[32]=ge):ge=t[32],Z.useLayoutEffect(he,ge);let _e,ve;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>()=>{me.current&&(me.current=!1,de.current?.(null))},ve=[],t[33]=_e,t[34]=ve):(_e=t[33],ve=t[34]),Z.useEffect(_e,ve);let ye,be;if(t[35]===ue?(ye=t[36],be=t[37]):(ye=()=>{if(!ue)return;let e=ae.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&le(e.offsetHeight)},be=[ue],t[35]=ue,t[36]=ye,t[37]=be),Z.useLayoutEffect(ye,be),!S||!v)return null;let xe=k!==`idle`,Se;t[38]===I?Se=t[39]:(Se=e=>{C.current=e,I()},t[38]=I,t[39]=Se);let Ce=Se,we;t[40]===R?we=t[41]:(we=()=>{C.current=`insert`,R()},t[40]=R,t[41]=we);let Te=we,Ee;bb0:{if(k===`failed`){Ee=``;break bb0}if(k===`uploading`){let e;t[42]===g?e=t[43]:(e=g(`chat.dictation.processing`),t[42]=g,t[43]=e),Ee=e;break bb0}if(V){let e;t[44]!==H||t[45]!==g?(e=H===null?g(`chat.dictation.downloadingModel`):g(`chat.dictation.downloadingModelProgress`,{percent:String(H)}),t[44]=H,t[45]=g,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===g?e=t[48]:(e=g(`chat.dictation.listening`),t[47]=g,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:su,onPointerDownCapture:cu},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==x||t[51]!==c||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==h||t[56]!==F||t[57]!==g?(Ae=h?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{F()},disabled:c||xe,title:x?`${g(`chat.dictation.start`)} (${x})`:g(`chat.dictation.start`),"aria-label":g(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=x,t[51]=c,t[52]=i,t[53]=o,t[54]=xe,t[55]=h,t[56]=F,t[57]=g,t[58]=Ae):Ae=t[58];let je;t[59]!==z||t[60]!==L||t[61]!==Ce||t[62]!==_||t[63]!==B||t[64]!==M||t[65]!==N||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==V||t[73]!==A||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==s||t[78]!==k||t[79]!==g||t[80]!==m||t[81]!==j?(je=xe?(0,$.jsxs)(`div`,{ref:ae,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:_.colors.surface.subtle},role:`dialog`,"aria-label":g(`chat.dictation.overlayAria`),children:[m,(0,$.jsx)(`div`,{ref:oe,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:se,className:Y(!A&&`translate-y-1.5`),children:[A?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:_.colors.surface.foreground},children:A}):k===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:_.colors.surface.mutedForeground},children:[(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:_.colors.surface.mutedForeground},children:De}),k===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.error},children:N||g(`chat.dictation.failed`)}):null,k===`recording`&&N&&!V?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.warning},children:N}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:_.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:_.colors.status.error}})]}),(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:eu(M)})]}):k===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:_.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-primary hover:text-primary`),onClick:()=>Ce(`send`),title:g(`chat.dictation.insertAndSend`),"aria-label":g(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:s})})]}):k===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:B,title:g(`chat.dictation.discard`),"aria-label":g(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:g(`chat.dictation.retry`),"aria-label":g(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),A.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{C.current=`insert`,z()},title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=z,t[60]=L,t[61]=Ce,t[62]=_,t[63]=B,t[64]=M,t[65]=N,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=V,t[73]=A,t[74]=De,t[75]=n,t[76]=Te,t[77]=s,t[78]=k,t[79]=g,t[80]=m,t[81]=j,t[82]=je):je=t[82];let Me;return t[83]!==Ae||t[84]!==je?(Me=(0,$.jsxs)($.Fragment,{children:[Ae,je]}),t[83]=Ae,t[84]=je,t[85]=Me):Me=t[85],Me};function iu(e){return e.dictationEnabled}function au(e){return e.shortcutOverrides}function ou(){return!se()&&Gl()}function su(e){return e.preventDefault()}function cu(e){e.pointerType===`touch`&&e.preventDefault()}var lu=2e3,uu=ce((e,t)=>({pending:!1,expiresAt:null,arm:(t=lu)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),du=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}},fu=15e3,pu=100,mu=new Map,hu=new Map,gu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,_u=e=>{let t=gu(e),n=e.now??Date.now(),r=hu.get(t);if(r&&n-r.loadedAt<fu)return Promise.resolve(r.sessions);let i=mu.get(t);if(i)return i;let a=e.request().then(e=>{for(hu.delete(t);hu.size>=pu;){let e=hu.keys().next().value;if(typeof e!=`string`)break;hu.delete(e)}return hu.set(t,{loadedAt:Date.now(),sessions:e}),e});return mu.set(t,a),a.then(()=>{mu.get(t)===a&&mu.delete(t)},()=>{mu.get(t)===a&&mu.delete(t)}),a},vu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),yu=(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(vu)},bu=30;function xu(e){return e===`busy`||e===`retry`}var Su=new Map;function Cu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function wu(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 Tu(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${wu(e.error)}`)}function Eu(e,t){let n=Pr();if(!n)return!1;let r=n.getTranscript(Bi(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>qr()}function Du(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Ou(e,t,n){let r=[...e.getState().session],i=Zr.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function ku(){let e=Ir(),t=Vt(),n=Hn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=Pr();if(!r||!t)return Cu({kind:`unknown`,loadedTurns:0},!1);let i=Bi(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Cu(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let r=n.getChild(e);if(!r)return;let i=r.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_error_at:{...i.session_error_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};At(a,t),Xt(r,t),r.setState(a);for(let n of t)qi(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=Su.get(t);if(n)return Su.delete(t),Su.set(t,n),n;let r=new Set;for(Su.set(t,r);Su.size>bu;){let e=Su.keys().next().value;if(!e)break;let t=[...Su.get(e)??[]];Su.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=_n(a.getState()),u=Qr(),d=$r({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),yt()){let e=new Set([r,...c,...l]),t=(Pr()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),n=(t.length>0?t:Array.from(c)).filter(t=>t===r||e.has(t)?!1:Eu(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await si(a,r):await _i(a,r)}catch{return}if(i?.isStale?.())return;let u=Pr()?.getTranscript(Bi(a,r));ir({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await pi({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),u=(0,Z.useCallback)(async(t,i)=>{await ln();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=De.getScopedSdkClient(o);c(t,o);let d=r(t,o);return du.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Pr(),i=Bi(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Zr.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&fn(o,t)){ir({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Du({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Cn(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Tu(e,`session.get`),e});if(n.data&&!e()){let r=nr(n.data);e()||Ou(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let i=r||e;if(!t||!i)return;let o=n.ensureChild(i,{bootstrap:!1}),s=De.getScopedSdkClient(i),c=await _u({runtimeKey:a(),directory:i,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:i});return Tu(e,`session.children`),e.data??[]}});o.setState(e=>{let n=yu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=i(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,i]),p=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).loading,[e,i]),m=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).complete,[e,i]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await ln();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(xu(o))throw Error(`refresh transcript busy`);try{await mr(i,t),ir({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Au=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,ju=e=>e===`original`||e===`modified`,Mu=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Nu=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Au(t.source))return null;let n=Mu(t.startLine),r=Mu(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:ju(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()}},Pu=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(Nu).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Fu=ce()(ue(le((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:Be(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Pu(e.drafts)}}),{name:`inline-comment-draft-store`}));function Iu(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 Lu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Iu).join(`
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -6517,12 +6517,12 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n
|
|
|
6517
6517
|
`,ud=`oc-file-type-icon-sprite-root`;(()=>{if(typeof document>`u`||document.getElementById(ud))return;let e=()=>{if(document.getElementById(ud))return;let e=document.createElement(`div`);e.id=ud,e.setAttribute(`aria-hidden`,`true`),e.style.position=`absolute`,e.style.width=`0`,e.style.height=`0`,e.style.overflow=`hidden`,e.innerHTML=ld,document.body.appendChild(e)};if(document.body){e();return}document.addEventListener(`DOMContentLoaded`,e,{once:!0})})();var dd={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`},fd={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`},pd={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`},md=`document`,hd=(e,t)=>{if(!e)return t===`light`?`${md}_light`:md;if(t===`light`){let t=e.endsWith(`_light`)?e:`${e}_light`;return cd.has(t)?t:e}return e},gd=e=>typeof e==`string`&&e.trim().length>0,_d=(e,t)=>{let n=e.replace(/\\/g,`/`).split(`/`).pop()?.toLowerCase()||``;if(dd[n])return dd[n];if(n.startsWith(`.env`))return`settings`;let r=fc(e);if(r&&fd[r])return fd[r];let i=gd(t)?t.toLowerCase():n.includes(`.`)&&n.split(`.`).pop()?.toLowerCase()||``;return i&&pd[i]?pd[i]:i&&cd.has(i)?i:md},vd=(e,t)=>{let n=t?.isDirectory?`folder`:_d(e,t?.extension);return`#${hd(cd.has(n)?n:md,t?.themeVariant||`dark`)}`},yd=e=>{let t=(0,Q.c)(12),{filePath:n,extension:r,isDirectory:i,className:a}=e,o=Ka()?.currentTheme.metadata.variant===`light`?`light`:`dark`,s;t[0]!==r||t[1]!==n||t[2]!==i||t[3]!==o?(s=vd(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},bd=(0,Z.memo)(()=>{let{t:e}=ct(),t=(0,Z.useRef)(null),n=ei(e=>e.addAttachedFile),r=q(e=>e.isMobile),i=ko(),a=i.runtime.isVSCode,o=r?`h-9 w-9`:`h-7 w-7`,s=r?`h-5 w-5`:`h-[1.125rem] w-[1.125rem]`,c=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),Br.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 c(n),t.current&&(t.current.value=``))}}),(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{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
|
`);Br.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 c(a)}catch(t){console.error(`VS Code file pick failed`,t),Br.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)(Ua,{side:`top`,children:(0,$.jsx)(`p`,{children:e(`chat.fileAttachment.actions.attach`)})})]})]})});bd.displayName=`FileAttachmentButton`;var xd=(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}=ct(),{isMobile:l,isTablet:u}=mo(),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=pc()??``,m=Co(f,p),h=`attachment-image:${n.id}`,g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=_c(),t[0]=g):g=t[0];let _=Z.useRef(g),v=qd,y=Jd,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||Do({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=J(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=J(E);if(!f){let e;t[20]!==C||t[21]!==n.filename?(e=(0,$.jsx)(yd,{filePath:n.filename,extension:C,className:`h-4 w-4`}),t[20]=C,t[21]=n.filename,t[22]=e):e=t[22];let i;t[23]===x?i=t[24]:(i=(0,$.jsx)(`span`,{className:`text-foreground truncate max-w-[12.5rem]`,children:x}),t[23]=x,t[24]=i);let a;t[25]===r?a=t[26]:(a=e=>{e.stopPropagation(),r()},t[25]=r,t[26]=a);let o;t[27]!==x||t[28]!==c?(o=c(`chat.fileAttachment.actions.removeNamed`,{name:x}),t[27]=x,t[28]=c,t[29]=o):o=t[29];let s;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`}),t[30]=s):s=t[30];let l;t[31]!==o||t[32]!==a?(l=(0,$.jsx)(`span`,{onClick:a,className:`flex items-center justify-center h-5 w-5 flex-shrink-0 hover:bg-[var(--interactive-hover)] rounded-full transition-colors cursor-pointer`,"aria-label":o,children:s}),t[31]=o,t[32]=a,t[33]=l):l=t[33];let u;return t[34]!==l||t[35]!==e||t[36]!==i?(u=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 text-sm hover:opacity-80 transition-opacity text-left h-5`,children:[e,i,l]}),t[34]=l,t[35]=e,t[36]=i,t[37]=u):u=t[37],u}let O=i?`button`:void 0,k=i?0:void 0,A;t[38]!==D||t[39]!==i?(A=e=>{i&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),D())},t[38]=D,t[39]=i,t[40]=A):A=t[40];let j;t[41]!==h||t[42]!==T?(j=e=>{(e.pointerType!==`mouse`||e.button===0)&&_.current.start({pointerId:e.pointerId,key:h,clientX:e.clientX,clientY:e.clientY,onTrigger:T})},t[41]=h,t[42]=T,t[43]=j):j=t[43];let M,N,P;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(M=e=>{_.current.move(e.pointerId,e.clientX,e.clientY)},N=e=>{_.current.end(e.pointerId)},P=e=>{_.current.cancel(e.pointerId)},t[44]=M,t[45]=N,t[46]=P):(M=t[44],N=t[45],P=t[46]);let F;t[47]!==h||t[48]!==T?(F=e=>{e.preventDefault(),e.stopPropagation(),_.current.openFromContextMenu(h,T)},t[47]=h,t[48]=T,t[49]=F):F=t[49];let I=m||void 0,L;t[50]!==x||t[51]!==I?(L=(0,$.jsx)(`img`,{src:I,alt:x,className:`h-full w-full object-cover`,loading:`lazy`,draggable:!1}),t[50]=x,t[51]=I,t[52]=L):L=t[52];let R;t[53]===r?R=t[54]:(R=e=>{e.stopPropagation(),r()},t[53]=r,t[54]=R);let z=d?`opacity-100`:`opacity-0 group-hover:opacity-100`,B;t[55]===z?B=t[56]:(B=Y(`absolute top-0.5 right-0.5 h-4 w-4 rounded-full bg-transparent text-foreground hover:text-destructive flex items-center justify-center transition-opacity focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,z),t[55]=z,t[56]=B);let V;t[57]===c?V=t[58]:(V=c(`chat.fileAttachment.actions.removeImage`),t[57]=c,t[58]=V);let H;t[59]!==x||t[60]!==c?(H=c(`chat.fileAttachment.actions.removeNamed`,{name:x}),t[59]=x,t[60]=c,t[61]=H):H=t[61];let U;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,$.jsx)(X,{name:`close`,className:`h-2.5 w-2.5`}),t[62]=U):U=t[62];let W;t[63]!==R||t[64]!==B||t[65]!==V||t[66]!==H?(W=(0,$.jsx)(`button`,{onClick:R,className:B,title:V,"aria-label":H,children:U}),t[63]=R,t[64]=B,t[65]=V,t[66]=H,t[67]=W):W=t[67];let ee;return t[68]!==x||t[69]!==D||t[70]!==j||t[71]!==F||t[72]!==L||t[73]!==W||t[74]!==O||t[75]!==k||t[76]!==A?(ee=(0,$.jsxs)(`div`,{role:O,tabIndex:k,onClick:D,onKeyDown:A,onPointerDown:j,onPointerMove:M,onPointerUp:N,onPointerCancel:P,onContextMenu:F,"data-attachment-preview":`true`,className:`relative h-10 w-10 rounded-lg border border-border/40 bg-muted/10 overflow-hidden flex-shrink-0 group cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"aria-label":x,children:[L,W]}),t[68]=x,t[69]=D,t[70]=j,t[71]=F,t[72]=L,t[73]=W,t[74]=O,t[75]=k,t[76]=A,t[77]=ee):ee=t[77],ee});xd.displayName=`ImagePreview`;var Sd=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)}),Cd=(0,Z.memo)(e=>{let t=(0,Q.c)(25),{file:n,onRemove:r}=e,{t:i}=ct(),{displayName:a,extension:o}=Sd(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)(yd,{filePath:n.filename,extension:o,className:`h-4 w-4`}),t[12]=o,t[13]=n.filename,t[14]=h):h=t[14];let g=s?`whitespace-nowrap`:`truncate max-w-[12.5rem]`,_;t[15]===g?_=t[16]:(_=Y(`text-foreground`,g),t[15]=g,t[16]=_);let v;t[17]!==a||t[18]!==_?(v=(0,$.jsx)(`span`,{className:_,children:a}),t[17]=a,t[18]=_,t[19]=v):v=t[19];let y;return t[20]!==n.vscodePath||t[21]!==v||t[22]!==m||t[23]!==h?(y=(0,$.jsxs)(`button`,{type:`button`,onClick:Yd,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});Cd.displayName=`VSCodeFileChip`;var wd=(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(Xd);if(e.length===0){l=null;break bb0}let n=e.filter(Zd),u=e.filter(Qd),d=n.map($d).filter(ef);o=`flex items-center gap-2 flex-wrap`,s=n.map((e,t)=>(0,$.jsx)(xd,{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)(Cd,{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});wd.displayName=`AttachedVSCodeFileChips`;var Td=(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(tf);if(e.length===0){l=null;break bb0}let t=e.map(nf).filter(rf);c=`pb-4 w-full px-1`,o=`flex items-center gap-1.5 flex-wrap`,s=e.map((e,n)=>(0,$.jsx)(xd,{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});Td.displayName=`AttachedFilesList`;var Ed=(e,t)=>e.some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t),Dd=(e,t,n)=>!!n&&e.some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n&&e.vscodePath===t),Od=(0,Z.memo)(e=>{let t=(0,Q.c)(41),{attachedFiles:n,onAddVSCodeFile:r,onAddVSCodeSelection:i}=e,{t:a}=ct(),o=ei(af),s=ei(of);if(!ko().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=Ed(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?(_=Dd(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(W(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(W(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)(yd,{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)(yd,{filePath:l,extension:b,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs truncate max-w-[13.75rem]`,children:x})]}),t[30]=x,t[31]=b,t[32]=l,t[33]=C,t[34]=u,t[35]=D,t[36]=a,t[37]=k):k=t[37];let A;return t[38]!==O||t[39]!==k?(A=(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[O,k]}),t[38]=O,t[39]=k,t[40]=A):A=t[40],A});Od.displayName=`ActiveEditorFileSuggestion`;var kd=`application/vnd.github.issue-link`,Ad=`application/vnd.github.pull-request-link`,jd=e=>e.mime===kd?`issue`:e.mime===Ad?`pr`:null,Md=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??``}`},Nd=e=>{let t=new Map,n=[];for(let r of e){if(r.type!==`file`||!(r.mime||r.url)||we(r))continue;let e=Md(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},Pd=(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?Nd(e):Nd(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))},Fd=e=>e.failed||e.repositoryStatus===`error`?`error`:e.flightActive||e.repositoryStatus===`loading`?`loading`:e.hasSlimImage&&e.repositoryStatus===`ready`?`idle`:e.repositoryStatus,Id=e=>/^(?:data|blob|https?):/i.test(e),Ld=e=>{for(let t of[e.byteSize,e.size])if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t},Rd=(e,t)=>t.some(t=>t.type===`file`&&t.mime?.startsWith(`image/`)===!0&&t.slim===!0&&!t.url&&So(e,Ld(t))),zd=(e,t)=>t.type!==`file`||t.mime?.startsWith(`image/`)!==!0||typeof t.url!=`string`||!t.url||Id(t.url)?!1:So(e,Ld(t)),Bd=e=>Y(`grid gap-2`,e===1?`grid-cols-1 max-w-56`:`grid-cols-2`),Vd=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}=ct(),u=pc()??``,d=Co(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)(ua,{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},Hd=e=>{let t=(0,Q.c)(11),{images:n,onLoad:r}=e,{t:i}=ct(),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)(ua,{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},Ud={threshold:.01},Wd=new Set,Gd=(0,Z.memo)(({files:e,messageID:t,sessionID:n,onShowPopup:r,compact:i=!1})=>{let{t:a}=ct(),o=pc()??``,s=n||e.find(e=>typeof e.sessionID==`string`&&e.sessionID)?.sessionID||``,c=ki(t,o,s||void 0),[l,u]=Z.useState(()=>ji(t)??[]),d=Z.useRef(null),f=Z.useRef(!1),p=Z.useRef(null),m=Z.useRef(!1),h=Z.useRef(new Set),g=Z.useRef(``),[,_]=Z.useReducer(e=>e+1,0),v=`${o}\n${s}\n${t}`;g.current!==v&&(g.current=v,f.current=!1,p.current=null,m.current=!1,h.current=new Set,u(ji(t)??[]));for(let t of e)t.type===`file`&&t.slim===!0&&t.mime?.startsWith(`image/`)&&h.current.add(Md(t));let y=e=>{if(!e)return`Unnamed file`;let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e},b=Z.useMemo(()=>e=>jd(e)!==null&&typeof e.filename==`string`&&e.filename.trim().length>0?e.filename.trim():y(e.filename||e.url)||a(`chat.fileAttachment.fileFallback`),[a]),x=e=>!e||!Number.isFinite(e)||e<=0?``:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`,S=Z.useMemo(()=>Pd(e,[...c,...l]),[l,e,c]),C=Eo(),w=Z.useMemo(()=>Rd(C,S),[S,C]),[T,E]=Z.useState({scope:``,keys:Wd}),D=T.scope===v?T.keys:Wd,O=Z.useMemo(()=>{if(!_o(C))return Wd;let e=new Set;for(let t of S){let n=Md(t);D.has(n)||zd(C,t)&&e.add(n)}return e},[D,S,C]),k=S.filter(e=>e.mime?.startsWith(`image/`)),A=k.filter(e=>!!e.url),j=S.filter(e=>!e.mime?.startsWith(`image/`)),M=k.some(e=>e.slim===!0),N=w&&k.some(e=>e.slim===!0&&!D.has(Md(e))),P=k.filter(e=>{let t=Md(e);return D.has(t)?!1:e.slim===!0?w:O.has(t)}),F=new Set(P.map(Md)),I=k.filter(e=>{let t=Md(e);return!F.has(t)&&(h.current.has(t)||!!e.url)}),L=P.map(e=>({key:Md(e),filename:b(e),sizeText:x(Ld(e))})),R=J((e=!1)=>{if(!M||!o||!s||!t||!e&&f.current||p.current)return;f.current=!0,m.current=!1;let n=Ii(o,s,t).then(()=>{let e=ji(t);e&&e.length>0&&u(e)}).catch(()=>{let e=ji(t);if(e&&e.length>0){u(e);return}m.current=!0}).finally(()=>{p.current=null,_()});p.current=n,_()}),z=J(e=>{E(t=>{let n=t.scope===v?new Set(t.keys):new Set;return n.add(e),{scope:v,keys:n}}),M&&R(!0)});rt(M&&!N?d:null,e=>{e.some(e=>e.isIntersecting)&&R(!1)},Ud),Z.useEffect(()=>{if(!M||N)return;let e=d.current;if(!e)return;let t=e.closest(`[data-scrollbar="chat"]`);if(!t||typeof IntersectionObserver>`u`){R(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();n.bottom>r.top&&n.top<r.bottom&&R(!1)},[o,M,t,s,N]);let B=M&&o&&s?Rr(o,s,t).status:`ready`,V=S.some(e=>e.mime?.startsWith(`image/`)===!0&&typeof e.url==`string`&&e.url.length>0&&e.slim!==!0)?`ready`:Fd({hasSlimImage:M,flightActive:!!p.current,failed:m.current,repositoryStatus:B}),H=Z.useMemo(()=>A.flatMap(e=>{if(!e.url)return[];let t=b(e)||`Image`;return[{url:e.url,mimeType:e.mime,filename:t,size:e.size}]}),[A,b]),U=J(e=>{if(!r)return;let t=A.findIndex(t=>Md(t)===Md(e)),n=H[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:H,index:t}})});return S.length===0?null:i?(0,$.jsxs)(`div`,{ref:d,className:`space-y-1.5 mt-1.5`,"data-message-files":t,children:[j.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:j.map(e=>{let t=b(e),n=t.split(`.`).pop()||``,r=x(e.size),i=jd(e),a=je(e.mime)||Me(e.filename)||Me(e.url);return(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:i&&e.url?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{oc(e.url||``)},className:`inline-flex items-center bg-muted/30 border border-border/30 typography-meta gap-1 px-2 py-0.5 rounded-lg text-foreground hover:text-primary transition-colors`,children:[i===`pr`?(0,$.jsx)(X,{name:`git-pull-request`,className:`text-muted-foreground h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`github`,className:`text-muted-foreground h-3.5 w-3.5`}),(0,$.jsx)(`div`,{className:`overflow-hidden max-w-[13.75rem]`,children:(0,$.jsx)(`span`,{className:`truncate block`,title:t,children:t})})]}):(0,$.jsxs)(`div`,{className:`inline-flex items-center bg-muted/30 border border-border/30 typography-meta gap-1 px-2 py-0.5 rounded-lg`,children:[e.mime?.includes(`pdf`)?(0,$.jsx)(X,{name:`file-pdf`,className:`text-muted-foreground h-3.5 w-3.5`}):(0,$.jsx)(yd,{filePath:t,extension:n,isDirectory:a,className:`text-muted-foreground h-3.5 w-3.5`}),(0,$.jsx)(`div`,{className:`overflow-hidden max-w-[8.75rem]`,children:(0,$.jsx)(`span`,{className:`truncate block`,title:t,children:t})})]})}),(0,$.jsx)(Ua,{children:(0,$.jsxs)(`p`,{children:[t,r?` (${r})`:``]})})]},`file-${Md(e)}`)})}),L.length>0?(0,$.jsx)(Hd,{images:L,onLoad:z}):null,I.length>0?(0,$.jsx)(`div`,{className:Bd(I.length),children:I.map(e=>{let t=b(e);return(0,$.jsx)(Vd,{source:e.url,filename:t,sizeText:x(Ld(e)),materializationStatus:e.url?`ready`:V,onRetry:()=>R(!0),onOpen:e.url?()=>U(e):void 0},Md(e))})}):null]}):(0,$.jsxs)(`div`,{ref:d,"data-message-files":t,className:Y(`grid gap-2`,i?`grid-cols-1`:`grid-cols-1 sm:grid-cols-2`),children:[L.length>0?(0,$.jsx)(Hd,{images:L,onLoad:z}):null,S.map(e=>{let t=b(e),n=e.mime?.startsWith(`image/`),o=x(e.size),s=jd(e);if(F.has(Md(e)))return null;if(n&&e.url)return(0,$.jsx)(Vd,{source:e.url,filename:t,sizeText:o,onOpen:()=>U(e)},Md(e));if(n)return(0,$.jsx)(Vd,{filename:t,sizeText:o,materializationStatus:V,onRetry:()=>R(!0)},Md(e));if(s&&e.url)return(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{oc(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)(Ua,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Md(e));let c=e.source,l=typeof c?.type==`string`?c.type:void 0,u=c&&typeof c.path==`string`?c.path:void 0,d=l===`file`&&u?u:e.url||``;return d&&lc(d)?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{q.getState().navigateToDiagram(d)},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)(Ua,{children:(0,$.jsx)(`p`,{children:a(`chat.fileAttachment.openInDiagram`)})})]},Md(e)):(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{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`)}):je(e.mime)||Me(e.filename)||Me(e.url)?(0,$.jsx)(yd,{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)(Ua,{children:(0,$.jsxs)(`p`,{children:[t,o?` (${o})`:``]})})]},Md(e))})]})});Gd.displayName=`MessageFilesDisplay`;var Kd=(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=Bd(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(sf),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});Kd.displayName=`ImageGallery`;function qd(e){let t=e.replace(/\\/g,`/`).split(`/`);return t[t.length-1]||e}function Jd(e){let t=e.split(`.`);return t.length>1?t[t.length-1].toLowerCase():``}function Yd(e){e.target.closest(`[data-remove-button]`)}function Xd(e){return e.source===`vscode`&&e.vscodeSource===`file`}function Zd(e){return e.mimeType.startsWith(`image/`)}function Qd(e){return!e.mimeType.startsWith(`image/`)}function $d(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function ef(e){return e.url}function tf(e){return e.source!==`server`&&e.source!==`vscode`&&e.mimeType.startsWith(`image/`)}function nf(e){return{url:e.dataUrl||e.serverPath||``,mimeType:e.mimeType,filename:e.filename,size:e.size}}function rf(e){return e.url}function af(e){return e.activeEditorFile}function of(e){return e.setPendingInputText}function sf(e){return{url:e}}var cf=`text-[var(--primary)]`,lf=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,uf=/(^|\s)\/(\u2003)?([A-Za-z0-9][A-Za-z0-9_-]*)/g,df=/\[skill:([A-Za-z0-9][A-Za-z0-9_-]*)\]/g,ff=/\[command:([^\]\r\n]+)\]/g,pf=/(^|[\s([{])(@session:([A-Za-z0-9_-]+))(?=$|[\s)\]},.!?;:])/g,mf=/@([^\s]+)/g,hf=` `,gf=e=>e.replaceAll(`\\`,`/`).split(`/`).at(-1)?.replace(/\.md$/,``)??``,_f=e=>e.trim().toLowerCase(),vf=(e,t)=>{let n=t>0?e[t-1]:null;return!n||/(\s|\(|\)|\[|\]|\{|\}|"|'|`|,|\.|;|:)/.test(n)},yf=e=>e.includes(`/`)||e.includes(`\\`)||e.includes(`.`),bf=(e,t)=>{e.push(t)},xf={kind:`skill`,priority:120,shouldScan:e=>e.includes(`/`)||e.includes(`[skill:`),detect:(e,t)=>{let n=[],r=t.skillNames;df.lastIndex=0;let i;for(;(i=df.exec(e))!==null;){let e=i[1];bf(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(uf.lastIndex=0;(i=uf.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)||bf(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:cf,href:yc(t),skillName:t}}},Sf={kind:`command`,priority:115,shouldScan:(e,t)=>e.includes(`[command:`)||!!t.commandNames?.size&&e.includes(`/`),detect:(e,t)=>{let n=[];ff.lastIndex=0;let r;for(;(r=ff.exec(e))!==null;){let e=r[1],t=gf(e);t&&bf(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(uf.lastIndex=0;(r=uf.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)||bf(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:cf})},Cf={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=V(e.slice(i+1,a)).trim(),s=_f(o),c=t.citationIcons?.get(s),l=!c&&lf.test(o),u=c??(l?`image`:null);if(!u){r=a+1;continue}let d=t.citationDisplayNames?.get(s)??o;bf(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:cf,filename:t}}},wf={kind:`session`,priority:105,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[];pf.lastIndex=0;let r;for(;(r=pf.exec(e))!==null;){let i=r[3],a=r.index+r[1].length,o=a+r[2].length,s=t.sessionTitles?.get(i)??i;bf(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=[`@${hf}${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&&bf(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:cf,sessionId:t}}},Tf={kind:`file`,priority:100,shouldScan:e=>e.includes(`@`),detect:(e,t)=>{let n=[],r=t.agentNames,i=t.filePaths,a=t.allowPathHeuristics===!0;mf.lastIndex=0;let o;for(;(o=mf.exec(e))!==null;){let t=o.index;if(!vf(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())){bf(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&&yf(s))&&bf(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:cf,href:Sc(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:cf,path:t}}},Ef=[xf,Sf,Cf,wf,Tf],Df=(e,t=Ef)=>{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`?Cf.decorate(e):e.kind===`agent`?Tf.decorate(e):{kind:e.kind,label:e.label,icon:null,className:cf}},Of=[`/`,`[`,`@`],kf=e=>{if(!e)return!1;for(let t of Of)if(e.includes(t))return!0;return!1},Af=(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)},jf=(e,t={},n=Ef)=>{if(!kf(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 Af(r,i)},Mf=(e,t,n=Ef)=>{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:Df(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}]},Nf=(e,t={},n=Ef)=>{if(!kf(e))return null;let r=jf(e,t,n);return r.length===0?null:Mf(e,r,n)},Pf=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,Ff=e=>e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`\\\\`),If=(e,t)=>!!t?.startsWith(`image/`)||Pf.test(e),Lf=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,If(e,i)?`image`:`attachment`)}return t},Rf=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=V(e.slice(r+1,i)).trim();Ff(a)&&Pf.test(a)&&t.push(a),n=i+1}return t},zf=(e,t)=>{let n=Lf(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&&If(e,typeof t.mime==`string`?t.mime:void 0)&&i.push(e)}if(i.length===0)return{icons:n,displayNames:r};let a=Rf(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}},Bf=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}},Vf=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=Bf(n),t[0]=n,t[1]=o);let s=o,c=s?.icon??n.icon,l=s?.label??n.label,u=s?`${s.trigger}${B}`:B,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:F,right:F},children:(0,$.jsx)(X,{name:c,className:Y(k,`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=hc(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:Hf,children:m}),t[24]=m,t[25]=r,t[26]=i):i=t[26],i}return m};Vf.displayName=`MessageReferenceChip`;function Hf(e){return e.stopPropagation()}var Uf=e=>e!==`frozen`,Wf=(e,t)=>e.length===0?t:t.length===0?e:[...e,...t],Gf=e=>e.status===`committed`&&e.current===!0,Kf=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}},qf=(e,t)=>{let n=e.status??`queued`;return!t&&(n===`queued`||n===`retrying`||n===`failed`||n===`unresolved`)},Jf=(e,t,n)=>_r(e)||t||e.manualDispatchRequested===!0&&!n?.allowManualDispatchRetry?!1:[`queued`,`retrying`,`failed`,`unresolved`].includes(e.status),Yf=(e,t)=>!t.frozen&&!_r(e),Xf=(e,t)=>!(t.frozen||_r(e)),Zf=e=>e.status===`sending`||e.status===`reconciling`,Qf=e=>e.status===`sending`||e.status===`reconciling`,$f=e=>e.manualDispatchRequested===!0||e.status===`sending`||e.status===`reconciling`,ep=e=>e.status===`sending`||e.status===`reconciling`,tp=8e3,np=(e,t)=>e.transportIdentity===t.transportIdentity&&e.runtimeGeneration===t.runtimeGeneration&&y(e.directory)===y(t.directory)&&e.sessionID===t.sessionID&&e.scopeID===t.scopeID,rp=(e,t)=>e.filter(e=>np(e,t)),ip=(e,t,n)=>e.filter(e=>np(e,t)&&Number.isSafeInteger(e.committedRevision)&&e.committedRevision>0&&(n===void 0||n<e.committedRevision)),ap=(e,t)=>{if(t.kind===`send`)return e;if(t.kind===`edit`||t.kind===`remove`){let n=e.findIndex(e=>!_r(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(_r(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},op=(e,t)=>t.reduce(ap,e),sp=(e,t)=>{let n=op(e,t),r=n.filter(e=>_r(e)||!ep(e));return r.length===n.length?n:r},cp=(e,t,n)=>({requestID:n,scopeID:e.scopeID,revision:e.revision,item:t}),lp=(e,t,n,r)=>({scopeID:e.scopeID,scopeRevision:e.revision,item:t,targetKey:n,expectedRevision:r}),up=(e,t,n,r,i=e.items)=>{let a=i.filter(e=>!_r(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}},dp=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},fp=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}Ne({source:n.source??`local`,vscodeSource:n.vscodeSource,mimeType:n.mimeType})&&t.set(r,`attachment`)}return t},pp=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},mp=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}},hp=e=>(e.split(`
|
|
6519
6519
|
`)[0]??``)+(e.includes(`
|
|
6520
|
-
`)?`...`:``),gp=(e,t={})=>{let n=hp(e);if(!n)return null;let r=mp(t.composerDocument);return Nf(n,{citationIcons:fp(t.attachments),sessionMentions:pp(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},_p=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`))},vp=(0,Z.memo)(e=>{let t=(0,Q.c)(132),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,sendPendingTimedOut:s,abortSendPending:c,isMobile:l,onEdit:u,onSend:d,onRemove:f}=e,{t:p}=ct(),m;t[0]===n?m=t[1]:(m=_r(n),t[0]=n,t[1]=m);let h=m,g=n.queueItemID||n.id,_;t[2]!==o||t[3]!==r?(_=r&&o.has(`edit`),t[2]=o,t[3]=r,t[4]=_):_=t[4];let v=_,y;t[5]!==o||t[6]!==r?(y=r&&o.has(`remove`),t[5]=o,t[6]=r,t[7]=y):y=t[7];let b=y,x;t[8]!==o||t[9]!==r?(x=r&&o.has(`reorder`),t[8]=o,t[9]=r,t[10]=x):x=t[10];let S=x,C=r||h?void 0:n,w;t[11]!==n||t[12]!==h||t[13]!==r?(w=r&&!h&&$f(n),t[11]=n,t[12]=h,t[13]=r,t[14]=w):w=t[14];let T=w,E;t[15]===C?E=t[16]:(E=C&&Qf(C),t[15]=C,t[16]=E);let D=!!E,O;t[17]!==n||t[18]!==h||t[19]!==r?(O=r&&!h&&Zf(n),t[17]=n,t[18]=h,t[19]=r,t[20]=O):O=t[20];let k=O,A;t[21]!==T||t[22]!==D||t[23]!==o||t[24]!==r?(A=r&&o.has(`send`)||T||D,t[21]=T,t[22]=D,t[23]=o,t[24]=r,t[25]=A):A=t[25];let j=c||A&&!s,M=i||h,N;t[26]!==i||t[27]!==n?(N=Yf(n,{frozen:i}),t[26]=i,t[27]=n,t[28]=N):N=t[28];let P=N,F;t[29]!==i||t[30]!==n?(F=Xf(n,{frozen:i}),t[29]=i,t[30]=n,t[31]=F):F=t[31];let I=F,L=C?.owner?.state===`unbound-legacy`||M||k,R;t[32]!==M||t[33]!==a||t[34]!==n||t[35]!==j||t[36]!==s||t[37]!==r?(R=!M&&!j&&(r?Jf(n,a,{allowManualDispatchRetry:s}):qf(n,a)),t[32]=M,t[33]=a,t[34]=n,t[35]=j,t[36]=s,t[37]=r,t[38]=R):R=t[38];let z=R,B=C?.failure?.recovery,V;t[39]===n?V=t[40]:(V=dp(n),t[39]=n,t[40]=V);let H=V,U=h?void 0:B?.attachments??n.attachments,W=B?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),ee;t[41]!==L||t[42]!==g?(ee={id:g,disabled:L},t[41]=L,t[42]=g,t[43]=ee):ee=t[43];let{attributes:G,listeners:K,setNodeRef:te,transform:ne,transition:re,isDragging:ie}=rc(ee),ae;t[44]===H?ae=t[45]:(ae=hp(H),t[44]=H,t[45]=ae);let oe=ae,se;t[46]!==U||t[47]!==W||t[48]!==H?(se=gp(H,{attachments:U,composerDocument:W}),t[46]=U,t[47]=W,t[48]=H,t[49]=se):se=t[49];let ce=se,le=h?n.attachmentCount:U?.length??0,ue;t[50]!==n||t[51]!==f?(ue=()=>f(n),t[50]=n,t[51]=f,t[52]=ue):ue=t[52];let de=!I,fe=b||void 0,pe=l?`h-7 w-3`:`size-7`,me;t[53]===pe?me=t[54]:(me=Y(`inline-flex shrink-0 items-center justify-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,pe),t[53]=pe,t[54]=me);let he;t[55]===p?he=t[56]:(he=p(`chat.queuedMessage.removeAria`),t[55]=p,t[56]=he);let ge=b?`loader-4`:`delete-bin`,_e=l?`size-3`:`size-3.5`,ve=b&&`animate-spin`,ye;t[57]!==_e||t[58]!==ve?(ye=Y(_e,ve),t[57]=_e,t[58]=ve,t[59]=ye):ye=t[59];let be;t[60]!==ge||t[61]!==ye?(be=(0,$.jsx)(X,{name:ge,className:ye,"aria-hidden":`true`}),t[60]=ge,t[61]=ye,t[62]=be):be=t[62];let xe;t[63]!==ue||t[64]!==de||t[65]!==fe||t[66]!==me||t[67]!==he||t[68]!==be?(xe=(0,$.jsx)(`button`,{type:`button`,onClick:ue,disabled:de,"aria-busy":fe,className:me,"aria-label":he,children:be}),t[63]=ue,t[64]=de,t[65]=fe,t[66]=me,t[67]=he,t[68]=be,t[69]=xe):xe=t[69];let Se=xe,Ce;t[70]===ne?Ce=t[71]:(Ce=ec.Translate.toString(ne),t[70]=ne,t[71]=Ce);let we;t[72]!==Ce||t[73]!==re?(we={transform:Ce,transition:re},t[72]=Ce,t[73]=re,t[74]=we):we=t[74];let Te=l?`gap-1 py-0.5`:`flex gap-1.5 md:gap-2`,Ee=ie&&`z-10 opacity-60`,De;t[75]!==Te||t[76]!==Ee?(De=Y(`flex min-w-0 items-center`,Te,Ee),t[75]=Te,t[76]=Ee,t[77]=De):De=t[77];let Oe=S||void 0,ke=l?`h-7 w-3`:`size-auto`,Ae=L?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,je;t[78]!==ke||t[79]!==Ae?(je=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,ke,`transition-colors`,Ae),t[78]=ke,t[79]=Ae,t[80]=je):je=t[80];let Me;t[81]===p?Me=t[82]:(Me=p(`chat.queuedMessage.reorderAria`),t[81]=p,t[82]=Me);let Ne=S?`loader-4`:`draggable`,Pe=l?`size-3`:`size-3.5`,Fe=S&&`animate-spin`,Ie;t[83]!==Pe||t[84]!==Fe?(Ie=Y(Pe,Fe),t[83]=Pe,t[84]=Fe,t[85]=Ie):Ie=t[85];let Le;t[86]!==Ne||t[87]!==Ie?(Le=(0,$.jsx)(X,{name:Ne,className:Ie,"aria-hidden":`true`}),t[86]=Ne,t[87]=Ie,t[88]=Le):Le=t[88];let Re;t[89]!==G||t[90]!==L||t[91]!==K||t[92]!==Oe||t[93]!==je||t[94]!==Me||t[95]!==Le?(Re=(0,$.jsx)(`button`,{type:`button`,...G,...K,disabled:L,"aria-busy":Oe,className:je,"aria-label":Me,children:Le}),t[89]=G,t[90]=L,t[91]=K,t[92]=Oe,t[93]=je,t[94]=Me,t[95]=Le,t[96]=Re):Re=t[96];let ze=l?Se:null,q=l?`text-xs leading-5`:`typography-ui-label leading-5`,Be;t[97]===q?Be=t[98]:(Be=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground`,q),t[97]=q,t[98]=Be);let Ve;t[99]!==oe||t[100]!==ce||t[101]!==p?(Ve=ce?ce.map(Dp):oe||p(`chat.queuedMessage.empty`),t[99]=oe,t[100]=ce,t[101]=p,t[102]=Ve):Ve=t[102];let He;t[103]!==le||t[104]!==p?(He=le>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:p(`chat.queuedMessage.attachments`,{count:le})}),t[103]=le,t[104]=p,t[105]=He):He=t[105];let Ue;t[106]!==Be||t[107]!==Ve||t[108]!==He?(Ue=(0,$.jsxs)(`span`,{className:Be,children:[Ve,He]}),t[106]=Be,t[107]=Ve,t[108]=He,t[109]=Ue):Ue=t[109];let We;t[110]!==P||t[111]!==z||t[112]!==v||t[113]!==l||t[114]!==n||t[115]!==u||t[116]!==d||t[117]!==h||t[118]!==j||t[119]!==p?(We=h?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.queuing`)})]}):j?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.sendingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.sending`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(n),disabled:!P,"aria-busy":v||void 0,"aria-label":p(`chat.queuedMessage.edit`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:v?`loader-4`:`edit`,className:Y(l?`size-3`:`size-3.5`,v&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{j||d(n)},disabled:!z||j,"aria-busy":j||void 0,"aria-label":p(`chat.queuedMessage.send`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`send-plane`,className:Y(l?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.send`)})]})]}),t[110]=P,t[111]=z,t[112]=v,t[113]=l,t[114]=n,t[115]=u,t[116]=d,t[117]=h,t[118]=j,t[119]=p,t[120]=We):We=t[120];let Ge=!l&&!h?Se:null,Ke;t[121]!==We||t[122]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[We,Ge]}),t[121]=We,t[122]=Ge,t[123]=Ke):Ke=t[123];let qe;return t[124]!==te||t[125]!==we||t[126]!==De||t[127]!==Re||t[128]!==ze||t[129]!==Ue||t[130]!==Ke?(qe=(0,$.jsxs)(`div`,{ref:te,style:we,className:De,children:[Re,ze,Ue,Ke]}),t[124]=te,t[125]=we,t[126]=De,t[127]=Re,t[128]=ze,t[129]=Ue,t[130]=Ke,t[131]=qe):qe=t[131],qe});vp.displayName=`QueuedMessageChip`;var yp=[],bp=[],xp=[],Sp=new Set,Cp=(e,t)=>t?Wf(_(e,v(t.sessionID)),_(e,t)):yp,wp=(e,t)=>{if(!t)return bp;let n=Cp(e,t),r=[...I(e,v(t.sessionID)),...I(e,t)];return r.length===0?n:[...n,...r]},Tp=(e,t)=>{let n=e.owner;return n?n.state===`unbound-legacy`?n.sessionID===t.sessionID?v(t.sessionID):null:p(n)===p(t)?t:null:null},Ep=(0,Z.memo)(e=>{let t=(0,Q.c)(152),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:s,clientPendingItems:c,onRemoveClientPending:l,trailing:u}=e,d=c===void 0?xp:c,{t:f}=ct(),m=q(Op),h=o?.transportIdentity??``,g=o?.directory??``,_=o?.sessionID??``,v;t[0]!==h||t[1]!==g||t[2]!==_?(v={transportIdentity:h,directory:g,sessionID:_},t[0]=h,t[1]=g,t[2]=_,t[3]=v):v=t[3];let y=Ju(v),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 C=o?.transportIdentity??``,w=o?.runtimeGeneration??-1,T;t[5]!==C||t[6]!==w?(T=[C,`messageQueue`,`scopeMutation`,w],t[5]=C,t[6]=w,t[7]=T):T=t[7];let E=T,D;t[8]===y.actions?D=t[9]:(D=e=>Xn(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=y.actions.captureRuntime();if(t.transportIdentity!==e.runtime.transportIdentity||t.generation!==e.runtime.generation)return Promise.resolve({status:`stale`});switch(e.kind){case`edit`:return y.actions.editIntoDraft(e.input);case`send`:return y.actions.manualSend(e.input);case`remove`:return y.actions.remove(e.input);case`reorder`:return y.actions.reorder(e.input)}throw Error(`Unsupported server queue operation`)}),t[8]=y.actions,t[9]=D);let O,k;t[10]!==y.actions||t[11]!==f?(O=(e,t)=>{let n=y.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&e.status!==`stale`&&t.kind===`edit`&&e.status!==`committed`&&Br.error(f(`chat.chatInput.toast.queueOperationFailed`))},k=(e,t)=>{let n=y.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&Br.error(f(e instanceof Dt&&e.code===`unavailable`?`chat.chatInput.toast.queueOperationStatusUnknown`:`chat.chatInput.toast.queueOperationFailed`))},t[10]=y.actions,t[11]=f,t[12]=O,t[13]=k):(O=t[12],k=t[13]);let A;t[14]!==E||t[15]!==D||t[16]!==O||t[17]!==k?(A={mutationKey:E,mutationFn:D,onSuccess:O,onError:k},t[14]=E,t[15]=D,t[16]=O,t[17]=k,t[18]=A):A=t[18];let j=Ke(A),M;t[19]===E?M=t[20]:(M={filters:{mutationKey:E,exact:!0,status:`pending`},select:kp},t[19]=E,t[20]=M);let P=Ge(M),F;t[21]===E?F=t[22]:(F={filters:{mutationKey:E,exact:!0,status:`success`},select:Ap},t[21]=E,t[22]=F);let I=Ge(F),L;bb0:{if(!o||!y.scope){L=null;break bb0}let e=o.runtimeGeneration??y.runtimeCapture.generation,n;t[23]!==o.directory||t[24]!==o.sessionID||t[25]!==o.transportIdentity||t[26]!==y.scope.scopeID||t[27]!==e?(n={transportIdentity:o.transportIdentity,directory:o.directory,sessionID:o.sessionID,scopeID:y.scope.scopeID,runtimeGeneration:e},t[23]=o.directory,t[24]=o.sessionID,t[25]=o.transportIdentity,t[26]=y.scope.scopeID,t[27]=e,t[28]=n):n=t[28],L=n}let R=L,z;bb1:{if(!R){let e;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[29]=e):e=t[29],z=e;break bb1}let e;if(t[30]!==R||t[31]!==P){let n;t[33]===R?n=t[34]:(n=e=>_p(e)&&e.scopeID===R.scopeID,t[33]=R,t[34]=n),e=rp(P.filter(n),R),t[30]=R,t[31]=P,t[32]=e}else e=t[32];z=e}let B=z,V;t[35]!==R||t[36]!==y.scope?.revision||t[37]!==I?(V=()=>R?ip(I.filter(jp),R,y.scope?.revision):[],t[35]=R,t[36]=y.scope?.revision,t[37]=I,t[38]=V):V=t[38],y.scope?.revision;let H;t[39]===V?H=t[40]:(H=V(),t[39]=V,t[40]=H);let U=H,W;t[41]!==U||t[42]!==B?(W=[...B,...U],t[41]=U,t[42]=B,t[43]=W):W=t[43];let ee=W,G;t[44]===o?G=t[45]:(G=e=>wp(e,o),t[44]=o,t[45]=G);let K=b(G);Z.useSyncExternalStore(Kt,dn,dn);let te;t[46]!==ee||t[47]!==K||t[48]!==y.items||t[49]!==y.mode?(te=y.mode===`server`?sp(y.items,ee):K,t[46]=ee,t[47]=K,t[48]=y.items,t[49]=y.mode,t[50]=te):te=t[50];let ne=te,re;t[51]!==ne||t[52]!==d?(re=d.length===0?ne:[...ne,...d],t[51]=ne,t[52]=d,t[53]=re):re=t[53];let ie=re,ae;t[54]!==o?.sessionID||t[55]!==ie?(ae=()=>{let e=o?.sessionID,t=new Set;if(!e)return t;for(let n of ie){let r=n.queueItemID||n.id;r&&bn(e,r)&&t.add(r)}return t},t[54]=o?.sessionID,t[55]=ie,t[56]=ae):ae=t[56],o?.sessionID;let oe;t[57]===ae?oe=t[58]:(oe=ae(),t[57]=ae,t[58]=oe);let se=oe,ce;if(t[59]!==ee){ce=new Map;for(let e of ee){let t=ce.get(e.queueItemID)??new Set;t.add(e.kind),ce.set(e.queueItemID,t)}t[59]=ee,t[60]=ce}else ce=t[60];let le=ce,ue;if(t[61]!==ee||t[62]!==ie||t[63]!==y.mode){bb2:{let e=new Set;if(y.mode===`server`){for(let t of ee)t.kind===`send`&&e.add(t.queueItemID);for(let t of ie){if(_r(t))continue;let n=t.queueItemID;n&&$f(t)&&e.add(n)}ue=e;break bb2}for(let t of ie){if(_r(t))continue;let n=t;Qf(n)&&e.add(n.queueItemID||n.id)}ue=e}t[61]=ee,t[62]=ie,t[63]=y.mode,t[64]=ue}else ue=t[64];let de=ue,[fe,pe]=Z.useState(Mp),me;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(me=new Map,t[65]=me):me=t[65];let he=Z.useRef(me),ge,_e;t[66]!==de||t[67]!==fe?(ge=()=>{let e=he.current,t=Date.now();for(let t of[...e.keys()])de.has(t)||e.delete(t);pe(e=>{let t=!1,n=new Set;for(let r of e)de.has(r)?n.add(r):t=!0;return t?n:e});let n=[];for(let r of de){if(e.has(r)||(e.set(r,t),pe(e=>{if(!e.has(r))return e;let t=new Set(e);return t.delete(r),t})),fe.has(r))continue;let i=tp-(t-(e.get(r)??t));if(i<=0){pe(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t});continue}n.push(setTimeout(()=>{he.current.has(r)&&pe(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t})},i))}return()=>{for(let e of n)clearTimeout(e)}},_e=[de,fe],t[66]=de,t[67]=fe,t[68]=ge,t[69]=_e):(ge=t[68],_e=t[69]),Z.useEffect(ge,_e);let ve;t[70]===y.mode?ve=t[71]:(ve=Uf(y.mode),t[70]=y.mode,t[71]=ve);let ye=!ve,be=Ht(o),xe;t[72]!==be||t[73]!==ie||t[74]!==y.mode?(xe=y.mode===`server`?!1:be||ie.some(Np),t[72]=be,t[73]=ie,t[74]=y.mode,t[75]=xe):xe=t[75];let Se=xe,Ce=b(Pp),we;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(we={activationConstraint:{distance:8}},t[76]=we):we=t[76];let Te;t[77]===Symbol.for(`react.memo_cache_sentinel`)?(Te={activationConstraint:{delay:200,tolerance:6}},t[77]=Te):Te=t[77];let Ee=$s(Ks(Zs,we),Ks(Js,Te)),De;t[78]!==ye||t[79]!==o||t[80]!==ie||t[81]!==Ce||t[82]!==j||t[83]!==y.actions||t[84]!==y.mode||t[85]!==y.scope?(De=e=>{if(ye)return;let{active:t,over:n}=e;if(!n||t.id===n.id)return;if(y.mode===`server`){if(!o||!y.scope)return;let e=ie,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||_r(r)||_r(i)||Zf(r)||Zf(i))return;let a=y.scope,s=y.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=N(),l=up(a,String(t.id),String(n.id),c,e);if(!l)return;j.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(Fp);return}let r=ie.filter(Ip),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=Tp(i,o),c=Tp(a,o);!s||!c||p(s)!==p(c)||Ce(s,String(t.id),String(n.id),i.operationID)},t[78]=ye,t[79]=o,t[80]=ie,t[81]=Ce,t[82]=j,t[83]=y.actions,t[84]=y.mode,t[85]=y.scope,t[86]=De):De=t[86];let Oe=J(De),ke;t[87]!==a||t[88]!==s||t[89]!==ye||t[90]!==i||t[91]!==n||t[92]!==o||t[93]!==j||t[94]!==y.actions||t[95]!==y.mode||t[96]!==y.scope?(ke=e=>{if(ye||_r(e))return;if(y.mode===`server`){if(!o||!y.scope||!a||!s)return;let t=e,n=s.expectedRevision(),r=y.scope,c=y.actions.captureRuntime();if(c.transportIdentity!==o.transportIdentity||c.generation!==o.runtimeGeneration)return;j.mutateAsync({kind:`edit`,transportIdentity:c.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:N(),runtime:c,runtimeGeneration:c.generation,input:lp(r,t,s.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(Lp);return}if(!o)return;let t=e,r=Tp(t,o);if(!r)return;let c=t.queueItemID??t.id,l=t.operationID,u=Kf(t);(async()=>{let e;try{e=await Promise.resolve(n(u.content,u.attachments,u.composerDocument,u.composerMentions))}catch{e=!1}e&&(i?.(),b.getState().removeFromQueue(r,c,l))})()},t[87]=a,t[88]=s,t[89]=ye,t[90]=i,t[91]=n,t[92]=o,t[93]=j,t[94]=y.actions,t[95]=y.mode,t[96]=y.scope,t[97]=ke):ke=t[97];let Ae=J(ke),je;t[98]!==ye||t[99]!==r||t[100]!==o||t[101]!==j||t[102]!==y.actions||t[103]!==y.mode||t[104]!==y.scope?(je=e=>{if(ye||_r(e))return;if(y.mode===`server`){if(!o||!y.scope)return;let t=e,n=y.scope,r=y.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=t.queueItemID;he.current.delete(i),pe(e=>{if(!e.has(i))return e;let t=new Set(e);return t.delete(i),t});let a=N();j.mutateAsync({kind:`send`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:a,runtime:r,runtimeGeneration:r.generation,input:cp(n,t,a)}).catch(Rp);return}if(!o)return;let t=e;if(!Tp(t,o))return;let n=t.queueItemID??t.id;he.current.delete(n),pe(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t}),r(n)},t[98]=ye,t[99]=r,t[100]=o,t[101]=j,t[102]=y.actions,t[103]=y.mode,t[104]=y.scope,t[105]=je):je=t[105];let Me=J(je),Ne;t[106]!==d||t[107]!==ye||t[108]!==l||t[109]!==o||t[110]!==j||t[111]!==y.actions||t[112]!==y.mode||t[113]!==y.scope?(Ne=e=>{if(_r(e)){d.some(t=>t.requestID===e.requestID)&&l?.(e.requestID);return}if(ye)return;if(y.mode===`server`){if(!o||!y.scope)return;let t=e,n=y.scope,r=y.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=N();j.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:cp(n,t,i)}).catch(zp);return}if(!o)return;let t=e,n=Tp(t,o);n&&b.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[106]=d,t[107]=ye,t[108]=l,t[109]=o,t[110]=j,t[111]=y.actions,t[112]=y.mode,t[113]=y.scope,t[114]=Ne):Ne=t[114];let Pe=J(Ne),Fe=ie.length>0&&(o||d.length>0);if(!Fe&&!u)return null;let Ie=m?`px-2`:`px-4`,Le;t[115]===Ie?Le=t[116]:(Le=Y(`oc-composer-queue relative z-0 -mb-5 w-full`,Ie),t[115]=Ie,t[116]=Le);let Re=m?`rounded-[1.25rem]`:`rounded-3xl`,ze;t[117]===Re?ze=t[118]:(ze=Y(`overflow-hidden border border-border/60 bg-[var(--surface-subtle)] text-foreground`,Re),t[117]=Re,t[118]=ze);let Be=m?`px-1.5 py-1`:`gap-0.5 px-3 pb-1 pt-1.5`,Ve;t[119]===Be?Ve=t[120]:(Ve=Y(`flex flex-col`,Be),t[119]=Be,t[120]=Ve);let He;t[121]!==se||t[122]!==ye||t[123]!==Oe||t[124]!==Ae||t[125]!==Pe||t[126]!==Me||t[127]!==Se||t[128]!==Fe||t[129]!==m||t[130]!==le||t[131]!==ie||t[132]!==fe||t[133]!==Ee||t[134]!==y.mode?(He=Fe?(0,$.jsx)(Qs,{sensors:Ee,collisionDetection:Xs,onDragEnd:Oe,children:(0,$.jsx)(ac,{items:ie.map(Bp),strategy:ic,children:ie.map(e=>{let t=e.queueItemID||e.id;return(0,$.jsx)(vp,{message:e,server:y.mode===`server`,frozen:ye,hasDispatchLock:Se,pendingOperationKinds:le.get(t)??Sp,sendPendingTimedOut:fe.has(t),abortSendPending:se.has(t),isMobile:m,onEdit:Ae,onSend:Me,onRemove:Pe},t)})})}):null,t[121]=se,t[122]=ye,t[123]=Oe,t[124]=Ae,t[125]=Pe,t[126]=Me,t[127]=Se,t[128]=Fe,t[129]=m,t[130]=le,t[131]=ie,t[132]=fe,t[133]=Ee,t[134]=y.mode,t[135]=He):He=t[135];let Ue;t[136]!==Fe||t[137]!==u?(Ue=u?(0,$.jsxs)($.Fragment,{children:[Fe?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,u]}):null,t[136]=Fe,t[137]=u,t[138]=Ue):Ue=t[138];let We;t[139]!==Ve||t[140]!==He||t[141]!==Ue?(We=(0,$.jsxs)(`div`,{"data-oc-queue-card-body":``,className:Ve,children:[He,Ue]}),t[139]=Ve,t[140]=He,t[141]=Ue,t[142]=We):We=t[142];let qe=m?`h-4`:`h-5`,Je;t[143]===qe?Je=t[144]:(Je=(0,$.jsx)(`div`,{"data-oc-queue-composer-overlap":``,"aria-hidden":`true`,className:qe}),t[143]=qe,t[144]=Je);let Ye;t[145]!==ze||t[146]!==We||t[147]!==Je?(Ye=(0,$.jsxs)(`div`,{"data-oc-queue-card":``,className:ze,children:[We,Je]}),t[145]=ze,t[146]=We,t[147]=Je,t[148]=Ye):Ye=t[148];let Xe;return t[149]!==Le||t[150]!==Ye?(Xe=(0,$.jsx)(`div`,{className:Le,children:Ye}),t[149]=Le,t[150]=Ye,t[151]=Xe):Xe=t[151],Xe});Ep.displayName=`QueuedMessageChips`;function Dp(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(Vf,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Op(e){return e.isMobile}function kp(e){return e.state.variables}function Ap(e){let t=e.state.variables;if(!_p(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 jp(e){return e!==void 0}function Mp(){return new Set}function Np(e){return!_r(e)&&(e.status===`sending`||e.status===`reconciling`)}function Pp(e){return e.reorderQueue}function Fp(){}function Ip(e){return!_r(e)}function Lp(){}function Rp(){}function zp(){}function Bp(e){return e.queueItemID||e.id}var Vp=[0,200,400],Hp=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=Vp.map(Up),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 Up(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var Wp=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=ct(),n=ri(Gp),r;e[0]===n?r=e[1]:(r=e=>{if(!n)return null;let t=e.runsByOriginalSessionID[n]??null;return t?.runtimeKey===a()?t:null},e[0]=n,e[1]=r);let i=Wt(r),o=Wt(Kp),s=q(qp),c=q(Jp);if(!n||!i||i.status!==`running`)return null;let l;e[2]!==i.phase||e[3]!==t?(l=i.phase===`waiting_for_reviewer`?t(`chat.autoReview.status.waitingForReviewer`):t(`chat.autoReview.status.waitingForImplementer`),e[2]=i.phase,e[3]=t,e[4]=l):l=e[4];let u=l,d;e[5]!==s||e[6]!==i.directory||e[7]!==i.reviewSessionID||e[8]!==t?(d=()=>{s(i.directory,{mode:`chat`,dedupeKey:`session:${i.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=s,e[6]=i.directory,e[7]=i.reviewSessionID,e[8]=t,e[9]=d):d=e[9];let f=d,p=c?`pb-1 text-xs`:`pb-2`,m;e[10]===p?m=e[11]:(m=Y(`w-full px-1`,p),e[10]=p,e[11]=m);let h=c?`rounded-lg`:`rounded-xl`,g;e[12]===h?g=e[13]:(g=Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,h),e[12]=h,e[13]=g);let _=c?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`,v;e[14]===_?v=e[15]:(v=Y(`flex w-full items-center text-left`,_),e[14]=_,e[15]=v);let y=c?`size-3.5`:`size-4`,b;e[16]===y?b=e[17]:(b=Y(`animate-spin text-muted-foreground`,y),e[16]=y,e[17]=b);let x;e[18]===b?x=e[19]:(x=(0,$.jsx)(X,{name:`loader-4`,className:b,"aria-hidden":`true`}),e[18]=b,e[19]=x);let S;e[20]===t?S=e[21]:(S=t(`chat.autoReview.title`),e[20]=t,e[21]=S);let C;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Hp,{}),e[22]=C):C=e[22];let w;e[23]===S?w=e[24]:(w=(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:[S,C]}),e[23]=S,e[24]=w);let T;e[25]===u?T=e[26]:(T=(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:u}),e[25]=u,e[26]=T);let E;e[27]!==w||e[28]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[w,T]}),e[27]=w,e[28]=T,e[29]=E):E=e[29];let D;e[30]===t?D=e[31]:(D=t(`chat.autoReview.actions.open`),e[30]=t,e[31]=D);let O;e[32]!==f||e[33]!==D?(O=(0,$.jsx)(ua,{type:`button`,variant:`secondary`,size:`xs`,onClick:f,children:D}),e[32]=f,e[33]=D,e[34]=O):O=e[34];let k;e[35]!==n||e[36]!==o?(k=()=>o(n),e[35]=n,e[36]=o,e[37]=k):k=e[37];let A;e[38]===t?A=e[39]:(A=t(`chat.autoReview.actions.stop`),e[38]=t,e[39]=A);let j;e[40]!==k||e[41]!==A?(j=(0,$.jsx)(ua,{type:`button`,variant:`secondary`,size:`xs`,onClick:k,children:A}),e[40]=k,e[41]=A,e[42]=j):j=e[42];let M;e[43]!==x||e[44]!==E||e[45]!==O||e[46]!==j||e[47]!==v?(M=(0,$.jsxs)(`div`,{className:v,children:[x,E,O,j]}),e[43]=x,e[44]=E,e[45]=O,e[46]=j,e[47]=v,e[48]=M):M=e[48];let N;e[49]!==M||e[50]!==g?(N=(0,$.jsx)(`div`,{className:g,children:M}),e[49]=M,e[50]=g,e[51]=N):N=e[51];let P;return e[52]!==N||e[53]!==m?(P=(0,$.jsx)(`div`,{className:m,children:N}),e[52]=N,e[53]=m,e[54]=P):P=e[54],P});Wp.displayName=`AutoReviewBanner`;function Gp(e){return e.currentSessionId}function Kp(e){return e.stopRun}function qp(e){return e.openContextPanelTab}function Jp(e){return e.isMobile}var Yp=Z.forwardRef(({searchQuery:e,onSkillSelect:t,onClose:n,directory:r,style:i,onRowsChange:a},o)=>{let s=Z.useRef(null),c=q(e=>e.isMobile),[l,u]=Z.useState(0),d=Z.useRef(0),f=Z.useRef(!1),[p,m]=Z.useState([]),h=Z.useRef([]),g=Z.useRef(null),_=Ei({directory:r}),v=Z.useMemo(()=>_.data??[],[_.data]);Z.useEffect(()=>{m(_l(v,e)),u(0)},[v,e]),Z.useEffect(()=>{d.current=l},[l]),Z.useEffect(()=>{h.current[l]?.scrollIntoView({block:`nearest`})},[l]),Z.useEffect(()=>{let e=e=>{let t=e.target;!t||!s.current||s.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),Z.useEffect(()=>{zo(a,g,{rows:Ro(p),highlightedIndex:l})},[p,a,l]);let y=Z.useRef(a);y.current=a,Z.useEffect(()=>()=>{Bo(y.current,g)},[]),Z.useImperativeHandle(o,()=>({acceptIndex:e=>{let n=p[e];n&&t(n)},handleKeyDown:e=>{if(e===`Escape`){n();return}if(p.length){if(e===`ArrowDown`){f.current=!0,u(e=>(e+1)%p.length);return}if(e===`ArrowUp`){f.current=!0,u(e=>(e-1+p.length)%p.length);return}if(e===`Enter`||e===`Tab`){let e=(d.current%p.length+p.length)%p.length,n=p[e];n&&t(n)}}}}),[p,t,n]);let b=(e,n)=>{let r=e.scope===`project`,i=e.source||`opencode`;return(0,$.jsx)(`div`,{ref:e=>{h.current[n]=e},className:Y(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,c?`items-center`:`items-start`,es(c,n===l)),onClick:()=>t(e),onMouseMove:()=>{f.current=!1,u(n)},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`,r?`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:i})]}),e.description&&!c&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:e.description})]})},`${e.name}-${e.scope}`)};return(0,$.jsxs)(Mo,{ref:s,isMobile:c,className:`max-w-[450px] max-h-60`,style:i,children:[(0,$.jsx)(pa,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:p.length?(0,$.jsx)(`div`,{children:p.map((e,t)=>b(e,t))}):(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:`No skills found`})}),!c&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:`↑↓ navigate • Enter select • Esc close`})]})});Yp.displayName=`SkillAutocomplete`;function Xp(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 Zp(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(Qp).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)(Xp,{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 Qp(e){return e.trim()}var $p=`mobile-overlay-root`,em=16,tm=200,nm=[],rm=0,im=``,am=0,om=()=>{if(typeof document>`u`)return null;let e=document.getElementById($p);return e||(e=document.createElement(`div`),e.id=$p,document.body.appendChild(e)),e},sm=({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=om()),Z.useEffect(()=>{if(!e){m(!1),g(!1);return}let t=window.setTimeout(()=>m(!0),em),n=window.setTimeout(()=>g(!0),266);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[e]),Z.useLayoutEffect(()=>{if(e)return am===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-opened`)),am+=1,()=>{am=Math.max(0,am-1),am===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-closed`))}},[e]),Z.useEffect(()=>{if(!e)return;let t=d.current;nm.push(t),rm===0&&(im=document.body.style.overflow),rm+=1,document.body.style.overflow=`hidden`;let n=e=>{e.key===`Escape`&&nm[nm.length-1]===t&&f.current()};return document.addEventListener(`keydown`,n),()=>{let e=nm.lastIndexOf(t);e>=0&&nm.splice(e,1),rm=Math.max(0,rm-1),rm===0&&(document.body.style.overflow=im),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:ha,onClick:e=>{ga(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 ${tm}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)(pa,{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,rl.createPortal)(v,u.current)},cm=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,lm=1e3,um=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)(la,{name:n,size:a,label:l}),t[2]=a,t[3]=n,t[4]=l,t[5]=u):u=t[5];let d;t[6]!==c||t[7]!==u?(d=(0,$.jsx)(`span`,{className:c,children:u}),t[6]=c,t[7]=u,t[8]=d):d=t[8];let f=i?`grid-cols-[1fr] opacity-100`:`grid-cols-[0fr] opacity-0`,p;t[9]===f?p=t[10]:(p=Y(`grid min-w-0 items-center ease-in-out`,f),t[9]=f,t[10]=p);let m;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m={transitionProperty:`grid-template-columns, opacity`,transitionDuration:`280ms`,transitionTimingFunction:`ease-in-out`},t[11]=m):m=t[11];let h=!i,g;t[12]===s?g=t[13]:(g=s?{color:`var(${s})`}:void 0,t[12]=s,t[13]=g);let _;t[14]!==r||t[15]!==g?(_=(0,$.jsx)(`span`,{className:`flex min-w-0 items-center overflow-hidden`,children:(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap pl-1.5 pr-0.5 typography-micro leading-none font-medium`,style:g,children:r})}),t[14]=r,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==_||t[18]!==p||t[19]!==h?(v=(0,$.jsx)(`span`,{className:p,style:m,"aria-hidden":h,children:_}),t[17]=_,t[18]=p,t[19]=h,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==d?(y=(0,$.jsxs)($.Fragment,{children:[d,v]}),t[21]=v,t[22]=d,t[23]=y):y=t[23],y};function dm(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},lm),()=>{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 fm=`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,pm=e=>`flow-root ${e?`py-1`:`py-1.5`}`,mm=`${fm} hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,hm=`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)]`,gm=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${hm}`,_m=`rounded-md ${hm}`,vm=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},ym=e=>{if(e)try{let t=vm();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},bm=(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`},xm=e=>{let t=ym(e);return t?bm(t.permission,`edit`):`ask`},Sm=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},Cm=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return Sm(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:Sm(n.tokens)},wm=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}},Tm=(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}},Em=[`ask`,`allow`,`full`],Dm=`__global__`,Om=ce()(ue(le((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=Tm(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=Cm(d);if(h===0)return m||null;let g=Tm(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=Cm(o);if(s===0)return;let c=Tm(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`&&Cm(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=xm(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Dm){let e=t().sessionAgentEditModes.get(Dm)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=xm(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Em.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=xm(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Em.indexOf(a),s=Em.indexOf(i),c=Em[((o>=0?o:s>=0?s:0)+1)%Em.length];t().setSessionAgentEditMode(e,n,c,i)}}),{name:`context-store`,storage:Be(),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`})),km=e=>Qt([...e??[]]),Am=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,jm=(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],Am(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 Mm(e,t){return!e&&t===`trigger-hover`}var Nm=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},Pm=e=>{let t=Nm(e);return t?(t.focus({preventScroll:!0}),!0):!1},Fm=(e,t)=>e&&!t,Im=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):[]:[]},Lm=(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 Im(i)},Rm=()=>!0,zm=(e,t)=>(e.commandPolicy??Rm)(t),Bm=Z.createContext(null),Vm=()=>Z.useContext(Bm),Hm=e=>e,Um=(e,t)=>t??e,Wm=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`)},Gm=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,Km=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},qm=(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}},Jm=(e,t)=>`${e}:${t}`,Ym=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,Xm=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},Zm=(e,t)=>{let n=Xm(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}}},Qm=[{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}],$m={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`}},eh=e=>e.trim().toLowerCase(),th=(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=>eh(e)))),i=[];for(let e of r){let t=$m[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},nh=e=>new Intl.NumberFormat(lt(),{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:1,minimumFractionDigits:0}).format(e),rh=e=>new Intl.NumberFormat(lt(),{style:`currency`,currency:`USD`,maximumFractionDigits:4,minimumFractionDigits:2}).format(e),ih=e=>new Intl.DateTimeFormat(lt(),{month:`short`,day:`numeric`,year:`numeric`}).format(e),ah=`__add_provider__`,oh=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},sh=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=cm(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},ch=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=nh(e);return t.endsWith(`.0`)?t.slice(0,-2):t},lh=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:rh(e),uh=e=>{let t=[];for(let n of Qm)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},dh=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:ih(t)},fh=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=ct(),o=Z.useId(),{isReady:s,isUnavailable:c}=no(),l=c||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),u=Ai(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),d=Ai(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=i?.catalog,p=s&&(f?.ready??!u)&&!f?.loading&&!f?.error&&!i?.disabled,m=s&&(f?.ready??!d)&&!f?.loading&&!f?.error&&!i?.disabled,h=p&&m,g=Ai(e=>e.providers),_=f?.providers??g,v=Ai(e=>e.currentProviderId),y=Ai(e=>e.currentModelId),b=i?.selection.providerID??v,x=i?.selection.modelID??y,S=Ai(e=>e.currentVariant),C=i?i.selection.variant:S,w=Ai(e=>e.currentAgentName),T=i?i.selection.agent??void 0:w,E=Ai(e=>e.settingsDefaultVariant),D=Ai(e=>e.settingsDefaultAgent),O=Ai(e=>e.setProvider),k=Ai(e=>e.setSelectedProvider),A=Ai(e=>e.setModel),j=Ai(e=>e.setCurrentVariant),M=Ai(e=>e.getCurrentModelVariants),N=Ai(e=>e.setAgent),P=Ai(e=>e.getCurrentProvider),F=Ai(e=>e.getModelMetadata),I=Ai(e=>e.getCurrentAgent),L=Ai(e=>e.getVisibleAgents),R=km(f?.agents??L()),z=Z.useMemo(()=>R.filter(e=>e.mode===`primary`),[R]),B=Z.useRef(!1);Z.useEffect(()=>{B.current||!h||(B.current=!0,Oe(`ModelControls:ready`,{providers:_.length,agents:R.length,currentProviderId:b,currentModelId:x,currentAgentName:T}))},[R.length,h,T,x,b,_.length]);let V=ri(e=>i?null:e.currentSessionId),H=ri(e=>e.getDirectoryForSession),U=ku(),W=Zi(e=>e.getSessionModelSelection),ee=Zi(e=>e.saveSessionModelSelection),G=Zi(e=>e.saveSessionAgentSelection),K=Zi(e=>e.saveAgentModelForSession),te=Zi(e=>e.getAgentModelForSession),ne=Zi(e=>e.saveAgentModelVariantForSession),re=Zi(e=>e.getAgentModelVariantForSession),ie=Om(e=>e.hasHydrated),ae=Zi(e=>V?e.sessionAgentSelections.get(V)??null:null),oe=Z.useRef(null);Z.useEffect(()=>{if(!V){oe.current=null;return}ae&&(oe.current=ae)},[V,ae]);let se=V?oe.current:null,ce=i?i.selection.agent??void 0:V&&(ae||se)||T,le=q(e=>e.toggleFavoriteModel),ue=q(e=>e.reorderFavoriteModel),de=q(e=>e.providerOrder),fe=q(e=>e.setProviderOrder),pe=q(e=>e.isFavoriteModel),me=q(e=>e.addRecentModel),he=q(e=>e.addRecentAgent),ge=q(e=>e.addRecentEffort),_e=q(e=>e.isModelSelectorOpen),ve=q(e=>e.setModelSelectorOpen),ye=q(e=>e.isAgentSelectorOpen),be=q(e=>e.setAgentSelectorOpen),xe=q(e=>e.isModelSelectorInstant),Se=q(e=>e.isAgentSelectorInstant),Ce=q(e=>e.setSettingsDialogOpen),we=q(e=>e.setSettingsPage),Te=q(e=>e.hiddenModels),Ee=q(e=>e.shortcutOverrides.cycle_agent),De=Z.useMemo(()=>Qa(`cycle_agent`,Ee?{cycle_agent:Ee}:void 0),[Ee]),{favoriteModelsList:ke,recentModelsList:Ae}=va({currentProviderID:b,currentModelID:x}),{isMobile:je}=mo(),Me=q(e=>e.isMobile),Ne=je||Me,Pe=jo(),Fe=Ne,[Ie,Le]=Z.useState(null),Re=n!==void 0&&typeof r==`function`,ze=Re?n:Ie,Be=Re?r:Le,Ve=J(e=>{Be(e),Ai.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),He=J((e,t)=>{if(Mm(e,t?.reason)){t?.cancel?.();return}be(e),e&&Ai.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopAgentMenu`})}),[Ue,We]=Z.useState(null),Ge=Z.useRef(!1),Ke=Z.useCallback(()=>Be(null),[Be]),qe=Z.useCallback(()=>We(null),[]),Je=Z.useRef(void 0),Ye=_e,Xe=ve,Ze=Z.useCallback(()=>{k(ah),we(`providers`),Ce(!0),Xe(!1),Ke()},[k,we,Ce,Xe,Ke]),[Qe,$e]=Z.useState(``),[et,tt]=Z.useState(null),[nt,rt]=Z.useState(!1),it=Z.useRef(0),at=J((e,t)=>{if(Mm(e,t?.reason)){t?.cancel?.();return}rt(!1),e||(it.current=performance.now()+200,tt(null),$e(``)),Xe(e),e&&Ai.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),ot=Z.useRef(!1),st=Z.useRef(null),lt=Z.useRef(void 0),[ut,dt]=Z.useState(new Map),[ft,pt]=Z.useState(new Set),[mt,ht]=Z.useState(0),gt=Z.useCallback(()=>{let e=()=>{let e=q.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&Pm(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),_t=Z.useCallback(e=>{let t=q.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(q.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!q.getState().isMobile&>())},[gt]),vt=Z.useCallback(()=>{let e=q.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Nm(t)},[t]),yt=Z.useRef(_e);Z.useEffect(()=>{let e=yt.current;yt.current=_e,_e||($e(``),ot.current=!1,st.current=null,dt(new Map),pt(new Set),e&&!Fe&&(rt(!1),it.current=performance.now()+200))},[_e,Fe]);let[bt,St]=Z.useState(``);Z.useEffect(()=>{ye||St(``)},[ye]);let Ct=Z.useMemo(()=>R.filter(e=>qn(e.mode)),[R]),wt=Z.useMemo(()=>bt.trim()?bi(Ct,bt.trim(),e=>[e.name,e.description??``]).map(e=>e.item):[...Ct].sort((e,t)=>e.name.localeCompare(t.name)),[Ct,bt]),Tt=Z.useMemo(()=>{if(D){let e=Ct.find(e=>e.name===D);if(e)return e.name}let e=Ct.find(e=>e.name===`build`);return e?e.name:Ct[0]?.name},[D,Ct]),Et=Z.useMemo(()=>ce?R.find(e=>e.name===ce):I?.(),[R,I,ce]),Dt=Ne?`mobile`:Pe?`vscode`:`default`,Ot=Dt===`mobile`?`size-5`:`size-4`,kt=Fe?`typography-micro`:`typography-meta`,At=Dt===`mobile`?`gap-x-1`:Dt===`vscode`?`gap-x-2`:`gap-x-1.5`,jt=Dt===`mobile`?`h-8 w-8`:Dt===`vscode`?`h-5 w-5`:`h-6 w-6`,Mt=Dt===`mobile`?18:Dt===`vscode`?14:16,Nt=dm(ce),Pt=i?_.find(e=>e.id===b):P(),Ft=Array.isArray(Pt?.models)?Pt.models:[],It=x?Ft.find(e=>e.id===x):void 0,Lt=b&&x&&It?xa(b,It,F(b,x)):b&&x?F(b,x):void 0,Rt=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]),zt=Z.useMemo(()=>uh(Lt).map(e=>({...e,label:Rt(e.label)})),[Lt,Rt]),Vt=Z.useMemo(()=>th(Lt,`input`).map(e=>({...e,label:Rt(e.label)})),[Lt,Rt]),Ht=Z.useMemo(()=>th(Lt,`output`).map(e=>({...e,label:Rt(e.label)})),[Lt,Rt]),Wt=Z.useMemo(()=>{if(f?.variantsReady===!1)return[];if(f?.variants)return[...f.variants];if(b&&x){let e=_.find(e=>e.id===b)?.models?.find(e=>e.id===x);return Im(e)}return i?[]:M()},[x,b,M,_,i,f?.variants,f?.variantsReady]),Gt=Wt.length>0,Kt=[{label:`Input`,value:lh(Lt?.cost?.input)},{label:`Output`,value:lh(Lt?.cost?.output)},{label:`Cache read`,value:lh(Lt?.cost?.cache_read)},{label:`Cache write`,value:lh(Lt?.cost?.cache_write)}],qt=[{label:`Context`,value:ch(Lt?.limit?.context)},{label:`Output`,value:ch(Lt?.limit?.output)}],Jt=Z.useRef(void 0),Yt=Z.useRef(null),Xt=Z.useRef(null),Zt=V?H(V):void 0,Qt=Mi(V??``,Zt??void 0).renderable,$t=fr(V??``,Zt??void 0),tn=Z.useMemo(()=>{for(let e=$t.length-1;e>=0;--e){let t=$t[e];if(t.role!==`user`)continue;let n=typeof t.model?.providerID==`string`&&t.model.providerID.trim().length>0?t.model.providerID:void 0,r=typeof t.model?.modelID==`string`&&t.model.modelID.trim().length>0?t.model.modelID:void 0,i=typeof t.agent==`string`&&t.agent.trim().length>0?t.agent:typeof t.mode==`string`&&t.mode.trim().length>0?t.mode:void 0,a=t.model?.variant??t.variant,o=typeof a==`string`&&a.trim().length>0?a:void 0;return{id:t.id,agent:i,providerID:n,modelID:r,variant:o}}return null},[$t]),nn=Z.useCallback((e,t,n)=>{if(!e||!t)return`model-missing`;let r=_.find(t=>t.id===e);return r?(Array.isArray(r.models)?r.models:[]).find(e=>e.id===t)?b===e&&x===t?`applied`:(O(e),A(t),V&&(ee(V,e,t),n&&K(V,n,e,t)),`applied`):`model-missing`:`provider-missing`},[_,b,x,O,A,V,K,ee]),rn=Z.useCallback((e,t)=>{if(i&&i.selection.providerID===e&&i.selection.modelID===t)return Lm(i.selection,i.catalog,e,t);let n=_.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Im(n)},[_,i,i?.selection.providerID,i?.selection.modelID,f?.variants,f?.variantsReady]),an=Z.useCallback((e,t)=>{let n=i?Lm(i.selection,i.catalog,e,t):[],r=n.length>0?n:rn(e,t);if(r.length===0)return;if(i){let n=i.selection.variant;if(i.selection.providerID===e&&i.selection.modelID===t&&n&&r.includes(n))return n}let a=ce||T;if(V&&a){let n=re(V,a,e,t);if(n&&r.includes(n))return n}if(b===e&&x===t&&C&&r.includes(C))return C;if(!V&&E&&r.includes(E))return E},[T,x,b,V,C,re,rn,i,E,ce]),on=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=Ai.getState().currentAgentName;return V?Zi.getState().getSessionAgentSelection(V)||oe.current||e||T:e||T},[T,V,i]),sn=Z.useCallback((e,t,n,r)=>{if(i){i.onChange({...i.selection,providerID:e,modelID:t,variant:n}).catch(()=>void 0);return}if(rn(e,t).length===0){Ge.current=!1,j(void 0);return}Ge.current=!0,j(n),ge(e,t,n);let a=r??on();V&&a&&ne(V,a,e,t,n)},[ge,V,rn,on,ne,i,j]),cn=Z.useCallback((e,t,n,r)=>{let a=r??on()??void 0,o=nn(e,t,a);if(o!==`applied`)return o;sn(e,t,n,a);let s=i?n:Ai.getState().currentVariant;return me(e,t,s),`applied`},[me,sn,on,i,nn]);Z.useEffect(()=>{if(i)return;if(!V){Xt.current=null;return}if(!ie||_.length===0||!Qt||!tn?.providerID||!tn.modelID)return;let e=[V,tn.id,tn.agent??``,tn.providerID,tn.modelID,tn.variant??``].join(`|`);if(Xt.current===e)return;tn.agent&&T!==tn.agent&&N(tn.agent);let t=tn.variant&&rn(tn.providerID,tn.modelID).includes(tn.variant)?tn.variant:void 0;cn(tn.providerID,tn.modelID,t,tn.agent||T||void 0)===`applied`&&(tn.agent&&(G(V,tn.agent),ne(V,tn.agent,tn.providerID,tn.modelID,t)),ee(V,tn.providerID,tn.modelID),Xt.current=e)},[i,V,T,ie,_,Qt,tn,N,cn,rn,G,ne,ee]),Z.useEffect(()=>{if(i)return;if(!V){Xt.current=null;return}if(!ie||_.length===0||R.length===0)return;let e=()=>{let e=W(V),t=V?Zi.getState().getSessionAgentSelection(V):null;if(t){T!==t&&N(t);let e=te(V,t);if(e){let n=nn(e.providerId,e.modelId,t);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}}if(e){let n=nn(e.providerId,e.modelId,t||T||void 0);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}for(let e of R){let t=te(V,e.name);if(!t)continue;T!==e.name&&N(e.name),Zi.getState().getSessionAgentSelection(V)||oe.current||G(V,e.name);let n=nn(t.providerId,t.modelId,e.name);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}return`continue`},t=()=>{if(R.length===0)return;let e=V?Zi.getState().getSessionAgentSelection(V)||oe.current:null,t=(V?Zi.getState().getSessionAgentSelection(V)||oe.current:null)||T;if(t&&R.some(e=>e.name===t)){T!==t&&N(t);return}let n=R.find(e=>e.name===`build`)||z[0]||R[0];n&&(e||G(V,n.name),T!==n.name&&N(n.name),n.model?.providerID&&n.model?.modelID&&nn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!Qt){U.isLoading(V)||U.ensureSessionRenderable(V);return}tn||t()}},[i,V,Qt,tn,R,z,T,W,te,N,nn,G,ie,_,U]),Z.useEffect(()=>{if(i||!ie)return;let e=new AbortController;return(async()=>{try{if(T!==Jt.current&&(Jt.current=T,T&&V)){let t=Yt.current===T;if(Yt.current=null,await new Promise(t=>{let n=setTimeout(t,50);e.signal.addEventListener(`abort`,()=>{clearTimeout(n),t()})}),e.signal.aborted)return;let n=te(V,T);if(n){let e=nn(n.providerId,n.modelId,T);if(e===`applied`||e===`provider-missing`)return}let r=Ai.getState().getAgentModelSelection(T);if(r){let e=nn(r.providerId,r.modelId,T);if(e===`applied`||e===`provider-missing`){e===`applied`&&(ee(V,r.providerId,r.modelId),K(V,T,r.providerId,r.modelId),r.variant!==void 0&&(ne(V,T,r.providerId,r.modelId,r.variant),j(r.variant)));return}}let i=t?R.find(e=>e.name===T):void 0;if(i?.model?.providerID&&i.model.modelID){let e=nn(i.model.providerID,i.model.modelID,T);if(e===`applied`||e===`provider-missing`){e===`applied`&&(ee(V,i.model.providerID,i.model.modelID),K(V,T,i.model.providerID,i.model.modelID));return}}}}catch(e){console.error(`[ModelControls] Agent change error:`,e)}})(),()=>{e.abort()}},[i,R,T,V,te,K,ne,ee,j,nn,ie]),Z.useEffect(()=>{if(i)return;if(!ie||!T){Ge.current=!1,j(void 0);return}if(!b||!x){Ge.current=!1,j(void 0);return}if(Wt.length===0){Ge.current=!1,j(void 0);return}if(C&&!Wt.includes(C)){j(void 0);return}if(!V){if(!C&&!Ge.current){let e=E&&Wt.includes(E)?E:void 0;j(e)}return}let e=re(V,T,b,x),t=e&&Wt.includes(e)?e:E&&Wt.includes(E)?E:void 0;j(t),Ge.current=!1},[i,Wt,ie,V,T,b,x,C,re,j,E]),Z.useEffect(()=>{Ge.current=!1},[b,x]);let ln=Z.useCallback((e,t)=>{if(i){let n=Bt(i.selection,e,R,_),r=n.providerID===i.selection.providerID&&n.modelID===i.selection.modelID;Fe&&Ke(),i.onChange({...n,variant:r?i.selection.variant:void 0}).then(()=>{he(e),(t?.closeModelSelector??!0)&&Xe(!1)}).catch(()=>void 0);return}try{Yt.current=e,N(e),he(e),(t?.closeModelSelector??!0)&&Xe(!1),V&&G(V,e),Fe&&Ke()}catch(e){console.error(`[ModelControls] Handle agent change error:`,e)}},[he,R,Ke,V,Fe,_,G,i,N,Xe]),un=Z.useCallback(e=>{let t=Ut(R,T,e);t&&ln(t,{closeModelSelector:!1})},[R,T,ln]),dn=Z.useCallback(e=>{let t=De&&!De.includes(`shift`)?Ja(`shift+${De}`):``;return t&&qa(e,t)?-1:qa(e,De)?1:null},[De]),fn=Z.useCallback(e=>{let t=dn(e);t&&(e.preventDefault(),e.stopPropagation(),un(t))},[dn,un]),pn=Z.useCallback((e,t,n,r)=>{!e||!t||!n||Ai.getState().saveAgentModelSelection(e,t,n,r)},[]),mn=(e,t,n)=>{let r=()=>{Xe(!1,n?.closeInstant?{instant:!0}:void 0)};if(i){Fe&&Ke();let a=n?.applyVariant?n.variant:an(e,t);i.onChange({providerID:e,modelID:t,agent:n?.agentName??i.selection.agent,variant:a}).then(()=>{me(e,t,a),r()}).catch(()=>void 0);return}try{let i=n?.agentName??on()??void 0,a=n?.applyVariant?cn(e,t,n.variant,i):nn(e,t,i);if(a!==`applied`){a===`provider-missing`?console.error(`[ModelControls] Provider not available for selection:`,e):a===`model-missing`&&console.error(`[ModelControls] Model not available for selection:`,{providerId:e,modelId:t});return}pn(i,e,t,n?.applyVariant?n.variant:Ai.getState().currentVariant),n?.applyVariant||me(e,t,Ai.getState().currentVariant),r(),Fe&&Ke()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},hn=(e,t)=>en(e,t,{maxLength:40}),gn=()=>_.find(e=>e.id===b)?.name||b,_n=()=>{if(!x)return a(`chat.modelControls.selectModel`);let e=Ft.find(e=>e.id===x);return hn(e,x)||a(`chat.modelControls.selectModel`)},vn=_n(),yn=Z.useRef(null),bn=jm(yn,[vn,C,Fe]),xn=()=>{if(!ce){let e=z.find(e=>e.name===`build`)||z[0];return e?Sn(e.name):`Select Agent`}let e=R.find(e=>e.name===ce);return Sn(e?e.name:ce)},Sn=e=>e.charAt(0).toUpperCase()+e.slice(1),Cn=Z.useCallback(e=>{Je.current&&clearTimeout(Je.current),Je.current=setTimeout(()=>{We(e)},500)},[]),wn=Z.useCallback(()=>{Je.current&&clearTimeout(Je.current)},[]);Z.useEffect(()=>()=>{Je.current&&clearTimeout(Je.current)},[]);let Tn=()=>!Fe||Ue!==`model`?null:(0,$.jsx)(sm,{open:!0,onClose:qe,title:Lt?.name||_n(),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:gn()})]}),zt.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:zt.map(({key:e,icon:t,label:n})=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(oh,{iconName:t,label:n},`cap-${e}`),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:n})]},e))})]}),(Vt.length>0||Ht.length>0)&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.modalities`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[Vt.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:Vt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(oh,{iconName:t,label:`${n} input`},`input-${e}`))})]}),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.output`)}),(0,$.jsx)(`div`,{className:`flex gap-1`,children:Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(oh,{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:ch(Lt?.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:ch(Lt?.limit?.output)})]})]})]}),Lt?.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:dh(Lt.release_date)})]})})]}):null]})}),En=()=>{if(!Fe||Ue!==`agent`||!Et)return null;let e=!!(Et.prompt&&Et.prompt.trim().length>0),t=Et.model?.providerID&&Et.model?.modelID,n=Et.temperature!==void 0||Et.topP!==void 0,r=e=>{let t=Xm(Et.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=Zm(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)(sm,{open:!0,onClose:qe,title:Sn(Et.name),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[Et.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:Et.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:Et.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Et.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Et.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:[Et.model.providerID,` / `,Et.model.modelID]}),n&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[Et.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:Et.temperature})]}),Et.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:Et.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)(sh,{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)(sh,{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)(sh,{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`})]})})]})})},Dn=()=>Fe?(0,$.jsx)(ao,{open:ze===`model`||ze===`variant`,view:ze===`variant`?`variant`:`model`,onViewChange:e=>Be(e),onClose:Ke,selectedProviderID:b||``,selectedModelID:x||``,resolveSelectedVariant:an,onSelect:(e,t,n)=>{if(i){Ke(),i.onChange({providerID:e,modelID:t,agent:i.selection.agent,variant:n}).then(()=>{me(e,t,n)}).catch(()=>void 0);return}let r=cn(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}pn(on(),e,t,n),Ke()},providers:_,favoriteModels:ke,recentModels:Ae,hiddenModels:Te,providerOrder:de,isFavorite:pe,onToggleFavorite:(e,t)=>le(e,t,e===b&&t===x?C:ke.find(n=>n.providerID===e&&n.modelID===t)?.variant??Ae.find(n=>n.providerID===e&&n.modelID===t)?.variant),getMetadata:F}):null,On=()=>Fe?(0,$.jsx)(_a,{id:`mobile-agent-picker-sheet-${o}`,open:ze===`agent`,onOpenChange:e=>{e||Ke()},ariaLabel:a(`chat.modelControls.selectAgent`),closeAriaLabel:a(`mobile.surface.closeAria`),resizeAriaLabel:a(`mobile.sessions.sheet.resizeAria`),bodyClassName:`px-2`,children:(0,$.jsx)(pa,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`flex flex-col gap-2 overscroll-contain`,children:Ct.map(e=>{let t=e.name===ce,n=na(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:()=>ln(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)(la,{name:e.name,size:18}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block typography-ui-label font-semibold`,style:t?{color:`var(${n.var})`}:void 0,children:Sn(e.name)}),e.description&&(0,$.jsx)(`span`,{className:`mt-1 block min-w-0 whitespace-normal break-words typography-micro text-muted-foreground`,children:e.description})]}),t&&(0,$.jsx)(X,{name:`check`,className:`size-4 shrink-0 text-primary`})]})},e.name)})})}):null,kn=()=>(0,$.jsx)(Ua,{align:`start`,sideOffset:8,className:`max-w-[320px]`,children:Lt?(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:Lt.name||_n()}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:gn()})]}),(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:zt.length>0?zt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(oh,{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:Vt.length>0?Vt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(oh,{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:Ht.length>0?Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(oh,{iconName:t,label:`${n} output`},`output-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:`-`})})]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.costPerMillion`)}),Kt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.limits`)}),qt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),Lt.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:dh(Lt.release_date)})]})]}):null]}):(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.metadataUnavailable`)})}),An=()=>{let e=(e,t)=>{if(ot.current=!0,e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return!1;let{providerID:n,modelID:r}=t,i=rn(n,r);if(i.length===0)return!1;e.preventDefault(),e.stopPropagation();let a=Jm(n,r),o=ut.has(a),s=ut.get(a),c=o?s:b===n&&x===r?C: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 dt(e=>{let t=new Map(e);return t.set(a,d),t}),pt(e=>{let t=new Set(e);return t.add(a),t}),ht(e=>e+1),!0},t=(t,n)=>{let r=dn(t);if(r){t.preventDefault(),un(r);return}n&&e(t,n)},n=e=>{let t=Jm(e.providerID,e.modelID),n=ut.get(t),r=ft.has(t),i=on();if(r){mn(e.providerID,e.modelID,{applyVariant:!0,variant:n,agentName:i});return}let a=rn(e.providerID,e.modelID),o=e.variant!==void 0&&a.includes(e.variant)?e.variant:void 0;if(o!==void 0){mn(e.providerID,e.modelID,{applyVariant:!0,variant:o,agentName:i});return}mn(e.providerID,e.modelID,{agentName:i})},r=e=>{let t=dn(e);t&&(e.preventDefault(),e.stopPropagation(),ot.current=!0,un(t))},i=e=>e?.trim()?xt(e):a(`chat.modelControls.default`),o=(e,t)=>{let n=on();mn(e.providerID,e.modelID,{applyVariant:!0,variant:t,agentName:n,closeInstant:!0})},s=e=>{e&&(Ye||performance.now()<it.current)||rt(e)},c={searchPlaceholder:a(`chat.modelControls.searchModels`),noResults:a(`chat.modelControls.noModelsFound`),favorites:a(`chat.modelControls.favorites`),recent:a(`chat.modelControls.recent`),keyboardHint:a(`chat.modelControls.keyboardHintNavigate`),favorite:a(`chat.modelControls.favoriteAria`),unfavorite:a(`chat.modelControls.unfavoriteAria`),provider:a(`chat.modelControls.provider`),capabilities:a(`chat.modelControls.capabilities`),capabilityToolCalling:a(`chat.modelControls.capability.toolCalling`),capabilityReasoning:a(`chat.modelControls.capability.reasoning`),modalityImage:a(`chat.modelControls.modality.image`),modalityVideo:a(`chat.modelControls.modality.video`),modalityAudio:a(`chat.modelControls.modality.audio`),costPerMillion:a(`chat.modelControls.costPerMillion`),costInput:a(`chat.modelControls.costInput`),costOutput:a(`chat.modelControls.costOutput`)},u=(e,{isSelected:t})=>{let n=rn(e.providerID,e.modelID);if(n.length===0)return null;let r=Jm(e.providerID,e.modelID),o=ut.has(r),s=ut.get(r),c=e.variant!==void 0&&n.includes(e.variant)?e.variant:void 0,l=o?s:t?C:c,u=ft.has(r);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`group/thinking flex shrink-0 items-center gap-0.5 rounded-md px-1.5 py-0.5 typography-micro font-medium transition-colors`,u||l?`text-foreground/80`:`text-muted-foreground`,`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] hover:text-foreground`),onClick:t=>{t.preventDefault(),t.stopPropagation(),tt(e)},"aria-label":a(`chat.modelControls.showThinkingModes`),children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),(0,$.jsx)(`span`,{className:`max-w-20 truncate`,children:i(l)}),(0,$.jsx)(X,{name:`arrow-right-s`,className:`size-3 opacity-60 transition-transform group-hover/thinking:translate-x-px`})]})},d=()=>{if(!et)return null;let e=rn(et.providerID,et.modelID),t=Jm(et.providerID,et.modelID),n=ut.has(t),r=ut.get(t),s=et.providerID===b&&et.modelID===x,c=et.variant!==void 0&&e.includes(et.variant)?et.variant:void 0,l=n?r:s?C:c,u=en(et.model,et.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(),tt(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:()=>tt(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)(Ma,{modelId:et.modelID,providerId:et.providerID,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate typography-meta font-medium text-foreground`,children:u}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`shrink-0 text-border`,children:`·`}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),a(`chat.modelControls.thinking`)]})]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 p-1`,role:`listbox`,"aria-label":a(`chat.modelControls.thinking`),children:[void 0,...e].map(e=>{let t=e===l||!e&&!l;return(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:Y(`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left typography-meta transition-colors`,t?`bg-interactive-selection text-interactive-selection-foreground`:`text-foreground hover:bg-interactive-hover/50`),onClick:()=>o(et,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)(Xp,{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=C&&Gt?xt(C):null;return(0,$.jsxs)(Wa,{open:!Ye&&nt,onOpenChange:s,delayDuration:200,children:[Fe?(0,$.jsx)(`button`,{type:`button`,onClick:p?()=>Ve(`model`):void 0,onTouchStart:p?()=>Cn(`model`):void 0,onTouchEnd:p?wn:void 0,onTouchCancel:p?wn:void 0,disabled:!p,className:Y(`model-controls__model-trigger min-w-0 focus:outline-none`,p?Y(`cursor-pointer`,gm):`opacity-60 cursor-not-allowed`),children:p?(0,$.jsxs)($.Fragment,{children:[b||x?(0,$.jsx)(Ma,{modelId:x,providerId:b,className:Y(Ot,`flex-shrink-0`)}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(Ot,`text-muted-foreground`)}),(0,$.jsx)(`span`,{ref:yn,className:Y(`model-controls__model-label typography-micro font-medium overflow-hidden min-w-0`,Ne?`max-w-[120px]`:`max-w-[220px]`),children:(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1`,bn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:vn}),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(Ot,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:`typography-micro font-medium text-muted-foreground min-w-0`,children:l})]})}):(0,$.jsxs)($a,{open:p&&Ye,onOpenChange:p?at:void 0,onOpenChangeComplete:e=>{e||_t(`model`)},children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,gm),children:[p?b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ma,{modelId:x,providerId:b,className:Y(Ot,`flex-shrink-0`)}),(0,$.jsx)(X,{name:`pencil-ai`,className:Y(Ot,`text-primary/60 hidden`)})]}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(Ot,`text-muted-foreground`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(Ot,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:Y(`model-controls__model-label`,kt,`font-medium whitespace-nowrap text-muted-foreground min-w-0`),children:l})]}),p&&(0,$.jsx)(`span`,{ref:yn,className:Y(`model-controls__model-label overflow-hidden`,kt,`font-medium whitespace-nowrap text-foreground min-w-0`,`max-w-[260px]`),children:(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1`,bn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:vn}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})},`${b}-${x}-${C??``}`)]})})}),(0,$.jsx)(uo,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,xe&&Ym),align:`end`,alignOffset:-40,onKeyDownCapture:r,finalFocus:vt,children:et?d():(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`p-1 border-b border-border/40`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:Ze,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)(ma,{providers:_,favoriteModels:ke,recentModels:Ae,getMetadata:F,searchQuery:Qe,onSearchQueryChange:$e,onSelect:n,labels:c,selectedModel:b&&x?{providerID:b,modelID:x}:null,hiddenModels:Te,onActiveKeyDown:t,onActiveEntryChange:e=>{lt.current=e},onVariantKey:e,isFavorite:e=>pe(e.providerID,e.modelID),onToggleFavorite:e=>le(e.providerID,e.modelID,e.providerID===b&&e.modelID===x?C:e.variant),renderRowEnd:u,renderVersion:mt,onReorderFavorite:(e,t)=>ue(e.providerID,e.modelID,t.providerID,t.modelID),reorderFavoriteAriaLabel:a(`chat.modelControls.reorderFavoriteAria`),reorderFavoriteTitle:a(`chat.modelControls.reorderFavoriteTitle`),providerOrder:de,onReorderProvider:fe,reorderProviderTitle:a(`chat.modelControls.reorderProviderTitle`),footerContent:e=>{let t=e?rn(e.providerID,e.modelID).length>0:!1;return(0,$.jsxs)(`div`,{className:`flex items-center gap-x-2 whitespace-nowrap overflow-hidden`,children:[(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintNavigate`)}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintSwitchAgent`,{shortcut:`Tab`})}),t?(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintThinking`)}):null]})},tooltipsEnabled:Ye&&!et,onEscape:()=>{if(et){tt(null);return}Xe(!1)}})]})})]}),kn()]})},jn=()=>{if(!Et)return(0,$.jsx)(Ua,{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=!!(Et.prompt&&Et.prompt.trim().length>0),t=Et.model?.providerID&&Et.model?.modelID,n=Et.temperature!==void 0||Et.topP!==void 0,r=e=>{let t=Xm(Et.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=Zm(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)(Ua,{align:`start`,sideOffset:8,className:`max-w-[280px]`,children:(0,$.jsxs)(`div`,{className:`flex min-w-[200px] flex-col gap-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-foreground`,children:Sn(Et.name)}),Et.description&&(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:Et.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:Et.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Et.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Et.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:[Et.model.providerID,` / `,Et.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:[Et.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:Et.temperature})]}),Et.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:Et.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)(sh,{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)(sh,{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)(sh,{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`})]})]})})},Mn=()=>{let e=xn(),t=ce?na(ce):null;return Fe?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>Ve(`agent`):void 0,onTouchStart:m?()=>Cn(`agent`):void 0,onTouchEnd:m?wn:void 0,onTouchCancel:m?wn:void 0,disabled:!m,className:Y(`model-controls__agent-trigger inline-flex items-center flex-shrink-0 min-w-0 focus:outline-none`,_m,m?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:m?(0,$.jsx)(um,{name:ce,label:e,revealed:Nt,avatarSize:Mt,slotClassName:jt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,jt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(Ot,`flex-shrink-0 animate-spin text-muted-foreground`)})})}):(0,$.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,$.jsxs)(Wa,{delayDuration:600,children:[(0,$.jsxs)($a,{open:m&&ye,onOpenChange:m?He:void 0,onOpenChangeComplete:e=>{e||_t(`agent`)},children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,_m),children:m?(0,$.jsx)(um,{name:ce,label:e,revealed:Nt,avatarSize:Mt,slotClassName:jt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,jt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(Ot,`flex-shrink-0 animate-spin text-muted-foreground`)})})})})}),(0,$.jsxs)(uo,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,Se&&Ym),onKeyDownCapture:fn,finalFocus:vt,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)(Va,{type:`text`,placeholder:a(`chat.modelControls.searchAgents`),value:bt,onChange:e=>St(e.target.value),onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),be(!1);return}e.stopPropagation()},className:`pl-8 h-8 typography-meta`})]})}),(0,$.jsx)(pa,{outerClassName:`max-h-[min(400px,calc(100dvh-12rem))] flex-1`,children:(0,$.jsxs)(`div`,{className:`p-1`,children:[!bt.trim()&&Tt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(po,{className:`typography-meta`,onSelect:()=>ln(Tt),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)(Ya,{})]}),wt.length===0?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-meta text-muted-foreground`,children:`No agents found`}):wt.map(e=>(0,$.jsx)(po,{className:`typography-meta`,onSelect:()=>ln(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)(la,{name:e.name,size:14}),(0,$.jsx)(`span`,{className:`font-medium`,children:Sn(e.name)})]}),e.description&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground min-w-0 max-w-full ml-5 break-words`,children:e.description})]})},e.name))]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border/40 px-2 py-1.5 typography-micro text-muted-foreground`,children:[(0,$.jsx)(Xp,{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`)})]})]})]}),jn()]})})},Nn=Y(`@container/model-controls flex items-center min-w-0`,Ne&&`w-full`,e),Pn=Mn();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Nn,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center min-w-0 flex-1 justify-end`,At,Ne&&`overflow-hidden`),children:[Pn,An()]})}),Dn(),On(),Tn(),En()]})},ph=[{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`}],mh=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=ct(),i=uu(hh),a=q(gh),o;t[0]===a?o=t[1]:(o=Za(Qa(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let s=o;if(!i)return null;let c;t[2]===r?c=t[3]:(c=r(`chat.leaderKey.pendingAria`),t[2]=r,t[3]=c);let l;t[4]===n?l=t[5]:(l=Y(`pointer-events-none absolute left-1/2 top-0 z-20 -translate-x-1/2 -translate-y-[calc(100%+0.4rem)]`,`inline-flex max-w-[calc(100cqw-1rem)] items-center gap-2 overflow-x-auto rounded-lg border px-2.5 py-1.5`,`border-[var(--interactive-border)] bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)]`,`shadow-sm animate-in fade-in-0 zoom-in-95 duration-150 whitespace-nowrap`,n),t[4]=n,t[5]=l);let u;t[6]===s?u=t[7]:(u=(0,$.jsx)(Zp,{shortcut:s,className:`opacity-[0.35] [&_[data-slot=kbd]]:rounded-md [&_[data-slot=kbd]]:border-0 [&_[data-slot=kbd]]:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] [&_[data-slot=kbd]]:text-muted-foreground/65 [&_[data-slot=kbd]]:shadow-none`}),t[6]=s,t[7]=u);let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}),t[8]=d):d=t[8];let f;t[9]===r?f=t[10]:(f=ph.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)(Xp,{className:`rounded-md border-0 bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] text-muted-foreground/65 shadow-none`,children:e.key}),(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(e.labelKey)})]})]},e.key)),t[9]=r,t[10]=f);let p;return t[11]!==c||t[12]!==l||t[13]!==u||t[14]!==f?(p=(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":c,className:l,children:[u,d,f]}),t[11]=c,t[12]=l,t[13]=u,t[14]=f,t[15]=p):p=t[15],p};function hh(e){return e.pending}function gh(e){return e.shortcutOverrides}var _h=28,vh=8,yh=10.5,bh=Math.PI/2,xh=e=>Array.from({length:vh},(t,n)=>{let r=n/vh*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*yh,Math.sin(r)*yh]}),Sh=[xh(0),xh(bh),xh(Math.PI),xh(Math.PI*1.5)],Ch=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,wh=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/_h,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:Sh[0].map(Th)}),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 Th(e,t){return(0,$.jsx)(`span`,{className:`oc-morph-orb-dot`,style:{"--m-1":Ch(Sh[0][t]),"--m-2":Ch(Sh[1][t]),"--m-3":Ch(Sh[2][t]),"--m-4":Ch(Sh[3][t])}},t)}var Eh=1200,Dh=600,Oh=1e9,kh=0xe8d4a51000,Ah=e=>e>=kh?e:e>=Oh?e*1e3:Date.now()+e;function jh({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o,isTurnSettled:s=!1}){let{locale:c,t:l}=ct(),[u,d]=Z.useState(null),[f,p]=Z.useState(!1),m=Z.useRef(u),h=Z.useRef(f),g=Z.useRef(!1);m.current=u,h.current=f;let _=Z.useRef(0),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(null),[x,S]=Z.useState(null),[C,w]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;w(Date.now());let t=window.setInterval(()=>w(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){S(null);return}let t=Ah(e),n=()=>{let e=Math.max(0,t-Date.now());S(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let T=J(()=>{y.current&&=(clearTimeout(y.current),null),b.current&&=(clearTimeout(b.current),null)}),E=J((e,t,n=!1)=>{T(),v.current=null,d(e),p(t),g.current=n,_.current=Date.now()}),D=J(()=>{if(y.current)return;let e=Date.now()-_.current,t=Math.max(0,Eh-e);y.current=setTimeout(()=>{y.current=null;let e=v.current;e&&E(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(s){T(),v.current=null,m.current&&(d(null),p(!1),g.current=!1);return}if(!e){if(y.current&&=(clearTimeout(y.current),null),v.current=null,!m.current||b.current)return;b.current=setTimeout(()=>{b.current=null,d(null),p(!1),g.current=!1},Dh);return}if(b.current&&=(clearTimeout(b.current),null),a){T(),v.current=null;return}let t=i?l(`chat.assistantStatus.waitingForPermission`):n,o=!!i,c=!!r&&!o;if(t){if(!m.current){E(t,o,c);return}if((t!==m.current||o!==h.current)&&!(c&&g.current)){if(c){v.current={text:t,permission:o,generic:c},D();return}E(t,o,c)}}},[e,s,n,r,i,a,l]),Z.useEffect(()=>()=>T(),[]),s||!e&&!u)return null;if(a&&e){let e=x!==null&&x>0?new Intl.RelativeTimeFormat(c,{numeric:`always`,style:`short`}).format(x,`second`):null,n=e?a.attempt&&a.attempt>1?l(`chat.assistantStatus.retryingInAttempt`,{duration:e,attempt:a.attempt}):l(`chat.assistantStatus.retryingIn`,{duration:e}):a.attempt&&a.attempt>1?l(`chat.assistantStatus.retryingAttempt`,{attempt:a.attempt}):l(`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)(wh,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:n})]})})}if(!u)return null;let O=u,k=typeof o==`number`&&e?vt(Math.max(0,C-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":f?`assertive`:`polite`,"aria-label":O,"data-waiting":f?`true`:void 0,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center ${t?`gap-1 typography-meta !text-[length:var(--text-meta)]`:`gap-1.5 typography-ui-header`}`,children:[(0,$.jsx)(`span`,{className:`inline-flex flex-none items-center justify-center ${t?`h-5 w-4`:`h-6 w-3.5`}`,children:(0,$.jsx)(wh,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:O}),k?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:k}):null]})})}var Mh={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Nh={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Ph={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:Mh},Fh=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?Mh:Nh}),Ih=Z.createContext(Ph),Lh=()=>Z.useContext(Ih),Rh=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}),zh=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,Bh={containerType:`inline-size`,containerName:`status-row`},Vh=[],Hh=e=>{let t=(0,Q.c)(99),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:s,retryInfo:c,turnStartedAt:l,isTurnSettled:u,showAbortStatus:d,showAbortPrompt:f,showAssistantStatus:p,showTodos:m,agentName:h,leftAccessory:g}=e,_=n!==void 0&&n,v=r===void 0?null:r,y=u!==void 0&&u,b=f!==void 0&&f,x=p===void 0||p,S=m===void 0||m,{t:C}=ct(),[w,T]=Z.useState(!1),E=Lh(),D=ri(Uh),O=E.sessionId??D,k;t[0]!==O||t[1]!==S?(k=e=>!S||!O?Vh:e.todo[O]??Vh,t[0]=O,t[1]=S,t[2]=k):k=t[2];let A=tn(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=Tn(j),N;bb0:{if(!O){N=Vh;break bb0}if(A.length>0){N=A;break bb0}N=M??Vh}let P=N,F=q(Wh),I;t[6]===F?I=t[7]:(I=F||se(),t[6]=F,t[7]=I);let L=I,R;t[8]===P?R=t[9]:(R=P.filter(Gh),t[8]=P,t[9]=R);let z=R,B;t[10]===z?B=t[11]:(B=z.find(Kh)||z.find(qh)||null,t[10]=z,t[11]=B);let V=B,H;t[12]===z?H=t[13]:(H=z.find(Jh)??null,t[12]=z,t[13]=H);let U=H,W;t[14]===P?W=t[15]:(W=P.filter(Yh),t[14]=P,t[15]=W);let ee=W.length,G;t[16]===P?G=t[17]:(G=P.filter(Xh),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(Zh),t[21]=z,t[22]=re);let ie=re.length,ae;t[23]===z?ae=t[24]:(ae=z.filter(Qh),t[23]=z,t[24]=ae);let oe=ae.length,ce;t[25]!==ie||t[26]!==oe?(ce={active:ie,left:oe},t[25]=ie,t[26]=oe,t[27]=ce):ce=t[27];let le=ce,ue=S&&le.left>0,de=!!b,[fe,pe]=Z.useState(!1),me,he;t[28]!==fe||t[29]!==y||t[30]!==_?(me=()=>{if(y){pe(!1);return}if(_){pe(!0);return}if(!fe)return;let e=window.setTimeout(()=>pe(!1),600);return()=>window.clearTimeout(e)},he=[_,fe,y],t[28]=fe,t[29]=y,t[30]=_,t[31]=me,t[32]=he):(me=t[31],he=t[32]),Z.useEffect(me,he);let ge=x&&(!y&&(_||fe)||!!o||!!d),_e=!!g,ve=!d&&!de&&(o||!s),ye=de||ge||ue||_e,be=Z.useRef(null),xe=Z.useRef(null),Se=Z.useRef(null),Ce,we;t[33]===w?(Ce=t[34],we=t[35]):(Ce=()=>{let e=xe.current,t=Se.current;if(!w||!e||!t)return;let n=t.offsetTop-e.offsetTop-(e.clientHeight-t.offsetHeight)/2,r=e.scrollHeight-e.clientHeight;e.scrollTop=Math.min(r,Math.max(0,n))},we=[w],t[33]=w,t[34]=Ce,t[35]=we),Z.useLayoutEffect(Ce,we);let Te,Ee;t[36]===w?(Te=t[37],Ee=t[38]):(Te=()=>{if(!w)return;let e=e=>{be.current&&!be.current.contains(e.target)&&T(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},Ee=[w],t[36]=w,t[37]=Te,t[38]=Ee),Z.useEffect(Te,Ee);let De;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(De=()=>T($h),t[39]=De):De=t[39];let Oe=J(De),ke;t[40]!==le.active||t[41]!==le.left||t[42]!==C?(ke=C(`chat.statusRow.summary.activeLeft`,{active:le.active,left:le.left}),t[40]=le.active,t[41]=le.left,t[42]=C,t[43]=ke):ke=t[43];let Ae=ke,je;t[44]!==V||t[45]!==ue||t[46]!==L||t[47]!==w||t[48]!==ne||t[49]!==C||t[50]!==Ae||t[51]!==Oe?(je=ue?(0,$.jsxs)(`button`,{type:`button`,onClick:Oe,className:Y(Ec,`shrink-0`),"aria-label":Ae,title:Ae,children:[(0,$.jsx)(X,{name:`list-check-3`,className:kc}),!L&&V?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,zc),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:wc,"aria-hidden":`true`,children:[ne.completed,`/`,ne.total]}),w?(0,$.jsx)(X,{name:`arrow-up-s`,className:kc}):(0,$.jsx)(X,{name:`arrow-down-s`,className:kc})]}):null,t[44]=V,t[45]=ue,t[46]=L,t[47]=w,t[48]=ne,t[49]=C,t[50]=Ae,t[51]=Oe,t[52]=je):je=t[52];let Me=je;if(!ye)return null;let Ne=!_e&&`chat-column`,Pe;t[53]===Ne?Pe=t[54]:(Pe=Y(`mb-1`,Ne),t[53]=Ne,t[54]=Pe);let Fe=_e&&`px-3`,Ie;t[55]===Fe?Ie=t[56]:(Ie=Y(`flex items-center justify-between py-0.5 gap-2 h-[1.2rem]`,Fe),t[55]=Fe,t[56]=Ie);let Le=!_e&&`overflow-x-hidden`,Re;t[57]===Le?Re=t[58]:(Re=Y(`flex-1 flex items-center min-w-0 gap-2`,Le),t[57]=Le,t[58]=Re);let ze;t[59]!==h||t[60]!==O||t[61]!==de||t[62]!==i||t[63]!==F||t[64]!==y||t[65]!==a||t[66]!==_||t[67]!==g||t[68]!==c||t[69]!==ve||t[70]!==d||t[71]!==x||t[72]!==v||t[73]!==C||t[74]!==l?(ze=de?(0,$.jsx)(`div`,{className:`flex min-w-0 items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":C(`chat.statusRow.abortPrompt`),children:(0,$.jsxs)(`span`,{className:Y(`flex min-w-0 items-center typography-ui-label`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5`,"aria-hidden":`true`})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer truncate whitespace-nowrap`,children:C(`chat.statusRow.abortPrompt`)})]})}):x&&d?(0,$.jsx)(`div`,{className:`flex h-full items-center text-[var(--status-error)]`,children:(0,$.jsxs)(`span`,{className:Y(`flex items-center typography-ui-label`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`close-circle`,className:`size-3.5`,"aria-hidden":`true`})}),C(`chat.statusRow.aborted`)]})}):x&&ve?(0,$.jsx)(jh,{isWorking:_,isMobile:F,statusText:v,isGenericStatus:i,isWaitingForPermission:a,retryInfo:c,turnStartedAt:l,isTurnSettled:y,agentName:h},O??`no-session`):g||null,t[59]=h,t[60]=O,t[61]=de,t[62]=i,t[63]=F,t[64]=y,t[65]=a,t[66]=_,t[67]=g,t[68]=c,t[69]=ve,t[70]=d,t[71]=x,t[72]=v,t[73]=C,t[74]=l,t[75]=ze):ze=t[75];let Be;t[76]!==Re||t[77]!==ze?(Be=(0,$.jsx)(`div`,{className:Re,children:ze}),t[76]=Re,t[77]=ze,t[78]=Be):Be=t[78];let Ve=!_e&&`-mr-3`,He;t[79]===Ve?He=t[80]:(He=Y(`relative flex items-center gap-2 flex-shrink-0`,Ve),t[79]=Ve,t[80]=He);let Ue;t[81]!==U||t[82]!==ue||t[83]!==w||t[84]!==ne||t[85]!==C||t[86]!==z?(Ue=w&&ue&&(0,$.jsxs)(`div`,{style:Dc,className:Y(Nc,`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:xe,className:Kc,children:z.map((e,t)=>(0,$.jsx)(Jc,{todo:e,isActive:e===U,activeRef:e===U?Se:void 0},e.id??`todo-${t}`))})]}),t[81]=U,t[82]=ue,t[83]=w,t[84]=ne,t[85]=C,t[86]=z,t[87]=Ue):Ue=t[87];let We;t[88]!==He||t[89]!==Ue||t[90]!==Me?(We=(0,$.jsxs)(`div`,{className:He,ref:be,children:[Me,Ue]}),t[88]=He,t[89]=Ue,t[90]=Me,t[91]=We):We=t[91];let Ge;t[92]!==Ie||t[93]!==Be||t[94]!==We?(Ge=(0,$.jsxs)(`div`,{className:Ie,children:[Be,We]}),t[92]=Ie,t[93]=Be,t[94]=We,t[95]=Ge):Ge=t[95];let Ke;return t[96]!==Pe||t[97]!==Ge?(Ke=(0,$.jsx)(`div`,{className:Pe,style:Bh,children:Ge}),t[96]=Pe,t[97]=Ge,t[98]=Ke):Ke=t[98],Ke};function Uh(e){return e.currentSessionId}function Wh(e){return e.isMobile}function Gh(e){return e.status!==`cancelled`}function Kh(e){return e.status===`in_progress`}function qh(e){return e.status===`pending`}function Jh(e){return e.status===`in_progress`}function Yh(e){return e.status!==`cancelled`}function Xh(e){return e.status===`completed`}function Zh(e){return e.status===`in_progress`}function Qh(e){return e.status===`in_progress`||e.status===`pending`}function $h(e){return!e}var eg=Z.createContext(null),tg=e=>{let t=(0,Q.c)(3),{actions:n,children:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(eg.Provider,{value:n,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},ng=()=>Z.useContext(eg),rg=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),ig=e=>`insertions`in e,ag=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},og=e=>{let t=0,n=0;for(let r of e.split(`
|
|
6521
|
-
`))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},sg=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!rg.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:ag(i.additions)??void 0,deletions:ag(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:ag(e.additions)??void 0,deletions:ag(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:ag(i.additions)??void 0,deletions:ag(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=og(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},cg=(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:bo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},lg=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},ug=(e,t)=>yo(e,t),dg=(e,t)=>{let n=ig(e)&&e.relativePath?e.relativePath:ug(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},fg=e=>ig(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},pg=2;function mg(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t)}}function hg(e,t=pg){let n=e??``,r=n.startsWith(`/`),i=n.split(`/`).filter(Boolean);if(i.length===0)return{prefix:``,parent:``,stem:``,ext:``,name:``,leadingSlash:r};let a=i[i.length-1]??``,{stem:o,ext:s}=mg(a),c=Math.max(1,Math.floor(t)),l=Math.min(i.length-1,c-1),u=i.length-1-l,d=l>0?i.slice(u,-1).join(`/`):``,f=i.slice(0,u).join(`/`),p=f?r?`/${f}`:f:``;return{prefix:p,parent:d,stem:o,ext:s,name:a,leadingSlash:r&&!p}}function gg(e){let t=(0,Q.c)(36),{path:n,className:r,title:i,dirClassName:a,nameClassName:o}=e,s=a===void 0?`text-muted-foreground`:a,c=o===void 0?`text-foreground`:o,l;t[0]===n?l=t[1]:(l=hg(n),t[0]=n,t[1]=l);let{prefix:u,parent:d,stem:f,ext:p,leadingSlash:m}=l,h=!!(u||d),g;t[2]===r?g=t[3]:(g=Y(`flex min-w-0 items-baseline overflow-hidden`,r),t[2]=r,t[3]=g);let _=i??n,v;t[4]!==s||t[5]!==m?(v=m?(0,$.jsx)(`span`,{className:Y(`shrink-0`,s),children:`/`}):null,t[4]=s,t[5]=m,t[6]=v):v=t[6];let y;t[7]!==s||t[8]!==u?(y=u?(0,$.jsx)(`span`,{className:Y(`min-w-0 shrink-[9999] truncate`,s),children:u}):null,t[7]=s,t[8]=u,t[9]=y):y=t[9];let b;t[10]!==s||t[11]!==d||t[12]!==u?(b=d?(0,$.jsxs)(`span`,{className:Y(`shrink-0`,s),children:[u?`/`:``,d]}):null,t[10]=s,t[11]=d,t[12]=u,t[13]=b):b=t[13];let x;t[14]!==s||t[15]!==h?(x=h?(0,$.jsx)(`span`,{className:s,children:`/`}):null,t[14]=s,t[15]=h,t[16]=x):x=t[16];let S;t[17]===c?S=t[18]:(S=Y(`min-w-0 truncate`,c),t[17]=c,t[18]=S);let C;t[19]!==f||t[20]!==S?(C=(0,$.jsx)(`span`,{className:S,children:f}),t[19]=f,t[20]=S,t[21]=C):C=t[21];let w;t[22]!==p||t[23]!==c?(w=p?(0,$.jsx)(`span`,{className:Y(`shrink-0`,c),children:p}):null,t[22]=p,t[23]=c,t[24]=w):w=t[24];let T;t[25]!==C||t[26]!==w||t[27]!==x?(T=(0,$.jsxs)(`span`,{className:`flex min-w-0 shrink items-baseline`,children:[x,C,w]}),t[25]=C,t[26]=w,t[27]=x,t[28]=T):T=t[28];let E;return t[29]!==T||t[30]!==g||t[31]!==_||t[32]!==v||t[33]!==y||t[34]!==b?(E=(0,$.jsxs)(`span`,{className:g,title:_,children:[v,y,b,T]}),t[29]=T,t[30]=g,t[31]=_,t[32]=v,t[33]=y,t[34]=b,t[35]=E):E=t[35],E}var _g=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=ct(),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:Tc,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Ac,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:qc,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}=dg(e,r),s=fg(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`,jc),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(yd,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(gg,{path:o?`${o}/${n}`:n,title:e.path,className:`min-w-0 flex-1`}),s.additions>0||s.deletions>0?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-baseline gap-1 text-xs tabular-nums leading-4 md:text-[0.8125rem] md:leading-5`,children:[s.additions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,s.additions]}):null,s.deletions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,s.deletions]}):null]}):null]},`${e.path}:${t}`)},t[14]=r,t[15]=i,t[16]=a,t[17]=e):e=t[17],u=n.map(e),t[9]=r,t[10]=n,t[11]=i,t[12]=a,t[13]=u}else u=t[13];let d;t[18]===u?d=t[19]:(d=(0,$.jsx)(`div`,{className:Kc,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},vg=`${Nc} origin-[var(--transform-origin)]`,yg=Dc,bg=Z.memo(()=>{let e=(0,Q.c)(60),{t}=ct(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=pc()??null,o=Z.useContext(Ao),s=fs(a),c;e[0]===a?c=e[1]:(c=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=c);let l=Xo(c),u=ng(),d,f;e[2]===n?(d=e[3],f=e[4]):(d=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},f=[n],e[2]=n,e[3]=d,e[4]=f),Z.useEffect(d,f);let p;bb0:{if(!a||s!==!0||!l||l.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],p=t;break bb0}let t;e[6]!==a||e[7]!==l.diffStats||e[8]!==l.files?(t=cg(l.files,l.diffStats,a),e[6]=a,e[7]=l.diffStats,e[8]=l.files,e[9]=t):t=e[9],p=t}let m=p,h=0,g=0;if(e[10]!==h||e[11]!==m||e[12]!==g){for(let e of m)h+=e.insertions,g+=e.deletions;e[10]=h,e[11]=m,e[12]=g,e[13]=h,e[14]=g}else h=e[13],g=e[14];let _;e[15]!==h||e[16]!==g?(_={totalAdded:h,totalRemoved:g},e[15]=h,e[16]=g,e[17]=_):_=e[17];let{totalAdded:v,totalRemoved:y}=_;if(!a||s!==!0||m.length===0)return null;let b;e[18]!==a||e[19]!==u||e[20]!==o?.editor?(b=e=>{if(!a||!ig(e))return;r(!1);let t=e.path;if(u){u.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=q.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]=u,e[20]=o?.editor,e[21]=b):b=e[21];let x=b,S=m.length,C;e[22]!==S||e[23]!==t?(C=t(S===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:S}),e[22]=S,e[23]=t,e[24]=C):C=e[24];let w=C,T,E;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(T=Y(Ec,`max-w-full text-left`),E=()=>r(xg),e[25]=T,e[26]=E):(T=e[25],E=e[26]);let D,O;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(X,{name:`file-edit`,className:kc}),D=Y(zc,`shrink-0`),e[27]=D,e[28]=O):(D=e[27],O=e[28]);let k;e[29]===w?k=e[30]:(k=(0,$.jsx)(`span`,{className:D,children:w}),e[29]=w,e[30]=k);let A;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(A=Y(`status-row__changed-label`,zc),e[31]=A):A=e[31];let j;e[32]===t?j=e[33]:(j=t(`chat.pendingChanges.changedInWorkspace`),e[32]=t,e[33]=j);let M;e[34]===j?M=e[35]:(M=(0,$.jsx)(`span`,{className:A,children:j}),e[34]=j,e[35]=M);let N;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(N=Y(wc,`items-baseline gap-0.5`),e[36]=N):N=e[36];let P;e[37]===v?P=e[38]:(P=v>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,v]}):null,e[37]=v,e[38]=P);let F;e[39]===y?F=e[40]:(F=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,y]}):null,e[39]=y,e[40]=F);let I;e[41]!==P||e[42]!==F?(I=(0,$.jsxs)(`span`,{className:N,children:[P,F]}),e[41]=P,e[42]=F,e[43]=I):I=e[43];let L;e[44]===n?L=e[45]:(L=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:kc}):(0,$.jsx)(X,{name:`arrow-down-s`,className:kc}),e[44]=n,e[45]=L);let R;e[46]!==n||e[47]!==k||e[48]!==M||e[49]!==I||e[50]!==L?(R=(0,$.jsxs)(`button`,{type:`button`,className:T,onClick:E,"aria-expanded":n,children:[O,k,M,I,L]}),e[46]=n,e[47]=k,e[48]=M,e[49]=I,e[50]=L,e[51]=R):R=e[51];let z;e[52]!==a||e[53]!==m||e[54]!==x||e[55]!==n?(z=n&&(0,$.jsx)(`div`,{style:yg,className:Y(vg,`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)(_g,{files:m,currentDirectory:a,onOpenFile:x})}),e[52]=a,e[53]=m,e[54]=x,e[55]=n,e[56]=z):z=e[56];let B;return e[57]!==R||e[58]!==z?(B=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[R,z]}),e[57]=R,e[58]=z,e[59]=B):B=e[59],B});bg.displayName=`PendingChangesBar`;function xg(e){return!e}var Sg=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=ct(),s=a===`compact`;if(s&&!n)return null;let c=a==="default"&&`absolute left-1/2 bottom-full mb-2 -translate-x-1/2`,l=a===`expanded`&&`absolute left-1/2 -translate-x-1/2 oc-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`oc-scroll-to-bottom--compact relative shrink-0`,d;t[0]!==a||t[1]!==c||t[2]!==l||t[3]!==u||t[4]!==n?(d=Y(c,l,u,n?Y(`pointer-events-auto`,a==="default"&&`opacity-100`):Y(`opacity-0 pointer-events-none`,a===`expanded`&&`oc-scroll-to-bottom--hidden`)),t[0]=a,t[1]=c,t[2]=l,t[3]=u,t[4]=n,t[5]=d):d=t[5];let f=s?`ghost`:`outline`,p=s?`composer-mobile-actions h-8 w-8 rounded-none bg-transparent hover:bg-transparent text-foreground`:`size-8 rounded-full [corner-shape:round] bg-background/95 hover:bg-interactive-hover`,m;t[6]===p?m=t[7]:(m=Y(`p-0 shadow-none`,p),t[6]=p,t[7]=m);let h;t[8]===o?h=t[9]:(h=o(`chat.scrollToBottom.aria`),t[8]=o,t[9]=h);let g=s?`size-5`:`size-4`,_=s?`medium`:`regular`,v;t[10]!==g||t[11]!==_?(v=(0,$.jsx)(X,{name:`arrow-down`,className:g,weight:_}),t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==r||t[14]!==v||t[15]!==f||t[16]!==m||t[17]!==h?(y=(0,$.jsx)(ua,{variant:f,size:`sm`,onClick:r,className:m,"aria-label":h,children:v}),t[13]=r,t[14]=v,t[15]=f,t[16]=m,t[17]=h,t[18]=y):y=t[18];let b;return t[19]!==y||t[20]!==d?(b=(0,$.jsx)(`div`,{className:d,children:y}),t[19]=y,t[20]=d,t[21]=b):b=t[21],b}),Cg=Z.createContext(`default`),wg=()=>Z.useContext(Cg),Tg=500,Eg=e=>{let t=(0,Q.c)(31),{onCycleAgent:n,onOpenAgentPanel:r,className:i,agentName:a,agents:o,disabled:s}=e,c;t[0]===o?c=t[1]:(c=o===void 0?[]:o,t[0]=o,t[1]=c);let l=c,u=s!==void 0&&s,d=a??void 0,f;t[2]!==l||t[3]!==d?(f=Un(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=dm(d),h;t[5]===d?h=t[6]:(h=na(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()},Tg))},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`,_m,i),t[16]=i,t[17]=D);let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[18]=O):O=t[18];let k;t[19]!==g.var||t[20]!==p||t[21]!==d||t[22]!==m?(k=(0,$.jsx)(um,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,colorVar:g.var}),t[19]=g.var,t[20]=p,t[21]=d,t[22]=m,t[23]=k):k=t[23];let A;return t[24]!==p||t[25]!==u||t[26]!==b||t[27]!==S||t[28]!==D||t[29]!==k?(A=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:Dg,onMouseDown:Og,className:D,style:O,title:p,"aria-label":p,children:k}),t[24]=p,t[25]=u,t[26]=b,t[27]=S,t[28]=D,t[29]=k,t[30]=A):A=t[30],A};function Dg(e){return e.preventDefault()}function Og(e){return e.preventDefault()}var kg=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}=ct(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=Bn(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()?xt(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)(Ma,{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:Ag,onPointerDownCapture:jg,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 Ag(e){return e.preventDefault()}function jg(e){e.preventDefault()}var Mg={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Ng=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function Pg(e,t){let n=(0,Q.c)(6),r=Fi(e??``,t),i=Sr(e??``,t),a=fr(e??``,t),o=yr(e??``,t),s=ai(e??``,t),c=jr(t),l;bb0:{if(!e){l=Mg;break bb0}if(o.length>0||s.length>0){l=Mg;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=Ng({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=Mg;break bb0}if(!y){l=Mg;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var Fg=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function Ig(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(`inline-flex shrink-0 items-center justify-center rounded-full bg-foreground text-background`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,$.jsx)(`span`,{className:a,...i,"aria-hidden":!0,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function Lg(e){let t=(0,Q.c)(7),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]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`span`,{"data-stop-glyph":`true`,className:`block size-[38%] rounded-[20%] bg-current`}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsx)(Ig,{className:n,...r,children:i}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function Rg(e){let t=(0,Q.c)(13),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,spinning:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i!==void 0&&i,o=a?`loader-4`:`arrow-up`,s=a?`size-[50%] animate-spin`:`size-[56%]`,c;t[4]===s?c=t[5]:(c=Y(s),t[4]=s,t[5]=c);let l;t[6]!==o||t[7]!==c?(l=(0,$.jsx)(X,{name:o,weight:`medium`,className:c}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u;return t[9]!==n||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(Ig,{className:n,...r,children:l}),t[9]=n,t[10]=r,t[11]=l,t[12]=u):u=t[12],u}var zg=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Bg=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Vg=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Hg=(e,t)=>e.id===t.id&&e.directory===t.directory,Ug=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Wg=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Vg(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Hg(e.parentTarget,i)&&Ug(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},Gg=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`}},Kg=`data-mobile-overlay-active`,qg=e=>Array.from(e).some(e=>e.getAttribute(Kg)!==`false`),Jg=`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(`.`),Yg=`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 Xg(){return`${Jg[Math.floor(Math.random()*Jg.length)]}-${Yg[Math.floor(Math.random()*Yg.length)]}`}function Zg(e){let t=Xg();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var Qg=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,$g=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),e_=(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))},t_=async(e,t)=>{await kn(e)&&await rr(t)},n_=e=>{let t=Qg(e),n=gr.getState().projects;if(n.length===0)return null;let r=gr.getState().getActiveProject();if(r?.path){let e=Qg(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=Qg(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>Qg(t.path).length-Qg(e.path).length)[0];return i?{id:i.id,path:i.path}:null},r_=!1,i_=async(e,t)=>{try{let n=gr.getState().projects.find(e=>e.id===t.id)??gr.getState().projects.find(e=>Qg(e.path)===Qg(t.path)),r=wr(t.path);await Ai.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Ai.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),e_(e,$g(Ai.getState()),Zi.getState())}catch{}},a_=async(e,t,n)=>{let r=ri.getState(),i=Ai.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await i_(e,n),Se.getState().setDirectory(t.path,{showOverlay:!1})},o_=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,s_=async e=>{if(r_)return null;let t=gr.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return Br.error(`No active project`,{description:`Please select a project first.`}),null;let r=n_(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return Br.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await fa(r.path)}catch{}if(!i)return Br.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;r_=!0;try{let t=wn(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?o_(n):Zg(),a=n?`existing`:`new`,o=ri.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 da(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(ri.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Se.getState().setDirectory(s.path,{showOverlay:!1}));let c=await rn(r),l=await Zo(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Er(t,l.path),ri.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Se.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=ri.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(ht(n,e instanceof Error?e:Error(t)),ri.getState().resolvePendingDraftWorktreeTarget(n,null)),ri.getState().setDraftBootstrapPendingDirectory(null),Br.error(`Failed to create worktree`,{description:t}),null}finally{r_=!1}};async function c_(){return s_()}async function l_(e){let t=e.branch?.trim();return t?s_({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function u_(e,t,n,r){if(r_)return null;r_=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=n_(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await fa(s.path)}catch{}if(!c)return Br.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await rn(s),u=await Fa(s.path);try{let e=await Zo(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 t_(s,e.path);let n=await ri.getState().createSession(void 0,e.path);if(!n)throw await La(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await a_(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 Br.error(`Failed to create worktree`,{description:t}),null}}finally{r_=!1}}var d_=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},f_=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 p_({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=ct(),{github:a}=ko(),o=to(),s=o.data??null,c=o.isFetched,l=q(e=>e.setSettingsDialogOpen),u=q(e=>e.setSettingsPage),d=q(e=>e.isMobile),{isTablet:f}=mo(),p=d||f,m=gr(e=>e.getActiveProject()),h=Se(e=>e.currentDirectory),g=Z.useMemo(()=>m?.path?.trim()||h?.trim()||null,[m?.path,h]),[_,v]=Z.useState(``),[y,b]=Z.useState(!1),[x,S]=Z.useState(null),C=Z.useRef(0),w=Z.useMemo(()=>d_(_),[_]),T=Ho(_,350),E=w?``:T.trim(),D=!!w||_===T,O=e&&D&&!!g&&!!a?.issuesList&&!(c&&s?.connected===!1),k=Je({queryKey:M.scoped(`github-issues`,g,E),enabled:O,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(g,{page:e,...E?{query:E}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),A=D?k.data?.pages.at(-1)??null:null,j=D?k.data?.pages.flatMap(e=>e.issues??[])??[]:[],N=D&&k.hasNextPage,P=!w&&!D||k.isLoading,F=D&&k.isFetchingNextPage,I=D&&k.error?k.error instanceof Error?k.error.message:String(k.error):null,L=Z.useCallback(()=>k.refetch(),[k]),R=Z.useCallback(async()=>{try{await k.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[k,i]);Z.useEffect(()=>{e||(++C.current,v(``),b(!1),S(null))},[e]),Z.useEffect(()=>{++C.current},[e,g]);let z=!c||s?.connected!==!1&&A?.connected!==!1,B=A?.repo?.url??null,V=Z.useCallback(()=>{u(`github`),l(!0)},[l,u]),H=Z.useCallback(()=>{let e=Ai.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},[]),U=Z.useCallback(()=>{let e=Ai.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=It(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),W=Z.useCallback((e,t)=>{let n=Ai.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},[]),ee=Z.useCallback(async(e,o)=>{let s=++C.current,c=()=>C.current===s;if(n===`select`){if(!g){Br.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Br.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(x)return;S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Br.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){Br.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=f_({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);Br.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&S(null)}return}if(!g){Br.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Br.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!x){S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Br.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){Br.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(y){let e=`issue-${r.number}-${Xg()}`,t=await u_(g,e,void 0,{returnAfterDirectoryCreated:!0});if(!t?.id)throw Error(`Failed to create worktree session`);return{sessionId:t.id,sessionDirectory:t.path}}let e=await Yt(u,g,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??g}})();if(!c())return;er(d,u).catch(()=>void 0);try{ri.getState().initializeNewOpenChamberSession(d,Ai.getState().agents)}catch{}t(!1);let f=Ai.getState(),p=Zi.getState().lastUsedProvider,m=U(),h=m?.providerID||f.currentProviderId||p?.providerID,_=m?.modelID||f.currentModelId||p?.modelID,v=H()||f.currentAgentName||void 0;if(!h||!_){Br.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let b=W(h,_),x=await Ci(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await Ci(`github.issue.review.instructions`);if(!c())return;let C=f_({repo:n.repo,issue:r,comments:l});ri.getState().sendMessage(x,h,_,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],b,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),Br.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&S(null)}}},[y,a,n,t,r,g,H,U,W,x,i]),G=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),K=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),te=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:_,onChange:e=>{v(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(d?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[g?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.noActiveProject`)}),a?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.runtimeUnavailable`)}),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,z===!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)(ua,{variant:`outline`,size:`sm`,onClick:V,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,I?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:I}):null,w&&g&&a&&z?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===w&&`bg-interactive-selection/30`),onClick:()=>void ee(w),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:i(`session.githubIssuePicker.actions.useIssue`,{number:w})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===w?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,j.length===0&&!P&&!I&&z&&a&&g?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:T.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,j.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===e.number&&`bg-interactive-selection/30`),onClick:()=>void ee(e.number,e.sourceRepo),children:[(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground w-12 text-right flex-shrink-0`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsx)(`p`,{className:`typography-small text-foreground truncate`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,p?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":i(`session.githubIssuePicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),N&&z&&g&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void R(),disabled:F||!!x,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(F||!!x)&&`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":y,onClick:()=>b(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),b(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),b(e=>!e)},"aria-label":i(`session.githubIssuePicker.actions.toggleWorktreeAria`),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:y?(0,$.jsx)(X,{name:`checkbox`,className:`h-4 w-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i(`session.githubIssuePicker.actions.createInWorktree`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/70 hidden sm:inline`,children:`(issue-<number>-<slug>)`})]}),(0,$.jsx)(`div`,{className:`hidden sm:block sm:flex-1`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B?(0,$.jsx)(ua,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:B,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:L,disabled:P||!!x,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return d?(0,$.jsx)(sm,{open:e,title:G,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:G}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:K})]}),children:te}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),G]}),(0,$.jsx)(aa,{children:K})]}),te]})})}var m_=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},h_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function g_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ct(),{github:i}=ko(),a=to(),o=a.data??null,s=a.isFetched,c=q(e=>e.setSettingsDialogOpen),l=q(e=>e.setSettingsPage),u=q(e=>e.isMobile),{isTablet:d}=mo(),f=u||d,p=gr(e=>e.getActiveProject())?.path??null,[m,h]=Z.useState(``),[g,_]=Z.useState(!1),[v,y]=Z.useState(null),b=Z.useRef(0),x=Z.useMemo(()=>m_(m),[m]),S=Ho(m,350),C=x?``:S.trim(),w=!!x||m===S,T=e&&w&&!!p&&!!i?.prsList&&!(s&&o?.connected===!1),E=Je({queryKey:M.scoped(`github-prs`,p,C),enabled:T,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(p,{page:e,...C?{query:C}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),D=w?E.data?.pages.at(-1)??null:null,O=w?E.data?.pages.flatMap(e=>e.prs??[])??[]:[],k=w&&E.hasNextPage,A=!x&&!w||E.isLoading,j=w&&E.isFetchingNextPage,N=w&&E.error?E.error instanceof Error?E.error.message:String(E.error):null,P=J(async()=>{try{await E.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Br.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++b.current,h(``),_(!1),y(null))},[e]),Z.useEffect(()=>{++b.current},[e,p]);let F=!s||o?.connected!==!1&&D?.connected!==!1,I=J(()=>{l(`github`),c(!0)}),L=J(async(e,a)=>{if(!p){Br.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){Br.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(v)return;let o=++b.current,s=()=>b.current===o;y(e);try{let o=await i.prContext(p,e,{includeDiff:g,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){Br.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){Br.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){Br.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await Ci(`github.pr.review.instructions`);if(!s())return;n({number:o.pr.number,title:o.pr.title,url:o.pr.url,head:o.pr.head,base:o.pr.base,includeDiff:g,instructionsText:e,contextText:h_(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);Br.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&y(null)}}),R=r(`session.githubPrPicker.title`),z=r(`session.githubPrPicker.description`),B=(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)(Va,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:m,onChange:e=>{h(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":g,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Da,{checked:g,onChange:e=>_(e),ariaLabel:r(`session.githubPrPicker.includeDiffAria`)})}),(0,$.jsx)(`span`,{className:`typography-small text-muted-foreground whitespace-nowrap`,children:r(`session.githubPrPicker.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(u?`min-h-0`:`flex-1 overflow-y-auto`),children:[p?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.noActiveProject`)}),i?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.runtimeUnavailable`)}),A?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.pullRequests`)]}):null,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)(ua,{variant:`outline`,size:`sm`,onClick:I,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,N?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:N}):null,x&&p&&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`,v===x&&`bg-interactive-selection/30`),onClick:()=>void L(x),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:r(`session.githubPrPicker.actions.usePullRequest`,{number:x})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===x?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,O.length===0&&!A&&!N&&F&&i&&p?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:S.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,O.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===e.number&&`bg-interactive-selection/30`),onClick:()=>void L(e.number,e.sourceRepo),children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsxs)(`p`,{className:`typography-small text-foreground truncate`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground mr-1`,children:[`#`,e.number]}),e.title]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,(0,$.jsxs)(`p`,{className:`typography-meta text-muted-foreground truncate`,children:[e.head,` → `,e.base]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,f?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":r(`session.githubPrPicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),k&&F&&p&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:j||!!v,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(j||!!v)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:j?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.more`)]}):r(`session.githubPrPicker.actions.loadMore`)})}):null]})]});return u?(0,$.jsx)(sm,{open:e,title:R,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:R}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:z})]}),children:B}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),R]}),(0,$.jsx)(aa,{children:z})]}),B]})})}function __(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)(Yc,{"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 v_=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)(Yc.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});v_.displayName=`CommandInput`;function y_(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)(pa,{as:Yc.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 b_(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)(Yc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function x_(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)(Yc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function S_(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)(Yc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function C_(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)(Yc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var w_=(e,t)=>`${e}:${S(t)}`,T_=e=>e.type===`skill`||!ne(e.name);function E_(e){let{t}=ct(),n=Z.useMemo(()=>se(),[]),r=q(e=>e.globalDraftStarters),i=gr(e=>e.activeProjectId),a=gr(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[s,c]=Z.useState([]),u=Z.useMemo(()=>r??re,[r]),d=u.some(T_)||s.some(T_),f=Yi({directory:e,enabled:d}),p=Z.useMemo(()=>f.data??[],[f.data]),{refetch:m}=f,h=Ei({directory:e,enabled:d}),g=Z.useMemo(()=>h.data??[],[h.data]),{refetch:_}=h;Z.useEffect(()=>{let e=!1;if(!o){c([]);return}return Jt(o).then(t=>{e||c(t)}).catch(()=>{e||c([])}),()=>{e=!0}},[o?.id]);let v=Z.useCallback(()=>{m(),_()},[m,_]),y=Z.useMemo(()=>new Set(p.map(e=>e.name)),[p]),b=Z.useMemo(()=>new Set(g.map(e=>e.name)),[g]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=ne(e.name);return n?{id:w_(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:y.has(e.name)?{id:w_(r,e),ref:e,group:r,label:x(e.name),icon:K,submitText:`/${e.name}`}:null}return b.has(e.name)?{id:w_(r,e),ref:e,group:r,label:x(e.name),icon:A,submitText:`/${e.name}`}:null},[t,y,b,n]),w=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),T=Z.useMemo(()=>s.map(e=>C(e,`project`)).filter(e=>e!==null),[s,C]),E=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(S(t));for(let t of s)e.add(S(t));return e},[u,s]),D=Z.useMemo(()=>{let e=[];for(let r of O)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 p)t.isBuiltIn||t.source===`skill`||ne(t.name)||e.push({type:`command`,name:t.name,label:x(t.name),icon:K,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of g)e.push({type:`skill`,name:t.name,label:x(t.name),icon:A,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!E.has(`${e.type}:${e.name}`))},[t,p,g,E,n]),k=Z.useCallback(e=>{q.getState().setGlobalDraftStarters(e),U({draftStarters:e})},[]),j=Z.useCallback(e=>{c(e),o&&Ct(o,e)},[o]),M=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||s.some(e=>l(e,t)))return;j([...s,t])}else{let e=r??re;if(e.some(e=>l(e,t)))return;k([...e,t])}},[o,s,r,j,k]),N=Z.useCallback((e,t)=>{e===`project`?j(s.filter(e=>!l(e,t))):k((r??re).filter(e=>!l(e,t)))},[s,r,j,k]),P=Z.useCallback((e,t,n)=>{let i=e===`project`?s:r??re,a=i.findIndex(n=>w_(e,n)===t),o=i.findIndex(t=>w_(e,t)===n);if(a<0||o<0||a===o)return;let c=nc([...i],a,o);e===`project`?j(c):k(c)},[s,r,j,k]);return{global:w,project:T,pinnable:D,hasProject:!!o,ensureLoaded:v,addStarter:M,removeStarter:N,reorder:P}}var D_=`__draft-starter-trash__`,O_=`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`,k_=`max-h-7`,A_=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],j_=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=ct(),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}=rc(s),m;t[2]===d?m=t[3]:(m=ec.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},M_=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(L_),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)(j_,{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)(ac,{items:o,strategy:tc,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},N_=()=>{let e=(0,Q.c)(13),{t}=ct(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:D_},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=Ys(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(O_,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},P_=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=ct(),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)(v_,{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)(b_,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=A_.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(x_,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(C_,{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)(y_,{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)(__,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},F_=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=ct(),[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)(oa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:O_,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)(ea,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(ia,{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)(P_,{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)(ra,{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)(sa,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},I_=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=ct(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=E_(pc()),{isMobile:f}=mo(),[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=$s(Ks(Zs,b),Ks(Js,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)===D_){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:qs.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&&k_,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)(M_,{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)(M_,{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(R_),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:O_,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)(N_,{}):(0,$.jsx)(F_,{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)(Qs,{sensors:S,collisionDetection:Xs,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 L_(e){return e.id}function R_(e){return!e}var z_=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});z_.displayName=`ChatComposerSurface`;var B_=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Pa,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});B_.displayName=`ChatPromptTextarea`;var V_=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},H_=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},U_=e=>{let t=(0,Q.c)(141),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||Fg(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(W_),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=!H&&!U&&ue,he;t[63]!==H||t[64]!==ue||t[65]!==W||t[66]!==C||t[67]!==U||t[68]!==O||t[69]!==me||t[70]!==k?(he=U&&C?(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,className:`flex size-8 shrink-0 items-center justify-center rounded-full outline-none hover:opacity-80`,onClick:C,"aria-label":k,children:(0,$.jsx)(Lg,{className:W?`size-6`:`size-full`})}):(0,$.jsx)(`button`,{type:`submit`,"data-composer-send":`true`,"data-composer-circle":me?`true`:void 0,className:Y(`flex size-8 shrink-0 items-center justify-center outline-none`,me?`rounded-full hover:opacity-80`:`rounded-md text-primary hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`),disabled:H||U||!ue,"aria-label":O,children:me?(0,$.jsx)(Rg,{className:W?`size-6`:`size-full`}):(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]=W,t[66]=C,t[67]=U,t[68]=O,t[69]=me,t[70]=k,t[71]=he):he=t[71];let ge=he,_e=z_,ve=K&&`flex-1`,ye;t[72]!==o||t[73]!==ve?(ye=Y(`relative flex min-h-0 flex-col`,ve,o),t[72]=o,t[73]=ve,t[74]=ye):ye=t[74];let be=K&&`flex min-h-0 flex-1 flex-col`,xe;t[75]!==_||t[76]!==be?(xe=Y(`overflow-hidden`,be,_),t[75]=_,t[76]=be,t[77]=xe):xe=t[77];let Se=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,Ce=K&&`flex min-h-0 flex-1 flex-col`,we;t[78]===Ce?we=t[79]:(we=Y(`relative overflow-hidden`,Ce),t[78]=Ce,t[79]=we);let Te;t[80]!==u||t[81]!==d||t[82]!==p||t[83]!==R?(Te=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[80]=u,t[81]=d,t[82]=p,t[83]=R,t[84]=Te):Te=t[84];let Ee;t[85]===g?Ee=t[86]:(Ee=e=>{te.current=e,H_(g,e)},t[85]=g,t[86]=Ee);let De;t[87]===x?De=t[88]:(De=e=>x(e.target.value,e),t[87]=x,t[88]=De);let Oe=H||U&&G,ke=W?`send`:z?.enterKeyHint,Ae=K&&`min-h-0 flex-1`,je;t[89]!==h||t[90]!==Ae?(je=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,Ae,h),t[89]=h,t[90]=Ae,t[91]=je):je=t[91];let Me=d&&`text-transparent caret-[var(--surface-foreground)]`,Ne;t[92]!==p||t[93]!==Me||t[94]!==R?(Ne=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,Me),t[92]=p,t[93]=Me,t[94]=R,t[95]=Ne):Ne=t[95];let Pe=z?.rows??1,Fe;t[96]!==se||t[97]!==v||t[98]!==T||t[99]!==Ee||t[100]!==De||t[101]!==Oe||t[102]!==ke||t[103]!==je||t[104]!==Ne||t[105]!==Pe||t[106]!==z||t[107]!==B?(Fe=(0,$.jsx)(B_,{...z,simple:!0,ref:Ee,"data-chat-input":`true`,value:B,onChange:De,onKeyDown:se,disabled:Oe,placeholder:T,enterKeyHint:ke,outerClassName:je,className:Ne,style:v,rows:Pe}),t[96]=se,t[97]=v,t[98]=T,t[99]=Ee,t[100]=De,t[101]=Oe,t[102]=ke,t[103]=je,t[104]=Ne,t[105]=Pe,t[106]=z,t[107]=B,t[108]=Fe):Fe=t[108];let Ie;t[109]!==we||t[110]!==Te||t[111]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:we,"data-composer-input-shell":`true`,children:[Te,Fe]}),t[109]=we,t[110]=Te,t[111]=Fe,t[112]=Ie):Ie=t[112];let Le;t[113]!==r||t[114]!==m||t[115]!==xe||t[116]!==Se||t[117]!==Ie?(Le=(0,$.jsxs)(`div`,{className:xe,children:[m,r,Se,Ie]}),t[113]=r,t[114]=m,t[115]=xe,t[116]=Se,t[117]=Ie,t[118]=Le):Le=t[118];let Re;t[119]!==pe||t[120]!==ge||t[121]!==c||t[122]!==f||t[123]!==y||t[124]!==D?(Re=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??ge})]}),t[119]=pe,t[120]=ge,t[121]=c,t[122]=f,t[123]=y,t[124]=D,t[125]=Re):Re=t[125];let ze;t[126]!==s||t[127]!==l||t[128]!==Re?(ze=(0,$.jsx)(V_,{className:s,style:l,children:Re}),t[126]=s,t[127]=l,t[128]=Re,t[129]=ze):ze=t[129];let q;t[130]!==ye||t[131]!==Le||t[132]!==ze?(q=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ye,children:[Le,ze]}),t[130]=ye,t[131]=Le,t[132]=ze,t[133]=q):q=t[133];let Be;return t[134]!==_e||t[135]!==i||t[136]!==a||t[137]!==K||t[138]!==A||t[139]!==q?(Be=(0,$.jsxs)(_e,{className:a,expanded:K,...A,children:[i,q]}),t[134]=_e,t[135]=i,t[136]=a,t[137]=K,t[138]=A,t[139]=q,t[140]=Be):Be=t[140],Be};function W_(e){return e.mime.startsWith(`image/`)}var G_=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),K_=({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}=ct(),[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(()=>G_(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?bi(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?bi(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?bi(m,e,e=>e.label).map(e=>e.item):m},[D,m]),te=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||bi([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),ne=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},re=e=>{g?.(e),B(!1),O(``)},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)(ua,{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)(fo,{asChild:!0,disabled:s,children:l??me}),ge=(0,$.jsxs)(__,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(v_,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(y_,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(b_,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(x_,{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)(C_,{onSelect:ie,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(S_,{}),(0,$.jsxs)(x_,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(C_,{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)(C_,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(S_,{}),(0,$.jsxs)(x_,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(C_,{onSelect:()=>ne(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(C_,{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)(S_,{}),(0,$.jsxs)(x_,{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)(C_,{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)(C_,{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)(_a,{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)($a,{open:z,onOpenChange:B,children:[f||l?he:(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:he}),(0,$.jsx)(Ua,{sideOffset:8,children:c?le:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(uo,{align:ue,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ge})]})};function q_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=bi(t,i,e=>e),o=bi(n,i,e=>e),s=new Set(a.map(e=>e.item)),c=new Set(o.map(e=>e.item));return{matching:[...a.map(e=>({label:e.item,value:e.item,source:`local`,score:e.score})),...o.map(e=>({label:e.item,value:`remotes/${e.item}`,source:`remote`,score:e.score}))].sort((e,t)=>e.score===t.score?e.source===t.source?e.label.length===t.label.length?e.label.localeCompare(t.label,void 0,{sensitivity:`accent`}):e.label.length-t.label.length:e.source===`local`?-1:1:e.score-t.score).map(({label:e,value:t,source:n})=>({label:e,value:t,source:n})),otherLocal:t.filter(e=>!s.has(e)),otherRemote:n.filter(e=>!c.has(e))}}function J_(e,t){return`${e}\0${t}`}function Y_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ct(),i=q(e=>e.isMobile),{github:a}=ko(),o=to(),s=o.data??null,c=o.isFetched,l=q(e=>e.setSettingsDialogOpen),u=q(e=>e.setSettingsPage),d=gr(e=>e.getActiveProject()),f=d?.id??null,p=d?.path??null,m=Z.useMemo(()=>p&&f?{id:f,path:p}:null,[f,p]),[h,g]=Z.useState(`issues`),[_,v]=Z.useState(``),[y,b]=Z.useState([]),[x,S]=Z.useState([]),[C,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState(null),[j,M]=Z.useState(null),[N,P]=Z.useState(!1),[F,I]=Z.useState(new Map),[L,R]=Z.useState(1),[z,B]=Z.useState(!1),V=Z.useRef(0),H=Ho(_,350),U=J(async e=>{if(!(!p||!a)&&!(c&&s?.connected===!1)){w(!0),O(null),R(1),B(!1);try{if(h===`issues`&&a.issuesList){let t=await a.issuesList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(t.issues??[]),R(t.page??1),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=await a.prsList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(t.prs??[]),R(t.page??1),B(!!t.hasMore))}}catch(e){O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{w(!1)}}});Z.useEffect(()=>{if(!e||!p||c&&s?.connected===!1||!a)return;if(!H.trim()){U();return}let t=new AbortController;w(!0),O(null),R(1),B(!1);let n=h===`issues`&&a.issuesList?a.issuesList(p,{page:1,query:H.trim()}):h===`prs`&&a.prsList?a.prsList(p,{page:1,query:H.trim()}):null;if(!n){w(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(e.issues??[]),R(e.page??1),B(!!e.hasMore)):`prs`in e&&(e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(e.prs??[]),R(e.page??1),B(!!e.hasMore))))}).catch(e=>{t.signal.aborted||O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||w(!1)}),()=>t.abort()},[e,p,a,c,s,h,H,U,r]);let W=J(async()=>{if(!(!p||!a)&&!(C||T)&&z){E(!0);try{let e=L+1;if(h===`issues`&&a.issuesList){let t=H.trim()?await a.issuesList(p,{page:e,query:H.trim()}):await a.issuesList(p,{page:e});t.connected!==!1&&(b(e=>[...e,...t.issues??[]]),R(t.page??e),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=H.trim()?await a.prsList(p,{page:e,query:H.trim()}):await a.prsList(p,{page:e});t.connected!==!1&&(S(e=>[...e,...t.prs??[]]),R(t.page??e),B(!!t.hasMore))}}catch{}finally{E(!1)}}});Z.useEffect(()=>{if(!e){g(`issues`),v(``),b([]),S([]),A(null),M(null),P(!1),O(null),I(new Map),R(1),B(!1);return}U()},[e,U]),Z.useEffect(()=>{V.current+=1,I(new Map)},[p,m]);let ee=J(async e=>{if(!m||!e)return;let t=J_(m.path,e);if(F.has(t))return;let n=V.current;try{let i=await Ea(m,{mode:`new`,branchName:e,worktreeName:e});if(n!==V.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);I(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==V.current)return;I(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||h!==`prs`||x.forEach(e=>{e.head&&ee(e.head)})},[e,h,x,p,m,ee]);let G=c&&s?.connected===!0,K=()=>{u(`github`),l(!0)},te=e=>{A(e),M(null)},ne=e=>{M(e),A(null)},re=()=>{k?n({type:`issue`,item:k}):j&&n({type:`pr`,item:j,includeDiff:N}),t(!1)},ie=()=>{A(null),M(null),P(!1)},ae=k||(j?.head&&p?F.get(J_(p,j.head))?.isValid!==!1:!1),oe=e=>!e.head||(p?F.get(J_(p,e.head)):void 0)?.isValid===!1,se=(0,$.jsx)($.Fragment,{children:G?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{value:_,onChange:e=>v(e.target.value),placeholder:r(h===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[C&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),D&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:D})]})}),!C&&!D&&h===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[y.length>0?y.map(e=>(0,$.jsx)(`button`,{onClick:()=>te(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,k?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!C&&!D&&h===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[x.length>0?x.map(e=>{let t=oe(e),n=e.head&&p?F.get(J_(p,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&ne(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,j?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,$.jsx)(X,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:r(`session.githubIntegration.connect.title`)}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:r(`session.githubIntegration.connect.description`)})]}),(0,$.jsx)(ua,{onClick:K,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),ce=(0,$.jsxs)(`div`,{className:Y(`w-full`,i?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-4`,i?`w-full justify-center order-1`:`flex-1`),children:[!i&&(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),h===`prs`&&j&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(Da,{checked:N,onChange:e=>P(e),ariaLabel:r(`session.githubIntegration.includeDiffAria`)}),(0,$.jsx)(`span`,{className:`typography-small text-foreground`,children:r(`session.githubIntegration.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,i?`w-full order-2`:`justify-end`),children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(ua,{size:`sm`,onClick:re,disabled:!ae,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(sm,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:G?ce: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)(Xc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})}),(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,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:se}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(ea,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(ia,{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)(Xc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),se,(0,$.jsx)(ta,{className:`mt-1`,children:ce})]})})})}var X_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},Z_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),Q_=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),$_=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,ev=(e,t,n)=>{let r=Z_(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-${$_(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}`}},tv=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},nv=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function rv({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ct(),{github:a,git:o}=ko(),s=q(e=>e.isMobile),c=Z.useId(),l=to(),u=l.data??null,d=l.isFetched,f=gr(e=>X_(e.projects,e.activeProjectId,r)),p=f?.path??null,m=Z.useMemo(()=>p&&f?{id:f.id,path:p}:null,[f,p]),[h,g]=Z.useState(`new-branch`),[_,v]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[y,b]=Z.useState({selectedBranch:``,worktreeName:``}),x=os(p),S=rs(p),C=Xo(e=>e.fetchBranches),w=Z.useMemo(()=>x?.all?x.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[x]),T=Z.useMemo(()=>x?.all?x.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[x]),E=ri(e=>e.availableWorktreesByProject),D=Z.useMemo(()=>{if(!p)return new Set;let e=E.get(p)??[];return new Set(e.map(e=>e.name))},[E,p]),O=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=Xg();if(!D.has(e))return e}return`${Xg()}-${Date.now().toString(36).slice(-4)}`},[D]),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(!1),[F,I]=Z.useState(!1),[L,R]=Z.useState(!1),[z,B]=Z.useState(``),[V,H]=Z.useState(``),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),G=Z.useRef(null),K=Z.useCallback(e=>{e.stopPropagation()},[]),te=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},[]),ne=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),re=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;ne(t)},[ne]),ie=Z.useCallback(e=>{let t=te(e.current);ne(t)},[te,ne]),ae=Z.useMemo(()=>q_({localBranches:w,remoteBranches:T,query:z}),[w,T,z]),oe=Z.useMemo(()=>q_({localBranches:w,remoteBranches:T,query:V}),[w,T,V]),se=z.trim().length>0,ce=V.trim().length>0,le=ae.matching.length>0,ue=oe.matching.length>0,de=!!(p&&o),fe=Z.useCallback(()=>{!p||!o||C(p,o)},[p,o,C]);Z.useEffect(()=>{!e||!p||!o||x?.all||C(p,o)},[e,p,o,x?.all,C]),Z.useEffect(()=>{!j&&!F&&B(``)},[j,F]),Z.useEffect(()=>{!N&&!L&&H(``)},[N,L]),Z.useEffect(()=>{j&&re(U),F&&ie(ee)},[j,F,z,re,ie]),Z.useEffect(()=>{N&&re(W),L&&ie(G)},[N,L,V,re,ie]);let[pe,me]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[he,ge]=Z.useState(!1),[_e,ve]=Z.useState(null),ye=Z.useCallback(()=>{let e=Ai.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},[]),be=Z.useCallback(()=>{let e=Ai.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=It(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),xe=Z.useCallback((e,t)=>{let n=Ai.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},[]),Se=Z.useCallback(async e=>{if(!p||!a)return;let t=Ai.getState(),n=Zi.getState().lastUsedProvider,r=be(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=ye()||t.currentAgentName||void 0;if(!o||!s){Br.error(i(`session.newWorktree.error.noModelSelected`));return}let l=xe(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await Ci(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await Ci(`github.issue.review.instructions`),d=tv({repo:t.repo,issue:t.issue,comments:n.comments??[]});await ri.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Br.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(p,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await Ci(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await Ci(`github.pr.review.instructions`),u=nv(t);await ri.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Br.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,p,ye,be,xe,i]),Ce=h===`new-branch`?_:y;Z.useEffect(()=>{if(!e||!x?.all||!p||_.sourceBranch)return;let t=_.sourceBranch,n=!1;return(async()=>{try{let e=await Fa(p).catch(()=>null);if(n)return;let r=localStorage.getItem(Yo),{sourceBranch:i,shouldClearSavedSourceBranch:a}=as({branches:x.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Yo),n||t)return;i&&v(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,x?.all,p,_.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;g(`new-branch`),b({selectedBranch:``,worktreeName:``}),M(!1),P(!1),I(!1),R(!1),B(``),H(``),me({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=O();v({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,O]),Z.useEffect(()=>{if(h!==`new-branch`||!_.isSyncingWorktreeName)return;let e=Q_(Z_(_.branchName));v(t=>({...t,worktreeName:e}))},[h,_.branchName,_.isSyncingWorktreeName]);let we=Z.useCallback(async()=>{if(!m||!pe.touched||he)return;_e&&_e.abort();let e=new AbortController;ve(e),me(e=>({...e,isValidating:!0}));try{let t=h===`new-branch`?_.branchName:y.selectedBranch,n=Ce.worktreeName,r=Z_(t),a=Q_(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=h===`new-branch`?_.linkedPr:null,n=t?ev(t,w,T):null,i=await Ea(m,{mode:h===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(h===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||me(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||me(e=>({...e,isValidating:!1}))}},[m,h,_.branchName,_.linkedPr,y.selectedBranch,Ce.worktreeName,w,T,pe.touched,_e,he,i]),Te=h===`new-branch`?_.branchName:y.selectedBranch;Z.useEffect(()=>{if(!e||!m||!pe.touched||he)return;let t=setTimeout(()=>{we()},300);return()=>clearTimeout(t)},[Ce.worktreeName,Te,e,m,we,pe.touched,he]);let Ee=async()=>{if(!m||!p){Br.error(i(`session.newWorktree.error.noActiveProject`));return}me(e=>({...e,touched:!0}));let e=h===`new-branch`?_.branchName:y.selectedBranch,r=Ce.worktreeName,a=Z_(e),o=Q_(r);if(!a){Br.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){Br.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}_e&&(_e.abort(),ve(null)),me(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),ge(!0);try{let e=h===`new-branch`?_.linkedPr:null,r=h===`new-branch`?_.linkedIssue:null,s=h===`new-branch`?_.linkedPr:null,c=h===`new-branch`&&_.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([rn(m),ns(p)]),f=_.sourceBranch,g=``,v=(()=>{if(e){let t=ev(e,w,T);return g=t.sourceLabel,{preferredName:a||o,mode:`existing`,branchName:a,worktreeName:o,existingBranch:t.existingBranch,setupCommands:u,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return g=h===`new-branch`?f:``,{preferredName:a||o,mode:h===`existing-branch`?`existing`:`new`,branchName:h===`existing-branch`?void 0:a,worktreeName:o,existingBranch:h===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&h===`new-branch`?{startRef:f}:{}}})(),b=await us(p,v,{resolvedRootTrackingRemote:d}),x=await Ia(m,b),S=null;if(l){await kn(m)&&await rr(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Yt(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),ge(!1),er(a.id,e).catch(()=>void 0);try{ri.getState().initializeNewOpenChamberSession(a.id,Ai.getState().agents)}catch{}}else t(!1),ge(!1);let C=cs({mode:h,sourceBranch:_.sourceBranch,linkedPr:!!_.linkedPr,selectedBranch:y.selectedBranch});C&&localStorage.setItem(Yo,C),Br.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${g?` ${i(`session.newWorktree.fromSource`,{source:g})}`:``}`})}),S?Se({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`);Br.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`);Br.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{ge(!1)}},De=e=>{g(e),me(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},Oe=e=>{if(!e){v(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${Xg()}`;v(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:Q_(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;v(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:Q_(t.head),isSyncingWorktreeName:!0}))}},ke=d&&u?.connected===!0,Ae=(h===`existing-branch`?!!y.selectedBranch&&!!y.worktreeName&&!pe.branchError&&!pe.worktreeError:!!Z_(_.branchName)&&!!_.worktreeName&&!pe.branchError&&!pe.worktreeError)&&!he,je=()=>{v(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Me=(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:pe.touched&&(pe.branchError||pe.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:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s&&`w-full`),children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,className:Y(s&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ua,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:Y(`gap-1.5`,s&&`flex-1`),children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[s?(0,$.jsx)(_a,{id:`new-worktree-sheet-${c}`,open:e,onOpenChange:t,title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(pa,{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)(Xc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>I(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:y.selectedBranch?`text-foreground`:`text-muted-foreground`,children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(sm,{open:F,title:i(`session.newWorktree.selectBranch`),onClose:()=>I(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:ee,children:[(0,$.jsx)(Va,{value:z,onChange:e=>B(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[se&&le&&(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:ae.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:Q_(e.label)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.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(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e,worktreeName:Q_(e)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),ae.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(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:Q_(e)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&ke&&(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Va,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=Q_(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===Q_(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===Q_(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Va,{value:Ce.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>R(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:_.sourceBranch?`text-foreground`:`text-muted-foreground`,children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})}),(0,$.jsx)(sm,{open:L,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>R(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(Va,{value:V,onChange:e=>H(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[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:()=>{v(t=>({...t,sourceBranch:e.value})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),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:()=>{v(t=>({...t,sourceBranch:e})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),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:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Me})]})}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(ea,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(ia,{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)(Xc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)($a,{open:j,onOpenChange:M,children:[(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,y.selectedBranch?`text-foreground`:`text-muted-foreground`),children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(uo,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:U,children:(0,$.jsxs)(__,{shouldFilter:!1,children:[(0,$.jsx)(v_,{placeholder:i(`session.newWorktree.searchBranches`),value:z,onValueChange:B,onKeyDown:K}),(0,$.jsx)(y_,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(b_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[se&&le&&(0,$.jsx)(x_,{heading:i(`session.newWorktree.matchingBranches`),children:ae.matching.map(e=>(0,$.jsx)(C_,{value:e.value,onSelect:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:Q_(e.label)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[se&&(0,$.jsx)(S_,{}),(0,$.jsx)(x_,{heading:i(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:ae.otherLocal.map(e=>(0,$.jsx)(C_,{value:e,onSelect:()=>{b(t=>({...t,selectedBranch:e,worktreeName:Q_(e)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),ae.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(ae.otherLocal.length>0||se)&&(0,$.jsx)(S_,{}),(0,$.jsx)(x_,{heading:i(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:ae.otherRemote.map(e=>(0,$.jsx)(C_,{value:`remotes/${e}`,onSelect:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:Q_(e)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&ke&&(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Va,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=Q_(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===Q_(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===Q_(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Va,{value:Ce.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)($a,{open:N,onOpenChange:P,children:[(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,_.sourceBranch?`text-foreground`:`text-muted-foreground`),children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(uo,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:W,children:(0,$.jsxs)(__,{shouldFilter:!1,children:[(0,$.jsx)(v_,{placeholder:i(`session.newWorktree.searchBranches`),value:V,onValueChange:H,onKeyDown:K}),(0,$.jsx)(y_,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(b_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(x_,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(C_,{value:e.value,onSelect:()=>{v(t=>({...t,sourceBranch:e.value})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),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)(S_,{}),(0,$.jsx)(x_,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(C_,{value:e,onSelect:()=>{v(t=>({...t,sourceBranch:e})),P(!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)(S_,{}),(0,$.jsx)(x_,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(C_,{value:`remotes/${e}`,onSelect:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)(ta,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:pe.touched&&(pe.branchError||pe.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:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ua,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:`gap-1.5`,children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(Y_,{open:k,onOpenChange:A,onSelect:Oe})]})}function iv(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 av(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 ov=(e,t)=>e??t??null,sv=(e,t)=>!!e&&t!==!1,cv=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:[]},lv=e=>e.replace(/^remotes\//,``).trim(),uv=e=>{let t=lv(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},dv=({directory:e,projectDirectory:t,label:n,projectRootOption:r,worktreeOptions:i,onSelectDirectory:a,className:o,maxWidthClassName:c=`max-w-[48vw] sm:max-w-[20rem]`,presentation:l=`dropdown`})=>{let{t:u}=ct(),{git:d}=ko(),f=ov(t,e),p=e,m=fs(f),h=fs(p),g=sv(f,m),_=p!==f&&sv(p,h),v=Po(f,d,g),y=Po(p,d,_),b=v.data,x=p===f?b:y.data,S=Xo(e=>e.fetchStatus),C=Xo(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=ds(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=gr(e=>e.projects),P=gr(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=s(t);if(e){let t=N.find(t=>s(t.path)===e);if(t)return t.id}return P},[P,t,N]),{localBranches:I,remoteBranches:L}=Z.useMemo(()=>cv(b?.all),[b]),R=x?.current?.trim()||C||null,z=!av(n,e)&&n||R||n||u(`chat.chatInput.branch`),B=J(async()=>{if(!d)return;let e=new Set;f&&e.add(f),p&&e.add(p),await Promise.all([...e].map(async e=>{await Go(e,d),await S(e,d,{silent:!0})}))}),V=J(e=>{let t=lv(e),n=uv(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),H=J(async e=>{if(!p||!d)return;let t=lv(e);if(R!==t&&R!==uv(t))try{await d.checkoutBranch(p,t),Br.success(u(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:u(`gitView.toast.checkoutFailed`,{name:t});Br.error(n)}}),U=J(e=>{let t=lv(e);if(!t||R===t||R===uv(t))return;let n=V(t);if(n){a(n.value);return}O(t)}),W=J(async()=>{if(!(!D||k)){A(!0);try{await H(D),O(null)}finally{A(!1)}}}),ee=J(async()=>{if(!(!D||k)){A(!0);try{await l_({branch:D,projectDirectory:t??void 0})&&O(null)}finally{A(!1)}}}),G=J(async(e,t)=>{if(!p||!d)return;let n=t?.name??`origin`;try{await d.createBranch(p,e,R??`HEAD`),Br.success(u(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),Br.success(u(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:u(`gitView.toast.branchCreatedLocally`);Br.warning(u(`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:u(`gitView.toast.createBranchFailed`);throw Br.error(t),e}}),K=J(()=>{let e=gr.getState(),n=s(t),r=n?e.projects.find(e=>s(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),te=J((e,n)=>{if(M(!1),n?.sessionId){ri.getState().setCurrentSession(n.sessionId,e);return}let r=gr.getState(),i=s(t),a=(i?r.projects.find(e=>s(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=ri.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),Se.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`,l===`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`,c,hm,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}),l===`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)(K_,{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:l,onOpenChange:T}),j?(0,$.jsx)(rv,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:te}):null,(0,$.jsx)(sa,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ra,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(ea,{children:[(0,$.jsx)(ia,{children:u(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(aa,{children:u(`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`}),u(`chat.chatInput.branchSwitch.checkoutHere`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:u(`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`}),u(`chat.chatInput.branchSwitch.createWorktree`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:u(`chat.chatInput.branchSwitch.createWorktreeDescription`)})]})]}),(0,$.jsx)(ta,{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:u(`chat.chatInput.branchSwitch.cancel`)})})]})})]})},fv=[],pv=[],mv={revertMessageID:void 0,records:pv},hv=e=>e.role===`user`,gv=(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},_v=(e,t,n=mv)=>{if(!t)return mv;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return mv;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!hv(e)||!gn(i,e.id,r)||o.push({message:e,parts:a[e.id]??fv});let s=o.length===0?pv:o;return n.revertMessageID===r&&gv(n.records,s)?n:{revertMessageID:r,records:s}},vv={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},yv={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`},bv=`text-foreground`;function xv(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 Sv=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function Cv(e){let t=Sv.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function wv(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function Tv(e){let t=[];if(!e)return t;let n=0,r=!1,i=``,a=e.split(`
|
|
6522
|
-
`);for(let e=0;e<a.length;e+=1){let o=a[e],s=n,c=s+o.length;if(n=c+1,r){t.push({start:s,end:c,style:`codeFence`}),
|
|
6523
|
-
`),r=0;for(let e=0;e<n.length;e+=1){let i=n[e];r+=i.length+1;let a=
|
|
6524
|
-
`);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${Mv} text-[var(--syntax-foreground)]`,priority:Nv}),!(d.length>zv)))try{let e=o.parser.parse(d);Xe(e,Lv,(e,n,r)=>{let i=Rv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:Pv})})}catch{}}return t}var Hv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Uv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Wv=e=>{if(!Uv(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(`/`)},Gv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Wv(n):Uv(n))?n:null},Kv=(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)Kv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))Kv(r,t,n+1)}},qv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Gv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Gv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;Kv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Jv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Hv){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 qv(r,i))t.add(e)}return Array.from(t)},Yv=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}}},Xv=e=>Uv(e);function Zv(e,t){let n=(0,Q.c)(5),r=_t(e,t),i=q(Qv),a;n[0]===r?a=n[1]:(a=sn(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 Qv(e){return e.sessionGoalEnabled}function $v(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 Mt(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 ey={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},ty={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`},ny=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ct(),i=q(e=>e.isMobile),{goal:a,enabled:o}=Zv(e??``,t),s=$v(e??``,a),c=Fi(e??``,t),l=En(e,t),u=Z.useRef(null),[d,f]=Z.useState(!1),[p,m]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=l[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;u.current!==r&&(u.current=r,Ot(e,t))},[e,t,a,l]);let h=J(async n=>{if(!(!e||d)){f(!0);try{await hn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{f(!1)}}});if(!e||!o||!a)return null;let g=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:p)-(a.createdAt||p)),_=vt(g),v=a.tokenBudget?`${Gr(a.tokensUsed)}/${Gr(a.tokenBudget)}`:a.tokensUsed>0?Gr(a.tokensUsed):null,y=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,b=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,x=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,S=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(S,`flex-shrink-0`),style:{color:ey[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,x),children:a.note||s||``}),a.status===`active`&&(!c||c.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,b),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(S,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,b),children:r(ty[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:_}),v?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:v}):null,y?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(y.next),disabled:d,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(y.labelKey),children:[(0,$.jsx)(X,{name:y.icon,className:S,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(y.labelKey)})]}):null]})});ny.displayName=`SessionGoalRow`;var ry=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ct(),{goal:i,enabled:a}=Zv(e??``,t),o=yn(e=>e.armed),s=yn(e=>e.setArmed),[c,l]=Z.useState(!1);if(se()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,d=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Ln(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void d(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});ry.displayName=`SessionGoalButton`;var iy=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ct();if(!yn(ay)||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});iy.displayName=`SessionGoalObjectiveCounter`;function ay(e){return e.armed}var oy=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),sy=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),cy=/^\/\u2003?([^\s]+)/i,ly=/^\/\u2003?goal\b/i,uy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(cy)?.[1]?.toLowerCase();return n&&oy.has(n)?n:null},dy=(e,t)=>uy(e,t)===`goal`?e.trimStart().replace(ly,``).trim():null,fy=(e,t)=>uy(e,t)!==null,py=(e,t)=>{let n=uy(e,t);return n!==null&&sy.has(n)},my=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},hy=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()}},gy=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,_y=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,vy=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},yy=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),by=(e,t)=>{let n=b.getState();return n.bindLegacyQueue(v(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},xy=async e=>{let t=mn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=yy(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}by(n,a)?r+=1:i+=1}catch{try{by(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Sy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Cy=e=>e===`allow`||e===`ask`||e===`deny`,wy=e=>{if(Cy(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`&&Cy(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(Cy(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))Cy(i)&&t.push({permission:n,pattern:e,action:i})}return t},Ty=e=>{let t=wy(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},Ey=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Ty(e.permission));let r=e.find(e=>e?.name===n);return!r||Ty(r.permission)},Dy=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)},Oy=null,ky=new Set,Ay=()=>{for(let e of ky)e()},jy=e=>e===`chat`||e===`assistant`,My=()=>Oy,Ny=e=>{Oy!==e&&(Oy=e,Ay())},Py=e=>{Oy&&(e&&Oy.surfaceID!==e||(Oy=null,Ay()))},Fy=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Iy=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}},Ly=(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}),Ry=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=Ly(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=Ly(e,`send`,i),o=Km(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=Ly(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Ly(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Ly(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Km(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>zm(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=Ly(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Ly(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},zy=(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)))},By=(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},Vy=(e,t)=>e.agents.some(e=>e.name===t),Hy=(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},Uy=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Hy(t,n,r,i)?i:void 0;if(a&&Hy(t,n,r,a))return a},Wy=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!By(r,n.providerID,n.modelID))return null;let s=n.agent&&Vy(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Vy(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Vy(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=Uy({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:c});return{agent:s,providerID:n.providerID,modelID:n.modelID,variant:l,source:o,messageId:n.id}},Gy=e=>{let{sessionId:t,latestUserChoice:n,latestExecution:r,catalog:i,memory:a,sessionEntity:o,fallbackAgentName:s,transcriptReady:c=!0}=e;if(c&&r){let e=Wy({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=Wy({sessionId:t,choice:n,catalog:i,memory:a,fallbackAgentName:s,source:`history`});if(e)return e}if(c&&a){let e=a.getSessionAgentSelection?.(t)??null,n=e&&Vy(i,e)?e:s&&Vy(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&By(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&Hy(i,e.providerId,e.modelId,r)?r:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let r=a.getSessionModelSelection?.(t);if(r&&By(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&Hy(i,r.providerId,r.modelId,e)?e:void 0;return{agent:n,providerID:r.providerId,modelID:r.modelId,variant:o,source:`session-memory`}}}let l=o?.model;if(l&&By(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&Vy(i,o.agent)?o.agent:void 0)??(e&&Vy(i,e)?e:s&&Vy(i,s)?s:void 0),r=l.variant,c=r&&Hy(i,l.providerID,l.id,r)?r:void 0;return{agent:n,providerID:l.providerID,modelID:l.id,variant:c,source:`session-entity`}}return null},Ky=(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))},qy=(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}},Jy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Yy=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}:{}}},Xy=e=>typeof e==`string`&&e.trim().length>0?e:void 0,Zy=e=>Xy(e.agent)??Xy(e.mode),Qy=e=>Xy(e.model?.variant)??Xy(e.variant),$y=e=>{let t=Xy(e.model?.providerID),n=Xy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},eb=e=>{let t=Xy(e.providerID)??Xy(e.model?.providerID),n=Xy(e.modelID)??Xy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},tb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=$y(n);return{id:typeof n.id==`string`?n.id:void 0,agent:Zy(n),providerID:r?.providerID,modelID:r?.modelID,variant:Qy(n)}}return null},nb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`user`){if($y(n))return null;continue}if(n.role!==`assistant`)continue;let r=eb(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:Zy(n),providerID:r.providerID,modelID:r.modelID,variant:Qy(n)}}return null},rb=500,ib=e=>Array.from(e).length,ab=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},ob=e=>ib(e)>=rb,sb=e=>{let t=h(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},cb=(e,t)=>{let n=t??e;return typeof n!=`string`||!ob(n)?!1:ae(typeof e==`string`?{text:``,references:[]}:e,n)},lb=(e,t,n,r,i=1)=>{let a=ib(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}-${ab(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},ub=e=>({text:e.text,references:e.references.map(e=>({...e}))}),db=e=>e.map(e=>({...e,range:{...e.range}})),fb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),pb=(e,t,n)=>({document:ub(e),mentions:db(t),selection:{...n}}),mb=()=>({undo:[],redo:[]}),hb=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),gb=(e,t)=>{let n=e.undo.at(-1);return!n||!fb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:pb(n.before.document,n.before.mentions,n.before.selection)}},_b=(e,t)=>{let n=e.redo.at(-1);return!n||!fb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:pb(n.after.document,n.after.mentions,n.after.selection)}},vb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),yb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),bb=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),xb=e=>JSON.stringify([e.text,e.references]),Sb=(e,t)=>e!==null&&t!==null&&ie(e)===t,Cb=(e,t,n)=>{let r=e?bb(e):null,i=r?n(r):void 0;return{document:w(vb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ie(r):null}},wb=(e,t,n,r)=>{if(!t||ie(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=xb(vb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===xb(e)?`same-document-metadata`:`external-document`},Tb=(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}]:[]})},Eb=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),Db=(e,t,n,r,i=r)=>{let a=f(e,n,r,i);return{document:a.document,mentions:Tb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},Ob=(e,t,n)=>({preview:{real:yb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),kb=e=>({document:e.real,mentions:e.realMentions}),Ab=(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)})},jb=(e,t)=>{let n=vb(t),r=C(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:Ab(e.mentions,t?.mentions??[],r,i)}},Mb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=ei})=>{let a=e?ie(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`),l=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[u,d]=(0,Z.useState)(()=>Cb(e,t,i.getState().getDraft).document),[p,m]=(0,Z.useState)(()=>Cb(e,t,i.getState().getDraft).mentions),[_,v]=(0,Z.useState)(`compose`),[y,b]=(0,Z.useState)(0),x=(0,Z.useRef)(u),S=(0,Z.useRef)(p),C=(0,Z.useRef)(t),E=(0,Z.useRef)(r),O=(0,Z.useRef)(e),k=(0,Z.useRef)(e?bb(e):null),A=(0,Z.useRef)(a),j=(0,Z.useRef)(a),M=(0,Z.useRef)(0),N=(0,Z.useRef)(o?.revision??0),P=(0,Z.useRef)(void 0),F=(0,Z.useRef)(void 0),I=(0,Z.useRef)(mb());x.current=u,S.current=p,C.current=t,E.current=r,O.current=e,A.current=a;let L=(0,Z.useCallback)((e,t)=>{x.current=e,S.current=t,d(e),m(t)},[]),R=(0,Z.useCallback)((e,t)=>{let n=D(e,t);E.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{M.current+=1;let e=M.current;j.current=a;let t=Cb(O.current,C.current,i.getState().getDraft),n=t.key;if(k.current=t.key,P.current=void 0,F.current=void 0,I.current=mb(),v(`compose`),N.current=t.revision,L(t.document,t.mentions),b(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!Sb(k.current,a)||j.current!==a||A.current!==a||M.current!==e||N.current!==r||o?.revision!==t.revision||(N.current=t.revision,L(w(vb(t),C.current),t.mentions))})}},[a,L,i]),(0,Z.useEffect)(()=>{if(!a||j.current!==a||F.current)return;let e=wb(x.current,o,P.current,{keyID:a,epoch:M.current,appliedRevision:N.current});if(e!==`ignore`){if(o&&(N.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&m(o.mentions);return}e===`external-document`&&o&&(P.current=void 0,L(w(vb(o),C.current),o.mentions),v(`compose`),b(e=>e+1))}},[a,L,o]);let z=(0,Z.useCallback)((e,t)=>{let n=k.current;if(!Sb(n,A.current)||F.current)return;let r=x.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Eb(t)});if(!a)return;let o=vb(a);return P.current={keyID:ie(n),revision:a.revision,fingerprint:xb(o)},N.current=a.revision,L(o,a.mentions),R(r,o),a},[i,L,R]),B=(0,Z.useCallback)((e,t,n,r,i,a)=>{I.current=hb(I.current,{before:pb(e,t,n),after:pb(r,i,a)})},[]),V=(0,Z.useCallback)(()=>F.current?(F.current=void 0,v(`compose`),!0):!1,[]),H=(0,Z.useCallback)(e=>(V(),z({text:e,references:[]},[])),[z,V]),U=(0,Z.useCallback)((e,t=[])=>{V();let n=te(e.text,e.references);return n?z(w(n,C.current),t):void 0},[z,V]),W=(0,Z.useCallback)((e,t,n=t,r)=>{let i=V(),a=yb(x.current),o=i?[]:S.current,s=Db(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return z(s.document,c),s.removedReferences.length>0&&B(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[z,V,B]),ee=(0,Z.useCallback)((e,t)=>{let n=x.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=V(),o=f(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=Tb(a?[]:S.current,o.document,o.edit);return z(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[z,V]),G=(0,Z.useCallback)((e,t)=>{let n=x.current;return ee({start:0,end:n.text.length,text:e},t)},[ee]),K=(0,Z.useCallback)((e,t,n,r)=>{let i=V(),a=c(x.current,e,t,n,r);return z(a.document,Tb(i?[]:S.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[z,V]),ne=(0,Z.useCallback)(e=>{let t=yb(x.current),n=g(t,e);if(!n)return null;let r=V()?[]:S.current,i=Tb(r,n.document,n.edit),a=T(n.document.text,n.caret),o=f(n.document,a.text,a.caret),s=Tb(i,o.document,o.edit);return z(o.document,s),B(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[z,V,B]),re=(0,Z.useCallback)(e=>{if(F.current)return null;let t=e===`undo`?gb(I.current,x.current):_b(I.current,x.current);return!t||!z(t.snapshot.document,t.snapshot.mentions)?null:(I.current=t.history,t.snapshot.selection)},[z]),ae=(0,Z.useCallback)(e=>z(x.current,e),[z]),oe=(0,Z.useCallback)(e=>{let t=F.current?{document:{text:e.text,references:[]},mentions:[]}:Ob(x.current,S.current,e);`preview`in t&&(F.current=t.preview),v(`history-preview`),L(t.document,t.mentions),b(e=>e+1)},[L]),se=(0,Z.useCallback)(()=>{let e=F.current;if(!e)return;F.current=void 0,v(`compose`);let t=kb(e);L(t.document,t.mentions),b(e=>e+1)},[L]),ce=(0,Z.useCallback)(()=>{let e=k.current;if(!Sb(e,A.current))return null;let t=i.getState().getDraft(e);return{key:bb(e),keyID:ie(e),revision:t?.revision??0,document:yb(x.current),mentions:S.current.map(e=>({...e,range:{...e.range}})),epoch:M.current,runtime:i.getState().captureDraftRuntime()}},[i]),le=(0,Z.useCallback)(e=>{let t=jb(e,i.getState().getDraft(e.key)),n=vb(i.getState().getDraft(e.key)),r=h(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Eb(t.mentions)});if(a){let e=vb(a);R(r,e)}return a},[R,i]),ue=(0,Z.useCallback)(()=>x.current,[]);return(0,Z.useMemo)(()=>({document:u,mentions:p,confirmedFileMentions:p.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:_,hydration:s,persistence:l,textPresetEpoch:y,getDocument:ue,replacePlainDocument:H,replaceMaterializedDocument:U,applyBrowserEdit:W,applyProgrammaticEdit:ee,replaceProgrammaticText:G,insertReference:K,deleteReference:ne,restoreReferenceHistory:re,commitMentions:ae,enterHistoryPreview:oe,exitHistoryPreview:se,captureSubmission:ce,recoverSubmission:le}),[W,ee,ce,ae,ne,u,oe,se,ue,s,_,K,p,l,le,U,H,G,re,y])};function Nb(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 Pb=`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`,Fb=ks(()=>Ue(()=>import(`./ToolOutputDialog-1bp7aeoj.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),Ib=[],Lb=[],Rb=[],zb=[],Bb=/^@[^\s]+$/,Vb=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Hb=/^(https?:\/\/|mailto:)\S+$/i,Ub=560,Wb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Gb=(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)},Kb=e=>e.includes(`@`)?`paste`:`manual`,qb=(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}},Jb=(e,t)=>ur(e,t).some(e=>e.role===`user`),Yb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Wn(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6525
|
-
`).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},Xb=`file://`,Zb=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(`/`)},Qb=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Xb)?t:`file://${Zb(t)}`},$b=e=>{if(!e)return[];let t=[...Jv(e).map(Yv),...Array.from(e.files||[]).map(e=>oe(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(Xv)))},ex=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},tx=e=>ca(e.path),nx=(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)]})},rx=Z.memo(fh),ix=Z.memo(ru),ax=Z.memo(Eg),ox=Z.memo(kg),sx=Z.memo(Hh),cx=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ct(),r=q(e=>e.isMobile),i=ri(e=>e.revertToMessage),a=ri(e=>e.forkFromMessage),o=ri(e=>e.handleSlashRedo),[s,c]=Z.useState(null),[l,u]=Z.useState(null),[d,f]=Z.useState(!0),p=Z.useRef(mv),m=Ir(),h=t||m,g=Vt(h),_=br(e??``,h,g),v=tn(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=_v({session:v,messages:t,partsByMessageID:_.partsByMessageID},e,p.current);return p.current=n,n},[e,v,_]),b=y.revertMessageID,x=Z.useMemo(()=>y.records.map(e=>e.message),[y]),S=n(`chat.revertPopover.noTextContent`),C=Z.useMemo(()=>b?y.records.map(e=>({id:e.message.id,text:Yb(e.parts,S)})):[],[S,b,y]),w=C[0]?.id;Z.useEffect(()=>{f(!0)},[b,w]);let T=Z.useCallback(async t=>{if(!(!e||s)){c(t);try{let n=x.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{c(null)}}},[o,i,s,e,x]),E=Z.useCallback(async t=>{if(!(!e||l)){u(t);try{await a(e,t)}finally{u(null)}}},[a,l,e]);return!e||C.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>f(e=>!e),"aria-expanded":!d,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,C.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!d&&`rotate-180`),"aria-hidden":`true`})]}),!d&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:C.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)(ua,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{E(e.id)},children:[l===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(ua,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{T(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))})]})})});cx.displayName=`RevertedMessageDock`;var lx=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=ct(),{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?yx:void 0,v=f?bx: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)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:S}),(0,$.jsx)(Ua,{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),ux=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=ct(),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=()=>Dy({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)(Ha,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:xx,onPointerDownCapture:Sx,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)(Ua,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Wa,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),dx=Z.memo(function(e){let t=(0,Q.c)(67),{isMobile:n,compact:r,footerIconButtonClass:i,stopFooterIconButtonClass:a,compactCircleButtonClass:o,sendIconSizeClass:s,stopIconSizeClass:c,canSend:l,canAbort:u,hasContent:d,currentSessionId:f,newSessionDraftOpen:p,draftSubmitting:m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v,onPrimaryAction:y,onAbort:b}=e,x=r!==void 0&&r,{t:S}=ct(),C,w,T,E,D;if(t[0]!==u||t[1]!==l||t[2]!==x||t[3]!==o||t[4]!==f||t[5]!==m||t[6]!==i||t[7]!==d||t[8]!==n||t[9]!==p||t[10]!==y||t[11]!==v||t[12]!==_||t[13]!==s||t[14]!==g||t[15]!==a||t[16]!==c||t[17]!==h||t[18]!==S){D=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Gg({canSend:l,hasSessionTarget:!!(f||p),draftSubmitting:!!m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:Cx,onPointerDownCapture:wx}:{},t[24]=n,t[25]=r);let b=r,O=g.inFlight,k=O&&g.flightKind===`queue`,A=O&&g.flightKind!==`queue`,j;t[26]!==u||t[27]!==v||t[28]!==_||t[29]!==k||t[30]!==A||t[31]!==S?(j=S(k?`chat.chatInput.actions.queuingMessageAria`:A?`chat.chatInput.actions.sendingMessageAria`:_&&v&&u?`chat.chatInput.actions.sendMessageAria`:u?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[26]=u,t[27]=v,t[28]=_,t[29]=k,t[30]=A,t[31]=S,t[32]=j):j=t[32];let M=j;C=x?o??a??i:a??i,w=c;let N=!u&&(!e.sendDisabled||O),P;t[33]!==n||t[34]!==y?(P=e=>{n&&(e.preventDefault(),y())},t[33]=n,t[34]=y,t[35]=P):P=t[35];let F;t[36]!==u||t[37]!==O||t[38]!==k||t[39]!==A||t[40]!==S?(F=S(A||!u&&O?k?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[36]=u,t[37]=O,t[38]=k,t[39]=A,t[40]=S,t[41]=F):F=t[41];let I;t[42]!==u||t[43]!==w||t[44]!==O||t[45]!==s||t[46]!==N?(I=N?(0,$.jsx)(Rg,{className:w,spinning:!!(O&&!u)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[42]=u,t[43]=w,t[44]=O,t[45]=s,t[46]=N,t[47]=I):I=t[47];let L=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":N?`true`:void 0,disabled:e.sendDisabled,"aria-busy":O||void 0,...b,onClick:P,className:Y(N?C:i,N?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":F,children:I});if(!u){D=L;break bb0}let R=!x&&(d||k),z=!e.sendDisabled&&!k,B=x&&`h-full`;t[48]===B?T=t[49]:(T=Y(`relative z-30 overflow-visible`,B),t[48]=B,t[49]=T),E=R?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":z||k?`true`:void 0,disabled:e.sendDisabled||k,"aria-busy":k||void 0,...b,onClick:e=>{e.preventDefault(),!k&&y()},className:Y(z||k?C:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,z||k?void 0:e.disabledClass),"aria-label":M,children:z||k?(0,$.jsx)(Rg,{className:w,spinning:k}):(0,$.jsx)(X,{name:`send-plane-2`,className:s})}):null}t[0]=u,t[1]=l,t[2]=x,t[3]=o,t[4]=f,t[5]=m,t[6]=i,t[7]=d,t[8]=n,t[9]=p,t[10]=y,t[11]=v,t[12]=_,t[13]=s,t[14]=g,t[15]=a,t[16]=c,t[17]=h,t[18]=S,t[19]=C,t[20]=w,t[21]=T,t[22]=E,t[23]=D}else C=t[19],w=t[20],T=t[21],E=t[22],D=t[23];if(D!==Symbol.for(`react.early_return_sentinel`))return D;let O;t[50]===C?O=t[51]:(O=Y(C,`relative z-30`),t[50]=C,t[51]=O);let k;t[52]===S?k=t[53]:(k=S(`chat.chatInput.actions.stopGeneratingAria`),t[52]=S,t[53]=k);let A;t[54]===w?A=t[55]:(A=Y(w),t[54]=w,t[55]=A);let j;t[56]===A?j=t[57]:(j=(0,$.jsx)(Lg,{className:A}),t[56]=A,t[57]=j);let M;t[58]!==b||t[59]!==O||t[60]!==k||t[61]!==j?(M=(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,onClick:b,className:O,"aria-label":k,children:j}),t[58]=b,t[59]=O,t[60]=k,t[61]=j,t[62]=M):M=t[62];let N;return t[63]!==T||t[64]!==E||t[65]!==M?(N=(0,$.jsxs)(`div`,{className:T,children:[E,M]}),t[63]=T,t[64]=E,t[65]=M,t[66]=N):N=t[66],N},(e,t)=>e.isMobile===t.isMobile&&e.compact===t.compact&&e.footerIconButtonClass===t.footerIconButtonClass&&e.stopFooterIconButtonClass===t.stopFooterIconButtonClass&&e.compactCircleButtonClass===t.compactCircleButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&e.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),fx=(e,t)=>`${e}${e?e.endsWith(`
|
|
6520
|
+
`)?`...`:``),gp=(e,t={})=>{let n=hp(e);if(!n)return null;let r=mp(t.composerDocument);return Nf(n,{citationIcons:fp(t.attachments),sessionMentions:pp(t.composerDocument),skillNames:r.skillNames,commandNames:r.commandNames,allowPathHeuristics:!0})},_p=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`))},vp=(0,Z.memo)(e=>{let t=(0,Q.c)(132),{message:n,server:r,frozen:i,hasDispatchLock:a,pendingOperationKinds:o,sendPendingTimedOut:s,abortSendPending:c,isMobile:l,onEdit:u,onSend:d,onRemove:f}=e,{t:p}=ct(),m;t[0]===n?m=t[1]:(m=_r(n),t[0]=n,t[1]=m);let h=m,g=n.queueItemID||n.id,_;t[2]!==o||t[3]!==r?(_=r&&o.has(`edit`),t[2]=o,t[3]=r,t[4]=_):_=t[4];let v=_,y;t[5]!==o||t[6]!==r?(y=r&&o.has(`remove`),t[5]=o,t[6]=r,t[7]=y):y=t[7];let b=y,x;t[8]!==o||t[9]!==r?(x=r&&o.has(`reorder`),t[8]=o,t[9]=r,t[10]=x):x=t[10];let S=x,C=r||h?void 0:n,w;t[11]!==n||t[12]!==h||t[13]!==r?(w=r&&!h&&$f(n),t[11]=n,t[12]=h,t[13]=r,t[14]=w):w=t[14];let T=w,E;t[15]===C?E=t[16]:(E=C&&Qf(C),t[15]=C,t[16]=E);let D=!!E,O;t[17]!==n||t[18]!==h||t[19]!==r?(O=r&&!h&&Zf(n),t[17]=n,t[18]=h,t[19]=r,t[20]=O):O=t[20];let k=O,A;t[21]!==T||t[22]!==D||t[23]!==o||t[24]!==r?(A=r&&o.has(`send`)||T||D,t[21]=T,t[22]=D,t[23]=o,t[24]=r,t[25]=A):A=t[25];let j=c||A&&!s,M=i||h,N;t[26]!==i||t[27]!==n?(N=Yf(n,{frozen:i}),t[26]=i,t[27]=n,t[28]=N):N=t[28];let P=N,F;t[29]!==i||t[30]!==n?(F=Xf(n,{frozen:i}),t[29]=i,t[30]=n,t[31]=F):F=t[31];let I=F,L=C?.owner?.state===`unbound-legacy`||M||k,R;t[32]!==M||t[33]!==a||t[34]!==n||t[35]!==j||t[36]!==s||t[37]!==r?(R=!M&&!j&&(r?Jf(n,a,{allowManualDispatchRetry:s}):qf(n,a)),t[32]=M,t[33]=a,t[34]=n,t[35]=j,t[36]=s,t[37]=r,t[38]=R):R=t[38];let z=R,B=C?.failure?.recovery,V;t[39]===n?V=t[40]:(V=dp(n),t[39]=n,t[40]=V);let H=V,U=h?void 0:B?.attachments??n.attachments,W=B?.composerDocument??(`composerDocument`in n?n.composerDocument:void 0),ee;t[41]!==L||t[42]!==g?(ee={id:g,disabled:L},t[41]=L,t[42]=g,t[43]=ee):ee=t[43];let{attributes:G,listeners:K,setNodeRef:te,transform:ne,transition:re,isDragging:ie}=rc(ee),ae;t[44]===H?ae=t[45]:(ae=hp(H),t[44]=H,t[45]=ae);let oe=ae,se;t[46]!==U||t[47]!==W||t[48]!==H?(se=gp(H,{attachments:U,composerDocument:W}),t[46]=U,t[47]=W,t[48]=H,t[49]=se):se=t[49];let ce=se,le=h?n.attachmentCount:U?.length??0,ue;t[50]!==n||t[51]!==f?(ue=()=>f(n),t[50]=n,t[51]=f,t[52]=ue):ue=t[52];let de=!I,fe=b||void 0,pe=l?`h-7 w-3`:`size-7`,me;t[53]===pe?me=t[54]:(me=Y(`inline-flex shrink-0 items-center justify-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,pe),t[53]=pe,t[54]=me);let he;t[55]===p?he=t[56]:(he=p(`chat.queuedMessage.removeAria`),t[55]=p,t[56]=he);let ge=b?`loader-4`:`delete-bin`,_e=l?`size-3`:`size-3.5`,ve=b&&`animate-spin`,ye;t[57]!==_e||t[58]!==ve?(ye=Y(_e,ve),t[57]=_e,t[58]=ve,t[59]=ye):ye=t[59];let be;t[60]!==ge||t[61]!==ye?(be=(0,$.jsx)(X,{name:ge,className:ye,"aria-hidden":`true`}),t[60]=ge,t[61]=ye,t[62]=be):be=t[62];let xe;t[63]!==ue||t[64]!==de||t[65]!==fe||t[66]!==me||t[67]!==he||t[68]!==be?(xe=(0,$.jsx)(`button`,{type:`button`,onClick:ue,disabled:de,"aria-busy":fe,className:me,"aria-label":he,children:be}),t[63]=ue,t[64]=de,t[65]=fe,t[66]=me,t[67]=he,t[68]=be,t[69]=xe):xe=t[69];let Se=xe,Ce;t[70]===ne?Ce=t[71]:(Ce=ec.Translate.toString(ne),t[70]=ne,t[71]=Ce);let we;t[72]!==Ce||t[73]!==re?(we={transform:Ce,transition:re},t[72]=Ce,t[73]=re,t[74]=we):we=t[74];let Te=l?`gap-1 py-0.5`:`flex gap-1.5 md:gap-2`,Ee=ie&&`z-10 opacity-60`,De;t[75]!==Te||t[76]!==Ee?(De=Y(`flex min-w-0 items-center`,Te,Ee),t[75]=Te,t[76]=Ee,t[77]=De):De=t[77];let Oe=S||void 0,ke=l?`h-7 w-3`:`size-auto`,Ae=L?`cursor-default opacity-50`:`cursor-grab hover:text-foreground active:cursor-grabbing`,je;t[78]!==ke||t[79]!==Ae?(je=Y(`flex flex-shrink-0 touch-none select-none items-center justify-center text-muted-foreground`,ke,`transition-colors`,Ae),t[78]=ke,t[79]=Ae,t[80]=je):je=t[80];let Me;t[81]===p?Me=t[82]:(Me=p(`chat.queuedMessage.reorderAria`),t[81]=p,t[82]=Me);let Ne=S?`loader-4`:`draggable`,Pe=l?`size-3`:`size-3.5`,Fe=S&&`animate-spin`,Ie;t[83]!==Pe||t[84]!==Fe?(Ie=Y(Pe,Fe),t[83]=Pe,t[84]=Fe,t[85]=Ie):Ie=t[85];let Le;t[86]!==Ne||t[87]!==Ie?(Le=(0,$.jsx)(X,{name:Ne,className:Ie,"aria-hidden":`true`}),t[86]=Ne,t[87]=Ie,t[88]=Le):Le=t[88];let Re;t[89]!==G||t[90]!==L||t[91]!==K||t[92]!==Oe||t[93]!==je||t[94]!==Me||t[95]!==Le?(Re=(0,$.jsx)(`button`,{type:`button`,...G,...K,disabled:L,"aria-busy":Oe,className:je,"aria-label":Me,children:Le}),t[89]=G,t[90]=L,t[91]=K,t[92]=Oe,t[93]=je,t[94]=Me,t[95]=Le,t[96]=Re):Re=t[96];let ze=l?Se:null,q=l?`text-xs leading-5`:`typography-ui-label leading-5`,Be;t[97]===q?Be=t[98]:(Be=Y(`flex min-w-0 flex-1 items-baseline overflow-hidden whitespace-nowrap text-foreground`,q),t[97]=q,t[98]=Be);let Ve;t[99]!==oe||t[100]!==ce||t[101]!==p?(Ve=ce?ce.map(Dp):oe||p(`chat.queuedMessage.empty`),t[99]=oe,t[100]=ce,t[101]=p,t[102]=Ve):Ve=t[102];let He;t[103]!==le||t[104]!==p?(He=le>0&&(0,$.jsx)(`span`,{className:`ml-1 shrink-0 text-muted-foreground`,children:p(`chat.queuedMessage.attachments`,{count:le})}),t[103]=le,t[104]=p,t[105]=He):He=t[105];let Ue;t[106]!==Be||t[107]!==Ve||t[108]!==He?(Ue=(0,$.jsxs)(`span`,{className:Be,children:[Ve,He]}),t[106]=Be,t[107]=Ve,t[108]=He,t[109]=Ue):Ue=t[109];let We;t[110]!==P||t[111]!==z||t[112]!==v||t[113]!==l||t[114]!==n||t[115]!==u||t[116]!==d||t[117]!==h||t[118]!==j||t[119]!==p?(We=h?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.queuingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.queuing`)})]}):j?(0,$.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 font-medium text-muted-foreground`,l?`h-7 text-[11px] leading-none`:`h-7 typography-ui-label`),"aria-live":`polite`,"aria-label":p(`chat.queuedMessage.sendingAria`),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(l?`size-3`:`size-3.5`,`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:p(`chat.queuedMessage.sending`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(n),disabled:!P,"aria-busy":v||void 0,"aria-label":p(`chat.queuedMessage.edit`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:v?`loader-4`:`edit`,className:Y(l?`size-3`:`size-3.5`,v&&`animate-spin`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.edit`)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{j||d(n)},disabled:!z||j,"aria-busy":j||void 0,"aria-label":p(`chat.queuedMessage.send`),className:Y(`inline-flex items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,l?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),children:[(0,$.jsx)(X,{name:`send-plane`,className:Y(l?`size-3`:`size-3.5`),"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,l?`leading-none`:`typography-ui-label`),children:p(`chat.queuedMessage.send`)})]})]}),t[110]=P,t[111]=z,t[112]=v,t[113]=l,t[114]=n,t[115]=u,t[116]=d,t[117]=h,t[118]=j,t[119]=p,t[120]=We):We=t[120];let Ge=!l&&!h?Se:null,Ke;t[121]!==We||t[122]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-muted-foreground`,children:[We,Ge]}),t[121]=We,t[122]=Ge,t[123]=Ke):Ke=t[123];let qe;return t[124]!==te||t[125]!==we||t[126]!==De||t[127]!==Re||t[128]!==ze||t[129]!==Ue||t[130]!==Ke?(qe=(0,$.jsxs)(`div`,{ref:te,style:we,className:De,children:[Re,ze,Ue,Ke]}),t[124]=te,t[125]=we,t[126]=De,t[127]=Re,t[128]=ze,t[129]=Ue,t[130]=Ke,t[131]=qe):qe=t[131],qe});vp.displayName=`QueuedMessageChip`;var yp=[],bp=[],xp=[],Sp=new Set,Cp=(e,t)=>t?Wf(_(e,v(t.sessionID)),_(e,t)):yp,wp=(e,t)=>{if(!t)return bp;let n=Cp(e,t),r=[...I(e,v(t.sessionID)),...I(e,t)];return r.length===0?n:[...n,...r]},Tp=(e,t)=>{let n=e.owner;return n?n.state===`unbound-legacy`?n.sessionID===t.sessionID?v(t.sessionID):null:p(n)===p(t)?t:null:null},Ep=(0,Z.memo)(e=>{let t=(0,Q.c)(152),{onEditMessage:n,onSendMessage:r,onEditCommitted:i,draftKey:a,scope:o,draftTarget:s,clientPendingItems:c,onRemoveClientPending:l,trailing:u}=e,d=c===void 0?xp:c,{t:f}=ct(),m=q(Op),h=o?.transportIdentity??``,g=o?.directory??``,_=o?.sessionID??``,v;t[0]!==h||t[1]!==g||t[2]!==_?(v={transportIdentity:h,directory:g,sessionID:_},t[0]=h,t[1]=g,t[2]=_,t[3]=v):v=t[3];let y=Ju(v),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 C=o?.transportIdentity??``,w=o?.runtimeGeneration??-1,T;t[5]!==C||t[6]!==w?(T=[C,`messageQueue`,`scopeMutation`,w],t[5]=C,t[6]=w,t[7]=T):T=t[7];let E=T,D;t[8]===y.actions?D=t[9]:(D=e=>Xn(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=y.actions.captureRuntime();if(t.transportIdentity!==e.runtime.transportIdentity||t.generation!==e.runtime.generation)return Promise.resolve({status:`stale`});switch(e.kind){case`edit`:return y.actions.editIntoDraft(e.input);case`send`:return y.actions.manualSend(e.input);case`remove`:return y.actions.remove(e.input);case`reorder`:return y.actions.reorder(e.input)}throw Error(`Unsupported server queue operation`)}),t[8]=y.actions,t[9]=D);let O,k;t[10]!==y.actions||t[11]!==f?(O=(e,t)=>{let n=y.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&e.status!==`stale`&&t.kind===`edit`&&e.status!==`committed`&&Br.error(f(`chat.chatInput.toast.queueOperationFailed`))},k=(e,t)=>{let n=y.actions.captureRuntime();n.transportIdentity===t.runtime.transportIdentity&&n.generation===t.runtime.generation&&Br.error(f(e instanceof Dt&&e.code===`unavailable`?`chat.chatInput.toast.queueOperationStatusUnknown`:`chat.chatInput.toast.queueOperationFailed`))},t[10]=y.actions,t[11]=f,t[12]=O,t[13]=k):(O=t[12],k=t[13]);let A;t[14]!==E||t[15]!==D||t[16]!==O||t[17]!==k?(A={mutationKey:E,mutationFn:D,onSuccess:O,onError:k},t[14]=E,t[15]=D,t[16]=O,t[17]=k,t[18]=A):A=t[18];let j=Ke(A),M;t[19]===E?M=t[20]:(M={filters:{mutationKey:E,exact:!0,status:`pending`},select:kp},t[19]=E,t[20]=M);let P=Ge(M),F;t[21]===E?F=t[22]:(F={filters:{mutationKey:E,exact:!0,status:`success`},select:Ap},t[21]=E,t[22]=F);let I=Ge(F),L;bb0:{if(!o||!y.scope){L=null;break bb0}let e=o.runtimeGeneration??y.runtimeCapture.generation,n;t[23]!==o.directory||t[24]!==o.sessionID||t[25]!==o.transportIdentity||t[26]!==y.scope.scopeID||t[27]!==e?(n={transportIdentity:o.transportIdentity,directory:o.directory,sessionID:o.sessionID,scopeID:y.scope.scopeID,runtimeGeneration:e},t[23]=o.directory,t[24]=o.sessionID,t[25]=o.transportIdentity,t[26]=y.scope.scopeID,t[27]=e,t[28]=n):n=t[28],L=n}let R=L,z;bb1:{if(!R){let e;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[29]=e):e=t[29],z=e;break bb1}let e;if(t[30]!==R||t[31]!==P){let n;t[33]===R?n=t[34]:(n=e=>_p(e)&&e.scopeID===R.scopeID,t[33]=R,t[34]=n),e=rp(P.filter(n),R),t[30]=R,t[31]=P,t[32]=e}else e=t[32];z=e}let B=z,V;t[35]!==R||t[36]!==y.scope?.revision||t[37]!==I?(V=()=>R?ip(I.filter(jp),R,y.scope?.revision):[],t[35]=R,t[36]=y.scope?.revision,t[37]=I,t[38]=V):V=t[38],y.scope?.revision;let H;t[39]===V?H=t[40]:(H=V(),t[39]=V,t[40]=H);let U=H,W;t[41]!==U||t[42]!==B?(W=[...B,...U],t[41]=U,t[42]=B,t[43]=W):W=t[43];let ee=W,G;t[44]===o?G=t[45]:(G=e=>wp(e,o),t[44]=o,t[45]=G);let K=b(G);Z.useSyncExternalStore(Kt,dn,dn);let te;t[46]!==ee||t[47]!==K||t[48]!==y.items||t[49]!==y.mode?(te=y.mode===`server`?sp(y.items,ee):K,t[46]=ee,t[47]=K,t[48]=y.items,t[49]=y.mode,t[50]=te):te=t[50];let ne=te,re;t[51]!==ne||t[52]!==d?(re=d.length===0?ne:[...ne,...d],t[51]=ne,t[52]=d,t[53]=re):re=t[53];let ie=re,ae;t[54]!==o?.sessionID||t[55]!==ie?(ae=()=>{let e=o?.sessionID,t=new Set;if(!e)return t;for(let n of ie){let r=n.queueItemID||n.id;r&&bn(e,r)&&t.add(r)}return t},t[54]=o?.sessionID,t[55]=ie,t[56]=ae):ae=t[56],o?.sessionID;let oe;t[57]===ae?oe=t[58]:(oe=ae(),t[57]=ae,t[58]=oe);let se=oe,ce;if(t[59]!==ee){ce=new Map;for(let e of ee){let t=ce.get(e.queueItemID)??new Set;t.add(e.kind),ce.set(e.queueItemID,t)}t[59]=ee,t[60]=ce}else ce=t[60];let le=ce,ue;if(t[61]!==ee||t[62]!==ie||t[63]!==y.mode){bb2:{let e=new Set;if(y.mode===`server`){for(let t of ee)t.kind===`send`&&e.add(t.queueItemID);for(let t of ie){if(_r(t))continue;let n=t.queueItemID;n&&$f(t)&&e.add(n)}ue=e;break bb2}for(let t of ie){if(_r(t))continue;let n=t;Qf(n)&&e.add(n.queueItemID||n.id)}ue=e}t[61]=ee,t[62]=ie,t[63]=y.mode,t[64]=ue}else ue=t[64];let de=ue,[fe,pe]=Z.useState(Mp),me;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(me=new Map,t[65]=me):me=t[65];let he=Z.useRef(me),ge,_e;t[66]!==de||t[67]!==fe?(ge=()=>{let e=he.current,t=Date.now();for(let t of[...e.keys()])de.has(t)||e.delete(t);pe(e=>{let t=!1,n=new Set;for(let r of e)de.has(r)?n.add(r):t=!0;return t?n:e});let n=[];for(let r of de){if(e.has(r)||(e.set(r,t),pe(e=>{if(!e.has(r))return e;let t=new Set(e);return t.delete(r),t})),fe.has(r))continue;let i=tp-(t-(e.get(r)??t));if(i<=0){pe(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t});continue}n.push(setTimeout(()=>{he.current.has(r)&&pe(e=>{if(e.has(r))return e;let t=new Set(e);return t.add(r),t})},i))}return()=>{for(let e of n)clearTimeout(e)}},_e=[de,fe],t[66]=de,t[67]=fe,t[68]=ge,t[69]=_e):(ge=t[68],_e=t[69]),Z.useEffect(ge,_e);let ve;t[70]===y.mode?ve=t[71]:(ve=Uf(y.mode),t[70]=y.mode,t[71]=ve);let ye=!ve,be=Ht(o),xe;t[72]!==be||t[73]!==ie||t[74]!==y.mode?(xe=y.mode===`server`?!1:be||ie.some(Np),t[72]=be,t[73]=ie,t[74]=y.mode,t[75]=xe):xe=t[75];let Se=xe,Ce=b(Pp),we;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(we={activationConstraint:{distance:8}},t[76]=we):we=t[76];let Te;t[77]===Symbol.for(`react.memo_cache_sentinel`)?(Te={activationConstraint:{delay:200,tolerance:6}},t[77]=Te):Te=t[77];let Ee=$s(Ks(Zs,we),Ks(Js,Te)),De;t[78]!==ye||t[79]!==o||t[80]!==ie||t[81]!==Ce||t[82]!==j||t[83]!==y.actions||t[84]!==y.mode||t[85]!==y.scope?(De=e=>{if(ye)return;let{active:t,over:n}=e;if(!n||t.id===n.id)return;if(y.mode===`server`){if(!o||!y.scope)return;let e=ie,r=e.find(e=>e.queueItemID===t.id),i=e.find(e=>e.queueItemID===n.id);if(!r||!i||_r(r)||_r(i)||Zf(r)||Zf(i))return;let a=y.scope,s=y.actions.captureRuntime();if(s.transportIdentity!==o.transportIdentity||s.generation!==o.runtimeGeneration)return;let c=N(),l=up(a,String(t.id),String(n.id),c,e);if(!l)return;j.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(Fp);return}let r=ie.filter(Ip),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=Tp(i,o),c=Tp(a,o);!s||!c||p(s)!==p(c)||Ce(s,String(t.id),String(n.id),i.operationID)},t[78]=ye,t[79]=o,t[80]=ie,t[81]=Ce,t[82]=j,t[83]=y.actions,t[84]=y.mode,t[85]=y.scope,t[86]=De):De=t[86];let Oe=J(De),ke;t[87]!==a||t[88]!==s||t[89]!==ye||t[90]!==i||t[91]!==n||t[92]!==o||t[93]!==j||t[94]!==y.actions||t[95]!==y.mode||t[96]!==y.scope?(ke=e=>{if(ye||_r(e))return;if(y.mode===`server`){if(!o||!y.scope||!a||!s)return;let t=e,n=s.expectedRevision(),r=y.scope,c=y.actions.captureRuntime();if(c.transportIdentity!==o.transportIdentity||c.generation!==o.runtimeGeneration)return;j.mutateAsync({kind:`edit`,transportIdentity:c.transportIdentity,directory:r.directory,sessionID:r.sessionID,scopeID:r.scopeID,queueItemID:t.queueItemID,requestID:N(),runtime:c,runtimeGeneration:c.generation,input:lp(r,t,s.key,n)}).then(e=>{(e.status===`committed`||`draftDurable`in e&&e.draftDurable)&&i?.()}).catch(Lp);return}if(!o)return;let t=e,r=Tp(t,o);if(!r)return;let c=t.queueItemID??t.id,l=t.operationID,u=Kf(t);(async()=>{let e;try{e=await Promise.resolve(n(u.content,u.attachments,u.composerDocument,u.composerMentions))}catch{e=!1}e&&(i?.(),b.getState().removeFromQueue(r,c,l))})()},t[87]=a,t[88]=s,t[89]=ye,t[90]=i,t[91]=n,t[92]=o,t[93]=j,t[94]=y.actions,t[95]=y.mode,t[96]=y.scope,t[97]=ke):ke=t[97];let Ae=J(ke),je;t[98]!==ye||t[99]!==r||t[100]!==o||t[101]!==j||t[102]!==y.actions||t[103]!==y.mode||t[104]!==y.scope?(je=e=>{if(ye||_r(e))return;if(y.mode===`server`){if(!o||!y.scope)return;let t=e,n=y.scope,r=y.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=t.queueItemID;he.current.delete(i),pe(e=>{if(!e.has(i))return e;let t=new Set(e);return t.delete(i),t});let a=N();j.mutateAsync({kind:`send`,transportIdentity:r.transportIdentity,directory:n.directory,sessionID:n.sessionID,scopeID:n.scopeID,queueItemID:t.queueItemID,requestID:a,runtime:r,runtimeGeneration:r.generation,input:cp(n,t,a)}).catch(Rp);return}if(!o)return;let t=e;if(!Tp(t,o))return;let n=t.queueItemID??t.id;he.current.delete(n),pe(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t}),r(n)},t[98]=ye,t[99]=r,t[100]=o,t[101]=j,t[102]=y.actions,t[103]=y.mode,t[104]=y.scope,t[105]=je):je=t[105];let Me=J(je),Ne;t[106]!==d||t[107]!==ye||t[108]!==l||t[109]!==o||t[110]!==j||t[111]!==y.actions||t[112]!==y.mode||t[113]!==y.scope?(Ne=e=>{if(_r(e)){d.some(t=>t.requestID===e.requestID)&&l?.(e.requestID);return}if(ye)return;if(y.mode===`server`){if(!o||!y.scope)return;let t=e,n=y.scope,r=y.actions.captureRuntime();if(r.transportIdentity!==o.transportIdentity||r.generation!==o.runtimeGeneration)return;let i=N();j.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:cp(n,t,i)}).catch(zp);return}if(!o)return;let t=e,n=Tp(t,o);n&&b.getState().removeFromQueue(n,t.queueItemID??t.id,t.operationID)},t[106]=d,t[107]=ye,t[108]=l,t[109]=o,t[110]=j,t[111]=y.actions,t[112]=y.mode,t[113]=y.scope,t[114]=Ne):Ne=t[114];let Pe=J(Ne),Fe=ie.length>0&&(o||d.length>0);if(!Fe&&!u)return null;let Ie=m?`px-2`:`px-4`,Le;t[115]===Ie?Le=t[116]:(Le=Y(`oc-composer-queue relative z-0 -mb-5 w-full`,Ie),t[115]=Ie,t[116]=Le);let Re=m?`rounded-[1.25rem]`:`rounded-3xl`,ze;t[117]===Re?ze=t[118]:(ze=Y(`overflow-hidden border border-border/60 bg-[var(--surface-subtle)] text-foreground`,Re),t[117]=Re,t[118]=ze);let Be=m?`px-1.5 py-1`:`gap-0.5 px-3 pb-1 pt-1.5`,Ve;t[119]===Be?Ve=t[120]:(Ve=Y(`flex flex-col`,Be),t[119]=Be,t[120]=Ve);let He;t[121]!==se||t[122]!==ye||t[123]!==Oe||t[124]!==Ae||t[125]!==Pe||t[126]!==Me||t[127]!==Se||t[128]!==Fe||t[129]!==m||t[130]!==le||t[131]!==ie||t[132]!==fe||t[133]!==Ee||t[134]!==y.mode?(He=Fe?(0,$.jsx)(Qs,{sensors:Ee,collisionDetection:Xs,onDragEnd:Oe,children:(0,$.jsx)(ac,{items:ie.map(Bp),strategy:ic,children:ie.map(e=>{let t=e.queueItemID||e.id;return(0,$.jsx)(vp,{message:e,server:y.mode===`server`,frozen:ye,hasDispatchLock:Se,pendingOperationKinds:le.get(t)??Sp,sendPendingTimedOut:fe.has(t),abortSendPending:se.has(t),isMobile:m,onEdit:Ae,onSend:Me,onRemove:Pe},t)})})}):null,t[121]=se,t[122]=ye,t[123]=Oe,t[124]=Ae,t[125]=Pe,t[126]=Me,t[127]=Se,t[128]=Fe,t[129]=m,t[130]=le,t[131]=ie,t[132]=fe,t[133]=Ee,t[134]=y.mode,t[135]=He):He=t[135];let Ue;t[136]!==Fe||t[137]!==u?(Ue=u?(0,$.jsxs)($.Fragment,{children:[Fe?(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`my-0.5 border-t border-border/40`}):null,u]}):null,t[136]=Fe,t[137]=u,t[138]=Ue):Ue=t[138];let We;t[139]!==Ve||t[140]!==He||t[141]!==Ue?(We=(0,$.jsxs)(`div`,{"data-oc-queue-card-body":``,className:Ve,children:[He,Ue]}),t[139]=Ve,t[140]=He,t[141]=Ue,t[142]=We):We=t[142];let qe=m?`h-4`:`h-5`,Je;t[143]===qe?Je=t[144]:(Je=(0,$.jsx)(`div`,{"data-oc-queue-composer-overlap":``,"aria-hidden":`true`,className:qe}),t[143]=qe,t[144]=Je);let Ye;t[145]!==ze||t[146]!==We||t[147]!==Je?(Ye=(0,$.jsxs)(`div`,{"data-oc-queue-card":``,className:ze,children:[We,Je]}),t[145]=ze,t[146]=We,t[147]=Je,t[148]=Ye):Ye=t[148];let Xe;return t[149]!==Le||t[150]!==Ye?(Xe=(0,$.jsx)(`div`,{className:Le,children:Ye}),t[149]=Le,t[150]=Ye,t[151]=Xe):Xe=t[151],Xe});Ep.displayName=`QueuedMessageChips`;function Dp(e,t){return e.type===`text`?(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text},`text-${t}`):(0,$.jsx)(Vf,{decoration:e.decoration,interactive:!1},`ref-${t}-${e.span.start}`)}function Op(e){return e.isMobile}function kp(e){return e.state.variables}function Ap(e){let t=e.state.variables;if(!_p(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 jp(e){return e!==void 0}function Mp(){return new Set}function Np(e){return!_r(e)&&(e.status===`sending`||e.status===`reconciling`)}function Pp(e){return e.reorderQueue}function Fp(){}function Ip(e){return!_r(e)}function Lp(){}function Rp(){}function zp(){}function Bp(e){return e.queueItemID||e.id}var Vp=[0,200,400],Hp=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=Vp.map(Up),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 Up(e){return(0,$.jsx)(`span`,{className:`animate-busy-pulse`,style:{animationDelay:`${e}ms`},children:`.`},e)}var Wp=(0,Z.memo)(()=>{let e=(0,Q.c)(55),{t}=ct(),n=ri(Gp),r;e[0]===n?r=e[1]:(r=e=>{if(!n)return null;let t=e.runsByOriginalSessionID[n]??null;return t?.runtimeKey===a()?t:null},e[0]=n,e[1]=r);let i=Wt(r),o=Wt(Kp),s=q(qp),c=q(Jp);if(!n||!i||i.status!==`running`)return null;let l;e[2]!==i.phase||e[3]!==t?(l=i.phase===`waiting_for_reviewer`?t(`chat.autoReview.status.waitingForReviewer`):t(`chat.autoReview.status.waitingForImplementer`),e[2]=i.phase,e[3]=t,e[4]=l):l=e[4];let u=l,d;e[5]!==s||e[6]!==i.directory||e[7]!==i.reviewSessionID||e[8]!==t?(d=()=>{s(i.directory,{mode:`chat`,dedupeKey:`session:${i.reviewSessionID}`,label:t(`chat.autoReview.reviewSessionLabel`),readOnly:!0})},e[5]=s,e[6]=i.directory,e[7]=i.reviewSessionID,e[8]=t,e[9]=d):d=e[9];let f=d,p=c?`pb-1 text-xs`:`pb-2`,m;e[10]===p?m=e[11]:(m=Y(`w-full px-1`,p),e[10]=p,e[11]=m);let h=c?`rounded-lg`:`rounded-xl`,g;e[12]===h?g=e[13]:(g=Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,h),e[12]=h,e[13]=g);let _=c?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`,v;e[14]===_?v=e[15]:(v=Y(`flex w-full items-center text-left`,_),e[14]=_,e[15]=v);let y=c?`size-3.5`:`size-4`,b;e[16]===y?b=e[17]:(b=Y(`animate-spin text-muted-foreground`,y),e[16]=y,e[17]=b);let x;e[18]===b?x=e[19]:(x=(0,$.jsx)(X,{name:`loader-4`,className:b,"aria-hidden":`true`}),e[18]=b,e[19]=x);let S;e[20]===t?S=e[21]:(S=t(`chat.autoReview.title`),e[20]=t,e[21]=S);let C;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Hp,{}),e[22]=C):C=e[22];let w;e[23]===S?w=e[24]:(w=(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:[S,C]}),e[23]=S,e[24]=w);let T;e[25]===u?T=e[26]:(T=(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:u}),e[25]=u,e[26]=T);let E;e[27]!==w||e[28]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[w,T]}),e[27]=w,e[28]=T,e[29]=E):E=e[29];let D;e[30]===t?D=e[31]:(D=t(`chat.autoReview.actions.open`),e[30]=t,e[31]=D);let O;e[32]!==f||e[33]!==D?(O=(0,$.jsx)(ua,{type:`button`,variant:`secondary`,size:`xs`,onClick:f,children:D}),e[32]=f,e[33]=D,e[34]=O):O=e[34];let k;e[35]!==n||e[36]!==o?(k=()=>o(n),e[35]=n,e[36]=o,e[37]=k):k=e[37];let A;e[38]===t?A=e[39]:(A=t(`chat.autoReview.actions.stop`),e[38]=t,e[39]=A);let j;e[40]!==k||e[41]!==A?(j=(0,$.jsx)(ua,{type:`button`,variant:`secondary`,size:`xs`,onClick:k,children:A}),e[40]=k,e[41]=A,e[42]=j):j=e[42];let M;e[43]!==x||e[44]!==E||e[45]!==O||e[46]!==j||e[47]!==v?(M=(0,$.jsxs)(`div`,{className:v,children:[x,E,O,j]}),e[43]=x,e[44]=E,e[45]=O,e[46]=j,e[47]=v,e[48]=M):M=e[48];let N;e[49]!==M||e[50]!==g?(N=(0,$.jsx)(`div`,{className:g,children:M}),e[49]=M,e[50]=g,e[51]=N):N=e[51];let P;return e[52]!==N||e[53]!==m?(P=(0,$.jsx)(`div`,{className:m,children:N}),e[52]=N,e[53]=m,e[54]=P):P=e[54],P});Wp.displayName=`AutoReviewBanner`;function Gp(e){return e.currentSessionId}function Kp(e){return e.stopRun}function qp(e){return e.openContextPanelTab}function Jp(e){return e.isMobile}var Yp=Z.forwardRef(({searchQuery:e,onSkillSelect:t,onClose:n,directory:r,style:i,onRowsChange:a},o)=>{let s=Z.useRef(null),c=q(e=>e.isMobile),[l,u]=Z.useState(0),d=Z.useRef(0),f=Z.useRef(!1),[p,m]=Z.useState([]),h=Z.useRef([]),g=Z.useRef(null),_=Ei({directory:r}),v=Z.useMemo(()=>_.data??[],[_.data]);Z.useEffect(()=>{m(_l(v,e)),u(0)},[v,e]),Z.useEffect(()=>{d.current=l},[l]),Z.useEffect(()=>{h.current[l]?.scrollIntoView({block:`nearest`})},[l]),Z.useEffect(()=>{let e=e=>{let t=e.target;!t||!s.current||s.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),Z.useEffect(()=>{zo(a,g,{rows:Ro(p),highlightedIndex:l})},[p,a,l]);let y=Z.useRef(a);y.current=a,Z.useEffect(()=>()=>{Bo(y.current,g)},[]),Z.useImperativeHandle(o,()=>({acceptIndex:e=>{let n=p[e];n&&t(n)},handleKeyDown:e=>{if(e===`Escape`){n();return}if(p.length){if(e===`ArrowDown`){f.current=!0,u(e=>(e+1)%p.length);return}if(e===`ArrowUp`){f.current=!0,u(e=>(e-1+p.length)%p.length);return}if(e===`Enter`||e===`Tab`){let e=(d.current%p.length+p.length)%p.length,n=p[e];n&&t(n)}}}}),[p,t,n]);let b=(e,n)=>{let r=e.scope===`project`,i=e.source||`opencode`;return(0,$.jsx)(`div`,{ref:e=>{h.current[n]=e},className:Y(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,c?`items-center`:`items-start`,es(c,n===l)),onClick:()=>t(e),onMouseMove:()=>{f.current=!1,u(n)},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`,r?`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:i})]}),e.description&&!c&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:e.description})]})},`${e.name}-${e.scope}`)};return(0,$.jsxs)(Mo,{ref:s,isMobile:c,className:`max-w-[450px] max-h-60`,style:i,children:[(0,$.jsx)(pa,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:p.length?(0,$.jsx)(`div`,{children:p.map((e,t)=>b(e,t))}):(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:`No skills found`})}),!c&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:`↑↓ navigate • Enter select • Esc close`})]})});Yp.displayName=`SkillAutocomplete`;function Xp(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 Zp(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(Qp).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)(Xp,{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 Qp(e){return e.trim()}var $p=`mobile-overlay-root`,em=16,tm=200,nm=[],rm=0,im=``,am=0,om=()=>{if(typeof document>`u`)return null;let e=document.getElementById($p);return e||(e=document.createElement(`div`),e.id=$p,document.body.appendChild(e)),e},sm=({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=om()),Z.useEffect(()=>{if(!e){m(!1),g(!1);return}let t=window.setTimeout(()=>m(!0),em),n=window.setTimeout(()=>g(!0),266);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[e]),Z.useLayoutEffect(()=>{if(e)return am===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-opened`)),am+=1,()=>{am=Math.max(0,am-1),am===0&&window.dispatchEvent(new Event(`oc:mobile-overlay-closed`))}},[e]),Z.useEffect(()=>{if(!e)return;let t=d.current;nm.push(t),rm===0&&(im=document.body.style.overflow),rm+=1,document.body.style.overflow=`hidden`;let n=e=>{e.key===`Escape`&&nm[nm.length-1]===t&&f.current()};return document.addEventListener(`keydown`,n),()=>{let e=nm.lastIndexOf(t);e>=0&&nm.splice(e,1),rm=Math.max(0,rm-1),rm===0&&(document.body.style.overflow=im),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:ha,onClick:e=>{ga(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 ${tm}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)(pa,{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,rl.createPortal)(v,u.current)},cm=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,lm=1e3,um=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)(la,{name:n,size:a,label:l}),t[2]=a,t[3]=n,t[4]=l,t[5]=u):u=t[5];let d;t[6]!==c||t[7]!==u?(d=(0,$.jsx)(`span`,{className:c,children:u}),t[6]=c,t[7]=u,t[8]=d):d=t[8];let f=i?`grid-cols-[1fr] opacity-100`:`grid-cols-[0fr] opacity-0`,p;t[9]===f?p=t[10]:(p=Y(`grid min-w-0 items-center ease-in-out`,f),t[9]=f,t[10]=p);let m;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m={transitionProperty:`grid-template-columns, opacity`,transitionDuration:`280ms`,transitionTimingFunction:`ease-in-out`},t[11]=m):m=t[11];let h=!i,g;t[12]===s?g=t[13]:(g=s?{color:`var(${s})`}:void 0,t[12]=s,t[13]=g);let _;t[14]!==r||t[15]!==g?(_=(0,$.jsx)(`span`,{className:`flex min-w-0 items-center overflow-hidden`,children:(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap pl-1.5 pr-0.5 typography-micro leading-none font-medium`,style:g,children:r})}),t[14]=r,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==_||t[18]!==p||t[19]!==h?(v=(0,$.jsx)(`span`,{className:p,style:m,"aria-hidden":h,children:_}),t[17]=_,t[18]=p,t[19]=h,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==d?(y=(0,$.jsxs)($.Fragment,{children:[d,v]}),t[21]=v,t[22]=d,t[23]=y):y=t[23],y};function dm(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},lm),()=>{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 fm=`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-pointer`,pm=e=>`flow-root ${e?`py-1`:`py-1.5`}`,mm=e=>`relative ml-2 flex flex-col pl-3 ${e?`gap-1 pt-1`:`gap-1.5 pt-1.5`}`,hm=`${fm} hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,gm=`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)]`,_m=`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 ${gm}`,vm=`rounded-md ${gm}`,ym=()=>{if(!(typeof window>`u`))return window.__zustand_config_store__},bm=e=>{if(e)try{let t=ym();if(t?.getState)return t.getState().agents?.find?.(t=>t.name===e)}catch{}},xm=(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`},Sm=e=>{let t=bm(e);return t?xm(t.permission,`edit`):`ask`},Cm=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},wm=e=>{let t=e.info.tokens;if(typeof t==`number`)return t;if(t&&typeof t==`object`)return Cm(t);let n=e.parts.find(e=>e.tokens!==void 0);return!n||n.tokens===void 0?0:typeof n.tokens==`number`?n.tokens:Cm(n.tokens)},Tm=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}},Em=(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}},Dm=[`ask`,`allow`,`full`],Om=`__global__`,km=ce()(ue(le((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=Em(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=wm(d);if(h===0)return m||null;let g=Em(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=wm(o);if(s===0)return;let c=Em(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`&&wm(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=Sm(n))=>{if(!e||!n)return r;let i=t().sessionAgentEditModes.get(e)?.get(n);if(i!==void 0)return i;if(e!==Om){let e=t().sessionAgentEditModes.get(Om)?.get(n);if(e!==void 0)return e}return r},setSessionAgentEditMode:(t,n,r,i=Sm(n))=>{if(!t||!n)return;let a=i??`ask`;a!==`deny`&&r!==`deny`&&Dm.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=Sm(n))=>{if(!e||!n)return;let i=r??`ask`;if(i===`deny`)return;let a=t().getSessionAgentEditMode(e,n,i),o=Dm.indexOf(a),s=Dm.indexOf(i),c=Dm[((o>=0?o:s>=0?s:0)+1)%Dm.length];t().setSessionAgentEditMode(e,n,c,i)}}),{name:`context-store`,storage:Be(),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`})),Am=e=>Qt([...e??[]]),jm=typeof window<`u`?Z.useLayoutEffect:Z.useEffect,Mm=(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],jm(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 Nm(e,t){return!e&&t===`trigger-hover`}var Pm=e=>{let t=e.current;return!t||!t.isConnected||t.disabled?null:t},Fm=e=>{let t=Pm(e);return t?(t.focus({preventScroll:!0}),!0):!1},Im=(e,t)=>e&&!t,Lm=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):[]:[]},Rm=(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 Lm(i)},zm=()=>!0,Bm=(e,t)=>(e.commandPolicy??zm)(t),Vm=Z.createContext(null),Hm=()=>Z.useContext(Vm),Um=e=>e,Wm=(e,t)=>t??e,Gm=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`)},Km=(e,t)=>e.kind===`secondary`?e.resources?.busy??!1:t,qm=e=>!e.sessionID||!e.directory?null:{deliveryTarget:e.deliveryTarget,sessionID:e.queueSessionID??e.sessionID,directory:e.directory,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration},Jm=(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}},Ym=(e,t)=>`${e}:${t}`,Xm=`transition-none animate-none data-[starting-style]:!opacity-100 data-[starting-style]:!scale-100 data-[ending-style]:!opacity-100 data-[ending-style]:!scale-100`,Zm=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},Qm=(e,t)=>{let n=Zm(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}}},$m=[{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}],eh={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`}},th=e=>e.trim().toLowerCase(),nh=(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=>th(e)))),i=[];for(let e of r){let t=eh[e];t&&i.push({key:e,icon:t.icon,label:t.label})}return i},rh=e=>new Intl.NumberFormat(lt(),{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:1,minimumFractionDigits:0}).format(e),ih=e=>new Intl.NumberFormat(lt(),{style:`currency`,currency:`USD`,maximumFractionDigits:4,minimumFractionDigits:2}).format(e),ah=e=>new Intl.DateTimeFormat(lt(),{month:`short`,day:`numeric`,year:`numeric`}).format(e),oh=`__add_provider__`,sh=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},ch=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=cm(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},lh=e=>{if(typeof e!=`number`||Number.isNaN(e))return`—`;if(e===0)return`0`;let t=rh(e);return t.endsWith(`.0`)?t.slice(0,-2):t},uh=e=>typeof e!=`number`||!Number.isFinite(e)?`—`:ih(e),dh=e=>{let t=[];for(let n of $m)n.isActive(e)&&t.push({key:n.key,icon:n.icon,label:n.label});return t},fh=e=>{if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:ah(t)},ph=({className:e,composerTextareaRef:t,mobilePanel:n,onMobilePanelChange:r,selectionAdapter:i})=>{let{t:a}=ct(),o=Z.useId(),{isReady:s,isUnavailable:c}=no(),l=c||i?.catalog?.error?a(`common.unavailable`):a(`common.loading`),u=Ai(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),d=Ai(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),f=i?.catalog,p=s&&(f?.ready??!u)&&!f?.loading&&!f?.error&&!i?.disabled,m=s&&(f?.ready??!d)&&!f?.loading&&!f?.error&&!i?.disabled,h=p&&m,g=Ai(e=>e.providers),_=f?.providers??g,v=Ai(e=>e.currentProviderId),y=Ai(e=>e.currentModelId),b=i?.selection.providerID??v,x=i?.selection.modelID??y,S=Ai(e=>e.currentVariant),C=i?i.selection.variant:S,w=Ai(e=>e.currentAgentName),T=i?i.selection.agent??void 0:w,E=Ai(e=>e.settingsDefaultVariant),D=Ai(e=>e.settingsDefaultAgent),O=Ai(e=>e.setProvider),k=Ai(e=>e.setSelectedProvider),A=Ai(e=>e.setModel),j=Ai(e=>e.setCurrentVariant),M=Ai(e=>e.getCurrentModelVariants),N=Ai(e=>e.setAgent),P=Ai(e=>e.getCurrentProvider),F=Ai(e=>e.getModelMetadata),I=Ai(e=>e.getCurrentAgent),L=Ai(e=>e.getVisibleAgents),R=Am(f?.agents??L()),z=Z.useMemo(()=>R.filter(e=>e.mode===`primary`),[R]),B=Z.useRef(!1);Z.useEffect(()=>{B.current||!h||(B.current=!0,Oe(`ModelControls:ready`,{providers:_.length,agents:R.length,currentProviderId:b,currentModelId:x,currentAgentName:T}))},[R.length,h,T,x,b,_.length]);let V=ri(e=>i?null:e.currentSessionId),H=ri(e=>e.getDirectoryForSession),U=ku(),W=Zi(e=>e.getSessionModelSelection),ee=Zi(e=>e.saveSessionModelSelection),G=Zi(e=>e.saveSessionAgentSelection),K=Zi(e=>e.saveAgentModelForSession),te=Zi(e=>e.getAgentModelForSession),ne=Zi(e=>e.saveAgentModelVariantForSession),re=Zi(e=>e.getAgentModelVariantForSession),ie=km(e=>e.hasHydrated),ae=Zi(e=>V?e.sessionAgentSelections.get(V)??null:null),oe=Z.useRef(null);Z.useEffect(()=>{if(!V){oe.current=null;return}ae&&(oe.current=ae)},[V,ae]);let se=V?oe.current:null,ce=i?i.selection.agent??void 0:V&&(ae||se)||T,le=q(e=>e.toggleFavoriteModel),ue=q(e=>e.reorderFavoriteModel),de=q(e=>e.providerOrder),fe=q(e=>e.setProviderOrder),pe=q(e=>e.isFavoriteModel),me=q(e=>e.addRecentModel),he=q(e=>e.addRecentAgent),ge=q(e=>e.addRecentEffort),_e=q(e=>e.isModelSelectorOpen),ve=q(e=>e.setModelSelectorOpen),ye=q(e=>e.isAgentSelectorOpen),be=q(e=>e.setAgentSelectorOpen),xe=q(e=>e.isModelSelectorInstant),Se=q(e=>e.isAgentSelectorInstant),Ce=q(e=>e.setSettingsDialogOpen),we=q(e=>e.setSettingsPage),Te=q(e=>e.hiddenModels),Ee=q(e=>e.shortcutOverrides.cycle_agent),De=Z.useMemo(()=>Qa(`cycle_agent`,Ee?{cycle_agent:Ee}:void 0),[Ee]),{favoriteModelsList:ke,recentModelsList:Ae}=va({currentProviderID:b,currentModelID:x}),{isMobile:je}=mo(),Me=q(e=>e.isMobile),Ne=je||Me,Pe=jo(),Fe=Ne,[Ie,Le]=Z.useState(null),Re=n!==void 0&&typeof r==`function`,ze=Re?n:Ie,Be=Re?r:Le,Ve=J(e=>{Be(e),Ai.getState().refreshCatalogsOnPickerOpen({source:`modelControls:mobilePanel`})}),He=J((e,t)=>{if(Nm(e,t?.reason)){t?.cancel?.();return}be(e),e&&Ai.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopAgentMenu`})}),[Ue,We]=Z.useState(null),Ge=Z.useRef(!1),Ke=Z.useCallback(()=>Be(null),[Be]),qe=Z.useCallback(()=>We(null),[]),Je=Z.useRef(void 0),Ye=_e,Xe=ve,Ze=Z.useCallback(()=>{k(oh),we(`providers`),Ce(!0),Xe(!1),Ke()},[k,we,Ce,Xe,Ke]),[Qe,$e]=Z.useState(``),[et,tt]=Z.useState(null),[nt,rt]=Z.useState(!1),it=Z.useRef(0),at=J((e,t)=>{if(Nm(e,t?.reason)){t?.cancel?.();return}rt(!1),e||(it.current=performance.now()+200,tt(null),$e(``)),Xe(e),e&&Ai.getState().refreshCatalogsOnPickerOpen({source:`modelControls:desktopModelMenu`})}),ot=Z.useRef(!1),st=Z.useRef(null),lt=Z.useRef(void 0),[ut,dt]=Z.useState(new Map),[ft,pt]=Z.useState(new Set),[mt,ht]=Z.useState(0),gt=Z.useCallback(()=>{let e=()=>{let e=q.getState();!e.isModelSelectorOpen&&!e.isAgentSelectorOpen&&Fm(t)};window.setTimeout(()=>{requestAnimationFrame(()=>{e(),requestAnimationFrame(e)})},0)},[t]),_t=Z.useCallback(e=>{let t=q.getState();(e===`model`?t.isModelSelectorOpen:t.isAgentSelectorOpen)||(q.setState(e===`model`?{isModelSelectorInstant:!1}:{isAgentSelectorInstant:!1}),!q.getState().isMobile&>())},[gt]),vt=Z.useCallback(()=>{let e=q.getState();return e.isModelSelectorOpen||e.isAgentSelectorOpen?!1:Pm(t)},[t]),yt=Z.useRef(_e);Z.useEffect(()=>{let e=yt.current;yt.current=_e,_e||($e(``),ot.current=!1,st.current=null,dt(new Map),pt(new Set),e&&!Fe&&(rt(!1),it.current=performance.now()+200))},[_e,Fe]);let[bt,St]=Z.useState(``);Z.useEffect(()=>{ye||St(``)},[ye]);let Ct=Z.useMemo(()=>R.filter(e=>qn(e.mode)),[R]),wt=Z.useMemo(()=>bt.trim()?bi(Ct,bt.trim(),e=>[e.name,e.description??``]).map(e=>e.item):[...Ct].sort((e,t)=>e.name.localeCompare(t.name)),[Ct,bt]),Tt=Z.useMemo(()=>{if(D){let e=Ct.find(e=>e.name===D);if(e)return e.name}let e=Ct.find(e=>e.name===`build`);return e?e.name:Ct[0]?.name},[D,Ct]),Et=Z.useMemo(()=>ce?R.find(e=>e.name===ce):I?.(),[R,I,ce]),Dt=Ne?`mobile`:Pe?`vscode`:`default`,Ot=Dt===`mobile`?`size-5`:`size-4`,kt=Fe?`typography-micro`:`typography-meta`,At=Dt===`mobile`?`gap-x-1`:Dt===`vscode`?`gap-x-2`:`gap-x-1.5`,jt=Dt===`mobile`?`h-8 w-8`:Dt===`vscode`?`h-5 w-5`:`h-6 w-6`,Mt=Dt===`mobile`?18:Dt===`vscode`?14:16,Nt=dm(ce),Pt=i?_.find(e=>e.id===b):P(),Ft=Array.isArray(Pt?.models)?Pt.models:[],It=x?Ft.find(e=>e.id===x):void 0,Lt=b&&x&&It?xa(b,It,F(b,x)):b&&x?F(b,x):void 0,Rt=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]),zt=Z.useMemo(()=>dh(Lt).map(e=>({...e,label:Rt(e.label)})),[Lt,Rt]),Vt=Z.useMemo(()=>nh(Lt,`input`).map(e=>({...e,label:Rt(e.label)})),[Lt,Rt]),Ht=Z.useMemo(()=>nh(Lt,`output`).map(e=>({...e,label:Rt(e.label)})),[Lt,Rt]),Wt=Z.useMemo(()=>{if(f?.variantsReady===!1)return[];if(f?.variants)return[...f.variants];if(b&&x){let e=_.find(e=>e.id===b)?.models?.find(e=>e.id===x);return Lm(e)}return i?[]:M()},[x,b,M,_,i,f?.variants,f?.variantsReady]),Gt=Wt.length>0,Kt=[{label:`Input`,value:uh(Lt?.cost?.input)},{label:`Output`,value:uh(Lt?.cost?.output)},{label:`Cache read`,value:uh(Lt?.cost?.cache_read)},{label:`Cache write`,value:uh(Lt?.cost?.cache_write)}],qt=[{label:`Context`,value:lh(Lt?.limit?.context)},{label:`Output`,value:lh(Lt?.limit?.output)}],Jt=Z.useRef(void 0),Yt=Z.useRef(null),Xt=Z.useRef(null),Zt=V?H(V):void 0,Qt=Mi(V??``,Zt??void 0).renderable,$t=fr(V??``,Zt??void 0),tn=Z.useMemo(()=>{for(let e=$t.length-1;e>=0;--e){let t=$t[e];if(t.role!==`user`)continue;let n=typeof t.model?.providerID==`string`&&t.model.providerID.trim().length>0?t.model.providerID:void 0,r=typeof t.model?.modelID==`string`&&t.model.modelID.trim().length>0?t.model.modelID:void 0,i=typeof t.agent==`string`&&t.agent.trim().length>0?t.agent:typeof t.mode==`string`&&t.mode.trim().length>0?t.mode:void 0,a=t.model?.variant??t.variant,o=typeof a==`string`&&a.trim().length>0?a:void 0;return{id:t.id,agent:i,providerID:n,modelID:r,variant:o}}return null},[$t]),nn=Z.useCallback((e,t,n)=>{if(!e||!t)return`model-missing`;let r=_.find(t=>t.id===e);return r?(Array.isArray(r.models)?r.models:[]).find(e=>e.id===t)?b===e&&x===t?`applied`:(O(e),A(t),V&&(ee(V,e,t),n&&K(V,n,e,t)),`applied`):`model-missing`:`provider-missing`},[_,b,x,O,A,V,K,ee]),rn=Z.useCallback((e,t)=>{if(i&&i.selection.providerID===e&&i.selection.modelID===t)return Rm(i.selection,i.catalog,e,t);let n=_.find(t=>t.id===e)?.models?.find(e=>e.id===t);return Lm(n)},[_,i,i?.selection.providerID,i?.selection.modelID,f?.variants,f?.variantsReady]),an=Z.useCallback((e,t)=>{let n=i?Rm(i.selection,i.catalog,e,t):[],r=n.length>0?n:rn(e,t);if(r.length===0)return;if(i){let n=i.selection.variant;if(i.selection.providerID===e&&i.selection.modelID===t&&n&&r.includes(n))return n}let a=ce||T;if(V&&a){let n=re(V,a,e,t);if(n&&r.includes(n))return n}if(b===e&&x===t&&C&&r.includes(C))return C;if(!V&&E&&r.includes(E))return E},[T,x,b,V,C,re,rn,i,E,ce]),on=Z.useCallback(()=>{if(i)return i.selection.agent??void 0;let e=Ai.getState().currentAgentName;return V?Zi.getState().getSessionAgentSelection(V)||oe.current||e||T:e||T},[T,V,i]),sn=Z.useCallback((e,t,n,r)=>{if(i){i.onChange({...i.selection,providerID:e,modelID:t,variant:n}).catch(()=>void 0);return}if(rn(e,t).length===0){Ge.current=!1,j(void 0);return}Ge.current=!0,j(n),ge(e,t,n);let a=r??on();V&&a&&ne(V,a,e,t,n)},[ge,V,rn,on,ne,i,j]),cn=Z.useCallback((e,t,n,r)=>{let a=r??on()??void 0,o=nn(e,t,a);if(o!==`applied`)return o;sn(e,t,n,a);let s=i?n:Ai.getState().currentVariant;return me(e,t,s),`applied`},[me,sn,on,i,nn]);Z.useEffect(()=>{if(i)return;if(!V){Xt.current=null;return}if(!ie||_.length===0||!Qt||!tn?.providerID||!tn.modelID)return;let e=[V,tn.id,tn.agent??``,tn.providerID,tn.modelID,tn.variant??``].join(`|`);if(Xt.current===e)return;tn.agent&&T!==tn.agent&&N(tn.agent);let t=tn.variant&&rn(tn.providerID,tn.modelID).includes(tn.variant)?tn.variant:void 0;cn(tn.providerID,tn.modelID,t,tn.agent||T||void 0)===`applied`&&(tn.agent&&(G(V,tn.agent),ne(V,tn.agent,tn.providerID,tn.modelID,t)),ee(V,tn.providerID,tn.modelID),Xt.current=e)},[i,V,T,ie,_,Qt,tn,N,cn,rn,G,ne,ee]),Z.useEffect(()=>{if(i)return;if(!V){Xt.current=null;return}if(!ie||_.length===0||R.length===0)return;let e=()=>{let e=W(V),t=V?Zi.getState().getSessionAgentSelection(V):null;if(t){T!==t&&N(t);let e=te(V,t);if(e){let n=nn(e.providerId,e.modelId,t);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}}if(e){let n=nn(e.providerId,e.modelId,t||T||void 0);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}for(let e of R){let t=te(V,e.name);if(!t)continue;T!==e.name&&N(e.name),Zi.getState().getSessionAgentSelection(V)||oe.current||G(V,e.name);let n=nn(t.providerId,t.modelId,e.name);if(n===`applied`)return`resolved`;if(n===`provider-missing`)return`waiting`}return`continue`},t=()=>{if(R.length===0)return;let e=V?Zi.getState().getSessionAgentSelection(V)||oe.current:null,t=(V?Zi.getState().getSessionAgentSelection(V)||oe.current:null)||T;if(t&&R.some(e=>e.name===t)){T!==t&&N(t);return}let n=R.find(e=>e.name===`build`)||z[0]||R[0];n&&(e||G(V,n.name),T!==n.name&&N(n.name),n.model?.providerID&&n.model?.modelID&&nn(n.model.providerID,n.model.modelID,n.name))},n=e();if(n!==`resolved`&&n!==`waiting`){if(!Qt){U.isLoading(V)||U.ensureSessionRenderable(V);return}tn||t()}},[i,V,Qt,tn,R,z,T,W,te,N,nn,G,ie,_,U]),Z.useEffect(()=>{if(i||!ie)return;let e=new AbortController;return(async()=>{try{if(T!==Jt.current&&(Jt.current=T,T&&V)){let t=Yt.current===T;if(Yt.current=null,await new Promise(t=>{let n=setTimeout(t,50);e.signal.addEventListener(`abort`,()=>{clearTimeout(n),t()})}),e.signal.aborted)return;let n=te(V,T);if(n){let e=nn(n.providerId,n.modelId,T);if(e===`applied`||e===`provider-missing`)return}let r=Ai.getState().getAgentModelSelection(T);if(r){let e=nn(r.providerId,r.modelId,T);if(e===`applied`||e===`provider-missing`){e===`applied`&&(ee(V,r.providerId,r.modelId),K(V,T,r.providerId,r.modelId),r.variant!==void 0&&(ne(V,T,r.providerId,r.modelId,r.variant),j(r.variant)));return}}let i=t?R.find(e=>e.name===T):void 0;if(i?.model?.providerID&&i.model.modelID){let e=nn(i.model.providerID,i.model.modelID,T);if(e===`applied`||e===`provider-missing`){e===`applied`&&(ee(V,i.model.providerID,i.model.modelID),K(V,T,i.model.providerID,i.model.modelID));return}}}}catch(e){console.error(`[ModelControls] Agent change error:`,e)}})(),()=>{e.abort()}},[i,R,T,V,te,K,ne,ee,j,nn,ie]),Z.useEffect(()=>{if(i)return;if(!ie||!T){Ge.current=!1,j(void 0);return}if(!b||!x){Ge.current=!1,j(void 0);return}if(Wt.length===0){Ge.current=!1,j(void 0);return}if(C&&!Wt.includes(C)){j(void 0);return}if(!V){if(!C&&!Ge.current){let e=E&&Wt.includes(E)?E:void 0;j(e)}return}let e=re(V,T,b,x),t=e&&Wt.includes(e)?e:E&&Wt.includes(E)?E:void 0;j(t),Ge.current=!1},[i,Wt,ie,V,T,b,x,C,re,j,E]),Z.useEffect(()=>{Ge.current=!1},[b,x]);let ln=Z.useCallback((e,t)=>{if(i){let n=Bt(i.selection,e,R,_),r=n.providerID===i.selection.providerID&&n.modelID===i.selection.modelID;Fe&&Ke(),i.onChange({...n,variant:r?i.selection.variant:void 0}).then(()=>{he(e),(t?.closeModelSelector??!0)&&Xe(!1)}).catch(()=>void 0);return}try{Yt.current=e,N(e),he(e),(t?.closeModelSelector??!0)&&Xe(!1),V&&G(V,e),Fe&&Ke()}catch(e){console.error(`[ModelControls] Handle agent change error:`,e)}},[he,R,Ke,V,Fe,_,G,i,N,Xe]),un=Z.useCallback(e=>{let t=Ut(R,T,e);t&&ln(t,{closeModelSelector:!1})},[R,T,ln]),dn=Z.useCallback(e=>{let t=De&&!De.includes(`shift`)?Ja(`shift+${De}`):``;return t&&qa(e,t)?-1:qa(e,De)?1:null},[De]),fn=Z.useCallback(e=>{let t=dn(e);t&&(e.preventDefault(),e.stopPropagation(),un(t))},[dn,un]),pn=Z.useCallback((e,t,n,r)=>{!e||!t||!n||Ai.getState().saveAgentModelSelection(e,t,n,r)},[]),mn=(e,t,n)=>{let r=()=>{Xe(!1,n?.closeInstant?{instant:!0}:void 0)};if(i){Fe&&Ke();let a=n?.applyVariant?n.variant:an(e,t);i.onChange({providerID:e,modelID:t,agent:n?.agentName??i.selection.agent,variant:a}).then(()=>{me(e,t,a),r()}).catch(()=>void 0);return}try{let i=n?.agentName??on()??void 0,a=n?.applyVariant?cn(e,t,n.variant,i):nn(e,t,i);if(a!==`applied`){a===`provider-missing`?console.error(`[ModelControls] Provider not available for selection:`,e):a===`model-missing`&&console.error(`[ModelControls] Model not available for selection:`,{providerId:e,modelId:t});return}pn(i,e,t,n?.applyVariant?n.variant:Ai.getState().currentVariant),n?.applyVariant||me(e,t,Ai.getState().currentVariant),r(),Fe&&Ke()}catch(e){console.error(`[ModelControls] Handle model change error:`,e)}},hn=(e,t)=>en(e,t,{maxLength:40}),gn=()=>_.find(e=>e.id===b)?.name||b,_n=()=>{if(!x)return a(`chat.modelControls.selectModel`);let e=Ft.find(e=>e.id===x);return hn(e,x)||a(`chat.modelControls.selectModel`)},vn=_n(),yn=Z.useRef(null),bn=Mm(yn,[vn,C,Fe]),xn=()=>{if(!ce){let e=z.find(e=>e.name===`build`)||z[0];return e?Sn(e.name):`Select Agent`}let e=R.find(e=>e.name===ce);return Sn(e?e.name:ce)},Sn=e=>e.charAt(0).toUpperCase()+e.slice(1),Cn=Z.useCallback(e=>{Je.current&&clearTimeout(Je.current),Je.current=setTimeout(()=>{We(e)},500)},[]),wn=Z.useCallback(()=>{Je.current&&clearTimeout(Je.current)},[]);Z.useEffect(()=>()=>{Je.current&&clearTimeout(Je.current)},[]);let Tn=()=>!Fe||Ue!==`model`?null:(0,$.jsx)(sm,{open:!0,onClose:qe,title:Lt?.name||_n(),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:gn()})]}),zt.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:zt.map(({key:e,icon:t,label:n})=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(sh,{iconName:t,label:n},`cap-${e}`),(0,$.jsx)(`span`,{className:`typography-meta text-foreground`,children:n})]},e))})]}),(Vt.length>0||Ht.length>0)&&(0,$.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/30 px-2 py-1.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:a(`chat.modelControls.modalities`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[Vt.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:Vt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(sh,{iconName:t,label:`${n} input`},`input-${e}`))})]}),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.output`)}),(0,$.jsx)(`div`,{className:`flex gap-1`,children:Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(sh,{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:lh(Lt?.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:lh(Lt?.limit?.output)})]})]})]}),Lt?.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:fh(Lt.release_date)})]})})]}):null]})}),En=()=>{if(!Fe||Ue!==`agent`||!Et)return null;let e=!!(Et.prompt&&Et.prompt.trim().length>0),t=Et.model?.providerID&&Et.model?.modelID,n=Et.temperature!==void 0||Et.topP!==void 0,r=e=>{let t=Zm(Et.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=Qm(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)(sm,{open:!0,onClose:qe,title:Sn(Et.name),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[Et.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:Et.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:Et.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Et.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Et.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:[Et.model.providerID,` / `,Et.model.modelID]}),n&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[Et.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:Et.temperature})]}),Et.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:Et.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)(ch,{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)(ch,{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)(ch,{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`})]})})]})})},Dn=()=>Fe?(0,$.jsx)(ao,{open:ze===`model`||ze===`variant`,view:ze===`variant`?`variant`:`model`,onViewChange:e=>Be(e),onClose:Ke,selectedProviderID:b||``,selectedModelID:x||``,resolveSelectedVariant:an,onSelect:(e,t,n)=>{if(i){Ke(),i.onChange({providerID:e,modelID:t,agent:i.selection.agent,variant:n}).then(()=>{me(e,t,n)}).catch(()=>void 0);return}let r=cn(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}pn(on(),e,t,n),Ke()},providers:_,favoriteModels:ke,recentModels:Ae,hiddenModels:Te,providerOrder:de,isFavorite:pe,onToggleFavorite:(e,t)=>le(e,t,e===b&&t===x?C:ke.find(n=>n.providerID===e&&n.modelID===t)?.variant??Ae.find(n=>n.providerID===e&&n.modelID===t)?.variant),getMetadata:F}):null,On=()=>Fe?(0,$.jsx)(_a,{id:`mobile-agent-picker-sheet-${o}`,open:ze===`agent`,onOpenChange:e=>{e||Ke()},ariaLabel:a(`chat.modelControls.selectAgent`),closeAriaLabel:a(`mobile.surface.closeAria`),resizeAriaLabel:a(`mobile.sessions.sheet.resizeAria`),bodyClassName:`px-2`,children:(0,$.jsx)(pa,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`flex flex-col gap-2 overscroll-contain`,children:Ct.map(e=>{let t=e.name===ce,n=na(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:()=>ln(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)(la,{name:e.name,size:18}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block typography-ui-label font-semibold`,style:t?{color:`var(${n.var})`}:void 0,children:Sn(e.name)}),e.description&&(0,$.jsx)(`span`,{className:`mt-1 block min-w-0 whitespace-normal break-words typography-micro text-muted-foreground`,children:e.description})]}),t&&(0,$.jsx)(X,{name:`check`,className:`size-4 shrink-0 text-primary`})]})},e.name)})})}):null,kn=()=>(0,$.jsx)(Ua,{align:`start`,sideOffset:8,className:`max-w-[320px]`,children:Lt?(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:Lt.name||_n()}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:gn()})]}),(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:zt.length>0?zt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(sh,{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:Vt.length>0?Vt.map(({key:e,icon:t,label:n})=>(0,$.jsx)(sh,{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:Ht.length>0?Ht.map(({key:e,icon:t,label:n})=>(0,$.jsx)(sh,{iconName:t,label:`${n} output`},`output-${e}`)):(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:`-`})})]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.costPerMillion`)}),Kt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold uppercase tracking-wide text-muted-foreground/90`,children:a(`chat.modelControls.limits`)}),qt.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground/80`,children:e.label}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e.value})]},e.label))]}),Lt.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:fh(Lt.release_date)})]})]}):null]}):(0,$.jsx)(`div`,{className:`min-w-[200px] typography-meta text-muted-foreground`,children:a(`chat.modelControls.metadataUnavailable`)})}),An=()=>{let e=(e,t)=>{if(ot.current=!0,e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return!1;let{providerID:n,modelID:r}=t,i=rn(n,r);if(i.length===0)return!1;e.preventDefault(),e.stopPropagation();let a=Ym(n,r),o=ut.has(a),s=ut.get(a),c=o?s:b===n&&x===r?C: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 dt(e=>{let t=new Map(e);return t.set(a,d),t}),pt(e=>{let t=new Set(e);return t.add(a),t}),ht(e=>e+1),!0},t=(t,n)=>{let r=dn(t);if(r){t.preventDefault(),un(r);return}n&&e(t,n)},n=e=>{let t=Ym(e.providerID,e.modelID),n=ut.get(t),r=ft.has(t),i=on();if(r){mn(e.providerID,e.modelID,{applyVariant:!0,variant:n,agentName:i});return}let a=rn(e.providerID,e.modelID),o=e.variant!==void 0&&a.includes(e.variant)?e.variant:void 0;if(o!==void 0){mn(e.providerID,e.modelID,{applyVariant:!0,variant:o,agentName:i});return}mn(e.providerID,e.modelID,{agentName:i})},r=e=>{let t=dn(e);t&&(e.preventDefault(),e.stopPropagation(),ot.current=!0,un(t))},i=e=>e?.trim()?xt(e):a(`chat.modelControls.default`),o=(e,t)=>{let n=on();mn(e.providerID,e.modelID,{applyVariant:!0,variant:t,agentName:n,closeInstant:!0})},s=e=>{e&&(Ye||performance.now()<it.current)||rt(e)},c={searchPlaceholder:a(`chat.modelControls.searchModels`),noResults:a(`chat.modelControls.noModelsFound`),favorites:a(`chat.modelControls.favorites`),recent:a(`chat.modelControls.recent`),keyboardHint:a(`chat.modelControls.keyboardHintNavigate`),favorite:a(`chat.modelControls.favoriteAria`),unfavorite:a(`chat.modelControls.unfavoriteAria`),provider:a(`chat.modelControls.provider`),capabilities:a(`chat.modelControls.capabilities`),capabilityToolCalling:a(`chat.modelControls.capability.toolCalling`),capabilityReasoning:a(`chat.modelControls.capability.reasoning`),modalityImage:a(`chat.modelControls.modality.image`),modalityVideo:a(`chat.modelControls.modality.video`),modalityAudio:a(`chat.modelControls.modality.audio`),costPerMillion:a(`chat.modelControls.costPerMillion`),costInput:a(`chat.modelControls.costInput`),costOutput:a(`chat.modelControls.costOutput`)},u=(e,{isSelected:t})=>{let n=rn(e.providerID,e.modelID);if(n.length===0)return null;let r=Ym(e.providerID,e.modelID),o=ut.has(r),s=ut.get(r),c=e.variant!==void 0&&n.includes(e.variant)?e.variant:void 0,l=o?s:t?C:c,u=ft.has(r);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`group/thinking flex shrink-0 items-center gap-0.5 rounded-md px-1.5 py-0.5 typography-micro font-medium transition-colors`,u||l?`text-foreground/80`:`text-muted-foreground`,`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] hover:text-foreground`),onClick:t=>{t.preventDefault(),t.stopPropagation(),tt(e)},"aria-label":a(`chat.modelControls.showThinkingModes`),children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),(0,$.jsx)(`span`,{className:`max-w-20 truncate`,children:i(l)}),(0,$.jsx)(X,{name:`arrow-right-s`,className:`size-3 opacity-60 transition-transform group-hover/thinking:translate-x-px`})]})},d=()=>{if(!et)return null;let e=rn(et.providerID,et.modelID),t=Ym(et.providerID,et.modelID),n=ut.has(t),r=ut.get(t),s=et.providerID===b&&et.modelID===x,c=et.variant!==void 0&&e.includes(et.variant)?et.variant:void 0,l=n?r:s?C:c,u=en(et.model,et.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(),tt(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:()=>tt(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)(Ma,{modelId:et.modelID,providerId:et.providerID,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate typography-meta font-medium text-foreground`,children:u}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`shrink-0 text-border`,children:`·`}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3 opacity-70`}),a(`chat.modelControls.thinking`)]})]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 p-1`,role:`listbox`,"aria-label":a(`chat.modelControls.thinking`),children:[void 0,...e].map(e=>{let t=e===l||!e&&!l;return(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:Y(`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left typography-meta transition-colors`,t?`bg-interactive-selection text-interactive-selection-foreground`:`text-foreground hover:bg-interactive-hover/50`),onClick:()=>o(et,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)(Xp,{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=C&&Gt?xt(C):null;return(0,$.jsxs)(Wa,{open:!Ye&&nt,onOpenChange:s,delayDuration:200,children:[Fe?(0,$.jsx)(`button`,{type:`button`,onClick:p?()=>Ve(`model`):void 0,onTouchStart:p?()=>Cn(`model`):void 0,onTouchEnd:p?wn:void 0,onTouchCancel:p?wn:void 0,disabled:!p,className:Y(`model-controls__model-trigger min-w-0 focus:outline-none`,p?Y(`cursor-pointer`,_m):`opacity-60 cursor-not-allowed`),children:p?(0,$.jsxs)($.Fragment,{children:[b||x?(0,$.jsx)(Ma,{modelId:x,providerId:b,className:Y(Ot,`flex-shrink-0`)}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(Ot,`text-muted-foreground`)}),(0,$.jsx)(`span`,{ref:yn,className:Y(`model-controls__model-label typography-micro font-medium overflow-hidden min-w-0`,Ne?`max-w-[120px]`:`max-w-[220px]`),children:(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1`,bn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:vn}),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(Ot,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:`typography-micro font-medium text-muted-foreground min-w-0`,children:l})]})}):(0,$.jsxs)($a,{open:p&&Ye,onOpenChange:p?at:void 0,onOpenChangeComplete:e=>{e||_t(`model`)},children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(`div`,{className:Y(`model-controls__model-trigger cursor-pointer min-w-0`,_m),children:[p?b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ma,{modelId:x,providerId:b,className:Y(Ot,`flex-shrink-0`)}),(0,$.jsx)(X,{name:`pencil-ai`,className:Y(Ot,`text-primary/60 hidden`)})]}):(0,$.jsx)(X,{name:`pencil-ai`,className:Y(Ot,`text-muted-foreground`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(Ot,`animate-spin text-muted-foreground flex-shrink-0`)}),(0,$.jsx)(`span`,{className:Y(`model-controls__model-label`,kt,`font-medium whitespace-nowrap text-muted-foreground min-w-0`),children:l})]}),p&&(0,$.jsx)(`span`,{ref:yn,className:Y(`model-controls__model-label overflow-hidden`,kt,`font-medium whitespace-nowrap text-foreground min-w-0`,`max-w-[260px]`),children:(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1`,bn&&`marquee-text marquee-text--active`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:vn}),f?(0,$.jsx)(`span`,{className:`shrink-0 font-normal text-muted-foreground`,children:f}):null]})},`${b}-${x}-${C??``}`)]})})}),(0,$.jsx)(uo,{className:Y(`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,xe&&Xm),align:`end`,alignOffset:-40,onKeyDownCapture:r,finalFocus:vt,children:et?d():(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`p-1 border-b border-border/40`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:Ze,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)(ma,{providers:_,favoriteModels:ke,recentModels:Ae,getMetadata:F,searchQuery:Qe,onSearchQueryChange:$e,onSelect:n,labels:c,selectedModel:b&&x?{providerID:b,modelID:x}:null,hiddenModels:Te,onActiveKeyDown:t,onActiveEntryChange:e=>{lt.current=e},onVariantKey:e,isFavorite:e=>pe(e.providerID,e.modelID),onToggleFavorite:e=>le(e.providerID,e.modelID,e.providerID===b&&e.modelID===x?C:e.variant),renderRowEnd:u,renderVersion:mt,onReorderFavorite:(e,t)=>ue(e.providerID,e.modelID,t.providerID,t.modelID),reorderFavoriteAriaLabel:a(`chat.modelControls.reorderFavoriteAria`),reorderFavoriteTitle:a(`chat.modelControls.reorderFavoriteTitle`),providerOrder:de,onReorderProvider:fe,reorderProviderTitle:a(`chat.modelControls.reorderProviderTitle`),footerContent:e=>{let t=e?rn(e.providerID,e.modelID).length>0:!1;return(0,$.jsxs)(`div`,{className:`flex items-center gap-x-2 whitespace-nowrap overflow-hidden`,children:[(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintNavigate`)}),(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintSwitchAgent`,{shortcut:`Tab`})}),t?(0,$.jsx)(`span`,{children:a(`chat.modelControls.keyboardHintThinking`)}):null]})},tooltipsEnabled:Ye&&!et,onEscape:()=>{if(et){tt(null);return}Xe(!1)}})]})})]}),kn()]})},jn=()=>{if(!Et)return(0,$.jsx)(Ua,{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=!!(Et.prompt&&Et.prompt.trim().length>0),t=Et.model?.providerID&&Et.model?.modelID,n=Et.temperature!==void 0||Et.topP!==void 0,r=e=>{let t=Zm(Et.permission)??[],n=t.some(t=>t.permission===e&&t.pattern!==`*`),r=Qm(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)(Ua,{align:`start`,sideOffset:8,className:`max-w-[280px]`,children:(0,$.jsxs)(`div`,{className:`flex min-w-[200px] flex-col gap-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-micro font-semibold text-foreground`,children:Sn(Et.name)}),Et.description&&(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:Et.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:Et.mode===`primary`?a(`chat.modelControls.modeValue.primary`):Et.mode===`subagent`?a(`chat.modelControls.modeValue.subagent`):Et.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:[Et.model.providerID,` / `,Et.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:[Et.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:Et.temperature})]}),Et.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:Et.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)(ch,{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)(ch,{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)(ch,{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`})]})]})})},Mn=()=>{let e=xn(),t=ce?na(ce):null;return Fe?(0,$.jsx)(`button`,{type:`button`,onClick:m?()=>Ve(`agent`):void 0,onTouchStart:m?()=>Cn(`agent`):void 0,onTouchEnd:m?wn:void 0,onTouchCancel:m?wn:void 0,disabled:!m,className:Y(`model-controls__agent-trigger inline-flex items-center flex-shrink-0 min-w-0 focus:outline-none`,vm,m?`cursor-pointer`:`opacity-60 cursor-not-allowed`),children:m?(0,$.jsx)(um,{name:ce,label:e,revealed:Nt,avatarSize:Mt,slotClassName:jt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,jt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(Ot,`flex-shrink-0 animate-spin text-muted-foreground`)})})}):(0,$.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,$.jsxs)(Wa,{delayDuration:600,children:[(0,$.jsxs)($a,{open:m&&ye,onOpenChange:m?He:void 0,onOpenChangeComplete:e=>{e||_t(`agent`)},children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsx)(`div`,{className:Y(`inline-flex cursor-pointer items-center flex-shrink-0 min-w-0`,vm),children:m?(0,$.jsx)(um,{name:ce,label:e,revealed:Nt,avatarSize:Mt,slotClassName:jt,colorVar:t?.var}):(0,$.jsx)(`span`,{className:Y(`inline-flex items-center justify-center`,jt),children:(0,$.jsx)(X,{name:`loader-4`,className:Y(Ot,`flex-shrink-0 animate-spin text-muted-foreground`)})})})})}),(0,$.jsxs)(uo,{align:`end`,alignOffset:-40,className:Y(`w-[min(280px,calc(100vw-2rem))] p-0 flex flex-col`,Se&&Xm),onKeyDownCapture:fn,finalFocus:vt,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)(Va,{type:`text`,placeholder:a(`chat.modelControls.searchAgents`),value:bt,onChange:e=>St(e.target.value),onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),be(!1);return}e.stopPropagation()},className:`pl-8 h-8 typography-meta`})]})}),(0,$.jsx)(pa,{outerClassName:`max-h-[min(400px,calc(100dvh-12rem))] flex-1`,children:(0,$.jsxs)(`div`,{className:`p-1`,children:[!bt.trim()&&Tt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(po,{className:`typography-meta`,onSelect:()=>ln(Tt),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)(Ya,{})]}),wt.length===0?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-meta text-muted-foreground`,children:`No agents found`}):wt.map(e=>(0,$.jsx)(po,{className:`typography-meta`,onSelect:()=>ln(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)(la,{name:e.name,size:14}),(0,$.jsx)(`span`,{className:`font-medium`,children:Sn(e.name)})]}),e.description&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground min-w-0 max-w-full ml-5 break-words`,children:e.description})]})},e.name))]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border/40 px-2 py-1.5 typography-micro text-muted-foreground`,children:[(0,$.jsx)(Xp,{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`)})]})]})]}),jn()]})})},Nn=Y(`@container/model-controls flex items-center min-w-0`,Ne&&`w-full`,e),Pn=Mn();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Nn,children:(0,$.jsxs)(`div`,{className:Y(`flex items-center min-w-0 flex-1 justify-end`,At,Ne&&`overflow-hidden`),children:[Pn,An()]})}),Dn(),On(),Tn(),En()]})},mh=[{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`}],hh=e=>{let t=(0,Q.c)(16),{className:n}=e,{t:r}=ct(),i=uu(gh),a=q(_h),o;t[0]===a?o=t[1]:(o=Za(Qa(`leader_key`,a)||`ctrl+x`),t[0]=a,t[1]=o);let s=o;if(!i)return null;let c;t[2]===r?c=t[3]:(c=r(`chat.leaderKey.pendingAria`),t[2]=r,t[3]=c);let l;t[4]===n?l=t[5]:(l=Y(`pointer-events-none absolute left-1/2 top-0 z-20 -translate-x-1/2 -translate-y-[calc(100%+0.4rem)]`,`inline-flex max-w-[calc(100cqw-1rem)] items-center gap-2 overflow-x-auto rounded-lg border px-2.5 py-1.5`,`border-[var(--interactive-border)] bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)]`,`shadow-sm animate-in fade-in-0 zoom-in-95 duration-150 whitespace-nowrap`,n),t[4]=n,t[5]=l);let u;t[6]===s?u=t[7]:(u=(0,$.jsx)(Zp,{shortcut:s,className:`opacity-[0.35] [&_[data-slot=kbd]]:rounded-md [&_[data-slot=kbd]]:border-0 [&_[data-slot=kbd]]:bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] [&_[data-slot=kbd]]:text-muted-foreground/65 [&_[data-slot=kbd]]:shadow-none`}),t[6]=s,t[7]=u);let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`span`,{className:`typography-micro text-[var(--surface-muted-foreground)]`,children:`·`}),t[8]=d):d=t[8];let f;t[9]===r?f=t[10]:(f=mh.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)(Xp,{className:`rounded-md border-0 bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] text-muted-foreground/65 shadow-none`,children:e.key}),(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(e.labelKey)})]})]},e.key)),t[9]=r,t[10]=f);let p;return t[11]!==c||t[12]!==l||t[13]!==u||t[14]!==f?(p=(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":c,className:l,children:[u,d,f]}),t[11]=c,t[12]=l,t[13]=u,t[14]=f,t[15]=p):p=t[15],p};function gh(e){return e.pending}function _h(e){return e.shortcutOverrides}var vh=28,yh=8,bh=10.5,xh=Math.PI/2,Sh=e=>Array.from({length:yh},(t,n)=>{let r=n/yh*Math.PI*2-Math.PI/2+e;return[Math.cos(r)*bh,Math.sin(r)*bh]}),Ch=[Sh(0),Sh(xh),Sh(Math.PI),Sh(Math.PI*1.5)],wh=([e,t])=>`${e.toFixed(1)}px, ${t.toFixed(1)}px`,Th=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/vh,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:Ch[0].map(Eh)}),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 Eh(e,t){return(0,$.jsx)(`span`,{className:`oc-morph-orb-dot`,style:{"--m-1":wh(Ch[0][t]),"--m-2":wh(Ch[1][t]),"--m-3":wh(Ch[2][t]),"--m-4":wh(Ch[3][t])}},t)}var Dh=1200,Oh=600,kh=1e9,Ah=0xe8d4a51000,jh=e=>e>=Ah?e:e>=kh?e*1e3:Date.now()+e;function Mh({isWorking:e,isMobile:t,statusText:n,isGenericStatus:r,isWaitingForPermission:i,retryInfo:a,turnStartedAt:o,isTurnSettled:s=!1}){let{locale:c,t:l}=ct(),[u,d]=Z.useState(null),[f,p]=Z.useState(!1),m=Z.useRef(u),h=Z.useRef(f),g=Z.useRef(!1);m.current=u,h.current=f;let _=Z.useRef(0),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(null),[x,S]=Z.useState(null),[C,w]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!e||typeof o!=`number`||a)return;w(Date.now());let t=window.setInterval(()=>w(Date.now()),1e3);return()=>window.clearInterval(t)},[e,o,a]),Z.useEffect(()=>{let e=a?.next;if(!e||e<=0){S(null);return}let t=jh(e),n=()=>{let e=Math.max(0,t-Date.now());S(Math.ceil(e/1e3))};n();let r=setInterval(n,500);return()=>clearInterval(r)},[a?.next,a?.attempt]);let T=J(()=>{y.current&&=(clearTimeout(y.current),null),b.current&&=(clearTimeout(b.current),null)}),E=J((e,t,n=!1)=>{T(),v.current=null,d(e),p(t),g.current=n,_.current=Date.now()}),D=J(()=>{if(y.current)return;let e=Date.now()-_.current,t=Math.max(0,Dh-e);y.current=setTimeout(()=>{y.current=null;let e=v.current;e&&E(e.text,e.permission,e.generic)},t)});if(Z.useEffect(()=>{if(s){T(),v.current=null,m.current&&(d(null),p(!1),g.current=!1);return}if(!e){if(y.current&&=(clearTimeout(y.current),null),v.current=null,!m.current||b.current)return;b.current=setTimeout(()=>{b.current=null,d(null),p(!1),g.current=!1},Oh);return}if(b.current&&=(clearTimeout(b.current),null),a){T(),v.current=null;return}let t=i?l(`chat.assistantStatus.waitingForPermission`):n,o=!!i,c=!!r&&!o;if(t){if(!m.current){E(t,o,c);return}if((t!==m.current||o!==h.current)&&!(c&&g.current)){if(c){v.current={text:t,permission:o,generic:c},D();return}E(t,o,c)}}},[e,s,n,r,i,a,l]),Z.useEffect(()=>()=>T(),[]),s||!e&&!u)return null;if(a&&e){let e=x!==null&&x>0?new Intl.RelativeTimeFormat(c,{numeric:`always`,style:`short`}).format(x,`second`):null,n=e?a.attempt&&a.attempt>1?l(`chat.assistantStatus.retryingInAttempt`,{duration:e,attempt:a.attempt}):l(`chat.assistantStatus.retryingIn`,{duration:e}):a.attempt&&a.attempt>1?l(`chat.assistantStatus.retryingAttempt`,{attempt:a.attempt}):l(`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)(Th,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:n})]})})}if(!u)return null;let O=u,k=typeof o==`number`&&e?vt(Math.max(0,C-o)):null;return(0,$.jsx)(`div`,{className:`flex h-full items-center text-muted-foreground`,role:`status`,"aria-live":f?`assertive`:`polite`,"aria-label":O,"data-waiting":f?`true`:void 0,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center ${t?`gap-1 typography-meta !text-[length:var(--text-meta)]`:`gap-1.5 typography-ui-header`}`,children:[(0,$.jsx)(`span`,{className:`inline-flex flex-none items-center justify-center ${t?`h-5 w-4`:`h-6 w-3.5`}`,children:(0,$.jsx)(Th,{isMobile:t})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer min-w-0 truncate whitespace-nowrap`,children:O}),k?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 font-light text-muted-foreground/70 tabular-nums`,"aria-hidden":`true`,children:k}):null]})})}var Nh={compose:!0,mutateSession:!0,answerRequests:!0,openTimeline:!0,navigateNestedSession:!0,textSelectionActions:!0,forkSession:!0},Ph={compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,navigateNestedSession:!0,textSelectionActions:!1,forkSession:!1},Fh={kind:`primary`,surfaceId:`primary`,sessionId:null,directory:null,active:!0,capabilities:Nh},Ih=e=>({kind:`primary`,surfaceId:`explicit:${e.viewKey}`,sessionId:e.sessionId,directory:e.directory,active:e.active,capabilities:e.active?Nh:Ph}),Lh=Z.createContext(Fh),Rh=()=>Z.useContext(Lh),zh=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}),Bh=(e,t,n,r)=>e.capabilities.navigateNestedSession?e.navigateSession?(e.navigateSession(t,n),!0):e.kind===`primary`&&(r(),!0):!1,Vh={containerType:`inline-size`,containerName:`status-row`},Hh=[],Uh=e=>{let t=(0,Q.c)(99),{isWorking:n,statusText:r,isGenericStatus:i,isWaitingForPermission:a,wasAborted:o,abortActive:s,retryInfo:c,turnStartedAt:l,isTurnSettled:u,showAbortStatus:d,showAbortPrompt:f,showAssistantStatus:p,showTodos:m,agentName:h,leftAccessory:g}=e,_=n!==void 0&&n,v=r===void 0?null:r,y=u!==void 0&&u,b=f!==void 0&&f,x=p===void 0||p,S=m===void 0||m,{t:C}=ct(),[w,T]=Z.useState(!1),E=Rh(),D=ri(Wh),O=E.sessionId??D,k;t[0]!==O||t[1]!==S?(k=e=>!S||!O?Hh:e.todo[O]??Hh,t[0]=O,t[1]=S,t[2]=k):k=t[2];let A=tn(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=Tn(j),N;bb0:{if(!O){N=Hh;break bb0}if(A.length>0){N=A;break bb0}N=M??Hh}let P=N,F=q(Gh),I;t[6]===F?I=t[7]:(I=F||se(),t[6]=F,t[7]=I);let L=I,R;t[8]===P?R=t[9]:(R=P.filter(Kh),t[8]=P,t[9]=R);let z=R,B;t[10]===z?B=t[11]:(B=z.find(qh)||z.find(Jh)||null,t[10]=z,t[11]=B);let V=B,H;t[12]===z?H=t[13]:(H=z.find(Yh)??null,t[12]=z,t[13]=H);let U=H,W;t[14]===P?W=t[15]:(W=P.filter(Xh),t[14]=P,t[15]=W);let ee=W.length,G;t[16]===P?G=t[17]:(G=P.filter(Zh),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(Qh),t[21]=z,t[22]=re);let ie=re.length,ae;t[23]===z?ae=t[24]:(ae=z.filter($h),t[23]=z,t[24]=ae);let oe=ae.length,ce;t[25]!==ie||t[26]!==oe?(ce={active:ie,left:oe},t[25]=ie,t[26]=oe,t[27]=ce):ce=t[27];let le=ce,ue=S&&le.left>0,de=!!b,[fe,pe]=Z.useState(!1),me,he;t[28]!==fe||t[29]!==y||t[30]!==_?(me=()=>{if(y){pe(!1);return}if(_){pe(!0);return}if(!fe)return;let e=window.setTimeout(()=>pe(!1),600);return()=>window.clearTimeout(e)},he=[_,fe,y],t[28]=fe,t[29]=y,t[30]=_,t[31]=me,t[32]=he):(me=t[31],he=t[32]),Z.useEffect(me,he);let ge=x&&(!y&&(_||fe)||!!o||!!d),_e=!!g,ve=!d&&!de&&(o||!s),ye=de||ge||ue||_e,be=Z.useRef(null),xe=Z.useRef(null),Se=Z.useRef(null),Ce,we;t[33]===w?(Ce=t[34],we=t[35]):(Ce=()=>{let e=xe.current,t=Se.current;if(!w||!e||!t)return;let n=t.offsetTop-e.offsetTop-(e.clientHeight-t.offsetHeight)/2,r=e.scrollHeight-e.clientHeight;e.scrollTop=Math.min(r,Math.max(0,n))},we=[w],t[33]=w,t[34]=Ce,t[35]=we),Z.useLayoutEffect(Ce,we);let Te,Ee;t[36]===w?(Te=t[37],Ee=t[38]):(Te=()=>{if(!w)return;let e=e=>{be.current&&!be.current.contains(e.target)&&T(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},Ee=[w],t[36]=w,t[37]=Te,t[38]=Ee),Z.useEffect(Te,Ee);let De;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(De=()=>T(eg),t[39]=De):De=t[39];let Oe=J(De),ke;t[40]!==le.active||t[41]!==le.left||t[42]!==C?(ke=C(`chat.statusRow.summary.activeLeft`,{active:le.active,left:le.left}),t[40]=le.active,t[41]=le.left,t[42]=C,t[43]=ke):ke=t[43];let Ae=ke,je;t[44]!==V||t[45]!==ue||t[46]!==L||t[47]!==w||t[48]!==ne||t[49]!==C||t[50]!==Ae||t[51]!==Oe?(je=ue?(0,$.jsxs)(`button`,{type:`button`,onClick:Oe,className:Y(Ec,`shrink-0`),"aria-label":Ae,title:Ae,children:[(0,$.jsx)(X,{name:`list-check-3`,className:kc}),!L&&V?(0,$.jsx)(`span`,{className:Y(`status-row__active-todo max-w-[200px]`,zc),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:wc,"aria-hidden":`true`,children:[ne.completed,`/`,ne.total]}),w?(0,$.jsx)(X,{name:`arrow-up-s`,className:kc}):(0,$.jsx)(X,{name:`arrow-down-s`,className:kc})]}):null,t[44]=V,t[45]=ue,t[46]=L,t[47]=w,t[48]=ne,t[49]=C,t[50]=Ae,t[51]=Oe,t[52]=je):je=t[52];let Me=je;if(!ye)return null;let Ne=!_e&&`chat-column`,Pe;t[53]===Ne?Pe=t[54]:(Pe=Y(`mb-1`,Ne),t[53]=Ne,t[54]=Pe);let Fe=_e&&`px-3`,Ie;t[55]===Fe?Ie=t[56]:(Ie=Y(`flex items-center justify-between py-0.5 gap-2 h-[1.2rem]`,Fe),t[55]=Fe,t[56]=Ie);let Le=!_e&&`overflow-x-hidden`,Re;t[57]===Le?Re=t[58]:(Re=Y(`flex-1 flex items-center min-w-0 gap-2`,Le),t[57]=Le,t[58]=Re);let ze;t[59]!==h||t[60]!==O||t[61]!==de||t[62]!==i||t[63]!==F||t[64]!==y||t[65]!==a||t[66]!==_||t[67]!==g||t[68]!==c||t[69]!==ve||t[70]!==d||t[71]!==x||t[72]!==v||t[73]!==C||t[74]!==l?(ze=de?(0,$.jsx)(`div`,{className:`flex min-w-0 items-center text-muted-foreground`,role:`status`,"aria-live":`polite`,"aria-label":C(`chat.statusRow.abortPrompt`),children:(0,$.jsxs)(`span`,{className:Y(`flex min-w-0 items-center typography-ui-label`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5`,"aria-hidden":`true`})}),(0,$.jsx)(`span`,{className:`animate-text-shimmer truncate whitespace-nowrap`,children:C(`chat.statusRow.abortPrompt`)})]})}):x&&d?(0,$.jsx)(`div`,{className:`flex h-full items-center text-[var(--status-error)]`,children:(0,$.jsxs)(`span`,{className:Y(`flex items-center typography-ui-label`,F?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,F?`h-5 w-4`:`h-6 w-3.5`),children:(0,$.jsx)(X,{name:`close-circle`,className:`size-3.5`,"aria-hidden":`true`})}),C(`chat.statusRow.aborted`)]})}):x&&ve?(0,$.jsx)(Mh,{isWorking:_,isMobile:F,statusText:v,isGenericStatus:i,isWaitingForPermission:a,retryInfo:c,turnStartedAt:l,isTurnSettled:y,agentName:h},O??`no-session`):g||null,t[59]=h,t[60]=O,t[61]=de,t[62]=i,t[63]=F,t[64]=y,t[65]=a,t[66]=_,t[67]=g,t[68]=c,t[69]=ve,t[70]=d,t[71]=x,t[72]=v,t[73]=C,t[74]=l,t[75]=ze):ze=t[75];let Be;t[76]!==Re||t[77]!==ze?(Be=(0,$.jsx)(`div`,{className:Re,children:ze}),t[76]=Re,t[77]=ze,t[78]=Be):Be=t[78];let Ve=!_e&&`-mr-3`,He;t[79]===Ve?He=t[80]:(He=Y(`relative flex items-center gap-2 flex-shrink-0`,Ve),t[79]=Ve,t[80]=He);let Ue;t[81]!==U||t[82]!==ue||t[83]!==w||t[84]!==ne||t[85]!==C||t[86]!==z?(Ue=w&&ue&&(0,$.jsxs)(`div`,{style:Dc,className:Y(Nc,`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:xe,className:Kc,children:z.map((e,t)=>(0,$.jsx)(Jc,{todo:e,isActive:e===U,activeRef:e===U?Se:void 0},e.id??`todo-${t}`))})]}),t[81]=U,t[82]=ue,t[83]=w,t[84]=ne,t[85]=C,t[86]=z,t[87]=Ue):Ue=t[87];let We;t[88]!==He||t[89]!==Ue||t[90]!==Me?(We=(0,$.jsxs)(`div`,{className:He,ref:be,children:[Me,Ue]}),t[88]=He,t[89]=Ue,t[90]=Me,t[91]=We):We=t[91];let Ge;t[92]!==Ie||t[93]!==Be||t[94]!==We?(Ge=(0,$.jsxs)(`div`,{className:Ie,children:[Be,We]}),t[92]=Ie,t[93]=Be,t[94]=We,t[95]=Ge):Ge=t[95];let Ke;return t[96]!==Pe||t[97]!==Ge?(Ke=(0,$.jsx)(`div`,{className:Pe,style:Vh,children:Ge}),t[96]=Pe,t[97]=Ge,t[98]=Ke):Ke=t[98],Ke};function Wh(e){return e.currentSessionId}function Gh(e){return e.isMobile}function Kh(e){return e.status!==`cancelled`}function qh(e){return e.status===`in_progress`}function Jh(e){return e.status===`pending`}function Yh(e){return e.status===`in_progress`}function Xh(e){return e.status!==`cancelled`}function Zh(e){return e.status===`completed`}function Qh(e){return e.status===`in_progress`}function $h(e){return e.status===`in_progress`||e.status===`pending`}function eg(e){return!e}var tg=Z.createContext(null),ng=e=>{let t=(0,Q.c)(3),{actions:n,children:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(tg.Provider,{value:n,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},rg=()=>Z.useContext(tg),ig=new Set([`edit`,`multiedit`,`write`,`apply_patch`,`create`,`file_write`]),ag=e=>`insertions`in e,og=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e))},sg=e=>{let t=0,n=0;for(let r of e.split(`
|
|
6521
|
+
`))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},cg=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!ig.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:og(i.additions)??void 0,deletions:og(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:og(e.additions)??void 0,deletions:og(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:og(i.additions)??void 0,deletions:og(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=sg(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},lg=(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:bo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},ug=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},dg=(e,t)=>yo(e,t),fg=(e,t)=>{let n=ag(e)&&e.relativePath?e.relativePath:dg(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},pg=e=>ag(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},mg=2;function hg(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t)}}function gg(e,t=mg){let n=e??``,r=n.startsWith(`/`),i=n.split(`/`).filter(Boolean);if(i.length===0)return{prefix:``,parent:``,stem:``,ext:``,name:``,leadingSlash:r};let a=i[i.length-1]??``,{stem:o,ext:s}=hg(a),c=Math.max(1,Math.floor(t)),l=Math.min(i.length-1,c-1),u=i.length-1-l,d=l>0?i.slice(u,-1).join(`/`):``,f=i.slice(0,u).join(`/`),p=f?r?`/${f}`:f:``;return{prefix:p,parent:d,stem:o,ext:s,name:a,leadingSlash:r&&!p}}function _g(e){let t=(0,Q.c)(36),{path:n,className:r,title:i,dirClassName:a,nameClassName:o}=e,s=a===void 0?`text-muted-foreground`:a,c=o===void 0?`text-foreground`:o,l;t[0]===n?l=t[1]:(l=gg(n),t[0]=n,t[1]=l);let{prefix:u,parent:d,stem:f,ext:p,leadingSlash:m}=l,h=!!(u||d),g;t[2]===r?g=t[3]:(g=Y(`flex min-w-0 items-baseline overflow-hidden`,r),t[2]=r,t[3]=g);let _=i??n,v;t[4]!==s||t[5]!==m?(v=m?(0,$.jsx)(`span`,{className:Y(`shrink-0`,s),children:`/`}):null,t[4]=s,t[5]=m,t[6]=v):v=t[6];let y;t[7]!==s||t[8]!==u?(y=u?(0,$.jsx)(`span`,{className:Y(`min-w-0 shrink-[9999] truncate`,s),children:u}):null,t[7]=s,t[8]=u,t[9]=y):y=t[9];let b;t[10]!==s||t[11]!==d||t[12]!==u?(b=d?(0,$.jsxs)(`span`,{className:Y(`shrink-0`,s),children:[u?`/`:``,d]}):null,t[10]=s,t[11]=d,t[12]=u,t[13]=b):b=t[13];let x;t[14]!==s||t[15]!==h?(x=h?(0,$.jsx)(`span`,{className:s,children:`/`}):null,t[14]=s,t[15]=h,t[16]=x):x=t[16];let S;t[17]===c?S=t[18]:(S=Y(`min-w-0 truncate`,c),t[17]=c,t[18]=S);let C;t[19]!==f||t[20]!==S?(C=(0,$.jsx)(`span`,{className:S,children:f}),t[19]=f,t[20]=S,t[21]=C):C=t[21];let w;t[22]!==p||t[23]!==c?(w=p?(0,$.jsx)(`span`,{className:Y(`shrink-0`,c),children:p}):null,t[22]=p,t[23]=c,t[24]=w):w=t[24];let T;t[25]!==C||t[26]!==w||t[27]!==x?(T=(0,$.jsxs)(`span`,{className:`flex min-w-0 shrink items-baseline`,children:[x,C,w]}),t[25]=C,t[26]=w,t[27]=x,t[28]=T):T=t[28];let E;return t[29]!==T||t[30]!==g||t[31]!==_||t[32]!==v||t[33]!==y||t[34]!==b?(E=(0,$.jsxs)(`span`,{className:g,title:_,children:[v,y,b,T]}),t[29]=T,t[30]=g,t[31]=_,t[32]=v,t[33]=y,t[34]=b,t[35]=E):E=t[35],E}var vg=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=ct(),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:Tc,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Ac,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:qc,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}=fg(e,r),s=pg(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`,jc),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(yd,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(_g,{path:o?`${o}/${n}`:n,title:e.path,className:`min-w-0 flex-1`}),s.additions>0||s.deletions>0?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-baseline gap-1 text-xs tabular-nums leading-4 md:text-[0.8125rem] md:leading-5`,children:[s.additions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,s.additions]}):null,s.deletions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,s.deletions]}):null]}):null]},`${e.path}:${t}`)},t[14]=r,t[15]=i,t[16]=a,t[17]=e):e=t[17],u=n.map(e),t[9]=r,t[10]=n,t[11]=i,t[12]=a,t[13]=u}else u=t[13];let d;t[18]===u?d=t[19]:(d=(0,$.jsx)(`div`,{className:Kc,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},yg=`${Nc} origin-[var(--transform-origin)]`,bg=Dc,xg=Z.memo(()=>{let e=(0,Q.c)(60),{t}=ct(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=pc()??null,o=Z.useContext(Ao),s=fs(a),c;e[0]===a?c=e[1]:(c=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=c);let l=Xo(c),u=rg(),d,f;e[2]===n?(d=e[3],f=e[4]):(d=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},f=[n],e[2]=n,e[3]=d,e[4]=f),Z.useEffect(d,f);let p;bb0:{if(!a||s!==!0||!l||l.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],p=t;break bb0}let t;e[6]!==a||e[7]!==l.diffStats||e[8]!==l.files?(t=lg(l.files,l.diffStats,a),e[6]=a,e[7]=l.diffStats,e[8]=l.files,e[9]=t):t=e[9],p=t}let m=p,h=0,g=0;if(e[10]!==h||e[11]!==m||e[12]!==g){for(let e of m)h+=e.insertions,g+=e.deletions;e[10]=h,e[11]=m,e[12]=g,e[13]=h,e[14]=g}else h=e[13],g=e[14];let _;e[15]!==h||e[16]!==g?(_={totalAdded:h,totalRemoved:g},e[15]=h,e[16]=g,e[17]=_):_=e[17];let{totalAdded:v,totalRemoved:y}=_;if(!a||s!==!0||m.length===0)return null;let b;e[18]!==a||e[19]!==u||e[20]!==o?.editor?(b=e=>{if(!a||!ag(e))return;r(!1);let t=e.path;if(u){u.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=q.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]=u,e[20]=o?.editor,e[21]=b):b=e[21];let x=b,S=m.length,C;e[22]!==S||e[23]!==t?(C=t(S===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:S}),e[22]=S,e[23]=t,e[24]=C):C=e[24];let w=C,T,E;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(T=Y(Ec,`max-w-full text-left`),E=()=>r(Sg),e[25]=T,e[26]=E):(T=e[25],E=e[26]);let D,O;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(X,{name:`file-edit`,className:kc}),D=Y(zc,`shrink-0`),e[27]=D,e[28]=O):(D=e[27],O=e[28]);let k;e[29]===w?k=e[30]:(k=(0,$.jsx)(`span`,{className:D,children:w}),e[29]=w,e[30]=k);let A;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(A=Y(`status-row__changed-label`,zc),e[31]=A):A=e[31];let j;e[32]===t?j=e[33]:(j=t(`chat.pendingChanges.changedInWorkspace`),e[32]=t,e[33]=j);let M;e[34]===j?M=e[35]:(M=(0,$.jsx)(`span`,{className:A,children:j}),e[34]=j,e[35]=M);let N;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(N=Y(wc,`items-baseline gap-0.5`),e[36]=N):N=e[36];let P;e[37]===v?P=e[38]:(P=v>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,v]}):null,e[37]=v,e[38]=P);let F;e[39]===y?F=e[40]:(F=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,y]}):null,e[39]=y,e[40]=F);let I;e[41]!==P||e[42]!==F?(I=(0,$.jsxs)(`span`,{className:N,children:[P,F]}),e[41]=P,e[42]=F,e[43]=I):I=e[43];let L;e[44]===n?L=e[45]:(L=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:kc}):(0,$.jsx)(X,{name:`arrow-down-s`,className:kc}),e[44]=n,e[45]=L);let R;e[46]!==n||e[47]!==k||e[48]!==M||e[49]!==I||e[50]!==L?(R=(0,$.jsxs)(`button`,{type:`button`,className:T,onClick:E,"aria-expanded":n,children:[O,k,M,I,L]}),e[46]=n,e[47]=k,e[48]=M,e[49]=I,e[50]=L,e[51]=R):R=e[51];let z;e[52]!==a||e[53]!==m||e[54]!==x||e[55]!==n?(z=n&&(0,$.jsx)(`div`,{style:bg,className:Y(yg,`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)(vg,{files:m,currentDirectory:a,onOpenFile:x})}),e[52]=a,e[53]=m,e[54]=x,e[55]=n,e[56]=z):z=e[56];let B;return e[57]!==R||e[58]!==z?(B=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[R,z]}),e[57]=R,e[58]=z,e[59]=B):B=e[59],B});xg.displayName=`PendingChangesBar`;function Sg(e){return!e}var Cg=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=ct(),s=a===`compact`;if(s&&!n)return null;let c=a==="default"&&`absolute left-1/2 bottom-full mb-2 -translate-x-1/2`,l=a===`expanded`&&`absolute left-1/2 -translate-x-1/2 oc-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`oc-scroll-to-bottom--compact relative shrink-0`,d;t[0]!==a||t[1]!==c||t[2]!==l||t[3]!==u||t[4]!==n?(d=Y(c,l,u,n?Y(`pointer-events-auto`,a==="default"&&`opacity-100`):Y(`opacity-0 pointer-events-none`,a===`expanded`&&`oc-scroll-to-bottom--hidden`)),t[0]=a,t[1]=c,t[2]=l,t[3]=u,t[4]=n,t[5]=d):d=t[5];let f=s?`ghost`:`outline`,p=s?`composer-mobile-actions h-8 w-8 rounded-none bg-transparent hover:bg-transparent text-foreground`:`size-8 rounded-full [corner-shape:round] bg-background/95 hover:bg-interactive-hover`,m;t[6]===p?m=t[7]:(m=Y(`p-0 shadow-none`,p),t[6]=p,t[7]=m);let h;t[8]===o?h=t[9]:(h=o(`chat.scrollToBottom.aria`),t[8]=o,t[9]=h);let g=s?`size-5`:`size-4`,_=s?`medium`:`regular`,v;t[10]!==g||t[11]!==_?(v=(0,$.jsx)(X,{name:`arrow-down`,className:g,weight:_}),t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==r||t[14]!==v||t[15]!==f||t[16]!==m||t[17]!==h?(y=(0,$.jsx)(ua,{variant:f,size:`sm`,onClick:r,className:m,"aria-label":h,children:v}),t[13]=r,t[14]=v,t[15]=f,t[16]=m,t[17]=h,t[18]=y):y=t[18];let b;return t[19]!==y||t[20]!==d?(b=(0,$.jsx)(`div`,{className:d,children:y}),t[19]=y,t[20]=d,t[21]=b):b=t[21],b}),wg=Z.createContext(`default`),Tg=()=>Z.useContext(wg),Eg=500,Dg=e=>{let t=(0,Q.c)(31),{onCycleAgent:n,onOpenAgentPanel:r,className:i,agentName:a,agents:o,disabled:s}=e,c;t[0]===o?c=t[1]:(c=o===void 0?[]:o,t[0]=o,t[1]=c);let l=c,u=s!==void 0&&s,d=a??void 0,f;t[2]!==l||t[3]!==d?(f=Un(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=dm(d),h;t[5]===d?h=t[6]:(h=na(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()},Eg))},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`,vm,i),t[16]=i,t[17]=D);let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[18]=O):O=t[18];let k;t[19]!==g.var||t[20]!==p||t[21]!==d||t[22]!==m?(k=(0,$.jsx)(um,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,colorVar:g.var}),t[19]=g.var,t[20]=p,t[21]=d,t[22]=m,t[23]=k):k=t[23];let A;return t[24]!==p||t[25]!==u||t[26]!==b||t[27]!==S||t[28]!==D||t[29]!==k?(A=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:Og,onMouseDown:kg,className:D,style:O,title:p,"aria-label":p,children:k}),t[24]=p,t[25]=u,t[26]=b,t[27]=S,t[28]=D,t[29]=k,t[30]=A):A=t[30],A};function Og(e){return e.preventDefault()}function kg(e){return e.preventDefault()}var Ag=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}=ct(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=Bn(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()?xt(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)(Ma,{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:jg,onPointerDownCapture:Mg,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 jg(e){return e.preventDefault()}function Mg(e){e.preventDefault()}var Ng={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Pg=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function Fg(e,t){let n=(0,Q.c)(6),r=Fi(e??``,t),i=Sr(e??``,t),a=fr(e??``,t),o=yr(e??``,t),s=ai(e??``,t),c=jr(t),l;bb0:{if(!e){l=Ng;break bb0}if(o.length>0||s.length>0){l=Ng;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=Pg({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=Ng;break bb0}if(!y){l=Ng;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var Ig=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function Lg(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(`inline-flex shrink-0 items-center justify-center rounded-full bg-foreground text-background`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,$.jsx)(`span`,{className:a,...i,"aria-hidden":!0,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function Rg(e){let t=(0,Q.c)(7),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]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`span`,{"data-stop-glyph":`true`,className:`block size-[38%] rounded-[20%] bg-current`}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsx)(Lg,{className:n,...r,children:i}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function zg(e){let t=(0,Q.c)(13),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,spinning:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i!==void 0&&i,o=a?`loader-4`:`arrow-up`,s=a?`size-[50%] animate-spin`:`size-[56%]`,c;t[4]===s?c=t[5]:(c=Y(s),t[4]=s,t[5]=c);let l;t[6]!==o||t[7]!==c?(l=(0,$.jsx)(X,{name:o,weight:`medium`,className:c}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u;return t[9]!==n||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(Lg,{className:n,...r,children:l}),t[9]=n,t[10]=r,t[11]=l,t[12]=u):u=t[12],u}var Bg=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Vg=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Hg=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Ug=(e,t)=>e.id===t.id&&e.directory===t.directory,Wg=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Gg=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Hg(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Ug(e.parentTarget,i)&&Wg(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},Kg=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`}},qg=`data-mobile-overlay-active`,Jg=e=>Array.from(e).some(e=>e.getAttribute(qg)!==`false`),Yg=`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(`.`),Xg=`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 Zg(){return`${Yg[Math.floor(Math.random()*Yg.length)]}-${Xg[Math.floor(Math.random()*Xg.length)]}`}function Qg(e){let t=Zg();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var $g=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,e_=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),t_=(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))},n_=async(e,t)=>{await kn(e)&&await rr(t)},r_=e=>{let t=$g(e),n=gr.getState().projects;if(n.length===0)return null;let r=gr.getState().getActiveProject();if(r?.path){let e=$g(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=$g(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>$g(t.path).length-$g(e.path).length)[0];return i?{id:i.id,path:i.path}:null},i_=!1,a_=async(e,t)=>{try{let n=gr.getState().projects.find(e=>e.id===t.id)??gr.getState().projects.find(e=>$g(e.path)===$g(t.path)),r=wr(t.path);await Ai.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Ai.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),t_(e,e_(Ai.getState()),Zi.getState())}catch{}},o_=async(e,t,n)=>{let r=ri.getState(),i=Ai.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await a_(e,n),Se.getState().setDirectory(t.path,{showOverlay:!1})},s_=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,c_=async e=>{if(i_)return null;let t=gr.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return Br.error(`No active project`,{description:`Please select a project first.`}),null;let r=r_(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return Br.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await fa(r.path)}catch{}if(!i)return Br.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;i_=!0;try{let t=wn(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?s_(n):Qg(),a=n?`existing`:`new`,o=ri.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 da(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(ri.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Se.getState().setDirectory(s.path,{showOverlay:!1}));let c=await rn(r),l=await Zo(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Er(t,l.path),ri.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Se.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=ri.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(ht(n,e instanceof Error?e:Error(t)),ri.getState().resolvePendingDraftWorktreeTarget(n,null)),ri.getState().setDraftBootstrapPendingDirectory(null),Br.error(`Failed to create worktree`,{description:t}),null}finally{i_=!1}};async function l_(){return c_()}async function u_(e){let t=e.branch?.trim();return t?c_({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function d_(e,t,n,r){if(i_)return null;i_=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=r_(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await fa(s.path)}catch{}if(!c)return Br.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await rn(s),u=await Fa(s.path);try{let e=await Zo(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 n_(s,e.path);let n=await ri.getState().createSession(void 0,e.path);if(!n)throw await La(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await o_(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 Br.error(`Failed to create worktree`,{description:t}),null}}finally{i_=!1}}var f_=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},p_=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 m_({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=ct(),{github:a}=ko(),o=to(),s=o.data??null,c=o.isFetched,l=q(e=>e.setSettingsDialogOpen),u=q(e=>e.setSettingsPage),d=q(e=>e.isMobile),{isTablet:f}=mo(),p=d||f,m=gr(e=>e.getActiveProject()),h=Se(e=>e.currentDirectory),g=Z.useMemo(()=>m?.path?.trim()||h?.trim()||null,[m?.path,h]),[_,v]=Z.useState(``),[y,b]=Z.useState(!1),[x,S]=Z.useState(null),C=Z.useRef(0),w=Z.useMemo(()=>f_(_),[_]),T=Ho(_,350),E=w?``:T.trim(),D=!!w||_===T,O=e&&D&&!!g&&!!a?.issuesList&&!(c&&s?.connected===!1),k=Je({queryKey:M.scoped(`github-issues`,g,E),enabled:O,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(g,{page:e,...E?{query:E}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),A=D?k.data?.pages.at(-1)??null:null,j=D?k.data?.pages.flatMap(e=>e.issues??[])??[]:[],N=D&&k.hasNextPage,P=!w&&!D||k.isLoading,F=D&&k.isFetchingNextPage,I=D&&k.error?k.error instanceof Error?k.error.message:String(k.error):null,L=Z.useCallback(()=>k.refetch(),[k]),R=Z.useCallback(async()=>{try{await k.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[k,i]);Z.useEffect(()=>{e||(++C.current,v(``),b(!1),S(null))},[e]),Z.useEffect(()=>{++C.current},[e,g]);let z=!c||s?.connected!==!1&&A?.connected!==!1,B=A?.repo?.url??null,V=Z.useCallback(()=>{u(`github`),l(!0)},[l,u]),H=Z.useCallback(()=>{let e=Ai.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},[]),U=Z.useCallback(()=>{let e=Ai.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=It(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),W=Z.useCallback((e,t)=>{let n=Ai.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},[]),ee=Z.useCallback(async(e,o)=>{let s=++C.current,c=()=>C.current===s;if(n===`select`){if(!g){Br.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Br.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(x)return;S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Br.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){Br.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=p_({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);Br.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&S(null)}return}if(!g){Br.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Br.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!x){S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Br.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){Br.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(y){let e=`issue-${r.number}-${Zg()}`,t=await d_(g,e,void 0,{returnAfterDirectoryCreated:!0});if(!t?.id)throw Error(`Failed to create worktree session`);return{sessionId:t.id,sessionDirectory:t.path}}let e=await Yt(u,g,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??g}})();if(!c())return;er(d,u).catch(()=>void 0);try{ri.getState().initializeNewOpenChamberSession(d,Ai.getState().agents)}catch{}t(!1);let f=Ai.getState(),p=Zi.getState().lastUsedProvider,m=U(),h=m?.providerID||f.currentProviderId||p?.providerID,_=m?.modelID||f.currentModelId||p?.modelID,v=H()||f.currentAgentName||void 0;if(!h||!_){Br.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let b=W(h,_),x=await Ci(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await Ci(`github.issue.review.instructions`);if(!c())return;let C=p_({repo:n.repo,issue:r,comments:l});ri.getState().sendMessage(x,h,_,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],b,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),Br.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&S(null)}}},[y,a,n,t,r,g,H,U,W,x,i]),G=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),K=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),te=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:_,onChange:e=>{v(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(d?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[g?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.noActiveProject`)}),a?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.runtimeUnavailable`)}),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,z===!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)(ua,{variant:`outline`,size:`sm`,onClick:V,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,I?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:I}):null,w&&g&&a&&z?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===w&&`bg-interactive-selection/30`),onClick:()=>void ee(w),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:i(`session.githubIssuePicker.actions.useIssue`,{number:w})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===w?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,j.length===0&&!P&&!I&&z&&a&&g?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:T.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,j.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===e.number&&`bg-interactive-selection/30`),onClick:()=>void ee(e.number,e.sourceRepo),children:[(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground w-12 text-right flex-shrink-0`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsx)(`p`,{className:`typography-small text-foreground truncate`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,p?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":i(`session.githubIssuePicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),N&&z&&g&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void R(),disabled:F||!!x,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(F||!!x)&&`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":y,onClick:()=>b(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),b(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),b(e=>!e)},"aria-label":i(`session.githubIssuePicker.actions.toggleWorktreeAria`),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:y?(0,$.jsx)(X,{name:`checkbox`,className:`h-4 w-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i(`session.githubIssuePicker.actions.createInWorktree`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/70 hidden sm:inline`,children:`(issue-<number>-<slug>)`})]}),(0,$.jsx)(`div`,{className:`hidden sm:block sm:flex-1`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B?(0,$.jsx)(ua,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:B,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:L,disabled:P||!!x,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return d?(0,$.jsx)(sm,{open:e,title:G,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:G}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:K})]}),children:te}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),G]}),(0,$.jsx)(aa,{children:K})]}),te]})})}var h_=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},g_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function __({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ct(),{github:i}=ko(),a=to(),o=a.data??null,s=a.isFetched,c=q(e=>e.setSettingsDialogOpen),l=q(e=>e.setSettingsPage),u=q(e=>e.isMobile),{isTablet:d}=mo(),f=u||d,p=gr(e=>e.getActiveProject())?.path??null,[m,h]=Z.useState(``),[g,_]=Z.useState(!1),[v,y]=Z.useState(null),b=Z.useRef(0),x=Z.useMemo(()=>h_(m),[m]),S=Ho(m,350),C=x?``:S.trim(),w=!!x||m===S,T=e&&w&&!!p&&!!i?.prsList&&!(s&&o?.connected===!1),E=Je({queryKey:M.scoped(`github-prs`,p,C),enabled:T,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(p,{page:e,...C?{query:C}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),D=w?E.data?.pages.at(-1)??null:null,O=w?E.data?.pages.flatMap(e=>e.prs??[])??[]:[],k=w&&E.hasNextPage,A=!x&&!w||E.isLoading,j=w&&E.isFetchingNextPage,N=w&&E.error?E.error instanceof Error?E.error.message:String(E.error):null,P=J(async()=>{try{await E.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Br.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++b.current,h(``),_(!1),y(null))},[e]),Z.useEffect(()=>{++b.current},[e,p]);let F=!s||o?.connected!==!1&&D?.connected!==!1,I=J(()=>{l(`github`),c(!0)}),L=J(async(e,a)=>{if(!p){Br.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){Br.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(v)return;let o=++b.current,s=()=>b.current===o;y(e);try{let o=await i.prContext(p,e,{includeDiff:g,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){Br.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){Br.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){Br.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await Ci(`github.pr.review.instructions`);if(!s())return;n({number:o.pr.number,title:o.pr.title,url:o.pr.url,head:o.pr.head,base:o.pr.base,includeDiff:g,instructionsText:e,contextText:g_(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);Br.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&y(null)}}),R=r(`session.githubPrPicker.title`),z=r(`session.githubPrPicker.description`),B=(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)(Va,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:m,onChange:e=>{h(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":g,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Da,{checked:g,onChange:e=>_(e),ariaLabel:r(`session.githubPrPicker.includeDiffAria`)})}),(0,$.jsx)(`span`,{className:`typography-small text-muted-foreground whitespace-nowrap`,children:r(`session.githubPrPicker.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(u?`min-h-0`:`flex-1 overflow-y-auto`),children:[p?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.noActiveProject`)}),i?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.runtimeUnavailable`)}),A?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.pullRequests`)]}):null,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)(ua,{variant:`outline`,size:`sm`,onClick:I,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,N?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:N}):null,x&&p&&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`,v===x&&`bg-interactive-selection/30`),onClick:()=>void L(x),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:r(`session.githubPrPicker.actions.usePullRequest`,{number:x})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===x?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,O.length===0&&!A&&!N&&F&&i&&p?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:S.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,O.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===e.number&&`bg-interactive-selection/30`),onClick:()=>void L(e.number,e.sourceRepo),children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsxs)(`p`,{className:`typography-small text-foreground truncate`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground mr-1`,children:[`#`,e.number]}),e.title]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,(0,$.jsxs)(`p`,{className:`typography-meta text-muted-foreground truncate`,children:[e.head,` → `,e.base]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,f?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":r(`session.githubPrPicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),k&&F&&p&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:j||!!v,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(j||!!v)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:j?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.more`)]}):r(`session.githubPrPicker.actions.loadMore`)})}):null]})]});return u?(0,$.jsx)(sm,{open:e,title:R,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:R}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:z})]}),children:B}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),R]}),(0,$.jsx)(aa,{children:z})]}),B]})})}function v_(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)(Yc,{"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 y_=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)(Yc.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});y_.displayName=`CommandInput`;function b_(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)(pa,{as:Yc.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 x_(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)(Yc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function S_(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)(Yc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function C_(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)(Yc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function w_(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)(Yc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var T_=(e,t)=>`${e}:${S(t)}`,E_=e=>e.type===`skill`||!ne(e.name);function D_(e){let{t}=ct(),n=Z.useMemo(()=>se(),[]),r=q(e=>e.globalDraftStarters),i=gr(e=>e.activeProjectId),a=gr(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[s,c]=Z.useState([]),u=Z.useMemo(()=>r??re,[r]),d=u.some(E_)||s.some(E_),f=Yi({directory:e,enabled:d}),p=Z.useMemo(()=>f.data??[],[f.data]),{refetch:m}=f,h=Ei({directory:e,enabled:d}),g=Z.useMemo(()=>h.data??[],[h.data]),{refetch:_}=h;Z.useEffect(()=>{let e=!1;if(!o){c([]);return}return Jt(o).then(t=>{e||c(t)}).catch(()=>{e||c([])}),()=>{e=!0}},[o?.id]);let v=Z.useCallback(()=>{m(),_()},[m,_]),y=Z.useMemo(()=>new Set(p.map(e=>e.name)),[p]),b=Z.useMemo(()=>new Set(g.map(e=>e.name)),[g]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=ne(e.name);return n?{id:T_(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:y.has(e.name)?{id:T_(r,e),ref:e,group:r,label:x(e.name),icon:K,submitText:`/${e.name}`}:null}return b.has(e.name)?{id:T_(r,e),ref:e,group:r,label:x(e.name),icon:A,submitText:`/${e.name}`}:null},[t,y,b,n]),w=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),T=Z.useMemo(()=>s.map(e=>C(e,`project`)).filter(e=>e!==null),[s,C]),E=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(S(t));for(let t of s)e.add(S(t));return e},[u,s]),D=Z.useMemo(()=>{let e=[];for(let r of O)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 p)t.isBuiltIn||t.source===`skill`||ne(t.name)||e.push({type:`command`,name:t.name,label:x(t.name),icon:K,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of g)e.push({type:`skill`,name:t.name,label:x(t.name),icon:A,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!E.has(`${e.type}:${e.name}`))},[t,p,g,E,n]),k=Z.useCallback(e=>{q.getState().setGlobalDraftStarters(e),U({draftStarters:e})},[]),j=Z.useCallback(e=>{c(e),o&&Ct(o,e)},[o]),M=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||s.some(e=>l(e,t)))return;j([...s,t])}else{let e=r??re;if(e.some(e=>l(e,t)))return;k([...e,t])}},[o,s,r,j,k]),N=Z.useCallback((e,t)=>{e===`project`?j(s.filter(e=>!l(e,t))):k((r??re).filter(e=>!l(e,t)))},[s,r,j,k]),P=Z.useCallback((e,t,n)=>{let i=e===`project`?s:r??re,a=i.findIndex(n=>T_(e,n)===t),o=i.findIndex(t=>T_(e,t)===n);if(a<0||o<0||a===o)return;let c=nc([...i],a,o);e===`project`?j(c):k(c)},[s,r,j,k]);return{global:w,project:T,pinnable:D,hasProject:!!o,ensureLoaded:v,addStarter:M,removeStarter:N,reorder:P}}var O_=`__draft-starter-trash__`,k_=`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`,A_=`max-h-7`,j_=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],M_=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=ct(),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}=rc(s),m;t[2]===d?m=t[3]:(m=ec.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},N_=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(R_),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)(M_,{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)(ac,{items:o,strategy:tc,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},P_=()=>{let e=(0,Q.c)(13),{t}=ct(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:O_},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=Ys(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(k_,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},F_=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=ct(),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)(y_,{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)(x_,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=j_.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(S_,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(w_,{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)(b_,{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)(v_,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},I_=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=ct(),[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)(oa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:k_,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)(ea,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(ia,{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)(F_,{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)(ra,{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)(sa,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},L_=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=ct(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=D_(pc()),{isMobile:f}=mo(),[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=$s(Ks(Zs,b),Ks(Js,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)===O_){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:qs.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&&A_,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)(N_,{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)(N_,{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(z_),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:k_,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)(P_,{}):(0,$.jsx)(I_,{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)(Qs,{sensors:S,collisionDetection:Xs,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 R_(e){return e.id}function z_(e){return!e}var B_=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});B_.displayName=`ChatComposerSurface`;var V_=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Pa,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});V_.displayName=`ChatPromptTextarea`;var H_=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},U_=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},W_=e=>{let t=(0,Q.c)(141),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||Ig(e))&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),!H&&(!U||!G)&&w())},t[49]=G,t[50]=H,t[51]=w,t[52]=U,t[53]=z,t[54]=oe):oe=t[54];let se=oe,ce;t[55]===b?ce=t[56]:(ce=e=>{b?.(e.target.files),e.target.value=``},t[55]=b,t[56]=ce);let le=ce,ue=B.trim().length>0||V.length>0,de=V.filter(G_),fe;t[57]!==n||t[58]!==H||t[59]!==le||t[60]!==b||t[61]!==U?(fe=b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:ne,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:le}),(0,$.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-foreground outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,onClick:()=>ne.current?.click(),disabled:H||U,"aria-label":n,children:(0,$.jsx)(X,{name:`attachment-2`,className:`size-[18px]`})})]}):null,t[57]=n,t[58]=H,t[59]=le,t[60]=b,t[61]=U,t[62]=fe):fe=t[62];let pe=fe,me=!H&&!U&&ue,he;t[63]!==H||t[64]!==ue||t[65]!==W||t[66]!==C||t[67]!==U||t[68]!==O||t[69]!==me||t[70]!==k?(he=U&&C?(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,className:`flex size-8 shrink-0 items-center justify-center rounded-full outline-none hover:opacity-80`,onClick:C,"aria-label":k,children:(0,$.jsx)(Rg,{className:W?`size-6`:`size-full`})}):(0,$.jsx)(`button`,{type:`submit`,"data-composer-send":`true`,"data-composer-circle":me?`true`:void 0,className:Y(`flex size-8 shrink-0 items-center justify-center outline-none`,me?`rounded-full hover:opacity-80`:`rounded-md text-primary hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`),disabled:H||U||!ue,"aria-label":O,children:me?(0,$.jsx)(zg,{className:W?`size-6`:`size-full`}):(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]=W,t[66]=C,t[67]=U,t[68]=O,t[69]=me,t[70]=k,t[71]=he):he=t[71];let ge=he,_e=B_,ve=K&&`flex-1`,ye;t[72]!==o||t[73]!==ve?(ye=Y(`relative flex min-h-0 flex-col`,ve,o),t[72]=o,t[73]=ve,t[74]=ye):ye=t[74];let be=K&&`flex min-h-0 flex-1 flex-col`,xe;t[75]!==_||t[76]!==be?(xe=Y(`overflow-hidden`,be,_),t[75]=_,t[76]=be,t[77]=xe):xe=t[77];let Se=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,Ce=K&&`flex min-h-0 flex-1 flex-col`,we;t[78]===Ce?we=t[79]:(we=Y(`relative overflow-hidden`,Ce),t[78]=Ce,t[79]=we);let Te;t[80]!==u||t[81]!==d||t[82]!==p||t[83]!==R?(Te=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[80]=u,t[81]=d,t[82]=p,t[83]=R,t[84]=Te):Te=t[84];let Ee;t[85]===g?Ee=t[86]:(Ee=e=>{te.current=e,U_(g,e)},t[85]=g,t[86]=Ee);let De;t[87]===x?De=t[88]:(De=e=>x(e.target.value,e),t[87]=x,t[88]=De);let Oe=H||U&&G,ke=W?`send`:z?.enterKeyHint,Ae=K&&`min-h-0 flex-1`,je;t[89]!==h||t[90]!==Ae?(je=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,Ae,h),t[89]=h,t[90]=Ae,t[91]=je):je=t[91];let Me=d&&`text-transparent caret-[var(--surface-foreground)]`,Ne;t[92]!==p||t[93]!==Me||t[94]!==R?(Ne=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,Me),t[92]=p,t[93]=Me,t[94]=R,t[95]=Ne):Ne=t[95];let Pe=z?.rows??1,Fe;t[96]!==se||t[97]!==v||t[98]!==T||t[99]!==Ee||t[100]!==De||t[101]!==Oe||t[102]!==ke||t[103]!==je||t[104]!==Ne||t[105]!==Pe||t[106]!==z||t[107]!==B?(Fe=(0,$.jsx)(V_,{...z,simple:!0,ref:Ee,"data-chat-input":`true`,value:B,onChange:De,onKeyDown:se,disabled:Oe,placeholder:T,enterKeyHint:ke,outerClassName:je,className:Ne,style:v,rows:Pe}),t[96]=se,t[97]=v,t[98]=T,t[99]=Ee,t[100]=De,t[101]=Oe,t[102]=ke,t[103]=je,t[104]=Ne,t[105]=Pe,t[106]=z,t[107]=B,t[108]=Fe):Fe=t[108];let Ie;t[109]!==we||t[110]!==Te||t[111]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:we,"data-composer-input-shell":`true`,children:[Te,Fe]}),t[109]=we,t[110]=Te,t[111]=Fe,t[112]=Ie):Ie=t[112];let Le;t[113]!==r||t[114]!==m||t[115]!==xe||t[116]!==Se||t[117]!==Ie?(Le=(0,$.jsxs)(`div`,{className:xe,children:[m,r,Se,Ie]}),t[113]=r,t[114]=m,t[115]=xe,t[116]=Se,t[117]=Ie,t[118]=Le):Le=t[118];let Re;t[119]!==pe||t[120]!==ge||t[121]!==c||t[122]!==f||t[123]!==y||t[124]!==D?(Re=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??ge})]}),t[119]=pe,t[120]=ge,t[121]=c,t[122]=f,t[123]=y,t[124]=D,t[125]=Re):Re=t[125];let ze;t[126]!==s||t[127]!==l||t[128]!==Re?(ze=(0,$.jsx)(H_,{className:s,style:l,children:Re}),t[126]=s,t[127]=l,t[128]=Re,t[129]=ze):ze=t[129];let q;t[130]!==ye||t[131]!==Le||t[132]!==ze?(q=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ye,children:[Le,ze]}),t[130]=ye,t[131]=Le,t[132]=ze,t[133]=q):q=t[133];let Be;return t[134]!==_e||t[135]!==i||t[136]!==a||t[137]!==K||t[138]!==A||t[139]!==q?(Be=(0,$.jsxs)(_e,{className:a,expanded:K,...A,children:[i,q]}),t[134]=_e,t[135]=i,t[136]=a,t[137]=K,t[138]=A,t[139]=q,t[140]=Be):Be=t[140],Be};function G_(e){return e.mime.startsWith(`image/`)}var K_=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),q_=({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}=ct(),[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(()=>K_(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?bi(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?bi(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?bi(m,e,e=>e.label).map(e=>e.item):m},[D,m]),te=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||bi([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),ne=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},re=e=>{g?.(e),B(!1),O(``)},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)(ua,{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)(fo,{asChild:!0,disabled:s,children:l??me}),ge=(0,$.jsxs)(v_,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(y_,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(b_,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(x_,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(S_,{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)(w_,{onSelect:ie,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(C_,{}),(0,$.jsxs)(S_,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(w_,{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)(w_,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(C_,{}),(0,$.jsxs)(S_,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(w_,{onSelect:()=>ne(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(w_,{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)(C_,{}),(0,$.jsxs)(S_,{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)(w_,{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)(w_,{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)(_a,{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)($a,{open:z,onOpenChange:B,children:[f||l?he:(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:he}),(0,$.jsx)(Ua,{sideOffset:8,children:c?le:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(uo,{align:ue,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ge})]})};function J_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=bi(t,i,e=>e),o=bi(n,i,e=>e),s=new Set(a.map(e=>e.item)),c=new Set(o.map(e=>e.item));return{matching:[...a.map(e=>({label:e.item,value:e.item,source:`local`,score:e.score})),...o.map(e=>({label:e.item,value:`remotes/${e.item}`,source:`remote`,score:e.score}))].sort((e,t)=>e.score===t.score?e.source===t.source?e.label.length===t.label.length?e.label.localeCompare(t.label,void 0,{sensitivity:`accent`}):e.label.length-t.label.length:e.source===`local`?-1:1:e.score-t.score).map(({label:e,value:t,source:n})=>({label:e,value:t,source:n})),otherLocal:t.filter(e=>!s.has(e)),otherRemote:n.filter(e=>!c.has(e))}}function Y_(e,t){return`${e}\0${t}`}function X_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ct(),i=q(e=>e.isMobile),{github:a}=ko(),o=to(),s=o.data??null,c=o.isFetched,l=q(e=>e.setSettingsDialogOpen),u=q(e=>e.setSettingsPage),d=gr(e=>e.getActiveProject()),f=d?.id??null,p=d?.path??null,m=Z.useMemo(()=>p&&f?{id:f,path:p}:null,[f,p]),[h,g]=Z.useState(`issues`),[_,v]=Z.useState(``),[y,b]=Z.useState([]),[x,S]=Z.useState([]),[C,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState(null),[j,M]=Z.useState(null),[N,P]=Z.useState(!1),[F,I]=Z.useState(new Map),[L,R]=Z.useState(1),[z,B]=Z.useState(!1),V=Z.useRef(0),H=Ho(_,350),U=J(async e=>{if(!(!p||!a)&&!(c&&s?.connected===!1)){w(!0),O(null),R(1),B(!1);try{if(h===`issues`&&a.issuesList){let t=await a.issuesList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(t.issues??[]),R(t.page??1),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=await a.prsList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(t.prs??[]),R(t.page??1),B(!!t.hasMore))}}catch(e){O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{w(!1)}}});Z.useEffect(()=>{if(!e||!p||c&&s?.connected===!1||!a)return;if(!H.trim()){U();return}let t=new AbortController;w(!0),O(null),R(1),B(!1);let n=h===`issues`&&a.issuesList?a.issuesList(p,{page:1,query:H.trim()}):h===`prs`&&a.prsList?a.prsList(p,{page:1,query:H.trim()}):null;if(!n){w(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(e.issues??[]),R(e.page??1),B(!!e.hasMore)):`prs`in e&&(e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(e.prs??[]),R(e.page??1),B(!!e.hasMore))))}).catch(e=>{t.signal.aborted||O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||w(!1)}),()=>t.abort()},[e,p,a,c,s,h,H,U,r]);let W=J(async()=>{if(!(!p||!a)&&!(C||T)&&z){E(!0);try{let e=L+1;if(h===`issues`&&a.issuesList){let t=H.trim()?await a.issuesList(p,{page:e,query:H.trim()}):await a.issuesList(p,{page:e});t.connected!==!1&&(b(e=>[...e,...t.issues??[]]),R(t.page??e),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=H.trim()?await a.prsList(p,{page:e,query:H.trim()}):await a.prsList(p,{page:e});t.connected!==!1&&(S(e=>[...e,...t.prs??[]]),R(t.page??e),B(!!t.hasMore))}}catch{}finally{E(!1)}}});Z.useEffect(()=>{if(!e){g(`issues`),v(``),b([]),S([]),A(null),M(null),P(!1),O(null),I(new Map),R(1),B(!1);return}U()},[e,U]),Z.useEffect(()=>{V.current+=1,I(new Map)},[p,m]);let ee=J(async e=>{if(!m||!e)return;let t=Y_(m.path,e);if(F.has(t))return;let n=V.current;try{let i=await Ea(m,{mode:`new`,branchName:e,worktreeName:e});if(n!==V.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);I(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==V.current)return;I(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||h!==`prs`||x.forEach(e=>{e.head&&ee(e.head)})},[e,h,x,p,m,ee]);let G=c&&s?.connected===!0,K=()=>{u(`github`),l(!0)},te=e=>{A(e),M(null)},ne=e=>{M(e),A(null)},re=()=>{k?n({type:`issue`,item:k}):j&&n({type:`pr`,item:j,includeDiff:N}),t(!1)},ie=()=>{A(null),M(null),P(!1)},ae=k||(j?.head&&p?F.get(Y_(p,j.head))?.isValid!==!1:!1),oe=e=>!e.head||(p?F.get(Y_(p,e.head)):void 0)?.isValid===!1,se=(0,$.jsx)($.Fragment,{children:G?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{value:_,onChange:e=>v(e.target.value),placeholder:r(h===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[C&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),D&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:D})]})}),!C&&!D&&h===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[y.length>0?y.map(e=>(0,$.jsx)(`button`,{onClick:()=>te(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,k?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!C&&!D&&h===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[x.length>0?x.map(e=>{let t=oe(e),n=e.head&&p?F.get(Y_(p,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&ne(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,j?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,$.jsx)(X,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:r(`session.githubIntegration.connect.title`)}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:r(`session.githubIntegration.connect.description`)})]}),(0,$.jsx)(ua,{onClick:K,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),ce=(0,$.jsxs)(`div`,{className:Y(`w-full`,i?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-4`,i?`w-full justify-center order-1`:`flex-1`),children:[!i&&(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),h===`prs`&&j&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(Da,{checked:N,onChange:e=>P(e),ariaLabel:r(`session.githubIntegration.includeDiffAria`)}),(0,$.jsx)(`span`,{className:`typography-small text-foreground`,children:r(`session.githubIntegration.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,i?`w-full order-2`:`justify-end`),children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(ua,{size:`sm`,onClick:re,disabled:!ae,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(sm,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:G?ce: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)(Xc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})}),(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,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:se}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(ea,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(ia,{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)(Xc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),se,(0,$.jsx)(ta,{className:`mt-1`,children:ce})]})})})}var Z_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},Q_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),$_=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),ev=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,tv=(e,t,n)=>{let r=Q_(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-${ev(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}`}},nv=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},rv=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function iv({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ct(),{github:a,git:o}=ko(),s=q(e=>e.isMobile),c=Z.useId(),l=to(),u=l.data??null,d=l.isFetched,f=gr(e=>Z_(e.projects,e.activeProjectId,r)),p=f?.path??null,m=Z.useMemo(()=>p&&f?{id:f.id,path:p}:null,[f,p]),[h,g]=Z.useState(`new-branch`),[_,v]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[y,b]=Z.useState({selectedBranch:``,worktreeName:``}),x=os(p),S=rs(p),C=Xo(e=>e.fetchBranches),w=Z.useMemo(()=>x?.all?x.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[x]),T=Z.useMemo(()=>x?.all?x.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[x]),E=ri(e=>e.availableWorktreesByProject),D=Z.useMemo(()=>{if(!p)return new Set;let e=E.get(p)??[];return new Set(e.map(e=>e.name))},[E,p]),O=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=Zg();if(!D.has(e))return e}return`${Zg()}-${Date.now().toString(36).slice(-4)}`},[D]),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(!1),[F,I]=Z.useState(!1),[L,R]=Z.useState(!1),[z,B]=Z.useState(``),[V,H]=Z.useState(``),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),G=Z.useRef(null),K=Z.useCallback(e=>{e.stopPropagation()},[]),te=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},[]),ne=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),re=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;ne(t)},[ne]),ie=Z.useCallback(e=>{let t=te(e.current);ne(t)},[te,ne]),ae=Z.useMemo(()=>J_({localBranches:w,remoteBranches:T,query:z}),[w,T,z]),oe=Z.useMemo(()=>J_({localBranches:w,remoteBranches:T,query:V}),[w,T,V]),se=z.trim().length>0,ce=V.trim().length>0,le=ae.matching.length>0,ue=oe.matching.length>0,de=!!(p&&o),fe=Z.useCallback(()=>{!p||!o||C(p,o)},[p,o,C]);Z.useEffect(()=>{!e||!p||!o||x?.all||C(p,o)},[e,p,o,x?.all,C]),Z.useEffect(()=>{!j&&!F&&B(``)},[j,F]),Z.useEffect(()=>{!N&&!L&&H(``)},[N,L]),Z.useEffect(()=>{j&&re(U),F&&ie(ee)},[j,F,z,re,ie]),Z.useEffect(()=>{N&&re(W),L&&ie(G)},[N,L,V,re,ie]);let[pe,me]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[he,ge]=Z.useState(!1),[_e,ve]=Z.useState(null),ye=Z.useCallback(()=>{let e=Ai.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},[]),be=Z.useCallback(()=>{let e=Ai.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=It(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),xe=Z.useCallback((e,t)=>{let n=Ai.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},[]),Se=Z.useCallback(async e=>{if(!p||!a)return;let t=Ai.getState(),n=Zi.getState().lastUsedProvider,r=be(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=ye()||t.currentAgentName||void 0;if(!o||!s){Br.error(i(`session.newWorktree.error.noModelSelected`));return}let l=xe(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await Ci(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await Ci(`github.issue.review.instructions`),d=nv({repo:t.repo,issue:t.issue,comments:n.comments??[]});await ri.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Br.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(p,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await Ci(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await Ci(`github.pr.review.instructions`),u=rv(t);await ri.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Br.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,p,ye,be,xe,i]),Ce=h===`new-branch`?_:y;Z.useEffect(()=>{if(!e||!x?.all||!p||_.sourceBranch)return;let t=_.sourceBranch,n=!1;return(async()=>{try{let e=await Fa(p).catch(()=>null);if(n)return;let r=localStorage.getItem(Yo),{sourceBranch:i,shouldClearSavedSourceBranch:a}=as({branches:x.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Yo),n||t)return;i&&v(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,x?.all,p,_.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;g(`new-branch`),b({selectedBranch:``,worktreeName:``}),M(!1),P(!1),I(!1),R(!1),B(``),H(``),me({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=O();v({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,O]),Z.useEffect(()=>{if(h!==`new-branch`||!_.isSyncingWorktreeName)return;let e=$_(Q_(_.branchName));v(t=>({...t,worktreeName:e}))},[h,_.branchName,_.isSyncingWorktreeName]);let we=Z.useCallback(async()=>{if(!m||!pe.touched||he)return;_e&&_e.abort();let e=new AbortController;ve(e),me(e=>({...e,isValidating:!0}));try{let t=h===`new-branch`?_.branchName:y.selectedBranch,n=Ce.worktreeName,r=Q_(t),a=$_(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=h===`new-branch`?_.linkedPr:null,n=t?tv(t,w,T):null,i=await Ea(m,{mode:h===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(h===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||me(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||me(e=>({...e,isValidating:!1}))}},[m,h,_.branchName,_.linkedPr,y.selectedBranch,Ce.worktreeName,w,T,pe.touched,_e,he,i]),Te=h===`new-branch`?_.branchName:y.selectedBranch;Z.useEffect(()=>{if(!e||!m||!pe.touched||he)return;let t=setTimeout(()=>{we()},300);return()=>clearTimeout(t)},[Ce.worktreeName,Te,e,m,we,pe.touched,he]);let Ee=async()=>{if(!m||!p){Br.error(i(`session.newWorktree.error.noActiveProject`));return}me(e=>({...e,touched:!0}));let e=h===`new-branch`?_.branchName:y.selectedBranch,r=Ce.worktreeName,a=Q_(e),o=$_(r);if(!a){Br.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){Br.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}_e&&(_e.abort(),ve(null)),me(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),ge(!0);try{let e=h===`new-branch`?_.linkedPr:null,r=h===`new-branch`?_.linkedIssue:null,s=h===`new-branch`?_.linkedPr:null,c=h===`new-branch`&&_.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([rn(m),ns(p)]),f=_.sourceBranch,g=``,v=(()=>{if(e){let t=tv(e,w,T);return g=t.sourceLabel,{preferredName:a||o,mode:`existing`,branchName:a,worktreeName:o,existingBranch:t.existingBranch,setupCommands:u,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return g=h===`new-branch`?f:``,{preferredName:a||o,mode:h===`existing-branch`?`existing`:`new`,branchName:h===`existing-branch`?void 0:a,worktreeName:o,existingBranch:h===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&h===`new-branch`?{startRef:f}:{}}})(),b=await us(p,v,{resolvedRootTrackingRemote:d}),x=await Ia(m,b),S=null;if(l){await kn(m)&&await rr(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Yt(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),ge(!1),er(a.id,e).catch(()=>void 0);try{ri.getState().initializeNewOpenChamberSession(a.id,Ai.getState().agents)}catch{}}else t(!1),ge(!1);let C=cs({mode:h,sourceBranch:_.sourceBranch,linkedPr:!!_.linkedPr,selectedBranch:y.selectedBranch});C&&localStorage.setItem(Yo,C),Br.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${g?` ${i(`session.newWorktree.fromSource`,{source:g})}`:``}`})}),S?Se({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`);Br.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`);Br.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{ge(!1)}},De=e=>{g(e),me(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},Oe=e=>{if(!e){v(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${Zg()}`;v(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:$_(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;v(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:$_(t.head),isSyncingWorktreeName:!0}))}},ke=d&&u?.connected===!0,Ae=(h===`existing-branch`?!!y.selectedBranch&&!!y.worktreeName&&!pe.branchError&&!pe.worktreeError:!!Q_(_.branchName)&&!!_.worktreeName&&!pe.branchError&&!pe.worktreeError)&&!he,je=()=>{v(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Me=(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:pe.touched&&(pe.branchError||pe.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:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s&&`w-full`),children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,className:Y(s&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ua,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:Y(`gap-1.5`,s&&`flex-1`),children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[s?(0,$.jsx)(_a,{id:`new-worktree-sheet-${c}`,open:e,onOpenChange:t,title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(pa,{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)(Xc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>I(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:y.selectedBranch?`text-foreground`:`text-muted-foreground`,children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(sm,{open:F,title:i(`session.newWorktree.selectBranch`),onClose:()=>I(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:ee,children:[(0,$.jsx)(Va,{value:z,onChange:e=>B(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[se&&le&&(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:ae.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:$_(e.label)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.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(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),ae.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(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&ke&&(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Va,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=$_(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===$_(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===$_(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Va,{value:Ce.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>R(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:_.sourceBranch?`text-foreground`:`text-muted-foreground`,children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})}),(0,$.jsx)(sm,{open:L,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>R(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(Va,{value:V,onChange:e=>H(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[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:()=>{v(t=>({...t,sourceBranch:e.value})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),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:()=>{v(t=>({...t,sourceBranch:e})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),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:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Me})]})}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(ea,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(ia,{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)(Xc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)($a,{open:j,onOpenChange:M,children:[(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,y.selectedBranch?`text-foreground`:`text-muted-foreground`),children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(uo,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:U,children:(0,$.jsxs)(v_,{shouldFilter:!1,children:[(0,$.jsx)(y_,{placeholder:i(`session.newWorktree.searchBranches`),value:z,onValueChange:B,onKeyDown:K}),(0,$.jsx)(b_,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(x_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[se&&le&&(0,$.jsx)(S_,{heading:i(`session.newWorktree.matchingBranches`),children:ae.matching.map(e=>(0,$.jsx)(w_,{value:e.value,onSelect:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:$_(e.label)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[se&&(0,$.jsx)(C_,{}),(0,$.jsx)(S_,{heading:i(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:ae.otherLocal.map(e=>(0,$.jsx)(w_,{value:e,onSelect:()=>{b(t=>({...t,selectedBranch:e,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),ae.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(ae.otherLocal.length>0||se)&&(0,$.jsx)(C_,{}),(0,$.jsx)(S_,{heading:i(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:ae.otherRemote.map(e=>(0,$.jsx)(w_,{value:`remotes/${e}`,onSelect:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&ke&&(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Va,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=$_(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===$_(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===$_(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Va,{value:Ce.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)($a,{open:N,onOpenChange:P,children:[(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,_.sourceBranch?`text-foreground`:`text-muted-foreground`),children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(uo,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:W,children:(0,$.jsxs)(v_,{shouldFilter:!1,children:[(0,$.jsx)(y_,{placeholder:i(`session.newWorktree.searchBranches`),value:V,onValueChange:H,onKeyDown:K}),(0,$.jsx)(b_,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(x_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(S_,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(w_,{value:e.value,onSelect:()=>{v(t=>({...t,sourceBranch:e.value})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),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)(C_,{}),(0,$.jsx)(S_,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(w_,{value:e,onSelect:()=>{v(t=>({...t,sourceBranch:e})),P(!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)(C_,{}),(0,$.jsx)(S_,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(w_,{value:`remotes/${e}`,onSelect:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)(ta,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:pe.touched&&(pe.branchError||pe.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:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ua,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:`gap-1.5`,children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(X_,{open:k,onOpenChange:A,onSelect:Oe})]})}function av(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 ov(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 sv=(e,t)=>e??t??null,cv=(e,t)=>!!e&&t!==!1,lv=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:[]},uv=e=>e.replace(/^remotes\//,``).trim(),dv=e=>{let t=uv(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},fv=({directory:e,projectDirectory:t,label:n,projectRootOption:r,worktreeOptions:i,onSelectDirectory:a,className:o,maxWidthClassName:c=`max-w-[48vw] sm:max-w-[20rem]`,presentation:l=`dropdown`})=>{let{t:u}=ct(),{git:d}=ko(),f=sv(t,e),p=e,m=fs(f),h=fs(p),g=cv(f,m),_=p!==f&&cv(p,h),v=Po(f,d,g),y=Po(p,d,_),b=v.data,x=p===f?b:y.data,S=Xo(e=>e.fetchStatus),C=Xo(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=ds(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=gr(e=>e.projects),P=gr(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=s(t);if(e){let t=N.find(t=>s(t.path)===e);if(t)return t.id}return P},[P,t,N]),{localBranches:I,remoteBranches:L}=Z.useMemo(()=>lv(b?.all),[b]),R=x?.current?.trim()||C||null,z=!ov(n,e)&&n||R||n||u(`chat.chatInput.branch`),B=J(async()=>{if(!d)return;let e=new Set;f&&e.add(f),p&&e.add(p),await Promise.all([...e].map(async e=>{await Go(e,d),await S(e,d,{silent:!0})}))}),V=J(e=>{let t=uv(e),n=dv(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),H=J(async e=>{if(!p||!d)return;let t=uv(e);if(R!==t&&R!==dv(t))try{await d.checkoutBranch(p,t),Br.success(u(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:u(`gitView.toast.checkoutFailed`,{name:t});Br.error(n)}}),U=J(e=>{let t=uv(e);if(!t||R===t||R===dv(t))return;let n=V(t);if(n){a(n.value);return}O(t)}),W=J(async()=>{if(!(!D||k)){A(!0);try{await H(D),O(null)}finally{A(!1)}}}),ee=J(async()=>{if(!(!D||k)){A(!0);try{await u_({branch:D,projectDirectory:t??void 0})&&O(null)}finally{A(!1)}}}),G=J(async(e,t)=>{if(!p||!d)return;let n=t?.name??`origin`;try{await d.createBranch(p,e,R??`HEAD`),Br.success(u(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),Br.success(u(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:u(`gitView.toast.branchCreatedLocally`);Br.warning(u(`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:u(`gitView.toast.createBranchFailed`);throw Br.error(t),e}}),K=J(()=>{let e=gr.getState(),n=s(t),r=n?e.projects.find(e=>s(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),te=J((e,n)=>{if(M(!1),n?.sessionId){ri.getState().setCurrentSession(n.sessionId,e);return}let r=gr.getState(),i=s(t),a=(i?r.projects.find(e=>s(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=ri.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),Se.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`,l===`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`,c,gm,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}),l===`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)(q_,{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:l,onOpenChange:T}),j?(0,$.jsx)(iv,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:te}):null,(0,$.jsx)(sa,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ra,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(ea,{children:[(0,$.jsx)(ia,{children:u(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(aa,{children:u(`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`}),u(`chat.chatInput.branchSwitch.checkoutHere`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:u(`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`}),u(`chat.chatInput.branchSwitch.createWorktree`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:u(`chat.chatInput.branchSwitch.createWorktreeDescription`)})]})]}),(0,$.jsx)(ta,{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:u(`chat.chatInput.branchSwitch.cancel`)})})]})})]})},pv=[],mv=[],hv={revertMessageID:void 0,records:mv},gv=e=>e.role===`user`,_v=(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},vv=(e,t,n=hv)=>{if(!t)return hv;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return hv;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!gv(e)||!gn(i,e.id,r)||o.push({message:e,parts:a[e.id]??pv});let s=o.length===0?mv:o;return n.revertMessageID===r&&_v(n.records,s)?n:{revertMessageID:r,records:s}},yv={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},bv={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`},xv=`text-foreground`;function Sv(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 Cv=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function wv(e){let t=Cv.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function Tv(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function Ev(e){let t=[];if(!e)return t;let n=0,r=!1,i=``,a=e.split(`
|
|
6522
|
+
`);for(let e=0;e<a.length;e+=1){let o=a[e],s=n,c=s+o.length;if(n=c+1,r){t.push({start:s,end:c,style:`codeFence`}),Tv(o,i)&&(r=!1);continue}let l=wv(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`}),Sv(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`}),Sv(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;Sv(o.slice(r-s),r,t);continue}Sv(o,s,t)}return t}function Dv(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??yv[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??bv[l.style]:xv,p=e.slice(n,r),m=l?.visual,h=l?.skillName,g=o[o.length-1];g&&g.className===f&&P(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 Ov(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 kv(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 Av(e,t,n){let r=Ov(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 jv(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?G({trigger:`@`,icon:`chat-thread`,label:e.label},L({trigger:`@`,icon:`chat-thread`,label:e.label})):void 0}))}function Mv(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:F,right:F},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:`${k} 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 Nv=`bg-[var(--surface-subtle)]`,Pv=91,Fv=94,Iv={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},Lv={keyword:`${Nv} text-[var(--syntax-keyword)]`,string:`${Nv} text-[var(--syntax-string)]`,number:`${Nv} text-[var(--syntax-number)]`,comment:`${Nv} text-[var(--syntax-comment)]`,function:`${Nv} text-[var(--syntax-function)]`,type:`${Nv} text-[var(--syntax-type)]`,variable:`${Nv} text-[var(--syntax-variable)]`,operator:`${Nv} text-[var(--syntax-operator)]`},Rv=Ye([{tag:[Ze.comment,Ze.lineComment,Ze.blockComment,Ze.docComment,Ze.meta],class:`comment`},{tag:[Ze.keyword,Ze.modifier,Ze.controlKeyword,Ze.operatorKeyword,Ze.definitionKeyword,Ze.moduleKeyword,Ze.self,Ze.null],class:`keyword`},{tag:[Ze.string,Ze.special(Ze.string),Ze.docString,Ze.character,Ze.regexp],class:`string`},{tag:[Ze.number,Ze.integer,Ze.float,Ze.bool,Ze.atom],class:`number`},{tag:[Ze.function(Ze.variableName),Ze.function(Ze.propertyName),Ze.macroName,Ze.standard(Ze.variableName)],class:`function`},{tag:[Ze.typeName,Ze.className,Ze.namespace,Ze.tagName],class:`type`},{tag:[Ze.variableName,Ze.propertyName,Ze.attributeName,Ze.labelName,Ze.definition(Ze.variableName)],class:`variable`},{tag:[Ze.operator,Ze.punctuation,Ze.bracket,Ze.derefOperator,Ze.separator],class:`operator`},{tag:[Ze.heading,Ze.heading1,Ze.heading2,Ze.heading3,Ze.heading4,Ze.heading5,Ze.heading6,Ze.strong],class:`keyword`},{tag:[Ze.emphasis,Ze.quote],class:`type`},{tag:[Ze.link,Ze.url],class:`function`},{tag:[Ze.monospace],class:`string`},{tag:[Ze.strikethrough],class:`comment`}]),zv=e=>{let t=null;for(let n of e.split(` `)){let e=n;Iv[e]!==void 0&&(t===null||Iv[e]>Iv[t])&&(t=e)}return t?Lv[t]:null},Bv=2e4,Vv=e=>{if(!e)return null;try{let t=oo(e);return t instanceof Qe?t:null}catch{return null}};function Hv(e){if(!e||!e.includes("```")&&!e.includes(`~~~`))return[];let t=[],n=e.split(`
|
|
6523
|
+
`),r=0;for(let e=0;e<n.length;e+=1){let i=n[e];r+=i.length+1;let a=wv(i);if(!a)continue;let o=Vv(a.lang),s=r,c=[],l=e+1,u=r;for(;l<n.length;l+=1){let e=n[l];if(Tv(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:`${Nv} text-[var(--syntax-foreground)]`,priority:Pv}),!(d.length>Bv)))try{let e=o.parser.parse(d);Xe(e,Rv,(e,n,r)=>{let i=zv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:Fv})})}catch{}}return t}var Uv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Wv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Gv=e=>{if(!Wv(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(`/`)},Kv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Gv(n):Wv(n))?n:null},qv=(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)qv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))qv(r,t,n+1)}},Jv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Kv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Kv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;qv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Yv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Uv){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 Jv(r,i))t.add(e)}return Array.from(t)},Xv=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}}},Zv=e=>Wv(e);function Qv(e,t){let n=(0,Q.c)(5),r=_t(e,t),i=q($v),a;n[0]===r?a=n[1]:(a=sn(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 $v(e){return e.sessionGoalEnabled}function ey(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 Mt(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 ty={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},ny={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`},ry=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ct(),i=q(e=>e.isMobile),{goal:a,enabled:o}=Qv(e??``,t),s=ey(e??``,a),c=Fi(e??``,t),l=En(e,t),u=Z.useRef(null),[d,f]=Z.useState(!1),[p,m]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=l[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;u.current!==r&&(u.current=r,Ot(e,t))},[e,t,a,l]);let h=J(async n=>{if(!(!e||d)){f(!0);try{await hn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{f(!1)}}});if(!e||!o||!a)return null;let g=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:p)-(a.createdAt||p)),_=vt(g),v=a.tokenBudget?`${Gr(a.tokensUsed)}/${Gr(a.tokenBudget)}`:a.tokensUsed>0?Gr(a.tokensUsed):null,y=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,b=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,x=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,S=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(S,`flex-shrink-0`),style:{color:ty[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,x),children:a.note||s||``}),a.status===`active`&&(!c||c.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,b),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(S,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,b),children:r(ny[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:_}),v?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:v}):null,y?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(y.next),disabled:d,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(y.labelKey),children:[(0,$.jsx)(X,{name:y.icon,className:S,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(y.labelKey)})]}):null]})});ry.displayName=`SessionGoalRow`;var iy=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ct(),{goal:i,enabled:a}=Qv(e??``,t),o=yn(e=>e.armed),s=yn(e=>e.setArmed),[c,l]=Z.useState(!1);if(se()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,d=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Ln(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void d(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});iy.displayName=`SessionGoalButton`;var ay=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ct();if(!yn(oy)||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});ay.displayName=`SessionGoalObjectiveCounter`;function oy(e){return e.armed}var sy=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),cy=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),ly=/^\/\u2003?([^\s]+)/i,uy=/^\/\u2003?goal\b/i,dy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(ly)?.[1]?.toLowerCase();return n&&sy.has(n)?n:null},fy=(e,t)=>dy(e,t)===`goal`?e.trimStart().replace(uy,``).trim():null,py=(e,t)=>dy(e,t)!==null,my=(e,t)=>{let n=dy(e,t);return n!==null&&cy.has(n)},hy=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},gy=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()}},_y=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,vy=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,yy=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},by=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),xy=(e,t)=>{let n=b.getState();return n.bindLegacyQueue(v(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},Sy=async e=>{let t=mn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=by(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}xy(n,a)?r+=1:i+=1}catch{try{xy(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Cy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),wy=e=>e===`allow`||e===`ask`||e===`deny`,Ty=e=>{if(wy(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`&&wy(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(wy(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))wy(i)&&t.push({permission:n,pattern:e,action:i})}return t},Ey=e=>{let t=Ty(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},Dy=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Ey(e.permission));let r=e.find(e=>e?.name===n);return!r||Ey(r.permission)},Oy=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)},ky=null,Ay=new Set,jy=()=>{for(let e of Ay)e()},My=e=>e===`chat`||e===`assistant`,Ny=()=>ky,Py=e=>{ky!==e&&(ky=e,jy())},Fy=e=>{ky&&(e&&ky.surfaceID!==e||(ky=null,jy()))},Iy=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Ly=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}},Ry=(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}),zy=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=Ry(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=Ry(e,`send`,i),o=qm(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=Ry(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Ry(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Ry(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:qm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Bm(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=Ry(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Ry(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},By=(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)))},Vy=(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},Hy=(e,t)=>e.agents.some(e=>e.name===t),Uy=(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},Wy=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Uy(t,n,r,i)?i:void 0;if(a&&Uy(t,n,r,a))return a},Gy=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!Vy(r,n.providerID,n.modelID))return null;let s=n.agent&&Hy(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Hy(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Hy(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=Wy({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:c});return{agent:s,providerID:n.providerID,modelID:n.modelID,variant:l,source:o,messageId:n.id}},Ky=e=>{let{sessionId:t,latestUserChoice:n,latestExecution:r,catalog:i,memory:a,sessionEntity:o,fallbackAgentName:s,transcriptReady:c=!0}=e;if(c&&r){let e=Gy({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=Gy({sessionId:t,choice:n,catalog:i,memory:a,fallbackAgentName:s,source:`history`});if(e)return e}if(c&&a){let e=a.getSessionAgentSelection?.(t)??null,n=e&&Hy(i,e)?e:s&&Hy(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&Vy(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&Uy(i,e.providerId,e.modelId,r)?r:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let r=a.getSessionModelSelection?.(t);if(r&&Vy(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&Uy(i,r.providerId,r.modelId,e)?e:void 0;return{agent:n,providerID:r.providerId,modelID:r.modelId,variant:o,source:`session-memory`}}}let l=o?.model;if(l&&Vy(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&Hy(i,o.agent)?o.agent:void 0)??(e&&Hy(i,e)?e:s&&Hy(i,s)?s:void 0),r=l.variant,c=r&&Uy(i,l.providerID,l.id,r)?r:void 0;return{agent:n,providerID:l.providerID,modelID:l.id,variant:c,source:`session-entity`}}return null},qy=(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))},Jy=(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}},Yy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Xy=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}:{}}},Zy=e=>typeof e==`string`&&e.trim().length>0?e:void 0,Qy=e=>Zy(e.agent)??Zy(e.mode),$y=e=>Zy(e.model?.variant)??Zy(e.variant),eb=e=>{let t=Zy(e.model?.providerID),n=Zy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},tb=e=>{let t=Zy(e.providerID)??Zy(e.model?.providerID),n=Zy(e.modelID)??Zy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},nb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=eb(n);return{id:typeof n.id==`string`?n.id:void 0,agent:Qy(n),providerID:r?.providerID,modelID:r?.modelID,variant:$y(n)}}return null},rb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`user`){if(eb(n))return null;continue}if(n.role!==`assistant`)continue;let r=tb(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:Qy(n),providerID:r.providerID,modelID:r.modelID,variant:$y(n)}}return null},ib=500,ab=e=>Array.from(e).length,ob=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},sb=e=>ab(e)>=ib,cb=e=>{let t=h(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},lb=(e,t)=>{let n=t??e;return typeof n!=`string`||!sb(n)?!1:ae(typeof e==`string`?{text:``,references:[]}:e,n)},ub=(e,t,n,r,i=1)=>{let a=ab(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}-${ob(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},db=e=>({text:e.text,references:e.references.map(e=>({...e}))}),fb=e=>e.map(e=>({...e,range:{...e.range}})),pb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),mb=(e,t,n)=>({document:db(e),mentions:fb(t),selection:{...n}}),hb=()=>({undo:[],redo:[]}),gb=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),_b=(e,t)=>{let n=e.undo.at(-1);return!n||!pb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:mb(n.before.document,n.before.mentions,n.before.selection)}},vb=(e,t)=>{let n=e.redo.at(-1);return!n||!pb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:mb(n.after.document,n.after.mentions,n.after.selection)}},yb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),bb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),xb=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),Sb=e=>JSON.stringify([e.text,e.references]),Cb=(e,t)=>e!==null&&t!==null&&ie(e)===t,wb=(e,t,n)=>{let r=e?xb(e):null,i=r?n(r):void 0;return{document:w(yb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ie(r):null}},Tb=(e,t,n,r)=>{if(!t||ie(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=Sb(yb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===Sb(e)?`same-document-metadata`:`external-document`},Eb=(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}]:[]})},Db=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),Ob=(e,t,n,r,i=r)=>{let a=f(e,n,r,i);return{document:a.document,mentions:Eb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},kb=(e,t,n)=>({preview:{real:bb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Ab=e=>({document:e.real,mentions:e.realMentions}),jb=(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)})},Mb=(e,t)=>{let n=yb(t),r=C(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:jb(e.mentions,t?.mentions??[],r,i)}},Nb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=ei})=>{let a=e?ie(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`),l=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[u,d]=(0,Z.useState)(()=>wb(e,t,i.getState().getDraft).document),[p,m]=(0,Z.useState)(()=>wb(e,t,i.getState().getDraft).mentions),[_,v]=(0,Z.useState)(`compose`),[y,b]=(0,Z.useState)(0),x=(0,Z.useRef)(u),S=(0,Z.useRef)(p),C=(0,Z.useRef)(t),E=(0,Z.useRef)(r),O=(0,Z.useRef)(e),k=(0,Z.useRef)(e?xb(e):null),A=(0,Z.useRef)(a),j=(0,Z.useRef)(a),M=(0,Z.useRef)(0),N=(0,Z.useRef)(o?.revision??0),P=(0,Z.useRef)(void 0),F=(0,Z.useRef)(void 0),I=(0,Z.useRef)(hb());x.current=u,S.current=p,C.current=t,E.current=r,O.current=e,A.current=a;let L=(0,Z.useCallback)((e,t)=>{x.current=e,S.current=t,d(e),m(t)},[]),R=(0,Z.useCallback)((e,t)=>{let n=D(e,t);E.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{M.current+=1;let e=M.current;j.current=a;let t=wb(O.current,C.current,i.getState().getDraft),n=t.key;if(k.current=t.key,P.current=void 0,F.current=void 0,I.current=hb(),v(`compose`),N.current=t.revision,L(t.document,t.mentions),b(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!Cb(k.current,a)||j.current!==a||A.current!==a||M.current!==e||N.current!==r||o?.revision!==t.revision||(N.current=t.revision,L(w(yb(t),C.current),t.mentions))})}},[a,L,i]),(0,Z.useEffect)(()=>{if(!a||j.current!==a||F.current)return;let e=Tb(x.current,o,P.current,{keyID:a,epoch:M.current,appliedRevision:N.current});if(e!==`ignore`){if(o&&(N.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&m(o.mentions);return}e===`external-document`&&o&&(P.current=void 0,L(w(yb(o),C.current),o.mentions),v(`compose`),b(e=>e+1))}},[a,L,o]);let z=(0,Z.useCallback)((e,t)=>{let n=k.current;if(!Cb(n,A.current)||F.current)return;let r=x.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Db(t)});if(!a)return;let o=yb(a);return P.current={keyID:ie(n),revision:a.revision,fingerprint:Sb(o)},N.current=a.revision,L(o,a.mentions),R(r,o),a},[i,L,R]),B=(0,Z.useCallback)((e,t,n,r,i,a)=>{I.current=gb(I.current,{before:mb(e,t,n),after:mb(r,i,a)})},[]),V=(0,Z.useCallback)(()=>F.current?(F.current=void 0,v(`compose`),!0):!1,[]),H=(0,Z.useCallback)(e=>(V(),z({text:e,references:[]},[])),[z,V]),U=(0,Z.useCallback)((e,t=[])=>{V();let n=te(e.text,e.references);return n?z(w(n,C.current),t):void 0},[z,V]),W=(0,Z.useCallback)((e,t,n=t,r)=>{let i=V(),a=bb(x.current),o=i?[]:S.current,s=Ob(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return z(s.document,c),s.removedReferences.length>0&&B(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[z,V,B]),ee=(0,Z.useCallback)((e,t)=>{let n=x.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=V(),o=f(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=Eb(a?[]:S.current,o.document,o.edit);return z(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[z,V]),G=(0,Z.useCallback)((e,t)=>{let n=x.current;return ee({start:0,end:n.text.length,text:e},t)},[ee]),K=(0,Z.useCallback)((e,t,n,r)=>{let i=V(),a=c(x.current,e,t,n,r);return z(a.document,Eb(i?[]:S.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[z,V]),ne=(0,Z.useCallback)(e=>{let t=bb(x.current),n=g(t,e);if(!n)return null;let r=V()?[]:S.current,i=Eb(r,n.document,n.edit),a=T(n.document.text,n.caret),o=f(n.document,a.text,a.caret),s=Eb(i,o.document,o.edit);return z(o.document,s),B(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[z,V,B]),re=(0,Z.useCallback)(e=>{if(F.current)return null;let t=e===`undo`?_b(I.current,x.current):vb(I.current,x.current);return!t||!z(t.snapshot.document,t.snapshot.mentions)?null:(I.current=t.history,t.snapshot.selection)},[z]),ae=(0,Z.useCallback)(e=>z(x.current,e),[z]),oe=(0,Z.useCallback)(e=>{let t=F.current?{document:{text:e.text,references:[]},mentions:[]}:kb(x.current,S.current,e);`preview`in t&&(F.current=t.preview),v(`history-preview`),L(t.document,t.mentions),b(e=>e+1)},[L]),se=(0,Z.useCallback)(()=>{let e=F.current;if(!e)return;F.current=void 0,v(`compose`);let t=Ab(e);L(t.document,t.mentions),b(e=>e+1)},[L]),ce=(0,Z.useCallback)(()=>{let e=k.current;if(!Cb(e,A.current))return null;let t=i.getState().getDraft(e);return{key:xb(e),keyID:ie(e),revision:t?.revision??0,document:bb(x.current),mentions:S.current.map(e=>({...e,range:{...e.range}})),epoch:M.current,runtime:i.getState().captureDraftRuntime()}},[i]),le=(0,Z.useCallback)(e=>{let t=Mb(e,i.getState().getDraft(e.key)),n=yb(i.getState().getDraft(e.key)),r=h(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Db(t.mentions)});if(a){let e=yb(a);R(r,e)}return a},[R,i]),ue=(0,Z.useCallback)(()=>x.current,[]);return(0,Z.useMemo)(()=>({document:u,mentions:p,confirmedFileMentions:p.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:_,hydration:s,persistence:l,textPresetEpoch:y,getDocument:ue,replacePlainDocument:H,replaceMaterializedDocument:U,applyBrowserEdit:W,applyProgrammaticEdit:ee,replaceProgrammaticText:G,insertReference:K,deleteReference:ne,restoreReferenceHistory:re,commitMentions:ae,enterHistoryPreview:oe,exitHistoryPreview:se,captureSubmission:ce,recoverSubmission:le}),[W,ee,ce,ae,ne,u,oe,se,ue,s,_,K,p,l,le,U,H,G,re,y])};function Pb(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 Fb=`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`,Ib=ks(()=>Ue(()=>import(`./ToolOutputDialog-CFFkJzQ4.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),Lb=[],Rb=[],zb=[],Bb=[],Vb=/^@[^\s]+$/,Hb=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Ub=/^(https?:\/\/|mailto:)\S+$/i,Wb=560,Gb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Kb=(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)},qb=e=>e.includes(`@`)?`paste`:`manual`,Jb=(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}},Yb=(e,t)=>ur(e,t).some(e=>e.role===`user`),Xb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Wn(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6525
|
+
`).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},Zb=`file://`,Qb=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(`/`)},$b=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Zb)?t:`file://${Qb(t)}`},ex=e=>{if(!e)return[];let t=[...Yv(e).map(Xv),...Array.from(e.files||[]).map(e=>oe(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(Zv)))},tx=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},nx=e=>ca(e.path),rx=(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)]})},ix=Z.memo(ph),ax=Z.memo(ru),ox=Z.memo(Dg),sx=Z.memo(Ag),cx=Z.memo(Uh),lx=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ct(),r=q(e=>e.isMobile),i=ri(e=>e.revertToMessage),a=ri(e=>e.forkFromMessage),o=ri(e=>e.handleSlashRedo),[s,c]=Z.useState(null),[l,u]=Z.useState(null),[d,f]=Z.useState(!0),p=Z.useRef(hv),m=Ir(),h=t||m,g=Vt(h),_=br(e??``,h,g),v=tn(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=vv({session:v,messages:t,partsByMessageID:_.partsByMessageID},e,p.current);return p.current=n,n},[e,v,_]),b=y.revertMessageID,x=Z.useMemo(()=>y.records.map(e=>e.message),[y]),S=n(`chat.revertPopover.noTextContent`),C=Z.useMemo(()=>b?y.records.map(e=>({id:e.message.id,text:Xb(e.parts,S)})):[],[S,b,y]),w=C[0]?.id;Z.useEffect(()=>{f(!0)},[b,w]);let T=Z.useCallback(async t=>{if(!(!e||s)){c(t);try{let n=x.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{c(null)}}},[o,i,s,e,x]),E=Z.useCallback(async t=>{if(!(!e||l)){u(t);try{await a(e,t)}finally{u(null)}}},[a,l,e]);return!e||C.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>f(e=>!e),"aria-expanded":!d,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,C.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!d&&`rotate-180`),"aria-hidden":`true`})]}),!d&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:C.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)(ua,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{E(e.id)},children:[l===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(ua,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{T(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))})]})})});lx.displayName=`RevertedMessageDock`;var ux=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=ct(),{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?bx:void 0,v=f?xx: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)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:S}),(0,$.jsx)(Ua,{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),dx=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=ct(),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=()=>Oy({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)(Ha,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:Sx,onPointerDownCapture:Cx,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)(Ua,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Wa,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),fx=Z.memo(function(e){let t=(0,Q.c)(67),{isMobile:n,compact:r,footerIconButtonClass:i,stopFooterIconButtonClass:a,compactCircleButtonClass:o,sendIconSizeClass:s,stopIconSizeClass:c,canSend:l,canAbort:u,hasContent:d,currentSessionId:f,newSessionDraftOpen:p,draftSubmitting:m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v,onPrimaryAction:y,onAbort:b}=e,x=r!==void 0&&r,{t:S}=ct(),C,w,T,E,D;if(t[0]!==u||t[1]!==l||t[2]!==x||t[3]!==o||t[4]!==f||t[5]!==m||t[6]!==i||t[7]!==d||t[8]!==n||t[9]!==p||t[10]!==y||t[11]!==v||t[12]!==_||t[13]!==s||t[14]!==g||t[15]!==a||t[16]!==c||t[17]!==h||t[18]!==S){D=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Kg({canSend:l,hasSessionTarget:!!(f||p),draftSubmitting:!!m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:wx,onPointerDownCapture:Tx}:{},t[24]=n,t[25]=r);let b=r,O=g.inFlight,k=O&&g.flightKind===`queue`,A=O&&g.flightKind!==`queue`,j;t[26]!==u||t[27]!==v||t[28]!==_||t[29]!==k||t[30]!==A||t[31]!==S?(j=S(k?`chat.chatInput.actions.queuingMessageAria`:A?`chat.chatInput.actions.sendingMessageAria`:_&&v&&u?`chat.chatInput.actions.sendMessageAria`:u?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[26]=u,t[27]=v,t[28]=_,t[29]=k,t[30]=A,t[31]=S,t[32]=j):j=t[32];let M=j;C=x?o??a??i:a??i,w=c;let N=!u&&(!e.sendDisabled||O),P;t[33]!==n||t[34]!==y?(P=e=>{n&&(e.preventDefault(),y())},t[33]=n,t[34]=y,t[35]=P):P=t[35];let F;t[36]!==u||t[37]!==O||t[38]!==k||t[39]!==A||t[40]!==S?(F=S(A||!u&&O?k?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[36]=u,t[37]=O,t[38]=k,t[39]=A,t[40]=S,t[41]=F):F=t[41];let I;t[42]!==u||t[43]!==w||t[44]!==O||t[45]!==s||t[46]!==N?(I=N?(0,$.jsx)(zg,{className:w,spinning:!!(O&&!u)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[42]=u,t[43]=w,t[44]=O,t[45]=s,t[46]=N,t[47]=I):I=t[47];let L=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":N?`true`:void 0,disabled:e.sendDisabled,"aria-busy":O||void 0,...b,onClick:P,className:Y(N?C:i,N?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":F,children:I});if(!u){D=L;break bb0}let R=!x&&(d||k),z=!e.sendDisabled&&!k,B=x&&`h-full`;t[48]===B?T=t[49]:(T=Y(`relative z-30 overflow-visible`,B),t[48]=B,t[49]=T),E=R?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":z||k?`true`:void 0,disabled:e.sendDisabled||k,"aria-busy":k||void 0,...b,onClick:e=>{e.preventDefault(),!k&&y()},className:Y(z||k?C:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,z||k?void 0:e.disabledClass),"aria-label":M,children:z||k?(0,$.jsx)(zg,{className:w,spinning:k}):(0,$.jsx)(X,{name:`send-plane-2`,className:s})}):null}t[0]=u,t[1]=l,t[2]=x,t[3]=o,t[4]=f,t[5]=m,t[6]=i,t[7]=d,t[8]=n,t[9]=p,t[10]=y,t[11]=v,t[12]=_,t[13]=s,t[14]=g,t[15]=a,t[16]=c,t[17]=h,t[18]=S,t[19]=C,t[20]=w,t[21]=T,t[22]=E,t[23]=D}else C=t[19],w=t[20],T=t[21],E=t[22],D=t[23];if(D!==Symbol.for(`react.early_return_sentinel`))return D;let O;t[50]===C?O=t[51]:(O=Y(C,`relative z-30`),t[50]=C,t[51]=O);let k;t[52]===S?k=t[53]:(k=S(`chat.chatInput.actions.stopGeneratingAria`),t[52]=S,t[53]=k);let A;t[54]===w?A=t[55]:(A=Y(w),t[54]=w,t[55]=A);let j;t[56]===A?j=t[57]:(j=(0,$.jsx)(Rg,{className:A}),t[56]=A,t[57]=j);let M;t[58]!==b||t[59]!==O||t[60]!==k||t[61]!==j?(M=(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,onClick:b,className:O,"aria-label":k,children:j}),t[58]=b,t[59]=O,t[60]=k,t[61]=j,t[62]=M):M=t[62];let N;return t[63]!==T||t[64]!==E||t[65]!==M?(N=(0,$.jsxs)(`div`,{className:T,children:[E,M]}),t[63]=T,t[64]=E,t[65]=M,t[66]=N):N=t[66],N},(e,t)=>e.isMobile===t.isMobile&&e.compact===t.compact&&e.footerIconButtonClass===t.footerIconButtonClass&&e.stopFooterIconButtonClass===t.stopFooterIconButtonClass&&e.compactCircleButtonClass===t.compactCircleButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&e.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),px=(e,t)=>`${e}${e?e.endsWith(`
|
|
6526
6526
|
|
|
6527
6527
|
`)?``:e.endsWith(`
|
|
6528
6528
|
`)?`
|
|
@@ -6531,53 +6531,53 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n
|
|
|
6531
6531
|
`:``}${t.endsWith(`
|
|
6532
6532
|
|
|
6533
6533
|
`)?t:t.endsWith(`
|
|
6534
|
-
`)?`${t}\n`:`${t}\n\n`}`,px=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},mx=(e,t,n,r)=>t?d({transportIdentity:e},t):n?u({transportIdentity:e},n):r,hx=[],gx=({onOpenSettings:e,scrollToBottom:n,showScrollToBottom:o=!1,onScrollToBottom:s,submissionBlocked:c=!1,surface:l})=>{let{t:u}=ct(),d=Cs(),[f,m]=Z.useState({open:!1,title:``,content:``}),[g,x]=Z.useState(`normal`),[S,C]=Z.useState(!1),[w,T]=Z.useState(!1),[D,O]=Z.useState(!1),[k,A]=Z.useState(``),[M,P]=Z.useState(!1),[F,L]=Z.useState(``),[U,W]=Z.useState(!1),[K,te]=Z.useState(``),[ne,re]=Z.useState(!1),[ae,oe]=Z.useState(``),[ce,le]=Z.useState([]),[ue,de]=Z.useState(0),[fe,pe]=Z.useState(null),[me,he]=Z.useState(null),ge=Z.useRef(null),_e=Z.useRef(null),[ve,ye]=Z.useState(!1),be=Z.useRef(null);Z.useEffect(()=>()=>{be.current!==null&&window.clearTimeout(be.current),ge.current!==null&&window.clearTimeout(ge.current),_e.current!==null&&window.clearTimeout(_e.current)},[]);let[we,Oe]=Z.useState(!1),[Ae,je]=Z.useState(!1),[Me,Pe]=Z.useState(null),Fe=Z.useId(),[Le,ze]=Z.useState(``),[Be,Ve]=Z.useState(``),[He,Ue]=Z.useState(!1),[We,Ge]=Z.useState(!1),Ke=Z.useRef(0),qe=Z.useCallback(()=>{Ke.current=Date.now()+500},[]),Je=Z.useRef(0),Ye=Z.useRef(!1),[Xe,Ze]=Z.useState(-1),Qe=Z.useRef(()=>{}),$e=Z.useRef((...e)=>Promise.resolve().then(()=>ri.getState().sendMessage(...e))).current,et=ri(e=>e.currentSessionId),tt=Ai(e=>e.currentProviderId),nt=Ai(e=>e.currentModelId),rt=Ai(e=>e.currentAgentName),it=Ai(e=>e.currentVariant),at=Ai(e=>e.providers),ot=Ai(e=>e.agents),lt=Ai(e=>e.getVisibleAgents),ut=Z.useMemo(()=>km(lt()),[lt,ot]),dt=Ai(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ft=Ai(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),mt=Z.useMemo(()=>{let e=at.find(e=>e.id===tt)?.models?.find(e=>e.id===nt);return Im(e)},[nt,tt,at]),ht=Se(e=>e.currentDirectory),vt=pc()??ht,{ensureSessionRenderable:yt}=ku(),St=ri(Z.useCallback(e=>et?e.getDirectoryForSession(et):null,[et])),Ct=fr(et??``,St??void 0),wt=Z.useMemo(()=>tb(Ct),[Ct]),Et=Z.useMemo(()=>nb(Ct),[Ct]),Dt=Mi(et??``,St??void 0).renderable,Ot=_t(et,St??void 0),kt=Ot?.agent,At=Ot?.model?.id,jt=Ot?.model?.providerID,Mt=Ot?.model?.variant,Nt=Ai(e=>e.activeDirectoryKey),Pt=Z.useRef(0),It=Z.useRef(null),Vt=Z.useRef(null),Ht=ri(e=>e.newSessionDraft),Gt=!!Ht?.open,Kt=ri(e=>e.newSessionDraft.draftSubmitting??!1),Jt=ri(e=>e.newSessionDraft.draftEstablishing??!1),Yt=Kt||Jt,Xt=ri(e=>e.openNewSessionDraft),Qt=ri(e=>e.setDraftPermissionAutoAcceptEnabled),en=Fn(e=>e.autoAccept),tn=Fn(e=>e.saving),nn=Fn(e=>e.setSessionAutoAccept),rn=ri(e=>e.setNewSessionDraftTarget),on=ri(e=>e.availableWorktreesByProject),sn=ri(e=>e.abortPromptSessionId),cn=ri(e=>e.clearAbortPrompt),ln=ei(e=>e.consumePendingInputText),dn=ei(e=>e.pendingPresetSubmit),fn=ei(e=>e.pendingInputText),hn=ei(e=>e.pendingInputMode),gn=ei(e=>e.consumePendingSyntheticParts),_n=ei(e=>e.activeAttachmentDraft),vn=Fu(Z.useCallback(e=>{let t=et??(Gt?`draft`:``);return t?e.drafts[t]??Lb:Lb},[Gt,et])),bn=sr(et??``),Cn=Z.useSyncExternalStore(t,r,r),wn=_n?.transportIdentity??null,Tn=_n?.owner.kind??null,En=_n?.owner.ownerID??null,Dn=Z.useMemo(()=>mx(Cn,et,Ht.draftID,wn&&Tn&&En?{transportIdentity:wn,owner:{kind:Tn,ownerID:En}}:null),[En,Tn,wn,Cn,et,Ht.draftID]),On=Dn?ie(Dn):null,kn=ei(Z.useCallback(e=>On?e.draftAttachmentViews[On]:void 0,[On])),An=ei(Z.useCallback(e=>On?e.drafts[On]:void 0,[On])),jn=Z.useMemo(()=>{if(!An||!kn)return hx;let e=An.attachments.flatMap(e=>{let t=kn[e.attachmentRefID];return t?[t]:[]});return e.length===0?hx:e},[kn,An]);Z.useEffect(()=>{Dn&&ei.getState().hydrateDraftAttachments(Dn)},[Dn]);let Mn=Vm(),Nn=q(e=>e.activeMainTab===`chat`),Pn=Fi(et??``,vt??void 0),In=Hm({kind:`primary`,surfaceID:`primary`,active:Nn,sessionID:et,directory:vt??null,activity:{phase:Pn?.type===`busy`?`busy`:Pn?.type===`retry`?`retry`:`idle`,canAbort:Pn?.type===`busy`||Pn?.type===`retry`},draftKey:Dn,transportIdentity:Cn,runtimeGeneration:i(),selection:{value:{providerID:tt,modelID:nt,agent:rt,variant:it},catalog:{providers:at,agents:ut,variants:mt,variantsReady:!dt,ready:!dt&&!ft,loading:dt||ft},flush:async()=>{let e=ri.getState().currentSessionId;if(!e)return;let t=i(),n=r(),a=Pt.current,o=e,s=ri.getState().getDirectoryForSession(o)??null,c=wr(s);if(Ai.getState().activeDirectoryKey!==c&&await Ai.getState().activateDirectory(s),i()!==t||r()!==n||ri.getState().currentSessionId!==o||Ai.getState().activeDirectoryKey!==c||Pt.current!==a)return;await yt(o,{directory:s??void 0});let l=ri.getState().getDirectoryForSession(o)??null,u=wr(l);if(i()!==t||r()!==n||ri.getState().currentSessionId!==o||l!==s||u!==c||Ai.getState().activeDirectoryKey!==c||Pt.current!==a)return;let d=Ai.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=ur(o,l??void 0),m=tb(p),h=nb(p);if(Jy({editRevision:a,pinnedHistoryMessageId:It.current,latestHistoryMessageId:m?.id??null}))return;let g=Zi.getState(),_=fi().get(o),v=Gy({sessionId:o,latestUserChoice:m,latestExecution:h,catalog:f,memory:g,sessionEntity:_?.model?{agent:_.agent,model:{id:_.model.id,providerID:_.model.providerID,variant:_.model.variant}}:_?.agent?{agent:_.agent}:null,fallbackAgentName:d.currentAgentName});if(!v)return;let y=[o,v.source,v.messageId??``,v.agent??``,v.providerID,v.modelID,v.variant??``,c].join(`|`);Vt.current!==y&&(Ky(v,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:o,memory:g}),Vt.current=y)},change:async e=>{Pt.current+=1;let t=ri.getState().currentSessionId;if(t){let e=ri.getState().getDirectoryForSession(t)??void 0,n=tb(ur(t,e));It.current=n?.id??null}else It.current=null;let n=Ai.getState();zy(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:Zi.getState()})}},resources:{attachments:jn,addAttachment:async e=>{Dn&&await xn(Dn,()=>ei.getState()).addLocal(e)},removeAttachment:async e=>Dn?xn(Dn,()=>ei.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>Dn?xn(Dn,()=>ei.getState()).clearRootAttachments():!1,restoreAttachments:async e=>Dn?xn(Dn,()=>ei.getState()).restoreRootAttachments(e):!1,pendingInput:fn===null?null:{text:fn,mode:hn},consumePendingInput:ln,pendingPreset:dn,consumePendingPreset:()=>ei.getState().consumePendingPresetSubmit(),consumeSyntheticParts:gn,restoreSyntheticParts:e=>ei.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:vn,removeInlineDraft:e=>{let t=et??(Gt?`draft`:``);t&&Fu.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=et??(Gt?`draft`:``);!t||e.length===0||Fu.setState(n=>{let r=n.drafts[t]??[],i=new Set(e.map(e=>e.id));return{drafts:{...n.drafts,[t]:[...e,...r.filter(e=>!i.has(e.id))]}}})},history:bn,captureRuntime:()=>ei.getState().captureDraftRuntime(),getDraft:e=>ei.getState().getDraft(e),abortPrompt:{sessionID:sn,clear:cn}},backend:{send:e=>{Fy(e,{transportIdentity:r(),runtimeGeneration:i()});let t=Iy(e);return $e(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Xi(e.sessionID??``,{delivery:e.options?.delivery===`steer`?`steer`:void 0,queueItemID:e.queueItemID,manual:e.manual,scope:e.queueScope?{state:`bound`,...e.queueScope}:void 0}),create:async()=>Xt(),compact:async e=>De.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Ft(e.sessionID),Jr(e.sessionID??``))},shortcuts:{cycle:e=>Qe.current(e),new:()=>Xt(),abort:()=>(et&&Ft(et),Jr(et??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),Ln=Um(In,l??Mn);Wm(Ln),Z.useLayoutEffect(()=>{if(!Ln.active){Py(Ln.surfaceID);return}return Ny(Ln),()=>Py(Ln.surfaceID)},[Ln]);let Rn=Ry(Ln),zn=Ln.resources??(Ln.kind===`primary`?In.resources:void 0);if(!zn)throw Error(`chat-input-surface-resources-incomplete`);let Vn=[...zn.attachments],Hn=Ln.sessionID,Wn=Gm(Ln,Yt),Gn=Ln.kind===`secondary`?Ln.commands.hasNewDraft:Gt,qn=Gn,Yn=Ln.directory??vt,Xn=Ln.draftKey??Dn,Qn=Z.useMemo(()=>{if(Ln.kind===`secondary`)return qm(Ln,!1,!1);let e=Hn?Jb(Hn,St??void 0):!1;return qm(Ln,e,Gn)},[Ln,Hn,St,Gn]),er=(e,t,n,r,i,a,o,s,c,l)=>Rn?Rn.send({providerID:t,modelID:n,agent:r,variant:s,text:e,attachments:i,agentMention:a,parts:o,systemContext:o?.filter(e=>e.synthetic).map(e=>({text:e.text,synthetic:!0})),inputMode:c,options:l}):Promise.reject(Error(`chat-input-surface-incomplete`)),nr=Z.useCallback(()=>Rn?Rn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[Rn]),rr=gr(e=>e.projects),ir=gr(e=>e.activeProjectId),ar=gr(e=>e.setActiveProjectIdOnly),[or,cr]=Z.useState(!1),[dr,mr]=Z.useState(!1),hr=Z.useMemo(()=>Hn?Tt({autoAccept:en,sessions:[],sessionById:fi(),sessionID:Hn}):Ht.permissionAutoAcceptEnabled===!0,[Hn,Ht.permissionAutoAcceptEnabled,en]),_r=Ai(e=>e.agents),vr=Ln.kind===`secondary`?Ln.selection.value.agent:rt,yr=Ln.kind===`secondary`?km(Ln.selection.catalog?.agents):_r,br=se()||Ey(yr,vr),xr=Z.useCallback(()=>{Br.error(u(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[u]),Sr=Ln.selection.value,Er=Ln.selection.change,Or=Ln.selection.catalog,kr=Z.useMemo(()=>({selection:{providerID:Sr.providerID??``,modelID:Sr.modelID??``,agent:Sr.agent??null,variant:Sr.variant},onChange:async e=>{if(!Er)throw Error(`chat-input-surface-selection-readonly`);await Er({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!Ln.active,catalog:Or}),[Or,Er,Sr.agent,Sr.modelID,Sr.providerID,Sr.variant,Ln.active]);Z.useEffect(()=>{Pt.current=0,It.current=null,Vt.current=null},[et]),Z.useEffect(()=>{if(Ln.kind!==`primary`||!et||dt||ft||at.length===0||ut.length===0)return;let e=wr(St);if(Nt!==e)return;let t=Zi.getState(),n={providers:at,agents:ut};if(Jy({editRevision:Pt.current,pinnedHistoryMessageId:It.current,latestHistoryMessageId:wt?.id??null}))return;let r=Gy({sessionId:et,latestUserChoice:wt,latestExecution:Et,catalog:n,memory:t,sessionEntity:jt&&At?{agent:kt,model:{id:At,providerID:jt,variant:Mt}}:kt?{agent:kt}:null,fallbackAgentName:rt,transcriptReady:Dt});if(!r)return;let i=[et,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,Nt].join(`|`);if(Vt.current===i)return;if((r.agent===void 0||r.agent===rt)&&r.providerID===tt&&r.modelID===nt&&r.variant===it){Vt.current=i;return}if(Ai.getState().activeDirectoryKey!==e)return;let a=Ai.getState();Ky(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:et,memory:t}),Vt.current=i},[Ln.kind,et,wt,Et,Dt,at,ut,dt,ft,Nt,St,rt,tt,nt,it,kt,At,jt,Mt]);let Ar=Ai(e=>e.getVisibleAgents),jr=Ln.kind===`primary`?Ar():Rb,Mr=Ai(e=>Ln.kind===`primary`?e.providers:zb),Pr=Ln.kind===`secondary`?km(Ln.selection.catalog?.agents):jr,Fr=Ln.kind===`secondary`?Ln.selection.catalog?.providers??zb:Mr,Ir=Ln.kind===`secondary`&&(!Ln.selection.catalog?.ready||!!Ln.selection.catalog.error),Rr=!Ln.active||!Ln.selection.change||Ir,zr=q(e=>e.isMobile),Ur=q(e=>e.setImagePreviewOpen),Gr=Z.useCallback(e=>{e.image&&(m(e),Ur(!0))},[Ur]),qr=Z.useCallback(e=>{m(t=>({...t,open:e})),Ur(e)},[Ur]),Xr=uu(e=>e.pending),Zr=q(e=>e.inputBarOffset),Qr=q(e=>e.persistChatDraft),$r=q(e=>e.inputSpellcheckEnabled),ai=q(e=>e.isExpandedInput),oi=q(e=>e.setExpandedInput),si=q(e=>e.setTimelineDialogOpen),ci=Mb({draftKey:Xn,sessionTitles:new Map(Array.from(fi(),([e,t])=>[e,t.title||e])),persistenceEnabled:Qr}),li=ci.document,di=li.text,{replacePlainDocument:pi,replaceProgrammaticText:mi,applyBrowserEdit:gi,insertReference:_i,deleteReference:vi,enterHistoryPreview:yi,exitHistoryPreview:bi,captureSubmission:Si,recoverSubmission:wi,confirmedFileMentions:Ti,mentions:Oi}=ci,ki=Z.useCallback((e,t)=>mi(e,t),[mi]),ji=Z.useMemo(()=>new Set(Ti.map(e=>e.value)),[Ti]),Pi=Z.useRef(null),Ii=Z.useRef(!1),Li=Z.useRef(0),Ri=Z.useRef(null),Bi=Z.useRef(di.length),Vi=Z.useRef(null),Hi=Z.useRef(0),Ui=Z.useRef(!1),Wi=Z.useRef(null),Gi=Z.useRef(!1),Ki=Z.useRef(null),qi=Z.useRef([]),Ji=Z.useRef(!1),Qi=Z.useRef(null),$i=Z.useRef(!1),ea=Z.useRef(null),ta=Z.useRef(null),na=Z.useRef(null),ra=Z.useRef(di),ia=Z.useRef(new Set),aa=ci.getDocument,oa=Z.useCallback((e,t,n=[])=>ki(e,(e,r)=>{let i=[],a=new Set(n);for(let e of t){let t=0,n=`@${e}`;for(;t<r.text.length;){let o=r.text.indexOf(n,t);if(o<0)break;i.push({kind:a.has(e)?`directory`:`file`,value:e,path:e,label:e,range:{start:o,end:o+n.length}}),t=o+n.length}}let o=new Set(e.map(e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`));return[...e,...i.filter(e=>!o.has(`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`))]}),[ki]),sa=Rh(Lh()),{git:la,vscode:da}=ko(),fa=q(e=>e.shortcutOverrides.cycle_agent),ma=q(e=>e.shortcutOverrides),ha=Z.useMemo(()=>Qa(`cycle_agent`,fa?{cycle_agent:fa}:void 0),[fa]),ga=Z.useMemo(()=>Qa(`clear_all_messages`,ma),[ma]),{currentTheme:va}=Ga(),xa=Vo(),Ca=fs(Yn),Ea=Xo(e=>Yn?e.directories.get(Yn)?.status??null:null),Da=Xo(e=>e.ensureStatus),ja=Xo(e=>e.fetchStatus),[Ma,Pa]=Z.useState(!1),Fa=Z.useRef(null),[Ia,La]=Z.useState(!1);Z.useEffect(()=>{!Yn||!la||Da(Yn,la)},[Yn,la,Da]),Z.useEffect(()=>{if(!(!Yn||!la))return gt.onGitRefreshHint(e=>{ex(e.directory)===ex(Yn)&&ja(Yn,la)})},[Yn,la,ja]);let Ha=Z.useCallback(async e=>{if(!Hn)return;let t=ri.getState().getDirectoryForSession(Hn)||Yn||``;if(!t){Br.error(u(`diffView.reviewDialog.toast.noSessionDirectory`));return}mr(!0);try{await ti({originalSessionID:Hn,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),cr(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),Br.error(e instanceof Error?e.message:u(`diffView.reviewDialog.toast.startFailed`))}finally{mr(!1)}},[Hn,Yn,u]),Ua=ai&&!zr,Wa=ai&&zr,Ka=Ua||Wa,Ya=`1.5rem`,Xa=u(Hn||Gn?g===`shell`?`chat.chatInput.placeholder.shell`:zr||Ia?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Za=u(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=Vi.current;if(!e)return;let t=e=>{let t=e>0&&e<Ub;La(e=>e===t?e:t)};if(t(e.clientWidth),typeof ResizeObserver>`u`){let n=()=>t(e.clientWidth);return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)}let n=new ResizeObserver(n=>{t(n[0]?.contentRect.width??e.clientWidth)});return n.observe(e),()=>n.disconnect()},[]);let $a=Vn,eo=Z.useMemo(()=>new Set(Pr.map(e=>e.name.toLowerCase())),[Pr]),to=Z.useRef(eo);to.current=eo;let no=Vb({inputMode:g,message:di,showCommandAutocomplete:M,showSkillAutocomplete:U}),ro=Yi({directory:Yn,enabled:no}),io=Z.useMemo(()=>ro.data??[],[ro.data]),ao=Ei({directory:Yn,enabled:no}),oo=Z.useMemo(()=>ao.data??[],[ao.data]),so=Z.useMemo(()=>new Map(oo.map(e=>[e.name.toLowerCase(),e.name])),[oo]),co=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!zr&&!se()&&e.add(`handoff-review`);for(let t of io)e.add(t.name.toLowerCase());for(let t of oo)e.add(t.name.toLowerCase());return e},[io,oo,zr]),lo=Z.useMemo(()=>{if(!di||!di.includes(`/`)||g===`shell`||co.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${B})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(di))!==null;){let t=n[2]??``,r=n[3];if(!co.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=so.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:G({trigger:`/`,icon:`book-open`,label:o},di.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:G({trigger:`/`,icon:`command`,label:r},di.slice(i,i+a))})}return e},[so,g,co,di]),uo=Sa(e=>e.snippets),fo=Z.useMemo(()=>{let e=new Set;for(let t of uo){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[uo]),po=Z.useMemo(()=>{if(!di||!di.includes(`#`)||g===`shell`||fo.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(di))!==null;){let t=n[2];if(!fo.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[g,fo,di]),mo=Z.useMemo(()=>!di||!di.includes(`@`)||g===`shell`?[]:Wr(di,{confirmedValues:ji,agentNames:eo}),[ji,g,eo,di]),ho=Z.useMemo(()=>{if(!di||!di.includes(`[`)||g===`shell`||$a.length===0)return[];let e=$a.filter(Ne),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return Te(di,e.map(e=>e.filename)).flatMap(e=>{let n=V(di.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:G({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},di.slice(e.start,e.end))}]})},[g,di,$a]),go=d&&Gs(zr)&&Ln.kind===`primary`,_o=Z.useMemo(()=>{if(!di||g===`shell`)return null;let e=[...go?[]:Tv(di),...go?[]:Vv(di),...Av(mo),...lo,...po,...ho,...li.references.map(e=>({start:e.start,end:e.end,priority:103,...E(e)}))];return Ev(di,e)},[ho,lo,po,mo,li.references,g,di,go]),vo=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?Qb(e.serverPath):e.dataUrl})),[]),[yo,bo]=Z.useState(null),xo=Z.useRef(null),[So,Co]=Z.useState(!1),[wo,To]=Z.useState(!1),[Eo,Do]=Z.useState(null),[Oo,Ao]=Z.useState(null),jo=b(e=>e.followUpBehavior),Mo=Z.useMemo(()=>{let e=Rn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[Rn]),Po=Ju({transportIdentity:Mo?.transportIdentity??``,directory:Mo?.directory??``,sessionID:Mo?.sessionID??``}),Ro=Z.useMemo(()=>Hn?v(Hn):null,[Hn]),zo=b(Z.useCallback(e=>Mo?_(e,Mo):Ib,[Mo])),Bo=b(Z.useCallback(e=>Ro?_(e,Ro):Ib,[Ro])),Ho=Z.useMemo(()=>Bo.length===0?zo:zo.length===0?Bo:[...Bo,...zo],[zo,Bo]),Go=Po.mode===`server`?Ib:Ho,qo=b(Z.useCallback(e=>Mo?I(e,Mo):Ib,[Mo])),Yo=b(e=>e.clearQueue),Zo=b(e=>e.removeFromQueue),es=zn.inlineDrafts,ns=es.length>0,[rs,as,cs]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of es)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[es]),us=Z.useCallback(e=>{for(let t of zn.inlineDrafts)t.source===e&&zn.removeInlineDraft(t.id)},[zn]),ds=Z.useCallback(()=>{for(let e of zn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&zn.removeInlineDraft(e.id)},[zn]),ms=zn.history;Z.useEffect(()=>{ra.current=di},[di]),Z.useLayoutEffect(()=>{x(`normal`),Ze(-1)},[Xn?.transportIdentity,Xn?.owner.kind,Xn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Gn||zr)return;let e=()=>{let e=Pi.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Gn,zr]);let hs=Pg(Ln.kind===`primary`?Hn:null,Ln.kind===`primary`?Yn??void 0:void 0),gs=Ln.activity?.phase??hs.phase,_s=Wt(Z.useCallback(e=>{if(!Hn)return!1;let t=e.runsByOriginalSessionID[Hn];return t?.status===`running`&&t.runtimeKey===a()},[Hn])),vs=J(e=>{zr&&(qe(),he(e),Pi.current?.blur(),Ai.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),ys=zn.pendingInput,bs=zn.consumePendingInput;Z.useEffect(()=>{if(ys===null)return;let e=bs();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=fx(ra.current,e.text);ra.current=t,ki(t)}else if(e.mode===`append-inline`){let t=px(ra.current,e.text);ra.current=t,ki(t)}else pi(e.text);setTimeout(()=>{Pi.current?.focus()},0)}},[ys,bs,pi,ki]);let xs=di.trim().length>0||$a.length>0||ns,Ss=Po.mode===`server`?Po.items.length>0:Go.length>0||qo.length>0,Ts=!Uf(Po.mode),Es=xs||Ss,Ds=ri(e=>e.stagedMessageEdit?.sessionId===Hn?e.stagedMessageEdit.messageId:null),Os=gs===`busy`||gs===`retry`,ks=Ln.activity?.canAbort??Os,As=Z.useCallback(()=>{let e=Pi.current,t=e?.value??aa().text;t!==aa().text&&gi(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=aa();return{message:n.text,document:n,hasContent:n.text.trim().length>0||$a.length>0||ns}},[gi,aa,ns,$a.length]),js=Z.useRef(async()=>{}),Ms=Ln.surfaceID,Ns=Ht?.draftID??null,Fs=mn(Z.useMemo(()=>bt(Ms),[Ms])),Is=mn(Z.useMemo(()=>un(Ns),[Ns])),Rs=Z.useMemo(()=>ni(Fs,Is),[Fs,Is]),zs=(e=`send`)=>mn.getState().beginFlight(Ms,e),Bs=()=>{mn.getState().endFlight(Ms)},Vs=()=>mn.getState().isInFlight(Ms),Hs=Z.useRef(null);Z.useEffect(()=>{if(Ln.kind!==`primary`||!Ds){Hs.current=null;return}if(Hs.current!==Ds){if(Hs.current=Ds,go){Ws().focus();return}Pm(Pi)||requestAnimationFrame(()=>Pm(Pi))}},[go,Ds,Ln.kind]);let Us=mn(Z.useMemo(()=>Yr(Ns),[Ns])),Ks=J(async()=>{let e=ri.getState().newSessionDraft.draftID;if(!e||!mn.getState().isEstablishing(e))return!1;let t=As();if(!t.hasContent)return!1;let n=H(t.document,`queue-canonical`);if(!n.ok)return Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1;if(await Ln.selection.flush(),!mn.getState().isEstablishing(e))return!1;let r=qy(Ai.getState());if(!r?.providerID||!r?.modelID)return Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1;let i=vo($a);return mn.getState().enqueueEstablishingFollowUp({draftID:e,content:n.text,sendConfig:{providerID:r.providerID,modelID:r.modelID,...r.agent?{agent:r.agent}:{},...r.variant?{variant:r.variant}:{}},attachments:i,composerDocument:t.document})?(pi(``),Ze(-1),oi(!1),i.length>0&&zn.clearAttachments(),!0):!1}),qs=()=>{if(Hn)return!1;let e=ri.getState().newSessionDraft.draftID;return mn.getState().isEstablishing(e)?(Ks(),!0):!1},Js=J(async()=>{if(!Ln.active||Vs())return;if(Hn){let e=ri.getState().stagedMessageEdit;if(e&&e.sessionId===Hn){ri.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await Rt(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{ri.getState().endMessageEditCommit(e.sessionId,e.messageId)}ri.getState().stagedMessageEdit===e&&ri.getState().clearStagedMessageEdit(e.sessionId)}}let e=As(),t=H(e.document);if(!t.ok){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let n={chunks:t.chunks??[],semantics:t.semantics??[]},a=t.text,o=a.trimStart(),s=n.chunks.every(e=>e.provenance===`authored`)&&g===`normal`&&o.startsWith(`/`)?Jo(o.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(s&&!Uo(s,e=>zm(Ln,{name:e.name,source:`openchamber`}))||c||!e.hasContent||!Hn)return;if(Ts||!zt(Ln.deliveryTarget?.kind,Po.mode)){js.current(Os?{delivery:`steer`}:void 0);return}if(n.chunks.every(e=>e.provenance===`authored`)&&fy(a,g)){js.current();return}if(!zs(`queue`))return;let l=Ln.transportIdentity,d=Ln.runtimeGeneration,f=zn.captureRuntime(),p=Mo,m=Ln.kind===`primary`?Mo?.sessionID??Hn:null,_=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),x=_.length>0?h(Ru(e.document.text,_),e.document.references).document:e.document,S=H(x,`queue-canonical`);if(!S.ok){Bs(),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let C=vo($a),w=Si(),T=C,E=$n(),D=!1,O=null,k=()=>{D&&p&&(Po.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(b.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&wi(w),T.length>0&&await zn.restoreAttachments(T),e&&zn.restoreSyntheticParts(e),_.length>0&&zn.restoreInlineDrafts(_)};try{if(!p){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}if(Po.mode===`server`){if(!Xn){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}xi({stage:()=>{Po.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:S.text,createdAt:E.createdAt,attachmentCount:C.length,composerDocument:x,composerMentions:Oi}}),D=!0},clearComposer:()=>{pi(``),Ze(-1),oi(!1)}})}else xi({stage:()=>{b.getState().bindLegacyQueue(v(p.sessionID),p),b.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:S.text,createdAt:E.createdAt,attachmentCount:C.length,composerDocument:x,composerMentions:Oi}),O=E.requestID},clearComposer:()=>{pi(``),Ze(-1),oi(!1)}});if(await Ln.selection.flush(),!Sn({transportIdentity:l,generation:d},{transportIdentity:r(),generation:i()})){await A();return}if(!Sn(f,zn.captureRuntime())){await A();return}if(m&&ri.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==r()||p.runtimeGeneration!==i()||p.sessionID!==(m??p.sessionID)||m&&y(ri.getState().getDirectoryForSession(m))!==y(p.directory)){await A();return}let t=p,n=Ln.kind===`primary`?(()=>{let e=Ai.getState(),t=m?ri.getState().getDirectoryForSession(m)??null:null;return qy(e,{expectedConfigKey:wr(t),activeDirectoryKey:e.activeDirectoryKey})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(!tr(n)){await A();return}if(Po.mode===`server`){if(!Xn){await A(),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let r=Zt({draftKey:Xn,runtime:f,document:e.document,attachments:$a,inlineDrafts:_}),i=t.deliveryTarget.kind===`assistant`?zn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??N()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=hi({plan:{chunks:S.chunks??[],semantics:S.semantics??[]},agents:Pr,installedSkillNames:new Set(Tr(ee,Yn).map(e=>e.name)),directory:Yn,root:xa||Yn,confirmedFilePaths:Ti.map(e=>e.path),confirmedDirectoryPaths:Ti.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:$a});return o=e.attachments,pt({text:_.length>0?Ru(e.text,_):e.text,attachments:[...C,...e.attachments],semanticParts:ui(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...$t(C),...$t(o),...(i??[]).flatMap(e=>$t(e.attachments??[],e.partID))],t=s?new Set(s.flatMap(e=>e.type===`file`?[e.attachmentID]:[])):null;a=e.filter((n,r)=>e.findIndex(e=>e.attachmentID===n.attachmentID)===r&&(!t||t.has(n.attachmentID)))}catch(e){await A(i),Br.error(u(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Dr(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Kn({capture:r,admit:async()=>{let r=await Po.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:S.text,composerDocument:x,composerMentions:Oi,sendConfig:n,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return r.status===`committed`&&(e=!0,D=!1),r},captureRuntime:zn.captureRuntime,getCurrentDraftKey:()=>Xn,getDocument:aa,consumeBody:()=>pi(``),getAttachments:()=>zn.attachments,removeAttachment:zn.removeAttachment,getInlineDrafts:()=>zn.inlineDrafts,removeInlineDraft:zn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!zr&&Pi.current?.focus()}catch(e){await A(i),Br.error(u(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!b.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:n,attachments:C.length>0?C:void 0}).ok){await A(),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of _)zn.removeInlineDraft(e.id);C.length>0&&zn.clearAttachments(),zr||Pi.current?.focus()}catch(e){await A(),Br.error(u(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Bs()}}),Ys=J(()=>{Sy(()=>Js(),()=>{Br.error(u(`chat.chatInput.toast.messageSendFailed`))})}),Xs=J(async(e,t,n,r)=>{if(Ts||!Ln.draftKey)return!1;try{let i=await qt({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=ei.getState(),o=a.getDraft(Ln.draftKey);return Gf(await Lt({key:Ln.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1}}),Zs=J(e=>{if(!(c||Ts)){if(Rn){Rn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}Br.error(u(`chat.chatInput.toast.messageSendFailed`))}}),Qs=J(()=>{qe(),he(`agent`),Pi.current?.blur(),Ai.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),$s=Z.useCallback(()=>{Co(!0)},[]),ec=Z.useCallback(()=>{To(!0)},[]),tc=async e=>{if(!Ln.active||c||qs()||Vs())return;let t=e?.queuedOnly??!1,a=e?.queuedMessageId,o=e?.delivery===`steer`&&Os?`steer`:void 0,s=e?.presetText==null?As():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||$a.length>0||ns},l=e?.presetText==null?Si():null,d=Vn,f=H(s.document,`direct-send-display`);if(!f.ok){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let m=f.text,h={chunks:f.chunks??[],semantics:f.semantics??[]},v=h.chunks.every(e=>e.provenance===`authored`),y=m.trimStart(),x=v?uy(y,g):null,S=v&&fy(m,g),C=v&&g===`normal`&&/^\/model(?:\s|$)/i.test(y),w=v&&g===`normal`&&y.startsWith(`/`)?Jo(y.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(w&&!Uo(w,e=>zm(Ln,{name:e.name,source:`openchamber`}))||t&&Ts)return;if(!t&&C){P(!1),L(``),zr?vs(`model`):(q.getState().setModelSelectorOpen(!0),Ai.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&x&&x!==`model`)){if(!t&&Hn&&Ss&&Ts)return;if(!t&&Hn&&Ss&&Po.mode===`server`){s.hasContent&&Ys();return}if(!t&&Hn&&Ss){s.hasContent&&Ys();let e=Go[0];e&&Rn&&await Rn.sendQueued(e.queueItemID,{options:Os?{delivery:`steer`}:void 0});return}}let T=S?[]:a?Go.filter(e=>e.id===a):Go;if(t&&_s)return;if(t){if(T.length===0||!Hn)return}else if(!s.hasContent&&!Ss||!Hn&&!Gn)return;if(!Hn&&Wn||!zs())return;let E=!Hn&&Gn&&!t&&!S?ri.getState().newSessionDraft.draftID??null:null,D=E?z(`msg`):void 0;if(E&&D&&!mn.getState().beginEstablishing({draftID:E,primaryMessageID:D})){Bs();return}let O=()=>{lr(),E&&mn.getState().clearEstablishing(E)},k=e=>{let t=ri.getState().currentSessionId,n=(t?ri.getState().getDirectoryForSession(t):null)??Yn??``;if(!t||!n){mn.getState().clearEstablishing(e);return}xy({draftID:e,sessionID:t,directory:n,transportIdentity:r(),runtimeGeneration:i(),admitServer:Po.mode===`server`?async e=>Po.actions.admit({requestID:e.requestID,scope:{directory:n,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?$t(e.attachments):void 0}):void 0})};if(Hn&&!t&&!S&&_s){Bs(),Ys();return}let A=!t&&!S;A&&(pi(``),Ze(-1),oi(!1));let j=!1,M,N,F=!1;try{if(_y({surfaceKind:Ln.kind,currentSessionId:Hn,queuedOnly:t,resourcePolicy:S,inputMode:g,localCommand:x})&&Hn){let e=ri.getState().getDirectoryForSession(Hn)??Yn??null,t=ri.getState().stagedMessageEdit;t&&t.sessionId===Hn&&(N={sessionId:t.sessionId,messageId:t.messageId},ri.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Ai.getState(),r=qy(n,{expectedConfigKey:wr(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=vo($a);M=pn({sessionId:Hn,directory:e,content:s.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=Ln.kind===`primary`?(()=>{if(t){let e=T[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(Mo?.sessionID)return Mo.sessionID}return Hn})():null,r=t?T[0]?.sendConfig:void 0;if(t&&r||await Ln.selection.flush(),e!==null&&ri.getState().currentSessionId!==e)return;let i=async()=>{let t=r?{...r}:Ln.kind===`primary`?(()=>{let t=Ai.getState();if(!e)return Yy({captured:qy(t),surfaceSelection:Ln.selection.value});let n=ri.getState().getDirectoryForSession(e)??Yn??null;return Yy({captured:qy(t,{expectedConfigKey:wr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:Ln.selection.value})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(Ln.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=ri.getState().getDirectoryForSession(e)??Yn??null,r=wr(n);if(Ai.getState().activeDirectoryKey!==r&&await Ai.getState().activateDirectory(n),ri.getState().currentSessionId===e){let e=Ai.getState();t=Yy({captured:qy(e,{expectedConfigKey:wr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:Ln.selection.value})}}return t},c=await i(),f=!1,m=c?.providerID,v=c?.modelID,y=c?.agent,C=c?.variant;if(!m||!v){if(!f){f=!0;try{await Ai.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await i(),m=c?.providerID,v=c?.modelID,y=c?.agent,C=c?.variant}catch{}}if(!m||!v){console.warn(`Cannot send message: provider or model not selected`),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}}Hn&&!t&&!S&&await an(Hn)&&await Jr(Hn);let w={...o?{delivery:o}:{},commitStagedMessageEdit:!t,...M?{messageID:M.messageID,ticket:M}:D?{messageID:D}:{},...e?{sessionId:e,directoryHint:ri.getState().getDirectoryForSession(e)??Yn??null}:Ln.kind===`primary`&&Hn?{sessionId:Hn,directoryHint:ri.getState().getDirectoryForSession(Hn)??Yn??null}:{}},A=``,P=[],I,L=[],R=new Set(Tr(ee,Yn).map(e=>e.name)),z=[],B=S?void 0:zn.consumeSyntheticParts();for(let e=0;e<T.length;e++){let t=T[e],n=t.composerDocument&&H(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Yn,a=new Set(Tr(ee,i).map(e=>e.name)),o=hi({plan:r??Di(t.content),agents:Pr,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(z.push(...o.semantics),!I&&o.agent&&(I=o.agent),e===0)A=o.text,P=Vr([...vo(t.attachments),...o.attachments]);else{let e=vo(t.attachments);L.push({text:o.text,attachments:Vr([...e,...o.attachments])})}}if(!t&&s.hasContent){let e=vo($a),t=hi({plan:h,agents:Pr,installedSkillNames:R,directory:Yn,root:xa||Yn,confirmedFilePaths:Ti.map(e=>e.path),confirmedDirectoryPaths:Ti.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:$a});z.push(...t.semantics),!I&&t.agent&&(I=t.agent),T.length===0?(A=t.text,P=Vr([...e,...t.attachments])):L.push({text:t.text,attachments:Vr([...e,...t.attachments])})}let V=Hn??(Gn?`draft`:null),U=[];if(!t&&V&&!S&&(U=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(T.length===0)A=Ru(A,U);else if(L.length>0){let e=L[L.length-1];e.text=Ru(e.text,U)}else A=Ru(A,U);if(B&&B.length>0&&L.push(...Ni(B)),Eo&&L.push({text:Eo.contextText,synthetic:!0}),Oo&&(L.push({text:Oo.instructionsText,synthetic:!0}),L.push({text:Oo.contextText,synthetic:!0})),L.push(...ui(z,Hn&&ri.getState().getDirectoryForSession(Hn)||Yn)),!A&&P.length===0&&L.length===0)return;if(E&&D){if(!await Hr({messageID:D,providerID:m,modelID:v,agent:y,text:A,attachments:P,additionalParts:L,agentMentionName:I}))return;if(!mn.getState().isEstablishing(E)){O();return}}let W=async()=>{if(O(),Mo&&T.length>0&&b.setState(e=>{let t=p(Mo),n=e.queuedMessages[t]??[],r=new Set(T.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...T,...n.filter(e=>!r.has(e.id))]}}}),t)return B&&zn.restoreSyntheticParts(B),!0;zn.pendingInput?.text===s.message&&zn.consumePendingInput(),l&&wi(l);let e=!0;return d.length>0&&(e=await zn.restoreAttachments(d)),B&&zn.restoreSyntheticParts(B),U.length>0&&zn.restoreInlineDrafts(U),e};if(!S&&Hn&&a){let e=Mo?_(b.getState(),Mo).find(e=>e.id===a||e.queueItemID===a):void 0;Mo&&e?.queueItemID&&e.operationID&&Zo(Mo,e.queueItemID,e.operationID)}else!S&&Hn&&Ss&&Mo&&Yo(Mo);!t&&!S&&(pi(``),Ze(-1),oi(!1),gy({queuedOnly:t,resourcePolicy:S,rootAttachmentCount:d.length})&&zn.clearAttachments());let G=()=>my({currentSessionId:Hn,messageRef:ra,replacePlainDocument:pi}),K=A.trimStart();if(g===`normal`&&K.startsWith(`/`)){let e=Jo(K.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Uo(e,e=>zm(Ln,{name:e.name,source:`openchamber`})))return;if(Hn&&(e===`undo`||e===`redo`)&&py(K,g)&&G(),e===`undo`&&Hn){try{await ri.getState().handleSlashUndo(Hn),n?.()}catch(e){Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){py(K,g)&&G(),await Rn?.shortcut(`new`);return}if(e===`redo`&&Hn){try{await ri.getState().handleSlashRedo(Hn),n?.()}catch(e){Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Hn){await hy({command:`fork`,consumeCommandText:G,forkSession:()=>ri.getState().forkCurrentSession(Hn),waitForConnection:Zn,getDirectoryForSession:()=>ri.getState().getDirectoryForSession(Hn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Hn&&sa.timeline){si(!0);return}if(e===`compact`&&Hn){hy({command:`compact`,consumeCommandText:G,forkSession:async()=>void 0,waitForConnection:Zn,getDirectoryForSession:()=>Ln.directory??``,summarizeSession:e=>Xn?Ln.backend.compact({operation:`compact`,surfaceID:Ln.surfaceID,transportIdentity:Ln.transportIdentity,runtimeGeneration:Ln.runtimeGeneration,sessionID:Hn,directory:e,draftKey:Xn,deliveryTarget:Ln.deliveryTarget,providerID:m,modelID:v,agent:y,variant:C}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{Br.error(u(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Hn){try{await Zn();let e=K.replace(/^\/\u2003?summary\b/i,``).trim(),t=e?` focused on: ${e}`:``,r=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await Ci(`session.summary.visible`,{topic_line:t}),a=await Ci(`session.summary.instructions`,{topic_block:r});await er(i,m,v,y,[],I,[{text:a,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.review.visible`),t=await Ci(`session.review.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Hn&&!zr&&!se()){cr(!0);return}if(e===`goal`&&(Hn||Gn)){O(),yn.getState().setArmed(!0);let e=dy(K,g)??``;pi(e),ra.current=e,Ze(-1),e||oi(!1);return}if(e===`craft-goal`&&(Hn||Gn)){try{await Zn();let e=K.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await Ci(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),r=await Ci(`session.craftGoal.instructions`);await er(t,m,v,y,[],I,[{text:r,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.catchup.visible`),t=await Ci(`session.catchup.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.debug.visible`),t=await Ci(`session.debug.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.weigh.visible`),t=await Ci(`session.weigh.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.explore.visible`),t=await Ci(`session.explore.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.exploreFailed`))}return}}let te=Hn&&ri.getState().getDirectoryForSession(Hn)||Yn;if(qn||Hn&&!Jb(Hn,te)){let e=await Kr().catch(()=>null);e&&L.push({text:zi(e),synthetic:!0})}try{let e=Sa.getState().expandText;A=await e(A);for(let t of L)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}F=!0;let ne=er(A,m,v,y,P,I,L.length>0?L:void 0,C,g,w);j=!0,ne.finally(()=>{Bs(),N&&ri.getState().endMessageEditCommit(N.sessionId,N.messageId)}),E&&ne.then(()=>{k(E)}).catch(()=>{mn.getState().clearEstablishing(E)}),typeof window>`u`?n?.():window.requestAnimationFrame(()=>{n?.()}),ne.then(()=>{Eo&&Do(null),Oo&&Ao(null)}).catch(e=>{M&&Jn(M),W().then(e=>{e||Br.error(u(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){Br.error(u(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){d.length>0&&Br.error(u(`chat.chatInput.toast.sendAttachmentsFailed`));return}Br.error(t||u(`chat.chatInput.toast.messageSendFailed`))}),zr||Pi.current?.focus()}finally{F||(M&&Jn(M),N&&ri.getState().endMessageEditCommit(N.sessionId,N.messageId)),j||(A&&l&&wi(l),Bs(),E&&k(E))}};js.current=tc;let nc=Z.useCallback(()=>{if(qs()||Vs())return;let e=As(),t=g===`normal`&&e.hasContent&&Hn&&(Os||_s),n=t&&Uf(Po.mode)&&zt(Ln.deliveryTarget?.kind,Po.mode);jo===`queue`&&n?Ys():jo===`steer`&&t||jo===`queue`&&t&&!n?js.current(t?{delivery:`steer`}:void 0):js.current()},[g,As,Hn,Os,_s,jo,Ys,Po.mode,Ln.deliveryTarget?.kind,Ks]),rc=Z.useCallback(e=>{if(Vs())return;let t=(Pi.current?.value??ra.current).trim(),n=t?`${e}\n${t}`:e;js.current({presetText:n})},[]),ic=Z.useCallback(e=>{let t=px(aa().text,e);ki(t),Pi.current&&(Pi.current.value=t),setTimeout(()=>{Pi.current?.focus()},0)},[ki]),ac=Z.useCallback(e=>{if(Vs())return;let t=px(Pi.current?.value??ra.current,e);js.current({presetText:t})},[]),oc=zn.pendingPreset,sc=zn.consumePendingPreset;Z.useEffect(()=>{if(oc==null)return;let e=sc();e&&rc(e)},[oc,sc,rc]);let cc=Z.useCallback(()=>{pi(``),Ze(-1),Vn.length>0&&zn.clearAttachments(),Mo&&Yo(Mo),P(!1),W(!1),re(!1),O(!1),g===`shell`&&x(`normal`)},[Vn.length,zn,Yo,Mo,pi,g]),lc=e=>{if(!Ln.active||Fg(e))return;if(ga&&qa(e,ga)&&!Xr){let t=Pi.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),cc();return}}if(g===`shell`&&e.key===`Escape`){e.preventDefault(),x(`normal`);return}if(g===`shell`&&e.key===`Backspace`&&di.length===0){e.preventDefault(),x(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Pi.current,n=t?.selectionStart??di.length,r=t?.selectionEnd??di.length,i=vi({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=qb(ci.getDocument().text,i.start);e.preventDefault(),ki(t.text),requestAnimationFrame(()=>{Pi.current?.setSelectionRange(t.caret,t.caret),bc()}),xc(t.text,t.caret);return}let a=Ee(di,Vn.filter(Ne).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=qb(a.text,a.caret);e.preventDefault(),ki(n.text);for(let e of Vn)t.has(e.filename.toLowerCase())&&zn.removeAttachment(e.id);requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=n.caret,Pi.current.selectionEnd=n.caret),bc()}),xc(n.text,n.caret);return}let o=kv(di,so.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=qb(o.text,o.caret);e.preventDefault(),ki(t.text),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=t.caret,Pi.current.selectionEnd=t.caret),bc()}),xc(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<di.length){let n=Te(di,Vn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=V(di.slice(n.start+1,n.end-1)).trim(),r=Vn.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=di[n.end]===` `?n.end+1:n.end,a=`${di.slice(0,n.start)}${di.slice(i)}`;e.preventDefault(),ki(a),r&&zn.removeAttachment(r.id),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=n.start,Pi.current.selectionEnd=n.start),bc()}),xc(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(di[r-1]);)--r;let i=t+1;for(;i<di.length&&!/\s/.test(di[i]);)i+=1;let a=di.slice(r,i),o=a.slice(1);if(Bb.test(a)&&!to.current.has(o.toLowerCase())&&Cr({mention:o,confirmed:ji.has(o),terminated:i<di.length&&/\s/.test(di[i])})){let t=di[i]===` `?i+1:i,n=`${di.slice(0,r)}${di.slice(t)}`;e.preventDefault(),ki(n),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=r,Pi.current.selectionEnd=r),bc()}),xc(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&ea.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ea.current.handleKeyDown(e.key);return}if(U&&ta.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ta.current.handleKeyDown(e.key);return}if(ne&&na.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),na.current.handleKeyDown(e.key);return}if(D&&Qi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Qi.current.handleKeyDown(e.key);return}if(Ua&&e.key===`Escape`){e.preventDefault(),oi(!1);return}let n=ha&&!ha.includes(`shift`)?Ja(`shift+${ha}`):``,r=n&&qa(e,n)?-1:+!!qa(e,ha);if(r!==0&&!M&&!U&&!ne&&!D){e.preventDefault(),e.stopPropagation(),Rn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Pi.current?.focus({preventScroll:!0})});return}let i=M||U||ne||D,a=Pi.current?.selectionStart===0&&Pi.current?.selectionEnd===0,o=Pi.current?.selectionStart===di.length&&Pi.current?.selectionEnd===di.length,s=!i&&(di.length===0||a),c=!i&&(di.length===0||o);if(g===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Pi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),ki(t),requestAnimationFrame(()=>{let e=Pi.current;e&&(e.selectionStart=n,e.selectionEnd=r),bc()}),xc(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=di.slice(n,r);t(`${di.slice(0,n)}${a}${s}${o}${di.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=di.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${di.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&ms.length>0){if(e.preventDefault(),Xe===-1)Ze(0),yi({text:ms[0],references:[]});else if(Xe<ms.length-1){let e=Xe+1;Ze(e),yi({text:ms[e],references:[]})}requestAnimationFrame(()=>{Pi.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Xe>=0){if(e.preventDefault(),Xe===0)Ze(-1),bi();else{let e=Xe-1;Ze(e),yi({text:ms[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),qs()||Vs())return;let t=e.ctrlKey||e.metaKey,n=g===`normal`&&xs&&Hn&&(Os||_s),r=n&&Uf(Po.mode)&&zt(Ln.deliveryTarget?.kind,Po.mode);jo===`queue`?t||!n?tc():r?Ys():tc({delivery:`steer`}):t||!n?tc():tc({delivery:`steer`})}},uc=Z.useCallback((e,t)=>{let n=e.ownerDocument,r=n.defaultView;if(!r)return null;let i=r.getComputedStyle(e),a=n.createElement(`div`),o=a.style;o.position=`absolute`,o.visibility=`hidden`,o.pointerEvents=`none`,o.whiteSpace=`pre-wrap`,o.wordWrap=`break-word`,o.overflow=`hidden`,o.left=`-9999px`,o.top=`0`,o.width=`${e.clientWidth}px`,o.font=i.font,o.fontSize=i.fontSize,o.fontFamily=i.fontFamily,o.fontWeight=i.fontWeight,o.fontStyle=i.fontStyle,o.fontVariant=i.fontVariant,o.letterSpacing=i.letterSpacing,o.textTransform=i.textTransform,o.textIndent=i.textIndent,o.padding=i.padding,o.border=i.border,o.boxSizing=i.boxSizing,o.lineHeight=i.lineHeight,o.tabSize=i.tabSize,a.textContent=e.value.slice(0,t);let s=n.createElement(`span`);s.textContent=e.value.slice(t,t+1)||` `,a.appendChild(s),n.body.appendChild(a);let c=s.offsetTop,l=s.offsetLeft;return n.body.removeChild(a),{top:c,left:l}},[]),dc=Z.useCallback(()=>{if(!Ua){bo(null);return}if(!M&&!U&&!ne&&!D){bo(null);return}let e=Pi.current,t=Vi.current;if(!e||!t)return;let n=e.selectionStart??di.length,r=uc(e,n);if(!r)return;let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=i.top-a.top+(r.top-e.scrollTop),s=i.left-a.left+(r.left-e.scrollLeft),c=o-8,l=a.height-o-8,u=l>=260||l>=c?`below`:`above`,d=D?520:M||ne?450:360,f=Math.max(8,Math.min(s-24,a.width-d-8)),p=Math.max(120,Math.min(260,u===`below`?l:c));bo({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Ua,uc,di.length,M,D,ne,U]);Z.useLayoutEffect(()=>{dc()},[dc,di,M,U,ne,D,Ua]),Z.useEffect(()=>{if(!Ua)return;let e=()=>dc();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Ua,dc]);let fc=Z.useCallback(()=>{xo.current&&=(clearTimeout(xo.current),null),Pa(!0),xo.current=setTimeout(()=>{Pa(!1),xo.current=null},1800)},[]),mc=Z.useCallback(()=>{if(zn.abortPrompt.clear(),fc(),Ln.kind===`secondary`){Rn?.shortcut(`abort`);return}nr()},[nr,Rn,fc,Ln.kind,zn]),hc=Z.useCallback((e=1)=>{if(Ir)return;let t=Ut(Pr,Ln.selection.value.agent??vr,e);if(!t||!Ln.selection.change)return;let n=Bt({providerID:Ln.selection.value.providerID??``,modelID:Ln.selection.value.modelID??``,agent:Ln.selection.value.agent??null},t,Pr,Fr);Ln.selection.change({...Ln.selection.value,...n,agent:n.agent??void 0}),Ln.kind===`primary`&&(q.getState().addRecentAgent(t),Ln.sessionID&&Zi.getState().saveSessionAgentSelection(Ln.sessionID,t))},[Pr,vr,Fr,Ir,Ln.kind,Ln.selection,Ln.sessionID]);Qe.current=hc;let gc=Z.useRef(null),[_c,vc]=Z.useState(null),yc=Z.useCallback(e=>{vc(t=>t===e?t:e)},[]),bc=Z.useCallback(e=>{let t=Pi.current;if(!t)return;let n=t.scrollTop;if(Ka){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,pe(null),t.scrollTop!==n&&(t.scrollTop=n);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let r=t.ownerDocument?.defaultView,i=r?r.getComputedStyle(t):null,a=i?parseFloat(i.lineHeight):NaN,o=i?parseFloat(i.paddingTop):NaN,s=i?parseFloat(i.paddingBottom):NaN,c=Number.isNaN(o)||Number.isNaN(s)?16:o+s,l=Number.isNaN(a)?22:a,u=Nb({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:gc.current??0,lineHeight:l,paddingTotal:c});t.style.height=`${u.height}px`,t.style.maxHeight=`${u.maxHeight}px`,t.style.overflowY=u.overflowY,t.scrollTop!==n&&(t.scrollTop=n),pe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[Ka]);Z.useLayoutEffect(()=>{let e=di.length<Bi.current;Bi.current=di.length,bc({allowShrink:e})},[bc,di,zr]),Z.useLayoutEffect(()=>{gc.current=_c,bc({allowShrink:_c===null})},[bc,_c]);let xc=Z.useCallback((e,t,n=`manual`,r)=>{let i=ps({text:e,cursor:t,inputMode:g,mentionInputSource:n,insertedText:r});if(Ri.current=i,!i){P(!1),O(!1),W(!1),re(!1),te(``);return}if(i.kind===`slash-command`){L(i.query),P(!0),O(!1),W(!1),re(!1);return}if(P(!1),i.kind===`slash-skill`){te(i.query),W(!0),O(!1),re(!1);return}if(W(!1),te(``),i.kind===`snippet`){oe(i.query),re(!0),O(!1);return}re(!1),A(i.query),O(!0)},[g,L,A,P,O,W,re,te,oe]),Sc=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(g===`normal`&&!Ii.current&&co.size>0&&e.includes(`/`)){let r=No(e,co,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=gi(a,o,s,(e,t)=>{let n=[...e];for(let e of pr(t.text,{agentNames:eo,includeUnterminatedPastedReferences:r===`paste`}))n=is(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=aa(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Pi.current;e&&Fm(u,Ii.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),bc()}),xc(l.text,c.end,r,i),{document:l,selection:c}},[bc,gi,aa,g,eo,co,xc]),Cc=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=Pi.current;if(!n){let n=di+e;Sc(n,n.length,n.length,t,e);return}let r=n.selectionStart??di.length,i=n.selectionEnd??di.length,a=`${di.substring(0,r)}${e}${di.substring(i)}`,o=r+e.length;Sc(a,o,o,t,e)},[Sc,di]),wc=J((e,t)=>{let n=new Set(xe(Vn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of Vn)n.has(e.filename)&&zn.removeAttachment(e.id)}),Tc=Z.useCallback(e=>{zn.removeAttachment(e.id)},[zn]),Ec=Z.useCallback(()=>{Ui.current=!1,qi.current=[],Wi.current&&=(clearTimeout(Wi.current),null)},[]),Dc=Z.useCallback(()=>{Wi.current&&clearTimeout(Wi.current),Wi.current=setTimeout(()=>{Ec()},700)},[Ec]),Oc=Z.useCallback(()=>{Gi.current=!1,Ki.current&&=(clearTimeout(Ki.current),null)},[]),kc=Z.useCallback(()=>{Gi.current=!0,Ki.current&&clearTimeout(Ki.current),Ki.current=setTimeout(()=>{Gi.current=!1,Ki.current=null},700)},[]),Ac=Z.useCallback(e=>{!se()||!Ui.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),Ec())},[Ec]),jc=e=>{if(Xr)return;let t=e.nativeEvent;if(se()&&Ui.current){let n=qi.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){Ec();return}}let n=e.target.value;wc(ra.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Gb(ra.current,n):``,a=i.includes(`@`)||Gi.current;Gi.current&&Oc();let o=a?`paste`:`manual`;if(g===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);x(`shell`),pi(e),bc(),P(!1),W(!1),O(!1),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=t,Pi.current.selectionEnd=t)});return}Sc(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{Ec(),Oc()},[Ec,Oc]);let Mc=Z.useCallback(e=>{let t=Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)));if(t.length===0)return;let n=t.map(e=>`@${e}`).join(` `),r=Pi.current,i=r?.selectionStart??di.length,a=r?.selectionEnd??di.length,o=$o(n,di.slice(0,i),di.slice(a)),s=`${di.slice(0,i)}${o}${di.slice(a)}`;wc(di,s),oa(s,t)},[di,oa,wc]),Nc=Z.useCallback(async e=>{let t=$b(e.clipboardData);if(t.length>0&&(Hn||Gn)){e.preventDefault(),Mc(t);return}if(g===`normal`&&(Hn||Gn)){let t=Pi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=di.slice(n,r);if(Hb.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${di.slice(0,n)}[${i}](${t})${di.slice(r)}`,o=n+1+i.length+2+t.length+1;ki(a),requestAnimationFrame(()=>{let e=Pi.current;e&&(e.selectionStart=o,e.selectionEnd=o),bc()}),xc(a,o,Kb(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(g===`normal`&&cb(aa(),a)){e.preventDefault();let t=aa().text,n=Pi.current,r=n?.selectionStart??di.length,i=n?.selectionEnd??di.length,o=lb(a,di,aa().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>u(`chat.chatInput.pastedTextReference`,{index:e,count:t}),sb(aa())),s=_i(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=ls(s.document.text,s.caret);Pi.current&&(Pi.current.value=s.document.text),requestAnimationFrame(()=>{Pi.current?.setSelectionRange(c,c),bc()}),xc(s.document.text,c),wc(t,s.document.text);return}a.includes(`@`)&&kc();return}if(!Hn&&!Gn){a.includes(`@`)&&kc();return}e.preventDefault();let o=ke(i,[...Vn.map(e=>e.filename),...ia.current]),s=Re(o),c=aa().text,l=Pi.current,d=l?.selectionStart??di.length,f=l?.selectionEnd??di.length,p=g===`normal`&&cb(aa(),a)?lb(a,di,aa().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>u(`chat.chatInput.pastedTextReference`,{index:e,count:t}),sb(aa())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,h=$o(m,di.slice(0,d),di.slice(f));if(p){let e=_i(d,f,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=ls(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;Sc(n,t+s.length,t+s.length,Kb(n),s),wc(c,n)}else Cc(h,Kb(h)),wc(c,`${di.slice(0,d)}${h}${di.slice(f)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Wb(i[e],t);ia.current.add(t);try{await zn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.clipboardAttachFailed`))}finally{ia.current.delete(t)}}},[zn,Mc,Vn,bc,Hn,aa,g,_i,kc,di,Gn,Cc,u,xc,Sc,ki,wc]),Pc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=Ov(r,i,[...Te(di,Vn.filter(Ne).map(e=>e.filename)),...Dv(di,so.keys()),...aa().references]),o=a?.start??r,s=a?.end??i,c=di.slice(o,s),l=R(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${di.slice(0,o)}${di.slice(s)}`;Sc(e,o,o),requestAnimationFrame(()=>{Pi.current?.setSelectionRange(o,o),bc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Pi.current?.setSelectionRange(o,s)})},[bc,Vn,so,Sc,aa,di]),Fc=Z.useCallback(e=>{Pc(e,`copy`)},[Pc]),Ic=Z.useCallback(e=>{Pc(e,`cut`)},[Pc]),Lc=e=>{let t=Pi.current,n=t&&document.activeElement===t?t.selectionStart??Li.current:Li.current;return Ps(e,n)},Rc=()=>{Gs(zr)||Pi.current?.focus()},zc=e=>{let t=Lc(di.length),n=Wo(di,t,Ri.current),r=di.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():Xc(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=ss(di,o,s,`@${i}`);oa(c.text,[i],a),Li.current=c.caret,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=c.caret,Pi.current.selectionEnd=c.caret),bc(),xc(c.text,c.caret)}),O(!1),A(``),Rc()},Bc=e=>{let t=Lc(di.length),n=Wo(di,t,Ri.current),r=di.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=ss(di,i,a,`@${e}`);ki(o.text,t=>is(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Li.current=o.caret,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=o.caret,Pi.current.selectionEnd=o.caret),bc(),xc(o.text,o.caret)}),O(!1),A(``),Rc()},Vc=J(e=>{$i.current||($i.current=!0,(async()=>{try{let t=ri.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){Br.error(u(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await yt(e.id,{directory:t}),!ii(e.id,t)){Br.error(u(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Lr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=aa(),r=Lc(n.text.length),i=Wo(n.text,r,Ri.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=fi().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,l={id:`session:${e.id}:${N()}`,kind:`session`,sessionId:e.id,display:j({trigger:`@`,icon:`chat-thread`,label:o})},d=_i(s,c,l,{inlineBoundaries:!0,padDocumentEdges:!0}),f=ls(d.document.text,d.caret);Li.current=f,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=f,Pi.current.selectionEnd=f),bc(),xc(d.document.text,f)}),O(!1),A(``),Rc()}catch{Br.error(u(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{$i.current=!1}})())}),Hc=J(e=>{let t=aa(),n=Lc(t.text.length),r=Wo(t.text,n,Ri.current)??Fo(t.text,n);if(!r)return!1;let i=_i(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=ls(i.document.text,i.caret);return Li.current=o,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=o,Pi.current.selectionEnd=o),bc(),xc(i.document.text,o),a&&(P(!1),W(!1))}),Rc(),a}),Uc=e=>{Hc({id:`skill:${e.name}:${N()}`,kind:`skill`,skillName:e.name,display:j({trigger:`/`,icon:`book-open`,label:e.name})})&&te(``)},Wc=(e,t)=>{let n=Lc(di.length),r=Wo(di,n,Ri.current),i=di.substring(0,n).lastIndexOf(`#`),a=r?.start??(i===-1?n:i),o=r?.end??n,s=`${di.substring(0,a)}#${t} ${di.substring(o)}`;ki(s);let c=a+t.length+2;Li.current=c,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=c,Pi.current.selectionEnd=c),bc(),xc(s,c)}),re(!1),oe(``),Rc()},Gc=(e,t=!1)=>{if(!zm(Ln,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Hc({id:`skill:${e.name}:${N()}`,kind:`skill`,skillName:e.name,display:j({trigger:`/`,icon:`book-open`,label:e.name})})&&L(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Hc({id:`command:${e.name}:${N()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:j({trigger:`/`,icon:`command`,label:e.name})})){L(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=No(r,new Set([...co,e.name.toLowerCase()]),r.length);pi(i?.text??r);let a=Pi.current;if(a&&(a._commandMetadata=e),P(!1),L(``),t){tc({presetText:n});return}let o=()=>{if(!Gs(zr)&&Pi.current){try{Pi.current.focus({preventScroll:!0})}catch{Pi.current.focus()}Pi.current.setSelectionRange(Pi.current.value.length,Pi.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Hn&&Pi.current&&!zr&&Pi.current.focus()},[Hn,zr]),Z.useEffect(()=>{zr||he(null)},[zr]);let Kc=zn.abortPrompt.sessionID,qc=zn.abortPrompt.clear;Z.useEffect(()=>{Kc&&Kc!==Hn&&qc()},[Hn,Kc,qc]),Z.useEffect(()=>{Ji.current=!!(Hn||Gn)},[Hn,Gn]);let Jc=Z.useCallback(e=>{if(!e)return!1;if(e.files&&e.files.length>0)return!0;if(e.types){let t=Array.from(e.types).map(e=>e.toLowerCase());if(t.includes(`files`)||t.includes(`text/uri-list`)||t.includes(`codefiles`)||t.includes(`application/x-openchamber-file-path`)||t.some(e=>e.includes(`vnd.code.tree`)))return!0}return Jv(e).length>0},[]),Yc=Z.useCallback(e=>{if(!e)return[];let t=Array.from(e.files||[]);return t.length>0?t:Array.from(e.items||[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>!!e)},[]),Xc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(xa||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[xa]),Zc=e=>{if(!Jc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Hi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==w&&T(t),(Hn||Gn)&&!S&&C(!0)},Qc=e=>{Jc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Hn||Gn)&&!S&&C(!0))},$c=e=>{e.preventDefault(),e.stopPropagation(),Hi.current--,Hi.current<=0&&(Hi.current=0,C(!1),T(!1),Ec())},el=()=>{Hi.current=0,C(!1),T(!1),Ec()},tl=async e=>{if(Hi.current=0,!Jc(e.dataTransfer)){Ec();return}if(e.preventDefault(),e.stopPropagation(),C(!1),!Hn&&!Gn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Pi.current,r=ra.current;if(n){let t=n.selectionStart??Li.current,i=n.selectionEnd??t,a=ss(r,t,i,e);ki(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Li.current=a.caret,n.focus()})}else{let t=ss(r,r.length,r.length,e);ki(t.text)}Ec();return}let n=$b(e.dataTransfer);if(n.length>0){se()&&(qi.current=n),Mc(n),se()||Ec();return}let r=Yc(e.dataTransfer);if(r.length>0){let e=Re(r.map(e=>e.name)),t=$o(e,ra.current.slice(0,Pi.current?.selectionStart??ra.current.length),ra.current.slice(Pi.current?.selectionEnd??ra.current.length));Cc(t);for(let e of r)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.attachFileFailed`))}}Ec()},nl=e=>{Jc(e.dataTransfer)&&(e.preventDefault(),se()&&(Ui.current=!0,Dc()))},Q=Z.useRef(null),rl=Z.useRef(null),il=J((e=!0)=>{Ke.current=0;let t=()=>{let t=Nm(Pi);if(!t||(Pm(Pi),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),al=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Re(t.map(e=>e.name)),n=$o(e,ra.current.slice(0,Pi.current?.selectionStart??ra.current.length),ra.current.slice(Pi.current?.selectionEnd??ra.current.length));Cc(n)}for(let e of t)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.attachFileFailed`))}},[zn,Cc,u]),ol=Z.useCallback(async()=>{try{let e=await da?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6535
|
-
`);Br.error(u(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(il(!1),await al(r),il())}catch(e){console.error(`VS Code file pick failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.vscodePickFailed`))}},[al,il,u,da]),sl=Z.useCallback(()=>{if(se()){ol();return}Q.current?.click()},[ol]),cl=Z.useCallback(()=>{if(se()){ol();return}rl.current?.click()},[ol]),ll=Z.useCallback(async()=>{if(!hl()){cl();return}try{let e=await gl(20);if(e===null){cl();return}e.length>0&&(il(!1),await al(e),il())}catch(e){console.error(`Native photo pick failed`,e),Br.error(u(`chat.chatInput.toast.attachFileFailed`))}},[al,il,cl,u]),ul=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(il(!1),await al(t),e.target.value=``,il())},[al,il]),dl=`gap-x-1.5 gap-y-0`,fl=se(),pl=Ln.kind===`primary`&&qn&&!fl,ml=Z.useMemo(()=>(Ht?.selectedProjectId?rr.find(e=>e.id===Ht.selectedProjectId)??null:null)||(ir?rr.find(e=>e.id===ir)??null:null)||(rr[0]??null),[ir,Ht?.selectedProjectId,rr]),_l=Z.useMemo(()=>
|
|
6536
|
-
`)})),e.length!==0&&al(e)},onRemoveAttachment:e=>{zn.removeAttachment(e)},onOpenModel:()=>vs(`model`),onCycleAgent:()=>hc(),onOpenAgent:Qs,showScrollToBottom:!!(o&&s),scrollAria:u(`chat.scrollToBottom.aria`),onScrollToBottom:s??(()=>{}),autocompleteOpen:ce.length>0&&(M||U||D),autocompleteHighlightedIndex:ue,autocompleteRows:ce,caret:Li.current,onAutocompleteAccept:Yl,onAutocompleteDismiss:Xl,chipHighlights:_o}),Ql=Z.useRef(null);st(Zl?Ql:null,()=>{let e=Ql.current?.getBoundingClientRect().height??0;Ls(document.documentElement,e)});let $l=Z.useRef(!1);$l.current=So||wo;let eu=Z.useRef(!1),tu=Z.useRef(0),nu=Z.useRef(0),ru=J(()=>{let e=ri.getState().stagedMessageEdit;!e||e.sessionId!==Hn||window.setTimeout(()=>{let t=ri.getState().stagedMessageEdit,n=document.activeElement,r=vy({surfaceKind:Ln.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:Vs(),focusHeld:Date.now()<nu.current,overlayOpen:tu.current>0||$l.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<Ke.current});r.action===`disarm`&&ri.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!zr||Ie()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{tu.current+=1},t=()=>{if(tu.current=Math.max(0,tu.current-1),eu.current){eu.current=!1;return}if(!Ye.current||$l.current||tu.current>0)return;if(ya()){Ye.current=!1;return}Ye.current=!1,nu.current=Date.now()+600,Pi.current?.focus(),document.activeElement===Pi.current&&ye(!0);let e=()=>{let e=Pi.current;!e||document.activeElement!==e||(iu.current??e).scrollIntoView({block:`end`})};ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),_e.current!==null&&(window.clearTimeout(_e.current),_e.current=null),ge.current=window.setTimeout(()=>{ge.current=null,e()},300),_e.current=window.setTimeout(()=>{_e.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),_e.current!==null&&(window.clearTimeout(_e.current),_e.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[zr]),Z.useEffect(()=>{if(!zr)return;if(Wl){(ve||Date.now()-Je.current<800)&&(Ye.current=!0);return}if(!Ye.current)return;let e=window.setTimeout(()=>{if(Ye.current=!1,ya())return;let e=Pi.current;e&&document.activeElement!==e&&e.focus({preventScroll:Ie()})},180);return()=>window.clearTimeout(e)},[zr,Wl,ve]),Z.useEffect(()=>{if(!zr||Ie()||typeof document>`u`||ve||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Pi.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[zr,ve]),Z.useEffect(()=>{ze(``)},[Me]);let iu=Z.useRef(null),au=zr?`px-1.5 py-1.5`:fl?`px-1.5 py-1`:`px-2.5 py-1.5`,ou=zr?`h-8 w-8`:fl?`h-5 w-5`:`h-6 w-6`,su=zr?`h-4 w-4`:fl?`h-3.5 w-3.5`:`h-4 w-4`,cu=zr?`h-6 w-6`:`size-full`,lu=zr?`h-[1.125rem] w-[1.125rem]`:fl?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,du=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,_m),fu=Y(du,ou),pu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,ou),mu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,`h-6 w-6`);Z.useEffect(()=>()=>{xo.current&&=(clearTimeout(xo.current),null)},[]);let hu=zr?(0,$.jsxs)(`div`,{"data-composer-action":`true`,className:`composer-mobile-model-controls flex min-w-0 flex-1 items-center justify-end gap-x-1.5`,children:[(0,$.jsx)(ax,{onOpenAgentPanel:Qs,onCycleAgent:()=>{qe(),hc()},agentName:Ln.selection.value.agent,agents:Pr,disabled:Rr}),(0,$.jsx)(ox,{onOpenModel:()=>vs(`model`),providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID,provider:Fr.find(e=>e.id===Ln.selection.value.providerID),variant:Ln.selection.value.variant})]}):null,gu=(0,$.jsxs)(`div`,{className:`oc-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(wd,{attachments:Vn,onShowPopup:Gr,onRemoveAttachedFile:Tc}),Ln.kind===`primary`?(0,$.jsx)(Od,{attachedFiles:Vn,onAddVSCodeFile:(e,t,n)=>{Xn&&xn(Xn,()=>ei.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Xn)return xn(Xn,()=>ei.getState()).addVSCodeSelection(e,t)}}):null]}),_u=_o?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(jv,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),vu=zr?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,ks&&`oc-mobile-composer-compact-chrome--aborting`,Es&&!ks&&`oc-mobile-composer-compact-chrome--sending`,o&&s&&`oc-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(lx,{isVSCode:fl,footerIconButtonClass:fu,iconSizeClass:lu,handlePickLocalFiles:sl,handlePickLocalImages:cl,openIssuePicker:$s,openPrPicker:ec,onOpenMobileSheet:Hl,onOpenAndroidPickSheet:hl()?Ul:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[o&&s?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(Sg,{placement:`compact`,visible:o,onClick:s})}):null,ks||Es?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(dx,{isMobile:!0,compact:!0,footerIconButtonClass:fu,stopFooterIconButtonClass:pu,compactCircleButtonClass:mu,sendIconSizeClass:su,stopIconSizeClass:cu,canSend:Es,canAbort:ks,hasContent:!1,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Wn,submissionBlocked:c,sendPhase:Rs,queueFrozen:Ts,queueFallbackAvailable:ks||Os,onPrimaryAction:nc,onAbort:mc})}):null]})]}):null,yu=zr?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`oc-mobile-composer-full-chrome flex w-full min-w-0 items-center gap-x-1.5`,"data-composer-action":`true`,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(lx,{isVSCode:fl,footerIconButtonClass:fu,iconSizeClass:lu,handlePickLocalFiles:sl,handlePickLocalImages:cl,openIssuePicker:$s,openPrPicker:ec,onOpenSettings:e,onOpenMobileSheet:Hl,onOpenAndroidPickSheet:hl()?Ul:void 0}),br?(0,$.jsx)(ux,{sessionId:Hn,draftOpen:Gn,draftEnabled:Ht.permissionAutoAcceptEnabled===!0,enabled:hr,saving:Hn?tn:!1,footerIconButtonClass:fu,iconSizeClass:lu,onSetDraftEnabled:Qt,onSetSessionEnabled:nn,onOpenSessionFirst:Xt,onToggleFailed:xr}):null,(0,$.jsx)(ry,{sessionId:Hn,directory:St??Yn,draftOpen:Gn}),(0,$.jsx)(iy,{length:di.length})]}),hu,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(dx,{isMobile:zr,footerIconButtonClass:fu,stopFooterIconButtonClass:pu,sendIconSizeClass:su,stopIconSizeClass:cu,canSend:Es,canAbort:ks,hasContent:!!xs,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Wn,submissionBlocked:c,sendPhase:Rs,queueFrozen:Ts,queueFallbackAvailable:ks||Os,onPrimaryAction:nc,onAbort:mc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,dl),children:[(0,$.jsx)(lx,{isVSCode:fl,footerIconButtonClass:fu,iconSizeClass:lu,handlePickLocalFiles:sl,handlePickLocalImages:cl,openIssuePicker:$s,openPrPicker:ec,onOpenSettings:e,withTooltip:!0}),br?(0,$.jsx)(ux,{sessionId:Hn,draftOpen:Gn,draftEnabled:Ht.permissionAutoAcceptEnabled===!0,enabled:hr,saving:Hn?tn:!1,footerIconButtonClass:fu,iconSizeClass:lu,onSetDraftEnabled:Qt,onSetSessionEnabled:nn,onOpenSessionFirst:Xt,onToggleFailed:xr}):null,(0,$.jsx)(ry,{sessionId:Hn,directory:St??Yn,draftOpen:Gn}),(0,$.jsx)(iy,{length:di.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,dl),children:[(0,$.jsx)(rx,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Pi,selectionAdapter:kr}),(0,$.jsx)(ix,{radius:Ya,isMobile:zr,footerIconButtonClass:fu,footerPaddingClass:au,iconSizeClass:lu,sendIconSizeClass:su,onInsert:ic,onInsertAndSend:ac,onContentHeightChange:yc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(dx,{isMobile:zr,footerIconButtonClass:fu,stopFooterIconButtonClass:pu,sendIconSizeClass:su,stopIconSizeClass:cu,canSend:Es,canAbort:ks,hasContent:!!xs,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Wn,submissionBlocked:c,sendPhase:Rs,queueFrozen:Ts,queueFallbackAvailable:ks||Os,onPrimaryAction:nc,onAbort:mc})]})]}),bu=J(()=>{if(zr){nu.current=Date.now()+600;let e=()=>{Pi.current?.focus({preventScroll:Ie()}),document.activeElement===Pi.current&&ye(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Pm(Pi))return;let e=Nm(Pi);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),xu=St??Yn,{goal:Su,enabled:Cu}=Zv(Hn??``,xu),wu=(0,$.jsx)(Ep,{onEditMessage:Xs,onSendMessage:Zs,onEditCommitted:bu,draftKey:Xn,scope:Mo,draftTarget:Xn?{key:Xn,expectedRevision:()=>zn.getDraft(Xn)?.revision??`absent`}:null,clientPendingItems:Us,onRemoveClientPending:e=>{let t=mn.getState().removeEstablishingFollowUp(e);t&&(t.content&&pi(t.content),t.attachments.length>0&&zn.restoreAttachments(t.attachments))},trailing:Hn&&Cu&&Su?(0,$.jsx)(ny,{sessionId:Hn,directory:xu}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:iu,onSubmit:e=>{e.preventDefault(),nc()},onPointerDownCapture:e=>{if(!zr)return;let t=e.target;t instanceof Element&&(t.closest(`textarea[data-chat-input="true"]`)||t.closest(`[data-chat-prompt-attachments="true"]`)||t.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(qe(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,Ua&&`flex h-full min-h-0 flex-col pt-4`,Wa&&`flex h-full min-h-0 flex-col pt-1`,zr&&`bottom-safe-area oc-mobile-composer`),"data-native-ios-composer":Zl?`true`:void 0,style:zr&&Ie()&&!Zl&&Zr>0&&!ve?{marginBottom:`${Zr}px`}:void 0,children:[qn&&!Ua&&!zr&&!fl&&!Fl?(0,$.jsx)(`div`,{className:`chat-input-column mb-7 text-center`,children:(0,$.jsx)(`h1`,{className:`text-balance text-2xl font-normal tracking-tight text-foreground md:text-3xl`,children:nx(vl?u(`chat.emptyState.draftTitleWithProject`,{project:vl}):u(`chat.emptyState.draftTitle`),vl)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Ka&&`flex flex-1 min-h-0 flex-col`),children:[Zl?null:(0,$.jsx)(Td,{attachments:Vn,onShowPopup:Gr,onRemoveAttachedFile:Tc}),(0,$.jsx)(Wp,{}),ns&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[cs>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:va?.colors?.surface?.elevated,borderColor:va?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:va?.colors?.status?.info},children:cs}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:ds,"aria-label":u(`chat.chatInput.reviewCommentsRemove`),title:u(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,rs>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:va?.colors?.surface?.elevated,borderColor:va?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:va?.colors?.status?.info},children:rs}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>us(`preview-console`),"aria-label":u(`chat.chatInput.devServerLogsRemove`),title:u(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,as>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:va?.colors?.surface?.elevated,borderColor:va?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:va?.colors?.status?.info},children:as}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>us(`preview-annotation`),"aria-label":u(`chat.chatInput.previewContextRemove`),title:u(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),Eo&&!fl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Co(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Eo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Eo.author.avatarUrl,alt:Eo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,Eo.number,Eo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:u(`chat.chatInput.linked.byAuthor`,{author:Eo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Eo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Eo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Do(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.issue.removeAria`),title:u(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),Oo&&!fl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>To(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Oo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Oo.author.avatarUrl,alt:Oo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[u(`chat.chatInput.linked.pr.number`,{number:Oo.number}),Oo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:u(`chat.chatInput.linked.byAuthor`,{author:Oo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Oo.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[Oo.head,` → `,Oo.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Oo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Ao(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.pr.removeAria`),title:u(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(cx,{sessionId:Hn,directory:St??Yn}),(0,$.jsxs)(`div`,{className:zr?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:zr?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:zr?`oc-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:Ql,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(sx,{showAbortStatus:Ma,showAssistantStatus:!1,showTodos:!0,leftAccessory:Gn||!Il?null:(0,$.jsx)(bg,{})}),!zr&&pl?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[ml?(0,$.jsxs)(ka,{value:ml.id,open:He,onValueChange:zl,onOpenChange:e=>{Ue(e),e||Ve(``)},children:[(0,$.jsx)(Ba,{asChild:!0,size:`sm`,children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex h-6 min-w-0 w-fit max-w-[42vw] items-center rounded-lg !border-0 px-1.5 py-1 pr-1.5 typography-micro font-medium text-foreground/80 transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5 sm:max-w-[18rem]`,hm),children:[(0,$.jsx)(ba,{children:Vl(ml)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`})]})}),(0,$.jsxs)(Oa,{fitContent:!0,children:[(0,$.jsx)(Va,{autoFocus:!0,value:Be,onChange:e=>Ve(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:u(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),rr.filter(e=>za(tx(e),Be)||za(e.path,Be)).map(e=>(0,$.jsx)(Ra,{value:e.id,className:`max-w-[24rem] truncate`,children:Vl(e)},e.id)),(0,$.jsx)(Ta,{}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left typography-ui-label text-foreground hover:bg-interactive-hover`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),Ue(!1),requestAnimationFrame(()=>gt.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,hm),onClick:()=>gt.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]}),ml&&Rl?(0,$.jsx)(dv,{directory:jl,projectDirectory:_l,label:Pl,projectRootOption:kl,worktreeOptions:Al,onSelectDirectory:Bl}):null]}):null,zr&&pl?(0,$.jsxs)(`div`,{className:`oc-mobile-draft-target-selectors mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[ml?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] shrink items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,hm),onClick:()=>Pe(`project`),children:Vl(ml)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,hm),onClick:()=>gt.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]}),ml&&Rl?(0,$.jsx)(dv,{directory:jl,projectDirectory:_l,label:Pl,projectRootOption:kl,worktreeOptions:Al,onSelectDirectory:Bl,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,wu]})}),(0,$.jsx)(`div`,{className:Y(!zr&&`contents`,zr&&`contents`,Wa&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:zr?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(U_,{value:di,attachments:[],disabled:!Hn&&!Gn||Wn&&!Rs.establishing,pending:ks||Rs.inFlight&&!Rs.establishing,isMobile:zr,onSubmit:nc,"data-mobile-composer-surface":zr?`true`:void 0,"data-session-swipe-surface":zr?`true`:void 0,expanded:Ka,focusedTone:g===`shell`?`info`:`primary`,className:Y(`relative z-10`,S&&`ring-2 ring-primary ring-offset-2`,Xr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,zr&&`oc-mobile-composer-surface`),style:{borderRadius:Ya},ref:Vi,onDropCapture:nl,onDragEnter:Zc,onDragOver:Qc,onDragLeave:$c,onDrop:tl,onDragEnd:el,autoResize:!1,disableInputWhilePending:!1,contentClassName:Ka?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:gu,highlightedContent:_u,highlightRef:Fa,inputRef:Pi,textLayoutClassName:Y(Pb,Ka?Y(`h-full min-h-0`,zr?`py-2.5`:`py-4`):zr?`py-2.5`:`pt-4 pb-2`,g===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Ka&&`flex-1 min-h-0`),inputStyle:{flex:Ka?`1 1 auto`:`none`,height:!Ka&&fe?`${fe.height}px`:void 0,maxHeight:!Ka&&fe?`${fe.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":Ka?`100%`:fe?`${fe.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!Ka&&fe?`${fe.maxHeight}px`:`none`,borderTopLeftRadius:Ya,borderTopRightRadius:Ya},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,au,zr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,dl)),footerStyle:{borderBottomLeftRadius:Ya,borderBottomRightRadius:Ya},footerContent:yu,placeholder:Xa,onChange:(e,t)=>jc(t),textareaProps:{readOnly:Xr,onCompositionStart:()=>{Ii.current=!0},onCompositionEnd:e=>{Ii.current=!1;let t=e.currentTarget;Sc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Ac,onKeyDown:lc,onCopy:Fc,onCut:Ic,onPaste:Nc,onDragEnter:Zc,onDragOver:Qc,onDropCapture:nl,onDrop:tl,onDragEnd:el,onKeyUp:dc,onClick:()=>{dc()},onScroll:e=>{dc();let t=e.currentTarget.scrollTop;Fa.current&&(Fa.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Ii.current){Li.current=r;return}let i=Ov(n,r,[...Te(di,Vn.filter(Ne).map(e=>e.filename)),...Dv(di,so.keys()),...li.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Li.current=i.end):Li.current=n,dc()},onFocus:()=>{if(zr){if(Date.now()<Ke.current){let e=Pi.current;e&&e.blur();return}be.current!==null&&(window.clearTimeout(be.current),be.current=null),ye(!0)}},onBlur:e=>{if(Ii.current=!1,Li.current=e.currentTarget.selectionStart??Li.current,ru(),zr){if(Date.now()<nu.current){let e=Pi.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<nu.current&&document.activeElement!==e&&e.focus()},50);return}}if(Je.current=Date.now(),Ie()){ye(!1);return}be.current!==null&&window.clearTimeout(be.current),be.current=window.setTimeout(()=>{be.current=null,ye(!1)},120)}},autoCorrect:zr?`on`:`off`,autoCapitalize:zr?`sentences`:`off`,spellCheck:zr||$r,fillContainer:Ka,rows:1},children:[(0,$.jsx)(mh,{}),S&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ya},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:du,onClick:()=>sl(),title:u(`chat.chatInput.actions.attachFiles`),"aria-label":u(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(lu,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:u(w?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(Io,{ref:ea,searchQuery:F,directory:Yn,onCommandSelect:Gc,onClose:()=>P(!1),commandPolicy:Jl,commandContext:Qn,onRowsChange:Zl?ql:void 0,style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0}),U&&(0,$.jsx)(Yp,{ref:ta,searchQuery:K,directory:Yn,onSkillSelect:Uc,onClose:()=>W(!1),onRowsChange:Zl?ql:void 0,style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0}),ne&&(0,$.jsx)(Ko,{ref:na,searchQuery:ae,onSnippetSelect:Wc,onClose:()=>re(!1),style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(ts,{ref:Qi,searchQuery:k,onFileSelect:zc,onAgentSelect:Bc,onSessionSelect:Vc,onClose:()=>O(!1),onRowsChange:Zl?ql:void 0,style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),zr?(0,$.jsx)(ix,{radius:Ya,isMobile:zr,footerIconButtonClass:fu,footerPaddingClass:au,iconSizeClass:lu,sendIconSizeClass:su,onInsert:ic,onInsertAndSend:ac,onContentHeightChange:yc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),zr?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[vu,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!di.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:di.trim()?di:Za})]}):null]}),zr?(0,$.jsx)(rx,{className:`hidden`,composerTextareaRef:Pi,selectionAdapter:kr,mobilePanel:me,onMobilePanelChange:he}):null]}),Gn&&!Ua&&!zr&&!fl&&!Fl?(0,$.jsx)(I_,{onSubmit:rc,className:`chat-input-column mt-4`}):null]}),f.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Fb,{popup:f,onOpenChange:qr,isMobile:zr})}):null,(0,$.jsx)(p_,{open:So,onOpenChange:Co,mode:`select`,onSelect:e=>{Do(e),Ao(null)}}),(0,$.jsx)(g_,{open:wo,onOpenChange:To,onSelect:e=>{Ao(e),Do(null)}}),(0,$.jsx)(Zu,{open:or,onOpenChange:cr,projectDirectory:St??Yn??null,submitting:dr,onConfirm:Ha}),(0,$.jsx)(`input`,{ref:Q,type:`file`,multiple:!0,className:`hidden`,onChange:ul,accept:`*/*`}),(0,$.jsx)(`input`,{ref:rl,type:`file`,multiple:!0,className:`hidden`,onChange:ul,accept:`image/*`}),null,zr?(0,$.jsx)(_a,{id:`android-media-pick-sheet`,open:Ae,onOpenChange:e=>{e||je(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:u(`chat.chatInput.actions.addAttachment`)}),ariaLabel:u(`chat.chatInput.actions.addAttachment`),closeAriaLabel:u(`mobile.surface.closeAria`),resizeAriaLabel:u(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Ye.current=!1,je(!1),requestAnimationFrame(ll)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:u(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Ye.current=!1,je(!1),requestAnimationFrame(sl)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:u(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,zr&&pl&&ml?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(_a,{id:`mobile-draft-project-picker-sheet-${Fe}`,open:Me===`project`,onOpenChange:e=>{e||Pe(null)},ariaLabel:u(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:u(`mobile.surface.closeAria`),resizeAriaLabel:u(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(Va,{value:Le,onChange:e=>ze(e.target.value),placeholder:u(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(pa,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:rr.filter(e=>za(tx(e),Le)||za(e.path,Le)).map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{zl(e.id),Pe(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:Vl(e)}),e.id===ml.id?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground`}):null]},e.id))})}),(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-4 pt-1`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg border-t border-border/50 px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{Pe(null),gt.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},_x=e=>{let t=(0,Q.c)(3),n=Vm(),r=e.surface??n;if(r&&!r.active)return null;let i=r??void 0,a;return t[0]!==e||t[1]!==i?(a=(0,$.jsx)(gx,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};_x.displayName=`ChatInput`;var vx=Z.memo(_x);function yx(e){return e.preventDefault()}function bx(e){e.preventDefault()}function xx(e){return e.preventDefault()}function Sx(e){e.pointerType===`touch`&&e.preventDefault()}function Cx(e){e.preventDefault()}function wx(e){e.pointerType===`touch`&&e.preventDefault()}function Tx(){let e=(0,Q.c)(47),{t}=ct(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>go(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=J(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],Is(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await Gc(n),Br.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}Br.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=J(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Ie()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,disabled:i,onClick:C,children:[E,O]})})}),e[34]=i,e[35]=C,e[36]=E,e[37]=O,e[38]=k):k=e[38];let A;return e[39]!==d||e[40]!==s||e[41]!==S||e[42]!==k||e[43]!==b||e[44]!==x||e[45]!==_?(A=(0,$.jsx)(`div`,{ref:o,children:(0,$.jsx)(_a,{id:`image-save-actions-sheet`,open:s,onOpenChange:d,title:b,ariaLabel:_,closeAriaLabel:x,resizeAriaLabel:S,fitContent:!0,children:k})}),e[39]=d,e[40]=s,e[41]=S,e[42]=k,e[43]=b,e[44]=x,e[45]=_,e[46]=A):A=e[46],A}var Ex=(e,t)=>{if(t.length===0)return e;let n=new Map(t.map(e=>[e.info.id,e])),r=!1,i=e.map(e=>{if(Ji(e.parts))return e;let t=n.get(e.info.id);return t?(r=!0,t):e}),a=r?i:e,o=new Set(e.map(e=>e.info.id)),s=t.filter(e=>!o.has(e.info.id));return s.length===0?a:[...a,...s]},Dx=(e,t)=>{if(e.length===0)return!1;let n;for(let t of e){let e=t.info.time?.created;typeof e==`number`&&(n===void 0||e>n)&&(n=e)}return!t.resolvedSessionStatus||typeof t.sessionStatusObservedAt!=`number`||typeof n!=`number`||n>t.sessionStatusObservedAt},Ox=e=>{let t=e.boundary.kind===`exhausted`,n=e.boundary.kind===`has-more`,r=t&&!e.assistantComplete,i=n||r;return{complete:t&&e.assistantComplete,canLoadEarlier:i}},kx=e=>e.syncLoading||e.assistantLoading,Ax=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),jx=e=>e.isLoadingOlder,Mx=e=>!e.isMobile&&e.isLoadingOlder,Nx=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Px=e=>e.hasTranscriptShell||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,Fx=e=>{let{sessionId:t,messages:n,retained:r}=e;return t?n.length>0?{messages:n,retained:{sessionId:t,messages:n}}:r?.sessionId===t?{messages:r.messages,retained:r}:{messages:n,retained:null}:{messages:n,retained:null}},Ix=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Lx=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Rx=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,zx=e=>{let t=(0,Q.c)(8),{providerId:n,modelId:r,label:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3.5`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{role:`img`,"aria-label":i,className:`inline-flex size-3.5 shrink-0 items-center justify-center`,children:a}),t[1]=i,t[2]=o);let s;return t[3]!==i||t[4]!==r||t[5]!==n||t[6]!==o?(s=(0,$.jsx)(Ma,{modelId:r,providerId:n,alt:i,className:`size-3.5 shrink-0`,fallback:o}),t[3]=i,t[4]=r,t[5]=n,t[6]=o,t[7]=s):s=t[7],s},Bx=e=>{let t=(0,Q.c)(42),{t:n}=ct(),r=q(Vx),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Rx,i;t[0]===e?i=t[1]:(i=Y(`p-3`,e),t[0]=e,t[1]=i);let a;t[2]===n?a=t[3]:(a=n(`chat.container.readOnlySubagentPromptBanner`),t[2]=n,t[3]=a);let o;t[4]===a?o=t[5]:(o=(0,$.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-[var(--surface-background)] px-4 py-3 text-muted-foreground ${Lx}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,s;t[11]!==e.agentName||t[12]!==o?(s=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=s):s=t[13];let c=s,l=e.modelName||o,u;t[14]===n?u=t[15]:(u=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=u);let d=`${u}: ${c}`,f;t[16]===n?f=t[17]:(f=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=f);let p=`${f}: ${l}`,m=r&&Rx,h;t[18]===m?h=t[19]:(h=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] p-3`,m),t[18]=m,t[19]=h);let g=r&&`oc-mobile-readonly-prompt-surface`,_;t[20]===g?_=t[21]:(_=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,g),t[20]=g,t[21]=_);let v;t[22]===n?v=t[23]:(v=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=v);let y;t[24]===v?y=t[25]:(y=(0,$.jsx)(`div`,{className:`text-muted-foreground ${Lx}`,children:v}),t[24]=v,t[25]=y);let b;t[26]!==d||t[27]!==c||t[28]!==p||t[29]!==l||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(b=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(la,{name:e.agentName,size:14,label:d}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:c,children:c})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(zx,{providerId:e.providerId,modelId:e.modelId,label:p}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:l,children:l})]})]}):null,t[26]=d,t[27]=c,t[28]=p,t[29]=l,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=b):b=t[34];let x;t[35]!==b||t[36]!==_||t[37]!==y?(x=(0,$.jsxs)(`div`,{className:_,children:[y,b]}),t[35]=b,t[36]=_,t[37]=y,t[38]=x):x=t[38];let S;return t[39]!==x||t[40]!==h?(S=(0,$.jsx)(`aside`,{className:h,children:x}),t[39]=x,t[40]=h,t[41]=S):S=t[41],S};function Vx(e){return e.isMobile}var Hx=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ct(),{currentTheme:n}=Ga(),r=Pt(Ux),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Xa,{width:140,height:140,className:`opacity-20`}),e[0]=a):a=e[0];let o;return e[1]!==r||e[2]!==t||e[3]!==i?(o=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-full w-full gap-6`,children:[a,r?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 max-w-md text-center px-4`,children:[(0,$.jsx)(`span`,{className:`typography-markdown font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`typography-meta`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`typography-markdown`,style:{color:i},children:t(`chat.emptyState.startNewChat`)})]}),e[1]=r,e[2]=t,e[3]=i,e[4]=o):o=e[4],o});function Ux(e){return e.error}var Wx=class e{static instance;sessionStartTimes=new Map;seenMessageIds=new Set;messageCreationTimes=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}recordSessionStart(e){this.sessionStartTimes.set(e,Date.now())}getSessionStartTime(e){return this.sessionStartTimes.get(e)}shouldAnimateMessage(e,t){if(e.role!==`assistant`||this.seenMessageIds.has(e.id))return!1;let n=this.sessionStartTimes.get(t);if(!n)return this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created),!1;let r=e.time.created>n-5e3;return r||(this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created)),r}clearSession(e){this.sessionStartTimes.delete(e)}hasSessionTiming(e){return this.sessionStartTimes.has(e)}hasBeenAnimated(e){return this.seenMessageIds.has(e)}markMessageAsAnimated(e,t){this.seenMessageIds.add(e),this.messageCreationTimes.set(e,t)}clearAll(){this.sessionStartTimes.clear(),this.seenMessageIds.clear(),this.messageCreationTimes.clear()}getDebugInfo(){return{sessionStartTimes:new Map(this.sessionStartTimes),seenMessageIds:new Set(this.seenMessageIds),messageCreationTimes:new Map(this.messageCreationTimes)}}},Gx=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:xt(t)},Kx=Z.memo(e=>{let t=(0,Q.c)(31),{isUser:n,isMobile:r,providerID:i,modelID:a,agentName:o,modelName:s,variant:c}=e,l;t[0]!==r||t[1]!==n||t[2]!==c?(l=!n&&!r?Gx(c):null,t[0]=r,t[1]=n,t[2]=c,t[3]=l):l=t[3];let u=l,d=s||`Assistant`,f,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=Y(`mb-1.5`),p=Y(`flex items-center justify-between gap-2`),t[4]=f,t[5]=p):(f=t[4],p=t[5]);let m;t[6]!==o||t[7]!==n||t[8]!==a||t[9]!==i?(m=(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:n?(0,$.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-primary/10 flex items-center justify-center`,children:(0,$.jsx)(X,{name:`user-3`,className:`h-4 w-4 text-primary`})}):(0,$.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,$.jsx)(Ma,{modelId:a,providerId:i,className:`h-4 w-4`,fallback:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-4 w-4`,style:{color:`var(${na(o).var})`}})})})}),t[6]=o,t[7]=n,t[8]=a,t[9]=i,t[10]=m):m=t[10];let h=n?`text-primary`:`text-foreground`,g;t[11]===h?g=t[12]:(g=Y(`inline-flex min-w-0 items-center gap-1.5 font-semibold typography-ui-header tracking-tight leading-tight`,h),t[11]=h,t[12]=g);let _=n?`You`:d,v;t[13]===_?v=t[14]:(v=(0,$.jsx)(`span`,{className:`truncate`,children:_}),t[13]=_,t[14]=v);let y;t[15]===u?y=t[16]:(y=u?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-normal leading-tight text-muted-foreground`,children:u}):null,t[15]=u,t[16]=y);let b;t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsxs)(`h3`,{className:g,children:[v,y]}),t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20];let x;t[21]!==o||t[22]!==r||t[23]!==n?(x=!n&&o&&(0,$.jsxs)(`div`,{className:Y(`agent-badge inline-flex items-center gap-1 cursor-default rounded font-normal leading-tight`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,na(o).class),children:[(0,$.jsx)(la,{name:o,size:10}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=r,t[23]=n,t[24]=x):x=t[24];let S;t[25]!==b||t[26]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b,x]}),t[25]=b,t[26]=x,t[27]=S):S=t[27];let C;return t[28]!==S||t[29]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m,S]})})}),t[28]=S,t[29]=m,t[30]=C):C=t[30],C}),qx=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,Jx=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,Yx=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),Xx=(e,t)=>e.split(Jx).map((e,n)=>n%2==1?e:t(e)).join(``),Zx=e=>Xx(e,e=>e.replace(/ *\n/g,`
|
|
6537
|
-
`)),Qx=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=Xx(e,Yx);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${Sc(t.name)})`;i=i.replace(t.token,e)}i=i.replace(qx,(e,t,r)=>n.has(r)?`${t}[/${r}](${yc(r)})`:e)}return Zx(i)},$x=e=>(qx.lastIndex=0,qx.test(e)||e.includes(`[skill:`)),eS=e=>e===`markdown`?`markdown`:`plain`,tS=e=>{if(typeof window>`u`)return!1;let t=window.getSelection();if(!t||t.isCollapsed||t.rangeCount===0)return!1;let n=t.getRangeAt(0);return e.contains(n.startContainer)||e.contains(n.endContainer)},nS=Z.memo(({part:e,messageId:t,agentMention:n,messageParts:r})=>{let i=e,a=i.text,o=typeof a==`string`?a:i.content||i.value||``,[s,c]=Z.useState(!1),[l,u]=Z.useState(!1),d=q(e=>e.userMessageRenderingMode),f=q(e=>e.collapsibleUserMessages),p=pc(),m=Ei({directory:p,enabled:$x(o)}),h=Z.useMemo(()=>m.data??[],[m.data]),g=q(e=>e.openContextFile),{t:_}=ct(),v=eS(d),y=f&&!s,b=Z.useRef(null),x=Z.useMemo(()=>new Map(h.map(e=>[e.name,e])),[h]),S=Z.useMemo(()=>zf(r,o),[r,o]),C=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!Wn(t))continue;let n=t.text;if(typeof n==`string`)for(let t of cr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of fi()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${B}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),w=J(e=>{let t=x.get(e),n=typeof t?.path==`string`?t.path:``,r=xo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=p||vo(``,i)||`/`,o=()=>{g(a,i)};if(p&&!wo(i,p)){mc(i,p).then(o);return}o()});Z.useEffect(()=>{let e=b.current;if(!e)return;let t=()=>{f&&!s&&u(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[f,o,s]),Z.useEffect(()=>{f||(c(!1),u(!1))},[f]);let T=J(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??gc(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),w(n);return}let r=b.current;r&&(tS(r)||f&&!s&&l&&c(!0))}),E=J(e=>{e.stopPropagation(),c(!1)}),D=Z.useMemo(()=>Nf(o,{skillNames:new Set(x.keys()),citationIcons:S.icons,citationDisplayNames:S.displayNames,sessionMentions:C,agentNames:n?.name?new Set([n.name.toLowerCase(),n.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),[n,S,C,x,o]),O=Z.useMemo(()=>Qx({textContent:o,agentMention:n,skillNames:new Set(x.keys()),decorateInlineReferences:!D}),[n,D,x,o]),k=(e,t)=>{if(!e)return null;if(v===`markdown`){let n=Qx({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(Ns,{content:n,className:Y(`inline w-auto align-baseline [&_.markdown-content]:contents [&_.markdown-content_p]:inline [&_[data-markdown-size-spacer]]:inline`,`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,y&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1},t)}return(0,$.jsx)(Z.Fragment,{children:e},t)},A=e=>e.map((e,t)=>e.type===`text`?k(e.text,`text-${t}`):(0,$.jsx)(Vf,{decoration:e.decoration,onOpenSkill:w},`ref-${t}-${e.span.start}`)),j=Z.useMemo(()=>{if(D)return A(D);let e=[],t=0,r=!1,i;for(qx.lastIndex=0;(i=qx.exec(o))!==null;){let n=i[1]||``,r=i[2],a=i.index+n.length;x.has(r)&&(i.index>t&&e.push(o.slice(t,i.index)),n&&e.push(n),e.push((0,$.jsxs)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:e=>{e.stopPropagation(),w(r)},children:[`/`,r]},`skill-${a}-${r}`)),t=a+r.length+1)}t<o.length&&e.push(o.slice(t));let a=e.length>0?e:[o];return!n?.token||!o.includes(n.token)?a:a.flatMap((e,t)=>{if(r||typeof e!=`string`)return e;let i=e.indexOf(n.token);return i===-1?e:(r=!0,[e.slice(0,i),(0,$.jsx)(`a`,{href:hc(n.name),className:`text-primary hover:underline`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:n.token},`agent-${t}`),e.slice(i+n.token.length)])})},[n,w,D,A,x,o]);return!o||o.trim().length===0?null:(0,$.jsxs)(`div`,{className:`relative`,children:[f&&s&&(0,$.jsx)(`button`,{type:`button`,onClick:E,className:`absolute top-0 right-0 z-10 flex items-center justify-center rounded-sm bg-[var(--surface-elevated)] p-0.5 text-[var(--surface-mutedForeground)] hover:text-[var(--surface-foreground)] hover:bg-[var(--interactive-hover)] transition-colors`,"aria-label":_(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,s&&`pb-3`,v===`plain`&&`whitespace-pre-wrap`,y&&`line-clamp-10`,f&&l&&!s&&`cursor-pointer`),ref:b,onClick:T,children:v===`markdown`?D?A(D):(0,$.jsx)(Ns,{content:O,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,y&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1}):j})]},e.id||`${t}-user-text`)}),rS=[{variant:`static`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:t,children:e})},{variant:`generate-effect`,component:({children:e,className:t,...n})=>{if(e==null)return null;let r=typeof e==`string`?e:typeof e==`number`?String(e):Array.isArray(e)?e.map(e=>typeof e==`string`||typeof e==`number`?String(e):``).join(``):``;return r?(0,$.jsx)(`span`,{className:Y(`inline-block align-baseline`,t),children:r.split(``).map((e,t)=>(0,Z.createElement)(el.span,{...n,key:e+String(t),className:Y(`inline-block whitespace-pre align-baseline`),initial:{opacity:0},animate:{opacity:1},transition:{ease:`easeOut`,duration:.14,delay:Math.min(t*.0045,.14)}},e))}):null}},{variant:`glitch`,component:({children:e,className:t,...n})=>(0,$.jsxs)(`div`,{className:`group relative overflow-hidden font-medium`,children:[(0,$.jsx)(`span`,{...n,className:Y(`invisible`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 text-primary-muted transition-transform duration-500 ease-in-out`,`group-hover:-translate-y-full hover:duration-300`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 translate-y-full text-primary-muted transition-transform duration-500`,`ease-in-out hover:duration-300 group-hover:translate-y-0`,t),children:e})]})},{variant:`hover-enter`,component:({children:e,className:t,...n})=>{if(typeof e!=`string`)return null;let r=.25,i=.025,a=e.split(``).map(e=>e===` `?`\xA0`:e);return(0,$.jsxs)(el.span,{...n,className:Y(`relative block select-none overflow-hidden whitespace-nowrap text-primary-muted`,t),initial:`initial`,whileHover:`hovered`,style:{lineHeight:.9},children:[(0,$.jsx)(`div`,{children:a.map((e,t)=>(0,$.jsx)(el.span,{className:`inline-block`,variants:{initial:{y:0},hovered:{y:`-100%`}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0`),children:a.map((e,t)=>(0,$.jsx)(el.span,{className:`inline-block`,variants:{initial:{y:`100%`},hovered:{y:0}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))})]})}},{variant:`shake`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted hover:animate-text-shake`,t),children:e})},{variant:`hover-decoration`,component:({children:e,className:t,...n})=>(0,$.jsx)(`div`,{className:Y(`relative after:absolute after:bottom-0 after:left-0 after:h-px after:w-full after:origin-bottom-right`,`after:scale-x-0 after:bg-primary-muted after:transition-transform after:duration-300 after:ease-in-out hover:after:origin-bottom-left hover:after:scale-x-100`),children:(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted`,t),children:e})})}];function iS(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({variant:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`static`:i,o;t[4]===a?o=t[5]:(o=rS.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||rS[0].component,c;return t[6]!==s||t[7]!==n||t[8]!==r?(c=(0,$.jsx)(s,{...r,className:n}),t[6]=s,t[7]=n,t[8]=r,t[9]=c):c=t[9],c}var aS=e=>{let t=`h-3.5 w-3.5 flex-shrink-0`,n=`h-[13px] w-[13px] flex-shrink-0`,r=e.toLowerCase();return r===`edit`||r===`multiedit`||r===`apply_patch`||r===`str_replace`||r===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil`,className:n}):r===`write`||r===`create`||r===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:n}):r===`read`||r===`view`||r===`file_read`||r===`cat`?(0,$.jsx)(X,{name:`file-text`,className:t}):r===`bash`||r===`shell`||r===`cmd`||r===`terminal`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):r===`list`||r===`ls`||r===`dir`||r===`list_files`?(0,$.jsx)(X,{name:`folder-6`,className:t}):r===`search`||r===`grep`||r===`find`||r===`ripgrep`?(0,$.jsx)(X,{name:`menu-search`,className:t}):r===`glob`?(0,$.jsx)(X,{name:`file-search`,className:t}):r===`fetch`||r===`curl`||r===`wget`||r===`webfetch`||r===`web-search`||r===`websearch`||r===`search_web`||r===`codesearch`||r===`google`||r===`bing`||r===`duckduckgo`||r===`perplexity`?(0,$.jsx)(X,{name:`global`,className:t}):r===`todowrite`||r===`todoread`?(0,$.jsx)(X,{name:`list-check-3`,className:t}):r===`structuredoutput`||r===`structured_output`?(0,$.jsx)(X,{name:`list-check-2`,className:t}):r===`skill`?(0,$.jsx)(X,{name:`book`,className:t}):r===`task`?(0,$.jsx)(X,{name:`ai-agent`,className:t}):r===`question`?(0,$.jsx)(X,{name:`survey`,className:t}):r===`lsp`?(0,$.jsx)(X,{name:`scan-2`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},oS=new Map,sS=e=>{let t=oS.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return oS.set(e,n),n},cS=(e,t)=>{let n=sS(e);return n.subscribers.add(t),t(Date.now()),n.timerId===null&&typeof window<`u`&&(n.timerId=window.setInterval(()=>{let e=Date.now();n.subscribers.forEach(t=>{t(e)})},e)),()=>{let n=oS.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),oS.delete(e)))}},lS=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(uS),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return cS(r,a)},s=[e,r],n[0]=e,n[1]=r,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),i};function uS(){return Date.now()}var dS=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],fS=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},pS=e=>{if(!e||typeof e!=`object`)return;let t=e;return fS(t.sessionId)??fS(t.sessionID)},mS=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>e?.type!==`subtask`||e.taskSessionID===t?e:(n=!0,{...e,taskSessionID:t}));return n?r:e},hS=e=>{if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){t.push({tool:`tool`,state:{status:`completed`,title:n}});continue}if(!n||typeof n!=`object`)continue;let e=n;t.push({id:typeof e.id==`string`?e.id:void 0,tool:typeof e.tool==`string`?e.tool:`tool`,state:{status:typeof e.state?.status==`string`?e.state.status:typeof e.status==`string`?e.status:void 0,title:typeof e.state?.title==`string`?e.state.title:typeof e.title==`string`?e.title:void 0,input:e.state?.input&&typeof e.state.input==`object`?e.state.input:void 0}})}return t},gS=e=>{if(typeof e!=`string`||e.trim().length===0)return{summaryEntries:[]};let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);if(!t?.[1])return{summaryEntries:[]};try{let e=JSON.parse(t[1].trim());return{sessionId:fS(e.sessionId)??fS(e.sessionID),status:fS(e.status),summaryEntries:hS(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},_S=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=gS(e);if(t.sessionId)return t.sessionId;let n=e.match(/task_id\s*:\s*([^\s<"']+)/i),r=e.match(/session[_\s-]?id\s*:\s*([^\s<"']+)/i);return fS((n?.[1]??r?.[1])||dS(e))},vS=e=>{if(!(!e||typeof e!=`object`))return fS(e.status)},yS=/"status"\s*:\s*"running"/i,bS=/\bstatus\s*[:=]\s*["'`]?running\b/i,xS=e=>{if(typeof e!=`string`||e.trim().length===0)return!1;let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);return t?.[1]&&yS.test(t[1])?!0:bS.test(e)},SS=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,CS=(e,t)=>fS(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),wS=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},TS=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(SS);if(!t)return;let n=CS(t[1],`sessionID`)??CS(t[1],`sessionId`),r=wS(CS(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:CS(t[1],`description`),body:t[2].trim()}},ES=new WeakMap,DS=e=>{let t=ES.get(e);if(t)return t;let n=[];if(e.info.role===`assistant`)for(let t of e.parts){if(t.type!==`tool`)continue;let e=t.tool?.trim().toLowerCase();if(!e||e===`task`||e===`todowrite`||e===`todoread`)continue;let r=t.state;n.push({id:t.id,tool:t.tool,state:{status:r?.status,title:r?.title,input:r?.input&&typeof r.input==`object`?r.input:void 0}})}return ES.set(e,n),n},OS=e=>{let t=[];for(let n of e)t.push(...DS(n));return t},kS=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),AS=[`summary`,`changes`,`verification`],jS={summary:`Summary`,changes:`Changes`,verification:`Verification`},MS=/<(summary|changes|verification)(?:\s[^>]*)?>/i,NS=()=>RegExp(`<(${AS.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),PS=e=>typeof e!=`string`||e.length===0?!1:MS.test(e),FS=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!PS(e)?e:e.replace(NS(),(e,t,n)=>{let r=jS[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),IS=e=>FS(kS(e)),LS=e=>{if(!e.isTaskTool)return{isDelegating:!1,showAvatar:!1,title:e.displayName};let t=e.taskAgentName?e.formatName(e.taskAgentName):void 0,n=!!(e.taskSessionId||t);return!e.isFinalized&&!n?{isDelegating:!0,showAvatar:!1,title:e.delegatingLabel}:{isDelegating:!1,showAvatar:n,title:t??e.displayName}};function RS(e){if(!e.isTaskTool||e.isFinalized)return!1;let t=e.taskSessionId?e.childSessionStatus:e.parentSessionStatus;if(t){if(t.type!==`idle`)return!1;if(typeof e.taskStartedAt==`number`&&typeof e.statusObservedAt==`number`&&e.taskStartedAt<=e.statusObservedAt)return!0}return typeof e.taskStartedAt==`number`&&typeof e.statusSnapshotAt==`number`&&e.taskStartedAt<=e.statusSnapshotAt}var zS=(e,t)=>{if(e===t)return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;let n=e,r=t;return n.input===r.input&&n.output===r.output&&n.reasoning===r.reasoning&&n.cache?.read===r.cache?.read&&n.cache?.write===r.cache?.write},BS=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},VS=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},HS=e=>e?.state,US=e=>e?.metadata,WS=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},GS=e=>{let t=e;return t?[typeof t.text==`string`?t.text:``,typeof t.content==`string`?t.content:``,typeof t.value==`string`?t.value:``].reduce((e,t)=>t.length>e.length?t:e,``):``},KS=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.type!==i.type||BS(r)!==BS(i))return!1;if(r.type===`tool`){if(HS(r)!==HS(i)||US(r)!==US(i)||VS(r)!==VS(i))return!1;let e=WS(r),t=WS(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=WS(r),o=WS(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(GS(r)!==GS(i))return!1;let e=r.shellAction,t=i.shellAction;if((e||t)&&(e?.command!==t?.command||e?.output!==t?.output||e?.status!==t?.status))return!1}}return!0},qS=(e,t)=>e===t||e.id===t.id&&e.role===t.role&&e.sessionID===t.sessionID&&e.finish===t.finish&&e.status===t.status&&e.mode===t.mode&&e.agent===t.agent&&e.providerID===t.providerID&&e.modelID===t.modelID&&e.variant===t.variant&&e.clientRole===t.clientRole&&e.userMessageMarker===t.userMessageMarker&&(e.time?.created??null)===(t.time?.created??null)&&(e.time?.completed??null)===(t.time?.completed??null)&&zS(e.tokens,t.tokens),JS=(e,t)=>qS(e.info,t.info)&&KS(e.parts,t.parts),YS=(e,t)=>!e||!t?e===t:JS(e,t),XS=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,ZS=(e,t)=>{if(e===t)return!0;if(!e||!t)return!e&&!t;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.file!==i.file||r.additions!==i.additions||r.deletions!==i.deletions)return!1}return!0},QS=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&KS([e.part],[t.part]),$S=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.messageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.messageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!QS(a,o))return!1;r+=1,i+=1}},eC=(e,t)=>{if(e.id!==t.id||e.anchorMessageId!==t.anchorMessageId||e.afterToolPartId!==t.afterToolPartId||e.parts.length!==t.parts.length)return!1;for(let n=0;n<e.parts.length;n+=1)if(!QS(e.parts[n],t.parts[n]))return!1;return!0},tC=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),nC=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.anchorMessageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.anchorMessageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!eC(a,o))return!1;r+=1,i+=1}},rC=(e,t,n,r)=>{if(e===t)return!0;if(!e||!t)return e===t;if(r)return!0;if(e.isGroupExpanded!==t.isGroupExpanded||e.turnId!==t.turnId||e.isFirstAssistantInTurn!==t.isFirstAssistantInTurn||e.isLastAssistantInTurn!==t.isLastAssistantInTurn||e.isLatestTurn!==t.isLatestTurn||e.isWorking!==t.isWorking||e.isTurnSettled!==t.isTurnSettled||e.hasTools!==t.hasTools||e.hasReasoning!==t.hasReasoning||e.userMessageCreatedAt!==t.userMessageCreatedAt||e.userMessageVariant!==t.userMessageVariant||(e.headerMessageId===n||t.headerMessageId===n)&&e.headerMessageId!==t.headerMessageId)return!1;let i=e.activityOwnerMessageId===n||t.activityOwnerMessageId===n;if(i&&e.activityOwnerMessageId!==t.activityOwnerMessageId||!$S(e.activityParts,t.activityParts,n)||!nC(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=tC(e.activityGroupSegments,n)||tC(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!XS(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!ZS(e.changedFiles,t.changedFiles))},iC=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,aC=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,oC=/(?=^diff --git\s+)/gm,sC=/^diff --git\s+/m,cC=/(?=^---\s+\S)/gm,lC=/^---\s+\S/m,uC=e=>typeof e==`object`&&!!e,dC=e=>e.replace(/\r\n/g,`
|
|
6534
|
+
`)?`${t}\n`:`${t}\n\n`}`,mx=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},hx=(e,t,n,r)=>t?d({transportIdentity:e},t):n?u({transportIdentity:e},n):r,gx=[],_x=({onOpenSettings:e,scrollToBottom:n,showScrollToBottom:o=!1,onScrollToBottom:s,submissionBlocked:c=!1,surface:l})=>{let{t:u}=ct(),d=Cs(),[f,m]=Z.useState({open:!1,title:``,content:``}),[g,x]=Z.useState(`normal`),[S,C]=Z.useState(!1),[w,T]=Z.useState(!1),[D,O]=Z.useState(!1),[k,A]=Z.useState(``),[M,P]=Z.useState(!1),[F,L]=Z.useState(``),[U,W]=Z.useState(!1),[K,te]=Z.useState(``),[ne,re]=Z.useState(!1),[ae,oe]=Z.useState(``),[ce,le]=Z.useState([]),[ue,de]=Z.useState(0),[fe,pe]=Z.useState(null),[me,he]=Z.useState(null),ge=Z.useRef(null),_e=Z.useRef(null),[ve,ye]=Z.useState(!1),be=Z.useRef(null);Z.useEffect(()=>()=>{be.current!==null&&window.clearTimeout(be.current),ge.current!==null&&window.clearTimeout(ge.current),_e.current!==null&&window.clearTimeout(_e.current)},[]);let[we,Oe]=Z.useState(!1),[Ae,je]=Z.useState(!1),[Me,Pe]=Z.useState(null),Fe=Z.useId(),[Le,ze]=Z.useState(``),[Be,Ve]=Z.useState(``),[He,Ue]=Z.useState(!1),[We,Ge]=Z.useState(!1),Ke=Z.useRef(0),qe=Z.useCallback(()=>{Ke.current=Date.now()+500},[]),Je=Z.useRef(0),Ye=Z.useRef(!1),[Xe,Ze]=Z.useState(-1),Qe=Z.useRef(()=>{}),$e=Z.useRef((...e)=>Promise.resolve().then(()=>ri.getState().sendMessage(...e))).current,et=ri(e=>e.currentSessionId),tt=Ai(e=>e.currentProviderId),nt=Ai(e=>e.currentModelId),rt=Ai(e=>e.currentAgentName),it=Ai(e=>e.currentVariant),at=Ai(e=>e.providers),ot=Ai(e=>e.agents),lt=Ai(e=>e.getVisibleAgents),ut=Z.useMemo(()=>Am(lt()),[lt,ot]),dt=Ai(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ft=Ai(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),mt=Z.useMemo(()=>{let e=at.find(e=>e.id===tt)?.models?.find(e=>e.id===nt);return Lm(e)},[nt,tt,at]),ht=Se(e=>e.currentDirectory),vt=pc()??ht,{ensureSessionRenderable:yt}=ku(),St=ri(Z.useCallback(e=>et?e.getDirectoryForSession(et):null,[et])),Ct=fr(et??``,St??void 0),wt=Z.useMemo(()=>nb(Ct),[Ct]),Et=Z.useMemo(()=>rb(Ct),[Ct]),Dt=Mi(et??``,St??void 0).renderable,Ot=_t(et,St??void 0),kt=Ot?.agent,At=Ot?.model?.id,jt=Ot?.model?.providerID,Mt=Ot?.model?.variant,Nt=Ai(e=>e.activeDirectoryKey),Pt=Z.useRef(0),It=Z.useRef(null),Vt=Z.useRef(null),Ht=ri(e=>e.newSessionDraft),Gt=!!Ht?.open,Kt=ri(e=>e.newSessionDraft.draftSubmitting??!1),Jt=ri(e=>e.newSessionDraft.draftEstablishing??!1),Yt=Kt||Jt,Xt=ri(e=>e.openNewSessionDraft),Qt=ri(e=>e.setDraftPermissionAutoAcceptEnabled),en=Fn(e=>e.autoAccept),tn=Fn(e=>e.saving),nn=Fn(e=>e.setSessionAutoAccept),rn=ri(e=>e.setNewSessionDraftTarget),on=ri(e=>e.availableWorktreesByProject),sn=ri(e=>e.abortPromptSessionId),cn=ri(e=>e.clearAbortPrompt),ln=ei(e=>e.consumePendingInputText),dn=ei(e=>e.pendingPresetSubmit),fn=ei(e=>e.pendingInputText),hn=ei(e=>e.pendingInputMode),gn=ei(e=>e.consumePendingSyntheticParts),_n=ei(e=>e.activeAttachmentDraft),vn=Fu(Z.useCallback(e=>{let t=et??(Gt?`draft`:``);return t?e.drafts[t]??Rb:Rb},[Gt,et])),bn=sr(et??``),Cn=Z.useSyncExternalStore(t,r,r),wn=_n?.transportIdentity??null,Tn=_n?.owner.kind??null,En=_n?.owner.ownerID??null,Dn=Z.useMemo(()=>hx(Cn,et,Ht.draftID,wn&&Tn&&En?{transportIdentity:wn,owner:{kind:Tn,ownerID:En}}:null),[En,Tn,wn,Cn,et,Ht.draftID]),On=Dn?ie(Dn):null,kn=ei(Z.useCallback(e=>On?e.draftAttachmentViews[On]:void 0,[On])),An=ei(Z.useCallback(e=>On?e.drafts[On]:void 0,[On])),jn=Z.useMemo(()=>{if(!An||!kn)return gx;let e=An.attachments.flatMap(e=>{let t=kn[e.attachmentRefID];return t?[t]:[]});return e.length===0?gx:e},[kn,An]);Z.useEffect(()=>{Dn&&ei.getState().hydrateDraftAttachments(Dn)},[Dn]);let Mn=Hm(),Nn=q(e=>e.activeMainTab===`chat`),Pn=Fi(et??``,vt??void 0),In=Um({kind:`primary`,surfaceID:`primary`,active:Nn,sessionID:et,directory:vt??null,activity:{phase:Pn?.type===`busy`?`busy`:Pn?.type===`retry`?`retry`:`idle`,canAbort:Pn?.type===`busy`||Pn?.type===`retry`},draftKey:Dn,transportIdentity:Cn,runtimeGeneration:i(),selection:{value:{providerID:tt,modelID:nt,agent:rt,variant:it},catalog:{providers:at,agents:ut,variants:mt,variantsReady:!dt,ready:!dt&&!ft,loading:dt||ft},flush:async()=>{let e=ri.getState().currentSessionId;if(!e)return;let t=i(),n=r(),a=Pt.current,o=e,s=ri.getState().getDirectoryForSession(o)??null,c=wr(s);if(Ai.getState().activeDirectoryKey!==c&&await Ai.getState().activateDirectory(s),i()!==t||r()!==n||ri.getState().currentSessionId!==o||Ai.getState().activeDirectoryKey!==c||Pt.current!==a)return;await yt(o,{directory:s??void 0});let l=ri.getState().getDirectoryForSession(o)??null,u=wr(l);if(i()!==t||r()!==n||ri.getState().currentSessionId!==o||l!==s||u!==c||Ai.getState().activeDirectoryKey!==c||Pt.current!==a)return;let d=Ai.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=ur(o,l??void 0),m=nb(p),h=rb(p);if(Yy({editRevision:a,pinnedHistoryMessageId:It.current,latestHistoryMessageId:m?.id??null}))return;let g=Zi.getState(),_=fi().get(o),v=Ky({sessionId:o,latestUserChoice:m,latestExecution:h,catalog:f,memory:g,sessionEntity:_?.model?{agent:_.agent,model:{id:_.model.id,providerID:_.model.providerID,variant:_.model.variant}}:_?.agent?{agent:_.agent}:null,fallbackAgentName:d.currentAgentName});if(!v)return;let y=[o,v.source,v.messageId??``,v.agent??``,v.providerID,v.modelID,v.variant??``,c].join(`|`);Vt.current!==y&&(qy(v,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:o,memory:g}),Vt.current=y)},change:async e=>{Pt.current+=1;let t=ri.getState().currentSessionId;if(t){let e=ri.getState().getDirectoryForSession(t)??void 0,n=nb(ur(t,e));It.current=n?.id??null}else It.current=null;let n=Ai.getState();By(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:Zi.getState()})}},resources:{attachments:jn,addAttachment:async e=>{Dn&&await xn(Dn,()=>ei.getState()).addLocal(e)},removeAttachment:async e=>Dn?xn(Dn,()=>ei.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>Dn?xn(Dn,()=>ei.getState()).clearRootAttachments():!1,restoreAttachments:async e=>Dn?xn(Dn,()=>ei.getState()).restoreRootAttachments(e):!1,pendingInput:fn===null?null:{text:fn,mode:hn},consumePendingInput:ln,pendingPreset:dn,consumePendingPreset:()=>ei.getState().consumePendingPresetSubmit(),consumeSyntheticParts:gn,restoreSyntheticParts:e=>ei.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:vn,removeInlineDraft:e=>{let t=et??(Gt?`draft`:``);t&&Fu.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=et??(Gt?`draft`:``);!t||e.length===0||Fu.setState(n=>{let r=n.drafts[t]??[],i=new Set(e.map(e=>e.id));return{drafts:{...n.drafts,[t]:[...e,...r.filter(e=>!i.has(e.id))]}}})},history:bn,captureRuntime:()=>ei.getState().captureDraftRuntime(),getDraft:e=>ei.getState().getDraft(e),abortPrompt:{sessionID:sn,clear:cn}},backend:{send:e=>{Iy(e,{transportIdentity:r(),runtimeGeneration:i()});let t=Ly(e);return $e(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Xi(e.sessionID??``,{delivery:e.options?.delivery===`steer`?`steer`:void 0,queueItemID:e.queueItemID,manual:e.manual,scope:e.queueScope?{state:`bound`,...e.queueScope}:void 0}),create:async()=>Xt(),compact:async e=>De.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Ft(e.sessionID),Jr(e.sessionID??``))},shortcuts:{cycle:e=>Qe.current(e),new:()=>Xt(),abort:()=>(et&&Ft(et),Jr(et??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),Ln=Wm(In,l??Mn);Gm(Ln),Z.useLayoutEffect(()=>{if(!Ln.active){Fy(Ln.surfaceID);return}return Py(Ln),()=>Fy(Ln.surfaceID)},[Ln]);let Rn=zy(Ln),zn=Ln.resources??(Ln.kind===`primary`?In.resources:void 0);if(!zn)throw Error(`chat-input-surface-resources-incomplete`);let Vn=[...zn.attachments],Hn=Ln.sessionID,Wn=Km(Ln,Yt),Gn=Ln.kind===`secondary`?Ln.commands.hasNewDraft:Gt,qn=Gn,Yn=Ln.directory??vt,Xn=Ln.draftKey??Dn,Qn=Z.useMemo(()=>{if(Ln.kind===`secondary`)return Jm(Ln,!1,!1);let e=Hn?Yb(Hn,St??void 0):!1;return Jm(Ln,e,Gn)},[Ln,Hn,St,Gn]),er=(e,t,n,r,i,a,o,s,c,l)=>Rn?Rn.send({providerID:t,modelID:n,agent:r,variant:s,text:e,attachments:i,agentMention:a,parts:o,systemContext:o?.filter(e=>e.synthetic).map(e=>({text:e.text,synthetic:!0})),inputMode:c,options:l}):Promise.reject(Error(`chat-input-surface-incomplete`)),nr=Z.useCallback(()=>Rn?Rn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[Rn]),rr=gr(e=>e.projects),ir=gr(e=>e.activeProjectId),ar=gr(e=>e.setActiveProjectIdOnly),[or,cr]=Z.useState(!1),[dr,mr]=Z.useState(!1),hr=Z.useMemo(()=>Hn?Tt({autoAccept:en,sessions:[],sessionById:fi(),sessionID:Hn}):Ht.permissionAutoAcceptEnabled===!0,[Hn,Ht.permissionAutoAcceptEnabled,en]),_r=Ai(e=>e.agents),vr=Ln.kind===`secondary`?Ln.selection.value.agent:rt,yr=Ln.kind===`secondary`?Am(Ln.selection.catalog?.agents):_r,br=se()||Dy(yr,vr),xr=Z.useCallback(()=>{Br.error(u(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[u]),Sr=Ln.selection.value,Er=Ln.selection.change,Or=Ln.selection.catalog,kr=Z.useMemo(()=>({selection:{providerID:Sr.providerID??``,modelID:Sr.modelID??``,agent:Sr.agent??null,variant:Sr.variant},onChange:async e=>{if(!Er)throw Error(`chat-input-surface-selection-readonly`);await Er({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!Ln.active,catalog:Or}),[Or,Er,Sr.agent,Sr.modelID,Sr.providerID,Sr.variant,Ln.active]);Z.useEffect(()=>{Pt.current=0,It.current=null,Vt.current=null},[et]),Z.useEffect(()=>{if(Ln.kind!==`primary`||!et||dt||ft||at.length===0||ut.length===0)return;let e=wr(St);if(Nt!==e)return;let t=Zi.getState(),n={providers:at,agents:ut};if(Yy({editRevision:Pt.current,pinnedHistoryMessageId:It.current,latestHistoryMessageId:wt?.id??null}))return;let r=Ky({sessionId:et,latestUserChoice:wt,latestExecution:Et,catalog:n,memory:t,sessionEntity:jt&&At?{agent:kt,model:{id:At,providerID:jt,variant:Mt}}:kt?{agent:kt}:null,fallbackAgentName:rt,transcriptReady:Dt});if(!r)return;let i=[et,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,Nt].join(`|`);if(Vt.current===i)return;if((r.agent===void 0||r.agent===rt)&&r.providerID===tt&&r.modelID===nt&&r.variant===it){Vt.current=i;return}if(Ai.getState().activeDirectoryKey!==e)return;let a=Ai.getState();qy(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:et,memory:t}),Vt.current=i},[Ln.kind,et,wt,Et,Dt,at,ut,dt,ft,Nt,St,rt,tt,nt,it,kt,At,jt,Mt]);let Ar=Ai(e=>e.getVisibleAgents),jr=Ln.kind===`primary`?Ar():zb,Mr=Ai(e=>Ln.kind===`primary`?e.providers:Bb),Pr=Ln.kind===`secondary`?Am(Ln.selection.catalog?.agents):jr,Fr=Ln.kind===`secondary`?Ln.selection.catalog?.providers??Bb:Mr,Ir=Ln.kind===`secondary`&&(!Ln.selection.catalog?.ready||!!Ln.selection.catalog.error),Rr=!Ln.active||!Ln.selection.change||Ir,zr=q(e=>e.isMobile),Ur=q(e=>e.setImagePreviewOpen),Gr=Z.useCallback(e=>{e.image&&(m(e),Ur(!0))},[Ur]),qr=Z.useCallback(e=>{m(t=>({...t,open:e})),Ur(e)},[Ur]),Xr=uu(e=>e.pending),Zr=q(e=>e.inputBarOffset),Qr=q(e=>e.persistChatDraft),$r=q(e=>e.inputSpellcheckEnabled),ai=q(e=>e.isExpandedInput),oi=q(e=>e.setExpandedInput),si=q(e=>e.setTimelineDialogOpen),ci=Nb({draftKey:Xn,sessionTitles:new Map(Array.from(fi(),([e,t])=>[e,t.title||e])),persistenceEnabled:Qr}),li=ci.document,di=li.text,{replacePlainDocument:pi,replaceProgrammaticText:mi,applyBrowserEdit:gi,insertReference:_i,deleteReference:vi,enterHistoryPreview:yi,exitHistoryPreview:bi,captureSubmission:Si,recoverSubmission:wi,confirmedFileMentions:Ti,mentions:Oi}=ci,ki=Z.useCallback((e,t)=>mi(e,t),[mi]),ji=Z.useMemo(()=>new Set(Ti.map(e=>e.value)),[Ti]),Pi=Z.useRef(null),Ii=Z.useRef(!1),Li=Z.useRef(0),Ri=Z.useRef(null),Bi=Z.useRef(di.length),Vi=Z.useRef(null),Hi=Z.useRef(0),Ui=Z.useRef(!1),Wi=Z.useRef(null),Gi=Z.useRef(!1),Ki=Z.useRef(null),qi=Z.useRef([]),Ji=Z.useRef(!1),Qi=Z.useRef(null),$i=Z.useRef(!1),ea=Z.useRef(null),ta=Z.useRef(null),na=Z.useRef(null),ra=Z.useRef(di),ia=Z.useRef(new Set),aa=ci.getDocument,oa=Z.useCallback((e,t,n=[])=>ki(e,(e,r)=>{let i=[],a=new Set(n);for(let e of t){let t=0,n=`@${e}`;for(;t<r.text.length;){let o=r.text.indexOf(n,t);if(o<0)break;i.push({kind:a.has(e)?`directory`:`file`,value:e,path:e,label:e,range:{start:o,end:o+n.length}}),t=o+n.length}}let o=new Set(e.map(e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`));return[...e,...i.filter(e=>!o.has(`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`))]}),[ki]),sa=zh(Rh()),{git:la,vscode:da}=ko(),fa=q(e=>e.shortcutOverrides.cycle_agent),ma=q(e=>e.shortcutOverrides),ha=Z.useMemo(()=>Qa(`cycle_agent`,fa?{cycle_agent:fa}:void 0),[fa]),ga=Z.useMemo(()=>Qa(`clear_all_messages`,ma),[ma]),{currentTheme:va}=Ga(),xa=Vo(),Ca=fs(Yn),Ea=Xo(e=>Yn?e.directories.get(Yn)?.status??null:null),Da=Xo(e=>e.ensureStatus),ja=Xo(e=>e.fetchStatus),[Ma,Pa]=Z.useState(!1),Fa=Z.useRef(null),[Ia,La]=Z.useState(!1);Z.useEffect(()=>{!Yn||!la||Da(Yn,la)},[Yn,la,Da]),Z.useEffect(()=>{if(!(!Yn||!la))return gt.onGitRefreshHint(e=>{tx(e.directory)===tx(Yn)&&ja(Yn,la)})},[Yn,la,ja]);let Ha=Z.useCallback(async e=>{if(!Hn)return;let t=ri.getState().getDirectoryForSession(Hn)||Yn||``;if(!t){Br.error(u(`diffView.reviewDialog.toast.noSessionDirectory`));return}mr(!0);try{await ti({originalSessionID:Hn,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),cr(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),Br.error(e instanceof Error?e.message:u(`diffView.reviewDialog.toast.startFailed`))}finally{mr(!1)}},[Hn,Yn,u]),Ua=ai&&!zr,Wa=ai&&zr,Ka=Ua||Wa,Ya=`1.5rem`,Xa=u(Hn||Gn?g===`shell`?`chat.chatInput.placeholder.shell`:zr||Ia?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Za=u(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=Vi.current;if(!e)return;let t=e=>{let t=e>0&&e<Wb;La(e=>e===t?e:t)};if(t(e.clientWidth),typeof ResizeObserver>`u`){let n=()=>t(e.clientWidth);return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)}let n=new ResizeObserver(n=>{t(n[0]?.contentRect.width??e.clientWidth)});return n.observe(e),()=>n.disconnect()},[]);let $a=Vn,eo=Z.useMemo(()=>new Set(Pr.map(e=>e.name.toLowerCase())),[Pr]),to=Z.useRef(eo);to.current=eo;let no=Hb({inputMode:g,message:di,showCommandAutocomplete:M,showSkillAutocomplete:U}),ro=Yi({directory:Yn,enabled:no}),io=Z.useMemo(()=>ro.data??[],[ro.data]),ao=Ei({directory:Yn,enabled:no}),oo=Z.useMemo(()=>ao.data??[],[ao.data]),so=Z.useMemo(()=>new Map(oo.map(e=>[e.name.toLowerCase(),e.name])),[oo]),co=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!zr&&!se()&&e.add(`handoff-review`);for(let t of io)e.add(t.name.toLowerCase());for(let t of oo)e.add(t.name.toLowerCase());return e},[io,oo,zr]),lo=Z.useMemo(()=>{if(!di||!di.includes(`/`)||g===`shell`||co.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${B})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(di))!==null;){let t=n[2]??``,r=n[3];if(!co.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=so.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:G({trigger:`/`,icon:`book-open`,label:o},di.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:G({trigger:`/`,icon:`command`,label:r},di.slice(i,i+a))})}return e},[so,g,co,di]),uo=Sa(e=>e.snippets),fo=Z.useMemo(()=>{let e=new Set;for(let t of uo){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[uo]),po=Z.useMemo(()=>{if(!di||!di.includes(`#`)||g===`shell`||fo.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(di))!==null;){let t=n[2];if(!fo.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[g,fo,di]),mo=Z.useMemo(()=>!di||!di.includes(`@`)||g===`shell`?[]:Wr(di,{confirmedValues:ji,agentNames:eo}),[ji,g,eo,di]),ho=Z.useMemo(()=>{if(!di||!di.includes(`[`)||g===`shell`||$a.length===0)return[];let e=$a.filter(Ne),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return Te(di,e.map(e=>e.filename)).flatMap(e=>{let n=V(di.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:G({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},di.slice(e.start,e.end))}]})},[g,di,$a]),go=d&&Gs(zr)&&Ln.kind===`primary`,_o=Z.useMemo(()=>{if(!di||g===`shell`)return null;let e=[...go?[]:Ev(di),...go?[]:Hv(di),...jv(mo),...lo,...po,...ho,...li.references.map(e=>({start:e.start,end:e.end,priority:103,...E(e)}))];return Dv(di,e)},[ho,lo,po,mo,li.references,g,di,go]),vo=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?$b(e.serverPath):e.dataUrl})),[]),[yo,bo]=Z.useState(null),xo=Z.useRef(null),[So,Co]=Z.useState(!1),[wo,To]=Z.useState(!1),[Eo,Do]=Z.useState(null),[Oo,Ao]=Z.useState(null),jo=b(e=>e.followUpBehavior),Mo=Z.useMemo(()=>{let e=Rn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[Rn]),Po=Ju({transportIdentity:Mo?.transportIdentity??``,directory:Mo?.directory??``,sessionID:Mo?.sessionID??``}),Ro=Z.useMemo(()=>Hn?v(Hn):null,[Hn]),zo=b(Z.useCallback(e=>Mo?_(e,Mo):Lb,[Mo])),Bo=b(Z.useCallback(e=>Ro?_(e,Ro):Lb,[Ro])),Ho=Z.useMemo(()=>Bo.length===0?zo:zo.length===0?Bo:[...Bo,...zo],[zo,Bo]),Go=Po.mode===`server`?Lb:Ho,qo=b(Z.useCallback(e=>Mo?I(e,Mo):Lb,[Mo])),Yo=b(e=>e.clearQueue),Zo=b(e=>e.removeFromQueue),es=zn.inlineDrafts,ns=es.length>0,[rs,as,cs]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of es)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[es]),us=Z.useCallback(e=>{for(let t of zn.inlineDrafts)t.source===e&&zn.removeInlineDraft(t.id)},[zn]),ds=Z.useCallback(()=>{for(let e of zn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&zn.removeInlineDraft(e.id)},[zn]),ms=zn.history;Z.useEffect(()=>{ra.current=di},[di]),Z.useLayoutEffect(()=>{x(`normal`),Ze(-1)},[Xn?.transportIdentity,Xn?.owner.kind,Xn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Gn||zr)return;let e=()=>{let e=Pi.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Gn,zr]);let hs=Fg(Ln.kind===`primary`?Hn:null,Ln.kind===`primary`?Yn??void 0:void 0),gs=Ln.activity?.phase??hs.phase,_s=Wt(Z.useCallback(e=>{if(!Hn)return!1;let t=e.runsByOriginalSessionID[Hn];return t?.status===`running`&&t.runtimeKey===a()},[Hn])),vs=J(e=>{zr&&(qe(),he(e),Pi.current?.blur(),Ai.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),ys=zn.pendingInput,bs=zn.consumePendingInput;Z.useEffect(()=>{if(ys===null)return;let e=bs();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=px(ra.current,e.text);ra.current=t,ki(t)}else if(e.mode===`append-inline`){let t=mx(ra.current,e.text);ra.current=t,ki(t)}else pi(e.text);setTimeout(()=>{Pi.current?.focus()},0)}},[ys,bs,pi,ki]);let xs=di.trim().length>0||$a.length>0||ns,Ss=Po.mode===`server`?Po.items.length>0:Go.length>0||qo.length>0,Ts=!Uf(Po.mode),Es=xs||Ss,Ds=ri(e=>e.stagedMessageEdit?.sessionId===Hn?e.stagedMessageEdit.messageId:null),Os=gs===`busy`||gs===`retry`,ks=Ln.activity?.canAbort??Os,As=Z.useCallback(()=>{let e=Pi.current,t=e?.value??aa().text;t!==aa().text&&gi(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=aa();return{message:n.text,document:n,hasContent:n.text.trim().length>0||$a.length>0||ns}},[gi,aa,ns,$a.length]),js=Z.useRef(async()=>{}),Ms=Ln.surfaceID,Ns=Ht?.draftID??null,Fs=mn(Z.useMemo(()=>bt(Ms),[Ms])),Is=mn(Z.useMemo(()=>un(Ns),[Ns])),Rs=Z.useMemo(()=>ni(Fs,Is),[Fs,Is]),zs=(e=`send`)=>mn.getState().beginFlight(Ms,e),Bs=()=>{mn.getState().endFlight(Ms)},Vs=()=>mn.getState().isInFlight(Ms),Hs=Z.useRef(null);Z.useEffect(()=>{if(Ln.kind!==`primary`||!Ds){Hs.current=null;return}if(Hs.current!==Ds){if(Hs.current=Ds,go){Ws().focus();return}Fm(Pi)||requestAnimationFrame(()=>Fm(Pi))}},[go,Ds,Ln.kind]);let Us=mn(Z.useMemo(()=>Yr(Ns),[Ns])),Ks=J(async()=>{let e=ri.getState().newSessionDraft.draftID;if(!e||!mn.getState().isEstablishing(e))return!1;let t=As();if(!t.hasContent)return!1;let n=H(t.document,`queue-canonical`);if(!n.ok)return Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1;if(await Ln.selection.flush(),!mn.getState().isEstablishing(e))return!1;let r=Jy(Ai.getState());if(!r?.providerID||!r?.modelID)return Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1;let i=vo($a);return mn.getState().enqueueEstablishingFollowUp({draftID:e,content:n.text,sendConfig:{providerID:r.providerID,modelID:r.modelID,...r.agent?{agent:r.agent}:{},...r.variant?{variant:r.variant}:{}},attachments:i,composerDocument:t.document})?(pi(``),Ze(-1),oi(!1),i.length>0&&zn.clearAttachments(),!0):!1}),qs=()=>{if(Hn)return!1;let e=ri.getState().newSessionDraft.draftID;return mn.getState().isEstablishing(e)?(Ks(),!0):!1},Js=J(async()=>{if(!Ln.active||Vs())return;if(Hn){let e=ri.getState().stagedMessageEdit;if(e&&e.sessionId===Hn){ri.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await Rt(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{ri.getState().endMessageEditCommit(e.sessionId,e.messageId)}ri.getState().stagedMessageEdit===e&&ri.getState().clearStagedMessageEdit(e.sessionId)}}let e=As(),t=H(e.document);if(!t.ok){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let n={chunks:t.chunks??[],semantics:t.semantics??[]},a=t.text,o=a.trimStart(),s=n.chunks.every(e=>e.provenance===`authored`)&&g===`normal`&&o.startsWith(`/`)?Jo(o.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(s&&!Uo(s,e=>Bm(Ln,{name:e.name,source:`openchamber`}))||c||!e.hasContent||!Hn)return;if(Ts||!zt(Ln.deliveryTarget?.kind,Po.mode)){js.current(Os?{delivery:`steer`}:void 0);return}if(n.chunks.every(e=>e.provenance===`authored`)&&py(a,g)){js.current();return}if(!zs(`queue`))return;let l=Ln.transportIdentity,d=Ln.runtimeGeneration,f=zn.captureRuntime(),p=Mo,m=Ln.kind===`primary`?Mo?.sessionID??Hn:null,_=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),x=_.length>0?h(Ru(e.document.text,_),e.document.references).document:e.document,S=H(x,`queue-canonical`);if(!S.ok){Bs(),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let C=vo($a),w=Si(),T=C,E=$n(),D=!1,O=null,k=()=>{D&&p&&(Po.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(b.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&wi(w),T.length>0&&await zn.restoreAttachments(T),e&&zn.restoreSyntheticParts(e),_.length>0&&zn.restoreInlineDrafts(_)};try{if(!p){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}if(Po.mode===`server`){if(!Xn){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}xi({stage:()=>{Po.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:S.text,createdAt:E.createdAt,attachmentCount:C.length,composerDocument:x,composerMentions:Oi}}),D=!0},clearComposer:()=>{pi(``),Ze(-1),oi(!1)}})}else xi({stage:()=>{b.getState().bindLegacyQueue(v(p.sessionID),p),b.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:S.text,createdAt:E.createdAt,attachmentCount:C.length,composerDocument:x,composerMentions:Oi}),O=E.requestID},clearComposer:()=>{pi(``),Ze(-1),oi(!1)}});if(await Ln.selection.flush(),!Sn({transportIdentity:l,generation:d},{transportIdentity:r(),generation:i()})){await A();return}if(!Sn(f,zn.captureRuntime())){await A();return}if(m&&ri.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==r()||p.runtimeGeneration!==i()||p.sessionID!==(m??p.sessionID)||m&&y(ri.getState().getDirectoryForSession(m))!==y(p.directory)){await A();return}let t=p,n=Ln.kind===`primary`?(()=>{let e=Ai.getState(),t=m?ri.getState().getDirectoryForSession(m)??null:null;return Jy(e,{expectedConfigKey:wr(t),activeDirectoryKey:e.activeDirectoryKey})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(!tr(n)){await A();return}if(Po.mode===`server`){if(!Xn){await A(),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let r=Zt({draftKey:Xn,runtime:f,document:e.document,attachments:$a,inlineDrafts:_}),i=t.deliveryTarget.kind===`assistant`?zn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??N()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=hi({plan:{chunks:S.chunks??[],semantics:S.semantics??[]},agents:Pr,installedSkillNames:new Set(Tr(ee,Yn).map(e=>e.name)),directory:Yn,root:xa||Yn,confirmedFilePaths:Ti.map(e=>e.path),confirmedDirectoryPaths:Ti.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:$a});return o=e.attachments,pt({text:_.length>0?Ru(e.text,_):e.text,attachments:[...C,...e.attachments],semanticParts:ui(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...$t(C),...$t(o),...(i??[]).flatMap(e=>$t(e.attachments??[],e.partID))],t=s?new Set(s.flatMap(e=>e.type===`file`?[e.attachmentID]:[])):null;a=e.filter((n,r)=>e.findIndex(e=>e.attachmentID===n.attachmentID)===r&&(!t||t.has(n.attachmentID)))}catch(e){await A(i),Br.error(u(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Dr(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Kn({capture:r,admit:async()=>{let r=await Po.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:S.text,composerDocument:x,composerMentions:Oi,sendConfig:n,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return r.status===`committed`&&(e=!0,D=!1),r},captureRuntime:zn.captureRuntime,getCurrentDraftKey:()=>Xn,getDocument:aa,consumeBody:()=>pi(``),getAttachments:()=>zn.attachments,removeAttachment:zn.removeAttachment,getInlineDrafts:()=>zn.inlineDrafts,removeInlineDraft:zn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!zr&&Pi.current?.focus()}catch(e){await A(i),Br.error(u(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!b.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:n,attachments:C.length>0?C:void 0}).ok){await A(),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of _)zn.removeInlineDraft(e.id);C.length>0&&zn.clearAttachments(),zr||Pi.current?.focus()}catch(e){await A(),Br.error(u(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Bs()}}),Ys=J(()=>{Cy(()=>Js(),()=>{Br.error(u(`chat.chatInput.toast.messageSendFailed`))})}),Xs=J(async(e,t,n,r)=>{if(Ts||!Ln.draftKey)return!1;try{let i=await qt({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=ei.getState(),o=a.getDraft(Ln.draftKey);return Gf(await Lt({key:Ln.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return Br.error(u(`chat.chatInput.toast.messageSendFailed`)),!1}}),Zs=J(e=>{if(!(c||Ts)){if(Rn){Rn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}Br.error(u(`chat.chatInput.toast.messageSendFailed`))}}),Qs=J(()=>{qe(),he(`agent`),Pi.current?.blur(),Ai.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),$s=Z.useCallback(()=>{Co(!0)},[]),ec=Z.useCallback(()=>{To(!0)},[]),tc=async e=>{if(!Ln.active||c||qs()||Vs())return;let t=e?.queuedOnly??!1,a=e?.queuedMessageId,o=e?.delivery===`steer`&&Os?`steer`:void 0,s=e?.presetText==null?As():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||$a.length>0||ns},l=e?.presetText==null?Si():null,d=Vn,f=H(s.document,`direct-send-display`);if(!f.ok){Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}let m=f.text,h={chunks:f.chunks??[],semantics:f.semantics??[]},v=h.chunks.every(e=>e.provenance===`authored`),y=m.trimStart(),x=v?dy(y,g):null,S=v&&py(m,g),C=v&&g===`normal`&&/^\/model(?:\s|$)/i.test(y),w=v&&g===`normal`&&y.startsWith(`/`)?Jo(y.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(w&&!Uo(w,e=>Bm(Ln,{name:e.name,source:`openchamber`}))||t&&Ts)return;if(!t&&C){P(!1),L(``),zr?vs(`model`):(q.getState().setModelSelectorOpen(!0),Ai.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&x&&x!==`model`)){if(!t&&Hn&&Ss&&Ts)return;if(!t&&Hn&&Ss&&Po.mode===`server`){s.hasContent&&Ys();return}if(!t&&Hn&&Ss){s.hasContent&&Ys();let e=Go[0];e&&Rn&&await Rn.sendQueued(e.queueItemID,{options:Os?{delivery:`steer`}:void 0});return}}let T=S?[]:a?Go.filter(e=>e.id===a):Go;if(t&&_s)return;if(t){if(T.length===0||!Hn)return}else if(!s.hasContent&&!Ss||!Hn&&!Gn)return;if(!Hn&&Wn||!zs())return;let E=!Hn&&Gn&&!t&&!S?ri.getState().newSessionDraft.draftID??null:null,D=E?z(`msg`):void 0;if(E&&D&&!mn.getState().beginEstablishing({draftID:E,primaryMessageID:D})){Bs();return}let O=()=>{lr(),E&&mn.getState().clearEstablishing(E)},k=e=>{let t=ri.getState().currentSessionId,n=(t?ri.getState().getDirectoryForSession(t):null)??Yn??``;if(!t||!n){mn.getState().clearEstablishing(e);return}Sy({draftID:e,sessionID:t,directory:n,transportIdentity:r(),runtimeGeneration:i(),admitServer:Po.mode===`server`?async e=>Po.actions.admit({requestID:e.requestID,scope:{directory:n,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?$t(e.attachments):void 0}):void 0})};if(Hn&&!t&&!S&&_s){Bs(),Ys();return}let A=!t&&!S;A&&(pi(``),Ze(-1),oi(!1));let j=!1,M,N,F=!1;try{if(vy({surfaceKind:Ln.kind,currentSessionId:Hn,queuedOnly:t,resourcePolicy:S,inputMode:g,localCommand:x})&&Hn){let e=ri.getState().getDirectoryForSession(Hn)??Yn??null,t=ri.getState().stagedMessageEdit;t&&t.sessionId===Hn&&(N={sessionId:t.sessionId,messageId:t.messageId},ri.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Ai.getState(),r=Jy(n,{expectedConfigKey:wr(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=vo($a);M=pn({sessionId:Hn,directory:e,content:s.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=Ln.kind===`primary`?(()=>{if(t){let e=T[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(Mo?.sessionID)return Mo.sessionID}return Hn})():null,r=t?T[0]?.sendConfig:void 0;if(t&&r||await Ln.selection.flush(),e!==null&&ri.getState().currentSessionId!==e)return;let i=async()=>{let t=r?{...r}:Ln.kind===`primary`?(()=>{let t=Ai.getState();if(!e)return Xy({captured:Jy(t),surfaceSelection:Ln.selection.value});let n=ri.getState().getDirectoryForSession(e)??Yn??null;return Xy({captured:Jy(t,{expectedConfigKey:wr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:Ln.selection.value})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(Ln.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=ri.getState().getDirectoryForSession(e)??Yn??null,r=wr(n);if(Ai.getState().activeDirectoryKey!==r&&await Ai.getState().activateDirectory(n),ri.getState().currentSessionId===e){let e=Ai.getState();t=Xy({captured:Jy(e,{expectedConfigKey:wr(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:Ln.selection.value})}}return t},c=await i(),f=!1,m=c?.providerID,v=c?.modelID,y=c?.agent,C=c?.variant;if(!m||!v){if(!f){f=!0;try{await Ai.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await i(),m=c?.providerID,v=c?.modelID,y=c?.agent,C=c?.variant}catch{}}if(!m||!v){console.warn(`Cannot send message: provider or model not selected`),Br.error(u(`chat.chatInput.toast.messageSendFailed`));return}}Hn&&!t&&!S&&await an(Hn)&&await Jr(Hn);let w={...o?{delivery:o}:{},commitStagedMessageEdit:!t,...M?{messageID:M.messageID,ticket:M}:D?{messageID:D}:{},...e?{sessionId:e,directoryHint:ri.getState().getDirectoryForSession(e)??Yn??null}:Ln.kind===`primary`&&Hn?{sessionId:Hn,directoryHint:ri.getState().getDirectoryForSession(Hn)??Yn??null}:{}},A=``,P=[],I,L=[],R=new Set(Tr(ee,Yn).map(e=>e.name)),z=[],B=S?void 0:zn.consumeSyntheticParts();for(let e=0;e<T.length;e++){let t=T[e],n=t.composerDocument&&H(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Yn,a=new Set(Tr(ee,i).map(e=>e.name)),o=hi({plan:r??Di(t.content),agents:Pr,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(z.push(...o.semantics),!I&&o.agent&&(I=o.agent),e===0)A=o.text,P=Vr([...vo(t.attachments),...o.attachments]);else{let e=vo(t.attachments);L.push({text:o.text,attachments:Vr([...e,...o.attachments])})}}if(!t&&s.hasContent){let e=vo($a),t=hi({plan:h,agents:Pr,installedSkillNames:R,directory:Yn,root:xa||Yn,confirmedFilePaths:Ti.map(e=>e.path),confirmedDirectoryPaths:Ti.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:$a});z.push(...t.semantics),!I&&t.agent&&(I=t.agent),T.length===0?(A=t.text,P=Vr([...e,...t.attachments])):L.push({text:t.text,attachments:Vr([...e,...t.attachments])})}let V=Hn??(Gn?`draft`:null),U=[];if(!t&&V&&!S&&(U=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(T.length===0)A=Ru(A,U);else if(L.length>0){let e=L[L.length-1];e.text=Ru(e.text,U)}else A=Ru(A,U);if(B&&B.length>0&&L.push(...Ni(B)),Eo&&L.push({text:Eo.contextText,synthetic:!0}),Oo&&(L.push({text:Oo.instructionsText,synthetic:!0}),L.push({text:Oo.contextText,synthetic:!0})),L.push(...ui(z,Hn&&ri.getState().getDirectoryForSession(Hn)||Yn)),!A&&P.length===0&&L.length===0)return;if(E&&D){if(!await Hr({messageID:D,providerID:m,modelID:v,agent:y,text:A,attachments:P,additionalParts:L,agentMentionName:I}))return;if(!mn.getState().isEstablishing(E)){O();return}}let W=async()=>{if(O(),Mo&&T.length>0&&b.setState(e=>{let t=p(Mo),n=e.queuedMessages[t]??[],r=new Set(T.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...T,...n.filter(e=>!r.has(e.id))]}}}),t)return B&&zn.restoreSyntheticParts(B),!0;zn.pendingInput?.text===s.message&&zn.consumePendingInput(),l&&wi(l);let e=!0;return d.length>0&&(e=await zn.restoreAttachments(d)),B&&zn.restoreSyntheticParts(B),U.length>0&&zn.restoreInlineDrafts(U),e};if(!S&&Hn&&a){let e=Mo?_(b.getState(),Mo).find(e=>e.id===a||e.queueItemID===a):void 0;Mo&&e?.queueItemID&&e.operationID&&Zo(Mo,e.queueItemID,e.operationID)}else!S&&Hn&&Ss&&Mo&&Yo(Mo);!t&&!S&&(pi(``),Ze(-1),oi(!1),_y({queuedOnly:t,resourcePolicy:S,rootAttachmentCount:d.length})&&zn.clearAttachments());let G=()=>hy({currentSessionId:Hn,messageRef:ra,replacePlainDocument:pi}),K=A.trimStart();if(g===`normal`&&K.startsWith(`/`)){let e=Jo(K.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Uo(e,e=>Bm(Ln,{name:e.name,source:`openchamber`})))return;if(Hn&&(e===`undo`||e===`redo`)&&my(K,g)&&G(),e===`undo`&&Hn){try{await ri.getState().handleSlashUndo(Hn),n?.()}catch(e){Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){my(K,g)&&G(),await Rn?.shortcut(`new`);return}if(e===`redo`&&Hn){try{await ri.getState().handleSlashRedo(Hn),n?.()}catch(e){Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Hn){await gy({command:`fork`,consumeCommandText:G,forkSession:()=>ri.getState().forkCurrentSession(Hn),waitForConnection:Zn,getDirectoryForSession:()=>ri.getState().getDirectoryForSession(Hn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Hn&&sa.timeline){si(!0);return}if(e===`compact`&&Hn){gy({command:`compact`,consumeCommandText:G,forkSession:async()=>void 0,waitForConnection:Zn,getDirectoryForSession:()=>Ln.directory??``,summarizeSession:e=>Xn?Ln.backend.compact({operation:`compact`,surfaceID:Ln.surfaceID,transportIdentity:Ln.transportIdentity,runtimeGeneration:Ln.runtimeGeneration,sessionID:Hn,directory:e,draftKey:Xn,deliveryTarget:Ln.deliveryTarget,providerID:m,modelID:v,agent:y,variant:C}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{Br.error(u(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Hn){try{await Zn();let e=K.replace(/^\/\u2003?summary\b/i,``).trim(),t=e?` focused on: ${e}`:``,r=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await Ci(`session.summary.visible`,{topic_line:t}),a=await Ci(`session.summary.instructions`,{topic_block:r});await er(i,m,v,y,[],I,[{text:a,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.review.visible`),t=await Ci(`session.review.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Hn&&!zr&&!se()){cr(!0);return}if(e===`goal`&&(Hn||Gn)){O(),yn.getState().setArmed(!0);let e=fy(K,g)??``;pi(e),ra.current=e,Ze(-1),e||oi(!1);return}if(e===`craft-goal`&&(Hn||Gn)){try{await Zn();let e=K.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await Ci(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),r=await Ci(`session.craftGoal.instructions`);await er(t,m,v,y,[],I,[{text:r,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.catchup.visible`),t=await Ci(`session.catchup.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.debug.visible`),t=await Ci(`session.debug.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.weigh.visible`),t=await Ci(`session.weigh.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Hn||Gn)){try{await Zn();let e=await Ci(`session.explore.visible`),t=await Ci(`session.explore.instructions`);await er(e,m,v,y,[],I,[{text:t,synthetic:!0}],C,g,w),n?.()}catch(e){await W(),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.exploreFailed`))}return}}let te=Hn&&ri.getState().getDirectoryForSession(Hn)||Yn;if(qn||Hn&&!Yb(Hn,te)){let e=await Kr().catch(()=>null);e&&L.push({text:zi(e),synthetic:!0})}try{let e=Sa.getState().expandText;A=await e(A);for(let t of L)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}F=!0;let ne=er(A,m,v,y,P,I,L.length>0?L:void 0,C,g,w);j=!0,ne.finally(()=>{Bs(),N&&ri.getState().endMessageEditCommit(N.sessionId,N.messageId)}),E&&ne.then(()=>{k(E)}).catch(()=>{mn.getState().clearEstablishing(E)}),typeof window>`u`?n?.():window.requestAnimationFrame(()=>{n?.()}),ne.then(()=>{Eo&&Do(null),Oo&&Ao(null)}).catch(e=>{M&&Jn(M),W().then(e=>{e||Br.error(u(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){Br.error(u(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){d.length>0&&Br.error(u(`chat.chatInput.toast.sendAttachmentsFailed`));return}Br.error(t||u(`chat.chatInput.toast.messageSendFailed`))}),zr||Pi.current?.focus()}finally{F||(M&&Jn(M),N&&ri.getState().endMessageEditCommit(N.sessionId,N.messageId)),j||(A&&l&&wi(l),Bs(),E&&k(E))}};js.current=tc;let nc=Z.useCallback(()=>{if(qs()||Vs())return;let e=As(),t=g===`normal`&&e.hasContent&&Hn&&(Os||_s),n=t&&Uf(Po.mode)&&zt(Ln.deliveryTarget?.kind,Po.mode);jo===`queue`&&n?Ys():jo===`steer`&&t||jo===`queue`&&t&&!n?js.current(t?{delivery:`steer`}:void 0):js.current()},[g,As,Hn,Os,_s,jo,Ys,Po.mode,Ln.deliveryTarget?.kind,Ks]),rc=Z.useCallback(e=>{if(Vs())return;let t=(Pi.current?.value??ra.current).trim(),n=t?`${e}\n${t}`:e;js.current({presetText:n})},[]),ic=Z.useCallback(e=>{let t=mx(aa().text,e);ki(t),Pi.current&&(Pi.current.value=t),setTimeout(()=>{Pi.current?.focus()},0)},[ki]),ac=Z.useCallback(e=>{if(Vs())return;let t=mx(Pi.current?.value??ra.current,e);js.current({presetText:t})},[]),oc=zn.pendingPreset,sc=zn.consumePendingPreset;Z.useEffect(()=>{if(oc==null)return;let e=sc();e&&rc(e)},[oc,sc,rc]);let cc=Z.useCallback(()=>{pi(``),Ze(-1),Vn.length>0&&zn.clearAttachments(),Mo&&Yo(Mo),P(!1),W(!1),re(!1),O(!1),g===`shell`&&x(`normal`)},[Vn.length,zn,Yo,Mo,pi,g]),lc=e=>{if(!Ln.active||Ig(e))return;if(ga&&qa(e,ga)&&!Xr){let t=Pi.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),cc();return}}if(g===`shell`&&e.key===`Escape`){e.preventDefault(),x(`normal`);return}if(g===`shell`&&e.key===`Backspace`&&di.length===0){e.preventDefault(),x(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Pi.current,n=t?.selectionStart??di.length,r=t?.selectionEnd??di.length,i=vi({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Jb(ci.getDocument().text,i.start);e.preventDefault(),ki(t.text),requestAnimationFrame(()=>{Pi.current?.setSelectionRange(t.caret,t.caret),bc()}),xc(t.text,t.caret);return}let a=Ee(di,Vn.filter(Ne).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=Jb(a.text,a.caret);e.preventDefault(),ki(n.text);for(let e of Vn)t.has(e.filename.toLowerCase())&&zn.removeAttachment(e.id);requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=n.caret,Pi.current.selectionEnd=n.caret),bc()}),xc(n.text,n.caret);return}let o=Av(di,so.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Jb(o.text,o.caret);e.preventDefault(),ki(t.text),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=t.caret,Pi.current.selectionEnd=t.caret),bc()}),xc(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<di.length){let n=Te(di,Vn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=V(di.slice(n.start+1,n.end-1)).trim(),r=Vn.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=di[n.end]===` `?n.end+1:n.end,a=`${di.slice(0,n.start)}${di.slice(i)}`;e.preventDefault(),ki(a),r&&zn.removeAttachment(r.id),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=n.start,Pi.current.selectionEnd=n.start),bc()}),xc(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(di[r-1]);)--r;let i=t+1;for(;i<di.length&&!/\s/.test(di[i]);)i+=1;let a=di.slice(r,i),o=a.slice(1);if(Vb.test(a)&&!to.current.has(o.toLowerCase())&&Cr({mention:o,confirmed:ji.has(o),terminated:i<di.length&&/\s/.test(di[i])})){let t=di[i]===` `?i+1:i,n=`${di.slice(0,r)}${di.slice(t)}`;e.preventDefault(),ki(n),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=r,Pi.current.selectionEnd=r),bc()}),xc(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&ea.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ea.current.handleKeyDown(e.key);return}if(U&&ta.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ta.current.handleKeyDown(e.key);return}if(ne&&na.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),na.current.handleKeyDown(e.key);return}if(D&&Qi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Qi.current.handleKeyDown(e.key);return}if(Ua&&e.key===`Escape`){e.preventDefault(),oi(!1);return}let n=ha&&!ha.includes(`shift`)?Ja(`shift+${ha}`):``,r=n&&qa(e,n)?-1:+!!qa(e,ha);if(r!==0&&!M&&!U&&!ne&&!D){e.preventDefault(),e.stopPropagation(),Rn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Pi.current?.focus({preventScroll:!0})});return}let i=M||U||ne||D,a=Pi.current?.selectionStart===0&&Pi.current?.selectionEnd===0,o=Pi.current?.selectionStart===di.length&&Pi.current?.selectionEnd===di.length,s=!i&&(di.length===0||a),c=!i&&(di.length===0||o);if(g===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Pi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),ki(t),requestAnimationFrame(()=>{let e=Pi.current;e&&(e.selectionStart=n,e.selectionEnd=r),bc()}),xc(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=di.slice(n,r);t(`${di.slice(0,n)}${a}${s}${o}${di.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=di.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${di.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&ms.length>0){if(e.preventDefault(),Xe===-1)Ze(0),yi({text:ms[0],references:[]});else if(Xe<ms.length-1){let e=Xe+1;Ze(e),yi({text:ms[e],references:[]})}requestAnimationFrame(()=>{Pi.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Xe>=0){if(e.preventDefault(),Xe===0)Ze(-1),bi();else{let e=Xe-1;Ze(e),yi({text:ms[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),qs()||Vs())return;let t=e.ctrlKey||e.metaKey,n=g===`normal`&&xs&&Hn&&(Os||_s),r=n&&Uf(Po.mode)&&zt(Ln.deliveryTarget?.kind,Po.mode);jo===`queue`?t||!n?tc():r?Ys():tc({delivery:`steer`}):t||!n?tc():tc({delivery:`steer`})}},uc=Z.useCallback((e,t)=>{let n=e.ownerDocument,r=n.defaultView;if(!r)return null;let i=r.getComputedStyle(e),a=n.createElement(`div`),o=a.style;o.position=`absolute`,o.visibility=`hidden`,o.pointerEvents=`none`,o.whiteSpace=`pre-wrap`,o.wordWrap=`break-word`,o.overflow=`hidden`,o.left=`-9999px`,o.top=`0`,o.width=`${e.clientWidth}px`,o.font=i.font,o.fontSize=i.fontSize,o.fontFamily=i.fontFamily,o.fontWeight=i.fontWeight,o.fontStyle=i.fontStyle,o.fontVariant=i.fontVariant,o.letterSpacing=i.letterSpacing,o.textTransform=i.textTransform,o.textIndent=i.textIndent,o.padding=i.padding,o.border=i.border,o.boxSizing=i.boxSizing,o.lineHeight=i.lineHeight,o.tabSize=i.tabSize,a.textContent=e.value.slice(0,t);let s=n.createElement(`span`);s.textContent=e.value.slice(t,t+1)||` `,a.appendChild(s),n.body.appendChild(a);let c=s.offsetTop,l=s.offsetLeft;return n.body.removeChild(a),{top:c,left:l}},[]),dc=Z.useCallback(()=>{if(!Ua){bo(null);return}if(!M&&!U&&!ne&&!D){bo(null);return}let e=Pi.current,t=Vi.current;if(!e||!t)return;let n=e.selectionStart??di.length,r=uc(e,n);if(!r)return;let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=i.top-a.top+(r.top-e.scrollTop),s=i.left-a.left+(r.left-e.scrollLeft),c=o-8,l=a.height-o-8,u=l>=260||l>=c?`below`:`above`,d=D?520:M||ne?450:360,f=Math.max(8,Math.min(s-24,a.width-d-8)),p=Math.max(120,Math.min(260,u===`below`?l:c));bo({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Ua,uc,di.length,M,D,ne,U]);Z.useLayoutEffect(()=>{dc()},[dc,di,M,U,ne,D,Ua]),Z.useEffect(()=>{if(!Ua)return;let e=()=>dc();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Ua,dc]);let fc=Z.useCallback(()=>{xo.current&&=(clearTimeout(xo.current),null),Pa(!0),xo.current=setTimeout(()=>{Pa(!1),xo.current=null},1800)},[]),mc=Z.useCallback(()=>{if(zn.abortPrompt.clear(),fc(),Ln.kind===`secondary`){Rn?.shortcut(`abort`);return}nr()},[nr,Rn,fc,Ln.kind,zn]),hc=Z.useCallback((e=1)=>{if(Ir)return;let t=Ut(Pr,Ln.selection.value.agent??vr,e);if(!t||!Ln.selection.change)return;let n=Bt({providerID:Ln.selection.value.providerID??``,modelID:Ln.selection.value.modelID??``,agent:Ln.selection.value.agent??null},t,Pr,Fr);Ln.selection.change({...Ln.selection.value,...n,agent:n.agent??void 0}),Ln.kind===`primary`&&(q.getState().addRecentAgent(t),Ln.sessionID&&Zi.getState().saveSessionAgentSelection(Ln.sessionID,t))},[Pr,vr,Fr,Ir,Ln.kind,Ln.selection,Ln.sessionID]);Qe.current=hc;let gc=Z.useRef(null),[_c,vc]=Z.useState(null),yc=Z.useCallback(e=>{vc(t=>t===e?t:e)},[]),bc=Z.useCallback(e=>{let t=Pi.current;if(!t)return;let n=t.scrollTop;if(Ka){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,pe(null),t.scrollTop!==n&&(t.scrollTop=n);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let r=t.ownerDocument?.defaultView,i=r?r.getComputedStyle(t):null,a=i?parseFloat(i.lineHeight):NaN,o=i?parseFloat(i.paddingTop):NaN,s=i?parseFloat(i.paddingBottom):NaN,c=Number.isNaN(o)||Number.isNaN(s)?16:o+s,l=Number.isNaN(a)?22:a,u=Pb({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:gc.current??0,lineHeight:l,paddingTotal:c});t.style.height=`${u.height}px`,t.style.maxHeight=`${u.maxHeight}px`,t.style.overflowY=u.overflowY,t.scrollTop!==n&&(t.scrollTop=n),pe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[Ka]);Z.useLayoutEffect(()=>{let e=di.length<Bi.current;Bi.current=di.length,bc({allowShrink:e})},[bc,di,zr]),Z.useLayoutEffect(()=>{gc.current=_c,bc({allowShrink:_c===null})},[bc,_c]);let xc=Z.useCallback((e,t,n=`manual`,r)=>{let i=ps({text:e,cursor:t,inputMode:g,mentionInputSource:n,insertedText:r});if(Ri.current=i,!i){P(!1),O(!1),W(!1),re(!1),te(``);return}if(i.kind===`slash-command`){L(i.query),P(!0),O(!1),W(!1),re(!1);return}if(P(!1),i.kind===`slash-skill`){te(i.query),W(!0),O(!1),re(!1);return}if(W(!1),te(``),i.kind===`snippet`){oe(i.query),re(!0),O(!1);return}re(!1),A(i.query),O(!0)},[g,L,A,P,O,W,re,te,oe]),Sc=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(g===`normal`&&!Ii.current&&co.size>0&&e.includes(`/`)){let r=No(e,co,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=gi(a,o,s,(e,t)=>{let n=[...e];for(let e of pr(t.text,{agentNames:eo,includeUnterminatedPastedReferences:r===`paste`}))n=is(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=aa(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Pi.current;e&&Im(u,Ii.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),bc()}),xc(l.text,c.end,r,i),{document:l,selection:c}},[bc,gi,aa,g,eo,co,xc]),Cc=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=Pi.current;if(!n){let n=di+e;Sc(n,n.length,n.length,t,e);return}let r=n.selectionStart??di.length,i=n.selectionEnd??di.length,a=`${di.substring(0,r)}${e}${di.substring(i)}`,o=r+e.length;Sc(a,o,o,t,e)},[Sc,di]),wc=J((e,t)=>{let n=new Set(xe(Vn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of Vn)n.has(e.filename)&&zn.removeAttachment(e.id)}),Tc=Z.useCallback(e=>{zn.removeAttachment(e.id)},[zn]),Ec=Z.useCallback(()=>{Ui.current=!1,qi.current=[],Wi.current&&=(clearTimeout(Wi.current),null)},[]),Dc=Z.useCallback(()=>{Wi.current&&clearTimeout(Wi.current),Wi.current=setTimeout(()=>{Ec()},700)},[Ec]),Oc=Z.useCallback(()=>{Gi.current=!1,Ki.current&&=(clearTimeout(Ki.current),null)},[]),kc=Z.useCallback(()=>{Gi.current=!0,Ki.current&&clearTimeout(Ki.current),Ki.current=setTimeout(()=>{Gi.current=!1,Ki.current=null},700)},[]),Ac=Z.useCallback(e=>{!se()||!Ui.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),Ec())},[Ec]),jc=e=>{if(Xr)return;let t=e.nativeEvent;if(se()&&Ui.current){let n=qi.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){Ec();return}}let n=e.target.value;wc(ra.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Kb(ra.current,n):``,a=i.includes(`@`)||Gi.current;Gi.current&&Oc();let o=a?`paste`:`manual`;if(g===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);x(`shell`),pi(e),bc(),P(!1),W(!1),O(!1),requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=t,Pi.current.selectionEnd=t)});return}Sc(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{Ec(),Oc()},[Ec,Oc]);let Mc=Z.useCallback(e=>{let t=Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)));if(t.length===0)return;let n=t.map(e=>`@${e}`).join(` `),r=Pi.current,i=r?.selectionStart??di.length,a=r?.selectionEnd??di.length,o=$o(n,di.slice(0,i),di.slice(a)),s=`${di.slice(0,i)}${o}${di.slice(a)}`;wc(di,s),oa(s,t)},[di,oa,wc]),Nc=Z.useCallback(async e=>{let t=ex(e.clipboardData);if(t.length>0&&(Hn||Gn)){e.preventDefault(),Mc(t);return}if(g===`normal`&&(Hn||Gn)){let t=Pi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=di.slice(n,r);if(Ub.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${di.slice(0,n)}[${i}](${t})${di.slice(r)}`,o=n+1+i.length+2+t.length+1;ki(a),requestAnimationFrame(()=>{let e=Pi.current;e&&(e.selectionStart=o,e.selectionEnd=o),bc()}),xc(a,o,qb(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(g===`normal`&&lb(aa(),a)){e.preventDefault();let t=aa().text,n=Pi.current,r=n?.selectionStart??di.length,i=n?.selectionEnd??di.length,o=ub(a,di,aa().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>u(`chat.chatInput.pastedTextReference`,{index:e,count:t}),cb(aa())),s=_i(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=ls(s.document.text,s.caret);Pi.current&&(Pi.current.value=s.document.text),requestAnimationFrame(()=>{Pi.current?.setSelectionRange(c,c),bc()}),xc(s.document.text,c),wc(t,s.document.text);return}a.includes(`@`)&&kc();return}if(!Hn&&!Gn){a.includes(`@`)&&kc();return}e.preventDefault();let o=ke(i,[...Vn.map(e=>e.filename),...ia.current]),s=Re(o),c=aa().text,l=Pi.current,d=l?.selectionStart??di.length,f=l?.selectionEnd??di.length,p=g===`normal`&&lb(aa(),a)?ub(a,di,aa().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>u(`chat.chatInput.pastedTextReference`,{index:e,count:t}),cb(aa())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,h=$o(m,di.slice(0,d),di.slice(f));if(p){let e=_i(d,f,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=ls(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;Sc(n,t+s.length,t+s.length,qb(n),s),wc(c,n)}else Cc(h,qb(h)),wc(c,`${di.slice(0,d)}${h}${di.slice(f)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Gb(i[e],t);ia.current.add(t);try{await zn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.clipboardAttachFailed`))}finally{ia.current.delete(t)}}},[zn,Mc,Vn,bc,Hn,aa,g,_i,kc,di,Gn,Cc,u,xc,Sc,ki,wc]),Pc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=kv(r,i,[...Te(di,Vn.filter(Ne).map(e=>e.filename)),...Ov(di,so.keys()),...aa().references]),o=a?.start??r,s=a?.end??i,c=di.slice(o,s),l=R(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${di.slice(0,o)}${di.slice(s)}`;Sc(e,o,o),requestAnimationFrame(()=>{Pi.current?.setSelectionRange(o,o),bc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Pi.current?.setSelectionRange(o,s)})},[bc,Vn,so,Sc,aa,di]),Fc=Z.useCallback(e=>{Pc(e,`copy`)},[Pc]),Ic=Z.useCallback(e=>{Pc(e,`cut`)},[Pc]),Lc=e=>{let t=Pi.current,n=t&&document.activeElement===t?t.selectionStart??Li.current:Li.current;return Ps(e,n)},Rc=()=>{Gs(zr)||Pi.current?.focus()},zc=e=>{let t=Lc(di.length),n=Wo(di,t,Ri.current),r=di.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():Xc(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=ss(di,o,s,`@${i}`);oa(c.text,[i],a),Li.current=c.caret,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=c.caret,Pi.current.selectionEnd=c.caret),bc(),xc(c.text,c.caret)}),O(!1),A(``),Rc()},Bc=e=>{let t=Lc(di.length),n=Wo(di,t,Ri.current),r=di.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=ss(di,i,a,`@${e}`);ki(o.text,t=>is(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Li.current=o.caret,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=o.caret,Pi.current.selectionEnd=o.caret),bc(),xc(o.text,o.caret)}),O(!1),A(``),Rc()},Vc=J(e=>{$i.current||($i.current=!0,(async()=>{try{let t=ri.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){Br.error(u(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await yt(e.id,{directory:t}),!ii(e.id,t)){Br.error(u(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Lr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=aa(),r=Lc(n.text.length),i=Wo(n.text,r,Ri.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=fi().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,l={id:`session:${e.id}:${N()}`,kind:`session`,sessionId:e.id,display:j({trigger:`@`,icon:`chat-thread`,label:o})},d=_i(s,c,l,{inlineBoundaries:!0,padDocumentEdges:!0}),f=ls(d.document.text,d.caret);Li.current=f,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=f,Pi.current.selectionEnd=f),bc(),xc(d.document.text,f)}),O(!1),A(``),Rc()}catch{Br.error(u(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{$i.current=!1}})())}),Hc=J(e=>{let t=aa(),n=Lc(t.text.length),r=Wo(t.text,n,Ri.current)??Fo(t.text,n);if(!r)return!1;let i=_i(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=ls(i.document.text,i.caret);return Li.current=o,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=o,Pi.current.selectionEnd=o),bc(),xc(i.document.text,o),a&&(P(!1),W(!1))}),Rc(),a}),Uc=e=>{Hc({id:`skill:${e.name}:${N()}`,kind:`skill`,skillName:e.name,display:j({trigger:`/`,icon:`book-open`,label:e.name})})&&te(``)},Wc=(e,t)=>{let n=Lc(di.length),r=Wo(di,n,Ri.current),i=di.substring(0,n).lastIndexOf(`#`),a=r?.start??(i===-1?n:i),o=r?.end??n,s=`${di.substring(0,a)}#${t} ${di.substring(o)}`;ki(s);let c=a+t.length+2;Li.current=c,requestAnimationFrame(()=>{Pi.current&&(Pi.current.selectionStart=c,Pi.current.selectionEnd=c),bc(),xc(s,c)}),re(!1),oe(``),Rc()},Gc=(e,t=!1)=>{if(!Bm(Ln,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Hc({id:`skill:${e.name}:${N()}`,kind:`skill`,skillName:e.name,display:j({trigger:`/`,icon:`book-open`,label:e.name})})&&L(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Hc({id:`command:${e.name}:${N()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:j({trigger:`/`,icon:`command`,label:e.name})})){L(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=No(r,new Set([...co,e.name.toLowerCase()]),r.length);pi(i?.text??r);let a=Pi.current;if(a&&(a._commandMetadata=e),P(!1),L(``),t){tc({presetText:n});return}let o=()=>{if(!Gs(zr)&&Pi.current){try{Pi.current.focus({preventScroll:!0})}catch{Pi.current.focus()}Pi.current.setSelectionRange(Pi.current.value.length,Pi.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Hn&&Pi.current&&!zr&&Pi.current.focus()},[Hn,zr]),Z.useEffect(()=>{zr||he(null)},[zr]);let Kc=zn.abortPrompt.sessionID,qc=zn.abortPrompt.clear;Z.useEffect(()=>{Kc&&Kc!==Hn&&qc()},[Hn,Kc,qc]),Z.useEffect(()=>{Ji.current=!!(Hn||Gn)},[Hn,Gn]);let Jc=Z.useCallback(e=>{if(!e)return!1;if(e.files&&e.files.length>0)return!0;if(e.types){let t=Array.from(e.types).map(e=>e.toLowerCase());if(t.includes(`files`)||t.includes(`text/uri-list`)||t.includes(`codefiles`)||t.includes(`application/x-openchamber-file-path`)||t.some(e=>e.includes(`vnd.code.tree`)))return!0}return Yv(e).length>0},[]),Yc=Z.useCallback(e=>{if(!e)return[];let t=Array.from(e.files||[]);return t.length>0?t:Array.from(e.items||[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>!!e)},[]),Xc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(xa||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[xa]),Zc=e=>{if(!Jc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Hi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==w&&T(t),(Hn||Gn)&&!S&&C(!0)},Qc=e=>{Jc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Hn||Gn)&&!S&&C(!0))},$c=e=>{e.preventDefault(),e.stopPropagation(),Hi.current--,Hi.current<=0&&(Hi.current=0,C(!1),T(!1),Ec())},el=()=>{Hi.current=0,C(!1),T(!1),Ec()},tl=async e=>{if(Hi.current=0,!Jc(e.dataTransfer)){Ec();return}if(e.preventDefault(),e.stopPropagation(),C(!1),!Hn&&!Gn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Pi.current,r=ra.current;if(n){let t=n.selectionStart??Li.current,i=n.selectionEnd??t,a=ss(r,t,i,e);ki(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Li.current=a.caret,n.focus()})}else{let t=ss(r,r.length,r.length,e);ki(t.text)}Ec();return}let n=ex(e.dataTransfer);if(n.length>0){se()&&(qi.current=n),Mc(n),se()||Ec();return}let r=Yc(e.dataTransfer);if(r.length>0){let e=Re(r.map(e=>e.name)),t=$o(e,ra.current.slice(0,Pi.current?.selectionStart??ra.current.length),ra.current.slice(Pi.current?.selectionEnd??ra.current.length));Cc(t);for(let e of r)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.attachFileFailed`))}}Ec()},nl=e=>{Jc(e.dataTransfer)&&(e.preventDefault(),se()&&(Ui.current=!0,Dc()))},Q=Z.useRef(null),rl=Z.useRef(null),il=J((e=!0)=>{Ke.current=0;let t=()=>{let t=Pm(Pi);if(!t||(Fm(Pi),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),al=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Re(t.map(e=>e.name)),n=$o(e,ra.current.slice(0,Pi.current?.selectionStart??ra.current.length),ra.current.slice(Pi.current?.selectionEnd??ra.current.length));Cc(n)}for(let e of t)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.attachFileFailed`))}},[zn,Cc,u]),ol=Z.useCallback(async()=>{try{let e=await da?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6535
|
+
`);Br.error(u(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(il(!1),await al(r),il())}catch(e){console.error(`VS Code file pick failed`,e),Br.error(e instanceof Error?e.message:u(`chat.chatInput.toast.vscodePickFailed`))}},[al,il,u,da]),sl=Z.useCallback(()=>{if(se()){ol();return}Q.current?.click()},[ol]),cl=Z.useCallback(()=>{if(se()){ol();return}rl.current?.click()},[ol]),ll=Z.useCallback(async()=>{if(!hl()){cl();return}try{let e=await gl(20);if(e===null){cl();return}e.length>0&&(il(!1),await al(e),il())}catch(e){console.error(`Native photo pick failed`,e),Br.error(u(`chat.chatInput.toast.attachFileFailed`))}},[al,il,cl,u]),ul=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(il(!1),await al(t),e.target.value=``,il())},[al,il]),dl=`gap-x-1.5 gap-y-0`,fl=se(),pl=Ln.kind===`primary`&&qn&&!fl,ml=Z.useMemo(()=>(Ht?.selectedProjectId?rr.find(e=>e.id===Ht.selectedProjectId)??null:null)||(ir?rr.find(e=>e.id===ir)??null:null)||(rr[0]??null),[ir,Ht?.selectedProjectId,rr]),_l=Z.useMemo(()=>tx(ml?.path??null),[ml?.path]),vl=ml?nx(ml):null,yl=os(_l),bl=Xo(e=>_l?e.directories.get(_l)?.lastBranchesFetch??0:0),xl=fs(_l),Sl=!!yl?.all,Cl=Xo(e=>e.fetchBranches),[Tl,El]=Z.useState(!1);Z.useEffect(()=>{!pl||!_l||!la||xl!==null||ja(_l,la,{silent:!0})},[ja,la,xl,_l,pl]),Z.useEffect(()=>{if(!pl||!_l||!ml||!la||xl!==!0){El(!1);return}let e=!bl||Date.now()-bl>3e4;if(Sl&&!e){El(!1);return}let t=!1;return El(!Sl),Cl(_l,la).finally(()=>{t||El(!1)}),()=>{t=!0}},[Cl,la,ml,bl,Sl,xl,_l,pl]);let Dl=Qo(_l),Ol=yl?.current?.trim()||Dl?.trim()||``,kl=Z.useMemo(()=>{if(!ml)return null;let e=tx(ml.path);return!e||!Ol?null:{value:e,label:Ol}},[ml,Ol]),Al=Z.useMemo(()=>{if(!ml)return[];let e=_l?on.get(_l)??on.get(ml.path)??[]:[];return Nr({projectRoot:tx(ml.path)??``,rootBranch:Ol,worktrees:e,pendingBootstrapDirectory:Ht?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[on,Ht?.bootstrapPendingDirectory,ml,Ol,_l]),jl=Z.useMemo(()=>tx(Ht?.bootstrapPendingDirectory??null)??tx(Ht?.directoryOverride??null)??_l,[Ht?.bootstrapPendingDirectory,Ht?.directoryOverride,_l]),Ml=Z.useMemo(()=>{let e=tx(Ht?.bootstrapPendingDirectory??null);return!!(Ht?.preserveDirectoryOverride||Ht?.pendingWorktreeRequestId||e&&e===jl)},[Ht?.bootstrapPendingDirectory,Ht?.pendingWorktreeRequestId,Ht?.preserveDirectoryOverride,jl]),Nl=Z.useMemo(()=>{let e=[];return kl&&e.push(kl),e.push(...Al),!jl||e.some(e=>e.value===jl)||!Ml?e:[...e,{value:jl,label:ca(jl)}]},[kl,jl,Ml,Al]),Pl=Z.useMemo(()=>av({selectedDirectory:jl,projectRootOption:kl,worktreeOptions:Al}),[kl,jl,Al]),Fl=Tg()===`mini-chat`,Il=Z.useMemo(()=>Fl||Ca!==!0||!Ea||Ea.isClean?!1:ug(Ea.files),[Ea,Ca,Fl]),Ll=Z.useMemo(()=>!jl||kl?.value===jl||Al.some(e=>e.value===jl),[kl?.value,jl,Al]);Z.useEffect(()=>{Ht?.open&&(!Ht.preserveDirectoryOverride&&!Ht.bootstrapPendingDirectory||!jl||!Ll||(Ht.preserveDirectoryOverride&&ri.getState().setDraftPreserveDirectoryOverride(!1),Ht.bootstrapPendingDirectory&&ri.getState().setDraftBootstrapPendingDirectory(null)))},[Ht?.bootstrapPendingDirectory,Ht?.open,Ht?.preserveDirectoryOverride,Ll,jl]);let Rl=Z.useMemo(()=>xl!==!0||Tl?!1:kl?!0:Al.length>0,[Tl,kl,xl,Al.length]),zl=Z.useCallback(e=>{if(ri.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=rr.find(t=>t.id===e);t&&(ir!==e&&ar(e),rn({projectId:e,directoryOverride:t.path},{force:!0}))},[ir,rr,ar,rn]),Bl=Z.useCallback(e=>{ri.getState().newSessionDraft?.pendingWorktreeRequestId||ml&&rn({projectId:ml.id,directoryOverride:e},{force:!0})},[ml,rn]),Vl=Z.useCallback(e=>{let t=e.icon?Aa[e.icon]:null,n=e.color?Na[e.color]:void 0,r=(0,$.jsx)(X,{name:t??`folder`,className:`h-3.5 w-3.5`,style:n?{color:n}:void 0});return(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-muted-foreground`,children:e.iconImage?(0,$.jsx)(wa,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:nx(e)})]})},[]);Z.useEffect(()=>{!pl||!ml||!jl||Ht?.pendingWorktreeRequestId||Ht?.bootstrapPendingDirectory||Ht?.preserveDirectoryOverride||Nl.some(e=>e.value===jl)||rn({projectId:ml.id,directoryOverride:ml.path})},[Nl,Ht?.bootstrapPendingDirectory,Ht?.pendingWorktreeRequestId,Ht?.preserveDirectoryOverride,jl,ml,rn,pl]);let Hl=Z.useCallback(()=>{qe(),Oe(!0),Pi.current?.blur()},[qe]),Ul=Z.useCallback(()=>{qe(),je(!0),Pi.current?.blur()},[qe]);Z.useEffect(()=>{if(!zr||typeof document>`u`)return;let e=document.getElementById(`mobile-overlay-root`);e||(e=document.createElement(`div`),e.id=`mobile-overlay-root`,document.body.appendChild(e));let t=e,n=()=>Ge(Jg(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[qg]}),()=>r.disconnect()},[zr]);let Wl=We||!!me||we||Ae||So||wo,Gl=Bn(Fr.find(e=>e.id===Ln.selection.value.providerID),Ln.selection.value.modelID,u(`chat.modelControls.selectModel`)),Kl=Ln.selection.value.variant?.trim(),ql=J(e=>{le(t=>Lo(t,e.rows)),de(t=>t===e.highlightedIndex?t:e.highlightedIndex)}),Jl=J(e=>Bm(Ln,e)),Yl=J(e=>{if(M){ea.current?.acceptIndex(e,!0);return}if(U){ta.current?.acceptIndex(e);return}D&&Qi.current?.acceptIndex(e)}),Xl=J(()=>{Ri.current=null,P(!1),W(!1),re(!1),O(!1),le([]),de(0)}),Zl=wl({enabled:zr&&Ln.kind===`primary`,isMobile:zr,text:di,textPresetEpoch:ci.textPresetEpoch,placeholder:Za,modelLabel:Gl,modelVariantLabel:Kl?xt(Kl):``,canSend:Es,canAbort:ks,attachmentCount:Vn.length,suppressed:Wl,attachAria:u(`chat.chatInput.actions.addAttachment`),attachTitle:u(`chat.chatInput.actions.addAttachment`),attachPhotosLabel:u(`chat.chatInput.actions.attachPhotos`),attachFilesLabel:u(`chat.chatInput.actions.attachFiles`),attachCancelLabel:u(`chat.chatInput.actions.attachCancel`),sendAria:u(`chat.chatInput.actions.sendMessageAria`),queueAria:u(`chat.chatInput.actions.queueMessageAria`),stopAria:u(`chat.chatInput.actions.stopGeneratingAria`),modelAria:u(`chat.modelControls.selectModel`),modelId:Ln.selection.value.modelID,providerId:Ln.selection.value.providerID,agentName:Ln.selection.value.agent??``,agentLabel:Un(Pr,Ln.selection.value.agent??void 0),agentAria:u(`chat.modelControls.selectAgent`),attachments:Vn,removeAttachmentNamedAria:e=>u(`chat.fileAttachment.actions.removeNamed`,{name:e}),onText:(e,t,n)=>{let r=Ps(e.length,n?.end??n?.start??e.length);if(Li.current=r,t){Pi.current&&(Pi.current.value=e),ki(e);return}let i=ra.current,a=Ce(i,e,Vn.filter(Ne).map(e=>e.filename)),o=a?.text??e;Pi.current&&(Pi.current.value=o),ki(o);let s=Ps(o.length,n?.end??n?.start??o.length);if(Li.current=s,xc(o,s),!a)return;let c=new Set(a.removedFilenames.map(e=>e.toLowerCase()));for(let e of Vn)c.has(e.filename.toLowerCase())&&zn.removeAttachment(e.id)},onSend:e=>{Pi.current&&(Pi.current.value=e),ws({text:e,applyDocument:ki,submit:nc})},onAbort:mc,onAttach:qe,onFiles:(e,t)=>{t.length>0&&Br.error(u(`chat.chatInput.toast.someFilesSkipped`,{summary:t.join(`
|
|
6536
|
+
`)})),e.length!==0&&al(e)},onRemoveAttachment:e=>{zn.removeAttachment(e)},onOpenModel:()=>vs(`model`),onCycleAgent:()=>hc(),onOpenAgent:Qs,showScrollToBottom:!!(o&&s),scrollAria:u(`chat.scrollToBottom.aria`),onScrollToBottom:s??(()=>{}),autocompleteOpen:ce.length>0&&(M||U||D),autocompleteHighlightedIndex:ue,autocompleteRows:ce,caret:Li.current,onAutocompleteAccept:Yl,onAutocompleteDismiss:Xl,chipHighlights:_o}),Ql=Z.useRef(null);st(Zl?Ql:null,()=>{let e=Ql.current?.getBoundingClientRect().height??0;Ls(document.documentElement,e)});let $l=Z.useRef(!1);$l.current=So||wo;let eu=Z.useRef(!1),tu=Z.useRef(0),nu=Z.useRef(0),ru=J(()=>{let e=ri.getState().stagedMessageEdit;!e||e.sessionId!==Hn||window.setTimeout(()=>{let t=ri.getState().stagedMessageEdit,n=document.activeElement,r=yy({surfaceKind:Ln.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:Vs(),focusHeld:Date.now()<nu.current,overlayOpen:tu.current>0||$l.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<Ke.current});r.action===`disarm`&&ri.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!zr||Ie()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{tu.current+=1},t=()=>{if(tu.current=Math.max(0,tu.current-1),eu.current){eu.current=!1;return}if(!Ye.current||$l.current||tu.current>0)return;if(ya()){Ye.current=!1;return}Ye.current=!1,nu.current=Date.now()+600,Pi.current?.focus(),document.activeElement===Pi.current&&ye(!0);let e=()=>{let e=Pi.current;!e||document.activeElement!==e||(iu.current??e).scrollIntoView({block:`end`})};ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),_e.current!==null&&(window.clearTimeout(_e.current),_e.current=null),ge.current=window.setTimeout(()=>{ge.current=null,e()},300),_e.current=window.setTimeout(()=>{_e.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),_e.current!==null&&(window.clearTimeout(_e.current),_e.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[zr]),Z.useEffect(()=>{if(!zr)return;if(Wl){(ve||Date.now()-Je.current<800)&&(Ye.current=!0);return}if(!Ye.current)return;let e=window.setTimeout(()=>{if(Ye.current=!1,ya())return;let e=Pi.current;e&&document.activeElement!==e&&e.focus({preventScroll:Ie()})},180);return()=>window.clearTimeout(e)},[zr,Wl,ve]),Z.useEffect(()=>{if(!zr||Ie()||typeof document>`u`||ve||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Pi.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[zr,ve]),Z.useEffect(()=>{ze(``)},[Me]);let iu=Z.useRef(null),au=zr?`px-1.5 py-1.5`:fl?`px-1.5 py-1`:`px-2.5 py-1.5`,ou=zr?`h-8 w-8`:fl?`h-5 w-5`:`h-6 w-6`,su=zr?`h-4 w-4`:fl?`h-3.5 w-3.5`:`h-4 w-4`,cu=zr?`h-6 w-6`:`size-full`,lu=zr?`h-[1.125rem] w-[1.125rem]`:fl?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,du=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,vm),fu=Y(du,ou),pu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,ou),mu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,`h-6 w-6`);Z.useEffect(()=>()=>{xo.current&&=(clearTimeout(xo.current),null)},[]);let hu=zr?(0,$.jsxs)(`div`,{"data-composer-action":`true`,className:`composer-mobile-model-controls flex min-w-0 flex-1 items-center justify-end gap-x-1.5`,children:[(0,$.jsx)(ox,{onOpenAgentPanel:Qs,onCycleAgent:()=>{qe(),hc()},agentName:Ln.selection.value.agent,agents:Pr,disabled:Rr}),(0,$.jsx)(sx,{onOpenModel:()=>vs(`model`),providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID,provider:Fr.find(e=>e.id===Ln.selection.value.providerID),variant:Ln.selection.value.variant})]}):null,gu=(0,$.jsxs)(`div`,{className:`oc-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(wd,{attachments:Vn,onShowPopup:Gr,onRemoveAttachedFile:Tc}),Ln.kind===`primary`?(0,$.jsx)(Od,{attachedFiles:Vn,onAddVSCodeFile:(e,t,n)=>{Xn&&xn(Xn,()=>ei.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Xn)return xn(Xn,()=>ei.getState()).addVSCodeSelection(e,t)}}):null]}),_u=_o?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Mv,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),vu=zr?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,ks&&`oc-mobile-composer-compact-chrome--aborting`,Es&&!ks&&`oc-mobile-composer-compact-chrome--sending`,o&&s&&`oc-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(ux,{isVSCode:fl,footerIconButtonClass:fu,iconSizeClass:lu,handlePickLocalFiles:sl,handlePickLocalImages:cl,openIssuePicker:$s,openPrPicker:ec,onOpenMobileSheet:Hl,onOpenAndroidPickSheet:hl()?Ul:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[o&&s?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(Cg,{placement:`compact`,visible:o,onClick:s})}):null,ks||Es?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(fx,{isMobile:!0,compact:!0,footerIconButtonClass:fu,stopFooterIconButtonClass:pu,compactCircleButtonClass:mu,sendIconSizeClass:su,stopIconSizeClass:cu,canSend:Es,canAbort:ks,hasContent:!1,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Wn,submissionBlocked:c,sendPhase:Rs,queueFrozen:Ts,queueFallbackAvailable:ks||Os,onPrimaryAction:nc,onAbort:mc})}):null]})]}):null,yu=zr?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`oc-mobile-composer-full-chrome flex w-full min-w-0 items-center gap-x-1.5`,"data-composer-action":`true`,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(ux,{isVSCode:fl,footerIconButtonClass:fu,iconSizeClass:lu,handlePickLocalFiles:sl,handlePickLocalImages:cl,openIssuePicker:$s,openPrPicker:ec,onOpenSettings:e,onOpenMobileSheet:Hl,onOpenAndroidPickSheet:hl()?Ul:void 0}),br?(0,$.jsx)(dx,{sessionId:Hn,draftOpen:Gn,draftEnabled:Ht.permissionAutoAcceptEnabled===!0,enabled:hr,saving:Hn?tn:!1,footerIconButtonClass:fu,iconSizeClass:lu,onSetDraftEnabled:Qt,onSetSessionEnabled:nn,onOpenSessionFirst:Xt,onToggleFailed:xr}):null,(0,$.jsx)(iy,{sessionId:Hn,directory:St??Yn,draftOpen:Gn}),(0,$.jsx)(ay,{length:di.length})]}),hu,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(fx,{isMobile:zr,footerIconButtonClass:fu,stopFooterIconButtonClass:pu,sendIconSizeClass:su,stopIconSizeClass:cu,canSend:Es,canAbort:ks,hasContent:!!xs,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Wn,submissionBlocked:c,sendPhase:Rs,queueFrozen:Ts,queueFallbackAvailable:ks||Os,onPrimaryAction:nc,onAbort:mc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,dl),children:[(0,$.jsx)(ux,{isVSCode:fl,footerIconButtonClass:fu,iconSizeClass:lu,handlePickLocalFiles:sl,handlePickLocalImages:cl,openIssuePicker:$s,openPrPicker:ec,onOpenSettings:e,withTooltip:!0}),br?(0,$.jsx)(dx,{sessionId:Hn,draftOpen:Gn,draftEnabled:Ht.permissionAutoAcceptEnabled===!0,enabled:hr,saving:Hn?tn:!1,footerIconButtonClass:fu,iconSizeClass:lu,onSetDraftEnabled:Qt,onSetSessionEnabled:nn,onOpenSessionFirst:Xt,onToggleFailed:xr}):null,(0,$.jsx)(iy,{sessionId:Hn,directory:St??Yn,draftOpen:Gn}),(0,$.jsx)(ay,{length:di.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,dl),children:[(0,$.jsx)(ix,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Pi,selectionAdapter:kr}),(0,$.jsx)(ax,{radius:Ya,isMobile:zr,footerIconButtonClass:fu,footerPaddingClass:au,iconSizeClass:lu,sendIconSizeClass:su,onInsert:ic,onInsertAndSend:ac,onContentHeightChange:yc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(fx,{isMobile:zr,footerIconButtonClass:fu,stopFooterIconButtonClass:pu,sendIconSizeClass:su,stopIconSizeClass:cu,canSend:Es,canAbort:ks,hasContent:!!xs,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Wn,submissionBlocked:c,sendPhase:Rs,queueFrozen:Ts,queueFallbackAvailable:ks||Os,onPrimaryAction:nc,onAbort:mc})]})]}),bu=J(()=>{if(zr){nu.current=Date.now()+600;let e=()=>{Pi.current?.focus({preventScroll:Ie()}),document.activeElement===Pi.current&&ye(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Fm(Pi))return;let e=Pm(Pi);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),xu=St??Yn,{goal:Su,enabled:Cu}=Qv(Hn??``,xu),wu=(0,$.jsx)(Ep,{onEditMessage:Xs,onSendMessage:Zs,onEditCommitted:bu,draftKey:Xn,scope:Mo,draftTarget:Xn?{key:Xn,expectedRevision:()=>zn.getDraft(Xn)?.revision??`absent`}:null,clientPendingItems:Us,onRemoveClientPending:e=>{let t=mn.getState().removeEstablishingFollowUp(e);t&&(t.content&&pi(t.content),t.attachments.length>0&&zn.restoreAttachments(t.attachments))},trailing:Hn&&Cu&&Su?(0,$.jsx)(ry,{sessionId:Hn,directory:xu}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:iu,onSubmit:e=>{e.preventDefault(),nc()},onPointerDownCapture:e=>{if(!zr)return;let t=e.target;t instanceof Element&&(t.closest(`textarea[data-chat-input="true"]`)||t.closest(`[data-chat-prompt-attachments="true"]`)||t.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(qe(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,Ua&&`flex h-full min-h-0 flex-col pt-4`,Wa&&`flex h-full min-h-0 flex-col pt-1`,zr&&`bottom-safe-area oc-mobile-composer`),"data-native-ios-composer":Zl?`true`:void 0,style:zr&&Ie()&&!Zl&&Zr>0&&!ve?{marginBottom:`${Zr}px`}:void 0,children:[qn&&!Ua&&!zr&&!fl&&!Fl?(0,$.jsx)(`div`,{className:`chat-input-column mb-7 text-center`,children:(0,$.jsx)(`h1`,{className:`text-balance text-2xl font-normal tracking-tight text-foreground md:text-3xl`,children:rx(vl?u(`chat.emptyState.draftTitleWithProject`,{project:vl}):u(`chat.emptyState.draftTitle`),vl)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Ka&&`flex flex-1 min-h-0 flex-col`),children:[Zl?null:(0,$.jsx)(Td,{attachments:Vn,onShowPopup:Gr,onRemoveAttachedFile:Tc}),(0,$.jsx)(Wp,{}),ns&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[cs>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:va?.colors?.surface?.elevated,borderColor:va?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:va?.colors?.status?.info},children:cs}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:ds,"aria-label":u(`chat.chatInput.reviewCommentsRemove`),title:u(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,rs>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:va?.colors?.surface?.elevated,borderColor:va?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:va?.colors?.status?.info},children:rs}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>us(`preview-console`),"aria-label":u(`chat.chatInput.devServerLogsRemove`),title:u(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,as>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:va?.colors?.surface?.elevated,borderColor:va?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:va?.colors?.status?.info},children:as}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>us(`preview-annotation`),"aria-label":u(`chat.chatInput.previewContextRemove`),title:u(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),Eo&&!fl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Co(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Eo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Eo.author.avatarUrl,alt:Eo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,Eo.number,Eo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:u(`chat.chatInput.linked.byAuthor`,{author:Eo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Eo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Eo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Do(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.issue.removeAria`),title:u(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),Oo&&!fl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>To(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Oo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Oo.author.avatarUrl,alt:Oo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[u(`chat.chatInput.linked.pr.number`,{number:Oo.number}),Oo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:u(`chat.chatInput.linked.byAuthor`,{author:Oo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Oo.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[Oo.head,` → `,Oo.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Oo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Ao(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":u(`chat.chatInput.linked.pr.removeAria`),title:u(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(lx,{sessionId:Hn,directory:St??Yn}),(0,$.jsxs)(`div`,{className:zr?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:zr?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:zr?`oc-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:Ql,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(cx,{showAbortStatus:Ma,showAssistantStatus:!1,showTodos:!0,leftAccessory:Gn||!Il?null:(0,$.jsx)(xg,{})}),!zr&&pl?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[ml?(0,$.jsxs)(ka,{value:ml.id,open:He,onValueChange:zl,onOpenChange:e=>{Ue(e),e||Ve(``)},children:[(0,$.jsx)(Ba,{asChild:!0,size:`sm`,children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex h-6 min-w-0 w-fit max-w-[42vw] items-center rounded-lg !border-0 px-1.5 py-1 pr-1.5 typography-micro font-medium text-foreground/80 transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5 sm:max-w-[18rem]`,gm),children:[(0,$.jsx)(ba,{children:Vl(ml)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`})]})}),(0,$.jsxs)(Oa,{fitContent:!0,children:[(0,$.jsx)(Va,{autoFocus:!0,value:Be,onChange:e=>Ve(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:u(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),rr.filter(e=>za(nx(e),Be)||za(e.path,Be)).map(e=>(0,$.jsx)(Ra,{value:e.id,className:`max-w-[24rem] truncate`,children:Vl(e)},e.id)),(0,$.jsx)(Ta,{}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left typography-ui-label text-foreground hover:bg-interactive-hover`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),Ue(!1),requestAnimationFrame(()=>gt.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,gm),onClick:()=>gt.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]}),ml&&Rl?(0,$.jsx)(fv,{directory:jl,projectDirectory:_l,label:Pl,projectRootOption:kl,worktreeOptions:Al,onSelectDirectory:Bl}):null]}):null,zr&&pl?(0,$.jsxs)(`div`,{className:`oc-mobile-draft-target-selectors mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[ml?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] shrink items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,gm),onClick:()=>Pe(`project`),children:Vl(ml)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,gm),onClick:()=>gt.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]}),ml&&Rl?(0,$.jsx)(fv,{directory:jl,projectDirectory:_l,label:Pl,projectRootOption:kl,worktreeOptions:Al,onSelectDirectory:Bl,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,wu]})}),(0,$.jsx)(`div`,{className:Y(!zr&&`contents`,zr&&`contents`,Wa&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:zr?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(W_,{value:di,attachments:[],disabled:!Hn&&!Gn||Wn&&!Rs.establishing,pending:ks||Rs.inFlight&&!Rs.establishing,isMobile:zr,onSubmit:nc,"data-mobile-composer-surface":zr?`true`:void 0,"data-session-swipe-surface":zr?`true`:void 0,expanded:Ka,focusedTone:g===`shell`?`info`:`primary`,className:Y(`relative z-10`,S&&`ring-2 ring-primary ring-offset-2`,Xr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,zr&&`oc-mobile-composer-surface`),style:{borderRadius:Ya},ref:Vi,onDropCapture:nl,onDragEnter:Zc,onDragOver:Qc,onDragLeave:$c,onDrop:tl,onDragEnd:el,autoResize:!1,disableInputWhilePending:!1,contentClassName:Ka?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:gu,highlightedContent:_u,highlightRef:Fa,inputRef:Pi,textLayoutClassName:Y(Fb,Ka?Y(`h-full min-h-0`,zr?`py-2.5`:`py-4`):zr?`py-2.5`:`pt-4 pb-2`,g===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Ka&&`flex-1 min-h-0`),inputStyle:{flex:Ka?`1 1 auto`:`none`,height:!Ka&&fe?`${fe.height}px`:void 0,maxHeight:!Ka&&fe?`${fe.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":Ka?`100%`:fe?`${fe.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!Ka&&fe?`${fe.maxHeight}px`:`none`,borderTopLeftRadius:Ya,borderTopRightRadius:Ya},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,au,zr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,dl)),footerStyle:{borderBottomLeftRadius:Ya,borderBottomRightRadius:Ya},footerContent:yu,placeholder:Xa,onChange:(e,t)=>jc(t),textareaProps:{readOnly:Xr,onCompositionStart:()=>{Ii.current=!0},onCompositionEnd:e=>{Ii.current=!1;let t=e.currentTarget;Sc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Ac,onKeyDown:lc,onCopy:Fc,onCut:Ic,onPaste:Nc,onDragEnter:Zc,onDragOver:Qc,onDropCapture:nl,onDrop:tl,onDragEnd:el,onKeyUp:dc,onClick:()=>{dc()},onScroll:e=>{dc();let t=e.currentTarget.scrollTop;Fa.current&&(Fa.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Ii.current){Li.current=r;return}let i=kv(n,r,[...Te(di,Vn.filter(Ne).map(e=>e.filename)),...Ov(di,so.keys()),...li.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Li.current=i.end):Li.current=n,dc()},onFocus:()=>{if(zr){if(Date.now()<Ke.current){let e=Pi.current;e&&e.blur();return}be.current!==null&&(window.clearTimeout(be.current),be.current=null),ye(!0)}},onBlur:e=>{if(Ii.current=!1,Li.current=e.currentTarget.selectionStart??Li.current,ru(),zr){if(Date.now()<nu.current){let e=Pi.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<nu.current&&document.activeElement!==e&&e.focus()},50);return}}if(Je.current=Date.now(),Ie()){ye(!1);return}be.current!==null&&window.clearTimeout(be.current),be.current=window.setTimeout(()=>{be.current=null,ye(!1)},120)}},autoCorrect:zr?`on`:`off`,autoCapitalize:zr?`sentences`:`off`,spellCheck:zr||$r,fillContainer:Ka,rows:1},children:[(0,$.jsx)(hh,{}),S&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ya},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:du,onClick:()=>sl(),title:u(`chat.chatInput.actions.attachFiles`),"aria-label":u(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(lu,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:u(w?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(Io,{ref:ea,searchQuery:F,directory:Yn,onCommandSelect:Gc,onClose:()=>P(!1),commandPolicy:Jl,commandContext:Qn,onRowsChange:Zl?ql:void 0,style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0}),U&&(0,$.jsx)(Yp,{ref:ta,searchQuery:K,directory:Yn,onSkillSelect:Uc,onClose:()=>W(!1),onRowsChange:Zl?ql:void 0,style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0}),ne&&(0,$.jsx)(Ko,{ref:na,searchQuery:ae,onSnippetSelect:Wc,onClose:()=>re(!1),style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(ts,{ref:Qi,searchQuery:k,onFileSelect:zc,onAgentSelect:Bc,onSessionSelect:Vc,onClose:()=>O(!1),onRowsChange:Zl?ql:void 0,style:Ua&&yo?{left:`${yo.left}px`,top:`${yo.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${yo.left+8}px))`,maxHeight:`${yo.maxHeight}px`,transform:yo.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),zr?(0,$.jsx)(ax,{radius:Ya,isMobile:zr,footerIconButtonClass:fu,footerPaddingClass:au,iconSizeClass:lu,sendIconSizeClass:su,onInsert:ic,onInsertAndSend:ac,onContentHeightChange:yc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),zr?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[vu,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!di.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:di.trim()?di:Za})]}):null]}),zr?(0,$.jsx)(ix,{className:`hidden`,composerTextareaRef:Pi,selectionAdapter:kr,mobilePanel:me,onMobilePanelChange:he}):null]}),Gn&&!Ua&&!zr&&!fl&&!Fl?(0,$.jsx)(L_,{onSubmit:rc,className:`chat-input-column mt-4`}):null]}),f.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Ib,{popup:f,onOpenChange:qr,isMobile:zr})}):null,(0,$.jsx)(m_,{open:So,onOpenChange:Co,mode:`select`,onSelect:e=>{Do(e),Ao(null)}}),(0,$.jsx)(__,{open:wo,onOpenChange:To,onSelect:e=>{Ao(e),Do(null)}}),(0,$.jsx)(Zu,{open:or,onOpenChange:cr,projectDirectory:St??Yn??null,submitting:dr,onConfirm:Ha}),(0,$.jsx)(`input`,{ref:Q,type:`file`,multiple:!0,className:`hidden`,onChange:ul,accept:`*/*`}),(0,$.jsx)(`input`,{ref:rl,type:`file`,multiple:!0,className:`hidden`,onChange:ul,accept:`image/*`}),null,zr?(0,$.jsx)(_a,{id:`android-media-pick-sheet`,open:Ae,onOpenChange:e=>{e||je(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:u(`chat.chatInput.actions.addAttachment`)}),ariaLabel:u(`chat.chatInput.actions.addAttachment`),closeAriaLabel:u(`mobile.surface.closeAria`),resizeAriaLabel:u(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Ye.current=!1,je(!1),requestAnimationFrame(ll)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:u(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Ye.current=!1,je(!1),requestAnimationFrame(sl)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:u(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,zr&&pl&&ml?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(_a,{id:`mobile-draft-project-picker-sheet-${Fe}`,open:Me===`project`,onOpenChange:e=>{e||Pe(null)},ariaLabel:u(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:u(`mobile.surface.closeAria`),resizeAriaLabel:u(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(Va,{value:Le,onChange:e=>ze(e.target.value),placeholder:u(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(pa,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:rr.filter(e=>za(nx(e),Le)||za(e.path,Le)).map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{zl(e.id),Pe(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:Vl(e)}),e.id===ml.id?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground`}):null]},e.id))})}),(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-4 pt-1`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg border-t border-border/50 px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{Pe(null),gt.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:u(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},vx=e=>{let t=(0,Q.c)(3),n=Hm(),r=e.surface??n;if(r&&!r.active)return null;let i=r??void 0,a;return t[0]!==e||t[1]!==i?(a=(0,$.jsx)(_x,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};vx.displayName=`ChatInput`;var yx=Z.memo(vx);function bx(e){return e.preventDefault()}function xx(e){e.preventDefault()}function Sx(e){return e.preventDefault()}function Cx(e){e.pointerType===`touch`&&e.preventDefault()}function wx(e){e.preventDefault()}function Tx(e){e.pointerType===`touch`&&e.preventDefault()}function Ex(){let e=(0,Q.c)(47),{t}=ct(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>go(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=J(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],Is(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await Gc(n),Br.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}Br.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=J(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Ie()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,disabled:i,onClick:C,children:[E,O]})})}),e[34]=i,e[35]=C,e[36]=E,e[37]=O,e[38]=k):k=e[38];let A;return e[39]!==d||e[40]!==s||e[41]!==S||e[42]!==k||e[43]!==b||e[44]!==x||e[45]!==_?(A=(0,$.jsx)(`div`,{ref:o,children:(0,$.jsx)(_a,{id:`image-save-actions-sheet`,open:s,onOpenChange:d,title:b,ariaLabel:_,closeAriaLabel:x,resizeAriaLabel:S,fitContent:!0,children:k})}),e[39]=d,e[40]=s,e[41]=S,e[42]=k,e[43]=b,e[44]=x,e[45]=_,e[46]=A):A=e[46],A}var Dx=(e,t)=>{if(t.length===0)return e;let n=new Map(t.map(e=>[e.info.id,e])),r=!1,i=e.map(e=>{if(Ji(e.parts))return e;let t=n.get(e.info.id);return t?(r=!0,t):e}),a=r?i:e,o=new Set(e.map(e=>e.info.id)),s=t.filter(e=>!o.has(e.info.id));return s.length===0?a:[...a,...s]},Ox=(e,t)=>{if(e.length===0)return!1;let n;for(let t of e){let e=t.info.time?.created;typeof e==`number`&&(n===void 0||e>n)&&(n=e)}return!t.resolvedSessionStatus||typeof t.sessionStatusObservedAt!=`number`||typeof n!=`number`||n>t.sessionStatusObservedAt},kx=e=>{let t=e.boundary.kind===`exhausted`,n=e.boundary.kind===`has-more`,r=t&&!e.assistantComplete,i=n||r;return{complete:t&&e.assistantComplete,canLoadEarlier:i}},Ax=e=>e.syncLoading||e.assistantLoading,jx=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Mx=e=>e.isLoadingOlder,Nx=e=>!e.isMobile&&e.isLoadingOlder,Px=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Fx=e=>e.hasTranscriptShell||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,Ix=e=>{let{sessionId:t,messages:n,retained:r}=e;return t?n.length>0?{messages:n,retained:{sessionId:t,messages:n}}:r?.sessionId===t?{messages:r.messages,retained:r}:{messages:n,retained:null}:{messages:n,retained:null}},Lx=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Rx=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,zx=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Bx=e=>{let t=(0,Q.c)(8),{providerId:n,modelId:r,label:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3.5`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{role:`img`,"aria-label":i,className:`inline-flex size-3.5 shrink-0 items-center justify-center`,children:a}),t[1]=i,t[2]=o);let s;return t[3]!==i||t[4]!==r||t[5]!==n||t[6]!==o?(s=(0,$.jsx)(Ma,{modelId:r,providerId:n,alt:i,className:`size-3.5 shrink-0`,fallback:o}),t[3]=i,t[4]=r,t[5]=n,t[6]=o,t[7]=s):s=t[7],s},Vx=e=>{let t=(0,Q.c)(42),{t:n}=ct(),r=q(Hx),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&zx,i;t[0]===e?i=t[1]:(i=Y(`p-3`,e),t[0]=e,t[1]=i);let a;t[2]===n?a=t[3]:(a=n(`chat.container.readOnlySubagentPromptBanner`),t[2]=n,t[3]=a);let o;t[4]===a?o=t[5]:(o=(0,$.jsx)(`div`,{className:`rounded-2xl border border-border/70 bg-[var(--surface-background)] px-4 py-3 text-muted-foreground ${Rx}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,s;t[11]!==e.agentName||t[12]!==o?(s=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=s):s=t[13];let c=s,l=e.modelName||o,u;t[14]===n?u=t[15]:(u=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=u);let d=`${u}: ${c}`,f;t[16]===n?f=t[17]:(f=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=f);let p=`${f}: ${l}`,m=r&&zx,h;t[18]===m?h=t[19]:(h=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] p-3`,m),t[18]=m,t[19]=h);let g=r&&`oc-mobile-readonly-prompt-surface`,_;t[20]===g?_=t[21]:(_=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,g),t[20]=g,t[21]=_);let v;t[22]===n?v=t[23]:(v=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=v);let y;t[24]===v?y=t[25]:(y=(0,$.jsx)(`div`,{className:`text-muted-foreground ${Rx}`,children:v}),t[24]=v,t[25]=y);let b;t[26]!==d||t[27]!==c||t[28]!==p||t[29]!==l||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(b=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(la,{name:e.agentName,size:14,label:d}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:c,children:c})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Bx,{providerId:e.providerId,modelId:e.modelId,label:p}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:l,children:l})]})]}):null,t[26]=d,t[27]=c,t[28]=p,t[29]=l,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=b):b=t[34];let x;t[35]!==b||t[36]!==_||t[37]!==y?(x=(0,$.jsxs)(`div`,{className:_,children:[y,b]}),t[35]=b,t[36]=_,t[37]=y,t[38]=x):x=t[38];let S;return t[39]!==x||t[40]!==h?(S=(0,$.jsx)(`aside`,{className:h,children:x}),t[39]=x,t[40]=h,t[41]=S):S=t[41],S};function Hx(e){return e.isMobile}var Ux=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ct(),{currentTheme:n}=Ga(),r=Pt(Wx),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Xa,{width:140,height:140,className:`opacity-20`}),e[0]=a):a=e[0];let o;return e[1]!==r||e[2]!==t||e[3]!==i?(o=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-full w-full gap-6`,children:[a,r?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 max-w-md text-center px-4`,children:[(0,$.jsx)(`span`,{className:`typography-markdown font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`typography-meta`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`typography-markdown`,style:{color:i},children:t(`chat.emptyState.startNewChat`)})]}),e[1]=r,e[2]=t,e[3]=i,e[4]=o):o=e[4],o});function Wx(e){return e.error}var Gx=class e{static instance;sessionStartTimes=new Map;seenMessageIds=new Set;messageCreationTimes=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}recordSessionStart(e){this.sessionStartTimes.set(e,Date.now())}getSessionStartTime(e){return this.sessionStartTimes.get(e)}shouldAnimateMessage(e,t){if(e.role!==`assistant`||this.seenMessageIds.has(e.id))return!1;let n=this.sessionStartTimes.get(t);if(!n)return this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created),!1;let r=e.time.created>n-5e3;return r||(this.seenMessageIds.add(e.id),this.messageCreationTimes.set(e.id,e.time.created)),r}clearSession(e){this.sessionStartTimes.delete(e)}hasSessionTiming(e){return this.sessionStartTimes.has(e)}hasBeenAnimated(e){return this.seenMessageIds.has(e)}markMessageAsAnimated(e,t){this.seenMessageIds.add(e),this.messageCreationTimes.set(e,t)}clearAll(){this.sessionStartTimes.clear(),this.seenMessageIds.clear(),this.messageCreationTimes.clear()}getDebugInfo(){return{sessionStartTimes:new Map(this.sessionStartTimes),seenMessageIds:new Set(this.seenMessageIds),messageCreationTimes:new Map(this.messageCreationTimes)}}},Kx=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:xt(t)},qx=Z.memo(e=>{let t=(0,Q.c)(31),{isUser:n,isMobile:r,providerID:i,modelID:a,agentName:o,modelName:s,variant:c}=e,l;t[0]!==r||t[1]!==n||t[2]!==c?(l=!n&&!r?Kx(c):null,t[0]=r,t[1]=n,t[2]=c,t[3]=l):l=t[3];let u=l,d=s||`Assistant`,f,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=Y(`mb-1.5`),p=Y(`flex items-center justify-between gap-2`),t[4]=f,t[5]=p):(f=t[4],p=t[5]);let m;t[6]!==o||t[7]!==n||t[8]!==a||t[9]!==i?(m=(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:n?(0,$.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-primary/10 flex items-center justify-center`,children:(0,$.jsx)(X,{name:`user-3`,className:`h-4 w-4 text-primary`})}):(0,$.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,$.jsx)(Ma,{modelId:a,providerId:i,className:`h-4 w-4`,fallback:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-4 w-4`,style:{color:`var(${na(o).var})`}})})})}),t[6]=o,t[7]=n,t[8]=a,t[9]=i,t[10]=m):m=t[10];let h=n?`text-primary`:`text-foreground`,g;t[11]===h?g=t[12]:(g=Y(`inline-flex min-w-0 items-center gap-1.5 font-semibold typography-ui-header tracking-tight leading-tight`,h),t[11]=h,t[12]=g);let _=n?`You`:d,v;t[13]===_?v=t[14]:(v=(0,$.jsx)(`span`,{className:`truncate`,children:_}),t[13]=_,t[14]=v);let y;t[15]===u?y=t[16]:(y=u?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-normal leading-tight text-muted-foreground`,children:u}):null,t[15]=u,t[16]=y);let b;t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsxs)(`h3`,{className:g,children:[v,y]}),t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20];let x;t[21]!==o||t[22]!==r||t[23]!==n?(x=!n&&o&&(0,$.jsxs)(`div`,{className:Y(`agent-badge inline-flex items-center gap-1 cursor-default rounded font-normal leading-tight`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,na(o).class),children:[(0,$.jsx)(la,{name:o,size:10}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=r,t[23]=n,t[24]=x):x=t[24];let S;t[25]!==b||t[26]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b,x]}),t[25]=b,t[26]=x,t[27]=S):S=t[27];let C;return t[28]!==S||t[29]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m,S]})})}),t[28]=S,t[29]=m,t[30]=C):C=t[30],C}),Jx=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,Yx=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,Xx=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),Zx=(e,t)=>e.split(Yx).map((e,n)=>n%2==1?e:t(e)).join(``),Qx=e=>Zx(e,e=>e.replace(/ *\n/g,`
|
|
6537
|
+
`)),$x=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=Zx(e,Xx);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${Sc(t.name)})`;i=i.replace(t.token,e)}i=i.replace(Jx,(e,t,r)=>n.has(r)?`${t}[/${r}](${yc(r)})`:e)}return Qx(i)},eS=e=>(Jx.lastIndex=0,Jx.test(e)||e.includes(`[skill:`)),tS=e=>e===`markdown`?`markdown`:`plain`,nS=e=>{if(typeof window>`u`)return!1;let t=window.getSelection();if(!t||t.isCollapsed||t.rangeCount===0)return!1;let n=t.getRangeAt(0);return e.contains(n.startContainer)||e.contains(n.endContainer)},rS=Z.memo(({part:e,messageId:t,agentMention:n,messageParts:r})=>{let i=e,a=i.text,o=typeof a==`string`?a:i.content||i.value||``,[s,c]=Z.useState(!1),[l,u]=Z.useState(!1),d=q(e=>e.userMessageRenderingMode),f=q(e=>e.collapsibleUserMessages),p=pc(),m=Ei({directory:p,enabled:eS(o)}),h=Z.useMemo(()=>m.data??[],[m.data]),g=q(e=>e.openContextFile),{t:_}=ct(),v=tS(d),y=f&&!s,b=Z.useRef(null),x=Z.useMemo(()=>new Map(h.map(e=>[e.name,e])),[h]),S=Z.useMemo(()=>zf(r,o),[r,o]),C=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!Wn(t))continue;let n=t.text;if(typeof n==`string`)for(let t of cr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of fi()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${B}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),w=J(e=>{let t=x.get(e),n=typeof t?.path==`string`?t.path:``,r=xo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=p||vo(``,i)||`/`,o=()=>{g(a,i)};if(p&&!wo(i,p)){mc(i,p).then(o);return}o()});Z.useEffect(()=>{let e=b.current;if(!e)return;let t=()=>{f&&!s&&u(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[f,o,s]),Z.useEffect(()=>{f||(c(!1),u(!1))},[f]);let T=J(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??gc(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),w(n);return}let r=b.current;r&&(nS(r)||f&&!s&&l&&c(!0))}),E=J(e=>{e.stopPropagation(),c(!1)}),D=Z.useMemo(()=>Nf(o,{skillNames:new Set(x.keys()),citationIcons:S.icons,citationDisplayNames:S.displayNames,sessionMentions:C,agentNames:n?.name?new Set([n.name.toLowerCase(),n.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),[n,S,C,x,o]),O=Z.useMemo(()=>$x({textContent:o,agentMention:n,skillNames:new Set(x.keys()),decorateInlineReferences:!D}),[n,D,x,o]),k=(e,t)=>{if(!e)return null;if(v===`markdown`){let n=$x({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(Ns,{content:n,className:Y(`inline w-auto align-baseline [&_.markdown-content]:contents [&_.markdown-content_p]:inline [&_[data-markdown-size-spacer]]:inline`,`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,y&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1},t)}return(0,$.jsx)(Z.Fragment,{children:e},t)},A=e=>e.map((e,t)=>e.type===`text`?k(e.text,`text-${t}`):(0,$.jsx)(Vf,{decoration:e.decoration,onOpenSkill:w},`ref-${t}-${e.span.start}`)),j=Z.useMemo(()=>{if(D)return A(D);let e=[],t=0,r=!1,i;for(Jx.lastIndex=0;(i=Jx.exec(o))!==null;){let n=i[1]||``,r=i[2],a=i.index+n.length;x.has(r)&&(i.index>t&&e.push(o.slice(t,i.index)),n&&e.push(n),e.push((0,$.jsxs)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:e=>{e.stopPropagation(),w(r)},children:[`/`,r]},`skill-${a}-${r}`)),t=a+r.length+1)}t<o.length&&e.push(o.slice(t));let a=e.length>0?e:[o];return!n?.token||!o.includes(n.token)?a:a.flatMap((e,t)=>{if(r||typeof e!=`string`)return e;let i=e.indexOf(n.token);return i===-1?e:(r=!0,[e.slice(0,i),(0,$.jsx)(`a`,{href:hc(n.name),className:`text-primary hover:underline`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:n.token},`agent-${t}`),e.slice(i+n.token.length)])})},[n,w,D,A,x,o]);return!o||o.trim().length===0?null:(0,$.jsxs)(`div`,{className:`relative`,children:[f&&s&&(0,$.jsx)(`button`,{type:`button`,onClick:E,className:`absolute top-0 right-0 z-10 flex items-center justify-center rounded-sm bg-[var(--surface-elevated)] p-0.5 text-[var(--surface-mutedForeground)] hover:text-[var(--surface-foreground)] hover:bg-[var(--interactive-hover)] transition-colors`,"aria-label":_(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,s&&`pb-3`,v===`plain`&&`whitespace-pre-wrap`,y&&`line-clamp-10`,f&&l&&!s&&`cursor-pointer`),ref:b,onClick:T,children:v===`markdown`?D?A(D):(0,$.jsx)(Ns,{content:O,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,y&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1}):j})]},e.id||`${t}-user-text`)}),iS=[{variant:`static`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:t,children:e})},{variant:`generate-effect`,component:({children:e,className:t,...n})=>{if(e==null)return null;let r=typeof e==`string`?e:typeof e==`number`?String(e):Array.isArray(e)?e.map(e=>typeof e==`string`||typeof e==`number`?String(e):``).join(``):``;return r?(0,$.jsx)(`span`,{className:Y(`inline-block align-baseline`,t),children:r.split(``).map((e,t)=>(0,Z.createElement)(el.span,{...n,key:e+String(t),className:Y(`inline-block whitespace-pre align-baseline`),initial:{opacity:0},animate:{opacity:1},transition:{ease:`easeOut`,duration:.14,delay:Math.min(t*.0045,.14)}},e))}):null}},{variant:`glitch`,component:({children:e,className:t,...n})=>(0,$.jsxs)(`div`,{className:`group relative overflow-hidden font-medium`,children:[(0,$.jsx)(`span`,{...n,className:Y(`invisible`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 text-primary-muted transition-transform duration-500 ease-in-out`,`group-hover:-translate-y-full hover:duration-300`,t),children:e}),(0,$.jsx)(`span`,{...n,className:Y(`absolute top-0 left-0 translate-y-full text-primary-muted transition-transform duration-500`,`ease-in-out hover:duration-300 group-hover:translate-y-0`,t),children:e})]})},{variant:`hover-enter`,component:({children:e,className:t,...n})=>{if(typeof e!=`string`)return null;let r=.25,i=.025,a=e.split(``).map(e=>e===` `?`\xA0`:e);return(0,$.jsxs)(el.span,{...n,className:Y(`relative block select-none overflow-hidden whitespace-nowrap text-primary-muted`,t),initial:`initial`,whileHover:`hovered`,style:{lineHeight:.9},children:[(0,$.jsx)(`div`,{children:a.map((e,t)=>(0,$.jsx)(el.span,{className:`inline-block`,variants:{initial:{y:0},hovered:{y:`-100%`}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0`),children:a.map((e,t)=>(0,$.jsx)(el.span,{className:`inline-block`,variants:{initial:{y:`100%`},hovered:{y:0}},transition:{duration:r,ease:`easeInOut`,delay:i*t},children:e},String(t)))})]})}},{variant:`shake`,component:({children:e,className:t,...n})=>(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted hover:animate-text-shake`,t),children:e})},{variant:`hover-decoration`,component:({children:e,className:t,...n})=>(0,$.jsx)(`div`,{className:Y(`relative after:absolute after:bottom-0 after:left-0 after:h-px after:w-full after:origin-bottom-right`,`after:scale-x-0 after:bg-primary-muted after:transition-transform after:duration-300 after:ease-in-out hover:after:origin-bottom-left hover:after:scale-x-100`),children:(0,$.jsx)(`span`,{...n,className:Y(`text-primary-muted`,t),children:e})})}];function aS(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({variant:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`static`:i,o;t[4]===a?o=t[5]:(o=iS.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||iS[0].component,c;return t[6]!==s||t[7]!==n||t[8]!==r?(c=(0,$.jsx)(s,{...r,className:n}),t[6]=s,t[7]=n,t[8]=r,t[9]=c):c=t[9],c}var oS=e=>{let t=`h-3.5 w-3.5 flex-shrink-0`,n=`h-[13px] w-[13px] flex-shrink-0`,r=e.toLowerCase();return r===`edit`||r===`multiedit`||r===`apply_patch`||r===`str_replace`||r===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil`,className:n}):r===`write`||r===`create`||r===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:n}):r===`read`||r===`view`||r===`file_read`||r===`cat`?(0,$.jsx)(X,{name:`file-text`,className:t}):r===`bash`||r===`shell`||r===`cmd`||r===`terminal`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):r===`list`||r===`ls`||r===`dir`||r===`list_files`?(0,$.jsx)(X,{name:`folder-6`,className:t}):r===`search`||r===`grep`||r===`find`||r===`ripgrep`?(0,$.jsx)(X,{name:`menu-search`,className:t}):r===`glob`?(0,$.jsx)(X,{name:`file-search`,className:t}):r===`fetch`||r===`curl`||r===`wget`||r===`webfetch`||r===`web-search`||r===`websearch`||r===`search_web`||r===`codesearch`||r===`google`||r===`bing`||r===`duckduckgo`||r===`perplexity`?(0,$.jsx)(X,{name:`global`,className:t}):r===`todowrite`||r===`todoread`?(0,$.jsx)(X,{name:`list-check-3`,className:t}):r===`structuredoutput`||r===`structured_output`?(0,$.jsx)(X,{name:`list-check-2`,className:t}):r===`skill`?(0,$.jsx)(X,{name:`book`,className:t}):r===`task`?(0,$.jsx)(X,{name:`ai-agent`,className:t}):r===`question`?(0,$.jsx)(X,{name:`survey`,className:t}):r===`lsp`?(0,$.jsx)(X,{name:`scan-2`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},sS=new Map,cS=e=>{let t=sS.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return sS.set(e,n),n},lS=(e,t)=>{let n=cS(e);return n.subscribers.add(t),t(Date.now()),n.timerId===null&&typeof window<`u`&&(n.timerId=window.setInterval(()=>{let e=Date.now();n.subscribers.forEach(t=>{t(e)})},e)),()=>{let n=sS.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),sS.delete(e)))}},uS=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(dS),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return lS(r,a)},s=[e,r],n[0]=e,n[1]=r,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),i};function dS(){return Date.now()}var fS=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],pS=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},mS=e=>{if(!e||typeof e!=`object`)return;let t=e;return pS(t.sessionId)??pS(t.sessionID)},hS=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>e?.type!==`subtask`||e.taskSessionID===t?e:(n=!0,{...e,taskSessionID:t}));return n?r:e},gS=e=>{if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){t.push({tool:`tool`,state:{status:`completed`,title:n}});continue}if(!n||typeof n!=`object`)continue;let e=n;t.push({id:typeof e.id==`string`?e.id:void 0,tool:typeof e.tool==`string`?e.tool:`tool`,state:{status:typeof e.state?.status==`string`?e.state.status:typeof e.status==`string`?e.status:void 0,title:typeof e.state?.title==`string`?e.state.title:typeof e.title==`string`?e.title:void 0,input:e.state?.input&&typeof e.state.input==`object`?e.state.input:void 0}})}return t},_S=e=>{if(typeof e!=`string`||e.trim().length===0)return{summaryEntries:[]};let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);if(!t?.[1])return{summaryEntries:[]};try{let e=JSON.parse(t[1].trim());return{sessionId:pS(e.sessionId)??pS(e.sessionID),status:pS(e.status),summaryEntries:gS(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},vS=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=_S(e);if(t.sessionId)return t.sessionId;let n=e.match(/task_id\s*:\s*([^\s<"']+)/i),r=e.match(/session[_\s-]?id\s*:\s*([^\s<"']+)/i);return pS((n?.[1]??r?.[1])||fS(e))},yS=e=>{if(!(!e||typeof e!=`object`))return pS(e.status)},bS=/"status"\s*:\s*"running"/i,xS=/\bstatus\s*[:=]\s*["'`]?running\b/i,SS=e=>{if(typeof e!=`string`||e.trim().length===0)return!1;let t=e.match(/<task_metadata>\s*([\s\S]*?)\s*<\/task_metadata>/i);return t?.[1]&&bS.test(t[1])?!0:xS.test(e)},CS=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,wS=(e,t)=>pS(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),TS=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},ES=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(CS);if(!t)return;let n=wS(t[1],`sessionID`)??wS(t[1],`sessionId`),r=TS(wS(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:wS(t[1],`description`),body:t[2].trim()}},DS=new WeakMap,OS=e=>{let t=DS.get(e);if(t)return t;let n=[];if(e.info.role===`assistant`)for(let t of e.parts){if(t.type!==`tool`)continue;let e=t.tool?.trim().toLowerCase();if(!e||e===`task`||e===`todowrite`||e===`todoread`)continue;let r=t.state;n.push({id:t.id,tool:t.tool,state:{status:r?.status,title:r?.title,input:r?.input&&typeof r.input==`object`?r.input:void 0}})}return DS.set(e,n),n},kS=e=>{let t=[];for(let n of e)t.push(...OS(n));return t},AS=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),jS=[`summary`,`changes`,`verification`],MS={summary:`Summary`,changes:`Changes`,verification:`Verification`},NS=/<(summary|changes|verification)(?:\s[^>]*)?>/i,PS=()=>RegExp(`<(${jS.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),FS=e=>typeof e!=`string`||e.length===0?!1:NS.test(e),IS=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!FS(e)?e:e.replace(PS(),(e,t,n)=>{let r=MS[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),LS=e=>IS(AS(e)),RS=e=>{if(!e.isTaskTool)return{isDelegating:!1,showAvatar:!1,title:e.displayName};let t=e.taskAgentName?e.formatName(e.taskAgentName):void 0,n=!!(e.taskSessionId||t);return!e.isFinalized&&!n?{isDelegating:!0,showAvatar:!1,title:e.delegatingLabel}:{isDelegating:!1,showAvatar:n,title:t??e.displayName}};function zS(e){if(!e.isTaskTool||e.isFinalized)return!1;let t=e.taskSessionId?e.childSessionStatus:e.parentSessionStatus;if(t){if(t.type!==`idle`)return!1;if(typeof e.taskStartedAt==`number`&&typeof e.statusObservedAt==`number`&&e.taskStartedAt<=e.statusObservedAt)return!0}return typeof e.taskStartedAt==`number`&&typeof e.statusSnapshotAt==`number`&&e.taskStartedAt<=e.statusSnapshotAt}var BS=(e,t)=>{if(e===t)return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;let n=e,r=t;return n.input===r.input&&n.output===r.output&&n.reasoning===r.reasoning&&n.cache?.read===r.cache?.read&&n.cache?.write===r.cache?.write},VS=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},HS=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},US=e=>e?.state,WS=e=>e?.metadata,GS=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},KS=e=>{let t=e;return t?[typeof t.text==`string`?t.text:``,typeof t.content==`string`?t.content:``,typeof t.value==`string`?t.value:``].reduce((e,t)=>t.length>e.length?t:e,``):``},qS=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.type!==i.type||VS(r)!==VS(i))return!1;if(r.type===`tool`){if(US(r)!==US(i)||WS(r)!==WS(i)||HS(r)!==HS(i))return!1;let e=GS(r),t=GS(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=GS(r),o=GS(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(KS(r)!==KS(i))return!1;let e=r.shellAction,t=i.shellAction;if((e||t)&&(e?.command!==t?.command||e?.output!==t?.output||e?.status!==t?.status))return!1}}return!0},JS=(e,t)=>e===t||e.id===t.id&&e.role===t.role&&e.sessionID===t.sessionID&&e.finish===t.finish&&e.status===t.status&&e.mode===t.mode&&e.agent===t.agent&&e.providerID===t.providerID&&e.modelID===t.modelID&&e.variant===t.variant&&e.clientRole===t.clientRole&&e.userMessageMarker===t.userMessageMarker&&(e.time?.created??null)===(t.time?.created??null)&&(e.time?.completed??null)===(t.time?.completed??null)&&BS(e.tokens,t.tokens),YS=(e,t)=>JS(e.info,t.info)&&qS(e.parts,t.parts),XS=(e,t)=>!e||!t?e===t:YS(e,t),ZS=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,QS=(e,t)=>{if(e===t)return!0;if(!e||!t)return!e&&!t;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.file!==i.file||r.additions!==i.additions||r.deletions!==i.deletions)return!1}return!0},$S=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&qS([e.part],[t.part]),eC=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.messageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.messageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!$S(a,o))return!1;r+=1,i+=1}},tC=(e,t)=>{if(e.id!==t.id||e.anchorMessageId!==t.anchorMessageId||e.afterToolPartId!==t.afterToolPartId||e.parts.length!==t.parts.length)return!1;for(let n=0;n<e.parts.length;n+=1)if(!$S(e.parts[n],t.parts[n]))return!1;return!0},nC=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),rC=(e,t,n)=>{let r=0,i=0;for(;;){for(;r<(e?.length??0)&&e?.[r]?.anchorMessageId!==n;)r+=1;for(;i<(t?.length??0)&&t?.[i]?.anchorMessageId!==n;)i+=1;let a=e?.[r],o=t?.[i];if(!a||!o)return a===o;if(!tC(a,o))return!1;r+=1,i+=1}},iC=(e,t,n,r)=>{if(e===t)return!0;if(!e||!t)return e===t;if(r)return!0;if(e.isGroupExpanded!==t.isGroupExpanded||e.turnId!==t.turnId||e.isFirstAssistantInTurn!==t.isFirstAssistantInTurn||e.isLastAssistantInTurn!==t.isLastAssistantInTurn||e.isLatestTurn!==t.isLatestTurn||e.isWorking!==t.isWorking||e.isTurnSettled!==t.isTurnSettled||e.hasTools!==t.hasTools||e.hasReasoning!==t.hasReasoning||e.userMessageCreatedAt!==t.userMessageCreatedAt||e.userMessageVariant!==t.userMessageVariant||(e.headerMessageId===n||t.headerMessageId===n)&&e.headerMessageId!==t.headerMessageId)return!1;let i=e.activityOwnerMessageId===n||t.activityOwnerMessageId===n;if(i&&e.activityOwnerMessageId!==t.activityOwnerMessageId||!eC(e.activityParts,t.activityParts,n)||!rC(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=nC(e.activityGroupSegments,n)||nC(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!ZS(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!QS(e.changedFiles,t.changedFiles))},aC=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,oC=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,sC=/(?=^diff --git\s+)/gm,cC=/^diff --git\s+/m,lC=/(?=^---\s+\S)/gm,uC=/^---\s+\S/m,dC=e=>typeof e==`object`&&!!e,fC=e=>e.replace(/\r\n/g,`
|
|
6538
6538
|
`).replace(/\r/g,`
|
|
6539
|
-
`).trim(),
|
|
6539
|
+
`).trim(),pC=e=>{let t=!1;return e.split(`
|
|
6540
6540
|
`).map(e=>{if(e.startsWith(`@@`))return t=!0,e;if(t)return e;let n=e.match(/^\s*(---|\+\+\+)\s+(.+)$/);if(!n)return e;let r=n[1],i=n[2]??``;return i.trim()===`/dev/null`?`${r} /dev/null`:`${r} ${i.replace(/\\/g,`/`)}`}).join(`
|
|
6541
|
-
`)},
|
|
6541
|
+
`)},mC=e=>{let t=!1;return e.split(`
|
|
6542
6542
|
`).map(e=>{if(e.startsWith(`@@`))return t=!0,e;if(!t||e.startsWith(`--- `)||e.startsWith(`+++ `)||e.startsWith(`diff --git`))return e;if(e.length===0)return` `;let n=e[0];return n===` `||n===`+`||n===`-`||n===`\\`?e:` ${e}`}).join(`
|
|
6543
|
-
`)},
|
|
6544
|
-
`),n=[...t];for(let e=0;e<t.length;e+=1){let r=(t[e]??``).match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@(.*)$/);if(!r)continue;let i=0,a=0;for(let n=e+1;n<t.length;n+=1){let e=t[n]??``;if(e.startsWith(`@@`)||e.startsWith(`--- `)||e.startsWith(`diff --git`))break;if(!e.startsWith(`\\`)){if(e.startsWith(`+`)){a+=1;continue}if(e.startsWith(`-`)){i+=1;continue}i+=1,a+=1}}n[e]=`@@ -${
|
|
6545
|
-
`)},
|
|
6546
|
-
`)){if(n.startsWith(`@@`)){if(!
|
|
6547
|
-
`),n,r;for(let e of t){let t=e.replace(/\r$/,``),i=t.match(/^@@\s+-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);if(i){let e=Number.parseInt(i[1]??``,10);Number.isFinite(e)&&(n=Math.max(1,e),Number.isFinite(r)||(r=n));continue}if(!(n===void 0||!Number.isFinite(n))&&!(t.startsWith(`+++`)||t.startsWith(`---`)||t.startsWith(`diff `))){if(t.startsWith(`+`))return n;if(t.startsWith(` `)){n+=1;continue}t.startsWith(`-`)||t.startsWith(`\\`)}}return r},
|
|
6543
|
+
`)},hC=(e,t)=>t===1?e:`${e},${t}`,gC=e=>{let t=e.split(`
|
|
6544
|
+
`),n=[...t];for(let e=0;e<t.length;e+=1){let r=(t[e]??``).match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@(.*)$/);if(!r)continue;let i=0,a=0;for(let n=e+1;n<t.length;n+=1){let e=t[n]??``;if(e.startsWith(`@@`)||e.startsWith(`--- `)||e.startsWith(`diff --git`))break;if(!e.startsWith(`\\`)){if(e.startsWith(`+`)){a+=1;continue}if(e.startsWith(`-`)){i+=1;continue}i+=1,a+=1}}n[e]=`@@ -${hC(r[1]??`0`,i)} +${hC(r[2]??`0`,a)} @@${r[3]??``}`}return n.join(`
|
|
6545
|
+
`)},_C=e=>gC(mC(pC(fC(e)))),vC=e=>{if(typeof e==`string`)return/\S/.test(e)?e:void 0;if(dC(e)){let t=e.patch;if(typeof t==`string`)return/\S/.test(t)?t:void 0}},yC=e=>{let t=(e??``).trim().replace(/\t.*$/,``);return!t||t===`/dev/null`?``:t.replace(/^[ab]\//,``)},bC=e=>{let t=e.trim().replace(/\s+/g,`-`);return t.length>0?t:`file`},xC=e=>{let t=!1;for(let n of e.split(`
|
|
6546
|
+
`)){if(n.startsWith(`@@`)){if(!oC.test(n))return!1;t=!0;continue}if(!t||n.length===0)continue;let e=n[0];if(e!==` `&&e!==`+`&&e!==`-`&&e!==`\\`)return!1}return!0},SC=e=>{let t=_C(e);if(!t||aC.test(t)||!oC.test(t)||!xC(t))return null;try{let e=et(t,void 0,!0);if(e.length!==1)return null;let n=e[0]?.files??[],r=n[0];return n.length!==1||!r||r.hunks.length===0?null:{patch:t,title:yC(r.name)}}catch{return null}},CC=e=>{let t=cC.test(e),n=uC.test(e);return!t&&!n?[]:e.split(t?sC:lC).map(e=>e.trim()).filter(e=>e.length>0)},wC=(e,t,n,r)=>{let i=_C(e);if(!i)return[];let a=SC(i);if(a){let e=a.title?r(a.title):r(t);return[{id:`${n}-0`,title:e,patch:a.patch,renderMode:`diff`}]}let o=[];for(let e of CC(i)){let i=SC(e),a=i?.title?r(i.title):r(t);if(!i){(oC.test(e)||cC.test(e)||uC.test(e))&&o.push({id:`${n}-${o.length}`,title:a,patch:e,renderMode:`text`});continue}o.push({id:`${n}-${o.length}`,title:a,patch:i.patch,renderMode:`diff`})}if(o.length>0)return o;if(!aC.test(i)&&oC.test(i)){let e=bC(t),a=SC(`--- ${e}\n+++ ${e}\n${i}`);if(a)return[{id:`${n}-0`,title:r(t),patch:a.patch,renderMode:`diff`}]}return[{id:`${n}-0`,title:r(t),patch:i,renderMode:`text`}]},TC=e=>{if(!dC(e))return null;let t=vC(e.patch)??vC(e.diff);return t?{patch:t,title:typeof e.movePath==`string`?e.movePath:typeof e.relativePath==`string`?e.relativePath:typeof e.filePath==`string`?e.filePath:``}:null},EC=(e,t,n)=>{let r=(Array.isArray(e?.files)?e.files:[]).flatMap((e,t)=>{let r=TC(e);return r?wC(r.patch,r.title||`File ${t+1}`,`file-${t}`,n):[]});return r.length>0?r:wC(typeof t==`string`?t:``,`Diff`,`fallback`,n)},DC=e=>e.trim().replace(/\\/g,`/`).replace(/\/{2,}/g,`/`).replace(/\/+$/,``),OC=(e,t,n,r,i)=>{let a=EC(t,n,i);if(a.length===0||a.some(e=>e.renderMode!==`diff`))return[];let o=Array.isArray(t?.files)?t.files:[];if(e===`apply_patch`){if(o.length>0){let e=o.reduce((e,t)=>TC(t)?e+1:e,0);if(e>0&&e!==o.length)return[]}return new Set(a.map(e=>DC(e.title))).size===a.length?a:[]}let s=DC(r),c=a.find(e=>DC(e.title)===s)??a[0];return c?[c]:[]},kC=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e));if(typeof e==`string`){let t=Number.parseInt(e,10);if(Number.isFinite(t))return Math.max(0,t)}return null},AC=e=>{let t=0,n=0,r=0;for(let i=0;i<=e.length;i+=1){if(i<e.length&&e.charCodeAt(i)!==10)continue;let a=e.slice(r,i);a.startsWith(`+`)&&!a.startsWith(`+++`)&&(t+=1),a.startsWith(`-`)&&!a.startsWith(`---`)&&(n+=1),r=i+1}return{added:t,removed:n}},jC=e=>{if(!e?.content||typeof e.content!=`string`)return 0;let t=1;for(let n=0;n<e.content.length;n+=1)e.content.charCodeAt(n)===10&&(t+=1);return t},MC=e=>{if(!dC(e))return{};let t=dC(e.state)?e.state:{};return{metadata:dC(t.metadata)?t.metadata:dC(e.metadata)?e.metadata:void 0,input:dC(t.input)?t.input:void 0}},NC=e=>{let{metadata:t,input:n}=MC(e),r=kC(t?.additions),i=kC(t?.deletions);if(r!==null||i!==null)return{added:r??0,removed:i??0};let a=Array.isArray(t?.files)?t.files:[],o=0,s=0,c=!1;for(let e of a){if(!dC(e))continue;let t=kC(e.additions),n=kC(e.deletions);(t!==null||n!==null)&&(c=!0,o+=t??0,s+=n??0)}if(c)return{added:o,removed:s};let l=vC(t?.patch)??vC(t?.diff);if(l){let e=AC(l);if(e.added>0||e.removed>0)return e}let u=jC(n);return u>0?{added:u,removed:0}:{added:0,removed:0}},PC=e=>{let t=0,n=0;for(let r of e){let e=NC(r);t+=e.added,n+=e.removed}return{added:t,removed:n}},FC=Z.createContext(!1),IC=()=>Z.useContext(FC),LC=`relative ml-2 pl-3`,RC=(e,t=`default`,n=!1)=>t===`todo`?`relative flex min-w-0 flex-col gap-1 py-0.5`:e?`relative flex min-w-0 flex-col ${n?`gap-1`:`gap-2`} py-2`:`relative flex flex-col gap-2 pr-2 pb-2 pt-2 pl-4`,zC=e=>e?`p-0`:`p-2`,BC=`1.25rem`,VC=28,HC=3,UC=4,WC=10,GC=1,KC=4,qC=e=>{let t=(0,Q.c)(17),{size:n,isMobile:r,className:i,label:a}=e,o=r!==void 0&&r,s=a===void 0?``:a,c=n??(o?12:14),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=Array.from({length:9},JC),t[0]=l):l=t[0];let u=l,d;t[1]===i?d=t[2]:(d=Y(`relative block flex-none overflow-clip`,i),t[1]=i,t[2]=d);let f;t[3]===c?f=t[4]:(f={width:c,height:c},t[3]=c,t[4]=f);let p=s?`img`:void 0,m=s||void 0,h=!s||void 0,g=`scale(${c/VC})`,_;t[5]===g?_=t[6]:(_={width:VC,height:VC,transform:g,transformOrigin:`top left`},t[5]=g,t[6]=_);let v;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(v=u.map(YC),t[7]=v):v=t[7];let y;t[8]===_?y=t[9]:(y=(0,$.jsx)(`span`,{className:`pointer-events-none absolute left-0 top-0 block`,style:_,children:v}),t[8]=_,t[9]=y);let b;return t[10]!==y||t[11]!==d||t[12]!==f||t[13]!==p||t[14]!==m||t[15]!==h?(b=(0,$.jsx)(`span`,{className:d,style:f,role:p,"aria-label":m,"aria-hidden":h,children:y}),t[10]=y,t[11]=d,t[12]=f,t[13]=p,t[14]=m,t[15]=h,t[16]=b):b=t[16],b};function JC(e,t){let n=t%HC,r=Math.floor(t/HC),i=n-GC,a=r-GC,o=i===0&&a===0;return{x:n,y:r,isCenter:o,delay:Math.hypot(i,a)*700-(o?180:0)}}function YC(e){let{x:t,y:n,isCenter:r,delay:i}=e;return(0,$.jsx)(`span`,{className:`oc-lattice-orb-dot absolute block rounded-full bg-current`,"data-center":r?`true`:void 0,style:{left:UC+t*WC,top:UC+n*WC,width:KC,height:KC,transform:`translate(-50%, -50%)`,animationDelay:`${i}ms`}},`${t}-${n}`)}var XC=new Set([`read`,`skill`]),ZC=new Set([`task`]),QC=new Set([`read`,`glob`,`grep`,`list`]),$C=new Set([`completed`,`error`,`failed`,`aborted`,`timeout`,`cancelled`]),ew=new Set([`pending`,`started`,`running`]),tw=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(n.includes(`.`)){let e=n.split(`.`).filter(Boolean);return e[e.length-1]??n}return n},nw=e=>!iw(e),rw=e=>ZC.has(tw(e)),iw=e=>XC.has(tw(e)),aw=e=>QC.has(tw(e)),ow=e=>tw(e)===`skill`,sw=e=>{let t=tw(e);return!(!t||QC.has(t)||t===`skill`||ZC.has(t)||t===`question`)},cw=e=>aw(e)||sw(e),lw=e=>{if(!e||typeof e!=`object`)return!1;let t=e.state;if(!t||typeof t!=`object`)return!1;let n=t.status;if(typeof n==`string`){let e=n.trim().toLowerCase();if(ew.has(e))return!1;if($C.has(e))return!0}let r=t.time;if(!r||typeof r!=`object`)return!1;let i=r.start,a=r.end;return typeof a!=`number`||!Number.isFinite(a)?!1:typeof i!=`number`||!Number.isFinite(i)||a>=i},uw=e=>!lw(e),dw=tw,fw=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,pw=Y(`typography-meta font-medium`,fw),mw=Y(`typography-meta`,fw),hw=`typography-micro !text-[length:calc(var(--text-meta)-0.0625rem)] !leading-5 tracking-normal`,gw=`flex w-full min-w-0 flex-col gap-1`,_w=e=>{if(e&&typeof e==`object`&&!Array.isArray(e))return e;if(typeof e!=`string`)return;let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return e}catch{return}},vw=(...e)=>{for(let t of e){let e=_w(t);if(!e)continue;let n=[e.subagent_type,e.subagentType,e.agent,e.subagent];for(let e of n){if(typeof e!=`string`)continue;let t=e.trim();if(t.length>0)return t}}},yw=e=>e.length>0?e.charAt(0).toUpperCase()+e.slice(1):e,bw=new $c({maxEntries:2e3,maxBytes:262144}),xw=(e,t=!0,n=!0)=>{let r=Array.isArray(e?.files)?e?.files:[];if(r.length<=1)return null;let i=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e));if(typeof e==`string`){let t=Number.parseInt(e,10);if(Number.isFinite(t))return Math.max(0,t)}return null},a=(e,t)=>e===null?t:t===null?e:e+t,o=new Map;for(let e of r){let t=e,n=t.relativePath||t.filePath||``;if(!n)continue;let r=n.split(`/`).pop()||n,s=i(t.additions),c=i(t.deletions),l=o.get(n);if(l){l.added=a(l.added,s),l.removed=a(l.removed,c);continue}o.set(n,{path:n,name:r,added:s,removed:c})}let s=Array.from(o.values());return(0,$.jsx)($.Fragment,{children:s.map(e=>{let r=e.added!==null||e.removed!==null;return(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 max-w-full items-center gap-1`,mw),style:{color:`var(--tools-description)`},children:[n?(0,$.jsx)(yd,{filePath:e.path,className:`h-3.5 w-3.5`}):null,(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 max-w-full truncate`,mw),style:{color:`var(--tools-description)`},title:e.path,children:e.name}),r?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,e.added??0]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,e.removed??0]})]}):null]},e.path)})})},Sw=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;if(t.includes(`.`)){let e=t.split(`.`).filter(Boolean),n=e[e.length-1];if(n)return n}return t},Cw=3e5,ww=new Set([`bash`,`edit`,`write`,`apply_patch`,`patch`,`task`]),Tw=new Set([`edit`,`multiedit`,`apply_patch`,`write`,`create`,`file_write`]),Ew=e=>Tw.has(e),Dw=e=>e===`write`||e===`create`||e===`file_write`,Ow=(e,t,n=Date.now())=>{let r=Math.min(Math.max(0,(t??n)-e),Cw)/1e3;return`${(r<.05&&t!==void 0?.1:r).toFixed(1)}s`},kw=e=>{let t=(0,Q.c)(6),{start:n,end:r,active:i}=e,a=uS(i,250),o;t[0]!==r||t[1]!==a||t[2]!==n?(o=Ow(n,r,a),t[0]=r,t[1]=a,t[2]=n,t[3]=o):o=t[3];let s;return t[4]===o?s=t[5]:(s=(0,$.jsx)($.Fragment,{children:o}),t[4]=o,t[5]=s),s},Aw=e=>{if(typeof e==`number`&&Number.isFinite(e))return Math.max(0,Math.trunc(e));if(typeof e==`string`){let t=Number.parseInt(e,10);if(Number.isFinite(t))return Math.max(0,t)}return null},jw=e=>{let t=Aw(e?.additions),n=Aw(e?.deletions);if(t!==null||n!==null){let e=t??0,r=n??0;return e===0&&r===0?null:{added:e,removed:r}}let r=vC(e?.patch)??vC(e?.diff);if(!r)return null;let i=0,a=0,o=0;for(let e=0;e<=r.length;e+=1){if(e<r.length&&r.charCodeAt(e)!==10)continue;let t=r.slice(o,e);t.startsWith(`+`)&&!t.startsWith(`+++`)&&i++,t.startsWith(`-`)&&!t.startsWith(`---`)&&a++,o=e+1}return i===0&&a===0?null:{added:i,removed:a}},Mw=e=>{if(!e?.content||typeof e.content!=`string`)return null;let t=1;for(let n=0;n<e.content.length;n+=1)e.content.charCodeAt(n)===10&&(t+=1);return t},Nw=e=>{if(!e||typeof e!=`string`)return;let t=e.split(`
|
|
6547
|
+
`),n,r;for(let e of t){let t=e.replace(/\r$/,``),i=t.match(/^@@\s+-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);if(i){let e=Number.parseInt(i[1]??``,10);Number.isFinite(e)&&(n=Math.max(1,e),Number.isFinite(r)||(r=n));continue}if(!(n===void 0||!Number.isFinite(n))&&!(t.startsWith(`+++`)||t.startsWith(`---`)||t.startsWith(`diff `))){if(t.startsWith(`+`))return n;if(t.startsWith(` `)){n+=1;continue}t.startsWith(`-`)||t.startsWith(`\\`)}}return r},Pw=(e,t)=>{let n=t.replace(/\r\n/g,`
|
|
6548
6548
|
`);if(!n.trim())return;let r=(()=>{let t=(e??``).trim();return t?t.startsWith(`/`)?t.slice(1):t:`new-file`})(),i=n.split(`
|
|
6549
6549
|
`),a=i.length,o=i.map(e=>`+${e}`).join(`
|
|
6550
6550
|
`);return[`--- /dev/null`,`+++ b/${r}`,`@@ -0,0 +1,${a} @@`,o].join(`
|
|
6551
|
-
`)},
|
|
6552
|
-
`)[0].substring(0,100);if(e.tool===`task`&&a?.description&&typeof a.description==`string`)return a.description.substring(0,80);if(e.tool===`lsp`)return Kw(a,n);let s=a?.description||i?.description||`title`in t&&t.title||``;return typeof s==`string`?s:``},Jw=e=>{let t=(0,Q.c)(17),{children:n,isMobile:r,maxHeightClass:i,className:a,outerClassName:o,disableHorizontal:s}=e,c=r!==void 0&&r,l=i===void 0?`max-h-[60vh]`:i,u=s!==void 0&&s,d;t[0]===o?d=t[1]:(d=Y(`w-full min-w-0 flex-none overflow-hidden`,o),t[0]=o,t[1]=d);let f;if(t[2]!==a||t[3]!==u||t[4]!==c||t[5]!==l){let e;t[7]===c?e=t[8]:(e=c&&RC(!0),t[7]=c,t[8]=e),f=Y(`tool-output-surface rounded-xl w-full min-w-0`,RC(c),l,u?`overflow-y-auto overflow-x-hidden`:`overflow-auto`,a,e),t[2]=a,t[3]=u,t[4]=c,t[5]=l,t[6]=f}else f=t[6];let p;t[9]===n?p=t[10]:(p=(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:n}),t[9]=n,t[10]=p);let m;t[11]!==f||t[12]!==p?(m=(0,$.jsx)(ja,{className:f,children:p}),t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==d||t[15]!==m?(h=(0,$.jsx)(`div`,{className:d,children:m}),t[14]=d,t[15]=m,t[16]=h):h=t[16],h},Yw=(e,t,n,r)=>t.tool===`bash`?`bash`:Mc(Bc(e,t.tool,n),t.tool,r),Xw=(e,t,n)=>t.tool===`bash`?e:Bc(e,t.tool,n),Zw=e=>{let t=(0,Q.c)(80),{output:n,part:r,metadata:i,input:a,isMobile:o}=e,s=o!==void 0&&o,{t:c}=ct(),l;t[0]!==i||t[1]!==n||t[2]!==r?(l=Xw(n,r,i),t[0]=i,t[1]=n,t[2]=r,t[3]=l):l=t[3];let u=l,d;t[4]!==a||t[5]!==i||t[6]!==n||t[7]!==r?(d=Yw(n,r,i,a),t[4]=a,t[5]=i,t[6]=n,t[7]=r,t[8]=d):d=t[8];let f=d,p;t[9]===u?p=t[10]:(p=Ic(u),t[9]=u,t[10]=p);let m=p,[h,g]=Z.useState(`formatted`),[_,v]=Z.useState(!1),y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{g(`formatted`),v(!1)},t[11]=y):y=t[11];let b;t[12]===u?b=t[13]:(b=[u],t[12]=u,t[13]=b),Z.useEffect(y,b);let x;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(x=(e,t)=>{t.stopPropagation(),g(e)},t[14]=x):x=t[14];let S=J(x),C;t[15]!==u||t[16]!==c?(C=async e=>{if(e.stopPropagation(),!(await ut(u)).ok){Br.error(c(`chat.toolPart.copyOutputFailed`));return}v(!0),typeof window<`u`&&window.setTimeout(()=>v(!1),1200)},t[15]=u,t[16]=c,t[17]=C):C=t[17];let w=J(C);if(m.isJson){let e=h===`formatted`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,n;t[18]===e?n=t[19]:(n=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,e),t[18]=e,t[19]=n);let r;t[20]===S?r=t[21]:(r=e=>S(`formatted`,e),t[20]=S,t[21]=r);let i;t[22]===c?i=t[23]:(i=c(`chat.toolPart.showFormattedJson`),t[22]=c,t[23]=i);let a;t[24]===c?a=t[25]:(a=c(`chat.toolPart.showFormattedJson`),t[24]=c,t[25]=a);let o;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(X,{name:`node-tree`,className:`h-3.5 w-3.5`}),t[26]=o):o=t[26];let s;t[27]!==n||t[28]!==r||t[29]!==i||t[30]!==a?(s=(0,$.jsx)(ua,{variant:`ghost`,size:`icon`,className:n,onClick:r,onPointerDown:CT,"aria-label":i,title:a,children:o}),t[27]=n,t[28]=r,t[29]=i,t[30]=a,t[31]=s):s=t[31];let l=h===`raw`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,d;t[32]===l?d=t[33]:(d=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,l),t[32]=l,t[33]=d);let f;t[34]===S?f=t[35]:(f=e=>S(`raw`,e),t[34]=S,t[35]=f);let p;t[36]===c?p=t[37]:(p=c(`chat.toolPart.showRawJson`),t[36]=c,t[37]=p);let g;t[38]===c?g=t[39]:(g=c(`chat.toolPart.showRawJson`),t[38]=c,t[39]=g);let v;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(X,{name:`code-box`,className:`h-3.5 w-3.5`}),t[40]=v):v=t[40];let y;t[41]!==d||t[42]!==f||t[43]!==p||t[44]!==g?(y=(0,$.jsx)(ua,{variant:`ghost`,size:`icon`,className:d,onClick:f,onPointerDown:wT,"aria-label":p,title:g,children:v}),t[41]=d,t[42]=f,t[43]=p,t[44]=g,t[45]=y):y=t[45];let b;t[46]!==_||t[47]!==c?(b=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[46]=_,t[47]=c,t[48]=b):b=t[48];let x;t[49]!==_||t[50]!==c?(x=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[49]=_,t[50]=c,t[51]=x):x=t[51];let C=_?`check`:`file-copy`,T;t[52]===C?T=t[53]:(T=(0,$.jsx)(X,{name:C,className:`h-3.5 w-3.5`}),t[52]=C,t[53]=T);let E;t[54]!==w||t[55]!==b||t[56]!==x||t[57]!==T?(E=(0,$.jsx)(ua,{variant:`ghost`,size:`icon`,className:`h-6 w-6 rounded-md bg-[var(--surface-elevated)]/80 text-muted-foreground hover:text-foreground`,onClick:w,onPointerDown:TT,"aria-label":b,title:x,children:T}),t[54]=w,t[55]=b,t[56]=x,t[57]=T,t[58]=E):E=t[58];let D;t[59]!==s||t[60]!==y||t[61]!==E?(D=(0,$.jsxs)(`div`,{className:`absolute right-2 top-2 z-10 flex items-center gap-1`,children:[s,y,E]}),t[59]=s,t[60]=y,t[61]=E,t[62]=D):D=t[62];let O;t[63]!==m.data||t[64]!==h||t[65]!==u?(O=h===`formatted`?(0,$.jsx)(Hc,{data:m.data,initiallyExpandedDepth:1,maxHeight:`400px`}):(0,$.jsx)(`div`,{className:`typography-code pr-12 text-muted-foreground/90`,children:(0,$.jsx)(Fc,{language:`json`,code:u,style:cT,codeStyle:lT.style,wrap:!0})}),t[63]=m.data,t[64]=h,t[65]=u,t[66]=O):O=t[66];let k;return t[67]!==D||t[68]!==O?(k=(0,$.jsxs)(`div`,{className:`tool-output-surface relative p-2 rounded-xl w-full min-w-0`,children:[D,O]}),t[67]=D,t[68]=O,t[69]=k):k=t[69],k}let T=r.tool===`bash`?`typography-code text-muted-foreground/90`:void 0,E;t[70]!==s||t[71]!==r.tool?(E={...cT,...s&&r.tool===`bash`?{lineHeight:zC}:{}},t[70]=s,t[71]=r.tool,t[72]=E):E=t[72];let D;t[73]!==f||t[74]!==u||t[75]!==E?(D=(0,$.jsx)(Fc,{language:f,code:u,style:E,codeStyle:lT.style,wrap:!0}),t[73]=f,t[74]=u,t[75]=E,t[76]=D):D=t[76];let O;return t[77]!==D||t[78]!==T?(O=(0,$.jsx)(`div`,{className:T,children:D}),t[77]=D,t[78]=T,t[79]=O):O=t[79],O};Zw.displayName=`ToolScrollableTextOutput`;var Qw=e=>{let t=e.state?.title;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.state?.input;if(n&&typeof n==`object`){let e=n.filePath??n.file_path??n.path;if(typeof e==`string`&&e.trim().length>0)return e.trim();let t=n.url;if(typeof t==`string`&&t.trim().length>0)return t.trim()}return``},$w=new Set([`read`,`view`,`file_read`,`cat`,`write`,`create`,`file_write`,`edit`,`multiedit`,`apply_patch`]),eT=(e,t)=>{if(!$w.has(e.toLowerCase()))return!1;let n=t.trim();if(!n||n===`Patch`||/^\d+\s+files$/.test(n))return!1;if(n.includes(`/`)||n.includes(`\\`))return!0;let r=n.split(/[\\/]/).pop()||n;return r.startsWith(`.`)||r.includes(`.`)?!0:/^[A-Za-z0-9_-]+$/.test(r)},tT=e=>{let t=xw(e.tool),n=e.state?.status??``,r=Qw(e);return`${e.id??``}\u0001${t}\u0001${n}\u0001${r}`},nT=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(tT(e[n])!==tT(t[n]))return!1;return!0},rT=Z.memo(e=>{let t=(0,Q.c)(10),{entry:n,isMobile:r,animateTailText:i,showToolFileIcons:a}=e,{t:o}=ct(),s;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==o){let e=xw(n.tool),c=e.length>0?e:`tool`,l=Qw(n),u=l.trim().length>0,d=n.state?.status,f=uc(c,o),p=r?`items-start`:`items-center`,m;t[6]===p?m=t[7]:(m=Y(`flex gap-1.5 min-w-0 w-full py-px`,p),t[6]=p,t[7]=m);let h,g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=Y(mw,`text-foreground/80 flex-shrink-0`),g={color:`var(--tools-title)`},t[8]=h,t[9]=g):(h=t[8],g=t[9]),s=(0,$.jsxs)(`div`,{className:m,children:[(0,$.jsx)(`span`,{className:`flex-shrink-0 scale-90 text-foreground/80`,children:aS(c)}),(0,$.jsx)(`span`,{className:h,style:g,title:f,children:f}),u?d!==`error`&&eT(c,l)?hT(l,i,!0,a,mw):d===`error`?(0,$.jsx)(`span`,{className:Y(mw,`flex-1 min-w-0 text-[var(--status-error)]`,r?`whitespace-normal break-words`:`truncate`),children:l}):(0,$.jsx)(iS,{variant:i?`generate-effect`:`static`,className:Y(mw,`flex-1 min-w-0 text-muted-foreground/70`,r?`whitespace-normal break-words`:`truncate`),style:{color:`var(--tools-description)`},title:l,children:l}):null]}),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o,t[5]=s}else s=t[5];return s},(e,t)=>e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&tT(e.entry)===tT(t.entry));rT.displayName=`TaskSummaryEntryRow`;var iT=Z.memo(e=>{let t=(0,Q.c)(24),{entries:n,isExpanded:r,isMobile:i,animateTailText:a,showToolFileIcons:o}=e,s;t[0]!==n||t[1]!==r?(s=r?n:n.slice(-6),t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=s,l=Math.max(0,n.length-c.length),u=n.length-c.length,d=r?`max-h-[40vh]`:`max-h-56`,f;t[3]===l?f=t[4]:(f=l>0?(0,$.jsxs)(`div`,{className:Y(mw,`text-muted-foreground/70`),children:[`+`,l,` more…`]}):null,t[3]=l,t[4]=f);let p;if(t[5]!==a||t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==c||t[10]!==u){let e;t[12]!==a||t[13]!==r||t[14]!==i||t[15]!==o||t[16]!==u?(e=(e,t)=>{let n=r?t:u+t,s=e.id??`${tT(e)}:${n}`;return(0,$.jsx)(rT,{entry:e,isMobile:i,animateTailText:a,showToolFileIcons:o},s)},t[12]=a,t[13]=r,t[14]=i,t[15]=o,t[16]=u,t[17]=e):e=t[17],p=c.map(e),t[5]=a,t[6]=r,t[7]=i,t[8]=o,t[9]=c,t[10]=u,t[11]=p}else p=t[11];let m;t[18]!==f||t[19]!==p?(m=(0,$.jsxs)(`div`,{className:hw,children:[f,p]}),t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==d||t[22]!==m?(h=(0,$.jsx)(Jw,{maxHeightClass:d,disableHorizontal:!0,children:m}),t[21]=d,t[22]=m,t[23]=h):h=t[23],h},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&nT(e.entries,t.entries));iT.displayName=`TaskSummaryEntriesList`;var aT=e=>{let t=(0,Q.c)(44),{entries:n,isExpanded:r,isMobile:i,output:a,sessionId:o,onShowPopup:s,input:c,animateTailText:l,isActive:u}=e,d=l===void 0||l,f=u!==void 0&&u,{t:p}=ct(),m=pc(),h=ri(ET),g=q(DT),_=q(OT),v=Z.useContext(Ao),y=Lh(),b=y.directory||m,x;t[0]===a?x=t[1]:(x=typeof a==`string`?IS(a):``,t[0]=a,t[1]=x);let S=x,C=S.length>0,[w,T]=Z.useState(!1),E,D,O,k;if(t[2]!==d||t[3]!==b||t[4]!==n||t[5]!==C||t[6]!==c||t[7]!==f||t[8]!==r||t[9]!==i||t[10]!==g||t[11]!==v?.runtime||t[12]!==o||t[13]!==y||t[14]!==h||t[15]!==_||t[16]!==p){k=Symbol.for(`react.early_return_sentinel`);bb0:{let e=vw(_w(c)??`subagent`),a=t=>{t.stopPropagation(),o&&b&&zh(y,o,b,()=>{if(!di({sessionId:o,directory:b})){if(fl()||i||v?.runtime.isVSCode){h(o,b);return}g(b,{mode:`chat`,dedupeKey:`session:${o}`,label:e,readOnly:!0})}})};if(n.length===0&&!C&&!o){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(mw,`text-muted-foreground/70`),t[21]=e):e=t[21];let n=f?`Waiting for subagent activity...`:`No subagent session id on task metadata.`,r;t[22]===n?r=t[23]:(r=(0,$.jsx)(`div`,{className:`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,children:(0,$.jsx)(`div`,{className:e,children:n})}),t[22]=n,t[23]=r),k=r;break bb0}t[24]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,`before:absolute before:left-[0.4375rem] before:w-px before:bg-border/80 before:content-[""]`,`before:top-0 before:bottom-0`),t[24]=E):E=t[24],t[25]!==d||t[26]!==n||t[27]!==r||t[28]!==i||t[29]!==_?(D=n.length>0?(0,$.jsx)(iT,{entries:n,isExpanded:r,isMobile:i,animateTailText:d,showToolFileIcons:_}):null,t[25]=d,t[26]=n,t[27]=r,t[28]=i,t[29]=_,t[30]=D):D=t[30],O=o&&y.capabilities.navigateNestedSession&&(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-primary hover:text-primary/80 w-full`,mw),onPointerDown:kT,onClick:a,children:[(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(mw,`text-primary font-medium`),children:p(`chat.toolPart.openSubtask`,{type:e})})]})}t[2]=d,t[3]=b,t[4]=n,t[5]=C,t[6]=c,t[7]=f,t[8]=r,t[9]=i,t[10]=g,t[11]=v?.runtime,t[12]=o,t[13]=y,t[14]=h,t[15]=_,t[16]=p,t[17]=E,t[18]=D,t[19]=O,t[20]=k}else E=t[17],D=t[18],O=t[19],k=t[20];if(k!==Symbol.for(`react.early_return_sentinel`))return k;let A;t[31]!==n.length||t[32]!==C||t[33]!==w||t[34]!==s||t[35]!==o||t[36]!==p||t[37]!==S?(A=C?(0,$.jsxs)(`div`,{className:Y(`flex flex-col gap-1`,(n.length>0||o)&&`pt-1`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-foreground/80 hover:text-foreground w-full`,mw),onPointerDown:AT,onClick:e=>{e.stopPropagation(),T(jT)},children:[w?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(mw,`text-foreground/80 font-medium`),children:p(`chat.toolPart.output`)})]}),w?(0,$.jsx)(Jw,{maxHeightClass:`max-h-[50vh]`,children:(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Ns,{content:S,variant:`tool`,onShowPopup:s})})}):null]}):null,t[31]=n.length,t[32]=C,t[33]=w,t[34]=s,t[35]=o,t[36]=p,t[37]=S,t[38]=A):A=t[38];let j;return t[39]!==E||t[40]!==D||t[41]!==O||t[42]!==A?(j=(0,$.jsxs)(`div`,{className:E,children:[D,O,A]}),t[39]=E,t[40]=D,t[41]=O,t[42]=A,t[43]=j):j=t[43],j},oT=`
|
|
6551
|
+
`)},Fw=(e,t,n)=>{if(!t||e!==`edit`&&e!==`multiedit`&&e!==`apply_patch`)return;let r=Iw(e,t,n);if(r){let e=Nw(r);if(Number.isFinite(e))return e}},Iw=(e,t,n)=>{if(!t||e!==`edit`&&e!==`multiedit`&&e!==`apply_patch`)return;let r=Array.isArray(t.files)?t.files:[];if(r.length>0){let e=typeof n==`string`&&n.length>0?n:void 0,t=e?r.find(t=>{if(!t||typeof t!=`object`)return!1;let n=t;return n.relativePath===e||n.filePath===e||n.movePath===e}):r[0];if(t&&typeof t==`object`){let e=vC(t.patch)??vC(t.diff);if(e)return e}}let i=t.filediff;if(i&&typeof i==`object`){let e=vC(i.patch)??vC(i.diff);if(e)return e}let a=vC(t.patch)??vC(t.diff);if(a)return a},Lw=e=>{let t=e.trim().replace(/\\/g,`/`).replace(/\/{2,}/g,`/`);return!t||t===`/`?t:t.replace(/\/+$/,``)},Rw=(e,t)=>{let n=Lw(e),r=Lw(t);if(!n)return``;if(!r)return n;if(n===r)return`.`;let i=`${r}/`;return n.startsWith(i)?n.slice(i.length):n},zw=5,Bw=e=>typeof e==`object`&&!!e,Vw=e=>{if(!Bw(e))return null;let t=typeof e.message==`string`?e.message.trim():``;if(!t)return null;let n=typeof e.severity==`number`&&Number.isFinite(e.severity)?Math.trunc(e.severity):void 0;if(n!==void 0&&n!==1)return null;let r=Bw(e.range)?e.range:void 0,i=r&&Bw(r.start)?r.start:void 0,a=typeof i?.line==`number`&&Number.isFinite(i.line)?Math.max(0,Math.trunc(i.line)):0,o=typeof i?.character==`number`&&Number.isFinite(i.character)?Math.max(0,Math.trunc(i.character)):0;return{message:t,line:a+1,character:o+1}},Hw=(e,t,n)=>{let r=Bw(n?.filediff)?n.filediff:void 0,i=Bw(r)&&typeof r.file==`string`?r.file:null;if(e===`apply_patch`){let e=(Array.isArray(n?.files)?n.files:[]).find(e=>Bw(e)?typeof e.movePath==`string`||typeof e.filePath==`string`||typeof e.relativePath==`string`:!1);if(Bw(e))return typeof e.movePath==`string`?e.movePath:typeof e.filePath==`string`?e.filePath:typeof e.relativePath==`string`?e.relativePath:i;let t=vC(n?.patch)??vC(n?.diff),r=t?EC(void 0,t,e=>e).find(e=>e.renderMode===`diff`):void 0;return r?.title?r.title:i}return e===`edit`||e===`multiedit`?i||(typeof t?.filePath==`string`?t.filePath:typeof t?.file_path==`string`?t.file_path:typeof t?.path==`string`?t.path:null):e===`write`?typeof t?.filePath==`string`?t.filePath:typeof t?.file_path==`string`?t.file_path:typeof t?.path==`string`?t.path:null:null},Uw=(e,t,n,r)=>{if(![`edit`,`multiedit`,`write`,`apply_patch`].includes(e))return null;let i=Hw(e,t,n);if(!i||!n||!Bw(n.diagnostics))return null;let a=Lw(i),o=a.startsWith(`/`)?a:`${Lw(r)}/${a}`.replace(/\/+/g,`/`),s=n.diagnostics[a]??n.diagnostics[o];if(!Array.isArray(s))return null;let c=s.map(e=>Vw(e)).filter(e=>!!e);if(c.length===0)return null;let l=c.slice(0,zw);return{displayPath:a.startsWith(`/`)?Rw(a,r):a,diagnostics:l,remaining:Math.max(0,c.length-l.length)}},Ww=()=>{let e=(0,Q.c)(22),t=Ka(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=Oo(!1),e[0]=n):n=e[0];let r=n,i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=Oo(!0),e[1]=i):i=e[1];let a=i,o;e[2]===t?.availableThemes?o=e[3]:(o=()=>t?.availableThemes??[r,a],e[2]=t?.availableThemes,e[3]=o),t?.availableThemes;let s;e[4]===o?s=e[5]:(s=o(),e[4]=o,e[5]=s);let c=s,l=t?.lightThemeId??r.metadata.id,u=t?.darkThemeId??a.metadata.id,d;e[6]!==c||e[7]!==l?(d=c.find(e=>e.metadata.id===l)??r,e[6]=c,e[7]=l,e[8]=d):d=e[8];let f=d,p;e[9]!==c||e[10]!==u?(p=c.find(e=>e.metadata.id===u)??a,e[9]=c,e[10]=u,e[11]=p):p=e[11];let m=p,h,g;e[12]!==m||e[13]!==f?(h=()=>{Vs(f),Vs(m)},g=[m,f],e[12]=m,e[13]=f,e[14]=h,e[15]=g):(h=e[14],g=e[15]),Z.useEffect(h,g);let _=t?.currentTheme.metadata.variant??`light`,v;e[16]!==m.metadata.id||e[17]!==f.metadata.id?(v={light:f.metadata.id,dark:m.metadata.id},e[16]=m.metadata.id,e[17]=f.metadata.id,e[18]=v):v=e[18];let y=_===`dark`?`dark`:`light`,b;return e[19]!==v||e[20]!==y?(b={pierreTheme:v,pierreThemeType:y},e[19]=v,e[20]=y,e[21]=b):b=e[21],b},Gw=e=>{let t=e.match(/^User has answered your questions:\s*(.+?)\.\s*You can now/s);if(!t)return null;let n=[],r=t[1],i=/"([^"]+)"="([^"]*(?:[^"\\]|\\.)*)"/g,a;for(;(a=i.exec(r))!==null;)n.push({question:a[1],answer:a[2]});return n.length>0?n:null},Kw=(e,t,n)=>{let r=t,i=r.metadata,a=r.input;if(e.tool===`apply_patch`){let e=Array.isArray(i?.files)?i?.files:[],t=e[0],r=t?.relativePath||t?.filePath;return e.length>1?null:typeof r==`string`?Rw(r,n):null}if((e.tool===`edit`||e.tool===`multiedit`)&&a){let e=a?.filePath||a?.file_path||a?.path||i?.filePath||i?.file_path||i?.path;if(typeof e==`string`)return Rw(e,n)}if(e.tool===`read`&&a){let e=a?.filePath||a?.file_path||a?.path||i?.filePath||i?.file_path||i?.path;if(typeof e==`string`)return Rw(e,n)}if([`write`,`create`,`file_write`].includes(e.tool)&&a){let e=a?.filePath||a?.file_path||a?.path;if(typeof e==`string`)return Rw(e,n)}if(e.tool===`lsp`&&a){let e=a?.filePath||a?.file_path||a?.path;if(typeof e==`string`)return Rw(e,n)}return null},qw=(e,t)=>{if(!e)return``;let n=typeof e.operation==`string`?e.operation:`lsp`;if(n===`workspaceSymbol`)return`${n}${typeof e.query==`string`&&e.query.trim().length>0?` "${e.query.trim()}"`:``}`;let r=typeof e.filePath==`string`?e.filePath:typeof e.file_path==`string`?e.file_path:typeof e.path==`string`?e.path:``,i=r?Rw(r,t):``;if(n===`documentSymbol`)return i?`${n} ${i}`:n;let a=typeof e.line==`number`&&Number.isFinite(e.line)?Math.trunc(e.line):void 0,o=typeof e.character==`number`&&Number.isFinite(e.character)?Math.trunc(e.character):void 0,s=a!==void 0&&o!==void 0?`:${a}:${o}`:``;return i?`${n} ${i}${s}`:n},Jw=(e,t,n)=>{let r=t,i=r.metadata,a=r.input,o=Kw(e,t,n);if(o)return o;if(e.tool===`apply_patch`){let e=Array.isArray(i?.files)?i?.files:[];return e.length>1?`${e.length} files`:``}if(e.tool===`question`&&a?.questions&&Array.isArray(a.questions)){let e=a.questions.length;return`Asked ${e} question${e===1?``:`s`}`}if(e.tool===`bash`&&a?.command&&typeof a.command==`string`)return a.command.split(`
|
|
6552
|
+
`)[0].substring(0,100);if(e.tool===`task`&&a?.description&&typeof a.description==`string`)return a.description.substring(0,80);if(e.tool===`lsp`)return qw(a,n);let s=a?.description||i?.description||`title`in t&&t.title||``;return typeof s==`string`?s:``},Yw=e=>{let t=(0,Q.c)(17),{children:n,isMobile:r,maxHeightClass:i,className:a,outerClassName:o,disableHorizontal:s}=e,c=r!==void 0&&r,l=i===void 0?`max-h-[60vh]`:i,u=s!==void 0&&s,d;t[0]===o?d=t[1]:(d=Y(`w-full min-w-0 flex-none overflow-hidden`,o),t[0]=o,t[1]=d);let f;if(t[2]!==a||t[3]!==u||t[4]!==c||t[5]!==l){let e;t[7]===c?e=t[8]:(e=c&&zC(!0),t[7]=c,t[8]=e),f=Y(`tool-output-surface rounded-xl w-full min-w-0`,zC(c),l,u?`overflow-y-auto overflow-x-hidden`:`overflow-auto`,a,e),t[2]=a,t[3]=u,t[4]=c,t[5]=l,t[6]=f}else f=t[6];let p;t[9]===n?p=t[10]:(p=(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:n}),t[9]=n,t[10]=p);let m;t[11]!==f||t[12]!==p?(m=(0,$.jsx)(ja,{className:f,children:p}),t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==d||t[15]!==m?(h=(0,$.jsx)(`div`,{className:d,children:m}),t[14]=d,t[15]=m,t[16]=h):h=t[16],h},Xw=(e,t,n,r)=>t.tool===`bash`?`bash`:Mc(Bc(e,t.tool,n),t.tool,r),Zw=(e,t,n)=>t.tool===`bash`?e:Bc(e,t.tool,n),Qw=e=>{let t=(0,Q.c)(80),{output:n,part:r,metadata:i,input:a,isMobile:o}=e,s=o!==void 0&&o,{t:c}=ct(),l;t[0]!==i||t[1]!==n||t[2]!==r?(l=Zw(n,r,i),t[0]=i,t[1]=n,t[2]=r,t[3]=l):l=t[3];let u=l,d;t[4]!==a||t[5]!==i||t[6]!==n||t[7]!==r?(d=Xw(n,r,i,a),t[4]=a,t[5]=i,t[6]=n,t[7]=r,t[8]=d):d=t[8];let f=d,p;t[9]===u?p=t[10]:(p=Ic(u),t[9]=u,t[10]=p);let m=p,[h,g]=Z.useState(`formatted`),[_,v]=Z.useState(!1),y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{g(`formatted`),v(!1)},t[11]=y):y=t[11];let b;t[12]===u?b=t[13]:(b=[u],t[12]=u,t[13]=b),Z.useEffect(y,b);let x;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(x=(e,t)=>{t.stopPropagation(),g(e)},t[14]=x):x=t[14];let S=J(x),C;t[15]!==u||t[16]!==c?(C=async e=>{if(e.stopPropagation(),!(await ut(u)).ok){Br.error(c(`chat.toolPart.copyOutputFailed`));return}v(!0),typeof window<`u`&&window.setTimeout(()=>v(!1),1200)},t[15]=u,t[16]=c,t[17]=C):C=t[17];let w=J(C);if(m.isJson){let e=h===`formatted`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,n;t[18]===e?n=t[19]:(n=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,e),t[18]=e,t[19]=n);let r;t[20]===S?r=t[21]:(r=e=>S(`formatted`,e),t[20]=S,t[21]=r);let i;t[22]===c?i=t[23]:(i=c(`chat.toolPart.showFormattedJson`),t[22]=c,t[23]=i);let a;t[24]===c?a=t[25]:(a=c(`chat.toolPart.showFormattedJson`),t[24]=c,t[25]=a);let o;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(X,{name:`node-tree`,className:`h-3.5 w-3.5`}),t[26]=o):o=t[26];let s;t[27]!==n||t[28]!==r||t[29]!==i||t[30]!==a?(s=(0,$.jsx)(ua,{variant:`ghost`,size:`icon`,className:n,onClick:r,onPointerDown:wT,"aria-label":i,title:a,children:o}),t[27]=n,t[28]=r,t[29]=i,t[30]=a,t[31]=s):s=t[31];let l=h===`raw`&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,d;t[32]===l?d=t[33]:(d=Y(`h-6 w-6 rounded-md text-muted-foreground hover:text-foreground`,l),t[32]=l,t[33]=d);let f;t[34]===S?f=t[35]:(f=e=>S(`raw`,e),t[34]=S,t[35]=f);let p;t[36]===c?p=t[37]:(p=c(`chat.toolPart.showRawJson`),t[36]=c,t[37]=p);let g;t[38]===c?g=t[39]:(g=c(`chat.toolPart.showRawJson`),t[38]=c,t[39]=g);let v;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(X,{name:`code-box`,className:`h-3.5 w-3.5`}),t[40]=v):v=t[40];let y;t[41]!==d||t[42]!==f||t[43]!==p||t[44]!==g?(y=(0,$.jsx)(ua,{variant:`ghost`,size:`icon`,className:d,onClick:f,onPointerDown:TT,"aria-label":p,title:g,children:v}),t[41]=d,t[42]=f,t[43]=p,t[44]=g,t[45]=y):y=t[45];let b;t[46]!==_||t[47]!==c?(b=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[46]=_,t[47]=c,t[48]=b):b=t[48];let x;t[49]!==_||t[50]!==c?(x=c(_?`chat.toolPart.copiedOutput`:`chat.toolPart.copyOutput`),t[49]=_,t[50]=c,t[51]=x):x=t[51];let C=_?`check`:`file-copy`,T;t[52]===C?T=t[53]:(T=(0,$.jsx)(X,{name:C,className:`h-3.5 w-3.5`}),t[52]=C,t[53]=T);let E;t[54]!==w||t[55]!==b||t[56]!==x||t[57]!==T?(E=(0,$.jsx)(ua,{variant:`ghost`,size:`icon`,className:`h-6 w-6 rounded-md bg-[var(--surface-elevated)]/80 text-muted-foreground hover:text-foreground`,onClick:w,onPointerDown:ET,"aria-label":b,title:x,children:T}),t[54]=w,t[55]=b,t[56]=x,t[57]=T,t[58]=E):E=t[58];let D;t[59]!==s||t[60]!==y||t[61]!==E?(D=(0,$.jsxs)(`div`,{className:`absolute right-2 top-2 z-10 flex items-center gap-1`,children:[s,y,E]}),t[59]=s,t[60]=y,t[61]=E,t[62]=D):D=t[62];let O;t[63]!==m.data||t[64]!==h||t[65]!==u?(O=h===`formatted`?(0,$.jsx)(Hc,{data:m.data,initiallyExpandedDepth:1,maxHeight:`400px`}):(0,$.jsx)(`div`,{className:`typography-code pr-12 text-muted-foreground/90`,children:(0,$.jsx)(Fc,{language:`json`,code:u,style:lT,codeStyle:uT.style,wrap:!0})}),t[63]=m.data,t[64]=h,t[65]=u,t[66]=O):O=t[66];let k;return t[67]!==D||t[68]!==O?(k=(0,$.jsxs)(`div`,{className:`tool-output-surface relative p-2 rounded-xl w-full min-w-0`,children:[D,O]}),t[67]=D,t[68]=O,t[69]=k):k=t[69],k}let T=r.tool===`bash`?`typography-code text-muted-foreground/90`:void 0,E;t[70]!==s||t[71]!==r.tool?(E={...lT,...s&&r.tool===`bash`?{lineHeight:BC}:{}},t[70]=s,t[71]=r.tool,t[72]=E):E=t[72];let D;t[73]!==f||t[74]!==u||t[75]!==E?(D=(0,$.jsx)(Fc,{language:f,code:u,style:E,codeStyle:uT.style,wrap:!0}),t[73]=f,t[74]=u,t[75]=E,t[76]=D):D=t[76];let O;return t[77]!==D||t[78]!==T?(O=(0,$.jsx)(`div`,{className:T,children:D}),t[77]=D,t[78]=T,t[79]=O):O=t[79],O};Qw.displayName=`ToolScrollableTextOutput`;var $w=e=>{let t=e.state?.title;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.state?.input;if(n&&typeof n==`object`){let e=n.filePath??n.file_path??n.path;if(typeof e==`string`&&e.trim().length>0)return e.trim();let t=n.url;if(typeof t==`string`&&t.trim().length>0)return t.trim()}return``},eT=new Set([`read`,`view`,`file_read`,`cat`,`write`,`create`,`file_write`,`edit`,`multiedit`,`apply_patch`]),tT=(e,t)=>{if(!eT.has(e.toLowerCase()))return!1;let n=t.trim();if(!n||n===`Patch`||/^\d+\s+files$/.test(n))return!1;if(n.includes(`/`)||n.includes(`\\`))return!0;let r=n.split(/[\\/]/).pop()||n;return r.startsWith(`.`)||r.includes(`.`)?!0:/^[A-Za-z0-9_-]+$/.test(r)},nT=e=>{let t=Sw(e.tool),n=e.state?.status??``,r=$w(e);return`${e.id??``}\u0001${t}\u0001${n}\u0001${r}`},rT=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(nT(e[n])!==nT(t[n]))return!1;return!0},iT=Z.memo(e=>{let t=(0,Q.c)(10),{entry:n,isMobile:r,animateTailText:i,showToolFileIcons:a}=e,{t:o}=ct(),s;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==o){let e=Sw(n.tool),c=e.length>0?e:`tool`,l=$w(n),u=l.trim().length>0,d=n.state?.status,f=uc(c,o),p=r?`items-start`:`items-center`,m;t[6]===p?m=t[7]:(m=Y(`flex gap-1.5 min-w-0 w-full py-px`,p),t[6]=p,t[7]=m);let h,g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=Y(hw,`text-foreground/80 flex-shrink-0`),g={color:`var(--tools-title)`},t[8]=h,t[9]=g):(h=t[8],g=t[9]),s=(0,$.jsxs)(`div`,{className:m,children:[(0,$.jsx)(`span`,{className:`flex-shrink-0 scale-90 text-foreground/80`,children:oS(c)}),(0,$.jsx)(`span`,{className:h,style:g,title:f,children:f}),u?d!==`error`&&tT(c,l)?gT(l,i,!0,a,hw):d===`error`?(0,$.jsx)(`span`,{className:Y(hw,`flex-1 min-w-0 text-[var(--status-error)]`,r?`whitespace-normal break-words`:`truncate`),children:l}):(0,$.jsx)(aS,{variant:i?`generate-effect`:`static`,className:Y(hw,`flex-1 min-w-0 text-muted-foreground/70`,r?`whitespace-normal break-words`:`truncate`),style:{color:`var(--tools-description)`},title:l,children:l}):null]}),t[0]=i,t[1]=n,t[2]=r,t[3]=a,t[4]=o,t[5]=s}else s=t[5];return s},(e,t)=>e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&nT(e.entry)===nT(t.entry));iT.displayName=`TaskSummaryEntryRow`;var aT=Z.memo(e=>{let t=(0,Q.c)(24),{entries:n,isExpanded:r,isMobile:i,animateTailText:a,showToolFileIcons:o}=e,s;t[0]!==n||t[1]!==r?(s=r?n:n.slice(-6),t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=s,l=Math.max(0,n.length-c.length),u=n.length-c.length,d=r?`max-h-[40vh]`:`max-h-56`,f;t[3]===l?f=t[4]:(f=l>0?(0,$.jsxs)(`div`,{className:Y(hw,`text-muted-foreground/70`),children:[`+`,l,` more…`]}):null,t[3]=l,t[4]=f);let p;if(t[5]!==a||t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==c||t[10]!==u){let e;t[12]!==a||t[13]!==r||t[14]!==i||t[15]!==o||t[16]!==u?(e=(e,t)=>{let n=r?t:u+t,s=e.id??`${nT(e)}:${n}`;return(0,$.jsx)(iT,{entry:e,isMobile:i,animateTailText:a,showToolFileIcons:o},s)},t[12]=a,t[13]=r,t[14]=i,t[15]=o,t[16]=u,t[17]=e):e=t[17],p=c.map(e),t[5]=a,t[6]=r,t[7]=i,t[8]=o,t[9]=c,t[10]=u,t[11]=p}else p=t[11];let m;t[18]!==f||t[19]!==p?(m=(0,$.jsxs)(`div`,{className:gw,children:[f,p]}),t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==d||t[22]!==m?(h=(0,$.jsx)(Yw,{maxHeightClass:d,disableHorizontal:!0,children:m}),t[21]=d,t[22]=m,t[23]=h):h=t[23],h},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&e.showToolFileIcons===t.showToolFileIcons&&rT(e.entries,t.entries));aT.displayName=`TaskSummaryEntriesList`;var oT=e=>{let t=(0,Q.c)(44),{entries:n,isExpanded:r,isMobile:i,output:a,sessionId:o,onShowPopup:s,input:c,animateTailText:l,isActive:u}=e,d=l===void 0||l,f=u!==void 0&&u,{t:p}=ct(),m=pc(),h=ri(DT),g=q(OT),_=q(kT),v=Z.useContext(Ao),y=Rh(),b=y.directory||m,x;t[0]===a?x=t[1]:(x=typeof a==`string`?LS(a):``,t[0]=a,t[1]=x);let S=x,C=S.length>0,[w,T]=Z.useState(!1),E,D,O,k;if(t[2]!==d||t[3]!==b||t[4]!==n||t[5]!==C||t[6]!==c||t[7]!==f||t[8]!==r||t[9]!==i||t[10]!==g||t[11]!==v?.runtime||t[12]!==o||t[13]!==y||t[14]!==h||t[15]!==_||t[16]!==p){k=Symbol.for(`react.early_return_sentinel`);bb0:{let e=yw(vw(c)??`subagent`),a=t=>{t.stopPropagation(),o&&b&&Bh(y,o,b,()=>{if(!di({sessionId:o,directory:b})){if(fl()||i||v?.runtime.isVSCode){h(o,b);return}g(b,{mode:`chat`,dedupeKey:`session:${o}`,label:e,readOnly:!0})}})};if(n.length===0&&!C&&!o){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(hw,`text-muted-foreground/70`),t[21]=e):e=t[21];let n=f?`Waiting for subagent activity...`:`No subagent session id on task metadata.`,r;t[22]===n?r=t[23]:(r=(0,$.jsx)(`div`,{className:`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,children:(0,$.jsx)(`div`,{className:e,children:n})}),t[22]=n,t[23]=r),k=r;break bb0}t[24]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,`before:absolute before:left-[0.4375rem] before:w-px before:bg-border/80 before:content-[""]`,`before:top-0 before:bottom-0`),t[24]=E):E=t[24],t[25]!==d||t[26]!==n||t[27]!==r||t[28]!==i||t[29]!==_?(D=n.length>0?(0,$.jsx)(aT,{entries:n,isExpanded:r,isMobile:i,animateTailText:d,showToolFileIcons:_}):null,t[25]=d,t[26]=n,t[27]=r,t[28]=i,t[29]=_,t[30]=D):D=t[30],O=o&&y.capabilities.navigateNestedSession&&(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-primary hover:text-primary/80 w-full`,hw),onPointerDown:AT,onClick:a,children:[(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(hw,`text-primary font-medium`),children:p(`chat.toolPart.openSubtask`,{type:e})})]})}t[2]=d,t[3]=b,t[4]=n,t[5]=C,t[6]=c,t[7]=f,t[8]=r,t[9]=i,t[10]=g,t[11]=v?.runtime,t[12]=o,t[13]=y,t[14]=h,t[15]=_,t[16]=p,t[17]=E,t[18]=D,t[19]=O,t[20]=k}else E=t[17],D=t[18],O=t[19],k=t[20];if(k!==Symbol.for(`react.early_return_sentinel`))return k;let A;t[31]!==n.length||t[32]!==C||t[33]!==w||t[34]!==s||t[35]!==o||t[36]!==p||t[37]!==S?(A=C?(0,$.jsxs)(`div`,{className:Y(`flex flex-col gap-1`,(n.length>0||o)&&`pt-1`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-foreground/80 hover:text-foreground w-full`,hw),onPointerDown:jT,onClick:e=>{e.stopPropagation(),T(MT)},children:[w?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(hw,`text-foreground/80 font-medium`),children:p(`chat.toolPart.output`)})]}),w?(0,$.jsx)(Yw,{maxHeightClass:`max-h-[50vh]`,children:(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Ns,{content:S,variant:`tool`,onShowPopup:s})})}):null]}):null,t[31]=n.length,t[32]=C,t[33]=w,t[34]=s,t[35]=o,t[36]=p,t[37]=S,t[38]=A):A=t[38];let j;return t[39]!==E||t[40]!==D||t[41]!==O||t[42]!==A?(j=(0,$.jsxs)(`div`,{className:E,children:[D,O,A]}),t[39]=E,t[40]=D,t[41]=O,t[42]=A,t[43]=j):j=t[43],j},sT=`
|
|
6553
6553
|
[data-diff-header],
|
|
6554
6554
|
[data-diff] {
|
|
6555
6555
|
[data-separator] {
|
|
6556
6556
|
height: 24px !important;
|
|
6557
6557
|
}
|
|
6558
6558
|
}
|
|
6559
|
-
`,sT={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},cT={...ze.getCollapsedStyles(),padding:0,overflow:`visible`},lT={style:{background:`transparent`,backgroundColor:`transparent`}},uT={color:`var(--status-error)`},dT={color:`var(--tools-icon)`},fT={color:`var(--status-error)`},pT={color:`var(--tools-title)`},mT=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate typography-ui-label text-foreground`,t&&`flex-1`),style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 flex items-baseline overflow-hidden typography-ui-label`,t&&`flex-1`),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0 text-muted-foreground`,children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i})]})]})},hT=(e,t=!0,n=!0,r=!0,i=pw)=>{let a=e.lastIndexOf(`/`),o=i===mw?`h-3 w-3 flex-shrink-0`:`h-3.5 w-3.5 flex-shrink-0`;if(a===-1)return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(yd,{filePath:e,className:o}):null,(0,$.jsx)(iS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 truncate whitespace-nowrap`,i,n&&`flex-1`),style:{color:`var(--tools-description)`},children:e})]});let s=e.slice(0,a),c=e.slice(a+1),l=s.startsWith(`/`),u=l?s.slice(1):s;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(yd,{filePath:e,className:o}):null,(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full items-baseline overflow-hidden`,i,n&&`flex-1`),children:[l?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:u}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(iS,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:c})]})]})},gT=e=>{let t=(0,Q.c)(3),{diff:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={backgroundColor:`var(--syntax-base-background)`,color:`var(--syntax-base-foreground)`},t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`pre`,{className:`m-0 overflow-auto whitespace-pre-wrap break-words rounded-lg p-2 typography-code`,style:r,children:n}),t[1]=n,t[2]=i),i},_T=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1})}componentDidCatch(e){}render(){return this.state.hasError?this.props.fallback:this.props.children}},vT=Z.memo(e=>{let t=(0,Q.c)(13),{diff:n,pierreTheme:r,pierreThemeType:i,diffViewMode:a}=e,o=a===`side-by-side`?`split`:`unified`,s;t[0]!==r||t[1]!==i||t[2]!==o?(s={diffStyle:o,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:`wrap`,theme:r,themeType:i,unsafeCSS:oT},t[0]=r,t[1]=i,t[2]=o,t[3]=s):s=t[3];let c=s,l;t[4]===n?l=t[5]:(l=(0,$.jsx)(gT,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)($e,{patch:n,metrics:sT,options:c,className:`block w-full`}),t[6]=n,t[7]=c,t[8]=d):d=t[8];let f;return t[9]!==n||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0`,children:(0,$.jsx)(_T,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});vT.displayName=`DiffPreview`;var yT=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=ct(),{pierreTheme:s,pierreThemeType:c}=Uw(),[l,u]=Z.useState(`unified`),d=t,f=d.metadata,p=d.input,m=d.output,h=typeof m==`string`&&m.length>0,g=typeof m==`string`?m:``,_=zw(f?.filediff)?f.filediff:void 0,v=_C(f?.patch)??_C(f?.diff)??_C(_?.patch)??_C(_?.diff)??null,y=Z.useMemo(()=>TC(f,v??void 0,e=>Lw(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>Hw(e.tool,p,f,n),[n,p,f,e.tool]),S=Z.useMemo(()=>!p||typeof p!=`object`||Object.keys(p).length===0?``:`command`in p&&typeof p.command==`string`&&e.tool===`bash`?Uc(p,e.tool):typeof p.content==`string`?p.content??``:Uc(p,e.tool),[p,e.tool]),C=!b&&S.trim().length>0,w=e.tool===`write`||e.tool===`create`||e.tool===`file_write`,T=e.tool===`todowrite`||e.tool===`todoread`,E=Z.useMemo(()=>Array.isArray(p?.todos)?JSON.stringify(p.todos):g,[p?.todos,g]),D=Z.useMemo(()=>!w||!C?void 0:Nw(typeof p?.filePath==`string`?p.filePath:typeof p?.file_path==`string`?p.file_path:typeof p?.path==`string`?p.path:void 0,S),[C,p?.filePath,p?.file_path,p?.path,S,w]);Z.useEffect(()=>{u(`unified`)},[e.id]);let O=(e,t)=>(0,$.jsx)(Jw,{isMobile:i,maxHeightClass:t?.maxHeightClass,className:t?.className,disableHorizontal:t?.disableHorizontal,outerClassName:t?.outerClassName,children:e}),k=()=>{let n=()=>x?(0,$.jsxs)(`div`,{className:`tool-output-surface flex flex-col gap-2 rounded-xl border p-2`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--status-error-background)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium`,style:{color:`var(--status-error)`},children:o(`chat.toolPart.lspErrors`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 min-w-0`,children:mT(x.displayPath,!1)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:x.diagnostics.map((e,t)=>(0,$.jsx)(`div`,{className:`rounded-md border px-2 py-1`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--surface-elevated)`},children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`typography-micro shrink-0`,style:{color:`var(--status-error)`},children:[`[`,e.line,`:`,e.character,`]`]}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground whitespace-pre-wrap break-words`,children:e.message})]})},`${x.displayPath}:${e.line}:${e.character}:${t}`))}),x.remaining>0?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:o(`chat.toolPart.moreErrors`,{count:x.remaining})}):null]})]}):null;if(e.tool===`question`){if(t.status===`completed`&&h){let e=Ww(g);if(e&&e.length>0)return O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.question}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground whitespace-pre-wrap`,children:e.answer})]},t))}),{maxHeightClass:`max-h-[40vh]`})}if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:Lc(t.error)})]});let e=p;return e?.questions&&Array.isArray(e.questions)&&e.questions.length>0?O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.questions.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[e.header?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:Lc(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:Lc(e.question)}),Array.isArray(e.options)&&e.options.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:e.options.map(e=>(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-muted/30 border border-border/30 text-muted-foreground`,children:Lc(e.label)},Lc(e.label)))}):null]},t))}),{maxHeightClass:`max-h-[40vh]`}):(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:o(`chat.toolPart.awaitingResponse`)})}return e.tool===`task`&&h?O((0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Ns,{content:Lc(g),variant:`tool`,onShowPopup:a})})):(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`||e.tool===`write`)&&(y.length>0||x)?O((0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[y.map(e=>(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:e.renderMode===`diff`?(0,$.jsx)(vT,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(gT,{diff:e.patch})},e.id)),n()]}),{className:`p-1`}):e.tool===`write`&&x?O((0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:n()}),{className:`p-1`}):w?null:h&&g.trim()?O((0,$.jsx)(Zw,{output:Lc(g),part:e,metadata:f,input:p,isMobile:i}),{className:e.tool===`bash`?`p-1 rounded-none`:`p-1`,maxHeightClass:e.tool===`bash`?`max-h-[46vh]`:void 0}):O((0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground/70`,children:o(`chat.toolPart.noOutputProduced`)}),{maxHeightClass:`max-h-60`})};if(T){if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:LC(i,`todo-error`),children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-none border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:t.error})]});let n=Vc(E,void 0,{listClassName:Rc});return(0,$.jsx)(`div`,{className:LC(i,`todo`),children:O(n??(0,$.jsx)(Zw,{output:E,part:e,metadata:f,input:p,isMobile:i}),Oc)})}return(0,$.jsx)(`div`,{className:LC(i,`default`,e.tool===`bash`),children:e.tool===`question`?k():(0,$.jsxs)($.Fragment,{children:[C?(0,$.jsx)(`div`,{children:O(e.tool===`bash`?(0,$.jsx)(`pre`,{className:`tool-input-text whitespace-pre-wrap break-words typography-code text-muted-foreground/90 m-0 p-0`,style:i?{lineHeight:zC}:void 0,children:S}):w&&D?(0,$.jsx)(vT,{diff:D,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(`blockquote`,{className:`tool-input-text m-0 whitespace-pre-wrap break-words typography-meta italic text-muted-foreground/70`,children:S}),{maxHeightClass:w&&D&&r?`max-h-[50vh]`:`max-h-60`,className:e.tool===`bash`?`tool-input-surface p-0 rounded-none`:`tool-input-surface`})}):null,t.status===`completed`&&`output`in t&&(0,$.jsx)(`div`,{children:k()}),t.status===`error`&&`error`in t&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:Lc(t.error)})]})]})})});yT.displayName=`ToolExpandedContent`;var bT=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:s=!0})=>{let c=e.state,l=q(e=>e.showToolFileIcons),u=q(e=>e.showSubagentTaskDetails),d=q(e=>e.openContextPanelTab),f=q(e=>e.openContextDiff),p=q(e=>e.openContextToolDiff),m=q(e=>e.navigateToDiff),{t:h}=ct(),g=pc(),_=ri(e=>e.setCurrentSession),v=ng(),y=Lh(),b=y.directory||g||``,x=xw(e.tool),S=x===`task`,C=x===`todowrite`||x===`todoread`,w=Tw(x),T=c?.status,E=cw(e),D=T===`error`||T===`failed`,[O,k]=Z.useState(!E),A=Z.useRef(e.id),j=Z.useRef(``);Z.useEffect(()=>{A.current!==e.id&&(A.current=e.id,j.current=``,k(!E))},[E,e.id]),Z.useEffect(()=>{E||k(!0)},[E]),Z.useEffect(()=>{if(!E||D||!b||!Cw.has(x))return;let t=`${e.id}:${T??`unknown`}`;j.current!==t&&(j.current=t,gt.requestGitRefresh({directory:b}))},[b,D,E,x,e.id,T]);let M=E||S,N=Z.useRef(a);N.current=a;let P=Z.useRef(null);Z.useLayoutEffect(()=>{if(S||w)return;let e=P.current;if(!e){M&&N.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,M&&N.current?.(`structural`)},[n,w,S,M]);let F=c,I=F.metadata,L=e.metadata,R=F.input,z=F.time,[B,V]=Z.useState(()=>({start:typeof z?.start==`number`?z.start:void 0,end:typeof z?.end==`number`?z.end:void 0})),[H,U]=Z.useState(void 0),[W,ee]=Z.useState(void 0);Z.useEffect(()=>{V({}),U(void 0),ee(void 0)},[e.id]),Z.useEffect(()=>{E||typeof z?.start!=`number`&&U(e=>e??Date.now())},[E,z?.start]),Z.useEffect(()=>{V(e=>{let t={...e},n=!1;return typeof z?.start==`number`&&(typeof e.start!=`number`||z.start<e.start)&&(t.start=z.start,n=!0),typeof z?.end==`number`&&(typeof e.end!=`number`||z.end>e.end)&&(t.end=z.end,n=!0),n?t:e})},[z?.end,z?.start]);let G=Z.useMemo(()=>{if(typeof H==`number`)return H;let e=[B.start,z?.start].filter(e=>typeof e==`number`);if(e.length!==0)return Math.min(...e)},[H,B.start,z?.start]),K=Z.useMemo(()=>typeof F.output==`string`?F.output:void 0,[F.output]),te=Z.useMemo(()=>gS(K),[K]),ne=Z.useMemo(()=>{if(!S)return[];let e=I,t=hS(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:te.summaryEntries},[S,I,te.summaryEntries]),re=E&&ne.length>0,ie=Z.useMemo(()=>S?pS(I)||pS(F)||pS(R)||pS(L)||(te.sessionId?te.sessionId:_S(K)):void 0,[R,S,I,te.sessionId,L,F,K]),ae=Z.useMemo(()=>S&&E&&!!(vS(I)===`running`||vS(F)===`running`||vS(L)===`running`||te.status===`running`||xS(K)),[S,E,I,te.status,L,F,K]),[oe,se]=Z.useState(!0),ce=S&&(!E&&O||ae&&oe),le=ce?ie:void 0,ue=ce&&!ie?e.sessionID:void 0,de=le??ue,fe=Fi(le??``,b),pe=Fi(ue??``,b),me=Sr(de??``,b),he=jr(b,ce),ge=!!(ae&&fe?.type===`idle`&&typeof G==`number`&&(typeof me==`number`&&G<=me||typeof he==`number`&&G<=he));Z.useEffect(()=>{ge&&se(!1)},[ge]);let _e=!!(ae&&oe&&ie&&fe?.type!==`idle`),ve=!u||re?``:ie??``,ye=Ur(ve,b);wi(ve,b);let be=Z.useMemo(()=>!S||!ie||!Array.isArray(ye)||ye.length===0?[]:OS(ye),[ye,S,ie]);Z.useEffect(()=>{if(typeof z?.end==`number`||typeof B.end==`number`){ee(void 0);return}typeof G==`number`&&E&&ee(e=>e??Date.now())},[G,E,B.end,z?.end]);let xe=E?B.end??z?.end??W:void 0,Se=!E&&O,Ce=RS({isTaskTool:S,isFinalized:E,taskSessionId:ie,childSessionStatus:fe,parentSessionStatus:pe,statusObservedAt:me,taskStartedAt:G,statusSnapshotAt:he}),we=Se&&!Ce||_e,Te=!!(S&&we&&!D);Z.useEffect(()=>{Ce&&k(!1)},[Ce]);let Ee=E,De=Z.useMemo(()=>be.length>0?be:ne,[be,ne]),Oe=Z.useMemo(()=>De.map(tT).join(`\0`),[De]),ke=Z.useRef(null);Z.useEffect(()=>{if(!S){ke.current=null;return}let e=ke.current;ke.current=Oe,e!==null&&e!==Oe&&De.length!==0&&N.current?.(`structural`)},[S,De.length,Oe]);let Ae=Z.useMemo(()=>x===`edit`||x===`multiedit`||x===`apply_patch`?Aw(I):null,[I,x]),je=Z.useMemo(()=>x===`write`?jw(R):null,[R,x]),Me=x===`apply_patch`&&Array.isArray(I?.files)&&(I?.files).length>1,Ne=x===e.tool?e:{...e,tool:x},Pe=Gw(Ne,c,b),Fe=qw(Ne,c,b),Ie=uc(x||e.tool,h),Le=_t(S?ie:void 0,b),Re=_t(S?ie:void 0),ze=S?_w(R,I,L,Le??Re):void 0,Be=LS({isTaskTool:S,isFinalized:E,taskSessionId:ie,taskAgentName:ze,displayName:Ie,delegatingLabel:h(`chat.assistantStatus.delegatingTask`),formatName:vw}),Ve=S&&Be.isDelegating,He=Be.title,Ue=typeof e.sessionID==`string`?e.sessionID.trim():``,We=Z.useMemo(()=>{if(!S||!Ue)return null;let n=typeof ie==`string`&&ie.trim().length>0?ie.trim():void 0,r=typeof e.id==`string`&&e.id.trim().length>0?e.id.trim():void 0,i=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():typeof t==`string`&&t.trim().length>0?t.trim():void 0;return{sessionID:Ue,...r?{partID:r}:{},...i?{messageID:i}:{},...b?{directory:b}:{},directoryPresent:!!b,childSessionPresent:!!n,...n?{childSessionID:n}:{},...T?{toolStatus:T}:{},finalized:E,backgroundRunning:_e,effectiveActive:we,suppressLoading:Ce,delegating:Ve,childStatus:xr(fe),parentStatus:xr(pe),idleConfirmed:ge,navigateCapability:y.capabilities.navigateNestedSession,surfaceKind:y.kind,...typeof G==`number`?{taskStartedAt:G}:{},...typeof me==`number`?{statusObservedAt:me}:{},...typeof he==`number`?{statusSnapshotAt:he}:{}}},[ge,fe,b,we,G,Ve,E,S,t,Ue,pe,e.id,e.messageID,y.capabilities.navigateNestedSession,y.kind,T,me,he,Ce,_e,ie]),Ge=We?vi(We):``,Ke=Z.useRef(We);Ke.current=We,Z.useEffect(()=>{let e=Ke.current;!e||!Ge||gi(e)},[Ge]);let qe=J((e,t)=>{let n=Ke.current;n&&dr({...n,opened:e,clickSource:t})}),Je=Ve?{"data-delegating":`true`}:void 0,Ye=Z.useMemo(()=>{if(x===`bash`||x===`apply_patch`||x===`lsp`||Pe&&(x===`apply_patch`||x===`edit`||x===`multiedit`||x===`write`))return null;let e=F.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=R?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Pe,x,F,R]),Xe=Z.useContext(Ao),Ze=Z.useRef(!1),Qe=J(e=>{let t=e??ie;return!t||!b?!1:(Ze.current=!1,zh(y,t,b,()=>{if(!di({sessionId:t,directory:b})){if(i||Xe?.runtime.isVSCode){_(t,b);return}d(b,{mode:`chat`,dedupeKey:`session:${t}`,label:He,readOnly:!0})}}))});Z.useEffect(()=>{!Ze.current||!ie||qe(Qe(ie),`queued-effect`)},[ie]);let $e=n=>{if(S){n.stopPropagation();let e=y.capabilities.navigateNestedSession,t=e?Qe():!1;qe(t,`row`),e&&!t&&(Ze.current=!0);return}if(w&&!b)return;let a,o,s;if(x===`edit`||x===`multiedit`||x===`apply_patch`)a=Vw(x,R,I),o=Pw(x,I,typeof a==`string`?a:void 0),typeof a==`string`&&(s=Fw(x,I,a));else if([`write`,`create`,`file_write`].includes(x))a=R?.filePath||R?.file_path||R?.path||I?.filePath||I?.file_path||I?.path,o=1,typeof a==`string`&&typeof R?.content==`string`&&(s=Nw(a,R.content));else if(x===`lsp`){a=R?.filePath||R?.file_path||R?.path;let e=R?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=bo(b,a)||(a.startsWith(`/`)?a:b.endsWith(`/`)?b+a:`${b}/${a}`);if(w){let e=Lw(r,b),n=s?DC(x,I,s,e,e=>Lw(e,b)):[],a=Ew(x)&&n.length===1&&n[0]?[{path:e,patch:n[0].patch}]:n.map(e=>({path:e.title,patch:e.patch}));if(Xe?.runtime.isVSCode&&Xe.editor&&s){let t=`${e} (changes)`;Xe.editor.openDiff(``,r,t,{line:o,patch:s});return}if(wo(r,b)){v?a.length>0?v.openToolDiff({diffPath:e,patches:a,targetLine:o}):x===`apply_patch`?v.openTurnDiff(t,y.sessionId):v.openChanges({diffPath:e,staged:!1,targetLine:o}):i?m(e,!1,Ew(x)?`working`:`turn`,o):a.length>0?p(b,e,a,o,t,y.sessionId):f(b,e,!1,Ew(x)?`working`:`turn`,o,t,y.sessionId);return}if(Xe?.editor){Xe.editor.openFile(r,o);return}mc(r,b).then(()=>{let e=q.getState(),t=vo(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(x===`lsp`){if(Xe?.editor){Xe.editor.openFile(r,o);return}let e=()=>{let e=q.getState(),t=vo(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!wo(r,b)){mc(r,b).then(e);return}e();return}if(Xe?.editor){if(Xe.runtime.isVSCode&&s&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${Lw(r,b)} (changes)`;Xe.editor.openDiff(``,r,e,{line:o,patch:s});return}Xe.editor.openFile(r,o);return}}if(x===`apply_patch`&&v){n.stopPropagation(),v.openTurnDiff(t,y.sessionId);return}if(x===`apply_patch`&&b&&!v&&!i&&!Xe?.runtime.isVSCode){n.stopPropagation(),d(b,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:y.sessionId});return}w||r(e.id)},et=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),$e(e))},tt=!S&&D?uT:dT,nt=!S&&D?fT:pT,rt=S&&u&&(De.length>0||we||Ee||!!ie),it=!S&&!w&&n;return!Ee&&!Se&&!S?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,mm,S&&`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Me?`flex-wrap items-start`:`items-center`),"data-mobile-press-feedback":`soft`,...Je,onClick:$e,onKeyDown:et,role:`button`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5`,Me?`w-full min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`:`items-center flex-shrink-0`),children:[(0,$.jsx)(`div`,{className:Y(`relative flex-shrink-0`,i?`size-4`:`size-3.5`),children:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,style:S&&Be.showAvatar?void 0:tt,children:S&&Be.showAvatar?(0,$.jsx)(la,{name:e.id||ze||`subagent`,size:14,label:He}):we?(0,$.jsx)(KC,{isMobile:i,className:`text-[var(--tools-icon)]`,label:h(`chat.assistantStatus.usingTool`,{tool:He})}):aS(x||e.tool)})}),Me?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(fw,`flex-shrink-0`),style:nt,title:Ie,children:Ie}),bw(I,s,l)]}):(0,$.jsxs)($.Fragment,{children:[Te?(0,$.jsx)(`span`,{className:Y(fw,`shrink-0 whitespace-nowrap animate-text-shimmer`),style:{color:`var(--tools-title)`,"--oc-text-shimmer-base":`var(--tools-title)`},title:He,children:He}):(0,$.jsx)(`span`,{className:Y(fw,`shrink-0 whitespace-nowrap`),style:nt,title:He,children:He}),x===`bash`&&typeof G==`number`?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,pw),children:(0,$.jsx)(Ow,{start:G,end:typeof xe==`number`?xe:void 0,active:!!(we&&typeof xe!=`number`)})}):null]})]}),!Me&&(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,pw),style:{color:`var(--tools-description)`},children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[Ye&&(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,pw,Te&&`animate-text-shimmer`),style:{color:`var(--tools-description)`,...Te?{"--oc-text-shimmer-base":`var(--tools-description)`}:{opacity:.8}},title:Ye,children:Ye}),!Ye&&x===`lsp`&&Pe?hT(Pe,s,!1,l):null,!Ye&&x!==`lsp`&&Fe&&(Pe&&Fe===Pe?hT(Pe,s,!1,l):(0,$.jsx)(iS,{variant:s?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,pw),style:{color:`var(--tools-description)`},title:Fe,children:Fe})),Ae&&(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,Ae.added]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,Ae.removed]})]}),je&&(0,$.jsx)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,je]})})]})}),!w&&(!S||u)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:S?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),rt?(0,$.jsx)(aT,{entries:De,isExpanded:n,isMobile:i,output:K,sessionId:ie,onShowPopup:o,input:R,animateTailText:s,isActive:we}):null,!S&&!w&&n?(0,$.jsx)(`div`,{ref:P,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:it?(0,$.jsxs)(`div`,{className:C?`relative ml-0.5 pl-1.5`:IC,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),(0,$.jsx)(yT,{part:e,state:c,currentDirectory:b,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},xT=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1,error:void 0})}componentDidCatch(e){}render(){if(!this.state.hasError)return this.props.children;let e=this.state.error?.message;return(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1.5 min-w-0`,fm),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:uT,children:aS(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(fw,`flex-shrink-0`),style:fT,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(pw,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},ST=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=ct(),r=FC(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=xw(e.part.tool)||`tool`,i=uc(a,n),t[0]=e.part.tool,t[1]=n,t[2]=i,t[3]=a):(i=t[2],a=t[3]);let o=i,s;t[4]!==r||t[5]!==e.part.id?(s=()=>!r||yw.get(e.part.id)===!0,t[4]=r,t[5]=e.part.id,t[6]=s):s=t[6];let[c,l]=Z.useState(s),u,d;if(t[7]!==r||t[8]!==c||t[9]!==e.part.id?(u=()=>{if(!(!r||c))return vc(()=>{yw.set(e.part.id,!0,e.part.id.length*2+8),Z.startTransition(()=>{l(!0)})})},d=[r,c,e.part.id],t[7]=r,t[8]=c,t[9]=e.part.id,t[10]=u,t[11]=d):(u=t[10],d=t[11]),Z.useEffect(u,d),!c){let e,n,r;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(`flex min-w-0 items-center gap-2`,fm),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(fw,`shrink-0 text-muted-foreground`),t[12]=e,t[13]=n,t[14]=r):(e=t[12],n=t[13],r=t[14]);let i;t[15]===o?i=t[16]:(i=(0,$.jsx)(`span`,{className:r,children:o}),t[15]=o,t[16]=i);let a;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`span`,{className:`h-3 w-24 min-w-0 rounded bg-muted/40`,"aria-hidden":`true`}),t[17]=a):a=t[17];let s;return t[18]===i?s=t[19]:(s=(0,$.jsxs)(`div`,{className:e,children:[n,i,a]}),t[18]=i,t[19]=s),s}let f;t[20]===n?f=t[21]:(f=n(`chat.toolPart.error`),t[20]=n,t[21]=f);let p;t[22]===e?p=t[23]:(p=(0,$.jsx)(bT,{...e}),t[22]=e,t[23]=p);let m;return t[24]!==o||t[25]!==e.part||t[26]!==f||t[27]!==p||t[28]!==a?(m=(0,$.jsx)(xT,{displayName:o,errorLabel:f,resetKey:e.part,toolName:a,children:p}),t[24]=o,t[25]=e.part,t[26]=f,t[27]=p,t[28]=a,t[29]=m):m=t[29],m},(e,t)=>KS([e.part],[t.part])&&e.messageId===t.messageId&&e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.alwaysShowActions===t.alwaysShowActions&&e.onContentChange===t.onContentChange&&e.onShowPopup===t.onShowPopup&&e.animateTailText===t.animateTailText);function CT(e){return e.stopPropagation()}function wT(e){return e.stopPropagation()}function TT(e){return e.stopPropagation()}function ET(e){return e.setCurrentSession}function DT(e){return e.openContextPanelTab}function OT(e){return e.showToolFileIcons}function kT(e){return e.stopPropagation()}function AT(e){return e.stopPropagation()}function jT(e){return!e}var MT=(e,t,n)=>{let r=t-e;return Math.max(0,n-r)},NT=e=>{e.timer&&=(clearTimeout(e.timer),null)},PT=({text:e,isStreaming:t,throttleMs:n=xc(Le()).textThrottleMs,identityKey:r})=>{let[i,a]=Z.useState(e),o=Z.useRef(e),s=Z.useRef(i),c=Z.useRef({timer:null,pendingText:e,lastEmitAt:0});return Z.useEffect(()=>{o.current=e},[e]),Z.useEffect(()=>{s.current=i},[i]),Z.useEffect(()=>{let e=c.current;NT(e),e.pendingText=o.current,e.lastEmitAt=0,a(o.current)},[r]),Z.useEffect(()=>{let r=c.current;r.pendingText=e;let i=s.current,o=t&&i.length>e.length?i:e;if(!t){NT(r),r.lastEmitAt=Date.now(),a(o);return}let l=Date.now(),u=MT(r.lastEmitAt,l,n);if(u<=0){NT(r),r.lastEmitAt=l,a(o);return}return NT(r),r.timer=setTimeout(()=>{r.timer=null,r.lastEmitAt=Date.now(),a(e=>t&&e.length>r.pendingText.length?e:r.pendingText)},u),()=>{NT(r)}},[t,e,n]),Z.useEffect(()=>{let e=c.current;return()=>{NT(e)}},[]),i},FT=e=>e.isStreaming?e.throttledTextContent:e.textContent,IT=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,LT=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=ct(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(RT)],t[2]=n.highlights,t[3]=n.subject,t[4]=e):e=t[4],l=e.join(`
|
|
6559
|
+
`,cT={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},lT={...ze.getCollapsedStyles(),padding:0,overflow:`visible`},uT={style:{background:`transparent`,backgroundColor:`transparent`}},dT={color:`var(--status-error)`},fT={color:`var(--tools-icon)`},pT={color:`var(--status-error)`},mT={color:`var(--tools-title)`},hT=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate typography-ui-label text-foreground`,t&&`flex-1`),style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 flex items-baseline overflow-hidden typography-ui-label`,t&&`flex-1`),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0 text-muted-foreground`,children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i})]})]})},gT=(e,t=!0,n=!0,r=!0,i=mw)=>{let a=e.lastIndexOf(`/`),o=i===hw?`h-3 w-3 flex-shrink-0`:`h-3.5 w-3.5 flex-shrink-0`;if(a===-1)return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(yd,{filePath:e,className:o}):null,(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 truncate whitespace-nowrap`,i,n&&`flex-1`),style:{color:`var(--tools-description)`},children:e})]});let s=e.slice(0,a),c=e.slice(a+1),l=s.startsWith(`/`),u=l?s.slice(1):s;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex items-center gap-1 overflow-hidden`,n&&`flex-1`),title:e,children:[r?(0,$.jsx)(yd,{filePath:e,className:o}):null,(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full items-baseline overflow-hidden`,i,n&&`flex-1`),children:[l?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:u}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:c})]})]})},_T=e=>{let t=(0,Q.c)(3),{diff:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={backgroundColor:`var(--syntax-base-background)`,color:`var(--syntax-base-foreground)`},t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`pre`,{className:`m-0 overflow-auto whitespace-pre-wrap break-words rounded-lg p-2 typography-code`,style:r,children:n}),t[1]=n,t[2]=i),i},vT=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1})}componentDidCatch(e){}render(){return this.state.hasError?this.props.fallback:this.props.children}},yT=Z.memo(e=>{let t=(0,Q.c)(13),{diff:n,pierreTheme:r,pierreThemeType:i,diffViewMode:a}=e,o=a===`side-by-side`?`split`:`unified`,s;t[0]!==r||t[1]!==i||t[2]!==o?(s={diffStyle:o,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,disableFileHeader:!0,maxLineDiffLength:1e3,expansionLineCount:20,overflow:`wrap`,theme:r,themeType:i,unsafeCSS:sT},t[0]=r,t[1]=i,t[2]=o,t[3]=s):s=t[3];let c=s,l;t[4]===n?l=t[5]:(l=(0,$.jsx)(_T,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)($e,{patch:n,metrics:cT,options:c,className:`block w-full`}),t[6]=n,t[7]=c,t[8]=d):d=t[8];let f;return t[9]!==n||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0`,children:(0,$.jsx)(vT,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});yT.displayName=`DiffPreview`;var bT=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=ct(),{pierreTheme:s,pierreThemeType:c}=Ww(),[l,u]=Z.useState(`unified`),d=t,f=d.metadata,p=d.input,m=d.output,h=typeof m==`string`&&m.length>0,g=typeof m==`string`?m:``,_=Bw(f?.filediff)?f.filediff:void 0,v=vC(f?.patch)??vC(f?.diff)??vC(_?.patch)??vC(_?.diff)??null,y=Z.useMemo(()=>EC(f,v??void 0,e=>Rw(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>Uw(e.tool,p,f,n),[n,p,f,e.tool]),S=Z.useMemo(()=>!p||typeof p!=`object`||Object.keys(p).length===0?``:`command`in p&&typeof p.command==`string`&&e.tool===`bash`?Uc(p,e.tool):typeof p.content==`string`?p.content??``:Uc(p,e.tool),[p,e.tool]),C=!b&&S.trim().length>0,w=e.tool===`write`||e.tool===`create`||e.tool===`file_write`,T=e.tool===`todowrite`||e.tool===`todoread`,E=Z.useMemo(()=>Array.isArray(p?.todos)?JSON.stringify(p.todos):g,[p?.todos,g]),D=Z.useMemo(()=>!w||!C?void 0:Pw(typeof p?.filePath==`string`?p.filePath:typeof p?.file_path==`string`?p.file_path:typeof p?.path==`string`?p.path:void 0,S),[C,p?.filePath,p?.file_path,p?.path,S,w]);Z.useEffect(()=>{u(`unified`)},[e.id]);let O=(e,t)=>(0,$.jsx)(Yw,{isMobile:i,maxHeightClass:t?.maxHeightClass,className:t?.className,disableHorizontal:t?.disableHorizontal,outerClassName:t?.outerClassName,children:e}),k=()=>{let n=()=>x?(0,$.jsxs)(`div`,{className:`tool-output-surface flex flex-col gap-2 rounded-xl border p-2`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--status-error-background)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium`,style:{color:`var(--status-error)`},children:o(`chat.toolPart.lspErrors`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 min-w-0`,children:hT(x.displayPath,!1)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:x.diagnostics.map((e,t)=>(0,$.jsx)(`div`,{className:`rounded-md border px-2 py-1`,style:{borderColor:`var(--status-error-border)`,backgroundColor:`var(--surface-elevated)`},children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`typography-micro shrink-0`,style:{color:`var(--status-error)`},children:[`[`,e.line,`:`,e.character,`]`]}),(0,$.jsx)(`span`,{className:`typography-meta text-foreground whitespace-pre-wrap break-words`,children:e.message})]})},`${x.displayPath}:${e.line}:${e.character}:${t}`))}),x.remaining>0?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:o(`chat.toolPart.moreErrors`,{count:x.remaining})}):null]})]}):null;if(e.tool===`question`){if(t.status===`completed`&&h){let e=Gw(g);if(e&&e.length>0)return O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.question}),(0,$.jsx)(`div`,{className:`typography-meta text-foreground whitespace-pre-wrap`,children:e.answer})]},t))}),{maxHeightClass:`max-h-[40vh]`})}if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:Lc(t.error)})]});let e=p;return e?.questions&&Array.isArray(e.questions)&&e.questions.length>0?O((0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.questions.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[e.header?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:Lc(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:Lc(e.question)}),Array.isArray(e.options)&&e.options.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:e.options.map(e=>(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-muted/30 border border-border/30 text-muted-foreground`,children:Lc(e.label)},Lc(e.label)))}):null]},t))}),{maxHeightClass:`max-h-[40vh]`}):(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:o(`chat.toolPart.awaitingResponse`)})}return e.tool===`task`&&h?O((0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(Ns,{content:Lc(g),variant:`tool`,onShowPopup:a})})):(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`||e.tool===`write`)&&(y.length>0||x)?O((0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[y.map(e=>(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:e.renderMode===`diff`?(0,$.jsx)(yT,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(_T,{diff:e.patch})},e.id)),n()]}),{className:`p-1`}):e.tool===`write`&&x?O((0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:n()}),{className:`p-1`}):w?null:h&&g.trim()?O((0,$.jsx)(Qw,{output:Lc(g),part:e,metadata:f,input:p,isMobile:i}),{className:e.tool===`bash`?`p-1 rounded-none`:`p-1`,maxHeightClass:e.tool===`bash`?`max-h-[46vh]`:void 0}):O((0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground/70`,children:o(`chat.toolPart.noOutputProduced`)}),{maxHeightClass:`max-h-60`})};if(T){if(t.status===`error`&&`error`in t)return(0,$.jsxs)(`div`,{className:RC(i,`todo-error`),children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-none border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:t.error})]});let n=Vc(E,void 0,{listClassName:Rc});return(0,$.jsx)(`div`,{className:RC(i,`todo`),children:O(n??(0,$.jsx)(Qw,{output:E,part:e,metadata:f,input:p,isMobile:i}),Oc)})}return(0,$.jsx)(`div`,{className:RC(i,`default`,e.tool===`bash`),children:e.tool===`question`?k():(0,$.jsxs)($.Fragment,{children:[C?(0,$.jsx)(`div`,{children:O(e.tool===`bash`?(0,$.jsx)(`pre`,{className:`tool-input-text whitespace-pre-wrap break-words typography-code text-muted-foreground/90 m-0 p-0`,style:i?{lineHeight:BC}:void 0,children:S}):w&&D?(0,$.jsx)(yT,{diff:D,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(`blockquote`,{className:`tool-input-text m-0 whitespace-pre-wrap break-words typography-meta italic text-muted-foreground/70`,children:S}),{maxHeightClass:w&&D&&r?`max-h-[50vh]`:`max-h-60`,className:e.tool===`bash`?`tool-input-surface p-0 rounded-none`:`tool-input-surface`})}):null,t.status===`completed`&&`output`in t&&(0,$.jsx)(`div`,{children:k()}),t.status===`error`&&`error`in t&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-muted-foreground/80`,children:o(`chat.toolPart.error`)}),(0,$.jsx)(`div`,{className:`typography-meta p-2 rounded-xl border`,style:{backgroundColor:`var(--status-error-background)`,color:`var(--status-error)`,borderColor:`var(--status-error-border)`},children:Lc(t.error)})]})]})})});bT.displayName=`ToolExpandedContent`;var xT=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:s=!0})=>{let c=e.state,l=q(e=>e.showToolFileIcons),u=q(e=>e.showSubagentTaskDetails),d=q(e=>e.openContextPanelTab),f=q(e=>e.openContextDiff),p=q(e=>e.openContextToolDiff),m=q(e=>e.navigateToDiff),{t:h}=ct(),g=pc(),_=ri(e=>e.setCurrentSession),v=rg(),y=Rh(),b=y.directory||g||``,x=Sw(e.tool),S=x===`task`,C=x===`todowrite`||x===`todoread`,w=Ew(x),T=c?.status,E=lw(e),D=T===`error`||T===`failed`,[O,k]=Z.useState(!E),A=Z.useRef(e.id),j=Z.useRef(``);Z.useEffect(()=>{A.current!==e.id&&(A.current=e.id,j.current=``,k(!E))},[E,e.id]),Z.useEffect(()=>{E||k(!0)},[E]),Z.useEffect(()=>{if(!E||D||!b||!ww.has(x))return;let t=`${e.id}:${T??`unknown`}`;j.current!==t&&(j.current=t,gt.requestGitRefresh({directory:b}))},[b,D,E,x,e.id,T]);let M=E||S,N=Z.useRef(a);N.current=a;let P=Z.useRef(null);Z.useLayoutEffect(()=>{if(S||w)return;let e=P.current;if(!e){M&&N.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,M&&N.current?.(`structural`)},[n,w,S,M]);let F=c,I=F.metadata,L=e.metadata,R=F.input,z=F.time,[B,V]=Z.useState(()=>({start:typeof z?.start==`number`?z.start:void 0,end:typeof z?.end==`number`?z.end:void 0})),[H,U]=Z.useState(void 0),[W,ee]=Z.useState(void 0);Z.useEffect(()=>{V({}),U(void 0),ee(void 0)},[e.id]),Z.useEffect(()=>{E||typeof z?.start!=`number`&&U(e=>e??Date.now())},[E,z?.start]),Z.useEffect(()=>{V(e=>{let t={...e},n=!1;return typeof z?.start==`number`&&(typeof e.start!=`number`||z.start<e.start)&&(t.start=z.start,n=!0),typeof z?.end==`number`&&(typeof e.end!=`number`||z.end>e.end)&&(t.end=z.end,n=!0),n?t:e})},[z?.end,z?.start]);let G=Z.useMemo(()=>{if(typeof H==`number`)return H;let e=[B.start,z?.start].filter(e=>typeof e==`number`);if(e.length!==0)return Math.min(...e)},[H,B.start,z?.start]),K=Z.useMemo(()=>typeof F.output==`string`?F.output:void 0,[F.output]),te=Z.useMemo(()=>_S(K),[K]),ne=Z.useMemo(()=>{if(!S)return[];let e=I,t=gS(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:te.summaryEntries},[S,I,te.summaryEntries]),re=E&&ne.length>0,ie=Z.useMemo(()=>S?mS(I)||mS(F)||mS(R)||mS(L)||(te.sessionId?te.sessionId:vS(K)):void 0,[R,S,I,te.sessionId,L,F,K]),ae=Z.useMemo(()=>S&&E&&!!(yS(I)===`running`||yS(F)===`running`||yS(L)===`running`||te.status===`running`||SS(K)),[S,E,I,te.status,L,F,K]),[oe,se]=Z.useState(!0),ce=S&&(!E&&O||ae&&oe),le=ce?ie:void 0,ue=ce&&!ie?e.sessionID:void 0,de=le??ue,fe=Fi(le??``,b),pe=Fi(ue??``,b),me=Sr(de??``,b),he=jr(b,ce),ge=!!(ae&&fe?.type===`idle`&&typeof G==`number`&&(typeof me==`number`&&G<=me||typeof he==`number`&&G<=he));Z.useEffect(()=>{ge&&se(!1)},[ge]);let _e=!!(ae&&oe&&ie&&fe?.type!==`idle`),ve=!u||re?``:ie??``,ye=Ur(ve,b);wi(ve,b);let be=Z.useMemo(()=>!S||!ie||!Array.isArray(ye)||ye.length===0?[]:kS(ye),[ye,S,ie]);Z.useEffect(()=>{if(typeof z?.end==`number`||typeof B.end==`number`){ee(void 0);return}typeof G==`number`&&E&&ee(e=>e??Date.now())},[G,E,B.end,z?.end]);let xe=E?B.end??z?.end??W:void 0,Se=!E&&O,Ce=zS({isTaskTool:S,isFinalized:E,taskSessionId:ie,childSessionStatus:fe,parentSessionStatus:pe,statusObservedAt:me,taskStartedAt:G,statusSnapshotAt:he}),we=Se&&!Ce||_e,Te=!!(S&&we&&!D);Z.useEffect(()=>{Ce&&k(!1)},[Ce]);let Ee=E,De=Z.useMemo(()=>be.length>0?be:ne,[be,ne]),Oe=Z.useMemo(()=>De.map(nT).join(`\0`),[De]),ke=Z.useRef(null);Z.useEffect(()=>{if(!S){ke.current=null;return}let e=ke.current;ke.current=Oe,e!==null&&e!==Oe&&De.length!==0&&N.current?.(`structural`)},[S,De.length,Oe]);let Ae=Z.useMemo(()=>x===`edit`||x===`multiedit`||x===`apply_patch`?jw(I):null,[I,x]),je=Z.useMemo(()=>x===`write`?Mw(R):null,[R,x]),Me=x===`apply_patch`&&Array.isArray(I?.files)&&(I?.files).length>1,Ne=x===e.tool?e:{...e,tool:x},Pe=Kw(Ne,c,b),Fe=Jw(Ne,c,b),Ie=uc(x||e.tool,h),Le=_t(S?ie:void 0,b),Re=_t(S?ie:void 0),ze=S?vw(R,I,L,Le??Re):void 0,Be=RS({isTaskTool:S,isFinalized:E,taskSessionId:ie,taskAgentName:ze,displayName:Ie,delegatingLabel:h(`chat.assistantStatus.delegatingTask`),formatName:yw}),Ve=S&&Be.isDelegating,He=Be.title,Ue=typeof e.sessionID==`string`?e.sessionID.trim():``,We=Z.useMemo(()=>{if(!S||!Ue)return null;let n=typeof ie==`string`&&ie.trim().length>0?ie.trim():void 0,r=typeof e.id==`string`&&e.id.trim().length>0?e.id.trim():void 0,i=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():typeof t==`string`&&t.trim().length>0?t.trim():void 0;return{sessionID:Ue,...r?{partID:r}:{},...i?{messageID:i}:{},...b?{directory:b}:{},directoryPresent:!!b,childSessionPresent:!!n,...n?{childSessionID:n}:{},...T?{toolStatus:T}:{},finalized:E,backgroundRunning:_e,effectiveActive:we,suppressLoading:Ce,delegating:Ve,childStatus:xr(fe),parentStatus:xr(pe),idleConfirmed:ge,navigateCapability:y.capabilities.navigateNestedSession,surfaceKind:y.kind,...typeof G==`number`?{taskStartedAt:G}:{},...typeof me==`number`?{statusObservedAt:me}:{},...typeof he==`number`?{statusSnapshotAt:he}:{}}},[ge,fe,b,we,G,Ve,E,S,t,Ue,pe,e.id,e.messageID,y.capabilities.navigateNestedSession,y.kind,T,me,he,Ce,_e,ie]),Ge=We?vi(We):``,Ke=Z.useRef(We);Ke.current=We,Z.useEffect(()=>{let e=Ke.current;!e||!Ge||gi(e)},[Ge]);let qe=J((e,t)=>{let n=Ke.current;n&&dr({...n,opened:e,clickSource:t})}),Je=Ve?{"data-delegating":`true`}:void 0,Ye=Z.useMemo(()=>{if(x===`bash`||x===`apply_patch`||x===`lsp`||Pe&&(x===`apply_patch`||x===`edit`||x===`multiedit`||x===`write`))return null;let e=F.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=R?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Pe,x,F,R]),Xe=Z.useContext(Ao),Ze=Z.useRef(!1),Qe=J(e=>{let t=e??ie;return!t||!b?!1:(Ze.current=!1,Bh(y,t,b,()=>{if(!di({sessionId:t,directory:b})){if(i||Xe?.runtime.isVSCode){_(t,b);return}d(b,{mode:`chat`,dedupeKey:`session:${t}`,label:He,readOnly:!0})}}))});Z.useEffect(()=>{!Ze.current||!ie||qe(Qe(ie),`queued-effect`)},[ie]);let $e=n=>{if(S){n.stopPropagation();let e=y.capabilities.navigateNestedSession,t=e?Qe():!1;qe(t,`row`),e&&!t&&(Ze.current=!0);return}if(w&&!b)return;let a,o,s;if(x===`edit`||x===`multiedit`||x===`apply_patch`)a=Hw(x,R,I),o=Fw(x,I,typeof a==`string`?a:void 0),typeof a==`string`&&(s=Iw(x,I,a));else if([`write`,`create`,`file_write`].includes(x))a=R?.filePath||R?.file_path||R?.path||I?.filePath||I?.file_path||I?.path,o=1,typeof a==`string`&&typeof R?.content==`string`&&(s=Pw(a,R.content));else if(x===`lsp`){a=R?.filePath||R?.file_path||R?.path;let e=R?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=bo(b,a)||(a.startsWith(`/`)?a:b.endsWith(`/`)?b+a:`${b}/${a}`);if(w){let e=Rw(r,b),n=s?OC(x,I,s,e,e=>Rw(e,b)):[],a=Dw(x)&&n.length===1&&n[0]?[{path:e,patch:n[0].patch}]:n.map(e=>({path:e.title,patch:e.patch}));if(Xe?.runtime.isVSCode&&Xe.editor&&s){let t=`${e} (changes)`;Xe.editor.openDiff(``,r,t,{line:o,patch:s});return}if(wo(r,b)){v?a.length>0?v.openToolDiff({diffPath:e,patches:a,targetLine:o}):x===`apply_patch`?v.openTurnDiff(t,y.sessionId):v.openChanges({diffPath:e,staged:!1,targetLine:o}):i?m(e,!1,Dw(x)?`working`:`turn`,o):a.length>0?p(b,e,a,o,t,y.sessionId):f(b,e,!1,Dw(x)?`working`:`turn`,o,t,y.sessionId);return}if(Xe?.editor){Xe.editor.openFile(r,o);return}mc(r,b).then(()=>{let e=q.getState(),t=vo(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(x===`lsp`){if(Xe?.editor){Xe.editor.openFile(r,o);return}let e=()=>{let e=q.getState(),t=vo(b,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!wo(r,b)){mc(r,b).then(e);return}e();return}if(Xe?.editor){if(Xe.runtime.isVSCode&&s&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${Rw(r,b)} (changes)`;Xe.editor.openDiff(``,r,e,{line:o,patch:s});return}Xe.editor.openFile(r,o);return}}if(x===`apply_patch`&&v){n.stopPropagation(),v.openTurnDiff(t,y.sessionId);return}if(x===`apply_patch`&&b&&!v&&!i&&!Xe?.runtime.isVSCode){n.stopPropagation(),d(b,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:y.sessionId});return}w||r(e.id)},et=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),$e(e))},tt=!S&&D?dT:fT,nt=!S&&D?pT:mT,rt=S&&u&&(De.length>0||we||Ee||!!ie),it=!S&&!w&&n;return!Ee&&!Se&&!S?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,hm,S&&`hover:!bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)]`,Me?`flex-wrap items-start`:`items-center`),"data-mobile-press-feedback":`soft`,...Je,onClick:$e,onKeyDown:et,role:`button`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5`,Me?`w-full min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`:`items-center flex-shrink-0`),children:[(0,$.jsx)(`div`,{className:Y(`relative flex-shrink-0`,i?`size-4`:`size-3.5`),children:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,style:S&&Be.showAvatar?void 0:tt,children:S&&Be.showAvatar?(0,$.jsx)(la,{name:e.id||ze||`subagent`,size:14,label:He}):we?(0,$.jsx)(qC,{isMobile:i,className:`text-[var(--tools-icon)]`,label:h(`chat.assistantStatus.usingTool`,{tool:He})}):oS(x||e.tool)})}),Me?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(pw,`flex-shrink-0`),style:nt,title:Ie,children:Ie}),xw(I,s,l)]}):(0,$.jsxs)($.Fragment,{children:[Te?(0,$.jsx)(`span`,{className:Y(pw,`shrink-0 whitespace-nowrap animate-text-shimmer`),style:{color:`var(--tools-title)`,"--oc-text-shimmer-base":`var(--tools-title)`},title:He,children:He}):(0,$.jsx)(`span`,{className:Y(pw,`shrink-0 whitespace-nowrap`),style:nt,title:He,children:He}),x===`bash`&&typeof G==`number`?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,mw),children:(0,$.jsx)(kw,{start:G,end:typeof xe==`number`?xe:void 0,active:!!(we&&typeof xe!=`number`)})}):null]})]}),!Me&&(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,mw),style:{color:`var(--tools-description)`},children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[Ye&&(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,mw,Te&&`animate-text-shimmer`),style:{color:`var(--tools-description)`,...Te?{"--oc-text-shimmer-base":`var(--tools-description)`}:{opacity:.8}},title:Ye,children:Ye}),!Ye&&x===`lsp`&&Pe?gT(Pe,s,!1,l):null,!Ye&&x!==`lsp`&&Fe&&(Pe&&Fe===Pe?gT(Pe,s,!1,l):(0,$.jsx)(aS,{variant:s?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,mw),style:{color:`var(--tools-description)`},title:Fe,children:Fe})),Ae&&(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,Ae.added]}),(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,Ae.removed]})]}),je&&(0,$.jsx)(`span`,{className:`flex-shrink-0 inline-flex items-center gap-0 typography-meta`,children:(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,je]})})]})}),!w&&(!S||u)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:S?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),rt?(0,$.jsx)(oT,{entries:De,isExpanded:n,isMobile:i,output:K,sessionId:ie,onShowPopup:o,input:R,animateTailText:s,isActive:we}):null,!S&&!w&&n?(0,$.jsx)(`div`,{ref:P,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:it?(0,$.jsxs)(`div`,{className:C?`relative ml-0.5 pl-1.5`:LC,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),(0,$.jsx)(bT,{part:e,state:c,currentDirectory:b,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},ST=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidUpdate(e){e.resetKey!==this.props.resetKey&&this.state.hasError&&this.setState({hasError:!1,error:void 0})}componentDidCatch(e){}render(){if(!this.state.hasError)return this.props.children;let e=this.state.error?.message;return(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1.5 min-w-0`,fm),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:dT,children:oS(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(pw,`flex-shrink-0`),style:pT,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(mw,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},CT=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=ct(),r=IC(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=Sw(e.part.tool)||`tool`,i=uc(a,n),t[0]=e.part.tool,t[1]=n,t[2]=i,t[3]=a):(i=t[2],a=t[3]);let o=i,s;t[4]!==r||t[5]!==e.part.id?(s=()=>!r||bw.get(e.part.id)===!0,t[4]=r,t[5]=e.part.id,t[6]=s):s=t[6];let[c,l]=Z.useState(s),u,d;if(t[7]!==r||t[8]!==c||t[9]!==e.part.id?(u=()=>{if(!(!r||c))return vc(()=>{bw.set(e.part.id,!0,e.part.id.length*2+8),Z.startTransition(()=>{l(!0)})})},d=[r,c,e.part.id],t[7]=r,t[8]=c,t[9]=e.part.id,t[10]=u,t[11]=d):(u=t[10],d=t[11]),Z.useEffect(u,d),!c){let e,n,r;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(`flex min-w-0 items-center gap-2`,fm),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(pw,`shrink-0 text-muted-foreground`),t[12]=e,t[13]=n,t[14]=r):(e=t[12],n=t[13],r=t[14]);let i;t[15]===o?i=t[16]:(i=(0,$.jsx)(`span`,{className:r,children:o}),t[15]=o,t[16]=i);let a;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`span`,{className:`h-3 w-24 min-w-0 rounded bg-muted/40`,"aria-hidden":`true`}),t[17]=a):a=t[17];let s;return t[18]===i?s=t[19]:(s=(0,$.jsxs)(`div`,{className:e,children:[n,i,a]}),t[18]=i,t[19]=s),s}let f;t[20]===n?f=t[21]:(f=n(`chat.toolPart.error`),t[20]=n,t[21]=f);let p;t[22]===e?p=t[23]:(p=(0,$.jsx)(xT,{...e}),t[22]=e,t[23]=p);let m;return t[24]!==o||t[25]!==e.part||t[26]!==f||t[27]!==p||t[28]!==a?(m=(0,$.jsx)(ST,{displayName:o,errorLabel:f,resetKey:e.part,toolName:a,children:p}),t[24]=o,t[25]=e.part,t[26]=f,t[27]=p,t[28]=a,t[29]=m):m=t[29],m},(e,t)=>qS([e.part],[t.part])&&e.messageId===t.messageId&&e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.alwaysShowActions===t.alwaysShowActions&&e.onContentChange===t.onContentChange&&e.onShowPopup===t.onShowPopup&&e.animateTailText===t.animateTailText);function wT(e){return e.stopPropagation()}function TT(e){return e.stopPropagation()}function ET(e){return e.stopPropagation()}function DT(e){return e.setCurrentSession}function OT(e){return e.openContextPanelTab}function kT(e){return e.showToolFileIcons}function AT(e){return e.stopPropagation()}function jT(e){return e.stopPropagation()}function MT(e){return!e}var NT=(e,t,n)=>{let r=t-e;return Math.max(0,n-r)},PT=e=>{e.timer&&=(clearTimeout(e.timer),null)},FT=({text:e,isStreaming:t,throttleMs:n=xc(Le()).textThrottleMs,identityKey:r})=>{let[i,a]=Z.useState(e),o=Z.useRef(e),s=Z.useRef(i),c=Z.useRef({timer:null,pendingText:e,lastEmitAt:0});return Z.useEffect(()=>{o.current=e},[e]),Z.useEffect(()=>{s.current=i},[i]),Z.useEffect(()=>{let e=c.current;PT(e),e.pendingText=o.current,e.lastEmitAt=0,a(o.current)},[r]),Z.useEffect(()=>{let r=c.current;r.pendingText=e;let i=s.current,o=t&&i.length>e.length?i:e;if(!t){PT(r),r.lastEmitAt=Date.now(),a(o);return}let l=Date.now(),u=NT(r.lastEmitAt,l,n);if(u<=0){PT(r),r.lastEmitAt=l,a(o);return}return PT(r),r.timer=setTimeout(()=>{r.timer=null,r.lastEmitAt=Date.now(),a(e=>t&&e.length>r.pendingText.length?e:r.pendingText)},u),()=>{PT(r)}},[t,e,n]),Z.useEffect(()=>{let e=c.current;return()=>{PT(e)}},[]),i},IT=e=>e.isStreaming?e.throttledTextContent:e.textContent,LT=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,RT=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=ct(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(zT)],t[2]=n.highlights,t[3]=n.subject,t[4]=e):e=t[4],l=e.join(`
|
|
6560
6560
|
`);break bb0}let e;t[5]!==n.body||t[6]!==n.title?(e=[n.title,n.body].filter(Boolean),t[5]=n.body,t[6]=n.title,t[7]=e):e=t[7],l=e.join(`
|
|
6561
6561
|
|
|
6562
|
-
`)}let u=l,d;t[8]!==u||t[9]!==n.raw?(d=async()=>{(await ut(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=J(d),p;t[11]!==n.kind||t[12]!==r?(p=n.kind===`commit`?r(`chat.generatedResult.commit.title`):r(`chat.generatedResult.pullRequest.title`),t[11]=n.kind,t[12]=r,t[13]=p):p=t[13];let m;t[14]===p?m=t[15]:(m=(0,$.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:p}),t[14]=p,t[15]=m);let h;t[16]===f?h=t[17]:(h=()=>{f()},t[16]=f,t[17]=h);let g;t[18]!==i||t[19]!==r?(g=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[18]=i,t[19]=r,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==r?(_=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[21]=i,t[22]=r,t[23]=_):_=t[23];let v;t[24]===i?v=t[25]:(v=i?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`}),t[24]=i,t[25]=v);let y;t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==_?(y=(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`xs`,onClick:h,title:g,"aria-label":_,className:`text-muted-foreground hover:text-foreground md:opacity-0 md:group-hover:opacity-100`,children:v}),t[26]=v,t[27]=h,t[28]=g,t[29]=_,t[30]=y):y=t[30];let b;t[31]!==y||t[32]!==m?(b=(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 px-3 py-1.5`,children:[m,y]}),t[31]=y,t[32]=m,t[33]=b):b=t[33];let x;t[34]!==n.body||t[35]!==n.highlights||t[36]!==n.kind||t[37]!==n.subject||t[38]!==n.title||t[39]!==r?(x=(0,$.jsx)(`div`,{className:`space-y-3 px-3 py-3`,children:n.kind===`commit`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n.subject}),n.highlights.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-sm text-muted-foreground`,children:n.highlights.map(
|
|
6562
|
+
`)}let u=l,d;t[8]!==u||t[9]!==n.raw?(d=async()=>{(await ut(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=J(d),p;t[11]!==n.kind||t[12]!==r?(p=n.kind===`commit`?r(`chat.generatedResult.commit.title`):r(`chat.generatedResult.pullRequest.title`),t[11]=n.kind,t[12]=r,t[13]=p):p=t[13];let m;t[14]===p?m=t[15]:(m=(0,$.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:p}),t[14]=p,t[15]=m);let h;t[16]===f?h=t[17]:(h=()=>{f()},t[16]=f,t[17]=h);let g;t[18]!==i||t[19]!==r?(g=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[18]=i,t[19]=r,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==r?(_=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[21]=i,t[22]=r,t[23]=_):_=t[23];let v;t[24]===i?v=t[25]:(v=i?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`}),t[24]=i,t[25]=v);let y;t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==_?(y=(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`xs`,onClick:h,title:g,"aria-label":_,className:`text-muted-foreground hover:text-foreground md:opacity-0 md:group-hover:opacity-100`,children:v}),t[26]=v,t[27]=h,t[28]=g,t[29]=_,t[30]=y):y=t[30];let b;t[31]!==y||t[32]!==m?(b=(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 px-3 py-1.5`,children:[m,y]}),t[31]=y,t[32]=m,t[33]=b):b=t[33];let x;t[34]!==n.body||t[35]!==n.highlights||t[36]!==n.kind||t[37]!==n.subject||t[38]!==n.title||t[39]!==r?(x=(0,$.jsx)(`div`,{className:`space-y-3 px-3 py-3`,children:n.kind===`commit`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n.subject}),n.highlights.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-sm text-muted-foreground`,children:n.highlights.map(BT)}):null]}):(0,$.jsxs)($.Fragment,{children:[n.title?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.titleLabel`)}),(0,$.jsx)(`div`,{className:`mt-1 typography-ui-label text-foreground`,children:n.title})]}):null,n.body?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro uppercase tracking-[0.12em] text-muted-foreground`,children:r(`chat.generatedResult.pullRequest.bodyLabel`)}),(0,$.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words text-sm leading-relaxed text-muted-foreground font-sans`,children:n.body})]}):null]})}),t[34]=n.body,t[35]=n.highlights,t[36]=n.kind,t[37]=n.subject,t[38]=n.title,t[39]=r,t[40]=x):x=t[40];let S;return t[41]!==b||t[42]!==x?(S=(0,$.jsxs)(`div`,{"data-component":`generated-json-result`,className:`my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]`,children:[b,x]}),t[41]=b,t[42]=x,t[43]=S):S=t[43],S};function zT(e){return`- ${e}`}function BT(e,t){return(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`-`}),(0,$.jsx)(`span`,{children:e})]},`${t}-${e}`)}var VT=e=>{let t=e.trim(),n=[],r=t.match(/^```(?:json)?\s*([\s\S]*?)```$/i);r?.[1]&&n.push(r[1].trim()),t.startsWith(`{`)&&t.endsWith(`}`)&&n.push(t);let i=[];for(let e of n)try{let t=JSON.parse(e);t&&typeof t==`object`&&!Array.isArray(t)&&i.push(t)}catch{}return i},HT=e=>{for(let t of VT(e)){let e=typeof t.subject==`string`?t.subject.trim():``,n=Array.isArray(t.highlights)?t.highlights.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean).slice(0,3):[];if(e)return{kind:`commit`,subject:e,highlights:n,raw:JSON.stringify({subject:e,highlights:n},null,2)};let r=typeof t.title==`string`?t.title.trim():``,i=typeof t.body==`string`?t.body.trim():``;if(r||i)return{kind:`pr`,title:r,body:i,raw:JSON.stringify({title:r,body:i},null,2)}}return null},UT=Z.memo(e=>{let t=(0,Q.c)(32),{part:n,sessionId:r,messageId:i,streamPhase:a,chatRenderMode:o,allowSortedFinalStreaming:s,hasStreamingHapticLifecycle:c,onShowPopup:l}=e,u=o===void 0?`live`:o,d=s!==void 0&&s,f=c!==void 0&&c,p=n,m=[typeof p.text==`string`?p.text:``,typeof p.content==`string`?p.content:``,typeof p.value==`string`?p.value:``].reduce(WT,``),h=(u===`live`||d)&&(a===`streaming`||a===`cooldown`);Fe(`ui.assistant_text_part.render`),h&&Fe(`ui.assistant_text_part.render.streaming`);let g=IT({textContent:m,throttledTextContent:FT({text:m,isStreaming:h,identityKey:`${i}:${n.id??`text`}`}),isStreaming:h}),_=`${i}:${n.id??`text`}`,v=Z.useRef(null),y,b;t[0]!==g||t[1]!==_||t[2]!==f||t[3]!==i||t[4]!==n.id||t[5]!==n.type||t[6]!==r?(y=()=>{if(!Et())return;let e=n.type===`text`||n.type===`reasoning`,t=In(v.current,{identity:_,content:g,isActive:f&&e,mode:n.type===`reasoning`?`appearance`:`changes`});v.current=t.nextState,!(!t.shouldEmit||!r)&&Ki({sessionID:r,messageID:i,partID:n.id,kind:n.type===`reasoning`?`thinking`:`text`})},b=[g,_,f,i,n.id,n.type,r],t[0]=g,t[1]=_,t[2]=f,t[3]=i,t[4]=n.id,t[5]=n.type,t[6]=r,t[7]=y,t[8]=b):(y=t[7],b=t[8]),Z.useEffect(y,b),Pe(`ui.assistant_text_part.display_len`,g.length);let x=p.time,S=!!(x&&x.end!==void 0);if(n.type!==`text`&&n.type!==`reasoning`||!LT({displayTextContent:g,isFinalized:S}))return null;let C;t[9]!==g||t[10]!==S||t[11]!==h?(C=!h&&S?HT(g):null,t[9]=g,t[10]=S,t[11]=h,t[12]=C):C=t[12];let w=C;if(w){let e=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,r=n.id||`${i}-text`,a;t[13]===w?a=t[14]:(a=(0,$.jsx)(RT,{result:w}),t[13]=w,t[14]=a);let o;return t[15]!==e||t[16]!==r||t[17]!==a?(o=(0,$.jsx)(`div`,{className:e,children:a},r),t[15]=e,t[16]=r,t[17]=a,t[18]=o):o=t[18],o}let T=`group/assistant-text relative break-words ${u===`live`?`my-1`:``}`,E=n.id||`${i}-text`,D=u===`sorted`&&!d,O=n.type===`reasoning`?`reasoning`:`assistant`,k;t[19]!==g||t[20]!==S||t[21]!==h||t[22]!==i||t[23]!==l||t[24]!==n||t[25]!==O||t[26]!==D?(k=(0,$.jsx)(zs,{content:g,part:n,messageId:i,isAnimated:!1,isStreaming:h,disableStreamAnimation:D,variant:O,enableFileReferences:S,onShowPopup:l}),t[19]=g,t[20]=S,t[21]=h,t[22]=i,t[23]=l,t[24]=n,t[25]=O,t[26]=D,t[27]=k):k=t[27];let A;return t[28]!==k||t[29]!==T||t[30]!==E?(A=(0,$.jsx)(`div`,{className:T,children:k},E),t[28]=k,t[29]=T,t[30]=E,t[31]=A):A=t[31],A});function WT(e,t){return t.length>e.length?t:e}var GT=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,KT=Y(`typography-meta font-medium`,GT),qT=Y(`typography-meta`,GT),JT=e=>typeof e!=`string`||e.trim().length===0?``:e.split(`
|
|
6563
6563
|
`).map(e=>e.replace(/^>\s?/,``).trimEnd()).filter(e=>e.trim().length>0).join(`
|
|
6564
|
-
`).trim(),JT=80,YT=200,XT={duration:.2,ease:`easeOut`},ZT=e=>e.replace(/<!--\s*-->/g,``).replace(/```[\w]*\n?([\s\S]*?)```/g,(e,t)=>t.trim()).replace(/`([^`]+)`/g,`$1`).replace(/\*{1,3}([^*]+)\*{1,3}/g,`$1`).replace(/_{1,3}([^_]+)_{1,3}/g,`$1`).replace(/^#{1,6}\s+/gm,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^>\s?/gm,``).replace(/^[-*_]{3,}\s*$/gm,``).trim(),QT=e=>{if(!e)return``;let t=ZT(e).replace(/\s+/g,` `).trim();if(t.length<=JT)return t;let n=t.lastIndexOf(` `,JT),r=n>0?n:JT;return`${t.substring(0,r).trimEnd()}…`},$T=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:s})=>{let{t:c}=ct(),l=q(e=>e.isMobile),u=typeof i?.end==`number`,d=a&&!u,[f,p]=Z.useState(()=>s===!0?{expanded:!0,source:`user`}:{expanded:d,source:`auto`}),m=f.source===`auto`?d&&f.expanded:f.expanded,[h,g]=Z.useState(s===!0||d),_=Z.useId(),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=Z.useRef(n);x.current=n;let S=Z.useMemo(()=>QT(e),[e]),C=c(m?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),w=J(()=>{g(!0),p({expanded:!m,source:`user`}),n?.(`structural`)}),T=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),w())});if(Z.useLayoutEffect(()=>{p(e=>e.source===`user`||e.expanded===d?e:{expanded:d,source:`auto`})},[d]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(m||a){g(!0);return}if(!h)return;if(typeof window>`u`){g(!1);return}let e=window.setTimeout(()=>{g(!1)},YT);return()=>{window.clearTimeout(e)}},[m,a,h]),Z.useLayoutEffect(()=>{let e=v.current;if(!e)return;if(y.current?.stop(),!b.current){if(b.current=!0,!m){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=tl(e,{height:`auto`},XT);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}}e.style.overflow=`hidden`,m?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,x.current?.(`animation`));let t=tl(e,{height:m?`auto`:`0px`},XT);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,m?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}},[m]),Z.useEffect(()=>()=>{y.current?.stop(),y.current=null},[]),!e||e.trim().length===0)return null;let E=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(zs,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":m,"aria-controls":_,"aria-label":C,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,mm),onClick:w,onKeyDown:T,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,m&&`opacity-0`,!m&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,m&&`opacity-100`,!m&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:m?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,GT),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--oc-text-shimmer-base":`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(KC,{isMobile:l,className:`block text-[var(--tools-icon)]`})]}):m?(0,$.jsx)(`span`,{className:GT,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:GT,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,KT),style:{color:`var(--tools-description)`},children:!a&&!m&&S?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,KT),style:{color:`var(--tools-description)`,opacity:.8},title:S,children:S}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),h?(0,$.jsx)(`div`,{ref:v,id:_,"aria-hidden":!m,style:{height:m?`auto`:`0px`,overflow:m?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!m,transform:m?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:E}):(0,$.jsx)(pa,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:E})]})}):null]})},eE=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=q(tE),s=n,c=s.text||s.content||``,l;t[0]===c?l=t[1]:(l=qT(c),t[0]=c,t[1]=l);let u=l,d=s.time,f=a===void 0||a!==`completed`,p=o===`live`&&f&&typeof d?.end!=`number`,m=`${i}:${n.id??`reasoning`}`,h;t[2]!==p||t[3]!==m||t[4]!==u?(h={text:u,isStreaming:p,identityKey:m},t[2]=p,t[3]=m,t[4]=u,t[5]=h):h=t[5];let g=PT(h),_=`${i}:${n.id??`reasoning`}`,v=Z.useRef(null),y=n.sessionID,b=f&&typeof d?.end!=`number`,x,S;if(t[6]!==_||t[7]!==b||t[8]!==i||t[9]!==n.id||t[10]!==y||t[11]!==g?(x=()=>{if(!Et())return;let e=In(v.current,{identity:_,content:g,isActive:b,mode:`appearance`});v.current=e.nextState,!(!e.shouldEmit||!y)&&Ki({sessionID:y,messageID:i,partID:n.id,kind:`thinking`})},S=[_,b,i,n.id,y,g],t[6]=_,t[7]=b,t[8]=i,t[9]=n.id,t[10]=y,t[11]=g,t[12]=x,t[13]=S):(x=t[12],S=t[13]),Z.useEffect(x,S),!g||g.trim().length===0)return null;let C=n.id||`${i}-reasoning`,w;return t[14]!==p||t[15]!==r||t[16]!==C||t[17]!==g||t[18]!==d?(w=(0,$.jsx)($T,{text:g,variant:`thinking`,onContentChange:r,blockId:C,time:d,isStreaming:p}),t[14]=p,t[15]=r,t[16]=C,t[17]=g,t[18]=d,t[19]=w):w=t[19],w});function tE(e){return e.chatRenderMode}var nE=(e,t)=>{let n=bo(e,t)||xo(t);return n?wo(n,e)?{kind:`diff`,path:yo(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},rE=e=>{let t=q.getState(),n=nE(e.directory,e.filePath);if(n.kind===`file`){mc(n.path,e.directory).then(()=>{t.openContextFile(e.directory,n.path,{fileNotice:n.notice}),e.mobile&&t.setRightSidebarOpen(!1)});return}if(e.mobile){t.navigateToDiff(n.path,!1,`turn`),t.setRightSidebarOpen(!1);return}t.openContextDiff(e.directory,n.path,!1,`turn`,void 0,e.turnMessageId,e.sessionId)},iE=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),s=Z.useRef(null),c=Lh(),l=Se(aE),u=c.directory||l,d=fs(u),f;if(t[0]!==n||t[1]!==d){bb0:{if(d!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],f=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],f=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&rg.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],f=e;break bb0}f=sg(e)}t[0]=n,t[1]=d,t[2]=f}else f=t[2];let p=f;if(p.length===0)return null;let m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=m):m=t[6];let h=m,g;t[7]!==u||t[8]!==c?(g=e=>{if(!u)return;let t=q.getState();rE({directory:u,filePath:e.path,sessionId:c.sessionId,mobile:t.isMobile}),i(!1)},t[7]=u,t[8]=c,t[9]=g):g=t[9];let _=g,v=p.length,y=`${v} file${v===1?``:`s`}`,b=`${y} changed in this turn`,x;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=x):x=t[10];let S;t[11]===y?S=t[12]:(S=(0,$.jsx)(`span`,{className:`message-footer__label`,children:y}),t[11]=y,t[12]=S);let C;t[13]===r?C=t[14]:(C=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=C);let w;t[15]!==b||t[16]!==S||t[17]!==C?(w=(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(pe,{render:(0,$.jsxs)(`button`,{ref:s,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":b,onPointerDownCapture:h,onFocusCapture:h,children:[x,S,C]})})}),t[15]=b,t[16]=S,t[17]=C,t[18]=w):w=t[18];let T;t[19]===y?T=t[20]:(T=(0,$.jsxs)(Ua,{children:[y,` changed in this turn`]}),t[19]=y,t[20]=T);let E;t[21]!==w||t[22]!==T?(E=(0,$.jsxs)(Wa,{children:[w,T]}),t[21]=w,t[22]=T,t[23]=E):E=t[23];let D=a||void 0,O;t[24]!==p||t[25]!==u||t[26]!==_?(O=(0,$.jsx)(he,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(fe,{style:yg,className:`${vg} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(_g,{files:p,currentDirectory:u,onOpenFile:_})})}),t[24]=p,t[25]=u,t[26]=_,t[27]=O):O=t[27];let k;t[28]!==D||t[29]!==O?(k=(0,$.jsx)(ye,{container:D,children:O}),t[28]=D,t[29]=O,t[30]=k):k=t[30];let A;return t[31]!==r||t[32]!==E||t[33]!==k?(A=(0,$.jsxs)(me,{open:r,onOpenChange:i,children:[E,k]}),t[31]=r,t[32]=E,t[33]=k,t[34]=A):A=t[34],A});iE.displayName=`TurnChangedFilesDropdown`;function aE(e){return e.currentDirectory}var oE=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,sE=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},cE=e=>e.type!==`tool`||oE(e)?!1:!sE(e),lE=e=>{let t=0;for(let n of e)cE(n)&&(t+=1);return t},uE=(e,t)=>e===`stop`&&lE(t)===0,dE=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},fE=(e,t,n)=>{if(n||!uE(e,t))return!1;for(let e of t)if(dE(e))return!0;return!1},pE=e=>e===`streaming`||e===`cooldown`,mE=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,hE=e=>e.error||e.isLastAssistantInTurn===!1?!1:uE(e.finish,e.parts)?!0:!pE(e.streamPhase)||typeof e.finish==`string`&&e.finish!==`stop`?!1:lE(e.parts)===0,gE=e=>pE(e.streamPhase)?hE(e):!1,_E=3e4,vE=new Map,yE=new Map;async function bE(e){let t=Date.now(),n=vE.get(e);if(n&&t-n.checkedAt<_E)return n.available;let r=yE.get(e);if(r)return r;let i=(async()=>{try{let t=await m(`/api/tts/status`);if(!t.ok)return vE.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return vE.set(e,{available:n,checkedAt:Date.now()}),n}catch{return vE.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{yE.delete(e)}})();return yE.set(e,i),i}var xE=null;function SE(){return xE||=new(window.AudioContext||window.webkitAudioContext),xE}function CE(e={}){let n=e.enabled??!0,i=e.availabilityMode??`auto`,[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),h=Ai(e=>e.currentProviderId),g=Ai(e=>e.currentModelId),_=Ai(e=>e.openaiApiKey),v=Ai(e=>e.openaiCompatibleUrl),y=Ai(e=>e.openaiCompatibleApiKey),b=(0,Z.useCallback)(async()=>{let e=++p.current,t=r(),a=n=>(e===p.current&&r()===t&&c(n),n);if(!n)return a(!1);let o=!!(_&&_.trim().length>0),s=!!(v&&v.trim().length>0);if(i===`openai-compatible`)return a(s);if(o||i===`auto`&&s)return a(!0);try{return a(await bE(t))}catch{return a(!1)}},[i,n,_,v]);(0,Z.useEffect)(()=>{b()},[b]),(0,Z.useEffect)(()=>t(()=>{b()}),[b]);let x=(0,Z.useCallback)(()=>{let e=f.current;if(f.current=null,e?.abort.abort(),d.current){try{d.current.onended=null,d.current.stop()}catch{}d.current=null}o(!1)},[]),S=(0,Z.useCallback)(async()=>{try{let e=SE();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useServerTTS] Failed to unlock audio:`,e)}},[]),C=(0,Z.useCallback)(async(e,t)=>{if(x(),!e.trim()){u(`No text to speak`),t?.onError?.(`No text to speak`);return}u(null);let n={abort:new AbortController};f.current=n;try{let r=SE();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),a=r.createBufferSource();a.buffer=i,a.connect(r.destination),a.start(0);let s=t?.voice||`nova`,c=await m(`/api/tts/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:s,model:t?.model||void 0,speed:t?.speed||.9,instructions:t?.instructions,summarize:!1,providerId:t?.providerId||h||void 0,modelId:t?.modelId||g||void 0,apiKey:t?.baseURL?y||void 0:_||void 0,baseURL:t?.baseURL||void 0}),signal:n.abort.signal});if(f.current!==n)return;if(!c.ok){let e=await c.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${c.status}`)}let l=await(await c.blob()).arrayBuffer();if(f.current!==n)return;let u=await r.decodeAudioData(l);if(f.current!==n)return;let p=r.createBufferSource();p.buffer=u;let v=t?.pitch??1;v!==1&&(p.detune.value=(v-1)*1200);let b=t?.volume??1,x=r.createGain();if(x.gain.value=b,p.connect(x),x.connect(r.destination),d.current=p,p.onended=()=>{f.current===n&&d.current===p&&(o(!1),d.current=null,f.current=null,t?.onEnd?.())},o(!0),t?.onStart?.(),f.current!==n||d.current!==p)return;p.start(0)}catch(e){if(e.name===`AbortError`||f.current!==n)return;let r=e instanceof Error?e.message:`Failed to speak`;console.error(`[useServerTTS] Error:`,r),u(r),t?.onError?.(r),o(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[x,h,g,_,y]);return(0,Z.useEffect)(()=>()=>{x()},[x]),{isPlaying:a,isAvailable:s,error:l,speak:C,stop:x,checkAvailability:b,unlockAudio:S}}var wE=3e4,TE=null,EE=null;async function DE(){return TE&&Date.now()-TE.checkedAt<wE?TE:EE||(EE=(async()=>{try{let e=await m(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return TE=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return TE=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return TE=e,e}finally{EE=null}})(),EE)}var OE=null;function kE(){return OE||=new(window.AudioContext||window.webkitAudioContext),OE}function AE(e={}){let t=e.enabled??!0,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useCallback)(async()=>{try{let e=kE();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useSayTTS] Failed to unlock audio:`,e)}},[]),p=(0,Z.useCallback)(async()=>{if(!t)return a(!1),s([]),!1;try{let e=await DE();return a(e.available),s(e.voices),e.available}catch{return a(!1),s([]),!1}},[t]);(0,Z.useEffect)(()=>{p()},[p]);let h=(0,Z.useCallback)(()=>{if(u.current){try{u.current.stop()}catch{}u.current=null}d.current&&=(d.current.abort(),null),r(!1)},[]),g=(0,Z.useCallback)(async(e,t)=>{if(h(),!e.trim()){l(`No text to speak`),t?.onError?.(`No text to speak`);return}l(null);try{d.current=new AbortController;let n=await m(`/api/tts/say/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:t?.voice||`Samantha`,rate:t?.rate||200}),signal:d.current.signal});if(!n.ok){let e=await n.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${n.status}`)}let i=await n.blob(),a=await i.arrayBuffer();i.size;let o=kE();o.state===`suspended`&&await o.resume();let s=await o.decodeAudioData(a),c=o.createBufferSource();c.buffer=s,c.connect(o.destination),u.current=c,c.onended=()=>{r(!1),u.current=null,t?.onEnd?.()},r(!0),t?.onStart?.(),c.start(0)}catch(e){if(e.name===`AbortError`)return;let n=e instanceof Error?e.message:`Failed to speak`;console.error(`[useSayTTS] Error:`,n),l(n),t?.onError?.(n),r(!1)}},[h]);return(0,Z.useEffect)(()=>()=>{h()},[h]),{isPlaying:n,isAvailable:i,voices:o,error:c,speak:g,stop:h,checkAvailability:p,unlockAudio:f}}function jE(e){return e?e.replace(/```[\s\S]*?```/g,``).replace(/`([^`\n]*)`/g,`$1`).replace(/[*_~#]/g,``).replace(/https?:\/\/[^\s]+/g,``).replace(/(^|\s)\/(?:[\w.-]+\/)*[\w.-]+/g,`$1`).replace(/([\w.])\/([\w.])/g,`$1 slash $2`).replace(/^\s*[$#>]\s*/gm,``).replace(/[[\]{}()<>|&;]/g,` `).replace(/\\/g,``).replace(/\s+/g,` `).trim():``}var ME=600,NE=`Summarize the assistant reply for text-to-speech listening. Reply with 2-4 sentences of plain spoken prose in the same language as the reply. No markdown, no lists, no code — mention code changes briefly in words instead.`;async function PE(e,t){try{let n=await m(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:NE,...t.providerID?{preferredProviderID:t.providerID}:{},...t.modelID?{preferredModelID:t.modelID}:{}})});if(!n.ok)return null;let r=await n.json().catch(()=>null);return typeof r?.text==`string`&&r.text.trim()?r.text.trim():null}catch{return null}}function FE(){let[e,t]=(0,Z.useState)(!1),n=Ai(e=>e.voiceProvider),r=Ai(e=>e.speechRate),i=Ai(e=>e.speechPitch),a=Ai(e=>e.speechVolume),o=Ai(e=>e.sayVoice),s=Ai(e=>e.localTtsVoiceId),c=Ai(e=>e.browserVoice),l=Ai(e=>e.openaiVoice),u=Ai(e=>e.openaiCompatibleVoice),d=Ai(e=>e.openaiCompatibleUrl),f=Ai(e=>e.openaiCompatibleTtsModel),p=Ai(e=>e.showMessageTTSButtons),m=Ai(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=CE({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=AE({enabled:_}),{speak:w,stop:T}=eo(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),io.cancelSpeech()},[y,S,T]);return{isPlaying:e,play:(0,Z.useCallback)(async e=>{if(e.trim()){E(),t(!0);try{let p=e;if(m===`summarized`&&e.length>=ME){let{currentProviderId:t,currentModelId:n}=Ai.getState(),r=await PE(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=jE(p),y=g?p:_;if(h&&b)await v(y,{voice:n===`openai-compatible`?u:l,model:n===`openai-compatible`?f:void 0,speed:r,pitch:i,volume:a,summarize:!1,baseURL:n===`openai-compatible`?d:void 0,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`local`)await w(_,{speakerId:s,speed:r,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`say`&&C){let e=Math.round(100+(r-.5)*200);await x(_,{voice:o,rate:e,onEnd:()=>t(!1),onError:()=>t(!1)})}else await io.waitForVoices(),await io.resumeAudioContext(),await io.speakText(_,navigator.language||`en-US`,()=>t(!1),{rate:r,pitch:i,volume:a,voiceName:c||void 0})}catch(e){console.error(`[useMessageTTS] Playback error:`,e),t(!1)}}},[n,h,r,i,a,o,c,l,u,d,f,b,C,m,v,x,w,s,E]),stop:E}}var IE=8,LE=280,RE=null;Or(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),RE&&(0,rl.flushSync)(RE)});var zE=new Set(`address.article.aside.blockquote.dd.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.table.ul`.split(`.`)),BE=e=>e.replace(/\r\n?/g,`
|
|
6565
|
-
`),
|
|
6566
|
-
`;if(n===`strong`||n===`b`)return`**${r}**`;if(n===`em`||n===`i`)return`*${r}*`;if(n===`code`)return`\`${r.replace(/`/g,"\\`")}\``;if(n===`a`){let e=t.getAttribute(`href`);return e?`[${r}](${e})`:r}return r},
|
|
6567
|
-
`),
|
|
6564
|
+
`).trim(),YT=80,XT=200,ZT={duration:.2,ease:`easeOut`},QT=e=>e.replace(/<!--\s*-->/g,``).replace(/```[\w]*\n?([\s\S]*?)```/g,(e,t)=>t.trim()).replace(/`([^`]+)`/g,`$1`).replace(/\*{1,3}([^*]+)\*{1,3}/g,`$1`).replace(/_{1,3}([^_]+)_{1,3}/g,`$1`).replace(/^#{1,6}\s+/gm,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^>\s?/gm,``).replace(/^[-*_]{3,}\s*$/gm,``).trim(),$T=e=>{if(!e)return``;let t=QT(e).replace(/\s+/g,` `).trim();if(t.length<=YT)return t;let n=t.lastIndexOf(` `,YT),r=n>0?n:YT;return`${t.substring(0,r).trimEnd()}…`},eE=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:s})=>{let{t:c}=ct(),l=q(e=>e.isMobile),u=typeof i?.end==`number`,d=a&&!u,[f,p]=Z.useState(()=>s===!0?{expanded:!0,source:`user`}:{expanded:d,source:`auto`}),m=f.source===`auto`?d&&f.expanded:f.expanded,[h,g]=Z.useState(s===!0||d),_=Z.useId(),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=Z.useRef(n);x.current=n;let S=Z.useMemo(()=>$T(e),[e]),C=c(m?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),w=J(()=>{g(!0),p({expanded:!m,source:`user`}),n?.(`structural`)}),T=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),w())});if(Z.useLayoutEffect(()=>{p(e=>e.source===`user`||e.expanded===d?e:{expanded:d,source:`auto`})},[d]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(m||a){g(!0);return}if(!h)return;if(typeof window>`u`){g(!1);return}let e=window.setTimeout(()=>{g(!1)},XT);return()=>{window.clearTimeout(e)}},[m,a,h]),Z.useLayoutEffect(()=>{let e=v.current;if(!e)return;if(y.current?.stop(),!b.current){if(b.current=!0,!m){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=tl(e,{height:`auto`},ZT);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}}e.style.overflow=`hidden`,m?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,x.current?.(`animation`));let t=tl(e,{height:m?`auto`:`0px`},ZT);return y.current=t,t.finished.then(()=>{y.current===t&&(y.current=null,m?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),y.current===t&&(y.current=null)}},[m]),Z.useEffect(()=>()=>{y.current?.stop(),y.current=null},[]),!e||e.trim().length===0)return null;let E=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(zs,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":m,"aria-controls":_,"aria-label":C,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,hm),onClick:w,onKeyDown:T,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,m&&`opacity-0`,!m&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,m&&`opacity-100`,!m&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:m?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,KT),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--oc-text-shimmer-base":`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(qC,{isMobile:l,className:`block text-[var(--tools-icon)]`})]}):m?(0,$.jsx)(`span`,{className:KT,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:KT,style:{color:`var(--tools-title)`},children:c(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,qT),style:{color:`var(--tools-description)`},children:!a&&!m&&S?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,qT),style:{color:`var(--tools-description)`,opacity:.8},title:S,children:S}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),h?(0,$.jsx)(`div`,{ref:v,id:_,"aria-hidden":!m,style:{height:m?`auto`:`0px`,overflow:m?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!m,transform:m?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:E}):(0,$.jsx)(pa,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:E})]})}):null]})},tE=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=q(nE),s=n,c=s.text||s.content||``,l;t[0]===c?l=t[1]:(l=JT(c),t[0]=c,t[1]=l);let u=l,d=s.time,f=a===void 0||a!==`completed`,p=o===`live`&&f&&typeof d?.end!=`number`,m=`${i}:${n.id??`reasoning`}`,h;t[2]!==p||t[3]!==m||t[4]!==u?(h={text:u,isStreaming:p,identityKey:m},t[2]=p,t[3]=m,t[4]=u,t[5]=h):h=t[5];let g=FT(h),_=`${i}:${n.id??`reasoning`}`,v=Z.useRef(null),y=n.sessionID,b=f&&typeof d?.end!=`number`,x,S;if(t[6]!==_||t[7]!==b||t[8]!==i||t[9]!==n.id||t[10]!==y||t[11]!==g?(x=()=>{if(!Et())return;let e=In(v.current,{identity:_,content:g,isActive:b,mode:`appearance`});v.current=e.nextState,!(!e.shouldEmit||!y)&&Ki({sessionID:y,messageID:i,partID:n.id,kind:`thinking`})},S=[_,b,i,n.id,y,g],t[6]=_,t[7]=b,t[8]=i,t[9]=n.id,t[10]=y,t[11]=g,t[12]=x,t[13]=S):(x=t[12],S=t[13]),Z.useEffect(x,S),!g||g.trim().length===0)return null;let C=n.id||`${i}-reasoning`,w;return t[14]!==p||t[15]!==r||t[16]!==C||t[17]!==g||t[18]!==d?(w=(0,$.jsx)(eE,{text:g,variant:`thinking`,onContentChange:r,blockId:C,time:d,isStreaming:p}),t[14]=p,t[15]=r,t[16]=C,t[17]=g,t[18]=d,t[19]=w):w=t[19],w});function nE(e){return e.chatRenderMode}var rE=(e,t)=>{let n=bo(e,t)||xo(t);return n?wo(n,e)?{kind:`diff`,path:yo(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},iE=e=>{let t=q.getState(),n=rE(e.directory,e.filePath);if(n.kind===`file`){mc(n.path,e.directory).then(()=>{t.openContextFile(e.directory,n.path,{fileNotice:n.notice}),e.mobile&&t.setRightSidebarOpen(!1)});return}if(e.mobile){t.navigateToDiff(n.path,!1,`turn`),t.setRightSidebarOpen(!1);return}t.openContextDiff(e.directory,n.path,!1,`turn`,void 0,e.turnMessageId,e.sessionId)},aE=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),s=Z.useRef(null),c=Rh(),l=Se(oE),u=c.directory||l,d=fs(u),f;if(t[0]!==n||t[1]!==d){bb0:{if(d!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],f=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],f=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&ig.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],f=e;break bb0}f=cg(e)}t[0]=n,t[1]=d,t[2]=f}else f=t[2];let p=f;if(p.length===0)return null;let m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=m):m=t[6];let h=m,g;t[7]!==u||t[8]!==c?(g=e=>{if(!u)return;let t=q.getState();iE({directory:u,filePath:e.path,sessionId:c.sessionId,mobile:t.isMobile}),i(!1)},t[7]=u,t[8]=c,t[9]=g):g=t[9];let _=g,v=p.length,y=`${v} file${v===1?``:`s`}`,b=`${y} changed in this turn`,x;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=x):x=t[10];let S;t[11]===y?S=t[12]:(S=(0,$.jsx)(`span`,{className:`message-footer__label`,children:y}),t[11]=y,t[12]=S);let C;t[13]===r?C=t[14]:(C=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=C);let w;t[15]!==b||t[16]!==S||t[17]!==C?(w=(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(pe,{render:(0,$.jsxs)(`button`,{ref:s,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":b,onPointerDownCapture:h,onFocusCapture:h,children:[x,S,C]})})}),t[15]=b,t[16]=S,t[17]=C,t[18]=w):w=t[18];let T;t[19]===y?T=t[20]:(T=(0,$.jsxs)(Ua,{children:[y,` changed in this turn`]}),t[19]=y,t[20]=T);let E;t[21]!==w||t[22]!==T?(E=(0,$.jsxs)(Wa,{children:[w,T]}),t[21]=w,t[22]=T,t[23]=E):E=t[23];let D=a||void 0,O;t[24]!==p||t[25]!==u||t[26]!==_?(O=(0,$.jsx)(he,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(fe,{style:bg,className:`${yg} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(vg,{files:p,currentDirectory:u,onOpenFile:_})})}),t[24]=p,t[25]=u,t[26]=_,t[27]=O):O=t[27];let k;t[28]!==D||t[29]!==O?(k=(0,$.jsx)(ye,{container:D,children:O}),t[28]=D,t[29]=O,t[30]=k):k=t[30];let A;return t[31]!==r||t[32]!==E||t[33]!==k?(A=(0,$.jsxs)(me,{open:r,onOpenChange:i,children:[E,k]}),t[31]=r,t[32]=E,t[33]=k,t[34]=A):A=t[34],A});aE.displayName=`TurnChangedFilesDropdown`;function oE(e){return e.currentDirectory}var sE=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,cE=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},lE=e=>e.type!==`tool`||sE(e)?!1:!cE(e),uE=e=>{let t=0;for(let n of e)lE(n)&&(t+=1);return t},dE=(e,t)=>e===`stop`&&uE(t)===0,fE=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},pE=(e,t,n)=>{if(n||!dE(e,t))return!1;for(let e of t)if(fE(e))return!0;return!1},mE=e=>e===`streaming`||e===`cooldown`,hE=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,gE=e=>e.error||e.isLastAssistantInTurn===!1?!1:dE(e.finish,e.parts)?!0:!mE(e.streamPhase)||typeof e.finish==`string`&&e.finish!==`stop`?!1:uE(e.parts)===0,_E=e=>mE(e.streamPhase)?gE(e):!1,vE=3e4,yE=new Map,bE=new Map;async function xE(e){let t=Date.now(),n=yE.get(e);if(n&&t-n.checkedAt<vE)return n.available;let r=bE.get(e);if(r)return r;let i=(async()=>{try{let t=await m(`/api/tts/status`);if(!t.ok)return yE.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return yE.set(e,{available:n,checkedAt:Date.now()}),n}catch{return yE.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{bE.delete(e)}})();return bE.set(e,i),i}var SE=null;function CE(){return SE||=new(window.AudioContext||window.webkitAudioContext),SE}function wE(e={}){let n=e.enabled??!0,i=e.availabilityMode??`auto`,[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),h=Ai(e=>e.currentProviderId),g=Ai(e=>e.currentModelId),_=Ai(e=>e.openaiApiKey),v=Ai(e=>e.openaiCompatibleUrl),y=Ai(e=>e.openaiCompatibleApiKey),b=(0,Z.useCallback)(async()=>{let e=++p.current,t=r(),a=n=>(e===p.current&&r()===t&&c(n),n);if(!n)return a(!1);let o=!!(_&&_.trim().length>0),s=!!(v&&v.trim().length>0);if(i===`openai-compatible`)return a(s);if(o||i===`auto`&&s)return a(!0);try{return a(await xE(t))}catch{return a(!1)}},[i,n,_,v]);(0,Z.useEffect)(()=>{b()},[b]),(0,Z.useEffect)(()=>t(()=>{b()}),[b]);let x=(0,Z.useCallback)(()=>{let e=f.current;if(f.current=null,e?.abort.abort(),d.current){try{d.current.onended=null,d.current.stop()}catch{}d.current=null}o(!1)},[]),S=(0,Z.useCallback)(async()=>{try{let e=CE();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useServerTTS] Failed to unlock audio:`,e)}},[]),C=(0,Z.useCallback)(async(e,t)=>{if(x(),!e.trim()){u(`No text to speak`),t?.onError?.(`No text to speak`);return}u(null);let n={abort:new AbortController};f.current=n;try{let r=CE();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),a=r.createBufferSource();a.buffer=i,a.connect(r.destination),a.start(0);let s=t?.voice||`nova`,c=await m(`/api/tts/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:s,model:t?.model||void 0,speed:t?.speed||.9,instructions:t?.instructions,summarize:!1,providerId:t?.providerId||h||void 0,modelId:t?.modelId||g||void 0,apiKey:t?.baseURL?y||void 0:_||void 0,baseURL:t?.baseURL||void 0}),signal:n.abort.signal});if(f.current!==n)return;if(!c.ok){let e=await c.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${c.status}`)}let l=await(await c.blob()).arrayBuffer();if(f.current!==n)return;let u=await r.decodeAudioData(l);if(f.current!==n)return;let p=r.createBufferSource();p.buffer=u;let v=t?.pitch??1;v!==1&&(p.detune.value=(v-1)*1200);let b=t?.volume??1,x=r.createGain();if(x.gain.value=b,p.connect(x),x.connect(r.destination),d.current=p,p.onended=()=>{f.current===n&&d.current===p&&(o(!1),d.current=null,f.current=null,t?.onEnd?.())},o(!0),t?.onStart?.(),f.current!==n||d.current!==p)return;p.start(0)}catch(e){if(e.name===`AbortError`||f.current!==n)return;let r=e instanceof Error?e.message:`Failed to speak`;console.error(`[useServerTTS] Error:`,r),u(r),t?.onError?.(r),o(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[x,h,g,_,y]);return(0,Z.useEffect)(()=>()=>{x()},[x]),{isPlaying:a,isAvailable:s,error:l,speak:C,stop:x,checkAvailability:b,unlockAudio:S}}var TE=3e4,EE=null,DE=null;async function OE(){return EE&&Date.now()-EE.checkedAt<TE?EE:DE||(DE=(async()=>{try{let e=await m(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return EE=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return EE=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return EE=e,e}finally{DE=null}})(),DE)}var kE=null;function AE(){return kE||=new(window.AudioContext||window.webkitAudioContext),kE}function jE(e={}){let t=e.enabled??!0,[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useCallback)(async()=>{try{let e=AE();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useSayTTS] Failed to unlock audio:`,e)}},[]),p=(0,Z.useCallback)(async()=>{if(!t)return a(!1),s([]),!1;try{let e=await OE();return a(e.available),s(e.voices),e.available}catch{return a(!1),s([]),!1}},[t]);(0,Z.useEffect)(()=>{p()},[p]);let h=(0,Z.useCallback)(()=>{if(u.current){try{u.current.stop()}catch{}u.current=null}d.current&&=(d.current.abort(),null),r(!1)},[]),g=(0,Z.useCallback)(async(e,t)=>{if(h(),!e.trim()){l(`No text to speak`),t?.onError?.(`No text to speak`);return}l(null);try{d.current=new AbortController;let n=await m(`/api/tts/say/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:t?.voice||`Samantha`,rate:t?.rate||200}),signal:d.current.signal});if(!n.ok){let e=await n.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${n.status}`)}let i=await n.blob(),a=await i.arrayBuffer();i.size;let o=AE();o.state===`suspended`&&await o.resume();let s=await o.decodeAudioData(a),c=o.createBufferSource();c.buffer=s,c.connect(o.destination),u.current=c,c.onended=()=>{r(!1),u.current=null,t?.onEnd?.()},r(!0),t?.onStart?.(),c.start(0)}catch(e){if(e.name===`AbortError`)return;let n=e instanceof Error?e.message:`Failed to speak`;console.error(`[useSayTTS] Error:`,n),l(n),t?.onError?.(n),r(!1)}},[h]);return(0,Z.useEffect)(()=>()=>{h()},[h]),{isPlaying:n,isAvailable:i,voices:o,error:c,speak:g,stop:h,checkAvailability:p,unlockAudio:f}}function ME(e){return e?e.replace(/```[\s\S]*?```/g,``).replace(/`([^`\n]*)`/g,`$1`).replace(/[*_~#]/g,``).replace(/https?:\/\/[^\s]+/g,``).replace(/(^|\s)\/(?:[\w.-]+\/)*[\w.-]+/g,`$1`).replace(/([\w.])\/([\w.])/g,`$1 slash $2`).replace(/^\s*[$#>]\s*/gm,``).replace(/[[\]{}()<>|&;]/g,` `).replace(/\\/g,``).replace(/\s+/g,` `).trim():``}var NE=600,PE=`Summarize the assistant reply for text-to-speech listening. Reply with 2-4 sentences of plain spoken prose in the same language as the reply. No markdown, no lists, no code — mention code changes briefly in words instead.`;async function FE(e,t){try{let n=await m(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:PE,...t.providerID?{preferredProviderID:t.providerID}:{},...t.modelID?{preferredModelID:t.modelID}:{}})});if(!n.ok)return null;let r=await n.json().catch(()=>null);return typeof r?.text==`string`&&r.text.trim()?r.text.trim():null}catch{return null}}function IE(){let[e,t]=(0,Z.useState)(!1),n=Ai(e=>e.voiceProvider),r=Ai(e=>e.speechRate),i=Ai(e=>e.speechPitch),a=Ai(e=>e.speechVolume),o=Ai(e=>e.sayVoice),s=Ai(e=>e.localTtsVoiceId),c=Ai(e=>e.browserVoice),l=Ai(e=>e.openaiVoice),u=Ai(e=>e.openaiCompatibleVoice),d=Ai(e=>e.openaiCompatibleUrl),f=Ai(e=>e.openaiCompatibleTtsModel),p=Ai(e=>e.showMessageTTSButtons),m=Ai(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=wE({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=jE({enabled:_}),{speak:w,stop:T}=eo(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),io.cancelSpeech()},[y,S,T]);return{isPlaying:e,play:(0,Z.useCallback)(async e=>{if(e.trim()){E(),t(!0);try{let p=e;if(m===`summarized`&&e.length>=NE){let{currentProviderId:t,currentModelId:n}=Ai.getState(),r=await FE(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=ME(p),y=g?p:_;if(h&&b)await v(y,{voice:n===`openai-compatible`?u:l,model:n===`openai-compatible`?f:void 0,speed:r,pitch:i,volume:a,summarize:!1,baseURL:n===`openai-compatible`?d:void 0,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`local`)await w(_,{speakerId:s,speed:r,onEnd:()=>t(!1),onError:()=>t(!1)});else if(n===`say`&&C){let e=Math.round(100+(r-.5)*200);await x(_,{voice:o,rate:e,onEnd:()=>t(!1),onError:()=>t(!1)})}else await io.waitForVoices(),await io.resumeAudioContext(),await io.speakText(_,navigator.language||`en-US`,()=>t(!1),{rate:r,pitch:i,volume:a,voiceName:c||void 0})}catch(e){console.error(`[useMessageTTS] Playback error:`,e),t(!1)}}},[n,h,r,i,a,o,c,l,u,d,f,b,C,m,v,x,w,s,E]),stop:E}}var LE=8,RE=280,zE=null;Or(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),zE&&(0,rl.flushSync)(zE)});var BE=new Set(`address.article.aside.blockquote.dd.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.table.ul`.split(`.`)),VE=e=>e.replace(/\r\n?/g,`
|
|
6565
|
+
`),HE=e=>VE(e).trim(),UE=(e,t)=>{if(e.contains(t))return!0;let n=t instanceof ShadowRoot?t:t.getRootNode();return n instanceof ShadowRoot&&e.contains(n.host)},WE=e=>{let t=[],n=e=>{for(let r of e.querySelectorAll(`*`))r.shadowRoot&&(t.push(r.shadowRoot),n(r.shadowRoot))};return n(e),t},GE=(e,t)=>{let n=WE(t),r=e.getComposedRanges?.({shadowRoots:n})[0];if(r){let e=document.createRange();if(e.setStart(r.startContainer,r.startOffset),e.setEnd(r.endContainer,r.endOffset),UE(t,e.commonAncestorContainer))return e}if(e.rangeCount===0)return null;let i=e.getRangeAt(0);return UE(t,i.commonAncestorContainer)?i:null},KE=e=>e.replace(/\s+/g,` `).trim(),qE=e=>{if(e.nodeType===Node.TEXT_NODE)return KE(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase(),r=Array.from(t.childNodes).map(e=>qE(e)).join(``).replace(/\s+/g,` `).trim();if(!r&&n!==`br`)return``;if(n===`br`)return`
|
|
6566
|
+
`;if(n===`strong`||n===`b`)return`**${r}**`;if(n===`em`||n===`i`)return`*${r}*`;if(n===`code`)return`\`${r.replace(/`/g,"\\`")}\``;if(n===`a`){let e=t.getAttribute(`href`);return e?`[${r}](${e})`:r}return r},JE=(e,t)=>Array.from(e.children).filter(e=>e instanceof HTMLElement&&e.tagName.toLowerCase()===`li`).map((e,n)=>{let r=t?`${n+1}. `:`- `,i=Array.from(e.childNodes).map(e=>qE(e)).join(``).replace(/\s+/g,` `).trim();return i?`${r}${i}`:``}).filter(Boolean).join(`
|
|
6567
|
+
`),YE=e=>{if(e.nodeType===Node.TEXT_NODE)return HE(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase();if(n===`pre`){let e=t.querySelector(`code`);return`\`\`\`${((e?.className||``).match(/language-([\w-]+)/)?.[1]||``).trim()}\n${VE(e?.textContent||t.textContent||``).replace(/\n$/,``)}\n\`\`\``}if(n===`code`){let e=VE(t.textContent||``).trim();return e?`\`${e.replace(/`/g,"\\`")}\``:``}if(n===`ul`)return JE(t,!1);if(n===`ol`)return JE(t,!0);if(n===`blockquote`)return HE(Array.from(t.childNodes).map(e=>YE(e)).join(`
|
|
6568
6568
|
`)).split(`
|
|
6569
6569
|
`).filter(e=>e.length>0).map(e=>`> ${e}`).join(`
|
|
6570
|
-
`);if(/^h[1-6]$/.test(n)){let e=Number.parseInt(n[1],10),r=
|
|
6570
|
+
`);if(/^h[1-6]$/.test(n)){let e=Number.parseInt(n[1],10),r=HE(Array.from(t.childNodes).map(e=>qE(e)).join(``));return r?`${`#`.repeat(e)} ${r}`:``}if(n===`p`||n===`div`||n===`li`)return HE(Array.from(t.childNodes).map(e=>qE(e)).join(``));let r=Array.from(t.childNodes).map(e=>YE(e)).filter(e=>e.length>0);return r.length>0?r.join(`
|
|
6571
6571
|
|
|
6572
|
-
`):
|
|
6572
|
+
`):HE(Array.from(t.childNodes).map(e=>qE(e)).join(``))},XE=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!BE.has(t.tagName.toLowerCase())}),ZE=(e,t)=>{let n=e.cloneContents();if(XE(n)){let e=HE(Array.from(n.childNodes).map(e=>qE(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>YE(e)).filter(e=>e.length>0).join(`
|
|
6573
6573
|
|
|
6574
|
-
`).trim()||VE(t)},ZE=({containerRef:e})=>{let{t}=ct(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),c=Z.useRef(!1),[l,u]=Z.useState(!1),d=Z.useRef(null),f=Z.useRef(LE),p=Z.useRef(null),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(!1),_=ri(e=>e.createSession),v=ei(e=>e.setPendingInputText),y=q(e=>e.isMobile),b=Rh(Lh()).textSelectionMutation;Z.useEffect(()=>{g.current=n.show},[n.show]),Z.useEffect(()=>()=>{m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]);let x=Z.useCallback(()=>{p.current=null,RE===x&&(RE=null),g.current&&=(m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),u(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{RE===x&&(RE=null)},[x]);let S=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=f.current/2,r=IE+n,i=t-IE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),C=Z.useCallback(()=>{if(!p.current)return;RE!==x&&(RE?.(),RE=x);let{plainText:e,markdownText:t,rect:i}=p.current,o=!n.show,c=y?i.left+i.width/2:S(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),g.current=!0,o&&(u(!0),m.current!==null&&window.cancelAnimationFrame(m.current),m.current=window.requestAnimationFrame(()=>{u(!1),m.current=null}))},[S,x,y,n.show]);Z.useLayoutEffect(()=>{if(!n.show||y||!d.current)return;let e=d.current.offsetWidth;!Number.isFinite(e)||e<=0||e===f.current||(f.current=e,r(e=>({...e,x:S(e.x)})))},[S,y,n.show]),Z.useEffect(()=>{if(!n.show||y)return;let e=()=>{r(e=>({...e,x:S(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[S,y,n.show]);let w=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){c.current||x();return}let r=VE(t.toString());if(!r){c.current||x();return}let i=WE(t,n);if(!i){c.current||x();return}let a=i.getBoundingClientRect();p.current={plainText:r,markdownText:XE(i,r),rect:a},c.current||C()},[e,x,C]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{c.current=!0,x()},r=()=>{c.current=!1,h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{h.current=null,w()},10)},i=new Set,a=()=>{for(let e of UE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,w))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,w),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{d.current&&!d.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&x()};return document.addEventListener(`mousedown`,s),()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,w);document.removeEventListener(`selectionchange`,w),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,w,x,C]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{d.current&&e.target instanceof Node&&d.current.contains(e.target)||x()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,x]);let T=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;v(t,`append`),x(),window.getSelection()?.removeAllRanges()},[v,x]),E=Z.useCallback(()=>{T(o)},[T,o]);Z.useEffect(()=>{let t=t=>{if(!b||!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=WE(n,r);i&&(t.preventDefault(),T(XE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[T,b,e]);let D=Z.useCallback(async()=>{i&&(await _(void 0,null,null)&&v(i,`replace`),x(),window.getSelection()?.removeAllRanges())},[i,_,v,x]),O=Z.useCallback(async()=>{if(!i)return;let e=await ut(i);e.ok||console.error(`Failed to copy:`,e.error),x(),window.getSelection()?.removeAllRanges()},[i,x]);return n.show?y?(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,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]`,l?`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:[b?(0,$.jsxs)(`button`,{onClick:E,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,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--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:O,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,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]`,l?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[b?(0,$.jsxs)(`button`,{onClick:E,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)(Zp,{shortcut:`⌘+I`})]}):null,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.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,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},QE=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),$E=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),QE(e,n)},eD=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),tD=(e,t)=>{if(!eD(e))return``;let n=new Date(e),r=new Date,i=co(n,t),a=lt(),o=dt.getState().dictionary;if(QE(n,r))return i;if($E(n,r))return ft(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}`},nD=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,rD=e=>e,iD=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=rD(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},aD=(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-iD(n);return!Number.isFinite(a)||a<=0?null:a},oD=e=>{let t=aD(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=nD(e.outputTokens)+nD(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},sD=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`},cD=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`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},lD=[`search`,`read`,`list`];function uD(e){let t=uw(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function dD(e){let t={read:0,search:0,list:0};for(let n of e){let e=uD(n);e&&(t[e]+=1)}return t}var fD=[`edit`,`command`,`other`],pD=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),mD=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function hD(e){if(!ow(e))return null;let t=uw(e);return pD.has(t)?`edit`:mD.has(t)?`command`:`other`}function gD(e){let t={edit:0,command:0,other:0};for(let n of e){let e=hD(n);e&&(t[e]+=1)}return t}function _D(e){return NC(e)}var vD=[...lD,...fD];function yD(e){return{...dD(e),...gD(e)}}function bD(e){return lw(e)}function xD(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!sw(e.toolName):e.kind!=null||e.type!=null}function SD(e,t,n){for(let r=t;r<e.length;r+=1)if(xD(n(e[r])))return!0;return!1}function CD(e){return`parts`in e?e.parts.some(e=>bD(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>bD(e))}function wD(e,t,n){let r=[],i=t;for(;i<e.length&&sw(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var TD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,ED=e=>{let t=(0,Q.c)(12),{added:n,removed:r}=e;if(n<=0&&r<=0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=Y(`inline-flex flex-none items-center gap-0.5 tabular-nums`,TD),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=n>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,n]}):null,t[1]=n,t[2]=a);let o;t[3]!==n||t[4]!==r?(o=n>0&&r>0?(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}):null,t[3]=n,t[4]=r,t[5]=o):o=t[5];let s;t[6]===r?s=t[7]:(s=r>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,r]}):null,t[6]=r,t[7]=s);let c;return t[8]!==a||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`span`,{className:i,children:[a,o,s]}),t[8]=a,t[9]=o,t[10]=s,t[11]=c):c=t[11],c},DD=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=ct(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??CD({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=yD(u.map(e=>e.tool)),p=_D(u),m=vD.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:e===`list`?t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`:e===`edit`?t===1?`chat.usedGroup.editSingle`:`chat.usedGroup.editPlural`:e===`command`?t===1?`chat.usedGroup.commandSingle`:`chat.usedGroup.commandPlural`:t===1?`chat.usedGroup.otherSingle`:`chat.usedGroup.otherPlural`,{count:t})}).join(`, `),h=J(()=>{c(e=>!e)}),g=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())}),_=o(s?`chat.usedGroup.collapseAria`:`chat.usedGroup.expandAria`),v=o(d?`chat.usedGroup.running`:`chat.usedGroup.used`),y=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":_,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,mm),onClick:h,onKeyDown:g,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,y,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(KC,{isMobile:t,label:o(`chat.usedGroup.running`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,y,TD,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:v}),m?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,y,TD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(cD,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(ED,{added:p.added,removed:p.removed}),(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:`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 OD(e,t,n){let r=[],i=t;for(;i<e.length&&aw(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var kD=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function AD(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=kD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=kD(e.name);if(t)return t;let r=kD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=kD(n.output.name);if(e)return e}return null}function jD(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 MD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,ND=({activities:e,isMobile:t,children:n})=>{let{t:r}=ct(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>lw(e)),{joinedVisible:l,hiddenCount:u}=jD(s.map(AD)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,mm),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)(KC,{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`,MD,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`,MD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(cD,{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]})},PD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=q(FD),l=n,u=typeof l.text==`string`?l.text:``,d=typeof l.content==`string`?l.content:``,f=d.length>u.length?d:u,p=l.time,m=n.sessionID,h=o===void 0||o!==`completed`,g,_;if(t[0]!==i||t[1]!==f?(g=()=>{f.trim().length!==0&&i?.(`structural`)},_=[i,f],t[0]=i,t[1]=f,t[2]=g,t[3]=_):(g=t[2],_=t[3]),Z.useEffect(g,_),!f||f.trim().length===0)return null;let v=o??`streaming`,y=h&&typeof p?.end!=`number`,b;t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==m||t[10]!==v||t[11]!==y?(b=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(HT,{part:n,sessionId:m,messageId:r,streamPhase:v,chatRenderMode:c,hasStreamingHapticLifecycle:y,onContentChange:i,onShowPopup:s})}),t[4]=c,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=m,t[10]=v,t[11]=y,t[12]=b):b=t[12];let x;t[13]===a?x=t[14]:(x=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=x);let S;return t[15]!==b||t[16]!==x?(S=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[b,x]}),t[15]=b,t[16]=x,t[17]=S):S=t[17],S});function FD(e){return e.chatRenderMode}var ID=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},LD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,RD=Y(`typography-meta font-medium`,LD),zD=Y(`typography-meta`,LD),BD=[],VD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},HD=e=>{let t=new Set;for(let n of e)VD(n)&&n.messageId&&t.add(n.messageId);return[...t]},UD=(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}),WD=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=sc(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},GD=e=>e,KD=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},qD=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},JD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},YD=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},XD=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=YD(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`}`},ZD=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=XD(n.todos);if(e)return e}if(Array.isArray(r)){let e=XD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=XD(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=XD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=XD(e.todos);if(t)return t}}catch{}return null},QD=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)},$D=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(iS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,zD),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`,zD),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)(iS,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},eO=e=>{let t=xo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},tO=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 AD(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`?ZD(e):KD(e)},nO=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}},rO=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=pm(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)(ST,{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&&KS([e.activity.part],[t.activity.part])),iO=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=pm(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(sO,{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&&oO(e.activities,t.activities)),aO=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Pn(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(sw(i)){let r=wD(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:SD(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(aw(i)){let r=OD(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(nw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(tw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(rw(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},oO=(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||!KS([r.part],[i.part]))return!1}return!0},sO=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ct(),s=q(dO),c=uc(n,o),l;t[0]===n?l=t[1]:(l=aS(n),t[0]=n,t[1]=l);let u=l,d;t[2]===n?d=t[3]:(d=n.toLowerCase(),t[2]=n,t[3]=d);let f=d===`read`,p=Z.useContext(Ao),m=ng(),h=Se(fO),g=Lh(),_=g.kind===`embedded`?g.directory:h,v;t[4]===n?v=t[5]:(v=n.toLowerCase(),t[4]=n,t[5]=v);let y=v===`skill`,b;t[6]===y?b=t[7]:(b={enabled:y},t[6]=y,t[7]=b);let x=Ei(b),S;t[8]===x.data?S=t[9]:(S=x.data??[],t[8]=x.data,t[9]=S);let C=S,w;t[10]===C?w=t[11]:(w=new Map(C.map(pO)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||lw(E.part),O;t[12]===E?O=t[13]:(O=E?tO(E):null,t[12]=E,t[13]=O);let k=O,A;if(t[14]!==k||t[15]!==E||t[16]!==T||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!E||!k){A=null;break bb0}let e=T.get(k)?.path||JD(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=eO(e);if(!r){A=null;break bb0}let i;t[19]!==k||t[20]!==r?(i={name:k,path:r},t[19]=k,t[20]=r,t[21]=i):i=t[21],A=i}t[14]=k,t[15]=E,t[16]=T,t[17]=n,t[18]=A}else A=t[18];let j=A,M;if(t[22]!==_||t[23]!==f||t[24]!==E){bb1:{if(!f||!E){M=null;break bb1}let e=qD(E);if(!e){M=null;break bb1}let n=yo(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=QD(E),t[26]=E,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],M=i}t[22]=_,t[23]=f,t[24]=E,t[25]=M}else M=t[25];let N=M,P;t[32]!==_||t[33]!==m||t[34]!==p?(P=(e,t)=>{if(!_)return;let n=bo(_,e);if(!n)return;if(m){m.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(p?.editor){p.editor.openFile(n,t);return}if(!wo(n,_)){mc(n,_).then(()=>{let e=q.getState(),r=_||vo(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=q.getState(),i=vo(_,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=_,t[33]=m,t[34]=p,t[35]=P):P=t[35];let F=J(P),I;t[36]!==_||t[37]!==m?(I=e=>{let t=xo(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=q.getState(),n=_||vo(``,t);e.openContextFile(n,t)};if(_&&!wo(t,_)){mc(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let G=J(ee),K;t[48]===G?K=t[49]:(K=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),G())},t[48]=G,t[49]=K);let te=J(K),ne=U&&W&&`cursor-pointer`,re=U&&!W&&`cursor-default opacity-70`,ie;t[50]!==ne||t[51]!==re?(ie=Y(`flex w-full items-center gap-x-1.5 min-w-0`,mm,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=U?`soft`:void 0,oe=U?G:void 0,se=U?te:void 0,ce=U?`button`:void 0,le=U&&W?0:void 0,ue=U&&!W?!0:void 0,de=i?`size-4`:`size-3.5`,fe;t[53]===de?fe=t[54]:(fe=Y(`inline-flex items-center justify-center flex-shrink-0`,de),t[53]=de,t[54]=fe);let pe;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(pe={color:`var(--tools-icon)`},t[55]=pe):pe=t[55];let me=D?(0,$.jsx)(KC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,he;t[56]!==fe||t[57]!==pe||t[58]!==me?(he=(0,$.jsx)(`div`,{className:fe,style:pe,children:me}),t[56]=fe,t[57]=pe,t[58]=me,t[59]=he):he=t[59];let ge,_e;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ge=Y(RD,`inline-flex items-center flex-shrink-0 opacity-85`),_e={color:`var(--tools-title)`},t[60]=ge,t[61]=_e):(ge=t[60],_e=t[61]);let ve;t[62]===c?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:c,children:c}),t[62]=c,t[63]=ve);let ye;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(ye=f&&N?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,zD),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(yd,{filePath:N.path,className:`h-3.5 w-3.5`}):null,$D(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==k||t[71]!==B?(be=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(iS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,zD),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=be):be=t[72];let xe;t[73]!==k||t[74]!==V?(xe=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:mO,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`,zD),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(WD,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=xe):xe=t[75];let Ce;t[76]!==H||t[77]!==j?(Ce=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,zD),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=Ce):Ce=t[78];let we;t[79]!==k||t[80]!==H||t[81]!==j?(we=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,zD),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=we):we=t[82];let Te;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Te=!f&&!B&&!V&&!H&&k?(0,$.jsx)(iS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,zD),style:{color:`var(--tools-description)`},children:k}):null,t[83]=a,t[84]=k,t[85]=V,t[86]=f,t[87]=B,t[88]=H,t[89]=Te):Te=t[89];let Ee;return t[90]!==ie||t[91]!==ae||t[92]!==oe||t[93]!==se||t[94]!==ce||t[95]!==le||t[96]!==ue||t[97]!==he||t[98]!==ve||t[99]!==ye||t[100]!==be||t[101]!==xe||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ie,"data-mobile-press-feedback":ae,onClick:oe,onKeyDown:se,role:ce,tabIndex:le,"aria-disabled":ue,children:[he,ve,ye,be,xe,Ce,we,Te]}),t[90]=ie,t[91]=ae,t[92]=oe,t[93]=se,t[94]=ce,t[95]=le,t[96]=ue,t[97]=he,t[98]=ve,t[99]=ye,t[100]=be,t[101]=xe,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&&oO(e.activities,t.activities)),cO=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)(eE,{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}),lO=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)(PD,{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}),uO=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}=ct(),_=pc()??``,v=Z.useMemo(()=>HD(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?ID(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(()=>nO(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Rr(_,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=J(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=J(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Rr(_,n,e).status}),U=H.includes(`loading`),W=H.includes(`error`),ee=H.length>0&&H.every(e=>e===`ready`),G=t.some(e=>V.has(e.messageId)&&VD(e)),K=ee&&!G&&!UD(t,V),te=Z.useMemo(()=>B?GD(e):BD,[e,B]),ne=Z.useMemo(()=>B?aO(te):[],[B,te]),re=Z.useMemo(()=>L||z===0?0:Math.max(0,ne.length-z),[L,z,ne.length]),ie=Z.useMemo(()=>L||z===0?ne:ne.slice(-z),[L,z,ne]);if((!m||I&&!O)&&ne.length===0)return null;let ae=(e,t)=>{let n=(0,$.jsx)(`div`,{className:pm(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},oe=B?ie.map((e,t)=>{switch(e.type){case`reasoning`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(cO,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(lO,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(rO,{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)(iO,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(DD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return iw(n)?(0,$.jsx)(sO,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(ST,{part:t,messageId:e.messageId,isExpanded:l.has(e.id),onToggle:u,isMobile:c,onContentChange:f,onShowPopup:d,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(ND,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(sO,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(rO,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,se=ie.length>0;return m?(0,$.jsxs)(`div`,{className:pm(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&mm,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(KC,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(la,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),se?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),re>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,re,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:oe})]}):null,L&&(U||W||K)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,W&&`text-[var(--status-error)]`),role:W?`alert`:`status`,children:U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(ua,{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:pm(c),children:oe})});function dO(e){return e.showToolFileIcons}function fO(e){return e.currentDirectory}function pO(e){return[e.name,e]}function mO(e){e.stopPropagation()}var hO=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(uO,{...e}),t[0]=e,t[1]=n),n}),gO={contain:`layout`},_O={containerType:`inline-size`,containerName:`message-footer`},vO=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,yO=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,bO=`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`,xO=`size-3.5!`,SO=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,CO=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,wO=`flex items-center gap-2`,TO=`flex items-center gap-2 text-muted-foreground`,EO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,DO=`size-3.5!`,OO=`medium`,kO=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,AO=`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)]`,jO=`h-7 gap-1.5`,MO=`h-6 gap-1`,NO=`text-[11px] leading-none`,PO=`size-3.5`,FO=`size-3`,IO=5,LO=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)(yd,{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=kO(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}),RO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ct(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?MO:jO,d;t[3]===u?d=t[4]:(d=Y(AO,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)(LO,{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)(ua,{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}),zO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=ct(),c=pc(),l=Lh(),u=l.directory||c,d=l.sessionId,f=ng(),p=q($O),m;t[0]===r?m=t[1]:(m=r??[],t[0]=r,t[1]=m);let h=m,g;t[2]===h?g=t[3]:(g=h.slice(0,IO),t[2]=h,t[3]=g);let _=g,v=Math.max(0,h.length-_.length),y=h.length>0?h.length:n,b=!!(f||!o&&u||o&&a),x;t[4]!==y||t[5]!==s?(x=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[4]=y,t[5]=s,t[6]=x):x=t[6];let S=x,C;t[7]!==v||t[8]!==s?(C=s(v===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:v}),t[7]=v,t[8]=s,t[9]=C):C=t[9];let w=C,T=Y(AO,o?MO:jO),E=o?FO:PO,D;t[10]===o?D=t[11]:(D=o?Y(NO,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=D);let O=D,k;t[12]===o?k=t[13]:(k=o?Y(NO,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=k);let A=k,j;t[14]===o?j=t[15]:(j=o?Y(NO,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=j);let M=j,N;t[16]!==u||t[17]!==d||t[18]!==a||t[19]!==o||t[20]!==f||t[21]!==i?(N=e=>{if(f){f.openTurnDiff(i,d,e);return}if(!o&&u){rE({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&rE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[16]=u,t[17]=d,t[18]=a,t[19]=o,t[20]=f,t[21]=i,t[22]=N):N=t[22];let P=J(N),F;t[23]!==u||t[24]!==d||t[25]!==a||t[26]!==o||t[27]!==f||t[28]!==p||t[29]!==i||t[30]!==_[0]?.file?(F=()=>{if(f){f.openTurnDiff(i,d);return}if(!o&&u){p(u,{mode:`diff`,dedupeKey:`turn-diff:${d||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:d});return}let e=_[0]?.file;e&&o&&a&&u&&rE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let G;t[46]!==S||t[47]!==A?(G=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=G):G=t[48];let K;t[49]===E?K=t[50]:(K=Y(E,`opacity-60`),t[49]=E,t[50]=K);let te;return t[51]===K?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:K}),t[51]=K,t[52]=te),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,G,te]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(RO,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),BO=e=>e.type===`subtask`,VO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},HO=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}`},UO=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=pc(),{isMobile:o}=mo(),s=ri(ek),c=q(tk),l=Lh(),{t:u}=ct(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,p;t[2]===n.command?p=t[3]:(p=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=p);let m=p,h;t[4]===n.agent?h=t[5]:(h=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=h);let g=h,_;t[6]===n.prompt?_=t[7]:(_=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=_);let v=_,y;t[8]===n.taskSessionID?y=t[9]:(y=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=y);let b=y,x;t[10]===n.model?x=t[11]:(x=HO(n.model),t[10]=n.model,t[11]=x);let S=x,C=!!v&&!(o&&l.kind===`primary`),w;t[12]===u?w=t[13]:(w=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=w);let T;t[14]===w?T=t[15]:(T=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:w}),t[14]=w,t[15]=T);let E;t[16]===m?E=t[17]:(E=m?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,m]}):null,t[16]=m,t[17]=E);let D;t[18]===g?D=t[19]:(D=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,g]}):null,t[18]=g,t[19]=D);let O;t[20]===S?O=t[21]:(O=S?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:S}):null,t[20]=S,t[21]=O);let k;t[22]!==D||t[23]!==O||t[24]!==T||t[25]!==E?(k=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T,E,D,O]}),t[22]=D,t[23]=O,t[24]=T,t[25]=E,t[26]=k):k=t[26];let A;t[27]===f?A=t[28]:(A=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=A);let j;t[29]!==r||t[30]!==v||t[31]!==C||t[32]!==u?(j=C?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(nk),children:u(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:v}):null]}):null,t[29]=r,t[30]=v,t[31]=C,t[32]=u,t[33]=j):j=t[33];let M;t[34]!==g||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==b?(M=b&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&zh(l,b,e,()=>{if(!di({sessionId:b,directory:e})){if(fl()||o||se()){s(b,e);return}c(e,{mode:`chat`,dedupeKey:`session:${b}`,label:f||g||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=g,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=b,t[43]=M):M=t[43];let N;return t[44]!==k||t[45]!==A||t[46]!==j||t[47]!==M?(N=(0,$.jsxs)(`div`,{className:`mt-2`,children:[k,A,j,M]}),t[44]=k,t[45]=A,t[46]=j,t[47]=M,t[48]=N):N=t[48],N},WO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=pc(),i=q(rk),{isMobile:a}=mo(),{t:o}=ct(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!se(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let c=!!s,l;t[3]!==n.state||t[4]!==o?(l=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=l):l=t[5];let u=l,d=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),f=n.description||d,p=J(()=>{!c||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:f,readOnly:!0})}),m;t[6]===p?m=t[7]:(m=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())},t[6]=p,t[7]=m);let h=J(m),g=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,_;t[8]===g?_=t[9]:(_=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,g),t[8]=g,t[9]=_);let v=c?`button`:void 0,y=c?0:void 0,b=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,x=c?p:void 0,S=c?h:void 0,C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=C):C=t[10];let w;t[11]===f?w=t[12]:(w=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=w);let T=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,E;t[13]===T?E=t[14]:(E=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,T),t[13]=T,t[14]=E);let D;t[15]!==u||t[16]!==E?(D=(0,$.jsx)(`span`,{className:E,children:u}),t[15]=u,t[16]=E,t[17]=D):D=t[17];let O;t[18]!==w||t[19]!==D?(O=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[w,D]}),t[18]=w,t[19]=D,t[20]=O):O=t[20];let k;t[21]===n.body?k=t[22]:(k=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)(Ns,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=k);let A;t[23]!==O||t[24]!==k?(A=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[O,k]}),t[23]=O,t[24]=k,t[25]=A):A=t[25];let j;return t[26]!==S||t[27]!==A||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==b||t[32]!==x?(j=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":b,onClick:x,onKeyDown:S,children:[C,A]}),t[26]=S,t[27]=A,t[28]=_,t[29]=v,t[30]=y,t[31]=b,t[32]=x,t[33]=j):j=t[33],j},GO={background:`transparent`,backgroundColor:`transparent`},KO=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}=ct(),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 _=J(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 ut(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=J(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)(Fc,{language:`bash`,code:u,codeStyle:GO,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(ik),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)(Fc,{language:`bash`,code:d,codeStyle:GO,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},qO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},JO=(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}},YO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=ct(),w=wg(),T=Rh(Lh()),E=q(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Vi(e):!!(BO(e)||VO(e))),[n]),j=Z.useMemo(()=>A.map(e=>Wn(e)?TS(Pn(e)):void 0),[A]),M=f?.token,N=!1,P=!!l,F=!!u,I=!!(s??a),L=!!c,R=b!==`external-actions`,z=b!==`external-content`,B=x&&b===`inline`,V=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),H=J(()=>{!I||!P||!L||typeof window>`u`||(V(),O(!0),k.current=window.setTimeout(()=>{O(!1),k.current=null},1800))});Z.useEffect(()=>{L||(O(!1),V())},[V,L]);let U=J(e=>{!l||!L||(e.stopPropagation(),e.preventDefault(),l(),I&&H())}),W=w===`mini-chat`||!T.fork?void 0:h,ee=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=tD(i,E);return e.length>0?e:null},[S,i,E]),G=Y(`group/user-actions`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),K=!_&&v&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(wO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(EO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:OO,name:`edit`,className:DO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:bO,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:OO,name:`close`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(_&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsx)(`div`,{className:Y(wO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(EO,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??K??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(wO,`justify-end`,!a&&b===`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:[ee?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(EO,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:OO,name:`time`,className:DO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(Ua,{children:ee})]}):null,m&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:bO,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:OO,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(xO,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:bO,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:OO,name:`edit`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:bO,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:OO,name:g===`fork`?`loader-4`:`git-branch`,className:Y(xO,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:bO,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:OO,name:`check`,className:Y(xO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:OO,name:`file-copy`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:gO,onTouchStart:I&&P&&L?H:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,B?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:B?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:A.map((e,i)=>{if(BO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(UO,{part:e})},e.id??`user-subtask-${i}`);if(VO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(KO,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(WO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&Pn(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(nS,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),XO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ct(),s=wg(),c=Lh(),l=Rh(c),{isPlaying:u,play:d,stop:f}=FE(),p=Ai(e=>e.showMessageTTSButtons),m=Ai(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=J(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=J(()=>{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=J(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=J(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=J(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=J(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=J(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(bO,!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:OO,name:`check`,className:Y(xO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:OO,name:`file-copy`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:bO,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:OO,name:`target`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(bO,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:OO,name:`loader-4`,className:Y(xO,`animate-spin`)}):(0,$.jsx)(X,{weight:OO,name:`arrow-left-right`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:Y(bO,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:OO,name:`stop`,className:xO}):(0,$.jsx)(X,{weight:OO,name:`volume-up`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:j})]})]})}),ZO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,messageTokens:c,isMobile:l,alwaysShowActions:u,hasTouchInput:d,expandedTools:f,onToggleTool:p,onShowPopup:m,streamPhase:h,allowAnimation:g,onContentChange:_,hasTextContent:v=!1,onCopyMessage:y,onAuxiliaryContentComplete:b,showReasoningTraces:x=!1,turnGroupingContext:S,errorMessage:C,errorVariant:w=`error`,reviewTransferDirection:T=null})=>{let{t:E,locale:D}=ct(),O=wg(),k=Rh(Lh()),A=h,j=Z.useRef(null),M=Z.useRef(null),N=h===`streaming`||h===`cooldown`,P=Z.useRef({messageId:t,experiencedStreamingOrCooldown:N});P.current.messageId===t?N&&(P.current.experiencedStreamingOrCooldown=!0):P.current={messageId:t,experiencedStreamingOrCooldown:N};let F=!!(d??l),I=!!(u??l),L=l?CO:SO,R=!i,z=Z.useMemo(()=>n.filter(e=>!Vi(e)).filter(e=>e.type!==`compaction`),[n]),B=Z.useMemo(()=>z.filter(e=>e.type===`tool`),[z]),V=Z.useMemo(()=>z.filter(e=>e.type===`text`),[z]),H=Z.useMemo(()=>Vn(V),[V]),U=q(e=>e.openContextPreview),W=se(),ee=O===`mini-chat`,G=Z.useMemo(()=>{if(W||l||ee)return null;for(let e of V){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=cc(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 B){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=cc(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},[V,l,ee,W,B]),K=ri(e=>e.forkFromMessage),te=ri(e=>e.forkTransition),ne=ri(e=>e.currentSessionId),re=ri(e=>e.getDirectoryForSession),ie=pc(),ae=T===`review-to-original`,oe=!l&&!W?T:null,ce=Z.useMemo(()=>{let t=H.trim();if(!(!e||!ie||!t||!oe))return oe===`review-to-original`?{ariaLabel:E(`chat.messageBody.actions.sendReviewFeedback`),tooltip:E(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await vn(e,ie,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:E(`chat.messageBody.actions.sendImplementationResponse`),tooltip:E(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await jt(e,ie,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[H,ie,oe,e,E]),[le,ue]=Z.useState(!1),de=q(e=>e.chatRenderMode),fe=q(e=>e.collapsibleThinkingBlocks),pe=q(e=>e.showSplitAssistantMessageActions),me=q(e=>e.showAssistantTps),he=q(e=>e.timeFormatPreference),ge=de===`sorted`,_e=S?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!C)&&(S?.isTurnSettled??!0),be=ve?`completed`:A,xe=B.length>0,Se=Z.useMemo(()=>B.some(e=>lw(e)),[B]),Ce=lw,we=cw,Te=P.current.experiencedStreamingOrCooldown,Ee=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Ee.current.messageId!==t&&(Ee.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Te||!Et())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of B){if(n.observedPartIds.has(i.id))continue;if(!Hi(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ki({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,B]);let De=Z.useMemo(()=>B.length===0||!Se&&B.every(e=>we(e)),[B,Se,we]),Oe=Z.useMemo(()=>z.filter(e=>e.type===`reasoning`),[z]),ke=Z.useMemo(()=>Oe.length===0||Oe.every(e=>typeof e.time?.end==`number`),[Oe]),Ae=typeof a!=`string`,je=Oe.length>0&&xe&&(Se||Ae||!De),Me=R||xe&&(Se||Ae||!De),Ne=R||je,Pe=xe||Oe.length>0,Fe=V.length===0,Ie=Pe&&Fe&&!Me&&!Ne&&De&&ke,Le=Z.useRef(!1),Re=Z.useRef(!1);Z.useEffect(()=>{Re.current=!1},[t]),Z.useEffect(()=>{if(!Ie){Le.current=!1;return}Le.current||(Le.current=!0,b?.())},[Ie,b]),Z.useEffect(()=>{if(R){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,_?.(`structural`)))},[R,xe,_,ke,Oe.length,Ne]);let ze=!!v&&!R,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||te)){ue(!0);try{await K(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=S?.activityParts;return!ge||!e?[]:e},[ge,S?.activityParts]),He=Z.useMemo(()=>{let e=S?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,S?.activityGroupSegments]),Ue=He.length>0,We=Z.useMemo(()=>{let e=new Map,t=new Map;return Ve.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)}}},[Ve]),Ge=S?.toggleGroup,Ke=S?.activityPresentationKind===`compaction`,qe=S?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?S?.activityOwnerMessageId===t||Ue:!S?.activityOwnerMessageId||S.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=uE(a,z),Qe={finish:a,parts:z,streamPhase:be,error:C,isLastAssistantInTurn:_e},$e=hE(Qe),et=ge&&gE(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!C,rt=w===`info`?`information`:`error-warning`,it=w===`muted`,at=ze,ot=_e&&ye&&!Je&&(v||!!C||i),st=S?.diffStats?.hasDiffs===!0,lt=!ee&&_e&&Ze&&ye&&!Je&&S?.diffStats?.hasDiffs===!0,dt=pe&&at&&!ot&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(XO,{hasCopyableText:ze,isTouchContext:F,onCopyMessage:y,ttsText:H,reviewTransferAction:ce,sessionId:e}),[H,ze,F,y,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=Pn(e.part).trim();return t?(0,$.jsx)(XO,{hasCopyableText:!0,isTouchContext:F,onCopyMessage:async()=>(await ut(t)).ok,ttsText:t}):null},[ge,F,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<z.length;t+=1){let n=z[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,z]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&S){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(hO,{parts:t,materializationParts:r,isExpanded:S.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:S.completionDisposition,activityPresentationKind:S.activityPresentationKind,durationMs:S.durationMs,startedAt:S.userMessageCreatedAt,onToggle:Ge,isMobile:l,expandedTools:f,onToggleTool:p,onShowPopup:m,onContentChange:_,streamPhase:be,showHeader:!0,diffStats:S.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ke&&e(`${t}:compaction-status`,[])}let r=0;for(;r<z.length;){let i=z[r];if(i.type===`text`){let a=We.get(i);if(tt){r+=1;continue}if(Je){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:M,"data-message-text-export-source":`true`,children:(0,$.jsx)(HT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:l?yO:vO,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:wO,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(We.get(i)?.kind===`reasoning`){r+=1;continue}if(!Pn(i).trim()){r+=1;continue}x&&(fe?n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(eE,{part:i,messageId:t,streamPhase:be,onContentChange:_})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(HT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(ge&&!Ye){r+=1;continue}if(We.get(i)?.kind===`tool`){r+=1;continue}if(sw(a)){let e=wD(z,r,e=>e.type!==`tool`||We.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)(DD,{activities:i,isMobile:l,isTurnLive:be!==`completed`,hasFollowingOtherType:SD(z,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return iw(n)?(0,$.jsx)(sO,{toolName:n,activities:[e],isMobile:l,animateTailText:!1},e.id):(0,$.jsx)(ST,{part:e.part,messageId:t,isExpanded:f.has(e.part.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(aw(a)){let e=OD(z,r,e=>e.type!==`tool`||We.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)(ND,{activities:i,isMobile:l,children:i.map(e=>(0,$.jsx)(sO,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:l,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(tw(a)){n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(ST,{part:e,messageId:t,isExpanded:f.has(e.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(sO,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:l,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,I,de,fe,0,f,Je,Ke,l,Ye,ge,mt,t,ft,pt,e,_,m,p,Xe,dt,be,Te,x,tt,et,Ge,S,z]),_t=Z.useMemo(()=>{if(!_e||!ye)return;let e=S?.durationMs;if(!(typeof e!=`number`||e<=0))return qO(e)},[_e,ye,S?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=tD(e,he);return t.length>0?t:null},[o,s,he,D]),yt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=JO(e,c),i=oD({createdAt:s,completedAt:o,fallbackDurationMs:S?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=sD(i);return a.length>0?a:null},[me,_e,ye,n,r,c,s,o,S?.durationMs]),bt=(0,$.jsxs)($.Fragment,{children:[!ee&&!l&&!W&&G?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:bO,"aria-label":E(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ie??(ne?re(ne):null);e&&U(e,G)},children:(0,$.jsx)(X,{weight:OO,name:`global`,className:xO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.openPreview`)})]}):null,!ee&&!ae&&k.fork?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,className:bO,"aria-label":E(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!te,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:OO,name:le?`loader-4`:`git-branch`,className:Y(xO,le&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:j,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:gO,children:[(0,$.jsx)(ZE,{containerRef:j}),(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,nt&&(0,$.jsx)(bc,{children:it?(0,$.jsxs)(`div`,{role:`status`,className:`my-1.5 flex max-w-full items-center gap-1.5 break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`stop-circle`,className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:C})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,w===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,l?`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:[w===`info`&&l?(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:rt,weight:OO,className:Y(xO,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:w===`info`?OO:void 0,className:Y(`shrink-0`,w===`info`?Y(xO,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,w===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,l?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(Ns,{content:C??``,onShowPopup:m,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),lt&&S?.diffStats?(0,$.jsx)(zO,{fileCount:S.diffStats.files,changedFiles:S.changedFiles,turnId:S.turnId,isLatestTurn:S.isLatestTurn,isMobile:l}):null,(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:m}),ht&&(0,$.jsx)(`div`,{className:Y(l?yO:vO),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:wO,"data-message-action-group":`true`,children:ft})}),ot&&(0,$.jsxs)(`div`,{className:L,"data-message-footer":`true`,style:_O,children:[(0,$.jsxs)(`div`,{className:wO,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt?(0,$.jsxs)(`div`,{className:TO,children:[yt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:EO,"aria-label":E(`chat.messageBody.meta.tpsAria`,{rate:yt}),children:[(0,$.jsx)(X,{weight:OO,name:`pulse`,className:DO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Ua,{children:E(`chat.messageBody.meta.tpsTooltip`)})]}):null,_t?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:EO,children:[(0,$.jsx)(X,{weight:OO,name:`hourglass`,className:DO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(Ua,{children:_t})]}):null,vt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:EO,"aria-label":`Message time: ${vt}`,children:[(0,$.jsx)(X,{weight:OO,name:`time`,className:DO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Ua,{children:vt})]}):null]}):null,!ee&&_e&&ve&&!st?(0,$.jsx)(iE,{activityParts:S?.activityParts}):null]})]})]})}),QO=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)(YO,{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)(ZO,{...r}),t[26]=r,t[27]=i),i});function $O(e){return e.openContextPanelTab}function ek(e){return e.setCurrentSession}function tk(e){return e.openContextPanelTab}function nk(e){return!e}function rk(e){return e.openContextPanelTab}function ik(e){return!e}var ak=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}},ok=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,sk=e=>!e,ck=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},lk=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),uk=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,dk=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,fk=`Authentication failed for this provider. Please re-authenticate and retry.`,pk=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};function mk(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:void 0,i=typeof n.message==`string`?n.message:void 0,a=typeof n.name==`string`?n.name:void 0,o=r||i||a;if(o)return a===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${o}\``,variant:`info`}:pk(o)?{text:fk,variant:`error`}:a===`MessageAbortedError`||o.trim().toLowerCase()===`aborted`?{text:t,variant:`muted`}:{text:`Opencode failed to send message with error:\n\`${o}\``,variant:`error`}}var hk=ks(()=>Ue(()=>import(`./ToolOutputDialog-1bp7aeoj.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),gk=4e3,_k=new Map,vk=new Map,yk=new Set([`bash`,`shell`,`cmd`,`terminal`]),bk=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},xk=e=>{let t=_k.get(e);return t?new Set(t):new Set},Sk=(e,t)=>{if(_k.size>=gk&&!_k.has(e)){let e=_k.keys().next().value;typeof e==`string`&&_k.delete(e)}_k.set(e,new Set(t))},Ck=e=>{let t=vk.get(e);return t?new Set(t):new Set},wk=(e,t)=>{if(vk.size>=gk&&!vk.has(e)){let e=vk.keys().next().value;typeof e==`string`&&vk.delete(e)}vk.set(e,new Set(t))},Tk=200,Ek=new Map,Dk=e=>Ek.get(e),Ok=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=Ek.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(Ek.size>=Tk&&!Ek.has(e)){let e=Ek.keys().next().value;typeof e==`string`&&Ek.delete(e)}Ek.set(e,t)}};function kk(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 Ak=(e,t)=>{if(typeof e==`object`&&e)return e[t]},jk=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:c=null,animateUserOnMount:l=!1,onUserAnimationConsumed:u,reviewTransferDirection:d=null})=>{let{t:f}=ct(),{isMobile:p,isTablet:m,hasTouchInput:h}=mo(),g=Lh(),_=Rh(g),v=p||m,y=Z.useRef(null),b=ri(e=>e.currentSessionId),x=Zi(e=>e.getAgentModelForSession),S=Zi(e=>e.getSessionModelSelection),C=ri(e=>e.revertToMessage),w=ri(e=>e.editMessagePreservingChanges),T=ri(e=>e.forkFromMessage),E=ri(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=ri(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=ri(e=>e.clearStagedMessageEdit);Fe(`ui.chat_message.render`),s&&Fe(`ui.chat_message.render.streaming`);let k=Ai(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=q(de(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Wx.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(()=>xk(e.info.id)),[U,W]=Z.useState(()=>Ck(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(xk(e.info.id)),W(Ck(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>ak(e.info),[e.info]).isUser,te=K&&(p||!j),ne=K&&!p&&j&&!te,re=e.info.sessionID,{currentContextAgent:ie,savedSessionAgentSelection:ae}=Om(de(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),oe=Z.useMemo(()=>Rn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),se=Z.useMemo(()=>K?Gi(oe):Rn(e.parts),[K,e.parts,oe]),ce=Z.useMemo(()=>{if(K||!t)return null;let e=Ak(t.info,`clientRole`),n=Ak(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=Ak(t.info,`mode`),i=Ak(t.info,`agent`),a=Ak(t.info,`providerID`),o=Ak(t.info,`modelID`),s=Ak(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=Ak(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[K,t]),le=Z.useMemo(()=>{if(K)return;let t=Ak(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=Ak(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(ce?.agentName)return ce.agentName;if(re)return ie||(ae??void 0)},[K,e.info,ce,re,ie,ae]),ue=K?null:Ak(e.info,`providerID`),fe=K?null:Ak(e.info,`modelID`),pe=Z.useMemo(()=>{if(K||!re)return null;if(ce?.providerId&&ce?.modelId)return{providerId:ce.providerId,modelId:ce.modelId};if(le){let e=x(re,le);if(e?.providerId&&e?.modelId)return e}let e=S(re);return e?.providerId&&e?.modelId?e:null},[K,re,le,ce,x,S]),me=Z.useMemo(()=>K?null:typeof ue==`string`&&ue.trim().length>0?ue:pe?.providerId??null,[K,ue,pe]),he=Z.useMemo(()=>K?null:typeof fe==`string`&&fe.trim().length>0?fe:pe?.modelId??null,[K,fe,pe]),ge=e.info.id?Dk(e.info.id):void 0;K||Ok(e.info.id,{agent:le,provider:me??void 0,model:he??void 0});let _e=le??ge?.agent,ve=me??ge?.provider??null,ye=he??ge?.model??null,be=Z.useMemo(()=>{if(K)return;let e=ve&&k.length>0?k.find(e=>e.id===ve):void 0;return Si(e,ye)||void 0},[K,ve,ye,k]),xe=Z.useMemo(()=>{if(K||!me||!he)return!1;let e=k.find(e=>e.id===me);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===he)?.variants;return!!(t&&Object.keys(t).length>0)},[K,he,me,k]),Se=kk(_e),Ce=kk(ve??void 0),we=kk(ye??void 0),Te=kk(be),Ee=Se??void 0,De=Ce??null,Oe=we??null,ke=Te??void 0,Ae=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),je=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Me=Z.useMemo(()=>K?!0:!!(Ae&&Ae>0),[K,Ae]),Ne=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Pe=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]),Ie=Z.useMemo(()=>wt(se,{includeReasoning:A}),[se,A]),Le=Z.useMemo(()=>K?Ie:!Me&&M===`sorted`?[]:Ie,[M,Me,K,Ie]),Re=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`text`),[K,Ie]),ze=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`tool`),[K,Ie]),Be=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of ze){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=bk(t.tool);!r||!yk.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=bk(t.part.tool);!n||!yk.has(n)||e.add(t.id)}return e},[N,ze,a?.activityParts]),Ve=Z.useMemo(()=>{if(Be.size===0&&U.size===0)return V;let e=new Set(V);return Be.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,Be,V]),He=Z.useMemo(()=>{if(!K)return;let e=se.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,se]),Ue=K&&!hr(Le),We=typeof Ne!=`string`,Ge=Z.useMemo(()=>K?!1:Re.length===0||ze.length===0?We:!0,[Re.length,ze.length,We,K]),Ke=Z.useMemo(()=>!K&&Wx.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[qe,Je]=Z.useState(!1),Ye=Z.useMemo(()=>n?ak(n.info):null,[n]),Xe=!!a,Ze=a?.isLastAssistantInTurn??!1,Qe=uk({isWorking:a?.isWorking===!0,isInActiveTurn:s,headerCompletionDisposition:a?.completionDisposition}),$e=Z.useMemo(()=>K?!1:Xe?!Ze:Ye?!Ye.isUser&&Ye.role===`assistant`:!1,[Xe,Ze,K,Ye]),et=Z.useMemo(()=>Me?`completed`:s?c??`streaming`:`completed`,[c,s,Me]);Z.useEffect(()=>{!K||!l||u?.(e.info.id)},[l,K,e.info.id,u]),Z.useEffect(()=>{Je(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;K||!t||t!==e.info.id||(et===`streaming`||et===`cooldown`)&&Je(!0)},[o,K,e.info.id,et,a?.headerMessageId]);let tt=Z.useMemo(()=>{if(K)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?et===`completed`||qe||et===`streaming`||et===`cooldown`:!1:!0},[o,qe,K,a,et,e.info.id]),nt=Z.useCallback(e=>{ut(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),rt=K?void 0:a?.userMessageVariant??ce?.variant,it=!K&&xe&&typeof rt==`string`&&rt.trim().length>0?rt:void 0,at=Z.useMemo(()=>{if(!K)return mk(e.info?.error,f(`chat.messageBody.aborted`))},[K,e.info,f]),ot=at?.text,st=at?.variant,lt=Z.useMemo(()=>{if(K){let e=Le.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(`
|
|
6574
|
+
`).trim()||HE(t)},QE=({containerRef:e})=>{let{t}=ct(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),c=Z.useRef(!1),[l,u]=Z.useState(!1),d=Z.useRef(null),f=Z.useRef(RE),p=Z.useRef(null),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(!1),_=ri(e=>e.createSession),v=ei(e=>e.setPendingInputText),y=q(e=>e.isMobile),b=zh(Rh()).textSelectionMutation;Z.useEffect(()=>{g.current=n.show},[n.show]),Z.useEffect(()=>()=>{m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]);let x=Z.useCallback(()=>{p.current=null,zE===x&&(zE=null),g.current&&=(m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),u(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{zE===x&&(zE=null)},[x]);let S=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=f.current/2,r=LE+n,i=t-LE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),C=Z.useCallback(()=>{if(!p.current)return;zE!==x&&(zE?.(),zE=x);let{plainText:e,markdownText:t,rect:i}=p.current,o=!n.show,c=y?i.left+i.width/2:S(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),g.current=!0,o&&(u(!0),m.current!==null&&window.cancelAnimationFrame(m.current),m.current=window.requestAnimationFrame(()=>{u(!1),m.current=null}))},[S,x,y,n.show]);Z.useLayoutEffect(()=>{if(!n.show||y||!d.current)return;let e=d.current.offsetWidth;!Number.isFinite(e)||e<=0||e===f.current||(f.current=e,r(e=>({...e,x:S(e.x)})))},[S,y,n.show]),Z.useEffect(()=>{if(!n.show||y)return;let e=()=>{r(e=>({...e,x:S(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[S,y,n.show]);let w=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){c.current||x();return}let r=HE(t.toString());if(!r){c.current||x();return}let i=GE(t,n);if(!i){c.current||x();return}let a=i.getBoundingClientRect();p.current={plainText:r,markdownText:ZE(i,r),rect:a},c.current||C()},[e,x,C]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{c.current=!0,x()},r=()=>{c.current=!1,h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{h.current=null,w()},10)},i=new Set,a=()=>{for(let e of WE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,w))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,w),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{d.current&&!d.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&x()};return document.addEventListener(`mousedown`,s),()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,w);document.removeEventListener(`selectionchange`,w),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,w,x,C]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{d.current&&e.target instanceof Node&&d.current.contains(e.target)||x()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,x]);let T=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;v(t,`append`),x(),window.getSelection()?.removeAllRanges()},[v,x]),E=Z.useCallback(()=>{T(o)},[T,o]);Z.useEffect(()=>{let t=t=>{if(!b||!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=GE(n,r);i&&(t.preventDefault(),T(ZE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[T,b,e]);let D=Z.useCallback(async()=>{i&&(await _(void 0,null,null)&&v(i,`replace`),x(),window.getSelection()?.removeAllRanges())},[i,_,v,x]),O=Z.useCallback(async()=>{if(!i)return;let e=await ut(i);e.ok||console.error(`Failed to copy:`,e.error),x(),window.getSelection()?.removeAllRanges()},[i,x]);return n.show?y?(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,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]`,l?`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:[b?(0,$.jsxs)(`button`,{onClick:E,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,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--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:O,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,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]`,l?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[b?(0,$.jsxs)(`button`,{onClick:E,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)(Zp,{shortcut:`⌘+I`})]}):null,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.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,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},$E=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),eD=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),$E(e,n)},tD=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),nD=(e,t)=>{if(!tD(e))return``;let n=new Date(e),r=new Date,i=co(n,t),a=lt(),o=dt.getState().dictionary;if($E(n,r))return i;if(eD(n,r))return ft(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}`},rD=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,iD=e=>e,aD=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=iD(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},oD=(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-aD(n);return!Number.isFinite(a)||a<=0?null:a},sD=e=>{let t=oD(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=rD(e.outputTokens)+rD(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},cD=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`},lD=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`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},uD=[`search`,`read`,`list`];function dD(e){let t=dw(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function fD(e){let t={read:0,search:0,list:0};for(let n of e){let e=dD(n);e&&(t[e]+=1)}return t}var pD=[`edit`,`command`,`other`],mD=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),hD=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function gD(e){if(!sw(e))return null;let t=dw(e);return mD.has(t)?`edit`:hD.has(t)?`command`:`other`}function _D(e){let t={edit:0,command:0,other:0};for(let n of e){let e=gD(n);e&&(t[e]+=1)}return t}function vD(e){return PC(e)}var yD=[...uD,...pD];function bD(e){return{...fD(e),..._D(e)}}function xD(e){return uw(e)}function SD(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!cw(e.toolName):e.kind!=null||e.type!=null}function CD(e,t,n){for(let r=t;r<e.length;r+=1)if(SD(n(e[r])))return!0;return!1}function wD(e){return`parts`in e?e.parts.some(e=>xD(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>xD(e))}function TD(e,t,n){let r=[],i=t;for(;i<e.length&&cw(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var ED=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,DD=e=>{let t=(0,Q.c)(12),{added:n,removed:r}=e;if(n<=0&&r<=0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=Y(`inline-flex flex-none items-center gap-0.5 tabular-nums`,ED),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=n>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,n]}):null,t[1]=n,t[2]=a);let o;t[3]!==n||t[4]!==r?(o=n>0&&r>0?(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}):null,t[3]=n,t[4]=r,t[5]=o):o=t[5];let s;t[6]===r?s=t[7]:(s=r>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,r]}):null,t[6]=r,t[7]=s);let c;return t[8]!==a||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`span`,{className:i,children:[a,o,s]}),t[8]=a,t[9]=o,t[10]=s,t[11]=c):c=t[11],c},OD=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=ct(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??wD({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=bD(u.map(e=>e.tool)),p=vD(u),m=yD.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:e===`list`?t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`:e===`edit`?t===1?`chat.usedGroup.editSingle`:`chat.usedGroup.editPlural`:e===`command`?t===1?`chat.usedGroup.commandSingle`:`chat.usedGroup.commandPlural`:t===1?`chat.usedGroup.otherSingle`:`chat.usedGroup.otherPlural`,{count:t})}).join(`, `),h=J(()=>{c(e=>!e)}),g=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())}),_=o(s?`chat.usedGroup.collapseAria`:`chat.usedGroup.expandAria`),v=o(d?`chat.usedGroup.running`:`chat.usedGroup.used`),y=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":_,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,hm),onClick:h,onKeyDown:g,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,y,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(qC,{isMobile:t,label:o(`chat.usedGroup.running`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,y,ED,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:v}),m?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,y,ED),style:{color:`var(--tools-description)`},children:(0,$.jsx)(lD,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(DD,{added:p.added,removed:p.removed}),(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:mm(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a]}):null]})};function kD(e,t,n){let r=[],i=t;for(;i<e.length&&ow(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var AD=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function jD(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=AD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=AD(e.name);if(t)return t;let r=AD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=AD(n.output.name);if(e)return e}return null}function MD(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 ND=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,PD=({activities:e,isMobile:t,children:n})=>{let{t:r}=ct(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>uw(e)),{joinedVisible:l,hiddenCount:u}=MD(s.map(jD)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,hm),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)(qC,{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`,ND,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`,ND),style:{color:`var(--tools-description)`},children:(0,$.jsx)(lD,{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:mm(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),n]}):null]})},FD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=q(ID),l=n,u=typeof l.text==`string`?l.text:``,d=typeof l.content==`string`?l.content:``,f=d.length>u.length?d:u,p=l.time,m=n.sessionID,h=o===void 0||o!==`completed`,g,_;if(t[0]!==i||t[1]!==f?(g=()=>{f.trim().length!==0&&i?.(`structural`)},_=[i,f],t[0]=i,t[1]=f,t[2]=g,t[3]=_):(g=t[2],_=t[3]),Z.useEffect(g,_),!f||f.trim().length===0)return null;let v=o??`streaming`,y=h&&typeof p?.end!=`number`,b;t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==m||t[10]!==v||t[11]!==y?(b=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(UT,{part:n,sessionId:m,messageId:r,streamPhase:v,chatRenderMode:c,hasStreamingHapticLifecycle:y,onContentChange:i,onShowPopup:s})}),t[4]=c,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=m,t[10]=v,t[11]=y,t[12]=b):b=t[12];let x;t[13]===a?x=t[14]:(x=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=x);let S;return t[15]!==b||t[16]!==x?(S=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[b,x]}),t[15]=b,t[16]=x,t[17]=S):S=t[17],S});function ID(e){return e.chatRenderMode}var LD=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},RD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,zD=Y(`typography-meta font-medium`,RD),BD=Y(`typography-meta`,RD),VD=[],HD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},UD=e=>{let t=new Set;for(let n of e)HD(n)&&n.messageId&&t.add(n.messageId);return[...t]},WD=(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}),GD=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=sc(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},KD=e=>e,qD=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},JD=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},YD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},XD=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},ZD=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=XD(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`}`},QD=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=ZD(n.todos);if(e)return e}if(Array.isArray(r)){let e=ZD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=ZD(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=ZD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=ZD(e.todos);if(t)return t}}catch{}return null},$D=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)},eO=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),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`,BD),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)(aS,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},tO=e=>{let t=xo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},nO=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 jD(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`?QD(e):qD(e)},rO=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}},iO=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=pm(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)(CT,{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&&qS([e.activity.part],[t.activity.part])),aO=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=pm(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(cO,{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&&sO(e.activities,t.activities)),oO=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Pn(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(cw(i)){let r=TD(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:CD(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(ow(i)){let r=kD(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(rw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(nw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(iw(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},sO=(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||!qS([r.part],[i.part]))return!1}return!0},cO=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ct(),s=q(fO),c=uc(n,o),l;t[0]===n?l=t[1]:(l=oS(n),t[0]=n,t[1]=l);let u=l,d;t[2]===n?d=t[3]:(d=n.toLowerCase(),t[2]=n,t[3]=d);let f=d===`read`,p=Z.useContext(Ao),m=rg(),h=Se(pO),g=Rh(),_=g.kind===`embedded`?g.directory:h,v;t[4]===n?v=t[5]:(v=n.toLowerCase(),t[4]=n,t[5]=v);let y=v===`skill`,b;t[6]===y?b=t[7]:(b={enabled:y},t[6]=y,t[7]=b);let x=Ei(b),S;t[8]===x.data?S=t[9]:(S=x.data??[],t[8]=x.data,t[9]=S);let C=S,w;t[10]===C?w=t[11]:(w=new Map(C.map(mO)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||uw(E.part),O;t[12]===E?O=t[13]:(O=E?nO(E):null,t[12]=E,t[13]=O);let k=O,A;if(t[14]!==k||t[15]!==E||t[16]!==T||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!E||!k){A=null;break bb0}let e=T.get(k)?.path||YD(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=tO(e);if(!r){A=null;break bb0}let i;t[19]!==k||t[20]!==r?(i={name:k,path:r},t[19]=k,t[20]=r,t[21]=i):i=t[21],A=i}t[14]=k,t[15]=E,t[16]=T,t[17]=n,t[18]=A}else A=t[18];let j=A,M;if(t[22]!==_||t[23]!==f||t[24]!==E){bb1:{if(!f||!E){M=null;break bb1}let e=JD(E);if(!e){M=null;break bb1}let n=yo(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=$D(E),t[26]=E,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],M=i}t[22]=_,t[23]=f,t[24]=E,t[25]=M}else M=t[25];let N=M,P;t[32]!==_||t[33]!==m||t[34]!==p?(P=(e,t)=>{if(!_)return;let n=bo(_,e);if(!n)return;if(m){m.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(p?.editor){p.editor.openFile(n,t);return}if(!wo(n,_)){mc(n,_).then(()=>{let e=q.getState(),r=_||vo(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=q.getState(),i=vo(_,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=_,t[33]=m,t[34]=p,t[35]=P):P=t[35];let F=J(P),I;t[36]!==_||t[37]!==m?(I=e=>{let t=xo(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=q.getState(),n=_||vo(``,t);e.openContextFile(n,t)};if(_&&!wo(t,_)){mc(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let G=J(ee),K;t[48]===G?K=t[49]:(K=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),G())},t[48]=G,t[49]=K);let te=J(K),ne=U&&W&&`cursor-pointer`,re=U&&!W&&`cursor-default opacity-70`,ie;t[50]!==ne||t[51]!==re?(ie=Y(`flex w-full items-center gap-x-1.5 min-w-0`,hm,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=U?`soft`:void 0,oe=U?G:void 0,se=U?te:void 0,ce=U?`button`:void 0,le=U&&W?0:void 0,ue=U&&!W?!0:void 0,de=i?`size-4`:`size-3.5`,fe;t[53]===de?fe=t[54]:(fe=Y(`inline-flex items-center justify-center flex-shrink-0`,de),t[53]=de,t[54]=fe);let pe;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(pe={color:`var(--tools-icon)`},t[55]=pe):pe=t[55];let me=D?(0,$.jsx)(qC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,he;t[56]!==fe||t[57]!==pe||t[58]!==me?(he=(0,$.jsx)(`div`,{className:fe,style:pe,children:me}),t[56]=fe,t[57]=pe,t[58]=me,t[59]=he):he=t[59];let ge,_e;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ge=Y(zD,`inline-flex items-center flex-shrink-0 opacity-85`),_e={color:`var(--tools-title)`},t[60]=ge,t[61]=_e):(ge=t[60],_e=t[61]);let ve;t[62]===c?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:c,children:c}),t[62]=c,t[63]=ve);let ye;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(ye=f&&N?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,BD),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(yd,{filePath:N.path,className:`h-3.5 w-3.5`}):null,eO(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==k||t[71]!==B?(be=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(aS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=be):be=t[72];let xe;t[73]!==k||t[74]!==V?(xe=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:hO,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`,BD),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(GD,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=xe):xe=t[75];let Ce;t[76]!==H||t[77]!==j?(Ce=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,BD),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=Ce):Ce=t[78];let we;t[79]!==k||t[80]!==H||t[81]!==j?(we=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,BD),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=we):we=t[82];let Te;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Te=!f&&!B&&!V&&!H&&k?(0,$.jsx)(aS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},children:k}):null,t[83]=a,t[84]=k,t[85]=V,t[86]=f,t[87]=B,t[88]=H,t[89]=Te):Te=t[89];let Ee;return t[90]!==ie||t[91]!==ae||t[92]!==oe||t[93]!==se||t[94]!==ce||t[95]!==le||t[96]!==ue||t[97]!==he||t[98]!==ve||t[99]!==ye||t[100]!==be||t[101]!==xe||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ie,"data-mobile-press-feedback":ae,onClick:oe,onKeyDown:se,role:ce,tabIndex:le,"aria-disabled":ue,children:[he,ve,ye,be,xe,Ce,we,Te]}),t[90]=ie,t[91]=ae,t[92]=oe,t[93]=se,t[94]=ce,t[95]=le,t[96]=ue,t[97]=he,t[98]=ve,t[99]=ye,t[100]=be,t[101]=xe,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&&sO(e.activities,t.activities)),lO=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)(tE,{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}),uO=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)(FD,{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}),dO=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}=ct(),_=pc()??``,v=Z.useMemo(()=>UD(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?LD(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(()=>rO(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Rr(_,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=J(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=J(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Rr(_,n,e).status}),U=H.includes(`loading`),W=H.includes(`error`),ee=H.length>0&&H.every(e=>e===`ready`),G=t.some(e=>V.has(e.messageId)&&HD(e)),K=ee&&!G&&!WD(t,V),te=Z.useMemo(()=>B?KD(e):VD,[e,B]),ne=Z.useMemo(()=>B?oO(te):[],[B,te]),re=Z.useMemo(()=>L||z===0?0:Math.max(0,ne.length-z),[L,z,ne.length]),ie=Z.useMemo(()=>L||z===0?ne:ne.slice(-z),[L,z,ne]);if((!m||I&&!O)&&ne.length===0)return null;let ae=(e,t)=>{let n=(0,$.jsx)(`div`,{className:pm(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},oe=B?ie.map((e,t)=>{switch(e.type){case`reasoning`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(lO,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(uO,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(iO,{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)(aO,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(OD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return aw(n)?(0,$.jsx)(cO,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(CT,{part:t,messageId:e.messageId,isExpanded:l.has(e.id),onToggle:u,isMobile:c,onContentChange:f,onShowPopup:d,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(PD,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(cO,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(iO,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,se=ie.length>0;return m?(0,$.jsxs)(`div`,{className:pm(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&hm,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(qC,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(la,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),se?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),re>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,re,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:oe})]}):null,L&&(U||W||K)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,W&&`text-[var(--status-error)]`),role:W?`alert`:`status`,children:U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(ua,{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:pm(c),children:oe})});function fO(e){return e.showToolFileIcons}function pO(e){return e.currentDirectory}function mO(e){return[e.name,e]}function hO(e){e.stopPropagation()}var gO=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(dO,{...e}),t[0]=e,t[1]=n),n}),_O={contain:`layout`},vO={containerType:`inline-size`,containerName:`message-footer`},yO=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,bO=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,xO=`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`,SO=`size-3.5!`,CO=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,wO=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,TO=`flex items-center gap-2`,EO=`flex items-center gap-2 text-muted-foreground`,DO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,OO=`size-3.5!`,kO=`medium`,AO=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,jO=`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)]`,MO=`h-7 gap-1.5`,NO=`h-6 gap-1`,PO=`text-[11px] leading-none`,FO=`size-3.5`,IO=`size-3`,LO=5,RO=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)(yd,{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=AO(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}),zO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ct(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?NO:MO,d;t[3]===u?d=t[4]:(d=Y(jO,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)(RO,{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)(ua,{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}),BO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=ct(),c=pc(),l=Rh(),u=l.directory||c,d=l.sessionId,f=rg(),p=q(ek),m;t[0]===r?m=t[1]:(m=r??[],t[0]=r,t[1]=m);let h=m,g;t[2]===h?g=t[3]:(g=h.slice(0,LO),t[2]=h,t[3]=g);let _=g,v=Math.max(0,h.length-_.length),y=h.length>0?h.length:n,b=!!(f||!o&&u||o&&a),x;t[4]!==y||t[5]!==s?(x=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[4]=y,t[5]=s,t[6]=x):x=t[6];let S=x,C;t[7]!==v||t[8]!==s?(C=s(v===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:v}),t[7]=v,t[8]=s,t[9]=C):C=t[9];let w=C,T=Y(jO,o?NO:MO),E=o?IO:FO,D;t[10]===o?D=t[11]:(D=o?Y(PO,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=D);let O=D,k;t[12]===o?k=t[13]:(k=o?Y(PO,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=k);let A=k,j;t[14]===o?j=t[15]:(j=o?Y(PO,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=j);let M=j,N;t[16]!==u||t[17]!==d||t[18]!==a||t[19]!==o||t[20]!==f||t[21]!==i?(N=e=>{if(f){f.openTurnDiff(i,d,e);return}if(!o&&u){iE({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&iE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[16]=u,t[17]=d,t[18]=a,t[19]=o,t[20]=f,t[21]=i,t[22]=N):N=t[22];let P=J(N),F;t[23]!==u||t[24]!==d||t[25]!==a||t[26]!==o||t[27]!==f||t[28]!==p||t[29]!==i||t[30]!==_[0]?.file?(F=()=>{if(f){f.openTurnDiff(i,d);return}if(!o&&u){p(u,{mode:`diff`,dedupeKey:`turn-diff:${d||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:d});return}let e=_[0]?.file;e&&o&&a&&u&&iE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let G;t[46]!==S||t[47]!==A?(G=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=G):G=t[48];let K;t[49]===E?K=t[50]:(K=Y(E,`opacity-60`),t[49]=E,t[50]=K);let te;return t[51]===K?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:K}),t[51]=K,t[52]=te),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,G,te]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(zO,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),VO=e=>e.type===`subtask`,HO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},UO=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}`},WO=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=pc(),{isMobile:o}=mo(),s=ri(tk),c=q(nk),l=Rh(),{t:u}=ct(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,p;t[2]===n.command?p=t[3]:(p=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=p);let m=p,h;t[4]===n.agent?h=t[5]:(h=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=h);let g=h,_;t[6]===n.prompt?_=t[7]:(_=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=_);let v=_,y;t[8]===n.taskSessionID?y=t[9]:(y=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=y);let b=y,x;t[10]===n.model?x=t[11]:(x=UO(n.model),t[10]=n.model,t[11]=x);let S=x,C=!!v&&!(o&&l.kind===`primary`),w;t[12]===u?w=t[13]:(w=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=w);let T;t[14]===w?T=t[15]:(T=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:w}),t[14]=w,t[15]=T);let E;t[16]===m?E=t[17]:(E=m?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,m]}):null,t[16]=m,t[17]=E);let D;t[18]===g?D=t[19]:(D=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,g]}):null,t[18]=g,t[19]=D);let O;t[20]===S?O=t[21]:(O=S?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:S}):null,t[20]=S,t[21]=O);let k;t[22]!==D||t[23]!==O||t[24]!==T||t[25]!==E?(k=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T,E,D,O]}),t[22]=D,t[23]=O,t[24]=T,t[25]=E,t[26]=k):k=t[26];let A;t[27]===f?A=t[28]:(A=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=A);let j;t[29]!==r||t[30]!==v||t[31]!==C||t[32]!==u?(j=C?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(rk),children:u(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:v}):null]}):null,t[29]=r,t[30]=v,t[31]=C,t[32]=u,t[33]=j):j=t[33];let M;t[34]!==g||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==b?(M=b&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&Bh(l,b,e,()=>{if(!di({sessionId:b,directory:e})){if(fl()||o||se()){s(b,e);return}c(e,{mode:`chat`,dedupeKey:`session:${b}`,label:f||g||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=g,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=b,t[43]=M):M=t[43];let N;return t[44]!==k||t[45]!==A||t[46]!==j||t[47]!==M?(N=(0,$.jsxs)(`div`,{className:`mt-2`,children:[k,A,j,M]}),t[44]=k,t[45]=A,t[46]=j,t[47]=M,t[48]=N):N=t[48],N},GO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=pc(),i=q(ik),{isMobile:a}=mo(),{t:o}=ct(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!se(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let c=!!s,l;t[3]!==n.state||t[4]!==o?(l=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=l):l=t[5];let u=l,d=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),f=n.description||d,p=J(()=>{!c||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:f,readOnly:!0})}),m;t[6]===p?m=t[7]:(m=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())},t[6]=p,t[7]=m);let h=J(m),g=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,_;t[8]===g?_=t[9]:(_=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,g),t[8]=g,t[9]=_);let v=c?`button`:void 0,y=c?0:void 0,b=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,x=c?p:void 0,S=c?h:void 0,C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=C):C=t[10];let w;t[11]===f?w=t[12]:(w=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=w);let T=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,E;t[13]===T?E=t[14]:(E=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,T),t[13]=T,t[14]=E);let D;t[15]!==u||t[16]!==E?(D=(0,$.jsx)(`span`,{className:E,children:u}),t[15]=u,t[16]=E,t[17]=D):D=t[17];let O;t[18]!==w||t[19]!==D?(O=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[w,D]}),t[18]=w,t[19]=D,t[20]=O):O=t[20];let k;t[21]===n.body?k=t[22]:(k=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)(Ns,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=k);let A;t[23]!==O||t[24]!==k?(A=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[O,k]}),t[23]=O,t[24]=k,t[25]=A):A=t[25];let j;return t[26]!==S||t[27]!==A||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==b||t[32]!==x?(j=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":b,onClick:x,onKeyDown:S,children:[C,A]}),t[26]=S,t[27]=A,t[28]=_,t[29]=v,t[30]=y,t[31]=b,t[32]=x,t[33]=j):j=t[33],j},KO={background:`transparent`,backgroundColor:`transparent`},qO=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}=ct(),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 _=J(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 ut(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=J(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)(Fc,{language:`bash`,code:u,codeStyle:KO,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(ak),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)(Fc,{language:`bash`,code:d,codeStyle:KO,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},JO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},YO=(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}},XO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=ct(),w=Tg(),T=zh(Rh()),E=q(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Vi(e):!!(VO(e)||HO(e))),[n]),j=Z.useMemo(()=>A.map(e=>Wn(e)?ES(Pn(e)):void 0),[A]),M=f?.token,N=!1,P=!!l,F=!!u,I=!!(s??a),L=!!c,R=b!==`external-actions`,z=b!==`external-content`,B=x&&b===`inline`,V=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),H=J(()=>{!I||!P||!L||typeof window>`u`||(V(),O(!0),k.current=window.setTimeout(()=>{O(!1),k.current=null},1800))});Z.useEffect(()=>{L||(O(!1),V())},[V,L]);let U=J(e=>{!l||!L||(e.stopPropagation(),e.preventDefault(),l(),I&&H())}),W=w===`mini-chat`||!T.fork?void 0:h,ee=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=nD(i,E);return e.length>0?e:null},[S,i,E]),G=Y(`group/user-actions`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),K=!_&&v&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(DO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:kO,name:`edit`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:kO,name:`close`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(_&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsx)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(DO,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??K??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(TO,`justify-end`,!a&&b===`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:[ee?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(DO,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:kO,name:`time`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(Ua,{children:ee})]}):null,m&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:kO,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(SO,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:kO,name:`edit`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:kO,name:g===`fork`?`loader-4`:`git-branch`,className:Y(SO,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:xO,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:kO,name:`check`,className:Y(SO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:kO,name:`file-copy`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:_O,onTouchStart:I&&P&&L?H:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,B?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:B?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:A.map((e,i)=>{if(VO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(WO,{part:e})},e.id??`user-subtask-${i}`);if(HO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(qO,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(GO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&Pn(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(rS,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),ZO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ct(),s=Tg(),c=Rh(),l=zh(c),{isPlaying:u,play:d,stop:f}=IE(),p=Ai(e=>e.showMessageTTSButtons),m=Ai(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=J(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=J(()=>{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=J(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=J(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=J(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=J(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=J(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(xO,!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:kO,name:`check`,className:Y(SO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:kO,name:`file-copy`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:kO,name:`target`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(xO,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:kO,name:`loader-4`,className:Y(SO,`animate-spin`)}):(0,$.jsx)(X,{weight:kO,name:`arrow-left-right`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:Y(xO,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:kO,name:`stop`,className:SO}):(0,$.jsx)(X,{weight:kO,name:`volume-up`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:j})]})]})}),QO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,messageTokens:c,isMobile:l,alwaysShowActions:u,hasTouchInput:d,expandedTools:f,onToggleTool:p,onShowPopup:m,streamPhase:h,allowAnimation:g,onContentChange:_,hasTextContent:v=!1,onCopyMessage:y,onAuxiliaryContentComplete:b,showReasoningTraces:x=!1,turnGroupingContext:S,errorMessage:C,errorVariant:w=`error`,reviewTransferDirection:T=null})=>{let{t:E,locale:D}=ct(),O=Tg(),k=zh(Rh()),A=h,j=Z.useRef(null),M=Z.useRef(null),N=h===`streaming`||h===`cooldown`,P=Z.useRef({messageId:t,experiencedStreamingOrCooldown:N});P.current.messageId===t?N&&(P.current.experiencedStreamingOrCooldown=!0):P.current={messageId:t,experiencedStreamingOrCooldown:N};let F=!!(d??l),I=!!(u??l),L=l?wO:CO,R=!i,z=Z.useMemo(()=>n.filter(e=>!Vi(e)).filter(e=>e.type!==`compaction`),[n]),B=Z.useMemo(()=>z.filter(e=>e.type===`tool`),[z]),V=Z.useMemo(()=>z.filter(e=>e.type===`text`),[z]),H=Z.useMemo(()=>Vn(V),[V]),U=q(e=>e.openContextPreview),W=se(),ee=O===`mini-chat`,G=Z.useMemo(()=>{if(W||l||ee)return null;for(let e of V){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=cc(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 B){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=cc(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},[V,l,ee,W,B]),K=ri(e=>e.forkFromMessage),te=ri(e=>e.forkTransition),ne=ri(e=>e.currentSessionId),re=ri(e=>e.getDirectoryForSession),ie=pc(),ae=T===`review-to-original`,oe=!l&&!W?T:null,ce=Z.useMemo(()=>{let t=H.trim();if(!(!e||!ie||!t||!oe))return oe===`review-to-original`?{ariaLabel:E(`chat.messageBody.actions.sendReviewFeedback`),tooltip:E(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await vn(e,ie,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:E(`chat.messageBody.actions.sendImplementationResponse`),tooltip:E(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await jt(e,ie,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[H,ie,oe,e,E]),[le,ue]=Z.useState(!1),de=q(e=>e.chatRenderMode),fe=q(e=>e.collapsibleThinkingBlocks),pe=q(e=>e.showSplitAssistantMessageActions),me=q(e=>e.showAssistantTps),he=q(e=>e.timeFormatPreference),ge=de===`sorted`,_e=S?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!C)&&(S?.isTurnSettled??!0),be=ve?`completed`:A,xe=B.length>0,Se=Z.useMemo(()=>B.some(e=>uw(e)),[B]),Ce=uw,we=lw,Te=P.current.experiencedStreamingOrCooldown,Ee=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Ee.current.messageId!==t&&(Ee.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Te||!Et())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of B){if(n.observedPartIds.has(i.id))continue;if(!Hi(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ki({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,B]);let De=Z.useMemo(()=>B.length===0||!Se&&B.every(e=>we(e)),[B,Se,we]),Oe=Z.useMemo(()=>z.filter(e=>e.type===`reasoning`),[z]),ke=Z.useMemo(()=>Oe.length===0||Oe.every(e=>typeof e.time?.end==`number`),[Oe]),Ae=typeof a!=`string`,je=Oe.length>0&&xe&&(Se||Ae||!De),Me=R||xe&&(Se||Ae||!De),Ne=R||je,Pe=xe||Oe.length>0,Fe=V.length===0,Ie=Pe&&Fe&&!Me&&!Ne&&De&&ke,Le=Z.useRef(!1),Re=Z.useRef(!1);Z.useEffect(()=>{Re.current=!1},[t]),Z.useEffect(()=>{if(!Ie){Le.current=!1;return}Le.current||(Le.current=!0,b?.())},[Ie,b]),Z.useEffect(()=>{if(R){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,_?.(`structural`)))},[R,xe,_,ke,Oe.length,Ne]);let ze=!!v&&!R,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||te)){ue(!0);try{await K(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=S?.activityParts;return!ge||!e?[]:e},[ge,S?.activityParts]),He=Z.useMemo(()=>{let e=S?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,S?.activityGroupSegments]),Ue=He.length>0,We=Z.useMemo(()=>{let e=new Map,t=new Map;return Ve.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)}}},[Ve]),Ge=S?.toggleGroup,Ke=S?.activityPresentationKind===`compaction`,qe=S?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?S?.activityOwnerMessageId===t||Ue:!S?.activityOwnerMessageId||S.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=dE(a,z),Qe={finish:a,parts:z,streamPhase:be,error:C,isLastAssistantInTurn:_e},$e=gE(Qe),et=ge&&_E(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!C,rt=w===`info`?`information`:`error-warning`,it=w===`muted`,at=ze,ot=_e&&ye&&!Je&&(v||!!C||i),st=S?.diffStats?.hasDiffs===!0,lt=!ee&&_e&&Ze&&ye&&!Je&&S?.diffStats?.hasDiffs===!0,dt=pe&&at&&!ot&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(ZO,{hasCopyableText:ze,isTouchContext:F,onCopyMessage:y,ttsText:H,reviewTransferAction:ce,sessionId:e}),[H,ze,F,y,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=Pn(e.part).trim();return t?(0,$.jsx)(ZO,{hasCopyableText:!0,isTouchContext:F,onCopyMessage:async()=>(await ut(t)).ok,ttsText:t}):null},[ge,F,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<z.length;t+=1){let n=z[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,z]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&S){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(gO,{parts:t,materializationParts:r,isExpanded:S.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:S.completionDisposition,activityPresentationKind:S.activityPresentationKind,durationMs:S.durationMs,startedAt:S.userMessageCreatedAt,onToggle:Ge,isMobile:l,expandedTools:f,onToggleTool:p,onShowPopup:m,onContentChange:_,streamPhase:be,showHeader:!0,diffStats:S.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ke&&e(`${t}:compaction-status`,[])}let r=0;for(;r<z.length;){let i=z[r];if(i.type===`text`){let a=We.get(i);if(tt){r+=1;continue}if(Je){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:M,"data-message-text-export-source":`true`,children:(0,$.jsx)(UT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:l?bO:yO,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:TO,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(We.get(i)?.kind===`reasoning`){r+=1;continue}if(!Pn(i).trim()){r+=1;continue}x&&(fe?n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(tE,{part:i,messageId:t,streamPhase:be,onContentChange:_})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(UT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(ge&&!Ye){r+=1;continue}if(We.get(i)?.kind===`tool`){r+=1;continue}if(cw(a)){let e=TD(z,r,e=>e.type!==`tool`||We.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)(OD,{activities:i,isMobile:l,isTurnLive:be!==`completed`,hasFollowingOtherType:CD(z,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return aw(n)?(0,$.jsx)(cO,{toolName:n,activities:[e],isMobile:l,animateTailText:!1},e.id):(0,$.jsx)(CT,{part:e.part,messageId:t,isExpanded:f.has(e.part.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(ow(a)){let e=kD(z,r,e=>e.type!==`tool`||We.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)(PD,{activities:i,isMobile:l,children:i.map(e=>(0,$.jsx)(cO,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:l,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(nw(a)){n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(CT,{part:e,messageId:t,isExpanded:f.has(e.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(cO,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:l,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,I,de,fe,0,f,Je,Ke,l,Ye,ge,mt,t,ft,pt,e,_,m,p,Xe,dt,be,Te,x,tt,et,Ge,S,z]),_t=Z.useMemo(()=>{if(!_e||!ye)return;let e=S?.durationMs;if(!(typeof e!=`number`||e<=0))return JO(e)},[_e,ye,S?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=nD(e,he);return t.length>0?t:null},[o,s,he,D]),yt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=YO(e,c),i=sD({createdAt:s,completedAt:o,fallbackDurationMs:S?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=cD(i);return a.length>0?a:null},[me,_e,ye,n,r,c,s,o,S?.durationMs]),bt=(0,$.jsxs)($.Fragment,{children:[!ee&&!l&&!W&&G?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":E(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ie??(ne?re(ne):null);e&&U(e,G)},children:(0,$.jsx)(X,{weight:kO,name:`global`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.openPreview`)})]}):null,!ee&&!ae&&k.fork?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,className:xO,"aria-label":E(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!te,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:kO,name:le?`loader-4`:`git-branch`,className:Y(SO,le&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:j,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:_O,children:[(0,$.jsx)(QE,{containerRef:j}),(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,nt&&(0,$.jsx)(bc,{children:it?(0,$.jsxs)(`div`,{role:`status`,className:`my-1.5 flex max-w-full items-center gap-1.5 break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`stop-circle`,className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:C})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,w===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,l?`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:[w===`info`&&l?(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:rt,weight:kO,className:Y(SO,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:w===`info`?kO:void 0,className:Y(`shrink-0`,w===`info`?Y(SO,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,w===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,l?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(Ns,{content:C??``,onShowPopup:m,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),lt&&S?.diffStats?(0,$.jsx)(BO,{fileCount:S.diffStats.files,changedFiles:S.changedFiles,turnId:S.turnId,isLatestTurn:S.isLatestTurn,isMobile:l}):null,(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:m}),ht&&(0,$.jsx)(`div`,{className:Y(l?bO:yO),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:TO,"data-message-action-group":`true`,children:ft})}),ot&&(0,$.jsxs)(`div`,{className:L,"data-message-footer":`true`,style:vO,children:[(0,$.jsxs)(`div`,{className:TO,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt?(0,$.jsxs)(`div`,{className:EO,children:[yt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,"aria-label":E(`chat.messageBody.meta.tpsAria`,{rate:yt}),children:[(0,$.jsx)(X,{weight:kO,name:`pulse`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Ua,{children:E(`chat.messageBody.meta.tpsTooltip`)})]}):null,_t?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,children:[(0,$.jsx)(X,{weight:kO,name:`hourglass`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(Ua,{children:_t})]}):null,vt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,"aria-label":`Message time: ${vt}`,children:[(0,$.jsx)(X,{weight:kO,name:`time`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Ua,{children:vt})]}):null]}):null,!ee&&_e&&ve&&!st?(0,$.jsx)(aE,{activityParts:S?.activityParts}):null]})]})]})}),$O=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)(XO,{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)(QO,{...r}),t[26]=r,t[27]=i),i});function ek(e){return e.openContextPanelTab}function tk(e){return e.setCurrentSession}function nk(e){return e.openContextPanelTab}function rk(e){return!e}function ik(e){return e.openContextPanelTab}function ak(e){return!e}var ok=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}},sk=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,ck=e=>!e,lk=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},uk=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),dk=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,fk=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,pk=`Authentication failed for this provider. Please re-authenticate and retry.`,mk=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};function hk(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:void 0,i=typeof n.message==`string`?n.message:void 0,a=typeof n.name==`string`?n.name:void 0,o=r||i||a;if(o)return a===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${o}\``,variant:`info`}:mk(o)?{text:pk,variant:`error`}:a===`MessageAbortedError`||o.trim().toLowerCase()===`aborted`?{text:t,variant:`muted`}:{text:`Opencode failed to send message with error:\n\`${o}\``,variant:`error`}}var gk=ks(()=>Ue(()=>import(`./ToolOutputDialog-CFFkJzQ4.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),_k=4e3,vk=new Map,yk=new Map,bk=new Set([`bash`,`shell`,`cmd`,`terminal`]),xk=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},Sk=e=>{let t=vk.get(e);return t?new Set(t):new Set},Ck=(e,t)=>{if(vk.size>=_k&&!vk.has(e)){let e=vk.keys().next().value;typeof e==`string`&&vk.delete(e)}vk.set(e,new Set(t))},wk=e=>{let t=yk.get(e);return t?new Set(t):new Set},Tk=(e,t)=>{if(yk.size>=_k&&!yk.has(e)){let e=yk.keys().next().value;typeof e==`string`&&yk.delete(e)}yk.set(e,new Set(t))},Ek=200,Dk=new Map,Ok=e=>Dk.get(e),kk=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=Dk.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(Dk.size>=Ek&&!Dk.has(e)){let e=Dk.keys().next().value;typeof e==`string`&&Dk.delete(e)}Dk.set(e,t)}};function Ak(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 jk=(e,t)=>{if(typeof e==`object`&&e)return e[t]},Mk=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:c=null,animateUserOnMount:l=!1,onUserAnimationConsumed:u,reviewTransferDirection:d=null})=>{let{t:f}=ct(),{isMobile:p,isTablet:m,hasTouchInput:h}=mo(),g=Rh(),_=zh(g),v=p||m,y=Z.useRef(null),b=ri(e=>e.currentSessionId),x=Zi(e=>e.getAgentModelForSession),S=Zi(e=>e.getSessionModelSelection),C=ri(e=>e.revertToMessage),w=ri(e=>e.editMessagePreservingChanges),T=ri(e=>e.forkFromMessage),E=ri(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=ri(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=ri(e=>e.clearStagedMessageEdit);Fe(`ui.chat_message.render`),s&&Fe(`ui.chat_message.render.streaming`);let k=Ai(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=q(de(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Gx.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(()=>Sk(e.info.id)),[U,W]=Z.useState(()=>wk(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(Sk(e.info.id)),W(wk(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>ok(e.info),[e.info]).isUser,te=K&&(p||!j),ne=K&&!p&&j&&!te,re=e.info.sessionID,{currentContextAgent:ie,savedSessionAgentSelection:ae}=km(de(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),oe=Z.useMemo(()=>Rn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),se=Z.useMemo(()=>K?Gi(oe):Rn(e.parts),[K,e.parts,oe]),ce=Z.useMemo(()=>{if(K||!t)return null;let e=jk(t.info,`clientRole`),n=jk(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=jk(t.info,`mode`),i=jk(t.info,`agent`),a=jk(t.info,`providerID`),o=jk(t.info,`modelID`),s=jk(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=jk(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[K,t]),le=Z.useMemo(()=>{if(K)return;let t=jk(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=jk(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(ce?.agentName)return ce.agentName;if(re)return ie||(ae??void 0)},[K,e.info,ce,re,ie,ae]),ue=K?null:jk(e.info,`providerID`),fe=K?null:jk(e.info,`modelID`),pe=Z.useMemo(()=>{if(K||!re)return null;if(ce?.providerId&&ce?.modelId)return{providerId:ce.providerId,modelId:ce.modelId};if(le){let e=x(re,le);if(e?.providerId&&e?.modelId)return e}let e=S(re);return e?.providerId&&e?.modelId?e:null},[K,re,le,ce,x,S]),me=Z.useMemo(()=>K?null:typeof ue==`string`&&ue.trim().length>0?ue:pe?.providerId??null,[K,ue,pe]),he=Z.useMemo(()=>K?null:typeof fe==`string`&&fe.trim().length>0?fe:pe?.modelId??null,[K,fe,pe]),ge=e.info.id?Ok(e.info.id):void 0;K||kk(e.info.id,{agent:le,provider:me??void 0,model:he??void 0});let _e=le??ge?.agent,ve=me??ge?.provider??null,ye=he??ge?.model??null,be=Z.useMemo(()=>{if(K)return;let e=ve&&k.length>0?k.find(e=>e.id===ve):void 0;return Si(e,ye)||void 0},[K,ve,ye,k]),xe=Z.useMemo(()=>{if(K||!me||!he)return!1;let e=k.find(e=>e.id===me);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===he)?.variants;return!!(t&&Object.keys(t).length>0)},[K,he,me,k]),Se=Ak(_e),Ce=Ak(ve??void 0),we=Ak(ye??void 0),Te=Ak(be),Ee=Se??void 0,De=Ce??null,Oe=we??null,ke=Te??void 0,Ae=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),je=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Me=Z.useMemo(()=>K?!0:!!(Ae&&Ae>0),[K,Ae]),Ne=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Pe=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]),Ie=Z.useMemo(()=>wt(se,{includeReasoning:A}),[se,A]),Le=Z.useMemo(()=>K?Ie:!Me&&M===`sorted`?[]:Ie,[M,Me,K,Ie]),Re=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`text`),[K,Ie]),ze=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`tool`),[K,Ie]),Be=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of ze){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=xk(t.tool);!r||!bk.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=xk(t.part.tool);!n||!bk.has(n)||e.add(t.id)}return e},[N,ze,a?.activityParts]),Ve=Z.useMemo(()=>{if(Be.size===0&&U.size===0)return V;let e=new Set(V);return Be.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,Be,V]),He=Z.useMemo(()=>{if(!K)return;let e=se.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,se]),Ue=K&&!hr(Le),We=typeof Ne!=`string`,Ge=Z.useMemo(()=>K?!1:Re.length===0||ze.length===0?We:!0,[Re.length,ze.length,We,K]),Ke=Z.useMemo(()=>!K&&Gx.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[qe,Je]=Z.useState(!1),Ye=Z.useMemo(()=>n?ok(n.info):null,[n]),Xe=!!a,Ze=a?.isLastAssistantInTurn??!1,Qe=dk({isWorking:a?.isWorking===!0,isInActiveTurn:s,headerCompletionDisposition:a?.completionDisposition}),$e=Z.useMemo(()=>K?!1:Xe?!Ze:Ye?!Ye.isUser&&Ye.role===`assistant`:!1,[Xe,Ze,K,Ye]),et=Z.useMemo(()=>Me?`completed`:s?c??`streaming`:`completed`,[c,s,Me]);Z.useEffect(()=>{!K||!l||u?.(e.info.id)},[l,K,e.info.id,u]),Z.useEffect(()=>{Je(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;K||!t||t!==e.info.id||(et===`streaming`||et===`cooldown`)&&Je(!0)},[o,K,e.info.id,et,a?.headerMessageId]);let tt=Z.useMemo(()=>{if(K)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?et===`completed`||qe||et===`streaming`||et===`cooldown`:!1:!0},[o,qe,K,a,et,e.info.id]),nt=Z.useCallback(e=>{ut(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),rt=K?void 0:a?.userMessageVariant??ce?.variant,it=!K&&xe&&typeof rt==`string`&&rt.trim().length>0?rt:void 0,at=Z.useMemo(()=>{if(!K)return hk(e.info?.error,f(`chat.messageBody.aborted`))},[K,e.info,f]),ot=at?.text,st=at?.variant,lt=Z.useMemo(()=>{if(K){let e=Le.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(`
|
|
6575
6575
|
|
|
6576
6576
|
`);let t=Le.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(`
|
|
6577
6577
|
`):Le.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
|
|
6578
6578
|
`).replace(/\n\s*\n+/g,`
|
|
6579
|
-
`)}return ot&&ot.trim().length>0?ot:Vn(Le)},[ot,Le,K]),dt=lt.length>0,ft=Z.useCallback(async()=>(await ut(lt)).ok?(K&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[K,lt]),pt=Z.useCallback(async()=>{if(!(!re||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(re,e.info.id,{directory:g.directory??void 0})}finally{B.current=null,z(null)}}},[re,e.info.id,C,g]),mt=J(()=>{if(!re||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(re,e.info.id,t).catch(()=>{})}),ht=J(()=>{re&&O(re)}),gt=Z.useCallback(async()=>{if(e.info.id,!re||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!re,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(re,e.info.id)}finally{B.current=null,z(null)}}},[re,e.info.id,T]),_t=J(t=>{let n=Be.has(t),r=Ve.has(t);if(n){W(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),wk(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),Sk(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),Sk(e.info.id,r),r}),W(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),wk(e.info.id,r),r})}),vt=i??null,yt=Z.useRef(!1),bt=Z.useRef(!1),xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1),Tt=Z.useRef(!1);Z.useEffect(()=>{bt.current=!1,xt.current=!1,St.current=!1,Ct.current=!1,yt.current=!1,Tt.current=!1},[e.info.id]);let Et=Z.useCallback(()=>{K||yt.current||(yt.current=!0,r?.(`structural`))},[K,r]),Dt=q(e=>e.setImagePreviewOpen),Ot=Z.useCallback(e=>{(e.image||e.mermaid)&&(G(e),Dt(!0))},[Dt]),kt=Z.useCallback(e=>{G(t=>({...t,open:e})),Dt(e)},[Dt]),At=!!Ak(e.info,`animationSettled`),jt=et===`streaming`||et===`cooldown`;jt&&(Tt.current=!0);let Mt=Z.useMemo(()=>!K&&Ie.some(e=>e.type===`reasoning`),[K,Ie]),Nt=Ke&&!At&&!jt&&!Tt.current,Pt=!K&&Ke&&Re.length>0&&!Ge;return Z.useEffect(()=>{if(vt?.onStreamingCandidate){if(!Pt){xt.current&&=(Mt&&vt?.onReasoningBlock?vt.onReasoningBlock():vt?.onReservationCancelled&&vt.onReservationCancelled(),!1);return}Ct.current||(Ct.current=!0,vt.onStreamingCandidate(),xt.current=!0)}},[vt,Pt,Mt]),Z.useEffect(()=>{vt?.onAnimationStart&&Nt&&(St.current||=(vt.onAnimationStart(),!0))},[vt,Nt]),Z.useEffect(()=>{if(K)return;let e=vt?.onAnimatedHeightChange;if(!e||!(Nt||Pt))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[Nt,K,vt,Pt]),Ue?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,K?p?`pt-2`:`pt-6`:!K&&tt?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,K||$e?`pb-0`:Qe?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:y,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:K?hr(Le)?(0,$.jsx)(bc,{forceAnimation:!0,skipAnimation:!l,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,p?void 0:`group/user-shell`),children:(0,$.jsxs)(`div`,{className:Y(`max-w-[85%]`,ne?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:`px-3 py-1.5 shadow-none border border-primary/5`,children:(0,$.jsx)(QO,{messageId:e.info.id,parts:Le,sourceParts:oe,isUser:K,isMessageCompleted:Me,messageFinish:Ne,messageCreatedAt:je??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:nt,expandedTools:V,onToggleTool:_t,onShowPopup:Ot,streamPhase:et,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:dt,onCopyMessage:ft,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Et,agentMention:He,onEdit:!E&&_.edit?mt:void 0,onRevert:!E&&_.revert?pt:void 0,onFork:!E&&K&&_.fork?gt:void 0,editing:E,editStaged:D,onCancelEdit:D?ht:void 0,pendingMessageAction:R,errorMessage:ot,errorVariant:st,userActionsMode:te?`external-content`:`inline`,stickyUserHeaderEnabled:j})}),te?(0,$.jsx)(QO,{messageId:e.info.id,parts:Le,sourceParts:oe,isUser:K,isMessageCompleted:Me,messageFinish:Ne,messageCreatedAt:je??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:nt,expandedTools:V,onToggleTool:_t,onShowPopup:Ot,streamPhase:et,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:dt,onCopyMessage:ft,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Et,agentMention:He,onEdit:!E&&_.edit?mt:void 0,onRevert:!E&&_.revert?pt:void 0,onFork:!E&&K&&_.fork?gt:void 0,editing:E,editStaged:D,onCancelEdit:D?ht:void 0,pendingMessageAction:R,errorMessage:ot,errorVariant:st,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[tt&&(0,$.jsx)(Kx,{isUser:K,isMobile:p,providerID:De,modelID:Oe,agentName:Ee,modelName:ke,variant:it}),(0,$.jsx)(QO,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Ie,sourceParts:se,isUser:K,isMessageCompleted:Me,messageFinish:Ne,messageCompletedAt:Ae??void 0,messageCreatedAt:je??void 0,messageTokens:Pe,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:nt,expandedTools:Ve,onToggleTool:_t,onShowPopup:Ot,streamPhase:et,allowAnimation:Nt,onContentChange:r,shouldShowHeader:tt,hasTextContent:dt,onCopyMessage:ft,copiedMessage:I,onAuxiliaryContentComplete:Et,showReasoningTraces:A,agentMention:He,turnGroupingContext:a,errorMessage:ot,errorVariant:st,reviewTransferDirection:d})]})})}),ee.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(hk,{popup:ee,onOpenChange:kt,isMobile:p})}):null]})},(e,t)=>JS({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&YS(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&YS(e.nextMessage?{info:e.nextMessage.info,parts:e.nextMessage.parts}:void 0,t.nextMessage?{info:t.nextMessage.info,parts:t.nextMessage.parts}:void 0)&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.reviewTransferDirection===t.reviewTransferDirection&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&rC(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,ak(e.message.info).isUser)),Mk=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},Nk=e=>{let t=e?.type;return t===`compaction`||t===`text`&&Mk(e).trim()===`/compact`},Pk=e=>e?e.some(e=>Nk(e)):!1,Fk=e=>Pk(e.parts),Ik=e=>e?Pk(e.sourceParts)||Pk(e.parts):!1,Lk=e=>{if(!Fk(e))return e;let t=!1,n=e.parts.map(e=>e?.type===`compaction`?(t=!0,{type:`text`,text:`/compact`}):e),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},Rk=e=>{let t=Rn(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},zk=new WeakMap,Bk=e=>{let t=zk.get(e);if(t)return t;let n=Lk(Rk(e)),r=n.parts,i=Qi(r),a=i===r?n:{...n,parts:i,sourceParts:r};return zk.set(e,a),a},Vk={activity:`idle`,hasWorkingContext:!1,hasActiveTools:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,lifecyclePhase:null,statusText:null,isGenericStatus:!0,isWaitingForPermission:!1,canAbort:!1,compactionDeadline:null,activePartType:void 0,activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:null,turnStartedAt:void 0},Hk=[],Uk=`\0`,Wk=new Set([`edit`,`write`,`multiedit`,`apply_patch`]),Gk={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,multiedit:`chat.assistantStatus.editingFiles`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`},Kk=[`chat.assistantStatus.working`,`chat.assistantStatus.processing`,`chat.assistantStatus.preparing`,`chat.assistantStatus.warmingUp`,`chat.assistantStatus.gearsTurning`,`chat.assistantStatus.computing`,`chat.assistantStatus.calculating`,`chat.assistantStatus.analyzing`,`chat.assistantStatus.wheelsSpinning`,`chat.assistantStatus.calibrating`,`chat.assistantStatus.synthesizing`,`chat.assistantStatus.connectingDots`,`chat.assistantStatus.inspectingLogic`,`chat.assistantStatus.weighingOptions`],qk=(e,t)=>{let n=Gk[e];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},Jk=e=>{let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)},Yk=(e,t)=>t(Kk[Jk(e)%Kk.length]??`chat.assistantStatus.working`),Xk=(e,t,n)=>{let r,i;if(!St(e))for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)switch(n.type){case`reasoning`:{let e=n.time??nA(n);(!e||e.end===void 0)&&!r&&(r=`reasoning`);break}case`tool`:{let e=n.state?.status;if((e===`running`||e===`pending`)&&!r){let e=rA(n);Wk.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=tA(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=nA(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?i===`multiedit`?qk(i,n):n(`chat.assistantStatus.editingFile`):r===`tool`&&i?qk(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):Yk(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},Zk=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(Uk),Qk=e=>{let[t,n,r=`working`,i]=e.split(Uk);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},$k=e=>e.type===`reasoning`,eA=e=>e.type===`text`,tA=e=>{if(eA(e))return e.text;let t=e;if(typeof t.text==`string`)return t.text;if(typeof t.content==`string`)return t.content;if(typeof t.value==`string`)return t.value},nA=e=>(eA(e)||$k(e),e.time),rA=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function iA(e,t){let{t:n}=ct(),r=ri(e=>e.currentSessionId),i=ri(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),c=ri(s),l=fr(a??``,o??void 0),u=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--){let t=l[e];if(t.role===`assistant`)return{id:t.id,finish:t.finish,error:t.error}}return{id:null,finish:void 0,error:void 0}},[l]),d=u.id,f=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--){let t=l[e];if(t.role===`user`)return{id:t.id,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,turnStartedAt:void 0}},[l]),p=f.id,m=ki(d??``,o??void 0,a??void 0),h=ki(p??``,o??void 0,a??void 0),g=!!p&&Pk(h),_=!!(d&&fE(u.finish,m,u.error)),v=Z.useMemo(()=>{let e=`${a??``}:${d??``}`;return Zk(Xk(d?m:Hk,e,n))},[a,d,m,n]),y=yr(a??``,o??void 0),b=ai(a??``,o??void 0),x=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),S=ri(x),{phase:C,isWorking:w}=Pg(a,o??void 0),T=Fi(a??``,o??void 0),E=T?.type===`retry`?T.attempt:void 0,D=T?.type===`retry`?T.next:void 0,O=Z.useMemo(()=>Qk(v),[v]),k=Z.useMemo(()=>{let e=!!(S&&!S.acknowledged);return{wasAborted:e,abortActive:e}},[S]),A=Z.useMemo(()=>{if(k.wasAborted)return{...Vk,wasAborted:!0,abortActive:k.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(_)return{...Vk,isComplete:!0,isTurnSettled:!0,turnStartedAt:f.turnStartedAt};let e=w,t=C===`busy`,r=C===`retry`,i=e&&g,a=`idle`;e&&(a=!i&&(O.activePartType===`tool`||O.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:E,next:D}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(O.activePartType===`tool`||O.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):O.statusText:null,isGenericStatus:!e||!i&&O.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?O.activePartType:void 0,activeToolName:e&&!i?O.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:o,turnStartedAt:f.turnStartedAt}},[C,w,_,g,f.turnStartedAt,O,k,E,D,n]);return{forming:Z.useMemo(()=>({isActive:w&&O.activePartType===`text`,characterCount:0}),[w,O.activePartType]),working:Z.useMemo(()=>{if(A.wasAborted||A.abortActive)return A;if(c)return{...A,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,isComplete:!1,isTurnSettled:!1,retryInfo:null};let e=y.length>0,t=b.length>0;return!e&&!t?A:t?{...A,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...A,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[A,c,y,b,n])}}var aA=Z.memo(()=>{let e=(0,Q.c)(14),t=Lh(),n=ri(oA),r=ri(sA),i=t.sessionId??n,a=t.directory??r??void 0,o;e[0]===i?o=e[1]:(o=e=>i?e.sessionAbortFlags?.get(i)??null:null,e[0]=i,e[1]=o);let s=ri(o),c=ri(cA),l=ri(lA),{working:u}=iA(i,a),d=Ai(uA),f=!!(s&&!s.acknowledged),p=!!(i&&c===i&&typeof l==`number`&&l>Date.now()),m=f||u.wasAborted,h=f||u.abortActive,g;return e[2]!==d||e[3]!==p||e[4]!==m||e[5]!==h||e[6]!==u.isGenericStatus||e[7]!==u.isTurnSettled||e[8]!==u.isWaitingForPermission||e[9]!==u.isWorking||e[10]!==u.retryInfo||e[11]!==u.statusText||e[12]!==u.turnStartedAt?(g=(0,$.jsx)(Hh,{isWorking:u.isWorking,statusText:u.statusText,isGenericStatus:u.isGenericStatus,isWaitingForPermission:u.isWaitingForPermission,wasAborted:m,abortActive:h,retryInfo:u.retryInfo,turnStartedAt:u.turnStartedAt,isTurnSettled:u.isTurnSettled,showAbortPrompt:p,showAssistantStatus:!0,showTodos:!1,agentName:d}),e[2]=d,e[3]=p,e[4]=m,e[5]=h,e[6]=u.isGenericStatus,e[7]=u.isTurnSettled,e[8]=u.isWaitingForPermission,e[9]=u.isWorking,e[10]=u.retryInfo,e[11]=u.statusText,e[12]=u.turnStartedAt,e[13]=g):g=e[13],g});aA.displayName=`StatusRowContainer`;function oA(e){return e.currentSessionId}function sA(e){return e.currentSessionDirectory}function cA(e){return e.abortPromptSessionId}function lA(e){return e.abortPromptExpiresAt}function uA(e){return e.currentAgentName}var dA=Z.memo(e=>{let t=(0,Q.c)(10),{assistantMessages:n,activityExpanded:r,renderMessage:i}=e,a;if(t[0]!==r||t[1]!==n||t[2]!==i){let e;t[4]!==r||t[5]!==i?(e=e=>i(e,r),t[4]=r,t[5]=i,t[6]=e):e=t[6],a=n.map(e),t[0]=r,t[1]=n,t[2]=i,t[3]=a}else a=t[3];let o;return t[7]!==r||t[8]!==a?(o=(0,$.jsx)(`div`,{className:`relative z-0`,"data-turn-assistant-activity-expanded":r,children:a}),t[7]=r,t[8]=a,t[9]=o):o=t[9],o}),fA=new Set,pA=()=>{},mA=()=>{},hA=Z.memo(e=>{let t=(0,Q.c)(32),{turn:n,activityExpanded:r,showCompactionStatus:i,pendingAssistantHeader:a,onToggleActivity:o,stickyUserHeader:s,renderMessage:c}=e,l=a===void 0?null:a,u=s===void 0||s,d=q(gA),f=n.userMessage.info.time?.created,p=n.activityPresentationKind===`compaction`,m=`turn-${n.turnId}`,h;t[0]!==r||t[1]!==p||t[2]!==c||t[3]!==u||t[4]!==n.userMessage?(h=p?null:u?(0,$.jsxs)(`div`,{className:`sticky top-0 z-20 relative bg-[var(--surface-background)] [overflow-anchor:none]`,children:[(0,$.jsx)(`div`,{className:`relative z-10`,children:c(n.userMessage,r)}),(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-full z-0 h-4 bg-gradient-to-b from-[var(--surface-background)] to-transparent sm:h-8`})]}):c(n.userMessage,r),t[0]=r,t[1]=p,t[2]=c,t[3]=u,t[4]=n.userMessage,t[5]=h):h=t[5];let g;t[6]!==d||t[7]!==l||t[8]!==u||t[9]!==n.assistantMessages?(g=l?(0,$.jsx)(`div`,{className:`group w-full ${d?u?`pt-4`:`pt-0`:`pt-6`} ${n.assistantMessages.length===0?`pb-1`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(Kx,{isUser:!1,isMobile:d,providerID:l.providerID,modelID:l.modelID,agentName:l.agentName,modelName:l.modelName,variant:l.variant})})}):null,t[6]=d,t[7]=l,t[8]=u,t[9]=n.assistantMessages,t[10]=g):g=t[10];let _;t[11]!==r||t[12]!==d||t[13]!==o||t[14]!==i||t[15]!==n.assistantMessages||t[16]!==n.completionDisposition||t[17]!==n.durationMs||t[18]!==f?(_=i?(0,$.jsx)(`div`,{className:`group w-full ${d?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(hO,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof f==`number`?f:void 0,onToggle:o,isMobile:d,expandedTools:fA,onToggleTool:pA,onShowPopup:mA,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[11]=r,t[12]=d,t[13]=o,t[14]=i,t[15]=n.assistantMessages,t[16]=n.completionDisposition,t[17]=n.durationMs,t[18]=f,t[19]=_):_=t[19];let v;t[20]!==r||t[21]!==c||t[22]!==n.assistantMessages?(v=(0,$.jsx)(dA,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:c}),t[20]=r,t[21]=c,t[22]=n.assistantMessages,t[23]=v):v=t[23];let y;return t[24]!==r||t[25]!==m||t[26]!==h||t[27]!==g||t[28]!==_||t[29]!==v||t[30]!==n.turnId?(y=(0,$.jsxs)(`section`,{className:`relative w-full`,id:m,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[h,g,_,v]}),t[24]=r,t[25]=m,t[26]=h,t[27]=g,t[28]=_,t[29]=v,t[30]=n.turnId,t[31]=y):y=t[31],y});function gA(e){return e.isMobile}var _A=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,vA=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},yA=e=>{let t=e.text;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.content;if(typeof n==`string`&&n.trim().length>0)return n},bA=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},xA=(e,t,n,r)=>({id:_A(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:vA(n)}),SA=e=>{let t=[],n=!1,r=!1;e.assistantMessages.forEach(e=>{e.parts.forEach(e=>{if(e.type===`tool`){n=!0;return}e.type===`reasoning`&&yA(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&uE(bA(t),t.parts));e.assistantMessages.forEach(n=>{let r=bA(n),a=n.parts.some(e=>e.type===`tool`);n.parts.forEach((o,s)=>{let c=o.type===`tool`,l=o.type===`reasoning`||o.type===`text`?yA(o):void 0,u=_A(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&uE(r,n.parts)&&e.summarySourceMessageId===n.info.id&&e.summarySourcePartId===u,f=null;c?f=`tool`:o.type===`reasoning`?f=`reasoning`:e.showTextJustificationActivity&&o.type===`text`&&l&&!d&&(i||a||typeof r==`string`&&r!==`stop`)&&(f=`justification`),f&&t.push({...xA(e.turnId,n.info.id,o,s),kind:f})})});let a=[];if(t.length>0){let n=e.assistantMessages[0]?.info.id;n&&a.push({id:`${e.turnId}:activity`,anchorMessageId:n,afterToolPartId:null,parts:t})}return{activityParts:t,activitySegments:a,hasTools:n,hasReasoning:r}},CA=e=>{let t=new Map,n=new Map,r=new Map,i=new Set;e.forEach(e=>{t.set(e.turnId,e);let a=e.assistantMessages[0]?.info.id,o=e.assistantMessages[e.assistantMessages.length-1]?.info.id;n.set(e.userMessageId,e.turnId),i.add(e.userMessageId),r.set(e.userMessageId,{turnId:e.turnId,messageId:e.userMessageId,userMessageId:e.userMessageId,isUserMessage:!0,isAssistantMessage:!1,isFirstAssistantInTurn:!1,isLastAssistantInTurn:!1,headerMessageId:e.headerMessageId}),e.assistantMessageIds.forEach(t=>{n.set(t,e.turnId),i.add(t),r.set(t,{turnId:e.turnId,messageId:t,userMessageId:e.userMessageId,isUserMessage:!1,isAssistantMessage:!0,isFirstAssistantInTurn:t===a,isLastAssistantInTurn:t===o,headerMessageId:e.headerMessageId})})});let a=e.length>0?e[e.length-1]:null,o=new Set;return a&&(o.add(a.userMessageId),a.assistantMessageIds.forEach(e=>{o.add(e)})),{turns:e,indexes:{turnById:t,messageToTurnId:n,messageMetaById:r},lastTurnId:a?.turnId??null,lastTurnMessageIds:o,ungroupedMessageIds:new Set}},wA=e=>{let t=e.text;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.content;if(typeof n==`string`&&n.trim().length>0)return n},TA=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(uE(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!dE(t))continue;let r=wA(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:_A(n.info.id,t,e)}}}for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||t.type!==`text`)continue;let r=wA(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:_A(n.info.id,t,e)}}}return{}},EA=e=>{let t=e.info.summary,n=t?.diffs,r=Array.isArray(n)?n:[],i=typeof t?.diffCount==`number`&&Number.isFinite(t.diffCount)?Math.max(0,Math.trunc(t.diffCount)):void 0,a=0,o=0,s=0;r.forEach(e=>{if(!e)return;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;(t!==0||n!==0)&&(s+=1),a+=t,o+=n});let c=i??s,l=t?.hasDiffs===!0||c>0||r.length>0;if(l)return{additions:a,deletions:o,files:c,hasDiffs:l}},DA=e=>{let t=e.info.summary?.diffs;if(!Array.isArray(t)||t.length===0)return;let n=t.map(e=>{if(!e||typeof e.file!=`string`||e.file.trim().length===0)return null;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;return t===0&&n===0?null:{file:e.file,additions:t,deletions:n}}).filter(e=>e!==null);return n.length>0?n:void 0},OA=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},kA=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},AA=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},jA=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},MA=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},NA=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},PA=(e,t)=>{let n=OA(e);return{messageId:e.info.id,role:n,parentMessageId:kA(e),message:e,order:t}},FA=(e,t)=>{let n=AA(e),r,i,a=!1;t.forEach(e=>{let t=jA(e);typeof t==`number`?r=Math.max(r??0,t):a=!0,e.parts.forEach(e=>{let t=MA(e);typeof t==`number`&&(i=Math.max(i??0,t))})});let o=r??i,s=typeof n==`number`&&typeof o==`number`&&o>=n?o-n:void 0;return{isStreaming:a,isRetrying:t.length>1,startedAt:n,completedAt:r,durationMs:s}},IA=e=>{if(e.length===0)return`active`;let t=e[e.length-1];if(!t)return`active`;let n=t.info.finish;if(t.info.error)return`abnormal`;if(n===`tool-calls`||lE(t.parts)>0)return`active`;if(n===`stop`)return`normal`;if(typeof n==`string`&&n.length>0)return`abnormal`;for(let t of e)if(typeof jA(t)!=`number`)return`active`;return`active`},LA=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return fE(n.finish,t.parts,n.error)},RA=e=>Ik(e)?`compaction`:`default`,zA={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},BA=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0},VA=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&BA(e.assistantMessages,t.assistantMessages),HA=(e,t)=>{e.summary=TA(e.assistantMessages),e.summaryText=e.summary.text??NA(e.userMessage),e.diffStats=EA(e.userMessage),e.changedFiles=t.showTurnChangedFiles?DA(e.userMessage):void 0,e.completionDisposition=IA(e.assistantMessages),e.hasConfirmedFinalBody=LA(e.assistantMessages),e.activityPresentationKind=RA(e.userMessage);let n=SA({turnId:e.turnId,assistantMessages:e.assistantMessages,summarySourceMessageId:e.summary.sourceMessageId,summarySourcePartId:e.summary.sourcePartId,showTextJustificationActivity:t.showTextJustificationActivity});return e.activityParts=n.activityParts,e.activitySegments=n.activitySegments,e.hasTools=n.hasTools,e.hasReasoning=n.hasReasoning,e.stream=FA(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},UA=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>HA(e,t));let r=n.turns.length===e.length,i=!1,a=e.map((e,a)=>{let o=n.indexes.turnById.get(e.turnId);return o&&VA(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,HA(e,t))});return r&&i?n.turns:a},WA=e=>{if(e.length<=1)return e;let t=!1,n=e.map((n,r)=>{if(r===e.length-1||n.completionDisposition!==`active`||(e[r+1]?.assistantMessages.length??0)===0)return n;t=!0;let i=e[r+1]?.startedAt,a=n.durationMs,o=n.completedAt;return typeof a!=`number`&&typeof n.startedAt==`number`&&typeof i==`number`&&i>=n.startedAt&&(o=i,a=i-n.startedAt),{...n,completionDisposition:`abnormal`,completedAt:o,durationMs:a,stream:{...n.stream,isStreaming:!1,completedAt:o??n.stream.completedAt,durationMs:a}}});return t?n:e},GA=(e,t)=>{let n={...zA,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(OA(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[PA(e,t)],assistantMessageIds:[],assistantMessages:[],activityParts:[],activitySegments:[],summary:{},summaryText:void 0,hasTools:!1,hasReasoning:!1,diffStats:void 0,changedFiles:void 0,stream:{isStreaming:!1,isRetrying:!1},completionDisposition:`active`,activityPresentationKind:`default`,hasConfirmedFinalBody:!1};r.push(n),i.set(n.userMessageId,n),a.add(e.info.id)}),e.forEach((e,t)=>{if(OA(e)!==`assistant`)return;let n=kA(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(PA(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=CA(WA(UA(r,n))),s=new Set;return e.forEach(e=>{OA(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},KA=30,qA=4,JA=4,YA=33554432,XA=8388608,ZA=new Map,QA=new Map,$A=0,ej=new WeakMap,tj=1,nj=()=>se()?qA:cn()?JA:KA,rj=()=>se()||cn()?XA:YA,ij=(e,t)=>{let n=e.length*2+256;for(let e of t.turns)n+=512,n+=e.messages.length*160,n+=e.activityParts.length*128,n+=(e.changedFiles?.length??0)*160,n+=(e.summaryText?.length??0)*2;return n},aj=e=>{ZA.delete(e);let t=QA.get(e)??0;QA.delete(e),$A=Math.max(0,$A-t)},oj=e=>{let t=ej.get(e);if(t!==void 0)return t;let n=tj;return tj+=1,ej.set(e,n),n},sj=e=>e.map(e=>`${oj(e.info)}:${oj(e.parts)}:${e.parts.map(e=>oj(e)).join(`,`)}`).join(`;`),cj=(e,t,n,r)=>{let i=t.length>0?t[t.length-1]:void 0,a=i?.info?.id??``,o=i?.parts?.length??0;return[e,t.length,a,o,sj(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},lj=e=>{let t=ZA.get(e);return t&&(ZA.delete(e),ZA.set(e,t)),t},uj=(e,t)=>{aj(e);let n=nj(),r=rj(),i=ij(e,t);if(!(i>r)){for(;ZA.size>=n||$A+i>r;){let e=ZA.keys().next().value;if(typeof e!=`string`)break;aj(e)}ZA.set(e,t),QA.set(e,i),$A+=i}},dj=[],fj=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0},pj=e=>{if(!e.hasLiveTail)return null;if(e.turnCount===0)return e.previousStart;let t=e.previousStart??e.turnCount-1,n=Math.min(Math.max(t,0),e.turnCount-1);return!e.liveTailActive&&e.turnCount-n>12?e.turnCount-1:n},mj=(e,t)=>t===null?{staticTurns:e,streamingTurns:dj}:{staticTurns:t===0?dj:e.slice(0,t),streamingTurns:e.slice(t)},hj=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(dj),a=Z.useRef(null),o=Z.useRef(t.sessionKey),s=Z.useRef(t.showTextJustificationActivity),c=Z.useRef(t.showTurnChangedFiles);(o.current!==t.sessionKey||s.current!==t.showTextJustificationActivity||c.current!==t.showTurnChangedFiles)&&(o.current=t.sessionKey,s.current=t.showTextJustificationActivity,c.current=t.showTurnChangedFiles,n.current=null,r.current=[],i.current=dj,a.current=null);let l=Z.useMemo(()=>{let r=cj(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=lj(r);return i?(n.current=i,i):be(`ui.turns.projection_ms`,()=>{let i=GA(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,uj(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=pj({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=mj(l.turns,u).staticTurns;return fj(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=mj(l.turns,u).streamingTurns;return fj(i.current,e)?i.current:i.current=e},[u,l.turns])}},gj=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},_j=(e,t)=>{if(!t.sessionId)return e;let n={name:`SessionRetry`,message:t.message,data:{message:t.message}},r=-1;for(let t=e.length-1;t>=0;--t)if(gj(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(gj(e[t])===`assistant`){i=t;break}if(i>=0)return e[i].info.error?e:e.map((e,t)=>t===i?{...e,info:{...e.info,error:n}}:e);let a=typeof t.confirmedAt==`number`?t.confirmedAt:t.fallbackTimestamp,o={info:{id:`synthetic_retry_notice_${t.sessionId}`,sessionID:t.sessionId,role:`assistant`,time:{created:a,completed:a},finish:`stop`,error:n},parts:[]},s=e.slice();return s.splice(r+1,0,o),s},vj=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=kt(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:Bk({...e,parts:r})},yj=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=vj(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=vj(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=GA([e.turn.userMessage,...i],{showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles}).turns[0]??{...e.turn,assistantMessages:i,assistantMessageIds:i.map(e=>e.info.id)};return{...e,turn:a}},bj=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},xj=2,Sj=2,Cj=e=>Math.min(Math.max(0,e),xj),wj=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+Sj),Tj=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(PC.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Ej=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ds.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Dj=12,Oj=16,kj=new Map,Aj=e=>{let t=kj.get(e);if(t)return kj.delete(e),kj.set(e,t),t},jj=(e,t)=>{if(t.size!==0)for(kj.delete(e),kj.set(e,t);kj.size>Oj;){let e=kj.keys().next().value;if(typeof e!=`string`)break;kj.delete(e)}},Mj=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Dj)),r=new Set;for(let t=Math.max(0,e.length-n);t<e.length;t+=1){let n=e[t];n&&r.add(n)}let i=t?.restore;if(i&&i.size>0){let t=new Set(e);for(let e of i)t.has(e)&&r.add(e)}return r},Nj=(e,t)=>{let n=t[t.length-1];if(!n||e.has(n))return e;let r=new Set(e);return r.add(n),r},Pj=({entryKeys:e,mountedIndexes:t,visibleStartIndex:n,visibleEndIndex:r,scrollDirection:i,preloadEntries:a,hydratedKeys:o})=>{if(e.length===0||t.length===0)return{visible:[],preload:[]};let s=new Set(t),c=[],l=[],u=new Set,d=(t,n)=>{if(n<0||n>=e.length||!s.has(n))return;let r=e[n];!r||o.has(r)||u.has(r)||(u.add(r),t.push(r))},f=e.length-1,p=Math.min(f,Math.max(0,Math.floor(n))),m=Math.min(f,Math.max(p,Math.floor(r)));for(let e=m;e>=p;--e)d(c,e);let h=Math.max(0,Math.floor(a)),g=()=>{let e=Math.min(f,m+h);for(let t=m+1;t<=e;t+=1)d(l,t)},_=()=>{let e=Math.max(0,p-h);for(let t=p-1;t>=e;--t)d(l,t)};return i===`backward`?(_(),g()):(g(),_()),{visible:c,preload:l}},Fj=e=>{let{visible:t,preload:n}=Pj(e),r=n.slice(0,Math.max(0,Math.floor(e.preloadReleaseLimit)));if(!e.allowVisibleRelease)return r;let i=e.visibleReleaseLimit,a=typeof i==`number`&&i>0?t.slice(0,Math.floor(i)):t;return a.length>0?[...a,...r]:r},Ij=(e,t)=>{let n=new Set(t),r=!1,i=new Set;for(let t of e)n.has(t)?i.add(t):r=!0;return r?i:e},Lj=`data-markdown-ready`,Rj=`data-markdown-hydration`,zj=`data-markdown-pin-reveal`,Bj=e=>[...Mj(e.entryKeys,{seedCount:e.seedCount,restore:e.restore})],Vj=e=>e.reason===`jump-to-latest`||!e.alreadyRevealedForScope,Hj=e=>{if(e.querySelector(`[data-markdown-hydration="deferred"]`))return!1;let t=e.querySelectorAll(`[data-markdown-content]`);if(t.length===0)return!0;for(let e of t)if(!e.closest(`[data-markdown-ready="true"]`))return!1;return!0},Uj=(e,t)=>{if(t.size===0)return!0;let n=e.querySelectorAll(`[data-turn-entry]`),r=!1;for(let e of n){let n=e.getAttribute(`data-turn-entry`);if(!(!n||!t.has(n))&&(r=!0,!Hj(e)))return!1}return r},Wj=(e,t)=>{if(e){if(t){e.style.visibility=`hidden`,e.setAttribute(zj,`pending`);return}e.style.removeProperty(`visibility`),e.setAttribute(zj,`ready`)}},Gj=(e,t)=>t?{...e,visibility:`hidden`}:e,Kj=({root:e,relevantKeys:t,onReady:n,timeoutMs:r=600,signal:i})=>{let a=!1,o=()=>{a||(a=!0,d(),n())},s=()=>{if(i?.aborted){o();return}Uj(e,t)&&o()},c=null;if(typeof MutationObserver<`u`){c=new MutationObserver(s);let t=e instanceof Element?e:e instanceof Document?e.documentElement:null;t&&c.observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[Lj,Rj,`data-turn-entry`]})}let l=null;r>0&&(l=setTimeout(o,r));let u=()=>o();i?.addEventListener(`abort`,u,{once:!0});let d=()=>{c?.disconnect(),c=null,l!==null&&(clearTimeout(l),l=null),i?.removeEventListener(`abort`,u)};return s(),queueMicrotask(s),()=>{a||(a=!0,d())}},qj=e=>{let t=new Map,n=!1,r=()=>{if(n=!1,t.size===0)return;let r=new Map(t);t.clear(),e(r)};return{enqueue(e,i){t.set(e,i),!n&&(n=!0,queueMicrotask(r))},flush:r,clear(){t.clear(),n=!1},pendingCount:()=>t.size}},Jj=e=>{let t=e.borderBoxSize?.[0];return t?{width:t.inlineSize,height:t.blockSize}:{width:e.contentRect.width,height:e.contentRect.height}},Yj=e=>{let t=qj(e),n=typeof ResizeObserver>`u`?null:new ResizeObserver(e=>{for(let n of e)t.enqueue(n.target,Jj(n))});return{observe(e){n?.observe(e)},unobserve(e){n?.unobserve(e)},disconnect(){n?.disconnect(),t.clear()}}},Xj=e=>{let t=e.resizeItem.bind(e),n=qj(e=>{for(let[n,r]of e)t(n,r)});return e.resizeItem=(e,t)=>{n.enqueue(e,t)},()=>{e.resizeItem=t,n.flush()}},Zj=({scopeKey:e,generation:t=0,root:n,relevantKeys:r,enabled:i=!0})=>{let a=`${e}:${t}`,[o,s]=Z.useState(a),[c,l]=Z.useState(i),u=Z.useRef(new Set);i&&o!==a&&(Vj({reason:t>0&&o.startsWith(`${e}:`)?`jump-to-latest`:`session-open`,alreadyRevealedForScope:u.current.has(e)})&&l(!0),s(a)),!i&&c&&l(!1);let d=r.join(`\0`),f=Z.useMemo(()=>new Set(r),[d]),p=J(()=>{u.current.add(e),l(!1)});return at(()=>{if(!i||!c){Wj(n,!1);return}if(Wj(n,!0),n)return Kj({root:n,relevantKeys:f,onReady:p})},[i,c,n,f,a]),i&&c},Qj=(e,t)=>{if(t.length===0||!Number.isFinite(e.scroll)||!Number.isFinite(e.start))return null;let n=Math.max(0,Math.min(Math.floor(e.start),t.length-1)),r=t[n];if(r===void 0)return null;let i=e.positionAtIndex(n);return i===void 0||!Number.isFinite(i)?null:{key:r,offsetFromViewportTop:i-e.scroll}},$j=(e,t)=>{let n=Qj(e,t);return n===null?null:{anchor:n,knownKeys:new Set(t)}},eM=15e3,tM=(e,t)=>{let n=e.positionByKey(t.key);return n===void 0||!Number.isFinite(n)?null:n-t.offsetFromViewportTop},nM=(e,t)=>{if(!Number.isFinite(e.scroll))return null;let n=tM(e,t);return n===null?null:e.scroll-n},rM=e=>{if(e.drift===null||e.elapsedMs>=3e3)return{action:`release`,stableFrames:0};if(Math.abs(e.drift)<=1){let t=e.stableFrames+1;return{action:t>=8?`release`:`wait`,stableFrames:t}}return{action:e.msSinceLastCorrection>=64?`correct`:`wait`,stableFrames:0}},iM=1;function aM(e,{offset:t=0,hideTopShadow:n=!1,hideBottomShadow:r=!1}={}){let i=e.scrollTop>t+iM,a=e.scrollHeight-(e.scrollTop+e.clientHeight)>t+iM,o=!n&&i;return r&&(a=!1),o&&a?(e.dataset.topBottomScroll=`true`,e.removeAttribute(`data-top-scroll`),e.removeAttribute(`data-bottom-scroll`)):(e.dataset.topScroll=String(o),e.dataset.bottomScroll=String(a),e.removeAttribute(`data-top-bottom-scroll`)),o&&a?`both`:o?`top`:a?`bottom`:`none`}function oM(e,t=48){e.dataset.scrollShadow=`true`,e.dataset.orientation=`vertical`,e.style.setProperty(`--scroll-shadow-size`,`${t}px`)}var sM=.4,cM=e=>!Number.isFinite(e)||e<=0?0:e*sM,lM=(e,t=16)=>Number.isFinite(e)&&e>0?e:t,uM=({viewportHeight:e,endInsetHeight:t=0,anchorOffset:n=16})=>!Number.isFinite(e)||e<=0?0:Math.max(0,e-(Number.isFinite(t)?Math.max(0,t):0)-n),dM=e=>{let{contentLength:t,scrollLength:n}=e;return typeof t!=`number`||typeof n!=`number`||!Number.isFinite(t)||!Number.isFinite(n)?null:Math.max(0,t-n)},fM=({anchorTop:e,anchorOffset:t=16,maxScrollOffset:n})=>{let r=Math.max(0,e-t);return typeof n!=`number`||!Number.isFinite(n)?r:Math.min(r,Math.max(0,n))},pM=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),mM=`data-oc-timeline-park-end`,hM=e=>{if(!e)return null;let t=e.getAttribute(mM);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},gM=(e,t)=>{if(!e)return;if(t===null||!Number.isFinite(t)){e.hasAttribute(`data-oc-timeline-park-end`)&&e.removeAttribute(mM);return}let n=String(Math.round(t));e.getAttribute(`data-oc-timeline-park-end`)!==n&&e.setAttribute(mM,n)},_M=(e,t)=>t!==null&&Number.isFinite(t)?pM({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),vM=({usableViewportHeight:e,viewportHeight:t,contentHeight:n})=>{if(!Number.isFinite(e)||e<=0)return 0;let r=cM(Number.isFinite(t)&&t>0?t:e),i=r>0?Math.min(e,r):e;return n===null||!Number.isFinite(n)||n<=0?i:Math.min(i,Math.max(0,e-n))},yM=(e,t)=>!Number.isFinite(e)||!Number.isFinite(t)||t<=0?!1:e>t+1,bM=({overflowsUsableViewport:e=!1,previousEndSpaceSize:t,nextEndSpaceSize:n})=>e?!0:t===void 0||n===void 0||!Number.isFinite(t)||!Number.isFinite(n)?!1:n>t+1,xM=({previous:e,reserveId:t,entryKey:n,contentHeight:r,usableViewportHeight:i,viewportHeight:a})=>{let o=vM({usableViewportHeight:i,viewportHeight:a,contentHeight:r}),s=r!==null&&yM(r,i),c={reserveId:t,entryKey:n,contentHeight:r,spacerHeight:s?0:o};return s?{snapshot:c,release:!0}:e===null||e.reserveId!==t||e.entryKey!==n?{snapshot:c,release:!1}:e.contentHeight!==null&&r!==null&&r+1<e.contentHeight&&bM({previousEndSpaceSize:e.spacerHeight,nextEndSpaceSize:o})?{snapshot:{...c,spacerHeight:0},release:!0}:{snapshot:c,release:!1}},SM=(e,t)=>{let n=e.positionAtIndex(t),r=e.sizeAtIndex(t);return typeof n!=`number`||typeof r!=`number`||!Number.isFinite(n)||!Number.isFinite(r)?null:n+Math.max(1,r)},CM=({state:e,anchorIndex:t,endInsetHeight:n,anchorOffset:r,lastIndex:i})=>{if(e.data.length===0)return null;let a=Math.max(0,Math.min(t,e.data.length-1)),o=e.positionAtIndex(a),s=SM(e,Math.max(0,Math.min(i??e.data.length-1,e.data.length-1)));if(typeof o!=`number`||!Number.isFinite(o)||s===null)return null;let c=uM({viewportHeight:e.scrollLength,endInsetHeight:n,anchorOffset:r}),l=Math.max(0,s-o),u=e.scroll+c,d=Math.max(0,s-c),f=Math.max(0,d-e.scroll);return{anchorTop:o,lastBottom:s,turnHeight:l,usableViewportHeight:c,visibleUsableBottom:u,overflowsUsableViewport:l>c,targetScrollToRevealEnd:d,scrollDeltaToRevealEnd:f}},wM=e=>{if(!e)return;let{contentLength:t,scroll:n,scrollLength:r}=e;return typeof t==`number`&&typeof n==`number`&&typeof r==`number`&&Number.isFinite(t)?t-(n+r)<=40:e.isNearEnd??e.isAtEnd},TM=e=>{if(!e)return;let{contentLength:t,scroll:n,scrollLength:r}=e;if(!(typeof t!=`number`||typeof n!=`number`||typeof r!=`number`||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)))return Math.max(0,t-(n+r))},EM=(e,t)=>e===void 0||!Number.isFinite(e)?t:e<=40?!1:e>=80||t,DM=(e,t)=>{if(e.length===0||t.length<=e.length)return!1;let n=e[0];return n===void 0||t[0]===n?!1:t.includes(n)},OM=`data-oc-timeline-anchoring`,kM=1200,AM=(e,t,n,r={})=>{if(t!==null)for(let i=e.length-1;i>=0;--i){let a=e[i];if(a!==void 0&&n(a)===t)return{anchorIndex:i,anchorOffset:r.anchorOffset??16,anchorId:t}}},jM=({sessionChanged:e,previousUserOrder:t,currentUserOrder:n,currentAnchorId:r,consumedSendMessageId:i})=>{if(i!==null)return i;if(e||r===null)return null;if(n.includes(r))return r;let a=t[t.length-1],o=n[n.length-1];return r===a&&o!==void 0&&n.length===t.length&&t.length>0?o:r},MM=(e,t)=>!Number.isFinite(t)||t<=0||typeof e!=`number`||!Number.isFinite(e)||t+1>=e?null:t,NM={itemVisiblePercentThreshold:0},PM=100,FM=116,IM=500,LM=new Set,RM=Z.createContext(LM),zM=`oc-reply-reserve`,BM=e=>e.kind===zM,VM=e=>{if(BM(e))return e.spacerHeight>0?e.spacerHeight:void 0},HM=(e,t,n,r,i)=>{if(!e||t)return null;let a=CM({state:n,anchorIndex:e.anchorIndex,lastIndex:e.anchorIndex,endInsetHeight:r,anchorOffset:i});return a?fM({anchorTop:a.anchorTop,anchorOffset:i,maxScrollOffset:dM(n)}):null},UM=(e,t)=>{if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t;let n=e?.clientHeight??0;return n>0?n:0},WM=e=>e.key,GM=e=>e.kind,KM=()=>{let e=(0,Q.c)(6),t=Z.useRef(null),n=Z.useRef(0),[r,i]=Z.useState(null),[a,o]=Z.useState(0),s;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=t.current?.offsetHeight??0;n.current=e,o(t=>t===e?t:e)},e[0]=s):s=e[0];let c=J(s),l;e[1]===c?l=e[2]:(l=e=>{t.current=e,i(t=>t===e?t:e),c()},e[1]=c,e[2]=l);let u=J(l);st(typeof ResizeObserver<`u`?r:null,c);let d;return e[3]!==a||e[4]!==u?(d={height:a,heightRef:n,setElement:u},e[3]=a,e[4]=u,e[5]=d):d=e[5],d},qM=({entry:e,index:t,renderEntryRef:n,sizeObserverRef:r})=>{let i=Z.useContext(RM),a=Z.useRef(null);return Z.useLayoutEffect(()=>{let e=a.current,t=r.current;if(!(!e||!t))return t.observe(e),()=>t.unobserve(e)},[e.key,r]),(0,$.jsx)(`div`,{ref:a,"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:n.current?.(e,t,i.has(e.key))})},JM=Z.memo(({entries:e,timelineCacheKey:t,estimatedItemSize:n,hydrationTuning:r,renderEntry:i,rowInvalidationKey:a,scrollElementRef:o,scrollElementDataset:s,hideTopScrollShadow:c=!1,hideBottomScrollShadow:l=!1,registerList:u,anchoredEndSpace:d,onAnchoredTurnParkReleased:f,followEnabled:p=!0,historyAnchorToken:m=0,pinRevealGeneration:h=0,sessionIsWorking:g=!1,onIsAtEndChange:_,onScroll:v,header:y,footer:b,className:x,style:S,contentContainerClassName:C,contentContainerStyle:w})=>{let T=Z.useRef(null),E=Z.useMemo(()=>e.map(e=>e.key),[e]),D=Z.useRef(E);D.current=E;let O=Z.useRef(r);O.current=r;let k=J(e=>{T.current=e,u?.(e)}),A=Z.useRef(null),[j,M]=Z.useState(null),[N,P]=Z.useState(0),{height:F,setElement:I}=KM(),{height:L,heightRef:R,setElement:z}=KM(),B=y==null?null:(0,$.jsx)(`div`,{ref:I,"data-oc-timeline-header":``,children:y}),V=b==null?null:(0,$.jsx)(`div`,{ref:z,"data-oc-timeline-footer":``,children:b}),H=Z.useRef(c);H.current=c;let U=Z.useRef(l);U.current=l;let W=J((e=A.current)=>{!e||s?.scrollShadow!==`true`||(oM(e),aM(e,{hideTopShadow:H.current,hideBottomShadow:U.current}))}),ee=J(e=>{let t=e?.getScrollableNode?.()??null;if(t&&s){for(let[e,n]of Object.entries(s))t.dataset[e]=n;W(t)}A.current=t,o&&(o.current=t),M(t);let n=UM(t,T.current?.getState()?.scrollLength);P(e=>e===n?e:n)}),G=J(()=>{let e=UM(A.current,T.current?.getState()?.scrollLength);P(t=>t===e?t:e),W()});Z.useLayoutEffect(()=>{W(j)},[l,c,j]),st(typeof ResizeObserver<`u`?j:null,G);let[K,te]=Z.useState(0),[ne,re]=Z.useState(0),ie=K!==ne,ae=Z.useRef(!0),oe=Z.useRef(!1),[se,ce]=Z.useState(!1),le=Z.useRef(!1);Z.useLayoutEffect(()=>{ae.current=!0,oe.current=!1,le.current=!1,ce(!1)},[t]);let[ue,de]=Z.useState(null),fe=J(e=>{de(t=>t?.token===e?null:t)});Z.useEffect(()=>{p&&de(null)},[p]),Z.useLayoutEffect(()=>{if(m<=0)return;let e=T.current;if(!e)return;let t=$j(e.getState(),D.current);t&&de({token:m,arm:t,holding:!1})},[m]),Z.useEffect(()=>{if(!ue||ue.holding)return;let{token:e}=ue,t=window.setTimeout(()=>{de(t=>t?.token===e&&!t.holding?null:t)},eM);return()=>window.clearTimeout(t)},[ue]);let pe=Z.useRef(E);Z.useLayoutEffect(()=>{let e=pe.current;pe.current=E,DM(e,E)&&(te(e=>e+1),de(e=>e===null||e.holding?e:{...e,holding:!0}))},[E]),Z.useEffect(()=>{if(!ie)return;let e=window.setTimeout(()=>{re(K)},kM);return()=>window.clearTimeout(e)},[ie,K]),Z.useEffect(()=>{if(!ue?.holding)return;let{token:e,arm:{anchor:t}}=ue,n=T.current;if(!n||typeof window>`u`){fe(e);return}let r=A.current,i=Date.now(),a=0,o=null,s=null,c=!1,l=[],u=t=>{if(!c){c=!0,s!==null&&(window.cancelAnimationFrame(s),s=null);for(let[e,t]of l)r?.removeEventListener(e,t);t&&fe(e)}},d=()=>{if(s=null,c)return;let e=n.getState();if(wM(e)??e.isAtEnd){u(!0);return}let r=Date.now(),l=rM({drift:nM(e,t),elapsedMs:r-i,stableFrames:a,msSinceLastCorrection:o===null?1/0:r-o});if(a=l.stableFrames,l.action===`release`){u(!0);return}if(l.action===`correct`){let i=tM(e,t);i!==null&&(o=r,n.scrollToOffset({offset:i,animated:!1}))}s=window.requestAnimationFrame(d)},f=()=>{u(!0)};for(let e of[`touchstart`,`touchmove`,`wheel`,`pointerdown`,`keydown`])l.push([e,f]);for(let[e,t]of l)r?.addEventListener(e,t,{passive:!0});return s=window.requestAnimationFrame(d),()=>{u(!1)}},[fe,ue]);let me=ie||ue!==null;Z.useLayoutEffect(()=>{let e=A.current;if(!(!e||!me))return e.setAttribute(OM,`true`),()=>{e.removeAttribute(OM)}},[me]);let he=Z.useMemo(()=>{if(ue===null)return{data:!0,size:ie};let{knownKeys:e}=ue.arm;return{data:!0,size:!0,shouldRestorePosition:t=>e.has(t.key)}},[ue,ie]),[ge,_e]=Z.useState(()=>Mj(E,{restore:Aj(t)??null})),ve=Z.useRef(ge);ve.current=ge;let ye=Z.useRef(0),be=Z.useRef(0),xe=Z.useRef(null),Se=Z.useRef(!1),Ce=Z.useRef(null),we=Z.useMemo(()=>Nj(ge,E),[ge,E]),Te=Gj(S,Zj({scopeKey:t,generation:h,root:j,relevantKeys:Z.useMemo(()=>Bj({entryKeys:E}),[t,h,E.length,E[E.length-1]]),enabled:E.length>0}));Z.useEffect(()=>{_e(e=>Ij(e,E))},[E]),Z.useEffect(()=>()=>{jj(t,ve.current)},[t]);let Ee=J(()=>{Se.current=!1;let e=T.current;if(!e)return;let t=D.current;if(t.length===0)return;let n=e.getState(),r=t.length-1,i=Math.max(0,Math.floor(n.startBuffered)),a=Math.min(r,Math.floor(n.endBuffered));if(!Number.isFinite(i)||!Number.isFinite(a)||a<i)return;let o=[];for(let e=i;e<=a;e+=1)o.push(e);let s=Math.max(0,Math.floor(n.start)),c=Math.min(r,Math.floor(n.end)),l=Math.max(0,c-s+1),u=Date.now()-ye.current>=PM,d=O.current,f=d.resolvePreloadEntries(l),p=Fj({entryKeys:t,mountedIndexes:o,visibleStartIndex:s,visibleEndIndex:c,scrollDirection:xe.current,preloadEntries:f,hydratedKeys:ve.current,allowVisibleRelease:u,preloadReleaseLimit:u?f:d.resolvePreloadReleaseWhileScrolling(),visibleReleaseLimit:d.resolveVisibleReleaseLimit()});p.length!==0&&(Oe(),Z.startTransition(()=>{_e(e=>{let t=!1,n=new Set(e);for(let e of p)n.has(e)||(n.add(e),t=!0);return t?n:e})}))}),De=J(()=>{Se.current||(Se.current=!0,vc(Ee))}),Oe=J(()=>{typeof window>`u`||(Ce.current!==null&&window.clearTimeout(Ce.current),Ce.current=window.setTimeout(()=>{Ce.current=null,De()},FM))});Z.useEffect(()=>()=>{Ce.current!==null&&(window.clearTimeout(Ce.current),Ce.current=null)},[]);let ke=J(()=>{De()}),Ae=J(()=>{ye.current=Date.now();let e=T.current;if(e){let t=e.getState(),n=t.scroll;Number.isFinite(n)&&n!==be.current&&(xe.current=n>be.current?`forward`:`backward`,be.current=n);let r=UM(A.current,t.scrollLength);r>0&&P(e=>e===r?e:r);let i=HM(qe.current,Fe.current,t,R.current,Ye.current);gM(A.current,i);let a=i===null?null:pM({scroll:t.scroll,parkOffset:i}),o=a??TM(t),s=a===null?wM(t)??t.isAtEnd:a<=40,c=EM(o,oe.current);(s!==ae.current||c!==oe.current)&&(ae.current=s,oe.current=c,_?.(s,c)),s&&!le.current&&(le.current=!0,ce(!0))}v?.(),W(),De(),Oe()}),je=Z.useRef(i);je.current=i;let[Me,Ne]=Z.useState(null),Pe=Z.useRef(null),Fe=Z.useRef(!1),Ie=Z.useRef(null),Le=Z.useRef(null),Re=Z.useRef(0),ze=Z.useRef(0),q=Z.useRef(null),Be=J((e,t)=>{let n=T.current,r=n?.getState().sizes.get(e);if(n&&MM(r,t.height)!==null&&n.setItemSize(e,t),Fe.current||e!==Le.current)return;let i=Ie.current;if(i===null)return;let{snapshot:a,release:o}=xM({previous:Pe.current,reserveId:i,entryKey:e,contentHeight:t.height,usableViewportHeight:Re.current,viewportHeight:ze.current});if(o){Ne(null),ot(i),ct(`reveal`);return}let s=Pe.current;(s?.spacerHeight!==a.spacerHeight||s?.contentHeight!==a.contentHeight||s?.entryKey!==a.entryKey||s?.reserveId!==a.reserveId)&&Ne(a),q.current!==i&&ct(`park`)&&(q.current=i)}),Ve=Z.useRef(Be);Ve.current=Be;let He=Z.useMemo(()=>Yj(e=>{for(let[t,n]of e){let e=t instanceof HTMLElement?t.dataset.turnEntry:void 0;e&&n.height>0&&Ve.current(e,n)}}),[]),Ue=Z.useRef(He);Ue.current=He,Z.useEffect(()=>()=>{He.disconnect()},[He]);let We=Z.useMemo(()=>({item:e,index:t})=>BM(e)?(0,$.jsx)(`div`,{"data-oc-reply-reserve":`true`,"aria-hidden":`true`,style:{height:e.spacerHeight,flexShrink:0}}):(0,$.jsx)(qM,{entry:e,index:t,renderEntryRef:je,sizeObserverRef:Ue}),[]),Ge=Z.useRef(p);Ge.current=p;let Ke=Z.useRef(ue);Ke.current=ue;let qe=Z.useRef(d);qe.current=d;let Je=Z.useRef(0),Ye=Z.useRef(16),Xe=Z.useRef(null),[Ze,Qe]=Z.useState(null),$e=d?e[d.anchorIndex]?.key??null:null,et=d?.anchorId??$e,tt=et!==null&&Ze===et;d||(q.current=null,Je.current=0);let nt=N>0?N:UM(A.current,T.current?.getState()?.scrollLength),rt=lM(F),it=uM({viewportHeight:nt,endInsetHeight:L,anchorOffset:rt}),at=Me;if(!et||!$e||tt)Me!==null&&Ne(null),at=null;else if(it<=0)at=Me!==null&&Me.reserveId===et&&Me.entryKey===$e?Me:null;else if(Me===null||Me.reserveId!==et||Me.entryKey!==$e){let{snapshot:e}=xM({previous:Me?.reserveId===et?Me:null,reserveId:et,entryKey:$e,contentHeight:Me?.reserveId===et?Me.contentHeight:null,usableViewportHeight:it,viewportHeight:nt});Ne(e),at=e}Pe.current=at,Fe.current=tt,Ie.current=et,Le.current=$e,Re.current=it,ze.current=nt,Ye.current=rt,Z.useLayoutEffect(()=>{q.current=null,Je.current=0,Xe.current=null,Qe(null)},[t]),Z.useLayoutEffect(()=>{d&&G()},[d]);let ot=J(e=>{e!==null&&Xe.current!==e&&(Xe.current=e,Qe(e),f?.(e))}),ct=J(t=>{let n=qe.current;if(!n||Ke.current)return!1;let r=T.current;if(!r)return!1;let i=r.getState(),a=Ye.current,o=CM({state:i,anchorIndex:n.anchorIndex,lastIndex:n.anchorIndex,endInsetHeight:R.current,anchorOffset:a});if(!o)return!1;if(t===`park`){let e=Math.max(0,o.anchorTop-a),t=typeof performance<`u`?performance.now():Date.now(),n=!(typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)&&Math.abs(i.scroll-e)>=1;return n&&(Je.current=t+IM),r.scrollToOffset({offset:e,animated:n}),!0}return yM(o.turnHeight,Re.current)&&ot(n.anchorId??e[n.anchorIndex]?.key??null),(typeof performance<`u`?performance.now():Date.now())<Je.current||!Ge.current||o.scrollDeltaToRevealEnd<1?!1:(r.scrollToOffset({offset:o.targetScrollToRevealEnd,animated:!1}),!0)});Z.useLayoutEffect(()=>{if(!et||!$e||tt||it<=0)return;let e=Pe.current;if(e===null||e.reserveId!==et||e.entryKey!==$e)return;let{snapshot:t,release:n}=xM({previous:e,reserveId:et,entryKey:$e,contentHeight:e.contentHeight,usableViewportHeight:it,viewportHeight:nt});if(n){Ne(null),ot(et),ct(`reveal`);return}t.spacerHeight!==e.spacerHeight&&Ne(t)},[$e,tt,et,nt,it]),Z.useLayoutEffect(()=>{!at||ue||q.current!==et&&ct(`park`)&&(q.current=et)},[at,ue,et]),Z.useLayoutEffect(()=>{let e=A.current,t=T.current;if(e){if(!t){gM(e,null);return}gM(e,HM(d,tt,t.getState(),L,rt))}},[d,L,rt,tt]);let lt=Z.useMemo(()=>{let t=at?.spacerHeight??0;return!at||t<=0?e:[...e,{key:`${zM}:${at.reserveId}`,kind:zM,spacerHeight:t}]},[at,e]),ut=Z.useMemo(()=>d&&!tt||!p||ue?!1:{animated:g&&se,on:{dataChange:!0,itemLayout:!0,layout:!0,footerLayout:!0}},[d,se,p,ue,tt,g]);return(0,$.jsx)(RM.Provider,{value:we,children:(0,$.jsx)(nl,{ref:k,refScrollView:ee,data:lt,extraData:a,keyExtractor:WM,getItemType:GM,getFixedItemSize:VM,renderItem:We,estimatedItemSize:n,initialScrollAtEnd:!0,recycleItems:!1,maintainScrollAtEnd:ut,maintainVisibleContentPosition:he,onScroll:Ae,onViewableItemsChanged:ke,viewabilityConfig:NM,ListHeaderComponent:B,ListFooterComponent:V,className:x,style:Te,contentContainerClassName:C,contentContainerStyle:w})})}),YM=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},XM=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},ZM=e=>!e||YM(e)!==`user`?!1:e.parts.some(e=>{if(e?.type!==`text`)return!1;let t=e.text;return e.synthetic===!0&&typeof t==`string`&&t.trim().startsWith(`The following tool was executed by the user`)}),QM=(e,t)=>{if(YM(e)!==`assistant`||t&&XM(e)!==t||e.parts.length!==1)return{hide:!1,details:null};let n=e.parts[0];return n?.type!==`tool`||(typeof n.tool==`string`?n.tool.toLowerCase():``)!==`bash`?{hide:!1,details:null}:{hide:!0,details:{command:typeof n.state?.input?.command==`string`?n.state.input.command:void 0,output:(typeof n.state?.output==`string`?n.state.output:void 0)??(typeof n.state?.metadata?.output==`string`?n.state.metadata.output:void 0),status:typeof n.state?.status==`string`?n.state.status:void 0}}},$M=(e,t)=>{let n=e[t];if(!n)return null;let r=n.info.id;for(let n=t+1;n<e.length;n+=1){let t=e[n];if(YM(t)===`user`)break;let{hide:i,details:a}=QM(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},eN=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},tN=(e,t)=>{if(e.length===0)return[];if(e.filter(eN).length===e.length)return e;if(t){let n=e.findIndex(e=>e.info.id===t);if(n>=0)return e.slice(0,n+1)}return e},nN=e=>{if(e.chatRenderMode!==`sorted`)return null;let t=e.streamingAssistantMessageId;if(!t)return null;let n=e.assistants.find(e=>e.info.id===t);if(!n)return null;let r=n.info,i=mE({finish:r.finish,isMessageCompleted:eN(n),activeStreamingPhase:e.activeStreamingPhase});return hE({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},rN=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},iN=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=rN(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},aN=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},oN=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=aN(t.mode)??aN(t.agent),r=aN(t.providerID),i=aN(t.modelID),a=aN(t.model?.variant)??aN(t.variant);return!n&&!r&&!i&&!a?null:{agentName:n,providerId:r,modelId:i,variant:a}},sN=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:Si(void 0,t)||void 0,variant:e?.variant}},cN=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),lN=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:ok(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),uN=5,dN=[],fN=new Set,pN=[],mN=16,hN=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),gN=320,_N=168,vN=8,yN=16,bN=6,xN=12,SN=4,CN=1,wN=2,TN=6,EN=4,DN=()=>cn()?yN:vN,ON=30,kN=180,AN=5,jN=2,MN=120,NN=1200,PN=80,FN=160,IN=1500,LN=1.5,RN=90,zN=(e,t)=>{if(e.length===0||t.length<=e.length||e[e.length-1]?.key!==t[t.length-1]?.key)return!1;let n=e[0]?.key;return t.findIndex(e=>e.key===n)>0},BN=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(hN(r.keys,n))return r.items;t.delete(e)}},write:(n,r,i)=>{if(r.length!==0)for(t.delete(n),t.set(n,{keys:r.slice(),items:i});t.size>e;){let e=t.keys().next().value;if(typeof e!=`string`)break;t.delete(e)}}}})(mN),VN=(e,t,n)=>{if(t.size===0)return[];let r=0;return e.map((e,i)=>{let a=t.get(e)??n,o={index:i,key:e,start:r,size:a,end:r+a,lane:0};return r+=a,o})},HN=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),UN=e=>e===`collapsed`?_N:gN,WN=(e,t)=>`${e}::activity:${t}`,GN=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),KN=(e,t,n)=>{let r=Number.isFinite(e)?Math.max(0,e):0,i=Number.isFinite(t)?Math.max(r,t):r,a=Number.isFinite(n)?Math.max(0,n):0;return{paddingTop:r,paddingBottom:Math.max(0,a-i),minHeight:a}},qN=(e,t)=>{if(!e)return;let n=`${Math.max(0,Number.isFinite(t)?t:0)}px`;e.style.height!==``&&(e.style.height=``),e.style.minHeight!==n&&(e.style.minHeight=n)},JN=(e,t=0)=>Math.max(e===`collapsed`?xN:bN,Math.max(0,Math.floor(t))),YN=e=>e===`collapsed`?wN:CN,XN=e=>e===`collapsed`?EN:TN,ZN=e=>e===`collapsed`?jN:AN,QN=(e,t)=>{e.current=t},$N=(e,t)=>BN.read(e,t),eP=(e,t,n)=>{!n||t.length===0||BN.write(e,t,n.takeSnapshot())},tP=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},nP=(e,t)=>{if(tP(e)!==`system`)return e;let n=aP(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},rP=e=>!e||tP(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),iP=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},aP=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},oP=(e,t,n)=>{if(typeof window>`u`)return!1;let r=e;for(;r&&r!==t;){if(window.getComputedStyle(r).position===`sticky`&&r.getBoundingClientRect().top<=n+1)return!0;r=r.parentElement}return!1},sP=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,cP=(e,t=e)=>{let n=e.getBoundingClientRect(),r=Array.from(t.querySelectorAll(`[data-message-id]`)),i=r.find(t=>t.getBoundingClientRect().bottom>n.top+1&&!oP(t,e,n.top))??r.find(e=>e.getBoundingClientRect().bottom>n.top+1),a=i?.dataset.messageId;return!i||!a?null:{messageId:a,offsetTop:i.getBoundingClientRect().top-n.top}},lP=(e,t)=>{let n=cP(t,e);if(!n)return null;let r=sP(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},uP=e=>{let t=e,n=t.state?.metadata,r=pS(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?_S(i)??null:null},dP=e=>{if(tP(e)!==`assistant`||e.parts.length!==1)return{hide:!1,taskSessionId:null};let t=e.parts[0];return t?.type!==`tool`||(typeof t.tool==`string`?t.tool.toLowerCase():``)!==`task`?{hide:!1,taskSessionId:null}:{hide:!0,taskSessionId:uP(e.parts[0])}},fP=(e,t)=>{if(!t)return e;let n=mS(e.parts,t);return n===e.parts?e:{...e,parts:n}},pP=(e,t)=>{let n=typeof t?.command==`string`?t.command.trim():``,r=typeof t?.output==`string`?t.output:``,i=typeof t?.status==`string`?t.status.trim():``,a=[],o=!1;for(let t of e.parts){if(!o&&t?.type===`text`){let e=t.text;if(t.synthetic===!0&&typeof e==`string`&&e.trim().startsWith(`The following tool was executed by the user`)){a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),o=!0;continue}}a.push(t)}return o||a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),{...e,parts:a}},mP=e=>e.kind===`turn`?e.turn.userMessage.info.id:tP(e.message)===`user`?e.message.info.id:null,hP=e=>e.chatRenderMode!==`sorted`||e.activityPresentationKind!==`compaction`||e.hasVisibleActivitySegments||e.hasAssistantMessages?!1:e.completionDisposition===`normal`||e.completionDisposition===`abnormal`||e.completionDisposition===`active`&&e.isLastTurn&&e.sessionIsWorking,gP=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,reviewTransferDirection:m}=e,h=Lh(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:h,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=h,t[3]=g):g=t[3];let _=g,v;t[4]!==c||t[5]!==l||t[6]!==f||t[7]!==o||t[8]!==s||t[9]!==n||t[10]!==i||t[11]!==d||t[12]!==u||t[13]!==r||t[14]!==m||t[15]!==p||t[16]!==a?(v=(0,$.jsx)(jk,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,reviewTransferDirection:m}),t[4]=c,t[5]=l,t[6]=f,t[7]=o,t[8]=s,t[9]=n,t[10]=i,t[11]=d,t[12]=u,t[13]=r,t[14]=m,t[15]=p,t[16]=a,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Ih.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return JS(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&YS(e.previousMessage,t.previousMessage)&&YS(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&rC(n,r,e.message.info.id,tP(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.reviewTransferDirection===t.reviewTransferDirection&&e.animationHandlers?.onChunk===t.animationHandlers?.onChunk&&e.animationHandlers?.onComplete===t.animationHandlers?.onComplete&&e.animationHandlers?.onStreamingCandidate===t.animationHandlers?.onStreamingCandidate&&e.animationHandlers?.onAnimationStart===t.animationHandlers?.onAnimationStart&&e.animationHandlers?.onReservationCancelled===t.animationHandlers?.onReservationCancelled&&e.animationHandlers?.onReasoningBlock===t.animationHandlers?.onReasoningBlock&&e.animationHandlers?.onAnimatedHeightChange===t.animationHandlers?.onAnimatedHeightChange});gP.displayName=`MessageRow`;var _P=Z.memo(e=>{let t=(0,Q.c)(109),{turn:n,isLastTurn:r,sessionIsWorking:i,activityRenderMode:a,turnUiStates:o,onToggleTurnGroup:s,chatRenderMode:c,onMessageContentChange:l,getAnimationHandlers:u,scrollToBottom:d,stickyUserHeader:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_}=e,v=f===void 0||f,y;t[0]!==n.turnId||t[1]!==o?(y=o.get(n.turnId),t[0]=n.turnId,t[1]=o,t[2]=y):y=t[2];let b=y,x;if(t[3]!==a||t[4]!==r||t[5]!==i||t[6]!==n.assistantMessages.length||t[7]!==n.completionDisposition||t[8]!==n.durationMs||t[9]!==n.hasConfirmedFinalBody){let e=ck({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=lN({expansionDisposition:dk({isLastTurn:r,turnCompletionDisposition:n.completionDisposition,headerPresentationDisposition:e.completionDisposition,hasAssistantMessages:n.assistantMessages.length>0}),activityRenderMode:a,isLastTurn:r,isActivelyProcessing:r&&i,hasConfirmedFinalBody:n.hasConfirmedFinalBody}),t[3]=a,t[4]=r,t[5]=i,t[6]=n.assistantMessages.length,t[7]=n.completionDisposition,t[8]=n.durationMs,t[9]=n.hasConfirmedFinalBody,t[10]=x}else x=t[10];let S=x,C=b?b.isExpanded:S,w;t[11]!==S||t[12]!==s||t[13]!==n.turnId?(w=()=>{s(n.turnId,S)},t[11]=S,t[12]=s,t[13]=n.turnId,t[14]=w):w=t[14];let T=J(w),E;if(t[15]!==n.assistantMessages||t[16]!==n.userMessage){let e=[n.userMessage,...n.assistantMessages],r=new Map;e.forEach((e,t)=>{r.set(e.info.id,t)}),E={ordered:e,lookup:r},t[15]=n.assistantMessages,t[16]=n.userMessage,t[17]=E}else E=t[17];let D=E,O;bb0:{if(h&&n.assistantMessages.some(e=>e.info.id===h)){O=h;break bb0}for(let e=n.assistantMessages.length-1;e>=0;--e){let t=n.assistantMessages[e];if(!eN(t)){O=t.info.id;break bb0}}O=null}let k=O,A;t[18]!==g||t[19]!==c||t[20]!==k||t[21]!==n.assistantMessages?(A=nN({chatRenderMode:c,assistants:n.assistantMessages,streamingAssistantMessageId:k,activeStreamingPhase:g}),t[18]=g,t[19]=c,t[20]=k,t[21]=n.assistantMessages,t[22]=A):A=t[22];let j=A,M;bb1:{if(c===`live`){M=n.assistantMessages;break bb1}let e;t[23]!==k||t[24]!==n.assistantMessages?(e=tN(n.assistantMessages,k),t[23]=k,t[24]=n.assistantMessages,t[25]=e):e=t[25],M=e}let N=M,P;t[26]===N?P=t[27]:(P=new Map,N.forEach((e,t)=>{P.set(e.info.id,t)}),t[26]=N,t[27]=P);let F=P,I;t[28]===N?I=t[29]:(I=new Set(N.map(EP)),t[28]=N,t[29]=I);let L=I,R=N[0]?.info.id,z;bb2:{if(c!==`sorted`){z=n.activityParts;break bb2}let e;t[30]!==n.activityParts||t[31]!==n.assistantMessages.length||t[32]!==L?(e=L.size===n.assistantMessages.length?n.activityParts:n.activityParts.filter(e=>L.has(e.messageId)),t[30]=n.activityParts,t[31]=n.assistantMessages.length,t[32]=L,t[33]=e):e=t[33];let r=e,i;t[34]!==j||t[35]!==r?(i=rN(r,j),t[34]=j,t[35]=r,t[36]=i):i=t[36],z=i}let B=z,V;bb3:{if(c!==`sorted`){V=n.activitySegments;break bb3}if(j){let e;t[37]!==j||t[38]!==n.activitySegments?(e=iN(n.activitySegments,j),t[37]=j,t[38]=n.activitySegments,t[39]=e):e=t[39],V=e;break bb3}if(L.size===n.assistantMessages.length){V=n.activitySegments;break bb3}let e;if(t[40]!==n.activitySegments||t[41]!==L){let r;t[43]===L?r=t[44]:(r=e=>{let t=e.parts.filter(e=>L.has(e.messageId));if(t.length===0)return null;let n=L.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null},t[43]=L,t[44]=r),e=n.activitySegments.map(r).filter(DP),t[40]=n.activitySegments,t[41]=L,t[42]=e}else e=t[42];V=e}let H=V,U=n.userMessage.info.time?.created,W=n.userMessage.info,ee=W?.model?.variant??W?.variant,G=typeof ee==`string`&&ee.trim().length>0?ee:void 0,K=typeof U==`number`?U:void 0,te;t[45]!==K||t[46]!==n.activityPresentationKind||t[47]!==n.changedFiles||t[48]!==n.diffStats||t[49]!==n.hasReasoning||t[50]!==n.hasTools||t[51]!==n.headerMessageId||t[52]!==n.summaryText||t[53]!==n.turnId||t[54]!==G||t[55]!==B||t[56]!==H?(te={turnId:n.turnId,summaryBody:n.summaryText,activityParts:B,activityGroupSegments:H,headerMessageId:n.headerMessageId,hasTools:n.hasTools,hasReasoning:n.hasReasoning,activityPresentationKind:n.activityPresentationKind,diffStats:n.diffStats,changedFiles:n.changedFiles,userMessageCreatedAt:K,userMessageVariant:G},t[45]=K,t[46]=n.activityPresentationKind,t[47]=n.changedFiles,t[48]=n.diffStats,t[49]=n.hasReasoning,t[50]=n.hasTools,t[51]=n.headerMessageId,t[52]=n.summaryText,t[53]=n.turnId,t[54]=G,t[55]=B,t[56]=H,t[57]=te):te=t[57];let ne=te,re;t[58]!==g||t[59]!==R||t[60]!==c||t[61]!==u||t[62]!==T||t[63]!==r||t[64]!==D.lookup||t[65]!==D.ordered||t[66]!==l||t[67]!==m||t[68]!==_||t[69]!==d||t[70]!==i||t[71]!==p||t[72]!==k||t[73]!==n.activityPresentationKind||t[74]!==n.completionDisposition||t[75]!==n.durationMs||t[76]!==n.hasConfirmedFinalBody||t[77]!==n.hasReasoning||t[78]!==n.hasTools||t[79]!==n.headerMessageId||t[80]!==n.turnId||t[81]!==n.userMessage||t[82]!==ne||t[83]!==H||t[84]!==F||t[85]!==N[0]?.info.id||t[86]!==N.length?(re=(e,t)=>{let a=tP(e)===`user`,o=D.lookup.get(e.info.id),s=F.get(e.info.id)??-1,f=s>=0,h=s===0,v=s===N.length-1,y=!!R&&e.info.id===R,b=H.some(t=>t.anchorMessageId===e.info.id),x=c===`sorted`?f:y||h||v,S=N[0]?.info.id??n.headerMessageId,C=a?void 0:f?h?n.userMessage:void 0:typeof o==`number`&&o>0?D.ordered[o-1]:void 0,w=ck({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs}),E=f?{turnId:n.turnId,activityOwnerMessageId:R,isFirstAssistantInTurn:h,isLastAssistantInTurn:v,isLatestTurn:r,isWorking:(r||n.completionDisposition===`active`)&&i&&(c===`sorted`?b:e.info.id===k),isTurnSettled:lk({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,hasConfirmedSettledAssistant:n.hasConfirmedFinalBody}),hasTools:n.hasTools,hasReasoning:n.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:n.activityPresentationKind,durationMs:w.durationMs,...x?{summaryBody:ne.summaryBody,activityParts:ne.activityParts,activityGroupSegments:ne.activityGroupSegments,headerMessageId:ne.headerMessageId,diffStats:ne.diffStats,changedFiles:ne.changedFiles,userMessageCreatedAt:ne.userMessageCreatedAt,userMessageVariant:ne.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(gP,{message:e,previousMessage:C,nextMessage:void 0,turnGroupingContext:E,assistantHeaderMessageId:S,isInActiveTurn:!!k&&e.info.id===k,activeStreamingPhase:e.info.id===k?g:null,reviewTransferDirection:_,animateUserOnMount:p(e),onUserAnimationConsumed:m,onContentChange:l,animationHandlers:u(e.info.id),scrollToBottom:d},e.info.id)},t[58]=g,t[59]=R,t[60]=c,t[61]=u,t[62]=T,t[63]=r,t[64]=D.lookup,t[65]=D.ordered,t[66]=l,t[67]=m,t[68]=_,t[69]=d,t[70]=i,t[71]=p,t[72]=k,t[73]=n.activityPresentationKind,t[74]=n.completionDisposition,t[75]=n.durationMs,t[76]=n.hasConfirmedFinalBody,t[77]=n.hasReasoning,t[78]=n.hasTools,t[79]=n.headerMessageId,t[80]=n.turnId,t[81]=n.userMessage,t[82]=ne,t[83]=H,t[84]=F,t[85]=N[0]?.info.id,t[86]=N.length,t[87]=re):re=t[87];let ie=bj(re),ae;bb4:{if(N===n.assistantMessages){ae=n;break bb4}let e;t[88]!==n||t[89]!==N?(e={...n,assistantMessages:N},t[88]=n,t[89]=N,t[90]=e):e=t[90],ae=e}let oe=ae,se;bb5:{if(!cN({isLastTurn:r,sessionIsWorking:i,hasAssistantMessages:n.assistantMessages.length>0,activityPresentationKind:n.activityPresentationKind,hasActiveStreamingMessage:!!h})){se=null;break bb5}let e;t[91]===n.userMessage.info?e=t[92]:(e=sN(oN(n.userMessage.info)),t[91]=n.userMessage.info,t[92]=e),se=e}let ce=se,le=H.length>0,ue=n.assistantMessages.length>0,de;t[93]!==c||t[94]!==r||t[95]!==i||t[96]!==le||t[97]!==ue||t[98]!==n.activityPresentationKind||t[99]!==n.completionDisposition?(de=hP({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:le,hasAssistantMessages:ue,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[93]=c,t[94]=r,t[95]=i,t[96]=le,t[97]=ue,t[98]=n.activityPresentationKind,t[99]=n.completionDisposition,t[100]=de):de=t[100];let fe;return t[101]!==T||t[102]!==C||t[103]!==ce||t[104]!==ie||t[105]!==oe||t[106]!==v||t[107]!==de?(fe=(0,$.jsx)(hA,{turn:oe,activityExpanded:C,onToggleActivity:T,showCompactionStatus:de,pendingAssistantHeader:ce,stickyUserHeader:v,renderMessage:ie}),t[101]=T,t[102]=C,t[103]=ce,t[104]=ie,t[105]=oe,t[106]=v,t[107]=de,t[108]=fe):fe=t[108],fe});_P.displayName=`TurnBlock`;var vP=Z.memo(e=>{let t=(0,Q.c)(31),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d,reviewTransferDirection:f}=e,{t:p}=ct();if(Fr(n)){let e;t[0]===p?e=t[1]:(e=p(`assistants.conversation.newSessionDivider`),t[0]=p,t[1]=e);let n;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[2]=n):n=t[2];let r;t[3]===p?r=t[4]:(r=p(`assistants.conversation.newSessionDivider`),t[3]=p,t[4]=r);let i;t[5]===r?i=t[6]:(i=(0,$.jsx)(`span`,{className:`shrink-0 typography-meta text-muted-foreground`,children:r}),t[5]=r,t[6]=i);let a;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[7]=a):a=t[7];let o;t[8]===i?o=t[9]:(o=(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[n,i,a]}),t[8]=i,t[9]=o);let s;return t[10]!==e||t[11]!==o?(s=(0,$.jsx)(`div`,{className:`chat-message-column px-4 py-5`,role:`separator`,"aria-label":e,children:o}),t[10]=e,t[11]=o,t[12]=s):s=t[12],s}let m;t[13]!==n||t[14]!==c?(m=c(n),t[13]=n,t[14]=c,t[15]=m):m=t[15];let h;t[16]!==o||t[17]!==n.info.id?(h=o(n.info.id),t[16]=o,t[17]=n.info.id,t[18]=h):h=t[18];let g=!!u&&n.info.id===u,_=n.info.id===u?d:null,v;return t[19]!==n||t[20]!==i||t[21]!==a||t[22]!==l||t[23]!==r||t[24]!==f||t[25]!==s||t[26]!==m||t[27]!==h||t[28]!==g||t[29]!==_?(v=(0,$.jsx)(gP,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:m,onUserAnimationConsumed:l,onContentChange:a,animationHandlers:h,scrollToBottom:s,isInActiveTurn:g,activeStreamingPhase:_,reviewTransferDirection:f}),t[19]=n,t[20]=i,t[21]=a,t[22]=l,t[23]=r,t[24]=f,t[25]=s,t[26]=m,t[27]=h,t[28]=g,t[29]=_,t[30]=v):v=t[30],v});vP.displayName=`UngroupedMessageRow`;var yP=Z.memo(e=>{let t=(0,Q.c)(24),{entry:n,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,showLiveStatusRow:_}=e,v=_!==void 0&&_,y;t[0]!==m||t[1]!==h||t[2]!==c||t[3]!==d||t[4]!==n.isLastTurn||t[5]!==n.kind||t[6]!==n.message||t[7]!==n.nextMessage||t[8]!==n.previousMessage||t[9]!==n.turn||t[10]!==i||t[11]!==r||t[12]!==u||t[13]!==p||t[14]!==g||t[15]!==a||t[16]!==s||t[17]!==f||t[18]!==o||t[19]!==l?(y=n.kind===`ungrouped`?(0,$.jsx)(vP,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}):(0,$.jsx)(_P,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o}),t[0]=m,t[1]=h,t[2]=c,t[3]=d,t[4]=n.isLastTurn,t[5]=n.kind,t[6]=n.message,t[7]=n.nextMessage,t[8]=n.previousMessage,t[9]=n.turn,t[10]=i,t[11]=r,t[12]=u,t[13]=p,t[14]=g,t[15]=a,t[16]=s,t[17]=f,t[18]=o,t[19]=l,t[20]=y):y=t[20];let b=y;if(!v)return b;let x;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(aA,{})}),t[21]=x):x=t[21];let S;return t[22]===b?S=t[23]:(S=(0,$.jsxs)($.Fragment,{children:[b,x]}),t[22]=b,t[23]=S),S});yP.displayName=`MessageListEntry`;var bP=Z.memo(({entries:e,engine:t,contentRef:n,scrollRef:r,registerTanstackVirtualizer:i,virtualizerKey:a,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g})=>{let _=t===`tanstack`,v=Z.useRef(t),y=Z.useRef(null),[b,x]=Z.useReducer(e=>e+1,0);if(t===`none`)y.current=null;else if(v.current===`none`&&_&&y.current===null){let e=n.current,t=r?.current;e&&t&&(y.current=lP(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&cn();Z.useEffect(()=>{if(!T)return;let e=r?.current;if(!e)return;let t=()=>{S.current=!0},n=()=>{S.current=!1},i=()=>{C.current=performance.now()};return e.addEventListener(`touchstart`,t,{passive:!0}),e.addEventListener(`touchend`,n,{passive:!0}),e.addEventListener(`touchcancel`,n,{passive:!0}),e.addEventListener(`scroll`,i,{passive:!0}),()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),e.removeEventListener(`scroll`,i)}},[T,r]);let E=()=>S.current||performance.now()-C.current<FN,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*LN},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&zN(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<IN)?w.current===null&&(w.current=performance.now()):(w.current=null,k(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);tt(()=>{if(w.current===null)return;let e=performance.now()-w.current>=IN;(!E()||D()||e)&&j()},T?RN:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=DN(),[F,I]=Z.useState(()=>Cj(P));Z.useEffect(()=>{if(!(!_||F>=P))return vc(()=>{Z.startTransition(()=>{I(e=>wj(e,P))})})},[F,_,P]);let L=WN(a,u),[R]=Z.useState(()=>_?$N(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=UN(u),V=Z.useRef(B),H=Z.useRef(u);H.current!==u&&(H.current=u,V.current=B);let U=Z.useRef(_),W=Z.useRef(new Map),ee=Z.useRef(void 0);Z.useLayoutEffect(()=>{if(_)return;let e=n?.current;if(!e)return;let t=W.current;t.clear(),e.querySelectorAll(`[data-turn-entry]`).forEach(e=>{let n=e.dataset.turnEntry;n&&t.set(n,e.getBoundingClientRect().height)}),ee.current=void 0}),_&&ee.current===void 0&&(ee.current=R??VN(N,W.current,V.current));let G=Qc({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{qN(z.current,n.getTotalSize()),Zc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:PN,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:ee.current});at(()=>{if(_)return Xj(G)},[_,G]);let K=Z.useRef(null),te=Z.useRef(null);_||(K.current=null);let ne=J(()=>{if(!_)return;let e=z.current??r?.current;if(!e)return;let t=e.offsetWidth;if(!GN(K.current,t)){K.current===null&&t>0&&(K.current=t);return}K.current=t,te.current!==null&&clearTimeout(te.current),te.current=setTimeout(()=>{te.current=null,G.measure()},220)}),re=_&&typeof ResizeObserver<`u`;st(re?z:null,ne),st(re&&r?r:null,ne),nt(()=>{te.current!==null&&(clearTimeout(te.current),te.current=null)}),at(()=>{_&&ne()},[_]),at(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=sP(n,e.messageId);if(i){let t=i.getBoundingClientRect().top-n.getBoundingClientRect().top-e.offsetTop;Math.abs(t)>.5&&(n.scrollTop+=t),y.current=null;return}let a=N.indexOf(e.entryKey);if(a<0||e.attempts>=1){y.current=null;return}e.attempts+=1,G.scrollToIndex(a,{align:`start`}),x()},[t,N,_,G,b]);let ie=G.getVirtualItems(),ae=ie.map(e=>e.index),[oe,se]=Z.useState(()=>Mj(N,{seedCount:JN(u),restore:Aj(L)})),ce=Nj(oe,N);ce!==oe&&se(ce);let le=Z.useRef(ce);le.current=ce;let ue=Z.useRef(null);G.scrollDirection&&(ue.current=G.scrollDirection);let de=G.range?.startIndex??ie[0]?.index??Math.max(0,A.length-1),fe=G.range?.endIndex??ie[ie.length-1]?.index??Math.max(0,A.length-1),pe=G.isScrolling,me=Math.max(0,fe-de+1),he=Fj({entryKeys:N,mountedIndexes:ae,visibleStartIndex:de,visibleEndIndex:fe,scrollDirection:ue.current,preloadEntries:JN(u,me),hydratedKeys:ce,allowVisibleRelease:!pe,preloadReleaseLimit:pe?YN(u):SN,visibleReleaseLimit:pe?0:XN(u)}),ge=he.join(`\0`),_e=Z.useRef(he);_e.current=he,Z.useEffect(()=>{if(!(!_||!ge))return vc(()=>{Z.startTransition(()=>{se(e=>{let t=null;for(let n of _e.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,ge]),Z.useEffect(()=>{se(e=>Ij(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=G.itemSizeCache,t=ZN(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(NN,Math.max(MN,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(G),()=>{eP(L,M.current.map(e=>e.key),G),jj(L,le.current),i?.(null)}},[_,G,L]);let ve=bj((e,t=!0)=>(0,$.jsx)(Ej,{enabled:t,children:(0,$.jsx)(yP,{entry:e,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,sessionIsWorking:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g},e.key)}));if(t===`none`)return(0,$.jsx)(`div`,{ref:n,className:`relative w-full`,children:A.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:ve(e)},e.key))});if(t===`tanstack`){let e=KN(ie[0]?.start??0,ie[ie.length-1]?.end??0,G.getTotalSize());return(0,$.jsx)(`div`,{ref:z,className:`relative w-full`,style:{minHeight:e.minHeight},children:(0,$.jsx)(`div`,{style:{paddingTop:e.paddingTop,paddingBottom:e.paddingBottom},children:ie.map(e=>{let t=A[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:G.measureElement,"data-turn-entry":t.key,className:`oc-chat-message-layout-boundary`,children:ve(t,ce.has(t.key))},t.key):null})})})}return null});bP.displayName=`StaticHistoryList`;var xP=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(`div`,{className:`oc-chat-message-layout-boundary`,children:(0,$.jsx)(yP,{...e})}),t[0]=e,t[1]=n),n});xP.displayName=`TailEntry`;var SP=e=>{let t=(0,Q.c)(43),{entries:n,directory:r,sessionId:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,showTurnChangedFiles:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:_,activeStreamingPhase:v,reviewTransferDirection:y}=e,b=n.length-1,x=ki(_??``,r,i??void 0),S;bb0:{let e=n[b];if(!e){S=void 0;break bb0}let r=p===`sorted`,i;t[0]!==_||t[1]!==x||t[2]!==e||t[3]!==m||t[4]!==r?(i=yj(e,{activeStreamingMessageId:_,liveParts:x,showTextJustificationActivity:r,showTurnChangedFiles:m}),t[0]=_,t[1]=x,t[2]=e,t[3]=m,t[4]=r,t[5]=i):i=t[5],S=i}let C=S,w;if(t[6]!==_||t[7]!==v||t[8]!==u||t[9]!==p||t[10]!==n||t[11]!==o||t[12]!==C||t[13]!==b||t[14]!==a||t[15]!==f||t[16]!==g||t[17]!==y||t[18]!==s||t[19]!==l||t[20]!==h||t[21]!==c||t[22]!==d){let e;t[24]!==_||t[25]!==v||t[26]!==u||t[27]!==p||t[28]!==o||t[29]!==C||t[30]!==b||t[31]!==a||t[32]!==f||t[33]!==g||t[34]!==y||t[35]!==s||t[36]!==l||t[37]!==h||t[38]!==c||t[39]!==d?(e=(e,t)=>{let n=t===b;return(0,$.jsx)(xP,{entry:n?C??e:e,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:n?l:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:n?_:null,activeStreamingPhase:n?v:null,reviewTransferDirection:y},e.key)},t[24]=_,t[25]=v,t[26]=u,t[27]=p,t[28]=o,t[29]=C,t[30]=b,t[31]=a,t[32]=f,t[33]=g,t[34]=y,t[35]=s,t[36]=l,t[37]=h,t[38]=c,t[39]=d,t[40]=e):e=t[40],w=n.map(e),t[6]=_,t[7]=v,t[8]=u,t[9]=p,t[10]=n,t[11]=o,t[12]=C,t[13]=b,t[14]=a,t[15]=f,t[16]=g,t[17]=y,t[18]=s,t[19]=l,t[20]=h,t[21]=c,t[22]=d,t[23]=w}else w=t[23];let T;return t[41]===w?T=t[42]:(T=(0,$.jsx)($.Fragment,{children:w}),t[41]=w,t[42]=T),T};SP.displayName=`StreamingTailContent`;var CP=e=>{let t=(0,Q.c)(73),{historyEntries:n,tailEntries:r,timelineCacheKey:i,directory:a,sessionId:o,scrollRef:s,registerList:c,onHistoryContentChange:l,onTailContentChange:u,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,showTurnChangedFiles:y,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w,header:T,footer:E,scrollClassName:D,scrollStyle:O,scrollDataset:k,onScroll:A,followEnabled:j,historyAnchorToken:M,pinRevealGeneration:N,onIsAtEndChange:P,anchoredUserMessageId:F,onAnchoredTurnParkReleased:I}=e,L=j===void 0||j,R=N===void 0?0:N,z=F===void 0?null:F,B=q(OP),V=n.length,H=r.length>0?r[r.length-1]:void 0,U=H?.key??null,W=ki(S??``,a,o??void 0),ee;bb0:{if(!H){ee=r;break bb0}let e=v===`sorted`,n;t[0]!==S||t[1]!==W||t[2]!==H||t[3]!==y||t[4]!==e?(n=yj(H,{activeStreamingMessageId:S,liveParts:W,showTextJustificationActivity:e,showTurnChangedFiles:y}),t[0]=S,t[1]=W,t[2]=H,t[3]=y,t[4]=e,t[5]=n):n=t[5];let i=n;if(i===H){ee=r;break bb0}let a;t[6]!==i||t[7]!==r?(a=r.slice(),a[a.length-1]=i,t[6]=i,t[7]=r,t[8]=a):a=t[8],ee=a}let G=ee,K;t[9]!==n||t[10]!==G?(K=G.length>0?[...n,...G]:n,t[9]=n,t[10]=G,t[11]=K):K=t[11];let te=K,ne;t[12]!==te||t[13]!==z?(ne=AM(te,z,mP,{anchorOffset:16}),t[12]=te,t[13]=z,t[14]=ne):ne=t[14];let re=ne,ie;t[15]===h?ie=t[16]:(ie={resolvePreloadEntries:e=>JN(h,e),resolvePreloadReleaseWhileScrolling:()=>YN(h),resolveVisibleReleaseLimit:()=>XN(h)},t[15]=h,t[16]=ie);let ae=ie,oe;t[17]!==S||t[18]!==C||t[19]!==h||t[20]!==v||t[21]!==V||t[22]!==U||t[23]!==w||t[24]!==m||t[25]!==y||t[26]!==p||t[27]!==g?(oe={historyCount:V,newestTailKey:U,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,chatRenderMode:v,showTurnChangedFiles:y,stickyUserHeader:p,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w},t[17]=S,t[18]=C,t[19]=h,t[20]=v,t[21]=V,t[22]=U,t[23]=w,t[24]=m,t[25]=y,t[26]=p,t[27]=g,t[28]=oe):oe=t[28];let se=oe,ce;t[29]!==S||t[30]!==C||t[31]!==h||t[32]!==v||t[33]!==d||t[34]!==V||t[35]!==U||t[36]!==l||t[37]!==u||t[38]!==_||t[39]!==x||t[40]!==w||t[41]!==f||t[42]!==m||t[43]!==b||t[44]!==p||t[45]!==g?(ce=(e,t,n)=>{let r=t>=V,i=U!==null&&e.key===U;return(0,$.jsx)(Cc,{disabled:!r,children:(0,$.jsx)(Ej,{enabled:n,children:(0,$.jsx)(yP,{entry:e,onMessageContentChange:r?u:l,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:i?m:!1,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:i?S:null,activeStreamingPhase:i?C:null,reviewTransferDirection:w,showLiveStatusRow:i})})})},t[29]=S,t[30]=C,t[31]=h,t[32]=v,t[33]=d,t[34]=V,t[35]=U,t[36]=l,t[37]=u,t[38]=_,t[39]=x,t[40]=w,t[41]=f,t[42]=m,t[43]=b,t[44]=p,t[45]=g,t[46]=ce):ce=t[46];let le=bj(ce),ue;t[47]===h?ue=t[48]:(ue=UN(h),t[47]=h,t[48]=ue);let de=B&&p,fe;return t[49]!==te||t[50]!==re||t[51]!==L||t[52]!==E||t[53]!==T||t[54]!==M||t[55]!==ae||t[56]!==B||t[57]!==I||t[58]!==P||t[59]!==A||t[60]!==R||t[61]!==c||t[62]!==le||t[63]!==se||t[64]!==D||t[65]!==k||t[66]!==s||t[67]!==O||t[68]!==m||t[69]!==ue||t[70]!==de||t[71]!==i?(fe=(0,$.jsx)(Tj,{enabled:!0,children:(0,$.jsx)(JM,{entries:te,timelineCacheKey:i,estimatedItemSize:ue,hydrationTuning:ae,renderEntry:le,rowInvalidationKey:se,scrollElementRef:s,registerList:c,followEnabled:L,historyAnchorToken:M,pinRevealGeneration:R,anchoredEndSpace:re,onAnchoredTurnParkReleased:I,sessionIsWorking:m,header:T,footer:E,className:D,style:O,scrollElementDataset:k,hideTopScrollShadow:de,hideBottomScrollShadow:B,onScroll:A,onIsAtEndChange:P})}),t[49]=te,t[50]=re,t[51]=L,t[52]=E,t[53]=T,t[54]=M,t[55]=ae,t[56]=B,t[57]=I,t[58]=P,t[59]=A,t[60]=R,t[61]=c,t[62]=le,t[63]=se,t[64]=D,t[65]=k,t[66]=s,t[67]=O,t[68]=m,t[69]=ue,t[70]=de,t[71]=i,t[72]=fe):fe=t[72],fe};CP.displayName=`LegendTimelineHost`;var wP=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,scrollRef:u,directory:d,headerSlot:f,footerSlot:p,timelineScrollClassName:m,timelineScrollStyle:h,timelineScrollDataset:g,timelineOnScroll:_,timelineFollowEnabled:v,timelineHistoryAnchorToken:y,timelineOnIsAtEndChange:b,enableSendPark:x=!0},S)=>{Fe(`ui.message_list.render`);let{sessionKey:C,virtualizerKey:w}=HN(e,t),T=q(e=>e.stickyUserHeader),E=q(e=>e.chatRenderMode),D=q(e=>e.activityRenderMode),O=q(e=>e.showTurnChangedFiles),k=Mr(e=>e.reviewTransferBySessionId.get(C)??null),[A,j]=Z.useState(()=>new Map),M=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),[N,P]=Z.useState(null),F=Z.useRef(null);F.current=N;let I=J(t=>{nn(e),F.current===t&&P(null)});at(()=>{if(x)return()=>{queueMicrotask(()=>{nn(e)})}},[x,e]);let L=J(c),R=J(()=>{l?.()}),z=J((e,t)=>{j(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:sk(i)}),r})}),B=Z.useMemo(()=>be(`ui.message_list.base_display_ms`,()=>{let e=new Set,t=new Map,r=[];for(let e of n){let n=e.info?.id;typeof n==`string`&&t.set(n,e)}for(let i=0;i<n.length;i+=1){let a=n[i],o=a.info?.id;if(typeof o==`string`){if(e.has(o))continue;e.add(o)}r.push(Bk(typeof o==`string`?t.get(o)??a:a))}let i=[],a=new Set;for(let e=0;e<r.length;e+=1){let t=r[e],n=nP(t,a);Ik(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(rP(o)){let e=dP(n);if(e.hide){i[i.length-1]=fP(o,e.taskSessionId);continue}}if(ZM(o)){let e=QM(n,iP(o));if(e.hide){i[i.length-1]=pP(o,e.details);continue}}i.push(n)}return i}),[n]),V=Z.useRef(null),H=Z.useRef(null),U=Z.useCallback(()=>{let e=H.current;e&&(H.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{U()},[U]);let W=J(()=>u?.current?u.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),ee=Z.useMemo(()=>be(`ui.message_list.retry_overlay_ms`,()=>_j(B,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[B,o]),G=r||!!i,K=Z.useRef(G),te=Z.useRef(C);te.current!==C&&(te.current=C,K.current=!1),G&&(K.current=!0);let{projection:ne,staticTurns:re,streamingTurns:ie}=hj(ee,{sessionKey:C,showTextJustificationActivity:E===`sorted`,showTurnChangedFiles:O,hasLiveTail:G||K.current,liveTailActive:G}),ae=ne.ungroupedMessageIds.size>0,oe=ae?ee:dN,se=ae?ne.ungroupedMessageIds:fN,ce=Z.useMemo(()=>be(`ui.message_list.render_entries_ms`,()=>{let e=re.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===ne.lastTurnId}));if(se.size===0)return e;let t=new Map;e.forEach(e=>{t.set(e.turn.userMessage.info.id,e)});let n=[];return oe.forEach((e,r)=>{let i=t.get(e.info.id);if(i){n.push(i);return}se.has(e.info.id)&&n.push({kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:r>0?oe[r-1]:void 0,nextMessage:r<oe.length-1?oe[r+1]:void 0})}),n}),[ne.lastTurnId,oe,se,re]),le=Z.useMemo(()=>{if(ie.length>0)return ie.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===ne.lastTurnId}));if(ne.ungroupedMessageIds.size===0)return pN;let e=ee[ee.length-1];return!e||!ne.ungroupedMessageIds.has(e.info.id)?pN:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:ee.length>1?ee[ee.length-2]:void 0,nextMessage:void 0}]},[ee,ne.lastTurnId,ne.ungroupedMessageIds,ie]),ue=le.length>0;ue&&G&&Fe(`ui.message_list.render.streaming`);let de=ce,fe=de.length>=uN,pe=Z.useRef(fe);QN(pe,fe);let me=fe?`tanstack`:`none`,he=Bs(e=>e.legendTimelineEnabled),ge=Z.useRef(null),_e=J(e=>{ge.current=e}),ve=Z.useRef(null),ye=J(e=>{ve.current=e}),xe=Z.useMemo(()=>le.length>0?[...de,...le]:de,[de,le]),[Se,Ce]=Z.useState(0),[we,Te]=Z.useState(null),Ee=WN(w,D),De=Gj(void 0,Zj({scopeKey:Ee,generation:Se,root:we,relevantKeys:Z.useMemo(()=>Bj({entryKeys:xe.map(e=>e.key),seedCount:JN(D)}),[Ee,Se,xe.length,xe[xe.length-1]?.key,D]),enabled:!he&&xe.length>0})),Oe=J(e=>{s(e)}),ke=J(e=>{s(e)}),Ae=Z.useMemo(()=>n.filter(e=>tP(e)===`user`).map(e=>e.info.id),[n]),je=M.current,Me=je.sessionKey!==e,Ne=je.previousOrder;Me&&(x&&je.sessionKey!==void 0&&nn(je.sessionKey),je.sessionKey=e,je.previousOrder=Ae,je.animatedIds=new Set);let Pe=x?On({sessionId:e,sessionChanged:Me,previousUserOrder:Ne,currentUserOrder:Ae,animatedIds:je.animatedIds}):null;je.previousOrder=Ae;let Ie=x?jM({sessionChanged:Me,previousUserOrder:Ne,currentUserOrder:Ae,currentAnchorId:N,consumedSendMessageId:Pe}):null;x&&Ie!==N&&P(Ie),x&&(F.current=Ie);let Le=J(e=>tP(e)===`user`&&M.current.animatedIds.has(e.info.id)),Re=J(e=>{M.current.animatedIds.delete(e)}),ze=Z.useMemo(()=>{let e=new Map;return xe.forEach((t,n)=>{if(t.kind===`ungrouped`){e.set(t.message.info.id,n);return}e.set(t.turn.userMessage.info.id,n),t.turn.assistantMessages.forEach(t=>{e.set(t.info.id,n)})}),e},[xe]),Be=Z.useMemo(()=>{let e=new Map;return xe.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[xe]),Ve=J(e=>{let t=W();return t?t.querySelector(`[data-message-id="${e}"]`):null}),He=J((e,t=`auto`)=>{if(e<0||e>=de.length)return!1;if(he){let n=ge.current;return n?(n.scrollToIndex({index:e,animated:t===`smooth`,viewOffset:0}),!0):!1}if(!fe)return!1;let n=ve.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),Ue=J((e,t=`auto`)=>{let n=W();if(!n)return!1;let r=Ve(e);if(!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect().top-i.top+n.scrollTop-50;return n.scrollTo({top:a,behavior:t}),!0});return Z.useEffect(()=>{if(!S)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Be.get(e);if(r===void 0)return!1;let i=W();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):ue&&r>=de.length?!1:He(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=ze.get(e);return r===void 0?!1:Ue(e,n)||(ue&&r>=de.length?!1:He(r,n))},holdViewportAnchor:e=>{let t=W();if(!t||typeof window>`u`)return;U();let n=0,r=0,i=!1,a=null,o=()=>{t.removeEventListener(`touchstart`,c),t.removeEventListener(`wheel`,c),t.removeEventListener(`keydown`,c),t.removeEventListener(`pointerdown`,c)},s=()=>{i||(i=!0,a!==null&&(window.cancelAnimationFrame(a),a=null),o(),H.current?.cancel===s&&(H.current=null))},c=()=>{s()};H.current={cancel:s},t.addEventListener(`touchstart`,c,{passive:!0}),t.addEventListener(`wheel`,c,{passive:!0}),t.addEventListener(`keydown`,c),t.addEventListener(`pointerdown`,c,{passive:!0});let l=()=>{if(i)return;let o=Ve(e.messageId);if(o){let n=o.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(n)>.5?(t.scrollTop+=n,r=0):r+=1}if(n+=1,r>=ON||n>=kN){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:U,isHistoryVirtualized:()=>he?!0:pe.current,captureViewportAnchor:()=>{let e=W();if(!e)return null;let t=e.getBoundingClientRect(),n=Array.from(e.querySelectorAll(`[data-message-id]`)),r=n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!oP(n,e,t.top))??n.find(e=>e.getBoundingClientRect().bottom>t.top+1);if(!r)return null;let i=r.dataset.messageId;return i?{messageId:i,offsetTop:r.getBoundingClientRect().top-t.top}:null},restoreViewportAnchor:e=>{let t=W();if(!t||!ze.has(e.messageId))return!1;let n=()=>{let n=Ve(e.messageId);if(!n)return!1;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect().top-r.top-e.offsetTop;return i!==0&&(t.scrollTop+=i),!0};if(!n()){let t=ze.get(e.messageId);if(typeof t==`number`&&t<de.length)return He(t,`auto`)}return n()},scrollToBottom:()=>{if(Ce(e=>e+1),he){let e=hM(W());if(e!==null){ge.current?.scrollToOffset({offset:e,animated:!1});return}ge.current?.scrollToEnd({animated:!1});return}if(fe&&de.length>0&&ve.current){ve.current.scrollToEnd();return}let e=W();e&&(e.scrollTop=e.scrollHeight)}};if(typeof S==`function`)return S(e),()=>{S(null)};let t=S;return t.current=e,()=>{t.current=null}},[U,de.length,he,ze,fe,ue,Be,S]),he?(0,$.jsx)(CP,{historyEntries:de,tailEntries:le,timelineCacheKey:WN(w,D),directory:d,sessionId:C,scrollRef:u,registerList:_e,onHistoryContentChange:Oe,onTailContentChange:ke,getAnimationHandlers:L,scrollToBottom:R,stickyUserHeader:T,sessionIsWorking:r,activityRenderMode:D,turnUiStates:A,onToggleTurnGroup:z,chatRenderMode:E,showTurnChangedFiles:O,shouldAnimateUserMessage:Le,onUserAnimationConsumed:Re,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:k,header:f,footer:p,scrollClassName:m,scrollStyle:h,scrollDataset:g,onScroll:_,followEnabled:v,historyAnchorToken:y,pinRevealGeneration:Se,onIsAtEndChange:b,anchoredUserMessageId:Ie,onAnchoredTurnParkReleased:I},w):(0,$.jsx)(`div`,{children:(0,$.jsx)(Cc,{disabled:!1,children:(0,$.jsxs)(`div`,{ref:Te,className:`relative w-full`,style:De,children:[(0,$.jsx)(Cc,{disabled:fe,children:(0,$.jsx)(Tj,{enabled:!0,children:(0,$.jsx)(bP,{entries:de,engine:me,contentRef:V,scrollRef:u,registerTanstackVirtualizer:ye,virtualizerKey:w,onMessageContentChange:Oe,getAnimationHandlers:L,scrollToBottom:R,stickyUserHeader:T,activityRenderMode:D,turnUiStates:A,onToggleTurnGroup:z,chatRenderMode:E,shouldAnimateUserMessage:Le,onUserAnimationConsumed:Re,reviewTransferDirection:k},w)})}),(0,$.jsx)(SP,{entries:le,directory:d,sessionId:C,onMessageContentChange:ke,getAnimationHandlers:L,scrollToBottom:R,stickyUserHeader:T,sessionIsWorking:r,activityRenderMode:D,turnUiStates:A,onToggleTurnGroup:z,chatRenderMode:E,showTurnChangedFiles:O,shouldAnimateUserMessage:Le,onUserAnimationConsumed:Re,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:k})]})})})});wP.displayName=`MessageList`;var TP=Z.memo(wP);function EP(e){return e.info.id}function DP(e){return e!==null}function OP(e){return e.isMobile}var kP=e=>{let t=(0,Q.c)(3),{content:n,html:r}=e,i;return t[0]!==n||t[1]!==r?(i=r===void 0?(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,children:n}):(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,dangerouslySetInnerHTML:{__html:r}}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},AP=({diff:e,filePath:t})=>{let{currentTheme:n}=Ga(),r=Z.useMemo(()=>To(n),[n]),i=Z.useMemo(()=>Pc(e),[e]),a=fc(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6580
|
-
`),[i]),s=Wc(o,a),c=0;return(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0 space-y-0`,style:r,children:i.map((e,n)=>(0,$.jsxs)(`div`,{className:`-mx-1 px-1 border-b border-border/20 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`bg-muted/20 px-2 py-1 typography-meta font-medium text-muted-foreground border-b border-border/10 break-words -mx-1`,children:`${e.file||t?.split(`/`).pop()||`file`} (line ${e.oldStart})`}),(0,$.jsx)(`div`,{children:e.lines.map((e,t)=>{let n=s?.[c];return c+=1,(0,$.jsxs)(`div`,{className:Y(`typography-code font-mono px-2 py-0.5 flex -mx-2`,e.type===`context`&&`bg-transparent`,e.type===`removed`&&`bg-transparent`,e.type===`added`&&`bg-transparent`),style:e.type===`removed`?{backgroundColor:`var(--tools-edit-removed-bg)`}:e.type===`added`?{backgroundColor:`var(--tools-edit-added-bg)`}:{},children:[(0,$.jsx)(`span`,{className:`w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5`,style:{color:`var(--tools-edit-line-number)`,borderColor:`var(--tools-border)`},children:e.lineNumber||``}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(
|
|
6581
|
-
`),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=fc(r??``)||`text`,t[4]=r,t[5]=l);let u=l,d;t[6]===r?d=t[7]:(d=r?.split(`/`).pop()||`New file`,t[6]=r,t[7]=d);let f=d,p=Math.max(c.length,1),m=p===1?`line 1`:`lines 1-${p}`,h=Wc(n,u),g=o,_=`${f} (${m})`,v;t[8]===_?v=t[9]:(v=(0,$.jsx)(`div`,{className:`bg-muted/20 px-2 py-1 typography-meta font-medium text-muted-foreground border border-border/10 rounded-lg mb-1`,children:_}),t[8]=_,t[9]=v);let y;if(t[10]!==h||t[11]!==c){let e;t[13]===h?e=t[14]:(e=(e,t)=>(0,$.jsxs)(`div`,{className:`typography-code font-mono px-2 py-0.5 flex -mx-1`,children:[(0,$.jsx)(`span`,{className:`w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5`,style:{color:`var(--tools-edit-line-number)`,borderColor:`var(--tools-border)`},children:t+1}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(kP,{content:e||` `,html:h?.[t]})})]},t),t[13]=h,t[14]=e),y=c.map(e),t[10]=h,t[11]=c,t[12]=y}else y=t[12];let b;t[15]===y?b=t[16]:(b=(0,$.jsx)(`div`,{className:`space-y-0`,children:y}),t[15]=y,t[16]=b);let x;return t[17]!==g||t[18]!==v||t[19]!==b?(x=(0,$.jsxs)(`div`,{className:`w-full min-w-0`,style:g,children:[v,b]}),t[17]=g,t[18]=v,t[19]=b,t[20]=x):x=t[20],x},MP=new Set([`id`,`identifier`,`title`,`name`]),NP=e=>typeof e==`object`&&!!e&&!Array.isArray(e),PP=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),FP=e=>{let t=typeof e.id==`string`?e.id:typeof e.identifier==`string`?e.identifier:``,n=typeof e.title==`string`?e.title:typeof e.name==`string`?e.name:``;return t&&n?`${t} · ${n}`:n||t||null},IP=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},LP=Z.memo(e=>{let t=(0,Q.c)(54),{value:n,label:r,depth:i}=e;if(Array.isArray(n)){let e;t[0]!==r||t[1]!==n.length?(e=r?`${PP(r)} (${n.length})`:`(${n.length})`,t[0]=r,t[1]=n.length,t[2]=e):e=t[2];let a=e,o=i<2,s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5 shrink-0 transition-transform group-open/json-summary:rotate-90`}),t[3]=s):s=t[3];let c;t[4]===a?c=t[5]:(c=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 py-1.5 typography-meta text-[var(--surface-foreground)] hover:text-[var(--surface-mutedForeground)]`,children:[s,(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:a})]}),t[4]=a,t[5]=c);let l;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-1 left-0 top-0 w-px bg-[var(--tools-border)] opacity-40`}),t[6]=l):l=t[6];let u;if(t[7]!==i||t[8]!==n){let e;t[10]===i?e=t[11]:(e=(e,t)=>(0,$.jsx)(LP,{value:e,depth:i+1},t),t[10]=i,t[11]=e),u=n.map(e),t[7]=i,t[8]=n,t[9]=u}else u=t[9];let d;t[12]===u?d=t[13]:(d=(0,$.jsxs)(`div`,{className:`relative ml-1 pl-3 pb-1`,children:[l,(0,$.jsx)(`div`,{className:`space-y-1`,children:u})]}),t[12]=u,t[13]=d);let f;return t[14]!==o||t[15]!==c||t[16]!==d?(f=(0,$.jsxs)(`details`,{open:o,className:`group/json-summary`,children:[c,d]}),t[14]=o,t[15]=c,t[16]=d,t[17]=f):f=t[17],f}if(NP(n)){let e;t[18]===n?e=t[19]:(e=FP(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(zP),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${PP(r)}${a?` · ${a}`:``}`:a,t[22]=a,t[23]=r,t[24]=c):c=t[24];let l=c,u;t[25]!==i||t[26]!==s?(u=(0,$.jsx)(`div`,{className:`space-y-1`,children:s.map(e=>{let[t,n]=e;return(0,$.jsx)(LP,{label:t,value:n,depth:i+1},t)})}),t[25]=i,t[26]=s,t[27]=u):u=t[27];let d=u;if(!r&&i===0){let e;t[28]===a?e=t[29]:(e=a?(0,$.jsx)(`div`,{className:`typography-meta font-medium text-[var(--surface-foreground)]`,children:a}):null,t[28]=a,t[29]=e);let n;return t[30]!==d||t[31]!==e?(n=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[e,d]}),t[30]=d,t[31]=e,t[32]=n):n=t[32],n}let f=i<2,p;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5 shrink-0 transition-transform group-open/json-summary:rotate-90`}),t[33]=p):p=t[33];let m;t[34]!==r||t[35]!==l?(m=l??(r?PP(r):`{}`),t[34]=r,t[35]=l,t[36]=m):m=t[36];let h;t[37]===m?h=t[38]:(h=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 py-1.5 typography-meta text-[var(--surface-foreground)] hover:text-[var(--surface-mutedForeground)]`,children:[p,(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:m})]}),t[37]=m,t[38]=h);let g;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-1 left-0 top-0 w-px bg-[var(--tools-border)] opacity-40`}),t[39]=g):g=t[39];let _;t[40]===d?_=t[41]:(_=(0,$.jsxs)(`div`,{className:`relative ml-1 pl-3 pb-1`,children:[g,d]}),t[40]=d,t[41]=_);let v;return t[42]!==_||t[43]!==f||t[44]!==h?(v=(0,$.jsxs)(`details`,{open:f,className:`group/json-summary`,children:[h,_]}),t[42]=_,t[43]=f,t[44]=h,t[45]=v):v=t[45],v}let a=n===null?`null`:typeof n==`boolean`?n?`true`:`false`:String(n),o;t[46]!==a||t[47]!==n?(o=typeof n==`string`&&IP(n)?(0,$.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`truncate text-[var(--status-info)] underline underline-offset-2 hover:opacity-80`,title:n,children:n}):(0,$.jsx)(`span`,{className:Y(`min-w-0 break-words`,n===null?`text-[var(--surface-mutedForeground)]`:`text-[var(--surface-foreground)]`),children:a}),t[46]=a,t[47]=n,t[48]=o):o=t[48];let s=o,c;t[49]===r?c=t[50]:(c=r?(0,$.jsx)(`span`,{className:`truncate text-[var(--surface-mutedForeground)]`,title:r,children:PP(r)}):(0,$.jsx)(`span`,{}),t[49]=r,t[50]=c);let l;return t[51]!==s||t[52]!==c?(l=(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(6rem,auto)_minmax(0,1fr)] gap-x-2 py-1 typography-meta`,children:[c,s]}),t[51]=s,t[52]=c,t[53]=l):l=t[53],l});LP.displayName=`JsonSummaryValue`;var RP=Z.memo(e=>{let t=(0,Q.c)(2),{data:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`space-y-1`,children:(0,$.jsx)(LP,{value:n,depth:0})}),t[0]=n,t[1]=r),r});RP.displayName=`JsonSummaryView`;function zP(e){let[t]=e;return!MP.has(t)}var BP={margin:0,padding:`0.5rem`,fontSize:`var(--text-meta)`,lineHeight:`1.25rem`,background:`rgb(var(--muted) / 0.3)`,borderRadius:`0.25rem`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`,overflow:`visible`},VP={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},HP=e=>{let t=`h-3 w-3`,n=e.toLowerCase();return n===`edit`||n===`multiedit`||n===`str_replace`||n===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil-ai`,className:t}):n===`write`||n===`create`||n===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:t}):n===`bash`||n===`shell`||n===`cmd`||n===`terminal`||n===`shell_command`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):n===`webfetch`||n===`fetch`||n===`curl`||n===`wget`?(0,$.jsx)(X,{name:`global`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},UP=e=>{let t=e.toLowerCase();return t===`edit`||t===`multiedit`||t===`str_replace`||t===`str_replace_based_edit_tool`?`edit`:t===`write`||t===`create`||t===`file_write`?`write`:t===`bash`||t===`shell`||t===`cmd`||t===`terminal`||t===`shell_command`?`bash`:t===`webfetch`||t===`fetch`||t===`curl`||t===`wget`?`webfetch`:e},WP=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,GP=e=>{let t=(0,Q.c)(2),{data:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`rounded-lg border border-border/20 bg-muted/15 px-2 py-1 sm:px-2.5 sm:py-1.5 [&_.typography-meta]:!text-xs [&_summary]:py-1`,children:(0,$.jsx)(RP,{data:n})}),t[0]=n,t[1]=r),r},KP=({permission:e,onResponse:t})=>{let{t:n}=ct(),[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Gn,c=zr(),l=ri(e=>e.currentSessionId),u=Z.useMemo(()=>{if(!l||e.sessionID===l)return!1;let t=c.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===l)},[e.sessionID,l,c]),d=async n=>{i(!0);try{await s(e.sessionID,e.id,n),o(!0),t?.(n)}catch(e){console.error(`[PermissionCard] Failed to respond to permission:`,e)}finally{i(!1)}};if(a)return null;let f=e.permission||`unknown`,p=f.toLowerCase(),m=(t,n=``)=>{let r=e.metadata[t];return typeof r==`string`?r:typeof r==`number`?String(r):n},h=t=>{let n=e.metadata[t];return typeof n==`number`?n:void 0},g=t=>!!e.metadata[t],_=UP(f),v=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[WP(e),t]));return(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{className:`-mt-1 overflow-hidden border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2.5 py-2 sm:px-2 sm:py-1.5 border-b border-border/20 bg-muted/5`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 sm:gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-[var(--status-warning)]`}),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] font-medium text-muted-foreground`,children:n(`sessions.sidebar.session.status.permissionRequired`)}),u?(0,$.jsx)(`span`,{className:`hidden sm:inline typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:n(`chat.questionCard.fromSubagent`)}):null]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[48%] items-center gap-1.5`,children:[HP(f),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] text-muted-foreground font-medium`,children:_})]})]})}),(0,$.jsxs)(`div`,{className:`px-2.5 py-2 sm:px-2 [&_.typography-meta]:!text-xs [&_.typography-micro]:!text-[0.6875rem]`,children:[e.patterns.length>0&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:n(`chat.permissionCard.patterns`)}),(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border/20 bg-muted/15`,children:e.patterns.map((e,t)=>(0,$.jsx)(`code`,{className:Y(`block break-all px-2 py-1.5 text-xs leading-4 sm:text-[length:var(--text-meta)]`,t>0&&`border-t border-border/15`),children:e},`${e}-${t}`))})]}),(()=>{if(p===`bash`||p===`shell`||p===`shell_command`){let e=m(`command`)||m(`cmd`)||m(`script`),t=m(`description`),r=m(`cwd`)||m(`working_directory`)||m(`directory`)||m(`path`),i=h(`timeout`);return(0,$.jsxs)($.Fragment,{children:[t&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:t}),r&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.workingDirectory`)}),` `,(0,$.jsx)(`code`,{className:`px-1 py-0.5 bg-muted/30 rounded`,children:r})]}),i&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.timeout`)}),` `,i,`ms`]}),e&&(0,$.jsx)(`div`,{children:(0,$.jsx)(Fc,{language:`bash`,code:e,style:BP,codeStyle:VP.style,wrap:!0})})]})}if(p===`edit`||p===`multiedit`||p===`str_replace`||p===`str_replace_based_edit_tool`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`changes`)||m(`diff`),r=g(`replace_all`)||g(`replaceAll`);return(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:(0,$.jsxs)(`span`,{className:`font-semibold`,children:[`⚠️ `,n(`chat.permissionCard.replaceAll`)]})}),t&&(0,$.jsx)(pa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(AP,{diff:t,filePath:e})})]})}if(p===`write`||p===`create`||p===`file_write`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`content`)||m(`text`)||m(`data`);return t?(0,$.jsx)(pa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(jP,{content:t,filePath:e})}):null}if(p===`webfetch`||p===`fetch`||p===`curl`||p===`wget`){let t=m(`url`)||m(`uri`)||m(`endpoint`),r=m(`method`)||`GET`,i=e.metadata.headers&&typeof e.metadata.headers==`object`?e.metadata.headers:void 0,a=e.metadata.body??e.metadata.data??e.metadata.payload,o=h(`timeout`),s=m(`format`)||m(`responseType`);return(0,$.jsxs)($.Fragment,{children:[t&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.request`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold px-1.5 py-0.5 bg-primary/20 text-primary rounded`,children:r}),(0,$.jsx)(`code`,{className:`typography-meta px-2 py-1 bg-muted/30 rounded flex-1 break-all`,children:t})]})]}),i&&Object.keys(i).length>0&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.headers`)}),(0,$.jsx)(pa,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(GP,{data:i})})]}),a&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.body`)}),(0,$.jsx)(pa,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(GP,{data:a}):(0,$.jsx)(`pre`,{className:`typography-meta font-mono px-2 py-1.5 bg-muted/20 border border-border/20 rounded-lg whitespace-pre-wrap break-all`,children:String(a)})})]}),(o||s)&&(0,$.jsxs)(`div`,{className:`typography-micro text-muted-foreground`,children:[o&&(0,$.jsxs)(`span`,{children:[n(`chat.permissionCard.timeout`),` `,o,`ms`]}),o&&s&&(0,$.jsx)(`span`,{children:` • `}),s&&(0,$.jsxs)(`span`,{children:[n(`chat.permissionCard.responseFormat`),` `,s]})]})]})}return Object.keys(v).length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:n(`chat.permissionCard.details`)}),(0,$.jsx)(pa,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(GP,{data:v})})]})})()]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-1 border-t border-border/20 px-1.5 py-1.5 sm:flex sm:items-center sm:flex-wrap sm:px-2 sm:py-1`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`once`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,children:[(0,$.jsx)(X,{name:`check`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.allowOnce`)})]}),(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`always`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,children:[(0,$.jsx)(X,{name:`arrow-right`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.alwaysAgree`)})]}),(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`reject`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-[var(--status-error)] sm:h-6 sm:w-auto sm:px-2`,children:[(0,$.jsx)(X,{name:`close`,className:`size-3.5 shrink-0 sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionToast.actions.deny`)})]}),r&&(0,$.jsx)(`div`,{className:`col-span-3 flex justify-center w-full sm:w-auto sm:ml-auto py-1 sm:py-0 typography-meta text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})})]})]})})})};function qP(e){let t=[];return(e.questions??[]).forEach((e,n)=>{let r=e.header?.trim(),i=r&&r.length>0?r:`Question ${n+1}`;t.push(`## ${i}`),t.push(``),t.push(e.question),t.push(``),e.multiple&&(t.push(`_Select all that apply._`),t.push(``)),e.options.forEach(e=>{let n=e.label,r=e.description?.trim();t.push(r?`- **${n}** — ${r}`:`- **${n}**`)}),t.push(``)}),t.join(`
|
|
6582
|
-
`).trimEnd()}function JP(e){let t={questions:(e.questions??[]).map(e=>({header:e.header??null,question:e.question,multiple:!!e.multiple,options:e.options.map(e=>({label:e.label,description:e.description??null}))}))};return JSON.stringify(t,null,2)}var YP=200;function XP(e){return Math.min(Math.max(e,40),YP)}var ZP=`summary`,QP=Z.memo(function(e){let t=(0,Q.c)(27),{value:n,placeholder:r,disabled:i,onValueChange:a,onKeyDown:o}=e,s=Z.useRef(null),[c,l]=Z.useState(n),[u,d]=Z.useState(40),[f,p]=Z.useState(!1),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current;if(!e||document.activeElement!==e)return;let t=e.closest(`.chat-scroll`);if(!t){e.scrollIntoView({block:`nearest`});return}let n=window.visualViewport,r=t.getBoundingClientRect(),i=n?.offsetTop??0,a=n?n.offsetTop+n.height:document.documentElement.clientHeight,o=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--oc-kb-scroll-inset`))||0,c=Math.max(r.top,i),l=Math.min(r.bottom,a-o),u=Math.max(0,l-c),d=e.closest(`[data-question-card]`),f=d?.getBoundingClientRect(),p=(d&&f&&f.height<=u?d:e).getBoundingClientRect();p.bottom>l-12?t.scrollTop+=p.bottom-l+12:p.top<c+12&&(t.scrollTop+=p.top-c-12)},t[0]=m):m=t[0];let h=J(m),g;t[1]===h?g=t[2]:(g=()=>{requestAnimationFrame(h)},t[1]=h,t[2]=g);let _=J(g),v;t[3]===h?v=t[4]:(v=()=>{let e=()=>requestAnimationFrame(h);return e(),window.addEventListener(`oc:keyboard-settled`,e),window.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`oc:keyboard-settled`,e),window.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`scroll`,e)}},t[3]=h,t[4]=v);let y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(y=[],t[5]=y):y=t[5],Z.useEffect(v,y);let b,x;t[6]===n?(b=t[7],x=t[8]):(b=()=>{l(n)},x=[n],t[6]=n,t[7]=b,t[8]=x),Z.useEffect(b,x);let S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>{let e=s.current;if(!e)return;e.style.height=`auto`,e.style.overflowY=`hidden`;let t=e.scrollHeight,n=XP(t),r=t>n;e.style.height=`${n}px`,e.style.overflowY=``,d(e=>e===n?e:n),p(e=>e===r?e:r)},t[9]=S):S=t[9];let C;t[10]===c?C=t[11]:(C=[c],t[10]=c,t[11]=C),Z.useLayoutEffect(S,C);let w;t[12]===a?w=t[13]:(w=e=>{let t=e.target.value;l(t),a(t)},t[12]=a,t[13]=w);let T;t[14]===u?T=t[15]:(T={height:u},t[14]=u,t[15]=T);let E=f?`overflow-y-auto`:`overflow-hidden`,D;t[16]===E?D=t[17]:(D=Y(`w-full bg-transparent border border-border/30 focus:border-primary rounded px-2 py-1 outline-none typography-meta text-foreground placeholder:text-muted-foreground/50 transition-colors resize-none`,E),t[16]=E,t[17]=D);let O;return t[18]!==i||t[19]!==_||t[20]!==c||t[21]!==o||t[22]!==r||t[23]!==T||t[24]!==D||t[25]!==w?(O=(0,$.jsx)(`textarea`,{ref:s,value:c,onChange:w,placeholder:r,disabled:i,rows:2,onKeyDown:o,onFocus:_,style:T,className:D,autoFocus:!0}),t[18]=i,t[19]=_,t[20]=c,t[21]=o,t[22]=r,t[23]=T,t[24]=D,t[25]=w,t[26]=O):O=t[26],O}),$P=({question:e})=>{let{t}=ct(),n=Gt,r=$i,i=q(e=>e.isMobile),a=zr(),o=ri(e=>e.currentSessionId),s=Z.useMemo(()=>{if(!o||e.sessionID===o)return!1;let t=a.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===o)},[e.sessionID,o,a]),[c,l]=Z.useState(`0`),[u,d]=Z.useState(!1),[f,p]=Z.useState(!1),[m,h]=Z.useState({}),[g,_]=Z.useState({}),v=Z.useRef({}),[y,b]=Z.useState({}),x=Z.useMemo(()=>e.questions??[],[e.questions]),S=c===ZP,C=S?-1:Math.max(0,Math.min(x.length-1,Number(c)||0)),w=S?null:x[C],T=Z.useMemo(()=>{if(S)return null;let e=w?.header?.trim();return e&&e.length>0?e:null},[w?.header,S]);Z.useEffect(()=>{l(`0`),h({}),_({}),v.current={},b({}),p(!1)},[e.id]);let E=Z.useMemo(()=>{let e=x.map((e,t)=>({value:String(t),label:e.header?.trim()||`Q${t+1}`}));return x.length>1&&e.push({value:ZP,label:t(`chat.questionCard.summaryTab`)}),e},[x,t]),D=Z.useCallback(e=>{if(g[e])return(v.current[e]??``).trim()||t(`chat.questionCard.noAnswer`);let n=m[e]??[];return n.length>0?n.join(`, `):t(`chat.questionCard.noAnswer`)},[g,m,t]),O=!!w?.multiple,k=m[C]??[],A=!!g[C],j=Z.useMemo(()=>{let e=[];for(let t=0;t<x.length;t+=1){if(g[t]){y[t]||e.push(t);continue}(m[t]??[]).length===0&&e.push(t)}return e},[g,y,x.length,m]),M=Z.useMemo(()=>x.length!==0&&j.length===0,[x.length,j.length]),N=Z.useCallback(()=>{if(x.length===0||j.length===0)return;let e=S?-1:C;for(let t=1;t<=x.length;t+=1){let n=(e+t+x.length)%x.length;if(j.includes(n)){l(String(n));return}}l(String(j[0]))},[C,S,x.length,j]),P=Z.useCallback(()=>{let e=[];for(let t=0;t<x.length;t+=1){if(g[t]){let n=(v.current[t]??``).trim();e.push(n?[n]:[]);continue}e.push(m[t]??[])}return e},[g,x.length,m]),F=Z.useCallback(e=>{w&&(_(e=>({...e,[C]:!1})),b(e=>e[C]?{...e,[C]:!1}:e),h(t=>{let n=t[C]??[];if(O){let r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,[C]:r}}return{...t,[C]:[e]}}))},[C,w,O]),I=Z.useCallback(()=>{_(e=>({...e,[C]:!0})),h(e=>({...e,[C]:[]}));let e=(v.current[C]??``).trim().length>0;b(t=>t[C]===e?t:{...t,[C]:e})},[C]),L=Z.useCallback(e=>{v.current[C]=e;let t=e.trim().length>0;b(e=>e[C]===t?e:{...e,[C]:t})},[C]),R=Z.useCallback(async()=>{if(M){d(!0);try{let t=P();await n(e.sessionID,e.id,t),p(!0)}catch(e){An(e)?(Br.info(t(`chat.questionCard.noLongerPending`)),p(!0)):Br.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{d(!1)}}},[P,e.id,e.sessionID,M,n,t]),z=Z.useCallback(e=>{Fg(e)||e.key===`Enter`&&!e.shiftKey&&(!i||e.ctrlKey||e.metaKey)&&(e.preventDefault(),M?R():N())},[R,N,i,M]),B=Z.useCallback(async()=>{d(!0);try{await r(e.sessionID,e.id),p(!0)}catch(e){An(e)?(Br.info(t(`chat.questionCard.noLongerPending`)),p(!0)):Br.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{d(!1)}},[e.id,e.sessionID,r,t]),V=Z.useCallback(async()=>{let n=qP(e);if((await ut(n)).ok){Br.success(t(`chat.questionCard.copiedMarkdown`));return}Br.error(t(`chat.questionCard.copyFailed`))},[e,t]),H=Z.useCallback(async()=>{let n=JP(e);if((await ut(n)).ok){Br.success(t(`chat.questionCard.copiedJson`));return}Br.error(t(`chat.questionCard.copyFailed`))},[e,t]);return f||x.length===0?null:(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{"data-question-card":!0,className:`-mt-1 border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1.5 border-b border-border/20`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:t(`chat.questionCard.inputNeeded`)}),s?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:t(`chat.questionCard.fromSubagent`)}):null,T?(0,$.jsx)(`span`,{className:`ml-auto typography-micro font-medium text-foreground/70 px-1.5 py-0.5 rounded bg-muted/30 border border-border/20`,children:T}):null,(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-0.5`,T?null:`ml-auto`),children:[(0,$.jsx)(`button`,{type:`button`,onClick:V,title:t(`chat.questionCard.copyMarkdown`),"aria-label":t(`chat.questionCard.copyMarkdown`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`file-text`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:H,title:t(`chat.questionCard.copyJson`),"aria-label":t(`chat.questionCard.copyJson`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`code-box`,className:`h-3 w-3`})})]})]})}),(0,$.jsxs)(`div`,{className:`px-2 py-2`,children:[E.length>1?(0,$.jsx)(`div`,{className:`flex items-center gap-1 mb-2 flex-wrap`,children:E.map(e=>{let t=c===e.value,n=e.value===ZP,r=n?-1:Number(e.value),i=!n&&Number.isFinite(r)&&!j.includes(r);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(e.value),className:Y(`px-2 py-0.5 typography-meta font-medium rounded transition-colors flex items-center gap-1`,t?`bg-interactive-selection/40 text-foreground`:n?`text-muted-foreground hover:text-foreground hover:bg-interactive-hover/20`:i?`text-muted-foreground/60 hover:text-muted-foreground hover:bg-interactive-hover/20`:`text-foreground/85 hover:text-foreground hover:bg-interactive-hover/20`),children:[n?(0,$.jsx)(X,{name:`list-check-3`,className:`h-3 w-3`}):null,e.label]},e.value)})}):null,S?(0,$.jsx)(`div`,{className:`space-y-2`,children:x.map((e,n)=>{let r=D(n),i=r!==t(`chat.questionCard.noAnswer`);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(String(n)),className:`w-full text-left rounded px-1.5 py-1 hover:bg-interactive-hover/20 transition-colors`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.header||t(`chat.questionCard.questionFallback`,{index:n+1})}),(0,$.jsx)(`div`,{className:Y(`typography-meta`,i?`text-foreground`:`text-muted-foreground/50 italic`),children:r})]},n)})}):w?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground mb-1.5`,children:w.question}),O?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1.5`,children:t(`chat.questionCard.selectMultiple`)}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[w.options.map((e,n)=>{let r=k.includes(e.label),i=/\(recommended\)/i.test(e.label);return(0,$.jsx)(`button`,{type:`button`,onClick:()=>F(e.label),disabled:u,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,r?`bg-interactive-selection/20`:null,u?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:O?(0,$.jsx)(Da,{checked:r,onChange:()=>F(e.label),disabled:u}):(0,$.jsx)(lo,{checked:r,onChange:()=>F(e.label),disabled:u})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:Y(`typography-meta break-all`,r?`text-foreground font-medium`:`text-foreground/80`),children:e.label}),i?(0,$.jsx)(`span`,{className:`typography-micro text-primary/80`,children:t(`chat.questionCard.recommended`)}):null]}),e.description?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground break-words`,children:e.description}):null]})]})},`${n}:${e.label}`)}),(0,$.jsx)(`button`,{type:`button`,onClick:I,disabled:u,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,A?`bg-interactive-selection/20`:null,u?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`edit`,className:Y(`h-3.5 w-3.5`,A?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,A?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),A?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)(QP,{value:v.current[C]??``,onValueChange:L,placeholder:t(`chat.questionCard.yourAnswer`),disabled:u,onKeyDown:z})}):null]})]}):null]}),(0,$.jsxs)(`div`,{className:`px-2 pb-1.5 pt-1 flex items-center gap-1.5 border-t border-border/20`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:M?R:N,disabled:u,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-success)/0.1)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[M?(0,$.jsx)(X,{name:`check`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`}),t(M?`chat.questionCard.submit`:`chat.questionCard.next`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:B,disabled:u,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-error)/0.1)] text-[var(--status-error)] hover:bg-[rgb(var(--status-error)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`}),t(`chat.questionCard.dismiss`)]}),u?(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})}):null]})]})})})};function eF(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
6583
|
-
`)}function tF(e,t=80){let n=eF(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var nF=160,rF=28,iF=12,aF=6,oF=30,sF=12,cF=18,lF=80,uF=4,dF=10,fF=14,pF=20,mF=54,hF=4,gF=8,_F=2,vF=160,yF=(e,t)=>e.map(e=>({turnId:e,preview:tF(t.get(e)??[],nF)})),bF=[1,.6,.35,.15],xF=(e,t,n)=>{let r=n?fF:dF;if(t===null)return r;let i=bF[Math.abs(e-t)]??0;return Math.round(r+(pF-r)*i)};function SF({turnIds:e,previewsByTurnId:t,activeTurnId:n,onSelectTurn:r,canLoadEarlier:i,isLoadingOlder:a,onLoadEarlier:o}){let{t:s}=ct(),c=q(e=>e.isPromptNavigatorPanelOpen),l=q(e=>e.setPromptNavigatorPanelOpen),u=Z.useRef(null),d=Z.useRef(null),[f,p]=Z.useState(null),[m,h]=Z.useState(0),[g,_]=Z.useState(!1);Z.useEffect(()=>{let e=d.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){_(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.right-aF-rF;_(r.right>i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let v=Z.useMemo(()=>yF(e,t),[t,e]),y=Math.min(v.length,oF),b=Math.max(0,v.length-y),x=Math.min(m,b),S=x+y,C=x>0,w=S<v.length,T=s(`chat.timeline.noTextContent`),E=s(`chat.promptNavigator.currentPrompt`),D=s(`chat.promptNavigator.loadMore`),O=Z.useMemo(()=>n?v.findIndex(e=>e.turnId===n):-1,[n,v]),k=Z.useRef(x);k.current=x;let A=Z.useRef(v.length);A.current=v.length;let j=Z.useRef(null),M=Z.useRef(null),N=Z.useRef(0),P=Z.useCallback(e=>{h(t=>{let n=A.current,r=Math.min(n,oF),i=Math.max(0,n-r),a=Math.min(t,i);return e<a?e:e>=a+r?Math.min(i,e-r+1):a})},[]),F=Z.useRef(v[0]?.turnId),I=Z.useRef(v.length);Z.useLayoutEffect(()=>{let e=F.current,t=I.current,n=v.length-t;n>0&&t>0&&e&&v[0]?.turnId!==e&&(h(e=>e+n),p(e=>e===null?null:e+n)),F.current=v[0]?.turnId,I.current=v.length},[v]),Z.useEffect(()=>{if(f!==null)return;let e=O>=0?O:v.length-1;h(()=>{let t=A.current,n=Math.min(t,oF),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[O,f,v.length]);let L=Z.useCallback(e=>{let t=u.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/sF),i=Math.min(A.current,oF);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),R=Z.useCallback(()=>{N.current=0,M.current!==null&&(window.clearInterval(M.current),M.current=null)},[]),z=Z.useCallback(()=>{let e=N.current;if(e===0){R();return}let t=A.current,n=Math.max(0,t-Math.min(t,oF)),r=Math.min(k.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){R();return}k.current=i,h(i);let a=j.current;if(a!==null){let e=L(a);e!==null&&p(Math.min(t-1,i+e))}},[L,R]),B=Z.useCallback(e=>{let t=u.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=cF&&C?i=-1:r>=n.height-cF&&w&&(i=1),N.current=i,i===0){R();return}M.current===null&&(M.current=window.setInterval(z,lF))},[z,C,w,R]);Z.useEffect(()=>()=>{M.current!==null&&window.clearInterval(M.current)},[]);let V=Z.useRef(null),H=Z.useCallback(()=>{V.current!==null&&(window.clearTimeout(V.current),V.current=null)},[]),U=Z.useCallback(()=>{H(),V.current=window.setTimeout(()=>{V.current=null,p(null)},vF)},[H]);Z.useEffect(()=>()=>{V.current!==null&&window.clearTimeout(V.current)},[]);let W=Z.useCallback(e=>{H(),j.current=e.clientY;let t=L(e.clientY);t!==null&&p(Math.min(A.current-1,k.current+t)),B(e.clientY)},[H,L,B]),ee=Z.useCallback(()=>{j.current=null,R(),U()},[U,R]),G=Z.useCallback(()=>{l(!1)},[l]),K=Z.useCallback(e=>{if(e===null)return;let t=v[e];t&&(r(t.turnId),R(),p(null),G(),u.current?.blur())},[G,r,v,R]),te=Z.useCallback(e=>{let t=L(e.clientY);t!==null&&K(Math.min(v.length-1,k.current+t))},[K,v.length,L]);Z.useEffect(()=>{if(!c)return;let e=u.current;!e||e===document.activeElement||(e.focus(),p(e=>{if(e!==null)return e;let t=O>=0?O:v.length-1;return P(t),t}))},[O,P,c,v.length]),Z.useEffect(()=>()=>{l(!1)},[l]);let ne=Z.useCallback(e=>{if(v.length===0)return;let t=f??(O>=0?O:v.length-1),n=e=>{let t=Math.max(0,Math.min(v.length-1,e));P(t),p(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(v.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),K(t);return}e.key===`Escape`&&(e.preventDefault(),p(null),G(),u.current?.blur())},[O,G,P,K,f,v.length]),re=Z.useCallback(()=>{R(),p(null),G()},[G,R]),ie=Z.useRef(null),ae=Z.useRef(f);ae.current=f;let oe=f!==null,se=Z.useRef(0);Z.useEffect(()=>{let e=ie.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),se.current+=e.deltaY;let t=Math.trunc(se.current/mF);if(t===0)return;se.current-=t*mF;let n=ae.current;if(n===null)return;let r=Math.max(0,Math.min(A.current-1,n+t));r!==n&&(P(r),p(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[P,oe]);let ce=f===null?void 0:v[f],le=Math.min(v.length,gF),ue=le*mF,de=v.length*mF-ue,fe=e=>Math.max(0,Math.min(de,e)),pe=Z.useRef(null),me=0;if(f===null)pe.current=null;else if(pe.current===null)me=fe(f*mF-(ue-mF)/2),pe.current=me;else{let e=pe.current,t=(f-_F)*mF,n=(f+1+_F)*mF-ue;e>t?e=t:e<n&&(e=n),me=fe(e),pe.current=me}let he=Math.floor(me/mF),ge=Math.max(0,he-uF),_e=Math.min(v.length,he+le+uF),ve=me>0,ye=me<de,be=ve||ye?`linear-gradient(to bottom, ${ve?`transparent, black 10%`:`black`}, ${ye?`black 90%, transparent`:`black`})`:void 0,xe=Math.max(0,x-uF),Se=Math.min(v.length,S+uF),Ce=v.slice(xe,Se),we=C||w?`linear-gradient(to bottom, ${C?`transparent, black 14%`:`black`}, ${w?`black 86%, transparent`:`black`})`:void 0;return v.length===0?null:(0,$.jsx)(`nav`,{ref:d,"aria-label":s(`chat.promptNavigator.aria`),className:`pointer-events-none absolute right-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-end`,children:[i?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-mr-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,a?`cursor-wait opacity-70`:void 0),"aria-label":D,title:D,disabled:a,onClick:e=>{e.stopPropagation(),a||o()},children:a?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:u,role:`listbox`,tabIndex:-1,"aria-activedescendant":ce?`prompt-rail-tick-${ce.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${g?iF:rF}px`,height:`${y*sF}px`},onMouseMove:W,onMouseLeave:ee,onClick:te,onKeyDown:ne,onBlur:re,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:we?{maskImage:we,WebkitMaskImage:we}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${x*sF}px)`},children:Ce.map((e,t)=>{let r=xe+t,i=e.turnId===n,a=f===r,o=xF(r,f,i);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,"aria-label":e.preview.trim()||T,className:`pointer-events-none absolute right-1 flex items-center justify-end`,style:{top:`${r*sF}px`,height:`${sF}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,i?`bg-[var(--surface-foreground)]`:a?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${o}px`}})},e.turnId)})},v[0]?.turnId)}),ce&&f!==null?(0,$.jsx)(`div`,{ref:ie,className:Y(`pointer-events-auto absolute right-full top-1/2 z-30 mr-3 -translate-y-1/2`,`w-[min(20rem,calc(100vw-6rem))] overflow-hidden rounded-xl`,`border border-[var(--interactive-border)]/60 bg-[var(--surface-elevated)] py-1 shadow-md`),onMouseEnter:H,onMouseLeave:U,onMouseMove:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(`div`,{className:`relative overflow-hidden`,style:{height:`${le*mF}px`,maskImage:be,WebkitMaskImage:be},children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-200 ease-out`,style:{height:`${v.length*mF}px`,transform:`translateY(-${me}px)`},children:v.slice(ge,_e).map((e,t)=>{let r=ge+t,i=e.turnId===n,a=f===r;return(0,$.jsx)(`div`,{role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,title:i?E:void 0,className:`absolute inset-x-0 cursor-pointer px-1.5`,style:{top:`${r*mF+hF}px`,height:`46px`},onMouseMove:()=>{H(),ae.current!==r&&(P(r),p(r))},onClick:()=>K(r),children:(0,$.jsx)(`div`,{className:Y(`flex h-full items-center rounded-lg border px-2 transition-colors`,i?`border-transparent bg-[var(--interactive-selection)]`:a?`border-[var(--interactive-border)]/60 bg-[var(--interactive-hover)]`:`border-[var(--interactive-border)]/40`),children:(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 line-clamp-2 [overflow-wrap:anywhere] typography-meta`,i?`text-[var(--interactive-selectionForeground)]`:`text-[var(--surface-mutedForeground)]`),children:e.preview.trim()||T})})},e.turnId)})})})}):null]})]})})}var CF=100,wF=(e,t)=>{if(e.length===0)return;let n=0,r=e.length-1,i=0;for(;n<=r;){let a=n+r>>1,o=e[a]?.top;if(o===void 0)break;if(o<=t){i=a,n=a+1;continue}r=a-1}return e[i]?.id},TF=e=>{let t=e.raf??requestAnimationFrame,n=e.caf??cancelAnimationFrame,r=e.ResizeObserver??globalThis.ResizeObserver,i=e.MutationObserver??globalThis.MutationObserver,a,o,s,c,l,u,d=!0,f=new Map,p=[],m=()=>{c===void 0&&(c=t(()=>{c=void 0,g()}))},h=()=>{let e=a;if(!e){p=[],d=!1;return}let t=e.getBoundingClientRect().top;p=[...f].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),p.sort((e,t)=>e.top-t.top),d=!1},g=()=>{let t=a;if(!t)return;d&&h();let n=wF(p,t.scrollTop+CF);!n||n===u||(u=n,e.onActive(n))},_=()=>{let e=a;if(e){if(clearTimeout(l),l=void 0,o?.disconnect(),o=void 0,r){o=new r(()=>{clearTimeout(l),l=setTimeout(()=>{d=!0,m()},100)}),o.observe(e);for(let e of f.values())o.observe(e)}if(s?.disconnect(),s=void 0,i){s=new i(()=>{d=!0,m()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}d=!0,m()}},v=e=>{a!==e&&(a=e,u=void 0,_())},y=(e,t)=>{let n=f.get(t);n&&n!==e&&o?.unobserve(n),f.set(t,e),o&&o.observe(e),d=!0,m()},b=e=>{let t=f.get(e);t&&(o?.unobserve(t),f.delete(e),d=!0,m())},x=()=>{d=!0,m()},S=()=>{for(let e of f.values())o?.unobserve(e);f.clear(),p=[],u=void 0,d=!0};return{setContainer:v,register:y,unregister:b,onScroll:m,markDirty:x,clear:S,destroy:()=>{c!==void 0&&n(c),c=void 0,clearTimeout(l),l=void 0,S(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>u}},EF=10,DF=`${EF}vh`,OF=`80px`,kF=`calc(${OF} + var(--oc-chat-foot-inset))`,AF=(e,t)=>e?80:t<=0?96:Math.max(48,EF/100*t),jF=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return!1;switch(e.key){case`ArrowUp`:case`PageUp`:case`Home`:return!0;default:return!1}},MF=(e,t)=>{let n=t instanceof Element?t:t instanceof Node?t.parentElement:null;for(;n&&n!==e;){if(n instanceof HTMLElement&&n.scrollTop>0&&n.scrollHeight>n.clientHeight+1)return!0;n=n.parentElement}return!1},NF=e=>{let t=(0,Q.c)(15),{scrollRef:n,enabled:r,onUpwardIntent:i}=e,a=r===void 0||r,o=Z.useRef(null),s;t[0]===i?s=t[1]:(s=()=>{i()},t[0]=i,t[1]=s);let c=J(s),l;t[2]!==c||t[3]!==n?(l=e=>{let t=n.current;t&&(e.deltaY>=0||t instanceof HTMLElement&&(MF(t,e.target)||c()))},t[2]=c,t[3]=n,t[4]=l):l=t[4];let u=J(l),d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>{let t=e.touches.item(0);o.current=t?t.clientY:null},t[5]=d):d=t[5];let f=J(d),p;t[6]!==c||t[7]!==n?(p=e=>{let t=n.current,r=e.touches.item(0);if(!r){o.current=null;return}let i=o.current;o.current=r.clientY,i!==null&&(r.clientY-i<=2||!t||!(t instanceof HTMLElement)||MF(t,e.target)||c())},t[6]=c,t[7]=n,t[8]=p):p=t[8];let m=J(p),h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{o.current=null},t[9]=h):h=t[9];let g=J(h),_;t[10]===c?_=t[11]:(_=e=>{jF(e)&&c()},t[10]=c,t[11]=_);let v=J(_),[y,b]=Z.useState(null),x;t[12]===n?x=t[13]:(x=()=>{let e=n.current??null;b(t=>t===e?t:e)},t[12]=n,t[13]=x),Z.useEffect(x);let S=a&&y?y:PF,C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C={passive:!0},t[14]=C):C=t[14];let w=C;ot(`wheel`,u,S,w),ot(`touchstart`,f,S,w),ot(`touchmove`,m,S,w),ot(`touchend`,g,S,w),ot(`touchcancel`,g,S,w),ot(`keydown`,v,S)};function PF(){}var FF=(e,t)=>({sessionId:e,viewportKey:t}),IF=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,LF=(e,t)=>IF(e,t),RF=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),zF=150,BF=1500,VF=2,HF=350,UF=600,WF=8e3,GF=24,KF=2,qF=(e,t)=>e<t,JF=()=>typeof performance<`u`?performance.now():Date.now(),YF=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),XF=e=>e.scrollHeight-e.scrollTop-e.clientHeight,ZF=e=>XF(YF(e)),QF=e=>e.scrollHeight-e.clientHeight>1,$F=(e,t)=>XF(e)<=AF(t,e.clientHeight),eI=({enabled:e=!0,currentSessionId:t,viewportKey:n,sessionMessageCount:r,sessionIsWorking:i,isMobile:a,onActiveTurnChange:o,onUpwardUserIntent:s})=>{let c=Z.useRef(null),[l,u]=Z.useState(null),d=Z.useRef(null),[f,p]=Z.useState(`following`),[m,h]=Z.useState(!1),[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),b=Z.useRef(`following`),x=Z.useRef(a);x.current=a;let S=Z.useRef(r);S.current=r;let C=Z.useRef(FF(t,n));C.current=FF(t,n);let w=Z.useRef(null),T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(0),O=Z.useRef(null),k=Z.useRef(null),A=Z.useRef(0),j=Z.useRef(!1),M=Z.useRef(!1),N=Z.useRef(null),P=Z.useRef(0),F=J(()=>{P.current=JF()+450}),I=Z.useRef(0),L=Z.useRef(!1),R=Z.useRef(null),z=Z.useRef(null),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(null),ee=Mn(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{c.current!==d.current&&(d.current=c.current,u(c.current))});let G=J(e=>{b.current!==e&&(b.current=e,p(e))}),K=J(e=>{T.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:JF()},E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{T.current=null,E.current=null},BF)}),te=J(e=>{let t=T.current;return t?JF()-t.time>BF?(T.current=null,!1):Math.abs(e.scrollTop-t.top)<VF:!1}),ne=J(()=>JF()<A.current),re=J(()=>{L.current=!1,R.current&&=(clearTimeout(R.current),null),z.current&&=(clearTimeout(z.current),null)}),ie=J(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,re()},UF)}),ae=J(()=>{let e=c.current;e&&(L.current=!0,B.current=e.scrollHeight,ie(),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{z.current=null,re()},WF))}),oe=J(e=>{let t=c.current;if(!t){h(!1),_(!1);return}let n=e??YF(t),r=QF(n);if(h(r),!r){_(!1);return}let i=b.current===`released`&&!$F(n,x.current);_(i)}),se=J(()=>{D.current+=1,O.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(O.current),O.current=null),k.current?.(),k.current=null});Z.useEffect(()=>()=>se(),[l]);let ce=J(()=>{if(!e)return;let t=c.current;if(!t)return;se();let n=D.current,r=t.style.overflow,i=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,t.style.overflow=`hidden`,t.scrollTop=t.scrollHeight,t.scrollHeight,t.style.overflow=r,t.style.scrollBehavior=i;let a=()=>{K(t),t.scrollTop=t.scrollHeight,I.current=t.scrollTop};if(a(),oe(),typeof window>`u`)return;let o=0,s=()=>{qF(JF(),P.current)||se()};t.addEventListener(`touchstart`,s,{passive:!0,once:!0}),k.current=()=>t.removeEventListener(`touchstart`,s);let l=()=>{if(n===D.current){if(ZF(t)>KF&&a(),o+=1,o>=GF){O.current=null,k.current?.(),k.current=null,oe();return}O.current=window.requestAnimationFrame(l)}};O.current=window.requestAnimationFrame(l)}),le=J(e=>{let t=c.current;if(t){if(K(t),e===`smooth`){t.scrollTo({top:t.scrollHeight,behavior:e});return}t.scrollTop=t.scrollHeight}}),ue=J((t,n=`auto`)=>{if(!e)return;let r=c.current;if(t&&b.current!==`following`&&G(`following`),r&&!(!t&&b.current!==`following`)){if(ZF(r)<VF){K(r);return}le(t?n:`auto`)}}),de=J(e=>{let t=c.current;if(!t)return;let n=e??YF(t);if(!QF(n)){G(`following`);return}b.current!==`released`&&(G(`released`),oe(n))}),fe=J((e=`instant`)=>{if(V.current=!1,G(`following`),re(),e===`instant`){ce();return}se(),ue(!0,`smooth`),oe()}),pe=J(()=>{V.current=!1,ue(!0)}),me=J(()=>{se(),re(),G(`released`),oe()}),he=J(()=>{V.current=!0,me()}),ge=J(()=>{V.current=!1}),_e=Z.useRef(s);_e.current=s;let ve=J(()=>{qF(JF(),P.current)||(se(),re(),de())}),ye=J(()=>{ve(),_e.current?.()}),be=J(()=>{H.current!==null&&(clearTimeout(H.current),H.current=null);let e=U.current;if(e){if(!e.identity.sessionId){U.current=null;return}ee(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),U.current=null}}),xe=J(()=>{let e=C.current;if(!e.sessionId)return;let t=c.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r>0?(n+i/2)/r:0,o=Math.floor(a*S.current);U.current=RF(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),H.current===null&&(H.current=setTimeout(()=>{H.current=null,be()},zF))}),Se=J(()=>{be()}),Ce=J(async(e=C.current)=>{if(!e.sessionId)return!1;V.current=!1;let t=Wi(e.sessionId,e.viewportKey);return c.current?(W.current=null,I.current=t?.scrollPosition?.scrollTop??0,G(`following`),F(),x.current?ce():ue(!0),ae(),oe(),!1):(W.current=e,G(`following`),!1)});Z.useEffect(()=>{let e=C.current,n=w.current;IF(e,n)||(be(),se(),F(),w.current=e,T.current=null,I.current=0,re(),V.current=!1,G(`following`),W.current=null,t&&t!==n?.sessionId&&Wx.getInstance().recordSessionStart(t))},[t,n]),Z.useEffect(()=>{i&&!V.current&&b.current===`following`&&ue(!0)},[i]),Z.useEffect(()=>{y(f===`following`&&i)},[f,i]),Z.useLayoutEffect(()=>{if(!l)return;let e=W.current;e&&LF(e,C.current)&&Ce(e)},[l,t,n]);let we=J(()=>{let e=c.current;if(!e)return;let t=YF(e),n=I.current;I.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(oe(t),V.current){xe();return}if(!QF(t)){G(`following`);return}if($F(t,x.current)){let e=XF(t)<=VF;(r||b.current===`following`||e)&&G(`following`),xe();return}if(b.current===`following`&&(te(e)||ne()||i)){j.current||ue(!1),xe();return}de(t),xe()});Z.useEffect(()=>{!e||!l||(I.current=l.scrollTop)},[l,e]);let Te=Z.useRef(null),Ee=J(e=>{let t=c.current;t&&(e.deltaY>=0||MF(t,e.target)||ye())}),De=J(e=>{let t=e.touches.item(0);Te.current=t?t.clientY:null}),Oe=J(e=>{let t=c.current,n=e.touches.item(0);if(!n){Te.current=null;return}let r=Te.current;Te.current=n.clientY,r!==null&&(n.clientY-r<=2||t&&(MF(t,e.target)||ye()))}),ke=J(()=>{Te.current=null}),Ae=J(e=>{jF(e)&&ye()}),je=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&ve()}),Me=Z.useMemo(()=>()=>void 0,[]),Ne=e&&l?l:Me,Pe=Z.useMemo(()=>({passive:!0}),[]);ot(`scroll`,we,Ne,Pe),ot(`wheel`,Ee,Ne,Pe),ot(`touchstart`,De,Ne,Pe),ot(`touchmove`,Oe,Ne,Pe),ot(`touchend`,ke,Ne,Pe),ot(`touchcancel`,ke,Ne,Pe),ot(`keydown`,Ae,Ne),ot(`pointerdown`,je,e&&typeof window<`u`?window:Me,!0);let Fe=J(()=>{let e=c.current;if(j.current){oe(e?YF(e):void 0);return}if(V.current){oe(e?YF(e):void 0);return}if(!e){oe(void 0);return}let t=YF(e);if(!QF(t)){G(`following`),oe(t);return}if(oe(t),L.current){let n=t.scrollHeight>B.current+1;B.current=t.scrollHeight,XF(t)<=VF?K(e):ue(!0),n&&ie();return}if(b.current===`following`){if(XF(t)<=VF){K(e);return}ue(!1)}}),Ie=typeof ResizeObserver<`u`,Le=Ie&&e?l:null,Re=Ie&&e&&l&&l.firstElementChild instanceof Element?l.firstElementChild:null;st(Le,Fe),st(Re,Fe);let ze=J(()=>{N.current!==null&&(clearTimeout(N.current),N.current=null)}),q=J(e=>{j.current=!0,typeof e==`number`&&e>0?A.current=JF()+e+HF:A.current=Math.max(A.current,JF()+HF)}),Be=J(e=>{let t=e.detail;if(t){if(t.open===!0){q(),ze(),N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},1500);return}ze(),q()}}),Ve=J(e=>{let t=e.detail;t&&(ze(),q(t.durationMs))}),He=J(e=>{let t=e.detail;ze(),t?.open===!0?(M.current=!0,j.current=!0):(M.current=!1,j.current=!0,N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},HF)),oe()}),Ue=e&&typeof window<`u`?window:Me;ot(`oc:keyboard-intent`,Be,Ue),ot(`oc:keyboard-anim`,Ve,Ue),ot(`oc:keyboard-settled`,He,Ue),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{ze(),j.current=!1,M.current=!1}},[e]),Z.useEffect(()=>{e&&oe()},[e,r]);let We=J(t=>{if(e){if(t===`animation`&&(A.current=JF()+HF),oe(),L.current){ue(!0),ie();return}b.current===`following`&&ue(!1)}}),Ge=Z.useRef(new Map),Ke=J(t=>{let n=Ge.current.get(t);if(n)return n;let r=()=>{e&&b.current===`following`&&ue(!1)},i={onChunk:r,onComplete:()=>{e&&oe()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return Ge.current.set(t,i),i});Z.useEffect(()=>()=>{E.current&&=(clearTimeout(E.current),null),se(),re(),be(),H.current!==null&&(clearTimeout(H.current),H.current=null)},[]);let qe=J(e=>{o?.(e)}),Je=!!o;return Z.useEffect(()=>{if(!e||!Je)return;let t=l;if(!t)return;let n=null,r=TF({onActive:e=>{e!==n&&(n=e,qe(e))}});r.setContainer(t);let i=new Map,a=e=>{let t=e.dataset.turnId;return t?(i.set(t,e),r.register(e,t),!0):!1},o=e=>{let t=e.dataset.turnId;return!t||i.get(t)!==e?!1:(i.delete(t),r.unregister(t),!0)},s=e=>{if(!(e instanceof HTMLElement))return[];let t=[];return e.matches(`[data-turn-id]`)&&t.push(e),e.querySelectorAll(`[data-turn-id]`).forEach(e=>t.push(e)),t};t.querySelectorAll(`[data-turn-id]`).forEach(a),r.markDirty();let c=new MutationObserver(e=>{let t=!1;e.forEach(e=>{e.removedNodes.forEach(e=>{s(e).forEach(e=>{o(e)&&(t=!0)})}),e.addedNodes.forEach(e=>{s(e).forEach(e=>{a(e)&&(t=!0)})})}),t&&r.markDirty()});c.observe(t,{subtree:!0,childList:!0});let u=()=>r.onScroll();return t.addEventListener(`scroll`,u,{passive:!0}),()=>{t.removeEventListener(`scroll`,u),c.disconnect(),r.destroy()}},[l,e,Je]),{scrollRef:c,state:f,isPinned:f===`following`,isOverflowing:m,isFollowingProgrammatically:v,showScrollButton:g,notifyContentChange:We,getAnimationHandlers:Ke,goToBottom:fe,scrollToBottomOnSend:pe,releaseAutoFollow:me,beginHistoryViewportPreservation:he,endHistoryViewportPreservation:ge,saveSnapshotNow:Se,restoreSnapshot:Ce}},tI=`--oc-mobile-composer-swap`,nI=`--oc-native-composer-dock`,rI=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),iI=(e,t,n)=>Math.min(n,Math.max(t,e)),aI=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,oI=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return aI(e,n)?e:n},sI=(e,t)=>t?oI(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?oI(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,cI=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:oI(e,{phase:`snapping`,rest:t,progress:n})},lI=e=>iI(e/80,0,1),uI=e=>e>=80?1:iI(e/80,0,1),dI=(e,t,n={})=>{if(e.pinned)return e;let r=Math.max(0,t),i=e.phase===`snapping`?oI(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(i.rest===`expanded`){if(r<=2||n.holdExpanded||n.userDriven===!1)return oI(i,{phase:`rest`,rest:`expanded`,progress:0});let e=lI(r);return e>=1?oI(i,{phase:`rest`,rest:`compact`,progress:1}):oI(i,{phase:`tracking`,rest:`expanded`,progress:e})}if(r<=2)return oI(i,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn)return oI(i,{phase:`rest`,rest:`compact`,progress:1});if(n.towardBottom&&r>=80)return oI(i,{phase:`snapping`,rest:`expanded`,progress:0});let a=uI(r);return a>=1?oI(i,{phase:`rest`,rest:`compact`,progress:1}):oI(i,{phase:`tracking`,rest:`compact`,progress:a})},fI=e=>e.pinned?`expanded`:e.rest===`expanded`?e.progress>=.5?`compact`:`expanded`:e.progress<=.5?`expanded`:`compact`,pI=e=>{if(e.pinned)return oI(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let t=fI(e),n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:oI(e,{phase:`snapping`,rest:t,progress:n})},mI=e=>e.phase===`snapping`?oI(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,hI=e=>iI(Math.max(0,e)/80,0,1),gI=(e,t=`away`)=>{let n=Math.max(0,e);return n<=2?{progress:0,rest:`bottom`}:t===`away`||n>=40?{progress:1,rest:`away`}:{progress:hI(n),rest:`bottom`}},_I=e=>{e.style.removeProperty(tI),e.style.removeProperty(nI),delete e.dataset.ocComposerSwapPhase,delete e.dataset.ocComposerSwapRest,delete e.dataset.ocNativeComposerDock},vI=(e,t,n)=>{let r=gI(t,n?.rest===`bottom`?`bottom`:`away`),i=String(r.progress),a=r.rest;return n?.progress!==i&&e.style.setProperty(nI,i),n?.rest!==a&&(e.dataset.ocNativeComposerDock=a),{progress:i,rest:a}},yI=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest;return n?.phase!==i&&(e.dataset.ocComposerSwapPhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty(tI,r),n?.rest!==a&&(e.dataset.ocComposerSwapRest=a),{progress:r,phase:i,rest:a}},bI=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),xI=()=>{let e=document.documentElement;return e.classList.contains(`oc-keyboard-open`)||e.classList.contains(`oc-kb-animating`)},SI=e=>{if(xI()||e.querySelector(`[data-oc-composer-dictation-active="true"]`))return!0;let t=document.activeElement;return t instanceof HTMLElement&&t.matches(`textarea[data-chat-input="true"]`)&&e.contains(t)},CI=e=>{let t=Z.useRef(rI()),n=Z.useRef(void 0),r=Z.useRef(void 0),i=Z.useRef(null),a=Z.useRef(null),o=Z.useRef(0),s=Z.useRef(!1),c=Z.useRef(0),l=Z.useRef(0),u=Z.useRef(null),d=Z.useRef(0),f=Z.useRef(0),p=Z.useRef(!1),m=Z.useRef(e.enabled);m.current=e.enabled;let h=e=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null)},g=J(t=>{let r=e.scopeRef.current;r&&(n.current=yI(r,t,n.current))}),_=J(e=>{e!==t.current&&(t.current=e,g(e))}),v=J(()=>{if(h(a),t.current.phase!==`snapping`)return;let e=t.current.rest;a.current=window.setTimeout(()=>{a.current=null;let n=mI(t.current);_(n),n.rest===`compact`&&e===`compact`&&(o.current=Date.now()+320,s.current=!0)},240)}),y=J(()=>{let n=e.scopeRef.current;!n||!m.current||_(sI(t.current,SI(n)))}),b=J(e=>s.current?Date.now()>=o.current?(s.current=!1,!1):e>=80?(s.current=!1,o.current=0,!1):!0:!1),x=J(()=>{if(h(i),!m.current||c.current>0||t.current.phase!==`tracking`)return;let e=pI(t.current);_(e),v()}),S=J(()=>{m.current&&(l.current=Date.now())}),C=J(()=>{m.current&&(l.current=Date.now(),c.current+=1,h(i))}),w=J(()=>{if(!m.current)return;let n=e.scrollRef.current,a=e.scopeRef.current;if(!n||!a)return;let o=SI(a),s=bI(n),g=_M(s,hM(n)),y=u.current;if(u.current=g,n.hasAttribute(`data-oc-timeline-anchoring`)){d.current=0,f.current=0;return}r.current=vI(a,g,r.current);let S=c.current>0||Date.now()-l.current<=1200,C=y===null?0:y-g;S?C>0?(f.current=0,s.scrollTop>0&&(d.current+=C)):C<0&&(d.current=0,f.current+=-C,f.current>=24&&(p.current=!1)):(d.current=0,f.current=0),g<=2&&(p.current=!1);let w=sI(t.current,o);if(!o){let e=w.rest===`compact`;w=dI(w,g,{suppressReturn:b(g),towardBottom:d.current>=24,holdExpanded:p.current,userDriven:S}),e&&w.rest===`expanded`&&g>2&&(p.current=!0,d.current=0)}if(_(w),h(i),w.phase===`snapping`){v();return}w.phase===`tracking`&&c.current===0&&(i.current=window.setTimeout(()=>{i.current=null,x()},120))}),T=J(()=>{x()}),E=J(()=>{m.current&&(l.current=Date.now(),c.current=Math.max(0,c.current-1),!(c.current>0)&&t.current.phase===`tracking`&&(h(i),i.current=window.setTimeout(()=>{i.current=null,x()},120)))}),D=J(()=>{let t=e.scopeRef.current;if(!t||typeof window>`u`)return;let n=e=>{e.preventDefault(),e.stopPropagation()};t.addEventListener(`pointerup`,n,!0),t.addEventListener(`click`,n,!0),window.setTimeout(()=>{t.removeEventListener(`pointerup`,n,!0),t.removeEventListener(`click`,n,!0)},240)}),O=J(n=>{if(!m.current)return;let r=n.target;r instanceof Element&&r.closest(`[data-oc-composer-compact-surface="true"]`)&&(r.closest(`[data-composer-action="true"]`)||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),p.current=!0,d.current=0,f.current=0,_(cI(t.current,`expanded`)),v(),D(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0})))}),[k,A]=Z.useState(null),[j,M]=Z.useState(null),N=Z.useRef(null),P=J(e=>{e&&_I(e),n.current=void 0,r.current=void 0,s.current=!1,o.current=0,c.current=0,l.current=0,u.current=null,d.current=0,f.current=0,p.current=!1,_(rI())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;N.current&&N.current!==n&&P(N.current),N.current=n,A(e=>e===t?e:t),M(e=>e===n?e:n)});let F=Z.useMemo(()=>()=>void 0,[]),I=e.enabled&&k?k:F,L=e.enabled&&j?j:F,R=e.enabled&&typeof window<`u`?window:F,z=Z.useMemo(()=>({passive:!0}),[]);ot(`scroll`,w,I,z),ot(`scrollend`,T,I,z),ot(`touchstart`,C,I,z),ot(`touchmove`,S,I,z),ot(`touchend`,E,I,z),ot(`touchcancel`,E,I,z),ot(`pointerdown`,O,L),ot(`focusin`,y,L),ot(`focusout`,y,L),ot(`oc:keyboard-intent`,y,R),ot(`oc:keyboard-anim`,y,R),ot(`oc:keyboard-settled`,y,R),Z.useEffect(()=>{if(!e.enabled){P(N.current),N.current=null;return}return y(),w(),()=>{h(i),h(a)}},[e.enabled,k,j])},wI=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},TI=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},EI=e=>{if(!e)return null;let t=wI(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${TI(e)??``}`},DI=e=>({turnIds:[...e.turnIds],turnMessageStartIndexes:[...e.turnMessageStartIndexes],turnIndexById:new Map(e.turnIndexById),messageToTurnId:new Map(e.messageToTurnId),messageToTurnIndex:new Map(e.messageToTurnIndex),turnCount:e.turnCount}),OI=(e,t,n)=>{if(!e||!t)return null;if(t.length===n.length){let r=-1;for(let e=0;e<n.length;e+=1)if(t[e]!==n[e]){if(r!==-1)return null;r=e}return r===-1||r===n.length-1&&EI(t[r])===EI(n[r])?e:null}if(n.length!==t.length+1)return null;for(let e=0;e<t.length;e+=1)if(t[e]!==n[e])return null;let r=n[n.length-1];if(!r)return null;let i=wI(r),a=r.info.id,o=DI(e);if(i===`user`){let e=o.turnIds.length;return o.turnIds.push(a),o.turnMessageStartIndexes.push(n.length-1),o.turnIndexById.set(a,e),o.messageToTurnId.set(a,a),o.messageToTurnIndex.set(a,e),o.turnCount=o.turnIds.length,o}if(i!==`assistant`){let e=o.turnIds.length-1;if(e<0)return null;let t=o.turnIds[e];return t?(o.messageToTurnId.set(a,t),o.messageToTurnIndex.set(a,e),o):null}let s=TI(r);if(!s)return o;let c=o.turnIndexById.get(s);if(typeof c!=`number`||c<0)return null;let l=o.turnIds[c];return l?(o.messageToTurnId.set(a,l),o.messageToTurnIndex.set(a,c),o):null},kI=e=>{let t=[],n=[],r=new Map,i=new Map,a=new Map,o=new Map,s=-1;return e.forEach((e,c)=>{let l=wI(e),u=e.info.id;if(l===`user`){s=t.length,t.push(u),n.push(c),r.set(u,s),o.set(u,s),i.set(u,u),a.set(u,s);return}if(l!==`assistant`){if(s>=0){let e=t[s];e&&(i.set(u,e),a.set(u,s))}return}let d=TI(e);if(!d)return;let f=o.get(d);if(typeof f!=`number`||f<0)return;let p=t[f];p&&(i.set(u,p),a.set(u,f))}),{turnIds:t,turnMessageStartIndexes:n,turnIndexById:r,messageToTurnId:i,messageToTurnIndex:a,turnCount:t.length}},AI=200,jI={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},MI=()=>AI,NI=()=>Math.round(MI()*.6),PI={MAX_SESSIONS:jI.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(AI*.6),HISTORICAL_MESSAGES:AI,FETCH_BUFFER:20,HISTORY_CHUNK:AI,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:jI.ZOMBIE_TIMEOUT},FI=()=>{let e=MI(),t=NI();return{...PI,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},II=PI,LI=600,RI=6e3,zI=.5,BI=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),VI=e=>{let t=e.getBoundingClientRect(),n=e.querySelectorAll(`[data-message-id]`);for(let e of n)if(e.getBoundingClientRect().bottom>t.top)return e;return null},HI=(e,t)=>{let n=BI(e,t);if(n||=VI(e),!n)return null;let r=n.dataset.messageId;if(!r)return null;let i=e.getBoundingClientRect();return{messageId:r,offsetTop:n.getBoundingClientRect().top-i.top}},UI=e=>{let{container:t,quiesceMs:n=LI,maxLifetimeMs:r=RI}=e,i={messageId:e.anchor.messageId,offsetTop:e.anchor.offsetTop},a=!1,o=null,s=null,c=!1,l=t.scrollTop,u=()=>{o!==null&&(clearTimeout(o),o=null)},d=()=>{s!==null&&(clearTimeout(s),s=null)},f=()=>{a||(a=!0,y.disconnect(),t.removeEventListener(`scroll`,v),u(),d())},p=()=>{u(),!a&&(o=setTimeout(()=>{o=null,f()},n))},m=()=>{d(),!a&&(s=setTimeout(()=>{s=null,f()},r))},h=()=>{if(a)return;let e=HI(t,i.messageId);if(!e){f();return}i.messageId=e.messageId,i.offsetTop=e.offsetTop,l=t.scrollTop},g=()=>{if(a)return;if(Math.abs(t.scrollTop-l)>zI){h();return}let e=BI(t,i.messageId);if(!e){let n=VI(t);if(!n){f();return}let r=n.dataset.messageId;if(!r){f();return}let a=t.getBoundingClientRect();i.messageId=r,i.offsetTop=n.getBoundingClientRect().top-a.top,e=n,l=t.scrollTop}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect().top-n.top-i.offsetTop;Math.abs(r)>zI&&(t.scrollTop+=r),l=t.scrollTop},_=()=>{a||c||(c=!0,queueMicrotask(()=>{c=!1,g()}))},v=()=>{h(),p(),m()},y=new MutationObserver(()=>{a||(_(),p())});return y.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`style`,`class`]}),t.addEventListener(`scroll`,v,{passive:!0}),m(),p(),{rebase:h,dispose:f}},WI=30,GI=1200,KI=1.5,qI=e=>Math.max(GI,e*KI),JI=4,YI=30,XI=4,ZI=30,QI=250,$I=2e3,eL=Nt+2e3,tL=40,nL=`history-loading-timeout`,rL=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),iL=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=nL,e},aL=(e,t,n)=>{if(e===`no-growth`){console.error(`[chat-history] load older completed without prepending messages`,t instanceof Error?t:Error(`chat history pagination returned no growth`),n);return}if(e===`timeout`){console.error(`[chat-history] load older timed out waiting for sync pagination`,t,n);return}console.error(`[chat-history] load older failed`,t,n)},oL=2500,sL=new Map,cL=()=>se()?JI:cn()?XI:WI,lL=e=>se()?e.length<=YI:!cn()||e.length<=ZI,uL=(e,t)=>{if(sL.delete(e),!lL(t.messages))return;let n=cL();for(;sL.size>=n;){let e=sL.keys().next().value;if(typeof e!=`string`)break;sL.delete(e)}sL.set(e,t)},dL=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),fL=e=>e?{owner:`tanstack-core`}:{owner:`controller`},pL=(e,t)=>e?e.canLoadEarlier:t>=FI().HISTORICAL_MESSAGES,mL=e=>!(e.isMobile||e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=qI(e.clientHeight)),hL=e=>e.pagesLoaded>=e.maxPages?`stop-bounded`:e.hasMoreAbove?e.scrollHeightAfter-e.scrollHeightBefore>1?`stop-visible`:e.messageCountAfter>e.messageCountBefore||typeof e.oldestIdBefore==`string`&&typeof e.oldestIdAfter==`string`&&e.oldestIdBefore!==e.oldestIdAfter||e.limitAfter>e.limitBefore?`continue`:`stop-no-growth`:`stop-exhausted`,gL=1,_L=8,vL=e=>!(!e.enabled||e.isMobile||!e.sessionReady||!e.messageReady||e.historyLoading||!e.canLoadEarlier||!e.isPinned||e.fillBlocked||e.pendingRevealWork||e.isLoadingOlder||!e.hasMessages||e.clientHeight<=0||e.scrollHeight>e.clientHeight+48),yL=e=>[`chat-timeline-auto-fill`,e.runtimeKey,e.sessionId,e.oldestMessageId,e.messageCount,e.canLoadEarlier],bL=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],xL=20,SL=4,CL=80,wL=new WeakMap,TL=new WeakMap,EL=e=>{let t=TL.get(e)??{generation:0};return t.generation+=1,TL.set(e,t),t.generation},DL=e=>{let t=wL.get(e);t&&(t.touches=0,t.pending=null,t.settleScheduled=!1),EL(e)},OL=e=>{kL(e)},kL=e=>{let t=wL.get(e);if(t)return t;let n={touches:0,pending:null,settleScheduled:!1};e.addEventListener(`touchstart`,()=>{n.touches+=1},{passive:!0});let r=()=>{n.touches=Math.max(0,n.touches-1),n.touches===0&&n.pending&&AL(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),wL.set(e,n),n},AL=(e,t)=>{t.settleScheduled||typeof window>`u`||(t.settleScheduled=!0,window.requestAnimationFrame(()=>{t.settleScheduled=!1;let n=t.pending;t.pending=null,!(!n||t.touches>0||!e.isConnected)&&(Math.abs(e.scrollTop-n.anchorTop)>n.delta+CL||jL(e,n.anchorTop+n.delta))}))},jL=(e,t)=>{let n=EL(e),r=e.style.overflow;if(e.style.overflow=`hidden`,e.scrollTop=t,e.scrollHeight,e.style.overflow=r,e.scrollTop=t,typeof window>`u`)return;let i=!1,a=0,o=()=>{i=!0};e.addEventListener(`touchstart`,o,{passive:!0,once:!0});let s=()=>{if(!i){if((TL.get(e)?.generation??0)!==n){e.removeEventListener(`touchstart`,o);return}e.scrollTop<t-SL&&(e.scrollTop=t),a+=1,a<xL?window.requestAnimationFrame(s):e.removeEventListener(`touchstart`,o)}};window.requestAnimationFrame(s)},ML=(e,t,n)=>{let r=kL(e);if(r.touches>0&&typeof n==`number`&&n>0){r.pending=r.pending?{anchorTop:r.pending.anchorTop,delta:r.pending.delta+n}:{anchorTop:e.scrollTop,delta:n};return}r.pending=null,jL(e,t)},NL=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),PL=(e,t)=>e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight?e:t,FL=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:o,loadMoreMessages:s,goToBottom:c,releaseAutoFollow:l,beginHistoryViewportPreservation:u,endHistoryViewportPreservation:d,isPinned:f,showScrollButton:p,autoFillEnabled:m=!1,onWillLoadEarlier:h})=>{let g=Z.useRef(null),_=Z.useRef(null),v=Z.useMemo(()=>{let t=e??``,r=t?sL.get(t):void 0;if(r&&r.messages===n)return uL(t,r),g.current=r.model,_.current=n,r.model;let i=OI(g.current,_.current,n)??kI(n);return g.current=i,_.current=n,t&&n.length>0&&uL(t,{messages:n,model:i}),i},[n,e]),[y,b]=Z.useState(!1),[x,S]=Z.useState(!1),[C,w]=Z.useState(null),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState({scrollHeight:0,clientHeight:0}),j=Z.useRef(v),M=Z.useRef(f),N=Z.useRef(y),P=Z.useRef(x),F=Z.useRef(e),I=Z.useRef(t??null),L=Z.useRef(n),R=Z.useRef(r),z=Z.useRef(D),B=Z.useRef([]),V=Z.useRef(null),H=Z.useRef(null),U=Z.useRef(!1),W=Z.useRef(null),[ee,G]=Z.useState(e);ee!==e&&(G(e),W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null),U.current=!1,N.current=!1,H.current=null,b(!1),S(!1),w(null),E(!1),z.current=null,O(null),A({scrollHeight:0,clientHeight:0}));let K=Z.useMemo(()=>{let e=r?.limit!==D&&pL(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),te=Z.useRef(K);j.current=v,M.current=f,P.current=x,te.current=K,F.current=e,I.current=t??null,L.current=n,R.current=r,z.current=D;let ne=J(()=>{U.current=!0,W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null)}),re=J(()=>{if(typeof window>`u`){U.current=!1;return}W.current!==null&&window.clearTimeout(W.current),W.current=window.setTimeout(()=>{W.current=null,U.current=!1},$I)}),ie=J(()=>{let e=B.current;e.length!==0&&(B.current=[],e.forEach(e=>e()))}),ae=J(()=>new Promise(e=>{if(typeof window>`u`){e();return}let t=!1,n=()=>{t||(t=!0,window.clearTimeout(r),e())};B.current.push(n);let r=window.setTimeout(n,QI)})),oe=J(e=>{let t=V.current;t&&(V.current=null,t.resolve(e))}),se=J(()=>{let e=V.current;if(e){if(e.sessionId!==F.current){oe(!1);return}if(e.kind===`turn`?o.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:o.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(H.current={turnId:e.turnId,expiresAt:Date.now()+oL},w(e.turnId)),oe(!0);return}typeof(e.kind===`turn`?j.current.turnIndexById.get(e.id):j.current.messageToTurnIndex.get(e.id))==`number`&&oe(!1)}}),ce=Z.useRef(null),le=J(()=>{let e=ce.current;e&&(ce.current=null,e.dispose())});nt(()=>{W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null),le(),ie(),oe(!1)});let ue=n;at(()=>{ie(),se()},[ue]);let de=J(()=>{let e=i.current;if(!e){A(e=>PL(e,{scrollHeight:0,clientHeight:0}));return}A(t=>PL(t,{scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))});st(typeof ResizeObserver<`u`?i:null,de),at(()=>{de()},[e,y]);let fe=Z.useRef(null),pe=J(()=>o.current?.captureViewportAnchor()??null),me=J(e=>o.current?.restoreViewportAnchor(e)??!1),he=J(()=>{if(cn())return;le();let e=i.current;if(!e)return;let t=pe();t&&(ce.current=UI({container:e,anchor:t}))}),ge=Z.useRef(null);at(()=>{if(!cn())return;let e=i.current;e&&(OL(e),DL(e))},[e,i]),at(()=>{le(),fe.current=null,ge.current=null,o.current?.cancelViewportAnchorHold()},[e]),at(()=>{let e=i.current;if(!e)return;let t=fe.current;t&&Math.abs(e.scrollTop-t.top)>_L&&(fe.current=null,t=null);let n=ge.current,r=ue[0]?.info?.id??null,a=ue[ue.length-1]?.info?.id??null,s=n?dL({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:a})||NL(n.oldestId,r,ue):!1;t&&t.sessionId!==F.current&&(fe.current=null,t=null);let l=t?dL({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:a})||NL(t.oldestId,r,ue):!1,u=s||l,d=e=>{ge.current={oldestId:r,newestId:a,scrollHeight:e??ge.current?.scrollHeight??0}};if(M.current&&!t){le(),u?(fe.current=null,c(`instant`),d(e.scrollHeight)):d();return}let f=fL(o.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){o.current?.cancelViewportAnchorHold();let e=t.anchor;e&&me(e),d();return}let n=e.scrollHeight,r=n-t.height;if(cn()){r>0&&ML(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&me(i))&&r>0&&(e.scrollTop=t.top+r),d(n);return}if(s&&n&&f.owner===`controller`){let t=e.scrollHeight,r=t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;cn()?ML(e,t,r):e.scrollTop=t}d(t),he();return}d()},[ue,c]);let _e=J(async()=>!1),ve=J(async e=>{let t=Date.now(),n=t+eL,r=I.current,i=r?Pr()?.getRequestState?.(Bi(r,e)):void 0;for(te.current.historyLoading,R.current,i?.status,i?.error;te.current.historyLoading;){if(F.current!==e)return Date.now()-t,`switched`;if(Date.now()>=n){let n=r?Pr()?.getRequestState?.(Bi(r,e)):void 0;return console.error(`[chat-history] historyLoading wait timed out — sync flag still true`,{sessionId:e,directory:r,elapsedMs:Date.now()-t,waitMs:eL,hostTurnPageTimeoutMs:Nt,historyLoading:te.current.historyLoading,historyMeta:R.current,requestStatusAtStart:i?.status??null,requestStatusAtTimeout:n?.status??null,requestErrorAtTimeout:n?.error??null,likelyStaleLoadingFlag:n?.status===`ready`||n?.status===`error`||n==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,tL)})}return Date.now()-t,r&&Pr()?.getRequestState?.(Bi(r,e))?.status,F.current===e?`cleared`:`switched`}),ye=J(async e=>{if(!F.current||N.current||!te.current.hasMoreAboveTurns)return!1;N.current=!0,ne(),b(!0);let t=F.current,n=null,r=!!e.userInitiated;r&&u();let a=()=>{n&&fe.current===n&&(fe.current=null,o.current?.cancelViewportAnchorHold()),r&&(r=!1,d())};try{if(te.current.historyLoading){if(!e.userInitiated)return!1;let n=await ve(t);if(n===`timeout`)throw iL();if(n===`switched`||!te.current.hasMoreAboveTurns)return!1}if(!F.current||F.current!==t)return!1;let r=i.current,o=L.current,c=o.length,l=o[0]?.info?.id??null,u=R.current?.limit??FI().HISTORICAL_MESSAGES;e.preserveViewport&&r&&(n={sessionId:F.current,height:r.scrollHeight,top:r.scrollTop,anchor:pe(),oldestId:l,newestId:o[o.length-1]?.info?.id??null},fe.current=n,he());let d=c,f=l,p=u,m=0;for(;;){if(te.current.historyLoading)if(e.userInitiated){let e=await ve(t);if(e===`timeout`)throw a(),iL();if(e===`switched`)return a(),!1}else return a(),!1;let n=i.current?.scrollHeight??0,r=d,o=f,c=p;if(await s(t,`up`),m+=1,F.current!==t)return a(),!1;await ae();let l=L.current,u=l.length,h=l[0]?.info?.id??null,g=R.current?.limit??p,_=hL({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:r,messageCountAfter:u,oldestIdBefore:o,oldestIdAfter:h,limitBefore:c,limitAfter:g,hasMoreAbove:te.current.hasMoreAboveTurns,pagesLoaded:m,maxPages:gL});if(_===`continue`){d=u,f=h,p=g;continue}if(_===`stop-no-growth`){if(te.current.historyLoading){if(e.userInitiated){let e=await ve(t);if(e===`timeout`)throw a(),iL();if(e===`switched`)return a(),!1;--m;continue}return a(),!1}let n=R.current?.limit??c;return z.current=n,O(n),te.current={...te.current,hasMoreAboveTurns:!1,canLoadEarlier:!1},a(),!1}return!0}}catch(e){throw a(),e}finally{N.current=!1,b(!1),re(),ae().then(a)}}),{t:be}=ct(),xe=Ke({mutationKey:bL({runtimeKey:a(),sessionId:e??``}),mutationFn:async e=>{if(F.current!==e.sessionId)return!1;ne(),e.userInitiated&&l();try{return await ye({preserveViewport:!0,userInitiated:!!e.userInitiated})}finally{re()}}}),Se=J(async e=>{let t=F.current;if(t&&!(xe.isPending&&xe.variables?.sessionId===t)){e?.userInitiated&&h?.();try{let n=await xe.mutateAsync({sessionId:t,userInitiated:!!e?.userInitiated});if(n===!1&&te.current.canLoadEarlier){let r={sessionId:t,grew:n,userInitiated:!!e?.userInitiated,canLoadEarlier:te.current.canLoadEarlier,hasMoreAboveTurns:te.current.hasMoreAboveTurns,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};aL(`no-growth`,Error(`chat history pagination returned no growth`),r),e?.userInitiated&&Br.error(be(`chat.history.loadOlderFailed`))}}catch(n){let r={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:eL,hostTurnPageTimeoutMs:Nt,canLoadEarlier:te.current.canLoadEarlier,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};rL(n)?aL(`timeout`,n,r):aL(`failed`,n,r),e?.userInitiated&&Br.error(rL(n)?be(`chat.history.loadOlderTimeout`):be(`chat.history.loadOlderFailed`))}}}),Ce=xe.isPending&&xe.variables?.sessionId===e||y,we=n[0]?.info?.id??null,Te=vL({enabled:m,isMobile:cn(),sessionReady:!!e,messageReady:n.length>0||!!r,historyLoading:K.historyLoading,canLoadEarlier:K.canLoadEarlier,isPinned:f,fillBlocked:T,scrollHeight:k.scrollHeight,clientHeight:k.clientHeight,pendingRevealWork:x,isLoadingOlder:!1,hasMessages:n.length>0});qe({queryKey:yL({runtimeKey:a(),sessionId:e??``,oldestMessageId:we,messageCount:n.length,canLoadEarlier:K.canLoadEarlier}),enabled:!!e&&Te,staleTime:1/0,gcTime:0,retry:(e,t)=>t?.code===`auto-fill-busy`&&e<40,retryDelay:50,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,queryFn:async()=>{let e=F.current;if(!e)return{status:`skip`};if(te.current.historyLoading||N.current){let e=Error(`auto-fill-busy`);throw e.code=`auto-fill-busy`,e}if(!te.current.canLoadEarlier)return{status:`skip`};let t=i.current;if(!t||t.clientHeight<=0)return{status:`skip`};if(t.scrollHeight>t.clientHeight+48)return{status:`tall`};try{let t=await ye({preserveViewport:!0});return t?{status:`grew`}:(te.current.canLoadEarlier&&aL(`no-growth`,Error(`chat history pagination returned no growth`),{sessionId:e,source:`auto-fill`,grew:t,canLoadEarlier:te.current.canLoadEarlier,hasMoreAboveTurns:te.current.hasMoreAboveTurns,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null}),E(!0),{status:`blocked`})}catch(t){if(t?.code===`auto-fill-busy`)throw t;let n={sessionId:e,source:`auto-fill`,waitMs:eL,canLoadEarlier:te.current.canLoadEarlier,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};throw rL(t)?aL(`timeout`,t,n):aL(`failed`,t,n),E(!0),t instanceof Error?t:Error(`chat timeline auto-fill failed`)}}});let Ee=J(e=>{let t=i.current;t&&mL({source:e,isMobile:cn(),isPinned:M.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:te.current.canLoadEarlier,isLoadingOlder:N.current,pendingRevealWork:P.current})&&Se({userInitiated:!0})}),De=J(()=>{Ee(`scroll`)}),Oe=J(()=>{Ee(`upward-intent`)}),ke=J(async(t,n)=>{if(!t||!F.current)return!1;l(),S(!0);try{return F.current!==e||typeof j.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{V.current={sessionId:F.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},se()})}finally{S(!1)}}),Ae=J(async(t,n)=>{if(!t||!F.current)return!1;l(),S(!0);try{if(F.current!==e)return!1;let r=j.current.messageToTurnId.get(t);return typeof j.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(i=>{V.current={sessionId:F.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:r??null,resolve:i},se()})}finally{S(!1)}}),je=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`smooth`)}),Me=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`instant`)}),Ne=J(e=>{let t=H.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;H.current=null}w(e)});return{turnIds:v.turnIds,turnStart:0,renderedMessages:ue,historySignals:K,isLoadingOlder:Ce,pendingRevealWork:x,activeTurnId:C,showScrollToBottom:p&&!x,turnWindowModel:v,loadEarlier:Se,revealBufferedTurns:_e,resumeToBottom:je,resumeToBottomInstant:Me,scrollToTurn:ke,scrollToMessage:Ae,handleHistoryScroll:De,handleHistoryUpwardIntent:Oe,captureViewportAnchor:pe,restoreViewportAnchor:me,handleActiveTurnChange:Ne}},IL=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),LL=({open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s=!1,isLoadingEarlier:c=!1,onLoadEarlier:l,onRevertMessage:u})=>{let{t:d}=ct(),f=Lh(),p=n,m=Ur(p??``,r),h=ri(e=>e.revertToMessage),g=ri(e=>e.forkFromMessage),_=IL(f.capabilities),{isMobile:v,isTablet:y}=mo(),b=v||y,[x,S]=Z.useState(null),C=Z.useRef(!1),[w,T]=Z.useState(``),[E,D]=Z.useState(0),O=Z.useRef([]),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(!1),M=Z.useRef(e),N=e=>new Date(e).toLocaleDateString(lt(),{year:`numeric`,month:`short`,day:`numeric`}),P=e=>new Date(e).toLocaleTimeString(lt(),{hour:`numeric`,minute:`2-digit`}),F=Z.useMemo(()=>m.filter(e=>e.info.role===`user`).map(e=>({message:e})),[m]),I=Z.useMemo(()=>{let e=w.trim();if(!e)return F;let t=e.toLowerCase();return F.filter(({message:e})=>eF(e.parts).toLowerCase().includes(t))},[F,w]);Z.useEffect(()=>{j.current||D(w.trim()?0:Math.max(0,I.length-1))},[I,w]),Z.useEffect(()=>{O.current=O.current.slice(0,I.length)},[I.length]),Z.useEffect(()=>{j.current||O.current[E]?.scrollIntoView({block:`nearest`})},[E]),Z.useEffect(()=>{!j.current||A.current||c||(j.current=!1)},[I.length,c]),Z.useLayoutEffect(()=>{let t=M.current;if(M.current=e,!e||t||j.current||w.trim())return;let n=k.current;n&&(n.scrollTop=n.scrollHeight)},[e,w]),Z.useLayoutEffect(()=>{let e=A.current,t=k.current;if(!e||!t||c)return;A.current=null;let n=O.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},[I.length,c]);let L=J(()=>{let e=k.current;if(e){let t=e.getBoundingClientRect().top,n=O.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(A.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}j.current=!0,l?.()}),R=J(async e=>{await i?.(e)!==!1&&t(!1)}),z=J(e=>{let t=I.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),D(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),D(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(E%t+t)%t,r=I[n];r&&R(r.message.info.id)}}}),B=J(async(e,n)=>{if(!(!p||C.current)){C.current=!0,S({type:e,messageId:n});try{e===`revert`?u?await u(n):await h(p,n,{directory:r}):await g(p,n,{directory:r}),t(!1)}finally{C.current=!1,S(null)}}});return p?(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),d(`chat.timeline.title`)]}),(0,$.jsx)(aa,{children:d(`chat.timeline.description`)})]}),(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{autoFocus:!0,placeholder:d(`chat.timeline.searchPlaceholder`),value:w,onChange:e=>T(e.target.value),onKeyDown:z,className:`pl-9 w-full`})]}),s&&l&&(0,$.jsx)(`div`,{className:`flex justify-center py-1`,children:(0,$.jsxs)(ua,{type:`button`,variant:`link`,size:`sm`,onClick:L,disabled:c,className:`h-auto px-1 py-0 text-muted-foreground hover:text-foreground`,children:[c&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),d(`chat.history.loadOlder`)]})}),(0,$.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto`,children:I.length===0?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:d(w?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):I.map(({message:e},t)=>{let n=tF(e.parts),r=e.info.time.created,i=N(r),a=I[t-1],o=i!==(a?N(a.message.info.time.created):null),s=P(r),c=t===E,l=w.trim()?RL(eF(e.parts),w):null;return(0,$.jsxs)(Z.Fragment,{children:[o&&(0,$.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-3 bg-background/95 py-2 backdrop-blur-sm`,children:[(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i}),(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`})]}),(0,$.jsxs)(`div`,{ref:e=>{O.current[t]=e},"data-timeline-message-id":e.info.id,className:Y(`group flex items-center gap-3 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,c&&`bg-interactive-selection text-interactive-selection-foreground`),onClick:()=>void R(e.info.id),onMouseEnter:()=>D(t),children:[(0,$.jsx)(`span`,{className:Y(`typography-meta w-16 flex-shrink-0 text-right tabular-nums`,c?`text-interactive-selection-foreground/70`:`text-muted-foreground`),children:s}),(0,$.jsxs)(`p`,{className:Y(`flex-1 min-w-0 typography-micro truncate`,c?`text-interactive-selection-foreground`:`text-foreground`),children:[l??(n||d(`chat.timeline.noTextContent`)),!l&&n&&n.length>=80&&`…`]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:(0,$.jsxs)(`div`,{className:Y(`gap-1`,b?`flex`:`hidden group-hover:flex`),children:[_.revert?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`revert`&&x.messageId===e.info.id,disabled:x!==null,onClick:t=>{t.stopPropagation(),B(`revert`,e.info.id)},children:(0,$.jsx)(X,{name:x?.type===`revert`&&x.messageId===e.info.id?`loader-4`:`arrow-go-back`,className:Y(`h-4 w-4`,x?.type===`revert`&&x.messageId===e.info.id&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:d(`chat.timeline.actions.revertFromHere`)})]}):null,_.fork?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`fork`&&x.messageId===e.info.id,onClick:t=>{t.stopPropagation(),B(`fork`,e.info.id)},disabled:x!==null,children:x?.type===`fork`&&x.messageId===e.info.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4`})})}),(0,$.jsx)(Ua,{sideOffset:6,children:d(`chat.timeline.actions.forkFromHere`)})]}):null]})})]})]},e.info.id)})}),(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:d(`chat.timeline.actions.title`)}),(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{a?.(-1),t(!1)},children:d(`chat.timeline.actions.previousTurn`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{o?.(),t(!1)},children:d(`chat.timeline.actions.latest`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:d(`chat.timeline.help.clickMessage`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`arrow-go-back`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:d(`chat.timeline.help.undoToPoint`)})]}),_.fork?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:d(`chat.timeline.help.createSessionFromHere`)})]}):null]})]})]})}):null};function RL(e,t,n=30){let r=e.toLowerCase(),i=t.toLowerCase(),a=r.indexOf(i);if(a===-1)return null;let o=Math.max(0,a-n),s=Math.min(e.length,a+t.length+n);return`${o>0?`…`:``}${e.slice(o,s).replace(/\n/g,` `)}${s<e.length?`…`:``}`}var zL=e=>{let t=e.startsWith(`#`)?e.slice(1):e;if(!t)return null;let n=t.match(/^turn-(.+)$/);if(n?.[1])return{kind:`turn`,id:n[1]};let r=t.match(/^message-(.+)$/);return r?.[1]?{kind:`message`,id:r[1]}:null},BL=(e,t,n)=>{if(n===0||e.length===0)return{kind:`noop`};let r=t?e.indexOf(t):e.length-1,i=(r>=0?r:e.length-1)+n;if(i>=e.length)return{kind:`resume`};let a=e[Math.max(0,i)];return a?{kind:`turn`,turnId:a}:{kind:`noop`}},VL=e=>{if(typeof window>`u`)return;let t=e?`#${e}`:``,n=`${window.location.pathname}${window.location.search}${t}`;window.history.replaceState(window.history.state,``,n)},HL=e=>{let t=(0,Q.c)(29),{sessionId:n,turnIds:r,activeTurnId:i,scrollToTurn:a,scrollToMessage:o,resumeToBottom:s}=e,c=Z.useRef(r),l=Z.useRef(i),u,d;t[0]===r?(u=t[1],d=t[2]):(u=()=>{c.current=r},d=[r],t[0]=r,t[1]=u,t[2]=d),Z.useEffect(u,d);let f,p;t[3]===i?(f=t[4],p=t[5]):(f=()=>{l.current=i},p=[i],t[3]=i,t[4]=f,t[5]=p),Z.useEffect(f,p);let m;t[6]===a?m=t[7]:(m=async(e,t)=>e?(t?.updateHash!==!1&&VL(`turn-${e}`),a(e,{behavior:t?.behavior})):!1,t[6]=a,t[7]=m);let h=m,g;t[8]===o?g=t[9]:(g=async(e,t)=>e?(t?.updateHash!==!1&&VL(`message-${e}`),o(e,{behavior:t?.behavior})):!1,t[8]=o,t[9]=g);let _=g,v;t[10]!==s||t[11]!==h?(v=async(e,t)=>{let n=c.current,r=BL(n,l.current,e);if(r.kind===`noop`)return e===0;if(r.kind===`resume`){if(t?.resumePastEnd===!1){let e=n[n.length-1];return e?h(e,{behavior:`auto`}):!1}return VL(null),s(),!0}return h(r.turnId,{behavior:`auto`})},t[10]=s,t[11]=h,t[12]=v):v=t[12];let y=v,b;t[13]===s?b=t[14]:(b=()=>{VL(null),s()},t[13]=s,t[14]=b);let x=b,S;t[15]!==_||t[16]!==h||t[17]!==n?(S=()=>{if(!n||typeof window>`u`)return;let e=()=>{let e=zL(window.location.hash);if(e){if(e.kind===`turn`){h(e.id,{behavior:`auto`,updateHash:!1});return}_(e.id,{behavior:`auto`,updateHash:!1})}};return e(),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`hashchange`,e)}},t[15]=_,t[16]=h,t[17]=n,t[18]=S):S=t[18];let C;t[19]!==_||t[20]!==h||t[21]!==n||t[22]!==r.length?(C=[n,_,h,r.length],t[19]=_,t[20]=h,t[21]=n,t[22]=r.length,t[23]=C):C=t[23],Z.useEffect(S,C);let w;return t[24]!==x||t[25]!==y||t[26]!==_||t[27]!==h?(w={scrollToTurnId:h,scrollToMessageId:_,scrollByTurnOffset:y,resumeToLatest:x},t[24]=x,t[25]=y,t[26]=_,t[27]=h,t[28]=w):w=t[28],w},UL=2e4,WL=6e4,GL=2e3,KL=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,qL=e=>{if(e.length===0)return`0`;let t=e[e.length-1];if(!t)return`0`;let n=t.parts??[],r=n[n.length-1],i=0;for(let e of n)i+=KL(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},JL={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},YL=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:JL,shouldRefresh:!1,stalledForMs:0};if(e.sessionKey!==n)return{state:{sessionKey:n,fingerprint:a,lastMovementAt:o,lastRefreshAt:null,attempts:0},shouldRefresh:!1,stalledForMs:0};if(e.fingerprint!==a)return{state:{...e,fingerprint:a,lastMovementAt:o,attempts:0},shouldRefresh:!1,stalledForMs:0};if(!r||i)return{state:{...e,lastMovementAt:o},shouldRefresh:!1,stalledForMs:0};let s=e.lastMovementAt??o,c=o-s,l=e.lastRefreshAt===null||o-e.lastRefreshAt>=t.cooldownMs,u=c>=t.thresholdMs&&l&&e.attempts<t.maxAttempts;return{state:{...e,lastMovementAt:s,lastRefreshAt:u?o:e.lastRefreshAt,attempts:u?e.attempts+1:e.attempts},shouldRefresh:u,stalledForMs:c}},XL=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function ZL(e){let t=e.match(/^User has answered your questions:\s*(.+?)\.\s*You can now/s);if(!t)return null;let n=[],r=t[1],i=/"([^"]+)"="([^"]*(?:[^"\\]|\\.)*)"/g,a;for(;(a=i.exec(r))!==null;)n.push({question:a[1],answer:a[2]});return n.length>0?n:null}function QL(e){if(typeof e.id==`string`&&e.id)return e.id;if(typeof e.callID==`string`&&e.callID)return e.callID;let t=e.state;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t.callID;if(typeof e==`string`&&e)return e}return null}function $L(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(t.type!==`tool`||t.tool!==`question`)return!1;let n=t.state&&typeof t.state==`object`&&!Array.isArray(t.state)?t.state:{},r=typeof n.status==`string`?n.status:void 0;if(r===`error`)return!1;if(r===`pending`||r===`running`||r===void 0)return!0;if(r!==`completed`)return!1;let i=typeof n.output==`string`?n.output:``;return!i||ZL(i)==null}function eR(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!$L(n))continue;let e=QL(n);e&&t.push(e)}}return t}function tR(e,t){return`${e}:${t.join(`,`)}`}function nR(e){let t=e.sessionId?.trim()??``,n=e.directory?.trim()??``;if(!t||!n||e.sessionQuestionCount>0||e.unansweredToolIds.length===0)return{recover:!1,attemptKey:null};let r=tR(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function rR(e,t,n,r){let i=(0,Q.c)(7),a=Hn(),o=Z.useRef(null),s=Z.useRef(`${e??``}:${t??``}`),c,l;i[0]!==a||i[1]!==t||i[2]!==n||i[3]!==e||i[4]!==r?(c=()=>{let i=`${e??``}:${t??``}`;s.current!==i&&(o.current=null,s.current=i);let c=nR({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:eR(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,on(t,l,[e]))},l=[e,t,n,r,a],i[0]=a,i[1]=t,i[2]=n,i[3]=e,i[4]=r,i[5]=c,i[6]=l):(c=i[5],l=i[6]),Z.useEffect(c,l)}var iR=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),aR=(e,t)=>({...e,key:oR(e),estimatedBytes:iR(t)}),oR=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),sR=e=>({key:e?oR(e):null,selection:e}),cR=(e,t,n)=>{let r=Math.max(1,Math.floor(n.maxEntries)),i=Math.max(0,n.maxEstimatedBytes),a=e.reduce((e,t)=>e+t.estimatedBytes,0);if(e.length<=r&&a<=i)return e;let o=[...e];for(;o.length>r||a>i;){let e=o.findIndex(e=>e.key!==t);if(e===-1)break;let[n]=o.splice(e,1);a-=n?.estimatedBytes??0}return o},lR=(e,t,n,r)=>{let i=oR(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return cR(e,i,n);let s=o||aR(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),cR(c,i,n)},uR=(e,t,n)=>{let r=iR(n),i=e.findIndex(e=>e.key===t);return i===-1||e[i].estimatedBytes===r?e:e.map((e,t)=>t===i?{...e,estimatedBytes:r}:e)},dR=(e,t)=>t&&e.some(e=>e.key===t)?t:null,fR=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?lR(e.cachedSessionViews,t.selection,n,r.estimatedBytes):cR(e.cachedSessionViews,t.key??``,n),a=!r&&e.pendingSessionView?.intent===t?e.pendingSessionView:null;return e.activeIntent===t&&!e.cacheNeedsTrim&&i===e.cachedSessionViews&&a===e.pendingSessionView?e:{activeIntent:t,cacheNeedsTrim:!1,cachedSessionViews:i,pendingSessionView:a}},pR=(e,t,n,r)=>{if(n!==t||e.activeIntent!==t||!t.selection||e.cachedSessionViews.some(e=>e.key===t.key))return e;let i={entry:aR(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},mR=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:lR(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},hR=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},gR=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},_R=e=>gR(e)?.role===`assistant`,vR=(e,t)=>{let n=gR(t);n&&(e.agentName??=hR(n.agent),e.providerId??=hR(n.providerID),e.modelId??=hR(n.modelID))},yR=e=>!!(e.agentName&&e.providerId&&e.modelId),bR=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!_R(r))&&(vR(t,r),yR(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||_R(r))&&(vR(t,r),yR(t)))break}return t},xR=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),SR=[],CR=[],wR={type:`idle`},TR=`openchamber:chat-force-scroll-bottom`,ER=()=>void 0,DR=`Quota limit reached. Retrying automatically.`,OR=1048576,kR=OR,AR=20,jR=OR,MR=16*OR,NR={maxEntries:3,maxEstimatedBytes:32*OR},PR={maxEntries:2,maxEstimatedBytes:32*OR},FR=e=>t(()=>e()),IR={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},LR={scrollbar:`chat`,scrollShadow:`true`,orientation:`vertical`},RR=()=>{let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 bottom-full z-0 h-11 bg-gradient-to-t from-[var(--surface-background)] to-transparent`}),e[0]=t):t=e[0],t},zR=`calc(max(0.625rem, var(--oc-safe-area-top, 0px)) + var(--oc-mobile-detail-navigation-height) + 1.25rem)`,BR=kF,VR=[`a[href]`,`button`,`input`,`select`,`textarea`,`[contenteditable="true"]`,`[role="button"]`,`[role="combobox"]`,`[role="dialog"]`,`[role="listbox"]`,`[role="menu"]`,`[role="menuitem"]`,`[role="option"]`,`[role="textbox"]`,`[data-radix-popper-content-wrapper]`].join(`,`),HR=e=>e instanceof HTMLElement,UR=e=>HR(e)?!!e.closest(VR):!1,WR=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||UR(e)?!0:!t?.contains(e),GR=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=q.getState();return e||t||n||r||i||a||o},KR=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,renderedMessages:l,isLoadingOlder:u,sessionIsWorking:d,streamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,handleMessageContentChange:h,getAnimationHandlers:g,handleHistoryScroll:_,handleHistoryUpwardIntent:v,onTimelineIsAtEndChange:y,timelineFollowSuspended:b,timelineHistoryAnchorToken:x,scrollToBottom:S,sessionQuestions:C,sessionPermissions:w,isProgrammaticFollowActive:T,showLoadOlderButton:E,onLoadOlder:D,turnIds:O,activeTurnId:k,onSelectTurn:A,showPromptNavigator:j,canLoadEarlierPrompts:M,isLoadingOlderPrompts:N,onLoadEarlierPrompts:P})=>{let{t:F}=ct(),I=Bs(e=>e.legendTimelineEnabled),L=jx({isLoadingOlder:u}),R=Mx({isMobile:r,isLoadingOlder:L}),z=Z.useRef(new Map),B=Z.useRef(new WeakMap),V=Z.useRef(new Map),H=Z.useMemo(()=>{let e=new Map;for(let t=0;t<l.length;t+=1){let n=l[t];if(n.info.role!==`user`)continue;if(ZM(n)){let r=$M(l,t)??``,i=V.current.get(n.info.id);if(i&&i.command===r)e.set(n.info.id,i.parts);else{let t=[{type:`text`,text:r?`$ ${r}`:`/shell`}];V.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(St(n.parts))continue;let r=B.current.get(n.parts);r||(r=Gi(n.parts),B.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=z.current;if(t.size===e.size){let n=!0;for(let[r,i]of e)if(t.get(r)!==i){n=!1;break}if(n)return t}return z.current=e,e},[l]),U=Z.useMemo(()=>O.filter(e=>H.has(e)),[H,O]),W=Z.useMemo(()=>{if(!k||H.has(k))return k;let e=O.indexOf(k);for(let t=e-1;t>=0;--t){let e=O[t];if(H.has(e))return e}return null},[k,H,O]),ee=J(e=>{e.defaultPrevented||UR(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return NF({scrollRef:o,enabled:I,onUpwardIntent:v}),I?(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,n?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":n,children:(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(TP,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:S,scrollRef:o,directory:a,timelineScrollClassName:`absolute inset-0 z-0 chat-scroll overlay-scrollbar-target`,timelineScrollStyle:IR,timelineScrollDataset:LR,timelineOnScroll:_,timelineFollowEnabled:!c&&!b,timelineHistoryAnchorToken:x,timelineOnIsAtEndChange:y,headerSlot:(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:zR},"aria-hidden":`true`}),E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(ua,{variant:`secondary`,size:`sm`,onClick:D,disabled:L,"aria-busy":L,children:[L&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),F(`chat.history.loadOlder`)]})}),R&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:F(`chat.history.loadingMore`)})]})})]}),footerSlot:(0,$.jsxs)($.Fragment,{children:[(C.length>0||w.length>0)&&(0,$.jsxs)(`div`,{children:[C.map(e=>(0,$.jsx)($P,{question:e},e.id)),w.map(e=>(0,$.jsx)(KP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?BR:DF},"aria-hidden":`true`})]})}),(0,$.jsx)(ho,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(SF,{turnIds:U,previewsByTurnId:H,activeTurnId:W,onSelectTurn:A,canLoadEarlier:M,isLoadingOlder:N,onLoadEarlier:P}):null]})}):(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,n?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":n,children:(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(ja,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:IR,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:ee,onScroll:_,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`oc-chat-scroll-content relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(ua,{variant:`secondary`,size:`sm`,onClick:D,disabled:L,"aria-busy":L,children:[L&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),F(`chat.history.loadOlder`)]})}),R&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:F(`chat.history.loadingMore`)})]})}),(0,$.jsx)(TP,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:S,scrollRef:o,directory:a}),(C.length>0||w.length>0)&&(0,$.jsxs)(`div`,{children:[C.map(e=>(0,$.jsx)($P,{question:e},e.id)),w.map(e=>(0,$.jsx)(KP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(aA,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?OF:DF},"aria-hidden":`true`})]})}),(0,$.jsx)(ho,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(SF,{turnIds:U,previewsByTurnId:H,activeTurnId:W,onSelectTurn:A,canLoadEarlier:M,isLoadingOlder:N,onLoadEarlier:P}):null]})})},(e,t)=>e.currentSessionId===t.currentSessionId&&e.virtualizerKey===t.virtualizerKey&&e.isDesktopExpandedInput===t.isDesktopExpandedInput&&e.isMobile===t.isMobile&&e.stickyUserHeader===t.stickyUserHeader&&e.directory===t.directory&&e.scrollRef===t.scrollRef&&e.messageListRef===t.messageListRef&&e.pendingRevealWork===t.pendingRevealWork&&e.renderedMessages===t.renderedMessages&&e.isLoadingOlder===t.isLoadingOlder&&e.sessionIsWorking===t.sessionIsWorking&&e.streamingMessageId===t.streamingMessageId&&e.activeStreamingPhase===t.activeStreamingPhase&&e.retryOverlay===t.retryOverlay&&e.handleMessageContentChange===t.handleMessageContentChange&&e.getAnimationHandlers===t.getAnimationHandlers&&e.handleHistoryScroll===t.handleHistoryScroll&&e.handleHistoryUpwardIntent===t.handleHistoryUpwardIntent&&e.onTimelineIsAtEndChange===t.onTimelineIsAtEndChange&&e.timelineFollowSuspended===t.timelineFollowSuspended&&e.timelineHistoryAnchorToken===t.timelineHistoryAnchorToken&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.onLoadOlder===t.onLoadOlder&&e.turnIds===t.turnIds&&e.activeTurnId===t.activeTurnId&&e.onSelectTurn===t.onSelectTurn&&e.showPromptNavigator===t.showPromptNavigator&&e.canLoadEarlierPrompts===t.canLoadEarlierPrompts&&e.isLoadingOlderPrompts===t.isLoadingOlderPrompts&&e.onLoadEarlierPrompts===t.onLoadEarlierPrompts);KR.displayName=`ChatViewport`;var qR=[{id:1,toolRows:[{id:`search`,titleWidth:`w-24`,detailWidth:`w-52`},{id:`read`,titleWidth:`w-20`,detailWidth:`w-36`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-64`}],textWidths:[`w-24`,`w-[92%]`,`w-[78%]`]},{id:2,toolRows:[{id:`read`,titleWidth:`w-20`,detailWidth:`w-40`},{id:`search`,titleWidth:`w-24`,detailWidth:`w-48`}],textWidths:[`w-20`,`w-[88%]`,`w-[70%]`]},{id:3,toolRows:[{id:`shell`,titleWidth:`w-28`,detailWidth:`w-44`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-56`}],textWidths:[`w-24`,`w-[84%]`,`w-[64%]`]}],JR=e=>ca(e.path),YR=(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)]})},XR=e=>{let t=Math.ceil(Math.max(0,e)/AR);return Math.min(MR,kR+t*jR)},ZR=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:s,hostedFeatures:c,assistantHistory:l,onRevertMessage:u,warning:d=null,pendingUserMessages:f=CR,onPendingUserMessagesMaterialized:p})=>{let m=c??Ix(void 0),{t:h}=ct();at(()=>{oi()},[]);let g=ri(e=>e.openNewSessionDraft),_=ri(e=>e.setCurrentSession),v=ri(e=>e.newSessionDraft),y=ri(e=>e.newSessionDraft.draftSubmitting??!1),b=ri(e=>e.newSessionDraft.draftEstablishing??!1),x=ri(e=>e.forkTransition),S=gr(e=>e.projects),C=gr(e=>e.activeProjectId),w=Ai(e=>e.providers),T=ku(),E=Ir(),D=i??E;at(()=>{!n||!r||!D||jn(D,r)},[n,r,D]);let O=J(e=>T.ensureSessionRenderable(e,{directory:D})),k=q(e=>e.isExpandedInput),A=q(e=>e.stickyUserHeader),j=q(e=>e.promptNavigatorEnabled),M=q(e=>e.allowPromptingSubagentSessions),N=q(e=>e.isTimelineDialogOpen),P=q(e=>e.setTimelineDialogOpen),F=zn(e=>n&&r?e.streamingMessageIds.get(r)??null:null),I=zn(e=>F?e.messageStreamStates.get(F)?.phase??null:null),L=mi(r??``,D),R=XR(L);Z.useEffect(()=>{!a||!o||o(a,R)},[o,R,a]);let z=Mi(r??``,D).renderable,B=_t(r,D),V=Yn(r),H=B??V,U=zg({sessionId:r,hasSessionEntity:!!H,hasRenderableSessionSnapshot:z,composerSurfaceKind:s?.kind}),W=r?JSON.stringify([D,r]):null,[ee,G]=Z.useState({key:W,attempt:0}),K=Ur(r??``,D,{suspendPartUpdates:!!F,suspendPartUpdatesForMessageId:F}),te=r?K:SR,ne=v.pendingUserMessage,re=ri(e=>r?e.retainedPendingUserMessages.get(r):void 0)??CR,ie=ri(e=>e.clearRetainedPendingUserMessages),ae=Z.useMemo(()=>{if(re.length===0)return f;if(f.length===0)return re;let e=new Set(f.map(e=>e.info.id));return[...f,...re.filter(t=>!e.has(t.info.id))]},[f,re]),oe=Z.useMemo(()=>bR(te),[te]),ce=Z.useMemo(()=>{if(!oe.modelId)return h(`common.unavailable`);let e=w.find(e=>e.id===oe.providerId);return Si(e,oe.modelId)||oe.modelId},[w,oe.modelId,oe.providerId,h]),le=Ti(r??``,D),ue=yi(r??``,D),[de,fe]=Z.useState(null),pe=!!r&&de===r,me=J(()=>{if(!r||pe)return;let e=r,t=D;fe(e);let n=Pi(()=>{let n=Pr();if(!n)throw Error(`unbound`);return n.getTranscript(Bi(t,e))});Oi(Ar({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:le?{sessionID:e,status:le.status===`ready`?`ready`:le.status,error:le.error}:void 0,hydration:ue,error:le?.error})),(async()=>{try{await Nn(t,e),await T.ensureSessionRenderable(e,{directory:t});try{let r=Pi(()=>{let n=Pr();if(!n)throw Error(`unbound`);return n.getTranscript(Bi(t,e))});n&&r&&vr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){Oi(Ar({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:ue,error:n}))}finally{fe(t=>t===e?null:t)}})()}),he=li(r??``,D).boundary,ge=J(async e=>{if(he.kind===`has-more`){await si(D,e);return}if(he.kind===`unknown`){await _i(D,e);return}l&&!l.complete&&await l.fetchPrevious()}),_e=Fi(r??``,D),ve=Sr(r??``,D),ye=jr(D),be=_e??wR,xe=ar(r,D),Se=En(r,D);rR(r,D,te,Se.length);let Ce=Z.useMemo(()=>{if(!r||xe.length>0||Se.length>0)return!1;let e=be.type??`idle`;if(e===`busy`||e===`retry`||Dx(ae,{resolvedSessionStatus:_e,sessionStatusObservedAt:ve}))return!0;let t=te[te.length-1]?.info,n=t?.time?.created;return _e&&typeof ve==`number`&&typeof n==`number`&&n<=ve||typeof ye==`number`&&typeof n==`number`&&n<=ye?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,ae,_e,te,xe.length,Se.length,be.type,ve,ye]),we=Z.useMemo(()=>!r||be.type!==`retry`?null:{sessionId:r,message:(typeof be.message==`string`?(be.message??``).trim():``)||DR,confirmedAt:be.confirmedAt},[r,be]),[Te,Ee]=Z.useState(0),De=Z.useRef(null);Z.useEffect(()=>{if(!we||typeof we.confirmedAt==`number`){De.current=null,Ee(0);return}De.current!==we.sessionId&&(De.current=we.sessionId,Ee(Date.now()))},[we]);let Oe=Z.useMemo(()=>we?{...we,fallbackTimestamp:Te}:null,[we,Te]),ke=!!(r&&T.isLoading(r,{directory:D})),Ae=Z.useMemo(()=>{if(!r)return null;let e=Ox({boundary:he,assistantComplete:l?.complete??!0});return{limit:he.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:kx({syncLoading:ke,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,he,ke]),je=q(e=>e.isMobile),Me=ng()!==null,Ne=se(),Pe=wg(),Fe=!!v?.open,Ie=Pt(e=>e.error),Le=k,Re=Me||je||Ne||Pe===`mini-chat`,ze=Z.useRef(null),Be=Z.useMemo(()=>{let e=v?.selectedProjectId?S.find(e=>e.id===v.selectedProjectId)??null:null,t=C?S.find(e=>e.id===C)??null:null,n=e??t??S[0]??null;return n?JR(n):null},[C,v?.selectedProjectId,S]),Ve=Qn(r,D),He=a??r??``,[Ue,We]=Z.useState(null),Ge=Wg(Ue,He,Ve,oe);at(()=>{We(e=>Wg(e,He,Ve,oe))},[Ve,oe,He]);let Ke=Ve??Ge?.parentTarget??null,qe=Ge?.execution??oe,Je=pl(),Ye=Je!==null&&r===Je,Xe=J(()=>{Ke&&_(Ke.id,Ke.directory)}),Ze=Ke?.session?.title,Qe=m.returnToParent&&Ke&&!Ye?(0,$.jsxs)(ua,{type:`button`,variant:`outline`,size:`xs`,onClick:Xe,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":h(`chat.container.returnToParent.aria`),title:Ze?.trim()?h(`chat.container.returnToParent.titleNamed`,{title:Ze}):h(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),h(`chat.container.returnToParent.label`)]}):null,$e=Bg({readOnly:t,sessionIdentityPending:U,isSubagentSession:!!H?.parentID||!!Ge,allowPromptingSubagentSessions:M}),et=qe.modelId===oe.modelId?ce:qe.modelId?Si(w.find(e=>e.id===qe.providerId),qe.modelId)||qe.modelId:h(`common.unavailable`),tt=Ke?(0,$.jsx)(Bx,{agentName:qe.agentName,providerId:qe.providerId,modelId:qe.modelId,modelName:et}):(0,$.jsx)(Bx,{}),rt=J(e=>{q.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),lt=J(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`openchamber:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&&rt({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),ut=typeof window<`u`&&window.parent!==window;ot(`message`,lt,ut?window:ER),it(()=>{if(!ut)return;let e=window;e.__openchamberApplyChatSettingsSync=rt,window.parent.postMessage({type:`openchamber:chat-settings-request`},window.location.origin)}),nt(()=>{if(typeof window>`u`)return;let e=window;e.__openchamberApplyChatSettingsSync===rt&&delete e.__openchamberApplyChatSettingsSync}),Z.useEffect(()=>{m.newSessionDraft&&e&&!r&&!Fe&&g()},[e,r,Fe,m.newSessionDraft,g]);let dt=Z.useRef(()=>{}),ft=J(e=>{dt.current(e)}),pt=Z.useRef(()=>{}),mt=J(()=>{pt.current()}),ht=Bs(e=>e.legendTimelineEnabled),[gt,vt]=Z.useState(!0),[yt,bt]=Z.useState(!1),[xt,St]=Z.useState(!1),[Ct,wt]=Z.useState(0),Tt=J(()=>{wt(e=>e+1)}),Et=J((e,t)=>{vt(e),e&&St(!1),t!==void 0&&bt(t)});Z.useEffect(()=>{vt(!0),bt(!1),St(!1)},[r]);let{scrollRef:Dt,notifyContentChange:Ot,getAnimationHandlers:kt,goToBottom:At,scrollToBottomOnSend:jt,releaseAutoFollow:Mt,beginHistoryViewportPreservation:Nt,endHistoryViewportPreservation:Ft,restoreSnapshot:It,isPinned:Lt,isFollowingProgrammatically:Rt,showScrollButton:zt}=eI({enabled:n&&!ht,currentSessionId:r,viewportKey:a,sessionMessageCount:L,sessionIsWorking:Ce,isMobile:je,onActiveTurnChange:ft,onUpwardUserIntent:mt}),Bt=Z.useRef(null);CI({enabled:je,scrollRef:Dt,scopeRef:Bt});let Vt=Z.useRef([]),Ht=Z.useMemo(()=>{let e=Li(l?.entries??[],r,Vt.current);return Vt.current=e,e},[l?.entries,r]),Ut=Z.useRef([]),Wt=Z.useMemo(()=>{if(!l)return te;let e=or(l.entries,r,te,Ut.current);return Ut.current=e,e},[l,r,te]),Gt=Z.useMemo(()=>Ex(Ht.length===0?Wt:r?[...Ht,ci(r),...Wt]:Ht,ae),[r,Wt,Ht,ae]),Kt=Z.useRef(null),qt=Z.useMemo(()=>Fx({sessionId:r,messages:Gt,retained:Kt.current}),[r,Gt]);Kt.current=qt.retained;let Jt=qt.messages,Yt=Z.useRef(null),Xt=Yt.current===r,Zt=Z.useRef(JL),Qt=r?`${D}\n${r}`:null,$t=J(()=>qL(Jt));Z.useEffect(()=>{if(!r||!Qt||!Ce){Zt.current={...Zt.current,lastMovementAt:null};return}let e=r,t=D,n=setInterval(()=>{let n=$t(),r=YL(Zt.current,{sessionKey:Qt,working:!0,streaming:!!F,fingerprint:n,now:Date.now(),thresholdMs:UL,cooldownMs:WL,maxAttempts:3});Zt.current=r.state,r.shouldRefresh&&(XL({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),mr(t,e).catch(()=>{}))},GL);return()=>clearInterval(n)},[r,D,$t,Ce,F,Qt]);let en=Z.useMemo(()=>{if(ae.length===0)return[];let e=new Set([...Ht,...Wt].filter(e=>Ji(e.parts)).map(e=>e.info.id));return ae.map(e=>e.info.id).filter(t=>e.has(t))},[Wt,Ht,ae]);Z.useEffect(()=>{en.length!==0&&(p?.(en),r&&ie(r,en))},[ie,r,en,p]);let tn=FL({sessionId:r,directory:D,messages:Jt,historyMeta:Ae,scrollRef:Dt,messageListRef:ze,loadMoreMessages:ge,goToBottom:At,releaseAutoFollow:Mt,beginHistoryViewportPreservation:Nt,endHistoryViewportPreservation:Ft,isPinned:ht?gt:Lt,showScrollButton:ht?yt:zt,autoFillEnabled:n&&!Le,onWillLoadEarlier:Tt}),nn=J(()=>{St(!1),ze.current?.scrollToBottom(),At(`instant`)}),rn=J(()=>{St(!1),jt()}),an=J(()=>{St(!0),tn.handleHistoryUpwardIntent()}),on=Ax({isMobile:je,canLoadEarlier:tn.historySignals.canLoadEarlier,isLoadingOlder:tn.isLoadingOlder}),sn=tn.isLoadingOlder,cn=tn.loadEarlier,ln=J(()=>{St(!0),cn({userInitiated:!0})});dt.current=tn.handleActiveTurnChange,pt.current=tn.handleHistoryUpwardIntent,Z.useEffect(()=>{(xe.length!==0||Se.length!==0)&&Ot(`permission`)},[Ot,xe,Se]);let un=HL({sessionId:r,turnIds:tn.turnIds,activeTurnId:tn.activeTurnId,scrollToTurn:tn.scrollToTurn,scrollToMessage:tn.scrollToMessage,resumeToBottom:nn}),dn=$e.showReadOnlyBanner?tt:t?null:(0,$.jsx)(vx,{surface:s,scrollToBottom:rn,showScrollToBottom:je&&tn.showScrollToBottom,onScrollToBottom:un.resumeToLatest,submissionBlocked:$e.blockSubmission}),fn=J(e=>{un.scrollToTurnId(e,{behavior:`smooth`})}),pn=tn.historySignals.canLoadEarlier,mn=m.promptNavigator&&!je&&!Ne&&!Le&&j&&tn.turnIds.length>=2;Z.useEffect(()=>{mn||q.getState().setPromptNavigatorPanelOpen(!1)},[mn]);let hn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||At(`instant`)});ot(TR,hn,n&&r&&typeof window<`u`?window:ER);let gn=J(e=>{if(!n||!r||Le||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=q.getState();if(t!==`chat`||GR())return;let i=Dt.current;if(WR(document.activeElement,i)||UR(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;un.scrollByTurnOffset(a,{resumePastEnd:!1})});ot(`keydown`,gn,n&&r&&!Le&&typeof window<`u`?window:ER);let _n=Z.useRef(0),vn=J(()=>{let e=Dt.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),yn=J(()=>{_n.current||=requestAnimationFrame(()=>{_n.current=0,vn()})});at(()=>{n&&vn()},[n,r,Le,vn]);let bn=typeof ResizeObserver<`u`;st(n&&bn?Dt:null,yn),ot(`resize`,yn,n&&!bn&&typeof window<`u`?window:ER),nt(()=>{_n.current&&=(cancelAnimationFrame(_n.current),0)});let xn=Z.useRef(null),Sn=Z.useRef(0),Cn=Nx({transcriptMessageCount:te.length,pendingUserCount:ae.length,historyPrefixCount:Ht.length}),wn=Px({hasTranscriptShell:Cn,p0Satisfied:ue.p0Satisfied,hasBusyShell:Ce&&Cn,hasImmediateShell:ae.length>0||Ht.length>0,hasRenderableSessionSnapshot:z,prefetchStatus:le?.status,syncLoading:!!(r&&T.isLoading(r,{directory:D})),userRetrying:pe,hasPaintedTranscript:Xt});wn===`pass`&&Jt.length>0&&(Yt.current=r);let Tn=!!r&&wn===`hydrating`,Dn=!!r&&wn===`load-error`;Z.useEffect(()=>{!Dn||!r||Oi(Ar({kind:`request-error`,sessionID:r,directory:D,purpose:`load-failed`,source:`network`,request:le?{sessionID:r,status:le.status===`ready`?`ready`:le.status,error:le.error}:void 0,hydration:ue,error:le?.error}))},[r,D,Dn,le,ue]),Z.useEffect(()=>{if(!n||!r||Tn)return;let e=Jt.length,t=xn.current!==r,i=!t&&Sn.current===0&&e>0;if(!t&&!i){xn.current===r&&(Sn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(xn.current=r,Sn.current=e,a){Mt();return}let o=()=>{It()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,Tn,Mt,It,Jt.length]),Z.useEffect(()=>{G(e=>e.key===W?e:{key:W,attempt:0})},[W]),Z.useEffect(()=>{if(!n||!r||ee.key!==W||!xR({sessionId:r,hasRenderableSessionSnapshot:z,hasCurrentSessionEntity:!!H})||(O(r),H||ee.attempt>=2))return;let e=ee.attempt+1,t=window.setTimeout(()=>{G(t=>t.key===W&&t.attempt===ee.attempt?{key:W,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,H,r,D,O,z,W,ee]);let On=x&&r&&(x.targetSessionId?r===x.targetSessionId:r===x.sourceSessionId)?x:null;if(On){let e=On.stage===`preparing`?`chat.forkTransition.preparing`:On.stage===`copying`?`chat.forkTransition.copying`:On.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=h(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(On.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${h(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:h(e)}),(0,$.jsx)(Hp,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}return!r&&!Fe?e&&!Ie?(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`}):(0,$.jsx)(`div`,{className:`flex flex-col h-full bg-background`,children:(0,$.jsx)(Hx,{})}):!r&&Fe?(y||b)&&ne?(0,$.jsx)(`div`,{className:`relative flex h-full flex-col bg-background`,children:(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:(0,$.jsxs)(ja,{className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll`,style:IR,children:[(0,$.jsx)(TP,{sessionKey:`draft:${v.draftID??`pending`}`,messages:[ne],sessionIsWorking:!0,isLoadingOlder:!1,onMessageContentChange:Ot,getAnimationHandlers:kt,scrollToBottom:nn}),(0,$.jsxs)(`div`,{className:`chat-message-column px-4 pb-10 pt-2 typography-meta text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:h(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Hp,{})]})]})})}):y||b?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":h(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:h(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Hp,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Re&&!Le?(0,$.jsxs)(`div`,{className:`oc-draft-center flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-balance text-3xl font-normal tracking-tight text-foreground`,children:YR(Be?h(`chat.emptyState.draftTitleWithProject`,{project:Be}):h(`chat.emptyState.draftTitle`),Be)}),(0,$.jsx)(I_,{onSubmit:e=>ei.getState().requestPresetSubmit(e),className:`oc-draft-starters mt-8 max-w-md`})]}):null,(0,$.jsx)(`div`,{className:Y(`relative z-10 flex min-h-0`,je&&`oc-mobile-composer-foot`,Le?`flex-1 bg-background`:Re?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:dn})]}):r?Dn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Qe,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Le?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Le,children:Le?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:h(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:h(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(ua,{type:`button`,className:`mt-5`,onClick:me,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),h(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:dn})]}):Tn?(0,$.jsxs)(`div`,{ref:Bt,className:Y(`relative flex flex-col h-full bg-background`,je&&`oc-chat-composer-swap-scope`),children:[Qe,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Le?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Le,children:(0,$.jsx)(`div`,{ref:Dt,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:IR,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:qR.map(e=>(0,$.jsx)(`div`,{className:`group w-full`,children:(0,$.jsx)(`div`,{className:`chat-message-column`,children:(0,$.jsxs)(`div`,{className:`space-y-2.5 px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.toolRows.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(dc,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,t.detailWidth)})]},`${e.id}-${t.id}`))}),(0,$.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!je&&!Le?(0,$.jsx)(RR,{}):null,dn]})]}):Jt.length===0&&!Ce?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[Qe,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Le?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Le,children:Le?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(Hx,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:dn}),(0,$.jsx)(Tx,{})]}):(0,$.jsxs)(`div`,{ref:Bt,className:Y(`relative flex flex-col h-full bg-background`,je&&`oc-chat-composer-swap-scope`),children:[d?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:d}):null,Qe,(0,$.jsx)(KR,{currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Le,isMobile:je,stickyUserHeader:A,directory:D,scrollRef:Dt,messageListRef:ze,pendingRevealWork:tn.pendingRevealWork,renderedMessages:tn.renderedMessages,isLoadingOlder:sn,sessionIsWorking:Ce,streamingMessageId:F,activeStreamingPhase:I,retryOverlay:Oe,handleMessageContentChange:Ot,getAnimationHandlers:kt,handleHistoryScroll:tn.handleHistoryScroll,handleHistoryUpwardIntent:an,onTimelineIsAtEndChange:Et,timelineFollowSuspended:xt,timelineHistoryAnchorToken:Ct,scrollToBottom:nn,sessionQuestions:Se,sessionPermissions:xe,isProgrammaticFollowActive:Rt,showLoadOlderButton:on,onLoadOlder:ln,turnIds:tn.turnIds,activeTurnId:tn.activeTurnId,onSelectTurn:fn,showPromptNavigator:mn,canLoadEarlierPrompts:pn,isLoadingOlderPrompts:sn,onLoadEarlierPrompts:ln},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!je&&!Le?(0,$.jsx)(RR,{}):null,!Le&&Jt.length>0&&(je?(0,$.jsx)(Sg,{placement:`expanded`,visible:tn.showScrollToBottom,onClick:un.resumeToLatest}):(0,$.jsx)(Sg,{visible:tn.showScrollToBottom,onClick:un.resumeToLatest})),dn]}),(0,$.jsx)(Tx,{}),(0,$.jsx)(LL,{open:N,onOpenChange:P,sessionID:r??void 0,directory:D,onRevertMessage:u,onScrollToMessage:tn.scrollToMessage,onScrollByTurnOffset:un.scrollByTurnOffset,onResumeToLatest:nn,canLoadEarlier:tn.historySignals.canLoadEarlier,isLoadingEarlier:sn,onLoadEarlier:ln})]}):null});ZR.displayName=`MemoizedChatContainerContent`;var QR=()=>{let e=(0,Q.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(dc,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(dc,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(dc,{className:`h-4 w-1/2 animate-none rounded-md`})]}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`,"data-session-view-loading":`true`,"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`mt-auto w-full pb-5 motion-safe:animate-pulse`,children:(0,$.jsxs)(`div`,{className:`chat-message-column space-y-6 px-4`,children:[t,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(dc,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(dc,{className:`h-4 w-3/5 animate-none rounded-md`})]}),(0,$.jsx)(dc,{className:`h-24 w-full animate-none rounded-xl`})]})})}),e[1]=n):n=e[1],n},$R=e=>{let t=(0,Q.c)(63),n,r;t[0]===e?(n=t[1],r=t[2]):({runtimeKey:r,...n}=e,t[0]=e,t[1]=n,t[2]=r);let i=wg(),a=Ir(),o=ri(de(rz)),s;bb0:{if(!o.sessionId){s=null;break bb0}let e=o.directory??a,n;t[3]!==r||t[4]!==o.sessionId||t[5]!==e?(n={runtimeKey:r,sessionId:o.sessionId,directory:e},t[3]=r,t[4]=o.sessionId,t[5]=e,t[6]=n):n=t[6],s=n}let c=s,l;t[7]===c?l=t[8]:(l=sR(c),t[7]=c,t[8]=l);let u=l,d=u.key,f=cn()||se()||i===`mini-chat`?PR:NR,p;t[9]!==f||t[10]!==c||t[11]!==u?(p=()=>({activeIntent:u,cacheNeedsTrim:!1,cachedSessionViews:c?lR([],c,f,kR):[],pendingSessionView:null}),t[9]=f,t[10]=c,t[11]=u,t[12]=p):p=t[12];let[m,h]=Z.useState(p),g=Z.useRef(u),_=Z.useRef(d),{cacheNeedsTrim:v,cachedSessionViews:y,pendingSessionView:b}=m,x=b?.intent===u?b.entry:null,S;if(t[13]!==y||t[14]!==x){let e=[...y];x&&!e.some(e=>e.key===x.key)&&e.push(x),S=e.sort(iz),t[13]=y,t[14]=x,t[15]=S}else S=t[15];let C=S,w;t[16]!==C||t[17]!==d?(w=dR(C,d),t[16]=C,t[17]=d,t[18]=w):w=t[18];let T=w,E=!!(d&&!T),D;t[19]!==f||t[20]!==u||t[21]!==d?(D=()=>{g.current=u,_.current=d,h(e=>fR(e,u,f))},t[19]=f,t[20]=u,t[21]=d,t[22]=D):D=t[22];let O;t[23]!==f||t[24]!==v||t[25]!==u||t[26]!==d?(O=[f,v,u,d],t[23]=f,t[24]=v,t[25]=u,t[26]=d,t[27]=O):O=t[27],at(D,O);let k=b?.intent??null,A,j;t[28]!==f||t[29]!==k?(A=()=>{k&&h(e=>mR(e,k,f))},j=[f,k],t[28]=f,t[29]=k,t[30]=A,t[31]=j):(A=t[30],j=t[31]),at(A,j);let M;t[32]!==T||t[33]!==u||t[34]!==d?(M=()=>{if(!u.selection||T)return;let e=u,t=d;return vc(()=>{g.current===e&&_.current===t&&h(n=>_.current===t?pR(n,e,g.current,kR):n)},{priority:`user-blocking`})},t[32]=T,t[33]=u,t[34]=d,t[35]=M):M=t[35];let N;t[36]!==T||t[37]!==f||t[38]!==u||t[39]!==d?(N=[T,f,u,d],t[36]=T,t[37]=f,t[38]=u,t[39]=d,t[40]=N):N=t[40],Z.useEffect(M,N);let P;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(P=(e,t)=>{let n=g.current,r=_.current;h(i=>{if(g.current!==n||_.current!==r||i.activeIntent!==n||e!==r)return i;let a=uR(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})},t[41]=P):P=t[41];let F=J(P),I=E||void 0,L;t[42]!==E||t[43]!==d?(L=E?(0,$.jsx)(QR,{},d):null,t[42]=E,t[43]=d,t[44]=L):L=t[44];let R;if(t[45]!==T||t[46]!==F||t[47]!==n||t[48]!==C){let e;t[50]!==T||t[51]!==F||t[52]!==n?(e=e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:T===e.key?`visible`:`hidden`,children:(0,$.jsx)(ZR,{...n,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:F})},e.key),t[50]=T,t[51]=F,t[52]=n,t[53]=e):e=t[53],R=C.map(e),t[45]=T,t[46]=F,t[47]=n,t[48]=C,t[49]=R}else R=t[49];let z;t[54]!==n||t[55]!==o.directory||t[56]!==d?(z=d?null:(0,$.jsx)(ZR,{...n,sessionId:null,sessionDirectory:o.directory}),t[54]=n,t[55]=o.directory,t[56]=d,t[57]=z):z=t[57];let B;return t[58]!==I||t[59]!==L||t[60]!==R||t[61]!==z?(B=(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":I,children:[L,R,z]}),t[58]=I,t[59]=L,t[60]=R,t[61]=z,t[62]=B):B=t[62],B},ez=e=>{let t=(0,Q.c)(24),{host:n,runtimeKey:r,readOnly:i}=e,a=i!==void 0&&i,o;t[0]===n?o=t[1]:(o=Ix(n),t[0]=n,t[1]=o);let s=o,c;t[2]===n.onRevertMessage?c=t[3]:(c=n.onRevertMessage?{onRevertMessage:n.onRevertMessage}:{},t[2]=n.onRevertMessage,t[3]=c);let l;t[4]!==n.directory||t[5]!==n.sessionId||t[6]!==n.sessionSurface||t[7]!==c?(l={...n.sessionSurface,sessionId:n.sessionId,directory:n.directory,...c},t[4]=n.directory,t[5]=n.sessionId,t[6]=n.sessionSurface,t[7]=c,t[8]=l):l=t[8];let u=l,d=`host:${r}:${u.surfaceId}:${n.sessionId}`,f;t[9]!==n.assistantHistory||t[10]!==n.composerSurface||t[11]!==n.directory||t[12]!==n.onPendingUserMessagesMaterialized||t[13]!==n.onRevertMessage||t[14]!==n.pendingUserMessages||t[15]!==n.sessionId||t[16]!==n.warning||t[17]!==s||t[18]!==a||t[19]!==d?(f=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(ZR,{autoOpenDraft:!1,readOnly:a,sessionId:n.sessionId,sessionDirectory:n.directory,sessionViewKey:d,composerSurface:n.composerSurface,hostedFeatures:s,assistantHistory:n.assistantHistory,pendingUserMessages:n.pendingUserMessages,onPendingUserMessagesMaterialized:n.onPendingUserMessagesMaterialized,onRevertMessage:n.onRevertMessage,warning:n.warning})}),t[9]=n.assistantHistory,t[10]=n.composerSurface,t[11]=n.directory,t[12]=n.onPendingUserMessagesMaterialized,t[13]=n.onRevertMessage,t[14]=n.pendingUserMessages,t[15]=n.sessionId,t[16]=n.warning,t[17]=s,t[18]=a,t[19]=d,t[20]=f):f=t[20];let p;return t[21]!==u||t[22]!==f?(p=(0,$.jsx)(Ih.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},tz=e=>{let t=(0,Q.c)(16),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({explicitSession:n,runtimeKey:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=Ir(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Fh({...n,directory:o}),t[4]=o,t[5]=n,t[6]=s):s=t[6];let c=s,l=`explicit:${i}:${n.viewKey}`,u;t[7]!==o||t[8]!==n.active||t[9]!==n.sessionId||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(ZR,{...r,active:n.active,sessionId:n.sessionId,sessionDirectory:o,sessionViewKey:l})}),t[7]=o,t[8]=n.active,t[9]=n.sessionId,t[10]=r,t[11]=l,t[12]=u):u=t[12];let d;return t[13]!==c||t[14]!==u?(d=(0,$.jsx)(Ih.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},nz=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(FR,a,a);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(ez,{...e,host:e.host,runtimeKey:n},r),t[0]=e,t[1]=n,t[2]=r,t[3]=i):i=t[3],i}if(e.explicitSession){let r=`${n}:${e.explicitSession.viewKey}`,i;return t[4]!==e.active||t[5]!==e.autoOpenDraft||t[6]!==e.explicitSession||t[7]!==e.readOnly||t[8]!==n||t[9]!==r?(i=(0,$.jsx)(tz,{autoOpenDraft:e.autoOpenDraft,readOnly:e.readOnly,active:e.active,explicitSession:e.explicitSession,runtimeKey:n},r),t[4]=e.active,t[5]=e.autoOpenDraft,t[6]=e.explicitSession,t[7]=e.readOnly,t[8]=n,t[9]=r,t[10]=i):i=t[10],i}let r;return t[11]!==e||t[12]!==n?(r=(0,$.jsx)($R,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r};function rz(e){return{sessionId:e.currentSessionId,directory:e.currentSessionDirectory}}function iz(e,t){return e.key.localeCompare(t.key)}export{al as $,qg as A,km as B,b_ as C,y_ as D,C_ as E,ng as F,Hp as G,sm as H,Mh as I,Fu as J,yd as K,Nh as L,Sg as M,gg as N,c_ as O,tg as P,il as Q,Ih as R,__ as S,v_ as T,Xp as U,wm as V,Zp as W,lu as X,ku as Y,uu as Z,Ry as _,eI as a,rv as b,TP as c,oD as d,ol as et,aD as f,Bx as g,FE as h,NI as i,Cg as j,Kg as k,iA as l,ZE as m,bR as n,fl as nt,NF as o,sD as p,Zu as q,II as r,sl as rt,DF as s,nz as t,ul as tt,ak as u,My as v,x_ as w,K_ as x,jy as y,Im as z};
|
|
6579
|
+
`)}return ot&&ot.trim().length>0?ot:Vn(Le)},[ot,Le,K]),dt=lt.length>0,ft=Z.useCallback(async()=>(await ut(lt)).ok?(K&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[K,lt]),pt=Z.useCallback(async()=>{if(!(!re||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(re,e.info.id,{directory:g.directory??void 0})}finally{B.current=null,z(null)}}},[re,e.info.id,C,g]),mt=J(()=>{if(!re||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(re,e.info.id,t).catch(()=>{})}),ht=J(()=>{re&&O(re)}),gt=Z.useCallback(async()=>{if(e.info.id,!re||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!re,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(re,e.info.id)}finally{B.current=null,z(null)}}},[re,e.info.id,T]),_t=J(t=>{let n=Be.has(t),r=Ve.has(t);if(n){W(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),Tk(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),Ck(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),Ck(e.info.id,r),r}),W(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),Tk(e.info.id,r),r})}),vt=i??null,yt=Z.useRef(!1),bt=Z.useRef(!1),xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1),Tt=Z.useRef(!1);Z.useEffect(()=>{bt.current=!1,xt.current=!1,St.current=!1,Ct.current=!1,yt.current=!1,Tt.current=!1},[e.info.id]);let Et=Z.useCallback(()=>{K||yt.current||(yt.current=!0,r?.(`structural`))},[K,r]),Dt=q(e=>e.setImagePreviewOpen),Ot=Z.useCallback(e=>{(e.image||e.mermaid)&&(G(e),Dt(!0))},[Dt]),kt=Z.useCallback(e=>{G(t=>({...t,open:e})),Dt(e)},[Dt]),At=!!jk(e.info,`animationSettled`),jt=et===`streaming`||et===`cooldown`;jt&&(Tt.current=!0);let Mt=Z.useMemo(()=>!K&&Ie.some(e=>e.type===`reasoning`),[K,Ie]),Nt=Ke&&!At&&!jt&&!Tt.current,Pt=!K&&Ke&&Re.length>0&&!Ge;return Z.useEffect(()=>{if(vt?.onStreamingCandidate){if(!Pt){xt.current&&=(Mt&&vt?.onReasoningBlock?vt.onReasoningBlock():vt?.onReservationCancelled&&vt.onReservationCancelled(),!1);return}Ct.current||(Ct.current=!0,vt.onStreamingCandidate(),xt.current=!0)}},[vt,Pt,Mt]),Z.useEffect(()=>{vt?.onAnimationStart&&Nt&&(St.current||=(vt.onAnimationStart(),!0))},[vt,Nt]),Z.useEffect(()=>{if(K)return;let e=vt?.onAnimatedHeightChange;if(!e||!(Nt||Pt))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[Nt,K,vt,Pt]),Ue?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,K?p?`pt-2`:`pt-6`:!K&&tt?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,K||$e?`pb-0`:Qe?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:y,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:K?hr(Le)?(0,$.jsx)(bc,{forceAnimation:!0,skipAnimation:!l,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,p?void 0:`group/user-shell`),children:(0,$.jsxs)(`div`,{className:Y(`max-w-[85%]`,ne?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:`px-3 py-1.5 shadow-none border border-primary/5`,children:(0,$.jsx)($O,{messageId:e.info.id,parts:Le,sourceParts:oe,isUser:K,isMessageCompleted:Me,messageFinish:Ne,messageCreatedAt:je??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:nt,expandedTools:V,onToggleTool:_t,onShowPopup:Ot,streamPhase:et,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:dt,onCopyMessage:ft,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Et,agentMention:He,onEdit:!E&&_.edit?mt:void 0,onRevert:!E&&_.revert?pt:void 0,onFork:!E&&K&&_.fork?gt:void 0,editing:E,editStaged:D,onCancelEdit:D?ht:void 0,pendingMessageAction:R,errorMessage:ot,errorVariant:st,userActionsMode:te?`external-content`:`inline`,stickyUserHeaderEnabled:j})}),te?(0,$.jsx)($O,{messageId:e.info.id,parts:Le,sourceParts:oe,isUser:K,isMessageCompleted:Me,messageFinish:Ne,messageCreatedAt:je??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:nt,expandedTools:V,onToggleTool:_t,onShowPopup:Ot,streamPhase:et,allowAnimation:Nt,onContentChange:r,shouldShowHeader:!1,hasTextContent:dt,onCopyMessage:ft,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Et,agentMention:He,onEdit:!E&&_.edit?mt:void 0,onRevert:!E&&_.revert?pt:void 0,onFork:!E&&K&&_.fork?gt:void 0,editing:E,editStaged:D,onCancelEdit:D?ht:void 0,pendingMessageAction:R,errorMessage:ot,errorVariant:st,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[tt&&(0,$.jsx)(qx,{isUser:K,isMobile:p,providerID:De,modelID:Oe,agentName:Ee,modelName:ke,variant:it}),(0,$.jsx)($O,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Ie,sourceParts:se,isUser:K,isMessageCompleted:Me,messageFinish:Ne,messageCompletedAt:Ae??void 0,messageCreatedAt:je??void 0,messageTokens:Pe,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:nt,expandedTools:Ve,onToggleTool:_t,onShowPopup:Ot,streamPhase:et,allowAnimation:Nt,onContentChange:r,shouldShowHeader:tt,hasTextContent:dt,onCopyMessage:ft,copiedMessage:I,onAuxiliaryContentComplete:Et,showReasoningTraces:A,agentMention:He,turnGroupingContext:a,errorMessage:ot,errorVariant:st,reviewTransferDirection:d})]})})}),ee.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(gk,{popup:ee,onOpenChange:kt,isMobile:p})}):null]})},(e,t)=>YS({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&XS(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&XS(e.nextMessage?{info:e.nextMessage.info,parts:e.nextMessage.parts}:void 0,t.nextMessage?{info:t.nextMessage.info,parts:t.nextMessage.parts}:void 0)&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.reviewTransferDirection===t.reviewTransferDirection&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&iC(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,ok(e.message.info).isUser)),Nk=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},Pk=e=>{let t=e?.type;return t===`compaction`||t===`text`&&Nk(e).trim()===`/compact`},Fk=e=>e?e.some(e=>Pk(e)):!1,Ik=e=>Fk(e.parts),Lk=e=>e?Fk(e.sourceParts)||Fk(e.parts):!1,Rk=e=>{if(!Ik(e))return e;let t=!1,n=e.parts.map(e=>e?.type===`compaction`?(t=!0,{type:`text`,text:`/compact`}):e),r=e.info.clientRole!==`user`;return!t&&!r?e:{...e,info:r?{...e.info,clientRole:`user`}:e.info,parts:t?n:e.parts}},zk=e=>{let t=Rn(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},Bk=new WeakMap,Vk=e=>{let t=Bk.get(e);if(t)return t;let n=Rk(zk(e)),r=n.parts,i=Qi(r),a=i===r?n:{...n,parts:i,sourceParts:r};return Bk.set(e,a),a},Hk={activity:`idle`,hasWorkingContext:!1,hasActiveTools:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,lifecyclePhase:null,statusText:null,isGenericStatus:!0,isWaitingForPermission:!1,canAbort:!1,compactionDeadline:null,activePartType:void 0,activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:null,turnStartedAt:void 0},Uk=[],Wk=`\0`,Gk=new Set([`edit`,`write`,`multiedit`,`apply_patch`]),Kk={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,multiedit:`chat.assistantStatus.editingFiles`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`},qk=[`chat.assistantStatus.working`,`chat.assistantStatus.processing`,`chat.assistantStatus.preparing`,`chat.assistantStatus.warmingUp`,`chat.assistantStatus.gearsTurning`,`chat.assistantStatus.computing`,`chat.assistantStatus.calculating`,`chat.assistantStatus.analyzing`,`chat.assistantStatus.wheelsSpinning`,`chat.assistantStatus.calibrating`,`chat.assistantStatus.synthesizing`,`chat.assistantStatus.connectingDots`,`chat.assistantStatus.inspectingLogic`,`chat.assistantStatus.weighingOptions`],Jk=(e,t)=>{let n=Kk[e];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},Yk=e=>{let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)},Xk=(e,t)=>t(qk[Yk(e)%qk.length]??`chat.assistantStatus.working`),Zk=(e,t,n)=>{let r,i;if(!St(e))for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)switch(n.type){case`reasoning`:{let e=n.time??rA(n);(!e||e.end===void 0)&&!r&&(r=`reasoning`);break}case`tool`:{let e=n.state?.status;if((e===`running`||e===`pending`)&&!r){let e=iA(n);Gk.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=nA(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=rA(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?i===`multiedit`?Jk(i,n):n(`chat.assistantStatus.editingFile`):r===`tool`&&i?Jk(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):Xk(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},Qk=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(Wk),$k=e=>{let[t,n,r=`working`,i]=e.split(Wk);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},eA=e=>e.type===`reasoning`,tA=e=>e.type===`text`,nA=e=>{if(tA(e))return e.text;let t=e;if(typeof t.text==`string`)return t.text;if(typeof t.content==`string`)return t.content;if(typeof t.value==`string`)return t.value},rA=e=>(tA(e)||eA(e),e.time),iA=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function aA(e,t){let{t:n}=ct(),r=ri(e=>e.currentSessionId),i=ri(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),c=ri(s),l=fr(a??``,o??void 0),u=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--){let t=l[e];if(t.role===`assistant`)return{id:t.id,finish:t.finish,error:t.error}}return{id:null,finish:void 0,error:void 0}},[l]),d=u.id,f=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--){let t=l[e];if(t.role===`user`)return{id:t.id,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,turnStartedAt:void 0}},[l]),p=f.id,m=ki(d??``,o??void 0,a??void 0),h=ki(p??``,o??void 0,a??void 0),g=!!p&&Fk(h),_=!!(d&&pE(u.finish,m,u.error)),v=Z.useMemo(()=>{let e=`${a??``}:${d??``}`;return Qk(Zk(d?m:Uk,e,n))},[a,d,m,n]),y=yr(a??``,o??void 0),b=ai(a??``,o??void 0),x=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),S=ri(x),{phase:C,isWorking:w}=Fg(a,o??void 0),T=Fi(a??``,o??void 0),E=T?.type===`retry`?T.attempt:void 0,D=T?.type===`retry`?T.next:void 0,O=Z.useMemo(()=>$k(v),[v]),k=Z.useMemo(()=>{let e=!!(S&&!S.acknowledged);return{wasAborted:e,abortActive:e}},[S]),A=Z.useMemo(()=>{if(k.wasAborted)return{...Hk,wasAborted:!0,abortActive:k.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(_)return{...Hk,isComplete:!0,isTurnSettled:!0,turnStartedAt:f.turnStartedAt};let e=w,t=C===`busy`,r=C===`retry`,i=e&&g,a=`idle`;e&&(a=!i&&(O.activePartType===`tool`||O.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:E,next:D}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(O.activePartType===`tool`||O.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):O.statusText:null,isGenericStatus:!e||!i&&O.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?O.activePartType:void 0,activeToolName:e&&!i?O.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,isTurnSettled:!1,retryInfo:o,turnStartedAt:f.turnStartedAt}},[C,w,_,g,f.turnStartedAt,O,k,E,D,n]);return{forming:Z.useMemo(()=>({isActive:w&&O.activePartType===`text`,characterCount:0}),[w,O.activePartType]),working:Z.useMemo(()=>{if(A.wasAborted||A.abortActive)return A;if(c)return{...A,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,isComplete:!1,isTurnSettled:!1,retryInfo:null};let e=y.length>0,t=b.length>0;return!e&&!t?A:t?{...A,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...A,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[A,c,y,b,n])}}var oA=Z.memo(()=>{let e=(0,Q.c)(14),t=Rh(),n=ri(sA),r=ri(cA),i=t.sessionId??n,a=t.directory??r??void 0,o;e[0]===i?o=e[1]:(o=e=>i?e.sessionAbortFlags?.get(i)??null:null,e[0]=i,e[1]=o);let s=ri(o),c=ri(lA),l=ri(uA),{working:u}=aA(i,a),d=Ai(dA),f=!!(s&&!s.acknowledged),p=!!(i&&c===i&&typeof l==`number`&&l>Date.now()),m=f||u.wasAborted,h=f||u.abortActive,g;return e[2]!==d||e[3]!==p||e[4]!==m||e[5]!==h||e[6]!==u.isGenericStatus||e[7]!==u.isTurnSettled||e[8]!==u.isWaitingForPermission||e[9]!==u.isWorking||e[10]!==u.retryInfo||e[11]!==u.statusText||e[12]!==u.turnStartedAt?(g=(0,$.jsx)(Uh,{isWorking:u.isWorking,statusText:u.statusText,isGenericStatus:u.isGenericStatus,isWaitingForPermission:u.isWaitingForPermission,wasAborted:m,abortActive:h,retryInfo:u.retryInfo,turnStartedAt:u.turnStartedAt,isTurnSettled:u.isTurnSettled,showAbortPrompt:p,showAssistantStatus:!0,showTodos:!1,agentName:d}),e[2]=d,e[3]=p,e[4]=m,e[5]=h,e[6]=u.isGenericStatus,e[7]=u.isTurnSettled,e[8]=u.isWaitingForPermission,e[9]=u.isWorking,e[10]=u.retryInfo,e[11]=u.statusText,e[12]=u.turnStartedAt,e[13]=g):g=e[13],g});oA.displayName=`StatusRowContainer`;function sA(e){return e.currentSessionId}function cA(e){return e.currentSessionDirectory}function lA(e){return e.abortPromptSessionId}function uA(e){return e.abortPromptExpiresAt}function dA(e){return e.currentAgentName}var fA=Z.memo(e=>{let t=(0,Q.c)(10),{assistantMessages:n,activityExpanded:r,renderMessage:i}=e,a;if(t[0]!==r||t[1]!==n||t[2]!==i){let e;t[4]!==r||t[5]!==i?(e=e=>i(e,r),t[4]=r,t[5]=i,t[6]=e):e=t[6],a=n.map(e),t[0]=r,t[1]=n,t[2]=i,t[3]=a}else a=t[3];let o;return t[7]!==r||t[8]!==a?(o=(0,$.jsx)(`div`,{className:`relative z-0`,"data-turn-assistant-activity-expanded":r,children:a}),t[7]=r,t[8]=a,t[9]=o):o=t[9],o}),pA=new Set,mA=()=>{},hA=()=>{},gA=Z.memo(e=>{let t=(0,Q.c)(32),{turn:n,activityExpanded:r,showCompactionStatus:i,pendingAssistantHeader:a,onToggleActivity:o,stickyUserHeader:s,renderMessage:c}=e,l=a===void 0?null:a,u=s===void 0||s,d=q(_A),f=n.userMessage.info.time?.created,p=n.activityPresentationKind===`compaction`,m=`turn-${n.turnId}`,h;t[0]!==r||t[1]!==p||t[2]!==c||t[3]!==u||t[4]!==n.userMessage?(h=p?null:u?(0,$.jsxs)(`div`,{className:`sticky top-0 z-20 relative bg-[var(--surface-background)] [overflow-anchor:none]`,children:[(0,$.jsx)(`div`,{className:`relative z-10`,children:c(n.userMessage,r)}),(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-full z-0 h-4 bg-gradient-to-b from-[var(--surface-background)] to-transparent sm:h-8`})]}):c(n.userMessage,r),t[0]=r,t[1]=p,t[2]=c,t[3]=u,t[4]=n.userMessage,t[5]=h):h=t[5];let g;t[6]!==d||t[7]!==l||t[8]!==u||t[9]!==n.assistantMessages?(g=l?(0,$.jsx)(`div`,{className:`group w-full ${d?u?`pt-4`:`pt-0`:`pt-6`} ${n.assistantMessages.length===0?`pb-1`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(qx,{isUser:!1,isMobile:d,providerID:l.providerID,modelID:l.modelID,agentName:l.agentName,modelName:l.modelName,variant:l.variant})})}):null,t[6]=d,t[7]=l,t[8]=u,t[9]=n.assistantMessages,t[10]=g):g=t[10];let _;t[11]!==r||t[12]!==d||t[13]!==o||t[14]!==i||t[15]!==n.assistantMessages||t[16]!==n.completionDisposition||t[17]!==n.durationMs||t[18]!==f?(_=i?(0,$.jsx)(`div`,{className:`group w-full ${d?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(gO,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof f==`number`?f:void 0,onToggle:o,isMobile:d,expandedTools:pA,onToggleTool:mA,onShowPopup:hA,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[11]=r,t[12]=d,t[13]=o,t[14]=i,t[15]=n.assistantMessages,t[16]=n.completionDisposition,t[17]=n.durationMs,t[18]=f,t[19]=_):_=t[19];let v;t[20]!==r||t[21]!==c||t[22]!==n.assistantMessages?(v=(0,$.jsx)(fA,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:c}),t[20]=r,t[21]=c,t[22]=n.assistantMessages,t[23]=v):v=t[23];let y;return t[24]!==r||t[25]!==m||t[26]!==h||t[27]!==g||t[28]!==_||t[29]!==v||t[30]!==n.turnId?(y=(0,$.jsxs)(`section`,{className:`relative w-full`,id:m,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[h,g,_,v]}),t[24]=r,t[25]=m,t[26]=h,t[27]=g,t[28]=_,t[29]=v,t[30]=n.turnId,t[31]=y):y=t[31],y});function _A(e){return e.isMobile}var vA=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,yA=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},bA=e=>{let t=e.text;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.content;if(typeof n==`string`&&n.trim().length>0)return n},xA=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},SA=(e,t,n,r)=>({id:vA(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:yA(n)}),CA=e=>{let t=[],n=!1,r=!1;e.assistantMessages.forEach(e=>{e.parts.forEach(e=>{if(e.type===`tool`){n=!0;return}e.type===`reasoning`&&bA(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&dE(xA(t),t.parts));e.assistantMessages.forEach(n=>{let r=xA(n),a=n.parts.some(e=>e.type===`tool`);n.parts.forEach((o,s)=>{let c=o.type===`tool`,l=o.type===`reasoning`||o.type===`text`?bA(o):void 0,u=vA(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&dE(r,n.parts)&&e.summarySourceMessageId===n.info.id&&e.summarySourcePartId===u,f=null;c?f=`tool`:o.type===`reasoning`?f=`reasoning`:e.showTextJustificationActivity&&o.type===`text`&&l&&!d&&(i||a||typeof r==`string`&&r!==`stop`)&&(f=`justification`),f&&t.push({...SA(e.turnId,n.info.id,o,s),kind:f})})});let a=[];if(t.length>0){let n=e.assistantMessages[0]?.info.id;n&&a.push({id:`${e.turnId}:activity`,anchorMessageId:n,afterToolPartId:null,parts:t})}return{activityParts:t,activitySegments:a,hasTools:n,hasReasoning:r}},wA=e=>{let t=new Map,n=new Map,r=new Map,i=new Set;e.forEach(e=>{t.set(e.turnId,e);let a=e.assistantMessages[0]?.info.id,o=e.assistantMessages[e.assistantMessages.length-1]?.info.id;n.set(e.userMessageId,e.turnId),i.add(e.userMessageId),r.set(e.userMessageId,{turnId:e.turnId,messageId:e.userMessageId,userMessageId:e.userMessageId,isUserMessage:!0,isAssistantMessage:!1,isFirstAssistantInTurn:!1,isLastAssistantInTurn:!1,headerMessageId:e.headerMessageId}),e.assistantMessageIds.forEach(t=>{n.set(t,e.turnId),i.add(t),r.set(t,{turnId:e.turnId,messageId:t,userMessageId:e.userMessageId,isUserMessage:!1,isAssistantMessage:!0,isFirstAssistantInTurn:t===a,isLastAssistantInTurn:t===o,headerMessageId:e.headerMessageId})})});let a=e.length>0?e[e.length-1]:null,o=new Set;return a&&(o.add(a.userMessageId),a.assistantMessageIds.forEach(e=>{o.add(e)})),{turns:e,indexes:{turnById:t,messageToTurnId:n,messageMetaById:r},lastTurnId:a?.turnId??null,lastTurnMessageIds:o,ungroupedMessageIds:new Set}},TA=e=>{let t=e.text;if(typeof t==`string`&&t.trim().length>0)return t;let n=e.content;if(typeof n==`string`&&n.trim().length>0)return n},EA=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(dE(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!fE(t))continue;let r=TA(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:vA(n.info.id,t,e)}}}for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||t.type!==`text`)continue;let r=TA(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:vA(n.info.id,t,e)}}}return{}},DA=e=>{let t=e.info.summary,n=t?.diffs,r=Array.isArray(n)?n:[],i=typeof t?.diffCount==`number`&&Number.isFinite(t.diffCount)?Math.max(0,Math.trunc(t.diffCount)):void 0,a=0,o=0,s=0;r.forEach(e=>{if(!e)return;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;(t!==0||n!==0)&&(s+=1),a+=t,o+=n});let c=i??s,l=t?.hasDiffs===!0||c>0||r.length>0;if(l)return{additions:a,deletions:o,files:c,hasDiffs:l}},OA=e=>{let t=e.info.summary?.diffs;if(!Array.isArray(t)||t.length===0)return;let n=t.map(e=>{if(!e||typeof e.file!=`string`||e.file.trim().length===0)return null;let t=typeof e.additions==`number`?e.additions:0,n=typeof e.deletions==`number`?e.deletions:0;return t===0&&n===0?null:{file:e.file,additions:t,deletions:n}}).filter(e=>e!==null);return n.length>0?n:void 0},kA=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},AA=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},jA=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},MA=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},NA=e=>{let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0},PA=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},FA=(e,t)=>{let n=kA(e);return{messageId:e.info.id,role:n,parentMessageId:AA(e),message:e,order:t}},IA=(e,t)=>{let n=jA(e),r,i,a=!1;t.forEach(e=>{let t=MA(e);typeof t==`number`?r=Math.max(r??0,t):a=!0,e.parts.forEach(e=>{let t=NA(e);typeof t==`number`&&(i=Math.max(i??0,t))})});let o=r??i,s=typeof n==`number`&&typeof o==`number`&&o>=n?o-n:void 0;return{isStreaming:a,isRetrying:t.length>1,startedAt:n,completedAt:r,durationMs:s}},LA=e=>{if(e.length===0)return`active`;let t=e[e.length-1];if(!t)return`active`;let n=t.info.finish;if(t.info.error)return`abnormal`;if(n===`tool-calls`||uE(t.parts)>0)return`active`;if(n===`stop`)return`normal`;if(typeof n==`string`&&n.length>0)return`abnormal`;for(let t of e)if(typeof MA(t)!=`number`)return`active`;return`active`},RA=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return pE(n.finish,t.parts,n.error)},zA=e=>Lk(e)?`compaction`:`default`,BA={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},VA=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0},HA=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&VA(e.assistantMessages,t.assistantMessages),UA=(e,t)=>{e.summary=EA(e.assistantMessages),e.summaryText=e.summary.text??PA(e.userMessage),e.diffStats=DA(e.userMessage),e.changedFiles=t.showTurnChangedFiles?OA(e.userMessage):void 0,e.completionDisposition=LA(e.assistantMessages),e.hasConfirmedFinalBody=RA(e.assistantMessages),e.activityPresentationKind=zA(e.userMessage);let n=CA({turnId:e.turnId,assistantMessages:e.assistantMessages,summarySourceMessageId:e.summary.sourceMessageId,summarySourcePartId:e.summary.sourcePartId,showTextJustificationActivity:t.showTextJustificationActivity});return e.activityParts=n.activityParts,e.activitySegments=n.activitySegments,e.hasTools=n.hasTools,e.hasReasoning=n.hasReasoning,e.stream=IA(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},WA=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>UA(e,t));let r=n.turns.length===e.length,i=!1,a=e.map((e,a)=>{let o=n.indexes.turnById.get(e.turnId);return o&&HA(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,UA(e,t))});return r&&i?n.turns:a},GA=e=>{if(e.length<=1)return e;let t=!1,n=e.map((n,r)=>{if(r===e.length-1||n.completionDisposition!==`active`||(e[r+1]?.assistantMessages.length??0)===0)return n;t=!0;let i=e[r+1]?.startedAt,a=n.durationMs,o=n.completedAt;return typeof a!=`number`&&typeof n.startedAt==`number`&&typeof i==`number`&&i>=n.startedAt&&(o=i,a=i-n.startedAt),{...n,completionDisposition:`abnormal`,completedAt:o,durationMs:a,stream:{...n.stream,isStreaming:!1,completedAt:o??n.stream.completedAt,durationMs:a}}});return t?n:e},KA=(e,t)=>{let n={...BA,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(kA(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[FA(e,t)],assistantMessageIds:[],assistantMessages:[],activityParts:[],activitySegments:[],summary:{},summaryText:void 0,hasTools:!1,hasReasoning:!1,diffStats:void 0,changedFiles:void 0,stream:{isStreaming:!1,isRetrying:!1},completionDisposition:`active`,activityPresentationKind:`default`,hasConfirmedFinalBody:!1};r.push(n),i.set(n.userMessageId,n),a.add(e.info.id)}),e.forEach((e,t)=>{if(kA(e)!==`assistant`)return;let n=AA(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(FA(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=wA(GA(WA(r,n))),s=new Set;return e.forEach(e=>{kA(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},qA=30,JA=4,YA=4,XA=33554432,ZA=8388608,QA=new Map,$A=new Map,ej=0,tj=new WeakMap,nj=1,rj=()=>se()?JA:cn()?YA:qA,ij=()=>se()||cn()?ZA:XA,aj=(e,t)=>{let n=e.length*2+256;for(let e of t.turns)n+=512,n+=e.messages.length*160,n+=e.activityParts.length*128,n+=(e.changedFiles?.length??0)*160,n+=(e.summaryText?.length??0)*2;return n},oj=e=>{QA.delete(e);let t=$A.get(e)??0;$A.delete(e),ej=Math.max(0,ej-t)},sj=e=>{let t=tj.get(e);if(t!==void 0)return t;let n=nj;return nj+=1,tj.set(e,n),n},cj=e=>e.map(e=>`${sj(e.info)}:${sj(e.parts)}:${e.parts.map(e=>sj(e)).join(`,`)}`).join(`;`),lj=(e,t,n,r)=>{let i=t.length>0?t[t.length-1]:void 0,a=i?.info?.id??``,o=i?.parts?.length??0;return[e,t.length,a,o,cj(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},uj=e=>{let t=QA.get(e);return t&&(QA.delete(e),QA.set(e,t)),t},dj=(e,t)=>{oj(e);let n=rj(),r=ij(),i=aj(e,t);if(!(i>r)){for(;QA.size>=n||ej+i>r;){let e=QA.keys().next().value;if(typeof e!=`string`)break;oj(e)}QA.set(e,t),$A.set(e,i),ej+=i}},fj=[],pj=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0},mj=e=>{if(!e.hasLiveTail)return null;if(e.turnCount===0)return e.previousStart;let t=e.previousStart??e.turnCount-1,n=Math.min(Math.max(t,0),e.turnCount-1);return!e.liveTailActive&&e.turnCount-n>12?e.turnCount-1:n},hj=(e,t)=>t===null?{staticTurns:e,streamingTurns:fj}:{staticTurns:t===0?fj:e.slice(0,t),streamingTurns:e.slice(t)},gj=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(fj),a=Z.useRef(null),o=Z.useRef(t.sessionKey),s=Z.useRef(t.showTextJustificationActivity),c=Z.useRef(t.showTurnChangedFiles);(o.current!==t.sessionKey||s.current!==t.showTextJustificationActivity||c.current!==t.showTurnChangedFiles)&&(o.current=t.sessionKey,s.current=t.showTextJustificationActivity,c.current=t.showTurnChangedFiles,n.current=null,r.current=[],i.current=fj,a.current=null);let l=Z.useMemo(()=>{let r=lj(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=uj(r);return i?(n.current=i,i):be(`ui.turns.projection_ms`,()=>{let i=KA(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,dj(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=mj({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=hj(l.turns,u).staticTurns;return pj(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=hj(l.turns,u).streamingTurns;return pj(i.current,e)?i.current:i.current=e},[u,l.turns])}},_j=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},vj=(e,t)=>{if(!t.sessionId)return e;let n={name:`SessionRetry`,message:t.message,data:{message:t.message}},r=-1;for(let t=e.length-1;t>=0;--t)if(_j(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(_j(e[t])===`assistant`){i=t;break}if(i>=0)return e[i].info.error?e:e.map((e,t)=>t===i?{...e,info:{...e.info,error:n}}:e);let a=typeof t.confirmedAt==`number`?t.confirmedAt:t.fallbackTimestamp,o={info:{id:`synthetic_retry_notice_${t.sessionId}`,sessionID:t.sessionId,role:`assistant`,time:{created:a,completed:a},finish:`stop`,error:n},parts:[]},s=e.slice();return s.splice(r+1,0,o),s},yj=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=kt(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:Vk({...e,parts:r})},bj=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=yj(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=yj(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=KA([e.turn.userMessage,...i],{showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles}).turns[0]??{...e.turn,assistantMessages:i,assistantMessageIds:i.map(e=>e.info.id)};return{...e,turn:a}},xj=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},Sj=2,Cj=2,wj=e=>Math.min(Math.max(0,e),Sj),Tj=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+Cj),Ej=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(FC.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Dj=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ds.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Oj=12,kj=16,Aj=new Map,jj=e=>{let t=Aj.get(e);if(t)return Aj.delete(e),Aj.set(e,t),t},Mj=(e,t)=>{if(t.size!==0)for(Aj.delete(e),Aj.set(e,t);Aj.size>kj;){let e=Aj.keys().next().value;if(typeof e!=`string`)break;Aj.delete(e)}},Nj=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Oj)),r=new Set;for(let t=Math.max(0,e.length-n);t<e.length;t+=1){let n=e[t];n&&r.add(n)}let i=t?.restore;if(i&&i.size>0){let t=new Set(e);for(let e of i)t.has(e)&&r.add(e)}return r},Pj=(e,t)=>{let n=t[t.length-1];if(!n||e.has(n))return e;let r=new Set(e);return r.add(n),r},Fj=({entryKeys:e,mountedIndexes:t,visibleStartIndex:n,visibleEndIndex:r,scrollDirection:i,preloadEntries:a,hydratedKeys:o})=>{if(e.length===0||t.length===0)return{visible:[],preload:[]};let s=new Set(t),c=[],l=[],u=new Set,d=(t,n)=>{if(n<0||n>=e.length||!s.has(n))return;let r=e[n];!r||o.has(r)||u.has(r)||(u.add(r),t.push(r))},f=e.length-1,p=Math.min(f,Math.max(0,Math.floor(n))),m=Math.min(f,Math.max(p,Math.floor(r)));for(let e=m;e>=p;--e)d(c,e);let h=Math.max(0,Math.floor(a)),g=()=>{let e=Math.min(f,m+h);for(let t=m+1;t<=e;t+=1)d(l,t)},_=()=>{let e=Math.max(0,p-h);for(let t=p-1;t>=e;--t)d(l,t)};return i===`backward`?(_(),g()):(g(),_()),{visible:c,preload:l}},Ij=e=>{let{visible:t,preload:n}=Fj(e),r=n.slice(0,Math.max(0,Math.floor(e.preloadReleaseLimit)));if(!e.allowVisibleRelease)return r;let i=e.visibleReleaseLimit,a=typeof i==`number`&&i>0?t.slice(0,Math.floor(i)):t;return a.length>0?[...a,...r]:r},Lj=(e,t)=>{let n=new Set(t),r=!1,i=new Set;for(let t of e)n.has(t)?i.add(t):r=!0;return r?i:e},Rj=`data-markdown-ready`,zj=`data-markdown-hydration`,Bj=`data-markdown-pin-reveal`,Vj=e=>[...Nj(e.entryKeys,{seedCount:e.seedCount,restore:e.restore})],Hj=e=>e.reason===`jump-to-latest`||!e.alreadyRevealedForScope,Uj=e=>{if(e.querySelector(`[data-markdown-hydration="deferred"]`))return!1;let t=e.querySelectorAll(`[data-markdown-content]`);if(t.length===0)return!0;for(let e of t)if(!e.closest(`[data-markdown-ready="true"]`))return!1;return!0},Wj=(e,t)=>{if(t.size===0)return!0;let n=e.querySelectorAll(`[data-turn-entry]`),r=!1;for(let e of n){let n=e.getAttribute(`data-turn-entry`);if(!(!n||!t.has(n))&&(r=!0,!Uj(e)))return!1}return r},Gj=(e,t)=>{if(e){if(t){e.style.visibility=`hidden`,e.setAttribute(Bj,`pending`);return}e.style.removeProperty(`visibility`),e.setAttribute(Bj,`ready`)}},Kj=(e,t)=>t?{...e,visibility:`hidden`}:e,qj=({root:e,relevantKeys:t,onReady:n,timeoutMs:r=600,signal:i})=>{let a=!1,o=()=>{a||(a=!0,d(),n())},s=()=>{if(i?.aborted){o();return}Wj(e,t)&&o()},c=null;if(typeof MutationObserver<`u`){c=new MutationObserver(s);let t=e instanceof Element?e:e instanceof Document?e.documentElement:null;t&&c.observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[Rj,zj,`data-turn-entry`]})}let l=null;r>0&&(l=setTimeout(o,r));let u=()=>o();i?.addEventListener(`abort`,u,{once:!0});let d=()=>{c?.disconnect(),c=null,l!==null&&(clearTimeout(l),l=null),i?.removeEventListener(`abort`,u)};return s(),queueMicrotask(s),()=>{a||(a=!0,d())}},Jj=e=>{let t=new Map,n=!1,r=()=>{if(n=!1,t.size===0)return;let r=new Map(t);t.clear(),e(r)};return{enqueue(e,i){t.set(e,i),!n&&(n=!0,queueMicrotask(r))},flush:r,clear(){t.clear(),n=!1},pendingCount:()=>t.size}},Yj=e=>{let t=e.borderBoxSize?.[0];return t?{width:t.inlineSize,height:t.blockSize}:{width:e.contentRect.width,height:e.contentRect.height}},Xj=e=>{let t=Jj(e),n=typeof ResizeObserver>`u`?null:new ResizeObserver(e=>{for(let n of e)t.enqueue(n.target,Yj(n))});return{observe(e){n?.observe(e)},unobserve(e){n?.unobserve(e)},disconnect(){n?.disconnect(),t.clear()}}},Zj=e=>{let t=e.resizeItem.bind(e),n=Jj(e=>{for(let[n,r]of e)t(n,r)});return e.resizeItem=(e,t)=>{n.enqueue(e,t)},()=>{e.resizeItem=t,n.flush()}},Qj=({scopeKey:e,generation:t=0,root:n,relevantKeys:r,enabled:i=!0})=>{let a=`${e}:${t}`,[o,s]=Z.useState(a),[c,l]=Z.useState(i),u=Z.useRef(new Set);i&&o!==a&&(Hj({reason:t>0&&o.startsWith(`${e}:`)?`jump-to-latest`:`session-open`,alreadyRevealedForScope:u.current.has(e)})&&l(!0),s(a)),!i&&c&&l(!1);let d=r.join(`\0`),f=Z.useMemo(()=>new Set(r),[d]),p=J(()=>{u.current.add(e),l(!1)});return at(()=>{if(!i||!c){Gj(n,!1);return}if(Gj(n,!0),n)return qj({root:n,relevantKeys:f,onReady:p})},[i,c,n,f,a]),i&&c},$j=(e,t)=>{if(t.length===0||!Number.isFinite(e.scroll)||!Number.isFinite(e.start))return null;let n=Math.max(0,Math.min(Math.floor(e.start),t.length-1)),r=t[n];if(r===void 0)return null;let i=e.positionAtIndex(n);return i===void 0||!Number.isFinite(i)?null:{key:r,offsetFromViewportTop:i-e.scroll}},eM=(e,t)=>{let n=$j(e,t);return n===null?null:{anchor:n,knownKeys:new Set(t)}},tM=15e3,nM=(e,t)=>{let n=e.positionByKey(t.key);return n===void 0||!Number.isFinite(n)?null:n-t.offsetFromViewportTop},rM=(e,t)=>{if(!Number.isFinite(e.scroll))return null;let n=nM(e,t);return n===null?null:e.scroll-n},iM=e=>{if(e.drift===null||e.elapsedMs>=3e3)return{action:`release`,stableFrames:0};if(Math.abs(e.drift)<=1){let t=e.stableFrames+1;return{action:t>=8?`release`:`wait`,stableFrames:t}}return{action:e.msSinceLastCorrection>=64?`correct`:`wait`,stableFrames:0}},aM=1;function oM(e,{offset:t=0,hideTopShadow:n=!1,hideBottomShadow:r=!1}={}){let i=e.scrollTop>t+aM,a=e.scrollHeight-(e.scrollTop+e.clientHeight)>t+aM,o=!n&&i;return r&&(a=!1),o&&a?(e.dataset.topBottomScroll=`true`,e.removeAttribute(`data-top-scroll`),e.removeAttribute(`data-bottom-scroll`)):(e.dataset.topScroll=String(o),e.dataset.bottomScroll=String(a),e.removeAttribute(`data-top-bottom-scroll`)),o&&a?`both`:o?`top`:a?`bottom`:`none`}function sM(e,t=48){e.dataset.scrollShadow=`true`,e.dataset.orientation=`vertical`,e.style.setProperty(`--scroll-shadow-size`,`${t}px`)}var cM=.4,lM=e=>!Number.isFinite(e)||e<=0?0:e*cM,uM=(e,t=16)=>Number.isFinite(e)&&e>0?e:t,dM=({viewportHeight:e,endInsetHeight:t=0,anchorOffset:n=16})=>!Number.isFinite(e)||e<=0?0:Math.max(0,e-(Number.isFinite(t)?Math.max(0,t):0)-n),fM=e=>{let{contentLength:t,scrollLength:n}=e;return typeof t!=`number`||typeof n!=`number`||!Number.isFinite(t)||!Number.isFinite(n)?null:Math.max(0,t-n)},pM=({anchorTop:e,anchorOffset:t=16,maxScrollOffset:n})=>{let r=Math.max(0,e-t);return typeof n!=`number`||!Number.isFinite(n)?r:Math.min(r,Math.max(0,n))},mM=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),hM=`data-oc-timeline-park-end`,gM=e=>{if(!e)return null;let t=e.getAttribute(hM);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},_M=(e,t)=>{if(!e)return;if(t===null||!Number.isFinite(t)){e.hasAttribute(`data-oc-timeline-park-end`)&&e.removeAttribute(hM);return}let n=String(Math.round(t));e.getAttribute(`data-oc-timeline-park-end`)!==n&&e.setAttribute(hM,n)},vM=(e,t)=>t!==null&&Number.isFinite(t)?mM({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),yM=({usableViewportHeight:e,viewportHeight:t,contentHeight:n})=>{if(!Number.isFinite(e)||e<=0)return 0;let r=lM(Number.isFinite(t)&&t>0?t:e),i=r>0?Math.min(e,r):e;return n===null||!Number.isFinite(n)||n<=0?i:Math.min(i,Math.max(0,e-n))},bM=(e,t)=>!Number.isFinite(e)||!Number.isFinite(t)||t<=0?!1:e>t+1,xM=({overflowsUsableViewport:e=!1,previousEndSpaceSize:t,nextEndSpaceSize:n})=>e?!0:t===void 0||n===void 0||!Number.isFinite(t)||!Number.isFinite(n)?!1:n>t+1,SM=({previous:e,reserveId:t,entryKey:n,contentHeight:r,usableViewportHeight:i,viewportHeight:a})=>{let o=yM({usableViewportHeight:i,viewportHeight:a,contentHeight:r}),s=r!==null&&bM(r,i),c={reserveId:t,entryKey:n,contentHeight:r,spacerHeight:s?0:o};return s?{snapshot:c,release:!0}:e===null||e.reserveId!==t||e.entryKey!==n?{snapshot:c,release:!1}:e.contentHeight!==null&&r!==null&&r+1<e.contentHeight&&xM({previousEndSpaceSize:e.spacerHeight,nextEndSpaceSize:o})?{snapshot:{...c,spacerHeight:0},release:!0}:{snapshot:c,release:!1}},CM=(e,t)=>{let n=e.positionAtIndex(t),r=e.sizeAtIndex(t);return typeof n!=`number`||typeof r!=`number`||!Number.isFinite(n)||!Number.isFinite(r)?null:n+Math.max(1,r)},wM=({state:e,anchorIndex:t,endInsetHeight:n,anchorOffset:r,lastIndex:i})=>{if(e.data.length===0)return null;let a=Math.max(0,Math.min(t,e.data.length-1)),o=e.positionAtIndex(a),s=CM(e,Math.max(0,Math.min(i??e.data.length-1,e.data.length-1)));if(typeof o!=`number`||!Number.isFinite(o)||s===null)return null;let c=dM({viewportHeight:e.scrollLength,endInsetHeight:n,anchorOffset:r}),l=Math.max(0,s-o),u=e.scroll+c,d=Math.max(0,s-c),f=Math.max(0,d-e.scroll);return{anchorTop:o,lastBottom:s,turnHeight:l,usableViewportHeight:c,visibleUsableBottom:u,overflowsUsableViewport:l>c,targetScrollToRevealEnd:d,scrollDeltaToRevealEnd:f}},TM=e=>{if(!e)return;let{contentLength:t,scroll:n,scrollLength:r}=e;return typeof t==`number`&&typeof n==`number`&&typeof r==`number`&&Number.isFinite(t)?t-(n+r)<=40:e.isNearEnd??e.isAtEnd},EM=e=>{if(!e)return;let{contentLength:t,scroll:n,scrollLength:r}=e;if(!(typeof t!=`number`||typeof n!=`number`||typeof r!=`number`||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)))return Math.max(0,t-(n+r))},DM=(e,t)=>e===void 0||!Number.isFinite(e)?t:e<=40?!1:e>=80||t,OM=(e,t)=>{if(e.length===0||t.length<=e.length)return!1;let n=e[0];return n===void 0||t[0]===n?!1:t.includes(n)},kM=`data-oc-timeline-anchoring`,AM=1200,jM=(e,t,n,r={})=>{if(t!==null)for(let i=e.length-1;i>=0;--i){let a=e[i];if(a!==void 0&&n(a)===t)return{anchorIndex:i,anchorOffset:r.anchorOffset??16,anchorId:t}}},MM=({sessionChanged:e,previousUserOrder:t,currentUserOrder:n,currentAnchorId:r,consumedSendMessageId:i})=>{if(i!==null)return i;if(e||r===null)return null;if(n.includes(r))return r;let a=t[t.length-1],o=n[n.length-1];return r===a&&o!==void 0&&n.length===t.length&&t.length>0?o:r},NM=(e,t)=>!Number.isFinite(t)||t<=0||typeof e!=`number`||!Number.isFinite(e)||t+1>=e?null:t,PM={itemVisiblePercentThreshold:0},FM=100,IM=116,LM=500,RM=new Set,zM=Z.createContext(RM),BM=`oc-reply-reserve`,VM=e=>e.kind===BM,HM=e=>{if(VM(e))return e.spacerHeight>0?e.spacerHeight:void 0},UM=(e,t,n,r,i)=>{if(!e||t)return null;let a=wM({state:n,anchorIndex:e.anchorIndex,lastIndex:e.anchorIndex,endInsetHeight:r,anchorOffset:i});return a?pM({anchorTop:a.anchorTop,anchorOffset:i,maxScrollOffset:fM(n)}):null},WM=(e,t)=>{if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t;let n=e?.clientHeight??0;return n>0?n:0},GM=e=>e.key,KM=e=>e.kind,qM=()=>{let e=(0,Q.c)(6),t=Z.useRef(null),n=Z.useRef(0),[r,i]=Z.useState(null),[a,o]=Z.useState(0),s;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=t.current?.offsetHeight??0;n.current=e,o(t=>t===e?t:e)},e[0]=s):s=e[0];let c=J(s),l;e[1]===c?l=e[2]:(l=e=>{t.current=e,i(t=>t===e?t:e),c()},e[1]=c,e[2]=l);let u=J(l);st(typeof ResizeObserver<`u`?r:null,c);let d;return e[3]!==a||e[4]!==u?(d={height:a,heightRef:n,setElement:u},e[3]=a,e[4]=u,e[5]=d):d=e[5],d},JM=({entry:e,index:t,renderEntryRef:n,sizeObserverRef:r})=>{let i=Z.useContext(zM),a=Z.useRef(null);return Z.useLayoutEffect(()=>{let e=a.current,t=r.current;if(!(!e||!t))return t.observe(e),()=>t.unobserve(e)},[e.key,r]),(0,$.jsx)(`div`,{ref:a,"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:n.current?.(e,t,i.has(e.key))})},YM=Z.memo(({entries:e,timelineCacheKey:t,estimatedItemSize:n,hydrationTuning:r,renderEntry:i,rowInvalidationKey:a,scrollElementRef:o,scrollElementDataset:s,hideTopScrollShadow:c=!1,hideBottomScrollShadow:l=!1,registerList:u,anchoredEndSpace:d,onAnchoredTurnParkReleased:f,followEnabled:p=!0,historyAnchorToken:m=0,pinRevealGeneration:h=0,sessionIsWorking:g=!1,onIsAtEndChange:_,onScroll:v,header:y,footer:b,className:x,style:S,contentContainerClassName:C,contentContainerStyle:w})=>{let T=Z.useRef(null),E=Z.useMemo(()=>e.map(e=>e.key),[e]),D=Z.useRef(E);D.current=E;let O=Z.useRef(r);O.current=r;let k=J(e=>{T.current=e,u?.(e)}),A=Z.useRef(null),[j,M]=Z.useState(null),[N,P]=Z.useState(0),{height:F,setElement:I}=qM(),{height:L,heightRef:R,setElement:z}=qM(),B=y==null?null:(0,$.jsx)(`div`,{ref:I,"data-oc-timeline-header":``,children:y}),V=b==null?null:(0,$.jsx)(`div`,{ref:z,"data-oc-timeline-footer":``,children:b}),H=Z.useRef(c);H.current=c;let U=Z.useRef(l);U.current=l;let W=J((e=A.current)=>{!e||s?.scrollShadow!==`true`||(sM(e),oM(e,{hideTopShadow:H.current,hideBottomShadow:U.current}))}),ee=J(e=>{let t=e?.getScrollableNode?.()??null;if(t&&s){for(let[e,n]of Object.entries(s))t.dataset[e]=n;W(t)}A.current=t,o&&(o.current=t),M(t);let n=WM(t,T.current?.getState()?.scrollLength);P(e=>e===n?e:n)}),G=J(()=>{let e=WM(A.current,T.current?.getState()?.scrollLength);P(t=>t===e?t:e),W()});Z.useLayoutEffect(()=>{W(j)},[l,c,j]),st(typeof ResizeObserver<`u`?j:null,G);let[K,te]=Z.useState(0),[ne,re]=Z.useState(0),ie=K!==ne,ae=Z.useRef(!0),oe=Z.useRef(!1),[se,ce]=Z.useState(!1),le=Z.useRef(!1);Z.useLayoutEffect(()=>{ae.current=!0,oe.current=!1,le.current=!1,ce(!1)},[t]);let[ue,de]=Z.useState(null),fe=J(e=>{de(t=>t?.token===e?null:t)});Z.useEffect(()=>{p&&de(null)},[p]),Z.useLayoutEffect(()=>{if(m<=0)return;let e=T.current;if(!e)return;let t=eM(e.getState(),D.current);t&&de({token:m,arm:t,holding:!1})},[m]),Z.useEffect(()=>{if(!ue||ue.holding)return;let{token:e}=ue,t=window.setTimeout(()=>{de(t=>t?.token===e&&!t.holding?null:t)},tM);return()=>window.clearTimeout(t)},[ue]);let pe=Z.useRef(E);Z.useLayoutEffect(()=>{let e=pe.current;pe.current=E,OM(e,E)&&(te(e=>e+1),de(e=>e===null||e.holding?e:{...e,holding:!0}))},[E]),Z.useEffect(()=>{if(!ie)return;let e=window.setTimeout(()=>{re(K)},AM);return()=>window.clearTimeout(e)},[ie,K]),Z.useEffect(()=>{if(!ue?.holding)return;let{token:e,arm:{anchor:t}}=ue,n=T.current;if(!n||typeof window>`u`){fe(e);return}let r=A.current,i=Date.now(),a=0,o=null,s=null,c=!1,l=[],u=t=>{if(!c){c=!0,s!==null&&(window.cancelAnimationFrame(s),s=null);for(let[e,t]of l)r?.removeEventListener(e,t);t&&fe(e)}},d=()=>{if(s=null,c)return;let e=n.getState();if(TM(e)??e.isAtEnd){u(!0);return}let r=Date.now(),l=iM({drift:rM(e,t),elapsedMs:r-i,stableFrames:a,msSinceLastCorrection:o===null?1/0:r-o});if(a=l.stableFrames,l.action===`release`){u(!0);return}if(l.action===`correct`){let i=nM(e,t);i!==null&&(o=r,n.scrollToOffset({offset:i,animated:!1}))}s=window.requestAnimationFrame(d)},f=()=>{u(!0)};for(let e of[`touchstart`,`touchmove`,`wheel`,`pointerdown`,`keydown`])l.push([e,f]);for(let[e,t]of l)r?.addEventListener(e,t,{passive:!0});return s=window.requestAnimationFrame(d),()=>{u(!1)}},[fe,ue]);let me=ie||ue!==null;Z.useLayoutEffect(()=>{let e=A.current;if(!(!e||!me))return e.setAttribute(kM,`true`),()=>{e.removeAttribute(kM)}},[me]);let he=Z.useMemo(()=>{if(ue===null)return{data:!0,size:ie};let{knownKeys:e}=ue.arm;return{data:!0,size:!0,shouldRestorePosition:t=>e.has(t.key)}},[ue,ie]),[ge,_e]=Z.useState(()=>Nj(E,{restore:jj(t)??null})),ve=Z.useRef(ge);ve.current=ge;let ye=Z.useRef(0),be=Z.useRef(0),xe=Z.useRef(null),Se=Z.useRef(!1),Ce=Z.useRef(null),we=Z.useMemo(()=>Pj(ge,E),[ge,E]),Te=Kj(S,Qj({scopeKey:t,generation:h,root:j,relevantKeys:Z.useMemo(()=>Vj({entryKeys:E}),[t,h,E.length,E[E.length-1]]),enabled:E.length>0}));Z.useEffect(()=>{_e(e=>Lj(e,E))},[E]),Z.useEffect(()=>()=>{Mj(t,ve.current)},[t]);let Ee=J(()=>{Se.current=!1;let e=T.current;if(!e)return;let t=D.current;if(t.length===0)return;let n=e.getState(),r=t.length-1,i=Math.max(0,Math.floor(n.startBuffered)),a=Math.min(r,Math.floor(n.endBuffered));if(!Number.isFinite(i)||!Number.isFinite(a)||a<i)return;let o=[];for(let e=i;e<=a;e+=1)o.push(e);let s=Math.max(0,Math.floor(n.start)),c=Math.min(r,Math.floor(n.end)),l=Math.max(0,c-s+1),u=Date.now()-ye.current>=FM,d=O.current,f=d.resolvePreloadEntries(l),p=Ij({entryKeys:t,mountedIndexes:o,visibleStartIndex:s,visibleEndIndex:c,scrollDirection:xe.current,preloadEntries:f,hydratedKeys:ve.current,allowVisibleRelease:u,preloadReleaseLimit:u?f:d.resolvePreloadReleaseWhileScrolling(),visibleReleaseLimit:d.resolveVisibleReleaseLimit()});p.length!==0&&(Oe(),Z.startTransition(()=>{_e(e=>{let t=!1,n=new Set(e);for(let e of p)n.has(e)||(n.add(e),t=!0);return t?n:e})}))}),De=J(()=>{Se.current||(Se.current=!0,vc(Ee))}),Oe=J(()=>{typeof window>`u`||(Ce.current!==null&&window.clearTimeout(Ce.current),Ce.current=window.setTimeout(()=>{Ce.current=null,De()},IM))});Z.useEffect(()=>()=>{Ce.current!==null&&(window.clearTimeout(Ce.current),Ce.current=null)},[]);let ke=J(()=>{De()}),Ae=J(()=>{ye.current=Date.now();let e=T.current;if(e){let t=e.getState(),n=t.scroll;Number.isFinite(n)&&n!==be.current&&(xe.current=n>be.current?`forward`:`backward`,be.current=n);let r=WM(A.current,t.scrollLength);r>0&&P(e=>e===r?e:r);let i=UM(qe.current,Fe.current,t,R.current,Ye.current);_M(A.current,i);let a=i===null?null:mM({scroll:t.scroll,parkOffset:i}),o=a??EM(t),s=a===null?TM(t)??t.isAtEnd:a<=40,c=DM(o,oe.current);(s!==ae.current||c!==oe.current)&&(ae.current=s,oe.current=c,_?.(s,c)),s&&!le.current&&(le.current=!0,ce(!0))}v?.(),W(),De(),Oe()}),je=Z.useRef(i);je.current=i;let[Me,Ne]=Z.useState(null),Pe=Z.useRef(null),Fe=Z.useRef(!1),Ie=Z.useRef(null),Le=Z.useRef(null),Re=Z.useRef(0),ze=Z.useRef(0),q=Z.useRef(null),Be=J((e,t)=>{let n=T.current,r=n?.getState().sizes.get(e);if(n&&NM(r,t.height)!==null&&n.setItemSize(e,t),Fe.current||e!==Le.current)return;let i=Ie.current;if(i===null)return;let{snapshot:a,release:o}=SM({previous:Pe.current,reserveId:i,entryKey:e,contentHeight:t.height,usableViewportHeight:Re.current,viewportHeight:ze.current});if(o){Ne(null),ot(i),ct(`reveal`);return}let s=Pe.current;(s?.spacerHeight!==a.spacerHeight||s?.contentHeight!==a.contentHeight||s?.entryKey!==a.entryKey||s?.reserveId!==a.reserveId)&&Ne(a),q.current!==i&&ct(`park`)&&(q.current=i)}),Ve=Z.useRef(Be);Ve.current=Be;let He=Z.useMemo(()=>Xj(e=>{for(let[t,n]of e){let e=t instanceof HTMLElement?t.dataset.turnEntry:void 0;e&&n.height>0&&Ve.current(e,n)}}),[]),Ue=Z.useRef(He);Ue.current=He,Z.useEffect(()=>()=>{He.disconnect()},[He]);let We=Z.useMemo(()=>({item:e,index:t})=>VM(e)?(0,$.jsx)(`div`,{"data-oc-reply-reserve":`true`,"aria-hidden":`true`,style:{height:e.spacerHeight,flexShrink:0}}):(0,$.jsx)(JM,{entry:e,index:t,renderEntryRef:je,sizeObserverRef:Ue}),[]),Ge=Z.useRef(p);Ge.current=p;let Ke=Z.useRef(ue);Ke.current=ue;let qe=Z.useRef(d);qe.current=d;let Je=Z.useRef(0),Ye=Z.useRef(16),Xe=Z.useRef(null),[Ze,Qe]=Z.useState(null),$e=d?e[d.anchorIndex]?.key??null:null,et=d?.anchorId??$e,tt=et!==null&&Ze===et;d||(q.current=null,Je.current=0);let nt=N>0?N:WM(A.current,T.current?.getState()?.scrollLength),rt=uM(F),it=dM({viewportHeight:nt,endInsetHeight:L,anchorOffset:rt}),at=Me;if(!et||!$e||tt)Me!==null&&Ne(null),at=null;else if(it<=0)at=Me!==null&&Me.reserveId===et&&Me.entryKey===$e?Me:null;else if(Me===null||Me.reserveId!==et||Me.entryKey!==$e){let{snapshot:e}=SM({previous:Me?.reserveId===et?Me:null,reserveId:et,entryKey:$e,contentHeight:Me?.reserveId===et?Me.contentHeight:null,usableViewportHeight:it,viewportHeight:nt});Ne(e),at=e}Pe.current=at,Fe.current=tt,Ie.current=et,Le.current=$e,Re.current=it,ze.current=nt,Ye.current=rt,Z.useLayoutEffect(()=>{q.current=null,Je.current=0,Xe.current=null,Qe(null)},[t]),Z.useLayoutEffect(()=>{d&&G()},[d]);let ot=J(e=>{e!==null&&Xe.current!==e&&(Xe.current=e,Qe(e),f?.(e))}),ct=J(t=>{let n=qe.current;if(!n||Ke.current)return!1;let r=T.current;if(!r)return!1;let i=r.getState(),a=Ye.current,o=wM({state:i,anchorIndex:n.anchorIndex,lastIndex:n.anchorIndex,endInsetHeight:R.current,anchorOffset:a});if(!o)return!1;if(t===`park`){let e=Math.max(0,o.anchorTop-a),t=typeof performance<`u`?performance.now():Date.now(),n=!(typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)&&Math.abs(i.scroll-e)>=1;return n&&(Je.current=t+LM),r.scrollToOffset({offset:e,animated:n}),!0}return bM(o.turnHeight,Re.current)&&ot(n.anchorId??e[n.anchorIndex]?.key??null),(typeof performance<`u`?performance.now():Date.now())<Je.current||!Ge.current||o.scrollDeltaToRevealEnd<1?!1:(r.scrollToOffset({offset:o.targetScrollToRevealEnd,animated:!1}),!0)});Z.useLayoutEffect(()=>{if(!et||!$e||tt||it<=0)return;let e=Pe.current;if(e===null||e.reserveId!==et||e.entryKey!==$e)return;let{snapshot:t,release:n}=SM({previous:e,reserveId:et,entryKey:$e,contentHeight:e.contentHeight,usableViewportHeight:it,viewportHeight:nt});if(n){Ne(null),ot(et),ct(`reveal`);return}t.spacerHeight!==e.spacerHeight&&Ne(t)},[$e,tt,et,nt,it]),Z.useLayoutEffect(()=>{!at||ue||q.current!==et&&ct(`park`)&&(q.current=et)},[at,ue,et]),Z.useLayoutEffect(()=>{let e=A.current,t=T.current;if(e){if(!t){_M(e,null);return}_M(e,UM(d,tt,t.getState(),L,rt))}},[d,L,rt,tt]);let lt=Z.useMemo(()=>{let t=at?.spacerHeight??0;return!at||t<=0?e:[...e,{key:`${BM}:${at.reserveId}`,kind:BM,spacerHeight:t}]},[at,e]),ut=Z.useMemo(()=>d&&!tt||!p||ue?!1:{animated:g&&se,on:{dataChange:!0,itemLayout:!0,layout:!0,footerLayout:!0}},[d,se,p,ue,tt,g]);return(0,$.jsx)(zM.Provider,{value:we,children:(0,$.jsx)(nl,{ref:k,refScrollView:ee,data:lt,extraData:a,keyExtractor:GM,getItemType:KM,getFixedItemSize:HM,renderItem:We,estimatedItemSize:n,initialScrollAtEnd:!0,recycleItems:!1,maintainScrollAtEnd:ut,maintainVisibleContentPosition:he,onScroll:Ae,onViewableItemsChanged:ke,viewabilityConfig:PM,ListHeaderComponent:B,ListFooterComponent:V,className:x,style:Te,contentContainerClassName:C,contentContainerStyle:w})})}),XM=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},ZM=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},QM=e=>!e||XM(e)!==`user`?!1:e.parts.some(e=>{if(e?.type!==`text`)return!1;let t=e.text;return e.synthetic===!0&&typeof t==`string`&&t.trim().startsWith(`The following tool was executed by the user`)}),$M=(e,t)=>{if(XM(e)!==`assistant`||t&&ZM(e)!==t||e.parts.length!==1)return{hide:!1,details:null};let n=e.parts[0];return n?.type!==`tool`||(typeof n.tool==`string`?n.tool.toLowerCase():``)!==`bash`?{hide:!1,details:null}:{hide:!0,details:{command:typeof n.state?.input?.command==`string`?n.state.input.command:void 0,output:(typeof n.state?.output==`string`?n.state.output:void 0)??(typeof n.state?.metadata?.output==`string`?n.state.metadata.output:void 0),status:typeof n.state?.status==`string`?n.state.status:void 0}}},eN=(e,t)=>{let n=e[t];if(!n)return null;let r=n.info.id;for(let n=t+1;n<e.length;n+=1){let t=e[n];if(XM(t)===`user`)break;let{hide:i,details:a}=$M(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},tN=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},nN=(e,t)=>{if(e.length===0)return[];if(e.filter(tN).length===e.length)return e;if(t){let n=e.findIndex(e=>e.info.id===t);if(n>=0)return e.slice(0,n+1)}return e},rN=e=>{if(e.chatRenderMode!==`sorted`)return null;let t=e.streamingAssistantMessageId;if(!t)return null;let n=e.assistants.find(e=>e.info.id===t);if(!n)return null;let r=n.info,i=hE({finish:r.finish,isMessageCompleted:tN(n),activeStreamingPhase:e.activeStreamingPhase});return gE({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},iN=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},aN=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=iN(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},oN=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},sN=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=oN(t.mode)??oN(t.agent),r=oN(t.providerID),i=oN(t.modelID),a=oN(t.model?.variant)??oN(t.variant);return!n&&!r&&!i&&!a?null:{agentName:n,providerId:r,modelId:i,variant:a}},cN=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:Si(void 0,t)||void 0,variant:e?.variant}},lN=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),uN=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:sk(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),dN=5,fN=[],pN=new Set,mN=[],hN=16,gN=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),_N=320,vN=168,yN=8,bN=16,xN=6,SN=12,CN=4,wN=1,TN=2,EN=6,DN=4,ON=()=>cn()?bN:yN,kN=30,AN=180,jN=5,MN=2,NN=120,PN=1200,FN=80,IN=160,LN=1500,RN=1.5,zN=90,BN=(e,t)=>{if(e.length===0||t.length<=e.length||e[e.length-1]?.key!==t[t.length-1]?.key)return!1;let n=e[0]?.key;return t.findIndex(e=>e.key===n)>0},VN=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(gN(r.keys,n))return r.items;t.delete(e)}},write:(n,r,i)=>{if(r.length!==0)for(t.delete(n),t.set(n,{keys:r.slice(),items:i});t.size>e;){let e=t.keys().next().value;if(typeof e!=`string`)break;t.delete(e)}}}})(hN),HN=(e,t,n)=>{if(t.size===0)return[];let r=0;return e.map((e,i)=>{let a=t.get(e)??n,o={index:i,key:e,start:r,size:a,end:r+a,lane:0};return r+=a,o})},UN=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),WN=e=>e===`collapsed`?vN:_N,GN=(e,t)=>`${e}::activity:${t}`,KN=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),qN=(e,t,n)=>{let r=Number.isFinite(e)?Math.max(0,e):0,i=Number.isFinite(t)?Math.max(r,t):r,a=Number.isFinite(n)?Math.max(0,n):0;return{paddingTop:r,paddingBottom:Math.max(0,a-i),minHeight:a}},JN=(e,t)=>{if(!e)return;let n=`${Math.max(0,Number.isFinite(t)?t:0)}px`;e.style.height!==``&&(e.style.height=``),e.style.minHeight!==n&&(e.style.minHeight=n)},YN=(e,t=0)=>Math.max(e===`collapsed`?SN:xN,Math.max(0,Math.floor(t))),XN=e=>e===`collapsed`?TN:wN,ZN=e=>e===`collapsed`?DN:EN,QN=e=>e===`collapsed`?MN:jN,$N=(e,t)=>{e.current=t},eP=(e,t)=>VN.read(e,t),tP=(e,t,n)=>{!n||t.length===0||VN.write(e,t,n.takeSnapshot())},nP=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},rP=(e,t)=>{if(nP(e)!==`system`)return e;let n=oP(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},iP=e=>!e||nP(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),aP=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},oP=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},sP=(e,t,n)=>{if(typeof window>`u`)return!1;let r=e;for(;r&&r!==t;){if(window.getComputedStyle(r).position===`sticky`&&r.getBoundingClientRect().top<=n+1)return!0;r=r.parentElement}return!1},cP=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,lP=(e,t=e)=>{let n=e.getBoundingClientRect(),r=Array.from(t.querySelectorAll(`[data-message-id]`)),i=r.find(t=>t.getBoundingClientRect().bottom>n.top+1&&!sP(t,e,n.top))??r.find(e=>e.getBoundingClientRect().bottom>n.top+1),a=i?.dataset.messageId;return!i||!a?null:{messageId:a,offsetTop:i.getBoundingClientRect().top-n.top}},uP=(e,t)=>{let n=lP(t,e);if(!n)return null;let r=cP(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},dP=e=>{let t=e,n=t.state?.metadata,r=mS(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?vS(i)??null:null},fP=e=>{if(nP(e)!==`assistant`||e.parts.length!==1)return{hide:!1,taskSessionId:null};let t=e.parts[0];return t?.type!==`tool`||(typeof t.tool==`string`?t.tool.toLowerCase():``)!==`task`?{hide:!1,taskSessionId:null}:{hide:!0,taskSessionId:dP(e.parts[0])}},pP=(e,t)=>{if(!t)return e;let n=hS(e.parts,t);return n===e.parts?e:{...e,parts:n}},mP=(e,t)=>{let n=typeof t?.command==`string`?t.command.trim():``,r=typeof t?.output==`string`?t.output:``,i=typeof t?.status==`string`?t.status.trim():``,a=[],o=!1;for(let t of e.parts){if(!o&&t?.type===`text`){let e=t.text;if(t.synthetic===!0&&typeof e==`string`&&e.trim().startsWith(`The following tool was executed by the user`)){a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),o=!0;continue}}a.push(t)}return o||a.push({type:`text`,text:`/shell`,shellAction:{...n?{command:n}:{},...r?{output:r}:{},...i?{status:i}:{}}}),{...e,parts:a}},hP=e=>e.kind===`turn`?e.turn.userMessage.info.id:nP(e.message)===`user`?e.message.info.id:null,gP=e=>e.chatRenderMode!==`sorted`||e.activityPresentationKind!==`compaction`||e.hasVisibleActivitySegments||e.hasAssistantMessages?!1:e.completionDisposition===`normal`||e.completionDisposition===`abnormal`||e.completionDisposition===`active`&&e.isLastTurn&&e.sessionIsWorking,_P=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,reviewTransferDirection:m}=e,h=Rh(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1}}:h,t[0]=n.sourceDirectory,t[1]=n.sourceSessionID,t[2]=h,t[3]=g):g=t[3];let _=g,v;t[4]!==c||t[5]!==l||t[6]!==f||t[7]!==o||t[8]!==s||t[9]!==n||t[10]!==i||t[11]!==d||t[12]!==u||t[13]!==r||t[14]!==m||t[15]!==p||t[16]!==a?(v=(0,$.jsx)(Mk,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,reviewTransferDirection:m}),t[4]=c,t[5]=l,t[6]=f,t[7]=o,t[8]=s,t[9]=n,t[10]=i,t[11]=d,t[12]=u,t[13]=r,t[14]=m,t[15]=p,t[16]=a,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Lh.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return YS(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&XS(e.previousMessage,t.previousMessage)&&XS(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&iC(n,r,e.message.info.id,nP(e.message)===`user`)&&e.assistantHeaderMessageId===t.assistantHeaderMessageId&&e.isInActiveTurn===t.isInActiveTurn&&e.activeStreamingPhase===t.activeStreamingPhase&&e.reviewTransferDirection===t.reviewTransferDirection&&e.animationHandlers?.onChunk===t.animationHandlers?.onChunk&&e.animationHandlers?.onComplete===t.animationHandlers?.onComplete&&e.animationHandlers?.onStreamingCandidate===t.animationHandlers?.onStreamingCandidate&&e.animationHandlers?.onAnimationStart===t.animationHandlers?.onAnimationStart&&e.animationHandlers?.onReservationCancelled===t.animationHandlers?.onReservationCancelled&&e.animationHandlers?.onReasoningBlock===t.animationHandlers?.onReasoningBlock&&e.animationHandlers?.onAnimatedHeightChange===t.animationHandlers?.onAnimatedHeightChange});_P.displayName=`MessageRow`;var vP=Z.memo(e=>{let t=(0,Q.c)(109),{turn:n,isLastTurn:r,sessionIsWorking:i,activityRenderMode:a,turnUiStates:o,onToggleTurnGroup:s,chatRenderMode:c,onMessageContentChange:l,getAnimationHandlers:u,scrollToBottom:d,stickyUserHeader:f,shouldAnimateUserMessage:p,onUserAnimationConsumed:m,activeStreamingMessageId:h,activeStreamingPhase:g,reviewTransferDirection:_}=e,v=f===void 0||f,y;t[0]!==n.turnId||t[1]!==o?(y=o.get(n.turnId),t[0]=n.turnId,t[1]=o,t[2]=y):y=t[2];let b=y,x;if(t[3]!==a||t[4]!==r||t[5]!==i||t[6]!==n.assistantMessages.length||t[7]!==n.completionDisposition||t[8]!==n.durationMs||t[9]!==n.hasConfirmedFinalBody){let e=lk({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=uN({expansionDisposition:fk({isLastTurn:r,turnCompletionDisposition:n.completionDisposition,headerPresentationDisposition:e.completionDisposition,hasAssistantMessages:n.assistantMessages.length>0}),activityRenderMode:a,isLastTurn:r,isActivelyProcessing:r&&i,hasConfirmedFinalBody:n.hasConfirmedFinalBody}),t[3]=a,t[4]=r,t[5]=i,t[6]=n.assistantMessages.length,t[7]=n.completionDisposition,t[8]=n.durationMs,t[9]=n.hasConfirmedFinalBody,t[10]=x}else x=t[10];let S=x,C=b?b.isExpanded:S,w;t[11]!==S||t[12]!==s||t[13]!==n.turnId?(w=()=>{s(n.turnId,S)},t[11]=S,t[12]=s,t[13]=n.turnId,t[14]=w):w=t[14];let T=J(w),E;if(t[15]!==n.assistantMessages||t[16]!==n.userMessage){let e=[n.userMessage,...n.assistantMessages],r=new Map;e.forEach((e,t)=>{r.set(e.info.id,t)}),E={ordered:e,lookup:r},t[15]=n.assistantMessages,t[16]=n.userMessage,t[17]=E}else E=t[17];let D=E,O;bb0:{if(h&&n.assistantMessages.some(e=>e.info.id===h)){O=h;break bb0}for(let e=n.assistantMessages.length-1;e>=0;--e){let t=n.assistantMessages[e];if(!tN(t)){O=t.info.id;break bb0}}O=null}let k=O,A;t[18]!==g||t[19]!==c||t[20]!==k||t[21]!==n.assistantMessages?(A=rN({chatRenderMode:c,assistants:n.assistantMessages,streamingAssistantMessageId:k,activeStreamingPhase:g}),t[18]=g,t[19]=c,t[20]=k,t[21]=n.assistantMessages,t[22]=A):A=t[22];let j=A,M;bb1:{if(c===`live`){M=n.assistantMessages;break bb1}let e;t[23]!==k||t[24]!==n.assistantMessages?(e=nN(n.assistantMessages,k),t[23]=k,t[24]=n.assistantMessages,t[25]=e):e=t[25],M=e}let N=M,P;t[26]===N?P=t[27]:(P=new Map,N.forEach((e,t)=>{P.set(e.info.id,t)}),t[26]=N,t[27]=P);let F=P,I;t[28]===N?I=t[29]:(I=new Set(N.map(DP)),t[28]=N,t[29]=I);let L=I,R=N[0]?.info.id,z;bb2:{if(c!==`sorted`){z=n.activityParts;break bb2}let e;t[30]!==n.activityParts||t[31]!==n.assistantMessages.length||t[32]!==L?(e=L.size===n.assistantMessages.length?n.activityParts:n.activityParts.filter(e=>L.has(e.messageId)),t[30]=n.activityParts,t[31]=n.assistantMessages.length,t[32]=L,t[33]=e):e=t[33];let r=e,i;t[34]!==j||t[35]!==r?(i=iN(r,j),t[34]=j,t[35]=r,t[36]=i):i=t[36],z=i}let B=z,V;bb3:{if(c!==`sorted`){V=n.activitySegments;break bb3}if(j){let e;t[37]!==j||t[38]!==n.activitySegments?(e=aN(n.activitySegments,j),t[37]=j,t[38]=n.activitySegments,t[39]=e):e=t[39],V=e;break bb3}if(L.size===n.assistantMessages.length){V=n.activitySegments;break bb3}let e;if(t[40]!==n.activitySegments||t[41]!==L){let r;t[43]===L?r=t[44]:(r=e=>{let t=e.parts.filter(e=>L.has(e.messageId));if(t.length===0)return null;let n=L.has(e.anchorMessageId)?e.anchorMessageId:t[0]?.messageId;return n?{...e,anchorMessageId:n,parts:t}:null},t[43]=L,t[44]=r),e=n.activitySegments.map(r).filter(OP),t[40]=n.activitySegments,t[41]=L,t[42]=e}else e=t[42];V=e}let H=V,U=n.userMessage.info.time?.created,W=n.userMessage.info,ee=W?.model?.variant??W?.variant,G=typeof ee==`string`&&ee.trim().length>0?ee:void 0,K=typeof U==`number`?U:void 0,te;t[45]!==K||t[46]!==n.activityPresentationKind||t[47]!==n.changedFiles||t[48]!==n.diffStats||t[49]!==n.hasReasoning||t[50]!==n.hasTools||t[51]!==n.headerMessageId||t[52]!==n.summaryText||t[53]!==n.turnId||t[54]!==G||t[55]!==B||t[56]!==H?(te={turnId:n.turnId,summaryBody:n.summaryText,activityParts:B,activityGroupSegments:H,headerMessageId:n.headerMessageId,hasTools:n.hasTools,hasReasoning:n.hasReasoning,activityPresentationKind:n.activityPresentationKind,diffStats:n.diffStats,changedFiles:n.changedFiles,userMessageCreatedAt:K,userMessageVariant:G},t[45]=K,t[46]=n.activityPresentationKind,t[47]=n.changedFiles,t[48]=n.diffStats,t[49]=n.hasReasoning,t[50]=n.hasTools,t[51]=n.headerMessageId,t[52]=n.summaryText,t[53]=n.turnId,t[54]=G,t[55]=B,t[56]=H,t[57]=te):te=t[57];let ne=te,re;t[58]!==g||t[59]!==R||t[60]!==c||t[61]!==u||t[62]!==T||t[63]!==r||t[64]!==D.lookup||t[65]!==D.ordered||t[66]!==l||t[67]!==m||t[68]!==_||t[69]!==d||t[70]!==i||t[71]!==p||t[72]!==k||t[73]!==n.activityPresentationKind||t[74]!==n.completionDisposition||t[75]!==n.durationMs||t[76]!==n.hasConfirmedFinalBody||t[77]!==n.hasReasoning||t[78]!==n.hasTools||t[79]!==n.headerMessageId||t[80]!==n.turnId||t[81]!==n.userMessage||t[82]!==ne||t[83]!==H||t[84]!==F||t[85]!==N[0]?.info.id||t[86]!==N.length?(re=(e,t)=>{let a=nP(e)===`user`,o=D.lookup.get(e.info.id),s=F.get(e.info.id)??-1,f=s>=0,h=s===0,v=s===N.length-1,y=!!R&&e.info.id===R,b=H.some(t=>t.anchorMessageId===e.info.id),x=c===`sorted`?f:y||h||v,S=N[0]?.info.id??n.headerMessageId,C=a?void 0:f?h?n.userMessage:void 0:typeof o==`number`&&o>0?D.ordered[o-1]:void 0,w=lk({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs}),E=f?{turnId:n.turnId,activityOwnerMessageId:R,isFirstAssistantInTurn:h,isLastAssistantInTurn:v,isLatestTurn:r,isWorking:(r||n.completionDisposition===`active`)&&i&&(c===`sorted`?b:e.info.id===k),isTurnSettled:uk({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,hasConfirmedSettledAssistant:n.hasConfirmedFinalBody}),hasTools:n.hasTools,hasReasoning:n.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:n.activityPresentationKind,durationMs:w.durationMs,...x?{summaryBody:ne.summaryBody,activityParts:ne.activityParts,activityGroupSegments:ne.activityGroupSegments,headerMessageId:ne.headerMessageId,diffStats:ne.diffStats,changedFiles:ne.changedFiles,userMessageCreatedAt:ne.userMessageCreatedAt,userMessageVariant:ne.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(_P,{message:e,previousMessage:C,nextMessage:void 0,turnGroupingContext:E,assistantHeaderMessageId:S,isInActiveTurn:!!k&&e.info.id===k,activeStreamingPhase:e.info.id===k?g:null,reviewTransferDirection:_,animateUserOnMount:p(e),onUserAnimationConsumed:m,onContentChange:l,animationHandlers:u(e.info.id),scrollToBottom:d},e.info.id)},t[58]=g,t[59]=R,t[60]=c,t[61]=u,t[62]=T,t[63]=r,t[64]=D.lookup,t[65]=D.ordered,t[66]=l,t[67]=m,t[68]=_,t[69]=d,t[70]=i,t[71]=p,t[72]=k,t[73]=n.activityPresentationKind,t[74]=n.completionDisposition,t[75]=n.durationMs,t[76]=n.hasConfirmedFinalBody,t[77]=n.hasReasoning,t[78]=n.hasTools,t[79]=n.headerMessageId,t[80]=n.turnId,t[81]=n.userMessage,t[82]=ne,t[83]=H,t[84]=F,t[85]=N[0]?.info.id,t[86]=N.length,t[87]=re):re=t[87];let ie=xj(re),ae;bb4:{if(N===n.assistantMessages){ae=n;break bb4}let e;t[88]!==n||t[89]!==N?(e={...n,assistantMessages:N},t[88]=n,t[89]=N,t[90]=e):e=t[90],ae=e}let oe=ae,se;bb5:{if(!lN({isLastTurn:r,sessionIsWorking:i,hasAssistantMessages:n.assistantMessages.length>0,activityPresentationKind:n.activityPresentationKind,hasActiveStreamingMessage:!!h})){se=null;break bb5}let e;t[91]===n.userMessage.info?e=t[92]:(e=cN(sN(n.userMessage.info)),t[91]=n.userMessage.info,t[92]=e),se=e}let ce=se,le=H.length>0,ue=n.assistantMessages.length>0,de;t[93]!==c||t[94]!==r||t[95]!==i||t[96]!==le||t[97]!==ue||t[98]!==n.activityPresentationKind||t[99]!==n.completionDisposition?(de=gP({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:le,hasAssistantMessages:ue,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[93]=c,t[94]=r,t[95]=i,t[96]=le,t[97]=ue,t[98]=n.activityPresentationKind,t[99]=n.completionDisposition,t[100]=de):de=t[100];let fe;return t[101]!==T||t[102]!==C||t[103]!==ce||t[104]!==ie||t[105]!==oe||t[106]!==v||t[107]!==de?(fe=(0,$.jsx)(gA,{turn:oe,activityExpanded:C,onToggleActivity:T,showCompactionStatus:de,pendingAssistantHeader:ce,stickyUserHeader:v,renderMessage:ie}),t[101]=T,t[102]=C,t[103]=ce,t[104]=ie,t[105]=oe,t[106]=v,t[107]=de,t[108]=fe):fe=t[108],fe});vP.displayName=`TurnBlock`;var yP=Z.memo(e=>{let t=(0,Q.c)(31),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d,reviewTransferDirection:f}=e,{t:p}=ct();if(Fr(n)){let e;t[0]===p?e=t[1]:(e=p(`assistants.conversation.newSessionDivider`),t[0]=p,t[1]=e);let n;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[2]=n):n=t[2];let r;t[3]===p?r=t[4]:(r=p(`assistants.conversation.newSessionDivider`),t[3]=p,t[4]=r);let i;t[5]===r?i=t[6]:(i=(0,$.jsx)(`span`,{className:`shrink-0 typography-meta text-muted-foreground`,children:r}),t[5]=r,t[6]=i);let a;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`div`,{className:`min-w-0 flex-1 border-t`}),t[7]=a):a=t[7];let o;t[8]===i?o=t[9]:(o=(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[n,i,a]}),t[8]=i,t[9]=o);let s;return t[10]!==e||t[11]!==o?(s=(0,$.jsx)(`div`,{className:`chat-message-column px-4 py-5`,role:`separator`,"aria-label":e,children:o}),t[10]=e,t[11]=o,t[12]=s):s=t[12],s}let m;t[13]!==n||t[14]!==c?(m=c(n),t[13]=n,t[14]=c,t[15]=m):m=t[15];let h;t[16]!==o||t[17]!==n.info.id?(h=o(n.info.id),t[16]=o,t[17]=n.info.id,t[18]=h):h=t[18];let g=!!u&&n.info.id===u,_=n.info.id===u?d:null,v;return t[19]!==n||t[20]!==i||t[21]!==a||t[22]!==l||t[23]!==r||t[24]!==f||t[25]!==s||t[26]!==m||t[27]!==h||t[28]!==g||t[29]!==_?(v=(0,$.jsx)(_P,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:m,onUserAnimationConsumed:l,onContentChange:a,animationHandlers:h,scrollToBottom:s,isInActiveTurn:g,activeStreamingPhase:_,reviewTransferDirection:f}),t[19]=n,t[20]=i,t[21]=a,t[22]=l,t[23]=r,t[24]=f,t[25]=s,t[26]=m,t[27]=h,t[28]=g,t[29]=_,t[30]=v):v=t[30],v});yP.displayName=`UngroupedMessageRow`;var bP=Z.memo(e=>{let t=(0,Q.c)(24),{entry:n,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,showLiveStatusRow:_}=e,v=_!==void 0&&_,y;t[0]!==m||t[1]!==h||t[2]!==c||t[3]!==d||t[4]!==n.isLastTurn||t[5]!==n.kind||t[6]!==n.message||t[7]!==n.nextMessage||t[8]!==n.previousMessage||t[9]!==n.turn||t[10]!==i||t[11]!==r||t[12]!==u||t[13]!==p||t[14]!==g||t[15]!==a||t[16]!==s||t[17]!==f||t[18]!==o||t[19]!==l?(y=n.kind===`ungrouped`?(0,$.jsx)(yP,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}):(0,$.jsx)(vP,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o}),t[0]=m,t[1]=h,t[2]=c,t[3]=d,t[4]=n.isLastTurn,t[5]=n.kind,t[6]=n.message,t[7]=n.nextMessage,t[8]=n.previousMessage,t[9]=n.turn,t[10]=i,t[11]=r,t[12]=u,t[13]=p,t[14]=g,t[15]=a,t[16]=s,t[17]=f,t[18]=o,t[19]=l,t[20]=y):y=t[20];let b=y;if(!v)return b;let x;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(oA,{})}),t[21]=x):x=t[21];let S;return t[22]===b?S=t[23]:(S=(0,$.jsxs)($.Fragment,{children:[b,x]}),t[22]=b,t[23]=S),S});bP.displayName=`MessageListEntry`;var xP=Z.memo(({entries:e,engine:t,contentRef:n,scrollRef:r,registerTanstackVirtualizer:i,virtualizerKey:a,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g})=>{let _=t===`tanstack`,v=Z.useRef(t),y=Z.useRef(null),[b,x]=Z.useReducer(e=>e+1,0);if(t===`none`)y.current=null;else if(v.current===`none`&&_&&y.current===null){let e=n.current,t=r?.current;e&&t&&(y.current=uP(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&cn();Z.useEffect(()=>{if(!T)return;let e=r?.current;if(!e)return;let t=()=>{S.current=!0},n=()=>{S.current=!1},i=()=>{C.current=performance.now()};return e.addEventListener(`touchstart`,t,{passive:!0}),e.addEventListener(`touchend`,n,{passive:!0}),e.addEventListener(`touchcancel`,n,{passive:!0}),e.addEventListener(`scroll`,i,{passive:!0}),()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),e.removeEventListener(`scroll`,i)}},[T,r]);let E=()=>S.current||performance.now()-C.current<IN,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*RN},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&BN(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<LN)?w.current===null&&(w.current=performance.now()):(w.current=null,k(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);tt(()=>{if(w.current===null)return;let e=performance.now()-w.current>=LN;(!E()||D()||e)&&j()},T?zN:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=ON(),[F,I]=Z.useState(()=>wj(P));Z.useEffect(()=>{if(!(!_||F>=P))return vc(()=>{Z.startTransition(()=>{I(e=>Tj(e,P))})})},[F,_,P]);let L=GN(a,u),[R]=Z.useState(()=>_?eP(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=WN(u),V=Z.useRef(B),H=Z.useRef(u);H.current!==u&&(H.current=u,V.current=B);let U=Z.useRef(_),W=Z.useRef(new Map),ee=Z.useRef(void 0);Z.useLayoutEffect(()=>{if(_)return;let e=n?.current;if(!e)return;let t=W.current;t.clear(),e.querySelectorAll(`[data-turn-entry]`).forEach(e=>{let n=e.dataset.turnEntry;n&&t.set(n,e.getBoundingClientRect().height)}),ee.current=void 0}),_&&ee.current===void 0&&(ee.current=R??HN(N,W.current,V.current));let G=Qc({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{JN(z.current,n.getTotalSize()),Zc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:FN,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:ee.current});at(()=>{if(_)return Zj(G)},[_,G]);let K=Z.useRef(null),te=Z.useRef(null);_||(K.current=null);let ne=J(()=>{if(!_)return;let e=z.current??r?.current;if(!e)return;let t=e.offsetWidth;if(!KN(K.current,t)){K.current===null&&t>0&&(K.current=t);return}K.current=t,te.current!==null&&clearTimeout(te.current),te.current=setTimeout(()=>{te.current=null,G.measure()},220)}),re=_&&typeof ResizeObserver<`u`;st(re?z:null,ne),st(re&&r?r:null,ne),nt(()=>{te.current!==null&&(clearTimeout(te.current),te.current=null)}),at(()=>{_&&ne()},[_]),at(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=cP(n,e.messageId);if(i){let t=i.getBoundingClientRect().top-n.getBoundingClientRect().top-e.offsetTop;Math.abs(t)>.5&&(n.scrollTop+=t),y.current=null;return}let a=N.indexOf(e.entryKey);if(a<0||e.attempts>=1){y.current=null;return}e.attempts+=1,G.scrollToIndex(a,{align:`start`}),x()},[t,N,_,G,b]);let ie=G.getVirtualItems(),ae=ie.map(e=>e.index),[oe,se]=Z.useState(()=>Nj(N,{seedCount:YN(u),restore:jj(L)})),ce=Pj(oe,N);ce!==oe&&se(ce);let le=Z.useRef(ce);le.current=ce;let ue=Z.useRef(null);G.scrollDirection&&(ue.current=G.scrollDirection);let de=G.range?.startIndex??ie[0]?.index??Math.max(0,A.length-1),fe=G.range?.endIndex??ie[ie.length-1]?.index??Math.max(0,A.length-1),pe=G.isScrolling,me=Math.max(0,fe-de+1),he=Ij({entryKeys:N,mountedIndexes:ae,visibleStartIndex:de,visibleEndIndex:fe,scrollDirection:ue.current,preloadEntries:YN(u,me),hydratedKeys:ce,allowVisibleRelease:!pe,preloadReleaseLimit:pe?XN(u):CN,visibleReleaseLimit:pe?0:ZN(u)}),ge=he.join(`\0`),_e=Z.useRef(he);_e.current=he,Z.useEffect(()=>{if(!(!_||!ge))return vc(()=>{Z.startTransition(()=>{se(e=>{let t=null;for(let n of _e.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,ge]),Z.useEffect(()=>{se(e=>Lj(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=G.itemSizeCache,t=QN(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(PN,Math.max(NN,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(G),()=>{tP(L,M.current.map(e=>e.key),G),Mj(L,le.current),i?.(null)}},[_,G,L]);let ve=xj((e,t=!0)=>(0,$.jsx)(Dj,{enabled:t,children:(0,$.jsx)(bP,{entry:e,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,sessionIsWorking:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g},e.key)}));if(t===`none`)return(0,$.jsx)(`div`,{ref:n,className:`relative w-full`,children:A.map(e=>(0,$.jsx)(`div`,{"data-turn-entry":e.key,className:`oc-chat-message-layout-boundary`,children:ve(e)},e.key))});if(t===`tanstack`){let e=qN(ie[0]?.start??0,ie[ie.length-1]?.end??0,G.getTotalSize());return(0,$.jsx)(`div`,{ref:z,className:`relative w-full`,style:{minHeight:e.minHeight},children:(0,$.jsx)(`div`,{style:{paddingTop:e.paddingTop,paddingBottom:e.paddingBottom},children:ie.map(e=>{let t=A[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:G.measureElement,"data-turn-entry":t.key,className:`oc-chat-message-layout-boundary`,children:ve(t,ce.has(t.key))},t.key):null})})})}return null});xP.displayName=`StaticHistoryList`;var SP=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(`div`,{className:`oc-chat-message-layout-boundary`,children:(0,$.jsx)(bP,{...e})}),t[0]=e,t[1]=n),n});SP.displayName=`TailEntry`;var CP=e=>{let t=(0,Q.c)(43),{entries:n,directory:r,sessionId:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,showTurnChangedFiles:m,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:_,activeStreamingPhase:v,reviewTransferDirection:y}=e,b=n.length-1,x=ki(_??``,r,i??void 0),S;bb0:{let e=n[b];if(!e){S=void 0;break bb0}let r=p===`sorted`,i;t[0]!==_||t[1]!==x||t[2]!==e||t[3]!==m||t[4]!==r?(i=bj(e,{activeStreamingMessageId:_,liveParts:x,showTextJustificationActivity:r,showTurnChangedFiles:m}),t[0]=_,t[1]=x,t[2]=e,t[3]=m,t[4]=r,t[5]=i):i=t[5],S=i}let C=S,w;if(t[6]!==_||t[7]!==v||t[8]!==u||t[9]!==p||t[10]!==n||t[11]!==o||t[12]!==C||t[13]!==b||t[14]!==a||t[15]!==f||t[16]!==g||t[17]!==y||t[18]!==s||t[19]!==l||t[20]!==h||t[21]!==c||t[22]!==d){let e;t[24]!==_||t[25]!==v||t[26]!==u||t[27]!==p||t[28]!==o||t[29]!==C||t[30]!==b||t[31]!==a||t[32]!==f||t[33]!==g||t[34]!==y||t[35]!==s||t[36]!==l||t[37]!==h||t[38]!==c||t[39]!==d?(e=(e,t)=>{let n=t===b;return(0,$.jsx)(SP,{entry:n?C??e:e,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,stickyUserHeader:c,sessionIsWorking:n?l:!1,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:h,onUserAnimationConsumed:g,activeStreamingMessageId:n?_:null,activeStreamingPhase:n?v:null,reviewTransferDirection:y},e.key)},t[24]=_,t[25]=v,t[26]=u,t[27]=p,t[28]=o,t[29]=C,t[30]=b,t[31]=a,t[32]=f,t[33]=g,t[34]=y,t[35]=s,t[36]=l,t[37]=h,t[38]=c,t[39]=d,t[40]=e):e=t[40],w=n.map(e),t[6]=_,t[7]=v,t[8]=u,t[9]=p,t[10]=n,t[11]=o,t[12]=C,t[13]=b,t[14]=a,t[15]=f,t[16]=g,t[17]=y,t[18]=s,t[19]=l,t[20]=h,t[21]=c,t[22]=d,t[23]=w}else w=t[23];let T;return t[41]===w?T=t[42]:(T=(0,$.jsx)($.Fragment,{children:w}),t[41]=w,t[42]=T),T};CP.displayName=`StreamingTailContent`;var wP=e=>{let t=(0,Q.c)(73),{historyEntries:n,tailEntries:r,timelineCacheKey:i,directory:a,sessionId:o,scrollRef:s,registerList:c,onHistoryContentChange:l,onTailContentChange:u,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,showTurnChangedFiles:y,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w,header:T,footer:E,scrollClassName:D,scrollStyle:O,scrollDataset:k,onScroll:A,followEnabled:j,historyAnchorToken:M,pinRevealGeneration:N,onIsAtEndChange:P,anchoredUserMessageId:F,onAnchoredTurnParkReleased:I}=e,L=j===void 0||j,R=N===void 0?0:N,z=F===void 0?null:F,B=q(kP),V=n.length,H=r.length>0?r[r.length-1]:void 0,U=H?.key??null,W=ki(S??``,a,o??void 0),ee;bb0:{if(!H){ee=r;break bb0}let e=v===`sorted`,n;t[0]!==S||t[1]!==W||t[2]!==H||t[3]!==y||t[4]!==e?(n=bj(H,{activeStreamingMessageId:S,liveParts:W,showTextJustificationActivity:e,showTurnChangedFiles:y}),t[0]=S,t[1]=W,t[2]=H,t[3]=y,t[4]=e,t[5]=n):n=t[5];let i=n;if(i===H){ee=r;break bb0}let a;t[6]!==i||t[7]!==r?(a=r.slice(),a[a.length-1]=i,t[6]=i,t[7]=r,t[8]=a):a=t[8],ee=a}let G=ee,K;t[9]!==n||t[10]!==G?(K=G.length>0?[...n,...G]:n,t[9]=n,t[10]=G,t[11]=K):K=t[11];let te=K,ne;t[12]!==te||t[13]!==z?(ne=jM(te,z,hP,{anchorOffset:16}),t[12]=te,t[13]=z,t[14]=ne):ne=t[14];let re=ne,ie;t[15]===h?ie=t[16]:(ie={resolvePreloadEntries:e=>YN(h,e),resolvePreloadReleaseWhileScrolling:()=>XN(h),resolveVisibleReleaseLimit:()=>ZN(h)},t[15]=h,t[16]=ie);let ae=ie,oe;t[17]!==S||t[18]!==C||t[19]!==h||t[20]!==v||t[21]!==V||t[22]!==U||t[23]!==w||t[24]!==m||t[25]!==y||t[26]!==p||t[27]!==g?(oe={historyCount:V,newestTailKey:U,sessionIsWorking:m,activityRenderMode:h,turnUiStates:g,chatRenderMode:v,showTurnChangedFiles:y,stickyUserHeader:p,activeStreamingMessageId:S,activeStreamingPhase:C,reviewTransferDirection:w},t[17]=S,t[18]=C,t[19]=h,t[20]=v,t[21]=V,t[22]=U,t[23]=w,t[24]=m,t[25]=y,t[26]=p,t[27]=g,t[28]=oe):oe=t[28];let se=oe,ce;t[29]!==S||t[30]!==C||t[31]!==h||t[32]!==v||t[33]!==d||t[34]!==V||t[35]!==U||t[36]!==l||t[37]!==u||t[38]!==_||t[39]!==x||t[40]!==w||t[41]!==f||t[42]!==m||t[43]!==b||t[44]!==p||t[45]!==g?(ce=(e,t,n)=>{let r=t>=V,i=U!==null&&e.key===U;return(0,$.jsx)(Cc,{disabled:!r,children:(0,$.jsx)(Dj,{enabled:n,children:(0,$.jsx)(bP,{entry:e,onMessageContentChange:r?u:l,getAnimationHandlers:d,scrollToBottom:f,stickyUserHeader:p,sessionIsWorking:i?m:!1,activityRenderMode:h,turnUiStates:g,onToggleTurnGroup:_,chatRenderMode:v,shouldAnimateUserMessage:b,onUserAnimationConsumed:x,activeStreamingMessageId:i?S:null,activeStreamingPhase:i?C:null,reviewTransferDirection:w,showLiveStatusRow:i})})})},t[29]=S,t[30]=C,t[31]=h,t[32]=v,t[33]=d,t[34]=V,t[35]=U,t[36]=l,t[37]=u,t[38]=_,t[39]=x,t[40]=w,t[41]=f,t[42]=m,t[43]=b,t[44]=p,t[45]=g,t[46]=ce):ce=t[46];let le=xj(ce),ue;t[47]===h?ue=t[48]:(ue=WN(h),t[47]=h,t[48]=ue);let de=B&&p,fe;return t[49]!==te||t[50]!==re||t[51]!==L||t[52]!==E||t[53]!==T||t[54]!==M||t[55]!==ae||t[56]!==B||t[57]!==I||t[58]!==P||t[59]!==A||t[60]!==R||t[61]!==c||t[62]!==le||t[63]!==se||t[64]!==D||t[65]!==k||t[66]!==s||t[67]!==O||t[68]!==m||t[69]!==ue||t[70]!==de||t[71]!==i?(fe=(0,$.jsx)(Ej,{enabled:!0,children:(0,$.jsx)(YM,{entries:te,timelineCacheKey:i,estimatedItemSize:ue,hydrationTuning:ae,renderEntry:le,rowInvalidationKey:se,scrollElementRef:s,registerList:c,followEnabled:L,historyAnchorToken:M,pinRevealGeneration:R,anchoredEndSpace:re,onAnchoredTurnParkReleased:I,sessionIsWorking:m,header:T,footer:E,className:D,style:O,scrollElementDataset:k,hideTopScrollShadow:de,hideBottomScrollShadow:B,onScroll:A,onIsAtEndChange:P})}),t[49]=te,t[50]=re,t[51]=L,t[52]=E,t[53]=T,t[54]=M,t[55]=ae,t[56]=B,t[57]=I,t[58]=P,t[59]=A,t[60]=R,t[61]=c,t[62]=le,t[63]=se,t[64]=D,t[65]=k,t[66]=s,t[67]=O,t[68]=m,t[69]=ue,t[70]=de,t[71]=i,t[72]=fe):fe=t[72],fe};wP.displayName=`LegendTimelineHost`;var TP=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:s,getAnimationHandlers:c,scrollToBottom:l,scrollRef:u,directory:d,headerSlot:f,footerSlot:p,timelineScrollClassName:m,timelineScrollStyle:h,timelineScrollDataset:g,timelineOnScroll:_,timelineFollowEnabled:v,timelineHistoryAnchorToken:y,timelineOnIsAtEndChange:b,enableSendPark:x=!0},S)=>{Fe(`ui.message_list.render`);let{sessionKey:C,virtualizerKey:w}=UN(e,t),T=q(e=>e.stickyUserHeader),E=q(e=>e.chatRenderMode),D=q(e=>e.activityRenderMode),O=q(e=>e.showTurnChangedFiles),k=Mr(e=>e.reviewTransferBySessionId.get(C)??null),[A,j]=Z.useState(()=>new Map),M=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),[N,P]=Z.useState(null),F=Z.useRef(null);F.current=N;let I=J(t=>{nn(e),F.current===t&&P(null)});at(()=>{if(x)return()=>{queueMicrotask(()=>{nn(e)})}},[x,e]);let L=J(c),R=J(()=>{l?.()}),z=J((e,t)=>{j(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:ck(i)}),r})}),B=Z.useMemo(()=>be(`ui.message_list.base_display_ms`,()=>{let e=new Set,t=new Map,r=[];for(let e of n){let n=e.info?.id;typeof n==`string`&&t.set(n,e)}for(let i=0;i<n.length;i+=1){let a=n[i],o=a.info?.id;if(typeof o==`string`){if(e.has(o))continue;e.add(o)}r.push(Vk(typeof o==`string`?t.get(o)??a:a))}let i=[],a=new Set;for(let e=0;e<r.length;e+=1){let t=r[e],n=rP(t,a);Lk(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(iP(o)){let e=fP(n);if(e.hide){i[i.length-1]=pP(o,e.taskSessionId);continue}}if(QM(o)){let e=$M(n,aP(o));if(e.hide){i[i.length-1]=mP(o,e.details);continue}}i.push(n)}return i}),[n]),V=Z.useRef(null),H=Z.useRef(null),U=Z.useCallback(()=>{let e=H.current;e&&(H.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{U()},[U]);let W=J(()=>u?.current?u.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),ee=Z.useMemo(()=>be(`ui.message_list.retry_overlay_ms`,()=>vj(B,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[B,o]),G=r||!!i,K=Z.useRef(G),te=Z.useRef(C);te.current!==C&&(te.current=C,K.current=!1),G&&(K.current=!0);let{projection:ne,staticTurns:re,streamingTurns:ie}=gj(ee,{sessionKey:C,showTextJustificationActivity:E===`sorted`,showTurnChangedFiles:O,hasLiveTail:G||K.current,liveTailActive:G}),ae=ne.ungroupedMessageIds.size>0,oe=ae?ee:fN,se=ae?ne.ungroupedMessageIds:pN,ce=Z.useMemo(()=>be(`ui.message_list.render_entries_ms`,()=>{let e=re.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===ne.lastTurnId}));if(se.size===0)return e;let t=new Map;e.forEach(e=>{t.set(e.turn.userMessage.info.id,e)});let n=[];return oe.forEach((e,r)=>{let i=t.get(e.info.id);if(i){n.push(i);return}se.has(e.info.id)&&n.push({kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:r>0?oe[r-1]:void 0,nextMessage:r<oe.length-1?oe[r+1]:void 0})}),n}),[ne.lastTurnId,oe,se,re]),le=Z.useMemo(()=>{if(ie.length>0)return ie.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===ne.lastTurnId}));if(ne.ungroupedMessageIds.size===0)return mN;let e=ee[ee.length-1];return!e||!ne.ungroupedMessageIds.has(e.info.id)?mN:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:ee.length>1?ee[ee.length-2]:void 0,nextMessage:void 0}]},[ee,ne.lastTurnId,ne.ungroupedMessageIds,ie]),ue=le.length>0;ue&&G&&Fe(`ui.message_list.render.streaming`);let de=ce,fe=de.length>=dN,pe=Z.useRef(fe);$N(pe,fe);let me=fe?`tanstack`:`none`,he=Bs(e=>e.legendTimelineEnabled),ge=Z.useRef(null),_e=J(e=>{ge.current=e}),ve=Z.useRef(null),ye=J(e=>{ve.current=e}),xe=Z.useMemo(()=>le.length>0?[...de,...le]:de,[de,le]),[Se,Ce]=Z.useState(0),[we,Te]=Z.useState(null),Ee=GN(w,D),De=Kj(void 0,Qj({scopeKey:Ee,generation:Se,root:we,relevantKeys:Z.useMemo(()=>Vj({entryKeys:xe.map(e=>e.key),seedCount:YN(D)}),[Ee,Se,xe.length,xe[xe.length-1]?.key,D]),enabled:!he&&xe.length>0})),Oe=J(e=>{s(e)}),ke=J(e=>{s(e)}),Ae=Z.useMemo(()=>n.filter(e=>nP(e)===`user`).map(e=>e.info.id),[n]),je=M.current,Me=je.sessionKey!==e,Ne=je.previousOrder;Me&&(x&&je.sessionKey!==void 0&&nn(je.sessionKey),je.sessionKey=e,je.previousOrder=Ae,je.animatedIds=new Set);let Pe=x?On({sessionId:e,sessionChanged:Me,previousUserOrder:Ne,currentUserOrder:Ae,animatedIds:je.animatedIds}):null;je.previousOrder=Ae;let Ie=x?MM({sessionChanged:Me,previousUserOrder:Ne,currentUserOrder:Ae,currentAnchorId:N,consumedSendMessageId:Pe}):null;x&&Ie!==N&&P(Ie),x&&(F.current=Ie);let Le=J(e=>nP(e)===`user`&&M.current.animatedIds.has(e.info.id)),Re=J(e=>{M.current.animatedIds.delete(e)}),ze=Z.useMemo(()=>{let e=new Map;return xe.forEach((t,n)=>{if(t.kind===`ungrouped`){e.set(t.message.info.id,n);return}e.set(t.turn.userMessage.info.id,n),t.turn.assistantMessages.forEach(t=>{e.set(t.info.id,n)})}),e},[xe]),Be=Z.useMemo(()=>{let e=new Map;return xe.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[xe]),Ve=J(e=>{let t=W();return t?t.querySelector(`[data-message-id="${e}"]`):null}),He=J((e,t=`auto`)=>{if(e<0||e>=de.length)return!1;if(he){let n=ge.current;return n?(n.scrollToIndex({index:e,animated:t===`smooth`,viewOffset:0}),!0):!1}if(!fe)return!1;let n=ve.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),Ue=J((e,t=`auto`)=>{let n=W();if(!n)return!1;let r=Ve(e);if(!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect().top-i.top+n.scrollTop-50;return n.scrollTo({top:a,behavior:t}),!0});return Z.useEffect(()=>{if(!S)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Be.get(e);if(r===void 0)return!1;let i=W();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):ue&&r>=de.length?!1:He(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=ze.get(e);return r===void 0?!1:Ue(e,n)||(ue&&r>=de.length?!1:He(r,n))},holdViewportAnchor:e=>{let t=W();if(!t||typeof window>`u`)return;U();let n=0,r=0,i=!1,a=null,o=()=>{t.removeEventListener(`touchstart`,c),t.removeEventListener(`wheel`,c),t.removeEventListener(`keydown`,c),t.removeEventListener(`pointerdown`,c)},s=()=>{i||(i=!0,a!==null&&(window.cancelAnimationFrame(a),a=null),o(),H.current?.cancel===s&&(H.current=null))},c=()=>{s()};H.current={cancel:s},t.addEventListener(`touchstart`,c,{passive:!0}),t.addEventListener(`wheel`,c,{passive:!0}),t.addEventListener(`keydown`,c),t.addEventListener(`pointerdown`,c,{passive:!0});let l=()=>{if(i)return;let o=Ve(e.messageId);if(o){let n=o.getBoundingClientRect().top-t.getBoundingClientRect().top-e.offsetTop;Math.abs(n)>.5?(t.scrollTop+=n,r=0):r+=1}if(n+=1,r>=kN||n>=AN){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:U,isHistoryVirtualized:()=>he?!0:pe.current,captureViewportAnchor:()=>{let e=W();if(!e)return null;let t=e.getBoundingClientRect(),n=Array.from(e.querySelectorAll(`[data-message-id]`)),r=n.find(n=>n.getBoundingClientRect().bottom<=t.top+1?!1:typeof window>`u`||!sP(n,e,t.top))??n.find(e=>e.getBoundingClientRect().bottom>t.top+1);if(!r)return null;let i=r.dataset.messageId;return i?{messageId:i,offsetTop:r.getBoundingClientRect().top-t.top}:null},restoreViewportAnchor:e=>{let t=W();if(!t||!ze.has(e.messageId))return!1;let n=()=>{let n=Ve(e.messageId);if(!n)return!1;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect().top-r.top-e.offsetTop;return i!==0&&(t.scrollTop+=i),!0};if(!n()){let t=ze.get(e.messageId);if(typeof t==`number`&&t<de.length)return He(t,`auto`)}return n()},scrollToBottom:()=>{if(Ce(e=>e+1),he){let e=gM(W());if(e!==null){ge.current?.scrollToOffset({offset:e,animated:!1});return}ge.current?.scrollToEnd({animated:!1});return}if(fe&&de.length>0&&ve.current){ve.current.scrollToEnd();return}let e=W();e&&(e.scrollTop=e.scrollHeight)}};if(typeof S==`function`)return S(e),()=>{S(null)};let t=S;return t.current=e,()=>{t.current=null}},[U,de.length,he,ze,fe,ue,Be,S]),he?(0,$.jsx)(wP,{historyEntries:de,tailEntries:le,timelineCacheKey:GN(w,D),directory:d,sessionId:C,scrollRef:u,registerList:_e,onHistoryContentChange:Oe,onTailContentChange:ke,getAnimationHandlers:L,scrollToBottom:R,stickyUserHeader:T,sessionIsWorking:r,activityRenderMode:D,turnUiStates:A,onToggleTurnGroup:z,chatRenderMode:E,showTurnChangedFiles:O,shouldAnimateUserMessage:Le,onUserAnimationConsumed:Re,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:k,header:f,footer:p,scrollClassName:m,scrollStyle:h,scrollDataset:g,onScroll:_,followEnabled:v,historyAnchorToken:y,pinRevealGeneration:Se,onIsAtEndChange:b,anchoredUserMessageId:Ie,onAnchoredTurnParkReleased:I},w):(0,$.jsx)(`div`,{children:(0,$.jsx)(Cc,{disabled:!1,children:(0,$.jsxs)(`div`,{ref:Te,className:`relative w-full`,style:De,children:[(0,$.jsx)(Cc,{disabled:fe,children:(0,$.jsx)(Ej,{enabled:!0,children:(0,$.jsx)(xP,{entries:de,engine:me,contentRef:V,scrollRef:u,registerTanstackVirtualizer:ye,virtualizerKey:w,onMessageContentChange:Oe,getAnimationHandlers:L,scrollToBottom:R,stickyUserHeader:T,activityRenderMode:D,turnUiStates:A,onToggleTurnGroup:z,chatRenderMode:E,shouldAnimateUserMessage:Le,onUserAnimationConsumed:Re,reviewTransferDirection:k},w)})}),(0,$.jsx)(CP,{entries:le,directory:d,sessionId:C,onMessageContentChange:ke,getAnimationHandlers:L,scrollToBottom:R,stickyUserHeader:T,sessionIsWorking:r,activityRenderMode:D,turnUiStates:A,onToggleTurnGroup:z,chatRenderMode:E,showTurnChangedFiles:O,shouldAnimateUserMessage:Le,onUserAnimationConsumed:Re,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:k})]})})})});TP.displayName=`MessageList`;var EP=Z.memo(TP);function DP(e){return e.info.id}function OP(e){return e!==null}function kP(e){return e.isMobile}var AP=e=>{let t=(0,Q.c)(3),{content:n,html:r}=e,i;return t[0]!==n||t[1]!==r?(i=r===void 0?(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,children:n}):(0,$.jsx)(`span`,{className:`whitespace-pre-wrap break-all`,dangerouslySetInnerHTML:{__html:r}}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},jP=({diff:e,filePath:t})=>{let{currentTheme:n}=Ga(),r=Z.useMemo(()=>To(n),[n]),i=Z.useMemo(()=>Pc(e),[e]),a=fc(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6580
|
+
`),[i]),s=Wc(o,a),c=0;return(0,$.jsx)(`div`,{className:`typography-code px-1 pb-1 pt-0 space-y-0`,style:r,children:i.map((e,n)=>(0,$.jsxs)(`div`,{className:`-mx-1 px-1 border-b border-border/20 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`bg-muted/20 px-2 py-1 typography-meta font-medium text-muted-foreground border-b border-border/10 break-words -mx-1`,children:`${e.file||t?.split(`/`).pop()||`file`} (line ${e.oldStart})`}),(0,$.jsx)(`div`,{children:e.lines.map((e,t)=>{let n=s?.[c];return c+=1,(0,$.jsxs)(`div`,{className:Y(`typography-code font-mono px-2 py-0.5 flex -mx-2`,e.type===`context`&&`bg-transparent`,e.type===`removed`&&`bg-transparent`,e.type===`added`&&`bg-transparent`),style:e.type===`removed`?{backgroundColor:`var(--tools-edit-removed-bg)`}:e.type===`added`?{backgroundColor:`var(--tools-edit-added-bg)`}:{},children:[(0,$.jsx)(`span`,{className:`w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5`,style:{color:`var(--tools-edit-line-number)`,borderColor:`var(--tools-border)`},children:e.lineNumber||``}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(AP,{content:e.content,html:n})})]},t)})})]},n))})},MP=e=>{let t=(0,Q.c)(21),{content:n,filePath:r}=e,{currentTheme:i}=Ga(),a;t[0]===i?a=t[1]:(a=To(i),t[0]=i,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=n.split(`
|
|
6581
|
+
`),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=fc(r??``)||`text`,t[4]=r,t[5]=l);let u=l,d;t[6]===r?d=t[7]:(d=r?.split(`/`).pop()||`New file`,t[6]=r,t[7]=d);let f=d,p=Math.max(c.length,1),m=p===1?`line 1`:`lines 1-${p}`,h=Wc(n,u),g=o,_=`${f} (${m})`,v;t[8]===_?v=t[9]:(v=(0,$.jsx)(`div`,{className:`bg-muted/20 px-2 py-1 typography-meta font-medium text-muted-foreground border border-border/10 rounded-lg mb-1`,children:_}),t[8]=_,t[9]=v);let y;if(t[10]!==h||t[11]!==c){let e;t[13]===h?e=t[14]:(e=(e,t)=>(0,$.jsxs)(`div`,{className:`typography-code font-mono px-2 py-0.5 flex -mx-1`,children:[(0,$.jsx)(`span`,{className:`w-10 flex-shrink-0 text-right pr-3 select-none border-r mr-3 -my-0.5 py-0.5`,style:{color:`var(--tools-edit-line-number)`,borderColor:`var(--tools-border)`},children:t+1}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(AP,{content:e||` `,html:h?.[t]})})]},t),t[13]=h,t[14]=e),y=c.map(e),t[10]=h,t[11]=c,t[12]=y}else y=t[12];let b;t[15]===y?b=t[16]:(b=(0,$.jsx)(`div`,{className:`space-y-0`,children:y}),t[15]=y,t[16]=b);let x;return t[17]!==g||t[18]!==v||t[19]!==b?(x=(0,$.jsxs)(`div`,{className:`w-full min-w-0`,style:g,children:[v,b]}),t[17]=g,t[18]=v,t[19]=b,t[20]=x):x=t[20],x},NP=new Set([`id`,`identifier`,`title`,`name`]),PP=e=>typeof e==`object`&&!!e&&!Array.isArray(e),FP=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),IP=e=>{let t=typeof e.id==`string`?e.id:typeof e.identifier==`string`?e.identifier:``,n=typeof e.title==`string`?e.title:typeof e.name==`string`?e.name:``;return t&&n?`${t} · ${n}`:n||t||null},LP=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},RP=Z.memo(e=>{let t=(0,Q.c)(54),{value:n,label:r,depth:i}=e;if(Array.isArray(n)){let e;t[0]!==r||t[1]!==n.length?(e=r?`${FP(r)} (${n.length})`:`(${n.length})`,t[0]=r,t[1]=n.length,t[2]=e):e=t[2];let a=e,o=i<2,s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5 shrink-0 transition-transform group-open/json-summary:rotate-90`}),t[3]=s):s=t[3];let c;t[4]===a?c=t[5]:(c=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 py-1.5 typography-meta text-[var(--surface-foreground)] hover:text-[var(--surface-mutedForeground)]`,children:[s,(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:a})]}),t[4]=a,t[5]=c);let l;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-1 left-0 top-0 w-px bg-[var(--tools-border)] opacity-40`}),t[6]=l):l=t[6];let u;if(t[7]!==i||t[8]!==n){let e;t[10]===i?e=t[11]:(e=(e,t)=>(0,$.jsx)(RP,{value:e,depth:i+1},t),t[10]=i,t[11]=e),u=n.map(e),t[7]=i,t[8]=n,t[9]=u}else u=t[9];let d;t[12]===u?d=t[13]:(d=(0,$.jsxs)(`div`,{className:`relative ml-1 pl-3 pb-1`,children:[l,(0,$.jsx)(`div`,{className:`space-y-1`,children:u})]}),t[12]=u,t[13]=d);let f;return t[14]!==o||t[15]!==c||t[16]!==d?(f=(0,$.jsxs)(`details`,{open:o,className:`group/json-summary`,children:[c,d]}),t[14]=o,t[15]=c,t[16]=d,t[17]=f):f=t[17],f}if(PP(n)){let e;t[18]===n?e=t[19]:(e=IP(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(BP),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${FP(r)}${a?` · ${a}`:``}`:a,t[22]=a,t[23]=r,t[24]=c):c=t[24];let l=c,u;t[25]!==i||t[26]!==s?(u=(0,$.jsx)(`div`,{className:`space-y-1`,children:s.map(e=>{let[t,n]=e;return(0,$.jsx)(RP,{label:t,value:n,depth:i+1},t)})}),t[25]=i,t[26]=s,t[27]=u):u=t[27];let d=u;if(!r&&i===0){let e;t[28]===a?e=t[29]:(e=a?(0,$.jsx)(`div`,{className:`typography-meta font-medium text-[var(--surface-foreground)]`,children:a}):null,t[28]=a,t[29]=e);let n;return t[30]!==d||t[31]!==e?(n=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[e,d]}),t[30]=d,t[31]=e,t[32]=n):n=t[32],n}let f=i<2,p;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5 shrink-0 transition-transform group-open/json-summary:rotate-90`}),t[33]=p):p=t[33];let m;t[34]!==r||t[35]!==l?(m=l??(r?FP(r):`{}`),t[34]=r,t[35]=l,t[36]=m):m=t[36];let h;t[37]===m?h=t[38]:(h=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 py-1.5 typography-meta text-[var(--surface-foreground)] hover:text-[var(--surface-mutedForeground)]`,children:[p,(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:m})]}),t[37]=m,t[38]=h);let g;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-1 left-0 top-0 w-px bg-[var(--tools-border)] opacity-40`}),t[39]=g):g=t[39];let _;t[40]===d?_=t[41]:(_=(0,$.jsxs)(`div`,{className:`relative ml-1 pl-3 pb-1`,children:[g,d]}),t[40]=d,t[41]=_);let v;return t[42]!==_||t[43]!==f||t[44]!==h?(v=(0,$.jsxs)(`details`,{open:f,className:`group/json-summary`,children:[h,_]}),t[42]=_,t[43]=f,t[44]=h,t[45]=v):v=t[45],v}let a=n===null?`null`:typeof n==`boolean`?n?`true`:`false`:String(n),o;t[46]!==a||t[47]!==n?(o=typeof n==`string`&&LP(n)?(0,$.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`truncate text-[var(--status-info)] underline underline-offset-2 hover:opacity-80`,title:n,children:n}):(0,$.jsx)(`span`,{className:Y(`min-w-0 break-words`,n===null?`text-[var(--surface-mutedForeground)]`:`text-[var(--surface-foreground)]`),children:a}),t[46]=a,t[47]=n,t[48]=o):o=t[48];let s=o,c;t[49]===r?c=t[50]:(c=r?(0,$.jsx)(`span`,{className:`truncate text-[var(--surface-mutedForeground)]`,title:r,children:FP(r)}):(0,$.jsx)(`span`,{}),t[49]=r,t[50]=c);let l;return t[51]!==s||t[52]!==c?(l=(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(6rem,auto)_minmax(0,1fr)] gap-x-2 py-1 typography-meta`,children:[c,s]}),t[51]=s,t[52]=c,t[53]=l):l=t[53],l});RP.displayName=`JsonSummaryValue`;var zP=Z.memo(e=>{let t=(0,Q.c)(2),{data:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`space-y-1`,children:(0,$.jsx)(RP,{value:n,depth:0})}),t[0]=n,t[1]=r),r});zP.displayName=`JsonSummaryView`;function BP(e){let[t]=e;return!NP.has(t)}var VP={margin:0,padding:`0.5rem`,fontSize:`var(--text-meta)`,lineHeight:`1.25rem`,background:`rgb(var(--muted) / 0.3)`,borderRadius:`0.25rem`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`,overflow:`visible`},HP={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},UP=e=>{let t=`h-3 w-3`,n=e.toLowerCase();return n===`edit`||n===`multiedit`||n===`str_replace`||n===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil-ai`,className:t}):n===`write`||n===`create`||n===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:t}):n===`bash`||n===`shell`||n===`cmd`||n===`terminal`||n===`shell_command`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):n===`webfetch`||n===`fetch`||n===`curl`||n===`wget`?(0,$.jsx)(X,{name:`global`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},WP=e=>{let t=e.toLowerCase();return t===`edit`||t===`multiedit`||t===`str_replace`||t===`str_replace_based_edit_tool`?`edit`:t===`write`||t===`create`||t===`file_write`?`write`:t===`bash`||t===`shell`||t===`cmd`||t===`terminal`||t===`shell_command`?`bash`:t===`webfetch`||t===`fetch`||t===`curl`||t===`wget`?`webfetch`:e},GP=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,KP=e=>{let t=(0,Q.c)(2),{data:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`rounded-lg border border-border/20 bg-muted/15 px-2 py-1 sm:px-2.5 sm:py-1.5 [&_.typography-meta]:!text-xs [&_summary]:py-1`,children:(0,$.jsx)(zP,{data:n})}),t[0]=n,t[1]=r),r},qP=({permission:e,onResponse:t})=>{let{t:n}=ct(),[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Gn,c=zr(),l=ri(e=>e.currentSessionId),u=Z.useMemo(()=>{if(!l||e.sessionID===l)return!1;let t=c.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===l)},[e.sessionID,l,c]),d=async n=>{i(!0);try{await s(e.sessionID,e.id,n),o(!0),t?.(n)}catch(e){console.error(`[PermissionCard] Failed to respond to permission:`,e)}finally{i(!1)}};if(a)return null;let f=e.permission||`unknown`,p=f.toLowerCase(),m=(t,n=``)=>{let r=e.metadata[t];return typeof r==`string`?r:typeof r==`number`?String(r):n},h=t=>{let n=e.metadata[t];return typeof n==`number`?n:void 0},g=t=>!!e.metadata[t],_=WP(f),v=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[GP(e),t]));return(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{className:`-mt-1 overflow-hidden border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2.5 py-2 sm:px-2 sm:py-1.5 border-b border-border/20 bg-muted/5`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 sm:gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-[var(--status-warning)]`}),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] font-medium text-muted-foreground`,children:n(`sessions.sidebar.session.status.permissionRequired`)}),u?(0,$.jsx)(`span`,{className:`hidden sm:inline typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:n(`chat.questionCard.fromSubagent`)}):null]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[48%] items-center gap-1.5`,children:[UP(f),(0,$.jsx)(`span`,{className:`truncate text-xs leading-4 sm:text-[length:var(--text-meta)] text-muted-foreground font-medium`,children:_})]})]})}),(0,$.jsxs)(`div`,{className:`px-2.5 py-2 sm:px-2 [&_.typography-meta]:!text-xs [&_.typography-micro]:!text-[0.6875rem]`,children:[e.patterns.length>0&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:n(`chat.permissionCard.patterns`)}),(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border/20 bg-muted/15`,children:e.patterns.map((e,t)=>(0,$.jsx)(`code`,{className:Y(`block break-all px-2 py-1.5 text-xs leading-4 sm:text-[length:var(--text-meta)]`,t>0&&`border-t border-border/15`),children:e},`${e}-${t}`))})]}),(()=>{if(p===`bash`||p===`shell`||p===`shell_command`){let e=m(`command`)||m(`cmd`)||m(`script`),t=m(`description`),r=m(`cwd`)||m(`working_directory`)||m(`directory`)||m(`path`),i=h(`timeout`);return(0,$.jsxs)($.Fragment,{children:[t&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:t}),r&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.workingDirectory`)}),` `,(0,$.jsx)(`code`,{className:`px-1 py-0.5 bg-muted/30 rounded`,children:r})]}),i&&(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:n(`chat.permissionCard.timeout`)}),` `,i,`ms`]}),e&&(0,$.jsx)(`div`,{children:(0,$.jsx)(Fc,{language:`bash`,code:e,style:VP,codeStyle:HP.style,wrap:!0})})]})}if(p===`edit`||p===`multiedit`||p===`str_replace`||p===`str_replace_based_edit_tool`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`changes`)||m(`diff`),r=g(`replace_all`)||g(`replaceAll`);return(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-2`,children:(0,$.jsxs)(`span`,{className:`font-semibold`,children:[`⚠️ `,n(`chat.permissionCard.replaceAll`)]})}),t&&(0,$.jsx)(pa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(jP,{diff:t,filePath:e})})]})}if(p===`write`||p===`create`||p===`file_write`){let e=m(`path`)||m(`file_path`)||m(`filename`)||m(`filePath`),t=m(`content`)||m(`text`)||m(`data`);return t?(0,$.jsx)(pa,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(MP,{content:t,filePath:e})}):null}if(p===`webfetch`||p===`fetch`||p===`curl`||p===`wget`){let t=m(`url`)||m(`uri`)||m(`endpoint`),r=m(`method`)||`GET`,i=e.metadata.headers&&typeof e.metadata.headers==`object`?e.metadata.headers:void 0,a=e.metadata.body??e.metadata.data??e.metadata.payload,o=h(`timeout`),s=m(`format`)||m(`responseType`);return(0,$.jsxs)($.Fragment,{children:[t&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.request`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-semibold px-1.5 py-0.5 bg-primary/20 text-primary rounded`,children:r}),(0,$.jsx)(`code`,{className:`typography-meta px-2 py-1 bg-muted/30 rounded flex-1 break-all`,children:t})]})]}),i&&Object.keys(i).length>0&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.headers`)}),(0,$.jsx)(pa,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(KP,{data:i})})]}),a&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mb-1`,children:n(`chat.permissionCard.body`)}),(0,$.jsx)(pa,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(KP,{data:a}):(0,$.jsx)(`pre`,{className:`typography-meta font-mono px-2 py-1.5 bg-muted/20 border border-border/20 rounded-lg whitespace-pre-wrap break-all`,children:String(a)})})]}),(o||s)&&(0,$.jsxs)(`div`,{className:`typography-micro text-muted-foreground`,children:[o&&(0,$.jsxs)(`span`,{children:[n(`chat.permissionCard.timeout`),` `,o,`ms`]}),o&&s&&(0,$.jsx)(`span`,{children:` • `}),s&&(0,$.jsxs)(`span`,{children:[n(`chat.permissionCard.responseFormat`),` `,s]})]})]})}return Object.keys(v).length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1`,children:n(`chat.permissionCard.details`)}),(0,$.jsx)(pa,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(KP,{data:v})})]})})()]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-1 border-t border-border/20 px-1.5 py-1.5 sm:flex sm:items-center sm:flex-wrap sm:px-2 sm:py-1`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`once`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,children:[(0,$.jsx)(X,{name:`check`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.allowOnce`)})]}),(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`always`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-foreground sm:h-6 sm:w-auto sm:px-2`,children:[(0,$.jsx)(X,{name:`arrow-right`,className:`size-3.5 shrink-0 text-[var(--status-success)] sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionCard.alwaysAgree`)})]}),(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>d(`reject`),disabled:r,className:`h-8 min-w-0 w-full gap-1 px-1 !text-xs leading-4 text-[var(--status-error)] sm:h-6 sm:w-auto sm:px-2`,children:[(0,$.jsx)(X,{name:`close`,className:`size-3.5 shrink-0 sm:size-3`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`chat.permissionToast.actions.deny`)})]}),r&&(0,$.jsx)(`div`,{className:`col-span-3 flex justify-center w-full sm:w-auto sm:ml-auto py-1 sm:py-0 typography-meta text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})})]})]})})})};function JP(e){let t=[];return(e.questions??[]).forEach((e,n)=>{let r=e.header?.trim(),i=r&&r.length>0?r:`Question ${n+1}`;t.push(`## ${i}`),t.push(``),t.push(e.question),t.push(``),e.multiple&&(t.push(`_Select all that apply._`),t.push(``)),e.options.forEach(e=>{let n=e.label,r=e.description?.trim();t.push(r?`- **${n}** — ${r}`:`- **${n}**`)}),t.push(``)}),t.join(`
|
|
6582
|
+
`).trimEnd()}function YP(e){let t={questions:(e.questions??[]).map(e=>({header:e.header??null,question:e.question,multiple:!!e.multiple,options:e.options.map(e=>({label:e.label,description:e.description??null}))}))};return JSON.stringify(t,null,2)}var XP=200;function ZP(e){return Math.min(Math.max(e,40),XP)}var QP=`summary`,$P=Z.memo(function(e){let t=(0,Q.c)(27),{value:n,placeholder:r,disabled:i,onValueChange:a,onKeyDown:o}=e,s=Z.useRef(null),[c,l]=Z.useState(n),[u,d]=Z.useState(40),[f,p]=Z.useState(!1),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current;if(!e||document.activeElement!==e)return;let t=e.closest(`.chat-scroll`);if(!t){e.scrollIntoView({block:`nearest`});return}let n=window.visualViewport,r=t.getBoundingClientRect(),i=n?.offsetTop??0,a=n?n.offsetTop+n.height:document.documentElement.clientHeight,o=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--oc-kb-scroll-inset`))||0,c=Math.max(r.top,i),l=Math.min(r.bottom,a-o),u=Math.max(0,l-c),d=e.closest(`[data-question-card]`),f=d?.getBoundingClientRect(),p=(d&&f&&f.height<=u?d:e).getBoundingClientRect();p.bottom>l-12?t.scrollTop+=p.bottom-l+12:p.top<c+12&&(t.scrollTop+=p.top-c-12)},t[0]=m):m=t[0];let h=J(m),g;t[1]===h?g=t[2]:(g=()=>{requestAnimationFrame(h)},t[1]=h,t[2]=g);let _=J(g),v;t[3]===h?v=t[4]:(v=()=>{let e=()=>requestAnimationFrame(h);return e(),window.addEventListener(`oc:keyboard-settled`,e),window.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`oc:keyboard-settled`,e),window.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`scroll`,e)}},t[3]=h,t[4]=v);let y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(y=[],t[5]=y):y=t[5],Z.useEffect(v,y);let b,x;t[6]===n?(b=t[7],x=t[8]):(b=()=>{l(n)},x=[n],t[6]=n,t[7]=b,t[8]=x),Z.useEffect(b,x);let S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>{let e=s.current;if(!e)return;e.style.height=`auto`,e.style.overflowY=`hidden`;let t=e.scrollHeight,n=ZP(t),r=t>n;e.style.height=`${n}px`,e.style.overflowY=``,d(e=>e===n?e:n),p(e=>e===r?e:r)},t[9]=S):S=t[9];let C;t[10]===c?C=t[11]:(C=[c],t[10]=c,t[11]=C),Z.useLayoutEffect(S,C);let w;t[12]===a?w=t[13]:(w=e=>{let t=e.target.value;l(t),a(t)},t[12]=a,t[13]=w);let T;t[14]===u?T=t[15]:(T={height:u},t[14]=u,t[15]=T);let E=f?`overflow-y-auto`:`overflow-hidden`,D;t[16]===E?D=t[17]:(D=Y(`w-full bg-transparent border border-border/30 focus:border-primary rounded px-2 py-1 outline-none typography-meta text-foreground placeholder:text-muted-foreground/50 transition-colors resize-none`,E),t[16]=E,t[17]=D);let O;return t[18]!==i||t[19]!==_||t[20]!==c||t[21]!==o||t[22]!==r||t[23]!==T||t[24]!==D||t[25]!==w?(O=(0,$.jsx)(`textarea`,{ref:s,value:c,onChange:w,placeholder:r,disabled:i,rows:2,onKeyDown:o,onFocus:_,style:T,className:D,autoFocus:!0}),t[18]=i,t[19]=_,t[20]=c,t[21]=o,t[22]=r,t[23]=T,t[24]=D,t[25]=w,t[26]=O):O=t[26],O}),eF=({question:e})=>{let{t}=ct(),n=Gt,r=$i,i=q(e=>e.isMobile),a=zr(),o=ri(e=>e.currentSessionId),s=Z.useMemo(()=>{if(!o||e.sessionID===o)return!1;let t=a.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===o)},[e.sessionID,o,a]),[c,l]=Z.useState(`0`),[u,d]=Z.useState(!1),[f,p]=Z.useState(!1),[m,h]=Z.useState({}),[g,_]=Z.useState({}),v=Z.useRef({}),[y,b]=Z.useState({}),x=Z.useMemo(()=>e.questions??[],[e.questions]),S=c===QP,C=S?-1:Math.max(0,Math.min(x.length-1,Number(c)||0)),w=S?null:x[C],T=Z.useMemo(()=>{if(S)return null;let e=w?.header?.trim();return e&&e.length>0?e:null},[w?.header,S]);Z.useEffect(()=>{l(`0`),h({}),_({}),v.current={},b({}),p(!1)},[e.id]);let E=Z.useMemo(()=>{let e=x.map((e,t)=>({value:String(t),label:e.header?.trim()||`Q${t+1}`}));return x.length>1&&e.push({value:QP,label:t(`chat.questionCard.summaryTab`)}),e},[x,t]),D=Z.useCallback(e=>{if(g[e])return(v.current[e]??``).trim()||t(`chat.questionCard.noAnswer`);let n=m[e]??[];return n.length>0?n.join(`, `):t(`chat.questionCard.noAnswer`)},[g,m,t]),O=!!w?.multiple,k=m[C]??[],A=!!g[C],j=Z.useMemo(()=>{let e=[];for(let t=0;t<x.length;t+=1){if(g[t]){y[t]||e.push(t);continue}(m[t]??[]).length===0&&e.push(t)}return e},[g,y,x.length,m]),M=Z.useMemo(()=>x.length!==0&&j.length===0,[x.length,j.length]),N=Z.useCallback(()=>{if(x.length===0||j.length===0)return;let e=S?-1:C;for(let t=1;t<=x.length;t+=1){let n=(e+t+x.length)%x.length;if(j.includes(n)){l(String(n));return}}l(String(j[0]))},[C,S,x.length,j]),P=Z.useCallback(()=>{let e=[];for(let t=0;t<x.length;t+=1){if(g[t]){let n=(v.current[t]??``).trim();e.push(n?[n]:[]);continue}e.push(m[t]??[])}return e},[g,x.length,m]),F=Z.useCallback(e=>{w&&(_(e=>({...e,[C]:!1})),b(e=>e[C]?{...e,[C]:!1}:e),h(t=>{let n=t[C]??[];if(O){let r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,[C]:r}}return{...t,[C]:[e]}}))},[C,w,O]),I=Z.useCallback(()=>{_(e=>({...e,[C]:!0})),h(e=>({...e,[C]:[]}));let e=(v.current[C]??``).trim().length>0;b(t=>t[C]===e?t:{...t,[C]:e})},[C]),L=Z.useCallback(e=>{v.current[C]=e;let t=e.trim().length>0;b(e=>e[C]===t?e:{...e,[C]:t})},[C]),R=Z.useCallback(async()=>{if(M){d(!0);try{let t=P();await n(e.sessionID,e.id,t),p(!0)}catch(e){An(e)?(Br.info(t(`chat.questionCard.noLongerPending`)),p(!0)):Br.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{d(!1)}}},[P,e.id,e.sessionID,M,n,t]),z=Z.useCallback(e=>{Ig(e)||e.key===`Enter`&&!e.shiftKey&&(!i||e.ctrlKey||e.metaKey)&&(e.preventDefault(),M?R():N())},[R,N,i,M]),B=Z.useCallback(async()=>{d(!0);try{await r(e.sessionID,e.id),p(!0)}catch(e){An(e)?(Br.info(t(`chat.questionCard.noLongerPending`)),p(!0)):Br.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{d(!1)}},[e.id,e.sessionID,r,t]),V=Z.useCallback(async()=>{let n=JP(e);if((await ut(n)).ok){Br.success(t(`chat.questionCard.copiedMarkdown`));return}Br.error(t(`chat.questionCard.copyFailed`))},[e,t]),H=Z.useCallback(async()=>{let n=YP(e);if((await ut(n)).ok){Br.success(t(`chat.questionCard.copiedJson`));return}Br.error(t(`chat.questionCard.copyFailed`))},[e,t]);return f||x.length===0?null:(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{"data-question-card":!0,className:`-mt-1 border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1.5 border-b border-border/20`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:t(`chat.questionCard.inputNeeded`)}),s?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:t(`chat.questionCard.fromSubagent`)}):null,T?(0,$.jsx)(`span`,{className:`ml-auto typography-micro font-medium text-foreground/70 px-1.5 py-0.5 rounded bg-muted/30 border border-border/20`,children:T}):null,(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-0.5`,T?null:`ml-auto`),children:[(0,$.jsx)(`button`,{type:`button`,onClick:V,title:t(`chat.questionCard.copyMarkdown`),"aria-label":t(`chat.questionCard.copyMarkdown`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`file-text`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:H,title:t(`chat.questionCard.copyJson`),"aria-label":t(`chat.questionCard.copyJson`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`code-box`,className:`h-3 w-3`})})]})]})}),(0,$.jsxs)(`div`,{className:`px-2 py-2`,children:[E.length>1?(0,$.jsx)(`div`,{className:`flex items-center gap-1 mb-2 flex-wrap`,children:E.map(e=>{let t=c===e.value,n=e.value===QP,r=n?-1:Number(e.value),i=!n&&Number.isFinite(r)&&!j.includes(r);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(e.value),className:Y(`px-2 py-0.5 typography-meta font-medium rounded transition-colors flex items-center gap-1`,t?`bg-interactive-selection/40 text-foreground`:n?`text-muted-foreground hover:text-foreground hover:bg-interactive-hover/20`:i?`text-muted-foreground/60 hover:text-muted-foreground hover:bg-interactive-hover/20`:`text-foreground/85 hover:text-foreground hover:bg-interactive-hover/20`),children:[n?(0,$.jsx)(X,{name:`list-check-3`,className:`h-3 w-3`}):null,e.label]},e.value)})}):null,S?(0,$.jsx)(`div`,{className:`space-y-2`,children:x.map((e,n)=>{let r=D(n),i=r!==t(`chat.questionCard.noAnswer`);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(String(n)),className:`w-full text-left rounded px-1.5 py-1 hover:bg-interactive-hover/20 transition-colors`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.header||t(`chat.questionCard.questionFallback`,{index:n+1})}),(0,$.jsx)(`div`,{className:Y(`typography-meta`,i?`text-foreground`:`text-muted-foreground/50 italic`),children:r})]},n)})}):w?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground mb-1.5`,children:w.question}),O?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1.5`,children:t(`chat.questionCard.selectMultiple`)}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[w.options.map((e,n)=>{let r=k.includes(e.label),i=/\(recommended\)/i.test(e.label);return(0,$.jsx)(`button`,{type:`button`,onClick:()=>F(e.label),disabled:u,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,r?`bg-interactive-selection/20`:null,u?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:O?(0,$.jsx)(Da,{checked:r,onChange:()=>F(e.label),disabled:u}):(0,$.jsx)(lo,{checked:r,onChange:()=>F(e.label),disabled:u})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:Y(`typography-meta break-all`,r?`text-foreground font-medium`:`text-foreground/80`),children:e.label}),i?(0,$.jsx)(`span`,{className:`typography-micro text-primary/80`,children:t(`chat.questionCard.recommended`)}):null]}),e.description?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground break-words`,children:e.description}):null]})]})},`${n}:${e.label}`)}),(0,$.jsx)(`button`,{type:`button`,onClick:I,disabled:u,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,A?`bg-interactive-selection/20`:null,u?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`edit`,className:Y(`h-3.5 w-3.5`,A?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,A?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),A?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)($P,{value:v.current[C]??``,onValueChange:L,placeholder:t(`chat.questionCard.yourAnswer`),disabled:u,onKeyDown:z})}):null]})]}):null]}),(0,$.jsxs)(`div`,{className:`px-2 pb-1.5 pt-1 flex items-center gap-1.5 border-t border-border/20`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:M?R:N,disabled:u,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-success)/0.1)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[M?(0,$.jsx)(X,{name:`check`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`}),t(M?`chat.questionCard.submit`:`chat.questionCard.next`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:B,disabled:u,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-error)/0.1)] text-[var(--status-error)] hover:bg-[rgb(var(--status-error)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`}),t(`chat.questionCard.dismiss`)]}),u?(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})}):null]})]})})})};function tF(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
6583
|
+
`)}function nF(e,t=80){let n=tF(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var rF=160,iF=28,aF=12,oF=6,sF=30,cF=12,lF=18,uF=80,dF=4,fF=10,pF=14,mF=20,hF=54,gF=4,_F=8,vF=2,yF=160,bF=(e,t)=>e.map(e=>({turnId:e,preview:nF(t.get(e)??[],rF)})),xF=[1,.6,.35,.15],SF=(e,t,n)=>{let r=n?pF:fF;if(t===null)return r;let i=xF[Math.abs(e-t)]??0;return Math.round(r+(mF-r)*i)};function CF({turnIds:e,previewsByTurnId:t,activeTurnId:n,onSelectTurn:r,canLoadEarlier:i,isLoadingOlder:a,onLoadEarlier:o}){let{t:s}=ct(),c=q(e=>e.isPromptNavigatorPanelOpen),l=q(e=>e.setPromptNavigatorPanelOpen),u=Z.useRef(null),d=Z.useRef(null),[f,p]=Z.useState(null),[m,h]=Z.useState(0),[g,_]=Z.useState(!1);Z.useEffect(()=>{let e=d.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){_(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.right-oF-iF;_(r.right>i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let v=Z.useMemo(()=>bF(e,t),[t,e]),y=Math.min(v.length,sF),b=Math.max(0,v.length-y),x=Math.min(m,b),S=x+y,C=x>0,w=S<v.length,T=s(`chat.timeline.noTextContent`),E=s(`chat.promptNavigator.currentPrompt`),D=s(`chat.promptNavigator.loadMore`),O=Z.useMemo(()=>n?v.findIndex(e=>e.turnId===n):-1,[n,v]),k=Z.useRef(x);k.current=x;let A=Z.useRef(v.length);A.current=v.length;let j=Z.useRef(null),M=Z.useRef(null),N=Z.useRef(0),P=Z.useCallback(e=>{h(t=>{let n=A.current,r=Math.min(n,sF),i=Math.max(0,n-r),a=Math.min(t,i);return e<a?e:e>=a+r?Math.min(i,e-r+1):a})},[]),F=Z.useRef(v[0]?.turnId),I=Z.useRef(v.length);Z.useLayoutEffect(()=>{let e=F.current,t=I.current,n=v.length-t;n>0&&t>0&&e&&v[0]?.turnId!==e&&(h(e=>e+n),p(e=>e===null?null:e+n)),F.current=v[0]?.turnId,I.current=v.length},[v]),Z.useEffect(()=>{if(f!==null)return;let e=O>=0?O:v.length-1;h(()=>{let t=A.current,n=Math.min(t,sF),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[O,f,v.length]);let L=Z.useCallback(e=>{let t=u.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/cF),i=Math.min(A.current,sF);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),R=Z.useCallback(()=>{N.current=0,M.current!==null&&(window.clearInterval(M.current),M.current=null)},[]),z=Z.useCallback(()=>{let e=N.current;if(e===0){R();return}let t=A.current,n=Math.max(0,t-Math.min(t,sF)),r=Math.min(k.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){R();return}k.current=i,h(i);let a=j.current;if(a!==null){let e=L(a);e!==null&&p(Math.min(t-1,i+e))}},[L,R]),B=Z.useCallback(e=>{let t=u.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=lF&&C?i=-1:r>=n.height-lF&&w&&(i=1),N.current=i,i===0){R();return}M.current===null&&(M.current=window.setInterval(z,uF))},[z,C,w,R]);Z.useEffect(()=>()=>{M.current!==null&&window.clearInterval(M.current)},[]);let V=Z.useRef(null),H=Z.useCallback(()=>{V.current!==null&&(window.clearTimeout(V.current),V.current=null)},[]),U=Z.useCallback(()=>{H(),V.current=window.setTimeout(()=>{V.current=null,p(null)},yF)},[H]);Z.useEffect(()=>()=>{V.current!==null&&window.clearTimeout(V.current)},[]);let W=Z.useCallback(e=>{H(),j.current=e.clientY;let t=L(e.clientY);t!==null&&p(Math.min(A.current-1,k.current+t)),B(e.clientY)},[H,L,B]),ee=Z.useCallback(()=>{j.current=null,R(),U()},[U,R]),G=Z.useCallback(()=>{l(!1)},[l]),K=Z.useCallback(e=>{if(e===null)return;let t=v[e];t&&(r(t.turnId),R(),p(null),G(),u.current?.blur())},[G,r,v,R]),te=Z.useCallback(e=>{let t=L(e.clientY);t!==null&&K(Math.min(v.length-1,k.current+t))},[K,v.length,L]);Z.useEffect(()=>{if(!c)return;let e=u.current;!e||e===document.activeElement||(e.focus(),p(e=>{if(e!==null)return e;let t=O>=0?O:v.length-1;return P(t),t}))},[O,P,c,v.length]),Z.useEffect(()=>()=>{l(!1)},[l]);let ne=Z.useCallback(e=>{if(v.length===0)return;let t=f??(O>=0?O:v.length-1),n=e=>{let t=Math.max(0,Math.min(v.length-1,e));P(t),p(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(v.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),K(t);return}e.key===`Escape`&&(e.preventDefault(),p(null),G(),u.current?.blur())},[O,G,P,K,f,v.length]),re=Z.useCallback(()=>{R(),p(null),G()},[G,R]),ie=Z.useRef(null),ae=Z.useRef(f);ae.current=f;let oe=f!==null,se=Z.useRef(0);Z.useEffect(()=>{let e=ie.current;if(!e)return;let t=e=>{e.preventDefault(),e.stopPropagation(),se.current+=e.deltaY;let t=Math.trunc(se.current/hF);if(t===0)return;se.current-=t*hF;let n=ae.current;if(n===null)return;let r=Math.max(0,Math.min(A.current-1,n+t));r!==n&&(P(r),p(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[P,oe]);let ce=f===null?void 0:v[f],le=Math.min(v.length,_F),ue=le*hF,de=v.length*hF-ue,fe=e=>Math.max(0,Math.min(de,e)),pe=Z.useRef(null),me=0;if(f===null)pe.current=null;else if(pe.current===null)me=fe(f*hF-(ue-hF)/2),pe.current=me;else{let e=pe.current,t=(f-vF)*hF,n=(f+1+vF)*hF-ue;e>t?e=t:e<n&&(e=n),me=fe(e),pe.current=me}let he=Math.floor(me/hF),ge=Math.max(0,he-dF),_e=Math.min(v.length,he+le+dF),ve=me>0,ye=me<de,be=ve||ye?`linear-gradient(to bottom, ${ve?`transparent, black 10%`:`black`}, ${ye?`black 90%, transparent`:`black`})`:void 0,xe=Math.max(0,x-dF),Se=Math.min(v.length,S+dF),Ce=v.slice(xe,Se),we=C||w?`linear-gradient(to bottom, ${C?`transparent, black 14%`:`black`}, ${w?`black 86%, transparent`:`black`})`:void 0;return v.length===0?null:(0,$.jsx)(`nav`,{ref:d,"aria-label":s(`chat.promptNavigator.aria`),className:`pointer-events-none absolute right-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-end`,children:[i?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-mr-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,a?`cursor-wait opacity-70`:void 0),"aria-label":D,title:D,disabled:a,onClick:e=>{e.stopPropagation(),a||o()},children:a?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:u,role:`listbox`,tabIndex:-1,"aria-activedescendant":ce?`prompt-rail-tick-${ce.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${g?aF:iF}px`,height:`${y*cF}px`},onMouseMove:W,onMouseLeave:ee,onClick:te,onKeyDown:ne,onBlur:re,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 overflow-hidden`,style:we?{maskImage:we,WebkitMaskImage:we}:void 0,children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-300 ease-out`,style:{transform:`translateY(-${x*cF}px)`},children:Ce.map((e,t)=>{let r=xe+t,i=e.turnId===n,a=f===r,o=SF(r,f,i);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,"aria-label":e.preview.trim()||T,className:`pointer-events-none absolute right-1 flex items-center justify-end`,style:{top:`${r*cF}px`,height:`${cF}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,i?`bg-[var(--surface-foreground)]`:a?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${o}px`}})},e.turnId)})},v[0]?.turnId)}),ce&&f!==null?(0,$.jsx)(`div`,{ref:ie,className:Y(`pointer-events-auto absolute right-full top-1/2 z-30 mr-3 -translate-y-1/2`,`w-[min(20rem,calc(100vw-6rem))] overflow-hidden rounded-xl`,`border border-[var(--interactive-border)]/60 bg-[var(--surface-elevated)] py-1 shadow-md`),onMouseEnter:H,onMouseLeave:U,onMouseMove:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(`div`,{className:`relative overflow-hidden`,style:{height:`${le*hF}px`,maskImage:be,WebkitMaskImage:be},children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-200 ease-out`,style:{height:`${v.length*hF}px`,transform:`translateY(-${me}px)`},children:v.slice(ge,_e).map((e,t)=>{let r=ge+t,i=e.turnId===n,a=f===r;return(0,$.jsx)(`div`,{role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,title:i?E:void 0,className:`absolute inset-x-0 cursor-pointer px-1.5`,style:{top:`${r*hF+gF}px`,height:`46px`},onMouseMove:()=>{H(),ae.current!==r&&(P(r),p(r))},onClick:()=>K(r),children:(0,$.jsx)(`div`,{className:Y(`flex h-full items-center rounded-lg border px-2 transition-colors`,i?`border-transparent bg-[var(--interactive-selection)]`:a?`border-[var(--interactive-border)]/60 bg-[var(--interactive-hover)]`:`border-[var(--interactive-border)]/40`),children:(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 line-clamp-2 [overflow-wrap:anywhere] typography-meta`,i?`text-[var(--interactive-selectionForeground)]`:`text-[var(--surface-mutedForeground)]`),children:e.preview.trim()||T})})},e.turnId)})})})}):null]})]})})}var wF=100,TF=(e,t)=>{if(e.length===0)return;let n=0,r=e.length-1,i=0;for(;n<=r;){let a=n+r>>1,o=e[a]?.top;if(o===void 0)break;if(o<=t){i=a,n=a+1;continue}r=a-1}return e[i]?.id},EF=e=>{let t=e.raf??requestAnimationFrame,n=e.caf??cancelAnimationFrame,r=e.ResizeObserver??globalThis.ResizeObserver,i=e.MutationObserver??globalThis.MutationObserver,a,o,s,c,l,u,d=!0,f=new Map,p=[],m=()=>{c===void 0&&(c=t(()=>{c=void 0,g()}))},h=()=>{let e=a;if(!e){p=[],d=!1;return}let t=e.getBoundingClientRect().top;p=[...f].map(([n,r])=>({id:n,top:r.getBoundingClientRect().top-t+e.scrollTop})),p.sort((e,t)=>e.top-t.top),d=!1},g=()=>{let t=a;if(!t)return;d&&h();let n=TF(p,t.scrollTop+wF);!n||n===u||(u=n,e.onActive(n))},_=()=>{let e=a;if(e){if(clearTimeout(l),l=void 0,o?.disconnect(),o=void 0,r){o=new r(()=>{clearTimeout(l),l=setTimeout(()=>{d=!0,m()},100)}),o.observe(e);for(let e of f.values())o.observe(e)}if(s?.disconnect(),s=void 0,i){s=new i(()=>{d=!0,m()});let t={subtree:!0,childList:!0};r||(t.characterData=!0,t.characterDataOldValue=!1),s.observe(e,t)}d=!0,m()}},v=e=>{a!==e&&(a=e,u=void 0,_())},y=(e,t)=>{let n=f.get(t);n&&n!==e&&o?.unobserve(n),f.set(t,e),o&&o.observe(e),d=!0,m()},b=e=>{let t=f.get(e);t&&(o?.unobserve(t),f.delete(e),d=!0,m())},x=()=>{d=!0,m()},S=()=>{for(let e of f.values())o?.unobserve(e);f.clear(),p=[],u=void 0,d=!0};return{setContainer:v,register:y,unregister:b,onScroll:m,markDirty:x,clear:S,destroy:()=>{c!==void 0&&n(c),c=void 0,clearTimeout(l),l=void 0,S(),o?.disconnect(),s?.disconnect(),o=void 0,s=void 0,a=void 0},getActiveId:()=>u}},DF=10,OF=`${DF}vh`,kF=`80px`,AF=`calc(${kF} + var(--oc-chat-foot-inset))`,jF=(e,t)=>e?80:t<=0?96:Math.max(48,DF/100*t),MF=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return!1;switch(e.key){case`ArrowUp`:case`PageUp`:case`Home`:return!0;default:return!1}},NF=(e,t)=>{let n=t instanceof Element?t:t instanceof Node?t.parentElement:null;for(;n&&n!==e;){if(n instanceof HTMLElement&&n.scrollTop>0&&n.scrollHeight>n.clientHeight+1)return!0;n=n.parentElement}return!1},PF=e=>{let t=(0,Q.c)(15),{scrollRef:n,enabled:r,onUpwardIntent:i}=e,a=r===void 0||r,o=Z.useRef(null),s;t[0]===i?s=t[1]:(s=()=>{i()},t[0]=i,t[1]=s);let c=J(s),l;t[2]!==c||t[3]!==n?(l=e=>{let t=n.current;t&&(e.deltaY>=0||t instanceof HTMLElement&&(NF(t,e.target)||c()))},t[2]=c,t[3]=n,t[4]=l):l=t[4];let u=J(l),d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>{let t=e.touches.item(0);o.current=t?t.clientY:null},t[5]=d):d=t[5];let f=J(d),p;t[6]!==c||t[7]!==n?(p=e=>{let t=n.current,r=e.touches.item(0);if(!r){o.current=null;return}let i=o.current;o.current=r.clientY,i!==null&&(r.clientY-i<=2||!t||!(t instanceof HTMLElement)||NF(t,e.target)||c())},t[6]=c,t[7]=n,t[8]=p):p=t[8];let m=J(p),h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{o.current=null},t[9]=h):h=t[9];let g=J(h),_;t[10]===c?_=t[11]:(_=e=>{MF(e)&&c()},t[10]=c,t[11]=_);let v=J(_),[y,b]=Z.useState(null),x;t[12]===n?x=t[13]:(x=()=>{let e=n.current??null;b(t=>t===e?t:e)},t[12]=n,t[13]=x),Z.useEffect(x);let S=a&&y?y:FF,C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C={passive:!0},t[14]=C):C=t[14];let w=C;ot(`wheel`,u,S,w),ot(`touchstart`,f,S,w),ot(`touchmove`,m,S,w),ot(`touchend`,g,S,w),ot(`touchcancel`,g,S,w),ot(`keydown`,v,S)};function FF(){}var IF=(e,t)=>({sessionId:e,viewportKey:t}),LF=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,RF=(e,t)=>LF(e,t),zF=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),BF=150,VF=1500,HF=2,UF=350,WF=600,GF=8e3,KF=24,qF=2,JF=(e,t)=>e<t,YF=()=>typeof performance<`u`?performance.now():Date.now(),XF=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),ZF=e=>e.scrollHeight-e.scrollTop-e.clientHeight,QF=e=>ZF(XF(e)),$F=e=>e.scrollHeight-e.clientHeight>1,eI=(e,t)=>ZF(e)<=jF(t,e.clientHeight),tI=({enabled:e=!0,currentSessionId:t,viewportKey:n,sessionMessageCount:r,sessionIsWorking:i,isMobile:a,onActiveTurnChange:o,onUpwardUserIntent:s})=>{let c=Z.useRef(null),[l,u]=Z.useState(null),d=Z.useRef(null),[f,p]=Z.useState(`following`),[m,h]=Z.useState(!1),[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),b=Z.useRef(`following`),x=Z.useRef(a);x.current=a;let S=Z.useRef(r);S.current=r;let C=Z.useRef(IF(t,n));C.current=IF(t,n);let w=Z.useRef(null),T=Z.useRef(null),E=Z.useRef(null),D=Z.useRef(0),O=Z.useRef(null),k=Z.useRef(null),A=Z.useRef(0),j=Z.useRef(!1),M=Z.useRef(!1),N=Z.useRef(null),P=Z.useRef(0),F=J(()=>{P.current=YF()+450}),I=Z.useRef(0),L=Z.useRef(!1),R=Z.useRef(null),z=Z.useRef(null),B=Z.useRef(0),V=Z.useRef(!1),H=Z.useRef(null),U=Z.useRef(null),W=Z.useRef(null),ee=Mn(e=>e.updateViewportAnchor);Z.useLayoutEffect(()=>{c.current!==d.current&&(d.current=c.current,u(c.current))});let G=J(e=>{b.current!==e&&(b.current=e,p(e))}),K=J(e=>{T.current={top:Math.max(0,e.scrollHeight-e.clientHeight),time:YF()},E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{T.current=null,E.current=null},VF)}),te=J(e=>{let t=T.current;return t?YF()-t.time>VF?(T.current=null,!1):Math.abs(e.scrollTop-t.top)<HF:!1}),ne=J(()=>YF()<A.current),re=J(()=>{L.current=!1,R.current&&=(clearTimeout(R.current),null),z.current&&=(clearTimeout(z.current),null)}),ie=J(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,re()},WF)}),ae=J(()=>{let e=c.current;e&&(L.current=!0,B.current=e.scrollHeight,ie(),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{z.current=null,re()},GF))}),oe=J(e=>{let t=c.current;if(!t){h(!1),_(!1);return}let n=e??XF(t),r=$F(n);if(h(r),!r){_(!1);return}let i=b.current===`released`&&!eI(n,x.current);_(i)}),se=J(()=>{D.current+=1,O.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(O.current),O.current=null),k.current?.(),k.current=null});Z.useEffect(()=>()=>se(),[l]);let ce=J(()=>{if(!e)return;let t=c.current;if(!t)return;se();let n=D.current,r=t.style.overflow,i=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,t.style.overflow=`hidden`,t.scrollTop=t.scrollHeight,t.scrollHeight,t.style.overflow=r,t.style.scrollBehavior=i;let a=()=>{K(t),t.scrollTop=t.scrollHeight,I.current=t.scrollTop};if(a(),oe(),typeof window>`u`)return;let o=0,s=()=>{JF(YF(),P.current)||se()};t.addEventListener(`touchstart`,s,{passive:!0,once:!0}),k.current=()=>t.removeEventListener(`touchstart`,s);let l=()=>{if(n===D.current){if(QF(t)>qF&&a(),o+=1,o>=KF){O.current=null,k.current?.(),k.current=null,oe();return}O.current=window.requestAnimationFrame(l)}};O.current=window.requestAnimationFrame(l)}),le=J(e=>{let t=c.current;if(t){if(K(t),e===`smooth`){t.scrollTo({top:t.scrollHeight,behavior:e});return}t.scrollTop=t.scrollHeight}}),ue=J((t,n=`auto`)=>{if(!e)return;let r=c.current;if(t&&b.current!==`following`&&G(`following`),r&&!(!t&&b.current!==`following`)){if(QF(r)<HF){K(r);return}le(t?n:`auto`)}}),de=J(e=>{let t=c.current;if(!t)return;let n=e??XF(t);if(!$F(n)){G(`following`);return}b.current!==`released`&&(G(`released`),oe(n))}),fe=J((e=`instant`)=>{if(V.current=!1,G(`following`),re(),e===`instant`){ce();return}se(),ue(!0,`smooth`),oe()}),pe=J(()=>{V.current=!1,ue(!0)}),me=J(()=>{se(),re(),G(`released`),oe()}),he=J(()=>{V.current=!0,me()}),ge=J(()=>{V.current=!1}),_e=Z.useRef(s);_e.current=s;let ve=J(()=>{JF(YF(),P.current)||(se(),re(),de())}),ye=J(()=>{ve(),_e.current?.()}),be=J(()=>{H.current!==null&&(clearTimeout(H.current),H.current=null);let e=U.current;if(e){if(!e.identity.sessionId){U.current=null;return}ee(e.identity.sessionId,e.anchor,e.scrollPosition,e.identity.viewportKey),U.current=null}}),xe=J(()=>{let e=C.current;if(!e.sessionId)return;let t=c.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r>0?(n+i/2)/r:0,o=Math.floor(a*S.current);U.current=zF(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),H.current===null&&(H.current=setTimeout(()=>{H.current=null,be()},BF))}),Se=J(()=>{be()}),Ce=J(async(e=C.current)=>{if(!e.sessionId)return!1;V.current=!1;let t=Wi(e.sessionId,e.viewportKey);return c.current?(W.current=null,I.current=t?.scrollPosition?.scrollTop??0,G(`following`),F(),x.current?ce():ue(!0),ae(),oe(),!1):(W.current=e,G(`following`),!1)});Z.useEffect(()=>{let e=C.current,n=w.current;LF(e,n)||(be(),se(),F(),w.current=e,T.current=null,I.current=0,re(),V.current=!1,G(`following`),W.current=null,t&&t!==n?.sessionId&&Gx.getInstance().recordSessionStart(t))},[t,n]),Z.useEffect(()=>{i&&!V.current&&b.current===`following`&&ue(!0)},[i]),Z.useEffect(()=>{y(f===`following`&&i)},[f,i]),Z.useLayoutEffect(()=>{if(!l)return;let e=W.current;e&&RF(e,C.current)&&Ce(e)},[l,t,n]);let we=J(()=>{let e=c.current;if(!e)return;let t=XF(e),n=I.current;I.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(oe(t),V.current){xe();return}if(!$F(t)){G(`following`);return}if(eI(t,x.current)){let e=ZF(t)<=HF;(r||b.current===`following`||e)&&G(`following`),xe();return}if(b.current===`following`&&(te(e)||ne()||i)){j.current||ue(!1),xe();return}de(t),xe()});Z.useEffect(()=>{!e||!l||(I.current=l.scrollTop)},[l,e]);let Te=Z.useRef(null),Ee=J(e=>{let t=c.current;t&&(e.deltaY>=0||NF(t,e.target)||ye())}),De=J(e=>{let t=e.touches.item(0);Te.current=t?t.clientY:null}),Oe=J(e=>{let t=c.current,n=e.touches.item(0);if(!n){Te.current=null;return}let r=Te.current;Te.current=n.clientY,r!==null&&(n.clientY-r<=2||t&&(NF(t,e.target)||ye()))}),ke=J(()=>{Te.current=null}),Ae=J(e=>{MF(e)&&ye()}),je=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&ve()}),Me=Z.useMemo(()=>()=>void 0,[]),Ne=e&&l?l:Me,Pe=Z.useMemo(()=>({passive:!0}),[]);ot(`scroll`,we,Ne,Pe),ot(`wheel`,Ee,Ne,Pe),ot(`touchstart`,De,Ne,Pe),ot(`touchmove`,Oe,Ne,Pe),ot(`touchend`,ke,Ne,Pe),ot(`touchcancel`,ke,Ne,Pe),ot(`keydown`,Ae,Ne),ot(`pointerdown`,je,e&&typeof window<`u`?window:Me,!0);let Fe=J(()=>{let e=c.current;if(j.current){oe(e?XF(e):void 0);return}if(V.current){oe(e?XF(e):void 0);return}if(!e){oe(void 0);return}let t=XF(e);if(!$F(t)){G(`following`),oe(t);return}if(oe(t),L.current){let n=t.scrollHeight>B.current+1;B.current=t.scrollHeight,ZF(t)<=HF?K(e):ue(!0),n&&ie();return}if(b.current===`following`){if(ZF(t)<=HF){K(e);return}ue(!1)}}),Ie=typeof ResizeObserver<`u`,Le=Ie&&e?l:null,Re=Ie&&e&&l&&l.firstElementChild instanceof Element?l.firstElementChild:null;st(Le,Fe),st(Re,Fe);let ze=J(()=>{N.current!==null&&(clearTimeout(N.current),N.current=null)}),q=J(e=>{j.current=!0,typeof e==`number`&&e>0?A.current=YF()+e+UF:A.current=Math.max(A.current,YF()+UF)}),Be=J(e=>{let t=e.detail;if(t){if(t.open===!0){q(),ze(),N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},1500);return}ze(),q()}}),Ve=J(e=>{let t=e.detail;t&&(ze(),q(t.durationMs))}),He=J(e=>{let t=e.detail;ze(),t?.open===!0?(M.current=!0,j.current=!0):(M.current=!1,j.current=!0,N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},UF)),oe()}),Ue=e&&typeof window<`u`?window:Me;ot(`oc:keyboard-intent`,Be,Ue),ot(`oc:keyboard-anim`,Ve,Ue),ot(`oc:keyboard-settled`,He,Ue),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{ze(),j.current=!1,M.current=!1}},[e]),Z.useEffect(()=>{e&&oe()},[e,r]);let We=J(t=>{if(e){if(t===`animation`&&(A.current=YF()+UF),oe(),L.current){ue(!0),ie();return}b.current===`following`&&ue(!1)}}),Ge=Z.useRef(new Map),Ke=J(t=>{let n=Ge.current.get(t);if(n)return n;let r=()=>{e&&b.current===`following`&&ue(!1)},i={onChunk:r,onComplete:()=>{e&&oe()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return Ge.current.set(t,i),i});Z.useEffect(()=>()=>{E.current&&=(clearTimeout(E.current),null),se(),re(),be(),H.current!==null&&(clearTimeout(H.current),H.current=null)},[]);let qe=J(e=>{o?.(e)}),Je=!!o;return Z.useEffect(()=>{if(!e||!Je)return;let t=l;if(!t)return;let n=null,r=EF({onActive:e=>{e!==n&&(n=e,qe(e))}});r.setContainer(t);let i=new Map,a=e=>{let t=e.dataset.turnId;return t?(i.set(t,e),r.register(e,t),!0):!1},o=e=>{let t=e.dataset.turnId;return!t||i.get(t)!==e?!1:(i.delete(t),r.unregister(t),!0)},s=e=>{if(!(e instanceof HTMLElement))return[];let t=[];return e.matches(`[data-turn-id]`)&&t.push(e),e.querySelectorAll(`[data-turn-id]`).forEach(e=>t.push(e)),t};t.querySelectorAll(`[data-turn-id]`).forEach(a),r.markDirty();let c=new MutationObserver(e=>{let t=!1;e.forEach(e=>{e.removedNodes.forEach(e=>{s(e).forEach(e=>{o(e)&&(t=!0)})}),e.addedNodes.forEach(e=>{s(e).forEach(e=>{a(e)&&(t=!0)})})}),t&&r.markDirty()});c.observe(t,{subtree:!0,childList:!0});let u=()=>r.onScroll();return t.addEventListener(`scroll`,u,{passive:!0}),()=>{t.removeEventListener(`scroll`,u),c.disconnect(),r.destroy()}},[l,e,Je]),{scrollRef:c,state:f,isPinned:f===`following`,isOverflowing:m,isFollowingProgrammatically:v,showScrollButton:g,notifyContentChange:We,getAnimationHandlers:Ke,goToBottom:fe,scrollToBottomOnSend:pe,releaseAutoFollow:me,beginHistoryViewportPreservation:he,endHistoryViewportPreservation:ge,saveSnapshotNow:Se,restoreSnapshot:Ce}},nI=`--oc-mobile-composer-swap`,rI=`--oc-native-composer-dock`,iI=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),aI=(e,t,n)=>Math.min(n,Math.max(t,e)),oI=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,sI=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return oI(e,n)?e:n},cI=(e,t)=>t?sI(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?sI(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,lI=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:sI(e,{phase:`snapping`,rest:t,progress:n})},uI=e=>aI(e/80,0,1),dI=e=>e>=80?1:aI(e/80,0,1),fI=(e,t,n={})=>{if(e.pinned)return e;let r=Math.max(0,t),i=e.phase===`snapping`?sI(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(i.rest===`expanded`){if(r<=2||n.holdExpanded||n.userDriven===!1)return sI(i,{phase:`rest`,rest:`expanded`,progress:0});let e=uI(r);return e>=1?sI(i,{phase:`rest`,rest:`compact`,progress:1}):sI(i,{phase:`tracking`,rest:`expanded`,progress:e})}if(r<=2)return sI(i,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn)return sI(i,{phase:`rest`,rest:`compact`,progress:1});if(n.towardBottom&&r>=80)return sI(i,{phase:`snapping`,rest:`expanded`,progress:0});let a=dI(r);return a>=1?sI(i,{phase:`rest`,rest:`compact`,progress:1}):sI(i,{phase:`tracking`,rest:`compact`,progress:a})},pI=e=>e.pinned?`expanded`:e.rest===`expanded`?e.progress>=.5?`compact`:`expanded`:e.progress<=.5?`expanded`:`compact`,mI=e=>{if(e.pinned)return sI(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let t=pI(e),n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:sI(e,{phase:`snapping`,rest:t,progress:n})},hI=e=>e.phase===`snapping`?sI(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,gI=e=>aI(Math.max(0,e)/80,0,1),_I=(e,t=`away`)=>{let n=Math.max(0,e);return n<=2?{progress:0,rest:`bottom`}:t===`away`||n>=40?{progress:1,rest:`away`}:{progress:gI(n),rest:`bottom`}},vI=e=>{e.style.removeProperty(nI),e.style.removeProperty(rI),delete e.dataset.ocComposerSwapPhase,delete e.dataset.ocComposerSwapRest,delete e.dataset.ocNativeComposerDock},yI=(e,t,n)=>{let r=_I(t,n?.rest===`bottom`?`bottom`:`away`),i=String(r.progress),a=r.rest;return n?.progress!==i&&e.style.setProperty(rI,i),n?.rest!==a&&(e.dataset.ocNativeComposerDock=a),{progress:i,rest:a}},bI=(e,t,n)=>{let r=String(t.progress),i=t.phase,a=t.rest;return n?.phase!==i&&(e.dataset.ocComposerSwapPhase=i,i===`snapping`&&n&&n.phase!==`snapping`&&e.offsetWidth),n?.progress!==r&&e.style.setProperty(nI,r),n?.rest!==a&&(e.dataset.ocComposerSwapRest=a),{progress:r,phase:i,rest:a}},xI=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),SI=()=>{let e=document.documentElement;return e.classList.contains(`oc-keyboard-open`)||e.classList.contains(`oc-kb-animating`)},CI=e=>{if(SI()||e.querySelector(`[data-oc-composer-dictation-active="true"]`))return!0;let t=document.activeElement;return t instanceof HTMLElement&&t.matches(`textarea[data-chat-input="true"]`)&&e.contains(t)},wI=e=>{let t=Z.useRef(iI()),n=Z.useRef(void 0),r=Z.useRef(void 0),i=Z.useRef(null),a=Z.useRef(null),o=Z.useRef(0),s=Z.useRef(!1),c=Z.useRef(0),l=Z.useRef(0),u=Z.useRef(null),d=Z.useRef(0),f=Z.useRef(0),p=Z.useRef(!1),m=Z.useRef(e.enabled);m.current=e.enabled;let h=e=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null)},g=J(t=>{let r=e.scopeRef.current;r&&(n.current=bI(r,t,n.current))}),_=J(e=>{e!==t.current&&(t.current=e,g(e))}),v=J(()=>{if(h(a),t.current.phase!==`snapping`)return;let e=t.current.rest;a.current=window.setTimeout(()=>{a.current=null;let n=hI(t.current);_(n),n.rest===`compact`&&e===`compact`&&(o.current=Date.now()+320,s.current=!0)},240)}),y=J(()=>{let n=e.scopeRef.current;!n||!m.current||_(cI(t.current,CI(n)))}),b=J(e=>s.current?Date.now()>=o.current?(s.current=!1,!1):e>=80?(s.current=!1,o.current=0,!1):!0:!1),x=J(()=>{if(h(i),!m.current||c.current>0||t.current.phase!==`tracking`)return;let e=mI(t.current);_(e),v()}),S=J(()=>{m.current&&(l.current=Date.now())}),C=J(()=>{m.current&&(l.current=Date.now(),c.current+=1,h(i))}),w=J(()=>{if(!m.current)return;let n=e.scrollRef.current,a=e.scopeRef.current;if(!n||!a)return;let o=CI(a),s=xI(n),g=vM(s,gM(n)),y=u.current;if(u.current=g,n.hasAttribute(`data-oc-timeline-anchoring`)){d.current=0,f.current=0;return}r.current=yI(a,g,r.current);let S=c.current>0||Date.now()-l.current<=1200,C=y===null?0:y-g;S?C>0?(f.current=0,s.scrollTop>0&&(d.current+=C)):C<0&&(d.current=0,f.current+=-C,f.current>=24&&(p.current=!1)):(d.current=0,f.current=0),g<=2&&(p.current=!1);let w=cI(t.current,o);if(!o){let e=w.rest===`compact`;w=fI(w,g,{suppressReturn:b(g),towardBottom:d.current>=24,holdExpanded:p.current,userDriven:S}),e&&w.rest===`expanded`&&g>2&&(p.current=!0,d.current=0)}if(_(w),h(i),w.phase===`snapping`){v();return}w.phase===`tracking`&&c.current===0&&(i.current=window.setTimeout(()=>{i.current=null,x()},120))}),T=J(()=>{x()}),E=J(()=>{m.current&&(l.current=Date.now(),c.current=Math.max(0,c.current-1),!(c.current>0)&&t.current.phase===`tracking`&&(h(i),i.current=window.setTimeout(()=>{i.current=null,x()},120)))}),D=J(()=>{let t=e.scopeRef.current;if(!t||typeof window>`u`)return;let n=e=>{e.preventDefault(),e.stopPropagation()};t.addEventListener(`pointerup`,n,!0),t.addEventListener(`click`,n,!0),window.setTimeout(()=>{t.removeEventListener(`pointerup`,n,!0),t.removeEventListener(`click`,n,!0)},240)}),O=J(n=>{if(!m.current)return;let r=n.target;r instanceof Element&&r.closest(`[data-oc-composer-compact-surface="true"]`)&&(r.closest(`[data-composer-action="true"]`)||(`preventDefault`in n&&n.preventDefault(),`stopPropagation`in n&&n.stopPropagation(),p.current=!0,d.current=0,f.current=0,_(lI(t.current,`expanded`)),v(),D(),(e.scopeRef.current?.querySelector(`textarea[data-chat-input="true"]`))?.focus({preventScroll:!0})))}),[k,A]=Z.useState(null),[j,M]=Z.useState(null),N=Z.useRef(null),P=J(e=>{e&&vI(e),n.current=void 0,r.current=void 0,s.current=!1,o.current=0,c.current=0,l.current=0,u.current=null,d.current=0,f.current=0,p.current=!1,_(iI())});Z.useLayoutEffect(()=>{let t=e.enabled?e.scrollRef.current:null,n=e.enabled?e.scopeRef.current:null;N.current&&N.current!==n&&P(N.current),N.current=n,A(e=>e===t?e:t),M(e=>e===n?e:n)});let F=Z.useMemo(()=>()=>void 0,[]),I=e.enabled&&k?k:F,L=e.enabled&&j?j:F,R=e.enabled&&typeof window<`u`?window:F,z=Z.useMemo(()=>({passive:!0}),[]);ot(`scroll`,w,I,z),ot(`scrollend`,T,I,z),ot(`touchstart`,C,I,z),ot(`touchmove`,S,I,z),ot(`touchend`,E,I,z),ot(`touchcancel`,E,I,z),ot(`pointerdown`,O,L),ot(`focusin`,y,L),ot(`focusout`,y,L),ot(`oc:keyboard-intent`,y,R),ot(`oc:keyboard-anim`,y,R),ot(`oc:keyboard-settled`,y,R),Z.useEffect(()=>{if(!e.enabled){P(N.current),N.current=null;return}return y(),w(),()=>{h(i),h(a)}},[e.enabled,k,j])},TI=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},EI=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},DI=e=>{if(!e)return null;let t=TI(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${EI(e)??``}`},OI=e=>({turnIds:[...e.turnIds],turnMessageStartIndexes:[...e.turnMessageStartIndexes],turnIndexById:new Map(e.turnIndexById),messageToTurnId:new Map(e.messageToTurnId),messageToTurnIndex:new Map(e.messageToTurnIndex),turnCount:e.turnCount}),kI=(e,t,n)=>{if(!e||!t)return null;if(t.length===n.length){let r=-1;for(let e=0;e<n.length;e+=1)if(t[e]!==n[e]){if(r!==-1)return null;r=e}return r===-1||r===n.length-1&&DI(t[r])===DI(n[r])?e:null}if(n.length!==t.length+1)return null;for(let e=0;e<t.length;e+=1)if(t[e]!==n[e])return null;let r=n[n.length-1];if(!r)return null;let i=TI(r),a=r.info.id,o=OI(e);if(i===`user`){let e=o.turnIds.length;return o.turnIds.push(a),o.turnMessageStartIndexes.push(n.length-1),o.turnIndexById.set(a,e),o.messageToTurnId.set(a,a),o.messageToTurnIndex.set(a,e),o.turnCount=o.turnIds.length,o}if(i!==`assistant`){let e=o.turnIds.length-1;if(e<0)return null;let t=o.turnIds[e];return t?(o.messageToTurnId.set(a,t),o.messageToTurnIndex.set(a,e),o):null}let s=EI(r);if(!s)return o;let c=o.turnIndexById.get(s);if(typeof c!=`number`||c<0)return null;let l=o.turnIds[c];return l?(o.messageToTurnId.set(a,l),o.messageToTurnIndex.set(a,c),o):null},AI=e=>{let t=[],n=[],r=new Map,i=new Map,a=new Map,o=new Map,s=-1;return e.forEach((e,c)=>{let l=TI(e),u=e.info.id;if(l===`user`){s=t.length,t.push(u),n.push(c),r.set(u,s),o.set(u,s),i.set(u,u),a.set(u,s);return}if(l!==`assistant`){if(s>=0){let e=t[s];e&&(i.set(u,e),a.set(u,s))}return}let d=EI(e);if(!d)return;let f=o.get(d);if(typeof f!=`number`||f<0)return;let p=t[f];p&&(i.set(u,p),a.set(u,f))}),{turnIds:t,turnMessageStartIndexes:n,turnIndexById:r,messageToTurnId:i,messageToTurnIndex:a,turnCount:t.length}},jI=200,MI={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},NI=()=>jI,PI=()=>Math.round(NI()*.6),FI={MAX_SESSIONS:MI.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(jI*.6),HISTORICAL_MESSAGES:jI,FETCH_BUFFER:20,HISTORY_CHUNK:jI,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:MI.ZOMBIE_TIMEOUT},II=()=>{let e=NI(),t=PI();return{...FI,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},LI=FI,RI=600,zI=6e3,BI=.5,VI=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),HI=e=>{let t=e.getBoundingClientRect(),n=e.querySelectorAll(`[data-message-id]`);for(let e of n)if(e.getBoundingClientRect().bottom>t.top)return e;return null},UI=(e,t)=>{let n=VI(e,t);if(n||=HI(e),!n)return null;let r=n.dataset.messageId;if(!r)return null;let i=e.getBoundingClientRect();return{messageId:r,offsetTop:n.getBoundingClientRect().top-i.top}},WI=e=>{let{container:t,quiesceMs:n=RI,maxLifetimeMs:r=zI}=e,i={messageId:e.anchor.messageId,offsetTop:e.anchor.offsetTop},a=!1,o=null,s=null,c=!1,l=t.scrollTop,u=()=>{o!==null&&(clearTimeout(o),o=null)},d=()=>{s!==null&&(clearTimeout(s),s=null)},f=()=>{a||(a=!0,y.disconnect(),t.removeEventListener(`scroll`,v),u(),d())},p=()=>{u(),!a&&(o=setTimeout(()=>{o=null,f()},n))},m=()=>{d(),!a&&(s=setTimeout(()=>{s=null,f()},r))},h=()=>{if(a)return;let e=UI(t,i.messageId);if(!e){f();return}i.messageId=e.messageId,i.offsetTop=e.offsetTop,l=t.scrollTop},g=()=>{if(a)return;if(Math.abs(t.scrollTop-l)>BI){h();return}let e=VI(t,i.messageId);if(!e){let n=HI(t);if(!n){f();return}let r=n.dataset.messageId;if(!r){f();return}let a=t.getBoundingClientRect();i.messageId=r,i.offsetTop=n.getBoundingClientRect().top-a.top,e=n,l=t.scrollTop}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect().top-n.top-i.offsetTop;Math.abs(r)>BI&&(t.scrollTop+=r),l=t.scrollTop},_=()=>{a||c||(c=!0,queueMicrotask(()=>{c=!1,g()}))},v=()=>{h(),p(),m()},y=new MutationObserver(()=>{a||(_(),p())});return y.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`style`,`class`]}),t.addEventListener(`scroll`,v,{passive:!0}),m(),p(),{rebase:h,dispose:f}},GI=30,KI=1200,qI=1.5,JI=e=>Math.max(KI,e*qI),YI=4,XI=30,ZI=4,QI=30,$I=250,eL=2e3,tL=Nt+2e3,nL=40,rL=`history-loading-timeout`,iL=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),aL=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=rL,e},oL=(e,t,n)=>{if(e===`no-growth`){console.error(`[chat-history] load older completed without prepending messages`,t instanceof Error?t:Error(`chat history pagination returned no growth`),n);return}if(e===`timeout`){console.error(`[chat-history] load older timed out waiting for sync pagination`,t,n);return}console.error(`[chat-history] load older failed`,t,n)},sL=2500,cL=new Map,lL=()=>se()?YI:cn()?ZI:GI,uL=e=>se()?e.length<=XI:!cn()||e.length<=QI,dL=(e,t)=>{if(cL.delete(e),!uL(t.messages))return;let n=lL();for(;cL.size>=n;){let e=cL.keys().next().value;if(typeof e!=`string`)break;cL.delete(e)}cL.set(e,t)},fL=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),pL=e=>e?{owner:`tanstack-core`}:{owner:`controller`},mL=(e,t)=>e?e.canLoadEarlier:t>=II().HISTORICAL_MESSAGES,hL=e=>!(e.isMobile||e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=JI(e.clientHeight)),gL=e=>e.pagesLoaded>=e.maxPages?`stop-bounded`:e.hasMoreAbove?e.scrollHeightAfter-e.scrollHeightBefore>1?`stop-visible`:e.messageCountAfter>e.messageCountBefore||typeof e.oldestIdBefore==`string`&&typeof e.oldestIdAfter==`string`&&e.oldestIdBefore!==e.oldestIdAfter||e.limitAfter>e.limitBefore?`continue`:`stop-no-growth`:`stop-exhausted`,_L=1,vL=8,yL=e=>!(!e.enabled||e.isMobile||!e.sessionReady||!e.messageReady||e.historyLoading||!e.canLoadEarlier||!e.isPinned||e.fillBlocked||e.pendingRevealWork||e.isLoadingOlder||!e.hasMessages||e.clientHeight<=0||e.scrollHeight>e.clientHeight+48),bL=e=>[`chat-timeline-auto-fill`,e.runtimeKey,e.sessionId,e.oldestMessageId,e.messageCount,e.canLoadEarlier],xL=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],SL=20,CL=4,wL=80,TL=new WeakMap,EL=new WeakMap,DL=e=>{let t=EL.get(e)??{generation:0};return t.generation+=1,EL.set(e,t),t.generation},OL=e=>{let t=TL.get(e);t&&(t.touches=0,t.pending=null,t.settleScheduled=!1),DL(e)},kL=e=>{AL(e)},AL=e=>{let t=TL.get(e);if(t)return t;let n={touches:0,pending:null,settleScheduled:!1};e.addEventListener(`touchstart`,()=>{n.touches+=1},{passive:!0});let r=()=>{n.touches=Math.max(0,n.touches-1),n.touches===0&&n.pending&&jL(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),TL.set(e,n),n},jL=(e,t)=>{t.settleScheduled||typeof window>`u`||(t.settleScheduled=!0,window.requestAnimationFrame(()=>{t.settleScheduled=!1;let n=t.pending;t.pending=null,!(!n||t.touches>0||!e.isConnected)&&(Math.abs(e.scrollTop-n.anchorTop)>n.delta+wL||ML(e,n.anchorTop+n.delta))}))},ML=(e,t)=>{let n=DL(e),r=e.style.overflow;if(e.style.overflow=`hidden`,e.scrollTop=t,e.scrollHeight,e.style.overflow=r,e.scrollTop=t,typeof window>`u`)return;let i=!1,a=0,o=()=>{i=!0};e.addEventListener(`touchstart`,o,{passive:!0,once:!0});let s=()=>{if(!i){if((EL.get(e)?.generation??0)!==n){e.removeEventListener(`touchstart`,o);return}e.scrollTop<t-CL&&(e.scrollTop=t),a+=1,a<SL?window.requestAnimationFrame(s):e.removeEventListener(`touchstart`,o)}};window.requestAnimationFrame(s)},NL=(e,t,n)=>{let r=AL(e);if(r.touches>0&&typeof n==`number`&&n>0){r.pending=r.pending?{anchorTop:r.pending.anchorTop,delta:r.pending.delta+n}:{anchorTop:e.scrollTop,delta:n};return}r.pending=null,ML(e,t)},PL=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),FL=(e,t)=>e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight?e:t,IL=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:i,messageListRef:o,loadMoreMessages:s,goToBottom:c,releaseAutoFollow:l,beginHistoryViewportPreservation:u,endHistoryViewportPreservation:d,isPinned:f,showScrollButton:p,autoFillEnabled:m=!1,onWillLoadEarlier:h})=>{let g=Z.useRef(null),_=Z.useRef(null),v=Z.useMemo(()=>{let t=e??``,r=t?cL.get(t):void 0;if(r&&r.messages===n)return dL(t,r),g.current=r.model,_.current=n,r.model;let i=kI(g.current,_.current,n)??AI(n);return g.current=i,_.current=n,t&&n.length>0&&dL(t,{messages:n,model:i}),i},[n,e]),[y,b]=Z.useState(!1),[x,S]=Z.useState(!1),[C,w]=Z.useState(null),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState({scrollHeight:0,clientHeight:0}),j=Z.useRef(v),M=Z.useRef(f),N=Z.useRef(y),P=Z.useRef(x),F=Z.useRef(e),I=Z.useRef(t??null),L=Z.useRef(n),R=Z.useRef(r),z=Z.useRef(D),B=Z.useRef([]),V=Z.useRef(null),H=Z.useRef(null),U=Z.useRef(!1),W=Z.useRef(null),[ee,G]=Z.useState(e);ee!==e&&(G(e),W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null),U.current=!1,N.current=!1,H.current=null,b(!1),S(!1),w(null),E(!1),z.current=null,O(null),A({scrollHeight:0,clientHeight:0}));let K=Z.useMemo(()=>{let e=r?.limit!==D&&mL(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),te=Z.useRef(K);j.current=v,M.current=f,P.current=x,te.current=K,F.current=e,I.current=t??null,L.current=n,R.current=r,z.current=D;let ne=J(()=>{U.current=!0,W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null)}),re=J(()=>{if(typeof window>`u`){U.current=!1;return}W.current!==null&&window.clearTimeout(W.current),W.current=window.setTimeout(()=>{W.current=null,U.current=!1},eL)}),ie=J(()=>{let e=B.current;e.length!==0&&(B.current=[],e.forEach(e=>e()))}),ae=J(()=>new Promise(e=>{if(typeof window>`u`){e();return}let t=!1,n=()=>{t||(t=!0,window.clearTimeout(r),e())};B.current.push(n);let r=window.setTimeout(n,$I)})),oe=J(e=>{let t=V.current;t&&(V.current=null,t.resolve(e))}),se=J(()=>{let e=V.current;if(e){if(e.sessionId!==F.current){oe(!1);return}if(e.kind===`turn`?o.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:o.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(H.current={turnId:e.turnId,expiresAt:Date.now()+sL},w(e.turnId)),oe(!0);return}typeof(e.kind===`turn`?j.current.turnIndexById.get(e.id):j.current.messageToTurnIndex.get(e.id))==`number`&&oe(!1)}}),ce=Z.useRef(null),le=J(()=>{let e=ce.current;e&&(ce.current=null,e.dispose())});nt(()=>{W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null),le(),ie(),oe(!1)});let ue=n;at(()=>{ie(),se()},[ue]);let de=J(()=>{let e=i.current;if(!e){A(e=>FL(e,{scrollHeight:0,clientHeight:0}));return}A(t=>FL(t,{scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))});st(typeof ResizeObserver<`u`?i:null,de),at(()=>{de()},[e,y]);let fe=Z.useRef(null),pe=J(()=>o.current?.captureViewportAnchor()??null),me=J(e=>o.current?.restoreViewportAnchor(e)??!1),he=J(()=>{if(cn())return;le();let e=i.current;if(!e)return;let t=pe();t&&(ce.current=WI({container:e,anchor:t}))}),ge=Z.useRef(null);at(()=>{if(!cn())return;let e=i.current;e&&(kL(e),OL(e))},[e,i]),at(()=>{le(),fe.current=null,ge.current=null,o.current?.cancelViewportAnchorHold()},[e]),at(()=>{let e=i.current;if(!e)return;let t=fe.current;t&&Math.abs(e.scrollTop-t.top)>vL&&(fe.current=null,t=null);let n=ge.current,r=ue[0]?.info?.id??null,a=ue[ue.length-1]?.info?.id??null,s=n?fL({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:a})||PL(n.oldestId,r,ue):!1;t&&t.sessionId!==F.current&&(fe.current=null,t=null);let l=t?fL({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:a})||PL(t.oldestId,r,ue):!1,u=s||l,d=e=>{ge.current={oldestId:r,newestId:a,scrollHeight:e??ge.current?.scrollHeight??0}};if(M.current&&!t){le(),u?(fe.current=null,c(`instant`),d(e.scrollHeight)):d();return}let f=pL(o.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){o.current?.cancelViewportAnchorHold();let e=t.anchor;e&&me(e),d();return}let n=e.scrollHeight,r=n-t.height;if(cn()){r>0&&NL(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&me(i))&&r>0&&(e.scrollTop=t.top+r),d(n);return}if(s&&n&&f.owner===`controller`){let t=e.scrollHeight,r=t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;cn()?NL(e,t,r):e.scrollTop=t}d(t),he();return}d()},[ue,c]);let _e=J(async()=>!1),ve=J(async e=>{let t=Date.now(),n=t+tL,r=I.current,i=r?Pr()?.getRequestState?.(Bi(r,e)):void 0;for(te.current.historyLoading,R.current,i?.status,i?.error;te.current.historyLoading;){if(F.current!==e)return Date.now()-t,`switched`;if(Date.now()>=n){let n=r?Pr()?.getRequestState?.(Bi(r,e)):void 0;return console.error(`[chat-history] historyLoading wait timed out — sync flag still true`,{sessionId:e,directory:r,elapsedMs:Date.now()-t,waitMs:tL,hostTurnPageTimeoutMs:Nt,historyLoading:te.current.historyLoading,historyMeta:R.current,requestStatusAtStart:i?.status??null,requestStatusAtTimeout:n?.status??null,requestErrorAtTimeout:n?.error??null,likelyStaleLoadingFlag:n?.status===`ready`||n?.status===`error`||n==null}),`timeout`}await new Promise(e=>{if(typeof window>`u`){e();return}window.setTimeout(e,nL)})}return Date.now()-t,r&&Pr()?.getRequestState?.(Bi(r,e))?.status,F.current===e?`cleared`:`switched`}),ye=J(async e=>{if(!F.current||N.current||!te.current.hasMoreAboveTurns)return!1;N.current=!0,ne(),b(!0);let t=F.current,n=null,r=!!e.userInitiated;r&&u();let a=()=>{n&&fe.current===n&&(fe.current=null,o.current?.cancelViewportAnchorHold()),r&&(r=!1,d())};try{if(te.current.historyLoading){if(!e.userInitiated)return!1;let n=await ve(t);if(n===`timeout`)throw aL();if(n===`switched`||!te.current.hasMoreAboveTurns)return!1}if(!F.current||F.current!==t)return!1;let r=i.current,o=L.current,c=o.length,l=o[0]?.info?.id??null,u=R.current?.limit??II().HISTORICAL_MESSAGES;e.preserveViewport&&r&&(n={sessionId:F.current,height:r.scrollHeight,top:r.scrollTop,anchor:pe(),oldestId:l,newestId:o[o.length-1]?.info?.id??null},fe.current=n,he());let d=c,f=l,p=u,m=0;for(;;){if(te.current.historyLoading)if(e.userInitiated){let e=await ve(t);if(e===`timeout`)throw a(),aL();if(e===`switched`)return a(),!1}else return a(),!1;let n=i.current?.scrollHeight??0,r=d,o=f,c=p;if(await s(t,`up`),m+=1,F.current!==t)return a(),!1;await ae();let l=L.current,u=l.length,h=l[0]?.info?.id??null,g=R.current?.limit??p,_=gL({scrollHeightBefore:n,scrollHeightAfter:i.current?.scrollHeight??n,messageCountBefore:r,messageCountAfter:u,oldestIdBefore:o,oldestIdAfter:h,limitBefore:c,limitAfter:g,hasMoreAbove:te.current.hasMoreAboveTurns,pagesLoaded:m,maxPages:_L});if(_===`continue`){d=u,f=h,p=g;continue}if(_===`stop-no-growth`){if(te.current.historyLoading){if(e.userInitiated){let e=await ve(t);if(e===`timeout`)throw a(),aL();if(e===`switched`)return a(),!1;--m;continue}return a(),!1}let n=R.current?.limit??c;return z.current=n,O(n),te.current={...te.current,hasMoreAboveTurns:!1,canLoadEarlier:!1},a(),!1}return!0}}catch(e){throw a(),e}finally{N.current=!1,b(!1),re(),ae().then(a)}}),{t:be}=ct(),xe=Ke({mutationKey:xL({runtimeKey:a(),sessionId:e??``}),mutationFn:async e=>{if(F.current!==e.sessionId)return!1;ne(),e.userInitiated&&l();try{return await ye({preserveViewport:!0,userInitiated:!!e.userInitiated})}finally{re()}}}),Se=J(async e=>{let t=F.current;if(t&&!(xe.isPending&&xe.variables?.sessionId===t)){e?.userInitiated&&h?.();try{let n=await xe.mutateAsync({sessionId:t,userInitiated:!!e?.userInitiated});if(n===!1&&te.current.canLoadEarlier){let r={sessionId:t,grew:n,userInitiated:!!e?.userInitiated,canLoadEarlier:te.current.canLoadEarlier,hasMoreAboveTurns:te.current.hasMoreAboveTurns,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};oL(`no-growth`,Error(`chat history pagination returned no growth`),r),e?.userInitiated&&Br.error(be(`chat.history.loadOlderFailed`))}}catch(n){let r={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:tL,hostTurnPageTimeoutMs:Nt,canLoadEarlier:te.current.canLoadEarlier,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};iL(n)?oL(`timeout`,n,r):oL(`failed`,n,r),e?.userInitiated&&Br.error(iL(n)?be(`chat.history.loadOlderTimeout`):be(`chat.history.loadOlderFailed`))}}}),Ce=xe.isPending&&xe.variables?.sessionId===e||y,we=n[0]?.info?.id??null,Te=yL({enabled:m,isMobile:cn(),sessionReady:!!e,messageReady:n.length>0||!!r,historyLoading:K.historyLoading,canLoadEarlier:K.canLoadEarlier,isPinned:f,fillBlocked:T,scrollHeight:k.scrollHeight,clientHeight:k.clientHeight,pendingRevealWork:x,isLoadingOlder:!1,hasMessages:n.length>0});qe({queryKey:bL({runtimeKey:a(),sessionId:e??``,oldestMessageId:we,messageCount:n.length,canLoadEarlier:K.canLoadEarlier}),enabled:!!e&&Te,staleTime:1/0,gcTime:0,retry:(e,t)=>t?.code===`auto-fill-busy`&&e<40,retryDelay:50,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,queryFn:async()=>{let e=F.current;if(!e)return{status:`skip`};if(te.current.historyLoading||N.current){let e=Error(`auto-fill-busy`);throw e.code=`auto-fill-busy`,e}if(!te.current.canLoadEarlier)return{status:`skip`};let t=i.current;if(!t||t.clientHeight<=0)return{status:`skip`};if(t.scrollHeight>t.clientHeight+48)return{status:`tall`};try{let t=await ye({preserveViewport:!0});return t?{status:`grew`}:(te.current.canLoadEarlier&&oL(`no-growth`,Error(`chat history pagination returned no growth`),{sessionId:e,source:`auto-fill`,grew:t,canLoadEarlier:te.current.canLoadEarlier,hasMoreAboveTurns:te.current.hasMoreAboveTurns,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null}),E(!0),{status:`blocked`})}catch(t){if(t?.code===`auto-fill-busy`)throw t;let n={sessionId:e,source:`auto-fill`,waitMs:tL,canLoadEarlier:te.current.canLoadEarlier,historyLoading:te.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};throw iL(t)?oL(`timeout`,t,n):oL(`failed`,t,n),E(!0),t instanceof Error?t:Error(`chat timeline auto-fill failed`)}}});let Ee=J(e=>{let t=i.current;t&&hL({source:e,isMobile:cn(),isPinned:M.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:te.current.canLoadEarlier,isLoadingOlder:N.current,pendingRevealWork:P.current})&&Se({userInitiated:!0})}),De=J(()=>{Ee(`scroll`)}),Oe=J(()=>{Ee(`upward-intent`)}),ke=J(async(t,n)=>{if(!t||!F.current)return!1;l(),S(!0);try{return F.current!==e||typeof j.current.turnIndexById.get(t)!=`number`?!1:!!await new Promise(r=>{V.current={sessionId:F.current??e??``,kind:`turn`,id:t,behavior:n?.behavior??`auto`,turnId:t,resolve:r},se()})}finally{S(!1)}}),Ae=J(async(t,n)=>{if(!t||!F.current)return!1;l(),S(!0);try{if(F.current!==e)return!1;let r=j.current.messageToTurnId.get(t);return typeof j.current.messageToTurnIndex.get(t)==`number`&&!!await new Promise(i=>{V.current={sessionId:F.current??e??``,kind:`message`,id:t,behavior:n?.behavior??`auto`,turnId:r??null,resolve:i},se()})}finally{S(!1)}}),je=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`smooth`)}),Me=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`instant`)}),Ne=J(e=>{let t=H.current;if(t){if(e!==t.turnId&&Date.now()<t.expiresAt)return;H.current=null}w(e)});return{turnIds:v.turnIds,turnStart:0,renderedMessages:ue,historySignals:K,isLoadingOlder:Ce,pendingRevealWork:x,activeTurnId:C,showScrollToBottom:p&&!x,turnWindowModel:v,loadEarlier:Se,revealBufferedTurns:_e,resumeToBottom:je,resumeToBottomInstant:Me,scrollToTurn:ke,scrollToMessage:Ae,handleHistoryScroll:De,handleHistoryUpwardIntent:Oe,captureViewportAnchor:pe,restoreViewportAnchor:me,handleActiveTurnChange:Ne}},LL=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),RL=({open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s=!1,isLoadingEarlier:c=!1,onLoadEarlier:l,onRevertMessage:u})=>{let{t:d}=ct(),f=Rh(),p=n,m=Ur(p??``,r),h=ri(e=>e.revertToMessage),g=ri(e=>e.forkFromMessage),_=LL(f.capabilities),{isMobile:v,isTablet:y}=mo(),b=v||y,[x,S]=Z.useState(null),C=Z.useRef(!1),[w,T]=Z.useState(``),[E,D]=Z.useState(0),O=Z.useRef([]),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(!1),M=Z.useRef(e),N=e=>new Date(e).toLocaleDateString(lt(),{year:`numeric`,month:`short`,day:`numeric`}),P=e=>new Date(e).toLocaleTimeString(lt(),{hour:`numeric`,minute:`2-digit`}),F=Z.useMemo(()=>m.filter(e=>e.info.role===`user`).map(e=>({message:e})),[m]),I=Z.useMemo(()=>{let e=w.trim();if(!e)return F;let t=e.toLowerCase();return F.filter(({message:e})=>tF(e.parts).toLowerCase().includes(t))},[F,w]);Z.useEffect(()=>{j.current||D(w.trim()?0:Math.max(0,I.length-1))},[I,w]),Z.useEffect(()=>{O.current=O.current.slice(0,I.length)},[I.length]),Z.useEffect(()=>{j.current||O.current[E]?.scrollIntoView({block:`nearest`})},[E]),Z.useEffect(()=>{!j.current||A.current||c||(j.current=!1)},[I.length,c]),Z.useLayoutEffect(()=>{let t=M.current;if(M.current=e,!e||t||j.current||w.trim())return;let n=k.current;n&&(n.scrollTop=n.scrollHeight)},[e,w]),Z.useLayoutEffect(()=>{let e=A.current,t=k.current;if(!e||!t||c)return;A.current=null;let n=O.current.find(t=>t?.dataset.timelineMessageId===e.messageId);if(!n)return;let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-e.top},[I.length,c]);let L=J(()=>{let e=k.current;if(e){let t=e.getBoundingClientRect().top,n=O.current.find(e=>e?e.getBoundingClientRect().bottom>=t:!1);n?.dataset.timelineMessageId&&(A.current={messageId:n.dataset.timelineMessageId,top:n.getBoundingClientRect().top-t})}j.current=!0,l?.()}),R=J(async e=>{await i?.(e)!==!1&&t(!1)}),z=J(e=>{let t=I.length;if(t!==0){if(e.key===`ArrowDown`){e.preventDefault(),D(e=>(e+1)%t);return}if(e.key===`ArrowUp`){e.preventDefault(),D(e=>(e-1+t)%t);return}if(e.key===`Enter`){e.preventDefault();let n=(E%t+t)%t,r=I[n];r&&R(r.message.info.id)}}}),B=J(async(e,n)=>{if(!(!p||C.current)){C.current=!0,S({type:e,messageId:n});try{e===`revert`?u?await u(n):await h(p,n,{directory:r}):await g(p,n,{directory:r}),t(!1)}finally{C.current=!1,S(null)}}});return p?(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),d(`chat.timeline.title`)]}),(0,$.jsx)(aa,{children:d(`chat.timeline.description`)})]}),(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{autoFocus:!0,placeholder:d(`chat.timeline.searchPlaceholder`),value:w,onChange:e=>T(e.target.value),onKeyDown:z,className:`pl-9 w-full`})]}),s&&l&&(0,$.jsx)(`div`,{className:`flex justify-center py-1`,children:(0,$.jsxs)(ua,{type:`button`,variant:`link`,size:`sm`,onClick:L,disabled:c,className:`h-auto px-1 py-0 text-muted-foreground hover:text-foreground`,children:[c&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),d(`chat.history.loadOlder`)]})}),(0,$.jsx)(`div`,{ref:k,className:`flex-1 overflow-y-auto`,children:I.length===0?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:d(w?`chat.timeline.empty.search`:`chat.timeline.empty.session`)}):I.map(({message:e},t)=>{let n=nF(e.parts),r=e.info.time.created,i=N(r),a=I[t-1],o=i!==(a?N(a.message.info.time.created):null),s=P(r),c=t===E,l=w.trim()?zL(tF(e.parts),w):null;return(0,$.jsxs)(Z.Fragment,{children:[o&&(0,$.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-3 bg-background/95 py-2 backdrop-blur-sm`,children:[(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i}),(0,$.jsx)(`div`,{className:`h-px flex-1 bg-border/60`})]}),(0,$.jsxs)(`div`,{ref:e=>{O.current[t]=e},"data-timeline-message-id":e.info.id,className:Y(`group flex items-center gap-3 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,c&&`bg-interactive-selection text-interactive-selection-foreground`),onClick:()=>void R(e.info.id),onMouseEnter:()=>D(t),children:[(0,$.jsx)(`span`,{className:Y(`typography-meta w-16 flex-shrink-0 text-right tabular-nums`,c?`text-interactive-selection-foreground/70`:`text-muted-foreground`),children:s}),(0,$.jsxs)(`p`,{className:Y(`flex-1 min-w-0 typography-micro truncate`,c?`text-interactive-selection-foreground`:`text-foreground`),children:[l??(n||d(`chat.timeline.noTextContent`)),!l&&n&&n.length>=80&&`…`]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:(0,$.jsxs)(`div`,{className:Y(`gap-1`,b?`flex`:`hidden group-hover:flex`),children:[_.revert?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`revert`&&x.messageId===e.info.id,disabled:x!==null,onClick:t=>{t.stopPropagation(),B(`revert`,e.info.id)},children:(0,$.jsx)(X,{name:x?.type===`revert`&&x.messageId===e.info.id?`loader-4`:`arrow-go-back`,className:Y(`h-4 w-4`,x?.type===`revert`&&x.messageId===e.info.id&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:d(`chat.timeline.actions.revertFromHere`)})]}):null,_.fork?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:`size-5 text-muted-foreground hover:text-foreground`,"aria-busy":x?.type===`fork`&&x.messageId===e.info.id,onClick:t=>{t.stopPropagation(),B(`fork`,e.info.id)},disabled:x!==null,children:x?.type===`fork`&&x.messageId===e.info.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4`})})}),(0,$.jsx)(Ua,{sideOffset:6,children:d(`chat.timeline.actions.forkFromHere`)})]}):null]})})]})]},e.info.id)})}),(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:d(`chat.timeline.actions.title`)}),(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{a?.(-1),t(!1)},children:d(`chat.timeline.actions.previousTurn`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`button`,{type:`button`,className:`text-[11px] uppercase tracking-wide text-muted-foreground/90 hover:text-foreground`,onClick:()=>{o?.(),t(!1)},children:d(`chat.timeline.actions.latest`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:d(`chat.timeline.help.clickMessage`)})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`arrow-go-back`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:d(`chat.timeline.help.undoToPoint`)})]}),_.fork?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 flex-shrink-0`}),(0,$.jsx)(`span`,{children:d(`chat.timeline.help.createSessionFromHere`)})]}):null]})]})]})}):null};function zL(e,t,n=30){let r=e.toLowerCase(),i=t.toLowerCase(),a=r.indexOf(i);if(a===-1)return null;let o=Math.max(0,a-n),s=Math.min(e.length,a+t.length+n);return`${o>0?`…`:``}${e.slice(o,s).replace(/\n/g,` `)}${s<e.length?`…`:``}`}var BL=e=>{let t=e.startsWith(`#`)?e.slice(1):e;if(!t)return null;let n=t.match(/^turn-(.+)$/);if(n?.[1])return{kind:`turn`,id:n[1]};let r=t.match(/^message-(.+)$/);return r?.[1]?{kind:`message`,id:r[1]}:null},VL=(e,t,n)=>{if(n===0||e.length===0)return{kind:`noop`};let r=t?e.indexOf(t):e.length-1,i=(r>=0?r:e.length-1)+n;if(i>=e.length)return{kind:`resume`};let a=e[Math.max(0,i)];return a?{kind:`turn`,turnId:a}:{kind:`noop`}},HL=e=>{if(typeof window>`u`)return;let t=e?`#${e}`:``,n=`${window.location.pathname}${window.location.search}${t}`;window.history.replaceState(window.history.state,``,n)},UL=e=>{let t=(0,Q.c)(29),{sessionId:n,turnIds:r,activeTurnId:i,scrollToTurn:a,scrollToMessage:o,resumeToBottom:s}=e,c=Z.useRef(r),l=Z.useRef(i),u,d;t[0]===r?(u=t[1],d=t[2]):(u=()=>{c.current=r},d=[r],t[0]=r,t[1]=u,t[2]=d),Z.useEffect(u,d);let f,p;t[3]===i?(f=t[4],p=t[5]):(f=()=>{l.current=i},p=[i],t[3]=i,t[4]=f,t[5]=p),Z.useEffect(f,p);let m;t[6]===a?m=t[7]:(m=async(e,t)=>e?(t?.updateHash!==!1&&HL(`turn-${e}`),a(e,{behavior:t?.behavior})):!1,t[6]=a,t[7]=m);let h=m,g;t[8]===o?g=t[9]:(g=async(e,t)=>e?(t?.updateHash!==!1&&HL(`message-${e}`),o(e,{behavior:t?.behavior})):!1,t[8]=o,t[9]=g);let _=g,v;t[10]!==s||t[11]!==h?(v=async(e,t)=>{let n=c.current,r=VL(n,l.current,e);if(r.kind===`noop`)return e===0;if(r.kind===`resume`){if(t?.resumePastEnd===!1){let e=n[n.length-1];return e?h(e,{behavior:`auto`}):!1}return HL(null),s(),!0}return h(r.turnId,{behavior:`auto`})},t[10]=s,t[11]=h,t[12]=v):v=t[12];let y=v,b;t[13]===s?b=t[14]:(b=()=>{HL(null),s()},t[13]=s,t[14]=b);let x=b,S;t[15]!==_||t[16]!==h||t[17]!==n?(S=()=>{if(!n||typeof window>`u`)return;let e=()=>{let e=BL(window.location.hash);if(e){if(e.kind===`turn`){h(e.id,{behavior:`auto`,updateHash:!1});return}_(e.id,{behavior:`auto`,updateHash:!1})}};return e(),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`hashchange`,e)}},t[15]=_,t[16]=h,t[17]=n,t[18]=S):S=t[18];let C;t[19]!==_||t[20]!==h||t[21]!==n||t[22]!==r.length?(C=[n,_,h,r.length],t[19]=_,t[20]=h,t[21]=n,t[22]=r.length,t[23]=C):C=t[23],Z.useEffect(S,C);let w;return t[24]!==x||t[25]!==y||t[26]!==_||t[27]!==h?(w={scrollToTurnId:h,scrollToMessageId:_,scrollByTurnOffset:y,resumeToLatest:x},t[24]=x,t[25]=y,t[26]=_,t[27]=h,t[28]=w):w=t[28],w},WL=2e4,GL=6e4,KL=2e3,qL=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,JL=e=>{if(e.length===0)return`0`;let t=e[e.length-1];if(!t)return`0`;let n=t.parts??[],r=n[n.length-1],i=0;for(let e of n)i+=qL(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},YL={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},XL=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:YL,shouldRefresh:!1,stalledForMs:0};if(e.sessionKey!==n)return{state:{sessionKey:n,fingerprint:a,lastMovementAt:o,lastRefreshAt:null,attempts:0},shouldRefresh:!1,stalledForMs:0};if(e.fingerprint!==a)return{state:{...e,fingerprint:a,lastMovementAt:o,attempts:0},shouldRefresh:!1,stalledForMs:0};if(!r||i)return{state:{...e,lastMovementAt:o},shouldRefresh:!1,stalledForMs:0};let s=e.lastMovementAt??o,c=o-s,l=e.lastRefreshAt===null||o-e.lastRefreshAt>=t.cooldownMs,u=c>=t.thresholdMs&&l&&e.attempts<t.maxAttempts;return{state:{...e,lastMovementAt:s,lastRefreshAt:u?o:e.lastRefreshAt,attempts:u?e.attempts+1:e.attempts},shouldRefresh:u,stalledForMs:c}},ZL=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)};function QL(e){let t=e.match(/^User has answered your questions:\s*(.+?)\.\s*You can now/s);if(!t)return null;let n=[],r=t[1],i=/"([^"]+)"="([^"]*(?:[^"\\]|\\.)*)"/g,a;for(;(a=i.exec(r))!==null;)n.push({question:a[1],answer:a[2]});return n.length>0?n:null}function $L(e){if(typeof e.id==`string`&&e.id)return e.id;if(typeof e.callID==`string`&&e.callID)return e.callID;let t=e.state;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t.callID;if(typeof e==`string`&&e)return e}return null}function eR(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(t.type!==`tool`||t.tool!==`question`)return!1;let n=t.state&&typeof t.state==`object`&&!Array.isArray(t.state)?t.state:{},r=typeof n.status==`string`?n.status:void 0;if(r===`error`)return!1;if(r===`pending`||r===`running`||r===void 0)return!0;if(r!==`completed`)return!1;let i=typeof n.output==`string`?n.output:``;return!i||QL(i)==null}function tR(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!eR(n))continue;let e=$L(n);e&&t.push(e)}}return t}function nR(e,t){return`${e}:${t.join(`,`)}`}function rR(e){let t=e.sessionId?.trim()??``,n=e.directory?.trim()??``;if(!t||!n||e.sessionQuestionCount>0||e.unansweredToolIds.length===0)return{recover:!1,attemptKey:null};let r=nR(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function iR(e,t,n,r){let i=(0,Q.c)(7),a=Hn(),o=Z.useRef(null),s=Z.useRef(`${e??``}:${t??``}`),c,l;i[0]!==a||i[1]!==t||i[2]!==n||i[3]!==e||i[4]!==r?(c=()=>{let i=`${e??``}:${t??``}`;s.current!==i&&(o.current=null,s.current=i);let c=rR({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:tR(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,on(t,l,[e]))},l=[e,t,n,r,a],i[0]=a,i[1]=t,i[2]=n,i[3]=e,i[4]=r,i[5]=c,i[6]=l):(c=i[5],l=i[6]),Z.useEffect(c,l)}var aR=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),oR=(e,t)=>({...e,key:sR(e),estimatedBytes:aR(t)}),sR=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),cR=e=>({key:e?sR(e):null,selection:e}),lR=(e,t,n)=>{let r=Math.max(1,Math.floor(n.maxEntries)),i=Math.max(0,n.maxEstimatedBytes),a=e.reduce((e,t)=>e+t.estimatedBytes,0);if(e.length<=r&&a<=i)return e;let o=[...e];for(;o.length>r||a>i;){let e=o.findIndex(e=>e.key!==t);if(e===-1)break;let[n]=o.splice(e,1);a-=n?.estimatedBytes??0}return o},uR=(e,t,n,r)=>{let i=sR(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return lR(e,i,n);let s=o||oR(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),lR(c,i,n)},dR=(e,t,n)=>{let r=aR(n),i=e.findIndex(e=>e.key===t);return i===-1||e[i].estimatedBytes===r?e:e.map((e,t)=>t===i?{...e,estimatedBytes:r}:e)},fR=(e,t)=>t&&e.some(e=>e.key===t)?t:null,pR=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?uR(e.cachedSessionViews,t.selection,n,r.estimatedBytes):lR(e.cachedSessionViews,t.key??``,n),a=!r&&e.pendingSessionView?.intent===t?e.pendingSessionView:null;return e.activeIntent===t&&!e.cacheNeedsTrim&&i===e.cachedSessionViews&&a===e.pendingSessionView?e:{activeIntent:t,cacheNeedsTrim:!1,cachedSessionViews:i,pendingSessionView:a}},mR=(e,t,n,r)=>{if(n!==t||e.activeIntent!==t||!t.selection||e.cachedSessionViews.some(e=>e.key===t.key))return e;let i={entry:oR(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},hR=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:uR(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},gR=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},_R=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},vR=e=>_R(e)?.role===`assistant`,yR=(e,t)=>{let n=_R(t);n&&(e.agentName??=gR(n.agent),e.providerId??=gR(n.providerID),e.modelId??=gR(n.modelID))},bR=e=>!!(e.agentName&&e.providerId&&e.modelId),xR=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!vR(r))&&(yR(t,r),bR(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||vR(r))&&(yR(t,r),bR(t)))break}return t},SR=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),CR=[],wR=[],TR={type:`idle`},ER=`openchamber:chat-force-scroll-bottom`,DR=()=>void 0,OR=`Quota limit reached. Retrying automatically.`,kR=1048576,AR=kR,jR=20,MR=kR,NR=16*kR,PR={maxEntries:3,maxEstimatedBytes:32*kR},FR={maxEntries:2,maxEstimatedBytes:32*kR},IR=e=>t(()=>e()),LR={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},RR={scrollbar:`chat`,scrollShadow:`true`,orientation:`vertical`},zR=()=>{let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 bottom-full z-0 h-11 bg-gradient-to-t from-[var(--surface-background)] to-transparent`}),e[0]=t):t=e[0],t},BR=`calc(max(0.625rem, var(--oc-safe-area-top, 0px)) + var(--oc-mobile-detail-navigation-height) + 1.25rem)`,VR=AF,HR=[`a[href]`,`button`,`input`,`select`,`textarea`,`[contenteditable="true"]`,`[role="button"]`,`[role="combobox"]`,`[role="dialog"]`,`[role="listbox"]`,`[role="menu"]`,`[role="menuitem"]`,`[role="option"]`,`[role="textbox"]`,`[data-radix-popper-content-wrapper]`].join(`,`),UR=e=>e instanceof HTMLElement,WR=e=>UR(e)?!!e.closest(HR):!1,GR=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||WR(e)?!0:!t?.contains(e),KR=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=q.getState();return e||t||n||r||i||a||o},qR=Z.memo(({currentSessionId:e,virtualizerKey:t,isDesktopExpandedInput:n,isMobile:r,stickyUserHeader:i,directory:a,scrollRef:o,messageListRef:s,pendingRevealWork:c,renderedMessages:l,isLoadingOlder:u,sessionIsWorking:d,streamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,handleMessageContentChange:h,getAnimationHandlers:g,handleHistoryScroll:_,handleHistoryUpwardIntent:v,onTimelineIsAtEndChange:y,timelineFollowSuspended:b,timelineHistoryAnchorToken:x,scrollToBottom:S,sessionQuestions:C,sessionPermissions:w,isProgrammaticFollowActive:T,showLoadOlderButton:E,onLoadOlder:D,turnIds:O,activeTurnId:k,onSelectTurn:A,showPromptNavigator:j,canLoadEarlierPrompts:M,isLoadingOlderPrompts:N,onLoadEarlierPrompts:P})=>{let{t:F}=ct(),I=Bs(e=>e.legendTimelineEnabled),L=Mx({isLoadingOlder:u}),R=Nx({isMobile:r,isLoadingOlder:L}),z=Z.useRef(new Map),B=Z.useRef(new WeakMap),V=Z.useRef(new Map),H=Z.useMemo(()=>{let e=new Map;for(let t=0;t<l.length;t+=1){let n=l[t];if(n.info.role!==`user`)continue;if(QM(n)){let r=eN(l,t)??``,i=V.current.get(n.info.id);if(i&&i.command===r)e.set(n.info.id,i.parts);else{let t=[{type:`text`,text:r?`$ ${r}`:`/shell`}];V.current.set(n.info.id,{command:r,parts:t}),e.set(n.info.id,t)}continue}if(St(n.parts))continue;let r=B.current.get(n.parts);r||(r=Gi(n.parts),B.current.set(n.parts,r)),r.length!==0&&e.set(n.info.id,r)}let t=z.current;if(t.size===e.size){let n=!0;for(let[r,i]of e)if(t.get(r)!==i){n=!1;break}if(n)return t}return z.current=e,e},[l]),U=Z.useMemo(()=>O.filter(e=>H.has(e)),[H,O]),W=Z.useMemo(()=>{if(!k||H.has(k))return k;let e=O.indexOf(k);for(let t=e-1;t>=0;--t){let e=O[t];if(H.has(e))return e}return null},[k,H,O]),ee=J(e=>{e.defaultPrevented||WR(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return PF({scrollRef:o,enabled:I,onUpwardIntent:v}),I?(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,n?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":n,children:(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(EP,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:S,scrollRef:o,directory:a,timelineScrollClassName:`absolute inset-0 z-0 chat-scroll overlay-scrollbar-target`,timelineScrollStyle:LR,timelineScrollDataset:RR,timelineOnScroll:_,timelineFollowEnabled:!c&&!b,timelineHistoryAnchorToken:x,timelineOnIsAtEndChange:y,headerSlot:(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:BR},"aria-hidden":`true`}),E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(ua,{variant:`secondary`,size:`sm`,onClick:D,disabled:L,"aria-busy":L,children:[L&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),F(`chat.history.loadOlder`)]})}),R&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:F(`chat.history.loadingMore`)})]})})]}),footerSlot:(0,$.jsxs)($.Fragment,{children:[(C.length>0||w.length>0)&&(0,$.jsxs)(`div`,{children:[C.map(e=>(0,$.jsx)(eF,{question:e},e.id)),w.map(e=>(0,$.jsx)(qP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?VR:OF},"aria-hidden":`true`})]})}),(0,$.jsx)(ho,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(CF,{turnIds:U,previewsByTurnId:H,activeTurnId:W,onSelectTurn:A,canLoadEarlier:M,isLoadingOlder:N,onLoadEarlier:P}):null]})}):(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,n?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":n,children:(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(ja,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:LR,observeMutations:!1,hideTopShadow:r&&i,hideBottomShadow:r,tabIndex:0,onClick:ee,onScroll:_,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:Y(`oc-chat-scroll-content relative z-0 min-h-full`,r&&`chat-scroll-foot-inset`),children:[E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(ua,{variant:`secondary`,size:`sm`,onClick:D,disabled:L,"aria-busy":L,children:[L&&(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),F(`chat.history.loadOlder`)]})}),R&&(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex justify-center pointer-events-none`,role:`status`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 pt-3 pb-1`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin text-[var(--surface-mutedForeground)]`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`typography-meta text-[var(--surface-mutedForeground)]`,children:F(`chat.history.loadingMore`)})]})}),(0,$.jsx)(EP,{ref:s,sessionKey:e,virtualizerKey:t,disableStaging:c,messages:l,sessionIsWorking:d,activeStreamingMessageId:f,activeStreamingPhase:p,retryOverlay:m,onMessageContentChange:h,getAnimationHandlers:g,isLoadingOlder:u,scrollToBottom:S,scrollRef:o,directory:a}),(C.length>0||w.length>0)&&(0,$.jsxs)(`div`,{children:[C.map(e=>(0,$.jsx)(eF,{question:e},e.id)),w.map(e=>(0,$.jsx)(qP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(oA,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?kF:OF},"aria-hidden":`true`})]})}),(0,$.jsx)(ho,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(CF,{turnIds:U,previewsByTurnId:H,activeTurnId:W,onSelectTurn:A,canLoadEarlier:M,isLoadingOlder:N,onLoadEarlier:P}):null]})})},(e,t)=>e.currentSessionId===t.currentSessionId&&e.virtualizerKey===t.virtualizerKey&&e.isDesktopExpandedInput===t.isDesktopExpandedInput&&e.isMobile===t.isMobile&&e.stickyUserHeader===t.stickyUserHeader&&e.directory===t.directory&&e.scrollRef===t.scrollRef&&e.messageListRef===t.messageListRef&&e.pendingRevealWork===t.pendingRevealWork&&e.renderedMessages===t.renderedMessages&&e.isLoadingOlder===t.isLoadingOlder&&e.sessionIsWorking===t.sessionIsWorking&&e.streamingMessageId===t.streamingMessageId&&e.activeStreamingPhase===t.activeStreamingPhase&&e.retryOverlay===t.retryOverlay&&e.handleMessageContentChange===t.handleMessageContentChange&&e.getAnimationHandlers===t.getAnimationHandlers&&e.handleHistoryScroll===t.handleHistoryScroll&&e.handleHistoryUpwardIntent===t.handleHistoryUpwardIntent&&e.onTimelineIsAtEndChange===t.onTimelineIsAtEndChange&&e.timelineFollowSuspended===t.timelineFollowSuspended&&e.timelineHistoryAnchorToken===t.timelineHistoryAnchorToken&&e.scrollToBottom===t.scrollToBottom&&e.sessionQuestions===t.sessionQuestions&&e.sessionPermissions===t.sessionPermissions&&e.isProgrammaticFollowActive===t.isProgrammaticFollowActive&&e.showLoadOlderButton===t.showLoadOlderButton&&e.onLoadOlder===t.onLoadOlder&&e.turnIds===t.turnIds&&e.activeTurnId===t.activeTurnId&&e.onSelectTurn===t.onSelectTurn&&e.showPromptNavigator===t.showPromptNavigator&&e.canLoadEarlierPrompts===t.canLoadEarlierPrompts&&e.isLoadingOlderPrompts===t.isLoadingOlderPrompts&&e.onLoadEarlierPrompts===t.onLoadEarlierPrompts);qR.displayName=`ChatViewport`;var JR=[{id:1,toolRows:[{id:`search`,titleWidth:`w-24`,detailWidth:`w-52`},{id:`read`,titleWidth:`w-20`,detailWidth:`w-36`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-64`}],textWidths:[`w-24`,`w-[92%]`,`w-[78%]`]},{id:2,toolRows:[{id:`read`,titleWidth:`w-20`,detailWidth:`w-40`},{id:`search`,titleWidth:`w-24`,detailWidth:`w-48`}],textWidths:[`w-20`,`w-[88%]`,`w-[70%]`]},{id:3,toolRows:[{id:`shell`,titleWidth:`w-28`,detailWidth:`w-44`},{id:`edit`,titleWidth:`w-24`,detailWidth:`w-56`}],textWidths:[`w-24`,`w-[84%]`,`w-[64%]`]}],YR=e=>ca(e.path),XR=(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)]})},ZR=e=>{let t=Math.ceil(Math.max(0,e)/jR);return Math.min(NR,AR+t*MR)},QR=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:s,hostedFeatures:c,assistantHistory:l,onRevertMessage:u,warning:d=null,pendingUserMessages:f=wR,onPendingUserMessagesMaterialized:p})=>{let m=c??Lx(void 0),{t:h}=ct();at(()=>{oi()},[]);let g=ri(e=>e.openNewSessionDraft),_=ri(e=>e.setCurrentSession),v=ri(e=>e.newSessionDraft),y=ri(e=>e.newSessionDraft.draftSubmitting??!1),b=ri(e=>e.newSessionDraft.draftEstablishing??!1),x=ri(e=>e.forkTransition),S=gr(e=>e.projects),C=gr(e=>e.activeProjectId),w=Ai(e=>e.providers),T=ku(),E=Ir(),D=i??E;at(()=>{!n||!r||!D||jn(D,r)},[n,r,D]);let O=J(e=>T.ensureSessionRenderable(e,{directory:D})),k=q(e=>e.isExpandedInput),A=q(e=>e.stickyUserHeader),j=q(e=>e.promptNavigatorEnabled),M=q(e=>e.allowPromptingSubagentSessions),N=q(e=>e.isTimelineDialogOpen),P=q(e=>e.setTimelineDialogOpen),F=zn(e=>n&&r?e.streamingMessageIds.get(r)??null:null),I=zn(e=>F?e.messageStreamStates.get(F)?.phase??null:null),L=mi(r??``,D),R=ZR(L);Z.useEffect(()=>{!a||!o||o(a,R)},[o,R,a]);let z=Mi(r??``,D).renderable,B=_t(r,D),V=Yn(r),H=B??V,U=Bg({sessionId:r,hasSessionEntity:!!H,hasRenderableSessionSnapshot:z,composerSurfaceKind:s?.kind}),W=r?JSON.stringify([D,r]):null,[ee,G]=Z.useState({key:W,attempt:0}),K=Ur(r??``,D,{suspendPartUpdates:!!F,suspendPartUpdatesForMessageId:F}),te=r?K:CR,ne=v.pendingUserMessage,re=ri(e=>r?e.retainedPendingUserMessages.get(r):void 0)??wR,ie=ri(e=>e.clearRetainedPendingUserMessages),ae=Z.useMemo(()=>{if(re.length===0)return f;if(f.length===0)return re;let e=new Set(f.map(e=>e.info.id));return[...f,...re.filter(t=>!e.has(t.info.id))]},[f,re]),oe=Z.useMemo(()=>xR(te),[te]),ce=Z.useMemo(()=>{if(!oe.modelId)return h(`common.unavailable`);let e=w.find(e=>e.id===oe.providerId);return Si(e,oe.modelId)||oe.modelId},[w,oe.modelId,oe.providerId,h]),le=Ti(r??``,D),ue=yi(r??``,D),[de,fe]=Z.useState(null),pe=!!r&&de===r,me=J(()=>{if(!r||pe)return;let e=r,t=D;fe(e);let n=Pi(()=>{let n=Pr();if(!n)throw Error(`unbound`);return n.getTranscript(Bi(t,e))});Oi(Ar({kind:`refresh`,sessionID:e,directory:t,purpose:`retry`,source:`network`,request:le?{sessionID:e,status:le.status===`ready`?`ready`:le.status,error:le.error}:void 0,hydration:ue,error:le?.error})),(async()=>{try{await Nn(t,e),await T.ensureSessionRenderable(e,{directory:t});try{let r=Pi(()=>{let n=Pr();if(!n)throw Error(`unbound`);return n.getTranscript(Bi(t,e))});n&&r&&vr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){Oi(Ar({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:ue,error:n}))}finally{fe(t=>t===e?null:t)}})()}),he=li(r??``,D).boundary,ge=J(async e=>{if(he.kind===`has-more`){await si(D,e);return}if(he.kind===`unknown`){await _i(D,e);return}l&&!l.complete&&await l.fetchPrevious()}),_e=Fi(r??``,D),ve=Sr(r??``,D),ye=jr(D),be=_e??TR,xe=ar(r,D),Se=En(r,D);iR(r,D,te,Se.length);let Ce=Z.useMemo(()=>{if(!r||xe.length>0||Se.length>0)return!1;let e=be.type??`idle`;if(e===`busy`||e===`retry`||Ox(ae,{resolvedSessionStatus:_e,sessionStatusObservedAt:ve}))return!0;let t=te[te.length-1]?.info,n=t?.time?.created;return _e&&typeof ve==`number`&&typeof n==`number`&&n<=ve||typeof ye==`number`&&typeof n==`number`&&n<=ye?!1:!!(t&&t.role===`assistant`&&typeof t.time?.completed!=`number`)},[r,ae,_e,te,xe.length,Se.length,be.type,ve,ye]),we=Z.useMemo(()=>!r||be.type!==`retry`?null:{sessionId:r,message:(typeof be.message==`string`?(be.message??``).trim():``)||OR,confirmedAt:be.confirmedAt},[r,be]),[Te,Ee]=Z.useState(0),De=Z.useRef(null);Z.useEffect(()=>{if(!we||typeof we.confirmedAt==`number`){De.current=null,Ee(0);return}De.current!==we.sessionId&&(De.current=we.sessionId,Ee(Date.now()))},[we]);let Oe=Z.useMemo(()=>we?{...we,fallbackTimestamp:Te}:null,[we,Te]),ke=!!(r&&T.isLoading(r,{directory:D})),Ae=Z.useMemo(()=>{if(!r)return null;let e=kx({boundary:he,assistantComplete:l?.complete??!0});return{limit:he.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:Ax({syncLoading:ke,assistantLoading:!!l?.loading})}},[l?.complete,l?.loading,r,he,ke]),je=q(e=>e.isMobile),Me=rg()!==null,Ne=se(),Pe=Tg(),Fe=!!v?.open,Ie=Pt(e=>e.error),Le=k,Re=Me||je||Ne||Pe===`mini-chat`,ze=Z.useRef(null),Be=Z.useMemo(()=>{let e=v?.selectedProjectId?S.find(e=>e.id===v.selectedProjectId)??null:null,t=C?S.find(e=>e.id===C)??null:null,n=e??t??S[0]??null;return n?YR(n):null},[C,v?.selectedProjectId,S]),Ve=Qn(r,D),He=a??r??``,[Ue,We]=Z.useState(null),Ge=Gg(Ue,He,Ve,oe);at(()=>{We(e=>Gg(e,He,Ve,oe))},[Ve,oe,He]);let Ke=Ve??Ge?.parentTarget??null,qe=Ge?.execution??oe,Je=pl(),Ye=Je!==null&&r===Je,Xe=J(()=>{Ke&&_(Ke.id,Ke.directory)}),Ze=Ke?.session?.title,Qe=m.returnToParent&&Ke&&!Ye?(0,$.jsxs)(ua,{type:`button`,variant:`outline`,size:`xs`,onClick:Xe,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":h(`chat.container.returnToParent.aria`),title:Ze?.trim()?h(`chat.container.returnToParent.titleNamed`,{title:Ze}):h(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),h(`chat.container.returnToParent.label`)]}):null,$e=Vg({readOnly:t,sessionIdentityPending:U,isSubagentSession:!!H?.parentID||!!Ge,allowPromptingSubagentSessions:M}),et=qe.modelId===oe.modelId?ce:qe.modelId?Si(w.find(e=>e.id===qe.providerId),qe.modelId)||qe.modelId:h(`common.unavailable`),tt=Ke?(0,$.jsx)(Vx,{agentName:qe.agentName,providerId:qe.providerId,modelId:qe.modelId,modelName:et}):(0,$.jsx)(Vx,{}),rt=J(e=>{q.getState().setAllowPromptingSubagentSessions(e.allowPromptingSubagentSessions)}),lt=J(e=>{if(typeof window>`u`||e.source!==window.parent||e.origin!==window.location.origin)return;let t=e.data;t?.type===`openchamber:chat-settings-sync`&&typeof t.payload?.allowPromptingSubagentSessions==`boolean`&&rt({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),ut=typeof window<`u`&&window.parent!==window;ot(`message`,lt,ut?window:DR),it(()=>{if(!ut)return;let e=window;e.__openchamberApplyChatSettingsSync=rt,window.parent.postMessage({type:`openchamber:chat-settings-request`},window.location.origin)}),nt(()=>{if(typeof window>`u`)return;let e=window;e.__openchamberApplyChatSettingsSync===rt&&delete e.__openchamberApplyChatSettingsSync}),Z.useEffect(()=>{m.newSessionDraft&&e&&!r&&!Fe&&g()},[e,r,Fe,m.newSessionDraft,g]);let dt=Z.useRef(()=>{}),ft=J(e=>{dt.current(e)}),pt=Z.useRef(()=>{}),mt=J(()=>{pt.current()}),ht=Bs(e=>e.legendTimelineEnabled),[gt,vt]=Z.useState(!0),[yt,bt]=Z.useState(!1),[xt,St]=Z.useState(!1),[Ct,wt]=Z.useState(0),Tt=J(()=>{wt(e=>e+1)}),Et=J((e,t)=>{vt(e),e&&St(!1),t!==void 0&&bt(t)});Z.useEffect(()=>{vt(!0),bt(!1),St(!1)},[r]);let{scrollRef:Dt,notifyContentChange:Ot,getAnimationHandlers:kt,goToBottom:At,scrollToBottomOnSend:jt,releaseAutoFollow:Mt,beginHistoryViewportPreservation:Nt,endHistoryViewportPreservation:Ft,restoreSnapshot:It,isPinned:Lt,isFollowingProgrammatically:Rt,showScrollButton:zt}=tI({enabled:n&&!ht,currentSessionId:r,viewportKey:a,sessionMessageCount:L,sessionIsWorking:Ce,isMobile:je,onActiveTurnChange:ft,onUpwardUserIntent:mt}),Bt=Z.useRef(null);wI({enabled:je,scrollRef:Dt,scopeRef:Bt});let Vt=Z.useRef([]),Ht=Z.useMemo(()=>{let e=Li(l?.entries??[],r,Vt.current);return Vt.current=e,e},[l?.entries,r]),Ut=Z.useRef([]),Wt=Z.useMemo(()=>{if(!l)return te;let e=or(l.entries,r,te,Ut.current);return Ut.current=e,e},[l,r,te]),Gt=Z.useMemo(()=>Dx(Ht.length===0?Wt:r?[...Ht,ci(r),...Wt]:Ht,ae),[r,Wt,Ht,ae]),Kt=Z.useRef(null),qt=Z.useMemo(()=>Ix({sessionId:r,messages:Gt,retained:Kt.current}),[r,Gt]);Kt.current=qt.retained;let Jt=qt.messages,Yt=Z.useRef(null),Xt=Yt.current===r,Zt=Z.useRef(YL),Qt=r?`${D}\n${r}`:null,$t=J(()=>JL(Jt));Z.useEffect(()=>{if(!r||!Qt||!Ce){Zt.current={...Zt.current,lastMovementAt:null};return}let e=r,t=D,n=setInterval(()=>{let n=$t(),r=XL(Zt.current,{sessionKey:Qt,working:!0,streaming:!!F,fingerprint:n,now:Date.now(),thresholdMs:WL,cooldownMs:GL,maxAttempts:3});Zt.current=r.state,r.shouldRefresh&&(ZL({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),mr(t,e).catch(()=>{}))},KL);return()=>clearInterval(n)},[r,D,$t,Ce,F,Qt]);let en=Z.useMemo(()=>{if(ae.length===0)return[];let e=new Set([...Ht,...Wt].filter(e=>Ji(e.parts)).map(e=>e.info.id));return ae.map(e=>e.info.id).filter(t=>e.has(t))},[Wt,Ht,ae]);Z.useEffect(()=>{en.length!==0&&(p?.(en),r&&ie(r,en))},[ie,r,en,p]);let tn=IL({sessionId:r,directory:D,messages:Jt,historyMeta:Ae,scrollRef:Dt,messageListRef:ze,loadMoreMessages:ge,goToBottom:At,releaseAutoFollow:Mt,beginHistoryViewportPreservation:Nt,endHistoryViewportPreservation:Ft,isPinned:ht?gt:Lt,showScrollButton:ht?yt:zt,autoFillEnabled:n&&!Le,onWillLoadEarlier:Tt}),nn=J(()=>{St(!1),ze.current?.scrollToBottom(),At(`instant`)}),rn=J(()=>{St(!1),jt()}),an=J(()=>{St(!0),tn.handleHistoryUpwardIntent()}),on=jx({isMobile:je,canLoadEarlier:tn.historySignals.canLoadEarlier,isLoadingOlder:tn.isLoadingOlder}),sn=tn.isLoadingOlder,cn=tn.loadEarlier,ln=J(()=>{St(!0),cn({userInitiated:!0})});dt.current=tn.handleActiveTurnChange,pt.current=tn.handleHistoryUpwardIntent,Z.useEffect(()=>{(xe.length!==0||Se.length!==0)&&Ot(`permission`)},[Ot,xe,Se]);let un=UL({sessionId:r,turnIds:tn.turnIds,activeTurnId:tn.activeTurnId,scrollToTurn:tn.scrollToTurn,scrollToMessage:tn.scrollToMessage,resumeToBottom:nn}),dn=$e.showReadOnlyBanner?tt:t?null:(0,$.jsx)(yx,{surface:s,scrollToBottom:rn,showScrollToBottom:je&&tn.showScrollToBottom,onScrollToBottom:un.resumeToLatest,submissionBlocked:$e.blockSubmission}),fn=J(e=>{un.scrollToTurnId(e,{behavior:`smooth`})}),pn=tn.historySignals.canLoadEarlier,mn=m.promptNavigator&&!je&&!Ne&&!Le&&j&&tn.turnIds.length>=2;Z.useEffect(()=>{mn||q.getState().setPromptNavigatorPanelOpen(!1)},[mn]);let hn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||At(`instant`)});ot(ER,hn,n&&r&&typeof window<`u`?window:DR);let gn=J(e=>{if(!n||!r||Le||e.defaultPrevented||e.isComposing||e.key!==`ArrowUp`&&e.key!==`ArrowDown`||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let{activeMainTab:t}=q.getState();if(t!==`chat`||KR())return;let i=Dt.current;if(GR(document.activeElement,i)||WR(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;un.scrollByTurnOffset(a,{resumePastEnd:!1})});ot(`keydown`,gn,n&&r&&!Le&&typeof window<`u`?window:DR);let _n=Z.useRef(0),vn=J(()=>{let e=Dt.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),yn=J(()=>{_n.current||=requestAnimationFrame(()=>{_n.current=0,vn()})});at(()=>{n&&vn()},[n,r,Le,vn]);let bn=typeof ResizeObserver<`u`;st(n&&bn?Dt:null,yn),ot(`resize`,yn,n&&!bn&&typeof window<`u`?window:DR),nt(()=>{_n.current&&=(cancelAnimationFrame(_n.current),0)});let xn=Z.useRef(null),Sn=Z.useRef(0),Cn=Px({transcriptMessageCount:te.length,pendingUserCount:ae.length,historyPrefixCount:Ht.length}),wn=Fx({hasTranscriptShell:Cn,p0Satisfied:ue.p0Satisfied,hasBusyShell:Ce&&Cn,hasImmediateShell:ae.length>0||Ht.length>0,hasRenderableSessionSnapshot:z,prefetchStatus:le?.status,syncLoading:!!(r&&T.isLoading(r,{directory:D})),userRetrying:pe,hasPaintedTranscript:Xt});wn===`pass`&&Jt.length>0&&(Yt.current=r);let Tn=!!r&&wn===`hydrating`,Dn=!!r&&wn===`load-error`;Z.useEffect(()=>{!Dn||!r||Oi(Ar({kind:`request-error`,sessionID:r,directory:D,purpose:`load-failed`,source:`network`,request:le?{sessionID:r,status:le.status===`ready`?`ready`:le.status,error:le.error}:void 0,hydration:ue,error:le?.error}))},[r,D,Dn,le,ue]),Z.useEffect(()=>{if(!n||!r||Tn)return;let e=Jt.length,t=xn.current!==r,i=!t&&Sn.current===0&&e>0;if(!t&&!i){xn.current===r&&(Sn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(xn.current=r,Sn.current=e,a){Mt();return}let o=()=>{It()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,Tn,Mt,It,Jt.length]),Z.useEffect(()=>{G(e=>e.key===W?e:{key:W,attempt:0})},[W]),Z.useEffect(()=>{if(!n||!r||ee.key!==W||!SR({sessionId:r,hasRenderableSessionSnapshot:z,hasCurrentSessionEntity:!!H})||(O(r),H||ee.attempt>=2))return;let e=ee.attempt+1,t=window.setTimeout(()=>{G(t=>t.key===W&&t.attempt===ee.attempt?{key:W,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,H,r,D,O,z,W,ee]);let On=x&&r&&(x.targetSessionId?r===x.targetSessionId:r===x.sourceSessionId)?x:null;if(On){let e=On.stage===`preparing`?`chat.forkTransition.preparing`:On.stage===`copying`?`chat.forkTransition.copying`:On.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=h(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(On.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${h(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:h(e)}),(0,$.jsx)(Hp,{})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70 tabular-nums`,children:n})]})})}return!r&&!Fe?e&&!Ie?(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`}):(0,$.jsx)(`div`,{className:`flex flex-col h-full bg-background`,children:(0,$.jsx)(Ux,{})}):!r&&Fe?(y||b)&&ne?(0,$.jsx)(`div`,{className:`relative flex h-full flex-col bg-background`,children:(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:(0,$.jsxs)(ja,{className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll`,style:LR,children:[(0,$.jsx)(EP,{sessionKey:`draft:${v.draftID??`pending`}`,messages:[ne],sessionIsWorking:!0,isLoadingOlder:!1,onMessageContentChange:Ot,getAnimationHandlers:kt,scrollToBottom:nn}),(0,$.jsxs)(`div`,{className:`chat-message-column px-4 pb-10 pt-2 typography-meta text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:h(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Hp,{})]})]})})}):y||b?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":h(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:h(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(Hp,{})]})})}):(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Re&&!Le?(0,$.jsxs)(`div`,{className:`oc-draft-center flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-balance text-3xl font-normal tracking-tight text-foreground`,children:XR(Be?h(`chat.emptyState.draftTitleWithProject`,{project:Be}):h(`chat.emptyState.draftTitle`),Be)}),(0,$.jsx)(L_,{onSubmit:e=>ei.getState().requestPresetSubmit(e),className:`oc-draft-starters mt-8 max-w-md`})]}):null,(0,$.jsx)(`div`,{className:Y(`relative z-10 flex min-h-0`,je&&`oc-mobile-composer-foot`,Le?`flex-1 bg-background`:Re?Y(`bg-background`,`px-0`):`flex-1 items-center justify-center bg-background px-0 pb-[6vh]`),children:dn})]}):r?Dn?(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col bg-background`,children:[Qe,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Le?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Le,children:Le?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6`,children:(0,$.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center text-center`,role:`alert`,"aria-live":`polite`,children:[(0,$.jsx)(`div`,{className:`mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--status-error-background)] text-[var(--status-error-foreground)]`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-5`,"aria-hidden":`true`})}),(0,$.jsx)(`h2`,{className:`typography-ui-header text-foreground`,children:h(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:h(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(ua,{type:`button`,className:`mt-5`,onClick:me,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),h(`chat.history.retry`)]})]})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:dn})]}):Tn?(0,$.jsxs)(`div`,{ref:Bt,className:Y(`relative flex flex-col h-full bg-background`,je&&`oc-chat-composer-swap-scope`),children:[Qe,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Le?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Le,children:(0,$.jsx)(`div`,{ref:Dt,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:LR,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:JR.map(e=>(0,$.jsx)(`div`,{className:`group w-full`,children:(0,$.jsx)(`div`,{className:`chat-message-column`,children:(0,$.jsxs)(`div`,{className:`space-y-2.5 px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.toolRows.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(dc,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,t.detailWidth)})]},`${e.id}-${t.id}`))}),(0,$.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(dc,{className:Y(`h-4 rounded-md`,e.textWidths[2])})]})]})})},e.id))})})}),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!je&&!Le?(0,$.jsx)(zR,{}):null,dn]})]}):Jt.length===0&&!Ce?(0,$.jsxs)(`div`,{className:`relative flex flex-col h-full bg-background`,children:[Qe,(0,$.jsx)(`div`,{className:Y(`relative min-h-0`,Le?`absolute inset-0 opacity-0 pointer-events-none`:`flex-1`),"aria-hidden":Le,children:Le?null:(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(Ux,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:dn}),(0,$.jsx)(Ex,{})]}):(0,$.jsxs)(`div`,{ref:Bt,className:Y(`relative flex flex-col h-full bg-background`,je&&`oc-chat-composer-swap-scope`),children:[d?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:d}):null,Qe,(0,$.jsx)(qR,{currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Le,isMobile:je,stickyUserHeader:A,directory:D,scrollRef:Dt,messageListRef:ze,pendingRevealWork:tn.pendingRevealWork,renderedMessages:tn.renderedMessages,isLoadingOlder:sn,sessionIsWorking:Ce,streamingMessageId:F,activeStreamingPhase:I,retryOverlay:Oe,handleMessageContentChange:Ot,getAnimationHandlers:kt,handleHistoryScroll:tn.handleHistoryScroll,handleHistoryUpwardIntent:an,onTimelineIsAtEndChange:Et,timelineFollowSuspended:xt,timelineHistoryAnchorToken:Ct,scrollToBottom:nn,sessionQuestions:Se,sessionPermissions:xe,isProgrammaticFollowActive:Rt,showLoadOlderButton:on,onLoadOlder:ln,turnIds:tn.turnIds,activeTurnId:tn.activeTurnId,onSelectTurn:fn,showPromptNavigator:mn,canLoadEarlierPrompts:pn,isLoadingOlderPrompts:sn,onLoadEarlierPrompts:ln},r),(0,$.jsxs)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot oc-mobile-composer-foot--overlay`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:[!je&&!Le?(0,$.jsx)(zR,{}):null,!Le&&Jt.length>0&&(je?(0,$.jsx)(Cg,{placement:`expanded`,visible:tn.showScrollToBottom,onClick:un.resumeToLatest}):(0,$.jsx)(Cg,{visible:tn.showScrollToBottom,onClick:un.resumeToLatest})),dn]}),(0,$.jsx)(Ex,{}),(0,$.jsx)(RL,{open:N,onOpenChange:P,sessionID:r??void 0,directory:D,onRevertMessage:u,onScrollToMessage:tn.scrollToMessage,onScrollByTurnOffset:un.scrollByTurnOffset,onResumeToLatest:nn,canLoadEarlier:tn.historySignals.canLoadEarlier,isLoadingEarlier:sn,onLoadEarlier:ln})]}):null});QR.displayName=`MemoizedChatContainerContent`;var $R=()=>{let e=(0,Q.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(dc,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(dc,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(dc,{className:`h-4 w-1/2 animate-none rounded-md`})]}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`flex h-full flex-col bg-background`,"data-session-view-loading":`true`,"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`mt-auto w-full pb-5 motion-safe:animate-pulse`,children:(0,$.jsxs)(`div`,{className:`chat-message-column space-y-6 px-4`,children:[t,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(dc,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(dc,{className:`h-4 w-3/5 animate-none rounded-md`})]}),(0,$.jsx)(dc,{className:`h-24 w-full animate-none rounded-xl`})]})})}),e[1]=n):n=e[1],n},ez=e=>{let t=(0,Q.c)(63),n,r;t[0]===e?(n=t[1],r=t[2]):({runtimeKey:r,...n}=e,t[0]=e,t[1]=n,t[2]=r);let i=Tg(),a=Ir(),o=ri(de(iz)),s;bb0:{if(!o.sessionId){s=null;break bb0}let e=o.directory??a,n;t[3]!==r||t[4]!==o.sessionId||t[5]!==e?(n={runtimeKey:r,sessionId:o.sessionId,directory:e},t[3]=r,t[4]=o.sessionId,t[5]=e,t[6]=n):n=t[6],s=n}let c=s,l;t[7]===c?l=t[8]:(l=cR(c),t[7]=c,t[8]=l);let u=l,d=u.key,f=cn()||se()||i===`mini-chat`?FR:PR,p;t[9]!==f||t[10]!==c||t[11]!==u?(p=()=>({activeIntent:u,cacheNeedsTrim:!1,cachedSessionViews:c?uR([],c,f,AR):[],pendingSessionView:null}),t[9]=f,t[10]=c,t[11]=u,t[12]=p):p=t[12];let[m,h]=Z.useState(p),g=Z.useRef(u),_=Z.useRef(d),{cacheNeedsTrim:v,cachedSessionViews:y,pendingSessionView:b}=m,x=b?.intent===u?b.entry:null,S;if(t[13]!==y||t[14]!==x){let e=[...y];x&&!e.some(e=>e.key===x.key)&&e.push(x),S=e.sort(az),t[13]=y,t[14]=x,t[15]=S}else S=t[15];let C=S,w;t[16]!==C||t[17]!==d?(w=fR(C,d),t[16]=C,t[17]=d,t[18]=w):w=t[18];let T=w,E=!!(d&&!T),D;t[19]!==f||t[20]!==u||t[21]!==d?(D=()=>{g.current=u,_.current=d,h(e=>pR(e,u,f))},t[19]=f,t[20]=u,t[21]=d,t[22]=D):D=t[22];let O;t[23]!==f||t[24]!==v||t[25]!==u||t[26]!==d?(O=[f,v,u,d],t[23]=f,t[24]=v,t[25]=u,t[26]=d,t[27]=O):O=t[27],at(D,O);let k=b?.intent??null,A,j;t[28]!==f||t[29]!==k?(A=()=>{k&&h(e=>hR(e,k,f))},j=[f,k],t[28]=f,t[29]=k,t[30]=A,t[31]=j):(A=t[30],j=t[31]),at(A,j);let M;t[32]!==T||t[33]!==u||t[34]!==d?(M=()=>{if(!u.selection||T)return;let e=u,t=d;return vc(()=>{g.current===e&&_.current===t&&h(n=>_.current===t?mR(n,e,g.current,AR):n)},{priority:`user-blocking`})},t[32]=T,t[33]=u,t[34]=d,t[35]=M):M=t[35];let N;t[36]!==T||t[37]!==f||t[38]!==u||t[39]!==d?(N=[T,f,u,d],t[36]=T,t[37]=f,t[38]=u,t[39]=d,t[40]=N):N=t[40],Z.useEffect(M,N);let P;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(P=(e,t)=>{let n=g.current,r=_.current;h(i=>{if(g.current!==n||_.current!==r||i.activeIntent!==n||e!==r)return i;let a=dR(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})},t[41]=P):P=t[41];let F=J(P),I=E||void 0,L;t[42]!==E||t[43]!==d?(L=E?(0,$.jsx)($R,{},d):null,t[42]=E,t[43]=d,t[44]=L):L=t[44];let R;if(t[45]!==T||t[46]!==F||t[47]!==n||t[48]!==C){let e;t[50]!==T||t[51]!==F||t[52]!==n?(e=e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:T===e.key?`visible`:`hidden`,children:(0,$.jsx)(QR,{...n,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:F})},e.key),t[50]=T,t[51]=F,t[52]=n,t[53]=e):e=t[53],R=C.map(e),t[45]=T,t[46]=F,t[47]=n,t[48]=C,t[49]=R}else R=t[49];let z;t[54]!==n||t[55]!==o.directory||t[56]!==d?(z=d?null:(0,$.jsx)(QR,{...n,sessionId:null,sessionDirectory:o.directory}),t[54]=n,t[55]=o.directory,t[56]=d,t[57]=z):z=t[57];let B;return t[58]!==I||t[59]!==L||t[60]!==R||t[61]!==z?(B=(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":I,children:[L,R,z]}),t[58]=I,t[59]=L,t[60]=R,t[61]=z,t[62]=B):B=t[62],B},tz=e=>{let t=(0,Q.c)(24),{host:n,runtimeKey:r,readOnly:i}=e,a=i!==void 0&&i,o;t[0]===n?o=t[1]:(o=Lx(n),t[0]=n,t[1]=o);let s=o,c;t[2]===n.onRevertMessage?c=t[3]:(c=n.onRevertMessage?{onRevertMessage:n.onRevertMessage}:{},t[2]=n.onRevertMessage,t[3]=c);let l;t[4]!==n.directory||t[5]!==n.sessionId||t[6]!==n.sessionSurface||t[7]!==c?(l={...n.sessionSurface,sessionId:n.sessionId,directory:n.directory,...c},t[4]=n.directory,t[5]=n.sessionId,t[6]=n.sessionSurface,t[7]=c,t[8]=l):l=t[8];let u=l,d=`host:${r}:${u.surfaceId}:${n.sessionId}`,f;t[9]!==n.assistantHistory||t[10]!==n.composerSurface||t[11]!==n.directory||t[12]!==n.onPendingUserMessagesMaterialized||t[13]!==n.onRevertMessage||t[14]!==n.pendingUserMessages||t[15]!==n.sessionId||t[16]!==n.warning||t[17]!==s||t[18]!==a||t[19]!==d?(f=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(QR,{autoOpenDraft:!1,readOnly:a,sessionId:n.sessionId,sessionDirectory:n.directory,sessionViewKey:d,composerSurface:n.composerSurface,hostedFeatures:s,assistantHistory:n.assistantHistory,pendingUserMessages:n.pendingUserMessages,onPendingUserMessagesMaterialized:n.onPendingUserMessagesMaterialized,onRevertMessage:n.onRevertMessage,warning:n.warning})}),t[9]=n.assistantHistory,t[10]=n.composerSurface,t[11]=n.directory,t[12]=n.onPendingUserMessagesMaterialized,t[13]=n.onRevertMessage,t[14]=n.pendingUserMessages,t[15]=n.sessionId,t[16]=n.warning,t[17]=s,t[18]=a,t[19]=d,t[20]=f):f=t[20];let p;return t[21]!==u||t[22]!==f?(p=(0,$.jsx)(Lh.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},nz=e=>{let t=(0,Q.c)(16),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({explicitSession:n,runtimeKey:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=Ir(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Ih({...n,directory:o}),t[4]=o,t[5]=n,t[6]=s):s=t[6];let c=s,l=`explicit:${i}:${n.viewKey}`,u;t[7]!==o||t[8]!==n.active||t[9]!==n.sessionId||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(`div`,{className:`h-full bg-background`,children:(0,$.jsx)(QR,{...r,active:n.active,sessionId:n.sessionId,sessionDirectory:o,sessionViewKey:l})}),t[7]=o,t[8]=n.active,t[9]=n.sessionId,t[10]=r,t[11]=l,t[12]=u):u=t[12];let d;return t[13]!==c||t[14]!==u?(d=(0,$.jsx)(Lh.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},rz=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(IR,a,a);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(tz,{...e,host:e.host,runtimeKey:n},r),t[0]=e,t[1]=n,t[2]=r,t[3]=i):i=t[3],i}if(e.explicitSession){let r=`${n}:${e.explicitSession.viewKey}`,i;return t[4]!==e.active||t[5]!==e.autoOpenDraft||t[6]!==e.explicitSession||t[7]!==e.readOnly||t[8]!==n||t[9]!==r?(i=(0,$.jsx)(nz,{autoOpenDraft:e.autoOpenDraft,readOnly:e.readOnly,active:e.active,explicitSession:e.explicitSession,runtimeKey:n},r),t[4]=e.active,t[5]=e.autoOpenDraft,t[6]=e.explicitSession,t[7]=e.readOnly,t[8]=n,t[9]=r,t[10]=i):i=t[10],i}let r;return t[11]!==e||t[12]!==n?(r=(0,$.jsx)(ez,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r};function iz(e){return{sessionId:e.currentSessionId,directory:e.currentSessionDirectory}}function az(e,t){return e.key.localeCompare(t.key)}export{al as $,Jg as A,Am as B,x_ as C,b_ as D,w_ as E,rg as F,Hp as G,sm as H,Nh as I,Fu as J,yd as K,Ph as L,Cg as M,_g as N,l_ as O,ng as P,il as Q,Lh as R,v_ as S,y_ as T,Xp as U,Tm as V,Zp as W,lu as X,ku as Y,uu as Z,zy as _,tI as a,iv as b,EP as c,sD as d,ol as et,oD as f,Vx as g,IE as h,PI as i,wg as j,qg as k,aA as l,QE as m,xR as n,fl as nt,PF as o,cD as p,Zu as q,LI as r,sl as rt,OF as s,rz as t,ul as tt,ok as u,Ny as v,S_ as w,q_ as x,My as y,Lm as z};
|