@openchambery/web 1.19.0-beta.36 → 1.19.0-beta.37
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/{AssistantView-DKkGbIaN.js → AssistantView-D5pDX9ES.js} +1 -1
- package/dist/assets/{ChatContainer-BV1_DKRK.js → ChatContainer-DBuXfy4g.js} +31 -31
- package/dist/assets/{ContextPanel-y2-b_Z2K.js → ContextPanel-RniXr46u.js} +3 -3
- package/dist/assets/{DiagramView-BQynaQK8.js → DiagramView-BwNKhbsZ.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-BLuEiJfe.js → MarkdownRendererImpl-wJgiOdis.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-DvQ7TyBM.js → MobileDetailNavigation-Dl6KVNYY.js} +1 -1
- package/dist/assets/{MobileShareBridge-CuVKbp4w.js → MobileShareBridge-BxR0pE_m.js} +1 -1
- package/dist/assets/{MobileSurface-Ckqf46Ht.js → MobileSurface-LhR2YNCl.js} +1 -1
- package/dist/assets/{MultiRunWindow-CryWGQm3.js → MultiRunWindow-Cgg9u8VX.js} +1 -1
- package/dist/assets/{SettingsView-4Qx32CM5.js → SettingsView-CBtDTnbu.js} +1 -1
- package/dist/assets/{SettingsWindow-5o4fZ7Mm.js → SettingsWindow-kBA9auJC.js} +1 -1
- package/dist/assets/{TerminalView-BcACDBI2.js → TerminalView-DhVu4pCB.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DPz8gn8_.js → ToolOutputDialog-cDDD9uCL.js} +1 -1
- package/dist/assets/{appThemeRegistry-5J_p1u_I.js → appThemeRegistry-staJMB2J.js} +2 -2
- package/dist/assets/{gitApi-iEiu2XFG.js → gitApi-CYDWoaIF.js} +1 -1
- package/dist/assets/{insertionBoundaries-0eRxJVW6.js → insertionBoundaries-DbiBrF9p.js} +1 -1
- package/dist/assets/{main-eSewAXup.js → main-Dkf8xb0G.js} +3 -3
- package/dist/assets/{main-BLhg2XWt.js → main-cvGY60fq.js} +2 -2
- package/dist/assets/{miniChat-D1-a2j3X.js → miniChat-Cz1ftAm8.js} +2 -2
- package/dist/assets/{mobile-Ci7TpzO5.js → mobile-C6Di4aP0.js} +2 -2
- package/dist/assets/{multirun-DSpk4Zg7.js → multirun-Dp0YasTz.js} +1 -1
- package/dist/assets/{projectMeta-BiPtYEsc.js → projectMeta-CVORtKSv.js} +1 -1
- package/dist/assets/{radio-DHDmOqeF.js → radio-BwGc_8vf.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-C_TDVAS5.js → renderElectronMiniChatApp-DovEohIn.js} +2 -2
- package/dist/assets/{renderMobileApp-CZkBh4ph.js → renderMobileApp-DKt9BrQO.js} +4 -4
- package/dist/assets/{runtimeConfig-D40WiKD4.js → runtimeConfig-ClXahK8y.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-N20BnvKg.js → runtimeEndpointReset-Wd0jJx7c.js} +1 -1
- package/dist/assets/{shikiHighlight-DSolaZz5.js → shikiHighlight-rNaL87ld.js} +1 -1
- package/dist/assets/{src-ILRsQd_W.css → src-Dc5_NNo2.css} +1 -1
- package/dist/assets/{useAppFontEffects-DovmEWUn.js → useAppFontEffects-BgJOiL9O.js} +2 -2
- package/dist/assets/{useDesktopWindowControlsLayout-uYmYg3ee.js → useDesktopWindowControlsLayout-BUMOckKt.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-lReAbPFb.js → useEffectiveDirectory-DmcTREeQ.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BKVdzZVI.js → useMobileNavigationStore-B5TOw3Mw.js} +1 -1
- package/dist/assets/{useSessionAutoCleanup-BkX_0XVu.js → useSessionAutoCleanup-CZdJsOtU.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-DFOYREuh.js → useWorkerHighlightedLines-DaZyFcgv.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +8 -1
- package/server/lib/notifications/apns-runtime.js +122 -28
- package/server/lib/notifications/apns-runtime.test.js +159 -0
- package/server/lib/relay/service.js +45 -3
- package/server/lib/relay/service.test.js +117 -0
|
@@ -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{A as t,E as n,P as r,T as i,U as a,g as o,t as s,w as c,y as l}from"./useUIStore-Wyu09VUF.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as W,ot as ee,pt as G,q as K,r as q,st as te,u as ne,ut as re,v as ie,wt as ae,x as oe,y as se,yt as ce,z as le}from"./persistence-aCOlo6ew.js";import{a as ue,i as de,r as fe,t as pe}from"./vendor-zustand-B4dlGEM2.js";import{c as me,d as he,f as ge,l as _e,nt as ve,rt as ye,tt as be,u as xe}from"./vendor-base-ui-CnHfUmDN.js";import{At as Se,Bt as Ce,Ct as we,Gt as Te,Ht as Ee,Jt as De,Kt as Oe,Nt as ke,Pt as Ae,Rt as je,St as Me,Ut as Ne,Wt as Pe,Yt as Fe,jt as Ie,kt as Le,n as Re,t as ze,zt as Be}from"./platform-ulFAVx1H.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as $e,d as et,i as tt,l as nt,n as J,o as rt,r as it,u as at}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ot,r as st,t as ct}from"./clipboard-mffeUZRt.js";import{i as lt,t as ut}from"./store-DcNAsu-r.js";import{$ as dt,$a as ft,$t as pt,A as mt,Aa as ht,Ai as gt,An as _t,Ar as vt,At as yt,Bi as bt,Bn as xt,Bo as St,Ca as Ct,Cn as wt,Cr as Tt,Ct as Et,D as Dt,Da as Ot,Di as kt,Dn as At,Do as jt,E as Mt,Ea as Nt,Ei as Pt,En as Ft,F as It,Fa as Lt,Fr as Rt,G as zt,Gi as Bt,Gr as Vt,Gt as Ht,H as Ut,Hi as Wt,Hn as Gt,I as Kt,Ia as qt,Ir as Jt,It as Yt,J as Xt,Ja as Zt,Ji as Qt,K as $t,Ki as en,Kr as tn,Kt as nn,La as rn,Li as an,Lo as on,Lr as sn,Lt as cn,M as ln,Ma as un,Mi as dn,Mr as fn,Mt as pn,N as mn,Ni as hn,Nt as gn,O as _n,Oa as vn,Oi as yn,On as bn,Oo as xn,Ot as Sn,P as Cn,Pi as wn,Q as Tn,Qa as En,Qr as Dn,Qt as On,R as kn,Ri as An,Rt as jn,S as Mn,Sa as Nn,Si as Pn,T as Fn,Ti as In,Ua as Ln,Ui as Rn,Ur as zn,Ut as Bn,Vi as Vn,Vn as Hn,Vr as Un,W as Wn,Wi as Gn,Wr as Kn,Wt as qn,X as Jn,Xa as Yn,Xi as Xn,Xr as Zn,Xt as Qn,Y as $n,Ya as er,Yi as tr,Yr as nr,Z as rr,Za as ir,Zi as ar,Zt as or,_a as sr,_n as cr,_t as lr,a as ur,aa as dr,ai as fr,an as pr,ar as mr,at as hr,ba as gr,bi as _r,br as vr,bt as yr,ca as br,cn as xr,co as Sr,cr as Cr,dn as wr,do as Tr,dt as Er,eo as Dr,et as Or,f as kr,fn as Ar,g as jr,gi as Mr,gn as Nr,gt as Pr,hi as Fr,hn as Ir,ht as Lr,i as Rr,ii as zr,in as Br,it as Vr,j as Hr,ji as Ur,jr as Wr,jt as Gr,k as Kr,ki as qr,kn as Jr,kr as Yr,kt as Xr,l as Zr,la as Qr,li as $r,ln as ei,m as ti,mi as ni,mn as ri,mt as ii,n as ai,nn as oi,no as si,nt as ci,oa as li,oi as ui,on as di,or as fi,pa as pi,pi as mi,pn as hi,pt as gi,q as _i,qa as vi,qi as yi,qn as bi,qr as xi,qt as Si,ri as Ci,rn as wi,rt as Ti,si as Ei,so as Di,sr as Oi,ta as ki,to as Ai,tt as ji,ua as Mi,ui as Ni,un as Pi,vi as Fi,vn as Ii,vt as Li,w as Ri,wa as zi,wi as Bi,wn as Vi,wt as Hi,x as Ui,xa as Wi,xi as Gi,ya as Ki,yi as qi,z as Ji,za as Yi,zi as Xi,zr as Zi}from"./useMobileNavigationStore-BKVdzZVI.js";import{a as Qi,i as $i,l as ea,n as ta,o as na,r as ra,s as ia,t as aa}from"./dialog-D8720PGH.js";import{n as oa,t as Y}from"./utils-CJdWZupK.js";import{t as sa}from"./AgentAvatar-Bt6ACcoy.js";import{n as X}from"./Icon-Bs6GJIoO.js";import{t as ca}from"./button-DfF088a8.js";import{E as la,n as ua}from"./gitApi-iEiu2XFG.js";import{A as da,B as fa,C as pa,G as ma,J as ha,K as ga,M as _a,O as va,S as ya,T as ba,W as xa,a as Sa,b as Ca,d as wa,g as Ta,h as Ea,i as Da,j as Oa,k as ka,n as Aa,o as ja,p as Ma,s as Na,u as Pa,v as Fa,w as Ia,x as La,z as Ra}from"./projectMeta-BiPtYEsc.js";import{t as za}from"./input-Ca2tUhgN.js";import{i as Ba,n as Va,t as Ha}from"./tooltip-GC3dg3gO.js";import{n as Ua,t as Wa}from"./useThemeSystem-DMzWVJaW.js";import{A as Ga,B as Ka,C as qa,K as Ja,M as Ya,P as Xa,_ as Za,a as Qa,f as $a,g as eo,h as to,i as no,m as ro,o as io,p as ao,r as oo,t as so,v as co,w as lo,y as uo}from"./radio-DHDmOqeF.js";import{i as fo,t as po}from"./OverlayScrollbar-VZKKu-cu.js";import{_ as mo,a as ho,d as go,f as _o,g as vo,h as yo,i as bo,l as xo,m as So,n as Co,u as wo,v as To,x as Eo}from"./markdownTheme-DidS-jC5.js";import{n as Do,r as Oo,t as ko}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Ao,B as jo,C as Mo,D as No,E as Po,F as Fo,H as Io,I as Lo,L as Ro,M as zo,O as Bo,P as Vo,R as Ho,S as Uo,T as Wo,V as Go,a as Ko,b as qo,c as Jo,f as Yo,i as Xo,j as Zo,k as Qo,l as $o,m as es,n as ts,o as ns,p as rs,r as is,s as as,t as os,u as ss,w as cs,x as ls,z as us}from"./insertionBoundaries-0eRxJVW6.js";import{A as ds,C as fs,D as ps,E as ms,M as hs,N as gs,O as _s,P as vs,S as ys,T as bs,_ as xs,a as Ss,b as Cs,c as ws,d as Ts,f as Es,g as Ds,h as Os,i as ks,j as As,k as js,m as Ms,p as Ns,r as Ps,t as Fs,u as Is,v as Ls,w as Rs,x as zs,y as Bs}from"./appThemeRegistry-5J_p1u_I.js";import{_ as Vs,a as Hs,c as Us,g as Ws,l as Gs,o as Ks,t as qs,v as Js,y as Ys}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Xs,n as Zs,o as Qs,s as $s,t as ec}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as tc,n as nc,t as rc}from"./url-BQHM4bC4.js";import{_ as ic,l as ac,m as oc,p as sc,s as cc}from"./markdown-worker-9Sn2jsDp.js";import{n as lc}from"./useEffectiveDirectory-lReAbPFb.js";import{a as uc,c as dc,d as fc,f as pc,i as mc,l as hc,n as gc,r as _c,s as vc,t as yc}from"./FadeInOnReveal-BpIMrqet.js";import{A as bc,C as xc,D as Sc,E as Cc,M as wc,O as Tc,S as Ec,T as Dc,a as Oc,b as kc,c as Ac,g as jc,h as Mc,i as Nc,j as Pc,k as Fc,o as Ic,p as Lc,r as Rc,s as zc,t as Bc,v as Vc,w as Hc,x as Uc,y as Wc}from"./useWorkerHighlightedLines-DFOYREuh.js";import{t as Gc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Kc}from"./sortable-tabs-strip-D2D5nqti.js";import{n as qc,t as Jc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as Yc,u as Xc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as Zc,t as Qc}from"./vendor-framer-motion-DFy_BSVd.js";import{t as $c}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(ye(),1),Q=We(),$=ve(),el=e(be(),1),tl=`openchamber:close-embedded-session-chat`,nl=`openchamber:embedded-visibility`,rl=`openchamber:embedded-visibility-request`,il=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,al=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),ol=(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()},sl=(e,t,n,r,i,a)=>{let o=al(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=ol(n,r,i,a);return e.set(t,{signature:o,src:c}),c},cl=null,ll=()=>{if(cl!==null)return cl;if(typeof window>`u`)return cl=!1,!1;try{return cl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,cl}catch{return cl=!1,!1}},ul=()=>{if(!ll())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},dl=Ve(`OpenChamberMedia`);function fl(){return Re()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function pl(e){if(!fl())return null;let t=await dl.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 ml=(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=gi([...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)},hl=new Map,gl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,_l=async e=>{let t=As(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=hl.get(n);return r===void 0&&(r=await Io(e.iconName,t)??``,hl.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},vl=[],yl=e=>void 0,bl=()=>void 0;function xl(e){let t=e.enabled&&Ls(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)(Bs()),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??yl),x=J(e.onAutocompleteDismiss??bl),S=J(e=>{typeof document>`u`||Ms(document.documentElement,e)});Es.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:De(e.text,e.attachments.map(e=>e.filename)),chipRanges:Ds(fs(e.text,e.chipHighlights),As(`--primary`)),appearance:typeof document>`u`?`dark`:ms(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:bs(e.agentName||void 0),agentIdenticon:ps(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 gs(e,!0),()=>{gs(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,Es.rememberText(i.text),Es.retain(e,i);let a=Ts();return()=>{n.current=null,a(),Es.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=ma(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Cs().update(a),i)return js(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},Cs().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let w=Os(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:[]},Es.rememberState(n.current)),Cs().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await _s(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},Es.rememberState(n.current)),Cs().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,w]);let T=e.autocompleteRows??vl,E=e.autocompleteOpen===!0,D=e.autocompleteHighlightedIndex??0,O=gl(T,E,D);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(E&&T.length>0)){let e=Bs();ys(l.current,e)||(l.current=e,n.current&&(n.current={...n.current,autocomplete:e},Es.rememberState(n.current)),Cs().update({autocomplete:e}));return}return _l(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};ys(l.current,r)||(l.current=r,n.current&&(n.current={...n.current,autocomplete:r},Es.rememberState(n.current)),Cs().update({autocomplete:r}))}),()=>{e=!0}},[t,O]);let k=t?fs(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&&Rs(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,Es.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=hs({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=xs(c,s,u,{caret:e.caret});d&&Cs().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 Sl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Cl=1e4,wl=15e3,Tl=3e4,El=3e4,Dl=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;get isConnected(){return this.socket?.readyState===WebSocket.OPEN}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(!this.isConnected){if(this.connectPromise){await this.connectPromise;return}try{await a()}catch{}this.connectPromise=new Promise((e,t)=>{let n=!1,i;try{let e=r().websocket(`/api/dictation/ws`);i=Me(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!n){n=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},Cl);i.onopen=()=>{},i.onmessage=t=>{let r;try{r=JSON.parse(String(t.data))}catch{return}if(!n&&r.type===`ready`){n=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(r)},i.onerror=()=>{window.setTimeout(()=>{n||(n=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!n){n=!0,clearTimeout(a),this.connectPromise=null;let r=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${r}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t,n){return await this.ensureConnected(),this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((r,i)=>{let a=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation start timed out`))},wl);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`))},El),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=Sl(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)}}},Tl))}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`,()=>{Dl.cancelAllForRuntimeSwitch()});var Ol=128,kl=`audio/pcm;rate=16000;bits=16`,Al=()=>new Promise(e=>setTimeout(e,0)),jl=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Ml=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??kl,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??jl}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<Ol;){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 Al()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Nl=16e3,Pl=Nl,Fl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Il=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Ll=(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]=Il(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]=Il(e[i]*(1-s)+e[o]*s)}return a},Rl=(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},zl=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)},Bl=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Vl=e=>{if(e)try{e.disconnect()}catch{}},Hl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Fl()!==null;function Ul(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=Bl(),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=Fl();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(Kl);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=Ll(a,n.sampleRate,Nl);for(t.pending=Rl(t.pending,c);t.pending.length>=Pl;){let e=t.pending.slice(0,Pl);t.pending=t.pending.slice(Pl),i.current(zl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Gl);try{await n.close()}catch{}throw l.current=Bl(),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{}Vl(e.processor),Vl(e.source),Vl(e.gain),e.stream&&e.stream.getTracks().forEach(Wl);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(zl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Bl())},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 Wl(e){try{e.stop()}catch{}}function Gl(e){try{e.stop()}catch{}}function Kl(){}var ql=1e3,Jl=e=>e instanceof Error?e:Error(String(e)),Yl=()=>{let e=Qr.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 Xl(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 Ml({client:Dl,getStartOptions:Yl});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},ql)},[]),C=(0,Z.useCallback)(e=>{let t=Jl(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)(()=>Dl.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Dl.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Ul({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 Zl=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},Ql=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ua(),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},$l=e=>{let t=Qr(e=>e.sttLocalModel),[n,r]=Z.useState(null);return Z.useEffect(()=>{if(!e){r(null);return}let n=!1,i=async()=>{try{let e=await V(`/api/dictation/status`,{query:{provider:`local`,localModel:t}});if(!e.ok||n)return;let i=await e.json(),a=Array.isArray(i?.models)?i.models.find(e=>e.id===t):null;n||r(typeof a?.downloadProgress==`number`?a.downloadProgress:null)}catch{}};i();let a=setInterval(()=>{i()},2e3);return()=>{n=!0,clearInterval(a)}},[e,t]),e?n:null},eu=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:c,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=ot(),{currentTheme:v}=Ua(),y=Qr(tu),b=s(nu),x;t[0]===b?x=t[1]:(x=Ya(Xa(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(ru),w=Z.useRef(null),T=Z.useRef(u),E=Z.useRef(d),D,O;t[2]!==u||t[3]!==d?(D=()=>{T.current=u,E.current=d},O=[u,d],t[2]=u,t[3]=d,t[4]=D,t[5]=O):(D=t[4],O=t[5]),Z.useEffect(D,O);let k;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(k={onTranscript:e=>{let t=w.current;w.current=null,t===`send`?E.current(e):T.current(e)}},t[6]=k):k=t[6];let{status:A,partialTranscript:j,volume:M,duration:N,error:P,errorReason:F,startDictation:I,confirmDictation:L,cancelDictation:R,retryFailedDictation:z,acceptPartialTranscript:B,discardFailedDictation:V}=Xl(k),H=A===`recording`&&F===`model_download_in_progress`,U=$l(H),W=Z.useRef(A),ee,G;t[7]===A?(ee=t[8],G=t[9]):(ee=()=>{W.current=A},G=[A],t[7]=A,t[8]=ee,t[9]=G),Z.useEffect(ee,G);let K,q;t[10]!==f||t[11]!==A?(K=()=>{f?.(A!==`idle`)},q=[A,f],t[10]=f,t[11]=A,t[12]=K,t[13]=q):(K=t[12],q=t[13]),Z.useLayoutEffect(K,q);let te,ne;t[14]!==L||t[15]!==I?(te=()=>{let e=()=>{W.current===`idle`?I():W.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[I,L],t[14]=L,t[15]=I,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==R||t[19]!==L||t[20]!==A?(re=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[A,L,R],t[18]=R,t[19]=L,t[20]=A,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=A!==`idle`,de=Z.useRef(p),fe,pe;t[23]===p?(fe=t[24],pe=t[25]):(fe=()=>{de.current=p},pe=[p],t[23]=p,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]!==P||t[29]!==ue||t[30]!==j||t[31]!==A?(ge=[ue,j,A,P],t[28]=P,t[29]=ue,t[30]=j,t[31]=A,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),!C||!y)return null;let xe=A!==`idle`,Se;t[38]===L?Se=t[39]:(Se=e=>{w.current=e,L()},t[38]=L,t[39]=Se);let Ce=Se,we;t[40]===z?we=t[41]:(we=()=>{w.current=`insert`,z()},t[40]=z,t[41]=we);let Te=we,Ee;bb0:{if(A===`failed`){Ee=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),Ee=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:iu,onPointerDownCapture:au},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==g||t[56]!==I||t[57]!==_?(Ae=g?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{I()},disabled:l||xe,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=xe,t[55]=g,t[56]=I,t[57]=_,t[58]=Ae):Ae=t[58];let je;t[59]!==B||t[60]!==R||t[61]!==Ce||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==c||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(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:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(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(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(Ql,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:De}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(Ql,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:Zl(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`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:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:c})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=Ce,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=H,t[73]=j,t[74]=De,t[75]=n,t[76]=Te,t[77]=c,t[78]=A,t[79]=_,t[80]=h,t[81]=M,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 tu(e){return e.dictationEnabled}function nu(e){return e.shortcutOverrides}function ru(){return!d()&&Hl()}function iu(e){return e.preventDefault()}function au(e){e.pointerType===`touch`&&e.preventDefault()}var ou=2e3,su=ue((e,t)=>({pending:!1,expiresAt:null,arm:(t=ou)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),cu=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}},lu=15e3,uu=100,du=new Map,fu=new Map,pu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,mu=e=>{let t=pu(e),n=e.now??Date.now(),r=fu.get(t);if(r&&n-r.loadedAt<lu)return Promise.resolve(r.sessions);let i=du.get(t);if(i)return i;let a=e.request().then(e=>{for(fu.delete(t);fu.size>=uu;){let e=fu.keys().next().value;if(typeof e!=`string`)break;fu.delete(e)}return fu.set(t,{loadedAt:Date.now(),sessions:e}),e});return du.set(t,a),a.then(()=>{du.get(t)===a&&du.delete(t)},()=>{du.get(t)===a&&du.delete(t)}),a},hu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),gu=(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(hu)},_u=30;function vu(e){return e===`busy`||e===`retry`}var yu=new Map;function bu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function xu(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 Su(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${xu(e.error)}`)}function Cu(e,t){let n=zi();if(!n)return!1;let r=n.getTranscript(un(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>Xi()}function wu(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Tu(e,t,n){let r=[...e.getState().session],i=rn.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Eu(){let e=cr(),t=Ht(),n=Bn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=zi();if(!r||!t)return bu({kind:`unknown`,loadedTurns:0},!1);let i=un(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return bu(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}};bn(a,t),Yt(r,t),r.setState(a);for(let n of t)Ot(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=yu.get(t);if(n)return yu.delete(t),yu.set(t,n),n;let r=new Set;for(yu.set(t,r);yu.size>_u;){let e=yu.keys().next().value;if(!e)break;let t=[...yu.get(e)??[]];yu.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=Jr(a.getState()),u=an(),d=_t({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),An()){let e=new Set([r,...c,...l]),t=(zi()?.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:Cu(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 Nn(a,r):await Wi(a,r)}catch{return}if(i?.isStale?.())return;let u=zi()?.getTranscript(un(a,r));fr({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await Ni({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 St();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=ke.getScopedSdkClient(o);c(t,o);let d=r(t,o);return cu.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=zi(),i=un(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=rn.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&Vn(o,t)){fr({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=wu({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await li(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Su(e,`session.get`),e});if(n.data&&!e()){let r=dr(n.data);e()||Tu(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let a=r||e;if(!t||!a)return;let o=n.ensureChild(a,{bootstrap:!1}),s=ke.getScopedSdkClient(a),c=await mu({runtimeKey:i(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return Su(e,`session.children`),e.data??[]}});o.setState(e=>{let n=gu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;gr(un(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;gr(un(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;gr(un(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await St();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(vu(o))throw Error(`refresh transcript busy`);try{await vn(i,t),fr({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 Du=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Ou=e=>e===`original`||e===`modified`,ku=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Au=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Du(t.source))return null;let n=ku(t.startLine),r=ku(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:Ou(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()}},ju=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(Au).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Mu=ue()(fe(de((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:ju(e.drafts)}}),{name:`inline-comment-draft-store`}));function Nu(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 Pu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Nu).join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-cDDD9uCL.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-Wyu09VUF.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-aCOlo6ew.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-mffeUZRt.js","assets/store-DcNAsu-r.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/dialog-D8720PGH.js","assets/utils-CJdWZupK.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-Bs6GJIoO.js","assets/button-DfF088a8.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-DidS-jC5.js","assets/vendor-pierre-diffs-BenIz2TM.js","assets/vendor-hast-util-to-html-B0p1k5Xa.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-DpDied8H.js","assets/appThemeRegistry-staJMB2J.js","assets/platform-ulFAVx1H.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-B5TOw3Mw.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-DxZsjSPQ.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-9Sn2jsDp.js","assets/useEffectiveDirectory-DmcTREeQ.js","assets/useWorkerHighlightedLines-DaZyFcgv.js","assets/tooltip-GC3dg3gO.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T as i,U as a,g as o,t as s,w as c,y as l}from"./useUIStore-Wyu09VUF.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as W,ot as ee,pt as G,q as K,r as q,st as te,u as ne,ut as re,v as ie,wt as ae,x as oe,y as se,yt as ce,z as le}from"./persistence-aCOlo6ew.js";import{a as ue,i as de,r as fe,t as pe}from"./vendor-zustand-B4dlGEM2.js";import{c as me,d as he,f as ge,l as _e,nt as ve,rt as ye,tt as be,u as xe}from"./vendor-base-ui-CnHfUmDN.js";import{At as Se,Bt as Ce,Ct as we,Gt as Te,Ht as Ee,Jt as De,Kt as Oe,Nt as ke,Pt as Ae,Rt as je,St as Me,Ut as Ne,Wt as Pe,Yt as Fe,jt as Ie,kt as Le,n as Re,t as ze,zt as Be}from"./platform-ulFAVx1H.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as $e,d as et,i as tt,l as nt,n as J,o as rt,r as it,u as at}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ot,r as st,t as ct}from"./clipboard-mffeUZRt.js";import{i as lt,t as ut}from"./store-DcNAsu-r.js";import{$ as dt,$a as ft,$t as pt,A as mt,Aa as ht,Ai as gt,An as _t,Ar as vt,At as yt,Bi as bt,Bn as xt,Bo as St,Ca as Ct,Cn as wt,Cr as Tt,Ct as Et,D as Dt,Da as Ot,Di as kt,Dn as At,Do as jt,E as Mt,Ea as Nt,Ei as Pt,En as Ft,F as It,Fa as Lt,Fr as Rt,G as zt,Gi as Bt,Gr as Vt,Gt as Ht,H as Ut,Hi as Wt,Hn as Gt,I as Kt,Ia as qt,Ir as Jt,It as Yt,J as Xt,Ja as Zt,Ji as Qt,K as $t,Ki as en,Kr as tn,Kt as nn,La as rn,Li as an,Lo as on,Lr as sn,Lt as cn,M as ln,Ma as un,Mi as dn,Mr as fn,Mt as pn,N as mn,Ni as hn,Nt as gn,O as _n,Oa as vn,Oi as yn,On as bn,Oo as xn,Ot as Sn,P as Cn,Pi as wn,Q as Tn,Qa as En,Qr as Dn,Qt as On,R as kn,Ri as An,Rt as jn,S as Mn,Sa as Nn,Si as Pn,T as Fn,Ti as In,Ua as Ln,Ui as Rn,Ur as zn,Ut as Bn,Vi as Vn,Vn as Hn,Vr as Un,W as Wn,Wi as Gn,Wr as Kn,Wt as qn,X as Jn,Xa as Yn,Xi as Xn,Xr as Zn,Xt as Qn,Y as $n,Ya as er,Yi as tr,Yr as nr,Z as rr,Za as ir,Zi as ar,Zt as or,_a as sr,_n as cr,_t as lr,a as ur,aa as dr,ai as fr,an as pr,ar as mr,at as hr,ba as gr,bi as _r,br as vr,bt as yr,ca as br,cn as xr,co as Sr,cr as Cr,dn as wr,do as Tr,dt as Er,eo as Dr,et as Or,f as kr,fn as Ar,g as jr,gi as Mr,gn as Nr,gt as Pr,hi as Fr,hn as Ir,ht as Lr,i as Rr,ii as zr,in as Br,it as Vr,j as Hr,ji as Ur,jr as Wr,jt as Gr,k as Kr,ki as qr,kn as Jr,kr as Yr,kt as Xr,l as Zr,la as Qr,li as $r,ln as ei,m as ti,mi as ni,mn as ri,mt as ii,n as ai,nn as oi,no as si,nt as ci,oa as li,oi as ui,on as di,or as fi,pa as pi,pi as mi,pn as hi,pt as gi,q as _i,qa as vi,qi as yi,qn as bi,qr as xi,qt as Si,ri as Ci,rn as wi,rt as Ti,si as Ei,so as Di,sr as Oi,ta as ki,to as Ai,tt as ji,ua as Mi,ui as Ni,un as Pi,vi as Fi,vn as Ii,vt as Li,w as Ri,wa as zi,wi as Bi,wn as Vi,wt as Hi,x as Ui,xa as Wi,xi as Gi,ya as Ki,yi as qi,z as Ji,za as Yi,zi as Xi,zr as Zi}from"./useMobileNavigationStore-B5TOw3Mw.js";import{a as Qi,i as $i,l as ea,n as ta,o as na,r as ra,s as ia,t as aa}from"./dialog-D8720PGH.js";import{n as oa,t as Y}from"./utils-CJdWZupK.js";import{t as sa}from"./AgentAvatar-Bt6ACcoy.js";import{n as X}from"./Icon-Bs6GJIoO.js";import{t as ca}from"./button-DfF088a8.js";import{E as la,n as ua}from"./gitApi-CYDWoaIF.js";import{A as da,B as fa,C as pa,G as ma,J as ha,K as ga,M as _a,O as va,S as ya,T as ba,W as xa,a as Sa,b as Ca,d as wa,g as Ta,h as Ea,i as Da,j as Oa,k as ka,n as Aa,o as ja,p as Ma,s as Na,u as Pa,v as Fa,w as Ia,x as La,z as Ra}from"./projectMeta-CVORtKSv.js";import{t as za}from"./input-Ca2tUhgN.js";import{i as Ba,n as Va,t as Ha}from"./tooltip-GC3dg3gO.js";import{n as Ua,t as Wa}from"./useThemeSystem-DMzWVJaW.js";import{A as Ga,B as Ka,C as qa,K as Ja,M as Ya,P as Xa,_ as Za,a as Qa,f as $a,g as eo,h as to,i as no,m as ro,o as io,p as ao,r as oo,t as so,v as co,w as lo,y as uo}from"./radio-BwGc_8vf.js";import{i as fo,t as po}from"./OverlayScrollbar-VZKKu-cu.js";import{_ as mo,a as ho,d as go,f as _o,g as vo,h as yo,i as bo,l as xo,m as So,n as Co,u as wo,v as To,x as Eo}from"./markdownTheme-DidS-jC5.js";import{n as Do,r as Oo,t as ko}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Ao,B as jo,C as Mo,D as No,E as Po,F as Fo,H as Io,I as Lo,L as Ro,M as zo,O as Bo,P as Vo,R as Ho,S as Uo,T as Wo,V as Go,a as Ko,b as qo,c as Jo,f as Yo,i as Xo,j as Zo,k as Qo,l as $o,m as es,n as ts,o as ns,p as rs,r as is,s as as,t as os,u as ss,w as cs,x as ls,z as us}from"./insertionBoundaries-DbiBrF9p.js";import{A as ds,C as fs,D as ps,E as ms,M as hs,N as gs,O as _s,P as vs,S as ys,T as bs,_ as xs,a as Ss,b as Cs,c as ws,d as Ts,f as Es,g as Ds,h as Os,i as ks,j as As,k as js,m as Ms,p as Ns,r as Ps,t as Fs,u as Is,v as Ls,w as Rs,x as zs,y as Bs}from"./appThemeRegistry-staJMB2J.js";import{_ as Vs,a as Hs,c as Us,g as Ws,l as Gs,o as Ks,t as qs,v as Js,y as Ys}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Xs,n as Zs,o as Qs,s as $s,t as ec}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as tc,n as nc,t as rc}from"./url-BQHM4bC4.js";import{_ as ic,l as ac,m as oc,p as sc,s as cc}from"./markdown-worker-9Sn2jsDp.js";import{n as lc}from"./useEffectiveDirectory-DmcTREeQ.js";import{a as uc,c as dc,d as fc,f as pc,i as mc,l as hc,n as gc,r as _c,s as vc,t as yc}from"./FadeInOnReveal-BpIMrqet.js";import{A as bc,C as xc,D as Sc,E as Cc,M as wc,O as Tc,S as Ec,T as Dc,a as Oc,b as kc,c as Ac,g as jc,h as Mc,i as Nc,j as Pc,k as Fc,o as Ic,p as Lc,r as Rc,s as zc,t as Bc,v as Vc,w as Hc,x as Uc,y as Wc}from"./useWorkerHighlightedLines-DaZyFcgv.js";import{t as Gc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Kc}from"./sortable-tabs-strip-D2D5nqti.js";import{n as qc,t as Jc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as Yc,u as Xc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as Zc,t as Qc}from"./vendor-framer-motion-DFy_BSVd.js";import{t as $c}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(ye(),1),Q=We(),$=ve(),el=e(be(),1),tl=`openchamber:close-embedded-session-chat`,nl=`openchamber:embedded-visibility`,rl=`openchamber:embedded-visibility-request`,il=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,al=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),ol=(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()},sl=(e,t,n,r,i,a)=>{let o=al(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=ol(n,r,i,a);return e.set(t,{signature:o,src:c}),c},cl=null,ll=()=>{if(cl!==null)return cl;if(typeof window>`u`)return cl=!1,!1;try{return cl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,cl}catch{return cl=!1,!1}},ul=()=>{if(!ll())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},dl=Ve(`OpenChamberMedia`);function fl(){return Re()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function pl(e){if(!fl())return null;let t=await dl.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 ml=(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=gi([...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)},hl=new Map,gl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,_l=async e=>{let t=As(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=hl.get(n);return r===void 0&&(r=await Io(e.iconName,t)??``,hl.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},vl=[],yl=e=>void 0,bl=()=>void 0;function xl(e){let t=e.enabled&&Ls(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)(Bs()),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??yl),x=J(e.onAutocompleteDismiss??bl),S=J(e=>{typeof document>`u`||Ms(document.documentElement,e)});Es.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:De(e.text,e.attachments.map(e=>e.filename)),chipRanges:Ds(fs(e.text,e.chipHighlights),As(`--primary`)),appearance:typeof document>`u`?`dark`:ms(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:bs(e.agentName||void 0),agentIdenticon:ps(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 gs(e,!0),()=>{gs(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,Es.rememberText(i.text),Es.retain(e,i);let a=Ts();return()=>{n.current=null,a(),Es.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=ma(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Cs().update(a),i)return js(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},Cs().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let w=Os(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:[]},Es.rememberState(n.current)),Cs().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await _s(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},Es.rememberState(n.current)),Cs().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,w]);let T=e.autocompleteRows??vl,E=e.autocompleteOpen===!0,D=e.autocompleteHighlightedIndex??0,O=gl(T,E,D);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(E&&T.length>0)){let e=Bs();ys(l.current,e)||(l.current=e,n.current&&(n.current={...n.current,autocomplete:e},Es.rememberState(n.current)),Cs().update({autocomplete:e}));return}return _l(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};ys(l.current,r)||(l.current=r,n.current&&(n.current={...n.current,autocomplete:r},Es.rememberState(n.current)),Cs().update({autocomplete:r}))}),()=>{e=!0}},[t,O]);let k=t?fs(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&&Rs(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,Es.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=hs({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=xs(c,s,u,{caret:e.caret});d&&Cs().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 Sl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Cl=1e4,wl=15e3,Tl=3e4,El=3e4,Dl=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;get isConnected(){return this.socket?.readyState===WebSocket.OPEN}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(!this.isConnected){if(this.connectPromise){await this.connectPromise;return}try{await a()}catch{}this.connectPromise=new Promise((e,t)=>{let n=!1,i;try{let e=r().websocket(`/api/dictation/ws`);i=Me(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!n){n=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},Cl);i.onopen=()=>{},i.onmessage=t=>{let r;try{r=JSON.parse(String(t.data))}catch{return}if(!n&&r.type===`ready`){n=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(r)},i.onerror=()=>{window.setTimeout(()=>{n||(n=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!n){n=!0,clearTimeout(a),this.connectPromise=null;let r=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${r}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t,n){return await this.ensureConnected(),this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((r,i)=>{let a=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation start timed out`))},wl);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`))},El),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=Sl(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)}}},Tl))}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`,()=>{Dl.cancelAllForRuntimeSwitch()});var Ol=128,kl=`audio/pcm;rate=16000;bits=16`,Al=()=>new Promise(e=>setTimeout(e,0)),jl=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Ml=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??kl,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??jl}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<Ol;){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 Al()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Nl=16e3,Pl=Nl,Fl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Il=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Ll=(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]=Il(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]=Il(e[i]*(1-s)+e[o]*s)}return a},Rl=(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},zl=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)},Bl=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Vl=e=>{if(e)try{e.disconnect()}catch{}},Hl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Fl()!==null;function Ul(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=Bl(),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=Fl();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(Kl);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=Ll(a,n.sampleRate,Nl);for(t.pending=Rl(t.pending,c);t.pending.length>=Pl;){let e=t.pending.slice(0,Pl);t.pending=t.pending.slice(Pl),i.current(zl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Gl);try{await n.close()}catch{}throw l.current=Bl(),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{}Vl(e.processor),Vl(e.source),Vl(e.gain),e.stream&&e.stream.getTracks().forEach(Wl);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(zl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Bl())},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 Wl(e){try{e.stop()}catch{}}function Gl(e){try{e.stop()}catch{}}function Kl(){}var ql=1e3,Jl=e=>e instanceof Error?e:Error(String(e)),Yl=()=>{let e=Qr.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 Xl(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 Ml({client:Dl,getStartOptions:Yl});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},ql)},[]),C=(0,Z.useCallback)(e=>{let t=Jl(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)(()=>Dl.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Dl.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Ul({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 Zl=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},Ql=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ua(),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},$l=e=>{let t=Qr(e=>e.sttLocalModel),[n,r]=Z.useState(null);return Z.useEffect(()=>{if(!e){r(null);return}let n=!1,i=async()=>{try{let e=await V(`/api/dictation/status`,{query:{provider:`local`,localModel:t}});if(!e.ok||n)return;let i=await e.json(),a=Array.isArray(i?.models)?i.models.find(e=>e.id===t):null;n||r(typeof a?.downloadProgress==`number`?a.downloadProgress:null)}catch{}};i();let a=setInterval(()=>{i()},2e3);return()=>{n=!0,clearInterval(a)}},[e,t]),e?n:null},eu=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:c,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=ot(),{currentTheme:v}=Ua(),y=Qr(tu),b=s(nu),x;t[0]===b?x=t[1]:(x=Ya(Xa(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(ru),w=Z.useRef(null),T=Z.useRef(u),E=Z.useRef(d),D,O;t[2]!==u||t[3]!==d?(D=()=>{T.current=u,E.current=d},O=[u,d],t[2]=u,t[3]=d,t[4]=D,t[5]=O):(D=t[4],O=t[5]),Z.useEffect(D,O);let k;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(k={onTranscript:e=>{let t=w.current;w.current=null,t===`send`?E.current(e):T.current(e)}},t[6]=k):k=t[6];let{status:A,partialTranscript:j,volume:M,duration:N,error:P,errorReason:F,startDictation:I,confirmDictation:L,cancelDictation:R,retryFailedDictation:z,acceptPartialTranscript:B,discardFailedDictation:V}=Xl(k),H=A===`recording`&&F===`model_download_in_progress`,U=$l(H),W=Z.useRef(A),ee,G;t[7]===A?(ee=t[8],G=t[9]):(ee=()=>{W.current=A},G=[A],t[7]=A,t[8]=ee,t[9]=G),Z.useEffect(ee,G);let K,q;t[10]!==f||t[11]!==A?(K=()=>{f?.(A!==`idle`)},q=[A,f],t[10]=f,t[11]=A,t[12]=K,t[13]=q):(K=t[12],q=t[13]),Z.useLayoutEffect(K,q);let te,ne;t[14]!==L||t[15]!==I?(te=()=>{let e=()=>{W.current===`idle`?I():W.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[I,L],t[14]=L,t[15]=I,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==R||t[19]!==L||t[20]!==A?(re=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[A,L,R],t[18]=R,t[19]=L,t[20]=A,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=A!==`idle`,de=Z.useRef(p),fe,pe;t[23]===p?(fe=t[24],pe=t[25]):(fe=()=>{de.current=p},pe=[p],t[23]=p,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]!==P||t[29]!==ue||t[30]!==j||t[31]!==A?(ge=[ue,j,A,P],t[28]=P,t[29]=ue,t[30]=j,t[31]=A,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),!C||!y)return null;let xe=A!==`idle`,Se;t[38]===L?Se=t[39]:(Se=e=>{w.current=e,L()},t[38]=L,t[39]=Se);let Ce=Se,we;t[40]===z?we=t[41]:(we=()=>{w.current=`insert`,z()},t[40]=z,t[41]=we);let Te=we,Ee;bb0:{if(A===`failed`){Ee=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),Ee=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:iu,onPointerDownCapture:au},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==g||t[56]!==I||t[57]!==_?(Ae=g?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{I()},disabled:l||xe,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=xe,t[55]=g,t[56]=I,t[57]=_,t[58]=Ae):Ae=t[58];let je;t[59]!==B||t[60]!==R||t[61]!==Ce||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==c||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(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:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(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(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(Ql,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:De}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(Ql,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:Zl(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`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:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:c})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=Ce,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=H,t[73]=j,t[74]=De,t[75]=n,t[76]=Te,t[77]=c,t[78]=A,t[79]=_,t[80]=h,t[81]=M,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 tu(e){return e.dictationEnabled}function nu(e){return e.shortcutOverrides}function ru(){return!d()&&Hl()}function iu(e){return e.preventDefault()}function au(e){e.pointerType===`touch`&&e.preventDefault()}var ou=2e3,su=ue((e,t)=>({pending:!1,expiresAt:null,arm:(t=ou)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),cu=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}},lu=15e3,uu=100,du=new Map,fu=new Map,pu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,mu=e=>{let t=pu(e),n=e.now??Date.now(),r=fu.get(t);if(r&&n-r.loadedAt<lu)return Promise.resolve(r.sessions);let i=du.get(t);if(i)return i;let a=e.request().then(e=>{for(fu.delete(t);fu.size>=uu;){let e=fu.keys().next().value;if(typeof e!=`string`)break;fu.delete(e)}return fu.set(t,{loadedAt:Date.now(),sessions:e}),e});return du.set(t,a),a.then(()=>{du.get(t)===a&&du.delete(t)},()=>{du.get(t)===a&&du.delete(t)}),a},hu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),gu=(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(hu)},_u=30;function vu(e){return e===`busy`||e===`retry`}var yu=new Map;function bu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function xu(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 Su(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${xu(e.error)}`)}function Cu(e,t){let n=zi();if(!n)return!1;let r=n.getTranscript(un(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>Xi()}function wu(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Tu(e,t,n){let r=[...e.getState().session],i=rn.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Eu(){let e=cr(),t=Ht(),n=Bn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=zi();if(!r||!t)return bu({kind:`unknown`,loadedTurns:0},!1);let i=un(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return bu(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}};bn(a,t),Yt(r,t),r.setState(a);for(let n of t)Ot(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=yu.get(t);if(n)return yu.delete(t),yu.set(t,n),n;let r=new Set;for(yu.set(t,r);yu.size>_u;){let e=yu.keys().next().value;if(!e)break;let t=[...yu.get(e)??[]];yu.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=Jr(a.getState()),u=an(),d=_t({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),An()){let e=new Set([r,...c,...l]),t=(zi()?.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:Cu(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 Nn(a,r):await Wi(a,r)}catch{return}if(i?.isStale?.())return;let u=zi()?.getTranscript(un(a,r));fr({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await Ni({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 St();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=ke.getScopedSdkClient(o);c(t,o);let d=r(t,o);return cu.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=zi(),i=un(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=rn.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&Vn(o,t)){fr({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=wu({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await li(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Su(e,`session.get`),e});if(n.data&&!e()){let r=dr(n.data);e()||Tu(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let a=r||e;if(!t||!a)return;let o=n.ensureChild(a,{bootstrap:!1}),s=ke.getScopedSdkClient(a),c=await mu({runtimeKey:i(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return Su(e,`session.children`),e.data??[]}});o.setState(e=>{let n=gu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;gr(un(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;gr(un(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;gr(un(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await St();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(vu(o))throw Error(`refresh transcript busy`);try{await vn(i,t),fr({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 Du=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Ou=e=>e===`original`||e===`modified`,ku=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Au=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Du(t.source))return null;let n=ku(t.startLine),r=ku(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:Ou(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()}},ju=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(Au).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Mu=ue()(fe(de((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:ju(e.drafts)}}),{name:`inline-comment-draft-store`}));function Nu(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 Pu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Nu).join(`
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -6521,8 +6521,8 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
|
|
|
6521
6521
|
`))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},ig=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!eg.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:ng(i.additions)??void 0,deletions:ng(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:ng(e.additions)??void 0,deletions:ng(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:ng(i.additions)??void 0,deletions:ng(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=rg(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},ag=(e,t,n)=>{let r=[];for(let i of e){let e=i.index?.trim()??``,a=i.working_dir?.trim()??``,o=!!(e&&e!==`?`),s=!!(a||e===`?`),c=a||e;if(!c||c===`!`)continue;let l=t?.[i.path];r.push({path:vo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},og=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},sg=(e,t)=>_o(e,t),cg=(e,t)=>{let n=tg(e)&&e.relativePath?e.relativePath:sg(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},lg=e=>tg(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},ug=2;function dg(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 fg(e,t=ug){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}=dg(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 pg(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=fg(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 mg=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=ot(),o;t[0]===a?o=t[1]:(o=a(`chat.changedFiles.title`),t[0]=a,t[1]=o);let s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`span`,{className:xc,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Ec,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:Uc,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;if(t[9]!==r||t[10]!==n||t[11]!==i||t[12]!==a){let e;t[14]!==r||t[15]!==i||t[16]!==a?(e=(e,t)=>{let{fileName:n,dirPart:o}=cg(e,r),s=lg(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`,Dc),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(gd,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(pg,{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:Hc,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},hg=`${kc} origin-[var(--transform-origin)]`,gg=Cc,_g=Z.memo(()=>{let e=(0,Q.c)(60),{t}=ot(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=lc()??null,o=Z.useContext(Oo),c=ls(a),l;e[0]===a?l=e[1]:(l=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=l);let u=qo(l),d=$h(),f,p;e[2]===n?(f=e[3],p=e[4]):(f=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},p=[n],e[2]=n,e[3]=f,e[4]=p),Z.useEffect(f,p);let m;bb0:{if(!a||c!==!0||!u||u.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],m=t;break bb0}let t;e[6]!==a||e[7]!==u.diffStats||e[8]!==u.files?(t=ag(u.files,u.diffStats,a),e[6]=a,e[7]=u.diffStats,e[8]=u.files,e[9]=t):t=e[9],m=t}let h=m,g=0,_=0;if(e[10]!==g||e[11]!==h||e[12]!==_){for(let e of h)g+=e.insertions,_+=e.deletions;e[10]=g,e[11]=h,e[12]=_,e[13]=g,e[14]=_}else g=e[13],_=e[14];let v;e[15]!==g||e[16]!==_?(v={totalAdded:g,totalRemoved:_},e[15]=g,e[16]=_,e[17]=v):v=e[17];let{totalAdded:y,totalRemoved:b}=v;if(!a||c!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!tg(e))return;r(!1);let t=e.path;if(d){d.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=s.getState(),c=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,c);return}i.navigateToDiff(e.relativePath,c),i.setRightSidebarOpen(!1)},e[18]=a,e[19]=d,e[20]=o?.editor,e[21]=x):x=e[21];let S=x,C=h.length,w;e[22]!==C||e[23]!==t?(w=t(C===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:C}),e[22]=C,e[23]=t,e[24]=w):w=e[24];let T=w,E,D;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(Sc,`max-w-full text-left`),D=()=>r(vg),e[25]=E,e[26]=D):(E=e[25],D=e[26]);let O,k;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(X,{name:`file-edit`,className:Tc}),O=Y(Fc,`shrink-0`),e[27]=O,e[28]=k):(O=e[27],k=e[28]);let A;e[29]===T?A=e[30]:(A=(0,$.jsx)(`span`,{className:O,children:T}),e[29]=T,e[30]=A);let j;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(j=Y(`status-row__changed-label`,Fc),e[31]=j):j=e[31];let M;e[32]===t?M=e[33]:(M=t(`chat.pendingChanges.changedInWorkspace`),e[32]=t,e[33]=M);let N;e[34]===M?N=e[35]:(N=(0,$.jsx)(`span`,{className:j,children:M}),e[34]=M,e[35]=N);let P;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(P=Y(bc,`items-baseline gap-0.5`),e[36]=P):P=e[36];let F;e[37]===y?F=e[38]:(F=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,y]}):null,e[37]=y,e[38]=F);let I;e[39]===b?I=e[40]:(I=b>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,b]}):null,e[39]=b,e[40]=I);let L;e[41]!==F||e[42]!==I?(L=(0,$.jsxs)(`span`,{className:P,children:[F,I]}),e[41]=F,e[42]=I,e[43]=L):L=e[43];let R;e[44]===n?R=e[45]:(R=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:Tc}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Tc}),e[44]=n,e[45]=R);let z;e[46]!==n||e[47]!==A||e[48]!==N||e[49]!==L||e[50]!==R?(z=(0,$.jsxs)(`button`,{type:`button`,className:E,onClick:D,"aria-expanded":n,children:[k,A,N,L,R]}),e[46]=n,e[47]=A,e[48]=N,e[49]=L,e[50]=R,e[51]=z):z=e[51];let B;e[52]!==a||e[53]!==h||e[54]!==S||e[55]!==n?(B=n&&(0,$.jsx)(`div`,{style:gg,className:Y(hg,`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)(mg,{files:h,currentDirectory:a,onOpenFile:S})}),e[52]=a,e[53]=h,e[54]=S,e[55]=n,e[56]=B):B=e[56];let V;return e[57]!==z||e[58]!==B?(V=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[z,B]}),e[57]=z,e[58]=B,e[59]=V):V=e[59],V});_g.displayName=`PendingChangesBar`;function vg(e){return!e}var yg=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=ot(),s=a===`compact`;if(s&&!n)return null;let c=a==="default"&&`absolute left-1/2 bottom-full mb-2 -translate-x-1/2`,l=a===`expanded`&&`absolute left-1/2 -translate-x-1/2 oc-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`oc-scroll-to-bottom--compact relative shrink-0`,d;t[0]!==a||t[1]!==c||t[2]!==l||t[3]!==u||t[4]!==n?(d=Y(c,l,u,n?Y(`pointer-events-auto`,a==="default"&&`opacity-100`):Y(`opacity-0 pointer-events-none`,a===`expanded`&&`oc-scroll-to-bottom--hidden`)),t[0]=a,t[1]=c,t[2]=l,t[3]=u,t[4]=n,t[5]=d):d=t[5];let f=s?`ghost`:`outline`,p=s?`composer-mobile-actions h-8 w-8 rounded-none bg-transparent hover:bg-transparent text-foreground`:`size-8 rounded-full [corner-shape:round] bg-background/95 hover:bg-interactive-hover`,m;t[6]===p?m=t[7]:(m=Y(`p-0 shadow-none`,p),t[6]=p,t[7]=m);let h;t[8]===o?h=t[9]:(h=o(`chat.scrollToBottom.aria`),t[8]=o,t[9]=h);let g=s?`size-5`:`size-4`,_=s?`medium`:`regular`,v;t[10]!==g||t[11]!==_?(v=(0,$.jsx)(X,{name:`arrow-down`,className:g,weight:_}),t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==r||t[14]!==v||t[15]!==f||t[16]!==m||t[17]!==h?(y=(0,$.jsx)(ca,{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}),bg=Z.createContext(`default`),xg=()=>Z.useContext(bg),Sg=500,Cg=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=er(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=cm(d),h;t[5]===d?h=t[6]:(h=ea(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()},Sg))},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`,mm,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)(sm,{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:wg,onMouseDown:Tg,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 wg(e){return e.preventDefault()}function Tg(e){return e.preventDefault()}var Eg=e=>{let t=(0,Q.c)(28),{onOpenModel:n,className:r,providerID:i,modelID:a,provider:o,variant:s,disabled:c}=e,l=c!==void 0&&c,{t:u}=ot(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=ir(o,a,u(`chat.modelControls.selectModel`)),t[0]=a,t[1]=o,t[2]=u,t[3]=d):d=t[3];let f=d,p;t[4]===s?p=t[5]:(p=s?.trim()?Zt(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)(ka,{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:Dg,onPointerDownCapture:Og,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 Dg(e){return e.preventDefault()}function Og(e){e.preventDefault()}var kg={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Ag=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function jg(e,t){let n=(0,Q.c)(6),r=wr(e??``,t),i=Ar(e??``,t),a=di(e??``,t),o=ei(e??``,t),s=Pi(e??``,t),c=hi(t),l;bb0:{if(!e){l=kg;break bb0}if(o.length>0||s.length>0){l=kg;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=Ag({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=kg;break bb0}if(!y){l=kg;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 Mg=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function Ng(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 Pg(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)(Ng,{className:n,...r,children:i}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function Fg(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)(Ng,{className:n,...r,children:l}),t[9]=n,t[10]=r,t[11]=l,t[12]=u):u=t[12],u}var Ig=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Lg=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Rg=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),zg=(e,t)=>e.id===t.id&&e.directory===t.directory,Bg=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Vg=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Rg(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&zg(e.parentTarget,i)&&Bg(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},Hg=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`}},Ug=`data-mobile-overlay-active`,Wg=e=>Array.from(e).some(e=>e.getAttribute(Ug)!==`false`),Gg=`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(`.`),Kg=`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 qg(){return`${Gg[Math.floor(Math.random()*Gg.length)]}-${Kg[Math.floor(Math.random()*Kg.length)]}`}function Jg(e){let t=qg();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var Yg=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,Xg=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),Zg=(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))},Qg=async(e,t)=>{await Gt(e)&&await mr(t)},$g=e=>{let t=Yg(e),n=xn.getState().projects;if(n.length===0)return null;let r=xn.getState().getActiveProject();if(r?.path){let e=Yg(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=Yg(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>Yg(t.path).length-Yg(e.path).length)[0];return i?{id:i.id,path:i.path}:null},e_=!1,t_=async(e,t)=>{try{let n=xn.getState().projects.find(e=>e.id===t.id)??xn.getState().projects.find(e=>Yg(e.path)===Yg(t.path)),r=br(t.path);await Qr.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Qr.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),Zg(e,Xg(Qr.getState()),vi.getState())}catch{}},n_=async(e,t,n)=>{let r=Zr.getState(),i=Qr.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await t_(e,n),we.getState().setDirectory(t.path,{showOverlay:!1})},r_=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,i_=async e=>{if(e_)return null;let t=xn.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return Tt.error(`No active project`,{description:`Please select a project first.`}),null;let r=$g(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return Tt.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await ua(r.path)}catch{}if(!i)return Tt.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;e_=!0;try{let t=fi(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?r_(n):Jg(),a=n?`existing`:`new`,o=Zr.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 la(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(Zr.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),we.getState().setDirectory(s.path,{showOverlay:!1}));let c=await Hn(r),l=await Jo(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Cr(t,l.path),Zr.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),we.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=Zr.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(Oi(n,e instanceof Error?e:Error(t)),Zr.getState().resolvePendingDraftWorktreeTarget(n,null)),Zr.getState().setDraftBootstrapPendingDirectory(null),Tt.error(`Failed to create worktree`,{description:t}),null}finally{e_=!1}};async function a_(){return i_()}async function o_(e){let t=e.branch?.trim();return t?i_({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function s_(e,t,n,r){if(e_)return null;e_=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=$g(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await ua(s.path)}catch{}if(!c)return Tt.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await Hn(s),u=await Ma(s.path);try{let e=await Jo(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 Qg(s,e.path);let n=await Zr.getState().createSession(void 0,e.path);if(!n)throw await Pa(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await n_(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 Tt.error(`Failed to create worktree`,{description:t}),null}}finally{e_=!1}}var c_=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},l_=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 u_({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=ot(),{github:a}=Do(),o=$a(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=s(e=>e.isMobile),{isTablet:p}=fo(),m=f||p,h=xn(e=>e.getActiveProject()),g=we(e=>e.currentDirectory),_=Z.useMemo(()=>h?.path?.trim()||g?.trim()||null,[h?.path,g]),[v,y]=Z.useState(``),[b,x]=Z.useState(!1),[S,C]=Z.useState(null),w=Z.useRef(0),T=Z.useMemo(()=>c_(v),[v]),E=zo(v,350),D=T?``:E.trim(),O=!!T||v===E,k=e&&O&&!!_&&!!a?.issuesList&&!(l&&c?.connected===!1),A=Je({queryKey:I.scoped(`github-issues`,_,D),enabled:k,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(_,{page:e,...D?{query:D}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),j=O?A.data?.pages.at(-1)??null:null,M=O?A.data?.pages.flatMap(e=>e.issues??[])??[]:[],N=O&&A.hasNextPage,P=!T&&!O||A.isLoading,F=O&&A.isFetchingNextPage,L=O&&A.error?A.error instanceof Error?A.error.message:String(A.error):null,R=Z.useCallback(()=>A.refetch(),[A]),z=Z.useCallback(async()=>{try{await A.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Tt.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[A,i]);Z.useEffect(()=>{e||(++w.current,y(``),x(!1),C(null))},[e]),Z.useEffect(()=>{++w.current},[e,_]);let B=!l||c?.connected!==!1&&j?.connected!==!1,V=j?.repo?.url??null,H=Z.useCallback(()=>{d(`github`),u(!0)},[u,d]),U=Z.useCallback(()=>{let e=Qr.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),W=Z.useCallback(()=>{let e=Qr.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Ln(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),ee=Z.useCallback((e,t)=>{let n=Qr.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),G=Z.useCallback(async(e,o)=>{let s=++w.current,c=()=>w.current===s;if(n===`select`){if(!_){Tt.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Tt.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(S)return;C(e);try{let n=await a.issueGet(_,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Tt.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Tt.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){Tt.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){Tt.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=l_({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);Tt.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&C(null)}return}if(!_){Tt.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Tt.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!S){C(e);try{let n=await a.issueGet(_,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Tt.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Tt.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){Tt.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){Tt.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(b){let e=`issue-${r.number}-${qg()}`,t=await s_(_,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 Kn(u,_,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??_}})();if(!c())return;Ci(d,u).catch(()=>void 0);try{Zr.getState().initializeNewOpenChamberSession(d,Qr.getState().agents)}catch{}t(!1);let f=Qr.getState(),p=vi.getState().lastUsedProvider,m=W(),h=m?.providerID||f.currentProviderId||p?.providerID,g=m?.modelID||f.currentModelId||p?.modelID,v=U()||f.currentAgentName||void 0;if(!h||!g){Tt.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let y=ee(h,g),x=await ki(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await ki(`github.issue.review.instructions`);if(!c())return;let C=l_({repo:n.repo,issue:r,comments:l});Zr.getState().sendMessage(x,h,g,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],y,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);Tt.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),Tt.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Tt.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&C(null)}}},[b,a,n,t,r,_,U,W,ee,S,i]),K=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),q=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)(za,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:v,onChange:e=>{y(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(f?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[_?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.noActiveProject`)}),a?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.runtimeUnavailable`)}),P?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.issues`)]}):null,B===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:i(`session.githubIssuePicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:H,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,L?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:L}):null,T&&_&&a&&B?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,S===T&&`bg-interactive-selection/30`),onClick:()=>void G(T),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:i(`session.githubIssuePicker.actions.useIssue`,{number:T})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:S===T?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,M.length===0&&!P&&!L&&B&&a&&_?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:E.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,M.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,S===e.number&&`bg-interactive-selection/30`),onClick:()=>void G(e.number,e.sourceRepo),children:[(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground w-12 text-right flex-shrink-0`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsx)(`p`,{className:`typography-small text-foreground truncate`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:S===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,m?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":i(`session.githubIssuePicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),N&&B&&_&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void z(),disabled:F||!!S,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(F||!!S)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:F?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.more`)]}):i(`session.githubIssuePicker.actions.loadMore`)})}):null]}),n!==`select`&&(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:i(`session.githubIssuePicker.actions.sectionTitle`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 cursor-pointer`,role:`button`,tabIndex:0,"aria-pressed":b,onClick:()=>x(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),x(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),x(e=>!e)},"aria-label":i(`session.githubIssuePicker.actions.toggleWorktreeAria`),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:b?(0,$.jsx)(X,{name:`checkbox`,className:`h-4 w-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i(`session.githubIssuePicker.actions.createInWorktree`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/70 hidden sm:inline`,children:`(issue-<number>-<slug>)`})]}),(0,$.jsx)(`div`,{className:`hidden sm:block sm:flex-1`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[V?(0,$.jsx)(ca,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:V,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:R,disabled:P||!!S,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return f?(0,$.jsx)(im,{open:e,title:K,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:K}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:q})]}),children:te}):(0,$.jsx)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(Qi,{className:`flex-shrink-0`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),K]}),(0,$.jsx)(ra,{children:q})]}),te]})})}var d_=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},f_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function p_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),{github:i}=Do(),a=$a(),o=a.data??null,c=a.isFetched,l=s(e=>e.setSettingsDialogOpen),u=s(e=>e.setSettingsPage),d=s(e=>e.isMobile),{isTablet:f}=fo(),p=d||f,m=xn(e=>e.getActiveProject())?.path??null,[h,g]=Z.useState(``),[_,v]=Z.useState(!1),[y,b]=Z.useState(null),x=Z.useRef(0),S=Z.useMemo(()=>d_(h),[h]),C=zo(h,350),w=S?``:C.trim(),T=!!S||h===C,E=e&&T&&!!m&&!!i?.prsList&&!(c&&o?.connected===!1),D=Je({queryKey:I.scoped(`github-prs`,m,w),enabled:E,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(m,{page:e,...w?{query:w}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),O=T?D.data?.pages.at(-1)??null:null,k=T?D.data?.pages.flatMap(e=>e.prs??[])??[]:[],A=T&&D.hasNextPage,j=!S&&!T||D.isLoading,M=T&&D.isFetchingNextPage,N=T&&D.error?D.error instanceof Error?D.error.message:String(D.error):null,P=J(async()=>{try{await D.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Tt.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++x.current,g(``),v(!1),b(null))},[e]),Z.useEffect(()=>{++x.current},[e,m]);let F=!c||o?.connected!==!1&&O?.connected!==!1,L=J(()=>{u(`github`),l(!0)}),R=J(async(e,a)=>{if(!m){Tt.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){Tt.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(y)return;let o=++x.current,s=()=>x.current===o;b(e);try{let o=await i.prContext(m,e,{includeDiff:_,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){Tt.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){Tt.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){Tt.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await ki(`github.pr.review.instructions`);if(!s())return;n({number:o.pr.number,title:o.pr.title,url:o.pr.url,head:o.pr.head,base:o.pr.base,includeDiff:_,instructionsText:e,contextText:f_(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);Tt.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&b(null)}}),z=r(`session.githubPrPicker.title`),B=r(`session.githubPrPicker.description`),V=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(za,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:h,onChange:e=>{g(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":_,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ha,{checked:_,onChange:e=>v(e),ariaLabel:r(`session.githubPrPicker.includeDiffAria`)})}),(0,$.jsx)(`span`,{className:`typography-small text-muted-foreground whitespace-nowrap`,children:r(`session.githubPrPicker.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(d?`min-h-0`:`flex-1 overflow-y-auto`),children:[m?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.noActiveProject`)}),i?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.runtimeUnavailable`)}),j?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.pullRequests`)]}):null,F===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:r(`session.githubPrPicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:L,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,N?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:N}):null,S&&m&&i&&F?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,y===S&&`bg-interactive-selection/30`),onClick:()=>void R(S),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:r(`session.githubPrPicker.actions.usePullRequest`,{number:S})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:y===S?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,k.length===0&&!j&&!N&&F&&i&&m?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:C.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,k.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,y===e.number&&`bg-interactive-selection/30`),onClick:()=>void R(e.number,e.sourceRepo),children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsxs)(`p`,{className:`typography-small text-foreground truncate`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground mr-1`,children:[`#`,e.number]}),e.title]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,(0,$.jsxs)(`p`,{className:`typography-meta text-muted-foreground truncate`,children:[e.head,` → `,e.base]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:y===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,p?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":r(`session.githubPrPicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),A&&F&&m&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:M||!!y,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(M||!!y)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:M?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.more`)]}):r(`session.githubPrPicker.actions.loadMore`)})}):null]})]});return d?(0,$.jsx)(im,{open:e,title:z,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:z}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:B})]}),children:V}):(0,$.jsx)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(Qi,{className:`flex-shrink-0`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),z]}),(0,$.jsx)(ra,{children:B})]}),V]})})}function m_(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)(Gc,{"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 h_=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)(Gc.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});h_.displayName=`CommandInput`;function g_(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)(da,{as:Gc.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 __(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)(Gc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function v_(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`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)(Gc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function y_(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)(Gc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function b_(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)(Gc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var x_=(e,t)=>`${e}:${T(t)}`,S_=e=>e.type===`skill`||!oe(e.name);function C_(e){let{t}=ot(),n=Z.useMemo(()=>d(),[]),r=s(e=>e.globalDraftStarters),i=xn(e=>e.activeProjectId),a=xn(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[c,l]=Z.useState([]),u=Z.useMemo(()=>r??se,[r]),f=u.some(S_)||c.some(S_),m=jt({directory:e,enabled:f}),h=Z.useMemo(()=>m.data??[],[m.data]),{refetch:g}=m,_=Tr({directory:e,enabled:f}),v=Z.useMemo(()=>_.data??[],[_.data]),{refetch:y}=_;Z.useEffect(()=>{let e=!1;if(!o){l([]);return}return xt(o).then(t=>{e||l(t)}).catch(()=>{e||l([])}),()=>{e=!0}},[o?.id]);let b=Z.useCallback(()=>{g(),y()},[g,y]),x=Z.useMemo(()=>new Set(h.map(e=>e.name)),[h]),S=Z.useMemo(()=>new Set(v.map(e=>e.name)),[v]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=oe(e.name);return n?{id:x_(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:x.has(e.name)?{id:x_(r,e),ref:e,group:r,label:w(e.name),icon:ie,submitText:`/${e.name}`}:null}return S.has(e.name)?{id:x_(r,e),ref:e,group:r,label:w(e.name),icon:P,submitText:`/${e.name}`}:null},[t,x,S,n]),E=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),D=Z.useMemo(()=>c.map(e=>C(e,`project`)).filter(e=>e!==null),[c,C]),O=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(T(t));for(let t of c)e.add(T(t));return e},[u,c]),k=Z.useMemo(()=>{let e=[];for(let r of M)n&&r.name===`craft-goal`||e.push({type:`command`,name:r.name,label:t(r.labelKey),icon:r.icon,section:`built-in`,scope:`user`});for(let t of h)t.isBuiltIn||t.source===`skill`||oe(t.name)||e.push({type:`command`,name:t.name,label:w(t.name),icon:ie,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of v)e.push({type:`skill`,name:t.name,label:w(t.name),icon:P,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!O.has(`${e.type}:${e.name}`))},[t,h,v,O,n]),A=Z.useCallback(e=>{s.getState().setGlobalDraftStarters(e),q({draftStarters:e})},[]),j=Z.useCallback(e=>{l(e),o&&bi(o,e)},[o]),N=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||c.some(e=>p(e,t)))return;j([...c,t])}else{let e=r??se;if(e.some(e=>p(e,t)))return;A([...e,t])}},[o,c,r,j,A]),F=Z.useCallback((e,t)=>{e===`project`?j(c.filter(e=>!p(e,t))):A((r??se).filter(e=>!p(e,t)))},[c,r,j,A]),I=Z.useCallback((e,t,n)=>{let i=e===`project`?c:r??se,a=i.findIndex(n=>x_(e,n)===t),o=i.findIndex(t=>x_(e,t)===n);if(a<0||o<0||a===o)return;let s=Zs([...i],a,o);e===`project`?j(s):A(s)},[c,r,j,A]);return{global:E,project:D,pinnable:k,hasProject:!!o,ensureLoaded:b,addStarter:N,removeStarter:F,reorder:I}}var w_=`__draft-starter-trash__`,T_=`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`,E_=`max-h-7`,D_=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],O_=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=ot(),s;t[0]===n.id?s=t[1]:(s={id:n.id},t[0]=n.id,t[1]=s);let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=Qs(s),m;t[2]===d?m=t[3]:(m=Ys.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},k_=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(P_),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)(O_,{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)(ec,{items:o,strategy:Xs,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},A_=()=>{let e=(0,Q.c)(13),{t}=ot(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:w_},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=Ws(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(T_,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},j_=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=ot(),o;t[0]===i?o=t[1]:(o=Y(`min-h-0`,i),t[0]=i,t[1]=o);let s;t[2]===a?s=t[3]:(s=a(`chat.draftStarters.searchPlaceholder`),t[2]=a,t[3]=s);let c;t[4]===s?c=t[5]:(c=(0,$.jsx)(h_,{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)(__,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=D_.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(v_,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(b_,{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)(g_,{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)(m_,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},M_=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=ot(),[o,s]=Z.useState(!1),c;t[0]===r?c=t[1]:(c=e=>{s(e),e&&r()},t[0]=r,t[1]=c);let l;t[2]===a?l=t[3]:(l=a(`chat.draftStarters.add`),t[2]=a,t[3]=l);let u;t[4]===a?u=t[5]:(u=a(`chat.draftStarters.add`),t[4]=a,t[5]=u);let d;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`}),t[6]=d):d=t[6];let f;t[7]!==l||t[8]!==u?(f=(0,$.jsx)(ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:T_,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)(Qi,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(na,{children:p})}),t[12]=p,t[13]=m);let h;t[14]===i?h=t[15]:(h=e=>{i(e),s(!1)},t[14]=i,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(j_,{pinnable:n,onPick:h,className:`flex max-h-[60vh] flex-col`}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==m||t[20]!==g?(_=(0,$.jsxs)(ta,{className:`gap-0 overflow-hidden p-0 sm:max-w-sm`,children:[m,g]}),t[19]=m,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==o||t[23]!==c||t[24]!==_||t[25]!==f?(v=(0,$.jsxs)(aa,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},N_=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=ot(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=C_(lc()),{isMobile:f}=fo(),[p,m]=Z.useState(!1),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),y=Z.useRef(null),b;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(b={activationConstraint:{distance:8}},t[0]=b):b=t[0];let x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(x={activationConstraint:{delay:200,tolerance:6}},t[1]=x):x=t[1];let S=Js(Vs(Ks,b),Vs(Us,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)===w_){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:Hs.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&&E_,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)(k_,{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)(k_,{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(F_),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:T_,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)(A_,{}):(0,$.jsx)(M_,{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 q;t[55]!==R||t[56]!==W||t[57]!==K?(q=(0,$.jsxs)(`div`,{className:R,children:[W,K]}),t[55]=R,t[56]=W,t[57]=K,t[58]=q):q=t[58];let te;return t[59]!==F||t[60]!==S||t[61]!==q?(te=(0,$.jsx)(qs,{sensors:S,collisionDetection:Gs,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:q}),t[59]=F,t[60]=S,t[61]=q,t[62]=te):te=t[62],te};function P_(e){return e.id}function F_(e){return!e}var I_=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});I_.displayName=`ChatComposerSurface`;var L_=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(ja,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});L_.displayName=`ChatPromptTextarea`;var R_=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},z_=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},B_=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,q=Z.useRef(null),te=Z.useRef(null),ne;t[40]!==ee||t[41]!==K||t[42]!==z?.fillContainer?(ne=()=>{if(!ee||K||z?.fillContainer)return;let e=q.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]=ne):ne=t[43];let re=z?.fillContainer,ie;t[44]!==ee||t[45]!==K||t[46]!==re||t[47]!==B?(ie=[ee,K,re,B],t[44]=ee,t[45]=K,t[46]=re,t[47]=B,t[48]=ie):ie=t[48],Z.useLayoutEffect(ne,ie);let ae;t[49]!==G||t[50]!==H||t[51]!==w||t[52]!==U||t[53]!==z?(ae=e=>{z?.onKeyDown?.(e),!(e.defaultPrevented||Mg(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]=ae):ae=t[54];let oe=ae,se;t[55]===b?se=t[56]:(se=e=>{b?.(e.target.files),e.target.value=``},t[55]=b,t[56]=se);let ce=se,le=B.trim().length>0||V.length>0,ue=V.filter(V_),de;t[57]!==n||t[58]!==H||t[59]!==ce||t[60]!==b||t[61]!==U?(de=b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:te,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:ce}),(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:()=>te.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]=ce,t[60]=b,t[61]=U,t[62]=de):de=t[62];let fe=de,pe=!H&&!U&&le,me;t[63]!==H||t[64]!==le||t[65]!==W||t[66]!==C||t[67]!==U||t[68]!==O||t[69]!==pe||t[70]!==k?(me=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)(Pg,{className:W?`size-6`:`size-full`})}):(0,$.jsx)(`button`,{type:`submit`,"data-composer-send":`true`,"data-composer-circle":pe?`true`:void 0,className:Y(`flex size-8 shrink-0 items-center justify-center outline-none`,pe?`rounded-full hover:opacity-80`:`rounded-md text-primary hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`),disabled:H||U||!le,"aria-label":O,children:pe?(0,$.jsx)(Fg,{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]=le,t[65]=W,t[66]=C,t[67]=U,t[68]=O,t[69]=pe,t[70]=k,t[71]=me):me=t[71];let he=me,ge=I_,_e=K&&`flex-1`,ve;t[72]!==o||t[73]!==_e?(ve=Y(`relative flex min-h-0 flex-col`,_e,o),t[72]=o,t[73]=_e,t[74]=ve):ve=t[74];let ye=K&&`flex min-h-0 flex-1 flex-col`,be;t[75]!==_||t[76]!==ye?(be=Y(`overflow-hidden`,ye,_),t[75]=_,t[76]=ye,t[77]=be):be=t[77];let xe=ue.length>0?(0,$.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-3 pt-3`,"data-chat-prompt-attachments":`true`,children:ue.map(e=>(0,$.jsxs)(`div`,{className:`group relative shrink-0`,children:[(0,$.jsx)(`img`,{src:e.url,alt:e.name,className:`size-16 rounded-lg border border-border object-cover`}),S?(0,$.jsx)(`button`,{type:`button`,className:`absolute -right-1 -top-1 flex size-6 items-center justify-center rounded-full border border-border bg-[var(--surface-elevated)] shadow-sm hover:bg-[var(--interactive-hover)]`,onClick:()=>S(e.id),"aria-label":E,children:(0,$.jsx)(X,{name:`close`,className:`size-3`})}):null]},e.id))}):null,Se=K&&`flex min-h-0 flex-1 flex-col`,Ce;t[78]===Se?Ce=t[79]:(Ce=Y(`relative overflow-hidden`,Se),t[78]=Se,t[79]=Ce);let we;t[80]!==u||t[81]!==d||t[82]!==p||t[83]!==R?(we=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[80]=u,t[81]=d,t[82]=p,t[83]=R,t[84]=we):we=t[84];let Te;t[85]===g?Te=t[86]:(Te=e=>{q.current=e,z_(g,e)},t[85]=g,t[86]=Te);let Ee;t[87]===x?Ee=t[88]:(Ee=e=>x(e.target.value,e),t[87]=x,t[88]=Ee);let De=H||U&&G,Oe=W?`send`:z?.enterKeyHint,ke=K&&`min-h-0 flex-1`,Ae;t[89]!==h||t[90]!==ke?(Ae=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,ke,h),t[89]=h,t[90]=ke,t[91]=Ae):Ae=t[91];let je=d&&`text-transparent caret-[var(--surface-foreground)]`,Me;t[92]!==p||t[93]!==je||t[94]!==R?(Me=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,je),t[92]=p,t[93]=je,t[94]=R,t[95]=Me):Me=t[95];let Ne=z?.rows??1,Pe;t[96]!==oe||t[97]!==v||t[98]!==T||t[99]!==Te||t[100]!==Ee||t[101]!==De||t[102]!==Oe||t[103]!==Ae||t[104]!==Me||t[105]!==Ne||t[106]!==z||t[107]!==B?(Pe=(0,$.jsx)(L_,{...z,simple:!0,ref:Te,"data-chat-input":`true`,value:B,onChange:Ee,onKeyDown:oe,disabled:De,placeholder:T,enterKeyHint:Oe,outerClassName:Ae,className:Me,style:v,rows:Ne}),t[96]=oe,t[97]=v,t[98]=T,t[99]=Te,t[100]=Ee,t[101]=De,t[102]=Oe,t[103]=Ae,t[104]=Me,t[105]=Ne,t[106]=z,t[107]=B,t[108]=Pe):Pe=t[108];let Fe;t[109]!==Ce||t[110]!==we||t[111]!==Pe?(Fe=(0,$.jsxs)(`div`,{className:Ce,"data-composer-input-shell":`true`,children:[we,Pe]}),t[109]=Ce,t[110]=we,t[111]=Pe,t[112]=Fe):Fe=t[112];let Ie;t[113]!==r||t[114]!==m||t[115]!==be||t[116]!==xe||t[117]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:be,children:[m,r,xe,Fe]}),t[113]=r,t[114]=m,t[115]=be,t[116]=xe,t[117]=Fe,t[118]=Ie):Ie=t[118];let Le;t[119]!==fe||t[120]!==he||t[121]!==c||t[122]!==f||t[123]!==y||t[124]!==D?(Le=c??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:y??fe}),f?(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,children:f}):(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:D??he})]}),t[119]=fe,t[120]=he,t[121]=c,t[122]=f,t[123]=y,t[124]=D,t[125]=Le):Le=t[125];let Re;t[126]!==s||t[127]!==l||t[128]!==Le?(Re=(0,$.jsx)(R_,{className:s,style:l,children:Le}),t[126]=s,t[127]=l,t[128]=Le,t[129]=Re):Re=t[129];let ze;t[130]!==ve||t[131]!==Ie||t[132]!==Re?(ze=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ve,children:[Ie,Re]}),t[130]=ve,t[131]=Ie,t[132]=Re,t[133]=ze):ze=t[133];let Be;return t[134]!==ge||t[135]!==i||t[136]!==a||t[137]!==K||t[138]!==A||t[139]!==ze?(Be=(0,$.jsxs)(ge,{className:a,expanded:K,...A,children:[i,ze]}),t[134]=ge,t[135]=i,t[136]=a,t[137]=K,t[138]=A,t[139]=ze,t[140]=Be):Be=t[140],Be};function V_(e){return e.mime.startsWith(`image/`)}var H_=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),U_=({currentBranch:e,localBranches:t,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:o=[],disabled:s=!1,iconOnly:c=!1,trigger:l,triggerLabel:u,contentAlign:d,hideTooltip:f=!1,projectRootOption:p=null,worktreeOptions:m=[],selectedDirectory:h=null,onSelectDirectory:g,onCreateWorktree:_,worktreesLabel:v,worktreeNewLabel:y,projectRootLabel:b,onOpenChange:x,open:S,presentation:C=`dropdown`})=>{let{t:w}=ot(),[T,E]=Z.useState(!1),[D,O]=Z.useState(``),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(``),[F,I]=Z.useState(!1),L=Z.useRef(null),R=Z.useId(),z=S??T,B=e=>{S===void 0&&E(e),x?.(e)},V=Z.useCallback(e=>{e.stopPropagation()},[]),H=o.length>1,U=!!(g||_),W=Z.useMemo(()=>H_(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?gi(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?gi(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?gi(m,e,e=>e.label).map(e=>e.item):m},[D,m]),q=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||gi([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),te=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},ne=e=>{g?.(e),B(!1),O(``)},re=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},ie=async()=>{if(!(!W||F)){if(H){M(!0);return}I(!0);try{await a(W,o[0]),P(``),A(!1),B(!1)}finally{I(!1)}}},ae=async e=>{if(!(!W||F)){I(!0);try{await a(W,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},oe=()=>{M(!1)},se=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let ce=u||e||w(`gitView.branch.detachedHead`),le=d??(c?`end`:`start`),ue=v??w(`chat.chatInput.worktrees`),de=y??w(`chat.chatInput.worktreeNew`),fe=b??w(`chat.chatInput.projectRoot`),pe=c?(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":ce,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(ca,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":ce,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:ce}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),me=(0,$.jsx)(lo,{asChild:!0,disabled:s,children:l??pe}),he=(0,$.jsxs)(m_,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(h_,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(g_,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(__,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(v_,{children:j?(0,$.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:oe,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-4`})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,$.jsx)(`span`,{className:`text-foreground font-medium`,children:W}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ae(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,$.jsx)(X,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,$.jsx)(`input`,{ref:L,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:N,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{V(e),e.key===`Enter`?(e.preventDefault(),ie()):e.key===`Escape`&&(e.preventDefault(),se())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:ie,disabled:!W||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:se,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(b_,{onSelect:re,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(y_,{}),(0,$.jsxs)(v_,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(b_,{onSelect:()=>te(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)(b_,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(y_,{}),(0,$.jsxs)(v_,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(b_,{onSelect:()=>te(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(b_,{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)(y_,{}),(0,$.jsxs)(v_,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:ue}),_?(0,$.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),B(!1),_()},children:de}):null]}),p&&q?(0,$.jsxs)(b_,{onSelect:()=>ne(p.value),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:fe}),(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,K.map(e=>(0,$.jsxs)(b_,{onSelect:()=>ne(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??pe,{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:he})]})}return(0,$.jsxs)(Za,{open:z,onOpenChange:B,children:[f||l?me:(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:me}),(0,$.jsx)(Va,{sideOffset:8,children:c?ce:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(co,{align:le,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:he})]})};function W_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=gi(t,i,e=>e),o=gi(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 G_(e,t){return`${e}\0${t}`}function K_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),i=s(e=>e.isMobile),{github:a}=Do(),o=$a(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=xn(e=>e.getActiveProject()),p=f?.id??null,m=f?.path??null,h=Z.useMemo(()=>m&&p?{id:p,path:m}:null,[p,m]),[g,_]=Z.useState(`issues`),[v,y]=Z.useState(``),[b,x]=Z.useState([]),[S,C]=Z.useState([]),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(null),[A,j]=Z.useState(null),[M,N]=Z.useState(null),[P,F]=Z.useState(!1),[I,L]=Z.useState(new Map),[R,z]=Z.useState(1),[B,V]=Z.useState(!1),H=Z.useRef(0),U=zo(v,350),W=J(async e=>{if(!(!m||!a)&&!(l&&c?.connected===!1)){T(!0),k(null),z(1),V(!1);try{if(g===`issues`&&a.issuesList){let t=await a.issuesList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(t.issues??[]),z(t.page??1),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=await a.prsList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(t.prs??[]),z(t.page??1),V(!!t.hasMore))}}catch(e){k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{T(!1)}}});Z.useEffect(()=>{if(!e||!m||l&&c?.connected===!1||!a)return;if(!U.trim()){W();return}let t=new AbortController;T(!0),k(null),z(1),V(!1);let n=g===`issues`&&a.issuesList?a.issuesList(m,{page:1,query:U.trim()}):g===`prs`&&a.prsList?a.prsList(m,{page:1,query:U.trim()}):null;if(!n){T(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(e.issues??[]),z(e.page??1),V(!!e.hasMore)):`prs`in e&&(e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(e.prs??[]),z(e.page??1),V(!!e.hasMore))))}).catch(e=>{t.signal.aborted||k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||T(!1)}),()=>t.abort()},[e,m,a,l,c,g,U,W,r]);let ee=J(async()=>{if(!(!m||!a)&&!(w||E)&&B){D(!0);try{let e=R+1;if(g===`issues`&&a.issuesList){let t=U.trim()?await a.issuesList(m,{page:e,query:U.trim()}):await a.issuesList(m,{page:e});t.connected!==!1&&(x(e=>[...e,...t.issues??[]]),z(t.page??e),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=U.trim()?await a.prsList(m,{page:e,query:U.trim()}):await a.prsList(m,{page:e});t.connected!==!1&&(C(e=>[...e,...t.prs??[]]),z(t.page??e),V(!!t.hasMore))}}catch{}finally{D(!1)}}});Z.useEffect(()=>{if(!e){_(`issues`),y(``),x([]),C([]),j(null),N(null),F(!1),k(null),L(new Map),z(1),V(!1);return}W()},[e,W]),Z.useEffect(()=>{H.current+=1,L(new Map)},[m,h]);let G=J(async e=>{if(!h||!e)return;let t=G_(h.path,e);if(I.has(t))return;let n=H.current;try{let i=await wa(h,{mode:`new`,branchName:e,worktreeName:e});if(n!==H.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);L(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==H.current)return;L(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||g!==`prs`||S.forEach(e=>{e.head&&G(e.head)})},[e,g,S,m,h,G]);let K=l&&c?.connected===!0,q=()=>{d(`github`),u(!0)},te=e=>{j(e),N(null)},ne=e=>{N(e),j(null)},re=()=>{A?n({type:`issue`,item:A}):M&&n({type:`pr`,item:M,includeDiff:P}),t(!1)},ie=()=>{j(null),N(null),F(!1)},ae=A||(M?.head&&m?I.get(G_(m,M.head))?.isValid!==!1:!1),oe=e=>!e.head||(m?I.get(G_(m,e.head)):void 0)?.isValid===!1,se=(0,$.jsx)($.Fragment,{children:K?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(za,{value:v,onChange:e=>y(e.target.value),placeholder:r(g===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[w&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),O&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:O})]})}),!w&&!O&&g===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[b.length>0?b.map(e=>(0,$.jsx)(`button`,{onClick:()=>te(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,A?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,onClick:()=>void ee(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!w&&!O&&g===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[S.length>0?S.map(e=>{let t=oe(e),n=e.head&&m?I.get(G_(m,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`,M?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,onClick:()=>void ee(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,$.jsx)(X,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:r(`session.githubIntegration.connect.title`)}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:r(`session.githubIntegration.connect.description`)})]}),(0,$.jsx)(ca,{onClick:q,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&&(A||M)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick: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`})})]}),g===`prs`&&M&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(ha,{checked:P,onChange:e=>F(e),ariaLabel:r(`session.githubIntegration.includeDiffAria`)}),(0,$.jsx)(`span`,{className:`typography-small text-foreground`,children:r(`session.githubIntegration.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,i?`w-full order-2`:`justify-end`),children:[(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(ca,{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)(im,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:K?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)(Kc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})}),(A||M)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick: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)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(Qi,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),r(`session.githubIntegration.title`)]}),(0,$.jsx)(`div`,{className:`w-[220px]`,children:(0,$.jsx)(Kc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),se,(0,$.jsx)($i,{className:`mt-1`,children:ce})]})})})}var q_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},J_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),Y_=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),X_=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,Z_=(e,t,n)=>{let r=J_(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-${X_(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}`}},Q_=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},$_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function ev({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ot(),{github:a,git:o}=Do(),c=s(e=>e.isMobile),l=Z.useId(),u=$a(),d=u.data??null,f=u.isFetched,p=xn(e=>q_(e.projects,e.activeProjectId,r)),m=p?.path??null,h=Z.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[g,_]=Z.useState(`new-branch`),[v,y]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[b,x]=Z.useState({selectedBranch:``,worktreeName:``}),S=rs(m),C=es(m),w=qo(e=>e.fetchBranches),T=Z.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),E=Z.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),D=Zr(e=>e.availableWorktreesByProject),O=Z.useMemo(()=>{if(!m)return new Set;let e=D.get(m)??[];return new Set(e.map(e=>e.name))},[D,m]),k=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=qg();if(!O.has(e))return e}return`${qg()}-${Date.now().toString(36).slice(-4)}`},[O]),[A,j]=Z.useState(!1),[M,N]=Z.useState(!1),[P,F]=Z.useState(!1),[I,L]=Z.useState(!1),[R,z]=Z.useState(!1),[B,V]=Z.useState(``),[H,U]=Z.useState(``),W=Z.useRef(null),ee=Z.useRef(null),G=Z.useRef(null),K=Z.useRef(null),q=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(()=>W_({localBranches:T,remoteBranches:E,query:B}),[T,E,B]),oe=Z.useMemo(()=>W_({localBranches:T,remoteBranches:E,query:H}),[T,E,H]),se=B.trim().length>0,ce=H.trim().length>0,le=ae.matching.length>0,ue=oe.matching.length>0,de=!!(m&&o),fe=Z.useCallback(()=>{!m||!o||w(m,o)},[m,o,w]);Z.useEffect(()=>{!e||!m||!o||S?.all||w(m,o)},[e,m,o,S?.all,w]),Z.useEffect(()=>{!M&&!I&&V(``)},[M,I]),Z.useEffect(()=>{!P&&!R&&U(``)},[P,R]),Z.useEffect(()=>{M&&re(W),I&&ie(G)},[M,I,B,re,ie]),Z.useEffect(()=>{P&&re(ee),R&&ie(K)},[P,R,H,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=Qr.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=Qr.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Ln(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=Qr.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(!m||!a)return;let t=Qr.getState(),n=vi.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){Tt.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(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await ki(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await ki(`github.issue.review.instructions`),d=Q_({repo:t.repo,issue:t.issue,comments:n.comments??[]});await Zr.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Tt.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(m,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await ki(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await ki(`github.pr.review.instructions`),u=$_(t);await Zr.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Tt.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,m,ye,be,xe,i]),Ce=g===`new-branch`?v:b;Z.useEffect(()=>{if(!e||!S?.all||!m||v.sourceBranch)return;let t=v.sourceBranch,n=!1;return(async()=>{try{let e=await Ma(m).catch(()=>null);if(n)return;let r=localStorage.getItem(Ko),{sourceBranch:i,shouldClearSavedSourceBranch:a}=ns({branches:S.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Ko),n||t)return;i&&y(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,S?.all,m,v.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;_(`new-branch`),x({selectedBranch:``,worktreeName:``}),N(!1),F(!1),L(!1),z(!1),V(``),U(``),me({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=k();y({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,k]),Z.useEffect(()=>{if(g!==`new-branch`||!v.isSyncingWorktreeName)return;let e=Y_(J_(v.branchName));y(t=>({...t,worktreeName:e}))},[g,v.branchName,v.isSyncingWorktreeName]);let we=Z.useCallback(async()=>{if(!h||!pe.touched||he)return;_e&&_e.abort();let e=new AbortController;ve(e),me(e=>({...e,isValidating:!0}));try{let t=g===`new-branch`?v.branchName:b.selectedBranch,n=Ce.worktreeName,r=J_(t),a=Y_(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=g===`new-branch`?v.linkedPr:null,n=t?Z_(t,T,E):null,i=await wa(h,{mode:g===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(g===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||me(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||me(e=>({...e,isValidating:!1}))}},[h,g,v.branchName,v.linkedPr,b.selectedBranch,Ce.worktreeName,T,E,pe.touched,_e,he,i]),Te=g===`new-branch`?v.branchName:b.selectedBranch;Z.useEffect(()=>{if(!e||!h||!pe.touched||he)return;let t=setTimeout(()=>{we()},300);return()=>clearTimeout(t)},[Ce.worktreeName,Te,e,h,we,pe.touched,he]);let Ee=async()=>{if(!h||!m){Tt.error(i(`session.newWorktree.error.noActiveProject`));return}me(e=>({...e,touched:!0}));let e=g===`new-branch`?v.branchName:b.selectedBranch,r=Ce.worktreeName,a=J_(e),o=Y_(r);if(!a){Tt.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){Tt.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=g===`new-branch`?v.linkedPr:null,r=g===`new-branch`?v.linkedIssue:null,s=g===`new-branch`?v.linkedPr:null,c=g===`new-branch`&&v.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([Hn(h),$o(m)]),f=v.sourceBranch,p=``,_=(()=>{if(e){let t=Z_(e,T,E);return p=t.sourceLabel,{preferredName:a||o,mode:`existing`,branchName:a,worktreeName:o,existingBranch:t.existingBranch,setupCommands:u,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return p=g===`new-branch`?f:``,{preferredName:a||o,mode:g===`existing-branch`?`existing`:`new`,branchName:g===`existing-branch`?void 0:a,worktreeName:o,existingBranch:g===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&g===`new-branch`?{startRef:f}:{}}})(),y=await ss(m,_,{resolvedRootTrackingRemote:d}),x=await Na(h,y),S=null;if(l){await Gt(h)&&await mr(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Kn(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),Ci(a.id,e).catch(()=>void 0);try{Zr.getState().initializeNewOpenChamberSession(a.id,Qr.getState().agents)}catch{}}else t(!1),ge(!1);let C=as({mode:g,sourceBranch:v.sourceBranch,linkedPr:!!v.linkedPr,selectedBranch:b.selectedBranch});C&&localStorage.setItem(Ko,C),Tt.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${p?` ${i(`session.newWorktree.fromSource`,{source:p})}`:``}`})}),S?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`);Tt.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`);Tt.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{ge(!1)}},De=e=>{_(e),me(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},Oe=e=>{if(!e){y(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${qg()}`;y(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:Y_(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;y(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:Y_(t.head),isSyncingWorktreeName:!0}))}},ke=f&&d?.connected===!0,Ae=(g===`existing-branch`?!!b.selectedBranch&&!!b.worktreeName&&!pe.branchError&&!pe.worktreeError:!!J_(v.branchName)&&!!v.worktreeName&&!pe.branchError&&!pe.worktreeError)&&!he,je=()=>{y(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Me=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,c?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,c?`w-full justify-center order-first`:`mr-auto`),children: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`,c&&`w-full`),children:[(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,className:Y(c&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ca,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:Y(`gap-1.5`,c&&`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:[c?(0,$.jsx)(_a,{id:`new-worktree-sheet-${l}`,open:e,onOpenChange:t,title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(da,{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)(Kc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[g===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>L(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:b.selectedBranch?`text-foreground`:`text-muted-foreground`,children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(im,{open:I,title:i(`session.newWorktree.selectBranch`),onClose:()=>L(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(za,{value:B,onChange:e=>V(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[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:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:Y_(e.label)})),me(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),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:()=>{x(t=>({...t,selectedBranch:e,worktreeName:Y_(e)})),me(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),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:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:Y_(e)})),me(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),g===`new-branch`&&ke&&(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(za,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:v.linkedPr.head})})]}),v.linkedIssue&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:v.linkedIssue.number,title:v.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=Y_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===Y_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===Y_(v.branchName)||!v.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(za,{value:Ce.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(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`)})]}),g===`new-branch`&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>z(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:v.sourceBranch?`text-foreground`:`text-muted-foreground`,children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})}),(0,$.jsx)(im,{open:R,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>z(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:K,children:[(0,$.jsx)(za,{value:H,onChange:e=>U(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[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:()=>{y(t=>({...t,sourceBranch:e.value})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),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:()=>{y(t=>({...t,sourceBranch:e})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),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:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(v.linkedIssue||v.linkedPr)&&g===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick: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`})})]}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Me})]})}):(0,$.jsx)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(Qi,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-5 w-5`}),i(`session.newWorktree.title`)]}),(0,$.jsx)(`div`,{className:`w-[280px] shrink-0`,children:(0,$.jsx)(Kc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>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:[g===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(Za,{open:M,onOpenChange:N,children:[(0,$.jsx)(lo,{asChild:!0,children:(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,b.selectedBranch?`text-foreground`:`text-muted-foreground`),children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(co,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:W,children:(0,$.jsxs)(m_,{shouldFilter:!1,children:[(0,$.jsx)(h_,{placeholder:i(`session.newWorktree.searchBranches`),value:B,onValueChange:V,onKeyDown:q}),(0,$.jsx)(g_,{disableHorizontal:!0,children:C?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(__,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[se&&le&&(0,$.jsx)(v_,{heading:i(`session.newWorktree.matchingBranches`),children:ae.matching.map(e=>(0,$.jsx)(b_,{value:e.value,onSelect:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:Y_(e.label)})),me(e=>({...e,touched:!0})),N(!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)(y_,{}),(0,$.jsx)(v_,{heading:i(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:ae.otherLocal.map(e=>(0,$.jsx)(b_,{value:e,onSelect:()=>{x(t=>({...t,selectedBranch:e,worktreeName:Y_(e)})),me(e=>({...e,touched:!0})),N(!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)(y_,{}),(0,$.jsx)(v_,{heading:i(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:ae.otherRemote.map(e=>(0,$.jsx)(b_,{value:`remotes/${e}`,onSelect:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:Y_(e)})),me(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),g===`new-branch`&&ke&&(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(za,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:v.linkedPr.head})})]}),v.linkedIssue&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:v.linkedIssue.number,title:v.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=Y_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===Y_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===Y_(v.branchName)||!v.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(za,{value:Ce.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(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`)})]}),g===`new-branch`&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(Za,{open:P,onOpenChange:F,children:[(0,$.jsx)(lo,{asChild:!0,children:(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,v.sourceBranch?`text-foreground`:`text-muted-foreground`),children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(co,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:ee,children:(0,$.jsxs)(m_,{shouldFilter:!1,children:[(0,$.jsx)(h_,{placeholder:i(`session.newWorktree.searchBranches`),value:H,onValueChange:U,onKeyDown:q}),(0,$.jsx)(g_,{disableHorizontal:!0,children:C?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(__,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(v_,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(b_,{value:e.value,onSelect:()=>{y(t=>({...t,sourceBranch:e.value})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),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)(y_,{}),(0,$.jsx)(v_,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(b_,{value:e,onSelect:()=>{y(t=>({...t,sourceBranch:e})),F(!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)(y_,{}),(0,$.jsx)(v_,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(b_,{value:`remotes/${e}`,onSelect:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})})]}),(v.linkedIssue||v.linkedPr)&&g===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick: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`})})]}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)($i,{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)(ca,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ca,{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)(K_,{open:A,onOpenChange:j,onSelect:Oe})]})}function tv(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 nv(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 rv=(e,t)=>e??t??null,iv=(e,t)=>!!e&&t!==!1,av=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:[]},ov=e=>e.replace(/^remotes\//,``).trim(),sv=e=>{let t=ov(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},cv=({directory:e,projectDirectory:t,label:n,projectRootOption:r,worktreeOptions:i,onSelectDirectory:a,className:o,maxWidthClassName:s=`max-w-[48vw] sm:max-w-[20rem]`,presentation:c=`dropdown`})=>{let{t:l}=ot(),{git:d}=Do(),f=rv(t,e),p=e,m=ls(f),h=ls(p),g=iv(f,m),_=p!==f&&iv(p,h),v=Mo(f,d,g),y=Mo(p,d,_),b=v.data,x=p===f?b:y.data,S=qo(e=>e.fetchStatus),C=qo(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=cs(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=xn(e=>e.projects),P=xn(e=>e.activeProjectId);Z.useEffect(()=>{d&&(f&&m===null&&S(f,d,{silent:!0}),p&&p!==f&&h===null&&S(p,d,{silent:!0}))},[S,d,m,h,f,p]);let F=Z.useMemo(()=>{let e=u(t);if(e){let t=N.find(t=>u(t.path)===e);if(t)return t.id}return P},[P,t,N]),{localBranches:I,remoteBranches:L}=Z.useMemo(()=>av(b?.all),[b]),R=x?.current?.trim()||C||null,z=!nv(n,e)&&n||R||n||l(`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 Uo(e,d),await S(e,d,{silent:!0})}))}),V=J(e=>{let t=ov(e),n=sv(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=ov(e);if(R!==t&&R!==sv(t))try{await d.checkoutBranch(p,t),Tt.success(l(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});Tt.error(n)}}),U=J(e=>{let t=ov(e);if(!t||R===t||R===sv(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 o_({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`),Tt.success(l(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),Tt.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);Tt.warning(l(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:t})}),await B()})}catch(e){let t=e instanceof Error?e.message:l(`gitView.toast.createBranchFailed`);throw Tt.error(t),e}}),K=J(()=>{let e=xn.getState(),n=u(t),r=n?e.projects.find(e=>u(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),q=J((e,n)=>{if(M(!1),n?.sessionId){Zr.getState().setCurrentSession(n.sessionId,e);return}let r=xn.getState(),i=u(t),a=(i?r.projects.find(e=>u(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=Zr.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),we.getState().setDirectory(e,{showOverlay:!1});return}o.openNewSessionDraft({...a?{selectedProjectId:a}:{},directoryOverride:e,preserveDirectoryOverride:!0})}),te=(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex min-w-0 w-fit items-center gap-1.5 rounded-lg !border-0 px-1.5 font-medium text-foreground/80`,c===`mobile-sheet`?`h-[26px] text-[11px] leading-none`:`h-6 py-1 pr-1.5 typography-micro transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5`,s,fm,o),"aria-label":z,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:z}),c===`dropdown`?(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`}):null]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(U_,{currentBranch:R,localBranches:I,remoteBranches:L,branchInfo:b?.branches,onCheckout:U,onCreate:G,remotes:E,trigger:te,triggerLabel:z,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:K,open:w,presentation:c,onOpenChange:T}),j?(0,$.jsx)(ev,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:q}):null,(0,$.jsx)(aa,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ta,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(Qi,{children:[(0,$.jsx)(na,{children:l(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(ra,{children:l(`chat.chatInput.branchSwitch.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:k,onClick:()=>{W()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[k?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-left-right`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.checkoutHere`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.checkoutHereDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,disabled:k,onClick:()=>{ee()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[k?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.createWorktree`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.createWorktreeDescription`)})]})]}),(0,$.jsx)($i,{children:(0,$.jsx)(`button`,{type:`button`,disabled:k,onClick:()=>O(null),className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 disabled:opacity-50`,children:l(`chat.chatInput.branchSwitch.cancel`)})})]})})]})},lv=[],uv=[],dv={revertMessageID:void 0,records:uv},fv=e=>e.role===`user`,pv=(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},mv=(e,t,n=dv)=>{if(!t)return dv;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return dv;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!fv(e)||!qt(i,e.id,r)||o.push({message:e,parts:a[e.id]??lv});let s=o.length===0?uv:o;return n.revertMessageID===r&&pv(n.records,s)?n:{revertMessageID:r,records:s}},hv={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},gv={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`},_v=`text-foreground`;function vv(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 yv=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function bv(e){let t=yv.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function xv(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function Sv(e){let t=[];if(!e)return t;let n=0,r=!1,i=``,a=e.split(`
|
|
6522
6522
|
`);for(let e=0;e<a.length;e+=1){let o=a[e],s=n,c=s+o.length;if(n=c+1,r){t.push({start:s,end:c,style:`codeFence`}),xv(o,i)&&(r=!1);continue}let l=bv(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`}),vv(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`}),vv(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;vv(o.slice(r-s),r,t);continue}vv(o,s,t)}return t}function Cv(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??hv[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??gv[l.style]:_v,p=e.slice(n,r),m=l?.visual,h=l?.skillName,g=o[o.length-1];g&&g.className===f&&R(g.visual,m)&&g.skillName===h?g.text+=p:o.push({text:p,className:f,visual:m,skillName:h})}return o.length>0?o:null}function wv(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 Tv(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 Ev(e,t,n){let r=wv(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 Dv(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?re({trigger:`@`,icon:`chat-thread`,label:e.label},H({trigger:`@`,icon:`chat-thread`,label:e.label})):void 0}))}function Ov(e){let t=(0,Q.c)(28),{visual:n,text:r}=e,i=n.trigger.length,a=i+n.label.length,o=a+(n.suffix?.length??0),s;t[0]!==a||t[1]!==i||t[2]!==r?(s=r.slice(i,Math.min(a,r.length)),t[0]=a,t[1]=i,t[2]=r,t[3]=s):s=t[3];let c=s,l;t[4]!==a||t[5]!==o||t[6]!==r?(l=r.slice(a,Math.min(o,r.length)),t[4]=a,t[5]=o,t[6]=r,t[7]=l):l=t[7];let u=l,d;t[8]!==o||t[9]!==r?(d=r.slice(Math.min(o,r.length)),t[8]=o,t[9]=r,t[10]=d):d=t[10];let f=d,p;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p={left:z,right:z},t[11]=p):p=t[11];let m=n.icon,h;t[12]===m?h=t[13]:(h=(0,$.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 inline-flex items-center justify-center`,style:p,children:(0,$.jsx)(X,{name:m,className:`${N} shrink-0 text-[var(--primary)]`,"aria-hidden":`true`})}),t[12]=m,t[13]=h);let g;t[14]!==h||t[15]!==n.trigger?(g=(0,$.jsxs)(`span`,{className:`relative inline-block align-baseline text-transparent leading-none`,children:[n.trigger,h]}),t[14]=h,t[15]=n.trigger,t[16]=g):g=t[16];let _;t[17]===c?_=t[18]:(_=(0,$.jsx)(`span`,{children:c}),t[17]=c,t[18]=_);let v;t[19]===u?v=t[20]:(v=u?(0,$.jsx)(`span`,{className:`text-transparent`,children:u}):null,t[19]=u,t[20]=v);let y;t[21]===f?y=t[22]:(y=f?(0,$.jsx)(`span`,{className:`text-transparent`,children:f}):null,t[21]=f,t[22]=y);let b;return t[23]!==y||t[24]!==g||t[25]!==_||t[26]!==v?(b=(0,$.jsxs)($.Fragment,{children:[g,_,v,y]}),t[23]=y,t[24]=g,t[25]=_,t[26]=v,t[27]=b):b=t[27],b}var kv=`bg-[var(--surface-subtle)]`,Av=91,jv=94,Mv={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},Nv={keyword:`${kv} text-[var(--syntax-keyword)]`,string:`${kv} text-[var(--syntax-string)]`,number:`${kv} text-[var(--syntax-number)]`,comment:`${kv} text-[var(--syntax-comment)]`,function:`${kv} text-[var(--syntax-function)]`,type:`${kv} text-[var(--syntax-type)]`,variable:`${kv} text-[var(--syntax-variable)]`,operator:`${kv} text-[var(--syntax-operator)]`},Pv=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`}]),Fv=e=>{let t=null;for(let n of e.split(` `)){let e=n;Mv[e]!==void 0&&(t===null||Mv[e]>Mv[t])&&(t=e)}return t?Nv[t]:null},Iv=2e4,Lv=e=>{if(!e)return null;try{let t=io(e);return t instanceof Qe?t:null}catch{return null}};function Rv(e){if(!e||!e.includes("```")&&!e.includes(`~~~`))return[];let t=[],n=e.split(`
|
|
6523
6523
|
`),r=0;for(let e=0;e<n.length;e+=1){let i=n[e];r+=i.length+1;let a=bv(i);if(!a)continue;let o=Lv(a.lang),s=r,c=[],l=e+1,u=r;for(;l<n.length;l+=1){let e=n[l];if(xv(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:`${kv} text-[var(--syntax-foreground)]`,priority:Av}),!(d.length>Iv)))try{let e=o.parser.parse(d);Xe(e,Pv,(e,n,r)=>{let i=Fv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:jv})})}catch{}}return t}var zv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Bv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Vv=e=>{if(!Bv(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(`/`)},Hv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Vv(n):Bv(n))?n:null},Uv=(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)Uv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))Uv(r,t,n+1)}},Wv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Hv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Hv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;Uv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Gv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of zv){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 Wv(r,i))t.add(e)}return Array.from(t)},Kv=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}}},qv=e=>Bv(e);function Jv(e,t){let n=(0,Q.c)(5),r=pt(e,t),i=s(Yv),a;n[0]===r?a=n[1]:(a=ln(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 Yv(e){return e.sessionGoalEnabled}function Xv(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 Zv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},Qv={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`},$v=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ot(),i=s(e=>e.isMobile),{goal:a,enabled:o}=Jv(e??``,t),c=Xv(e??``,a),l=wr(e??``,t),u=On(e,t),d=Z.useRef(null),[f,p]=Z.useState(!1),[m,h]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>h(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=u[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;d.current!==r&&(d.current=r,Dt(e,t))},[e,t,a,u]);let g=J(async n=>{if(!(!e||f)){p(!0);try{await _n(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Tt.error(r(`chat.goal.toast.actionFailed`))}finally{p(!1)}}});if(!e||!o||!a)return null;let _=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:m)-(a.createdAt||m)),v=mt(_),y=a.tokenBudget?`${Hr(a.tokensUsed)}/${Hr(a.tokenBudget)}`:a.tokensUsed>0?Hr(a.tokensUsed):null,b=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:c??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:Zv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||c||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(Qv[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:v}),y?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:y}):null,b?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void g(b.next),disabled:f,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(b.labelKey),children:[(0,$.jsx)(X,{name:b.icon,className:C,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(b.labelKey)})]}):null]})});$v.displayName=`SessionGoalRow`;var ey=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ot(),{goal:i,enabled:a}=Jv(e??``,t),o=Sn(e=>e.armed),s=Sn(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Fn(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Tt.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void f(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});ey.displayName=`SessionGoalButton`;var ty=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ot();if(!Sn(ny)||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,`/`,Kr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});ty.displayName=`SessionGoalObjectiveCounter`;function ny(e){return e.armed}var ry=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),iy=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),ay=/^\/\u2003?([^\s]+)/i,oy=/^\/\u2003?goal\b/i,sy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(ay)?.[1]?.toLowerCase();return n&&ry.has(n)?n:null},cy=(e,t)=>sy(e,t)===`goal`?e.trimStart().replace(oy,``).trim():null,ly=(e,t)=>sy(e,t)!==null,uy=(e,t)=>{let n=sy(e,t);return n!==null&&iy.has(n)},dy=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},fy=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()}},py=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,my=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,hy=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},gy=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),_y=(e,t)=>{let n=C.getState();return n.bindLegacyQueue(x(e.sessionID),e),n.stageAdmission(e,{requestID:t.requestID,queueItemID:t.queueItemID,operationID:t.operationID,messageID:t.messageID,content:t.content,createdAt:t.createdAt,attachmentCount:t.attachments.length,...t.composerDocument?{composerDocument:t.composerDocument}:{},...t.composerMentions?{composerMentions:t.composerMentions}:{}}),n.confirmAdmission(e,{requestID:t.requestID,sendConfig:t.sendConfig,attachments:t.attachments}).ok},vy=async e=>{let t=gn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=gy(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}_y(n,a)?r+=1:i+=1}catch{try{_y(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},yy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),by=e=>e===`allow`||e===`ask`||e===`deny`,xy=e=>{if(by(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`&&by(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(by(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))by(i)&&t.push({permission:n,pattern:e,action:i})}return t},Sy=e=>{let t=xy(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},Cy=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Sy(e.permission));let r=e.find(e=>e?.name===n);return!r||Sy(r.permission)},wy=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)},Ty=null,Ey=new Set,Dy=()=>{for(let e of Ey)e()},Oy=e=>e===`chat`||e===`assistant`,ky=()=>Ty,Ay=e=>{Ty!==e&&(Ty=e,Dy())},jy=e=>{Ty&&(e&&Ty.surfaceID!==e||(Ty=null,Dy()))},My=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Ny=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}},Py=(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}),Fy=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=Py(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=Py(e,`send`,i),o=Um(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=Py(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Py(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Py(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Um(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Im(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=Py(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Py(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Iy=(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)))},Ly=(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},Ry=(e,t)=>e.agents.some(e=>e.name===t),zy=(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},By=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return zy(t,n,r,i)?i:void 0;if(a&&zy(t,n,r,a))return a},Vy=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,sessionEntity:a,fallbackAgentName:o,transcriptReady:s=!0}=e;if(s&&n?.providerID&&n.modelID&&Ly(r,n.providerID,n.modelID)){let e=n.agent&&Ry(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Ry(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):o&&Ry(r,o)?o:void 0,a=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=By({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:a});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(s&&i){let e=i.getSessionAgentSelection?.(t)??null,n=e&&Ry(r,e)?e:o&&Ry(r,o)?o:void 0;if(n){let e=i.getAgentModelForSession?.(t,n);if(e&&Ly(r,e.providerId,e.modelId)){let a=i.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=a&&zy(r,e.providerId,e.modelId,a)?a:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let a=i.getSessionModelSelection?.(t);if(a&&Ly(r,a.providerId,a.modelId)){let e=n?i.getAgentModelVariantForSession?.(t,n,a.providerId,a.modelId):void 0,o=e&&zy(r,a.providerId,a.modelId,e)?e:void 0;return{agent:n,providerID:a.providerId,modelID:a.modelId,variant:o,source:`session-memory`}}}let c=a?.model;if(c&&Ly(r,c.providerID,c.id)){let e=i?.getSessionAgentSelection?.(t)??null,n=(a?.agent&&Ry(r,a.agent)?a.agent:void 0)??(e&&Ry(r,e)?e:o&&Ry(r,o)?o:void 0),s=c.variant,l=s&&zy(r,c.providerID,c.id,s)?s:void 0;return{agent:n,providerID:c.providerID,modelID:c.id,variant:l,source:`session-entity`}}return null},Hy=(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))},Uy=(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}},Wy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Gy=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}:{}}},Ky=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=typeof n.model?.providerID==`string`&&n.model.providerID.trim().length>0?n.model.providerID:void 0,i=typeof n.model?.modelID==`string`&&n.model.modelID.trim().length>0?n.model.modelID:void 0,a=typeof n.agent==`string`&&n.agent.trim().length>0?n.agent:typeof n.mode==`string`&&n.mode.trim().length>0?n.mode:void 0,o=n.model?.variant??n.variant,s=typeof o==`string`&&o.trim().length>0?o:void 0;return{id:typeof n.id==`string`?n.id:void 0,agent:a,providerID:r,modelID:i,variant:s}}return null},qy=500,Jy=e=>Array.from(e).length,Yy=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},Xy=e=>Jy(e)>=qy,Zy=e=>{let t=v(e.text,e.references).document.references,n=t.reduce((e,t)=>{let n=t.kind===`paste`?t.index:0;return typeof n==`number`&&Number.isSafeInteger(n)&&n>=1?Math.max(e,n):e},0);if(n<2**53-1)return n+1;let r=new Set(t.flatMap(e=>e.kind===`paste`&&typeof e.index==`number`&&Number.isSafeInteger(e.index)&&e.index>=1?[e.index]:[]));for(let e=1;e<=t.length+1;e+=1)if(!r.has(e))return e;return 1},Qy=(e,t)=>{let n=t??e;return typeof n!=`string`||!Xy(n)?!1:le(typeof e==`string`?{text:``,references:[]}:e,n)},$y=(e,t,n,r,i=1)=>{let a=Jy(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}-${Yy(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},eb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),tb=e=>e.map(e=>({...e,range:{...e.range}})),nb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),rb=(e,t,n)=>({document:eb(e),mentions:tb(t),selection:{...n}}),ib=()=>({undo:[],redo:[]}),ab=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),ob=(e,t)=>{let n=e.undo.at(-1);return!n||!nb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:rb(n.before.document,n.before.mentions,n.before.selection)}},sb=(e,t)=>{let n=e.redo.at(-1);return!n||!nb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:rb(n.after.document,n.after.mentions,n.after.selection)}},cb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),lb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),ub=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),db=e=>JSON.stringify([e.text,e.references]),fb=(e,t)=>e!==null&&t!==null&&ce(e)===t,pb=(e,t,n)=>{let r=e?ub(e):null,i=r?n(r):void 0;return{document:D(cb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ce(r):null}},mb=(e,t,n,r)=>{if(!t||ce(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=db(cb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===db(e)?`same-document-metadata`:`external-document`},hb=(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}]:[]})},gb=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),_b=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:hb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},vb=(e,t,n)=>({preview:{real:lb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),yb=e=>({document:e.real,mentions:e.realMentions}),bb=(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)})},xb=(e,t)=>{let n=cb(t),r=E(e.document,n),i=e.document.text===n.text&&JSON.stringify(e.document.references)===JSON.stringify(n.references)?0:e.document.text.length+2;return{document:r,mentions:bb(e.mentions,t?.mentions??[],r,i)}},Sb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=on})=>{let a=e?ce(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>pb(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>pb(e,t,i.getState().getDraft).mentions),[m,h]=(0,Z.useState)(`compose`),[_,b]=(0,Z.useState)(0),x=(0,Z.useRef)(l),S=(0,Z.useRef)(d),C=(0,Z.useRef)(t),w=(0,Z.useRef)(r),T=(0,Z.useRef)(e),E=(0,Z.useRef)(e?ub(e):null),k=(0,Z.useRef)(a),A=(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)(ib());x.current=l,S.current=d,C.current=t,w.current=r,T.current=e,k.current=a;let L=(0,Z.useCallback)((e,t)=>{x.current=e,S.current=t,u(e),p(t)},[]),R=(0,Z.useCallback)((e,t)=>{let n=j(e,t);w.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{M.current+=1;let e=M.current;A.current=a;let t=pb(T.current,C.current,i.getState().getDraft),n=t.key;if(E.current=t.key,P.current=void 0,F.current=void 0,I.current=ib(),h(`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||!fb(E.current,a)||A.current!==a||k.current!==a||M.current!==e||N.current!==r||o?.revision!==t.revision||(N.current=t.revision,L(D(cb(t),C.current),t.mentions))})}},[a,L,i]),(0,Z.useEffect)(()=>{if(!a||A.current!==a||F.current)return;let e=mb(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&&p(o.mentions);return}e===`external-document`&&o&&(P.current=void 0,L(D(cb(o),C.current),o.mentions),h(`compose`),b(e=>e+1))}},[a,L,o]);let z=(0,Z.useCallback)((e,t)=>{let n=E.current;if(!fb(n,k.current)||F.current)return;let r=x.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:gb(t)});if(!a)return;let o=cb(a);return P.current={keyID:ce(n),revision:a.revision,fingerprint:db(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=ab(I.current,{before:rb(e,t,n),after:rb(r,i,a)})},[]),V=(0,Z.useCallback)(()=>F.current?(F.current=void 0,h(`compose`),!0):!1,[]),H=(0,Z.useCallback)(e=>(V(),z({text:e,references:[]},[])),[z,V]),U=(0,Z.useCallback)((e,t=[])=>{V();let n=ae(e.text,e.references);return n?z(D(n,C.current),t):void 0},[z,V]),W=(0,Z.useCallback)((e,t,n=t,r)=>{let i=V(),a=lb(x.current),o=i?[]:S.current,s=_b(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=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=hb(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=f(x.current,e,t,n,r);return z(a.document,hb(i?[]:S.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[z,V]),q=(0,Z.useCallback)(e=>{let t=lb(x.current),n=y(t,e);if(!n)return null;let r=V()?[]:S.current,i=hb(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=hb(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]),te=(0,Z.useCallback)(e=>{if(F.current)return null;let t=e===`undo`?ob(I.current,x.current):sb(I.current,x.current);return!t||!z(t.snapshot.document,t.snapshot.mentions)?null:(I.current=t.history,t.snapshot.selection)},[z]),ne=(0,Z.useCallback)(e=>z(x.current,e),[z]),re=(0,Z.useCallback)(e=>{let t=F.current?{document:{text:e.text,references:[]},mentions:[]}:vb(x.current,S.current,e);`preview`in t&&(F.current=t.preview),h(`history-preview`),L(t.document,t.mentions),b(e=>e+1)},[L]),ie=(0,Z.useCallback)(()=>{let e=F.current;if(!e)return;F.current=void 0,h(`compose`);let t=yb(e);L(t.document,t.mentions),b(e=>e+1)},[L]),oe=(0,Z.useCallback)(()=>{let e=E.current;if(!fb(e,k.current))return null;let t=i.getState().getDraft(e);return{key:ub(e),keyID:ce(e),revision:t?.revision??0,document:lb(x.current),mentions:S.current.map(e=>({...e,range:{...e.range}})),epoch:M.current,runtime:i.getState().captureDraftRuntime()}},[i]),se=(0,Z.useCallback)(e=>{let t=xb(e,i.getState().getDraft(e.key)),n=cb(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:gb(t.mentions)});if(a){let e=cb(a);R(r,e)}return a},[R,i]),le=(0,Z.useCallback)(()=>x.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:m,hydration:s,persistence:c,textPresetEpoch:_,getDocument:le,replacePlainDocument:H,replaceMaterializedDocument:U,applyBrowserEdit:W,applyProgrammaticEdit:ee,replaceProgrammaticText:G,insertReference:K,deleteReference:q,restoreReferenceHistory:te,commitMentions:ne,enterHistoryPreview:re,exitHistoryPreview:ie,captureSubmission:oe,recoverSubmission:se}),[W,ee,oe,ne,q,l,re,ie,le,s,m,K,d,c,se,U,H,G,te,_])};function Cb(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 wb=`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`,Tb=Is(()=>Ue(()=>import(`./ToolOutputDialog-DPz8gn8_.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]))),Eb=[],Db=[],Ob=[],kb=[],Ab=/^@[^\s]+$/,jb=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Mb=/^(https?:\/\/|mailto:)\S+$/i,Nb=560,Pb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Fb=(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)},Ib=e=>e.includes(`@`)?`paste`:`manual`,Lb=(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}},Rb=(e,t)=>pi(e,t).some(e=>e.role===`user`),zb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!tr(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},Bb=`file://`,Vb=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(`/`)},Hb=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Bb)?t:`file://${Vb(t)}`},Ub=e=>{if(!e)return[];let t=[...Gv(e).map(Kv),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(qv)))},Wb=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},Gb=e=>oa(e.path),Kb=(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)]})},qb=Z.memo(lh),Jb=Z.memo(eu),Yb=Z.memo(Cg),Xb=Z.memo(Eg),Zb=Z.memo(zh),Qb=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ot(),r=s(e=>e.isMobile),i=Zr(e=>e.revertToMessage),a=Zr(e=>e.forkFromMessage),o=Zr(e=>e.handleSlashRedo),[c,l]=Z.useState(null),[u,d]=Z.useState(null),[f,p]=Z.useState(!0),m=Z.useRef(dv),h=cr(),g=t||h,_=Ht(g),v=Ki(e??``,g,_),y=nn(e=>e.session,g),b=Z.useMemo(()=>{let t=v.messageOrder.map(e=>v.messagesByID[e]).filter(e=>!!e),n=mv({session:y,messages:t,partsByMessageID:v.partsByMessageID},e,m.current);return m.current=n,n},[e,y,v]),x=b.revertMessageID,S=Z.useMemo(()=>b.records.map(e=>e.message),[b]),C=n(`chat.revertPopover.noTextContent`),w=Z.useMemo(()=>x?b.records.map(e=>({id:e.message.id,text:zb(e.parts,C)})):[],[C,x,b]),T=w[0]?.id;Z.useEffect(()=>{p(!0)},[x,T]);let E=Z.useCallback(async t=>{if(!(!e||c)){l(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{l(null)}}},[o,i,c,e,S]),D=Z.useCallback(async t=>{if(!(!e||u)){d(t);try{await a(e,t)}finally{d(null)}}},[a,u,e]);return!e||w.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>p(e=>!e),"aria-expanded":!f,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!f&&`rotate-180`),"aria-hidden":`true`})]}),!f&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:w.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(ca,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{D(e.id)},children:[u===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(ca,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{E(e.id)},children:[c===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});Qb.displayName=`RevertedMessageDock`;var $b=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=ot(),{isVSCode:r,footerIconButtonClass:i,iconSizeClass:a,handlePickLocalFiles:o,openIssuePicker:s,openPrPicker:c,onOpenSettings:l,withTooltip:u}=e,d=u!==void 0&&u,f=!!e.onOpenMobileSheet,p;t[0]===n?p=t[1]:(p=n(`chat.chatInput.actions.attachFiles`),t[0]=n,t[1]=p);let m=p,h=o,g;t[2]!==h||t[3]!==e?(g=()=>e.onOpenAndroidPickSheet?e.onOpenAndroidPickSheet():h(),t[2]=h,t[3]=e,t[4]=g):g=t[4];let _=f?lx:void 0,v=f?ux: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)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:S}),(0,$.jsx)(Va,{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),ex=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=ot(),r=e.enabled?`chat.chatInput.permissionAutoAccept.disable`:`chat.chatInput.permissionAutoAccept.enable`,i;t[0]!==n||t[1]!==r?(i=n(r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o=e.saving,s=e.enabled,c=e.footerIconButtonClass,l;t[3]!==e.draftEnabled||t[4]!==e.draftOpen||t[5]!==e.enabled||t[6]!==e.onOpenSessionFirst||t[7]!==e.onSetDraftEnabled||t[8]!==e.onSetSessionEnabled||t[9]!==e.onToggleFailed||t[10]!==e.sessionId?(l=()=>wy({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)(Ba,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:dx,onPointerDownCapture:fx,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)(Va,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Ha,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),tx=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}=ot(),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=Hg({canSend:l,hasSessionTarget:!!(f||p),draftSubmitting:!!m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:px,onPointerDownCapture:mx}:{},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)(Fg,{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)(Fg,{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)(Pg,{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),nx=(e,t)=>`${e}${e?e.endsWith(`
|
|
6524
|
+
`);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${kv} text-[var(--syntax-foreground)]`,priority:Av}),!(d.length>Iv)))try{let e=o.parser.parse(d);Xe(e,Pv,(e,n,r)=>{let i=Fv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:jv})})}catch{}}return t}var zv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Bv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Vv=e=>{if(!Bv(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(`/`)},Hv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Vv(n):Bv(n))?n:null},Uv=(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)Uv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))Uv(r,t,n+1)}},Wv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Hv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Hv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;Uv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Gv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of zv){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 Wv(r,i))t.add(e)}return Array.from(t)},Kv=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}}},qv=e=>Bv(e);function Jv(e,t){let n=(0,Q.c)(5),r=pt(e,t),i=s(Yv),a;n[0]===r?a=n[1]:(a=ln(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 Yv(e){return e.sessionGoalEnabled}function Xv(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 Zv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},Qv={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`},$v=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ot(),i=s(e=>e.isMobile),{goal:a,enabled:o}=Jv(e??``,t),c=Xv(e??``,a),l=wr(e??``,t),u=On(e,t),d=Z.useRef(null),[f,p]=Z.useState(!1),[m,h]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>h(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=u[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;d.current!==r&&(d.current=r,Dt(e,t))},[e,t,a,u]);let g=J(async n=>{if(!(!e||f)){p(!0);try{await _n(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Tt.error(r(`chat.goal.toast.actionFailed`))}finally{p(!1)}}});if(!e||!o||!a)return null;let _=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:m)-(a.createdAt||m)),v=mt(_),y=a.tokenBudget?`${Hr(a.tokensUsed)}/${Hr(a.tokenBudget)}`:a.tokensUsed>0?Hr(a.tokensUsed):null,b=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:c??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:Zv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||c||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(Qv[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:v}),y?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,x,`text-muted-foreground/70`),children:y}):null,b?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void g(b.next),disabled:f,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(b.labelKey),children:[(0,$.jsx)(X,{name:b.icon,className:C,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(b.labelKey)})]}):null]})});$v.displayName=`SessionGoalRow`;var ey=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ot(),{goal:i,enabled:a}=Jv(e??``,t),o=Sn(e=>e.armed),s=Sn(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Fn(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Tt.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void f(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});ey.displayName=`SessionGoalButton`;var ty=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ot();if(!Sn(ny)||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,`/`,Kr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});ty.displayName=`SessionGoalObjectiveCounter`;function ny(e){return e.armed}var ry=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),iy=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),ay=/^\/\u2003?([^\s]+)/i,oy=/^\/\u2003?goal\b/i,sy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(ay)?.[1]?.toLowerCase();return n&&ry.has(n)?n:null},cy=(e,t)=>sy(e,t)===`goal`?e.trimStart().replace(oy,``).trim():null,ly=(e,t)=>sy(e,t)!==null,uy=(e,t)=>{let n=sy(e,t);return n!==null&&iy.has(n)},dy=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},fy=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()}},py=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,my=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,hy=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},gy=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),_y=(e,t)=>{let n=C.getState();return n.bindLegacyQueue(x(e.sessionID),e),n.stageAdmission(e,{requestID:t.requestID,queueItemID:t.queueItemID,operationID:t.operationID,messageID:t.messageID,content:t.content,createdAt:t.createdAt,attachmentCount:t.attachments.length,...t.composerDocument?{composerDocument:t.composerDocument}:{},...t.composerMentions?{composerMentions:t.composerMentions}:{}}),n.confirmAdmission(e,{requestID:t.requestID,sendConfig:t.sendConfig,attachments:t.attachments}).ok},vy=async e=>{let t=gn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=gy(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}_y(n,a)?r+=1:i+=1}catch{try{_y(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},yy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),by=e=>e===`allow`||e===`ask`||e===`deny`,xy=e=>{if(by(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`&&by(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(by(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))by(i)&&t.push({permission:n,pattern:e,action:i})}return t},Sy=e=>{let t=xy(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},Cy=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Sy(e.permission));let r=e.find(e=>e?.name===n);return!r||Sy(r.permission)},wy=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)},Ty=null,Ey=new Set,Dy=()=>{for(let e of Ey)e()},Oy=e=>e===`chat`||e===`assistant`,ky=()=>Ty,Ay=e=>{Ty!==e&&(Ty=e,Dy())},jy=e=>{Ty&&(e&&Ty.surfaceID!==e||(Ty=null,Dy()))},My=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Ny=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}},Py=(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}),Fy=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=Py(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=Py(e,`send`,i),o=Um(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=Py(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Py(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Py(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Um(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Im(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=Py(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Py(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Iy=(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)))},Ly=(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},Ry=(e,t)=>e.agents.some(e=>e.name===t),zy=(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},By=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return zy(t,n,r,i)?i:void 0;if(a&&zy(t,n,r,a))return a},Vy=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!Ly(r,n.providerID,n.modelID))return null;let s=n.agent&&Ry(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Ry(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Ry(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=By({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}},Hy=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=Vy({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=Vy({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&&Ry(i,e)?e:s&&Ry(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&Ly(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&zy(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&&Ly(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&zy(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&&Ly(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&Ry(i,o.agent)?o.agent:void 0)??(e&&Ry(i,e)?e:s&&Ry(i,s)?s:void 0),r=l.variant,c=r&&zy(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},Uy=(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))},Wy=(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}},Gy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Ky=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}:{}}},qy=e=>typeof e==`string`&&e.trim().length>0?e:void 0,Jy=e=>qy(e.agent)??qy(e.mode),Yy=e=>qy(e.model?.variant)??qy(e.variant),Xy=e=>{let t=qy(e.model?.providerID),n=qy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},Zy=e=>{let t=qy(e.providerID)??qy(e.model?.providerID),n=qy(e.modelID)??qy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},Qy=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=Xy(n);return{id:typeof n.id==`string`?n.id:void 0,agent:Jy(n),providerID:r?.providerID,modelID:r?.modelID,variant:Yy(n)}}return null},$y=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`user`){if(Xy(n))return null;continue}if(n.role!==`assistant`)continue;let r=Zy(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:Jy(n),providerID:r.providerID,modelID:r.modelID,variant:Yy(n)}}return null},eb=500,tb=e=>Array.from(e).length,nb=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},rb=e=>tb(e)>=eb,ib=e=>{let t=v(e.text,e.references).document.references,n=t.reduce((e,t)=>{let n=t.kind===`paste`?t.index:0;return typeof n==`number`&&Number.isSafeInteger(n)&&n>=1?Math.max(e,n):e},0);if(n<2**53-1)return n+1;let r=new Set(t.flatMap(e=>e.kind===`paste`&&typeof e.index==`number`&&Number.isSafeInteger(e.index)&&e.index>=1?[e.index]:[]));for(let e=1;e<=t.length+1;e+=1)if(!r.has(e))return e;return 1},ab=(e,t)=>{let n=t??e;return typeof n!=`string`||!rb(n)?!1:le(typeof e==`string`?{text:``,references:[]}:e,n)},ob=(e,t,n,r,i=1)=>{let a=tb(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}-${nb(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},sb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),cb=e=>e.map(e=>({...e,range:{...e.range}})),lb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),ub=(e,t,n)=>({document:sb(e),mentions:cb(t),selection:{...n}}),db=()=>({undo:[],redo:[]}),fb=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),pb=(e,t)=>{let n=e.undo.at(-1);return!n||!lb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:ub(n.before.document,n.before.mentions,n.before.selection)}},mb=(e,t)=>{let n=e.redo.at(-1);return!n||!lb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:ub(n.after.document,n.after.mentions,n.after.selection)}},hb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),gb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),_b=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),vb=e=>JSON.stringify([e.text,e.references]),yb=(e,t)=>e!==null&&t!==null&&ce(e)===t,bb=(e,t,n)=>{let r=e?_b(e):null,i=r?n(r):void 0;return{document:D(hb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ce(r):null}},xb=(e,t,n,r)=>{if(!t||ce(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=vb(hb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===vb(e)?`same-document-metadata`:`external-document`},Sb=(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}]:[]})},Cb=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),wb=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:Sb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},Tb=(e,t,n)=>({preview:{real:gb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Eb=e=>({document:e.real,mentions:e.realMentions}),Db=(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)})},Ob=(e,t)=>{let n=hb(t),r=E(e.document,n),i=e.document.text===n.text&&JSON.stringify(e.document.references)===JSON.stringify(n.references)?0:e.document.text.length+2;return{document:r,mentions:Db(e.mentions,t?.mentions??[],r,i)}},kb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=on})=>{let a=e?ce(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>bb(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>bb(e,t,i.getState().getDraft).mentions),[m,h]=(0,Z.useState)(`compose`),[_,b]=(0,Z.useState)(0),x=(0,Z.useRef)(l),S=(0,Z.useRef)(d),C=(0,Z.useRef)(t),w=(0,Z.useRef)(r),T=(0,Z.useRef)(e),E=(0,Z.useRef)(e?_b(e):null),k=(0,Z.useRef)(a),A=(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)(db());x.current=l,S.current=d,C.current=t,w.current=r,T.current=e,k.current=a;let L=(0,Z.useCallback)((e,t)=>{x.current=e,S.current=t,u(e),p(t)},[]),R=(0,Z.useCallback)((e,t)=>{let n=j(e,t);w.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{M.current+=1;let e=M.current;A.current=a;let t=bb(T.current,C.current,i.getState().getDraft),n=t.key;if(E.current=t.key,P.current=void 0,F.current=void 0,I.current=db(),h(`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||!yb(E.current,a)||A.current!==a||k.current!==a||M.current!==e||N.current!==r||o?.revision!==t.revision||(N.current=t.revision,L(D(hb(t),C.current),t.mentions))})}},[a,L,i]),(0,Z.useEffect)(()=>{if(!a||A.current!==a||F.current)return;let e=xb(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&&p(o.mentions);return}e===`external-document`&&o&&(P.current=void 0,L(D(hb(o),C.current),o.mentions),h(`compose`),b(e=>e+1))}},[a,L,o]);let z=(0,Z.useCallback)((e,t)=>{let n=E.current;if(!yb(n,k.current)||F.current)return;let r=x.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Cb(t)});if(!a)return;let o=hb(a);return P.current={keyID:ce(n),revision:a.revision,fingerprint:vb(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=fb(I.current,{before:ub(e,t,n),after:ub(r,i,a)})},[]),V=(0,Z.useCallback)(()=>F.current?(F.current=void 0,h(`compose`),!0):!1,[]),H=(0,Z.useCallback)(e=>(V(),z({text:e,references:[]},[])),[z,V]),U=(0,Z.useCallback)((e,t=[])=>{V();let n=ae(e.text,e.references);return n?z(D(n,C.current),t):void 0},[z,V]),W=(0,Z.useCallback)((e,t,n=t,r)=>{let i=V(),a=gb(x.current),o=i?[]:S.current,s=wb(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=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=Sb(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=f(x.current,e,t,n,r);return z(a.document,Sb(i?[]:S.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[z,V]),q=(0,Z.useCallback)(e=>{let t=gb(x.current),n=y(t,e);if(!n)return null;let r=V()?[]:S.current,i=Sb(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=Sb(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]),te=(0,Z.useCallback)(e=>{if(F.current)return null;let t=e===`undo`?pb(I.current,x.current):mb(I.current,x.current);return!t||!z(t.snapshot.document,t.snapshot.mentions)?null:(I.current=t.history,t.snapshot.selection)},[z]),ne=(0,Z.useCallback)(e=>z(x.current,e),[z]),re=(0,Z.useCallback)(e=>{let t=F.current?{document:{text:e.text,references:[]},mentions:[]}:Tb(x.current,S.current,e);`preview`in t&&(F.current=t.preview),h(`history-preview`),L(t.document,t.mentions),b(e=>e+1)},[L]),ie=(0,Z.useCallback)(()=>{let e=F.current;if(!e)return;F.current=void 0,h(`compose`);let t=Eb(e);L(t.document,t.mentions),b(e=>e+1)},[L]),oe=(0,Z.useCallback)(()=>{let e=E.current;if(!yb(e,k.current))return null;let t=i.getState().getDraft(e);return{key:_b(e),keyID:ce(e),revision:t?.revision??0,document:gb(x.current),mentions:S.current.map(e=>({...e,range:{...e.range}})),epoch:M.current,runtime:i.getState().captureDraftRuntime()}},[i]),se=(0,Z.useCallback)(e=>{let t=Ob(e,i.getState().getDraft(e.key)),n=hb(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Cb(t.mentions)});if(a){let e=hb(a);R(r,e)}return a},[R,i]),le=(0,Z.useCallback)(()=>x.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:m,hydration:s,persistence:c,textPresetEpoch:_,getDocument:le,replacePlainDocument:H,replaceMaterializedDocument:U,applyBrowserEdit:W,applyProgrammaticEdit:ee,replaceProgrammaticText:G,insertReference:K,deleteReference:q,restoreReferenceHistory:te,commitMentions:ne,enterHistoryPreview:re,exitHistoryPreview:ie,captureSubmission:oe,recoverSubmission:se}),[W,ee,oe,ne,q,l,re,ie,le,s,m,K,d,c,se,U,H,G,te,_])};function Ab(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 jb=`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`,Mb=Is(()=>Ue(()=>import(`./ToolOutputDialog-cDDD9uCL.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]))),Nb=[],Pb=[],Fb=[],Ib=[],Lb=/^@[^\s]+$/,Rb=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),zb=/^(https?:\/\/|mailto:)\S+$/i,Bb=560,Vb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Hb=(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)},Ub=e=>e.includes(`@`)?`paste`:`manual`,Wb=(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}},Gb=(e,t)=>pi(e,t).some(e=>e.role===`user`),Kb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!tr(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},qb=`file://`,Jb=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(`/`)},Yb=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(qb)?t:`file://${Jb(t)}`},Xb=e=>{if(!e)return[];let t=[...Gv(e).map(Kv),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(qv)))},Zb=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},Qb=e=>oa(e.path),$b=(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)]})},ex=Z.memo(lh),tx=Z.memo(eu),nx=Z.memo(Cg),rx=Z.memo(Eg),ix=Z.memo(zh),ax=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ot(),r=s(e=>e.isMobile),i=Zr(e=>e.revertToMessage),a=Zr(e=>e.forkFromMessage),o=Zr(e=>e.handleSlashRedo),[c,l]=Z.useState(null),[u,d]=Z.useState(null),[f,p]=Z.useState(!0),m=Z.useRef(dv),h=cr(),g=t||h,_=Ht(g),v=Ki(e??``,g,_),y=nn(e=>e.session,g),b=Z.useMemo(()=>{let t=v.messageOrder.map(e=>v.messagesByID[e]).filter(e=>!!e),n=mv({session:y,messages:t,partsByMessageID:v.partsByMessageID},e,m.current);return m.current=n,n},[e,y,v]),x=b.revertMessageID,S=Z.useMemo(()=>b.records.map(e=>e.message),[b]),C=n(`chat.revertPopover.noTextContent`),w=Z.useMemo(()=>x?b.records.map(e=>({id:e.message.id,text:Kb(e.parts,C)})):[],[C,x,b]),T=w[0]?.id;Z.useEffect(()=>{p(!0)},[x,T]);let E=Z.useCallback(async t=>{if(!(!e||c)){l(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{l(null)}}},[o,i,c,e,S]),D=Z.useCallback(async t=>{if(!(!e||u)){d(t);try{await a(e,t)}finally{d(null)}}},[a,u,e]);return!e||w.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>p(e=>!e),"aria-expanded":!f,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!f&&`rotate-180`),"aria-hidden":`true`})]}),!f&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:w.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(ca,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{D(e.id)},children:[u===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(ca,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{E(e.id)},children:[c===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});ax.displayName=`RevertedMessageDock`;var ox=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=ot(),{isVSCode:r,footerIconButtonClass:i,iconSizeClass:a,handlePickLocalFiles:o,openIssuePicker:s,openPrPicker:c,onOpenSettings:l,withTooltip:u}=e,d=u!==void 0&&u,f=!!e.onOpenMobileSheet,p;t[0]===n?p=t[1]:(p=n(`chat.chatInput.actions.attachFiles`),t[0]=n,t[1]=p);let m=p,h=o,g;t[2]!==h||t[3]!==e?(g=()=>e.onOpenAndroidPickSheet?e.onOpenAndroidPickSheet():h(),t[2]=h,t[3]=e,t[4]=g):g=t[4];let _=f?gx:void 0,v=f?_x: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)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:S}),(0,$.jsx)(Va,{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),sx=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=ot(),r=e.enabled?`chat.chatInput.permissionAutoAccept.disable`:`chat.chatInput.permissionAutoAccept.enable`,i;t[0]!==n||t[1]!==r?(i=n(r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o=e.saving,s=e.enabled,c=e.footerIconButtonClass,l;t[3]!==e.draftEnabled||t[4]!==e.draftOpen||t[5]!==e.enabled||t[6]!==e.onOpenSessionFirst||t[7]!==e.onSetDraftEnabled||t[8]!==e.onSetSessionEnabled||t[9]!==e.onToggleFailed||t[10]!==e.sessionId?(l=()=>wy({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)(Ba,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:vx,onPointerDownCapture:yx,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)(Va,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Ha,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),cx=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}=ot(),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=Hg({canSend:l,hasSessionTarget:!!(f||p),draftSubmitting:!!m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:bx,onPointerDownCapture:xx}:{},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)(Fg,{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)(Fg,{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)(Pg,{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),lx=(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{A as t,E as n,P as r,T
|
|
|
6531
6531
|
`:``}${t.endsWith(`
|
|
6532
6532
|
|
|
6533
6533
|
`)?t:t.endsWith(`
|
|
6534
|
-
`)?`${t}\n`:`${t}\n\n`}`,rx=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},ix=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,ax=[],ox=({onOpenSettings:e,scrollToBottom:r,showScrollToBottom:a=!1,onScrollToBottom:o,submissionBlocked:l=!1,surface:u})=>{let{t:f}=ot(),[p,m]=Z.useState({open:!1,title:``,content:``}),[h,g]=Z.useState(`normal`),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(!1),[k,j]=Z.useState(``),[M,N]=Z.useState(!1),[P,I]=Z.useState(``),[R,z]=Z.useState(!1),[V,H]=Z.useState(``),[q,te]=Z.useState(!1),[ie,ae]=Z.useState(``),[oe,se]=Z.useState([]),[le,ue]=Z.useState(0),[de,fe]=Z.useState(null),[pe,me]=Z.useState(null),he=Z.useRef(null),ge=Z.useRef(null),[_e,ve]=Z.useState(!1),ye=Z.useRef(null);Z.useEffect(()=>()=>{ye.current!==null&&window.clearTimeout(ye.current),he.current!==null&&window.clearTimeout(he.current),ge.current!==null&&window.clearTimeout(ge.current)},[]);let[be,xe]=Z.useState(!1),[Se,Ee]=Z.useState(!1),[Ae,Me]=Z.useState(null),Ne=Z.useId(),[Pe,Ie]=Z.useState(``),[Le,ze]=Z.useState(``),[Ve,He]=Z.useState(!1),[Ue,We]=Z.useState(!1),Ge=Z.useRef(0),Ke=Z.useCallback(()=>{Ge.current=Date.now()+500},[]),qe=Z.useRef(0),Je=Z.useRef(!1),[Ye,Xe]=Z.useState(-1),Ze=Z.useRef(()=>{}),Qe=Z.useRef((...e)=>Promise.resolve().then(()=>Zr.getState().sendMessage(...e))).current,$e=Zr(e=>e.currentSessionId),et=Qr(e=>e.currentProviderId),tt=Qr(e=>e.currentModelId),nt=Qr(e=>e.currentAgentName),rt=Qr(e=>e.currentVariant),it=Qr(e=>e.providers),st=Qr(e=>e.agents),ct=Qr(e=>e.getVisibleAgents),lt=Z.useMemo(()=>Em(ct()),[ct,st]),ut=Qr(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),mt=Qr(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ht=Z.useMemo(()=>{let e=it.find(e=>e.id===et)?.models?.find(e=>e.id===tt);return Nm(e)},[tt,et,it]),gt=we(e=>e.currentDirectory),_t=lc()??gt,{ensureSessionRenderable:vt}=Eu(),bt=Zr(Z.useCallback(e=>$e?e.getDirectoryForSession($e):null,[$e])),xt=di($e??``,bt??void 0),St=Z.useMemo(()=>Ky(xt),[xt]),Ct=oi($e??``,bt??void 0).renderable,Et=pt($e,bt??void 0),Dt=Et?.agent,Ot=Et?.model?.id,kt=Et?.model?.providerID,At=Et?.model?.variant,Mt=Qr(e=>e.activeDirectoryKey),Nt=Z.useRef(0),Pt=Z.useRef(null),Ft=Z.useRef(null),Lt=Zr(e=>e.newSessionDraft),Rt=!!Lt?.open,Bt=Zr(e=>e.newSessionDraft.draftSubmitting??!1),Ht=Zr(e=>e.newSessionDraft.draftEstablishing??!1),Ut=Bt||Ht,Gt=Zr(e=>e.openNewSessionDraft),Kt=Zr(e=>e.setDraftPermissionAutoAcceptEnabled),qt=wt(e=>e.autoAccept),Jt=wt(e=>e.saving),Yt=wt(e=>e.setSessionAutoAccept),Qt=Zr(e=>e.setNewSessionDraftTarget),en=Zr(e=>e.availableWorktreesByProject),tn=Zr(e=>e.abortPromptSessionId),nn=Zr(e=>e.clearAbortPrompt),rn=on(e=>e.consumePendingInputText),an=on(e=>e.pendingPresetSubmit),cn=on(e=>e.pendingInputText),ln=on(e=>e.pendingInputMode),un=on(e=>e.consumePendingSyntheticParts),dn=on(e=>e.activeAttachmentDraft),fn=Mu(Z.useCallback(e=>{let t=$e??(Rt?`draft`:``);return t?e.drafts[t]??Db:Db},[Rt,$e])),mn=Ii($e??``),hn=Z.useSyncExternalStore(t,n,n),_n=dn?.transportIdentity??null,vn=dn?.owner.kind??null,yn=dn?.owner.ownerID??null,bn=Z.useMemo(()=>ix(hn,$e,Lt.draftID,_n&&vn&&yn?{transportIdentity:_n,owner:{kind:vn,ownerID:yn}}:null),[yn,vn,_n,hn,$e,Lt.draftID]),Cn=bn?ce(bn):null,wn=on(Z.useCallback(e=>Cn?e.draftAttachmentViews[Cn]:void 0,[Cn])),En=on(Z.useCallback(e=>Cn?e.drafts[Cn]:void 0,[Cn])),On=Z.useMemo(()=>{if(!En||!wn)return ax;let e=En.attachments.flatMap(e=>{let t=wn[e.attachmentRefID];return t?[t]:[]});return e.length===0?ax:e},[wn,En]);Z.useEffect(()=>{bn&&on.getState().hydrateDraftAttachments(bn)},[bn]);let kn=Rm(),An=s(e=>e.activeMainTab===`chat`),jn=wr($e??``,_t??void 0),Mn=zm({kind:`primary`,surfaceID:`primary`,active:An,sessionID:$e,directory:_t??null,activity:{phase:jn?.type===`busy`?`busy`:jn?.type===`retry`?`retry`:`idle`,canAbort:jn?.type===`busy`||jn?.type===`retry`},draftKey:bn,transportIdentity:hn,runtimeGeneration:c(),selection:{value:{providerID:et,modelID:tt,agent:nt,variant:rt},catalog:{providers:it,agents:lt,variants:ht,variantsReady:!ut,ready:!ut&&!mt,loading:ut||mt},flush:async()=>{let e=Zr.getState().currentSessionId;if(!e)return;let t=c(),r=n(),i=Nt.current,a=e,o=Zr.getState().getDirectoryForSession(a)??null,s=br(o);if(Qr.getState().activeDirectoryKey!==s&&await Qr.getState().activateDirectory(o),c()!==t||n()!==r||Zr.getState().currentSessionId!==a||Qr.getState().activeDirectoryKey!==s||Nt.current!==i)return;await vt(a,{directory:o??void 0});let l=Zr.getState().getDirectoryForSession(a)??null,u=br(l);if(c()!==t||n()!==r||Zr.getState().currentSessionId!==a||l!==o||u!==s||Qr.getState().activeDirectoryKey!==s||Nt.current!==i)return;let d=Qr.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=Ky(pi(a,l??void 0));if(Wy({editRevision:i,pinnedHistoryMessageId:Pt.current,latestHistoryMessageId:p?.id??null}))return;let m=vi.getState(),h=Mi().get(a),g=Vy({sessionId:a,latestUserChoice:p,catalog:f,memory:m,sessionEntity:h?.model?{agent:h.agent,model:{id:h.model.id,providerID:h.model.providerID,variant:h.model.variant}}:h?.agent?{agent:h.agent}:null,fallbackAgentName:d.currentAgentName});if(!g)return;let _=[a,g.source,g.messageId??``,g.agent??``,g.providerID,g.modelID,g.variant??``,s].join(`|`);Ft.current!==_&&(Hy(g,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:a,memory:m}),Ft.current=_)},change:async e=>{Nt.current+=1;let t=Zr.getState().currentSessionId;if(t){let e=Zr.getState().getDirectoryForSession(t)??void 0,n=Ky(pi(t,e));Pt.current=n?.id??null}else Pt.current=null;let n=Qr.getState();Iy(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:vi.getState()})}},resources:{attachments:On,addAttachment:async e=>{bn&&await Wt(bn,()=>on.getState()).addLocal(e)},removeAttachment:async e=>bn?Wt(bn,()=>on.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>bn?Wt(bn,()=>on.getState()).clearRootAttachments():!1,restoreAttachments:async e=>bn?Wt(bn,()=>on.getState()).restoreRootAttachments(e):!1,pendingInput:cn===null?null:{text:cn,mode:ln},consumePendingInput:rn,pendingPreset:an,consumePendingPreset:()=>on.getState().consumePendingPresetSubmit(),consumeSyntheticParts:un,restoreSyntheticParts:e=>on.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:fn,removeInlineDraft:e=>{let t=$e??(Rt?`draft`:``);t&&Mu.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=$e??(Rt?`draft`:``);!t||e.length===0||Mu.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:mn,captureRuntime:()=>on.getState().captureDraftRuntime(),getDraft:e=>on.getState().getDraft(e),abortPrompt:{sessionID:tn,clear:nn}},backend:{send:e=>{My(e,{transportIdentity:n(),runtimeGeneration:c()});let t=Ny(e);return Qe(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Ji(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()=>Gt(),compact:async e=>ke.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&It(e.sessionID),Zi(e.sessionID??``))},shortcuts:{cycle:e=>Ze.current(e),new:()=>Gt(),abort:()=>($e&&It($e),Zi($e??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),Nn=Bm(Mn,u??kn);Vm(Nn),Z.useLayoutEffect(()=>{if(!Nn.active){jy(Nn.surfaceID);return}return Ay(Nn),()=>jy(Nn.surfaceID)},[Nn]);let Pn=Fy(Nn),Fn=Nn.resources??(Nn.kind===`primary`?Mn.resources:void 0);if(!Fn)throw Error(`chat-input-surface-resources-incomplete`);let In=[...Fn.attachments],Ln=Nn.sessionID,Bn=Hm(Nn,Ut),Vn=Nn.kind===`secondary`?Nn.commands.hasNewDraft:Rt,Hn=Vn,Kn=Nn.directory??_t,qn=Nn.draftKey??bn,Jn=Z.useMemo(()=>{if(Nn.kind===`secondary`)return Wm(Nn,!1,!1);let e=Ln?Rb(Ln,bt??void 0):!1;return Wm(Nn,e,Vn)},[Nn,Ln,bt,Vn]),Zn=(e,t,n,r,i,a,o,s,c,l)=>Pn?Pn.send({providerID:t,modelID:n,agent:r,variant:s,text:e,attachments:i,agentMention:a,parts:o,systemContext:o?.filter(e=>e.synthetic).map(e=>({text:e.text,synthetic:!0})),inputMode:c,options:l}):Promise.reject(Error(`chat-input-surface-incomplete`)),Qn=Z.useCallback(()=>Pn?Pn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[Pn]),tr=xn(e=>e.projects),nr=xn(e=>e.activeProjectId),ar=xn(e=>e.setActiveProjectIdOnly),[or,cr]=Z.useState(!1),[lr,dr]=Z.useState(!1),fr=Z.useMemo(()=>Ln?Vi({autoAccept:qt,sessions:[],sessionById:Mi(),sessionID:Ln}):Lt.permissionAutoAcceptEnabled===!0,[Ln,Lt.permissionAutoAcceptEnabled,qt]),pr=Qr(e=>e.agents),mr=Nn.kind===`secondary`?Nn.selection.value.agent:nt,gr=Nn.kind===`secondary`?Em(Nn.selection.catalog?.agents):pr,_r=d()||Cy(gr,mr),vr=Z.useCallback(()=>{Tt.error(f(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[f]),yr=Nn.selection.value,xr=Nn.selection.change,Cr=Nn.selection.catalog,Dr=Z.useMemo(()=>({selection:{providerID:yr.providerID??``,modelID:yr.modelID??``,agent:yr.agent??null,variant:yr.variant},onChange:async e=>{if(!xr)throw Error(`chat-input-surface-selection-readonly`);await xr({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!Nn.active,catalog:Cr}),[Cr,xr,yr.agent,yr.modelID,yr.providerID,yr.variant,Nn.active]);Z.useEffect(()=>{Nt.current=0,Pt.current=null,Ft.current=null},[$e]),Z.useEffect(()=>{if(Nn.kind!==`primary`||!$e||ut||mt||it.length===0||lt.length===0)return;let e=br(bt);if(Mt!==e)return;let t=vi.getState(),n={providers:it,agents:lt};if(Wy({editRevision:Nt.current,pinnedHistoryMessageId:Pt.current,latestHistoryMessageId:St?.id??null}))return;let r=Vy({sessionId:$e,latestUserChoice:St,catalog:n,memory:t,sessionEntity:kt&&Ot?{agent:Dt,model:{id:Ot,providerID:kt,variant:At}}:Dt?{agent:Dt}:null,fallbackAgentName:nt,transcriptReady:Ct});if(!r)return;let i=[$e,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,Mt].join(`|`);if(Ft.current===i)return;if((r.agent===void 0||r.agent===nt)&&r.providerID===et&&r.modelID===tt&&r.variant===rt){Ft.current=i;return}if(Qr.getState().activeDirectoryKey!==e)return;let a=Qr.getState();Hy(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:$e,memory:t}),Ft.current=i},[Nn.kind,$e,St,Ct,it,lt,ut,mt,Mt,bt,nt,et,tt,rt,Dt,Ot,kt,At]);let kr=Qr(e=>e.getVisibleAgents),Ar=Nn.kind===`primary`?kr():Ob,Mr=Qr(e=>Nn.kind===`primary`?e.providers:kb),Nr=Nn.kind===`secondary`?Em(Nn.selection.catalog?.agents):Ar,Fr=Nn.kind===`secondary`?Nn.selection.catalog?.providers??kb:Mr,Ir=Nn.kind===`secondary`&&(!Nn.selection.catalog?.ready||!!Nn.selection.catalog.error),Br=!Nn.active||!Nn.selection.change||Ir,Hr=s(e=>e.isMobile),Ur=s(e=>e.setImagePreviewOpen),Wr=Z.useCallback(e=>{e.image&&(m(e),Ur(!0))},[Ur]),Kr=Z.useCallback(e=>{m(t=>({...t,open:e})),Ur(e)},[Ur]),qr=su(e=>e.pending),Jr=s(e=>e.inputBarOffset),Yr=s(e=>e.persistChatDraft),$r=s(e=>e.inputSpellcheckEnabled),ei=s(e=>e.isExpandedInput),ti=s(e=>e.setExpandedInput),ni=s(e=>e.setTimelineDialogOpen),ri=Sb({draftKey:qn,sessionTitles:new Map(Array.from(Mi(),([e,t])=>[e,t.title||e])),persistenceEnabled:Yr}),ai=ri.document,si=ai.text,{replacePlainDocument:li,replaceProgrammaticText:ui,applyBrowserEdit:fi,insertReference:mi,deleteReference:hi,enterHistoryPreview:gi,exitHistoryPreview:yi,captureSubmission:bi,recoverSubmission:xi,confirmedFileMentions:Si,mentions:Ci}=ri,wi=Z.useCallback((e,t)=>ui(e,t),[ui]),Di=Z.useMemo(()=>new Set(Si.map(e=>e.value)),[Si]),Oi=Z.useRef(null),Ai=Z.useRef(!1),Ni=Z.useRef(0),Pi=Z.useRef(null),Fi=Z.useRef(si.length),Li=Z.useRef(null),zi=Z.useRef(0),Bi=Z.useRef(!1),Hi=Z.useRef(null),Ui=Z.useRef(!1),Wi=Z.useRef(null),Gi=Z.useRef([]),Ki=Z.useRef(!1),qi=Z.useRef(null),Xi=Z.useRef(!1),Qi=Z.useRef(null),$i=Z.useRef(null),ea=Z.useRef(null),ta=Z.useRef(si),na=Z.useRef(new Set),ra=ri.getDocument,ia=Z.useCallback((e,t,n=[])=>wi(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}`))]}),[wi]),aa=Fh(Ph()),{git:sa,vscode:la}=Do(),ua=s(e=>e.shortcutOverrides.cycle_agent),fa=s(e=>e.shortcutOverrides),pa=Z.useMemo(()=>Xa(`cycle_agent`,ua?{cycle_agent:ua}:void 0),[ua]),ma=Z.useMemo(()=>Xa(`clear_all_messages`,fa),[fa]),{currentTheme:ha}=Ua(),va=Zo(),ba=ls(Kn),wa=qo(e=>Kn?e.directories.get(Kn)?.status??null:null),Oa=qo(e=>e.ensureStatus),ka=qo(e=>e.fetchStatus),[ja,Ma]=Z.useState(!1),Na=Z.useRef(null),[Pa,Ra]=Z.useState(!1);Z.useEffect(()=>{!Kn||!sa||Oa(Kn,sa)},[Kn,sa,Oa]),Z.useEffect(()=>{if(!(!Kn||!sa))return Ei.onGitRefreshHint(e=>{Wb(e.directory)===Wb(Kn)&&ka(Kn,sa)})},[Kn,sa,ka]);let Ba=Z.useCallback(async e=>{if(!Ln)return;let t=Zr.getState().getDirectoryForSession(Ln)||Kn||``;if(!t){Tt.error(f(`diffView.reviewDialog.toast.noSessionDirectory`));return}dr(!0);try{await sn({originalSessionID:Ln,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),Tt.error(e instanceof Error?e.message:f(`diffView.reviewDialog.toast.startFailed`))}finally{dr(!1)}},[Ln,Kn,f]),Va=ei&&!Hr,Ha=ei&&Hr,Wa=Va||Ha,qa=`1.5rem`,Ja=f(Ln||Vn?h===`shell`?`chat.chatInput.placeholder.shell`:Hr||Pa?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Ya=f(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=Li.current;if(!e)return;let t=e=>{let t=e>0&&e<Nb;Ra(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 Za=In,Qa=Z.useMemo(()=>new Set(Nr.map(e=>e.name.toLowerCase())),[Nr]),$a=Z.useRef(Qa);$a.current=Qa;let eo=jb({inputMode:h,message:si,showCommandAutocomplete:M,showSkillAutocomplete:R}),to=jt({directory:Kn,enabled:eo}),no=Z.useMemo(()=>to.data??[],[to.data]),ro=Tr({directory:Kn,enabled:eo}),io=Z.useMemo(()=>ro.data??[],[ro.data]),ao=Z.useMemo(()=>new Map(io.map(e=>[e.name.toLowerCase(),e.name])),[io]),oo=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`plan-feature`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!Hr&&!d()&&e.add(`handoff-review`);for(let t of no)e.add(t.name.toLowerCase());for(let t of io)e.add(t.name.toLowerCase());return e},[no,io,Hr]),so=Z.useMemo(()=>{if(!si||!si.includes(`/`)||h===`shell`||oo.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(si))!==null;){let t=n[2]??``,r=n[3];if(!oo.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=ao.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:re({trigger:`/`,icon:`book-open`,label:o},si.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:re({trigger:`/`,icon:`command`,label:r},si.slice(i,i+a))})}return e},[ao,h,oo,si]),co=xa(e=>e.snippets),lo=Z.useMemo(()=>{let e=new Set;for(let t of co){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[co]),uo=Z.useMemo(()=>{if(!si||!si.includes(`#`)||h===`shell`||lo.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(si))!==null;){let t=n[2];if(!lo.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[h,lo,si]),fo=Z.useMemo(()=>!si||!si.includes(`@`)||h===`shell`?[]:Vr(si,{confirmedValues:Di,agentNames:Qa}),[Di,h,Qa,si]),po=Z.useMemo(()=>{if(!si||!si.includes(`[`)||h===`shell`||Za.length===0)return[];let e=Za.filter(Fe),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return De(si,e.map(e=>e.filename)).flatMap(e=>{let n=G(si.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:re({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},si.slice(e.start,e.end))}]})},[h,si,Za]),mo=Ls(Hr)&&Nn.kind===`primary`,ho=Z.useMemo(()=>{if(!si||h===`shell`)return null;let e=[...mo?[]:Sv(si),...mo?[]:Rv(si),...Dv(fo),...so,...uo,...po,...ai.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return Cv(si,e)},[po,so,uo,fo,ai.references,h,si,mo]),go=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?Hb(e.serverPath):e.dataUrl})),[]),[_o,vo]=Z.useState(null),yo=Z.useRef(null),[bo,xo]=Z.useState(!1),[So,Co]=Z.useState(!1),[wo,To]=Z.useState(null),[Eo,Oo]=Z.useState(null),ko=C(e=>e.followUpBehavior),Ao=Z.useMemo(()=>{let e=Pn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[Pn]),Mo=Gu({transportIdentity:Ao?.transportIdentity??``,directory:Ao?.directory??``,sessionID:Ao?.sessionID??``}),Fo=Z.useMemo(()=>Ln?x(Ln):null,[Ln]),Io=C(Z.useCallback(e=>Ao?b(e,Ao):Eb,[Ao])),Lo=C(Z.useCallback(e=>Fo?b(e,Fo):Eb,[Fo])),zo=Z.useMemo(()=>Lo.length===0?Io:Io.length===0?Lo:[...Lo,...Io],[Io,Lo]),Uo=Mo.mode===`server`?Eb:zo,Go=C(Z.useCallback(e=>Ao?B(e,Ao):Eb,[Ao])),Ko=C(e=>e.clearQueue),Jo=C(e=>e.removeFromQueue),$o=Fn.inlineDrafts,es=$o.length>0,[ns,as,ss]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of $o)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[$o]),cs=Z.useCallback(e=>{for(let t of Fn.inlineDrafts)t.source===e&&Fn.removeInlineDraft(t.id)},[Fn]),fs=Z.useCallback(()=>{for(let e of Fn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&Fn.removeInlineDraft(e.id)},[Fn]),ps=Fn.history;Z.useEffect(()=>{ta.current=si},[si]),Z.useLayoutEffect(()=>{g(`normal`),Xe(-1)},[qn?.transportIdentity,qn?.owner.kind,qn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Vn||Hr)return;let e=()=>{let e=Oi.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Vn,Hr]);let ms=jg(Nn.kind===`primary`?Ln:null,Nn.kind===`primary`?Kn??void 0:void 0),hs=Nn.activity?.phase??ms.phase,gs=Xn(Z.useCallback(e=>{if(!Ln)return!1;let t=e.runsByOriginalSessionID[Ln];return t?.status===`running`&&t.runtimeKey===i()},[Ln])),_s=J(e=>{Hr&&(Ke(),me(e),Oi.current?.blur(),Qr.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),vs=Fn.pendingInput,ys=Fn.consumePendingInput;Z.useEffect(()=>{if(vs===null)return;let e=ys();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=nx(ta.current,e.text);ta.current=t,wi(t)}else if(e.mode===`append-inline`){let t=rx(ta.current,e.text);ta.current=t,wi(t)}else li(e.text);setTimeout(()=>{Oi.current?.focus()},0)}},[vs,ys,li,wi]);let bs=si.trim().length>0||Za.length>0||es,xs=Mo.mode===`server`?Mo.items.length>0:Uo.length>0||Go.length>0,Ss=!Bf(Mo.mode),ws=bs||xs,Ts=Zr(e=>e.stagedMessageEdit?.sessionId===Ln?e.stagedMessageEdit.messageId:null),Es=hs===`busy`||hs===`retry`,Ds=Nn.activity?.canAbort??Es,Os=Z.useCallback(()=>{let e=Oi.current,t=e?.value??ra().text;t!==ra().text&&fi(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=ra();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Za.length>0||es}},[fi,ra,es,Za.length]),ks=Z.useRef(async()=>{}),As=Nn.surfaceID,js=Lt?.draftID??null,Ms=gn(Z.useMemo(()=>yt(As),[As])),Ps=gn(Z.useMemo(()=>pn(js),[js])),Fs=Z.useMemo(()=>Xr(Ms,Ps),[Ms,Ps]),Is=(e=`send`)=>gn.getState().beginFlight(As,e),Rs=()=>{gn.getState().endFlight(As)},Bs=()=>gn.getState().isInFlight(As),Vs=Z.useRef(null);Z.useEffect(()=>{if(Nn.kind!==`primary`||!Ts){Vs.current=null;return}if(Vs.current!==Ts){if(Vs.current=Ts,mo){Cs().focus();return}jm(Oi)||requestAnimationFrame(()=>jm(Oi))}},[mo,Ts,Nn.kind]);let Hs=gn(Z.useMemo(()=>Gr(js),[js])),Us=J(async()=>{let e=Zr.getState().newSessionDraft.draftID;if(!e||!gn.getState().isEstablishing(e))return!1;let t=Os();if(!t.hasContent)return!1;let n=K(t.document,`queue-canonical`);if(!n.ok)return Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;if(await Nn.selection.flush(),!gn.getState().isEstablishing(e))return!1;let r=Uy(Qr.getState());if(!r?.providerID||!r?.modelID)return Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;let i=go(Za);return gn.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})?(li(``),Xe(-1),ti(!1),i.length>0&&Fn.clearAttachments(),!0):!1}),Ws=()=>{if(Ln)return!1;let e=Zr.getState().newSessionDraft.draftID;return gn.getState().isEstablishing(e)?(Us(),!0):!1},Gs=J(async()=>{if(!Nn.active||Bs())return;if(Ln){let e=Zr.getState().stagedMessageEdit;if(e&&e.sessionId===Ln){Zr.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await zn(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{Zr.getState().endMessageEditCommit(e.sessionId,e.messageId)}Zr.getState().stagedMessageEdit===e&&Zr.getState().clearStagedMessageEdit(e.sessionId)}}let e=Os(),t=K(e.document);if(!t.ok){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:t.chunks??[],semantics:t.semantics??[]},i=t.text,a=i.trimStart(),o=r.chunks.every(e=>e.provenance===`authored`)&&h===`normal`&&a.startsWith(`/`)?jo(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(o&&!Bo(o,e=>Im(Nn,{name:e.name,source:`openchamber`}))||l||!e.hasContent||!Ln)return;if(Ss||!zt(Nn.deliveryTarget?.kind,Mo.mode)){ks.current(Es?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&ly(i,h)){ks.current();return}if(!Is(`queue`))return;let s=Nn.transportIdentity,u=Nn.runtimeGeneration,d=Fn.captureRuntime(),p=Ao,m=Nn.kind===`primary`?Ao?.sessionID??Ln:null,g=[...Fn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Fu(e.document.text,g),e.document.references).document:e.document,y=K(_,`queue-canonical`);if(!y.ok){Rs(),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let b=go(Za),w=bi(),T=b,E=$n(),D=!1,O=null,k=()=>{D&&p&&(Mo.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(C.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&xi(w),T.length>0&&await Fn.restoreAttachments(T),e&&Fn.restoreSyntheticParts(e),g.length>0&&Fn.restoreInlineDrafts(g)};try{if(!p){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(Mo.mode===`server`){if(!qn){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}_i({stage:()=>{Mo.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:Ci}}),D=!0},clearComposer:()=>{li(``),Xe(-1),ti(!1)}})}else _i({stage:()=>{C.getState().bindLegacyQueue(x(p.sessionID),p),C.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:Ci}),O=E.requestID},clearComposer:()=>{li(``),Xe(-1),ti(!1)}});if(await Nn.selection.flush(),!Tn({transportIdentity:s,generation:u},{transportIdentity:n(),generation:c()})){await A();return}if(!Tn(d,Fn.captureRuntime())){await A();return}if(m&&Zr.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==n()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&S(Zr.getState().getDirectoryForSession(m))!==S(p.directory)){await A();return}let t=p,r=Nn.kind===`primary`?(()=>{let e=Qr.getState(),t=m?Zr.getState().getDirectoryForSession(m)??null:null;return Uy(e,{expectedConfigKey:br(t),activeDirectoryKey:e.activeDirectoryKey})})():Nn.selection.value.providerID&&Nn.selection.value.modelID?{...Nn.selection.value,providerID:Nn.selection.value.providerID,modelID:Nn.selection.value.modelID}:void 0;if(!rr(r)){await A();return}if(Mo.mode===`server`){if(!qn){await A(),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let n=Xt({draftKey:qn,runtime:d,document:e.document,attachments:Za,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?Fn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=ci({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:Nr,installedSkillNames:new Set(Sr(ne,Kn).map(e=>e.name)),directory:Kn,root:va||Kn,confirmedFilePaths:Si.map(e=>e.path),confirmedDirectoryPaths:Si.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Za});return o=e.attachments,dt({text:g.length>0?Fu(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:ii(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...$t(b),...$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),Tt.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Or(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Wn({capture:n,admit:async()=>{let n=await Mo.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:Ci,sendConfig:r,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return n.status===`committed`&&(e=!0,D=!1),n},captureRuntime:Fn.captureRuntime,getCurrentDraftKey:()=>qn,getDocument:ra,consumeBody:()=>li(``),getAttachments:()=>Fn.attachments,removeAttachment:Fn.removeAttachment,getInlineDrafts:()=>Fn.inlineDrafts,removeInlineDraft:Fn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!Hr&&Oi.current?.focus()}catch(e){await A(i),Tt.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)Fn.removeInlineDraft(e.id);b.length>0&&Fn.clearAttachments(),Hr||Oi.current?.focus()}catch(e){await A(),Tt.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Rs()}}),Ks=J(()=>{yy(()=>Gs(),()=>{Tt.error(f(`chat.chatInput.toast.messageSendFailed`))})}),qs=J(async(e,t,n,r)=>{if(Ss||!Nn.draftKey)return!1;try{let i=await Gn({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=on.getState(),o=a.getDraft(Nn.draftKey);return Hf(await Rn({key:Nn.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1}}),Js=J(e=>{if(!(l||Ss)){if(Pn){Pn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}Tt.error(f(`chat.chatInput.toast.messageSendFailed`))}}),Ys=J(()=>{Ke(),me(`agent`),Oi.current?.blur(),Qr.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),Xs=Z.useCallback(()=>{xo(!0)},[]),Zs=Z.useCallback(()=>{Co(!0)},[]),Qs=async e=>{if(!Nn.active||l||Ws()||Bs())return;let t=e?.queuedOnly??!1,i=e?.queuedMessageId,a=e?.delivery===`steer`&&Es?`steer`:void 0,o=e?.presetText==null?Os():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Za.length>0||es},u=e?.presetText==null?bi():null,p=In,m=K(o.document,`direct-send-display`);if(!m.ok){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let g=m.text,v={chunks:m.chunks??[],semantics:m.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?sy(x,h):null,w=y&&ly(g,h),T=y&&h===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&h===`normal`&&x.startsWith(`/`)?jo(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Bo(E,e=>Im(Nn,{name:e.name,source:`openchamber`}))||t&&Ss)return;if(!t&&T){N(!1),I(``),Hr?_s(`model`):(s.getState().setModelSelectorOpen(!0),Qr.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&S&&S!==`model`)){if(!t&&Ln&&xs&&Ss)return;if(!t&&Ln&&xs&&Mo.mode===`server`){o.hasContent&&Ks();return}if(!t&&Ln&&xs){o.hasContent&&Ks();let e=Uo[0];e&&Pn&&await Pn.sendQueued(e.queueItemID,{options:Es?{delivery:`steer`}:void 0});return}}let D=w?[]:i?Uo.filter(e=>e.id===i):Uo;if(t&&gs)return;if(t){if(D.length===0||!Ln)return}else if(!o.hasContent&&!xs||!Ln&&!Vn)return;if(!Ln&&Bn||!Is())return;let O=!Ln&&Vn&&!t&&!w?Zr.getState().newSessionDraft.draftID??null:null,k=O?W(`msg`):void 0;if(O&&k&&!gn.getState().beginEstablishing({draftID:O,primaryMessageID:k})){Rs();return}let A=()=>{ur(),O&&gn.getState().clearEstablishing(O)},j=e=>{let t=Zr.getState().currentSessionId,r=(t?Zr.getState().getDirectoryForSession(t):null)??Kn??``;if(!t||!r){gn.getState().clearEstablishing(e);return}vy({draftID:e,sessionID:t,directory:r,transportIdentity:n(),runtimeGeneration:c(),admitServer:Mo.mode===`server`?async e=>Mo.actions.admit({requestID:e.requestID,scope:{directory:r,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?$t(e.attachments):void 0}):void 0})};if(Ln&&!t&&!w&&gs){Rs(),Ks();return}let M=!t&&!w;M&&(li(``),Xe(-1),ti(!1));let P=!1,F,L,R=!1;try{if(my({surfaceKind:Nn.kind,currentSessionId:Ln,queuedOnly:t,resourcePolicy:w,inputMode:h,localCommand:S})&&Ln){let e=Zr.getState().getDirectoryForSession(Ln)??Kn??null,t=Zr.getState().stagedMessageEdit;t&&t.sessionId===Ln&&(L={sessionId:t.sessionId,messageId:t.messageId},Zr.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Qr.getState(),r=Uy(n,{expectedConfigKey:br(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=go(Za);F=Un({sessionId:Ln,directory:e,content:o.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=Nn.kind===`primary`?(()=>{if(t){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(Ao?.sessionID)return Ao.sessionID}return Ln})():null,n=t?D[0]?.sendConfig:void 0;if(t&&n||await Nn.selection.flush(),e!==null&&Zr.getState().currentSessionId!==e)return;let s=async()=>{let t=n?{...n}:Nn.kind===`primary`?(()=>{let t=Qr.getState();if(!e)return Gy({captured:Uy(t),surfaceSelection:Nn.selection.value});let n=Zr.getState().getDirectoryForSession(e)??Kn??null;return Gy({captured:Uy(t,{expectedConfigKey:br(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:Nn.selection.value})})():Nn.selection.value.providerID&&Nn.selection.value.modelID?{...Nn.selection.value,providerID:Nn.selection.value.providerID,modelID:Nn.selection.value.modelID}:void 0;if(Nn.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=Zr.getState().getDirectoryForSession(e)??Kn??null,r=br(n);if(Qr.getState().activeDirectoryKey!==r&&await Qr.getState().activateDirectory(n),Zr.getState().currentSessionId===e){let e=Qr.getState();t=Gy({captured:Uy(e,{expectedConfigKey:br(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:Nn.selection.value})}}return t},c=await s(),l=!1,m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant;if(!m||!g){if(!l){l=!0;try{await Qr.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await s(),m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant}catch{}}if(!m||!g){console.warn(`Cannot send message: provider or model not selected`),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}}Ln&&!t&&!w&&await Vt(Ln)&&await Zi(Ln);let T={...a?{delivery:a}:{},commitStagedMessageEdit:!t,...F?{messageID:F.messageID,ticket:F}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:Zr.getState().getDirectoryForSession(e)??Kn??null}:Nn.kind===`primary`&&Ln?{sessionId:Ln,directoryHint:Zr.getState().getDirectoryForSession(Ln)??Kn??null}:{}},E=``,M=[],N,I=[],z=new Set(Sr(ne,Kn).map(e=>e.name)),B=[],V=w?void 0:Fn.consumeSyntheticParts();for(let e=0;e<D.length;e++){let t=D[e],n=t.composerDocument&&K(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:Kn,a=new Set(Sr(ne,i).map(e=>e.name)),o=ci({plan:r??Ti(t.content),agents:Nr,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(B.push(...o.semantics),!N&&o.agent&&(N=o.agent),e===0)E=o.text,M=Lr([...go(t.attachments),...o.attachments]);else{let e=go(t.attachments);I.push({text:o.text,attachments:Lr([...e,...o.attachments])})}}if(!t&&o.hasContent){let e=go(Za),t=ci({plan:v,agents:Nr,installedSkillNames:z,directory:Kn,root:va||Kn,confirmedFilePaths:Si.map(e=>e.path),confirmedDirectoryPaths:Si.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Za});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,M=Lr([...e,...t.attachments])):I.push({text:t.text,attachments:Lr([...e,...t.attachments])})}let H=Ln??(Vn?`draft`:null),U=[];if(!t&&H&&!w&&(U=[...Fn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Fu(E,U);else if(I.length>0){let e=I[I.length-1];e.text=Fu(e.text,U)}else E=Fu(E,U);if(V&&V.length>0&&I.push(...ji(V)),wo&&I.push({text:wo.contextText,synthetic:!0}),Eo&&(I.push({text:Eo.instructionsText,synthetic:!0}),I.push({text:Eo.contextText,synthetic:!0})),I.push(...ii(B,Ln&&Zr.getState().getDirectoryForSession(Ln)||Kn)),!E&&M.length===0&&I.length===0)return;if(O&&k){if(!await Rr({messageID:k,providerID:m,modelID:g,agent:y,text:E,attachments:M,additionalParts:I,agentMentionName:N}))return;if(!gn.getState().isEstablishing(O)){A();return}}let W=async()=>{if(A(),Ao&&D.length>0&&C.setState(e=>{let t=_(Ao),n=e.queuedMessages[t]??[],r=new Set(D.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...D,...n.filter(e=>!r.has(e.id))]}}}),t)return V&&Fn.restoreSyntheticParts(V),!0;Fn.pendingInput?.text===o.message&&Fn.consumePendingInput(),u&&xi(u);let e=!0;return p.length>0&&(e=await Fn.restoreAttachments(p)),V&&Fn.restoreSyntheticParts(V),U.length>0&&Fn.restoreInlineDrafts(U),e};if(!w&&Ln&&i){let e=Ao?b(C.getState(),Ao).find(e=>e.id===i||e.queueItemID===i):void 0;Ao&&e?.queueItemID&&e.operationID&&Jo(Ao,e.queueItemID,e.operationID)}else!w&&Ln&&xs&&Ao&&Ko(Ao);!t&&!w&&(li(``),Xe(-1),ti(!1),py({queuedOnly:t,resourcePolicy:w,rootAttachmentCount:p.length})&&Fn.clearAttachments());let ee=()=>dy({currentSessionId:Ln,messageRef:ta,replacePlainDocument:li}),G=E.trimStart();if(h===`normal`&&G.startsWith(`/`)){let e=jo(G.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Bo(e,e=>Im(Nn,{name:e.name,source:`openchamber`})))return;if(Ln&&(e===`undo`||e===`redo`)&&uy(G,h)&&ee(),e===`undo`&&Ln){try{await Zr.getState().handleSlashUndo(Ln),r?.()}catch(e){Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){uy(G,h)&&ee(),await Pn?.shortcut(`new`);return}if(e===`redo`&&Ln){try{await Zr.getState().handleSlashRedo(Ln),r?.()}catch(e){Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Ln){await fy({command:`fork`,consumeCommandText:ee,forkSession:()=>Zr.getState().forkCurrentSession(Ln),waitForConnection:zr,getDirectoryForSession:()=>Zr.getState().getDirectoryForSession(Ln),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Ln&&aa.timeline){ni(!0);return}if(e===`compact`&&Ln){fy({command:`compact`,consumeCommandText:ee,forkSession:async()=>void 0,waitForConnection:zr,getDirectoryForSession:()=>Nn.directory??``,summarizeSession:e=>qn?Nn.backend.compact({operation:`compact`,surfaceID:Nn.surfaceID,transportIdentity:Nn.transportIdentity,runtimeGeneration:Nn.runtimeGeneration,sessionID:Ln,directory:e,draftKey:qn,deliveryTarget:Nn.deliveryTarget,providerID:m,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{Tt.error(f(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Ln){try{await zr();let e=G.replace(/^\/\u2003?summary\b/i,``).trim(),t=e?` focused on: ${e}`:``,n=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await ki(`session.summary.visible`,{topic_line:t}),a=await ki(`session.summary.instructions`,{topic_block:n});await Zn(i,m,g,y,[],N,[{text:a,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Ln||Vn)){try{await zr();let e=await ki(`session.review.visible`),t=await ki(`session.review.instructions`);await Zn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Ln&&!Hr&&!d()){cr(!0);return}if(e===`plan-feature`&&(Ln||Vn)){try{await zr();let e=await ki(`session.plan.visible`),t=await ki(`session.plan.instructions`);await Zn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(Ln||Vn)){A(),Sn.getState().setArmed(!0);let e=cy(G,h)??``;li(e),ta.current=e,Xe(-1),e||ti(!1);return}if(e===`craft-goal`&&(Ln||Vn)){try{await zr();let e=G.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await ki(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await ki(`session.craftGoal.instructions`);await Zn(t,m,g,y,[],N,[{text:n,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Ln||Vn)){try{await zr();let e=await ki(`session.catchup.visible`),t=await ki(`session.catchup.instructions`);await Zn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Ln||Vn)){try{await zr();let e=await ki(`session.debug.visible`),t=await ki(`session.debug.instructions`);await Zn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Ln||Vn)){try{await zr();let e=await ki(`session.weigh.visible`),t=await ki(`session.weigh.instructions`);await Zn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Ln||Vn)){try{await zr();let e=await ki(`session.explore.visible`),t=await ki(`session.explore.instructions`);await Zn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.exploreFailed`))}return}}let q=Ln&&Zr.getState().getDirectoryForSession(Ln)||Kn;if(Hn||Ln&&!Rb(Ln,q)){let e=await Yi().catch(()=>null);e&&I.push({text:Ri(e),synthetic:!0})}try{let e=xa.getState().expandText;E=await e(E);for(let t of I)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let te=Zn(E,m,g,y,M,N,I.length>0?I:void 0,x,h,T);P=!0,te.finally(()=>{Rs(),L&&Zr.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&te.then(()=>{j(O)}).catch(()=>{gn.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),te.then(()=>{wo&&To(null),Eo&&Oo(null)}).catch(e=>{F&&Dn(F),W().then(e=>{e||Tt.error(f(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){Tt.error(f(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){p.length>0&&Tt.error(f(`chat.chatInput.toast.sendAttachmentsFailed`));return}Tt.error(t||f(`chat.chatInput.toast.messageSendFailed`))}),Hr||Oi.current?.focus()}finally{R||(F&&Dn(F),L&&Zr.getState().endMessageEditCommit(L.sessionId,L.messageId)),P||(M&&u&&xi(u),Rs(),O&&j(O))}};ks.current=Qs;let $s=Z.useCallback(()=>{if(Ws()||Bs())return;let e=Os(),t=h===`normal`&&e.hasContent&&Ln&&(Es||gs),n=t&&Bf(Mo.mode)&&zt(Nn.deliveryTarget?.kind,Mo.mode);ko===`queue`&&n?Ks():ko===`steer`&&t||ko===`queue`&&t&&!n?ks.current(t?{delivery:`steer`}:void 0):ks.current()},[h,Os,Ln,Es,gs,ko,Ks,Mo.mode,Nn.deliveryTarget?.kind,Us]),ec=Z.useCallback(e=>{if(Bs())return;let t=(Oi.current?.value??ta.current).trim(),n=t?`${e}\n${t}`:e;ks.current({presetText:n})},[]),tc=Z.useCallback(e=>{let t=rx(ra().text,e);wi(t),Oi.current&&(Oi.current.value=t),setTimeout(()=>{Oi.current?.focus()},0)},[wi]),nc=Z.useCallback(e=>{if(Bs())return;let t=rx(Oi.current?.value??ta.current,e);ks.current({presetText:t})},[]),rc=Fn.pendingPreset,ic=Fn.consumePendingPreset;Z.useEffect(()=>{if(rc==null)return;let e=ic();e&&ec(e)},[rc,ic,ec]);let ac=Z.useCallback(()=>{li(``),Xe(-1),In.length>0&&Fn.clearAttachments(),Ao&&Ko(Ao),N(!1),z(!1),te(!1),O(!1),h===`shell`&&g(`normal`)},[In.length,Fn,Ko,Ao,li,h]),oc=e=>{if(!Nn.active||Mg(e))return;if(ma&&Ga(e,ma)&&!qr){let t=Oi.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),ac();return}}if(h===`shell`&&e.key===`Escape`){e.preventDefault(),g(`normal`);return}if(h===`shell`&&e.key===`Backspace`&&si.length===0){e.preventDefault(),g(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Oi.current,n=t?.selectionStart??si.length,r=t?.selectionEnd??si.length,i=hi({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Lb(ri.getDocument().text,i.start);e.preventDefault(),wi(t.text),requestAnimationFrame(()=>{Oi.current?.setSelectionRange(t.caret,t.caret),_c()}),vc(t.text,t.caret);return}let a=Oe(si,In.filter(Fe).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=Lb(a.text,a.caret);e.preventDefault(),wi(n.text);for(let e of In)t.has(e.filename.toLowerCase())&&Fn.removeAttachment(e.id);requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=n.caret,Oi.current.selectionEnd=n.caret),_c()}),vc(n.text,n.caret);return}let o=Ev(si,ao.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Lb(o.text,o.caret);e.preventDefault(),wi(t.text),requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=t.caret,Oi.current.selectionEnd=t.caret),_c()}),vc(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<si.length){let n=De(si,In.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=G(si.slice(n.start+1,n.end-1)).trim(),r=In.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=si[n.end]===` `?n.end+1:n.end,a=`${si.slice(0,n.start)}${si.slice(i)}`;e.preventDefault(),wi(a),r&&Fn.removeAttachment(r.id),requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=n.start,Oi.current.selectionEnd=n.start),_c()}),vc(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(si[r-1]);)--r;let i=t+1;for(;i<si.length&&!/\s/.test(si[i]);)i+=1;let a=si.slice(r,i),o=a.slice(1);if(Ab.test(a)&&!$a.current.has(o.toLowerCase())&&Er({mention:o,confirmed:Di.has(o),terminated:i<si.length&&/\s/.test(si[i])})){let t=si[i]===` `?i+1:i,n=`${si.slice(0,r)}${si.slice(t)}`;e.preventDefault(),wi(n),requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=r,Oi.current.selectionEnd=r),_c()}),vc(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&Qi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Qi.current.handleKeyDown(e.key);return}if(R&&$i.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),$i.current.handleKeyDown(e.key);return}if(q&&ea.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ea.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(Va&&e.key===`Escape`){e.preventDefault(),ti(!1);return}let n=pa&&!pa.includes(`shift`)?Ka(`shift+${pa}`):``,r=n&&Ga(e,n)?-1:+!!Ga(e,pa);if(r!==0&&!M&&!R&&!q&&!D){e.preventDefault(),e.stopPropagation(),Pn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Oi.current?.focus({preventScroll:!0})});return}let i=M||R||q||D,a=Oi.current?.selectionStart===0&&Oi.current?.selectionEnd===0,o=Oi.current?.selectionStart===si.length&&Oi.current?.selectionEnd===si.length,s=!i&&(si.length===0||a),c=!i&&(si.length===0||o);if(h===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Oi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),wi(t),requestAnimationFrame(()=>{let e=Oi.current;e&&(e.selectionStart=n,e.selectionEnd=r),_c()}),vc(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=si.slice(n,r);t(`${si.slice(0,n)}${a}${s}${o}${si.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=si.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${si.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&ps.length>0){if(e.preventDefault(),Ye===-1)Xe(0),gi({text:ps[0],references:[]});else if(Ye<ps.length-1){let e=Ye+1;Xe(e),gi({text:ps[e],references:[]})}requestAnimationFrame(()=>{Oi.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Ye>=0){if(e.preventDefault(),Ye===0)Xe(-1),yi();else{let e=Ye-1;Xe(e),gi({text:ps[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),Ws()||Bs())return;let t=e.ctrlKey||e.metaKey,n=h===`normal`&&bs&&Ln&&(Es||gs),r=n&&Bf(Mo.mode)&&zt(Nn.deliveryTarget?.kind,Mo.mode);ko===`queue`?t||!n?Qs():r?Ks():Qs({delivery:`steer`}):t||!n?Qs():Qs({delivery:`steer`})}},sc=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}},[]),cc=Z.useCallback(()=>{if(!Va){vo(null);return}if(!M&&!R&&!q&&!D){vo(null);return}let e=Oi.current,t=Li.current;if(!e||!t)return;let n=e.selectionStart??si.length,r=sc(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||q?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));vo({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Va,sc,si.length,M,D,q,R]);Z.useLayoutEffect(()=>{cc()},[cc,si,M,R,q,D,Va]),Z.useEffect(()=>{if(!Va)return;let e=()=>cc();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Va,cc]);let uc=Z.useCallback(()=>{yo.current&&=(clearTimeout(yo.current),null),Ma(!0),yo.current=setTimeout(()=>{Ma(!1),yo.current=null},1800)},[]),dc=Z.useCallback(()=>{if(Fn.abortPrompt.clear(),uc(),Nn.kind===`secondary`){Pn?.shortcut(`abort`);return}Qn()},[Qn,Pn,uc,Nn.kind,Fn]),fc=Z.useCallback((e=1)=>{if(Ir)return;let t=Yn(Nr,Nn.selection.value.agent??mr,e);if(!t||!Nn.selection.change)return;let n=ft({providerID:Nn.selection.value.providerID??``,modelID:Nn.selection.value.modelID??``,agent:Nn.selection.value.agent??null},t,Nr,Fr);Nn.selection.change({...Nn.selection.value,...n,agent:n.agent??void 0}),Nn.kind===`primary`&&(s.getState().addRecentAgent(t),Nn.sessionID&&vi.getState().saveSessionAgentSelection(Nn.sessionID,t))},[Nr,mr,Fr,Ir,Nn.kind,Nn.selection,Nn.sessionID]);Ze.current=fc;let pc=Z.useRef(null),[mc,hc]=Z.useState(null),gc=Z.useCallback(e=>{hc(t=>t===e?t:e)},[]),_c=Z.useCallback(e=>{let t=Oi.current;if(!t)return;let n=t.scrollTop;if(Wa){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,fe(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=Cb({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:pc.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),fe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[Wa]);Z.useLayoutEffect(()=>{let e=si.length<Fi.current;Fi.current=si.length,_c({allowShrink:e})},[_c,si,Hr]),Z.useLayoutEffect(()=>{pc.current=mc,_c({allowShrink:mc===null})},[_c,mc]);let vc=Z.useCallback((e,t,n=`manual`,r)=>{let i=Ho({text:e,cursor:t,inputMode:h,mentionInputSource:n,insertedText:r});if(Pi.current=i,!i){N(!1),O(!1),z(!1),te(!1),H(``);return}if(i.kind===`slash-command`){I(i.query),N(!0),O(!1),z(!1),te(!1);return}if(N(!1),i.kind===`slash-skill`){H(i.query),z(!0),O(!1),te(!1);return}if(z(!1),H(``),i.kind===`snippet`){ae(i.query),te(!0),O(!1);return}te(!1),j(i.query),O(!0)},[h,I,j,N,O,z,te,H,ae]),yc=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(h===`normal`&&!Ai.current&&oo.size>0&&e.includes(`/`)){let r=us(e,oo,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=fi(a,o,s,(e,t)=>{let n=[...e];for(let e of hr(t.text,{agentNames:Qa,includeUnterminatedPastedReferences:r===`paste`}))n=ts(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=ra(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Oi.current;e&&Mm(u,Ai.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),_c()}),vc(l.text,c.end,r,i),{document:l,selection:c}},[_c,fi,ra,h,Qa,oo,vc]),bc=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=Oi.current;if(!n){let n=si+e;yc(n,n.length,n.length,t,e);return}let r=n.selectionStart??si.length,i=n.selectionEnd??si.length,a=`${si.substring(0,r)}${e}${si.substring(i)}`,o=r+e.length;yc(a,o,o,t,e)},[yc,si]),xc=J((e,t)=>{let n=new Set(Ce(In.map(e=>e.filename),e,t));if(n.size!==0)for(let e of In)n.has(e.filename)&&Fn.removeAttachment(e.id)}),Sc=Z.useCallback(e=>{Fn.removeAttachment(e.id)},[Fn]),Cc=Z.useCallback(()=>{Bi.current=!1,Gi.current=[],Hi.current&&=(clearTimeout(Hi.current),null)},[]),wc=Z.useCallback(()=>{Hi.current&&clearTimeout(Hi.current),Hi.current=setTimeout(()=>{Cc()},700)},[Cc]),Tc=Z.useCallback(()=>{Ui.current=!1,Wi.current&&=(clearTimeout(Wi.current),null)},[]),Ec=Z.useCallback(()=>{Ui.current=!0,Wi.current&&clearTimeout(Wi.current),Wi.current=setTimeout(()=>{Ui.current=!1,Wi.current=null},700)},[]),Dc=Z.useCallback(e=>{!d()||!Bi.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),Cc())},[Cc]),Oc=e=>{if(qr)return;let t=e.nativeEvent;if(d()&&Bi.current){let n=Gi.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){Cc();return}}let n=e.target.value;xc(ta.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Fb(ta.current,n):``,a=i.includes(`@`)||Ui.current;Ui.current&&Tc();let o=a?`paste`:`manual`;if(h===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);g(`shell`),li(e),_c(),N(!1),z(!1),O(!1),requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=t,Oi.current.selectionEnd=t)});return}yc(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{Cc(),Tc()},[Cc,Tc]);let kc=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=Oi.current,i=r?.selectionStart??si.length,a=r?.selectionEnd??si.length,o=Xo(n,si.slice(0,i),si.slice(a)),s=`${si.slice(0,i)}${o}${si.slice(a)}`;xc(si,s),ia(s,t)},[si,ia,xc]),Ac=Z.useCallback(async e=>{let t=Ub(e.clipboardData);if(t.length>0&&(Ln||Vn)){e.preventDefault(),kc(t);return}if(h===`normal`&&(Ln||Vn)){let t=Oi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=si.slice(n,r);if(Mb.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${si.slice(0,n)}[${i}](${t})${si.slice(r)}`,o=n+1+i.length+2+t.length+1;wi(a),requestAnimationFrame(()=>{let e=Oi.current;e&&(e.selectionStart=o,e.selectionEnd=o),_c()}),vc(a,o,Ib(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(h===`normal`&&Qy(ra(),a)){e.preventDefault();let t=ra().text,n=Oi.current,r=n?.selectionStart??si.length,i=n?.selectionEnd??si.length,o=$y(a,si,ra().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),Zy(ra())),s=mi(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=os(s.document.text,s.caret);Oi.current&&(Oi.current.value=s.document.text),requestAnimationFrame(()=>{Oi.current?.setSelectionRange(c,c),_c()}),vc(s.document.text,c),xc(t,s.document.text);return}a.includes(`@`)&&Ec();return}if(!Ln&&!Vn){a.includes(`@`)&&Ec();return}e.preventDefault();let o=je(i,[...In.map(e=>e.filename),...na.current]),s=Be(o),c=ra().text,l=Oi.current,u=l?.selectionStart??si.length,d=l?.selectionEnd??si.length,p=h===`normal`&&Qy(ra(),a)?$y(a,si,ra().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),Zy(ra())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=Xo(m,si.slice(0,u),si.slice(d));if(p){let e=mi(u,d,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=os(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;yc(n,t+s.length,t+s.length,Ib(n),s),xc(c,n)}else bc(g,Ib(g)),xc(c,`${si.slice(0,u)}${g}${si.slice(d)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Pb(i[e],t);na.current.add(t);try{await Fn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.clipboardAttachFailed`))}finally{na.current.delete(t)}}},[Fn,kc,In,_c,Ln,ra,h,mi,Ec,si,Vn,bc,f,vc,yc,wi,xc]),jc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=Tv(r,i,[...De(si,In.filter(Fe).map(e=>e.filename)),...wv(si,ao.keys()),...ra().references]),o=a?.start??r,s=a?.end??i,c=si.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${si.slice(0,o)}${si.slice(s)}`;yc(e,o,o),requestAnimationFrame(()=>{Oi.current?.setSelectionRange(o,o),_c()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Oi.current?.setSelectionRange(o,s)})},[_c,In,ao,yc,ra,si]),Mc=Z.useCallback(e=>{jc(e,`copy`)},[jc]),Nc=Z.useCallback(e=>{jc(e,`cut`)},[jc]),Pc=e=>{let t=Oi.current,n=t&&document.activeElement===t?t.selectionStart??Ni.current:Ni.current;return ds(e,n)},Fc=()=>{Ls(Hr)||Oi.current?.focus()},Ic=e=>{let t=Pc(si.length),n=Ro(si,t,Pi.current),r=si.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():qc(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=is(si,o,s,`@${i}`);ia(c.text,[i],a),Ni.current=c.caret,requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=c.caret,Oi.current.selectionEnd=c.caret),_c(),vc(c.text,c.caret)}),O(!1),j(``),Fc()},Lc=e=>{let t=Pc(si.length),n=Ro(si,t,Pi.current),r=si.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=is(si,i,a,`@${e}`);wi(o.text,t=>ts(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Ni.current=o.caret,requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=o.caret,Oi.current.selectionEnd=o.caret),_c(),vc(o.text,o.caret)}),O(!1),j(``),Fc()},Rc=J(e=>{Xi.current||(Xi.current=!0,(async()=>{try{let t=Zr.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){Tt.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await vt(e.id,{directory:t}),!sr(e.id,t)){Tt.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Pr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=ra(),r=Pc(n.text.length),i=Ro(n.text,r,Pi.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=Mi().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,l={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:o})},u=mi(s,c,l,{inlineBoundaries:!0,padDocumentEdges:!0}),d=os(u.document.text,u.caret);Ni.current=d,requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=d,Oi.current.selectionEnd=d),_c(),vc(u.document.text,d)}),O(!1),j(``),Fc()}catch{Tt.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Xi.current=!1}})())}),zc=J(e=>{let t=ra(),n=Pc(t.text.length),r=Ro(t.text,n,Pi.current)??No(t.text,n);if(!r)return!1;let i=mi(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=os(i.document.text,i.caret);return Ni.current=o,requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=o,Oi.current.selectionEnd=o),_c(),vc(i.document.text,o),a&&(N(!1),z(!1))}),Fc(),a}),Bc=e=>{zc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&H(``)},Vc=(e,t)=>{let n=Pc(si.length),r=Ro(si,n,Pi.current),i=si.substring(0,n).lastIndexOf(`#`),a=r?.start??(i===-1?n:i),o=r?.end??n,s=`${si.substring(0,a)}#${t} ${si.substring(o)}`;wi(s);let c=a+t.length+2;Ni.current=c,requestAnimationFrame(()=>{Oi.current&&(Oi.current.selectionStart=c,Oi.current.selectionEnd=c),_c(),vc(s,c)}),te(!1),ae(``),Fc()},Hc=(e,t=!1)=>{if(!Im(Nn,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){zc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&I(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&zc({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){I(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=us(r,new Set([...oo,e.name.toLowerCase()]),r.length);li(i?.text??r);let a=Oi.current;if(a&&(a._commandMetadata=e),N(!1),I(``),t){Qs({presetText:n});return}let o=()=>{if(!Ls(Hr)&&Oi.current){try{Oi.current.focus({preventScroll:!0})}catch{Oi.current.focus()}Oi.current.setSelectionRange(Oi.current.value.length,Oi.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Ln&&Oi.current&&!Hr&&Oi.current.focus()},[Ln,Hr]),Z.useEffect(()=>{Hr||me(null)},[Hr]);let Uc=Fn.abortPrompt.sessionID,Wc=Fn.abortPrompt.clear;Z.useEffect(()=>{Uc&&Uc!==Ln&&Wc()},[Ln,Uc,Wc]),Z.useEffect(()=>{Ki.current=!!(Ln||Vn)},[Ln,Vn]);let Gc=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 Gv(e).length>0},[]),Kc=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)},[]),qc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(va||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[va]),Jc=e=>{if(!Gc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),zi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==T&&E(t),(Ln||Vn)&&!y&&w(!0)},Yc=e=>{Gc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Ln||Vn)&&!y&&w(!0))},Xc=e=>{e.preventDefault(),e.stopPropagation(),zi.current--,zi.current<=0&&(zi.current=0,w(!1),E(!1),Cc())},Zc=()=>{zi.current=0,w(!1),E(!1),Cc()},Qc=async e=>{if(zi.current=0,!Gc(e.dataTransfer)){Cc();return}if(e.preventDefault(),e.stopPropagation(),w(!1),!Ln&&!Vn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Oi.current,r=ta.current;if(n){let t=n.selectionStart??Ni.current,i=n.selectionEnd??t,a=is(r,t,i,e);wi(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Ni.current=a.caret,n.focus()})}else{let t=is(r,r.length,r.length,e);wi(t.text)}Cc();return}let n=Ub(e.dataTransfer);if(n.length>0){d()&&(Gi.current=n),kc(n),d()||Cc();return}let r=Kc(e.dataTransfer);if(r.length>0){let e=Be(r.map(e=>e.name)),t=Xo(e,ta.current.slice(0,Oi.current?.selectionStart??ta.current.length),ta.current.slice(Oi.current?.selectionEnd??ta.current.length));bc(t);for(let e of r)try{await Fn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}}Cc()},$c=e=>{Gc(e.dataTransfer)&&(e.preventDefault(),d()&&(Bi.current=!0,wc()))},Q=Z.useRef(null),el=Z.useRef(null),tl=J((e=!0)=>{Ge.current=0;let t=()=>{let t=Am(Oi);if(!t||(jm(Oi),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),nl=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Be(t.map(e=>e.name)),n=Xo(e,ta.current.slice(0,Oi.current?.selectionStart??ta.current.length),ta.current.slice(Oi.current?.selectionEnd??ta.current.length));bc(n)}for(let e of t)try{await Fn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}},[Fn,bc,f]),rl=Z.useCallback(async()=>{try{let e=await la?.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
|
-
`);Tt.error(f(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(
|
|
6536
|
-
`)})),e.length!==0&&nl(e)},onRemoveAttachment:e=>{Fn.removeAttachment(e)},onOpenModel:()=>_s(`model`),onCycleAgent:()=>fc(),onOpenAgent:Ys,showScrollToBottom:!!(a&&o),scrollAria:f(`chat.scrollToBottom.aria`),onScrollToBottom:o??(()=>{}),autocompleteOpen:oe.length>0&&(M||R||D),autocompleteHighlightedIndex:le,autocompleteRows:oe,caret:Ni.current,onAutocompleteAccept:Kl,onAutocompleteDismiss:ql,chipHighlights:ho}),Yl=Z.useRef(null);at(Jl?Yl:null,()=>{let e=Yl.current?.getBoundingClientRect().height??0;Ns(document.documentElement,e)});let Xl=Z.useRef(!1);Xl.current=bo||So;let Zl=Z.useRef(!1),Ql=Z.useRef(0),$l=Z.useRef(0),eu=J(()=>{let e=Zr.getState().stagedMessageEdit;!e||e.sessionId!==Ln||window.setTimeout(()=>{let t=Zr.getState().stagedMessageEdit,n=document.activeElement,r=hy({surfaceKind:Nn.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:Bs(),focusHeld:Date.now()<$l.current,overlayOpen:Ql.current>0||Xl.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<Ge.current});r.action===`disarm`&&Zr.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Hr||Re()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Ql.current+=1},t=()=>{if(Ql.current=Math.max(0,Ql.current-1),Zl.current){Zl.current=!1;return}if(!Je.current||Xl.current||Ql.current>0)return;if(ga()){Je.current=!1;return}Je.current=!1,$l.current=Date.now()+600,Oi.current?.focus(),document.activeElement===Oi.current&&ve(!0);let e=()=>{let e=Oi.current;!e||document.activeElement!==e||(tu.current??e).scrollIntoView({block:`end`})};he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),he.current=window.setTimeout(()=>{he.current=null,e()},300),ge.current=window.setTimeout(()=>{ge.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[Hr]),Z.useEffect(()=>{if(!Hr)return;if(Vl){(_e||Date.now()-qe.current<800)&&(Je.current=!0);return}if(!Je.current)return;let e=window.setTimeout(()=>{if(Je.current=!1,ga())return;let e=Oi.current;e&&document.activeElement!==e&&e.focus({preventScroll:Re()})},180);return()=>window.clearTimeout(e)},[Hr,Vl,_e]),Z.useEffect(()=>{if(!Hr||Re()||typeof document>`u`||_e||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Oi.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[Hr,_e]),Z.useEffect(()=>{Ie(``)},[Ae]);let tu=Z.useRef(null),nu=Hr?`px-1.5 py-1.5`:ll?`px-1.5 py-1`:`px-2.5 py-1.5`,ru=Hr?`h-8 w-8`:ll?`h-5 w-5`:`h-6 w-6`,iu=Hr?`h-4 w-4`:ll?`h-3.5 w-3.5`:`h-4 w-4`,au=Hr?`h-6 w-6`:`size-full`,ou=Hr?`h-[1.125rem] w-[1.125rem]`:ll?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,cu=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,mm),lu=Y(cu,ru),uu=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`,ru),du=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(()=>()=>{yo.current&&=(clearTimeout(yo.current),null)},[]);let fu=Hr?(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)(Yb,{onOpenAgentPanel:Ys,onCycleAgent:()=>{Ke(),fc()},agentName:Nn.selection.value.agent,agents:Nr,disabled:Br}),(0,$.jsx)(Xb,{onOpenModel:()=>_s(`model`),providerID:Nn.selection.value.providerID,modelID:Nn.selection.value.modelID,provider:Fr.find(e=>e.id===Nn.selection.value.providerID),variant:Nn.selection.value.variant})]}):null,pu=(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)(xd,{attachments:In,onShowPopup:Wr,onRemoveAttachedFile:Sc}),Nn.kind===`primary`?(0,$.jsx)(Td,{attachedFiles:In,onAddVSCodeFile:(e,t,n)=>{qn&&Wt(qn,()=>on.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(qn)return Wt(qn,()=>on.getState()).addVSCodeSelection(e,t)}}):null]}),mu=ho?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Ov,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),hu=Hr?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,Ds&&`oc-mobile-composer-compact-chrome--aborting`,ws&&!Ds&&`oc-mobile-composer-compact-chrome--sending`,a&&o&&`oc-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)($b,{isVSCode:ll,footerIconButtonClass:lu,iconSizeClass:ou,handlePickLocalFiles:il,handlePickLocalImages:al,openIssuePicker:Xs,openPrPicker:Zs,onOpenMobileSheet:zl,onOpenAndroidPickSheet:fl()?Bl:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[a&&o?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(yg,{placement:`compact`,visible:a,onClick:o})}):null,Ds||ws?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(tx,{isMobile:!0,compact:!0,footerIconButtonClass:lu,stopFooterIconButtonClass:uu,compactCircleButtonClass:du,sendIconSizeClass:iu,stopIconSizeClass:au,canSend:ws,canAbort:Ds,hasContent:!1,currentSessionId:Ln,newSessionDraftOpen:Vn,draftSubmitting:Bn,submissionBlocked:l,sendPhase:Fs,queueFrozen:Ss,queueFallbackAvailable:Ds||Es,onPrimaryAction:$s,onAbort:dc})}):null]})]}):null,gu=Hr?(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)($b,{isVSCode:ll,footerIconButtonClass:lu,iconSizeClass:ou,handlePickLocalFiles:il,handlePickLocalImages:al,openIssuePicker:Xs,openPrPicker:Zs,onOpenSettings:e,onOpenMobileSheet:zl,onOpenAndroidPickSheet:fl()?Bl:void 0}),_r?(0,$.jsx)(ex,{sessionId:Ln,draftOpen:Vn,draftEnabled:Lt.permissionAutoAcceptEnabled===!0,enabled:fr,saving:Ln?Jt:!1,footerIconButtonClass:lu,iconSizeClass:ou,onSetDraftEnabled:Kt,onSetSessionEnabled:Yt,onOpenSessionFirst:Gt,onToggleFailed:vr}):null,(0,$.jsx)(ey,{sessionId:Ln,directory:bt??Kn,draftOpen:Vn}),(0,$.jsx)(ty,{length:si.length})]}),fu,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(tx,{isMobile:Hr,footerIconButtonClass:lu,stopFooterIconButtonClass:uu,sendIconSizeClass:iu,stopIconSizeClass:au,canSend:ws,canAbort:Ds,hasContent:!!bs,currentSessionId:Ln,newSessionDraftOpen:Vn,draftSubmitting:Bn,submissionBlocked:l,sendPhase:Fs,queueFrozen:Ss,queueFallbackAvailable:Ds||Es,onPrimaryAction:$s,onAbort:dc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,cl),children:[(0,$.jsx)($b,{isVSCode:ll,footerIconButtonClass:lu,iconSizeClass:ou,handlePickLocalFiles:il,handlePickLocalImages:al,openIssuePicker:Xs,openPrPicker:Zs,onOpenSettings:e,withTooltip:!0}),_r?(0,$.jsx)(ex,{sessionId:Ln,draftOpen:Vn,draftEnabled:Lt.permissionAutoAcceptEnabled===!0,enabled:fr,saving:Ln?Jt:!1,footerIconButtonClass:lu,iconSizeClass:ou,onSetDraftEnabled:Kt,onSetSessionEnabled:Yt,onOpenSessionFirst:Gt,onToggleFailed:vr}):null,(0,$.jsx)(ey,{sessionId:Ln,directory:bt??Kn,draftOpen:Vn}),(0,$.jsx)(ty,{length:si.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,cl),children:[(0,$.jsx)(qb,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Oi,selectionAdapter:Dr}),(0,$.jsx)(Jb,{radius:qa,isMobile:Hr,footerIconButtonClass:lu,footerPaddingClass:nu,iconSizeClass:ou,sendIconSizeClass:iu,onInsert:tc,onInsertAndSend:nc,onContentHeightChange:gc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(tx,{isMobile:Hr,footerIconButtonClass:lu,stopFooterIconButtonClass:uu,sendIconSizeClass:iu,stopIconSizeClass:au,canSend:ws,canAbort:Ds,hasContent:!!bs,currentSessionId:Ln,newSessionDraftOpen:Vn,draftSubmitting:Bn,submissionBlocked:l,sendPhase:Fs,queueFrozen:Ss,queueFallbackAvailable:Ds||Es,onPrimaryAction:$s,onAbort:dc})]})]}),_u=J(()=>{if(Hr){$l.current=Date.now()+600;let e=()=>{Oi.current?.focus({preventScroll:Re()}),document.activeElement===Oi.current&&ve(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!jm(Oi))return;let e=Am(Oi);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),vu=bt??Kn,{goal:yu,enabled:bu}=Jv(Ln??``,vu),xu=(0,$.jsx)(Cp,{onEditMessage:qs,onSendMessage:Js,onEditCommitted:_u,draftKey:qn,scope:Ao,draftTarget:qn?{key:qn,expectedRevision:()=>Fn.getDraft(qn)?.revision??`absent`}:null,clientPendingItems:Hs,onRemoveClientPending:e=>{let t=gn.getState().removeEstablishingFollowUp(e);t&&(t.content&&li(t.content),t.attachments.length>0&&Fn.restoreAttachments(t.attachments))},trailing:Ln&&bu&&yu?(0,$.jsx)($v,{sessionId:Ln,directory:vu}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:tu,onSubmit:e=>{e.preventDefault(),$s()},onPointerDownCapture:e=>{if(!Hr)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"]`)&&(Ke(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,Va&&`flex h-full min-h-0 flex-col pt-4`,Ha&&`flex h-full min-h-0 flex-col pt-1`,Hr&&`bottom-safe-area oc-mobile-composer`),"data-native-ios-composer":Jl?`true`:void 0,style:Hr&&Re()&&!Jl&&Jr>0&&!_e?{marginBottom:`${Jr}px`}:void 0,children:[Hn&&!Va&&!Hr&&!ll&&!Ml?(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:Kb(hl?f(`chat.emptyState.draftTitleWithProject`,{project:hl}):f(`chat.emptyState.draftTitle`),hl)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Wa&&`flex flex-1 min-h-0 flex-col`),children:[Jl?null:(0,$.jsx)(Sd,{attachments:In,onShowPopup:Wr,onRemoveAttachedFile:Sc}),(0,$.jsx)(Vp,{}),es&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[ss>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ha?.colors?.surface?.elevated,borderColor:ha?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ha?.colors?.status?.info},children:ss}),(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:fs,"aria-label":f(`chat.chatInput.reviewCommentsRemove`),title:f(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,ns>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ha?.colors?.surface?.elevated,borderColor:ha?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ha?.colors?.status?.info},children:ns}),(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:()=>cs(`preview-console`),"aria-label":f(`chat.chatInput.devServerLogsRemove`),title:f(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,as>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ha?.colors?.surface?.elevated,borderColor:ha?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ha?.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:()=>cs(`preview-annotation`),"aria-label":f(`chat.chatInput.previewContextRemove`),title:f(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),wo&&!ll&&(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:()=>xo(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[wo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:wo.author.avatarUrl,alt:wo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,wo.number,wo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:wo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:wo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:wo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{To(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.removeAria`),title:f(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),Eo&&!ll&&(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:[f(`chat.chatInput.linked.pr.number`,{number:Eo.number}),Eo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:Eo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Eo.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[Eo.head,` → `,Eo.base]})]}),(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":f(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Oo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.removeAria`),title:f(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(Qb,{sessionId:Ln,directory:bt??Kn}),(0,$.jsxs)(`div`,{className:Hr?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:Hr?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:Hr?`oc-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:Yl,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(Zb,{showAbortStatus:ja,showAssistantStatus:!1,showTodos:!0,leftAccessory:Vn||!Nl?null:(0,$.jsx)(_g,{})}),!Hr&&ul?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[dl?(0,$.jsxs)(Ea,{value:dl.id,open:Ve,onValueChange:Il,onOpenChange:e=>{He(e),e||ze(``)},children:[(0,$.jsx)(La,{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]`,fm),children:[(0,$.jsx)(ya,{children:Rl(dl)}),(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)(Ta,{fitContent:!0,children:[(0,$.jsx)(za,{autoFocus:!0,value:Le,onChange:e=>ze(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),tr.filter(e=>Ia(Gb(e),Le)||Ia(e.path,Le)).map(e=>(0,$.jsx)(Fa,{value:e.id,className:`max-w-[24rem] truncate`,children:Rl(e)},e.id)),(0,$.jsx)(Ca,{}),(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(),He(!1),requestAnimationFrame(()=>Ei.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,fm),onClick:()=>Ei.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),dl&&Fl?(0,$.jsx)(cv,{directory:Ol,projectDirectory:ml,label:jl,projectRootOption:El,worktreeOptions:Dl,onSelectDirectory:Ll}):null]}):null,Hr&&ul?(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:[dl?(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`,fm),onClick:()=>Me(`project`),children:Rl(dl)}):(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`,fm),onClick:()=>Ei.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),dl&&Fl?(0,$.jsx)(cv,{directory:Ol,projectDirectory:ml,label:jl,projectRootOption:El,worktreeOptions:Dl,onSelectDirectory:Ll,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,xu]})}),(0,$.jsx)(`div`,{className:Y(!Hr&&`contents`,Hr&&`contents`,Ha&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:Hr?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(B_,{value:si,attachments:[],disabled:!Ln&&!Vn||Bn&&!Fs.establishing,pending:Ds||Fs.inFlight&&!Fs.establishing,isMobile:Hr,onSubmit:$s,"data-mobile-composer-surface":Hr?`true`:void 0,"data-session-swipe-surface":Hr?`true`:void 0,expanded:Wa,focusedTone:h===`shell`?`info`:`primary`,className:Y(`relative z-10`,y&&`ring-2 ring-primary ring-offset-2`,qr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,Hr&&`oc-mobile-composer-surface`),style:{borderRadius:qa},ref:Li,onDropCapture:$c,onDragEnter:Jc,onDragOver:Yc,onDragLeave:Xc,onDrop:Qc,onDragEnd:Zc,autoResize:!1,disableInputWhilePending:!1,contentClassName:Wa?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:pu,highlightedContent:mu,highlightRef:Na,inputRef:Oi,textLayoutClassName:Y(wb,Wa?Y(`h-full min-h-0`,Hr?`py-2.5`:`py-4`):Hr?`py-2.5`:`pt-4 pb-2`,h===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Wa&&`flex-1 min-h-0`),inputStyle:{flex:Wa?`1 1 auto`:`none`,height:!Wa&&de?`${de.height}px`:void 0,maxHeight:!Wa&&de?`${de.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":Wa?`100%`:de?`${de.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!Wa&&de?`${de.maxHeight}px`:`none`,borderTopLeftRadius:qa,borderTopRightRadius:qa},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,nu,Hr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,cl)),footerStyle:{borderBottomLeftRadius:qa,borderBottomRightRadius:qa},footerContent:gu,placeholder:Ja,onChange:(e,t)=>Oc(t),textareaProps:{readOnly:qr,onCompositionStart:()=>{Ai.current=!0},onCompositionEnd:e=>{Ai.current=!1;let t=e.currentTarget;yc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Dc,onKeyDown:oc,onCopy:Mc,onCut:Nc,onPaste:Ac,onDragEnter:Jc,onDragOver:Yc,onDropCapture:$c,onDrop:Qc,onDragEnd:Zc,onKeyUp:cc,onClick:()=>{cc()},onScroll:e=>{cc();let t=e.currentTarget.scrollTop;Na.current&&(Na.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Ai.current){Ni.current=r;return}let i=Tv(n,r,[...De(si,In.filter(Fe).map(e=>e.filename)),...wv(si,ao.keys()),...ai.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Ni.current=i.end):Ni.current=n,cc()},onFocus:()=>{if(Hr){if(Date.now()<Ge.current){let e=Oi.current;e&&e.blur();return}ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null),ve(!0)}},onBlur:e=>{if(Ai.current=!1,Ni.current=e.currentTarget.selectionStart??Ni.current,eu(),Hr){if(Date.now()<$l.current){let e=Oi.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<$l.current&&document.activeElement!==e&&e.focus()},50);return}}if(qe.current=Date.now(),Re()){ve(!1);return}ye.current!==null&&window.clearTimeout(ye.current),ye.current=window.setTimeout(()=>{ye.current=null,ve(!1)},120)}},autoCorrect:Hr?`on`:`off`,autoCapitalize:Hr?`sentences`:`off`,spellCheck:Hr||$r,fillContainer:Wa,rows:1},children:[(0,$.jsx)(dh,{}),y&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:qa},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:cu,onClick:()=>il(),title:f(`chat.chatInput.actions.attachFiles`),"aria-label":f(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(ou,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:f(T?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(Po,{ref:Qi,searchQuery:P,directory:Kn,onCommandSelect:Hc,onClose:()=>N(!1),commandPolicy:Gl,commandContext:Jn,onRowsChange:Jl?Wl:void 0,style:Va&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0}),R&&(0,$.jsx)(Kp,{ref:$i,searchQuery:V,directory:Kn,onSkillSelect:Bc,onClose:()=>z(!1),onRowsChange:Jl?Wl:void 0,style:Va&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0}),q&&(0,$.jsx)(Wo,{ref:ea,searchQuery:ie,onSnippetSelect:Vc,onClose:()=>te(!1),style:Va&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(Qo,{ref:qi,searchQuery:k,onFileSelect:Ic,onAgentSelect:Lc,onSessionSelect:Rc,onClose:()=>O(!1),onRowsChange:Jl?Wl:void 0,style:Va&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Hr?(0,$.jsx)(Jb,{radius:qa,isMobile:Hr,footerIconButtonClass:lu,footerPaddingClass:nu,iconSizeClass:ou,sendIconSizeClass:iu,onInsert:tc,onInsertAndSend:nc,onContentHeightChange:gc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),Hr?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[hu,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!si.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:si.trim()?si:Ya})]}):null]}),Hr?(0,$.jsx)(qb,{className:`hidden`,composerTextareaRef:Oi,selectionAdapter:Dr,mobilePanel:pe,onMobilePanelChange:me}):null]}),Vn&&!Va&&!Hr&&!ll&&!Ml?(0,$.jsx)(N_,{onSubmit:ec,className:`chat-input-column mt-4`}):null]}),p.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Tb,{popup:p,onOpenChange:Kr,isMobile:Hr})}):null,(0,$.jsx)(u_,{open:bo,onOpenChange:xo,mode:`select`,onSelect:e=>{To(e),Oo(null)}}),(0,$.jsx)(p_,{open:So,onOpenChange:Co,onSelect:e=>{Oo(e),To(null)}}),(0,$.jsx)(Ju,{open:or,onOpenChange:cr,projectDirectory:bt??Kn??null,submitting:lr,onConfirm:Ba}),(0,$.jsx)(`input`,{ref:Q,type:`file`,multiple:!0,className:`hidden`,onChange:sl,accept:`*/*`}),(0,$.jsx)(`input`,{ref:el,type:`file`,multiple:!0,className:`hidden`,onChange:sl,accept:`image/*`}),null,Hr?(0,$.jsx)(_a,{id:`android-media-pick-sheet`,open:Se,onOpenChange:e=>{e||Ee(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:f(`chat.chatInput.actions.addAttachment`)}),ariaLabel:f(`chat.chatInput.actions.addAttachment`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(ca,{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:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(ol)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(ca,{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:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(il)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,Hr&&ul&&dl?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(_a,{id:`mobile-draft-project-picker-sheet-${Ne}`,open:Ae===`project`,onOpenChange:e=>{e||Me(null)},ariaLabel:f(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(za,{value:Pe,onChange:e=>Ie(e.target.value),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(da,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:tr.filter(e=>Ia(Gb(e),Pe)||Ia(e.path,Pe)).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:()=>{Il(e.id),Me(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:Rl(e)}),e.id===dl.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:()=>{Me(null),Ei.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},sx=e=>{let t=(0,Q.c)(3),n=Rm(),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)(ox,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};sx.displayName=`ChatInput`;var cx=Z.memo(sx);function lx(e){return e.preventDefault()}function ux(e){e.preventDefault()}function dx(e){return e.preventDefault()}function fx(e){e.pointerType===`touch`&&e.preventDefault()}function px(e){e.preventDefault()}function mx(e){e.pointerType===`touch`&&e.preventDefault()}function hx(){let e=(0,Q.c)(47),{t}=ot(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>mo(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=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],ws(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await Vc(n),Tt.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}Tt.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=Re()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(ca,{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 gx=(e,t)=>{if(t.length===0)return e;let n=new Map(t.map(e=>[e.info.id,e])),r=!1,i=e.map(e=>{if(kt(e.parts))return e;let t=n.get(e.info.id);return t?(r=!0,t):e}),a=r?i:e,o=new Set(e.map(e=>e.info.id)),s=t.filter(e=>!o.has(e.info.id));return s.length===0?a:[...a,...s]},_x=(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},vx=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}},yx=e=>e.syncLoading||e.assistantLoading,bx=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),xx=e=>e.isLoadingOlder,Sx=e=>!e.isMobile&&e.isLoadingOlder,Cx=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,wx=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`,Tx=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}},Ex=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Dx=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Ox=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,kx=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)(ka,{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},Ax=e=>{let t=(0,Q.c)(42),{t:n}=ot(),r=s(jx),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Ox,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 ${Dx}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,c;t[11]!==e.agentName||t[12]!==o?(c=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=c):c=t[13];let l=c,u=e.modelName||o,d;t[14]===n?d=t[15]:(d=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=d);let f=`${d}: ${l}`,p;t[16]===n?p=t[17]:(p=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=p);let m=`${p}: ${u}`,h=r&&Ox,g;t[18]===h?g=t[19]:(g=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] p-3`,h),t[18]=h,t[19]=g);let _=r&&`oc-mobile-readonly-prompt-surface`,v;t[20]===_?v=t[21]:(v=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,_),t[20]=_,t[21]=v);let y;t[22]===n?y=t[23]:(y=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=y);let b;t[24]===y?b=t[25]:(b=(0,$.jsx)(`div`,{className:`text-muted-foreground ${Dx}`,children:y}),t[24]=y,t[25]=b);let x;t[26]!==f||t[27]!==l||t[28]!==m||t[29]!==u||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(x=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(sa,{name:e.agentName,size:14,label:f}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:l,children:l})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(kx,{providerId:e.providerId,modelId:e.modelId,label:m}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:u,children:u})]})]}):null,t[26]=f,t[27]=l,t[28]=m,t[29]=u,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=x):x=t[34];let S;t[35]!==x||t[36]!==v||t[37]!==b?(S=(0,$.jsxs)(`div`,{className:v,children:[b,x]}),t[35]=x,t[36]=v,t[37]=b,t[38]=S):S=t[38];let C;return t[39]!==S||t[40]!==g?(C=(0,$.jsx)(`aside`,{className:g,children:S}),t[39]=S,t[40]=g,t[41]=C):C=t[41],C};function jx(e){return e.isMobile}var Mx=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ot(),{currentTheme:n}=Ua(),r=At(Nx),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Ja,{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 Nx(e){return e.error}var Px=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)}}},Fx=`oc:legend-timeline`,Ix=()=>{try{return typeof localStorage>`u`||localStorage.getItem(Fx)!==`0`}catch{return!0}},Lx=ue(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t}),legendTimelineEnabled:Ix(),setLegendTimelineEnabled:t=>{try{typeof localStorage<`u`&&localStorage.setItem(Fx,t?`1`:`0`)}catch{}e({legendTimelineEnabled:t})}})),Rx=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:Zt(t)},zx=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?Rx(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)(ka,{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(${ea(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`,ea(o).class),children:[(0,$.jsx)(sa,{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}),Bx=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,Vx=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,Hx=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),Ux=(e,t)=>e.split(Vx).map((e,n)=>n%2==1?e:t(e)).join(``),Wx=e=>Ux(e,e=>e.replace(/ *\n/g,`
|
|
6537
|
-
`)),Gx=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=Ux(e,Hx);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${vc(t.name)})`;i=i.replace(t.token,e)}i=i.replace(Bx,(e,t,r)=>n.has(r)?`${t}[/${r}](${hc(r)})`:e)}return Wx(i)},Kx=e=>(Bx.lastIndex=0,Bx.test(e)||e.includes(`[skill:`)),qx=e=>e===`markdown`?`markdown`:`plain`,Jx=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)},Yx=Z.memo(({part:e,messageId:t,agentMention:n,messageParts:r})=>{let i=e,a=i.text,o=typeof a==`string`?a:i.content||i.value||``,[c,l]=Z.useState(!1),[u,d]=Z.useState(!1),f=s(e=>e.userMessageRenderingMode),p=s(e=>e.collapsibleUserMessages),m=lc(),h=Tr({directory:m,enabled:Kx(o)}),g=Z.useMemo(()=>h.data??[],[h.data]),_=s(e=>e.openContextFile),{t:v}=ot(),y=qx(f),b=p&&!c,x=Z.useRef(null),S=Z.useMemo(()=>new Map(g.map(e=>[e.name,e])),[g]),C=Z.useMemo(()=>If(r,o),[r,o]),w=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!tr(t))continue;let n=t.text;if(typeof n==`string`)for(let t of lr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of Mi()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${ee}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),T=J(e=>{let t=S.get(e),n=typeof t?.path==`string`?t.path:``,r=yo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=m||go(``,i)||`/`,o=()=>{_(a,i)};if(m&&!So(i,m)){uc(i,m).then(o);return}o()});Z.useEffect(()=>{let e=x.current;if(!e)return;let t=()=>{p&&!c&&d(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[p,o,c]),Z.useEffect(()=>{p||(l(!1),d(!1))},[p]);let E=J(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??fc(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),T(n);return}let r=x.current;r&&(Jx(r)||p&&!c&&u&&l(!0))}),D=J(e=>{e.stopPropagation(),l(!1)}),O=Z.useMemo(()=>Af(o,{skillNames:new Set(S.keys()),citationIcons:C.icons,citationDisplayNames:C.displayNames,sessionMentions:w,agentNames:n?.name?new Set([n.name.toLowerCase(),n.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),[n,C,w,S,o]),k=Z.useMemo(()=>Gx({textContent:o,agentMention:n,skillNames:new Set(S.keys()),decorateInlineReferences:!O}),[n,O,S,o]),A=(e,t)=>{if(!e)return null;if(y===`markdown`){let n=Gx({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(ks,{content:n,className:Y(`inline w-auto align-baseline [&_.markdown-content]:contents [&_.markdown-content_p]:inline [&_[data-markdown-size-spacer]]:inline`,`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,b&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1},t)}return(0,$.jsx)(Z.Fragment,{children:e},t)},j=e=>e.map((e,t)=>e.type===`text`?A(e.text,`text-${t}`):(0,$.jsx)(Rf,{decoration:e.decoration,onOpenSkill:T},`ref-${t}-${e.span.start}`)),M=Z.useMemo(()=>{if(O)return j(O);let e=[],t=0,r=!1,i;for(Bx.lastIndex=0;(i=Bx.exec(o))!==null;){let n=i[1]||``,r=i[2],a=i.index+n.length;S.has(r)&&(i.index>t&&e.push(o.slice(t,i.index)),n&&e.push(n),e.push((0,$.jsxs)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:e=>{e.stopPropagation(),T(r)},children:[`/`,r]},`skill-${a}-${r}`)),t=a+r.length+1)}t<o.length&&e.push(o.slice(t));let a=e.length>0?e:[o];return!n?.token||!o.includes(n.token)?a:a.flatMap((e,t)=>{if(r||typeof e!=`string`)return e;let i=e.indexOf(n.token);return i===-1?e:(r=!0,[e.slice(0,i),(0,$.jsx)(`a`,{href:dc(n.name),className:`text-primary hover:underline`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:n.token},`agent-${t}`),e.slice(i+n.token.length)])})},[n,T,O,j,S,o]);return!o||o.trim().length===0?null:(0,$.jsxs)(`div`,{className:`relative`,children:[p&&c&&(0,$.jsx)(`button`,{type:`button`,onClick:D,className:`absolute top-0 right-0 z-10 flex items-center justify-center rounded-sm bg-[var(--surface-elevated)] p-0.5 text-[var(--surface-mutedForeground)] hover:text-[var(--surface-foreground)] hover:bg-[var(--interactive-hover)] transition-colors`,"aria-label":v(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,c&&`pb-3`,y===`plain`&&`whitespace-pre-wrap`,b&&`line-clamp-10`,p&&u&&!c&&`cursor-pointer`),ref:x,onClick:E,children:y===`markdown`?O?j(O):(0,$.jsx)(ks,{content:k,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,b&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1}):M})]},e.id||`${t}-user-text`)}),Xx=[{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)(Zc.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)(Zc.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)(Zc.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)(Zc.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 Zx(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=Xx.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||Xx[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 Qx=e=>{let t=`h-3.5 w-3.5 flex-shrink-0`,n=`h-[13px] w-[13px] flex-shrink-0`,r=e.toLowerCase();return r===`edit`||r===`multiedit`||r===`apply_patch`||r===`str_replace`||r===`str_replace_based_edit_tool`?(0,$.jsx)(X,{name:`pencil`,className:n}):r===`write`||r===`create`||r===`file_write`?(0,$.jsx)(X,{name:`file-edit`,className:n}):r===`read`||r===`view`||r===`file_read`||r===`cat`?(0,$.jsx)(X,{name:`file-text`,className:t}):r===`bash`||r===`shell`||r===`cmd`||r===`terminal`?(0,$.jsx)(X,{name:`terminal-box`,className:t}):r===`list`||r===`ls`||r===`dir`||r===`list_files`?(0,$.jsx)(X,{name:`folder-6`,className:t}):r===`search`||r===`grep`||r===`find`||r===`ripgrep`?(0,$.jsx)(X,{name:`menu-search`,className:t}):r===`glob`?(0,$.jsx)(X,{name:`file-search`,className:t}):r===`fetch`||r===`curl`||r===`wget`||r===`webfetch`||r===`web-search`||r===`websearch`||r===`search_web`||r===`codesearch`||r===`google`||r===`bing`||r===`duckduckgo`||r===`perplexity`?(0,$.jsx)(X,{name:`global`,className:t}):r===`todowrite`||r===`todoread`?(0,$.jsx)(X,{name:`list-check-3`,className:t}):r===`structuredoutput`||r===`structured_output`?(0,$.jsx)(X,{name:`list-check-2`,className:t}):r===`skill`?(0,$.jsx)(X,{name:`book`,className:t}):r===`task`?(0,$.jsx)(X,{name:`ai-agent`,className:t}):r===`question`?(0,$.jsx)(X,{name:`survey`,className:t}):r===`lsp`?(0,$.jsx)(X,{name:`scan-2`,className:t}):r===`plan_enter`?(0,$.jsx)(X,{name:`file-list-2`,className:t}):r===`plan_exit`?(0,$.jsx)(X,{name:`task`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},$x=new Map,eS=e=>{let t=$x.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return $x.set(e,n),n},tS=(e,t)=>{let n=eS(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=$x.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),$x.delete(e)))}},nS=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(rS),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return tS(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 rS(){return Date.now()}var iS=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],aS=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},oS=e=>{if(!e||typeof e!=`object`)return;let t=e;return aS(t.sessionId)??aS(t.sessionID)},sS=(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},cS=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},lS=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:aS(e.sessionId)??aS(e.sessionID),status:aS(e.status),summaryEntries:cS(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},uS=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=lS(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 aS((n?.[1]??r?.[1])||iS(e))},dS=e=>{if(!(!e||typeof e!=`object`))return aS(e.status)},fS=/"status"\s*:\s*"running"/i,pS=/\bstatus\s*[:=]\s*["'`]?running\b/i,mS=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]&&fS.test(t[1])?!0:pS.test(e)},hS=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,gS=(e,t)=>aS(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),_S=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},vS=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(hS);if(!t)return;let n=gS(t[1],`sessionID`)??gS(t[1],`sessionId`),r=_S(gS(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:gS(t[1],`description`),body:t[2].trim()}},yS=new WeakMap,bS=e=>{let t=yS.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 yS.set(e,n),n},xS=e=>{let t=[];for(let n of e)t.push(...bS(n));return t},SS=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),CS=[`summary`,`changes`,`verification`],wS={summary:`Summary`,changes:`Changes`,verification:`Verification`},TS=/<(summary|changes|verification)(?:\s[^>]*)?>/i,ES=()=>RegExp(`<(${CS.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),DS=e=>typeof e!=`string`||e.length===0?!1:TS.test(e),OS=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!DS(e)?e:e.replace(ES(),(e,t,n)=>{let r=wS[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),kS=e=>OS(SS(e)),AS=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 jS(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 MS=(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},NS=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},PS=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},FS=e=>e?.state,IS=e=>e?.metadata,LS=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},RS=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,``):``},zS=(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||NS(r)!==NS(i))return!1;if(r.type===`tool`){if(FS(r)!==FS(i)||IS(r)!==IS(i)||PS(r)!==PS(i))return!1;let e=LS(r),t=LS(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=LS(r),o=LS(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(RS(r)!==RS(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},BS=(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)&&MS(e.tokens,t.tokens),VS=(e,t)=>BS(e.info,t.info)&&zS(e.parts,t.parts),HS=(e,t)=>!e||!t?e===t:VS(e,t),US=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,WS=(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},GS=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&zS([e.part],[t.part]),KS=(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(!GS(a,o))return!1;r+=1,i+=1}},qS=(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(!GS(e.parts[n],t.parts[n]))return!1;return!0},JS=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),YS=(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(!qS(a,o))return!1;r+=1,i+=1}},XS=(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||!KS(e.activityParts,t.activityParts,n)||!YS(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=JS(e.activityGroupSegments,n)||JS(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!US(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!WS(e.changedFiles,t.changedFiles))},ZS=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,QS=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,$S=/(?=^diff --git\s+)/gm,eC=/^diff --git\s+/m,tC=/(?=^---\s+\S)/gm,nC=/^---\s+\S/m,rC=e=>typeof e==`object`&&!!e,iC=e=>e.replace(/\r\n/g,`
|
|
6534
|
+
`)?`${t}\n`:`${t}\n\n`}`,ux=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},dx=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,fx=[],px=({onOpenSettings:e,scrollToBottom:r,showScrollToBottom:a=!1,onScrollToBottom:o,submissionBlocked:l=!1,surface:u})=>{let{t:f}=ot(),[p,m]=Z.useState({open:!1,title:``,content:``}),[h,g]=Z.useState(`normal`),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(!1),[k,j]=Z.useState(``),[M,N]=Z.useState(!1),[P,I]=Z.useState(``),[R,z]=Z.useState(!1),[V,H]=Z.useState(``),[q,te]=Z.useState(!1),[ie,ae]=Z.useState(``),[oe,se]=Z.useState([]),[le,ue]=Z.useState(0),[de,fe]=Z.useState(null),[pe,me]=Z.useState(null),he=Z.useRef(null),ge=Z.useRef(null),[_e,ve]=Z.useState(!1),ye=Z.useRef(null);Z.useEffect(()=>()=>{ye.current!==null&&window.clearTimeout(ye.current),he.current!==null&&window.clearTimeout(he.current),ge.current!==null&&window.clearTimeout(ge.current)},[]);let[be,xe]=Z.useState(!1),[Se,Ee]=Z.useState(!1),[Ae,Me]=Z.useState(null),Ne=Z.useId(),[Pe,Ie]=Z.useState(``),[Le,ze]=Z.useState(``),[Ve,He]=Z.useState(!1),[Ue,We]=Z.useState(!1),Ge=Z.useRef(0),Ke=Z.useCallback(()=>{Ge.current=Date.now()+500},[]),qe=Z.useRef(0),Je=Z.useRef(!1),[Ye,Xe]=Z.useState(-1),Ze=Z.useRef(()=>{}),Qe=Z.useRef((...e)=>Promise.resolve().then(()=>Zr.getState().sendMessage(...e))).current,$e=Zr(e=>e.currentSessionId),et=Qr(e=>e.currentProviderId),tt=Qr(e=>e.currentModelId),nt=Qr(e=>e.currentAgentName),rt=Qr(e=>e.currentVariant),it=Qr(e=>e.providers),st=Qr(e=>e.agents),ct=Qr(e=>e.getVisibleAgents),lt=Z.useMemo(()=>Em(ct()),[ct,st]),ut=Qr(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),mt=Qr(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ht=Z.useMemo(()=>{let e=it.find(e=>e.id===et)?.models?.find(e=>e.id===tt);return Nm(e)},[tt,et,it]),gt=we(e=>e.currentDirectory),_t=lc()??gt,{ensureSessionRenderable:vt}=Eu(),bt=Zr(Z.useCallback(e=>$e?e.getDirectoryForSession($e):null,[$e])),xt=di($e??``,bt??void 0),St=Z.useMemo(()=>Qy(xt),[xt]),Ct=Z.useMemo(()=>$y(xt),[xt]),Et=oi($e??``,bt??void 0).renderable,Dt=pt($e,bt??void 0),Ot=Dt?.agent,kt=Dt?.model?.id,At=Dt?.model?.providerID,Mt=Dt?.model?.variant,Nt=Qr(e=>e.activeDirectoryKey),Pt=Z.useRef(0),Ft=Z.useRef(null),Lt=Z.useRef(null),Rt=Zr(e=>e.newSessionDraft),Bt=!!Rt?.open,Ht=Zr(e=>e.newSessionDraft.draftSubmitting??!1),Ut=Zr(e=>e.newSessionDraft.draftEstablishing??!1),Gt=Ht||Ut,Kt=Zr(e=>e.openNewSessionDraft),qt=Zr(e=>e.setDraftPermissionAutoAcceptEnabled),Jt=wt(e=>e.autoAccept),Yt=wt(e=>e.saving),Qt=wt(e=>e.setSessionAutoAccept),en=Zr(e=>e.setNewSessionDraftTarget),tn=Zr(e=>e.availableWorktreesByProject),nn=Zr(e=>e.abortPromptSessionId),rn=Zr(e=>e.clearAbortPrompt),an=on(e=>e.consumePendingInputText),cn=on(e=>e.pendingPresetSubmit),ln=on(e=>e.pendingInputText),un=on(e=>e.pendingInputMode),dn=on(e=>e.consumePendingSyntheticParts),fn=on(e=>e.activeAttachmentDraft),mn=Mu(Z.useCallback(e=>{let t=$e??(Bt?`draft`:``);return t?e.drafts[t]??Pb:Pb},[Bt,$e])),hn=Ii($e??``),_n=Z.useSyncExternalStore(t,n,n),vn=fn?.transportIdentity??null,yn=fn?.owner.kind??null,bn=fn?.owner.ownerID??null,Cn=Z.useMemo(()=>dx(_n,$e,Rt.draftID,vn&&yn&&bn?{transportIdentity:vn,owner:{kind:yn,ownerID:bn}}:null),[bn,yn,vn,_n,$e,Rt.draftID]),wn=Cn?ce(Cn):null,En=on(Z.useCallback(e=>wn?e.draftAttachmentViews[wn]:void 0,[wn])),On=on(Z.useCallback(e=>wn?e.drafts[wn]:void 0,[wn])),kn=Z.useMemo(()=>{if(!On||!En)return fx;let e=On.attachments.flatMap(e=>{let t=En[e.attachmentRefID];return t?[t]:[]});return e.length===0?fx:e},[En,On]);Z.useEffect(()=>{Cn&&on.getState().hydrateDraftAttachments(Cn)},[Cn]);let An=Rm(),jn=s(e=>e.activeMainTab===`chat`),Mn=wr($e??``,_t??void 0),Nn=zm({kind:`primary`,surfaceID:`primary`,active:jn,sessionID:$e,directory:_t??null,activity:{phase:Mn?.type===`busy`?`busy`:Mn?.type===`retry`?`retry`:`idle`,canAbort:Mn?.type===`busy`||Mn?.type===`retry`},draftKey:Cn,transportIdentity:_n,runtimeGeneration:c(),selection:{value:{providerID:et,modelID:tt,agent:nt,variant:rt},catalog:{providers:it,agents:lt,variants:ht,variantsReady:!ut,ready:!ut&&!mt,loading:ut||mt},flush:async()=>{let e=Zr.getState().currentSessionId;if(!e)return;let t=c(),r=n(),i=Pt.current,a=e,o=Zr.getState().getDirectoryForSession(a)??null,s=br(o);if(Qr.getState().activeDirectoryKey!==s&&await Qr.getState().activateDirectory(o),c()!==t||n()!==r||Zr.getState().currentSessionId!==a||Qr.getState().activeDirectoryKey!==s||Pt.current!==i)return;await vt(a,{directory:o??void 0});let l=Zr.getState().getDirectoryForSession(a)??null,u=br(l);if(c()!==t||n()!==r||Zr.getState().currentSessionId!==a||l!==o||u!==s||Qr.getState().activeDirectoryKey!==s||Pt.current!==i)return;let d=Qr.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=pi(a,l??void 0),m=Qy(p),h=$y(p);if(Gy({editRevision:i,pinnedHistoryMessageId:Ft.current,latestHistoryMessageId:m?.id??null}))return;let g=vi.getState(),_=Mi().get(a),v=Hy({sessionId:a,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=[a,v.source,v.messageId??``,v.agent??``,v.providerID,v.modelID,v.variant??``,s].join(`|`);Lt.current!==y&&(Uy(v,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:a,memory:g}),Lt.current=y)},change:async e=>{Pt.current+=1;let t=Zr.getState().currentSessionId;if(t){let e=Zr.getState().getDirectoryForSession(t)??void 0,n=Qy(pi(t,e));Ft.current=n?.id??null}else Ft.current=null;let n=Qr.getState();Iy(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:vi.getState()})}},resources:{attachments:kn,addAttachment:async e=>{Cn&&await Wt(Cn,()=>on.getState()).addLocal(e)},removeAttachment:async e=>Cn?Wt(Cn,()=>on.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>Cn?Wt(Cn,()=>on.getState()).clearRootAttachments():!1,restoreAttachments:async e=>Cn?Wt(Cn,()=>on.getState()).restoreRootAttachments(e):!1,pendingInput:ln===null?null:{text:ln,mode:un},consumePendingInput:an,pendingPreset:cn,consumePendingPreset:()=>on.getState().consumePendingPresetSubmit(),consumeSyntheticParts:dn,restoreSyntheticParts:e=>on.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:mn,removeInlineDraft:e=>{let t=$e??(Bt?`draft`:``);t&&Mu.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=$e??(Bt?`draft`:``);!t||e.length===0||Mu.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:hn,captureRuntime:()=>on.getState().captureDraftRuntime(),getDraft:e=>on.getState().getDraft(e),abortPrompt:{sessionID:nn,clear:rn}},backend:{send:e=>{My(e,{transportIdentity:n(),runtimeGeneration:c()});let t=Ny(e);return Qe(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Ji(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()=>Kt(),compact:async e=>ke.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&It(e.sessionID),Zi(e.sessionID??``))},shortcuts:{cycle:e=>Ze.current(e),new:()=>Kt(),abort:()=>($e&&It($e),Zi($e??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),Pn=Bm(Nn,u??An);Vm(Pn),Z.useLayoutEffect(()=>{if(!Pn.active){jy(Pn.surfaceID);return}return Ay(Pn),()=>jy(Pn.surfaceID)},[Pn]);let Fn=Fy(Pn),In=Pn.resources??(Pn.kind===`primary`?Nn.resources:void 0);if(!In)throw Error(`chat-input-surface-resources-incomplete`);let Ln=[...In.attachments],Bn=Pn.sessionID,Vn=Hm(Pn,Gt),Hn=Pn.kind===`secondary`?Pn.commands.hasNewDraft:Bt,Kn=Hn,qn=Pn.directory??_t,Jn=Pn.draftKey??Cn,Zn=Z.useMemo(()=>{if(Pn.kind===`secondary`)return Wm(Pn,!1,!1);let e=Bn?Gb(Bn,bt??void 0):!1;return Wm(Pn,e,Hn)},[Pn,Bn,bt,Hn]),Qn=(e,t,n,r,i,a,o,s,c,l)=>Fn?Fn.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`)),tr=Z.useCallback(()=>Fn?Fn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[Fn]),nr=xn(e=>e.projects),ar=xn(e=>e.activeProjectId),or=xn(e=>e.setActiveProjectIdOnly),[cr,lr]=Z.useState(!1),[dr,fr]=Z.useState(!1),pr=Z.useMemo(()=>Bn?Vi({autoAccept:Jt,sessions:[],sessionById:Mi(),sessionID:Bn}):Rt.permissionAutoAcceptEnabled===!0,[Bn,Rt.permissionAutoAcceptEnabled,Jt]),mr=Qr(e=>e.agents),gr=Pn.kind===`secondary`?Pn.selection.value.agent:nt,_r=Pn.kind===`secondary`?Em(Pn.selection.catalog?.agents):mr,vr=d()||Cy(_r,gr),yr=Z.useCallback(()=>{Tt.error(f(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[f]),xr=Pn.selection.value,Cr=Pn.selection.change,Dr=Pn.selection.catalog,kr=Z.useMemo(()=>({selection:{providerID:xr.providerID??``,modelID:xr.modelID??``,agent:xr.agent??null,variant:xr.variant},onChange:async e=>{if(!Cr)throw Error(`chat-input-surface-selection-readonly`);await Cr({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!Pn.active,catalog:Dr}),[Dr,Cr,xr.agent,xr.modelID,xr.providerID,xr.variant,Pn.active]);Z.useEffect(()=>{Pt.current=0,Ft.current=null,Lt.current=null},[$e]),Z.useEffect(()=>{if(Pn.kind!==`primary`||!$e||ut||mt||it.length===0||lt.length===0)return;let e=br(bt);if(Nt!==e)return;let t=vi.getState(),n={providers:it,agents:lt};if(Gy({editRevision:Pt.current,pinnedHistoryMessageId:Ft.current,latestHistoryMessageId:St?.id??null}))return;let r=Hy({sessionId:$e,latestUserChoice:St,latestExecution:Ct,catalog:n,memory:t,sessionEntity:At&&kt?{agent:Ot,model:{id:kt,providerID:At,variant:Mt}}:Ot?{agent:Ot}:null,fallbackAgentName:nt,transcriptReady:Et});if(!r)return;let i=[$e,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,Nt].join(`|`);if(Lt.current===i)return;if((r.agent===void 0||r.agent===nt)&&r.providerID===et&&r.modelID===tt&&r.variant===rt){Lt.current=i;return}if(Qr.getState().activeDirectoryKey!==e)return;let a=Qr.getState();Uy(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:$e,memory:t}),Lt.current=i},[Pn.kind,$e,St,Ct,Et,it,lt,ut,mt,Nt,bt,nt,et,tt,rt,Ot,kt,At,Mt]);let Ar=Qr(e=>e.getVisibleAgents),Mr=Pn.kind===`primary`?Ar():Fb,Nr=Qr(e=>Pn.kind===`primary`?e.providers:Ib),Fr=Pn.kind===`secondary`?Em(Pn.selection.catalog?.agents):Mr,Ir=Pn.kind===`secondary`?Pn.selection.catalog?.providers??Ib:Nr,Br=Pn.kind===`secondary`&&(!Pn.selection.catalog?.ready||!!Pn.selection.catalog.error),Hr=!Pn.active||!Pn.selection.change||Br,Ur=s(e=>e.isMobile),Wr=s(e=>e.setImagePreviewOpen),Kr=Z.useCallback(e=>{e.image&&(m(e),Wr(!0))},[Wr]),qr=Z.useCallback(e=>{m(t=>({...t,open:e})),Wr(e)},[Wr]),Jr=su(e=>e.pending),Yr=s(e=>e.inputBarOffset),$r=s(e=>e.persistChatDraft),ei=s(e=>e.inputSpellcheckEnabled),ti=s(e=>e.isExpandedInput),ni=s(e=>e.setExpandedInput),ri=s(e=>e.setTimelineDialogOpen),ai=kb({draftKey:Jn,sessionTitles:new Map(Array.from(Mi(),([e,t])=>[e,t.title||e])),persistenceEnabled:$r}),si=ai.document,li=si.text,{replacePlainDocument:ui,replaceProgrammaticText:fi,applyBrowserEdit:mi,insertReference:hi,deleteReference:gi,enterHistoryPreview:yi,exitHistoryPreview:bi,captureSubmission:xi,recoverSubmission:Si,confirmedFileMentions:Ci,mentions:wi}=ai,Di=Z.useCallback((e,t)=>fi(e,t),[fi]),Oi=Z.useMemo(()=>new Set(Ci.map(e=>e.value)),[Ci]),Ai=Z.useRef(null),Ni=Z.useRef(!1),Pi=Z.useRef(0),Fi=Z.useRef(null),Li=Z.useRef(li.length),zi=Z.useRef(null),Bi=Z.useRef(0),Hi=Z.useRef(!1),Ui=Z.useRef(null),Wi=Z.useRef(!1),Gi=Z.useRef(null),Ki=Z.useRef([]),qi=Z.useRef(!1),Xi=Z.useRef(null),Qi=Z.useRef(!1),$i=Z.useRef(null),ea=Z.useRef(null),ta=Z.useRef(null),na=Z.useRef(li),ra=Z.useRef(new Set),ia=ai.getDocument,aa=Z.useCallback((e,t,n=[])=>Di(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}`))]}),[Di]),sa=Fh(Ph()),{git:la,vscode:ua}=Do(),fa=s(e=>e.shortcutOverrides.cycle_agent),pa=s(e=>e.shortcutOverrides),ma=Z.useMemo(()=>Xa(`cycle_agent`,fa?{cycle_agent:fa}:void 0),[fa]),ha=Z.useMemo(()=>Xa(`clear_all_messages`,pa),[pa]),{currentTheme:va}=Ua(),ba=Zo(),wa=ls(qn),Oa=qo(e=>qn?e.directories.get(qn)?.status??null:null),ka=qo(e=>e.ensureStatus),ja=qo(e=>e.fetchStatus),[Ma,Na]=Z.useState(!1),Pa=Z.useRef(null),[Ra,Ba]=Z.useState(!1);Z.useEffect(()=>{!qn||!la||ka(qn,la)},[qn,la,ka]),Z.useEffect(()=>{if(!(!qn||!la))return Ei.onGitRefreshHint(e=>{Zb(e.directory)===Zb(qn)&&ja(qn,la)})},[qn,la,ja]);let Va=Z.useCallback(async e=>{if(!Bn)return;let t=Zr.getState().getDirectoryForSession(Bn)||qn||``;if(!t){Tt.error(f(`diffView.reviewDialog.toast.noSessionDirectory`));return}fr(!0);try{await sn({originalSessionID:Bn,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}),lr(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),Tt.error(e instanceof Error?e.message:f(`diffView.reviewDialog.toast.startFailed`))}finally{fr(!1)}},[Bn,qn,f]),Ha=ti&&!Ur,Wa=ti&&Ur,qa=Ha||Wa,Ja=`1.5rem`,Ya=f(Bn||Hn?h===`shell`?`chat.chatInput.placeholder.shell`:Ur||Ra?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Za=f(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=zi.current;if(!e)return;let t=e=>{let t=e>0&&e<Bb;Ba(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 Qa=Ln,$a=Z.useMemo(()=>new Set(Fr.map(e=>e.name.toLowerCase())),[Fr]),eo=Z.useRef($a);eo.current=$a;let to=Rb({inputMode:h,message:li,showCommandAutocomplete:M,showSkillAutocomplete:R}),no=jt({directory:qn,enabled:to}),ro=Z.useMemo(()=>no.data??[],[no.data]),io=Tr({directory:qn,enabled:to}),ao=Z.useMemo(()=>io.data??[],[io.data]),oo=Z.useMemo(()=>new Map(ao.map(e=>[e.name.toLowerCase(),e.name])),[ao]),so=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`plan-feature`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!Ur&&!d()&&e.add(`handoff-review`);for(let t of ro)e.add(t.name.toLowerCase());for(let t of ao)e.add(t.name.toLowerCase());return e},[ro,ao,Ur]),co=Z.useMemo(()=>{if(!li||!li.includes(`/`)||h===`shell`||so.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(li))!==null;){let t=n[2]??``,r=n[3];if(!so.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=oo.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:re({trigger:`/`,icon:`book-open`,label:o},li.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:re({trigger:`/`,icon:`command`,label:r},li.slice(i,i+a))})}return e},[oo,h,so,li]),lo=xa(e=>e.snippets),uo=Z.useMemo(()=>{let e=new Set;for(let t of lo){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[lo]),fo=Z.useMemo(()=>{if(!li||!li.includes(`#`)||h===`shell`||uo.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(li))!==null;){let t=n[2];if(!uo.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[h,uo,li]),po=Z.useMemo(()=>!li||!li.includes(`@`)||h===`shell`?[]:Vr(li,{confirmedValues:Oi,agentNames:$a}),[Oi,h,$a,li]),mo=Z.useMemo(()=>{if(!li||!li.includes(`[`)||h===`shell`||Qa.length===0)return[];let e=Qa.filter(Fe),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return De(li,e.map(e=>e.filename)).flatMap(e=>{let n=G(li.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:re({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},li.slice(e.start,e.end))}]})},[h,li,Qa]),ho=Ls(Ur)&&Pn.kind===`primary`,go=Z.useMemo(()=>{if(!li||h===`shell`)return null;let e=[...ho?[]:Sv(li),...ho?[]:Rv(li),...Dv(po),...co,...fo,...mo,...si.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return Cv(li,e)},[mo,co,fo,po,si.references,h,li,ho]),_o=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?Yb(e.serverPath):e.dataUrl})),[]),[vo,yo]=Z.useState(null),bo=Z.useRef(null),[xo,So]=Z.useState(!1),[Co,wo]=Z.useState(!1),[To,Eo]=Z.useState(null),[Oo,ko]=Z.useState(null),Ao=C(e=>e.followUpBehavior),Mo=Z.useMemo(()=>{let e=Fn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[Fn]),Fo=Gu({transportIdentity:Mo?.transportIdentity??``,directory:Mo?.directory??``,sessionID:Mo?.sessionID??``}),Io=Z.useMemo(()=>Bn?x(Bn):null,[Bn]),Lo=C(Z.useCallback(e=>Mo?b(e,Mo):Nb,[Mo])),zo=C(Z.useCallback(e=>Io?b(e,Io):Nb,[Io])),Uo=Z.useMemo(()=>zo.length===0?Lo:Lo.length===0?zo:[...zo,...Lo],[Lo,zo]),Go=Fo.mode===`server`?Nb:Uo,Ko=C(Z.useCallback(e=>Mo?B(e,Mo):Nb,[Mo])),Jo=C(e=>e.clearQueue),$o=C(e=>e.removeFromQueue),es=In.inlineDrafts,ns=es.length>0,[as,ss,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]),fs=Z.useCallback(e=>{for(let t of In.inlineDrafts)t.source===e&&In.removeInlineDraft(t.id)},[In]),ps=Z.useCallback(()=>{for(let e of In.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&In.removeInlineDraft(e.id)},[In]),ms=In.history;Z.useEffect(()=>{na.current=li},[li]),Z.useLayoutEffect(()=>{g(`normal`),Xe(-1)},[Jn?.transportIdentity,Jn?.owner.kind,Jn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Hn||Ur)return;let e=()=>{let e=Ai.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Hn,Ur]);let hs=jg(Pn.kind===`primary`?Bn:null,Pn.kind===`primary`?qn??void 0:void 0),gs=Pn.activity?.phase??hs.phase,_s=Xn(Z.useCallback(e=>{if(!Bn)return!1;let t=e.runsByOriginalSessionID[Bn];return t?.status===`running`&&t.runtimeKey===i()},[Bn])),vs=J(e=>{Ur&&(Ke(),me(e),Ai.current?.blur(),Qr.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),ys=In.pendingInput,bs=In.consumePendingInput;Z.useEffect(()=>{if(ys===null)return;let e=bs();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=lx(na.current,e.text);na.current=t,Di(t)}else if(e.mode===`append-inline`){let t=ux(na.current,e.text);na.current=t,Di(t)}else ui(e.text);setTimeout(()=>{Ai.current?.focus()},0)}},[ys,bs,ui,Di]);let xs=li.trim().length>0||Qa.length>0||ns,Ss=Fo.mode===`server`?Fo.items.length>0:Go.length>0||Ko.length>0,ws=!Bf(Fo.mode),Ts=xs||Ss,Es=Zr(e=>e.stagedMessageEdit?.sessionId===Bn?e.stagedMessageEdit.messageId:null),Ds=gs===`busy`||gs===`retry`,Os=Pn.activity?.canAbort??Ds,ks=Z.useCallback(()=>{let e=Ai.current,t=e?.value??ia().text;t!==ia().text&&mi(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=ia();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Qa.length>0||ns}},[mi,ia,ns,Qa.length]),As=Z.useRef(async()=>{}),js=Pn.surfaceID,Ms=Rt?.draftID??null,Ps=gn(Z.useMemo(()=>yt(js),[js])),Fs=gn(Z.useMemo(()=>pn(Ms),[Ms])),Is=Z.useMemo(()=>Xr(Ps,Fs),[Ps,Fs]),Rs=(e=`send`)=>gn.getState().beginFlight(js,e),Bs=()=>{gn.getState().endFlight(js)},Vs=()=>gn.getState().isInFlight(js),Hs=Z.useRef(null);Z.useEffect(()=>{if(Pn.kind!==`primary`||!Es){Hs.current=null;return}if(Hs.current!==Es){if(Hs.current=Es,ho){Cs().focus();return}jm(Ai)||requestAnimationFrame(()=>jm(Ai))}},[ho,Es,Pn.kind]);let Us=gn(Z.useMemo(()=>Gr(Ms),[Ms])),Ws=J(async()=>{let e=Zr.getState().newSessionDraft.draftID;if(!e||!gn.getState().isEstablishing(e))return!1;let t=ks();if(!t.hasContent)return!1;let n=K(t.document,`queue-canonical`);if(!n.ok)return Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;if(await Pn.selection.flush(),!gn.getState().isEstablishing(e))return!1;let r=Wy(Qr.getState());if(!r?.providerID||!r?.modelID)return Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;let i=_o(Qa);return gn.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})?(ui(``),Xe(-1),ni(!1),i.length>0&&In.clearAttachments(),!0):!1}),Gs=()=>{if(Bn)return!1;let e=Zr.getState().newSessionDraft.draftID;return gn.getState().isEstablishing(e)?(Ws(),!0):!1},Ks=J(async()=>{if(!Pn.active||Vs())return;if(Bn){let e=Zr.getState().stagedMessageEdit;if(e&&e.sessionId===Bn){Zr.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await zn(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{Zr.getState().endMessageEditCommit(e.sessionId,e.messageId)}Zr.getState().stagedMessageEdit===e&&Zr.getState().clearStagedMessageEdit(e.sessionId)}}let e=ks(),t=K(e.document);if(!t.ok){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:t.chunks??[],semantics:t.semantics??[]},i=t.text,a=i.trimStart(),o=r.chunks.every(e=>e.provenance===`authored`)&&h===`normal`&&a.startsWith(`/`)?jo(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(o&&!Bo(o,e=>Im(Pn,{name:e.name,source:`openchamber`}))||l||!e.hasContent||!Bn)return;if(ws||!zt(Pn.deliveryTarget?.kind,Fo.mode)){As.current(Ds?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&ly(i,h)){As.current();return}if(!Rs(`queue`))return;let s=Pn.transportIdentity,u=Pn.runtimeGeneration,d=In.captureRuntime(),p=Mo,m=Pn.kind===`primary`?Mo?.sessionID??Bn:null,g=[...In.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Fu(e.document.text,g),e.document.references).document:e.document,y=K(_,`queue-canonical`);if(!y.ok){Bs(),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let b=_o(Qa),w=xi(),T=b,E=$n(),D=!1,O=null,k=()=>{D&&p&&(Fo.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(C.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&Si(w),T.length>0&&await In.restoreAttachments(T),e&&In.restoreSyntheticParts(e),g.length>0&&In.restoreInlineDrafts(g)};try{if(!p){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(Fo.mode===`server`){if(!Jn){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}_i({stage:()=>{Fo.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:wi}}),D=!0},clearComposer:()=>{ui(``),Xe(-1),ni(!1)}})}else _i({stage:()=>{C.getState().bindLegacyQueue(x(p.sessionID),p),C.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:wi}),O=E.requestID},clearComposer:()=>{ui(``),Xe(-1),ni(!1)}});if(await Pn.selection.flush(),!Tn({transportIdentity:s,generation:u},{transportIdentity:n(),generation:c()})){await A();return}if(!Tn(d,In.captureRuntime())){await A();return}if(m&&Zr.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==n()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&S(Zr.getState().getDirectoryForSession(m))!==S(p.directory)){await A();return}let t=p,r=Pn.kind===`primary`?(()=>{let e=Qr.getState(),t=m?Zr.getState().getDirectoryForSession(m)??null:null;return Wy(e,{expectedConfigKey:br(t),activeDirectoryKey:e.activeDirectoryKey})})():Pn.selection.value.providerID&&Pn.selection.value.modelID?{...Pn.selection.value,providerID:Pn.selection.value.providerID,modelID:Pn.selection.value.modelID}:void 0;if(!rr(r)){await A();return}if(Fo.mode===`server`){if(!Jn){await A(),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let n=Xt({draftKey:Jn,runtime:d,document:e.document,attachments:Qa,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?In.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=ci({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:Fr,installedSkillNames:new Set(Sr(ne,qn).map(e=>e.name)),directory:qn,root:ba||qn,confirmedFilePaths:Ci.map(e=>e.path),confirmedDirectoryPaths:Ci.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Qa});return o=e.attachments,dt({text:g.length>0?Fu(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:ii(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...$t(b),...$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),Tt.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Or(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Wn({capture:n,admit:async()=>{let n=await Fo.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:wi,sendConfig:r,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return n.status===`committed`&&(e=!0,D=!1),n},captureRuntime:In.captureRuntime,getCurrentDraftKey:()=>Jn,getDocument:ia,consumeBody:()=>ui(``),getAttachments:()=>In.attachments,removeAttachment:In.removeAttachment,getInlineDrafts:()=>In.inlineDrafts,removeInlineDraft:In.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!Ur&&Ai.current?.focus()}catch(e){await A(i),Tt.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)In.removeInlineDraft(e.id);b.length>0&&In.clearAttachments(),Ur||Ai.current?.focus()}catch(e){await A(),Tt.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Bs()}}),qs=J(()=>{yy(()=>Ks(),()=>{Tt.error(f(`chat.chatInput.toast.messageSendFailed`))})}),Js=J(async(e,t,n,r)=>{if(ws||!Pn.draftKey)return!1;try{let i=await Gn({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=on.getState(),o=a.getDraft(Pn.draftKey);return Hf(await Rn({key:Pn.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return Tt.error(f(`chat.chatInput.toast.messageSendFailed`)),!1}}),Ys=J(e=>{if(!(l||ws)){if(Fn){Fn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}Tt.error(f(`chat.chatInput.toast.messageSendFailed`))}}),Xs=J(()=>{Ke(),me(`agent`),Ai.current?.blur(),Qr.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),Zs=Z.useCallback(()=>{So(!0)},[]),Qs=Z.useCallback(()=>{wo(!0)},[]),$s=async e=>{if(!Pn.active||l||Gs()||Vs())return;let t=e?.queuedOnly??!1,i=e?.queuedMessageId,a=e?.delivery===`steer`&&Ds?`steer`:void 0,o=e?.presetText==null?ks():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Qa.length>0||ns},u=e?.presetText==null?xi():null,p=Ln,m=K(o.document,`direct-send-display`);if(!m.ok){Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}let g=m.text,v={chunks:m.chunks??[],semantics:m.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?sy(x,h):null,w=y&&ly(g,h),T=y&&h===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&h===`normal`&&x.startsWith(`/`)?jo(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Bo(E,e=>Im(Pn,{name:e.name,source:`openchamber`}))||t&&ws)return;if(!t&&T){N(!1),I(``),Ur?vs(`model`):(s.getState().setModelSelectorOpen(!0),Qr.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&S&&S!==`model`)){if(!t&&Bn&&Ss&&ws)return;if(!t&&Bn&&Ss&&Fo.mode===`server`){o.hasContent&&qs();return}if(!t&&Bn&&Ss){o.hasContent&&qs();let e=Go[0];e&&Fn&&await Fn.sendQueued(e.queueItemID,{options:Ds?{delivery:`steer`}:void 0});return}}let D=w?[]:i?Go.filter(e=>e.id===i):Go;if(t&&_s)return;if(t){if(D.length===0||!Bn)return}else if(!o.hasContent&&!Ss||!Bn&&!Hn)return;if(!Bn&&Vn||!Rs())return;let O=!Bn&&Hn&&!t&&!w?Zr.getState().newSessionDraft.draftID??null:null,k=O?W(`msg`):void 0;if(O&&k&&!gn.getState().beginEstablishing({draftID:O,primaryMessageID:k})){Bs();return}let A=()=>{ur(),O&&gn.getState().clearEstablishing(O)},j=e=>{let t=Zr.getState().currentSessionId,r=(t?Zr.getState().getDirectoryForSession(t):null)??qn??``;if(!t||!r){gn.getState().clearEstablishing(e);return}vy({draftID:e,sessionID:t,directory:r,transportIdentity:n(),runtimeGeneration:c(),admitServer:Fo.mode===`server`?async e=>Fo.actions.admit({requestID:e.requestID,scope:{directory:r,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?$t(e.attachments):void 0}):void 0})};if(Bn&&!t&&!w&&_s){Bs(),qs();return}let M=!t&&!w;M&&(ui(``),Xe(-1),ni(!1));let P=!1,F,L,R=!1;try{if(my({surfaceKind:Pn.kind,currentSessionId:Bn,queuedOnly:t,resourcePolicy:w,inputMode:h,localCommand:S})&&Bn){let e=Zr.getState().getDirectoryForSession(Bn)??qn??null,t=Zr.getState().stagedMessageEdit;t&&t.sessionId===Bn&&(L={sessionId:t.sessionId,messageId:t.messageId},Zr.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Qr.getState(),r=Wy(n,{expectedConfigKey:br(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=_o(Qa);F=Un({sessionId:Bn,directory:e,content:o.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=Pn.kind===`primary`?(()=>{if(t){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(Mo?.sessionID)return Mo.sessionID}return Bn})():null,n=t?D[0]?.sendConfig:void 0;if(t&&n||await Pn.selection.flush(),e!==null&&Zr.getState().currentSessionId!==e)return;let s=async()=>{let t=n?{...n}:Pn.kind===`primary`?(()=>{let t=Qr.getState();if(!e)return Ky({captured:Wy(t),surfaceSelection:Pn.selection.value});let n=Zr.getState().getDirectoryForSession(e)??qn??null;return Ky({captured:Wy(t,{expectedConfigKey:br(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:Pn.selection.value})})():Pn.selection.value.providerID&&Pn.selection.value.modelID?{...Pn.selection.value,providerID:Pn.selection.value.providerID,modelID:Pn.selection.value.modelID}:void 0;if(Pn.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=Zr.getState().getDirectoryForSession(e)??qn??null,r=br(n);if(Qr.getState().activeDirectoryKey!==r&&await Qr.getState().activateDirectory(n),Zr.getState().currentSessionId===e){let e=Qr.getState();t=Ky({captured:Wy(e,{expectedConfigKey:br(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:Pn.selection.value})}}return t},c=await s(),l=!1,m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant;if(!m||!g){if(!l){l=!0;try{await Qr.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await s(),m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant}catch{}}if(!m||!g){console.warn(`Cannot send message: provider or model not selected`),Tt.error(f(`chat.chatInput.toast.messageSendFailed`));return}}Bn&&!t&&!w&&await Vt(Bn)&&await Zi(Bn);let T={...a?{delivery:a}:{},commitStagedMessageEdit:!t,...F?{messageID:F.messageID,ticket:F}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:Zr.getState().getDirectoryForSession(e)??qn??null}:Pn.kind===`primary`&&Bn?{sessionId:Bn,directoryHint:Zr.getState().getDirectoryForSession(Bn)??qn??null}:{}},E=``,M=[],N,I=[],z=new Set(Sr(ne,qn).map(e=>e.name)),B=[],V=w?void 0:In.consumeSyntheticParts();for(let e=0;e<D.length;e++){let t=D[e],n=t.composerDocument&&K(t.composerDocument,`direct-send-display`),r=n&&n.ok?{chunks:n.chunks??[],semantics:n.semantics??[]}:null,i=t.owner?.state===`bound`?t.owner.directory:qn,a=new Set(Sr(ne,i).map(e=>e.name)),o=ci({plan:r??Ti(t.content),agents:Fr,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(B.push(...o.semantics),!N&&o.agent&&(N=o.agent),e===0)E=o.text,M=Lr([..._o(t.attachments),...o.attachments]);else{let e=_o(t.attachments);I.push({text:o.text,attachments:Lr([...e,...o.attachments])})}}if(!t&&o.hasContent){let e=_o(Qa),t=ci({plan:v,agents:Fr,installedSkillNames:z,directory:qn,root:ba||qn,confirmedFilePaths:Ci.map(e=>e.path),confirmedDirectoryPaths:Ci.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Qa});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,M=Lr([...e,...t.attachments])):I.push({text:t.text,attachments:Lr([...e,...t.attachments])})}let H=Bn??(Hn?`draft`:null),U=[];if(!t&&H&&!w&&(U=[...In.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Fu(E,U);else if(I.length>0){let e=I[I.length-1];e.text=Fu(e.text,U)}else E=Fu(E,U);if(V&&V.length>0&&I.push(...ji(V)),To&&I.push({text:To.contextText,synthetic:!0}),Oo&&(I.push({text:Oo.instructionsText,synthetic:!0}),I.push({text:Oo.contextText,synthetic:!0})),I.push(...ii(B,Bn&&Zr.getState().getDirectoryForSession(Bn)||qn)),!E&&M.length===0&&I.length===0)return;if(O&&k){if(!await Rr({messageID:k,providerID:m,modelID:g,agent:y,text:E,attachments:M,additionalParts:I,agentMentionName:N}))return;if(!gn.getState().isEstablishing(O)){A();return}}let W=async()=>{if(A(),Mo&&D.length>0&&C.setState(e=>{let t=_(Mo),n=e.queuedMessages[t]??[],r=new Set(D.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...D,...n.filter(e=>!r.has(e.id))]}}}),t)return V&&In.restoreSyntheticParts(V),!0;In.pendingInput?.text===o.message&&In.consumePendingInput(),u&&Si(u);let e=!0;return p.length>0&&(e=await In.restoreAttachments(p)),V&&In.restoreSyntheticParts(V),U.length>0&&In.restoreInlineDrafts(U),e};if(!w&&Bn&&i){let e=Mo?b(C.getState(),Mo).find(e=>e.id===i||e.queueItemID===i):void 0;Mo&&e?.queueItemID&&e.operationID&&$o(Mo,e.queueItemID,e.operationID)}else!w&&Bn&&Ss&&Mo&&Jo(Mo);!t&&!w&&(ui(``),Xe(-1),ni(!1),py({queuedOnly:t,resourcePolicy:w,rootAttachmentCount:p.length})&&In.clearAttachments());let ee=()=>dy({currentSessionId:Bn,messageRef:na,replacePlainDocument:ui}),G=E.trimStart();if(h===`normal`&&G.startsWith(`/`)){let e=jo(G.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Bo(e,e=>Im(Pn,{name:e.name,source:`openchamber`})))return;if(Bn&&(e===`undo`||e===`redo`)&&uy(G,h)&&ee(),e===`undo`&&Bn){try{await Zr.getState().handleSlashUndo(Bn),r?.()}catch(e){Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){uy(G,h)&&ee(),await Fn?.shortcut(`new`);return}if(e===`redo`&&Bn){try{await Zr.getState().handleSlashRedo(Bn),r?.()}catch(e){Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Bn){await fy({command:`fork`,consumeCommandText:ee,forkSession:()=>Zr.getState().forkCurrentSession(Bn),waitForConnection:zr,getDirectoryForSession:()=>Zr.getState().getDirectoryForSession(Bn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Bn&&sa.timeline){ri(!0);return}if(e===`compact`&&Bn){fy({command:`compact`,consumeCommandText:ee,forkSession:async()=>void 0,waitForConnection:zr,getDirectoryForSession:()=>Pn.directory??``,summarizeSession:e=>Jn?Pn.backend.compact({operation:`compact`,surfaceID:Pn.surfaceID,transportIdentity:Pn.transportIdentity,runtimeGeneration:Pn.runtimeGeneration,sessionID:Bn,directory:e,draftKey:Jn,deliveryTarget:Pn.deliveryTarget,providerID:m,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{Tt.error(f(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Bn){try{await zr();let e=G.replace(/^\/\u2003?summary\b/i,``).trim(),t=e?` focused on: ${e}`:``,n=e?`The user asked you to focus this summary on: ${e}. Prioritize that topic; mention unrelated threads only in passing.`:``,i=await ki(`session.summary.visible`,{topic_line:t}),a=await ki(`session.summary.instructions`,{topic_block:n});await Qn(i,m,g,y,[],N,[{text:a,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Bn||Hn)){try{await zr();let e=await ki(`session.review.visible`),t=await ki(`session.review.instructions`);await Qn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Bn&&!Ur&&!d()){lr(!0);return}if(e===`plan-feature`&&(Bn||Hn)){try{await zr();let e=await ki(`session.plan.visible`),t=await ki(`session.plan.instructions`);await Qn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(Bn||Hn)){A(),Sn.getState().setArmed(!0);let e=cy(G,h)??``;ui(e),na.current=e,Xe(-1),e||ni(!1);return}if(e===`craft-goal`&&(Bn||Hn)){try{await zr();let e=G.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await ki(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await ki(`session.craftGoal.instructions`);await Qn(t,m,g,y,[],N,[{text:n,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Bn||Hn)){try{await zr();let e=await ki(`session.catchup.visible`),t=await ki(`session.catchup.instructions`);await Qn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Bn||Hn)){try{await zr();let e=await ki(`session.debug.visible`),t=await ki(`session.debug.instructions`);await Qn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Bn||Hn)){try{await zr();let e=await ki(`session.weigh.visible`),t=await ki(`session.weigh.instructions`);await Qn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Bn||Hn)){try{await zr();let e=await ki(`session.explore.visible`),t=await ki(`session.explore.instructions`);await Qn(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.exploreFailed`))}return}}let q=Bn&&Zr.getState().getDirectoryForSession(Bn)||qn;if(Kn||Bn&&!Gb(Bn,q)){let e=await Yi().catch(()=>null);e&&I.push({text:Ri(e),synthetic:!0})}try{let e=xa.getState().expandText;E=await e(E);for(let t of I)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let te=Qn(E,m,g,y,M,N,I.length>0?I:void 0,x,h,T);P=!0,te.finally(()=>{Bs(),L&&Zr.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&te.then(()=>{j(O)}).catch(()=>{gn.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),te.then(()=>{To&&Eo(null),Oo&&ko(null)}).catch(e=>{F&&Dn(F),W().then(e=>{e||Tt.error(f(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){Tt.error(f(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){p.length>0&&Tt.error(f(`chat.chatInput.toast.sendAttachmentsFailed`));return}Tt.error(t||f(`chat.chatInput.toast.messageSendFailed`))}),Ur||Ai.current?.focus()}finally{R||(F&&Dn(F),L&&Zr.getState().endMessageEditCommit(L.sessionId,L.messageId)),P||(M&&u&&Si(u),Bs(),O&&j(O))}};As.current=$s;let ec=Z.useCallback(()=>{if(Gs()||Vs())return;let e=ks(),t=h===`normal`&&e.hasContent&&Bn&&(Ds||_s),n=t&&Bf(Fo.mode)&&zt(Pn.deliveryTarget?.kind,Fo.mode);Ao===`queue`&&n?qs():Ao===`steer`&&t||Ao===`queue`&&t&&!n?As.current(t?{delivery:`steer`}:void 0):As.current()},[h,ks,Bn,Ds,_s,Ao,qs,Fo.mode,Pn.deliveryTarget?.kind,Ws]),tc=Z.useCallback(e=>{if(Vs())return;let t=(Ai.current?.value??na.current).trim(),n=t?`${e}\n${t}`:e;As.current({presetText:n})},[]),nc=Z.useCallback(e=>{let t=ux(ia().text,e);Di(t),Ai.current&&(Ai.current.value=t),setTimeout(()=>{Ai.current?.focus()},0)},[Di]),rc=Z.useCallback(e=>{if(Vs())return;let t=ux(Ai.current?.value??na.current,e);As.current({presetText:t})},[]),ic=In.pendingPreset,ac=In.consumePendingPreset;Z.useEffect(()=>{if(ic==null)return;let e=ac();e&&tc(e)},[ic,ac,tc]);let oc=Z.useCallback(()=>{ui(``),Xe(-1),Ln.length>0&&In.clearAttachments(),Mo&&Jo(Mo),N(!1),z(!1),te(!1),O(!1),h===`shell`&&g(`normal`)},[Ln.length,In,Jo,Mo,ui,h]),sc=e=>{if(!Pn.active||Mg(e))return;if(ha&&Ga(e,ha)&&!Jr){let t=Ai.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),oc();return}}if(h===`shell`&&e.key===`Escape`){e.preventDefault(),g(`normal`);return}if(h===`shell`&&e.key===`Backspace`&&li.length===0){e.preventDefault(),g(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Ai.current,n=t?.selectionStart??li.length,r=t?.selectionEnd??li.length,i=gi({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Wb(ai.getDocument().text,i.start);e.preventDefault(),Di(t.text),requestAnimationFrame(()=>{Ai.current?.setSelectionRange(t.caret,t.caret),vc()}),yc(t.text,t.caret);return}let a=Oe(li,Ln.filter(Fe).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=Wb(a.text,a.caret);e.preventDefault(),Di(n.text);for(let e of Ln)t.has(e.filename.toLowerCase())&&In.removeAttachment(e.id);requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=n.caret,Ai.current.selectionEnd=n.caret),vc()}),yc(n.text,n.caret);return}let o=Ev(li,oo.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Wb(o.text,o.caret);e.preventDefault(),Di(t.text),requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=t.caret,Ai.current.selectionEnd=t.caret),vc()}),yc(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<li.length){let n=De(li,Ln.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=G(li.slice(n.start+1,n.end-1)).trim(),r=Ln.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=li[n.end]===` `?n.end+1:n.end,a=`${li.slice(0,n.start)}${li.slice(i)}`;e.preventDefault(),Di(a),r&&In.removeAttachment(r.id),requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=n.start,Ai.current.selectionEnd=n.start),vc()}),yc(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(li[r-1]);)--r;let i=t+1;for(;i<li.length&&!/\s/.test(li[i]);)i+=1;let a=li.slice(r,i),o=a.slice(1);if(Lb.test(a)&&!eo.current.has(o.toLowerCase())&&Er({mention:o,confirmed:Oi.has(o),terminated:i<li.length&&/\s/.test(li[i])})){let t=li[i]===` `?i+1:i,n=`${li.slice(0,r)}${li.slice(t)}`;e.preventDefault(),Di(n),requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=r,Ai.current.selectionEnd=r),vc()}),yc(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&$i.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),$i.current.handleKeyDown(e.key);return}if(R&&ea.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ea.current.handleKeyDown(e.key);return}if(q&&ta.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ta.current.handleKeyDown(e.key);return}if(D&&Xi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Xi.current.handleKeyDown(e.key);return}if(Ha&&e.key===`Escape`){e.preventDefault(),ni(!1);return}let n=ma&&!ma.includes(`shift`)?Ka(`shift+${ma}`):``,r=n&&Ga(e,n)?-1:+!!Ga(e,ma);if(r!==0&&!M&&!R&&!q&&!D){e.preventDefault(),e.stopPropagation(),Fn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Ai.current?.focus({preventScroll:!0})});return}let i=M||R||q||D,a=Ai.current?.selectionStart===0&&Ai.current?.selectionEnd===0,o=Ai.current?.selectionStart===li.length&&Ai.current?.selectionEnd===li.length,s=!i&&(li.length===0||a),c=!i&&(li.length===0||o);if(h===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Ai.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),Di(t),requestAnimationFrame(()=>{let e=Ai.current;e&&(e.selectionStart=n,e.selectionEnd=r),vc()}),yc(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=li.slice(n,r);t(`${li.slice(0,n)}${a}${s}${o}${li.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=li.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${li.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(),Ye===-1)Xe(0),yi({text:ms[0],references:[]});else if(Ye<ms.length-1){let e=Ye+1;Xe(e),yi({text:ms[e],references:[]})}requestAnimationFrame(()=>{Ai.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Ye>=0){if(e.preventDefault(),Ye===0)Xe(-1),bi();else{let e=Ye-1;Xe(e),yi({text:ms[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),Gs()||Vs())return;let t=e.ctrlKey||e.metaKey,n=h===`normal`&&xs&&Bn&&(Ds||_s),r=n&&Bf(Fo.mode)&&zt(Pn.deliveryTarget?.kind,Fo.mode);Ao===`queue`?t||!n?$s():r?qs():$s({delivery:`steer`}):t||!n?$s():$s({delivery:`steer`})}},cc=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}},[]),uc=Z.useCallback(()=>{if(!Ha){yo(null);return}if(!M&&!R&&!q&&!D){yo(null);return}let e=Ai.current,t=zi.current;if(!e||!t)return;let n=e.selectionStart??li.length,r=cc(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||q?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));yo({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Ha,cc,li.length,M,D,q,R]);Z.useLayoutEffect(()=>{uc()},[uc,li,M,R,q,D,Ha]),Z.useEffect(()=>{if(!Ha)return;let e=()=>uc();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Ha,uc]);let dc=Z.useCallback(()=>{bo.current&&=(clearTimeout(bo.current),null),Na(!0),bo.current=setTimeout(()=>{Na(!1),bo.current=null},1800)},[]),fc=Z.useCallback(()=>{if(In.abortPrompt.clear(),dc(),Pn.kind===`secondary`){Fn?.shortcut(`abort`);return}tr()},[tr,Fn,dc,Pn.kind,In]),pc=Z.useCallback((e=1)=>{if(Br)return;let t=Yn(Fr,Pn.selection.value.agent??gr,e);if(!t||!Pn.selection.change)return;let n=ft({providerID:Pn.selection.value.providerID??``,modelID:Pn.selection.value.modelID??``,agent:Pn.selection.value.agent??null},t,Fr,Ir);Pn.selection.change({...Pn.selection.value,...n,agent:n.agent??void 0}),Pn.kind===`primary`&&(s.getState().addRecentAgent(t),Pn.sessionID&&vi.getState().saveSessionAgentSelection(Pn.sessionID,t))},[Fr,gr,Ir,Br,Pn.kind,Pn.selection,Pn.sessionID]);Ze.current=pc;let mc=Z.useRef(null),[hc,gc]=Z.useState(null),_c=Z.useCallback(e=>{gc(t=>t===e?t:e)},[]),vc=Z.useCallback(e=>{let t=Ai.current;if(!t)return;let n=t.scrollTop;if(qa){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,fe(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=Ab({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:mc.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),fe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[qa]);Z.useLayoutEffect(()=>{let e=li.length<Li.current;Li.current=li.length,vc({allowShrink:e})},[vc,li,Ur]),Z.useLayoutEffect(()=>{mc.current=hc,vc({allowShrink:hc===null})},[vc,hc]);let yc=Z.useCallback((e,t,n=`manual`,r)=>{let i=Ho({text:e,cursor:t,inputMode:h,mentionInputSource:n,insertedText:r});if(Fi.current=i,!i){N(!1),O(!1),z(!1),te(!1),H(``);return}if(i.kind===`slash-command`){I(i.query),N(!0),O(!1),z(!1),te(!1);return}if(N(!1),i.kind===`slash-skill`){H(i.query),z(!0),O(!1),te(!1);return}if(z(!1),H(``),i.kind===`snippet`){ae(i.query),te(!0),O(!1);return}te(!1),j(i.query),O(!0)},[h,I,j,N,O,z,te,H,ae]),bc=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(h===`normal`&&!Ni.current&&so.size>0&&e.includes(`/`)){let r=us(e,so,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=mi(a,o,s,(e,t)=>{let n=[...e];for(let e of hr(t.text,{agentNames:$a,includeUnterminatedPastedReferences:r===`paste`}))n=ts(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=ia(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Ai.current;e&&Mm(u,Ni.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),vc()}),yc(l.text,c.end,r,i),{document:l,selection:c}},[vc,mi,ia,h,$a,so,yc]),xc=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=Ai.current;if(!n){let n=li+e;bc(n,n.length,n.length,t,e);return}let r=n.selectionStart??li.length,i=n.selectionEnd??li.length,a=`${li.substring(0,r)}${e}${li.substring(i)}`,o=r+e.length;bc(a,o,o,t,e)},[bc,li]),Sc=J((e,t)=>{let n=new Set(Ce(Ln.map(e=>e.filename),e,t));if(n.size!==0)for(let e of Ln)n.has(e.filename)&&In.removeAttachment(e.id)}),Cc=Z.useCallback(e=>{In.removeAttachment(e.id)},[In]),wc=Z.useCallback(()=>{Hi.current=!1,Ki.current=[],Ui.current&&=(clearTimeout(Ui.current),null)},[]),Tc=Z.useCallback(()=>{Ui.current&&clearTimeout(Ui.current),Ui.current=setTimeout(()=>{wc()},700)},[wc]),Ec=Z.useCallback(()=>{Wi.current=!1,Gi.current&&=(clearTimeout(Gi.current),null)},[]),Dc=Z.useCallback(()=>{Wi.current=!0,Gi.current&&clearTimeout(Gi.current),Gi.current=setTimeout(()=>{Wi.current=!1,Gi.current=null},700)},[]),Oc=Z.useCallback(e=>{!d()||!Hi.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),wc())},[wc]),kc=e=>{if(Jr)return;let t=e.nativeEvent;if(d()&&Hi.current){let n=Ki.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){wc();return}}let n=e.target.value;Sc(na.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Hb(na.current,n):``,a=i.includes(`@`)||Wi.current;Wi.current&&Ec();let o=a?`paste`:`manual`;if(h===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);g(`shell`),ui(e),vc(),N(!1),z(!1),O(!1),requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=t,Ai.current.selectionEnd=t)});return}bc(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{wc(),Ec()},[wc,Ec]);let Ac=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=Ai.current,i=r?.selectionStart??li.length,a=r?.selectionEnd??li.length,o=Xo(n,li.slice(0,i),li.slice(a)),s=`${li.slice(0,i)}${o}${li.slice(a)}`;Sc(li,s),aa(s,t)},[li,aa,Sc]),jc=Z.useCallback(async e=>{let t=Xb(e.clipboardData);if(t.length>0&&(Bn||Hn)){e.preventDefault(),Ac(t);return}if(h===`normal`&&(Bn||Hn)){let t=Ai.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=li.slice(n,r);if(zb.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${li.slice(0,n)}[${i}](${t})${li.slice(r)}`,o=n+1+i.length+2+t.length+1;Di(a),requestAnimationFrame(()=>{let e=Ai.current;e&&(e.selectionStart=o,e.selectionEnd=o),vc()}),yc(a,o,Ub(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(h===`normal`&&ab(ia(),a)){e.preventDefault();let t=ia().text,n=Ai.current,r=n?.selectionStart??li.length,i=n?.selectionEnd??li.length,o=ob(a,li,ia().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),ib(ia())),s=hi(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=os(s.document.text,s.caret);Ai.current&&(Ai.current.value=s.document.text),requestAnimationFrame(()=>{Ai.current?.setSelectionRange(c,c),vc()}),yc(s.document.text,c),Sc(t,s.document.text);return}a.includes(`@`)&&Dc();return}if(!Bn&&!Hn){a.includes(`@`)&&Dc();return}e.preventDefault();let o=je(i,[...Ln.map(e=>e.filename),...ra.current]),s=Be(o),c=ia().text,l=Ai.current,u=l?.selectionStart??li.length,d=l?.selectionEnd??li.length,p=h===`normal`&&ab(ia(),a)?ob(a,li,ia().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),ib(ia())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=Xo(m,li.slice(0,u),li.slice(d));if(p){let e=hi(u,d,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=os(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;bc(n,t+s.length,t+s.length,Ub(n),s),Sc(c,n)}else xc(g,Ub(g)),Sc(c,`${li.slice(0,u)}${g}${li.slice(d)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Vb(i[e],t);ra.current.add(t);try{await In.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.clipboardAttachFailed`))}finally{ra.current.delete(t)}}},[In,Ac,Ln,vc,Bn,ia,h,hi,Dc,li,Hn,xc,f,yc,bc,Di,Sc]),Mc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=Tv(r,i,[...De(li,Ln.filter(Fe).map(e=>e.filename)),...wv(li,oo.keys()),...ia().references]),o=a?.start??r,s=a?.end??i,c=li.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${li.slice(0,o)}${li.slice(s)}`;bc(e,o,o),requestAnimationFrame(()=>{Ai.current?.setSelectionRange(o,o),vc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Ai.current?.setSelectionRange(o,s)})},[vc,Ln,oo,bc,ia,li]),Nc=Z.useCallback(e=>{Mc(e,`copy`)},[Mc]),Pc=Z.useCallback(e=>{Mc(e,`cut`)},[Mc]),Fc=e=>{let t=Ai.current,n=t&&document.activeElement===t?t.selectionStart??Pi.current:Pi.current;return ds(e,n)},Ic=()=>{Ls(Ur)||Ai.current?.focus()},Lc=e=>{let t=Fc(li.length),n=Ro(li,t,Fi.current),r=li.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():Jc(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=is(li,o,s,`@${i}`);aa(c.text,[i],a),Pi.current=c.caret,requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=c.caret,Ai.current.selectionEnd=c.caret),vc(),yc(c.text,c.caret)}),O(!1),j(``),Ic()},Rc=e=>{let t=Fc(li.length),n=Ro(li,t,Fi.current),r=li.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=is(li,i,a,`@${e}`);Di(o.text,t=>ts(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Pi.current=o.caret,requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=o.caret,Ai.current.selectionEnd=o.caret),vc(),yc(o.text,o.caret)}),O(!1),j(``),Ic()},zc=J(e=>{Qi.current||(Qi.current=!0,(async()=>{try{let t=Zr.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){Tt.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await vt(e.id,{directory:t}),!sr(e.id,t)){Tt.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Pr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=ia(),r=Fc(n.text.length),i=Ro(n.text,r,Fi.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=Mi().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,l={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:o})},u=hi(s,c,l,{inlineBoundaries:!0,padDocumentEdges:!0}),d=os(u.document.text,u.caret);Pi.current=d,requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=d,Ai.current.selectionEnd=d),vc(),yc(u.document.text,d)}),O(!1),j(``),Ic()}catch{Tt.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Qi.current=!1}})())}),Bc=J(e=>{let t=ia(),n=Fc(t.text.length),r=Ro(t.text,n,Fi.current)??No(t.text,n);if(!r)return!1;let i=hi(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=os(i.document.text,i.caret);return Pi.current=o,requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=o,Ai.current.selectionEnd=o),vc(),yc(i.document.text,o),a&&(N(!1),z(!1))}),Ic(),a}),Vc=e=>{Bc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&H(``)},Hc=(e,t)=>{let n=Fc(li.length),r=Ro(li,n,Fi.current),i=li.substring(0,n).lastIndexOf(`#`),a=r?.start??(i===-1?n:i),o=r?.end??n,s=`${li.substring(0,a)}#${t} ${li.substring(o)}`;Di(s);let c=a+t.length+2;Pi.current=c,requestAnimationFrame(()=>{Ai.current&&(Ai.current.selectionStart=c,Ai.current.selectionEnd=c),vc(),yc(s,c)}),te(!1),ae(``),Ic()},Uc=(e,t=!1)=>{if(!Im(Pn,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Bc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&I(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Bc({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){I(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=us(r,new Set([...so,e.name.toLowerCase()]),r.length);ui(i?.text??r);let a=Ai.current;if(a&&(a._commandMetadata=e),N(!1),I(``),t){$s({presetText:n});return}let o=()=>{if(!Ls(Ur)&&Ai.current){try{Ai.current.focus({preventScroll:!0})}catch{Ai.current.focus()}Ai.current.setSelectionRange(Ai.current.value.length,Ai.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Bn&&Ai.current&&!Ur&&Ai.current.focus()},[Bn,Ur]),Z.useEffect(()=>{Ur||me(null)},[Ur]);let Wc=In.abortPrompt.sessionID,Gc=In.abortPrompt.clear;Z.useEffect(()=>{Wc&&Wc!==Bn&&Gc()},[Bn,Wc,Gc]),Z.useEffect(()=>{qi.current=!!(Bn||Hn)},[Bn,Hn]);let Kc=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 Gv(e).length>0},[]),qc=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)},[]),Jc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(ba||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[ba]),Yc=e=>{if(!Kc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Bi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==T&&E(t),(Bn||Hn)&&!y&&w(!0)},Xc=e=>{Kc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Bn||Hn)&&!y&&w(!0))},Zc=e=>{e.preventDefault(),e.stopPropagation(),Bi.current--,Bi.current<=0&&(Bi.current=0,w(!1),E(!1),wc())},Qc=()=>{Bi.current=0,w(!1),E(!1),wc()},$c=async e=>{if(Bi.current=0,!Kc(e.dataTransfer)){wc();return}if(e.preventDefault(),e.stopPropagation(),w(!1),!Bn&&!Hn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Ai.current,r=na.current;if(n){let t=n.selectionStart??Pi.current,i=n.selectionEnd??t,a=is(r,t,i,e);Di(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Pi.current=a.caret,n.focus()})}else{let t=is(r,r.length,r.length,e);Di(t.text)}wc();return}let n=Xb(e.dataTransfer);if(n.length>0){d()&&(Ki.current=n),Ac(n),d()||wc();return}let r=qc(e.dataTransfer);if(r.length>0){let e=Be(r.map(e=>e.name)),t=Xo(e,na.current.slice(0,Ai.current?.selectionStart??na.current.length),na.current.slice(Ai.current?.selectionEnd??na.current.length));xc(t);for(let e of r)try{await In.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}}wc()},Q=e=>{Kc(e.dataTransfer)&&(e.preventDefault(),d()&&(Hi.current=!0,Tc()))},el=Z.useRef(null),tl=Z.useRef(null),nl=J((e=!0)=>{Ge.current=0;let t=()=>{let t=Am(Ai);if(!t||(jm(Ai),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),rl=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Be(t.map(e=>e.name)),n=Xo(e,na.current.slice(0,Ai.current?.selectionStart??na.current.length),na.current.slice(Ai.current?.selectionEnd??na.current.length));xc(n)}for(let e of t)try{await In.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}},[In,xc,f]),il=Z.useCallback(async()=>{try{let e=await ua?.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
|
+
`);Tt.error(f(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(nl(!1),await rl(r),nl())}catch(e){console.error(`VS Code file pick failed`,e),Tt.error(e instanceof Error?e.message:f(`chat.chatInput.toast.vscodePickFailed`))}},[rl,nl,f,ua]),al=Z.useCallback(()=>{if(d()){il();return}el.current?.click()},[il]),ol=Z.useCallback(()=>{if(d()){il();return}tl.current?.click()},[il]),sl=Z.useCallback(async()=>{if(!fl()){ol();return}try{let e=await pl(20);if(e===null){ol();return}e.length>0&&(nl(!1),await rl(e),nl())}catch(e){console.error(`Native photo pick failed`,e),Tt.error(f(`chat.chatInput.toast.attachFileFailed`))}},[rl,nl,ol,f]),cl=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(nl(!1),await rl(t),e.target.value=``,nl())},[rl,nl]),ll=`gap-x-1.5 gap-y-0`,ul=d(),dl=Pn.kind===`primary`&&Kn&&!ul,ml=Z.useMemo(()=>(Rt?.selectedProjectId?nr.find(e=>e.id===Rt.selectedProjectId)??null:null)||(ar?nr.find(e=>e.id===ar)??null:null)||(nr[0]??null),[ar,Rt?.selectedProjectId,nr]),hl=Z.useMemo(()=>Zb(ml?.path??null),[ml?.path]),gl=ml?Qb(ml):null,_l=rs(hl),vl=qo(e=>hl?e.directories.get(hl)?.lastBranchesFetch??0:0),yl=ls(hl),bl=!!_l?.all,Sl=qo(e=>e.fetchBranches),[Cl,wl]=Z.useState(!1);Z.useEffect(()=>{!dl||!hl||!la||yl!==null||ja(hl,la,{silent:!0})},[ja,la,yl,hl,dl]),Z.useEffect(()=>{if(!dl||!hl||!ml||!la||yl!==!0){wl(!1);return}let e=!vl||Date.now()-vl>3e4;if(bl&&!e){wl(!1);return}let t=!1;return wl(!bl),Sl(hl,la).finally(()=>{t||wl(!1)}),()=>{t=!0}},[Sl,la,ml,vl,bl,yl,hl,dl]);let Tl=Yo(hl),El=_l?.current?.trim()||Tl?.trim()||``,Dl=Z.useMemo(()=>{if(!ml)return null;let e=Zb(ml.path);return!e||!El?null:{value:e,label:El}},[ml,El]),Ol=Z.useMemo(()=>{if(!ml)return[];let e=hl?tn.get(hl)??tn.get(ml.path)??[]:[];return jr({projectRoot:Zb(ml.path)??``,rootBranch:El,worktrees:e,pendingBootstrapDirectory:Rt?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[tn,Rt?.bootstrapPendingDirectory,ml,El,hl]),kl=Z.useMemo(()=>Zb(Rt?.bootstrapPendingDirectory??null)??Zb(Rt?.directoryOverride??null)??hl,[Rt?.bootstrapPendingDirectory,Rt?.directoryOverride,hl]),Al=Z.useMemo(()=>{let e=Zb(Rt?.bootstrapPendingDirectory??null);return!!(Rt?.preserveDirectoryOverride||Rt?.pendingWorktreeRequestId||e&&e===kl)},[Rt?.bootstrapPendingDirectory,Rt?.pendingWorktreeRequestId,Rt?.preserveDirectoryOverride,kl]),jl=Z.useMemo(()=>{let e=[];return Dl&&e.push(Dl),e.push(...Ol),!kl||e.some(e=>e.value===kl)||!Al?e:[...e,{value:kl,label:oa(kl)}]},[Dl,kl,Al,Ol]),Ml=Z.useMemo(()=>tv({selectedDirectory:kl,projectRootOption:Dl,worktreeOptions:Ol}),[Dl,kl,Ol]),Nl=xg()===`mini-chat`,Pl=Z.useMemo(()=>Nl||wa!==!0||!Oa||Oa.isClean?!1:og(Oa.files),[Oa,wa,Nl]),Fl=Z.useMemo(()=>!kl||Dl?.value===kl||Ol.some(e=>e.value===kl),[Dl?.value,kl,Ol]);Z.useEffect(()=>{Rt?.open&&(!Rt.preserveDirectoryOverride&&!Rt.bootstrapPendingDirectory||!kl||!Fl||(Rt.preserveDirectoryOverride&&Zr.getState().setDraftPreserveDirectoryOverride(!1),Rt.bootstrapPendingDirectory&&Zr.getState().setDraftBootstrapPendingDirectory(null)))},[Rt?.bootstrapPendingDirectory,Rt?.open,Rt?.preserveDirectoryOverride,Fl,kl]);let Il=Z.useMemo(()=>yl!==!0||Cl?!1:Dl?!0:Ol.length>0,[Cl,Dl,yl,Ol.length]),Ll=Z.useCallback(e=>{if(Zr.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=nr.find(t=>t.id===e);t&&(ar!==e&&or(e),en({projectId:e,directoryOverride:t.path},{force:!0}))},[ar,nr,or,en]),Rl=Z.useCallback(e=>{Zr.getState().newSessionDraft?.pendingWorktreeRequestId||ml&&en({projectId:ml.id,directoryOverride:e},{force:!0})},[ml,en]),zl=Z.useCallback(e=>{let t=e.icon?Da[e.icon]:null,n=e.color?Aa[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)(Sa,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:Qb(e)})]})},[]);Z.useEffect(()=>{!dl||!ml||!kl||Rt?.pendingWorktreeRequestId||Rt?.bootstrapPendingDirectory||Rt?.preserveDirectoryOverride||jl.some(e=>e.value===kl)||en({projectId:ml.id,directoryOverride:ml.path})},[jl,Rt?.bootstrapPendingDirectory,Rt?.pendingWorktreeRequestId,Rt?.preserveDirectoryOverride,kl,ml,en,dl]);let Bl=Z.useCallback(()=>{Ke(),xe(!0),Ai.current?.blur()},[Ke]),Vl=Z.useCallback(()=>{Ke(),Ee(!0),Ai.current?.blur()},[Ke]);Z.useEffect(()=>{if(!Ur||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=()=>We(Wg(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[Ug]}),()=>r.disconnect()},[Ur]);let Hl=Ue||!!pe||be||Se||xo||Co,Ul=ir(Ir.find(e=>e.id===Pn.selection.value.providerID),Pn.selection.value.modelID,f(`chat.modelControls.selectModel`)),Wl=Pn.selection.value.variant?.trim(),Gl=J(e=>{se(t=>Vo(t,e.rows)),ue(t=>t===e.highlightedIndex?t:e.highlightedIndex)}),Kl=J(e=>Im(Pn,e)),ql=J(e=>{if(M){$i.current?.acceptIndex(e,!0);return}if(R){ea.current?.acceptIndex(e);return}D&&Xi.current?.acceptIndex(e)}),Jl=J(()=>{Fi.current=null,N(!1),z(!1),te(!1),O(!1),se([]),ue(0)}),Yl=xl({enabled:Ur&&Pn.kind===`primary`,isMobile:Ur,text:li,textPresetEpoch:ai.textPresetEpoch,placeholder:Za,modelLabel:Ul,modelVariantLabel:Wl?Zt(Wl):``,canSend:Ts,canAbort:Os,attachmentCount:Ln.length,suppressed:Hl,attachAria:f(`chat.chatInput.actions.addAttachment`),attachTitle:f(`chat.chatInput.actions.addAttachment`),attachPhotosLabel:f(`chat.chatInput.actions.attachPhotos`),attachFilesLabel:f(`chat.chatInput.actions.attachFiles`),attachCancelLabel:f(`chat.chatInput.actions.attachCancel`),sendAria:f(`chat.chatInput.actions.sendMessageAria`),queueAria:f(`chat.chatInput.actions.queueMessageAria`),stopAria:f(`chat.chatInput.actions.stopGeneratingAria`),modelAria:f(`chat.modelControls.selectModel`),modelId:Pn.selection.value.modelID,providerId:Pn.selection.value.providerID,agentName:Pn.selection.value.agent??``,agentLabel:er(Fr,Pn.selection.value.agent??void 0),agentAria:f(`chat.modelControls.selectAgent`),attachments:Ln,removeAttachmentNamedAria:e=>f(`chat.fileAttachment.actions.removeNamed`,{name:e}),onText:(e,t,n)=>{let r=ds(e.length,n?.end??n?.start??e.length);if(Pi.current=r,t){Ai.current&&(Ai.current.value=e),Di(e);return}let i=na.current,a=Te(i,e,Ln.filter(Fe).map(e=>e.filename)),o=a?.text??e;Ai.current&&(Ai.current.value=o),Di(o);let s=ds(o.length,n?.end??n?.start??o.length);if(Pi.current=s,yc(o,s),!a)return;let c=new Set(a.removedFilenames.map(e=>e.toLowerCase()));for(let e of Ln)c.has(e.filename.toLowerCase())&&In.removeAttachment(e.id)},onSend:e=>{Ai.current&&(Ai.current.value=e),zs({text:e,applyDocument:Di,submit:ec})},onAbort:fc,onAttach:Ke,onFiles:(e,t)=>{t.length>0&&Tt.error(f(`chat.chatInput.toast.someFilesSkipped`,{summary:t.join(`
|
|
6536
|
+
`)})),e.length!==0&&rl(e)},onRemoveAttachment:e=>{In.removeAttachment(e)},onOpenModel:()=>vs(`model`),onCycleAgent:()=>pc(),onOpenAgent:Xs,showScrollToBottom:!!(a&&o),scrollAria:f(`chat.scrollToBottom.aria`),onScrollToBottom:o??(()=>{}),autocompleteOpen:oe.length>0&&(M||R||D),autocompleteHighlightedIndex:le,autocompleteRows:oe,caret:Pi.current,onAutocompleteAccept:ql,onAutocompleteDismiss:Jl,chipHighlights:go}),Xl=Z.useRef(null);at(Yl?Xl:null,()=>{let e=Xl.current?.getBoundingClientRect().height??0;Ns(document.documentElement,e)});let Zl=Z.useRef(!1);Zl.current=xo||Co;let Ql=Z.useRef(!1),$l=Z.useRef(0),eu=Z.useRef(0),tu=J(()=>{let e=Zr.getState().stagedMessageEdit;!e||e.sessionId!==Bn||window.setTimeout(()=>{let t=Zr.getState().stagedMessageEdit,n=document.activeElement,r=hy({surfaceKind:Pn.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:Vs(),focusHeld:Date.now()<eu.current,overlayOpen:$l.current>0||Zl.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<Ge.current});r.action===`disarm`&&Zr.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Ur||Re()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{$l.current+=1},t=()=>{if($l.current=Math.max(0,$l.current-1),Ql.current){Ql.current=!1;return}if(!Je.current||Zl.current||$l.current>0)return;if(ga()){Je.current=!1;return}Je.current=!1,eu.current=Date.now()+600,Ai.current?.focus(),document.activeElement===Ai.current&&ve(!0);let e=()=>{let e=Ai.current;!e||document.activeElement!==e||(nu.current??e).scrollIntoView({block:`end`})};he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),he.current=window.setTimeout(()=>{he.current=null,e()},300),ge.current=window.setTimeout(()=>{ge.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[Ur]),Z.useEffect(()=>{if(!Ur)return;if(Hl){(_e||Date.now()-qe.current<800)&&(Je.current=!0);return}if(!Je.current)return;let e=window.setTimeout(()=>{if(Je.current=!1,ga())return;let e=Ai.current;e&&document.activeElement!==e&&e.focus({preventScroll:Re()})},180);return()=>window.clearTimeout(e)},[Ur,Hl,_e]),Z.useEffect(()=>{if(!Ur||Re()||typeof document>`u`||_e||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Ai.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[Ur,_e]),Z.useEffect(()=>{Ie(``)},[Ae]);let nu=Z.useRef(null),ru=Ur?`px-1.5 py-1.5`:ul?`px-1.5 py-1`:`px-2.5 py-1.5`,iu=Ur?`h-8 w-8`:ul?`h-5 w-5`:`h-6 w-6`,au=Ur?`h-4 w-4`:ul?`h-3.5 w-3.5`:`h-4 w-4`,ou=Ur?`h-6 w-6`:`size-full`,cu=Ur?`h-[1.125rem] w-[1.125rem]`:ul?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,lu=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,mm),uu=Y(lu,iu),du=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`,iu),fu=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(()=>()=>{bo.current&&=(clearTimeout(bo.current),null)},[]);let pu=Ur?(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)(nx,{onOpenAgentPanel:Xs,onCycleAgent:()=>{Ke(),pc()},agentName:Pn.selection.value.agent,agents:Fr,disabled:Hr}),(0,$.jsx)(rx,{onOpenModel:()=>vs(`model`),providerID:Pn.selection.value.providerID,modelID:Pn.selection.value.modelID,provider:Ir.find(e=>e.id===Pn.selection.value.providerID),variant:Pn.selection.value.variant})]}):null,mu=(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)(xd,{attachments:Ln,onShowPopup:Kr,onRemoveAttachedFile:Cc}),Pn.kind===`primary`?(0,$.jsx)(Td,{attachedFiles:Ln,onAddVSCodeFile:(e,t,n)=>{Jn&&Wt(Jn,()=>on.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Jn)return Wt(Jn,()=>on.getState()).addVSCodeSelection(e,t)}}):null]}),hu=go?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Ov,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),gu=Ur?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,Os&&`oc-mobile-composer-compact-chrome--aborting`,Ts&&!Os&&`oc-mobile-composer-compact-chrome--sending`,a&&o&&`oc-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(ox,{isVSCode:ul,footerIconButtonClass:uu,iconSizeClass:cu,handlePickLocalFiles:al,handlePickLocalImages:ol,openIssuePicker:Zs,openPrPicker:Qs,onOpenMobileSheet:Bl,onOpenAndroidPickSheet:fl()?Vl:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[a&&o?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(yg,{placement:`compact`,visible:a,onClick:o})}):null,Os||Ts?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(cx,{isMobile:!0,compact:!0,footerIconButtonClass:uu,stopFooterIconButtonClass:du,compactCircleButtonClass:fu,sendIconSizeClass:au,stopIconSizeClass:ou,canSend:Ts,canAbort:Os,hasContent:!1,currentSessionId:Bn,newSessionDraftOpen:Hn,draftSubmitting:Vn,submissionBlocked:l,sendPhase:Is,queueFrozen:ws,queueFallbackAvailable:Os||Ds,onPrimaryAction:ec,onAbort:fc})}):null]})]}):null,_u=Ur?(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)(ox,{isVSCode:ul,footerIconButtonClass:uu,iconSizeClass:cu,handlePickLocalFiles:al,handlePickLocalImages:ol,openIssuePicker:Zs,openPrPicker:Qs,onOpenSettings:e,onOpenMobileSheet:Bl,onOpenAndroidPickSheet:fl()?Vl:void 0}),vr?(0,$.jsx)(sx,{sessionId:Bn,draftOpen:Hn,draftEnabled:Rt.permissionAutoAcceptEnabled===!0,enabled:pr,saving:Bn?Yt:!1,footerIconButtonClass:uu,iconSizeClass:cu,onSetDraftEnabled:qt,onSetSessionEnabled:Qt,onOpenSessionFirst:Kt,onToggleFailed:yr}):null,(0,$.jsx)(ey,{sessionId:Bn,directory:bt??qn,draftOpen:Hn}),(0,$.jsx)(ty,{length:li.length})]}),pu,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(cx,{isMobile:Ur,footerIconButtonClass:uu,stopFooterIconButtonClass:du,sendIconSizeClass:au,stopIconSizeClass:ou,canSend:Ts,canAbort:Os,hasContent:!!xs,currentSessionId:Bn,newSessionDraftOpen:Hn,draftSubmitting:Vn,submissionBlocked:l,sendPhase:Is,queueFrozen:ws,queueFallbackAvailable:Os||Ds,onPrimaryAction:ec,onAbort:fc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,ll),children:[(0,$.jsx)(ox,{isVSCode:ul,footerIconButtonClass:uu,iconSizeClass:cu,handlePickLocalFiles:al,handlePickLocalImages:ol,openIssuePicker:Zs,openPrPicker:Qs,onOpenSettings:e,withTooltip:!0}),vr?(0,$.jsx)(sx,{sessionId:Bn,draftOpen:Hn,draftEnabled:Rt.permissionAutoAcceptEnabled===!0,enabled:pr,saving:Bn?Yt:!1,footerIconButtonClass:uu,iconSizeClass:cu,onSetDraftEnabled:qt,onSetSessionEnabled:Qt,onOpenSessionFirst:Kt,onToggleFailed:yr}):null,(0,$.jsx)(ey,{sessionId:Bn,directory:bt??qn,draftOpen:Hn}),(0,$.jsx)(ty,{length:li.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,ll),children:[(0,$.jsx)(ex,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Ai,selectionAdapter:kr}),(0,$.jsx)(tx,{radius:Ja,isMobile:Ur,footerIconButtonClass:uu,footerPaddingClass:ru,iconSizeClass:cu,sendIconSizeClass:au,onInsert:nc,onInsertAndSend:rc,onContentHeightChange:_c,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(cx,{isMobile:Ur,footerIconButtonClass:uu,stopFooterIconButtonClass:du,sendIconSizeClass:au,stopIconSizeClass:ou,canSend:Ts,canAbort:Os,hasContent:!!xs,currentSessionId:Bn,newSessionDraftOpen:Hn,draftSubmitting:Vn,submissionBlocked:l,sendPhase:Is,queueFrozen:ws,queueFallbackAvailable:Os||Ds,onPrimaryAction:ec,onAbort:fc})]})]}),vu=J(()=>{if(Ur){eu.current=Date.now()+600;let e=()=>{Ai.current?.focus({preventScroll:Re()}),document.activeElement===Ai.current&&ve(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!jm(Ai))return;let e=Am(Ai);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),yu=bt??qn,{goal:bu,enabled:xu}=Jv(Bn??``,yu),Su=(0,$.jsx)(Cp,{onEditMessage:Js,onSendMessage:Ys,onEditCommitted:vu,draftKey:Jn,scope:Mo,draftTarget:Jn?{key:Jn,expectedRevision:()=>In.getDraft(Jn)?.revision??`absent`}:null,clientPendingItems:Us,onRemoveClientPending:e=>{let t=gn.getState().removeEstablishingFollowUp(e);t&&(t.content&&ui(t.content),t.attachments.length>0&&In.restoreAttachments(t.attachments))},trailing:Bn&&xu&&bu?(0,$.jsx)($v,{sessionId:Bn,directory:yu}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:nu,onSubmit:e=>{e.preventDefault(),ec()},onPointerDownCapture:e=>{if(!Ur)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"]`)&&(Ke(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,Ha&&`flex h-full min-h-0 flex-col pt-4`,Wa&&`flex h-full min-h-0 flex-col pt-1`,Ur&&`bottom-safe-area oc-mobile-composer`),"data-native-ios-composer":Yl?`true`:void 0,style:Ur&&Re()&&!Yl&&Yr>0&&!_e?{marginBottom:`${Yr}px`}:void 0,children:[Kn&&!Ha&&!Ur&&!ul&&!Nl?(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:$b(gl?f(`chat.emptyState.draftTitleWithProject`,{project:gl}):f(`chat.emptyState.draftTitle`),gl)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,qa&&`flex flex-1 min-h-0 flex-col`),children:[Yl?null:(0,$.jsx)(Sd,{attachments:Ln,onShowPopup:Kr,onRemoveAttachedFile:Cc}),(0,$.jsx)(Vp,{}),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:f(`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:ps,"aria-label":f(`chat.chatInput.reviewCommentsRemove`),title:f(`chat.chatInput.reviewCommentsRemove`),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:f(`chat.chatInput.devServerLogs`)}),(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:()=>fs(`preview-console`),"aria-label":f(`chat.chatInput.devServerLogsRemove`),title:f(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,ss>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:f(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:va?.colors?.status?.info},children:ss}),(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:()=>fs(`preview-annotation`),"aria-label":f(`chat.chatInput.previewContextRemove`),title:f(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),To&&!ul&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>So(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[To.author?.avatarUrl&&(0,$.jsx)(`img`,{src:To.author.avatarUrl,alt:To.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,To.number,To.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:To.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:To.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:To.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Eo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.removeAria`),title:f(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),Oo&&!ul&&(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:()=>wo(!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:[f(`chat.chatInput.linked.pr.number`,{number:Oo.number}),Oo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`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":f(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{ko(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.removeAria`),title:f(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(ax,{sessionId:Bn,directory:bt??qn}),(0,$.jsxs)(`div`,{className:Ur?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:Ur?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:Ur?`oc-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:Xl,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(ix,{showAbortStatus:Ma,showAssistantStatus:!1,showTodos:!0,leftAccessory:Hn||!Pl?null:(0,$.jsx)(_g,{})}),!Ur&&dl?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[ml?(0,$.jsxs)(Ea,{value:ml.id,open:Ve,onValueChange:Ll,onOpenChange:e=>{He(e),e||ze(``)},children:[(0,$.jsx)(La,{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]`,fm),children:[(0,$.jsx)(ya,{children:zl(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)(Ta,{fitContent:!0,children:[(0,$.jsx)(za,{autoFocus:!0,value:Le,onChange:e=>ze(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),nr.filter(e=>Ia(Qb(e),Le)||Ia(e.path,Le)).map(e=>(0,$.jsx)(Fa,{value:e.id,className:`max-w-[24rem] truncate`,children:zl(e)},e.id)),(0,$.jsx)(Ca,{}),(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(),He(!1),requestAnimationFrame(()=>Ei.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,fm),onClick:()=>Ei.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),ml&&Il?(0,$.jsx)(cv,{directory:kl,projectDirectory:hl,label:Ml,projectRootOption:Dl,worktreeOptions:Ol,onSelectDirectory:Rl}):null]}):null,Ur&&dl?(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`,fm),onClick:()=>Me(`project`),children:zl(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`,fm),onClick:()=>Ei.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),ml&&Il?(0,$.jsx)(cv,{directory:kl,projectDirectory:hl,label:Ml,projectRootOption:Dl,worktreeOptions:Ol,onSelectDirectory:Rl,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,Su]})}),(0,$.jsx)(`div`,{className:Y(!Ur&&`contents`,Ur&&`contents`,Wa&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:Ur?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(B_,{value:li,attachments:[],disabled:!Bn&&!Hn||Vn&&!Is.establishing,pending:Os||Is.inFlight&&!Is.establishing,isMobile:Ur,onSubmit:ec,"data-mobile-composer-surface":Ur?`true`:void 0,"data-session-swipe-surface":Ur?`true`:void 0,expanded:qa,focusedTone:h===`shell`?`info`:`primary`,className:Y(`relative z-10`,y&&`ring-2 ring-primary ring-offset-2`,Jr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,Ur&&`oc-mobile-composer-surface`),style:{borderRadius:Ja},ref:zi,onDropCapture:Q,onDragEnter:Yc,onDragOver:Xc,onDragLeave:Zc,onDrop:$c,onDragEnd:Qc,autoResize:!1,disableInputWhilePending:!1,contentClassName:qa?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:mu,highlightedContent:hu,highlightRef:Pa,inputRef:Ai,textLayoutClassName:Y(jb,qa?Y(`h-full min-h-0`,Ur?`py-2.5`:`py-4`):Ur?`py-2.5`:`pt-4 pb-2`,h===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(qa&&`flex-1 min-h-0`),inputStyle:{flex:qa?`1 1 auto`:`none`,height:!qa&&de?`${de.height}px`:void 0,maxHeight:!qa&&de?`${de.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":qa?`100%`:de?`${de.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!qa&&de?`${de.maxHeight}px`:`none`,borderTopLeftRadius:Ja,borderTopRightRadius:Ja},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,ru,Ur?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,ll)),footerStyle:{borderBottomLeftRadius:Ja,borderBottomRightRadius:Ja},footerContent:_u,placeholder:Ya,onChange:(e,t)=>kc(t),textareaProps:{readOnly:Jr,onCompositionStart:()=>{Ni.current=!0},onCompositionEnd:e=>{Ni.current=!1;let t=e.currentTarget;bc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Oc,onKeyDown:sc,onCopy:Nc,onCut:Pc,onPaste:jc,onDragEnter:Yc,onDragOver:Xc,onDropCapture:Q,onDrop:$c,onDragEnd:Qc,onKeyUp:uc,onClick:()=>{uc()},onScroll:e=>{uc();let t=e.currentTarget.scrollTop;Pa.current&&(Pa.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Ni.current){Pi.current=r;return}let i=Tv(n,r,[...De(li,Ln.filter(Fe).map(e=>e.filename)),...wv(li,oo.keys()),...si.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Pi.current=i.end):Pi.current=n,uc()},onFocus:()=>{if(Ur){if(Date.now()<Ge.current){let e=Ai.current;e&&e.blur();return}ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null),ve(!0)}},onBlur:e=>{if(Ni.current=!1,Pi.current=e.currentTarget.selectionStart??Pi.current,tu(),Ur){if(Date.now()<eu.current){let e=Ai.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<eu.current&&document.activeElement!==e&&e.focus()},50);return}}if(qe.current=Date.now(),Re()){ve(!1);return}ye.current!==null&&window.clearTimeout(ye.current),ye.current=window.setTimeout(()=>{ye.current=null,ve(!1)},120)}},autoCorrect:Ur?`on`:`off`,autoCapitalize:Ur?`sentences`:`off`,spellCheck:Ur||ei,fillContainer:qa,rows:1},children:[(0,$.jsx)(dh,{}),y&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ja},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:lu,onClick:()=>al(),title:f(`chat.chatInput.actions.attachFiles`),"aria-label":f(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(cu,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:f(T?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(Po,{ref:$i,searchQuery:P,directory:qn,onCommandSelect:Uc,onClose:()=>N(!1),commandPolicy:Kl,commandContext:Zn,onRowsChange:Yl?Gl:void 0,style:Ha&&vo?{left:`${vo.left}px`,top:`${vo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${vo.left+8}px))`,maxHeight:`${vo.maxHeight}px`,transform:vo.place===`above`?`translateY(-100%)`:void 0}:void 0}),R&&(0,$.jsx)(Kp,{ref:ea,searchQuery:V,directory:qn,onSkillSelect:Vc,onClose:()=>z(!1),onRowsChange:Yl?Gl:void 0,style:Ha&&vo?{left:`${vo.left}px`,top:`${vo.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${vo.left+8}px))`,maxHeight:`${vo.maxHeight}px`,transform:vo.place===`above`?`translateY(-100%)`:void 0}:void 0}),q&&(0,$.jsx)(Wo,{ref:ta,searchQuery:ie,onSnippetSelect:Hc,onClose:()=>te(!1),style:Ha&&vo?{left:`${vo.left}px`,top:`${vo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${vo.left+8}px))`,maxHeight:`${vo.maxHeight}px`,transform:vo.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(Qo,{ref:Xi,searchQuery:k,onFileSelect:Lc,onAgentSelect:Rc,onSessionSelect:zc,onClose:()=>O(!1),onRowsChange:Yl?Gl:void 0,style:Ha&&vo?{left:`${vo.left}px`,top:`${vo.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${vo.left+8}px))`,maxHeight:`${vo.maxHeight}px`,transform:vo.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Ur?(0,$.jsx)(tx,{radius:Ja,isMobile:Ur,footerIconButtonClass:uu,footerPaddingClass:ru,iconSizeClass:cu,sendIconSizeClass:au,onInsert:nc,onInsertAndSend:rc,onContentHeightChange:_c,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),Ur?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[gu,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!li.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:li.trim()?li:Za})]}):null]}),Ur?(0,$.jsx)(ex,{className:`hidden`,composerTextareaRef:Ai,selectionAdapter:kr,mobilePanel:pe,onMobilePanelChange:me}):null]}),Hn&&!Ha&&!Ur&&!ul&&!Nl?(0,$.jsx)(N_,{onSubmit:tc,className:`chat-input-column mt-4`}):null]}),p.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Mb,{popup:p,onOpenChange:qr,isMobile:Ur})}):null,(0,$.jsx)(u_,{open:xo,onOpenChange:So,mode:`select`,onSelect:e=>{Eo(e),ko(null)}}),(0,$.jsx)(p_,{open:Co,onOpenChange:wo,onSelect:e=>{ko(e),Eo(null)}}),(0,$.jsx)(Ju,{open:cr,onOpenChange:lr,projectDirectory:bt??qn??null,submitting:dr,onConfirm:Va}),(0,$.jsx)(`input`,{ref:el,type:`file`,multiple:!0,className:`hidden`,onChange:cl,accept:`*/*`}),(0,$.jsx)(`input`,{ref:tl,type:`file`,multiple:!0,className:`hidden`,onChange:cl,accept:`image/*`}),null,Ur?(0,$.jsx)(_a,{id:`android-media-pick-sheet`,open:Se,onOpenChange:e=>{e||Ee(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:f(`chat.chatInput.actions.addAttachment`)}),ariaLabel:f(`chat.chatInput.actions.addAttachment`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(ca,{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:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(sl)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(ca,{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:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(al)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,Ur&&dl&&ml?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(_a,{id:`mobile-draft-project-picker-sheet-${Ne}`,open:Ae===`project`,onOpenChange:e=>{e||Me(null)},ariaLabel:f(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(za,{value:Pe,onChange:e=>Ie(e.target.value),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(da,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:nr.filter(e=>Ia(Qb(e),Pe)||Ia(e.path,Pe)).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:()=>{Ll(e.id),Me(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:zl(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:()=>{Me(null),Ei.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},mx=e=>{let t=(0,Q.c)(3),n=Rm(),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)(px,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};mx.displayName=`ChatInput`;var hx=Z.memo(mx);function gx(e){return e.preventDefault()}function _x(e){e.preventDefault()}function vx(e){return e.preventDefault()}function yx(e){e.pointerType===`touch`&&e.preventDefault()}function bx(e){e.preventDefault()}function xx(e){e.pointerType===`touch`&&e.preventDefault()}function Sx(){let e=(0,Q.c)(47),{t}=ot(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>mo(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=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],ws(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await Vc(n),Tt.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}Tt.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=Re()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(ca,{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 Cx=(e,t)=>{if(t.length===0)return e;let n=new Map(t.map(e=>[e.info.id,e])),r=!1,i=e.map(e=>{if(kt(e.parts))return e;let t=n.get(e.info.id);return t?(r=!0,t):e}),a=r?i:e,o=new Set(e.map(e=>e.info.id)),s=t.filter(e=>!o.has(e.info.id));return s.length===0?a:[...a,...s]},wx=(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},Tx=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}},Ex=e=>e.syncLoading||e.assistantLoading,Dx=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Ox=e=>e.isLoadingOlder,kx=e=>!e.isMobile&&e.isLoadingOlder,Ax=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,jx=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`,Mx=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}},Nx=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Px=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Fx=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Ix=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)(ka,{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},Lx=e=>{let t=(0,Q.c)(42),{t:n}=ot(),r=s(Rx),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Fx,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 ${Px}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,c;t[11]!==e.agentName||t[12]!==o?(c=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=c):c=t[13];let l=c,u=e.modelName||o,d;t[14]===n?d=t[15]:(d=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=d);let f=`${d}: ${l}`,p;t[16]===n?p=t[17]:(p=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=p);let m=`${p}: ${u}`,h=r&&Fx,g;t[18]===h?g=t[19]:(g=Y(`shrink-0 border-t border-border/70 bg-[var(--surface-background)] p-3`,h),t[18]=h,t[19]=g);let _=r&&`oc-mobile-readonly-prompt-surface`,v;t[20]===_?v=t[21]:(v=Y(`rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-3 py-2.5 sm:px-4 sm:py-3`,_),t[20]=_,t[21]=v);let y;t[22]===n?y=t[23]:(y=n(`chat.container.readOnlySubagentPromptBanner`),t[22]=n,t[23]=y);let b;t[24]===y?b=t[25]:(b=(0,$.jsx)(`div`,{className:`text-muted-foreground ${Px}`,children:y}),t[24]=y,t[25]=b);let x;t[26]!==f||t[27]!==l||t[28]!==m||t[29]!==u||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(x=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(sa,{name:e.agentName,size:14,label:f}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:l,children:l})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Ix,{providerId:e.providerId,modelId:e.modelId,label:m}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-right text-foreground`,title:u,children:u})]})]}):null,t[26]=f,t[27]=l,t[28]=m,t[29]=u,t[30]=e.agentName,t[31]=e.modelId,t[32]=e.providerId,t[33]=i,t[34]=x):x=t[34];let S;t[35]!==x||t[36]!==v||t[37]!==b?(S=(0,$.jsxs)(`div`,{className:v,children:[b,x]}),t[35]=x,t[36]=v,t[37]=b,t[38]=S):S=t[38];let C;return t[39]!==S||t[40]!==g?(C=(0,$.jsx)(`aside`,{className:g,children:S}),t[39]=S,t[40]=g,t[41]=C):C=t[41],C};function Rx(e){return e.isMobile}var zx=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ot(),{currentTheme:n}=Ua(),r=At(Bx),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Ja,{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 Bx(e){return e.error}var Vx=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)}}},Hx=`oc:legend-timeline`,Ux=()=>{try{return typeof localStorage>`u`||localStorage.getItem(Hx)!==`0`}catch{return!0}},Wx=ue(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t}),legendTimelineEnabled:Ux(),setLegendTimelineEnabled:t=>{try{typeof localStorage<`u`&&localStorage.setItem(Hx,t?`1`:`0`)}catch{}e({legendTimelineEnabled:t})}})),Gx=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:Zt(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)(ka,{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(${ea(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`,ea(o).class),children:[(0,$.jsx)(sa,{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}](${vc(t.name)})`;i=i.replace(t.token,e)}i=i.replace(qx,(e,t,r)=>n.has(r)?`${t}[/${r}](${hc(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||``,[c,l]=Z.useState(!1),[u,d]=Z.useState(!1),f=s(e=>e.userMessageRenderingMode),p=s(e=>e.collapsibleUserMessages),m=lc(),h=Tr({directory:m,enabled:$x(o)}),g=Z.useMemo(()=>h.data??[],[h.data]),_=s(e=>e.openContextFile),{t:v}=ot(),y=eS(f),b=p&&!c,x=Z.useRef(null),S=Z.useMemo(()=>new Map(g.map(e=>[e.name,e])),[g]),C=Z.useMemo(()=>If(r,o),[r,o]),w=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!tr(t))continue;let n=t.text;if(typeof n==`string`)for(let t of lr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of Mi()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${ee}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),T=J(e=>{let t=S.get(e),n=typeof t?.path==`string`?t.path:``,r=yo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=m||go(``,i)||`/`,o=()=>{_(a,i)};if(m&&!So(i,m)){uc(i,m).then(o);return}o()});Z.useEffect(()=>{let e=x.current;if(!e)return;let t=()=>{p&&!c&&d(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[p,o,c]),Z.useEffect(()=>{p||(l(!1),d(!1))},[p]);let E=J(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??fc(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),T(n);return}let r=x.current;r&&(tS(r)||p&&!c&&u&&l(!0))}),D=J(e=>{e.stopPropagation(),l(!1)}),O=Z.useMemo(()=>Af(o,{skillNames:new Set(S.keys()),citationIcons:C.icons,citationDisplayNames:C.displayNames,sessionMentions:w,agentNames:n?.name?new Set([n.name.toLowerCase(),n.token.replace(/^@/,``).toLowerCase()]):void 0,allowPathHeuristics:!0}),[n,C,w,S,o]),k=Z.useMemo(()=>Qx({textContent:o,agentMention:n,skillNames:new Set(S.keys()),decorateInlineReferences:!O}),[n,O,S,o]),A=(e,t)=>{if(!e)return null;if(y===`markdown`){let n=Qx({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(ks,{content:n,className:Y(`inline w-auto align-baseline [&_.markdown-content]:contents [&_.markdown-content_p]:inline [&_[data-markdown-size-spacer]]:inline`,`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,b&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1},t)}return(0,$.jsx)(Z.Fragment,{children:e},t)},j=e=>e.map((e,t)=>e.type===`text`?A(e.text,`text-${t}`):(0,$.jsx)(Rf,{decoration:e.decoration,onOpenSkill:T},`ref-${t}-${e.span.start}`)),M=Z.useMemo(()=>{if(O)return j(O);let e=[],t=0,r=!1,i;for(qx.lastIndex=0;(i=qx.exec(o))!==null;){let n=i[1]||``,r=i[2],a=i.index+n.length;S.has(r)&&(i.index>t&&e.push(o.slice(t,i.index)),n&&e.push(n),e.push((0,$.jsxs)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:e=>{e.stopPropagation(),T(r)},children:[`/`,r]},`skill-${a}-${r}`)),t=a+r.length+1)}t<o.length&&e.push(o.slice(t));let a=e.length>0?e:[o];return!n?.token||!o.includes(n.token)?a:a.flatMap((e,t)=>{if(r||typeof e!=`string`)return e;let i=e.indexOf(n.token);return i===-1?e:(r=!0,[e.slice(0,i),(0,$.jsx)(`a`,{href:dc(n.name),className:`text-primary hover:underline`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:n.token},`agent-${t}`),e.slice(i+n.token.length)])})},[n,T,O,j,S,o]);return!o||o.trim().length===0?null:(0,$.jsxs)(`div`,{className:`relative`,children:[p&&c&&(0,$.jsx)(`button`,{type:`button`,onClick:D,className:`absolute top-0 right-0 z-10 flex items-center justify-center rounded-sm bg-[var(--surface-elevated)] p-0.5 text-[var(--surface-mutedForeground)] hover:text-[var(--surface-foreground)] hover:bg-[var(--interactive-hover)] transition-colors`,"aria-label":v(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,c&&`pb-3`,y===`plain`&&`whitespace-pre-wrap`,b&&`line-clamp-10`,p&&u&&!c&&`cursor-pointer`),ref:x,onClick:E,children:y===`markdown`?O?j(O):(0,$.jsx)(ks,{content:k,className:Y(`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,b&&[`[&_.markdown-content>*]:my-0`,`[&_[data-component='markdown-code']]:my-0`,`[&_[data-component='markdown-code']]:inline`,`[&_[data-component='markdown-code']]:border-0`,`[&_[data-component='markdown-code']]:bg-transparent`,`[&_[data-component='markdown-code']>*:first-child]:hidden`,`[&_[data-component='markdown-code']>div]:inline`,`[&_[data-component='markdown-code']>div]:p-0`,`[&_[data-component='markdown-code']_pre]:inline`,`[&_[data-component='markdown-code']_code]:inline`,`[&_[data-md-code-line-numbers]]:hidden`]),disableLinkSafety:!0,enableFileReferences:!1}):M})]},e.id||`${t}-user-text`)}),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)(Zc.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)(Zc.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)(Zc.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)(Zc.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===`plan_enter`?(0,$.jsx)(X,{name:`file-list-2`,className:t}):r===`plan_exit`?(0,$.jsx)(X,{name:`task`,className:t}):r.startsWith(`git`)?(0,$.jsx)(X,{name:`git-branch`,className:t}):(0,$.jsx)(X,{name:`tools`,className:t})},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,`
|
|
6538
6538
|
`).replace(/\r/g,`
|
|
6539
|
-
`).trim(),
|
|
6539
|
+
`).trim(),fC=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
|
+
`)},pC=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
|
+
`)},mC=(e,t)=>t===1?e:`${e},${t}`,hC=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]=`@@ -${mC(r[1]??`0`,i)} +${mC(r[2]??`0`,a)} @@${r[3]??``}`}return n.join(`
|
|
6545
|
+
`)},gC=e=>hC(pC(fC(dC(e)))),_C=e=>{if(typeof e==`string`)return/\S/.test(e)?e:void 0;if(uC(e)){let t=e.patch;if(typeof t==`string`)return/\S/.test(t)?t:void 0}},vC=e=>{let t=(e??``).trim().replace(/\t.*$/,``);return!t||t===`/dev/null`?``:t.replace(/^[ab]\//,``)},yC=e=>{let t=e.trim().replace(/\s+/g,`-`);return t.length>0?t:`file`},bC=e=>{let t=!1;for(let n of e.split(`
|
|
6546
|
+
`)){if(n.startsWith(`@@`)){if(!aC.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},xC=e=>{let t=gC(e);if(!t||iC.test(t)||!aC.test(t)||!bC(t))return null;try{let e=Xc(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:vC(r.name)}}catch{return null}},SC=e=>{let t=sC.test(e),n=lC.test(e);return!t&&!n?[]:e.split(t?oC:cC).map(e=>e.trim()).filter(e=>e.length>0)},CC=(e,t,n,r)=>{let i=gC(e);if(!i)return[];let a=xC(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 SC(i)){let i=xC(e),a=i?.title?r(i.title):r(t);if(!i){(aC.test(e)||sC.test(e)||lC.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(!iC.test(i)&&aC.test(i)){let e=yC(t),a=xC(`--- ${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`}]},wC=e=>{if(!uC(e))return null;let t=_C(e.patch)??_C(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},TC=(e,t,n)=>{let r=(Array.isArray(e?.files)?e.files:[]).flatMap((e,t)=>{let r=wC(e);return r?CC(r.patch,r.title||`File ${t+1}`,`file-${t}`,n):[]});return r.length>0?r:CC(typeof t==`string`?t:``,`Diff`,`fallback`,n)},EC=e=>e.trim().replace(/\\/g,`/`).replace(/\/{2,}/g,`/`).replace(/\/+$/,``),DC=(e,t,n,r,i)=>{let a=TC(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)=>wC(t)?e+1:e,0);if(e>0&&e!==o.length)return[]}return new Set(a.map(e=>EC(e.title))).size===a.length?a:[]}let s=EC(r),c=a.find(e=>EC(e.title)===s)??a[0];return c?[c]:[]},OC=Z.createContext(!1),kC=()=>Z.useContext(OC),AC=`relative ml-2 pl-3`,jC=(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`,MC=e=>e?`p-0`:`p-2`,NC=`1.25rem`,PC=28,FC=3,IC=4,LC=10,RC=1,zC=4,BC=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},VC),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/PC})`,_;t[5]===g?_=t[6]:(_={width:PC,height:PC,transform:g,transformOrigin:`top left`},t[5]=g,t[6]=_);let v;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(v=u.map(HC),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 VC(e,t){let n=t%FC,r=Math.floor(t/FC),i=n-RC,a=r-RC,o=i===0&&a===0;return{x:n,y:r,isCenter:o,delay:Math.hypot(i,a)*700-(o?180:0)}}function HC(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:IC+t*LC,top:IC+n*LC,width:zC,height:zC,transform:`translate(-50%, -50%)`,animationDelay:`${i}ms`}},`${t}-${n}`)}var UC=new Set([`read`,`skill`]),WC=new Set([`task`]),GC=new Set([`read`,`glob`,`grep`,`list`]),KC=new Set([`completed`,`error`,`failed`,`aborted`,`timeout`,`cancelled`]),qC=new Set([`pending`,`started`,`running`]),JC=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},YC=e=>!ZC(e),XC=e=>WC.has(JC(e)),ZC=e=>UC.has(JC(e)),QC=e=>GC.has(JC(e)),$C=e=>JC(e)===`skill`,ew=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(qC.has(e))return!1;if(KC.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},tw=e=>!ew(e),nw=JC,rw=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,iw=Y(`typography-meta font-medium`,rw),aw=Y(`typography-meta`,rw),ow=`typography-micro !text-[length:calc(var(--text-meta)-0.0625rem)] !leading-5 tracking-normal`,sw=`flex w-full min-w-0 flex-col gap-1`,cw=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}},lw=(...e)=>{for(let t of e){let e=cw(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}}},uw=e=>e.length>0?e.charAt(0).toUpperCase()+e.slice(1):e,dw=new cc({maxEntries:2e3,maxBytes:262144}),fw=(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`,aw),style:{color:`var(--tools-description)`},children:[n?(0,$.jsx)(gd,{filePath:e.path,className:`h-3.5 w-3.5`}):null,(0,$.jsx)(iS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 max-w-full truncate`,aw),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)})})},pw=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},mw=3e5,hw=new Set([`bash`,`edit`,`write`,`apply_patch`,`patch`,`task`]),gw=new Set([`edit`,`multiedit`,`apply_patch`,`write`,`create`,`file_write`]),_w=e=>gw.has(e),vw=(e,t,n=Date.now())=>{let r=Math.min(Math.max(0,(t??n)-e),mw)/1e3;return`${(r<.05&&t!==void 0?.1:r).toFixed(1)}s`},yw=e=>{let t=(0,Q.c)(6),{start:n,end:r,active:i}=e,a=lS(i,250),o;t[0]!==r||t[1]!==a||t[2]!==n?(o=vw(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},bw=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},xw=e=>{let t=bw(e?.additions),n=bw(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=_C(e?.patch)??_C(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}},Sw=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},Cw=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},ww=(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 Aw(a,n);let s=a?.description||i?.description||`title`in t&&t.title||``;return typeof s==`string`?s:``},Mw=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&&TC(!0),t[7]=c,t[8]=e),f=Y(`tool-output-surface rounded-xl w-full min-w-0`,TC(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)(Oa,{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},Nw=(e,t,n,r)=>t.tool===`bash`?`bash`:Oc(Ic(e,t.tool,n),t.tool,r),Pw=(e,t,n)=>t.tool===`bash`?e:Ic(e,t.tool,n),Fw=e=>{let t=(0,Q.c)(80),{output:n,part:r,metadata:i,input:a,isMobile:o}=e,s=o!==void 0&&o,{t:c}=ot(),l;t[0]!==i||t[1]!==n||t[2]!==r?(l=Pw(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=Nw(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=Mc(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 ct(u)).ok){Tt.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)(ca,{variant:`ghost`,size:`icon`,className:n,onClick:r,onPointerDown:sT,"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)(ca,{variant:`ghost`,size:`icon`,className:d,onClick:f,onPointerDown:cT,"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)(ca,{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:lT,"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)(Rc,{data:m.data,initiallyExpandedDepth:1,maxHeight:`400px`}):(0,$.jsx)(`div`,{className:`typography-code pr-12 text-muted-foreground/90`,children:(0,$.jsx)(jc,{language:`json`,code:u,style:Kw,codeStyle:qw.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={...Kw,...s&&r.tool===`bash`?{lineHeight:EC}:{}},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)(jc,{language:f,code:u,style:E,codeStyle:qw.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};Fw.displayName=`ToolScrollableTextOutput`;var Iw=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``},Lw=new Set([`read`,`view`,`file_read`,`cat`,`write`,`create`,`file_write`,`edit`,`multiedit`,`apply_patch`]),Rw=(e,t)=>{if(!Lw.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)},zw=e=>{let t=ow(e.tool),n=e.state?.status??``,r=Iw(e);return`${e.id??``}\u0001${t}\u0001${n}\u0001${r}`},Bw=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(zw(e[n])!==zw(t[n]))return!1;return!0},Vw=Z.memo(e=>{let t=(0,Q.c)(10),{entry:n,isMobile:r,animateTailText:i,showToolFileIcons:a}=e,{t:o}=ot(),s;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==o){let e=ow(n.tool),c=e.length>0?e:`tool`,l=Iw(n),u=l.trim().length>0,d=n.state?.status,f=ic(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($C,`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:Qx(c)}),(0,$.jsx)(`span`,{className:h,style:g,title:f,children:f}),u?d!==`error`&&Rw(c,l)?$w(l,i,!0,a,$C):d===`error`?(0,$.jsx)(`span`,{className:Y($C,`flex-1 min-w-0 text-[var(--status-error)]`,r?`whitespace-normal break-words`:`truncate`),children:l}):(0,$.jsx)(Zx,{variant:i?`generate-effect`:`static`,className:Y($C,`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&&zw(e.entry)===zw(t.entry));Vw.displayName=`TaskSummaryEntryRow`;var Hw=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($C,`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??`${zw(e)}:${n}`;return(0,$.jsx)(Vw,{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:ew,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)(Mw,{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&&Bw(e.entries,t.entries));Hw.displayName=`TaskSummaryEntriesList`;var Uw=e=>{let t=(0,Q.c)(44),{entries:n,isExpanded:r,isMobile:i,output:a,sessionId:o,onShowPopup:c,input:l,animateTailText:u,isActive:d}=e,f=u===void 0||u,p=d!==void 0&&d,{t:m}=ot(),h=lc(),g=Zr(uT),_=s(dT),v=s(fT),y=Z.useContext(Oo),b=Ph(),x=b.directory||h,S;t[0]===a?S=t[1]:(S=typeof a==`string`?kS(a):``,t[0]=a,t[1]=S);let C=S,w=C.length>0,[T,E]=Z.useState(!1),D,O,k,A;if(t[2]!==f||t[3]!==x||t[4]!==n||t[5]!==w||t[6]!==l||t[7]!==p||t[8]!==r||t[9]!==i||t[10]!==_||t[11]!==y?.runtime||t[12]!==o||t[13]!==b||t[14]!==g||t[15]!==v||t[16]!==m){A=Symbol.for(`react.early_return_sentinel`);bb0:{let e=rw(nw(l)??`subagent`),a=t=>{t.stopPropagation(),o&&x&&Ih(b,o,x,()=>{if(!ai({sessionId:o,directory:x})){if(ll()||i||y?.runtime.isVSCode){g(o,x);return}_(x,{mode:`chat`,dedupeKey:`session:${o}`,label:e,readOnly:!0})}})};if(n.length===0&&!w&&!o){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y($C,`text-muted-foreground/70`),t[21]=e):e=t[21];let n=p?`Waiting for subagent activity...`:`No subagent session id on task metadata.`,r;t[22]===n?r=t[23]:(r=(0,$.jsx)(`div`,{className:`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,children:(0,$.jsx)(`div`,{className:e,children:n})}),t[22]=n,t[23]=r),A=r;break bb0}t[24]===Symbol.for(`react.memo_cache_sentinel`)?(D=Y(`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,`before:absolute before:left-[0.4375rem] before:w-px before:bg-border/80 before:content-[""]`,`before:top-0 before:bottom-0`),t[24]=D):D=t[24],t[25]!==f||t[26]!==n||t[27]!==r||t[28]!==i||t[29]!==v?(O=n.length>0?(0,$.jsx)(Hw,{entries:n,isExpanded:r,isMobile:i,animateTailText:f,showToolFileIcons:v}):null,t[25]=f,t[26]=n,t[27]=r,t[28]=i,t[29]=v,t[30]=O):O=t[30],k=o&&b.capabilities.navigateNestedSession&&(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-primary hover:text-primary/80 w-full`,$C),onPointerDown:pT,onClick:a,children:[(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y($C,`text-primary font-medium`),children:m(`chat.toolPart.openSubtask`,{type:e})})]})}t[2]=f,t[3]=x,t[4]=n,t[5]=w,t[6]=l,t[7]=p,t[8]=r,t[9]=i,t[10]=_,t[11]=y?.runtime,t[12]=o,t[13]=b,t[14]=g,t[15]=v,t[16]=m,t[17]=D,t[18]=O,t[19]=k,t[20]=A}else D=t[17],O=t[18],k=t[19],A=t[20];if(A!==Symbol.for(`react.early_return_sentinel`))return A;let j;t[31]!==n.length||t[32]!==w||t[33]!==T||t[34]!==c||t[35]!==o||t[36]!==m||t[37]!==C?(j=w?(0,$.jsxs)(`div`,{className:Y(`flex flex-col gap-1`,(n.length>0||o)&&`pt-1`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-foreground/80 hover:text-foreground w-full`,$C),onPointerDown:mT,onClick:e=>{e.stopPropagation(),E(hT)},children:[T?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y($C,`text-foreground/80 font-medium`),children:m(`chat.toolPart.output`)})]}),T?(0,$.jsx)(Mw,{maxHeightClass:`max-h-[50vh]`,children:(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(ks,{content:C,variant:`tool`,onShowPopup:c})})}):null]}):null,t[31]=n.length,t[32]=w,t[33]=T,t[34]=c,t[35]=o,t[36]=m,t[37]=C,t[38]=j):j=t[38];let M;return t[39]!==D||t[40]!==O||t[41]!==k||t[42]!==j?(M=(0,$.jsxs)(`div`,{className:D,children:[O,k,j]}),t[39]=D,t[40]=O,t[41]=k,t[42]=j,t[43]=M):M=t[43],M},Ww=`
|
|
6551
|
+
`)},Tw=(e,t,n)=>{if(!t||e!==`edit`&&e!==`multiedit`&&e!==`apply_patch`)return;let r=Ew(e,t,n);if(r){let e=Cw(r);if(Number.isFinite(e))return e}},Ew=(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=_C(t.patch)??_C(t.diff);if(e)return e}}let i=t.filediff;if(i&&typeof i==`object`){let e=_C(i.patch)??_C(i.diff);if(e)return e}let a=_C(t.patch)??_C(t.diff);if(a)return a},Dw=e=>{let t=e.trim().replace(/\\/g,`/`).replace(/\/{2,}/g,`/`);return!t||t===`/`?t:t.replace(/\/+$/,``)},Ow=(e,t)=>{let n=Dw(e),r=Dw(t);if(!n)return``;if(!r)return n;if(n===r)return`.`;let i=`${r}/`;return n.startsWith(i)?n.slice(i.length):n},kw=5,Aw=e=>typeof e==`object`&&!!e,jw=e=>{if(!Aw(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=Aw(e.range)?e.range:void 0,i=r&&Aw(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}},Mw=(e,t,n)=>{let r=Aw(n?.filediff)?n.filediff:void 0,i=Aw(r)&&typeof r.file==`string`?r.file:null;if(e===`apply_patch`){let e=(Array.isArray(n?.files)?n.files:[]).find(e=>Aw(e)?typeof e.movePath==`string`||typeof e.filePath==`string`||typeof e.relativePath==`string`:!1);if(Aw(e))return typeof e.movePath==`string`?e.movePath:typeof e.filePath==`string`?e.filePath:typeof e.relativePath==`string`?e.relativePath:i;let t=_C(n?.patch)??_C(n?.diff),r=t?TC(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},Nw=(e,t,n,r)=>{if(![`edit`,`multiedit`,`write`,`apply_patch`].includes(e))return null;let i=Mw(e,t,n);if(!i||!n||!Aw(n.diagnostics))return null;let a=Dw(i),o=a.startsWith(`/`)?a:`${Dw(r)}/${a}`.replace(/\/+/g,`/`),s=n.diagnostics[a]??n.diagnostics[o];if(!Array.isArray(s))return null;let c=s.map(e=>jw(e)).filter(e=>!!e);if(c.length===0)return null;let l=c.slice(0,kw);return{displayPath:a.startsWith(`/`)?Ow(a,r):a,diagnostics:l,remaining:Math.max(0,c.length-l.length)}},Pw=()=>{let e=(0,Q.c)(22),t=Wa(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=Eo(!1),e[0]=n):n=e[0];let r=n,i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=Eo(!0),e[1]=i):i=e[1];let a=i,o;e[2]===t?.availableThemes?o=e[3]:(o=()=>t?.availableThemes??[r,a],e[2]=t?.availableThemes,e[3]=o),t?.availableThemes;let s;e[4]===o?s=e[5]:(s=o(),e[4]=o,e[5]=s);let c=s,l=t?.lightThemeId??r.metadata.id,u=t?.darkThemeId??a.metadata.id,d;e[6]!==c||e[7]!==l?(d=c.find(e=>e.metadata.id===l)??r,e[6]=c,e[7]=l,e[8]=d):d=e[8];let f=d,p;e[9]!==c||e[10]!==u?(p=c.find(e=>e.metadata.id===u)??a,e[9]=c,e[10]=u,e[11]=p):p=e[11];let m=p,h,g;e[12]!==m||e[13]!==f?(h=()=>{Fs(f),Fs(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},Fw=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},Iw=(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`?Ow(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 Ow(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 Ow(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 Ow(e,n)}if(e.tool===`lsp`&&a){let e=a?.filePath||a?.file_path||a?.path;if(typeof e==`string`)return Ow(e,n)}return null},Lw=(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?Ow(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},Rw=(e,t,n)=>{let r=t,i=r.metadata,a=r.input,o=Iw(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 Lw(a,n);let s=a?.description||i?.description||`title`in t&&t.title||``;return typeof s==`string`?s:``},zw=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&&MC(!0),t[7]=c,t[8]=e),f=Y(`tool-output-surface rounded-xl w-full min-w-0`,MC(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)(Oa,{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},Bw=(e,t,n,r)=>t.tool===`bash`?`bash`:Oc(Ic(e,t.tool,n),t.tool,r),Vw=(e,t,n)=>t.tool===`bash`?e:Ic(e,t.tool,n),Hw=e=>{let t=(0,Q.c)(80),{output:n,part:r,metadata:i,input:a,isMobile:o}=e,s=o!==void 0&&o,{t:c}=ot(),l;t[0]!==i||t[1]!==n||t[2]!==r?(l=Vw(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=Bw(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=Mc(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 ct(u)).ok){Tt.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)(ca,{variant:`ghost`,size:`icon`,className:n,onClick:r,onPointerDown:mT,"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)(ca,{variant:`ghost`,size:`icon`,className:d,onClick:f,onPointerDown:hT,"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)(ca,{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:gT,"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)(Rc,{data:m.data,initiallyExpandedDepth:1,maxHeight:`400px`}):(0,$.jsx)(`div`,{className:`typography-code pr-12 text-muted-foreground/90`,children:(0,$.jsx)(jc,{language:`json`,code:u,style:$w,codeStyle:eT.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={...$w,...s&&r.tool===`bash`?{lineHeight:NC}:{}},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)(jc,{language:f,code:u,style:E,codeStyle:eT.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};Hw.displayName=`ToolScrollableTextOutput`;var Uw=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``},Ww=new Set([`read`,`view`,`file_read`,`cat`,`write`,`create`,`file_write`,`edit`,`multiedit`,`apply_patch`]),Gw=(e,t)=>{if(!Ww.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)},Kw=e=>{let t=pw(e.tool),n=e.state?.status??``,r=Uw(e);return`${e.id??``}\u0001${t}\u0001${n}\u0001${r}`},qw=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(Kw(e[n])!==Kw(t[n]))return!1;return!0},Jw=Z.memo(e=>{let t=(0,Q.c)(10),{entry:n,isMobile:r,animateTailText:i,showToolFileIcons:a}=e,{t:o}=ot(),s;if(t[0]!==i||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==o){let e=pw(n.tool),c=e.length>0?e:`tool`,l=Uw(n),u=l.trim().length>0,d=n.state?.status,f=ic(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(ow,`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`&&Gw(c,l)?oT(l,i,!0,a,ow):d===`error`?(0,$.jsx)(`span`,{className:Y(ow,`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(ow,`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&&Kw(e.entry)===Kw(t.entry));Jw.displayName=`TaskSummaryEntryRow`;var Yw=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(ow,`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??`${Kw(e)}:${n}`;return(0,$.jsx)(Jw,{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:sw,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)(zw,{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&&qw(e.entries,t.entries));Yw.displayName=`TaskSummaryEntriesList`;var Xw=e=>{let t=(0,Q.c)(44),{entries:n,isExpanded:r,isMobile:i,output:a,sessionId:o,onShowPopup:c,input:l,animateTailText:u,isActive:d}=e,f=u===void 0||u,p=d!==void 0&&d,{t:m}=ot(),h=lc(),g=Zr(_T),_=s(vT),v=s(yT),y=Z.useContext(Oo),b=Ph(),x=b.directory||h,S;t[0]===a?S=t[1]:(S=typeof a==`string`?IS(a):``,t[0]=a,t[1]=S);let C=S,w=C.length>0,[T,E]=Z.useState(!1),D,O,k,A;if(t[2]!==f||t[3]!==x||t[4]!==n||t[5]!==w||t[6]!==l||t[7]!==p||t[8]!==r||t[9]!==i||t[10]!==_||t[11]!==y?.runtime||t[12]!==o||t[13]!==b||t[14]!==g||t[15]!==v||t[16]!==m){A=Symbol.for(`react.early_return_sentinel`);bb0:{let e=uw(lw(l)??`subagent`),a=t=>{t.stopPropagation(),o&&x&&Ih(b,o,x,()=>{if(!ai({sessionId:o,directory:x})){if(ll()||i||y?.runtime.isVSCode){g(o,x);return}_(x,{mode:`chat`,dedupeKey:`session:${o}`,label:e,readOnly:!0})}})};if(n.length===0&&!w&&!o){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(ow,`text-muted-foreground/70`),t[21]=e):e=t[21];let n=p?`Waiting for subagent activity...`:`No subagent session id on task metadata.`,r;t[22]===n?r=t[23]:(r=(0,$.jsx)(`div`,{className:`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,children:(0,$.jsx)(`div`,{className:e,children:n})}),t[22]=n,t[23]=r),A=r;break bb0}t[24]===Symbol.for(`react.memo_cache_sentinel`)?(D=Y(`relative flex flex-col gap-1 pr-2 pb-1.5 pt-0.5 pl-[1.4375rem]`,`before:absolute before:left-[0.4375rem] before:w-px before:bg-border/80 before:content-[""]`,`before:top-0 before:bottom-0`),t[24]=D):D=t[24],t[25]!==f||t[26]!==n||t[27]!==r||t[28]!==i||t[29]!==v?(O=n.length>0?(0,$.jsx)(Yw,{entries:n,isExpanded:r,isMobile:i,animateTailText:f,showToolFileIcons:v}):null,t[25]=f,t[26]=n,t[27]=r,t[28]=i,t[29]=v,t[30]=O):O=t[30],k=o&&b.capabilities.navigateNestedSession&&(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-primary hover:text-primary/80 w-full`,ow),onPointerDown:bT,onClick:a,children:[(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(ow,`text-primary font-medium`),children:m(`chat.toolPart.openSubtask`,{type:e})})]})}t[2]=f,t[3]=x,t[4]=n,t[5]=w,t[6]=l,t[7]=p,t[8]=r,t[9]=i,t[10]=_,t[11]=y?.runtime,t[12]=o,t[13]=b,t[14]=g,t[15]=v,t[16]=m,t[17]=D,t[18]=O,t[19]=k,t[20]=A}else D=t[17],O=t[18],k=t[19],A=t[20];if(A!==Symbol.for(`react.early_return_sentinel`))return A;let j;t[31]!==n.length||t[32]!==w||t[33]!==T||t[34]!==c||t[35]!==o||t[36]!==m||t[37]!==C?(j=w?(0,$.jsxs)(`div`,{className:Y(`flex flex-col gap-1`,(n.length>0||o)&&`pt-1`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex items-center gap-1.5 text-foreground/80 hover:text-foreground w-full`,ow),onPointerDown:xT,onClick:e=>{e.stopPropagation(),E(ST)},children:[T?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:Y(ow,`text-foreground/80 font-medium`),children:m(`chat.toolPart.output`)})]}),T?(0,$.jsx)(zw,{maxHeightClass:`max-h-[50vh]`,children:(0,$.jsx)(`div`,{className:`w-full min-w-0`,children:(0,$.jsx)(ks,{content:C,variant:`tool`,onShowPopup:c})})}):null]}):null,t[31]=n.length,t[32]=w,t[33]=T,t[34]=c,t[35]=o,t[36]=m,t[37]=C,t[38]=j):j=t[38];let M;return t[39]!==D||t[40]!==O||t[41]!==k||t[42]!==j?(M=(0,$.jsxs)(`div`,{className:D,children:[O,k,j]}),t[39]=D,t[40]=O,t[41]=k,t[42]=j,t[43]=M):M=t[43],M},Zw=`
|
|
6553
6553
|
[data-diff-header],
|
|
6554
6554
|
[data-diff] {
|
|
6555
6555
|
[data-separator] {
|
|
6556
6556
|
height: 24px !important;
|
|
6557
6557
|
}
|
|
6558
6558
|
}
|
|
6559
|
-
`,Gw={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},Kw={...o.getCollapsedStyles(),padding:0,overflow:`visible`},qw={style:{background:`transparent`,backgroundColor:`transparent`}},Jw={color:`var(--status-error)`},Yw={color:`var(--tools-icon)`},Xw={color:`var(--status-error)`},Zw={color:`var(--tools-title)`},Qw=(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})]})]})},$w=(e,t=!0,n=!0,r=!0,i=QC)=>{let a=e.lastIndexOf(`/`),o=i===$C?`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)(gd,{filePath:e,className:o}):null,(0,$.jsx)(Zx,{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)(gd,{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)(Zx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:c})]})]})},eT=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},tT=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}},nT=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:Ww},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)(eT,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)(Yc,{patch:n,metrics:Gw,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)(tT,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});nT.displayName=`DiffPreview`;var rT=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=ot(),{pierreTheme:s,pierreThemeType:c}=Dw(),[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:``,_=Cw(f?.filediff)?f.filediff:void 0,v=uC(f?.patch)??uC(f?.diff)??uC(_?.patch)??uC(_?.diff)??null,y=Z.useMemo(()=>vC(f,v??void 0,e=>xw(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>Ew(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`?zc(p,e.tool):typeof p.content==`string`?p.content??``:zc(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:_w(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)(Mw,{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:Qw(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=Ow(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:Nc(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:Nc(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:Nc(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:Nc(e.label)},Nc(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)(ks,{content:Nc(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)(nT,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(eT,{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)(Fw,{output:Nc(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:wC(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=Lc(E,void 0,{listClassName:Pc});return(0,$.jsx)(`div`,{className:wC(i,`todo`),children:O(n??(0,$.jsx)(Fw,{output:E,part:e,metadata:f,input:p,isMobile:i}),wc)})}return(0,$.jsx)(`div`,{className:wC(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:EC}:void 0,children:S}):w&&D?(0,$.jsx)(nT,{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:Nc(t.error)})]})]})})});rT.displayName=`ToolExpandedContent`;var iT=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:c=!0})=>{let l=e.state,u=s(e=>e.showToolFileIcons),d=s(e=>e.showSubagentTaskDetails),f=s(e=>e.openContextPanelTab),p=s(e=>e.openContextDiff),m=s(e=>e.openContextToolDiff),h=s(e=>e.navigateToDiff),{t:g}=ot(),_=lc(),v=Zr(e=>e.setCurrentSession),y=$h(),b=Ph(),x=b.directory||_||``,S=ow(e.tool),C=S===`task`,w=S===`todowrite`||S===`todoread`,T=uw(S),E=l?.status,D=qC(e),O=E===`error`||E===`failed`,[k,A]=Z.useState(!D),j=Z.useRef(e.id),M=Z.useRef(``);Z.useEffect(()=>{j.current!==e.id&&(j.current=e.id,M.current=``,A(!D))},[D,e.id]),Z.useEffect(()=>{D||A(!0)},[D]),Z.useEffect(()=>{if(!D||O||!x||!cw.has(S))return;let t=`${e.id}:${E??`unknown`}`;M.current!==t&&(M.current=t,Ei.requestGitRefresh({directory:x}))},[x,O,D,S,e.id,E]);let N=D||C,P=Z.useRef(a);P.current=a;let F=Z.useRef(null);Z.useLayoutEffect(()=>{if(C||T)return;let e=F.current;if(!e){N&&P.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,N&&P.current?.(`structural`)},[n,T,C,N]);let I=l,L=I.metadata,R=e.metadata,z=I.input,B=I.time,[V,H]=Z.useState(()=>({start:typeof B?.start==`number`?B.start:void 0,end:typeof B?.end==`number`?B.end:void 0})),[U,W]=Z.useState(void 0),[ee,G]=Z.useState(void 0);Z.useEffect(()=>{H({}),W(void 0),G(void 0)},[e.id]),Z.useEffect(()=>{D||typeof B?.start!=`number`&&W(e=>e??Date.now())},[D,B?.start]),Z.useEffect(()=>{H(e=>{let t={...e},n=!1;return typeof B?.start==`number`&&(typeof e.start!=`number`||B.start<e.start)&&(t.start=B.start,n=!0),typeof B?.end==`number`&&(typeof e.end!=`number`||B.end>e.end)&&(t.end=B.end,n=!0),n?t:e})},[B?.end,B?.start]);let K=Z.useMemo(()=>{if(typeof U==`number`)return U;let e=[V.start,B?.start].filter(e=>typeof e==`number`);if(e.length!==0)return Math.min(...e)},[U,V.start,B?.start]),q=Z.useMemo(()=>typeof I.output==`string`?I.output:void 0,[I.output]),te=Z.useMemo(()=>lS(q),[q]),ne=Z.useMemo(()=>{if(!C)return[];let e=L,t=cS(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:te.summaryEntries},[C,L,te.summaryEntries]),re=D&&ne.length>0,ie=Z.useMemo(()=>C?oS(L)||oS(I)||oS(z)||oS(R)||(te.sessionId?te.sessionId:uS(q)):void 0,[z,C,L,te.sessionId,R,I,q]),ae=Z.useMemo(()=>C&&D&&!!(dS(L)===`running`||dS(I)===`running`||dS(R)===`running`||te.status===`running`||mS(q)),[C,D,L,te.status,R,I,q]),[oe,se]=Z.useState(!0),ce=C&&(!D&&k||ae&&oe),le=ce?ie:void 0,ue=ce&&!ie?e.sessionID:void 0,de=le??ue,fe=wr(le??``,x),pe=wr(ue??``,x),me=Ar(de??``,x),he=hi(x,ce),ge=!!(ae&&fe?.type===`idle`&&typeof K==`number`&&(typeof me==`number`&&K<=me||typeof he==`number`&&K<=he));Z.useEffect(()=>{ge&&se(!1)},[ge]);let _e=!!(ae&&oe&&ie&&fe?.type!==`idle`),ve=!d||re?``:ie??``,ye=pr(ve,x);Si(ve,x);let be=Z.useMemo(()=>!C||!ie||!Array.isArray(ye)||ye.length===0?[]:xS(ye),[ye,C,ie]);Z.useEffect(()=>{if(typeof B?.end==`number`||typeof V.end==`number`){G(void 0);return}typeof K==`number`&&D&&G(e=>e??Date.now())},[K,D,V.end,B?.end]);let xe=D?V.end??B?.end??ee:void 0,Se=!D&&k,Ce=jS({isTaskTool:C,isFinalized:D,taskSessionId:ie,childSessionStatus:fe,parentSessionStatus:pe,statusObservedAt:me,taskStartedAt:K,statusSnapshotAt:he}),we=Se&&!Ce||_e,Te=!!(C&&we&&!O);Z.useEffect(()=>{Ce&&A(!1)},[Ce]);let Ee=D,De=Z.useMemo(()=>be.length>0?be:ne,[be,ne]),Oe=Z.useMemo(()=>De.map(zw).join(`\0`),[De]),ke=Z.useRef(null);Z.useEffect(()=>{if(!C){ke.current=null;return}let e=ke.current;ke.current=Oe,e!==null&&e!==Oe&&De.length!==0&&P.current?.(`structural`)},[C,De.length,Oe]);let Ae=Z.useMemo(()=>S===`edit`||S===`multiedit`||S===`apply_patch`?mw(L):null,[L,S]),je=Z.useMemo(()=>S===`write`?hw(z):null,[z,S]),Me=S===`apply_patch`&&Array.isArray(L?.files)&&(L?.files).length>1,Ne=S===e.tool?e:{...e,tool:S},Pe=kw(Ne,l,x),Fe=jw(Ne,l,x),Ie=ic(S||e.tool,g),Le=pt(C?ie:void 0,x),Re=pt(C?ie:void 0),ze=C?nw(z,L,R,Le??Re):void 0,Be=AS({isTaskTool:C,isFinalized:D,taskSessionId:ie,taskAgentName:ze,displayName:Ie,delegatingLabel:g(`chat.assistantStatus.delegatingTask`),formatName:rw}),Ve=C&&Be.isDelegating,He=Be.title,Ue=typeof e.sessionID==`string`?e.sessionID.trim():``,We=Z.useMemo(()=>{if(!C||!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}:{},...x?{directory:x}:{},directoryPresent:!!x,childSessionPresent:!!n,...n?{childSessionID:n}:{},...E?{toolStatus:E}:{},finalized:D,backgroundRunning:_e,effectiveActive:we,suppressLoading:Ce,delegating:Ve,childStatus:qi(fe),parentStatus:qi(pe),idleConfirmed:ge,navigateCapability:b.capabilities.navigateNestedSession,surfaceKind:b.kind,...typeof K==`number`?{taskStartedAt:K}:{},...typeof me==`number`?{statusObservedAt:me}:{},...typeof he==`number`?{statusSnapshotAt:he}:{}}},[ge,fe,x,we,K,Ve,D,C,t,Ue,pe,e.id,e.messageID,b.capabilities.navigateNestedSession,b.kind,E,me,he,Ce,_e,ie]),Ge=We?Gi(We):``,Ke=Z.useRef(We);Ke.current=We,Z.useEffect(()=>{let e=Ke.current;!e||!Ge||ni(e)},[Ge]);let qe=J((e,t)=>{let n=Ke.current;n&&mi({...n,opened:e,clickSource:t})}),Je=Ve?{"data-delegating":`true`}:void 0,Ye=Z.useMemo(()=>{if(S===`bash`||S===`apply_patch`||S===`lsp`||Pe&&(S===`apply_patch`||S===`edit`||S===`multiedit`||S===`write`))return null;let e=I.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=z?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Pe,S,I,z]),Xe=Z.useContext(Oo),Ze=Z.useRef(!1),Qe=J(e=>{let t=e??ie;return!t||!x?!1:(Ze.current=!1,Ih(b,t,x,()=>{if(!ai({sessionId:t,directory:x})){if(i||Xe?.runtime.isVSCode){v(t,x);return}f(x,{mode:`chat`,dedupeKey:`session:${t}`,label:He,readOnly:!0})}}))});Z.useEffect(()=>{!Ze.current||!ie||qe(Qe(ie),`queued-effect`)},[ie]);let $e=n=>{if(C){n.stopPropagation();let e=b.capabilities.navigateNestedSession,t=e?Qe():!1;qe(t,`row`),e&&!t&&(Ze.current=!0);return}if(T&&!x)return;let a,o,c;if(S===`edit`||S===`multiedit`||S===`apply_patch`)a=Tw(S,z,L),o=vw(S,L,typeof a==`string`?a:void 0),typeof a==`string`&&(c=yw(S,L,a));else if([`write`,`create`,`file_write`].includes(S))a=z?.filePath||z?.file_path||z?.path||L?.filePath||L?.file_path||L?.path,o=1,typeof a==`string`&&typeof z?.content==`string`&&(c=_w(a,z.content));else if(S===`lsp`){a=z?.filePath||z?.file_path||z?.path;let e=z?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=vo(x,a)||(a.startsWith(`/`)?a:x.endsWith(`/`)?x+a:`${x}/${a}`);if(T){let e=xw(r,x),n=(c?bC(S,L,c,e,e=>xw(e,x)):[]).map(e=>({path:e.title,patch:e.patch}));if(Xe?.runtime.isVSCode&&Xe.editor&&c){let t=`${e} (changes)`;Xe.editor.openDiff(``,r,t,{line:o,patch:c});return}if(So(r,x)){y?n.length>0?y.openToolDiff({diffPath:e,patches:n,targetLine:o}):S===`apply_patch`?y.openTurnDiff(t,b.sessionId):y.openChanges({diffPath:e,staged:!1,targetLine:o}):i?h(e,!1,`turn`,o):n.length>0?m(x,e,n,o,t,b.sessionId):p(x,e,!1,`turn`,o,t,b.sessionId);return}if(Xe?.editor){Xe.editor.openFile(r,o);return}uc(r,x).then(()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(S===`lsp`){if(Xe?.editor){Xe.editor.openFile(r,o);return}let e=()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!So(r,x)){uc(r,x).then(e);return}e();return}if(Xe?.editor){if(Xe.runtime.isVSCode&&c&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${xw(r,x)} (changes)`;Xe.editor.openDiff(``,r,e,{line:o,patch:c});return}Xe.editor.openFile(r,o);return}}if(S===`apply_patch`&&y){n.stopPropagation(),y.openTurnDiff(t,b.sessionId);return}if(S===`apply_patch`&&x&&!y&&!i&&!Xe?.runtime.isVSCode){n.stopPropagation(),f(x,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:b.sessionId});return}T||r(e.id)},et=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),$e(e))},tt=!C&&O?Jw:Yw,nt=!C&&O?Xw:Zw,rt=C&&d&&(De.length>0||we||Ee||!!ie),it=!C&&!T&&n;return!Ee&&!Se&&!C?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,dm,C&&`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:C&&Be.showAvatar?void 0:tt,children:C&&Be.showAvatar?(0,$.jsx)(sa,{name:e.id||ze||`subagent`,size:14,label:He}):we?(0,$.jsx)(NC,{isMobile:i,className:`text-[var(--tools-icon)]`,label:g(`chat.assistantStatus.usingTool`,{tool:He})}):Qx(S||e.tool)})}),Me?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(ZC,`flex-shrink-0`),style:nt,title:Ie,children:Ie}),aw(L,c,u)]}):(0,$.jsxs)($.Fragment,{children:[Te?(0,$.jsx)(`span`,{className:Y(ZC,`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(ZC,`shrink-0 whitespace-nowrap`),style:nt,title:He,children:He}),S===`bash`&&typeof K==`number`?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,QC),children:(0,$.jsx)(fw,{start:K,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`,QC),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`,QC,Te&&`animate-text-shimmer`),style:{color:`var(--tools-description)`,...Te?{"--oc-text-shimmer-base":`var(--tools-description)`}:{opacity:.8}},title:Ye,children:Ye}),!Ye&&S===`lsp`&&Pe?$w(Pe,c,!1,u):null,!Ye&&S!==`lsp`&&Fe&&(Pe&&Fe===Pe?$w(Pe,c,!1,u):(0,$.jsx)(Zx,{variant:c?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,QC),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]})})]})}),!T&&(!C||d)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:C?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),rt?(0,$.jsx)(Uw,{entries:De,isExpanded:n,isMobile:i,output:q,sessionId:ie,onShowPopup:o,input:z,animateTailText:c,isActive:we}):null,!C&&!T&&n?(0,$.jsx)(`div`,{ref:F,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:it?(0,$.jsxs)(`div`,{className:w?`relative ml-0.5 pl-1.5`:CC,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)(rT,{part:e,state:l,currentDirectory:x,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},aT=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`,lm),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:Jw,children:Qx(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(ZC,`flex-shrink-0`),style:Xw,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(QC,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},oT=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=ot(),r=SC(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=ow(e.part.tool)||`tool`,i=ic(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||iw.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 mc(()=>{iw.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`,lm),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(ZC,`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)(iT,{...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)(aT,{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)=>zS([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 sT(e){return e.stopPropagation()}function cT(e){return e.stopPropagation()}function lT(e){return e.stopPropagation()}function uT(e){return e.setCurrentSession}function dT(e){return e.openContextPanelTab}function fT(e){return e.showToolFileIcons}function pT(e){return e.stopPropagation()}function mT(e){return e.stopPropagation()}function hT(e){return!e}var gT=(e,t,n)=>{let r=t-e;return Math.max(0,n-r)},_T=e=>{e.timer&&=(clearTimeout(e.timer),null)},vT=({text:e,isStreaming:t,throttleMs:n=_c(ze()).textThrottleMs,identityKey:r})=>{let[i,a]=Z.useState(e),o=Z.useRef(e),s=Z.useRef(i),c=Z.useRef({timer:null,pendingText:e,lastEmitAt:0});return Z.useEffect(()=>{o.current=e},[e]),Z.useEffect(()=>{s.current=i},[i]),Z.useEffect(()=>{let e=c.current;_T(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){_T(r),r.lastEmitAt=Date.now(),a(o);return}let l=Date.now(),u=gT(r.lastEmitAt,l,n);if(u<=0){_T(r),r.lastEmitAt=l,a(o);return}return _T(r),r.timer=setTimeout(()=>{r.timer=null,r.lastEmitAt=Date.now(),a(e=>t&&e.length>r.pendingText.length?e:r.pendingText)},u),()=>{_T(r)}},[t,e,n]),Z.useEffect(()=>{let e=c.current;return()=>{_T(e)}},[]),i},yT=e=>e.isStreaming?e.throttledTextContent:e.textContent,bT=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,xT=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=ot(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(ST)],t[2]=n.highlights,t[3]=n.subject,t[4]=e):e=t[4],l=e.join(`
|
|
6559
|
+
`,Qw={hunkLineCount:50,lineHeight:24,diffHeaderHeight:44,hunkSeparatorHeight:24,spacing:0},$w={...o.getCollapsedStyles(),padding:0,overflow:`visible`},eT={style:{background:`transparent`,backgroundColor:`transparent`}},tT={color:`var(--status-error)`},nT={color:`var(--tools-icon)`},rT={color:`var(--status-error)`},iT={color:`var(--tools-title)`},aT=(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})]})]})},oT=(e,t=!0,n=!0,r=!0,i=aw)=>{let a=e.lastIndexOf(`/`),o=i===ow?`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)(gd,{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)(gd,{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})]})]})},sT=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},cT=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}},lT=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:Zw},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)(sT,{diff:n}),t[4]=n,t[5]=l);let u=l,d;t[6]!==n||t[7]!==c?(d=(0,$.jsx)(Yc,{patch:n,metrics:Qw,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)(cT,{resetKey:n,fallback:u,children:d})}),t[9]=n,t[10]=u,t[11]=d,t[12]=f):f=t[12],f});lT.displayName=`DiffPreview`;var uT=Z.memo(({part:e,state:t,currentDirectory:n,isExpanded:r,isMobile:i,onShowPopup:a})=>{let{t:o}=ot(),{pierreTheme:s,pierreThemeType:c}=Pw(),[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:``,_=Aw(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=>Ow(e,n)),[n,v,f]),b=e.tool===`apply_patch`||e.tool===`edit`||e.tool===`multiedit`,x=Z.useMemo(()=>Nw(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`?zc(p,e.tool):typeof p.content==`string`?p.content??``:zc(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:ww(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)(zw,{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:aT(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=Fw(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:Nc(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:Nc(e.header)}):null,(0,$.jsx)(`div`,{className:`typography-meta text-foreground`,children:Nc(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:Nc(e.label)},Nc(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)(ks,{content:Nc(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)(lT,{diff:e.patch,pierreTheme:s,pierreThemeType:c,diffViewMode:l}):(0,$.jsx)(sT,{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)(Hw,{output:Nc(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:jC(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=Lc(E,void 0,{listClassName:Pc});return(0,$.jsx)(`div`,{className:jC(i,`todo`),children:O(n??(0,$.jsx)(Hw,{output:E,part:e,metadata:f,input:p,isMobile:i}),wc)})}return(0,$.jsx)(`div`,{className:jC(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:NC}:void 0,children:S}):w&&D?(0,$.jsx)(lT,{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:Nc(t.error)})]})]})})});uT.displayName=`ToolExpandedContent`;var dT=({part:e,messageId:t,isExpanded:n,onToggle:r,isMobile:i,onContentChange:a,onShowPopup:o,animateTailText:c=!0})=>{let l=e.state,u=s(e=>e.showToolFileIcons),d=s(e=>e.showSubagentTaskDetails),f=s(e=>e.openContextPanelTab),p=s(e=>e.openContextDiff),m=s(e=>e.openContextToolDiff),h=s(e=>e.navigateToDiff),{t:g}=ot(),_=lc(),v=Zr(e=>e.setCurrentSession),y=$h(),b=Ph(),x=b.directory||_||``,S=pw(e.tool),C=S===`task`,w=S===`todowrite`||S===`todoread`,T=_w(S),E=l?.status,D=ew(e),O=E===`error`||E===`failed`,[k,A]=Z.useState(!D),j=Z.useRef(e.id),M=Z.useRef(``);Z.useEffect(()=>{j.current!==e.id&&(j.current=e.id,M.current=``,A(!D))},[D,e.id]),Z.useEffect(()=>{D||A(!0)},[D]),Z.useEffect(()=>{if(!D||O||!x||!hw.has(S))return;let t=`${e.id}:${E??`unknown`}`;M.current!==t&&(M.current=t,Ei.requestGitRefresh({directory:x}))},[x,O,D,S,e.id,E]);let N=D||C,P=Z.useRef(a);P.current=a;let F=Z.useRef(null);Z.useLayoutEffect(()=>{if(C||T)return;let e=F.current;if(!e){N&&P.current?.(`structural`);return}e.style.height=n?`auto`:`0px`,e.style.overflow=n?`visible`:`hidden`,N&&P.current?.(`structural`)},[n,T,C,N]);let I=l,L=I.metadata,R=e.metadata,z=I.input,B=I.time,[V,H]=Z.useState(()=>({start:typeof B?.start==`number`?B.start:void 0,end:typeof B?.end==`number`?B.end:void 0})),[U,W]=Z.useState(void 0),[ee,G]=Z.useState(void 0);Z.useEffect(()=>{H({}),W(void 0),G(void 0)},[e.id]),Z.useEffect(()=>{D||typeof B?.start!=`number`&&W(e=>e??Date.now())},[D,B?.start]),Z.useEffect(()=>{H(e=>{let t={...e},n=!1;return typeof B?.start==`number`&&(typeof e.start!=`number`||B.start<e.start)&&(t.start=B.start,n=!0),typeof B?.end==`number`&&(typeof e.end!=`number`||B.end>e.end)&&(t.end=B.end,n=!0),n?t:e})},[B?.end,B?.start]);let K=Z.useMemo(()=>{if(typeof U==`number`)return U;let e=[V.start,B?.start].filter(e=>typeof e==`number`);if(e.length!==0)return Math.min(...e)},[U,V.start,B?.start]),q=Z.useMemo(()=>typeof I.output==`string`?I.output:void 0,[I.output]),te=Z.useMemo(()=>gS(q),[q]),ne=Z.useMemo(()=>{if(!C)return[];let e=L,t=hS(e?.summary??e?.entries??e?.tools??e?.calls);return t.length>0?t:te.summaryEntries},[C,L,te.summaryEntries]),re=D&&ne.length>0,ie=Z.useMemo(()=>C?pS(L)||pS(I)||pS(z)||pS(R)||(te.sessionId?te.sessionId:_S(q)):void 0,[z,C,L,te.sessionId,R,I,q]),ae=Z.useMemo(()=>C&&D&&!!(vS(L)===`running`||vS(I)===`running`||vS(R)===`running`||te.status===`running`||xS(q)),[C,D,L,te.status,R,I,q]),[oe,se]=Z.useState(!0),ce=C&&(!D&&k||ae&&oe),le=ce?ie:void 0,ue=ce&&!ie?e.sessionID:void 0,de=le??ue,fe=wr(le??``,x),pe=wr(ue??``,x),me=Ar(de??``,x),he=hi(x,ce),ge=!!(ae&&fe?.type===`idle`&&typeof K==`number`&&(typeof me==`number`&&K<=me||typeof he==`number`&&K<=he));Z.useEffect(()=>{ge&&se(!1)},[ge]);let _e=!!(ae&&oe&&ie&&fe?.type!==`idle`),ve=!d||re?``:ie??``,ye=pr(ve,x);Si(ve,x);let be=Z.useMemo(()=>!C||!ie||!Array.isArray(ye)||ye.length===0?[]:OS(ye),[ye,C,ie]);Z.useEffect(()=>{if(typeof B?.end==`number`||typeof V.end==`number`){G(void 0);return}typeof K==`number`&&D&&G(e=>e??Date.now())},[K,D,V.end,B?.end]);let xe=D?V.end??B?.end??ee:void 0,Se=!D&&k,Ce=RS({isTaskTool:C,isFinalized:D,taskSessionId:ie,childSessionStatus:fe,parentSessionStatus:pe,statusObservedAt:me,taskStartedAt:K,statusSnapshotAt:he}),we=Se&&!Ce||_e,Te=!!(C&&we&&!O);Z.useEffect(()=>{Ce&&A(!1)},[Ce]);let Ee=D,De=Z.useMemo(()=>be.length>0?be:ne,[be,ne]),Oe=Z.useMemo(()=>De.map(Kw).join(`\0`),[De]),ke=Z.useRef(null);Z.useEffect(()=>{if(!C){ke.current=null;return}let e=ke.current;ke.current=Oe,e!==null&&e!==Oe&&De.length!==0&&P.current?.(`structural`)},[C,De.length,Oe]);let Ae=Z.useMemo(()=>S===`edit`||S===`multiedit`||S===`apply_patch`?xw(L):null,[L,S]),je=Z.useMemo(()=>S===`write`?Sw(z):null,[z,S]),Me=S===`apply_patch`&&Array.isArray(L?.files)&&(L?.files).length>1,Ne=S===e.tool?e:{...e,tool:S},Pe=Iw(Ne,l,x),Fe=Rw(Ne,l,x),Ie=ic(S||e.tool,g),Le=pt(C?ie:void 0,x),Re=pt(C?ie:void 0),ze=C?lw(z,L,R,Le??Re):void 0,Be=LS({isTaskTool:C,isFinalized:D,taskSessionId:ie,taskAgentName:ze,displayName:Ie,delegatingLabel:g(`chat.assistantStatus.delegatingTask`),formatName:uw}),Ve=C&&Be.isDelegating,He=Be.title,Ue=typeof e.sessionID==`string`?e.sessionID.trim():``,We=Z.useMemo(()=>{if(!C||!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}:{},...x?{directory:x}:{},directoryPresent:!!x,childSessionPresent:!!n,...n?{childSessionID:n}:{},...E?{toolStatus:E}:{},finalized:D,backgroundRunning:_e,effectiveActive:we,suppressLoading:Ce,delegating:Ve,childStatus:qi(fe),parentStatus:qi(pe),idleConfirmed:ge,navigateCapability:b.capabilities.navigateNestedSession,surfaceKind:b.kind,...typeof K==`number`?{taskStartedAt:K}:{},...typeof me==`number`?{statusObservedAt:me}:{},...typeof he==`number`?{statusSnapshotAt:he}:{}}},[ge,fe,x,we,K,Ve,D,C,t,Ue,pe,e.id,e.messageID,b.capabilities.navigateNestedSession,b.kind,E,me,he,Ce,_e,ie]),Ge=We?Gi(We):``,Ke=Z.useRef(We);Ke.current=We,Z.useEffect(()=>{let e=Ke.current;!e||!Ge||ni(e)},[Ge]);let qe=J((e,t)=>{let n=Ke.current;n&&mi({...n,opened:e,clickSource:t})}),Je=Ve?{"data-delegating":`true`}:void 0,Ye=Z.useMemo(()=>{if(S===`bash`||S===`apply_patch`||S===`lsp`||Pe&&(S===`apply_patch`||S===`edit`||S===`multiedit`||S===`write`))return null;let e=I.title;if(typeof e==`string`&&e.trim().length>0)return e;let t=z?.description;return typeof t==`string`&&t.trim().length>0?t:null},[Pe,S,I,z]),Xe=Z.useContext(Oo),Ze=Z.useRef(!1),Qe=J(e=>{let t=e??ie;return!t||!x?!1:(Ze.current=!1,Ih(b,t,x,()=>{if(!ai({sessionId:t,directory:x})){if(i||Xe?.runtime.isVSCode){v(t,x);return}f(x,{mode:`chat`,dedupeKey:`session:${t}`,label:He,readOnly:!0})}}))});Z.useEffect(()=>{!Ze.current||!ie||qe(Qe(ie),`queued-effect`)},[ie]);let $e=n=>{if(C){n.stopPropagation();let e=b.capabilities.navigateNestedSession,t=e?Qe():!1;qe(t,`row`),e&&!t&&(Ze.current=!0);return}if(T&&!x)return;let a,o,c;if(S===`edit`||S===`multiedit`||S===`apply_patch`)a=Mw(S,z,L),o=Tw(S,L,typeof a==`string`?a:void 0),typeof a==`string`&&(c=Ew(S,L,a));else if([`write`,`create`,`file_write`].includes(S))a=z?.filePath||z?.file_path||z?.path||L?.filePath||L?.file_path||L?.path,o=1,typeof a==`string`&&typeof z?.content==`string`&&(c=ww(a,z.content));else if(S===`lsp`){a=z?.filePath||z?.file_path||z?.path;let e=z?.line;o=typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0}if(typeof a==`string`){n.stopPropagation();let r=vo(x,a)||(a.startsWith(`/`)?a:x.endsWith(`/`)?x+a:`${x}/${a}`);if(T){let e=Ow(r,x),n=(c?DC(S,L,c,e,e=>Ow(e,x)):[]).map(e=>({path:e.title,patch:e.patch}));if(Xe?.runtime.isVSCode&&Xe.editor&&c){let t=`${e} (changes)`;Xe.editor.openDiff(``,r,t,{line:o,patch:c});return}if(So(r,x)){y?n.length>0?y.openToolDiff({diffPath:e,patches:n,targetLine:o}):S===`apply_patch`?y.openTurnDiff(t,b.sessionId):y.openChanges({diffPath:e,staged:!1,targetLine:o}):i?h(e,!1,`turn`,o):n.length>0?m(x,e,n,o,t,b.sessionId):p(x,e,!1,`turn`,o,t,b.sessionId);return}if(Xe?.editor){Xe.editor.openFile(r,o);return}uc(r,x).then(()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)});return}if(S===`lsp`){if(Xe?.editor){Xe.editor.openFile(r,o);return}let e=()=>{let e=s.getState(),t=go(x,r);if(typeof o==`number`&&Number.isFinite(o)){e.openContextFileAtLine(t,r,Math.max(1,Math.trunc(o)),1);return}e.openContextFile(t,r)};if(!So(r,x)){uc(r,x).then(e);return}e();return}if(Xe?.editor){if(Xe.runtime.isVSCode&&c&&(e.tool===`edit`||e.tool===`multiedit`||e.tool===`apply_patch`)){let e=`${Ow(r,x)} (changes)`;Xe.editor.openDiff(``,r,e,{line:o,patch:c});return}Xe.editor.openFile(r,o);return}}if(S===`apply_patch`&&y){n.stopPropagation(),y.openTurnDiff(t,b.sessionId);return}if(S===`apply_patch`&&x&&!y&&!i&&!Xe?.runtime.isVSCode){n.stopPropagation(),f(x,{mode:`diff`,diffScope:`turn`,diffTurnMessageId:t,diffSessionId:b.sessionId});return}T||r(e.id)},et=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),$e(e))},tt=!C&&O?tT:nT,nt=!C&&O?rT:iT,rt=C&&d&&(De.length>0||we||Ee||!!ie),it=!C&&!T&&n;return!Ee&&!Se&&!C?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:Y(`group/tool flex gap-1.5 cursor-pointer`,dm,C&&`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:C&&Be.showAvatar?void 0:tt,children:C&&Be.showAvatar?(0,$.jsx)(sa,{name:e.id||ze||`subagent`,size:14,label:He}):we?(0,$.jsx)(BC,{isMobile:i,className:`text-[var(--tools-icon)]`,label:g(`chat.assistantStatus.usingTool`,{tool:He})}):aS(S||e.tool)})}),Me?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:Y(iw,`flex-shrink-0`),style:nt,title:Ie,children:Ie}),fw(L,c,u)]}):(0,$.jsxs)($.Fragment,{children:[Te?(0,$.jsx)(`span`,{className:Y(iw,`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(iw,`shrink-0 whitespace-nowrap`),style:nt,title:He,children:He}),S===`bash`&&typeof K==`number`?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums text-muted-foreground/80`,aw),children:(0,$.jsx)(yw,{start:K,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`,aw),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`,aw,Te&&`animate-text-shimmer`),style:{color:`var(--tools-description)`,...Te?{"--oc-text-shimmer-base":`var(--tools-description)`}:{opacity:.8}},title:Ye,children:Ye}),!Ye&&S===`lsp`&&Pe?oT(Pe,c,!1,u):null,!Ye&&S!==`lsp`&&Fe&&(Pe&&Fe===Pe?oT(Pe,c,!1,u):(0,$.jsx)(iS,{variant:c?`generate-effect`:`static`,className:Y(`min-w-0 truncate`,aw),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]})})]})}),!T&&(!C||d)?(0,$.jsx)(`span`,{className:`ml-auto inline-flex size-3.5 flex-shrink-0 items-center justify-center text-muted-foreground opacity-70`,onClick:C?t=>{t.stopPropagation(),r(e.id)}:void 0,children:(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})}):null]}),rt?(0,$.jsx)(Xw,{entries:De,isExpanded:n,isMobile:i,output:q,sessionId:ie,onShowPopup:o,input:z,animateTailText:c,isActive:we}):null,!C&&!T&&n?(0,$.jsx)(`div`,{ref:F,"aria-hidden":!1,style:{height:`auto`,overflow:`visible`,overflowAnchor:`none`},children:it?(0,$.jsxs)(`div`,{className:w?`relative ml-0.5 pl-1.5`:AC,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)(uT,{part:e,state:l,currentDirectory:x,isExpanded:n,isMobile:i,onShowPopup:o})]}):null}):null]})},fT=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`,lm),children:[(0,$.jsx)(`div`,{className:`h-3.5 w-3.5 flex-shrink-0`,style:tT,children:aS(this.props.toolName)}),(0,$.jsx)(`span`,{className:Y(iw,`flex-shrink-0`),style:rT,children:this.props.displayName}),e?(0,$.jsxs)(`span`,{className:Y(aw,`min-w-0 truncate`),style:{color:`var(--tools-description)`},title:e,children:[this.props.errorLabel,`: `,e]}):null]})}},pT=Z.memo(e=>{let t=(0,Q.c)(30),{t:n}=ot(),r=kC(),i,a;t[0]!==e.part.tool||t[1]!==n?(a=pw(e.part.tool)||`tool`,i=ic(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||dw.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 mc(()=>{dw.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`,lm),n=(0,$.jsx)(`span`,{className:`h-3.5 w-3.5 shrink-0 rounded bg-muted/50`,"aria-hidden":`true`}),r=Y(iw,`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)(dT,{...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)(fT,{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 mT(e){return e.stopPropagation()}function hT(e){return e.stopPropagation()}function gT(e){return e.stopPropagation()}function _T(e){return e.setCurrentSession}function vT(e){return e.openContextPanelTab}function yT(e){return e.showToolFileIcons}function bT(e){return e.stopPropagation()}function xT(e){return e.stopPropagation()}function ST(e){return!e}var CT=(e,t,n)=>{let r=t-e;return Math.max(0,n-r)},wT=e=>{e.timer&&=(clearTimeout(e.timer),null)},TT=({text:e,isStreaming:t,throttleMs:n=_c(ze()).textThrottleMs,identityKey:r})=>{let[i,a]=Z.useState(e),o=Z.useRef(e),s=Z.useRef(i),c=Z.useRef({timer:null,pendingText:e,lastEmitAt:0});return Z.useEffect(()=>{o.current=e},[e]),Z.useEffect(()=>{s.current=i},[i]),Z.useEffect(()=>{let e=c.current;wT(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){wT(r),r.lastEmitAt=Date.now(),a(o);return}let l=Date.now(),u=CT(r.lastEmitAt,l,n);if(u<=0){wT(r),r.lastEmitAt=l,a(o);return}return wT(r),r.timer=setTimeout(()=>{r.timer=null,r.lastEmitAt=Date.now(),a(e=>t&&e.length>r.pendingText.length?e:r.pendingText)},u),()=>{wT(r)}},[t,e,n]),Z.useEffect(()=>{let e=c.current;return()=>{wT(e)}},[]),i},ET=e=>e.isStreaming?e.throttledTextContent:e.textContent,DT=e=>!e.isFinalized&&e.displayTextContent.trim().length===0?!1:e.displayTextContent.trim().length>0,OT=e=>{let t=(0,Q.c)(44),{result:n}=e,{t:r}=ot(),[i,a]=Z.useState(!1),o=Z.useRef(null),s,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>()=>{o.current!==null&&window.clearTimeout(o.current)},c=[],t[0]=s,t[1]=c):(s=t[0],c=t[1]),Z.useEffect(s,c);let l;bb0:{if(n.kind===`commit`){let e;t[2]!==n.highlights||t[3]!==n.subject?(e=[n.subject,...n.highlights.map(kT)],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 ct(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=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)(ca,{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 ct(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=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)(ca,{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(AT)}):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 kT(e){return`- ${e}`}function AT(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 jT=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},MT=e=>{for(let t of jT(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},NT=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(PT,``),h=(u===`live`||d)&&(a===`streaming`||a===`cooldown`);Le(`ui.assistant_text_part.render`),h&&Le(`ui.assistant_text_part.render.streaming`);let g=ET({textContent:m,throttledTextContent:TT({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(!Wr())return;let e=n.type===`text`||n.type===`reasoning`,t=vt(v.current,{identity:_,content:g,isActive:f&&e,mode:n.type===`reasoning`?`appearance`:`changes`});v.current=t.nextState,!(!t.shouldEmit||!r)&&Yr({sessionID:r,messageID:i,partID:n.id,kind:n.type===`reasoning`?`thinking`:`text`})},b=[g,_,f,i,n.id,n.type,r],t[0]=g,t[1]=_,t[2]=f,t[3]=i,t[4]=n.id,t[5]=n.type,t[6]=r,t[7]=y,t[8]=b):(y=t[7],b=t[8]),Z.useEffect(y,b),Ie(`ui.assistant_text_part.display_len`,g.length);let x=p.time,S=!!(x&&x.end!==void 0);if(n.type!==`text`&&n.type!==`reasoning`||!DT({displayTextContent:g,isFinalized:S}))return null;let C;t[9]!==g||t[10]!==S||t[11]!==h?(C=!h&&S?MT(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)(OT,{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)(Ps,{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 PT(e,t){return t.length>e.length?t:e}var FT=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,IT=Y(`typography-meta font-medium`,FT),LT=Y(`typography-meta`,FT),RT=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(),MT=80,NT=200,PT={duration:.2,ease:`easeOut`},FT=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(),IT=e=>{if(!e)return``;let t=FT(e).replace(/\s+/g,` `).trim();if(t.length<=MT)return t;let n=t.lastIndexOf(` `,MT),r=n>0?n:MT;return`${t.substring(0,r).trimEnd()}…`},LT=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:c})=>{let{t:l}=ot(),u=s(e=>e.isMobile),d=typeof i?.end==`number`,f=a&&!d,[p,m]=Z.useState(()=>c===!0?{expanded:!0,source:`user`}:{expanded:f,source:`auto`}),h=p.source===`auto`?f&&p.expanded:p.expanded,[g,_]=Z.useState(c===!0||f),v=Z.useId(),y=Z.useRef(null),b=Z.useRef(null),x=Z.useRef(!1),S=Z.useRef(n);S.current=n;let C=Z.useMemo(()=>IT(e),[e]),w=l(h?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),T=J(()=>{_(!0),m({expanded:!h,source:`user`}),n?.(`structural`)}),E=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())});if(Z.useLayoutEffect(()=>{m(e=>e.source===`user`||e.expanded===f?e:{expanded:f,source:`auto`})},[f]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(h||a){_(!0);return}if(!g)return;if(typeof window>`u`){_(!1);return}let e=window.setTimeout(()=>{_(!1)},NT);return()=>{window.clearTimeout(e)}},[h,a,g]),Z.useLayoutEffect(()=>{let e=y.current;if(!e)return;if(b.current?.stop(),!x.current){if(x.current=!0,!h){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=Qc(e,{height:`auto`},PT);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}}e.style.overflow=`hidden`,h?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,S.current?.(`animation`));let t=Qc(e,{height:h?`auto`:`0px`},PT);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,h?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}},[h]),Z.useEffect(()=>()=>{b.current?.stop(),b.current=null},[]),!e||e.trim().length===0)return null;let D=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(Ps,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":h,"aria-controls":v,"aria-label":w,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,dm),onClick:T,onKeyDown:E,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,h&&`opacity-0`,!h&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,h&&`opacity-100`,!h&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:h?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,kT),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--oc-text-shimmer-base":`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(NC,{isMobile:u,className:`block text-[var(--tools-icon)]`})]}):h?(0,$.jsx)(`span`,{className:kT,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:kT,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,AT),style:{color:`var(--tools-description)`},children:!a&&!h&&C?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,AT),style:{color:`var(--tools-description)`,opacity:.8},title:C,children:C}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),g?(0,$.jsx)(`div`,{ref:y,id:v,"aria-hidden":!h,style:{height:h?`auto`:`0px`,overflow:h?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!h,transform:h?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:D}):(0,$.jsx)(da,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:D})]})}):null]})},RT=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=s(zT),c=n,l=c.text||c.content||``,u;t[0]===l?u=t[1]:(u=jT(l),t[0]=l,t[1]=u);let d=u,f=c.time,p=a===void 0||a!==`completed`,m=o===`live`&&p&&typeof f?.end!=`number`,h=`${i}:${n.id??`reasoning`}`,g;t[2]!==m||t[3]!==h||t[4]!==d?(g={text:d,isStreaming:m,identityKey:h},t[2]=m,t[3]=h,t[4]=d,t[5]=g):g=t[5];let _=vT(g),v=`${i}:${n.id??`reasoning`}`,y=Z.useRef(null),b=n.sessionID,x=p&&typeof f?.end!=`number`,S,C;if(t[6]!==v||t[7]!==x||t[8]!==i||t[9]!==n.id||t[10]!==b||t[11]!==_?(S=()=>{if(!Wr())return;let e=vt(y.current,{identity:v,content:_,isActive:x,mode:`appearance`});y.current=e.nextState,!(!e.shouldEmit||!b)&&Yr({sessionID:b,messageID:i,partID:n.id,kind:`thinking`})},C=[v,x,i,n.id,b,_],t[6]=v,t[7]=x,t[8]=i,t[9]=n.id,t[10]=b,t[11]=_,t[12]=S,t[13]=C):(S=t[12],C=t[13]),Z.useEffect(S,C),!_||_.trim().length===0)return null;let w=n.id||`${i}-reasoning`,T;return t[14]!==m||t[15]!==r||t[16]!==w||t[17]!==_||t[18]!==f?(T=(0,$.jsx)(LT,{text:_,variant:`thinking`,onContentChange:r,blockId:w,time:f,isStreaming:m}),t[14]=m,t[15]=r,t[16]=w,t[17]=_,t[18]=f,t[19]=T):T=t[19],T});function zT(e){return e.chatRenderMode}var BT=(e,t)=>{let n=vo(e,t)||yo(t);return n?So(n,e)?{kind:`diff`,path:_o(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},VT=e=>{let t=s.getState(),n=BT(e.directory,e.filePath);if(n.kind===`file`){uc(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)},HT=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),c=Z.useRef(null),l=Ph(),u=we(UT),d=l.directory||u,f=ls(d),p;if(t[0]!==n||t[1]!==f){bb0:{if(f!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],p=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],p=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&eg.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],p=e;break bb0}p=ig(e)}t[0]=n,t[1]=f,t[2]=p}else p=t[2];let m=p;if(m.length===0)return null;let h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{let e=c.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=h):h=t[6];let g=h,_;t[7]!==d||t[8]!==l?(_=e=>{if(!d)return;let t=s.getState();VT({directory:d,filePath:e.path,sessionId:l.sessionId,mobile:t.isMobile}),i(!1)},t[7]=d,t[8]=l,t[9]=_):_=t[9];let v=_,y=m.length,b=`${y} file${y===1?``:`s`}`,x=`${b} changed in this turn`,S;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=S):S=t[10];let C;t[11]===b?C=t[12]:(C=(0,$.jsx)(`span`,{className:`message-footer__label`,children:b}),t[11]=b,t[12]=C);let w;t[13]===r?w=t[14]:(w=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=w);let T;t[15]!==x||t[16]!==C||t[17]!==w?(T=(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(he,{render:(0,$.jsxs)(`button`,{ref:c,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":x,onPointerDownCapture:g,onFocusCapture:g,children:[S,C,w]})})}),t[15]=x,t[16]=C,t[17]=w,t[18]=T):T=t[18];let E;t[19]===b?E=t[20]:(E=(0,$.jsxs)(Va,{children:[b,` changed in this turn`]}),t[19]=b,t[20]=E);let D;t[21]!==T||t[22]!==E?(D=(0,$.jsxs)(Ha,{children:[T,E]}),t[21]=T,t[22]=E,t[23]=D):D=t[23];let O=a||void 0,k;t[24]!==m||t[25]!==d||t[26]!==v?(k=(0,$.jsx)(_e,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(me,{style:gg,className:`${hg} 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)(mg,{files:m,currentDirectory:d,onOpenFile:v})})}),t[24]=m,t[25]=d,t[26]=v,t[27]=k):k=t[27];let A;t[28]!==O||t[29]!==k?(A=(0,$.jsx)(xe,{container:O,children:k}),t[28]=O,t[29]=k,t[30]=A):A=t[30];let j;return t[31]!==r||t[32]!==D||t[33]!==A?(j=(0,$.jsxs)(ge,{open:r,onOpenChange:i,children:[D,A]}),t[31]=r,t[32]=D,t[33]=A,t[34]=j):j=t[34],j});HT.displayName=`TurnChangedFilesDropdown`;function UT(e){return e.currentDirectory}var WT=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,GT=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},KT=e=>e.type!==`tool`||WT(e)?!1:!GT(e),qT=e=>{let t=0;for(let n of e)KT(n)&&(t+=1);return t},JT=(e,t)=>e===`stop`&&qT(t)===0,YT=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},XT=(e,t,n)=>{if(n||!JT(e,t))return!1;for(let e of t)if(YT(e))return!0;return!1},ZT=e=>e===`streaming`||e===`cooldown`,QT=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,$T=e=>e.error||e.isLastAssistantInTurn===!1?!1:JT(e.finish,e.parts)?!0:!ZT(e.streamPhase)||typeof e.finish==`string`&&e.finish!==`stop`?!1:qT(e.parts)===0,eE=e=>ZT(e.streamPhase)?$T(e):!1,tE=3e4,nE=new Map,rE=new Map;async function iE(e){let t=Date.now(),n=nE.get(e);if(n&&t-n.checkedAt<tE)return n.available;let r=rE.get(e);if(r)return r;let i=(async()=>{try{let t=await V(`/api/tts/status`);if(!t.ok)return nE.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return nE.set(e,{available:n,checkedAt:Date.now()}),n}catch{return nE.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{rE.delete(e)}})();return rE.set(e,i),i}var aE=null;function oE(){return aE||=new(window.AudioContext||window.webkitAudioContext),aE}function sE(e={}){let r=e.enabled??!0,i=e.availabilityMode??`auto`,[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=Qr(e=>e.currentProviderId),h=Qr(e=>e.currentModelId),g=Qr(e=>e.openaiApiKey),_=Qr(e=>e.openaiCompatibleUrl),v=Qr(e=>e.openaiCompatibleApiKey),y=(0,Z.useCallback)(async()=>{let e=++p.current,t=n(),a=r=>(e===p.current&&n()===t&&c(r),r);if(!r)return a(!1);let o=!!(g&&g.trim().length>0),s=!!(_&&_.trim().length>0);if(i===`openai-compatible`)return a(s);if(o||i===`auto`&&s)return a(!0);try{return a(await iE(t))}catch{return a(!1)}},[i,r,g,_]);(0,Z.useEffect)(()=>{y()},[y]),(0,Z.useEffect)(()=>t(()=>{y()}),[y]);let b=(0,Z.useCallback)(()=>{let e=f.current;if(f.current=null,e?.abort.abort(),d.current){try{d.current.onended=null,d.current.stop()}catch{}d.current=null}o(!1)},[]),x=(0,Z.useCallback)(async()=>{try{let e=oE();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useServerTTS] Failed to unlock audio:`,e)}},[]),S=(0,Z.useCallback)(async(e,t)=>{if(b(),!e.trim()){u(`No text to speak`),t?.onError?.(`No text to speak`);return}u(null);let n={abort:new AbortController};f.current=n;try{let r=oE();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),a=r.createBufferSource();a.buffer=i,a.connect(r.destination),a.start(0);let s=t?.voice||`nova`,c=await V(`/api/tts/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:s,model:t?.model||void 0,speed:t?.speed||.9,instructions:t?.instructions,summarize:!1,providerId:t?.providerId||m||void 0,modelId:t?.modelId||h||void 0,apiKey:t?.baseURL?v||void 0:g||void 0,baseURL:t?.baseURL||void 0}),signal:n.abort.signal});if(f.current!==n)return;if(!c.ok){let e=await c.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${c.status}`)}let l=await(await c.blob()).arrayBuffer();if(f.current!==n)return;let u=await r.decodeAudioData(l);if(f.current!==n)return;let p=r.createBufferSource();p.buffer=u;let _=t?.pitch??1;_!==1&&(p.detune.value=(_-1)*1200);let y=t?.volume??1,b=r.createGain();if(b.gain.value=y,p.connect(b),b.connect(r.destination),d.current=p,p.onended=()=>{f.current===n&&d.current===p&&(o(!1),d.current=null,f.current=null,t?.onEnd?.())},o(!0),t?.onStart?.(),f.current!==n||d.current!==p)return;p.start(0)}catch(e){if(e.name===`AbortError`||f.current!==n)return;let r=e instanceof Error?e.message:`Failed to speak`;console.error(`[useServerTTS] Error:`,r),u(r),t?.onError?.(r),o(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[b,m,h,g,v]);return(0,Z.useEffect)(()=>()=>{b()},[b]),{isPlaying:a,isAvailable:s,error:l,speak:S,stop:b,checkAvailability:y,unlockAudio:x}}var cE=3e4,lE=null,uE=null;async function dE(){return lE&&Date.now()-lE.checkedAt<cE?lE:uE||(uE=(async()=>{try{let e=await V(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return lE=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return lE=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return lE=e,e}finally{uE=null}})(),uE)}var fE=null;function pE(){return fE||=new(window.AudioContext||window.webkitAudioContext),fE}function mE(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=pE();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 m=(0,Z.useCallback)(()=>{if(u.current){try{u.current.stop()}catch{}u.current=null}d.current&&=(d.current.abort(),null),r(!1)},[]),h=(0,Z.useCallback)(async(e,t)=>{if(m(),!e.trim()){l(`No text to speak`),t?.onError?.(`No text to speak`);return}l(null);try{d.current=new AbortController;let n=await V(`/api/tts/say/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:t?.voice||`Samantha`,rate:t?.rate||200}),signal:d.current.signal});if(!n.ok){let e=await n.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${n.status}`)}let i=await n.blob(),a=await i.arrayBuffer();i.size;let o=pE();o.state===`suspended`&&await o.resume();let s=await o.decodeAudioData(a),c=o.createBufferSource();c.buffer=s,c.connect(o.destination),u.current=c,c.onended=()=>{r(!1),u.current=null,t?.onEnd?.()},r(!0),t?.onStart?.(),c.start(0)}catch(e){if(e.name===`AbortError`)return;let n=e instanceof Error?e.message:`Failed to speak`;console.error(`[useSayTTS] Error:`,n),l(n),t?.onError?.(n),r(!1)}},[m]);return(0,Z.useEffect)(()=>()=>{m()},[m]),{isPlaying:n,isAvailable:i,voices:o,error:c,speak:h,stop:m,checkAvailability:p,unlockAudio:f}}function hE(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 gE=600,_E=`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 vE(e,t){try{let n=await V(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:_E,...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 yE(){let[e,t]=(0,Z.useState)(!1),n=Qr(e=>e.voiceProvider),r=Qr(e=>e.speechRate),i=Qr(e=>e.speechPitch),a=Qr(e=>e.speechVolume),o=Qr(e=>e.sayVoice),s=Qr(e=>e.localTtsVoiceId),c=Qr(e=>e.browserVoice),l=Qr(e=>e.openaiVoice),u=Qr(e=>e.openaiCompatibleVoice),d=Qr(e=>e.openaiCompatibleUrl),f=Qr(e=>e.openaiCompatibleTtsModel),p=Qr(e=>e.showMessageTTSButtons),m=Qr(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=sE({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=mE({enabled:_}),{speak:w,stop:T}=Qa(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),no.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>=gE){let{currentProviderId:t,currentModelId:n}=Qr.getState(),r=await vE(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=hE(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 no.waitForVoices(),await no.resumeAudioContext(),await no.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 bE=8,xE=280,SE=null;kr(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),SE&&(0,el.flushSync)(SE)});var CE=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(`.`)),wE=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(),zT=80,BT=200,VT={duration:.2,ease:`easeOut`},HT=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(),UT=e=>{if(!e)return``;let t=HT(e).replace(/\s+/g,` `).trim();if(t.length<=zT)return t;let n=t.lastIndexOf(` `,zT),r=n>0?n:zT;return`${t.substring(0,r).trimEnd()}…`},WT=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:c})=>{let{t:l}=ot(),u=s(e=>e.isMobile),d=typeof i?.end==`number`,f=a&&!d,[p,m]=Z.useState(()=>c===!0?{expanded:!0,source:`user`}:{expanded:f,source:`auto`}),h=p.source===`auto`?f&&p.expanded:p.expanded,[g,_]=Z.useState(c===!0||f),v=Z.useId(),y=Z.useRef(null),b=Z.useRef(null),x=Z.useRef(!1),S=Z.useRef(n);S.current=n;let C=Z.useMemo(()=>UT(e),[e]),w=l(h?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),T=J(()=>{_(!0),m({expanded:!h,source:`user`}),n?.(`structural`)}),E=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())});if(Z.useLayoutEffect(()=>{m(e=>e.source===`user`||e.expanded===f?e:{expanded:f,source:`auto`})},[f]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(h||a){_(!0);return}if(!g)return;if(typeof window>`u`){_(!1);return}let e=window.setTimeout(()=>{_(!1)},BT);return()=>{window.clearTimeout(e)}},[h,a,g]),Z.useLayoutEffect(()=>{let e=y.current;if(!e)return;if(b.current?.stop(),!x.current){if(x.current=!0,!h){e.style.height=`0px`,e.style.overflow=`hidden`;return}e.style.height=`0px`,e.style.overflow=`hidden`;let t=Qc(e,{height:`auto`},VT);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,e.style.overflow=`visible`,e.style.height=`auto`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}}e.style.overflow=`hidden`,h?e.style.height=`0px`:(e.style.height=`${e.scrollHeight}px`,S.current?.(`animation`));let t=Qc(e,{height:h?`auto`:`0px`},VT);return b.current=t,t.finished.then(()=>{b.current===t&&(b.current=null,h?(e.style.overflow=`visible`,e.style.height=`auto`):e.style.overflow=`hidden`)}).catch(()=>void 0),()=>{t.stop(),b.current===t&&(b.current=null)}},[h]),Z.useEffect(()=>()=>{b.current?.stop(),b.current=null},[]),!e||e.trim().length===0)return null;let D=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(Ps,{content:e,messageId:r,isAnimated:!1,isStreaming:a,variant:`reasoning`})}),o?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:o})}):null]});return(0,$.jsxs)(`div`,{"data-reasoning-block-id":r,"data-message-text-export-root":`true`,children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":h,"aria-controls":v,"aria-label":w,"data-mobile-press-feedback":`soft`,className:Y(`group/tool flex gap-1.5 cursor-pointer items-center`,dm),onClick:T,onKeyDown:E,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`relative h-3.5 w-3.5 flex-shrink-0 cursor-pointer`,children:[(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity`,h&&`opacity-0`,!h&&`group-hover/tool:opacity-0`),style:{color:`var(--tools-icon)`},children:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`absolute inset-0 transition-opacity flex items-center justify-center`,h&&`opacity-100`,!h&&`opacity-0 group-hover/tool:opacity-100`),style:{color:`var(--tools-icon)`},children:h?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`})})]}),a?(0,$.jsxs)(`span`,{className:Y(`flex items-center gap-1`,IT),style:{color:`var(--tools-title)`},children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,style:{"--oc-text-shimmer-base":`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}),(0,$.jsx)(BC,{isMobile:u,className:`block text-[var(--tools-icon)]`})]}):h?(0,$.jsx)(`span`,{className:IT,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:IT,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thought`)})]}),(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1 flex-1 min-w-0`,LT),style:{color:`var(--tools-description)`},children:!a&&!h&&C?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,LT),style:{color:`var(--tools-description)`,opacity:.8},title:C,children:C}):(0,$.jsx)(`span`,{className:`min-w-0 flex-1`})})]}),g?(0,$.jsx)(`div`,{ref:y,id:v,"aria-hidden":!h,style:{height:h?`auto`:`0px`,overflow:h?`visible`:`hidden`,overflowAnchor:`none`},children:(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3 pb-1 pt-0.5`,style:{opacity:+!!h,transform:h?`translateY(0)`:`translateY(-4px)`,transition:`opacity 180ms ease-out, transform 180ms ease-out`},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a?(0,$.jsx)(`div`,{className:`p-0`,children:D}):(0,$.jsx)(da,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:D})]})}):null]})},GT=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=s(KT),c=n,l=c.text||c.content||``,u;t[0]===l?u=t[1]:(u=RT(l),t[0]=l,t[1]=u);let d=u,f=c.time,p=a===void 0||a!==`completed`,m=o===`live`&&p&&typeof f?.end!=`number`,h=`${i}:${n.id??`reasoning`}`,g;t[2]!==m||t[3]!==h||t[4]!==d?(g={text:d,isStreaming:m,identityKey:h},t[2]=m,t[3]=h,t[4]=d,t[5]=g):g=t[5];let _=TT(g),v=`${i}:${n.id??`reasoning`}`,y=Z.useRef(null),b=n.sessionID,x=p&&typeof f?.end!=`number`,S,C;if(t[6]!==v||t[7]!==x||t[8]!==i||t[9]!==n.id||t[10]!==b||t[11]!==_?(S=()=>{if(!Wr())return;let e=vt(y.current,{identity:v,content:_,isActive:x,mode:`appearance`});y.current=e.nextState,!(!e.shouldEmit||!b)&&Yr({sessionID:b,messageID:i,partID:n.id,kind:`thinking`})},C=[v,x,i,n.id,b,_],t[6]=v,t[7]=x,t[8]=i,t[9]=n.id,t[10]=b,t[11]=_,t[12]=S,t[13]=C):(S=t[12],C=t[13]),Z.useEffect(S,C),!_||_.trim().length===0)return null;let w=n.id||`${i}-reasoning`,T;return t[14]!==m||t[15]!==r||t[16]!==w||t[17]!==_||t[18]!==f?(T=(0,$.jsx)(WT,{text:_,variant:`thinking`,onContentChange:r,blockId:w,time:f,isStreaming:m}),t[14]=m,t[15]=r,t[16]=w,t[17]=_,t[18]=f,t[19]=T):T=t[19],T});function KT(e){return e.chatRenderMode}var qT=(e,t)=>{let n=vo(e,t)||yo(t);return n?So(n,e)?{kind:`diff`,path:_o(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},JT=e=>{let t=s.getState(),n=qT(e.directory,e.filePath);if(n.kind===`file`){uc(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)},YT=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),c=Z.useRef(null),l=Ph(),u=we(XT),d=l.directory||u,f=ls(d),p;if(t[0]!==n||t[1]!==f){bb0:{if(f!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],p=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],p=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&eg.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],p=e;break bb0}p=ig(e)}t[0]=n,t[1]=f,t[2]=p}else p=t[2];let m=p;if(m.length===0)return null;let h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{let e=c.current?.closest(`[data-slot="dialog-content"], [role="dialog"]`);o(e||null)},t[6]=h):h=t[6];let g=h,_;t[7]!==d||t[8]!==l?(_=e=>{if(!d)return;let t=s.getState();JT({directory:d,filePath:e.path,sessionId:l.sessionId,mobile:t.isMobile}),i(!1)},t[7]=d,t[8]=l,t[9]=_):_=t[9];let v=_,y=m.length,b=`${y} file${y===1?``:`s`}`,x=`${b} changed in this turn`,S;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(X,{name:`file-edit`,className:`h-3.5 w-3.5`}),t[10]=S):S=t[10];let C;t[11]===b?C=t[12]:(C=(0,$.jsx)(`span`,{className:`message-footer__label`,children:b}),t[11]=b,t[12]=C);let w;t[13]===r?w=t[14]:(w=r?(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`}),t[13]=r,t[14]=w);let T;t[15]!==x||t[16]!==C||t[17]!==w?(T=(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(he,{render:(0,$.jsxs)(`button`,{ref:c,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":x,onPointerDownCapture:g,onFocusCapture:g,children:[S,C,w]})})}),t[15]=x,t[16]=C,t[17]=w,t[18]=T):T=t[18];let E;t[19]===b?E=t[20]:(E=(0,$.jsxs)(Va,{children:[b,` changed in this turn`]}),t[19]=b,t[20]=E);let D;t[21]!==T||t[22]!==E?(D=(0,$.jsxs)(Ha,{children:[T,E]}),t[21]=T,t[22]=E,t[23]=D):D=t[23];let O=a||void 0,k;t[24]!==m||t[25]!==d||t[26]!==v?(k=(0,$.jsx)(_e,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(me,{style:gg,className:`${hg} 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)(mg,{files:m,currentDirectory:d,onOpenFile:v})})}),t[24]=m,t[25]=d,t[26]=v,t[27]=k):k=t[27];let A;t[28]!==O||t[29]!==k?(A=(0,$.jsx)(xe,{container:O,children:k}),t[28]=O,t[29]=k,t[30]=A):A=t[30];let j;return t[31]!==r||t[32]!==D||t[33]!==A?(j=(0,$.jsxs)(ge,{open:r,onOpenChange:i,children:[D,A]}),t[31]=r,t[32]=D,t[33]=A,t[34]=j):j=t[34],j});YT.displayName=`TurnChangedFilesDropdown`;function XT(e){return e.currentDirectory}var ZT=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,QT=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},$T=e=>e.type!==`tool`||ZT(e)?!1:!QT(e),eE=e=>{let t=0;for(let n of e)$T(n)&&(t+=1);return t},tE=(e,t)=>e===`stop`&&eE(t)===0,nE=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},rE=(e,t,n)=>{if(n||!tE(e,t))return!1;for(let e of t)if(nE(e))return!0;return!1},iE=e=>e===`streaming`||e===`cooldown`,aE=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,oE=e=>e.error||e.isLastAssistantInTurn===!1?!1:tE(e.finish,e.parts)?!0:!iE(e.streamPhase)||typeof e.finish==`string`&&e.finish!==`stop`?!1:eE(e.parts)===0,sE=e=>iE(e.streamPhase)?oE(e):!1,cE=3e4,lE=new Map,uE=new Map;async function dE(e){let t=Date.now(),n=lE.get(e);if(n&&t-n.checkedAt<cE)return n.available;let r=uE.get(e);if(r)return r;let i=(async()=>{try{let t=await V(`/api/tts/status`);if(!t.ok)return lE.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return lE.set(e,{available:n,checkedAt:Date.now()}),n}catch{return lE.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{uE.delete(e)}})();return uE.set(e,i),i}var fE=null;function pE(){return fE||=new(window.AudioContext||window.webkitAudioContext),fE}function mE(e={}){let r=e.enabled??!0,i=e.availabilityMode??`auto`,[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=Qr(e=>e.currentProviderId),h=Qr(e=>e.currentModelId),g=Qr(e=>e.openaiApiKey),_=Qr(e=>e.openaiCompatibleUrl),v=Qr(e=>e.openaiCompatibleApiKey),y=(0,Z.useCallback)(async()=>{let e=++p.current,t=n(),a=r=>(e===p.current&&n()===t&&c(r),r);if(!r)return a(!1);let o=!!(g&&g.trim().length>0),s=!!(_&&_.trim().length>0);if(i===`openai-compatible`)return a(s);if(o||i===`auto`&&s)return a(!0);try{return a(await dE(t))}catch{return a(!1)}},[i,r,g,_]);(0,Z.useEffect)(()=>{y()},[y]),(0,Z.useEffect)(()=>t(()=>{y()}),[y]);let b=(0,Z.useCallback)(()=>{let e=f.current;if(f.current=null,e?.abort.abort(),d.current){try{d.current.onended=null,d.current.stop()}catch{}d.current=null}o(!1)},[]),x=(0,Z.useCallback)(async()=>{try{let e=pE();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch(e){console.error(`[useServerTTS] Failed to unlock audio:`,e)}},[]),S=(0,Z.useCallback)(async(e,t)=>{if(b(),!e.trim()){u(`No text to speak`),t?.onError?.(`No text to speak`);return}u(null);let n={abort:new AbortController};f.current=n;try{let r=pE();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),a=r.createBufferSource();a.buffer=i,a.connect(r.destination),a.start(0);let s=t?.voice||`nova`,c=await V(`/api/tts/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:s,model:t?.model||void 0,speed:t?.speed||.9,instructions:t?.instructions,summarize:!1,providerId:t?.providerId||m||void 0,modelId:t?.modelId||h||void 0,apiKey:t?.baseURL?v||void 0:g||void 0,baseURL:t?.baseURL||void 0}),signal:n.abort.signal});if(f.current!==n)return;if(!c.ok){let e=await c.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${c.status}`)}let l=await(await c.blob()).arrayBuffer();if(f.current!==n)return;let u=await r.decodeAudioData(l);if(f.current!==n)return;let p=r.createBufferSource();p.buffer=u;let _=t?.pitch??1;_!==1&&(p.detune.value=(_-1)*1200);let y=t?.volume??1,b=r.createGain();if(b.gain.value=y,p.connect(b),b.connect(r.destination),d.current=p,p.onended=()=>{f.current===n&&d.current===p&&(o(!1),d.current=null,f.current=null,t?.onEnd?.())},o(!0),t?.onStart?.(),f.current!==n||d.current!==p)return;p.start(0)}catch(e){if(e.name===`AbortError`||f.current!==n)return;let r=e instanceof Error?e.message:`Failed to speak`;console.error(`[useServerTTS] Error:`,r),u(r),t?.onError?.(r),o(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[b,m,h,g,v]);return(0,Z.useEffect)(()=>()=>{b()},[b]),{isPlaying:a,isAvailable:s,error:l,speak:S,stop:b,checkAvailability:y,unlockAudio:x}}var hE=3e4,gE=null,_E=null;async function vE(){return gE&&Date.now()-gE.checkedAt<hE?gE:_E||(_E=(async()=>{try{let e=await V(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return gE=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return gE=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return gE=e,e}finally{_E=null}})(),_E)}var yE=null;function bE(){return yE||=new(window.AudioContext||window.webkitAudioContext),yE}function xE(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=bE();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 vE();return a(e.available),s(e.voices),e.available}catch{return a(!1),s([]),!1}},[t]);(0,Z.useEffect)(()=>{p()},[p]);let m=(0,Z.useCallback)(()=>{if(u.current){try{u.current.stop()}catch{}u.current=null}d.current&&=(d.current.abort(),null),r(!1)},[]),h=(0,Z.useCallback)(async(e,t)=>{if(m(),!e.trim()){l(`No text to speak`),t?.onError?.(`No text to speak`);return}l(null);try{d.current=new AbortController;let n=await V(`/api/tts/say/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e.trim(),voice:t?.voice||`Samantha`,rate:t?.rate||200}),signal:d.current.signal});if(!n.ok){let e=await n.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${n.status}`)}let i=await n.blob(),a=await i.arrayBuffer();i.size;let o=bE();o.state===`suspended`&&await o.resume();let s=await o.decodeAudioData(a),c=o.createBufferSource();c.buffer=s,c.connect(o.destination),u.current=c,c.onended=()=>{r(!1),u.current=null,t?.onEnd?.()},r(!0),t?.onStart?.(),c.start(0)}catch(e){if(e.name===`AbortError`)return;let n=e instanceof Error?e.message:`Failed to speak`;console.error(`[useSayTTS] Error:`,n),l(n),t?.onError?.(n),r(!1)}},[m]);return(0,Z.useEffect)(()=>()=>{m()},[m]),{isPlaying:n,isAvailable:i,voices:o,error:c,speak:h,stop:m,checkAvailability:p,unlockAudio:f}}function SE(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 CE=600,wE=`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 TE(e,t){try{let n=await V(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:wE,...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 EE(){let[e,t]=(0,Z.useState)(!1),n=Qr(e=>e.voiceProvider),r=Qr(e=>e.speechRate),i=Qr(e=>e.speechPitch),a=Qr(e=>e.speechVolume),o=Qr(e=>e.sayVoice),s=Qr(e=>e.localTtsVoiceId),c=Qr(e=>e.browserVoice),l=Qr(e=>e.openaiVoice),u=Qr(e=>e.openaiCompatibleVoice),d=Qr(e=>e.openaiCompatibleUrl),f=Qr(e=>e.openaiCompatibleTtsModel),p=Qr(e=>e.showMessageTTSButtons),m=Qr(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=mE({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=xE({enabled:_}),{speak:w,stop:T}=Qa(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),no.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>=CE){let{currentProviderId:t,currentModelId:n}=Qr.getState(),r=await TE(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=SE(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 no.waitForVoices(),await no.resumeAudioContext(),await no.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 DE=8,OE=280,kE=null;kr(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),kE&&(0,el.flushSync)(kE)});var AE=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(`.`)),jE=e=>e.replace(/\r\n?/g,`
|
|
6565
|
+
`),ME=e=>jE(e).trim(),NE=(e,t)=>{if(e.contains(t))return!0;let n=t instanceof ShadowRoot?t:t.getRootNode();return n instanceof ShadowRoot&&e.contains(n.host)},PE=e=>{let t=[],n=e=>{for(let r of e.querySelectorAll(`*`))r.shadowRoot&&(t.push(r.shadowRoot),n(r.shadowRoot))};return n(e),t},FE=(e,t)=>{let n=PE(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),NE(t,e.commonAncestorContainer))return e}if(e.rangeCount===0)return null;let i=e.getRangeAt(0);return NE(t,i.commonAncestorContainer)?i:null},IE=e=>e.replace(/\s+/g,` `).trim(),LE=e=>{if(e.nodeType===Node.TEXT_NODE)return IE(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase(),r=Array.from(t.childNodes).map(e=>LE(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},RE=(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=>LE(e)).join(``).replace(/\s+/g,` `).trim();return i?`${r}${i}`:``}).filter(Boolean).join(`
|
|
6567
|
+
`),zE=e=>{if(e.nodeType===Node.TEXT_NODE)return ME(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${jE(e?.textContent||t.textContent||``).replace(/\n$/,``)}\n\`\`\``}if(n===`code`){let e=jE(t.textContent||``).trim();return e?`\`${e.replace(/`/g,"\\`")}\``:``}if(n===`ul`)return RE(t,!1);if(n===`ol`)return RE(t,!0);if(n===`blockquote`)return ME(Array.from(t.childNodes).map(e=>zE(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=ME(Array.from(t.childNodes).map(e=>LE(e)).join(``));return r?`${`#`.repeat(e)} ${r}`:``}if(n===`p`||n===`div`||n===`li`)return ME(Array.from(t.childNodes).map(e=>LE(e)).join(``));let r=Array.from(t.childNodes).map(e=>zE(e)).filter(e=>e.length>0);return r.length>0?r.join(`
|
|
6571
6571
|
|
|
6572
|
-
`):
|
|
6572
|
+
`):ME(Array.from(t.childNodes).map(e=>LE(e)).join(``))},BE=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!AE.has(t.tagName.toLowerCase())}),VE=(e,t)=>{let n=e.cloneContents();if(BE(n)){let e=ME(Array.from(n.childNodes).map(e=>LE(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>zE(e)).filter(e=>e.length>0).join(`
|
|
6573
6573
|
|
|
6574
|
-
`).trim()||TE(t)},FE=({containerRef:e})=>{let{t}=ot(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,c]=Z.useState(``),l=Z.useRef(!1),[u,d]=Z.useState(!1),f=Z.useRef(null),p=Z.useRef(xE),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(null),_=Z.useRef(!1),v=Zr(e=>e.createSession),y=on(e=>e.setPendingInputText),b=s(e=>e.isMobile),x=Fh(Ph()).textSelectionMutation;Z.useEffect(()=>{_.current=n.show},[n.show]),Z.useEffect(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]);let S=Z.useCallback(()=>{m.current=null,SE===S&&(SE=null),_.current&&=(h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),d(!1),r(e=>({...e,show:!1})),a(``),c(``),!1)},[]);Z.useEffect(()=>()=>{SE===S&&(SE=null)},[S]);let C=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=p.current/2,r=bE+n,i=t-bE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),w=Z.useCallback(()=>{if(!m.current)return;SE!==S&&(SE?.(),SE=S);let{plainText:e,markdownText:t,rect:i}=m.current,o=!n.show,s=b?i.left+i.width/2:C(i.left+i.width/2),l=i.top-10;a(e),c(t),r({x:s,y:l,show:!0}),_.current=!0,o&&(d(!0),h.current!==null&&window.cancelAnimationFrame(h.current),h.current=window.requestAnimationFrame(()=>{d(!1),h.current=null}))},[C,S,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!f.current)return;let e=f.current.offsetWidth;!Number.isFinite(e)||e<=0||e===p.current||(p.current=e,r(e=>({...e,x:C(e.x)})))},[C,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:C(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[C,b,n.show]);let T=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||S();return}let r=TE(t.toString());if(!r){l.current||S();return}let i=OE(t,n);if(!i){l.current||S();return}let a=i.getBoundingClientRect();m.current={plainText:r,markdownText:PE(i,r),rect:a},l.current||w()},[e,S,w]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,S()},r=()=>{l.current=!1,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{g.current=null,T()},10)},i=new Set,a=()=>{for(let e of DE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,T))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,T),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{f.current&&!f.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&S()};return document.addEventListener(`mousedown`,s),()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,T);document.removeEventListener(`selectionchange`,T),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,T,S,w]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{f.current&&e.target instanceof Node&&f.current.contains(e.target)||S()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,S]);let E=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;y(t,`append`),S(),window.getSelection()?.removeAllRanges()},[y,S]),D=Z.useCallback(()=>{E(o)},[E,o]);Z.useEffect(()=>{let t=t=>{if(!x||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=OE(n,r);i&&(t.preventDefault(),E(PE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[E,x,e]);let O=Z.useCallback(async()=>{i&&(await v(void 0,null,null)&&y(i,`replace`),S(),window.getSelection()?.removeAllRanges())},[i,v,y,S]),k=Z.useCallback(async()=>{if(!i)return;let e=await ct(i);e.ok||console.error(`Failed to copy:`,e.error),S(),window.getSelection()?.removeAllRanges()},[i,S]);return n.show?b?(0,el.createPortal)((0,$.jsx)(`div`,{ref:f,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,el.createPortal)((0,$.jsx)(`div`,{ref:f,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(Jp,{shortcut:`⌘+I`})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},IE=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),LE=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),IE(e,n)},RE=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),zE=(e,t)=>{if(!RE(e))return``;let n=new Date(e),r=new Date,i=oo(n,t),a=st(),o=lt.getState().dictionary;if(IE(n,r))return i;if(LE(n,r))return ut(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},BE=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,VE=e=>e,HE=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=VE(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},UE=(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-HE(n);return!Number.isFinite(a)||a<=0?null:a},WE=e=>{let t=UE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=BE(e.outputTokens)+BE(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},GE=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`},KE=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},qE=[`search`,`read`,`list`];function JE(e){let t=YC(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function YE(e){let t={read:0,search:0,list:0};for(let n of e){let e=JE(n);e&&(t[e]+=1)}return t}function XE(e){return JC(e)}function ZE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!GC(e.toolName):e.kind!=null||e.type!=null}function QE(e,t,n){for(let r=t;r<e.length;r+=1)if(ZE(n(e[r])))return!0;return!1}function $E(e){return`parts`in e?e.parts.some(e=>XE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>XE(e))}function eD(e,t,n){let r=[],i=t;for(;i<e.length&&GC(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`,nD=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=ot(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??$E({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=YE(u.map(e=>e.tool)),p=qE.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=J(()=>{c(e=>!e)}),h=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:um(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,dm),onClick:m,onKeyDown:h,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,v,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(NC,{isMobile:t,label:o(`chat.contextGroup.exploring`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,v,tD,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:_}),p?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,v,tD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(KE,{text:p,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:`relative ml-2 pl-3 pt-0.5`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a]}):null]})};function rD(e,t,n){let r=[],i=t;for(;i<e.length&&KC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var iD=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=iD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=iD(e.name);if(t)return t;let r=iD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=iD(n.output.name);if(e)return e}return null}function oD(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 sD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,cD=({activities:e,isMobile:t,children:n})=>{let{t:r}=ot(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>JC(e)),{joinedVisible:l,hiddenCount:u}=oD(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:um(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`,dm),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)(NC,{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`,sD,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`,sD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(KE,{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]})},lD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:c}=e,l=s(uD),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==c||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(ET,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:c})}),t[4]=l,t[5]=r,t[6]=i,t[7]=c,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function uD(e){return e.chatRenderMode}var dD=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},fD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,pD=Y(`typography-meta font-medium`,fD),mD=Y(`typography-meta`,fD),hD=[],gD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},_D=e=>{let t=new Set;for(let n of e)gD(n)&&n.messageId&&t.add(n.messageId);return[...t]},vD=(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}),yD=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=nc(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},bD=e=>e,xD=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},SD=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},CD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},wD=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},TD=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=wD(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`}`},ED=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=TD(n.todos);if(e)return e}if(Array.isArray(r)){let e=TD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=TD(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=TD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=TD(e.todos);if(t)return t}}catch{}return null},DD=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)},OD=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(Zx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,mD),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`,mD),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)(Zx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},kD=e=>{let t=yo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},AD=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`?ED(e):xD(e)},jD=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}},MD=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=um(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)(oT,{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&&zS([e.activity.part],[t.activity.part])),ND=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=um(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(ID,{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&&FD(e.activities,t.activities)),PD=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!gt(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(GC(i)){let r=eD(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:QE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(KC(i)){let r=rD(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(UC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(HC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(WC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},FD=(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||!zS([r.part],[i.part]))return!1}return!0},ID=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ot(),c=s(BD),l=ic(n,o),u;t[0]===n?u=t[1]:(u=Qx(n),t[0]=n,t[1]=u);let d=u,f;t[2]===n?f=t[3]:(f=n.toLowerCase(),t[2]=n,t[3]=f);let p=f===`read`,m=Z.useContext(Oo),h=$h(),g=we(VD),_=Ph(),v=_.kind===`embedded`?_.directory:g,y;t[4]===n?y=t[5]:(y=n.toLowerCase(),t[4]=n,t[5]=y);let b=y===`skill`,x;t[6]===b?x=t[7]:(x={enabled:b},t[6]=b,t[7]=x);let S=Tr(x),C;t[8]===S.data?C=t[9]:(C=S.data??[],t[8]=S.data,t[9]=C);let w=C,T;t[10]===w?T=t[11]:(T=new Map(w.map(HD)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||JC(D.part),k;t[12]===D?k=t[13]:(k=D?AD(D):null,t[12]=D,t[13]=k);let A=k,j;if(t[14]!==A||t[15]!==D||t[16]!==E||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!D||!A){j=null;break bb0}let e=E.get(A)?.path||CD(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=kD(e);if(!r){j=null;break bb0}let i;t[19]!==A||t[20]!==r?(i={name:A,path:r},t[19]=A,t[20]=r,t[21]=i):i=t[21],j=i}t[14]=A,t[15]=D,t[16]=E,t[17]=n,t[18]=j}else j=t[18];let M=j,N;if(t[22]!==v||t[23]!==p||t[24]!==D){bb1:{if(!p||!D){N=null;break bb1}let e=SD(D);if(!e){N=null;break bb1}let n=_o(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=DD(D),t[26]=D,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],N=i}t[22]=v,t[23]=p,t[24]=D,t[25]=N}else N=t[25];let P=N,F;t[32]!==v||t[33]!==h||t[34]!==m?(F=(e,t)=>{if(!v)return;let n=vo(v,e);if(!n)return;if(h){h.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(m?.editor){m.editor.openFile(n,t);return}if(!So(n,v)){uc(n,v).then(()=>{let e=s.getState(),r=v||go(v,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=s.getState(),i=go(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=J(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=yo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=s.getState(),n=v||go(``,t);e.openContextFile(n,t)};if(v&&!So(t,v)){uc(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=J(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,W=!!(P||M),ee=!!(P&&v||M),G;t[41]!==ee||t[42]!==I||t[43]!==R||t[44]!==W||t[45]!==P||t[46]!==M?(G=()=>{if(!(!W||!ee)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=ee,t[42]=I,t[43]=R,t[44]=W,t[45]=P,t[46]=M,t[47]=G):G=t[47];let K=J(G),q;t[48]===K?q=t[49]:(q=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K())},t[48]=K,t[49]=q);let te=J(q),ne=W&&ee&&`cursor-pointer`,re=W&&!ee&&`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`,dm,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=W?`soft`:void 0,oe=W?K:void 0,se=W?te:void 0,ce=W?`button`:void 0,le=W&&ee?0:void 0,ue=W&&!ee?!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=O?(0,$.jsx)(NC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,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(pD,`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]===l?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:l,children:l}),t[62]=l,t[63]=ve);let ye;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==c?(ye=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,mD),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[c?(0,$.jsx)(gd,{filePath:P.path,className:`h-3.5 w-3.5`}):null,OD(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=c,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==A||t[71]!==V?(be=V&&A?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(Zx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,mD),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=be):be=t[72];let xe;t[73]!==A||t[74]!==H?(xe=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:UD,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`,mD),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(yD,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=xe):xe=t[75];let Se;t[76]!==U||t[77]!==M?(Se=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,mD),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=Se):Se=t[78];let Ce;t[79]!==A||t[80]!==U||t[81]!==M?(Ce=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,mD),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=Ce):Ce=t[82];let Te;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Te=!p&&!V&&!H&&!U&&A?(0,$.jsx)(Zx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,mD),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=Te):Te=t[89];let Ee;return t[90]!==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]!==Se||t[103]!==Ce||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,Se,Ce,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]=Se,t[103]=Ce,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&FD(e.activities,t.activities)),LD=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)(RT,{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}),RD=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)(lD,{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}),zD=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=ot(),_=lc()??``,v=Z.useMemo(()=>_D(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?dD(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(()=>jD(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=Ct(_,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=Nt(_,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 Ct(_,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)&&gD(e)),K=ee&&!G&&!vD(t,V),q=Z.useMemo(()=>B?bD(e):hD,[e,B]),te=Z.useMemo(()=>B?PD(q):[],[B,q]),ne=Z.useMemo(()=>L||z===0?0:Math.max(0,te.length-z),[L,z,te.length]),re=Z.useMemo(()=>L||z===0?te:te.slice(-z),[L,z,te]);if((!m||I&&!O)&&te.length===0)return null;let ie=(e,t)=>{let n=(0,$.jsx)(`div`,{className:um(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ae=B?re.map((e,t)=>{switch(e.type){case`reasoning`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(LD,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(RD,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(MD,{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)(ND,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(nD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(ID,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(cD,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(ID,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(MD,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,oe=re.length>0;return m?(0,$.jsxs)(`div`,{className:um(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&&dm,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)(NC,{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)(sa,{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`)})]})]}),oe?(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)`}}),ne>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:[`+`,ne,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ae})]}):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)(ca,{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:um(c),children:ae})});function BD(e){return e.showToolFileIcons}function VD(e){return e.currentDirectory}function HD(e){return[e.name,e]}function UD(e){e.stopPropagation()}var WD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(zD,{...e}),t[0]=e,t[1]=n),n}),GD={contain:`layout`},KD={containerType:`inline-size`,containerName:`message-footer`},qD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,JD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,YD=`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`,XD=`size-3.5!`,ZD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,QD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,$D=`flex items-center gap-2`,eO=`flex items-center gap-2 text-muted-foreground`,tO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,nO=`size-3.5!`,rO=`medium`,iO=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)]`,oO=`h-7 gap-1.5`,sO=`h-6 gap-1`,cO=`text-[11px] leading-none`,lO=`size-3.5`,uO=`size-3`,dO=5,fO=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)(gd,{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=iO(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}),pO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ot(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?sO:oO,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)(fO,{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)(ca,{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}),mO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:c}=ot(),l=lc(),u=Ph(),d=u.directory||l,f=u.sessionId,p=$h(),m=s(OO),h;t[0]===r?h=t[1]:(h=r??[],t[0]=r,t[1]=h);let g=h,_;t[2]===g?_=t[3]:(_=g.slice(0,dO),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==c?(S=c(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=c,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==c?(w=c(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=c,t[9]=w):w=t[9];let T=w,E=Y(aO,o?sO:oO),D=o?uO:lO,O;t[10]===o?O=t[11]:(O=o?Y(cO,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=O);let k=O,A;t[12]===o?A=t[13]:(A=o?Y(cO,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=A);let j=A,M;t[14]===o?M=t[15]:(M=o?Y(cO,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=M);let N=M,P;t[16]!==d||t[17]!==f||t[18]!==a||t[19]!==o||t[20]!==p||t[21]!==i?(P=e=>{if(p){p.openTurnDiff(i,f,e);return}if(!o&&d){VT({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&VT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=J(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&VT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=J(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===c?V=t[35]:(V=c(`diffView.actions.reviewAria`),t[34]=c,t[35]=V);let H;t[36]===c?H=t[37]:(H=c(`diffView.actions.reviewAria`),t[36]=c,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let W=`turn-changes-${i}`,ee;t[40]===c?ee=t[41]:(ee=c(`chat.changedFiles.title`),t[40]=c,t[41]=ee);let G;t[42]!==W||t[43]!==ee||t[44]!==k?(G=(0,$.jsx)(`span`,{id:W,className:k,children:ee}),t[42]=W,t[43]=ee,t[44]=k,t[45]=G):G=t[45];let K;t[46]!==C||t[47]!==j?(K=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=K):K=t[48];let q;t[49]===D?q=t[50]:(q=Y(D,`opacity-60`),t[49]=D,t[50]=q);let te;return t[51]===q?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:q}),t[51]=q,t[52]=te),(0,$.jsxs)(`section`,{className:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,G,K,te]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(pO,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":c(`diffView.actions.reviewAria`),title:c(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),hO=e=>e.type===`subtask`,gO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},_O=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}`},vO=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=lc(),{isMobile:o}=fo(),c=Zr(kO),l=s(AO),u=Ph(),{t:f}=ot(),p;t[0]===n.description?p=t[1]:(p=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=p);let m=p,h;t[2]===n.command?h=t[3]:(h=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=h);let g=h,_;t[4]===n.agent?_=t[5]:(_=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=_);let v=_,y;t[6]===n.prompt?y=t[7]:(y=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=y);let b=y,x;t[8]===n.taskSessionID?x=t[9]:(x=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=x);let S=x,C;t[10]===n.model?C=t[11]:(C=_O(n.model),t[10]=n.model,t[11]=C);let w=C,T=!!b&&!(o&&u.kind===`primary`),E;t[12]===f?E=t[13]:(E=f(`chat.messageBody.subtask.title`),t[12]=f,t[13]=E);let D;t[14]===E?D=t[15]:(D=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:E}),t[14]=E,t[15]=D);let O;t[16]===g?O=t[17]:(O=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,g]}):null,t[16]=g,t[17]=O);let k;t[18]===v?k=t[19]:(k=v?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,v]}):null,t[18]=v,t[19]=k);let A;t[20]===w?A=t[21]:(A=w?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:w}):null,t[20]=w,t[21]=A);let j;t[22]!==k||t[23]!==A||t[24]!==D||t[25]!==O?(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D,O,k,A]}),t[22]=k,t[23]=A,t[24]=D,t[25]=O,t[26]=j):j=t[26];let M;t[27]===m?M=t[28]:(M=m?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:m}):null,t[27]=m,t[28]=M);let N;t[29]!==r||t[30]!==b||t[31]!==T||t[32]!==f?(N=T?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(jO),children:f(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==c||t[41]!==f||t[42]!==S?(P=S&&u.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=u.directory||a;e&&Ih(u,S,e,()=>{if(!ai({sessionId:S,directory:e})){if(ll()||o||d()){c(S,e);return}l(e,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=c,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},yO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=lc(),i=s(MO),{isMobile:a}=fo(),{t:o}=ot(),c;t[0]!==r||t[1]!==a?(c=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=c):c=t[2];let l=!!c,u;t[3]!==n.state||t[4]!==o?(u=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=J(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=J(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(ks,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=j);let M;t[23]!==A||t[24]!==j?(M=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[A,j]}),t[23]=A,t[24]=j,t[25]=M):M=t[25];let N;return t[26]!==w||t[27]!==M||t[28]!==y||t[29]!==b||t[30]!==x||t[31]!==S||t[32]!==C?(N=(0,$.jsxs)(`div`,{className:y,role:b,tabIndex:x,"aria-label":S,onClick:C,onKeyDown:w,children:[T,M]}),t[26]=w,t[27]=M,t[28]=y,t[29]=b,t[30]=x,t[31]=S,t[32]=C,t[33]=N):N=t[33],N},bO={background:`transparent`,backgroundColor:`transparent`},xO=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ot(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=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 ct(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=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)(jc,{language:`bash`,code:u,codeStyle:bO,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(NO),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)(jc,{language:`bash`,code:d,codeStyle:bO,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},SO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},CO=(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}},wO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:c,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=ot(),T=xg(),E=Fh(Ph()),D=s(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!dn(e):!!(hO(e)||gO(e))),[n]),M=Z.useMemo(()=>j.map(e=>tr(e)?vS(gt(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(c??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=J(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=J(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let W=J(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),ee=T===`mini-chat`||!E.fork?void 0:g,G=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=zE(i,D);return e.length>0?e:null},[C,i,D]),K=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),q=!v&&y&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y($D,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(tO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:rO,name:`edit`,className:nO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:YD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:rO,name:`close`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y($D,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(tO,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??q??((F&&R||m||h||ee)&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y($D,`justify-end`,!a&&x===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[G?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(tO,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:rO,name:`time`,className:nO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(Va,{children:G})]}):null,h&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:YD,"aria-label":w(`chat.messageBody.actions.revertAria`),"aria-busy":_===`revert`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),h()},children:(0,$.jsx)(X,{weight:rO,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(XD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:YD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:rO,name:`edit`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:YD,"aria-label":w(`chat.messageBody.actions.forkAria`),"aria-busy":_===`fork`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),ee()},children:(0,$.jsx)(X,{weight:rO,name:_===`fork`?`loader-4`:`git-branch`,className:Y(XD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:YD,"aria-label":w(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:W,onFocus:()=>k(!0),onBlur:()=>{I||k(!1)},children:I?(0,$.jsx)(X,{weight:rO,name:`check`,className:Y(XD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:rO,name:`file-copy`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:GD,onTouchStart:L&&F&&R?U:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,V?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:V?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:j.map((e,i)=>{if(hO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(vO,{part:e})},e.id??`user-subtask-${i}`);if(gO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(xO,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(yO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&>(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(Yx,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Hd,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),TO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ot(),s=xg(),c=Ph(),l=Fh(c),{isPlaying:u,play:d,stop:f}=yE(),p=Qr(e=>e.showMessageTTSButtons),m=Qr(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)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(YD,!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:rO,name:`check`,className:Y(XD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:rO,name:`file-copy`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:YD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:rO,name:`target`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(YD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:rO,name:`loader-4`,className:Y(XD,`animate-spin`)}):(0,$.jsx)(X,{weight:rO,name:`arrow-left-right`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:Y(YD,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:rO,name:`stop`,className:XD}):(0,$.jsx)(X,{weight:rO,name:`volume-up`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:j})]})]})}),EO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:c,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=ot(),A=xg(),j=Fh(Ph()),M=_,N=Z.useRef(null),P=Z.useRef(null),F=_===`streaming`||_===`cooldown`,I=Z.useRef({messageId:t,experiencedStreamingOrCooldown:F});I.current.messageId===t?F&&(I.current.experiencedStreamingOrCooldown=!0):I.current={messageId:t,experiencedStreamingOrCooldown:F};let L=!!(p??u),R=!!(f??u),z=u?QD:ZD,B=!i,V=Z.useMemo(()=>n.filter(e=>!dn(e)).filter(e=>e.type!==`compaction`),[n]),H=Z.useMemo(()=>V.filter(e=>e.type===`tool`),[V]),U=Z.useMemo(()=>V.filter(e=>e.type===`text`),[V]),W=Z.useMemo(()=>ar(U),[U]),ee=s(e=>e.openContextPreview),G=d(),K=A===`mini-chat`,q=Z.useMemo(()=>{if(G||u||K)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=rc(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of H){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=rc(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[U,u,K,G,H]),te=Zr(e=>e.forkFromMessage),ne=Zr(e=>e.forkTransition),re=Zr(e=>e.currentSessionId),ie=Zr(e=>e.getDirectoryForSession),ae=lc(),oe=D===`review-to-original`,se=!u&&!G?D:null,ce=Z.useMemo(()=>{let t=W.trim();if(!(!e||!ae||!t||!se))return se===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await Jt(e,ae,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await Rt(e,ae,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[W,ae,se,e,O]),[le,ue]=Z.useState(!1),de=s(e=>e.chatRenderMode),fe=s(e=>e.collapsibleThinkingBlocks),pe=s(e=>e.showSplitAssistantMessageActions),me=s(e=>e.showAssistantTps),he=s(e=>e.timeFormatPreference),ge=de===`sorted`,_e=w?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!T)&&(w?.isTurnSettled??!0),be=ve?`completed`:M,xe=H.length>0,Se=Z.useMemo(()=>H.some(e=>JC(e)),[H]),Ce=JC,we=qC,Te=I.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||!Wr())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!fn(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Yr({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,H]);let De=Z.useMemo(()=>H.length===0||!Se&&H.every(e=>we(e)),[H,Se,we]),Oe=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),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=B||xe&&(Se||Ae||!De),Ne=B||je,Pe=xe||Oe.length>0,Fe=U.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,S?.())},[Ie,S]),Z.useEffect(()=>{if(B){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,y?.(`structural`)))},[B,xe,y,ke,Oe.length,Ne]);let ze=!!b&&!B,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||ne)){ue(!0);try{await te(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=w?.activityParts;return!ge||!e?[]:e},[ge,w?.activityParts]),He=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,w?.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=w?.toggleGroup,Ke=w?.activityPresentationKind===`compaction`,qe=w?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?w?.activityOwnerMessageId===t||Ue:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=JT(a,V),Qe={finish:a,parts:V,streamPhase:be,error:T,isLastAssistantInTurn:_e},$e=$T(Qe),et=ge&&eE(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!T,rt=E===`info`?`information`:`error-warning`,it=E===`muted`,at=ze,st=_e&&ye&&!Je&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&_e&&Ze&&ye&&!Je&&w?.diffStats?.hasDiffs===!0,dt=pe&&at&&!st&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(TO,{hasCopyableText:ze,isTouchContext:L,onCopyMessage:x,ttsText:W,reviewTransferAction:ce,sessionId:e}),[W,ze,L,x,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=gt(e.part).trim();return t?(0,$.jsx)(TO,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ct(t)).ok,ttsText:t}):null},[ge,L,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,V]),ht=dt&&mt<0,_t=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(WD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:Ge,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:be,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=C?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<V.length;){let i=V[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:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(ET,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:u?JD:qD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:$D,"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(!gt(i).trim()){r+=1;continue}C&&(fe?n.push((0,$.jsx)(`div`,{className:um(u),children:(0,$.jsx)(RT,{part:i,messageId:t,streamPhase:be,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(ET,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g},`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(GC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!GC(r.tool?.toLowerCase()??``)||We.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(nD,{activities:e,isMobile:u,isTurnLive:be!==`completed`,hasFollowingOtherType:QE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(ID,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(KC(a)){let e=rD(V,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)(cD,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(ID,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(HC(a)){n.push((0,$.jsx)(`div`,{className:um(u),children:(0,$.jsx)(oT,{part:e,messageId:t,isExpanded:m.has(e.id),onToggle:h,isMobile:u,alwaysShowActions:R,onContentChange:y,onShowPopup:g,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:um(u),children:(0,$.jsx)(ID,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,R,de,fe,0,m,Je,Ke,u,Ye,ge,mt,t,ft,pt,e,y,g,h,Xe,dt,be,Te,C,tt,et,Ge,w,V]),vt=Z.useMemo(()=>{if(!_e||!ye)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return SO(e)},[_e,ye,w?.durationMs]),yt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof c==`number`&&c>0?c:null;if(e===null)return null;let t=zE(e,he);return t.length>0?t:null},[o,c,he,k]),bt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=CO(e,l),i=WE({createdAt:c,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=GE(i);return a.length>0?a:null},[me,_e,ye,n,r,l,c,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&q?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:YD,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ae??(re?ie(re):null);e&&ee(e,q)},children:(0,$.jsx)(X,{weight:rO,name:`global`,className:XD})})}),(0,$.jsx)(Va,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!oe&&j.fork?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,className:YD,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!ne,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:rO,name:le?`loader-4`:`git-branch`,className:Y(XD,le&&`animate-spin`)})})}),(0,$.jsx)(Va,{sideOffset:6,children:O(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:N,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:GD,children:[(0,$.jsx)(FE,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[_t,nt&&(0,$.jsx)(gc,{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:T})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:rt,weight:rO,className:Y(XD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:E===`info`?rO:void 0,className:Y(`shrink-0`,E===`info`?Y(XD,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,E===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,u?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(ks,{content:T??``,onShowPopup:g,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),ut&&w?.diffStats?(0,$.jsx)(mO,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(Hd,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?JD:qD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:$D,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:KD,children:[(0,$.jsxs)(`div`,{className:$D,"data-message-action-group":`true`,children:[ft,xt]}),bt||vt||yt?(0,$.jsxs)(`div`,{className:eO,children:[bt?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:tO,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:rO,name:`pulse`,className:nO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(Va,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,vt?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:tO,children:[(0,$.jsx)(X,{weight:rO,name:`hourglass`,className:nO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Va,{children:vt})]}):null,yt?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:tO,"aria-label":`Message time: ${yt}`,children:[(0,$.jsx)(X,{weight:rO,name:`time`,className:nO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Va,{children:yt})]}):null]}):null,!K&&_e&&ve&&!lt?(0,$.jsx)(HT,{activityParts:w?.activityParts}):null]})]})]})}),DO=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)(wO,{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)(EO,{...r}),t[26]=r,t[27]=i),i});function OO(e){return e.openContextPanelTab}function kO(e){return e.setCurrentSession}function AO(e){return e.openContextPanelTab}function jO(e){return!e}function MO(e){return e.openContextPanelTab}function NO(e){return!e}var PO=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}},FO=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,IO=e=>!e,LO=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},RO=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),zO=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,BO=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,VO=`Authentication failed for this provider. Please re-authenticate and retry.`,HO=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 UO(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`}:HO(o)?{text:VO,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 WO=Is(()=>Ue(()=>import(`./ToolOutputDialog-DPz8gn8_.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]))),GO=4e3,KO=new Map,qO=new Map,JO=new Set([`bash`,`shell`,`cmd`,`terminal`]),YO=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},XO=e=>{let t=KO.get(e);return t?new Set(t):new Set},ZO=(e,t)=>{if(KO.size>=GO&&!KO.has(e)){let e=KO.keys().next().value;typeof e==`string`&&KO.delete(e)}KO.set(e,new Set(t))},QO=e=>{let t=qO.get(e);return t?new Set(t):new Set},$O=(e,t)=>{if(qO.size>=GO&&!qO.has(e)){let e=qO.keys().next().value;typeof e==`string`&&qO.delete(e)}qO.set(e,new Set(t))},ek=200,tk=new Map,nk=e=>tk.get(e),rk=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=tk.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(tk.size>=ek&&!tk.has(e)){let e=tk.keys().next().value;typeof e==`string`&&tk.delete(e)}tk.set(e,t)}};function ik(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]},ok=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=ot(),{isMobile:m,isTablet:h,hasTouchInput:g}=fo(),_=Ph(),v=Fh(_),y=m||h,b=Z.useRef(null),x=Zr(e=>e.currentSessionId),S=vi(e=>e.getAgentModelForSession),C=vi(e=>e.getSessionModelSelection),w=Zr(e=>e.revertToMessage),T=Zr(e=>e.editMessagePreservingChanges),E=Zr(e=>e.forkFromMessage),D=Zr(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=Zr(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=Zr(e=>e.clearStagedMessageEdit);Le(`ui.chat_message.render`),c&&Le(`ui.chat_message.render.streaming`);let A=Qr(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=s(pe(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{x&&Px.getInstance().recordSessionStart(x)},[x]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[H,U]=Z.useState(()=>XO(e.info.id)),[W,ee]=Z.useState(()=>QO(e.info.id)),[G,K]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{U(XO(e.info.id)),ee(QO(e.info.id))},[e.info.id]);let q=Z.useMemo(()=>PO(e.info),[e.info]).isUser,te=q&&(m||!M),ne=q&&!m&&M&&!te,re=e.info.sessionID,ie=Lx(e=>e.planModeEnabled),{currentContextAgent:ae,savedSessionAgentSelection:oe}=Tm(pe(e=>({currentContextAgent:c&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:c&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>hn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>q?qr(se,{planModeEnabled:ie}):hn(e.parts),[q,e.parts,ie,se]),le=Z.useMemo(()=>{if(q||!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}},[q,t]),ue=Z.useMemo(()=>{if(!ie||q||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[q,ie,t]),de=Z.useMemo(()=>{if(q)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&ue&&le?.agentName)return le.agentName;let n=ak(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=ak(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(le?.agentName)return le.agentName;if(re)return ae||(oe??void 0)},[q,e.info,ue,le,re,ae,oe]),fe=q?null:ak(e.info,`providerID`),me=q?null:ak(e.info,`modelID`),he=Z.useMemo(()=>{if(q||!re)return null;if(le?.providerId&&le?.modelId)return{providerId:le.providerId,modelId:le.modelId};if(de){let e=S(re,de);if(e?.providerId&&e?.modelId)return e}let e=C(re);return e?.providerId&&e?.modelId?e:null},[q,re,de,le,S,C]),ge=Z.useMemo(()=>q?null:typeof fe==`string`&&fe.trim().length>0?fe:he?.providerId??null,[q,fe,he]),_e=Z.useMemo(()=>q?null:typeof me==`string`&&me.trim().length>0?me:he?.modelId??null,[q,me,he]),ve=e.info.id?nk(e.info.id):void 0;q||rk(e.info.id,{agent:de,provider:ge??void 0,model:_e??void 0});let ye=de??ve?.agent,be=ge??ve?.provider??null,xe=_e??ve?.model??null,Se=Z.useMemo(()=>{if(q)return;let e=be&&A.length>0?A.find(e=>e.id===be):void 0;return Ai(e,xe)||void 0},[q,be,xe,A]),Ce=Z.useMemo(()=>{if(q||!ge||!_e)return!1;let e=A.find(e=>e.id===ge);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===_e)?.variants;return!!(t&&Object.keys(t).length>0)},[q,_e,ge,A]),we=ik(ye),Te=ik(be??void 0),Ee=ik(xe??void 0),De=ik(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,je=De??void 0,Me=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Pe=Z.useMemo(()=>q?!0:!!(Me&&Me>0),[q,Me]),Fe=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Ie=Z.useMemo(()=>{if(q)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}},[q,e.info]),Re=Z.useMemo(()=>Ur(ce,{includeReasoning:j}),[ce,j]),ze=Z.useMemo(()=>q?Re:!Pe&&N===`sorted`?[]:Re,[N,Pe,q,Re]),Be=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`text`),[q,Re]),Ve=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`tool`),[q,Re]),He=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of Ve){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=YO(t.tool);!r||!JO.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=YO(t.part.tool);!n||!JO.has(n)||e.add(t.id)}return e},[P,Ve,a?.activityParts]),Ue=Z.useMemo(()=>{if(He.size===0&&W.size===0)return H;let e=new Set(H);return He.forEach(t=>{W.has(t)||e.add(t)}),W.forEach(t=>{e.delete(t)}),e},[W,He,H]),We=Z.useMemo(()=>{if(!q)return;let e=ce.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[q,ce]),Ge=q&&!yn(ze),Ke=typeof Fe!=`string`,qe=Z.useMemo(()=>q?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,q]),Je=Z.useMemo(()=>!q&&Px.getInstance().shouldAnimateMessage(e.info,x||e.info.sessionID),[e.info,x,q]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?PO(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=zO({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),tt=Z.useMemo(()=>q?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,q,Ze]),nt=Z.useMemo(()=>Pe?`completed`:c?l??`streaming`:`completed`,[l,c,Pe]);Z.useEffect(()=>{!q||!u||d?.(e.info.id)},[u,q,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;q||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,q,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(q)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,q,a,nt,e.info.id]),it=Z.useCallback(e=>{ct(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),at=q?void 0:a?.userMessageVariant??le?.variant,st=!q&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,lt=Z.useMemo(()=>{if(!q)return UO(e.info?.error,p(`chat.messageBody.aborted`))},[q,e.info,p]),ut=lt?.text,dt=lt?.variant,ft=Z.useMemo(()=>{if(q){let e=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6574
|
+
`).trim()||ME(t)},HE=({containerRef:e})=>{let{t}=ot(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,c]=Z.useState(``),l=Z.useRef(!1),[u,d]=Z.useState(!1),f=Z.useRef(null),p=Z.useRef(OE),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(null),_=Z.useRef(!1),v=Zr(e=>e.createSession),y=on(e=>e.setPendingInputText),b=s(e=>e.isMobile),x=Fh(Ph()).textSelectionMutation;Z.useEffect(()=>{_.current=n.show},[n.show]),Z.useEffect(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]);let S=Z.useCallback(()=>{m.current=null,kE===S&&(kE=null),_.current&&=(h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),d(!1),r(e=>({...e,show:!1})),a(``),c(``),!1)},[]);Z.useEffect(()=>()=>{kE===S&&(kE=null)},[S]);let C=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=p.current/2,r=DE+n,i=t-DE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),w=Z.useCallback(()=>{if(!m.current)return;kE!==S&&(kE?.(),kE=S);let{plainText:e,markdownText:t,rect:i}=m.current,o=!n.show,s=b?i.left+i.width/2:C(i.left+i.width/2),l=i.top-10;a(e),c(t),r({x:s,y:l,show:!0}),_.current=!0,o&&(d(!0),h.current!==null&&window.cancelAnimationFrame(h.current),h.current=window.requestAnimationFrame(()=>{d(!1),h.current=null}))},[C,S,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!f.current)return;let e=f.current.offsetWidth;!Number.isFinite(e)||e<=0||e===p.current||(p.current=e,r(e=>({...e,x:C(e.x)})))},[C,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:C(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[C,b,n.show]);let T=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||S();return}let r=ME(t.toString());if(!r){l.current||S();return}let i=FE(t,n);if(!i){l.current||S();return}let a=i.getBoundingClientRect();m.current={plainText:r,markdownText:VE(i,r),rect:a},l.current||w()},[e,S,w]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,S()},r=()=>{l.current=!1,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{g.current=null,T()},10)},i=new Set,a=()=>{for(let e of PE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,T))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,T),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{f.current&&!f.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&S()};return document.addEventListener(`mousedown`,s),()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,T);document.removeEventListener(`selectionchange`,T),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,T,S,w]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{f.current&&e.target instanceof Node&&f.current.contains(e.target)||S()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,S]);let E=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;y(t,`append`),S(),window.getSelection()?.removeAllRanges()},[y,S]),D=Z.useCallback(()=>{E(o)},[E,o]);Z.useEffect(()=>{let t=t=>{if(!x||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=FE(n,r);i&&(t.preventDefault(),E(VE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[E,x,e]);let O=Z.useCallback(async()=>{i&&(await v(void 0,null,null)&&y(i,`replace`),S(),window.getSelection()?.removeAllRanges())},[i,v,y,S]),k=Z.useCallback(async()=>{if(!i)return;let e=await ct(i);e.ok||console.error(`Failed to copy:`,e.error),S(),window.getSelection()?.removeAllRanges()},[i,S]);return n.show?b?(0,el.createPortal)((0,$.jsx)(`div`,{ref:f,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,el.createPortal)((0,$.jsx)(`div`,{ref:f,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(Jp,{shortcut:`⌘+I`})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},UE=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),WE=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),UE(e,n)},GE=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),KE=(e,t)=>{if(!GE(e))return``;let n=new Date(e),r=new Date,i=oo(n,t),a=st(),o=lt.getState().dictionary;if(UE(n,r))return i;if(WE(n,r))return ut(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},qE=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,JE=e=>e,YE=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=JE(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},XE=(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-YE(n);return!Number.isFinite(a)||a<=0?null:a},ZE=e=>{let t=XE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=qE(e.outputTokens)+qE(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},QE=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`},$E=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},eD=[`search`,`read`,`list`];function tD(e){let t=nw(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function nD(e){let t={read:0,search:0,list:0};for(let n of e){let e=tD(n);e&&(t[e]+=1)}return t}function rD(e){return tw(e)}function iD(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!QC(e.toolName):e.kind!=null||e.type!=null}function aD(e,t,n){for(let r=t;r<e.length;r+=1)if(iD(n(e[r])))return!0;return!1}function oD(e){return`parts`in e?e.parts.some(e=>rD(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>rD(e))}function sD(e,t,n){let r=[],i=t;for(;i<e.length&&QC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var cD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,lD=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=ot(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??oD({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=nD(u.map(e=>e.tool)),p=eD.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=J(()=>{c(e=>!e)}),h=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:um(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,dm),onClick:m,onKeyDown:h,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,v,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(BC,{isMobile:t,label:o(`chat.contextGroup.exploring`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,v,cD,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:_}),p?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,v,cD),style:{color:`var(--tools-description)`},children:(0,$.jsx)($E,{text:p,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:`relative ml-2 pl-3 pt-0.5`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a]}):null]})};function uD(e,t,n){let r=[],i=t;for(;i<e.length&&$C(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var dD=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function fD(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=dD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=dD(e.name);if(t)return t;let r=dD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=dD(n.output.name);if(e)return e}return null}function pD(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`,hD=({activities:e,isMobile:t,children:n})=>{let{t:r}=ot(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>tw(e)),{joinedVisible:l,hiddenCount:u}=pD(s.map(fD)),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:um(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`,dm),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)(BC,{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)($E,{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]})},gD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:c}=e,l=s(_D),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==c||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(NT,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:c})}),t[4]=l,t[5]=r,t[6]=i,t[7]=c,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function _D(e){return e.chatRenderMode}var vD=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},yD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,bD=Y(`typography-meta font-medium`,yD),xD=Y(`typography-meta`,yD),SD=[],CD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},wD=e=>{let t=new Set;for(let n of e)CD(n)&&n.messageId&&t.add(n.messageId);return[...t]},TD=(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}),ED=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=nc(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},DD=e=>e,OD=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},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;return typeof i==`string`&&i.trim().length>0?i:null},AD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},jD=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},MD=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=jD(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`}`},ND=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=MD(n.todos);if(e)return e}if(Array.isArray(r)){let e=MD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=MD(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=MD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=MD(e.todos);if(t)return t}}catch{}return null},PD=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)},FD=(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`,xD),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`,xD),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})]})},ID=e=>{let t=yo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},LD=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 fD(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`?ND(e):OD(e)},RD=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}},zD=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=um(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)(pT,{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])),BD=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=um(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(UD,{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&&HD(e.activities,t.activities)),VD=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!gt(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(QC(i)){let r=sD(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:aD(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if($C(i)){let r=uD(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(XC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(YC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(ZC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},HD=(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},UD=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ot(),c=s(qD),l=ic(n,o),u;t[0]===n?u=t[1]:(u=aS(n),t[0]=n,t[1]=u);let d=u,f;t[2]===n?f=t[3]:(f=n.toLowerCase(),t[2]=n,t[3]=f);let p=f===`read`,m=Z.useContext(Oo),h=$h(),g=we(JD),_=Ph(),v=_.kind===`embedded`?_.directory:g,y;t[4]===n?y=t[5]:(y=n.toLowerCase(),t[4]=n,t[5]=y);let b=y===`skill`,x;t[6]===b?x=t[7]:(x={enabled:b},t[6]=b,t[7]=x);let S=Tr(x),C;t[8]===S.data?C=t[9]:(C=S.data??[],t[8]=S.data,t[9]=C);let w=C,T;t[10]===w?T=t[11]:(T=new Map(w.map(YD)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||tw(D.part),k;t[12]===D?k=t[13]:(k=D?LD(D):null,t[12]=D,t[13]=k);let A=k,j;if(t[14]!==A||t[15]!==D||t[16]!==E||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!D||!A){j=null;break bb0}let e=E.get(A)?.path||AD(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=ID(e);if(!r){j=null;break bb0}let i;t[19]!==A||t[20]!==r?(i={name:A,path:r},t[19]=A,t[20]=r,t[21]=i):i=t[21],j=i}t[14]=A,t[15]=D,t[16]=E,t[17]=n,t[18]=j}else j=t[18];let M=j,N;if(t[22]!==v||t[23]!==p||t[24]!==D){bb1:{if(!p||!D){N=null;break bb1}let e=kD(D);if(!e){N=null;break bb1}let n=_o(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=PD(D),t[26]=D,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],N=i}t[22]=v,t[23]=p,t[24]=D,t[25]=N}else N=t[25];let P=N,F;t[32]!==v||t[33]!==h||t[34]!==m?(F=(e,t)=>{if(!v)return;let n=vo(v,e);if(!n)return;if(h){h.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(m?.editor){m.editor.openFile(n,t);return}if(!So(n,v)){uc(n,v).then(()=>{let e=s.getState(),r=v||go(v,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=s.getState(),i=go(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=J(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=yo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=s.getState(),n=v||go(``,t);e.openContextFile(n,t)};if(v&&!So(t,v)){uc(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=J(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,W=!!(P||M),ee=!!(P&&v||M),G;t[41]!==ee||t[42]!==I||t[43]!==R||t[44]!==W||t[45]!==P||t[46]!==M?(G=()=>{if(!(!W||!ee)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=ee,t[42]=I,t[43]=R,t[44]=W,t[45]=P,t[46]=M,t[47]=G):G=t[47];let K=J(G),q;t[48]===K?q=t[49]:(q=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K())},t[48]=K,t[49]=q);let te=J(q),ne=W&&ee&&`cursor-pointer`,re=W&&!ee&&`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`,dm,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=W?`soft`:void 0,oe=W?K:void 0,se=W?te:void 0,ce=W?`button`:void 0,le=W&&ee?0:void 0,ue=W&&!ee?!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=O?(0,$.jsx)(BC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,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(bD,`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]===l?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:l,children:l}),t[62]=l,t[63]=ve);let ye;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==c?(ye=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,xD),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[c?(0,$.jsx)(gd,{filePath:P.path,className:`h-3.5 w-3.5`}):null,FD(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=c,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==A||t[71]!==V?(be=V&&A?(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`,xD),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=be):be=t[72];let xe;t[73]!==A||t[74]!==H?(xe=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:XD,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`,xD),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(ED,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=xe):xe=t[75];let Se;t[76]!==U||t[77]!==M?(Se=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,xD),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=Se):Se=t[78];let Ce;t[79]!==A||t[80]!==U||t[81]!==M?(Ce=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,xD),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=Ce):Ce=t[82];let Te;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Te=!p&&!V&&!H&&!U&&A?(0,$.jsx)(iS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,xD),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=Te):Te=t[89];let Ee;return t[90]!==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]!==Se||t[103]!==Ce||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,Se,Ce,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]=Se,t[103]=Ce,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&HD(e.activities,t.activities)),WD=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)(GT,{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}),GD=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)(gD,{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}),KD=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=ot(),_=lc()??``,v=Z.useMemo(()=>wD(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?vD(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(()=>RD(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=Ct(_,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=Nt(_,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 Ct(_,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)&&CD(e)),K=ee&&!G&&!TD(t,V),q=Z.useMemo(()=>B?DD(e):SD,[e,B]),te=Z.useMemo(()=>B?VD(q):[],[B,q]),ne=Z.useMemo(()=>L||z===0?0:Math.max(0,te.length-z),[L,z,te.length]),re=Z.useMemo(()=>L||z===0?te:te.slice(-z),[L,z,te]);if((!m||I&&!O)&&te.length===0)return null;let ie=(e,t)=>{let n=(0,$.jsx)(`div`,{className:um(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ae=B?re.map((e,t)=>{switch(e.type){case`reasoning`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(WD,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(GD,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(zD,{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)(BD,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(lD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(UD,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(hD,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(UD,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(zD,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,oe=re.length>0;return m?(0,$.jsxs)(`div`,{className:um(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&&dm,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)(BC,{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)(sa,{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`)})]})]}),oe?(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)`}}),ne>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:[`+`,ne,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ae})]}):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)(ca,{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:um(c),children:ae})});function qD(e){return e.showToolFileIcons}function JD(e){return e.currentDirectory}function YD(e){return[e.name,e]}function XD(e){e.stopPropagation()}var ZD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(KD,{...e}),t[0]=e,t[1]=n),n}),QD={contain:`layout`},$D={containerType:`inline-size`,containerName:`message-footer`},eO=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,tO=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,nO=`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`,rO=`size-3.5!`,iO=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,aO=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,oO=`flex items-center gap-2`,sO=`flex items-center gap-2 text-muted-foreground`,cO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,lO=`size-3.5!`,uO=`medium`,dO=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,fO=`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)]`,pO=`h-7 gap-1.5`,mO=`h-6 gap-1`,hO=`text-[11px] leading-none`,gO=`size-3.5`,_O=`size-3`,vO=5,yO=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)(gd,{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=dO(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}),bO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ot(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?mO:pO,d;t[3]===u?d=t[4]:(d=Y(fO,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)(yO,{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)(ca,{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}),xO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:c}=ot(),l=lc(),u=Ph(),d=u.directory||l,f=u.sessionId,p=$h(),m=s(FO),h;t[0]===r?h=t[1]:(h=r??[],t[0]=r,t[1]=h);let g=h,_;t[2]===g?_=t[3]:(_=g.slice(0,vO),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==c?(S=c(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=c,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==c?(w=c(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=c,t[9]=w):w=t[9];let T=w,E=Y(fO,o?mO:pO),D=o?_O:gO,O;t[10]===o?O=t[11]:(O=o?Y(hO,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=O);let k=O,A;t[12]===o?A=t[13]:(A=o?Y(hO,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=A);let j=A,M;t[14]===o?M=t[15]:(M=o?Y(hO,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=M);let N=M,P;t[16]!==d||t[17]!==f||t[18]!==a||t[19]!==o||t[20]!==p||t[21]!==i?(P=e=>{if(p){p.openTurnDiff(i,f,e);return}if(!o&&d){JT({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&JT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=J(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&JT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=J(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===c?V=t[35]:(V=c(`diffView.actions.reviewAria`),t[34]=c,t[35]=V);let H;t[36]===c?H=t[37]:(H=c(`diffView.actions.reviewAria`),t[36]=c,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let W=`turn-changes-${i}`,ee;t[40]===c?ee=t[41]:(ee=c(`chat.changedFiles.title`),t[40]=c,t[41]=ee);let G;t[42]!==W||t[43]!==ee||t[44]!==k?(G=(0,$.jsx)(`span`,{id:W,className:k,children:ee}),t[42]=W,t[43]=ee,t[44]=k,t[45]=G):G=t[45];let K;t[46]!==C||t[47]!==j?(K=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=K):K=t[48];let q;t[49]===D?q=t[50]:(q=Y(D,`opacity-60`),t[49]=D,t[50]=q);let te;return t[51]===q?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:q}),t[51]=q,t[52]=te),(0,$.jsxs)(`section`,{className:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,G,K,te]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(bO,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":c(`diffView.actions.reviewAria`),title:c(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),SO=e=>e.type===`subtask`,CO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},wO=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}`},TO=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=lc(),{isMobile:o}=fo(),c=Zr(IO),l=s(LO),u=Ph(),{t:f}=ot(),p;t[0]===n.description?p=t[1]:(p=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=p);let m=p,h;t[2]===n.command?h=t[3]:(h=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=h);let g=h,_;t[4]===n.agent?_=t[5]:(_=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=_);let v=_,y;t[6]===n.prompt?y=t[7]:(y=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=y);let b=y,x;t[8]===n.taskSessionID?x=t[9]:(x=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=x);let S=x,C;t[10]===n.model?C=t[11]:(C=wO(n.model),t[10]=n.model,t[11]=C);let w=C,T=!!b&&!(o&&u.kind===`primary`),E;t[12]===f?E=t[13]:(E=f(`chat.messageBody.subtask.title`),t[12]=f,t[13]=E);let D;t[14]===E?D=t[15]:(D=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:E}),t[14]=E,t[15]=D);let O;t[16]===g?O=t[17]:(O=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,g]}):null,t[16]=g,t[17]=O);let k;t[18]===v?k=t[19]:(k=v?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,v]}):null,t[18]=v,t[19]=k);let A;t[20]===w?A=t[21]:(A=w?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:w}):null,t[20]=w,t[21]=A);let j;t[22]!==k||t[23]!==A||t[24]!==D||t[25]!==O?(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D,O,k,A]}),t[22]=k,t[23]=A,t[24]=D,t[25]=O,t[26]=j):j=t[26];let M;t[27]===m?M=t[28]:(M=m?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:m}):null,t[27]=m,t[28]=M);let N;t[29]!==r||t[30]!==b||t[31]!==T||t[32]!==f?(N=T?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(RO),children:f(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==c||t[41]!==f||t[42]!==S?(P=S&&u.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=u.directory||a;e&&Ih(u,S,e,()=>{if(!ai({sessionId:S,directory:e})){if(ll()||o||d()){c(S,e);return}l(e,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=c,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},EO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=lc(),i=s(zO),{isMobile:a}=fo(),{t:o}=ot(),c;t[0]!==r||t[1]!==a?(c=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=c):c=t[2];let l=!!c,u;t[3]!==n.state||t[4]!==o?(u=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=J(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=J(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(ks,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=j);let M;t[23]!==A||t[24]!==j?(M=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[A,j]}),t[23]=A,t[24]=j,t[25]=M):M=t[25];let N;return t[26]!==w||t[27]!==M||t[28]!==y||t[29]!==b||t[30]!==x||t[31]!==S||t[32]!==C?(N=(0,$.jsxs)(`div`,{className:y,role:b,tabIndex:x,"aria-label":S,onClick:C,onKeyDown:w,children:[T,M]}),t[26]=w,t[27]=M,t[28]=y,t[29]=b,t[30]=x,t[31]=S,t[32]=C,t[33]=N):N=t[33],N},DO={background:`transparent`,backgroundColor:`transparent`},OO=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ot(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=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 ct(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=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)(jc,{language:`bash`,code:u,codeStyle:DO,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(BO),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)(jc,{language:`bash`,code:d,codeStyle:DO,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},kO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},AO=(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}},jO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:c,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=ot(),T=xg(),E=Fh(Ph()),D=s(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!dn(e):!!(SO(e)||CO(e))),[n]),M=Z.useMemo(()=>j.map(e=>tr(e)?TS(gt(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(c??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=J(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=J(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let W=J(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),ee=T===`mini-chat`||!E.fork?void 0:g,G=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=KE(i,D);return e.length>0?e:null},[C,i,D]),K=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),q=!v&&y&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(oO,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(cO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:uO,name:`edit`,className:lO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:nO,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:uO,name:`close`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(oO,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(cO,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??q??((F&&R||m||h||ee)&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(oO,`justify-end`,!a&&x===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[G?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(cO,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:uO,name:`time`,className:lO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(Va,{children:G})]}):null,h&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:nO,"aria-label":w(`chat.messageBody.actions.revertAria`),"aria-busy":_===`revert`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),h()},children:(0,$.jsx)(X,{weight:uO,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(rO,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:nO,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:uO,name:`edit`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:nO,"aria-label":w(`chat.messageBody.actions.forkAria`),"aria-busy":_===`fork`,disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),ee()},children:(0,$.jsx)(X,{weight:uO,name:_===`fork`?`loader-4`:`git-branch`,className:Y(rO,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:nO,"aria-label":w(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:W,onFocus:()=>k(!0),onBlur:()=>{I||k(!1)},children:I?(0,$.jsx)(X,{weight:uO,name:`check`,className:Y(rO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:uO,name:`file-copy`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:QD,onTouchStart:L&&F&&R?U:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,V?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:V?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:j.map((e,i)=>{if(SO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(TO,{part:e})},e.id??`user-subtask-${i}`);if(CO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(OO,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(EO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&>(e).includes(N)&&(s=p,P=!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)(Hd,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),MO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ot(),s=xg(),c=Ph(),l=Fh(c),{isPlaying:u,play:d,stop:f}=EE(),p=Qr(e=>e.showMessageTTSButtons),m=Qr(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)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(nO,!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:uO,name:`check`,className:Y(rO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:uO,name:`file-copy`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:nO,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:uO,name:`target`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(nO,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:uO,name:`loader-4`,className:Y(rO,`animate-spin`)}):(0,$.jsx)(X,{weight:uO,name:`arrow-left-right`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:Y(nO,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:uO,name:`stop`,className:rO}):(0,$.jsx)(X,{weight:uO,name:`volume-up`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:j})]})]})}),NO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:c,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=ot(),A=xg(),j=Fh(Ph()),M=_,N=Z.useRef(null),P=Z.useRef(null),F=_===`streaming`||_===`cooldown`,I=Z.useRef({messageId:t,experiencedStreamingOrCooldown:F});I.current.messageId===t?F&&(I.current.experiencedStreamingOrCooldown=!0):I.current={messageId:t,experiencedStreamingOrCooldown:F};let L=!!(p??u),R=!!(f??u),z=u?aO:iO,B=!i,V=Z.useMemo(()=>n.filter(e=>!dn(e)).filter(e=>e.type!==`compaction`),[n]),H=Z.useMemo(()=>V.filter(e=>e.type===`tool`),[V]),U=Z.useMemo(()=>V.filter(e=>e.type===`text`),[V]),W=Z.useMemo(()=>ar(U),[U]),ee=s(e=>e.openContextPreview),G=d(),K=A===`mini-chat`,q=Z.useMemo(()=>{if(G||u||K)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=rc(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of H){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=rc(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[U,u,K,G,H]),te=Zr(e=>e.forkFromMessage),ne=Zr(e=>e.forkTransition),re=Zr(e=>e.currentSessionId),ie=Zr(e=>e.getDirectoryForSession),ae=lc(),oe=D===`review-to-original`,se=!u&&!G?D:null,ce=Z.useMemo(()=>{let t=W.trim();if(!(!e||!ae||!t||!se))return se===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await Jt(e,ae,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await Rt(e,ae,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[W,ae,se,e,O]),[le,ue]=Z.useState(!1),de=s(e=>e.chatRenderMode),fe=s(e=>e.collapsibleThinkingBlocks),pe=s(e=>e.showSplitAssistantMessageActions),me=s(e=>e.showAssistantTps),he=s(e=>e.timeFormatPreference),ge=de===`sorted`,_e=w?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!T)&&(w?.isTurnSettled??!0),be=ve?`completed`:M,xe=H.length>0,Se=Z.useMemo(()=>H.some(e=>tw(e)),[H]),Ce=tw,we=ew,Te=I.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||!Wr())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!fn(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Yr({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,H]);let De=Z.useMemo(()=>H.length===0||!Se&&H.every(e=>we(e)),[H,Se,we]),Oe=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),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=B||xe&&(Se||Ae||!De),Ne=B||je,Pe=xe||Oe.length>0,Fe=U.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,S?.())},[Ie,S]),Z.useEffect(()=>{if(B){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,y?.(`structural`)))},[B,xe,y,ke,Oe.length,Ne]);let ze=!!b&&!B,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||ne)){ue(!0);try{await te(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=w?.activityParts;return!ge||!e?[]:e},[ge,w?.activityParts]),He=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,w?.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=w?.toggleGroup,Ke=w?.activityPresentationKind===`compaction`,qe=w?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?w?.activityOwnerMessageId===t||Ue:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=tE(a,V),Qe={finish:a,parts:V,streamPhase:be,error:T,isLastAssistantInTurn:_e},$e=oE(Qe),et=ge&&sE(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!T,rt=E===`info`?`information`:`error-warning`,it=E===`muted`,at=ze,st=_e&&ye&&!Je&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&_e&&Ze&&ye&&!Je&&w?.diffStats?.hasDiffs===!0,dt=pe&&at&&!st&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(MO,{hasCopyableText:ze,isTouchContext:L,onCopyMessage:x,ttsText:W,reviewTransferAction:ce,sessionId:e}),[W,ze,L,x,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=gt(e.part).trim();return t?(0,$.jsx)(MO,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ct(t)).ok,ttsText:t}):null},[ge,L,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,V]),ht=dt&&mt<0,_t=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(ZD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:Ge,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:be,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=C?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<V.length;){let i=V[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:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(NT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:u?tO:eO,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:oO,"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(!gt(i).trim()){r+=1;continue}C&&(fe?n.push((0,$.jsx)(`div`,{className:um(u),children:(0,$.jsx)(GT,{part:i,messageId:t,streamPhase:be,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(NT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g},`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(QC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!QC(r.tool?.toLowerCase()??``)||We.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(lD,{activities:e,isMobile:u,isTurnLive:be!==`completed`,hasFollowingOtherType:aD(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(UD,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if($C(a)){let e=uD(V,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)(hD,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(UD,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(YC(a)){n.push((0,$.jsx)(`div`,{className:um(u),children:(0,$.jsx)(pT,{part:e,messageId:t,isExpanded:m.has(e.id),onToggle:h,isMobile:u,alwaysShowActions:R,onContentChange:y,onShowPopup:g,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:um(u),children:(0,$.jsx)(UD,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,R,de,fe,0,m,Je,Ke,u,Ye,ge,mt,t,ft,pt,e,y,g,h,Xe,dt,be,Te,C,tt,et,Ge,w,V]),vt=Z.useMemo(()=>{if(!_e||!ye)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return kO(e)},[_e,ye,w?.durationMs]),yt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof c==`number`&&c>0?c:null;if(e===null)return null;let t=KE(e,he);return t.length>0?t:null},[o,c,he,k]),bt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=AO(e,l),i=ZE({createdAt:c,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=QE(i);return a.length>0?a:null},[me,_e,ye,n,r,l,c,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&q?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:nO,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ae??(re?ie(re):null);e&&ee(e,q)},children:(0,$.jsx)(X,{weight:uO,name:`global`,className:rO})})}),(0,$.jsx)(Va,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!oe&&j.fork?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,className:nO,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!ne,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:uO,name:le?`loader-4`:`git-branch`,className:Y(rO,le&&`animate-spin`)})})}),(0,$.jsx)(Va,{sideOffset:6,children:O(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:N,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:QD,children:[(0,$.jsx)(HE,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[_t,nt&&(0,$.jsx)(gc,{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:T})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:rt,weight:uO,className:Y(rO,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:E===`info`?uO:void 0,className:Y(`shrink-0`,E===`info`?Y(rO,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,E===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,u?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(ks,{content:T??``,onShowPopup:g,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),ut&&w?.diffStats?(0,$.jsx)(xO,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(Hd,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?tO:eO),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:oO,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:$D,children:[(0,$.jsxs)(`div`,{className:oO,"data-message-action-group":`true`,children:[ft,xt]}),bt||vt||yt?(0,$.jsxs)(`div`,{className:sO,children:[bt?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cO,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:uO,name:`pulse`,className:lO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(Va,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,vt?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cO,children:[(0,$.jsx)(X,{weight:uO,name:`hourglass`,className:lO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Va,{children:vt})]}):null,yt?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsxs)(`span`,{className:cO,"aria-label":`Message time: ${yt}`,children:[(0,$.jsx)(X,{weight:uO,name:`time`,className:lO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Va,{children:yt})]}):null]}):null,!K&&_e&&ve&&!lt?(0,$.jsx)(YT,{activityParts:w?.activityParts}):null]})]})]})}),PO=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)(jO,{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)(NO,{...r}),t[26]=r,t[27]=i),i});function FO(e){return e.openContextPanelTab}function IO(e){return e.setCurrentSession}function LO(e){return e.openContextPanelTab}function RO(e){return!e}function zO(e){return e.openContextPanelTab}function BO(e){return!e}var VO=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}},HO=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,UO=e=>!e,WO=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},GO=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),KO=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,qO=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,JO=`Authentication failed for this provider. Please re-authenticate and retry.`,YO=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 XO(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`}:YO(o)?{text:JO,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 ZO=Is(()=>Ue(()=>import(`./ToolOutputDialog-cDDD9uCL.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]))),QO=4e3,$O=new Map,ek=new Map,tk=new Set([`bash`,`shell`,`cmd`,`terminal`]),nk=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},rk=e=>{let t=$O.get(e);return t?new Set(t):new Set},ik=(e,t)=>{if($O.size>=QO&&!$O.has(e)){let e=$O.keys().next().value;typeof e==`string`&&$O.delete(e)}$O.set(e,new Set(t))},ak=e=>{let t=ek.get(e);return t?new Set(t):new Set},ok=(e,t)=>{if(ek.size>=QO&&!ek.has(e)){let e=ek.keys().next().value;typeof e==`string`&&ek.delete(e)}ek.set(e,new Set(t))},sk=200,ck=new Map,lk=e=>ck.get(e),uk=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=ck.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(ck.size>=sk&&!ck.has(e)){let e=ck.keys().next().value;typeof e==`string`&&ck.delete(e)}ck.set(e,t)}};function dk(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 fk=(e,t)=>{if(typeof e==`object`&&e)return e[t]},pk=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=ot(),{isMobile:m,isTablet:h,hasTouchInput:g}=fo(),_=Ph(),v=Fh(_),y=m||h,b=Z.useRef(null),x=Zr(e=>e.currentSessionId),S=vi(e=>e.getAgentModelForSession),C=vi(e=>e.getSessionModelSelection),w=Zr(e=>e.revertToMessage),T=Zr(e=>e.editMessagePreservingChanges),E=Zr(e=>e.forkFromMessage),D=Zr(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=Zr(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=Zr(e=>e.clearStagedMessageEdit);Le(`ui.chat_message.render`),c&&Le(`ui.chat_message.render.streaming`);let A=Qr(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=s(pe(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{x&&Vx.getInstance().recordSessionStart(x)},[x]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[H,U]=Z.useState(()=>rk(e.info.id)),[W,ee]=Z.useState(()=>ak(e.info.id)),[G,K]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{U(rk(e.info.id)),ee(ak(e.info.id))},[e.info.id]);let q=Z.useMemo(()=>VO(e.info),[e.info]).isUser,te=q&&(m||!M),ne=q&&!m&&M&&!te,re=e.info.sessionID,ie=Wx(e=>e.planModeEnabled),{currentContextAgent:ae,savedSessionAgentSelection:oe}=Tm(pe(e=>({currentContextAgent:c&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:c&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>hn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>q?qr(se,{planModeEnabled:ie}):hn(e.parts),[q,e.parts,ie,se]),le=Z.useMemo(()=>{if(q||!t)return null;let e=fk(t.info,`clientRole`),n=fk(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=fk(t.info,`mode`),i=fk(t.info,`agent`),a=fk(t.info,`providerID`),o=fk(t.info,`modelID`),s=fk(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=fk(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}},[q,t]),ue=Z.useMemo(()=>{if(!ie||q||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[q,ie,t]),de=Z.useMemo(()=>{if(q)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&ue&&le?.agentName)return le.agentName;let n=fk(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=fk(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(le?.agentName)return le.agentName;if(re)return ae||(oe??void 0)},[q,e.info,ue,le,re,ae,oe]),fe=q?null:fk(e.info,`providerID`),me=q?null:fk(e.info,`modelID`),he=Z.useMemo(()=>{if(q||!re)return null;if(le?.providerId&&le?.modelId)return{providerId:le.providerId,modelId:le.modelId};if(de){let e=S(re,de);if(e?.providerId&&e?.modelId)return e}let e=C(re);return e?.providerId&&e?.modelId?e:null},[q,re,de,le,S,C]),ge=Z.useMemo(()=>q?null:typeof fe==`string`&&fe.trim().length>0?fe:he?.providerId??null,[q,fe,he]),_e=Z.useMemo(()=>q?null:typeof me==`string`&&me.trim().length>0?me:he?.modelId??null,[q,me,he]),ve=e.info.id?lk(e.info.id):void 0;q||uk(e.info.id,{agent:de,provider:ge??void 0,model:_e??void 0});let ye=de??ve?.agent,be=ge??ve?.provider??null,xe=_e??ve?.model??null,Se=Z.useMemo(()=>{if(q)return;let e=be&&A.length>0?A.find(e=>e.id===be):void 0;return Ai(e,xe)||void 0},[q,be,xe,A]),Ce=Z.useMemo(()=>{if(q||!ge||!_e)return!1;let e=A.find(e=>e.id===ge);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===_e)?.variants;return!!(t&&Object.keys(t).length>0)},[q,_e,ge,A]),we=dk(ye),Te=dk(be??void 0),Ee=dk(xe??void 0),De=dk(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,je=De??void 0,Me=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Pe=Z.useMemo(()=>q?!0:!!(Me&&Me>0),[q,Me]),Fe=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Ie=Z.useMemo(()=>{if(q)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}},[q,e.info]),Re=Z.useMemo(()=>Ur(ce,{includeReasoning:j}),[ce,j]),ze=Z.useMemo(()=>q?Re:!Pe&&N===`sorted`?[]:Re,[N,Pe,q,Re]),Be=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`text`),[q,Re]),Ve=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`tool`),[q,Re]),He=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of Ve){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=nk(t.tool);!r||!tk.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=nk(t.part.tool);!n||!tk.has(n)||e.add(t.id)}return e},[P,Ve,a?.activityParts]),Ue=Z.useMemo(()=>{if(He.size===0&&W.size===0)return H;let e=new Set(H);return He.forEach(t=>{W.has(t)||e.add(t)}),W.forEach(t=>{e.delete(t)}),e},[W,He,H]),We=Z.useMemo(()=>{if(!q)return;let e=ce.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[q,ce]),Ge=q&&!yn(ze),Ke=typeof Fe!=`string`,qe=Z.useMemo(()=>q?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,q]),Je=Z.useMemo(()=>!q&&Vx.getInstance().shouldAnimateMessage(e.info,x||e.info.sessionID),[e.info,x,q]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?VO(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=KO({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),tt=Z.useMemo(()=>q?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,q,Ze]),nt=Z.useMemo(()=>Pe?`completed`:c?l??`streaming`:`completed`,[l,c,Pe]);Z.useEffect(()=>{!q||!u||d?.(e.info.id)},[u,q,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;q||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,q,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(q)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,q,a,nt,e.info.id]),it=Z.useCallback(e=>{ct(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),at=q?void 0:a?.userMessageVariant??le?.variant,st=!q&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,lt=Z.useMemo(()=>{if(!q)return XO(e.info?.error,p(`chat.messageBody.aborted`))},[q,e.info,p]),ut=lt?.text,dt=lt?.variant,ft=Z.useMemo(()=>{if(q){let e=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6575
6575
|
|
|
6576
6576
|
`);let t=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.command;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);return t.length>0?t.join(`
|
|
6577
6577
|
`):ze.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 ut&&ut.trim().length>0?ut:ar(ze)},[ut,ze,q]),pt=ft.length>0,mt=Z.useCallback(async()=>(await ct(ft)).ok?(q&&(R(!0),setTimeout(()=>R(!1),2e3)),!0):!1,[q,ft]),ht=Z.useCallback(async()=>{if(!(!re||!e.info.id||V.current)){V.current=`revert`,B(`revert`);try{_.onRevertMessage?await _.onRevertMessage(e.info.id):await w(re,e.info.id,{directory:_.directory??void 0})}finally{V.current=null,B(null)}}},[re,e.info.id,w,_]),gt=J(()=>{if(!re||!e.info.id||V.current)return;let t={info:e.info,parts:e.parts};if(_.onEditMessage){_.onEditMessage(e.info.id,t).catch(()=>{});return}T(re,e.info.id,t).catch(()=>{})}),_t=J(()=>{re&&k(re)}),vt=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(!V.current){V.current=`fork`,B(`fork`);try{await E(re,e.info.id)}finally{V.current=null,B(null)}}},[re,e.info.id,E]),yt=J(t=>{let n=He.has(t),r=Ue.has(t);if(n){ee(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),$O(e.info.id,i),i}),r||U(n=>{let r=new Set(n);return r.delete(t),ZO(e.info.id,r),r});return}U(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),ZO(e.info.id,r),r}),ee(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),$O(e.info.id,r),r})}),bt=i??null,xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1),wt=Z.useRef(!1),Tt=Z.useRef(!1),Et=Z.useRef(!1);Z.useEffect(()=>{St.current=!1,Ct.current=!1,wt.current=!1,Tt.current=!1,xt.current=!1,Et.current=!1},[e.info.id]);let Dt=Z.useCallback(()=>{q||xt.current||(xt.current=!0,r?.(`structural`))},[q,r]),Ot=s(e=>e.setImagePreviewOpen),kt=Z.useCallback(e=>{(e.image||e.mermaid)&&(K(e),Ot(!0))},[Ot]),At=Z.useCallback(e=>{K(t=>({...t,open:e})),Ot(e)},[Ot]),jt=!!ak(e.info,`animationSettled`),Mt=nt===`streaming`||nt===`cooldown`;Mt&&(Et.current=!0);let Nt=Z.useMemo(()=>!q&&Re.some(e=>e.type===`reasoning`),[q,Re]),Pt=Je&&!jt&&!Mt&&!Et.current,Ft=!q&&Je&&Be.length>0&&!qe;return Z.useEffect(()=>{if(bt?.onStreamingCandidate){if(!Ft){Ct.current&&=(Nt&&bt?.onReasoningBlock?bt.onReasoningBlock():bt?.onReservationCancelled&&bt.onReservationCancelled(),!1);return}Tt.current||(Tt.current=!0,bt.onStreamingCandidate(),Ct.current=!0)}},[bt,Ft,Nt]),Z.useEffect(()=>{bt?.onAnimationStart&&Pt&&(wt.current||=(bt.onAnimationStart(),!0))},[bt,Pt]),Z.useEffect(()=>{if(q)return;let e=bt?.onAnimatedHeightChange;if(!e||!(Pt||Ft))return;let t=b.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[Pt,q,bt,Ft]),Ge?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,q?m?`pt-2`:`pt-6`:!q&&rt?m?M?`pt-4`:`pt-0`:`pt-6`:`pt-0`,q||tt?`pb-0`:et?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:b,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:q?yn(ze)?(0,$.jsx)(gc,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,m?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)(DO,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:q,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:it,expandedTools:H,onToggleTool:yt,onShowPopup:kt,streamPhase:nt,allowAnimation:Pt,onContentChange:r,shouldShowHeader:!1,hasTextContent:pt,onCopyMessage:mt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!D&&v.edit?gt:void 0,onRevert:!D&&v.revert?ht:void 0,onFork:!D&&q&&v.fork?vt:void 0,editing:D,editStaged:O,onCancelEdit:O?_t:void 0,pendingMessageAction:z,errorMessage:ut,errorVariant:dt,userActionsMode:te?`external-content`:`inline`,stickyUserHeaderEnabled:M})}),te?(0,$.jsx)(DO,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:q,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:it,expandedTools:H,onToggleTool:yt,onShowPopup:kt,streamPhase:nt,allowAnimation:Pt,onContentChange:r,shouldShowHeader:!1,hasTextContent:pt,onCopyMessage:mt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!D&&v.edit?gt:void 0,onRevert:!D&&v.revert?ht:void 0,onFork:!D&&q&&v.fork?vt:void 0,editing:D,editStaged:O,onCancelEdit:O?_t:void 0,pendingMessageAction:z,errorMessage:ut,errorVariant:dt,userActionsMode:`external-actions`,stickyUserHeaderEnabled:M}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[rt&&(0,$.jsx)(zx,{isUser:q,isMobile:m,providerID:ke,modelID:Ae,agentName:Oe,modelName:je,variant:st}),(0,$.jsx)(DO,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Re,sourceParts:ce,isUser:q,isMessageCompleted:Pe,messageFinish:Fe,messageCompletedAt:Me??void 0,messageCreatedAt:Ne??void 0,messageTokens:Ie,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:it,expandedTools:Ue,onToggleTool:yt,onShowPopup:kt,streamPhase:nt,allowAnimation:Pt,onContentChange:r,shouldShowHeader:rt,hasTextContent:pt,onCopyMessage:mt,copiedMessage:L,onAuxiliaryContentComplete:Dt,showReasoningTraces:j,agentMention:We,turnGroupingContext:a,errorMessage:ut,errorVariant:dt,reviewTransferDirection:f})]})})}),G.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(WO,{popup:G,onOpenChange:At,isMobile:m})}):null]})},(e,t)=>VS({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&HS(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&HS(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&&XS(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,PO(e.message.info).isUser)),sk=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},ck=e=>{let t=e?.type;return t===`compaction`||t===`text`&&sk(e).trim()===`/compact`},lk=e=>e?e.some(e=>ck(e)):!1,uk=e=>lk(e.parts),dk=e=>e?lk(e.sourceParts)||lk(e.parts):!1,fk=e=>{if(!uk(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}},pk=e=>{let t=hn(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},mk=new WeakMap,hk=e=>{let t=mk.get(e);if(t)return t;let n=fk(pk(e)),r=n.parts,i=yi(r),a=i===r?n:{...n,parts:i,sourceParts:r};return mk.set(e,a),a},gk={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},_k=[],vk=`\0`,yk=new Set([`edit`,`write`,`multiedit`,`apply_patch`]),bk={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,multiedit:`chat.assistantStatus.editingFiles`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`,plan_enter:`chat.assistantStatus.switchingToPlanning`,plan_exit:`chat.assistantStatus.switchingToBuilding`},xk=[`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`],Sk=(e,t)=>{let n=bk[e];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},Ck=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)},wk=(e,t)=>t(xk[Ck(e)%xk.length]??`chat.assistantStatus.working`),Tk=(e,t,n)=>{let r,i;if(!Qt(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??jk(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=Mk(n);yk.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=Ak(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=jk(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?i===`multiedit`?Sk(i,n):n(`chat.assistantStatus.editingFile`):r===`tool`&&i?Sk(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):wk(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},Ek=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(vk),Dk=e=>{let[t,n,r=`working`,i]=e.split(vk);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},Ok=e=>e.type===`reasoning`,kk=e=>e.type===`text`,Ak=e=>{if(kk(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},jk=e=>(kk(e)||Ok(e),e.time),Mk=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function Nk(e,t){let{t:n}=ot(),r=Zr(e=>e.currentSessionId),i=Zr(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),c=Zr(s),l=di(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=xr(d??``,o??void 0,a??void 0),h=xr(p??``,o??void 0,a??void 0),g=!!p&&lk(h),_=!!(d&&XT(u.finish,m,u.error)),v=Z.useMemo(()=>{let e=`${a??``}:${d??``}`;return Ek(Tk(d?m:_k,e,n))},[a,d,m,n]),y=ei(a??``,o??void 0),b=Pi(a??``,o??void 0),x=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),S=Zr(x),{phase:C,isWorking:w}=jg(a,o??void 0),T=wr(a??``,o??void 0),E=T?.type===`retry`?T.attempt:void 0,D=T?.type===`retry`?T.next:void 0,O=Z.useMemo(()=>Dk(v),[v]),k=Z.useMemo(()=>{let e=!!(S&&!S.acknowledged);return{wasAborted:e,abortActive:e}},[S]),A=Z.useMemo(()=>{if(k.wasAborted)return{...gk,wasAborted:!0,abortActive:k.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(_)return{...gk,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 Pk=Z.memo(()=>{let e=(0,Q.c)(14),t=Ph(),n=Zr(Fk),r=Zr(Ik),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=Zr(o),c=Zr(Lk),l=Zr(Rk),{working:u}=Nk(i,a),d=Qr(zk),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)(zh,{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});Pk.displayName=`StatusRowContainer`;function Fk(e){return e.currentSessionId}function Ik(e){return e.currentSessionDirectory}function Lk(e){return e.abortPromptSessionId}function Rk(e){return e.abortPromptExpiresAt}function zk(e){return e.currentAgentName}var Bk=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}),Vk=new Set,Hk=()=>{},Uk=()=>{},Wk=Z.memo(e=>{let t=(0,Q.c)(32),{turn:n,activityExpanded:r,showCompactionStatus:i,pendingAssistantHeader:a,onToggleActivity:o,stickyUserHeader:c,renderMessage:l}=e,u=a===void 0?null:a,d=c===void 0||c,f=s(Gk),p=n.userMessage.info.time?.created,m=n.activityPresentationKind===`compaction`,h=`turn-${n.turnId}`,g;t[0]!==r||t[1]!==m||t[2]!==l||t[3]!==d||t[4]!==n.userMessage?(g=m?null:d?(0,$.jsxs)(`div`,{className:`sticky top-0 z-20 relative bg-[var(--surface-background)] [overflow-anchor:none]`,children:[(0,$.jsx)(`div`,{className:`relative z-10`,children:l(n.userMessage,r)}),(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-full z-0 h-4 bg-gradient-to-b from-[var(--surface-background)] to-transparent sm:h-8`})]}):l(n.userMessage,r),t[0]=r,t[1]=m,t[2]=l,t[3]=d,t[4]=n.userMessage,t[5]=g):g=t[5];let _;t[6]!==f||t[7]!==u||t[8]!==d||t[9]!==n.assistantMessages?(_=u?(0,$.jsx)(`div`,{className:`group w-full ${f?d?`pt-4`:`pt-0`:`pt-6`} ${n.assistantMessages.length===0?`pb-1`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(zx,{isUser:!1,isMobile:f,providerID:u.providerID,modelID:u.modelID,agentName:u.agentName,modelName:u.modelName,variant:u.variant})})}):null,t[6]=f,t[7]=u,t[8]=d,t[9]=n.assistantMessages,t[10]=_):_=t[10];let v;t[11]!==r||t[12]!==f||t[13]!==o||t[14]!==i||t[15]!==n.assistantMessages||t[16]!==n.completionDisposition||t[17]!==n.durationMs||t[18]!==p?(v=i?(0,$.jsx)(`div`,{className:`group w-full ${f?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(WD,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof p==`number`?p:void 0,onToggle:o,isMobile:f,expandedTools:Vk,onToggleTool:Hk,onShowPopup:Uk,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[11]=r,t[12]=f,t[13]=o,t[14]=i,t[15]=n.assistantMessages,t[16]=n.completionDisposition,t[17]=n.durationMs,t[18]=p,t[19]=v):v=t[19];let y;t[20]!==r||t[21]!==l||t[22]!==n.assistantMessages?(y=(0,$.jsx)(Bk,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:l}),t[20]=r,t[21]=l,t[22]=n.assistantMessages,t[23]=y):y=t[23];let b;return t[24]!==r||t[25]!==h||t[26]!==g||t[27]!==_||t[28]!==v||t[29]!==y||t[30]!==n.turnId?(b=(0,$.jsxs)(`section`,{className:`relative w-full`,id:h,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[g,_,v,y]}),t[24]=r,t[25]=h,t[26]=g,t[27]=_,t[28]=v,t[29]=y,t[30]=n.turnId,t[31]=b):b=t[31],b});function Gk(e){return e.isMobile}var Kk=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,qk=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},Jk=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},Yk=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},Xk=(e,t,n,r)=>({id:Kk(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:qk(n)}),Zk=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`&&Jk(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&JT(Yk(t),t.parts));e.assistantMessages.forEach(n=>{let r=Yk(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`?Jk(o):void 0,u=Kk(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&JT(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({...Xk(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}},Qk=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}},$k=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(JT(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!YT(t))continue;let r=$k(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:Kk(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=$k(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:Kk(n.info.id,t,e)}}}return{}},tA=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}},nA=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},rA=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},iA=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},oA=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},sA=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},cA=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},lA=(e,t)=>{let n=rA(e);return{messageId:e.info.id,role:n,parentMessageId:iA(e),message:e,order:t}},uA=(e,t)=>{let n=aA(e),r,i,a=!1;t.forEach(e=>{let t=oA(e);typeof t==`number`?r=Math.max(r??0,t):a=!0,e.parts.forEach(e=>{let t=sA(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}},dA=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`||qT(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 oA(t)!=`number`)return`active`;return`active`},fA=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return XT(n.finish,t.parts,n.error)},pA=e=>dk(e)?`compaction`:`default`,mA={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},hA=(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},gA=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&hA(e.assistantMessages,t.assistantMessages),_A=(e,t)=>{e.summary=eA(e.assistantMessages),e.summaryText=e.summary.text??cA(e.userMessage),e.diffStats=tA(e.userMessage),e.changedFiles=t.showTurnChangedFiles?nA(e.userMessage):void 0,e.completionDisposition=dA(e.assistantMessages),e.hasConfirmedFinalBody=fA(e.assistantMessages),e.activityPresentationKind=pA(e.userMessage);let n=Zk({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=uA(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},vA=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>_A(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&&gA(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,_A(e,t))});return r&&i?n.turns:a},yA=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},bA=(e,t)=>{let n={...mA,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(rA(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[lA(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(rA(e)!==`assistant`)return;let n=iA(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(lA(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=Qk(yA(vA(r,n))),s=new Set;return e.forEach(e=>{rA(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},xA=30,SA=4,CA=4,wA=33554432,TA=8388608,EA=new Map,DA=new Map,OA=0,kA=new WeakMap,AA=1,jA=()=>d()?SA:bt()?CA:xA,MA=()=>d()||bt()?TA:wA,NA=(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},PA=e=>{EA.delete(e);let t=DA.get(e)??0;DA.delete(e),OA=Math.max(0,OA-t)},FA=e=>{let t=kA.get(e);if(t!==void 0)return t;let n=AA;return AA+=1,kA.set(e,n),n},IA=e=>e.map(e=>`${FA(e.info)}:${FA(e.parts)}:${e.parts.map(e=>FA(e)).join(`,`)}`).join(`;`),LA=(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,IA(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},RA=e=>{let t=EA.get(e);return t&&(EA.delete(e),EA.set(e,t)),t},zA=(e,t)=>{PA(e);let n=jA(),r=MA(),i=NA(e,t);if(!(i>r)){for(;EA.size>=n||OA+i>r;){let e=EA.keys().next().value;if(typeof e!=`string`)break;PA(e)}EA.set(e,t),DA.set(e,i),OA+=i}},BA=[],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=>{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},UA=(e,t)=>t===null?{staticTurns:e,streamingTurns:BA}:{staticTurns:t===0?BA:e.slice(0,t),streamingTurns:e.slice(t)},WA=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(BA),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=BA,a.current=null);let l=Z.useMemo(()=>{let r=LA(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=RA(r);return i?(n.current=i,i):Se(`ui.turns.projection_ms`,()=>{let i=bA(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,zA(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=HA({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=UA(l.turns,u).staticTurns;return VA(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=UA(l.turns,u).streamingTurns;return VA(i.current,e)?i.current:i.current=e},[u,l.turns])}},GA=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},KA=(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(GA(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(GA(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},qA=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=Lt(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:hk({...e,parts:r})},JA=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=qA(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=qA(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=bA([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}},YA=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},XA=2,ZA=2,QA=e=>Math.min(Math.max(0,e),XA),$A=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+ZA),ej=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(xC.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},tj=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ss.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},nj=12,rj=16,ij=new Map,aj=e=>{let t=ij.get(e);if(t)return ij.delete(e),ij.set(e,t),t},oj=(e,t)=>{if(t.size!==0)for(ij.delete(e),ij.set(e,t);ij.size>rj;){let e=ij.keys().next().value;if(typeof e!=`string`)break;ij.delete(e)}},sj=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??nj)),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},cj=(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},lj=({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}},uj=e=>{let{visible:t,preload:n}=lj(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},dj=(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},fj=(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}},pj=(e,t)=>{let n=fj(e,t);return n===null?null:{anchor:n,knownKeys:new Set(t)}},mj=15e3,hj=(e,t)=>{let n=e.positionByKey(t.key);return n===void 0||!Number.isFinite(n)?null:n-t.offsetFromViewportTop},gj=(e,t)=>{if(!Number.isFinite(e.scroll))return null;let n=hj(e,t);return n===null?null:e.scroll-n},_j=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}},vj=1;function yj(e,{offset:t=0,hideTopShadow:n=!1,hideBottomShadow:r=!1}={}){let i=e.scrollTop>t+vj,a=e.scrollHeight-(e.scrollTop+e.clientHeight)>t+vj,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 bj(e,t=48){e.dataset.scrollShadow=`true`,e.dataset.orientation=`vertical`,e.style.setProperty(`--scroll-shadow-size`,`${t}px`)}var xj=.4,Sj=e=>!Number.isFinite(e)||e<=0?0:e*xj,Cj=(e,t=16)=>Number.isFinite(e)&&e>0?e:t,wj=({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),Tj=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)},Ej=({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))},Dj=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),Oj=`data-oc-timeline-park-end`,kj=e=>{if(!e)return null;let t=e.getAttribute(Oj);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},Aj=(e,t)=>{if(!e)return;if(t===null||!Number.isFinite(t)){e.hasAttribute(`data-oc-timeline-park-end`)&&e.removeAttribute(Oj);return}let n=String(Math.round(t));e.getAttribute(`data-oc-timeline-park-end`)!==n&&e.setAttribute(Oj,n)},jj=(e,t)=>t!==null&&Number.isFinite(t)?Dj({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),Mj=({usableViewportHeight:e,viewportHeight:t,contentHeight:n})=>{if(!Number.isFinite(e)||e<=0)return 0;let r=Sj(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))},Nj=(e,t)=>!Number.isFinite(e)||!Number.isFinite(t)||t<=0?!1:e>t+1,Pj=({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,Fj=({previous:e,reserveId:t,entryKey:n,contentHeight:r,usableViewportHeight:i,viewportHeight:a})=>{let o=Mj({usableViewportHeight:i,viewportHeight:a,contentHeight:r}),s=r!==null&&Nj(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&&Pj({previousEndSpaceSize:e.spacerHeight,nextEndSpaceSize:o})?{snapshot:{...c,spacerHeight:0},release:!0}:{snapshot:c,release:!1}},Ij=(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)},Lj=({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=Ij(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=wj({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}},Rj=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},zj=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))},Bj=(e,t)=>e===void 0||!Number.isFinite(e)?t:e<=40?!1:e>=80||t,Vj=(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)},Hj=`data-oc-timeline-anchoring`,Uj=1200,Wj=(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}}},Gj=({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},Kj=(e,t)=>!Number.isFinite(t)||t<=0||typeof e!=`number`||!Number.isFinite(e)||t+1>=e?null:t,qj={itemVisiblePercentThreshold:0},Jj=100,Yj=116,Xj=500,Zj=new Set,Qj=Z.createContext(Zj),$j=`oc-reply-reserve`,eM=e=>e.kind===$j,tM=e=>{if(eM(e))return e.spacerHeight>0?e.spacerHeight:void 0},nM=(e,t,n,r,i)=>{if(!e||t)return null;let a=Lj({state:n,anchorIndex:e.anchorIndex,lastIndex:e.anchorIndex,endInsetHeight:r,anchorOffset:i});return a?Ej({anchorTop:a.anchorTop,anchorOffset:i,maxScrollOffset:Tj(n)}):null},rM=(e,t)=>{if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t;let n=e?.clientHeight??0;return n>0?n:0},iM=e=>e.key,aM=e=>e.kind,oM=()=>{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);at(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},sM=({entry:e,index:t,renderEntryRef:n,onMeasuredSizeRef:r})=>{let i=Z.useContext(Qj),a=Z.useRef(null);return Z.useLayoutEffect(()=>{let t=a.current;if(!t||typeof ResizeObserver>`u`)return;let n=()=>{let n=t.offsetHeight,i=t.offsetWidth;n>0&&r.current?.(e.key,{height:n,width:i})},i=new ResizeObserver(n);return i.observe(t),n(),()=>i.disconnect()},[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))})},cM=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,sessionIsWorking:h=!1,onIsAtEndChange:g,onScroll:_,header:v,footer:y,className:b,style:x,contentContainerClassName:S,contentContainerStyle:C})=>{let w=Z.useRef(null),T=Z.useMemo(()=>e.map(e=>e.key),[e]),E=Z.useRef(T);E.current=T;let D=Z.useRef(r);D.current=r;let O=J(e=>{w.current=e,u?.(e)}),k=Z.useRef(null),[A,j]=Z.useState(null),[M,N]=Z.useState(0),{height:P,setElement:F}=oM(),{height:I,heightRef:L,setElement:R}=oM(),z=v==null?null:(0,$.jsx)(`div`,{ref:F,"data-oc-timeline-header":``,children:v}),B=y==null?null:(0,$.jsx)(`div`,{ref:R,"data-oc-timeline-footer":``,children:y}),V=Z.useRef(c);V.current=c;let H=Z.useRef(l);H.current=l;let U=J((e=k.current)=>{!e||s?.scrollShadow!==`true`||(bj(e),yj(e,{hideTopShadow:V.current,hideBottomShadow:H.current}))}),W=J(e=>{let t=e?.getScrollableNode?.()??null;if(t&&s){for(let[e,n]of Object.entries(s))t.dataset[e]=n;U(t)}k.current=t,o&&(o.current=t),j(t);let n=rM(t,w.current?.getState()?.scrollLength);N(e=>e===n?e:n)}),ee=J(()=>{let e=rM(k.current,w.current?.getState()?.scrollLength);N(t=>t===e?t:e),U()});Z.useLayoutEffect(()=>{U(A)},[l,c,A]),at(typeof ResizeObserver<`u`?A:null,ee);let[G,K]=Z.useState(0),[q,te]=Z.useState(0),ne=G!==q,re=Z.useRef(!0),ie=Z.useRef(!1),[ae,oe]=Z.useState(!1),se=Z.useRef(!1);Z.useLayoutEffect(()=>{re.current=!0,ie.current=!1,se.current=!1,oe(!1)},[t]);let[ce,le]=Z.useState(null),ue=J(e=>{le(t=>t?.token===e?null:t)});Z.useEffect(()=>{p&&le(null)},[p]),Z.useLayoutEffect(()=>{if(m<=0)return;let e=w.current;if(!e)return;let t=pj(e.getState(),E.current);t&&le({token:m,arm:t,holding:!1})},[m]),Z.useEffect(()=>{if(!ce||ce.holding)return;let{token:e}=ce,t=window.setTimeout(()=>{le(t=>t?.token===e&&!t.holding?null:t)},mj);return()=>window.clearTimeout(t)},[ce]);let de=Z.useRef(T);Z.useLayoutEffect(()=>{let e=de.current;de.current=T,Vj(e,T)&&(K(e=>e+1),le(e=>e===null||e.holding?e:{...e,holding:!0}))},[T]),Z.useEffect(()=>{if(!ne)return;let e=window.setTimeout(()=>{te(G)},Uj);return()=>window.clearTimeout(e)},[ne,G]),Z.useEffect(()=>{if(!ce?.holding)return;let{token:e,arm:{anchor:t}}=ce,n=w.current;if(!n||typeof window>`u`){ue(e);return}let r=k.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&&ue(e)}},d=()=>{if(s=null,c)return;let e=n.getState();if(Rj(e)??e.isAtEnd){u(!0);return}let r=Date.now(),l=_j({drift:gj(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=hj(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)}},[ue,ce]);let fe=ne||ce!==null;Z.useLayoutEffect(()=>{let e=k.current;if(!(!e||!fe))return e.setAttribute(Hj,`true`),()=>{e.removeAttribute(Hj)}},[fe]);let pe=Z.useMemo(()=>{if(ce===null)return{data:!0,size:ne};let{knownKeys:e}=ce.arm;return{data:!0,size:!0,shouldRestorePosition:t=>e.has(t.key)}},[ce,ne]),[me,he]=Z.useState(()=>sj(T,{restore:aj(t)??null})),ge=Z.useRef(me);ge.current=me;let _e=Z.useRef(0),ve=Z.useRef(0),ye=Z.useRef(null),be=Z.useRef(!1),xe=Z.useRef(null),Se=Z.useMemo(()=>cj(me,T),[me,T]);Z.useEffect(()=>{he(e=>dj(e,T))},[T]),Z.useEffect(()=>()=>{oj(t,ge.current)},[t]);let Ce=J(()=>{be.current=!1;let e=w.current;if(!e)return;let t=E.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()-_e.current>=Jj,d=D.current,f=d.resolvePreloadEntries(l),p=uj({entryKeys:t,mountedIndexes:o,visibleStartIndex:s,visibleEndIndex:c,scrollDirection:ye.current,preloadEntries:f,hydratedKeys:ge.current,allowVisibleRelease:u,preloadReleaseLimit:u?f:d.resolvePreloadReleaseWhileScrolling(),visibleReleaseLimit:d.resolveVisibleReleaseLimit()});p.length!==0&&(Te(),Z.startTransition(()=>{he(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})}))}),we=J(()=>{be.current||(be.current=!0,mc(Ce))}),Te=J(()=>{typeof window>`u`||(xe.current!==null&&window.clearTimeout(xe.current),xe.current=window.setTimeout(()=>{xe.current=null,we()},Yj))});Z.useEffect(()=>()=>{xe.current!==null&&(window.clearTimeout(xe.current),xe.current=null)},[]);let Ee=J(()=>{we()}),De=J(()=>{_e.current=Date.now();let e=w.current;if(e){let t=e.getState(),n=t.scroll;Number.isFinite(n)&&n!==ve.current&&(ye.current=n>ve.current?`forward`:`backward`,ve.current=n);let r=rM(k.current,t.scrollLength);r>0&&N(e=>e===r?e:r);let i=nM(Ue.current,Me.current,t,L.current,Ge.current);Aj(k.current,i);let a=i===null?null:Dj({scroll:t.scroll,parkOffset:i}),o=a??zj(t),s=a===null?Rj(t)??t.isAtEnd:a<=40,c=Bj(o,ie.current);(s!==re.current||c!==ie.current)&&(re.current=s,ie.current=c,g?.(s,c)),s&&!se.current&&(se.current=!0,oe(!0))}_?.(),U(),we(),Te()}),Oe=Z.useRef(i);Oe.current=i;let[ke,Ae]=Z.useState(null),je=Z.useRef(null),Me=Z.useRef(!1),Ne=Z.useRef(null),Pe=Z.useRef(null),Fe=Z.useRef(0),Ie=Z.useRef(0),Le=Z.useRef(null),Re=J((e,t)=>{let n=w.current,r=n?.getState().sizes.get(e);if(n&&Kj(r,t.height)!==null&&n.setItemSize(e,t),Me.current||e!==Pe.current)return;let i=Ne.current;if(i===null)return;let{snapshot:a,release:o}=Fj({previous:je.current,reserveId:i,entryKey:e,contentHeight:t.height,usableViewportHeight:Fe.current,viewportHeight:Ie.current});if(o){Ae(null),nt(i),rt(`reveal`);return}let s=je.current;(s?.spacerHeight!==a.spacerHeight||s?.contentHeight!==a.contentHeight||s?.entryKey!==a.entryKey||s?.reserveId!==a.reserveId)&&Ae(a),Le.current!==i&&rt(`park`)&&(Le.current=i)}),ze=Z.useRef(Re);ze.current=Re;let Be=Z.useMemo(()=>({item:e,index:t})=>eM(e)?(0,$.jsx)(`div`,{"data-oc-reply-reserve":`true`,"aria-hidden":`true`,style:{height:e.spacerHeight,flexShrink:0}}):(0,$.jsx)(sM,{entry:e,index:t,renderEntryRef:Oe,onMeasuredSizeRef:ze}),[]),Ve=Z.useRef(p);Ve.current=p;let He=Z.useRef(ce);He.current=ce;let Ue=Z.useRef(d);Ue.current=d;let We=Z.useRef(0),Ge=Z.useRef(16),Ke=Z.useRef(null),[qe,Je]=Z.useState(null),Ye=d?e[d.anchorIndex]?.key??null:null,Xe=d?.anchorId??Ye,Ze=Xe!==null&&qe===Xe;d||(Le.current=null,We.current=0);let Qe=M>0?M:rM(k.current,w.current?.getState()?.scrollLength),$e=Cj(P),et=wj({viewportHeight:Qe,endInsetHeight:I,anchorOffset:$e}),tt=ke;if(!Xe||!Ye||Ze)ke!==null&&Ae(null),tt=null;else if(et<=0)tt=ke!==null&&ke.reserveId===Xe&&ke.entryKey===Ye?ke:null;else if(ke===null||ke.reserveId!==Xe||ke.entryKey!==Ye){let{snapshot:e}=Fj({previous:ke?.reserveId===Xe?ke:null,reserveId:Xe,entryKey:Ye,contentHeight:ke?.reserveId===Xe?ke.contentHeight:null,usableViewportHeight:et,viewportHeight:Qe});Ae(e),tt=e}je.current=tt,Me.current=Ze,Ne.current=Xe,Pe.current=Ye,Fe.current=et,Ie.current=Qe,Ge.current=$e,Z.useLayoutEffect(()=>{Le.current=null,We.current=0,Ke.current=null,Je(null)},[t]),Z.useLayoutEffect(()=>{d&&ee()},[d]);let nt=J(e=>{e!==null&&Ke.current!==e&&(Ke.current=e,Je(e),f?.(e))}),rt=J(t=>{let n=Ue.current;if(!n||He.current)return!1;let r=w.current;if(!r)return!1;let i=r.getState(),a=Ge.current,o=Lj({state:i,anchorIndex:n.anchorIndex,lastIndex:n.anchorIndex,endInsetHeight:L.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&&(We.current=t+Xj),r.scrollToOffset({offset:e,animated:n}),!0}return Nj(o.turnHeight,Fe.current)&&nt(n.anchorId??e[n.anchorIndex]?.key??null),(typeof performance<`u`?performance.now():Date.now())<We.current||!Ve.current||o.scrollDeltaToRevealEnd<1?!1:(r.scrollToOffset({offset:o.targetScrollToRevealEnd,animated:!1}),!0)});Z.useLayoutEffect(()=>{if(!Xe||!Ye||Ze||et<=0)return;let e=je.current;if(e===null||e.reserveId!==Xe||e.entryKey!==Ye)return;let{snapshot:t,release:n}=Fj({previous:e,reserveId:Xe,entryKey:Ye,contentHeight:e.contentHeight,usableViewportHeight:et,viewportHeight:Qe});if(n){Ae(null),nt(Xe),rt(`reveal`);return}t.spacerHeight!==e.spacerHeight&&Ae(t)},[Ye,Ze,Xe,Qe,et]),Z.useLayoutEffect(()=>{!tt||ce||Le.current!==Xe&&rt(`park`)&&(Le.current=Xe)},[tt,ce,Xe]),Z.useLayoutEffect(()=>{let e=k.current,t=w.current;if(e){if(!t){Aj(e,null);return}Aj(e,nM(d,Ze,t.getState(),I,$e))}},[d,I,$e,Ze]);let it=Z.useMemo(()=>{let t=tt?.spacerHeight??0;return!tt||t<=0?e:[...e,{key:`${$j}:${tt.reserveId}`,kind:$j,spacerHeight:t}]},[tt,e]),ot=Z.useMemo(()=>d&&!Ze||!p||ce?!1:{animated:h&&ae,on:{dataChange:!0,itemLayout:!0,layout:!0,footerLayout:!0}},[d,ae,p,ce,Ze,h]);return(0,$.jsx)(Qj.Provider,{value:Se,children:(0,$.jsx)($c,{ref:O,refScrollView:W,data:it,extraData:a,keyExtractor:iM,getItemType:aM,getFixedItemSize:tM,renderItem:Be,estimatedItemSize:n,initialScrollAtEnd:!0,recycleItems:!1,maintainScrollAtEnd:ot,maintainVisibleContentPosition:pe,onScroll:De,onViewableItemsChanged:Ee,viewabilityConfig:qj,ListHeaderComponent:z,ListFooterComponent:B,className:b,style:x,contentContainerClassName:S,contentContainerStyle:C})})}),lM=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},uM=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},dM=e=>!e||lM(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`)}),fM=(e,t)=>{if(lM(e)!==`assistant`||t&&uM(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}}},pM=(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(lM(t)===`user`)break;let{hide:i,details:a}=fM(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},mM=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},hM=(e,t)=>{if(e.length===0)return[];if(e.filter(mM).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},gM=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=QT({finish:r.finish,isMessageCompleted:mM(n),activeStreamingPhase:e.activeStreamingPhase});return $T({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},_M=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},vM=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=_M(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},yM=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},bM=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=yM(t.mode)??yM(t.agent),r=yM(t.providerID),i=yM(t.modelID),a=yM(t.model?.variant)??yM(t.variant);return!n&&!r&&!i&&!a?null:{agentName:n,providerId:r,modelId:i,variant:a}},xM=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:Ai(void 0,t)||void 0,variant:e?.variant}},SM=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),CM=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:FO(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),wM=5,TM=[],EM=new Set,DM=[],OM=16,kM=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),AM=320,jM=168,MM=8,NM=16,PM=6,FM=12,IM=4,LM=1,RM=2,zM=6,BM=4,VM=()=>bt()?NM:MM,HM=30,UM=180,WM=5,GM=2,KM=120,qM=1200,JM=80,YM=160,XM=1500,ZM=1.5,QM=90,$M=(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},eN=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(kM(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)}}}})(OM),tN=(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})},nN=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),rN=e=>e===`collapsed`?jM:AM,iN=(e,t)=>`${e}::activity:${t}`,aN=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),oN=(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}},sN=(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)},cN=(e,t=0)=>Math.max(e===`collapsed`?FM:PM,Math.max(0,Math.floor(t))),lN=e=>e===`collapsed`?RM:LM,uN=e=>e===`collapsed`?BM:zM,dN=e=>e===`collapsed`?GM:WM,fN=(e,t)=>{e.current=t},pN=(e,t)=>eN.read(e,t),mN=(e,t,n)=>{!n||t.length===0||eN.write(e,t,n.takeSnapshot())},hN=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},gN=(e,t)=>{if(hN(e)!==`system`)return e;let n=yN(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},_N=e=>!e||hN(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),vN=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},yN=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},bN=(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},xN=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,SN=(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&&!bN(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}},CN=(e,t)=>{let n=SN(t,e);if(!n)return null;let r=xN(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},wN=e=>{let t=e,n=t.state?.metadata,r=oS(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?uS(i)??null:null},TN=e=>{if(hN(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:wN(e.parts[0])}},EN=(e,t)=>{if(!t)return e;let n=sS(e.parts,t);return n===e.parts?e:{...e,parts:n}},DN=(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}},ON=e=>e.kind===`turn`?e.turn.userMessage.info.id:hN(e.message)===`user`?e.message.info.id:null,kN=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,AN=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=Ph(),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)(ok,{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)(Nh.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 VS(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&HS(e.previousMessage,t.previousMessage)&&HS(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&XS(n,r,e.message.info.id,hN(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});AN.displayName=`MessageRow`;var jN=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=LO({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=CM({expansionDisposition:BO({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(!mM(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=gM({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=hM(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(BN)),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=_M(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=vM(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(VN),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,q;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?(q={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]=q):q=t[57];let te=q,ne;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]!==te||t[83]!==H||t[84]!==F||t[85]!==N[0]?.info.id||t[86]!==N.length?(ne=(e,t)=>{let a=hN(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=LO({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:RO({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:te.summaryBody,activityParts:te.activityParts,activityGroupSegments:te.activityGroupSegments,headerMessageId:te.headerMessageId,diffStats:te.diffStats,changedFiles:te.changedFiles,userMessageCreatedAt:te.userMessageCreatedAt,userMessageVariant:te.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(AN,{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]=te,t[83]=H,t[84]=F,t[85]=N[0]?.info.id,t[86]=N.length,t[87]=ne):ne=t[87];let re=YA(ne),ie;bb4:{if(N===n.assistantMessages){ie=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],ie=e}let ae=ie,oe;bb5:{if(!SM({isLastTurn:r,sessionIsWorking:i,hasAssistantMessages:n.assistantMessages.length>0,activityPresentationKind:n.activityPresentationKind,hasActiveStreamingMessage:!!h})){oe=null;break bb5}let e;t[91]===n.userMessage.info?e=t[92]:(e=xM(bM(n.userMessage.info)),t[91]=n.userMessage.info,t[92]=e),oe=e}let se=oe,ce=H.length>0,le=n.assistantMessages.length>0,ue;t[93]!==c||t[94]!==r||t[95]!==i||t[96]!==ce||t[97]!==le||t[98]!==n.activityPresentationKind||t[99]!==n.completionDisposition?(ue=kN({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:ce,hasAssistantMessages:le,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[93]=c,t[94]=r,t[95]=i,t[96]=ce,t[97]=le,t[98]=n.activityPresentationKind,t[99]=n.completionDisposition,t[100]=ue):ue=t[100];let de;return t[101]!==T||t[102]!==C||t[103]!==se||t[104]!==re||t[105]!==ae||t[106]!==v||t[107]!==ue?(de=(0,$.jsx)(Wk,{turn:ae,activityExpanded:C,onToggleActivity:T,showCompactionStatus:ue,pendingAssistantHeader:se,stickyUserHeader:v,renderMessage:re}),t[101]=T,t[102]=C,t[103]=se,t[104]=re,t[105]=ae,t[106]=v,t[107]=ue,t[108]=de):de=t[108],de});jN.displayName=`TurnBlock`;var MN=Z.memo(e=>{let t=(0,Q.c)(31),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d,reviewTransferDirection:f}=e,{t:p}=ot();if(Bi(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)(AN,{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});MN.displayName=`UngroupedMessageRow`;var NN=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)(MN,{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)(jN,{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)(Pk,{})}),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});NN.displayName=`MessageListEntry`;var PN=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=CN(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&bt();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<YM,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*ZM},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&$M(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<XM)?w.current===null&&(w.current=performance.now()):(w.current=null,k(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);$e(()=>{if(w.current===null)return;let e=performance.now()-w.current>=XM;(!E()||D()||e)&&j()},T?QM:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=VM(),[F,I]=Z.useState(()=>QA(P));Z.useEffect(()=>{if(!(!_||F>=P))return mc(()=>{Z.startTransition(()=>{I(e=>$A(e,P))})})},[F,_,P]);let L=iN(a,u),[R]=Z.useState(()=>_?pN(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=rN(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??tN(N,W.current,V.current));let G=Jc({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{sN(z.current,n.getTotalSize()),qc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:JM,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:ee.current}),K=Z.useRef(null),q=Z.useRef(null);_||(K.current=null);let te=J(()=>{if(!_)return;let e=z.current??r?.current;if(!e)return;let t=e.offsetWidth;if(!aN(K.current,t)){K.current===null&&t>0&&(K.current=t);return}K.current=t,q.current!==null&&clearTimeout(q.current),q.current=setTimeout(()=>{q.current=null,G.measure()},220)}),ne=_&&typeof ResizeObserver<`u`;at(ne?z:null,te),at(ne&&r?r:null,te),et(()=>{q.current!==null&&(clearTimeout(q.current),q.current=null)}),rt(()=>{_&&te()},[_]),rt(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=xN(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 re=G.getVirtualItems(),ie=re.map(e=>e.index),[ae,oe]=Z.useState(()=>sj(N,{seedCount:cN(u),restore:aj(L)})),se=cj(ae,N);se!==ae&&oe(se);let ce=Z.useRef(se);ce.current=se;let le=Z.useRef(null);G.scrollDirection&&(le.current=G.scrollDirection);let ue=G.range?.startIndex??re[0]?.index??Math.max(0,A.length-1),de=G.range?.endIndex??re[re.length-1]?.index??Math.max(0,A.length-1),fe=G.isScrolling,pe=Math.max(0,de-ue+1),me=uj({entryKeys:N,mountedIndexes:ie,visibleStartIndex:ue,visibleEndIndex:de,scrollDirection:le.current,preloadEntries:cN(u,pe),hydratedKeys:se,allowVisibleRelease:!fe,preloadReleaseLimit:fe?lN(u):IM,visibleReleaseLimit:fe?0:uN(u)}),he=me.join(`\0`),ge=Z.useRef(me);ge.current=me,Z.useEffect(()=>{if(!(!_||!he))return mc(()=>{Z.startTransition(()=>{oe(e=>{let t=null;for(let n of ge.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,he]),Z.useEffect(()=>{oe(e=>dj(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=G.itemSizeCache,t=dN(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(qM,Math.max(KM,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(G),()=>{mN(L,M.current.map(e=>e.key),G),oj(L,ce.current),i?.(null)}},[_,G,L]);let _e=YA((e,t=!0)=>(0,$.jsx)(tj,{enabled:t,children:(0,$.jsx)(NN,{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:_e(e)},e.key))});if(t===`tanstack`){let e=oN(re[0]?.start??0,re[re.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:re.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:_e(t,se.has(t.key))},t.key):null})})})}return null});PN.displayName=`StaticHistoryList`;var FN=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)(NN,{...e})}),t[0]=e,t[1]=n),n});FN.displayName=`TailEntry`;var IN=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=xr(_??``,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=JA(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)(FN,{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};IN.displayName=`StreamingTailContent`;var LN=e=>{let t=(0,Q.c)(72),{historyEntries:n,tailEntries:r,timelineCacheKey:i,directory:a,sessionId:o,scrollRef:c,registerList:l,onHistoryContentChange:u,onTailContentChange:d,getAnimationHandlers:f,scrollToBottom:p,stickyUserHeader:m,sessionIsWorking:h,activityRenderMode:g,turnUiStates:_,onToggleTurnGroup:v,chatRenderMode:y,showTurnChangedFiles:b,shouldAnimateUserMessage:x,onUserAnimationConsumed:S,activeStreamingMessageId:C,activeStreamingPhase:w,reviewTransferDirection:T,header:E,footer:D,scrollClassName:O,scrollStyle:k,scrollDataset:A,onScroll:j,followEnabled:M,historyAnchorToken:N,onIsAtEndChange:P,anchoredUserMessageId:F,onAnchoredTurnParkReleased:I}=e,L=M===void 0||M,R=F===void 0?null:F,z=s(HN),B=n.length,V=r.length>0?r[r.length-1]:void 0,H=V?.key??null,U=xr(C??``,a,o??void 0),W;bb0:{if(!V){W=r;break bb0}let e=y===`sorted`,n;t[0]!==C||t[1]!==U||t[2]!==V||t[3]!==b||t[4]!==e?(n=JA(V,{activeStreamingMessageId:C,liveParts:U,showTextJustificationActivity:e,showTurnChangedFiles:b}),t[0]=C,t[1]=U,t[2]=V,t[3]=b,t[4]=e,t[5]=n):n=t[5];let i=n;if(i===V){W=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],W=a}let ee=W,G;t[9]!==n||t[10]!==ee?(G=ee.length>0?[...n,...ee]:n,t[9]=n,t[10]=ee,t[11]=G):G=t[11];let K=G,q;t[12]!==K||t[13]!==R?(q=Wj(K,R,ON,{anchorOffset:16}),t[12]=K,t[13]=R,t[14]=q):q=t[14];let te=q,ne;t[15]===g?ne=t[16]:(ne={resolvePreloadEntries:e=>cN(g,e),resolvePreloadReleaseWhileScrolling:()=>lN(g),resolveVisibleReleaseLimit:()=>uN(g)},t[15]=g,t[16]=ne);let re=ne,ie;t[17]!==C||t[18]!==w||t[19]!==g||t[20]!==y||t[21]!==B||t[22]!==H||t[23]!==T||t[24]!==h||t[25]!==b||t[26]!==m||t[27]!==_?(ie={historyCount:B,newestTailKey:H,sessionIsWorking:h,activityRenderMode:g,turnUiStates:_,chatRenderMode:y,showTurnChangedFiles:b,stickyUserHeader:m,activeStreamingMessageId:C,activeStreamingPhase:w,reviewTransferDirection:T},t[17]=C,t[18]=w,t[19]=g,t[20]=y,t[21]=B,t[22]=H,t[23]=T,t[24]=h,t[25]=b,t[26]=m,t[27]=_,t[28]=ie):ie=t[28];let ae=ie,oe;t[29]!==C||t[30]!==w||t[31]!==g||t[32]!==y||t[33]!==f||t[34]!==B||t[35]!==H||t[36]!==u||t[37]!==d||t[38]!==v||t[39]!==S||t[40]!==T||t[41]!==p||t[42]!==h||t[43]!==x||t[44]!==m||t[45]!==_?(oe=(e,t,n)=>{let r=t>=B,i=H!==null&&e.key===H;return(0,$.jsx)(yc,{disabled:!r,children:(0,$.jsx)(tj,{enabled:n,children:(0,$.jsx)(NN,{entry:e,onMessageContentChange:r?d:u,getAnimationHandlers:f,scrollToBottom:p,stickyUserHeader:m,sessionIsWorking:i?h:!1,activityRenderMode:g,turnUiStates:_,onToggleTurnGroup:v,chatRenderMode:y,shouldAnimateUserMessage:x,onUserAnimationConsumed:S,activeStreamingMessageId:i?C:null,activeStreamingPhase:i?w:null,reviewTransferDirection:T,showLiveStatusRow:i})})})},t[29]=C,t[30]=w,t[31]=g,t[32]=y,t[33]=f,t[34]=B,t[35]=H,t[36]=u,t[37]=d,t[38]=v,t[39]=S,t[40]=T,t[41]=p,t[42]=h,t[43]=x,t[44]=m,t[45]=_,t[46]=oe):oe=t[46];let se=YA(oe),ce;t[47]===g?ce=t[48]:(ce=rN(g),t[47]=g,t[48]=ce);let le=z&&m,ue;return t[49]!==K||t[50]!==te||t[51]!==L||t[52]!==D||t[53]!==E||t[54]!==N||t[55]!==re||t[56]!==z||t[57]!==I||t[58]!==P||t[59]!==j||t[60]!==l||t[61]!==se||t[62]!==ae||t[63]!==O||t[64]!==A||t[65]!==c||t[66]!==k||t[67]!==h||t[68]!==le||t[69]!==ce||t[70]!==i?(ue=(0,$.jsx)(ej,{enabled:!0,children:(0,$.jsx)(cM,{entries:K,timelineCacheKey:i,estimatedItemSize:ce,hydrationTuning:re,renderEntry:se,rowInvalidationKey:ae,scrollElementRef:c,registerList:l,followEnabled:L,historyAnchorToken:N,anchoredEndSpace:te,onAnchoredTurnParkReleased:I,sessionIsWorking:h,header:E,footer:D,className:O,style:k,scrollElementDataset:A,hideTopScrollShadow:le,hideBottomScrollShadow:z,onScroll:j,onIsAtEndChange:P})}),t[49]=K,t[50]=te,t[51]=L,t[52]=D,t[53]=E,t[54]=N,t[55]=re,t[56]=z,t[57]=I,t[58]=P,t[59]=j,t[60]=l,t[61]=se,t[62]=ae,t[63]=O,t[64]=A,t[65]=c,t[66]=k,t[67]=h,t[68]=le,t[69]=ce,t[70]=i,t[71]=ue):ue=t[71],ue};LN.displayName=`LegendTimelineHost`;var RN=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:c,getAnimationHandlers:l,scrollToBottom:u,scrollRef:d,directory:f,headerSlot:p,footerSlot:m,timelineScrollClassName:h,timelineScrollStyle:g,timelineScrollDataset:_,timelineOnScroll:v,timelineFollowEnabled:y,timelineHistoryAnchorToken:b,timelineOnIsAtEndChange:x,enableSendPark:S=!0},C)=>{Le(`ui.message_list.render`);let{sessionKey:w,virtualizerKey:T}=nN(e,t),E=s(e=>e.stickyUserHeader),D=s(e=>e.chatRenderMode),O=s(e=>e.activityRenderMode),k=s(e=>e.showTurnChangedFiles),A=vr(e=>e.reviewTransferBySessionId.get(w)??null),[j,M]=Z.useState(()=>new Map),N=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),[P,F]=Z.useState(null),I=Z.useRef(null);I.current=P;let L=J(t=>{Bt(e),I.current===t&&F(null)}),R=J(l),z=J(()=>{u?.()}),B=J((e,t)=>{M(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:IO(i)}),r})}),V=Z.useMemo(()=>Se(`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(hk(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=gN(t,a);dk(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(_N(o)){let e=TN(n);if(e.hide){i[i.length-1]=EN(o,e.taskSessionId);continue}}if(dM(o)){let e=fM(n,vN(o));if(e.hide){i[i.length-1]=DN(o,e.details);continue}}i.push(n)}return i}),[n]),H=Z.useRef(null),U=Z.useRef(null),W=Z.useCallback(()=>{let e=U.current;e&&(U.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{W()},[W]);let ee=J(()=>d?.current?d.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),G=Z.useMemo(()=>Se(`ui.message_list.retry_overlay_ms`,()=>KA(V,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[V,o]),K=r||!!i,q=Z.useRef(K),te=Z.useRef(w);te.current!==w&&(te.current=w,q.current=!1),K&&(q.current=!0);let{projection:ne,staticTurns:re,streamingTurns:ie}=WA(G,{sessionKey:w,showTextJustificationActivity:D===`sorted`,showTurnChangedFiles:k,hasLiveTail:K||q.current,liveTailActive:K}),ae=ne.ungroupedMessageIds.size>0,oe=ae?G:TM,se=ae?ne.ungroupedMessageIds:EM,ce=Z.useMemo(()=>Se(`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 DM;let e=G[G.length-1];return!e||!ne.ungroupedMessageIds.has(e.info.id)?DM:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:G.length>1?G[G.length-2]:void 0,nextMessage:void 0}]},[G,ne.lastTurnId,ne.ungroupedMessageIds,ie]),ue=le.length>0;ue&&K&&Le(`ui.message_list.render.streaming`);let de=ce,fe=de.length>=wM,pe=Z.useRef(fe);fN(pe,fe);let me=fe?`tanstack`:`none`,he=Lx(e=>e.legendTimelineEnabled),ge=Z.useRef(null),_e=J(e=>{ge.current=e}),ve=Z.useRef(null),ye=J(e=>{ve.current=e}),be=Z.useMemo(()=>le.length>0?[...de,...le]:de,[de,le]),xe=J(e=>{c(e)}),Ce=J(e=>{c(e)}),we=Z.useMemo(()=>n.filter(e=>hN(e)===`user`).map(e=>e.info.id),[n]),Te=N.current,Ee=Te.sessionKey!==e,De=Te.previousOrder;Ee&&(S&&Te.sessionKey!==void 0&&Bt(Te.sessionKey),Te.sessionKey=e,Te.previousOrder=we,Te.animatedIds=new Set);let Oe=S?en({sessionId:e,sessionChanged:Ee,previousUserOrder:De,currentUserOrder:we,animatedIds:Te.animatedIds}):null;Te.previousOrder=we;let ke=S?Gj({sessionChanged:Ee,previousUserOrder:De,currentUserOrder:we,currentAnchorId:P,consumedSendMessageId:Oe}):null;S&&ke!==P&&F(ke),S&&(I.current=ke);let Ae=J(e=>hN(e)===`user`&&N.current.animatedIds.has(e.info.id)),je=J(e=>{N.current.animatedIds.delete(e)}),Me=Z.useMemo(()=>{let e=new Map;return be.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},[be]),Ne=Z.useMemo(()=>{let e=new Map;return be.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[be]),Pe=J(e=>{let t=ee();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Fe=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}),Ie=J((e,t=`auto`)=>{let n=ee();if(!n)return!1;let r=Pe(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(!C)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Ne.get(e);if(r===void 0)return!1;let i=ee();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:Fe(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=Me.get(e);return r===void 0?!1:Ie(e,n)||(ue&&r>=de.length?!1:Fe(r,n))},holdViewportAnchor:e=>{let t=ee();if(!t||typeof window>`u`)return;W();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(),U.current?.cancel===s&&(U.current=null))},c=()=>{s()};U.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=Pe(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>=HM||n>=UM){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:W,isHistoryVirtualized:()=>he?!0:pe.current,captureViewportAnchor:()=>{let e=ee();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`||!bN(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=ee();if(!t||!Me.has(e.messageId))return!1;let n=()=>{let n=Pe(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=Me.get(e.messageId);if(typeof t==`number`&&t<de.length)return Fe(t,`auto`)}return n()},scrollToBottom:()=>{if(he){let e=kj(ee());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=ee();e&&(e.scrollTop=e.scrollHeight)}};if(typeof C==`function`)return C(e),()=>{C(null)};let t=C;return t.current=e,()=>{t.current=null}},[W,de.length,he,Me,fe,ue,Ne,C]),he?(0,$.jsx)(LN,{historyEntries:de,tailEntries:le,timelineCacheKey:iN(T,O),directory:f,sessionId:w,scrollRef:d,registerList:_e,onHistoryContentChange:xe,onTailContentChange:Ce,getAnimationHandlers:R,scrollToBottom:z,stickyUserHeader:E,sessionIsWorking:r,activityRenderMode:O,turnUiStates:j,onToggleTurnGroup:B,chatRenderMode:D,showTurnChangedFiles:k,shouldAnimateUserMessage:Ae,onUserAnimationConsumed:je,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:A,header:p,footer:m,scrollClassName:h,scrollStyle:g,scrollDataset:_,onScroll:v,followEnabled:y,historyAnchorToken:b,onIsAtEndChange:x,anchoredUserMessageId:ke,onAnchoredTurnParkReleased:L},T):(0,$.jsx)(`div`,{children:(0,$.jsx)(yc,{disabled:!1,children:(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(yc,{disabled:fe,children:(0,$.jsx)(ej,{enabled:!0,children:(0,$.jsx)(PN,{entries:de,engine:me,contentRef:H,scrollRef:d,registerTanstackVirtualizer:ye,virtualizerKey:T,onMessageContentChange:xe,getAnimationHandlers:R,scrollToBottom:z,stickyUserHeader:E,activityRenderMode:O,turnUiStates:j,onToggleTurnGroup:B,chatRenderMode:D,shouldAnimateUserMessage:Ae,onUserAnimationConsumed:je,reviewTransferDirection:A},T)})}),(0,$.jsx)(IN,{entries:le,directory:f,sessionId:w,onMessageContentChange:Ce,getAnimationHandlers:R,scrollToBottom:z,stickyUserHeader:E,sessionIsWorking:r,activityRenderMode:O,turnUiStates:j,onToggleTurnGroup:B,chatRenderMode:D,showTurnChangedFiles:k,shouldAnimateUserMessage:Ae,onUserAnimationConsumed:je,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:A})]})})})});RN.displayName=`MessageList`;var zN=Z.memo(RN);function BN(e){return e.info.id}function VN(e){return e!==null}function HN(e){return e.isMobile}var UN=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},WN=({diff:e,filePath:t})=>{let{currentTheme:n}=Ua(),r=Z.useMemo(()=>Co(n),[n]),i=Z.useMemo(()=>Ac(e),[e]),a=sc(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6580
|
-
`),[i]),s=Bc(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=sc(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=Bc(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)(UN,{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},KN=new Set([`id`,`identifier`,`title`,`name`]),qN=e=>typeof e==`object`&&!!e&&!Array.isArray(e),JN=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),YN=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},XN=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},ZN=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?`${JN(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)(ZN,{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(qN(n)){let e;t[18]===n?e=t[19]:(e=YN(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter($N),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${JN(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)(ZN,{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?JN(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`&&XN(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:JN(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});ZN.displayName=`JsonSummaryValue`;var QN=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)(ZN,{value:n,depth:0})}),t[0]=n,t[1]=r),r});QN.displayName=`JsonSummaryView`;function $N(e){let[t]=e;return!KN.has(t)}var eP={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`},tP={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},nP=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})},rP=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},iP=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,aP=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)(QN,{data:n})}),t[0]=n,t[1]=r),r},oP=({permission:e,onResponse:t})=>{let{t:n}=ot(),[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=nr,c=Nr(),l=Zr(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],_=rP(f),v=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[iP(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:[nP(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)(jc,{language:`bash`,code:e,style:eP,codeStyle:tP.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)(da,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(WN,{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)(da,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(GN,{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)(da,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(aP,{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)(da,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(aP,{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)(da,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(aP,{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)(ca,{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)(ca,{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)(ca,{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 sP(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 cP(e){let t={questions:(e.questions??[]).map(e=>({header:e.header??null,question:e.question,multiple:!!e.multiple,options:e.options.map(e=>({label:e.label,description:e.description??null}))}))};return JSON.stringify(t,null,2)}function lP({scrollHeight:e,currentHeight:t}){let n=Math.min(Math.max(e,40),200);return t===n?null:n}var uP=`summary`,dP=Z.memo(function(e){let t=(0,Q.c)(31),{value:n,placeholder:r,disabled:i,onValueChange:a,onKeyDown:o}=e,s=Z.useRef(null),[c,l]=Z.useState(n),[u,d]=Z.useState(40),[f,p]=Z.useState(!1),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current;if(!e||document.activeElement!==e)return;let t=e.closest(`.chat-scroll`);if(!t){e.scrollIntoView({block:`nearest`});return}let n=window.visualViewport,r=t.getBoundingClientRect(),i=n?.offsetTop??0,a=n?n.offsetTop+n.height:document.documentElement.clientHeight,o=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--oc-kb-scroll-inset`))||0,c=Math.max(r.top,i),l=Math.min(r.bottom,a-o),u=Math.max(0,l-c),d=e.closest(`[data-question-card]`),f=d?.getBoundingClientRect(),p=(d&&f&&f.height<=u?d:e).getBoundingClientRect();p.bottom>l-12?t.scrollTop+=p.bottom-l+12:p.top<c+12&&(t.scrollTop+=p.top-c-12)},t[0]=m):m=t[0];let h=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]!==u||t[10]!==f?(S=()=>{let e=s.current;if(!e)return;let t=lP({scrollHeight:e.scrollHeight,currentHeight:u}),n=e.scrollHeight>(t??u);f!==n&&p(n),t!==null&&d(t)},t[9]=u,t[10]=f,t[11]=S):S=t[11];let C;t[12]!==u||t[13]!==f||t[14]!==c?(C=[u,f,c],t[12]=u,t[13]=f,t[14]=c,t[15]=C):C=t[15],Z.useLayoutEffect(S,C);let w;t[16]===a?w=t[17]:(w=e=>{let t=e.target.value;l(t),a(t)},t[16]=a,t[17]=w);let T;t[18]===u?T=t[19]:(T={height:u},t[18]=u,t[19]=T);let E=f?`overflow-y-auto`:`overflow-hidden`,D;t[20]===E?D=t[21]:(D=Y(`w-full bg-transparent border border-border/30 focus:border-primary rounded px-2 py-1 outline-none typography-meta text-foreground placeholder:text-muted-foreground/50 transition-colors resize-none`,E),t[20]=E,t[21]=D);let O;return t[22]!==i||t[23]!==_||t[24]!==c||t[25]!==o||t[26]!==r||t[27]!==T||t[28]!==D||t[29]!==w?(O=(0,$.jsx)(`textarea`,{ref:s,value:c,onChange:w,placeholder:r,disabled:i,rows:2,onKeyDown:o,onFocus:_,style:T,className:D,autoFocus:!0}),t[22]=i,t[23]=_,t[24]=c,t[25]=o,t[26]=r,t[27]=T,t[28]=D,t[29]=w,t[30]=O):O=t[30],O}),fP=({question:e})=>{let{t}=ot(),n=Zn,r=xi,i=s(e=>e.isMobile),a=Nr(),o=Zr(e=>e.currentSessionId),c=Z.useMemo(()=>{if(!o||e.sessionID===o)return!1;let t=a.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===o)},[e.sessionID,o,a]),[l,u]=Z.useState(`0`),[d,f]=Z.useState(!1),[p,m]=Z.useState(!1),[h,g]=Z.useState({}),[_,v]=Z.useState({}),y=Z.useRef({}),[b,x]=Z.useState({}),S=Z.useMemo(()=>e.questions??[],[e.questions]),C=l===uP,w=C?-1:Math.max(0,Math.min(S.length-1,Number(l)||0)),T=C?null:S[w],E=Z.useMemo(()=>{if(C)return null;let e=T?.header?.trim();return e&&e.length>0?e:null},[T?.header,C]);Z.useEffect(()=>{u(`0`),g({}),v({}),y.current={},x({}),m(!1)},[e.id]);let D=Z.useMemo(()=>{let e=S.map((e,t)=>({value:String(t),label:e.header?.trim()||`Q${t+1}`}));return S.length>1&&e.push({value:uP,label:t(`chat.questionCard.summaryTab`)}),e},[S,t]),O=Z.useCallback(e=>{if(_[e])return(y.current[e]??``).trim()||t(`chat.questionCard.noAnswer`);let n=h[e]??[];return n.length>0?n.join(`, `):t(`chat.questionCard.noAnswer`)},[_,h,t]),k=!!T?.multiple,A=h[w]??[],j=!!_[w],M=Z.useMemo(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){b[t]||e.push(t);continue}(h[t]??[]).length===0&&e.push(t)}return e},[_,b,S.length,h]),N=Z.useMemo(()=>S.length!==0&&M.length===0,[S.length,M.length]),P=Z.useCallback(()=>{if(S.length===0||M.length===0)return;let e=C?-1:w;for(let t=1;t<=S.length;t+=1){let n=(e+t+S.length)%S.length;if(M.includes(n)){u(String(n));return}}u(String(M[0]))},[w,C,S.length,M]),F=Z.useCallback(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){let n=(y.current[t]??``).trim();e.push(n?[n]:[]);continue}e.push(h[t]??[])}return e},[_,S.length,h]),I=Z.useCallback(e=>{T&&(v(e=>({...e,[w]:!1})),x(e=>e[w]?{...e,[w]:!1}:e),g(t=>{let n=t[w]??[];if(k){let r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,[w]:r}}return{...t,[w]:[e]}}))},[w,T,k]),L=Z.useCallback(()=>{v(e=>({...e,[w]:!0})),g(e=>({...e,[w]:[]}));let e=(y.current[w]??``).trim().length>0;x(t=>t[w]===e?t:{...t,[w]:e})},[w]),R=Z.useCallback(e=>{y.current[w]=e;let t=e.trim().length>0;x(e=>e[w]===t?e:{...e,[w]:t})},[w]),z=Z.useCallback(async()=>{if(N){f(!0);try{let t=F();await n(e.sessionID,e.id,t),m(!0)}catch(e){tn(e)?(Tt.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Tt.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}}},[F,e.id,e.sessionID,N,n,t]),B=Z.useCallback(e=>{Mg(e)||e.key===`Enter`&&!e.shiftKey&&(!i||e.ctrlKey||e.metaKey)&&(e.preventDefault(),N?z():P())},[z,P,i,N]),V=Z.useCallback(async()=>{f(!0);try{await r(e.sessionID,e.id),m(!0)}catch(e){tn(e)?(Tt.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Tt.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}},[e.id,e.sessionID,r,t]),H=Z.useCallback(async()=>{let n=sP(e);if((await ct(n)).ok){Tt.success(t(`chat.questionCard.copiedMarkdown`));return}Tt.error(t(`chat.questionCard.copyFailed`))},[e,t]),U=Z.useCallback(async()=>{let n=cP(e);if((await ct(n)).ok){Tt.success(t(`chat.questionCard.copiedJson`));return}Tt.error(t(`chat.questionCard.copyFailed`))},[e,t]);return p||S.length===0?null:(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{"data-question-card":!0,className:`-mt-1 border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1.5 border-b border-border/20`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:t(`chat.questionCard.inputNeeded`)}),c?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:t(`chat.questionCard.fromSubagent`)}):null,E?(0,$.jsx)(`span`,{className:`ml-auto typography-micro font-medium text-foreground/70 px-1.5 py-0.5 rounded bg-muted/30 border border-border/20`,children:E}):null,(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-0.5`,E?null:`ml-auto`),children:[(0,$.jsx)(`button`,{type:`button`,onClick:H,title:t(`chat.questionCard.copyMarkdown`),"aria-label":t(`chat.questionCard.copyMarkdown`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`file-text`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:U,title:t(`chat.questionCard.copyJson`),"aria-label":t(`chat.questionCard.copyJson`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`code-box`,className:`h-3 w-3`})})]})]})}),(0,$.jsxs)(`div`,{className:`px-2 py-2`,children:[D.length>1?(0,$.jsx)(`div`,{className:`flex items-center gap-1 mb-2 flex-wrap`,children:D.map(e=>{let t=l===e.value,n=e.value===uP,r=n?-1:Number(e.value),i=!n&&Number.isFinite(r)&&!M.includes(r);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(e.value),className:Y(`px-2 py-0.5 typography-meta font-medium rounded transition-colors flex items-center gap-1`,t?`bg-interactive-selection/40 text-foreground`:n?`text-muted-foreground hover:text-foreground hover:bg-interactive-hover/20`:i?`text-muted-foreground/60 hover:text-muted-foreground hover:bg-interactive-hover/20`:`text-foreground/85 hover:text-foreground hover:bg-interactive-hover/20`),children:[n?(0,$.jsx)(X,{name:`list-check-3`,className:`h-3 w-3`}):null,e.label]},e.value)})}):null,C?(0,$.jsx)(`div`,{className:`space-y-2`,children:S.map((e,n)=>{let r=O(n),i=r!==t(`chat.questionCard.noAnswer`);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(String(n)),className:`w-full text-left rounded px-1.5 py-1 hover:bg-interactive-hover/20 transition-colors`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.header||t(`chat.questionCard.questionFallback`,{index:n+1})}),(0,$.jsx)(`div`,{className:Y(`typography-meta`,i?`text-foreground`:`text-muted-foreground/50 italic`),children:r})]},n)})}):T?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground mb-1.5`,children:T.question}),k?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1.5`,children:t(`chat.questionCard.selectMultiple`)}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[T.options.map((e,n)=>{let r=A.includes(e.label),i=/\(recommended\)/i.test(e.label);return(0,$.jsx)(`button`,{type:`button`,onClick:()=>I(e.label),disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,r?`bg-interactive-selection/20`:null,d?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:k?(0,$.jsx)(ha,{checked:r,onChange:()=>I(e.label),disabled:d}):(0,$.jsx)(so,{checked:r,onChange:()=>I(e.label),disabled:d})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:Y(`typography-meta break-all`,r?`text-foreground font-medium`:`text-foreground/80`),children:e.label}),i?(0,$.jsx)(`span`,{className:`typography-micro text-primary/80`,children:t(`chat.questionCard.recommended`)}):null]}),e.description?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground break-words`,children:e.description}):null]})]})},`${n}:${e.label}`)}),(0,$.jsx)(`button`,{type:`button`,onClick:L,disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,j?`bg-interactive-selection/20`:null,d?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`edit`,className:Y(`h-3.5 w-3.5`,j?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,j?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),j?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)(dP,{value:y.current[w]??``,onValueChange:R,placeholder:t(`chat.questionCard.yourAnswer`),disabled:d,onKeyDown:B})}):null]})]}):null]}),(0,$.jsxs)(`div`,{className:`px-2 pb-1.5 pt-1 flex items-center gap-1.5 border-t border-border/20`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:N?z:P,disabled:d,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-success)/0.1)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[N?(0,$.jsx)(X,{name:`check`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`}),t(N?`chat.questionCard.submit`:`chat.questionCard.next`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:V,disabled:d,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-error)/0.1)] text-[var(--status-error)] hover:bg-[rgb(var(--status-error)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`}),t(`chat.questionCard.dismiss`)]}),d?(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})}):null]})]})})})};function pP(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
6583
|
-
`)}function mP(e,t=80){let n=pP(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var hP=160,gP=28,_P=12,vP=6,yP=30,bP=12,xP=18,SP=80,CP=4,wP=10,TP=14,EP=20,DP=54,OP=4,kP=8,AP=2,jP=160,MP=(e,t)=>e.map(e=>({turnId:e,preview:mP(t.get(e)??[],hP)})),NP=[1,.6,.35,.15],PP=(e,t,n)=>{let r=n?TP:wP;if(t===null)return r;let i=NP[Math.abs(e-t)]??0;return Math.round(r+(EP-r)*i)};function FP({turnIds:e,previewsByTurnId:t,activeTurnId:n,onSelectTurn:r,canLoadEarlier:i,isLoadingOlder:a,onLoadEarlier:o}){let{t:c}=ot(),l=s(e=>e.isPromptNavigatorPanelOpen),u=s(e=>e.setPromptNavigatorPanelOpen),d=Z.useRef(null),f=Z.useRef(null),[p,m]=Z.useState(null),[h,g]=Z.useState(0),[_,v]=Z.useState(!1);Z.useEffect(()=>{let e=f.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){v(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.right-vP-gP;v(r.right>i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let y=Z.useMemo(()=>MP(e,t),[t,e]),b=Math.min(y.length,yP),x=Math.max(0,y.length-b),S=Math.min(h,x),C=S+b,w=S>0,T=C<y.length,E=c(`chat.timeline.noTextContent`),D=c(`chat.promptNavigator.currentPrompt`),O=c(`chat.promptNavigator.loadMore`),k=Z.useMemo(()=>n?y.findIndex(e=>e.turnId===n):-1,[n,y]),A=Z.useRef(S);A.current=S;let j=Z.useRef(y.length);j.current=y.length;let M=Z.useRef(null),N=Z.useRef(null),P=Z.useRef(0),F=Z.useCallback(e=>{g(t=>{let n=j.current,r=Math.min(n,yP),i=Math.max(0,n-r),a=Math.min(t,i);return e<a?e:e>=a+r?Math.min(i,e-r+1):a})},[]),I=Z.useRef(y[0]?.turnId),L=Z.useRef(y.length);Z.useLayoutEffect(()=>{let e=I.current,t=L.current,n=y.length-t;n>0&&t>0&&e&&y[0]?.turnId!==e&&(g(e=>e+n),m(e=>e===null?null:e+n)),I.current=y[0]?.turnId,L.current=y.length},[y]),Z.useEffect(()=>{if(p!==null)return;let e=k>=0?k:y.length-1;g(()=>{let t=j.current,n=Math.min(t,yP),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[k,p,y.length]);let R=Z.useCallback(e=>{let t=d.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/bP),i=Math.min(j.current,yP);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),z=Z.useCallback(()=>{P.current=0,N.current!==null&&(window.clearInterval(N.current),N.current=null)},[]),B=Z.useCallback(()=>{let e=P.current;if(e===0){z();return}let t=j.current,n=Math.max(0,t-Math.min(t,yP)),r=Math.min(A.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){z();return}A.current=i,g(i);let a=M.current;if(a!==null){let e=R(a);e!==null&&m(Math.min(t-1,i+e))}},[R,z]),V=Z.useCallback(e=>{let t=d.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=xP&&w?i=-1:r>=n.height-xP&&T&&(i=1),P.current=i,i===0){z();return}N.current===null&&(N.current=window.setInterval(B,SP))},[B,w,T,z]);Z.useEffect(()=>()=>{N.current!==null&&window.clearInterval(N.current)},[]);let H=Z.useRef(null),U=Z.useCallback(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),W=Z.useCallback(()=>{U(),H.current=window.setTimeout(()=>{H.current=null,m(null)},jP)},[U]);Z.useEffect(()=>()=>{H.current!==null&&window.clearTimeout(H.current)},[]);let ee=Z.useCallback(e=>{U(),M.current=e.clientY;let t=R(e.clientY);t!==null&&m(Math.min(j.current-1,A.current+t)),V(e.clientY)},[U,R,V]),G=Z.useCallback(()=>{M.current=null,z(),W()},[W,z]),K=Z.useCallback(()=>{u(!1)},[u]),q=Z.useCallback(e=>{if(e===null)return;let t=y[e];t&&(r(t.turnId),z(),m(null),K(),d.current?.blur())},[K,r,y,z]),te=Z.useCallback(e=>{let t=R(e.clientY);t!==null&&q(Math.min(y.length-1,A.current+t))},[q,y.length,R]);Z.useEffect(()=>{if(!l)return;let e=d.current;!e||e===document.activeElement||(e.focus(),m(e=>{if(e!==null)return e;let t=k>=0?k:y.length-1;return F(t),t}))},[k,F,l,y.length]),Z.useEffect(()=>()=>{u(!1)},[u]);let ne=Z.useCallback(e=>{if(y.length===0)return;let t=p??(k>=0?k:y.length-1),n=e=>{let t=Math.max(0,Math.min(y.length-1,e));F(t),m(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(y.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),q(t);return}e.key===`Escape`&&(e.preventDefault(),m(null),K(),d.current?.blur())},[k,K,F,q,p,y.length]),re=Z.useCallback(()=>{z(),m(null),K()},[K,z]),ie=Z.useRef(null),ae=Z.useRef(p);ae.current=p;let oe=p!==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/DP);if(t===0)return;se.current-=t*DP;let n=ae.current;if(n===null)return;let r=Math.max(0,Math.min(j.current-1,n+t));r!==n&&(F(r),m(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[F,oe]);let ce=p===null?void 0:y[p],le=Math.min(y.length,kP),ue=le*DP,de=y.length*DP-ue,fe=e=>Math.max(0,Math.min(de,e)),pe=Z.useRef(null),me=0;if(p===null)pe.current=null;else if(pe.current===null)me=fe(p*DP-(ue-DP)/2),pe.current=me;else{let e=pe.current,t=(p-AP)*DP,n=(p+1+AP)*DP-ue;e>t?e=t:e<n&&(e=n),me=fe(e),pe.current=me}let he=Math.floor(me/DP),ge=Math.max(0,he-CP),_e=Math.min(y.length,he+le+CP),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,S-CP),Se=Math.min(y.length,C+CP),Ce=y.slice(xe,Se),we=w||T?`linear-gradient(to bottom, ${w?`transparent, black 14%`:`black`}, ${T?`black 86%, transparent`:`black`})`:void 0;return y.length===0?null:(0,$.jsx)(`nav`,{ref:f,"aria-label":c(`chat.promptNavigator.aria`),className:`pointer-events-none absolute right-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-end`,children:[i?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-mr-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,a?`cursor-wait opacity-70`:void 0),"aria-label":O,title:O,disabled:a,onClick:e=>{e.stopPropagation(),a||o()},children:a?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:d,role:`listbox`,tabIndex:-1,"aria-activedescendant":ce?`prompt-rail-tick-${ce.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${_?_P:gP}px`,height:`${b*bP}px`},onMouseMove:ee,onMouseLeave:G,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(-${S*bP}px)`},children:Ce.map((e,t)=>{let r=xe+t,i=e.turnId===n,a=p===r,o=PP(r,p,i);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,"aria-label":e.preview.trim()||E,className:`pointer-events-none absolute right-1 flex items-center justify-end`,style:{top:`${r*bP}px`,height:`${bP}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,i?`bg-[var(--surface-foreground)]`:a?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${o}px`}})},e.turnId)})},y[0]?.turnId)}),ce&&p!==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:U,onMouseLeave:W,onMouseMove:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(`div`,{className:`relative overflow-hidden`,style:{height:`${le*DP}px`,maskImage:be,WebkitMaskImage:be},children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-200 ease-out`,style:{height:`${y.length*DP}px`,transform:`translateY(-${me}px)`},children:y.slice(ge,_e).map((e,t)=>{let r=ge+t,i=e.turnId===n,a=p===r;return(0,$.jsx)(`div`,{role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,title:i?D:void 0,className:`absolute inset-x-0 cursor-pointer px-1.5`,style:{top:`${r*DP+OP}px`,height:`46px`},onMouseMove:()=>{U(),ae.current!==r&&(F(r),m(r))},onClick:()=>q(r),children:(0,$.jsx)(`div`,{className:Y(`flex h-full items-center rounded-lg border px-2 transition-colors`,i?`border-transparent bg-[var(--interactive-selection)]`:a?`border-[var(--interactive-border)]/60 bg-[var(--interactive-hover)]`:`border-[var(--interactive-border)]/40`),children:(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 line-clamp-2 [overflow-wrap:anywhere] typography-meta`,i?`text-[var(--interactive-selectionForeground)]`:`text-[var(--surface-mutedForeground)]`),children:e.preview.trim()||E})})},e.turnId)})})})}):null]})]})})}var IP=100,LP=(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},RP=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=LP(p,t.scrollTop+IP);!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}},zP=10,BP=`${zP}vh`,VP=`80px`,HP=`calc(${VP} + var(--oc-chat-foot-inset))`,UP=(e,t)=>e?80:t<=0?96:Math.max(48,zP/100*t),WP=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return!1;switch(e.key){case`ArrowUp`:case`PageUp`:case`Home`:return!0;default:return!1}},GP=(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},KP=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&&(GP(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)||GP(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=>{WP(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:qP,C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C={passive:!0},t[14]=C):C=t[14];let w=C;it(`wheel`,u,S,w),it(`touchstart`,f,S,w),it(`touchmove`,m,S,w),it(`touchend`,g,S,w),it(`touchcancel`,g,S,w),it(`keydown`,v,S)};function qP(){}var JP=(e,t)=>({sessionId:e,viewportKey:t}),YP=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,XP=(e,t)=>YP(e,t),ZP=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),QP=150,$P=1500,eF=2,tF=350,nF=600,rF=8e3,iF=24,aF=2,oF=(e,t)=>e<t,sF=()=>typeof performance<`u`?performance.now():Date.now(),cF=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),lF=e=>e.scrollHeight-e.scrollTop-e.clientHeight,uF=e=>lF(cF(e)),dF=e=>e.scrollHeight-e.clientHeight>1,fF=(e,t)=>lF(e)<=UP(t,e.clientHeight),pF=({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(JP(t,n));C.current=JP(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=sF()+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:sF()},E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{T.current=null,E.current=null},$P)}),q=J(e=>{let t=T.current;return t?sF()-t.time>$P?(T.current=null,!1):Math.abs(e.scrollTop-t.top)<eF:!1}),te=J(()=>sF()<A.current),ne=J(()=>{L.current=!1,R.current&&=(clearTimeout(R.current),null),z.current&&=(clearTimeout(z.current),null)}),re=J(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,ne()},nF)}),ie=J(()=>{let e=c.current;e&&(L.current=!0,B.current=e.scrollHeight,re(),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{z.current=null,ne()},rF))}),ae=J(e=>{let t=c.current;if(!t){h(!1),_(!1);return}let n=e??cF(t),r=dF(n);if(h(r),!r){_(!1);return}let i=b.current===`released`&&!fF(n,x.current);_(i)}),oe=J(()=>{D.current+=1,O.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(O.current),O.current=null),k.current?.(),k.current=null});Z.useEffect(()=>()=>oe(),[l]);let se=J(()=>{if(!e)return;let t=c.current;if(!t)return;oe();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(),ae(),typeof window>`u`)return;let o=0,s=()=>{oF(sF(),P.current)||oe()};t.addEventListener(`touchstart`,s,{passive:!0,once:!0}),k.current=()=>t.removeEventListener(`touchstart`,s);let l=()=>{if(n===D.current){if(uF(t)>aF&&a(),o+=1,o>=iF){O.current=null,k.current?.(),k.current=null,ae();return}O.current=window.requestAnimationFrame(l)}};O.current=window.requestAnimationFrame(l)}),ce=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}}),le=J((t,n=`auto`)=>{if(!e)return;let r=c.current;if(t&&b.current!==`following`&&G(`following`),r&&!(!t&&b.current!==`following`)){if(uF(r)<eF){K(r);return}ce(t?n:`auto`)}}),ue=J(e=>{let t=c.current;if(!t)return;let n=e??cF(t);if(!dF(n)){G(`following`);return}b.current!==`released`&&(G(`released`),ae(n))}),de=J((e=`instant`)=>{if(V.current=!1,G(`following`),ne(),e===`instant`){se();return}oe(),le(!0,`smooth`),ae()}),fe=J(()=>{V.current=!1,le(!0)}),pe=J(()=>{oe(),ne(),G(`released`),ae()}),me=J(()=>{V.current=!0,pe()}),he=J(()=>{V.current=!1}),ge=Z.useRef(s);ge.current=s;let _e=J(()=>{oF(sF(),P.current)||(oe(),ne(),ue())}),ve=J(()=>{_e(),ge.current?.()}),ye=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}}),be=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=ZP(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),H.current===null&&(H.current=setTimeout(()=>{H.current=null,ye()},QP))}),xe=J(()=>{ye()}),Se=J(async(e=C.current)=>{if(!e.sessionId)return!1;V.current=!1;let t=Ui(e.sessionId,e.viewportKey);return c.current?(W.current=null,I.current=t?.scrollPosition?.scrollTop??0,G(`following`),F(),x.current?se():le(!0),ie(),ae(),!1):(W.current=e,G(`following`),!1)});Z.useEffect(()=>{let e=C.current,n=w.current;YP(e,n)||(ye(),oe(),F(),w.current=e,T.current=null,I.current=0,ne(),V.current=!1,G(`following`),W.current=null,t&&t!==n?.sessionId&&Px.getInstance().recordSessionStart(t))},[t,n]),Z.useEffect(()=>{i&&!V.current&&b.current===`following`&&le(!0)},[i]),Z.useEffect(()=>{y(f===`following`&&i)},[f,i]),Z.useLayoutEffect(()=>{if(!l)return;let e=W.current;e&&XP(e,C.current)&&Se(e)},[l,t,n]);let Ce=J(()=>{let e=c.current;if(!e)return;let t=cF(e),n=I.current;I.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(ae(t),V.current){be();return}if(!dF(t)){G(`following`);return}if(fF(t,x.current)){let e=lF(t)<=eF;(r||b.current===`following`||e)&&G(`following`),be();return}if(b.current===`following`&&(q(e)||te()||i)){j.current||le(!1),be();return}ue(t),be()});Z.useEffect(()=>{!e||!l||(I.current=l.scrollTop)},[l,e]);let we=Z.useRef(null),Te=J(e=>{let t=c.current;t&&(e.deltaY>=0||GP(t,e.target)||ve())}),Ee=J(e=>{let t=e.touches.item(0);we.current=t?t.clientY:null}),De=J(e=>{let t=c.current,n=e.touches.item(0);if(!n){we.current=null;return}let r=we.current;we.current=n.clientY,r!==null&&(n.clientY-r<=2||t&&(GP(t,e.target)||ve()))}),Oe=J(()=>{we.current=null}),ke=J(e=>{WP(e)&&ve()}),Ae=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&_e()}),je=Z.useMemo(()=>()=>void 0,[]),Me=e&&l?l:je,Ne=Z.useMemo(()=>({passive:!0}),[]);it(`scroll`,Ce,Me,Ne),it(`wheel`,Te,Me,Ne),it(`touchstart`,Ee,Me,Ne),it(`touchmove`,De,Me,Ne),it(`touchend`,Oe,Me,Ne),it(`touchcancel`,Oe,Me,Ne),it(`keydown`,ke,Me),it(`pointerdown`,Ae,e&&typeof window<`u`?window:je,!0);let Pe=J(()=>{let e=c.current;if(j.current){ae(e?cF(e):void 0);return}if(V.current){ae(e?cF(e):void 0);return}if(!e){ae(void 0);return}let t=cF(e);if(!dF(t)){G(`following`),ae(t);return}if(ae(t),L.current){let n=t.scrollHeight>B.current+1;B.current=t.scrollHeight,lF(t)<=eF?K(e):le(!0),n&&re();return}if(b.current===`following`){if(lF(t)<=eF){K(e);return}le(!1)}}),Fe=typeof ResizeObserver<`u`,Ie=Fe&&e?l:null,Le=Fe&&e&&l&&l.firstElementChild instanceof Element?l.firstElementChild:null;at(Ie,Pe),at(Le,Pe);let Re=J(()=>{N.current!==null&&(clearTimeout(N.current),N.current=null)}),ze=J(e=>{j.current=!0,typeof e==`number`&&e>0?A.current=sF()+e+tF:A.current=Math.max(A.current,sF()+tF)}),Be=J(e=>{let t=e.detail;if(t){if(t.open===!0){ze(),Re(),N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},1500);return}Re(),ze()}}),Ve=J(e=>{let t=e.detail;t&&(Re(),ze(t.durationMs))}),He=J(e=>{let t=e.detail;Re(),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)},tF)),ae()}),Ue=e&&typeof window<`u`?window:je;it(`oc:keyboard-intent`,Be,Ue),it(`oc:keyboard-anim`,Ve,Ue),it(`oc:keyboard-settled`,He,Ue),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{Re(),j.current=!1,M.current=!1}},[e]),Z.useEffect(()=>{e&&ae()},[e,r]);let We=J(t=>{if(e){if(t===`animation`&&(A.current=sF()+tF),ae(),L.current){le(!0),re();return}b.current===`following`&&le(!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`&&le(!1)},i={onChunk:r,onComplete:()=>{e&&ae()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return Ge.current.set(t,i),i});Z.useEffect(()=>()=>{E.current&&=(clearTimeout(E.current),null),oe(),ne(),ye(),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=RP({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:de,scrollToBottomOnSend:fe,releaseAutoFollow:pe,beginHistoryViewportPreservation:me,endHistoryViewportPreservation:he,saveSnapshotNow:xe,restoreSnapshot:Se}},mF=`--oc-mobile-composer-swap`,hF=`--oc-native-composer-dock`,gF=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),_F=(e,t,n)=>Math.min(n,Math.max(t,e)),vF=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,yF=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return vF(e,n)?e:n},bF=(e,t)=>t?yF(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?yF(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,xF=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:yF(e,{phase:`snapping`,rest:t,progress:n})},SF=e=>_F(e/80,0,1),CF=e=>e>=80?1:_F(e/80,0,1),wF=(e,t,n={})=>{if(e.pinned)return e;let r=Math.max(0,t),i=e.phase===`snapping`?yF(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(i.rest===`expanded`){if(r<=2||n.holdExpanded||n.userDriven===!1)return yF(i,{phase:`rest`,rest:`expanded`,progress:0});let e=SF(r);return e>=1?yF(i,{phase:`rest`,rest:`compact`,progress:1}):yF(i,{phase:`tracking`,rest:`expanded`,progress:e})}if(r<=2)return yF(i,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn)return yF(i,{phase:`rest`,rest:`compact`,progress:1});if(n.towardBottom&&r>=80)return yF(i,{phase:`snapping`,rest:`expanded`,progress:0});let a=CF(r);return a>=1?yF(i,{phase:`rest`,rest:`compact`,progress:1}):yF(i,{phase:`tracking`,rest:`compact`,progress:a})},TF=e=>e.pinned?`expanded`:e.rest===`expanded`?e.progress>=.5?`compact`:`expanded`:e.progress<=.5?`expanded`:`compact`,EF=e=>{if(e.pinned)return yF(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let t=TF(e),n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:yF(e,{phase:`snapping`,rest:t,progress:n})},DF=e=>e.phase===`snapping`?yF(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,OF=e=>_F(Math.max(0,e)/80,0,1),kF=(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:OF(n),rest:`bottom`}},AF=e=>{e.style.removeProperty(mF),e.style.removeProperty(hF),delete e.dataset.ocComposerSwapPhase,delete e.dataset.ocComposerSwapRest,delete e.dataset.ocNativeComposerDock},jF=(e,t,n)=>{let r=kF(t,n?.rest===`bottom`?`bottom`:`away`),i=String(r.progress),a=r.rest;return n?.progress!==i&&e.style.setProperty(hF,i),n?.rest!==a&&(e.dataset.ocNativeComposerDock=a),{progress:i,rest:a}},MF=(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(mF,r),n?.rest!==a&&(e.dataset.ocComposerSwapRest=a),{progress:r,phase:i,rest:a}},NF=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),PF=()=>{let e=document.documentElement;return e.classList.contains(`oc-keyboard-open`)||e.classList.contains(`oc-kb-animating`)},FF=e=>{if(PF()||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)},IF=e=>{let t=Z.useRef(gF()),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=MF(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=DF(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||_(bF(t.current,FF(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=EF(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=FF(a),s=NF(n),g=jj(s,kj(n)),y=u.current;if(u.current=g,n.hasAttribute(`data-oc-timeline-anchoring`)){d.current=0,f.current=0;return}r.current=jF(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=bF(t.current,o);if(!o){let e=w.rest===`compact`;w=wF(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,_(xF(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&&AF(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,_(gF())});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}),[]);it(`scroll`,w,I,z),it(`scrollend`,T,I,z),it(`touchstart`,C,I,z),it(`touchmove`,S,I,z),it(`touchend`,E,I,z),it(`touchcancel`,E,I,z),it(`pointerdown`,O,L),it(`focusin`,y,L),it(`focusout`,y,L),it(`oc:keyboard-intent`,y,R),it(`oc:keyboard-anim`,y,R),it(`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])},LF=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},RF=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},zF=e=>{if(!e)return null;let t=LF(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${RF(e)??``}`},BF=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}),VF=(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&&zF(t[r])===zF(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=LF(r),a=r.info.id,o=BF(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=RF(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},HF=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=LF(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=RF(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}},UF=200,WF={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},GF=()=>UF,KF=()=>Math.round(GF()*.6),qF={MAX_SESSIONS:WF.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(UF*.6),HISTORICAL_MESSAGES:UF,FETCH_BUFFER:20,HISTORY_CHUNK:UF,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:WF.ZOMBIE_TIMEOUT},JF=()=>{let e=GF(),t=KF();return{...qF,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},YF=qF,XF=600,ZF=6e3,QF=.5,$F=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),eI=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},tI=(e,t)=>{let n=$F(e,t);if(n||=eI(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}},nI=e=>{let{container:t,quiesceMs:n=XF,maxLifetimeMs:r=ZF}=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=tI(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)>QF){h();return}let e=$F(t,i.messageId);if(!e){let n=eI(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)>QF&&(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}},rI=30,iI=1200,aI=1.5,oI=e=>Math.max(iI,e*aI),sI=4,cI=30,lI=4,uI=30,dI=250,fI=2e3,pI=wn+2e3,mI=40,hI=`history-loading-timeout`,gI=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),_I=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=hI,e},vI=(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)},yI=2500,bI=new Map,xI=()=>d()?sI:bt()?lI:rI,SI=e=>d()?e.length<=cI:!bt()||e.length<=uI,CI=(e,t)=>{if(bI.delete(e),!SI(t.messages))return;let n=xI();for(;bI.size>=n;){let e=bI.keys().next().value;if(typeof e!=`string`)break;bI.delete(e)}bI.set(e,t)},wI=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),TI=e=>e?{owner:`tanstack-core`}:{owner:`controller`},EI=(e,t)=>e?e.canLoadEarlier:t>=JF().HISTORICAL_MESSAGES,DI=e=>!(e.isMobile||e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=oI(e.clientHeight)),OI=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`,kI=1,AI=8,jI=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),MI=e=>[`chat-timeline-auto-fill`,e.runtimeKey,e.sessionId,e.oldestMessageId,e.messageCount,e.canLoadEarlier],NI=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],PI=20,FI=4,II=80,LI=new WeakMap,RI=new WeakMap,zI=e=>{let t=RI.get(e)??{generation:0};return t.generation+=1,RI.set(e,t),t.generation},BI=e=>{let t=LI.get(e);t&&(t.touches=0,t.pending=null,t.settleScheduled=!1),zI(e)},VI=e=>{HI(e)},HI=e=>{let t=LI.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&&UI(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),LI.set(e,n),n},UI=(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+II||WI(e,n.anchorTop+n.delta))}))},WI=(e,t)=>{let n=zI(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((RI.get(e)?.generation??0)!==n){e.removeEventListener(`touchstart`,o);return}e.scrollTop<t-FI&&(e.scrollTop=t),a+=1,a<PI?window.requestAnimationFrame(s):e.removeEventListener(`touchstart`,o)}};window.requestAnimationFrame(s)},GI=(e,t,n)=>{let r=HI(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,WI(e,t)},KI=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),qI=(e,t)=>e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight?e:t,JI=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:a,messageListRef:o,loadMoreMessages:s,goToBottom:c,releaseAutoFollow:l,beginHistoryViewportPreservation:u,endHistoryViewportPreservation:d,isPinned:f,showScrollButton:p,autoFillEnabled:m=!1,onWillLoadEarlier:h})=>{let g=Z.useRef(null),_=Z.useRef(null),v=Z.useMemo(()=>{let t=e??``,r=t?bI.get(t):void 0;if(r&&r.messages===n)return CI(t,r),g.current=r.model,_.current=n,r.model;let i=VF(g.current,_.current,n)??HF(n);return g.current=i,_.current=n,t&&n.length>0&&CI(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&&EI(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),q=Z.useRef(K);j.current=v,M.current=f,P.current=x,q.current=K,F.current=e,I.current=t??null,L.current=n,R.current=r,z.current=D;let te=J(()=>{U.current=!0,W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null)}),ne=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},fI)}),re=J(()=>{let e=B.current;e.length!==0&&(B.current=[],e.forEach(e=>e()))}),ie=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,dI)})),ae=J(e=>{let t=V.current;t&&(V.current=null,t.resolve(e))}),oe=J(()=>{let e=V.current;if(e){if(e.sessionId!==F.current){ae(!1);return}if(e.kind===`turn`?o.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:o.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(H.current={turnId:e.turnId,expiresAt:Date.now()+yI},w(e.turnId)),ae(!0);return}typeof(e.kind===`turn`?j.current.turnIndexById.get(e.id):j.current.messageToTurnIndex.get(e.id))==`number`&&ae(!1)}}),se=Z.useRef(null),ce=J(()=>{let e=se.current;e&&(se.current=null,e.dispose())});et(()=>{W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null),ce(),re(),ae(!1)});let le=n;rt(()=>{re(),oe()},[le]);let ue=J(()=>{let e=a.current;if(!e){A(e=>qI(e,{scrollHeight:0,clientHeight:0}));return}A(t=>qI(t,{scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))});at(typeof ResizeObserver<`u`?a:null,ue),rt(()=>{ue()},[e,y]);let de=Z.useRef(null),fe=J(()=>o.current?.captureViewportAnchor()??null),pe=J(e=>o.current?.restoreViewportAnchor(e)??!1),me=J(()=>{if(bt())return;ce();let e=a.current;if(!e)return;let t=fe();t&&(se.current=nI({container:e,anchor:t}))}),he=Z.useRef(null);rt(()=>{if(!bt())return;let e=a.current;e&&(VI(e),BI(e))},[e,a]),rt(()=>{ce(),de.current=null,he.current=null,o.current?.cancelViewportAnchorHold()},[e]),rt(()=>{let e=a.current;if(!e)return;let t=de.current;t&&Math.abs(e.scrollTop-t.top)>AI&&(de.current=null,t=null);let n=he.current,r=le[0]?.info?.id??null,i=le[le.length-1]?.info?.id??null,s=n?wI({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:i})||KI(n.oldestId,r,le):!1;t&&t.sessionId!==F.current&&(de.current=null,t=null);let l=t?wI({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:i})||KI(t.oldestId,r,le):!1,u=s||l,d=e=>{he.current={oldestId:r,newestId:i,scrollHeight:e??he.current?.scrollHeight??0}};if(M.current&&!t){ce(),u?(de.current=null,c(`instant`),d(e.scrollHeight)):d();return}let f=TI(o.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){o.current?.cancelViewportAnchorHold();let e=t.anchor;e&&pe(e),d();return}let n=e.scrollHeight,r=n-t.height;if(bt()){r>0&&GI(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&pe(i))&&r>0&&(e.scrollTop=t.top+r),d(n);return}if(s&&n&&f.owner===`controller`){let t=e.scrollHeight,r=t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;bt()?GI(e,t,r):e.scrollTop=t}d(t),me();return}d()},[le,c]);let ge=J(async()=>!1),_e=J(async e=>{let t=Date.now(),n=t+pI,r=I.current,i=r?zi()?.getRequestState?.(un(r,e)):void 0;for(q.current.historyLoading,R.current,i?.status,i?.error;q.current.historyLoading;){if(F.current!==e)return Date.now()-t,`switched`;if(Date.now()>=n){let n=r?zi()?.getRequestState?.(un(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:pI,hostTurnPageTimeoutMs:wn,historyLoading:q.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,mI)})}return Date.now()-t,r&&zi()?.getRequestState?.(un(r,e))?.status,F.current===e?`cleared`:`switched`}),ve=J(async e=>{if(!F.current||N.current||!q.current.hasMoreAboveTurns)return!1;N.current=!0,te(),b(!0);let t=F.current,n=null,r=!!e.userInitiated;r&&u();let i=()=>{n&&de.current===n&&(de.current=null,o.current?.cancelViewportAnchorHold()),r&&(r=!1,d())};try{if(q.current.historyLoading){if(!e.userInitiated)return!1;let n=await _e(t);if(n===`timeout`)throw _I();if(n===`switched`||!q.current.hasMoreAboveTurns)return!1}if(!F.current||F.current!==t)return!1;let r=a.current,o=L.current,c=o.length,l=o[0]?.info?.id??null,u=R.current?.limit??JF().HISTORICAL_MESSAGES;e.preserveViewport&&r&&(n={sessionId:F.current,height:r.scrollHeight,top:r.scrollTop,anchor:fe(),oldestId:l,newestId:o[o.length-1]?.info?.id??null},de.current=n,me());let d=c,f=l,p=u,m=0;for(;;){if(q.current.historyLoading)if(e.userInitiated){let e=await _e(t);if(e===`timeout`)throw i(),_I();if(e===`switched`)return i(),!1}else return i(),!1;let n=a.current?.scrollHeight??0,r=d,o=f,c=p;if(await s(t,`up`),m+=1,F.current!==t)return i(),!1;await ie();let l=L.current,u=l.length,h=l[0]?.info?.id??null,g=R.current?.limit??p,_=OI({scrollHeightBefore:n,scrollHeightAfter:a.current?.scrollHeight??n,messageCountBefore:r,messageCountAfter:u,oldestIdBefore:o,oldestIdAfter:h,limitBefore:c,limitAfter:g,hasMoreAbove:q.current.hasMoreAboveTurns,pagesLoaded:m,maxPages:kI});if(_===`continue`){d=u,f=h,p=g;continue}if(_===`stop-no-growth`){if(q.current.historyLoading){if(e.userInitiated){let e=await _e(t);if(e===`timeout`)throw i(),_I();if(e===`switched`)return i(),!1;--m;continue}return i(),!1}let n=R.current?.limit??c;return z.current=n,O(n),q.current={...q.current,hasMoreAboveTurns:!1,canLoadEarlier:!1},i(),!1}return!0}}catch(e){throw i(),e}finally{N.current=!1,b(!1),ne(),ie().then(i)}}),{t:ye}=ot(),be=Ke({mutationKey:NI({runtimeKey:i(),sessionId:e??``}),mutationFn:async e=>{if(F.current!==e.sessionId)return!1;te(),e.userInitiated&&l();try{return await ve({preserveViewport:!0,userInitiated:!!e.userInitiated})}finally{ne()}}}),xe=J(async e=>{let t=F.current;if(t&&!(be.isPending&&be.variables?.sessionId===t)){e?.userInitiated&&h?.();try{let n=await be.mutateAsync({sessionId:t,userInitiated:!!e?.userInitiated});if(n===!1&&q.current.canLoadEarlier){let r={sessionId:t,grew:n,userInitiated:!!e?.userInitiated,canLoadEarlier:q.current.canLoadEarlier,hasMoreAboveTurns:q.current.hasMoreAboveTurns,historyLoading:q.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};vI(`no-growth`,Error(`chat history pagination returned no growth`),r),e?.userInitiated&&Tt.error(ye(`chat.history.loadOlderFailed`))}}catch(n){let r={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:pI,hostTurnPageTimeoutMs:wn,canLoadEarlier:q.current.canLoadEarlier,historyLoading:q.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};gI(n)?vI(`timeout`,n,r):vI(`failed`,n,r),e?.userInitiated&&Tt.error(gI(n)?ye(`chat.history.loadOlderTimeout`):ye(`chat.history.loadOlderFailed`))}}}),Se=be.isPending&&be.variables?.sessionId===e||y,Ce=n[0]?.info?.id??null,we=jI({enabled:m,isMobile:bt(),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:MI({runtimeKey:i(),sessionId:e??``,oldestMessageId:Ce,messageCount:n.length,canLoadEarlier:K.canLoadEarlier}),enabled:!!e&&we,staleTime:1/0,gcTime:0,retry:(e,t)=>t?.code===`auto-fill-busy`&&e<40,retryDelay:50,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,queryFn:async()=>{let e=F.current;if(!e)return{status:`skip`};if(q.current.historyLoading||N.current){let e=Error(`auto-fill-busy`);throw e.code=`auto-fill-busy`,e}if(!q.current.canLoadEarlier)return{status:`skip`};let t=a.current;if(!t||t.clientHeight<=0)return{status:`skip`};if(t.scrollHeight>t.clientHeight+48)return{status:`tall`};try{let t=await ve({preserveViewport:!0});return t?{status:`grew`}:(q.current.canLoadEarlier&&vI(`no-growth`,Error(`chat history pagination returned no growth`),{sessionId:e,source:`auto-fill`,grew:t,canLoadEarlier:q.current.canLoadEarlier,hasMoreAboveTurns:q.current.hasMoreAboveTurns,historyLoading:q.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:pI,canLoadEarlier:q.current.canLoadEarlier,historyLoading:q.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};throw gI(t)?vI(`timeout`,t,n):vI(`failed`,t,n),E(!0),t instanceof Error?t:Error(`chat timeline auto-fill failed`)}}});let Te=J(e=>{let t=a.current;t&&DI({source:e,isMobile:bt(),isPinned:M.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:q.current.canLoadEarlier,isLoadingOlder:N.current,pendingRevealWork:P.current})&&xe({userInitiated:!0})}),Ee=J(()=>{Te(`scroll`)}),De=J(()=>{Te(`upward-intent`)}),Oe=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},oe()})}finally{S(!1)}}),ke=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},oe()})}finally{S(!1)}}),Ae=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`smooth`)}),je=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`instant`)}),Me=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:le,historySignals:K,isLoadingOlder:Se,pendingRevealWork:x,activeTurnId:C,showScrollToBottom:p&&!x,turnWindowModel:v,loadEarlier:xe,revealBufferedTurns:ge,resumeToBottom:Ae,resumeToBottomInstant:je,scrollToTurn:Oe,scrollToMessage:ke,handleHistoryScroll:Ee,handleHistoryUpwardIntent:De,captureViewportAnchor:fe,restoreViewportAnchor:pe,handleActiveTurnChange:Me}},YI=({mutateSession:e,forkSession:t})=>({revert:e,fork:t}),XI=({open:e,onOpenChange:t,sessionID:n,directory:r,onScrollToMessage:i,onScrollByTurnOffset:a,onResumeToLatest:o,canLoadEarlier:s=!1,isLoadingEarlier:c=!1,onLoadEarlier:l,onRevertMessage:u})=>{let{t:d}=ot(),f=Ph(),p=n,m=pr(p??``,r),h=Zr(e=>e.revertToMessage),g=Zr(e=>e.forkFromMessage),_=YI(f.capabilities),{isMobile:v,isTablet:y}=fo(),b=v||y,[x,S]=Z.useState(null),C=Z.useRef(!1),[w,T]=Z.useState(``),[E,D]=Z.useState(0),O=Z.useRef([]),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(!1),M=Z.useRef(e),N=e=>new Date(e).toLocaleDateString(st(),{year:`numeric`,month:`short`,day:`numeric`}),P=e=>new Date(e).toLocaleTimeString(st(),{hour:`numeric`,minute:`2-digit`}),F=Z.useMemo(()=>m.filter(e=>e.info.role===`user`).map(e=>({message:e})),[m]),I=Z.useMemo(()=>{let e=w.trim();if(!e)return F;let t=e.toLowerCase();return F.filter(({message:e})=>pP(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)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(Qi,{children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),d(`chat.timeline.title`)]}),(0,$.jsx)(ra,{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)(za,{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)(ca,{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=mP(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()?ZI(pP(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)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{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)(Va,{sideOffset:6,children:d(`chat.timeline.actions.revertFromHere`)})]}):null,_.fork?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{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)(Va,{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 ZI(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 QI=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},$I=(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`}},eL=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)},tL=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&&eL(`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&&eL(`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=$I(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 eL(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=()=>{eL(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=QI(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},nL=2e4,rL=6e4,iL=2e3,aL=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,oL=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+=aL(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},sL={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},cL=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:sL,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}},lL=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)},uL=(e,t)=>{let n=(0,Q.c)(7),r=Lx(dL),i=Zr(fL),a=Zr(pL),o,s;n[0]!==a||n[1]!==i||n[2]!==t||n[3]!==r||n[4]!==e?(o=()=>{if(r&&e&&!a(e)){for(let n of t)if(n.info.role===`assistant`)for(let t of n.parts){let n=t;if(n.type!==`text`)continue;let r=n.text||``;if(r.includes(`The plan at `)||r.includes(`User has requested to enter plan mode`)){i(e);return}}}},s=[r,e,t,i,a],n[0]=a,n[1]=i,n[2]=t,n[3]=r,n[4]=e,n[5]=o,n[6]=s):(o=n[5],s=n[6]),Z.useEffect(o,s)};function dL(e){return e.planModeEnabled}function fL(e){return e.markSessionPlanAvailable}function pL(e){return e.isSessionPlanAvailable}function mL(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 hL(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 gL(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||mL(i)==null}function _L(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!gL(n))continue;let e=hL(n);e&&t.push(e)}}return t}function vL(e,t){return`${e}:${t.join(`,`)}`}function yL(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=vL(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function bL(e,t,n,r){let i=(0,Q.c)(7),a=Bn(),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=yL({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:_L(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,cn(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 xL=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),SL=(e,t)=>({...e,key:CL(e),estimatedBytes:xL(t)}),CL=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),wL=e=>({key:e?CL(e):null,selection:e}),TL=(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},EL=(e,t,n,r)=>{let i=CL(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return TL(e,i,n);let s=o||SL(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),TL(c,i,n)},DL=(e,t,n)=>{let r=xL(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)},OL=(e,t)=>t&&e.some(e=>e.key===t)?t:null,kL=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?EL(e.cachedSessionViews,t.selection,n,r.estimatedBytes):TL(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}},AL=(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:SL(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},jL=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:EL(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},ML=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},NL=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},PL=e=>NL(e)?.role===`assistant`,FL=(e,t)=>{let n=NL(t);n&&(e.agentName??=ML(n.agent),e.providerId??=ML(n.providerID),e.modelId??=ML(n.modelID))},IL=e=>!!(e.agentName&&e.providerId&&e.modelId),LL=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!PL(r))&&(FL(t,r),IL(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||PL(r))&&(FL(t,r),IL(t)))break}return t},RL=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),zL=[],BL=[],VL={type:`idle`},HL=`openchamber:chat-force-scroll-bottom`,UL=()=>void 0,WL=`Quota limit reached. Retrying automatically.`,GL=1048576,KL=GL,qL=20,JL=GL,YL=16*GL,XL={maxEntries:3,maxEstimatedBytes:32*GL},ZL={maxEntries:2,maxEstimatedBytes:32*GL},QL=e=>t(()=>e()),$L={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},eR={scrollbar:`chat`,scrollShadow:`true`,orientation:`vertical`},tR=()=>{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},nR=`calc(max(0.625rem, var(--oc-safe-area-top, 0px)) + var(--oc-mobile-detail-navigation-height) + 1.25rem)`,rR=HP,iR=[`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(`,`),aR=e=>e instanceof HTMLElement,oR=e=>aR(e)?!!e.closest(iR):!1,sR=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||oR(e)?!0:!t?.contains(e),cR=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=s.getState();return e||t||n||r||i||a||o},lR=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}=ot(),I=Lx(e=>e.legendTimelineEnabled),L=xx({isLoadingOlder:u}),R=Sx({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(dM(n)){let r=pM(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(Qt(n.parts))continue;let r=B.current.get(n.parts);r||(r=qr(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||oR(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return KP({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)(zN,{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:$L,timelineScrollDataset:eR,timelineOnScroll:_,timelineFollowEnabled:!c&&!b,timelineHistoryAnchorToken:x,timelineOnIsAtEndChange:y,headerSlot:(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:nR},"aria-hidden":`true`}),E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(ca,{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)(fP,{question:e},e.id)),w.map(e=>(0,$.jsx)(oP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?rR:BP},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(FP,{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)(Oa,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:$L,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)(ca,{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)(zN,{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)(fP,{question:e},e.id)),w.map(e=>(0,$.jsx)(oP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(Pk,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?VP:BP},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(FP,{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);lR.displayName=`ChatViewport`;var uR=[{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%]`]}],dR=e=>oa(e.path),fR=(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)]})},pR=e=>{let t=Math.ceil(Math.max(0,e)/qL);return Math.min(YL,KL+t*JL)},mR=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:c,hostedFeatures:l,assistantHistory:u,onRevertMessage:f,warning:p=null,pendingUserMessages:m=BL,onPendingUserMessagesMaterialized:h})=>{let g=l??Ex(void 0),{t:_}=ot();rt(()=>{ti()},[]);let v=Zr(e=>e.openNewSessionDraft),y=Zr(e=>e.setCurrentSession),b=Zr(e=>e.newSessionDraft),x=Zr(e=>e.newSessionDraft.draftSubmitting??!1),S=Zr(e=>e.newSessionDraft.draftEstablishing??!1),C=Zr(e=>e.forkTransition),w=xn(e=>e.projects),T=xn(e=>e.activeProjectId),E=Qr(e=>e.providers),D=Eu(),O=cr(),k=i??O;rt(()=>{!n||!r||!k||jn(k,r)},[n,r,k]);let A=J(e=>D.ensureSessionRenderable(e,{directory:k})),j=s(e=>e.isExpandedInput),M=s(e=>e.stickyUserHeader),N=s(e=>e.promptNavigatorEnabled),P=s(e=>e.allowPromptingSubagentSessions),F=s(e=>e.isTimelineDialogOpen),I=s(e=>e.setTimelineDialogOpen),L=Ft(e=>n&&r?e.streamingMessageIds.get(r)??null:null),R=Ft(e=>L?e.messageStreamStates.get(L)?.phase??null:null),z=wi(r??``,k),B=pR(z);Z.useEffect(()=>{!a||!o||o(a,B)},[o,B,a]);let V=oi(r??``,k).renderable,H=pt(r,k),U=qn(r),W=H??U,ee=Ig({sessionId:r,hasSessionEntity:!!W,hasRenderableSessionSnapshot:V,composerSurfaceKind:c?.kind}),G=r?JSON.stringify([k,r]):null,[K,q]=Z.useState({key:G,attempt:0}),te=pr(r??``,k,{suspendPartUpdates:!!L,suspendPartUpdatesForMessageId:L}),ne=r?te:zL,re=b.pendingUserMessage,ie=Zr(e=>r?e.retainedPendingUserMessages.get(r):void 0)??BL,ae=Zr(e=>e.clearRetainedPendingUserMessages),oe=Z.useMemo(()=>{if(ie.length===0)return m;if(m.length===0)return ie;let e=new Set(m.map(e=>e.info.id));return[...m,...ie.filter(t=>!e.has(t.info.id))]},[m,ie]),se=Z.useMemo(()=>LL(ne),[ne]),ce=Z.useMemo(()=>{if(!se.modelId)return _(`common.unavailable`);let e=E.find(e=>e.id===se.providerId);return Ai(e,se.modelId)||se.modelId},[E,se.modelId,se.providerId,_]),le=Br(r??``,k),ue=ri(r??``,k),[de,fe]=Z.useState(null),pe=!!r&&de===r,me=J(()=>{if(!r||pe)return;let e=r,t=k;fe(e);let n=Fi(()=>{let n=zi();if(!n)throw Error(`unbound`);return n.getTranscript(un(t,e))});Fr(_r({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 ht(t,e),await D.ensureSessionRenderable(e,{directory:t});try{let r=Fi(()=>{let n=zi();if(!n)throw Error(`unbound`);return n.getTranscript(un(t,e))});n&&r&&Mr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){Fr(_r({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:ue,error:n}))}finally{fe(t=>t===e?null:t)}})()}),he=Ir(r??``,k).boundary,ge=J(async e=>{if(he.kind===`has-more`){await Nn(k,e);return}if(he.kind===`unknown`){await Wi(k,e);return}u&&!u.complete&&await u.fetchPrevious()});uL(r??``,ne);let _e=wr(r??``,k),ve=Ar(r??``,k),ye=hi(k),be=_e??VL,xe=or(r,k),Se=On(r,k);bL(r,k,ne,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`||_x(oe,{resolvedSessionStatus:_e,sessionStatusObservedAt:ve}))return!0;let t=ne[ne.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,oe,_e,ne,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():``)||WL,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&&D.isLoading(r,{directory:k})),Ae=Z.useMemo(()=>{if(!r)return null;let e=vx({boundary:he,assistantComplete:u?.complete??!0});return{limit:he.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:yx({syncLoading:ke,assistantLoading:!!u?.loading})}},[u?.complete,u?.loading,r,he,ke]),je=s(e=>e.isMobile),Me=$h()!==null,Ne=d(),Pe=xg(),Fe=!!b?.open,Ie=At(e=>e.error),Le=j,Re=Me||je||Ne||Pe===`mini-chat`,ze=Z.useRef(null),Be=Z.useMemo(()=>{let e=b?.selectedProjectId?w.find(e=>e.id===b.selectedProjectId)??null:null,t=T?w.find(e=>e.id===T)??null:null,n=e??t??w[0]??null;return n?dR(n):null},[T,b?.selectedProjectId,w]),Ve=Qn(r,k),He=a??r??``,[Ue,We]=Z.useState(null),Ge=Vg(Ue,He,Ve,se);rt(()=>{We(e=>Vg(e,He,Ve,se))},[Ve,se,He]);let Ke=Ve??Ge?.parentTarget??null,qe=Ge?.execution??se,Je=ul(),Ye=Je!==null&&r===Je,Xe=J(()=>{Ke&&y(Ke.id,Ke.directory)}),Ze=Ke?.session?.title,Qe=g.returnToParent&&Ke&&!Ye?(0,$.jsxs)(ca,{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":_(`chat.container.returnToParent.aria`),title:Ze?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:Ze}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,$e=Lg({readOnly:t,sessionIdentityPending:ee,isSubagentSession:!!W?.parentID||!!Ge,allowPromptingSubagentSessions:P}),tt=qe.modelId===se.modelId?ce:qe.modelId?Ai(E.find(e=>e.id===qe.providerId),qe.modelId)||qe.modelId:_(`common.unavailable`),st=Ke?(0,$.jsx)(Ax,{agentName:qe.agentName,providerId:qe.providerId,modelId:qe.modelId,modelName:tt}):(0,$.jsx)(Ax,{}),ct=J(e=>{s.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`&&ct({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),ut=typeof window<`u`&&window.parent!==window;it(`message`,lt,ut?window:UL),nt(()=>{if(!ut)return;let e=window;e.__openchamberApplyChatSettingsSync=ct,window.parent.postMessage({type:`openchamber:chat-settings-request`},window.location.origin)}),et(()=>{if(typeof window>`u`)return;let e=window;e.__openchamberApplyChatSettingsSync===ct&&delete e.__openchamberApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Fe&&v()},[e,r,Fe,g.newSessionDraft,v]);let dt=Z.useRef(()=>{}),ft=J(e=>{dt.current(e)}),mt=Z.useRef(()=>{}),gt=J(()=>{mt.current()}),_t=Lx(e=>e.legendTimelineEnabled),[vt,yt]=Z.useState(!0),[bt,xt]=Z.useState(!1),[St,Ct]=Z.useState(!1),[wt,Tt]=Z.useState(0),Et=J(()=>{Tt(e=>e+1)}),Dt=J((e,t)=>{yt(e),e&&Ct(!1),t!==void 0&&xt(t)});Z.useEffect(()=>{yt(!0),xt(!1),Ct(!1)},[r]);let{scrollRef:Ot,notifyContentChange:jt,getAnimationHandlers:Mt,goToBottom:Nt,scrollToBottomOnSend:It,releaseAutoFollow:Lt,beginHistoryViewportPreservation:Rt,endHistoryViewportPreservation:zt,restoreSnapshot:Bt,isPinned:Vt,isFollowingProgrammatically:Ht,showScrollButton:Ut}=pF({enabled:n&&!_t,currentSessionId:r,viewportKey:a,sessionMessageCount:z,sessionIsWorking:Ce,isMobile:je,onActiveTurnChange:ft,onUpwardUserIntent:gt}),Wt=Z.useRef(null);IF({enabled:je,scrollRef:Ot,scopeRef:Wt});let Gt=Z.useRef([]),Kt=Z.useMemo(()=>{let e=Pt(u?.entries??[],r,Gt.current);return Gt.current=e,e},[u?.entries,r]),qt=Z.useRef([]),Jt=Z.useMemo(()=>{if(!u)return ne;let e=In(u.entries,r,ne,qt.current);return qt.current=e,e},[u,r,ne]),Yt=Z.useMemo(()=>gx(Kt.length===0?Jt:r?[...Kt,Pn(r),...Jt]:Kt,oe),[r,Jt,Kt,oe]),Xt=Z.useRef(null),Zt=Z.useMemo(()=>Tx({sessionId:r,messages:Yt,retained:Xt.current}),[r,Yt]);Xt.current=Zt.retained;let Qt=Zt.messages,$t=Z.useRef(null),en=$t.current===r,tn=Z.useRef(sL),nn=r?`${k}\n${r}`:null,rn=J(()=>oL(Qt));Z.useEffect(()=>{if(!r||!nn||!Ce){tn.current={...tn.current,lastMovementAt:null};return}let e=r,t=k,n=setInterval(()=>{let n=rn(),r=cL(tn.current,{sessionKey:nn,working:!0,streaming:!!L,fingerprint:n,now:Date.now(),thresholdMs:nL,cooldownMs:rL,maxAttempts:3});tn.current=r.state,r.shouldRefresh&&(lL({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),vn(t,e).catch(()=>{}))},iL);return()=>clearInterval(n)},[r,k,rn,Ce,L,nn]);let an=Z.useMemo(()=>{if(oe.length===0)return[];let e=new Set([...Kt,...Jt].filter(e=>kt(e.parts)).map(e=>e.info.id));return oe.map(e=>e.info.id).filter(t=>e.has(t))},[Jt,Kt,oe]);Z.useEffect(()=>{an.length!==0&&(h?.(an),r&&ae(r,an))},[ae,r,an,h]);let sn=JI({sessionId:r,directory:k,messages:Qt,historyMeta:Ae,scrollRef:Ot,messageListRef:ze,loadMoreMessages:ge,goToBottom:Nt,releaseAutoFollow:Lt,beginHistoryViewportPreservation:Rt,endHistoryViewportPreservation:zt,isPinned:_t?vt:Vt,showScrollButton:_t?bt:Ut,autoFillEnabled:n&&!Le,onWillLoadEarlier:Et}),cn=J(()=>{Ct(!1),ze.current?.scrollToBottom(),Nt(`instant`)}),ln=J(()=>{Ct(!1),It()}),dn=J(()=>{Ct(!0),sn.handleHistoryUpwardIntent()}),fn=bx({isMobile:je,canLoadEarlier:sn.historySignals.canLoadEarlier,isLoadingOlder:sn.isLoadingOlder}),pn=sn.isLoadingOlder,mn=sn.loadEarlier,hn=J(()=>{Ct(!0),mn({userInitiated:!0})});dt.current=sn.handleActiveTurnChange,mt.current=sn.handleHistoryUpwardIntent,Z.useEffect(()=>{(xe.length!==0||Se.length!==0)&&jt(`permission`)},[jt,xe,Se]);let gn=tL({sessionId:r,turnIds:sn.turnIds,activeTurnId:sn.activeTurnId,scrollToTurn:sn.scrollToTurn,scrollToMessage:sn.scrollToMessage,resumeToBottom:cn}),_n=$e.showReadOnlyBanner?st:t?null:(0,$.jsx)(cx,{surface:c,scrollToBottom:ln,showScrollToBottom:je&&sn.showScrollToBottom,onScrollToBottom:gn.resumeToLatest,submissionBlocked:$e.blockSubmission}),yn=J(e=>{gn.scrollToTurnId(e,{behavior:`smooth`})}),bn=sn.historySignals.canLoadEarlier,Sn=g.promptNavigator&&!je&&!Ne&&!Le&&N&&sn.turnIds.length>=2;Z.useEffect(()=>{Sn||s.getState().setPromptNavigatorPanelOpen(!1)},[Sn]);let Cn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||Nt(`instant`)});it(HL,Cn,n&&r&&typeof window<`u`?window:UL);let wn=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}=s.getState();if(t!==`chat`||cR())return;let i=Ot.current;if(sR(document.activeElement,i)||oR(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;gn.scrollByTurnOffset(a,{resumePastEnd:!1})});it(`keydown`,wn,n&&r&&!Le&&typeof window<`u`?window:UL);let Tn=Z.useRef(0),En=J(()=>{let e=Ot.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),Dn=J(()=>{Tn.current||=requestAnimationFrame(()=>{Tn.current=0,En()})});rt(()=>{n&&En()},[n,r,Le,En]);let kn=typeof ResizeObserver<`u`;at(n&&kn?Ot:null,Dn),it(`resize`,Dn,n&&!kn&&typeof window<`u`?window:UL),et(()=>{Tn.current&&=(cancelAnimationFrame(Tn.current),0)});let An=Z.useRef(null),Mn=Z.useRef(0),Fn=Cx({transcriptMessageCount:ne.length,pendingUserCount:oe.length,historyPrefixCount:Kt.length}),Ln=wx({hasTranscriptShell:Fn,p0Satisfied:ue.p0Satisfied,hasBusyShell:Ce&&Fn,hasImmediateShell:oe.length>0||Kt.length>0,hasRenderableSessionSnapshot:V,prefetchStatus:le?.status,syncLoading:!!(r&&D.isLoading(r,{directory:k})),userRetrying:pe,hasPaintedTranscript:en});Ln===`pass`&&Qt.length>0&&($t.current=r);let Rn=!!r&&Ln===`hydrating`,zn=!!r&&Ln===`load-error`;Z.useEffect(()=>{!zn||!r||Fr(_r({kind:`request-error`,sessionID:r,directory:k,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,k,zn,le,ue]),Z.useEffect(()=>{if(!n||!r||Rn)return;let e=Qt.length,t=An.current!==r,i=!t&&Mn.current===0&&e>0;if(!t&&!i){An.current===r&&(Mn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(An.current=r,Mn.current=e,a){Lt();return}let o=()=>{Bt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,Rn,Lt,Bt,Qt.length]),Z.useEffect(()=>{q(e=>e.key===G?e:{key:G,attempt:0})},[G]),Z.useEffect(()=>{if(!n||!r||K.key!==G||!RL({sessionId:r,hasRenderableSessionSnapshot:V,hasCurrentSessionEntity:!!W})||(A(r),W||K.attempt>=2))return;let e=K.attempt+1,t=window.setTimeout(()=>{q(t=>t.key===G&&t.attempt===K.attempt?{key:G,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,W,r,k,A,V,G,K]);let Bn=C&&r&&(C.targetSessionId?r===C.targetSessionId:r===C.sourceSessionId)?C:null;if(Bn){let e=Bn.stage===`preparing`?`chat.forkTransition.preparing`:Bn.stage===`copying`?`chat.forkTransition.copying`:Bn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Bn.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${_(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(e)}),(0,$.jsx)(zp,{})]}),(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)(Mx,{})}):!r&&Fe?(x||S)&&re?(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)(Oa,{className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll`,style:$L,children:[(0,$.jsx)(zN,{sessionKey:`draft:${b.draftID??`pending`}`,messages:[re],sessionIsWorking:!0,isLoadingOlder:!1,onMessageContentChange:jt,getAnimationHandlers:Mt,scrollToBottom:cn}),(0,$.jsxs)(`div`,{className:`chat-message-column px-4 pb-10 pt-2 typography-meta text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zp,{})]})]})})}):x||S?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":_(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zp,{})]})})}):(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:fR(Be?_(`chat.emptyState.draftTitleWithProject`,{project:Be}):_(`chat.emptyState.draftTitle`),Be)}),(0,$.jsx)(N_,{onSubmit:e=>on.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:_n})]}):r?zn?(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:_(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:_(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(ca,{type:`button`,className:`mt-5`,onClick:me,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`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:_n})]}):Rn?(0,$.jsxs)(`div`,{ref:Wt,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:Ot,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:$L,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:uR.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)(ac,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(ac,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(ac,{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)(ac,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(ac,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(ac,{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)(tR,{}):null,_n]})]}):Qt.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)(Mx,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:_n}),(0,$.jsx)(hx,{})]}):(0,$.jsxs)(`div`,{ref:Wt,className:Y(`relative flex flex-col h-full bg-background`,je&&`oc-chat-composer-swap-scope`),children:[p?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:p}):null,Qe,(0,$.jsx)(lR,{currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Le,isMobile:je,stickyUserHeader:M,directory:k,scrollRef:Ot,messageListRef:ze,pendingRevealWork:sn.pendingRevealWork,renderedMessages:sn.renderedMessages,isLoadingOlder:pn,sessionIsWorking:Ce,streamingMessageId:L,activeStreamingPhase:R,retryOverlay:Oe,handleMessageContentChange:jt,getAnimationHandlers:Mt,handleHistoryScroll:sn.handleHistoryScroll,handleHistoryUpwardIntent:dn,onTimelineIsAtEndChange:Dt,timelineFollowSuspended:St,timelineHistoryAnchorToken:wt,scrollToBottom:cn,sessionQuestions:Se,sessionPermissions:xe,isProgrammaticFollowActive:Ht,showLoadOlderButton:fn,onLoadOlder:hn,turnIds:sn.turnIds,activeTurnId:sn.activeTurnId,onSelectTurn:yn,showPromptNavigator:Sn,canLoadEarlierPrompts:bn,isLoadingOlderPrompts:pn,onLoadEarlierPrompts:hn},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)(tR,{}):null,!Le&&Qt.length>0&&(je?(0,$.jsx)(yg,{placement:`expanded`,visible:sn.showScrollToBottom,onClick:gn.resumeToLatest}):(0,$.jsx)(yg,{visible:sn.showScrollToBottom,onClick:gn.resumeToLatest})),_n]}),(0,$.jsx)(hx,{}),(0,$.jsx)(XI,{open:F,onOpenChange:I,sessionID:r??void 0,directory:k,onRevertMessage:f,onScrollToMessage:sn.scrollToMessage,onScrollByTurnOffset:gn.scrollByTurnOffset,onResumeToLatest:cn,canLoadEarlier:sn.historySignals.canLoadEarlier,isLoadingEarlier:pn,onLoadEarlier:hn})]}):null});mR.displayName=`MemoizedChatContainerContent`;var hR=()=>{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)(ac,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(ac,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(ac,{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)(ac,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(ac,{className:`h-4 w-3/5 animate-none rounded-md`})]}),(0,$.jsx)(ac,{className:`h-24 w-full animate-none rounded-xl`})]})})}),e[1]=n):n=e[1],n},gR=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=xg(),a=cr(),o=Zr(pe(bR)),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=wL(c),t[7]=c,t[8]=l);let u=l,f=u.key,p=bt()||d()||i===`mini-chat`?ZL:XL,m;t[9]!==p||t[10]!==c||t[11]!==u?(m=()=>({activeIntent:u,cacheNeedsTrim:!1,cachedSessionViews:c?EL([],c,p,KL):[],pendingSessionView:null}),t[9]=p,t[10]=c,t[11]=u,t[12]=m):m=t[12];let[h,g]=Z.useState(m),_=Z.useRef(u),v=Z.useRef(f),{cacheNeedsTrim:y,cachedSessionViews:b,pendingSessionView:x}=h,S=x?.intent===u?x.entry:null,C;if(t[13]!==b||t[14]!==S){let e=[...b];S&&!e.some(e=>e.key===S.key)&&e.push(S),C=e.sort(xR),t[13]=b,t[14]=S,t[15]=C}else C=t[15];let w=C,T;t[16]!==w||t[17]!==f?(T=OL(w,f),t[16]=w,t[17]=f,t[18]=T):T=t[18];let E=T,D=!!(f&&!E),O;t[19]!==p||t[20]!==u||t[21]!==f?(O=()=>{_.current=u,v.current=f,g(e=>kL(e,u,p))},t[19]=p,t[20]=u,t[21]=f,t[22]=O):O=t[22];let k;t[23]!==p||t[24]!==y||t[25]!==u||t[26]!==f?(k=[p,y,u,f],t[23]=p,t[24]=y,t[25]=u,t[26]=f,t[27]=k):k=t[27],rt(O,k);let A=x?.intent??null,j,M;t[28]!==p||t[29]!==A?(j=()=>{A&&g(e=>jL(e,A,p))},M=[p,A],t[28]=p,t[29]=A,t[30]=j,t[31]=M):(j=t[30],M=t[31]),rt(j,M);let N;t[32]!==E||t[33]!==u||t[34]!==f?(N=()=>{if(!u.selection||E)return;let e=u,t=f;return mc(()=>{_.current===e&&v.current===t&&g(n=>v.current===t?AL(n,e,_.current,KL):n)},{priority:`user-blocking`})},t[32]=E,t[33]=u,t[34]=f,t[35]=N):N=t[35];let P;t[36]!==E||t[37]!==p||t[38]!==u||t[39]!==f?(P=[E,p,u,f],t[36]=E,t[37]=p,t[38]=u,t[39]=f,t[40]=P):P=t[40],Z.useEffect(N,P);let F;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(F=(e,t)=>{let n=_.current,r=v.current;g(i=>{if(_.current!==n||v.current!==r||i.activeIntent!==n||e!==r)return i;let a=DL(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})},t[41]=F):F=t[41];let I=J(F),L=D||void 0,R;t[42]!==D||t[43]!==f?(R=D?(0,$.jsx)(hR,{},f):null,t[42]=D,t[43]=f,t[44]=R):R=t[44];let z;if(t[45]!==E||t[46]!==I||t[47]!==n||t[48]!==w){let e;t[50]!==E||t[51]!==I||t[52]!==n?(e=e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:E===e.key?`visible`:`hidden`,children:(0,$.jsx)(mR,{...n,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:I})},e.key),t[50]=E,t[51]=I,t[52]=n,t[53]=e):e=t[53],z=w.map(e),t[45]=E,t[46]=I,t[47]=n,t[48]=w,t[49]=z}else z=t[49];let B;t[54]!==n||t[55]!==o.directory||t[56]!==f?(B=f?null:(0,$.jsx)(mR,{...n,sessionId:null,sessionDirectory:o.directory}),t[54]=n,t[55]=o.directory,t[56]=f,t[57]=B):B=t[57];let V;return t[58]!==L||t[59]!==R||t[60]!==z||t[61]!==B?(V=(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":L,children:[R,z,B]}),t[58]=L,t[59]=R,t[60]=z,t[61]=B,t[62]=V):V=t[62],V},_R=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=Ex(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)(mR,{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)(Nh.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},vR=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=cr(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Mh({...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)(mR,{...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)(Nh.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},yR=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(QL,i,i);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(_R,{...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)(vR,{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)(gR,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r};function bR(e){return{sessionId:e.currentSessionId,directory:e.currentSessionDirectory}}function xR(e,t){return e.key.localeCompare(t.key)}export{su as $,Ug as A,Nm as B,v_ as C,a_ as D,g_ as E,Qh as F,Jp as G,xm as H,$h as I,Ju as J,zp as K,kh as L,bg as M,yg as N,s_ as O,pg as P,ou as Q,Ah as R,__ as S,b_ as T,im as U,Em as V,qp as W,Mu as X,Ku as Y,Eu as Z,ky as _,pF as a,il as at,U_ as b,PO as c,GE as d,tl as et,FE as f,Fy as g,Ax as h,KF as i,ll as it,Wg as j,Jg as k,WE as l,Lx as m,LL as n,rl as nt,zN as o,yE as p,gd as q,YF as r,sl as rt,Nk as s,yR as t,nl as tt,UE as u,Oy as v,h_ as w,m_ as x,ev as y,Nh as z};
|
|
6579
|
+
`)}return ut&&ut.trim().length>0?ut:ar(ze)},[ut,ze,q]),pt=ft.length>0,mt=Z.useCallback(async()=>(await ct(ft)).ok?(q&&(R(!0),setTimeout(()=>R(!1),2e3)),!0):!1,[q,ft]),ht=Z.useCallback(async()=>{if(!(!re||!e.info.id||V.current)){V.current=`revert`,B(`revert`);try{_.onRevertMessage?await _.onRevertMessage(e.info.id):await w(re,e.info.id,{directory:_.directory??void 0})}finally{V.current=null,B(null)}}},[re,e.info.id,w,_]),gt=J(()=>{if(!re||!e.info.id||V.current)return;let t={info:e.info,parts:e.parts};if(_.onEditMessage){_.onEditMessage(e.info.id,t).catch(()=>{});return}T(re,e.info.id,t).catch(()=>{})}),_t=J(()=>{re&&k(re)}),vt=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(!V.current){V.current=`fork`,B(`fork`);try{await E(re,e.info.id)}finally{V.current=null,B(null)}}},[re,e.info.id,E]),yt=J(t=>{let n=He.has(t),r=Ue.has(t);if(n){ee(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),ok(e.info.id,i),i}),r||U(n=>{let r=new Set(n);return r.delete(t),ik(e.info.id,r),r});return}U(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),ik(e.info.id,r),r}),ee(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),ok(e.info.id,r),r})}),bt=i??null,xt=Z.useRef(!1),St=Z.useRef(!1),Ct=Z.useRef(!1),wt=Z.useRef(!1),Tt=Z.useRef(!1),Et=Z.useRef(!1);Z.useEffect(()=>{St.current=!1,Ct.current=!1,wt.current=!1,Tt.current=!1,xt.current=!1,Et.current=!1},[e.info.id]);let Dt=Z.useCallback(()=>{q||xt.current||(xt.current=!0,r?.(`structural`))},[q,r]),Ot=s(e=>e.setImagePreviewOpen),kt=Z.useCallback(e=>{(e.image||e.mermaid)&&(K(e),Ot(!0))},[Ot]),At=Z.useCallback(e=>{K(t=>({...t,open:e})),Ot(e)},[Ot]),jt=!!fk(e.info,`animationSettled`),Mt=nt===`streaming`||nt===`cooldown`;Mt&&(Et.current=!0);let Nt=Z.useMemo(()=>!q&&Re.some(e=>e.type===`reasoning`),[q,Re]),Pt=Je&&!jt&&!Mt&&!Et.current,Ft=!q&&Je&&Be.length>0&&!qe;return Z.useEffect(()=>{if(bt?.onStreamingCandidate){if(!Ft){Ct.current&&=(Nt&&bt?.onReasoningBlock?bt.onReasoningBlock():bt?.onReservationCancelled&&bt.onReservationCancelled(),!1);return}Tt.current||(Tt.current=!0,bt.onStreamingCandidate(),Ct.current=!0)}},[bt,Ft,Nt]),Z.useEffect(()=>{bt?.onAnimationStart&&Pt&&(wt.current||=(bt.onAnimationStart(),!0))},[bt,Pt]),Z.useEffect(()=>{if(q)return;let e=bt?.onAnimatedHeightChange;if(!e||!(Pt||Ft))return;let t=b.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[Pt,q,bt,Ft]),Ge?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,q?m?`pt-2`:`pt-6`:!q&&rt?m?M?`pt-4`:`pt-0`:`pt-6`:`pt-0`,q||tt?`pb-0`:et?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:b,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:q?yn(ze)?(0,$.jsx)(gc,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,m?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)(PO,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:q,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:it,expandedTools:H,onToggleTool:yt,onShowPopup:kt,streamPhase:nt,allowAnimation:Pt,onContentChange:r,shouldShowHeader:!1,hasTextContent:pt,onCopyMessage:mt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!D&&v.edit?gt:void 0,onRevert:!D&&v.revert?ht:void 0,onFork:!D&&q&&v.fork?vt:void 0,editing:D,editStaged:O,onCancelEdit:O?_t:void 0,pendingMessageAction:z,errorMessage:ut,errorVariant:dt,userActionsMode:te?`external-content`:`inline`,stickyUserHeaderEnabled:M})}),te?(0,$.jsx)(PO,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:q,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:it,expandedTools:H,onToggleTool:yt,onShowPopup:kt,streamPhase:nt,allowAnimation:Pt,onContentChange:r,shouldShowHeader:!1,hasTextContent:pt,onCopyMessage:mt,copiedMessage:L,showReasoningTraces:j,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!D&&v.edit?gt:void 0,onRevert:!D&&v.revert?ht:void 0,onFork:!D&&q&&v.fork?vt:void 0,editing:D,editStaged:O,onCancelEdit:O?_t:void 0,pendingMessageAction:z,errorMessage:ut,errorVariant:dt,userActionsMode:`external-actions`,stickyUserHeaderEnabled:M}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[rt&&(0,$.jsx)(Kx,{isUser:q,isMobile:m,providerID:ke,modelID:Ae,agentName:Oe,modelName:je,variant:st}),(0,$.jsx)(PO,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Re,sourceParts:ce,isUser:q,isMessageCompleted:Pe,messageFinish:Fe,messageCompletedAt:Me??void 0,messageCreatedAt:Ne??void 0,messageTokens:Ie,isMobile:m,alwaysShowActions:y,hasTouchInput:g,copiedCode:F,onCopyCode:it,expandedTools:Ue,onToggleTool:yt,onShowPopup:kt,streamPhase:nt,allowAnimation:Pt,onContentChange:r,shouldShowHeader:rt,hasTextContent:pt,onCopyMessage:mt,copiedMessage:L,onAuxiliaryContentComplete:Dt,showReasoningTraces:j,agentMention:We,turnGroupingContext:a,errorMessage:ut,errorVariant:dt,reviewTransferDirection:f})]})})}),G.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(ZO,{popup:G,onOpenChange:At,isMobile:m})}):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,VO(e.message.info).isUser)),mk=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},hk=e=>{let t=e?.type;return t===`compaction`||t===`text`&&mk(e).trim()===`/compact`},gk=e=>e?e.some(e=>hk(e)):!1,_k=e=>gk(e.parts),vk=e=>e?gk(e.sourceParts)||gk(e.parts):!1,yk=e=>{if(!_k(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}},bk=e=>{let t=hn(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},xk=new WeakMap,Sk=e=>{let t=xk.get(e);if(t)return t;let n=yk(bk(e)),r=n.parts,i=yi(r),a=i===r?n:{...n,parts:i,sourceParts:r};return xk.set(e,a),a},Ck={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},wk=[],Tk=`\0`,Ek=new Set([`edit`,`write`,`multiedit`,`apply_patch`]),Dk={read:`chat.assistantStatus.readingFile`,write:`chat.assistantStatus.writingFile`,edit:`chat.assistantStatus.editingFile`,multiedit:`chat.assistantStatus.editingFiles`,apply_patch:`chat.assistantStatus.applyingPatch`,bash:`chat.assistantStatus.runningCommand`,grep:`chat.assistantStatus.searchingContent`,glob:`chat.assistantStatus.findingFiles`,list:`chat.assistantStatus.listingDirectory`,task:`chat.assistantStatus.delegatingTask`,webfetch:`chat.assistantStatus.fetchingUrl`,websearch:`chat.assistantStatus.searchingWeb`,codesearch:`chat.assistantStatus.webCodeSearch`,todowrite:`chat.assistantStatus.updatingTodos`,todoread:`chat.assistantStatus.readingTodos`,skill:`chat.assistantStatus.learningSkill`,question:`chat.assistantStatus.askingQuestion`,plan_enter:`chat.assistantStatus.switchingToPlanning`,plan_exit:`chat.assistantStatus.switchingToBuilding`},Ok=[`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`],kk=(e,t)=>{let n=Dk[e];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},Ak=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)},jk=(e,t)=>t(Ok[Ak(e)%Ok.length]??`chat.assistantStatus.working`),Mk=(e,t,n)=>{let r,i;if(!Qt(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??Rk(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=zk(n);Ek.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=Lk(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=Rk(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?i===`multiedit`?kk(i,n):n(`chat.assistantStatus.editingFile`):r===`tool`&&i?kk(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):jk(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},Nk=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(Tk),Pk=e=>{let[t,n,r=`working`,i]=e.split(Tk);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},Fk=e=>e.type===`reasoning`,Ik=e=>e.type===`text`,Lk=e=>{if(Ik(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},Rk=e=>(Ik(e)||Fk(e),e.time),zk=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function Bk(e,t){let{t:n}=ot(),r=Zr(e=>e.currentSessionId),i=Zr(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),c=Zr(s),l=di(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=xr(d??``,o??void 0,a??void 0),h=xr(p??``,o??void 0,a??void 0),g=!!p&&gk(h),_=!!(d&&rE(u.finish,m,u.error)),v=Z.useMemo(()=>{let e=`${a??``}:${d??``}`;return Nk(Mk(d?m:wk,e,n))},[a,d,m,n]),y=ei(a??``,o??void 0),b=Pi(a??``,o??void 0),x=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),S=Zr(x),{phase:C,isWorking:w}=jg(a,o??void 0),T=wr(a??``,o??void 0),E=T?.type===`retry`?T.attempt:void 0,D=T?.type===`retry`?T.next:void 0,O=Z.useMemo(()=>Pk(v),[v]),k=Z.useMemo(()=>{let e=!!(S&&!S.acknowledged);return{wasAborted:e,abortActive:e}},[S]),A=Z.useMemo(()=>{if(k.wasAborted)return{...Ck,wasAborted:!0,abortActive:k.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};if(_)return{...Ck,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 Vk=Z.memo(()=>{let e=(0,Q.c)(14),t=Ph(),n=Zr(Hk),r=Zr(Uk),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=Zr(o),c=Zr(Wk),l=Zr(Gk),{working:u}=Bk(i,a),d=Qr(Kk),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)(zh,{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});Vk.displayName=`StatusRowContainer`;function Hk(e){return e.currentSessionId}function Uk(e){return e.currentSessionDirectory}function Wk(e){return e.abortPromptSessionId}function Gk(e){return e.abortPromptExpiresAt}function Kk(e){return e.currentAgentName}var qk=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}),Jk=new Set,Yk=()=>{},Xk=()=>{},Zk=Z.memo(e=>{let t=(0,Q.c)(32),{turn:n,activityExpanded:r,showCompactionStatus:i,pendingAssistantHeader:a,onToggleActivity:o,stickyUserHeader:c,renderMessage:l}=e,u=a===void 0?null:a,d=c===void 0||c,f=s(Qk),p=n.userMessage.info.time?.created,m=n.activityPresentationKind===`compaction`,h=`turn-${n.turnId}`,g;t[0]!==r||t[1]!==m||t[2]!==l||t[3]!==d||t[4]!==n.userMessage?(g=m?null:d?(0,$.jsxs)(`div`,{className:`sticky top-0 z-20 relative bg-[var(--surface-background)] [overflow-anchor:none]`,children:[(0,$.jsx)(`div`,{className:`relative z-10`,children:l(n.userMessage,r)}),(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-full z-0 h-4 bg-gradient-to-b from-[var(--surface-background)] to-transparent sm:h-8`})]}):l(n.userMessage,r),t[0]=r,t[1]=m,t[2]=l,t[3]=d,t[4]=n.userMessage,t[5]=g):g=t[5];let _;t[6]!==f||t[7]!==u||t[8]!==d||t[9]!==n.assistantMessages?(_=u?(0,$.jsx)(`div`,{className:`group w-full ${f?d?`pt-4`:`pt-0`:`pt-6`} ${n.assistantMessages.length===0?`pb-1`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(Kx,{isUser:!1,isMobile:f,providerID:u.providerID,modelID:u.modelID,agentName:u.agentName,modelName:u.modelName,variant:u.variant})})}):null,t[6]=f,t[7]=u,t[8]=d,t[9]=n.assistantMessages,t[10]=_):_=t[10];let v;t[11]!==r||t[12]!==f||t[13]!==o||t[14]!==i||t[15]!==n.assistantMessages||t[16]!==n.completionDisposition||t[17]!==n.durationMs||t[18]!==p?(v=i?(0,$.jsx)(`div`,{className:`group w-full ${f?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(ZD,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof p==`number`?p:void 0,onToggle:o,isMobile:f,expandedTools:Jk,onToggleTool:Yk,onShowPopup:Xk,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[11]=r,t[12]=f,t[13]=o,t[14]=i,t[15]=n.assistantMessages,t[16]=n.completionDisposition,t[17]=n.durationMs,t[18]=p,t[19]=v):v=t[19];let y;t[20]!==r||t[21]!==l||t[22]!==n.assistantMessages?(y=(0,$.jsx)(qk,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:l}),t[20]=r,t[21]=l,t[22]=n.assistantMessages,t[23]=y):y=t[23];let b;return t[24]!==r||t[25]!==h||t[26]!==g||t[27]!==_||t[28]!==v||t[29]!==y||t[30]!==n.turnId?(b=(0,$.jsxs)(`section`,{className:`relative w-full`,id:h,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[g,_,v,y]}),t[24]=r,t[25]=h,t[26]=g,t[27]=_,t[28]=v,t[29]=y,t[30]=n.turnId,t[31]=b):b=t[31],b});function Qk(e){return e.isMobile}var $k=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,eA=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},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},nA=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},rA=(e,t,n,r)=>({id:$k(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:eA(n)}),iA=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`&&tA(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&tE(nA(t),t.parts));e.assistantMessages.forEach(n=>{let r=nA(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`?tA(o):void 0,u=$k(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&tE(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({...rA(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}},aA=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}},oA=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},sA=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(tE(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!nE(t))continue;let r=oA(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:$k(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=oA(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:$k(n.info.id,t,e)}}}return{}},cA=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}},lA=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},uA=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},dA=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},fA=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},pA=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},hA=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},gA=(e,t)=>{let n=uA(e);return{messageId:e.info.id,role:n,parentMessageId:dA(e),message:e,order:t}},_A=(e,t)=>{let n=fA(e),r,i,a=!1;t.forEach(e=>{let t=pA(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}},vA=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`||eE(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 pA(t)!=`number`)return`active`;return`active`},yA=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return rE(n.finish,t.parts,n.error)},bA=e=>vk(e)?`compaction`:`default`,xA={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},SA=(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},CA=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&SA(e.assistantMessages,t.assistantMessages),wA=(e,t)=>{e.summary=sA(e.assistantMessages),e.summaryText=e.summary.text??hA(e.userMessage),e.diffStats=cA(e.userMessage),e.changedFiles=t.showTurnChangedFiles?lA(e.userMessage):void 0,e.completionDisposition=vA(e.assistantMessages),e.hasConfirmedFinalBody=yA(e.assistantMessages),e.activityPresentationKind=bA(e.userMessage);let n=iA({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=_A(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},TA=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>wA(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&&CA(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,wA(e,t))});return r&&i?n.turns:a},EA=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},DA=(e,t)=>{let n={...xA,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(uA(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[gA(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(uA(e)!==`assistant`)return;let n=dA(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(gA(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=aA(EA(TA(r,n))),s=new Set;return e.forEach(e=>{uA(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},OA=30,kA=4,AA=4,jA=33554432,MA=8388608,NA=new Map,PA=new Map,FA=0,IA=new WeakMap,LA=1,RA=()=>d()?kA:bt()?AA:OA,zA=()=>d()||bt()?MA:jA,BA=(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},VA=e=>{NA.delete(e);let t=PA.get(e)??0;PA.delete(e),FA=Math.max(0,FA-t)},HA=e=>{let t=IA.get(e);if(t!==void 0)return t;let n=LA;return LA+=1,IA.set(e,n),n},UA=e=>e.map(e=>`${HA(e.info)}:${HA(e.parts)}:${e.parts.map(e=>HA(e)).join(`,`)}`).join(`;`),WA=(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,UA(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},GA=e=>{let t=NA.get(e);return t&&(NA.delete(e),NA.set(e,t)),t},KA=(e,t)=>{VA(e);let n=RA(),r=zA(),i=BA(e,t);if(!(i>r)){for(;NA.size>=n||FA+i>r;){let e=NA.keys().next().value;if(typeof e!=`string`)break;VA(e)}NA.set(e,t),PA.set(e,i),FA+=i}},qA=[],JA=(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},YA=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},XA=(e,t)=>t===null?{staticTurns:e,streamingTurns:qA}:{staticTurns:t===0?qA:e.slice(0,t),streamingTurns:e.slice(t)},ZA=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(qA),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=qA,a.current=null);let l=Z.useMemo(()=>{let r=WA(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=GA(r);return i?(n.current=i,i):Se(`ui.turns.projection_ms`,()=>{let i=DA(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,KA(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=YA({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=XA(l.turns,u).staticTurns;return JA(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=XA(l.turns,u).streamingTurns;return JA(i.current,e)?i.current:i.current=e},[u,l.turns])}},QA=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},$A=(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(QA(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(QA(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},ej=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=Lt(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:Sk({...e,parts:r})},tj=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=ej(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=ej(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=DA([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}},nj=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},rj=2,ij=2,aj=e=>Math.min(Math.max(0,e),rj),oj=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+ij),sj=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(OC.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},cj=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ss.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},lj=12,uj=16,dj=new Map,fj=e=>{let t=dj.get(e);if(t)return dj.delete(e),dj.set(e,t),t},pj=(e,t)=>{if(t.size!==0)for(dj.delete(e),dj.set(e,t);dj.size>uj;){let e=dj.keys().next().value;if(typeof e!=`string`)break;dj.delete(e)}},mj=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??lj)),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},hj=(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},gj=({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}},_j=e=>{let{visible:t,preload:n}=gj(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},vj=(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},yj=(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}},bj=(e,t)=>{let n=yj(e,t);return n===null?null:{anchor:n,knownKeys:new Set(t)}},xj=15e3,Sj=(e,t)=>{let n=e.positionByKey(t.key);return n===void 0||!Number.isFinite(n)?null:n-t.offsetFromViewportTop},Cj=(e,t)=>{if(!Number.isFinite(e.scroll))return null;let n=Sj(e,t);return n===null?null:e.scroll-n},wj=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}},Tj=1;function Ej(e,{offset:t=0,hideTopShadow:n=!1,hideBottomShadow:r=!1}={}){let i=e.scrollTop>t+Tj,a=e.scrollHeight-(e.scrollTop+e.clientHeight)>t+Tj,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 Dj(e,t=48){e.dataset.scrollShadow=`true`,e.dataset.orientation=`vertical`,e.style.setProperty(`--scroll-shadow-size`,`${t}px`)}var Oj=.4,kj=e=>!Number.isFinite(e)||e<=0?0:e*Oj,Aj=(e,t=16)=>Number.isFinite(e)&&e>0?e:t,jj=({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),Mj=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)},Nj=({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))},Pj=({scroll:e,parkOffset:t})=>!Number.isFinite(e)||!Number.isFinite(t)?0:Math.max(0,t-e),Fj=`data-oc-timeline-park-end`,Ij=e=>{if(!e)return null;let t=e.getAttribute(Fj);if(t===null||t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null},Lj=(e,t)=>{if(!e)return;if(t===null||!Number.isFinite(t)){e.hasAttribute(`data-oc-timeline-park-end`)&&e.removeAttribute(Fj);return}let n=String(Math.round(t));e.getAttribute(`data-oc-timeline-park-end`)!==n&&e.setAttribute(Fj,n)},Rj=(e,t)=>t!==null&&Number.isFinite(t)?Pj({scroll:e.scrollTop,parkOffset:t}):Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),zj=({usableViewportHeight:e,viewportHeight:t,contentHeight:n})=>{if(!Number.isFinite(e)||e<=0)return 0;let r=kj(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))},Bj=(e,t)=>!Number.isFinite(e)||!Number.isFinite(t)||t<=0?!1:e>t+1,Vj=({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,Hj=({previous:e,reserveId:t,entryKey:n,contentHeight:r,usableViewportHeight:i,viewportHeight:a})=>{let o=zj({usableViewportHeight:i,viewportHeight:a,contentHeight:r}),s=r!==null&&Bj(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&&Vj({previousEndSpaceSize:e.spacerHeight,nextEndSpaceSize:o})?{snapshot:{...c,spacerHeight:0},release:!0}:{snapshot:c,release:!1}},Uj=(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)},Wj=({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=Uj(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=jj({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}},Gj=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},Kj=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))},qj=(e,t)=>e===void 0||!Number.isFinite(e)?t:e<=40?!1:e>=80||t,Jj=(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)},Yj=`data-oc-timeline-anchoring`,Xj=1200,Zj=(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}}},Qj=({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},$j=(e,t)=>!Number.isFinite(t)||t<=0||typeof e!=`number`||!Number.isFinite(e)||t+1>=e?null:t,eM={itemVisiblePercentThreshold:0},tM=100,nM=116,rM=500,iM=new Set,aM=Z.createContext(iM),oM=`oc-reply-reserve`,sM=e=>e.kind===oM,cM=e=>{if(sM(e))return e.spacerHeight>0?e.spacerHeight:void 0},lM=(e,t,n,r,i)=>{if(!e||t)return null;let a=Wj({state:n,anchorIndex:e.anchorIndex,lastIndex:e.anchorIndex,endInsetHeight:r,anchorOffset:i});return a?Nj({anchorTop:a.anchorTop,anchorOffset:i,maxScrollOffset:Mj(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},dM=e=>e.key,fM=e=>e.kind,pM=()=>{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);at(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},mM=({entry:e,index:t,renderEntryRef:n,onMeasuredSizeRef:r})=>{let i=Z.useContext(aM),a=Z.useRef(null);return Z.useLayoutEffect(()=>{let t=a.current;if(!t||typeof ResizeObserver>`u`)return;let n=()=>{let n=t.offsetHeight,i=t.offsetWidth;n>0&&r.current?.(e.key,{height:n,width:i})},i=new ResizeObserver(n);return i.observe(t),n(),()=>i.disconnect()},[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))})},hM=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,sessionIsWorking:h=!1,onIsAtEndChange:g,onScroll:_,header:v,footer:y,className:b,style:x,contentContainerClassName:S,contentContainerStyle:C})=>{let w=Z.useRef(null),T=Z.useMemo(()=>e.map(e=>e.key),[e]),E=Z.useRef(T);E.current=T;let D=Z.useRef(r);D.current=r;let O=J(e=>{w.current=e,u?.(e)}),k=Z.useRef(null),[A,j]=Z.useState(null),[M,N]=Z.useState(0),{height:P,setElement:F}=pM(),{height:I,heightRef:L,setElement:R}=pM(),z=v==null?null:(0,$.jsx)(`div`,{ref:F,"data-oc-timeline-header":``,children:v}),B=y==null?null:(0,$.jsx)(`div`,{ref:R,"data-oc-timeline-footer":``,children:y}),V=Z.useRef(c);V.current=c;let H=Z.useRef(l);H.current=l;let U=J((e=k.current)=>{!e||s?.scrollShadow!==`true`||(Dj(e),Ej(e,{hideTopShadow:V.current,hideBottomShadow:H.current}))}),W=J(e=>{let t=e?.getScrollableNode?.()??null;if(t&&s){for(let[e,n]of Object.entries(s))t.dataset[e]=n;U(t)}k.current=t,o&&(o.current=t),j(t);let n=uM(t,w.current?.getState()?.scrollLength);N(e=>e===n?e:n)}),ee=J(()=>{let e=uM(k.current,w.current?.getState()?.scrollLength);N(t=>t===e?t:e),U()});Z.useLayoutEffect(()=>{U(A)},[l,c,A]),at(typeof ResizeObserver<`u`?A:null,ee);let[G,K]=Z.useState(0),[q,te]=Z.useState(0),ne=G!==q,re=Z.useRef(!0),ie=Z.useRef(!1),[ae,oe]=Z.useState(!1),se=Z.useRef(!1);Z.useLayoutEffect(()=>{re.current=!0,ie.current=!1,se.current=!1,oe(!1)},[t]);let[ce,le]=Z.useState(null),ue=J(e=>{le(t=>t?.token===e?null:t)});Z.useEffect(()=>{p&&le(null)},[p]),Z.useLayoutEffect(()=>{if(m<=0)return;let e=w.current;if(!e)return;let t=bj(e.getState(),E.current);t&&le({token:m,arm:t,holding:!1})},[m]),Z.useEffect(()=>{if(!ce||ce.holding)return;let{token:e}=ce,t=window.setTimeout(()=>{le(t=>t?.token===e&&!t.holding?null:t)},xj);return()=>window.clearTimeout(t)},[ce]);let de=Z.useRef(T);Z.useLayoutEffect(()=>{let e=de.current;de.current=T,Jj(e,T)&&(K(e=>e+1),le(e=>e===null||e.holding?e:{...e,holding:!0}))},[T]),Z.useEffect(()=>{if(!ne)return;let e=window.setTimeout(()=>{te(G)},Xj);return()=>window.clearTimeout(e)},[ne,G]),Z.useEffect(()=>{if(!ce?.holding)return;let{token:e,arm:{anchor:t}}=ce,n=w.current;if(!n||typeof window>`u`){ue(e);return}let r=k.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&&ue(e)}},d=()=>{if(s=null,c)return;let e=n.getState();if(Gj(e)??e.isAtEnd){u(!0);return}let r=Date.now(),l=wj({drift:Cj(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=Sj(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)}},[ue,ce]);let fe=ne||ce!==null;Z.useLayoutEffect(()=>{let e=k.current;if(!(!e||!fe))return e.setAttribute(Yj,`true`),()=>{e.removeAttribute(Yj)}},[fe]);let pe=Z.useMemo(()=>{if(ce===null)return{data:!0,size:ne};let{knownKeys:e}=ce.arm;return{data:!0,size:!0,shouldRestorePosition:t=>e.has(t.key)}},[ce,ne]),[me,he]=Z.useState(()=>mj(T,{restore:fj(t)??null})),ge=Z.useRef(me);ge.current=me;let _e=Z.useRef(0),ve=Z.useRef(0),ye=Z.useRef(null),be=Z.useRef(!1),xe=Z.useRef(null),Se=Z.useMemo(()=>hj(me,T),[me,T]);Z.useEffect(()=>{he(e=>vj(e,T))},[T]),Z.useEffect(()=>()=>{pj(t,ge.current)},[t]);let Ce=J(()=>{be.current=!1;let e=w.current;if(!e)return;let t=E.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()-_e.current>=tM,d=D.current,f=d.resolvePreloadEntries(l),p=_j({entryKeys:t,mountedIndexes:o,visibleStartIndex:s,visibleEndIndex:c,scrollDirection:ye.current,preloadEntries:f,hydratedKeys:ge.current,allowVisibleRelease:u,preloadReleaseLimit:u?f:d.resolvePreloadReleaseWhileScrolling(),visibleReleaseLimit:d.resolveVisibleReleaseLimit()});p.length!==0&&(Te(),Z.startTransition(()=>{he(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})}))}),we=J(()=>{be.current||(be.current=!0,mc(Ce))}),Te=J(()=>{typeof window>`u`||(xe.current!==null&&window.clearTimeout(xe.current),xe.current=window.setTimeout(()=>{xe.current=null,we()},nM))});Z.useEffect(()=>()=>{xe.current!==null&&(window.clearTimeout(xe.current),xe.current=null)},[]);let Ee=J(()=>{we()}),De=J(()=>{_e.current=Date.now();let e=w.current;if(e){let t=e.getState(),n=t.scroll;Number.isFinite(n)&&n!==ve.current&&(ye.current=n>ve.current?`forward`:`backward`,ve.current=n);let r=uM(k.current,t.scrollLength);r>0&&N(e=>e===r?e:r);let i=lM(Ue.current,Me.current,t,L.current,Ge.current);Lj(k.current,i);let a=i===null?null:Pj({scroll:t.scroll,parkOffset:i}),o=a??Kj(t),s=a===null?Gj(t)??t.isAtEnd:a<=40,c=qj(o,ie.current);(s!==re.current||c!==ie.current)&&(re.current=s,ie.current=c,g?.(s,c)),s&&!se.current&&(se.current=!0,oe(!0))}_?.(),U(),we(),Te()}),Oe=Z.useRef(i);Oe.current=i;let[ke,Ae]=Z.useState(null),je=Z.useRef(null),Me=Z.useRef(!1),Ne=Z.useRef(null),Pe=Z.useRef(null),Fe=Z.useRef(0),Ie=Z.useRef(0),Le=Z.useRef(null),Re=J((e,t)=>{let n=w.current,r=n?.getState().sizes.get(e);if(n&&$j(r,t.height)!==null&&n.setItemSize(e,t),Me.current||e!==Pe.current)return;let i=Ne.current;if(i===null)return;let{snapshot:a,release:o}=Hj({previous:je.current,reserveId:i,entryKey:e,contentHeight:t.height,usableViewportHeight:Fe.current,viewportHeight:Ie.current});if(o){Ae(null),nt(i),rt(`reveal`);return}let s=je.current;(s?.spacerHeight!==a.spacerHeight||s?.contentHeight!==a.contentHeight||s?.entryKey!==a.entryKey||s?.reserveId!==a.reserveId)&&Ae(a),Le.current!==i&&rt(`park`)&&(Le.current=i)}),ze=Z.useRef(Re);ze.current=Re;let Be=Z.useMemo(()=>({item:e,index:t})=>sM(e)?(0,$.jsx)(`div`,{"data-oc-reply-reserve":`true`,"aria-hidden":`true`,style:{height:e.spacerHeight,flexShrink:0}}):(0,$.jsx)(mM,{entry:e,index:t,renderEntryRef:Oe,onMeasuredSizeRef:ze}),[]),Ve=Z.useRef(p);Ve.current=p;let He=Z.useRef(ce);He.current=ce;let Ue=Z.useRef(d);Ue.current=d;let We=Z.useRef(0),Ge=Z.useRef(16),Ke=Z.useRef(null),[qe,Je]=Z.useState(null),Ye=d?e[d.anchorIndex]?.key??null:null,Xe=d?.anchorId??Ye,Ze=Xe!==null&&qe===Xe;d||(Le.current=null,We.current=0);let Qe=M>0?M:uM(k.current,w.current?.getState()?.scrollLength),$e=Aj(P),et=jj({viewportHeight:Qe,endInsetHeight:I,anchorOffset:$e}),tt=ke;if(!Xe||!Ye||Ze)ke!==null&&Ae(null),tt=null;else if(et<=0)tt=ke!==null&&ke.reserveId===Xe&&ke.entryKey===Ye?ke:null;else if(ke===null||ke.reserveId!==Xe||ke.entryKey!==Ye){let{snapshot:e}=Hj({previous:ke?.reserveId===Xe?ke:null,reserveId:Xe,entryKey:Ye,contentHeight:ke?.reserveId===Xe?ke.contentHeight:null,usableViewportHeight:et,viewportHeight:Qe});Ae(e),tt=e}je.current=tt,Me.current=Ze,Ne.current=Xe,Pe.current=Ye,Fe.current=et,Ie.current=Qe,Ge.current=$e,Z.useLayoutEffect(()=>{Le.current=null,We.current=0,Ke.current=null,Je(null)},[t]),Z.useLayoutEffect(()=>{d&&ee()},[d]);let nt=J(e=>{e!==null&&Ke.current!==e&&(Ke.current=e,Je(e),f?.(e))}),rt=J(t=>{let n=Ue.current;if(!n||He.current)return!1;let r=w.current;if(!r)return!1;let i=r.getState(),a=Ge.current,o=Wj({state:i,anchorIndex:n.anchorIndex,lastIndex:n.anchorIndex,endInsetHeight:L.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&&(We.current=t+rM),r.scrollToOffset({offset:e,animated:n}),!0}return Bj(o.turnHeight,Fe.current)&&nt(n.anchorId??e[n.anchorIndex]?.key??null),(typeof performance<`u`?performance.now():Date.now())<We.current||!Ve.current||o.scrollDeltaToRevealEnd<1?!1:(r.scrollToOffset({offset:o.targetScrollToRevealEnd,animated:!1}),!0)});Z.useLayoutEffect(()=>{if(!Xe||!Ye||Ze||et<=0)return;let e=je.current;if(e===null||e.reserveId!==Xe||e.entryKey!==Ye)return;let{snapshot:t,release:n}=Hj({previous:e,reserveId:Xe,entryKey:Ye,contentHeight:e.contentHeight,usableViewportHeight:et,viewportHeight:Qe});if(n){Ae(null),nt(Xe),rt(`reveal`);return}t.spacerHeight!==e.spacerHeight&&Ae(t)},[Ye,Ze,Xe,Qe,et]),Z.useLayoutEffect(()=>{!tt||ce||Le.current!==Xe&&rt(`park`)&&(Le.current=Xe)},[tt,ce,Xe]),Z.useLayoutEffect(()=>{let e=k.current,t=w.current;if(e){if(!t){Lj(e,null);return}Lj(e,lM(d,Ze,t.getState(),I,$e))}},[d,I,$e,Ze]);let it=Z.useMemo(()=>{let t=tt?.spacerHeight??0;return!tt||t<=0?e:[...e,{key:`${oM}:${tt.reserveId}`,kind:oM,spacerHeight:t}]},[tt,e]),ot=Z.useMemo(()=>d&&!Ze||!p||ce?!1:{animated:h&&ae,on:{dataChange:!0,itemLayout:!0,layout:!0,footerLayout:!0}},[d,ae,p,ce,Ze,h]);return(0,$.jsx)(aM.Provider,{value:Se,children:(0,$.jsx)($c,{ref:O,refScrollView:W,data:it,extraData:a,keyExtractor:dM,getItemType:fM,getFixedItemSize:cM,renderItem:Be,estimatedItemSize:n,initialScrollAtEnd:!0,recycleItems:!1,maintainScrollAtEnd:ot,maintainVisibleContentPosition:pe,onScroll:De,onViewableItemsChanged:Ee,viewabilityConfig:eM,ListHeaderComponent:z,ListFooterComponent:B,className:b,style:x,contentContainerClassName:S,contentContainerStyle:C})})}),gM=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},_M=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},vM=e=>!e||gM(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`)}),yM=(e,t)=>{if(gM(e)!==`assistant`||t&&_M(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}}},bM=(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(gM(t)===`user`)break;let{hide:i,details:a}=yM(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},xM=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},SM=(e,t)=>{if(e.length===0)return[];if(e.filter(xM).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},CM=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=aE({finish:r.finish,isMessageCompleted:xM(n),activeStreamingPhase:e.activeStreamingPhase});return oE({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},wM=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},TM=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=wM(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},EM=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},DM=e=>{if(typeof e!=`object`||!e)return null;let t=e,n=EM(t.mode)??EM(t.agent),r=EM(t.providerID),i=EM(t.modelID),a=EM(t.model?.variant)??EM(t.variant);return!n&&!r&&!i&&!a?null:{agentName:n,providerId:r,modelId:i,variant:a}},OM=e=>{let t=e?.modelId??null;return{providerID:e?.providerId??null,modelID:t,agentName:e?.agentName,modelName:Ai(void 0,t)||void 0,variant:e?.variant}},kM=e=>!(!e.isLastTurn||!e.sessionIsWorking||e.hasAssistantMessages||e.activityPresentationKind===`compaction`||e.hasActiveStreamingMessage),AM=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:HO(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),jM=5,MM=[],NM=new Set,PM=[],FM=16,IM=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),LM=320,RM=168,zM=8,BM=16,VM=6,HM=12,UM=4,WM=1,GM=2,KM=6,qM=4,JM=()=>bt()?BM:zM,YM=30,XM=180,ZM=5,QM=2,$M=120,eN=1200,tN=80,nN=160,rN=1500,iN=1.5,aN=90,oN=(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},sN=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(IM(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)}}}})(FM),cN=(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})},lN=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),uN=e=>e===`collapsed`?RM:LM,dN=(e,t)=>`${e}::activity:${t}`,fN=(e,t)=>!Number.isFinite(t)||t<=0||e===null?!1:Math.round(e)!==Math.round(t),pN=(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}},mN=(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)},hN=(e,t=0)=>Math.max(e===`collapsed`?HM:VM,Math.max(0,Math.floor(t))),gN=e=>e===`collapsed`?GM:WM,_N=e=>e===`collapsed`?qM:KM,vN=e=>e===`collapsed`?QM:ZM,yN=(e,t)=>{e.current=t},bN=(e,t)=>sN.read(e,t),xN=(e,t,n)=>{!n||t.length===0||sN.write(e,t,n.takeSnapshot())},SN=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},CN=(e,t)=>{if(SN(e)!==`system`)return e;let n=EN(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},wN=e=>!e||SN(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),TN=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},EN=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},DN=(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},ON=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,kN=(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&&!DN(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}},AN=(e,t)=>{let n=kN(t,e);if(!n)return null;let r=ON(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},jN=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},MN=e=>{if(SN(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:jN(e.parts[0])}},NN=(e,t)=>{if(!t)return e;let n=mS(e.parts,t);return n===e.parts?e:{...e,parts:n}},PN=(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}},FN=e=>e.kind===`turn`?e.turn.userMessage.info.id:SN(e.message)===`user`?e.message.info.id:null,IN=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,LN=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=Ph(),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)(pk,{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)(Nh.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,SN(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});LN.displayName=`MessageRow`;var RN=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=WO({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=AM({expansionDisposition:qO({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(!xM(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=CM({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=SM(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(qN)),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=wM(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=TM(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(JN),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,q;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?(q={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]=q):q=t[57];let te=q,ne;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]!==te||t[83]!==H||t[84]!==F||t[85]!==N[0]?.info.id||t[86]!==N.length?(ne=(e,t)=>{let a=SN(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=WO({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:GO({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:te.summaryBody,activityParts:te.activityParts,activityGroupSegments:te.activityGroupSegments,headerMessageId:te.headerMessageId,diffStats:te.diffStats,changedFiles:te.changedFiles,userMessageCreatedAt:te.userMessageCreatedAt,userMessageVariant:te.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(LN,{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]=te,t[83]=H,t[84]=F,t[85]=N[0]?.info.id,t[86]=N.length,t[87]=ne):ne=t[87];let re=nj(ne),ie;bb4:{if(N===n.assistantMessages){ie=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],ie=e}let ae=ie,oe;bb5:{if(!kM({isLastTurn:r,sessionIsWorking:i,hasAssistantMessages:n.assistantMessages.length>0,activityPresentationKind:n.activityPresentationKind,hasActiveStreamingMessage:!!h})){oe=null;break bb5}let e;t[91]===n.userMessage.info?e=t[92]:(e=OM(DM(n.userMessage.info)),t[91]=n.userMessage.info,t[92]=e),oe=e}let se=oe,ce=H.length>0,le=n.assistantMessages.length>0,ue;t[93]!==c||t[94]!==r||t[95]!==i||t[96]!==ce||t[97]!==le||t[98]!==n.activityPresentationKind||t[99]!==n.completionDisposition?(ue=IN({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:ce,hasAssistantMessages:le,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[93]=c,t[94]=r,t[95]=i,t[96]=ce,t[97]=le,t[98]=n.activityPresentationKind,t[99]=n.completionDisposition,t[100]=ue):ue=t[100];let de;return t[101]!==T||t[102]!==C||t[103]!==se||t[104]!==re||t[105]!==ae||t[106]!==v||t[107]!==ue?(de=(0,$.jsx)(Zk,{turn:ae,activityExpanded:C,onToggleActivity:T,showCompactionStatus:ue,pendingAssistantHeader:se,stickyUserHeader:v,renderMessage:re}),t[101]=T,t[102]=C,t[103]=se,t[104]=re,t[105]=ae,t[106]=v,t[107]=ue,t[108]=de):de=t[108],de});RN.displayName=`TurnBlock`;var zN=Z.memo(e=>{let t=(0,Q.c)(31),{message:n,previousMessage:r,nextMessage:i,onMessageContentChange:a,getAnimationHandlers:o,scrollToBottom:s,shouldAnimateUserMessage:c,onUserAnimationConsumed:l,activeStreamingMessageId:u,activeStreamingPhase:d,reviewTransferDirection:f}=e,{t:p}=ot();if(Bi(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)(LN,{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});zN.displayName=`UngroupedMessageRow`;var BN=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)(zN,{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)(RN,{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)(Vk,{})}),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});BN.displayName=`MessageListEntry`;var VN=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=AN(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&bt();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<nN,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*iN},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&oN(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<rN)?w.current===null&&(w.current=performance.now()):(w.current=null,k(e),A=e);let[,j]=Z.useReducer(e=>e+1,0);$e(()=>{if(w.current===null)return;let e=performance.now()-w.current>=rN;(!E()||D()||e)&&j()},T?aN:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=JM(),[F,I]=Z.useState(()=>aj(P));Z.useEffect(()=>{if(!(!_||F>=P))return mc(()=>{Z.startTransition(()=>{I(e=>oj(e,P))})})},[F,_,P]);let L=dN(a,u),[R]=Z.useState(()=>_?bN(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??cN(N,W.current,V.current));let G=Jc({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{mN(z.current,n.getTotalSize()),qc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:tN,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:ee.current}),K=Z.useRef(null),q=Z.useRef(null);_||(K.current=null);let te=J(()=>{if(!_)return;let e=z.current??r?.current;if(!e)return;let t=e.offsetWidth;if(!fN(K.current,t)){K.current===null&&t>0&&(K.current=t);return}K.current=t,q.current!==null&&clearTimeout(q.current),q.current=setTimeout(()=>{q.current=null,G.measure()},220)}),ne=_&&typeof ResizeObserver<`u`;at(ne?z:null,te),at(ne&&r?r:null,te),et(()=>{q.current!==null&&(clearTimeout(q.current),q.current=null)}),rt(()=>{_&&te()},[_]),rt(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=ON(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 re=G.getVirtualItems(),ie=re.map(e=>e.index),[ae,oe]=Z.useState(()=>mj(N,{seedCount:hN(u),restore:fj(L)})),se=hj(ae,N);se!==ae&&oe(se);let ce=Z.useRef(se);ce.current=se;let le=Z.useRef(null);G.scrollDirection&&(le.current=G.scrollDirection);let ue=G.range?.startIndex??re[0]?.index??Math.max(0,A.length-1),de=G.range?.endIndex??re[re.length-1]?.index??Math.max(0,A.length-1),fe=G.isScrolling,pe=Math.max(0,de-ue+1),me=_j({entryKeys:N,mountedIndexes:ie,visibleStartIndex:ue,visibleEndIndex:de,scrollDirection:le.current,preloadEntries:hN(u,pe),hydratedKeys:se,allowVisibleRelease:!fe,preloadReleaseLimit:fe?gN(u):UM,visibleReleaseLimit:fe?0:_N(u)}),he=me.join(`\0`),ge=Z.useRef(me);ge.current=me,Z.useEffect(()=>{if(!(!_||!he))return mc(()=>{Z.startTransition(()=>{oe(e=>{let t=null;for(let n of ge.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,he]),Z.useEffect(()=>{oe(e=>vj(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=G.itemSizeCache,t=vN(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(eN,Math.max($M,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(G),()=>{xN(L,M.current.map(e=>e.key),G),pj(L,ce.current),i?.(null)}},[_,G,L]);let _e=nj((e,t=!0)=>(0,$.jsx)(cj,{enabled:t,children:(0,$.jsx)(BN,{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:_e(e)},e.key))});if(t===`tanstack`){let e=pN(re[0]?.start??0,re[re.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:re.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:_e(t,se.has(t.key))},t.key):null})})})}return null});VN.displayName=`StaticHistoryList`;var HN=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)(BN,{...e})}),t[0]=e,t[1]=n),n});HN.displayName=`TailEntry`;var UN=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=xr(_??``,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=tj(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)(HN,{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};UN.displayName=`StreamingTailContent`;var WN=e=>{let t=(0,Q.c)(72),{historyEntries:n,tailEntries:r,timelineCacheKey:i,directory:a,sessionId:o,scrollRef:c,registerList:l,onHistoryContentChange:u,onTailContentChange:d,getAnimationHandlers:f,scrollToBottom:p,stickyUserHeader:m,sessionIsWorking:h,activityRenderMode:g,turnUiStates:_,onToggleTurnGroup:v,chatRenderMode:y,showTurnChangedFiles:b,shouldAnimateUserMessage:x,onUserAnimationConsumed:S,activeStreamingMessageId:C,activeStreamingPhase:w,reviewTransferDirection:T,header:E,footer:D,scrollClassName:O,scrollStyle:k,scrollDataset:A,onScroll:j,followEnabled:M,historyAnchorToken:N,onIsAtEndChange:P,anchoredUserMessageId:F,onAnchoredTurnParkReleased:I}=e,L=M===void 0||M,R=F===void 0?null:F,z=s(YN),B=n.length,V=r.length>0?r[r.length-1]:void 0,H=V?.key??null,U=xr(C??``,a,o??void 0),W;bb0:{if(!V){W=r;break bb0}let e=y===`sorted`,n;t[0]!==C||t[1]!==U||t[2]!==V||t[3]!==b||t[4]!==e?(n=tj(V,{activeStreamingMessageId:C,liveParts:U,showTextJustificationActivity:e,showTurnChangedFiles:b}),t[0]=C,t[1]=U,t[2]=V,t[3]=b,t[4]=e,t[5]=n):n=t[5];let i=n;if(i===V){W=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],W=a}let ee=W,G;t[9]!==n||t[10]!==ee?(G=ee.length>0?[...n,...ee]:n,t[9]=n,t[10]=ee,t[11]=G):G=t[11];let K=G,q;t[12]!==K||t[13]!==R?(q=Zj(K,R,FN,{anchorOffset:16}),t[12]=K,t[13]=R,t[14]=q):q=t[14];let te=q,ne;t[15]===g?ne=t[16]:(ne={resolvePreloadEntries:e=>hN(g,e),resolvePreloadReleaseWhileScrolling:()=>gN(g),resolveVisibleReleaseLimit:()=>_N(g)},t[15]=g,t[16]=ne);let re=ne,ie;t[17]!==C||t[18]!==w||t[19]!==g||t[20]!==y||t[21]!==B||t[22]!==H||t[23]!==T||t[24]!==h||t[25]!==b||t[26]!==m||t[27]!==_?(ie={historyCount:B,newestTailKey:H,sessionIsWorking:h,activityRenderMode:g,turnUiStates:_,chatRenderMode:y,showTurnChangedFiles:b,stickyUserHeader:m,activeStreamingMessageId:C,activeStreamingPhase:w,reviewTransferDirection:T},t[17]=C,t[18]=w,t[19]=g,t[20]=y,t[21]=B,t[22]=H,t[23]=T,t[24]=h,t[25]=b,t[26]=m,t[27]=_,t[28]=ie):ie=t[28];let ae=ie,oe;t[29]!==C||t[30]!==w||t[31]!==g||t[32]!==y||t[33]!==f||t[34]!==B||t[35]!==H||t[36]!==u||t[37]!==d||t[38]!==v||t[39]!==S||t[40]!==T||t[41]!==p||t[42]!==h||t[43]!==x||t[44]!==m||t[45]!==_?(oe=(e,t,n)=>{let r=t>=B,i=H!==null&&e.key===H;return(0,$.jsx)(yc,{disabled:!r,children:(0,$.jsx)(cj,{enabled:n,children:(0,$.jsx)(BN,{entry:e,onMessageContentChange:r?d:u,getAnimationHandlers:f,scrollToBottom:p,stickyUserHeader:m,sessionIsWorking:i?h:!1,activityRenderMode:g,turnUiStates:_,onToggleTurnGroup:v,chatRenderMode:y,shouldAnimateUserMessage:x,onUserAnimationConsumed:S,activeStreamingMessageId:i?C:null,activeStreamingPhase:i?w:null,reviewTransferDirection:T,showLiveStatusRow:i})})})},t[29]=C,t[30]=w,t[31]=g,t[32]=y,t[33]=f,t[34]=B,t[35]=H,t[36]=u,t[37]=d,t[38]=v,t[39]=S,t[40]=T,t[41]=p,t[42]=h,t[43]=x,t[44]=m,t[45]=_,t[46]=oe):oe=t[46];let se=nj(oe),ce;t[47]===g?ce=t[48]:(ce=uN(g),t[47]=g,t[48]=ce);let le=z&&m,ue;return t[49]!==K||t[50]!==te||t[51]!==L||t[52]!==D||t[53]!==E||t[54]!==N||t[55]!==re||t[56]!==z||t[57]!==I||t[58]!==P||t[59]!==j||t[60]!==l||t[61]!==se||t[62]!==ae||t[63]!==O||t[64]!==A||t[65]!==c||t[66]!==k||t[67]!==h||t[68]!==le||t[69]!==ce||t[70]!==i?(ue=(0,$.jsx)(sj,{enabled:!0,children:(0,$.jsx)(hM,{entries:K,timelineCacheKey:i,estimatedItemSize:ce,hydrationTuning:re,renderEntry:se,rowInvalidationKey:ae,scrollElementRef:c,registerList:l,followEnabled:L,historyAnchorToken:N,anchoredEndSpace:te,onAnchoredTurnParkReleased:I,sessionIsWorking:h,header:E,footer:D,className:O,style:k,scrollElementDataset:A,hideTopScrollShadow:le,hideBottomScrollShadow:z,onScroll:j,onIsAtEndChange:P})}),t[49]=K,t[50]=te,t[51]=L,t[52]=D,t[53]=E,t[54]=N,t[55]=re,t[56]=z,t[57]=I,t[58]=P,t[59]=j,t[60]=l,t[61]=se,t[62]=ae,t[63]=O,t[64]=A,t[65]=c,t[66]=k,t[67]=h,t[68]=le,t[69]=ce,t[70]=i,t[71]=ue):ue=t[71],ue};WN.displayName=`LegendTimelineHost`;var GN=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:c,getAnimationHandlers:l,scrollToBottom:u,scrollRef:d,directory:f,headerSlot:p,footerSlot:m,timelineScrollClassName:h,timelineScrollStyle:g,timelineScrollDataset:_,timelineOnScroll:v,timelineFollowEnabled:y,timelineHistoryAnchorToken:b,timelineOnIsAtEndChange:x,enableSendPark:S=!0},C)=>{Le(`ui.message_list.render`);let{sessionKey:w,virtualizerKey:T}=lN(e,t),E=s(e=>e.stickyUserHeader),D=s(e=>e.chatRenderMode),O=s(e=>e.activityRenderMode),k=s(e=>e.showTurnChangedFiles),A=vr(e=>e.reviewTransferBySessionId.get(w)??null),[j,M]=Z.useState(()=>new Map),N=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),[P,F]=Z.useState(null),I=Z.useRef(null);I.current=P;let L=J(t=>{Bt(e),I.current===t&&F(null)}),R=J(l),z=J(()=>{u?.()}),B=J((e,t)=>{M(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:UO(i)}),r})}),V=Z.useMemo(()=>Se(`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(Sk(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=CN(t,a);vk(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(wN(o)){let e=MN(n);if(e.hide){i[i.length-1]=NN(o,e.taskSessionId);continue}}if(vM(o)){let e=yM(n,TN(o));if(e.hide){i[i.length-1]=PN(o,e.details);continue}}i.push(n)}return i}),[n]),H=Z.useRef(null),U=Z.useRef(null),W=Z.useCallback(()=>{let e=U.current;e&&(U.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{W()},[W]);let ee=J(()=>d?.current?d.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),G=Z.useMemo(()=>Se(`ui.message_list.retry_overlay_ms`,()=>$A(V,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[V,o]),K=r||!!i,q=Z.useRef(K),te=Z.useRef(w);te.current!==w&&(te.current=w,q.current=!1),K&&(q.current=!0);let{projection:ne,staticTurns:re,streamingTurns:ie}=ZA(G,{sessionKey:w,showTextJustificationActivity:D===`sorted`,showTurnChangedFiles:k,hasLiveTail:K||q.current,liveTailActive:K}),ae=ne.ungroupedMessageIds.size>0,oe=ae?G:MM,se=ae?ne.ungroupedMessageIds:NM,ce=Z.useMemo(()=>Se(`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 PM;let e=G[G.length-1];return!e||!ne.ungroupedMessageIds.has(e.info.id)?PM:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:G.length>1?G[G.length-2]:void 0,nextMessage:void 0}]},[G,ne.lastTurnId,ne.ungroupedMessageIds,ie]),ue=le.length>0;ue&&K&&Le(`ui.message_list.render.streaming`);let de=ce,fe=de.length>=jM,pe=Z.useRef(fe);yN(pe,fe);let me=fe?`tanstack`:`none`,he=Wx(e=>e.legendTimelineEnabled),ge=Z.useRef(null),_e=J(e=>{ge.current=e}),ve=Z.useRef(null),ye=J(e=>{ve.current=e}),be=Z.useMemo(()=>le.length>0?[...de,...le]:de,[de,le]),xe=J(e=>{c(e)}),Ce=J(e=>{c(e)}),we=Z.useMemo(()=>n.filter(e=>SN(e)===`user`).map(e=>e.info.id),[n]),Te=N.current,Ee=Te.sessionKey!==e,De=Te.previousOrder;Ee&&(S&&Te.sessionKey!==void 0&&Bt(Te.sessionKey),Te.sessionKey=e,Te.previousOrder=we,Te.animatedIds=new Set);let Oe=S?en({sessionId:e,sessionChanged:Ee,previousUserOrder:De,currentUserOrder:we,animatedIds:Te.animatedIds}):null;Te.previousOrder=we;let ke=S?Qj({sessionChanged:Ee,previousUserOrder:De,currentUserOrder:we,currentAnchorId:P,consumedSendMessageId:Oe}):null;S&&ke!==P&&F(ke),S&&(I.current=ke);let Ae=J(e=>SN(e)===`user`&&N.current.animatedIds.has(e.info.id)),je=J(e=>{N.current.animatedIds.delete(e)}),Me=Z.useMemo(()=>{let e=new Map;return be.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},[be]),Ne=Z.useMemo(()=>{let e=new Map;return be.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[be]),Pe=J(e=>{let t=ee();return t?t.querySelector(`[data-message-id="${e}"]`):null}),Fe=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}),Ie=J((e,t=`auto`)=>{let n=ee();if(!n)return!1;let r=Pe(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(!C)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=Ne.get(e);if(r===void 0)return!1;let i=ee();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:Fe(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=Me.get(e);return r===void 0?!1:Ie(e,n)||(ue&&r>=de.length?!1:Fe(r,n))},holdViewportAnchor:e=>{let t=ee();if(!t||typeof window>`u`)return;W();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(),U.current?.cancel===s&&(U.current=null))},c=()=>{s()};U.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=Pe(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>=YM||n>=XM){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:W,isHistoryVirtualized:()=>he?!0:pe.current,captureViewportAnchor:()=>{let e=ee();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`||!DN(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=ee();if(!t||!Me.has(e.messageId))return!1;let n=()=>{let n=Pe(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=Me.get(e.messageId);if(typeof t==`number`&&t<de.length)return Fe(t,`auto`)}return n()},scrollToBottom:()=>{if(he){let e=Ij(ee());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=ee();e&&(e.scrollTop=e.scrollHeight)}};if(typeof C==`function`)return C(e),()=>{C(null)};let t=C;return t.current=e,()=>{t.current=null}},[W,de.length,he,Me,fe,ue,Ne,C]),he?(0,$.jsx)(WN,{historyEntries:de,tailEntries:le,timelineCacheKey:dN(T,O),directory:f,sessionId:w,scrollRef:d,registerList:_e,onHistoryContentChange:xe,onTailContentChange:Ce,getAnimationHandlers:R,scrollToBottom:z,stickyUserHeader:E,sessionIsWorking:r,activityRenderMode:O,turnUiStates:j,onToggleTurnGroup:B,chatRenderMode:D,showTurnChangedFiles:k,shouldAnimateUserMessage:Ae,onUserAnimationConsumed:je,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:A,header:p,footer:m,scrollClassName:h,scrollStyle:g,scrollDataset:_,onScroll:v,followEnabled:y,historyAnchorToken:b,onIsAtEndChange:x,anchoredUserMessageId:ke,onAnchoredTurnParkReleased:L},T):(0,$.jsx)(`div`,{children:(0,$.jsx)(yc,{disabled:!1,children:(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(yc,{disabled:fe,children:(0,$.jsx)(sj,{enabled:!0,children:(0,$.jsx)(VN,{entries:de,engine:me,contentRef:H,scrollRef:d,registerTanstackVirtualizer:ye,virtualizerKey:T,onMessageContentChange:xe,getAnimationHandlers:R,scrollToBottom:z,stickyUserHeader:E,activityRenderMode:O,turnUiStates:j,onToggleTurnGroup:B,chatRenderMode:D,shouldAnimateUserMessage:Ae,onUserAnimationConsumed:je,reviewTransferDirection:A},T)})}),(0,$.jsx)(UN,{entries:le,directory:f,sessionId:w,onMessageContentChange:Ce,getAnimationHandlers:R,scrollToBottom:z,stickyUserHeader:E,sessionIsWorking:r,activityRenderMode:O,turnUiStates:j,onToggleTurnGroup:B,chatRenderMode:D,showTurnChangedFiles:k,shouldAnimateUserMessage:Ae,onUserAnimationConsumed:je,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:A})]})})})});GN.displayName=`MessageList`;var KN=Z.memo(GN);function qN(e){return e.info.id}function JN(e){return e!==null}function YN(e){return e.isMobile}var XN=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},ZN=({diff:e,filePath:t})=>{let{currentTheme:n}=Ua(),r=Z.useMemo(()=>Co(n),[n]),i=Z.useMemo(()=>Ac(e),[e]),a=sc(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6580
|
+
`),[i]),s=Bc(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)(XN,{content:e.content,html:n})})]},t)})})]},n))})},QN=e=>{let t=(0,Q.c)(21),{content:n,filePath:r}=e,{currentTheme:i}=Ua(),a;t[0]===i?a=t[1]:(a=Co(i),t[0]=i,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=n.split(`
|
|
6581
|
+
`),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=sc(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=Bc(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)(XN,{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},$N=new Set([`id`,`identifier`,`title`,`name`]),eP=e=>typeof e==`object`&&!!e&&!Array.isArray(e),tP=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),nP=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},rP=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},iP=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?`${tP(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)(iP,{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(eP(n)){let e;t[18]===n?e=t[19]:(e=nP(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(oP),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${tP(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)(iP,{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?tP(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`&&rP(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:tP(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});iP.displayName=`JsonSummaryValue`;var aP=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)(iP,{value:n,depth:0})}),t[0]=n,t[1]=r),r});aP.displayName=`JsonSummaryView`;function oP(e){let[t]=e;return!$N.has(t)}var sP={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`},cP={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},lP=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},dP=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,fP=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)(aP,{data:n})}),t[0]=n,t[1]=r),r},pP=({permission:e,onResponse:t})=>{let{t:n}=ot(),[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=nr,c=Nr(),l=Zr(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])=>[dP(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:[lP(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)(jc,{language:`bash`,code:e,style:sP,codeStyle:cP.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)(da,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(ZN,{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)(da,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(QN,{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)(da,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(fP,{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)(da,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(fP,{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)(da,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(fP,{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)(ca,{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)(ca,{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)(ca,{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 mP(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 hP(e){let t={questions:(e.questions??[]).map(e=>({header:e.header??null,question:e.question,multiple:!!e.multiple,options:e.options.map(e=>({label:e.label,description:e.description??null}))}))};return JSON.stringify(t,null,2)}function gP({scrollHeight:e,currentHeight:t}){let n=Math.min(Math.max(e,40),200);return t===n?null:n}var _P=`summary`,vP=Z.memo(function(e){let t=(0,Q.c)(31),{value:n,placeholder:r,disabled:i,onValueChange:a,onKeyDown:o}=e,s=Z.useRef(null),[c,l]=Z.useState(n),[u,d]=Z.useState(40),[f,p]=Z.useState(!1),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current;if(!e||document.activeElement!==e)return;let t=e.closest(`.chat-scroll`);if(!t){e.scrollIntoView({block:`nearest`});return}let n=window.visualViewport,r=t.getBoundingClientRect(),i=n?.offsetTop??0,a=n?n.offsetTop+n.height:document.documentElement.clientHeight,o=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--oc-kb-scroll-inset`))||0,c=Math.max(r.top,i),l=Math.min(r.bottom,a-o),u=Math.max(0,l-c),d=e.closest(`[data-question-card]`),f=d?.getBoundingClientRect(),p=(d&&f&&f.height<=u?d:e).getBoundingClientRect();p.bottom>l-12?t.scrollTop+=p.bottom-l+12:p.top<c+12&&(t.scrollTop+=p.top-c-12)},t[0]=m):m=t[0];let h=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]!==u||t[10]!==f?(S=()=>{let e=s.current;if(!e)return;let t=gP({scrollHeight:e.scrollHeight,currentHeight:u}),n=e.scrollHeight>(t??u);f!==n&&p(n),t!==null&&d(t)},t[9]=u,t[10]=f,t[11]=S):S=t[11];let C;t[12]!==u||t[13]!==f||t[14]!==c?(C=[u,f,c],t[12]=u,t[13]=f,t[14]=c,t[15]=C):C=t[15],Z.useLayoutEffect(S,C);let w;t[16]===a?w=t[17]:(w=e=>{let t=e.target.value;l(t),a(t)},t[16]=a,t[17]=w);let T;t[18]===u?T=t[19]:(T={height:u},t[18]=u,t[19]=T);let E=f?`overflow-y-auto`:`overflow-hidden`,D;t[20]===E?D=t[21]:(D=Y(`w-full bg-transparent border border-border/30 focus:border-primary rounded px-2 py-1 outline-none typography-meta text-foreground placeholder:text-muted-foreground/50 transition-colors resize-none`,E),t[20]=E,t[21]=D);let O;return t[22]!==i||t[23]!==_||t[24]!==c||t[25]!==o||t[26]!==r||t[27]!==T||t[28]!==D||t[29]!==w?(O=(0,$.jsx)(`textarea`,{ref:s,value:c,onChange:w,placeholder:r,disabled:i,rows:2,onKeyDown:o,onFocus:_,style:T,className:D,autoFocus:!0}),t[22]=i,t[23]=_,t[24]=c,t[25]=o,t[26]=r,t[27]=T,t[28]=D,t[29]=w,t[30]=O):O=t[30],O}),yP=({question:e})=>{let{t}=ot(),n=Zn,r=xi,i=s(e=>e.isMobile),a=Nr(),o=Zr(e=>e.currentSessionId),c=Z.useMemo(()=>{if(!o||e.sessionID===o)return!1;let t=a.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===o)},[e.sessionID,o,a]),[l,u]=Z.useState(`0`),[d,f]=Z.useState(!1),[p,m]=Z.useState(!1),[h,g]=Z.useState({}),[_,v]=Z.useState({}),y=Z.useRef({}),[b,x]=Z.useState({}),S=Z.useMemo(()=>e.questions??[],[e.questions]),C=l===_P,w=C?-1:Math.max(0,Math.min(S.length-1,Number(l)||0)),T=C?null:S[w],E=Z.useMemo(()=>{if(C)return null;let e=T?.header?.trim();return e&&e.length>0?e:null},[T?.header,C]);Z.useEffect(()=>{u(`0`),g({}),v({}),y.current={},x({}),m(!1)},[e.id]);let D=Z.useMemo(()=>{let e=S.map((e,t)=>({value:String(t),label:e.header?.trim()||`Q${t+1}`}));return S.length>1&&e.push({value:_P,label:t(`chat.questionCard.summaryTab`)}),e},[S,t]),O=Z.useCallback(e=>{if(_[e])return(y.current[e]??``).trim()||t(`chat.questionCard.noAnswer`);let n=h[e]??[];return n.length>0?n.join(`, `):t(`chat.questionCard.noAnswer`)},[_,h,t]),k=!!T?.multiple,A=h[w]??[],j=!!_[w],M=Z.useMemo(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){b[t]||e.push(t);continue}(h[t]??[]).length===0&&e.push(t)}return e},[_,b,S.length,h]),N=Z.useMemo(()=>S.length!==0&&M.length===0,[S.length,M.length]),P=Z.useCallback(()=>{if(S.length===0||M.length===0)return;let e=C?-1:w;for(let t=1;t<=S.length;t+=1){let n=(e+t+S.length)%S.length;if(M.includes(n)){u(String(n));return}}u(String(M[0]))},[w,C,S.length,M]),F=Z.useCallback(()=>{let e=[];for(let t=0;t<S.length;t+=1){if(_[t]){let n=(y.current[t]??``).trim();e.push(n?[n]:[]);continue}e.push(h[t]??[])}return e},[_,S.length,h]),I=Z.useCallback(e=>{T&&(v(e=>({...e,[w]:!1})),x(e=>e[w]?{...e,[w]:!1}:e),g(t=>{let n=t[w]??[];if(k){let r=n.includes(e)?n.filter(t=>t!==e):[...n,e];return{...t,[w]:r}}return{...t,[w]:[e]}}))},[w,T,k]),L=Z.useCallback(()=>{v(e=>({...e,[w]:!0})),g(e=>({...e,[w]:[]}));let e=(y.current[w]??``).trim().length>0;x(t=>t[w]===e?t:{...t,[w]:e})},[w]),R=Z.useCallback(e=>{y.current[w]=e;let t=e.trim().length>0;x(e=>e[w]===t?e:{...e,[w]:t})},[w]),z=Z.useCallback(async()=>{if(N){f(!0);try{let t=F();await n(e.sessionID,e.id,t),m(!0)}catch(e){tn(e)?(Tt.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Tt.error(t(`chat.questionCard.submitFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}}},[F,e.id,e.sessionID,N,n,t]),B=Z.useCallback(e=>{Mg(e)||e.key===`Enter`&&!e.shiftKey&&(!i||e.ctrlKey||e.metaKey)&&(e.preventDefault(),N?z():P())},[z,P,i,N]),V=Z.useCallback(async()=>{f(!0);try{await r(e.sessionID,e.id),m(!0)}catch(e){tn(e)?(Tt.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Tt.error(t(`chat.questionCard.dismissFailed`),{description:t(`chat.questionCard.tryAgain`)})}finally{f(!1)}},[e.id,e.sessionID,r,t]),H=Z.useCallback(async()=>{let n=mP(e);if((await ct(n)).ok){Tt.success(t(`chat.questionCard.copiedMarkdown`));return}Tt.error(t(`chat.questionCard.copyFailed`))},[e,t]),U=Z.useCallback(async()=>{let n=hP(e);if((await ct(n)).ok){Tt.success(t(`chat.questionCard.copiedJson`));return}Tt.error(t(`chat.questionCard.copyFailed`))},[e,t]);return p||S.length===0?null:(0,$.jsx)(`div`,{className:`group w-full pt-0 pb-2`,children:(0,$.jsx)(`div`,{className:`chat-column`,children:(0,$.jsxs)(`div`,{"data-question-card":!0,className:`-mt-1 border border-border/30 rounded-xl bg-muted/10`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1.5 border-b border-border/20`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:t(`chat.questionCard.inputNeeded`)}),c?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:t(`chat.questionCard.fromSubagent`)}):null,E?(0,$.jsx)(`span`,{className:`ml-auto typography-micro font-medium text-foreground/70 px-1.5 py-0.5 rounded bg-muted/30 border border-border/20`,children:E}):null,(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-0.5`,E?null:`ml-auto`),children:[(0,$.jsx)(`button`,{type:`button`,onClick:H,title:t(`chat.questionCard.copyMarkdown`),"aria-label":t(`chat.questionCard.copyMarkdown`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`file-text`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:U,title:t(`chat.questionCard.copyJson`),"aria-label":t(`chat.questionCard.copyJson`),className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:text-foreground hover:bg-interactive-hover/30 transition-colors`,children:(0,$.jsx)(X,{name:`code-box`,className:`h-3 w-3`})})]})]})}),(0,$.jsxs)(`div`,{className:`px-2 py-2`,children:[D.length>1?(0,$.jsx)(`div`,{className:`flex items-center gap-1 mb-2 flex-wrap`,children:D.map(e=>{let t=l===e.value,n=e.value===_P,r=n?-1:Number(e.value),i=!n&&Number.isFinite(r)&&!M.includes(r);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(e.value),className:Y(`px-2 py-0.5 typography-meta font-medium rounded transition-colors flex items-center gap-1`,t?`bg-interactive-selection/40 text-foreground`:n?`text-muted-foreground hover:text-foreground hover:bg-interactive-hover/20`:i?`text-muted-foreground/60 hover:text-muted-foreground hover:bg-interactive-hover/20`:`text-foreground/85 hover:text-foreground hover:bg-interactive-hover/20`),children:[n?(0,$.jsx)(X,{name:`list-check-3`,className:`h-3 w-3`}):null,e.label]},e.value)})}):null,C?(0,$.jsx)(`div`,{className:`space-y-2`,children:S.map((e,n)=>{let r=O(n),i=r!==t(`chat.questionCard.noAnswer`);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(String(n)),className:`w-full text-left rounded px-1.5 py-1 hover:bg-interactive-hover/20 transition-colors`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:e.header||t(`chat.questionCard.questionFallback`,{index:n+1})}),(0,$.jsx)(`div`,{className:Y(`typography-meta`,i?`text-foreground`:`text-muted-foreground/50 italic`),children:r})]},n)})}):T?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground mb-1.5`,children:T.question}),k?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-1.5`,children:t(`chat.questionCard.selectMultiple`)}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[T.options.map((e,n)=>{let r=A.includes(e.label),i=/\(recommended\)/i.test(e.label);return(0,$.jsx)(`button`,{type:`button`,onClick:()=>I(e.label),disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,r?`bg-interactive-selection/20`:null,d?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:k?(0,$.jsx)(ha,{checked:r,onChange:()=>I(e.label),disabled:d}):(0,$.jsx)(so,{checked:r,onChange:()=>I(e.label),disabled:d})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:Y(`typography-meta break-all`,r?`text-foreground font-medium`:`text-foreground/80`),children:e.label}),i?(0,$.jsx)(`span`,{className:`typography-micro text-primary/80`,children:t(`chat.questionCard.recommended`)}):null]}),e.description?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground break-words`,children:e.description}):null]})]})},`${n}:${e.label}`)}),(0,$.jsx)(`button`,{type:`button`,onClick:L,disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,j?`bg-interactive-selection/20`:null,d?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`edit`,className:Y(`h-3.5 w-3.5`,j?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,j?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),j?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)(vP,{value:y.current[w]??``,onValueChange:R,placeholder:t(`chat.questionCard.yourAnswer`),disabled:d,onKeyDown:B})}):null]})]}):null]}),(0,$.jsxs)(`div`,{className:`px-2 pb-1.5 pt-1 flex items-center gap-1.5 border-t border-border/20`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:N?z:P,disabled:d,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-success)/0.1)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[N?(0,$.jsx)(X,{name:`check`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`}),t(N?`chat.questionCard.submit`:`chat.questionCard.next`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:V,disabled:d,className:Y(`flex items-center gap-1 px-2 py-1 typography-meta font-medium rounded transition-colors`,`bg-[rgb(var(--status-error)/0.1)] text-[var(--status-error)] hover:bg-[rgb(var(--status-error)/0.2)]`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`}),t(`chat.questionCard.dismiss`)]}),d?(0,$.jsx)(`div`,{className:`ml-auto`,children:(0,$.jsx)(`div`,{className:`animate-spin h-3 w-3 border border-primary border-t-transparent rounded-full`})}):null]})]})})})};function bP(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|
|
6583
|
+
`)}function xP(e,t=80){let n=bP(e).replace(/\n/g,` `);return n.length>t?`${n.slice(0,t)}…`:n}var SP=160,CP=28,wP=12,TP=6,EP=30,DP=12,OP=18,kP=80,AP=4,jP=10,MP=14,NP=20,PP=54,FP=4,IP=8,LP=2,RP=160,zP=(e,t)=>e.map(e=>({turnId:e,preview:xP(t.get(e)??[],SP)})),BP=[1,.6,.35,.15],VP=(e,t,n)=>{let r=n?MP:jP;if(t===null)return r;let i=BP[Math.abs(e-t)]??0;return Math.round(r+(NP-r)*i)};function HP({turnIds:e,previewsByTurnId:t,activeTurnId:n,onSelectTurn:r,canLoadEarlier:i,isLoadingOlder:a,onLoadEarlier:o}){let{t:c}=ot(),l=s(e=>e.isPromptNavigatorPanelOpen),u=s(e=>e.setPromptNavigatorPanelOpen),d=Z.useRef(null),f=Z.useRef(null),[p,m]=Z.useState(null),[h,g]=Z.useState(0),[_,v]=Z.useState(!1);Z.useEffect(()=>{let e=f.current?.parentElement;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelector(`.chat-message-column`);if(!t){v(!1);return}let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.right-TP-CP;v(r.right>i)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let y=Z.useMemo(()=>zP(e,t),[t,e]),b=Math.min(y.length,EP),x=Math.max(0,y.length-b),S=Math.min(h,x),C=S+b,w=S>0,T=C<y.length,E=c(`chat.timeline.noTextContent`),D=c(`chat.promptNavigator.currentPrompt`),O=c(`chat.promptNavigator.loadMore`),k=Z.useMemo(()=>n?y.findIndex(e=>e.turnId===n):-1,[n,y]),A=Z.useRef(S);A.current=S;let j=Z.useRef(y.length);j.current=y.length;let M=Z.useRef(null),N=Z.useRef(null),P=Z.useRef(0),F=Z.useCallback(e=>{g(t=>{let n=j.current,r=Math.min(n,EP),i=Math.max(0,n-r),a=Math.min(t,i);return e<a?e:e>=a+r?Math.min(i,e-r+1):a})},[]),I=Z.useRef(y[0]?.turnId),L=Z.useRef(y.length);Z.useLayoutEffect(()=>{let e=I.current,t=L.current,n=y.length-t;n>0&&t>0&&e&&y[0]?.turnId!==e&&(g(e=>e+n),m(e=>e===null?null:e+n)),I.current=y[0]?.turnId,L.current=y.length},[y]),Z.useEffect(()=>{if(p!==null)return;let e=k>=0?k:y.length-1;g(()=>{let t=j.current,n=Math.min(t,EP),r=Math.max(0,t-n);return Math.max(0,Math.min(r,e-Math.floor(n/2)))})},[k,p,y.length]);let R=Z.useCallback(e=>{let t=d.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.floor((e-n.top)/DP),i=Math.min(j.current,EP);return i===0?null:Math.max(0,Math.min(i-1,r))},[]),z=Z.useCallback(()=>{P.current=0,N.current!==null&&(window.clearInterval(N.current),N.current=null)},[]),B=Z.useCallback(()=>{let e=P.current;if(e===0){z();return}let t=j.current,n=Math.max(0,t-Math.min(t,EP)),r=Math.min(A.current,n),i=Math.max(0,Math.min(n,r+e));if(i===r){z();return}A.current=i,g(i);let a=M.current;if(a!==null){let e=R(a);e!==null&&m(Math.min(t-1,i+e))}},[R,z]),V=Z.useCallback(e=>{let t=d.current;if(!t)return;let n=t.getBoundingClientRect(),r=e-n.top,i=0;if(r<=OP&&w?i=-1:r>=n.height-OP&&T&&(i=1),P.current=i,i===0){z();return}N.current===null&&(N.current=window.setInterval(B,kP))},[B,w,T,z]);Z.useEffect(()=>()=>{N.current!==null&&window.clearInterval(N.current)},[]);let H=Z.useRef(null),U=Z.useCallback(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),W=Z.useCallback(()=>{U(),H.current=window.setTimeout(()=>{H.current=null,m(null)},RP)},[U]);Z.useEffect(()=>()=>{H.current!==null&&window.clearTimeout(H.current)},[]);let ee=Z.useCallback(e=>{U(),M.current=e.clientY;let t=R(e.clientY);t!==null&&m(Math.min(j.current-1,A.current+t)),V(e.clientY)},[U,R,V]),G=Z.useCallback(()=>{M.current=null,z(),W()},[W,z]),K=Z.useCallback(()=>{u(!1)},[u]),q=Z.useCallback(e=>{if(e===null)return;let t=y[e];t&&(r(t.turnId),z(),m(null),K(),d.current?.blur())},[K,r,y,z]),te=Z.useCallback(e=>{let t=R(e.clientY);t!==null&&q(Math.min(y.length-1,A.current+t))},[q,y.length,R]);Z.useEffect(()=>{if(!l)return;let e=d.current;!e||e===document.activeElement||(e.focus(),m(e=>{if(e!==null)return e;let t=k>=0?k:y.length-1;return F(t),t}))},[k,F,l,y.length]),Z.useEffect(()=>()=>{u(!1)},[u]);let ne=Z.useCallback(e=>{if(y.length===0)return;let t=p??(k>=0?k:y.length-1),n=e=>{let t=Math.max(0,Math.min(y.length-1,e));F(t),m(t)};if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),n(t+(e.key===`ArrowUp`?-1:1));return}if(e.key===`Home`){e.preventDefault(),n(0);return}if(e.key===`End`){e.preventDefault(),n(y.length-1);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),q(t);return}e.key===`Escape`&&(e.preventDefault(),m(null),K(),d.current?.blur())},[k,K,F,q,p,y.length]),re=Z.useCallback(()=>{z(),m(null),K()},[K,z]),ie=Z.useRef(null),ae=Z.useRef(p);ae.current=p;let oe=p!==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/PP);if(t===0)return;se.current-=t*PP;let n=ae.current;if(n===null)return;let r=Math.max(0,Math.min(j.current-1,n+t));r!==n&&(F(r),m(r))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[F,oe]);let ce=p===null?void 0:y[p],le=Math.min(y.length,IP),ue=le*PP,de=y.length*PP-ue,fe=e=>Math.max(0,Math.min(de,e)),pe=Z.useRef(null),me=0;if(p===null)pe.current=null;else if(pe.current===null)me=fe(p*PP-(ue-PP)/2),pe.current=me;else{let e=pe.current,t=(p-LP)*PP,n=(p+1+LP)*PP-ue;e>t?e=t:e<n&&(e=n),me=fe(e),pe.current=me}let he=Math.floor(me/PP),ge=Math.max(0,he-AP),_e=Math.min(y.length,he+le+AP),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,S-AP),Se=Math.min(y.length,C+AP),Ce=y.slice(xe,Se),we=w||T?`linear-gradient(to bottom, ${w?`transparent, black 14%`:`black`}, ${T?`black 86%, transparent`:`black`})`:void 0;return y.length===0?null:(0,$.jsx)(`nav`,{ref:f,"aria-label":c(`chat.promptNavigator.aria`),className:`pointer-events-none absolute right-1.5 top-1/2 z-20 -translate-y-1/2`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto flex flex-col items-end`,children:[i?(0,$.jsx)(`button`,{type:`button`,tabIndex:-1,className:Y(`-mr-px mb-1.5 flex size-5 shrink-0 items-center justify-center rounded-full`,`text-[var(--surface-mutedForeground)] transition-colors`,`hover:bg-[var(--interactive-hover)]/60 hover:text-[var(--surface-foreground)]`,a?`cursor-wait opacity-70`:void 0),"aria-label":O,title:O,disabled:a,onClick:e=>{e.stopPropagation(),a||o()},children:a?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-3.5`})}):null,(0,$.jsxs)(`div`,{ref:d,role:`listbox`,tabIndex:-1,"aria-activedescendant":ce?`prompt-rail-tick-${ce.turnId}`:void 0,className:`relative cursor-pointer outline-none`,style:{width:`${_?wP:CP}px`,height:`${b*DP}px`},onMouseMove:ee,onMouseLeave:G,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(-${S*DP}px)`},children:Ce.map((e,t)=>{let r=xe+t,i=e.turnId===n,a=p===r,o=VP(r,p,i);return(0,$.jsx)(`div`,{id:`prompt-rail-tick-${e.turnId}`,role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,"aria-label":e.preview.trim()||E,className:`pointer-events-none absolute right-1 flex items-center justify-end`,style:{top:`${r*DP}px`,height:`${DP}px`},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(`block h-0.5 rounded-full transition-all duration-200 ease-out`,i?`bg-[var(--surface-foreground)]`:a?`bg-[var(--surface-foreground)]/80`:`bg-[var(--surface-foreground)]/30`),style:{width:`${o}px`}})},e.turnId)})},y[0]?.turnId)}),ce&&p!==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:U,onMouseLeave:W,onMouseMove:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,$.jsx)(`div`,{className:`relative overflow-hidden`,style:{height:`${le*PP}px`,maskImage:be,WebkitMaskImage:be},children:(0,$.jsx)(`div`,{className:`absolute inset-x-0 top-0 transition-transform duration-200 ease-out`,style:{height:`${y.length*PP}px`,transform:`translateY(-${me}px)`},children:y.slice(ge,_e).map((e,t)=>{let r=ge+t,i=e.turnId===n,a=p===r;return(0,$.jsx)(`div`,{role:`option`,"aria-selected":a,"aria-current":i?`true`:void 0,title:i?D:void 0,className:`absolute inset-x-0 cursor-pointer px-1.5`,style:{top:`${r*PP+FP}px`,height:`46px`},onMouseMove:()=>{U(),ae.current!==r&&(F(r),m(r))},onClick:()=>q(r),children:(0,$.jsx)(`div`,{className:Y(`flex h-full items-center rounded-lg border px-2 transition-colors`,i?`border-transparent bg-[var(--interactive-selection)]`:a?`border-[var(--interactive-border)]/60 bg-[var(--interactive-hover)]`:`border-[var(--interactive-border)]/40`),children:(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 line-clamp-2 [overflow-wrap:anywhere] typography-meta`,i?`text-[var(--interactive-selectionForeground)]`:`text-[var(--surface-mutedForeground)]`),children:e.preview.trim()||E})})},e.turnId)})})})}):null]})]})})}var UP=100,WP=(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},GP=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=WP(p,t.scrollTop+UP);!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}},KP=10,qP=`${KP}vh`,JP=`80px`,YP=`calc(${JP} + var(--oc-chat-foot-inset))`,XP=(e,t)=>e?80:t<=0?96:Math.max(48,KP/100*t),ZP=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return!1;switch(e.key){case`ArrowUp`:case`PageUp`:case`Home`:return!0;default:return!1}},QP=(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},$P=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&&(QP(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)||QP(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=>{ZP(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:eF,C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C={passive:!0},t[14]=C):C=t[14];let w=C;it(`wheel`,u,S,w),it(`touchstart`,f,S,w),it(`touchmove`,m,S,w),it(`touchend`,g,S,w),it(`touchcancel`,g,S,w),it(`keydown`,v,S)};function eF(){}var tF=(e,t)=>({sessionId:e,viewportKey:t}),nF=(e,t)=>e?.sessionId===t?.sessionId&&e?.viewportKey===t?.viewportKey,rF=(e,t)=>nF(e,t),iF=(e,t,n)=>({identity:e,anchor:t,scrollPosition:n}),aF=150,oF=1500,sF=2,cF=350,lF=600,uF=8e3,dF=24,fF=2,pF=(e,t)=>e<t,mF=()=>typeof performance<`u`?performance.now():Date.now(),hF=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),gF=e=>e.scrollHeight-e.scrollTop-e.clientHeight,_F=e=>gF(hF(e)),vF=e=>e.scrollHeight-e.clientHeight>1,yF=(e,t)=>gF(e)<=XP(t,e.clientHeight),bF=({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(tF(t,n));C.current=tF(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=mF()+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:mF()},E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{T.current=null,E.current=null},oF)}),q=J(e=>{let t=T.current;return t?mF()-t.time>oF?(T.current=null,!1):Math.abs(e.scrollTop-t.top)<sF:!1}),te=J(()=>mF()<A.current),ne=J(()=>{L.current=!1,R.current&&=(clearTimeout(R.current),null),z.current&&=(clearTimeout(z.current),null)}),re=J(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,ne()},lF)}),ie=J(()=>{let e=c.current;e&&(L.current=!0,B.current=e.scrollHeight,re(),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{z.current=null,ne()},uF))}),ae=J(e=>{let t=c.current;if(!t){h(!1),_(!1);return}let n=e??hF(t),r=vF(n);if(h(r),!r){_(!1);return}let i=b.current===`released`&&!yF(n,x.current);_(i)}),oe=J(()=>{D.current+=1,O.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(O.current),O.current=null),k.current?.(),k.current=null});Z.useEffect(()=>()=>oe(),[l]);let se=J(()=>{if(!e)return;let t=c.current;if(!t)return;oe();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(),ae(),typeof window>`u`)return;let o=0,s=()=>{pF(mF(),P.current)||oe()};t.addEventListener(`touchstart`,s,{passive:!0,once:!0}),k.current=()=>t.removeEventListener(`touchstart`,s);let l=()=>{if(n===D.current){if(_F(t)>fF&&a(),o+=1,o>=dF){O.current=null,k.current?.(),k.current=null,ae();return}O.current=window.requestAnimationFrame(l)}};O.current=window.requestAnimationFrame(l)}),ce=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}}),le=J((t,n=`auto`)=>{if(!e)return;let r=c.current;if(t&&b.current!==`following`&&G(`following`),r&&!(!t&&b.current!==`following`)){if(_F(r)<sF){K(r);return}ce(t?n:`auto`)}}),ue=J(e=>{let t=c.current;if(!t)return;let n=e??hF(t);if(!vF(n)){G(`following`);return}b.current!==`released`&&(G(`released`),ae(n))}),de=J((e=`instant`)=>{if(V.current=!1,G(`following`),ne(),e===`instant`){se();return}oe(),le(!0,`smooth`),ae()}),fe=J(()=>{V.current=!1,le(!0)}),pe=J(()=>{oe(),ne(),G(`released`),ae()}),me=J(()=>{V.current=!0,pe()}),he=J(()=>{V.current=!1}),ge=Z.useRef(s);ge.current=s;let _e=J(()=>{pF(mF(),P.current)||(oe(),ne(),ue())}),ve=J(()=>{_e(),ge.current?.()}),ye=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}}),be=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=iF(e,o,{scrollTop:n,scrollHeight:r,clientHeight:i}),H.current===null&&(H.current=setTimeout(()=>{H.current=null,ye()},aF))}),xe=J(()=>{ye()}),Se=J(async(e=C.current)=>{if(!e.sessionId)return!1;V.current=!1;let t=Ui(e.sessionId,e.viewportKey);return c.current?(W.current=null,I.current=t?.scrollPosition?.scrollTop??0,G(`following`),F(),x.current?se():le(!0),ie(),ae(),!1):(W.current=e,G(`following`),!1)});Z.useEffect(()=>{let e=C.current,n=w.current;nF(e,n)||(ye(),oe(),F(),w.current=e,T.current=null,I.current=0,ne(),V.current=!1,G(`following`),W.current=null,t&&t!==n?.sessionId&&Vx.getInstance().recordSessionStart(t))},[t,n]),Z.useEffect(()=>{i&&!V.current&&b.current===`following`&&le(!0)},[i]),Z.useEffect(()=>{y(f===`following`&&i)},[f,i]),Z.useLayoutEffect(()=>{if(!l)return;let e=W.current;e&&rF(e,C.current)&&Se(e)},[l,t,n]);let Ce=J(()=>{let e=c.current;if(!e)return;let t=hF(e),n=I.current;I.current=t.scrollTop;let r=t.scrollTop>n+.5,i=Math.abs(t.scrollTop-n)<.5;if(ae(t),V.current){be();return}if(!vF(t)){G(`following`);return}if(yF(t,x.current)){let e=gF(t)<=sF;(r||b.current===`following`||e)&&G(`following`),be();return}if(b.current===`following`&&(q(e)||te()||i)){j.current||le(!1),be();return}ue(t),be()});Z.useEffect(()=>{!e||!l||(I.current=l.scrollTop)},[l,e]);let we=Z.useRef(null),Te=J(e=>{let t=c.current;t&&(e.deltaY>=0||QP(t,e.target)||ve())}),Ee=J(e=>{let t=e.touches.item(0);we.current=t?t.clientY:null}),De=J(e=>{let t=c.current,n=e.touches.item(0);if(!n){we.current=null;return}let r=we.current;we.current=n.clientY,r!==null&&(n.clientY-r<=2||t&&(QP(t,e.target)||ve()))}),Oe=J(()=>{we.current=null}),ke=J(e=>{ZP(e)&&ve()}),Ae=J(e=>{let t=e.target;t instanceof Element&&t.closest(`[data-overlay-scrollbar-thumb]`)&&_e()}),je=Z.useMemo(()=>()=>void 0,[]),Me=e&&l?l:je,Ne=Z.useMemo(()=>({passive:!0}),[]);it(`scroll`,Ce,Me,Ne),it(`wheel`,Te,Me,Ne),it(`touchstart`,Ee,Me,Ne),it(`touchmove`,De,Me,Ne),it(`touchend`,Oe,Me,Ne),it(`touchcancel`,Oe,Me,Ne),it(`keydown`,ke,Me),it(`pointerdown`,Ae,e&&typeof window<`u`?window:je,!0);let Pe=J(()=>{let e=c.current;if(j.current){ae(e?hF(e):void 0);return}if(V.current){ae(e?hF(e):void 0);return}if(!e){ae(void 0);return}let t=hF(e);if(!vF(t)){G(`following`),ae(t);return}if(ae(t),L.current){let n=t.scrollHeight>B.current+1;B.current=t.scrollHeight,gF(t)<=sF?K(e):le(!0),n&&re();return}if(b.current===`following`){if(gF(t)<=sF){K(e);return}le(!1)}}),Fe=typeof ResizeObserver<`u`,Ie=Fe&&e?l:null,Le=Fe&&e&&l&&l.firstElementChild instanceof Element?l.firstElementChild:null;at(Ie,Pe),at(Le,Pe);let Re=J(()=>{N.current!==null&&(clearTimeout(N.current),N.current=null)}),ze=J(e=>{j.current=!0,typeof e==`number`&&e>0?A.current=mF()+e+cF:A.current=Math.max(A.current,mF()+cF)}),Be=J(e=>{let t=e.detail;if(t){if(t.open===!0){ze(),Re(),N.current=setTimeout(()=>{N.current=null,M.current||(j.current=!1)},1500);return}Re(),ze()}}),Ve=J(e=>{let t=e.detail;t&&(Re(),ze(t.durationMs))}),He=J(e=>{let t=e.detail;Re(),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)},cF)),ae()}),Ue=e&&typeof window<`u`?window:je;it(`oc:keyboard-intent`,Be,Ue),it(`oc:keyboard-anim`,Ve,Ue),it(`oc:keyboard-settled`,He,Ue),Z.useEffect(()=>{if(!(!e||typeof window>`u`))return()=>{Re(),j.current=!1,M.current=!1}},[e]),Z.useEffect(()=>{e&&ae()},[e,r]);let We=J(t=>{if(e){if(t===`animation`&&(A.current=mF()+cF),ae(),L.current){le(!0),re();return}b.current===`following`&&le(!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`&&le(!1)},i={onChunk:r,onComplete:()=>{e&&ae()},onStreamingCandidate:()=>{},onAnimationStart:()=>{},onAnimatedHeightChange:r,onReservationCancelled:()=>{},onReasoningBlock:()=>{}};return Ge.current.set(t,i),i});Z.useEffect(()=>()=>{E.current&&=(clearTimeout(E.current),null),oe(),ne(),ye(),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=GP({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:de,scrollToBottomOnSend:fe,releaseAutoFollow:pe,beginHistoryViewportPreservation:me,endHistoryViewportPreservation:he,saveSnapshotNow:xe,restoreSnapshot:Se}},xF=`--oc-mobile-composer-swap`,SF=`--oc-native-composer-dock`,CF=()=>({phase:`rest`,rest:`expanded`,progress:0,pinned:!1}),wF=(e,t,n)=>Math.min(n,Math.max(t,e)),TF=(e,t)=>e.phase===t.phase&&e.rest===t.rest&&e.progress===t.progress&&e.pinned===t.pinned,EF=(e,t)=>{let n={phase:t.phase,rest:t.rest,progress:t.progress,pinned:t.pinned??e.pinned};return TF(e,n)?e:n},DF=(e,t)=>t?EF(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0}):e.pinned?EF(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!1}):e,OF=(e,t)=>{if(e.pinned&&t===`compact`)return e;let n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:EF(e,{phase:`snapping`,rest:t,progress:n})},kF=e=>wF(e/80,0,1),AF=e=>e>=80?1:wF(e/80,0,1),jF=(e,t,n={})=>{if(e.pinned)return e;let r=Math.max(0,t),i=e.phase===`snapping`?EF(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e;if(i.rest===`expanded`){if(r<=2||n.holdExpanded||n.userDriven===!1)return EF(i,{phase:`rest`,rest:`expanded`,progress:0});let e=kF(r);return e>=1?EF(i,{phase:`rest`,rest:`compact`,progress:1}):EF(i,{phase:`tracking`,rest:`expanded`,progress:e})}if(r<=2)return EF(i,{phase:`rest`,rest:`expanded`,progress:0});if(n.suppressReturn)return EF(i,{phase:`rest`,rest:`compact`,progress:1});if(n.towardBottom&&r>=80)return EF(i,{phase:`snapping`,rest:`expanded`,progress:0});let a=AF(r);return a>=1?EF(i,{phase:`rest`,rest:`compact`,progress:1}):EF(i,{phase:`tracking`,rest:`compact`,progress:a})},MF=e=>e.pinned?`expanded`:e.rest===`expanded`?e.progress>=.5?`compact`:`expanded`:e.progress<=.5?`expanded`:`compact`,NF=e=>{if(e.pinned)return EF(e,{phase:`rest`,rest:`expanded`,progress:0,pinned:!0});if(e.phase===`snapping`)return e;let t=MF(e),n=+(t===`compact`);return e.phase===`rest`&&e.rest===t&&e.progress===n?e:EF(e,{phase:`snapping`,rest:t,progress:n})},PF=e=>e.phase===`snapping`?EF(e,{phase:`rest`,rest:e.rest,progress:+(e.rest===`compact`)}):e,FF=e=>wF(Math.max(0,e)/80,0,1),IF=(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:FF(n),rest:`bottom`}},LF=e=>{e.style.removeProperty(xF),e.style.removeProperty(SF),delete e.dataset.ocComposerSwapPhase,delete e.dataset.ocComposerSwapRest,delete e.dataset.ocNativeComposerDock},RF=(e,t,n)=>{let r=IF(t,n?.rest===`bottom`?`bottom`:`away`),i=String(r.progress),a=r.rest;return n?.progress!==i&&e.style.setProperty(SF,i),n?.rest!==a&&(e.dataset.ocNativeComposerDock=a),{progress:i,rest:a}},zF=(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(xF,r),n?.rest!==a&&(e.dataset.ocComposerSwapRest=a),{progress:r,phase:i,rest:a}},BF=e=>({scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,clientHeight:e.clientHeight}),VF=()=>{let e=document.documentElement;return e.classList.contains(`oc-keyboard-open`)||e.classList.contains(`oc-kb-animating`)},HF=e=>{if(VF()||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)},UF=e=>{let t=Z.useRef(CF()),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=zF(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=PF(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||_(DF(t.current,HF(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=NF(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=HF(a),s=BF(n),g=Rj(s,Ij(n)),y=u.current;if(u.current=g,n.hasAttribute(`data-oc-timeline-anchoring`)){d.current=0,f.current=0;return}r.current=RF(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=DF(t.current,o);if(!o){let e=w.rest===`compact`;w=jF(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,_(OF(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&&LF(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,_(CF())});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}),[]);it(`scroll`,w,I,z),it(`scrollend`,T,I,z),it(`touchstart`,C,I,z),it(`touchmove`,S,I,z),it(`touchend`,E,I,z),it(`touchcancel`,E,I,z),it(`pointerdown`,O,L),it(`focusin`,y,L),it(`focusout`,y,L),it(`oc:keyboard-intent`,y,R),it(`oc:keyboard-anim`,y,R),it(`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])},WF=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},GF=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},KF=e=>{if(!e)return null;let t=WF(e);return`${typeof e.info?.id==`string`?e.info.id:``}::${t}::${GF(e)??``}`},qF=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}),JF=(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&&KF(t[r])===KF(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=WF(r),a=r.info.id,o=qF(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=GF(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},YF=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=WF(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=GF(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}},XF=200,ZF={MAX_SESSIONS:3,ZOMBIE_TIMEOUT:6e5},QF=()=>XF,$F=()=>Math.round(QF()*.6),eI={MAX_SESSIONS:ZF.MAX_SESSIONS,VIEWPORT_MESSAGES:Math.round(XF*.6),HISTORICAL_MESSAGES:XF,FETCH_BUFFER:20,HISTORY_CHUNK:XF,STREAMING_BUFFER:1/0,ZOMBIE_TIMEOUT:ZF.ZOMBIE_TIMEOUT},tI=()=>{let e=QF(),t=$F();return{...eI,HISTORICAL_MESSAGES:e,VIEWPORT_MESSAGES:t,HISTORY_CHUNK:e}},nI=eI,rI=600,iI=6e3,aI=.5,oI=(e,t)=>e.querySelector(`[data-message-id="${CSS.escape(t)}"]`),sI=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},cI=(e,t)=>{let n=oI(e,t);if(n||=sI(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}},lI=e=>{let{container:t,quiesceMs:n=rI,maxLifetimeMs:r=iI}=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=cI(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)>aI){h();return}let e=oI(t,i.messageId);if(!e){let n=sI(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)>aI&&(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}},uI=30,dI=1200,fI=1.5,pI=e=>Math.max(dI,e*fI),mI=4,hI=30,gI=4,_I=30,vI=250,yI=2e3,bI=wn+2e3,xI=40,SI=`history-loading-timeout`,CI=e=>!!(e&&typeof e==`object`&&e.code===`history-loading-timeout`),wI=()=>{let e=Error(`chat history pagination wait timed out`);return e.code=SI,e},TI=(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)},EI=2500,DI=new Map,OI=()=>d()?mI:bt()?gI:uI,kI=e=>d()?e.length<=hI:!bt()||e.length<=_I,AI=(e,t)=>{if(DI.delete(e),!kI(t.messages))return;let n=OI();for(;DI.size>=n;){let e=DI.keys().next().value;if(typeof e!=`string`)break;DI.delete(e)}DI.set(e,t)},jI=e=>!!(e.previousOldestId&&e.currentOldestId&&e.currentOldestId!==e.previousOldestId&&e.previousNewestId&&e.currentNewestId&&e.currentNewestId===e.previousNewestId),MI=e=>e?{owner:`tanstack-core`}:{owner:`controller`},NI=(e,t)=>e?e.canLoadEarlier:t>=tI().HISTORICAL_MESSAGES,PI=e=>!(e.isMobile||e.isLoadingOlder||e.pendingRevealWork||!e.canLoadEarlier||e.source===`scroll`&&e.isPinned||e.scrollTop>=pI(e.clientHeight)),FI=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`,II=1,LI=8,RI=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),zI=e=>[`chat-timeline-auto-fill`,e.runtimeKey,e.sessionId,e.oldestMessageId,e.messageCount,e.canLoadEarlier],BI=e=>[`chat-timeline-load-earlier`,e.runtimeKey,e.sessionId],VI=20,HI=4,UI=80,WI=new WeakMap,GI=new WeakMap,KI=e=>{let t=GI.get(e)??{generation:0};return t.generation+=1,GI.set(e,t),t.generation},qI=e=>{let t=WI.get(e);t&&(t.touches=0,t.pending=null,t.settleScheduled=!1),KI(e)},JI=e=>{YI(e)},YI=e=>{let t=WI.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&&XI(e,n)};return e.addEventListener(`touchend`,r,{passive:!0}),e.addEventListener(`touchcancel`,r,{passive:!0}),WI.set(e,n),n},XI=(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+UI||ZI(e,n.anchorTop+n.delta))}))},ZI=(e,t)=>{let n=KI(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((GI.get(e)?.generation??0)!==n){e.removeEventListener(`touchstart`,o);return}e.scrollTop<t-HI&&(e.scrollTop=t),a+=1,a<VI?window.requestAnimationFrame(s):e.removeEventListener(`touchstart`,o)}};window.requestAnimationFrame(s)},QI=(e,t,n)=>{let r=YI(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,ZI(e,t)},$I=(e,t,n)=>!e||!t||t===e?!1:n.some(t=>t.info.id===e),eL=(e,t)=>e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight?e:t,tL=({sessionId:e,directory:t=null,messages:n,historyMeta:r,scrollRef:a,messageListRef:o,loadMoreMessages:s,goToBottom:c,releaseAutoFollow:l,beginHistoryViewportPreservation:u,endHistoryViewportPreservation:d,isPinned:f,showScrollButton:p,autoFillEnabled:m=!1,onWillLoadEarlier:h})=>{let g=Z.useRef(null),_=Z.useRef(null),v=Z.useMemo(()=>{let t=e??``,r=t?DI.get(t):void 0;if(r&&r.messages===n)return AI(t,r),g.current=r.model,_.current=n,r.model;let i=JF(g.current,_.current,n)??YF(n);return g.current=i,_.current=n,t&&n.length>0&&AI(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&&NI(r,n.length);return{hasBufferedTurns:!1,hasMoreAboveTurns:e,historyLoading:!!r?.loading,canLoadEarlier:e}},[r,n.length]),q=Z.useRef(K);j.current=v,M.current=f,P.current=x,q.current=K,F.current=e,I.current=t??null,L.current=n,R.current=r,z.current=D;let te=J(()=>{U.current=!0,W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null)}),ne=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},yI)}),re=J(()=>{let e=B.current;e.length!==0&&(B.current=[],e.forEach(e=>e()))}),ie=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,vI)})),ae=J(e=>{let t=V.current;t&&(V.current=null,t.resolve(e))}),oe=J(()=>{let e=V.current;if(e){if(e.sessionId!==F.current){ae(!1);return}if(e.kind===`turn`?o.current?.scrollToTurnId(e.id,{behavior:e.behavior})??!1:o.current?.scrollToMessageId(e.id,{behavior:e.behavior})??!1){e.turnId&&(H.current={turnId:e.turnId,expiresAt:Date.now()+EI},w(e.turnId)),ae(!0);return}typeof(e.kind===`turn`?j.current.turnIndexById.get(e.id):j.current.messageToTurnIndex.get(e.id))==`number`&&ae(!1)}}),se=Z.useRef(null),ce=J(()=>{let e=se.current;e&&(se.current=null,e.dispose())});et(()=>{W.current!==null&&typeof window<`u`&&(window.clearTimeout(W.current),W.current=null),ce(),re(),ae(!1)});let le=n;rt(()=>{re(),oe()},[le]);let ue=J(()=>{let e=a.current;if(!e){A(e=>eL(e,{scrollHeight:0,clientHeight:0}));return}A(t=>eL(t,{scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))});at(typeof ResizeObserver<`u`?a:null,ue),rt(()=>{ue()},[e,y]);let de=Z.useRef(null),fe=J(()=>o.current?.captureViewportAnchor()??null),pe=J(e=>o.current?.restoreViewportAnchor(e)??!1),me=J(()=>{if(bt())return;ce();let e=a.current;if(!e)return;let t=fe();t&&(se.current=lI({container:e,anchor:t}))}),he=Z.useRef(null);rt(()=>{if(!bt())return;let e=a.current;e&&(JI(e),qI(e))},[e,a]),rt(()=>{ce(),de.current=null,he.current=null,o.current?.cancelViewportAnchorHold()},[e]),rt(()=>{let e=a.current;if(!e)return;let t=de.current;t&&Math.abs(e.scrollTop-t.top)>LI&&(de.current=null,t=null);let n=he.current,r=le[0]?.info?.id??null,i=le[le.length-1]?.info?.id??null,s=n?jI({previousOldestId:n.oldestId,previousNewestId:n.newestId,currentOldestId:r,currentNewestId:i})||$I(n.oldestId,r,le):!1;t&&t.sessionId!==F.current&&(de.current=null,t=null);let l=t?jI({previousOldestId:t.oldestId,previousNewestId:t.newestId,currentOldestId:r,currentNewestId:i})||$I(t.oldestId,r,le):!1,u=s||l,d=e=>{he.current={oldestId:r,newestId:i,scrollHeight:e??he.current?.scrollHeight??0}};if(M.current&&!t){ce(),u?(de.current=null,c(`instant`),d(e.scrollHeight)):d();return}let f=MI(o.current?.isHistoryVirtualized()??!1);if(t){if(f.owner===`tanstack-core`){o.current?.cancelViewportAnchorHold();let e=t.anchor;e&&pe(e),d();return}let n=e.scrollHeight,r=n-t.height;if(bt()){r>0&&QI(e,t.top+r,r),d(n);return}let i=t.anchor;!(i&&pe(i))&&r>0&&(e.scrollTop=t.top+r),d(n);return}if(s&&n&&f.owner===`controller`){let t=e.scrollHeight,r=t-n.scrollHeight;if(r>0){let t=e.scrollTop+r;bt()?QI(e,t,r):e.scrollTop=t}d(t),me();return}d()},[le,c]);let ge=J(async()=>!1),_e=J(async e=>{let t=Date.now(),n=t+bI,r=I.current,i=r?zi()?.getRequestState?.(un(r,e)):void 0;for(q.current.historyLoading,R.current,i?.status,i?.error;q.current.historyLoading;){if(F.current!==e)return Date.now()-t,`switched`;if(Date.now()>=n){let n=r?zi()?.getRequestState?.(un(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:bI,hostTurnPageTimeoutMs:wn,historyLoading:q.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,xI)})}return Date.now()-t,r&&zi()?.getRequestState?.(un(r,e))?.status,F.current===e?`cleared`:`switched`}),ve=J(async e=>{if(!F.current||N.current||!q.current.hasMoreAboveTurns)return!1;N.current=!0,te(),b(!0);let t=F.current,n=null,r=!!e.userInitiated;r&&u();let i=()=>{n&&de.current===n&&(de.current=null,o.current?.cancelViewportAnchorHold()),r&&(r=!1,d())};try{if(q.current.historyLoading){if(!e.userInitiated)return!1;let n=await _e(t);if(n===`timeout`)throw wI();if(n===`switched`||!q.current.hasMoreAboveTurns)return!1}if(!F.current||F.current!==t)return!1;let r=a.current,o=L.current,c=o.length,l=o[0]?.info?.id??null,u=R.current?.limit??tI().HISTORICAL_MESSAGES;e.preserveViewport&&r&&(n={sessionId:F.current,height:r.scrollHeight,top:r.scrollTop,anchor:fe(),oldestId:l,newestId:o[o.length-1]?.info?.id??null},de.current=n,me());let d=c,f=l,p=u,m=0;for(;;){if(q.current.historyLoading)if(e.userInitiated){let e=await _e(t);if(e===`timeout`)throw i(),wI();if(e===`switched`)return i(),!1}else return i(),!1;let n=a.current?.scrollHeight??0,r=d,o=f,c=p;if(await s(t,`up`),m+=1,F.current!==t)return i(),!1;await ie();let l=L.current,u=l.length,h=l[0]?.info?.id??null,g=R.current?.limit??p,_=FI({scrollHeightBefore:n,scrollHeightAfter:a.current?.scrollHeight??n,messageCountBefore:r,messageCountAfter:u,oldestIdBefore:o,oldestIdAfter:h,limitBefore:c,limitAfter:g,hasMoreAbove:q.current.hasMoreAboveTurns,pagesLoaded:m,maxPages:II});if(_===`continue`){d=u,f=h,p=g;continue}if(_===`stop-no-growth`){if(q.current.historyLoading){if(e.userInitiated){let e=await _e(t);if(e===`timeout`)throw i(),wI();if(e===`switched`)return i(),!1;--m;continue}return i(),!1}let n=R.current?.limit??c;return z.current=n,O(n),q.current={...q.current,hasMoreAboveTurns:!1,canLoadEarlier:!1},i(),!1}return!0}}catch(e){throw i(),e}finally{N.current=!1,b(!1),ne(),ie().then(i)}}),{t:ye}=ot(),be=Ke({mutationKey:BI({runtimeKey:i(),sessionId:e??``}),mutationFn:async e=>{if(F.current!==e.sessionId)return!1;te(),e.userInitiated&&l();try{return await ve({preserveViewport:!0,userInitiated:!!e.userInitiated})}finally{ne()}}}),xe=J(async e=>{let t=F.current;if(t&&!(be.isPending&&be.variables?.sessionId===t)){e?.userInitiated&&h?.();try{let n=await be.mutateAsync({sessionId:t,userInitiated:!!e?.userInitiated});if(n===!1&&q.current.canLoadEarlier){let r={sessionId:t,grew:n,userInitiated:!!e?.userInitiated,canLoadEarlier:q.current.canLoadEarlier,hasMoreAboveTurns:q.current.hasMoreAboveTurns,historyLoading:q.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};TI(`no-growth`,Error(`chat history pagination returned no growth`),r),e?.userInitiated&&Tt.error(ye(`chat.history.loadOlderFailed`))}}catch(n){let r={sessionId:t,userInitiated:!!e?.userInitiated,waitMs:bI,hostTurnPageTimeoutMs:wn,canLoadEarlier:q.current.canLoadEarlier,historyLoading:q.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};CI(n)?TI(`timeout`,n,r):TI(`failed`,n,r),e?.userInitiated&&Tt.error(CI(n)?ye(`chat.history.loadOlderTimeout`):ye(`chat.history.loadOlderFailed`))}}}),Se=be.isPending&&be.variables?.sessionId===e||y,Ce=n[0]?.info?.id??null,we=RI({enabled:m,isMobile:bt(),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:zI({runtimeKey:i(),sessionId:e??``,oldestMessageId:Ce,messageCount:n.length,canLoadEarlier:K.canLoadEarlier}),enabled:!!e&&we,staleTime:1/0,gcTime:0,retry:(e,t)=>t?.code===`auto-fill-busy`&&e<40,retryDelay:50,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,queryFn:async()=>{let e=F.current;if(!e)return{status:`skip`};if(q.current.historyLoading||N.current){let e=Error(`auto-fill-busy`);throw e.code=`auto-fill-busy`,e}if(!q.current.canLoadEarlier)return{status:`skip`};let t=a.current;if(!t||t.clientHeight<=0)return{status:`skip`};if(t.scrollHeight>t.clientHeight+48)return{status:`tall`};try{let t=await ve({preserveViewport:!0});return t?{status:`grew`}:(q.current.canLoadEarlier&&TI(`no-growth`,Error(`chat history pagination returned no growth`),{sessionId:e,source:`auto-fill`,grew:t,canLoadEarlier:q.current.canLoadEarlier,hasMoreAboveTurns:q.current.hasMoreAboveTurns,historyLoading:q.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:bI,canLoadEarlier:q.current.canLoadEarlier,historyLoading:q.current.historyLoading,historyMeta:R.current,messageCount:L.current.length,oldestMessageId:L.current[0]?.info?.id??null};throw CI(t)?TI(`timeout`,t,n):TI(`failed`,t,n),E(!0),t instanceof Error?t:Error(`chat timeline auto-fill failed`)}}});let Te=J(e=>{let t=a.current;t&&PI({source:e,isMobile:bt(),isPinned:M.current,scrollTop:t.scrollTop,clientHeight:t.clientHeight,canLoadEarlier:q.current.canLoadEarlier,isLoadingOlder:N.current,pendingRevealWork:P.current})&&xe({userInitiated:!0})}),Ee=J(()=>{Te(`scroll`)}),De=J(()=>{Te(`upward-intent`)}),Oe=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},oe()})}finally{S(!1)}}),ke=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},oe()})}finally{S(!1)}}),Ae=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`smooth`)}),je=J(async()=>{S(!1),N.current=!1,b(!1),o.current?.scrollToBottom(),c(`instant`)}),Me=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:le,historySignals:K,isLoadingOlder:Se,pendingRevealWork:x,activeTurnId:C,showScrollToBottom:p&&!x,turnWindowModel:v,loadEarlier:xe,revealBufferedTurns:ge,resumeToBottom:Ae,resumeToBottomInstant:je,scrollToTurn:Oe,scrollToMessage:ke,handleHistoryScroll:Ee,handleHistoryUpwardIntent:De,captureViewportAnchor:fe,restoreViewportAnchor:pe,handleActiveTurnChange:Me}},nL=({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}=ot(),f=Ph(),p=n,m=pr(p??``,r),h=Zr(e=>e.revertToMessage),g=Zr(e=>e.forkFromMessage),_=nL(f.capabilities),{isMobile:v,isTablet:y}=fo(),b=v||y,[x,S]=Z.useState(null),C=Z.useRef(!1),[w,T]=Z.useState(``),[E,D]=Z.useState(0),O=Z.useRef([]),k=Z.useRef(null),A=Z.useRef(null),j=Z.useRef(!1),M=Z.useRef(e),N=e=>new Date(e).toLocaleDateString(st(),{year:`numeric`,month:`short`,day:`numeric`}),P=e=>new Date(e).toLocaleTimeString(st(),{hour:`numeric`,minute:`2-digit`}),F=Z.useMemo(()=>m.filter(e=>e.info.role===`user`).map(e=>({message:e})),[m]),I=Z.useMemo(()=>{let e=w.trim();if(!e)return F;let t=e.toLowerCase();return F.filter(({message:e})=>bP(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)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(Qi,{children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`time`,className:`h-5 w-5`}),d(`chat.timeline.title`)]}),(0,$.jsx)(ra,{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)(za,{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)(ca,{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=xP(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()?iL(bP(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)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{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)(Va,{sideOffset:6,children:d(`chat.timeline.actions.revertFromHere`)})]}):null,_.fork?(0,$.jsxs)(Ha,{children:[(0,$.jsx)(Ba,{asChild:!0,children:(0,$.jsx)(ca,{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)(Va,{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 iL(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 aL=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},oL=(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`}},sL=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)},cL=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&&sL(`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&&sL(`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=oL(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 sL(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=()=>{sL(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=aL(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},lL=2e4,uL=6e4,dL=2e3,fL=e=>e?(typeof e.text==`string`?e.text.length:0)+(typeof e.state?.output==`string`?e.state.output.length:0):0,pL=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+=fL(e);return[e.length,t.info.id,n.length,r?.id??``,r?.state?.status??``,i].join(`:`)},mL={sessionKey:null,fingerprint:null,lastMovementAt:null,lastRefreshAt:null,attempts:0},hL=(e,t)=>{let{sessionKey:n,working:r,streaming:i,fingerprint:a,now:o}=t;if(!n)return{state:mL,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}},gL=e=>{console.warn(`[transcript] tail frozen while session is working — refetching authority`,e)},_L=(e,t)=>{let n=(0,Q.c)(7),r=Wx(vL),i=Zr(yL),a=Zr(bL),o,s;n[0]!==a||n[1]!==i||n[2]!==t||n[3]!==r||n[4]!==e?(o=()=>{if(r&&e&&!a(e)){for(let n of t)if(n.info.role===`assistant`)for(let t of n.parts){let n=t;if(n.type!==`text`)continue;let r=n.text||``;if(r.includes(`The plan at `)||r.includes(`User has requested to enter plan mode`)){i(e);return}}}},s=[r,e,t,i,a],n[0]=a,n[1]=i,n[2]=t,n[3]=r,n[4]=e,n[5]=o,n[6]=s):(o=n[5],s=n[6]),Z.useEffect(o,s)};function vL(e){return e.planModeEnabled}function yL(e){return e.markSessionPlanAvailable}function bL(e){return e.isSessionPlanAvailable}function xL(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 SL(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 CL(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||xL(i)==null}function wL(e){let t=[];for(let n of e){let e=Array.isArray(n.parts)?n.parts:[];for(let n of e){if(!CL(n))continue;let e=SL(n);e&&t.push(e)}}return t}function TL(e,t){return`${e}:${t.join(`,`)}`}function EL(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=TL(t,e.unansweredToolIds);return e.attemptedKey===r?{recover:!1,attemptKey:r}:{recover:!0,attemptKey:r}}function DL(e,t,n,r){let i=(0,Q.c)(7),a=Bn(),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=EL({sessionId:e,directory:t,sessionQuestionCount:r,unansweredToolIds:wL(n),attemptedKey:o.current});if(!c.recover||!e||!t||!c.attemptKey)return;let l=a.getChild(t);l&&(o.current=c.attemptKey,cn(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 OL=e=>!Number.isFinite(e)||e<0?0:Math.ceil(e),kL=(e,t)=>({...e,key:AL(e),estimatedBytes:OL(t)}),AL=({runtimeKey:e,sessionId:t,directory:n})=>JSON.stringify([e,n??``,t]),jL=e=>({key:e?AL(e):null,selection:e}),ML=(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},NL=(e,t,n,r)=>{let i=AL(t),a=e.findIndex(e=>e.key===i),o=a>=0?e[a]:void 0;if(o&&a===e.length-1)return ML(e,i,n);let s=o||kL(t,r),c=a>=0?e.filter((e,t)=>t!==a):[...e];return c.push(s),ML(c,i,n)},PL=(e,t,n)=>{let r=OL(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)},FL=(e,t)=>t&&e.some(e=>e.key===t)?t:null,IL=(e,t,n)=>{let r=t.key?e.cachedSessionViews.find(e=>e.key===t.key):void 0,i=r&&t.selection?NL(e.cachedSessionViews,t.selection,n,r.estimatedBytes):ML(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}},LL=(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:kL(t.selection,r),intent:t};return e.pendingSessionView?.intent===t?e:{activeIntent:e.activeIntent,cacheNeedsTrim:e.cacheNeedsTrim,cachedSessionViews:e.cachedSessionViews,pendingSessionView:i}},RL=(e,t,n)=>{let r=e.pendingSessionView;return e.activeIntent!==t||r?.intent!==t||!t.selection?e:{activeIntent:e.activeIntent,cacheNeedsTrim:!1,cachedSessionViews:NL(e.cachedSessionViews,t.selection,n,r.entry.estimatedBytes),pendingSessionView:null}},zL=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},BL=e=>{if(!(!e.info||typeof e.info!=`object`))return e.info},VL=e=>BL(e)?.role===`assistant`,HL=(e,t)=>{let n=BL(t);n&&(e.agentName??=zL(n.agent),e.providerId??=zL(n.providerID),e.modelId??=zL(n.modelID))},UL=e=>!!(e.agentName&&e.providerId&&e.modelId),WL=e=>{let t={};for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||!VL(r))&&(HL(t,r),UL(t)))return t}for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(!r||VL(r))&&(HL(t,r),UL(t)))break}return t},GL=e=>!!e.sessionId&&!(e.hasRenderableSessionSnapshot&&e.hasCurrentSessionEntity),KL=[],qL=[],JL={type:`idle`},YL=`openchamber:chat-force-scroll-bottom`,XL=()=>void 0,ZL=`Quota limit reached. Retrying automatically.`,QL=1048576,$L=QL,eR=20,tR=QL,nR=16*QL,rR={maxEntries:3,maxEstimatedBytes:32*QL},iR={maxEntries:2,maxEstimatedBytes:32*QL},aR=e=>t(()=>e()),oR={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},sR={scrollbar:`chat`,scrollShadow:`true`,orientation:`vertical`},cR=()=>{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},lR=`calc(max(0.625rem, var(--oc-safe-area-top, 0px)) + var(--oc-mobile-detail-navigation-height) + 1.25rem)`,uR=YP,dR=[`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(`,`),fR=e=>e instanceof HTMLElement,pR=e=>fR(e)?!!e.closest(dR):!1,mR=(e,t)=>typeof document>`u`||!e||e===document.body||e===document.documentElement||pR(e)?!0:!t?.contains(e),hR=()=>{let{isAboutDialogOpen:e,isCommandPaletteOpen:t,isHelpDialogOpen:n,isImagePreviewOpen:r,isMultiRunLauncherOpen:i,isSessionSwitcherOpen:a,isSettingsDialogOpen:o}=s.getState();return e||t||n||r||i||a||o},gR=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}=ot(),I=Wx(e=>e.legendTimelineEnabled),L=Ox({isLoadingOlder:u}),R=kx({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(vM(n)){let r=bM(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(Qt(n.parts))continue;let r=B.current.get(n.parts);r||(r=qr(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||pR(e.target)||typeof window<`u`&&window.getSelection()?.type===`Range`||o.current?.focus({preventScroll:!0})});return $P({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)(KN,{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:oR,timelineScrollDataset:sR,timelineOnScroll:_,timelineFollowEnabled:!c&&!b,timelineHistoryAnchorToken:x,timelineOnIsAtEndChange:y,headerSlot:(0,$.jsxs)($.Fragment,{children:[r&&(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:lR},"aria-hidden":`true`}),E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(ca,{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)(yP,{question:e},e.id)),w.map(e=>(0,$.jsx)(pP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?uR:qP},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(HP,{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)(Oa,{className:Y(`absolute inset-0 overflow-y-auto overflow-x-hidden z-0 chat-scroll overlay-scrollbar-target`),ref:o,style:oR,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)(ca,{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)(KN,{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)(yP,{question:e},e.id)),w.map(e=>(0,$.jsx)(pP,{permission:e},e.id))]}),(0,$.jsx)(`div`,{className:`mb-1`,children:(0,$.jsx)(Vk,{})}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:r?JP:qP},"aria-hidden":`true`})]})}),(0,$.jsx)(po,{containerRef:o,suppressVisibility:T,userIntentOnly:!0,observeMutations:!1}),j&&U.length>=2?(0,$.jsx)(HP,{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);gR.displayName=`ChatViewport`;var _R=[{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%]`]}],vR=e=>oa(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)]})},bR=e=>{let t=Math.ceil(Math.max(0,e)/eR);return Math.min(nR,$L+t*tR)},xR=Z.memo(({autoOpenDraft:e=!0,readOnly:t=!1,active:n=!0,sessionId:r,sessionDirectory:i,sessionViewKey:a,onSessionViewEstimateChange:o,composerSurface:c,hostedFeatures:l,assistantHistory:u,onRevertMessage:f,warning:p=null,pendingUserMessages:m=qL,onPendingUserMessagesMaterialized:h})=>{let g=l??Nx(void 0),{t:_}=ot();rt(()=>{ti()},[]);let v=Zr(e=>e.openNewSessionDraft),y=Zr(e=>e.setCurrentSession),b=Zr(e=>e.newSessionDraft),x=Zr(e=>e.newSessionDraft.draftSubmitting??!1),S=Zr(e=>e.newSessionDraft.draftEstablishing??!1),C=Zr(e=>e.forkTransition),w=xn(e=>e.projects),T=xn(e=>e.activeProjectId),E=Qr(e=>e.providers),D=Eu(),O=cr(),k=i??O;rt(()=>{!n||!r||!k||jn(k,r)},[n,r,k]);let A=J(e=>D.ensureSessionRenderable(e,{directory:k})),j=s(e=>e.isExpandedInput),M=s(e=>e.stickyUserHeader),N=s(e=>e.promptNavigatorEnabled),P=s(e=>e.allowPromptingSubagentSessions),F=s(e=>e.isTimelineDialogOpen),I=s(e=>e.setTimelineDialogOpen),L=Ft(e=>n&&r?e.streamingMessageIds.get(r)??null:null),R=Ft(e=>L?e.messageStreamStates.get(L)?.phase??null:null),z=wi(r??``,k),B=bR(z);Z.useEffect(()=>{!a||!o||o(a,B)},[o,B,a]);let V=oi(r??``,k).renderable,H=pt(r,k),U=qn(r),W=H??U,ee=Ig({sessionId:r,hasSessionEntity:!!W,hasRenderableSessionSnapshot:V,composerSurfaceKind:c?.kind}),G=r?JSON.stringify([k,r]):null,[K,q]=Z.useState({key:G,attempt:0}),te=pr(r??``,k,{suspendPartUpdates:!!L,suspendPartUpdatesForMessageId:L}),ne=r?te:KL,re=b.pendingUserMessage,ie=Zr(e=>r?e.retainedPendingUserMessages.get(r):void 0)??qL,ae=Zr(e=>e.clearRetainedPendingUserMessages),oe=Z.useMemo(()=>{if(ie.length===0)return m;if(m.length===0)return ie;let e=new Set(m.map(e=>e.info.id));return[...m,...ie.filter(t=>!e.has(t.info.id))]},[m,ie]),se=Z.useMemo(()=>WL(ne),[ne]),ce=Z.useMemo(()=>{if(!se.modelId)return _(`common.unavailable`);let e=E.find(e=>e.id===se.providerId);return Ai(e,se.modelId)||se.modelId},[E,se.modelId,se.providerId,_]),le=Br(r??``,k),ue=ri(r??``,k),[de,fe]=Z.useState(null),pe=!!r&&de===r,me=J(()=>{if(!r||pe)return;let e=r,t=k;fe(e);let n=Fi(()=>{let n=zi();if(!n)throw Error(`unbound`);return n.getTranscript(un(t,e))});Fr(_r({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 ht(t,e),await D.ensureSessionRenderable(e,{directory:t});try{let r=Fi(()=>{let n=zi();if(!n)throw Error(`unbound`);return n.getTranscript(un(t,e))});n&&r&&Mr({trigger:`user-refresh`,sessionID:e,directory:t,purpose:`retry`,before:n,after:r})}catch{}}catch(n){Fr(_r({kind:`request-error`,sessionID:e,directory:t,purpose:`retry`,source:`network`,hydration:ue,error:n}))}finally{fe(t=>t===e?null:t)}})()}),he=Ir(r??``,k).boundary,ge=J(async e=>{if(he.kind===`has-more`){await Nn(k,e);return}if(he.kind===`unknown`){await Wi(k,e);return}u&&!u.complete&&await u.fetchPrevious()});_L(r??``,ne);let _e=wr(r??``,k),ve=Ar(r??``,k),ye=hi(k),be=_e??JL,xe=or(r,k),Se=On(r,k);DL(r,k,ne,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`||wx(oe,{resolvedSessionStatus:_e,sessionStatusObservedAt:ve}))return!0;let t=ne[ne.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,oe,_e,ne,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():``)||ZL,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&&D.isLoading(r,{directory:k})),Ae=Z.useMemo(()=>{if(!r)return null;let e=Tx({boundary:he,assistantComplete:u?.complete??!0});return{limit:he.loadedTurns,complete:e.complete,canLoadEarlier:e.canLoadEarlier,loading:Ex({syncLoading:ke,assistantLoading:!!u?.loading})}},[u?.complete,u?.loading,r,he,ke]),je=s(e=>e.isMobile),Me=$h()!==null,Ne=d(),Pe=xg(),Fe=!!b?.open,Ie=At(e=>e.error),Le=j,Re=Me||je||Ne||Pe===`mini-chat`,ze=Z.useRef(null),Be=Z.useMemo(()=>{let e=b?.selectedProjectId?w.find(e=>e.id===b.selectedProjectId)??null:null,t=T?w.find(e=>e.id===T)??null:null,n=e??t??w[0]??null;return n?vR(n):null},[T,b?.selectedProjectId,w]),Ve=Qn(r,k),He=a??r??``,[Ue,We]=Z.useState(null),Ge=Vg(Ue,He,Ve,se);rt(()=>{We(e=>Vg(e,He,Ve,se))},[Ve,se,He]);let Ke=Ve??Ge?.parentTarget??null,qe=Ge?.execution??se,Je=ul(),Ye=Je!==null&&r===Je,Xe=J(()=>{Ke&&y(Ke.id,Ke.directory)}),Ze=Ke?.session?.title,Qe=g.returnToParent&&Ke&&!Ye?(0,$.jsxs)(ca,{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":_(`chat.container.returnToParent.aria`),title:Ze?.trim()?_(`chat.container.returnToParent.titleNamed`,{title:Ze}):_(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),_(`chat.container.returnToParent.label`)]}):null,$e=Lg({readOnly:t,sessionIdentityPending:ee,isSubagentSession:!!W?.parentID||!!Ge,allowPromptingSubagentSessions:P}),tt=qe.modelId===se.modelId?ce:qe.modelId?Ai(E.find(e=>e.id===qe.providerId),qe.modelId)||qe.modelId:_(`common.unavailable`),st=Ke?(0,$.jsx)(Lx,{agentName:qe.agentName,providerId:qe.providerId,modelId:qe.modelId,modelName:tt}):(0,$.jsx)(Lx,{}),ct=J(e=>{s.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`&&ct({allowPromptingSubagentSessions:t.payload.allowPromptingSubagentSessions})}),ut=typeof window<`u`&&window.parent!==window;it(`message`,lt,ut?window:XL),nt(()=>{if(!ut)return;let e=window;e.__openchamberApplyChatSettingsSync=ct,window.parent.postMessage({type:`openchamber:chat-settings-request`},window.location.origin)}),et(()=>{if(typeof window>`u`)return;let e=window;e.__openchamberApplyChatSettingsSync===ct&&delete e.__openchamberApplyChatSettingsSync}),Z.useEffect(()=>{g.newSessionDraft&&e&&!r&&!Fe&&v()},[e,r,Fe,g.newSessionDraft,v]);let dt=Z.useRef(()=>{}),ft=J(e=>{dt.current(e)}),mt=Z.useRef(()=>{}),gt=J(()=>{mt.current()}),_t=Wx(e=>e.legendTimelineEnabled),[vt,yt]=Z.useState(!0),[bt,xt]=Z.useState(!1),[St,Ct]=Z.useState(!1),[wt,Tt]=Z.useState(0),Et=J(()=>{Tt(e=>e+1)}),Dt=J((e,t)=>{yt(e),e&&Ct(!1),t!==void 0&&xt(t)});Z.useEffect(()=>{yt(!0),xt(!1),Ct(!1)},[r]);let{scrollRef:Ot,notifyContentChange:jt,getAnimationHandlers:Mt,goToBottom:Nt,scrollToBottomOnSend:It,releaseAutoFollow:Lt,beginHistoryViewportPreservation:Rt,endHistoryViewportPreservation:zt,restoreSnapshot:Bt,isPinned:Vt,isFollowingProgrammatically:Ht,showScrollButton:Ut}=bF({enabled:n&&!_t,currentSessionId:r,viewportKey:a,sessionMessageCount:z,sessionIsWorking:Ce,isMobile:je,onActiveTurnChange:ft,onUpwardUserIntent:gt}),Wt=Z.useRef(null);UF({enabled:je,scrollRef:Ot,scopeRef:Wt});let Gt=Z.useRef([]),Kt=Z.useMemo(()=>{let e=Pt(u?.entries??[],r,Gt.current);return Gt.current=e,e},[u?.entries,r]),qt=Z.useRef([]),Jt=Z.useMemo(()=>{if(!u)return ne;let e=In(u.entries,r,ne,qt.current);return qt.current=e,e},[u,r,ne]),Yt=Z.useMemo(()=>Cx(Kt.length===0?Jt:r?[...Kt,Pn(r),...Jt]:Kt,oe),[r,Jt,Kt,oe]),Xt=Z.useRef(null),Zt=Z.useMemo(()=>Mx({sessionId:r,messages:Yt,retained:Xt.current}),[r,Yt]);Xt.current=Zt.retained;let Qt=Zt.messages,$t=Z.useRef(null),en=$t.current===r,tn=Z.useRef(mL),nn=r?`${k}\n${r}`:null,rn=J(()=>pL(Qt));Z.useEffect(()=>{if(!r||!nn||!Ce){tn.current={...tn.current,lastMovementAt:null};return}let e=r,t=k,n=setInterval(()=>{let n=rn(),r=hL(tn.current,{sessionKey:nn,working:!0,streaming:!!L,fingerprint:n,now:Date.now(),thresholdMs:lL,cooldownMs:uL,maxAttempts:3});tn.current=r.state,r.shouldRefresh&&(gL({sessionId:e,directory:t,stalledForMs:r.stalledForMs,attempt:r.state.attempts,fingerprint:n}),vn(t,e).catch(()=>{}))},dL);return()=>clearInterval(n)},[r,k,rn,Ce,L,nn]);let an=Z.useMemo(()=>{if(oe.length===0)return[];let e=new Set([...Kt,...Jt].filter(e=>kt(e.parts)).map(e=>e.info.id));return oe.map(e=>e.info.id).filter(t=>e.has(t))},[Jt,Kt,oe]);Z.useEffect(()=>{an.length!==0&&(h?.(an),r&&ae(r,an))},[ae,r,an,h]);let sn=tL({sessionId:r,directory:k,messages:Qt,historyMeta:Ae,scrollRef:Ot,messageListRef:ze,loadMoreMessages:ge,goToBottom:Nt,releaseAutoFollow:Lt,beginHistoryViewportPreservation:Rt,endHistoryViewportPreservation:zt,isPinned:_t?vt:Vt,showScrollButton:_t?bt:Ut,autoFillEnabled:n&&!Le,onWillLoadEarlier:Et}),cn=J(()=>{Ct(!1),ze.current?.scrollToBottom(),Nt(`instant`)}),ln=J(()=>{Ct(!1),It()}),dn=J(()=>{Ct(!0),sn.handleHistoryUpwardIntent()}),fn=Dx({isMobile:je,canLoadEarlier:sn.historySignals.canLoadEarlier,isLoadingOlder:sn.isLoadingOlder}),pn=sn.isLoadingOlder,mn=sn.loadEarlier,hn=J(()=>{Ct(!0),mn({userInitiated:!0})});dt.current=sn.handleActiveTurnChange,mt.current=sn.handleHistoryUpwardIntent,Z.useEffect(()=>{(xe.length!==0||Se.length!==0)&&jt(`permission`)},[jt,xe,Se]);let gn=cL({sessionId:r,turnIds:sn.turnIds,activeTurnId:sn.activeTurnId,scrollToTurn:sn.scrollToTurn,scrollToMessage:sn.scrollToMessage,resumeToBottom:cn}),_n=$e.showReadOnlyBanner?st:t?null:(0,$.jsx)(hx,{surface:c,scrollToBottom:ln,showScrollToBottom:je&&sn.showScrollToBottom,onScrollToBottom:gn.resumeToLatest,submissionBlocked:$e.blockSubmission}),yn=J(e=>{gn.scrollToTurnId(e,{behavior:`smooth`})}),bn=sn.historySignals.canLoadEarlier,Sn=g.promptNavigator&&!je&&!Ne&&!Le&&N&&sn.turnIds.length>=2;Z.useEffect(()=>{Sn||s.getState().setPromptNavigatorPanelOpen(!1)},[Sn]);let Cn=J(e=>{if(!n||!r)return;let t=e;t.detail?.sessionId&&t.detail.sessionId!==r||Nt(`instant`)});it(YL,Cn,n&&r&&typeof window<`u`?window:XL);let wn=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}=s.getState();if(t!==`chat`||hR())return;let i=Ot.current;if(mR(document.activeElement,i)||pR(e.target))return;e.preventDefault();let a=e.key===`ArrowUp`?-1:1;gn.scrollByTurnOffset(a,{resumePastEnd:!1})});it(`keydown`,wn,n&&r&&!Le&&typeof window<`u`?window:XL);let Tn=Z.useRef(0),En=J(()=>{let e=Ot.current;e&&e.style.setProperty(`--chat-scroll-height`,`${e.clientHeight}px`)}),Dn=J(()=>{Tn.current||=requestAnimationFrame(()=>{Tn.current=0,En()})});rt(()=>{n&&En()},[n,r,Le,En]);let kn=typeof ResizeObserver<`u`;at(n&&kn?Ot:null,Dn),it(`resize`,Dn,n&&!kn&&typeof window<`u`?window:XL),et(()=>{Tn.current&&=(cancelAnimationFrame(Tn.current),0)});let An=Z.useRef(null),Mn=Z.useRef(0),Fn=Ax({transcriptMessageCount:ne.length,pendingUserCount:oe.length,historyPrefixCount:Kt.length}),Ln=jx({hasTranscriptShell:Fn,p0Satisfied:ue.p0Satisfied,hasBusyShell:Ce&&Fn,hasImmediateShell:oe.length>0||Kt.length>0,hasRenderableSessionSnapshot:V,prefetchStatus:le?.status,syncLoading:!!(r&&D.isLoading(r,{directory:k})),userRetrying:pe,hasPaintedTranscript:en});Ln===`pass`&&Qt.length>0&&($t.current=r);let Rn=!!r&&Ln===`hydrating`,zn=!!r&&Ln===`load-error`;Z.useEffect(()=>{!zn||!r||Fr(_r({kind:`request-error`,sessionID:r,directory:k,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,k,zn,le,ue]),Z.useEffect(()=>{if(!n||!r||Rn)return;let e=Qt.length,t=An.current!==r,i=!t&&Mn.current===0&&e>0;if(!t&&!i){An.current===r&&(Mn.current=e);return}let a=typeof window<`u`&&window.location.hash.length>0;if(An.current=r,Mn.current=e,a){Lt();return}let o=()=>{Bt()};typeof window>`u`?o():window.requestAnimationFrame(o)},[n,r,Rn,Lt,Bt,Qt.length]),Z.useEffect(()=>{q(e=>e.key===G?e:{key:G,attempt:0})},[G]),Z.useEffect(()=>{if(!n||!r||K.key!==G||!GL({sessionId:r,hasRenderableSessionSnapshot:V,hasCurrentSessionEntity:!!W})||(A(r),W||K.attempt>=2))return;let e=K.attempt+1,t=window.setTimeout(()=>{q(t=>t.key===G&&t.attempt===K.attempt?{key:G,attempt:e}:t)},e*1e3);return()=>window.clearTimeout(t)},[n,W,r,k,A,V,G,K]);let Bn=C&&r&&(C.targetSessionId?r===C.targetSessionId:r===C.sourceSessionId)?C:null;if(Bn){let e=Bn.stage===`preparing`?`chat.forkTransition.preparing`:Bn.stage===`copying`?`chat.forkTransition.copying`:Bn.stage===`opening`?`chat.forkTransition.opening`:`chat.forkTransition.loading`,t=[`preparing`,`copying`,`opening`,`loading`],n=_(`chat.forkTransition.progress`,{current:Math.max(1,t.indexOf(Bn.stage)+1),total:t.length});return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,role:`status`,"aria-live":`polite`,"aria-label":`${_(e)}. ${n}`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(e)}),(0,$.jsx)(zp,{})]}),(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)(zx,{})}):!r&&Fe?(x||S)&&re?(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)(Oa,{className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll`,style:oR,children:[(0,$.jsx)(KN,{sessionKey:`draft:${b.draftID??`pending`}`,messages:[re],sessionIsWorking:!0,isLoadingOlder:!1,onMessageContentChange:jt,getAnimationHandlers:Mt,scrollToBottom:cn}),(0,$.jsxs)(`div`,{className:`chat-message-column px-4 pb-10 pt-2 typography-meta text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zp,{})]})]})})}):x||S?(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center bg-background px-6 text-center`,children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3`,role:`status`,"aria-live":`polite`,"aria-label":_(`chat.emptyState.establishingConversation`),children:(0,$.jsxs)(`span`,{className:`typography-ui-header text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`animate-text-shimmer`,children:_(`chat.emptyState.establishingConversation`)}),(0,$.jsx)(zp,{})]})})}):(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?_(`chat.emptyState.draftTitleWithProject`,{project:Be}):_(`chat.emptyState.draftTitle`),Be)}),(0,$.jsx)(N_,{onSubmit:e=>on.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:_n})]}):r?zn?(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:_(`chat.history.loadFailedTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:_(`chat.history.loadFailedDescription`)}),(0,$.jsxs)(ca,{type:`button`,className:`mt-5`,onClick:me,children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`,"aria-hidden":`true`}),_(`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:_n})]}):Rn?(0,$.jsxs)(`div`,{ref:Wt,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:Ot,className:`absolute inset-0 overflow-y-auto overflow-x-hidden bg-background pt-6 chat-scroll`,style:oR,children:(0,$.jsx)(`div`,{className:`space-y-4 chat-scroll-foot-inset`,children:_R.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)(ac,{className:`h-3.5 w-3.5 rounded-full flex-shrink-0`}),(0,$.jsx)(ac,{className:Y(`h-4 rounded-md`,t.titleWidth)}),(0,$.jsx)(ac,{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)(ac,{className:Y(`h-4 rounded-md`,e.textWidths[0])}),(0,$.jsx)(ac,{className:Y(`h-4 rounded-md`,e.textWidths[1])}),(0,$.jsx)(ac,{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)(cR,{}):null,_n]})]}):Qt.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)(zx,{})})}),(0,$.jsx)(`div`,{className:Y(`relative z-10`,je&&`oc-mobile-composer-foot`,Le?`flex-1 min-h-0 bg-background`:`bg-background`),children:_n}),(0,$.jsx)(Sx,{})]}):(0,$.jsxs)(`div`,{ref:Wt,className:Y(`relative flex flex-col h-full bg-background`,je&&`oc-chat-composer-swap-scope`),children:[p?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-[var(--status-warning-background)] px-4 py-2.5 typography-meta text-[var(--status-warning-foreground)]`,children:p}):null,Qe,(0,$.jsx)(gR,{currentSessionId:r,virtualizerKey:a??r,isDesktopExpandedInput:Le,isMobile:je,stickyUserHeader:M,directory:k,scrollRef:Ot,messageListRef:ze,pendingRevealWork:sn.pendingRevealWork,renderedMessages:sn.renderedMessages,isLoadingOlder:pn,sessionIsWorking:Ce,streamingMessageId:L,activeStreamingPhase:R,retryOverlay:Oe,handleMessageContentChange:jt,getAnimationHandlers:Mt,handleHistoryScroll:sn.handleHistoryScroll,handleHistoryUpwardIntent:dn,onTimelineIsAtEndChange:Dt,timelineFollowSuspended:St,timelineHistoryAnchorToken:wt,scrollToBottom:cn,sessionQuestions:Se,sessionPermissions:xe,isProgrammaticFollowActive:Ht,showLoadOlderButton:fn,onLoadOlder:hn,turnIds:sn.turnIds,activeTurnId:sn.activeTurnId,onSelectTurn:yn,showPromptNavigator:Sn,canLoadEarlierPrompts:bn,isLoadingOlderPrompts:pn,onLoadEarlierPrompts:hn},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)(cR,{}):null,!Le&&Qt.length>0&&(je?(0,$.jsx)(yg,{placement:`expanded`,visible:sn.showScrollToBottom,onClick:gn.resumeToLatest}):(0,$.jsx)(yg,{visible:sn.showScrollToBottom,onClick:gn.resumeToLatest})),_n]}),(0,$.jsx)(Sx,{}),(0,$.jsx)(rL,{open:F,onOpenChange:I,sessionID:r??void 0,directory:k,onRevertMessage:f,onScrollToMessage:sn.scrollToMessage,onScrollByTurnOffset:gn.scrollByTurnOffset,onResumeToLatest:cn,canLoadEarlier:sn.historySignals.canLoadEarlier,isLoadingEarlier:pn,onLoadEarlier:hn})]}):null});xR.displayName=`MemoizedChatContainerContent`;var SR=()=>{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)(ac,{className:`h-4 w-4/5 animate-none rounded-md`}),(0,$.jsx)(ac,{className:`h-4 w-2/3 animate-none rounded-md`}),(0,$.jsx)(ac,{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)(ac,{className:`h-4 w-5/6 animate-none rounded-md`}),(0,$.jsx)(ac,{className:`h-4 w-3/5 animate-none rounded-md`})]}),(0,$.jsx)(ac,{className:`h-24 w-full animate-none rounded-xl`})]})})}),e[1]=n):n=e[1],n},CR=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=xg(),a=cr(),o=Zr(pe(DR)),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=jL(c),t[7]=c,t[8]=l);let u=l,f=u.key,p=bt()||d()||i===`mini-chat`?iR:rR,m;t[9]!==p||t[10]!==c||t[11]!==u?(m=()=>({activeIntent:u,cacheNeedsTrim:!1,cachedSessionViews:c?NL([],c,p,$L):[],pendingSessionView:null}),t[9]=p,t[10]=c,t[11]=u,t[12]=m):m=t[12];let[h,g]=Z.useState(m),_=Z.useRef(u),v=Z.useRef(f),{cacheNeedsTrim:y,cachedSessionViews:b,pendingSessionView:x}=h,S=x?.intent===u?x.entry:null,C;if(t[13]!==b||t[14]!==S){let e=[...b];S&&!e.some(e=>e.key===S.key)&&e.push(S),C=e.sort(OR),t[13]=b,t[14]=S,t[15]=C}else C=t[15];let w=C,T;t[16]!==w||t[17]!==f?(T=FL(w,f),t[16]=w,t[17]=f,t[18]=T):T=t[18];let E=T,D=!!(f&&!E),O;t[19]!==p||t[20]!==u||t[21]!==f?(O=()=>{_.current=u,v.current=f,g(e=>IL(e,u,p))},t[19]=p,t[20]=u,t[21]=f,t[22]=O):O=t[22];let k;t[23]!==p||t[24]!==y||t[25]!==u||t[26]!==f?(k=[p,y,u,f],t[23]=p,t[24]=y,t[25]=u,t[26]=f,t[27]=k):k=t[27],rt(O,k);let A=x?.intent??null,j,M;t[28]!==p||t[29]!==A?(j=()=>{A&&g(e=>RL(e,A,p))},M=[p,A],t[28]=p,t[29]=A,t[30]=j,t[31]=M):(j=t[30],M=t[31]),rt(j,M);let N;t[32]!==E||t[33]!==u||t[34]!==f?(N=()=>{if(!u.selection||E)return;let e=u,t=f;return mc(()=>{_.current===e&&v.current===t&&g(n=>v.current===t?LL(n,e,_.current,$L):n)},{priority:`user-blocking`})},t[32]=E,t[33]=u,t[34]=f,t[35]=N):N=t[35];let P;t[36]!==E||t[37]!==p||t[38]!==u||t[39]!==f?(P=[E,p,u,f],t[36]=E,t[37]=p,t[38]=u,t[39]=f,t[40]=P):P=t[40],Z.useEffect(N,P);let F;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(F=(e,t)=>{let n=_.current,r=v.current;g(i=>{if(_.current!==n||v.current!==r||i.activeIntent!==n||e!==r)return i;let a=PL(i.cachedSessionViews,e,t);return a===i.cachedSessionViews?i:{...i,cacheNeedsTrim:!0,cachedSessionViews:a}})},t[41]=F):F=t[41];let I=J(F),L=D||void 0,R;t[42]!==D||t[43]!==f?(R=D?(0,$.jsx)(SR,{},f):null,t[42]=D,t[43]=f,t[44]=R):R=t[44];let z;if(t[45]!==E||t[46]!==I||t[47]!==n||t[48]!==w){let e;t[50]!==E||t[51]!==I||t[52]!==n?(e=e=>(0,$.jsx)(Z.Activity,{name:`chat-session-${e.sessionId}`,mode:E===e.key?`visible`:`hidden`,children:(0,$.jsx)(xR,{...n,sessionId:e.sessionId,sessionDirectory:e.directory,sessionViewKey:e.key,onSessionViewEstimateChange:I})},e.key),t[50]=E,t[51]=I,t[52]=n,t[53]=e):e=t[53],z=w.map(e),t[45]=E,t[46]=I,t[47]=n,t[48]=w,t[49]=z}else z=t[49];let B;t[54]!==n||t[55]!==o.directory||t[56]!==f?(B=f?null:(0,$.jsx)(xR,{...n,sessionId:null,sessionDirectory:o.directory}),t[54]=n,t[55]=o.directory,t[56]=f,t[57]=B):B=t[57];let V;return t[58]!==L||t[59]!==R||t[60]!==z||t[61]!==B?(V=(0,$.jsxs)(`div`,{className:`h-full bg-background`,"aria-busy":L,children:[R,z,B]}),t[58]=L,t[59]=R,t[60]=z,t[61]=B,t[62]=V):V=t[62],V},wR=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=Nx(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)(xR,{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)(Nh.Provider,{value:u,children:f}),t[21]=u,t[22]=f,t[23]=p):p=t[23],p},TR=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=cr(),o=n.directory??a,s;t[4]!==o||t[5]!==n?(s=Mh({...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)(xR,{...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)(Nh.Provider,{value:c,children:u}),t[13]=c,t[14]=u,t[15]=d):d=t[15],d},ER=e=>{let t=(0,Q.c)(14),n=Z.useSyncExternalStore(aR,i,i);if(e.host){let r=`${n}:${e.host.sessionSurface.surfaceId}`,i;return t[0]!==e||t[1]!==n||t[2]!==r?(i=(0,$.jsx)(wR,{...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)(TR,{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)(CR,{...e,runtimeKey:n},n),t[11]=e,t[12]=n,t[13]=r):r=t[13],r};function DR(e){return{sessionId:e.currentSessionId,directory:e.currentSessionDirectory}}function OR(e,t){return e.key.localeCompare(t.key)}export{su as $,Ug as A,Nm as B,v_ as C,a_ as D,g_ as E,Qh as F,Jp as G,xm as H,$h as I,Ju as J,zp as K,kh as L,bg as M,yg as N,s_ as O,pg as P,ou as Q,Ah as R,__ as S,b_ as T,im as U,Em as V,qp as W,Mu as X,Ku as Y,Eu as Z,ky as _,bF as a,il as at,U_ as b,VO as c,QE as d,tl as et,HE as f,Fy as g,Lx as h,$F as i,ll as it,Wg as j,Jg as k,ZE as l,Wx as m,WL as n,rl as nt,KN as o,EE as p,gd as q,nI as r,sl as rt,Bk as s,ER as t,nl as tt,XE as u,Oy as v,h_ as w,m_ as x,ev as y,Nh as z};
|